<?php
namespace App\Entity;
use ApiPlatform\Core\Annotation\ApiResource;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Gedmo\Mapping\Annotation as Gedmo;
use JMS\Serializer\Annotation as Serializer;
use Symfony\Component\HttpFoundation\File\UploadedFile;
use Symfony\Component\Serializer\Annotation\Ignore;
use Symfony\Component\Serializer\Annotation\MaxDepth;
use Symfony\Component\Validator\Constraints as Assert;
use Symfony\Component\Serializer\Annotation\Groups;
/**
* @ORM\Entity(repositoryClass="App\Repository\MenuRepository")
* @ApiResource(
* itemOperations={"get"},
* normalizationContext={"groups"={"anonymouns:read"}, "enable_max_depth"=true},
* )
*/
class Menu implements \Serializable
{
/**
* @ORM\Id()
* @ORM\GeneratedValue()
* @ORM\Column(type="integer")
* @Groups({"anonymouns:read"})
* @Groups({"user:read"})
*/
private $id;
/**
* @var Shop
* @ORM\ManyToOne(targetEntity="App\Entity\Shop", inversedBy="menus")
* @ORM\JoinColumn(onDelete="CASCADE")
* @Serializer\Exclude
* @Ignore
*/
private $shop;
/**
* @var MenuGroup
* @ORM\ManyToOne(targetEntity="App\Entity\MenuGroup", inversedBy="menus")
* @ORM\JoinColumn(onDelete="CASCADE", nullable=true)
* @Serializer\Exclude
* @Ignore()
*/
private $group;
/**
* @ORM\Column(type="string", length=255)
* @Assert\NotBlank()
* @Groups({"anonymouns:read"})
* @Groups({"user:read"})
*/
private $name;
/**
* @ORM\Column(type="text", nullable=true)
* @Assert\NotBlank()
* @Groups({"anonymouns:read"})
* @Groups({"user:read"})
*/
private $description;
/**
* @ORM\Column(type="integer", nullable=true)
* @Groups({"anonymouns:read"})
* @Groups({"user:read"})
*/
private $minutes;
/**
* @ORM\Column(type="integer", nullable=true)
* @Assert\NotBlank()
* @Groups({"anonymouns:read"})
* @Groups({"user:read"})
*/
private $price;
/**
* @ORM\Column(type="string", length=255, nullable=true)
* @Groups({"anonymouns:read"})
* @Groups({"user:read"})
*/
private $image;
/**
* @var UploadedFile
*/
private $ieImage;
/**
* @var string
*/
private $defaultImage;
/**
* @Gedmo\SortablePosition()
* @ORM\Column(type="integer")
* @Groups({"anonymouns:read"})
* @Groups({"user:read"})
*/
private $position;
/**
* @ORM\Column(type="integer", nullable=true)
* @Groups({"anonymouns:read"})
v */
private $discountedPrice;
/**
* @ORM\OneToMany(targetEntity=CartItem::class, mappedBy="menu")
* @Serializer\Exclude()
* @Ignore()
*/
private $cartItems;
/**
* @ORM\OneToMany(targetEntity=OrderMenu::class, mappedBy="menu")
* @Serializer\Exclude()
* @Ignore()
*/
private $orderMenus;
/**
* @ORM\Column(type="integer", nullable=true)
* @Groups({"anonymouns:read"})
* @Groups({"user:read"})
*/
private $appStock;
public function __construct()
{
$this->cartItems = new ArrayCollection();
$this->orderMenus = new ArrayCollection();
}
public function getId(): ?int
{
return $this->id;
}
public function getName(): ?string
{
return $this->name;
}
public function setName(string $name): self
{
$this->name = $name;
return $this;
}
public function getDescription(): ?string
{
return $this->description;
}
public function setDescription(?string $description): self
{
$this->description = $description;
return $this;
}
public function getMinutes(): ?int
{
return $this->minutes;
}
public function setMinutes(?int $minutes): self
{
$this->minutes = $minutes;
return $this;
}
public function getPrice(): ?int
{
return $this->price;
}
public function setPrice(?int $price): self
{
$this->price = $price;
return $this;
}
public function getImage(): ?string
{
return $this->image;
}
public function setImage(?string $image): self
{
$this->image = $image;
return $this;
}
public function getDefaultImage(): ?string
{
return $this->defaultImage;
}
public function setDefaultImage(?string $image): self
{
$this->defaultImage = $image;
return $this;
}
public function getPosition(): ?int
{
return $this->position;
}
public function setPosition(int $position): self
{
$this->position = $position;
return $this;
}
/**
* @return Shop
*/
public function getShop(): ?Shop
{
return $this->shop;
}
/**
* @param Shop $shop
*
* @return $this
*/
public function setShop($shop)
{
$this->shop = $shop;
return $this;
}
/**
* @return MenuGroup
*/
public function getGroup(): ?MenuGroup
{
return $this->group;
}
/**
* @param MenuGroup $group
*
* @return $this
*/
public function setGroup($group)
{
$this->group = $group;
return $this;
}
/**
* @return UploadedFile
*/
public function getIeImage(): ?UploadedFile
{
return $this->ieImage;
}
/**
* @param UploadedFile $ieImage
*
* @return $this
*/
public function setIeImage($ieImage)
{
$this->ieImage = $ieImage;
return $this;
}
public function hasUploadedFile(): bool
{
return !!$this->ieImage;
}
/**
* @inheritDoc
*/
public function serialize()
{
return serialize([
$this->getId(),
$this->getDefaultImage(),
$this->getImage(),
$this->getIeImage() ? true : false
]);
}
/**
* @inheritDoc
*/
public function unserialize($serialized)
{
$array = unserialize($serialized);
$this->id = $array[0];
$this->setDefaultImage($array[1]);
$this->setImage($array[2]);
$this->ieImage = $array[3];
}
public function getDiscountedPrice(): ?int
{
return $this->discountedPrice;
}
public function setDiscountedPrice(?int $discountedPrice): self
{
$this->discountedPrice = $discountedPrice;
return $this;
}
/**
* @return Collection|CartItem[]
*/
public function getCartItems(): Collection
{
return $this->cartItems;
}
public function addCartItem(CartItem $cartItem): self
{
if (!$this->cartItems->contains($cartItem)) {
$this->cartItems[] = $cartItem;
$cartItem->setMenu($this);
}
return $this;
}
public function removeCartItem(CartItem $cartItem): self
{
if ($this->cartItems->removeElement($cartItem)) {
// set the owning side to null (unless already changed)
if ($cartItem->getMenu() === $this) {
$cartItem->setMenu(null);
}
}
return $this;
}
/**
* @return Collection|OrderMenu[]
*/
public function getOrderMenus(): Collection
{
return $this->orderMenus;
}
public function addOrderMenu(OrderMenu $orderMenu): self
{
if (!$this->orderMenus->contains($orderMenu)) {
$this->orderMenus[] = $orderMenu;
$orderMenu->setMenu($this);
}
return $this;
}
public function removeOrderMenu(OrderMenu $orderMenu): self
{
if ($this->orderMenus->removeElement($orderMenu)) {
// set the owning side to null (unless already changed)
if ($orderMenu->getMenu() === $this) {
$orderMenu->setMenu(null);
}
}
return $this;
}
public function getAppStock(): ?int
{
return $this->appStock;
}
public function setAppStock(?int $appStock): self
{
$this->appStock = $appStock;
return $this;
}
}