ILIAS  Release_5_0_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
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  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  {
54  switch ($a_version)
55  {
56  case "4.3.0":
57  return array(
58  "Id" => "integer",
59  "Title" => "text",
60  "Description" => "text",
61  "SortingMode" => "integer");
62  }
63  }
64 
65  // tax_usage
66  if ($a_entity == "tax_usage")
67  {
68  switch ($a_version)
69  {
70  case "4.3.0":
71  return array(
72  "TaxId" => "integer",
73  "ObjId" => "integer"
74  );
75  }
76  }
77 
78  // tax_tree
79  if ($a_entity == "tax_tree")
80  {
81  switch ($a_version)
82  {
83  case "4.3.0":
84  return array(
85  "TaxId" => "integer",
86  "Child" => "integer",
87  "Parent" => "integer",
88  "Depth" => "integer",
89  "Type" => "text",
90  "Title" => "text",
91  "OrderNr" => "integer"
92  );
93  }
94  }
95 
96  // tax_node_assignment
97  if ($a_entity == "tax_node_assignment")
98  {
99  switch ($a_version)
100  {
101  case "4.3.0":
102  return array(
103  "NodeId" => "integer",
104  "Component" => "text",
105  "ItemType" => "text",
106  "ItemId" => "integer"
107  );
108  }
109  }
110 
111  }
112 
119  function readData($a_entity, $a_version, $a_ids, $a_field = "")
120  {
121  global $ilDB;
122 
123  if (!is_array($a_ids))
124  {
125  $a_ids = array($a_ids);
126  }
127 
128  // tax
129  if ($a_entity == "tax")
130  {
131  switch ($a_version)
132  {
133  case "4.3.0":
134  $this->getDirectDataFromQuery("SELECT id, title, description, ".
135  " sorting_mode".
136  " FROM tax_data JOIN object_data ON (tax_data.id = object_data.obj_id) ".
137  "WHERE ".
138  $ilDB->in("id", $a_ids, false, "integer"));
139  break;
140  }
141  }
142 
143  // tax usage
144  if ($a_entity == "tax_usage")
145  {
146  switch ($a_version)
147  {
148  case "4.3.0":
149  $this->getDirectDataFromQuery("SELECT tax_id, obj_id ".
150  " FROM tax_usage ".
151  "WHERE ".
152  $ilDB->in("tax_id", $a_ids, false, "integer"));
153  break;
154  }
155  }
156 
157  // tax_tree
158  if ($a_entity == "tax_tree")
159  {
160  switch ($a_version)
161  {
162  case "4.3.0":
163  $this->getDirectDataFromQuery("SELECT tax_id, child ".
164  " ,parent,depth,type,title,order_nr ".
165  " FROM tax_tree JOIN tax_node ON (child = obj_id) ".
166  " WHERE ".
167  $ilDB->in("tax_id", $a_ids, false, "integer").
168  " ORDER BY depth");
169  break;
170  }
171  }
172 
173  // tax node assignment
174  if ($a_entity == "tax_node_assignment")
175  {
176  switch ($a_version)
177  {
178  case "4.3.0":
179  $this->getDirectDataFromQuery("SELECT node_id, component, item_type, item_id ".
180  " FROM tax_node_assignment ".
181  "WHERE ".
182  $ilDB->in("node_id", $a_ids, false, "integer"));
183  break;
184  }
185  }
186 
187  }
188 
192  protected function getDependencies($a_entity, $a_version, $a_rec, $a_ids)
193  {
194  switch ($a_entity)
195  {
196  case "tax":
197  return array (
198  "tax_tree" => array("ids" => $a_rec["Id"]),
199  "tax_usage" => array("ids" => $a_rec["Id"])
200  );
201  case "tax_tree":
202  return array (
203  "tax_node_assignment" => array("ids" => $a_rec["Child"])
204  );
205  }
206  return false;
207  }
208 
212 
213 
220  function importRecord($a_entity, $a_types, $a_rec, $a_mapping, $a_schema_version)
221  {
222 //echo $a_entity;
223 //var_dump($a_rec);
224 
225  switch ($a_entity)
226  {
227  case "tax":
228  include_once("./Services/Taxonomy/classes/class.ilObjTaxonomy.php");
229 
230 // if($new_id = $a_mapping->getMapping('Services/Container','objs',$a_rec['Id']))
231 // {
232 // $newObj = ilObjectFactory::getInstanceByObjId($new_id,false);
233 // }
234 // else
235 // {
236  $newObj = new ilObjTaxonomy();
237  $newObj->create();
238 // }
239 
240  $newObj->setTitle($a_rec["Title"]);
241  $newObj->setDescription($a_rec["Description"]);
242  $newObj->setSortingMode($a_rec["SortingMode"]);
243  $newObj->update();
244 
245  $this->current_obj = $newObj;
246  $a_mapping->addMapping("Services/Taxonomy", "tax", $a_rec["Id"], $newObj->getId());
247  break;
248 
249  case "tax_tree":
250  switch ($a_rec["Type"])
251  {
252  case "taxn":
253  $parent = (int) $a_mapping->getMapping("Services/Taxonomy", "tax_tree", $a_rec["Parent"]);
254  $tax_id = $a_mapping->getMapping("Services/Taxonomy", "tax", $a_rec["TaxId"]);
255  if ($parent == 0)
256  {
257  $parent = $this->current_obj->getTree()->readRootId();
258  }
259  $node = new ilTaxonomyNode();
260  $node->setTitle($a_rec["Title"]);
261  $node->setOrderNr($a_rec["OrderNr"]);
262  $node->setTaxonomyId($tax_id);
263  $node->create();
264  ilTaxonomyNode::putInTree($tax_id, $node, (int) $parent, "", $a_rec["OrderNr"]);
265  $a_mapping->addMapping("Services/Taxonomy", "tax_tree", $a_rec["Child"],
266  $node->getId());
267  break;
268 
269  }
270 
271  case "tax_node_assignment":
272  $new_item_id = (int) $a_mapping->getMapping("Services/Taxonomy", "tax_item",
273  $a_rec["Component"].":".$a_rec["ItemType"].":".$a_rec["ItemId"]);
274  $new_node_id = (int) $a_mapping->getMapping("Services/Taxonomy", "tax_tree", $a_rec["NodeId"]);
275 
276  // this is needed since 4.4 (but not exported with 4.3)
277  // with 4.4 this should be part of export/import
278  $new_item_id_obj = (int) $a_mapping->getMapping("Services/Taxonomy", "tax_item_obj_id",
279  $a_rec["Component"].":".$a_rec["ItemType"].":".$a_rec["ItemId"]);
280  if ($new_item_id > 0 && $new_node_id > 0 && $new_item_id_obj > 0)
281  {
282  include_once("./Services/Taxonomy/classes/class.ilTaxNodeAssignment.php");
283  $node_ass = new ilTaxNodeAssignment($a_rec["Component"], $new_item_id_obj, $a_rec["ItemType"], $this->current_obj->getId());
284  $node_ass->addAssignment($new_node_id, $new_item_id);
285  }
286  break;
287 
288  case "tax_usage":
289  $usage = $a_mapping->getMapping("Services/Taxonomy", "tax_usage_of_obj", $a_rec["ObjId"]);
290  if ($usage != "")
291  {
292  $usage.=":";
293  }
294  $a_mapping->addMapping("Services/Taxonomy", "tax_usage_of_obj", $a_rec["ObjId"],
295  $this->current_obj->getId());
296  break;
297  }
298  }
299 }
300 ?>