Development

Changeset 1142

You must first sign up to be able to contribute.

Changeset 1142

Show
Ignore:
Timestamp:
04/07/06 11:22:55 (3 years ago)
Author:
fabien
Message:

patched data select support (patch from brujahRg - closes #26)

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/lib/helper/FormHelper.php

    r1096 r1142  
    516516function select_day_tag($name, $value, $options = array(), $html_options = array()) 
    517517{ 
     518  $options = _parse_attributes($options); 
     519 
    518520  $select_options = array(); 
    519  
    520521  if (_get_option($options, 'include_blank')) 
    521522  { 
     
    532533  } 
    533534 
    534   $option_tags = options_for_select($select_options, $value); 
    535  
    536   return select_tag($name, $option_tags, $html_options); 
     535  return select_tag($name, options_for_select($select_options, $value), $html_options); 
    537536} 
    538537 
    539538function select_month_tag($name, $value, $options = array(), $html_options = array()) 
    540539{ 
     540  $options = _parse_attributes($options); 
    541541 
    542542  $culture = _get_option($options, 'culture', sfContext::getInstance()->getUser()->getCulture()); 
    543  
    544543  $I18n_arr = _get_I18n_date_locales($culture); 
    545544 
    546545  $select_options = array(); 
    547  
    548546  if (_get_option($options, 'include_blank')) 
    549547  { 
     
    580578  } 
    581579 
    582   $option_tags = options_for_select($select_options, $value); 
    583  
    584   return select_tag($name, $option_tags, $html_options); 
     580  return select_tag($name, options_for_select($select_options, $value), $html_options); 
    585581} 
    586582 
    587583function select_year_tag($name, $value, $options = array(), $html_options = array()) 
    588584{ 
     585  $options = _parse_attributes($options); 
     586 
    589587  $select_options = array(); 
    590  
    591588  if (_get_option($options, 'include_blank')) 
    592589  { 
     
    618615  } 
    619616 
    620   $option_tags = options_for_select($select_options, $value); 
    621  
    622   return select_tag($name, $option_tags, $html_options); 
     617  return select_tag($name, options_for_select($select_options, $value), $html_options); 
    623618} 
    624619 
     
    629624 * @param string $value (proper date format: array('year'=>2005, 'month'=>1, 'day'=1) or timestamp or english date text) 
    630625 * @param array $options 
     626 * @param array $html_options 
    631627 * @return string 
    632628 */ 
    633629function select_date_tag($name, $value, $options = array(), $html_options = array()) 
    634630{ 
    635   $html_options = _parse_attributes($html_options); 
    636631  $options = _parse_attributes($options); 
    637632 
     
    649644 
    650645  //discarding month automatically discards day 
    651   if ($discard_month)  
     646  if ($discard_month) 
     647  { 
    652648    $discard_day = true; 
     649  } 
    653650 
    654651  $order = _get_option($options, 'order'); 
    655  
    656652  $tags = array(); 
    657653 
    658654  if (is_array($order) && count($order) == 3) 
    659655  { 
    660     foreach ($order as $k => $v) 
    661     { 
    662       $tags[] = $v[0]; //'day' => 'd' | 'month' => 'm' 
     656    foreach ($order as $v) 
     657    { 
     658      $tags[] = $v[0]; 
    663659    } 
    664660  } 
     
    690686 
    691687  $html_options['id'] = $name . '_month'; 
    692   $m = ($discard_month != true) ? select_month_tag($name . '[month]', _parse_value_for_date($value, 'month', 'm'), $options + $include_custom_month, $html_options) : ''; 
     688  $m = (!$discard_month) ? select_month_tag($name . '[month]', _parse_value_for_date($value, 'month', 'm'), $options + $include_custom_month, $html_options) : ''; 
    693689 
    694690  $html_options['id'] = $name . '_day'; 
    695   $d = ($discard_day != true) ? select_day_tag($name . '[day]', _parse_value_for_date($value, 'day', 'd'), $options + $include_custom_day, $html_options) : ''; 
     691  $d = (!$discard_day) ? select_day_tag($name . '[day]', _parse_value_for_date($value, 'day', 'd'), $options + $include_custom_day, $html_options) : ''; 
    696692 
    697693  $html_options['id'] = $name . '_year'; 
    698   $y = ($discard_year != true) ? select_year_tag($name . '[year]', _parse_value_for_date($value, 'year', 'Y'), $options + $include_custom_year, $html_options) : ''; 
    699  
    700   //we have $tags = array ('m','d','y') 
     694  $y = (!$discard_year) ? select_year_tag($name . '[year]', _parse_value_for_date($value, 'year', 'Y'), $options + $include_custom_year, $html_options) : ''; 
     695 
     696  // we have $tags = array ('m','d','y') 
    701697  foreach ($tags as $k => $v) 
    702698  { 
     699    // $tags['m|d|y'] = $m|$d|$y 
    703700    $tags[$k] = $$v; 
    704701  } 
     
    709706function select_second_tag($name, $value, $options = array(), $html_options = array()) 
    710707{ 
     708  $options = _parse_attributes($options); 
    711709  $select_options = array(); 
    712710 
     
    726724  } 
    727725 
    728   $option_tags = options_for_select($select_options, $value); 
    729  
    730   return select_tag($name, $option_tags, $html_options); 
     726  return select_tag($name, options_for_select($select_options, $value), $html_options); 
    731727} 
    732728 
    733729function select_minute_tag($name, $value, $options = array(), $html_options = array()) 
    734730{ 
     731  $options = _parse_attributes($options); 
    735732  $select_options = array(); 
    736733 
     
    750747  } 
    751748 
    752   $option_tags = options_for_select($select_options, $value); 
    753  
    754   return select_tag($name, $option_tags, $html_options); 
     749  return select_tag($name, options_for_select($select_options, $value), $html_options); 
    755750} 
    756751 
    757752function select_hour_tag($name, $value, $options = array(), $html_options = array()) 
    758753{ 
     754  $options = _parse_attributes($options); 
    759755  $select_options = array(); 
    760756 
     
    778774  } 
    779775 
    780   $option_tags = options_for_select($select_options, $value); 
    781  
    782   return select_tag($name, $option_tags, $html_options); 
     776  return select_tag($name, options_for_select($select_options, $value), $html_options); 
    783777} 
    784778 
    785779function select_ampm_tag($name, $value, $options = array(), $html_options = array()) 
    786780{ 
     781  $options = _parse_attributes($options); 
    787782  $select_options = array(); 
    788783 
     
    799794  $select_options['PM'] = 'PM'; 
    800795 
    801   $option_tags = options_for_select($select_options, $value); 
    802  
    803   return select_tag($name, $option_tags, $html_options); 
     796  return select_tag($name, options_for_select($select_options, $value), $html_options); 
    804797} 
    805798 
     
    810803 * @param string $value (proper time format: array('hour'=>0, 'minute'=>0, 'second'=0) or timestamp or english date text) 
    811804 * @param array $options 
     805 * @param array $html_options 
    812806 * @return string 
    813807 */ 
    814808function select_time_tag($name, $value, $options = array(), $html_options = array()) 
    815809{ 
    816   $html_options = _parse_attributes($html_options); 
    817810  $options = _parse_attributes($options); 
    818811 
     
    907900} 
    908901 
    909 function _get_I18n_date_locales($culture = ''
    910 { 
    911   if (empty($culture)
     902function _get_I18n_date_locales($culture = null
     903{ 
     904  if (!$culture
    912905  { 
    913906    $culture = sfContext::getInstance()->getUser()->getCulture(); 
    914907  } 
    915908 
    916   $ret_val = array(); 
    917   $ret_val['culture'] = $culture; 
     909  $retval = array('culture'=>$culture); 
    918910 
    919911  $dateFormatInfo = sfDateTimeFormatInfo::getInstance($culture); 
    920912  $date_format = strtolower($dateFormatInfo->getShortDatePattern()); 
    921913 
    922   $ret_val['dateFormatInfo'] = $dateFormatInfo; 
     914  $retval['dateFormatInfo'] = $dateFormatInfo; 
    923915     
    924916  $match_pattern = "/([dmy]+)(.*?)([dmy]+)(.*?)([dmy]+)/"; 
     
    929921  } 
    930922 
    931   $ret_val['date_seperator'] = $match_arr[2]; 
     923  $retval['date_seperator'] = $match_arr[2]; 
    932924 
    933925  //unset all but [dmy]+ 
    934926  unset($match_arr[0], $match_arr[2], $match_arr[4]); 
    935927   
    936   $cnt = 0; 
    937   foreach ($match_arr as $k => $v) 
    938   { 
    939     $ret_val['date_order'][$cnt++] = $v[0]; //$arr[date_order][0] = 'm'; [1] = 'd'; [2] = 'y'; 
     928  $retval['date_order'] = array(); 
     929  foreach ($match_arr as $v) 
     930  { 
     931    // 'm/d/yy' => $retval[date_order] = array ('m', 'd', 'y'); 
     932    $retval['date_order'][] = $v[0]; 
    940933  } 
    941934   
    942   return $ret_val; 
    943 } 
    944  
    945 /** 
    946 * _parse_value_for_date function can parse any date field from $value given as: 
    947 *  - an array('year'=>2000, 'month'=> 1, .. 
    948 *  - a timestamp 
    949 *  - english text presentation of date (i.e '14:23', '03:30 AM', '2005-12-25' Refer to strtotime function in PHP manual) 
     935  return $retval; 
     936} 
     937 
     938/* 
     939      # _parse_value_for_date can parse any date field from $value given as: 
     940      # 1. $value = array('year'=>2000, 'month'=>1, 'day'=>1) and $key = 'year|month|day' 
     941      # 2. $value = timestamp and $format_char = 'h|H|i|s|A|d|m|Y' 
     942      # 3. english text presentation of date (i.e '14:23', '03:30 AM', '2005-12-25' Refer to strtotime function in PHP manual) 
    950943*/ 
    951 function _parse_value_for_date($value, $name, $format_char) 
     944function _parse_value_for_date($value, $key, $format_char) 
    952945{ 
    953946  if (is_array($value)) 
    954947  { 
    955     return (isset($value[$name])) ? $value[$name] : ''; 
     948    return (isset($value[$key])) ? $value[$key] : ''; 
    956949  } 
    957950  else if (is_numeric($value)) 
     
    964957  } 
    965958 
     959  // english text presentation 
    966960  return date($format_char, strtotime($value)); 
    967961}