Ejemplo n.º 1
0
 public static final function Add($arFields, $isCourse = false, $parentLessonId = true, $arProperties = array('SORT' => 500), $isCheckPermissions = true, $checkPermissionsForUserId = -1)
 {
     global $USER_FIELD_MANAGER;
     $isAccessGranted = false;
     if ($isCheckPermissions) {
         if (CLearnAccessMacroses::CanUserAddLessonWithoutParentLesson(array('user_id' => $checkPermissionsForUserId))) {
             if ($parentLessonId === true) {
                 // we don't need to link lesson to parent,
                 // so permissions check is complete
                 $isAccessGranted = true;
             } else {
                 // We must check, is user have access to link lesson to some parent
                 if (CLearnAccessMacroses::CanUserAddLessonToParentLesson(array('parent_lesson_id' => $parentLessonId, 'user_id' => $checkPermissionsForUserId))) {
                     $isAccessGranted = true;
                 }
             }
         }
     } else {
         $isAccessGranted = true;
     }
     // don't check permissions
     if (!$isAccessGranted) {
         throw new LearnException('EA_ACCESS_DENIED', LearnException::EXC_ERR_ALL_ACCESS_DENIED);
     }
     // If lesson is course, there is can be additional params, which must be extracted
     if ($isCourse) {
         // Additional fields will be removed from $arFields by this method
         $arCourseFields = self::_ExtractAdditionalCourseFields($arFields);
     }
     if (!$USER_FIELD_MANAGER->CheckFields('LEARNING_LESSONS', 0, $arFields)) {
         return false;
     }
     foreach (GetModuleEvents('learning', 'OnBeforeLessonAdd', true) as $arEvent) {
         ExecuteModuleEventEx($arEvent, array(&$arFields));
     }
     if (!isset($arFields['NAME']) || $arFields['NAME'] == '') {
         $lessonId = false;
         $arMsg = array(array("id" => "NAME", "text" => GetMessage("LEARNING_BAD_NAME")));
         $e = new CAdminException($arMsg);
         $GLOBALS["APPLICATION"]->ThrowException($e);
     } else {
         $lessonId = CLearnGraphNode::Create($arFields);
     }
     if ($lessonId) {
         $USER_FIELD_MANAGER->Update('LEARNING_LESSONS', $lessonId, $arFields);
         if ($isCourse) {
             // Convert lesson to course
             self::BecomeCourse($lessonId, $arCourseFields);
         } else {
             // Link to parent lesson, if need
             if ($parentLessonId !== true) {
                 self::RelationAdd($parentLessonId, $lessonId, $arProperties);
             }
         }
         CLearnCacheOfLessonTreeComponent::MarkAsDirty();
     }
     $arFields['LESSON_ID'] = $lessonId;
     foreach (GetModuleEvents('learning', 'OnAfterLessonAdd', true) as $arEvent) {
         ExecuteModuleEventEx($arEvent, array(&$arFields));
     }
     return $lessonId;
 }
