1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
state.php
См. документацию.
1<?php
2
3namespace Bitrix\Calendar\Internals\Counter\State;
4
5use Bitrix\Calendar\Internals\Counter\CounterDictionary;
6use Bitrix\Calendar\OpenEvents\Provider\CategoryMuteProvider;
7
8class State
9{
10 private Loader $loader;
11
12 protected int $userId;
13 protected array $counters = [];
15
16 public function __construct(int $userId, Loader $loader)
17 {
18 $this->userId = $userId;
19 $this->loader = $loader;
20 $this->muteProvider = new CategoryMuteProvider($this->userId);
21 $this->init();
22 }
23
24 public function init(): void
25 {
26 $this->counters = $this->getCountersEmptyState();
27 $this->loadCounters();
28 }
29
30 public function get(string $metaProp = CounterDictionary::META_PROP_ALL): array
31 {
32 return $this->counters[$metaProp] ?? [];
33 }
34
35 private function loadCounters(): void
36 {
37 $categoryIds = [];
38 foreach ($this->loader->getRawCounters() as $counter)
39 {
40 $type = $counter['TYPE'];
41 $parentId = (int)$counter['PARENT_ID'];
42
44 {
45 $categoryIds[] = $parentId;
46 }
47 }
48
49 $mutedCategories = $this->muteProvider->getByCategoryIds($categoryIds);
50
51 foreach ($this->loader->getRawCounters() as $counter)
52 {
53 $type = $counter['TYPE'];
54 $value = (int)$counter['VALUE'];
55 $eventId = (int)$counter['EVENT_ID'];
56 $parentId = (int)$counter['PARENT_ID'];
57
58 // pre-calculating open events
61 {
62 // for specific category
63 $this->counters[$openEventMetaProp]['category'][$parentId] ??= 0;
64 $this->counters[$openEventMetaProp]['category'][$parentId] += $value;
65
66 // for all categories
67 $isMuted = $mutedCategories[$parentId] ?? false;
68 if (!$isMuted)
69 {
70 $this->counters[$openEventMetaProp]['total'] += $value;
71 }
72
73 // for specific event
74 $this->counters[CounterDictionary::META_PROP_NEW_EVENTS][$eventId] = $value;
75 }
76 }
77 }
78
79 private function getCountersEmptyState(): array
80 {
81 return [
85 'category' => [],
86 'total' => 0,
87 ],
88 ];
89 }
90}
$type
Определения options.php:106
__construct(int $userId, Loader $loader)
Определения state.php:16
CategoryMuteProvider $muteProvider
Определения state.php:14
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
Определения file_new.php:804
$counter
Определения options.php:5