ILIAS  release_7 Revision v7.30-3-g800a261c036
ilCmiXapiContentUploadImporter Class Reference
+ Collaboration diagram for ilCmiXapiContentUploadImporter:

Public Member Functions

 __construct (ilObjCmiXapi $object)
 ilCmiXapiContentUploadImporter constructor. More...
 
 ensureCreatedObjectDirectory ()
 
 importServerFile ($serverFile)
 
 importFormUpload (ilFileInputGUI $uploadInput)
 
 getWebDataDirRelativeObjectDirectory ()
 

Data Fields

const RELATIVE_CONTENT_DIRECTORY_NAMEBASE = 'lm_data/lm_'
 
const RELATIVE_XSD_DIRECTORY = 'Modules/CmiXapi/xml/contentschema'
 
const IMP_FILE_EXTENSION_XML = 'xml'
 
const IMP_FILE_EXTENSION_ZIP = 'zip'
 
const CMI5_XML = 'cmi5.xml'
 
const CMI5_XSD = 'cmi5_v1_CourseStructure.xsd'
 
const TINCAN_XML = 'tincan.xml'
 
const TINCAN_XSD = 'tincan.xsd'
 

Protected Member Functions

 sanitizeObjectDirectory ()
 
 handleFile (string $serverFile)
 
 getUpload ($uploadFilePath)
 
 handleUpload (FileUploadResult $uploadResult)
 
 handleXmlFile ($xmlFilePath)
 
 handleXmlFileFromUpload ($xmlFileName, $xmlFilePath)
 
 validateXmlFile (DOMDocument $dom, $xsdFilePath)
 
 handleZipContentUpload ($uploadFilePath)
 
 getAbsoluteObjectDirectory ()
 
 fetchFileExtension (FileUploadResult $uploadResult)
 
 hasStoredContentXml ()
 
 getStoredContentXml ()
 
 getXsdFilePath ($xsdFileName)
 
 initObjectFromCmi5Xml ($dom)
 
 initObjectFromTincanXml ($dom)
 

Protected Attributes

 $object
 

Static Protected Attributes

static $CONTENT_XML_FILENAMES
 
static $CONTENT_XSD_FILENAMES
 

Private Member Functions

 generateActivityId ($publisherId)
 

Detailed Description

Definition at line 18 of file class.ilCmiXapiContentUploadImporter.php.

Constructor & Destructor Documentation

◆ __construct()

ilCmiXapiContentUploadImporter::__construct ( ilObjCmiXapi  $object)

ilCmiXapiContentUploadImporter constructor.

Parameters
ilObjCmiXapi$object

Definition at line 57 of file class.ilCmiXapiContentUploadImporter.php.

References $object.

Member Function Documentation

◆ ensureCreatedObjectDirectory()

ilCmiXapiContentUploadImporter::ensureCreatedObjectDirectory ( )
Exceptions

ILIAS\Filesystem\Exception\IOException

Definition at line 65 of file class.ilCmiXapiContentUploadImporter.php.

66 {
67 global $DIC; /* @var \ILIAS\DI\Container $DIC */
68
69 if (!$DIC->filesystem()->web()->has($this->getWebDataDirRelativeObjectDirectory())) {
70 $DIC->filesystem()->web()->createDir($this->getWebDataDirRelativeObjectDirectory());
71 }
72 }
global $DIC
Definition: goto.php:24

References $DIC, and getWebDataDirRelativeObjectDirectory().

Referenced by importFormUpload(), and importServerFile().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ fetchFileExtension()

ilCmiXapiContentUploadImporter::fetchFileExtension ( FileUploadResult  $uploadResult)
protected
Parameters
FileUploadResult$uploadResult
Returns
mixed

Definition at line 306 of file class.ilCmiXapiContentUploadImporter.php.

307 {
308 return pathinfo($uploadResult->getName(), PATHINFO_EXTENSION);
309 }

Referenced by handleUpload().

+ Here is the caller graph for this function:

◆ generateActivityId()

ilCmiXapiContentUploadImporter::generateActivityId (   $publisherId)
private

