ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilDataSetImportParser.php
Go to the documentation of this file.
1<?php
2
25{
26 protected string $dspref;
27 protected string $schema_version;
28 protected string $top_entity;
29 protected ilDataSet $ds;
30 protected ?ilImport $import = null; // import object
31 protected array $entities = array(); // types array
32 protected string $current_entity = ""; // current entity
33 protected string $current_version = ""; // current version
34 protected array $current_ftypes = array(); // current field types
35 protected bool $entities_sent = false; // sent entities to import class?
36 protected bool $in_record = false; // are we currently in a rec tag?
37 protected string $current_field = ""; // current field
38 protected array $current_field_values = array(); // current field values
39 protected string $current_installation_id = "";
40 protected string $chr_data = "";
42
43 public function __construct(
44 string $a_top_entity,
45 string $a_schema_version,
46 string $a_xml,
47 ilDataSet $a_ds,
48 ilImportMapping $a_mapping
49 ) {
50 $this->ds = $a_ds;
51 $this->mapping = $a_mapping;
52 $this->top_entity = $a_top_entity;
53 $this->schema_version = $a_schema_version;
54 $this->dspref = ($this->ds->getDSPrefix() !== "")
55 ? $this->ds->getDSPrefix() . ":"
56 : "";
57
59 $this->setXMLContent($a_xml);
60 $this->startParsing();
61 }
62
63 public function getCurrentInstallationId(): string
64 {
66 }
67
68
69 public function setHandlers($a_xml_parser): void
70 {
71 xml_set_element_handler($a_xml_parser, $this->handleBeginTag(...), $this->handleEndTag(...));
72 xml_set_character_data_handler($a_xml_parser, $this->handleCharacterData(...));
73 }
74
75
76 public function handleBeginTag(
77 $a_xml_parser,
78 string $a_name,
79 array $a_attribs
80 ): void {
81 switch ($a_name) {
82 case $this->dspref . "DataSet":
83 // $this->import->initDataset($this->ds_component, $a_attribs["top_entity"]);
84 $this->current_installation_id = $a_attribs["InstallationId"];
85 $this->ds->setCurrentInstallationId($a_attribs["InstallationId"]);
86 break;
87
88 case $this->dspref . "Types":
89 $this->current_entity = $a_attribs["Entity"];
90 $this->current_version = $a_attribs["Version"];
91 break;
92
93 case $this->dspref . "FieldType":
94 $this->current_ftypes[$a_attribs["Name"]] =
95 $a_attribs["Type"];
96 break;
97
98 case $this->dspref . "Rec":
99 $this->current_entity = $a_attribs["Entity"];
100 $this->in_record = true;
101 $this->current_field_values = array();
102 break;
103
104 default:
105 if ($this->in_record) {
106 $field = explode(":", $a_name); // remove namespace
107 $field = $field[count($field) - 1];
108 $this->current_field = $field;
109 }
110 }
111 }
112
113 public function handleEndTag(
114 $a_xml_parser,
115 string $a_name
116 ): void {
117 switch ($a_name) {
118 case $this->dspref . "Types":
119 $this->entities[$this->current_entity] =
120 array(
121 "version" => $this->current_version,
122 "types" => $this->current_ftypes
123 );
124 $this->current_ftypes = array();
125 $this->current_entity = "";
126 $this->current_version = "";
127 break;
128
129 case $this->dspref . "Rec":
130 $this->ds->importRecord(
131 $this->current_entity,
132 $this->entities[$this->current_entity]["types"] ?? [],
133 $this->current_field_values,
134 $this->mapping,
135 $this->schema_version
136 );
137 $this->in_record = false;
138 $this->current_entity = "";
139 $this->current_field_values = array();
140 break;
141
142 default:
143 if ($this->in_record && $this->current_field !== "") {
144 $this->current_field_values[$this->current_field] =
145 $this->chr_data;
146 }
147 $this->current_field = "";
148 break;
149 }
150
151 $this->chr_data = "";
152 }
153
154
155 public function handleCharacterData(
156 $a_xml_parser,
157 string $a_data
158 ): void {
159 $this->chr_data .= $a_data;
160 }
161}
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
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)
A dataset contains in data in a common structure that can be shared and transformed for different pur...
Import class.
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