Exemple #1
0
require_login($course);
$context = context_course::instance($course->id);
require_capability('moodle/grade:manage', $context);
// todo $PAGE->requires->js_module() should be used here instead
$PAGE->requires->js('/grade/edit/tree/functions.js');
/// return tracking object
$gpr = new grade_plugin_return(array('type' => 'edit', 'plugin' => 'tree', 'courseid' => $courseid));
$returnurl = $gpr->get_return_url(null);
// Change category aggregation if requested
if (!is_null($category) && !is_null($aggregationtype) && confirm_sesskey()) {
    if (!($grade_category = grade_category::fetch(array('id' => $category, 'courseid' => $courseid)))) {
        print_error('invalidcategoryid');
    }
    $data = new stdClass();
    $data->aggregation = $aggregationtype;
    grade_category::set_properties($grade_category, $data);
    $grade_category->update();
    grade_regrade_final_grades($courseid);
}
//first make sure we have proper final grades - we need it for locking changes
$normalisationmessage = null;
$originalweights = grade_helper::fetch_all_natural_weights_for_course($courseid);
grade_regrade_final_grades($courseid);
$alteredweights = grade_helper::fetch_all_natural_weights_for_course($courseid);
if (array_diff($originalweights, $alteredweights)) {
    $normalisationmessage = get_string('weightsadjusted', 'grades');
}
// get the grading tree object
// note: total must be first for moving to work correctly, if you want it last moving code must be rewritten!
$gtree = new grade_tree($courseid, false, false);
if (empty($eid)) {
 /**
  * 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;
     $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;
     }
     // For gradelib classes.
     require_once $CFG->libdir . '/gradelib.php';
     // Create new grading category in this course.
     $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();
     $gradecategory->update_from_db();
     return $gradecategory->get_record_data();
 }