File: D:/HostingSpaces/marisrental/boldt.tech/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\Sites\Models\Site;
use App\Komma\Sites\SiteServiceInterface;
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 = $this->getCurrentSectionSlug();
$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();
$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($baseStructure,
$this->getSiteSubItems($sites->first(), $currentSiteSlug, $currentSectionSlug));
} //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' => ($site->slug == $currentSiteSlug),
];
}
}
$mainMenu = array_merge($baseStructure, $siteMenus);
}
/**
* 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
*/
$shopMenus = [];
$menuStructure = array_merge($topStructure, $mainMenu, $shopMenus);
$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' => ('' == $currentSectionSlug)
];
$items[] = [
'name' => trans('kms/sidebarMenu.users'),
'url' => route('users.index'),
'active' => ('users' == $currentSectionSlug),
];
$items[] = [
'name' => trans('kms/sidebarMenu.siteUsers'),
'url' => route('siteusers.index'),
'active' => ('siteusers' == $currentSectionSlug),
];
$items[] = [
'name' => trans('kms/sidebarMenu.employees'),
'url' => route('employees.index'),
'active' => ('employees' == $currentSectionSlug),
];
$items[] = [
'name' => trans('kms/sidebarMenu.pages'),
'url' => route('pages.index', ['siteSlug' => 'default']),
'active' => ('pages' == $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.projects'),
'url' => route('projects.index'),
'active' => ('projects' == $currentSectionSlug),
];
$items[] = [
'name' => trans('kms/sidebarMenu.services'),
'url' => route('services.index'),
'active' => ('services' == $currentSectionSlug),
];
$items[] = [
'name' => trans('kms/sidebarMenu.references'),
'url' => route('references.index'),
'active' => ('references' == $currentSectionSlug),
];
$items[] = [
'name' => trans('kms/sidebarMenu.jobs'),
'url' => route('vacancies.index'),
'active' => ('jobs' == $currentSectionSlug),
];
$items[] = [
'name' => trans('kms/sidebarMenu.fiches'),
'url' => route('fiche_materials.index'),
'active' => ('fiche_materials' == $currentSectionSlug),
];
return $items;
}
/**
* This will return the site specific items
*
* @param $site
* @param $currentSiteSlug
* @param $currentSectionSlug
* @return array
*/
protected function getSiteSubItems(Site $site, $currentSiteSlug, $currentSectionSlug)
{
return [];
}
}