first upload all files
This commit is contained in:
31
Modules/Menu/MegaMenu/MegaMenu.php
Normal file
31
Modules/Menu/MegaMenu/MegaMenu.php
Normal file
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Menu\MegaMenu;
|
||||
|
||||
use Illuminate\Support\Facades\Cache;
|
||||
use Modules\Menu\Entities\Menu as MenuModel;
|
||||
|
||||
class MegaMenu
|
||||
{
|
||||
private $menuId;
|
||||
|
||||
public function __construct($menuId)
|
||||
{
|
||||
$this->menuId = $menuId;
|
||||
}
|
||||
|
||||
public function menus()
|
||||
{
|
||||
return Cache::tags(['mega_menu', 'menu_items', 'pages', 'categories'])
|
||||
->rememberForever(md5("mega_menu.{$this->menuId}:" . locale()), function () {
|
||||
return $this->getMenus()->map(function ($menu) {
|
||||
return new Menu($menu);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
private function getMenus()
|
||||
{
|
||||
return MenuModel::for($this->menuId)->where('menu_id', $this->menuId);
|
||||
}
|
||||
}
|
||||
89
Modules/Menu/MegaMenu/Menu.php
Normal file
89
Modules/Menu/MegaMenu/Menu.php
Normal file
@@ -0,0 +1,89 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Menu\MegaMenu;
|
||||
|
||||
use Modules\Category\Entities\Category;
|
||||
|
||||
class Menu
|
||||
{
|
||||
private $menu;
|
||||
private $subMenus;
|
||||
|
||||
public function __construct($menu)
|
||||
{
|
||||
$this->menu = $menu;
|
||||
}
|
||||
|
||||
public function isFluid()
|
||||
{
|
||||
return $this->menu->is_fluid;
|
||||
}
|
||||
|
||||
public function url()
|
||||
{
|
||||
return $this->menu->url();
|
||||
}
|
||||
|
||||
public function hasIcon()
|
||||
{
|
||||
return ! is_null($this->icon());
|
||||
}
|
||||
|
||||
public function icon()
|
||||
{
|
||||
return $this->menu->icon;
|
||||
}
|
||||
|
||||
public function hasBackgroundImage()
|
||||
{
|
||||
return ! is_null($this->backgroundImage());
|
||||
}
|
||||
|
||||
public function backgroundImage()
|
||||
{
|
||||
return $this->menu->background_image->path;
|
||||
}
|
||||
|
||||
public function target()
|
||||
{
|
||||
return $this->menu->target;
|
||||
}
|
||||
|
||||
public function name()
|
||||
{
|
||||
return $this->menu->name;
|
||||
}
|
||||
|
||||
public function hasSubMenus()
|
||||
{
|
||||
return $this->subMenus()->isNotEmpty();
|
||||
}
|
||||
|
||||
public function subMenus()
|
||||
{
|
||||
if (! is_null($this->subMenus)) {
|
||||
return $this->subMenus;
|
||||
}
|
||||
|
||||
return $this->subMenus = $this->getSubMenus()->map(function ($subMenu) {
|
||||
return new SubMenu($subMenu);
|
||||
});
|
||||
}
|
||||
|
||||
private function getSubMenus()
|
||||
{
|
||||
if ($this->menu->isCategoryType()) {
|
||||
return $this->getCategorySubMenus();
|
||||
}
|
||||
|
||||
return $this->menu->items ?? collect();
|
||||
}
|
||||
|
||||
private function getCategorySubMenus()
|
||||
{
|
||||
return Category::tree()
|
||||
->where('id', $this->menu->category_id)
|
||||
->first()
|
||||
->items ?? collect();
|
||||
}
|
||||
}
|
||||
51
Modules/Menu/MegaMenu/SubMenu.php
Normal file
51
Modules/Menu/MegaMenu/SubMenu.php
Normal file
@@ -0,0 +1,51 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Menu\MegaMenu;
|
||||
|
||||
use Modules\Category\Entities\Category;
|
||||
|
||||
class SubMenu
|
||||
{
|
||||
private $subMenu;
|
||||
private $subMenuItems;
|
||||
|
||||
public function __construct($subMenu)
|
||||
{
|
||||
$this->subMenu = $subMenu;
|
||||
}
|
||||
|
||||
public function url()
|
||||
{
|
||||
return $this->subMenu->url();
|
||||
}
|
||||
|
||||
public function target()
|
||||
{
|
||||
if ($this->subMenu instanceof Category) {
|
||||
return '_self';
|
||||
}
|
||||
|
||||
return $this->subMenu->target;
|
||||
}
|
||||
|
||||
public function name()
|
||||
{
|
||||
return $this->subMenu->name;
|
||||
}
|
||||
|
||||
public function hasItems()
|
||||
{
|
||||
return $this->items()->isNotEmpty();
|
||||
}
|
||||
|
||||
public function items()
|
||||
{
|
||||
if (! is_null($this->subMenuItems)) {
|
||||
return $this->subMenuItems;
|
||||
}
|
||||
|
||||
return $this->subMenuItems = $this->subMenu->items->map(function ($item) {
|
||||
return new SubMenu($item);
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user