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)
45 $query = LogRightTable::query()
49 ->whereIn(
'GROUP_CODE', $this->getAccessCodes())
50 ->where(
'LOG_UPDATE',
'>', $this->getDateStartFrom())
55 foreach (
$query->fetchAll() as $row)
65 $res = LogRightTable::getList([
68 'GROUP_CODE' => $this->getAccessCodes(),
69 '>LOG_UPDATE' => $this->getDateStartFrom()
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);
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 $format =
'Y-m-d H:i:s';
129 $twoWeeks = date($format, strtotime(
'-14 days'));
131 return new Date($twoWeeks, $format);
134 private function getAccessCodes():
array
136 if (!empty($this->accessCodes))
138 return $this->accessCodes;
141 $this->accessCodes = array_merge(
142 $this->getUserAccessSocialGroups(),
143 $this->getUserAccessCodes()
146 return $this->accessCodes;