1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
loader.php
См. документацию.
1<?php
2
3namespace Bitrix\Socialnetwork\Internals\LiveFeed\Counter;
4
5use Bitrix\Main\Application;
6use Bitrix\Main\Data\Cache;
7use Bitrix\Socialnetwork\Internals\LiveFeed\Counter;
8
12class Loader
13{
14 private int $userId;
15 private int $flagCounted = 0;
16 private int $flagCleared = 0;
17 private array $rows;
18
19 private const CACHE_PREFIX = 'sonet_scorer_cache_';
20 private const CACHE_TTL = 10 * 60;
21 private const CACHE_DIR = '/sonet/counterstate';
22
23 private const FLAGS = [
26 ];
27
28 public function __construct(int $userId)
29 {
30 $this->userId = $userId;
31 }
32
33 public function isCounterFlag(string $type): bool
34 {
35 return in_array($type, self::FLAGS, true);
36 }
37
38 public function getRawCounters(): array
39 {
40 return $this->rows;
41 }
42
43 public function getTotalCounters(): int
44 {
45 return count($this->rows);
46 }
47
48 public function isCounted(): bool
49 {
50 return (bool) $this->flagCounted;
51 }
52
53 public function getClearedDate(): int
54 {
55 return $this->flagCleared;
56 }
57
58 public function resetCache(): void
59 {
60 $cache = Cache::createInstance();
61 $cache->clean($this->getCacheTag(), $this->getCacheDir());
62 }
63
64 private function getCacheDir(): string
65 {
66 return self::CACHE_DIR . '/' . substr(md5($this->userId),2,2) . '/';
67 }
68
69 private function getCacheTag(): string
70 {
71 return self::CACHE_PREFIX . $this->userId;
72 }
73
74 public function fetchCounters(): void
75 {
76 $limit = Counter::getGlobalLimit();
77 if ($limit === 0)
78 {
79 $this->rows = $this->getFlags();
80 return;
81 }
82
84 ->setSelect([
85 'VALUE',
86 'SONET_LOG_ID',
87 'GROUP_ID',
88 'TYPE'
89 ])
90 ->where('USER_ID', $this->userId);
91
92 $rowsFlag = null;
93 if (!is_null($limit))
94 {
95 $rowsFlag = $this->getFlags();
96 $query->setLimit($limit);
97 }
98
99 $this->rows = $query->exec()->fetchAll();
100 if (!is_null($rowsFlag))
101 {
102 $this->rows = array_merge($this->rows, $rowsFlag);
103 }
104 }
105
106 private function getFlags(): array
107 {
108 $rows = [];
109 $cache = Cache::createInstance();
110
111 if ($cache->initCache(self::CACHE_TTL, $this->getCacheTag(), $this->getCacheDir()))
112 {
113 $rows = $cache->getVars();
114 }
115 else
116 {
117 $rows = CounterTable::query()
118 ->setSelect([
119 'VALUE',
120 'SONET_LOG_ID',
121 'GROUP_ID',
122 'TYPE'
123 ])
124 ->where('USER_ID', $this->userId)
125 ->whereIn('TYPE', self::FLAGS)
126 ->setLimit(2)
127 ->fetchAll();
128
129 if (!empty($rows))
130 {
131 $taggedCache = Application::getInstance()->getTaggedCache();
132 $taggedCache->StartTagCache($this->getCacheDir());
133 $taggedCache->RegisterTag($this->getCacheTag());
134
135 $cache->startDataCache();
136 $cache->endDataCache($rows);
137 $taggedCache->EndTagCache();
138 }
139 }
140
141 foreach ($rows as $row)
142 {
143 switch ($row['TYPE'])
144 {
145 case CounterDictionary::COUNTER_FLAG_COUNTED:
146 $this->flagCounted = (int) $row['VALUE'];
147 break;
148 case CounterDictionary::COUNTER_FLAG_CLEARED:
149 $this->flagCleared = (int) $row['VALUE'];
150 break;
151 }
152 }
153
154 return $rows;
155 }
156}
$type
Определения options.php:106
if(!is_object($USER)||! $USER->IsAuthorized()) $userId
Определения check_mail.php:18
static getInstance()
Определения application.php:98
Определения loader.php:13
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
Определения file_new.php:804
$query
Определения get_search.php:11
</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."%"
Определения waybill.php:936
$rows
Определения options.php:264