Beispiel #1
0
 public function onMenuConfig($event)
 {
     $models = Page::find()->select(["id", "parent", "title"])->asArray()->all();
     array_unshift($models, Page::getAppDefaultPage());
     $data = [];
     $tree = new Tree($models);
     $nodes = $tree->getRootNodes();
     $data = [];
     foreach ($nodes as $node) {
         $node = $node->toArray();
         $data[] = call_user_func([$this, "repalceKey"], $node);
     }
     $event->parameters->set($this->id, ["name" => "页面", "id" => $this->id, "tree" => $data]);
 }
Beispiel #2
0
 public function getCanParentNodes()
 {
     $models = Page::find()->select(["id", "parent", "title"])->asArray()->all();
     $tree = new Tree($models);
     $nodes = $tree->getNodes();
     // 去处当前节点和子节点
     if ($this->primaryKey) {
         $node = $tree->getNodeById($this->primaryKey);
         $ancestors = $node->getDescendantsAndSelf();
         $nodes = array_diff($nodes, $ancestors);
     }
     $result = [];
     foreach ($nodes as $node) {
         $result[$node->get("id")] = str_repeat("--", $node->getLevel() - 1) . $node->get("title");
     }
     return $result;
 }