Commit 83cd9b16 authored by Andrew Robert Nicols's avatar Andrew Robert Nicols Committed by Eloy Lafuente
Browse files

MDL-20306 Add course_category idnumber field

parent d87ef085
......@@ -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
......
......@@ -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;
}
}
......@@ -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.<br />Your file upload was NOT successful. Your administrator has been emailed to notify them so they can fix it.<br />Maybe try uploading this file later.';
......
<?xml version="1.0" encoding="UTF-8" ?>
<XMLDB PATH="lib/db" VERSION="20110926" COMMENT="XMLDB file for core Moodle tables"
<XMLDB PATH="lib/db" VERSION="20111007" COMMENT="XMLDB file for core Moodle tables"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="../../lib/xmldb/xmldb.xsd"
>
......@@ -115,8 +115,9 @@
<TABLE NAME="course_categories" COMMENT="Course categories" PREVIOUS="course" NEXT="course_completion_aggr_methd">
<FIELDS>
<FIELD NAME="id" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" SEQUENCE="true" NEXT="name"/>
<FIELD NAME="name" TYPE="char" LENGTH="255" NOTNULL="true" SEQUENCE="false" PREVIOUS="id" NEXT="description"/>
<FIELD NAME="description" TYPE="text" LENGTH="small" NOTNULL="false" SEQUENCE="false" PREVIOUS="name" NEXT="descriptionformat"/>
<FIELD NAME="name" TYPE="char" LENGTH="255" NOTNULL="true" SEQUENCE="false" PREVIOUS="id" NEXT="idnumber"/>
<FIELD NAME="idnumber" TYPE="char" LENGTH="100" NOTNULL="false" SEQUENCE="false" PREVIOUS="name" NEXT="description"/>
<FIELD NAME="description" TYPE="text" LENGTH="small" NOTNULL="false" SEQUENCE="false" PREVIOUS="idnumber" NEXT="descriptionformat"/>
<FIELD NAME="descriptionformat" TYPE="int" LENGTH="2" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" PREVIOUS="description" NEXT="parent"/>
<FIELD NAME="parent" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" PREVIOUS="descriptionformat" NEXT="sortorder"/>
<FIELD NAME="sortorder" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" PREVIOUS="parent" NEXT="coursecount"/>
......
......@@ -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;
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment