Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
controller.php
1<?php
2
4
11
12final class Controller
13{
14
15 public static function onContextGetMessages(Event $event): array
16 {
17 $moduleId = $event->getParameter('module');
18 $contextId = $event->getParameter('id');
19 $contextParameters = $event->getParameter('params');
20
21 $isAddedQuote = filter_var(($contextParameters['isAddedQuote'] ?? null), FILTER_VALIDATE_BOOLEAN);
22 $messageId = $contextParameters['messageId'];
23 $messageIds = $contextParameters['messageIds'];
24
25 if (!$moduleId || !$contextId)
26 {
27 return ['messages' => []];
28 }
29
30 if (!self::isNeededMailMessageContext($moduleId, $contextId, $isAddedQuote, $messageId, $messageIds))
31 {
32 return ['messages' => []];
33 }
34
35 if (!$messageIds)
36 {
37 $messageThreadLoader = new MessageThreadLoader($messageId);
38 $messageThreadLoader->loadFullThreadMessageIds();
39 $messageIds = $messageThreadLoader->getThreadMessageIds();
40 }
41
42 if (!$messageIds)
43 {
44 return ['messages' => []];
45 }
46
47 return self::loadMessages($messageIds);
48 }
49
50 private static function isNeededMailMessageContext(
51 string $moduleId,
52 string $contextId,
53 bool $isAddedQuote,
54 ?int $messageId = null,
55 ?array $messageIds = null,
56 ): bool
57 {
58 if ($moduleId !== 'mail' || $isAddedQuote !== false)
59 {
60 return false;
61 }
62
63 if (!str_starts_with($contextId, 'mail_reply') && !str_starts_with($contextId, 'crm_mail_reply'))
64 {
65 return false;
66 }
67
68 if ($messageId < 0 && empty($messageIds))
69 {
70 return false;
71 }
72
73 return true;
74 }
75
80 private static function loadMessages(array $messageIds): array
81 {
82 $messageIds = array_filter($messageIds, function ($item) {
83 return filter_var($item, FILTER_VALIDATE_INT) !== false;
84 });
85
86 if (empty($messageIds))
87 {
88 return ['messages' => []];
89 }
90
91 $message = MailMessageTable::query()
92 ->setSelect(['BODY'])
93 ->where('ID', end($messageIds))
94 ->fetchObject()
95 ;
96
97 if (!$message)
98 {
99 return ['messages' => []];
100 }
101
102 $messages[] = [
103 'content' => $message['BODY']]
104 ;
105
106 return [
107 'messages' => $messages,
108 ];
109 }
110}
static onContextGetMessages(Event $event)
getParameter($key)
Definition event.php:80