ILIAS  release_5-0 Revision 5.0.0-1144-gc4397b1f870
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

 ilTree ($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...
 
 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...
 
 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...
 
 _removeEntry ($a_tree, $a_child, $a_db_table="tree")
 STATIC METHOD Removes a single entry from a tree. 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)
 

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.

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
Deprecated:
since 4.4.0

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

2505 {
2506 global $ilDB;
2507
2508
2509 $query = $this->getTreeImplementation()->getSubTreeQuery($a_node, array(),false);
2510 $GLOBALS['ilLog']->write(__METHOD__.': '.$query);
2511 $res = $ilDB->query($query);
2512
2513 $counter = (int) $lft_childs = array();
2514 while($row = $ilDB->fetchObject($res))
2515 {
2516 $lft_childs[$row->child] = $row->parent;
2517 ++$counter;
2518 }
2519
2520 // CHECK FOR DUPLICATE CHILD IDS
2521 if($counter != count($lft_childs))
2522 {
2523 $message = sprintf('%s::__checkTree(): Duplicate entries for "child" in maintree! $a_node_id: %s',
2524 get_class($this),
2525 $a_node['child']);
2526 $this->log->write($message,$this->log->FATAL);
2527 $this->ilErr->raiseError($message,$this->ilErr->WARNING);
2528 }
2529
2530 // GET SUBTREE BY PARENT RELATION
2531 $parent_childs = array();
2532 $this->__getSubTreeByParentRelation($a_node['child'],$parent_childs);
2533 $this->__validateSubtrees($lft_childs,$parent_childs);
2534
2535 return true;
2536 }
getTreeImplementation()
Get tree implementation.
__getSubTreeByParentRelation($a_node_id, &$parent_childs)
@global type $ilDB
__validateSubtrees(&$lft_childs, $parent_childs)
$GLOBALS['ct_recipient']
global $ilDB

References $GLOBALS, $ilDB, $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
Deprecated:
since 4.4.0

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

2547 {
2548 global $ilDB;
2549
2550 // GET PARENT ID
2551 $query = 'SELECT * FROM '.$this->table_tree.' '.
2552 'WHERE child = %s '.
2553 'AND tree = %s ';
2554 $res = $ilDB->queryF($query,array('integer','integer'),array(
2555 $a_node_id,
2556 $this->tree_id));
2557
2558 $counter = 0;
2559 while($row = $ilDB->fetchObject($res))
2560 {
2561 $parent_childs[$a_node_id] = $row->parent;
2562 ++$counter;
2563 }
2564 // MULTIPLE ENTRIES
2565 if($counter > 1)
2566 {
2567 $message = sprintf('%s::__getSubTreeByParentRelation(): Multiple entries in maintree! $a_node_id: %s',
2568 get_class($this),
2569 $a_node_id);
2570 $this->log->write($message,$this->log->FATAL);
2571 $this->ilErr->raiseError($message,$this->ilErr->WARNING);
2572 }
2573
2574 // GET ALL CHILDS
2575 $query = 'SELECT * FROM '.$this->table_tree.' '.
2576 'WHERE parent = %s ';
2577 $res = $ilDB->queryF($query,array('integer'),array($a_node_id));
2578
2579 while($row = $ilDB->fetchObject($res))
2580 {
2581 // RECURSION
2582 $this->__getSubTreeByParentRelation($row->child,$parent_childs);
2583 }
2584 return true;
2585 }

References $ilDB, $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 2489 of file class.ilTree.php.

2490 {
2491 return $this->table_tree === 'tree';
2492 }

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

+ 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 2353 of file class.ilTree.php.

2354 {
2355 global $ilDB;
2356
2357 $query = 'UPDATE '.$this->table_tree.' SET lft = %s WHERE child = %s';
2358 $res = $ilDB->manipulateF($query,array('integer','integer'),array(
2359 $i,
2360 $node_id));
2361
2362 $childs = $this->getChilds($node_id);
2363
2364 foreach ($childs as $child)
2365 {
2366 $i = $this->__renumber($child["child"],$i+1);
2367 }
2368 $i++;
2369
2370 // Insert a gap at the end of node, if the node has children
2371 if (count($childs) > 0)
2372 {
2373 $i += $this->gap * 2;
2374 }
2375
2376
2377 $query = 'UPDATE '.$this->table_tree.' SET rgt = %s WHERE child = %s';
2378 $res = $ilDB->manipulateF($query,array('integer','integer'),array(
2379 $i,
2380 $node_id));
2381 return $i;
2382 }
__renumber($node_id=1, $i=1)
This method is private.
getChilds($a_node_id, $a_order="", $a_direction="ASC")
get child nodes of given node @access public

References $ilDB, $query, $res, __renumber(), and getChilds().

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 
)

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

2588 {
2589 // SORT BY KEY
2590 ksort($lft_childs);
2591 ksort($parent_childs);
2592
2593 $GLOBALS['ilLog']->write(__METHOD__.': left childs '. print_r($lft_childs,true));
2594 $GLOBALS['ilLog']->write(__METHOD__.': parent childs '. print_r($parent_childs,true));
2595
2596 if(count($lft_childs) != count($parent_childs))
2597 {
2598 $message = sprintf('%s::__validateSubtrees(): (COUNT) Tree is corrupted! Left/Right subtree does not comply .'.
2599 'with parent relation',
2600 get_class($this));
2601 $this->log->write($message,$this->log->FATAL);
2602 $this->ilErr->raiseError($message,$this->ilErr->WARNING);
2603 }
2604
2605
2606 foreach($lft_childs as $key => $value)
2607 {
2608 if($parent_childs[$key] != $value)
2609 {
2610 $message = sprintf('%s::__validateSubtrees(): (COMPARE) Tree is corrupted! Left/Right subtree does not comply '.
2611 'with parent relation',
2612 get_class($this));
2613 $this->log->write($message,$this->log->FATAL);
2614 $this->ilErr->raiseError($message,$this->ilErr->WARNING);
2615 }
2616 if($key == ROOT_FOLDER_ID)
2617 {
2618 $message = sprintf('%s::__validateSubtrees(): (ROOT_FOLDER) Tree is corrupted! Tried to delete root folder',
2619 get_class($this));
2620 $this->log->write($message,$this->log->FATAL);
2621 $this->ilErr->raiseError($message,$this->ilErr->WARNING);
2622 }
2623 }
2624 return true;
2625 }

References $GLOBALS.

Referenced by __checkDelete().

+ Here is the caller graph for this function:

◆ _removeEntry()

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

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)

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

2458 {
2459 global $ilDB,$ilLog,$ilErr;
2460
2461 if($a_db_table === 'tree')
2462 {
2463 if($a_tree == 1 and $a_child == ROOT_FOLDER_ID)
2464 {
2465 $message = sprintf('%s::_removeEntry(): Tried to delete root node! $a_tree: %s $a_child: %s',
2466 get_class($this),
2467 $a_tree,
2468 $a_child);
2469 $ilLog->write($message,$ilLog->FATAL);
2470 $ilErr->raiseError($message,$ilErr->WARNING);
2471 }
2472 }
2473
2474 $query = 'DELETE FROM '.$a_db_table.' '.
2475 'WHERE tree = %s '.
2476 'AND child = %s ';
2477 $res = $ilDB->manipulateF($query,array('integer','integer'),array(
2478 $a_tree,
2479 $a_child));
2480
2481 }

References $ilDB, $ilErr, $ilLog, $query, and $res.

Referenced by ilValidator\purgeObjects().

+ 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 @access public

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

1700 {
1701 global $ilDB;
1702
1703 // FOR SECURITY addTree() IS NOT ALLOWED ON MAIN TREE
1704 if($this->__isMainTree())
1705 {
1706 $message = sprintf('%s::addTree(): Operation not allowed on main tree! $a_tree_if: %s $a_node_id: %s',
1707 get_class($this),
1708 $a_tree_id,
1709 $a_node_id);
1710 $this->log->write($message,$this->log->FATAL);
1711 $this->ilErr->raiseError($message,$this->ilErr->WARNING);
1712 }
1713
1714 if (!isset($a_tree_id))
1715 {
1716 $this->ilErr->raiseError(get_class($this)."::addTree(): No tree_id given! ",$this->ilErr->WARNING);
1717 }
1718
1719 if ($a_node_id <= 0)
1720 {
1721 $a_node_id = $a_tree_id;
1722 }
1723
1724 $query = 'INSERT INTO '.$this->table_tree.' ('.
1725 $this->tree_pk.', child,parent,lft,rgt,depth) '.
1726 'VALUES '.
1727 '(%s,%s,%s,%s,%s,%s)';
1728 $res = $ilDB->manipulateF($query,array('integer','integer','integer','integer','integer','integer'),array(
1729 $a_tree_id,
1730 $a_node_id,
1731 0,
1732 1,
1733 2,
1734 1));
1735
1736 return true;
1737 }
__isMainTree()
Check if operations are done on main tree.

