public function getByMenuAndDestinationAndParameters(Entity $menu, string $destination, array $parameters = []) { $destination = explode(':', ltrim($destination, ':')); $links = $this->findBy(['this->link->action' => array_pop($destination), 'this->link->presenter' => array_pop($destination), 'this->link->module' => implode(':', $destination), current($menu->getMetadata()->getPrimaryKey()) => array_keys([$menu->id => $menu] + $menu->getterChildren(TRUE))])->fetchPairs(NULL, 'link'); $links = array_combine(array_map(function (Ytnuk\Link\Entity $entity) { return $entity->id; }, $links), $links); if (!$links) { return NULL; } if (!$parameters || !($link = $this->linkRepository->sortByParameters($this->linkRepository->findById(array_keys($links)), $parameters)->fetch())) { $link = reset($links); } return $this->getBy(['link' => $link]); }
private function getActive() : Entity { if ($this->active === NULL) { $menu = $this->repository->getByMenuAndDestinationAndParameters($this->menu, $destination = $this->getPresenter()->getAction(TRUE), array_map(function ($parameter) { return $parameter instanceof Nextras\Orm\Entity\IEntity ? $parameter->getPersistedId() : $parameter; }, $this->getPresenter()->getRequest()->getParameters())); if (!$menu) { $destination = substr($destination, 0, -strlen($this->getPresenter()->getAction())); foreach ($this->menu->getterChildren(TRUE) as $child) { if (strpos($child->link->destination, $destination) !== FALSE) { $menu = $child; break; } } } $this->active = $menu ?: $this->menu; } return $this->active; }