if ($grade_item->is_course_item() or $grade_item->is_category_item()) { $grade_category = $grade_item->get_item_category(); $url = $CFG->wwwroot . '/grade/edit/tree/category.php?id=' . $grade_category->id . '&courseid=' . $courseid; redirect($gpr->add_url_params($url)); } $item = $grade_item->get_record_data(); $parent_category = $grade_item->get_parent_category(); $item->parentcategory = $parent_category->id; } else { $heading = get_string('newitem', 'grades'); $grade_item = new grade_item(array('courseid' => $courseid, 'itemtype' => 'manual'), false); $item = $grade_item->get_record_data(); $parent_category = grade_category::fetch_course_category($courseid); $item->parentcategory = $parent_category->id; } $decimalpoints = $grade_item->get_decimals(); if ($item->hidden > 1) { $item->hiddenuntil = $item->hidden; $item->hidden = 0; } else { $item->hiddenuntil = 0; } $item->locked = !empty($item->locked); $item->grademax = format_float($item->grademax, $decimalpoints); $item->grademin = format_float($item->grademin, $decimalpoints); $item->gradepass = format_float($item->gradepass, $decimalpoints); $item->multfactor = format_float($item->multfactor, 4); $item->plusfactor = format_float($item->plusfactor, 4); if ($parent_category->aggregation == GRADE_AGGREGATE_SUM or $parent_category->aggregation == GRADE_AGGREGATE_WEIGHTED_MEAN2) { $item->aggregationcoef = $item->aggregationcoef == 0 ? 0 : 1; } else {
if (empty($item->outcomeid)) { $url = $CFG->wwwroot . '/grade/edit/tree/item.php?id=' . $id . '&courseid=' . $courseid; redirect($gpr->add_url_params($url)); } $item->calculation = grade_item::denormalize_formula($item->calculation, $course->id); if ($item->itemtype == 'mod') { $cm = get_coursemodule_from_instance($item->itemmodule, $item->iteminstance, $item->courseid); $item->cmid = $cm->id; } else { $item->cmid = 0; } } else { $item = new grade_item(array('courseid' => $courseid, 'itemtype' => 'manual')); $item->cmid = 0; } $decimalpoints = $item->get_decimals(); if ($item->hidden > 1) { $item->hiddenuntil = $item->hidden; $item->hidden = 0; } else { $item->hiddenuntil = 0; } $item->locked = !empty($item->locked); $item->gradepass = format_float($item->gradepass, $decimalpoints); $item->aggregationcoef = format_float($item->aggregationcoef, 4); $mform->set_data($item); if ($data = $mform->get_data(false)) { if (array_key_exists('calculation', $data)) { $data->calculation = grade_item::normalize_formula($data->calculation, $course->id); } $hidden = empty($data->hidden) ? 0 : $data->hidden;