References $ilDB, $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 451 of file class.ilTree.php.

452 {
453 if ($this->table_obj_reference)
454 {
455 // Use inner join instead of left join to improve performance
456 return "JOIN ".$this->table_obj_reference." ON ".$this->table_tree.".child=".$this->table_obj_reference.".".$this->ref_pk." ".
457 "JOIN ".$this->table_obj_data." ON ".$this->table_obj_reference.".".$this->obj_pk."=".$this->table_obj_data.".".$this->obj_pk." ";
458 }
459 else
460 {
461 // Use inner join instead of left join to improve performance
462 return "JOIN ".$this->table_obj_data." ON ".$this->table_tree.".child=".$this->table_obj_data.".".$this->obj_pk." ";
463 }
464 }

Referenced by fetchPredecessorNode(), fetchSuccessorNode(), getChildsByTypeFilter(), getChildSequenceNumber(), getNodeData(), getNodeDataByType(), getPathFull(), getSavedNodeData(), and getSavedNodeObjIds().

+ 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 2395 of file class.ilTree.php.

2396 {
2397 // #12577
2398 $cache_key = $a_ref_id.'.'.$a_type.'.'.((int)$a_exclude_source_check);
2399
2400 // Try to return a cached result
2401 if($this->isCacheUsed() &&
2402 array_key_exists($cache_key, $this->parent_type_cache))
2403 {
2404 return $this->parent_type_cache[$cache_key];
2405 }
2406
2407 // Store up to 1000 results in cache
2408 $do_cache = ($this->__isMainTree() && count($this->parent_type_cache) < 1000);
2409
2410 // ref_id is not in tree
2411 if(!$this->isInTree($a_ref_id))
2412 {
2413 if($do_cache)
2414 {
2415 $this->parent_type_cache[$cache_key] = false;
2416 }
2417 return false;
2418 }
2419
2420 $path = array_reverse($this->getPathFull($a_ref_id));
2421
2422 // remove first path entry as it is requested node
2423 if($a_exclude_source_check)
2424 {
2425 array_shift($path);
2426 }
2427
2428 foreach($path as $node)
2429 {
2430 // found matching parent
2431 if($node["type"] == $a_type)
2432 {
2433 if($do_cache)
2434 {
2435 $this->parent_type_cache[$cache_key] = $node["child"];
2436 }
2437 return $node["child"];
2438 }
2439 }
2440
2441 if($do_cache)
2442 {
2443 $this->parent_type_cache[$cache_key] = false;
2444 }
2445 return 0;
2446 }
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...
$path
Definition: index.php:22

References $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

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

1240 {
1241 global $ilDB;
1242
1243 $types = array('integer');
1244 $query = 'SELECT lft,rgt FROM '.$this->table_tree.' '.
1245 'WHERE '.$this->tree_pk.' = %s ';
1246
1247 $res = $ilDB->queryF($query,$types,array($this->tree_id));
1248 while ($row = $ilDB->fetchObject($res))
1249 {
1250 $lft[] = $row->lft;
1251 $rgt[] = $row->rgt;
1252 }
1253
1254 $all = array_merge($lft,$rgt);
1255 $uni = array_unique($all);
1256
1257 if (count($all) != count($uni))
1258 {
1259 $message = sprintf('%s::checkTree(): Tree is corrupted!',
1260 get_class($this));
1261
1262 $this->log->write($message,$this->log->FATAL);
1263 $this->ilErr->raiseError($message,$this->ilErr->WARNING);
1264 }
1265
1266 return true;
1267 }

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

◆ checkTreeChilds()

ilTree::checkTreeChilds (   $a_no_zero_child = true)

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

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

1273 {
1274 global $ilDB;
1275
1276 $query = 'SELECT * FROM '.$this->table_tree.' '.
1277 'WHERE '.$this->tree_pk.' = %s '.
1278 'ORDER BY lft';
1279 $r1 = $ilDB->queryF($query,array('integer'),array($this->tree_id));
1280
1281 while ($row = $ilDB->fetchAssoc($r1))
1282 {
1283//echo "tree:".$row[$this->tree_pk].":lft:".$row["lft"].":rgt:".$row["rgt"].":child:".$row["child"].":<br>";
1284 if (($row["child"] == 0) && $a_no_zero_child)
1285 {
1286 $this->ilErr->raiseError(get_class($this)."::checkTreeChilds(): Tree contains child with ID 0!",$this->ilErr->WARNING);
1287 }
1288
1289 if ($this->table_obj_reference)
1290 {
1291 // get object reference data
1292 $query = 'SELECT * FROM '.$this->table_obj_reference.' WHERE '.$this->ref_pk.' = %s ';
1293 $r2 = $ilDB->queryF($query,array('integer'),array($row['child']));
1294
1295//echo "num_childs:".$r2->numRows().":<br>";
1296 if ($r2->numRows() == 0)
1297 {
1298 $this->ilErr->raiseError(get_class($this)."::checkTree(): No Object-to-Reference entry found for ID ".
1299 $row["child"]."!",$this->ilErr->WARNING);
1300 }
1301 if ($r2->numRows() > 1)
1302 {
1303 $this->ilErr->raiseError(get_class($this)."::checkTree(): More Object-to-Reference entries found for ID ".
1304 $row["child"]."!",$this->ilErr->WARNING);
1305 }
1306
1307 // get object data
1308 $obj_ref = $ilDB->fetchAssoc($r2);
1309
1310 $query = 'SELECT * FROM '.$this->table_obj_data.' WHERE '.$this->obj_pk.' = %s';
1311 $r3 = $ilDB->queryF($query,array('integer'),array($obj_ref[$this->obj_pk]));
1312 if ($r3->numRows() == 0)
1313 {
1314 $this->ilErr->raiseError(get_class($this)."::checkTree(): No child found for ID ".
1315 $obj_ref[$this->obj_pk]."!",$this->ilErr->WARNING);
1316 }
1317 if ($r3->numRows() > 1)
1318 {
1319 $this->ilErr->raiseError(get_class($this)."::checkTree(): More childs found for ID ".
1320 $obj_ref[$this->obj_pk]."!",$this->ilErr->WARNING);
1321 }
1322
1323 }
1324 else
1325 {
1326 // get only object data
1327 $query = 'SELECT * FROM '.$this->table_obj_data.' WHERE '.$this->obj_pk.' = %s';
1328 $r2 = $ilDB->queryF($query,array('integer'),array($row['child']));
1329//echo "num_childs:".$r2->numRows().":<br>";
1330 if ($r2->numRows() == 0)
1331 {
1332 $this->ilErr->raiseError(get_class($this)."::checkTree(): No child found for ID ".
1333 $row["child"]."!",$this->ilErr->WARNING);
1334 }
1335 if ($r2->numRows() > 1)
1336 {
1337 $this->ilErr->raiseError(get_class($this)."::checkTree(): More childs found for ID ".
1338 $row["child"]."!",$this->ilErr->WARNING);
1339 }
1340 }
1341 }
1342
1343 return true;
1344 }

References $ilDB, $query, and $row.

◆ deleteNode()

ilTree::deleteNode (   $a_tree_id,
  $a_node_id 
)

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

2726 {
2727 global $ilDB;
2728
2729 $query = 'DELETE FROM tree where '.
2730 'child = '.$ilDB->quote($a_node_id,'integer').' '.
2731 'AND tree = '.$ilDB->quote($a_tree_id,'integer');
2732 $ilDB->manipulate($query);
2733 }

References $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,InvalidTreeStructureException

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

908 {
909 global $ilDB;
910
911 $GLOBALS['ilLog']->write(__METHOD__.': Delete tree with node '. $a_node);
912
913 if (!is_array($a_node))
914 {
915 $GLOBALS['ilLog']->logStack();
916 throw new InvalidArgumentException(__METHOD__.': Wrong datatype for node data!');
917 }
918
919 $GLOBALS['ilLog']->write(__METHOD__.': '. $this->tree_pk);
920
921 if($this->__isMainTree() )
922 {
923 // @todo normally this part is not executed, since the subtree is first
924 // moved to trash and then deleted.
925 if(!$this->__checkDelete($a_node))
926 {
927 $GLOBALS['ilLog']->logStack();
928 throw new ilInvalidTreeStructureException('Deletion canceled due to invalid tree structure.' . print_r($a_node,true));
929 }
930 }
931
932 $this->getTreeImplementation()->deleteTree($a_node['child']);
933
934 $this->resetInTreeCache();
935
936 }
Thrown if invalid tree strucutes are found.
__checkDelete($a_node)
Check for deleteTree() compares a subtree of a given node by checking lft, rgt against parent relatio...
resetInTreeCache()

