1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
total.php
См. документацию.
1<?php
2
3namespace Bitrix\Calendar\Internals\Counter\Processor;
4
5use Bitrix\Calendar\Integration\Pull\PushCommand;
6use Bitrix\Calendar\Integration\Pull\PushService;
7use Bitrix\Calendar\Internals\Counter;
8use Bitrix\Calendar\Internals\Counter\CounterDictionary;
9use Bitrix\Calendar\Internals\Counter\Event\Event;
10use Bitrix\Calendar\Internals\Counter\Event\EventCollection;
11
12class Total implements Base
13{
14 public function process(): void
15 {
16 $events = (EventCollection::getInstance())->list();
17 foreach ($events as $event)
18 {
19 /* @var $event Event */
20 $affectedUsers = $event->getData()['user_ids'] ?? [];
21 $this->recountTotal($affectedUsers);
22 }
23 }
24
25 private function recountTotal(array $userIds): void
26 {
27 if (empty($userIds))
28 {
29 return;
30 }
31
32 foreach ($userIds as $userId)
33 {
34 // total counter (left menu, top menu, etc.)
36 if (!$this->isSameValueCached($value, $userId, CounterDictionary::COUNTER_TOTAL))
37 {
38 \CUserCounter::Set(
39 $userId,
41 $value,
42 '**',
43 );
44
45 $this->sendUserCountersPush($userId);
46 }
47
48 // my calendar counter (top menu etc.)
50 if (!$this->isSameValueCached($value, $userId, CounterDictionary::COUNTER_MY))
51 {
52 \CUserCounter::Set(
53 $userId,
55 $value,
56 '**',
57 );
58 }
59
60 // open events total (top menu etc.)
62 if (!$this->isSameValueCached($value, $userId, CounterDictionary::COUNTER_OPEN_EVENTS))
63 {
64 \CUserCounter::Set(
65 $userId,
67 $value,
68 '**',
69 );
70 }
71 }
72 }
73
74 private function isSameValueCached(int $value, int $userId, string $code): bool
75 {
76 global $CACHE_MANAGER;
77
78 $cache = $CACHE_MANAGER->Get('user_counter' . $userId);
79 if (!$cache)
80 {
81 return false;
82 }
83
84 foreach ($cache as $item)
85 {
86 if (
87 $item['CODE'] === $code
88 && $item['SITE_ID'] === '**'
89 && (int)$item['CNT'] === $value
90 )
91 {
92 return true;
93 }
94 }
95
96 return false;
97 }
98
108 private function sendUserCountersPush(int $userId): void
109 {
110 PushService::addEvent($userId, [
111 'module_id' => PushService::MODULE_ID,
112 'command' => PushCommand::UpdateUserCounters->value,
113 'params' => [
114 'counters' => [
118 ],
119 ],
120 ]);
121 }
122}
if(!is_object($USER)||! $USER->IsAuthorized()) $userId
Определения check_mail.php:18
static getInstance()
Определения application.php:98
global $CACHE_MANAGER
Определения clear_component_cache.php:7
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
Определения file_new.php:804
if(!is_null($config))($config as $configItem)(! $configItem->isVisible()) $code
Определения options.php:195
$event
Определения prolog_after.php:141