<?php
namespace App\Entity;
use App\Repository\MenuRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Vich\UploaderBundle\Mapping\Annotation as Vich;
use Symfony\Component\HttpFoundation\File\File;
use Symfony\Component\Validator\Constraints as Assert;
#[ORM\Entity(repositoryClass: MenuRepository::class)]
#[Vich\Uploadable]
class Menu
{
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column]
private ?int $id = null;
#[ORM\Column(length: 255)]
#[Assert\NotBlank(message: 'Le nom du menu est obligatoire')]
#[Assert\Length(min: 2, max: 255, minMessage: 'Le nom doit faire au moins {{ limit }} caractères', maxMessage: 'Le nom ne peut pas dépasser {{ limit }} caractères')]
private ?string $nom = null;
#[ORM\Column(length: 255, nullable: true)]
#[Assert\Length(max: 255, maxMessage: 'La description ne peut pas dépasser {{ limit }} caractères')]
private ?string $description = null;
#[ORM\OneToMany(targetEntity: MenuProduit::class, mappedBy: "menu", cascade: ["persist", "remove"], orphanRemoval: true)]
private Collection $menuProduit;
#[ORM\Column(nullable: true)]
private ?\DateTimeImmutable $updatedAt = null;
#[ORM\Column(nullable: true)]
private ?string $imageName = null;
#[Vich\UploadableField(mapping: 'menu', fileNameProperty: 'imageName')]
private ?File $imageFile = null;
#[ORM\Column]
#[Assert\NotBlank(message: 'Le prix est obligatoire')]
#[Assert\PositiveOrZero(message: 'Le prix doit être positif ou zéro')]
private ?int $prix = null;
#[ORM\OneToMany(mappedBy: 'menu', targetEntity: DetailsVente::class, orphanRemoval: false)]
private Collection $detailsVentes;
public function __construct()
{
$this->menuProduit = new ArrayCollection(); // Initialize the collection
$this->detailsVentes = new ArrayCollection();
}
// Other getter and setter methods...
public function getId(): ?int
{
return $this->id;
}
public function getNom(): ?string
{
return $this->nom;
}
public function setNom(string $nom): static
{
$this->nom = $nom;
return $this;
}
public function getDescription(): ?string
{
return $this->description;
}
public function setDescription(string $description): static
{
$this->description = $description;
return $this;
}
/**
* @return Collection<int, MenuProduit>
*/
public function getMenuProduit(): Collection
{
return $this->menuProduit;
}
public function addMenuProduit(MenuProduit $menuProduit): static
{
if (!$this->menuProduit->contains($menuProduit)) {
$this->menuProduit->add($menuProduit);
$menuProduit->setMenu($this);
}
return $this;
}
public function removeMenuProduit(MenuProduit $menuProduit): static
{
if ($this->menuProduit->removeElement($menuProduit)) {
// set the owning side to null (unless already changed)
if ($menuProduit->getMenu() === $this) {
$menuProduit->setMenu(null);
}
}
return $this;
}
public function setImageFile(?File $imageFile = null): void
{
$this->imageFile = $imageFile;
if (null !== $imageFile) {
$this->updatedAt = new \DateTimeImmutable('now');
}
}
public function getImageFile(): ?File
{
return $this->imageFile;
}
public function setImageName(?string $imageName): void
{
$this->imageName = $imageName;
}
public function getImageName(): ?string
{
return $this->imageName;
}
public function getPrix(): ?int
{
return $this->prix;
}
public function setPrix(int $prix): static
{
$this->prix = $prix;
return $this;
}
/**
* @return Collection<int, DetailsVente>
*/
public function getDetailsVentes(): Collection
{
return $this->detailsVentes;
}
public function addDetailsVente(DetailsVente $detailsVente): static
{
if (!$this->detailsVentes->contains($detailsVente)) {
$this->detailsVentes->add($detailsVente);
$detailsVente->setMenu($this);
}
return $this;
}
public function removeDetailsVente(DetailsVente $detailsVente): static
{
if ($this->detailsVentes->removeElement($detailsVente)) {
// set the owning side to null (unless already changed)
if ($detailsVente->getMenu() === $this) {
$detailsVente->setMenu(null);
}
}
return $this;
}
}