public static function ProccessPOST($oAccess, $LESSON_ID, $sort = false) { $isAccessUseCache = true; if ($sort === false) { $sort = 500; } // Remove/add relations from/to parent if ($oAccess->IsBaseAccess(CLearnAccess::OP_LESSON_LINK_TO_PARENTS, $isAccessUseCache) || $oAccess->IsLessonAccessible($LESSON_ID, CLearnAccess::OP_LESSON_LINK_TO_PARENTS, $isAccessUseCache) || $oAccess->IsBaseAccess(CLearnAccess::OP_LESSON_UNLINK_FROM_PARENTS, $isAccessUseCache) || $oAccess->IsLessonAccessible($LESSON_ID, CLearnAccess::OP_LESSON_UNLINK_FROM_PARENTS, $isAccessUseCache)) { $arCurParentsIds = array(); $resParents = CLearnLesson::GetListOfImmediateParents($LESSON_ID); while ($arParent = $resParents->Fetch()) { $arCurParentsIds[] = (int) $arParent['LESSON_ID']; } $arDestParentsIds = array(); if (isset($_POST['RELATION_PARENT']) && is_array($_POST['RELATION_PARENT'])) { foreach ($_POST['RELATION_PARENT'] as $key => $relatedLessonId) { $arDestParentsIds[] = (int) $relatedLessonId; } } // remove relations if ($oAccess->IsBaseAccess(CLearnAccess::OP_LESSON_UNLINK_FROM_PARENTS, $isAccessUseCache) || $oAccess->IsLessonAccessible($LESSON_ID, CLearnAccess::OP_LESSON_UNLINK_FROM_PARENTS, $isAccessUseCache)) { $arRemoveIds = array_diff($arCurParentsIds, $arDestParentsIds); foreach ($arRemoveIds as $relatedLessonId) { if ($oAccess->IsBaseAccess(CLearnAccess::OP_LESSON_UNLINK_DESCENDANTS, $isAccessUseCache) || $oAccess->IsLessonAccessible($relatedLessonId, CLearnAccess::OP_LESSON_UNLINK_DESCENDANTS, $isAccessUseCache)) { CLearnLesson::RelationRemove($relatedLessonId, $LESSON_ID); } } } // add relations if ($oAccess->IsBaseAccess(CLearnAccess::OP_LESSON_LINK_TO_PARENTS, $isAccessUseCache) || $oAccess->IsLessonAccessible($LESSON_ID, CLearnAccess::OP_LESSON_LINK_TO_PARENTS, $isAccessUseCache)) { $arAddIds = array_diff($arDestParentsIds, $arCurParentsIds); foreach ($arAddIds as $relatedLessonId) { if ($oAccess->IsBaseAccess(CLearnAccess::OP_LESSON_LINK_DESCENDANTS, $isAccessUseCache) || $oAccess->IsLessonAccessible($relatedLessonId, CLearnAccess::OP_LESSON_LINK_DESCENDANTS, $isAccessUseCache)) { CLearnLesson::RelationAdd($relatedLessonId, $LESSON_ID, array('SORT' => $sort)); } } } } // Remove/add relations from/to childs if ($oAccess->IsBaseAccess(CLearnAccess::OP_LESSON_LINK_DESCENDANTS, $isAccessUseCache) || $oAccess->IsLessonAccessible($LESSON_ID, CLearnAccess::OP_LESSON_LINK_DESCENDANTS, $isAccessUseCache) || $oAccess->IsBaseAccess(CLearnAccess::OP_LESSON_UNLINK_DESCENDANTS, $isAccessUseCache) || $oAccess->IsLessonAccessible($LESSON_ID, CLearnAccess::OP_LESSON_UNLINK_DESCENDANTS, $isAccessUseCache)) { $arCurChildsIds = array(); $resChilds = CLearnLesson::GetListOfImmediateChilds($LESSON_ID); while ($arChild = $resChilds->Fetch()) { $arCurChildsIds[] = (int) $arChild['LESSON_ID']; } $arDestChildsIds = array(); if (isset($_POST['RELATION_CHILD']) && is_array($_POST['RELATION_CHILD'])) { foreach ($_POST['RELATION_CHILD'] as $key => $relatedLessonId) { $arDestChildsIds[] = (int) $relatedLessonId; } } // remove relations if ($oAccess->IsBaseAccess(CLearnAccess::OP_LESSON_UNLINK_DESCENDANTS, $isAccessUseCache) || $oAccess->IsLessonAccessible($LESSON_ID, CLearnAccess::OP_LESSON_UNLINK_DESCENDANTS, $isAccessUseCache)) { $arRemoveIds = array_diff($arCurChildsIds, $arDestChildsIds); foreach ($arRemoveIds as $relatedLessonId) { if ($oAccess->IsBaseAccess(CLearnAccess::OP_LESSON_UNLINK_FROM_PARENTS, $isAccessUseCache) || $oAccess->IsLessonAccessible($relatedLessonId, CLearnAccess::OP_LESSON_UNLINK_FROM_PARENTS, $isAccessUseCache)) { CLearnLesson::RelationRemove($LESSON_ID, $relatedLessonId); } } } // add relations if ($oAccess->IsBaseAccess(CLearnAccess::OP_LESSON_LINK_DESCENDANTS, $isAccessUseCache) || $oAccess->IsLessonAccessible($LESSON_ID, CLearnAccess::OP_LESSON_LINK_DESCENDANTS, $isAccessUseCache)) { $arAddIds = array_diff($arDestChildsIds, $arCurChildsIds); foreach ($arAddIds as $relatedLessonId) { if ($oAccess->IsBaseAccess(CLearnAccess::OP_LESSON_LINK_TO_PARENTS, $isAccessUseCache) || $oAccess->IsLessonAccessible($relatedLessonId, CLearnAccess::OP_LESSON_LINK_TO_PARENTS, $isAccessUseCache)) { CLearnLesson::RelationAdd($LESSON_ID, $relatedLessonId, array('SORT' => $sort)); } } } } }
} else { $bBadCourse = true; } //Defaults $str_ACTIVE = "Y"; $str_DETAIL_TEXT_TYPE = $str_PREVIEW_TEXT_TYPE = "text"; $str_EDGE_SORT = '500'; $str_PUBLISH_PROHIBITED = 'N'; // Are we in context of parent lesson? $result = false; if (isset($g_learn_parentLessonId)) { $str_PARENT_LESSON_ID = $g_learn_parentLessonId; if ($LESSON_ID > 0) { // Get lesson data as immediate child of parent lesson. // It needs for getting edges data (SORT). $result = CLearnLesson::GetListOfImmediateChilds($str_PARENT_LESSON_ID, array(), array('LESSON_ID' => $LESSON_ID)); // get data for current lesson only } } else { if (isset($str_PARENT_LESSON_ID)) { unset($str_PARENT_LESSON_ID); } if ($LESSON_ID > 0) { $result = CLearnLesson::GetByID($LESSON_ID); } } // Now $str_PARENT_LESSON_ID exists only if in GET and/or POST request was PARENT_LESSON_ID if ($topCourseLessonId !== false && $LESSON_ID > 0) { if (CLearnLesson::IsPublishProhibited($LESSON_ID, $topCourseLessonId)) { $str_PUBLISH_PROHIBITED = 'Y'; }
:</td> <td> <input type="text" name="SORT" size="4" maxlength="10" value="<?php echo htmlspecialcharsbx($str_SORT); ?> "> </td> </tr> <?php $tabControl->EndCustomField("SORT"); $tabControl->AddSection("LEARNING_ACTIVATION_SCHEDULE", GetMessage('LEARNING_ACTIVATION_SCHEDULE')); $tabControl->BeginCustomField("PROPERTY_2", GetMessage('LEARNING_ACTIVATION_SCHEDULE_TITLE'), false); $html = '<table cellpadding="0" cellspacing="0" border="0" class="nopadding" width="100%" id="tb' . md5($name) . '">'; $arLessons = $arDelays = array(); if ($ID && $str_COURSE_LESSON_ID) { $rs = CLearnLesson::GetListOfImmediateChilds($str_COURSE_LESSON_ID, array('SORT' => 'ASC')); while ($ar = $rs->getNext()) { $arLessons[$ar['LESSON_ID']] = $ar['NAME']; } $arDelays = CLearningGroupLesson::getDelays($ID, array_keys($arLessons)); foreach ($arLessons as $lessonId => $lessonName) { $period = $arDelays[$lessonId]; $html .= '<tr><td>'; $html .= $lessonName; $html .= '</td><td>'; $html .= '<input type="text" name="PERIOD_L[' . $lessonId . ']" size="4" maxlength="5" value="' . htmlspecialcharsbx($period) . '">'; $html .= '</td></tr>'; } } else { $html .= GetMessage('LEARNING_AVAILABLE_AFTER_ELEMENT_CREATION'); }
/** * 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 _GetCourseContent($parentLessonId, $DEPTH_LEVEL = 1) { global $DB; $res = CLearnLesson::GetListOfImmediateChilds($parentLessonId, array('EDGE_SORT' => 'asc')); while ($arRes = $res->Fetch()) { $arRes['ID'] = $arRes['LESSON_ID']; // for compatibility if ($arRes['IS_CHILDS'] == '1') { $itemType = 'CHA'; } else { $itemType = 'LES'; } if (CLearnLesson::IsPublishProhibited($arRes['LESSON_ID'], $parentLessonId)) { $arRes['META_PUBLISH_PROHIBITED'] = 'Y'; } else { $arRes['META_PUBLISH_PROHIBITED'] = 'N'; } $r = ++$this->RefID; $this->arItems[$r] = $this->_CreateContent($itemType, $arRes, $r); $this->strItems .= '<item identifier="' . $itemType . $r . '" identifierref="RES' . $r . '"><title>' . htmlspecialcharsbx($arRes["NAME"]) . '</title>'; $this->strResourses .= '<resource identifier="RES' . $r . '" type="webcontent" href="res' . $r . '.xml">' . $this->_GetResourceFiles($r) . '</resource>'; $this->createQuestionItems($arRes["ID"]); // Load content recursively for chapters if ($arRes['IS_CHILDS'] == '1') { $this->_GetCourseContent($arRes["ID"], $DEPTH_LEVEL + 1); } $this->strItems .= "</item>"; } }
public function BuildList() { global $USER; $filterParams = GetFilterParams('filter_'); // list's footer $this->oList->AddFooter(array(array('title' => GetMessage('MAIN_ADMIN_LIST_SELECTED'), 'value' => $this->rsData->SelectedRowsCount()), array('counter' => true, 'title' => GetMessage('MAIN_ADMIN_LIST_CHECKED'), 'value' => '0'))); $oParentPath = new CLearnPath(); if (isset($_GET['LESSON_PATH'])) { $oParentPath->ImportUrlencoded($_GET['LESSON_PATH']); } $arParentPath = $oParentPath->GetPathAsArray(); // building list while ($arRes = $this->rsData->NavNext(false)) { $oCurPath = new CLearnPath(); $oCurPath->SetPathFromArray(array_merge($arParentPath, array($arRes['LESSON_ID']))); $urlCurPath = $oCurPath->ExportUrlencoded(); unset($oCurPath); // PUBLISH_PROHIBITED available in context of most parent course only if ($this->contextCourseLessonId !== false) { $arRes['PUBLISH_PROHIBITED'] = 'N'; if (CLearnLesson::IsPublishProhibited($arRes['LESSON_ID'], $this->contextCourseLessonId)) { $arRes['PUBLISH_PROHIBITED'] = 'Y'; } } $arRes['SITE_ID'] = ''; $courseId = CLearnLesson::GetLinkedCourse($arRes['LESSON_ID']); if ($courseId !== false) { $hrefPrefix = 'learn_course_edit.php?COURSE_ID=' . $courseId; $resCourseSites = CCourse::GetSite($courseId); while ($arCourseSites = $resCourseSites->Fetch()) { if ($arRes['SITE_ID'] != '') { $arRes['SITE_ID'] .= ' / '; } $arRes['SITE_ID'] .= htmlspecialcharsbx($arCourseSites['LID']); } } else { $hrefPrefix = 'learn_unilesson_edit.php?LESSON_ID=' . $arRes['LESSON_ID'] . '&LESSON_PATH=' . urlencode($urlCurPath); } $actionEditLesson = $hrefPrefix . '&lang=' . LANG . $filterParams; $rowAction = false; $rowTitle = ''; if (!$this->IsSearchMode()) { $rowAction = 'learn_unilesson_admin.php?lang=' . LANG . '&set_filter=Y' . '&PARENT_LESSON_ID=' . ($arRes['LESSON_ID'] + 0) . '&LESSON_PATH=' . $urlCurPath . '&' . $this->hrefSearchRetPoint; $rowTitle = GetMessage('LEARNING_TRAVERSE'); // "Traverse list of immediate childs" if (!$arRes['IS_CHILDS']) { $rowAction = $actionEditLesson; $rowTitle = GetMessage('LEARNING_EDIT_TITLE'); } } $row =& $this->oList->AddRow($arRes['LESSON_ID'], $arRes, $rowAction, $rowTitle); $arParents = $arChilds = array(); $htmlParents = $htmlChilds = ''; $rsParents = CLearnLesson::GetListOfImmediateParents($arRes['LESSON_ID'], array(), array('CHECK_PERMISSIONS' => 'N')); while ($arParent = $rsParents->Fetch()) { $arParents[] = $arParent['NAME']; } $arParents = array_map('htmlspecialcharsbx', $arParents); if (count($arParents) > 0) { $htmlParents = implode('<hr width="100%" size="1">', $arParents); } else { $htmlParents = ' '; } $rsChilds = CLearnLesson::GetListOfImmediateChilds($arRes['LESSON_ID'], array(), array('CHECK_PERMISSIONS' => 'N')); while ($arChild = $rsChilds->Fetch()) { $arChilds[] = $arChild['NAME']; } $arChilds = array_map('htmlspecialcharsbx', $arChilds); if (count($arChilds) > 0) { $htmlChilds = implode('<hr width="100%" size="1">', $arChilds); } else { $htmlChilds = ' '; } if (isset($arRes['LINKED_LESSON_ID']) && $arRes['LINKED_LESSON_ID'] > 0) { $icon = 'learning_icon_courses'; } elseif (count($arChilds) > 0) { $icon = 'learning_icon_chapters'; } else { $icon = 'learning_icon_lessons'; } if (!$this->IsSearchMode()) { $row->AddViewField('NAME', '<span class="adm-list-table-icon-link"><span class="adm-submenu-item-link-icon adm-list-table-icon ' . $icon . '"></span>' . ($rowAction === false ? '<span class="adm-list-table-link">' . htmlspecialcharsbx($arRes['NAME']) . '</span>' : '<a href="' . $rowAction . '" class="adm-list-table-link">' . htmlspecialcharsbx($arRes['NAME']) . '</a>') . '</span>'); } else { $actionUseLesson = "(function()\n\t\t\t\t\t{\n\t\t\t\t\t\tvar fnName = '" . str_replace(array("'", ';', ',', "\n", "\r"), '', htmlspecialcharsbx($this->search_retpoint)) . "';\n\t\t\t\t\t\tif ( ! (window.opener && window.opener[fnName]) )\n\t\t\t\t\t\t\treturn;\n\n\t\t\t\t\t\twindow.opener[fnName]('" . (int) $arRes['LESSON_ID'] . "', '" . CUtil::JSEscape(htmlspecialcharsbx($arRes['NAME'])) . "');\n\t\t\t\t\t\twindow.close();\n\t\t\t\t\t})();\n\t\t\t\t\t"; $row->AddViewField('NAME', '<a href="javascript:void(0);" class="adm-list-table-icon-link" onclick="' . $actionUseLesson . '"><span class="adm-submenu-item-link-icon adm-list-table-icon ' . $icon . '"></span><span class="adm-list-table-link">' . htmlspecialcharsbx($arRes['NAME']) . '</span></a>'); } $row->AddViewField('PARENTS', $htmlParents); $row->AddEditField('PARENTS', ' '); $row->AddViewField('CHILDS', $htmlChilds); $row->AddEditField('CHILDS', ' '); // this is very heavy statistic, so will be a good idea to add settings to the module, which turn off this statistics $oLearnTree = CLearnLesson::GetTree($arRes['LESSON_ID']); $arTree = $oLearnTree->GetTreeAsList(); $depth = -1; $chapterCount = 0; $lessonsCount = 0; $questionsCount = CLQuestion::GetCount(array('LESSON_ID' => (int) $arRes['LESSON_ID'])); foreach ($arTree as $arLessonData) { if ($arLessonData['IS_CHILDS']) { ++$chapterCount; } else { ++$lessonsCount; } if ((int) $arLessonData['#DEPTH_IN_TREE'] > $depth) { $depth = (int) $arLessonData['#DEPTH_IN_TREE']; } $questionsCount += CLQuestion::GetCount(array('LESSON_ID' => (int) $arLessonData['LESSON_ID'])); } // PUBLISH_PROHIBITED available in context of most parent course only if ($this->contextCourseLessonId !== false) { if ($this->IsLessonUpdateAccess($arRes['LESSON_ID']) === true) { $row->AddInputField('PUBLISH_PROHIBITED', array('size' => '35')); $row->AddCheckField('PUBLISH_PROHIBITED'); } else { $row->AddCheckField('PUBLISH_PROHIBITED', true); } } // Render CARDINALITY fields $htmlDepth = (int) ($depth + 1); $htmlChapters = (string) (int) $chapterCount . ' [<a href="learn_unilesson_edit.php?lang=' . LANG . '&PROPOSE_RETURN_LESSON_PATH=' . $urlCurPath . '" title="' . GetMessage('LEARNING_UNILESSON_ADD') . '"' . '>+</a>]'; $htmlLessons = (string) (int) $lessonsCount . ' [<a href="learn_unilesson_edit.php?lang=' . LANG . '&PROPOSE_RETURN_LESSON_PATH=' . $urlCurPath . '" title="' . GetMessage('LEARNING_UNILESSON_ADD') . '"' . '>+</a>]'; $htmlQuestions = '<a href="learn_question_admin.php?lang=' . LANG . '&filter=Y&set_filter=Y' . '&PARENT_LESSON_ID=' . ($arRes['LESSON_ID'] + 0) . '&LESSON_PATH=' . $urlCurPath . '" title="' . GetMessage('LEARNING_QUESTION_ALT') . '">' . (int) $questionsCount . '</a>' . ' [' . '<a href="learn_question_edit.php?lang=' . LANG . '&LESSON_PATH=' . $urlCurPath . '&QUESTION_TYPE=S' . '&filter=Y&set_filter=Y' . '&from=learn_menu"' . ' title="' . GetMessage('LEARNING_QUESTION_ADD') . '">+</a>' . ']'; $row->AddViewField('CARDINALITY_DEPTH', $htmlDepth); $row->AddViewField('CARDINALITY_CHAPTERS', $htmlChapters); $row->AddViewField('CARDINALITY_LESSONS', $htmlLessons); $row->AddViewField('CARDINALITY_QUESTIONS', $htmlQuestions); if ($courseId !== false) { $testsCount = (int) CTest::GetCount(array('COURSE_ID' => $courseId)); $htmlTests = '<a href="learn_test_admin.php?lang=' . LANG . '&COURSE_ID=' . $courseId . '&PARENT_LESSON_ID=' . (int) $arRes['LESSON_ID'] . '&LESSON_PATH=' . $urlCurPath . '&filter=Y&set_filter=Y"' . '>' . $testsCount . '</a>' . ' [<a href="learn_test_edit.php?lang=' . LANG . '&COURSE_ID=' . $courseId . '&PARENT_LESSON_ID=' . (int) $arRes['LESSON_ID'] . '&LESSON_PATH=' . $urlCurPath . '&filter=Y&set_filter=Y" title="' . GetMessage('LEARNING_QUESTION_ADD') . '"' . '>+</a>]'; $row->AddViewField('CARDINALITY_TESTS', $htmlTests); } if (!$this->IsSearchMode() && $this->IsLessonUpdateAccess($arRes['LESSON_ID']) === true) { $row->AddInputField('NAME', array('size' => '35')); // SORT field editing possibly only for courses and for lessons in relation to parent lesson if ($this->IsListChildLessonsMode() || $this->IsListAnyCoursesMode()) { $row->AddInputField('SORT', array('size' => '3')); } $row->AddCheckField('ACTIVE'); $row->AddInputField('CODE'); } else { $row->AddCheckField('ACTIVE', false); } $row->AddViewField('CREATED_USER_NAME', $arRes['CREATED_USER_NAME']); $arActions = array(); if (!$this->IsSearchMode()) { if ($this->IsLessonUpdateAccess($arRes['LESSON_ID']) === true) { $editTxt = GetMessage('MAIN_ADMIN_MENU_EDIT'); } else { $editTxt = GetMessage('MAIN_ADMIN_MENU_OPEN'); } // Actions $arActions[] = array('ICON' => 'edit', 'TEXT' => $editTxt, 'ACTION' => $this->oList->ActionRedirect($actionEditLesson)); $arActions[] = array("SEPARATOR" => true); $arActions[] = array('ICON' => 'list', 'TEXT' => GetMessage('LEARNING_QUESTION_ALT') . ' (' . ($questionsCount + 0) . ')', 'ACTION' => $this->oList->ActionRedirect('learn_question_admin.php?lang=' . LANG . '&filter=Y&set_filter=Y' . '&PARENT_LESSON_ID=' . ($arRes['LESSON_ID'] + 0) . '&LESSON_PATH=' . urlencode($urlCurPath))); /* $arActions[] = array( "ICON"=>"copy", "TEXT"=>GetMessage("MAIN_ADMIN_ADD_COPY"), "ACTION"=>$this->oList->ActionRedirect("learn_course_edit.php?COPY_ID=".$f_ID)); */ $isDeleteCmdDisabled = true; $isDisbandCmdDisabled = true; $deleteMSG = ''; $disbandMSG = ''; $actionDisband = ''; $action = ''; if ($arRes['CHILDS_CNT'] > 0) { $deleteMSG = GetMessage('LEARNING_ADMIN_MENU_DELETE_RECURSIVE') . ' (' . (string) (int) $arRes['CHILDS_CNT'] . ')'; } else { $deleteMSG = GetMessage("MAIN_ADMIN_MENU_DELETE"); } $disbandMSG = GetMessage('LEARNING_ADMIN_MENU_DISBAND'); $isEnoughRightsForDisbandLesson = false; try { $this->EnsureLessonDisbandAccess($arRes['LESSON_ID']); $isEnoughRightsForDisbandLesson = true; } catch (CLearnRenderAdminUnilessonListException $e) { if ($e->GetCode() & CLearnRenderAdminUnilessonListException::C_ACCESS_DENIED) { } else { // bubble exception throw new CLearnRenderAdminUnilessonListException($e->GetMessage(), $e->GetCode()); } } // If we can unlink all neighbours and remove lesson if ($isEnoughRightsForDisbandLesson) { $arOPathes = CLearnLesson::GetListOfParentPathes($arRes['LESSON_ID']); $parentPathesCnt = count($arOPathes); // prepare "Disband" command $isDisbandCmdDisabled = false; $actionDisband = $this->oList->ActionDoGroup($arRes['LESSON_ID'], 'disband', 'PARENT_LESSON_ID=' . ($this->requestedParentLessonId + 0)); if ($parentPathesCnt >= 1) { $actionDisband = "if(confirm('" . str_replace('#CNT#', $parentPathesCnt, GetMessageJS('LEARNING_CONFIRM_DISBAND_LESSON_WITH_PARENT_PATHES')) . "')) " . '{ ' . $actionDisband . ' }'; } $actionDisband = "if(confirm('" . GetMessageJS('LEARNING_ADMIN_MENU_DISBAND_QUESTION') . "')) " . '{ ' . $actionDisband . ' }'; // prepare "Remove" command $isDeleteCmdDisabled = false; if ($arRes['CHILDS_CNT'] > 0) { $action = $this->oList->ActionDoGroup($arRes['LESSON_ID'], 'recursive_delete', 'PARENT_LESSON_ID=' . ($this->requestedParentLessonId + 0)); } else { // If no childs => "delete" is equal to "disband" $action = $this->oList->ActionDoGroup($arRes['LESSON_ID'], 'disband', 'PARENT_LESSON_ID=' . ($this->requestedParentLessonId + 0)); } if ($parentPathesCnt >= 1) { $deleteMSG .= ' [' . $parentPathesCnt . ']'; $action = "if(confirm('" . str_replace('#CNT#', $parentPathesCnt, GetMessageJS("LEARNING_CONFIRM_DEL_LESSON_WITH_PARENT_PATHES")) . "')) " . $action; } else { $action = "if(confirm('" . GetMessageJS('LEARNING_CONFIRM_DEL_MESSAGE') . "')) " . $action; } } // We can "disband" only lessons, that contains childs $arActions[] = array("SEPARATOR" => true); if ($arRes['CHILDS_CNT'] > 0) { $arActions[] = array('ICON' => 'delete', 'TEXT' => $disbandMSG, 'ACTION' => $actionDisband, 'DISABLED' => $isDisbandCmdDisabled, 'TITLE' => GetMessage('LEARNING_ADMIN_MENU_DISBAND_TITLE')); } $arActions[] = array('ICON' => 'delete', 'TEXT' => $deleteMSG, 'ACTION' => $action, 'DISABLED' => $isDeleteCmdDisabled); } else { $arActions[] = array('ICON' => 'list', 'TEXT' => GetMessage('LEARNING_SELECT'), 'ACTION' => $actionUseLesson); } $row->AddActions($arActions); } return $this; }
public 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; }
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; }
public function _GetCourseContent($parentLessonId, $DEPTH_LEVEL = 1) { global $DB; $res = CLearnLesson::GetListOfImmediateChilds ( $parentLessonId, array( // order 'EDGE_SORT' => 'asc' ) ); while ($arRes= $res->Fetch()) { $arRes['ID'] = $arRes['LESSON_ID']; // for compatibility if ($arRes['IS_CHILDS'] == '1') $itemType = 'CHA'; else $itemType = 'LES'; $r = $this->RefID++; $this->arItems[$r] = $this->_CreateContent($itemType, $arRes, $r); $this->strItems .= '<item identifier="' . $itemType . $r . '" identifierref="RES'.$r.'"><title>'.htmlspecialcharsbx($arRes["NAME"]).'</title>'; $this->strResourses .= '<resource identifier="RES'.$r.'" type="webcontent" href="res'.$r.'.xml">'.$this->_GetResourceFiles($r).'</resource>'; $strSql = "SELECT * FROM b_learn_question WHERE LESSON_ID=".$arRes["ID"]." ORDER BY SORT ASC "; $q = $DB->Query($strSql, false, "File: ".__FILE__."<br>Line: ".__LINE__); while ($arQRes = $q->Fetch()) { $r = $this->RefID++; $this->arItems[$r] = $this->CreateQTI($arQRes, $r); $this->strItems .= '<item identifier="QUE'.$r.'" identifierref="RES'.$r.'"><title>'.htmlspecialcharsbx($arQRes["NAME"]).'</title></item>'; $this->strResourses .= '<resource identifier="RES'.$r.'" type="imsqti_xmlv1p1" href="res'.$r.'.xml">'.$this->_GetResourceFiles($r).'</resource>'; } // Load content recursively for chapters if ($arRes['IS_CHILDS'] == '1') $this->_GetCourseContent($arRes["ID"], $DEPTH_LEVEL+1); $this->strItems .= "</item>"; } }