wpWidgetFormRichDate.class.php 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. <?php
  2. class wpWidgetFormRichDate extends sfWidgetFormDate {
  3. /**
  4. *
  5. * @param array $options An array of options
  6. * @param array $attributes An array of default HTML attributes
  7. * @see sfWidgetForm
  8. */
  9. protected function configure($options = array(), $attributes = array()) {
  10. $this->setAttributes(array(
  11. // 'withtime' => true,
  12. 'rich' => true,
  13. 'calendar_button_img' => '/sf/sf_admin/images/date.png',
  14. 'css' => 'skins/aqua/theme',
  15. 'format' => 'dd/MM/yyyy',
  16. 'culture' => 'fr',
  17. ));
  18. parent::configure($options, $attributes);
  19. }
  20. /**
  21. *
  22. * @param string $name The element name
  23. * @param string $value The value displayed in this widget
  24. * @param array $attributes An array of HTML attributes to be merged with the default HTML attributes
  25. * @param array $errors An array of errors for the field
  26. * @return string An HTML tag string
  27. * @see sfWidgetForm
  28. */
  29. public function render($name, $value = null, $attributes = array(), $errors = array()) {
  30. use_helper('Form');
  31. try {
  32. if (preg_match('#([0-9]+)/([0-9]+)/([0-9]+)#', $value, $tokens)) {
  33. $value = sprintf('%04d-%02d-%02d', $tokens[3], $tokens[2], $tokens[1]);
  34. }
  35. $result = input_date_tag($name, $value, array_merge($this->attributes, $attributes));
  36. }
  37. catch(Exception $e) {
  38. $result = input_date_tag($name, null, array_merge($this->attributes, $attributes));
  39. }
  40. return $result;
  41. }
  42. }