ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
ilTree Class Reference

Tree class data representation in hierachical trees using the Nested Set Model with Gaps by Joe Celco. More...

+ Inheritance diagram for ilTree:
+ Collaboration diagram for ilTree:

Public Member Functions

 __construct ($a_tree_id, $a_root_id=0)
 Constructor @access public. More...
 
 initTreeImplementation ()
 Init tree implementation. More...
 
 getTreeImplementation ()
 Get tree implementation. More...
 
 useCache ($a_use=true)
 Use Cache (usually activated) More...
 
 isCacheUsed ()
 Check if cache is active. More...
 
 getDepthCache ()
 Get depth cache. More...
 
 getParentCache ()
 Get parent cache. More...
 
 initLangCode ()
 Store user language. More...
 
 getTreeTable ()
 Get tree table name. More...
 
 getObjectDataTable ()
 Get object data table. More...
 
 getTreePk ()
 Get tree primary key. More...
 
 getTableReference ()
 Get reference table if available. More...
 
 getGap ()
 Get default gap *. More...
 
 resetInTreeCache ()
 
 setTableNames ($a_table_tree, $a_table_obj_data, $a_table_obj_reference="")
 set table names The primary key of the table containing your object_data must be 'obj_id' You may use a reference table. More...
 
 setReferenceTablePK ($a_column_name)
 set column containing primary key in reference table @access public More...
 
 setObjectTablePK ($a_column_name)
 set column containing primary key in object table @access public More...
 
 setTreeTablePK ($a_column_name)
 set column containing primary key in tree table @access public More...
 
 buildJoin ()
 build join depending on table settings @access private More...
 
 getRelation ($a_node_a, $a_node_b)
 Get relation of two nodes. More...
 
 getRelationOfNodes ($a_node_a_arr, $a_node_b_arr)
 get relation of two nodes by node data More...
 
 getChildIds ($a_node)
 Get node child ids @global type $ilDB. More...
 
 getChilds ($a_node_id, $a_order="", $a_direction="ASC")
 get child nodes of given node @access public More...
 
 getFilteredChilds ($a_filter, $a_node, $a_order="", $a_direction="ASC")
 get child nodes of given node (exclude filtered obj_types) @access public More...
 
 getChildsByType ($a_node_id, $a_type)
 get child nodes of given node by object type @access public More...
 
 getChildsByTypeFilter ($a_node_id, $a_types, $a_order="", $a_direction="ASC")
 get child nodes of given node by object type @access public More...
 
 insertNodeFromTrash ($a_source_id, $a_target_id, $a_tree_id, $a_pos=IL_LAST_NODE, $a_reset_deleted_date=false)
 Insert node from trash deletes trash entry. More...
 
 insertNode ($a_node_id, $a_parent_id, $a_pos=IL_LAST_NODE, $a_reset_deletion_date=false)
 insert new node with node_id under parent node with parent_id @access public More...
 
 getFilteredSubTree ($a_node_id, $a_filter=array())
 get filtered subtree More...
 
 getSubTreeIds ($a_ref_id)
 Get all ids of subnodes. More...
 
 getSubTree ($a_node, $a_with_data=true, $a_type="")
 get all nodes in the subtree under specified node More...
 
 getSubTreeTypes ($a_node, $a_filter=0)
 get types of nodes in the subtree under specified node More...
 
 deleteTree ($a_node)
 delete node and the whole subtree under this node @access public More...
 
 validateParentRelations ()
 Validate parent relations of tree. More...
 
 getPathFull ($a_endnode_id, $a_startnode_id=0)
 get path from a given startnode to a given endnode if startnode is not given the rootnode is startnode. More...
 
 preloadDepthParent ($a_node_ids)
 Preload depth/parent. More...
 
 getPathId ($a_endnode_id, $a_startnode_id=0)
 get path from a given startnode to a given endnode if startnode is not given the rootnode is startnode @access public More...
 
 getNodePathForTitlePath ($titlePath, $a_startnode_id=null)
 Converts a path consisting of object titles into a path consisting of tree nodes. More...
 
 getNodePath ($a_endnode_id, $a_startnode_id=0)
 Returns the node path for the specified object reference. More...
 
 checkTree ()
 check consistence of tree all left & right values are checked if they are exists only once @access public More...
 
 checkTreeChilds ($a_no_zero_child=true)
 check, if all childs of tree nodes exist in object table More...
 
 getMaximumDepth ()
 Return the current maximum depth in the tree @access public. More...
 
 getDepth ($a_node_id)
 return depth of a node in tree @access private More...
 
 getNodeTreeData ($a_node_id)
 return all columns of tabel tree More...
 
 getNodeData ($a_node_id, $a_tree_pk=null)
 get all information of a node. More...
 
 fetchNodeData ($a_row)
 get data of parent node from tree and object_data @access private More...
 
 isInTree ($a_node_id)
 get all information of a node. More...
 
 getParentNodeData ($a_node_id)
 get data of parent node from tree and object_data @access public More...
 
 isGrandChild ($a_startnode_id, $a_querynode_id)
 checks if a node is in the path of an other node @access public More...
 
 addTree ($a_tree_id, $a_node_id=-1)
 create a new tree to do: ??? More...
 
 getNodeDataByType ($a_type)
 get nodes by type More...
 
 removeTree ($a_tree_id)
 remove an existing tree More...
 
 moveToTrash ($a_node_id, $a_set_deleted=false)
 Wrapper for saveSubTree. More...
 
 saveSubTree ($a_node_id, $a_set_deleted=false)
 Use the wrapper moveToTrash save subtree: delete a subtree (defined by node_id) to a new tree with $this->tree_id -node_id. More...
 
 isDeleted ($a_node_id)
 This is a wrapper for isSaved() with a more useful name. More...
 
 isSaved ($a_node_id)
 Use method isDeleted check if node is saved. More...
 
 preloadDeleted ($a_node_ids)
 Preload deleted information. More...
 
 getSavedNodeData ($a_parent_id)
 get data saved/deleted nodes More...
 
 getSavedNodeObjIds (array $a_obj_ids)
 get object id of saved/deleted nodes More...
 
 getParentId ($a_node_id)
 get parent id of given node @access public More...
 
 getLeftValue ($a_node_id)
 get left value of given node @access public More...
 
 getChildSequenceNumber ($a_node, $type="")
 get sequence number of node in sibling sequence @access public More...
 
 readRootId ()
 read root id from database More...
 
 getRootId ()
 get the root id of tree @access public More...
 
 setRootId ($a_root_id)
 
 getTreeId ()
 get tree id @access public More...
 
 setTreeId ($a_tree_id)
 set tree id @access public More...
 
 fetchSuccessorNode ($a_node_id, $a_type="")
 get node data of successor node More...
 
 fetchPredecessorNode ($a_node_id, $a_type="")
 get node data of predecessor node More...
 
 renumber ($node_id=1, $i=1)
 Wrapper for renumber. More...
 
 __renumber ($node_id=1, $i=1)
 This method is private. More...
 
 checkForParentType ($a_ref_id, $a_type, $a_exclude_source_check=false)
 Check for parent type e.g check if a folder (ref_id 3) is in a parent course obj => checkForParentType(3,'crs');. More...
 
 __isMainTree ()
 Check if operations are done on main tree. More...
 
 __checkDelete ($a_node)
 Check for deleteTree() compares a subtree of a given node by checking lft, rgt against parent relation. More...
 
 __getSubTreeByParentRelation ($a_node_id, &$parent_childs)
 @global type $ilDB More...
 
 __validateSubtrees (&$lft_childs, $parent_childs)
 
 moveTree ($a_source_id, $a_target_id, $a_location=self::POS_LAST_NODE)
 Move Tree Implementation. More...
 
 getRbacSubtreeInfo ($a_endnode_id)
 This method is used for change existing objects and returns all necessary information for this action. More...
 
 getSubTreeQuery ($a_node_id, $a_fields=array(), $a_types='', $a_force_join_reference=false)
 Get tree subtree query. More...
 
 getSubTreeFilteredByObjIds ($a_node_id, array $a_obj_ids, array $a_fields=array())
 get all node ids in the subtree under specified node id, filter by object ids More...
 
 deleteNode ($a_tree_id, $a_node_id)
 
 lookupTrashedObjectTypes ()
 Lookup object types in trash @global type $ilDB. More...
 

Static Public Member Functions

static _removeEntry ($a_tree, $a_child, $a_db_table="tree")
 STATIC METHOD Removes a single entry from a tree. More...
 

Data Fields

const POS_LAST_NODE = -2
 
const POS_FIRST_NODE = -1
 
const RELATION_CHILD = 1
 
const RELATION_PARENT = 2
 
const RELATION_SIBLING = 3
 
const RELATION_EQUALS = 4
 
const RELATION_NONE = 5
 
 $ilias
 
 $log
 
 $root_id
 
 $tree_id
 
 $table_tree
 
 $table_obj_data
 
 $table_obj_reference
 
 $ref_pk
 
 $obj_pk
 
 $tree_pk
 
 $gap
 

Protected Member Functions

 fetchTranslationFromObjectDataCache ($a_obj_ids)
 Get translation data from object cache (trigger in object cache on preload) More...
 

Protected Attributes

 $depth_cache = array()
 
 $parent_cache = array()
 
 $in_tree_cache = array()
 

Private Attributes

 $tree_impl = null
 

Detailed Description

Tree class data representation in hierachical trees using the Nested Set Model with Gaps by Joe Celco.

Author
Sascha Hofmann sasch.nosp@m.ahof.nosp@m.mann@.nosp@m.gmx..nosp@m.de
Stefan Meyer meyer.nosp@m.@lei.nosp@m.fos.c.nosp@m.om
Version
$Id$

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

Constructor & Destructor Documentation

◆ __construct()

ilTree::__construct (   $a_tree_id,
  $a_root_id = 0 
)

Constructor @access public.

Parameters
integer$a_tree_idtree_id
integer$a_root_idroot_id (optional)
Exceptions
InvalidArgumentException

Reimplemented in ilWorkspaceTree.

Definition at line 148 of file class.ilTree.php.

149 {
150 global $DIC;
151
152 $ilDB = $DIC['ilDB'];
153
154 // set db
155 $this->ilDB = $ilDB;
156
157 $this->lang_code = "en";
158
159 // CREATE LOGGER INSTANCE
160 $this->log = ilLoggerFactory::getLogger('tree');
161
162 if (!isset($a_tree_id) or (func_num_args() == 0)) {
163 $this->log->error("No tree_id given!");
164 $this->log->logStack(ilLogLevel::DEBUG);
165 throw new InvalidArgumentException("No tree_id given!");
166 }
167
168 if (func_num_args() > 2) {
169 $this->log->error("Wrong parameter count!");
170 throw new InvalidArgumentException("Wrong parameter count!");
171 }
172
173 //init variables
174 if (empty($a_root_id)) {
175 $a_root_id = ROOT_FOLDER_ID;
176 }
177
178 $this->tree_id = $a_tree_id;
179 $this->root_id = $a_root_id;
180 $this->table_tree = 'tree';
181 $this->table_obj_data = 'object_data';
182 $this->table_obj_reference = 'object_reference';
183 $this->ref_pk = 'ref_id';
184 $this->obj_pk = 'obj_id';
185 $this->tree_pk = 'tree';
186
187 $this->use_cache = true;
188
189 // If cache is activated, cache object translations to improve performance
190 $this->translation_cache = array();
191 $this->parent_type_cache = array();
192
193 // By default, we create gaps in the tree sequence numbering for 50 nodes
194 $this->gap = 50;
195
196
197 // init tree implementation
198 $this->initTreeImplementation();
199 }
static getLogger($a_component_id)
Get component logger.
initTreeImplementation()
Init tree implementation.
global $DIC
Definition: saml.php:7
global $ilDB

References $DIC, $ilDB, ilLogLevel\DEBUG, ilLoggerFactory\getLogger(), and initTreeImplementation().

+ Here is the call graph for this function:

Member Function Documentation

◆ __checkDelete()

ilTree::__checkDelete (   $a_node)

Check for deleteTree() compares a subtree of a given node by checking lft, rgt against parent relation.

@access private

Parameters
arraynode data from ilTree::getNodeData()
Returns
boolean
Exceptions
ilInvalidTreeStructureException
Deprecated:
since 4.4.0

Definition at line 2494 of file class.ilTree.php.

2495 {
2496 global $DIC;
2497
2498 $ilDB = $DIC['ilDB'];
2499
2500
2501 $query = $this->getTreeImplementation()->getSubTreeQuery($a_node, array(), false);
2502 $this->log->debug($query);
2503 $res = $ilDB->query($query);
2504
2505 $counter = (int) $lft_childs = array();
2506 while ($row = $ilDB->fetchObject($res)) {
2507 $lft_childs[$row->child] = $row->parent;
2508 ++$counter;
2509 }
2510
2511 // CHECK FOR DUPLICATE CHILD IDS
2512 if ($counter != count($lft_childs)) {
2513 $message = 'Duplicate entries for "child" in maintree! $a_node_id: ' . $a_node['child'];
2514
2515 $this->log->error($message);
2517 }
2518
2519 // GET SUBTREE BY PARENT RELATION
2520 $parent_childs = array();
2521 $this->__getSubTreeByParentRelation($a_node['child'], $parent_childs);
2522 $this->__validateSubtrees($lft_childs, $parent_childs);
2523
2524 return true;
2525 }
Thrown if invalid tree strucutes are found.
getTreeImplementation()
Get tree implementation.
__getSubTreeByParentRelation($a_node_id, &$parent_childs)
@global type $ilDB
__validateSubtrees(&$lft_childs, $parent_childs)
catch(Exception $e) $message
$row
$query
foreach($_POST as $key=> $value) $res

References $DIC, $ilDB, $message, $query, $res, $row, __getSubTreeByParentRelation(), __validateSubtrees(), and getTreeImplementation().

Referenced by deleteTree().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ __getSubTreeByParentRelation()

ilTree::__getSubTreeByParentRelation (   $a_node_id,
$parent_childs 
)

@global type $ilDB

Parameters
type$a_node_id
type$parent_childs
Returns
boolean
Exceptions
ilInvalidTreeStructureException
Deprecated:
since 4.4.0

Definition at line 2536 of file class.ilTree.php.

2537 {
2538 global $DIC;
2539
2540 $ilDB = $DIC['ilDB'];
2541
2542 // GET PARENT ID
2543 $query = 'SELECT * FROM ' . $this->table_tree . ' ' .
2544 'WHERE child = %s ' .
2545 'AND tree = %s ';
2546 $res = $ilDB->queryF($query, array('integer','integer'), array(
2547 $a_node_id,
2548 $this->tree_id));
2549
2550 $counter = 0;
2551 while ($row = $ilDB->fetchObject($res)) {
2552 $parent_childs[$a_node_id] = $row->parent;
2553 ++$counter;
2554 }
2555 // MULTIPLE ENTRIES
2556 if ($counter > 1) {
2557 $message = 'Multiple entries in maintree! $a_node_id: ' . $a_node_id;
2558
2559 $this->log->error($message);
2561 }
2562
2563 // GET ALL CHILDS
2564 $query = 'SELECT * FROM ' . $this->table_tree . ' ' .
2565 'WHERE parent = %s ';
2566 $res = $ilDB->queryF($query, array('integer'), array($a_node_id));
2567
2568 while ($row = $ilDB->fetchObject($res)) {
2569 // RECURSION
2570 $this->__getSubTreeByParentRelation($row->child, $parent_childs);
2571 }
2572 return true;
2573 }

