• Модуль: socialnetwork
  • Путь к файлу: ~/bitrix/modules/socialnetwork/lib/component/loglistcommon/processor.php
  • Класс: BitrixSocialnetworkComponentLogListCommonProcessor
  • Вызов: Processor::getUnreadCommentsIdList
static function getUnreadCommentsIdList($params): array
{
	$result = [];

	$userId = (int)($params['userId'] ?? 0);
	$logIdList = (is_set($params['logIdList']) && is_array($params['logIdList']) ? $params['logIdList'] : []);

	if (
		$userId <= 0
		|| empty($logIdList)
	)
	{
		return $result;
	}

	foreach($logIdList as $logId)
	{
		$result[(int)$logId] = [];
	}

	$query = UserCounterTable::query();
	$query->addFilter('=USER_ID', $userId);
	$query->addFilter('=SITE_ID', SITE_ID);

	$subQuery = LogCommentTable::query();
	$subQuery->whereIn('LOG_ID', $logIdList);
	$subQuery->addSelect(new BitrixMainEntityExpressionField('COMMENT_CODE', "CONCAT('**LC', %s)", [ 'ID' ]));

	$query->addFilter('@CODE', new SqlExpression($subQuery->getQuery()));
	$query->addSelect('CODE');
	$res = $query->exec();

	$unreadCommentIdList = [];

	while ($counterFields = $res->fetch())
	{
		if (preg_match('/**LC(d+)/i', $counterFields['CODE'], $matches))
		{
			$unreadCommentIdList[] = (int)$matches[1];
		}
	}

	if (!empty($unreadCommentIdList))
	{
		$res = LogCommentTable::getList([
			'filter' => [
				'@ID' => $unreadCommentIdList,
			],
			'select' => [ 'ID', 'LOG_ID' ],
		]);
		while ($logCommentFields = $res->fetch())
		{
			$result[(int)$logCommentFields['LOG_ID']][] = (int)$logCommentFields['ID'];
		}
	}

	return $result;
}