References $GLOBALS, $ilDB, __checkDelete(), __isMainTree(), 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 1470 of file class.ilTree.php.

1471 {
1472 global $objDefinition, $lng, $ilBench,$ilDB;
1473
1474 //$ilBench->start("Tree", "fetchNodeData_getRow");
1475 $data = $a_row;
1476 $data["desc"] = $a_row["description"]; // for compability
1477 //$ilBench->stop("Tree", "fetchNodeData_getRow");
1478
1479 // multilingual support systemobjects (sys) & categories (db)
1480 //$ilBench->start("Tree", "fetchNodeData_readDefinition");
1481 if (is_object($objDefinition))
1482 {
1483 $translation_type = $objDefinition->getTranslationType($data["type"]);
1484 }
1485 //$ilBench->stop("Tree", "fetchNodeData_readDefinition");
1486
1487 if ($translation_type == "sys")
1488 {
1489 //$ilBench->start("Tree", "fetchNodeData_getLangData");
1490 if ($data["type"] == "rolf" and $data["obj_id"] != ROLE_FOLDER_ID)
1491 {
1492 $data["description"] = $lng->txt("obj_".$data["type"]."_local_desc").$data["title"].$data["desc"];
1493 $data["desc"] = $lng->txt("obj_".$data["type"]."_local_desc").$data["title"].$data["desc"];
1494 $data["title"] = $lng->txt("obj_".$data["type"]."_local");
1495 }
1496 else
1497 {
1498 $data["title"] = $lng->txt("obj_".$data["type"]);
1499 $data["description"] = $lng->txt("obj_".$data["type"]."_desc");
1500 $data["desc"] = $lng->txt("obj_".$data["type"]."_desc");
1501 }
1502 //$ilBench->stop("Tree", "fetchNodeData_getLangData");
1503 }
1504 elseif ($translation_type == "db")
1505 {
1506
1507 // Try to retrieve object translation from cache
1508 if ($this->isCacheUsed() &&
1509 array_key_exists($data["obj_id"].'.'.$lang_code, $this->translation_cache)) {
1510
1511 $key = $data["obj_id"].'.'.$lang_code;
1512 $data["title"] = $this->translation_cache[$key]['title'];
1513 $data["description"] = $this->translation_cache[$key]['description'];
1514 $data["desc"] = $this->translation_cache[$key]['desc'];
1515 }
1516 else
1517 {
1518 // Object translation is not in cache, read it from database
1519 //$ilBench->start("Tree", "fetchNodeData_getTranslation");
1520 $query = 'SELECT title,description FROM object_translation '.
1521 'WHERE obj_id = %s '.
1522 'AND lang_code = %s '.
1523 'AND NOT lang_default = %s';
1524
1525 $res = $ilDB->queryF($query,array('integer','text','integer'),array(
1526 $data['obj_id'],
1527 $this->lang_code,
1528 1));
1529 $row = $ilDB->fetchObject($res);
1530
1531 if ($row)
1532 {
1533 $data["title"] = $row->title;
1534 $data["description"] = ilUtil::shortenText($row->description,ilObject::DESC_LENGTH,true);
1535 $data["desc"] = $row->description;
1536 }
1537 //$ilBench->stop("Tree", "fetchNodeData_getTranslation");
1538
1539 // Store up to 1000 object translations in cache
1540 if ($this->isCacheUsed() && count($this->translation_cache) < 1000)
1541 {
1542 $key = $data["obj_id"].'.'.$lang_code;
1543 $this->translation_cache[$key] = array();
1544 $this->translation_cache[$key]['title'] = $data["title"] ;
1545 $this->translation_cache[$key]['description'] = $data["description"];
1546 $this->translation_cache[$key]['desc'] = $data["desc"];
1547 }
1548 }
1549 }
1550
1551 // TODO: Handle this switch by module.xml definitions
1552 if($data['type'] == 'crsr' or $data['type'] == 'catr')
1553 {
1554 include_once('./Services/ContainerReference/classes/class.ilContainerReference.php');
1555 $data['title'] = ilContainerReference::_lookupTitle($data['obj_id']);
1556 }
1557
1558 return $data ? $data : array();
1559 }
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
global $lng
Definition: privfeed.php:40

References $data, $ilBench, $ilDB, $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

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

2245 {
2246 global $ilDB;
2247
2248 if (!isset($a_node_id))
2249 {
2250 $this->ilErr->raiseError(get_class($this)."::getNodeData(): No node_id given! ",$this->ilErr->WARNING);
2251 }
2252
2253 // get lft value for current node
2254 $query = 'SELECT lft FROM '.$this->table_tree.' '.
2255 'WHERE '.$this->table_tree.'.child = %s '.
2256 'AND '.$this->table_tree.'.'.$this->tree_pk.' = %s ';
2257 $res = $ilDB->queryF($query,array('integer','integer'),array(
2258 $a_node_id,
2259 $this->tree_id));
2260
2261 $curr_node = $ilDB->fetchAssoc($res);
2262
2263 if($a_type)
2264 {
2265 $query = 'SELECT * FROM '.$this->table_tree.' '.
2266 $this->buildJoin().
2267 'WHERE lft < %s '.
2268 'AND '.$this->table_obj_data.'.type = %s '.
2269 'AND '.$this->table_tree.'.'.$this->tree_pk.' = %s '.
2270 'ORDER BY lft DESC';
2271 $ilDB->setLimit(1);
2272 $res = $ilDB->queryF($query,array('integer','text','integer'),array(
2273 $curr_node['lft'],
2274 $a_type,
2275 $this->tree_id));
2276 }
2277 else
2278 {
2279 $query = 'SELECT * FROM '.$this->table_tree.' '.
2280 $this->buildJoin().
2281 'WHERE lft < %s '.
2282 'AND '.$this->table_tree.'.'.$this->tree_pk.' = %s '.
2283 'ORDER BY lft DESC';
2284 $ilDB->setLimit(1);
2285 $res = $ilDB->queryF($query,array('integer','integer'),array(
2286 $curr_node['lft'],
2287 $this->tree_id));
2288 }
2289
2290 if ($res->numRows() < 1)
2291 {
2292 return false;
2293 }
2294 else
2295 {
2296 $row = $ilDB->fetchAssoc($res);
2297 return $this->fetchNodeData($row);
2298 }
2299 }
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 $ilDB, $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

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

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

References $ilDB, $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 1566 of file class.ilTree.php.

1567 {
1568 global $ilObjDataCache;
1569
1570 if ($this->isCacheUsed() && is_array($a_obj_ids) && is_object($ilObjDataCache))
1571 {
1572 foreach ($a_obj_ids as $id)
1573 {
1574 $this->translation_cache[$id.'.']['title'] = $ilObjDataCache->lookupTitle($id);
1575 $this->translation_cache[$id.'.']['description'] = $ilObjDataCache->lookupDescription($id);;
1576 $this->translation_cache[$id.'.']['desc'] =
1577 $this->translation_cache[$id.'.']['description'];
1578 }
1579 }
1580 }

References 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 496 of file class.ilTree.php.

497 {
498 global $ilDB;
499
500 $query = 'SELECT * FROM tree '.
501 'WHERE parent = '.$ilDB->quote($a_node,'integer').' '.
502 'AND tree > '.$ilDB->quote(0,'integer');
503 $res = $ilDB->query($query);
504
505 $childs = array();
506 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
507 {
508 $childs[] = $row->child;
509 }
510 return $childs;
511 }
const DB_FETCHMODE_OBJECT
Definition: class.ilDB.php:11

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

◆ 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

Reimplemented in ilSCORMTree.

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

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

References $ilBench, $ilDB, $ilUser, $query, $res, $row, __isMainTree(), fetchNodeData(), fetchTranslationFromObjectDataCache(), and isCacheUsed().

Referenced by __renumber(), and getFilteredChilds().

+ 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

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

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

References $ilDB, $query, $res, $row, 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

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

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

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

+ Here is the call 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

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

2078 {
2079 global $ilDB;
2080
2081 if (!isset($a_node))
2082 {
2083 $this->ilErr->raiseError(get_class($this)."::getChildSequenceNumber(): No node_id given! ",$this->ilErr->WARNING);
2084 }
2085
2086 if($type)
2087 {
2088 $query = 'SELECT count(*) cnt FROM '.$this->table_tree.' '.
2089 $this->buildJoin().
2090 'WHERE lft <= %s '.
2091 'AND type = %s '.
2092 'AND parent = %s '.
2093 'AND '.$this->table_tree.'.'.$this->tree_pk.' = %s ';
2094
2095 $res = $ilDB->queryF($query,array('integer','text','integer','integer'),array(
2096 $a_node['lft'],
2097 $type,
2098 $a_node['parent'],
2099 $this->tree_id));
2100 }
2101 else
2102 {
2103 $query = 'SELECT count(*) cnt FROM '.$this->table_tree.' '.
2104 $this->buildJoin().
2105 'WHERE lft <= %s '.
2106 'AND parent = %s '.
2107 'AND '.$this->table_tree.'.'.$this->tree_pk.' = %s ';
2108
2109 $res = $ilDB->queryF($query,array('integer','integer','integer'),array(
2110 $a_node['lft'],
2111 $a_node['parent'],
2112 $this->tree_id));
2113
2114 }
2115 $row = $ilDB->fetchAssoc($res);
2116 return $row["cnt"];
2117 }

