Bitrix-D7
23.9
Загрузка...
Поиск...
Не найдено
foreignvalidator.php
1
<?php
9
namespace
Bitrix\Main\ORM\Fields\Validators
;
10
11
use
Bitrix\Main\ORM
;
12
use
Bitrix\Main\Localization\Loc
;
13
14
Loc::loadMessages
(__FILE__);
15
23
class
ForeignValidator
extends
Validator
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
}
Bitrix\Main\Localization\Loc
Definition
loc.php:11
Bitrix\Main\Localization\Loc\loadMessages
static loadMessages($file)
Definition
loc.php:64
Bitrix\Main\ORM\Fields\FieldError
Definition
fielderror.php:14
Bitrix\Main\ORM\Fields\Field
Definition
field.php:25
Bitrix\Main\ORM\Fields\Validators\ForeignValidator
Definition
foreignvalidator.php:24
Bitrix\Main\ORM\Fields\Validators\ForeignValidator\$reference
$reference
Definition
foreignvalidator.php:26
Bitrix\Main\ORM\Fields\Validators\ForeignValidator\NOT_EXISTS
const NOT_EXISTS
Definition
foreignvalidator.php:28
Bitrix\Main\ORM\Fields\Validators\ForeignValidator\__construct
__construct(ORM\Fields\Field $reference, array $filter=array())
Definition
foreignvalidator.php:34
Bitrix\Main\ORM\Fields\Validators\ForeignValidator\$errorPhraseCode
$errorPhraseCode
Definition
foreignvalidator.php:25
Bitrix\Main\ORM\Fields\Validators\ForeignValidator\validate
validate($value, $primary, array $row, ORM\Fields\Field $field)
Definition
foreignvalidator.php:41
Bitrix\Main\ORM\Fields\Validators\ForeignValidator\$filter
$filter
Definition
foreignvalidator.php:27
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
foreignvalidator.php
Создано системой
1.10.0