• Модуль: socialnetwork
  • Путь к файлу: ~/bitrix/modules/socialnetwork/lib/livefeed/intranetnewuser.php
  • Класс: BitrixSocialnetworkLivefeedIntranetNewUser
  • Вызов: IntranetNewUser::initSourceFields
public function initSourceFields()
{
	static $cache = [];

	$ratingEntityId = $this->getEntityId();

	if ($ratingEntityId <= 0)
	{
		return;
	}

	$sourceFields = [];

	if (isset($cache[$ratingEntityId]))
	{
		$sourceFields = $cache[$ratingEntityId];
	}
	else
	{
		$userId = 0;
		$bitrix24NewUserProvider = new Bitrix24NewUser();

		$res = LogTable::getList([
			'filter' => [
				'@EVENT_ID' => array_merge($this->getEventId(), $bitrix24NewUserProvider->getEventId() ),
				'=RATING_ENTITY_ID' => $ratingEntityId
			],
			'select' => [ 'ID', 'ENTITY_ID' ]
		]);
		if ($logEntry = $res->fetch())
		{
			$userId = $logEntry['ENTITY_ID'];
		}

		if ($userId > 0)
		{
			$res = UserTable::getList(array(
				'filter' => [
					'=ID' => $userId
				],
				'select' => [
					'NAME', 'LAST_NAME', 'SECOND_NAME', 'LOGIN', 'UF_DEPARTMENT'
				]
			));
			if ($user = $res->fetch())
			{
				$userName = CUser::formatName(
					CSite::getNameFormat(),
					$user,
					true,
					false
				);
				$user['FULL_NAME'] = $userName;

				$user['DEPARTMENT_NAME'] = '';
				if (
					is_array($user['UF_DEPARTMENT'])
					&& !empty($user['UF_DEPARTMENT'])
					&& Loader::includeModule('iblock')
				)
				{
					$res = SectionTable::getList([
						'filter' => [
							'ID' => $user['UF_DEPARTMENT']
						],
						'select' => [ 'ID', 'NAME' ]
					]);
					if ($sectionFields = $res->fetch())
					{
						$user['DEPARTMENT_NAME'] = $sectionFields['NAME'];
					}
				}

				$sourceFields = array_merge($user, [ 'LOG_ENTRY' => $logEntry ]);
				$cache[$ratingEntityId] = $sourceFields;
			}
		}
	}

	if (empty($sourceFields))
	{
		return;
	}

	$this->setLogId($sourceFields['LOG_ENTRY']['ID']);
	$this->setSourceFields($sourceFields);
	$this->setSourceTitle(Loc::getMessage('SONET_LIVEFEED_INTRANET_NEW_USER_TITLE', [
		'#USER_NAME#' => $sourceFields['FULL_NAME']
	]));
}