1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
counter.php
См. документацию.
1<?php
2
3namespace Bitrix\Socialnetwork\Internals\Space;
4
5use Bitrix\Socialnetwork\Integration\Tasks;
6use Bitrix\Socialnetwork\Integration\Calendar;
7use Bitrix\Socialnetwork\Integration\SocialNetwork\WorkGroup;
8use Bitrix\Socialnetwork\Integration\SocialNetwork\LiveFeed;
9use Bitrix\Socialnetwork\Internals\Space\Counter\Cache;
10use Bitrix\Socialnetwork\Internals\Space\Counter\Dictionary;
11use Bitrix\Socialnetwork\Internals\Space\Counter\ProviderCollection;
12
14{
15 private static array $instance = [];
16 private Cache $cache;
17
18 public static function getInstance(int $userId): self
19 {
20 if (!array_key_exists($userId, self::$instance))
21 {
22 self::$instance[$userId] = new self(
23 $userId,
24 new ProviderCollection(...[
29 ])
30 );
31 }
32
33 return self::$instance[$userId];
34 }
35
43 public function getTotal(int $spaceId = 0): int
44 {
45 $total = 0;
46
47 foreach ($this->providerCollection as $provider)
48 {
49 $total += $provider->getTotal($spaceId);
50 }
51
52 return $total;
53 }
54
62 public function getValue(int $spaceId = 0, array $metrics = []): int
63 {
64 if (empty($metrics))
65 {
66 return $this->getTotal($spaceId);
67 }
68
69 $value = 0;
70
71 foreach ($this->providerCollection as $provider)
72 {
73 $value += $provider->getValue($spaceId, $metrics);
74 }
75
76 return $value;
77 }
78
83 public function getAvailableMetrics(): array
84 {
85 $availableMetrics = [];
86
87 foreach ($this->providerCollection as $provider)
88 {
89 $availableMetrics = array_merge($availableMetrics, $provider->getAvailableMetrics());
90 }
91
92 return $availableMetrics;
93 }
94
106 public function getMemberSpaceCounters(): array
107 {
108 $total = 0;
109 $spacesTotal = $this->getMemberSpacesTotal();
110 $invitationsTotal = $this->getInvitationsTotal();
111 $total += $invitationsTotal;
112 $total += $spacesTotal['total'];
113
114 return [
115 'userId' => $this->userId,
116 'total' => $total,
117 'spaces' => $spacesTotal['spaces'],
118 'invitations' => $invitationsTotal,
119 ];
120 }
121
122 private function __construct(private int $userId, private ProviderCollection $providerCollection)
123 {
124 $this->cache = new Cache($this->userId);
125 $this->updateLeftMenuCounter();
126 }
127
128 public function updateLeftMenuCounter(): void
129 {
130 $memberCounters = $this->getMemberSpaceCounters();
131 $value = $memberCounters['total'];
132 $code = Dictionary::LEFT_MENU_SPACES;
133
134 if (!$this->cache->isSameLeftMenuTotal($code, $value))
135 {
136 \CUserCounter::Set(
137 $this->userId,
138 $code,
139 $value,
140 '**',
141 '',
142 false
143 );
144 }
145 }
146
147 private function getMemberSpacesTotal(): array
148 {
149 $total = 0;
150 $spaces = [];
151
152 $userSpaces = $this->cache->getUserSpaceIds();
153
154 foreach ($userSpaces as $spaceId)
155 {
156 $spaceTotal = $this->getTotal($spaceId);
157
158 if ($spaceTotal === 0)
159 {
160 continue;
161 }
162
163 $total += $spaceTotal;
164
165 $spaceCounters = [
166 'id' => $spaceId,
167 'total' => $spaceTotal,
168 ];
169
170 foreach ($this->getAvailableMetrics() as $metric)
171 {
172 $spaceCounters['metrics'][$metric] = $this->getValue($spaceId, [$metric]);
173 }
174
175 $spaces[] = $spaceCounters;
176 }
177
178 return [
179 'total' => $total,
180 'spaces' => $spaces,
181 ];
182 }
183
184 private function getInvitationsTotal(): int
185 {
186 $total = 0;
187
188 $invitations = $this->cache->getUserInvitationIds();
189
190 foreach ($invitations as $invitationId)
191 {
192 $total += $this->getValue($invitationId, [Dictionary::COUNTERS_WORKGROUP_REQUEST_OUT]);
193 }
194
195 return $total;
196 }
197}
if(!Loader::includeModule('messageservice')) $provider
Определения callback_ednaruimhpx.php:21
if(!is_object($USER)||! $USER->IsAuthorized()) $userId
Определения check_mail.php:18
getValue(int $spaceId=0, array $metrics=[])
Определения counter.php:62
getTotal(int $spaceId=0)
Определения counter.php:43
static getInstance(int $userId)
Определения counter.php:18
</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