<?php
namespace App\Entity;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
/**
* @ORM\Entity(repositoryClass="App\Repository\MenuItemRepository")
*/
class MenuItem
{
/**
* @ORM\Id()
* @ORM\GeneratedValue()
* @ORM\Column(type="bigint")
*/
private $id;
/**
* @ORM\Column(type="string", length=255)
*/
private $title;
/**
* @ORM\Column(type="text")
*/
private $description;
/**
* @ORM\Column(type="text")
*/
private $attributes;
/**
* @ORM\Column(type="integer")
*/
private $status;
/**
* @ORM\Column(type="integer")
*/
private $sort;
/**
* @ORM\Column(type="datetime")
*/
private $modified_at;
/**
* @ORM\Column(type="datetime")
*/
private $created_at;
/**
* @ORM\ManyToOne(targetEntity="App\Entity\Menu", inversedBy="menuItems")
* @ORM\JoinColumn(name="menu_id", referencedColumnName="id", onDelete="SET NULL")
*/
private $menu;
/**
* @ORM\ManyToOne(targetEntity="App\Entity\Link", cascade={"persist"})
* @ORM\JoinColumn(nullable=true)
*/
private $link;
/**
* @ORM\ManyToOne(targetEntity="App\Entity\MenuItem", inversedBy="children", cascade={"persist", "remove"})
* @ORM\JoinColumn(name="prnt_id", referencedColumnName="id")
*/
private $prnt;
/**
* @ORM\OneToMany(targetEntity="App\Entity\MenuItem", mappedBy="prnt", orphanRemoval=true, cascade={"persist", "remove"}, fetch="EAGER")
* @ORM\OrderBy({"sort" = "ASC"})
*/
private $children;
/**
* @ORM\ManyToOne(targetEntity="App\Entity\Media")
*/
private $image;
/**
* @ORM\Column(type="string", length=255)
*/
private $placeholder;
/**
* @ORM\Column(type="boolean")
*/
private $show_title;
public function __construct ()
{
$this->title = "";
$this->description = "";
$this->attributes = "";
$this->placeholder = "";
$this->status = 1;
$this->sort = 0;
$this->show_title = true;
$this->prnt = null;
$this->children = new ArrayCollection();
$this->modified_at = new \DateTime("now");
$this->created_at = new \DateTime("now");
}
public function getId()
{
return $this->id;
}
public function getTitle(): ?string
{
return $this->title;
}
public function setTitle(string $title = null): self
{
$this->title = $title ? $title : "";
return $this;
}
public function getDescription(): ?string
{
return $this->description;
}
public function setDescription(string $description = null): self
{
$this->description = $description ? $description : "";
return $this;
}
public function getAttributes(): ?string
{
return $this->attributes;
}
public function setAttributes(string $attributes = null): self
{
$this->attributes = $attributes ? $attributes : "";
return $this;
}
public function getModifiedAt(): ?\DateTimeInterface
{
return $this->modified_at;
}
public function setModifiedAt(\DateTimeInterface $modified_at = null): self
{
if (!$modified_at) {
$modified_at = new \DateTime("now");
}
$this->modifiedAt = $modified_at;
return $this;
}
public function getCreatedAt(): ?\DateTimeInterface
{
return $this->created_at;
}
public function setCreatedAt(\DateTimeInterface $created_at = null): self
{
if (!$created_at) {
$created_at = new \DateTime("now");
}
$this->created_at = $created_at;
return $this;
}
public function getStatus(): ?int
{
return $this->status;
}
public function setStatus(int $status): self
{
$this->status = $status;
return $this;
}
public function __toString ()
{
return "{$this->title}: {$this->description}";
}
public function getSort(): ?int
{
return $this->sort;
}
public function setSort(int $sort): self
{
$this->sort = $sort;
return $this;
}
public function getMenu(): ?Menu
{
return $this->menu;
}
public function setMenu(?Menu $menu = null): self
{
$this->menu = $menu;
return $this;
}
public function getLink(): ?Link
{
return $this->link;
}
public function setLink(?Link $link): self
{
$this->link = $link;
return $this;
}
public function getprnt (): ?MenuItem
{
return $this->prnt;
}
public function setprnt ($prnt = null): self
{
$this->prnt = $prnt;
return $this;
}
/**
* @return Collection|MenuItem[]
*/
public function getChildren(): Collection
{
return $this->children;
}
public function addChild(MenuItem $child): self
{
if (!$this->children->contains($child)) {
$this->children[] = $child;
$child->setprnt($this);
}
return $this;
}
public function removeChild(MenuItem $child): self
{
if ($this->children->contains($child)) {
$this->children->removeElement($child);
// set the owning side to null (unless already changed)
if ($child->getprnt() === $this) {
$child->setprnt(null);
}
}
return $this;
}
public function getImage(): ?Media
{
return $this->image;
}
public function setImage(?Media $image): self
{
$this->image = $image;
return $this;
}
public function getPlaceholder(): ?string
{
return $this->placeholder;
}
public function setPlaceholder(string $placeholder = null): self
{
$this->placeholder = $placeholder ? $placeholder : "";
return $this;
}
public function getShowTitle(): ?bool
{
return $this->show_title;
}
public function setShowTitle(bool $show_title): self
{
$this->show_title = $show_title;
return $this;
}
}