File: D:/HostingSpaces/SBogers10/topswtw.komma.pro/app/KommaApp/Shop/Menus/Menu.php
<?php
namespace KommaApp\Shop\menus;
use Illuminate\Routing\Router;
class Menu
{
/**
* @var MenuRepository
*/
protected $menuRepository;
/**
* @var Router
*/
protected $router;
/**
* @var Int
*/
protected $languageId;
/**
* @var Int
*/
protected $shopId;
/**
* @var array
*/
protected $routeData;
/**
* @var Array
*/
protected $menuItems;
/**
* @param MenuRepository $menuRepository
* @param Router $router
*/
public function __construct(MenuRepository $menuRepository, Router $router)
{
$this->menuRepository = $menuRepository;
$this->router = $router;
}
/**
* @param mixed $shopId
*/
public function setShopId($shopId)
{
$this->shopId = $shopId;
}
/**
* @param mixed $languageId
*/
public function setLanguageId($languageId)
{
$this->languageId = $languageId;
}
/**
* @param $currentRoutableId
*/
public function setRouteData($routeData)
{
$this->routeData = $routeData;
}
/**
* @param array $items
* @param string $keyType
* @return array
*/
protected function stripDoubleRoutes(array $items, $keyType = 'id')
{
$menuItems = [];
$checkForRoutes = [];
foreach($items as $item)
{
$addItem = true;
// If this item already exists with a different route
if(isset($checkForRoutes[$item->{$keyType}]))
{
$addItem = false;
$existingRoute = $checkForRoutes[$item->{$keyType}];
// Always make sure the shortest route is added to the array
if(strlen($item->route) < strlen($existingRoute))
{
$addItem = true;
}
}
// Do we need to add / update this item to the array?
if($addItem)
{
$menuItems[$item->{$keyType}] = $item;
// Also update the array $checkForRoutes
$checkForRoutes[$item->{$keyType}] = $item->route;
}
}
return $menuItems;
}
}