References $DIC, $ilDB, $message, $query, $res, $row, and __getSubTreeByParentRelation().

Referenced by __checkDelete(), and __getSubTreeByParentRelation().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ __isMainTree()

ilTree::__isMainTree ( )

Check if operations are done on main tree.

@access private

Returns
boolean

Definition at line 2478 of file class.ilTree.php.

2479 {
2480 return $this->table_tree === 'tree';
2481 }

Referenced by addTree(), checkForParentType(), deleteTree(), getChilds(), getNodeData(), getPathFull(), getPathId(), getSubTree(), initTreeImplementation(), insertNode(), insertNodeFromTrash(), isCacheUsed(), isInTree(), isSaved(), moveTree(), preloadDeleted(), preloadDepthParent(), removeTree(), and renumber().

+ Here is the caller graph for this function:

◆ __renumber()

ilTree::__renumber (   $node_id = 1,
  $i = 1 
)

This method is private.

Always call ilTree->renumber() since it locks the tree table renumber left/right values and close the gaps in numbers (recursive) @access private

Parameters
integernode_id where to start (usually the root node)
integerfirst left value of start node (usually 1)
Returns
integer current left value of recursive call

Definition at line 2345 of file class.ilTree.php.

2346 {
2347 global $DIC;
2348
2349 $ilDB = $DIC['ilDB'];
2350
2351 $query = 'UPDATE ' . $this->table_tree . ' SET lft = %s WHERE child = %s AND tree = %s';
2352 $res = $ilDB->manipulateF($query, array('integer','integer','integer'), array(
2353 $i,
2354 $node_id,
2355 $this->tree_id));
2356
2357 // to much dependencies
2358 //$childs = $this->getChilds($node_id);
2359 $childs = $this->getChildIds($node_id);
2360
2361 foreach ($childs as $child) {
2362 $i = $this->__renumber($child, $i + 1);
2363 }
2364 $i++;
2365
2366 // Insert a gap at the end of node, if the node has children
2367 if (count($childs) > 0) {
2368 $i += $this->gap * 2;
2369 }
2370
2371
2372 $query = 'UPDATE ' . $this->table_tree . ' SET rgt = %s WHERE child = %s AND tree = %s';
2373 $res = $ilDB->manipulateF($query, array('integer','integer', 'integer'), array(
2374 $i,
2375 $node_id,
2376 $this->tree_id));
2377 return $i;
2378 }
getChildIds($a_node)
Get node child ids @global type $ilDB.
__renumber($node_id=1, $i=1)
This method is private.
$i
Definition: disco.tpl.php:19

References $DIC, $i, $ilDB, $query, $res, __renumber(), and getChildIds().

Referenced by __renumber(), and renumber().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ __validateSubtrees()

ilTree::__validateSubtrees ( $lft_childs,
  $parent_childs 
)
Parameters
$lft_childs
$parent_childs
Returns
bool
Exceptions
ilInvalidTreeStructureException
Deprecated:
since 4.4.0

Definition at line 2582 of file class.ilTree.php.

2583 {
2584 // SORT BY KEY
2585 ksort($lft_childs);
2586 ksort($parent_childs);
2587
2588 $this->log->debug('left childs ' . print_r($lft_childs, true));
2589 $this->log->debug('parent childs ' . print_r($parent_childs, true));
2590
2591 if (count($lft_childs) != count($parent_childs)) {
2592 $message = '(COUNT) Tree is corrupted! Left/Right subtree does not comply with parent relation';
2593 $this->log->error($message);
2595 }
2596
2597
2598 foreach ($lft_childs as $key => $value) {
2599 if ($parent_childs[$key] != $value) {
2600 $message = '(COMPARE) Tree is corrupted! Left/Right subtree does not comply with parent relation';
2601 $this->log->error($message);
2603 }
2604 if ($key == ROOT_FOLDER_ID) {
2605 $message = '(ROOT_FOLDER) Tree is corrupted! Tried to delete root folder';
2606 $this->log->error($message);
2608 }
2609 }
2610 return true;
2611 }
$key
Definition: croninfo.php:18

References $key, and $message.

Referenced by __checkDelete().

+ Here is the caller graph for this function:

◆ _removeEntry()

static ilTree::_removeEntry (   $a_tree,
  $a_child,
  $a_db_table = "tree" 
)
static

STATIC METHOD Removes a single entry from a tree.

The tree structure is NOT updated!

@access public

Parameters
integertree id
integerchild id
stringdb_table name. default is 'tree' (optional)
Exceptions
InvalidArgumentException

Definition at line 2446 of file class.ilTree.php.

2447 {
2448 global $DIC;
2449
2450 $ilDB = $DIC['ilDB'];
2451
2452 if ($a_db_table === 'tree') {
2453 if ($a_tree == 1 and $a_child == ROOT_FOLDER_ID) {
2454 $message = sprintf(
2455 'Tried to delete root node! $a_tree: %s $a_child: %s',
2456 $a_tree,
2457 $a_child
2458 );
2459 ilLoggerFactory::getLogger('tree')->error($message);
2460 throw new InvalidArgumentException($message);
2461 }
2462 }
2463
2464 $query = 'DELETE FROM ' . $a_db_table . ' ' .
2465 'WHERE tree = %s ' .
2466 'AND child = %s ';
2467 $res = $ilDB->manipulateF($query, array('integer','integer'), array(
2468 $a_tree,
2469 $a_child));
2470 }

References $DIC, $ilDB, $message, $query, $res, and ilLoggerFactory\getLogger().

Referenced by ilValidator\purgeObjects(), and ilSystemCheckTrash\removeSelectedFromSystem().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ addTree()

ilTree::addTree (   $a_tree_id,
  $a_node_id = -1 
)

create a new tree to do: ???

Parameters
integera_tree_id: obj_id of object where tree belongs to
integera_node_id: root node of tree (optional; default is tree_id itself)
Returns
boolean true on success
Exceptions
InvalidArgumentException@access public

Definition at line 1717 of file class.ilTree.php.

1718 {
1719 global $DIC;
1720
1721 $ilDB = $DIC['ilDB'];
1722
1723 // FOR SECURITY addTree() IS NOT ALLOWED ON MAIN TREE
1724 if ($this->__isMainTree()) {
1725 $message = sprintf(
1726 'Operation not allowed on main tree! $a_tree_if: %s $a_node_id: %s',
1727 $a_tree_id,
1728 $a_node_id
1729 );
1730 $this->log->error($message);
1731 throw new InvalidArgumentException($message);
1732 }
1733
1734 if (!isset($a_tree_id)) {
1735 $message = "No tree_id given!";
1736 $this->log->error($message);
1737 throw new InvalidArgumentException($message);
1738 }
1739
1740 if ($a_node_id <= 0) {
1741 $a_node_id = $a_tree_id;
1742 }
1743
1744 $query = 'INSERT INTO ' . $this->table_tree . ' (' .
1745 $this->tree_pk . ', child,parent,lft,rgt,depth) ' .
1746 'VALUES ' .
1747 '(%s,%s,%s,%s,%s,%s)';
1748 $res = $ilDB->manipulateF($query, array('integer','integer','integer','integer','integer','integer'), array(
1749 $a_tree_id,
1750 $a_node_id,
1751 0,
1752 1,
1753 2,
1754 1));
1755
1756 return true;
1757 }
__isMainTree()
Check if operations are done on main tree.

References $DIC, $ilDB, $message, $query, $res, and __isMainTree().

Referenced by ilWorkspaceExplorer\__construct(), and ilWorkspaceTree\createTreeForUser().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ buildJoin()

ilTree::buildJoin ( )

build join depending on table settings @access private

Returns
string

Definition at line 441 of file class.ilTree.php.

442 {
443 if ($this->table_obj_reference) {
444 // Use inner join instead of left join to improve performance
445 return "JOIN " . $this->table_obj_reference . " ON " . $this->table_tree . ".child=" . $this->table_obj_reference . "." . $this->ref_pk . " " .
446 "JOIN " . $this->table_obj_data . " ON " . $this->table_obj_reference . "." . $this->obj_pk . "=" . $this->table_obj_data . "." . $this->obj_pk . " ";
447 } else {
448 // Use inner join instead of left join to improve performance
449 return "JOIN " . $this->table_obj_data . " ON " . $this->table_tree . ".child=" . $this->table_obj_data . "." . $this->obj_pk . " ";
450 }
451 }

Referenced by fetchPredecessorNode(), fetchSuccessorNode(), ilSCORMTree\getChilds(), getChilds(), getChildsByType(), getChildsByTypeFilter(), getChildSequenceNumber(), getNodeData(), getNodeDataByType(), getPathFull(), getSavedNodeData(), getSavedNodeObjIds(), and getSubTreeFilteredByObjIds().

+ Here is the caller graph for this function:

◆ checkForParentType()

ilTree::checkForParentType (   $a_ref_id,
  $a_type,
  $a_exclude_source_check = false 
)

Check for parent type e.g check if a folder (ref_id 3) is in a parent course obj => checkForParentType(3,'crs');.

@access public

Parameters
integerref_id
stringtype
Returns
mixed false if item is not in tree, int (object ref_id) > 0 if path container course, int 0 if pathc does not contain the object type

Definition at line 2391 of file class.ilTree.php.

2392 {
2393 // #12577
2394 $cache_key = $a_ref_id . '.' . $a_type . '.' . ((int) $a_exclude_source_check);
2395
2396 // Try to return a cached result
2397 if ($this->isCacheUsed() &&
2398 array_key_exists($cache_key, $this->parent_type_cache)) {
2399 return $this->parent_type_cache[$cache_key];
2400 }
2401
2402 // Store up to 1000 results in cache
2403 $do_cache = ($this->__isMainTree() && count($this->parent_type_cache) < 1000);
2404
2405 // ref_id is not in tree
2406 if (!$this->isInTree($a_ref_id)) {
2407 if ($do_cache) {
2408 $this->parent_type_cache[$cache_key] = false;
2409 }
2410 return false;
2411 }
2412
2413 $path = array_reverse($this->getPathFull($a_ref_id));
2414
2415 // remove first path entry as it is requested node
2416 if ($a_exclude_source_check) {
2417 array_shift($path);
2418 }
2419
2420 foreach ($path as $node) {
2421 // found matching parent
2422 if ($node["type"] == $a_type) {
2423 if ($do_cache) {
2424 $this->parent_type_cache[$cache_key] = $node["child"];
2425 }
2426 return $node["child"];
2427 }
2428 }
2429
2430 if ($do_cache) {
2431 $this->parent_type_cache[$cache_key] = false;
2432 }
2433 return 0;
2434 }
$path
Definition: aliased.php:25
isCacheUsed()
Check if cache is active.
isInTree($a_node_id)
get all information of a node.
getPathFull($a_endnode_id, $a_startnode_id=0)
get path from a given startnode to a given endnode if startnode is not given the rootnode is startnod...
$a_type
Definition: workflow.php:92

References $a_type, $path, __isMainTree(), getPathFull(), isCacheUsed(), and isInTree().

+ Here is the call graph for this function:

◆ checkTree()

ilTree::checkTree ( )

check consistence of tree all left & right values are checked if they are exists only once @access public

Returns
boolean true if tree is ok; otherwise throws error object
Exceptions
ilInvalidTreeStructureException

Definition at line 1268 of file class.ilTree.php.

1269 {
1270 global $DIC;
1271
1272 $ilDB = $DIC['ilDB'];
1273
1274 $types = array('integer');
1275 $query = 'SELECT lft,rgt FROM ' . $this->table_tree . ' ' .
1276 'WHERE ' . $this->tree_pk . ' = %s ';
1277
1278 $res = $ilDB->queryF($query, $types, array($this->tree_id));
1279 while ($row = $ilDB->fetchObject($res)) {
1280 $lft[] = $row->lft;
1281 $rgt[] = $row->rgt;
1282 }
1283
1284 $all = array_merge($lft, $rgt);
1285 $uni = array_unique($all);
1286
1287 if (count($all) != count($uni)) {
1288 $message = 'Tree is corrupted!';
1289
1290 $this->log->error($message);
1292 }
1293
1294 return true;
1295 }

References $DIC, $ilDB, $message, $query, $res, and $row.

◆ checkTreeChilds()

ilTree::checkTreeChilds (   $a_no_zero_child = true)

check, if all childs of tree nodes exist in object table

Parameters
bool$a_no_zero_child
Returns
bool
Exceptions
ilInvalidTreeStructureException

Definition at line 1304 of file class.ilTree.php.

1305 {
1306 global $DIC;
1307
1308 $ilDB = $DIC['ilDB'];
1309
1310 $query = 'SELECT * FROM ' . $this->table_tree . ' ' .
1311 'WHERE ' . $this->tree_pk . ' = %s ' .
1312 'ORDER BY lft';
1313 $r1 = $ilDB->queryF($query, array('integer'), array($this->tree_id));
1314
1315 while ($row = $ilDB->fetchAssoc($r1)) {
1316 //echo "tree:".$row[$this->tree_pk].":lft:".$row["lft"].":rgt:".$row["rgt"].":child:".$row["child"].":<br>";
1317 if (($row["child"] == 0) && $a_no_zero_child) {
1318 $message = "Tree contains child with ID 0!";
1319 $this->log->error($message);
1321 }
1322
1323 if ($this->table_obj_reference) {
1324 // get object reference data
1325 $query = 'SELECT * FROM ' . $this->table_obj_reference . ' WHERE ' . $this->ref_pk . ' = %s ';
1326 $r2 = $ilDB->queryF($query, array('integer'), array($row['child']));
1327
1328 //echo "num_childs:".$r2->numRows().":<br>";
1329 if ($r2->numRows() == 0) {
1330 $message = "No Object-to-Reference entry found for ID " . $row["child"] . "!";
1331 $this->log->error($message);
1333 }
1334 if ($r2->numRows() > 1) {
1335 $message = "More Object-to-Reference entries found for ID " . $row["child"] . "!";
1336 $this->log->error($message);
1338 }
1339
1340 // get object data
1341 $obj_ref = $ilDB->fetchAssoc($r2);
1342
1343 $query = 'SELECT * FROM ' . $this->table_obj_data . ' WHERE ' . $this->obj_pk . ' = %s';
1344 $r3 = $ilDB->queryF($query, array('integer'), array($obj_ref[$this->obj_pk]));
1345 if ($r3->numRows() == 0) {
1346 $message = " No child found for ID " . $obj_ref[$this->obj_pk] . "!";
1347 $this->log->error($message);
1349 }
1350 if ($r3->numRows() > 1) {
1351 $message = "More childs found for ID " . $obj_ref[$this->obj_pk] . "!";
1352 $this->log->error($message);
1354 }
1355 } else {
1356 // get only object data
1357 $query = 'SELECT * FROM ' . $this->table_obj_data . ' WHERE ' . $this->obj_pk . ' = %s';
1358 $r2 = $ilDB->queryF($query, array('integer'), array($row['child']));
1359 //echo "num_childs:".$r2->numRows().":<br>";
1360 if ($r2->numRows() == 0) {
1361 $message = "No child found for ID " . $row["child"] . "!";
1362 $this->log->error($message);
1364 }
1365 if ($r2->numRows() > 1) {
1366 $message = "More childs found for ID " . $row["child"] . "!";
1367 $this->log->error($message);
1369 }
1370 }
1371 }
1372
1373 return true;
1374 }

