• Модуль: learning
  • Путь к файлу: ~/bitrix/modules/learning/classes/general/clearnlesson.php
  • Класс: CLearnLesson
  • Вызов: CLearnLesson::CourseBecomeLesson
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
		WHERE ID=" . (string) ((int) $courseId),
		true	// $ignore_errors
		);

	// 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);
}