Development

Changeset 1434

You must first sign up to be able to contribute.

Changeset 1434

Show
Ignore:
Timestamp:
06/13/06 14:27:05 (2 years ago)
Author:
fabien
Message:
  • Renamed _add_zeros to _prepend_zeros to actually describe what the function does.
  • Updated all Date/Time form helpers to accept a null value. If null, we assign the value to the current date/time value for that tag.

(patch from slickrick)

Files:

Legend:

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

    r1433 r1434  
    562562} 
    563563 
    564 function select_day_tag($name, $value, $options = array(), $html_options = array()) 
    565 
     564function select_day_tag($name, $value = null, $options = array(), $html_options = array()) 
     565
     566  if ($value === null) 
     567  { 
     568    $value = date('j'); 
     569  } 
     570     
    566571  $options = _parse_attributes($options); 
    567572 
     
    578583  for ($x = 1; $x < 32; $x++) 
    579584  { 
    580     $select_options[$x] = _add_zeros($x, 2); 
     585    $select_options[$x] = _prepend_zeros($x, 2); 
    581586  } 
    582587 
     
    584589} 
    585590 
    586 function select_month_tag($name, $value, $options = array(), $html_options = array()) 
    587 
     591function select_month_tag($name, $value = null, $options = array(), $html_options = array()) 
     592
     593  if ($value === null) 
     594  { 
     595    $value = date('n'); 
     596  } 
     597     
    588598  $options = _parse_attributes($options); 
    589599 
     
    605615    for ($k = 1; $k < 13; $k++)  
    606616    { 
    607       $select_options[$k] = _add_zeros($k, 2); 
     617      $select_options[$k] = _prepend_zeros($k, 2); 
    608618    } 
    609619  } 
     
    629639} 
    630640 
    631 function select_year_tag($name, $value, $options = array(), $html_options = array()) 
    632 
     641function select_year_tag($name, $value = null, $options = array(), $html_options = array()) 
     642
     643  if ($value === null) 
     644  { 
     645    $value = date('Y'); 
     646  } 
     647     
    633648  $options = _parse_attributes($options); 
    634649 
     
    675690 * @return string 
    676691 */ 
    677 function select_date_tag($name, $value, $options = array(), $html_options = array()) 
     692function select_date_tag($name, $value = null, $options = array(), $html_options = array()) 
    678693{ 
    679694  $options = _parse_attributes($options); 
     
    733748  } 
    734749 
    735   $html_options['id'] = $name . '_month'; 
    736   $m = (!$discard_month) ? select_month_tag($name . '[month]', _parse_value_for_date($value, 'month', 'm'), $options + $include_custom_month, $html_options) : ''; 
    737  
    738   $html_options['id'] = $name . '_day'; 
    739   $d = (!$discard_day) ? select_day_tag($name . '[day]', _parse_value_for_date($value, 'day', 'd'), $options + $include_custom_day, $html_options) : ''; 
    740  
    741   $html_options['id'] = $name . '_year'; 
    742   $y = (!$discard_year) ? select_year_tag($name . '[year]', _parse_value_for_date($value, 'year', 'Y'), $options + $include_custom_year, $html_options) : ''; 
     750  $month_name = $name . '[month]'; 
     751  $m = (!$discard_month) ? select_month_tag($month_name, _parse_value_for_date($value, 'month', 'm'), $options + $include_custom_month, $html_options) : ''; 
     752 
     753 
     754  $day_name = $name . '[day]'; 
     755  $d = (!$discard_day) ? select_day_tag($day_name, _parse_value_for_date($value, 'day', 'd'), $options + $include_custom_day, $html_options) : ''; 
     756 
     757  $year_name = $name . '[year]'; 
     758  $y = (!$discard_year) ? select_year_tag($year_name, _parse_value_for_date($value, 'year', 'Y'), $options + $include_custom_year, $html_options) : ''; 
    743759 
    744760  // we have $tags = array ('m','d','y') 
     
    752768} 
    753769 
    754 function select_second_tag($name, $value, $options = array(), $html_options = array()) 
    755 
     770function select_second_tag($name, $value = null, $options = array(), $html_options = array()) 
     771
     772  if ($value === null) 
     773  { 
     774    $value = date('s'); 
     775  } 
     776   
    756777  $options = _parse_attributes($options); 
    757778  $select_options = array(); 
     
    769790  for ($x = 0; $x < 60; $x += $second_step) 
    770791  { 
    771     $select_options[$x] = _add_zeros($x, 2); 
     792    $select_options[$x] = _prepend_zeros($x, 2); 
    772793  } 
    773794 
     
    775796} 
    776797 
    777 function select_minute_tag($name, $value, $options = array(), $html_options = array()) 
    778 
     798function select_minute_tag($name, $value = null, $options = array(), $html_options = array()) 
     799
     800  if ($value === null) 
     801  { 
     802    $value = date('i'); 
     803  } 
     804     
    779805  $options = _parse_attributes($options); 
    780806  $select_options = array(); 
     
    792818  for ($x = 0; $x < 60; $x += $minute_step) 
    793819  { 
    794     $select_options[$x] = _add_zeros($x, 2); 
     820    $select_options[$x] = _prepend_zeros($x, 2); 
    795821  } 
    796822 
     
    798824} 
    799825 
    800 function select_hour_tag($name, $value, $options = array(), $html_options = array()) 
    801 
     826function select_hour_tag($name, $value = null, $options = array(), $html_options = array()) 
     827
     828  if ($value === null) 
     829  { 
     830    $value = date('h'); 
     831  } 
     832     
    802833  $options = _parse_attributes($options); 
    803834  $select_options = array(); 
     
    819850  for ($x = $start_hour; $x <= $end_hour; $x++) 
    820851  { 
    821     $select_options[$x] = _add_zeros($x, 2); 
     852    $select_options[$x] = _prepend_zeros($x, 2); 
    822853  } 
    823854 
     
    825856} 
    826857 
    827 function select_ampm_tag($name, $value, $options = array(), $html_options = array()) 
    828 
     858function select_ampm_tag($name, $value = null, $options = array(), $html_options = array()) 
     859
     860  if ($value === null) 
     861  { 
     862    $value = date('A'); 
     863  } 
     864     
    829865  $options = _parse_attributes($options); 
    830866  $select_options = array(); 
     
    854890 * @return string 
    855891 */ 
    856 function select_time_tag($name, $value, $options = array(), $html_options = array()) 
     892function select_time_tag($name, $value = null, $options = array(), $html_options = array()) 
    857893{ 
    858894  $options = _parse_attributes($options); 
     
    893929  $tags = array(); 
    894930 
    895   $html_options['id'] = $name . '_hour'; 
    896   $tags[] = select_hour_tag($name . '[hour]', _parse_value_for_date($value, 'hour', ($_12hour_time) ? 'h' : 'H'), $options + $include_custom_hour, $html_options); 
    897  
    898   $html_options['id'] = $name . '_minute'; 
    899   $tags[] = select_minute_tag($name . '[minute]', _parse_value_for_date($value, 'minute', 'i'), $options + $include_custom_minute, $html_options); 
     931  $hour_name = $name . '[hour]'; 
     932  $tags[] = select_hour_tag($hour_name, _parse_value_for_date($value, 'hour', ($_12hour_time) ? 'h' : 'H'), $options + $include_custom_hour, $html_options); 
     933 
     934  $minute_name = $name . '[minute]'; 
     935  $tags[] = select_minute_tag($minute_name, _parse_value_for_date($value, 'minute', 'i'), $options + $include_custom_minute, $html_options); 
    900936 
    901937  if ($include_second) 
    902938  { 
    903     $html_options['id'] = $name . '_second'; 
    904     $tags[] = select_second_tag($name . "[second]" , _parse_value_for_date($value, 'second', 's'), $options + $include_custom_second, $html_options); 
     939    $second_name = $name . '[second]'; 
     940    $tags[] = select_second_tag($second_name, _parse_value_for_date($value, 'second', 's'), $options + $include_custom_second, $html_options); 
    905941  } 
    906942 
     
    909945  if ($_12hour_time) 
    910946  { 
    911     $html_options['id'] = $name . '_ampm'
    912     $time .=  $ampm_seperator . select_ampm_tag($name . "[ampm]" , _parse_value_for_date($value, 'ampm', 'A'), $options + $include_custom_ampm, $html_options); 
     947    $ampm_name = $name . "[ampm]"
     948    $time .=  $ampm_seperator . select_ampm_tag($ampm_name, _parse_value_for_date($value, 'ampm', 'A'), $options + $include_custom_ampm, $html_options); 
    913949  } 
    914950 
     
    924960 * @return string 
    925961 */ 
    926 function select_datetime_tag($name, $value, $options = array(), $html_options = array()) 
     962function select_datetime_tag($name, $value = null, $options = array(), $html_options = array()) 
    927963{ 
    928964  $options = _parse_attributes($options); 
     
    957993} 
    958994 
    959 function _add_zeros($string, $strlen) 
     995function _prepend_zeros($string, $strlen) 
    960996{ 
    961997  if ($strlen > strlen($string)) 
     
    10261062    return $value; 
    10271063  } 
     1064  else if (empty($value)) 
     1065  { 
     1066    $value = date('Y-m-d H:i:s'); 
     1067  } 
    10281068 
    10291069  // english text presentation