Merge branch 'wip-MDL-26747' of git://github.com/sammarshallou/moodle
[moodle.git] / lib / form / modgrade.php
blob0abb9465f5987721a9dd5d1f6739ae1f523a533b
1 <?php
2 global $CFG;
3 require_once "$CFG->libdir/form/select.php";
5 /**
6 * HTML class for a drop down element to select the grade for an activity,
7 * used in mod update form
9 * @author Jamie Pratt
10 * @access public
12 class MoodleQuickForm_modgrade extends MoodleQuickForm_select{
14 var $_hidenograde = false;
16 /**
17 * Class constructor
19 * @param string Select name attribute
20 * @param mixed Label(s) for the select
21 * @param mixed Either a typical HTML attribute string or an associative array
22 * @param mixed $options ignored
23 * @access public
24 * @return void
26 function MoodleQuickForm_modgrade($elementName=null, $elementLabel=null, $attributes=null, $hidenograde=false)
28 HTML_QuickForm_element::HTML_QuickForm_element($elementName, $elementLabel, $attributes, null);
29 $this->_type = 'modgrade';
30 $this->_hidenograde = $hidenograde;
32 } //end constructor
34 /**
35 * Called by HTML_QuickForm whenever form event is made on this element
37 * @param string $event Name of event
38 * @param mixed $arg event arguments
39 * @param object $caller calling object
40 * @since 1.0
41 * @access public
42 * @return mixed
44 function onQuickFormEvent($event, $arg, &$caller)
46 global $COURSE, $CFG, $OUTPUT;
47 switch ($event) {
48 case 'createElement':
49 // Need to call superclass first because we want the constructor
50 // to run.
51 $result = parent::onQuickFormEvent($event, $arg, $caller);
52 $strscale = get_string('scale');
53 $strscales = get_string('scales');
54 $scales = get_scales_menu($COURSE->id);
55 foreach ($scales as $i => $scalename) {
56 $grades[-$i] = $strscale .': '. $scalename;
58 if (!$this->_hidenograde) {
59 $grades[0] = get_string('nograde');
61 for ($i=100; $i>=1; $i--) {
62 $grades[$i] = $i;
64 $this->load($grades);
65 //TODO: rewrite mod grading support in modforms
66 return $result;
68 return parent::onQuickFormEvent($event, $arg, $caller);