File: D:/HostingSpaces/ZelfVerkopen/zelfverkopen.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\Kms\Core\Kms;
use App\KommaApp\Kms\Core\KmsInterface;
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)
]
]
);
}
}
//Generate the base menu structure
$menuStructure = array_merge($menuStructure, $this->getBottomBaseItems($currentSectionSlug, $currentSectionSubSlug));
$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' => \Lang::get('kms/SidebarMenu.invoice'),
'subItems' => [
[
'name' => \Lang::get('kms/SidebarMenu.invoiceAll'),
'url' => route('orders.index'),
'active' => ('orders' == $currentSectionSlug && \Input::get('status', null) === null)
],
[
'name' => \Lang::get('kms/SidebarMenu.invoiceNew'),
'url' => route('orders.index').'?status=0',
'active' => ('orders' == $currentSectionSlug && \Input::get('status', null) === '0')
],
[
'name' => \Lang::get('kms/SidebarMenu.invoiceWorking'),
'url' => route('orders.index').'?status=1',
'active' => ('orders' == $currentSectionSlug && \Input::get('status', null) == 1)
],
[
'name' => \Lang::get('kms/SidebarMenu.invoiceAwaitingPayment'),
'url' => route('orders.index').'?status=2',
'active' => ('orders' == $currentSectionSlug && \Input::get('status', null) == 2)
],
[
'name' => \Lang::get('kms/SidebarMenu.invoiceInSale'),
'url' => route('orders.index').'?status=3',
'active' => ('orders' == $currentSectionSlug && \Input::get('status', null) == 3)
],
[
'name' => \Lang::get('kms/SidebarMenu.invoiceDone'),
'url' => route('orders.index').'?status=4',
'active' => ('orders' == $currentSectionSlug && \Input::get('status', null) == 4)
],
[
'name' => \Lang::get('kms/SidebarMenu.invoiceDeleted'),
'url' => route('orders.index').'?status=5',
'active' => ('orders' == $currentSectionSlug && \Input::get('status', null) == 5)
],
[
'name' => \Lang::get('kms/SidebarMenu.invoiceRefunded'),
'url' => route('orders.index').'?status=6',
'active' => ('orders' == $currentSectionSlug && \Input::get('status', null) == 6)
],
[
'name' => \Lang::get('kms/SidebarMenu.invoiceCredit'),
'url' => route('orders.index').'?status=7',
'active' => ('orders' == $currentSectionSlug && \Input::get('status', null) == 7)
],
[ 'name' => 'Exporteren',
'url' => route('asperion.index'),
'active' => ('asperion' == $currentSectionSlug) ]
],
'active' => ('orders' == $currentSectionSlug)
];
$items[] = [
'name' => \Lang::get('kms/SidebarMenu.customers'),
'url' => route('customers.index'),
'active' => ('customers' == $currentSectionSlug)
];
// $items[] = [
// 'name' => \Lang::get('kms/SidebarMenu.customerProperties'),
// 'url' => route('customerproperties.index'),
// 'active' => ('customerproperties' == $currentSectionSlug)
// ];
// // Allow site(s) editing only for SuperAdmin and when projects has multiple sites
// if (\Auth::user()->role->id == 1 && \Config::get('app.multipleSites')) {
// $items[] = [
// 'name' => 'Sites',
// 'url' => route('sites.index'),
// 'active' => ('sites' == $currentSectionSlug)
// ];
// }
$items[] =
[
'name' => \Lang::get('kms/SidebarMenu.blog'),
'subItems' => [
[
'name' => \Lang::get('kms/SidebarMenu.posts'),
'url' => route('posts.index'),
'active' => ('posts' == $currentSectionSlug)
],
[
'name' => \Lang::get('kms/SidebarMenu.postAuthors'),
'url' => route('postauthors.index'),
'active' => ('postauthors' == $currentSectionSlug)
],
[
'name' => \Lang::get('kms/SidebarMenu.postcategories'),
'url' => route('postcategories.index'),
'active' => ('postcategories' == $currentSectionSlug)
],
],
'active' => (in_array($currentSectionSlug, ['posts', 'postauthors', 'postcategories']))
];
$items[] = [
'name' => \Lang::get('kms/SidebarMenu.products'),
'url' => route('products.index'),
'active' => ('products' == $currentSectionSlug)
];
$items[] = [
'name' => \Lang::get('kms/SidebarMenu.vacancies'),
'url' => route('vacancies.index'),
'active' => ('vacancies' == $currentSectionSlug)
];
$items[] = [
'name' => \Lang::get('kms/SidebarMenu.tips'),
'url' => route('tips.index'),
'active' => ('tips' == $currentSectionSlug)
];
return $items;
}
/**
* This functions will return the basic menu items appended to the bottom
*
* @param $currentSectionSlug
* @param $currentSectionSubSlug
* @return array
*/
protected function getBottomBaseItems($currentSectionSlug, $currentSectionSubSlug)
{
$items = [];
$items[] = [
'name' => 'Instellingen',
'url' => route('sites.show', ['siteId' => 1]),
'active' => ('sites' == $currentSectionSlug)
];
$items[] = [
'name' => \Lang::get('kms/SidebarMenu.users'),
'url' => route('users.index'),
'active' => ('users' == $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 = [
[
'name' => \Lang::get('kms/SidebarMenu.pages'),
'url' => route('pages.index', ['site' => $site->slug]),
'active' => ('pages' == $currentSectionSlug && $site->slug == $currentSiteSlug)
],
[
'name' => \Lang::get('kms/SidebarMenu.landingpages'),
'url' => route('landingpages.index', ['site' => $site->slug]),
'active' => ('landingpages' == $currentSectionSlug && $site->slug == $currentSiteSlug)
],
[
'name' => \Lang::get('kms/SidebarMenu.services'),
'url' => route('services.index', ['site' => $site->slug]),
'active' => ('services' == $currentSectionSlug && $site->slug == $currentSiteSlug)
],
[
'name' => \Lang::get('kms/SidebarMenu.faq'),
'subItems' => [
[
'name' => \Lang::get('kms/SidebarMenu.faqQuestions'),
'url' => route('questions.index', ['site' => $site->slug]),
'active' => ('questions' == $currentSectionSlug && $site->slug == $currentSiteSlug)
],
[
'name' => \Lang::get('kms/SidebarMenu.faqCategories'),
'url' => route('questioncategories.index'),
'active' => ('questioncategories' == $currentSectionSlug),
],
],
'active' => (in_array($currentSectionSlug, ['questions', 'questioncategories']))
],
[
'name' => \Lang::get('kms/SidebarMenu.team'),
'url' => route('colleagues.index', ['site' => $site->slug]),
'active' => ('colleagues' == $currentSectionSlug && $site->slug == $currentSiteSlug)
],
[
'name' => \Lang::get('kms/SidebarMenu.references'),
'url' => route('references.index', ['site' => $site->slug]),
'active' => ('references' == $currentSectionSlug && $site->slug == $currentSiteSlug)
]
];
// $items = array_merge($items, SideBarShopMenuComposerBridge::get($currentSectionSlug, $site));
return $items;
}
}