Skip to content

Commit

Permalink
MDL-21781 cohort id duplicates detection
Browse files Browse the repository at this point in the history
  • Loading branch information
skodak committed Apr 23, 2010
1 parent 5fa30fb commit a379029
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 11 deletions.
26 changes: 17 additions & 9 deletions cohort/edit_form.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'];
Expand All @@ -46,10 +46,10 @@ function definition () {
$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();
Expand All @@ -59,11 +59,19 @@ function validation($data, $files) {
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;
Expand Down
5 changes: 3 additions & 2 deletions lang/en/cohort.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,11 @@
$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';
Expand Down

0 comments on commit a379029

Please sign in to comment.