ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
ilTaxNodeAssignment Class Reference

Taxonomy node <-> item assignment. More...

+ Collaboration diagram for ilTaxNodeAssignment:

Public Member Functions

 __construct ($a_component_id, $a_obj_id, $a_item_type, $a_tax_id)
 Constructor. More...
 
 getComponentId ()
 Get component id. More...
 
 getItemType ()
 Get item type. More...
 
 getTaxonomyId ()
 Get taxonomy id. More...
 
 setObjectId ($a_val)
 Set object id. More...
 
 getObjectId ()
 Get object id. More...
 
 getAssignmentsOfNode ($a_node_id)
 Get assignments of node. More...
 
 getAssignmentsOfItem ($a_item_id)
 Get assignments for item. More...
 
 addAssignment ($a_node_id, $a_item_id, $a_order_nr=0)
 Add assignment. More...
 
 deleteAssignment ($a_node_id, $a_item_id)
 Delete assignment. More...
 
 getMaxOrderNr ($a_node_id)
 Get maximum order number. More...
 
 setOrderNr ($a_node_id, $a_item_id, $a_order_nr)
 Set order nr. More...
 
 deleteAssignmentsOfItem ($a_item_id)
 Delete assignments of item. More...
 
 deleteAssignmentsOfNode ($a_node_id)
 Delete assignments of node. More...
 
 fixOrderNr ($a_node_id)
 Fix Order Nr. More...
 

Static Public Member Functions

static deleteAllAssignmentsOfNode ($a_node_id)
 Delete assignments of node. More...
 
static findObjectsByNode ($a_tax_id, array $a_node_ids, $a_item_type)
 Find object which have assigned nodes. More...
 

Protected Member Functions

 setComponentId ($a_val)
 Set component id. More...
 
 setItemType ($a_val)
 Set item type. More...
 
 setTaxonomyId ($a_val)
 Set taxonomy id. More...
 

Detailed Description

Taxonomy node <-> item assignment.

This class allows to assign items to taxonomy nodes.

Author
Alex Killing alex..nosp@m.kill.nosp@m.ing@g.nosp@m.mx.d.nosp@m.e
Version
$Id$

/

Definition at line 17 of file class.ilTaxNodeAssignment.php.

Constructor & Destructor Documentation

◆ __construct()

ilTaxNodeAssignment::__construct (   $a_component_id,
  $a_obj_id,
  $a_item_type,
  $a_tax_id 
)

Constructor.

Parameters
string$a_component_idcomponent id (e.g. "glo" for Modules/Glossary)
int$a_obj_idrepository object id of the object that is responsible for the assignment
string$a_item_typeitem type (e.g. "term", must be unique component wide) [use "obj" if repository object wide taxonomies!]
int$a_tax_idtaxonomy id
Exceptions
ilTaxonomyException

Definition at line 28 of file class.ilTaxNodeAssignment.php.

29 {
30 if ($a_component_id == "")
31 {
32 throw new ilTaxonomyException('No component ID passed to ilTaxNodeAssignment.');
33 }
34
35 if ($a_item_type == "")
36 {
37 throw new ilTaxonomyException('No item type passed to ilTaxNodeAssignment.');
38 }
39
40 if ((int) $a_tax_id == 0)
41 {
42 throw new ilTaxonomyException('No taxonomy ID passed to ilTaxNodeAssignment.');
43 }
44
45 $this->setComponentId($a_component_id);
46 $this->setItemType($a_item_type);
47 $this->setTaxonomyId($a_tax_id);
48 $this->setObjectId($a_obj_id);
49 }
setComponentId($a_val)
Set component id.
setTaxonomyId($a_val)
Set taxonomy id.
setItemType($a_val)
Set item type.
setObjectId($a_val)
Set object id.
Class for advanced editing exception handling in ILIAS.

References setComponentId(), setItemType(), setObjectId(), and setTaxonomyId().

+ Here is the call graph for this function:

Member Function Documentation

◆ addAssignment()

ilTaxNodeAssignment::addAssignment (   $a_node_id,
  $a_item_id,
  $a_order_nr = 0 
)

Add assignment.

Parameters
int$a_node_idnode id
int$a_item_iditem id
int$a_order_nrorder nr
Exceptions
ilTaxonomyException