Definition at line 446 of file class.ilCmiXapiContentUploadImporter.php.

447 {
448 global $DIC;
449 $objId = $this->object->getId();
450 $activityId = "https://ilias.de/cmi5/activityid/" . (new \Ramsey\Uuid\UuidFactory())->uuid3(ilCmiXapiUser::getIliasUuid(), $objId . '-' . $publisherId);
451 return $activityId;
452 }
$objId
Definition: xapitoken.php:39

References $DIC, $objId, and ilCmiXapiUser\getIliasUuid().

Referenced by initObjectFromCmi5Xml().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getAbsoluteObjectDirectory()

ilCmiXapiContentUploadImporter::getAbsoluteObjectDirectory ( )
protected
Returns
string

Definition at line 283 of file class.ilCmiXapiContentUploadImporter.php.

284 {
285 $dirs = [
286 ILIAS_ABSOLUTE_PATH,
289 ];
290
291 return implode(DIRECTORY_SEPARATOR, $dirs);
292 }
static getWebspaceDir($mode="filesystem")
get webspace directory

References getWebDataDirRelativeObjectDirectory(), and ilUtil\getWebspaceDir().

Referenced by getStoredContentXml(), and handleZipContentUpload().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getStoredContentXml()

ilCmiXapiContentUploadImporter::getStoredContentXml ( )
protected
Returns
string

Definition at line 322 of file class.ilCmiXapiContentUploadImporter.php.

323 {
324 global $DIC; /* @var \ILIAS\DI\Container $DIC */
325
326 foreach (self::$CONTENT_XML_FILENAMES as $xmlFileName) {
327 $xmlFilePath = $this->getWebDataDirRelativeObjectDirectory() . DIRECTORY_SEPARATOR . $xmlFileName;
328
329 if ($DIC->filesystem()->web()->has($xmlFilePath)) {
330 return $this->getAbsoluteObjectDirectory() . DIRECTORY_SEPARATOR . $xmlFileName;
331 }
332 }
333
334 return '';
335 }

References $DIC, getAbsoluteObjectDirectory(), and getWebDataDirRelativeObjectDirectory().

Referenced by handleFile(), handleUpload(), and hasStoredContentXml().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getUpload()

ilCmiXapiContentUploadImporter::getUpload (   $uploadFilePath)
protected
Parameters
$uploadFilePath
Returns
FileUploadResult
Exceptions

ILIAS\FileUpload\Exception\IllegalStateException

Exceptions
ilCmiXapiInvalidUploadContentException

Definition at line 148 of file class.ilCmiXapiContentUploadImporter.php.

149 {
150 global $DIC; /* @var \ILIAS\DI\Container $DIC */
151
152 if ($DIC->upload()->hasUploads()) {
153 if (!$DIC->upload()->hasBeenProcessed()) {
154 $DIC->upload()->process();
155 }
156
157 /* @var FileUploadResult $result */
158
159 $results = $DIC->upload()->getResults();
160
161 if (isset($results[$uploadFilePath])) {
162 $result = $results[$uploadFilePath];
163
164 if ($result->getStatus() == FileUploadProcessingStatus::OK) {
165 return $result;
166 }
167
169 'upload processing failed with message ' .
170 '"' . $result->getStatus()->getMessage() . '"'
171 );
172 }
173
174 throw new ilCmiXapiInvalidUploadContentException('upload lost during processing!');
175 }
176
177 throw new ilCmiXapiInvalidUploadContentException('no upload provided!');
178 }
$result
$results

References $DIC, $result, and $results.

Referenced by importFormUpload().

+ Here is the caller graph for this function:

◆ getWebDataDirRelativeObjectDirectory()

ilCmiXapiContentUploadImporter::getWebDataDirRelativeObjectDirectory ( )
Returns
string

Definition at line 297 of file class.ilCmiXapiContentUploadImporter.php.

298 {
299 return self::RELATIVE_CONTENT_DIRECTORY_NAMEBASE . $this->object->getId();
300 }

Referenced by ensureCreatedObjectDirectory(), getAbsoluteObjectDirectory(), getStoredContentXml(), and sanitizeObjectDirectory().

