• Модуль: learning
  • Путь к файлу: ~/bitrix/modules/learning/classes/general/clearnlesson.php
  • Класс: CLearnLesson
  • Вызов: CLearnLesson::GetListOfParentPathesRecursive
static function GetListOfParentPathesRecursive ($arPathes, &$arAlreadyProcessedLessons, $arIgnoreEdges = array())
{
	$arPathesNew = $arPathes;
	$must_be_stopped = 0x1;	// stop if no more parents available or finally cycled

	foreach ($arPathes as $key => $arPath)
	{
		$lessonId = $arPath[count($arPath) - 1];
		$arEdges = self::ListImmediateParents($lessonId);
		$arParents = array();
		foreach ($arEdges as $arEdge)
		{
			$parentLessonId = (int) $arEdge['PARENT_LESSON'];
			if ( ! in_array($parentLessonId, $arAlreadyProcessedLessons, true) )
			{
				$isEdgeIgnored = false;
				foreach ($arIgnoreEdges as $arIgnoreEdge)
				{
					if (
						($arIgnoreEdge['PARENT_LESSON'] == $arEdge['PARENT_LESSON'])
						&& ($arIgnoreEdge['CHILD_LESSON'] == $arEdge['CHILD_LESSON'])
					)
					{
						$isEdgeIgnored = true;
						break;
					}
				}

				if ( ! $isEdgeIgnored )
				{
					$arParents[] = $parentLessonId;

					// Precache already processed lesson (for prevent cycling)
					$arAlreadyProcessedLessons[] = $parentLessonId;
				}
			}
		}

		$must_be_stopped &= (int) (count($arParents) === 0);	// true evaluted to 1

		$i = 0;
		foreach ($arParents as $parentLessonId)
		{
			$parentLessonId = (int) $parentLessonId;
			if ( $i || $i++ )	// executed only for all except first lesson in $arParents
			{
				$arPathTmp     = $arPath;
				$arPathTmp[]   = $parentLessonId;
				$arPathesNew[] = $arPathTmp;
			}
			else
			{
				$arPathesNew[$key][] = $parentLessonId;
			}
		}
	}

	if ($must_be_stopped)
		return ($arPathesNew);

	return (self::GetListOfParentPathesRecursive($arPathesNew, $arAlreadyProcessedLessons, $arIgnoreEdges));
}