MDL-47398 core_grades: fix grade category generator

This commit is contained in:
Marina Glancy
2014-09-25 10:39:46 +08:00
parent cbc60dd58b
commit 607a001c8e
2 changed files with 39 additions and 14 deletions
+9 -5
View File
@@ -753,6 +753,12 @@ EOD;
$this->gradecategorycounter++;
$i = $this->gradecategorycounter;
$record = (array)$record;
if (empty($record['courseid'])) {
throw new coding_exception('courseid must be present in testing::create_grade_category() $record');
}
if (!isset($record['fullname'])) {
$record['fullname'] = 'Grade category ' . $i;
}
@@ -760,17 +766,15 @@ EOD;
// For gradelib classes.
require_once($CFG->libdir . '/gradelib.php');
// Create new grading category in this course.
$gradecategory = new grade_category($record, false);
$gradecategory = new grade_category(array('courseid' => $record['courseid']), false);
$gradecategory->apply_default_settings();
grade_category::set_properties($gradecategory, $record);
$gradecategory->apply_forced_settings();
$gradecategory->insert();
// This creates a default grade item for the category
$gradeitem = $gradecategory->load_grade_item();
if (isset($record->parentcategory)) {
$gradecategory->set_parent($data->parentcategory);
}
$gradecategory->update_from_db();
return $gradecategory->get_record_data();
}