+ Here is the caller graph for this function:

◆ getXsdFilePath()

ilCmiXapiContentUploadImporter::getXsdFilePath (   $xsdFileName)
protected
Parameters
string$xsdFileName
Returns
string

Definition at line 341 of file class.ilCmiXapiContentUploadImporter.php.

342 {
343 return ILIAS_ABSOLUTE_PATH . DIRECTORY_SEPARATOR . self::RELATIVE_XSD_DIRECTORY . DIRECTORY_SEPARATOR . $xsdFileName;
344 }

Referenced by handleXmlFile(), and handleXmlFileFromUpload().

+ Here is the caller graph for this function:

◆ handleFile()

ilCmiXapiContentUploadImporter::handleFile ( string  $serverFile)
protected
Parameters
string$serverFile
Exceptions
ilCmiXapiInvalidUploadContentException

Definition at line 99 of file class.ilCmiXapiContentUploadImporter.php.

100 {
101 $fileInfo = pathinfo($serverFile);
102
103 switch ($fileInfo['extension']) {
105
106 $this->handleXmlFile($serverFile);
107 break;
108
110
111 $this->handleZipContentUpload($serverFile);
112
113 if ($this->hasStoredContentXml()) {
114 $this->handleXmlFile($this->getStoredContentXml());
115 }
116
117 break;
118 }
119 }

References getStoredContentXml(), handleXmlFile(), handleZipContentUpload(), hasStoredContentXml(), IMP_FILE_EXTENSION_XML, and IMP_FILE_EXTENSION_ZIP.

Referenced by importServerFile().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ handleUpload()

ilCmiXapiContentUploadImporter::handleUpload ( FileUploadResult  $uploadResult)
protected
Parameters
FileUploadResult$uploadResult
Exceptions
ilCmiXapiInvalidUploadContentException

Definition at line 184 of file class.ilCmiXapiContentUploadImporter.php.

185 {
186 switch ($this->fetchFileExtension($uploadResult)) {
188
189 $this->handleXmlFileFromUpload($uploadResult->getName(), $uploadResult->getPath());
190 break;
191
193
194 $this->handleZipContentUpload($uploadResult->getPath());
195
196 if ($this->hasStoredContentXml()) {
197 $this->handleXmlFile($this->getStoredContentXml());
198 }
199
200 break;
201 }
202 }
fetchFileExtension(FileUploadResult $uploadResult)

References fetchFileExtension(), getStoredContentXml(), handleXmlFile(), handleXmlFileFromUpload(), handleZipContentUpload(), hasStoredContentXml(), IMP_FILE_EXTENSION_XML, and IMP_FILE_EXTENSION_ZIP.

Referenced by importFormUpload().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ handleXmlFile()

ilCmiXapiContentUploadImporter::handleXmlFile (   $xmlFilePath)
protected
Parameters
string$xmlFilePath
Exceptions
ilCmiXapiInvalidUploadContentException

Definition at line 208 of file class.ilCmiXapiContentUploadImporter.php.

209 {
210 $dom = new DOMDocument();
211 $dom->load($xmlFilePath);
212
213 switch (basename($xmlFilePath)) {
214 case self::CMI5_XML:
215
216 $xsdFilePath = $this->getXsdFilePath(self::CMI5_XSD);
217 $this->validateXmlFile($dom, $xsdFilePath);
218
219 $this->initObjectFromCmi5Xml($dom);
220
221 break;
222
223 case self::TINCAN_XML:
224
225 $xsdFilePath = $this->getXsdFilePath(self::TINCAN_XSD);
226 $this->validateXmlFile($dom, $xsdFilePath);
227
228 $this->initObjectFromTincanXml($dom);
229
230 break;
231 }
232 }

References CMI5_XML, getXsdFilePath(), initObjectFromCmi5Xml(), initObjectFromTincanXml(), TINCAN_XML, and validateXmlFile().

Referenced by handleFile(), and handleUpload().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ handleXmlFileFromUpload()

ilCmiXapiContentUploadImporter::handleXmlFileFromUpload (   $xmlFileName,
  $xmlFilePath 
)
protected
Parameters
string$xmlFileName
string$xmlFilePath
Exceptions
ilCmiXapiInvalidUploadContentException

