Esempio n. 1
0
$t->like(select_second_tag('second', null, array('include_blank' => true)), "/<option value=\"\"><\\/option>/", 'select_second_tag() can take an "include_blank" option');
$t->like(select_second_tag('second', null, array(), array('class' => 'foo')), '<select name="second" id="second" class="foo">', 'select_second_tag() takes an array of attribute options as its fourth argument');
$t->like(select_second_tag('second', null, array(), array('id' => 'foo')), '<select name="second" id="foo">', 'select_second_tag() takes an array of attribute options as its fourth argument');
$t->is(preg_match_all("/<option value=\"/", select_second_tag('second', null, array('second_step' => 10)), $matches), 6, 'select_second_tag() can take an "second_step" option');
// select_minute_tag()
$t->diag('select_minute_tag()');
$t->like(select_minute_tag('minute'), '/<select name="minute" id="minute">/', 'select_minute_tag() outputs a select tag for minutes');
$t->like(select_minute_tag('minute'), '/selected="selected">' . date('i') . '/', 'select_minute_tag() selects the current minutes by default');
$t->like(select_minute_tag('minute', 12), '/<option value="12" selected="selected">/', 'select_minute_tag() takes a minute number as its second argument');
$t->like(select_minute_tag('minute', '02'), '/<option value="2" selected="selected">/', 'select_minute_tag() takes a minute number as its second argument');
// options
$t->like(select_minute_tag('minute', null, array('include_custom' => 'test')), "/<option value=\"\">test<\\/option>/", 'select_minute_tag() can take an "include_custom" option');
$t->like(select_minute_tag('minute', null, array('include_blank' => true)), "/<option value=\"\"><\\/option>/", 'select_minute_tag() can take an "include_blank" option');
$t->like(select_minute_tag('minute', null, array(), array('class' => 'foo')), '<select name="minute" id="minute" class="foo">', 'select_minute_tag() takes an array of attribute options as its fourth argument');
$t->like(select_minute_tag('minute', null, array(), array('id' => 'foo')), '<select name="minute" id="foo">', 'select_minute_tag() takes an array of attribute options as its fourth argument');
$t->is(preg_match_all("/<option value=\"/", select_minute_tag('minute', null, array('minute_step' => 10)), $matches), 6, 'select_minute_tag() can take an "minute_step" option');
// select_hour_tag()
$t->diag('select_hour_tag()');
$t->like(select_hour_tag('hour'), '/<select name="hour" id="hour">/', 'select_hour_tag() outputs a select tag for hours');
$t->like(select_hour_tag('hour'), '/selected="selected">' . date('H') . '/', 'select_hour_tag() selects the current hours by default');
$t->like(select_hour_tag('hour', 1), '/<option value="1" selected="selected">/', 'select_hour_tag() takes a hour number as its second argument');
// options
$t->like(select_hour_tag('hour', null, array('include_custom' => 'test')), "/<option value=\"\">test<\\/option>/", 'select_hour_tag() can take an "include_custom" option');
$t->like(select_hour_tag('hour', null, array('include_blank' => true)), "/<option value=\"\"><\\/option>/", 'select_hour_tag() can take an "include_blank" option');
$t->like(select_hour_tag('hour', null, array(), array('class' => 'foo')), '<select name="hour" id="hour" class="foo">', 'select_hour_tag() takes an array of attribute options as its fourth argument');
$t->like(select_hour_tag('hour', null, array(), array('id' => 'foo')), '<select name="hour" id="foo">', 'select_hour_tag() takes an array of attribute options as its fourth argument');
$t->is(preg_match_all("/<option value=\"/", select_hour_tag('hour'), $matches), 24, 'select_hour_tag() can take an "12hour_time" option');
$t->is(preg_match_all("/<option value=\"/", select_hour_tag('hour', null, array('12hour_time' => true)), $matches), 12, 'select_hour_tag() can take an "12hour_time" option');
// select_ampm_tag()
$t->diag('select_ampm_tag()');
$t->like(select_ampm_tag('ampm'), '/<select name="ampm" id="ampm">/', 'select_ampm_tag() outputs a select tag for ampm');
/**
 * Returns three <select> tags populated with hours, minutes, and optionally seconds.
 *
 * By default, the <i>$value</i> parameter is set to the current hour and minute. To override this, simply pass a valid time
 * or a correctly formatted time array (see example) to the <i>$value</i> parameter. You can also set the <i>$value</i> 
 * parameter to null which will disable the <i>$value</i>, however this will only be useful if you pass 'include_blank' or 
 * 'include_custom' to the <i>$options</i> parameter. To include seconds to the result, use set the 'include_second' option in the 
 * <i>$options</i> parameter to true. <b>Note:</b> The <i>$name</i> parameter will automatically converted to array names. 
 * For example, a <i>$name</i> of "time" becomes:
 * <samp>
 *  <select name="time[hour]">...</select>
 *  <select name="time[minute]">...</select>
 *  <select name="time[second]">...</select>
 * </samp>
 *  
 * <b>Options:</b>
 * - include_blank  - Includes a blank <option> tag at the beginning of the string with an empty value.
 * - include_custom - Includes an <option> tag with a custom display title at the beginning of the string with an empty value.
 * - include_second - If set to true, includes the "seconds" select tag as part of the result.
 * - second_step    - If set, the seconds will be incremented in blocks of X, where X = 'second_step'
 * - minute_step    - If set, the minutes will be incremented in blocks of X, where X = 'minute_step'
 * - 12hour_time    - If set to true, will return integers 1 through 12 instead of the default 0 through 23 as well as an AM/PM select box.
 * - time_seperator - Includes a string of defined text between each generated select tag
 * - ampm_seperator - Includes a string of defined text between the minute/second select box and the AM/PM select box 
 *  
 * <b>Examples:</b>
 * <code>
 *  echo select_time_tag('time');
 * </code>
 *
 * <code>
 *  echo select_time_tag('date', '09:31');
 * </code>
 *
 * <code>
 *  $time = array('hour' => '15', 'minute' => 46, 'second' => 01);
 *  echo select_time_tag('time', $time, array('include_second' => true, '12hour_time' => true));
 * </code>
 *
 * @param  string field name (automatically becomes an array of parts: name[hour], name[minute], year[second])
 * @param  mixed  accepts a valid time string or properly formatted time array
 * @param  array  additional HTML compliant <select> tag parameters
 * @return string three <select> tags populated with a hours, minutes and optionally seconds.
 * @see select datetime_tag, select_hour_tag, select_minute_tag, select_second_tag
 */
