MDL-21781 cohort id duplicates detection

This commit is contained in:
Petr Skoda 2010-04-23 09:10:05 +00:00
parent 5fa30fb7a6
commit a379029c54
2 changed files with 20 additions and 11 deletions

View File

@ -24,14 +24,14 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
require_once($CFG->dirroot.'/lib/formslib.php');
require_once($CFG->dirroot . '/lib/formslib.php');
class cohort_edit_form extends moodleform {
// Define the form
function definition () {
global $USER, $CFG, $COURSE;
/**
* Define the form
*/
function definition() {
$mform = $this->_form;
$editoroptions = $this->_customdata['editoroptions'];
@ -46,10 +46,10 @@ class cohort_edit_form extends moodleform {
$mform->addElement('editor', 'description_editor', get_string('description', 'cohort'), null, $editoroptions);
$mform->setType('description_editor', PARAM_RAW);
$mform->addElement('hidden','id');
$mform->addElement('hidden', 'id');
$mform->setType('id', PARAM_INT);
$mform->addElement('hidden','contextid');
$mform->addElement('hidden', 'contextid');
$mform->setType('contextid', PARAM_INT);
$this->add_action_buttons();
@ -59,11 +59,19 @@ class cohort_edit_form extends moodleform {
global $DB;
$errors = parent::validation($data, $files);
$textlib = textlib_get_instance();
$idnumber = trim($data['idnumber']);
if ($data['id']) {
//TODO: validate there are no idnumber
$current = $DB->get_record('cohort', array('id'=>$data['id']), '*', MUST_EXIST);
if ($current->idnumber !== $idnumber) {
if ($DB->record_exists('cohort', array('idnumber'=>$idnumber))) {
$errors['idnumber'] = get_string('duplicateidnumber', 'cohort');
}
}
} else {
if ($DB->record_exists('cohort', array('idnumber'=>$idnumber))) {
$errors['idnumber'] = get_string('duplicateidnumber', 'cohort');
}
}
return $errors;

View File

@ -37,10 +37,11 @@ $string['component'] = 'Source';
$string['currentusers'] = 'Current users';
$string['currentusersmatching'] = 'Current users matching';
$string['delcohort'] = 'Delete cohort';
$string['delconfirm'] = 'Do you really want to delete cohort $a?';
$string['delconfirm'] = 'Do you really want to delete cohort \'{$a}\'?';
$string['description'] = 'Description';
$string['duplicateidnumber'] = 'Cohort with the same ID number already exists';
$string['editcohort'] = 'Edit cohort';
$string['idnumber'] = 'ID number';
$string['idnumber'] = 'Cohort ID';
$string['memberscount'] = 'Cohort size';
$string['name'] = 'Name';
$string['nocomponent'] = 'Created manually';