• Модуль: learning
  • Путь к файлу: ~/bitrix/modules/learning/classes/general/import.php
  • Класс: CCourseImport
  • Вызов: CCourseImport::CreateCourse
protected function CreateCourse()
{
	global $APPLICATION;

	if ($this->LAST_ERROR <> '')
		return false;

	if (!$title = $this->objXML->SelectNodes("/manifest/organizations/organization/item/title"))
	{
		$this->LAST_ERROR = GetMessage("LEARNING_BAD_NAME");
		return false;
	}

	$arFields = Array(
		"NAME" => $title->content,
		"SITE_ID" => $this->arSITE_ID,
	);

	$course = new CCourse;
	$this->COURSE_ID = $course->Add($arFields);
	$res = ($this->COURSE_ID);

	if(!$res)
	{
		if($e = $APPLICATION->GetException())
			$this->LAST_ERROR = $e->GetString();
		return false;
	}

	$r = new CDataXML();
	if (!$r->Load($this->package_dir."/res1.xml"))
		return false;

	if (!$data = $r->SelectNodes("/coursetoc/"))
		return false;

	$ar = $data->__toArray();
	$arFields =  $this->_MakeFields($ar);

	$res = $course->Update($this->COURSE_ID, $arFields);

	if(!$res)
	{
		if($e = $APPLICATION->GetException())
			$this->LAST_ERROR = $e->GetString();
		return false;
	}

	CheckDirPath($_SERVER["DOCUMENT_ROOT"]."/".(COption::GetOptionString("main", "upload_dir", "upload"))."/learning/".$this->COURSE_ID);
	CLearnHelper::CopyDirFiles(
		$this->package_dir."/resources/res1", 
		$_SERVER["DOCUMENT_ROOT"] . "/" . (COption::GetOptionString("main", "upload_dir", "upload")) . "/learning/" . $this->COURSE_ID . "/res1",
		true);

	return true;
}