References $DIC, $ilDB, $message, $obj_pk, $query, and $row.

◆ deleteNode()

ilTree::deleteNode (   $a_tree_id,
  $a_node_id 
)

Definition at line 2716 of file class.ilTree.php.

2717 {
2718 global $DIC;
2719
2720 $ilDB = $DIC['ilDB'];
2721 $ilAppEventHandler = $DIC['ilAppEventHandler'];
2722
2723 $query = 'DELETE FROM tree where ' .
2724 'child = ' . $ilDB->quote($a_node_id, 'integer') . ' ' .
2725 'AND tree = ' . $ilDB->quote($a_tree_id, 'integer');
2726 $ilDB->manipulate($query);
2727
2728 $ilAppEventHandler->raise(
2729 "Services/Tree",
2730 "deleteNode",
2731 array('tree' => $this->table_tree,
2732 'node_id' => $a_node_id,
2733 'tree_id' => $a_tree_id
2734 )
2735 );
2736 }

References $DIC, $ilDB, and $query.

◆ deleteTree()

ilTree::deleteTree (   $a_node)

delete node and the whole subtree under this node @access public

Parameters
arraynode_data of a node
Exceptions
InvalidArgumentException
ilInvalidTreeStructureException

Definition at line 941 of file class.ilTree.php.

942 {
943 global $DIC;
944
945 $ilDB = $DIC['ilDB'];
946
947 $this->log->debug('Delete tree with node ' . $a_node);
948
949 if (!is_array($a_node)) {
950 $this->log->logStack(ilLogLevel::ERROR);
951 throw new InvalidArgumentException(__METHOD__ . ': Wrong datatype for node data!');
952 }
953
954 $this->log->debug($this->tree_pk);
955
956 if ($this->__isMainTree()) {
957 // @todo normally this part is not executed, since the subtree is first
958 // moved to trash and then deleted.
959 if (!$this->__checkDelete($a_node)) {
960 $this->log->logStack(ilLogLevel::ERROR);
961 throw new ilInvalidTreeStructureException('Deletion canceled due to invalid tree structure.' . print_r($a_node, true));
962 }
963 }
964
965 $this->getTreeImplementation()->deleteTree($a_node['child']);
966
967 $this->resetInTreeCache();
968 }
__checkDelete($a_node)
Check for deleteTree() compares a subtree of a given node by checking lft, rgt against parent relatio...
resetInTreeCache()

References $DIC, $ilDB, __checkDelete(), __isMainTree(), ilLogLevel\ERROR, getTreeImplementation(), and resetInTreeCache().

Referenced by ilWorkspaceTree\cascadingDelete().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ fetchNodeData()

ilTree::fetchNodeData (   $a_row)

get data of parent node from tree and object_data @access private

Parameters
objectdb db result object containing node_data
Returns
array 2-dim (int/str) node_data TODO: select description twice for compability. Please use 'desc' in future only

Definition at line 1499 of file class.ilTree.php.

1500 {
1501 global $DIC;
1502
1503 $objDefinition = $DIC['objDefinition'];
1504 $lng = $DIC['lng'];
1505 $ilBench = $DIC['ilBench'];
1506 $ilDB = $DIC['ilDB'];
1507
1508 //$ilBench->start("Tree", "fetchNodeData_getRow");
1509 $data = $a_row;
1510 $data["desc"] = $a_row["description"]; // for compability
1511 //$ilBench->stop("Tree", "fetchNodeData_getRow");
1512
1513 // multilingual support systemobjects (sys) & categories (db)
1514 //$ilBench->start("Tree", "fetchNodeData_readDefinition");
1515 if (is_object($objDefinition)) {
1516 $translation_type = $objDefinition->getTranslationType($data["type"]);
1517 }
1518 //$ilBench->stop("Tree", "fetchNodeData_readDefinition");
1519
1520 if ($translation_type == "sys") {
1521 //$ilBench->start("Tree", "fetchNodeData_getLangData");
1522 if ($data["type"] == "rolf" and $data["obj_id"] != ROLE_FOLDER_ID) {
1523 $data["description"] = $lng->txt("obj_" . $data["type"] . "_local_desc") . $data["title"] . $data["desc"];
1524 $data["desc"] = $lng->txt("obj_" . $data["type"] . "_local_desc") . $data["title"] . $data["desc"];
1525 $data["title"] = $lng->txt("obj_" . $data["type"] . "_local");
1526 } else {
1527 $data["title"] = $lng->txt("obj_" . $data["type"]);
1528 $data["description"] = $lng->txt("obj_" . $data["type"] . "_desc");
1529 $data["desc"] = $lng->txt("obj_" . $data["type"] . "_desc");
1530 }
1531 //$ilBench->stop("Tree", "fetchNodeData_getLangData");
1532 } elseif ($translation_type == "db") {
1533
1534 // Try to retrieve object translation from cache
1535 if ($this->isCacheUsed() &&
1536 array_key_exists($data["obj_id"] . '.' . $lang_code, $this->translation_cache)) {
1537 $key = $data["obj_id"] . '.' . $lang_code;
1538 $data["title"] = $this->translation_cache[$key]['title'];
1539 $data["description"] = $this->translation_cache[$key]['description'];
1540 $data["desc"] = $this->translation_cache[$key]['desc'];
1541 } else {
1542 // Object translation is not in cache, read it from database
1543 //$ilBench->start("Tree", "fetchNodeData_getTranslation");
1544 $query = 'SELECT title,description FROM object_translation ' .
1545 'WHERE obj_id = %s ' .
1546 'AND lang_code = %s ' .
1547 'AND NOT lang_default = %s';
1548
1549 $res = $ilDB->queryF($query, array('integer','text','integer'), array(
1550 $data['obj_id'],
1551 $this->lang_code,
1552 1));
1553 $row = $ilDB->fetchObject($res);
1554
1555 if ($row) {
1556 $data["title"] = $row->title;
1557 $data["description"] = ilUtil::shortenText($row->description, ilObject::DESC_LENGTH, true);
1558 $data["desc"] = $row->description;
1559 }
1560 //$ilBench->stop("Tree", "fetchNodeData_getTranslation");
1561
1562 // Store up to 1000 object translations in cache
1563 if ($this->isCacheUsed() && count($this->translation_cache) < 1000) {
1564 $key = $data["obj_id"] . '.' . $lang_code;
1565 $this->translation_cache[$key] = array();
1566 $this->translation_cache[$key]['title'] = $data["title"] ;
1567 $this->translation_cache[$key]['description'] = $data["description"];
1568 $this->translation_cache[$key]['desc'] = $data["desc"];
1569 }
1570 }
1571 }
1572
1573 // TODO: Handle this switch by module.xml definitions
1574 if ($data['type'] == 'crsr' or $data['type'] == 'catr' or $data['type'] == 'grpr') {
1575 include_once('./Services/ContainerReference/classes/class.ilContainerReference.php');
1576 $data['title'] = ilContainerReference::_lookupTitle($data['obj_id']);
1577 }
1578
1579 return $data ? $data : array();
1580 }
static _lookupTitle($a_obj_id)
Overwitten from base class.
const DESC_LENGTH
static shortenText( $a_str, $a_len, $a_dots=false, $a_next_blank=false, $a_keep_extension=false)
shorten a string to given length.
global $ilBench
Definition: ilias.php:18
$lng
$data
Definition: bench.php:6

References $data, $DIC, $ilBench, $ilDB, $key, $lng, $query, $res, $row, ilContainerReference\_lookupTitle(), ilObject\DESC_LENGTH, isCacheUsed(), and ilUtil\shortenText().

Referenced by fetchPredecessorNode(), fetchSuccessorNode(), ilSCORMTree\getChilds(), getChilds(), getChildsByType(), getChildsByTypeFilter(), getNodeData(), getNodeDataByType(), getParentNodeData(), getPathFull(), getSavedNodeData(), and getSubTree().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ fetchPredecessorNode()

ilTree::fetchPredecessorNode (   $a_node_id,
  $a_type = "" 
)

get node data of predecessor node

@access public

Parameters
integernode id
Returns
array node data array
Exceptions
InvalidArgumentException

Definition at line 2250 of file class.ilTree.php.

2251 {
2252 global $DIC;
2253
2254 $ilDB = $DIC['ilDB'];
2255
2256 if (!isset($a_node_id)) {
2257 $message = "No node_id given!";
2258 $this->log->error($message);
2259 throw new InvalidArgumentException($message);
2260 }
2261
2262 // get lft value for current node
2263 $query = 'SELECT lft FROM ' . $this->table_tree . ' ' .
2264 'WHERE ' . $this->table_tree . '.child = %s ' .
2265 'AND ' . $this->table_tree . '.' . $this->tree_pk . ' = %s ';
2266 $res = $ilDB->queryF($query, array('integer','integer'), array(
2267 $a_node_id,
2268 $this->tree_id));
2269
2270 $curr_node = $ilDB->fetchAssoc($res);
2271
2272 if ($a_type) {
2273 $query = 'SELECT * FROM ' . $this->table_tree . ' ' .
2274 $this->buildJoin() .
2275 'WHERE lft < %s ' .
2276 'AND ' . $this->table_obj_data . '.type = %s ' .
2277 'AND ' . $this->table_tree . '.' . $this->tree_pk . ' = %s ' .
2278 'ORDER BY lft DESC';
2279 $ilDB->setLimit(1);
2280 $res = $ilDB->queryF($query, array('integer','text','integer'), array(
2281 $curr_node['lft'],
2282 $a_type,
2283 $this->tree_id));
2284 } else {
2285 $query = 'SELECT * FROM ' . $this->table_tree . ' ' .
2286 $this->buildJoin() .
2287 'WHERE lft < %s ' .
2288 'AND ' . $this->table_tree . '.' . $this->tree_pk . ' = %s ' .
2289 'ORDER BY lft DESC';
2290 $ilDB->setLimit(1);
2291 $res = $ilDB->queryF($query, array('integer','integer'), array(
2292 $curr_node['lft'],
2293 $this->tree_id));
2294 }
2295
2296 if ($res->numRows() < 1) {
2297 return false;
2298 } else {
2299 $row = $ilDB->fetchAssoc($res);
2300 return $this->fetchNodeData($row);
2301 }
2302 }
fetchNodeData($a_row)
get data of parent node from tree and object_data @access private
buildJoin()
build join depending on table settings @access private

References $a_type, $DIC, $ilDB, $message, $query, $res, $row, buildJoin(), and fetchNodeData().

+ Here is the call graph for this function:

◆ fetchSuccessorNode()

ilTree::fetchSuccessorNode (   $a_node_id,
  $a_type = "" 
)

get node data of successor node

@access public

Parameters
integernode id
Returns
array node data array
Exceptions
InvalidArgumentException

Definition at line 2189 of file class.ilTree.php.

2190 {
2191 global $DIC;
2192
2193 $ilDB = $DIC['ilDB'];
2194
2195 if (!isset($a_node_id)) {
2196 $message = "No node_id given!";
2197 $this->log->error($message);
2198 throw new InvalidArgumentException($message);
2199 }
2200
2201 // get lft value for current node
2202 $query = 'SELECT lft FROM ' . $this->table_tree . ' ' .
2203 'WHERE ' . $this->table_tree . '.child = %s ' .
2204 'AND ' . $this->table_tree . '.' . $this->tree_pk . ' = %s ';
2205 $res = $ilDB->queryF($query, array('integer','integer'), array(
2206 $a_node_id,
2207 $this->tree_id));
2208 $curr_node = $ilDB->fetchAssoc($res);
2209
2210 if ($a_type) {
2211 $query = 'SELECT * FROM ' . $this->table_tree . ' ' .
2212 $this->buildJoin() .
2213 'WHERE lft > %s ' .
2214 'AND ' . $this->table_obj_data . '.type = %s ' .
2215 'AND ' . $this->table_tree . '.' . $this->tree_pk . ' = %s ' .
2216 'ORDER BY lft ';
2217 $ilDB->setLimit(1);
2218 $res = $ilDB->queryF($query, array('integer','text','integer'), array(
2219 $curr_node['lft'],
2220 $a_type,
2221 $this->tree_id));
2222 } else {
2223 $query = 'SELECT * FROM ' . $this->table_tree . ' ' .
2224 $this->buildJoin() .
2225 'WHERE lft > %s ' .
2226 'AND ' . $this->table_tree . '.' . $this->tree_pk . ' = %s ' .
2227 'ORDER BY lft ';
2228 $ilDB->setLimit(1);
2229 $res = $ilDB->queryF($query, array('integer','integer'), array(
2230 $curr_node['lft'],
2231 $this->tree_id));
2232 }
2233
2234 if ($res->numRows() < 1) {
2235 return false;
2236 } else {
2237 $row = $ilDB->fetchAssoc($res);
2238 return $this->fetchNodeData($row);
2239 }
2240 }

References $a_type, $DIC, $ilDB, $message, $query, $res, $row, buildJoin(), and fetchNodeData().

+ Here is the call graph for this function:

◆ fetchTranslationFromObjectDataCache()

ilTree::fetchTranslationFromObjectDataCache (   $a_obj_ids)
protected

Get translation data from object cache (trigger in object cache on preload)

Parameters
array$a_obj_idsobject ids

Definition at line 1587 of file class.ilTree.php.

1588 {
1589 global $DIC;
1590
1591 $ilObjDataCache = $DIC['ilObjDataCache'];
1592
1593 if ($this->isCacheUsed() && is_array($a_obj_ids) && is_object($ilObjDataCache)) {
1594 foreach ($a_obj_ids as $id) {
1595 $this->translation_cache[$id . '.']['title'] = $ilObjDataCache->lookupTitle($id);
1596 $this->translation_cache[$id . '.']['description'] = $ilObjDataCache->lookupDescription($id);
1597 ;
1598 $this->translation_cache[$id . '.']['desc'] =
1599 $this->translation_cache[$id . '.']['description'];
1600 }
1601 }
1602 }
if(!array_key_exists('StateId', $_REQUEST)) $id

References $DIC, $id, and isCacheUsed().

Referenced by getChilds().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getChildIds()

ilTree::getChildIds (   $a_node)

Get node child ids @global type $ilDB.

Parameters
type$a_node
Returns
type

Definition at line 483 of file class.ilTree.php.

484 {
485 global $DIC;
486
487 $ilDB = $DIC['ilDB'];
488
489 $query = 'SELECT * FROM ' . $this->table_tree . ' ' .
490 'WHERE parent = ' . $ilDB->quote($a_node, 'integer') . ' ' .
491 'AND tree = ' . $ilDB->quote($this->tree_id, 'integer' . ' ' .
492 'ORDER BY lft');
493 $res = $ilDB->query($query);
494
495 $childs = array();
496 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
497 $childs[] = $row->child;
498 }
499 return $childs;
500 }

References $DIC, $ilDB, $query, $res, $row, and ilDBConstants\FETCHMODE_OBJECT.

Referenced by __renumber().

+ Here is the caller graph for this function:

◆ getChilds()

