$id='', $listbox=false, $multiple=false, $class='') {
global $OUTPUT;
- debugging('choose_from_menu() has been deprecated. Please change your code to use $OUTPUT->select($select).');
+ debugging('choose_from_menu() has been deprecated. Please change your code to use html_writer::select().');
if ($script) {
debugging('The $script parameter has been deprecated. You must use component_actions instead', DEBUG_DEVELOPER);
}
- $select = html_select::make($options, $name, $selected);
- $select->nothinglabel = $nothing;
- $select->nothingvalue = $nothingvalue;
- $select->disabled = $disabled;
- $select->tabindex = $tabindex;
- $select->id = $id;
- $select->listbox = $listbox;
- $select->multiple = $multiple;
- $select->add_classes($class);
-
- if ($nothing == 'choose') {
- $select->nothinglabel = '';
- }
+ $attributes = array();
+ $attributes['disabled'] = $disabled ? 'disabled' : null;
+ $attributes['tabindex'] = $tabindex ? $tabindex : null;
+ $attributes['multiple'] = $multiple ? $multiple : null;
+ $attributes['class'] = $class ? $class : null;
+ $attributes['id'] = $id ? $id : null;
- $output = $OUTPUT->select($select);
+ $output = html_writer::select($options, $name, $selected, array($nothingvalue=>$nothing), $attributes);
if ($return) {
return $output;
* @return string|void If $return=true returns string, else echo's and returns void
*/
function choose_from_menu_yesno($name, $selected, $script = '', $return = false, $disabled = false, $tabindex = 0) {
- debugging('choose_from_menu_yesno() has been deprecated. Please change your code to use $OUTPUT->select($select).');
+ debugging('choose_from_menu_yesno() has been deprecated. Please change your code to use html_writer.');
global $OUTPUT;
if ($script) {
function choose_from_menu_nested($options,$name,$selected='',$nothing='choose',$script = '',
$nothingvalue=0,$return=false,$disabled=false,$tabindex=0) {
- debugging('choose_from_menu_nested() has been deprecated. Please change your code to use $OUTPUT->select($select).');
+ debugging('choose_from_menu_nested() has been removed. Please change your code to use html_writer:.select().');
global $OUTPUT;
-
- if ($script) {
- debugging('The $script parameter has been deprecated. You must use component_actions instead', DEBUG_DEVELOPER);
- }
- $select = html_select::make($options, $name, $selected);
- $select->tabindex = $tabindex;
- $select->disabled = $disabled;
- $select->nothingvalue = $nothingvalue;
- $select->nested = true;
-
- if ($nothing == 'choose') {
- $select->nothinglabel = '';
- }
-
- $output = $OUTPUT->select($select);
-
- if ($return) {
- return $output;
- } else {
- echo $output;
- }
}
/**
* @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($select) instead');
+ throw new coding_exception('print_timer_selector is completely removed. Please use html_writer instead');
}
/**
* @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($timeselector).');
+ debugging('print_time_selector() has been deprecated. Please change your code to use html_writer.');
$hourselector = html_writer::select_time('hours', $hour, $currenttime);
$minuteselector = html_writer::select_time('minutes', $minute, $currenttime, $step);
* @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($dateselector).');
+ debugging('print_date_selector() has been deprecated. Please change your code to use html_writer.');
$dayselector = html_writer::select_time('days', $day, $currenttime);
$monthselector = html_writer::select_time('months', $month, $currenttime);
* @return string|void If $return=true returns string, else echo's and returns void
*/
function choose_from_radio ($options, $name, $checked='', $return=false) {
-
- debugging('choose_from_radio() has been deprecated. Please change your code to use $OUTPUT->select($select).');
- global $OUTPUT;
-
- $select = html_select::make($options, $name, $checked);
- $select->rendertype = 'radio';
-
- $output = $OUTPUT->select($select);
-
- if ($return) {
- return $output;
- } else {
- echo $output;
- }
+ debugging('choose_from_radio() has been removed. Please change your code to use html_writer.');
}
/**
return $this->container($this->render($button), 'closewindow');
}
- /**
- * Outputs a <select> menu or a list of radio/checkbox inputs.
- *
- * This method is extremely versatile, and can be used to output yes/no menus,
- * form-enclosed menus with automatic redirects when an option is selected,
- * descriptive labels and help icons. By default it just outputs a select
- * menu.
- *
- * To add a descriptive label, use html_select::set_label($text, $for) or
- * html_select::set_label($label) passing a html_label object
- *
- * To add a help icon, use html_select::set_help($page, $text, $linktext) or
- * html_select::set_help($helpicon) passing a help_icon object
- *
- * If you html_select::$rendertype to "radio", it will render radio buttons
- * instead of a <select> menu, unless $multiple is true, in which case it
- * will render checkboxes.
- *
- * To surround the menu with a form, simply set html_select->form as a
- * valid html_form object. Note that this function will NOT automatically
- * add a form for non-JS browsers. If you do not set one up, it assumes
- * that you are providing your own form in some other way.
- *
- * You can either call this function with a single html_select argument
- * or, with a list of parameters, in which case those parameters are sent to
- * the html_select constructor.
- *
- * @param html_select $select a html_select that describes
- * the select menu you want output.
- * @return string the HTML for the <select>
- */
- public function select($select) {
- $select = clone($select);
- $select->prepare($this, $this->page, $this->target);
-
- $this->prepare_event_handlers($select);
-
- if (empty($select->id)) {
- $select->id = 'menu' . str_replace(array('[', ']'), '', $select->name);
- }
-
- $attributes = array(
- 'name' => $select->name,
- 'id' => $select->id,
- 'class' => $select->get_classes_string()
- );
- if ($select->disabled) {
- $attributes['disabled'] = 'disabled';
- }
- if ($select->tabindex) {
- $attributes['tabindex'] = $select->tabindex;
- }
-
- if ($select->rendertype == 'menu' && $select->listbox) {
- if (is_integer($select->listbox)) {
- $size = $select->listbox;
- } else {
- $size = min($select->maxautosize, count($select->options));
- }
- $attributes['size'] = $size;
- if ($select->multiple) {
- $attributes['multiple'] = 'multiple';
- }
- }
-
- $html = '';
-
- if (!empty($select->label)) {
- $html .= $this->label($select->label);
- }
-
- if ($select->helpicon) {
- $html .= $this->help_icon($select->helpicon['helppage'], $select->helpicon['text'], $select->helpicon['component']);
- }
-
- if ($select->rendertype == 'menu') {
- $html .= html_writer::start_tag('select', $attributes) . "\n";
-
- foreach ($select->options as $option) {
- // $OUTPUT->select_option detects if $option is an option or an optgroup
- $html .= $this->select_option($option);
- }
-
- $html .= html_writer::end_tag('select') . "\n";
- } else if ($select->rendertype == 'radio') {
- $currentradio = 0;
- foreach ($select->options as $option) {
- $html .= $this->radio($option, $select->name);
- $currentradio++;
- }
- } else if ($select->rendertype == 'checkbox') {
- $currentcheckbox = 0;
- // If only two choices are available, suggest using the checkbox method instead
- if (count($select->options) < 3 && !$select->multiple) {
- debugging('You are using $OUTPUT->select() to render two mutually exclusive choices using checkboxes. Please use $OUTPUT->checkbox(html_select_option) instead.', DEBUG_DEVELOPER);
- } else {
- foreach ($select->options as $option) {
- $html .= $this->checkbox($option, $select->name);
- $currentcheckbox++;
- }
- }
- }
-
- if (!empty($select->form) && $select->form instanceof html_form) {
- $html = $this->form($select->form, $html);
- }
-
- return $html;
- }
-
- /**
- * Outputs a <input type="radio" /> element. Optgroups are ignored, so do not
- * pass a html_select_optgroup as a param to this function.
- *
- * @param html_select_option $option a html_select_option
- * @return string the HTML for the <input type="radio">
- */
- public function radio($option, $name='unnamed') {
- static $currentradio = array();
-
- if (empty($currentradio[$name])) {
- $currentradio[$name] = 0;
- }
-
- if ($option instanceof html_select_optgroup) {
- throw new coding_exception('$OUTPUT->radio($option) does not support a html_select_optgroup object as param.');
- } else if (!($option instanceof html_select_option)) {
- throw new coding_exception('$OUTPUT->radio($option) only accepts a html_select_option object as param.');
- }
- $option = clone($option);
- $option->prepare($this, $this->page, $this->target);
- $option->label->for = $option->id;
- $this->prepare_event_handlers($option);
-
- $output = html_writer::start_tag('span', array('class' => "radiogroup $name rb{$currentradio[$name]}")) . "\n";
- $output .= $this->label($option->label);
-
- if ($option->selected == 'selected') {
- $option->selected = 'checked';
- }
-
- $output .= html_writer::empty_tag('input', array(
- 'type' => 'radio',
- 'value' => $option->value,
- 'name' => $name,
- 'alt' => $option->alt,
- 'id' => $option->id,
- 'class' => $option->get_classes_string(),
- 'checked' => $option->selected));
-
- $output .= html_writer::end_tag('span');
- $currentradio[$name]++;
- return $output;
- }
-
/**
* Outputs a <input type="checkbox" /> element. Optgroups are ignored, so do not
* pass a html_select_optgroup as a param to this function.