ILIAS  release_7 Revision v7.30-3-g800a261c036
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...
 

Protected Attributes

 $db
 

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 33 of file class.ilTaxNodeAssignment.php.

34 {
35 global $DIC;
36
37 $this->db = $DIC->database();
38 if ($a_component_id == "") {
39 throw new ilTaxonomyException('No component ID passed to ilTaxNodeAssignment.');
40 }
41
42 if ($a_item_type == "") {
43 throw new ilTaxonomyException('No item type passed to ilTaxNodeAssignment.');
44 }
45
46 if ((int) $a_tax_id == 0) {
47 throw new ilTaxonomyException('No taxonomy ID passed to ilTaxNodeAssignment.');
48 }
49
50 $this->setComponentId($a_component_id);
51 $this->setItemType($a_item_type);
52 $this->setTaxonomyId($a_tax_id);
53 $this->setObjectId($a_obj_id);
54 }
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.
global $DIC
Definition: goto.php:24

References $DIC, 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 208 of file class.ilTaxNodeAssignment.php.

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

References $db, $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 387 of file class.ilTaxNodeAssignment.php.

388 {
389 global $DIC;
390
391 $ilDB = $DIC->database();
392
393 $ilDB->manipulate(
394 "DELETE FROM tax_node_assignment WHERE " .
395 " node_id = " . $ilDB->quote($a_node_id, "integer")
396 );
397 }

References $DIC, and $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 269 of file class.ilTaxNodeAssignment.php.

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

References $db, $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 350 of file class.ilTaxNodeAssignment.php.

351 {
353
354 $ilDB->manipulate(
355 "DELETE FROM tax_node_assignment WHERE " .
356 " component = " . $ilDB->quote($this->getComponentId(), "text") .
357 " AND item_type = " . $ilDB->quote($this->getItemType(), "text") .
358 " AND obj_id = " . $ilDB->quote($this->getObjectId(), "integer") .
359 " AND item_id = " . $ilDB->quote($a_item_id, "integer") .
360 " AND tax_id = " . $ilDB->quote($this->getTaxonomyId(), "integer")
361 );
362 }

References $db, and $ilDB.

◆ deleteAssignmentsOfNode()

ilTaxNodeAssignment::deleteAssignmentsOfNode (   $a_node_id)

Delete assignments of node.

Parameters
int$a_node_idnode id

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

370 {
372
373 $ilDB->manipulate(
374 "DELETE FROM tax_node_assignment WHERE " .
375 " node_id = " . $ilDB->quote($a_node_id, "integer") .
376 " AND component = " . $ilDB->quote($this->getComponentId(), "text") .
377 " AND obj_id = " . $ilDB->quote($this->getObjectId(), "integer") .
378 " AND item_type = " . $ilDB->quote($this->getItemType(), "text")
379 );
380 }

References $db, and $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 441 of file class.ilTaxNodeAssignment.php.

442 {
443 global $DIC;
444
445 $ilDB = $DIC->database();
446
447 $res = array();
448
449 $set = $ilDB->query(
450 "SELECT * FROM tax_node_assignment" .
451 " WHERE " . $ilDB->in("node_id", $a_node_ids, "", "integer") .
452 " AND tax_id = " . $ilDB->quote($a_tax_id, "integer") .
453 " AND item_type = " . $ilDB->quote($a_item_type, "text") .
454 " ORDER BY order_nr ASC"
455 );
456 while ($row = $ilDB->fetchAssoc($set)) {
457 $res[] = $row["obj_id"];
458 }
459
460 return $res;
461 }
foreach($_POST as $key=> $value) $res

References $DIC, $ilDB, and $res.

Referenced by ilTaxonomyClassificationProvider\getFilteredObjects().

+ Here is the caller graph for this function:

◆ fixOrderNr()

ilTaxNodeAssignment::fixOrderNr (   $a_node_id)

Fix Order Nr.

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

403 {
405
406 $set = $ilDB->query(
407 "SELECT * FROM tax_node_assignment " .
408 " WHERE component = " . $ilDB->quote($this->getComponentId(), "text") .
409 " AND item_type = " . $ilDB->quote($this->getItemType(), "text") .
410 " AND obj_id = " . $ilDB->quote($this->getObjectId(), "integer") .
411 " AND node_id = " . $ilDB->quote($a_node_id, "integer") .
412 " AND tax_id = " . $ilDB->quote($this->getTaxonomyId(), "integer") .
413 " ORDER BY order_nr ASC"
414 );
415 $cnt = 10;
416 while ($rec = $ilDB->fetchAssoc($set)) {
417 $ilDB->manipulate(
418 "UPDATE tax_node_assignment SET " .
419 " order_nr = " . $ilDB->quote($cnt, "integer") .
420 " WHERE component = " . $ilDB->quote($this->getComponentId(), "text") .
421 " AND item_type = " . $ilDB->quote($this->getItemType(), "text") .
422 " AND obj_id = " . $ilDB->quote($this->getObjectId(), "integer") .
423 " AND node_id = " . $ilDB->quote($a_node_id, "integer") .
424 " AND tax_id = " . $ilDB->quote($this->getTaxonomyId(), "integer") .
425 " AND item_id = " . $ilDB->quote($rec["item_id"], "integer")
426 );
427 $cnt += 10;
428 }
429 }

References $db, and $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 181 of file class.ilTaxNodeAssignment.php.

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

References $db, and $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 142 of file class.ilTaxNodeAssignment.php.

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

References $db, and $ilDB.

◆ getComponentId()

ilTaxNodeAssignment::getComponentId ( )

Get component id.

Returns
string component id

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

72 {
73 return $this->component_id;
74 }

Referenced by addAssignment().

+ Here is the caller graph for this function:

◆ getItemType()

ilTaxNodeAssignment::getItemType ( )

Get item type.

Returns
string item type

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

92 {
93 return $this->item_type;
94 }

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 305 of file class.ilTaxNodeAssignment.php.

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

References $db, and $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 131 of file class.ilTaxNodeAssignment.php.

132 {
133 return $this->obj_id;
134 }

Referenced by addAssignment().

+ Here is the caller graph for this function:

◆ getTaxonomyId()

ilTaxNodeAssignment::getTaxonomyId ( )

Get taxonomy id.

Returns
int taxonomy id

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

112 {
113 return $this->taxonomy_id;
114 }

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 61 of file class.ilTaxNodeAssignment.php.

62 {
63 $this->component_id = $a_val;
64 }

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 81 of file class.ilTaxNodeAssignment.php.

82 {
83 $this->item_type = $a_val;
84 }

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 121 of file class.ilTaxNodeAssignment.php.

122 {
123 $this->obj_id = $a_val;
124 }

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 328 of file class.ilTaxNodeAssignment.php.

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

References $db, and $ilDB.

◆ setTaxonomyId()

ilTaxNodeAssignment::setTaxonomyId (   $a_val)
protected

Set taxonomy id.

Parameters
int$a_valtaxonomy id

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

102 {
103 $this->taxonomy_id = $a_val;
104 }

Referenced by __construct().

+ Here is the caller graph for this function:

Field Documentation

◆ $db


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