ILIAS  release_8 Revision v8.24
class.ilCmiXapiDataSet.php
Go to the documentation of this file.
1<?php
2
3declare(strict_types=1);
28{
29 private array $_data = [];
30 private array $_archive = [];
31 private array $_element_db_mapping = [];
32 public array $_cmixSettingsProperties = [
33 "LrsTypeId" => ["db_col" => "lrs_type_id", "db_type" => "integer"]
34 ,
35 "ContentType" => ["db_col" => "content_type", "db_type" => "text"]
36 ,
37 "SourceType" => ["db_col" => "source_type", "db_type" => "text"]
38 ,
39 "ActivityId" => ["db_col" => "activity_id", "db_type" => "text"]
40 ,
41 "Instructions" => ["db_col" => "instructions", "db_type" => "text"]
42 // ,"OfflineStatus" => ["db_col" => "offline_status", "db_type" => "integer"]
43 ,
44 "LaunchUrl" => ["db_col" => "launch_url", "db_type" => "text"]
45 ,
46 "AuthFetchUrl" => ["db_col" => "auth_fetch_url", "db_type" => "integer"]
47 ,
48 "LaunchMethod" => ["db_col" => "launch_method", "db_type" => "text"]
49 ,
50 "LaunchMode" => ["db_col" => "launch_mode", "db_type" => "text"]
51 ,
52 "MasteryScore" => ["db_col" => "mastery_score", "db_type" => "float"]
53 ,
54 "KeepLp" => ["db_col" => "keep_lp", "db_type" => "integer"]
55 ,
56 "PrivacyIdent" => ["db_col" => "privacy_ident", "db_type" => "integer"]
57 ,
58 "PrivacyName" => ["db_col" => "privacy_name", "db_type" => "integer"]
59 ,
60 "UsrPrivacyComment" => ["db_col" => "usr_privacy_comment", "db_type" => "text"]
61 ,
62 "ShowStatements" => ["db_col" => "show_statements", "db_type" => "integer"]
63 ,
64 "XmlManifest" => ["db_col" => "xml_manifest", "db_type" => "text"]
65 ,
66 "Version" => ["db_col" => "version", "db_type" => "integer"]
67 ,
68 "HighscoreEnabled" => ["db_col" => "highscore_enabled", "db_type" => "integer"]
69 ,
70 "HighscoreAchievedTs" => ["db_col" => "highscore_achieved_ts", "db_type" => "integer"]
71 ,
72 "HighscorePercentage" => ["db_col" => "highscore_percentage", "db_type" => "integer"]
73 ,
74 "HighscoreWtime" => ["db_col" => "highscore_wtime", "db_type" => "integer"]
75 ,
76 "HighscoreOwnTable" => ["db_col" => "highscore_own_table", "db_type" => "integer"]
77 ,
78 "HighscoreTopTable" => ["db_col" => "highscore_top_table", "db_type" => "integer"]
79 ,
80 "HighscoreTopNum" => ["db_col" => "highscore_top_num", "db_type" => "integer"]
81 ,
82 "BypassProxy" => ["db_col" => "bypass_proxy", "db_type" => "integer"]
83 ,
84 "OnlyMoveon" => ["db_col" => "only_moveon", "db_type" => "integer"]
85 ,
86 "Achieved" => ["db_col" => "achieved", "db_type" => "integer"]
87 ,
88 "Answered" => ["db_col" => "answered", "db_type" => "integer"]
89 ,
90 "Completed" => ["db_col" => "completed", "db_type" => "integer"]
91 ,
92 "Failed" => ["db_col" => "failed", "db_type" => "integer"]
93 ,
94 "Initialized" => ["db_col" => "initialized", "db_type" => "integer"]
95 ,
96 "Passed" => ["db_col" => "passed", "db_type" => "integer"]
97 ,
98 "Progressed" => ["db_col" => "progressed", "db_type" => "integer"]
99 ,
100 "Satisfied" => ["db_col" => "satisfied", "db_type" => "integer"]
101 ,
102 "Terminated" => ["db_col" => "c_terminated", "db_type" => "integer"]
103 ,
104 "HideData" => ["db_col" => "hide_data", "db_type" => "integer"]
105 ,
106 "Timestamp" => ["db_col" => "c_timestamp", "db_type" => "integer"]
107 ,
108 "Duration" => ["db_col" => "duration", "db_type" => "integer"]
109 ,
110 "NoSubstatements" => ["db_col" => "no_substatements", "db_type" => "integer"]
111 ,
112 "PublisherId" => ["db_col" => "publisher_id", "db_type" => "text"]
113 ,
114 "AnonymousHomepage" => ["db_col" => "anonymous_homepage", "db_type" => "integer"]
115 ,
116 "MoveOn" => ["db_col" => "moveon", "db_type" => "text"]
117 ,
118 "LaunchParameters" => ["db_col" => "launch_parameters", "db_type" => "text"]
119 ,
120 "EntitlementKey" => ["db_col" => "entitlement_key", "db_type" => "text"]
121 ,
122 "SwitchToReview" => ["db_col" => "switch_to_review", "db_type" => "integer"]
123 ];
124
129 public function __construct(int $a_id = 0, bool $a_reference = true)
130 {
131 global $DIC;
134// $this->_main_object_id = $a_id;
135// $this->_dataSetMapping = ilObjCmiXapi::getInstance($a_id, $a_reference)->getDataSetMapping();
136
137 //var_dump($this->_dataSetMapping); exit;
139
140 foreach ($this->_cmixSettingsProperties as $key => $value) {
141 $this->_element_db_mapping [$value["db_col"]] = $key;
142 }
143 }
144
149 protected function getDependencies(
150 string $a_entity,
151 string $a_version,
152 ?array $a_rec = null,
153 ?array $a_ids = null
154 ): array {
155 return [];
156 }
157 public function getCmiXapiXmlRepresentation(
158 string $a_entity,
159 string $a_schema_version,
160 array $a_ids,
161 string $a_field = "",
162 bool $a_omit_header = false,
163 bool $a_omit_types = false
164 ): string {
165 global $DIC;
168 $GLOBALS["ilLog"]->write(json_encode($this->getTypes("cmix", "5.1.0"), JSON_PRETTY_PRINT));
169
170 $this->dircnt = 1;
171
172 $this->readData($a_entity, $a_schema_version, $a_ids);
173
174 //var_dump($this->data); exit;
175 $id = (int) $this->data["Id"];
176
177 // prepare archive skeleton
178 $objTypeAndId = "cmix_" . $id;
179 $this->_archive['directories'] = [
180 "exportDir" => ilExport::_getExportDirectory($id)
181 ,
182 "tempDir" => ilExport::_getExportDirectory($id) . "/temp"
183 ,
184 "archiveDir" => time() . "__" . IL_INST_ID . "__" . $objTypeAndId
185 ,
186 "moduleDir" => "cmix_" . $id
187 ];
188
189 $this->_archive['files'] = [
190 "properties" => "properties.xml",
191 "metadata" => "metadata.xml",
192 "manifest" => 'manifest.xml',
193 ];
194 if (false !== strpos($this->data['SourceType'], 'local')) {
195 $this->_archive['files']['content'] = "content.zip";
196 }
197
198 //var_dump([$this->_archive, $this->buildManifest()]); exit;
199
200 // Prepare temp storage on the local filesystem
201 if (!file_exists($this->_archive['directories']['exportDir'])) {
202 mkdir($this->_archive['directories']['exportDir'], 0755, true);
203 //$DIC->filesystem()->storage()->createDir($this->_archive['directories']['tempDir']);
204 }
205 if (!file_exists($this->_archive['directories']['tempDir'])) {
206 mkdir($this->_archive['directories']['tempDir'], 0755, true);
207 //$DIC->filesystem()->storage()->createDir($this->_archive['directories']['tempDir']);
208 }
209
210 // build metadata xml file
211 file_put_contents(
212 $this->_archive['directories']['tempDir'] . "/" . $this->_archive['files']['metadata'],
213 $this->buildMetaData($id)
214 );
215
216 // build manifest xml file
217 file_put_contents(
218 $this->_archive['directories']['tempDir'] . "/" . $this->_archive['files']['manifest'],
219 $this->buildManifest()
220 );
221
222 // build content zip file
223 if (isset($this->_archive['files']['content'])) {
224 $lmDir = ilFileUtils::getWebspaceDir("filesystem") . "/lm_data/lm_" . $id;
226 $lmDir,
227 $this->_archive['directories']['tempDir'] . "/" . substr($this->_archive['files']['content'], 0, -4),
228 true
229 );
230 }
231
232 // build property xml file
233 file_put_contents(
234 $this->_archive['directories']['tempDir'] . "/" . $this->_archive['files']['properties'],
235 $this->buildProperties($a_entity, $a_omit_header)
236 );
237
238 // zip tempDir and append to export folder
239
240 $fileName = $this->_archive['directories']['exportDir'] . "/" . $this->_archive['directories']['archiveDir'] . ".zip";
241 $zArchive = new ZipArchive();
242 if ($zArchive->open($fileName, ZipArchive::CREATE) !== true) {
243 exit("cannot open <$fileName>\n");
244 }
245 $zArchive->addFile(
246 $this->_archive['directories']['tempDir'] . "/" . $this->_archive['files']['properties'],
247 $this->_archive['directories']['archiveDir'] . '/properties.xml'
248 );
249 $zArchive->addFile(
250 $this->_archive['directories']['tempDir'] . "/" . $this->_archive['files']['manifest'],
251 $this->_archive['directories']['archiveDir'] . '/' . "manifest.xml"
252 );
253 $zArchive->addFile(
254 $this->_archive['directories']['tempDir'] . "/" . $this->_archive['files']['metadata'],
255 $this->_archive['directories']['archiveDir'] . '/' . "metadata.xml"
256 );
257 if (isset($this->_archive['files']['content'])) {
258 $zArchive->addFile(
259 $this->_archive['directories']['tempDir'] . "/" . $this->_archive['files']['content'],
260 $this->_archive['directories']['archiveDir'] . '/content.zip'
261 );
262 }
263 //var_dump($zArchive); exit;
264 $zArchive->close();
265
266 /*
267 ilUtil::zip(
268 $this->_archive['directories']['tempDir'],
269 $this->_archive['directories']['archiveDir'] . ".zip"
270 );
271 */
272
273 // unlink tempDir and its content
274 unlink($this->_archive['directories']['tempDir'] . "/metadata.xml");
275 unlink($this->_archive['directories']['tempDir'] . "/manifest.xml");
276 unlink($this->_archive['directories']['tempDir'] . "/properties.xml");
277 if (isset($this->_archive['files']['content'])) {
278 unlink($this->_archive['directories']['tempDir'] . "/content.zip");
279 }
280 //unlink($this->_archive['directories']['tempDir']);
281 //$DIC->filesystem()->storage()->readAndDelete($this->_archive['directories']['tempDir']);
282 //$DIC->filesystem()->storage()->deleteDir($this->_archive['directories']['tempDir']);
283
284 //var_dump($this->_archive); exit;
285
286 return $fileName;
287 }
288
295 protected function getTypes(string $a_entity, string $a_version): array
296 {
297 $types = [];
298 foreach ($this->_cmixSettingsProperties as $key => $value) {
299 $types[$key] = $value["db_type"];
300 }
301 //var_dump($types); exit;
302 //return $types;
303
304 if ($a_entity == "cmix") {
305 switch ($a_version) {
306 case "5.1.0":
307 $types = [];
308 foreach ($this->_cmixSettingsProperties as $key => $value) {
309 $types[$key] = $value["db_type"];
310 }
311 //return $types;
312 break;
313 }
314 }
315 return $types;
316 }
317
318 public function readData(string $a_entity, string $a_version, array $a_ids): void
319 {
320 global $DIC;
323 //$a_ids = [];
324 if (!is_array($a_ids)) {
325 $a_ids = array($a_ids);
326 }
327
328 //var_dump([$a_entity, $a_version, $a_id]); exit;
329 if ($a_entity == "cmix") {
330 switch ($a_version) {
331 case "5.1.0":
332 $this->getDirectDataFromQuery("SELECT obj_id id, title, description " .
333 " FROM object_data " .
334 "WHERE " .
335 $DIC->database()->in("obj_id", $a_ids, false, "integer"));
336 break;
337 } // EOF switch
338 } // EOF if( $a_entity == "cmix" )
339
340 foreach ($this->data as $key => $data) {
341 $query = "SELECT " . implode(",", array_keys($this->_element_db_mapping)) . " ";
342 $query .= "FROM `cmix_settings` ";
343 $query .= "WHERE " . $DIC->database()->in("obj_id", $a_ids, false, "integer");
344 $result = $DIC->database()->query($query);
345 //$this->data = [];
346 if ($dataset = $DIC->database()->fetchAssoc($result)) {
347 $this->_data = $dataset;
348 }
349
350 //foreach( $this->_data AS $key => $data ) {
351 foreach ($this->_data as $dbColName => $value) {
352 $attr = $this->_element_db_mapping[$dbColName];
353 $this->data[$key][$attr] = $value;
354 //$this->data[$key][$dbColName] = $value;
355 } // EOF foreach ($this->_dataSetMapping as $dbColName => $value)
356 } // EOF foreach( $this->_data AS $key => $data )
357 $this->data = $this->data[0];
358 //var_dump($this->data); exit;
359 }
360
361 public function buildMetaData(int $id): string
362 {
363 $md2xml = new ilMD2XML($id, $id, "cmix");
364 $md2xml->startExport();
365 return $md2xml->getXML();
366 }
367
368 private function buildManifest(): string
369 {
370 $manWriter = new ilXmlWriter();
371 $manWriter->xmlHeader();
372 foreach ($this->_archive['files'] as $key => $value) {
373 $manWriter->xmlElement($key, null, $value, true, true);
374 }
375 #$manWriter->appendXML ("</content>\n");
376 return $manWriter->xmlDumpMem(true);
377 }
378
382 private function buildProperties($a_entity, bool $a_omit_header = false): string
383 {
384 $atts = array(
385 "InstallationId" => IL_INST_ID,
386 "InstallationUrl" => ILIAS_HTTP_PATH,
387 "TopEntity" => $a_entity
388 );
389
390 $writer = new ilXmlWriter();
391
392 $writer->xmlStartTag('DataSet', $atts);
393
394 if (!$a_omit_header) {
395 $writer->xmlHeader();
396 }
397
398 foreach ($this->data as $key => $value) {
399 $writer->xmlElement($key, null, $value, true, true);
400 }
401
402 $writer->xmlEndTag("DataSet");
403
404 return $writer->xmlDumpMem(true);
405 }
406
407 public function importRecord(
408 string $a_entity,
409 array $a_types,
410 array $a_rec,
411 ilImportMapping $a_mapping,
412 string $a_schema_version
413 ): void {
414 //var_dump( [$a_entity, $a_types, $a_rec, $a_mapping, $a_schema_version] ); exit;
415 switch ($a_entity) {
416 case "cmix":
417
418 if ($new_id = $a_mapping->getMapping('Services/Container', 'objs', $a_rec['Id'])) {
419 $newObj = ilObjectFactory::getInstanceByObjId((int) $new_id, false);
420 } else {
421 $newObj = new ilObjCmiXapi();
422 $newObj->setType("cmix");
423 $newObj->create(true);
424 }
425
426 $newObj->setTitle($a_rec["Title"]);
427 $newObj->setDescription($a_rec["Description"]);
428 $newObj->update();
429
430 //$this->current_obj = $newObj;
431 $a_mapping->addMapping("Modules/CmiXapi", "cmix", $a_rec["Id"], (string) $newObj->getId());
432 break;
433 }
434 }
435
440 public function getSupportedVersions(): array
441 {
442 return array("5.1.0");
443 }
444
448 public function getXmlNamespace(string $a_entity, string $a_schema_version): string
449 {
450 return "http://www.ilias.de/xml/Modules/CmiXapi/" . $a_entity;
451 }
452}
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
if(!defined('PATH_SEPARATOR')) $GLOBALS['_PEAR_default_error_mode']
Definition: PEAR.php:64
getSupportedVersions()
Get supported versions.
getXmlNamespace(string $a_entity, string $a_schema_version)
Get xml namespace.
getTypes(string $a_entity, string $a_version)
Get field types for entity.
buildProperties($a_entity, bool $a_omit_header=false)
getDependencies(string $a_entity, string $a_version, ?array $a_rec=null, ?array $a_ids=null)
Determine the dependent sets of data.
importRecord(string $a_entity, array $a_types, array $a_rec, ilImportMapping $a_mapping, string $a_schema_version)
Needs to be overwritten for import use case.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static _getExportDirectory(int $a_obj_id, string $a_type="xml", string $a_obj_type="", string $a_entity="")
Get export directory for an repository object.
static getWebspaceDir(string $mode="filesystem")
get webspace directory
static zip(string $a_dir, string $a_file, bool $compress_content=false)
zips given directory/file into given zip.file
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
addMapping(string $a_comp, string $a_entity, string $a_old_id, string $a_new_id)
getMapping(string $a_comp, string $a_entity, string $a_old_id)
static getInstanceByObjId(?int $obj_id, bool $stop_on_error=true)
get an instance of an Ilias object by object id
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
const IL_INST_ID
Definition: constants.php:40
return['3gp', '7z', 'ai', 'aif', 'aifc', 'aiff', 'au', 'arw', 'avi', 'backup', 'bak', 'bas', 'bpmn', 'bpmn2', 'bmp', 'bib', 'bibtex', 'bz', 'bz2', 'c', 'c++', 'cc', 'cct', 'cdf', 'cer', 'class', 'cls', 'conf', 'cpp', 'crt', 'crs', 'crw', 'cr2', 'css', 'cst', 'csv', 'cur', 'db', 'dcr', 'des', 'dng', 'doc', 'docx', 'dot', 'dotx', 'dtd', 'dvi', 'el', 'eps', 'epub', 'f', 'f77', 'f90', 'flv', 'for', 'g3', 'gif', 'gl', 'gan', 'ggb', 'gsd', 'gsm', 'gtar', 'gz', 'gzip', 'h', 'hpp', 'htm', 'html', 'htmls', 'ibooks', 'ico', 'ics', 'ini', 'ipynb', 'java', 'jbf', 'jpeg', 'jpg', 'js', 'jsf', 'jso', 'json', 'latex', 'lang', 'less', 'log', 'lsp', 'ltx', 'm1v', 'm2a', 'm2v', 'm3u', 'm4a', 'm4v', 'markdown', 'm', 'mat', 'md', 'mdl', 'mdown', 'mid', 'min', 'midi', 'mobi', 'mod', 'mov', 'movie', 'mp2', 'mp3', 'mp4', 'mpa', 'mpeg', 'mpg', 'mph', 'mpga', 'mpp', 'mpt', 'mpv', 'mpx', 'mv', 'mw', 'mv4', 'nb', 'nbp', 'nef', 'nif', 'niff', 'obj', 'obm', 'odt', 'ods', 'odp', 'odg', 'odf', 'oga', 'ogg', 'ogv', 'old', 'p', 'pas', 'pbm', 'pcl', 'pct', 'pcx', 'pdf', 'pgm', 'pic', 'pict', 'png', 'por', 'pov', 'project', 'properties', 'ppa', 'ppm', 'pps', 'ppsx', 'ppt', 'pptx', 'ppz', 'ps', 'psd', 'pwz', 'qt', 'qtc', 'qti', 'qtif', 'r', 'ra', 'ram', 'rar', 'rast', 'rda', 'rev', 'rexx', 'ris', 'rf', 'rgb', 'rm', 'rmd', 'rmi', 'rmm', 'rmp', 'rt', 'rtf', 'rtx', 'rv', 's', 's3m', 'sav', 'sbs', 'sec', 'sdml', 'sgm', 'sgml', 'smi', 'smil', 'srt', 'sps', 'spv', 'stl', 'svg', 'swa', 'swf', 'swz', 'tar', 'tex', 'texi', 'texinfo', 'text', 'tgz', 'tif', 'tiff', 'ttf', 'txt', 'tmp', 'uvproj', 'vdf', 'vimeo', 'viv', 'vivo', 'vrml', 'vsdx', 'wav', 'webm', 'wmv', 'wmx', 'wmz', 'woff', 'wwd', 'xhtml', 'xif', 'xls', 'xlsx', 'xmind', 'xml', 'xsl', 'xsd', 'zip']
global $DIC
Definition: feed.php:28
exit
Definition: login.php:28
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
string $key
Consumer key/client ID value.
Definition: System.php:193
$query