Server IP : 80.87.202.40 / Your IP : 216.73.216.169 Web Server : Apache System : Linux rospirotorg.ru 5.14.0-539.el9.x86_64 #1 SMP PREEMPT_DYNAMIC Thu Dec 5 22:26:13 UTC 2024 x86_64 User : bitrix ( 600) PHP Version : 8.2.27 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : OFF | Sudo : ON | Pkexec : ON Directory : /home/bitrix/ext_www/rospirotorg.ru/bitrix/modules/mail/lib/helper/message/ |
Upload File : |
<?php namespace Bitrix\Mail\Helper\Message; use Bitrix\Main\ArgumentException; use Bitrix\Main\ObjectPropertyException; use Bitrix\Main\SystemException; use Bitrix\Mail\Internals\MessageClosureTable; final class MessageThreadLoader { private array $threadBeforeMessageId = []; private array $threadAfterMessageId = []; public function __construct( private int $messageId, ){} public function getMessageId(): int { return $this->messageId; } /** * returns an array of message ids sorted in ascending order * @return int[] */ public function getThreadMessageIds(): array { $threadMessageIds = [$this->messageId]; if ($this->threadBeforeMessageId) { $threadMessageIds = array_merge($this->threadBeforeMessageId, $threadMessageIds); } if ($this->threadAfterMessageId) { $threadMessageIds = array_merge($threadMessageIds, $this->threadAfterMessageId); } return $threadMessageIds; } /** * clears the message id array if you need to separately load the previous or next messages relative to the set messageId * @return void */ public function clearThreadMessageIds(): void { $this->threadBeforeMessageId = []; $this->threadAfterMessageId = []; } public function loadBeforeThreadMessageIds(?int $limit = null): void { $this->threadBeforeMessageId = []; $query = MessageClosureTable::query() ->setSelect(['PARENT_ID']) ->where('MESSAGE_ID', $this->messageId) ->where('PARENT_ID', '<', $this->messageId) ->setOrder(['PARENT_ID' => 'ASC']) ; if ($limit) { $query->setLimit($limit); } foreach ($query->fetchAll() as $item) { $this->threadBeforeMessageId[] = (int)$item['PARENT_ID']; } } public function loadAfterThreadMessageIds(?int $limit = null): void { $this->threadAfterMessageId = []; $query = MessageClosureTable::query() ->setSelect(['MESSAGE_ID']) ->where('PARENT_ID', $this->messageId) ->where('MESSAGE_ID', '>', $this->messageId) ->setOrder(['PARENT_ID' => 'ASC']) ; if ($limit) { $query->setLimit($limit); } foreach ($query->fetchAll() as $item) { $this->threadAfterMessageId[] = (int)$item['MESSAGE_ID']; } } public function loadFullThreadMessageIds(?int $limit = null): void { $this->loadBeforeThreadMessageIds($limit); $this->loadAfterThreadMessageIds($limit); } }