Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
trigger.php
1<?php
3
7
8class Trigger
9{
10 const TRIGGER_COPY_ERROR = "TRIGGER_COPY_ERROR";
11
12 private $targetDocumentType = [];
13 private $mapStatusIdsCopiedDocument = [];
14
15 private $result;
16
17 public function __construct($targetDocumentType = [], $mapStatusIdsCopiedDocument = [])
18 {
19 $this->targetDocumentType = $targetDocumentType;
20 $this->mapStatusIdsCopiedDocument = $mapStatusIdsCopiedDocument;
21
22 $this->result = new Result();
23 }
24
32 public function getFields($triggerId)
33 {
34 $queryResult = TriggerTable::getList(["filter" => ["=ID" => $triggerId]]);
35 return (($fields = $queryResult->fetch()) ? $fields : []);
36 }
37
38 public function prepareFieldsToCopy(array $fields)
39 {
40 if (isset($fields["ID"]))
41 {
42 unset($fields["ID"]);
43 }
44
45 if ($this->targetDocumentType)
46 {
47 $fields["MODULE_ID"] = $this->targetDocumentType[0];
48 $fields["ENTITY"] = $this->targetDocumentType[1];
49 $fields["DOCUMENT_TYPE"] = $this->targetDocumentType[2];
50 }
51
52 if (array_key_exists($fields["DOCUMENT_STATUS"], $this->mapStatusIdsCopiedDocument))
53 {
54 $fields["DOCUMENT_STATUS"] = $this->mapStatusIdsCopiedDocument[$fields["DOCUMENT_STATUS"]];
55 }
56
57 return $fields;
58 }
59
65 public function add(array $fields)
66 {
67 $result = false;
68
69 if ($fields)
70 {
71 $addResult = TriggerTable::add($fields);
72 $result = ($addResult->isSuccess() ? $addResult->getId() : false);
73 }
74
75 if (!$result)
76 {
77 $this->result->addError(new Error("Failed to copy trigger", self::TRIGGER_COPY_ERROR));
78 }
79
80 return $result;
81 }
82}
__construct($targetDocumentType=[], $mapStatusIdsCopiedDocument=[])
Definition trigger.php:17