src/Entity/Commentaires.php line 18

  1. <?php
  2. namespace App\Entity;
  3. use Doctrine\DBAL\Types\Types;
  4. use Doctrine\ORM\Mapping as ORM;
  5. use App\Repository\CommentairesRepository;
  6. use Doctrine\Common\Collections\Collection;
  7. use Doctrine\Common\Collections\ArrayCollection;
  8. use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
  9. #[ORM\Entity(repositoryClassCommentairesRepository::class)]
  10. #[UniqueEntity(
  11.     fields: ['user''projet'],
  12.     message'Tu a déjà commenté ce projet.',
  13. )]
  14. class Commentaires
  15. {
  16.     #[ORM\Id]
  17.     #[ORM\GeneratedValue]
  18.     #[ORM\Column]
  19.     private ?int $id null;
  20.     #[ORM\Column(typeTypes::TEXT)]
  21.     private ?string $text null;
  22.     #[ORM\ManyToOne(inversedBy'commentaires')]
  23.     private ?User $user null;
  24.     #[ORM\ManyToOne(inversedBy'commentaires')]
  25.     private ?UserProjets $projet null;
  26.     #[ORM\OneToMany(mappedBy'commentaire'targetEntityNotes::class, cascade: ['persist''remove'])]
  27.     private Collection $notes;
  28.     #[ORM\Column]
  29.     private ?\DateTimeImmutable $createdAt null;
  30.     public function __construct()
  31.     {
  32.         $this->notes = new ArrayCollection();
  33.         $this->createdAt = new \DateTimeImmutable();
  34.     }
  35.     public function getId(): ?int
  36.     {
  37.         return $this->id;
  38.     }
  39.     public function getText(): ?string
  40.     {
  41.         return $this->text;
  42.     }
  43.     public function setText(string $text): self
  44.     {
  45.         $this->text $text;
  46.         return $this;
  47.     }
  48.     public function getUser(): ?User
  49.     {
  50.         return $this->user;
  51.     }
  52.     public function setUser(?User $user): self
  53.     {
  54.         $this->user $user;
  55.         return $this;
  56.     }
  57.     public function getProjet(): ?UserProjets
  58.     {
  59.         return $this->projet;
  60.     }
  61.     public function setProjet(?UserProjets $projet): self
  62.     {
  63.         $this->projet $projet;
  64.         return $this;
  65.     }
  66.     /**
  67.      * @return Collection<int, Notes>
  68.      */
  69.     public function getNotes(): Collection
  70.     {
  71.         return $this->notes;
  72.     }
  73.     public function addNote(Notes $note): self
  74.     {
  75.         if (!$this->notes->contains($note)) {
  76.             $this->notes->add($note);
  77.             $note->setCommentaire($this);
  78.         }
  79.         return $this;
  80.     }
  81.     public function removeNote(Notes $note): self
  82.     {
  83.         if ($this->notes->removeElement($note)) {
  84.             // set the owning side to null (unless already changed)
  85.             if ($note->getCommentaire() === $this) {
  86.                 $note->setCommentaire(null);
  87.             }
  88.         }
  89.         return $this;
  90.     }
  91.     public function getCreatedAt(): ?\DateTimeImmutable
  92.     {
  93.         return $this->createdAt;
  94.     }
  95.     public function setCreatedAt(\DateTimeImmutable $createdAt): self
  96.     {
  97.         $this->createdAt $createdAt;
  98.         return $this;
  99.     }
  100. }