ILIAS  release_8 Revision v8.19
All Data Structures Namespaces Files Functions Variables Modules Pages
ilTaxNodeAssignment Class Reference

This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Learning e.V. More...

+ Collaboration diagram for ilTaxNodeAssignment:

Public Member Functions

 __construct (string $a_component_id, int $a_obj_id, string $a_item_type, int $a_tax_id, ilDBInterface $db=null)
 Constructor. More...
 
 getComponentId ()
 
 getItemType ()
 
 getTaxonomyId ()
 
 setObjectId (int $a_val)
 
 getObjectId ()
 
 getAssignmentsOfNode ($a_node_id)
 Get assignments of node. More...
 
 getAssignmentsOfItem (int $a_item_id)
 Get assignments for item. More...
 
 addAssignment (int $a_node_id, int $a_item_id, int $a_order_nr=0)
 Add assignment. More...
 
 deleteAssignment (int $a_node_id, int $a_item_id)
 
 getMaxOrderNr (int $a_node_id)
 
 setOrderNr (int $a_node_id, int $a_item_id, int $a_order_nr)
 
 deleteAssignmentsOfItem (int $a_item_id)
 
 deleteAssignmentsOfNode (int $a_node_id)
 
 fixOrderNr (int $a_node_id)
 

Static Public Member Functions

static deleteAllAssignmentsOfNode (int $a_node_id)
 
static findObjectsByNode (int $a_tax_id, array $a_node_ids, string $a_item_type)
 Find object which have assigned nodes. More...
 

Protected Member Functions

 setComponentId (string $a_val)
 
 setItemType (string $a_val)
 
 setTaxonomyId (int $a_val)
 

Protected Attributes

ilDBInterface $db
 
string $component_id
 
int $taxonomy_id
 
string $item_type
 
int $obj_id
 

Detailed Description

This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Learning e.V.

ILIAS is licensed with the GPL-3.0, see https://www.gnu.org/licenses/gpl-3.0.en.html You should have received a copy of said license along with the source code, too.

If this is not the case or you just want to try ILIAS, you'll find us at: https://www.ilias.de https://github.com/ILIAS-eLearning Taxonomy node <-> item assignment This class allows to assign items to taxonomy nodes.

Author
Alexander Killing killi.nosp@m.ng@l.nosp@m.eifos.nosp@m..de

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

Constructor & Destructor Documentation

◆ __construct()

ilTaxNodeAssignment::__construct ( string  $a_component_id,
int  $a_obj_id,
string  $a_item_type,
int  $a_tax_id,
ilDBInterface  $db = null 
)

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
ilDBInterface | null$db
Exceptions
ilTaxonomyException

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

References $db, $DIC, setComponentId(), setItemType(), setObjectId(), and setTaxonomyId().

47  {
48  global $DIC;
49 
50  $this->db = (is_null($db))
51  ? $DIC->database()
52  : $db;
53 
54  if ($a_component_id == "") {
55  throw new ilTaxonomyException('No component ID passed to ilTaxNodeAssignment.');
56  }
57 
58  if ($a_item_type == "") {
59  throw new ilTaxonomyException('No item type passed to ilTaxNodeAssignment.');
60  }
61 
62  if ($a_tax_id == 0) {
63  throw new ilTaxonomyException('No taxonomy ID passed to ilTaxNodeAssignment.');
64  }
65 
66  $this->setComponentId($a_component_id);
67  $this->setItemType($a_item_type);
68  $this->setTaxonomyId($a_tax_id);
69  $this->setObjectId($a_obj_id);
70  }
global $DIC
Definition: feed.php:28
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
+ Here is the call graph for this function:

Member Function Documentation

◆ addAssignment()

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

Add assignment.

Exceptions
ilTaxonomyException

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

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

Referenced by ilObjCategory\cloneDependencies(), and ilTaxonomyDataSet\importRecord().

