Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
condition.php
1<?php
2
4
20
22{
23 protected $operator;
24 protected $value;
25
26 public function __construct(array $params = null)
27 {
28 if ($params)
29 {
30 if (isset($params['operator']))
31 {
32 $this->setOperator($params['operator']);
33 }
34 if (isset($params['value']))
35 {
36 $this->setValue($params['value']);
37 }
38 }
39 }
40
45 public function setOperator($operator)
46 {
47 $this->operator = (string)$operator;
48 return $this;
49 }
50
54 public function getOperator()
55 {
56 return $this->operator;
57 }
58
63 public function setValue($value)
64 {
65 $this->value = $value;
66 return $this;
67 }
68
72 public function getValue()
73 {
74 return $this->value;
75 }
76
83 public function checkValue($valueToCheck, FieldType $fieldType, array $documentId)
84 {
85 $fieldType = clone($fieldType);
86 $fieldType->setDocumentId($documentId);
87
88 switch ($this->getOperator())
89 {
91 $operator = new EmptyOperator($valueToCheck, $this->getValue(), $fieldType);
92 break;
94 $operator = new NotEmptyOperator($valueToCheck, $this->getValue(), $fieldType);
95 break;
97 $operator = new ContainOperator($valueToCheck, $this->getValue(), $fieldType);
98 break;
100 $operator = new NotContainOperator($valueToCheck, $this->getValue(), $fieldType);
101 break;
102 case InOperator::getCode():
103 $operator = new InOperator($valueToCheck, $this->getValue(), $fieldType);
104 break;
106 $operator = new NotInOperator($valueToCheck, $this->getValue(), $fieldType);
107 break;
109 $operator = new BetweenOperator($valueToCheck, $this->getValue(), $fieldType);
110 break;
112 $operator = new GreaterThenOperator($valueToCheck, $this->getValue(), $fieldType);
113 break;
115 $operator = new GreaterThenOrEqualOperator($valueToCheck, $this->getValue(), $fieldType);
116 break;
118 $operator = new LessThenOperator($valueToCheck, $this->getValue(), $fieldType);
119 break;
121 $operator = new LessThenOrEqualOperator($valueToCheck, $this->getValue(), $fieldType);
122 break;
124 $operator = new EqualOperator($valueToCheck, $this->getValue(), $fieldType);
125 break;
127 $operator = new NotEqualOperator($valueToCheck, $this->getValue(), $fieldType);
128 break;
129 default:
130 $operator = new BaseOperator($valueToCheck, $this->getValue(), $fieldType);
131 }
132
133 return $operator->check();
134 }
135
139 public function toArray()
140 {
141 return [
142 'operator' => $this->getOperator(),
143 'value' => $this->getValue(),
144 ];
145 }
146
147 public static function getOperatorList(): array
148 {
149 $operators = [
150 Operator\EqualOperator::class,
151 Operator\NotEqualOperator::class,
152
153 Operator\GreaterThenOperator::class,
154 Operator\GreaterThenOrEqualOperator::class,
155
156 Operator\LessThenOperator::class,
157 Operator\LessThenOrEqualOperator::class,
158
159 Operator\InOperator::class,
160 Operator\NotInOperator::class,
161
162 Operator\ContainOperator::class,
163 Operator\NotContainOperator::class,
164
165 Operator\NotEmptyOperator::class,
166 Operator\EmptyOperator::class,
167
168 Operator\BetweenOperator::class,
169 ];
170
171 $operatorList = [];
172
174 foreach ($operators as $operator)
175 {
176 $operatorList[$operator::getCode()] = $operator::getTitle();
177 }
178
179 return $operatorList;
180 }
181}
__construct(array $params=null)
Definition condition.php:26
checkValue($valueToCheck, FieldType $fieldType, array $documentId)
Definition condition.php:83
setDocumentId(array $documentId)