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 getTitlePattern($action, $default = null) { return isset($this->titlePattern[$action]) ? $this->titlePattern[$action] : $default; } public function setTitlePattern($action, $pattern) { $this->titlePattern[$action] = $pattern; 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 exec() { $this->enable(); $this->add($this->getPage('menuTitle'), $this->getPage('url')); 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->getTitlePattern($action, 'Add New {itemName}')); break; case 'edit': // break was intentionally omitted case 'update': $this->add($this->getTitlePattern($action, 'Edit "{title}" {itemName}'), $this->getActionUrl('edit')); break; case 'reorder': // break was intentionally omitted case 'updateOrder': $this->add($this->getTitlePattern($action, 'Reorder {itemsName}')); break; case 'view': $this->add($this->getTitlePattern($action, '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; } }