Development

/branches/1.4/lib/widget/sfWidgetFormFilterDate.class.php

You must first sign up to be able to contribute.

root/branches/1.4/lib/widget/sfWidgetFormFilterDate.class.php

Revision 30762, 2.7 kB (checked in by fabien, 4 years ago)

[1.3, 1.4] fixed phpdoc (closes #8931)

  • Property svn:mime-type set to text/x-php
  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
Line 
1 <?php
2
3 /*
4  * This file is part of the symfony package.
5  * (c) Fabien Potencier <fabien.potencier@symfony-project.com>
6  *
7  * For the full copyright and license information, please view the LICENSE
8  * file that was distributed with this source code.
9  */
10
11 /**
12  * sfWidgetFormFilterDate represents a date filter widget.
13  *
14  * @package    symfony
15  * @subpackage widget
16  * @author     Fabien Potencier <fabien.potencier@symfony-project.com>
17  * @version    SVN: $Id$
18  */
19 class sfWidgetFormFilterDate extends sfWidgetFormDateRange
20 {
21   /**
22    * Configures the current widget.
23    *
24    * Available options:
25    *
26    *  * with_empty:      Whether to add the empty checkbox (true by default)
27    *  * empty_label:     The label to use when using an empty checkbox
28    *  * template:        The template used for from date and to date
29    *                     Available placeholders: %from_date%, %to_date%
30    *  * filter_template: The template to use to render the widget
31    *                     Available placeholders: %date_range%, %empty_checkbox%, %empty_label%
32    *
33    * @param array $options     An array of options
34    * @param array $attributes  An array of default HTML attributes
35    *
36    * @see sfWidgetForm
37    */
38   protected function configure($options = array(), $attributes = array())
39   {
40     parent::configure($options, $attributes);
41
42     $this->addOption('with_empty', true);
43     $this->addOption('empty_label', 'is empty');
44     $this->addOption('template', 'from %from_date%<br />to %to_date%');
45     $this->addOption('filter_template', '%date_range%<br />%empty_checkbox% %empty_label%');
46   }
47
48   /**
49    * Renders the widget.
50    *
51    * @param  string $name        The element name
52    * @param  string $value       The date displayed in this widget
53    * @param  array  $attributes  An array of HTML attributes to be merged with the default HTML attributes
54    * @param  array  $errors      An array of errors for the field
55    *
56    * @return string An HTML tag string
57    *
58    * @see sfWidgetForm
59    */
60   public function render($name, $value = null, $attributes = array(), $errors = array())
61   {
62     $values = array_merge(array('is_empty' => ''), is_array($value) ? $value : array());
63
64     return strtr($this->getOption('filter_template'), array(
65       '%date_range%'     => parent::render($name, $value, $attributes, $errors),
66       '%empty_checkbox%' => $this->getOption('with_empty') ? $this->renderTag('input', array('type' => 'checkbox', 'name' => $name.'[is_empty]', 'checked' => $values['is_empty'] ? 'checked' : '')) : '',
67       '%empty_label%'    => $this->getOption('with_empty') ? $this->renderContentTag('label', $this->translate($this->getOption('empty_label')), array('for' => $this->generateId($name.'[is_empty]'))) : '',
68     ));
69   }
70 }
71
Note: See TracBrowser for help on using the browser.