ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
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)
 
 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 = ""
 

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 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_compatibility" => ["db_col" => "ie_compatibility", "db_type" => "text"],
32  "Ie_force_render" => ["db_col" => "ie_force_render", "db_type" => "text"],
33  "Interactions" => ["db_col" => "interactions", "db_type" => "text"],
34  "Localization" => ["db_col" => "localization", "db_type" => "text"],
35  "MasteryScore" => ["db_col" => "mastery_score", "db_type" => "integer"],
36  "MaxAttempt" => ["db_col" => "max_attempt", "db_type" => "integer"],
37  "ModuleVersion" => ["db_col" => "module_version", "db_type" => "integer"],
38  "NoMenu" => ["db_col" => "no_menu", "db_type" => "text"],
39  "Objectives" => ["db_col" => "objectives", "db_type" => "text"],
40  "OfflineMode" => ["db_col" => "offline_mode", "db_type" => "text"],
41  "Online" => ["db_col" => "c_online", "db_type" => "text"],
42  "OpenMode" => ["db_col" => "open_mode", "db_type" => "integer"],
43  "Sequencing" => ["db_col" => "sequencing", "db_type" => "text"],
44  "SequencingExpertMode" => ["db_col" => "seq_exp_mode", "db_type" => "integer"],
45  "Session" => ["db_col" => "unlimited_session", "db_type" => "text"],
46  "StyleSheetId" => ["db_col" => "stylesheet", "db_type" => "integer"],
47  "SubType" => ["db_col" => "c_type", "db_type" => "text"],
48  "Time_from_lms" => ["db_col" => "time_from_lms", "db_type" => "text"],
49  "Tries" => ["db_col" => "question_tries", "db_type" => "integer"],
50  "Width" => ["db_col" => "width", "db_type" => "integer"]
51  ];
52 
53  $this->element_db_mapping = [];
54  foreach ($this->properties as $key => $value)
55  {
56  $this->element_db_mapping [$value["db_col"]] = $key;
57  }
58  }
Set document properties

Member Function Documentation

◆ buildMetaData()

ilScormAiccDataSet::buildMetaData (   $id)

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

Referenced by getExtendedXmlRepresentation().

270  {
271  require_once ("Services/MetaData/classes/class.ilMD2XML.php");
272  $md2xml = new ilMD2XML ($id, $id, "sahs");
273  $md2xml->startExport();
274  $xml = $md2xml->getXML();
275  return $xml;
276  }
+ Here is the caller graph for this function:

◆ getDependencies()

ilScormAiccDataSet::getDependencies ( )

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

312  {
313  return null;
314  }

◆ getElementNameByDbColumn()

ilScormAiccDataSet::getElementNameByDbColumn (   $db_col_name)

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

Referenced by getExtendedXmlRepresentation().

146  {
147  if ($db_col_name == "title") return "Title";
148  if ($db_col_name == "description") return "Description";
149  return $this->element_db_mapping[$db_col_name];
150  }
+ 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 
)

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

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

