ILIAS  release_7 Revision v7.30-3-g800a261c036
class.ilCmiXapiImporter.php
Go to the documentation of this file.
1<?php
2
3/* Copyright (c) 1998-2019 ILIAS open source, Extended GPL, see docs/LICENSE */
4
5
16{
18 private $_moduleProperties = [];
19
21 public $manifest = [];
22
24 private $_dataset;
25
27 private $_cmixObj;
28
30 private $_newId = null;
31
33 private $_entity;
34
37
40
42 private $_mapping;
43
45 private $_hasContent = false;
46
48 private $_relWebDir = 'lm_data/lm_';
49
51 private $_relImportDir = '';
52
54 private $_isSingleImport = false;
55
59 public function __construct()
60 {
61 require_once "./Modules/CmiXapi/classes/class.ilCmiXapiDataSet.php";
62 $this->_dataset = new ilCmiXapiDataSet();
63 $this->_dataset->_cmixSettingsProperties['Title'] = '';
64 $this->_dataset->_cmixSettingsProperties['Description'] = '';
65 //todo: at the moment restricted to one module in xml file, extend?
66 }
67
78 public function importXmlRepresentation($a_entity, $a_id, $a_xml, $a_mapping) : void
79 {
80 global $DIC;
82 $this->_entity = $a_entity;
83 $this->_import_objId = $a_id;
84 $this->_import_dirname = $a_xml;
85 $this->_mapping = $a_mapping;
86
87 if (false === ($this->_newId = $a_mapping->getMapping('Services/Container', 'objs', $this->_import_objId))) {
88 $this->prepareSingleObject();
90 $this->_isSingleImport = true;
91 } else {
92 $this->prepareContainerObject();
94 }
95 $this->prepareLocalSourceStorage();
96 $this->parseXmlFileProperties();
97 $this->updateNewObj();
98 }
99
104 private function prepareSingleObject()
105 {
106 global $DIC;
109 // create new cmix object
110 $this->_cmixObj = new ilObjCmiXapi();
111 // set type of questionpool object
112 $this->_cmixObj->setType('cmix');
113 // set title of questionpool object to "dummy"
114 $this->_cmixObj->setTitle("dummy");
115 // set description of questionpool object
116 $this->_cmixObj->setDescription("test import");
117 // create the questionpool class in the ILIAS database (object_data table)
118 $this->_cmixObj->create(true);
119 $this->_newId = $this->_cmixObj->getId();
120 $this->_mapping->addMapping('Modules/CmiXapi', 'cmix', $this->_import_objId, $this->_newId);
121 //$this->getImport();
122 $this->_cmixObj->update();
123
124 return $this;
125 }
126
130 private function prepareContainerObject() : void
131 {
132 global $DIC;
135 // Container import => test object already created
136 include_once "./Modules/Test/classes/class.ilObjTest.php";
137 $this->_import_dirname = $this->getImportDirectoryContainer();
138
139 if ($this->_newId = $this->_mapping->getMapping('Services/Container', 'objs', $this->_import_objId)) {
140 // container content
141 $this->_cmixObj = ilObjectFactory::getInstanceByObjId($this->_newId, false);
142 //$_SESSION['tst_import_subdir'] = $this->getImportPackageName();
143 $this->_cmixObj->save(); // this generates test id first time
144 //var_dump([$this->getImportDirectory(), $this->_import_dirname]); exit;
145 $this->_mapping->addMapping("Modules/CmiXapi", "cmix", $this->_import_objId, $this->_newId);
146 }
147 $this->_cmixObj->save();
148 $this->_cmixObj->update();
149 }
150
157 private function prepareLocalSourceStorage()
158 {
159 global $DIC;
162 if (true === (bool) $DIC->filesystem()->temp()->has($this->_relImportDir . '/content.zip')) {
163 $this->_hasContent = true;
164 $this->_relWebDir = $this->_relWebDir . $this->_cmixObj->getId();
165 if (false === (bool) $DIC->filesystem()->web()->has($this->_relWebDir)) {
166 $DIC->filesystem()->web()->createDir($this->_relWebDir);
167 $DIC->filesystem()->web()->put($this->_relWebDir . '/content.zip', $DIC->filesystem()->temp()->read($this->_relImportDir . '/content.zip'));
168 $webDataDir = ilUtil::getWebspaceDir();
169 ilUtil::unzip($webDataDir . "/" . $this->_relWebDir . "/content.zip");
170 $DIC->filesystem()->web()->delete($this->_relWebDir . '/content.zip');
171 }
172 }
173 return $this;
174 }
175
182 private function parseXmlFileProperties()
183 {
184 global $DIC;
186 $xmlRoot = null;
187 $xml = $DIC->filesystem()->temp()->readStream($this->_relImportDir . '/properties.xml');
188 if ($xml != false) {
189 $xmlRoot = simplexml_load_string($xml);
190 }
191 foreach ($this->_dataset->_cmixSettingsProperties as $key => $property) {
192 $this->_moduleProperties[$key] = trim($xmlRoot->$key->__toString());
193 }
194 return $this;
195 }
196
201 private function updateNewObj()
202 {
203 global $DIC;
204 $this->_cmixObj->setTitle($this->_moduleProperties['Title'] . " " . $DIC->language()->txt("copy_of_suffix"));
205 $this->_cmixObj->setDescription($this->_moduleProperties['Description']);
206 $this->_cmixObj->update();
207
208 if ($this->_moduleProperties['LrsTypeId']) {
209 $this->_cmixObj->setLrsTypeId((int) $this->_moduleProperties['LrsTypeId']);
210 $this->_cmixObj->setLrsType(new ilCmiXapiLrsType((int) $this->_moduleProperties['LrsTypeId']));
211 }
212 $this->_cmixObj->setContentType($this->_moduleProperties['ContentType']);
213 $this->_cmixObj->setSourceType($this->_moduleProperties['SourceType']);
214 $this->_cmixObj->setActivityId($this->_moduleProperties['ActivityId']);
215 $this->_cmixObj->setInstructions($this->_moduleProperties['Instructions']);
216 // $this->_cmixObj->setOfflineStatus($this->_moduleProperties['OfflineStatus']);
217 $this->_cmixObj->setLaunchUrl($this->_moduleProperties['LaunchUrl']);
218 $this->_cmixObj->setAuthFetchUrlEnabled($this->_moduleProperties['AuthFetchUrl']);
219 $this->_cmixObj->setLaunchMethod($this->_moduleProperties['LaunchMethod']);
220 $this->_cmixObj->setLaunchMode($this->_moduleProperties['LaunchMode']);
221 $this->_cmixObj->setMasteryScore($this->_moduleProperties['MasteryScore']);
222 $this->_cmixObj->setKeepLpStatusEnabled($this->_moduleProperties['KeepLp']);
223 $this->_cmixObj->setPrivacyIdent($this->_moduleProperties['PrivacyIdent']);
224 $this->_cmixObj->setPrivacyName($this->_moduleProperties['PrivacyName']);
225 $this->_cmixObj->setUserPrivacyComment($this->_moduleProperties['UsrPrivacyComment']);
226 $this->_cmixObj->setStatementsReportEnabled($this->_moduleProperties['ShowStatements']);
227 $this->_cmixObj->setXmlManifest($this->_moduleProperties['XmlManifest']);
228 $this->_cmixObj->setVersion($this->_moduleProperties['Version']);
229 $this->_cmixObj->setHighscoreEnabled($this->_moduleProperties['HighscoreEnabled']);
230 $this->_cmixObj->setHighscoreAchievedTS($this->_moduleProperties['HighscoreAchievedTs']);
231 $this->_cmixObj->setHighscorePercentage($this->_moduleProperties['HighscorePercentage']);
232 $this->_cmixObj->setHighscoreWtime($this->_moduleProperties['HighscoreWtime']);
233 $this->_cmixObj->setHighscoreOwnTable($this->_moduleProperties['HighscoreOwnTable']);
234 $this->_cmixObj->setHighscoreTopTable($this->_moduleProperties['HighscoreTopTable']);
235 $this->_cmixObj->setHighscoreTopNum($this->_moduleProperties['HighscoreTopNum']);
236 $this->_cmixObj->setBypassProxyEnabled($this->_moduleProperties['BypassProxy']);
237 $this->_cmixObj->setOnlyMoveon($this->_moduleProperties['OnlyMoveon']);
238 $this->_cmixObj->setAchieved($this->_moduleProperties['Achieved']);
239 $this->_cmixObj->setAnswered($this->_moduleProperties['Answered']);
240 $this->_cmixObj->setCompleted($this->_moduleProperties['Completed']);
241 $this->_cmixObj->setFailed($this->_moduleProperties['Failed']);
242 $this->_cmixObj->setInitialized($this->_moduleProperties['Initialized']);
243 $this->_cmixObj->setPassed($this->_moduleProperties['Passed']);
244 $this->_cmixObj->setProgressed($this->_moduleProperties['Progressed']);
245 $this->_cmixObj->setSatisfied($this->_moduleProperties['Satisfied']);
246 $this->_cmixObj->setTerminated($this->_moduleProperties['Terminated']);
247 $this->_cmixObj->setHideData($this->_moduleProperties['HideData']);
248 $this->_cmixObj->setTimestamp($this->_moduleProperties['Timestamp']);
249 $this->_cmixObj->setDuration($this->_moduleProperties['Duration']);
250 $this->_cmixObj->setNoSubstatements($this->_moduleProperties['NoSubstatements']);
251 $this->_cmixObj->setPublisherId((string) $this->_moduleProperties['PublisherId']);
252// $this->_cmixObj->setAnonymousHomepage($this->_moduleProperties['AnonymousHomepage']);
253 $this->_cmixObj->setMoveOn((string) $this->_moduleProperties['MoveOn']);
254 $this->_cmixObj->setLaunchParameters((string) $this->_moduleProperties['LaunchParameters']);
255 $this->_cmixObj->setEntitlementKey((string) $this->_moduleProperties['EntitlementKey']);
256 $this->_cmixObj->setSwitchToReviewEnabled($this->_moduleProperties['SwitchToReview']);
257 $this->_cmixObj->save();
258 $this->_cmixObj->updateMetaData();
259
260 return $this;
261 }
262
269 private function deleteImportDirectiry()
270 {
271 global $DIC;
272 $DIC->filesystem()->temp()->delete($this->_relImportDir);
273 return $this;
274 }
275
280 private function getImportDirectorySingle()
281 {
282 $importTempDir = $this->getImportDirectory();
283 $dirArr = array_reverse(explode('/', $importTempDir));
284 $this->_relImportDir = $dirArr[1] . '/' . $dirArr[0];
285 return $this;
286 }
287
293 {
294 $importTempDir = $this->getImportDirectory();
295 $dirArr = array_reverse(explode('/', $importTempDir));
296 $this->_relImportDir = $dirArr[3] . '/' . $dirArr[2] . '/' . $dirArr[1] . '/' . $dirArr[0];
297 return $this;
298 /*
299 $dir = $this->getImportDirectory();
300 $dir = dirname($dir);
301 return $dir;
302 */
303 }
304
306 public function init() : void
307 {
308 }
309
313 public function __destruct()
314 {
315 if (true === $this->_isSingleImport) {
316 $this->deleteImportDirectiry();
317 }
318 }
319} // EOF class
An exception for terminatinating execution or to throw for unit testing.
getImportDirectorySingle()
Gets the relative path to the Filesystem::temp Folder.
getImportDirectoryContainer()
Gets the relative path to the Filesystem::temp Folder.
__construct()
ilCmiXapiImporter constructor.
__destruct()
if single import then deleteImportDirectiry
static getInstanceByObjId($a_obj_id, $stop_on_error=true)
get an instance of an Ilias object by object id
static getWebspaceDir($mode="filesystem")
get webspace directory
static unzip(string $path_to_zip_file, bool $overwrite_existing=false, bool $unpack_flat=false)
Xml importer class.
importXmlRepresentation($a_entity, $a_id, $a_xml, $a_mapping)
Import xml representation.
getImportDirectory()
Get import directory.
global $DIC
Definition: goto.php:24
$xml
Definition: metadata.php:332