1. sfWidgetFormDateRange.class.php
  2. /** * sfWidgetFormDateRange represents a date range widget. * * @package symfony * @subpackage widget * @author Fabien Potencier * @version SVN: $Id: sfWidgetFormDateRange.class.php 24015 2009-11-16 13:33:34Z bschussek $ */
  3. class sfWidgetFormDateRange extends sfWidgetForm
  4. {
  5. /**
  6. * Configures the current widget.
  7. *
  8. * Available options:
  9. *
  10. * * from_date: The from date widget (required)
  11. * * to_date: The to date widget (required)
  12. * * template: The template to use to render the widget
  13. * Available placeholders: %from_date%, %to_date%
  14. *
  15. * @param array $options An array of options
  16. * @param array $attributes An array of default HTML attributes
  17. *
  18. * @see sfWidgetForm
  19. */
  20. protected function configure($options = array(), $attributes = array())
  21. {
  22. $this->addRequiredOption('from_date');
  23. $this->addRequiredOption('to_date');
  24. $this->addOption('template', 'from %from_date% to %to_date%');
  25. }
  26. /**
  27. * @param string $name The element name
  28. * @param string $value The date displayed in this widget
  29. * @param array $attributes An array of HTML attributes to be merged with the default HTML attributes
  30. * @param array $errors An array of errors for the field
  31. *
  32. * @return string An HTML tag string
  33. *
  34. * @see sfWidgetForm
  35. */
  36. public function render($name, $value = null, $attributes = array(), $errors = array())
  37. {
  38. $values = array_merge(array('from' => '', 'to' => '', 'is_empty' => ''), is_array($value) ? $value : array());
  39. return strtr($this->translate($this->getOption('template')), array(
  40. '%from_date%' => $this->getOption('from_date')->render($name.'[from]', $value['from']),
  41. '%to_date%' => $this->getOption('to_date')->render($name.'[to]', $value['to']),
  42. ));
  43. }
  44. /**
  45. * Gets the stylesheet paths associated with the widget.
  46. *
  47. * @return array An array of stylesheet paths
  48. */
  49. public function getStylesheets()
  50. {
  51. return array_unique(array_merge($this->getOption('from_date')->getStylesheets(), $this->getOption('to_date')->getStylesheets()));
  52. }
  53. /**
  54. * Gets the JavaScript paths associated with the widget.
  55. *
  56. * @return array An array of JavaScript paths
  57. */
  58. public function getJavaScripts()
  59. {
  60. return array_unique(array_merge($this->getOption('from_date')->getJavaScripts(), $this->getOption('to_date')->getJavaScripts()));
  61. }
  62. }

Debug toolbar