<?php
namespace App\Entity\Content;
use Symfony\Component\Validator\Constraints AS Constraints;
use Symfony\Component\Validator\Constraints AS Assert;
use Doctrine\ORM\Mapping AS ORM;
use Ramsey\Uuid\Uuid;
/**
* @ORM\Entity(repositoryClass="App\Repository\Content\MenuRepository")
* @ORM\Table(name="content_menu")
*/
class Menu
{
/**
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
* @ORM\Column(type="integer")
*/
private $id;
/**
* @ORM\Column(type="uuid")
* @Assert\Uuid
*/
protected $uuid;
/**
* @var \DateTime
*
* @ORM\Column(type="datetime", nullable=false)
*/
private $created;
/**
* @var \DateTime
*
* @ORM\Column(type="datetime", nullable=false)
*/
private $modified;
/**
* @ORM\Column(type="string", length=60, nullable=false)
*/
private $identifier;
/**
* @ORM\Column(type="string", length=60, nullable=false)
*/
private $name;
/**
* @ORM\Column(type="boolean", nullable=true)
*/
private $isLocked;
/**
* @ORM\Column(type="boolean", nullable=true)
*/
private $disableChildItems;
/**
* @ORM\OneToMany(targetEntity="MenuItem", mappedBy="menu", cascade={"all"})
* @ORM\OrderBy({"displayOrder" = "ASC"})
**/
private $menuItems;
/**
* @ORM\ManyToOne(targetEntity="\App\Entity\Settings\Language")
**/
private $language;
public function __construct()
{
// UUID
if(!$this->getUuid())
{
$uuid = Uuid::uuid1();
$this->setUuid($uuid->toString());
}
// Set some defaults
$this->setCreated(new \DateTime());
$this->setModified(new \DateTime());
if(!$this->getIsLocked())
$this->setIsLocked(false);
if(!$this->getDisableChildItems())
$this->setDisableChildItems(false);
$this->menuItems = array();
}
public function getTopLevelMenuItems()
{
$menuItemAray = array();
$menuItems = $this->getMenuItems();
if(!count($menuItems))
return $menuItemAray;
// Loop items
foreach($menuItems AS $someItem)
{
if(!$someItem->getParent())
$menuItemAray[] = $someItem;
}
return $menuItemAray;
}
public function __toString()
{
return $this->getName();
}
public function getId()
{
return $this->id;
}
public function setUuid($uuid)
{
$this->uuid = $uuid;
return $this;
}
public function getUuid()
{
return $this->uuid;
}
public function setCreated(\DateTime $created)
{
$this->created = $created;
}
public function getCreated()
{
return $this->created;
}
public function setModified(\DateTime $modified)
{
$this->modified = $modified;
}
public function getModified()
{
return $this->modified;
}
public function getName()
{
return $this->name;
}
public function setName(string $name)
{
$this->name = $name;
}
public function getIdentifier()
{
return $this->identifier;
}
public function setIdentifier(string $identifier)
{
$this->identifier = $identifier;
}
public function getIsLocked()
{
return $this->isLocked;
}
public function setIsLocked($isLocked)
{
$this->isLocked = $isLocked;
}
public function getDisableChildItems()
{
return $this->disableChildItems;
}
public function setDisableChildItems($disableChildItems)
{
$this->disableChildItems = $disableChildItems;
}
public function addMenuItem(\App\Entity\Content\MenuItem $menuItem)
{
if(!in_array($menuItem, (array)$this->menuItems))
$this->menuItems[] = $menuItem;
if($menuItem->getMenu() != $this)
$menuItem->setMenu($this);
return $this;
}
public function removeMenuItem(\App\Entity\Content\MenuItem $menuItem)
{
$this->menuItems->removeElement($menuItem);
$menuItem->setMenu(null);
}
public function getMenuItems()
{
return $this->menuItems;
}
public function setLanguage(\App\Entity\Settings\Language $language = null)
{
$this->language = $language;
}
public function getLanguage()
{
return $this->language;
}
}