[ Index ] |
PHP Cross Reference of Unnamed Project |
[Summary view] [Print] [Text view]
1 <?php 2 // This file is part of Moodle - http://moodle.org/ 3 // 4 // Moodle is free software: you can redistribute it and/or modify 5 // it under the terms of the GNU General Public License as published by 6 // the Free Software Foundation, either version 3 of the License, or 7 // (at your option) any later version. 8 // 9 // Moodle is distributed in the hope that it will be useful, 10 // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 // GNU General Public License for more details. 13 // 14 // You should have received a copy of the GNU General Public License 15 // along with Moodle. If not, see <http://www.gnu.org/licenses/>. 16 17 /** 18 * Edit category form. 19 * 20 * @package core_course 21 * @copyright 2002 onwards Martin Dougiamas (http://dougiamas.com) 22 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 23 */ 24 25 defined('MOODLE_INTERNAL') || die; 26 27 require_once($CFG->libdir.'/formslib.php'); 28 require_once($CFG->libdir.'/coursecatlib.php'); 29 30 /** 31 * Edit category form. 32 * 33 * @package core_course 34 * @copyright 2002 onwards Martin Dougiamas (http://dougiamas.com) 35 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 36 */ 37 class core_course_editcategory_form extends moodleform { 38 39 /** 40 * The form definition. 41 */ 42 public function definition() { 43 global $CFG, $DB; 44 $mform = $this->_form; 45 $categoryid = $this->_customdata['categoryid']; 46 $parent = $this->_customdata['parent']; 47 48 // Get list of categories to use as parents, with site as the first one. 49 $options = array(); 50 if (has_capability('moodle/category:manage', context_system::instance()) || $parent == 0) { 51 $options[0] = get_string('top'); 52 } 53 if ($categoryid) { 54 // Editing an existing category. 55 $options += coursecat::make_categories_list('moodle/category:manage', $categoryid); 56 if (empty($options[$parent])) { 57 // Ensure the the category parent has been included in the options. 58 $options[$parent] = $DB->get_field('course_categories', 'name', array('id'=>$parent)); 59 } 60 $strsubmit = get_string('savechanges'); 61 } else { 62 // Making a new category. 63 $options += coursecat::make_categories_list('moodle/category:manage'); 64 $strsubmit = get_string('createcategory'); 65 } 66 67 $mform->addElement('select', 'parent', get_string('parentcategory'), $options); 68 69 $mform->addElement('text', 'name', get_string('categoryname'), array('size' => '30')); 70 $mform->addRule('name', get_string('required'), 'required', null); 71 $mform->setType('name', PARAM_TEXT); 72 73 $mform->addElement('text', 'idnumber', get_string('idnumbercoursecategory'), 'maxlength="100" size="10"'); 74 $mform->addHelpButton('idnumber', 'idnumbercoursecategory'); 75 $mform->setType('idnumber', PARAM_RAW); 76 77 $mform->addElement('editor', 'description_editor', get_string('description'), null, 78 $this->get_description_editor_options()); 79 80 if (!empty($CFG->allowcategorythemes)) { 81 $themes = array(''=>get_string('forceno')); 82 $allthemes = get_list_of_themes(); 83 foreach ($allthemes as $key => $theme) { 84 if (empty($theme->hidefromselector)) { 85 $themes[$key] = get_string('pluginname', 'theme_'.$theme->name); 86 } 87 } 88 $mform->addElement('select', 'theme', get_string('forcetheme'), $themes); 89 } 90 91 $mform->addElement('hidden', 'id', 0); 92 $mform->setType('id', PARAM_INT); 93 $mform->setDefault('id', $categoryid); 94 95 $this->add_action_buttons(true, $strsubmit); 96 } 97 98 /** 99 * Returns the description editor options. 100 * @return array 101 */ 102 public function get_description_editor_options() { 103 global $CFG; 104 $context = $this->_customdata['context']; 105 $itemid = $this->_customdata['itemid']; 106 return array( 107 'maxfiles' => EDITOR_UNLIMITED_FILES, 108 'maxbytes' => $CFG->maxbytes, 109 'trusttext' => true, 110 'context' => $context, 111 'subdirs' => file_area_contains_subdirs($context, 'coursecat', 'description', $itemid), 112 ); 113 } 114 115 /** 116 * Validates the data submit for this form. 117 * 118 * @param array $data An array of key,value data pairs. 119 * @param array $files Any files that may have been submit as well. 120 * @return array An array of errors. 121 */ 122 public function validation($data, $files) { 123 global $DB; 124 $errors = parent::validation($data, $files); 125 if (!empty($data['idnumber'])) { 126 if ($existing = $DB->get_record('course_categories', array('idnumber' => $data['idnumber']))) { 127 if (!$data['id'] || $existing->id != $data['id']) { 128 $errors['idnumber'] = get_string('categoryidnumbertaken', 'error'); 129 } 130 } 131 } 132 return $errors; 133 } 134 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Thu Aug 11 10:00:09 2016 | Cross-referenced by PHPXref 0.7.1 |