- Модуль: learning
- Путь к файлу: ~/bitrix/modules/learning/classes/general/clearnlessontree.php
- Класс: CLearnLessonTree
- Вызов: CLearnLessonTree::BuildTreeRecursive
protected function BuildTreeRecursive ($rootLessonId, $arOrder, $arFilter, $depth = 0, $parentChapterId = NULL, $arSelectFields, $arRootPath)
{
$oPath = new CLearnPath();
$arLessons = array();
$CDBResult = CLearnLesson::GetListOfImmediateChilds($rootLessonId, $arOrder, $arFilter, $arSelectFields);
while (($arData = $CDBResult->Fetch()) !== false)
{
// Skip lessons that are already in tree (prevent cycling)
if ( in_array($arData['LESSON_ID'], $this->arLessonsInTree) )
continue;
// Skip lessons prohibited for publishing
if (in_array( (int) $arData['LESSON_ID'], $this->arPublishProhibitedLessons, true))
continue;
// Path as array for current LESSON_ID
$arCurrentLessonPath = $arRootPath;
$arCurrentLessonPath[] = (int) $arData['LESSON_ID'];
$oPath->SetPathFromArray($arCurrentLessonPath);
$strUrlencodedCurrentLessonPath = $oPath->ExportUrlencoded();
// Register lesson
$this->arLessonsInTree[] = $arData['LESSON_ID'];
$this->arLessonsAsList[] = array_merge(
$arData,
array(
'#DEPTH_IN_TREE' => $depth,
'#LESSON_PATH' => $strUrlencodedCurrentLessonPath
)
);
// hack: we don't know yet, what index name must be for element in array.
// And we must preserve order in array elements (for compatibility).
// But we will know index name after BuildTreeRecursive will be called, which
// adds to array new elements. So create bother elements, and after remove unneeded.
$this->arLessonsAsListOldMode['LE' . $arData['LESSON_ID']] = array();
$this->arLessonsAsListOldMode['CH' . $arData['LESSON_ID']] = array();
$item = $arData;
$item['#childs'] = array();
$lessonType_oldDataModel = 'LE';
if ($arData['IS_CHILDS'])
{
$lessonType_oldDataModel = 'CH';
$item['#childs'] = $this->BuildTreeRecursive (
$arData['LESSON_ID'],
$arOrder,
$arFilter,
$depth + 1,
$arData['LESSON_ID'],
$arSelectFields,
$arCurrentLessonPath
);
// It still can be zero childs due to $arFilter, publish prohibition or prevent cycling instead of non-zero $arData['IS_CHILDS']
if (count($item['#childs']) == 0)
$lessonType_oldDataModel = 'LE';
}
// remove unneeded element caused by hack above
if ($lessonType_oldDataModel === 'LE')
unset($this->arLessonsAsListOldMode['CH' . $arData['LESSON_ID']]);
else
unset($this->arLessonsAsListOldMode['LE' . $arData['LESSON_ID']]);
$this->arLessonsAsListOldMode[$lessonType_oldDataModel . $arData['LESSON_ID']] = array_merge(
$arData,
array(
'ID' => $arData['LESSON_ID'],
'CHAPTER_ID' => $parentChapterId,
'SORT' => $arData['EDGE_SORT'],
'TYPE' => $lessonType_oldDataModel,
'DEPTH_LEVEL' => $depth + 1,
'#LESSON_PATH' => $strUrlencodedCurrentLessonPath
)
);
$arLessons[] = $item;
}
return ($arLessons);
}