src/Entity/Budget.php line 19

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