ILIAS  release_7 Revision v7.30-3-g800a261c036
class.ilTaxonomyDataSet.php
Go to the documentation of this file.
1<?php
2/* Copyright (c) 1998-2013 ILIAS open source, Extended GPL, see docs/LICENSE */
3
4include_once("./Services/DataSet/classes/class.ilDataSet.php");
5
20{
27 public function getSupportedVersions()
28 {
29 return array("4.3.0");
30 }
31
38 public function getXmlNamespace($a_entity, $a_schema_version)
39 {
40 return "http://www.ilias.de/xml/Services/Taxonomy/" . $a_entity;
41 }
42
49 protected function getTypes($a_entity, $a_version)
50 {
51 // tax
52 if ($a_entity == "tax") {
53 switch ($a_version) {
54 case "4.3.0":
55 return array(
56 "Id" => "integer",
57 "Title" => "text",
58 "Description" => "text",
59 "SortingMode" => "integer");
60 }
61 }
62
63 // tax_usage
64 if ($a_entity == "tax_usage") {
65 switch ($a_version) {
66 case "4.3.0":
67 return array(
68 "TaxId" => "integer",
69 "ObjId" => "integer"
70 );
71 }
72 }
73
74 // tax_tree
75 if ($a_entity == "tax_tree") {
76 switch ($a_version) {
77 case "4.3.0":
78 return array(
79 "TaxId" => "integer",
80 "Child" => "integer",
81 "Parent" => "integer",
82 "Depth" => "integer",
83 "Type" => "text",
84 "Title" => "text",
85 "OrderNr" => "integer"
86 );
87 }
88 }
89
90 // tax_node_assignment
91 if ($a_entity == "tax_node_assignment") {
92 switch ($a_version) {
93 case "4.3.0":
94 return array(
95 "NodeId" => "integer",
96 "Component" => "text",
97 "ItemType" => "text",
98 "ItemId" => "integer"
99 );
100 }
101 }
102 }
103
110 public function readData($a_entity, $a_version, $a_ids, $a_field = "")
111 {
113
114 if (!is_array($a_ids)) {
115 $a_ids = array($a_ids);
116 }
117
118 // tax
119 if ($a_entity == "tax") {
120 switch ($a_version) {
121 case "4.3.0":
122 $this->getDirectDataFromQuery("SELECT id, title, description, " .
123 " sorting_mode" .
124 " FROM tax_data JOIN object_data ON (tax_data.id = object_data.obj_id) " .
125 "WHERE " .
126 $ilDB->in("id", $a_ids, false, "integer"));
127 break;
128 }
129 }
130
131 // tax usage
132 if ($a_entity == "tax_usage") {
133 switch ($a_version) {
134 case "4.3.0":
135 $this->getDirectDataFromQuery("SELECT tax_id, obj_id " .
136 " FROM tax_usage " .
137 "WHERE " .
138 $ilDB->in("tax_id", $a_ids, false, "integer"));
139 break;
140 }
141 }
142
143 // tax_tree
144 if ($a_entity == "tax_tree") {
145 switch ($a_version) {
146 case "4.3.0":
147 $this->getDirectDataFromQuery("SELECT tax_id, child " .
148 " ,parent,depth,type,title,order_nr " .
149 " FROM tax_tree JOIN tax_node ON (child = obj_id) " .
150 " WHERE " .
151 $ilDB->in("tax_id", $a_ids, false, "integer") .
152 " ORDER BY depth");
153 break;
154 }
155 }
156
157 // tax node assignment
158 if ($a_entity == "tax_node_assignment") {
159 switch ($a_version) {
160 case "4.3.0":
161 $this->getDirectDataFromQuery("SELECT node_id, component, item_type, item_id " .
162 " FROM tax_node_assignment " .
163 "WHERE " .
164 $ilDB->in("node_id", $a_ids, false, "integer"));
165 break;
166 }
167 }
168 }
169
173 protected function getDependencies($a_entity, $a_version, $a_rec, $a_ids)
174 {
175 switch ($a_entity) {
176 case "tax":
177 return array(
178 "tax_tree" => array("ids" => $a_rec["Id"]),
179 "tax_usage" => array("ids" => $a_rec["Id"])
180 );
181 case "tax_tree":
182 return array(
183 "tax_node_assignment" => array("ids" => $a_rec["Child"])
184 );
185 }
186 return false;
187 }
188
192
193
200 public function importRecord($a_entity, $a_types, $a_rec, $a_mapping, $a_schema_version)
201 {
202 $a_rec = $this->stripTags($a_rec);
203
204 switch ($a_entity) {
205 case "tax":
206 include_once("./Services/Taxonomy/classes/class.ilObjTaxonomy.php");
207
208// if($new_id = $a_mapping->getMapping('Services/Container','objs',$a_rec['Id']))
209// {
210// $newObj = ilObjectFactory::getInstanceByObjId($new_id,false);
211// }
212// else
213// {
214 $newObj = new ilObjTaxonomy();
215 $newObj->create();
216// }
217
218 $newObj->setTitle($a_rec["Title"]);
219 $newObj->setDescription($a_rec["Description"]);
220 $newObj->setSortingMode($a_rec["SortingMode"]);
221 $newObj->update();
222
223 $this->current_obj = $newObj;
224 $a_mapping->addMapping("Services/Taxonomy", "tax", $a_rec["Id"], $newObj->getId());
225 break;
226
227 case "tax_tree":
228 switch ($a_rec["Type"]) {
229 case "taxn":
230 $parent = (int) $a_mapping->getMapping("Services/Taxonomy", "tax_tree", $a_rec["Parent"]);
231 $tax_id = $a_mapping->getMapping("Services/Taxonomy", "tax", $a_rec["TaxId"]);
232 if ($parent == 0) {
233 $parent = $this->current_obj->getTree()->readRootId();
234 }
235 $node = new ilTaxonomyNode();
236 $node->setTitle($a_rec["Title"]);
237 $node->setOrderNr($a_rec["OrderNr"]);
238 $node->setTaxonomyId($tax_id);
239 $node->create();
240 ilTaxonomyNode::putInTree($tax_id, $node, (int) $parent, "", $a_rec["OrderNr"]);
241 $a_mapping->addMapping(
242 "Services/Taxonomy",
243 "tax_tree",
244 $a_rec["Child"],
245 $node->getId()
246 );
247 break;
248
249 }
250
251 // no break
252 case "tax_node_assignment":
253 $new_item_id = (int) $a_mapping->getMapping(
254 "Services/Taxonomy",
255 "tax_item",
256 $a_rec["Component"] . ":" . $a_rec["ItemType"] . ":" . $a_rec["ItemId"]
257 );
258 $new_node_id = (int) $a_mapping->getMapping("Services/Taxonomy", "tax_tree", $a_rec["NodeId"]);
259
260 // this is needed since 4.4 (but not exported with 4.3)
261 // with 4.4 this should be part of export/import
262 $new_item_id_obj = (int) $a_mapping->getMapping(
263 "Services/Taxonomy",
264 "tax_item_obj_id",
265 $a_rec["Component"] . ":" . $a_rec["ItemType"] . ":" . $a_rec["ItemId"]
266 );
267 if ($new_item_id > 0 && $new_node_id > 0 && $new_item_id_obj > 0) {
268 include_once("./Services/Taxonomy/classes/class.ilTaxNodeAssignment.php");
269 $node_ass = new ilTaxNodeAssignment($a_rec["Component"], $new_item_id_obj, $a_rec["ItemType"], $this->current_obj->getId());
270 $node_ass->addAssignment($new_node_id, $new_item_id);
271 }
272 break;
273
274 case "tax_usage":
275 $usage = $a_mapping->getMapping("Services/Taxonomy", "tax_usage_of_obj", $a_rec["ObjId"]);
276 if ($usage != "") {
277 $usage .= ":";
278 }
279 $a_mapping->addMapping(
280 "Services/Taxonomy",
281 "tax_usage_of_obj",
282 $a_rec["ObjId"],
283 $usage . $this->current_obj->getId()
284 );
285 break;
286 }
287 }
288}
An exception for terminatinating execution or to throw for unit testing.
A dataset contains in data in a common structure that can be shared and transformed for different pur...
stripTags(array $rec, array $omit_keys=[])
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 ...
Taxonomy node <-> item assignment.
Taxonomy data set class.
getDependencies($a_entity, $a_version, $a_rec, $a_ids)
Determine the dependent sets of data.
getTypes($a_entity, $a_version)
Get field types for entity.
getXmlNamespace($a_entity, $a_schema_version)
Get xml namespace.
readData($a_entity, $a_version, $a_ids, $a_field="")
Read data.
getSupportedVersions()
Get supported versions.
importRecord($a_entity, $a_types, $a_rec, $a_mapping, $a_schema_version)
Import record.
static putInTree( $a_tax_id, $a_node, $a_parent_id="", $a_target_node_id="", $a_order_nr=0)
Put this node into the taxonomy tree.
global $ilDB