Development

Changeset 24605

You must first sign up to be able to contribute.

Changeset 24605

Show
Ignore:
Timestamp:
11/30/09 22:20:19 (3 years ago)
Author:
FabianLange
Message:

[1.3, 1.4] refactored sfWidgetFormDate.class to allow easier extension and tests, as well as being easier to read (closes #7699)

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • branches/1.3/lib/widget/sfWidgetFormDate.class.php

    r16259 r24605  
    44 * This file is part of the symfony package. 
    55 * (c) Fabien Potencier <fabien.potencier@symfony-project.com> 
    6  *  
     6 * 
    77 * For the full copyright and license information, please view the LICENSE 
    88 * file that was distributed with this source code. 
     
    8383    $emptyValues = $this->getOption('empty_values'); 
    8484 
    85     // days 
    86     $widget = new sfWidgetFormSelect(array('choices' => $this->getOption('can_be_empty') ? array('' => $emptyValues['day']) + $this->getOption('days') : $this->getOption('days')), array_merge($this->attributes, $attributes)); 
    87     $date['%day%'] = $widget->render($name.'[day]', $value['day']); 
     85    $date['%day%'] = $this->renderDayWidget($name.'[day]', $value['day'], array('choices' => $this->getOption('can_be_empty') ? array('' => $emptyValues['day']) + $this->getOption('days') : $this->getOption('days')), array_merge($this->attributes, $attributes)); 
     86    $date['%month%'] = $this->renderMonthWidget($name.'[month]', $value['month'], array('choices' => $this->getOption('can_be_empty') ? array('' => $emptyValues['month']) + $this->getOption('months') : $this->getOption('months')), array_merge($this->attributes, $attributes)); 
     87    $date['%year%'] = $this->renderYearWidget($name.'[year]', $value['year'], array('choices' => $this->getOption('can_be_empty') ? array('' => $emptyValues['year']) + $this->getOption('years') : $this->getOption('years')), array_merge($this->attributes, $attributes)); 
    8888 
    89     // months 
    90     $widget = new sfWidgetFormSelect(array('choices' => $this->getOption('can_be_empty') ? array('' => $emptyValues['month']) + $this->getOption('months') : $this->getOption('months')), array_merge($this->attributes, $attributes)); 
    91     $date['%month%'] = $widget->render($name.'[month]', $value['month']); 
    92  
    93     // years 
    94     $widget = new sfWidgetFormSelect(array('choices' => $this->getOption('can_be_empty') ? array('' => $emptyValues['year']) + $this->getOption('years') : $this->getOption('years')), array_merge($this->attributes, $attributes)); 
    95     $date['%year%'] = $widget->render($name.'[year]', $value['year']); 
    9689 
    9790    return strtr($this->getOption('format'), $date); 
    9891  } 
     92 
     93  /** 
     94   * @param string $name 
     95   * @param string $value 
     96   * @param array $options 
     97   * @param array $attributes 
     98   * @return string rendered widget 
     99   */ 
     100  protected function renderDayWidget($name, $value, $options, $attributes) 
     101  { 
     102    $widget = new sfWidgetFormSelect($options, $attributes); 
     103    return $widget->render($name, $value); 
     104  } 
     105 
     106  /** 
     107   * @param string $name 
     108   * @param string $value 
     109   * @param array $options 
     110   * @param array $attributes 
     111   * @return string rendered widget 
     112   */ 
     113  protected function renderMonthWidget($name, $value, $options, $attributes) 
     114  { 
     115    $widget = new sfWidgetFormSelect($options, $attributes); 
     116    return $widget->render($name, $value); 
     117  } 
     118 
     119  /** 
     120   * @param string $name 
     121   * @param string $value 
     122   * @param array $options 
     123   * @param array $attributes 
     124   * @return string rendered widget 
     125   */ 
     126  protected function renderYearWidget($name, $value, $options, $attributes) 
     127  { 
     128    $widget = new sfWidgetFormSelect($options, $attributes); 
     129    return $widget->render($name, $value); 
     130  } 
    99131} 
  • branches/1.4/lib/widget/sfWidgetFormDate.class.php

    r16259 r24605  
    44 * This file is part of the symfony package. 
    55 * (c) Fabien Potencier <fabien.potencier@symfony-project.com> 
    6  *  
     6 * 
    77 * For the full copyright and license information, please view the LICENSE 
    88 * file that was distributed with this source code. 
     
    8383    $emptyValues = $this->getOption('empty_values'); 
    8484 
    85     // days 
    86     $widget = new sfWidgetFormSelect(array('choices' => $this->getOption('can_be_empty') ? array('' => $emptyValues['day']) + $this->getOption('days') : $this->getOption('days')), array_merge($this->attributes, $attributes)); 
    87     $date['%day%'] = $widget->render($name.'[day]', $value['day']); 
     85    $date['%day%'] = $this->renderDayWidget($name.'[day]', $value['day'], array('choices' => $this->getOption('can_be_empty') ? array('' => $emptyValues['day']) + $this->getOption('days') : $this->getOption('days')), array_merge($this->attributes, $attributes)); 
     86    $date['%month%'] = $this->renderMonthWidget($name.'[month]', $value['month'], array('choices' => $this->getOption('can_be_empty') ? array('' => $emptyValues['month']) + $this->getOption('months') : $this->getOption('months')), array_merge($this->attributes, $attributes)); 
     87    $date['%year%'] = $this->renderYearWidget($name.'[year]', $value['year'], array('choices' => $this->getOption('can_be_empty') ? array('' => $emptyValues['year']) + $this->getOption('years') : $this->getOption('years')), array_merge($this->attributes, $attributes)); 
    8888 
    89     // months 
    90     $widget = new sfWidgetFormSelect(array('choices' => $this->getOption('can_be_empty') ? array('' => $emptyValues['month']) + $this->getOption('months') : $this->getOption('months')), array_merge($this->attributes, $attributes)); 
    91     $date['%month%'] = $widget->render($name.'[month]', $value['month']); 
    92  
    93     // years 
    94     $widget = new sfWidgetFormSelect(array('choices' => $this->getOption('can_be_empty') ? array('' => $emptyValues['year']) + $this->getOption('years') : $this->getOption('years')), array_merge($this->attributes, $attributes)); 
    95     $date['%year%'] = $widget->render($name.'[year]', $value['year']); 
    9689 
    9790    return strtr($this->getOption('format'), $date); 
    9891  } 
     92 
     93  /** 
     94   * @param string $name 
     95   * @param string $value 
     96   * @param array $options 
     97   * @param array $attributes 
     98   * @return string rendered widget 
     99   */ 
     100  protected function renderDayWidget($name, $value, $options, $attributes) 
     101  { 
     102    $widget = new sfWidgetFormSelect($options, $attributes); 
     103    return $widget->render($name, $value); 
     104  } 
     105 
     106  /** 
     107   * @param string $name 
     108   * @param string $value 
     109   * @param array $options 
     110   * @param array $attributes 
     111   * @return string rendered widget 
     112   */ 
     113  protected function renderMonthWidget($name, $value, $options, $attributes) 
     114  { 
     115    $widget = new sfWidgetFormSelect($options, $attributes); 
     116    return $widget->render($name, $value); 
     117  } 
     118 
     119  /** 
     120   * @param string $name 
     121   * @param string $value 
     122   * @param array $options 
     123   * @param array $attributes 
     124   * @return string rendered widget 
     125   */ 
     126  protected function renderYearWidget($name, $value, $options, $attributes) 
     127  { 
     128    $widget = new sfWidgetFormSelect($options, $attributes); 
     129    return $widget->render($name, $value); 
     130  } 
    99131}