Definition at line 239 of file class.ilCmiXapiContentUploadImporter.php.

240 {
241 $dom = new DOMDocument();
242 $dom->load($xmlFilePath);
243 switch (basename($xmlFileName)) {
244 case self::CMI5_XML:
245
246 $xsdFilePath = $this->getXsdFilePath(self::CMI5_XSD);
247 $this->validateXmlFile($dom, $xsdFilePath);
248
249 $this->initObjectFromCmi5Xml($dom);
250
251 break;
252
253 case self::TINCAN_XML:
254
255 $xsdFilePath = $this->getXsdFilePath(self::TINCAN_XSD);
256 $this->validateXmlFile($dom, $xsdFilePath);
257
258 $this->initObjectFromTincanXml($dom);
259
260 break;
261 }
262 }

References CMI5_XML, getXsdFilePath(), initObjectFromCmi5Xml(), initObjectFromTincanXml(), TINCAN_XML, and validateXmlFile().

Referenced by handleUpload().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ handleZipContentUpload()

ilCmiXapiContentUploadImporter::handleZipContentUpload (   $uploadFilePath)
protected

Definition at line 271 of file class.ilCmiXapiContentUploadImporter.php.

272 {
273 $targetPath = $this->getAbsoluteObjectDirectory();
274 $zar = new ZipArchive();
275 $zar->open($uploadFilePath);
276 $zar->extractTo($targetPath);
277 $zar->close();
278 }

References getAbsoluteObjectDirectory().

Referenced by handleFile(), and handleUpload().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ hasStoredContentXml()

ilCmiXapiContentUploadImporter::hasStoredContentXml ( )
protected
Returns
bool

Definition at line 314 of file class.ilCmiXapiContentUploadImporter.php.

315 {
316 return $this->getStoredContentXml() !== '';
317 }

References getStoredContentXml().

Referenced by handleFile(), and handleUpload().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ importFormUpload()

ilCmiXapiContentUploadImporter::importFormUpload ( ilFileInputGUI  $uploadInput)
Parameters
ilFileInputGUI$uploadInput
Exceptions

ILIAS\FileUpload\Exception\IllegalStateException

Exceptions

ILIAS\Filesystem\Exception\IOException

Exceptions
ilCmiXapiInvalidUploadContentException

Definition at line 127 of file class.ilCmiXapiContentUploadImporter.php.

128 {
130
131 $fileData = $_POST[$uploadInput->getPostVar()];
132
133 $uploadResult = $this->getUpload(
134 $fileData['tmp_name']
135 );
136
137 $this->handleUpload($uploadResult);
138
140 }
$_POST["username"]
getPostVar()
Get Post Variable.

References $_POST, ensureCreatedObjectDirectory(), ilFormPropertyGUI\getPostVar(), getUpload(), handleUpload(), and sanitizeObjectDirectory().

+ Here is the call graph for this function:

◆ importServerFile()

ilCmiXapiContentUploadImporter::importServerFile (   $serverFile)
Parameters
$serverFile
Exceptions

ILIAS\Filesystem\Exception\IOException

Exceptions
ilCmiXapiInvalidUploadContentException

Definition at line 86 of file class.ilCmiXapiContentUploadImporter.php.

87 {
89
90 $this->handleFile($serverFile);
91
93 }

References ensureCreatedObjectDirectory(), handleFile(), and sanitizeObjectDirectory().

+ Here is the call graph for this function:

◆ initObjectFromCmi5Xml()

ilCmiXapiContentUploadImporter::initObjectFromCmi5Xml (   $dom)
protected

Definition at line 346 of file class.ilCmiXapiContentUploadImporter.php.

