ILIAS  trunk Revision v12.0_alpha-377-g3641b37b9db
class.ilCourseImporter.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=0);
25{
26 public const ENTITY_MAIN = 'crs';
27 public const ENTITY_OBJECTIVE = 'objectives';
28
29 private ?ilObjCourse $course = null;
30 private array $final_processing_info = [];
31
32 protected ilLogger $logger;
33 protected ilDBInterface $db;
34
35 public function __construct()
36 {
37 global $DIC;
38 $this->logger = $DIC->logger()->crs();
39 $this->db = $DIC->database();
40 }
41
42 public function init(): void
43 {
44 }
45
47 public function importXmlRepresentation(
48 string $a_entity,
49 string $a_id,
50 string $a_xml,
51 ilImportMapping $a_mapping
52 ): void {
53 if ($new_id = $a_mapping->getMapping('components/ILIAS/Container', 'objs', $a_id)) {
54 $refs = ilObject::_getAllReferences((int) $new_id);
55 $this->course = ilObjectFactory::getInstanceByRefId((int) end($refs), false);
56 } // Mapping for containers without subitems
57 elseif ($new_id = $a_mapping->getMapping('components/ILIAS/Container', 'refs', '0')) {
58 $this->course = ilObjectFactory::getInstanceByRefId((int) $new_id, false);
59 } elseif (!$this->course instanceof ilObjCourse) {
60 $this->course = new ilObjCourse();
61 $this->course->create();
62 }
63
64 if ($a_entity == self::ENTITY_OBJECTIVE) {
65 $this->addFinalProcessingInfo($this->course, $a_entity, $a_xml);
66
67 // import learning objectives => without materials and fixed questions.
68 // These are handled in afterContainerImportProcessing
69 $parser = new ilLOXmlParser($this->course, $a_xml);
70 $parser->setMapping($a_mapping);
71 $parser->parse();
72 (new \ILIAS\Conditions\Export\Repository($this->db))->updateCourseValuesResultRangePercentage(
73 $this->course->getId(),
74 $a_mapping
75 );
76 return;
77 }
78
79 try {
80 $parser = new ilCourseXMLParser($this->course);
81 $parser->setXMLContent($a_xml);
82 $parser->startParsing();
83
84 // set course offline
85 $this->course->setOfflineStatus(true);
86 $this->course->update();
87
88 $a_mapping->addMapping('components/ILIAS/Course', 'crs', $a_id, (string) $this->course->getId());
89 $a_mapping->addMapping('components/ILIAS/AdvancedMetaData', 'parent', $a_id, (string) $this->course->getId());
90
91 // workaround for ilImportContainer::createDummy which creates Metadata via create(true)
92 $this->course->deleteMetaData();
93 $a_mapping->addMapping(
94 'components/ILIAS/MetaData',
95 'md',
96 $a_id . ':0:crs',
97 $this->course->getId() . ':0:crs'
98 );
99 } catch (ilSaxParserException|Exception $e) {
100 $this->logger->error('Parsing failed with message, "' . $e->getMessage() . '".');
101 }
102 }
103
104 public function afterContainerImportProcessing(\ilImportMapping $mapping): void
105 {
106 foreach ($this->final_processing_info as $info) {
107 // import learning objectives
108 $parser = new ilLOXmlParser($info['course'], $info['xml']);
109 $parser->setMapping($mapping);
110 $parser->parseObjectDependencies();
111 return;
112 }
113 }
114
115 protected function addFinalProcessingInfo($a_course, $a_entity, $a_xml): void
116 {
117 $this->final_processing_info[] = array(
118 'course' => $a_course,
119 'entity' => $a_entity,
120 'xml' => $a_xml
121 );
122 }
123}
afterContainerImportProcessing(\ilImportMapping $mapping)
importXmlRepresentation(string $a_entity, string $a_id, string $a_xml, ilImportMapping $a_mapping)
@noinspection PhpFieldAssignmentTypeMismatchInspection
addFinalProcessingInfo($a_course, $a_entity, $a_xml)
Class ilLOXmlWriter.
Component logger with individual log levels by component id.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static getInstanceByRefId(int $ref_id, bool $stop_on_error=true)
get an instance of an Ilias object by reference id
static _getAllReferences(int $id)
get all reference ids for object ID
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Xml importer class.
$info
Definition: entry_point.php:21
Interface ilDBInterface.
if(!file_exists('../ilias.ini.php'))
global $DIC
Definition: shib_login.php:26