49 lines
1.1 KiB
PHP
49 lines
1.1 KiB
PHP
<?php
|
|
|
|
namespace kernel\services;
|
|
|
|
use app\helpers\Debug;
|
|
use kernel\models\Menu;
|
|
use kernel\Request;
|
|
|
|
class MenuService
|
|
{
|
|
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;
|
|
// }
|
|
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;
|
|
}
|
|
} |