3 declare(strict_types=1);
47 public const CMI5_XSD =
'cmi5_v1_CourseStructure.xsd';
56 self::CMI5_XML, self::TINCAN_XML
63 self::CMI5_XML => self::CMI5_XSD,
64 self::TINCAN_XML => self::TINCAN_XSD
69 private \ILIAS\DI\Container
$dic;
95 implode(DIRECTORY_SEPARATOR, [
120 $fileInfo = pathinfo($serverFile);
122 switch ($fileInfo[
'extension']) {
123 case self::IMP_FILE_EXTENSION_XML:
128 case self::IMP_FILE_EXTENSION_ZIP:
151 $fileData[
'tmp_name']
167 if ($DIC->upload()->hasUploads()) {
168 if (!$DIC->upload()->hasBeenProcessed()) {
169 $DIC->upload()->process();
174 $results = $DIC->upload()->getResults();
176 if (isset(
$results[$uploadFilePath])) {
177 $result =
$results[$uploadFilePath];
179 if ($result->isOK()) {
184 'upload processing failed with message ' .
185 '"' . $result->getStatus()->getMessage() .
'"' 201 case self::IMP_FILE_EXTENSION_XML:
206 case self::IMP_FILE_EXTENSION_ZIP:
224 $dom->load($xmlFilePath);
226 switch (basename($xmlFilePath)) {
236 case self::TINCAN_XML:
253 $dom->load($xmlFilePath);
254 switch (basename($xmlFileName)) {
264 case self::TINCAN_XML:
280 if (!$dom->schemaValidate($xsdFilePath)) {
289 $unzip = $archives->unzip(
290 Streams::ofResource(fopen($uploadFilePath,
'rb')),
291 $archives->unzipOptions()
292 ->withZipOutputPath($targetPath)
293 ->withOverwrite(
true)
311 return implode(DIRECTORY_SEPARATOR, $dirs);
316 return self::RELATIVE_CONTENT_DIRECTORY_NAMEBASE . $this->
object->getId();
321 return pathinfo($uploadResult->getName(), PATHINFO_EXTENSION);
331 foreach (self::$CONTENT_XML_FILENAMES as $xmlFileName) {
334 if ($this->dic->filesystem()->web()->has($xmlFilePath)) {
344 return ILIAS_ABSOLUTE_PATH . DIRECTORY_SEPARATOR . self::RELATIVE_XSD_DIRECTORY . DIRECTORY_SEPARATOR . $xsdFileName;
351 $courseNode = $xPath->query(
"//*[local-name()='course']")->item(0);
353 $title = $xPath->query(
"//*[local-name()='title']/*[local-name()='langstring']", $courseNode)->item(0)->nodeValue;
354 $this->
object->setTitle(trim($title));
356 $description = $xPath->query(
"//*[local-name()='description']/*[local-name()='langstring']", $courseNode)->item(0)->nodeValue;
357 $this->
object->setDescription(trim($description));
359 $publisherId = trim($courseNode->getAttribute(
'id'));
360 $this->
object->setPublisherId($publisherId);
363 $this->
object->setActivityId($activityId);
367 foreach ($xPath->query(
"//*[local-name()='au']") as $assignedUnitNode) {
368 $relativeLaunchUrl = $xPath->query(
"//*[local-name()='url']", $assignedUnitNode)->item(0)->nodeValue;
369 if (!empty($xPath->query(
"//*[local-name()='launchParameters']", $assignedUnitNode)->item(0)->nodeValue)) {
370 $launchParameters = $xPath->query(
371 "//*[local-name()='launchParameters']",
373 )->item(0)->nodeValue;
375 if (!empty($assignedUnitNode->getAttribute(
'moveOn'))) {
376 $moveOn = trim($assignedUnitNode->getAttribute(
'moveOn'));
378 if (!empty($xPath->query(
"//*[local-name()='entitlementKey']", $assignedUnitNode)->item(0)->nodeValue)) {
379 $entitlementKey = $xPath->query(
380 "//*[local-name()='entitlementKey']",
382 )->item(0)->nodeValue;
384 if (!empty($assignedUnitNode->getAttribute(
'masteryScore'))) {
385 $masteryScore = trim($assignedUnitNode->getAttribute(
'masteryScore'));
388 if (!empty($relativeLaunchUrl)) {
389 $this->
object->setLaunchUrl(trim($relativeLaunchUrl));
391 if (!empty($launchParameters)) {
392 $this->
object->setLaunchParameters(trim($launchParameters));
394 if (!empty($moveOn)) {
398 $this->
object->setMoveOn($moveOn);
400 if (!empty($entitlementKey)) {
401 $this->
object->setEntitlementKey($entitlementKey);
403 if (!empty($masteryScore)) {
404 $this->
object->setMasteryScore((
float) $masteryScore);
411 $xml_str = $dom->saveXML();
412 $this->
object->setXmlManifest($xml_str);
413 $this->
object->update();
414 $this->
object->save();
433 $lpSettings->setMode($mode);
434 $lpSettings->update();
441 foreach ($xPath->query(
"//*[local-name()='activity']") as $activityNode) {
442 $title = $xPath->query(
"//*[local-name()='name']", $activityNode)->item(0)->nodeValue;
443 $this->
object->setTitle(trim($title));
445 $description = $xPath->query(
"//*[local-name()='description']", $activityNode)->item(0)->nodeValue;
446 $this->
object->setDescription(trim($description));
448 $activityId = $activityNode->getAttribute(
'id');
449 $this->
object->setActivityId(trim($activityId));
451 $relativeLaunchUrl = $xPath->query(
"//*[local-name()='launch']", $activityNode)->item(0)->nodeValue;
452 $this->
object->setLaunchUrl(trim($relativeLaunchUrl));
457 $xml_str = $dom->saveXML();
458 $this->
object->setXmlManifest($xml_str);
459 $this->
object->update();
460 $this->
object->save();
466 $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)