private function get_moodle_grades() { global $DB, $CFG; $grades = $DB->get_records('grade_grades', array('itemid' => $this->course_grade_item->id), 'userid', 'userid, finalgrade'); if (!is_array($grades)) { $grades = array(); } $this->moodle_grades = array(); if ($this->course_grade_item->gradetype == GRADE_TYPE_SCALE) { $pg_scale = new grade_scale(array('id' => $CFG->grade_report_newgradereport_scale)); $scale_items = $pg_scale->load_items(); foreach ($this->moodle_students as $st) { if (isset($grades[$st->id])) { $fg = (int) $grades[$st->id]->finalgrade; if (isset($scale_items[$fg - 1])) { $this->moodle_grades[$st->id] = $scale_items[$fg - 1]; } else { $this->moodle_grades[$st->id] = null; } } else { $this->moodle_grades[$st->id] = null; } } } else { foreach ($this->moodle_students as $st) { if (isset($grades[$st->id])) { $this->moodle_grades[$st->id] = grade_format_gradevalue($grades[$st->id]->finalgrade, $this->course_grade_item, true, $this->course_grade_item->get_displaytype(), null); } else { $this->moodle_grades[$st->id] = null; } } } }
function validation($data) { global $CFG, $COURSE; $errors = array(); // we can not allow 2 scales with the same exact scale as this creates // problems for backup/restore $old = grade_scale::fetch(array('id' => $data['id'])); if (array_key_exists('standard', $data)) { if (empty($data['standard'])) { $courseid = $COURSE->id; } else { $courseid = 0; } } else { $courseid = $old->courseid; } if (array_key_exists('scale', $data)) { $count = count_records('scale', 'courseid', $courseid, 'scale', $data['scale']); if (empty($old->id) or $old->courseid != $courseid) { if ($count) { $errors['scale'] = get_string('duplicatescale', 'grades'); } } else { if ($old->scale != $data['scale']) { if ($count) { $errors['scale'] = get_string('duplicatescale', 'grades'); } } } $options = explode(',', $data['scale']); if (count($options) < 2) { $errors['scale'] = get_string('error'); } } if (0 == count($errors)) { return true; } else { return $errors; } }
/** * */ public function get_data() { $data = parent::get_data(); if (!$data) { return false; } if (empty($data->timeavailable)) { unset($data->timeinterval); $data->intervalcount = 1; } if (empty($data->timeinterval)) { $data->intervalcount = 1; } // Turn off completion settings if the checkboxes aren't ticked. if (!empty($data->completionunlocked)) { $autocompletion = !empty($data->completion) && $data->completion == COMPLETION_TRACKING_AUTOMATIC; if (empty($data->completionentriesenabled) or !$autocompletion) { $data->completionentries = 0; } if (empty($data->completionspecificgradeenabled) or !$autocompletion) { $data->completionspecificgrade = 0; } if (empty($data->grade) and !empty($data->completionspecificgradeenabled)) { unset($data->completionspecificgradeenabled); $data->completionspecificgrade = 0; } if (!empty($data->grade) and !empty($data->completionspecificgrade)) { if ($data->grade > 0) { if ($data->completionspecificgrade > $data->grade) { $data->completionspecificgrade = $data->grade; } } else { // Custom scale. $scale = grade_scale::fetch(array('id' => -$data->grade)); $numitems = count($scale->load_items()); if ($data->completionspecificgrade > $numitems) { $data->completionspecificgrade = $numitems; } } } } // Grade items. $gradeitems = array(); if ($this->_instance) { $gradeitems = \mod_dataform_dataform::instance($this->_instance)->grade_items; } $gradeitems[0] = empty($gradeitems[0]) ? array() : $gradeitems[0]; $updategradeitems = false; // Check grade calc change. $thiscalc = !empty($gradeitems[0]['ca']) ? $gradeitems[0]['ca'] : null; $gradecalc = !empty($data->gradecalc) ? $data->gradecalc : null; if ($thiscalc != $gradecalc) { if (!$gradecalc) { unset($gradeitems[0]['ca']); } else { $gradeitems[0]['ca'] = $gradecalc; } $updategradeitems = true; } // Check grade guide change. $thisguide = !empty($gradeitems[0]['ru']) ? $gradeitems[0]['ru'] : null; $gradeguide = !empty($data->gradeguide) ? $data->gradeguide : null; if ($thisguide != $gradeguide) { if (!$gradeguide) { unset($gradeitems[0]['ru']); } else { $gradeitems[0]['ru'] = $gradeguide; } $updategradeitems = true; } if ($updategradeitems) { $data->gradeitems = $gradeitems[0] ? serialize($gradeitems) : null; } return $data; }
function sub_test_grade_scale_fetch() { $grade_scale = new grade_scale(); $this->assertTrue(method_exists($grade_scale, 'fetch')); $grade_scale = grade_scale::fetch(array('id' => $this->scale[0]->id)); $this->assertEqual($this->scale[0]->id, $grade_scale->id); $this->assertEqual($this->scale[0]->name, $grade_scale->name); }
/** * Remove all grade related course data - history is kept * @param int $courseid * @param bool @showfeedback print feedback */ function remove_course_grades($courseid, $showfeedback) { $strdeleted = get_string('deleted'); $course_category = grade_category::fetch_course_category($courseid); $course_category->delete('coursedelete'); if ($showfeedback) { notify($strdeleted . ' - ' . get_string('grades', 'grades') . ', ' . get_string('items', 'grades') . ', ' . get_string('categories', 'grades')); } if ($outcomes = grade_outcome::fetch_all(array('courseid' => $courseid))) { foreach ($outcomes as $outcome) { $outcome->delete('coursedelete'); } } delete_records('grade_outcomes_courses', 'courseid', $courseid); if ($showfeedback) { notify($strdeleted . ' - ' . get_string('outcomes', 'grades')); } if ($scales = grade_scale::fetch_all(array('courseid' => $courseid))) { foreach ($scales as $scale) { $scale->delete('coursedelete'); } } if ($showfeedback) { notify($strdeleted . ' - ' . get_string('scales')); } }
/** * Instantiates a grade_scale object whose data is retrieved from the * @return object grade_scale */ function load_scale() { if (empty($this->scale->id) or $this->scale->id != $this->scaleid) { $this->scale = grade_scale::fetch(array('id' => $this->scaleid)); $this->scale->load_items(); } return $this->scale; }
function definition() { global $COURSE, $CFG, $DB; $mform =& $this->_form; $item = $this->_customdata['current']; /// visible elements $mform->addElement('header', 'general', get_string('gradeitem', 'grades')); $mform->addElement('text', 'itemname', get_string('itemname', 'grades')); $mform->addElement('text', 'iteminfo', get_string('iteminfo', 'grades')); $mform->setHelpButton('iteminfo', array('iteminfo', get_string('iteminfo', 'grades'), 'grade'), true); $mform->addElement('text', 'idnumber', get_string('idnumbermod')); $mform->setHelpButton('idnumber', array('idnumber', get_string('idnumber', 'grades'), 'grade'), true); $options = array(GRADE_TYPE_NONE => get_string('typenone', 'grades'), GRADE_TYPE_VALUE => get_string('typevalue', 'grades'), GRADE_TYPE_SCALE => get_string('typescale', 'grades'), GRADE_TYPE_TEXT => get_string('typetext', 'grades')); $mform->addElement('select', 'gradetype', get_string('gradetype', 'grades'), $options); $mform->setHelpButton('gradetype', array('gradetype', get_string('gradetype', 'grades'), 'grade'), true); $mform->setDefault('gradetype', GRADE_TYPE_VALUE); //$mform->addElement('text', 'calculation', get_string('calculation', 'grades')); //$mform->disabledIf('calculation', 'gradetype', 'eq', GRADE_TYPE_TEXT); //$mform->disabledIf('calculation', 'gradetype', 'eq', GRADE_TYPE_NONE); $options = array(0 => get_string('usenoscale', 'grades')); if ($scales = grade_scale::fetch_all_local($COURSE->id)) { foreach ($scales as $scale) { $options[$scale->id] = $scale->get_name(); } } if ($scales = grade_scale::fetch_all_global()) { foreach ($scales as $scale) { $options[$scale->id] = $scale->get_name(); } } // ugly BC hack - it was possbile to use custom scale from other courses :-( if (!empty($item->scaleid) and !isset($options[$item->scaleid])) { if ($scale = grade_scale::fetch(array('id' => $item->scaleid))) { $options[$scale->id] = $scale->get_name() . get_string('incorrectcustomscale', 'grades'); } } $mform->addElement('select', 'scaleid', get_string('scale'), $options); $mform->setHelpButton('scaleid', array('scaleid', get_string('scaleid', 'grades'), 'grade'), true); $mform->disabledIf('scaleid', 'gradetype', 'noteq', GRADE_TYPE_SCALE); $mform->addElement('text', 'grademax', get_string('grademax', 'grades')); $mform->setHelpButton('grademax', array('grademax', get_string('grademax', 'grades'), 'grade'), true); $mform->disabledIf('grademax', 'gradetype', 'noteq', GRADE_TYPE_VALUE); $mform->addElement('text', 'grademin', get_string('grademin', 'grades')); $mform->setHelpButton('grademin', array('grademin', get_string('grademin', 'grades'), 'grade'), true); $mform->disabledIf('grademin', 'gradetype', 'noteq', GRADE_TYPE_VALUE); $mform->addElement('text', 'gradepass', get_string('gradepass', 'grades')); $mform->setHelpButton('gradepass', array('gradepass', get_string('gradepass', 'grades'), 'grade'), true); $mform->disabledIf('gradepass', 'gradetype', 'eq', GRADE_TYPE_NONE); $mform->disabledIf('gradepass', 'gradetype', 'eq', GRADE_TYPE_TEXT); $mform->addElement('text', 'multfactor', get_string('multfactor', 'grades')); $mform->setHelpButton('multfactor', array('multfactor', get_string('multfactor', 'grades'), 'grade'), true); $mform->setAdvanced('multfactor'); $mform->disabledIf('multfactor', 'gradetype', 'eq', GRADE_TYPE_NONE); $mform->disabledIf('multfactor', 'gradetype', 'eq', GRADE_TYPE_TEXT); $mform->addElement('text', 'plusfactor', get_string('plusfactor', 'grades')); $mform->setHelpButton('plusfactor', array('plusfactor', get_string('plusfactor', 'grades'), 'grade'), true); $mform->setAdvanced('plusfactor'); $mform->disabledIf('plusfactor', 'gradetype', 'eq', GRADE_TYPE_NONE); $mform->disabledIf('plusfactor', 'gradetype', 'eq', GRADE_TYPE_TEXT); /// grade display prefs $default_gradedisplaytype = grade_get_setting($COURSE->id, 'displaytype', $CFG->grade_displaytype); $options = array(GRADE_DISPLAY_TYPE_DEFAULT => get_string('default', 'grades'), GRADE_DISPLAY_TYPE_REAL => get_string('real', 'grades'), GRADE_DISPLAY_TYPE_PERCENTAGE => get_string('percentage', 'grades'), GRADE_DISPLAY_TYPE_LETTER => get_string('letter', 'grades'), GRADE_DISPLAY_TYPE_REAL_PERCENTAGE => get_string('realpercentage', 'grades'), GRADE_DISPLAY_TYPE_REAL_LETTER => get_string('realletter', 'grades'), GRADE_DISPLAY_TYPE_LETTER_REAL => get_string('letterreal', 'grades'), GRADE_DISPLAY_TYPE_LETTER_PERCENTAGE => get_string('letterpercentage', 'grades'), GRADE_DISPLAY_TYPE_PERCENTAGE_LETTER => get_string('percentageletter', 'grades'), GRADE_DISPLAY_TYPE_PERCENTAGE_REAL => get_string('percentagereal', 'grades')); asort($options); foreach ($options as $key => $option) { if ($key == $default_gradedisplaytype) { $options[GRADE_DISPLAY_TYPE_DEFAULT] = get_string('defaultprev', 'grades', $option); break; } } $mform->addElement('select', 'display', get_string('gradedisplaytype', 'grades'), $options); $mform->setHelpButton('display', array('gradedisplaytype', get_string('gradedisplaytype', 'grades'), 'grade'), true); $default_gradedecimals = grade_get_setting($COURSE->id, 'decimalpoints', $CFG->grade_decimalpoints); $options = array(-1 => get_string('defaultprev', 'grades', $default_gradedecimals), 0 => 0, 1 => 1, 2 => 2, 3 => 3, 4 => 4, 5 => 5); $mform->addElement('select', 'decimals', get_string('decimalpoints', 'grades'), $options); $mform->setHelpButton('decimals', array('decimalpoints', get_string('decimalpoints', 'grades'), 'grade'), true); $mform->setDefault('decimals', -1); $mform->disabledIf('decimals', 'display', 'eq', GRADE_DISPLAY_TYPE_LETTER); if ($default_gradedisplaytype == GRADE_DISPLAY_TYPE_LETTER) { $mform->disabledIf('decimals', 'display', "eq", GRADE_DISPLAY_TYPE_DEFAULT); } /// hiding // advcheckbox is not compatible with disabledIf! $mform->addElement('checkbox', 'hidden', get_string('hidden', 'grades')); $mform->setHelpButton('hidden', array('hidden', get_string('hidden', 'grades'), 'grade')); $mform->addElement('date_time_selector', 'hiddenuntil', get_string('hiddenuntil', 'grades'), array('optional' => true)); $mform->setHelpButton('hiddenuntil', array('hiddenuntil', get_string('hiddenuntil', 'grades'), 'grade')); $mform->disabledIf('hidden', 'hiddenuntil[off]', 'notchecked'); /// locking $mform->addElement('advcheckbox', 'locked', get_string('locked', 'grades')); $mform->setHelpButton('locked', array('locked', get_string('locked', 'grades'), 'grade')); $mform->addElement('date_time_selector', 'locktime', get_string('locktime', 'grades'), array('optional' => true)); $mform->setHelpButton('locktime', array('lockedafter', get_string('locktime', 'grades'), 'grade')); $mform->disabledIf('locktime', 'gradetype', 'eq', GRADE_TYPE_NONE); /// parent category related settings $mform->addElement('header', 'headerparent', get_string('parentcategory', 'grades')); $options = array(); $coefstring = ''; $categories = grade_category::fetch_all(array('courseid' => $COURSE->id)); foreach ($categories as $cat) { $cat->apply_forced_settings(); $options[$cat->id] = $cat->get_name(); } if (count($categories) > 1) { $mform->addElement('select', 'parentcategory', get_string('gradecategory', 'grades'), $options); } /// hidden params $mform->addElement('hidden', 'id', 0); $mform->setType('id', PARAM_INT); $mform->addElement('hidden', 'courseid', $COURSE->id); $mform->setType('courseid', PARAM_INT); $mform->addElement('hidden', 'itemtype', 'manual'); // all new items are manual only $mform->setType('itemtype', PARAM_ALPHA); /// add return tracking info $gpr = $this->_customdata['gpr']; $gpr->add_mform_elements($mform); /// mark advanced according to site settings if (isset($CFG->grade_item_advanced)) { $advanced = explode(',', $CFG->grade_item_advanced); foreach ($advanced as $el) { if ($mform->elementExists($el)) { $mform->setAdvanced($el); } } } //------------------------------------------------------------------------------- // buttons $this->add_action_buttons(); //------------------------------------------------------------------------------- $this->set_data($item); }
function validation($data, $files) { $errors = parent::validation($data, $files); if ($data['scaleid'] < 1) { $errors['scaleid'] = get_string('required'); } if (!empty($data['standard']) and $scale = grade_scale::fetch(array('id' => $data['scaleid']))) { if (!empty($scale->courseid)) { //TODO: localize $errors['scaleid'] = 'Can not use custom scale in global outcome!'; } } return $errors; }
if ($data = $mform->get_data()) { $scale = new grade_scale(array('id' => $id)); $data->userid = $USER->id; if (empty($scale->id)) { $data->description = $data->description_editor['text']; $data->descriptionformat = $data->description_editor['format']; grade_scale::set_properties($scale, $data); if (!has_capability('moodle/grade:manage', $systemcontext)) { $data->standard = 0; } $scale->courseid = !empty($data->standard) ? 0 : $courseid; $scale->insert(); $data = file_postupdate_standard_editor($data, 'description', $editoroptions, $systemcontext, 'grade', 'scale', $scale->id); $DB->set_field($scale->table, 'description', $data->description, array('id' => $scale->id)); } else { $data = file_postupdate_standard_editor($data, 'description', $editoroptions, $systemcontext, 'grade', 'scale', $id); grade_scale::set_properties($scale, $data); if (isset($data->standard)) { $scale->courseid = !empty($data->standard) ? 0 : $courseid; } else { unset($scale->courseid); // keep previous } $scale->update(); } redirect($returnurl); } } print_grade_page_head($COURSE->id, 'scale', null, $heading, false, false, false); $mform->display(); echo $OUTPUT->footer();
function definition() { global $CFG, $COURSE, $DB; $mform =& $this->_form; $category = $this->_customdata['current']; $this->aggregation_options = array(GRADE_AGGREGATE_MEAN => get_string('aggregatemean', 'grades'), GRADE_AGGREGATE_WEIGHTED_MEAN => get_string('aggregateweightedmean', 'grades'), GRADE_AGGREGATE_WEIGHTED_MEAN2 => get_string('aggregateweightedmean2', 'grades'), GRADE_AGGREGATE_EXTRACREDIT_MEAN => get_string('aggregateextracreditmean', 'grades'), GRADE_AGGREGATE_MEDIAN => get_string('aggregatemedian', 'grades'), GRADE_AGGREGATE_MIN => get_string('aggregatemin', 'grades'), GRADE_AGGREGATE_MAX => get_string('aggregatemax', 'grades'), GRADE_AGGREGATE_MODE => get_string('aggregatemode', 'grades'), GRADE_AGGREGATE_SUM => get_string('aggregatesum', 'grades')); // visible elements $mform->addElement('header', 'headercategory', get_string('gradecategory', 'grades')); $mform->addElement('text', 'fullname', get_string('categoryname', 'grades')); $mform->addRule('fullname', null, 'required', null, 'client'); $mform->addElement('select', 'aggregation', get_string('aggregation', 'grades'), $this->aggregation_options); $mform->addHelpButton('aggregation', 'aggregation', 'grades'); if ((int) $CFG->grade_aggregation_flag & 2) { $mform->setAdvanced('aggregation'); } $mform->addElement('checkbox', 'aggregateonlygraded', get_string('aggregateonlygraded', 'grades')); $mform->addHelpButton('aggregateonlygraded', 'aggregateonlygraded', 'grades'); $mform->disabledIf('aggregateonlygraded', 'aggregation', 'eq', GRADE_AGGREGATE_SUM); if ((int) $CFG->grade_aggregateonlygraded_flag & 2) { $mform->setAdvanced('aggregateonlygraded'); } if (empty($CFG->enableoutcomes)) { $mform->addElement('hidden', 'aggregateoutcomes'); $mform->setType('aggregateoutcomes', PARAM_INT); } else { $mform->addElement('checkbox', 'aggregateoutcomes', get_string('aggregateoutcomes', 'grades')); $mform->addHelpButton('aggregateoutcomes', 'aggregateoutcomes', 'grades'); if ((int) $CFG->grade_aggregateoutcomes_flag & 2) { $mform->setAdvanced('aggregateoutcomes'); } } $mform->addElement('advcheckbox', 'aggregatesubcats', get_string('aggregatesubcats', 'grades')); $mform->addHelpButton('aggregatesubcats', 'aggregatesubcats', 'grades'); if ((int) $CFG->grade_aggregatesubcats_flag & 2) { $mform->setAdvanced('aggregatesubcats'); } $options = array(0 => get_string('none')); for ($i = 1; $i <= 20; $i++) { $options[$i] = $i; } $mform->addElement('select', 'keephigh', get_string('keephigh', 'grades'), $options); $mform->addHelpButton('keephigh', 'keephigh', 'grades'); if ((int) $CFG->grade_keephigh_flag & 2) { $mform->setAdvanced('keephigh'); } $mform->addElement('select', 'droplow', get_string('droplow', 'grades'), $options); $mform->addHelpButton('droplow', 'droplow', 'grades'); $mform->disabledIf('droplow', 'keephigh', 'noteq', 0); if ((int) $CFG->grade_droplow_flag & 2) { $mform->setAdvanced('droplow'); } $mform->disabledIf('keephigh', 'droplow', 'noteq', 0); $mform->disabledIf('droplow', 'keephigh', 'noteq', 0); // Grade item settings // Displayed as Category total to avoid confusion between grade items requiring marking and category totals $mform->addElement('header', 'general', get_string('categorytotal', 'grades')); $mform->addElement('text', 'grade_item_itemname', get_string('categorytotalname', 'grades')); $mform->setAdvanced('grade_item_itemname'); $mform->addElement('text', 'grade_item_iteminfo', get_string('iteminfo', 'grades')); $mform->addHelpButton('grade_item_iteminfo', 'iteminfo', 'grades'); $mform->addElement('text', 'grade_item_idnumber', get_string('idnumbermod')); $mform->addHelpButton('grade_item_idnumber', 'idnumbermod'); $options = array(GRADE_TYPE_NONE => get_string('typenone', 'grades'), GRADE_TYPE_VALUE => get_string('typevalue', 'grades'), GRADE_TYPE_SCALE => get_string('typescale', 'grades'), GRADE_TYPE_TEXT => get_string('typetext', 'grades')); $mform->addElement('select', 'grade_item_gradetype', get_string('gradetype', 'grades'), $options); $mform->addHelpButton('grade_item_gradetype', 'gradetype', 'grades'); $mform->setDefault('grade_item_gradetype', GRADE_TYPE_VALUE); $mform->disabledIf('grade_item_gradetype', 'aggregation', 'eq', GRADE_AGGREGATE_SUM); //$mform->addElement('text', 'calculation', get_string('calculation', 'grades')); //$mform->disabledIf('calculation', 'gradetype', 'eq', GRADE_TYPE_TEXT); //$mform->disabledIf('calculation', 'gradetype', 'eq', GRADE_TYPE_NONE); $options = array(0 => get_string('usenoscale', 'grades')); if ($scales = grade_scale::fetch_all_local($COURSE->id)) { foreach ($scales as $scale) { $options[$scale->id] = $scale->get_name(); } } if ($scales = grade_scale::fetch_all_global()) { foreach ($scales as $scale) { $options[$scale->id] = $scale->get_name(); } } // ugly BC hack - it was possible to use custom scale from other courses :-( if (!empty($category->grade_item_scaleid) and !isset($options[$category->grade_item_scaleid])) { if ($scale = grade_scale::fetch(array('id' => $category->grade_item_scaleid))) { $options[$scale->id] = $scale->get_name() . ' ' . get_string('incorrectcustomscale', 'grades'); } } $mform->addElement('select', 'grade_item_scaleid', get_string('scale'), $options); $mform->addHelpButton('grade_item_scaleid', 'typescale', 'grades'); $mform->disabledIf('grade_item_scaleid', 'grade_item_gradetype', 'noteq', GRADE_TYPE_SCALE); $mform->disabledIf('grade_item_scaleid', 'aggregation', 'eq', GRADE_AGGREGATE_SUM); $mform->addElement('text', 'grade_item_grademax', get_string('grademax', 'grades')); $mform->addHelpButton('grade_item_grademax', 'grademax', 'grades'); $mform->disabledIf('grade_item_grademax', 'grade_item_gradetype', 'noteq', GRADE_TYPE_VALUE); $mform->disabledIf('grade_item_grademax', 'aggregation', 'eq', GRADE_AGGREGATE_SUM); $mform->addElement('text', 'grade_item_grademin', get_string('grademin', 'grades')); $mform->addHelpButton('grade_item_grademin', 'grademin', 'grades'); $mform->disabledIf('grade_item_grademin', 'grade_item_gradetype', 'noteq', GRADE_TYPE_VALUE); $mform->disabledIf('grade_item_grademin', 'aggregation', 'eq', GRADE_AGGREGATE_SUM); $mform->addElement('text', 'grade_item_gradepass', get_string('gradepass', 'grades')); $mform->addHelpButton('grade_item_gradepass', 'gradepass', 'grades'); $mform->disabledIf('grade_item_gradepass', 'grade_item_gradetype', 'eq', GRADE_TYPE_NONE); $mform->disabledIf('grade_item_gradepass', 'grade_item_gradetype', 'eq', GRADE_TYPE_TEXT); /// grade display prefs $default_gradedisplaytype = grade_get_setting($COURSE->id, 'displaytype', $CFG->grade_displaytype); $options = array(GRADE_DISPLAY_TYPE_DEFAULT => get_string('default', 'grades'), GRADE_DISPLAY_TYPE_REAL => get_string('real', 'grades'), GRADE_DISPLAY_TYPE_PERCENTAGE => get_string('percentage', 'grades'), GRADE_DISPLAY_TYPE_LETTER => get_string('letter', 'grades'), GRADE_DISPLAY_TYPE_REAL_PERCENTAGE => get_string('realpercentage', 'grades'), GRADE_DISPLAY_TYPE_REAL_LETTER => get_string('realletter', 'grades'), GRADE_DISPLAY_TYPE_LETTER_REAL => get_string('letterreal', 'grades'), GRADE_DISPLAY_TYPE_LETTER_PERCENTAGE => get_string('letterpercentage', 'grades'), GRADE_DISPLAY_TYPE_PERCENTAGE_LETTER => get_string('percentageletter', 'grades'), GRADE_DISPLAY_TYPE_PERCENTAGE_REAL => get_string('percentagereal', 'grades')); asort($options); foreach ($options as $key => $option) { if ($key == $default_gradedisplaytype) { $options[GRADE_DISPLAY_TYPE_DEFAULT] = get_string('defaultprev', 'grades', $option); break; } } $mform->addElement('select', 'grade_item_display', get_string('gradedisplaytype', 'grades'), $options); $mform->addHelpButton('grade_item_display', 'gradedisplaytype', 'grades'); $default_gradedecimals = grade_get_setting($COURSE->id, 'decimalpoints', $CFG->grade_decimalpoints); $options = array(-1 => get_string('defaultprev', 'grades', $default_gradedecimals), 0 => 0, 1 => 1, 2 => 2, 3 => 3, 4 => 4, 5 => 5); $mform->addElement('select', 'grade_item_decimals', get_string('decimalpoints', 'grades'), $options); $mform->addHelpButton('grade_item_decimals', 'decimalpoints', 'grades'); $mform->setDefault('grade_item_decimals', -1); $mform->disabledIf('grade_item_decimals', 'grade_item_display', 'eq', GRADE_DISPLAY_TYPE_LETTER); if ($default_gradedisplaytype == GRADE_DISPLAY_TYPE_LETTER) { $mform->disabledIf('grade_item_decimals', 'grade_item_display', "eq", GRADE_DISPLAY_TYPE_DEFAULT); } /// hiding // advcheckbox is not compatible with disabledIf! $mform->addElement('checkbox', 'grade_item_hidden', get_string('hidden', 'grades')); $mform->addHelpButton('grade_item_hidden', 'hidden', 'grades'); $mform->addElement('date_time_selector', 'grade_item_hiddenuntil', get_string('hiddenuntil', 'grades'), array('optional' => true)); $mform->disabledIf('grade_item_hidden', 'grade_item_hiddenuntil[off]', 'notchecked'); /// locking $mform->addElement('checkbox', 'grade_item_locked', get_string('locked', 'grades')); $mform->addHelpButton('grade_item_locked', 'locked', 'grades'); $mform->addElement('date_time_selector', 'grade_item_locktime', get_string('locktime', 'grades'), array('optional' => true)); $mform->disabledIf('grade_item_locktime', 'grade_item_gradetype', 'eq', GRADE_TYPE_NONE); /// parent category related settings $mform->addElement('header', 'headerparent', get_string('parentcategory', 'grades')); $options = array(); $default = ''; $categories = grade_category::fetch_all(array('courseid' => $COURSE->id)); foreach ($categories as $cat) { $cat->apply_forced_settings(); $options[$cat->id] = $cat->get_name(); if ($cat->is_course_category()) { $default = $cat->id; } } if (count($categories) > 1) { $mform->addElement('select', 'parentcategory', get_string('parentcategory', 'grades'), $options); $mform->addElement('static', 'currentparentaggregation', get_string('currentparentaggregation', 'grades')); } // hidden params $mform->addElement('hidden', 'id', 0); $mform->setType('id', PARAM_INT); $mform->addElement('hidden', 'courseid', 0); $mform->setType('courseid', PARAM_INT); /// add return tracking info $gpr = $this->_customdata['gpr']; $gpr->add_mform_elements($mform); /// mark advanced according to site settings if (isset($CFG->grade_item_advanced)) { $advanced = explode(',', $CFG->grade_item_advanced); foreach ($advanced as $el) { $el = 'grade_item_' . $el; if ($mform->elementExists($el)) { $mform->setAdvanced($el); } } } //------------------------------------------------------------------------------- // buttons $this->add_action_buttons(); //------------------------------------------------------------------------------- $this->set_data($category); }
$outcome->insert(); } else { if (isset($data->standard)) { $outcome->courseid = !empty($data->standard) ? null : $courseid; } else { unset($outcome->courseid); // keep previous } $outcome->update(); } redirect($returnurl); } } if ($courseid) { print_grade_page_head($courseid, 'outcome', 'edit', $heading); } else { require_once $CFG->libdir . '/adminlib.php'; admin_externalpage_setup('outcomes'); admin_externalpage_print_header(); } if (!grade_scale::fetch_all_local($courseid) && !grade_scale::fetch_all_global()) { notice_yesno(get_string('noscales', 'grades'), $CFG->wwwroot . '/grade/edit/scale/edit.php?courseid=' . $courseid, $returnurl); print_footer($course); die; } $mform->display(); if ($courseid) { print_footer($course); } else { admin_externalpage_print_footer(); }
function validation($data) { $errors = array(); if ($data['scaleid'] < 1) { $errors['scaleid'] = get_string('required'); } if (!empty($data['standard']) and $scale = grade_scale::fetch(array('id' => $data['scaleid']))) { if (!empty($scale->courseid)) { //TODO: localize $errors['scaleid'] = 'Can not use custom scale in global outcome!'; } } if (0 == count($errors)) { return true; } else { return $errors; } }
/** * Return the scale. * * @return \grade_scale */ public function get_scale() { $scaleid = $this->get_scaleid(); if ($scaleid === null) { return $this->get_framework()->get_scale(); } $scale = \grade_scale::fetch(array('id' => $scaleid)); $scale->load_items(); return $scale; }
protected function sub_test_scale_one_item() { $params = new stdClass(); $params->name = 'unittestscale1i'; $params->courseid = $this->course->id; $params->userid = $this->userid; $params->scale = 'Like'; $params->description = 'This scale is used to like something.'; $params->timemodified = time(); $scale = new grade_scale($params, false); $scale->load_items(); $this->assertCount(1, $scale->scale_items); $this->assertSame(array('Like'), $scale->scale_items); $this->assertSame('Like', $scale->compact_items()); $scale->insert(); // Manual grade item with 1 item scale. $grade_item = new stdClass(); $grade_item->courseid = $this->course->id; $grade_item->categoryid = $this->grade_categories[0]->id; $grade_item->itemname = 'manual grade_item scale_1'; $grade_item->itemtype = 'manual'; $grade_item->itemnumber = 0; $grade_item->needsupdate = false; $grade_item->gradetype = GRADE_TYPE_SCALE; $grade_item->scaleid = $scale->id; $grade_item->iteminfo = 'Manual grade item used for unit testing'; $grade_item->timecreated = time(); $grade_item->timemodified = time(); $grade_item = new grade_item($grade_item); $grade_item->insert(); $this->assertNotEmpty($grade_item->id); $this->assertEquals(1, $grade_item->grademin); $this->assertEquals(1, $grade_item->grademax); }
/** * Local shortcut function for creating a link to a scale. * @param int $courseid The Course ID * @param grade_scale $scale The Scale to link to * @param grade_plugin_return $gpr An object used to identify the page we just came from * @return string html */ function grade_print_scale_link($courseid, $scale, $gpr) { global $CFG, $OUTPUT; $url = new moodle_url('/grade/edit/scale/edit.php', array('courseid' => $courseid, 'id' => $scale->id)); $url = $gpr->add_url_params($url); return html_writer::link($url, $scale->get_name()); }
function definition() { global $CFG, $COURSE, $DB, $OUTPUT; $mform =& $this->_form; $category = $this->_customdata['current']; $this->aggregation_options = grade_helper::get_aggregation_strings(); // visible elements $mform->addElement('header', 'headercategory', get_string('gradecategory', 'grades')); $mform->addElement('text', 'fullname', get_string('categoryname', 'grades')); $mform->setType('fullname', PARAM_TEXT); $mform->addRule('fullname', null, 'required', null, 'client'); $mform->addElement('select', 'aggregation', get_string('aggregation', 'grades'), $this->aggregation_options); $mform->addHelpButton('aggregation', 'aggregation', 'grades'); if ((int) $CFG->grade_aggregation_flag & 2) { $mform->setAdvanced('aggregation'); } $mform->addElement('checkbox', 'aggregateonlygraded', get_string('aggregateonlygraded', 'grades')); $mform->addHelpButton('aggregateonlygraded', 'aggregateonlygraded', 'grades'); if ((int) $CFG->grade_aggregateonlygraded_flag & 2) { $mform->setAdvanced('aggregateonlygraded'); } if (empty($CFG->enableoutcomes)) { $mform->addElement('hidden', 'aggregateoutcomes'); $mform->setType('aggregateoutcomes', PARAM_INT); } else { $mform->addElement('checkbox', 'aggregateoutcomes', get_string('aggregateoutcomes', 'grades')); $mform->addHelpButton('aggregateoutcomes', 'aggregateoutcomes', 'grades'); if ((int) $CFG->grade_aggregateoutcomes_flag & 2) { $mform->setAdvanced('aggregateoutcomes'); } } $mform->addElement('text', 'keephigh', get_string('keephigh', 'grades'), 'size="3"'); $mform->setType('keephigh', PARAM_INT); $mform->addHelpButton('keephigh', 'keephigh', 'grades'); if ((int) $CFG->grade_keephigh_flag & 2) { $mform->setAdvanced('keephigh'); } $mform->addElement('text', 'droplow', get_string('droplow', 'grades'), 'size="3"'); $mform->setType('droplow', PARAM_INT); $mform->addHelpButton('droplow', 'droplow', 'grades'); $mform->disabledIf('droplow', 'keephigh', 'noteq', 0); if ((int) $CFG->grade_droplow_flag & 2) { $mform->setAdvanced('droplow'); } $mform->disabledIf('keephigh', 'droplow', 'noteq', 0); $mform->disabledIf('droplow', 'keephigh', 'noteq', 0); // Grade item settings // Displayed as Category total to avoid confusion between grade items requiring marking and category totals $mform->addElement('header', 'general', get_string('categorytotal', 'grades')); $mform->addElement('text', 'grade_item_itemname', get_string('categorytotalname', 'grades')); $mform->setType('grade_item_itemname', PARAM_TEXT); $mform->setAdvanced('grade_item_itemname'); $mform->addElement('text', 'grade_item_iteminfo', get_string('iteminfo', 'grades')); $mform->addHelpButton('grade_item_iteminfo', 'iteminfo', 'grades'); $mform->setType('grade_item_iteminfo', PARAM_TEXT); $mform->addElement('text', 'grade_item_idnumber', get_string('idnumbermod')); $mform->addHelpButton('grade_item_idnumber', 'idnumbermod'); $mform->setType('grade_item_idnumber', PARAM_RAW); if (!empty($category->id)) { $gradecategory = grade_category::fetch(array('id' => $category->id)); $gradeitem = $gradecategory->load_grade_item(); // If grades exist set a message so the user knows why they can not alter the grade type or scale. // We could never change the grade type for external items, so only need to show this for manual grade items. if ($gradeitem->has_overridden_grades()) { // Set a message so the user knows why the can not alter the grade type or scale. if ($gradeitem->gradetype == GRADE_TYPE_SCALE) { $gradesexistmsg = get_string('modgradecategorycantchangegradetyporscalemsg', 'grades'); } else { $gradesexistmsg = get_string('modgradecategorycantchangegradetypemsg', 'grades'); } $notification = new \core\output\notification($gradesexistmsg, \core\output\notification::NOTIFY_INFO); $notification->set_show_closebutton(false); $mform->addElement('static', 'gradesexistmsg', '', $OUTPUT->render($notification)); } } $options = array(GRADE_TYPE_NONE => get_string('typenone', 'grades'), GRADE_TYPE_VALUE => get_string('typevalue', 'grades'), GRADE_TYPE_SCALE => get_string('typescale', 'grades'), GRADE_TYPE_TEXT => get_string('typetext', 'grades')); $mform->addElement('select', 'grade_item_gradetype', get_string('gradetype', 'grades'), $options); $mform->addHelpButton('grade_item_gradetype', 'gradetype', 'grades'); $mform->setDefault('grade_item_gradetype', GRADE_TYPE_VALUE); $mform->disabledIf('grade_item_gradetype', 'aggregation', 'eq', GRADE_AGGREGATE_SUM); //$mform->addElement('text', 'calculation', get_string('calculation', 'grades')); //$mform->disabledIf('calculation', 'gradetype', 'eq', GRADE_TYPE_TEXT); //$mform->disabledIf('calculation', 'gradetype', 'eq', GRADE_TYPE_NONE); $options = array(0 => get_string('usenoscale', 'grades')); if ($scales = grade_scale::fetch_all_local($COURSE->id)) { foreach ($scales as $scale) { $options[$scale->id] = $scale->get_name(); } } if ($scales = grade_scale::fetch_all_global()) { foreach ($scales as $scale) { $options[$scale->id] = $scale->get_name(); } } // ugly BC hack - it was possible to use custom scale from other courses :-( if (!empty($category->grade_item_scaleid) and !isset($options[$category->grade_item_scaleid])) { if ($scale = grade_scale::fetch(array('id' => $category->grade_item_scaleid))) { $options[$scale->id] = $scale->get_name() . ' ' . get_string('incorrectcustomscale', 'grades'); } } $mform->addElement('select', 'grade_item_scaleid', get_string('scale'), $options); $mform->addHelpButton('grade_item_scaleid', 'typescale', 'grades'); $mform->disabledIf('grade_item_scaleid', 'grade_item_gradetype', 'noteq', GRADE_TYPE_SCALE); $mform->disabledIf('grade_item_scaleid', 'aggregation', 'eq', GRADE_AGGREGATE_SUM); $choices = array(); $choices[''] = get_string('choose'); $choices['no'] = get_string('no'); $choices['yes'] = get_string('yes'); $mform->addElement('select', 'grade_item_rescalegrades', get_string('modgradecategoryrescalegrades', 'grades'), $choices); $mform->addHelpButton('grade_item_rescalegrades', 'modgradecategoryrescalegrades', 'grades'); $mform->disabledIf('grade_item_rescalegrades', 'grade_item_gradetype', 'noteq', GRADE_TYPE_VALUE); $mform->addElement('text', 'grade_item_grademax', get_string('grademax', 'grades')); $mform->setType('grade_item_grademax', PARAM_RAW); $mform->addHelpButton('grade_item_grademax', 'grademax', 'grades'); $mform->disabledIf('grade_item_grademax', 'grade_item_gradetype', 'noteq', GRADE_TYPE_VALUE); $mform->disabledIf('grade_item_grademax', 'aggregation', 'eq', GRADE_AGGREGATE_SUM); if ((bool) get_config('moodle', 'grade_report_showmin')) { $mform->addElement('text', 'grade_item_grademin', get_string('grademin', 'grades')); $mform->setType('grade_item_grademin', PARAM_RAW); $mform->addHelpButton('grade_item_grademin', 'grademin', 'grades'); $mform->disabledIf('grade_item_grademin', 'grade_item_gradetype', 'noteq', GRADE_TYPE_VALUE); $mform->disabledIf('grade_item_grademin', 'aggregation', 'eq', GRADE_AGGREGATE_SUM); } $mform->addElement('text', 'grade_item_gradepass', get_string('gradepass', 'grades')); $mform->setType('grade_item_gradepass', PARAM_RAW); $mform->addHelpButton('grade_item_gradepass', 'gradepass', 'grades'); $mform->disabledIf('grade_item_gradepass', 'grade_item_gradetype', 'eq', GRADE_TYPE_NONE); $mform->disabledIf('grade_item_gradepass', 'grade_item_gradetype', 'eq', GRADE_TYPE_TEXT); /// grade display prefs $default_gradedisplaytype = grade_get_setting($COURSE->id, 'displaytype', $CFG->grade_displaytype); $options = array(GRADE_DISPLAY_TYPE_DEFAULT => get_string('default', 'grades'), GRADE_DISPLAY_TYPE_REAL => get_string('real', 'grades'), GRADE_DISPLAY_TYPE_PERCENTAGE => get_string('percentage', 'grades'), GRADE_DISPLAY_TYPE_LETTER => get_string('letter', 'grades'), GRADE_DISPLAY_TYPE_REAL_PERCENTAGE => get_string('realpercentage', 'grades'), GRADE_DISPLAY_TYPE_REAL_LETTER => get_string('realletter', 'grades'), GRADE_DISPLAY_TYPE_LETTER_REAL => get_string('letterreal', 'grades'), GRADE_DISPLAY_TYPE_LETTER_PERCENTAGE => get_string('letterpercentage', 'grades'), GRADE_DISPLAY_TYPE_PERCENTAGE_LETTER => get_string('percentageletter', 'grades'), GRADE_DISPLAY_TYPE_PERCENTAGE_REAL => get_string('percentagereal', 'grades')); asort($options); foreach ($options as $key => $option) { if ($key == $default_gradedisplaytype) { $options[GRADE_DISPLAY_TYPE_DEFAULT] = get_string('defaultprev', 'grades', $option); break; } } $mform->addElement('select', 'grade_item_display', get_string('gradedisplaytype', 'grades'), $options); $mform->addHelpButton('grade_item_display', 'gradedisplaytype', 'grades'); $default_gradedecimals = grade_get_setting($COURSE->id, 'decimalpoints', $CFG->grade_decimalpoints); $options = array(-1 => get_string('defaultprev', 'grades', $default_gradedecimals), 0 => 0, 1 => 1, 2 => 2, 3 => 3, 4 => 4, 5 => 5); $mform->addElement('select', 'grade_item_decimals', get_string('decimalpoints', 'grades'), $options); $mform->addHelpButton('grade_item_decimals', 'decimalpoints', 'grades'); $mform->setDefault('grade_item_decimals', -1); $mform->disabledIf('grade_item_decimals', 'grade_item_display', 'eq', GRADE_DISPLAY_TYPE_LETTER); if ($default_gradedisplaytype == GRADE_DISPLAY_TYPE_LETTER) { $mform->disabledIf('grade_item_decimals', 'grade_item_display', "eq", GRADE_DISPLAY_TYPE_DEFAULT); } /// hiding // advcheckbox is not compatible with disabledIf! $mform->addElement('checkbox', 'grade_item_hidden', get_string('hidden', 'grades')); $mform->addHelpButton('grade_item_hidden', 'hidden', 'grades'); $mform->addElement('date_time_selector', 'grade_item_hiddenuntil', get_string('hiddenuntil', 'grades'), array('optional' => true)); $mform->disabledIf('grade_item_hidden', 'grade_item_hiddenuntil[off]', 'notchecked'); /// locking $mform->addElement('checkbox', 'grade_item_locked', get_string('locked', 'grades')); $mform->addHelpButton('grade_item_locked', 'locked', 'grades'); $mform->addElement('date_time_selector', 'grade_item_locktime', get_string('locktime', 'grades'), array('optional' => true)); $mform->disabledIf('grade_item_locktime', 'grade_item_gradetype', 'eq', GRADE_TYPE_NONE); /// parent category related settings $mform->addElement('header', 'headerparent', get_string('parentcategory', 'grades')); $mform->addElement('advcheckbox', 'grade_item_weightoverride', get_string('adjustedweight', 'grades')); $mform->addHelpButton('grade_item_weightoverride', 'weightoverride', 'grades'); $mform->addElement('text', 'grade_item_aggregationcoef2', get_string('weight', 'grades')); $mform->addHelpButton('grade_item_aggregationcoef2', 'weight', 'grades'); $mform->setType('grade_item_aggregationcoef2', PARAM_RAW); $mform->disabledIf('grade_item_aggregationcoef2', 'grade_item_weightoverride'); $options = array(); $default = -1; $categories = grade_category::fetch_all(array('courseid' => $COURSE->id)); foreach ($categories as $cat) { $cat->apply_forced_settings(); $options[$cat->id] = $cat->get_name(); if ($cat->is_course_category()) { $default = $cat->id; } } if (count($categories) > 1) { $mform->addElement('select', 'parentcategory', get_string('parentcategory', 'grades'), $options); $mform->setDefault('parentcategory', $default); $mform->addElement('static', 'currentparentaggregation', get_string('currentparentaggregation', 'grades')); } // hidden params $mform->addElement('hidden', 'id', 0); $mform->setType('id', PARAM_INT); $mform->addElement('hidden', 'courseid', 0); $mform->setType('courseid', PARAM_INT); /// add return tracking info $gpr = $this->_customdata['gpr']; $gpr->add_mform_elements($mform); /// mark advanced according to site settings if (isset($CFG->grade_item_advanced)) { $advanced = explode(',', $CFG->grade_item_advanced); foreach ($advanced as $el) { $el = 'grade_item_' . $el; if ($mform->elementExists($el)) { $mform->setAdvanced($el); } } } //------------------------------------------------------------------------------- // buttons $this->add_action_buttons(); //------------------------------------------------------------------------------- $this->set_data($category); }
$line[] = $used ? get_string('yes') : get_string('no'); $buttons = ""; $buttons .= grade_button('edit', $courseid, $scale); if (!$used) { $buttons .= grade_button('delete', $courseid, $scale); } $line[] = $buttons; $data[] = $line; } $table->head = array($strscale, $strused, $stredit); $table->size = array('70%', '20%', '10%'); $table->align = array('left', 'center', 'center'); $table->attributes['class'] = 'scaletable localscales generaltable'; $table->data = $data; } if ($scales = grade_scale::fetch_all_global()) { $heading = $strstandardscale; $data = array(); foreach ($scales as $scale) { $line = array(); $line[] = format_string($scale->name) . '<div class="scale_options">' . str_replace(",", ", ", $scale->scale) . '</div>'; $used = $scale->is_used(); $line[] = $used ? get_string('yes') : get_string('no'); $buttons = ""; if (has_capability('moodle/course:managescales', get_context_instance(CONTEXT_SYSTEM))) { $buttons .= grade_button('edit', $courseid, $scale); } if (!$used and has_capability('moodle/course:managescales', get_context_instance(CONTEXT_SYSTEM))) { $buttons .= grade_button('delete', $courseid, $scale); } $line[] = $buttons;
/** * Test get_course_module */ public function test_get_course_module() { global $DB; $this->resetAfterTest(true); $this->setAdminUser(); $course = self::getDataGenerator()->create_course(); $record = array('course' => $course->id, 'name' => 'First Assignment'); $options = array('idnumber' => 'ABC', 'visible' => 0); // Hidden activity. $assign = self::getDataGenerator()->create_module('assign', $record, $options); $outcomescale = 'Distinction, Very Good, Good, Pass, Fail'; // Insert a custom grade scale to be used by an outcome. $gradescale = new grade_scale(); $gradescale->name = 'gettcoursemodulescale'; $gradescale->courseid = $course->id; $gradescale->userid = 0; $gradescale->scale = $outcomescale; $gradescale->description = 'This scale is used to mark standard assignments.'; $gradescale->insert(); // Insert an outcome. $data = new stdClass(); $data->courseid = $course->id; $data->fullname = 'Team work'; $data->shortname = 'Team work'; $data->scaleid = $gradescale->id; $outcome = new grade_outcome($data, false); $outcome->insert(); $outcomegradeitem = new grade_item(); $outcomegradeitem->itemname = $outcome->shortname; $outcomegradeitem->itemtype = 'mod'; $outcomegradeitem->itemmodule = 'assign'; $outcomegradeitem->iteminstance = $assign->id; $outcomegradeitem->outcomeid = $outcome->id; $outcomegradeitem->cmid = 0; $outcomegradeitem->courseid = $course->id; $outcomegradeitem->aggregationcoef = 0; $outcomegradeitem->itemnumber = 1; // The activity's original grade item will be 0. $outcomegradeitem->gradetype = GRADE_TYPE_SCALE; $outcomegradeitem->scaleid = $outcome->scaleid; $outcomegradeitem->insert(); $assignmentgradeitem = grade_item::fetch(array('itemtype' => 'mod', 'itemmodule' => 'assign', 'iteminstance' => $assign->id, 'itemnumber' => 0, 'courseid' => $course->id)); $outcomegradeitem->set_parent($assignmentgradeitem->categoryid); $outcomegradeitem->move_after_sortorder($assignmentgradeitem->sortorder); // Test admin user can see the complete hidden activity. $result = core_course_external::get_course_module($assign->cmid); $result = external_api::clean_returnvalue(core_course_external::get_course_module_returns(), $result); $this->assertCount(0, $result['warnings']); // Test we retrieve all the fields. $this->assertCount(27, $result['cm']); $this->assertEquals($record['name'], $result['cm']['name']); $this->assertEquals($options['idnumber'], $result['cm']['idnumber']); $this->assertEquals(100, $result['cm']['grade']); $this->assertEquals(0.0, $result['cm']['gradepass']); $this->assertEquals('submissions', $result['cm']['advancedgrading'][0]['area']); $this->assertEmpty($result['cm']['advancedgrading'][0]['method']); $this->assertEquals($outcomescale, $result['cm']['outcomes'][0]['scale']); $student = $this->getDataGenerator()->create_user(); $studentrole = $DB->get_record('role', array('shortname' => 'student')); self::getDataGenerator()->enrol_user($student->id, $course->id, $studentrole->id); $this->setUser($student); // The user shouldn't be able to see the activity. try { core_course_external::get_course_module($assign->cmid); $this->fail('Exception expected due to invalid permissions.'); } catch (moodle_exception $e) { $this->assertEquals('requireloginerror', $e->errorcode); } // Make module visible. set_coursemodule_visible($assign->cmid, 1); // Test student user. $result = core_course_external::get_course_module($assign->cmid); $result = external_api::clean_returnvalue(core_course_external::get_course_module_returns(), $result); $this->assertCount(0, $result['warnings']); // Test we retrieve only the few files we can see. $this->assertCount(11, $result['cm']); $this->assertEquals($assign->cmid, $result['cm']['id']); $this->assertEquals($course->id, $result['cm']['course']); $this->assertEquals('assign', $result['cm']['modname']); $this->assertEquals($assign->id, $result['cm']['instance']); }
function referentiel_print_scales($course, $cm, $context, $roles) { global $DB; global $OUTPUT; global $CFG; $strscale = get_string('scale'); $strstandardscale = get_string('scalesstandard'); $strcustomscales = get_string('scalescustom'); $srtcreatenewscale = get_string('scalescustomcreate'); $strname = get_string('name'); $strselect = get_string('select'); $strused = get_string('scaleused', 'referentiel'); $table = new html_table(); $table2 = new html_table(); $heading = ''; if ($course->id and $scales = grade_scale::fetch_all_local($course->id)) { $heading = $strcustomscales; $data = array(); foreach ($scales as $scale) { $line = array(); $line[] = format_string($scale->name) . '<div class="scale_options">' . str_replace(",", ", ", $scale->scale) . '</div>'; $used = $scale->is_used(); $line[] = $used ? get_string('yes') : get_string('no'); $menu = ""; if (has_capability('mod/referentiel:writereferentiel', $context)) { $menu .= '<a href="' . $CFG->wwwroot . '/mod/referentiel/bareme.php?id=' . $cm->id . '&scaleid=' . $scale->id . '&mode=editbareme&sesskey=' . sesskey() . '"><img src="' . $OUTPUT->pix_url('square_small', 'referentiel') . '" alt="' . get_string('select') . '" title="' . get_string('select') . '" /></a>'; } $line[] = $menu; $data[] = $line; } $table->head = array($strscale, $strused, $strselect); $table->size = array('60%', '30%', '10%'); $table->align = array('left', 'center', 'center'); $table->attributes['class'] = 'scaletable localscales generaltable'; $table->data = $data; //print_grade_page_head($courseid, 'scale', 'scale', get_string('coursescales', 'grades')); echo $OUTPUT->heading($strcustomscales . ' ' . $OUTPUT->help_icon('scalelocalh', 'referentiel'), 3, 'main'); echo html_writer::table($table); } else { echo '<div align="center">' . get_string('no_custom_scale', 'referentiel') . '<br />' . "\n"; if ($roles->is_admin) { $link = new moodle_url('/grade/edit/scale/index.php', NULL); } else { if ($roles->is_teacher) { $link = new moodle_url('/grade/edit/scale/index.php?id=' . $course->id, NULL); } else { $link = ''; } } if ($link) { echo '<a href="' . $link . '">' . get_string('create_a_scale', 'referentiel') . '</a>' . "\n"; } echo '</div>' . "\n"; } if ($scales = grade_scale::fetch_all_global()) { $heading = $strstandardscale; $data = array(); foreach ($scales as $scale) { $line = array(); $line[] = format_string($scale->name) . '<div class="scale_options">' . str_replace(",", ", ", $scale->scale) . '</div>'; $used = $scale->is_used(); $line[] = $used ? get_string('yes') : get_string('no'); $menu = ""; /* if (has_capability('mod/referentiel:writereferentiel', $context)) { $menu.= '<a href="'.$CFG->wwwroot.'/mod/referentiel/bareme.php?id='.$cm->id.'&scaleid='.$scale->id.'&mode=editbareme&sesskey='.sesskey().'"><img src="'.$OUTPUT->pix_url('square_small','referentiel').'" alt="'.get_string('select').'" title="'.get_string('select').'" /></a>'; } */ $line[] = $menu; $data[] = $line; } $table2->head = array($strscale, $strused, $strselect); $table->attributes['class'] = 'scaletable globalscales generaltable'; $table2->size = array('60%', '30%', '10%'); $table2->align = array('left', 'center', 'center'); $table2->data = $data; echo $OUTPUT->heading($strstandardscale . ' ' . $OUTPUT->help_icon('scaleglobalh', 'referentiel'), 3, 'main'); echo html_writer::table($table2); } else { echo '<div align="center">' . get_string('no_global_scale', 'referentiel') . "\n"; if ($roles->is_admin) { $link = new moodle_url('/grade/edit/scale/index.php', NULL); echo '<br /><a href="' . $link . '">' . get_string('create_global_scale', 'referentiel') . '</a>' . "\n"; } echo '</div>' . "\n"; } }
/** * Load initial test information * * @param string $assignmentname Assignment name * @param int $student1rawgrade Student 1 grade * @param int $student2rawgrade Student 2 grade * @return array Array of vars with test information */ protected function load_test_data($assignmentname, $student1rawgrade, $student2rawgrade) { global $DB; // Adds a course, a teacher, 2 students, an assignment and grades for the students. $course = $this->getDataGenerator()->create_course(); $coursecontext = context_course::instance($course->id); $studentrole = $DB->get_record('role', array('shortname' => 'student')); $student1 = $this->getDataGenerator()->create_user(); $this->getDataGenerator()->enrol_user($student1->id, $course->id, $studentrole->id); $student2 = $this->getDataGenerator()->create_user(); $this->getDataGenerator()->enrol_user($student2->id, $course->id, $studentrole->id); $teacherrole = $DB->get_record('role', array('shortname' => 'editingteacher')); $teacher = $this->getDataGenerator()->create_user(); $this->getDataGenerator()->enrol_user($teacher->id, $course->id, $teacherrole->id); $parent = $this->getDataGenerator()->create_user(); $this->setUser($parent); $student1context = context_user::instance($student1->id); // Creates a new role, gives it the capability and gives $USER that role. $parentroleid = $this->assignUserCapability('moodle/grade:viewall', $student1context->id); // Enrol the user in the course using the new role. $this->getDataGenerator()->enrol_user($parent->id, $course->id, $parentroleid); $assignment = $this->getDataGenerator()->create_module('assign', array('name' => $assignmentname, 'course' => $course->id)); $modcontext = get_coursemodule_from_instance('assign', $assignment->id, $course->id); $assignment->cmidnumber = $modcontext->id; $student1grade = array('userid' => $student1->id, 'rawgrade' => $student1rawgrade); $student2grade = array('userid' => $student2->id, 'rawgrade' => $student2rawgrade); $studentgrades = array($student1->id => $student1grade, $student2->id => $student2grade); assign_grade_item_update($assignment, $studentgrades); // Insert a custom grade scale to be used by an outcome. $gradescale = new grade_scale(); $gradescale->name = 'unittestscale3'; $gradescale->courseid = $course->id; $gradescale->userid = 0; $gradescale->scale = 'Distinction, Very Good, Good, Pass, Fail'; $gradescale->description = 'This scale is used to mark standard assignments.'; $gradescale->insert(); // Insert an outcome. $data = new stdClass(); $data->courseid = $course->id; $data->fullname = 'Team work'; $data->shortname = 'Team work'; $data->scaleid = $gradescale->id; $outcome = new grade_outcome($data, false); $outcome->insert(); $outcomegradeitem = new grade_item(); $outcomegradeitem->itemname = $outcome->shortname; $outcomegradeitem->itemtype = 'mod'; $outcomegradeitem->itemmodule = 'assign'; $outcomegradeitem->iteminstance = $assignment->id; $outcomegradeitem->outcomeid = $outcome->id; $outcomegradeitem->cmid = 0; $outcomegradeitem->courseid = $course->id; $outcomegradeitem->aggregationcoef = 0; $outcomegradeitem->itemnumber = 1; // The activity's original grade item will be 0. $outcomegradeitem->gradetype = GRADE_TYPE_SCALE; $outcomegradeitem->scaleid = $outcome->scaleid; // This next two values for testing that returns parameters are correcly formatted. $outcomegradeitem->set_locked(true); $outcomegradeitem->hidden = ''; $outcomegradeitem->insert(); $assignmentgradeitem = grade_item::fetch(array('itemtype' => 'mod', 'itemmodule' => 'assign', 'iteminstance' => $assignment->id, 'itemnumber' => 0, 'courseid' => $course->id)); $outcomegradeitem->set_parent($assignmentgradeitem->categoryid); $outcomegradeitem->move_after_sortorder($assignmentgradeitem->sortorder); return array($course, $assignment, $student1, $student2, $teacher, $parent); }
$html .= '<th class="header c5" scope="col">' . get_string('numberofgrades', 'grades') . '</th></tr>' . "\n"; $row = 0; foreach ($report_info as $outcomeid => $outcomedata) { $rowspan = count($outcomedata['items']); // If there are no items for this outcome, rowspan will equal 0, which is not good if ($rowspan == 0) { $rowspan = 1; } $shortname_html = '<tr class="r' . $row . '"><td class="cell c0" rowspan="' . $rowspan . '">' . $outcomedata['outcome']->shortname . "</td>\n"; $sitewide = get_string('no'); if (empty($outcomedata['outcome']->courseid)) { $sitewide = get_string('yes'); } $sitewide_html = '<td class="cell c2" rowspan="' . $rowspan . '">' . $sitewide . "</td>\n"; $outcomedata['outcome']->sum = 0; $scale = new grade_scale(array('id' => $outcomedata['outcome']->scaleid), false); $print_tr = false; $items_html = ''; if (!empty($outcomedata['items'])) { foreach ($outcomedata['items'] as $itemid => $item) { if ($print_tr) { $row++; $items_html .= "<tr class=\"r{$row}\">\n"; } $grade_item = new grade_item($item, false); if ($item->itemtype == 'mod') { $cm = get_coursemodule_from_instance($item->itemmodule, $item->iteminstance, $item->courseid); $itemname = '<a href="' . $CFG->wwwroot . '/mod/' . $item->itemmodule . '/view.php?id=' . $cm->id . '">' . $grade_item->get_name() . '</a>'; } else { $itemname = $grade_item->get_name(); }
function validation($data, $files) { global $CFG, $COURSE, $DB; $errors = parent::validation($data, $files); // we can not allow 2 scales with the same exact scale as this creates // problems for backup/restore $old = grade_scale::fetch(array('id' => $data['id'])); if (array_key_exists('standard', $data)) { if (empty($data['standard'])) { $courseid = $COURSE->id; } else { $courseid = 0; } } else { $courseid = $old->courseid; } if (array_key_exists('scale', $data)) { $scalearray = explode(',', $data['scale']); $scalearray = array_map('trim', $scalearray); $scaleoptioncount = count($scalearray); if (count($scalearray) < 2) { $errors['scale'] = get_string('badlyformattedscale', 'grades'); } else { $thescale = implode(',', $scalearray); //this check strips out whitespace from the scale we're validating but not from those already in the DB $count = $DB->count_records_select('scale', "courseid=:courseid AND " . $DB->sql_compare_text('scale', core_text::strlen($thescale)) . '=:scale', array('courseid' => $courseid, 'scale' => $thescale)); if ($count) { //if this is a new scale but we found a duplice in the DB //or we found a duplicate in another course report the error if (empty($old->id) or $old->courseid != $courseid) { $errors['scale'] = get_string('duplicatescale', 'grades'); } else { if ($old->scale !== $thescale and $old->scale !== $data['scale']) { //if the old scale from DB is different but we found a duplicate then we're trying to modify a scale to be a duplicate $errors['scale'] = get_string('duplicatescale', 'grades'); } } } } } return $errors; }
/** * Instantiates a grade_scale object whose data is retrieved from the DB, * if this item's scaleid variable is set. * @return object grade_scale or null if no scale used */ function load_scale() { if ($this->gradetype != GRADE_TYPE_SCALE) { $this->scaleid = null; } if (!empty($this->scaleid)) { //do not load scale if already present if (empty($this->scale->id) or $this->scale->id != $this->scaleid) { $this->scale = grade_scale::fetch(array('id' => $this->scaleid)); if (!$this->scale) { debugging('Incorrect scale id: ' . $this->scaleid); $this->scale = null; return null; } $this->scale->load_items(); } // Until scales are uniformly set to min=0 max=count(scaleitems)-1 throughout Moodle, we // stay with the current min=1 max=count(scaleitems) $this->grademax = count($this->scale->scale_items); $this->grademin = 1; } else { $this->scale = null; } return $this->scale; }
/** * Return the scale. * * @return \grade_scale */ public function get_scale() { $scale = \grade_scale::fetch(array('id' => $this->get_scaleid())); $scale->load_items(); return $scale; }
/** * Remove all grade related course data * Grade history is kept * * @param int $courseid The course ID * @param bool $showfeedback If true success notifications will be displayed */ function remove_course_grades($courseid, $showfeedback) { global $DB, $OUTPUT; $fs = get_file_storage(); $strdeleted = get_string('deleted'); $course_category = grade_category::fetch_course_category($courseid); $course_category->delete('coursedelete'); $fs->delete_area_files(get_context_instance(CONTEXT_COURSE, $courseid)->id, 'grade', 'feedback'); if ($showfeedback) { echo $OUTPUT->notification($strdeleted . ' - ' . get_string('grades', 'grades') . ', ' . get_string('items', 'grades') . ', ' . get_string('categories', 'grades'), 'notifysuccess'); } if ($outcomes = grade_outcome::fetch_all(array('courseid' => $courseid))) { foreach ($outcomes as $outcome) { $outcome->delete('coursedelete'); } } $DB->delete_records('grade_outcomes_courses', array('courseid' => $courseid)); if ($showfeedback) { echo $OUTPUT->notification($strdeleted . ' - ' . get_string('outcomes', 'grades'), 'notifysuccess'); } if ($scales = grade_scale::fetch_all(array('courseid' => $courseid))) { foreach ($scales as $scale) { $scale->delete('coursedelete'); } } if ($showfeedback) { echo $OUTPUT->notification($strdeleted . ' - ' . get_string('scales'), 'notifysuccess'); } $DB->delete_records('grade_settings', array('courseid' => $courseid)); if ($showfeedback) { echo $OUTPUT->notification($strdeleted . ' - ' . get_string('settings', 'grades'), 'notifysuccess'); } }
/** * Create a new framework. * * @param array|stdClass $record * @return competency_framework */ public function create_framework($record = null) { $generator = phpunit_util::get_data_generator(); $this->frameworkcount++; $i = $this->frameworkcount; $record = (object) $record; if (!isset($record->shortname)) { $record->shortname = "Framework shortname {$i}"; } if (!isset($record->idnumber)) { $record->idnumber = "frm{$i}"; } if (!isset($record->description)) { $record->description = "Framework {$i} description "; } if (!isset($record->descriptionformat)) { $record->descriptionformat = FORMAT_HTML; } if (!isset($record->visible)) { $record->visible = 1; } if (!isset($record->scaleid)) { if (isset($record->scaleconfiguration)) { throw new coding_exception('Scale configuration must be provided with a scale.'); } if (!$this->scale) { $this->scale = $generator->create_scale(array('scale' => 'A,B,C,D')); } $record->scaleid = $this->scale->id; } if (!isset($record->scaleconfiguration)) { $scale = grade_scale::fetch(array('id' => $record->scaleid)); $values = $scale->load_items(); foreach ($values as $key => $value) { // Add a key (make the first value 1). $values[$key] = array('id' => $key + 1, 'name' => $value); } if (count($values) < 2) { throw new coding_exception('Please provide the scale configuration for one-item scales.'); } $scaleconfig = array(); // Last item is proficient. $item = array_pop($values); array_unshift($scaleconfig, array('id' => $item['id'], 'proficient' => 1)); // Second-last item is default and proficient. $item = array_pop($values); array_unshift($scaleconfig, array('id' => $item['id'], 'scaledefault' => 1, 'proficient' => 1)); array_unshift($scaleconfig, array('scaleid' => $record->scaleid)); $record->scaleconfiguration = json_encode($scaleconfig); } if (is_array($record->scaleconfiguration) || is_object($record->scaleconfiguration)) { // Conveniently encode the config. $record->scaleconfiguration = json_encode($record->scaleconfiguration); } if (!isset($record->contextid)) { $record->contextid = context_system::instance()->id; } $framework = new competency_framework(0, $record); $framework->create(); return $framework; }
/** * Static function returning all local course scales * @return object */ function fetch_all_local($courseid) { return grade_scale::fetch_all(array('courseid' => $courseid)); }
/** * Remove all grade related course data - history is kept * * @global object * @param int $courseid * @param bool $showfeedback print feedback */ function remove_course_grades($courseid, $showfeedback) { global $DB, $OUTPUT; $strdeleted = get_string('deleted'); $course_category = grade_category::fetch_course_category($courseid); $course_category->delete('coursedelete'); if ($showfeedback) { echo $OUTPUT->notification($strdeleted.' - '.get_string('grades', 'grades').', '.get_string('items', 'grades').', '.get_string('categories', 'grades')); } if ($outcomes = grade_outcome::fetch_all(array('courseid'=>$courseid))) { foreach ($outcomes as $outcome) { $outcome->delete('coursedelete'); } } $DB->delete_records('grade_outcomes_courses', array('courseid'=>$courseid)); if ($showfeedback) { echo $OUTPUT->notification($strdeleted.' - '.get_string('outcomes', 'grades')); } if ($scales = grade_scale::fetch_all(array('courseid'=>$courseid))) { foreach ($scales as $scale) { $scale->delete('coursedelete'); } } if ($showfeedback) { echo $OUTPUT->notification($strdeleted.' - '.get_string('scales')); } $DB->delete_records('grade_settings', array('courseid'=>$courseid)); if ($showfeedback) { echo $OUTPUT->notification($strdeleted.' - '.get_string('settings', 'grades')); } }
// already exists in the right scope: use it. $scale_id = key($scale); } else { if (!has_capability('moodle/course:managescales', $context)) { echo $OUTPUT->box(get_string('importskippednomanagescale', 'grades', $csv_data[$imported_headers['outcome_shortname']])); continue; } else { // scale doesn't exists : create it. $scale_data = array('name' => $csv_data[$imported_headers['scale_name']], 'scale' => $csv_data[$imported_headers['scale_items']], 'description' => $csv_data[$imported_headers['scale_description']], 'userid' => $USER->id); if ($local_scope) { $scale_data['courseid'] = $courseid; } else { $scale_data['courseid'] = 0; // 'global' : scale use '0', outcomes use null } $scale = new grade_scale($scale_data); $scale_id = $scale->insert(); } } // add outcome $outcome_data = array('shortname' => $csv_data[$imported_headers['outcome_shortname']], 'fullname' => $csv_data[$imported_headers['outcome_name']], 'scaleid' => $scale_id, 'description' => $csv_data[$imported_headers['outcome_description']], 'usermodified' => $USER->id); if ($local_scope) { $outcome_data['courseid'] = $courseid; } else { $outcome_data['courseid'] = null; // 'global' : scale use '0', outcomes use null } $outcome = new grade_outcome($outcome_data); $outcome_id = $outcome->insert(); $outcome_success_strings = new StdClass(); $outcome_success_strings->name = $outcome_data['fullname'];
/** * Creates new standard (global) scales to replace the legacy workshop ones * * In workshop 1.x, scale field in workshop_elements had the following meaning: * 0 | 2 point Yes/No scale * 1 | 2 point Present/Absent scale * 2 | 2 point Correct/Incorrect scale * 3 | 3 point Good/Poor scale * 4 | 4 point Excellent/Very Poor scale * 5 | 5 point Excellent/Very Poor scale * 6 | 7 point Excellent/Very Poor scale * 7 | Score out of 10 * 8 | Score out of 20 * 9 | Score out of 100 * * @return array (int)oldscale => (int)newscaleid */ function workshopform_accumulative_upgrade_scales() { global $DB, $CFG, $USER; require_once $CFG->libdir . '/gradelib.php'; $sql = 'SELECT DISTINCT scale FROM {workshop_elements_old} WHERE newplugin IS NULL'; $oldscales = $DB->get_records_sql($sql); $newscales = array(); foreach ($oldscales as $oldscale => $whatever) { switch ($oldscale) { case 0: $data = new stdclass(); $data->courseid = 0; $data->userid = $USER->id; $data->name = get_string('scalename0', 'workshopform_accumulative'); $data->scale = implode(',', array(get_string('no'), get_string('yes'))); $data->description = ''; $data->descriptionformat = FORMAT_HTML; $scale = new grade_scale(); grade_scale::set_properties($scale, $data); $newscales[0] = $scale->insert('mod/workshop'); break; case 1: $data = new stdclass(); $data->courseid = 0; $data->userid = $USER->id; $data->name = get_string('scalename1', 'workshopform_accumulative'); $data->scale = implode(',', array(get_string('absent', 'workshopform_accumulative'), get_string('present', 'workshopform_accumulative'))); $data->description = ''; $data->descriptionformat = FORMAT_HTML; $scale = new grade_scale(); grade_scale::set_properties($scale, $data); $newscales[1] = $scale->insert('mod/workshop'); break; case 2: $data = new stdclass(); $data->courseid = 0; $data->userid = $USER->id; $data->name = get_string('scalename2', 'workshopform_accumulative'); $data->scale = implode(',', array(get_string('incorrect', 'workshopform_accumulative'), get_string('correct', 'workshopform_accumulative'))); $data->description = ''; $data->descriptionformat = FORMAT_HTML; $scale = new grade_scale(); grade_scale::set_properties($scale, $data); $newscales[2] = $scale->insert('mod/workshop'); break; case 3: $data = new stdclass(); $data->courseid = 0; $data->userid = $USER->id; $data->name = get_string('scalename3', 'workshopform_accumulative'); $data->scale = implode(',', array('* ' . get_string('poor', 'workshopform_accumulative'), '**', '*** ' . get_string('good', 'workshopform_accumulative'))); $data->description = ''; $data->descriptionformat = FORMAT_HTML; $scale = new grade_scale(); grade_scale::set_properties($scale, $data); $newscales[3] = $scale->insert('mod/workshop'); break; case 4: $data = new stdclass(); $data->courseid = 0; $data->userid = $USER->id; $data->name = get_string('scalename4', 'workshopform_accumulative'); $data->scale = implode(',', array('* ' . get_string('verypoor', 'workshopform_accumulative'), '**', '***', '**** ' . get_string('excellent', 'workshopform_accumulative'))); $data->description = ''; $data->descriptionformat = FORMAT_HTML; $scale = new grade_scale(); grade_scale::set_properties($scale, $data); $newscales[4] = $scale->insert('mod/workshop'); break; case 5: $data = new stdclass(); $data->courseid = 0; $data->userid = $USER->id; $data->name = get_string('scalename5', 'workshopform_accumulative'); $data->scale = implode(',', array('* ' . get_string('verypoor', 'workshopform_accumulative'), '**', '***', '****', '***** ' . get_string('excellent', 'workshopform_accumulative'))); $data->description = ''; $data->descriptionformat = FORMAT_HTML; $scale = new grade_scale(); grade_scale::set_properties($scale, $data); $newscales[5] = $scale->insert('mod/workshop'); break; case 6: $data = new stdclass(); $data->courseid = 0; $data->userid = $USER->id; $data->name = get_string('scalename6', 'workshopform_accumulative'); $data->scale = implode(',', array('* ' . get_string('verypoor', 'workshopform_accumulative'), '**', '***', '****', '*****', '******', '******* ' . get_string('excellent', 'workshopform_accumulative'))); $data->description = ''; $data->descriptionformat = FORMAT_HTML; $scale = new grade_scale(); grade_scale::set_properties($scale, $data); $newscales[6] = $scale->insert('mod/workshop'); break; } } return $newscales; }