123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131 |
- <?php
- class sfWidgetFormDateTime extends sfWidgetForm
- {
-
- protected function configure($options = array(), $attributes = array())
- {
- $this->addOption('date', array());
- $this->addOption('time', array());
- $this->addOption('with_time', true);
- $this->addOption('format', '%date% %time%');
- }
-
- function render($name, $value = null, $attributes = array(), $errors = array())
- {
- $date = $this->getDateWidget($attributes)->render($name, $value);
- if (!$this->getOption('with_time'))
- {
- return $date;
- }
- return strtr($this->getOption('format'), array(
- '%date%' => $date,
- '%time%' => $this->getTimeWidget($attributes)->render($name, $value),
- ));
- }
-
- protected function getDateWidget($attributes = array())
- {
- return new sfWidgetFormDate($this->getOptionsFor('date'), $this->getAttributesFor('date', $attributes));
- }
-
- protected function getTimeWidget($attributes = array())
- {
- return new sfWidgetFormTime($this->getOptionsFor('time'), $this->getAttributesFor('time', $attributes));
- }
-
- protected function getOptionsFor($type)
- {
- $options = $this->getOption($type);
- if (!is_array($options))
- {
- throw new InvalidArgumentException(sprintf('You must pass an array for the %s option.', $type));
- }
- return $options;
- }
-
- protected function getAttributesFor($type, $attributes)
- {
- $defaults = isset($this->attributes[$type]) ? $this->attributes[$type] : array();
- return isset($attributes[$type]) ? array_merge($defaults, $attributes[$type]) : $defaults;
- }
- }
|