177  : void
178  {
179  $ilDB = $this->db;
180 
181  // nothing to do, if not both IDs are greater 0
182  if ($a_node_id == 0 || $a_item_id == 0) {
183  return;
184  }
185 
186  // sanity check: does the node belong to the given taxonomy?
187  $set = $ilDB->query(
188  "SELECT tax_tree_id FROM tax_tree " .
189  " WHERE child = " . $ilDB->quote($a_node_id, "integer")
190  );
191  $rec = $ilDB->fetchAssoc($set);
192  if ($rec["tax_tree_id"] != $this->getTaxonomyId()) {
193  throw new ilTaxonomyException('addAssignment: Node ID does not belong to current taxonomy.');
194  }
195 
196  // do not re-assign, if assignment already exists
197  // order number should be kept in this case
198  $set2 = $ilDB->query(
199  $q = "SELECT item_id FROM tax_node_assignment " .
200  " WHERE component = " . $ilDB->quote($this->getComponentId(), "text") .
201  " AND item_type = " . $ilDB->quote($this->getItemType(), "text") .
202  " AND obj_id = " . $ilDB->quote($this->getObjectId(), "integer") .
203  " AND node_id = " . $ilDB->quote($a_node_id, "integer") .
204  " AND tax_id = " . $ilDB->quote($this->getTaxonomyId(), "integer") .
205  " AND item_id = " . $ilDB->quote($a_item_id, "integer")
206  );
207  if ($rec2 = $ilDB->fetchAssoc($set2)) {
208  return;
209  }
210 
211  if ($a_order_nr == 0) {
212  $a_order_nr = $this->getMaxOrderNr($a_node_id) + 10;
213  }
214 
215  $ilDB->replace(
216  "tax_node_assignment",
217  array(
218  "node_id" => array("integer", $a_node_id),
219  "component" => array("text", $this->getComponentId()),
220  "item_type" => array("text", $this->getItemType()),
221  "obj_id" => array("integer", $this->getObjectId()),
222  "item_id" => array("integer", $a_item_id)
223  ),
224  array(
225  "tax_id" => array("integer", $this->getTaxonomyId()),
226  "order_nr" => array("integer", $a_order_nr)
227  )
228  );
229  }
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ deleteAllAssignmentsOfNode()

static ilTaxNodeAssignment::deleteAllAssignmentsOfNode ( int  $a_node_id)
static

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

References $DIC, and $ilDB.

Referenced by ilTaxonomyNode\delete().

321  : void
322  {
323  global $DIC;
324 
325  $ilDB = $DIC->database();
326 
327  $ilDB->manipulate(
328  "DELETE FROM tax_node_assignment WHERE " .
329  " node_id = " . $ilDB->quote($a_node_id, "integer")
330  );
331  }
global $DIC
Definition: feed.php:28
+ Here is the caller graph for this function:

◆ deleteAssignment()

ilTaxNodeAssignment::deleteAssignment ( int  $a_node_id,
int  $a_item_id 
)

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

References $db, $ilDB, and getTaxonomyId().

231  : void
232  {
233  $ilDB = $this->db;
234 
235  // nothing to do, if not both IDs are greater 0
236  if ($a_node_id == 0 || $a_item_id == 0) {
237  return;
238  }
239 
240  // sanity check: does the node belong to the given taxonomy?
241  $set = $ilDB->query(
242  "SELECT tax_tree_id FROM tax_tree " .
243  " WHERE child = " . $ilDB->quote($a_node_id, "integer")
244  );
245  $rec = $ilDB->fetchAssoc($set);
246  if ((int) $rec["tax_tree_id"] != $this->getTaxonomyId()) {
247  throw new ilTaxonomyException('addAssignment: Node ID does not belong to current taxonomy.');
248  }
249 
250  $ilDB->manipulate(
251  "DELETE FROM tax_node_assignment WHERE " .
252  " component = " . $ilDB->quote($this->getComponentId(), "text") .
253  " AND item_type = " . $ilDB->quote($this->getItemType(), "text") .
254  " AND obj_id = " . $ilDB->quote($this->getObjectId(), "integer") .
255  " AND item_id = " . $ilDB->quote($a_item_id, "integer") .
256  " AND node_id = " . $ilDB->quote($a_node_id, "integer") .
257  " AND tax_id = " . $ilDB->quote($this->getTaxonomyId(), "integer")
258  );
259  }
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
+ Here is the call graph for this function:

