Newer
Older
<?php
namespace QUI\Menu\Independent;
use QUI;
/**
* Menu handler
* - get menus
*/
class Handler
{
/**
* @return string
*/
public static function table(): string
{
return QUI::getDBTableName('menus');
}
/**
* @param int $menuId
* @return Menu
*
* @throws QUI\Exception
*/
public static function getMenu(int $menuId): Menu
{
return new Menu($menuId);
}
/**
* @param bool|int $menuId
* @param QUI\Projects\Project|null $Project
* @return string
*/
public static function getMenuCacheName(
bool | int $menuId = false,
null | QUI\Projects\Project $Project = null
): string {
$project = $Project->getName();
$lang = $Project->getLang();
$template = $Project->getAttribute('template');
$projectHash = '/' . md5($project . '/' . $lang . '/' . $template);
} else {
$projectHash = '';
}
if ($menuId) {
return 'quiqqer/menu/independent/' . $menuId . $projectHash;
}
return 'quiqqer/menu/independent';
}
/**
* @param int $menuId
* @return array
*
* @throws QUI\Database\Exception
* @throws QUI\Exception
*/
public static function getMenuData(int $menuId): array
{
$data = QUI::getDataBase()->fetch([
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
'where' => [
'id' => $menuId
],
'limit' => 1
]);
if (isset($data[0])) {
return $data[0];
}
throw new QUI\Exception(
'Menu not found',
404,
[
'menuId' => $menuId
]
);
}
/**
* @return Menu[]
* @throws QUI\Database\Exception
*/
public static function getList(): array
{
$data = QUI::getDataBase()->fetch([
'from' => self::table()
]);
$result = [];
foreach ($data as $entry) {
try {
$result[] = new Menu($entry);
} catch (QUI\Exception $Exception) {
QUI\System\Log::addError($Exception->getMessage());
}
}
return $result;
}
/**
* @return string[]
*
* @todo Item Class Provider -> API
*/
public static function getItemList(): array
{
return [
QUI\Menu\Independent\Items\Site::class,
QUI\Menu\Independent\Items\Anchor::class,
QUI\Menu\Independent\Items\Custom::class,