src/Entity/UserSport.php line 12

  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\UserSportRepository;
  4. use Doctrine\Common\Collections\ArrayCollection;
  5. use Doctrine\Common\Collections\Collection;
  6. use Doctrine\DBAL\Types\Types;
  7. use Doctrine\ORM\Mapping as ORM;
  8. #[ORM\Entity(repositoryClassUserSportRepository::class)]
  9. class UserSport
  10. {
  11.     #[ORM\Id]
  12.     #[ORM\GeneratedValue]
  13.     #[ORM\Column]
  14.     private ?int $id null;
  15.     #[ORM\Column(typeTypes::DATE_MUTABLE)]
  16.     private ?\DateTimeInterface $date_ajout null;
  17.     #[ORM\ManyToOne(inversedBy'userSport')]
  18.     private ?User $user null;
  19.     #[ORM\ManyToMany(targetEntitySport::class, inversedBy'userSports')]
  20.     private Collection $userSports;
  21.     public function __construct()
  22.     {
  23.         $this->date_ajout = new \DateTimeImmutable();
  24.         $this->userSports = new ArrayCollection();
  25.     }
  26.     public function getId(): ?int
  27.     {
  28.         return $this->id;
  29.     }
  30.     public function getDateAjout(): ?\DateTimeInterface
  31.     {
  32.         return $this->date_ajout;
  33.     }
  34.     public function setDateAjout(\DateTimeInterface $date_ajout): static
  35.     {
  36.         $this->date_ajout $date_ajout;
  37.         return $this;
  38.     }
  39.     public function getUser(): ?User
  40.     {
  41.         return $this->user;
  42.     }
  43.     public function setUser(?User $user): static
  44.     {
  45.         $this->user $user;
  46.         return $this;
  47.     }
  48.     /**
  49.      * @return Collection<int, Sport>
  50.      */
  51.     public function getUserSports(): Collection
  52.     {
  53.         return $this->userSports;
  54.     }
  55.     public function addUserSport(Sport $userSport): static
  56.     {
  57.         if (!$this->userSports->contains($userSport)) {
  58.             $this->userSports->add($userSport);
  59.         }
  60.         return $this;
  61.     }
  62.     public function removeUserSport(Sport $userSport): static
  63.     {
  64.         $this->userSports->removeElement($userSport);
  65.         return $this;
  66.     }
  67. }