src/Flexy/FrontBundle/Entity/Menu.php line 16
<?php
namespace App\Flexy\FrontBundle\Entity;
use ApiPlatform\Core\Annotation\ApiResource;
use App\Flexy\FrontBundle\Repository\MenuRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Gedmo\Mapping\Annotation as Gedmo;
use Doctrine\Common\Collections\Criteria;
#[ApiResource]
#[ORM\Entity(repositoryClass: MenuRepository::class)]
class Menu
{
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column(type: 'integer')]
private $id;
#[ORM\Column(type: 'string', length: 255)]
private ?string $name = null;
#[ORM\Column(type: 'string', length: 255, nullable: true)]
private $cssClasses;
#[ORM\Column(type: 'datetime', nullable: true)]
private ?\DateTimeInterface $createdAt = null;
#[ORM\Column(type: 'boolean', nullable: true)]
private ?bool $isMainMenu = null;
#[ORM\OneToMany(targetEntity: MenuItem::class, mappedBy: 'menu', orphanRemoval: true, cascade: ['persist'])]
private \Doctrine\Common\Collections\Collection|array $menuItems;
public function __construct()
{
$this->menuItems = new ArrayCollection();
}
public function getId(): ?int
{
return $this->id;
}
public function getName(): ?string
{
return $this->name;
}
public function setName(string $name): self
{
$this->name = $name;
return $this;
}
public function getCreatedAt(): ?\DateTimeInterface
{
return $this->createdAt;
}
public function setCreatedAt(?\DateTimeInterface $createdAt): self
{
$this->createdAt = $createdAt;
return $this;
}
public function getIsMainMenu(): ?bool
{
return $this->isMainMenu;
}
public function setIsMainMenu(?bool $isMainMenu): self
{
$this->isMainMenu = $isMainMenu;
return $this;
}
/**
* @return Collection<int, MenuItem>
*/
public function getMenuItems(): Collection
{
$criteria = Criteria::create()
->where(Criteria::expr()->eq('parentMenuItem', null))
->orderBy(["position"=>"ASC"]);
return $this->menuItems->matching($criteria);
}
public function addMenuItem(MenuItem $menuItem): self
{
if (!$this->menuItems->contains($menuItem)) {
$this->menuItems[] = $menuItem;
$menuItem->setMenu($this);
}
return $this;
}
public function removeMenuItem(MenuItem $menuItem): self
{
if ($this->menuItems->removeElement($menuItem)) {
// set the owning side to null (unless already changed)
if ($menuItem->getMenu() === $this) {
$menuItem->setMenu(null);
}
}
return $this;
}
/**
* Get the value of cssClasses
*/
public function getCssClasses()
{
return $this->cssClasses;
}
/**
* Set the value of cssClasses
*
* @return self
*/
public function setCssClasses($cssClasses)
{
$this->cssClasses = $cssClasses;
return $this;
}
}