src/Entity/Instructor.php line 13

  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\InstructorRepository;
  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. use Symfony\Component\Validator\Constraints as Assert;
  9. #[ORM\Entity(repositoryClass: InstructorRepository::class)]
  10. class Instructor
  11. {
  12.     #[ORM\Id]
  13.     #[ORM\GeneratedValue]
  14.     #[ORM\Column]
  15.     private ?int $id = null;
  16.     #[Assert\Length(
  17.         min: 2,
  18.         max: 255,
  19.         minMessage: 'Le nom doit contenir au moins {{ limit }} caractères',
  20.         maxMessage: 'Le nom ne peut pas dépasser {{ limit }} caractères',
  21.     )]
  22.     #[ORM\Column(length: 255)]
  23.     private ?string $nom = null;
  24.     #[Assert\Length(
  25.         min: 2,
  26.         max: 255,
  27.         minMessage: 'Le prénom doit contenir au moins {{ limit }} caractères',
  28.         maxMessage: 'Le prénom ne peut pas dépasser {{ limit }} caractères',
  29.     )]
  30.     #[ORM\Column(length: 255)]
  31.     private ?string $prenom = null;
  32.     #[Assert\Email(message: 'L\'email {{ value }} n\'est pas valide')]
  33.     #[ORM\Column(length: 255, nullable: true)]
  34.     private ?string $email = null;
  35.     #[ORM\Column(type: Types::TEXT, nullable: true)]
  36.     private ?string $bio = null;
  37.     #[ORM\Column(length: 255, nullable: true)]
  38.     private ?string $photo = null;
  39.     #[ORM\Column(nullable: true)]
  40.     private ?\DateTimeImmutable $createdAt = null;
  41.     #[ORM\ManyToMany(targetEntity: Playlist::class, mappedBy: 'instructors')]
  42.     private Collection $playlists;
  43.     public function __construct()
  44.     {
  45.         $this->playlists = new ArrayCollection();
  46.         $this->createdAt = new \DateTimeImmutable();
  47.     }
  48.     public function __toString()
  49.     {
  50.         return $this->prenom . ' ' . $this->nom;
  51.     }
  52.     public function getId(): ?int
  53.     {
  54.         return $this->id;
  55.     }
  56.     public function getNom(): ?string
  57.     {
  58.         return $this->nom;
  59.     }
  60.     public function setNom(string $nom): self
  61.     {
  62.         $this->nom = $nom;
  63.         return $this;
  64.     }
  65.     public function getPrenom(): ?string
  66.     {
  67.         return $this->prenom;
  68.     }
  69.     public function setPrenom(string $prenom): self
  70.     {
  71.         $this->prenom = $prenom;
  72.         return $this;
  73.     }
  74.     public function getEmail(): ?string
  75.     {
  76.         return $this->email;
  77.     }
  78.     public function setEmail(?string $email): self
  79.     {
  80.         $this->email = $email;
  81.         return $this;
  82.     }
  83.     public function getBio(): ?string
  84.     {
  85.         return $this->bio;
  86.     }
  87.     public function setBio(?string $bio): self
  88.     {
  89.         $this->bio = $bio;
  90.         return $this;
  91.     }
  92.     public function getPhoto(): ?string
  93.     {
  94.         return $this->photo;
  95.     }
  96.     public function setPhoto(?string $photo): self
  97.     {
  98.         $this->photo = $photo;
  99.         return $this;
  100.     }
  101.     public function getCreatedAt(): ?\DateTimeImmutable
  102.     {
  103.         return $this->createdAt;
  104.     }
  105.     public function setCreatedAt(?\DateTimeImmutable $createdAt): self
  106.     {
  107.         $this->createdAt = $createdAt;
  108.         return $this;
  109.     }
  110.     /**
  111.      * @return Collection<int, Playlist>
  112.      */
  113.     public function getPlaylists(): Collection
  114.     {
  115.         return $this->playlists;
  116.     }
  117.     public function addPlaylist(Playlist $playlist): self
  118.     {
  119.         if (!$this->playlists->contains($playlist)) {
  120.             $this->playlists->add($playlist);
  121.             $playlist->addInstructor($this);
  122.         }
  123.         return $this;
  124.     }
  125.     public function removePlaylist(Playlist $playlist): self
  126.     {
  127.         if ($this->playlists->removeElement($playlist)) {
  128.             $playlist->removeInstructor($this);
  129.         }
  130.         return $this;
  131.     }
  132. }