/** * <p>Метод удаляет курс с идентификатором ID.</p> * * * * * @param int $ID Идентификатор курса. * * * * @return bool <p>Метод возвращает <i>true</i> в случае успешного удаления курса, в * противном случае возвращает <i>false</i>.</p> <a name="examples"></a> * * * <h4>Example</h4> * <pre> * <? * * if (CModule::IncludeModule("learning")) * { * * $ID = 109;//Course ID * * if($USER->IsAdmin()) * { * @set_time_limit(0); * $DB->StartTransaction(); * if(!CCourse::Delete($ID)) * $DB->Rollback(); * else * $DB->Commit(); * } * * } * * ?> * </pre> * * * @static * @link http://dev.1c-bitrix.ru/api_help/learning/classes/ccourse/delete.php * @author Bitrix */ public static function Delete($ID) { global $DB; $ID = intval($ID); if ($ID < 1) { return false; } $lessonId = CCourse::CourseGetLinkedLesson($ID); if ($lessonId === false) { return false; } CLearnLesson::Delete($lessonId); return true; }
public function ProcessActionsOnList() { if (isset($_POST['action']) && strlen($_POST['action']) !== 0) { $action = $_POST['action']; } elseif (isset($_GET['action']) && strlen($_GET['action']) !== 0) { $action = $_GET['action']; } elseif (isset($_POST['action_button']) && strlen($_POST['action_button']) !== 0) { $action = $_POST['action_button']; } elseif (isset($_GET['action_button']) && strlen($_GET['action_button']) !== 0) { $action = $_GET['action_button']; } else { return $this; } // nothing to do $arID = $this->oList->GroupAction(); if ($arID === false) { return $this; } // no items selected if (check_bitrix_sessid() !== true) { throw new CLearnRenderAdminUnilessonListException('', CLearnRenderAdminUnilessonListException::C_ACCESS_DENIED); } if ($_POST['action_target'] === 'selected') { $arID = array(); $rsData = $this->fetchDataFromDb(); while ($arRes = $rsData->Fetch()) { $arID[] = $arRes['LESSON_ID']; } } foreach ($arID as $lessonId) { // If not int or string can't be strictly casted to int if (!(is_numeric($lessonId) && is_int($lessonId + 0))) { continue; } $lessonId += 0; $wasError = false; $preventSelectionOnError = false; try { switch ($action) { case 'unlink': // !!! In case of unlinking in $lessonId not Lesson's id, but it's full path $oPath = new CLearnPath(); $oPath->ImportUrlencoded($lessonId); $arPath = $oPath->GetPathAsArray(); if (count($arPath) < 2) { throw new CLearnRenderAdminUnilessonListException('', CLearnRenderAdminUnilessonListException::C_LOGIC); } $childLessonId = $oPath->GetBottom(); $parentLessonId = $oPath->GetBottom(); if ($parentLessonId === false || $childLessonId === false) { // something goes wrong throw new CLearnRenderAdminUnilessonListException('', CLearnRenderAdminUnilessonListException::C_LOGIC); } $this->EnsureLessonUnlinkAccess($parentLessonId, $childLessonId); // throws an exception on error CLearnLesson::RelationRemove($parentLessonId, $childLessonId); break; case 'disband': @set_time_limit(0); $courseId = CLearnLesson::GetLinkedCourse($lessonId); if ($courseId !== false && CCourse::IsCertificatesExists($courseId)) { throw new Exception(GetMessage(LEARNING_COURSE_UNREMOVABLE_CAUSE_OF_CERTIFICATES)); } $this->EnsureLessonDisbandAccess($lessonId); CLearnLesson::Delete($lessonId); break; case 'delete': case 'recursive_delete': $preventSelectionOnError = true; // prevent switch table to "selection mode" when cannot delete item in list @set_time_limit(0); $courseId = CLearnLesson::GetLinkedCourse($lessonId); if ($courseId !== false && CCourse::IsCertificatesExists($courseId)) { throw new Exception(GetMessage(LEARNING_COURSE_UNREMOVABLE_CAUSE_OF_CERTIFICATES)); } try { // firstly, simulate to check permissions CLearnLesson::DeleteRecursiveLikeHardlinks(array('lesson_id' => $lessonId, 'simulate' => true)); // If all is OK, try to really remove it CLearnLesson::DeleteRecursiveLikeHardlinks($lessonId); } catch (LearnException $e) { if ($e->GetCode() === LearnException::EXC_ERR_ALL_ACCESS_DENIED) { throw new CLearnRenderAdminUnilessonListException('', CLearnRenderAdminUnilessonListException::C_ACCESS_DENIED); } else { // bubble exception throw new LearnException($e->GetMessage(), $e->GetCode()); } } break; case 'activate': case 'deactivate': if (strtolower($action) === 'deactivate') { $this->EnsureLessonDeactivateAccess($lessonId); $arFields = array('ACTIVE' => 'N'); } elseif (strtolower($action) === 'activate') { $this->EnsureLessonActivateAccess($lessonId); $arFields = array('ACTIVE' => 'Y'); } else { throw new CLearnRenderAdminUnilessonListException('WTFAYD,#Pro#?!', CLearnRenderAdminUnilessonListException::C_ACCESS_DENIED); } // Is item course or not? $courseId = CLearnLesson::GetLinkedCourse($lessonId); if ($courseId === false) { // not course CLearnLesson::Update($lessonId, $arFields); } else { $oCourse = new CCourse(); $rc = $oCourse->Update($courseId, $arFields); unset($oCourse); if ($rc === false) { throw new Exception(); } } break; default: throw new Exception(); break; } } catch (CLearnRenderAdminUnilessonListException $e) { $wasError = true; $errorText = $e->getMessage(); $errorCode = $e->getCode(); } catch (Exception $e) { $wasError = true; $errorText = $e->getMessage(); $errorCode = 0; // Because we checks below only CLearnRenderAdminUnilessonListException codes } if ($wasError) { if ($e->getCode() & CLearnRenderAdminUnilessonListException::C_ACCESS_DENIED) { // Access denied $errmsg = GetMessage('LEARNING_SAVE_ERROR') . '#' . $lessonId . ': ' . GetMessage('LEARNING_ACCESS_D'); if (strlen($errorText) > 0) { $errmsg .= ': ' . $errorText; } } else { // Some error occured during update operation $errmsg = GetMessage('LEARNING_SAVE_ERROR') . $lessonId; if (strlen($errorText) > 0) { $errmsg .= ' (' . $errorText . ')'; } } if ($preventSelectionOnError) { $this->oList->AddUpdateError($errmsg); } else { $this->oList->AddUpdateError($errmsg, $lessonId); } } } return $this; }