Skip to content

Commit

Permalink
feat: do not modify the menu with simplified interface
Browse files Browse the repository at this point in the history
  • Loading branch information
btry committed May 23, 2022
1 parent 63e5416 commit f7ccc2b
Showing 1 changed file with 48 additions and 73 deletions.
121 changes: 48 additions & 73 deletions inc/common.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -754,86 +754,61 @@ public static function hookRedefineMenu($menus) {
return $menus;
}

if (plugin_formcreator_replaceHelpdesk() !== false) {
$newMenu = [];
$newMenu['seek_assistance'] = [
'default' => Plugin::getWebDir('formcreator', false) . '/front/wizard.php',
'title' => __('Seek assistance', 'formcreator'),
'icon' => 'fa-fw ti ti-headset',
];
$newMenu['my_assistance_requests'] = [
'default' => PluginFormcreatorIssue::getSearchURL(false),
'title' => __('My requests for assistance', 'formcreator'),
'icon' => 'fa-fw ti ti-list',
];
if (plugin_formcreator_replaceHelpdesk() === false) {
return $menus;
}

if (PluginFormcreatorEntityConfig::getUsedConfig('is_kb_separated', Session::getActiveEntity()) == PluginFormcreatorEntityConfig::CONFIG_KB_DISTINCT
&& Session::haveRight('knowbase', KnowbaseItem::READFAQ)
) {
$newMenu['faq'] = $menus['faq'];
$newMenu['faq']['default'] = Plugin::getWebDir('formcreator', false) . '/front/knowbaseitem.php';
}
if (Session::haveRight("reservation", ReservationItem::RESERVEANITEM)) {
if (isset($menus['reservation'])) {
$newMenu['reservation'] = $menus['reservation'];
}
}
$rssFeedTable = RSSFeed::getTable();
$criteria = [
'SELECT' => "$rssFeedTable.*",
'DISTINCT' => true,
'FROM' => $rssFeedTable,
'ORDER' => "$rssFeedTable.name"
];
$criteria = $criteria + RSSFeed::getVisibilityCriteria();
$criteria['WHERE']["$rssFeedTable.users_id"] = ['<>', Session::getLoginUserID()];
$iterator = $DB->request($criteria);
$hasRssFeeds = $iterator->count() > 0;

if (RSSFeed::canView() && $hasRssFeeds) {
$newMenu['feeds'] = [
'default' => Plugin::getWebDir('formcreator', false) . '/front/wizardfeeds.php',
'title' => __('Consult feeds', 'formcreator'),
'icon' => 'fa-fw ti ti-rss',
];
}
$newMenu = [];
$newMenu['seek_assistance'] = [
'default' => Plugin::getWebDir('formcreator', false) . '/front/wizard.php',
'title' => __('Seek assistance', 'formcreator'),
'icon' => 'fa-fw ti ti-headset',
];
$newMenu['my_assistance_requests'] = [
'default' => PluginFormcreatorIssue::getSearchURL(false),
'title' => __('My requests for assistance', 'formcreator'),
'icon' => 'fa-fw ti ti-list',
];

// Add plugins menus
$plugin_menus = $menus['plugins']['content'] ?? [];
foreach ($plugin_menus as $menu_name => $menu_data) {
$menu_data['default'] = $menu_data['page'] ?? '#';
$newMenu[$menu_name] = $menu_data;
if (PluginFormcreatorEntityConfig::getUsedConfig('is_kb_separated', Session::getActiveEntity()) == PluginFormcreatorEntityConfig::CONFIG_KB_DISTINCT
&& Session::haveRight('knowbase', KnowbaseItem::READFAQ)
) {
$newMenu['faq'] = $menus['faq'];
$newMenu['faq']['default'] = Plugin::getWebDir('formcreator', false) . '/front/knowbaseitem.php';
}
if (Session::haveRight("reservation", ReservationItem::RESERVEANITEM)) {
if (isset($menus['reservation'])) {
$newMenu['reservation'] = $menus['reservation'];
}

return $newMenu;
}
$rssFeedTable = RSSFeed::getTable();
$criteria = [
'SELECT' => "$rssFeedTable.*",
'DISTINCT' => true,
'FROM' => $rssFeedTable,
'ORDER' => "$rssFeedTable.name"
];
$criteria = $criteria + RSSFeed::getVisibilityCriteria();
$criteria['WHERE']["$rssFeedTable.users_id"] = ['<>', Session::getLoginUserID()];
$iterator = $DB->request($criteria);
$hasRssFeeds = $iterator->count() > 0;

if (RSSFeed::canView() && $hasRssFeeds) {
$newMenu['feeds'] = [
'default' => Plugin::getWebDir('formcreator', false) . '/front/wizardfeeds.php',
'title' => __('Consult feeds', 'formcreator'),
'icon' => 'fa-fw ti ti-rss',
];
}

// Using GLPI's helpdesk interface; then just modify the menu
$newMenus = [];
foreach ($menus as $key => $menu) {
switch ($key) {
case 'create_ticket':
$newMenus['forms'] = [
'default' => '/' . Plugin::getWebDir('formcreator', false) . '/front/formlist.php',
'title' => _n('Form', 'Forms', 2, 'formcreator'),
'icon' => 'fas fa-edit',
];
break;

case 'tickets':
$newMenus['tickets'] = [
'default' => PluginFormcreatorIssue::getSearchURL(false),
'title' => PluginFormcreatorIssue::getTypeName(Session::getPluralNumber()),
'icon' => 'fas fa-exclamation-circle',
];
break;

default:
$newMenus[$key] = $menu;
}
// Add plugins menus
$plugin_menus = $menus['plugins']['content'] ?? [];
foreach ($plugin_menus as $menu_name => $menu_data) {
$menu_data['default'] = $menu_data['page'] ?? '#';
$newMenu[$menu_name] = $menu_data;
}

return $newMenus;
return $newMenu;
}

/**
Expand Down

0 comments on commit f7ccc2b

Please sign in to comment.