src/Entity/MenuItem.php line 12

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\MenuItemRepository")
  8.  */
  9. class MenuItem
  10. {
  11.     /**
  12.      * @ORM\Id()
  13.      * @ORM\GeneratedValue()
  14.      * @ORM\Column(type="bigint")
  15.      */
  16.     private $id;
  17.     /**
  18.      * @ORM\Column(type="string", length=255)
  19.      */
  20.     private $title;
  21.     /**
  22.      * @ORM\Column(type="text")
  23.      */
  24.     private $description;
  25.     /**
  26.      * @ORM\Column(type="text")
  27.      */
  28.     private $attributes;
  29.     /**
  30.      * @ORM\Column(type="integer")
  31.      */
  32.     private $status;
  33.     /**
  34.      * @ORM\Column(type="integer")
  35.      */
  36.     private $sort;
  37.     /**
  38.      * @ORM\Column(type="datetime")
  39.      */
  40.     private $modified_at;
  41.     /**
  42.      * @ORM\Column(type="datetime")
  43.      */
  44.     private $created_at;
  45.     /**
  46.      * @ORM\ManyToOne(targetEntity="App\Entity\Menu", inversedBy="menuItems")
  47.      * @ORM\JoinColumn(name="menu_id", referencedColumnName="id", onDelete="SET NULL")
  48.      */
  49.     private $menu;
  50.     /**
  51.      * @ORM\ManyToOne(targetEntity="App\Entity\Link", cascade={"persist"})
  52.      * @ORM\JoinColumn(nullable=true)
  53.      */
  54.     private $link;
  55.     /**
  56.      * @ORM\ManyToOne(targetEntity="App\Entity\MenuItem", inversedBy="children", cascade={"persist", "remove"})
  57.      * @ORM\JoinColumn(name="prnt_id", referencedColumnName="id")
  58.      */
  59.     private $prnt;
  60.     /**
  61.      * @ORM\OneToMany(targetEntity="App\Entity\MenuItem", mappedBy="prnt", orphanRemoval=true, cascade={"persist", "remove"}, fetch="EAGER")
  62.      * @ORM\OrderBy({"sort" = "ASC"})
  63.      */
  64.     private $children;
  65.     /**
  66.      * @ORM\ManyToOne(targetEntity="App\Entity\Media")
  67.      */
  68.     private $image;
  69.     /**
  70.      * @ORM\Column(type="string", length=255)
  71.      */
  72.     private $placeholder;
  73.     /**
  74.      * @ORM\Column(type="boolean")
  75.      */
  76.     private $show_title;
  77.     
  78.     public function __construct ()
  79.     {
  80.         $this->title "";
  81.         $this->description "";
  82.         $this->attributes "";
  83.         $this->placeholder "";
  84.         $this->status 1;
  85.         $this->sort 0;
  86.         $this->show_title true;
  87.         
  88.         $this->prnt null;
  89.         $this->children = new ArrayCollection();
  90.         
  91.         $this->modified_at = new \DateTime("now");
  92.         $this->created_at = new \DateTime("now");
  93.         
  94.     }
  95.     public function getId()
  96.     {
  97.         return $this->id;
  98.     }
  99.     public function getTitle(): ?string
  100.     {
  101.         return $this->title;
  102.     }
  103.     public function setTitle(string $title null): self
  104.     {
  105.         $this->title $title $title "";
  106.         return $this;
  107.     }
  108.     public function getDescription(): ?string
  109.     {
  110.         return $this->description;
  111.     }
  112.     public function setDescription(string $description null): self
  113.     {
  114.         $this->description $description $description "";
  115.         return $this;
  116.     }
  117.     public function getAttributes(): ?string
  118.     {
  119.         return $this->attributes;
  120.     }
  121.     public function setAttributes(string $attributes null): self
  122.     {
  123.         $this->attributes $attributes $attributes "";
  124.         return $this;
  125.     }
  126.     public function getModifiedAt(): ?\DateTimeInterface
  127.     {
  128.         return $this->modified_at;
  129.     }
  130.     public function setModifiedAt(\DateTimeInterface $modified_at null): self
  131.     {
  132.         if (!$modified_at) {
  133.             $modified_at = new \DateTime("now");
  134.         }
  135.         
  136.         $this->modifiedAt $modified_at;
  137.         return $this;
  138.     }
  139.     public function getCreatedAt(): ?\DateTimeInterface
  140.     {
  141.         return $this->created_at;
  142.     }
  143.     public function setCreatedAt(\DateTimeInterface $created_at null): self
  144.     {
  145.         if (!$created_at) {
  146.             $created_at = new \DateTime("now");
  147.         }
  148.         
  149.         $this->created_at $created_at;
  150.         return $this;
  151.     }
  152.     public function getStatus(): ?int
  153.     {
  154.         return $this->status;
  155.     }
  156.     public function setStatus(int $status): self
  157.     {
  158.         $this->status $status;
  159.         return $this;
  160.     }
  161.     public function __toString ()
  162.     {
  163.         return "{$this->title}{$this->description}";
  164.     }
  165.     public function getSort(): ?int
  166.     {
  167.         return $this->sort;
  168.     }
  169.     public function setSort(int $sort): self
  170.     {
  171.         $this->sort $sort;
  172.         return $this;
  173.     }
  174.     public function getMenu(): ?Menu
  175.     {
  176.         return $this->menu;
  177.     }
  178.     public function setMenu(?Menu $menu null): self
  179.     {
  180.         $this->menu $menu;
  181.         return $this;
  182.     }
  183.     public function getLink(): ?Link
  184.     {
  185.         return $this->link;
  186.     }
  187.     public function setLink(?Link $link): self
  188.     {
  189.         $this->link $link;
  190.         return $this;
  191.     }
  192.     public function getprnt (): ?MenuItem
  193.     {
  194.         return $this->prnt;
  195.     }
  196.     
  197.     public function setprnt ($prnt null): self
  198.     {
  199.         $this->prnt $prnt;
  200.         
  201.         return $this;
  202.     }
  203.     /**
  204.      * @return Collection|MenuItem[]
  205.      */
  206.     public function getChildren(): Collection
  207.     {
  208.         return $this->children;
  209.     }
  210.     public function addChild(MenuItem $child): self
  211.     {
  212.         if (!$this->children->contains($child)) {
  213.             $this->children[] = $child;
  214.             $child->setprnt($this);
  215.         }
  216.         return $this;
  217.     }
  218.     public function removeChild(MenuItem $child): self
  219.     {
  220.         if ($this->children->contains($child)) {
  221.             $this->children->removeElement($child);
  222.             // set the owning side to null (unless already changed)
  223.             if ($child->getprnt() === $this) {
  224.                 $child->setprnt(null);
  225.             }
  226.         }
  227.         return $this;
  228.     }
  229.     public function getImage(): ?Media
  230.     {
  231.         return $this->image;
  232.     }
  233.     public function setImage(?Media $image): self
  234.     {
  235.         $this->image $image;
  236.         return $this;
  237.     }
  238.     public function getPlaceholder(): ?string
  239.     {
  240.         return $this->placeholder;
  241.     }
  242.     public function setPlaceholder(string $placeholder null): self
  243.     {
  244.         $this->placeholder $placeholder $placeholder "";
  245.         return $this;
  246.     }
  247.     public function getShowTitle(): ?bool
  248.     {
  249.         return $this->show_title;
  250.     }
  251.     public function setShowTitle(bool $show_title): self
  252.     {
  253.         $this->show_title $show_title;
  254.         return $this;
  255.     }
  256. }