3namespace Bitrix\Socialnetwork\Internals\EventService\Queue;
5use Bitrix\Main\UserTable;
6use Bitrix\Main\Web\Json;
7use Bitrix\Socialnetwork\Internals\EventService\Event;
8use Bitrix\Socialnetwork\Internals\EventService\EventTable;
9use Bitrix\Socialnetwork\Internals\EventService\Exception\CounterQueuePopException;
10use Bitrix\Socialnetwork\Internals\EventService\Processors\SpaceEventProcessor;
11use Bitrix\Socialnetwork\Internals\EventService\Recepients\Recepient;
19 private array $popped = [];
20 private array $buffer = [];
21 private static Queue|
null $instance =
null;
27 self::$instance =
new self();
29 return self::$instance;
32 private function __construct()
40 'EVENT_ID' =>
$event->getId(),
41 'USER_ID' =>
$user->getId(),
42 'PRIORITY' => $this->getPriority(
$user),
46 public function save(): void
55 (
new Agent())->addAgent();
61 $queue = $this->
get($spaceProcessor->getStepLimit());
62 $events = $this->getEvents($queue[
'event_ids']);
63 $users = $this->getUsers($queue[
'user_ids']);
65 foreach ($queue[
'rows'] as $row)
67 $event = (isset($events[$row[
'event_id']])) ? $events[$row[
'event_id']] :
null;
68 $user = (isset($users[$row[
'user_id']])) ? $users[$row[
'user_id']] :
null;
72 $spaceProcessor->processEventForUser(
$event,
$user);
78 return count($queue[
'rows']);
81 private function get(
int $limit):
array
83 if (!empty($this->popped))
110 $this->popped[] = $row[
'ID'];
112 $userId = (int) $row[
'USER_ID'];
113 $eventId = (int) $row[
'EVENT_ID'];
114 $queue[
'user_ids'][] =
$userId;
115 $queue[
'event_ids'][] = $eventId;
118 'event_id' => $eventId,
125 private function done(): void
127 if (empty($this->popped))
132 QueueTable::deleteByFilter([
133 'ID' => $this->popped,
139 private function getPriority(Recepient
$user): int
141 if (!
$user->isOnline())
143 return self::PRIORITY_LOW;
146 if (
$user->isWatchingSpaces())
148 return self::PRIORITY_HIGH;
151 return self::PRIORITY_MEDIUM;
154 private function getEvents(
array $eventIds):
array
156 if (empty($eventIds))
162 'select' => [
'ID',
'HID',
'TYPE',
'DATA'],
170 while ($row =
$res->fetch())
172 $events[$row[
'ID']] = Event\Factory::buildEvent(
175 Json::decode($row[
'DATA']),
183 private function getUsers(
array $userIds):
array
190 $res = UserTable::getList([
191 'select' => [
'ID',
'IS_ONLINE'],
199 while ($row =
$res->fetch())
201 $isOnline = (
$user[
'IS_ONLINE'] ??
'Y') ===
'Y';
202 $users[$row[
'ID']] =
new Recepient($row[
'ID'], $isOnline);
if(!is_object($USER)||! $USER->IsAuthorized()) $userId
static getList(array $parameters=array())
static addMulti($rows, $ignoreEvents=false)
add(Event $event, Recepient $user)
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
</p ></td >< td valign=top style='border-top:none;border-left:none;border-bottom:solid windowtext 1.0pt;border-right:solid windowtext 1.0pt;padding:0cm 2.0pt 0cm 2.0pt;height:9.0pt'>< p class=Normal align=center style='margin:0cm;margin-bottom:.0001pt;text-align:center;line-height:normal'>< a name=ТекстовоеПоле54 ></a ><?=($taxRate > count( $arTaxList) > 0) ? $taxRate."%"