References $ilDB, $query, $res, $row, 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 1368 of file class.ilTree.php.

1369 {
1370 global $ilDB;
1371
1372 if ($a_node_id)
1373 {
1374 $query = 'SELECT depth FROM '.$this->table_tree.' '.
1375 'WHERE child = %s '.
1376 'AND '.$this->tree_pk.' = %s ';
1377 $res = $ilDB->queryF($query,array('integer','integer'),array($a_node_id,$this->tree_id));
1378 $row = $ilDB->fetchObject($res);
1379
1380 return $row->depth;
1381 }
1382 else
1383 {
1384 return 1;
1385 }
1386 }

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

◆ getDepthCache()

ilTree::getDepthCache ( )

Get depth cache.

Returns
type

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

280 {
281 return (array) $this->depth_cache;
282 }

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 608 of file class.ilTree.php.

609 {
610 $childs = $this->getChilds($a_node,$a_order,$a_direction);
611
612 foreach($childs as $child)
613 {
614 if(!in_array($child["type"],$a_filter))
615 {
616 $filtered[] = $child;
617 }
618 }
619 return $filtered ? $filtered : array();
620 }

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 789 of file class.ilTree.php.

790 {
791 $node = $this->getNodeData($a_node_id);
792
793 $first = true;
794 $depth = 0;
795 foreach($this->getSubTree($node) as $subnode)
796 {
797 if($depth and $subnode['depth'] > $depth)
798 {
799 continue;
800 }
801 if(!$first and in_array($subnode['type'],$a_filter))
802 {
803 $depth = $subnode['depth'];
804 $first = false;
805 continue;
806 }
807 $depth = 0;
808 $first = false;
809 $filtered[] = $subnode;
810 }
811 return $filtered ? $filtered : array();
812 }
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 350 of file class.ilTree.php.

351 {
352 return $this->gap;
353 }

References $gap.

◆ getLeftValue()

ilTree::getLeftValue (   $a_node_id)

get left value of given node @access public

Parameters
integernode id
Returns
integer left value

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

2053 {
2054 global $ilDB;
2055
2056 if (!isset($a_node_id))
2057 {
2058 $this->ilErr->raiseError(get_class($this)."::getLeftValued(): No node_id given! ",$this->ilErr->WARNING);
2059 }
2060
2061 $query = 'SELECT lft FROM '.$this->table_tree.' '.
2062 'WHERE child = %s '.
2063 'AND '.$this->tree_pk.' = %s ';
2064 $res = $ilDB->queryF($query,array('integer','integer'),array(
2065 $a_node_id,
2066 $this->tree_id));
2067 $row = $ilDB->fetchObject($res);
2068 return $row->lft;
2069 }

References $ilDB, $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 1351 of file class.ilTree.php.

1352 {
1353 global $ilDB;
1354
1355 $query = 'SELECT MAX(depth) depth FROM '.$this->table_tree;
1356 $res = $ilDB->query($query);
1357
1358 $row = $ilDB->fetchAssoc($res);
1359 return $row['depth'];
1360 }

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

◆ 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

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

1427 {
1428 global $ilDB;
1429
1430 if (!isset($a_node_id))
1431 {
1432 $GLOBALS['ilLog']->logStack();
1433 $this->ilErr->raiseError(get_class($this)."::getNodeData(): No node_id given! ",$this->ilErr->WARNING);
1434 }
1435 if($this->__isMainTree())
1436 {
1437 if($a_node_id < 1)
1438 {
1439 $message = sprintf('%s::getNodeData(): No valid parameter given! $a_node_id: %s',
1440 get_class($this),
1441 $a_node_id);
1442
1443 $this->log->write($message,$this->log->FATAL);
1444 $this->ilErr->raiseError($message,$this->ilErr->WARNING);
1445 }
1446 }
1447
1448 // BEGIN WebDAV: Pass tree id to this method
1449 $query = 'SELECT * FROM '.$this->table_tree.' '.
1450 $this->buildJoin().
1451 'WHERE '.$this->table_tree.'.child = %s '.
1452 'AND '.$this->table_tree.'.'.$this->tree_pk.' = %s ';
1453 $res = $ilDB->queryF($query,array('integer','integer'),array(
1454 $a_node_id,
1455 $a_tree_pk === null ? $this->tree_id : $a_tree_pk));
1456 // END WebDAV: Pass tree id to this method
1457 $row = $ilDB->fetchAssoc($res);
1459
1460 return $this->fetchNodeData($row);
1461 }

References $GLOBALS, $ilDB, $query, $res, $row, $tree_id, $tree_pk, __isMainTree(), buildJoin(), and fetchNodeData().

Referenced by ilWorkspaceTree\cascadingDelete(), getFilteredSubTree(), ilWorkspaceTree\getObjectsFromType(), getSubTreeFilteredByObjIds(), and getSubTreeTypes().

+ 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
Deprecated:
since 4.4.0

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

1748 {
1749 global $ilDB;
1750
1751 if(!isset($a_type) or (!is_string($a_type)))
1752 {
1753 $GLOBALS['ilLog']->logStack();
1754 throw new InvalidArgumentException('Type not given or wrong datatype');
1755 }
1756
1757 $query = 'SELECT * FROM ' . $this->table_tree . ' ' .
1758 $this->buildJoin().
1759 'WHERE ' . $this->table_obj_data . '.type = ' . $this->ilDB->quote($a_type, 'text').
1760 'AND ' . $this->table_tree . '.' . $this->tree_pk . ' = ' . $this->ilDB->quote($this->tree_id, 'integer');
1761
1762 $res = $ilDB->query($query);
1763 $data = array();
1764 while($row = $ilDB->fetchAssoc($res))
1765 {
1766 $data[] = $this->fetchNodeData($row);
1767 }
1768
1769 return $data;
1770 }
Database Wrapper.
Definition: class.ilDB.php:29
quote($a_query, $a_type=null)
Wrapper for quote method.

References $data, $GLOBALS, $ilDB, $query, $res, $row, buildJoin(), fetchNodeData(), and ilDB\quote().

+ 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 1194 of file class.ilTree.php.

1195 {
1196 global $ilDB;
1197
1198 $pathIds = $this->getPathId($a_endnode_id, $a_startnode_id);
1199
1200 // Abort if no path ids were found
1201 if (count($pathIds) == 0)
1202 {
1203 return null;
1204 }
1205
1206
1207 $types = array();
1208 $data = array();
1209 for ($i = 0; $i < count($pathIds); $i++)
1210 {
1211 $types[] = 'integer';
1212 $data[] = $pathIds[$i];
1213 }
1214
1215 $query = 'SELECT t.depth,t.parent,t.child,d.obj_id,d.type,d.title '.
1216 'FROM '.$this->table_tree.' t '.
1217 'JOIN '.$this->table_obj_reference.' r ON r.ref_id = t.child '.
1218 'JOIN '.$this->table_obj_data.' d ON d.obj_id = r.obj_id '.
1219 'WHERE '.$ilDB->in('t.child',$data,false,'integer').' '.
1220 'ORDER BY t.depth ';
1221
1222 $res = $ilDB->queryF($query,$types,$data);
1223
1224 $titlePath = array();
1225 while ($row = $ilDB->fetchAssoc($res))
1226 {
1227 $titlePath[] = $row;
1228 }
1229 return $titlePath;
1230 }
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, $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 1071 of file class.ilTree.php.

1072 {
1073 global $ilDB, $log;
1074 //$log->write('getNodePathForTitlePath('.implode('/',$titlePath));
1075
1076 // handle empty title path
1077 if ($titlePath == null || count($titlePath) == 0)
1078 {
1079 if ($a_startnode_id == 0)
1080 {
1081 return null;
1082 }
1083 else
1084 {
1085 return $this->getNodePath($a_startnode_id);
1086 }
1087 }
1088
1089 // fetch the node path up to the startnode
1090 if ($a_startnode_id != null && $a_startnode_id != 0)
1091 {
1092 // Start using the node path to the root of the relative path
1093 $nodePath = $this->getNodePath($a_startnode_id);
1094 $parent = $a_startnode_id;
1095 }
1096 else
1097 {
1098 // Start using the root of the tree
1099 $nodePath = array();
1100 $parent = 0;
1101 }
1102
1103
1104 // Convert title path into Unicode Normal Form C
1105 // This is needed to ensure that we can compare title path strings with
1106 // strings from the database.
1107 require_once('include/Unicode/UtfNormal.php');
1108 include_once './Services/Utilities/classes/class.ilStr.php';
1109 $inClause = 'd.title IN (';
1110 for ($i=0; $i < count($titlePath); $i++)
1111 {
1112 $titlePath[$i] = ilStr::strToLower(UtfNormal::toNFC($titlePath[$i]));
1113 if ($i > 0) $inClause .= ',';
1114 $inClause .= $ilDB->quote($titlePath[$i],'text');
1115 }
1116 $inClause .= ')';
1117
1118 // Fetch all rows that are potential path elements
1119 if ($this->table_obj_reference)
1120 {
1121 $joinClause = 'JOIN '.$this->table_obj_reference.' r ON t.child = r.'.$this->ref_pk.' '.
1122 'JOIN '.$this->table_obj_data.' d ON r.'.$this->obj_pk.' = d.'.$this->obj_pk;
1123 }
1124 else
1125 {
1126 $joinClause = 'JOIN '.$this->table_obj_data.' d ON t.child = d.'.$this->obj_pk;
1127 }
1128 // The ORDER BY clause in the following SQL statement ensures that,
1129 // in case of a multiple objects with the same title, always the Object
1130 // with the oldest ref_id is chosen.
1131 // This ensure, that, if a new object with the same title is added,
1132 // WebDAV clients can still work with the older object.
1133 $q = 'SELECT t.depth, t.parent, t.child, d.'.$this->obj_pk.' obj_id, d.type, d.title '.
1134 'FROM '.$this->table_tree.' t '.
1135 $joinClause.' '.
1136 'WHERE '.$inClause.' '.
1137 'AND t.depth <= '.(count($titlePath)+count($nodePath)).' '.
1138 'AND t.tree = 1 '.
1139 'ORDER BY t.depth, t.child ASC';
1140 $r = $ilDB->query($q);
1141
1142 $rows = array();
1143 while ($row = $r->fetchRow(DB_FETCHMODE_ASSOC))
1144 {
1145 $row['title'] = UtfNormal::toNFC($row['title']);
1146 $row['ref_id'] = $row['child'];
1147 $rows[] = $row;
1148 }
1149
1150 // Extract the path elements from the fetched rows
1151 for ($i = 0; $i < count($titlePath); $i++) {
1152 $pathElementFound = false;
1153 foreach ($rows as $row) {
1154 if ($row['parent'] == $parent &&
1155 ilStr::strToLower($row['title']) == $titlePath[$i])
1156 {
1157 // FIXME - We should test here, if the user has
1158 // 'visible' permission for the object.
1159 $nodePath[] = $row;
1160 $parent = $row['child'];
1161 $pathElementFound = true;
1162 break;
1163 }
1164 }
1165 // Abort if we haven't found a path element for the current depth
1166 if (! $pathElementFound)
1167 {
1168 //$log->write('ilTree.getNodePathForTitlePath('.var_export($titlePath,true).','.$a_startnode_id.'):null');
1169 return null;
1170 }
1171 }
1172 // Return the node path
1173 //$log->write('ilTree.getNodePathForTitlePath('.var_export($titlePath,true).','.$a_startnode_id.'):'.var_export($nodePath,true));
1174 return $nodePath;
1175 }
toNFC( $string)
Convert a UTF-8 string to normal form C, canonical composition.
Definition: UtfNormal.php:157
const DB_FETCHMODE_ASSOC
Definition: class.ilDB.php:10
static strToLower($a_string)
Definition: class.ilStr.php:89
getNodePath($a_endnode_id, $a_startnode_id=0)
Returns the node path for the specified object reference.

References $ilDB, $log, $obj_pk, $row, DB_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 1395 of file class.ilTree.php.

1396 {
1397 global $ilDB;
1398
1399 if(!$a_node_id)
1400 {
1401 $GLOBALS['ilLog']->logStack();
1402 throw new InvalidArgumentException('Missing or empty parameter $a_node_id: '. $a_node_id);
1403 }
1404
1405 $query = 'SELECT * FROM '.$this->table_tree.' '.
1406 'WHERE child = '.$ilDB->quote($a_node_id,'integer');
1407 $res = $ilDB->query($query);
1408 while($row = $res->fetchRow(DB_FETCHMODE_ASSOC))
1409 {
1410 return $row;
1411 }
1412 return array();
1413 }

References $GLOBALS, $ilDB, $query, $res, $row, and DB_FETCHMODE_ASSOC.

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

+ Here is the caller graph for this function:

◆ getObjectDataTable()

ilTree::getObjectDataTable ( )

Get object data table.

Returns
type

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

326 {
328 }

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 288 of file class.ilTree.php.

289 {
290 return (array) $this->parent_cache;
291 }

References $parent_cache.

◆ getParentId()

ilTree::getParentId (   $a_node_id)

get parent id of given node @access public

Parameters
integernode id
Returns
integer parent id

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

2027 {
2028 global $ilDB;
2029
2030 if (!isset($a_node_id))
2031 {
2032 $this->ilErr->raiseError(get_class($this)."::getParentId(): No node_id given! ",$this->ilErr->WARNING);
2033 }
2034
2035 $query = 'SELECT parent FROM '.$this->table_tree.' '.
2036 'WHERE child = %s '.
2037 'AND '.$this->tree_pk.' = %s ';
2038 $res = $ilDB->queryF($query,array('integer','integer'),array(
2039 $a_node_id,
2040 $this->tree_id));
2041
2042 $row = $ilDB->fetchObject($res);
2043 return $row->parent;
2044 }

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

◆ 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 1642 of file class.ilTree.php.

1643 {
1644 global $ilDB;
1645 global $ilLog;
1646
1647 if (!isset($a_node_id))
1648 {
1649 $ilLog->logStack();
1650 throw new InvalidArgumentException(__METHOD__.': No node_id given!');
1651 }
1652
1653 if ($this->table_obj_reference)
1654 {
1655 // Use inner join instead of left join to improve performance
1656 $innerjoin = "JOIN ".$this->table_obj_reference." ON v.child=".$this->table_obj_reference.".".$this->ref_pk." ".
1657 "JOIN ".$this->table_obj_data." ON ".$this->table_obj_reference.".".$this->obj_pk."=".$this->table_obj_data.".".$this->obj_pk." ";
1658 }
1659 else
1660 {
1661 // Use inner join instead of left join to improve performance
1662 $innerjoin = "JOIN ".$this->table_obj_data." ON v.child=".$this->table_obj_data.".".$this->obj_pk." ";
1663 }
1664
1665 $query = 'SELECT * FROM '.$this->table_tree.' s, '.$this->table_tree.' v '.
1666 $innerjoin.
1667 'WHERE s.child = %s '.
1668 'AND s.parent = v.child '.
1669 'AND s.'.$this->tree_pk.' = %s '.
1670 'AND v.'.$this->tree_pk.' = %s';
1671 $res = $ilDB->queryF($query,array('integer','integer','integer'),array(
1672 $a_node_id,
1673 $this->tree_id,
1674 $this->tree_id));
1675 $row = $ilDB->fetchAssoc($res);
1676 return $this->fetchNodeData($row);
1677 }

References $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 948 of file class.ilTree.php.

949 {
950 $pathIds =& $this->getPathId($a_endnode_id, $a_startnode_id);
951
952 // We retrieve the full path in a single query to improve performance
953 global $ilDB;
954
955 // Abort if no path ids were found
956 if (count($pathIds) == 0)
957 {
958 return null;
959 }
960
961 $inClause = 'child IN (';
962 for ($i=0; $i < count($pathIds); $i++)
963 {
964 if ($i > 0) $inClause .= ',';
965 $inClause .= $ilDB->quote($pathIds[$i],'integer');
966 }
967 $inClause .= ')';
968
969 $q = 'SELECT * '.
970 'FROM '.$this->table_tree.' '.
971 $this->buildJoin().' '.
972 'WHERE '.$inClause.' '.
973 'AND '.$this->table_tree.'.'.$this->tree_pk.' = '.$this->ilDB->quote($this->tree_id,'integer').' '.
974 'ORDER BY depth';
975 $r = $ilDB->query($q);
976
977 $pathFull = array();
978 while ($row = $r->fetchRow(DB_FETCHMODE_ASSOC))
979 {
980 $pathFull[] = $this->fetchNodeData($row);
981
982 // Update cache
983 if ($this->__isMainTree())
984 {
985 #$GLOBALS['ilLog']->write(__METHOD__.': Storing in tree cache '.$row['child']);
986 $this->in_tree_cache[$row['child']] = $row['tree'] == 1;
987 }
988 }
989 return $pathFull;
990 }