347 {
348 global $DIC;
349 $xPath = new DOMXPath($dom);
350
351 $courseNode = $xPath->query("//*[local-name()='course']")->item(0);
352 // TODO: multilanguage support
353 $title = $xPath->query("//*[local-name()='title']/*[local-name()='langstring']", $courseNode)->item(0)->nodeValue;
354 $this->object->setTitle(trim($title));
355
356 $description = $xPath->query("//*[local-name()='description']/*[local-name()='langstring']", $courseNode)->item(0)->nodeValue;
357 $this->object->setDescription(trim($description));
358
359 $publisherId = trim($courseNode->getAttribute('id'));
360 $this->object->setPublisherId($publisherId);
361
362 $activityId = $this->generateActivityId($publisherId);
363 $this->object->setActivityId($activityId);
364
365 foreach ($xPath->query("//*[local-name()='au']") as $assignedUnitNode) {
366 $relativeLaunchUrl = $xPath->query("//*[local-name()='url']", $assignedUnitNode)->item(0)->nodeValue;
367 $launchParameters = $xPath->query("//*[local-name()='launchParameters']", $assignedUnitNode)->item(0)->nodeValue;
368 $moveOn = trim($assignedUnitNode->getAttribute('moveOn'));
369 $entitlementKey = $xPath->query("//*[local-name()='entitlementKey']", $assignedUnitNode)->item(0)->nodeValue;
370 $masteryScore = trim($assignedUnitNode->getAttribute('masteryScore'));
371
372 if (!empty($relativeLaunchUrl)) {
373 $this->object->setLaunchUrl(trim($relativeLaunchUrl));
374 }
375 if (!empty($launchParameters)) {
376 $this->object->setLaunchParameters(trim($launchParameters));
377 }
378 if (!empty($moveOn)) {
381 }
382 $this->object->setMoveOn($moveOn);
383 }
384 if (!empty($entitlementKey)) {
385 $this->object->setEntitlementKey($entitlementKey);
386 }
387 if (!empty($masteryScore)) {
388 $this->object->setMasteryScore($masteryScore);
389 } else {
390 $this->object->setMasteryScore(ilObjCmiXapi::LMS_MASTERY_SCORE);
391 }
392
393 break; // TODO: manage multi au imports
394 }
395 $xml_str = $dom->saveXML();
396 $this->object->setXmlManifest($xml_str);
397 $this->object->update();
398 $this->object->save();
399
400 $lpSettings = new ilLPObjSettings($this->object->getId());
402 switch ($moveOn) {
405 break;
408 break;
411 break;
412 case ilCmiXapiLP::MOVEON_COMPLETED_AND_PASSED: // ich würde es noch implementieren
414 break;
415 }
416 $lpSettings->setMode($mode);
417 $lpSettings->update();
418 }
const MOVEON_COMPLETED_OR_PASSED
const MOVEON_COMPLETED_AND_PASSED

References $DIC, generateActivityId(), ilObjCmiXapi\LMS_MASTERY_SCORE, ilLPObjSettings\LP_MODE_CMIX_COMPLETED, ilLPObjSettings\LP_MODE_CMIX_COMPLETED_OR_PASSED, ilLPObjSettings\LP_MODE_CMIX_PASSED, ilLPObjSettings\LP_MODE_DEACTIVATED, ilCmiXapiLP\MOVEON_COMPLETED, ilCmiXapiLP\MOVEON_COMPLETED_AND_PASSED, ilCmiXapiLP\MOVEON_COMPLETED_OR_PASSED, and ilCmiXapiLP\MOVEON_PASSED.

Referenced by handleXmlFile(), and handleXmlFileFromUpload().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ initObjectFromTincanXml()

ilCmiXapiContentUploadImporter::initObjectFromTincanXml (   $dom)
protected

Definition at line 420 of file class.ilCmiXapiContentUploadImporter.php.

421 {
422 $xPath = new DOMXPath($dom);
423
424 foreach ($xPath->query("//*[local-name()='activity']") as $activityNode) {
425 $title = $xPath->query("//*[local-name()='name']", $activityNode)->item(0)->nodeValue;
426 $this->object->setTitle(trim($title));
427
428 $description = $xPath->query("//*[local-name()='description']", $activityNode)->item(0)->nodeValue;
429 $this->object->setDescription(trim($description));
430
431 $activityId = $activityNode->getAttribute('id');
432 $this->object->setActivityId(trim($activityId));
433
434 $relativeLaunchUrl = $xPath->query("//*[local-name()='launch']", $activityNode)->item(0)->nodeValue;
435 $this->object->setLaunchUrl(trim($relativeLaunchUrl));
436
437 break; // TODO: manage multi activities imports
438 }
439
440 $xml_str = $dom->saveXML();
441 $this->object->setXmlManifest($xml_str);
442 $this->object->update();
443 $this->object->save();
444 }

