ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilLearningModuleImporter.php
Go to the documentation of this file.
1<?php
2
20
27{
29 protected array $qtis;
32 protected ilLogger $log;
33
34 public function init(): void
35 {
36 $this->ds = new ilLearningModuleDataSet();
37 $this->ds->setDSPrefix("ds");
38
39 $this->log = ilLoggerFactory::getLogger('lm');
40
41 $this->config = $this->getImport()->getConfig("components/ILIAS/LearningModule");
42 if ($this->config->getTranslationImportMode()) {
43 $this->ds->setTranslationImportMode(
44 $this->config->getTranslationLM(),
45 $this->config->getTranslationLang()
46 );
47 $cop_config = $this->getImport()->getConfig("components/ILIAS/COPage");
48 $cop_config->setUpdateIfExists(true);
49 $cop_config->setForceLanguage($this->config->getTranslationLang());
50 $cop_config->setReuseOriginallyExportedMedia(true);
51 $cop_config->setSkipInternalLinkResolve(true);
52
53 $mob_config = $this->getImport()->getConfig("components/ILIAS/MediaObjects");
54 $mob_config->setUsePreviousImportIds(true);
55 }
56 $this->reading_time_manager = new ReadingTimeManager();
57 }
58
59 public function importXmlRepresentation(
60 string $a_entity,
61 string $a_id,
62 string $a_xml,
63 ilImportMapping $a_mapping
64 ): void {
65 $this->log->debug("import XML Representation");
66
67 // case i container
68 if ($new_id = $a_mapping->getMapping('components/ILIAS/Container', 'objs', $a_id)) {
69 $newObj = ilObjectFactory::getInstanceByObjId($new_id, false);
70 $newObj->createLMTree();
71 $this->log->debug("got mapping, new id is: " . $new_id);
72 }
73
74 // in the new version (5.1) we are also here, but the following file should not exist
75 // if being exported with 5.1 or higher
76 $xml_file = $this->getImportDirectory() . '/' . basename($this->getImportDirectory()) . '.xml';
77
78 // old school import
79 // currently this means we got a container and mapping, too, since
80 // for single lms the processing in ilObjContentObjectGUI->importFileObject is used
81 // (this should be streamlined, see glossary)
82 if (file_exists($xml_file)) {
83 throw new ilLMOldExportFileException("This file seems to be from ILIAS version 5.0.x or lower. Import is not supported anymore.");
84 } else { // new import version (does mapping, too)
85 $this->log->debug("create ilDataSetIportParser instance");
86 $parser = new ilDataSetImportParser(
87 $a_entity,
88 $this->getSchemaVersion(),
89 $a_xml,
90 $this->ds,
91 $a_mapping
92 );
93 }
94
95 // import qti stuff
96 $this->log->debug("import qti data");
97 $qti_file = $this->getImportDirectory() . '/qti.xml';
98 $this->qtis = array();
99 if (is_file($qti_file)) {
100 $qtiParser = new ilQTIParser(
101 $this->getImportDirectory(),
102 $qti_file,
104 0,
105 []
106 );
107 $result = $qtiParser->startParsing();
108 $founditems = &$qtiParser->getFoundItems();
109 $testObj = new ilObjTest(0, true);
110 if (count($founditems) > 0) {
111 $qtiParser = new ilQTIParser(
112 $this->getImportDirectory(),
113 $qti_file,
115 0,
116 []
117 );
118 $qtiParser->setTestObject($testObj);
119 $result = $qtiParser->startParsing();
120 $this->qtis = array_merge($this->qtis, $qtiParser->getImportMapping());
121 }
122 }
123 }
124
125 public function finalProcessing(ilImportMapping $a_mapping): void
126 {
127 $pg_map = $a_mapping->getMappingsOfEntity("components/ILIAS/LearningModule", "pg");
128
129 $this->log->debug("pg map entries: " . count($pg_map));
130 foreach ($pg_map as $pg_id) {
131 $lm_id = ilLMPageObject::_lookupContObjID($pg_id);
132 ilLMPage::_writeParentId("lm", $pg_id, $lm_id);
133 $this->log->debug("write parent id, pg id: " . $pg_id . ", lm id: " . $lm_id);
134 }
135
136 // header footer page
137 foreach ($a_mapping->getMappingsOfEntity("components/ILIAS/LearningModule", "lm_header_page") as $old_id => $dummy) {
138 $new_page_id = (int) $a_mapping->getMapping("components/ILIAS/LearningModule", "pg", $old_id);
139 if ($new_page_id > 0) {
140 $lm_id = ilLMPageObject::_lookupContObjID($new_page_id);
141 ilObjLearningModule::writeHeaderPage($lm_id, $new_page_id);
142 }
143 }
144 foreach ($a_mapping->getMappingsOfEntity("components/ILIAS/LearningModule", "lm_footer_page") as $old_id => $dummy) {
145 $new_page_id = (int) $a_mapping->getMapping("components/ILIAS/LearningModule", "pg", $old_id);
146 if ($new_page_id > 0) {
147 $lm_id = ilLMPageObject::_lookupContObjID($new_page_id);
148 ilObjLearningModule::writeFooterPage($lm_id, $new_page_id);
149 }
150 }
151
152
153 $link_map = $a_mapping->getMappingsOfEntity("components/ILIAS/LearningModule", "link");
154 $pages = $a_mapping->getMappingsOfEntity("components/ILIAS/COPage", "pgl");
155 foreach ($pages as $p) {
156 $id = explode(":", $p);
157 if (count($id) == 3) {
158 if (ilPageObject::_exists($id[0], $id[1], $id[2], true)) {
159 $new_page = ilPageObjectFactory::getInstance($id[0], $id[1], 0, $id[2]);
160 $new_page->buildDom();
161
162 // fix question references
163 $updated = $new_page->resolveQuestionReferences($this->qtis);
164
165 // in translation mode use link mapping to fix internal links
166 //$a_mapping->addMapping("components/ILIAS/LearningModule", "link",
167 if ($this->config->getTranslationImportMode()) {
168 $il = $new_page->resolveIntLinks($link_map);
169 if ($il) {
170 $updated = true;
171 }
172 }
173
174 if ($updated) {
175 $new_page->update(false, true);
176 }
177 }
178 }
179 }
180
181 // assign style
182 /*
183 $alls_map = $a_mapping->getMappingsOfEntity("components/ILIAS/LearningModule", "lm_style");
184 foreach ($alls_map as $new_lm_id => $old_style_id) {
185 $new_style_id = (int) $a_mapping->getMapping("components/ILIAS/Style", "sty", $old_style_id);
186 if ($new_lm_id > 0 && $new_style_id > 0) {
187 $lm = new ilObjLearningModule($new_lm_id, false);
188 $lm->writeStyleSheetId($new_style_id);
189 }
190 }*/
191
192 // menu item ref ids
193 $ref_mapping = $a_mapping->getMappingsOfEntity('components/ILIAS/Container', 'refs');
194 $lm_map = $a_mapping->getMappingsOfEntity("components/ILIAS/LearningModule", "lm");
195 foreach ($lm_map as $old_lm_id => $new_lm_id) {
196 ilLMMenuEditor::fixImportMenuItems($new_lm_id, $ref_mapping);
197 }
198
199 // typical reading time
200 $lm_map = $a_mapping->getMappingsOfEntity("components/ILIAS/LearningModule", "lm");
201 foreach ($lm_map as $old_lm_id => $new_lm_id) {
202 $this->reading_time_manager->updateReadingTime($new_lm_id);
203 }
204 }
205}
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Import configuration class parent class.
getMapping(string $a_comp, string $a_entity, string $a_old_id)
getMappingsOfEntity(string $a_comp, string $a_entity)
static fixImportMenuItems(int $new_lm_id, array $ref_mapping)
static _lookupContObjID(int $a_id)
get learning module id for lm object
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
LearningModule Data set class.
finalProcessing(ilImportMapping $a_mapping)
importXmlRepresentation(string $a_entity, string $a_id, string $a_xml, ilImportMapping $a_mapping)
static getLogger(string $a_component_id)
Get component logger.
Component logger with individual log levels by component id.
static writeFooterPage(int $a_lm_id, int $a_page_id)
static writeHeaderPage(int $a_lm_id, int $a_page_id)
static getInstanceByObjId(?int $obj_id, bool $stop_on_error=true)
get an instance of an Ilias object by object id
static getInstance(string $a_parent_type, int $a_id=0, int $a_old_nr=0, string $a_lang="-")
Get page object instance.
static _exists(string $a_parent_type, int $a_id, string $a_lang="", bool $a_no_cache=false)
Checks whether page exists.
static _writeParentId(string $a_parent_type, int $a_pg_id, int $a_par_id)
Xml importer class.