ilTree::getChilds (   $a_node_id,
  $a_order = "",
  $a_direction = "ASC" 
)

get child nodes of given node @access public

Parameters
integernode_id
stringsort order of returned childs, optional (possible values: 'title','desc','last_update' or 'type')
stringsort direction, optional (possible values: 'DESC' or 'ASC'; defalut is 'ASC')
Returns
array with node data of all childs or empty array
Exceptions
InvalidArgumentException

Reimplemented in ilSCORMTree.

Definition at line 511 of file class.ilTree.php.

512 {
513 global $DIC;
514
515 $ilBench = $DIC['ilBench'];
516 $ilDB = $DIC['ilDB'];
517 $ilObjDataCache = $DIC['ilObjDataCache'];
518 $ilUser = $DIC['ilUser'];
519
520 if (!isset($a_node_id)) {
521 $message = "No node_id given!";
522 $this->log->error($message);
523 throw new InvalidArgumentException($message);
524 }
525
526 // init childs
527 $childs = array();
528
529 // number of childs
530 $count = 0;
531
532 // init order_clause
533 $order_clause = "";
534
535 // set order_clause if sort order parameter is given
536 if (!empty($a_order)) {
537 $order_clause = "ORDER BY " . $a_order . " " . $a_direction;
538 } else {
539 $order_clause = "ORDER BY " . $this->table_tree . ".lft";
540 }
541
542
543 $query = sprintf(
544 'SELECT * FROM ' . $this->table_tree . ' ' .
545 $this->buildJoin() .
546 "WHERE parent = %s " .
547 "AND " . $this->table_tree . "." . $this->tree_pk . " = %s " .
548 $order_clause,
549 $ilDB->quote($a_node_id, 'integer'),
550 $ilDB->quote($this->tree_id, 'integer')
551 );
552
553 $res = $ilDB->query($query);
554
555 if (!$count = $res->numRows()) {
556 return array();
557 }
558
559 // get rows and object ids
560 $rows = array();
561 while ($r = $ilDB->fetchAssoc($res)) {
562 $rows[] = $r;
563 $obj_ids[] = $r["obj_id"];
564 }
565
566 // preload object translation information
567 if ($this->__isMainTree() && $this->isCacheUsed() && is_object($ilObjDataCache) &&
568 is_object($ilUser) && $this->lang_code == $ilUser->getLanguage() && !$this->oc_preloaded[$a_node_id]) {
569 // $ilObjDataCache->preloadTranslations($obj_ids, $this->lang_code);
570 $ilObjDataCache->preloadObjectCache($obj_ids, $this->lang_code);
572 $this->oc_preloaded[$a_node_id] = true;
573 }
574
575 foreach ($rows as $row) {
576 $childs[] = $this->fetchNodeData($row);
577
578 // Update cache of main tree
579 if ($this->__isMainTree()) {
580 #$GLOBALS['DIC']['ilLog']->write(__METHOD__.': Storing in tree cache '.$row['child'].' = true');
581 $this->in_tree_cache[$row['child']] = $row['tree'] == 1;
582 }
583 }
584 $childs[$count - 1]["last"] = true;
585 return $childs;
586 }
fetchTranslationFromObjectDataCache($a_obj_ids)
Get translation data from object cache (trigger in object cache on preload)
$r
Definition: example_031.php:79
$ilUser
Definition: imgupload.php:18
$rows
Definition: xhr_table.php:10

References $DIC, $ilBench, $ilDB, $ilUser, $message, $query, $r, $res, $row, $rows, __isMainTree(), buildJoin(), fetchNodeData(), fetchTranslationFromObjectDataCache(), and isCacheUsed().

Referenced by getFilteredChilds(), and ilSkillTree\getMaxOrderNr().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getChildsByType()

ilTree::getChildsByType (   $a_node_id,
  $a_type 
)

get child nodes of given node by object type @access public

Parameters
integernode_id
stringobject type
Returns
array with node data of all childs or empty array
Exceptions
InvalidArgumentException

Definition at line 618 of file class.ilTree.php.

619 {
620 global $DIC;
621
622 $ilDB = $DIC['ilDB'];
623
624 if (!isset($a_node_id) or !isset($a_type)) {
625 $message = "Missing parameter! node_id:" . $a_node_id . " type:" . $a_type;
626 $this->log->error($message);
627 throw new InvalidArgumentException($message);
628 }
629
630 if ($a_type == 'rolf' && $this->table_obj_reference) {
631 // Performance optimization: A node can only have exactly one
632 // role folder as its child. Therefore we don't need to sort the
633 // results, and we can let the database know about the expected limit.
634 $ilDB->setLimit(1, 0);
635 $query = sprintf(
636 "SELECT * FROM " . $this->table_tree . " " .
637 $this->buildJoin() .
638 "WHERE parent = %s " .
639 "AND " . $this->table_tree . "." . $this->tree_pk . " = %s " .
640 "AND " . $this->table_obj_data . ".type = %s ",
641 $ilDB->quote($a_node_id, 'integer'),
642 $ilDB->quote($this->tree_id, 'integer'),
643 $ilDB->quote($a_type, 'text')
644 );
645 } else {
646 $query = sprintf(
647 "SELECT * FROM " . $this->table_tree . " " .
648 $this->buildJoin() .
649 "WHERE parent = %s " .
650 "AND " . $this->table_tree . "." . $this->tree_pk . " = %s " .
651 "AND " . $this->table_obj_data . ".type = %s " .
652 "ORDER BY " . $this->table_tree . ".lft",
653 $ilDB->quote($a_node_id, 'integer'),
654 $ilDB->quote($this->tree_id, 'integer'),
655 $ilDB->quote($a_type, 'text')
656 );
657 }
658 $res = $ilDB->query($query);
659
660 // init childs
661 $childs = array();
662 while ($row = $ilDB->fetchAssoc($res)) {
663 $childs[] = $this->fetchNodeData($row);
664 }
665
666 return $childs ? $childs : array();
667 }

References $a_type, $DIC, $ilDB, $message, $query, $res, $row, buildJoin(), and fetchNodeData().

+ Here is the call graph for this function:

◆ getChildsByTypeFilter()

ilTree::getChildsByTypeFilter (   $a_node_id,
  $a_types,
  $a_order = "",
  $a_direction = "ASC" 
)

get child nodes of given node by object type @access public

Parameters
integernode_id
arrayarray of object type
Returns
array with node data of all childs or empty array
Exceptions
InvalidArgumentException

Definition at line 678 of file class.ilTree.php.

679 {
680 global $DIC;
681
682 $ilDB = $DIC['ilDB'];
683
684 if (!isset($a_node_id) or !$a_types) {
685 $message = "Missing parameter! node_id:" . $a_node_id . " type:" . $a_types;
686 $this->log->error($message);
687 throw new InvalidArgumentException($message);
688 }
689
690 $filter = ' ';
691 if ($a_types) {
692 $filter = 'AND ' . $this->table_obj_data . '.type IN(' . implode(',', ilUtil::quoteArray($a_types)) . ') ';
693 }
694
695 // set order_clause if sort order parameter is given
696 if (!empty($a_order)) {
697 $order_clause = "ORDER BY " . $a_order . " " . $a_direction;
698 } else {
699 $order_clause = "ORDER BY " . $this->table_tree . ".lft";
700 }
701
702 $query = 'SELECT * FROM ' . $this->table_tree . ' ' .
703 $this->buildJoin() .
704 'WHERE parent = ' . $ilDB->quote($a_node_id, 'integer') . ' ' .
705 'AND ' . $this->table_tree . '.' . $this->tree_pk . ' = ' . $ilDB->quote($this->tree_id, 'integer') . ' ' .
706 $filter .
707 $order_clause;
708
709 $res = $ilDB->query($query);
710 while ($row = $ilDB->fetchAssoc($res)) {
711 $childs[] = $this->fetchNodeData($row);
712 }
713
714 return $childs ? $childs : array();
715 }
static quoteArray($a_array)
Quotes all members of an array for usage in DB query statement.

References $DIC, $ilDB, $message, $query, $res, $row, buildJoin(), fetchNodeData(), and ilUtil\quoteArray().

Referenced by ilSkillTree\getMaxOrderNr().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getChildSequenceNumber()

ilTree::getChildSequenceNumber (   $a_node,
  $type = "" 
)

get sequence number of node in sibling sequence @access public

Parameters
arraynode
Returns
integer sequence number
Exceptions
InvalidArgumentException

Definition at line 2083 of file class.ilTree.php.

2084 {
2085 global $DIC;
2086
2087 $ilDB = $DIC['ilDB'];
2088
2089 if (!isset($a_node)) {
2090 $message = "No node_id given!";
2091 $this->log->error($message);
2092 throw new InvalidArgumentException($message);
2093 }
2094
2095 if ($type) {
2096 $query = 'SELECT count(*) cnt FROM ' . $this->table_tree . ' ' .
2097 $this->buildJoin() .
2098 'WHERE lft <= %s ' .
2099 'AND type = %s ' .
2100 'AND parent = %s ' .
2101 'AND ' . $this->table_tree . '.' . $this->tree_pk . ' = %s ';
2102
2103 $res = $ilDB->queryF($query, array('integer','text','integer','integer'), array(
2104 $a_node['lft'],
2105 $type,
2106 $a_node['parent'],
2107 $this->tree_id));
2108 } else {
2109 $query = 'SELECT count(*) cnt FROM ' . $this->table_tree . ' ' .
2110 $this->buildJoin() .
2111 'WHERE lft <= %s ' .
2112 'AND parent = %s ' .
2113 'AND ' . $this->table_tree . '.' . $this->tree_pk . ' = %s ';
2114
2115 $res = $ilDB->queryF($query, array('integer','integer','integer'), array(
2116 $a_node['lft'],
2117 $a_node['parent'],
2118 $this->tree_id));
2119 }
2120 $row = $ilDB->fetchAssoc($res);
2121 return $row["cnt"];
2122 }
$type

References $DIC, $ilDB, $message, $query, $res, $row, $type, and buildJoin().

+ Here is the call graph for this function:

◆ getDepth()

ilTree::getDepth (   $a_node_id)

return depth of a node in tree @access private

Parameters
integernode_id of parent's node_id
Returns
integer depth of node in tree

Definition at line 1400 of file class.ilTree.php.

1401 {
1402 global $DIC;
1403
1404 $ilDB = $DIC['ilDB'];
1405
1406 if ($a_node_id) {
1407 $query = 'SELECT depth FROM ' . $this->table_tree . ' ' .
1408 'WHERE child = %s ' .
1409 'AND ' . $this->tree_pk . ' = %s ';
1410 $res = $ilDB->queryF($query, array('integer','integer'), array($a_node_id,$this->tree_id));
1411 $row = $ilDB->fetchObject($res);
1412
1413 return $row->depth;
1414 } else {
1415 return 1;
1416 }
1417 }

References $DIC, $ilDB, $query, $res, and $row.

◆ getDepthCache()

ilTree::getDepthCache ( )

Get depth cache.

Returns
type

Definition at line 262 of file class.ilTree.php.

263 {
264 return (array) $this->depth_cache;
265 }

References $depth_cache.

◆ getFilteredChilds()

ilTree::getFilteredChilds (   $a_filter,
  $a_node,
  $a_order = "",
  $a_direction = "ASC" 
)

get child nodes of given node (exclude filtered obj_types) @access public

Parameters
arrayobjects to filter (e.g array('rolf'))
integernode_id
stringsort order of returned childs, optional (possible values: 'title','desc','last_update' or 'type')
stringsort direction, optional (possible values: 'DESC' or 'ASC'; defalut is 'ASC')
Returns
array with node data of all childs or empty array

Definition at line 597 of file class.ilTree.php.

598 {
599 $childs = $this->getChilds($a_node, $a_order, $a_direction);
600
601 foreach ($childs as $child) {
602 if (!in_array($child["type"], $a_filter)) {
603 $filtered[] = $child;
604 }
605 }
606 return $filtered ? $filtered : array();
607 }
getChilds($a_node_id, $a_order="", $a_direction="ASC")
get child nodes of given node @access public

References getChilds().

+ Here is the call graph for this function:

◆ getFilteredSubTree()

ilTree::getFilteredSubTree (   $a_node_id,
  $a_filter = array() 
)

get filtered subtree

get all subtree nodes beginning at a specific node excluding specific object types and their child nodes.

E.g getFilteredSubTreeNodes()

@access public

Parameters

return

Definition at line 831 of file class.ilTree.php.

832 {
833 $node = $this->getNodeData($a_node_id);
834
835 $first = true;
836 $depth = 0;
837 foreach ($this->getSubTree($node) as $subnode) {
838 if ($depth and $subnode['depth'] > $depth) {
839 continue;
840 }
841 if (!$first and in_array($subnode['type'], $a_filter)) {
842 $depth = $subnode['depth'];
843 $first = false;
844 continue;
845 }
846 $depth = 0;
847 $first = false;
848 $filtered[] = $subnode;
849 }
850 return $filtered ? $filtered : array();
851 }
getSubTree($a_node, $a_with_data=true, $a_type="")
get all nodes in the subtree under specified node
getNodeData($a_node_id, $a_tree_pk=null)
get all information of a node.

References getNodeData(), and getSubTree().

+ Here is the call graph for this function:

◆ getGap()

ilTree::getGap ( )

Get default gap *.

Returns
int

Definition at line 331 of file class.ilTree.php.

332 {
333 return $this->gap;
334 }

References $gap.

◆ getLeftValue()

ilTree::getLeftValue (   $a_node_id)

get left value of given node @access public

Parameters
integernode id
Returns
integer left value
Exceptions
InvalidArgumentException

Definition at line 2054 of file class.ilTree.php.

2055 {
2056 global $DIC;
2057
2058 $ilDB = $DIC['ilDB'];
2059
2060 if (!isset($a_node_id)) {
2061 $message = "No node_id given!";
2062 $this->log->error($message);
2063 throw new InvalidArgumentException($message);
2064 }
2065
2066 $query = 'SELECT lft FROM ' . $this->table_tree . ' ' .
2067 'WHERE child = %s ' .
2068 'AND ' . $this->tree_pk . ' = %s ';
2069 $res = $ilDB->queryF($query, array('integer','integer'), array(
2070 $a_node_id,
2071 $this->tree_id));
2072 $row = $ilDB->fetchObject($res);
2073 return $row->lft;
2074 }

References $DIC, $ilDB, $message, $query, $res, and $row.

◆ getMaximumDepth()

ilTree::getMaximumDepth ( )

Return the current maximum depth in the tree @access public.

Returns
integer max depth level of tree

Definition at line 1381 of file class.ilTree.php.

1382 {
1383 global $DIC;
1384
1385 $ilDB = $DIC['ilDB'];
1386
1387 $query = 'SELECT MAX(depth) depth FROM ' . $this->table_tree;
1388 $res = $ilDB->query($query);
1389
1390 $row = $ilDB->fetchAssoc($res);
1391 return $row['depth'];
1392 }

References $DIC, $ilDB, $query, $res, $row, and $table_tree.

◆ getNodeData()

ilTree::getNodeData (   $a_node_id,
  $a_tree_pk = null 
)

get all information of a node.

get data of a specific node from tree and object_data @access public

Parameters
integernode id
Returns
array 2-dim (int/str) node_data
Exceptions
InvalidArgumentException