function select_time_tag($name, $value = null, $options = array(), $html_options = array())
{
    $options = _parse_attributes($options);
    $time_seperator = _get_option($options, 'time_seperator', ':');
    $ampm_seperator = _get_option($options, 'ampm_seperator', '');
    $include_second = _get_option($options, 'include_second');
    $_12hour_time = _get_option($options, '12hour_time');
    $options['12hour_time'] = $_12hour_time;
    // set it back. hour tag needs it.
    if ($include_custom = _get_option($options, 'include_custom')) {
        $include_custom_hour = is_array($include_custom) ? isset($include_custom['hour']) ? array('include_custom' => $include_custom['hour']) : array() : array('include_custom' => $include_custom);
        $include_custom_minute = is_array($include_custom) ? isset($include_custom['minute']) ? array('include_custom' => $include_custom['minute']) : array() : array('include_custom' => $include_custom);
        $include_custom_second = is_array($include_custom) ? isset($include_custom['second']) ? array('include_custom' => $include_custom['second']) : array() : array('include_custom' => $include_custom);
        $include_custom_ampm = is_array($include_custom) ? isset($include_custom['ampm']) ? array('include_custom' => $include_custom['ampm']) : array() : array('include_custom' => $include_custom);
    } else {
        $include_custom_hour = array();
        $include_custom_minute = array();
        $include_custom_second = array();
        $include_custom_ampm = array();
    }
    $tags = array();
    $hour_name = $name . '[hour]';
    $tags[] = select_hour_tag($hour_name, _parse_value_for_date($value, 'hour', $_12hour_time ? 'h' : 'H'), $options + $include_custom_hour, $html_options);
    $minute_name = $name . '[minute]';
    $tags[] = select_minute_tag($minute_name, _parse_value_for_date($value, 'minute', 'i'), $options + $include_custom_minute, $html_options);
    if ($include_second) {
        $second_name = $name . '[second]';
        $tags[] = select_second_tag($second_name, _parse_value_for_date($value, 'second', 's'), $options + $include_custom_second, $html_options);
    }
    $time = implode($time_seperator, $tags);
    if ($_12hour_time) {
        $ampm_name = $name . '[ampm]';
        $time .= $ampm_seperator . select_ampm_tag($ampm_name, _parse_value_for_date($value, 'ampm', 'A'), $options + $include_custom_ampm, $html_options);
    }
    return $time;
}
Esempio n. 3
0
function select_minute($path, $options = array(), $html_options = array())
{
    $name = _get_complete_bind_path($path);
    $bindStatus =& new BindStatus(_get_bind_path($path));
    $boundValue = $bindStatus->getDisplayValue();
    return select_minute_tag($name, $boundValue, $options, $html_options);
}