src/Entity/ChannelMenu.php line 14

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use Doctrine\Common\Collections\ArrayCollection;
  4. use Doctrine\Common\Collections\Collection;
  5. use Doctrine\ORM\Mapping as ORM;
  6. /**
  7.  * @ORM\Entity(repositoryClass="App\Repository\ChannelMenuRepository")
  8.  *
  9.  * @ORM\HasLifecycleCallbacks()
  10.  */
  11. class ChannelMenu
  12. {
  13.     public function __construct()
  14.     {
  15.         $this->children = new ArrayCollection();
  16.     }
  17.     /**
  18.      * @ORM\Id()
  19.      *
  20.      * @ORM\GeneratedValue()
  21.      *
  22.      * @ORM\Column(type="integer")
  23.      */
  24.     private $id;
  25.     /**
  26.      * @ORM\Column(type="integer", nullable=false)
  27.      */
  28.     private $position 0;
  29.     /**
  30.      * @ORM\Column(type="string", nullable=false ,options={"default": "permanent"})
  31.      */
  32.     private $status;
  33.     /**
  34.      * @return mixed
  35.      */
  36.     public function getStatus()
  37.     {
  38.         return $this->status;
  39.     }
  40.     /**
  41.      * @param mixed $status
  42.      */
  43.     public function setStatus($status): void
  44.     {
  45.         $this->status $status;
  46.     }
  47.     public function getId(): ?int
  48.     {
  49.         return $this->id;
  50.     }
  51.     public function getPosition()
  52.     {
  53.         return $this->position;
  54.     }
  55.     public function setPosition($position)
  56.     {
  57.         $this->position $position;
  58.         return $this;
  59.     }
  60.     /**
  61.      * @ORM\Column(type="string", nullable=false, length=180)
  62.      */
  63.     private $name null;
  64.     public function getName()
  65.     {
  66.         return $this->name;
  67.     }
  68.     public function setName($name)
  69.     {
  70.         $this->name $name;
  71.         return $this;
  72.     }
  73.     /**
  74.      * @ORM\Column(type="string", nullable=true, length=180)
  75.      */
  76.     private $url null;
  77.     public function getUrl()
  78.     {
  79.         return $this->url;
  80.     }
  81.     public function setUrl($url)
  82.     {
  83.         $this->url $url;
  84.         return $this;
  85.     }
  86.     /**
  87.      * @ORM\Column(type="datetime", nullable=false)
  88.      */
  89.     private $created_at;
  90.     /**
  91.      * @ORM\Column(type="datetime", nullable=true)
  92.      */
  93.     private $updated_at null;
  94.     public function getCreatedAt(): \DateTimeInterface
  95.     {
  96.         return $this->created_at;
  97.     }
  98.     public function setCreatedAt(\DateTimeInterface $created_at): self
  99.     {
  100.         $this->created_at $created_at;
  101.         return $this;
  102.     }
  103.     public function getUpdatedAt(): ?\DateTimeInterface
  104.     {
  105.         return $this->updated_at;
  106.     }
  107.     public function setUpdatedAt(?\DateTimeInterface $updated_at): self
  108.     {
  109.         $this->updated_at $updated_at;
  110.         return $this;
  111.     }
  112.     /**
  113.      * @ORM\PrePersist
  114.      */
  115.     public function setCreatedAtValue()
  116.     {
  117.         $this->setCreatedAt(new \DateTime());
  118.     }
  119.     /**
  120.      * @ORM\PreUpdate
  121.      */
  122.     public function setUpdatedAtValue()
  123.     {
  124.         $this->setUpdatedAt(new \DateTime());
  125.     }
  126.     /**
  127.      * @ORM\Column(type="datetime", nullable=true)
  128.      */
  129.     private $deleted_at;
  130.     public function getDeletedAt(): ?\DateTimeInterface
  131.     {
  132.         return $this->deleted_at;
  133.     }
  134.     public function setDeletedAt(?\DateTimeInterface $deleted_at): self
  135.     {
  136.         $this->deleted_at $deleted_at;
  137.         return $this;
  138.     }
  139.     /**
  140.      * @ORM\ManyToOne(targetEntity="App\Entity\ChannelMenu", inversedBy="children")
  141.      *
  142.      * @ORM\JoinColumn(nullable=true)
  143.      */
  144.     private $parent null;
  145.     public function getParent(): ?self
  146.     {
  147.         return $this->parent;
  148.     }
  149.     public function setParent(?self $parent): self
  150.     {
  151.         $this->parent $parent;
  152.         return $this;
  153.     }
  154.     /**
  155.      * @ORM\OneToMany(targetEntity="App\Entity\ChannelMenu", mappedBy="parent")
  156.      */
  157.     private $children;
  158.     /**
  159.      * @ORM\ManyToOne(targetEntity="App\Entity\Category", inversedBy="menus")
  160.      */
  161.     private $category;
  162.     /**
  163.      * @ORM\ManyToOne(targetEntity="App\Entity\StaticPage", inversedBy="menus")
  164.      */
  165.     private $page;
  166.     /**
  167.      * @ORM\ManyToOne(targetEntity="App\Entity\Channel", inversedBy="menus")
  168.      *
  169.      * @ORM\JoinColumn(nullable=false)
  170.      */
  171.     private $channel;
  172.     /**
  173.      * @ORM\Column(type="string", length=255, nullable=true)
  174.      */
  175.     private $color;
  176.     /**
  177.      * @return Collection|ChannelMenu[]
  178.      */
  179.     public function getChildrens(): Collection
  180.     {
  181.         $children $this->children->toArray();
  182.         $children array_filter($children, function ($menu) {
  183.             return null === $menu->getDeletedAt();
  184.         });
  185.         usort($children, function ($a$b) {
  186.             return $a->getPosition() - $b->getPosition();
  187.         });
  188.         return new ArrayCollection($children);
  189.     }
  190.     public function addChildren(self $child): self
  191.     {
  192.         if (!$this->children->contains($child)) {
  193.             $this->children[] = $child;
  194.             $child->setParent($this);
  195.         }
  196.         return $this;
  197.     }
  198.     public function removeChildren(self $child): self
  199.     {
  200.         if ($this->children->contains($child)) {
  201.             $this->children->removeElement($child);
  202.             // set the owning side to null (unless already changed)
  203.             if ($child->getParent() === $this) {
  204.                 $child->setParent(null);
  205.             }
  206.         }
  207.         return $this;
  208.     }
  209.     public function getCategory(): ?Category
  210.     {
  211.         return $this->category;
  212.     }
  213.     public function setCategory(?Category $category): self
  214.     {
  215.         $this->category $category;
  216.         return $this;
  217.     }
  218.     public function getPage(): ?StaticPage
  219.     {
  220.         return $this->page;
  221.     }
  222.     public function setPage(?StaticPage $page): self
  223.     {
  224.         $this->page $page;
  225.         return $this;
  226.     }
  227.     public function getChannel(): ?Channel
  228.     {
  229.         return $this->channel;
  230.     }
  231.     public function setChannel(?Channel $channel): self
  232.     {
  233.         $this->channel $channel;
  234.         return $this;
  235.     }
  236.     public function getColor(): ?string
  237.     {
  238.         return $this->color;
  239.     }
  240.     public function setColor(?string $color): self
  241.     {
  242.         $this->color $color;
  243.         return $this;
  244.     }
  245. }