ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
ilScormAiccDataSet Class Reference
+ Inheritance diagram for ilScormAiccDataSet:
+ Collaboration diagram for ilScormAiccDataSet:

Public Member Functions

 __construct ()
 
 readData ($a_entity, $a_version, $a_id, $a_field="")
 Read data. More...
 
 writeData ($a_entity, $a_version, $a_id, $data)
 Write properties for imported object (actually updates !!) More...
 
 getElementNameByDbColumn ($db_col_name)
 
 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 More...
 
 buildMetaData ($id)
 
 getXmlNamespace ($a_entity, $a_schema_version)
 Get xml namespace. More...
 
 getDependencies ()
 
 getSupportedVersions ()
 
- Public Member Functions inherited from ilDataSet
 __construct ()
 Constructor. More...
 
 init ($a_entity, $a_schema_version)
 Init. More...
 
 getSupportedVersions ()
 Get supported version. More...
 
 readData ($a_entity, $a_version, $a_ids)
 Read data from DB. More...
 
 setExportDirectories ($a_relative, $a_absolute)
 Set export directories. More...
 
 setImportDirectory ($a_val)
 Set import directory. More...
 
 getImportDirectory ()
 Get import directory. More...
 
 setDSPrefix ($a_val)
 Set XML dataset namespace prefix. More...
 
 getDSPrefix ()
 Get XML dataset namespace prefix. More...
 
 getDSPrefixString ()
 
 getDirectDataFromQuery ($a_query, $a_convert_to_leading_upper=true, $a_set=true)
 Get data from query.This is a standard procedure, all db field names are directly mapped to abstract fields. More...
 
 convertToLeadingUpper ($a_str)
 Make xyz_abc a XyzAbc string. More...
 
 getJsonRepresentation ()
 Get json representation. More...
 
 getXmlRepresentation ( $a_entity, $a_schema_version, $a_ids, $a_field="", $a_omit_header=false, $a_omit_types=false)
 Get xml representation <dataset install_id="123" install_url="..."> <types entity="table_name" version="4.0.1"> <ftype name="field_1" type="text"> <ftype name="field_2" type="date"> <ftype name="field_3" type="integer"> </types> <types ...> ... More...
 
 addRecordsXml ($a_writer, $a_prefixes, $a_entity, $a_schema_version, $a_ids, $a_field="")
 Add records xml. More...
 
 afterXmlRecordWriting ($a_entity, $a_version, $a_set)
 After xml record writing hook record. More...
 
 getNamespaces (&$namespaces, $a_entity, $a_schema_version)
 Get xml namespaces. More...
 
 getXmlRecord ($a_entity, $a_version, $a_set)
 Get xml record for version. More...
 
 getJsonRecord ($a_set)
 Get json record for version. More...
 
 getXmlTypes ($a_entity, $a_version)
 Get xml types. More...
 
 getJsonTypes ($a_entity, $a_version)
 Get json types. More...
 
 getXMLEntityName ($a_entity, $a_version)
 Get entity name for xml (may be overwritten) More...
 
 getXMLEntityTag ($a_entity, $a_schema_version)
 Get entity tag. More...
 
 getJsonEntityName ($a_entity, $a_version)
 Get entity name for json (may be overwritten) More...
 
 setImport ($a_val)
 Set import object. More...
 
 getImport ()
 Get import object. More...
 
 setCurrentInstallationId ($a_val)
 Set current installation id. More...
 
 getCurrentInstallationId ()
 Get current installation id. More...
 

Protected Member Functions

 getTypes ($a_entity, $a_version)
 Get field types for entity. More...
 
- Protected Member Functions inherited from ilDataSet
 getTypes ($a_entity, $a_version)
 Get (abstract) types for (abstract) field names. More...
 
 getXmlNamespace ($a_entity, $a_schema_version)
 Get xml namespace. More...
 
 createObjectExportId ($a_type, $a_id)
 Build ilias export id. More...
 
 parseObjectExportId ($a_id, $a_fallback_id=null)
 Parse export id. More...
 

Additional Inherited Members

- Data Fields inherited from ilDataSet
 $dircnt
 
const EXPORT_NO_INST_ID = 1
 
const EXPORT_ID_ILIAS_LOCAL = 2
 
const EXPORT_ID_ILIAS_LOCAL_INVALID = 3
 
const EXPORT_ID_ILIAS_REMOTE = 4
 
const EXPORT_ID_ILIAS_REMOTE_INVALID = 5
 
