|
Revision 11671, 1.7 kB
(checked in by fabien, 4 years ago)
|
[1.2] added sfValidatorDateRange and sfWidgetFormDateRange
|
- 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 |
|
|---|
| 5 |
|
|---|
| 6 |
|
|---|
| 7 |
|
|---|
| 8 |
|
|---|
| 9 |
|
|---|
| 10 |
|
|---|
| 11 |
|
|---|
| 12 |
|
|---|
| 13 |
|
|---|
| 14 |
|
|---|
| 15 |
|
|---|
| 16 |
|
|---|
| 17 |
|
|---|
| 18 |
|
|---|
| 19 |
class sfValidatorDateRange extends sfValidatorBase |
|---|
| 20 |
{ |
|---|
| 21 |
|
|---|
| 22 |
* Configures the current validator. |
|---|
| 23 |
* |
|---|
| 24 |
* Available options: |
|---|
| 25 |
* |
|---|
| 26 |
* * from_date: The from date validator (required) |
|---|
| 27 |
* * to_date: The to date validator (required) |
|---|
| 28 |
* |
|---|
| 29 |
* @param array $options An array of options |
|---|
| 30 |
* @param array $messages An array of error messages |
|---|
| 31 |
* |
|---|
| 32 |
* @see sfValidatorBase |
|---|
| 33 |
*/ |
|---|
| 34 |
protected function configure($options = array(), $messages = array()) |
|---|
| 35 |
{ |
|---|
| 36 |
$this->addMessage('invalid', 'The begin date must be before the end date.'); |
|---|
| 37 |
|
|---|
| 38 |
$this->addRequiredOption('from_date'); |
|---|
| 39 |
$this->addRequiredOption('to_date'); |
|---|
| 40 |
} |
|---|
| 41 |
|
|---|
| 42 |
|
|---|
| 43 |
* @see sfValidatorBase |
|---|
| 44 |
*/ |
|---|
| 45 |
protected function doClean($value) |
|---|
| 46 |
{ |
|---|
| 47 |
$value['from'] = $this->getOption('from_date')->clean(isset($value['from']) ? $value['from'] : null); |
|---|
| 48 |
$value['to'] = $this->getOption('to_date')->clean(isset($value['to']) ? $value['to'] : null); |
|---|
| 49 |
|
|---|
| 50 |
if ($value['from'] && $value['to']) |
|---|
| 51 |
{ |
|---|
| 52 |
$v = new sfValidatorSchemaCompare('from', sfValidatorSchemaCompare::LESS_THAN_EQUAL, 'to', array('throw_global_error' => true), array('invalid' => $this->getMessage('invalid'))); |
|---|
| 53 |
$v->clean($value); |
|---|
| 54 |
} |
|---|
| 55 |
|
|---|
| 56 |
return $value; |
|---|
| 57 |
} |
|---|
| 58 |
} |
|---|
| 59 |
|
|---|