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

	if ( isset($arFields['ACTIVE'])
		&& ( ! is_bool($arFields['ACTIVE']) )
	)
	{
		if ($arFields['ACTIVE'] === 'Y')
			$arFields['ACTIVE'] = true;
		else
			$arFields['ACTIVE'] = false;
	}

	if ( ! $USER_FIELD_MANAGER->CheckFields('LEARNING_LESSONS', $id, $arFields) )
		return (false);

	$courseId = self::GetLinkedCourse ($id);

	// if lesson is course, extract additional fields of course
	if ($courseId !== false)
	{
		// Additional fields will be removed from $arFields by this method
		$arCourseFields = self::_ExtractAdditionalCourseFields ($arFields);
	}

	foreach(GetModuleEvents('learning', 'OnBeforeLessonUpdate', true) as $arEvent)
		ExecuteModuleEventEx($arEvent, array(&$arFields));

	if (
		array_key_exists('NAME', $arFields)
		&& ($arFields['NAME'] == '')
	)
	{
		$lessonId = false;

		$arMsg = array(array("id"=>"NAME", "text"=> GetMessage("LEARNING_BAD_NAME")));

		$e = new CAdminException($arMsg);
		$GLOBALS["APPLICATION"]->ThrowException($e);

		return(false);
	}

	$USER_FIELD_MANAGER->Update('LEARNING_LESSONS', $id, $arFields);

	// Update main lesson data
	CLearnGraphNode::Update ($id, $arFields);

	// If lesson is course, update course-specific data
	if ($courseId !== false)
	{
		// LearnException will be throwed on invalid params
		$arCourseFields = self::_CanonizeAndCheckAdditionalParamsForAddCourse ($arCourseFields, true);	// forUpdate = true

		$arFieldsToDb = array();

		if (array_key_exists('COURSE_SORT', $arCourseFields))
			$arFieldsToDb['SORT'] = "'" . (int) ($arCourseFields['COURSE_SORT'] + 0) . "'";

		if (array_key_exists('ACTIVE_FROM', $arCourseFields))
		{
			if (($arCourseFields['ACTIVE_FROM'] === NULL) || ($arCourseFields['ACTIVE_FROM'] === ''))
				$arFieldsToDb['ACTIVE_FROM'] = 'NULL';
			else
				$arFieldsToDb['ACTIVE_FROM'] = $DB->CharToDateFunction($arCourseFields['ACTIVE_FROM']);
		}

		if (array_key_exists('ACTIVE_TO', $arCourseFields))
		{
			if (($arCourseFields['ACTIVE_TO'] === NULL) || ($arCourseFields['ACTIVE_TO'] === ''))
				$arFieldsToDb['ACTIVE_TO'] = 'NULL';
			else
				$arFieldsToDb['ACTIVE_TO'] = $DB->CharToDateFunction($arCourseFields['ACTIVE_TO']);
		}

		if (array_key_exists('RATING', $arCourseFields))
			$arFieldsToDb['RATING'] = "'" . $DB->ForSql($arCourseFields['RATING']) . "'";

		if (array_key_exists('RATING_TYPE', $arCourseFields))
		{
			if ($arCourseFields['RATING_TYPE'] === NULL)
				$arFieldsToDb['RATING_TYPE'] = 'NULL';
			else
				$arFieldsToDb['RATING_TYPE'] = "'" . $DB->ForSql($arCourseFields['RATING_TYPE']) . "'";
		}

		if (array_key_exists('SCORM', $arCourseFields))
			$arFieldsToDb['SCORM'] = "'" . $DB->ForSql($arCourseFields['SCORM']) . "'";

		// Does need update for some fields?
		if (count($arFieldsToDb) > 0)
		{
			$rc = $DB->Update ('b_learn_course', $arFieldsToDb,
				"WHERE ID='" . (int) ($courseId + 0) . "'", __LINE__, false,
				false);	// we must halt on errors due to bug in CDatabase::Update();

			// reload cache of LINKED_LESSON_ID -> COURSE_ID
			self::GetCourseToLessonMap_ReloadCache();

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

	CLearnCacheOfLessonTreeComponent::MarkAsDirty();

	foreach(GetModuleEvents('learning', 'OnAfterLessonUpdate', true) as $arEvent)
		ExecuteModuleEventEx($arEvent, array(&$arFields, $id));

	BitrixLearningIntegrationSearch::indexLesson($id);

	return true;
}