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.
This commit is contained in:
Damyon Wiese
2016-10-05 14:23:10 +08:00
parent 9bf212b072
commit 9b807e6dbf
@@ -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,13 +356,17 @@ class framework_importer {
require_once($CFG->libdir . '/gradelib.php');
$allscales = grade_scale::fetch_all_global();
$matchingscale = false;
foreach ($allscales as $scale) {
if ($scale->compact_items() == $scalevalues) {
$matchingscale = $scale;
if (empty($this->scalecache)) {
$allscales = grade_scale::fetch_all_global();
foreach ($allscales as $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.
$newscale = new grade_scale();
@@ -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;