13 private const RECOUNT_FROM =
'lf_cnt_recount_from';
20 private array $socialGroups = [];
22 private array $accessCodes = [];
24 private static array $instances = [];
28 if (!array_key_exists($userId, self::$instances))
30 self::$instances[$userId] =
new self($userId);
33 return self::$instances[$userId];
36 private function __construct(
int $userId)
38 $this->userId = $userId;
41 public function fetch(
int $limit,
int $offset): array
45 $query = LogRightTable::query()
49 ->whereIn(
'GROUP_CODE', $this->getAccessCodes())
50 ->where(
'LOG_UPDATE',
'>', $this->getDateStartFrom())
55 foreach ($query->fetchAll() as $row)
57 $result[] = $row[
'LOG_ID'];
65 $res = LogRightTable::getList([
68 'GROUP_CODE' => $this->getAccessCodes(),
69 '>LOG_UPDATE' => $this->getDateStartFrom()
72 new ExpressionField(
'CNT',
'COUNT(*)'),
76 return $res[
'CNT'] ?? 0;
80 private function getUserAccessCodes(): array
89 private function getUserAccessSocialGroups(): array
91 if (!empty($this->socialGroups))
93 return $this->socialGroups;
96 $query = UserAccessTable::query()
101 ->where(
'USER_ID',
'=', $this->userId)
102 ->where(
'PROVIDER_ID',
'=',
'socnetgroup')
105 foreach ($query->fetchAll() as $group)
108 preg_match(
'/SG([0-9]+)/m', $group[
'ACCESS_CODE'], $matches);
110 if (isset($matches[0]))
112 $this->socialGroups[] = $matches[0];
116 return $this->socialGroups;
119 private function getDateStartFrom(): Date
121 $recountFromOption = Option::get(
'socialnetwork', self::RECOUNT_FROM,
'null',
'-');
123 if ($recountFromOption !==
'null' && strtotime($recountFromOption))
125 return new Date($recountFromOption,
'Y-m-d H:i:s');
128 return new Date(
'2023-10-03 00:00:00',
'Y-m-d H:i:s');
131 private function getAccessCodes(): array
133 if (!empty($this->accessCodes))
135 return $this->accessCodes;
138 $this->accessCodes = array_merge(
139 $this->getUserAccessSocialGroups(),
140 $this->getUserAccessCodes()
143 return $this->accessCodes;