ILIAS  release_8 Revision v8.24
class.ilCourseImporter.php
Go to the documentation of this file.
1<?php
2
3declare(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
34 public function __construct()
35 {
36 global $DIC;
37
38 $this->logger = $DIC->logger()->crs();
39 }
40
41 public function init(): void
42 {
43 }
44
46 public function importXmlRepresentation(
47 string $a_entity,
48 string $a_id,
49 string $a_xml,
50 ilImportMapping $a_mapping
51 ): void {
52 if ($new_id = $a_mapping->getMapping('Services/Container', 'objs', $a_id)) {
53 $refs = ilObject::_getAllReferences((int) $new_id);
54 $this->course = ilObjectFactory::getInstanceByRefId((int) end($refs), false);
55 } // Mapping for containers without subitems
56 elseif ($new_id = $a_mapping->getMapping('Services/Container', 'refs', '0')) {
57 $this->course = ilObjectFactory::getInstanceByRefId((int) $new_id, false);
58 } elseif (!$this->course instanceof ilObjCourse) {
59 $this->course = new ilObjCourse();
60 $this->course->create(true);
61 }
62
63 if ($a_entity == self::ENTITY_OBJECTIVE) {
64 $this->addFinalProcessingInfo($this->course, $a_entity, $a_xml);
65
66 // import learning objectives => without materials and fixed questions.
67 // These are handled in afterContainerImportProcessing
68 $parser = new ilLOXmlParser($this->course, $a_xml);
69 $parser->setMapping($a_mapping);
70 $parser->parse();
71 return;
72 }
73
74 try {
75 $parser = new ilCourseXMLParser($this->course);
76 $parser->setXMLContent($a_xml);
77 $parser->startParsing();
78
79 // set course offline
80 $this->course->setOfflineStatus(true);
81 $this->course->update();
82
83 $a_mapping->addMapping('Modules/Course', 'crs', $a_id, (string) $this->course->getId());
84 } catch (ilSaxParserException|Exception $e) {
85 $this->logger->error('Parsing failed with message, "' . $e->getMessage() . '".');
86 }
87 }
88
89 public function afterContainerImportProcessing(\ilImportMapping $mapping): void
90 {
91 foreach ($this->final_processing_info as $info) {
92 // import learning objectives
93 $parser = new ilLOXmlParser($info['course'], $info['xml']);
94 $parser->setMapping($mapping);
95 $parser->parseObjectDependencies();
96 return;
97 }
98 }
99
100 protected function addFinalProcessingInfo($a_course, $a_entity, $a_xml): void
101 {
102 $this->final_processing_info[] = array(
103 'course' => $a_course,
104 'entity' => $a_entity,
105 'xml' => $a_xml
106 );
107 }
108}
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
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)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
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
SaxParserException thrown by ilSaxParser if property throwException is set.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
if(!file_exists(getcwd() . '/ilias.ini.php'))
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Definition: confirmReg.php:20
global $DIC
Definition: feed.php:28