7use Bitrix\Bizproc\Automation\Trigger\Entity\EO_Trigger;
12 private const CACHE_TTL = 7200;
32 $this->appliedTrigger = $trigger;
51 if ($this->runtime ===
null)
54 $this->runtime->setTarget($this);
76 $iterator = TriggerTable::getList(array(
81 '@DOCUMENT_STATUS' => $statuses
84 'ttl' => self::CACHE_TTL
88 while ($row = $iterator->fetch())
105 $iterator = TriggerTable::getList([
110 '@DOCUMENT_STATUS' => $statuses,
114 return $iterator->fetchCollection()->getAll();
119 foreach ($triggers as $i => $trigger)
121 if (isset($trigger[
'DELETED']) && $trigger[
'DELETED'] ===
'Y')
126 $triggers[$i][
'APPLY_RULES'] = $this->prepareApplyRules($trigger[
'APPLY_RULES']);
132 foreach ($triggers as $i => $trigger)
134 $triggers[$i][
'APPLY_RULES'] = $this->prepareApplyRules($trigger[
'APPLY_RULES'],
true);
140 $updatedTriggers = [];
141 foreach ($triggers as $trigger)
143 $triggerId = isset($trigger[
'ID']) ? (int)$trigger[
'ID'] : 0;
145 if (isset($trigger[
'DELETED']) && $trigger[
'DELETED'] ===
'Y')
150 TriggerTable::delete($triggerId);
157 TriggerTable::update($triggerId, array(
158 'NAME' => $trigger[
'NAME'],
159 'DOCUMENT_STATUS' => $trigger[
'DOCUMENT_STATUS'],
160 'APPLY_RULES' => is_array($trigger[
'APPLY_RULES']) ? $trigger[
'APPLY_RULES'] : null
163 elseif (isset($trigger[
'CODE']) && isset($trigger[
'DOCUMENT_STATUS']))
166 $addResult = TriggerTable::add(array(
167 'NAME' => $trigger[
'NAME'],
171 'DOCUMENT_STATUS' => $trigger[
'DOCUMENT_STATUS'],
172 'CODE' => $trigger[
'CODE'],
173 'APPLY_RULES' => is_array($trigger[
'APPLY_RULES']) ? $trigger[
'APPLY_RULES'] : null
176 if ($addResult->isSuccess())
178 $trigger[
'ID'] = $addResult->getId();
181 $updatedTriggers[] = $trigger;
184 return $updatedTriggers;
190 foreach ($triggers as $trigger)
193 $status = $trigger[
'DOCUMENT_STATUS'];
195 if ($triggerDescription && isset($triggerDescription[
'RETURN']))
197 if (!isset($params[$status]))
199 $params[$status] = [];
201 foreach ($triggerDescription[
'RETURN'] as $property)
203 $params[$status][$property[
'Id']] = $property;
210 private function prepareApplyRules($rules, $external =
false): ?array
212 if (!is_array($rules))
217 if (isset($rules[
'Condition']))
219 $condition =
new ConditionGroup($rules[
'Condition']);
228 $rules[
'Condition'] = $condition->toArray();
231 if (isset($rules[
'ExecuteBy']))
235 $rules[
'ExecuteBy'] = \CBPHelper::UsersArrayToString(
243 $rules[
'ExecuteBy'] = \CBPHelper::UsersStringToArray(
275 if ($code === $availableTrigger[
'CODE'])
277 return $availableTrigger;
318 $this->appliedTriggerConditionResults = $log;
setAppliedTrigger(array $trigger)
prepareTriggersToShow(array &$triggers)
setDocumentStatus($statusId)
setAppliedTriggerConditionResults(array $log)
setTriggers(array $triggers)
setDocumentType(array $documentType)
getAppliedTriggerConditionResults()
prepareTriggersToSave(array &$triggers)
getTriggers(array $statuses)
extractTemplateParameters(array $triggers)
setDocumentId($documentId)
getAvailableTriggerByCode($code)
getDocumentStatusList($categoryId=0)
array $appliedTriggerConditionResults
getTriggerObjects(array $statuses)
getDocumentCategoryCode()