Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public function render($name, $value = null, $attributes = array(), $errors = array())
- {
- // convert value to an array
- $default = array('year' => null, 'month' => null, 'day' => null);
- if (is_array($value))
- {
- $value = array_merge($default, $value);
- }
- else
- {
- // this bit checks if $value = [the integer of $value] - if so its a timestamp (like u get from mktime or strtotime)
- // and use it direct (as the date function is used below which uses a timestamp).
- // otherwise it uses strtotime($value) as $value comes from the db and strtotime is awesome and interprets
- // loads of different types of strings - importantly this returns a timestamp
- $value = (string) $value == (string) (integer) $value ? (integer) $value : strtotime($value);
- // we cant use timestamps since they are the num of seconds since 1970, so we have to change all of this too: -------
- if (false === $value)
- {
- $value = $default;
- }
- else
- {
- $value = array('year' => date('Y', $value), 'month' => date('n', $value), 'day' => date('j', $value));
- }
- ////---------------------------------
- // here we need to produce an array like :
- $value = array('year' => xx, 'month' => xx, 'day' => yy);
- // from a string from the db that will look like: "YYYY-MM-DD"
- }
- /// the rest can be left the same: --------------------------
- $date = array();
- $emptyValues = $this->getOption('empty_values');
- $date['%day%'] = $this->renderDayWidget($name.'[day]', $value['day'], array('choices' => $this->getOption('can_be_empty') ? array('' => $emptyValues['day']) + $this->getOption('days') : $this->getOption('days'), 'id_format' => $this->getOption('id_format')), array_merge($this->attributes, $attributes));
- $date['%month%'] = $this->renderMonthWidget($name.'[month]', $value['month'], array('choices' => $this->getOption('can_be_empty') ? array('' => $emptyValues['month']) + $this->getOption('months') : $this->getOption('months'), 'id_format' => $this->getOption('id_format')), array_merge($this->attributes, $attributes));
- $date['%year%'] = $this->renderYearWidget($name.'[year]', $value['year'], array('choices' => $this->getOption('can_be_empty') ? array('' => $emptyValues['year']) + $this->getOption('years') : $this->getOption('years'), 'id_format' => $this->getOption('id_format')), array_merge($this->attributes, $attributes));
- return strtr($this->getOption('format'), $date);
- }
Add Comment
Please, Sign In to add comment