| 1 |
<?php |
|---|
| 2 |
|
|---|
| 3 |
|
|---|
| 4 |
|
|---|
| 5 |
|
|---|
| 6 |
|
|---|
| 7 |
|
|---|
| 8 |
|
|---|
| 9 |
|
|---|
| 10 |
|
|---|
| 11 |
|
|---|
| 12 |
|
|---|
| 13 |
|
|---|
| 14 |
|
|---|
| 15 |
|
|---|
| 16 |
|
|---|
| 17 |
|
|---|
| 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 |
|
|---|