ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
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 $ilLog;
28
29 if ($this->handleEditableLmXml($a_entity, $a_id, $a_import_dirname, $a_mapping)) {
30 return true;
31 }
32 // case i container
33 if ($a_id != null && $new_id = $a_mapping->getMapping('Services/Container', 'objs', $a_id)) {
34 $newObj = ilObjectFactory::getInstanceByObjId($new_id, false);
35
36 require_once("./Services/Export/classes/class.ilExport.php");
37 $exportDir = ilExport::_getExportDirectory($a_id);
38 $tempFile = dirname($exportDir) . '/export/' . basename($this->getImportDirectory()) . '.zip';
39 $timeStamp = time();
40 $lmDir = ilUtil::getWebspaceDir("filesystem") . "/lm_data/";
41 $lmTempDir = $lmDir . $timeStamp;
42 if (!file_exists($lmTempDir)) {
43 mkdir($lmTempDir, 0755, true);
44 }
45 $zar = new ZipArchive();
46 $zar->open($tempFile);
47 $zar->extractTo($lmTempDir);
48 $zar->close();
49 $a_import_dirname = $lmTempDir . '/' . basename($this->getImportDirectory());
50 }
51
52
53
54 $result = false;
55 if (file_exists($a_import_dirname)) {
56 $manifestFile = $a_import_dirname . "/manifest.xml";
57 if (file_exists($manifestFile)) {
58 $manifest = file_get_contents($manifestFile);
59 if (isset($manifest)) {
60 $propertiesFile = $a_import_dirname . "/properties.xml";
61 $xml = file_get_contents($propertiesFile);
62 if (isset($xml)) {
63 $xmlRoot = simplexml_load_string($xml);
64 foreach ($this->dataset->properties as $key => $value) {
65 $this->moduleProperties[$key] = $xmlRoot->$key;
66 }
67 $this->moduleProperties["Title"] = $xmlRoot->Title;
68 $this->moduleProperties["Description"] = $xmlRoot->Description;
69
70 if ($a_id != null && $new_id = $a_mapping->getMapping('Services/Container', 'objs', $a_id)) {
71 $this->dataset->writeData("sahs", "5.1.0", $newObj->getId(), $this->moduleProperties);
72
73 $newObj->createReference();
74
75 $scormFile = "content.zip";
76 $scormFilePath = $a_import_dirname . "/" . $scormFile;
77 $targetPath = $newObj->getDataDirectory() . "/" . $scormFile;
78 $file_path = $targetPath;
79
80 ilFileUtils::rename($scormFilePath, $targetPath);
81 ilUtil::unzip($file_path);
82 unlink($file_path);
83 ilUtil::delDir($lmTempDir, false);
84 ilUtil::renameExecutables($newObj->getDataDirectory());
85
86 $newId = $newObj->getRefId();
87 // $newObj->putInTree($newId);
88 // $newObj->setPermissions($newId);
89 $subType = $this->moduleProperties["SubType"][0];
90 if ($subType == "scorm") {
91 include_once("./Modules/ScormAicc/classes/class.ilObjSCORMLearningModule.php");
92 $newObj = new ilObjSCORMLearningModule($newId);
93 } else {
94 include_once("./Modules/Scorm2004/classes/class.ilObjSCORM2004LearningModule.php");
95 $newObj = new ilObjSCORM2004LearningModule($newId);
96 }
97 $title = $newObj->readObject();
98 //auto set learning progress settings
99 $newObj->setLearningProgressSettingsAtUpload();
100 }
101
102
103 $result = true;
104 } else {
105 $ilLog->write("error parsing xml file for scorm import");
106 //error xml parsing
107 }
108 } else {
109 $ilLog->write("error reading manifest file");
110 }
111 } else {
112 $ilLog->write("error no manifest file found");
113 }
114 } else {
115 $ilLog->write("error file lost while importing");
116 //error non existing file
117 }
118 return $result;
119 }
120
121 public function writeData($a_entity, $a_version, $a_id)
122 {
123 $this->dataset->writeData($a_entity, $a_version, $a_id, $this->moduleProperties);
124 }
125
135 public function handleEditableLmXml($a_entity, $a_id, $a_xml, $a_mapping)
136 {
137 // if editable...
138 if (is_int(strpos($a_xml, "<Editable>1</Editable>"))) {
139 // ...use ilScorm2004DataSet for import
140 include_once("./Modules/Scorm2004/classes/class.ilScorm2004DataSet.php");
142 $dataset->setDSPrefix("ds");
143 $dataset->setImportDirectory($this->getImportDirectory());
144
145 include_once("./Services/DataSet/classes/class.ilDataSetImportParser.php");
147 $a_entity,
148 $this->getSchemaVersion(),
149 $a_xml,
150 $dataset,
151 $a_mapping
152 );
153 return true;
154 }
155 return false;
156 }
157}
$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.
$key
Definition: croninfo.php:18
$xml
Definition: metadata.php:240
$dataset
Definition: showstats.php:45