◆ deleteAssignmentsOfItem()

ilTaxNodeAssignment::deleteAssignmentsOfItem ( int  $a_item_id)

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

References $db, $ilDB, and getTaxonomyId().

Referenced by ilGlossaryTermGUI\updateTerm().

294  : void
295  {
296  $ilDB = $this->db;
297 
298  $ilDB->manipulate(
299  "DELETE FROM tax_node_assignment WHERE " .
300  " component = " . $ilDB->quote($this->getComponentId(), "text") .
301  " AND item_type = " . $ilDB->quote($this->getItemType(), "text") .
302  " AND obj_id = " . $ilDB->quote($this->getObjectId(), "integer") .
303  " AND item_id = " . $ilDB->quote($a_item_id, "integer") .
304  " AND tax_id = " . $ilDB->quote($this->getTaxonomyId(), "integer")
305  );
306  }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ deleteAssignmentsOfNode()

ilTaxNodeAssignment::deleteAssignmentsOfNode ( int  $a_node_id)

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

References $db, $ilDB, getComponentId(), getItemType(), and getObjectId().

308  : void
309  {
310  $ilDB = $this->db;
311 
312  $ilDB->manipulate(
313  "DELETE FROM tax_node_assignment WHERE " .
314  " node_id = " . $ilDB->quote($a_node_id, "integer") .
315  " AND component = " . $ilDB->quote($this->getComponentId(), "text") .
316  " AND obj_id = " . $ilDB->quote($this->getObjectId(), "integer") .
317  " AND item_type = " . $ilDB->quote($this->getItemType(), "text")
318  );
319  }
+ Here is the call graph for this function:

◆ findObjectsByNode()

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

Find object which have assigned nodes.

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

References $DIC, $ilDB, $res, and ILIAS\Repository\int().

Referenced by ilTaxonomyClassificationProvider\getFilteredObjects().

366  : array
367  {
368  global $DIC;
369 
370  $ilDB = $DIC->database();
371 
372  $res = array();
373 
374  $set = $ilDB->query(
375  "SELECT * FROM tax_node_assignment" .
376  " WHERE " . $ilDB->in("node_id", $a_node_ids, "", "integer") .
377  " AND tax_id = " . $ilDB->quote($a_tax_id, "integer") .
378  " AND item_type = " . $ilDB->quote($a_item_type, "text") .
379  " ORDER BY order_nr ASC"
380  );
381  while ($row = $ilDB->fetchAssoc($set)) {
382  $res[] = (int) $row["obj_id"];
383  }
384 
385  return $res;
386  }
$res
Definition: ltiservices.php:69
global $DIC
Definition: feed.php:28
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ fixOrderNr()

ilTaxNodeAssignment::fixOrderNr ( int  $a_node_id)

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

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

334  : void
335  {
336  $ilDB = $this->db;
337 
338  $set = $ilDB->query(
339  "SELECT * FROM tax_node_assignment " .
340  " WHERE component = " . $ilDB->quote($this->getComponentId(), "text") .
341  " AND item_type = " . $ilDB->quote($this->getItemType(), "text") .
342  " AND obj_id = " . $ilDB->quote($this->getObjectId(), "integer") .
343  " AND node_id = " . $ilDB->quote($a_node_id, "integer") .
344  " AND tax_id = " . $ilDB->quote($this->getTaxonomyId(), "integer") .
345  " ORDER BY order_nr ASC"
346  );
347  $cnt = 10;
348  while ($rec = $ilDB->fetchAssoc($set)) {
349  $ilDB->manipulate(
350  "UPDATE tax_node_assignment SET " .
351  " order_nr = " . $ilDB->quote($cnt, "integer") .
352  " WHERE component = " . $ilDB->quote($this->getComponentId(), "text") .
353  " AND item_type = " . $ilDB->quote($this->getItemType(), "text") .
354  " AND obj_id = " . $ilDB->quote($this->getObjectId(), "integer") .
355  " AND node_id = " . $ilDB->quote($a_node_id, "integer") .
356  " AND tax_id = " . $ilDB->quote($this->getTaxonomyId(), "integer") .
357  " AND item_id = " . $ilDB->quote($rec["item_id"], "integer")
358  );
359  $cnt += 10;
360  }
361  }
+ Here is the call graph for this function:

