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/topswtwmobile.komma.pro/app/KommaApp/Shop/Menus/ShopMenu.php
<?php


namespace KommaApp\Shop\menus;


use Jenssegers\Agent\Facades\Agent;

class ShopMenu extends Menu
{
    /*
     * @var Array
     * $menus = [
     *    shopId => [
     *      menuType => [pages.id, pages.id, pages.id, etc]
     *    ]
     * ]
     */
    protected $menus = [
        1 => [
            'main' => ['home', 'brands', 'company', 'information', 'contact'],
            'footer' => ['home', 'brands', 'company', 'information', 'contact', 'disclaimer', 'terms', 'sitemap'],
            'info' => ['discount', 'reminderService', 'returnPolicy', 'payment_shipping', 'replacement', 'ventilation'],
            'footer-mobile' => ['brands', 'information', 'company']
        ],
        2 => [
            'main' => ['home', 'brands', 'company', 'information', 'contact'],
            'footer' => ['home', 'brands', 'company', 'information', 'contact', 'disclaimer', 'terms', 'sitemap'],
            'info' => ['discount', 'reminderService', 'returnPolicy', 'payment_shipping', 'replacement', 'ventilation'],
            'footer-mobile' => ['brands', 'information', 'company']
        ],
        3 => [
            'main' => ['home', 'brands', 'company', 'information', 'contact'],
            'footer' => ['home', 'brands', 'company', 'information', 'contact', 'disclaimer', 'terms', 'sitemap'],
            'info' => ['discount', 'reminderService', 'returnPolicy', 'payment_shipping', 'replacement', 'ventilation'],
            'footer-mobile' => ['brands', 'information', 'company']
        ],
        'NL' => [
            'main' => ['home', 'brands', 'company', 'information', 'contact'],
            'footer' => ['home', 'brands', 'company', 'information', 'contact', 'disclaimer', 'terms', 'sitemap'],
            'info' => ['discount', 'reminderService', 'returnPolicy', 'payment_shipping', 'replacement', 'ventilation']
            // Remove Maintenance
            //'main' => ['home', 'brands', 'maintenanceOverview', 'company', 'information', 'contact'],
            //'footer' => ['home', 'brands', 'maintenanceOverview', 'company', 'information', 'contact', 'disclaimer', 'terms', 'sitemap'],
        ],

    ];

    //protected $ghostPages = ['ventilation'];

    /**
     * @param $menuType
     * @return string $listItems
     */
    public function getUnsortedList($menuType)
    {
        // Reset menu to prevent stacking
        $this->menuItems = [];

        // Refill the menuItems property
        $this->setMenuItems($menuType);

        // Create output
        $listItems = '';
        foreach ($this->menuItems as $item) {

            //skip maintenance in mobile for time being
            if( Agent::isMobile() && $item->codeName == 'maintenanceOverview') continue;

            $listItems .= '<li';

            if (((strpos($this->router->currentRouteName(), $item->route) !== false) &&
                    $item->codeName != 'home') ||
                $this->router->currentRouteName() == '/' . $item->route
            ) {
                $listItems .= ' class="active"';
            }
            // Exception for brands
            if ($item->codeName == 'brands') {
                $routableType = \Shop::getRouteData()->routable_type;

                $brandTypes = [
                    'Komma\Kms\Categories\Models\CategoryTranslation',
                    'Komma\Kms\Products\Models\ShopProductTranslation'
                ];

                if (in_array($routableType, $brandTypes)) $listItems .= ' class="active"';
            }


            //if($this->router->currentRouteName() == '/'.$item->route) $listItems .= ' class="active"';
            $listItems .= '>';



            $listItems .= '<a href="/' . $item->route . '">';

            if($menuType == 'footer-mobile') $listItems .= trans('mobile.pages.'.$item->codeName);
            else $listItems .= $item->name;

            $listItems .= '</a>';
            $listItems .= '</li>';
        }

        return $listItems;
    }

    /**
     * Set the menu items to an array with PageObjects
     * @param $menuType
     */
    public function setMenuItems($menuType)
    {
        // Get page ids from menu type in current shop
        $slugs = $this->getPageSlugs($menuType);

        // Get items from the database in the current language
        $allMenuItems = $this->menuRepository->getMenuItemsBySlugs($slugs, $this->languageId);

        // Some ids are double because multiple routes go to that page
        // Make sure we only keep the item with the shortest route
        $usedMenuItems = $this->stripDoubleRoutes($allMenuItems, 'codeName');

        /*
        // Ghost pages
        foreach($usedMenuItems as &$item)
        {
            if( in_array($item->codeName,$this->ghostPages) )
            {
                $firstChild = $this->menuRepository->getMenuItemsFirstChild($item,$this->languageId);
                $newItem = $firstChild;
                $newItem->name = $item->name;
                $item = $newItem;
            }
        }*/

        // Set the correct order as specified in pageIds
        foreach ($slugs as $slug) {
            if (isset($usedMenuItems[$slug])) {
                $this->menuItems[] = $usedMenuItems[$slug];
            }
        }
    }

    /**
     * @param $menuType
     * @return array
     */
    protected function getPageSlugs($menuType)
    {
        //Check if there is a menu for the specific domain country eg NL
        if (isset($this->menus[\Shop::getDomainCountry()][$menuType])) {
            //Yes, return these
            return $this->menus[\Shop::getDomainCountry()][$menuType];
        }

        //Check if there is a menu for the shopId
        if (isset($this->menus[\Shop::getId()][$menuType])) {
            //Yes, return this
            return $this->menus[\Shop::getId()][$menuType];
        }
        return [];
    }
}