Merge branch 'MDL-80715-main' of https://github.com/ferranrecio/moodle
[moodle.git] / lib / form / questioncategory.php
blob788090bd0f0b8a1e208cfe79c029e8bad167f018
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.
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/>.
18 /**
19 * Drop down for question categories.
21 * Contains HTML class for a drop down element to select a question category.
23 * @package core_form
24 * @copyright 2007 Tim Hunt
25 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
28 global $CFG;
29 use qbank_managecategories\helper;
30 require_once("$CFG->libdir/form/selectgroups.php");
31 require_once("$CFG->libdir/questionlib.php");
33 /**
34 * Drop down for question categories.
36 * HTML class for a drop down element to select a question category.
38 * @package core_form
39 * @category form
40 * @copyright 2007 Tim Hunt
41 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
43 class MoodleQuickForm_questioncategory extends MoodleQuickForm_selectgroups {
44 /** @var array default options for question categories */
45 var $_options = array('top'=>false, 'currentcat'=>0, 'nochildrenof' => -1);
47 /**
48 * Constructor
50 * @param string $elementName Select name attribute
51 * @param mixed $elementLabel Label(s) for the select
52 * @param array $options additional options. Recognised options are courseid, published and
53 * only_editable, corresponding to the arguments of question_category_options
54 * from moodlelib.php.
55 * @param mixed $attributes Either a typical HTML attribute string or an associative array
57 public function __construct($elementName = null, $elementLabel = null, $options = null, $attributes = null) {
58 parent::__construct($elementName, $elementLabel, array(), $attributes);
59 $this->_type = 'questioncategory';
60 if (is_array($options)) {
61 $this->_options = $options + $this->_options;
62 $this->loadArrayOptGroups(
63 helper::question_category_options($this->_options['contexts'], $this->_options['top'],
64 $this->_options['currentcat'], false, $this->_options['nochildrenof'], false));
68 /**
69 * Old syntax of class constructor. Deprecated in PHP7.
71 * @deprecated since Moodle 3.1
73 public function MoodleQuickForm_questioncategory($elementName = null, $elementLabel = null, $options = null, $attributes = null) {
74 debugging('Use of class name as constructor is deprecated', DEBUG_DEVELOPER);
75 self::__construct($elementName, $elementLabel, $options, $attributes);