2009-07-07 02:26:36 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
// This file is part of Moodle - http://moodle.org/
|
|
|
|
//
|
|
|
|
// Moodle is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU General Public License as published by
|
|
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
|
|
// (at your option) any later version.
|
|
|
|
//
|
|
|
|
// Moodle is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU General Public License
|
|
|
|
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
2007-10-10 06:34:20 +00:00
|
|
|
|
2010-05-13 02:02:05 +00:00
|
|
|
if (!defined('MOODLE_INTERNAL')) {
|
|
|
|
die('Direct access to this script is forbidden.'); /// It must be included from a Moodle page
|
|
|
|
}
|
|
|
|
|
2007-07-02 18:26:11 +00:00
|
|
|
require_once $CFG->libdir.'/formslib.php';
|
|
|
|
|
2007-07-02 08:57:04 +00:00
|
|
|
class edit_item_form extends moodleform {
|
2008-06-03 16:10:57 +00:00
|
|
|
private $displayoptions;
|
2007-10-07 10:51:52 +00:00
|
|
|
|
2007-07-02 08:57:04 +00:00
|
|
|
function definition() {
|
2008-06-03 16:10:57 +00:00
|
|
|
global $COURSE, $CFG, $DB;
|
2007-07-02 18:26:11 +00:00
|
|
|
|
2007-07-02 08:57:04 +00:00
|
|
|
$mform =& $this->_form;
|
2007-07-02 18:26:11 +00:00
|
|
|
|
2009-05-07 08:39:29 +00:00
|
|
|
$item = $this->_customdata['current'];
|
|
|
|
|
2007-07-02 18:26:11 +00:00
|
|
|
/// visible elements
|
|
|
|
$mform->addElement('header', 'general', get_string('gradeitem', 'grades'));
|
|
|
|
|
2007-07-02 08:57:04 +00:00
|
|
|
$mform->addElement('text', 'itemname', get_string('itemname', 'grades'));
|
|
|
|
$mform->addElement('text', 'iteminfo', get_string('iteminfo', 'grades'));
|
2008-03-03 10:25:37 +00:00
|
|
|
$mform->setHelpButton('iteminfo', array('iteminfo', get_string('iteminfo', 'grades'), 'grade'), true);
|
2007-08-06 18:52:12 +00:00
|
|
|
|
2008-01-30 16:34:04 +00:00
|
|
|
$mform->addElement('text', 'idnumber', get_string('idnumbermod'));
|
2010-05-18 06:06:52 +00:00
|
|
|
$mform->addHelpButton('idnumber', 'idnumbermod');
|
2007-07-02 18:26:11 +00:00
|
|
|
|
|
|
|
$options = array(GRADE_TYPE_NONE=>get_string('typenone', 'grades'),
|
2007-07-24 14:26:05 +00:00
|
|
|
GRADE_TYPE_VALUE=>get_string('typevalue', 'grades'),
|
|
|
|
GRADE_TYPE_SCALE=>get_string('typescale', 'grades'),
|
|
|
|
GRADE_TYPE_TEXT=>get_string('typetext', 'grades'));
|
|
|
|
|
2007-07-02 18:26:11 +00:00
|
|
|
$mform->addElement('select', 'gradetype', get_string('gradetype', 'grades'), $options);
|
2008-03-03 10:25:37 +00:00
|
|
|
$mform->setHelpButton('gradetype', array('gradetype', get_string('gradetype', 'grades'), 'grade'), true);
|
2007-07-02 18:26:11 +00:00
|
|
|
$mform->setDefault('gradetype', GRADE_TYPE_VALUE);
|
|
|
|
|
2007-08-06 09:42:47 +00:00
|
|
|
//$mform->addElement('text', 'calculation', get_string('calculation', 'grades'));
|
|
|
|
//$mform->disabledIf('calculation', 'gradetype', 'eq', GRADE_TYPE_TEXT);
|
|
|
|
//$mform->disabledIf('calculation', 'gradetype', 'eq', GRADE_TYPE_NONE);
|
2007-07-02 18:26:11 +00:00
|
|
|
|
|
|
|
$options = array(0=>get_string('usenoscale', 'grades'));
|
2009-05-07 08:39:29 +00:00
|
|
|
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()) {
|
2007-07-02 18:26:11 +00:00
|
|
|
foreach ($scales as $scale) {
|
2009-05-07 08:39:29 +00:00
|
|
|
$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');
|
2007-07-02 18:26:11 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
$mform->addElement('select', 'scaleid', get_string('scale'), $options);
|
2008-03-03 10:25:37 +00:00
|
|
|
$mform->setHelpButton('scaleid', array('scaleid', get_string('scaleid', 'grades'), 'grade'), true);
|
2007-07-12 09:20:08 +00:00
|
|
|
$mform->disabledIf('scaleid', 'gradetype', 'noteq', GRADE_TYPE_SCALE);
|
2007-07-02 18:26:11 +00:00
|
|
|
|
2007-07-02 08:57:04 +00:00
|
|
|
$mform->addElement('text', 'grademax', get_string('grademax', 'grades'));
|
2008-03-03 10:25:37 +00:00
|
|
|
$mform->setHelpButton('grademax', array('grademax', get_string('grademax', 'grades'), 'grade'), true);
|
2007-07-12 09:20:08 +00:00
|
|
|
$mform->disabledIf('grademax', 'gradetype', 'noteq', GRADE_TYPE_VALUE);
|
2007-07-02 18:26:11 +00:00
|
|
|
|
2007-07-02 08:57:04 +00:00
|
|
|
$mform->addElement('text', 'grademin', get_string('grademin', 'grades'));
|
2008-03-03 10:25:37 +00:00
|
|
|
$mform->setHelpButton('grademin', array('grademin', get_string('grademin', 'grades'), 'grade'), true);
|
2007-07-12 09:20:08 +00:00
|
|
|
$mform->disabledIf('grademin', 'gradetype', 'noteq', GRADE_TYPE_VALUE);
|
2007-07-02 18:26:11 +00:00
|
|
|
|
2007-07-02 08:57:04 +00:00
|
|
|
$mform->addElement('text', 'gradepass', get_string('gradepass', 'grades'));
|
2008-03-03 10:25:37 +00:00
|
|
|
$mform->setHelpButton('gradepass', array('gradepass', get_string('gradepass', 'grades'), 'grade'), true);
|
2007-07-02 18:26:11 +00:00
|
|
|
$mform->disabledIf('gradepass', 'gradetype', 'eq', GRADE_TYPE_NONE);
|
2007-07-12 09:20:08 +00:00
|
|
|
$mform->disabledIf('gradepass', 'gradetype', 'eq', GRADE_TYPE_TEXT);
|
2007-07-02 18:26:11 +00:00
|
|
|
|
2007-07-02 08:57:04 +00:00
|
|
|
$mform->addElement('text', 'multfactor', get_string('multfactor', 'grades'));
|
2008-03-03 10:25:37 +00:00
|
|
|
$mform->setHelpButton('multfactor', array('multfactor', get_string('multfactor', 'grades'), 'grade'), true);
|
2007-08-31 22:42:05 +00:00
|
|
|
$mform->setAdvanced('multfactor');
|
2007-07-02 18:26:11 +00:00
|
|
|
$mform->disabledIf('multfactor', 'gradetype', 'eq', GRADE_TYPE_NONE);
|
2007-07-12 09:20:08 +00:00
|
|
|
$mform->disabledIf('multfactor', 'gradetype', 'eq', GRADE_TYPE_TEXT);
|
2007-07-02 18:26:11 +00:00
|
|
|
|
2007-07-02 08:57:04 +00:00
|
|
|
$mform->addElement('text', 'plusfactor', get_string('plusfactor', 'grades'));
|
2008-03-03 10:25:37 +00:00
|
|
|
$mform->setHelpButton('plusfactor', array('plusfactor', get_string('plusfactor', 'grades'), 'grade'), true);
|
2007-08-31 22:42:05 +00:00
|
|
|
$mform->setAdvanced('plusfactor');
|
2007-07-02 18:26:11 +00:00
|
|
|
$mform->disabledIf('plusfactor', 'gradetype', 'eq', GRADE_TYPE_NONE);
|
2007-07-12 09:20:08 +00:00
|
|
|
$mform->disabledIf('plusfactor', 'gradetype', 'eq', GRADE_TYPE_TEXT);
|
2007-07-18 19:29:32 +00:00
|
|
|
|
2007-10-07 10:51:52 +00:00
|
|
|
/// grade display prefs
|
2007-10-08 23:09:10 +00:00
|
|
|
$default_gradedisplaytype = grade_get_setting($COURSE->id, 'displaytype', $CFG->grade_displaytype);
|
2009-01-08 08:53:20 +00:00
|
|
|
$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);
|
|
|
|
|
2007-10-08 23:09:10 +00:00
|
|
|
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);
|
2008-03-03 10:25:37 +00:00
|
|
|
$mform->setHelpButton('display', array('gradedisplaytype', get_string('gradedisplaytype', 'grades'), 'grade'), true);
|
2007-09-19 14:28:26 +00:00
|
|
|
|
2007-10-08 23:09:10 +00:00
|
|
|
$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);
|
2010-05-24 15:35:03 +00:00
|
|
|
$mform->addHelpButton('decimals', 'decimalpoints', 'grades');
|
2007-10-08 23:09:10 +00:00
|
|
|
$mform->setDefault('decimals', -1);
|
2007-10-07 10:51:52 +00:00
|
|
|
$mform->disabledIf('decimals', 'display', 'eq', GRADE_DISPLAY_TYPE_LETTER);
|
2007-10-08 23:09:10 +00:00
|
|
|
if ($default_gradedisplaytype == GRADE_DISPLAY_TYPE_LETTER) {
|
|
|
|
$mform->disabledIf('decimals', 'display', "eq", GRADE_DISPLAY_TYPE_DEFAULT);
|
|
|
|
}
|
2007-09-25 14:40:49 +00:00
|
|
|
|
2007-08-06 20:51:09 +00:00
|
|
|
/// hiding
|
2008-02-18 19:10:44 +00:00
|
|
|
// advcheckbox is not compatible with disabledIf!
|
2007-08-06 20:51:09 +00:00
|
|
|
$mform->addElement('checkbox', 'hidden', get_string('hidden', 'grades'));
|
2007-08-07 16:29:53 +00:00
|
|
|
$mform->setHelpButton('hidden', array('hidden', get_string('hidden', 'grades'), 'grade'));
|
2007-08-06 20:51:09 +00:00
|
|
|
$mform->addElement('date_time_selector', 'hiddenuntil', get_string('hiddenuntil', 'grades'), array('optional'=>true));
|
2007-08-07 16:29:53 +00:00
|
|
|
$mform->setHelpButton('hiddenuntil', array('hiddenuntil', get_string('hiddenuntil', 'grades'), 'grade'));
|
2007-08-09 16:19:06 +00:00
|
|
|
$mform->disabledIf('hidden', 'hiddenuntil[off]', 'notchecked');
|
2007-08-06 20:51:09 +00:00
|
|
|
|
|
|
|
/// locking
|
2007-07-10 18:08:24 +00:00
|
|
|
$mform->addElement('advcheckbox', 'locked', get_string('locked', 'grades'));
|
2007-08-07 16:29:53 +00:00
|
|
|
$mform->setHelpButton('locked', array('locked', get_string('locked', 'grades'), 'grade'));
|
2007-07-02 08:57:04 +00:00
|
|
|
|
|
|
|
$mform->addElement('date_time_selector', 'locktime', get_string('locktime', 'grades'), array('optional'=>true));
|
2008-02-27 18:46:20 +00:00
|
|
|
$mform->setHelpButton('locktime', array('lockedafter', get_string('locktime', 'grades'), 'grade'));
|
2007-07-02 18:26:11 +00:00
|
|
|
$mform->disabledIf('locktime', 'gradetype', 'eq', GRADE_TYPE_NONE);
|
2007-07-02 08:57:04 +00:00
|
|
|
|
2007-11-15 08:29:12 +00:00
|
|
|
/// parent category related settings
|
|
|
|
$mform->addElement('header', 'headerparent', get_string('parentcategory', 'grades'));
|
|
|
|
|
|
|
|
$options = array();
|
|
|
|
$coefstring = '';
|
|
|
|
$categories = grade_category::fetch_all(array('courseid'=>$COURSE->id));
|
2008-10-10 07:18:19 +00:00
|
|
|
|
2007-11-15 08:29:12 +00:00
|
|
|
foreach ($categories as $cat) {
|
|
|
|
$cat->apply_forced_settings();
|
|
|
|
$options[$cat->id] = $cat->get_name();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (count($categories) > 1) {
|
2007-11-16 07:36:18 +00:00
|
|
|
$mform->addElement('select', 'parentcategory', get_string('gradecategory', 'grades'), $options);
|
2007-11-15 08:29:12 +00:00
|
|
|
}
|
|
|
|
|
2007-07-02 18:26:11 +00:00
|
|
|
/// hidden params
|
2007-07-02 08:57:04 +00:00
|
|
|
$mform->addElement('hidden', 'id', 0);
|
|
|
|
$mform->setType('id', PARAM_INT);
|
|
|
|
|
2007-07-18 19:29:32 +00:00
|
|
|
$mform->addElement('hidden', 'courseid', $COURSE->id);
|
2007-07-02 08:57:04 +00:00
|
|
|
$mform->setType('courseid', PARAM_INT);
|
|
|
|
|
2007-07-18 19:29:32 +00:00
|
|
|
$mform->addElement('hidden', 'itemtype', 'manual'); // all new items are manual only
|
2007-07-02 08:57:04 +00:00
|
|
|
$mform->setType('itemtype', PARAM_ALPHA);
|
|
|
|
|
2007-07-16 18:58:09 +00:00
|
|
|
/// add return tracking info
|
|
|
|
$gpr = $this->_customdata['gpr'];
|
|
|
|
$gpr->add_mform_elements($mform);
|
|
|
|
|
2007-11-15 17:32:31 +00:00
|
|
|
/// 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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2007-07-02 08:57:04 +00:00
|
|
|
//-------------------------------------------------------------------------------
|
|
|
|
// buttons
|
|
|
|
$this->add_action_buttons();
|
2009-05-07 08:39:29 +00:00
|
|
|
//-------------------------------------------------------------------------------
|
|
|
|
$this->set_data($item);
|
2007-07-02 08:57:04 +00:00
|
|
|
}
|
2007-07-02 18:26:11 +00:00
|
|
|
|
|
|
|
|
|
|
|
/// tweak the form - depending on existing data
|
|
|
|
function definition_after_data() {
|
2007-07-18 19:29:32 +00:00
|
|
|
global $CFG, $COURSE;
|
2007-07-02 18:26:11 +00:00
|
|
|
|
|
|
|
$mform =& $this->_form;
|
|
|
|
|
|
|
|
if ($id = $mform->getElementValue('id')) {
|
|
|
|
$grade_item = grade_item::fetch(array('id'=>$id));
|
2007-07-18 19:29:32 +00:00
|
|
|
|
2007-08-31 22:42:05 +00:00
|
|
|
if (!$grade_item->is_raw_used()) {
|
2007-07-18 19:29:32 +00:00
|
|
|
$mform->removeElement('plusfactor');
|
|
|
|
$mform->removeElement('multfactor');
|
2007-08-31 22:42:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if ($grade_item->is_outcome_item()) {
|
2007-10-07 10:51:52 +00:00
|
|
|
// we have to prevent incompatible modifications of outcomes if outcomes disabled
|
2007-08-01 12:40:38 +00:00
|
|
|
$mform->removeElement('grademax');
|
|
|
|
$mform->removeElement('grademin');
|
|
|
|
$mform->removeElement('gradetype');
|
2007-10-07 10:51:52 +00:00
|
|
|
$mform->removeElement('display');
|
|
|
|
$mform->removeElement('decimals');
|
2007-08-01 12:40:38 +00:00
|
|
|
$mform->hardFreeze('scaleid');
|
|
|
|
|
|
|
|
} else {
|
2007-10-30 11:40:50 +00:00
|
|
|
if ($grade_item->is_external_item()) {
|
2007-08-01 12:40:38 +00:00
|
|
|
// following items are set up from modules and should not be overrided by user
|
|
|
|
$mform->hardFreeze('itemname,idnumber,gradetype,grademax,grademin,scaleid');
|
2007-08-06 09:42:47 +00:00
|
|
|
//$mform->removeElement('calculation');
|
2007-08-01 12:40:38 +00:00
|
|
|
}
|
2007-07-18 19:29:32 +00:00
|
|
|
}
|
2007-11-13 15:08:59 +00:00
|
|
|
|
2009-04-29 14:35:47 +00:00
|
|
|
// if we wanted to change parent of existing item - we would have to verify there are no circular references in parents!!!
|
|
|
|
if ($mform->elementExists('parentcategory')) {
|
|
|
|
$mform->hardFreeze('parentcategory');
|
|
|
|
}
|
|
|
|
|
|
|
|
$parent_category = $grade_item->get_parent_category();
|
|
|
|
$parent_category->apply_forced_settings();
|
|
|
|
|
|
|
|
if (!$parent_category->is_aggregationcoef_used()) {
|
2007-11-15 08:29:12 +00:00
|
|
|
if ($mform->elementExists('aggregationcoef')) {
|
|
|
|
$mform->removeElement('aggregationcoef');
|
|
|
|
}
|
2007-07-18 19:29:32 +00:00
|
|
|
|
2007-10-20 19:12:33 +00:00
|
|
|
} else {
|
2009-04-29 14:35:47 +00:00
|
|
|
$coefstring = $grade_item->get_coefstring();
|
2007-11-15 08:29:12 +00:00
|
|
|
|
2009-04-29 14:35:47 +00:00
|
|
|
if ($coefstring !== '') {
|
|
|
|
if ($coefstring == 'aggregationcoefextrasum') {
|
|
|
|
// advcheckbox is not compatible with disabledIf!
|
|
|
|
$element =& $mform->createElement('checkbox', 'aggregationcoef', get_string($coefstring, 'grades'));
|
2009-04-16 07:16:44 +00:00
|
|
|
} else {
|
2009-04-29 14:35:47 +00:00
|
|
|
$element =& $mform->createElement('text', 'aggregationcoef', get_string($coefstring, 'grades'));
|
2007-11-15 08:29:12 +00:00
|
|
|
}
|
2009-04-29 14:35:47 +00:00
|
|
|
if ($mform->elementExists('parentcategory')) {
|
|
|
|
$mform->insertElementBefore($element, 'parentcategory');
|
|
|
|
} else {
|
|
|
|
$mform->insertElementBefore($element, 'id');
|
2007-10-20 19:12:33 +00:00
|
|
|
}
|
2010-05-21 13:46:28 +00:00
|
|
|
$mform->addHelpButton('aggregationcoef', $coefstring, 'grades');
|
2007-07-18 19:29:32 +00:00
|
|
|
}
|
2009-04-29 14:35:47 +00:00
|
|
|
|
|
|
|
$mform->disabledIf('aggregationcoef', 'parentcategory', 'eq', $parent_category->id);
|
2007-07-18 19:29:32 +00:00
|
|
|
}
|
|
|
|
|
2007-11-13 15:08:59 +00:00
|
|
|
if ($category = $grade_item->get_item_category()) {
|
|
|
|
if ($category->aggregation == GRADE_AGGREGATE_SUM) {
|
|
|
|
if ($mform->elementExists('gradetype')) {
|
|
|
|
$mform->hardFreeze('gradetype');
|
|
|
|
}
|
|
|
|
if ($mform->elementExists('grademin')) {
|
|
|
|
$mform->hardFreeze('grademin');
|
|
|
|
}
|
|
|
|
if ($mform->elementExists('grademax')) {
|
|
|
|
$mform->hardFreeze('grademax');
|
|
|
|
}
|
|
|
|
if ($mform->elementExists('scaleid')) {
|
|
|
|
$mform->removeElement('scaleid');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-07-18 19:29:32 +00:00
|
|
|
} else {
|
|
|
|
// all new items are manual, children of course category
|
|
|
|
$mform->removeElement('plusfactor');
|
|
|
|
$mform->removeElement('multfactor');
|
2007-11-15 08:29:12 +00:00
|
|
|
}
|
2007-07-18 19:29:32 +00:00
|
|
|
|
2007-11-15 08:29:12 +00:00
|
|
|
// no parent header for course category
|
|
|
|
if (!$mform->elementExists('aggregationcoef') and !$mform->elementExists('parentcategory')) {
|
|
|
|
$mform->removeElement('headerparent');
|
2007-07-02 18:26:11 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// perform extra validation before submission
|
2007-11-23 22:15:07 +00:00
|
|
|
function validation($data, $files) {
|
2008-01-14 22:46:03 +00:00
|
|
|
global $COURSE;
|
|
|
|
|
2007-11-23 22:15:07 +00:00
|
|
|
$errors = parent::validation($data, $files);
|
2007-08-02 10:38:18 +00:00
|
|
|
|
|
|
|
if (array_key_exists('idnumber', $data)) {
|
|
|
|
if ($data['id']) {
|
|
|
|
$grade_item = new grade_item(array('id'=>$data['id'], 'courseid'=>$data['courseid']));
|
|
|
|
if ($grade_item->itemtype == 'mod') {
|
|
|
|
$cm = get_coursemodule_from_instance($grade_item->itemmodule, $grade_item->iteminstance, $grade_item->courseid);
|
|
|
|
} else {
|
|
|
|
$cm = null;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
$grade_item = null;
|
|
|
|
$cm = null;
|
|
|
|
}
|
2008-01-14 22:46:03 +00:00
|
|
|
if (!grade_verify_idnumber($data['idnumber'], $COURSE->id, $grade_item, $cm)) {
|
2007-08-02 10:38:18 +00:00
|
|
|
$errors['idnumber'] = get_string('idnumbertaken');
|
|
|
|
}
|
|
|
|
}
|
2007-07-02 18:26:11 +00:00
|
|
|
|
2007-10-29 20:35:05 +00:00
|
|
|
if (array_key_exists('gradetype', $data) and $data['gradetype'] == GRADE_TYPE_SCALE) {
|
|
|
|
if (empty($data['scaleid'])) {
|
2007-11-26 04:10:08 +00:00
|
|
|
$errors['scaleid'] = get_string('missingscale', 'grades');
|
2007-10-29 20:35:05 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-07-10 18:08:24 +00:00
|
|
|
if (array_key_exists('grademin', $data) and array_key_exists('grademax', $data)) {
|
|
|
|
if ($data['grademax'] == $data['grademin'] or $data['grademax'] < $data['grademin']) {
|
2007-11-26 04:10:08 +00:00
|
|
|
$errors['grademin'] = get_string('incorrectminmax', 'grades');
|
|
|
|
$errors['grademax'] = get_string('incorrectminmax', 'grades');
|
2007-07-10 18:08:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-11-23 22:15:07 +00:00
|
|
|
return $errors;
|
2007-07-02 18:26:11 +00:00
|
|
|
}
|
|
|
|
|
2007-07-02 08:57:04 +00:00
|
|
|
}
|
2009-11-01 12:11:29 +00:00
|
|
|
|