MDL-10105 some more idnumber fixes
This commit is contained in:
@@ -94,17 +94,40 @@ class edit_calculation_form extends moodleform {
|
||||
function validation($data){
|
||||
$errors = array();
|
||||
|
||||
//first validate and store the new idnubmers
|
||||
$mform =& $this->_form;
|
||||
|
||||
//first validate and store the new idnumbers
|
||||
if ($this->noidnumbers and $this->showing) {
|
||||
foreach ($this->noidnumbers as $item) {
|
||||
if (!empty($data['idnumber_'.$item->id])) {
|
||||
if(!$item->add_idnumber(stripslashes($data['idnumber_'.$item->id]))) {
|
||||
$errors['idnumber_'.$item->id] = get_string('error');
|
||||
foreach ($this->noidnumbers as $grade_item) {
|
||||
$idnumber = 'idnumber_'.$grade_item->id;
|
||||
if (!empty($data[$idnumber])) {
|
||||
if ($grade_item->itemtype == 'mod') {
|
||||
$cm = get_coursemodule_from_instance($grade_item->itemmodule, $grade_item->iteminstance, $grade_item->courseid);
|
||||
} else {
|
||||
$cm = null;
|
||||
}
|
||||
|
||||
if (!grade_verify_idnumber($data[$idnumber], $grade_item, $cm)) {
|
||||
$errors[$idnumber] = get_string('idnumbertaken');
|
||||
continue;
|
||||
}
|
||||
|
||||
if (empty($grade_item->idnumber) and !$grade_item->add_idnumber(stripslashes($data['idnumber_'.$grade_item->id]))) {
|
||||
$errors[$idnumber] = get_string('error');
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
// lock the adding field if idnumber already present or just changed
|
||||
if (!empty($grade_item->idnumber)) {
|
||||
$el =& $mform->getElement($idnumber);
|
||||
$el->setValue($grade_item->idnumber);
|
||||
$mform->hardFreeze($idnumber);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// check the calculation formula
|
||||
if ($data['calculation'] != '') {
|
||||
$grade_item = grade_item::fetch(array('id'=>$data['id'], 'courseid'=>$data['courseid']));
|
||||
$result = $grade_item->validate_formula(stripslashes($data['calculation']));
|
||||
@@ -112,6 +135,7 @@ class edit_calculation_form extends moodleform {
|
||||
$errors['calculation'] = $result;
|
||||
}
|
||||
}
|
||||
|
||||
if (0 == count($errors)){
|
||||
return true;
|
||||
} else {
|
||||
|
||||
@@ -365,11 +365,10 @@ class grade_item extends grade_object {
|
||||
|
||||
/**
|
||||
* Set idnumber of grade item, updates also course_modules table
|
||||
* @param string $idnumber
|
||||
* @param string $idnumber (without magic quotes)
|
||||
* @return boolean success
|
||||
*/
|
||||
function add_idnumber($idnumber) {
|
||||
//TODO: add uniqueness checking
|
||||
if (!empty($this->idnumber)) {
|
||||
return false;
|
||||
}
|
||||
@@ -381,10 +380,7 @@ class grade_item extends grade_object {
|
||||
if (!empty($cm->idnumber)) {
|
||||
return false;
|
||||
}
|
||||
$ncm = new object();
|
||||
$ncm->id = $cm->id;
|
||||
$ncm->idnumber = $idnumber();
|
||||
if(update_record('course_modules', $ncm)) {
|
||||
if (set_field('course_modules', 'idnumber', addslashes($idnumber), 'id', $cm->id)) {
|
||||
$this->idnumber = $idnumber;
|
||||
return $this->update();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user