Definition at line 205 of file class.ilTaxNodeAssignment.php.

206 {
207 global $ilDB;
208
209 // nothing to do, if not both IDs are greater 0
210 if ((int) $a_node_id == 0 || (int) $a_item_id == 0)
211 {
212 return;
213 }
214
215 // sanity check: does the node belong to the given taxonomy?
216 $set = $ilDB->query("SELECT tax_tree_id FROM tax_tree ".
217 " WHERE child = ".$ilDB->quote($a_node_id, "integer")
218 );
219 $rec = $ilDB->fetchAssoc($set);
220 if ($rec["tax_tree_id"] != $this->getTaxonomyId())
221 {
222 throw new ilTaxonomyException('addAssignment: Node ID does not belong to current taxonomy.');
223 }
224
225 // do not re-assign, if assignment already exists
226 // order number should be kept in this case
227 $set2 = $ilDB->query($q = "SELECT item_id FROM tax_node_assignment ".
228 " WHERE component = ".$ilDB->quote($this->getComponentId(), "text").
229 " AND item_type = ".$ilDB->quote($this->getItemType(), "text").
230 " AND obj_id = ".$ilDB->quote($this->getObjectId(), "integer").
231 " AND node_id = ".$ilDB->quote($a_node_id, "integer").
232 " AND tax_id = ".$ilDB->quote($this->getTaxonomyId(), "integer").
233 " AND item_id = ".$ilDB->quote($a_item_id, "integer")
234 );
235 if ($rec2 = $ilDB->fetchAssoc($set2))
236 {
237 return;
238 }
239
240 if ($a_order_nr == 0)
241 {
242 $a_order_nr = $this->getMaxOrderNr($a_node_id) + 10;
243 }
244
245 $ilDB->replace("tax_node_assignment",
246 array(
247 "node_id" => array("integer", $a_node_id),
248 "component" => array("text", $this->getComponentId()),
249 "item_type" => array("text", $this->getItemType()),
250 "obj_id" => array("integer", $this->getObjectId()),
251 "item_id" => array("integer", $a_item_id)
252 ),
253 array(
254 "tax_id" => array("integer", $this->getTaxonomyId()),
255 "order_nr" => array("integer", $a_order_nr)
256 )
257 );
258 }
getMaxOrderNr($a_node_id)
Get maximum order number.
getComponentId()
Get component id.
global $ilDB

References $ilDB, getComponentId(), getItemType(), getMaxOrderNr(), getObjectId(), and getTaxonomyId().

+ Here is the call graph for this function:

◆ deleteAllAssignmentsOfNode()

static ilTaxNodeAssignment::deleteAllAssignmentsOfNode (   $a_node_id)
static

Delete assignments of node.

Parameters
int$a_node_idnode id

Definition at line 381 of file class.ilTaxNodeAssignment.php.

382 {
383 global $ilDB;
384
385 $ilDB->manipulate("DELETE FROM tax_node_assignment WHERE ".
386 " node_id = ".$ilDB->quote($a_node_id, "integer")
387 );
388 }

References $ilDB.

Referenced by ilTaxonomyNode\delete().

+ Here is the caller graph for this function:

◆ deleteAssignment()

ilTaxNodeAssignment::deleteAssignment (   $a_node_id,
  $a_item_id 
)

Delete assignment.

Parameters
int$a_node_idnode id
int$a_item_iditem id
Exceptions
ilTaxonomyException

Definition at line 267 of file class.ilTaxNodeAssignment.php.

268 {
269 global $ilDB;
270
271 // nothing to do, if not both IDs are greater 0
272 if ((int) $a_node_id == 0 || (int) $a_item_id == 0)
273 {
274 return;
275 }
276
277 // sanity check: does the node belong to the given taxonomy?
278 $set = $ilDB->query("SELECT tax_tree_id FROM tax_tree ".
279 " WHERE child = ".$ilDB->quote($a_node_id, "integer")
280 );
281 $rec = $ilDB->fetchAssoc($set);
282 if ($rec["tax_tree_id"] != $this->getTaxonomyId())
283 {
284 throw new ilTaxonomyException('addAssignment: Node ID does not belong to current taxonomy.');
285 }
286
287 $ilDB->manipulate("DELETE FROM tax_node_assignment WHERE ".
288 " component = ".$ilDB->quote($this->getComponentId(), "text").
289 " AND item_type = ".$ilDB->quote($this->getItemType(), "text").
290 " AND obj_id = ".$ilDB->quote($this->getObjectId(), "integer").
291 " AND item_id = ".$ilDB->quote($a_item_id, "integer").
292 " AND node_id = ".$ilDB->quote($a_node_id, "integer").
293 " AND tax_id = ".$ilDB->quote($this->getTaxonomyId(), "integer")
294 );
295 }

