itemName; } public function setItemName($itemName) { $this->itemName = $itemName; return $this; } public function getItemsName() { return $this->itemsName; } public function setItemsName($itemsName) { $this->itemsName = $itemsName; return $this; } public function isShowItem() { return $this->showItem; } public function showItem($flag = true) { $this->showItem = $flag; return $this; } public function getEntity($field = null, $default = null) { return Qs_Array::get($this->entity, $field, $default); } public function setEntity($entity) { $this->entity = $entity; return $this; } public function getAction() { return $this->action; } public function setAction($action) { $this->action = $action; return $this; } public function getTemplate($action, $default = null) { return isset($this->templates[$action]) ? $this->templates[$action] : $default; } public function setTemplate($action, $pattern) { $this->templates[$action] = $pattern; return $this; } public function setTemplates(array $templates) { $this->templates = $templates; return $this; } public function getPage($field = null, $default = null) { return Qs_Array::get($this->page, $field, $default); } public function setPage($page) { $this->page = $page; return $this; } public function addPage() { return $this->add($this->getPage('menuTitle'), $this->getPage('url')); } public function exec() { $this->enable(); $this->addPage(); if ($this->isShowItem() && $this->getEntity()) { $this->add($this->getEntity('title'), $this->getActionUrl('edit')); } $this->addAction(); return $this; } public function enable() { Qs_Navigation::enable(); return $this; } public function addAction() { $action = $this->getAction(); switch ($action) { case 'new': // break was intentionally omitted case 'insert': $this->add($this->getTemplate(self::ADD, 'Add New {itemName}')); break; case 'edit': // break was intentionally omitted case 'update': $this->add($this->getTemplate(self::EDIT, 'Edit "{title}" {itemName}'), $this->getActionUrl('edit')); break; case 'reorder': // break was intentionally omitted case 'updateOrder': $this->add($this->getTemplate(self::REORDER, 'Reorder {itemsName}')); break; case 'view': $this->add($this->getTemplate(self::PREVIEW, 'Preview "{title}" {itemName}'), $this->getActionUrl('edit')); break; } return $this; } protected function getActionUrl($action) { return $this->getPage('url') . '?' . http_build_query(['action' => $action, 'id' => $this->getEntity('id')]); } protected function getPlaceholders() { $placeholders = [ 'itemName' => $this->getItemName(), 'itemsName' => $this->getItemsName(), ]; $placeholders = array_merge($placeholders, $this->getEntity()); $placeholders = array_filter($placeholders, 'is_scalar'); return $placeholders; } public function add($title, $url = null) { $title = Qs_String::fill($title, $this->getPlaceholders(), '{}'); Qs_Navigation::add(compact('title', 'url')); return $this; } public function unshift($title, $url = null) { $title = Qs_String::fill($title, $this->getPlaceholders(), '{}'); Qs_Navigation::unshift(compact('title', 'url')); return $this; } }