1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
counterstate.php
См. документацию.
1<?php
2
3namespace Bitrix\Socialnetwork\Internals\LiveFeed\Counter;
4
5use Bitrix\Socialnetwork\Internals\LiveFeed\Counter;
6use Bitrix\Socialnetwork\Internals\Registry\UserRegistry;
7
8abstract class CounterState implements \Iterator
9{
10 private Counter\Loader $loader;
11
12 protected int $userId;
13 protected array $counters = [];
14
15 protected function __construct(int $userId, Counter\Loader $loader)
16 {
17 $this->userId = $userId;
18 $this->loader = $loader;
19 $this->init();
20 }
21
22 abstract public function rewind(): void;
23
24 #[\ReturnTypeWillChange]
25 abstract public function current();
26
27 #[\ReturnTypeWillChange]
28 abstract public function key();
29
30 abstract public function next(): void;
31
32 abstract public function valid(): bool;
33
34 abstract public function getSize(): int;
35
36 abstract protected function loadCounters(): void;
37
38 abstract public function updateState(array $rawCounters, array $types = [], array $sonetLogIds = []): void;
39
40 public function init(): void
41 {
42 $this->counters = $this->getCountersEmptyState();
43 $this->loadCounters();
44 }
45
46 public function getLoader(): Counter\Loader
47 {
48 return $this->loader;
49 }
50
51 public function isCounted(): bool
52 {
53 return $this->loader->isCounted();
54 }
55
56 public function getClearedDate(): int
57 {
58 return $this->loader->getClearedDate();
59 }
60
61 public function resetCache(): void
62 {
63 $this->loader->resetCache();
64 }
65
66 public function getRawCounters(string $meta = CounterDictionary::META_PROP_ALL): array
67 {
68 return $this->counters[$meta] ?? [];
69 }
70
71 public function getValue(string $name, int $groupId = null): int
72 {
74
75 if ($groupId >= 0)
76 {
77 if (
78 !array_key_exists($name, $counters)
79 || !array_key_exists($groupId, $counters[$name])
80 )
81 {
82 return 0;
83 }
84
85 return $counters[$name][$groupId];
86 }
87
88 return 0;
89
90// if (!array_key_exists($name, $counters))
91// {
92// return 0;
93// }
94//
95// return array_sum($counters[$name]);
96 }
97
102 protected function updateRawCounters(): void
103 {
104 $this->counters = $this->getCountersEmptyState();
105
106 $user = UserRegistry::getInstance($this->userId);
107 $groups = $user->getUserGroups(UserRegistry::MODE_GROUP);
108
109 $tmpHeap[] = [];
110 foreach ($this as $item)
111 {
112 if ($this->getLoader()->isCounterFlag($item['TYPE']))
113 {
114 continue;
115 }
116
117 $logId = $item['SONET_LOG_ID'];
118 $groupId = $item['GROUP_ID'];
119 $value = $item['VALUE'];
120 $type = $item['TYPE'];
121
122 $meta = $this->getMetaProp($item, $groups);
123 $subType = $this->getItemSubType($type);
124
125 if (!isset($this->counters[$meta][$type][$groupId]))
126 {
127 $this->counters[$meta][$type][$groupId] = 0;
128 }
129 if (!isset($this->counters[$meta][$subType][$groupId]))
130 {
131 $this->counters[$meta][$subType][$groupId] = 0;
132 }
133 if (!isset($tmpHeap[$meta][$subType][$groupId]))
134 {
135 $tmpHeap[$meta][$subType][$groupId] = [];
136 }
137 if (!isset($this->counters[CounterDictionary::META_PROP_SONET][$type][$groupId]))
138 {
139 $this->counters[CounterDictionary::META_PROP_SONET][$type][$groupId] = 0;
140 }
141 if (!isset($this->counters[CounterDictionary::META_PROP_SONET][$subType][$groupId]))
142 {
143 $this->counters[CounterDictionary::META_PROP_SONET][$subType][$groupId] = 0;
144 }
145 if (!isset($this->counters[CounterDictionary::META_PROP_ALL][$type][$groupId]))
146 {
147 $this->counters[CounterDictionary::META_PROP_ALL][$type][$groupId] = 0;
148 }
149 if (!isset($this->counters[CounterDictionary::META_PROP_ALL][$subType][$groupId]))
150 {
151 $this->counters[CounterDictionary::META_PROP_ALL][$subType][$groupId] = 0;
152 }
153
154 if (!isset($tmpHeap[$meta][$type][$groupId][$logId]))
155 {
156 $tmpHeap[$meta][$type][$groupId][$logId] = $value;
157 $this->counters[$meta][$type][$groupId] += $value;
158
159 if (in_array($meta, [CounterDictionary::META_PROP_GROUP]))
160 {
161 $this->counters[CounterDictionary::META_PROP_SONET][$type][$groupId] += $value;
162 }
163 }
164
165 if (
166 $type !== $subType
167 && !isset($tmpHeap[$meta][$subType][$groupId][$logId])
168 )
169 {
170 $tmpHeap[$meta][$subType][$groupId][$logId] = $value;
171 $this->counters[$meta][$subType][$groupId] += $value;
172
173 if (in_array($meta, [CounterDictionary::META_PROP_GROUP]))
174 {
175 $this->counters[CounterDictionary::META_PROP_SONET][$subType][$groupId] += $value;
176 }
177 }
178
179 if (!isset($tmpHeap[CounterDictionary::META_PROP_ALL][$type][$groupId][$logId]))
180 {
181 $tmpHeap[CounterDictionary::META_PROP_ALL][$type][$groupId][$logId] = $value;
182 $this->counters[CounterDictionary::META_PROP_ALL][$type][$groupId] += $value;
183 }
184
185 if (
186 $type !== $subType
187 && !isset($tmpHeap[CounterDictionary::META_PROP_ALL][$subType][$groupId][$logId])
188 )
189 {
190 $tmpHeap[CounterDictionary::META_PROP_ALL][$subType][$groupId][$logId] = $value;
191 $this->counters[CounterDictionary::META_PROP_ALL][$subType][$groupId] += $value;
192 }
193 }
194
195 unset($tmpHeap);
196 }
197
198 private function getCountersEmptyState(): array
199 {
200 return [
204 ];
205 }
206
207 private function getItemSubType(string $type): string
208 {
210 {
212 }
213
215 {
217 }
218
219 return $type;
220 }
221
222 private function getMetaProp(array $item, array $groups): string
223 {
224 if (array_key_exists($item['GROUP_ID'], $groups))
225 {
227 }
228
230 }
231}
$type
Определения options.php:106
Определения loader.php:13
updateState(array $rawCounters, array $types=[], array $sonetLogIds=[])
getValue(string $name, int $groupId=null)
Определения counterstate.php:71
__construct(int $userId, Counter\Loader $loader)
Определения counterstate.php:15
getRawCounters(string $meta=CounterDictionary::META_PROP_ALL)
Определения counterstate.php:66
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
Определения file_new.php:804
$groups
Определения options.php:30
$name
Определения menu_edit.php:35
$user
Определения mysql_to_pgsql.php:33