HEX
Server: Microsoft-IIS/8.5
System: Windows NT YDAWBH120 6.3 build 9600 (Windows Server 2012 R2 Standard Edition) AMD64
User: tentjecom_web (0)
PHP: 7.4.14
Disabled: NONE
Upload Files
File: D:/HostingSpaces/stafa/werkenbijstafa.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\Kms\ActionLog\ActionLog;
use App\Komma\Shop\Bridges\SideBarShopMenuComposerBridge;
use App\Komma\Sites\Kms\SiteService;
use App\Komma\Sites\Models\Site;
use App\Komma\Sites\SiteServiceInterface;
use App\Komma\Users\Models\KmsUser;
use App\Komma\Users\Models\KmsUserRole;
use Illuminate\Notifications\Action;

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 = [];
        if (\Auth::user()->isAtLeast(KmsUserRole::SuperAdmin)) {
            $baseStructure = $this->getBaseItems($currentSectionSlug, $currentSectionSubSlug);
        }

        $menuStructure = array_merge($topStructure, $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.pages'),
            'url' => route('pages.index', ['siteSlug' => 'default']),
            'active' => ('pages' == $currentSectionSlug),
        ];

        $items[] = [
            'name' => trans('kms/sidebarMenu.jobs'),
            'url' => route('jobs.index'),
            'active' => ('jobs' == $currentSectionSlug),
        ];

        return $items;
    }

    /**
     * This functions will return the basic menu items
     *
     * @param $currentSectionSlug
     * @param $currentSectionSubSlug
     * @return array
     */
    protected function getBaseItems($currentSectionSlug, $currentSectionSubSlug)
    {
        $items = [];

        $items[] = [
            'is_separator' => true
        ];

        $items[] = [
            'name' => trans('kms/sidebarMenu.websiteconfig'),
            'url' => route('websiteconfig.index'),
            'active' => ('websiteconfig' == $currentSectionSlug),
        ];

        $items[] = [
            'name' => trans('kms/sidebarMenu.buttons'),
            'url' => route('buttons.index'),
            'active' => ('buttons' == $currentSectionSlug),
        ];

        $items[] = [
            'name' => trans('kms/sidebarMenu.servicepoints'),
            'url' => route('servicepoints.index'),
            'active' => ('servicepoints' == $currentSectionSlug),
        ];

        $items[] = [
            'name' => trans('kms/sidebarMenu.users'),
            'url' => route('kms_users.index'),
            'active' => ('kms_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 = [

        ];

        return $items;
    }
}