Trabla: Moodle: Course Category create/edit form - add field yes/no
Solving:
1. Create database column
ALTER TABLE mdl_course_categories ADD COLUMN myfield smallint DEFAULT 0;--defaultNO
UPDATE mdl_course_categories SET myfield = 0;
ALTER TABLE mdl_course_categories ALTER COLUMN myfield SET NOT NULL;
2. Modify course category form .php script
/moodle/course/editcategory_form.php
$mform->addElement('text', 'idnumber', get_string('idnumbercoursecategory'),'maxlength="100" size="10"');
$mform->addHelpButton('idnumber', 'idnumbercoursecategory');
//Start: This is my field!!!
$mform->addElement('selectyesno', 'myfield ', "This is my course yes/no field" );
$mform->setDefault('myfield ', 0); //default NO
//End: This is my field!!!
$mform->addElement('editor', 'description_editor', get_string('description'), null, $editoroptions);
$mform->setType('description_editor', PARAM_RAW);
3. Modify course category processing .php script
/moodle/course/editcategory.php
$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
//Start: This is my field!!!
$newcategory->myfield = $data->myfield ;
//End: This is my field!!!
if (isset($data->theme) && !empty($CFG->allowcategorythemes)) {
$newcategory->theme = $data->theme;
}
Result:
No comments:
Post a Comment