ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilScormAiccDataSet.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22{
23 private string $db_table;
24 public array $properties;
25 private array $_archive;
26 private array $element_db_mapping;
27
28 public function __construct()
29 {
30 $this->db_table = "sahs_lm";
31 $this->_archive = [];
32 $this->properties = [
33 "Id" => ["db_col" => "id", "db_type" => "integer"],
34 "APIAdapterName" => ["db_col" => "api_adapter", "db_type" => "text"],
35 "APIFunctionsPrefix" => ["db_col" => "api_func_prefix", "db_type" => "text"],
36 "AssignedGlossary" => ["db_col" => "glossary", "db_type" => "integer"],
37 "AutoContinue" => ["db_col" => "auto_continue", "db_type" => "text"],
38 "AutoReviewChar" => ["db_col" => "auto_review", "db_type" => "text"],
39 "AutoSuspend" => ["db_col" => "auto_suspend", "db_type" => "text"],
40 "Auto_last_visited" => ["db_col" => "auto_last_visited", "db_type" => "text"],
41 "Check_values" => ["db_col" => "check_values", "db_type" => "text"],
42 "Comments" => ["db_col" => "comments", "db_type" => "text"],
43 "CreditMode" => ["db_col" => "credit", "db_type" => "text"],
44 "Debug" => ["db_col" => "debug", "db_type" => "text"],
45 "DebugPw" => ["db_col" => "debugpw", "db_type" => "text"],
46 "DefaultLessonMode" => ["db_col" => "default_lesson_mode", "db_type" => "text"],
47 "Editable" => ["db_col" => "editable", "db_type" => "integer"],
48 "Fourth_edition" => ["db_col" => "fourth_edition", "db_type" => "text"],
49 "Height" => ["db_col" => "height", "db_type" => "integer"],
50 "HideNavig" => ["db_col" => "hide_navig", "db_type" => "text"],
51 "Ie_force_render" => ["db_col" => "ie_force_render", "db_type" => "text"],
52 "Interactions" => ["db_col" => "interactions", "db_type" => "text"],
53 "Localization" => ["db_col" => "localization", "db_type" => "text"],
54 "MasteryScore" => ["db_col" => "mastery_score", "db_type" => "integer"],
55 "MaxAttempt" => ["db_col" => "max_attempt", "db_type" => "integer"],
56 "ModuleVersion" => ["db_col" => "module_version", "db_type" => "integer"],
57 "NoMenu" => ["db_col" => "no_menu", "db_type" => "text"],
58 "Objectives" => ["db_col" => "objectives", "db_type" => "text"],
59 "OfflineMode" => ["db_col" => "offline_mode", "db_type" => "text"],
60 "OpenMode" => ["db_col" => "open_mode", "db_type" => "integer"],
61 "Sequencing" => ["db_col" => "sequencing", "db_type" => "text"],
62 "SequencingExpertMode" => ["db_col" => "seq_exp_mode", "db_type" => "integer"],
63 "Session" => ["db_col" => "unlimited_session", "db_type" => "text"],
64 "StyleSheetId" => ["db_col" => "stylesheet", "db_type" => "integer"],
65 "SubType" => ["db_col" => "c_type", "db_type" => "text"],
66 "Time_from_lms" => ["db_col" => "time_from_lms", "db_type" => "text"],
67 "Tries" => ["db_col" => "question_tries", "db_type" => "integer"],
68 "Width" => ["db_col" => "width", "db_type" => "integer"],
69 "IdSetting" => ["db_col" => "id_setting", "db_type" => "integer"],
70 "NameSetting" => ["db_col" => "name_setting", "db_type" => "integer"]
71 ];
72
73 $this->element_db_mapping = [];
74
76
77 foreach ($this->properties as $key => $value) {
78 $this->element_db_mapping [$value["db_col"]] = $key;
79 }
80 }
81
82 protected function getDependencies(
83 string $a_entity,
84 string $a_version,
85 ?array $a_rec = null,
86 ?array $a_ids = null
87 ): array {
88 return [];
89 }
90
91 public function writeData(string $a_entity, string $a_version, int $a_id, array $data): void
92 {
93 global $DIC;
94 $ilDB = $DIC->database();
95 $ilLog = ilLoggerFactory::getLogger('sahs');
96 if (count($data) > 0) {
97 $columns = [];
98 foreach ($this->properties as $key => $value) {
99 if ($key === "Id" || $key === "title" || $key === "description") {
100 continue;
101 }
102 //fix localization and mastery_score
103 if ($key === "MasteryScore" && isset($data[$key][0]) && $data[$key][0] == 0) {
104 continue;
105 }
106 if ($key === "Localization" && isset($data[$key][0]) && $data[$key][0] == "") {
107 continue;
108 }
109 //end fix
110 if ( isset( $data[ $key ] ) ) {
111 $data_value = '';
112 if ( is_array( $data[ $key ] ) ) {
113 $data_value = $data[ $key ][ 0 ] ?? '';
114 }
115 else {
116 $data_value = $data[ $key ];
117 }
118 $columns [ $value[ "db_col" ] ] = [
119 $value[ "db_type" ],
120 $data_value
121 ];
122 }
123 }
124 if (is_array($columns)) {
125 if (count($columns) > 0) {
126 $conditions ["id"] = ["integer", $a_id];
127 $ilDB->update($this->db_table, $columns, $conditions);
128 }
129 }
130
131 //setting title and description in table object_data
132 $od_table = "object_data";
133 $od_properties = [
134 "Title" => ["db_col" => "title", "db_type" => "text"],
135 "Description" => ["db_col" => "description", "db_type" => "text"]
136 ];
137 foreach ($od_properties as $key => $value) {
138 if ( isset( $data[ $key ] ) ) {
139 $data_value = '';
140 if ( is_array( $data[ $key ] ) ) {
141 $data_value = $data[ $key ][ 0 ] ?? '';
142 }
143 else {
144 $data_value = $data[ $key ];
145 }
146 $od_columns [ $value[ "db_col" ] ] = [
147 $value[ "db_type" ],
148 $data_value
149 ];
150 }
151
152 if (isset($od_columns) && is_array($od_columns)) {
153 if (count($od_columns) > 0) {
154 $od_conditions ["obj_id"] = ["integer", $a_id];
155 $ilDB->update("object_data", $od_columns, $od_conditions);
156 }
157 }
158 }
159 } else {
160 $ilLog->write("no module properties for imported object");
161 }
162 }
163
168 string $exportArchiveDir,
169 string $a_entity,
170 string $a_schema_version,
171 array $a_ids,
172 string $a_field = "",
173 bool $a_omit_header = false,
174 bool $a_omit_types = false
175 ): string {
176
177 global $DIC;
178 $ilLog = ilLoggerFactory::getLogger('sahs');
179
180 $ilLog->write(json_encode($this->getTypes("sahs", "5.1.0"), JSON_PRETTY_PRINT));
181
182 $this->dircnt = 1;
183
184 $this->readData($a_entity, $a_schema_version, $a_ids, $a_field = "");
185 $id = (int) $this->data["id"];
186
187 $this->_archive['files'] = [
188 "properties" => "properties.xml",
189 "manifest" => 'manifest.xml',
190 'scormFile' => "content.zip"
191 ];
192
193 // build manifest xml file
194 file_put_contents(
195 $exportArchiveDir . "/" . $this->_archive['files']['manifest'],
196 $this->buildManifest()
197 );
198
199 // build content zip file
200 if (isset($this->_archive['files']['scormFile'])) {
201 $lmDir = './' . ILIAS_WEB_DIR . "/" . CLIENT_ID . "/lm_data/lm_" . $id;
202 // Important: content zip should not contain a 'lm_x' directory
203 $DIC->legacyArchives()->zip(
204 $lmDir,
205 $exportArchiveDir . "/" . $this->_archive['files']['scormFile'],
206 false
207 );
208 }
209
210 // build property xml file
211 file_put_contents(
212 $exportArchiveDir . "/" . $this->_archive['files']['properties'],
213 $this->buildProperties($a_entity, $a_omit_header)
214 );
215
216 return $exportArchiveDir . '.zip';
217 }
218
225 protected function getTypes(string $a_entity, string $a_version): array
226 {
227 if ($a_entity === "sahs") {
228 switch ($a_version) {
229 case "5.1.0":
230 $types = [];
231 foreach ($this->properties as $key => $value) {
232 $types[$key] = $value["db_type"];
233 }
234 return $types;
235 }
236 }
237 return [];
238 }
239
240 public function readData(string $a_entity, string $a_version, array $a_ids, string $a_field = ""): void
241 {
242 global $DIC;
243 $ilDB = $DIC->database();
244
245 $obj_id = (int) $a_ids[0];
246 $columns = [];
247 foreach ($this->properties as $property) {
248 $columns[] = $property["db_col"];
249 }
250
251 $query = "SELECT " . implode(",", $columns) . " FROM " . $this->db_table;
252 $query .= " WHERE id=" . $ilDB->quote($obj_id, "integer");
253 $result = $ilDB->query($query);
254 $this->data = [];
255 if ($dataset = $ilDB->fetchAssoc($result)) {
256 $this->data = $dataset;
257 }
258
259 $query = "SELECT title,description FROM object_data";
260 $query .= " WHERE obj_id=" . $ilDB->quote($obj_id, "integer");
261 $result = $ilDB->query($query);
262 while ($dataset = $ilDB->fetchAssoc($result)) {
263 $this->data ["title"] = $dataset["title"];
264 $this->data ["description"] = $dataset["description"];
265 }
266 }
267
271 public function getElementNameByDbColumn(string $db_col_name): string
272 {
273 if ($db_col_name === "title") {
274 return "Title";
275 }
276 if ($db_col_name === "description") {
277 return "Description";
278 }
279 return $this->element_db_mapping[$db_col_name];
280 }
281
285 protected function getXmlNamespace(string $a_entity, string $a_schema_version): string
286 {
287 return "http://www.ilias.de/xml/Modules/ScormAicc/" . $a_entity;
288 }
289
293 public function getSupportedVersions(): array
294 {
295 return ["5.1.0"];
296 }
297
301 private function buildManifest(): string
302 {
303 $manWriter = new ilXmlWriter();
304 $manWriter->xmlHeader();
305 foreach ($this->_archive['files'] as $key => $value) {
306 $manWriter->xmlElement($key, null, $value, true, true);
307 }
308
309 return $manWriter->xmlDumpMem(true);
310 }
311
317 private function buildProperties($a_entity, bool $a_omit_header = false): string
318 {
319 $writer = new ilXmlWriter();
320
321 if (!$a_omit_header) {
322 $writer->xmlHeader();
323 }
324
325 $writer->appendXML("\n");
326 $writer->xmlStartTag('DataSet', array(
327 "InstallationId" => IL_INST_ID,
328 "InstallationUrl" => ILIAS_HTTP_PATH,
329 "TopEntity" => $a_entity
330 ));
331
332 $writer->appendXML("\n");
333
334 foreach ($this->data as $key => $value) {
335 $writer->xmlElement($this->getElementNameByDbColumn($key), null, $value, true, true);
336 $writer->appendXML("\n");
337 }
338
339 $writer->xmlEndTag("DataSet");
340
341 return $writer->xmlDumpMem(false);
342 }
343}
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
A dataset contains in data in a common structure that can be shared and transformed for different pur...
static getLogger(string $a_component_id)
Get component logger.
getElementNameByDbColumn(string $db_col_name)
retrieve element name by database column name
buildProperties($a_entity, bool $a_omit_header=false)
getExtendedXmlRepresentation(string $exportArchiveDir, string $a_entity, string $a_schema_version, array $a_ids, string $a_field="", bool $a_omit_header=false, bool $a_omit_types=false)
own getXmlRepresentation function to embed zipfile in xml
getXmlNamespace(string $a_entity, string $a_schema_version)
Get xml namespace.
getTypes(string $a_entity, string $a_version)
Get field types for entity.
getDependencies(string $a_entity, string $a_version, ?array $a_rec=null, ?array $a_ids=null)
writeData(string $a_entity, string $a_version, int $a_id, array $data)
readData(string $a_entity, string $a_version, array $a_ids, string $a_field="")
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
const CLIENT_ID
Definition: constants.php:41
const ILIAS_WEB_DIR
Definition: constants.php:45
const IL_INST_ID
Definition: constants.php:40
return['delivery_method'=> 'php',]
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
global $DIC
Definition: shib_login.php:26