src/Entity/Menu.php line 24

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use ApiPlatform\Core\Annotation\ApiResource;
  4. use Doctrine\Common\Collections\ArrayCollection;
  5. use Doctrine\Common\Collections\Collection;
  6. use Doctrine\ORM\Mapping as ORM;
  7. use Gedmo\Mapping\Annotation as Gedmo;
  8. use JMS\Serializer\Annotation as Serializer;
  9. use Symfony\Component\HttpFoundation\File\UploadedFile;
  10. use Symfony\Component\Serializer\Annotation\Ignore;
  11. use Symfony\Component\Serializer\Annotation\MaxDepth;
  12. use Symfony\Component\Validator\Constraints as Assert;
  13. use Symfony\Component\Serializer\Annotation\Groups;
  14. /**
  15.  * @ORM\Entity(repositoryClass="App\Repository\MenuRepository")
  16.  * @ApiResource(
  17.  *     itemOperations={"get"},
  18.  *     normalizationContext={"groups"={"anonymouns:read"}, "enable_max_depth"=true},
  19.  * )
  20.  */
  21. class Menu implements \Serializable
  22. {
  23.     /**
  24.      * @ORM\Id()
  25.      * @ORM\GeneratedValue()
  26.      * @ORM\Column(type="integer")
  27.      * @Groups({"anonymouns:read"})
  28.      * @Groups({"user:read"})
  29.      */
  30.     private $id;
  31.     /**
  32.      * @var Shop
  33.      * @ORM\ManyToOne(targetEntity="App\Entity\Shop", inversedBy="menus")
  34.      * @ORM\JoinColumn(onDelete="CASCADE")
  35.      * @Serializer\Exclude
  36.      * @Ignore
  37.      */
  38.     private $shop;
  39.     /**
  40.      * @var MenuGroup
  41.      * @ORM\ManyToOne(targetEntity="App\Entity\MenuGroup", inversedBy="menus")
  42.      * @ORM\JoinColumn(onDelete="CASCADE", nullable=true)
  43.      * @Serializer\Exclude
  44.      * @Ignore()
  45.      */
  46.     private $group;
  47.     /**
  48.      * @ORM\Column(type="string", length=255)
  49.      * @Assert\NotBlank()
  50.      * @Groups({"anonymouns:read"})
  51.      * @Groups({"user:read"})
  52.      */
  53.     private $name;
  54.     /**
  55.      * @ORM\Column(type="text", nullable=true)
  56.      * @Assert\NotBlank()
  57.      * @Groups({"anonymouns:read"})
  58.      * @Groups({"user:read"})
  59.      */
  60.     private $description;
  61.     /**
  62.      * @ORM\Column(type="integer", nullable=true)
  63.      * @Groups({"anonymouns:read"})
  64.      * @Groups({"user:read"})
  65.      */
  66.     private $minutes;
  67.     /**
  68.      * @ORM\Column(type="integer", nullable=true)
  69.      * @Assert\NotBlank()
  70.      * @Groups({"anonymouns:read"})
  71.      * @Groups({"user:read"})
  72.      */
  73.     private $price;
  74.     /**
  75.      * @ORM\Column(type="string", length=255, nullable=true)
  76.      * @Groups({"anonymouns:read"})
  77.      * @Groups({"user:read"})
  78.      */
  79.     private $image;
  80.     /**
  81.      * @var UploadedFile
  82.      */
  83.     private $ieImage;
  84.     /**
  85.      * @var string
  86.      */
  87.     private $defaultImage;
  88.     /**
  89.      * @Gedmo\SortablePosition()
  90.      * @ORM\Column(type="integer")
  91.      * @Groups({"anonymouns:read"})
  92.      * @Groups({"user:read"})
  93.      */
  94.     private $position;
  95.     /**
  96.      * @ORM\Column(type="integer", nullable=true)
  97.      * @Groups({"anonymouns:read"})
  98. v     */
  99.     private $discountedPrice;
  100.     /**
  101.      * @ORM\OneToMany(targetEntity=CartItem::class, mappedBy="menu")
  102.      * @Serializer\Exclude()
  103.      * @Ignore()
  104.      */
  105.     private $cartItems;
  106.     /**
  107.      * @ORM\OneToMany(targetEntity=OrderMenu::class, mappedBy="menu")
  108.      * @Serializer\Exclude()
  109.      * @Ignore()
  110.      */
  111.     private $orderMenus;
  112.     /**
  113.      * @ORM\Column(type="integer", nullable=true)
  114.      * @Groups({"anonymouns:read"})
  115.      * @Groups({"user:read"})
  116.      */
  117.     private $appStock;
  118.     public function __construct()
  119.     {
  120.         $this->cartItems = new ArrayCollection();
  121.         $this->orderMenus = new ArrayCollection();
  122.     }
  123.     public function getId(): ?int
  124.     {
  125.         return $this->id;
  126.     }
  127.     public function getName(): ?string
  128.     {
  129.         return $this->name;
  130.     }
  131.     public function setName(string $name): self
  132.     {
  133.         $this->name $name;
  134.         return $this;
  135.     }
  136.     public function getDescription(): ?string
  137.     {
  138.         return $this->description;
  139.     }
  140.     public function setDescription(?string $description): self
  141.     {
  142.         $this->description $description;
  143.         return $this;
  144.     }
  145.     public function getMinutes(): ?int
  146.     {
  147.         return $this->minutes;
  148.     }
  149.     public function setMinutes(?int $minutes): self
  150.     {
  151.         $this->minutes $minutes;
  152.         return $this;
  153.     }
  154.     public function getPrice(): ?int
  155.     {
  156.         return $this->price;
  157.     }
  158.     public function setPrice(?int $price): self
  159.     {
  160.         $this->price $price;
  161.         return $this;
  162.     }
  163.     public function getImage(): ?string
  164.     {
  165.         return $this->image;
  166.     }
  167.     public function setImage(?string $image): self
  168.     {
  169.         $this->image $image;
  170.         return $this;
  171.     }
  172.     public function getDefaultImage(): ?string
  173.     {
  174.         return $this->defaultImage;
  175.     }
  176.     public function setDefaultImage(?string $image): self
  177.     {
  178.         $this->defaultImage $image;
  179.         return $this;
  180.     }
  181.     public function getPosition(): ?int
  182.     {
  183.         return $this->position;
  184.     }
  185.     public function setPosition(int $position): self
  186.     {
  187.         $this->position $position;
  188.         return $this;
  189.     }
  190.     /**
  191.      * @return Shop
  192.      */
  193.     public function getShop(): ?Shop
  194.     {
  195.         return $this->shop;
  196.     }
  197.     /**
  198.      * @param Shop $shop
  199.      *
  200.      * @return $this
  201.      */
  202.     public function setShop($shop)
  203.     {
  204.         $this->shop $shop;
  205.         return $this;
  206.     }
  207.     /**
  208.      * @return MenuGroup
  209.      */
  210.     public function getGroup(): ?MenuGroup
  211.     {
  212.         return $this->group;
  213.     }
  214.     /**
  215.      * @param MenuGroup $group
  216.      *
  217.      * @return $this
  218.      */
  219.     public function setGroup($group)
  220.     {
  221.         $this->group $group;
  222.         return $this;
  223.     }
  224.     /**
  225.      * @return UploadedFile
  226.      */
  227.     public function getIeImage(): ?UploadedFile
  228.     {
  229.         return $this->ieImage;
  230.     }
  231.     /**
  232.      * @param UploadedFile $ieImage
  233.      *
  234.      * @return $this
  235.      */
  236.     public function setIeImage($ieImage)
  237.     {
  238.         $this->ieImage $ieImage;
  239.         return $this;
  240.     }
  241.     public function hasUploadedFile(): bool
  242.     {
  243.         return !!$this->ieImage;
  244.     }
  245.     /**
  246.      * @inheritDoc
  247.      */
  248.     public function serialize()
  249.     {
  250.         return serialize([
  251.             $this->getId(),
  252.             $this->getDefaultImage(),
  253.             $this->getImage(),
  254.             $this->getIeImage() ? true false
  255.         ]);
  256.     }
  257.     /**
  258.      * @inheritDoc
  259.      */
  260.     public function unserialize($serialized)
  261.     {
  262.         $array unserialize($serialized);
  263.         $this->id $array[0];
  264.         $this->setDefaultImage($array[1]);
  265.         $this->setImage($array[2]);
  266.         $this->ieImage $array[3];
  267.     }
  268.     public function getDiscountedPrice(): ?int
  269.     {
  270.         return $this->discountedPrice;
  271.     }
  272.     public function setDiscountedPrice(?int $discountedPrice): self
  273.     {
  274.         $this->discountedPrice $discountedPrice;
  275.         return $this;
  276.     }
  277.     /**
  278.      * @return Collection|CartItem[]
  279.      */
  280.     public function getCartItems(): Collection
  281.     {
  282.         return $this->cartItems;
  283.     }
  284.     public function addCartItem(CartItem $cartItem): self
  285.     {
  286.         if (!$this->cartItems->contains($cartItem)) {
  287.             $this->cartItems[] = $cartItem;
  288.             $cartItem->setMenu($this);
  289.         }
  290.         return $this;
  291.     }
  292.     public function removeCartItem(CartItem $cartItem): self
  293.     {
  294.         if ($this->cartItems->removeElement($cartItem)) {
  295.             // set the owning side to null (unless already changed)
  296.             if ($cartItem->getMenu() === $this) {
  297.                 $cartItem->setMenu(null);
  298.             }
  299.         }
  300.         return $this;
  301.     }
  302.     /**
  303.      * @return Collection|OrderMenu[]
  304.      */
  305.     public function getOrderMenus(): Collection
  306.     {
  307.         return $this->orderMenus;
  308.     }
  309.     public function addOrderMenu(OrderMenu $orderMenu): self
  310.     {
  311.         if (!$this->orderMenus->contains($orderMenu)) {
  312.             $this->orderMenus[] = $orderMenu;
  313.             $orderMenu->setMenu($this);
  314.         }
  315.         return $this;
  316.     }
  317.     public function removeOrderMenu(OrderMenu $orderMenu): self
  318.     {
  319.         if ($this->orderMenus->removeElement($orderMenu)) {
  320.             // set the owning side to null (unless already changed)
  321.             if ($orderMenu->getMenu() === $this) {
  322.                 $orderMenu->setMenu(null);
  323.             }
  324.         }
  325.         return $this;
  326.     }
  327.     public function getAppStock(): ?int
  328.     {
  329.         return $this->appStock;
  330.     }
  331.     public function setAppStock(?int $appStock): self
  332.     {
  333.         $this->appStock $appStock;
  334.         return $this;
  335.     }
  336. }