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/SBogers10/vebon.komma.pro/app/KommaApp/Kms/Composers/KmsSidebarMenuComposer.php
<?php namespace KommaApp\Kms\Composers;

/**
 *
 *
 * @author      Komma <info@komma.pro>
 * @copyright   (c) 2012-2016, Komma Mediadesign
 */

use KommaApp\Kms\Core\Kms;
use KommaApp\Orders\Models\Order;

class KmsSidebarMenuComposer
{
    protected $kms;

    public function __construct(Kms $kms)
    {
        $this->kms = $kms;
    }

    public function compose($view)
    {
        $viewData = $view->getData();

        $currentSiteSlug = $this->kms->getCurrentSiteSlug();

        //$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[] = [
                    'name' => $site->name,
                    'url' => route('kms.dashboard.index', ['site' => $site->slug]),
                    'active' => ($site->slug == $currentSiteSlug),
                    'subItems' => $this->getSiteSubItems($site, $currentSiteSlug, $currentSectionSlug)
                ];
            }
        }

        $view->with('menuStructure', $menuStructure);
    }

    protected function getCurrentSectionSlug()
    {
        $route = explode('/', \Route::current()->uri());
        if (\Route::current()->getParameter('site')) {
            return $route[2];
        }
        return isset($route[1]) ? $route[1] : null;
    }

    protected function getCurrentSectionSubSlug()
    {
        $route = explode('/', \Route::current()->uri());
        if (\Route::current()->getParameter('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'), 'active' => ('' == $currentSectionSlug)];

        if (in_array(\Auth::user()->get()->role, [1, 2, 3])) {
            $items[] = ['name' => \Lang::get('kms/SidebarMenu.users'), 'url' => route('kms.users.index'), 'active' => ('users' == $currentSectionSlug)];
        }

        if (in_array(\Auth::user()->get()->role, [4])) {
            $items[] = ['name' => \Lang::get('kms/SidebarMenu.my_profile'), 'url' => route('kms.users.update', [\Auth::user()->get()->id]), 'active' => ('users' == $currentSectionSlug)];
        }

        if (\Auth::user()->get()->role == 1) {
            $items[] = ['name' => \Lang::get('kms/SidebarMenu.translation'), 'url' => route('kms.translations.index'), 'active' => ('translations' == $currentSectionSlug)];
        }

        if (in_array(\Auth::user()->get()->role, [1, 2, 3])) {

            $items[] = ['name' => \Lang::get('kms/SidebarMenu.documentGroups'), 'url' => route('kms.base-document-groups.index'), 'active' => ('base-document-groups' == $currentSectionSlug)];
        }

        return $items;
    }

    /**
     * This will return the site specific items
     *
     * @param $site
     * @param $currentSiteSlug
     * @param $currentSectionSlug
     * @return array
     */
    protected function getSiteSubItems($site, $currentSiteSlug, $currentSectionSlug)
    {

        $items = [];


        $items[] = [
            'name' => \Lang::get('kms/SidebarMenu.members'),
            'url' => route('kms.{site}.members.index', ['site' => $site->slug]),
            'active' => ($site->slug == $currentSiteSlug) && ('members' == $currentSectionSlug)
        ];
        $items[] = [
            'name' => \Lang::get('kms/SidebarMenu.auditors'),
            'url' => route('kms.{site}.auditors.index', ['site' => $site->slug]),
            'active' => ($site->slug == $currentSiteSlug) && ('auditors' == $currentSectionSlug)
        ];


        return $items;
    }
}