1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
sonetlogcollector.php
См. документацию.
1<?php
2
3namespace Bitrix\Socialnetwork\Internals\LiveFeed\Counter\Collector;
4
5use Bitrix\Main\Config\Option;
6use Bitrix\Main\Entity\ExpressionField;
7use Bitrix\Main\Type\Date;
8use Bitrix\Main\UserAccessTable;
9use Bitrix\Socialnetwork\LogRightTable;
10
12{
13 private const RECOUNT_FROM = 'lf_cnt_recount_from';
14 private int $userId;
15
20 private array $socialGroups = [];
21
22 private array $accessCodes = [];
23
24 private static array $instances = [];
25
26 public static function getInstance(int $userId)
27 {
28 if (!array_key_exists($userId, self::$instances))
29 {
30 self::$instances[$userId] = new self($userId);
31 }
32
33 return self::$instances[$userId];
34 }
35
36 private function __construct(int $userId)
37 {
38 $this->userId = $userId;
39 }
40
41 public function fetch(int $limit, int $offset): array
42 {
43 $result = [];
44
45 $query = LogRightTable::query()
46 ->setSelect([
47 'LOG_ID',
48 ])
49 ->whereIn('GROUP_CODE', $this->getAccessCodes())
50 ->where('LOG_UPDATE', '>', $this->getDateStartFrom())
51 ->setLimit($limit)
52 ->setOffset($offset)
53 ->exec();
54
55 foreach ($query->fetchAll() as $row)
56 {
57 $result[] = $row['LOG_ID'];
58 }
59
60 return $result;
61 }
62
63 public function fetchTotal(): int
64 {
65 $res = LogRightTable::getList([
66 'select' => ['CNT'],
67 'filter' => [
68 'GROUP_CODE' => $this->getAccessCodes(),
69 '>LOG_UPDATE' => $this->getDateStartFrom()
70 ],
71 'runtime' => [
72 new ExpressionField('CNT', 'COUNT(*)'),
73 ]
74 ])->fetch();
75
76 return $res['CNT'] ?? 0;
77 }
78
79
80 private function getUserAccessCodes(): array
81 {
82 return [
83 'G2',
84 'AU',
85 'U'.$this->userId,
86 ];
87 }
88
89 private function getUserAccessSocialGroups(): array
90 {
91 if (!empty($this->socialGroups))
92 {
93 return $this->socialGroups;
94 }
95
96 $query = UserAccessTable::query()
97 ->setDistinct()
98 ->setSelect([
99 'ACCESS_CODE',
100 ])
101 ->where('USER_ID', '=', $this->userId)
102 ->where('PROVIDER_ID', '=', 'socnetgroup')
103 ->exec();
104
105 foreach ($query->fetchAll() as $group)
106 {
107 $matches = [];
108 preg_match('/SG([0-9]+)/m', $group['ACCESS_CODE'], $matches);
109
110 if (isset($matches[0]))
111 {
112 $this->socialGroups[] = $matches[0];
113 }
114 }
115
116 return $this->socialGroups;
117 }
118
119 private function getDateStartFrom(): Date
120 {
121 $recountFromOption = Option::get('socialnetwork', self::RECOUNT_FROM, 'null', '-');
122
123 if ($recountFromOption !== 'null' && strtotime($recountFromOption))
124 {
125 return new Date($recountFromOption, 'Y-m-d H:i:s');
126 }
127
128 $format = 'Y-m-d H:i:s';
129 $twoWeeks = date($format, strtotime('-14 days'));
130
131 return new Date($twoWeeks, $format);
132 }
133
134 private function getAccessCodes(): array
135 {
136 if (!empty($this->accessCodes))
137 {
138 return $this->accessCodes;
139 }
140
141 $this->accessCodes = array_merge(
142 $this->getUserAccessSocialGroups(),
143 $this->getUserAccessCodes()
144 );
145
146 return $this->accessCodes;
147 }
148}
if(!is_object($USER)||! $USER->IsAuthorized()) $userId
Определения check_mail.php:18
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
Определения file_new.php:804
$res
Определения filter_act.php:7
$result
Определения get_property_values.php:14
$query
Определения get_search.php:11
$matches
Определения index.php:22