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 @@ ?>