MDL-10234
[moodle-linuxchix.git] / lib / form / questioncategory.php
blob04a90596dd14d9f55baeaf88fe2caee335904f64
1 <?php
2 /**
3 * A moodle form field type for question categories.
5 * @copyright &copy; 2006 The Open University
6 * @author T.J.Hunt@open.ac.uk
7 * @license http://www.gnu.org/copyleft/gpl.html GNU Public License
8 * @package moodleforms
9 *//** */
11 global $CFG;
12 require_once("$CFG->libdir/form/select.php");
14 /**
15 * HTML class for a drop down element to select a question category.
16 * @access public
18 class MoodleQuickForm_questioncategory extends MoodleQuickForm_select {
20 /**
21 * Constructor
23 * @param string $elementName Select name attribute
24 * @param mixed $elementLabel Label(s) for the select
25 * @param mixed $attributes Either a typical HTML attribute string or an associative array
26 * @param array $options additional options. Recognised options are courseid, published and
27 * only_editable, corresponding to the arguments of question_category_options from moodlelib.php.
28 * @access public
29 * @return void
31 function MoodleQuickForm_questioncategory($elementName = null,
32 $elementLabel = null, $attributes = null, $options = null) {
33 HTML_QuickForm_element::HTML_QuickForm_element($elementName, $elementLabel, $attributes, null);
35 global $COURSE;
36 $this->_type = 'questioncategory';
37 if (!empty($options['courseid'])) {
38 $this->_courseid = $options['courseid'];
39 } else {
40 $this->_courseid = $COURSE->id;
42 if (!empty($options['published'])) {
43 $this->_published = $options['published'];
44 } else {
45 $this->_published = false;
47 if (!empty($options['only_editable'])) {
48 $this->_only_editable = $options['only_editable'];
49 } else {
50 $this->_only_editable = false;
54 /**
55 * Called by HTML_QuickForm whenever form event is made on this element
57 * @param string $event Name of event
58 * @param mixed $arg event arguments
59 * @param object $caller calling object
60 * @access public
61 * @return mixed
63 function onQuickFormEvent($event, $arg, &$caller) {
64 switch ($event) {
65 case 'createElement':
66 $this->load(question_category_options($this->_courseid, $this->_published, $this->_only_editable));
67 break;
69 return parent::onQuickFormEvent($event, $arg, $caller);