Subversion-Projekte lars-tiefland.php_share

Revision

Details | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
1 lars 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: sfWidgetFormDateRange.class.php 30762 2010-08-25 12:33:33Z fabien $
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
   * Renders the widget.
46
   *
47
   * @param  string $name        The element name
48
   * @param  string $value       The date displayed in this widget
49
   * @param  array  $attributes  An array of HTML attributes to be merged with the default HTML attributes
50
   * @param  array  $errors      An array of errors for the field
51
   *
52
   * @return string An HTML tag string
53
   *
54
   * @see sfWidgetForm
55
   */
56
  public function render($name, $value = null, $attributes = array(), $errors = array())
57
  {
58
    $values = array_merge(array('from' => '', 'to' => '', 'is_empty' => ''), is_array($value) ? $value : array());
59
 
60
    return strtr($this->translate($this->getOption('template')), array(
61
      '%from_date%'      => $this->getOption('from_date')->render($name.'[from]', $value['from']),
62
      '%to_date%'        => $this->getOption('to_date')->render($name.'[to]', $value['to']),
63
    ));
64
  }
65
 
66
  /**
67
   * Gets the stylesheet paths associated with the widget.
68
   *
69
   * @return array An array of stylesheet paths
70
   */
71
  public function getStylesheets()
72
  {
73
    return array_unique(array_merge($this->getOption('from_date')->getStylesheets(), $this->getOption('to_date')->getStylesheets()));
74
  }
75
 
76
  /**
77
   * Gets the JavaScript paths associated with the widget.
78
   *
79
   * @return array An array of JavaScript paths
80
   */
81
  public function getJavaScripts()
82
  {
83
    return array_unique(array_merge($this->getOption('from_date')->getJavaScripts(), $this->getOption('to_date')->getJavaScripts()));
84
  }
85
}