const EXPORT_ID = 6
 
const EXPORT_ID_INVALID = 7
 
- Protected Attributes inherited from ilDataSet
 $current_installation_id = ""
 
 $db
 
 $ds_log
 

Detailed Description

Definition at line 5 of file class.ilScormAiccDataSet.php.

Constructor & Destructor Documentation

◆ __construct()

ilScormAiccDataSet::__construct ( )

Definition at line 7 of file class.ilScormAiccDataSet.php.

References $key, and properties.

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  "Online" => ["db_col" => "c_online", "db_type" => "text"],
41  "OpenMode" => ["db_col" => "open_mode", "db_type" => "integer"],
42  "Sequencing" => ["db_col" => "sequencing", "db_type" => "text"],
43  "SequencingExpertMode" => ["db_col" => "seq_exp_mode", "db_type" => "integer"],
44  "Session" => ["db_col" => "unlimited_session", "db_type" => "text"],
45  "StyleSheetId" => ["db_col" => "stylesheet", "db_type" => "integer"],
46  "SubType" => ["db_col" => "c_type", "db_type" => "text"],
47  "Time_from_lms" => ["db_col" => "time_from_lms", "db_type" => "text"],
48  "Tries" => ["db_col" => "question_tries", "db_type" => "integer"],
49  "Width" => ["db_col" => "width", "db_type" => "integer"],
50  "IdSetting" => ["db_col" => "id_setting", "db_type" => "integer"],
51  "NameSetting" => ["db_col" => "name_setting", "db_type" => "integer"]
52  ];
53 
54  $this->element_db_mapping = [];
55  foreach ($this->properties as $key => $value) {
56  $this->element_db_mapping [$value["db_col"]] = $key;
57  }
58  }
Set document properties
$key
Definition: croninfo.php:18

Member Function Documentation

◆ buildMetaData()

ilScormAiccDataSet::buildMetaData (   $id)

Definition at line 285 of file class.ilScormAiccDataSet.php.

References $id, and $xml.

Referenced by getExtendedXmlRepresentation().

286  {
287  require_once("Services/MetaData/classes/class.ilMD2XML.php");
288  $md2xml = new ilMD2XML($id, $id, "sahs");
289  $md2xml->startExport();
290  $xml = $md2xml->getXML();
291  return $xml;
292  }
if(!array_key_exists('StateId', $_REQUEST)) $id
$xml
Definition: metadata.php:240
+ Here is the caller graph for this function:

◆ getDependencies()

ilScormAiccDataSet::getDependencies ( )

Definition at line 326 of file class.ilScormAiccDataSet.php.

327  {
328  return null;
329  }

◆ getElementNameByDbColumn()

ilScormAiccDataSet::getElementNameByDbColumn (   $db_col_name)

Definition at line 151 of file class.ilScormAiccDataSet.php.

Referenced by getExtendedXmlRepresentation().

152  {
153  if ($db_col_name == "title") {
154  return "Title";
155  }
156  if ($db_col_name == "description") {
157  return "Description";
158  }
159  return $this->element_db_mapping[$db_col_name];
160  }
+ Here is the caller graph for this function:

◆ getExtendedXmlRepresentation()

ilScormAiccDataSet::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

Parameters
$a_entity
$a_schema_version
$a_ids(obj_id)
string$a_field
bool$a_omit_header
bool$a_omit_types
Returns
string

Definition at line 173 of file class.ilScormAiccDataSet.php.

References $files, $GLOBALS, $id, $key, $xml, ilExport\_getExportDirectory(), array, buildMetaData(), data, exit, ilDataSet\getDSPrefixString(), getElementNameByDbColumn(), getTypes(), ilUtil\getWebspaceDir(), readData(), time, and ilUtil\zip().

