ILIAS  release_8 Revision v8.24
class.ilTestTaxonomyTree.php
Go to the documentation of this file.
1<?php
2
28{
29 private $allNodes = array();
31 private $pathNodesByNodeCache = array();
33
34 public function __construct($taxonomyId)
35 {
36 parent::__construct($taxonomyId);
37 $this->readRootId();
38 }
39
40 public function initOrderedTreeIndex(ilObjTaxonomy $taxonomy)
41 {
42 switch ($taxonomy->getSortingMode()) {
44 $this->orderingFieldName = 'order_nr';
45 break;
46
48 default:
49 $this->orderingFieldName = 'title';
50 }
51
52 $this->allNodes = $this->getSubTree($this->getNodeData($this->getRootId()));
53 $this->maxOrderValueLength = $this->getMaxOrderValueLength($this->allNodes);
54 }
55
56 public function getNodeOrderingPathString($nodeId): string
57 {
58 $pathNodes = $this->getPathNodes($nodeId);
59
60 $pathString = '';
61
62 foreach ($pathNodes as $n) {
63 if (strlen($pathString)) {
64 $pathString .= '-';
65 }
66
67 switch ($this->orderingFieldName) {
68 case 'order_nr':
69 $pathString .= sprintf("%0{$this->maxOrderValueLength}d", (int) $n[$this->orderingFieldName]);
70 break;
71 case 'title':
72 default:
73 $pathString .= $n[$this->orderingFieldName];
74 }
75 }
76
77 return $pathString;
78 }
79
80 protected function getPathNodes($nodeId)
81 {
82 if (!isset($this->pathNodesByNodeCache[$nodeId])) {
83 $this->pathNodesByNodeCache[$nodeId] = $this->getPathFull($nodeId);
84 }
85
86 return $this->pathNodesByNodeCache[$nodeId];
87 }
88
89 protected function getMaxOrderValueLength($nodes): int
90 {
91 $length = 0;
92
93 foreach ($nodes as $n) {
94 $l = strlen($n[$this->orderingFieldName]);
95
96 if ($l > $length) {
97 $length = $l;
98 }
99 }
100
101 return $length;
102 }
103}
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
initOrderedTreeIndex(ilObjTaxonomy $taxonomy)
getPathFull(int $a_endnode_id, int $a_startnode_id=0)
get path from a given startnode to a given endnode if startnode is not given the rootnode is startnod...
getNodeData(int $a_node_id, ?int $a_tree_pk=null)
get all information of a node.
getSubTree(array $a_node, bool $a_with_data=true, array $a_type=[])
get all nodes in the subtree under specified node
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc