File: D:/HostingSpaces/SBogers10/liempde.ehbo.today/app/KommaApp/Kms/Composers/KmsSidebarMenuComposer.php
<?php namespace App\KommaApp\Kms\Composers;
/**
*
*
* @author Komma <info@komma.pro>
* @copyright (c) 2012-2016, Komma
*/
use App\KommaApp\Shop\Bridges\SideBarShopMenuComposerBridge;
use App\KommaApp\Sites\Kms\SiteService;
use App\KommaApp\Sites\Models\Site;
use App\KommaApp\Sites\SiteServiceInterface;
use App\KommaApp\Users\Roles;
class KmsSidebarMenuComposer
{
/** @var SiteServiceInterface $siteService */
protected $siteService;
public function __construct()
{
$this->siteService = \App::make(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
$menuStructure = $this->getBaseItems($currentSectionSlug, $currentSectionSubSlug);
//Load all the available sites
$sites = $this->siteService->getSites();
$siteMenus = [];
//If there is only one, merge the siteSub items, sot it is not a sub menu
if ($sites->count() == 1) {
$menuStructure = array_merge($menuStructure, $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' => ($site->slug == $currentSiteSlug)
];
}
}
}
$menuStructure = array_merge($menuStructure, $siteMenus);
$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 basic menu items
*
* @param $currentSectionSlug
* @param $currentSectionSubSlug
* @return array
*/
protected function getBaseItems($currentSectionSlug, $currentSectionSubSlug)
{
$items = [];
if(\Auth::user()->isAtLeast(Roles::Admin)) $items[] = [
'name' => trans('kms/sidebarMenu.users'),
'url' => route('users.index'),
'active' => ('users' == $currentSectionSlug)
];
$items[] = [
'name' => trans('kms/sidebarMenu.courses'),
'url' => route('courses.index'),
'active' => ('courses' == $currentSectionSlug)
];
$items[] = [
'name' => trans('kms/sidebarMenu.competences'),
'url' => route('competences.index'),
'active' => ('competences' == $currentSectionSlug)
];
// $items[] = [
// 'name' => __('kms/transfer.transfer'),
// 'url' => route('transfer.index'),
// 'active' => ('transfer' == $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)
{
$items = [];
return $items;
}
}