src/Entity/RecipeType.php line 19

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\RecipeTypeRepository;
  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 Doctrine\ORM\Mapping\HasLifecycleCallbacks;
  12. use Doctrine\ORM\Mapping\PrePersist;
  13. use Symfony\Component\Serializer\Annotation\Groups;
  14. #[ORM\Entity(repositoryClassRecipeTypeRepository::class)]
  15. #[HasLifecycleCallbacks]
  16. class RecipeType
  17. {
  18.     use Timestapable;
  19.     use base64Field;
  20.     #[ORM\Id]
  21.     #[ORM\GeneratedValue]
  22.     #[ORM\Column]
  23.     #[Groups(["show_recipe""show_recipe_type"])]
  24.     private ?int $id null;
  25.     #[ORM\Column(length255)]
  26.     #[Groups(["list_recipes""show_recipe""user_info""show_recipe_type""for_abj"])]
  27.     private ?string $name null;
  28.     #[ORM\Column(length255nullabletrue)]
  29.     private ?string $cattype null;
  30.     #[ORM\Column(length255nullabletrue)]
  31.     private ?string $cataff null;
  32.     #[ORM\Column(length255nullabletrue)]
  33.     #[Groups(["list_recipes""show_recipe""user_info""show_recipe_type""for_abj"])]
  34.     private ?string $slug null;
  35.     #[ORM\Column(typeTypes::TEXTnullabletrue)]
  36.     #[Groups(["list_recipes""user_info""show_recipe_type"])]
  37.     private ?string $description null;
  38.     #[ORM\Column(length255nullabletrue)]
  39.     #[Groups(["list_recipes""user_info""show_recipe_type"])]
  40.     private ?string $image_url null;
  41.     
  42.     #[Groups(["list_recipes""user_info""show_recipe_type"])]
  43.     private ?string $imageMiniature null;
  44.     #[ORM\OneToMany(mappedBy'recipeType'targetEntityRecipe::class)]
  45.     private Collection $recipes;
  46.     #[PrePersist]
  47.     public function generateSlug()
  48.     {
  49.         $this->slug = (new Slugify())->slugify($this->name);
  50.     }
  51.     public function __construct()
  52.     {
  53.         $this->recipes = new ArrayCollection();
  54.     }
  55.     public function getId(): ?int
  56.     {
  57.         return $this->id;
  58.     }
  59.     public function getName(): ?string
  60.     {
  61.         return $this->name;
  62.     }
  63.     public function setName(string $name): self
  64.     {
  65.         $this->name $name;
  66.         return $this;
  67.     }
  68.     public function getDescription(): ?string
  69.     {
  70.         return $this->description;
  71.     }
  72.     public function setDescription(string $description): self
  73.     {
  74.         $this->description $description;
  75.         return $this;
  76.     }
  77.     public function getImageUrl(): ?string
  78.     {
  79.         return $this->image_url;
  80.     }
  81.     public function setImageUrl(string $image_url): self
  82.     {
  83.         $this->image_url $image_url;
  84.         return $this;
  85.     }
  86.     /**
  87.      * @return Collection<int, Recipe>
  88.      */
  89.     public function getRecipes($need false)
  90.     {
  91.         if ($need) {
  92.             return $this->recipes;
  93.         } else {
  94.             return [];
  95.         }
  96.     }
  97.     public function addRecipe(Recipe $recipe): self
  98.     {
  99.         if (!$this->recipes->contains($recipe)) {
  100.             $this->recipes->add($recipe);
  101.             $recipe->setRecipeType($this);
  102.         }
  103.         return $this;
  104.     }
  105.     public function removeRecipe(Recipe $recipe): self
  106.     {
  107.         if ($this->recipes->removeElement($recipe)) {
  108.             // set the owning side to null (unless already changed)
  109.             if ($recipe->getRecipeType() === $this) {
  110.                 $recipe->setRecipeType(null);
  111.             }
  112.         }
  113.         return $this;
  114.     }
  115.     public function getSlug()
  116.     {
  117.         return $this->slug;
  118.     }
  119.     public function setSlug($slug)
  120.     {
  121.         $this->slug $slug;
  122.         return $this;
  123.     }
  124.     public function getImageMiniature()
  125.     {
  126.         return $this->imageMiniature;
  127.     }
  128.  
  129.     public function setImageMiniature($imageMiniature)
  130.     {
  131.         $this->imageMiniature $imageMiniature;
  132.         return $this;
  133.     }
  134. }