1. sfWidgetFormFilterDate.class.php
  2. /** * sfWidgetFormFilterDate represents a date filter widget. * * @package symfony * @subpackage widget * @author Fabien Potencier * @version SVN: $Id: sfWidgetFormFilterDate.class.php 24015 2009-11-16 13:33:34Z bschussek $ */
  3. class sfWidgetFormFilterDate extends sfWidgetFormDateRange
  4. {
  5. /**
  6. * Configures the current widget.
  7. *
  8. * Available options:
  9. *
  10. * * with_empty: Whether to add the empty checkbox (true by default)
  11. * * empty_label: The label to use when using an empty checkbox
  12. * * template: The template used for from date and to date
  13. * Available placeholders: %from_date%, %to_date%
  14. * * filter_template: The template to use to render the widget
  15. * Available placeholders: %date_range%, %empty_checkbox%, %empty_label%
  16. *
  17. * @param array $options An array of options
  18. * @param array $attributes An array of default HTML attributes
  19. *
  20. * @see sfWidgetForm
  21. */
  22. protected function configure($options = array(), $attributes = array())
  23. {
  24. parent::configure($options, $attributes);
  25. $this->addOption('with_empty', true);
  26. $this->addOption('empty_label', 'is empty');
  27. $this->addOption('template', 'from %from_date%<br />to %to_date%');
  28. $this->addOption('filter_template', '%date_range%<br />%empty_checkbox% %empty_label%');
  29. }
  30. /**
  31. * @param string $name The element name
  32. * @param string $value The date displayed in this widget
  33. * @param array $attributes An array of HTML attributes to be merged with the default HTML attributes
  34. * @param array $errors An array of errors for the field
  35. *
  36. * @return string An HTML tag string
  37. *
  38. * @see sfWidgetForm
  39. */
  40. public function render($name, $value = null, $attributes = array(), $errors = array())
  41. {
  42. $values = array_merge(array('is_empty' => ''), is_array($value) ? $value : array());
  43. return strtr($this->getOption('filter_template'), array(
  44. '%date_range%' => parent::render($name, $value, $attributes, $errors),
  45. '%empty_checkbox%' => $this->getOption('with_empty') ? $this->renderTag('input', array('type' => 'checkbox', 'name' => $name.'[is_empty]', 'checked' => $values['is_empty'] ? 'checked' : '')) : '',
  46. '%empty_label%' => $this->getOption('with_empty') ? $this->renderContentTag('label', $this->translate($this->getOption('empty_label')), array('for' => $this->generateId($name.'[is_empty]'))) : '',
  47. ));
  48. }
  49. }

Debug toolbar