References $ilDB, $row, __isMainTree(), buildJoin(), DB_FETCHMODE_ASSOC, fetchNodeData(), getPathId(), and ilDB\quote().

Referenced by checkForParentType(), 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 1028 of file class.ilTree.php.

1029 {
1030 if(!$a_endnode_id)
1031 {
1032 $GLOBALS['ilLog']->logStack();
1033 throw new InvalidArgumentException(__METHOD__.': No endnode given!');
1034 }
1035
1036 // path id cache
1037 if ($this->isCacheUsed() && isset($this->path_id_cache[$a_endnode_id][$a_startnode_id]))
1038 {
1039//echo "<br>getPathIdhit";
1040 return $this->path_id_cache[$a_endnode_id][$a_startnode_id];
1041 }
1042//echo "<br>miss";
1043
1044 $pathIds = $this->getTreeImplementation()->getPathIds($a_endnode_id, $a_startnode_id);
1045
1046 if($this->__isMainTree())
1047 {
1048 $this->path_id_cache[$a_endnode_id][$a_startnode_id] = $pathIds;
1049 }
1050 return $pathIds;
1051 }

References $GLOBALS, __isMainTree(), 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 2660 of file class.ilTree.php.

2661 {
2662 return $this->getTreeImplementation()->getSubtreeInfo($a_endnode_id);
2663 }

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 471 of file class.ilTree.php.

472 {
473 return $this->getRelationOfNodes(
474 $this->getNodeTreeData($a_node_a),
475 $this->getNodeTreeData($a_node_b)
476 );
477 }
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 485 of file class.ilTree.php.

486 {
487 return $this->getTreeImplementation()->getRelation($a_node_a_arr, $a_node_b_arr);
488 }

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 2145 of file class.ilTree.php.

2146 {
2147 return $this->root_id;
2148 }

References $root_id.

Referenced by ilWorkspaceTree\getObjectsFromType().

+ 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

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

1973 {
1974 global $ilDB;
1975
1976 if (!isset($a_parent_id))
1977 {
1978 $this->ilErr->raiseError(get_class($this)."::getSavedNodeData(): No node_id given!",$this->ilErr->WARNING);
1979 }
1980
1981 $query = 'SELECT * FROM '.$this->table_tree.' '.
1982 $this->buildJoin().
1983 'WHERE '.$this->table_tree.'.'.$this->tree_pk.' < %s '.
1984 'AND '.$this->table_tree.'.parent = %s';
1985 $res = $ilDB->queryF($query,array('integer','integer'),array(
1986 0,
1987 $a_parent_id));
1988
1989 while($row = $ilDB->fetchAssoc($res))
1990 {
1991 $saved[] = $this->fetchNodeData($row);
1992 }
1993
1994 return $saved ? $saved : array();
1995 }

References $ilDB, $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 2003 of file class.ilTree.php.

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

References $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 834 of file class.ilTree.php.

835 {
836 global $ilDB;
837
838 if (!is_array($a_node))
839 {
840 $GLOBALS['ilLog']->logStack();
841 throw new InvalidArgumentException(__METHOD__.': wrong datatype for node data given');
842 }
843
844 /*
845 if($a_node['lft'] < 1 or $a_node['rgt'] < 2)
846 {
847 $GLOBALS['ilLog']->logStack();
848 $message = sprintf('%s: Invalid node given! $a_node["lft"]: %s $a_node["rgt"]: %s',
849 __METHOD__,
850 $a_node['lft'],
851 $a_node['rgt']);
852
853 throw new InvalidArgumentException($message);
854 }
855 */
856
857 $query = $this->getTreeImplementation()->getSubTreeQuery($a_node, $a_type);
858 $res = $ilDB->query($query);
859 while($row = $ilDB->fetchAssoc($res))
860 {
861 if($a_with_data)
862 {
863 $subtree[] = $this->fetchNodeData($row);
864 }
865 else
866 {
867 $subtree[] = $row['child'];
868 }
869 // the lm_data "hack" should be removed in the trunk during an alpha
870 if($this->__isMainTree() || $this->table_tree == "lm_tree")
871 {
872 $this->in_tree_cache[$row['child']] = true;
873 }
874 }
875 return $subtree ? $subtree : array();
876 }

References $GLOBALS, $ilDB, $query, $res, $row, __isMainTree(), fetchNodeData(), and getTreeImplementation().

Referenced by ilWorkspaceTree\cascadingDelete(), getFilteredSubTree(), and ilWorkspaceTree\getObjectsFromType().

+ 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 2691 of file class.ilTree.php.

2692 {
2693 global $ilDB;
2694
2695 $node = $this->getNodeData($a_node_id);
2696 if(!sizeof($node))
2697 {
2698 return;
2699 }
2700
2701 $res = array();
2702
2703 $query = $this->getTreeImplementation()->getSubTreeQuery($node, '', true, array($this->ref_pk));
2704
2705 $fields = '*';
2706 if(count($a_fields))
2707 {
2708 $fields = implode(',',$a_fields);
2709 }
2710
2711 $query = "SELECT ".$fields.
2712 " FROM ".$this->getTreeTable().
2713 " ".$this->buildJoin().
2714 " WHERE ".$this->getTableReference().".".$this->ref_pk." IN (".$query.")".
2715 " AND ".$ilDB->in($this->getObjectDataTable().".".$this->obj_pk, $a_obj_ids, "", "integer");
2716 $set = $ilDB->query($query);
2717 while($row = $ilDB->fetchAssoc($set))
2718 {
2719 $res[] = $row;
2720 }
2721
2722 return $res;
2723 }
getObjectDataTable()
Get object data table.

References $ilDB, $query, $res, $row, getNodeData(), getObjectDataTable(), and getTreeImplementation().

+ 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 819 of file class.ilTree.php.

820 {
821 return $this->getTreeImplementation()->getSubTreeIds($a_ref_id);
822 }

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 2673 of file class.ilTree.php.

2674 {
2675 return $this->getTreeImplementation()->getSubTreeQuery(
2676 $this->getNodeTreeData($a_node_id),
2677 $a_types,
2678 $a_force_join_reference,
2679 $a_fields);
2680 }

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 886 of file class.ilTree.php.

887 {
888 $a_filter = $a_filter ? $a_filter : array();
889
890 foreach($this->getSubtree($this->getNodeData($a_node)) as $node)
891 {
892 if(in_array($node["type"],$a_filter))
893 {
894 continue;
895 }
896 $types["$node[type]"] = $node["type"];
897 }
898 return $types ? $types : array();
899 }

References getNodeData().

+ Here is the call graph for this function:

◆ getTableReference()

ilTree::getTableReference ( )

Get reference table if available.

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

343 {
345 }
$table_obj_reference

References $table_obj_reference.

◆ getTreeId()

ilTree::getTreeId ( )

get tree id @access public

Returns
integer tree id

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

2160 {
2161 return $this->tree_id;
2162 }

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 253 of file class.ilTree.php.

254 {
255 return $this->tree_impl;
256 }

References $tree_impl.

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

+ Here is the caller graph for this function:

◆ getTreePk()

ilTree::getTreePk ( )

Get tree primary key.

Returns
string column of pk

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

335 {
336 return $this->tree_pk;
337 }

References $tree_pk.

◆ getTreeTable()

ilTree::getTreeTable ( )

Get tree table name.

Returns
string tree table name

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

317 {
318 return $this->table_tree;
319 }

References $table_tree.

◆ ilTree()

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

Constructor @access public.

Parameters
integer$a_tree_idtree_id
integer$a_root_idroot_id (optional)

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

148 {
149 global $ilDB,$ilErr,$ilias,$ilLog;
150
151 // set db & error handler
152 $this->ilDB = $ilDB;
153
154 if (!isset($ilErr))
155 {
156 $ilErr = new ilErrorHandling();
157 $ilErr->setErrorHandling(PEAR_ERROR_CALLBACK,array($ilErr,'errorHandler'));
158 }
159 else
160 {
161 $this->ilErr = $ilErr;
162 }
163
164 $this->lang_code = "en";
165
166 if (!isset($a_tree_id) or (func_num_args() == 0) )
167 {
168 $this->ilErr->raiseError(get_class($this)."::Constructor(): No tree_id given!",$this->ilErr->WARNING);
169 }
170
171 if (func_num_args() > 2)
172 {
173 $this->ilErr->raiseError(get_class($this)."::Constructor(): Wrong parameter count!",$this->ilErr->WARNING);
174 }
175
176 // CREATE LOGGER INSTANCE
177 $this->log = $ilLog;
178
179 //init variables
180 if (empty($a_root_id))
181 {
182 $a_root_id = ROOT_FOLDER_ID;
183 }
184
185 $this->tree_id = $a_tree_id;
186 $this->root_id = $a_root_id;
187 $this->table_tree = 'tree';
188 $this->table_obj_data = 'object_data';
189 $this->table_obj_reference = 'object_reference';
190 $this->ref_pk = 'ref_id';
191 $this->obj_pk = 'obj_id';
192 $this->tree_pk = 'tree';
193
194 $this->use_cache = true;
195
196 // If cache is activated, cache object translations to improve performance
197 $this->translation_cache = array();
198 $this->parent_type_cache = array();
199
200 // By default, we create gaps in the tree sequence numbering for 50 nodes
201 $this->gap = 50;
202
203
204 // init tree implementation
205 $this->initTreeImplementation();
206 }
const PEAR_ERROR_CALLBACK
Definition: PEAR.php:35
Error Handling & global info handling uses PEAR error class.
initTreeImplementation()
Init tree implementation.

