src/Entity/Produit.php line 11

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\ProduitRepository;
  4. use Doctrine\Common\Collections\ArrayCollection;
  5. use Doctrine\Common\Collections\Collection;
  6. use Doctrine\ORM\Mapping as ORM;
  7. #[ORM\Entity(repositoryClass: ProduitRepository::class)]
  8. class Produit
  9. {
  10. #[ORM\Id]
  11. #[ORM\GeneratedValue]
  12. #[ORM\Column(type: 'integer')]
  13. private $id;
  14. #[ORM\Column(type: 'string',length: 255)]
  15. private $libelle;
  16. #[ORM\Column(type: 'string',length: 255, nullable: true)]
  17. private $description;
  18. #[ORM\Column(type: 'string',length: 255, nullable: true)]
  19. private $img;
  20. #[ORM\OneToMany(mappedBy: 'produit', targetEntity: Ingredient::class, orphanRemoval: true)]
  21. private $ingredients;
  22. #[ORM\ManyToOne(targetEntity: Categorie::class, inversedBy:'produits')]
  23. private $categorie;
  24. public function __toString()
  25. {
  26. return $this->libelle;
  27. }
  28. public function __construct()
  29. {
  30. $this->ingredients = new ArrayCollection();
  31. }
  32. public function getId(): ?int
  33. {
  34. return $this->id;
  35. }
  36. public function getLibelle(): ?string
  37. {
  38. return $this->libelle;
  39. }
  40. public function setLibelle(string $libelle): self
  41. {
  42. $this->libelle = $libelle;
  43. return $this;
  44. }
  45. public function getDescription(): ?string
  46. {
  47. return $this->description;
  48. }
  49. public function setDescription(?string $description): self
  50. {
  51. $this->description = $description;
  52. return $this;
  53. }
  54. public function getImg(): ?string
  55. {
  56. return $this->img;
  57. }
  58. public function setImg(?string $img): self
  59. {
  60. $this->img = $img;
  61. return $this;
  62. }
  63. /**
  64. * @return Collection|Ingredient[]
  65. */
  66. public function getIngredients(): Collection
  67. {
  68. return $this->ingredients;
  69. }
  70. public function addIngredient(Ingredient $ingredient): self
  71. {
  72. if (!$this->ingredients->contains($ingredient)) {
  73. $this->ingredients[] = $ingredient;
  74. $ingredient->setProduit($this);
  75. }
  76. return $this;
  77. }
  78. public function removeIngredient(Ingredient $ingredient): self
  79. {
  80. if ($this->ingredients->removeElement($ingredient)) {
  81. // set the owning side to null (unless already changed)
  82. if ($ingredient->getProduit() === $this) {
  83. $ingredient->setProduit(null);
  84. }
  85. }
  86. return $this;
  87. }
  88. public function getCategorie(): ?Categorie
  89. {
  90. return $this->categorie;
  91. }
  92. public function setCategorie(?Categorie $categorie): self
  93. {
  94. $this->categorie = $categorie;
  95. return $this;
  96. }
  97. }