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; } }
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); }
/** * 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; }
/** * 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; }
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; }
$strscale = get_string('scale'); $strstandardscale = get_string('scalesstandard'); $strcustomscales = get_string('scalescustom'); $strname = get_string('name'); $strdelete = get_string('delete'); $stredit = get_string('edit'); $srtcreatenewscale = get_string('scalescustomcreate'); $strused = get_string('used'); $stredit = get_string('edit'); switch ($action) { case 'delete': if (!confirm_sesskey()) { break; } $scaleid = required_param('scaleid', PARAM_INT); if (!($scale = grade_scale::fetch(array('id' => $scaleid)))) { break; } if (empty($scale->courseid)) { require_capability('moodle/course:managescales', get_context_instance(CONTEXT_SYSTEM)); } else { if ($scale->courseid != $courseid) { print_error('invalidcourseid'); } } if (!$scale->can_delete()) { break; } $deleteconfirmed = optional_param('deleteconfirmed', 0, PARAM_BOOL); if (!$deleteconfirmed) { $strdeletescale = get_string('delete') . ' ' . get_string('scale');
/** * 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; }
/** * Return the scale. * * @return \grade_scale */ public function get_scale() { $scale = \grade_scale::fetch(array('id' => $this->get_scaleid())); $scale->load_items(); return $scale; }
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; }
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); }
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); }
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; }
/** * */ 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 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->setType('itemname', PARAM_TEXT); $mform->addElement('text', 'iteminfo', get_string('iteminfo', 'grades')); $mform->addHelpButton('iteminfo', 'iteminfo', 'grades'); $mform->setType('iteminfo', PARAM_TEXT); $mform->addElement('text', 'idnumber', get_string('idnumbermod')); $mform->addHelpButton('idnumber', 'idnumbermod'); $mform->setType('idnumber', PARAM_RAW); if (!empty($item->id)) { $gradeitem = new grade_item(array('id' => $item->id, 'courseid' => $item->courseid)); // 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_grades() && !$gradeitem->is_external_item()) { // Set a message so the user knows why they can not alter the grade type or scale. if ($gradeitem->gradetype == GRADE_TYPE_SCALE) { $gradesexistmsg = get_string('modgradecantchangegradetyporscalemsg', 'grades'); } else { $gradesexistmsg = get_string('modgradecantchangegradetypemsg', 'grades'); } $gradesexisthtml = '<div class=\'alert\'>' . $gradesexistmsg . '</div>'; $mform->addElement('static', 'gradesexistmsg', '', $gradesexisthtml); } } // Manual grade items cannot have grade type GRADE_TYPE_NONE. $options = array(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->addHelpButton('gradetype', 'gradetype', 'grades'); $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 possible 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->addHelpButton('scaleid', 'typescale', 'grades'); $mform->disabledIf('scaleid', 'gradetype', 'noteq', GRADE_TYPE_SCALE); $choices = array(); $choices[''] = get_string('choose'); $choices['no'] = get_string('no'); $choices['yes'] = get_string('yes'); $mform->addElement('select', 'rescalegrades', get_string('modgraderescalegrades', 'grades'), $choices); $mform->addHelpButton('rescalegrades', 'modgraderescalegrades', 'grades'); $mform->disabledIf('rescalegrades', 'gradetype', 'noteq', GRADE_TYPE_VALUE); $mform->addElement('text', 'grademax', get_string('grademax', 'grades')); $mform->addHelpButton('grademax', 'grademax', 'grades'); $mform->disabledIf('grademax', 'gradetype', 'noteq', GRADE_TYPE_VALUE); $mform->setType('grademax', PARAM_RAW); if ((bool) get_config('moodle', 'grade_report_showmin')) { $mform->addElement('text', 'grademin', get_string('grademin', 'grades')); $mform->addHelpButton('grademin', 'grademin', 'grades'); $mform->disabledIf('grademin', 'gradetype', 'noteq', GRADE_TYPE_VALUE); $mform->setType('grademin', PARAM_RAW); } $mform->addElement('text', 'gradepass', get_string('gradepass', 'grades')); $mform->addHelpButton('gradepass', 'gradepass', 'grades'); $mform->disabledIf('gradepass', 'gradetype', 'eq', GRADE_TYPE_NONE); $mform->disabledIf('gradepass', 'gradetype', 'eq', GRADE_TYPE_TEXT); $mform->setType('gradepass', PARAM_RAW); $mform->addElement('text', 'multfactor', get_string('multfactor', 'grades')); $mform->addHelpButton('multfactor', 'multfactor', 'grades'); $mform->setAdvanced('multfactor'); $mform->disabledIf('multfactor', 'gradetype', 'eq', GRADE_TYPE_NONE); $mform->disabledIf('multfactor', 'gradetype', 'eq', GRADE_TYPE_TEXT); $mform->setType('multfactor', PARAM_RAW); $mform->addElement('text', 'plusfactor', get_string('plusfactor', 'grades')); $mform->addHelpButton('plusfactor', 'plusfactor', 'grades'); $mform->setAdvanced('plusfactor'); $mform->disabledIf('plusfactor', 'gradetype', 'eq', GRADE_TYPE_NONE); $mform->disabledIf('plusfactor', 'gradetype', 'eq', GRADE_TYPE_TEXT); $mform->setType('plusfactor', PARAM_RAW); /// 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->addHelpButton('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', 'decimals', get_string('decimalpoints', 'grades'), $options); $mform->addHelpButton('decimals', 'decimalpoints', 'grades'); $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 if ($item->cancontrolvisibility) { // advcheckbox is not compatible with disabledIf! $mform->addElement('checkbox', 'hidden', get_string('hidden', 'grades')); $mform->addElement('date_time_selector', 'hiddenuntil', get_string('hiddenuntil', 'grades'), array('optional' => true)); $mform->disabledIf('hidden', 'hiddenuntil[off]', 'notchecked'); } else { $mform->addElement('static', 'hidden', get_string('hidden', 'grades'), get_string('componentcontrolsvisibility', 'grades')); // Unset hidden to avoid data override. unset($item->hidden); } $mform->addHelpButton('hidden', 'hidden', 'grades'); /// locking $mform->addElement('advcheckbox', 'locked', get_string('locked', 'grades')); $mform->addHelpButton('locked', 'locked', 'grades'); $mform->addElement('date_time_selector', 'locktime', get_string('locktime', 'grades'), array('optional' => true)); $mform->disabledIf('locktime', 'gradetype', 'eq', GRADE_TYPE_NONE); /// parent category related settings $mform->addElement('header', 'headerparent', get_string('parentcategory', 'grades')); $mform->addElement('advcheckbox', 'weightoverride', get_string('adjustedweight', 'grades')); $mform->addHelpButton('weightoverride', 'weightoverride', 'grades'); $mform->disabledIf('weightoverride', 'gradetype', 'eq', GRADE_TYPE_NONE); $mform->disabledIf('weightoverride', 'gradetype', 'eq', GRADE_TYPE_TEXT); $mform->addElement('text', 'aggregationcoef2', get_string('weight', 'grades')); $mform->addHelpButton('aggregationcoef2', 'weight', 'grades'); $mform->setType('aggregationcoef2', PARAM_RAW); $mform->disabledIf('aggregationcoef2', 'weightoverride'); $mform->disabledIf('aggregationcoef2', 'gradetype', 'eq', GRADE_TYPE_NONE); $mform->disabledIf('aggregationcoef2', 'gradetype', 'eq', GRADE_TYPE_TEXT); $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); }