DiscountPhoneForm.class.php 995 Bytes
Newer Older
Яков's avatar
first  
Яков committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
<?php

/**
 * DiscountPhone form.
 *
 * @package    sf
 * @subpackage form
 * @author     Atma
 * @version    SVN: $Id: sfDoctrineFormTemplate.php 23810 2009-11-12 11:07:44Z Kris.Wallsmith $
 */
class DiscountPhoneForm extends BaseDiscountPhoneForm
{
	public function configure()
	{
		$this->useFields(array('phone', 'discount_id', 'order_id'));
	}

	public function isValid()
	{
	    $is_valid = parent::isValid();
	    if ($is_valid) {
	        $dp = Doctrine_Query::create()
                ->from("DiscountPhone dp")
                ->where("dp.phone = ?", $this->getValue('phone'))
                ->andWhere("dp.id != ?", $this->getValue('id'))
                ->andWhere("dp.order_id is null")
                ->count();
	        if($dp > 0) {
	        	$is_valid = false;
	        	$this->getErrorSchema()->addError(new sfValidatorError($this->getValidator('phone'), 'Пользователь уже добавил скидку'), 'phone');
	        }
	    }
	    return $is_valid;
	}
}