Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
foreignvalidator.php
1<?php
10
13
14Loc::loadMessages(__FILE__);
15
24{
25 protected $errorPhraseCode = 'MAIN_ENTITY_VALIDATOR_FOREIGN';
26 protected $reference = null;
27 protected $filter = null;
28 const NOT_EXISTS = 'BX_FOREIGN_NOT_EXISTS';
29
34 public function __construct(ORM\Fields\Field $reference, array $filter = array())
35 {
36 $this->reference = $reference;
37 $this->filter = $filter;
38 parent::__construct();
39 }
40
41 public function validate($value, $primary, array $row, ORM\Fields\Field $field)
42 {
43 $query = new ORM\Query\Query($this->reference->getEntity());
44 $query->setFilter(array('='.$this->reference->getName() => $value) + $this->filter);
45 $query->setLimit(1);
46 $result = $query->exec();
47
48 if($result->fetch())
49 {
50 return true;
51 }
52 return new ORM\Fields\FieldError($field, $this->getErrorMessage($value, $field), self::NOT_EXISTS);
53 }
54}
static loadMessages($file)
Definition loc.php:64
__construct(ORM\Fields\Field $reference, array $filter=array())
validate($value, $primary, array $row, ORM\Fields\Field $field)
getErrorMessage($value, ORM\Fields\Field $field, $errorPhrase=null, $additionalTemplates=null)
Definition validator.php:50