Development

/branches/1.2/lib/plugins/sfDoctrinePlugin/lib/validator/sfValidatorDoctrineChoiceMany.class.php

You must first sign up to be able to contribute.

root/branches/1.2/lib/plugins/sfDoctrinePlugin/lib/validator/sfValidatorDoctrineChoiceMany.class.php

Revision 16964, 1.4 kB (checked in by Jonathan.Wage, 6 years ago)

[1.2, 1.3] sfDoctrinePlugin: fixing sfValidatorDoctrineChoiceMany and reverting change to make it equal to Propel (closes #4511)

Line 
1 <?php
2
3 /*
4  * This file is part of the symfony package.
5  * (c) Fabien Potencier <fabien.potencier@symfony-project.com>
6  * (c) Jonathan H. Wage <jonwage@gmail.com>
7  *
8  * For the full copyright and license information, please view the LICENSE
9  * file that was distributed with this source code.
10  */
11
12 /**
13  * sfValidatorDoctrineChoiceMany validates than an array of values is in the array of the existing rows of a table.
14  *
15  * @package    symfony
16  * @subpackage doctrine
17  * @author     Fabien Potencier <fabien.potencier@symfony-project.com>
18  * @author     Jonathan H. Wage <jonwage@gmail.com>
19  * @version    SVN: $Id: sfValidatorDoctrineChoiceMany.class.php 7902 2008-03-15 13:17:33Z fabien $
20  */
21 class sfValidatorDoctrineChoiceMany extends sfValidatorDoctrineChoice
22 {
23   /**
24    * @see sfValidatorBase
25    */
26   protected function doClean($values)
27   {
28     if (!is_array($values))
29     {
30       $values = array($values);
31     }
32
33     if(isset($values[0]) && !$values[0])
34     {
35       unset($values[0]);
36     }
37
38     $a = $this->getOption('alias');
39     $q = is_null($this->getOption('query')) ? Doctrine_Query::create()->from($this->getOption('model') . ' ' . $a) : $this->getOption('query');
40     $q = $q->andWhereIn($a . '.' . $this->getColumn(), $values);
41
42     $objects = $q->execute();
43
44     if (count($objects) != count($values))
45     {
46       throw new sfValidatorError($this, 'invalid', array('value' => $values));
47     }
48
49     return $values;
50   }
51 }
52
Note: See TracBrowser for help on using the browser.