src/Entity/Level.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\LevelRepository;
  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(repositoryClassLevelRepository::class)]
  15. #[HasLifecycleCallbacks]
  16. class Level
  17. {
  18.     use Timestapable;
  19.     use base64Field;
  20.     #[ORM\Id]
  21.     #[ORM\GeneratedValue]
  22.     #[ORM\Column]
  23.     #[Groups(["show_recipe"])]
  24.     private ?int $id null;
  25.     #[ORM\Column(length255)]
  26.     #[Groups(["list_recipes""show_recipe"])]
  27.     private ?string $name null;
  28.     #[ORM\Column(typeTypes::TEXTnullabletrue)]
  29.     #[Groups(["list_recipes""show_recipe"])]
  30.     private ?string $description null;
  31.     #[ORM\Column(length255nullabletrue)]
  32.     #[Groups(["list_recipes""show_recipe"])]
  33.     private ?string $slug null;
  34.     #[ORM\OneToMany(mappedBy'level'targetEntityRecipe::class)]
  35.     private Collection $recipes;
  36.     #[PrePersist]
  37.     public function addSlug()
  38.     {
  39.         $this->slug = (new Slugify())->slugify($this->name);
  40.     }
  41.     public function __construct()
  42.     {
  43.         $this->recipes = new ArrayCollection();
  44.     }
  45.     public function getId(): ?int
  46.     {
  47.         return $this->id;
  48.     }
  49.     public function getName(): ?string
  50.     {
  51.         return $this->name;
  52.     }
  53.     public function setName(string $name): self
  54.     {
  55.         $this->name $name;
  56.         return $this;
  57.     }
  58.     public function getDescription(): ?string
  59.     {
  60.         return $this->description;
  61.     }
  62.     public function setDescription(string $description): self
  63.     {
  64.         $this->description $description;
  65.         return $this;
  66.     }
  67.     public function getSlug(): ?string
  68.     {
  69.         return $this->slug;
  70.     }
  71.     public function setSlug(string $slug): self
  72.     {
  73.         $this->slug $slug;
  74.         return $this;
  75.     }
  76.     /**
  77.      * @return Collection<int, Recipe>
  78.      */
  79.     public function getRecipes($need false)
  80.     {
  81.         if ($need) {
  82.             return $this->recipes;
  83.         } else {
  84.             return null;
  85.         }
  86.     }
  87.     public function addRecipe(Recipe $recipe): self
  88.     {
  89.         if (!$this->recipes->contains($recipe)) {
  90.             $this->recipes->add($recipe);
  91.             $recipe->setLevel($this);
  92.         }
  93.         return $this;
  94.     }
  95.     public function removeRecipe(Recipe $recipe): self
  96.     {
  97.         if ($this->recipes->removeElement($recipe)) {
  98.             // set the owning side to null (unless already changed)
  99.             if ($recipe->getLevel() === $this) {
  100.                 $recipe->setLevel(null);
  101.             }
  102.         }
  103.         return $this;
  104.     }
  105. }