1: <?php
2:
3: 4: 5: 6: 7: 8: 9: 10:
11:
12: namespace App\Lib\Html;
13:
14: use Nette\Object,
15: Nette\Utils\Html,
16: App\Interfaces as I,
17: App\Lib\Statics\Cons;
18: 19: 20:
21: class Tree extends Object implements I\IHtml{
22:
23:
24: private $tree;
25:
26:
27: private $html = "";
28:
29: 30: 31: 32:
33: public function __construct($tree = NULL) {
34: (!$tree)?:$this->tree = $tree;
35: }
36:
37: 38: 39: 40:
41: public function getHtml(){
42: return $this->html;
43: }
44:
45: 46: 47: 48:
49: public function getCode() {
50: $level = 0;
51: foreach ($this->tree as $item) {
52: if ($item[Cons::COLUMN_DEPTH] > 0) {
53: $this->setTreePart($item[Cons::COLUMN_DEPTH], $level);
54: $level = $item[Cons::COLUMN_DEPTH];
55: }
56: }
57: $this->setRemainUlLi($level);
58: return $this->html;
59: }
60:
61: 62: 63: 64: 65: 66:
67: public function setTreePart($depth, $level) {
68: $this->getLiUl($depth, $level);
69: $this->getUlLi($depth, $level);
70: $this->html .= Html::el('li')->startTag();
71: }
72:
73: 74: 75: 76: 77: 78: 79:
80: public function setA($name,$link = NULL, $carpet = FALSE) {
81: $a = HTML::el('a');
82: if (!is_null($link)) {
83: $a->href($link);
84: }
85: $a->setText($name);
86: if($carpet === TRUE){
87: $a->add(Html::el('span class="sb-caret"'));
88: }
89: $this->html .= $a;
90: }
91:
92: 93: 94:
95: public function setCarpet(){
96: $this->html .= Html::el('span class="sb-caret"');
97: }
98:
99: 100: 101: 102: 103:
104: private function getLiUl($depth, $level) {
105: if ($depth < $level) {
106: $dismiss = $level - $depth;
107: for ($i = 0; $i < $dismiss; ++$i) {
108: $this->html .= Html::el('li')->endTag();
109: $this->html .= Html::el('ul')->endTag();
110: }
111: }
112: }
113:
114: 115: 116: 117: 118:
119: private function getUlLi($depth, $level) {
120: if ($depth === $level) {
121: $this->html .= Html::el('li')->endTag();
122: }
123: if ($depth > $level) {
124: $this->html .= Html::el('ul')->startTag();
125: }
126: }
127:
128: 129: 130: 131:
132: public function setRemainUlLi($level) {
133: for ($i = $level; $i >= 1; --$i) {
134: $this->html .= Html::el('li')->endTag();
135: $this->html .= Html::el('ul')->endTag();
136: }
137: }
138: }