mirror of
https://github.com/moodle/moodle.git
synced 2025-04-22 00:42:54 +02:00
MDL-10105 idnumber uniqueness tested before insert in UI now - both modedit and item edit pages
This commit is contained in:
parent
489a965500
commit
602433133e
@ -294,6 +294,15 @@
|
||||
error("Data submitted is invalid.");
|
||||
}
|
||||
|
||||
//sync idnumber with grade_item
|
||||
if ($grade_item = grade_item::fetch(array('itemtype'=>'mod', 'itemmodule'=>$fromform->modulename,
|
||||
'iteminstance'=>$fromform->instance, 'itemnumber'=>0, 'courseid'=>$COURSE->id))) {
|
||||
if ($grade_item->idnumber != $fromform->idnumber) {
|
||||
$grade_item->idnumber = $fromform->idnumber;
|
||||
$grade_item->update();
|
||||
}
|
||||
}
|
||||
|
||||
// add outcomes if requested
|
||||
if ($outcomes = grade_outcome::fetch_all_available($COURSE->id)) {
|
||||
foreach($outcomes as $outcome) {
|
||||
|
@ -66,6 +66,32 @@ class moodleform_mod extends moodleform {
|
||||
}
|
||||
}
|
||||
|
||||
// form verification
|
||||
function validation($data) {
|
||||
global $COURSE;
|
||||
|
||||
$errors = array();
|
||||
|
||||
$grade_item = grade_item::fetch(array('itemtype'=>'mod', 'itemmodule'=>$data['modulename'],
|
||||
'iteminstance'=>$data['instance'], 'itemnumber'=>0, 'courseid'=>$COURSE->id));
|
||||
if ($data['coursemodule']) {
|
||||
$cm = get_record('course_modules', 'id', $data['coursemodule']);
|
||||
} else {
|
||||
$cm = null;
|
||||
}
|
||||
|
||||
// verify the idnumber
|
||||
if (!grade_verify_idnumber($data['cmidnumber'], $grade_item, $cm)) {
|
||||
$errors['cmidnumber'] = get_string('idnumbertaken');
|
||||
}
|
||||
|
||||
if (count($errors) == 0) {
|
||||
return true;
|
||||
} else {
|
||||
return $errors;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Load in existing data as form defaults. Usually new entry defaults are stored directly in
|
||||
* form definition (new entry form); this function is used to load in data where values
|
||||
|
@ -171,7 +171,24 @@ class edit_item_form extends moodleform {
|
||||
|
||||
/// perform extra validation before submission
|
||||
function validation($data){
|
||||
$errors= array();
|
||||
$errors = array();
|
||||
|
||||
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;
|
||||
}
|
||||
if (!grade_verify_idnumber($data['idnumber'], $grade_item, $cm)) {
|
||||
$errors['idnumber'] = get_string('idnumbertaken');
|
||||
}
|
||||
}
|
||||
|
||||
if (array_key_exists('calculation', $data) and $data['calculation'] != '') {
|
||||
$grade_item = new grade_item(array('id'=>$data['id'], 'itemtype'=>$data['itemtype'], 'courseid'=>$data['courseid']));
|
||||
|
@ -104,6 +104,17 @@ class edit_outcomeitem_form extends moodleform {
|
||||
function validation($data){
|
||||
$errors= array();
|
||||
|
||||
if (array_key_exists('idnumber', $data)) {
|
||||
if ($data['id']) {
|
||||
$grade_item = new grade_item(array('id'=>$data['id'], 'courseid'=>$data['courseid']));
|
||||
} else {
|
||||
$grade_item = null;
|
||||
}
|
||||
if (!grade_verify_idnumber($data['idnumber'], $grade_item, null)) {
|
||||
$errors['idnumber'] = get_string('idnumbertaken');
|
||||
}
|
||||
}
|
||||
|
||||
if (0 == count($errors)){
|
||||
return true;
|
||||
} else {
|
||||
|
@ -752,6 +752,7 @@ $string['htmlformat'] = 'Pretty HTML format';
|
||||
$string['icqnumber'] = 'ICQ number';
|
||||
$string['idnumber'] = 'ID number';
|
||||
$string['idnumbercourse'] = 'Course ID number';
|
||||
$string['idnumbertaken'] = 'This ID number is already taken';
|
||||
$string['imagealt'] = 'Picture description';
|
||||
$string['import'] = 'Import';
|
||||
$string['importactivities'] = 'Import activities from another course';
|
||||
|
@ -360,6 +360,42 @@ function grade_update_outcomes($source, $courseid, $itemtype, $itemmodule, $item
|
||||
|
||||
/***** END OF PUBLIC API *****/
|
||||
|
||||
|
||||
/**
|
||||
* Verify nwe value of idnumber - checks for uniqueness of new idnubmers, old are kept intact
|
||||
* @param string idnumber string (with magic quotes)
|
||||
* @param object $cm used for course module idnumbers and items attached to modules
|
||||
* @param object $gradeitem is item idnumber
|
||||
* @return boolean true means idnumber ok
|
||||
*/
|
||||
function grade_verify_idnumber($idnumber, $grade_item=null, $cm=null) {
|
||||
if ($idnumber == '') {
|
||||
//we allow empty idnumbers
|
||||
return true;
|
||||
}
|
||||
|
||||
// keep existing even when not unique
|
||||
if ($cm and $cm->idnumber == $idnumber) {
|
||||
return true;
|
||||
} else if ($grade_item and $grade_item->idnumber == $idnumber) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (get_records('course_modules', 'idnumber', $idnumber)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (get_records('grade_items', 'idnumber', $idnumber)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Force final grade recalculation in all course items
|
||||
* @param int $courseid
|
||||
*/
|
||||
function grade_force_full_regrading($courseid) {
|
||||
set_field('grade_items', 'needsupdate', 1, 'courseid', $courseid);
|
||||
}
|
||||
|
@ -115,20 +115,31 @@ class mod_choice_mod_form extends moodleform_mod {
|
||||
}
|
||||
|
||||
function validation($data){
|
||||
$choices=0;
|
||||
$errors = parent::validation($data);
|
||||
if ($errors === true) {
|
||||
$errors = array();
|
||||
}
|
||||
|
||||
$choices = 0;
|
||||
foreach ($data['option'] as $option){
|
||||
if (trim($option)!=''){
|
||||
if (trim($option) != ''){
|
||||
$choices++;
|
||||
}
|
||||
}
|
||||
if ($choices>1){
|
||||
return true;
|
||||
} elseif ($choices==0) {
|
||||
return array('option[0]'=>get_string('fillinatleastoneoption', 'choice'));
|
||||
} else {
|
||||
return array('option[1]'=>get_string('fillinatleastoneoption', 'choice'));
|
||||
|
||||
if ($choices < 1) {
|
||||
$errors['option[0]'] = get_string('fillinatleastoneoption', 'choice');
|
||||
}
|
||||
|
||||
if ($choices < 2) {
|
||||
$errors['option[1]'] = get_string('fillinatleastoneoption', 'choice');
|
||||
}
|
||||
|
||||
if (count($errors) == 0) {
|
||||
return true;
|
||||
} else {
|
||||
return $errors;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
@ -324,13 +324,20 @@ class mod_lesson_mod_form extends moodleform_mod {
|
||||
* @return array
|
||||
**/
|
||||
function validation($data) {
|
||||
$errors = array();
|
||||
$errors = parent::validation($data);
|
||||
if ($errors === true) {
|
||||
$errors = array();
|
||||
}
|
||||
|
||||
if (empty($data['maxtime']) and !empty($data['timed'])) {
|
||||
$errors['timedgrp'] = get_string('err_numeric', 'form');
|
||||
}
|
||||
|
||||
return $errors;
|
||||
if (count($errors) == 0) {
|
||||
return true;
|
||||
} else {
|
||||
return $errors;
|
||||
}
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
@ -304,7 +304,11 @@ class mod_quiz_mod_form extends moodleform_mod {
|
||||
}
|
||||
|
||||
function validation($data){
|
||||
$errors = array();
|
||||
$errors = parent::validation($data);
|
||||
if ($errors === true) {
|
||||
$errors = array();
|
||||
}
|
||||
|
||||
// Check open and close times are consistent.
|
||||
if ($data['timeopen'] != 0 && $data['timeclose'] != 0 && $data['timeclose'] < $data['timeopen']) {
|
||||
$errors['timeclose'] = get_string('closebeforeopen', 'quiz');
|
||||
@ -344,7 +348,12 @@ class mod_quiz_mod_form extends moodleform_mod {
|
||||
$errors["feedbacktext[$i]"] = get_string('feedbackerrorjunkinfeedback', 'quiz', $i + 1);
|
||||
}
|
||||
}
|
||||
return $errors;
|
||||
|
||||
if (count($errors) == 0) {
|
||||
return true;
|
||||
} else {
|
||||
return $errors;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -232,12 +232,21 @@ class mod_scorm_mod_form extends moodleform_mod {
|
||||
}
|
||||
|
||||
function validation($data) {
|
||||
$errors = parent::validation($data);
|
||||
if ($errors === true) {
|
||||
$errors = array();
|
||||
}
|
||||
|
||||
$validate = scorm_validate($data);
|
||||
|
||||
if ($validate->result) {
|
||||
if (!$validate->result) {
|
||||
$errors = $errors + $validate->errors;
|
||||
}
|
||||
|
||||
if (count($errors) == 0) {
|
||||
return true;
|
||||
} else {
|
||||
return $validate->errors;
|
||||
return $errors;
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user