ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilTestTaxonomyTree.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
30{
31 private $allNodes = [];
35
36 public function __construct($taxonomyId)
37 {
38 parent::__construct($taxonomyId);
39 $this->readRootId();
40 }
41
42 public function initOrderedTreeIndex(ilObjTaxonomy $taxonomy)
43 {
44 switch ($taxonomy->getSortingMode()) {
46 $this->orderingFieldName = 'order_nr';
47 break;
48
50 default:
51 $this->orderingFieldName = 'title';
52 }
53
54 $this->allNodes = $this->getSubTree($this->getNodeData($this->getRootId()));
55 $this->maxOrderValueLength = $this->getMaxOrderValueLength($this->allNodes);
56 }
57
58 public function getNodeOrderingPathString($nodeId): string
59 {
60 $pathNodes = $this->getPathNodes($nodeId);
61
62 $pathString = '';
63
64 foreach ($pathNodes as $n) {
65 if (strlen($pathString)) {
66 $pathString .= '-';
67 }
68
69 switch ($this->orderingFieldName) {
70 case 'order_nr':
71 $pathString .= sprintf("%0{$this->maxOrderValueLength}d", (int) $n[$this->orderingFieldName]);
72 break;
73 case 'title':
74 default:
75 $pathString .= $n[$this->orderingFieldName];
76 }
77 }
78
79 return $pathString;
80 }
81
82 protected function getPathNodes($nodeId)
83 {
84 if (!isset($this->pathNodesByNodeCache[$nodeId])) {
85 $this->pathNodesByNodeCache[$nodeId] = $this->getPathFull($nodeId);
86 }
87
88 return $this->pathNodesByNodeCache[$nodeId];
89 }
90
91 protected function getMaxOrderValueLength($nodes): int
92 {
93 $length = 0;
94
95 foreach ($nodes as $n) {
96 $l = strlen($n[$this->orderingFieldName]);
97
98 if ($l > $length) {
99 $length = $l;
100 }
101 }
102
103 return $length;
104 }
105}
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