ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
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;
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()) {
32  $this->orderingFieldName = 'order_nr';
33  break;
34 
36  default:
37  $this->orderingFieldName = 'title';
38  }
39 
40  $this->allNodes = $this->getSubTree($this->getNodeData($this->getRootId()));
41  $this->maxOrderValueLength = $this->getMaxOrderValueLength($this->allNodes);
42  }
43 
44  public function getNodeOrderingPathString($nodeId)
45  {
46  $pathNodes = $this->getPathNodes($nodeId);
47 
48  $pathString = '';
49 
50  foreach ($pathNodes as $n) {
51  if (strlen($pathString)) {
52  $pathString .= '-';
53  }
54 
55  switch ($this->orderingFieldName) {
56  case 'order_nr':
57  $pathString .= sprintf("%0{$this->maxOrderValueLength}d", (int) $n[$this->orderingFieldName]);
58  break;
59  case 'title':
60  default:
61  $pathString .= $n[$this->orderingFieldName];
62  }
63  }
64 
65  return $pathString;
66  }
67 
68  protected function getPathNodes($nodeId)
69  {
70  if (!isset($this->pathNodesByNodeCache[$nodeId])) {
71  $this->pathNodesByNodeCache[$nodeId] = $this->getPathFull($nodeId);
72  }
73 
74  return $this->pathNodesByNodeCache[$nodeId];
75  }
76 
77  protected function getMaxOrderValueLength($nodes)
78  {
79  $length = 0;
80 
81  foreach ($nodes as $n) {
82  $l = strlen($n[$this->orderingFieldName]);
83 
84  if ($l > $length) {
85  $length = $l;
86  }
87  }
88 
89  return $length;
90  }
91 }
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:85
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