Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
page.php
1<?php
2
4
8
9class Page
10{
11 protected $component;
13 protected $request;
14
15 protected $needSetLogPage = false;
16 protected $dateLastPageStart = null;
17 protected $lastPageData = null;
18 protected $prevPageLogIdList = [];
19 protected $dateFirstPageTS = 0;
20
21 public function __construct($params)
22 {
23 if (!empty($params['component']))
24 {
25 $this->component = $params['component'];
26 }
27 if (!empty($params['processorInstance']))
28 {
29 $this->processorInstance = $params['processorInstance'];
30 }
31 if (!empty($params['request']))
32 {
33 $this->request = $params['request'];
34 }
35 else
36 {
37 $this->request = Util::getRequest();
38 }
39 }
40
41 public function getRequest()
42 {
43 return $this->request;
44 }
45
46 protected function getComponent()
47 {
48 return $this->component;
49 }
50 protected function getProcessorInstance()
51 {
52 return $this->processorInstance;
53 }
54
55 public function setNeedSetLogPage($value = false): void
56 {
57 $this->needSetLogPage = $value;
58 }
59 public function getNeedSetLogPage(): bool
60 {
61 return $this->needSetLogPage;
62 }
63
64 public function setDateLastPageStart($value = null): void
65 {
66 $this->dateLastPageStart = $value;
67 }
68 public function getDateLastPageStart()
69 {
70 return $this->dateLastPageStart;
71 }
72
73 public function setLastPageData($value = null): void
74 {
75 $this->lastPageData = $value;
76 }
77 public function getLastPageData()
78 {
79 return $this->lastPageData;
80 }
81
82 public function setPrevPageLogIdList($value = []): void
83 {
84 $this->prevPageLogIdList = $value;
85 }
86 public function getPrevPageLogIdList(): array
87 {
88 return $this->prevPageLogIdList;
89 }
90
91 public function setDateFirstPageTimestamp($value = 0): void
92 {
93 $this->dateFirstPageTS = $value;
94 }
95 public function getDateFirstPageTimestamp(): int
96 {
97 return $this->dateFirstPageTS;
98 }
99
100 public function preparePrevPageLogId(): void
101 {
102 $request = $this->getRequest();
103 $params = $this->getComponent()->arParams;
104
105 $prevPageLogId = null;
106 if (isset($params['PREV_PAGE_LOG_ID']))
107 {
108 $prevPageLogId = $params['PREV_PAGE_LOG_ID'];
109 }
110 elseif ($request->get('pplogid') !== null)
111 {
112 $prevPageLogId = $request->get('pplogid');
113 }
114
115 if ($prevPageLogId !== null)
116 {
117 $prevPageLogIdList = explode('|', trim($prevPageLogId));
118 foreach($prevPageLogIdList as $key => $val)
119 {
120 preg_match('/^(\d+)$/', $val, $matches);
121 if (count($matches) <= 0)
122 {
123 unset($prevPageLogIdList[$key]);
124 }
125 }
126 $prevPageLogIdList = array_map(static function($logId) { return (int)$logId; }, array_unique($prevPageLogIdList));
128 }
129 }
130
131 public function getLogPageData(&$result): void
132 {
133 $params = $this->getComponent()->arParams;
135
136 $this->setNeedSetLogPage(false);
137
138 if ($params['SET_LOG_PAGE_CACHE'] === 'Y')
139 {
140 $resPages = LogPageTable::getList([
141 'order' => [],
142 'filter' => [
143 'USER_ID' => $result['currentUserId'],
144 '=SITE_ID' => SITE_ID,
145 '=GROUP_CODE' => $result['COUNTER_TYPE'],
146 'PAGE_SIZE' => $params['PAGE_SIZE'],
147 'PAGE_NUM' => $result['PAGE_NUMBER']
148 ],
149 'select' => [ 'PAGE_LAST_DATE', 'TRAFFIC_AVG', 'TRAFFIC_CNT', 'TRAFFIC_LAST_DATE' ]
150 ]);
151
152 if ($pagesFields = $resPages->fetch())
153 {
154 $this->setDateLastPageStart($pagesFields['PAGE_LAST_DATE']);
155 $this->setLastPageData([
156 'TRAFFIC_LAST_DATE_TS' => ($pagesFields['TRAFFIC_LAST_DATE'] ? $processorInstance->makeTimeStampFromDateTime($pagesFields['TRAFFIC_LAST_DATE'], 'FULL') : 0),
157 'TRAFFIC_AVG' => (int)$pagesFields['TRAFFIC_AVG'],
158 'TRAFFIC_CNT' => (int)$pagesFields['TRAFFIC_CNT']
159 ]);
160 $processorInstance->setFilterKey('>=LOG_UPDATE', convertTimeStamp($processorInstance->makeTimeStampFromDateTime($pagesFields['PAGE_LAST_DATE'], 'FULL') - 60*60*24*1, 'FULL'));
161 }
162 elseif(
163 $result['isExtranetSite']
164 && !$this->getComponent()->getCurrentUserAdmin()
165 ) // extranet user
166 {
167 $res = UserToGroupTable::getList([
168 'order' => [
169 'GROUP_DATE_CREATE' => 'ASC'
170 ],
171 'filter' => [
172 'USER_ID' => $result['currentUserId'],
173 '@ROLE' => UserToGroupTable::getRolesMember(),
174 '!GROUP_DATE_CREATE' => false
175 ],
176 'select' => [
177 'GROUP_DATE_CREATE' => 'GROUP.DATE_CREATE'
178 ]
179 ]);
180 if ($relation = $res->fetch())
181 {
182 $processorInstance->setFilterKey('>=LOG_UPDATE', $relation['GROUP_DATE_CREATE']);
183 }
184 }
185 elseif (
186 (
187 $result['COUNTER_TYPE'] !== '**'
188 || $result['MY_GROUPS_ONLY'] !== 'Y'
189 )
190 && $result['PAGE_NUMBER'] <= 1
191 )
192 {
193 $resPages = LogPageTable::getList([
194 'order' => [
195 'PAGE_LAST_DATE' => 'DESC'
196 ],
197 'filter' => [
198 '=SITE_ID' => SITE_ID,
199 '=GROUP_CODE' => $result['COUNTER_TYPE'],
200 'PAGE_SIZE' => $params['PAGE_SIZE'],
201 'PAGE_NUM' => $result['PAGE_NUMBER']
202 ],
203 'select' => [ 'PAGE_LAST_DATE' ]
204 ]);
205
206 if ($pagesFields = $resPages->fetch())
207 {
208 $this->setDateLastPageStart($pagesFields['PAGE_LAST_DATE']);
209 $processorInstance->setFilterKey('>=LOG_UPDATE', convertTimeStamp($processorInstance->makeTimeStampFromDateTime($pagesFields['PAGE_LAST_DATE'], 'FULL') - 60*60*24*4, 'FULL'));
210 $this->setNeedSetLogPage(true);
211 }
212 }
213 }
214 }
215
216 public function setLogPageData(&$result): void
217 {
218 $params = $this->getComponent()->arParams;
220
221 $lastEventFields = false;
222 if (is_array($result['Events']))
223 {
224 $tmp = $result['Events'];
225 $lastEventFields = array_pop($tmp);
226 unset($tmp);
227 }
228
229 $result['LAST_ENTRY_DATE_TS'] = 0;
230 $result['dateLastPageId'] = ($lastEventFields ? $lastEventFields['ID'] : 0);
231
232 if ($lastEventFields)
233 {
234 if ($params['USE_FOLLOW'] === 'N')
235 {
236 if (!empty($processorInstance->getOrderKey('LOG_DATE')))
237 {
238 $result['LAST_ENTRY_DATE_TS'] = $processorInstance->makeTimeStampFromDateTime($lastEventFields['LOG_DATE'], 'FULL');
239 }
240 elseif ($lastEventFields['LOG_UPDATE'])
241 {
242 $result['LAST_ENTRY_DATE_TS'] = $processorInstance->makeTimeStampFromDateTime($lastEventFields['LOG_UPDATE'], 'FULL');
243 }
244 }
245
246 if (
247 empty($result['LAST_ENTRY_DATE_TS'])
248 && $lastEventFields['DATE_FOLLOW']
249 )
250 {
251 $result['LAST_ENTRY_DATE_TS'] = $processorInstance->makeTimeStampFromDateTime($lastEventFields['DATE_FOLLOW'], 'FULL');
252 }
253 }
254
255 if ($params['SET_LOG_PAGE_CACHE'] !== 'N')
256 {
257 $result['dateLastPageTS'] = $result['LAST_ENTRY_DATE_TS'];
258 }
259
260 $dateLastPage = null;
261 if (!empty($result['dateLastPageTS']))
262 {
263 $dateLastPage = convertTimeStamp($result['dateLastPageTS'], 'FULL');
264 }
265
266 if (
267 $params['SET_LOG_PAGE_CACHE'] === 'Y'
268 && $dateLastPage
269 && Util::checkUserAuthorized()
270 && (
271 !$this->getDateLastPageStart()
272 || $this->getDateLastPageStart() != $dateLastPage
273 || $this->getNeedSetLogPage()
274 )
275 )
276 {
278 if (empty($lastPageData))
279 {
280 $lastPageData = [
281 'TRAFFIC_AVG' => 0,
282 'TRAFFIC_CNT' => 0,
283 'TRAFFIC_LAST_DATE_TS' => 0
284 ];
285 }
286
287 $bNeedSetTraffic = \CSocNetLogComponent::isSetTrafficNeeded([
288 'PAGE_NUMBER' => $result['PAGE_NUMBER'],
289 'GROUP_CODE' => $result['COUNTER_TYPE'],
290 'TRAFFIC_LAST_DATE_TS' => $lastPageData['TRAFFIC_LAST_DATE_TS']
291 ]);
292
293 \CSocNetLogPages::set(
294 $result['currentUserId'],
295 convertTimeStamp($processorInstance->makeTimeStampFromDateTime($dateLastPage, 'FULL') - $result['TZ_OFFSET'], 'FULL'),
296 $params['PAGE_SIZE'],
297 $result['PAGE_NUMBER'],
298 SITE_ID,
299 $result['COUNTER_TYPE'],
300 (
301 $bNeedSetTraffic
302 ? ($lastPageData['TRAFFIC_AVG'] + $this->getDateFirstPageTimestamp() - $result['dateLastPageTS']) / ($lastPageData['TRAFFIC_CNT'] + 1)
303 : false
304 ),
305 (
306 $bNeedSetTraffic
307 ? ($lastPageData['TRAFFIC_CNT'] + 1)
308 : false
309 )
310 );
311
312 if (
313 (int)$result['PAGE_NUMBER'] === 1
314 && $params['USE_TASKS'] === 'Y'
315 && $result['EXPERT_MODE'] !== 'Y'
316 )
317 {
318 $result['EXPERT_MODE_SET'] = LogViewTable::checkExpertModeAuto($result['currentUserId'], $processorInstance->getTasksCount(), $params['PAGE_SIZE']);
319 if ($result['EXPERT_MODE_SET'])
320 {
321 $params['SET_LOG_COUNTER'] = 'N';
322 $this->getComponent()->arParams = $params;
323 }
324 }
325 }
326 }
327
328 public function deleteLogPageData($result): void
329 {
330 $params = $this->getComponent()->arParams;
331
332 if (
333 empty($result['arLogTmpID'])
334 && $params['SET_LOG_PAGE_CACHE'] === 'Y'
335 && $this->getDateLastPageStart() !== null
336 && Util::checkUserAuthorized()
337 )
338 {
339 \CSocNetLogPages::deleteEx($result['currentUserId'], SITE_ID, $params['PAGE_SIZE'], $result['COUNTER_TYPE']);
340 $this->setNeedSetLogPage(true);
341 }
342 }
343
344}