Development

Changeset 3294

You must first sign up to be able to contribute.

Changeset 3294

Show
Ignore:
Timestamp:
01/16/07 07:53:15 (2 years ago)
Author:
fabien
Message:

fixed support for time in admin generator and object helpers

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/data/generator/sfPropelAdmin/default/template/actions/actions.class.php

    r3293 r3294  
    250250        { 
    251251          $dateFormat = new sfDateFormat($this->getUser()->getCulture()); 
    252           <?php $inputPattern = ($type == CreoleTypes::DATE ? 'd' : 'g'); ?> 
    253           <?php $outputPattern = ($type == CreoleTypes::DATE ? 'i' : 'I'); ?> 
     252          <?php $inputPattern = $type == CreoleTypes::DATE ? 'd' : 'g'; ?> 
     253          <?php $outputPattern = $type == CreoleTypes::DATE ? 'i' : 'I'; ?> 
    254254          if (!is_array($<?php echo $this->getSingularName() ?>['<?php echo $name ?>'])) 
    255255          { 
     
    259259          { 
    260260            $value_array = $<?php echo $this->getSingularName() ?>['<?php echo $name ?>']; 
    261             $value = $value_array['year'].'-'.$value_array['month'].'-'.$value_array['day']
     261            $value = $value_array['year'].'-'.$value_array['month'].'-'.$value_array['day'].(isset($value_array['hour']) ? ' '.$value_array['hour'].':'.$value_array['minute'].(isset($value_array['second']) ? ':'.$value_array['second'] : '') : '')
    262262          } 
    263263          $this-><?php echo $this->getSingularName() ?>->set<?php echo $column->getPhpName() ?>($value); 
  • trunk/lib/helper/DateFormHelper.php

    r2849 r3294  
    588588  $ampm_seperator = _get_option($options, 'ampm_seperator', ''); 
    589589  $include_second = _get_option($options, 'include_second'); 
    590   $_12hour_time = _get_option($options, '12hour_time'); 
    591  
    592   $options['12hour_time'] = $_12hour_time; //set it back. hour tag needs it. 
     590  $_12hour_time   = _get_option($options, '12hour_time'); 
     591 
     592  $options['12hour_time'] = $_12hour_time; // set it back. hour tag needs it. 
    593593 
    594594  if ($include_custom = _get_option($options, 'include_custom')) 
     
    620620  $tags = array(); 
    621621 
    622   $hour_name = $name . '[hour]'; 
    623   $tags[] = select_hour_tag($hour_name, _parse_value_for_date($value, 'hour', ($_12hour_time) ? 'h' : 'H'), $options + $include_custom_hour, $html_options); 
    624  
    625   $minute_name = $name . '[minute]'; 
     622  $hour_name = $name.'[hour]'; 
     623  $tags[] = select_hour_tag($hour_name, _parse_value_for_date($value, 'hour', $_12hour_time ? 'h' : 'H'), $options + $include_custom_hour, $html_options); 
     624 
     625  $minute_name = $name.'[minute]'; 
    626626  $tags[] = select_minute_tag($minute_name, _parse_value_for_date($value, 'minute', 'i'), $options + $include_custom_minute, $html_options); 
    627627 
    628628  if ($include_second) 
    629629  { 
    630     $second_name = $name . '[second]'; 
     630    $second_name = $name.'[second]'; 
    631631    $tags[] = select_second_tag($second_name, _parse_value_for_date($value, 'second', 's'), $options + $include_custom_second, $html_options); 
    632632  } 
     
    636636  if ($_12hour_time) 
    637637  { 
    638     $ampm_name = $name . "[ampm]"
    639     $time .=  $ampm_seperator . select_ampm_tag($ampm_name, _parse_value_for_date($value, 'ampm', 'A'), $options + $include_custom_ampm, $html_options); 
     638    $ampm_name = $name.'[ampm]'
     639    $time .=  $ampm_seperator.select_ampm_tag($ampm_name, _parse_value_for_date($value, 'ampm', 'A'), $options + $include_custom_ampm, $html_options); 
    640640  } 
    641641 
  • trunk/lib/helper/FormHelper.php

    r3290 r3294  
    619619  $culture = _get_option($options, 'culture', $context->getUser()->getCulture()); 
    620620 
     621  $withTime = _get_option($options, 'withtime', false); 
     622 
    621623  // rich control? 
    622624  if (!_get_option($options, 'rich', false)) 
     
    627629    $options['culture'] = $culture; 
    628630 
    629     return select_date_tag($name, $value, $options, isset($options['html']) ? $options['html'] : array()); 
    630   } 
    631  
    632   if ($withTime = _get_option($options, 'withtime', false)) 
    633   { 
    634     $pattern = 'g'; 
    635   } 
    636   else 
    637   { 
    638     $pattern = 'd'; 
    639   } 
    640  
    641   $pattern = _get_option($options, 'format', $pattern); 
     631    if ($withTime) 
     632    { 
     633      return select_datetime_tag($name, $value, $options, isset($options['html']) ? $options['html'] : array()); 
     634    } 
     635    else 
     636    { 
     637      return select_date_tag($name, $value, $options, isset($options['html']) ? $options['html'] : array()); 
     638    } 
     639  } 
     640 
     641  $pattern = _get_option($options, 'format', $withTime ? 'g' : 'd'); 
    642642 
    643643  $dateFormat = new sfDateFormat($culture); 
  • trunk/lib/helper/ObjectHelper.php

    r3184 r3294  
    3535  $options = _parse_attributes($options); 
    3636 
    37   $value = _get_object_value($object, $method, $default_value, $param = 'Y-m-d'); 
     37  $value = _get_object_value($object, $method, $default_value, $param = 'Y-m-d G:i'); 
    3838 
    3939  return input_date_tag(_convert_method_to_name($method, $options), $value, $options); 
  • trunk/test/functional/backend/timeTest.php

    r3293 r3294  
    3232; 
    3333 
    34 // non rich date 
    35 $tomorrow = time() + 86400
     34// non rich date (without time) 
     35$tomorrow = time() + 86400 + 3600
    3636$b-> 
    37   customizeGenerator(array('edit' => array('fields' => array('end_date' => array('params' => 'rich=false')))))-> 
     37  customizeGenerator(array('edit' => array('fields' => array('end_date' => array('params' => 'withtime=false rich=false')))))-> 
    3838 
    3939  post('/article/edit/id/1', array('article' => array('end_date' => array('day' => date('d', $tomorrow), 'month' => date('m', $tomorrow), 'year' => date('Y', $tomorrow)))))-> 
     
    4646  checkResponseElement(sprintf('select[name="article[end_date][day]"] option[value="%s"][selected="selected"]', date('d', $tomorrow)))-> 
    4747  checkResponseElement(sprintf('select[name="article[end_date][month]"] option[value="%s"][selected="selected"]', date('m', $tomorrow)))-> 
    48   checkResponseElement(sprintf('select[name="article[end_date][year]"] option[value="%s"][selected="selected"]', date('Y', $tomorrow))) 
     48  checkResponseElement(sprintf('select[name="article[end_date][year]"] option[value="%s"][selected="selected"]', date('Y', $tomorrow)))-> 
     49  checkResponseElement('select[name="article[end_date][hour]"]', false)-> 
     50  checkResponseElement('select[name="article[end_date][minute]"]', false) 
    4951; 
     52 
     53// non rich date (with time) 
     54$b-> 
     55  customizeGenerator(array('edit' => array('fields' => array('end_date' => array('params' => 'withtime=true rich=false')))))-> 
     56 
     57  post('/article/edit/id/1', array('article' => array('end_date' => array('day' => date('d', $tomorrow), 'month' => date('m', $tomorrow), 'year' => date('Y', $tomorrow), 'hour' => date('G', $tomorrow), 'minute' => date('i', $tomorrow)))))-> 
     58  isStatusCode(302)-> 
     59  isRequestParameter('module', 'article')-> 
     60  isRequestParameter('action', 'edit')-> 
     61 
     62  isRedirected(true)-> 
     63  followRedirect()-> 
     64  checkResponseElement(sprintf('select[name="article[end_date][day]"] option[value="%s"][selected="selected"]', date('d', $tomorrow)))-> 
     65  checkResponseElement(sprintf('select[name="article[end_date][month]"] option[value="%s"][selected="selected"]', date('m', $tomorrow)))-> 
     66  checkResponseElement(sprintf('select[name="article[end_date][year]"] option[value="%s"][selected="selected"]', date('Y', $tomorrow)))-> 
     67  checkResponseElement(sprintf('select[name="article[end_date][hour]"] option[value="%s"][selected="selected"]', date('G', $tomorrow)))-> 
     68  checkResponseElement(sprintf('select[name="article[end_date][minute]"] option[value="%s"][selected="selected"]', date('i', $tomorrow))) 
     69; 
  • trunk/test/unit/helper/DateFormHelperTest.php

    r2849 r3294  
    8181} 
    8282 
    83 $t = new lime_test(77, new lime_output_color()); 
     83$t = new lime_test(81, new lime_output_color()); 
    8484 
    8585$context = sfContext::getInstance(); 
     
    189189// select_time_tag() 
    190190$t->diag('select_time_tag()'); 
     191$t->like(select_time_tag('time'), '/<select name="time\[hour\]" id="time_hour">/', 'select_time_tag() outputs a select tag for hours'); 
     192$t->like(select_time_tag('time'), '/selected="selected">'.date('H').'/', 'select_time_tag() selects the current hours by default'); 
     193$t->like(select_time_tag('time'), '/<select name="time\[minute\]" id="time_minute">/', 'select_time_tag() outputs a select tag for minutes'); 
     194$t->like(select_time_tag('time'), '/selected="selected">'.date('i').'/', 'select_time_tag() selects the current minutes by default'); 
    191195$t->todo('select_time_tag()'); 
    192196