<?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\ChannelMenuRepository")
*
* @ORM\HasLifecycleCallbacks()
*/
class ChannelMenu
{
public function __construct()
{
$this->children = new ArrayCollection();
}
/**
* @ORM\Id()
*
* @ORM\GeneratedValue()
*
* @ORM\Column(type="integer")
*/
private $id;
/**
* @ORM\Column(type="integer", nullable=false)
*/
private $position = 0;
/**
* @ORM\Column(type="string", nullable=false ,options={"default": "permanent"})
*/
private $status;
/**
* @return mixed
*/
public function getStatus()
{
return $this->status;
}
/**
* @param mixed $status
*/
public function setStatus($status): void
{
$this->status = $status;
}
public function getId(): ?int
{
return $this->id;
}
public function getPosition()
{
return $this->position;
}
public function setPosition($position)
{
$this->position = $position;
return $this;
}
/**
* @ORM\Column(type="string", nullable=false, length=180)
*/
private $name = null;
public function getName()
{
return $this->name;
}
public function setName($name)
{
$this->name = $name;
return $this;
}
/**
* @ORM\Column(type="string", nullable=true, length=180)
*/
private $url = null;
public function getUrl()
{
return $this->url;
}
public function setUrl($url)
{
$this->url = $url;
return $this;
}
/**
* @ORM\Column(type="datetime", nullable=false)
*/
private $created_at;
/**
* @ORM\Column(type="datetime", nullable=true)
*/
private $updated_at = null;
public function getCreatedAt(): \DateTimeInterface
{
return $this->created_at;
}
public function setCreatedAt(\DateTimeInterface $created_at): self
{
$this->created_at = $created_at;
return $this;
}
public function getUpdatedAt(): ?\DateTimeInterface
{
return $this->updated_at;
}
public function setUpdatedAt(?\DateTimeInterface $updated_at): self
{
$this->updated_at = $updated_at;
return $this;
}
/**
* @ORM\PrePersist
*/
public function setCreatedAtValue()
{
$this->setCreatedAt(new \DateTime());
}
/**
* @ORM\PreUpdate
*/
public function setUpdatedAtValue()
{
$this->setUpdatedAt(new \DateTime());
}
/**
* @ORM\Column(type="datetime", nullable=true)
*/
private $deleted_at;
public function getDeletedAt(): ?\DateTimeInterface
{
return $this->deleted_at;
}
public function setDeletedAt(?\DateTimeInterface $deleted_at): self
{
$this->deleted_at = $deleted_at;
return $this;
}
/**
* @ORM\ManyToOne(targetEntity="App\Entity\ChannelMenu", inversedBy="children")
*
* @ORM\JoinColumn(nullable=true)
*/
private $parent = null;
public function getParent(): ?self
{
return $this->parent;
}
public function setParent(?self $parent): self
{
$this->parent = $parent;
return $this;
}
/**
* @ORM\OneToMany(targetEntity="App\Entity\ChannelMenu", mappedBy="parent")
*/
private $children;
/**
* @ORM\ManyToOne(targetEntity="App\Entity\Category", inversedBy="menus")
*/
private $category;
/**
* @ORM\ManyToOne(targetEntity="App\Entity\StaticPage", inversedBy="menus")
*/
private $page;
/**
* @ORM\ManyToOne(targetEntity="App\Entity\Channel", inversedBy="menus")
*
* @ORM\JoinColumn(nullable=false)
*/
private $channel;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $color;
/**
* @return Collection|ChannelMenu[]
*/
public function getChildrens(): Collection
{
$children = $this->children->toArray();
$children = array_filter($children, function ($menu) {
return null === $menu->getDeletedAt();
});
usort($children, function ($a, $b) {
return $a->getPosition() - $b->getPosition();
});
return new ArrayCollection($children);
}
public function addChildren(self $child): self
{
if (!$this->children->contains($child)) {
$this->children[] = $child;
$child->setParent($this);
}
return $this;
}
public function removeChildren(self $child): self
{
if ($this->children->contains($child)) {
$this->children->removeElement($child);
// set the owning side to null (unless already changed)
if ($child->getParent() === $this) {
$child->setParent(null);
}
}
return $this;
}
public function getCategory(): ?Category
{
return $this->category;
}
public function setCategory(?Category $category): self
{
$this->category = $category;
return $this;
}
public function getPage(): ?StaticPage
{
return $this->page;
}
public function setPage(?StaticPage $page): self
{
$this->page = $page;
return $this;
}
public function getChannel(): ?Channel
{
return $this->channel;
}
public function setChannel(?Channel $channel): self
{
$this->channel = $channel;
return $this;
}
public function getColor(): ?string
{
return $this->color;
}
public function setColor(?string $color): self
{
$this->color = $color;
return $this;
}
}