// Input fields for grademin and grademax are disabled for the "Natural" category, // this means they will be ignored if user does not change aggregation method. // But if user does change aggregation method the default values should be used. // This does not apply to calculated category totals. $category->grademax = 100; $category->grade_item_grademax = 100; $category->grademin = 0; $category->grade_item_grademin = 0; } } } else { $heading = get_string('newcategory', 'grades'); $grade_category = new grade_category(array('courseid' => $courseid), false); $grade_category->apply_default_settings(); $grade_category->apply_forced_settings(); $category = $grade_category->get_record_data(); $grade_item = new grade_item(array('courseid' => $courseid, 'itemtype' => 'manual'), false); foreach ($grade_item->get_record_data() as $key => $value) { $category->{"grade_item_{$key}"} = $value; } } $mform = new edit_category_form(null, array('current' => $category, 'gpr' => $gpr)); if ($mform->is_cancelled()) { redirect($returnurl); } else { if ($data = $mform->get_data(false)) { // If no fullname is entered for a course category, put ? in the DB if (!isset($data->fullname) || $data->fullname == '') { $data->fullname = '?'; } if (!isset($data->aggregateonlygraded)) {
/** * Create a grade_category. * * @param array|stdClass $record * @return stdClass the grade category record */ public function create_grade_category($record = null) { global $CFG; $this->gradecategorycounter++; $i = $this->gradecategorycounter; if (!isset($record['fullname'])) { $record['fullname'] = 'Grade category ' . $i; } // For gradelib classes. require_once $CFG->libdir . '/gradelib.php'; // Create new grading category in this course. $gradecategory = new grade_category($record, false); $gradecategory->apply_default_settings(); $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(); }