sfWidgetFormDateRange.class.php 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. <?php
  2. /*
  3. * This file is part of the symfony package.
  4. * (c) Fabien Potencier <fabien.potencier@symfony-project.com>
  5. *
  6. * For the full copyright and license information, please view the LICENSE
  7. * file that was distributed with this source code.
  8. */
  9. /**
  10. * sfWidgetFormDateRange represents a date range widget.
  11. *
  12. * @package symfony
  13. * @subpackage widget
  14. * @author Fabien Potencier <fabien.potencier@symfony-project.com>
  15. * @version SVN: $Id: sfWidgetFormDateRange.class.php 12873 2008-11-10 12:15:31Z fabien $
  16. */
  17. class sfWidgetFormDateRange extends sfWidgetForm
  18. {
  19. /**
  20. * Configures the current widget.
  21. *
  22. * Available options:
  23. *
  24. * * from_date: The from date widget (required)
  25. * * to_date: The to date widget (required)
  26. * * template: The template to use to render the widget
  27. * Available placeholders: %from_date%, %to_date%
  28. *
  29. * @param array $options An array of options
  30. * @param array $attributes An array of default HTML attributes
  31. *
  32. * @see sfWidgetForm
  33. */
  34. protected function configure($options = array(), $attributes = array())
  35. {
  36. $this->addRequiredOption('from_date');
  37. $this->addRequiredOption('to_date');
  38. $this->addOption('template', 'from %from_date% to %to_date%');
  39. }
  40. /**
  41. * @param string $name The element name
  42. * @param string $value The date displayed in this widget
  43. * @param array $attributes An array of HTML attributes to be merged with the default HTML attributes
  44. * @param array $errors An array of errors for the field
  45. *
  46. * @return string An HTML tag string
  47. *
  48. * @see sfWidgetForm
  49. */
  50. public function render($name, $value = null, $attributes = array(), $errors = array())
  51. {
  52. $values = array_merge(array('from' => '', 'to' => '', 'is_empty' => ''), is_array($value) ? $value : array());
  53. return strtr($this->getOption('template'), array(
  54. '%from_date%' => $this->getOption('from_date')->render($name.'[from]', $value['from']),
  55. '%to_date%' => $this->getOption('to_date')->render($name.'[to]', $value['to']),
  56. ));
  57. }
  58. /**
  59. * Gets the stylesheet paths associated with the widget.
  60. *
  61. * @return array An array of stylesheet paths
  62. */
  63. public function getStylesheets()
  64. {
  65. return array_unique(array_merge($this->getOption('from_date')->getStylesheets(), $this->getOption('to_date')->getStylesheets()));
  66. }
  67. /**
  68. * Gets the JavaScript paths associated with the widget.
  69. *
  70. * @return array An array of JavaScript paths
  71. */
  72. public function getJavaScripts()
  73. {
  74. return array_unique(array_merge($this->getOption('from_date')->getJavaScripts(), $this->getOption('to_date')->getJavaScripts()));
  75. }
  76. }