ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
class.ilScormAiccDataSet.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/DataSet/classes/class.ilDataSet.php");
4
6{
7 public function __construct()
8 {
9 $this->db_table = "sahs_lm";
10 $this->properties = [
11 //"OfflineZipCreated" => "datetime",
12 "Id" => ["db_col" => "id", "db_type" => "integer"],
13 //"EntryPage" => "integer",
14 "APIAdapterName" => ["db_col" => "api_adapter", "db_type" => "text"],
15 "APIFunctionsPrefix" => ["db_col" => "api_func_prefix", "db_type" => "text"],
16 "AssignedGlossary" => ["db_col" => "glossary", "db_type" => "integer"],
17 "AutoContinue" => ["db_col" => "auto_continue", "db_type" => "text"],
18 "AutoReviewChar" => ["db_col" => "auto_review", "db_type" => "text"],
19 "AutoSuspend" => ["db_col" => "auto_suspend", "db_type" => "text"],
20 "Auto_last_visited" => ["db_col" => "auto_last_visited", "db_type" => "text"],
21 "Check_values" => ["db_col" => "check_values", "db_type" => "text"],
22 "Comments" => ["db_col" => "comments", "db_type" => "text"],
23 "CreditMode" => ["db_col" => "credit", "db_type" => "text"],
24 "Debug" => ["db_col" => "debug", "db_type" => "text"],
25 "DebugPw" => ["db_col" => "debugpw", "db_type" => "text"],
26 "DefaultLessonMode" => ["db_col" => "default_lesson_mode", "db_type" => "text"],
27 "Editable" => ["db_col" => "editable", "db_type" => "integer"],
28 "Fourth_edition" => ["db_col" => "fourth_edition", "db_type" => "text"],
29 "Height" => ["db_col" => "height", "db_type" => "integer"],
30 "HideNavig" => ["db_col" => "hide_navig", "db_type" => "text"],
31 "Ie_force_render" => ["db_col" => "ie_force_render", "db_type" => "text"],
32 "Interactions" => ["db_col" => "interactions", "db_type" => "text"],
33 "Localization" => ["db_col" => "localization", "db_type" => "text"],
34 "MasteryScore" => ["db_col" => "mastery_score", "db_type" => "integer"],
35 "MaxAttempt" => ["db_col" => "max_attempt", "db_type" => "integer"],
36 "ModuleVersion" => ["db_col" => "module_version", "db_type" => "integer"],
37 "NoMenu" => ["db_col" => "no_menu", "db_type" => "text"],
38 "Objectives" => ["db_col" => "objectives", "db_type" => "text"],
39 "OfflineMode" => ["db_col" => "offline_mode", "db_type" => "text"],
40 "OpenMode" => ["db_col" => "open_mode", "db_type" => "integer"],
41 "Sequencing" => ["db_col" => "sequencing", "db_type" => "text"],
42 "SequencingExpertMode" => ["db_col" => "seq_exp_mode", "db_type" => "integer"],
43 "Session" => ["db_col" => "unlimited_session", "db_type" => "text"],
44 "StyleSheetId" => ["db_col" => "stylesheet", "db_type" => "integer"],
45 "SubType" => ["db_col" => "c_type", "db_type" => "text"],
46 "Time_from_lms" => ["db_col" => "time_from_lms", "db_type" => "text"],
47 "Tries" => ["db_col" => "question_tries", "db_type" => "integer"],
48 "Width" => ["db_col" => "width", "db_type" => "integer"],
49 "IdSetting" => ["db_col" => "id_setting", "db_type" => "integer"],
50 "NameSetting" => ["db_col" => "name_setting", "db_type" => "integer"]
51 ];
52
53 $this->element_db_mapping = [];
54 foreach ($this->properties as $key => $value) {
55 $this->element_db_mapping [$value["db_col"]] = $key;
56 }
57 }
58
64 public function readData($a_entity, $a_version, $a_id, $a_field = "")
65 {
66 global $DIC;
67 $ilDB = $DIC['ilDB'];
68
69 $obj_id = $a_id;
70 $columns = [];
71 foreach ($this->properties as $property) {
72 array_push($columns, $property["db_col"]);
73 }
74
75 $query = "SELECT " . implode(",", $columns) . " FROM " . $this->db_table;
76 $query .= " WHERE id=" . $ilDB->quote($obj_id, "integer");
77 $result = $ilDB->query($query);
78 $this->data = [];
79 if ($dataset = $ilDB->fetchAssoc($result)) {
80 $this->data = $dataset;
81 }
82
83 $query = "SELECT title,description FROM object_data";
84 $query .= " WHERE obj_id=" . $ilDB->quote($obj_id, "integer");
85 $result = $ilDB->query($query);
86 while ($dataset = $ilDB->fetchAssoc($result)) {
87 $this->data ["title"] = $dataset["title"];
88 $this->data ["description"] = $dataset["description"];
89 }
90 }
91
98 public function writeData($a_entity, $a_version, $a_id, $data)
99 {
100 global $DIC;
101 $ilDB = $DIC['ilDB'];
102 $ilLog = $DIC['ilLog'];
103 if (count($data) > 0) {
104 $columns = [];
105 foreach ($this->properties as $key => $value) {
106 if ($key == "Id" || $key == "title" || $key == "description") {
107 continue;
108 }
109 //fix localization and mastery_score
110 if ($key == "MasteryScore" && $data[$key][0] == 0) {
111 continue;
112 }
113 if ($key == "Localization" && $data[$key][0] == "") {
114 continue;
115 }
116 //end fix
117 if (isset($data[$key])) {
118 if (count($data[$key]) > 0) {
119 $columns [$value["db_col"]] = [$value["db_type"], $data[$key][0]];
120 }
121 }
122 }
123 if (count($columns) > 0) {
124 $conditions ["id"] = ["integer", $a_id];
125 $ilDB->update($this->db_table, $columns, $conditions);
126 }
127
128 //setting title and description in table object_data
129 $od_table = "object_data";
130 $od_properties = [
131 "Title" => ["db_col" => "title", "db_type" => "text"],
132 "Description" => ["db_col" => "description", "db_type" => "text"]
133 ];
134 foreach ($od_properties as $key => $value) {
135 if (isset($data[$key])) {
136 if (count($data[$key]) > 0) {
137 $od_columns [$value["db_col"]] = [$value["db_type"], $data[$key][0]];
138 }
139 }
140
141 if (count($od_columns) > 0) {
142 $od_conditions ["obj_id"] = ["integer", $a_id];
143 $ilDB->update("object_data", $od_columns, $od_conditions);
144 }
145 }
146 } else {
147 $ilLog->write("no module properties for imported object");
148 }
149 }
150
151 /* retrieve element name by database column name
152 */
153 public function getElementNameByDbColumn($db_col_name)
154 {
155 if ($db_col_name == "title") {
156 return "Title";
157 }
158 if ($db_col_name == "description") {
159 return "Description";
160 }
161 return $this->element_db_mapping[$db_col_name];
162 }
163
175 public function getExtendedXmlRepresentation($a_entity, $a_schema_version, $a_ids, $a_field = "", $a_omit_header = false, $a_omit_types = false)
176 {
177 $GLOBALS['DIC']["ilLog"]->write(json_encode($this->getTypes("sahs", "5.1.0"), JSON_PRETTY_PRINT));
178
179 $this->dircnt = 1;
180
181 $this->readData($a_entity, $a_schema_version, $a_ids, $a_field = "");
182 $id = $this->data["id"];
183
184 require_once("./Services/Export/classes/class.ilExport.php");
186
187 // step 1: check target release and supported versions
188 // step 2: init writer
189 require_once("./Services/Xml/classes/class.ilXmlWriter.php");
190 $writer = new ilXmlWriter();
191 if (!$a_omit_header) {
192 $writer->xmlHeader();
193 }
194
195 $atts = array("InstallationId" => IL_INST_ID,
196 "InstallationUrl" => ILIAS_HTTP_PATH, "TopEntity" => $a_entity);
197
198 $writer->appendXML("\n");
199 $writer->xmlStartTag($this->getDSPrefixString() . 'DataSet', $atts);
200 $writer->appendXML("\n");
201
202 foreach ($this->data as $key => $value) {
203 $writer->xmlElement($this->getElementNameByDbColumn($key), null, $value, true, true);
204 $writer->appendXML("\n");
205 }
206
207 $lmDir = ilUtil::getWebspaceDir("filesystem") . "/lm_data/lm_" . $id;
208 $baseFileName = "sahs_" . $id;
209 $scormBasePath = $exportDir . "/" . $baseFileName;
210 if (!file_exists($exportDir)) {
211 mkdir($exportDir, 0755, true);
212 }
213
214 ilUtil::zip($lmDir, $scormBasePath, true);
215 $scormFilePath = $scormBasePath . ".zip";
216
217 $writer->xmlEndTag($this->getDSPrefixString() . "DataSet");
218 $writer->appendXML("\n");
219
220 $xml = $writer->xmlDumpMem(false);
221 $baseExportName = time() . "__" . IL_INST_ID . "__" . $baseFileName;
222 $xmlFilePath = $exportDir . "/" . $baseExportName . ".xml";
223
224 if (!file_exists($xmlFilePath)) {
225 $xmlFile = fopen($xmlFilePath, "w");
226 fwrite($xmlFile, $xml);
227 fclose($xmlFile);
228 }
229
230 //create metadata
231 $metaData = $this->buildMetaData($id);
232
233 $metaDataFilePath = $exportDir . "/" . $baseExportName . "_metadata.xml";
234 if (!file_exists($metaDataFilePath)) {
235 $metaDataFile = fopen($metaDataFilePath, "w");
236 fwrite($metaDataFile, $metaData);
237 fclose($metaDataFile);
238 }
239
240 //create manifest file
241 $manWriter = new ilXmlWriter();
242 $manWriter->xmlHeader();
243 $manWriter->appendXML("\n<content>\n");
244
245 $files = [
246 "scormFile" => "content.zip",
247 "properties" => "properties.xml",
248 "metadata" => "metadata.xml"
249 ];
250 foreach ($files as $key => $value) {
251 $manWriter->xmlElement($key, null, $value, true, true);
252 $manWriter->appendXML("\n");
253 }
254
255 $manWriter->appendXML("</content>\n");
256 $manifest = $manWriter->xmlDumpMem(false);
257
258 $manifestFilePath = $exportDir . "/" . $baseExportName . "_manifest.xml";
259 if (!file_exists($manifestFilePath)) {
260 $manifestFile = fopen($manifestFilePath, "w");
261 fwrite($manifestFile, $manifest);
262 fclose($manifestFile);
263 }
264
265 $zArchive = new zipArchive();
266 $fileName = $exportDir . "/" . $baseExportName . ".zip";
267
268 if ($zArchive->open($fileName, ZipArchive::CREATE) !== true) {
269 exit("cannot open <$fileName>\n");
270 }
271
272 //creating final zip file
273 $zArchive->addFile($xmlFilePath, $baseExportName . '/properties.xml');
274 $zArchive->addFile($scormFilePath, $baseExportName . '/content.zip');
275 $zArchive->addFile($manifestFilePath, $baseExportName . '/' . "manifest.xml");
276 $zArchive->addFile($metaDataFilePath, $baseExportName . '/' . "metadata.xml");
277 $zArchive->close();
278 //delete temporary files
279 unlink($xmlFilePath);
280 unlink($scormFilePath);
281 unlink($manifestFilePath);
282 unlink($metaDataFilePath);
283
284 return $fileName;
285 }
286
287 public function buildMetaData($id)
288 {
289 require_once("Services/MetaData/classes/class.ilMD2XML.php");
290 $md2xml = new ilMD2XML($id, $id, "sahs");
291 $md2xml->startExport();
292 $xml = $md2xml->getXML();
293 return $xml;
294 }
295
303 protected function getTypes($a_entity, $a_version)
304 {
305 if ($a_entity == "sahs") {
306 switch ($a_version) {
307 case "5.1.0":
308 $types = [];
309 foreach ($this->properties as $key => $value) {
310 $types[$key] = $value["db_type"];
311 }
312 return $types;
313 break;
314 }
315 }
316 }
317
323 public function getXmlNamespace($a_entity, $a_schema_version)
324 {
325 return "http://www.ilias.de/xml/Modules/ScormAicc/" . $a_entity;
326 }
327
328 public function getDependencies()
329 {
330 return null;
331 }
332
333 public function getSupportedVersions()
334 {
335 return ["5.1.0"];
336 }
337}
$result
if(! $in) $columns
Definition: Utf8Test.php:45
exit
Definition: backend.php:16
$metaData
Definition: buildPhar.php:18
An exception for terminatinating execution or to throw for unit testing.
A dataset contains in data in a common structure that can be shared and transformed for different pur...
static _getExportDirectory($a_obj_id, $a_type="xml", $a_obj_type="", $a_entity="")
Get export directory for an repository object.
getSupportedVersions()
Get supported version.
getExtendedXmlRepresentation($a_entity, $a_schema_version, $a_ids, $a_field="", $a_omit_header=false, $a_omit_types=false)
own getXmlRepresentation function to embed zipfile in xml
readData($a_entity, $a_version, $a_id, $a_field="")
Read data.
writeData($a_entity, $a_version, $a_id, $data)
Write properties for imported object (actually updates !!)
getElementNameByDbColumn($db_col_name)
getXmlNamespace($a_entity, $a_schema_version)
Get xml namespace.
getTypes($a_entity, $a_version)
Get field types for entity.
static getWebspaceDir($mode="filesystem")
get webspace directory
static zip($a_dir, $a_file, $compress_content=false)
zips given directory/file into given zip.file
XML writer class.
$key
Definition: croninfo.php:18
if(!array_key_exists('StateId', $_REQUEST)) $id
$files
Definition: metarefresh.php:49
$GLOBALS['JPEG_Segment_Names']
Global Variable: XMP_tag_captions.
$query
global $DIC
Definition: saml.php:7
global $ilDB
$this data['403_header']
$data
Definition: bench.php:6