174  {
175  $GLOBALS["ilLog"]->write(json_encode($this->getTypes("sahs", "5.1.0"), JSON_PRETTY_PRINT));
176 
177  $this->dircnt = 1;
178 
179  $this->readData($a_entity, $a_schema_version, $a_ids, $a_field = "");
180  $id = $this->data["id"];
181 
182  require_once("./Services/Export/classes/class.ilExport.php");
183  $exportDir = ilExport::_getExportDirectory($id);
184 
185  // step 1: check target release and supported versions
186  // step 2: init writer
187  require_once("./Services/Xml/classes/class.ilXmlWriter.php");
188  $writer = new ilXmlWriter();
189  if (!$a_omit_header) {
190  $writer->xmlHeader();
191  }
192 
193  $atts = array("InstallationId" => IL_INST_ID,
194  "InstallationUrl" => ILIAS_HTTP_PATH, "TopEntity" => $a_entity);
195 
196  $writer->appendXML("\n");
197  $writer->xmlStartTag($this->getDSPrefixString() . 'DataSet', $atts);
198  $writer->appendXML("\n");
199 
200  foreach ($this->data as $key => $value) {
201  $writer->xmlElement($this->getElementNameByDbColumn($key), null, $value, true, true);
202  $writer->appendXML("\n");
203  }
204 
205  $lmDir = ilUtil::getWebspaceDir("filesystem") . "/lm_data/lm_" . $id;
206  $baseFileName = "sahs_" . $id;
207  $scormBasePath=$exportDir . "/" . $baseFileName;
208  if (!file_exists($exportDir)) {
209  mkdir($exportDir, 0755, true);
210  }
211 
212  ilUtil::zip($lmDir, $scormBasePath, true);
213  $scormFilePath = $scormBasePath . ".zip";
214 
215  $writer->xmlEndTag($this->getDSPrefixString() . "DataSet");
216  $writer->appendXML("\n");
217 
218  $xml = $writer->xmlDumpMem(false);
219  $baseExportName = time() . "__" . IL_INST_ID . "__" . $baseFileName;
220  $xmlFilePath = $exportDir . "/" . $baseExportName . ".xml";
221 
222  if (!file_exists($xmlFilePath)) {
223  $xmlFile = fopen($xmlFilePath, "w");
224  fwrite($xmlFile, $xml);
225  fclose($xmlFile);
226  }
227 
228  //create metadata
229  $metaData = $this->buildMetaData($id);
230 
231  $metaDataFilePath = $exportDir . "/" . $baseExportName . "_metadata.xml";
232  if (!file_exists($metaDataFilePath)) {
233  $metaDataFile = fopen($metaDataFilePath, "w");
234  fwrite($metaDataFile, $metaData);
235  fclose($metaDataFile);
236  }
237 
238  //create manifest file
239  $manWriter = new ilXmlWriter();
240  $manWriter->xmlHeader();
241  $manWriter->appendXML("\n<content>\n");
242 
243  $files = [
244  "scormFile" => "content.zip",
245  "properties" => "properties.xml",
246  "metadata" => "metadata.xml"
247  ];
248  foreach ($files as $key => $value) {
249  $manWriter->xmlElement($key, null, $value, true, true);
250  $manWriter->appendXML("\n");
251  }
252 
253  $manWriter->appendXML("</content>\n");
254  $manifest = $manWriter->xmlDumpMem(false);
255 
256  $manifestFilePath = $exportDir . "/" . $baseExportName . "_manifest.xml";
257  if (!file_exists($manifestFilePath)) {
258  $manifestFile = fopen($manifestFilePath, "w");
259  fwrite($manifestFile, $manifest);
260  fclose($manifestFile);
261  }
262 
263  $zArchive = new zipArchive();
264  $fileName = $exportDir . "/" . $baseExportName . ".zip";
265 
266  if ($zArchive->open($fileName, ZipArchive::CREATE)!==true) {
267  exit("cannot open <$fileName>\n");
268  }
269 
270  //creating final zip file
271  $zArchive->addFile($xmlFilePath, $baseExportName . '/properties.xml');
272  $zArchive->addFile($scormFilePath, $baseExportName . '/content.zip');
273  $zArchive->addFile($manifestFilePath, $baseExportName . '/' . "manifest.xml");
274  $zArchive->addFile($metaDataFilePath, $baseExportName . '/' . "metadata.xml");
275  $zArchive->close();
276  //delete temporary files
277  unlink($xmlFilePath);
278  unlink($scormFilePath);
279  unlink($manifestFilePath);
280  unlink($metaDataFilePath);
281 
282  return $fileName;
283  }
$files
Definition: add-vimline.php:18
Add some data
readData($a_entity, $a_version, $a_id, $a_field="")
Read data.
$GLOBALS['loaded']
Global hash that tracks already loaded includes.
if(!array_key_exists('StateId', $_REQUEST)) $id
XML writer class.
$xml
Definition: metadata.php:240
static zip($a_dir, $a_file, $compress_content=false)
zips given directory/file into given zip.file
Create styles array
The data for the language used.
getElementNameByDbColumn($db_col_name)
static _getExportDirectory($a_obj_id, $a_type="xml", $a_obj_type="", $a_entity="")
Get export directory for an repository object.
Add data(end) time
Method that wraps PHPs time in order to allow simulations with the workflow.
static getWebspaceDir($mode="filesystem")
get webspace directory
$key
Definition: croninfo.php:18
getTypes($a_entity, $a_version)
Get field types for entity.
+ Here is the call graph for this function:

