• Модуль: learning
  • Путь к файлу: ~/bitrix/modules/learning/classes/general/clearnaccessmacroses.php
  • Класс: CLearnAccessMacroses
  • Вызов: CLearnAccessMacroses::getActiveLearningChaptersPeriod
static function getActiveLearningChaptersPeriod($courseLessonId, $userId)
{
	$arGroupsPeriods = self::getActiveLearningGroupsPeriod($courseLessonId, $userId);
	if (!$arGroupsPeriods['IS_EXISTS'])
	{
		return false;
	}

	$arChaptersActiveFrom = array();
	$arGroupsActiveFrom = $arGroupsPeriods['GROUPS_ACTIVE_FROM'];

	$arLessons = array();
	$rs = CLearnLesson::GetListOfImmediateChilds(
		$courseLessonId,
		array(),
		array('CHECK_PERMISSIONS' => 'N'),
		array('LESSON_ID')
	);

	$arMinChaptersActiveFromTimestamp = array();
	while ($ar = $rs->fetch())
	{
		$arLessons[$ar['LESSON_ID']] = $ar['NAME'];
		$arChaptersActiveFrom[$ar['LESSON_ID']] = null;
		$arMinChaptersActiveFromTimestamp[$ar['LESSON_ID']] = PHP_INT_MAX;
	}

	// Get the nearest dates, when lesson can be opened
	foreach ($arGroupsActiveFrom as $groupId => $groupActiveFrom)
	{
		if ($groupActiveFrom === null)
		{
			continue;
		}

		$arDelays = CLearningGroupLesson::getDelays($groupId, array_keys($arLessons));
		$groupActiveFromTs = MakeTimeStamp($groupActiveFrom);

		foreach ($arDelays as $lessonId => $delay)
		{
			$fromTs = $groupActiveFromTs + 86400 * $delay;	// 24h is 86400 seconds

			// search for nearest dates
			if ($fromTs < $arMinChaptersActiveFromTimestamp[$lessonId])
			{
				$arChaptersActiveFrom[$lessonId] = ConvertTimeStamp($fromTs, 'FULL');
				$arMinChaptersActiveFromTimestamp[$lessonId] = $fromTs;
			}
		}
	}

	return ($arChaptersActiveFrom);
}