19declare(strict_types=1);
45 public const CMI5_XSD =
'cmi5_v1_CourseStructure.xsd';
67 private \ILIAS\DI\Container
$dic;
86 if (!
$DIC->filesystem()->web()->has($this->getWebDataDirRelativeObjectDirectory())) {
94 implode(DIRECTORY_SEPARATOR, [
119 $fileInfo = pathinfo($serverFile);
121 switch ($fileInfo[
'extension']) {
150 $fileData[
'tmp_name']
162 protected function getUpload(?
string $uploadFilePath): FileUploadResult
166 if (
$DIC->upload()->hasUploads()) {
167 if (!
$DIC->upload()->hasBeenProcessed()) {
168 $DIC->upload()->process();
175 if (isset(
$results[$uploadFilePath])) {
176 $result =
$results[$uploadFilePath];
178 if ($result->isOK()) {
183 'upload processing failed with message ' .
184 '"' . $result->getStatus()->getMessage() .
'"'
222 $dom =
new DOMDocument();
223 $dom->load($xmlFilePath);
225 switch (basename($xmlFilePath)) {
251 $dom =
new DOMDocument();
252 $dom->load($xmlFilePath);
253 switch (basename($xmlFileName)) {
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;
339 $xPath =
new DOMXPath($dom);
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();
429 $xPath =
new DOMXPath($dom);
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();
Stream factory which enables the user to create streams without the knowledge of the concrete class.
sanitizeObjectDirectory()
validateXmlFile(DOMDocument $dom, $xsdFilePath)
initObjectFromCmi5Xml(DOMDocument $dom)
static array $CONTENT_XSD_FILENAMES
getXsdFilePath(string $xsdFileName)
__construct(ilObjCmiXapi $object)
ilCmiXapiContentUploadImporter constructor.
fetchFileExtension(FileUploadResult $uploadResult)
const IMP_FILE_EXTENSION_ZIP
const IMP_FILE_EXTENSION_XML
static array $CONTENT_XML_FILENAMES
importServerFile(string $serverFile)
getAbsoluteObjectDirectory()
const RELATIVE_CONTENT_DIRECTORY_NAMEBASE
handleZipContentUpload(string $uploadFilePath)
const RELATIVE_XSD_DIRECTORY
handleFile(string $serverFile)
generateActivityId(string $publisherId)
importFormUpload(array $fileData)
initObjectFromTincanXml(DOMDocument $dom)
getWebDataDirRelativeObjectDirectory()
getUpload(?string $uploadFilePath)
ensureCreatedObjectDirectory()
handleUpload(FileUploadResult $uploadResult)
handleXmlFile(string $xmlFilePath)
handleXmlFileFromUpload(string $xmlFileName, string $xmlFilePath)
const MOVEON_COMPLETED_OR_PASSED
const MOVEON_COMPLETED_AND_PASSED
static getWebspaceDir(string $mode="filesystem")
get webspace directory
static renameExecutables(string $a_dir)
const LP_MODE_CMIX_COMPLETED_OR_PASSED
const LP_MODE_CMIX_PASSED
const LP_MODE_DEACTIVATED
const LP_MODE_CMIX_COMPLETED