Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
counter.php
1<?php
2
4
5class Counter
6{
7 protected $component;
9 protected $request;
10
11 protected $emptyCounter = false;
12
13 public function __construct($params)
14 {
15 if (!empty($params['component']))
16 {
17 $this->component = $params['component'];
18 }
19 if (!empty($params['processorInstance']))
20 {
21 $this->processorInstance = $params['processorInstance'];
22 }
23 if (!empty($params['request']))
24 {
25 $this->request = $params['request'];
26 }
27 else
28 {
29 $this->request = Util::getRequest();
30 }
31 }
32
33 public function getRequest()
34 {
35 return $this->request;
36 }
37
38 protected function getComponent()
39 {
40 return $this->component;
41 }
42
43 protected function getProcessorInstance()
44 {
46 }
47
48 public function setEmptyCounter($value = false): void
49 {
50 $this->emptyCounter = $value;
51 }
52
53 public function getEmptyCounter(): bool
54 {
56 }
57
58 public function processCounterTypeData(&$result): void
59 {
60 $params = $this->getComponent()->arParams;
61
62 $result['COUNTER_TYPE'] = \CUserCounter::LIVEFEED_CODE;
63
64 if ($params['GROUP_ID'] > 0)
65 {
66 $result['COUNTER_TYPE'] = \CUserCounter::LIVEFEED_CODE . 'SG' . $params['GROUP_ID'];
67 }
68 elseif(
69 $params['IS_CRM'] === 'Y'
70 && (
71 $params['SET_LOG_COUNTER'] !== 'N'
72 || $params['SET_LOG_PAGE_CACHE'] !== 'N'
73 )
74 )
75 {
76 $result['COUNTER_TYPE'] = (
77 is_set($params['CUSTOM_DATA'])
78 && is_set($params['CUSTOM_DATA']['CRM_PRESET_TOP_ID'])
79 && $params['CUSTOM_DATA']['CRM_PRESET_TOP_ID'] === 'all'
80 ? 'CRM_**_ALL'
81 : 'CRM_**'
82 );
83 }
84 elseif(($params['EXACT_EVENT_ID'] ?? '') === 'blog_post')
85 {
86 $result['COUNTER_TYPE'] = 'blog_post';
87 }
88 }
89
90 public function clearLogCounter(&$result): void
91 {
92 $params = $this->getComponent()->arParams;
93
94 if (
95 $params['SET_LOG_COUNTER'] !== 'Y'
96 || (isset($result['EXPERT_MODE_SET']) && $result['EXPERT_MODE_SET'])
98 )
99 {
100 return;
101 }
102
103 if (
104 (int)$result['LOG_COUNTER'] > 0
105 || $this->getEmptyCounter()
106 )
107 {
108 \CUserCounter::clear(
109 $result['currentUserId'],
110 $result['COUNTER_TYPE'],
111 [ SITE_ID, '**' ],
112 true, // sendPull
113 true // multiple
114 );
115
116 if ((int)$result['LOG_COUNTER_IMPORTANT'] > 0)
117 {
118 \CUserCounter::clear(
119 $result['currentUserId'],
120 'BLOG_POST_IMPORTANT',
121 SITE_ID
122 );
123 }
124
125 $res = getModuleEvents('socialnetwork', 'OnSonetLogCounterClear');
126 while ($eventFields = $res->fetch())
127 {
128 executeModuleEventEx($eventFields, [ $result['COUNTER_TYPE'], (int)$result['LAST_LOG_TS'] ]);
129 }
130 }
131 elseif (in_array($result['COUNTER_TYPE'], [ '**', 'CRM_**' ], true)) // set last date only
132 {
133 $pool = \Bitrix\Main\Application::getInstance()->getConnectionPool();
134 $pool->useMasterOnly(true);
135
136 \CUserCounter::clear(
137 $result['currentUserId'],
138 $result['COUNTER_TYPE'],
139 [ SITE_ID, '**' ],
140 false, // sendPull
141 false, // multiple
142 false // cleanCache
143 );
144
145 $pool->useMasterOnly(false);
146 }
147 }
148
149 public function setLogCounter(&$result): void
150 {
151 $params = $this->getComponent()->arParams;
152
153 $result['LOG_COUNTER'] = 0;
154 $result['LOG_COUNTER_IMPORTANT'] = 0;
155
156 if (
157 $params['SET_LOG_COUNTER'] !== 'Y'
159 )
160 {
161 return;
162 }
163
164 $counters = \CUserCounter::getValues($result['currentUserId'], SITE_ID);
165
166 if (isset($counters['BLOG_POST_IMPORTANT']))
167 {
168 $result['LOG_COUNTER_IMPORTANT'] = (int)$counters['BLOG_POST_IMPORTANT'];
169 }
170
171 if (isset($counters[$result['COUNTER_TYPE']]))
172 {
173 $result['LOG_COUNTER'] = (int)$counters[$result['COUNTER_TYPE']];
174 }
175 else
176 {
177 $this->setEmptyCounter(true);
178 $result['LOG_COUNTER'] = 0;
179 }
180 }
181}