1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
ChatEvent.php
См. документацию.
1<?php
2
4
22
23class ChatEvent extends Event
24{
25 protected const CHAT_TYPE_CONDITIONS = [
26 'collab' => ['instanceof' => CollabChat::class],
27
28 'call' => ['entity' => 'CALL'],
29 'crm' => ['entity' => 'CRM'],
30 'mail' => ['entity' => 'MAIL'],
31 'sonetGroup' => ['entity' => 'SONET_GROUP'],
32 'tasks' => ['entity' => 'TASKS'],
33
34 'calendar' => ['entity' => 'CALENDAR'],
35 'support24Notifier' => ['entity' => 'SUPPORT24_NOTIFIER'],
36 'support24Question' => ['entity' => 'SUPPORT24_QUESTION'],
37 'thread' => ['entity' => 'THREAD'],
38 'announcement' => ['entity' => 'ANNOUNCEMENT'],
39
40 'generalChannel' => ['instanceof' => GeneralChat::class],
41 'openChannel' => ['instanceof' => OpenChannelChat::class],
42 'channel' => ['instanceof' => ChannelChat::class],
43
44 'comment' => ['instanceof' => CommentChat::class],
45 'open' => ['instanceof' => OpenChat::class],
46 'general' => ['instanceof' => GeneralChat::class],
47 'videoconf' => ['instanceof' => VideoConfChat::class],
48 'copilot' => ['instanceof' => CopilotChat::class],
49 'chat' => ['instanceof' => GroupChat::class],
50 'user' => ['instanceof' => PrivateChat::class],
51 ];
52 protected const CHAT_P1_CONDITIONS = [
53 'chatType_collab' => ['instanceof' => CollabChat::class],
54
55 'chatType_call' => ['entity' => 'CALL'],
56 'chatType_crm' => ['entity' => 'CRM'],
57 'chatType_mail' => ['entity' => 'MAIL'],
58 'chatType_sonetGroup' => ['entity' => 'SONET_GROUP'],
59 'chatType_tasks' => ['entity' => 'TASKS'],
60 'chatType_calendar' => ['entity' => 'CALENDAR'],
61
62 'chatType_generalChannel' => ['instanceof' => GeneralChannel::class],
63 'chatType_openChannel' => ['instanceof' => OpenChannelChat::class],
64 'chatType_channel' => ['instanceof' => ChannelChat::class],
65
66 'chatType_comments' => ['instanceof' => CommentChat::class],
67 'chatType_open' => ['instanceof' => OpenChat::class],
68 'chatType_general' => ['instanceof' => GeneralChat::class],
69 'chatType_videoconf' => ['instanceof' => VideoConfChat::class],
70 'chatType_copilot' => ['instanceof' => CopilotChat::class],
71 'chatType_chat' => ['instanceof' => GroupChat::class],
72
73 'chatType_notes' => ['instanceof' => FavoriteChat::class],
74 'chatType_user' => ['instanceof' => PrivateChat::class],
75 ];
76
77 protected function setDefaultParams(): self
78 {
79 $this
80 ->setChatP1()
81 ->setChatP2()
82 ->setChatP4()
83 ->setChatP5()
84 ;
85
86 return $this;
87 }
88
89 public function setChatType(): self
90 {
91 $entityType = $this->chat->getEntityType();
92 foreach (self::CHAT_TYPE_CONDITIONS as $typeName => $conditions)
93 {
94 if (array_key_exists('entity', $conditions) && $conditions['entity'] === $entityType)
95 {
96 $this->type = $typeName;
97
98 return $this;
99 }
100
101 if (array_key_exists('instanceof', $conditions))
102 {
103 if (!is_array($conditions['instanceof']))
104 {
105 $conditions['instanceof'] = [$conditions['instanceof']];
106 }
107
108 foreach ($conditions['instanceof'] as $condition)
109 {
110 if ($this->chat instanceof $condition)
111 {
112 $this->type = $typeName;
113
114 return $this;
115 }
116 }
117 }
118 }
119
120 $this->type = '';
121
122 return $this;
123 }
124
125 protected function setChatP1(): self
126 {
127 $entityType = $this->chat->getEntityType();
128
129 foreach (self::CHAT_P1_CONDITIONS as $typeName => $conditions)
130 {
131 if (array_key_exists('entity', $conditions) && $conditions['entity'] === $entityType)
132 {
133 $this->p1 = $typeName;
134
135 return $this;
136 }
137
138 if (array_key_exists('instanceof', $conditions) && $this->chat instanceof $conditions['instanceof'])
139 {
140 $this->p1 = $typeName;
141
142 return $this;
143 }
144 }
145
146 $this->p1 = 'custom';
147
148 return $this;
149 }
150
151 protected function setChatP2(): self
152 {
153 if ($this->chat instanceof CopilotChat)
154 {
155 $engineCode = $this->chat->getEngineCode() ?? EngineManager::getDefaultEngineCode();
156 $engineName = (new EngineManager())->getEngineNameByCode($engineCode) ?? '';
157
158 $this->p2 = 'provider_' . Event::convertUnderscore($engineName);
159
160 return $this;
161 }
162
163 $currentUser = $this->chat->getContext()->getUser();
164
165 $this->p2 = match (true)
166 {
167 $currentUser instanceof UserCollaber => 'user_collaber',
168 $currentUser instanceof UserExternal => 'user_extranet',
169 default => 'user_intranet',
170 };
171
172 return $this;
173 }
174
175 protected function setChatP4(): self
176 {
177 if ($this->chat instanceof CollabChat)
178 {
179 $this->p4 = 'collabId_' . ($this->chat->getEntityId() ?? 0);
180
181 return $this;
182 }
183
184 if ($this->chat instanceof CopilotChat)
185 {
186 $role = (new RoleManager())->getMainRole($this->chat->getChatId()) ?? '';
187 $this->p4 = 'role_' . self::convertUnderscore($role);
188
189 return $this;
190 }
191
192
193 $parentChatId = $this->chat->getParentChatId();
194 $this->p4 = 'parentChatId_' . ($parentChatId ?? 0);
195
196 return $this;
197 }
198
199 protected function setChatP5(): self
200 {
201 if ($this->chat->getChatId() !== null)
202 {
203 $this->p5 = 'chatId_' . $this->chat->getChatId();
204 }
205
206 return $this;
207 }
208
209 protected function getTool(): string
210 {
211 return 'im';
212 }
213
214 protected function getCategory(string $eventName): string
215 {
216 $additionalCategories = $eventName === ChatAnalytics::SUBMIT_CREATE_NEW;
217
218 return match (true)
219 {
220 $this->chat instanceof ChannelChat || $this->chat instanceof CommentChat => 'channel',
221 $this->chat instanceof CopilotChat => 'copilot',
222 $this->chat instanceof CollabChat => 'collab',
223 $this->chat instanceof VideoConfChat && $additionalCategories => 'videoconf',
224 default => 'chat',
225 };
226 }
227}
getCategory(string $eventName)
Определения ChatEvent.php:214
static convertUnderscore(string $string)
Определения Event.php:46