Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
basetrigger.php
1<?php
3
7
9{
10 protected $target;
11 protected $returnValues;
12
16 public static function className()
17 {
18 return get_called_class();
19 }
20
21 public static function isEnabled()
22 {
23 return true;
24 }
25
30 public function setTarget(BaseTarget $target)
31 {
32 $this->target = $target;
33 return $this;
34 }
35
40 public function getTarget()
41 {
42 if ($this->target === null)
43 {
44 throw new Main\InvalidOperationException('Target must be set by setTarget method.');
45 }
46 return $this->target;
47 }
48
52 public static function getCode()
53 {
54 return 'BASE';
55 }
56
60 public static function getName()
61 {
62 return 'Base trigger';
63 }
64
65 protected function getPotentialTriggers()
66 {
67 $triggers = [];
68
69 $currentStatus = $this->getTarget()->getDocumentStatus();
70 $allStatuses = array_keys($this->getTarget()->getDocumentStatusList());
71
72 $needleKey = array_search($currentStatus, $allStatuses);
73
74 if ($needleKey === false)
75 {
76 return $triggers;
77 }
78
79 $forwardStatuses = array_slice($allStatuses, $needleKey + 1);
80
81 $code = static::getCode();
82 $rows = [];
83 $targetTriggers = $this->getTarget()->getTriggers($allStatuses);
84
85 foreach ($targetTriggers as $row)
86 {
87 if ($row['CODE'] !== $code)
88 {
89 continue;
90 }
91
92 if (!in_array($row['DOCUMENT_STATUS'], $forwardStatuses))
93 {
94 if (
95 !isset($row['APPLY_RULES']['ALLOW_BACKWARDS'])
96 ||
97 $row['APPLY_RULES']['ALLOW_BACKWARDS'] !== 'Y'
98 )
99 {
100 continue;
101 }
102 }
103
104 $rows[$row['DOCUMENT_STATUS']][] = $row;
105 }
106
107 if ($rows)
108 {
109 foreach ($allStatuses as $needleStatus)
110 {
111 if (isset($rows[$needleStatus]))
112 {
113 $triggers = array_merge($triggers, $rows[$needleStatus]);
114 }
115 }
116 }
117
118 return $triggers;
119 }
120
121 public function checkApplyRules(array $trigger)
122 {
123 $conditionRules = is_array($trigger['APPLY_RULES']) && isset($trigger['APPLY_RULES']['Condition'])
124 ? $trigger['APPLY_RULES']['Condition'] : null;
125
126 if ($conditionRules)
127 {
128 $conditionGroup = new ConditionGroup($conditionRules);
129 $target = $this->getTarget();
130 $result = $conditionGroup->evaluate($target);
131
132 if ($result)
133 {
134 $target->setAppliedTriggerConditionResults($conditionGroup->getEvaluateResults());
135 }
136
137 return $result;
138 }
139
140 return true;
141 }
142
143 public function getReturnValues(): ?array
144 {
145 return $this->returnValues;
146 }
147
152 public function setReturnValues(array $values)
153 {
154 $this->returnValues = $values;
155 return $this;
156 }
157
158 public static function getReturnProperties(): array
159 {
160 return [];
161 }
162
163 public static function toArray()
164 {
165 return [
166 'NAME' => static::getName(),
167 'CODE' => static::getCode(),
168 'RETURN' => static::getReturnProperties(),
169 'DESCRIPTION' => static::getDescription(),
170 'GROUP' => static::getGroup(),
171 'SETTINGS' => static::getSettings(),
172 ];
173 }
174
175 public static function getDescription(): string
176 {
177 return '';
178 }
179
180 public static function getGroup(): array
181 {
182 return [];
183 }
184
185 protected static function getSettings(): ?array
186 {
187 $map = static::getPropertiesMap();
188 if ($map)
189 {
190 return ['Properties' => array_values($map)];
191 }
192
193 return null;
194 }
195
196 protected static function getPropertiesMap(): array
197 {
198 return [];
199 }
200}