src/Entity/Trick.php line 20

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Entity\Trait\CreatedAtTrait;
  4. use App\Repository\TrickRepository;
  5. use Doctrine\Common\Collections\ArrayCollection;
  6. use Doctrine\Common\Collections\Collection;
  7. use Doctrine\ORM\Mapping as ORM;
  8. use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
  9. //////
  10. use Symfony\Component\Serializer\Annotation\Groups;
  11. #[ORM\Entity(repositoryClassTrickRepository::class)]
  12. #[UniqueEntity(
  13.   fields: ['name'],
  14.   message'Ce trick existe déjà.',
  15. )]
  16. class Trick
  17. {
  18.   use CreatedAtTrait;
  19.   #[ORM\Id]
  20.   #[ORM\GeneratedValue]
  21.   #[ORM\Column]
  22.   private ?int $id null;
  23.   #[ORM\Column(name'name'length150type'string'uniquetrue)]
  24.   private ?string $name null;
  25.   #[ORM\Column(length2500)]
  26.   private ?string $description null;
  27.   #[ORM\Column]
  28.   private ?\DateTimeImmutable $updated_at null;
  29.   #[ORM\ManyToOne(inversedBy'tricks')]
  30.   #[ORM\JoinColumn(nullablefalseonDelete'CASCADE'name'id_user')]
  31.   private ?User $user null;
  32.   #[ORM\ManyToOne(inversedBy'tricks')]
  33.   #[ORM\JoinColumn(nullablefalseonDelete'CASCADE'name'id_category')]
  34.   private ?Category $category null;
  35.   #[ORM\OneToMany(mappedBy'trick'targetEntityMessage::class)]
  36.   #[Groups(['get_messages'])]
  37.   private Collection $messages;
  38.   #[ORM\OneToMany(mappedBy'trick'targetEntityImage::class)]
  39.   private Collection $images;
  40.   #[ORM\OneToMany(mappedBy'trick'targetEntityVideo::class)]
  41.   private Collection $videos;
  42.   #[ORM\Column(type'string'uniquetrue)]
  43.   #[Groups(['get_messages'])]
  44.   private string $slug;
  45.   public function __construct()
  46.   {
  47.     $this->messages = new ArrayCollection();
  48.     $this->images = new ArrayCollection();
  49.     $this->videos = new ArrayCollection();
  50.     $this->created_at = new \DateTimeImmutable();
  51.   }
  52.   public function getId(): ?int
  53.   {
  54.     return $this->id;
  55.   }
  56.   public function getName(): ?string
  57.   {
  58.     return $this->name;
  59.   }
  60.   public function setName(string $name): self
  61.   {
  62.     $this->name $name;
  63.     return $this;
  64.   }
  65.   public function getDescription(): ?string
  66.   {
  67.     return $this->description;
  68.   }
  69.   public function setDescription(string $description): self
  70.   {
  71.     $this->description $description;
  72.     return $this;
  73.   }
  74.   public function getUpdatedAt(): ?\DateTimeImmutable
  75.   {
  76.     return $this->updated_at;
  77.   }
  78.   public function setUpdatedAt(\DateTimeImmutable $updated_at): self
  79.   {
  80.     $this->updated_at $updated_at;
  81.     return $this;
  82.   }
  83.   public function getUser(): ?User
  84.   {
  85.     return $this->user;
  86.   }
  87.   public function setUser(?User $user): self
  88.   {
  89.     $this->user $user;
  90.     return $this;
  91.   }
  92.   public function getCategory(): ?Category
  93.   {
  94.     return $this->category;
  95.   }
  96.   public function setCategory(?Category $category): self
  97.   {
  98.     $this->category $category;
  99.     return $this;
  100.   }
  101.   /**
  102.    * @return Collection<int, Message>
  103.    */
  104.   public function getMessages(): Collection
  105.   {
  106.     return $this->messages;
  107.   }
  108.   public function addMessage(Message $message): self
  109.   {
  110.     if (!$this->messages->contains($message)) {
  111.       $this->messages->add($message);
  112.       $message->setTrick($this);
  113.     }
  114.     return $this;
  115.   }
  116.   public function removeMessage(Message $message): self
  117.   {
  118.     if ($this->messages->removeElement($message)) {
  119.       // set the owning side to null (unless already changed)
  120.       if ($message->getTrick() === $this) {
  121.         $message->setTrick(null);
  122.       }
  123.     }
  124.     return $this;
  125.   }
  126.   /**
  127.    * @return Collection<int, Image>
  128.    */
  129.   public function getImages(): Collection
  130.   {
  131.     return $this->images;
  132.   }
  133.   public function addImage(Image $image): self
  134.   {
  135.     if (!$this->images->contains($image)) {
  136.       $this->images->add($image);
  137.       $image->setTrick($this);
  138.     }
  139.     return $this;
  140.   }
  141.   public function removeImage(Image $image): self
  142.   {
  143.     if ($this->images->removeElement($image)) {
  144.       // set the owning side to null (unless already changed)
  145.       if ($image->getTrick() === $this) {
  146.         $image->setTrick(null);
  147.       }
  148.     }
  149.     return $this;
  150.   }
  151.   /**
  152.    * @return Collection<int, Video>
  153.    */
  154.   public function getVideos(): Collection
  155.   {
  156.     return $this->videos;
  157.   }
  158.   public function addVideo(Video $video): self
  159.   {
  160.     if (!$this->videos->contains($video)) {
  161.       $this->videos->add($video);
  162.       $video->setTrick($this);
  163.     }
  164.     return $this;
  165.   }
  166.   public function removeVideo(Video $video): self
  167.   {
  168.     if ($this->videos->removeElement($video)) {
  169.       // set the owning side to null (unless already changed)
  170.       if ($video->getTrick() === $this) {
  171.         $video->setTrick(null);
  172.       }
  173.     }
  174.     return $this;
  175.   }
  176.   public function getSlug(): ?string
  177.   {
  178.     return $this->slug;
  179.   }
  180.   public function setSlug(string $slug): self
  181.   {
  182.     $this->slug $slug;
  183.     return $this;
  184.   }
  185. }