File: D:/HostingSpaces/SBogers10/kooken.komma.pro/vendor/komma/kms/src/Menu/Item.php
<?php declare(strict_types=1);
namespace Komma\KMS\Menu;
/**
* Class Item
*
* Represents a menu item
*
* @package Komma\KMS\Menu
*/
class Item
{
/** @var string $name */
protected $name = '';
/** @var bool */
protected $isSeparator = false;
/** @var bool */
protected $isActive = false;
/** @var Item */
protected $parent;
/** @var Item[] */
protected $subItems = [];
/** @var string */
protected $url = '#';
protected $sortOrder = -1;
/**
* @var string[]
*/
private $slugs = [];
/**
* @return string
*/
public function getName(): string
{
return $this->name;
}
/**
* @param string $name
* @return Item
*/
public function setName(string $name): Item
{
$this->name = $name;
return $this;
}
/**
* @return bool
*/
public function isSeparator(): bool
{
return $this->isSeparator;
}
/**
* @param bool $isSeparator
* @return Item
*/
public function setIsSeparator(bool $isSeparator): Item
{
$this->isSeparator = $isSeparator;
return $this;
}
/**
* @return bool
*/
public function isActive(): bool
{
return $this->isActive;
}
/**
* @param bool $isActive
* @return Item
*/
public function setIsActive(bool $isActive): Item
{
$this->isActive = $isActive;
return $this;
}
/**
* @return Item[]
*/
public function getSubItems(): array
{
return $this->subItems;
}
/**
* @param Item[] $subItems
* @return Item
*/
public function setSubItems(array $subItems): Item
{
$this->subItems = [];
foreach($subItems as $subItem) $this->addSubItem($subItem, $this);
return $this;
}
/**
* @param Item $subItem
* @return $this
*/
public function addSubItem(Item $subItem)
{
$subItem->parent = $this;
$this->subItems[] = $subItem;
return $this;
}
public function hasSubItems(): bool
{
return count($this->subItems) > 0;
}
/**
* @return string
*/
public function getUrl(): string
{
return $this->url;
}
/**
* @param string $url
* @return Item
*/
public function setUrl(string $url): Item
{
$this->url = $url;
return $this;
}
/**
* @param string $string
* @return Item
*/
public function setSlug(string $string)
{
$this->slugs = [$string];
return $this;
}
/**
* @param array $slugs
* @return Item
*/
public function setSlugs(array $slugs)
{
foreach($slugs as $slug) $this->addSlug($slug);
return $this;
}
/**
* @param string $slug
*/
public function addSlug(string $slug)
{
$this->slugs[] = $slug;
}
/**
* @return string[]
*/
public function getSlugs(): array
{
return $this->slugs;
}
/**
* @return string
*/
public function getSlug(): string
{
if(count($this->slugs) == 0) return '';
else return $this->slugs[0];
}
/**
* @return bool
*/
public function hasSlugs(): bool
{
return (count($this->slugs) != 0);
}
/**
* @return bool
*/
public function hasActiveSubItems(): bool
{
foreach($this->subItems as $subItem) {
if($subItem->isActive()) return true;
}
return false;
}
/**
* @param Item $item
*/
private function checkIfItemHasActiveSubItems(Item $item)
{
if(!$this->hasSubItems()) return;
foreach($this->subItems as $subItem) {
if($subItem->isActive()) return true;
if($subItem->hasSubItems() && $this->checkIfItemHasActiveSubItems($subItem)) return true;
}
return false;
}
/**
* @return {bool}
*/
public function hasParent(): bool
{
return !!$this->parent;
}
/**
* @return Item|null
*/
public function getParent(): ?Item
{
return $this->parent;
}
/**
* @return int
*/
public function getSortOrder(): int
{
return $this->sortOrder;
}
/**
* @param int $sortOrder
* @return Item
*/
public function setSortOrder(int $sortOrder): Item
{
$this->sortOrder = $sortOrder;
return $this;
}
}