References $ilDB, $ilErr, $ilias, $ilLog, initTreeImplementation(), and PEAR_ERROR_CALLBACK.

+ Here is the call graph for this function:

◆ initLangCode()

ilTree::initLangCode ( )

Store user language.

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

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

298 {
299 global $ilUser;
300
301 // lang_code is only required in $this->fetchnodedata
302 if (!is_object($ilUser))
303 {
304 $this->lang_code = "en";
305 }
306 else
307 {
308 $this->lang_code = $ilUser->getCurrentLanguage();
309 }
310 }

References $ilUser.

◆ initTreeImplementation()

ilTree::initTreeImplementation ( )

Init tree implementation.

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

212 {
213 global $ilDB;
214
215
216 if(!is_object($GLOBALS['ilSetting']) or $GLOBALS['ilSetting']->getModule() != 'common')
217 {
218 include_once './Services/Administration/classes/class.ilSetting.php';
219 $setting = new ilSetting('common');
220 }
221 else
222 {
223 $setting = $GLOBALS['ilSetting'];
224 }
225
226 if($this->__isMainTree())
227 {
228 if($setting->get('main_tree_impl','ns') == 'ns')
229 {
230 #$GLOBALS['ilLog']->write(__METHOD__.': Using nested set.');
231 include_once './Services/Tree/classes/class.ilNestedSetTree.php';
232 $this->tree_impl = new ilNestedSetTree($this);
233 }
234 else
235 {
236 #$GLOBALS['ilLog']->write(__METHOD__.': Using materialized path.');
237 include_once './Services/Tree/classes/class.ilMaterializedPathTree.php';
238 $this->tree_impl = new ilMaterializedPathTree($this);
239 }
240 }
241 else
242 {
243 #$GLOBALS['ilLog']->write(__METHOD__.': Using netsted set for non main tree.');
244 include_once './Services/Tree/classes/class.ilNestedSetTree.php';
245 $this->tree_impl = new ilNestedSetTree($this);
246 }
247 }
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 $GLOBALS, $ilDB, and __isMainTree().

Referenced by ilTree(), 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

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

734 {
735 global $ilDB;
736
737//echo "+$a_node_id+$a_parent_id+";
738 // CHECK node_id and parent_id > 0 if in main tree
739 if($this->__isMainTree())
740 {
741 if($a_node_id <= 1 or $a_parent_id <= 0)
742 {
743 $GLOBALS['ilLog']->logStack();
744 $message = sprintf('%s::insertNode(): Invalid parameters! $a_node_id: %s $a_parent_id: %s',
745 get_class($this),
746 $a_node_id,
747 $a_parent_id);
748 $this->log->write($message,$this->log->FATAL);
749 $this->ilErr->raiseError($message,$this->ilErr->WARNING);
750 }
751 }
752
753
754 if (!isset($a_node_id) or !isset($a_parent_id))
755 {
756 $GLOBALS['ilLog']->logStack();
757 $this->ilErr->raiseError(get_class($this)."::insertNode(): Missing parameter! ".
758 "node_id: ".$a_node_id." parent_id: ".$a_parent_id,$this->ilErr->WARNING);
759 }
760 if ($this->isInTree($a_node_id))
761 {
762 $this->ilErr->raiseError(get_class($this)."::insertNode(): Node ".$a_node_id." already in tree ".
763 $this->table_tree."!",$this->ilErr->WARNING);
764 }
765
766 $this->getTreeImplementation()->insertNode($a_node_id, $a_parent_id, $a_pos);
767
768 $this->in_tree_cache[$a_node_id] = true;
769
770 // reset deletion date
771 if ($a_reset_deletion_date)
772 {
773 ilObject::_resetDeletedDate($a_node_id);
774 }
775 }
_resetDeletedDate($a_ref_id)
only called in ilObjectGUI::insertSavedNodes

References $GLOBALS, $ilDB, __isMainTree(), ilObject\_resetDeletedDate(), getTreeImplementation(), and isInTree().

Referenced by ilWorkspaceTree\insertObject().

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

◆ isCacheUsed()

ilTree::isCacheUsed ( )

Check if cache is active.

Returns
bool

Reimplemented in ilLMTree.

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

271 {
272 return $this->__isMainTree() and $this->use_cache;
273 }

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 1883 of file class.ilTree.php.

1884 {
1885 return $this->isSaved($a_node_id);
1886 }
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 1686 of file class.ilTree.php.

1687 {
1688 return $this->getRelation($a_startnode_id, $a_querynode_id) == self::RELATION_PARENT;
1689 }
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 1590 of file class.ilTree.php.

1591 {
1592 global $ilDB;
1593
1594 if (!isset($a_node_id))
1595 {
1596 return false;
1597 #$this->ilErr->raiseError(get_class($this)."::getNodeData(): No node_id given! ",$this->ilErr->WARNING);
1598 }
1599 // is in tree cache
1600 if ($this->isCacheUsed() && isset($this->in_tree_cache[$a_node_id]))
1601 {
1602 #$GLOBALS['ilLog']->write(__METHOD__.': Using in tree cache '.$a_node_id);
1603//echo "<br>in_tree_hit";
1604 return $this->in_tree_cache[$a_node_id];
1605 }
1606
1607 $query = 'SELECT * FROM '.$this->table_tree.' '.
1608 'WHERE '.$this->table_tree.'.child = %s '.
1609 'AND '.$this->table_tree.'.'.$this->tree_pk.' = %s';
1610
1611 $res = $ilDB->queryF($query,array('integer','integer'),array(
1612 $a_node_id,
1613 $this->tree_id));
1614
1615 if ($res->numRows() > 0)
1616 {
1617 if($this->__isMainTree())
1618 {
1619 #$GLOBALS['ilLog']->write(__METHOD__.': Storing in tree cache '.$a_node_id.' = true');
1620 $this->in_tree_cache[$a_node_id] = true;
1621 }
1622 return true;
1623 }
1624 else
1625 {
1626 if($this->__isMainTree())
1627 {
1628 #$GLOBALS['ilLog']->write(__METHOD__.': Storing in tree cache '.$a_node_id.' = false');
1629 $this->in_tree_cache[$a_node_id] = false;
1630 }
1631 return false;
1632 }
1633 }

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

Referenced by checkForParentType(), and insertNode().

+ 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 1893 of file class.ilTree.php.

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

References $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:

◆ moveToTrash()

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

Wrapper for saveSubTree.

Parameters
type$a_node_id
type$a_set_deleted
Exceptions
InvalidArgumentException

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

1808 {
1809 return $this->saveSubTree($a_node_id, $a_set_deleted);
1810 }
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 $t...

References saveSubTree().

+ Here is the call 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)

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

2637 {
2638 $this->getTreeImplementation()->moveTree($a_source_id,$a_target_id,$a_location);
2639 $GLOBALS['ilAppEventHandler']->raise(
2640 "Services/Tree",
2641 "moveTree",
2642 array(
2643 'tree' => $this->table_tree,
2644 'source_id' => $a_source_id,
2645 'target_id' => $a_target_id)
2646 );
2647 return true;
2648 }

References $GLOBALS, 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 1933 of file class.ilTree.php.

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

References $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 999 of file class.ilTree.php.

1000 {
1001 global $ilDB;
1002
1003 if (!$this->__isMainTree() || !is_array($a_node_ids) || !$this->isCacheUsed())
1004 {
1005 return;
1006 }
1007
1008 $res = $ilDB->query('SELECT t.depth, t.parent, t.child '.
1009 'FROM '.$this->table_tree.' t '.
1010 'WHERE '.$ilDB->in("child", $a_node_ids, false, "integer").
1011 'AND '.$this->tree_pk.' = '.$ilDB->quote($this->tree_id, "integer"));
1012 while ($row = $ilDB->fetchAssoc($res))
1013 {
1014 $this->depth_cache[$row["child"]] = $row["depth"];
1015 $this->parent_cache[$row["child"]] = $row["parent"];
1016 }
1017 }

References $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 2125 of file class.ilTree.php.

