/** * Returns three <select> tags populated with a range of months, days, and years. * * By default, the <i>$value</i> parameter is set to today's month, day and year. To override this, simply pass a valid date * or a correctly formatted date 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. Also, the default selectable range of years is set to show five years * back and five years forward from today's year. For instance, if today's year is 2006, the default 'year_start' option will * be set to 2001 and the 'year_end' option will be set to 2011. These start and end dates can easily be overwritten by * setting the 'year_start' and 'year_end' options in the <i>$options</i> parameter. * * <b>Note:</b> The <i>$name</i> parameter will automatically converted to array names. For example, a <i>$name</i> of "date" becomes: * <samp> * <select name="date[month]">...</select> * <select name="date[day]">...</select> * <select name="date[year]">...</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. * - discard_month - If set to true, will only return select tags for day and year. * - discard_day - If set to true, will only return select tags for month and year. * - discard_year - If set to true, will only return select tags for month and day. * - use_month_numbers - If set to true, will show the month's numerical value (1 - 12) instead of the months full name. * - use_short_month - If set to true, will show the month's short name (i.e. Jan, Feb, Mar) instead of its full name. * - year_start - If set, the range of years will begin at this four-digit date (i.e. 1979) * - year_end - If set, the range of years will end at this four-digit date (i.e. 2025) * - date_seperator - Includes a string of defined text between each generated select tag * * <b>Examples:</b> * <code> * echo select_date_tag('date'); * </code> * * <code> * echo select_date_tag('date', '2006-10-30'); * </code> * * <code> * $date = array('year' => '1979', 'month' => 10, 'day' => 30); * echo select_date_tag('date', $date, array('year_start' => $date['year'] - 10, 'year_end' => $date['year'] + 10)); * </code> * * @param string field name (automatically becomes an array of parts: name[year], name[month], year[day]) * @param mixed accepts a valid date string or properly formatted date array * @param array additional HTML compliant <select> tag parameters * @return string three <select> tags populated with a months, days and years * @see select datetime_tag, select_month_tag, select_date_tag, select_year_tag */ function select_date_tag($name, $value = null, $options = array(), $html_options = array()) { $options = _parse_attributes($options); $culture = _get_option($options, 'culture', sfContext::getInstance()->getUser()->getCulture()); // set it back for month tag $options['culture'] = $culture; $I18n_arr = _get_I18n_date_locales($culture); $date_seperator = _get_option($options, 'date_seperator', $I18n_arr['date_seperator']); $discard_month = _get_option($options, 'discard_month'); $discard_day = _get_option($options, 'discard_day'); $discard_year = _get_option($options, 'discard_year'); // discarding month automatically discards day if ($discard_month) { $discard_day = true; } $order = _get_option($options, 'order'); $tags = array(); if (is_array($order) && count($order) == 3) { foreach ($order as $v) { $tags[] = $v[0]; } } else { $tags = $I18n_arr['date_order']; } if ($include_custom = _get_option($options, 'include_custom')) { $include_custom_month = is_array($include_custom) ? isset($include_custom['month']) ? array('include_custom' => $include_custom['month']) : array() : array('include_custom' => $include_custom); $include_custom_day = is_array($include_custom) ? isset($include_custom['day']) ? array('include_custom' => $include_custom['day']) : array() : array('include_custom' => $include_custom); $include_custom_year = is_array($include_custom) ? isset($include_custom['year']) ? array('include_custom' => $include_custom['year']) : array() : array('include_custom' => $include_custom); } else { $include_custom_month = array(); $include_custom_day = array(); $include_custom_year = array(); } $month_name = $name . '[month]'; $m = !$discard_month ? select_month_tag($month_name, _parse_value_for_date($value, 'month', 'm'), $options + $include_custom_month, $html_options) : ''; $day_name = $name . '[day]'; $d = !$discard_day ? select_day_tag($day_name, _parse_value_for_date($value, 'day', 'd'), $options + $include_custom_day, $html_options) : ''; $year_name = $name . '[year]'; $y = !$discard_year ? select_year_tag($year_name, _parse_value_for_date($value, 'year', 'Y'), $options + $include_custom_year, $html_options) : ''; // we have $tags = array ('m','d','y') foreach ($tags as $k => $v) { // $tags['m|d|y'] = $m|$d|$y if (strlen(${$v})) { $tags[$k] = ${$v}; } else { unset($tags[$k]); } } return implode($date_seperator, $tags); }
function my_input_date_tag($name, $value = null, $options = array(), $html_options = array()) { $options = _parse_attributes($options); $context = sfContext::getInstance(); $culture = _get_option($options, 'culture', $context->getUser()->getCulture()); // set it back for month tag $options['culture'] = $culture; $I18n_arr = _get_I18n_date_locales($culture); $date_seperator = _get_option($options, 'date_seperator', $I18n_arr['date_seperator']); $include_blank_month = array('include_blank' => _get_option($options, 'include_blank_month', false)); $include_blank_day = array('include_blank' => _get_option($options, 'include_blank_day', false)); $include_blank_year = array('include_blank' => _get_option($options, 'include_blank_year', false)); $order = _get_option($options, 'order'); $tags = array(); if (is_array($order) && count($order) == 3) { foreach ($order as $v) { $tags[] = $v[0]; } } else { $tags = $I18n_arr['date_order']; } $month_name = $name . '[month]'; $m = select_month_tag($month_name, _parse_value_for_date($value, 'month', 'm'), $options + $include_blank_month, $html_options); $day_name = $name . '[day]'; $d = select_day_tag($day_name, _parse_value_for_date($value, 'day', 'd'), $options + $include_blank_day, $html_options); $year_name = $name . '[year]'; $y = select_year_tag($year_name, _parse_value_for_date($value, 'year', 'Y'), $options + $include_blank_year, $html_options); // we have $tags = array ('m','d','y') foreach ($tags as $k => $v) { // $tags['m|d|y'] = $m|$d|$y $tags[$k] = ${$v}; } return implode($date_seperator, $tags); }
function field_months_data($document, $name) { use_helper('DateForm'); $months = $document->getRaw($name); $I18n_arr = _get_I18n_date_locales(sfContext::getInstance()->getUser()->getCulture()); $month_names = $I18n_arr['dateFormatInfo']->getMonthNames(); if (is_array($months)) { if (count($months) == 12) { $value = __('all months'); } else { $value = array(); foreach ($months as $month) { $month--; if (!array_key_exists($month, $month_names)) { continue; } $value[] = $month_names[$month]; } $value = implode(', ', $value); } } else { $months--; $value = array_key_exists($months, $month_names) ? $month_names[$months] : ''; } return _format_data($name, $value); }
function object_months_list_tag($document, $fieldname, $multiple = true) { $I18n_arr = _get_I18n_date_locales(sfContext::getInstance()->getUser()->getCulture()); $months = $I18n_arr['dateFormatInfo']->getMonthNames(); $value = $document->getRaw($fieldname); if (is_array($value)) { $options = ''; foreach ($months as $month_id => $month_name) { $option_options = array('value' => ++$month_id); if (in_array($month_id, $value)) { $option_options['selected'] = 'selected'; } $options .= content_tag('option', $month_name, $option_options) . "\n"; } } else { $select_options = array(); foreach ($months as $month_id => $month_name) { $select_options[$month_id + 1] = $month_name; } $options = options_for_select($select_options, $value); } $html_options = array(); if ($multiple) { $html_options['multiple'] = true; } return start_group_tag() . label_tag($fieldname) . select_tag($fieldname, $options, $html_options) . end_group_tag(); }