◆ getSupportedVersions()

ilScormAiccDataSet::getSupportedVersions ( )

Definition at line 331 of file class.ilScormAiccDataSet.php.

332  {
333  return ["5.1.0"];
334  }

◆ getTypes()

ilScormAiccDataSet::getTypes (   $a_entity,
  $a_version 
)
protected

Get field types for entity.

Parameters
string$a_entityentity
string$a_versionversion number
Returns
array types array

Definition at line 301 of file class.ilScormAiccDataSet.php.

References $key, and properties.

Referenced by getExtendedXmlRepresentation().

302  {
303  if ($a_entity == "sahs") {
304  switch ($a_version) {
305  case "5.1.0":
306  $types = [];
307  foreach ($this->properties as $key => $value) {
308  $types[$key] = $value["db_type"];
309  }
310  return $types;
311  break;
312  }
313  }
314  }
Set document properties
$key
Definition: croninfo.php:18
+ Here is the caller graph for this function:

◆ getXmlNamespace()

ilScormAiccDataSet::getXmlNamespace (   $a_entity,
  $a_schema_version 
)

Get xml namespace.

Parameters

Definition at line 321 of file class.ilScormAiccDataSet.php.

322  {
323  return "http://www.ilias.de/xml/Modules/ScormAicc/" . $a_entity;
324  }

◆ readData()

ilScormAiccDataSet::readData (   $a_entity,
  $a_version,
  $a_id,
  $a_field = "" 
)

Read data.

Parameters

Definition at line 65 of file class.ilScormAiccDataSet.php.

References $columns, $dataset, $ilDB, $query, $result, data, and properties.

Referenced by getExtendedXmlRepresentation().

66  {
67  global $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  }
Add some data
$result
$dataset
Definition: showstats.php:45
$query
global $ilDB
Set document properties
if(! $in) $columns
Definition: Utf8Test.php:45
+ Here is the caller graph for this function:

◆ writeData()

ilScormAiccDataSet::writeData (   $a_entity,
  $a_version,
  $a_id,
  $data 
)

Write properties for imported object (actually updates !!)

Parameters
$datacontains imported module properties from xml file
Returns

Definition at line 98 of file class.ilScormAiccDataSet.php.

References $columns, $data, $ilDB, $ilLog, $key, and properties.

99  {
100  global $ilDB, $ilLog;
101  if (count($data) > 0) {
102  $columns = [];
103  foreach ($this->properties as $key => $value) {
104  if ($key == "Id" || $key == "title"|| $key == "description") {
105  continue;
106  }
107  //fix localization and mastery_score
108  if ($key == "MasteryScore" && $data[$key][0] == 0) {
109  continue;
110  }
111  if ($key == "Localization" && $data[$key][0] == "") {
112  continue;
113  }
114  //end fix
115  if (isset($data[$key])) {
116  if (count($data[$key]) > 0) {
117  $columns [$value["db_col"]] = [$value["db_type"], $data[$key][0]];
118  }
119  }
120  }
121  if (count($columns) > 0) {
122  $conditions ["id"] = ["integer", $a_id];
123  $ilDB->update($this->db_table, $columns, $conditions);
124  }
125 
126  //setting title and description in table object_data
127  $od_table = "object_data";
128  $od_properties = [
129  "Title" => ["db_col" => "title", "db_type" => "text"],
130  "Description" => ["db_col" => "description", "db_type" => "text"]
131  ];
132  foreach ($od_properties as $key => $value) {
133  if (isset($data[$key])) {
134  if (count($data[$key]) > 0) {
135  $od_columns [$value["db_col"]] = [$value["db_type"], $data[$key][0]];
136  }
137  }
138 
139  if (count($od_columns) > 0) {
140  $od_conditions ["obj_id"] = ["integer", $a_id];
141  $ilDB->update("object_data", $od_columns, $od_conditions);
142  }
143  }
144  } else {
145  $ilLog->write("no module properties for imported object");
146  }
147  }
global $ilDB
Set document properties
if(! $in) $columns
Definition: Utf8Test.php:45
$key
Definition: croninfo.php:18

The documentation for this class was generated from the following file: