/** * affiliated to another registered * * @param Permission $item permission instance * @param string $to parent name * * @return void */ public function affiliate(Permission $item, $to) { if ($to !== null) { $this->conn->table($this->table)->where('siteKey', $item->siteKey)->where(function ($query) use($item) { $query->where('name', $item->name)->orWhere('name', 'like', $item->name . '.%'); })->update(['name' => $this->conn->raw("concat('{$to}', '.', `name`)")]); } }
/** * affiliated to another config * * @param ConfigEntity $config config object * @param string|null $to parent name * * @return void */ public function affiliate(ConfigEntity $config, $to = null) { if ($to !== null) { $this->conn->table($this->table)->where('siteKey', $config->siteKey)->where(function ($query) use($config) { $query->where('name', $config->name)->orWhere('name', 'like', $config->name . '.%'); })->update(['name' => $this->conn->raw("concat('{$to}', '.', `name`)")]); } }
/** * linked parent and child relation * * @param NodeInterface $descendant child node instance * @param NodeInterface $ancestor parent node instance * @return bool */ public function linkHierarchy(NodeInterface $descendant, NodeInterface $ancestor) { $prefix = $this->conn->getTablePrefix(); $expression = $this->conn->raw(implode(' ', ["insert into {$prefix}{$this->hierarchyTable} (`ancestor`, `descendant`, `depth`) ", "select a.`ancestor`, d.`descendant`, a.`depth` + d.`depth` + 1 ", "from {$prefix}{$this->hierarchyTable} a, {$prefix}{$this->hierarchyTable} d ", "where a.`descendant` = '{$ancestor->id}' and d.`ancestor` = '{$descendant->id}'"])); return $this->conn->statement($expression); }