Пример #1
0
 /**
  * {@inheritdoc}
  */
 public function removeChild(NodeInterface $child)
 {
     foreach ($this->children as $key => $myChild) {
         if ($child == $myChild) {
             unset($this->children[$key]);
         }
     }
     $this->children = array_values($this->children);
     $child->setParent(null);
     return $this;
 }
Пример #2
0
 /**
  * {@inheritdoc}
  */
 public function visit(NodeInterface $node)
 {
     if ($node->isLeaf()) {
         return [$node];
     }
     $yield = [];
     foreach ($node->getChildren() as $child) {
         $yield = array_merge($yield, $child->accept($this));
     }
     return $yield;
 }
Пример #3
0
 /**
  * {@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;
 }