ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilTaxonomyDataSet.php
Go to the documentation of this file.
1<?php
2
29{
31
32 public function getSupportedVersions(): array
33 {
34 return array("4.3.0");
35 }
36
37 protected function getXmlNamespace(string $a_entity, string $a_schema_version): string
38 {
39 return "http://www.ilias.de/xml/Services/Taxonomy/" . $a_entity;
40 }
41
45 protected function getTypes(string $a_entity, string $a_version): array
46 {
47 // tax
48 if ($a_entity == "tax") {
49 switch ($a_version) {
50 case "4.3.0":
51 return array(
52 "Id" => "integer",
53 "Title" => "text",
54 "Description" => "text",
55 "SortingMode" => "integer"
56 );
57 }
58 }
59
60 // tax_usage
61 if ($a_entity == "tax_usage") {
62 switch ($a_version) {
63 case "4.3.0":
64 return array(
65 "TaxId" => "integer",
66 "ObjId" => "integer"
67 );
68 }
69 }
70
71 // tax_tree
72 if ($a_entity == "tax_tree") {
73 switch ($a_version) {
74 case "4.3.0":
75 return array(
76 "TaxId" => "integer",
77 "Child" => "integer",
78 "Parent" => "integer",
79 "Depth" => "integer",
80 "Type" => "text",
81 "Title" => "text",
82 "OrderNr" => "integer"
83 );
84 }
85 }
86
87 // tax_node_assignment
88 if ($a_entity == "tax_node_assignment") {
89 switch ($a_version) {
90 case "4.3.0":
91 return array(
92 "NodeId" => "integer",
93 "Component" => "text",
94 "ItemType" => "text",
95 "ItemId" => "integer"
96 );
97 }
98 }
99 return [];
100 }
101
105 public function readData(string $a_entity, string $a_version, array $a_ids): void
106 {
108
109 if (!is_array($a_ids)) {
110 $a_ids = array($a_ids);
111 }
112
113 // tax
114 if ($a_entity == "tax") {
115 switch ($a_version) {
116 case "4.3.0":
117 $this->getDirectDataFromQuery("SELECT id, title, description, " .
118 " sorting_mode" .
119 " FROM tax_data JOIN object_data ON (tax_data.id = object_data.obj_id) " .
120 "WHERE " .
121 $ilDB->in("id", $a_ids, false, "integer"));
122 break;
123 }
124 }
125
126 // tax usage
127 if ($a_entity == "tax_usage") {
128 switch ($a_version) {
129 case "4.3.0":
130 $this->getDirectDataFromQuery("SELECT tax_id, obj_id " .
131 " FROM tax_usage " .
132 "WHERE " .
133 $ilDB->in("tax_id", $a_ids, false, "integer"));
134 break;
135 }
136 }
137
138 // tax_tree
139 if ($a_entity == "tax_tree") {
140 switch ($a_version) {
141 case "4.3.0":
142 $this->getDirectDataFromQuery("SELECT tax_id, child " .
143 " ,parent,depth,type,title,order_nr " .
144 " FROM tax_tree JOIN tax_node ON (child = obj_id) " .
145 " WHERE " .
146 $ilDB->in("tax_id", $a_ids, false, "integer") .
147 " ORDER BY depth");
148 break;
149 }
150 }
151
152 // tax node assignment
153 if ($a_entity == "tax_node_assignment") {
154 switch ($a_version) {
155 case "4.3.0":
156 $this->getDirectDataFromQuery("SELECT node_id, component, item_type, item_id " .
157 " FROM tax_node_assignment " .
158 "WHERE " .
159 $ilDB->in("node_id", $a_ids, false, "integer"));
160 break;
161 }
162 }
163 }
164
168 protected function getDependencies(
169 string $a_entity,
170 string $a_version,
171 ?array $a_rec = null,
172 ?array $a_ids = null
173 ): array {
174 switch ($a_entity) {
175 case "tax":
176 return array(
177 "tax_tree" => array("ids" => $a_rec["Id"] ?? null),
178 "tax_usage" => array("ids" => $a_rec["Id"] ?? null)
179 );
180 case "tax_tree":
181 return array(
182 "tax_node_assignment" => array("ids" => $a_rec["Child"] ?? null)
183 );
184 }
185 return [];
186 }
187
191
192 public function importRecord(
193 string $a_entity,
194 array $a_types,
195 array $a_rec,
196 ilImportMapping $a_mapping,
197 string $a_schema_version
198 ): void {
199 $a_rec = $this->stripTags($a_rec);
200 switch ($a_entity) {
201 case "tax":
202 $newObj = new ilObjTaxonomy();
203 $newObj->create();
204
205 $newObj->setTitle($a_rec["Title"]);
206 $newObj->setDescription($a_rec["Description"]);
207 $newObj->setSortingMode((int) $a_rec["SortingMode"]);
208 $newObj->update();
209
210 $this->current_obj = $newObj;
211 $a_mapping->addMapping("components/ILIAS/Taxonomy", "tax", $a_rec["Id"], $newObj->getId());
212 break;
213
214 case "tax_tree":
215 switch ($a_rec["Type"]) {
216 case "taxn":
217 $parent = (int) $a_mapping->getMapping("components/ILIAS/Taxonomy", "tax_tree", $a_rec["Parent"]);
218 $tax_id = $a_mapping->getMapping("components/ILIAS/Taxonomy", "tax", $a_rec["TaxId"]);
219 if ($parent == 0) {
220 $parent = $this->current_obj->getTree()->readRootId();
221 }
222 $node = new ilTaxonomyNode();
223 $node->setTitle($a_rec["Title"]);
224 $node->setOrderNr((int) $a_rec["OrderNr"]);
225 $node->setTaxonomyId((int) $tax_id);
226 $node->create();
227 ilTaxonomyNode::putInTree((int) $tax_id, $node, (int) $parent, 0, (int) $a_rec["OrderNr"]);
228 $a_mapping->addMapping(
229 "components/ILIAS/Taxonomy",
230 "tax_tree",
231 $a_rec["Child"],
232 $node->getId()
233 );
234 break;
235 }
236
237 // no break
238 case "tax_node_assignment":
239 $new_item_id = (int) $a_mapping->getMapping(
240 "components/ILIAS/Taxonomy",
241 "tax_item",
242 ($a_rec["Component"] ?? "") .
243 ":" . ($a_rec["ItemType"] ?? "") . ":" .
244 ($a_rec["ItemId"] ?? "")
245 );
246 $new_node_id = (int) $a_mapping->getMapping("components/ILIAS/Taxonomy", "tax_tree", $a_rec["NodeId"] ?? "");
247
248 // this is needed since 4.4 (but not exported with 4.3)
249 // with 4.4 this should be part of export/import
250 $new_item_id_obj = (int) $a_mapping->getMapping(
251 "components/ILIAS/Taxonomy",
252 "tax_item_obj_id",
253 ($a_rec["Component"] ?? "") .
254 ":" . ($a_rec["ItemType"] ?? "") . ":" .
255 ($a_rec["ItemId"] ?? "")
256 );
257 if ($new_item_id > 0 && $new_node_id > 0 && $new_item_id_obj > 0) {
258 $node_ass = new ilTaxNodeAssignment(
259 $a_rec["Component"],
260 $new_item_id_obj,
261 $a_rec["ItemType"],
262 $this->current_obj->getId()
263 );
264 $node_ass->addAssignment($new_node_id, $new_item_id);
265 }
266 break;
267
268 case "tax_usage":
269 $usage = $a_mapping->getMapping("components/ILIAS/Taxonomy", "tax_usage_of_obj", $a_rec["ObjId"]);
270 if ($usage != "") {
271 $usage .= ":";
272 }
273 $a_mapping->addMapping(
274 "components/ILIAS/Taxonomy",
275 "tax_usage_of_obj",
276 $a_rec["ObjId"],
277 $usage . $this->current_obj->getId()
278 );
279 break;
280 }
281 }
282}
A dataset contains in data in a common structure that can be shared and transformed for different pur...
getDirectDataFromQuery(string $a_query, bool $a_convert_to_leading_upper=true, bool $a_set=true)
Get data from query.This is a standard procedure, all db field names are directly mapped to abstract ...
ilDBInterface $db
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)
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...
getTypes(string $a_entity, string $a_version)
@inheritDoc
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.
readData(string $a_entity, string $a_version, array $a_ids)
@inheritDoc
getXmlNamespace(string $a_entity, string $a_schema_version)
getDependencies(string $a_entity, string $a_version, ?array $a_rec=null, ?array $a_ids=null)
Determine the dependent sets of data.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static putInTree(int $a_tax_id, ilTaxonomyNode $a_node, int $a_parent_id=0, int $a_target_node_id=0, int $a_order_nr=0)