Commit 9b807e6d authored by Damyon Wiese's avatar Damyon Wiese
Browse files

MDL-55767 tool_lpimportcsv: Find existing scales on the site

The code was trying to match the imported scale to an existing scale for the site. It was
not loading the items before comparing them, so the matching always failed.
parent 9bf212b0
...@@ -52,6 +52,7 @@ class framework_importer { ...@@ -52,6 +52,7 @@ class framework_importer {
protected $importid = 0; protected $importid = 0;
protected $importer = null; protected $importer = null;
protected $foundheaders = array(); protected $foundheaders = array();
protected $scalecache = array();
/** /**
* Store an error message for display later * Store an error message for display later
...@@ -355,13 +356,17 @@ class framework_importer { ...@@ -355,13 +356,17 @@ class framework_importer {
require_once($CFG->libdir . '/gradelib.php'); require_once($CFG->libdir . '/gradelib.php');
$allscales = grade_scale::fetch_all_global(); if (empty($this->scalecache)) {
$matchingscale = false; $allscales = grade_scale::fetch_all_global();
foreach ($allscales as $scale) { foreach ($allscales as $scale) {
if ($scale->compact_items() == $scalevalues) { $scale->load_items();
$matchingscale = $scale; $this->scalecache[$scale->compact_items()] = $scale;
} }
} }
$matchingscale = false;
if (isset($this->scalecache[$scalevalues])) {
$matchingscale = $this->scalecache[$scalevalues];
}
if (!$matchingscale) { if (!$matchingscale) {
// Create it. // Create it.
$newscale = new grade_scale(); $newscale = new grade_scale();
...@@ -371,6 +376,7 @@ class framework_importer { ...@@ -371,6 +376,7 @@ class framework_importer {
$newscale->scale = $scalevalues; $newscale->scale = $scalevalues;
$newscale->description = get_string('competencyscaledescription', 'tool_lpimportcsv'); $newscale->description = get_string('competencyscaledescription', 'tool_lpimportcsv');
$newscale->insert(); $newscale->insert();
$this->scalecache[$scalevalues] = $newscale;
return $newscale->id; return $newscale->id;
} }
return $matchingscale->id; return $matchingscale->id;
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment