File: D:/HostingSpaces/stafa/stafa.nl/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\Buttons\Models\Button;
use App\Komma\Kms\ActionLog\Models\ActionLog;
use App\Komma\Servicepoints\Models\Servicepoint;
use App\Komma\Sites\Models\Site;
use App\Komma\Sites\SiteServiceInterface;
use App\Komma\Users\Models\KmsUser;
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['section']) ? $viewData['section']->getSlug() : $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();
$siteMenus = [];
//If there is only one, merge the siteSub items, so it is not a sub menu
if (!config('app.multipleSites') || $sites->count() == 1) {
$siteMenus = $this->getSiteSubItems($sites->first(), $currentSiteSlug, $currentSectionSlug);
} //If there are multiple sites, loop and ad these as an sub menu
else {
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),
];
}
}
}
$menuStructure = array_merge($topStructure, $siteMenus, $baseStructure);
$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),
];
$items[] = [
'name' => trans('kms/sidebarMenu.kms_users'),
'url' => route('kms_users.index'),
'active' => ('kms_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.team'),
'active' => ($currentSectionSlug == 'departments' || $currentSectionSlug == 'employees'),
'subItems' => [
[
'name' => trans('kms/sidebarMenu.employees'),
'url' => route('employees.index'),
'active' => ('employees' == $currentSectionSlug),
],
[
'name' => trans('kms/sidebarMenu.departments'),
'url' => route('departments.index'),
'active' => ('departments' == $currentSectionSlug),
]
]
];
$items[] = [
'name' => trans('kms/sidebarMenu.locations'),
'url' => route('locations.index'),
'active' => ('locations' == $currentSectionSlug),
];
$items[] = [
'name' => trans('kms/sidebarMenu.services'),
'url' => route('services.index'),
'active' => ('services' == $currentSectionSlug),
];
$items[] = [
'name' => trans('kms/sidebarMenu.projects'),
'url' => route('projects.index'),
'active' => ('projects' == $currentSectionSlug),
];
$items[] = [
'name' => trans('kms/sidebarMenu.posts'),
'url' => route('posts.index'),
'active' => ('posts' == $currentSectionSlug),
];
$items[] = [
'name' => trans('kms/sidebarMenu.events'),
'url' => route('events.index'),
'active' => ('events' == $currentSectionSlug),
];
$items[] = [
'name' => trans('kms/sidebarMenu.jobs'),
'url' => route('jobs.index'),
'active' => ('jobs' == $currentSectionSlug),
];
$items[] = [
'name' => trans('kms/sidebarMenu.references'),
'url' => route('references.index'),
'active' => ('references' == $currentSectionSlug),
];
$items[] = [
'name' => trans('kms/sidebarMenu.testimonials'),
'url' => route('testimonials.index'),
'active' => ('testimonials' == $currentSectionSlug),
];
$items[] = [
'is_separator' => true
];
// 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),
// ];
// }
if(\Auth::user()->can('index', Button::class)) {
$items[] = [
'name' => trans('kms/sidebarMenu.buttons'),
'url' => route('buttons.index'),
'active' => ('buttons' == $currentSectionSlug),
];
}
if(\Auth::user()->can('index', Servicepoint::class)) {
$items[] = [
'name' => trans('kms/sidebarMenu.servicepoints'),
'url' => route('servicepoints.index'),
'active' => ('servicepoints' == $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),
],
[
'name' => trans('kms/sidebarMenu.assortments'),
'url' => route('assortments.index', ['siteSlug' => $site->slug]),
'active' => ('assortments' == $currentSectionSubSlug && $site->slug == $currentSiteSlug),
]
];
return $items;
}
}