Definition at line 1457 of file class.ilTree.php.

1459 {
1460 global $DIC;
1461
1462 $ilDB = $DIC['ilDB'];
1463
1464 if (!isset($a_node_id)) {
1465 $this->log->logStack(ilLogLevel::ERROR);
1466 throw new InvalidArgumentException("No node_id given!");
1467 }
1468 if ($this->__isMainTree()) {
1469 if ($a_node_id < 1) {
1470 $message = 'No valid parameter given! $a_node_id: %s' . $a_node_id;
1471
1472 $this->log->error($message);
1473 throw new InvalidArgumentException($message);
1474 }
1475 }
1476
1477 // BEGIN WebDAV: Pass tree id to this method
1478 $query = 'SELECT * FROM ' . $this->table_tree . ' ' .
1479 $this->buildJoin() .
1480 'WHERE ' . $this->table_tree . '.child = %s ' .
1481 'AND ' . $this->table_tree . '.' . $this->tree_pk . ' = %s ';
1482 $res = $ilDB->queryF($query, array('integer','integer'), array(
1483 $a_node_id,
1484 $a_tree_pk === null ? $this->tree_id : $a_tree_pk));
1485 // END WebDAV: Pass tree id to this method
1486 $row = $ilDB->fetchAssoc($res);
1488
1489 return $this->fetchNodeData($row);
1490 }

References $DIC, $ilDB, $message, $query, $res, $row, $tree_id, $tree_pk, __isMainTree(), buildJoin(), ilLogLevel\ERROR, and fetchNodeData().

Referenced by ilWorkspaceTree\cascadingDelete(), ilLMTree\getCompleteTree(), getFilteredSubTree(), ilWorkspaceTree\getObjectsFromType(), getSubTreeFilteredByObjIds(), getSubTreeTypes(), and ilTestTaxonomyTree\initOrderedTreeIndex().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getNodeDataByType()

ilTree::getNodeDataByType (   $a_type)

get nodes by type

Parameters
integera_tree_id: obj_id of object where tree belongs to
integera_type_id: type of object @access public
Exceptions
InvalidArgumentException
Returns
array
Deprecated:
since 4.4.0

Definition at line 1768 of file class.ilTree.php.

1769 {
1770 global $DIC;
1771
1772 $ilDB = $DIC['ilDB'];
1773
1774 if (!isset($a_type) or (!is_string($a_type))) {
1775 $this->log->logStack(ilLogLevel::ERROR);
1776 throw new InvalidArgumentException('Type not given or wrong datatype');
1777 }
1778
1779 $query = 'SELECT * FROM ' . $this->table_tree . ' ' .
1780 $this->buildJoin() .
1781 'WHERE ' . $this->table_obj_data . '.type = ' . $this->ilDB->quote($a_type, 'text') .
1782 'AND ' . $this->table_tree . '.' . $this->tree_pk . ' = ' . $this->ilDB->quote($this->tree_id, 'integer');
1783
1784 $res = $ilDB->query($query);
1785 $data = array();
1786 while ($row = $ilDB->fetchAssoc($res)) {
1787 $data[] = $this->fetchNodeData($row);
1788 }
1789
1790 return $data;
1791 }

References $a_type, $data, $DIC, $ilDB, $query, $res, $row, buildJoin(), ilLogLevel\ERROR, and fetchNodeData().

+ Here is the call graph for this function:

◆ getNodePath()

ilTree::getNodePath (   $a_endnode_id,
  $a_startnode_id = 0 
)

Returns the node path for the specified object reference.

Note: this function returns the same result as getNodePathForTitlePath, but takes ref-id's as parameters.

This function differs from getPathFull, in the following aspects:

  • The title of an object is not translated into the language of the user
  • This function is significantly faster than getPathFull.

@access public

Parameters
integernode_id of endnode
integernode_id of startnode (optional)
Returns
array ordered path info (depth,parent,child,obj_id,type,title) or null, if the node_id can not be converted into a node path.

Definition at line 1223 of file class.ilTree.php.

1224 {
1225 global $DIC;
1226
1227 $ilDB = $DIC['ilDB'];
1228
1229 $pathIds = $this->getPathId($a_endnode_id, $a_startnode_id);
1230
1231 // Abort if no path ids were found
1232 if (count($pathIds) == 0) {
1233 return null;
1234 }
1235
1236
1237 $types = array();
1238 $data = array();
1239 for ($i = 0; $i < count($pathIds); $i++) {
1240 $types[] = 'integer';
1241 $data[] = $pathIds[$i];
1242 }
1243
1244 $query = 'SELECT t.depth,t.parent,t.child,d.obj_id,d.type,d.title ' .
1245 'FROM ' . $this->table_tree . ' t ' .
1246 'JOIN ' . $this->table_obj_reference . ' r ON r.ref_id = t.child ' .
1247 'JOIN ' . $this->table_obj_data . ' d ON d.obj_id = r.obj_id ' .
1248 'WHERE ' . $ilDB->in('t.child', $data, false, 'integer') . ' ' .
1249 'ORDER BY t.depth ';
1250
1251 $res = $ilDB->queryF($query, $types, $data);
1252
1253 $titlePath = array();
1254 while ($row = $ilDB->fetchAssoc($res)) {
1255 $titlePath[] = $row;
1256 }
1257 return $titlePath;
1258 }
getPathId($a_endnode_id, $a_startnode_id=0)
get path from a given startnode to a given endnode if startnode is not given the rootnode is startnod...

References $data, $DIC, $i, $ilDB, $query, $res, $row, and getPathId().

Referenced by getNodePathForTitlePath().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getNodePathForTitlePath()

ilTree::getNodePathForTitlePath (   $titlePath,
  $a_startnode_id = null 
)

Converts a path consisting of object titles into a path consisting of tree nodes.

The comparison is non-case sensitive.

Note: this function returns the same result as getNodePath, but takes a title path as parameter.

@access public

Parameters
ArrayPath array with object titles. e.g. array('ILIAS','English','Course A')
ref_idStartnode of the relative path. Specify null, if the title path is an absolute path. Specify a ref id, if the title path is a relative path starting at this ref id.
Returns
array ordered path info (depth,parent,child,obj_id,type,title) or null, if the title path can not be converted into a node path.

Definition at line 1109 of file class.ilTree.php.

1110 {
1111 global $DIC;
1112
1113 $ilDB = $DIC['ilDB'];
1114 $log = $DIC['log'];
1115 //$log->write('getNodePathForTitlePath('.implode('/',$titlePath));
1116
1117 // handle empty title path
1118 if ($titlePath == null || count($titlePath) == 0) {
1119 if ($a_startnode_id == 0) {
1120 return null;
1121 } else {
1122 return $this->getNodePath($a_startnode_id);
1123 }
1124 }
1125
1126 // fetch the node path up to the startnode
1127 if ($a_startnode_id != null && $a_startnode_id != 0) {
1128 // Start using the node path to the root of the relative path
1129 $nodePath = $this->getNodePath($a_startnode_id);
1130 $parent = $a_startnode_id;
1131 } else {
1132 // Start using the root of the tree
1133 $nodePath = array();
1134 $parent = 0;
1135 }
1136
1137
1138 // Convert title path into Unicode Normal Form C
1139 // This is needed to ensure that we can compare title path strings with
1140 // strings from the database.
1141 require_once('include/Unicode/UtfNormal.php');
1142 include_once './Services/Utilities/classes/class.ilStr.php';
1143 $inClause = 'd.title IN (';
1144 for ($i = 0; $i < count($titlePath); $i++) {
1145 $titlePath[$i] = ilStr::strToLower(UtfNormal::toNFC($titlePath[$i]));
1146 if ($i > 0) {
1147 $inClause .= ',';
1148 }
1149 $inClause .= $ilDB->quote($titlePath[$i], 'text');
1150 }
1151 $inClause .= ')';
1152
1153 // Fetch all rows that are potential path elements
1154 if ($this->table_obj_reference) {
1155 $joinClause = 'JOIN ' . $this->table_obj_reference . ' r ON t.child = r.' . $this->ref_pk . ' ' .
1156 'JOIN ' . $this->table_obj_data . ' d ON r.' . $this->obj_pk . ' = d.' . $this->obj_pk;
1157 } else {
1158 $joinClause = 'JOIN ' . $this->table_obj_data . ' d ON t.child = d.' . $this->obj_pk;
1159 }
1160 // The ORDER BY clause in the following SQL statement ensures that,
1161 // in case of a multiple objects with the same title, always the Object
1162 // with the oldest ref_id is chosen.
1163 // This ensure, that, if a new object with the same title is added,
1164 // WebDAV clients can still work with the older object.
1165 $q = 'SELECT t.depth, t.parent, t.child, d.' . $this->obj_pk . ' obj_id, d.type, d.title ' .
1166 'FROM ' . $this->table_tree . ' t ' .
1167 $joinClause . ' ' .
1168 'WHERE ' . $inClause . ' ' .
1169 'AND t.depth <= ' . (count($titlePath) + count($nodePath)) . ' ' .
1170 'AND t.tree = 1 ' .
1171 'ORDER BY t.depth, t.child ASC';
1172 $r = $ilDB->query($q);
1173
1174 $rows = array();
1175 while ($row = $r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) {
1176 $row['title'] = UtfNormal::toNFC($row['title']);
1177 $row['ref_id'] = $row['child'];
1178 $rows[] = $row;
1179 }
1180
1181 // Extract the path elements from the fetched rows
1182 for ($i = 0; $i < count($titlePath); $i++) {
1183 $pathElementFound = false;
1184 foreach ($rows as $row) {
1185 if ($row['parent'] == $parent &&
1186 ilStr::strToLower($row['title']) == $titlePath[$i]) {
1187 // FIXME - We should test here, if the user has
1188 // 'visible' permission for the object.
1189 $nodePath[] = $row;
1190 $parent = $row['child'];
1191 $pathElementFound = true;
1192 break;
1193 }
1194 }
1195 // Abort if we haven't found a path element for the current depth
1196 if (!$pathElementFound) {
1197 //$log->write('ilTree.getNodePathForTitlePath('.var_export($titlePath,true).','.$a_startnode_id.'):null');
1198 return null;
1199 }
1200 }
1201 // Return the node path
1202 //$log->write('ilTree.getNodePathForTitlePath('.var_export($titlePath,true).','.$a_startnode_id.'):'.var_export($nodePath,true));
1203 return $nodePath;
1204 }
static toNFC($string)
Convert a UTF-8 string to normal form C, canonical composition.
Definition: UtfNormal.php:157
static strToLower($a_string)
Definition: class.ilStr.php:87
getNodePath($a_endnode_id, $a_startnode_id=0)
Returns the node path for the specified object reference.

References $DIC, $i, $ilDB, $log, $obj_pk, $r, $row, $rows, ilDBConstants\FETCHMODE_ASSOC, getNodePath(), ilStr\strToLower(), and UtfNormal\toNFC().

+ Here is the call graph for this function:

◆ getNodeTreeData()

ilTree::getNodeTreeData (   $a_node_id)

return all columns of tabel tree

Parameters
type$a_node_id
Returns
array of table column => values
Exceptions
InvalidArgumentException

Definition at line 1426 of file class.ilTree.php.

1427 {
1428 global $DIC;
1429
1430 $ilDB = $DIC['ilDB'];
1431
1432 if (!$a_node_id) {
1433 $this->log->logStack(ilLogLevel::ERROR);
1434 throw new InvalidArgumentException('Missing or empty parameter $a_node_id: ' . $a_node_id);
1435 }
1436
1437 $query = 'SELECT * FROM ' . $this->table_tree . ' ' .
1438 'WHERE child = ' . $ilDB->quote($a_node_id, 'integer');
1439 $res = $ilDB->query($query);
1440 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) {
1441 return $row;
1442 }
1443 return array();
1444 }

References $DIC, $ilDB, $query, $res, $row, ilLogLevel\ERROR, and ilDBConstants\FETCHMODE_ASSOC.

Referenced by getRelation(), getSubTreeQuery(), and moveToTrash().

+ Here is the caller graph for this function:

◆ getObjectDataTable()

ilTree::getObjectDataTable ( )

Get object data table.

Returns
type

Definition at line 306 of file class.ilTree.php.

307 {
309 }

References $table_obj_data.

Referenced by getSubTreeFilteredByObjIds().

+ Here is the caller graph for this function:

◆ getParentCache()

ilTree::getParentCache ( )

Get parent cache.

Returns
type

Definition at line 271 of file class.ilTree.php.

272 {
273 return (array) $this->parent_cache;
274 }

References $parent_cache.

◆ getParentId()

ilTree::getParentId (   $a_node_id)

get parent id of given node @access public

Parameters
integernode id
Returns
integer parent id
Exceptions
InvalidArgumentException

Definition at line 2024 of file class.ilTree.php.

2025 {
2026 global $DIC;
2027
2028 $ilDB = $DIC['ilDB'];
2029
2030 if (!isset($a_node_id)) {
2031 $message = "No node_id given!";
2032 $this->log->error($message);
2033 throw new InvalidArgumentException($message);
2034 }
2035
2036 $query = 'SELECT parent FROM ' . $this->table_tree . ' ' .
2037 'WHERE child = %s ' .
2038 'AND ' . $this->tree_pk . ' = %s ';
2039 $res = $ilDB->queryF($query, array('integer','integer'), array(
2040 $a_node_id,
2041 $this->tree_id));
2042
2043 $row = $ilDB->fetchObject($res);
2044 return $row->parent;
2045 }

References $DIC, $ilDB, $message, $query, $res, and $row.

Referenced by moveTree().

+ Here is the caller graph for this function:

◆ getParentNodeData()

ilTree::getParentNodeData (   $a_node_id)

get data of parent node from tree and object_data @access public

Parameters
integernode id
Returns
array
Exceptions
InvalidArgumentException

Definition at line 1659 of file class.ilTree.php.

1660 {
1661 global $DIC;
1662
1663 $ilDB = $DIC['ilDB'];
1664 global $DIC;
1665
1666 $ilLog = $DIC['ilLog'];
1667
1668 if (!isset($a_node_id)) {
1669 $ilLog->logStack();
1670 throw new InvalidArgumentException(__METHOD__ . ': No node_id given!');
1671 }
1672
1673 if ($this->table_obj_reference) {
1674 // Use inner join instead of left join to improve performance
1675 $innerjoin = "JOIN " . $this->table_obj_reference . " ON v.child=" . $this->table_obj_reference . "." . $this->ref_pk . " " .
1676 "JOIN " . $this->table_obj_data . " ON " . $this->table_obj_reference . "." . $this->obj_pk . "=" . $this->table_obj_data . "." . $this->obj_pk . " ";
1677 } else {
1678 // Use inner join instead of left join to improve performance
1679 $innerjoin = "JOIN " . $this->table_obj_data . " ON v.child=" . $this->table_obj_data . "." . $this->obj_pk . " ";
1680 }
1681
1682 $query = 'SELECT * FROM ' . $this->table_tree . ' s, ' . $this->table_tree . ' v ' .
1683 $innerjoin .
1684 'WHERE s.child = %s ' .
1685 'AND s.parent = v.child ' .
1686 'AND s.' . $this->tree_pk . ' = %s ' .
1687 'AND v.' . $this->tree_pk . ' = %s';
1688 $res = $ilDB->queryF($query, array('integer','integer','integer'), array(
1689 $a_node_id,
1690 $this->tree_id,
1691 $this->tree_id));
1692 $row = $ilDB->fetchAssoc($res);
1693 return $this->fetchNodeData($row);
1694 }

