-
Notifications
You must be signed in to change notification settings - Fork 1
/
TreeVisitor.php
39 lines (36 loc) · 1 KB
/
TreeVisitor.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
<?php
namespace yii\dwz;
use yii\dwz\tree\Visitor\Visitor;
use yii\helpers\Html;
use yii\helpers\Url;
/**
*
*/
class TreeVisitor implements Visitor
{
/**
* {@inheritdoc}
*/
public function visit(\yii\dwz\tree\Node\NodeInterface $node) {
if ($node->isLeaf()) {
$value = $node->getValue();
return [Html::tag('li',Html::a($value['label'],$value['url'],['target'=>'navTab','rel'=>static::generateId($value['label'])]))];
}
$yield = [];
if(!$node->isRoot()){
$yield = array_merge($yield, ['<li><a>'.$node->getValue()['label'].'</a>']);
}
$yield = array_merge($yield, ['<ul>']);
foreach ($node->getChildren() as $child) {
$yield = array_merge($yield, $child->accept($this));
}
$yield = array_merge($yield, ['</ul>']);
if(!$node->isRoot()){
$yield = array_merge($yield, ['</li>']);
}
return $yield;
}
public static function generateId($label){
return '_'.crc32($label);
}
}