Exemple #1
0
 /**
  * WARNING: don't use this method, it's for internal use only
  * 
  * Convert course to non-course lesson (course will be removed,
  * but lesson will stay exists)
  * 
  * WARNING: this method terminates (by die()/exit()) current execution flow
  * when SQL server error occured. It's due to bug in CDatabase::Update() in main
  * module (version info:
  *    define("SM_VERSION","11.0.12");
  *    define("SM_VERSION_DATE","2012-02-21 17:00:00"); // YYYY-MM-DD HH:MI:SS
  * )
  *
  * @param int $courseId (returned by GetLinkedCourse($lessonId) )
  * 
  * @access private
  */
 protected static function CourseBecomeLesson($courseId)
 {
     global $DB;
     self::_EnsureArgsStrictlyCastableToIntegers($courseId);
     $linkedLessonId = CCourse::CourseGetLinkedLesson($courseId);
     if ($linkedLessonId === false) {
         return false;
     }
     // Check certificates (if exists => forbid removing course)
     $certificate = CCertification::GetList(array(), array("COURSE_ID" => $courseId, 'CHECK_PERMISSIONS' => 'N'));
     if ($certificate === false || $certificate->GetNext()) {
         return false;
     }
     // Remove tests
     $tests = CTest::GetList(array(), array("COURSE_ID" => $courseId));
     if ($tests === false) {
         return false;
     }
     while ($arTest = $tests->Fetch()) {
         if (!CTest::Delete($arTest["ID"])) {
             return false;
         }
     }
     // Remove all prohibitions for lessons in context of course to be removed
     // and remove prohibitions for course to be removed in context of all other courses
     self::PublishProhibitionPurge($linkedLessonId, self::PUBLISH_PROHIBITION_PURGE_ALL_LESSONS_IN_COURSE_CONTEXT | self::PUBLISH_PROHIBITION_PURGE_LESSON_IN_ALL_COURSE_CONTEXT);
     $rc = $DB->Query("DELETE FROM b_learn_course\n\t\t\tWHERE ID=" . (string) (int) $courseId, true);
     // reload cache of LINKED_LESSON_ID -> COURSE_ID
     self::GetCourseToLessonMap_ReloadCache();
     CLearnCacheOfLessonTreeComponent::MarkAsDirty();
     /**
      * This code will be useful after bug in CDatabase::Update()
      * and CDatabase::Insert() will be solved and $ignore_errors setted
      * to true in Insert()/Update() call above.
      */
     if ($rc === false) {
         throw new LearnException('EA_SQLERROR', LearnException::EXC_ERR_ALL_GIVEUP);
     }
     // If data not updated
     if ($rc === 0) {
         throw new LearnException('EA_OTHER: data not updated', LearnException::EXC_ERR_ALL_GIVEUP);
     }
 }
     $rsData = CTest::GetList(array($by => $order), $arFilter);
     while ($arRes = $rsData->Fetch()) {
         $arID[] = $arRes['ID'];
     }
 }
 foreach ($arID as $ID) {
     if (strlen($ID) <= 0) {
         continue;
     }
     $ID = IntVal($ID);
     switch ($_REQUEST['action']) {
         case "delete":
             @set_time_limit(0);
             $DB->StartTransaction();
             $ch = new CTest();
             if (!$ch->Delete($ID)) {
                 $DB->Rollback();
                 $lAdmin->AddGroupError(GetMessage("LEARNING_DELETE_ERROR"), $ID);
             }
             $DB->Commit();
             break;
         case "activate":
         case "deactivate":
             $ch = new CTest();
             $arFields = array("ACTIVE" => $_REQUEST['action'] == "activate" ? "Y" : "N");
             if (!$ch->Update($ID, $arFields)) {
                 if ($e = $APPLICATION->GetException()) {
                     $lAdmin->AddGroupError(GetMessage("SAVE_ERROR") . $ID . ": " . $e->GetString(), $ID);
                 }
             }
             break;