◆ getAssignmentsOfItem()

ilTaxNodeAssignment::getAssignmentsOfItem ( int  $a_item_id)
final

Get assignments for item.

Returns
array array of tax node assignments arrays

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

References $db, $ilDB, getObjectId(), and getTaxonomyId().

Referenced by ilObjGlossary\cloneObject(), ilTestRandomQuestionSetPoolDeriver\filterForQuestionRelatedTaxonomies(), and assQuestionGUI\populateTaxonomyFormSection().

154  : array
155  {
156  $ilDB = $this->db;
157 
158  $set = $ilDB->query(
159  "SELECT * FROM tax_node_assignment" .
160  " WHERE component = " . $ilDB->quote($this->getComponentId(), "text") .
161  " AND item_type = " . $ilDB->quote($this->getItemType(), "text") .
162  " AND item_id = " . $ilDB->quote($a_item_id, "integer") .
163  " AND obj_id = " . $ilDB->quote($this->getObjectId(), "integer") .
164  " AND tax_id = " . $ilDB->quote($this->getTaxonomyId(), "integer")
165  );
166  $ass = array();
167  while ($rec = $ilDB->fetchAssoc($set)) {
168  $ass[] = $rec;
169  }
170  return $ass;
171  }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getAssignmentsOfNode()

ilTaxNodeAssignment::getAssignmentsOfNode (   $a_node_id)
final

Get assignments of node.

Parameters
string | array$a_node_idnode id
Returns
array array of tax node assignments arrays

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

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

117  : array
118  {
119  $ilDB = $this->db;
120 
121  if (is_array($a_node_id)) {
122  $set = $ilDB->query(
123  "SELECT * FROM tax_node_assignment " .
124  " WHERE " . $ilDB->in("node_id", $a_node_id, false, "integer") .
125  " AND tax_id = " . $ilDB->quote($this->getTaxonomyId(), "integer") .
126  " AND component = " . $ilDB->quote($this->getComponentId(), "text") .
127  " AND obj_id = " . $ilDB->quote($this->getObjectId(), "integer") .
128  " AND item_type = " . $ilDB->quote($this->getItemType(), "text") .
129  " ORDER BY order_nr ASC"
130  );
131  } else {
132  $set = $ilDB->query(
133  "SELECT * FROM tax_node_assignment " .
134  " WHERE node_id = " . $ilDB->quote($a_node_id, "integer") .
135  " AND tax_id = " . $ilDB->quote($this->getTaxonomyId(), "integer") .
136  " AND component = " . $ilDB->quote($this->getComponentId(), "text") .
137  " AND obj_id = " . $ilDB->quote($this->getObjectId(), "integer") .
138  " AND item_type = " . $ilDB->quote($this->getItemType(), "text") .
139  " ORDER BY order_nr ASC"
140  );
141  }
142  $ass = array();
143  while ($rec = $ilDB->fetchAssoc($set)) {
144  $ass[] = $rec;
145  }
146 
147  return $ass;
148  }
+ Here is the call graph for this function:

◆ getComponentId()

ilTaxNodeAssignment::getComponentId ( )

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

References $component_id.

Referenced by addAssignment(), deleteAssignmentsOfNode(), fixOrderNr(), getAssignmentsOfNode(), and setOrderNr().

77  : string
78  {
79  return $this->component_id;
80  }
+ Here is the caller graph for this function:

◆ getItemType()

ilTaxNodeAssignment::getItemType ( )

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

References $item_type.

Referenced by addAssignment(), deleteAssignmentsOfNode(), fixOrderNr(), getAssignmentsOfNode(), and setOrderNr().

87  : string
88  {
89  return $this->item_type;
90  }
+ Here is the caller graph for this function:

◆ getMaxOrderNr()

