Exemple #1
0
 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);
 }