src/Entity/Ingredient.php line 17

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Entity\traits\base64Field;
  4. use App\Entity\traits\Timestapable;
  5. use App\Repository\IngredientRepository;
  6. use Cocur\Slugify\Slugify;
  7. use Doctrine\Common\Collections\ArrayCollection;
  8. use Doctrine\Common\Collections\Collection;
  9. use Doctrine\DBAL\Types\Types;
  10. use Doctrine\ORM\Mapping as ORM;
  11. use Symfony\Component\Serializer\Annotation\Groups;
  12. #[ORM\Entity(repositoryClassIngredientRepository::class)]
  13. #[ORM\HasLifecycleCallbacks]
  14. class Ingredient
  15. {
  16.     use Timestapable;
  17.     use base64Field;
  18.     #[ORM\Id]
  19.     #[ORM\GeneratedValue]
  20.     #[ORM\Column]
  21.     #[Groups(["list_recipes""show_recipe"])]
  22.     private ?int $id null;
  23.     #[ORM\Column(length255)]
  24.     #[Groups(["list_recipes""show_recipe"])]
  25.     private ?string $name null;
  26.     #[ORM\Column(length255)]
  27.     #[Groups(["list_recipes""show_recipe"])]
  28.     private ?string $quantity null;
  29.     #[ORM\Column(length255)]
  30.     #[Groups(["list_recipes""show_recipe"])]
  31.     private ?string $mesureUnit null;
  32.     #[ORM\Column(typeTypes::TEXTnullabletrue)]
  33.     #[Groups(["list_recipes""show_recipe"])]
  34.     private ?string $description null;
  35.     #[ORM\Column(length255nullabletrue)]
  36.     private ?string $image_url null;
  37.     #[ORM\Column(length255nullabletrue)]
  38.     private ?string $prix null;
  39.     #[ORM\Column(nullabletrue)]
  40.     private ?bool $is_buyable null;
  41.     #[ORM\Column(nullabletrueoptions: ["default" => 0])]
  42.     private ?int $stock null;
  43.     #[ORM\Column(length255)]
  44.     private ?string $slug null;
  45.     #[ORM\ManyToMany(targetEntityRecipe::class, mappedBy'ingredients')]
  46.     private Collection $recipes;
  47.     public function __construct()
  48.     {
  49.         $this->recipes = new ArrayCollection();
  50.     }
  51.     #[ORM\PrePersist]
  52.     public function addSlug()
  53.     {
  54.         $this->setSlug(
  55.             (new Slugify())->slugify(
  56.                 $this->name
  57.             )
  58.         );
  59.     }
  60.     public function getId(): ?int
  61.     {
  62.         return $this->id;
  63.     }
  64.     public function getName(): ?string
  65.     {
  66.         return $this->name;
  67.     }
  68.     public function setName(string $name): self
  69.     {
  70.         $this->name $name;
  71.         return $this;
  72.     }
  73.     public function getDescription(): ?string
  74.     {
  75.         return $this->description;
  76.     }
  77.     public function setDescription(string $description): self
  78.     {
  79.         $this->description $description;
  80.         return $this;
  81.     }
  82.     public function getImageUrl(): ?string
  83.     {
  84.         return $this->image_url;
  85.     }
  86.     public function setImageUrl(string $image_url): self
  87.     {
  88.         $this->image_url $image_url;
  89.         return $this;
  90.     }
  91.     public function getPrix(): ?string
  92.     {
  93.         return $this->prix;
  94.     }
  95.     public function setPrix(string $prix): self
  96.     {
  97.         $this->prix $prix;
  98.         return $this;
  99.     }
  100.     public function isIsBuyable(): ?bool
  101.     {
  102.         return $this->is_buyable;
  103.     }
  104.     public function setIsBuyable(?bool $is_buyable): self
  105.     {
  106.         $this->is_buyable $is_buyable;
  107.         return $this;
  108.     }
  109.     public function getStock(): ?int
  110.     {
  111.         return $this->stock;
  112.     }
  113.     public function setStock(int $stock): self
  114.     {
  115.         $this->stock $stock;
  116.         return $this;
  117.     }
  118.     public function getSlug(): ?string
  119.     {
  120.         return $this->slug;
  121.     }
  122.     public function setSlug(string $slug): self
  123.     {
  124.         $this->slug $slug;
  125.         return $this;
  126.     }
  127.     /**
  128.      * Get the value of quantity
  129.      */
  130.     public function getQuantity()
  131.     {
  132.         return $this->quantity;
  133.     }
  134.     /**
  135.      * Set the value of quantity
  136.      *
  137.      * @return  self
  138.      */
  139.     public function setQuantity($quantity)
  140.     {
  141.         $this->quantity $quantity;
  142.         return $this;
  143.     }
  144.     /**
  145.      * Get the value of mesureUnit
  146.      */
  147.     public function getMesureUnit()
  148.     {
  149.         return $this->mesureUnit;
  150.     }
  151.     /**
  152.      * Set the value of mesureUnit
  153.      *
  154.      * @return  self
  155.      */
  156.     public function setMesureUnit($mesureUnit)
  157.     {
  158.         $this->mesureUnit $mesureUnit;
  159.         return $this;
  160.     }
  161.     public function getRecipes($need false)
  162.     {
  163.         if ($need == true) {
  164.             return $this->recipes;
  165.         } else {
  166.             return null;
  167.         }
  168.     }
  169.     public function addRecipe(Recipe $recipe): self
  170.     {
  171.         if (!$this->recipes->contains($recipe)) {
  172.             $this->recipes->add($recipe);
  173.             $recipe->addIngredient($this);
  174.         }
  175.         return $this;
  176.     }
  177.     public function removeRecipe(Recipe $recipe): self
  178.     {
  179.         if ($this->recipes->removeElement($recipe)) {
  180.             $recipe->removeIngredient($this);
  181.         }
  182.         return $this;
  183.     }
  184. }