1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
Event.php
См. документацию.
1<?php
2declare(strict_types=1);
3
4namespace Bitrix\Landing\Copilot\Generation;
5
6use Bitrix\Landing\Copilot\Generation;
7use Bitrix\Main\Loader;
8use Bitrix\Pull;
9
13class Event
14{
15 private Generation $generation;
16 private ?int $siteId = null;
17 private ?int $landingId = null;
18
19 private string $name = '';
20 private ?array $params = null;
21 private ?string $error = null;
22
26 public function __construct(Generation $generation)
27 {
28 $this->generation = $generation;
29 }
30
36 public function setSiteId(?int $siteId): self
37 {
38 $this->siteId = $siteId;
39
40 return $this;
41 }
42
48 public function setLandingId(?int $landingId): self
49 {
50 $this->landingId = $landingId;
51
52 return $this;
53 }
54
61 public function send(string $eventName, ?array $params = null): void
62 {
63 $this->name = $eventName;
64 $this->params = $params;
65 $this->error = null;
66
67 $this->sendBackendEvent();
68 $this->sendFrontendEvent();
69 }
70
77 public function sendError(string $eventName, string $error): void
78 {
79 $this->name = $eventName;
80 $this->params = null;
81 $this->error = $error;
82
83 $this->sendBackendEvent();
84 $this->sendFrontendEvent();
85 }
86
87 private function sendBackendEvent(): void
88 {
89 $event = new \Bitrix\Main\Event(
90 'landing',
91 $this->name,
92 $this->getEventParams(),
93 );
94 $event->send();
95 }
96
97 private function sendFrontendEvent(): void
98 {
99 if (Loader::includeModule('pull'))
100 {
101 $command = 'LandingCopilotGeneration:' . $this->name;
103 $this->generation->getAuthorId(),
104 [
105 'module_id' => 'landing',
106 'command' => $command,
107 'params' => $this->getEventParams(),
108 ]
109 );
110
112 }
113 }
114
115 private function getEventParams(): array
116 {
117 $params = [
118 'generationId' => $this->generation->getId(),
119 ];
120
121 if ($this->siteId)
122 {
123 $params['siteId'] = $this->siteId;
124 }
125
126 if ($this->landingId)
127 {
128 $params['landingId'] = $this->landingId;
129 }
130
131 if ($this->params)
132 {
133 $params['params'] = $this->params;
134 }
135
136 if ($this->error)
137 {
138 $params['error'] = $this->error;
139 }
140
141 return $params;
142 }
143}
setSiteId(?int $siteId)
Определения Event.php:36
setLandingId(?int $landingId)
Определения Event.php:48
sendError(string $eventName, string $error)
Определения Event.php:77
send(string $eventName, ?array $params=null)
Определения Event.php:61
__construct(Generation $generation)
Определения Event.php:26
static send()
Определения event.php:387
static add($recipient, array $parameters, $channelType=\CPullChannel::TYPE_PRIVATE)
Определения event.php:22
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
Определения file_new.php:804
$siteId
Определения ajax.php:8
$name
Определения menu_edit.php:35
Определения buffer.php:3
$event
Определения prolog_after.php:141
if($inWords) echo htmlspecialcharsbx(Number2Word_Rus(roundEx($totalVatSum $params['CURRENCY']
Определения template.php:799
$error
Определения subscription_card_product.php:20