From 9f132e7bc4012b3712ba81115f868170444e3670 Mon Sep 17 00:00:00 2001 From: stasbilay02 Date: Wed, 4 Sep 2024 16:47:05 +0300 Subject: [PATCH] fix active menu --- kernel/models/Menu.php | 24 ---------------- kernel/services/MenuService.php | 49 +++++++++++++++++++++++++++++++++ views/widgets/admin/menu.php | 6 ++-- 3 files changed, 52 insertions(+), 27 deletions(-) create mode 100644 kernel/services/MenuService.php diff --git a/kernel/models/Menu.php b/kernel/models/Menu.php index 1eb9482..989fa3b 100644 --- a/kernel/models/Menu.php +++ b/kernel/models/Menu.php @@ -37,30 +37,6 @@ class Menu extends Model ]; } - public static function getChild(int $id) - { - $collection = Menu::where("parent_id", $id)->get(); - if (!$collection->isEmpty()){ - return $collection; - } - - return false; - } - - public static function hasActiveChild(int $id): bool - { - $child = self::getChild($id); - if (!$child->isEmpty()){ - foreach ($child as $item){ - if ($item->url === \kernel\Request::getUrlPath()){ - return true; - } - } - } - - return false; - } - /** * @return string[] */ diff --git a/kernel/services/MenuService.php b/kernel/services/MenuService.php new file mode 100644 index 0000000..583606c --- /dev/null +++ b/kernel/services/MenuService.php @@ -0,0 +1,49 @@ +get(); + if (!$collection->isEmpty()){ + return $collection; + } + + return false; + } + + public static function hasActiveChild(int $id): bool + { + $child = self::getChild($id); + if (!$child->isEmpty()){ + foreach ($child as $item){ +// if ($item->url === \kernel\Request::getUrlPath()){ +// return true; +// } + if (strripos(Request::getUrlPath(), $item->url) !== false) { + return true; + } + } + } + + return false; + } + + public static function getActiveStatus($url) + { + if ($url === Request::getUrlPath()){ + return true; + } else { + if (strripos(\kernel\Request::getUrlPath(), ($url . "/page")) !== false) { + return true; + } + } + return false; + } +} \ No newline at end of file diff --git a/views/widgets/admin/menu.php b/views/widgets/admin/menu.php index 78eeebd..82be0db 100644 --- a/views/widgets/admin/menu.php +++ b/views/widgets/admin/menu.php @@ -5,13 +5,13 @@ ?>