ilTaxNodeAssignment::getMaxOrderNr ( int  $a_node_id)

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

References $db, $ilDB, and getTaxonomyId().

Referenced by addAssignment().

261  : int
262  {
263  $ilDB = $this->db;
264 
265  $set = $ilDB->query(
266  "SELECT max(order_nr) mnr FROM tax_node_assignment " .
267  " WHERE component = " . $ilDB->quote($this->getComponentId(), "text") .
268  " AND item_type = " . $ilDB->quote($this->getItemType(), "text") .
269  " AND obj_id = " . $ilDB->quote($this->getObjectId(), "integer") .
270  " AND node_id = " . $ilDB->quote($a_node_id, "integer") .
271  " AND tax_id = " . $ilDB->quote($this->getTaxonomyId(), "integer")
272  );
273  $rec = $ilDB->fetchAssoc($set);
274 
275  return (int) $rec["mnr"];
276  }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getObjectId()

ilTaxNodeAssignment::getObjectId ( )

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

References $obj_id.

Referenced by addAssignment(), deleteAssignmentsOfNode(), fixOrderNr(), getAssignmentsOfItem(), getAssignmentsOfNode(), and setOrderNr().

107  : int
108  {
109  return $this->obj_id;
110  }
+ Here is the caller graph for this function:

◆ getTaxonomyId()

ilTaxNodeAssignment::getTaxonomyId ( )

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

References $taxonomy_id.

Referenced by addAssignment(), deleteAssignment(), deleteAssignmentsOfItem(), fixOrderNr(), getAssignmentsOfItem(), getAssignmentsOfNode(), getMaxOrderNr(), and setOrderNr().

97  : int
98  {
99  return $this->taxonomy_id;
100  }
+ Here is the caller graph for this function:

◆ setComponentId()

ilTaxNodeAssignment::setComponentId ( string  $a_val)
protected

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

Referenced by __construct().

72  : void
73  {
74  $this->component_id = $a_val;
75  }
+ Here is the caller graph for this function:

◆ setItemType()

ilTaxNodeAssignment::setItemType ( string  $a_val)
protected

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

Referenced by __construct().

82  : void
83  {
84  $this->item_type = $a_val;
85  }
+ Here is the caller graph for this function:

◆ setObjectId()

ilTaxNodeAssignment::setObjectId ( int  $a_val)

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

Referenced by __construct().

102  : void
103  {
104  $this->obj_id = $a_val;
105  }
+ Here is the caller graph for this function:

◆ setOrderNr()

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

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

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

278  : void
279  {
280  $ilDB = $this->db;
281 
282  $ilDB->manipulate(
283  "UPDATE tax_node_assignment SET " .
284  " order_nr = " . $ilDB->quote($a_order_nr, "integer") .
285  " WHERE component = " . $ilDB->quote($this->getComponentId(), "text") .
286  " AND item_type = " . $ilDB->quote($this->getItemType(), "text") .
287  " AND obj_id = " . $ilDB->quote($this->getObjectId(), "integer") .
288  " AND node_id = " . $ilDB->quote($a_node_id, "integer") .
289  " AND item_id = " . $ilDB->quote($a_item_id, "integer") .
290  " AND tax_id = " . $ilDB->quote($this->getTaxonomyId(), "integer")
291  );
292  }
+ Here is the call graph for this function:

◆ setTaxonomyId()

ilTaxNodeAssignment::setTaxonomyId ( int  $a_val)
protected

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

Referenced by __construct().

92  : void
93  {
94  $this->taxonomy_id = $a_val;
95  }
+ Here is the caller graph for this function:

Field Documentation

◆ $component_id

string ilTaxNodeAssignment::$component_id
protected

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

Referenced by getComponentId().

◆ $db

◆ $item_type

string ilTaxNodeAssignment::$item_type
protected

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

Referenced by getItemType().

◆ $obj_id

int ilTaxNodeAssignment::$obj_id
protected

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

Referenced by getObjectId().

◆ $taxonomy_id

int ilTaxNodeAssignment::$taxonomy_id
protected

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

Referenced by getTaxonomyId().


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