References $ilDB, and getTaxonomyId().

+ Here is the call graph for this function:

◆ deleteAssignmentsOfItem()

ilTaxNodeAssignment::deleteAssignmentsOfItem (   $a_item_id)

Delete assignments of item.

Parameters
int$a_item_iditem id

Definition at line 346 of file class.ilTaxNodeAssignment.php.

347 {
348 global $ilDB;
349
350 $ilDB->manipulate("DELETE FROM tax_node_assignment WHERE ".
351 " component = ".$ilDB->quote($this->getComponentId(), "text").
352 " AND item_type = ".$ilDB->quote($this->getItemType(), "text").
353 " AND obj_id = ".$ilDB->quote($this->getObjectId(), "integer").
354 " AND item_id = ".$ilDB->quote($a_item_id, "integer").
355 " AND tax_id = ".$ilDB->quote($this->getTaxonomyId(), "integer")
356 );
357 }

References $ilDB.

◆ deleteAssignmentsOfNode()

ilTaxNodeAssignment::deleteAssignmentsOfNode (   $a_node_id)

Delete assignments of node.

Parameters
int$a_node_idnode id

Definition at line 364 of file class.ilTaxNodeAssignment.php.

365 {
366 global $ilDB;
367
368 $ilDB->manipulate("DELETE FROM tax_node_assignment WHERE ".
369 " node_id = ".$ilDB->quote($a_node_id, "integer").
370 " AND component = ".$ilDB->quote($this->getComponentId(), "text").
371 " AND obj_id = ".$ilDB->quote($this->getObjectId(), "integer").
372 " AND item_type = ".$ilDB->quote($this->getItemType(), "text")
373 );
374 }

References $ilDB.

◆ findObjectsByNode()

static ilTaxNodeAssignment::findObjectsByNode (   $a_tax_id,
array  $a_node_ids,
  $a_item_type 
)
static

Find object which have assigned nodes.

Parameters
int$a_item_type
int$a_tax_id
array$a_node_ids
Returns
array

Definition at line 431 of file class.ilTaxNodeAssignment.php.

432 {
433 global $ilDB;
434
435 $res = array();
436
437 $set = $ilDB->query("SELECT * FROM tax_node_assignment".
438 " WHERE ".$ilDB->in("node_id", $a_node_ids, "", "integer").
439 " AND tax_id = ".$ilDB->quote($a_tax_id, "integer").
440 " AND item_type = ".$ilDB->quote($a_item_type, "text").
441 " ORDER BY order_nr ASC"
442 );
443 while($row = $ilDB->fetchAssoc($set))
444 {
445 $res[] = $row["obj_id"];
446 }
447
448 return $res;
449 }

References $ilDB, $res, and $row.

Referenced by ilTaxonomyClassificationProvider\getFilteredObjects().

+ Here is the caller graph for this function:

◆ fixOrderNr()

ilTaxNodeAssignment::fixOrderNr (   $a_node_id)

Fix Order Nr.

Definition at line 393 of file class.ilTaxNodeAssignment.php.

