FleetCart/Modules/Menu/MegaMenu/SubMenu.php

58 lines
986 B
PHP
Raw Normal View History

2023-06-11 12:14:03 +00:00
<?php
namespace Modules\Menu\MegaMenu;
use Modules\Category\Entities\Category;
class SubMenu
{
private $subMenu;
private $subMenuItems;
2023-12-03 14:07:47 +00:00
2023-06-11 12:14:03 +00:00
public function __construct($subMenu)
{
$this->subMenu = $subMenu;
}
2023-12-03 14:07:47 +00:00
2023-06-11 12:14:03 +00:00
public function url()
{
return $this->subMenu->url();
}
2023-12-03 14:07:47 +00:00
2023-06-11 12:14:03 +00:00
public function target()
{
if ($this->subMenu instanceof Category) {
return '_self';
}
return $this->subMenu->target;
}
2023-12-03 14:07:47 +00:00
2023-06-11 12:14:03 +00:00
public function name()
{
return $this->subMenu->name;
}
2023-12-03 14:07:47 +00:00
2023-06-11 12:14:03 +00:00
public function hasItems()
{
return $this->items()->isNotEmpty();
}
2023-12-03 14:07:47 +00:00
2023-06-11 12:14:03 +00:00
public function items()
{
2023-12-03 14:07:47 +00:00
if (!is_null($this->subMenuItems)) {
2023-06-11 12:14:03 +00:00
return $this->subMenuItems;
}
return $this->subMenuItems = $this->subMenu->items->map(function ($item) {
return new SubMenu($item);
});
}
}