Development

/branches/1.2/lib/validator/sfValidatorDateRange.class.php

You must first sign up to be able to contribute.

root/branches/1.2/lib/validator/sfValidatorDateRange.class.php

Revision 11671, 1.7 kB (checked in by fabien, 6 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  * 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  * sfValidatorDateRange validates a range of date. It also converts the input values to valid dates.
13  *
14  * @package    symfony
15  * @subpackage validator
16  * @author     Fabien Potencier <fabien.potencier@symfony-project.com>
17  * @version    SVN: $Id$
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
Note: See TracBrowser for help on using the browser.