Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
tracker.php
1<?php
10namespace Bitrix\Sender\Message;
11
15
17{
18 public const TYPE_READ = 1;
19 public const TYPE_CLICK = 2;
20 public const TYPE_UNSUB = 3;
21
23 protected $type;
24
26 protected $moduleId;
27
29 protected $fields = [];
30
32 protected $uriParameters = [];
33
35 protected $handlerUri;
36
38 protected $linkDomain;
39
41 protected $siteId;
42
43 private $siteData;
44
50 public function __construct($type)
51 {
52 $this->type = $type;
53 }
54
58 public function getModuleId()
59 {
60 return $this->moduleId;
61 }
62
67 public function setModuleId($moduleId)
68 {
69 $this->moduleId = $moduleId;
70 return $this;
71 }
72
76 public function getSiteId()
77 {
78 return $this->moduleId;
79 }
80
85 public function setSiteId($siteId)
86 {
87 $this->siteId = $siteId;
88 return $this;
89 }
90
94 public function getFields()
95 {
96 return $this->fields;
97 }
98
103 public function setFields($fields)
104 {
105 $this->fields = $fields;
106 return $this;
107 }
108
113 public function addField($key, $value)
114 {
115 $this->fields[$key] = $value;
116 }
117
121 public function getUriParameters()
122 {
124 }
125
131 {
132 $this->uriParameters = $uriParameters;
133 return $this;
134 }
135
141 public function addUriParameter($key, $value)
142 {
143 $this->uriParameters[$key] = $value;
144 return $this;
145 }
146
152 public function getHandlerUri()
153 {
154 if (!$this->handlerUri && Integration\Bitrix24\Service::isPortal())
155 {
156 return Integration\Bitrix24\Service::getTrackingUri(
157 $this->type,
158 (Integration\Bitrix24\Service::isCloud() ? null : $this->siteId) // $this->siteId is not used for cloud
159 );
160 }
161
162 return $this->handlerUri;
163 }
164
171 public function setHandlerUri($handlerUri)
172 {
173 $this->handlerUri = $handlerUri;
174 return $this;
175 }
176
182 public function getLinkDomain()
183 {
184 if ($this->linkDomain === null)
185 {
186 if (Integration\Bitrix24\Service::isCloud())
187 {
188 return '';
189 }
190 if ($this->siteId)
191 {
192 if ($this->siteData === null)
193 {
194 $this->siteData = SiteTable::getById($this->siteId)->fetch();
195 }
196 if ($this->siteData && $this->siteData['SERVER_NAME'])
197 {
198 return $this->siteData['SERVER_NAME'];
199 }
200 }
201 }
202
203 return $this->linkDomain;
204 }
205
212 public function setLinkDomain($linkDomain)
213 {
214 $this->linkDomain = $linkDomain;
215 return $this;
216 }
217
223 public function getLink()
224 {
225 $link = '';
226
227 $moduleId = $this->getModuleId();
228 $fields = $this->getFields();
229 if (!$moduleId || empty($fields))
230 {
231 return $link;
232 }
233
234 $uri = $this->getHandlerUri();
235 switch ($this->type)
236 {
237 case self::TYPE_READ:
238 $link = Tracking::getLinkRead($moduleId, $fields, $uri);
239 break;
240
241 case self::TYPE_CLICK:
242 $link = Tracking::getLinkClick($moduleId, $fields, $uri);
243 break;
244
245 case self::TYPE_UNSUB:
246 $link = Tracking::getLinkUnsub($moduleId, $fields, $uri);
247 break;
248 }
249
250 return $link;
251 }
252
258 public function getArray()
259 {
260 return [
261 'MODULE_ID' => $this->getModuleId(),
262 'FIELDS' => $this->getFields(),
263 'URL_PAGE' => $this->getHandlerUri(),
264 'URL_PARAMS' => $this->getUriParameters(),
265 ];
266 }
267
274 public function setArray(array $data)
275 {
276 if (isset($data['MODULE_ID']))
277 {
278 $this->setModuleId($data['MODULE_ID']);
279 }
280 if (isset($data['FIELDS']))
281 {
282 $this->setFields($data['FIELDS']);
283 }
284 if (isset($data['URL_PARAMS']))
285 {
286 $this->setUriParameters($data['URL_PARAMS']);
287 }
288 if (isset($data['URL_PAGE']))
289 {
290 $this->setHandlerUri($data['URL_PAGE']);
291 }
292
293 return $this;
294 }
295}
addUriParameter($key, $value)
Definition tracker.php:141
setUriParameters($uriParameters)
Definition tracker.php:130