Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
messagethreadloader.php
1<?php
2
4
9
11{
12 private array $threadBeforeMessageId = [];
13 private array $threadAfterMessageId = [];
14
15 public function __construct(
16 private int $messageId,
17 ){}
18
19 public function getMessageId(): int
20 {
21 return $this->messageId;
22 }
23
28 public function getThreadMessageIds(): array
29 {
30 $threadMessageIds = [$this->messageId];
31 if ($this->threadBeforeMessageId)
32 {
33 $threadMessageIds = array_merge($this->threadBeforeMessageId, $threadMessageIds);
34 }
35 if ($this->threadAfterMessageId)
36 {
37 $threadMessageIds = array_merge($threadMessageIds, $this->threadAfterMessageId);
38 }
39
40 return $threadMessageIds;
41 }
42
47 public function clearThreadMessageIds(): void
48 {
49 $this->threadBeforeMessageId = [];
50 $this->threadAfterMessageId = [];
51 }
52
53 public function loadBeforeThreadMessageIds(?int $limit = null): void
54 {
55 $this->threadBeforeMessageId = [];
56
57 $query = MessageClosureTable::query()
58 ->setSelect(['PARENT_ID'])
59 ->where('MESSAGE_ID', $this->messageId)
60 ->where('PARENT_ID', '<', $this->messageId)
61 ->setOrder(['PARENT_ID' => 'ASC'])
62 ;
63
64 if ($limit)
65 {
66 $query->setLimit($limit);
67 }
68
69 foreach ($query->fetchAll() as $item)
70 {
71 $this->threadBeforeMessageId[] = (int)$item['PARENT_ID'];
72 }
73 }
74
75 public function loadAfterThreadMessageIds(?int $limit = null): void
76 {
77 $this->threadAfterMessageId = [];
78
79 $query = MessageClosureTable::query()
80 ->setSelect(['MESSAGE_ID'])
81 ->where('PARENT_ID', $this->messageId)
82 ->where('MESSAGE_ID', '>', $this->messageId)
83 ->setOrder(['PARENT_ID' => 'ASC'])
84 ;
85
86 if ($limit)
87 {
88 $query->setLimit($limit);
89 }
90
91 foreach ($query->fetchAll() as $item)
92 {
93 $this->threadAfterMessageId[] = (int)$item['MESSAGE_ID'];
94 }
95 }
96
97 public function loadFullThreadMessageIds(?int $limit = null): void
98 {
99 $this->loadBeforeThreadMessageIds($limit);
100 $this->loadAfterThreadMessageIds($limit);
101 }
102}