• Модуль: learning
  • Путь к файлу: ~/bitrix/modules/learning/classes/general/clearnlesson.php
  • Класс: CLearnLesson
  • Вызов: CLearnLesson::BecomeCourse
static function BecomeCourse ($lessonId, $arFields)
{
	global $DB;

	self::_EnsureArgsStrictlyCastableToIntegers ($lessonId);

	// LearnException will be throwed on invalid params
	$arCourseFields = self::_CanonizeAndCheckAdditionalParamsForAddCourse ($arFields);

	$ACTIVE_FROM = $ACTIVE_TO = 'NULL';

	if (($arCourseFields['ACTIVE_FROM'] !== NULL) && ($arCourseFields['ACTIVE_FROM'] !== ''))
		$ACTIVE_FROM = $DB->CharToDateFunction($arCourseFields['ACTIVE_FROM']);

	if (($arCourseFields['ACTIVE_TO'] !== NULL) && ($arCourseFields['ACTIVE_TO'] !== ''))
		$ACTIVE_TO = $DB->CharToDateFunction($arCourseFields['ACTIVE_TO']);

	$arFieldsToDb = array(
		'LINKED_LESSON_ID' => "'" . (int) ($lessonId + 0) . "'",
		'SORT'             => "'" . (int) ($arCourseFields['COURSE_SORT'] + 0) . "'",
		'ACTIVE_FROM'      => $ACTIVE_FROM,
		'ACTIVE_TO'        => $ACTIVE_TO,
		'RATING'           => "'" . $DB->ForSql($arCourseFields['RATING']) . "'",
		'RATING_TYPE'      => ( ($arCourseFields['RATING_TYPE'] === NULL) ? 'NULL' : ("'" . $DB->ForSql($arCourseFields['RATING_TYPE']) . "'") ),
		'SCORM'            => "'" . $DB->ForSql($arCourseFields['SCORM']) . "'"
		);

	$rc = $DB->Insert ('b_learn_course',
							$arFieldsToDb,
							__LINE__,		// $error_position
							false,			// $debug
							"",				// $exist_id
							false			// $ignore_errors, we must halt on errors due to bug in CDatabase::Insert();
							);

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

	return ( (int) $rc);	// returns course_id
}