2126 {
2127 global $ilDB;
2128
2129 $query = 'SELECT child FROM '.$this->table_tree.' '.
2130 'WHERE parent = %s '.
2131 'AND '.$this->tree_pk.' = %s ';
2132 $res = $ilDB->queryF($query,array('integer','integer'),array(
2133 0,
2134 $this->tree_id));
2135 $row = $ilDB->fetchObject($res);
2136 $this->root_id = $row->child;
2137 return $this->root_id;
2138 }

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

Referenced by ilWorkspaceTree\__construct(), ilWorkspaceExplorer\__construct(), ilWorkspaceTree\cascadingDelete(), and ilWorkspaceAccessHandler\checkAccessOfUser().

+ 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

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

1780 {
1781 global $ilDB;
1782
1783 // OPERATION NOT ALLOWED ON MAIN TREE
1784 if($this->__isMainTree())
1785 {
1786 $GLOBALS['ilLog']->logStack();
1787 throw new InvalidArgumentException('Operation not allowed on main tree');
1788 }
1789 if (!$a_tree_id)
1790 {
1791 $GLOBALS['ilLog']->logStack();
1792 throw new InvalidArgumentException('Missing parameter tree id');
1793 }
1794
1795 $query = 'DELETE FROM '.$this->table_tree.
1796 ' WHERE '.$this->tree_pk.' = %s ';
1797 $ilDB->manipulateF($query,array('integer'),array($a_tree_id));
1798 return true;
1799 }

References $GLOBALS, $ilDB, $query, and __isMainTree().

+ 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 2309 of file class.ilTree.php.

2310 {
2311 global $ilDB;
2312
2313 // LOCKED ###################################
2314 if($this->__isMainTree())
2315 {
2316 /*
2317 ilDB::_lockTables(array($this->table_tree => 'WRITE',
2318 $this->table_obj_data => 'WRITE',
2319 $this->table_obj_reference => 'WRITE',
2320 'object_translation' => 'WRITE',
2321 'object_data od' => 'WRITE',
2322 'container_reference cr' => 'WRITE'));
2323 */
2324 $ilDB->lockTables(
2325 array(
2326 0 => array('name' => $this->table_tree, 'type' => ilDB::LOCK_WRITE),
2327 1 => array('name' => $this->table_obj_data, 'type' => ilDB::LOCK_WRITE),
2328 2 => array('name' => $this->table_obj_reference, 'type' => ilDB::LOCK_WRITE),
2329 3 => array('name' => 'object_translation', 'type' => ilDB::LOCK_WRITE),
2330 4 => array('name' => 'object_data', 'type' => ilDB::LOCK_WRITE, 'alias' => 'od'),
2331 5 => array('name' => 'container_reference', 'type' => ilDB::LOCK_WRITE, 'alias' => 'cr')
2332 ));
2333 }
2334 $return = $this->__renumber($node_id,$i);
2335 if($this->__isMainTree())
2336 {
2337 $ilDB->unlockTables();
2338 }
2339 // LOCKED ###################################
2340 return $return;
2341 }
const LOCK_WRITE
Definition: class.ilDB.php:30

References $ilDB, __isMainTree(), __renumber(), and ilDB\LOCK_WRITE.

+ Here is the call graph for this function:

◆ resetInTreeCache()

ilTree::resetInTreeCache ( )

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

359 {
360 $this->in_tree_cache = array();
361 }

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 1822 of file class.ilTree.php.

1823 {
1824 global $ilDB;
1825
1826 if(!$a_node_id)
1827 {
1828 $GLOBALS['ilLog']->logStack();
1829 throw new InvalidArgumentException('No valid parameter given! $a_node_id: '.$a_node_id);
1830 }
1831
1832 // LOCKED ###############################################
1833 if($this->__isMainTree())
1834 {
1835 $ilDB->lockTables(
1836 array(
1837 0 => array('name' => 'tree', 'type' => ilDB::LOCK_WRITE),
1838 1 => array('name' => 'object_reference', 'type' => ilDB::LOCK_WRITE)));
1839 }
1840
1841 $query = $this->getTreeImplementation()->getSubTreeQuery($this->getNodeTreeData($a_node_id),'',false);
1842 $res = $ilDB->query($query);
1843
1844 $subnodes = array();
1845 while($row = $res->fetchRow(DB_FETCHMODE_ASSOC))
1846 {
1847 $subnodes[] = $row['child'];
1848 }
1849
1850 if(!count($subnodes))
1851 {
1852 // Possibly already deleted
1853 // Unlock locked tables before returning
1854 if($this->__isMainTree())
1855 {
1856 $ilDB->unlockTables();
1857 }
1858 return false;
1859 }
1860
1861 if($a_set_deleted)
1862 {
1863 include_once './Services/Object/classes/class.ilObject.php';
1864 ilObject::setDeletedDates($subnodes);
1865 }
1866
1867 // netsted set <=> mp
1868 $this->getTreeImplementation()->moveToTrash($a_node_id);
1869
1870 if($this->__isMainTree())
1871 {
1872 $ilDB->unlockTables();
1873 }
1874
1875 // LOCKED ###############################################
1876 return true;
1877 }
static setDeletedDates($a_ref_ids)
Set deleted date @global type $ilDB.

References $GLOBALS, $ilDB, $query, $res, $row, __isMainTree(), DB_FETCHMODE_ASSOC, getNodeTreeData(), getTreeImplementation(), ilDB\LOCK_WRITE, and ilObject\setDeletedDates().

Referenced by moveToTrash().

+ Here is the call graph for this function:
+ Here is the caller 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

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

419 {
420 if (!isset($a_column_name))
421 {
422 $this->ilErr->raiseError(get_class($this)."::setObjectTablePK(): No column name given!",$this->ilErr->WARNING);
423 }
424
425 $this->obj_pk = $a_column_name;
426 return true;
427 }

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

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

402 {
403 if (!isset($a_column_name))
404 {
405 $this->ilErr->raiseError(get_class($this)."::setReferenceTablePK(): No column name given!",$this->ilErr->WARNING);
406 }
407
408 $this->ref_pk = $a_column_name;
409 return true;
410 }

Referenced by ilWorkspaceTree\__construct().

+ Here is the caller graph for this function:

◆ setRootId()

ilTree::setRootId (   $a_root_id)

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

2150 {
2151 $this->root_id = $a_root_id;
2152 }

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

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

379 {
380 if (!isset($a_table_tree) or !isset($a_table_obj_data))
381 {
382 $this->ilErr->raiseError(get_class($this)."::setTableNames(): Missing parameter! ".
383 "tree table: ".$a_table_tree." object data table: ".$a_table_obj_data,$this->ilErr->WARNING);
384 }
385
386 $this->table_tree = $a_table_tree;
387 $this->table_obj_data = $a_table_obj_data;
388 $this->table_obj_reference = $a_table_obj_reference;
389
390 $this->initTreeImplementation();
391
392 return true;
393 }

References initTreeImplementation().

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

+ 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 2169 of file class.ilTree.php.

2170 {
2171 $this->tree_id = $a_tree_id;
2172 }

◆ 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

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

436 {
437 if (!isset($a_column_name))
438 {
439 $this->ilErr->raiseError(get_class($this)."::setTreeTablePK(): No column name given!",$this->ilErr->WARNING);
440 }
441
442 $this->tree_pk = $a_column_name;
443 return true;
444 }

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

+ Here is the caller graph for this function:

◆ useCache()

ilTree::useCache (   $a_use = true)

Use Cache (usually activated)

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

262 {
263 $this->use_cache = $a_use;
264 }

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

+ Here is the caller 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
Size of the gaps to be created in the nested sets sequence numbering of the

tree nodes. Having gaps in the tree greatly improves performance on all operations that add or remove tree nodes.

Setting this to zero will leave no gaps in the tree. Setting this to a value larger than zero will create gaps in the tree. Each gap leaves room in the sequence numbering for the specified number of nodes. (The gap is expressed as the number of nodes. Since each node consumes two sequence numbers, specifying a gap of 1 will leave space for 2 sequence numbers.)

A gap is created, when a new child is added to a node, and when not
enough room between node.rgt and the child with the highest node.rgt value 
of the node is available.
A gap is closed, when a node is removed and when (node.rgt - node.lft) 
is bigger than gap * 2.


@var                integer
@access     private

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

Referenced by getGap().

◆ $ilias

ilTree::$ilias

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

Referenced by ilTree().

◆ $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

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

Referenced by getNodePathForTitlePath(), and ilWorkspaceTree\lookupObjectId().

◆ $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 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

const ilTree::RELATION_CHILD = 1

◆ RELATION_EQUALS

const ilTree::RELATION_EQUALS = 4

◆ RELATION_NONE

const ilTree::RELATION_NONE = 5

◆ RELATION_PARENT

const ilTree::RELATION_PARENT = 2

◆ RELATION_SIBLING

const ilTree::RELATION_SIBLING = 3

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