ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
class.ilScormAiccImporter.php
Go to the documentation of this file.
1<?php
2/* Copyright (c) 1998-2016 ILIAS open source, Extended GPL, see docs/LICENSE */
3include_once("./Services/Export/classes/class.ilXmlImporter.php");
5{
6 public function __construct()
7 {
8 require_once "./Modules/ScormAicc/classes/class.ilScormAiccDataSet.php";
9 $this->dataset = new ilScormAiccDataSet();
10 //todo: at the moment restricted to one module in xml file, extend?
11 $this->moduleProperties = [];
12 $this->manifest = [];
13 }
14
15 public function init()
16 {
17 }
18
25 public function importXmlRepresentation($a_entity, $a_id, $a_import_dirname, $a_mapping)
26 {
27 global $DIC;
28 $ilLog = $DIC['ilLog'];
29
30 if ($this->handleEditableLmXml($a_entity, $a_id, $a_import_dirname, $a_mapping)) {
31 return true;
32 }
33 // case i container
34 if ($a_id != null && $new_id = $a_mapping->getMapping('Services/Container', 'objs', $a_id)) {
35 $newObj = ilObjectFactory::getInstanceByObjId($new_id, false);
36
37 require_once("./Services/Export/classes/class.ilExport.php");
38 $exportDir = ilExport::_getExportDirectory($a_id);
39 $tempFile = dirname($exportDir) . '/export/' . basename($this->getImportDirectory()) . '.zip';
40 $timeStamp = time();
41 $lmDir = ilUtil::getWebspaceDir("filesystem") . "/lm_data/";
42 $lmTempDir = $lmDir . $timeStamp;
43 if (!file_exists($lmTempDir)) {
44 mkdir($lmTempDir, 0755, true);
45 }
46 $zar = new ZipArchive();
47 $zar->open($tempFile);
48 $zar->extractTo($lmTempDir);
49 $zar->close();
50 $a_import_dirname = $lmTempDir . '/' . basename($this->getImportDirectory());
51 }
52
53
54
55 $result = false;
56 if (file_exists($a_import_dirname)) {
57 $manifestFile = $a_import_dirname . "/manifest.xml";
58 if (file_exists($manifestFile)) {
59 $manifest = file_get_contents($manifestFile);
60 if (isset($manifest)) {
61 $propertiesFile = $a_import_dirname . "/properties.xml";
62 $xml = file_get_contents($propertiesFile);
63 if (isset($xml)) {
64 $xmlRoot = simplexml_load_string($xml);
65 foreach ($this->dataset->properties as $key => $value) {
66 $this->moduleProperties[$key] = $xmlRoot->$key;
67 }
68 $this->moduleProperties["Title"] = $xmlRoot->Title;
69 $this->moduleProperties["Description"] = $xmlRoot->Description;
70
71 if ($a_id != null && $new_id = $a_mapping->getMapping('Services/Container', 'objs', $a_id)) {
72 $this->dataset->writeData("sahs", "5.1.0", $newObj->getId(), $this->moduleProperties);
73
74 $newObj->createReference();
75
76 $scormFile = "content.zip";
77 $scormFilePath = $a_import_dirname . "/" . $scormFile;
78 $targetPath = $newObj->getDataDirectory() . "/" . $scormFile;
79 $file_path = $targetPath;
80
81 ilFileUtils::rename($scormFilePath, $targetPath);
82 ilUtil::unzip($file_path);
83 unlink($file_path);
84 ilUtil::delDir($lmTempDir, false);
85 ilUtil::renameExecutables($newObj->getDataDirectory());
86
87 $newId = $newObj->getRefId();
88 // $newObj->putInTree($newId);
89 // $newObj->setPermissions($newId);
90 $subType = $this->moduleProperties["SubType"][0];
91 if ($subType == "scorm") {
92 include_once("./Modules/ScormAicc/classes/class.ilObjSCORMLearningModule.php");
93 $newObj = new ilObjSCORMLearningModule($newId);
94 } else {
95 include_once("./Modules/Scorm2004/classes/class.ilObjSCORM2004LearningModule.php");
96 $newObj = new ilObjSCORM2004LearningModule($newId);
97 }
98 $title = $newObj->readObject();
99 //auto set learning progress settings
100 $newObj->setLearningProgressSettingsAtUpload();
101 }
102
103
104 $result = true;
105 } else {
106 $ilLog->write("error parsing xml file for scorm import");
107 //error xml parsing
108 }
109 } else {
110 $ilLog->write("error reading manifest file");
111 }
112 } else {
113 $ilLog->write("error no manifest file found");
114 }
115 } else {
116 $ilLog->write("error file lost while importing");
117 //error non existing file
118 }
119 return $result;
120 }
121
122 public function writeData($a_entity, $a_version, $a_id)
123 {
124 $this->dataset->writeData($a_entity, $a_version, $a_id, $this->moduleProperties);
125 }
126
136 public function handleEditableLmXml($a_entity, $a_id, $a_xml, $a_mapping)
137 {
138 // if editable...
139 if (is_int(strpos($a_xml, "<Editable>1</Editable>"))) {
140 // ...use ilScorm2004DataSet for import
141 include_once("./Modules/Scorm2004/classes/class.ilScorm2004DataSet.php");
142 $dataset = new ilScorm2004DataSet();
143 $dataset->setDSPrefix("ds");
144 $dataset->setImportDirectory($this->getImportDirectory());
145
146 include_once("./Services/DataSet/classes/class.ilDataSetImportParser.php");
148 $a_entity,
149 $this->getSchemaVersion(),
150 $a_xml,
151 $dataset,
152 $a_mapping
153 );
154 return true;
155 }
156 return false;
157 }
158}
$parser
Definition: BPMN2Parser.php:23
$result
An exception for terminatinating execution or to throw for unit testing.
Manifest parser for ILIAS standard export files.
static _getExportDirectory($a_obj_id, $a_type="xml", $a_obj_type="", $a_entity="")
Get export directory for an repository object.
static rename($a_source, $a_target)
Rename a file.
Class ilObjSCORM2004LearningModule.
Class ilObjSCORMLearningModule.
static getInstanceByObjId($a_obj_id, $stop_on_error=true)
get an instance of an Ilias object by object id
importXmlRepresentation($a_entity, $a_id, $a_import_dirname, $a_mapping)
Import XML.
handleEditableLmXml($a_entity, $a_id, $a_xml, $a_mapping)
Handle editable (authoring) scorm lms.
writeData($a_entity, $a_version, $a_id)
static delDir($a_dir, $a_clean_only=false)
removes a dir and all its content (subdirs and files) recursively
static getWebspaceDir($mode="filesystem")
get webspace directory
static unzip($a_file, $overwrite=false, $a_flat=false)
unzip file
static renameExecutables($a_dir)
Rename uploaded executables for security reasons.
Xml importer class.
getSchemaVersion()
Get schema version.
getImportDirectory()
Get import directory.
$xml
Definition: metadata.php:332
$DIC
Definition: xapitoken.php:46