ILIAS  Release_4_4_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
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.
 getComponentId ()
 Get component id.
 getItemType ()
 Get item type.
 getTaxonomyId ()
 Get taxonomy id.
 setObjectId ($a_val)
 Set object id.
 getObjectId ()
 Get object id.
 getAssignmentsOfNode ($a_node_id)
 Get assignments of node.
 getAssignmentsOfItem ($a_item_id)
 Get assignments for item.
 addAssignment ($a_node_id, $a_item_id, $a_order_nr=0)
 Add assignment.
 deleteAssignment ($a_node_id, $a_item_id)
 Delete assignment.
 getMaxOrderNr ($a_node_id)
 Get maximum order number.
 setOrderNr ($a_node_id, $a_item_id, $a_order_nr)
 Set order nr.
 deleteAssignmentsOfItem ($a_item_id)
 Delete assignments of item.
 deleteAssignmentsOfNode ($a_node_id)
 Delete assignments of node.
 fixOrderNr ($a_node_id)
 Fix Order Nr.

Static Public Member Functions

static deleteAllAssignmentsOfNode ($a_node_id)
 Delete assignments of node.

Protected Member Functions

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

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

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)
int$a_tax_idtaxonomy id
Exceptions
ilTaxonomyException

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

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

{
if ($a_component_id == "")
{
throw new ilTaxonomyException('No component ID passed to ilTaxNodeAssignment.');
}
if ($a_item_type == "")
{
throw new ilTaxonomyException('No item type passed to ilTaxNodeAssignment.');
}
if ((int) $a_tax_id == 0)
{
throw new ilTaxonomyException('No taxonomy ID passed to ilTaxNodeAssignment.');
}
$this->setComponentId($a_component_id);
$this->setItemType($a_item_type);
$this->setTaxonomyId($a_tax_id);
$this->setObjectId($a_obj_id);
}

+ Here is the call graph for this function:

Member Function Documentation

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.

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

Referenced by ilTaxonomyDataSet\importRecord().

