ILIAS  release_8 Revision v8.24
class.ilDataSetImportParser.php
Go to the documentation of this file.
1<?php
2
3/******************************************************************************
4 *
5 * This file is part of ILIAS, a powerful learning management system.
6 *
7 * ILIAS is licensed with the GPL-3.0, you should have received a copy
8 * of said license along with the source code.
9 *
10 * If this is not the case or you just want to try ILIAS, you'll find
11 * us at:
12 * https://www.ilias.de
13 * https://github.com/ILIAS-eLearning
14 *
15 *****************************************************************************/
22{
23 protected string $dspref;
24 protected string $schema_version;
25 protected string $top_entity;
26 protected ilDataSet $ds;
27 protected ?ilImport $import = null; // import object
28 protected array $entities = array(); // types array
29 protected string $current_entity = ""; // current entity
30 protected string $current_version = ""; // current version
31 protected array $current_ftypes = array(); // current field types
32 protected bool $entities_sent = false; // sent entities to import class?
33 protected bool $in_record = false; // are we currently in a rec tag?
34 protected string $current_field = ""; // current field
35 protected array $current_field_values = array(); // current field values
36 protected string $current_installation_id = "";
37 protected string $chr_data = "";
39
40 public function __construct(
41 string $a_top_entity,
42 string $a_schema_version,
43 string $a_xml,
44 ilDataSet $a_ds,
45 ilImportMapping $a_mapping
46 ) {
47 $this->ds = $a_ds;
48 $this->mapping = $a_mapping;
49 $this->top_entity = $a_top_entity;
50 $this->schema_version = $a_schema_version;
51 $this->dspref = ($this->ds->getDSPrefix() !== "")
52 ? $this->ds->getDSPrefix() . ":"
53 : "";
54
56 $this->setXMLContent($a_xml);
57 $this->startParsing();
58 }
59
60 public function getCurrentInstallationId(): string
61 {
63 }
64
65
66 public function setHandlers($a_xml_parser): void
67 {
68 xml_set_object($a_xml_parser, $this);
69 xml_set_element_handler($a_xml_parser, 'handleBeginTag', 'handleEndTag');
70 xml_set_character_data_handler($a_xml_parser, 'handleCharacterData');
71 }
72
73
74 public function handleBeginTag(
75 $a_xml_parser,
76 string $a_name,
77 array $a_attribs
78 ): void {
79 switch ($a_name) {
80 case $this->dspref . "DataSet":
81// $this->import->initDataset($this->ds_component, $a_attribs["top_entity"]);
82 $this->current_installation_id = $a_attribs["InstallationId"];
83 $this->ds->setCurrentInstallationId($a_attribs["InstallationId"]);
84 break;
85
86 case $this->dspref . "Types":
87 $this->current_entity = $a_attribs["Entity"];
88 $this->current_version = $a_attribs["Version"];
89 break;
90
91 case $this->dspref . "FieldType":
92 $this->current_ftypes[$a_attribs["Name"]] =
93 $a_attribs["Type"];
94 break;
95
96 case $this->dspref . "Rec":
97 $this->current_entity = $a_attribs["Entity"];
98 $this->in_record = true;
99 $this->current_field_values = array();
100 break;
101
102 default:
103 if ($this->in_record) {
104 $field = explode(":", $a_name); // remove namespace
105 $field = $field[count($field) - 1];
106 $this->current_field = $field;
107 }
108 }
109 }
110
111 public function handleEndTag(
112 $a_xml_parser,
113 string $a_name
114 ): void {
115 switch ($a_name) {
116 case $this->dspref . "Types":
117 $this->entities[$this->current_entity] =
118 array(
119 "version" => $this->current_version,
120 "types" => $this->current_ftypes
121 );
122 $this->current_ftypes = array();
123 $this->current_entity = "";
124 $this->current_version = "";
125 break;
126
127 case $this->dspref . "Rec":
128 $this->ds->importRecord(
129 $this->current_entity,
130 $this->entities[$this->current_entity]["types"] ?? [],
131 $this->current_field_values,
132 $this->mapping,
133 $this->schema_version
134 );
135 $this->in_record = false;
136 $this->current_entity = "";
137 $this->current_field_values = array();
138 break;
139
140 default:
141 if ($this->in_record && $this->current_field !== "") {
142 $this->current_field_values[$this->current_field] =
143 $this->chr_data;
144 }
145 $this->current_field = "";
146 break;
147 }
148
149 $this->chr_data = "";
150 }
151
152
153 public function handleCharacterData(
154 $a_xml_parser,
155 string $a_data
156 ): void {
157 $this->chr_data .= $a_data;
158 }
159}
Manifest parser for ILIAS standard export files.
handleCharacterData( $a_xml_parser, string $a_data)
handleBeginTag( $a_xml_parser, string $a_name, array $a_attribs)
handleEndTag( $a_xml_parser, string $a_name)
__construct(string $a_top_entity, string $a_schema_version, string $a_xml, ilDataSet $a_ds, ilImportMapping $a_mapping)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
setXMLContent(string $a_xml_content)
startParsing()
stores xml data in array
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc