Development

/branches/1.2/lib/widget/sfWidgetFormDateRange.class.php

You must first sign up to be able to contribute.

root/branches/1.2/lib/widget/sfWidgetFormDateRange.class.php

Revision 12873, 2.6 kB (checked in by fabien, 6 years ago)

[1.2] added CSS and JS support to sfWidgetFormDateRange widget (closes #4831)

  • 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  * sfWidgetFormDateRange represents a date range widget.
13  *
14  * @package    symfony
15  * @subpackage widget
16  * @author     Fabien Potencier <fabien.potencier@symfony-project.com>
17  * @version    SVN: $Id$
18  */
19 class sfWidgetFormDateRange extends sfWidgetForm
20 {
21   /**
22    * Configures the current widget.
23    *
24    * Available options:
25    *
26    *  * from_date:   The from date widget (required)
27    *  * to_date:     The to date widget (required)
28    *  * template:    The template to use to render the widget
29    *                 Available placeholders: %from_date%, %to_date%
30    *
31    * @param array $options     An array of options
32    * @param array $attributes  An array of default HTML attributes
33    *
34    * @see sfWidgetForm
35    */
36   protected function configure($options = array(), $attributes = array())
37   {
38     $this->addRequiredOption('from_date');
39     $this->addRequiredOption('to_date');
40
41     $this->addOption('template', 'from %from_date% to %to_date%');
42   }
43
44   /**
45    * @param  string $name        The element name
46    * @param  string $value       The date displayed in this widget
47    * @param  array  $attributes  An array of HTML attributes to be merged with the default HTML attributes
48    * @param  array  $errors      An array of errors for the field
49    *
50    * @return string An HTML tag string
51    *
52    * @see sfWidgetForm
53    */
54   public function render($name, $value = null, $attributes = array(), $errors = array())
55   {
56     $values = array_merge(array('from' => '', 'to' => '', 'is_empty' => ''), is_array($value) ? $value : array());
57
58     return strtr($this->getOption('template'), array(
59       '%from_date%'      => $this->getOption('from_date')->render($name.'[from]', $value['from']),
60       '%to_date%'        => $this->getOption('to_date')->render($name.'[to]', $value['to']),
61     ));
62   }
63
64   /**
65    * Gets the stylesheet paths associated with the widget.
66    *
67    * @return array An array of stylesheet paths
68    */
69   public function getStylesheets()
70   {
71     return array_unique(array_merge($this->getOption('from_date')->getStylesheets(), $this->getOption('to_date')->getStylesheets()));
72   }
73
74   /**
75    * Gets the JavaScript paths associated with the widget.
76    *
77    * @return array An array of JavaScript paths
78    */
79   public function getJavaScripts()
80   {
81     return array_unique(array_merge($this->getOption('from_date')->getJavaScripts(), $this->getOption('to_date')->getJavaScripts()));
82   }
83 }
84
Note: See TracBrowser for help on using the browser.