From 83cd9b163a9d84a802d98073fac55fd4de0c184e Mon Sep 17 00:00:00 2001 From: Andrew Robert Nicols Date: Fri, 7 Oct 2011 09:35:17 +0100 Subject: [PATCH] MDL-20306 Add course_category idnumber field --- course/editcategory.php | 1 + course/editcategory_form.php | 16 ++++++++++++++++ lang/en/moodle.php | 2 ++ lib/db/install.xml | 7 ++++--- lib/db/upgrade.php | 12 ++++++++++++ 5 files changed, 35 insertions(+), 3 deletions(-) diff --git a/course/editcategory.php b/course/editcategory.php index ceffc63bb89..9752cce1713 100644 --- a/course/editcategory.php +++ b/course/editcategory.php @@ -74,6 +74,7 @@ if ($mform->is_cancelled()) { } else if ($data = $mform->get_data()) { $newcategory = new stdClass(); $newcategory->name = $data->name; + $newcategory->idnumber = $data->idnumber; $newcategory->description_editor = $data->description_editor; $newcategory->parent = $data->parent; // if $data->parent = 0, the new category will be a top-level category diff --git a/course/editcategory_form.php b/course/editcategory_form.php index a708a021496..3e3cfe32fad 100644 --- a/course/editcategory_form.php +++ b/course/editcategory_form.php @@ -35,6 +35,8 @@ class editcategory_form extends moodleform { $mform->addElement('select', 'parent', get_string('parentcategory'), $options); $mform->addElement('text', 'name', get_string('categoryname'), array('size'=>'30')); $mform->addRule('name', get_string('required'), 'required', null); + $mform->addElement('text', 'idnumber', get_string('idnumbercoursecategory'),'maxlength="100" size="10"'); + $mform->addHelpButton('idnumber', 'idnumbercoursecategory'); $mform->addElement('editor', 'description_editor', get_string('description'), null, $editoroptions); $mform->setType('description_editor', PARAM_RAW); if (!empty($CFG->allowcategorythemes)) { @@ -54,5 +56,19 @@ class editcategory_form extends moodleform { $this->add_action_buttons(true, $strsubmit); } + + function validation($data, $files) { + global $DB; + $errors = parent::validation($data, $files); + if (!empty($data['idnumber'])) { + if ($existing = $DB->get_record('course_categories', array('idnumber' => $data['idnumber']))) { + if (!$data['id'] || $existing->id != $data['id']) { + $errors['idnumber']= get_string('idnumbertaken'); + } + } + } + + return $errors; + } } diff --git a/lang/en/moodle.php b/lang/en/moodle.php index a51008a8807..dc1bc8f3a73 100644 --- a/lang/en/moodle.php +++ b/lang/en/moodle.php @@ -216,6 +216,8 @@ $string['categorydeleted'] = 'The category \'{$a}\' was deleted'; $string['categoryduplicate'] = 'A category named \'{$a}\' already exists!'; $string['categorymodifiedcancel'] = 'Category was modified! Please cancel and try again.'; $string['categoryname'] = 'Category name'; +$string['idnumbercoursecategory'] = 'Category ID number'; +$string['idnumbercoursecategory_help'] = 'The ID number of a course category is only used when matching the category against external systems and is not displayed anywhere on the site. If the category has an official code name it may be entered, otherwise the field can be left blank.'; $string['categoryupdated'] = 'The category \'{$a}\' was updated'; $string['city'] = 'City/town'; $string['clambroken'] = 'Your administrator has enabled virus checking for file uploads but has misconfigured something.
Your file upload was NOT successful. Your administrator has been emailed to notify them so they can fix it.
Maybe try uploading this file later.'; diff --git a/lib/db/install.xml b/lib/db/install.xml index c98f8880ed3..e05f3a689e6 100644 --- a/lib/db/install.xml +++ b/lib/db/install.xml @@ -1,5 +1,5 @@ - @@ -115,8 +115,9 @@ - - + + + diff --git a/lib/db/upgrade.php b/lib/db/upgrade.php index 8ab21df0316..03db374a2c2 100644 --- a/lib/db/upgrade.php +++ b/lib/db/upgrade.php @@ -6778,6 +6778,18 @@ FROM upgrade_main_savepoint(true, 2011092800.03); } + if ($oldversion < 2011100700.01) { + // Define field idnumber to be added to course_categories + $table = new xmldb_table('course_categories'); + $field = new xmldb_field('idnumber', XMLDB_TYPE_CHAR, '100', null, null, null, null, 'name'); + + // Conditionally launch add field idnumber + if (!$dbman->field_exists($table,$field)) { + + // Main savepoint reached + upgrade_main_savepoint(true, 2011100700.01); + } + return true; }