Referenced by handleXmlFile(), and handleXmlFileFromUpload().

+ Here is the caller graph for this function:

◆ sanitizeObjectDirectory()

ilCmiXapiContentUploadImporter::sanitizeObjectDirectory ( )
protected

Definition at line 74 of file class.ilCmiXapiContentUploadImporter.php.

75 {
76 ilUtil::renameExecutables(implode(DIRECTORY_SEPARATOR, [
78 ]));
79 }
static renameExecutables($a_dir)
Rename uploaded executables for security reasons.

References getWebDataDirRelativeObjectDirectory(), ilUtil\getWebspaceDir(), and ilUtil\renameExecutables().

Referenced by importFormUpload(), and importServerFile().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ validateXmlFile()

ilCmiXapiContentUploadImporter::validateXmlFile ( DOMDocument  $dom,
  $xsdFilePath 
)
protected

Definition at line 264 of file class.ilCmiXapiContentUploadImporter.php.

265 {
266 if (!$dom->schemaValidate($xsdFilePath)) {
267 throw new ilCmiXapiInvalidUploadContentException('invalid content xml given!');
268 }
269 }

Referenced by handleXmlFile(), and handleXmlFileFromUpload().

+ Here is the caller graph for this function:

Field Documentation

◆ $CONTENT_XML_FILENAMES

ilCmiXapiContentUploadImporter::$CONTENT_XML_FILENAMES
staticprotected
Initial value:

Definition at line 36 of file class.ilCmiXapiContentUploadImporter.php.

◆ $CONTENT_XSD_FILENAMES

ilCmiXapiContentUploadImporter::$CONTENT_XSD_FILENAMES
staticprotected

◆ $object

ilCmiXapiContentUploadImporter::$object
protected

Definition at line 51 of file class.ilCmiXapiContentUploadImporter.php.

Referenced by __construct().

◆ CMI5_XML

const ilCmiXapiContentUploadImporter::CMI5_XML = 'cmi5.xml'

◆ CMI5_XSD

const ilCmiXapiContentUploadImporter::CMI5_XSD = 'cmi5_v1_CourseStructure.xsd'

Definition at line 28 of file class.ilCmiXapiContentUploadImporter.php.

◆ IMP_FILE_EXTENSION_XML

const ilCmiXapiContentUploadImporter::IMP_FILE_EXTENSION_XML = 'xml'

Definition at line 24 of file class.ilCmiXapiContentUploadImporter.php.

Referenced by handleFile(), and handleUpload().

◆ IMP_FILE_EXTENSION_ZIP

const ilCmiXapiContentUploadImporter::IMP_FILE_EXTENSION_ZIP = 'zip'

Definition at line 25 of file class.ilCmiXapiContentUploadImporter.php.

Referenced by handleFile(), and handleUpload().

◆ RELATIVE_CONTENT_DIRECTORY_NAMEBASE

const ilCmiXapiContentUploadImporter::RELATIVE_CONTENT_DIRECTORY_NAMEBASE = 'lm_data/lm_'

◆ RELATIVE_XSD_DIRECTORY

const ilCmiXapiContentUploadImporter::RELATIVE_XSD_DIRECTORY = 'Modules/CmiXapi/xml/contentschema'

Definition at line 22 of file class.ilCmiXapiContentUploadImporter.php.

◆ TINCAN_XML

const ilCmiXapiContentUploadImporter::TINCAN_XML = 'tincan.xml'

◆ TINCAN_XSD

const ilCmiXapiContentUploadImporter::TINCAN_XSD = 'tincan.xsd'

Definition at line 31 of file class.ilCmiXapiContentUploadImporter.php.


The documentation for this class was generated from the following file: