ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
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 
5 require_once 'Services/Taxonomy/classes/class.ilTaxonomyTree.php';
6 
16 {
17  private $allNodes = array();
18  private $maxOrderValueLength = 1;
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 }
initOrderedTreeIndex(ilObjTaxonomy $taxonomy)
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...
getRootId()
get the root id of tree public
getNodeData($a_node_id, $a_tree_pk=null)
get all information of a node.
$n
Definition: RandomTest.php:80
Create styles array
The data for the language used.
global $l
Definition: afr.php:30
getSubTree($a_node, $a_with_data=true, $a_type="")
get all nodes in the subtree under specified node
getSortingMode()
Get sorting mode.
readRootId()
read root id from database