1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
CommentPopupItem.php
См. документацию.
1<?php
2
4
12
14{
15 use ContextCustomer;
16
20 private array $messageIds;
21 private int $chatId;
22 private array $userIds = [];
23 private array $childChatIds = [];
24 private ?array $commentsInfo = null;
25 private ?LastMessages $lastMessages = null;
26 private bool $withSubscriptionFlag = true;
27
28 public function __construct(int $chatId, array $messageIds = [])
29 {
30 $this->messageIds = array_unique($messageIds);
31 $this->chatId = $chatId;
32 }
33
34 public function merge(PopupDataItem $item): self
35 {
36 if ($item instanceof self)
37 {
38 $this->messageIds = array_unique(array_merge($this->messageIds, $item->messageIds));
39 }
40
41 return $this;
42 }
43
44 public static function getRestEntityName(): string
45 {
46 return 'commentInfo';
47 }
48
49 public function toRestFormat(array $option = []): array
50 {
51 if ($option['MESSAGE_ONLY_COMMON_FIELDS'] ?? false)
52 {
53 $this->withSubscribeFlag = false;
54 }
55
56 return $this->getInfo();
57 }
58
59 protected function getInfo(): array
60 {
61 if (empty($this->messageIds))
62 {
63 return [];
64 }
65
66 $this->fill();
67
68 return $this->commentsInfo;
69 }
70
71 protected function fill(): void
72 {
73 $this->fillBaseCommentsInfo();
74 $this->fillUsers();
75 }
76
77 protected function fillBaseCommentsInfo(): void
78 {
79 if (isset($this->commentsInfo))
80 {
81 return;
82 }
83
84 $this->commentsInfo = [];
85
86 if (empty($this->messageIds))
87 {
88 return;
89 }
90
91 $query = ChatTable::query()
92 ->setSelect(['ID', 'MESSAGE_COUNT', 'PARENT_MID'])
93 ->where('PARENT_ID', $this->chatId)
94 ->whereIn('PARENT_MID', $this->messageIds)
95 ;
96
97 if ($this->withSubscriptionFlag)
98 {
99 $query
100 ->addSelect('RELATION.NOTIFY_BLOCK', 'NOTIFY_BLOCK')
101 ->withRelation($this->getContext()->getUserId())
102 ;
103 }
104
105 $raw = $query->fetchAll();
106
107 foreach ($raw as $row)
108 {
109 $this->childChatIds[] = (int)$row['ID'];
110 $this->commentsInfo[] = [
111 'chatId' => (int)$row['ID'],
112 'dialogId' => 'chat' . $row['ID'],
113 'messageId' => (int)$row['PARENT_MID'],
114 'lastUserIds' => [],
115 'messageCount' => (int)$row['MESSAGE_COUNT'],
116 'isUserSubscribed' => ($row['NOTIFY_BLOCK'] ?? 'Y') === 'N',
117 ];
118 }
119 }
120
121 protected function fillUsers(): void
122 {
123 $this->fillBaseCommentsInfo();
124 $lastMessages = $this->getLastMessages();
125
126 foreach ($this->commentsInfo as $key => $commentInfo)
127 {
128 $lastUserIds = $lastMessages->getUsersByChatId($commentInfo['chatId']);
129 $this->commentsInfo[$key]['lastUserIds'] = $lastUserIds;
130
131 foreach ($lastUserIds as $userId)
132 {
133 $this->userIds[$userId] = $userId;
134 }
135 }
136 }
137
138 protected function getLastMessages(): LastMessages
139 {
140 if (!isset($this->lastMessages))
141 {
142 $this->fillBaseCommentsInfo();
143 $this->lastMessages = new LastMessages($this->childChatIds);
144 }
145
146 return $this->lastMessages;
147 }
148
149 public function getPopupData(array $excludedList = []): PopupData
150 {
151 $this->fillUsers();
152
153 return new PopupData([new UserShortPopupItem($this->userIds)], $excludedList);
154 }
155}
if(!is_object($USER)||! $USER->IsAuthorized()) $userId
Определения check_mail.php:18
toRestFormat(array $option=[])
Определения CommentPopupItem.php:49
__construct(int $chatId, array $messageIds=[])
Определения CommentPopupItem.php:28
getPopupData(array $excludedList=[])
Определения CommentPopupItem.php:149
merge(PopupDataItem $item)
Определения CommentPopupItem.php:34
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
Определения file_new.php:804
$query
Определения get_search.php:11
trait ContextCustomer
Определения ContextCustomer.php:12
if(empty($signedUserToken)) $key
Определения quickway.php:257
$option
Определения options.php:1711