ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
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 
4 include_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  {
112  $ilDB = $this->db;
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  //echo $a_entity;
203  //var_dump($a_rec);
204 
205  switch ($a_entity) {
206  case "tax":
207  include_once("./Services/Taxonomy/classes/class.ilObjTaxonomy.php");
208 
209 // if($new_id = $a_mapping->getMapping('Services/Container','objs',$a_rec['Id']))
210 // {
211 // $newObj = ilObjectFactory::getInstanceByObjId($new_id,false);
212 // }
213 // else
214 // {
215  $newObj = new ilObjTaxonomy();
216  $newObj->create();
217 // }
218 
219  $newObj->setTitle($a_rec["Title"]);
220  $newObj->setDescription($a_rec["Description"]);
221  $newObj->setSortingMode($a_rec["SortingMode"]);
222  $newObj->update();
223 
224  $this->current_obj = $newObj;
225  $a_mapping->addMapping("Services/Taxonomy", "tax", $a_rec["Id"], $newObj->getId());
226  break;
227 
228  case "tax_tree":
229  switch ($a_rec["Type"]) {
230  case "taxn":
231  $parent = (int) $a_mapping->getMapping("Services/Taxonomy", "tax_tree", $a_rec["Parent"]);
232  $tax_id = $a_mapping->getMapping("Services/Taxonomy", "tax", $a_rec["TaxId"]);
233  if ($parent == 0) {
234  $parent = $this->current_obj->getTree()->readRootId();
235  }
236  $node = new ilTaxonomyNode();
237  $node->setTitle($a_rec["Title"]);
238  $node->setOrderNr($a_rec["OrderNr"]);
239  $node->setTaxonomyId($tax_id);
240  $node->create();
241  ilTaxonomyNode::putInTree($tax_id, $node, (int) $parent, "", $a_rec["OrderNr"]);
242  $a_mapping->addMapping(
243  "Services/Taxonomy",
244  "tax_tree",
245  $a_rec["Child"],
246  $node->getId()
247  );
248  break;
249 
250  }
251 
252  // no break
253  case "tax_node_assignment":
254  $new_item_id = (int) $a_mapping->getMapping(
255  "Services/Taxonomy",
256  "tax_item",
257  $a_rec["Component"] . ":" . $a_rec["ItemType"] . ":" . $a_rec["ItemId"]
258  );
259  $new_node_id = (int) $a_mapping->getMapping("Services/Taxonomy", "tax_tree", $a_rec["NodeId"]);
260 
261  // this is needed since 4.4 (but not exported with 4.3)
262  // with 4.4 this should be part of export/import
263  $new_item_id_obj = (int) $a_mapping->getMapping(
264  "Services/Taxonomy",
265  "tax_item_obj_id",
266  $a_rec["Component"] . ":" . $a_rec["ItemType"] . ":" . $a_rec["ItemId"]
267  );
268  if ($new_item_id > 0 && $new_node_id > 0 && $new_item_id_obj > 0) {
269  include_once("./Services/Taxonomy/classes/class.ilTaxNodeAssignment.php");
270  $node_ass = new ilTaxNodeAssignment($a_rec["Component"], $new_item_id_obj, $a_rec["ItemType"], $this->current_obj->getId());
271  $node_ass->addAssignment($new_node_id, $new_item_id);
272  }
273  break;
274 
275  case "tax_usage":
276  $usage = $a_mapping->getMapping("Services/Taxonomy", "tax_usage_of_obj", $a_rec["ObjId"]);
277  if ($usage != "") {
278  $usage.=":";
279  }
280  $a_mapping->addMapping(
281  "Services/Taxonomy",
282  "tax_usage_of_obj",
283  $a_rec["ObjId"],
284  $usage . $this->current_obj->getId()
285  );
286  break;
287  }
288  }
289 }
addAssignment($a_node_id, $a_item_id, $a_order_nr=0)
Add assignment.
Taxonomy node <-> item assignment.
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 data set class.
readData($a_entity, $a_version, $a_ids, $a_field="")
Read data.
getDependencies($a_entity, $a_version, $a_rec, $a_ids)
Determine the dependent sets of data.
Create styles array
The data for the language used.
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
getSupportedVersions()
Get supported versions.
getXmlNamespace($a_entity, $a_schema_version)
Get xml namespace.
A dataset contains in data in a common structure that can be shared and transformed for different pur...
importRecord($a_entity, $a_types, $a_rec, $a_mapping, $a_schema_version)
Import record.
getTypes($a_entity, $a_version)
Get field types for entity.