• Модуль: socialnetwork
  • Путь к файлу: ~/bitrix/modules/socialnetwork/classes/general/rest.php
  • Класс: CSocNetLogRestService
  • Вызов: CSocNetLogRestService::getUserLogComment
static function getUserLogComment($arParams, $offset, CRestServer $server): array
{
	$arParams = array_change_key_case($arParams, CASE_UPPER);

	$result = [
		'COMMENTS' => [],
		'FILES' => [],
	];

	$userId = (int)(
		isset($arParams["USER_ID"])
		&& (int)$arParams["USER_ID"] > 0
		&& self::isAdmin()
			? $arParams["USER_ID"]
			: self::getCurrentUserId()
	);

	$otherUserMode = ($userId !== self::getCurrentUserId());

	if ($userId <= 0)
	{
		throw new BitrixRestRestException("User ID can't be empty", "ID_EMPTY", CRestServer::STATUS_WRONG_REQUEST);
	}

	if (isset($arParams['FIRST_ID']))
	{
		$options['FIRST_ID'] = (int)$arParams['FIRST_ID'];
	}
	else
	{
		$options['LAST_ID'] = (
			isset($arParams['LAST_ID'])
			&& (int)$arParams['LAST_ID'] > 0
				? (int)$arParams['LAST_ID']
				: 0
		);
	}

	$options['LIMIT'] = (
		isset($arParams['LIMIT'])
			? (
				(int)$arParams['LIMIT'] > 1000
					? 1000
					: (int)$arParams['LIMIT'])
			: 100
	);

	$filter = array(
		'=USER_ID' => $userId,
		'@EVENT_ID' => self::getLogCommentEventId()
	);

	if (isset($options['FIRST_ID']))
	{
		$order = array();

		if ((int)$options['FIRST_ID'] > 0)
		{
			$filter['>ID'] = $options['FIRST_ID'];
		}
	}
	else
	{
		$order = [ 'ID' => 'DESC' ];

		if (isset($options['LAST_ID']) && (int)$options['LAST_ID'] > 0)
		{
			$filter[' $filter,
		'select' => array(
			'ID', 'LOG_ID', 'LOG_DATE', 'MESSAGE', 'UF_SONET_COM_DOC'
		),
		'order' => $order,
		'limit' => $options['LIMIT']
	));

	$attachedIdList = array();

	while ($commentFields = $res->fetch())
	{
		$result['COMMENTS'][$commentFields['ID']] = array(
			'ID' => (int)$commentFields['ID'],
			'COMMENT_ID' => (int)$commentFields['ID'],
			'LOG_ID' => (int)$commentFields['LOG_ID'],
			'DATE' => $commentFields['LOG_DATE'],
			'TEXT' => ($otherUserMode ? '' : (string)$commentFields['MESSAGE']),
			'ATTACH' => array()
		);

		if (!empty($commentFields['UF_SONET_COM_DOC']))
		{
			if (is_array($commentFields['UF_SONET_COM_DOC']))
			{
				$attached = $commentFields['UF_SONET_COM_DOC'];
			}
			elseif ((int)$commentFields['UF_SONET_COM_DOC'] > 0)
			{
				$attached = array((int)$commentFields['UF_SONET_COM_DOC']);
			}
			else
			{
				$attached = array();
			}

			if (!empty($attached))
			{
				$attachedIdList = array_merge($attachedIdList, $attached);
			}

			$commentAttachedList[$commentFields['ID']] = $attached;
		}
	}

	$attachedObjectList = array();

	if (
		!empty($attachedIdList)
		&& Loader::includeModule('disk')
	)
	{
		$res = BitrixDiskAttachedObject::getList(array(
			'filter' => array(
				'@ID' => array_unique($attachedIdList)
			),
			'select' => array('ID', 'OBJECT_ID')
		));
		while ($attachedObjectFields = $res->fetch())
		{
			$diskObjectId = $attachedObjectFields['OBJECT_ID'];

			if ($fileData = self::getFileData($diskObjectId))
			{
				$attachedObjectList[$attachedObjectFields['ID']] = $diskObjectId;
				$result['FILES'][$diskObjectId] = $fileData;
			}
		}
	}

	foreach ($result['COMMENTS'] as $key => $value)
	{
		if ($value['DATE'] instanceof BitrixMainTypeDateTime)
		{
			$result['COMMENTS'][$key]['DATE'] = date('c', $value['DATE']->getTimestamp());
		}

		if (!empty($commentAttachedList[$key]))
		{
			foreach ($commentAttachedList[$key] as $attachedId)
			{
				if (!empty($attachedObjectList[$attachedId]))
				{
					$result['COMMENTS'][$key]['ATTACH'][] = $attachedObjectList[$attachedId];
				}
			}
		}

		$result['COMMENTS'][$key] = array_change_key_case($result['COMMENTS'][$key], CASE_LOWER);
	}

	$result['COMMENTS'] = array_values($result['COMMENTS']);
	$result['FILES'] = self::convertFileData($result['FILES']);

	return $result;
}