From e0b1860b2ddeea2312b8a24751b5055a2f6a90db Mon Sep 17 00:00:00 2001 From: Vincent Vanwaelscappel Date: Thu, 11 Jul 2019 12:03:49 +0200 Subject: [PATCH] wip #2878 @2 --- .../Http/Controllers/CubistPageController.php | 2 +- src/app/Magic/Menu/Item.php | 39 +++++++++++++++++-- src/app/Magic/Menu/PageItem.php | 12 +++--- src/app/Magic/Models/CMSPage.php | 8 ---- 4 files changed, 41 insertions(+), 20 deletions(-) diff --git a/src/app/Http/Controllers/CubistPageController.php b/src/app/Http/Controllers/CubistPageController.php index 6323119..ab86203 100644 --- a/src/app/Http/Controllers/CubistPageController.php +++ b/src/app/Http/Controllers/CubistPageController.php @@ -33,7 +33,7 @@ class CubistPageController extends CubistFrontController $path = 'home'; } $nav = Menu::getNavigation(); - $item = $nav->findItemByHref($path); + $item = $nav->findOneByHref($path); if (null === $item) { $this->_404(); } diff --git a/src/app/Magic/Menu/Item.php b/src/app/Magic/Menu/Item.php index 0d8e21b..b9859c7 100644 --- a/src/app/Magic/Menu/Item.php +++ b/src/app/Magic/Menu/Item.php @@ -95,17 +95,21 @@ class Item $this->addChild($child); } - - public function findItemByHref($href) + /** + * @param $param + * @param $search + * @return $this|Item|null + */ + public function findOneBy($param, $search) { - if ($this->getHref() == $href) { + if ($this->get($param) == $search) { return $this; } if (!$this->hasChildren()) { return null; } foreach ($this->getChildren() as $child) { - $res = $child->findItemByHref($href); + $res = $child->findOneBy($param, $search); if (null !== $res) { return $res; } @@ -113,6 +117,33 @@ class Item return null; } + public function get($param) + { + $name = 'get' . ucfirst($param); + if (method_exists($this, $name)) { + return $this->$name(); + } + return null; + } + + /** + * @param $id + * @return Item|null + */ + public function findOneById($id) + { + return $this->findOneBy('id', $id); + } + + /** + * @param $href + * @return Item|null + */ + public function findOneByHref($href) + { + return $this->findOneBy('href', $href); + } + /** * @return string */ diff --git a/src/app/Magic/Menu/PageItem.php b/src/app/Magic/Menu/PageItem.php index 2b1c4e7..50fa504 100644 --- a/src/app/Magic/Menu/PageItem.php +++ b/src/app/Magic/Menu/PageItem.php @@ -35,15 +35,13 @@ class PageItem extends Item public function getHref() { - if ($this->getPage()->isRedirection()) { - if ($this->getPage()->template == 'FirstRedirection' && $this->hasChildren()) { - return $this->getChildren()[0]->getHref(); - } else if ($this->getPage()->template == 'InternalRedirection') { - } else if ($this->getPage()->template == 'Redirection') { - return $this->navigation; - } + if ($this->getPage()->template == 'first_redirection' && $this->hasChildren()) { + return $this->getChildren()[0]->getHref(); + } else if ($this->getPage()->template == 'internal_redirection') { + } else if ($this->getPage()->template == 'redirection') { + return $this->navigation; } if ($this->getPage()->getUsedTemplate()->isVirtual()) { diff --git a/src/app/Magic/Models/CMSPage.php b/src/app/Magic/Models/CMSPage.php index 2926dfd..db46adc 100644 --- a/src/app/Magic/Models/CMSPage.php +++ b/src/app/Magic/Models/CMSPage.php @@ -241,14 +241,6 @@ class CMSPage extends CubistMagicNestedModel return Json::decodeRecursive(parent::_prepareData($attributes), Json::TYPE_ARRAY); } - /** - * @return bool - */ - public function isRedirection() - { - return $this->_usedTemplate instanceof Redirection; - } - public static function getPageClass() { $class = CMSPage::class; -- 2.39.5