/** * fetch node list tree type * * @param NodeInterface $top node instance * @param int $depth want get depth * * @return TreeCollection */ public function fetchTree(NodeInterface $top, $depth = 0) { $prefix = $this->conn->getTablePrefix(); $query = $this->conn->table($this->nodeTable . " as t")->selectRaw("{$prefix}t.*, {$prefix}h.`depth`, GROUP_CONCAT({$prefix}crumbs.`ancestor` " . "order by {$prefix}crumbs.`depth` desc) AS breadcrumbs")->join($this->hierarchyTable . ' as h', 't.id', '=', 'h.descendant')->join($this->hierarchyTable . ' as crumbs', 'crumbs.descendant', '=', 'h.descendant')->where('h.ancestor', $top->id); if ($depth > 0) { $query->where('h.depth', '<', $depth); } $rows = $query->groupBy('t.id')->orderBy('breadcrumbs')->orderBy('t.ordering')->get(); $nodes = []; foreach ($rows as $row) { $row = (array) $row; $node = $this->createNodeModel(array_diff_key($row, array_flip(['depth', 'breadcrumbs']))); $node->setdepth($row['depth']); $node->setTreeNodePath($row['breadcrumbs']); $nodes[$node->id] = $node; } return new TreeCollection($nodes); }
/** * drop document instance * * @param ConfigEntity $config 현제 설정 되어 있는 config * @return void */ protected function dropDivisionTable(ConfigEntity $config) { if ($config->get('division') === true) { $this->connection->getSchemaBuilder()->drop(sprintf("%s%s", $this->connection->getTablePrefix(), $this->getDivisionTableName($config))); } }