19 declare(strict_types=1);
45 public const CMI5_XSD =
'cmi5_v1_CourseStructure.xsd';
54 self::CMI5_XML, self::TINCAN_XML
61 self::CMI5_XML => self::CMI5_XSD,
62 self::TINCAN_XML => self::TINCAN_XSD
67 private \ILIAS\DI\Container
$dic;
94 implode(DIRECTORY_SEPARATOR, [
119 $fileInfo = pathinfo($serverFile);
121 switch ($fileInfo[
'extension']) {
122 case self::IMP_FILE_EXTENSION_XML:
127 case self::IMP_FILE_EXTENSION_ZIP:
150 $fileData[
'tmp_name']
166 if ($DIC->upload()->hasUploads()) {
167 if (!$DIC->upload()->hasBeenProcessed()) {
168 $DIC->upload()->process();
173 $results = $DIC->upload()->getResults();
175 if (isset(
$results[$uploadFilePath])) {
176 $result =
$results[$uploadFilePath];
178 if ($result->isOK()) {
183 'upload processing failed with message ' .
184 '"' . $result->getStatus()->getMessage() .
'"' 200 case self::IMP_FILE_EXTENSION_XML:
205 case self::IMP_FILE_EXTENSION_ZIP:
223 $dom->load($xmlFilePath);
225 switch (basename($xmlFilePath)) {
235 case self::TINCAN_XML:
252 $dom->load($xmlFilePath);
253 switch (basename($xmlFileName)) {
263 case self::TINCAN_XML:
279 if (!$dom->schemaValidate($xsdFilePath)) {
287 $zar = new \ZipArchive();
288 $zar->open($uploadFilePath);
289 $zar->extractTo($targetPath);
301 return implode(DIRECTORY_SEPARATOR, $dirs);
306 return self::RELATIVE_CONTENT_DIRECTORY_NAMEBASE . $this->
object->getId();
311 return pathinfo($uploadResult->getName(), PATHINFO_EXTENSION);
321 foreach (self::$CONTENT_XML_FILENAMES as $xmlFileName) {
324 if ($this->dic->filesystem()->web()->has($xmlFilePath)) {
334 return ILIAS_ABSOLUTE_PATH . DIRECTORY_SEPARATOR . self::RELATIVE_XSD_DIRECTORY . DIRECTORY_SEPARATOR . $xsdFileName;
341 $courseNode = $xPath->query(
"//*[local-name()='course']")->item(0);
343 $title = $xPath->query(
"//*[local-name()='title']/*[local-name()='langstring']", $courseNode)->item(0)->nodeValue;
344 $this->
object->setTitle(trim($title));
346 $description = $xPath->query(
"//*[local-name()='description']/*[local-name()='langstring']", $courseNode)->item(0)->nodeValue;
347 $this->
object->setDescription(trim($description));
349 $publisherId = trim($courseNode->getAttribute(
'id'));
350 $this->
object->setPublisherId($publisherId);
353 $this->
object->setActivityId($activityId);
357 foreach ($xPath->query(
"//*[local-name()='au']") as $assignedUnitNode) {
358 $relativeLaunchUrl = $xPath->query(
"//*[local-name()='url']", $assignedUnitNode)->item(0)->nodeValue;
359 if (!empty($xPath->query(
"//*[local-name()='launchParameters']", $assignedUnitNode)->item(0)->nodeValue)) {
360 $launchParameters = $xPath->query(
361 "//*[local-name()='launchParameters']",
363 )->item(0)->nodeValue;
365 if (!empty($assignedUnitNode->getAttribute(
'moveOn'))) {
366 $moveOn = trim($assignedUnitNode->getAttribute(
'moveOn'));
368 if (!empty($xPath->query(
"//*[local-name()='entitlementKey']", $assignedUnitNode)->item(0)->nodeValue)) {
369 $entitlementKey = $xPath->query(
370 "//*[local-name()='entitlementKey']",
372 )->item(0)->nodeValue;
374 if (!empty($assignedUnitNode->getAttribute(
'masteryScore'))) {
375 $masteryScore = trim($assignedUnitNode->getAttribute(
'masteryScore'));
378 if (!empty($relativeLaunchUrl)) {
379 $this->
object->setLaunchUrl(trim($relativeLaunchUrl));
381 if (!empty($launchParameters)) {
382 $this->
object->setLaunchParameters(trim($launchParameters));
384 if (!empty($moveOn)) {
388 $this->
object->setMoveOn($moveOn);
390 if (!empty($entitlementKey)) {
391 $this->
object->setEntitlementKey($entitlementKey);
393 if (!empty($masteryScore)) {
394 $this->
object->setMasteryScore((
float) $masteryScore);
401 $xml_str = $dom->saveXML();
402 $this->
object->setXmlManifest($xml_str);
403 $this->
object->update();
404 $this->
object->save();
423 $lpSettings->setMode($mode);
424 $lpSettings->update();
431 foreach ($xPath->query(
"//*[local-name()='activity']") as $activityNode) {
432 $title = $xPath->query(
"//*[local-name()='name']", $activityNode)->item(0)->nodeValue;
433 $this->
object->setTitle(trim($title));
435 $description = $xPath->query(
"//*[local-name()='description']", $activityNode)->item(0)->nodeValue;
436 $this->
object->setDescription(trim($description));
438 $activityId = $activityNode->getAttribute(
'id');
439 $this->
object->setActivityId(trim($activityId));
441 $relativeLaunchUrl = $xPath->query(
"//*[local-name()='launch']", $activityNode)->item(0)->nodeValue;
442 $this->
object->setLaunchUrl(trim($relativeLaunchUrl));
447 $xml_str = $dom->saveXML();
448 $this->
object->setXmlManifest($xml_str);
449 $this->
object->update();
450 $this->
object->save();
456 $objId = $this->
object->getId();
static getWebspaceDir(string $mode="filesystem")
get webspace directory
const LP_MODE_CMIX_COMPLETED
static array $CONTENT_XML_FILENAMES
const LP_MODE_CMIX_COMPLETED_OR_PASSED
const IMP_FILE_EXTENSION_XML
fetchFileExtension(FileUploadResult $uploadResult)
const MOVEON_COMPLETED_AND_PASSED
handleFile(string $serverFile)
const LP_MODE_CMIX_PASSED
importServerFile(string $serverFile)
ensureCreatedObjectDirectory()
const RELATIVE_CONTENT_DIRECTORY_NAMEBASE
handleUpload(FileUploadResult $uploadResult)
handleXmlFileFromUpload(string $xmlFileName, string $xmlFilePath)
sanitizeObjectDirectory()
static renameExecutables(string $a_dir)
const IMP_FILE_EXTENSION_ZIP
__construct(ilObjCmiXapi $object)
ilCmiXapiContentUploadImporter constructor.
validateXmlFile(DOMDocument $dom, $xsdFilePath)
generateActivityId(string $publisherId)
static array $CONTENT_XSD_FILENAMES
getAbsoluteObjectDirectory()
const LP_MODE_DEACTIVATED
handleXmlFile(string $xmlFilePath)
getUpload(?string $uploadFilePath)
initObjectFromCmi5Xml(DOMDocument $dom)
getXsdFilePath(string $xsdFileName)
const MOVEON_COMPLETED_OR_PASSED
handleZipContentUpload(string $uploadFilePath)
importFormUpload(array $fileData)
getWebDataDirRelativeObjectDirectory()
const RELATIVE_XSD_DIRECTORY
initObjectFromTincanXml(DOMDocument $dom)