References $DIC, $ilDB, $ilLog, $query, $res, $row, and fetchNodeData().

+ Here is the call graph for this function:

◆ getPathFull()

ilTree::getPathFull (   $a_endnode_id,
  $a_startnode_id = 0 
)

get path from a given startnode to a given endnode if startnode is not given the rootnode is startnode.

This function chooses the algorithm to be used.

@access public

Parameters
integernode_id of endnode
integernode_id of startnode (optional)
Returns
array ordered path info (id,title,parent) from start to end

Definition at line 989 of file class.ilTree.php.

990 {
991 $pathIds = $this->getPathId($a_endnode_id, $a_startnode_id);
992
993 // We retrieve the full path in a single query to improve performance
994 global $DIC;
995
996 $ilDB = $DIC['ilDB'];
997
998 // Abort if no path ids were found
999 if (count($pathIds) == 0) {
1000 return null;
1001 }
1002
1003 $inClause = 'child IN (';
1004 for ($i = 0; $i < count($pathIds); $i++) {
1005 if ($i > 0) {
1006 $inClause .= ',';
1007 }
1008 $inClause .= $ilDB->quote($pathIds[$i], 'integer');
1009 }
1010 $inClause .= ')';
1011
1012 $q = 'SELECT * ' .
1013 'FROM ' . $this->table_tree . ' ' .
1014 $this->buildJoin() . ' ' .
1015 'WHERE ' . $inClause . ' ' .
1016 'AND ' . $this->table_tree . '.' . $this->tree_pk . ' = ' . $this->ilDB->quote($this->tree_id, 'integer') . ' ' .
1017 'ORDER BY depth';
1018 $r = $ilDB->query($q);
1019
1020 $pathFull = array();
1021 while ($row = $r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) {
1022 $pathFull[] = $this->fetchNodeData($row);
1023
1024 // Update cache
1025 if ($this->__isMainTree()) {
1026 #$GLOBALS['DIC']['ilLog']->write(__METHOD__.': Storing in tree cache '.$row['child']);
1027 $this->in_tree_cache[$row['child']] = $row['tree'] == 1;
1028 }
1029 }
1030 return $pathFull;
1031 }

References $DIC, $i, $ilDB, $r, $row, __isMainTree(), buildJoin(), ilDBConstants\FETCHMODE_ASSOC, fetchNodeData(), and getPathId().

Referenced by checkForParentType(), ilTestTaxonomyTree\getPathNodes(), and ilSkillTree\getSkillTreePath().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getPathId()

ilTree::getPathId (   $a_endnode_id,
  $a_startnode_id = 0 
)

get path from a given startnode to a given endnode if startnode is not given the rootnode is startnode @access public

Parameters
integernode_id of endnode
integernode_id of startnode (optional)
Returns
array all path ids from startnode to endnode
Exceptions
InvalidArgumentException

Definition at line 1069 of file class.ilTree.php.

1070 {
1071 if (!$a_endnode_id) {
1072 $this->log->logStack(ilLogLevel::ERROR);
1073 throw new InvalidArgumentException(__METHOD__ . ': No endnode given!');
1074 }
1075
1076 // path id cache
1077 if ($this->isCacheUsed() && isset($this->path_id_cache[$a_endnode_id][$a_startnode_id])) {
1078 //echo "<br>getPathIdhit";
1079 return $this->path_id_cache[$a_endnode_id][$a_startnode_id];
1080 }
1081 //echo "<br>miss";
1082
1083 $pathIds = $this->getTreeImplementation()->getPathIds($a_endnode_id, $a_startnode_id);
1084
1085 if ($this->__isMainTree()) {
1086 $this->path_id_cache[$a_endnode_id][$a_startnode_id] = $pathIds;
1087 }
1088 return $pathIds;
1089 }

References __isMainTree(), ilLogLevel\ERROR, getTreeImplementation(), and isCacheUsed().

Referenced by getNodePath(), getPathFull(), and ilSkillTree\getTopParentNodeId().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getRbacSubtreeInfo()

ilTree::getRbacSubtreeInfo (   $a_endnode_id)

This method is used for change existing objects and returns all necessary information for this action.

The former use of ilTree::getSubtree needs to much memory.

Parameters
ref_idref_id of source node
Returns

Definition at line 2651 of file class.ilTree.php.

2652 {
2653 return $this->getTreeImplementation()->getSubtreeInfo($a_endnode_id);
2654 }

References getTreeImplementation().

+ Here is the call graph for this function:

◆ getRelation()

ilTree::getRelation (   $a_node_a,
  $a_node_b 
)

Get relation of two nodes.

Parameters
int$a_node_a
int$a_node_b

Definition at line 458 of file class.ilTree.php.

459 {
460 return $this->getRelationOfNodes(
461 $this->getNodeTreeData($a_node_a),
462 $this->getNodeTreeData($a_node_b)
463 );
464 }
getRelationOfNodes($a_node_a_arr, $a_node_b_arr)
get relation of two nodes by node data
getNodeTreeData($a_node_id)
return all columns of tabel tree

References getNodeTreeData(), and getRelationOfNodes().

Referenced by isGrandChild().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getRelationOfNodes()

ilTree::getRelationOfNodes (   $a_node_a_arr,
  $a_node_b_arr 
)

get relation of two nodes by node data

Parameters
array$a_node_a_arr
array$a_node_b_arr

Definition at line 472 of file class.ilTree.php.

473 {
474 return $this->getTreeImplementation()->getRelation($a_node_a_arr, $a_node_b_arr);
475 }

References getTreeImplementation().

Referenced by getRelation().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getRootId()

ilTree::getRootId ( )

get the root id of tree @access public

Returns
integer root node id

Definition at line 2152 of file class.ilTree.php.

2153 {
2154 return $this->root_id;
2155 }

References $root_id.

Referenced by ilWorkspaceTree\getObjectsFromType(), and ilTestTaxonomyTree\initOrderedTreeIndex().

+ Here is the caller graph for this function:

◆ getSavedNodeData()

ilTree::getSavedNodeData (   $a_parent_id)

get data saved/deleted nodes

Returns
array data
Parameters
integerid of parent object of saved object @access public
Exceptions
InvalidArgumentException

Definition at line 1966 of file class.ilTree.php.

1967 {
1968 global $DIC;
1969
1970 $ilDB = $DIC['ilDB'];
1971
1972 if (!isset($a_parent_id)) {
1973 $message = "No node_id given!";
1974 $this->log->error($message);
1975 throw new InvalidArgumentException($message);
1976 }
1977
1978 $query = 'SELECT * FROM ' . $this->table_tree . ' ' .
1979 $this->buildJoin() .
1980 'WHERE ' . $this->table_tree . '.' . $this->tree_pk . ' < %s ' .
1981 'AND ' . $this->table_tree . '.parent = %s';
1982 $res = $ilDB->queryF($query, array('integer','integer'), array(
1983 0,
1984 $a_parent_id));
1985
1986 while ($row = $ilDB->fetchAssoc($res)) {
1987 $saved[] = $this->fetchNodeData($row);
1988 }
1989
1990 return $saved ? $saved : array();
1991 }

References $DIC, $ilDB, $message, $query, $res, $row, buildJoin(), and fetchNodeData().

+ Here is the call graph for this function:

◆ getSavedNodeObjIds()

ilTree::getSavedNodeObjIds ( array  $a_obj_ids)

get object id of saved/deleted nodes

Returns
array data
Parameters
arrayobject ids to check @access public

Definition at line 1999 of file class.ilTree.php.

2000 {
2001 global $DIC;
2002
2003 $ilDB = $DIC['ilDB'];
2004
2005 $query = 'SELECT ' . $this->table_obj_data . '.obj_id FROM ' . $this->table_tree . ' ' .
2006 $this->buildJoin() .
2007 'WHERE ' . $this->table_tree . '.' . $this->tree_pk . ' < ' . $ilDB->quote(0, 'integer') . ' ' .
2008 'AND ' . $ilDB->in($this->table_obj_data . '.obj_id', $a_obj_ids, '', 'integer');
2009 $res = $ilDB->query($query);
2010 while ($row = $ilDB->fetchAssoc($res)) {
2011 $saved[] = $row['obj_id'];
2012 }
2013
2014 return $saved ? $saved : array();
2015 }

References $DIC, $ilDB, $query, $res, $row, and buildJoin().

+ Here is the call graph for this function:

◆ getSubTree()

ilTree::getSubTree (   $a_node,
  $a_with_data = true,
  $a_type = "" 
)

get all nodes in the subtree under specified node

@access public

Parameters
arraynode_data
booleanwith data: default is true otherwise this function return only a ref_id array
Returns
array 2-dim (int/array) key, node_data of each subtree node including the specified node
Exceptions
InvalidArgumentException

Definition at line 873 of file class.ilTree.php.

874 {
875 global $DIC;
876
877 $ilDB = $DIC['ilDB'];
878
879 if (!is_array($a_node)) {
880 $this->log->logStack(ilLogLevel::ERROR);
881 throw new InvalidArgumentException(__METHOD__ . ': wrong datatype for node data given');
882 }
883
884 /*
885 if($a_node['lft'] < 1 or $a_node['rgt'] < 2)
886 {
887 $GLOBALS['DIC']['ilLog']->logStack();
888 $message = sprintf('%s: Invalid node given! $a_node["lft"]: %s $a_node["rgt"]: %s',
889 __METHOD__,
890 $a_node['lft'],
891 $a_node['rgt']);
892
893 throw new InvalidArgumentException($message);
894 }
895 */
896
897 $query = $this->getTreeImplementation()->getSubTreeQuery($a_node, $a_type);
898 $res = $ilDB->query($query);
899 while ($row = $ilDB->fetchAssoc($res)) {
900 if ($a_with_data) {
901 $subtree[] = $this->fetchNodeData($row);
902 } else {
903 $subtree[] = $row['child'];
904 }
905 // the lm_data "hack" should be removed in the trunk during an alpha
906 if ($this->__isMainTree() || $this->table_tree == "lm_tree") {
907 $this->in_tree_cache[$row['child']] = true;
908 }
909 }
910 return $subtree ? $subtree : array();
911 }

References $a_type, $DIC, $ilDB, $query, $res, $row, __isMainTree(), ilLogLevel\ERROR, fetchNodeData(), and getTreeImplementation().

Referenced by ilWorkspaceTree\cascadingDelete(), ilLMTree\getCompleteTree(), getFilteredSubTree(), ilWorkspaceTree\getObjectsFromType(), and ilTestTaxonomyTree\initOrderedTreeIndex().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getSubTreeFilteredByObjIds()

ilTree::getSubTreeFilteredByObjIds (   $a_node_id,
array  $a_obj_ids,
array  $a_fields = array() 
)

get all node ids in the subtree under specified node id, filter by object ids

Parameters
int$a_node_id
array$a_obj_ids
array$a_fields
Returns
array

Definition at line 2683 of file class.ilTree.php.

2684 {
2685 global $DIC;
2686
2687 $ilDB = $DIC['ilDB'];
2688
2689 $node = $this->getNodeData($a_node_id);
2690 if (!sizeof($node)) {
2691 return;
2692 }
2693
2694 $res = array();
2695
2696 $query = $this->getTreeImplementation()->getSubTreeQuery($node, '', true, array($this->ref_pk));
2697
2698 $fields = '*';
2699 if (count($a_fields)) {
2700 $fields = implode(',', $a_fields);
2701 }
2702
2703 $query = "SELECT " . $fields .
2704 " FROM " . $this->getTreeTable() .
2705 " " . $this->buildJoin() .
2706 " WHERE " . $this->getTableReference() . "." . $this->ref_pk . " IN (" . $query . ")" .
2707 " AND " . $ilDB->in($this->getObjectDataTable() . "." . $this->obj_pk, $a_obj_ids, "", "integer");
2708 $set = $ilDB->query($query);
2709 while ($row = $ilDB->fetchAssoc($set)) {
2710 $res[] = $row;
2711 }
2712
2713 return $res;
2714 }
getTreeTable()
Get tree table name.
getTableReference()
Get reference table if available.
getObjectDataTable()
Get object data table.

References $DIC, $ilDB, $query, $res, $row, buildJoin(), getNodeData(), getObjectDataTable(), getTableReference(), getTreeImplementation(), and getTreeTable().

+ Here is the call graph for this function:

◆ getSubTreeIds()

ilTree::getSubTreeIds (   $a_ref_id)

Get all ids of subnodes.

Returns
Parameters
object$a_ref_id

Definition at line 858 of file class.ilTree.php.

859 {
860 return $this->getTreeImplementation()->getSubTreeIds($a_ref_id);
861 }

References getTreeImplementation().

+ Here is the call graph for this function:

◆ getSubTreeQuery()

ilTree::getSubTreeQuery (   $a_node_id,
  $a_fields = array(),
  $a_types = '',
  $a_force_join_reference = false 
)

Get tree subtree query.

Parameters
type$a_node_id
type$a_types
type$a_force_join_reference
Returns
type

Definition at line 2664 of file class.ilTree.php.

2665 {
2666 return $this->getTreeImplementation()->getSubTreeQuery(
2667 $this->getNodeTreeData($a_node_id),
2668 $a_types,
2669 $a_force_join_reference,
2670 $a_fields
2671 );
2672 }

References getNodeTreeData(), and getTreeImplementation().

+ Here is the call graph for this function:

◆ getSubTreeTypes()

ilTree::getSubTreeTypes (   $a_node,
  $a_filter = 0 
)

get types of nodes in the subtree under specified node

@access public

Parameters
arraynode_id
arrayobject types to filter e.g array('rolf')
Returns
array 2-dim (int/array) key, node_data of each subtree node including the specified node

Definition at line 921 of file class.ilTree.php.

922 {
923 $a_filter = $a_filter ? $a_filter : array();
924
925 foreach ($this->getSubtree($this->getNodeData($a_node)) as $node) {
926 if (in_array($node["type"], $a_filter)) {
927 continue;
928 }
929 $types["$node[type]"] = $node["type"];
930 }
931 return $types ? $types : array();
932 }

References getNodeData().

+ Here is the call graph for this function:

◆ getTableReference()

ilTree::getTableReference ( )

Get reference table if available.

Definition at line 323 of file class.ilTree.php.

324 {
326 }
$table_obj_reference

References $table_obj_reference.

Referenced by getSubTreeFilteredByObjIds().

+ Here is the caller graph for this function:

◆ getTreeId()

ilTree::getTreeId ( )

get tree id @access public

Returns
integer tree id

Definition at line 2166 of file class.ilTree.php.

2167 {
2168 return $this->tree_id;
2169 }

References $tree_id.

Referenced by ilWorkspaceExplorer\__construct().

+ Here is the caller graph for this function:

◆ getTreeImplementation()

ilTree::getTreeImplementation ( )

Get tree implementation.

Returns
ilTreeImplementation $impl

Definition at line 236 of file class.ilTree.php.

237 {
238 return $this->tree_impl;
239 }

References $tree_impl.

