]> _ Git - cubist_cms-back.git/commitdiff
wip #2878 @2
authorVincent Vanwaelscappel <vincent@cubedesigners.com>
Thu, 11 Jul 2019 10:03:49 +0000 (12:03 +0200)
committerVincent Vanwaelscappel <vincent@cubedesigners.com>
Thu, 11 Jul 2019 10:03:49 +0000 (12:03 +0200)
src/app/Http/Controllers/CubistPageController.php
src/app/Magic/Menu/Item.php
src/app/Magic/Menu/PageItem.php
src/app/Magic/Models/CMSPage.php

index 6323119e6d5f07df417ba144809c7cd3396d9876..ab86203d58381c36bb11eaeffb519712bb7dda76 100644 (file)
@@ -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();
         }
index 0d8e21b7881dd4b62fd8b7eafe7c2134bcd53498..b9859c70f5ab3fc43207c6519111e9802ef93fc0 100644 (file)
@@ -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
      */
index 2b1c4e7c589931d1871119f0ba68f124150e12a0..50fa504a8a350cefea1f79aed5efd53a954a1bb1 100644 (file)
@@ -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()) {
index 2926dfdc69a0e0757d76fc9f8d9a1ea3e256b21c..db46adcc257f385123c24b1a12fee358376957ac 100644 (file)
@@ -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;