{
global $ilDB;
// nothing to do, if not both IDs are greater 0
if ((int) $a_node_id == 0 || (int) $a_item_id == 0)
{
return;
}
// sanity check: does the node belong to the given taxonomy?
$set = $ilDB->query("SELECT tax_tree_id FROM tax_tree ".
" WHERE child = ".$ilDB->quote($a_node_id, "integer")
);
$rec = $ilDB->fetchAssoc($set);
if ($rec["tax_tree_id"] != $this->getTaxonomyId())
{
throw new ilTaxonomyException('addAssignment: Node ID does not belong to current taxonomy.');
}
// do not re-assign, if assignment already exists
// order number should be kept in this case
$set2 = $ilDB->query($q = "SELECT item_id FROM tax_node_assignment ".
" WHERE component = ".$ilDB->quote($this->getComponentId(), "text").
" AND item_type = ".$ilDB->quote($this->getItemType(), "text").
" AND obj_id = ".$ilDB->quote($this->getObjectId(), "integer").
" AND node_id = ".$ilDB->quote($a_node_id, "integer").
" AND tax_id = ".$ilDB->quote($this->getTaxonomyId(), "integer").
" AND item_id = ".$ilDB->quote($a_item_id, "integer")
);
if ($rec2 = $ilDB->fetchAssoc($set2))
{
return;
}
if ($a_order_nr == 0)
{
$a_order_nr = $this->getMaxOrderNr($a_node_id) + 10;
}
$ilDB->replace("tax_node_assignment",
array(
"node_id" => array("integer", $a_node_id),
"component" => array("text", $this->getComponentId()),
"item_type" => array("text", $this->getItemType()),
"obj_id" => array("integer", $this->getObjectId()),
"item_id" => array("integer", $a_item_id)
),
array(
"tax_id" => array("integer", $this->getTaxonomyId()),
"order_nr" => array("integer", $a_order_nr)
)
);
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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.

Referenced by ilTaxonomyNode\delete().

{
global $ilDB;
$ilDB->manipulate("DELETE FROM tax_node_assignment WHERE ".
" node_id = ".$ilDB->quote($a_node_id, "integer")
);
}

+ Here is the caller graph for this function:

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.

References getTaxonomyId().

{
global $ilDB;
// nothing to do, if not both IDs are greater 0
if ((int) $a_node_id == 0 || (int) $a_item_id == 0)
{
return;
}
// sanity check: does the node belong to the given taxonomy?
$set = $ilDB->query("SELECT tax_tree_id FROM tax_tree ".
" WHERE child = ".$ilDB->quote($a_node_id, "integer")
);
$rec = $ilDB->fetchAssoc($set);
if ($rec["tax_tree_id"] != $this->getTaxonomyId())
{
throw new ilTaxonomyException('addAssignment: Node ID does not belong to current taxonomy.');
}
$ilDB->manipulate("DELETE FROM tax_node_assignment WHERE ".
" component = ".$ilDB->quote($this->getComponentId(), "text").
" AND item_type = ".$ilDB->quote($this->getItemType(), "text").
" AND obj_id = ".$ilDB->quote($this->getObjectId(), "integer").
" AND item_id = ".$ilDB->quote($a_item_id, "integer").
" AND node_id = ".$ilDB->quote($a_node_id, "integer").
" AND tax_id = ".$ilDB->quote($this->getTaxonomyId(), "integer")
);
}

+ Here is the call graph for this function:

ilTaxNodeAssignment::deleteAssignmentsOfItem (   $a_item_id)

Delete assignments of item.

Parameters
int$a_item_iditem id

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

References getTaxonomyId().

Referenced by ilGlossaryTermGUI\updateTerm().

{
global $ilDB;
$ilDB->manipulate("DELETE FROM tax_node_assignment WHERE ".
" component = ".$ilDB->quote($this->getComponentId(), "text").
" AND item_type = ".$ilDB->quote($this->getItemType(), "text").
" AND obj_id = ".$ilDB->quote($this->getObjectId(), "integer").
" AND item_id = ".$ilDB->quote($a_item_id, "integer").
" AND tax_id = ".$ilDB->quote($this->getTaxonomyId(), "integer")
);
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

ilTaxNodeAssignment::deleteAssignmentsOfNode (   $a_node_id)

Delete assignments of node.

Parameters
int$a_node_idnode id

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

References getComponentId(), getItemType(), and getObjectId().

{
global $ilDB;
$ilDB->manipulate("DELETE FROM tax_node_assignment WHERE ".
" node_id = ".$ilDB->quote($a_node_id, "integer").
" AND component = ".$ilDB->quote($this->getComponentId(), "text").
" AND obj_id = ".$ilDB->quote($this->getObjectId(), "integer").
" AND item_type = ".$ilDB->quote($this->getItemType(), "text")
);
}

+ Here is the call graph for this function:

ilTaxNodeAssignment::fixOrderNr (   $a_node_id)

Fix Order Nr.

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

References getComponentId(), getItemType(), getObjectId(), and getTaxonomyId().

{
global $ilDB;
$set = $ilDB->query("SELECT * FROM tax_node_assignment ".
" WHERE component = ".$ilDB->quote($this->getComponentId(), "text").
" AND item_type = ".$ilDB->quote($this->getItemType(), "text").
" AND obj_id = ".$ilDB->quote($this->getObjectId(), "integer").
" AND node_id = ".$ilDB->quote($a_node_id, "integer").
" AND tax_id = ".$ilDB->quote($this->getTaxonomyId(), "integer").
" ORDER BY order_nr ASC"
);
$cnt = 10;
while ($rec = $ilDB->fetchAssoc($set))
{
$ilDB->manipulate("UPDATE tax_node_assignment SET ".
" order_nr = ".$ilDB->quote($cnt, "integer").
" WHERE component = ".$ilDB->quote($this->getComponentId(), "text").
" AND item_type = ".$ilDB->quote($this->getItemType(), "text").
" AND obj_id = ".$ilDB->quote($this->getObjectId(), "integer").
" AND node_id = ".$ilDB->quote($a_node_id, "integer").
" AND tax_id = ".$ilDB->quote($this->getTaxonomyId(), "integer").
" AND item_id = ".$ilDB->quote($rec["item_id"], "integer")
);
$cnt+= 10;
}
}

+ Here is the call graph for this function:

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.

References getObjectId(), and getTaxonomyId().

Referenced by ilGlossaryTermGUI\getEditTermForm(), and ilTestRandomQuestionSetSourcePoolTaxonomiesDuplicator\transferAssignmentsFromOriginalToDuplicatedTaxonomy().

{
global $ilDB;
$set = $ilDB->query("SELECT * FROM tax_node_assignment".
" WHERE component = ".$ilDB->quote($this->getComponentId(), "text").
" AND item_type = ".$ilDB->quote($this->getItemType(), "text").
" AND item_id = ".$ilDB->quote($a_item_id, "integer").
" AND obj_id = ".$ilDB->quote($this->getObjectId(), "integer").
" AND tax_id = ".$ilDB->quote($this->getTaxonomyId(), "integer")
);
$ass = array();
while ($rec = $ilDB->fetchAssoc($set))
{
$ass[] = $rec;
}
return $ass;
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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.

References getComponentId(), getItemType(), getObjectId(), and getTaxonomyId().

{
global $ilDB;
if (is_array($a_node_id))
{
$set = $ilDB->query("SELECT * FROM tax_node_assignment ".
" WHERE ".$ilDB->in("node_id", $a_node_id, false, "integer").
" AND tax_id = ".$ilDB->quote($this->getTaxonomyId(), "integer").
" AND component = ".$ilDB->quote($this->getComponentId(), "text").
" AND obj_id = ".$ilDB->quote($this->getObjectId(), "integer").
" AND item_type = ".$ilDB->quote($this->getItemType(), "text").
" ORDER BY order_nr ASC"
);
}
else
{
$set = $ilDB->query("SELECT * FROM tax_node_assignment ".
" WHERE node_id = ".$ilDB->quote($a_node_id, "integer").
" AND tax_id = ".$ilDB->quote($this->getTaxonomyId(), "integer").
" AND component = ".$ilDB->quote($this->getComponentId(), "text").
" AND obj_id = ".$ilDB->quote($this->getObjectId(), "integer").
" AND item_type = ".$ilDB->quote($this->getItemType(), "text").
" ORDER BY order_nr ASC"
);
}
$ass = array();
while ($rec = $ilDB->fetchAssoc($set))
{
$ass[] = $rec;
}
return $ass;
}

+ Here is the call graph for this function:

ilTaxNodeAssignment::getComponentId ( )

Get component id.

Returns
string component id

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

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

{
return $this->component_id;
}

+ Here is the caller graph for this function:

ilTaxNodeAssignment::getItemType ( )

Get item type.

Returns
string item type

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

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

{
return $this->item_type;
}

+ Here is the caller graph for this function:

ilTaxNodeAssignment::getMaxOrderNr (   $a_node_id)

Get maximum order number.

Parameters
@return

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

References getTaxonomyId().

Referenced by addAssignment().

{
global $ilDB;
$set = $ilDB->query("SELECT max(order_nr) mnr FROM tax_node_assignment ".
" WHERE component = ".$ilDB->quote($this->getComponentId(), "text").
" AND item_type = ".$ilDB->quote($this->getItemType(), "text").
" AND obj_id = ".$ilDB->quote($this->getObjectId(), "integer").
" AND node_id = ".$ilDB->quote($a_node_id, "integer").
" AND tax_id = ".$ilDB->quote($this->getTaxonomyId(), "integer")
);
$rec = $ilDB->fetchAssoc($set);
return (int) $rec["mnr"];
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

ilTaxNodeAssignment::getObjectId ( )

Get object id.

Returns
int object id

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

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

{
return $this->obj_id;
}

+ Here is the caller graph for this function:

ilTaxNodeAssignment::getTaxonomyId ( )

Get taxonomy id.

Returns
int taxonomy id

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

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

{
return $this->taxonomy_id;
}

+ Here is the caller graph for this function:

ilTaxNodeAssignment::setComponentId (   $a_val)
protected

Set component id.

Parameters
string$a_valcomponent id

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

Referenced by __construct().

{
$this->component_id = $a_val;
}

+ Here is the caller graph for this function:

ilTaxNodeAssignment::setItemType (   $a_val)
protected

Set item type.

Parameters
string$a_valitem type

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

Referenced by __construct().

{
$this->item_type = $a_val;
}

+ Here is the caller graph for this function:

ilTaxNodeAssignment::setObjectId (   $a_val)

Set object id.

Parameters
int$a_valobject id

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

Referenced by __construct().

{
$this->obj_id = $a_val;
}

+ Here is the caller graph for this function:

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.

References getComponentId(), getItemType(), getObjectId(), and getTaxonomyId().

{
global $ilDB;
$ilDB->manipulate("UPDATE tax_node_assignment SET ".
" order_nr = ".$ilDB->quote($a_order_nr, "integer").
" WHERE component = ".$ilDB->quote($this->getComponentId(), "text").
" AND item_type = ".$ilDB->quote($this->getItemType(), "text").
" AND obj_id = ".$ilDB->quote($this->getObjectId(), "integer").
" AND node_id = ".$ilDB->quote($a_node_id, "integer").
" AND item_id = ".$ilDB->quote($a_item_id, "integer").
" AND tax_id = ".$ilDB->quote($this->getTaxonomyId(), "integer")
);
}

+ Here is the call graph for this function:

ilTaxNodeAssignment::setTaxonomyId (   $a_val)
protected

Set taxonomy id.

Parameters
int$a_valtaxonomy id

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

Referenced by __construct().

{
$this->taxonomy_id = $a_val;
}

+ Here is the caller graph for this function:


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