$ID = intval($ID); $filter_lesson_id = intval($filter_lesson_id); $lessonPath = ''; if (isset($_POST['LESSON_PATH'])) { $lessonPath = $_POST['LESSON_PATH']; } elseif (isset($_GET['LESSON_PATH'])) { $lessonPath = $_GET['LESSON_PATH']; } else { $result = CLQuestion::GetByID($ID); $arData = $result->Fetch(); $oPath = new CLearnPath($arData['LESSON_ID']); $lessonPath = $oPath->ExportUrlencoded(); } $oPath = new CLearnPath(); $oPath->ImportUrlencoded($lessonPath); $uriLessonPath = $oPath->ExportUrlencoded(); $NEW_LESSON_ID = false; $LESSON_ID = false; if ($ID == 0) { $LESSON_ID = $oPath->PopBottom(); } else { // Get lesson id from item data $result = CLQuestion::GetByID($ID); $arQuestionData = $result->ExtractFields("str_"); if ($arQuestionData) { $LESSON_ID = $arQuestionData['LESSON_ID']; if (isset($_POST['LESSON_ID']) && $_POST['LESSON_ID'] >= 1 && $_POST['LESSON_ID'] != $LESSON_ID) { $NEW_LESSON_ID = (int) $_POST['LESSON_ID']; } } }
//Set Title $arParams["SET_TITLE"] = $arParams["SET_TITLE"] == "N" ? "N" : "Y"; if ($arParams["SET_TITLE"] == "Y") { $APPLICATION->SetTitle($arResult["CHAPTER"]["NAME"]); } $bCanEdit = CLearnAccessMacroses::CanUserEditLesson(array('lesson_id' => $arParams['CHAPTER_ID'])) || $USER->IsAdmin(); if ($bCanEdit) { $deleteReturnUrl = ""; if ($parent = $this->GetParent()) { $parentLessonId = 0; $lessonPath = ""; if (strlen($arParams["LESSON_PATH"]) > 0) { $path = new CLearnPath(); $path->ImportUrlencoded($arParams["LESSON_PATH"]); $path->PopBottom(); $lessonPath = $path->ExportUrlencoded(); $lessonId = $path->PopBottom(); $edgesToParents = CLearnLesson::ListImmediateParents($arParams['CHAPTER_ID']); foreach ($edgesToParents as $arEdgeToParent) { if ((int) $arEdgeToParent['PARENT_LESSON'] === (int) $lessonId) { $parentLessonId = $lessonId; break; } } } if ($parentLessonId) { $deleteReturnUrl = CComponentEngine::MakePathFromTemplate($parent->arResult["FOLDER"] . $parent->arResult["URL_TEMPLATES"]["chapter.detail"], array("CHAPTER_ID" => "0" . $parentLessonId, "COURSE_ID" => $arParams["COURSE_ID"])); $deleteReturnUrl .= strpos($deleteReturnUrl, "?") !== false ? "&" : "?"; $deleteReturnUrl .= "LESSON_PATH=" . $lessonPath; } else { $deleteReturnUrl = CComponentEngine::MakePathFromTemplate($parent->arResult["FOLDER"] . $parent->arResult["URL_TEMPLATES"]["course.detail"], array("COURSE_ID" => $arParams["COURSE_ID"]));
ClearVars(); $lessonPath = ''; if (isset($_POST['LESSON_PATH'])) { $lessonPath = $_POST['LESSON_PATH']; } elseif (isset($_GET['LESSON_PATH'])) { $lessonPath = $_GET['LESSON_PATH']; } $oPath = new CLearnPath(); $oPath->ImportUrlencoded($lessonPath); $LESSON_ID = $oPath->GetBottom(); if ($LESSON_ID === false) { CAdminMessage::ShowMessage(GetMessage('LEARNING_BAD_LESSON')); require $_SERVER['DOCUMENT_ROOT'] . '/bitrix/modules/main/include/epilog_admin.php'; exit; } $uriLessonPath = $oPath->ExportUrlencoded(); unset($lessonPath); if (isset($from) && strlen($from) > 0) { $str_from = "&from=" . htmlspecialcharsbx($from); } else { $str_from = ""; } $oAccess = CLearnAccess::GetInstance($USER->GetID()); $bAccessLessonModify = $oAccess->IsLessonAccessible($LESSON_ID, CLearnAccess::OP_LESSON_WRITE); $lesson = CLearnLesson::GetList(array(), array('LESSON_ID' => $LESSON_ID)); $arLesson = $lesson->Fetch(); $oTree = CLearnLesson::GetTree($LESSON_ID, array('EDGE_SORT' => 'asc'), array(), false); $arSubLessons = $oTree->GetTreeAsList(); $arSubLessonsIDs = array(); foreach ($arSubLessons as $arSubLesson) { $arSubLessonsIDs[] = (int) $arSubLesson['LESSON_ID'];
if (isset($_POST['LESSON_PATH']) || isset($_GET['LESSON_PATH'])) { if (isset($_POST['LESSON_PATH'])) { $g_learn_currentLessonPath = $_POST['LESSON_PATH']; } else { $g_learn_currentLessonPath = $_GET['LESSON_PATH']; } $oPath = new CLearnPath(); $oPath->ImportUrlencoded($g_learn_currentLessonPath); $arPath = $oPath->GetPathAsArray(); if (count($arPath) >= 2) { // pop current lesson id array_pop($arPath); // remember parent path $oParentPath = new CLearnPath(); $oParentPath->SetPathFromArray($arPath); $g_learn_parentLessonPath = urldecode($oParentPath->ExportUrlencoded()); // pop parent lesson id $g_learn_parentLessonId = array_pop($arPath); // If lesson was edited and unlinked from parent $g_parentLessonId // we must cleanup LESSON_PATH. Also we must cleanup lesson path if // it is wrong due to other reasons. // $arEdgesToParents = CLearnLesson::ListImmediateParents($LESSON_ID); // // $isLinkToParentFound = true; // foreach ($arEdgesToParents as $arEdgeToParent) // { // if ( (int) $arEdgeToParent['PARENT_LESSON'] === (int) $g_learn_parentLessonId ) // $isLinkToParentFound = true; // } // // if ( ! $isLinkToParentFound )
/** * WARNING: tree build algorithm skips duplicated lessons, so * if there is some duplicates lessons, only one of them * will be in resulted tree. */ 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; }
public function BuildListContextMenu() { $aContext = array(); $parentLessonId = false; // Button "level up" available only if LESSON_PATH available and parent exists in it if (isset($_GET['LESSON_PATH']) && strlen($_GET['LESSON_PATH']) > 0) { $PROPOSE_RETURN_LESSON_PATH = '&PROPOSE_RETURN_LESSON_PATH=' . urlencode($_GET['LESSON_PATH']); $oPath = new CLearnPath(); $oPath->ImportUrlencoded($_GET['LESSON_PATH']); $arPath = $oPath->GetPathAsArray(); $arUpPath = $arPath; $count_arUpPath = count($arUpPath); if (isset($arUpPath[$count_arUpPath - 1])) { $parentLessonId = $arUpPath[$count_arUpPath - 1]; } // Is parent node exists if ($count_arUpPath >= 2) { // "Level up" array_pop($arUpPath); $oUpPath = new CLearnPath(); $oUpPath->SetPathFromArray($arUpPath); $aContext[] = array('ICON' => 'btn_up', 'TEXT' => GetMessage('LEARNING_A_UP'), 'LINK' => 'learn_unilesson_admin.php?lang=' . LANG . '&set_filter=Y' . '&PARENT_LESSON_ID=' . htmlspecialcharsbx($arUpPath[count($arUpPath) - 1]) . '&LESSON_PATH=' . $oUpPath->ExportUrlencoded() . '&' . $this->hrefSearchRetPoint, 'TITLE' => GetMessage('LEARNING_A_UP')); } else { // To all lessons list $aContext[] = array('ICON' => 'btn_up', 'TEXT' => GetMessage('LEARNING_ALL_LESSONS'), 'LINK' => 'learn_unilesson_admin.php?lang=' . LANG . '&set_filter=Y' . '&PARENT_LESSON_ID=-2' . '&' . $this->hrefSearchRetPoint, 'TITLE' => GetMessage('LEARNING_ALL_LESSONS')); } unset($arPath, $oPath, $arUpPath, $oUpPath); } else { $PROPOSE_RETURN_LESSON_PATH = ''; } if (!$this->IsSearchMode()) { /** * User can create lesson if he has base access for creating AND: * 1) no parent lesson * OR * 2) if user creating lesson linked to some parent on which user has access * to link childs, and user has access to link his created lesson to parent */ $isAccessCreate = false; try { if ($this->oAccess->IsBaseAccess(CLearnAccess::OP_LESSON_CREATE)) { if ($parentLessonId === false) { $isAccessCreate = true; } elseif ($this->oAccess->IsBaseAccess(CLearnAccess::OP_LESSON_LINK_DESCENDANTS | CLearnAccess::OP_LESSON_LINK_TO_PARENTS) || $this->oAccess->IsLessonAccessible($parentLessonId, CLearnAccess::OP_LESSON_LINK_DESCENDANTS) && $this->oAccess->IsBaseAccessForCR(CLearnAccess::OP_LESSON_LINK_TO_PARENTS)) { $isAccessCreate = true; } } } catch (Exception $e) { } if ($isAccessCreate) { // btn add new course $aContext[] = array('ICON' => 'btn_new', 'TEXT' => GetMessage('LEARNING_ADD_COURSE'), 'LINK' => 'learn_course_edit.php?lang=' . LANG . $PROPOSE_RETURN_LESSON_PATH, 'TITLE' => GetMessage('LEARNING_ADD_COURSE_ALT')); // btn add new unilesson (non-course) $aContext[] = array('ICON' => 'btn_new', 'TEXT' => GetMessage('LEARNING_UNILESSON_ADD'), 'LINK' => 'learn_unilesson_edit.php?lang=' . LANG . $PROPOSE_RETURN_LESSON_PATH, 'TITLE' => GetMessage('LEARNING_UNILESSON_ADD')); } } $this->oList->AddAdminContextMenu($aContext); return $this; }
function __learning_admin_get_menu($THIS, $arPath = array(), $deep = 0, &$immediateChildsIds, $loadOnlySpecialEntities = false) { $immediateChildsIds = array(); // puts here ids of all immediate childs $deep = (int) $deep; // Index in path for current parentLessonId $indexInPath = $deep - 1; // Path doesn't include top root element ('all courses' or 'all unilessons') $arMenu = array(); //$urlPath = $oPath->ExportUrlencoded(); // current lesson id (not exists only for top root) if (isset($arPath[$deep])) { $currentLessonIdInPath = (int) $arPath[$deep]; } else { $currentLessonIdInPath = false; } // Path to current element $arCurrentDeepPath = array(); foreach ($arPath as $key => $value) { if ($key === $deep) { break; } $arCurrentDeepPath[] = $value; } if ($deep === 0) { // We are at the top level, so we must get list of all courses $CDBResult = CCourse::GetList(array('COURSE_SORT' => 'ASC')); } else { // If not parent with such indexInPath => we are deep too much. if (!isset($arPath[$indexInPath])) { return $arMenu; } // no items $parentLessonId = $arPath[$indexInPath]; $oCurrentDeepPath = new CLearnPath(); $oCurrentDeepPath->SetPathFromArray(array_merge($arCurrentDeepPath)); $urlPath = $oCurrentDeepPath->ExportUrlencoded(); $arMenu[] = array("text" => GetMessage("LEARNING_QUESTION"), "url" => "learn_question_admin.php?lang=" . LANG . '&PARENT_LESSON_ID=' . ($parentLessonId + 0) . '&LESSON_PATH=' . $urlPath . "&from=learn_menu", "icon" => "learning_icon_question", "more_url" => array("learn_question_admin.php?lang=" . LANG . '&PARENT_LESSON_ID=' . ($parentLessonId + 0) . '&LESSON_PATH=' . $urlPath . "&from=learn_menu", "learn_question_edit.php?lang=" . LANG . '&LESSON_PATH=' . $urlPath . "&from=learn_menu", "learn_question_admin.php?lang=" . LANG . '&PARENT_LESSON_ID=' . ($parentLessonId + 0) . '&LESSON_PATH=' . $urlPath, "learn_question_edit.php?lang=" . LANG . '&LESSON_PATH=' . $urlPath, "learn_question_admin.php?lang=" . LANG . '&LESSON_PATH=' . $urlPath), "title" => GetMessage("LEARNING_QUESTION_LIST")); $CDBResult = CLearnLesson::GetListOfImmediateChilds($parentLessonId, array('EDGE_SORT' => 'ASC')); // determine, is parent a course (only for courses in subroot level)? if ($deep === 1) { $immediateParentCourse = CLearnLesson::GetLinkedCourse($parentLessonId); if ($immediateParentCourse !== false) { // immediate parent is a course, so we must add entity 'Tests' $arMenu[] = array('text' => GetMessage('LEARNING_TESTS'), 'url' => 'learn_test_admin.php?lang=' . LANG . '&filter=Y&set_filter=Y' . '&COURSE_ID=' . ($immediateParentCourse + 0) . '&PARENT_LESSON_ID=' . ($parentLessonId + 0) . '&LESSON_PATH=' . $urlPath, 'icon' => 'learning_icon_tests', 'more_url' => array('learn_test_admin.php?lang=' . LANG . '&set_filter=Y' . '&COURSE_ID=' . ($immediateParentCourse + 0) . '&PARENT_LESSON_ID=' . ($parentLessonId + 0) . '&LESSON_PATH=' . $urlPath, 'learn_test_edit.php?lang=' . LANG . '&filter=Y&set_filter=Y' . '&COURSE_ID=' . ($immediateParentCourse + 0) . '&PARENT_LESSON_ID=' . ($parentLessonId + 0) . '&LESSON_PATH=' . $urlPath), 'title' => GetMessage('LEARNING_TESTS_LIST')); unset($urlPath); unset($oCurrentDeepPath); } } } if ($loadOnlySpecialEntities) { return $arMenu; } // When listing courses, limit it's count if ($deep === 0) { $items = 0; $learning_menu_max_courses = (int) COption::GetOptionString("learning", "menu_max_courses", "10"); } while ($arData = $CDBResult->GetNext()) { // When listing courses, limit it's count if ($deep === 0) { if ($items >= $learning_menu_max_courses) { // add element 'other courses' $arMenu[] = array('text' => GetMessage('LEARNING_MENU_COURSES_OTHER'), 'url' => 'learn_unilesson_admin.php?lang=' . LANG . '&PARENT_LESSON_ID=-1', 'title' => GetMessage('LEARNING_MENU_COURSES_ALT'), 'more_url' => array('learn_test_admin.php', 'learn_test_edit.php', 'learn_unilesson_admin.php', 'learn_unilesson_edit.php', 'learn_question_admin.php', 'learn_question_edit.php')); // stop adding courses to menu break; } $items++; } $arSubImmediateChildsIds = false; $arCurItemPath = $arCurrentDeepPath; $arCurItemPath[] = $arData['LESSON_ID'] + 0; // Remember all immediate childs $immediateChildsIds[] = $arData['LESSON_ID'] + 0; $oCurItemPath = new CLearnPath(); $oCurItemPath->SetPathFromArray($arCurItemPath); $urlCurItemPath = $oCurItemPath->ExportUrlencoded(); $arItem = array('text' => $arData['NAME'], 'url' => 'learn_unilesson_admin.php?lang=' . LANG . '&PARENT_LESSON_ID=' . ($arData['LESSON_ID'] + 0) . '&LESSON_PATH=' . $oCurItemPath->ExportUrlencoded(), 'title' => $arData['NAME'], 'items_id' => 'menu_learning_courses_new_' . implode('_', $arCurItemPath), "icon" => "learning_icon_courses", 'module_id' => 'learning', 'more_url' => array('learn_unilesson_admin.php?lang=' . LANG . '&set_filter=Y' . '&PARENT_LESSON_ID=' . ($arData['LESSON_ID'] + 0) . '&LESSON_PATH=' . $urlCurItemPath, 'learn_unilesson_admin.php?lang=' . LANG . '&PARENT_LESSON_ID=' . ($arData['LESSON_ID'] + 0) . '&LESSON_PATH=' . $urlCurItemPath, 'learn_unilesson_admin.php?lang=' . LANG . '&set_filter=Y' . '&LESSON_PATH=' . $urlCurItemPath, 'learn_question_admin.php?lang=' . LANG . '&filter=Y&set_filter=Y' . '&LESSON_PATH=' . $urlCurItemPath, 'learn_question_edit.php?lang=' . LANG . '&set_filter=Y' . '&LESSON_PATH=' . $urlCurItemPath, 'learn_unilesson_edit.php?lang=' . LANG . '&LESSON_ID=' . ($arData['LESSON_ID'] + 0) . '&LESSON_PATH=' . $urlCurItemPath, 'learn_unilesson_edit.php?lang=' . LANG . '&PARENT_LESSON_ID=' . ($arData['LESSON_ID'] + 0) . '&LESSON_PATH=' . $urlCurItemPath)); $arItem['items'] = array(); if ($deep === 0 && isset($arData['LINKED_LESSON_ID']) && $arData['LINKED_LESSON_ID'] > 0) { $arItem['page_icon'] = $arItem['icon'] = 'learning_icon_courses'; $arItem['dynamic'] = true; $loadOnlySpecialEntities = false; // Load child items only for lesson in current path if ($arData['LESSON_ID'] == $currentLessonIdInPath) { $arItem['items'] = __learning_admin_get_menu($THIS, $arPath, $deep + 1, $arSubImmediateChildsIds); } } else { $loadOnlySpecialEntities = false; $childsCnt = CLearnLesson::CountImmediateChilds($arData['LESSON_ID']); $questionsCnt = CLQuestion::GetCount(array('LESSON_ID' => (int) $arData['LESSON_ID'])); if ($childsCnt > 0) { $arItem['page_icon'] = $arItem['icon'] = 'learning_icon_chapters'; } else { $arItem['page_icon'] = $arItem['icon'] = 'learning_icon_lessons'; } $arItem['dynamic'] = true; // Load child items only for lesson in current path if ($arData['LESSON_ID'] == $currentLessonIdInPath) { $arItem['items'] = __learning_admin_get_menu($THIS, $arPath, $deep + 1, $arSubImmediateChildsIds); } } // now, adds items into more_url (it needs when edit form for childs opened) if (is_array($arSubImmediateChildsIds)) { $oSubItemPath = new CLearnPath(); foreach ($arSubImmediateChildsIds as $k => $v) { // determine path for every child $arSubItemPath = $arCurItemPath; $arSubItemPath[] = $v; // child id added to current path $oSubItemPath->SetPathFromArray($arSubItemPath); $arItem['more_url'][] = 'learn_unilesson_edit.php?lang=' . LANG . '&filter=Y&set_filter=Y' . '&LESSON_ID=' . ($v + 0) . '&LESSON_PATH=' . $oSubItemPath->ExportUrlencoded(); } unset($oSubItemPath); $arSubImmediateChildsIds = false; } $arMenu[] = $arItem; unset($oCurItemPath, $arCurItemPath, $urlCurItemPath, $arItem); } return $arMenu; }