File: D:/HostingSpaces/SBogers10/blije-gasten.komma.pro/app/Komma/Kms/Composers/SidebarMenuComposer.php
<?php namespace App\Komma\Kms\Composers;
/**
*
*
* @author Komma <info@komma.pro>
* @copyright (c) 2012-2016, Komma
*/
use App\Komma\Kms\ActionLog\ActionLog;
use App\Komma\Shop\Bridges\SideBarShopMenuComposerBridge;
use App\Komma\Sites\Kms\SiteService;
use App\Komma\Sites\Models\Site;
use App\Komma\Sites\SiteServiceInterface;
use App\Komma\Users\Models\KmsUser;
use App\Komma\Users\Models\KmsUserRole;
use Illuminate\Notifications\Action;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Route;
class SidebarMenuComposer
{
/** @var SiteServiceInterface $siteService */
protected $siteService;
public function __construct()
{
$this->siteService = app(SiteServiceInterface::class);
}
public function compose($view)
{
$viewData = $view->getData();
$currentSiteSlug = $this->siteService->getCurrentSite()->slug;
$currentSectionSlug = isset($viewData['slug']) ? $viewData['slug'] : $this->getCurrentSectionSlug();
$currentSectionSubSlug = $this->getCurrentSectionSubSlug();
//Generate the base menu structure
$topStructure = $this->getTopItems($currentSectionSlug, $currentSectionSubSlug);
$baseStructure = $this->getBaseItems($currentSectionSlug, $currentSectionSubSlug);
//Load all the available sites
$sites = $this->siteService->getSites();
$mainMenu = [];
//If there is only one, merge the siteSub items, so it is not a sub menu
if ( !config('app.multipleSites') || $sites->count() == 1) {
$mainMenu = array_merge(
$this->getSiteSubItems($sites->first(), $currentSiteSlug, $currentSectionSlug), $baseStructure);
} //If there are multiple sites, loop and ad these as an sub menu
else {
$siteMenus = [];
foreach ($sites as $site) {
//We put all site items in a submenu for a site except for the default site.
if ($site->exists) {
$siteMenus[] = [
'name' => $site->name,
'subItems' => $this->getSiteSubItems($site, $currentSiteSlug, $currentSectionSlug),
'active' => ($currentSectionSlug != 'dashboard' && $site->slug == $currentSiteSlug),
];
}
}
$mainMenu = array_merge($siteMenus, $baseStructure);
}
$menuStructure = array_merge($topStructure, $mainMenu);
/**
* Doesn't mean that if the environment setting shop is true the shop is installed
* To install the shop, go to:
* app / Komma / Shop / Readme.txt
*/
if (\Config::get('app.isShop')) {
$menuStructure = array_merge($menuStructure, SideBarShopMenuComposerBridge::get($currentSectionSlug));
}
$view->with('menuStructure', $menuStructure);
}
protected function getCurrentSectionSlug()
{
$route = explode('/', Route::current()->uri());
if (Route::current()->parameter('site')) {
return $route[2];
}
return isset($route[1]) ? $route[1] : null;
}
protected function getCurrentSectionSubSlug()
{
$route = explode('/', Route::current()->uri());
if (Route::current()->parameter('site')) {
if (isset($route[3])) {
return $route[3];
}
}
return isset($route[2]) ? $route[2] : null;
}
/**
* This functions will return the top menu items
*
* @param $currentSectionSlug
* @param $currentSectionSubSlug
* @return array
*/
protected function getTopItems($currentSectionSlug, $currentSectionSubSlug)
{
$items = [];
$items[] = [
'name' => __('kms/SidebarMenu.dashboard'),
'url' => route('dashboard.index'),
'active' => ('dashboard' == $currentSectionSlug),
];
if(Auth::user()->can('index', KmsUser::class)) {
$items[] = [
'name' => trans('kms/sidebarMenu.users'),
'active' => ('kms_users' == $currentSectionSlug) || ('site_users' == $currentSectionSlug),
'subItems' => [
[
'name' => trans('kms/sidebarMenu.kms_users'),
'url' => route('kms_users.index'),
'active' => ('kms_users' == $currentSectionSlug),
],
[
'name' => trans('kms/sidebarMenu.site_users'),
'url' => route('site_users.index'),
'active' => ('site_users' == $currentSectionSlug),
]
],
];
}
else {
$items[] = [
'name' => trans('kms/sidebarMenu.site_users'),
'url' => route('site_users.index'),
'active' => ('site_users' == $currentSectionSlug),
];
}
return $items;
}
/**
* This functions will return the basic menu items
*
* @param $currentSectionSlug
* @param $currentSectionSubSlug
* @return array
*/
protected function getBaseItems($currentSectionSlug, $currentSectionSubSlug)
{
$items = [];
$items[] = [
'name' => trans('kms/sidebarMenu.questions_dropdown'),
'active' => (in_array($currentSectionSlug, ['questions', 'questioncategories'])),
'subItems' => [
[
'name' => __('kms/sidebarMenu.questions'),
'url' => route('questions.index'),
'active' => ('questions' == $currentSectionSlug),
],
[
'name' => __('kms/sidebarMenu.questionCategories'),
'url' => route('questioncategories.index'),
'active' => ('questioncategories' == $currentSectionSlug),
]
],
];
$items[] = [
'name' => __('kms/sidebarMenu.employees'),
'url' => route('employees.index'),
'active' => ('employees' == $currentSectionSlug),
];
//
// if (\Auth::user()->can('viewLogs', ActionLog::class)) {
// $items[] = [
// 'name' => __('kms/actionlog.section.title'),
// 'url' => route('actionlog.index'),
// 'active' => ('actionlog' == $currentSectionSlug),
// ];
// }
//
// // Allow site(s) editing only for SuperAdmin
// if (\Auth::user()->can('editSites', KmsUser::class)) {
// $items[] = [
// 'name' => trans('kms/sidebarMenu.sites'),
// 'url' => route('sites.index'),
// 'active' => ('sites' == $currentSectionSlug),
// ];
// }
return $items;
}
/**
* This will return the site specific items
*
* @param $site
* @param $currentSiteSlug
* @param $currentSectionSlug
* @return array
*/
protected function getSiteSubItems(Site $site, $currentSiteSlug, $currentSectionSubSlug)
{
$items = [
[
'name' => trans('kms/sidebarMenu.pages'),
'url' => route('pages.index', ['siteSlug' => $site->slug]),
'active' => ('pages' == $currentSectionSubSlug && $site->slug == $currentSiteSlug),
],
];
return $items;
}
}