Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
conditiongroup.php
1<?php
2
4
6
8{
9 public const JOINER_AND = 'AND'; // 0
10 public const JOINER_OR = 'OR'; // 1
11
12 protected array $items = [];
13 protected array $result = [];
14 protected array $parameterDocumentId = [];
15
16 public function __construct(array $params = [])
17 {
18 if (!empty($params))
19 {
20 if (isset($params['items']) && is_array($params['items']))
21 {
22 foreach ($params['items'] as $item)
23 {
24 $this->addItem($item);
25 }
26 }
27 if (isset($params['parameterDocumentId']) && is_array($params['parameterDocumentId']))
28 {
29 $this->parameterDocumentId = $params['parameterDocumentId'];
30 }
31 }
32 }
33
34 public function addItem(array $item): ConditionGroup
35 {
36 if (!empty($item))
37 {
38 $this->items[] = [
39 'condition' => new Condition($item),
40 'joiner' => isset($item['joiner']) && $item['joiner'] === 0 ? static::JOINER_AND : self::JOINER_OR,
41 'valueToCheck' => $item['valueToCheck'] ?? null,
42 'fieldType' => $item['fieldType'] ?? new FieldType([], [], 'Bitrix\Bizproc\BaseType\StringType')
43 ];
44 }
45
46 return $this;
47 }
48
49 public function getItems(): array
50 {
51 return $this->items;
52 }
53
54 public function getParameterDocumentId(): array
55 {
57 }
58
59 public function evaluate(): bool
60 {
61 $result = [0 => true];
62 $i = 0;
63
64 $this->result = [];
65
66 foreach ($this->getItems() as $item)
67 {
68 $joiner = $item['joiner'];
70 $condition = $item['condition'];
71
72 if ($condition->getOperator() === 'modified')
73 {
74 $conditionResult =
75 is_array($condition->getValue()) && in_array($item['valueToCheck'], $condition->getValue(), true)
76 ;
77 }
78 else
79 {
80 $conditionResult = $condition->checkValue($item['valueToCheck'], $item['fieldType'], $this->parameterDocumentId);
81 }
82
83 if ($joiner === static::JOINER_OR)
84 {
85 ++$i;
86 $result[$i] = $conditionResult;
87 }
88 elseif (!$conditionResult)
89 {
90 $result[$i] = false;
91 }
92
93 $this->result[] = $conditionResult;
94 }
95
96 return (count(array_filter($result)) > 0);
97 }
98
99 public function getEvaluateResults(): array
100 {
101 return $this->result;
102 }
103}