mirror of
https://github.com/moodle/moodle.git
synced 2025-08-04 08:26:37 +02:00
MDL-62708 question: Add idnumbers to question and question category
This commit is contained in:
parent
6902f39141
commit
6189fda47f
24 changed files with 502 additions and 13 deletions
|
@ -63,6 +63,10 @@ class question_category_edit_form extends moodleform {
|
|||
$mform->setDefault('info', '');
|
||||
$mform->setType('info', PARAM_RAW);
|
||||
|
||||
$mform->addElement('text', 'idnumber', get_string('idnumber', 'question'), 'maxlength="100" size="10"');
|
||||
$mform->addHelpButton('idnumber', 'idnumber', 'question');
|
||||
$mform->setType('idnumber', PARAM_RAW);
|
||||
|
||||
$this->add_action_buttons(false, get_string('addcategory', 'question'));
|
||||
|
||||
$mform->addElement('hidden', 'id', 0);
|
||||
|
@ -81,4 +85,33 @@ class question_category_edit_form extends moodleform {
|
|||
}
|
||||
parent::set_data($current);
|
||||
}
|
||||
|
||||
/**
|
||||
* Validation.
|
||||
*
|
||||
* @param array $data
|
||||
* @param array $files
|
||||
* @return array the errors that were found
|
||||
*/
|
||||
public function validation($data, $files) {
|
||||
global $DB;
|
||||
|
||||
$errors = parent::validation($data, $files);
|
||||
|
||||
// Add field validation check for duplicate idnumber.
|
||||
list($parentid, $contextid) = explode(',', $data['parent']);
|
||||
if (((string) $data['idnumber'] !== '') && !empty($contextid)) {
|
||||
$conditions = 'contextid = ? AND idnumber = ?';
|
||||
$params = [$contextid, $data['idnumber']];
|
||||
if (!empty($data['id'])) {
|
||||
$conditions .= ' AND id <> ?';
|
||||
$params[] = $data['id'];
|
||||
}
|
||||
if ($DB->record_exists_select('question_categories', $conditions, $params)) {
|
||||
$errors['idnumber'] = get_string('idnumbertaken', 'error');
|
||||
}
|
||||
}
|
||||
|
||||
return $errors;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue