1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
Action.php
См. документацию.
1<?php
2
4
10
11class Action
12{
13 use ContextCustomer;
14
15 protected Chat $chat;
16 protected Type $type;
17 protected ?string $customUserName = null;
18 protected bool $byEvent = false;
19 protected bool $linesSilentMode = false;
20
21 public function __construct(Chat $chat, Type $type)
22 {
23 $this->chat = $chat;
24 $this->type = $type;
25 }
26
27 public function notify(): Result
28 {
29 $resultSend = $this->sendPull();
30 if (!$resultSend->isSuccess())
31 {
32 return $resultSend;
33 }
34
35 $resultSendLegacy = $this->sendLegacyPull();
36 if (!$resultSendLegacy->isSuccess())
37 {
38 return $resultSendLegacy;
39 }
40
41 $this->sendLegacyEvent();
42
43 return new Result();
44 }
45
46 public function setCustomUserName(string $customUserName): void
47 {
48 $this->customUserName = $customUserName;
49 }
50
51 public function setByEvent(bool $byEvent): void
52 {
53 $this->byEvent = $byEvent;
54 }
55
56 public function setLinesSilentMode(bool $linesSilentMode): void
57 {
58 $this->linesSilentMode = $linesSilentMode;
59 }
60
61 private function sendPull(): Result
62 {
63 $pull = (new InputActionNotify($this->chat, $this->type))
64 ->setContext($this->context)
65 ->setCustomUserName($this->customUserName)
66 ;
67
68 return $pull->send();
69 }
70
71 private function sendLegacyPull(): Result
72 {
73 if ($this->type !== Type::Writing)
74 {
75 return new Result(); // send legacy pull only for writting action
76 }
77
78 $pull = (new StartWriting($this->chat))
79 ->setContext($this->context)
80 ->setCustomUserName($this->customUserName)
81 ;
82
83 return $pull->send();
84 }
85
86 private function sendLegacyEvent(): void
87 {
88 if ($this->type !== Type::Writing)
89 {
90 return; // send legacy event only for writing action
91 }
92
93 $eventParams = [[
94 'DIALOG_ID' => $this->chat->getDialogId(),
95 'CHAT' => $this->getChatArray(),
96 'RELATION' => $this->getRelationsArray(),
97 'USER_ID' => $this->getContext()->getUserId(),
98 'USER_NAME' => $this->customUserName ?? $this->getContext()->getUser()->getName(),
99 'BY_EVENT' => $this->byEvent,
100 'LINES_SILENT_MODE' => $this->linesSilentMode,
101 ]];
102
103 foreach(GetModuleEvents("im", "OnStartWriting", true) as $arEvent)
104 {
105 ExecuteModuleEventEx($arEvent, $eventParams);
106 }
107 }
108
109 private function getRelationsArray(): array
110 {
111 $relationsArray = [];
112 if ($this->chat instanceof Chat\PrivateChat)
113 {
114 return [];
115 }
116
117 foreach ($this->chat->getRelations() as $relation)
118 {
119 $relationArray = $relation->toArray();
120 $relationArray['EXTERNAL_AUTH_ID'] = $relation->getUser()->getExternalAuthId();
121 $relationsArray[] = static::convertBoolToChar($relationArray);
122 }
123
124 return $relationsArray;
125 }
126
127 private function getChatArray(): array
128 {
129 if ($this->chat instanceof Chat\PrivateChat)
130 {
131 return [];
132 }
133
134 return static::convertBoolToChar($this->chat->toArray());
135 }
136
144 private static function convertBoolToChar(array $array): array
145 {
146 foreach ($array as $field => $value)
147 {
148 if (is_bool($value))
149 {
150 $array[$field] = $value ? 'Y' : 'N';
151 }
152 }
153
154 return $array;
155 }
156}
string $customUserName
Определения Action.php:17
bool $linesSilentMode
Определения Action.php:19
setByEvent(bool $byEvent)
Определения Action.php:51
__construct(Chat $chat, Type $type)
Определения Action.php:21
setCustomUserName(string $customUserName)
Определения Action.php:46
setLinesSilentMode(bool $linesSilentMode)
Определения Action.php:56
Определения result.php:20
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
Определения file_new.php:804
ExecuteModuleEventEx($arEvent, $arParams=[])
Определения tools.php:5214
GetModuleEvents($MODULE_ID, $MESSAGE_ID, $bReturnArray=false)
Определения tools.php:5177
$value
Определения Param.php:39
trait ContextCustomer
Определения ContextCustomer.php:12
Определения collection.php:2