ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
class.ilTestTaxonomyTree.php
Go to the documentation of this file.
1<?php
2
3/* Copyright (c) 1998-2013 ILIAS open source, Extended GPL, see docs/LICENSE */
4
5require_once 'Services/Taxonomy/classes/class.ilTaxonomyTree.php';
6
16{
17 private $allNodes = array();
19 private $pathNodesByNodeCache = array();
21
22 public function __construct($taxonomyId)
23 {
24 parent::__construct($taxonomyId);
25 $this->readRootId();
26 }
27
28 public function initOrderedTreeIndex(ilObjTaxonomy $taxonomy)
29 {
30 switch($taxonomy->getSortingMode())
31 {
33 $this->orderingFieldName = 'order_nr';
34 break;
35
37 default:
38 $this->orderingFieldName = 'title';
39 }
40
41 $this->allNodes = $this->getSubTree($this->getNodeData($this->getRootId()));
42 $this->maxOrderValueLength = $this->getMaxOrderValueLength($this->allNodes);
43 }
44
45 public function getNodeOrderingPathString($nodeId)
46 {
47 $pathNodes = $this->getPathNodes($nodeId);
48
49 $pathString = '';
50
51 foreach($pathNodes as $n)
52 {
53 if( strlen($pathString) )
54 {
55 $pathString .= '-';
56 }
57
58 switch($this->orderingFieldName)
59 {
60 case 'order_nr':
61 $pathString .= sprintf("%0{$this->maxOrderValueLength}d", (int)$n[$this->orderingFieldName]);
62 break;
63 case 'title':
64 default:
65 $pathString .= $n[$this->orderingFieldName];
66 }
67
68
69 }
70
71 return $pathString;
72 }
73
74 protected function getPathNodes($nodeId)
75 {
76 if( !isset($this->pathNodesByNodeCache[$nodeId]) )
77 {
78 $this->pathNodesByNodeCache[$nodeId] = $this->getPathFull($nodeId);
79 }
80
81 return $this->pathNodesByNodeCache[$nodeId];
82 }
83
84 protected function getMaxOrderValueLength($nodes)
85 {
86 $length = 0;
87
88 foreach($nodes as $n)
89 {
90 $l = strlen($n[$this->orderingFieldName]);
91
92 if( $l > $length )
93 {
94 $length = $l;
95 }
96 }
97
98 return $length;
99 }
100}
$n
Definition: RandomTest.php:80
global $l
Definition: afr.php:30
getSortingMode()
Get sorting mode.
initOrderedTreeIndex(ilObjTaxonomy $taxonomy)
getSubTree($a_node, $a_with_data=true, $a_type="")
get all nodes in the subtree under specified node
readRootId()
read root id from database
getNodeData($a_node_id, $a_tree_pk=null)
get all information of a node.
getRootId()
get the root id of tree @access public
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...