Ejemplo n.º 2
0
         exit;
     }
 }
 if ($arParams['SEF_MODE'] === 'Y') {
     $addReturnUrl = array("lesson" => CComponentEngine::MakePathFromTemplate($arParams['~SEF_FOLDER'] . $arResult["URL_TEMPLATES"]["lesson.detail"], array("COURSE_ID" => $arParams["COURSE_ID"])), "test" => CComponentEngine::MakePathFromTemplate($arParams['~SEF_FOLDER'] . $arResult["URL_TEMPLATES"]["test"], array("COURSE_ID" => $arParams["COURSE_ID"])), "course" => str_replace("COURSE_ID=" . $arParams["COURSE_ID"], "COURSE_ID=#COURSE_ID#", $arParams['~SEF_FOLDER'] . $arResult["URL_TEMPLATES"]["course.detail"]));
 } else {
     $addReturnUrl = array("lesson" => CComponentEngine::MakePathFromTemplate($arResult["URL_TEMPLATES"]["lesson.detail"], array("COURSE_ID" => $arParams["COURSE_ID"])), "test" => CComponentEngine::MakePathFromTemplate($arResult["URL_TEMPLATES"]["test"], array("COURSE_ID" => $arParams["COURSE_ID"])), "course" => str_replace("COURSE_ID=" . $arParams["COURSE_ID"], "COURSE_ID=#COURSE_ID#", $arResult["URL_TEMPLATES"]["course.detail"]));
 }
 $contextLessonId = $lessonID;
 // If lessonId not determined and there is course id known - use it
 if ($contextLessonId == 0 && $linkedLessonId !== false) {
     $contextLessonId = $linkedLessonId;
 }
 $arMenuButtons = array();
 if ($contextLessonId > 0) {
     if (CLearnAccessMacroses::CanUserAddLessonToParentLesson(array('parent_lesson_id' => $contextLessonId))) {
         $arMenuButtons[] = array("TEXT" => GetMessage("LEARNING_COURSES_LESSON_ADD"), "TITLE" => GetMessage("LEARNING_COURSES_LESSON_ADD"), "URL" => 'javascript:' . $APPLICATION->GetPopupLink(array("URL" => "/bitrix/admin/learn_unilesson_edit.php?lang=" . LANGUAGE_ID . "&PARENT_LESSON_ID=" . $contextLessonId . "&bxpublic=Y&from_module=learning&return_url=" . urlencode($addReturnUrl["lesson"]), "PARAMS" => array("width" => 700, 'height' => 500, 'resize' => false))), "ICON" => "bx-context-toolbar-create-icon", "ID" => "bx-context-toolbar-create-lesson");
         $arMenuButtons[] = array("TEXT" => GetMessage("LEARNING_COURSES_CHAPTER_ADD"), "TITLE" => GetMessage("LEARNING_COURSES_CHAPTER_ADD"), "URL" => 'javascript:' . $APPLICATION->GetPopupLink(array("URL" => "/bitrix/admin/learn_unilesson_edit.php?lang=" . LANGUAGE_ID . "&PARENT_LESSON_ID=" . $contextLessonId . "&bxpublic=Y&from_module=learning&return_url=" . urlencode($addReturnUrl["lesson"]), "PARAMS" => array("width" => 700, 'height' => 500, 'resize' => false))), "ICON" => "bx-context-toolbar-create-icon", "ID" => "bx-context-toolbar-create-chapter");
     }
     if (CLearnAccessMacroses::CanUserEditLesson(array('lesson_id' => $contextLessonId))) {
         $arMenuButtons[] = array("TEXT" => GetMessage("LEARNING_COURSES_TEST_ADD"), "TITLE" => GetMessage("LEARNING_COURSES_TEST_ADD"), "URL" => 'javascript:' . $APPLICATION->GetPopupLink(array("URL" => "/bitrix/admin/learn_test_edit.php?lang=" . LANGUAGE_ID . "&COURSE_ID=" . $arParams["COURSE_ID"] . "&bxpublic=Y&from_module=learning&return_url=" . urlencode($addReturnUrl["test"]), "PARAMS" => array("width" => 700, 'height' => 500, 'resize' => false))), "ICON" => "bx-context-toolbar-create-icon", "ID" => "bx-context-toolbar-create-test");
     }
     if (CLearnAccessMacroses::CanUserAddLessonWithoutParentLesson()) {
         $arMenuButtons[] = array("TEXT" => GetMessage("LEARNING_COURSES_COURSE_ADD"), "TITLE" => GetMessage("LEARNING_COURSES_COURSE_ADD"), "URL" => 'javascript:' . $APPLICATION->GetPopupLink(array("URL" => "/bitrix/admin/learn_course_edit.php?lang=" . LANGUAGE_ID . "&bxpublic=Y&from_module=learning&return_url=" . urlencode($addReturnUrl["course"]), "PARAMS" => array("width" => 700, 'height' => 500, 'resize' => false))), "ICON" => "bx-context-toolbar-create-icon", "ID" => "bx-context-toolbar-create-course");
     }
     if (count($arMenuButtons) > 0) {
         $arMenuButtons[] = array("SEPARATOR" => "Y");
     }
     if (CLearnAccessMacroses::CanUserEditLesson(array('lesson_id' => $contextLessonId))) {
         $arMenuButtons[] = array("TEXT" => GetMessage("LEARNING_COURSES_QUEST_S_ADD"), "TITLE" => GetMessage("LEARNING_COURSES_QUEST_S_ADD"), "URL" => 'javascript:' . $APPLICATION->GetPopupLink(array("URL" => "/bitrix/admin/learn_question_edit.php?lang=" . LANGUAGE_ID . "&COURSE_ID=" . $arParams["COURSE_ID"] . "&LESSON_PATH=" . $contextLessonId . "&QUESTION_TYPE=S&bxpublic=Y&from_module=learning", "PARAMS" => array("width" => 700, 'height' => 500, 'resize' => false))), "ICON" => "bx-context-toolbar-create-icon", "ID" => "bx-context-toolbar-create-question-s");
         $arMenuButtons[] = array("TEXT" => GetMessage("LEARNING_COURSES_QUEST_M_ADD"), "TITLE" => GetMessage("LEARNING_COURSES_QUEST_M_ADD"), "URL" => 'javascript:' . $APPLICATION->GetPopupLink(array("URL" => "/bitrix/admin/learn_question_edit.php?lang=" . LANGUAGE_ID . "&COURSE_ID=" . $arParams["COURSE_ID"] . "&LESSON_PATH=" . $contextLessonId . "&QUESTION_TYPE=M&bxpublic=Y&from_module=learning", "PARAMS" => array("width" => 700, 'height' => 500, 'resize' => false))), "ICON" => "bx-context-toolbar-create-icon", "ID" => "bx-context-toolbar-create-question-m");
Ejemplo n.º 3
0
 public static final function Add($arFields, $isCourse = false, $parentLessonId = true, $arProperties = array('SORT' => 500), $isCheckPermissions = true, $checkPermissionsForUserId = -1)
 {
     $isAccessGranted = false;
     if ($isCheckPermissions) {
         if (CLearnAccessMacroses::CanUserAddLessonWithoutParentLesson(array('user_id' => $checkPermissionsForUserId))) {
             if ($parentLessonId === true) {
                 // we don't need to link lesson to parent,
                 // so permissions check is complete
                 $isAccessGranted = true;
             } else {
                 // We must check, is user have access to link lesson to some parent
                 if (CLearnAccessMacroses::CanUserAddLessonToParentLesson(array('parent_lesson_id' => $parentLessonId, 'user_id' => $checkPermissionsForUserId))) {
                     $isAccessGranted = true;
                 }
             }
         }
     } else {
         $isAccessGranted = true;
     }
     // don't check permissions
     if (!$isAccessGranted) {
         throw new LearnException('EA_ACCESS_DENIED', LearnException::EXC_ERR_ALL_ACCESS_DENIED);
     }
     // If lesson is course, there is can be additional params, which must be extracted
     if ($isCourse) {
         // Additional fields will be removed from $arFields by this method
         $arCourseFields = self::_ExtractAdditionalCourseFields($arFields);
     }
     CLearnHelper::FireEvent('OnBeforeLessonAdd', $arFields);
     $lessonId = CLearnGraphNode::Create($arFields);
     if ($isCourse) {
         // Convert lesson to course
         self::BecomeCourse($lessonId, $arCourseFields);
     } else {
         // Link to parent lesson, if need
         if ($parentLessonId !== true) {
             self::RelationAdd($parentLessonId, $lessonId, $arProperties);
         }
     }
     CLearnCacheOfLessonTreeComponent::MarkAsDirty();
     $arFields['LESSON_ID'] = $lessonId;
     CLearnHelper::FireEvent('OnAfterLessonAdd', $arFields);
     return $lessonId;
 }