13 private const DEFAULT_LIMIT = 4999;
14 private static array $instance = [];
17 public static function isReady($userId): bool
19 return array_key_exists($userId, self::$instance);
24 $limit = \COption::GetOptionString(
'socialnetwork',
'sonetCounterLimit',
'');
27 return self::DEFAULT_LIMIT;
34 if (!array_key_exists($userId, self::$instance))
36 self::$instance[$userId] =
new self($userId);
40 return self::$instance[$userId];
43 private function __construct($userId)
45 $this->userId = (int)$userId;
47 $state = $this->getState();
51 && !$state->isCounted()
57 Service::getInstance();
64 return $this->getState()->isCounted();
69 return $this->getState()->getRawCounters($meta);
72 public function getCounters(
int $groupId = 0, array $params = []): array
74 $skipAccessCheck = (isset($params[
'SKIP_ACCESS_CHECK']) && $params[
'SKIP_ACCESS_CHECK']);
76 if (!$skipAccessCheck && !$this->isAccessToCounters())
97 public function get($name,
int $groupId = 0)
106 $value = $this->getState()->getValue($name, $groupId);
113 private function dropOldCounters(): void
115 $state = $this->getState();
117 if (!$state->isCounted())
122 if (
Counter\Queue\Queue::isInQueue($this->userId))
127 if ($state->getClearedDate() >= (
int) date(
'ymd'))
133 \
Bitrix\Socialnetwork\Internals\EventService\EventDictionary::EVENT_GARBAGE_COLLECT,
135 'USER_ID' => $this->userId,
140 private function isAccessToCounters(): bool
142 return $this->userId === \Bitrix\Socialnetwork\Helper\User::getCurrentUserId();
148 private function getState(): CounterState