mirror of
https://github.com/slawkens/myaac.git
synced 2025-04-27 09:49:22 +02:00
Add Plugins::installMenus function
This commit is contained in:
parent
de1bb37bcb
commit
d1c5a189c3
@ -405,4 +405,60 @@ class Plugins {
|
|||||||
|
|
||||||
return $string;
|
return $string;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Install menus
|
||||||
|
* Helper function for plugins
|
||||||
|
*
|
||||||
|
* @param string $templateName
|
||||||
|
* @param array $categories
|
||||||
|
*/
|
||||||
|
public static function installMenus($templateName, $categories, $clearOld = true)
|
||||||
|
{
|
||||||
|
global $db;
|
||||||
|
|
||||||
|
if ($clearOld) {
|
||||||
|
$db->query('DELETE FROM `' . TABLE_PREFIX . 'menu` WHERE `template` = ' . $db->quote($templateName));
|
||||||
|
}
|
||||||
|
|
||||||
|
// check if menus already exist
|
||||||
|
$query = $db->query('SELECT `id` FROM `' . TABLE_PREFIX . 'menu` WHERE `template` = ' . $db->quote($templateName) . ' LIMIT 1;');
|
||||||
|
if ($query->rowCount() > 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach ($categories as $category => $menus) {
|
||||||
|
$i = 0;
|
||||||
|
foreach ($menus as $name => $link) {
|
||||||
|
$color = '';
|
||||||
|
$blank = 0;
|
||||||
|
|
||||||
|
if (is_array($link)) {
|
||||||
|
if (isset($link['name'])) {
|
||||||
|
$name = $link['name'];
|
||||||
|
}
|
||||||
|
if (isset($link['color'])) {
|
||||||
|
$color = $link['color'];
|
||||||
|
}
|
||||||
|
if (isset($link['blank'])) {
|
||||||
|
$blank = $link['blank'] ? 1 : 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
$link = $link['link'];
|
||||||
|
}
|
||||||
|
|
||||||
|
$insert_array = [
|
||||||
|
'template' => $templateName,
|
||||||
|
'name' => $name,
|
||||||
|
'link' => $link,
|
||||||
|
'category' => $category,
|
||||||
|
'ordering' => $i++,
|
||||||
|
'blank' => $blank,
|
||||||
|
'color' => $color,
|
||||||
|
];
|
||||||
|
|
||||||
|
$db->insert(TABLE_PREFIX . 'menu', $insert_array);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user