Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
triggerconnector.php
1<?php
9
11
12abstract class TriggerConnector extends Base
13{
15 public $connector;
16
18 final protected function getConnectorForm()
19 {
20 $endpoint = $this->getConnector();
21 if(is_array($endpoint) && !empty($endpoint['CODE']))
22 {
23 $this->connector = Connector\Manager::getConnector($endpoint);
24 }
25 elseif(is_object($endpoint) && $endpoint instanceof Connector\Base)
26 {
27 $this->connector = $endpoint;
28 }
29
30 if($this->connector)
31 {
32 $this->connector->setFieldPrefixExtended($this->getFieldPrefix());
33 $this->connector->setFieldFormName($this->getFieldFormName());
34 $this->connector->setFieldValues($this->getFields());
35
36 return $this->connector->getForm();
37 }
38 else
39 return '';
40 }
41
43 final protected function filterConnectorData()
44 {
45 $result = true;
46
47 $endpoint = $this->getConnector();
48 if(is_array($endpoint) && !empty($endpoint['CODE']))
49 {
50 // do not send mails if connector will not found
51 $result = false;
52
53 // try to find connector
54 $connector = Connector\Manager::getConnector($endpoint);
55 $this->connector = $connector;
56 }
57 elseif(is_object($endpoint) && $endpoint instanceof Connector\Base)
58 {
59 $this->connector = $endpoint;
60 }
61
62
63 if($this->connector)
64 {
65 // merge connector filter and proxy fields. proxy fields have priority
66 $connectorFields = $this->getProxyFieldsFromEventToConnector();
67 if(!empty($connectorFields))
68 {
69 $connectorFields = $connectorFields + $this->getFields();
70 }
71 // set fields to connector
72 $this->connector->setFieldValues($connectorFields);
73
74
75 $result = false;
76 // add recipient from data if connector get it
77 $recipientDb = $this->connector->getData();
78 if($recipient = $recipientDb->Fetch())
79 {
80 $this->recipient = $recipient;
81 $result = true;
82 }
83 }
84
85 return $result;
86 }
87
88
90 public function getForm()
91 {
92 $connectorForm = $this->getConnectorForm();
93 if($connectorForm)
94 return $connectorForm;
95 else
96 return '';
97 }
98
100 public function filter()
101 {
102 return $this->filterConnectorData();
103 }
104
106 public function getRecipient()
107 {
108 return $this->recipient;
109 }
110
113 {
114 $eventData = $this->getParam('EVENT');
115 return array('ID' => $eventData['ID']);
116 }
117
121 public function getRecipientResult()
122 {
123 $result = parent::getRecipientResult();
124 if(!$this->connector)
125 {
126 return $result;
127 }
128
129 $personalizeList = array();
130 $connectorPersonalizeList = $this->connector->getPersonalizeList();
131 foreach($connectorPersonalizeList as $tag)
132 {
133 if($tag['CODE'] <> '')
134 {
135 $personalizeList[] = $tag['CODE'];
136 }
137 }
138 $result->setFilterFields(array_merge($result->getFilterFields(), $personalizeList));
139
140 return $result;
141 }
142
149 public function getConnector()
150 {
151 return array(
152 'MODULE_ID' => '',
153 'CODE' => ''
154 );
155 }
156}