• Модуль: learning
  • Путь к файлу: ~/bitrix/modules/learning/classes/general/clearnaccess.php
  • Класс: CLearnAccess
  • Вызов: CLearnAccess::GetAccessCodes
protected function GetAccessCodes ($isUseCache = false)
{
	global $USER;
	static $cache = array();
	$isNeedCAccessUpdate = true;

	if ($isUseCache)
	{
		// Cache hits?
		if (isset($cache['str' . $this->userId]))
			return ($cache['str' . $this->userId]);

		// Prevent call CAccess->UpdateCodes() multiple times per hit,
		// except long time period (three seconds) expired.
		if ( ($this->CAccessLastUpdated === false) 
			|| ( (microtime(true) - $this->CAccessLastUpdated) > 3 )
		)
		{
			$isNeedCAccessUpdate = true;
		}
		else
			$isNeedCAccessUpdate = false;
	}
	else
		$isNeedCAccessUpdate = true;

	if ($isNeedCAccessUpdate)
	{
		$oAcc = new CAccess();
		$oAcc->UpdateCodes();

		if ($isUseCache)
			$this->CAccessLastUpdated = microtime(true);

		unset ($oAcc);
	}

	$rc = CAccess::GetUserCodes($this->userId);
	if ($rc === false)
	{
		throw new LearnException('', 
			LearnException::EXC_ERR_ALL_GIVEUP 
			| LearnException::EXC_ERR_ALL_ACCESS_DENIED);
	}

	$arData = array();
	while ($arItem = $rc->Fetch())
	{
		if ( ( (int) $arItem['USER_ID'] ) !== $this->userId )
		{
			throw new LearnException('', 
				LearnException::EXC_ERR_ALL_GIVEUP 
				| LearnException::EXC_ERR_ALL_LOGIC
				| LearnException::EXC_ERR_ALL_ACCESS_DENIED);
		}

		$arData[] = $arItem['ACCESS_CODE'];
	}

	if ( is_object($USER) && ( $this->userId === ((int) $USER->GetID()) ) )
		$arData[] = 'AU';

	// Cache in case when $isUseCache === false too. 
	// Because, this will refresh cache, if it exists before.
	$cache['str' . $this->userId] = $arData;

	return ($arData);
}