src/Entity/Staff.php line 11

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\StaffRepository;
  4. use Doctrine\ORM\Mapping as ORM;
  5. use Doctrine\Common\Collections\ArrayCollection;
  6. use Doctrine\Common\Collections\Collection;
  7. #[ORM\Entity(repositoryClass: StaffRepository::class)]
  8. class Staff
  9. {
  10.     #[ORM\Id]
  11.     #[ORM\GeneratedValue]
  12.     #[ORM\Column]
  13.     private ?int $id = null;
  14.     #[ORM\Column(length: 255)]
  15.     private ?string $fullName = null;
  16.        
  17.    
  18.     #[ORM\ManyToMany(targetEntity: Calendar::class, inversedBy: 'staffs')]
  19.     private $calendars;
  20.     // ...
  21.     public function __construct()
  22.     {
  23.         $this->calendars = new ArrayCollection();
  24.     }
  25.     public function __toString()
  26.     {
  27.         return $this->fullName;
  28.     } 
  29.     public function getId(): ?int
  30.     {
  31.         return $this->id;
  32.     }
  33.     public function getFullName(): ?string
  34.     {
  35.         return $this->fullName;
  36.     }
  37.     public function setFullName(string $fullName): self
  38.     {
  39.         $this->fullName = $fullName;
  40.         return $this;
  41.     }
  42.    /**
  43.  * @return Collection<int, Calendar>
  44.  */
  45. public function getCalendars(): Collection
  46. {
  47.     return $this->calendars;
  48. }
  49. public function addCalendar(Calendar $calendar): static
  50. {
  51.     if (!$this->calendars->contains($calendar)) {
  52.         $this->calendars->add($calendar);
  53.         $calendar->addStaff($this); // Vous devriez également ajouter le membre du personnel au calendrier
  54.     }
  55.     return $this;
  56. }
  57. public function setCalendar(?Calendar $calendar): static
  58. {
  59.     $this->calendar = $calendar;
  60.     return $this;
  61. }
  62. public function removeCalendar(Calendar $calendar): static
  63. {
  64.     if ($this->calendars->removeElement($calendar)) {
  65.         // Assurez-vous de retirer le membre du personnel du calendrier si nécessaire
  66.         $calendar->removeStaff($this);
  67.     }
  68.     return $this;
  69. }
  70. }