ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
class.ilTaxonomyNode.php
Go to the documentation of this file.
1<?php
2
3/* Copyright (c) 1998-2012 ILIAS open source, Extended GPL, see docs/LICENSE */
4
5
15{
16 var $type;
17 var $id;
18 var $title;
19
24 function __construct($a_id = 0)
25 {
26 $this->id = $a_id;
27
28// include_once("./Services/Taxonomy/classes/class.ilTaxonomyTree.php");
29// $this->taxonomy_tree = new ilTaxonomyTree();
30
31 if($a_id != 0)
32 {
33 $this->read();
34 }
35
36 $this->setType("taxn");
37 }
38
44 function setTitle($a_title)
45 {
46 $this->title = $a_title;
47 }
48
54 function getTitle()
55 {
56 return $this->title;
57 }
58
64 function setType($a_type)
65 {
66 $this->type = $a_type;
67 }
68
74 function getType()
75 {
76 return $this->type;
77 }
78
84 function setId($a_id)
85 {
86 $this->id = $a_id;
87 }
88
94 function getId()
95 {
96 return $this->id;
97 }
98
104 function setOrderNr($a_val)
105 {
106 $this->order_nr = $a_val;
107 }
108
114 function getOrderNr()
115 {
116 return $this->order_nr;
117 }
118
124 function setTaxonomyId($a_val)
125 {
126 $this->taxonomy_id = $a_val;
127 }
128
134 function getTaxonomyId()
135 {
136 return $this->taxonomy_id;
137 }
138
142 function read()
143 {
144 global $ilDB;
145
146 if(!isset($this->data_record))
147 {
148 $query = "SELECT * FROM tax_node WHERE obj_id = ".
149 $ilDB->quote($this->id, "integer");
150 $obj_set = $ilDB->query($query);
151 $this->data_record = $ilDB->fetchAssoc($obj_set);
152 }
153 $this->setType($this->data_record["type"]);
154 $this->setTitle($this->data_record["title"]);
155 $this->setOrderNr($this->data_record["order_nr"]);
156 $this->setTaxonomyId($this->data_record["tax_id"]);
157 }
158
162 function create()
163 {
164 global $ilDB;
165
166 if ($this->getTaxonomyId() <= 0)
167 {
168 die("ilTaxonomyNode->create: No taxonomy ID given");
169 }
170
171 // insert object data
172 $id = $ilDB->nextId("tax_node");
173 $query = "INSERT INTO tax_node (obj_id, title, type, create_date, order_nr, tax_id) ".
174 "VALUES (".
175 $ilDB->quote($id, "integer").",".
176 $ilDB->quote($this->getTitle(), "text").",".
177 $ilDB->quote($this->getType(), "text").", ".
178 $ilDB->now().", ".
179 $ilDB->quote((int) $this->getOrderNr(), "integer").", ".
180 $ilDB->quote((int) $this->getTaxonomyId(), "integer").
181 ")";
182 $ilDB->manipulate($query);
183 $this->setId($id);
184
185 }
186
190 function update()
191 {
192 global $ilDB;
193
194 $query = "UPDATE tax_node SET ".
195 " title = ".$ilDB->quote($this->getTitle(), "text").
196 " ,order_nr = ".$ilDB->quote((int) $this->getOrderNr(), "integer").
197 " WHERE obj_id = ".$ilDB->quote($this->getId(), "integer");
198
199 $ilDB->manipulate($query);
200 }
201
205 function delete()
206 {
207 global $ilDB;
208
209 // delete all assignments of the node
210 include_once("./Services/Taxonomy/classes/class.ilTaxNodeAssignment.php");
212
213 $query = "DELETE FROM tax_node WHERE obj_id= ".
214 $ilDB->quote($this->getId(), "integer");
215 $ilDB->manipulate($query);
216 }
217
221 function copy($a_tax_id = 0)
222 {
223 $taxn = new ilTaxonomyNode();
224 $taxn->setTitle($this->getTitle());
225 $taxn->setType($this->getType());
226 $taxn->setOrderNr($this->getOrderNr());
227 if ($a_tax_id == 0)
228 {
229 $taxn->setTaxonomyId($this->getTaxonomyId());
230 }
231 else
232 {
233 $taxn->setTaxonomyId($a_tax_id);
234 }
235
236 $taxn->create();
237
238 return $taxn;
239 }
240
246 protected static function _lookup($a_obj_id, $a_field)
247 {
248 global $ilDB;
249
250 $query = "SELECT $a_field FROM tax_node WHERE obj_id = ".
251 $ilDB->quote($a_obj_id, "integer");
252 $obj_set = $ilDB->query($query);
253 $obj_rec = $ilDB->fetchAssoc($obj_set);
254
255 return $obj_rec[$a_field];
256 }
257
264 static function _lookupTitle($a_obj_id)
265 {
266 global $ilDB;
267
268 return self::_lookup($a_obj_id, "title");
269 }
270
274 static function putInTree($a_tax_id, $a_node, $a_parent_id = "", $a_target_node_id = "",
275 $a_order_nr = 0)
276 {
277 include_once("./Services/Taxonomy/classes/class.ilTaxonomyTree.php");
278 $tax_tree = new ilTaxonomyTree($a_tax_id);
279
280 // determine parent
281 $parent_id = ($a_parent_id != "")
282 ? $a_parent_id
283 : $tax_tree->readRootId();
284
285 // determine target
286 if ($a_target_node_id != "")
287 {
288 $target = $a_target_node_id;
289 }
290 else
291 {
292 // determine last child that serves as predecessor
293 $childs = $tax_tree->getChilds($parent_id);
294
295 if (count($childs) == 0)
296 {
297 $target = IL_FIRST_NODE;
298 }
299 else
300 {
301 $target = $childs[count($childs) - 1]["obj_id"];
302 }
303 }
304
305 if ($tax_tree->isInTree($parent_id) && !$tax_tree->isInTree($a_node->getId()))
306 {
307 $tax_tree->insertNode($a_node->getId(), $parent_id, $target);
308 }
309 }
310
317 static function writeOrderNr($a_node_id, $a_order_nr)
318 {
319 global $ilDB;
320
321 $ilDB->manipulate("UPDATE tax_node SET ".
322 " order_nr = ".$ilDB->quote($a_order_nr, "integer").
323 " WHERE obj_id = ".$ilDB->quote($a_node_id, "integer")
324 );
325 }
326
333 static function writeTitle($a_node_id, $a_title)
334 {
335 global $ilDB;
336
337 $ilDB->manipulate("UPDATE tax_node SET ".
338 " title = ".$ilDB->quote($a_title, "text").
339 " WHERE obj_id = ".$ilDB->quote($a_node_id, "integer")
340 );
341 }
342
346 static function getNextOrderNr($a_tax_id, $a_parent_id)
347 {
348 include_once("./Services/Taxonomy/classes/class.ilTaxonomyTree.php");
349 $tax_tree = new ilTaxonomyTree($a_tax_id);
350 if ($a_parent_id == 0)
351 {
352 $a_parent_id = $tax_tree->readRootId();
353 }
354 $childs = $tax_tree->getChilds($a_parent_id);
355 $max = 0;
356
357 foreach ($childs as $c)
358 {
359 if ($c["order_nr"] > $max)
360 {
361 $max = $c["order_nr"] + 10;
362 }
363 }
364
365 return $max;
366 }
367
374 static function fixOrderNumbers($a_tax_id, $a_parent_id)
375 {
376 include_once("./Services/Taxonomy/classes/class.ilTaxonomyTree.php");
377 $tax_tree = new ilTaxonomyTree($a_tax_id);
378 if ($a_parent_id == 0)
379 {
380 $a_parent_id = $tax_tree->readRootId();
381 }
382 $childs = $tax_tree->getChilds($a_parent_id);
383 $childs = ilUtil::sortArray($childs, "order_nr", "asc", true);
384
385 $cnt = 10;
386 foreach ($childs as $c)
387 {
388 self::writeOrderNr($c["child"], $cnt);
389 $cnt += 10;
390 }
391 }
392
393}
394?>
const IL_FIRST_NODE
Definition: class.ilTree.php:5
static deleteAllAssignmentsOfNode($a_node_id)
Delete assignments of node.
static writeOrderNr($a_node_id, $a_order_nr)
Write order nr.
copy($a_tax_id=0)
Copy taxonomy node.
__construct($a_id=0)
Constructor @access public.
getTaxonomyId()
Get taxonomy id.
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.
setTaxonomyId($a_val)
Set taxonomy id.
static fixOrderNumbers($a_tax_id, $a_parent_id)
Fix order numbers.
setTitle($a_title)
Set title.
static writeTitle($a_node_id, $a_title)
Write title.
setId($a_id)
Set Node ID.
static _lookup($a_obj_id, $a_field)
Lookup.
read()
Read data from database.
setType($a_type)
Set type.
getOrderNr()
Get order nr.
static _lookupTitle($a_obj_id)
Lookup Title.
create()
Create taxonomy node.
setOrderNr($a_val)
Set order nr.
static getNextOrderNr($a_tax_id, $a_parent_id)
Put this node into the taxonomy tree.
static sortArray($array, $a_array_sortby, $a_array_sortorder=0, $a_numeric=false, $a_keep_keys=false)
sortArray
global $ilDB