mirror of
https://github.com/slawkens/myaac.git
synced 2025-04-26 17:29:21 +02:00
Add Plugins::installMenus function
This commit is contained in:
parent
787416e552
commit
2458393d22
@ -401,4 +401,62 @@ class Plugins {
|
|||||||
|
|
||||||
return $string;
|
return $string;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Install menus
|
||||||
|
* Helper function for plugins
|
||||||
|
*
|
||||||
|
* @param string $templateName
|
||||||
|
* @param array $categories
|
||||||
|
*/
|
||||||
|
public static function installMenus($templateName, $categories)
|
||||||
|
{
|
||||||
|
global $db;
|
||||||
|
|
||||||
|
// check if menu table exist (it does not on MyAAC 0.7.0 and lower)
|
||||||
|
if (!$db->hasTable(TABLE_PREFIX . 'menu')) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 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['color'])) {
|
||||||
|
$color = $link['color'];
|
||||||
|
}
|
||||||
|
if (isset($link['blank'])) {
|
||||||
|
$blank = $link['blank'] === true ? 1 : 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
$link = $link['link'];
|
||||||
|
}
|
||||||
|
|
||||||
|
$insert_array = [
|
||||||
|
'template' => $templateName,
|
||||||
|
'name' => $name,
|
||||||
|
'link' => $link,
|
||||||
|
'category' => $category,
|
||||||
|
'ordering' => $i++,
|
||||||
|
];
|
||||||
|
|
||||||
|
// support for color and blank attributes since 0.8.0
|
||||||
|
if(version_compare(MYAAC_VERSION, '0.8.0', '>=')) {
|
||||||
|
$insert_array['blank'] = $blank;
|
||||||
|
$insert_array['color'] = $color;
|
||||||
|
}
|
||||||
|
|
||||||
|
$db->insert(TABLE_PREFIX . 'menu', $insert_array);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user