PageRenderTime 40ms CodeModel.GetById 7ms RepoModel.GetById 0ms app.codeStats 0ms

/question/category_form.php

https://bitbucket.org/synergylearning/campusconnect
PHP | 85 lines | 42 code | 15 blank | 28 comment | 5 complexity | 94deb3cf1d4b756ef70de6ef75f4e4c9 MD5 | raw file
Possible License(s): MPL-2.0-no-copyleft-exception, LGPL-3.0, GPL-3.0, LGPL-2.1, Apache-2.0, BSD-3-Clause, AGPL-3.0
  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. * Defines the form for editing question categories.
  18. *
  19. * @package moodlecore
  20. * @subpackage questionbank
  21. * @copyright 2007 Jamie Pratt me@jamiep.org
  22. * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  23. */
  24. defined('MOODLE_INTERNAL') || die();
  25. require_once($CFG->libdir.'/formslib.php');
  26. /**
  27. * Form for editing qusetions categories (name, description, etc.)
  28. *
  29. * @copyright 2007 Jamie Pratt me@jamiep.org
  30. * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  31. */
  32. class question_category_edit_form extends moodleform {
  33. protected function definition() {
  34. global $CFG, $DB;
  35. $mform = $this->_form;
  36. $contexts = $this->_customdata['contexts'];
  37. $currentcat = $this->_customdata['currentcat'];
  38. $mform->addElement('header', 'categoryheader', get_string('addcategory', 'question'));
  39. $questioncategoryel = $mform->addElement('questioncategory', 'parent', get_string('parentcategory', 'question'),
  40. array('contexts'=>$contexts, 'top'=>true, 'currentcat'=>$currentcat, 'nochildrenof'=>$currentcat));
  41. $mform->setType('parent', PARAM_SEQUENCE);
  42. if (question_is_only_toplevel_category_in_context($currentcat)) {
  43. $mform->hardFreeze('parent');
  44. }
  45. $mform->addHelpButton('parent', 'parentcategory', 'question');
  46. $mform->addElement('text', 'name', get_string('name'),'maxlength="254" size="50"');
  47. $mform->setDefault('name', '');
  48. $mform->addRule('name', get_string('categorynamecantbeblank', 'question'), 'required', null, 'client');
  49. $mform->setType('name', PARAM_TEXT);
  50. $mform->addElement('editor', 'info', get_string('categoryinfo', 'question'),
  51. array('rows' => 10), array('noclean' => 1));
  52. $mform->setDefault('info', '');
  53. $mform->setType('info', PARAM_RAW);
  54. $this->add_action_buttons(false, get_string('addcategory', 'question'));
  55. $mform->addElement('hidden', 'id', 0);
  56. $mform->setType('id', PARAM_INT);
  57. }
  58. public function set_data($current) {
  59. if (is_object($current)) {
  60. $current = (array) $current;
  61. }
  62. if (!empty($current['info'])) {
  63. $current['info'] = array('text' => $current['info'],
  64. 'infoformat' => $current['infoformat']);
  65. } else {
  66. $current['info'] = array('text' => '', 'infoformat' => FORMAT_HTML);
  67. }
  68. parent::set_data($current);
  69. }
  70. }