Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
uniquevalidator.php
1<?php
10
14
15Loc::loadMessages(__FILE__);
16
18{
22 protected $errorPhraseCode = 'MAIN_ENTITY_VALIDATOR_UNIQUE';
23
24 public function validate($value, $primary, array $row, ORM\Fields\Field $field)
25 {
26 $entity = $field->getEntity();
27 $primaryNames = $entity->getPrimaryArray();
28
29 $query = new Query($entity);
30 $query->setSelect($primaryNames);
31 $query->setFilter(array('='.$field->getName() => $value));
32 $query->setLimit(2);
33 $result = $query->exec();
34
35 while ($existing = $result->fetch())
36 {
37 // check primary
38 foreach ($existing as $k => $v)
39 {
40 if (!isset($primary[$k]) || $primary[$k] != $existing[$k])
41 {
42 return $this->getErrorMessage($value, $field);
43 }
44 }
45 }
46
47 return true;
48 }
49}
static loadMessages($file)
Definition loc.php:64
validate($value, $primary, array $row, ORM\Fields\Field $field)
getErrorMessage($value, ORM\Fields\Field $field, $errorPhrase=null, $additionalTemplates=null)
Definition validator.php:50