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/Neopoints/momsecurity.be/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\User;
use Illuminate\Notifications\Action;

class SidebarMenuComposer
{
    /** @var SiteServiceInterface $siteService  */
    protected $siteService;

    public function __construct()
    {
        $this->siteService = \App::make(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
        $menuStructure = $this->getBaseItems($currentSectionSlug, $currentSectionSubSlug);

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

        $siteMenus = [];
        //If there is only one, merge the siteSub items, so 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) {
                //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)
                    ];
                }
            }
        }

        $menuStructure = array_merge($menuStructure, $siteMenus);
        $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)
        ];
//
//        $items[] = [
//            'name' => trans('kms/sidebarMenu.posts'),
//            'url' => route('posts.index'),
//            'active' => ('posts' == $currentSectionSlug)
//        ];
//
//        $items[] = [
//            'name' => __('kms/transfer.transfer'),
//            'url' => route('transfer.index'),
//            'active' => ('transfer' == $currentSectionSlug)
//        ];

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

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

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

        /**
         * 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
         */
        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 = [
            [
                'name' => trans('kms/sidebarMenu.pages'),
                'url' => route('pages.index', ['siteSlug' => $site->slug]),
                'active' => ('pages' == $currentSectionSlug && $site->slug == $currentSiteSlug)
            ],
        ];

        return $items;
    }
}