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/slenders.komma.pro/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\Categories\Models\Category;
use App\Komma\Shop\Bridges\SideBarShopMenuComposerBridge;
use App\Komma\Sites\Models\Site;
use App\Komma\Sites\SiteServiceInterface;

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 = $this->getBaseItems($currentSectionSlug, $currentSectionSubSlug);

        //Load all the available sites
        $sites = $this->siteService->getSites();

        $mainMenu = [];

        //If there is only one, merge the siteSub items, so it is not a sub menu
        if ( !config('app.multipleSites') || $sites->count() == 1) {
            $mainMenu = array_merge($baseStructure,
                $this->getSiteSubItems($sites->first(), $currentSiteSlug, $currentSectionSlug));
        } //If there are multiple sites, loop and ad these as an sub menu
        else {

            $siteMenus = [];

            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),
                    ];
                }
            }

            $mainMenu = array_merge($baseStructure, $siteMenus);
        }

        /**
         * Doesn't mean that if the environment setting shop is true the shop is installed
         * To install the shop, go to:
         * app / Komma / Shop / Readme.txt
         */
        $shopMenus = [];
        if (\Config::get('app.isShop')) {
            $shopMenus[] = [
                'name' => 'Shop',
                'subItems' => SideBarShopMenuComposerBridge::get($currentSectionSlug),
                'active' =>
                    ('products' == $currentSectionSlug) ||
                    ('productgroups' == $currentSectionSlug) ||
                    ('productcomposites' == $currentSectionSlug) ||
                    ('categories' == $currentSectionSlug) ||
                    (('orders' == $currentSectionSlug) || \Route::current()->getName() == 'orders.index' || \Route::current()->getName() == 'orders.show') ||
                    ('shipmentgroups' == $currentSectionSlug) ||
                    ('shipments' == $currentSectionSlug),
            ];
        }

        $menuStructure = array_merge($topStructure, $mainMenu, $shopMenus);
        $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' => ('' == $currentSectionSlug)
        ];
        $items[] = [
            'name' => trans('kms/sidebarMenu.kms_users'),
            'url' => route('kms_users.index'),
            'active' => ('kms_users' == $currentSectionSlug),
        ];

//        $items[] = [
//            'name' => trans('kms/sidebarMenu.users'),
//            'active' =>  ('kms_users' == $currentSectionSlug) || ('site_users' == $currentSectionSlug),
//            'subItems' => [
//                [
//                    'name' => trans('kms/sidebarMenu.kms_users'),
//                    'url' => route('kms_users.index'),
//                    'active' => ('kms_users' == $currentSectionSlug),
//                ],
//                [
//                    'name' => trans('kms/sidebarMenu.site_users'),
//                    'url' => route('site_users.index'),
//                    'active' => ('site_users' == $currentSectionSlug),
//                ]
//            ],
//        ];

        return $items;
    }

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

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

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

        if(auth()->user()->can('index', Category::class))
        {
            $items[] = [
                'name' => trans('kms/sidebarMenu.categories'),
                'url' => route('categories.index'),
                'active' => ('categories' == $currentSectionSlug),
            ];
        }



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

//        if (\Auth::user()->can('viewLogs', ActionLog::class)) {
//            $items[] = [
//                'name' => __('kms/actionlog.section.title'),
//                'url' => route('actionlog.index'),
//                'active' => ('actionlog' == $currentSectionSlug),
//            ];
//        }

        // Allow site(s) editing only for SuperAdmin
//        if (\Auth::user()->can('editSites', User::class)) {
//            $items[] = [
//                'name' => trans('kms/sidebarMenu.sites'),
//                'url' => route('sites.index'),
//                'active' => ('sites' == $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' => trans('kms/sidebarMenu.pages'),
                'url' => route('pages.index', ['siteSlug' => $site->slug]),
                'active' => ('pages' == $currentSectionSlug && $site->slug == $currentSiteSlug),
            ],
        ];

        return $items;
    }
}