Guest User

Untitled

a guest
Oct 20th, 2017
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.52 KB | None | 0 0
  1. public function render($name, $value = null, $attributes = array(), $errors = array())
  2. {
  3. // convert value to an array
  4. $default = array('year' => null, 'month' => null, 'day' => null);
  5. if (is_array($value))
  6. {
  7. $value = array_merge($default, $value);
  8. }
  9. else
  10. {
  11. // this bit checks if $value = [the integer of $value] - if so its a timestamp (like u get from mktime or strtotime)
  12. // and use it direct (as the date function is used below which uses a timestamp).
  13. // otherwise it uses strtotime($value) as $value comes from the db and strtotime is awesome and interprets
  14. // loads of different types of strings - importantly this returns a timestamp
  15.  
  16. $value = (string) $value == (string) (integer) $value ? (integer) $value : strtotime($value);
  17.  
  18.  
  19. // we cant use timestamps since they are the num of seconds since 1970, so we have to change all of this too: -------
  20. if (false === $value)
  21. {
  22. $value = $default;
  23. }
  24. else
  25. {
  26. $value = array('year' => date('Y', $value), 'month' => date('n', $value), 'day' => date('j', $value));
  27. }
  28. ////---------------------------------
  29.  
  30.  
  31. // here we need to produce an array like :
  32. $value = array('year' => xx, 'month' => xx, 'day' => yy);
  33.  
  34. // from a string from the db that will look like: "YYYY-MM-DD"
  35.  
  36. }
  37.  
  38. /// the rest can be left the same: --------------------------
  39. $date = array();
  40. $emptyValues = $this->getOption('empty_values');
  41.  
  42. $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));
  43. $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));
  44. $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));
  45.  
  46. return strtr($this->getOption('format'), $date);
  47. }
Add Comment
Please, Sign In to add comment