156  {
157  $GLOBALS["ilLog"]->write(json_encode($this->getTypes("sahs", "5.1.0"), JSON_PRETTY_PRINT));
158 
159  global $ilCtrl, $ilDB;
160  $this->dircnt = 1;
161 
162  $this->readData($a_entity, $a_schema_version, $a_ids, $a_field = "");
163  $id = $this->data["id"];
164 
165  require_once ("./Services/Export/classes/class.ilExport.php");
166  $exportDir = ilExport::_getExportDirectory($id);
167 
168  // step 1: check target release and supported versions
169  // step 2: init writer
170  require_once ("./Services/Xml/classes/class.ilXmlWriter.php");
171  $writer = new ilXmlWriter();
172  if (!$a_omit_header) { $writer->xmlHeader(); }
173 
174  $atts = array("InstallationId" => IL_INST_ID,
175  "InstallationUrl" => ILIAS_HTTP_PATH, "TopEntity" => $a_entity);
176 
177  $writer->appendXML ("\n");
178  $writer->xmlStartTag($this->getDSPrefixString().'DataSet', $atts);
179  $writer->appendXML ("\n");
180 
181  foreach ($this->data as $key => $value)
182  {
183  $writer->xmlElement($this->getElementNameByDbColumn ($key), Null, $value, TRUE, TRUE);
184  $writer->appendXML ("\n");
185  }
186 
187  $lmDir = ilUtil::getWebspaceDir ("filesystem")."/lm_data/lm_".$id;
188  $baseFileName = "sahs_" . $id;
189  $scormBasePath=$exportDir . "/" . $baseFileName;
190  if (!file_exists ($exportDir)) mkdir ($exportDir, 0755, true);
191 
192  ilUtil::zip($lmDir, $scormBasePath, true);
193  $scormFilePath = $scormBasePath . ".zip";
194 
195  $writer->xmlEndTag($this->getDSPrefixString()."DataSet");
196  $writer->appendXML ("\n");
197 
198  $xml = $writer->xmlDumpMem(false);
199  $baseExportName = time() . "__" . IL_INST_ID . "__". $baseFileName;
200  $xmlFilePath = $exportDir . "/" . $baseExportName . ".xml";
201 
202  if (!file_exists ($xmlFilePath))
203  {
204  $xmlFile = fopen ($xmlFilePath, "w");
205  fwrite ($xmlFile, $xml);
206  fclose($xmlFile);
207  }
208 
209  //create metadata
210  $metaData = $this->buildMetaData ($id);
211 
212  $metaDataFilePath = $exportDir . "/" . $baseExportName . "_metadata.xml";
213  if (!file_exists ($metaDataFilePath))
214  {
215  $metaDataFile = fopen ($metaDataFilePath, "w");
216  fwrite ($metaDataFile, $metaData);
217  fclose($metaDataFile);
218  }
219 
220  //create manifest file
221  $manWriter = new ilXmlWriter();
222  $manWriter->xmlHeader();
223  $manWriter->appendXML ("\n<content>\n");
224 
225  $files = [
226  "scormFile" => $baseFileName . ".zip",
227  "properties" => $baseFileName . ".xml",
228  "metadata" => "metadata.xml"
229  ];
230  foreach ($files as $key => $value)
231  {
232  $manWriter->xmlElement($key, Null, $value, TRUE, TRUE);
233  $manWriter->appendXML ("\n");
234  }
235 
236  $manWriter->appendXML ("</content>\n");
237  $manifest = $manWriter->xmlDumpMem(false);
238 
239  $manifestFilePath = $exportDir . "/" . $baseExportName . "_manifest.xml";
240  if (!file_exists ($manifestFilePath))
241  {
242  $manifestFile = fopen ($manifestFilePath, "w");
243  fwrite ($manifestFile, $manifest);
244  fclose($manifestFile);
245  }
246 
247  $zArchive = new zipArchive();
248  $fileName = $exportDir . "/" . $baseExportName . ".zip";
249 
250  if ($zArchive->open($fileName, ZipArchive::CREATE)!==TRUE) {
251  exit("cannot open <$fileName>\n");
252  }
253 
254  //creating final zip file
255  $zArchive->addFile($xmlFilePath, $baseFileName . ".xml");
256  $zArchive->addFile($scormFilePath, $baseFileName . ".zip");
257  $zArchive->addFile($manifestFilePath, "manifest.xml");
258  $zArchive->addFile($metaDataFilePath, "metadata.xml");
259  $zArchive->close();
260  //delete temporary files
261  unlink ($xmlFilePath);
262  unlink ($scormFilePath);
263  unlink ($manifestFilePath);
264  unlink ($metaDataFilePath);
265 
266  return $fileName;
267  }
$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.
XML writer class.
global $ilCtrl
Definition: ilias.php:18
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.
global $ilDB
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
getTypes($a_entity, $a_version)
Get field types for entity.
+ Here is the call graph for this function:

◆ getSupportedVersions()

ilScormAiccDataSet::getSupportedVersions ( )

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

317  {
318  return ["5.1.0"];
319  }

◆ 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 285 of file class.ilScormAiccDataSet.php.

References properties.

Referenced by getExtendedXmlRepresentation().

286  {
287  if ($a_entity == "sahs")
288  {
289  switch ($a_version)
290  {
291  case "5.1.0":
292  $types = [];
293  foreach ($this->properties as $key => $value)
294  $types[$key] = $value["db_type"];
295  return $types;
296  break;
297  }
298  }
299  }
Set document properties
+ Here is the caller graph for this function:

◆ getXmlNamespace()

ilScormAiccDataSet::getXmlNamespace (   $a_entity,
  $a_schema_version 
)

Get xml namespace.

Parameters

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

307  {
308  return "http://www.ilias.de/xml/Modules/ScormAicc/".$a_entity;
309  }

◆ 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, $ilDB, $query, $result, ilObject\_lookupObjectId(), data, and properties.

Referenced by getExtendedXmlRepresentation().

66  {
67  global $ilDB;
68 
69  $obj_id = ilObject::_lookupObjectId ($a_id);
70  $columns = [];
71  foreach ($this->properties as $property)
72  array_push ($columns, $property["db_col"]);
73 
74  $query = "SELECT " . implode (",", $columns) . " FROM " . $this->db_table;
75  $query .= " WHERE id=" . $ilDB->quote($obj_id, "integer");
76  $result = $ilDB->query($query);
77  $this->data = [];
78  if ($dataset = $ilDB->fetchAssoc($result))
79  {
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  {
88  $this->data ["title"] = $dataset["title"];
89  $this->data ["description"] = $dataset["description"];
90  }
91  }
Add some data
$result
static _lookupObjectId($a_ref_id)
lookup object id
global $ilDB
Set document properties
if(! $in) $columns
Definition: Utf8Test.php:45
+ Here is the call graph for this function:
+ 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 99 of file class.ilScormAiccDataSet.php.

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

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

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