}
}
+/**
+ * Prints a help button about a scale
+ *
+ * @deprecated since Moodle 2.0
+ *
+ * @global object
+ * @param id $courseid
+ * @param object $scale
+ * @param boolean $return If set to true returns rather than echo's
+ * @return string|bool Depending on value of $return
+ */
+function print_scale_menu_helpbutton($courseid, $scale, $return=false) {
+ // debugging('print_scale_menu_helpbutton() has been deprecated. Please change your code to use $OUTPUT->help_button($scaleselectmenu).');
+ global $OUTPUT;
+
+ $helpbutton = help_button::make_scale_menu($courseid, $scale);
+
+ $output = $OUTPUT->help_button($helpbutton);
+
+ if ($return) {
+ return $output;
+ } else {
+ echo $output;
+ }
+}
+
+
+/**
+ * Prints time limit value selector
+ *
+ * @deprecated since Moodle 2.0
+ *
+ * Uses {@link choose_from_menu()} to generate HTML
+ * @see choose_from_menu()
+ *
+ * @global object
+ * @param int $timelimit default
+ * @param string $unit
+ * @param string $name
+ * @param boolean $return If set to true returns rather than echo's
+ * @return string|bool Depending on value of $return
+ */
+function print_timer_selector($timelimit = 0, $unit = '', $name = 'timelimit', $return=false) {
+ throw new coding_exception('print_timer_selector is completely deprecated. Please use $OUTPUT->select_menu($selectmenu) instead');
+}
+
+/**
+ * Prints form items with the names $hour and $minute
+ *
+ * @deprecated since Moodle 2.0
+ *
+ * @param string $hour fieldname
+ * @param string $minute fieldname
+ * @param int $currenttime A default timestamp in GMT
+ * @param int $step minute spacing
+ * @param boolean $return If set to true returns rather than echo's
+ * @return string|bool Depending on value of $return
+ */
+function print_time_selector($hour, $minute, $currenttime=0, $step=5, $return=false) {
+ // debugging('print_time_selector() has been deprecated. Please change your code to use $OUTPUT->select_menu($timeselector).');
+ global $OUTPUT;
+ $hourselector = moodle_select_menu::make_time_selector('hours', $hour, $currenttime);
+ $minuteselector = moodle_select_menu::make_time_selector('minutes', $minute, $currenttime, $step);
+
+ $output = $OUTPUT->select_menu($hourselector) . $OUTPUT->select_menu($minuteselector);
+
+ if ($return) {
+ return $output;
+ } else {
+ echo $output;
+ }
+}
+
+/**
+ * Prints form items with the names $day, $month and $year
+ *
+ * @deprecated since Moodle 2.0
+ *
+ * @param string $day fieldname
+ * @param string $month fieldname
+ * @param string $year fieldname
+ * @param int $currenttime A default timestamp in GMT
+ * @param boolean $return If set to true returns rather than echo's
+ * @return string|bool Depending on value of $return
+ */
+function print_date_selector($day, $month, $year, $currenttime=0, $return=false) {
+
+ // debugging('print_date_selector() has been deprecated. Please change your code to use $OUTPUT->select_menu($dateselector).');
+ global $OUTPUT;
+
+ $dayselector = moodle_select_menu::make_time_selector('days', $day, $currenttime);
+ $monthselector = moodle_select_menu::make_time_selector('months', $month, $currenttime);
+ $yearselector = moodle_select_menu::make_time_selector('years', $year, $currenttime);
+
+ $output = $OUTPUT->select_menu($dayselector) . $OUTPUT->select_menu($monthselector) . $OUTPUT->select_menu($yearselector);
+
+ if ($return) {
+ return $output;
+ } else {
+ echo $output;
+ }
+}
+
throw new coding_exception('The 3rd param to $OUTPUT->confirm must be either a URL (string/moodle_url) or a html_form object.');
}
- if (empty($continue->button->label)) {
- $continue->button->label = get_string('yes');
+ if (empty($continue->button->text)) {
+ $continue->button->text = get_string('yes');
}
- if (empty($cancel->button->label)) {
- $cancel->button->label = get_string('no');
+ if (empty($cancel->button->text)) {
+ $cancel->button->text = get_string('no');
}
$output = $this->box_start('generalbox', 'notice');
$buttonattributes = array('class' => $form->button->get_classes_string(),
'type' => 'submit',
- 'value' => $form->button->label,
+ 'value' => $form->button->text,
'disabled' => $form->button->disabled,
'id' => $form->button->id);
$html = '';
if (!empty($selectmenu->label)) {
- $html .= $this->output_tag('label', array('for' => $selectmenu->name), $selectmenu->label);
+ $html .= $this->label($selectmenu->label);
}
$html .= $this->output_start_tag('select', $attributes) . "\n";
if (!is_array($values)) {
var_dump($values);
}
- foreach ($values as $value => $label) {
+ foreach ($values as $value => $display) {
$attributes = array('value' => $value);
if ((string) $value == (string) $selectmenu->selectedvalue ||
$html .= $this->output_start_tag('option', $attributes);
- if ($label === '') {
+ if ($display === '') {
$html .= $value;
} else {
- $html .= $label;
+ $html .= $display;
}
$html .= $this->output_end_tag('option');
$html .= $this->output_end_tag('optgroup');
}
} else {
- foreach ($selectmenu->options as $value => $label) {
+ foreach ($selectmenu->options as $value => $display) {
$attributes = array('value' => $value);
if ((string) $value == (string) $selectmenu->selectedvalue ||
(is_array($selectmenu->selectedvalue) && in_array($value, $selectmenu->selectedvalue))) {
$attributes['selected'] = 'selected';
}
- $html .= ' ' . $this->output_tag('option', $attributes, s($label)) . "\n";
+ $html .= ' ' . $this->output_tag('option', $attributes, s($display)) . "\n";
}
}
$html .= $this->output_end_tag('select') . "\n";
return $html;
}
- // TODO choose_from_menu_nested
+ /**
+ * Outputs a <label> element.
+ * @param html_label $label A html_label object
+ * @return HTML fragment
+ */
+ public function label($label) {
+ $label->prepare();
+ $this->prepare_event_handlers($label);
+ return $this->output_tag('label', array('for' => $label->for, 'class' => $label->get_classes_string()), $label->text);
+ }
// TODO choose_from_radio
$form = new html_form();
$form->url = $link;
$form->values = $link->params();
- $form->button->label = get_string('continue');
+ $form->button->text = get_string('continue');
$form->method = 'get';
return $this->output_tag('div', array('class' => 'continuebutton') , $this->button($form));
*/
class moodle_select_menu extends moodle_html_component {
/**
- * @var array the choices to show in the menu. An array $value => $label.
+ * @var array the choices to show in the menu. An array $value => $display.
*/
public $options;
/**
*/
public $name;
/**
- * @var string $label The label for that component
+ * @var mixed $label The label for that component. String or html_label object
*/
public $label;
/**
$this->nothinglabel = '';
}
+ if (!($this->label instanceof html_label)) {
+ $label = new html_label();
+ $label->text = $this->label;
+ $label->for = $this->name;
+ $this->label = $label;
+ }
+
$this->add_class('select');
parent::prepare();
public static function make_yes_no($name, $selected) {
return self::make(array(0 => get_string('no'), 1 => get_string('yes')), $name, $selected);
}
+
+ /**
+ * This is a shortcut for making an hour selector menu.
+ * @param string $type The type of selector (years, months, days, hours, minutes)
+ * @param string $name fieldname
+ * @param int $currenttime A default timestamp in GMT
+ * @param int $step minute spacing
+ * @return moodle_select_menu A menu initialised with hour options.
+ */
+ public static function make_time_selector($type, $name, $currenttime=0, $step=5) {
+
+ if (!$currenttime) {
+ $currenttime = time();
+ }
+ $currentdate = usergetdate($currenttime);
+ $userdatetype = $type;
+
+ switch ($type) {
+ case 'years':
+ for ($i=1970; $i<=2020; $i++) {
+ $timeunits[$i] = $i;
+ }
+ $userdatetype = 'year';
+ break;
+ case 'months':
+ for ($i=1; $i<=12; $i++) {
+ $timeunits[$i] = userdate(gmmktime(12,0,0,$i,15,2000), "%B");
+ }
+ $userdatetype = 'month';
+ break;
+ case 'days':
+ for ($i=1; $i<=31; $i++) {
+ $timeunits[$i] = $i;
+ }
+ $userdatetype = 'mday';
+ break;
+ case 'hours':
+ for ($i=0; $i<=23; $i++) {
+ $timeunits[$i] = sprintf("%02d",$i);
+ }
+ break;
+ case 'minutes':
+ if ($step != 1) {
+ $currentdate['minutes'] = ceil($currentdate['minutes']/$step)*$step;
+ }
+
+ for ($i=0; $i<=59; $i+=$step) {
+ $timeunits[$i] = sprintf("%02d",$i);
+ }
+ break;
+ default:
+ throw new coding_exception("Time type $type is not supported by moodle_select_menu::make_time_selector().");
+ }
+
+ $timerselector = self::make($timeunits, $name, $currentdate[$userdatetype]);
+ $timerselector->label = new html_label();
+ $timerselector->label->text = get_string(substr($type, -1), 'form');
+ $timerselector->label->for = "menu$timerselector->name";
+ $timerselector->label->add_class('accesshide');
+ $timerselector->nothinglabel = '';
+
+ return $timerselector;
+ }
}
+/**
+ * This class represents how a block appears on a page.
+ *
+ * @copyright 2009 Nicolas Connault
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ * @since Moodle 2.0
+ */
+class html_label extends moodle_html_component {
+ /**
+ * @var string $text The text to display in the label
+ */
+ public $text;
+ /**
+ * @var string $for The name of the form field this label is associated with
+ */
+ public $for;
+
+ public function prepare() {
+ parent::prepare();
+ }
+}
/**
* This class represents how a block appears on a page.
parent::prepare();
}
+
+ public static function make_scale_menu($courseid, $scale) {
+ $helpbutton = new help_button();
+ $strscales = get_string('scales');
+ $helpbutton->image->alt = $scale->name;
+ $helpbutton->link->url = new moodle_url('/course/scales.php', array('id' => $courseid, 'list' => true, 'scaleid' => $scale->id));
+ $popupaction = new popup_action('click', $helpbutton->url, 'ratingscale', $popupparams);
+ $popupaction->width = 500;
+ $popupaction->height = 400;
+ $helpbutton->link->add_action($popupaction);
+ $helpbutton->link->title = $scale->name;
+ return $helpbutton;
+ }
}
*/
class html_button extends moodle_html_component {
/**
- * @var string $label
+ * @var string $text
*/
- public $label;
+ public $text;
/**
* @var boolean $disabled Whether or not this button is disabled
public function prepare() {
$this->add_class('singlebutton');
- if (empty($this->label)) {
- throw new coding_exception('A html_button must have a label value!');
+ if (empty($this->text)) {
+ throw new coding_exception('A html_button must have a text value!');
}
if ($this->disabled) {
$this->button = new html_button();
if (!isset($go)) {
$go = get_string('go');
- $this->button->label = $go;
+ $this->button->text = $go;
}
}
return implode("\n", $menu);
}
-/**
- * Prints form items with the names $day, $month and $year
- *
- * @param string $day fieldname
- * @param string $month fieldname
- * @param string $year fieldname
- * @param int $currenttime A default timestamp in GMT
- * @param boolean $return If set to true returns rather than echo's
- * @return string|bool Depending on value of $return
- */
-function print_date_selector($day, $month, $year, $currenttime=0, $return=false) {
-
- if (!$currenttime) {
- $currenttime = time();
- }
- $currentdate = usergetdate($currenttime);
-
- for ($i=1; $i<=31; $i++) {
- $days[$i] = $i;
- }
- for ($i=1; $i<=12; $i++) {
- $months[$i] = userdate(gmmktime(12,0,0,$i,15,2000), "%B");
- }
- for ($i=1970; $i<=2020; $i++) {
- $years[$i] = $i;
- }
-
- // Build or print result
- $result='';
- // Note: There should probably be a fieldset around these fields as they are
- // clearly grouped. However this causes problems with display. See Mozilla
- // bug 474415
- $result.='<label class="accesshide" for="menu'.$day.'">'.get_string('day','form').'</label>';
- $result.=choose_from_menu($days, $day, $currentdate['mday'], '', '', '0', true);
- $result.='<label class="accesshide" for="menu'.$month.'">'.get_string('month','form').'</label>';
- $result.=choose_from_menu($months, $month, $currentdate['mon'], '', '', '0', true);
- $result.='<label class="accesshide" for="menu'.$year.'">'.get_string('year','form').'</label>';
- $result.=choose_from_menu($years, $year, $currentdate['year'], '', '', '0', true);
-
- if ($return) {
- return $result;
- } else {
- echo $result;
- }
-}
-
-/**
- * Prints form items with the names $hour and $minute
- *
- * @param string $hour fieldname
- * @param string $minute fieldname
- * @param int $currenttime A default timestamp in GMT
- * @param int $step minute spacing
- * @param boolean $return If set to true returns rather than echo's
- * @return string|bool Depending on value of $return
- */
-function print_time_selector($hour, $minute, $currenttime=0, $step=5, $return=false) {
-
- if (!$currenttime) {
- $currenttime = time();
- }
- $currentdate = usergetdate($currenttime);
- if ($step != 1) {
- $currentdate['minutes'] = ceil($currentdate['minutes']/$step)*$step;
- }
- for ($i=0; $i<=23; $i++) {
- $hours[$i] = sprintf("%02d",$i);
- }
- for ($i=0; $i<=59; $i+=$step) {
- $minutes[$i] = sprintf("%02d",$i);
- }
-
- // Build or print result
- $result='';
- // Note: There should probably be a fieldset around these fields as they are
- // clearly grouped. However this causes problems with display. See Mozilla
- // bug 474415
- $result.='<label class="accesshide" for="menu'.$hour.'">'.get_string('hour','form').'</label>';
- $result.=choose_from_menu($hours, $hour, $currentdate['hours'], '','','0',true);
- $result.='<label class="accesshide" for="menu'.$minute.'">'.get_string('minute','form').'</label>';
- $result.=choose_from_menu($minutes, $minute, $currentdate['minutes'], '','','0',true);
-
- if ($return) {
- return $result;
- } else {
- echo $result;
- }
-}
-
-/**
- * Prints time limit value selector
- *
- * Uses {@link choose_from_menu()} to generate HTML
- * @see choose_from_menu()
- *
- * @global object
- * @param int $timelimit default
- * @param string $unit
- * @param string $name
- * @param boolean $return If set to true returns rather than echo's
- * @return string|bool Depending on value of $return
- */
-function print_timer_selector($timelimit = 0, $unit = '', $name = 'timelimit', $return=false) {
-
- global $CFG;
-
- if ($unit) {
- $unit = ' '.$unit;
- }
-
- // Max timelimit is sessiontimeout - 10 minutes.
- $maxvalue = ($CFG->sessiontimeout / 60) - 10;
-
- for ($i=1; $i<=$maxvalue; $i++) {
- $minutes[$i] = $i.$unit;
- }
- return choose_from_menu($minutes, $name, $timelimit, get_string('none'), '','','0',$return);
-}
-
/**
* Prints a grade menu (as part of an existing form) with help
* Showing all possible numerical grades and scales
}
}
-/**
- * Prints a help button about a scale
- *
- * @global object
- * @param id $courseid
- * @param object $scale
- * @param boolean $return If set to true returns rather than echo's
- * @return string|bool Depending on value of $return
- */
-function print_scale_menu_helpbutton($courseid, $scale, $return=false) {
-
- global $OUTPUT;
-
- $output = '';
- $strscales = get_string('scales');
-
- $linkobject = '<span class="helplink"><img class="iconhelp" alt="'.$scale->name.'" src="'.$OUTPUT->old_icon_url('help') . '" /></span>';
- $output .= link_to_popup_window ('/course/scales.php?id='. $courseid .'&list=true&scaleid='. $scale->id, 'ratingscale',
- $linkobject, 400, 500, $scale->name, 'none', true);
- if ($return) {
- return $output;
- } else {
- echo $output;
- }
-}
-
/**
* Print an error to STDOUT and exit with a non-zero code. For commandline scripts.
* Default errorcode is 1.