394 {
395 global $ilDB;
396
397 $set = $ilDB->query("SELECT * FROM tax_node_assignment ".
398 " WHERE component = ".$ilDB->quote($this->getComponentId(), "text").
399 " AND item_type = ".$ilDB->quote($this->getItemType(), "text").
400 " AND obj_id = ".$ilDB->quote($this->getObjectId(), "integer").
401 " AND node_id = ".$ilDB->quote($a_node_id, "integer").
402 " AND tax_id = ".$ilDB->quote($this->getTaxonomyId(), "integer").
403 " ORDER BY order_nr ASC"
404 );
405 $cnt = 10;
406 while ($rec = $ilDB->fetchAssoc($set))
407 {
408 $ilDB->manipulate("UPDATE tax_node_assignment SET ".
409 " order_nr = ".$ilDB->quote($cnt, "integer").
410 " WHERE component = ".$ilDB->quote($this->getComponentId(), "text").
411 " AND item_type = ".$ilDB->quote($this->getItemType(), "text").
412 " AND obj_id = ".$ilDB->quote($this->getObjectId(), "integer").
413 " AND node_id = ".$ilDB->quote($a_node_id, "integer").
414 " AND tax_id = ".$ilDB->quote($this->getTaxonomyId(), "integer").
415 " AND item_id = ".$ilDB->quote($rec["item_id"], "integer")
416 );
417 $cnt+= 10;
418 }
419 }

References $ilDB.

◆ getAssignmentsOfItem()

ilTaxNodeAssignment::getAssignmentsOfItem (   $a_item_id)
final

Get assignments for item.

Parameters
int$a_item_iditem id
Returns
array array of tax node assignments arrays

Definition at line 178 of file class.ilTaxNodeAssignment.php.

179 {
180 global $ilDB;
181
182 $set = $ilDB->query("SELECT * FROM tax_node_assignment".
183 " WHERE component = ".$ilDB->quote($this->getComponentId(), "text").
184 " AND item_type = ".$ilDB->quote($this->getItemType(), "text").
185 " AND item_id = ".$ilDB->quote($a_item_id, "integer").
186 " AND obj_id = ".$ilDB->quote($this->getObjectId(), "integer").
187 " AND tax_id = ".$ilDB->quote($this->getTaxonomyId(), "integer")
188 );
189 $ass = array();
190 while ($rec = $ilDB->fetchAssoc($set))
191 {
192 $ass[] = $rec;
193 }
194 return $ass;
195 }

References $ilDB.

◆ getAssignmentsOfNode()

ilTaxNodeAssignment::getAssignmentsOfNode (   $a_node_id)
final

Get assignments of node.

Parameters
int$a_node_idnode id
Returns
array array of tax node assignments arrays

Definition at line 137 of file class.ilTaxNodeAssignment.php.

138 {
139 global $ilDB;
140
141 if (is_array($a_node_id))
142 {
143 $set = $ilDB->query("SELECT * FROM tax_node_assignment ".
144 " WHERE ".$ilDB->in("node_id", $a_node_id, false, "integer").
145 " AND tax_id = ".$ilDB->quote($this->getTaxonomyId(), "integer").
146 " AND component = ".$ilDB->quote($this->getComponentId(), "text").
147 " AND obj_id = ".$ilDB->quote($this->getObjectId(), "integer").
148 " AND item_type = ".$ilDB->quote($this->getItemType(), "text").
149 " ORDER BY order_nr ASC"
150 );
151 }
152 else
153 {
154 $set = $ilDB->query("SELECT * FROM tax_node_assignment ".
155 " WHERE node_id = ".$ilDB->quote($a_node_id, "integer").
156 " AND tax_id = ".$ilDB->quote($this->getTaxonomyId(), "integer").
157 " AND component = ".$ilDB->quote($this->getComponentId(), "text").
158 " AND obj_id = ".$ilDB->quote($this->getObjectId(), "integer").
159 " AND item_type = ".$ilDB->quote($this->getItemType(), "text").
160 " ORDER BY order_nr ASC"
161 );
162 }
163 $ass = array();
164 while ($rec = $ilDB->fetchAssoc($set))
165 {
166 $ass[] = $rec;
167 }
168
169 return $ass;
170 }

References $ilDB.

◆ getComponentId()

ilTaxNodeAssignment::getComponentId ( )

Get component id.

Returns
string component id

Definition at line 66 of file class.ilTaxNodeAssignment.php.

67 {
68 return $this->component_id;
69 }

Referenced by addAssignment().

+ Here is the caller graph for this function:

◆ getItemType()

ilTaxNodeAssignment::getItemType ( )

Get item type.

Returns
string item type

Definition at line 86 of file class.ilTaxNodeAssignment.php.

87 {
88 return $this->item_type;
89 }

