Skip to content

Commit

Permalink
MDL-20204 converting yes_no selects
Browse files Browse the repository at this point in the history
  • Loading branch information
skodak committed Feb 10, 2010
1 parent 81aba78 commit 78bdac6
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 27 deletions.
3 changes: 1 addition & 2 deletions enrol/mnet/config.html
Expand Up @@ -8,7 +8,6 @@
if (is_array($mnethosts)) {
$servercount = count(array_keys($mnethosts));
}
$select = html_select::make_yes_no('enrol_mnet_allow_allcourses', $frm->enrol_mnet_allow_allcourses);

?>
<table cellspacing="0" cellpadding="5" border="0" class="boxaligncenter">
Expand All @@ -20,7 +19,7 @@
<tr valign="top">
<td align="right">allow_allcourses:</td>
<td>
<?php echo $OUTPUT->select($select); ?>
<?php echo html_writer:.select_yes_no('enrol_mnet_allow_allcourses', $frm->enrol_mnet_allow_allcourses); ?>
</td>
<td>
<?php print_string("allow_allcourses", "enrol_mnet") ?>
Expand Down
5 changes: 1 addition & 4 deletions lib/deprecatedlib.php
Expand Up @@ -3113,10 +3113,7 @@ function choose_from_menu_yesno($name, $selected, $script = '', $return = false,
debugging('The $script parameter has been deprecated. You must use component_actions instead', DEBUG_DEVELOPER);
}

$select = html_select::make_yes_no($name, $selected);
$select->disabled = $disabled;
$select->tabindex = $tabindex;
$output = $OUTPUT->select($select);
$output = html_writer::select_yes_no($name, $selected, array('disabled'=>($disabled ? 'disabled' : null), 'tabindex'=>$tabindex));

if ($return) {
return $output;
Expand Down
24 changes: 13 additions & 11 deletions lib/outputcomponents.php
Expand Up @@ -689,6 +689,18 @@ public static function checkbox($name, $value, $checked = true, $label = '', arr
return $output;
}

/**
* Generates a simple select yes/no form field
* @param string $name name of select element
* @param bool $selected
* @param array $attributes - html select element attributes
* @return string HRML fragment
*/
public function select_yes_no($name, $selected=true, array $attributes = null) {
$options = array('1'=>get_string('yes'), '0'=>get_string('no'));
return self::select($options, $name, $selected, null, $attributes);
}

/**
* Generates a simple select form field
* @param array $options associative array value=>label ex.:
Expand All @@ -700,7 +712,7 @@ public static function checkbox($name, $value, $checked = true, $label = '', arr
* @param string|array $selected value or arary of values depending on multiple attribute
* @param array|bool $nothing, add nothing selected option, or false of not added
* @param array $attributes - html select element attributes
* @return string HRML fragment
* @return string HTML fragment
*/
public static function select(array $options, $name, $selected = '', $nothing = array(''=>'choosedots'), array $attributes = null) {
$attributes = (array)$attributes;
Expand Down Expand Up @@ -1362,16 +1374,6 @@ public static function make($options, $name, $selected = '', $nothinglabel='choo
return $menu;
}

/**
* This is a shortcut for making a yes/no select menu.
* @param string $name used to initialise {@link $name}.
* @param string $selected used to initialise {@link $selected}.
* @return html_select A menu initialised with yes/no options.
*/
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)
Expand Down
10 changes: 0 additions & 10 deletions lib/simpletest/testoutputlib.php
Expand Up @@ -574,16 +574,6 @@ public function test_select_with_label() {
$this->assert(new ContainsTagWithContents('label', 'Cool menu'), $html);
}
public function test_select_yesno() {
$select = html_select::make_yes_no('question', 1);
$html = $this->renderer->select($select);
$this->assert(new ContainsTagWithAttributes('select', array('class' => 'menuquestion select', 'name' => 'question', 'id' => 'menuquestion')), $html);
$this->assert(new ContainsTagWithContents('option', get_string('choosedots')), $html);
$this->assert(new ContainsTagWithContents('option', get_string('yes')), $html);
$this->assert(new ContainsTagWithContents('option', get_string('no')), $html);
$this->assert(new ContainsTagWithAttributes('option', array('value' => '1', 'selected' => 'selected')), $html);
}
public function test_error_text() {
$html = $this->renderer->error_text('message');
$this->assert(new ContainsTagWithContents('span', 'message'), $html);
Expand Down

0 comments on commit 78bdac6

Please sign in to comment.