| 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 |
* * from_field: The name of the "from" date field (optional, default: from) |
|---|
| 29 |
* * to_field: The name of the "to" date field (optional, default: to) |
|---|
| 30 |
* |
|---|
| 31 |
* @param array $options An array of options |
|---|
| 32 |
* @param array $messages An array of error messages |
|---|
| 33 |
* |
|---|
| 34 |
* @see sfValidatorBase |
|---|
| 35 |
*/ |
|---|
| 36 |
protected function configure($options = array(), $messages = array()) |
|---|
| 37 |
{ |
|---|
| 38 |
$this->setMessage('invalid', 'The begin date must be before the end date.'); |
|---|
| 39 |
|
|---|
| 40 |
$this->addRequiredOption('from_date'); |
|---|
| 41 |
$this->addRequiredOption('to_date'); |
|---|
| 42 |
$this->addOption('from_field', 'from'); |
|---|
| 43 |
$this->addOption('to_field', 'to'); |
|---|
| 44 |
} |
|---|
| 45 |
|
|---|
| 46 |
|
|---|
| 47 |
* @see sfValidatorBase |
|---|
| 48 |
*/ |
|---|
| 49 |
protected function doClean($value) |
|---|
| 50 |
{ |
|---|
| 51 |
$fromField = $this->getOption('from_field'); |
|---|
| 52 |
$toField = $this->getOption('to_field'); |
|---|
| 53 |
|
|---|
| 54 |
$value[$fromField] = $this->getOption('from_date')->clean(isset($value[$fromField]) ? $value[$fromField] : null); |
|---|
| 55 |
$value[$toField] = $this->getOption('to_date')->clean(isset($value[$toField]) ? $value[$toField] : null); |
|---|
| 56 |
|
|---|
| 57 |
if ($value[$fromField] && $value[$toField]) |
|---|
| 58 |
{ |
|---|
| 59 |
$v = new sfValidatorSchemaCompare($fromField, sfValidatorSchemaCompare::LESS_THAN_EQUAL, $toField, array('throw_global_error' => true), array('invalid' => $this->getMessage('invalid'))); |
|---|
| 60 |
$v->clean($value); |
|---|
| 61 |
} |
|---|
| 62 |
|
|---|
| 63 |
return $value; |
|---|
| 64 |
} |
|---|
| 65 |
} |
|---|
| 66 |
|
|---|