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 {
protected $importid = 0;
protected $importer = null;
protected $foundheaders = array();
protected $scalecache = array();
/**
* Store an error message for display later
......@@ -355,12 +356,16 @@ class framework_importer {
require_once($CFG->libdir . '/gradelib.php');
if (empty($this->scalecache)) {
$allscales = grade_scale::fetch_all_global();
$matchingscale = false;
foreach ($allscales as $scale) {
if ($scale->compact_items() == $scalevalues) {
$matchingscale = $scale;
$scale->load_items();
$this->scalecache[$scale->compact_items()] = $scale;
}
}
$matchingscale = false;
if (isset($this->scalecache[$scalevalues])) {
$matchingscale = $this->scalecache[$scalevalues];
}
if (!$matchingscale) {
// Create it.
......@@ -371,6 +376,7 @@ class framework_importer {
$newscale->scale = $scalevalues;
$newscale->description = get_string('competencyscaledescription', 'tool_lpimportcsv');
$newscale->insert();
$this->scalecache[$scalevalues] = $newscale;
return $newscale->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