Referenced by __checkDelete(), deleteTree(), getPathId(), getRbacSubtreeInfo(), getRelationOfNodes(), getSubTree(), getSubTreeFilteredByObjIds(), getSubTreeIds(), getSubTreeQuery(), insertNode(), moveToTrash(), moveTree(), and validateParentRelations().

+ Here is the caller graph for this function:

◆ getTreePk()

ilTree::getTreePk ( )

Get tree primary key.

Returns
string column of pk

Definition at line 315 of file class.ilTree.php.

316 {
317 return $this->tree_pk;
318 }

References $tree_pk.

◆ getTreeTable()

ilTree::getTreeTable ( )

Get tree table name.

Returns
string tree table name

Definition at line 297 of file class.ilTree.php.

298 {
299 return $this->table_tree;
300 }

References $table_tree.

Referenced by getSubTreeFilteredByObjIds().

+ Here is the caller graph for this function:

◆ initLangCode()

ilTree::initLangCode ( )

Store user language.

This function is used by the "main" tree only (during initialisation).

Definition at line 280 of file class.ilTree.php.

281 {
282 global $DIC;
283
284 // lang_code is only required in $this->fetchnodedata
285 try {
286 $ilUser = $DIC['ilUser'];
287 $this->lang_code = $ilUser->getCurrentLanguage();
288 } catch (\InvalidArgumentException $e) {
289 $this->lang_code = "en";
290 }
291 }

References $DIC, and $ilUser.

◆ initTreeImplementation()

ilTree::initTreeImplementation ( )

Init tree implementation.

Definition at line 204 of file class.ilTree.php.

205 {
206 global $DIC;
207
208 if (!$DIC->isDependencyAvailable('settings') || $DIC->settings()->getModule() != 'common') {
209 include_once './Services/Administration/classes/class.ilSetting.php';
210 $setting = new ilSetting('common');
211 } else {
212 $setting = $DIC->settings();
213 }
214
215 if ($this->__isMainTree()) {
216 if ($setting->get('main_tree_impl', 'ns') == 'ns') {
217 #$GLOBALS['DIC']['ilLog']->write(__METHOD__.': Using nested set.');
218 include_once './Services/Tree/classes/class.ilNestedSetTree.php';
219 $this->tree_impl = new ilNestedSetTree($this);
220 } else {
221 #$GLOBALS['DIC']['ilLog']->write(__METHOD__.': Using materialized path.');
222 include_once './Services/Tree/classes/class.ilMaterializedPathTree.php';
223 $this->tree_impl = new ilMaterializedPathTree($this);
224 }
225 } else {
226 #$GLOBALS['DIC']['ilLog']->write(__METHOD__.': Using netsted set for non main tree.');
227 include_once './Services/Tree/classes/class.ilNestedSetTree.php';
228 $this->tree_impl = new ilNestedSetTree($this);
229 }
230 }
Base class for materialize path based trees Based on implementation of Werner Randelshofer.
Base class for nested set path based trees.
ILIAS Setting Class.

References $DIC, and __isMainTree().

Referenced by __construct(), and setTableNames().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ insertNode()

ilTree::insertNode (   $a_node_id,
  $a_parent_id,
  $a_pos = IL_LAST_NODE,
  $a_reset_deletion_date = false 
)

insert new node with node_id under parent node with parent_id @access public

Parameters
integernode_id
integerparent_id
integerIL_LAST_NODE | IL_FIRST_NODE | node id of preceding child
Exceptions
InvalidArgumentException

Definition at line 767 of file class.ilTree.php.

768 {
769 global $DIC;
770
771 $ilDB = $DIC['ilDB'];
772
773 //echo "+$a_node_id+$a_parent_id+";
774 // CHECK node_id and parent_id > 0 if in main tree
775 if ($this->__isMainTree()) {
776 if ($a_node_id <= 1 or $a_parent_id <= 0) {
777 $message = sprintf(
778 'Invalid parameters! $a_node_id: %s $a_parent_id: %s',
779 $a_node_id,
780 $a_parent_id
781 );
782 $this->log->logStack(ilLogLevel::ERROR, $message);
783 throw new InvalidArgumentException($message);
784 }
785 }
786
787
788 if (!isset($a_node_id) or !isset($a_parent_id)) {
789 $this->log->logStack(ilLogLevel::ERROR);
790 throw new InvalidArgumentException("Missing parameter! " .
791 "node_id: " . $a_node_id . " parent_id: " . $a_parent_id);
792 }
793 if ($this->isInTree($a_node_id)) {
794 throw new InvalidArgumentException("Node " . $a_node_id . " already in tree " .
795 $this->table_tree . "!");
796 }
797
798 $this->getTreeImplementation()->insertNode($a_node_id, $a_parent_id, $a_pos);
799
800 $this->in_tree_cache[$a_node_id] = true;
801
802 // reset deletion date
803 if ($a_reset_deletion_date) {
804 ilObject::_resetDeletedDate($a_node_id);
805 }
806
807 if (isset($GLOBALS['DIC']["ilAppEventHandler"]) && $this->__isMainTree()) {
808 $GLOBALS['DIC']['ilAppEventHandler']->raise(
809 "Services/Tree",
810 "insertNode",
811 array(
812 'tree' => $this->table_tree,
813 'node_id' => $a_node_id,
814 'parent_id' => $a_parent_id)
815 );
816 }
817 }
static _resetDeletedDate($a_ref_id)
only called in ilObjectGUI::insertSavedNodes
$GLOBALS['JPEG_Segment_Names']
Global Variable: XMP_tag_captions.

References $DIC, $GLOBALS, $ilDB, $message, __isMainTree(), ilObject\_resetDeletedDate(), ilLogLevel\ERROR, getTreeImplementation(), and isInTree().

Referenced by insertNodeFromTrash(), and ilWorkspaceTree\insertObject().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ insertNodeFromTrash()

ilTree::insertNodeFromTrash (   $a_source_id,
  $a_target_id,
  $a_tree_id,
  $a_pos = IL_LAST_NODE,
  $a_reset_deleted_date = false 
)

Insert node from trash deletes trash entry.

If we have database query exceptions we could wrap insertNode in try/catch and rollback if the insert failed.

Parameters
type$a_source_id
type$a_target_id
type$a_tree_id
Exceptions
InvalidArgumentException

Definition at line 728 of file class.ilTree.php.

729 {
730 global $DIC;
731
732 $ilDB = $DIC['ilDB'];
733
734 if ($this->__isMainTree()) {
735 if ($a_source_id <= 1 or $a_target_id <= 0) {
737 throw new InvalidArgumentException('Invalid parameter given for ilTree::insertNodeFromTrash');
738 }
739 }
740 if (!isset($a_source_id) or !isset($a_target_id)) {
742 throw new InvalidArgumentException('Missing parameter for ilTree::insertNodeFromTrash');
743 }
744 if ($this->isInTree($a_source_id)) {
745 ilLoggerFactory::getLogger('tree')->error('Node already in tree');
747 throw new InvalidArgumentException('Node already in tree.');
748 }
749
750 $query = 'DELETE from tree ' .
751 'WHERE tree = ' . $ilDB->quote($a_tree_id, 'integer') . ' ' .
752 'AND child = ' . $ilDB->quote($a_source_id, 'integer');
753 $ilDB->manipulate($query);
754
755 $this->insertNode($a_source_id, $a_target_id, IL_LAST_NODE, $a_reset_deleted_date);
756 }
const IL_LAST_NODE
Definition: class.ilTree.php:4
insertNode($a_node_id, $a_parent_id, $a_pos=IL_LAST_NODE, $a_reset_deletion_date=false)
insert new node with node_id under parent node with parent_id @access public

References $DIC, $ilDB, $query, __isMainTree(), ilLoggerFactory\getLogger(), IL_LAST_NODE, ilLogLevel\INFO, insertNode(), and isInTree().

+ Here is the call graph for this function:

◆ isCacheUsed()

ilTree::isCacheUsed ( )

Check if cache is active.

Returns
bool

Reimplemented in ilLMTree.

Definition at line 253 of file class.ilTree.php.

254 {
255 return $this->__isMainTree() and $this->use_cache;
256 }

References __isMainTree().

Referenced by checkForParentType(), fetchNodeData(), fetchTranslationFromObjectDataCache(), getChilds(), getPathId(), isInTree(), isSaved(), preloadDeleted(), and preloadDepthParent().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ isDeleted()

ilTree::isDeleted (   $a_node_id)

This is a wrapper for isSaved() with a more useful name.

Parameters
int$a_node_id

Definition at line 1885 of file class.ilTree.php.

1886 {
1887 return $this->isSaved($a_node_id);
1888 }
isSaved($a_node_id)
Use method isDeleted check if node is saved.

References isSaved().

+ Here is the call graph for this function:

◆ isGrandChild()

ilTree::isGrandChild (   $a_startnode_id,
  $a_querynode_id 
)

checks if a node is in the path of an other node @access public

Parameters
integerobject id of start node
integerobject id of query node
Returns
integer number of entries

Definition at line 1703 of file class.ilTree.php.

1704 {
1705 return $this->getRelation($a_startnode_id, $a_querynode_id) == self::RELATION_PARENT;
1706 }
getRelation($a_node_a, $a_node_b)
Get relation of two nodes.
const RELATION_PARENT

References getRelation(), and RELATION_PARENT.

+ Here is the call graph for this function:

◆ isInTree()

ilTree::isInTree (   $a_node_id)

get all information of a node.

get data of a specific node from tree and object_data @access public

Parameters
integernode id
Returns
boolean true, if node id is in tree

Definition at line 1612 of file class.ilTree.php.

1613 {
1614 global $DIC;
1615
1616 $ilDB = $DIC['ilDB'];
1617
1618 if (!isset($a_node_id)) {
1619 return false;
1620 #$this->ilErr->raiseError(get_class($this)."::getNodeData(): No node_id given! ",$this->ilErr->WARNING);
1621 }
1622 // is in tree cache
1623 if ($this->isCacheUsed() && isset($this->in_tree_cache[$a_node_id])) {
1624 #$GLOBALS['DIC']['ilLog']->write(__METHOD__.': Using in tree cache '.$a_node_id);
1625 //echo "<br>in_tree_hit";
1626 return $this->in_tree_cache[$a_node_id];
1627 }
1628
1629 $query = 'SELECT * FROM ' . $this->table_tree . ' ' .
1630 'WHERE ' . $this->table_tree . '.child = %s ' .
1631 'AND ' . $this->table_tree . '.' . $this->tree_pk . ' = %s';
1632
1633 $res = $ilDB->queryF($query, array('integer','integer'), array(
1634 $a_node_id,
1635 $this->tree_id));
1636
1637 if ($res->numRows() > 0) {
1638 if ($this->__isMainTree()) {
1639 #$GLOBALS['DIC']['ilLog']->write(__METHOD__.': Storing in tree cache '.$a_node_id.' = true');
1640 $this->in_tree_cache[$a_node_id] = true;
1641 }
1642 return true;
1643 } else {
1644 if ($this->__isMainTree()) {
1645 #$GLOBALS['DIC']['ilLog']->write(__METHOD__.': Storing in tree cache '.$a_node_id.' = false');
1646 $this->in_tree_cache[$a_node_id] = false;
1647 }
1648 return false;
1649 }
1650 }

References $DIC, $ilDB, $query, $res, __isMainTree(), and isCacheUsed().

Referenced by checkForParentType(), insertNode(), and insertNodeFromTrash().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ isSaved()

ilTree::isSaved (   $a_node_id)

Use method isDeleted check if node is saved.

Deprecated:
since 4.4.0

Definition at line 1895 of file class.ilTree.php.

1896 {
1897 global $DIC;
1898
1899 $ilDB = $DIC['ilDB'];
1900
1901 // is saved cache
1902 if ($this->isCacheUsed() && isset($this->is_saved_cache[$a_node_id])) {
1903 //echo "<br>issavedhit";
1904 return $this->is_saved_cache[$a_node_id];
1905 }
1906
1907 $query = 'SELECT ' . $this->tree_pk . ' FROM ' . $this->table_tree . ' ' .
1908 'WHERE child = %s ';
1909 $res = $ilDB->queryF($query, array('integer'), array($a_node_id));
1910 $row = $ilDB->fetchAssoc($res);
1911
1912 if ($row[$this->tree_pk] < 0) {
1913 if ($this->__isMainTree()) {
1914 $this->is_saved_cache[$a_node_id] = true;
1915 }
1916 return true;
1917 } else {
1918 if ($this->__isMainTree()) {
1919 $this->is_saved_cache[$a_node_id] = false;
1920 }
1921 return false;
1922 }
1923 }

References $DIC, $ilDB, $query, $res, $row, __isMainTree(), and isCacheUsed().

Referenced by isDeleted().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ lookupTrashedObjectTypes()

ilTree::lookupTrashedObjectTypes ( )

Lookup object types in trash @global type $ilDB.

Returns
type

Definition at line 2743 of file class.ilTree.php.

2744 {
2745 global $DIC;
2746
2747 $ilDB = $DIC['ilDB'];
2748
2749 $query = 'SELECT DISTINCT(o.type) ' . $ilDB->quoteIdentifier('type') . ' FROM tree t JOIN object_reference r ON child = r.ref_id ' .
2750 'JOIN object_data o on r.obj_id = o.obj_id ' .
2751 'WHERE tree < ' . $ilDB->quote(0, 'integer') . ' ' .
2752 'AND child = -tree ' .
2753 'GROUP BY o.type';
2754 $res = $ilDB->query($query);
2755
2756 $types_deleted = array();
2757 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
2758 $types_deleted[] = $row->type;
2759 }
2760 return $types_deleted;
2761 }

References $DIC, $ilDB, $query, $res, $row, and ilDBConstants\FETCHMODE_OBJECT.

◆ moveToTrash()

ilTree::moveToTrash (   $a_node_id,
  $a_set_deleted = false 
)

Wrapper for saveSubTree.

Parameters
int$a_node_id
bool$a_set_deleted
Returns
integer
Exceptions
InvalidArgumentException

Definition at line 1830 of file class.ilTree.php.

1831 {
1832 global $DIC;
1833
1834 $ilDB = $DIC['ilDB'];
1835
1836 if (!$a_node_id) {
1837 $this->log->logStack(ilLogLevel::ERROR);
1838 throw new InvalidArgumentException('No valid parameter given! $a_node_id: ' . $a_node_id);
1839 }
1840
1841
1842 $query = $this->getTreeImplementation()->getSubTreeQuery($this->getNodeTreeData($a_node_id), '', false);
1843 $res = $ilDB->query($query);
1844
1845 $subnodes = array();
1846 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) {
1847 $subnodes[] = $row['child'];
1848 }
1849
1850 if (!count($subnodes)) {
1851 // Possibly already deleted
1852 return false;
1853 }
1854
1855 if ($a_set_deleted) {
1856 include_once './Services/Object/classes/class.ilObject.php';
1857 ilObject::setDeletedDates($subnodes);
1858 }
1859
1860 // netsted set <=> mp
1861 $this->getTreeImplementation()->moveToTrash($a_node_id);
1862
1863 return true;
1864 }
static setDeletedDates($a_ref_ids)
Set deleted date.

References $DIC, $ilDB, $query, $res, $row, ilLogLevel\ERROR, ilDBConstants\FETCHMODE_ASSOC, getNodeTreeData(), getTreeImplementation(), and ilObject\setDeletedDates().

