timeline: if a section is set to hidden and the user is not capable of editing a...
[moodle-blog-course-format.git] / lib / form / modgrade.php
blobfbf178921585cb0d165fa625479021c1d80e8705
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;
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 $linkobject = '<span class="helplink"><img height="17" width="17" alt="'.$strscales.'" src="'.$CFG->pixpath .'/help.gif" /></span>';
66 $this->setHelpButton(array('/course/scales.php?id='. $COURSE->id .'&amp;list=true', 'ratingscales',
67 $linkobject, 400, 500, $strscales, 'none', true), 'link_to_popup_window');
68 return $result;
70 return parent::onQuickFormEvent($event, $arg, $caller);