Bitrix-D7
23.9
Загрузка...
Поиск...
Не найдено
uniquevalidator.php
1
<?php
9
namespace
Bitrix\Main\ORM\Fields\Validators
;
10
11
use
Bitrix\Main\ORM
;
12
use
Bitrix\Main\ORM\Query\Query
;
13
use
Bitrix\Main\Localization\Loc
;
14
15
Loc::loadMessages
(__FILE__);
16
17
class
UniqueValidator
extends
Validator
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
}
Bitrix\Main\Localization\Loc
Definition
loc.php:11
Bitrix\Main\Localization\Loc\loadMessages
static loadMessages($file)
Definition
loc.php:64
Bitrix\Main\ORM\Fields\Field
Definition
field.php:25
Bitrix\Main\ORM\Fields\Validators\UniqueValidator
Definition
uniquevalidator.php:18
Bitrix\Main\ORM\Fields\Validators\UniqueValidator\$errorPhraseCode
$errorPhraseCode
Definition
uniquevalidator.php:22
Bitrix\Main\ORM\Fields\Validators\UniqueValidator\validate
validate($value, $primary, array $row, ORM\Fields\Field $field)
Definition
uniquevalidator.php:24
Bitrix\Main\ORM\Fields\Validators\Validator
Definition
validator.php:18
Bitrix\Main\ORM\Fields\Validators\Validator\getErrorMessage
getErrorMessage($value, ORM\Fields\Field $field, $errorPhrase=null, $additionalTemplates=null)
Definition
validator.php:50
Bitrix\Main\ORM\Query\Query
Definition
query.php:118
Bitrix\Main\ORM\Fields\Validators
Definition
booleanvalidator.php:9
Bitrix\Main\ORM
modules
main
lib
orm
fields
validators
uniquevalidator.php
Создано системой
1.10.0