Referenced by saveSubTree().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ moveTree()

ilTree::moveTree (   $a_source_id,
  $a_target_id,
  $a_location = self::POS_LAST_NODE 
)

Move Tree Implementation.

@access public

Parameters
intsource ref_id
inttarget ref_id
intlocation IL_LAST_NODE or IL_FIRST_NODE (IL_FIRST_NODE not implemented yet)
Returns
bool

Definition at line 2622 of file class.ilTree.php.

2623 {
2624 $old_parent_id = $this->getParentId($a_source_id);
2625 $this->getTreeImplementation()->moveTree($a_source_id, $a_target_id, $a_location);
2626 if (isset($GLOBALS['DIC']["ilAppEventHandler"]) && $this->__isMainTree()) {
2627 $GLOBALS['DIC']['ilAppEventHandler']->raise(
2628 "Services/Tree",
2629 "moveTree",
2630 array(
2631 'tree' => $this->table_tree,
2632 'source_id' => $a_source_id,
2633 'target_id' => $a_target_id,
2634 'old_parent_id' => $old_parent_id
2635 )
2636 );
2637 }
2638 return true;
2639 }
getParentId($a_node_id)
get parent id of given node @access public

References $GLOBALS, __isMainTree(), getParentId(), and getTreeImplementation().

+ Here is the call graph for this function:

◆ preloadDeleted()

ilTree::preloadDeleted (   $a_node_ids)

Preload deleted information.

Parameters
arraynodfe ids
Returns
bool

Definition at line 1931 of file class.ilTree.php.

1932 {
1933 global $DIC;
1934
1935 $ilDB = $DIC['ilDB'];
1936
1937 if (!is_array($a_node_ids) || !$this->isCacheUsed()) {
1938 return;
1939 }
1940
1941 $query = 'SELECT ' . $this->tree_pk . ', child FROM ' . $this->table_tree . ' ' .
1942 'WHERE ' . $ilDB->in("child", $a_node_ids, false, "integer");
1943
1944 $res = $ilDB->query($query);
1945 while ($row = $ilDB->fetchAssoc($res)) {
1946 if ($row[$this->tree_pk] < 0) {
1947 if ($this->__isMainTree()) {
1948 $this->is_saved_cache[$row["child"]] = true;
1949 }
1950 } else {
1951 if ($this->__isMainTree()) {
1952 $this->is_saved_cache[$row["child"]] = false;
1953 }
1954 }
1955 }
1956 }

References $DIC, $ilDB, $query, $res, $row, __isMainTree(), and isCacheUsed().

+ Here is the call graph for this function:

◆ preloadDepthParent()

ilTree::preloadDepthParent (   $a_node_ids)

Preload depth/parent.

Parameters

return

Definition at line 1040 of file class.ilTree.php.

1041 {
1042 global $DIC;
1043
1044 $ilDB = $DIC['ilDB'];
1045
1046 if (!$this->__isMainTree() || !is_array($a_node_ids) || !$this->isCacheUsed()) {
1047 return;
1048 }
1049
1050 $res = $ilDB->query('SELECT t.depth, t.parent, t.child ' .
1051 'FROM ' . $this->table_tree . ' t ' .
1052 'WHERE ' . $ilDB->in("child", $a_node_ids, false, "integer") .
1053 'AND ' . $this->tree_pk . ' = ' . $ilDB->quote($this->tree_id, "integer"));
1054 while ($row = $ilDB->fetchAssoc($res)) {
1055 $this->depth_cache[$row["child"]] = $row["depth"];
1056 $this->parent_cache[$row["child"]] = $row["parent"];
1057 }
1058 }

References $DIC, $ilDB, $res, $row, __isMainTree(), and isCacheUsed().

+ Here is the call graph for this function:

◆ readRootId()

ilTree::readRootId ( )

read root id from database

Parameters
root_id@access public
Returns
int new root id

Definition at line 2130 of file class.ilTree.php.

2131 {
2132 global $DIC;
2133
2134 $ilDB = $DIC['ilDB'];
2135
2136 $query = 'SELECT child FROM ' . $this->table_tree . ' ' .
2137 'WHERE parent = %s ' .
2138 'AND ' . $this->tree_pk . ' = %s ';
2139 $res = $ilDB->queryF($query, array('integer','integer'), array(
2140 0,
2141 $this->tree_id));
2142 $row = $ilDB->fetchObject($res);
2143 $this->root_id = $row->child;
2144 return $this->root_id;
2145 }

References $DIC, $ilDB, $query, $res, $root_id, and $row.

Referenced by ilWorkspaceTree\__construct(), ilWorkspaceExplorer\__construct(), ilTestTaxonomyTree\__construct(), ilWorkspaceTree\cascadingDelete(), ilWorkspaceAccessHandler\checkAccessOfUser(), ilLMTree\getCompleteTree(), and ilSkillTree\getMaxOrderNr().

+ Here is the caller graph for this function:

◆ removeTree()

ilTree::removeTree (   $a_tree_id)

remove an existing tree

Parameters
integera_tree_id: tree to be removed
Returns
boolean true on success @access public
Exceptions
InvalidArgumentException

Definition at line 1801 of file class.ilTree.php.

1802 {
1803 global $DIC;
1804
1805 $ilDB = $DIC['ilDB'];
1806
1807 // OPERATION NOT ALLOWED ON MAIN TREE
1808 if ($this->__isMainTree()) {
1809 $this->log->logStack(ilLogLevel::ERROR);
1810 throw new InvalidArgumentException('Operation not allowed on main tree');
1811 }
1812 if (!$a_tree_id) {
1813 $this->log->logStack(ilLogLevel::ERROR);
1814 throw new InvalidArgumentException('Missing parameter tree id');
1815 }
1816
1817 $query = 'DELETE FROM ' . $this->table_tree .
1818 ' WHERE ' . $this->tree_pk . ' = %s ';
1819 $ilDB->manipulateF($query, array('integer'), array($a_tree_id));
1820 return true;
1821 }

References $DIC, $ilDB, $query, __isMainTree(), and ilLogLevel\ERROR.

+ Here is the call graph for this function:

◆ renumber()

ilTree::renumber (   $node_id = 1,
  $i = 1 
)

Wrapper for renumber.

This method locks the table tree (recursive) @access public

Parameters
integernode_id where to start (usually the root node)
integerfirst left value of start node (usually 1)
Returns
integer current left value of recursive call

Definition at line 2312 of file class.ilTree.php.

2313 {
2314 global $DIC;
2315
2316 $ilDB = $DIC['ilDB'];
2317
2318 $renumber_callable = function (ilDBInterface $ilDB) use ($node_id,$i,&$return) {
2319 $return = $this->__renumber($node_id, $i);
2320 };
2321
2322 // LOCKED ###################################
2323 if ($this->__isMainTree()) {
2324 $ilAtomQuery = $ilDB->buildAtomQuery();
2325 $ilAtomQuery->addTableLock($this->table_tree);
2326
2327 $ilAtomQuery->addQueryCallable($renumber_callable);
2328 $ilAtomQuery->run();
2329 } else {
2330 $renumber_callable($ilDB);
2331 }
2332 return $return;
2333 }
Interface ilDBInterface.

References $DIC, $i, $ilDB, __isMainTree(), and __renumber().

+ Here is the call graph for this function:

◆ resetInTreeCache()

ilTree::resetInTreeCache ( )

Definition at line 339 of file class.ilTree.php.

340 {
341 $this->in_tree_cache = array();
342 }

Referenced by deleteTree().

+ Here is the caller graph for this function:

◆ saveSubTree()

ilTree::saveSubTree (   $a_node_id,
  $a_set_deleted = false 
)

Use the wrapper moveToTrash save subtree: delete a subtree (defined by node_id) to a new tree with $this->tree_id -node_id.

This is neccessary for undelete functionality

Parameters
integernode_id
Returns
integer @access public
Exceptions
InvalidArgumentException
Deprecated:
since 4.4.0

Definition at line 1876 of file class.ilTree.php.

1877 {
1878 return $this->moveToTrash($a_node_id, $a_set_deleted);
1879 }
moveToTrash($a_node_id, $a_set_deleted=false)
Wrapper for saveSubTree.

References moveToTrash().

+ Here is the call graph for this function:

◆ setObjectTablePK()

ilTree::setObjectTablePK (   $a_column_name)

set column containing primary key in object table @access public

Parameters
stringcolumn name
Returns
boolean true, when successfully set
Exceptions
InvalidArgumentException

Definition at line 405 of file class.ilTree.php.

406 {
407 if (!isset($a_column_name)) {
408 $message = "No column name given!";
409 $this->log->error($message);
410 throw new InvalidArgumentException($message);
411 }
412
413 $this->obj_pk = $a_column_name;
414 return true;
415 }

References $message.

Referenced by ilECSCmsTree\__construct(), and ilWorkspaceTree\__construct().

+ Here is the caller graph for this function:

◆ setReferenceTablePK()

ilTree::setReferenceTablePK (   $a_column_name)

set column containing primary key in reference table @access public

Parameters
stringcolumn name
Returns
boolean true, when successfully set
Exceptions
InvalidArgumentException

Definition at line 386 of file class.ilTree.php.

387 {
388 if (!isset($a_column_name)) {
389 $message = "No column name given!";
390 $this->log->error($message);
391 throw new InvalidArgumentException($message);
392 }
393
394 $this->ref_pk = $a_column_name;
395 return true;
396 }

References $message.

Referenced by ilWorkspaceTree\__construct().

+ Here is the caller graph for this function:

◆ setRootId()

ilTree::setRootId (   $a_root_id)

Definition at line 2156 of file class.ilTree.php.

2157 {
2158 $this->root_id = $a_root_id;
2159 }

Referenced by ilWorkspaceExplorer\__construct(), and ilWorkspaceTree\createTreeForUser().

+ Here is the caller graph for this function:

◆ setTableNames()

ilTree::setTableNames (   $a_table_tree,
  $a_table_obj_data,
  $a_table_obj_reference = "" 
)

set table names The primary key of the table containing your object_data must be 'obj_id' You may use a reference table.

If no reference table is specified the given tree table is directly joined with the given object_data table. The primary key in object_data table and its foreign key in reference table must have the same name!

Parameters
stringtable name of tree table
stringtable name of object_data table
stringtable name of object_reference table (optional) @access public
Returns
boolean
Exceptions
InvalidArgumentException

Definition at line 361 of file class.ilTree.php.

362 {
363 if (!isset($a_table_tree) or !isset($a_table_obj_data)) {
364 $message = "Missing parameter! " .
365 "tree table: " . $a_table_tree . " object data table: " . $a_table_obj_data;
366 $this->log->error($message);
367 throw new InvalidArgumentException($message);
368 }
369
370 $this->table_tree = $a_table_tree;
371 $this->table_obj_data = $a_table_obj_data;
372 $this->table_obj_reference = $a_table_obj_reference;
373
374 $this->initTreeImplementation();
375
376 return true;
377 }

References $message, and initTreeImplementation().

Referenced by ilSCORM2004Tree\__construct(), ilTaxonomyTree\__construct(), ilSCORMTree\__construct(), ilLMTree\__construct(), ilECSCmsTree\__construct(), ilWorkspaceTree\__construct(), ilBookmarkTree\__construct(), and ilSkillTree\__construct().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ setTreeId()

ilTree::setTreeId (   $a_tree_id)

set tree id @access public

Returns
integer tree id

Definition at line 2176 of file class.ilTree.php.

2177 {
2178 $this->tree_id = $a_tree_id;
2179 }

◆ setTreeTablePK()

ilTree::setTreeTablePK (   $a_column_name)

set column containing primary key in tree table @access public

Parameters
stringcolumn name
Returns
boolean true, when successfully set
Exceptions
InvalidArgumentException

Definition at line 424 of file class.ilTree.php.

425 {
426 if (!isset($a_column_name)) {
427 $message = "No column name given!";
428 $this->log->error($message);
429 throw new InvalidArgumentException($message);
430 }
431
432 $this->tree_pk = $a_column_name;
433 return true;
434 }

References $message.

Referenced by ilSCORM2004Tree\__construct(), ilTaxonomyTree\__construct(), ilSCORMTree\__construct(), ilLMTree\__construct(), ilWorkspaceTree\__construct(), and ilSkillTree\__construct().

+ Here is the caller graph for this function:

◆ useCache()

ilTree::useCache (   $a_use = true)

Use Cache (usually activated)

Definition at line 244 of file class.ilTree.php.

245 {
246 $this->use_cache = $a_use;
247 }

Referenced by ilLMTree\__construct(), and ilECSCmsTree\__construct().

+ Here is the caller graph for this function:

◆ validateParentRelations()

ilTree::validateParentRelations ( )

Validate parent relations of tree.

Returns
int[] array of failure nodes

Definition at line 974 of file class.ilTree.php.

975 {
976 return $this->getTreeImplementation()->validateParentRelations();
977 }

References getTreeImplementation().

+ Here is the call graph for this function:

Field Documentation

◆ $depth_cache

ilTree::$depth_cache = array()
protected

Definition at line 134 of file class.ilTree.php.

Referenced by getDepthCache().

◆ $gap

ilTree::$gap

Definition at line 132 of file class.ilTree.php.

Referenced by getGap().

◆ $ilias

ilTree::$ilias

Definition at line 42 of file class.ilTree.php.

◆ $in_tree_cache

ilTree::$in_tree_cache = array()
protected

Definition at line 136 of file class.ilTree.php.

◆ $log

ilTree::$log

Definition at line 50 of file class.ilTree.php.

Referenced by getNodePathForTitlePath().

◆ $obj_pk

ilTree::$obj_pk

◆ $parent_cache

ilTree::$parent_cache = array()
protected

Definition at line 135 of file class.ilTree.php.

Referenced by getParentCache().

◆ $ref_pk

ilTree::$ref_pk

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

Referenced by ilWorkspaceTree\lookupNodeId().

◆ $root_id

ilTree::$root_id

◆ $table_obj_data

ilTree::$table_obj_data

Definition at line 78 of file class.ilTree.php.

Referenced by getObjectDataTable().

◆ $table_obj_reference

ilTree::$table_obj_reference

Definition at line 85 of file class.ilTree.php.

Referenced by getTableReference().

◆ $table_tree

ilTree::$table_tree

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

Referenced by getMaximumDepth(), and getTreeTable().

◆ $tree_id

ilTree::$tree_id

Definition at line 64 of file class.ilTree.php.

Referenced by getNodeData(), and getTreeId().

◆ $tree_impl

ilTree::$tree_impl = null
private

Definition at line 138 of file class.ilTree.php.

Referenced by getTreeImplementation().

◆ $tree_pk

ilTree::$tree_pk

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

Referenced by getNodeData(), and getTreePk().

◆ POS_FIRST_NODE

const ilTree::POS_FIRST_NODE = -1

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

Referenced by ilNestedSetTree\insertNode().

◆ POS_LAST_NODE

const ilTree::POS_LAST_NODE = -2

Definition at line 26 of file class.ilTree.php.

◆ RELATION_CHILD

◆ RELATION_EQUALS

const ilTree::RELATION_EQUALS = 4

◆ RELATION_NONE

const ilTree::RELATION_NONE = 5

◆ RELATION_PARENT

◆ RELATION_SIBLING

const ilTree::RELATION_SIBLING = 3

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