File: D:/HostingSpaces/fire-tech/fire-tech.nl/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\Courses\Models\Course;
use App\KommaApp\Kms\Core\Kms;
use App\KommaApp\Kms\Core\KmsInterface;
use App\KommaApp\Pages\Models\Page;
use App\KommaApp\Shop\Bridges\SideBarShopMenuComposerBridge;
use App\KommaApp\Sites\Models\Site;
class KmsSidebarMenuComposer
{
protected $kms;
public function __construct()
{
$this->kms = \App::make(KmsInterface::class);
}
public function compose($view)
{
$viewData = $view->getData();
$currentSiteSlug = $this->kms->getSiteSlug();
//$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->kms->getSites();
//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) {
$menuStructure = array_merge($menuStructure,
[
[
'name' => $site->name,
'subItems' => $this->getSiteSubItems($site, $currentSiteSlug, $currentSectionSlug),
'active' => ($site->slug == $currentSiteSlug)
]
]
);
}
}
$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 = [];
// $items[] = [
// 'name' => \Lang::get('kms/SidebarMenu.dashboard'),
//// 'url' => route('kms.dashboard.index'),
// 'url' => route('dashboard.index'),
// 'active' => ('' == $currentSectionSlug)
// ];
$items[] = [
'name' => trans('kms/sidebarMenu.users'),
'url' => route('users.index'),
'active' => ('users' == $currentSectionSlug)
];
$news = Page::where('code_name', '=', 'posts')->first();
if(isset($news) && $news->active) {
$items[] = [
'name' => trans('kms/sidebarMenu.posts'),
'url' => route('posts.index'),
'active' => ('posts' == $currentSectionSlug)
];
}
$items[] = [
'name' => trans('kms/sidebarMenu.courses'),
'url' => route('courses.index'),
'active' => ('courses' == $currentSectionSlug)
];
if(Course::count() > 0) {
$items[] = [
'name' => trans('kms/sidebarMenu.subscriptions'),
'url' => route('subscriptions.index'),
'active' => ('subscriptions' == $currentSectionSlug)
];
}
$items[] = [
'name' => trans('kms/sidebarMenu.students'),
'url' => route('students.index'),
'active' => ('students' == $currentSectionSlug)
];
// $items[] = [
// 'name' => __('kms/transfer.transfer'),
// 'url' => route('transfer.index'),
// 'active' => ('transfer' == $currentSectionSlug)
// ];
// Allow site(s) editing only for SuperAdmin
if (\Auth::user()->role->id == 1) {
$items[] = [
'name' => trans('kms/sidebarMenu.sites'),
'url' => route('sites.index'),
'active' => ('sites' == $currentSectionSlug)
];
}
/**
* Doesn't mean that if the environment setting shop is true the shop is installed
* To install the shop, go to:
* app / KommaApp / Shop / Readme.txt
*/
if(\Config::get('app.isShop')){
$items = array_merge($items, SideBarShopMenuComposerBridge::get($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 = [];
$items[]= [
'name' => trans('kms/sidebarMenu.pages'),
'url' => route('pages.index', ['site' => $site->slug]),
'active' => ('pages' == $currentSectionSlug && $site->slug == $currentSiteSlug)
];
$projects = Page::where('code_name', '=', 'projects')->first();
if(isset($projects) && $projects->active) {
$items[] = [
'name' => trans('kms/sidebarMenu.projects'),
'url' => route('projects.index', ['site' => $site->slug]),
'active' => ('projects' == $currentSectionSlug && $site->slug == $currentSiteSlug)
];
}
$services = Page::where('code_name', '=', 'services')->first();
if(isset($services) && $services->active) {
$items[] = [
'name' => trans('kms/sidebarMenu.services'),
'url' => route('services.index', ['site' => $site->slug]),
'active' => ('services' == $currentSectionSlug && $site->slug == $currentSiteSlug)
];
}
$items[]= [
'name' => trans('kms/sidebarMenu.clients'),
'url' => route('clients.index', ['site' => $site->slug]),
'active' => ('clients' == $currentSectionSlug && $site->slug == $currentSiteSlug)
];
return $items;
}
}