Referenced by addAssignment().

+ Here is the caller graph for this function:

◆ getMaxOrderNr()

ilTaxNodeAssignment::getMaxOrderNr (   $a_node_id)

Get maximum order number.

Parameters

return

Definition at line 303 of file class.ilTaxNodeAssignment.php.

304 {
305 global $ilDB;
306
307 $set = $ilDB->query("SELECT max(order_nr) mnr FROM tax_node_assignment ".
308 " WHERE component = ".$ilDB->quote($this->getComponentId(), "text").
309 " AND item_type = ".$ilDB->quote($this->getItemType(), "text").
310 " AND obj_id = ".$ilDB->quote($this->getObjectId(), "integer").
311 " AND node_id = ".$ilDB->quote($a_node_id, "integer").
312 " AND tax_id = ".$ilDB->quote($this->getTaxonomyId(), "integer")
313 );
314 $rec = $ilDB->fetchAssoc($set);
315
316 return (int) $rec["mnr"];
317 }

References $ilDB.

Referenced by addAssignment().

+ Here is the caller graph for this function:

◆ getObjectId()

ilTaxNodeAssignment::getObjectId ( )

Get object id.

Returns
int object id

Definition at line 126 of file class.ilTaxNodeAssignment.php.

127 {
128 return $this->obj_id;
129 }

Referenced by addAssignment().

+ Here is the caller graph for this function:

◆ getTaxonomyId()

ilTaxNodeAssignment::getTaxonomyId ( )

Get taxonomy id.

Returns
int taxonomy id

Definition at line 106 of file class.ilTaxNodeAssignment.php.

107 {
108 return $this->taxonomy_id;
109 }

Referenced by addAssignment(), and deleteAssignment().

+ Here is the caller graph for this function:

◆ setComponentId()

ilTaxNodeAssignment::setComponentId (   $a_val)
protected

Set component id.

Parameters
string$a_valcomponent id

Definition at line 56 of file class.ilTaxNodeAssignment.php.

57 {
58 $this->component_id = $a_val;
59 }

Referenced by __construct().

+ Here is the caller graph for this function:

◆ setItemType()

ilTaxNodeAssignment::setItemType (   $a_val)
protected

Set item type.

Parameters
string$a_valitem type

Definition at line 76 of file class.ilTaxNodeAssignment.php.

77 {
78 $this->item_type = $a_val;
79 }

Referenced by __construct().

+ Here is the caller graph for this function:

◆ setObjectId()

ilTaxNodeAssignment::setObjectId (   $a_val)

Set object id.

Parameters
int$a_valobject id

Definition at line 116 of file class.ilTaxNodeAssignment.php.

117 {
118 $this->obj_id = $a_val;
119 }

Referenced by __construct().

+ Here is the caller graph for this function:

◆ setOrderNr()

ilTaxNodeAssignment::setOrderNr (   $a_node_id,
  $a_item_id,
  $a_order_nr 
)

Set order nr.

Parameters

return

Definition at line 325 of file class.ilTaxNodeAssignment.php.

326 {
327 global $ilDB;
328
329 $ilDB->manipulate("UPDATE tax_node_assignment SET ".
330 " order_nr = ".$ilDB->quote($a_order_nr, "integer").
331 " WHERE component = ".$ilDB->quote($this->getComponentId(), "text").
332 " AND item_type = ".$ilDB->quote($this->getItemType(), "text").
333 " AND obj_id = ".$ilDB->quote($this->getObjectId(), "integer").
334 " AND node_id = ".$ilDB->quote($a_node_id, "integer").
335 " AND item_id = ".$ilDB->quote($a_item_id, "integer").
336 " AND tax_id = ".$ilDB->quote($this->getTaxonomyId(), "integer")
337 );
338 }

References $ilDB.

◆ setTaxonomyId()

ilTaxNodeAssignment::setTaxonomyId (   $a_val)
protected

Set taxonomy id.

Parameters
int$a_valtaxonomy id

Definition at line 96 of file class.ilTaxNodeAssignment.php.

97 {
98 $this->taxonomy_id = $a_val;
99 }

Referenced by __construct().

+ Here is the caller graph for this function:

The documentation for this class was generated from the following file: