19declare(strict_types=1);
47 public const CMI5_XSD =
'cmi5_v1_CourseStructure.xsd';
69 private \ILIAS\DI\Container
$dic;
87 if (!
$DIC->filesystem()->web()->has($this->getWebDataDirRelativeObjectDirectory())) {
95 implode(DIRECTORY_SEPARATOR, [
120 $fileInfo = pathinfo($serverFile);
122 switch ($fileInfo[
'extension']) {
151 $fileData[
'tmp_name']
163 protected function getUpload(?
string $uploadFilePath): FileUploadResult
167 if (
$DIC->upload()->hasUploads()) {
168 if (!
$DIC->upload()->hasBeenProcessed()) {
169 $DIC->upload()->process();
176 if (isset(
$results[$uploadFilePath])) {
177 $result =
$results[$uploadFilePath];
179 if ($result->isOK()) {
184 'upload processing failed with message ' .
185 '"' . $result->getStatus()->getMessage() .
'"'
223 $dom =
new DOMDocument();
224 $dom->load($xmlFilePath);
226 switch (basename($xmlFilePath)) {
252 $dom =
new DOMDocument();
253 $dom->load($xmlFilePath);
254 switch (basename($xmlFileName)) {
280 if (!$dom->schemaValidate($xsdFilePath)) {
289 $unzip = $archives->unzip(
290 Streams::ofResource(fopen($uploadFilePath,
'rb')),
291 $archives->unzipOptions()
292 ->withZipOutputPath($targetPath)
293 ->withOverwrite(
true)
307 return implode(DIRECTORY_SEPARATOR, $dirs);
312 return self::RELATIVE_CONTENT_DIRECTORY_NAMEBASE . $this->
object->getId();
317 return pathinfo($uploadResult->getName(), PATHINFO_EXTENSION);
327 foreach (self::$CONTENT_XML_FILENAMES as $xmlFileName) {
330 if ($this->dic->filesystem()->web()->has($xmlFilePath)) {
340 return ILIAS_ABSOLUTE_PATH . DIRECTORY_SEPARATOR . self::RELATIVE_XSD_DIRECTORY . DIRECTORY_SEPARATOR . $xsdFileName;
345 $xPath =
new DOMXPath($dom);
347 $courseNode = $xPath->query(
"//*[local-name()='course']")->item(0);
349 $title = $xPath->query(
"//*[local-name()='title']/*[local-name()='langstring']", $courseNode)->item(0)->nodeValue;
350 $this->
object->setTitle(trim($title));
352 $description = $xPath->query(
"//*[local-name()='description']/*[local-name()='langstring']", $courseNode)->item(0)->nodeValue;
353 $this->
object->setDescription(trim($description));
355 $publisherId = trim($courseNode->getAttribute(
'id'));
356 $this->
object->setPublisherId($publisherId);
359 $this->
object->setActivityId($activityId);
363 foreach ($xPath->query(
"//*[local-name()='au']") as $assignedUnitNode) {
364 $relativeLaunchUrl = $xPath->query(
"//*[local-name()='url']", $assignedUnitNode)->item(0)->nodeValue;
365 if (!empty($xPath->query(
"//*[local-name()='launchParameters']", $assignedUnitNode)->item(0)->nodeValue)) {
366 $launchParameters = $xPath->query(
367 "//*[local-name()='launchParameters']",
369 )->item(0)->nodeValue;
371 if (!empty($assignedUnitNode->getAttribute(
'moveOn'))) {
372 $moveOn = trim($assignedUnitNode->getAttribute(
'moveOn'));
374 if (!empty($xPath->query(
"//*[local-name()='entitlementKey']", $assignedUnitNode)->item(0)->nodeValue)) {
375 $entitlementKey = $xPath->query(
376 "//*[local-name()='entitlementKey']",
378 )->item(0)->nodeValue;
380 if (!empty($assignedUnitNode->getAttribute(
'masteryScore'))) {
381 $masteryScore = trim($assignedUnitNode->getAttribute(
'masteryScore'));
384 if (!empty($relativeLaunchUrl)) {
385 $this->
object->setLaunchUrl(trim($relativeLaunchUrl));
387 if (!empty($launchParameters)) {
388 $this->
object->setLaunchParameters(trim($launchParameters));
390 if (!empty($moveOn)) {
394 $this->
object->setMoveOn($moveOn);
396 if (!empty($entitlementKey)) {
397 $this->
object->setEntitlementKey($entitlementKey);
399 if (!empty($masteryScore)) {
400 $this->
object->setMasteryScore((
float) $masteryScore);
407 $xml_str = $dom->saveXML();
408 $this->
object->setXmlManifest($xml_str);
409 $this->
object->update();
410 $this->
object->save();
429 $lpSettings->setMode($mode);
430 $lpSettings->update();
435 $xPath =
new DOMXPath($dom);
437 foreach ($xPath->query(
"//*[local-name()='activity']") as $activityNode) {
438 $title = $xPath->query(
"//*[local-name()='name']", $activityNode)->item(0)->nodeValue;
439 $this->
object->setTitle(trim($title));
441 $description = $xPath->query(
"//*[local-name()='description']", $activityNode)->item(0)->nodeValue;
442 $this->
object->setDescription(trim($description));
444 $activityId = $activityNode->getAttribute(
'id');
445 $this->
object->setActivityId(trim($activityId));
447 $relativeLaunchUrl = $xPath->query(
"//*[local-name()='launch']", $activityNode)->item(0)->nodeValue;
448 $this->
object->setLaunchUrl(trim($relativeLaunchUrl));
453 $xml_str = $dom->saveXML();
454 $this->
object->setXmlManifest($xml_str);
455 $this->
object->update();
456 $this->
object->save();
462 $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