src/Entity/Meeting.php line 17

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Entity\Traits\TimeStampable;
  4. use App\Repository\MeetingRepository;
  5. use Doctrine\Common\Collections\ArrayCollection;
  6. use Doctrine\Common\Collections\Collection;
  7. use Doctrine\DBAL\Types\Types;
  8. use Doctrine\ORM\Mapping as ORM;
  9. use Symfony\Component\Validator\Constraints as Assert;
  10. use App\Entity\Traits\TimeStampableTrait;
  11. #[ORM\Entity(repositoryClass: MeetingRepository::class)]
  12. #[ORM\HasLifecycleCallbacks]
  13. class Meeting
  14. {
  15.     use TimeStampable;
  16.     #[ORM\Id]
  17.     #[ORM\GeneratedValue]
  18.     #[ORM\Column]
  19.     private ?int $id = null;
  20.     #[ORM\Column(nullable: true)]
  21.     private ?\DateTimeImmutable $expectedStartDate = null;
  22.     #[ORM\Column(nullable:true)]
  23.     #[Assert\NotBlank(message: "ce champ est obligatoire.")]
  24.     #[Assert\GreaterThanOrEqual(
  25.         value: "today",
  26.         message: "La date de la réunion ne peut pas être inférieure à la date du jour."
  27.     )]
  28.     private ?\DateTimeImmutable $effectiveStartDate = null;
  29.     #[ORM\Column(length: 16, nullable: true)]
  30.     private ?string $estimatedDuration = null;
  31.     #[ORM\Column(length: 16, nullable: true)]
  32.     private ?string $effectiveDuration = null;
  33.     #[ORM\Column(type: Types::TEXT, nullable: true)]
  34.     private ?string $observation = null;
  35.     #[ORM\ManyToOne]
  36.     #[ORM\JoinColumn(nullable: true)]
  37.     private ?User $createdBy = null;
  38.     #[ORM\Column(length: 255)]
  39.     private ?string $location;
  40.     #[ORM\ManyToOne(targetEntity: Structure::class, inversedBy: 'meetings')]
  41.     #[ORM\JoinColumn(nullable: true)]
  42.     private ?Structure $structure = null;
  43.     #[ORM\ManyToOne(targetEntity: User::class, inversedBy: 'meetings')]
  44.     #[ORM\JoinColumn(nullable: true)]
  45.     private ?User $user = null;
  46.     #[ORM\Column(length: 65, nullable: true)]
  47.     private ?string $reportFilename = null;
  48.     #[ORM\Column(length: 255)]
  49.     #[Assert\NotBlank(message: "ce champ est obligatoire.")]
  50.     private ?string $objet;
  51.     #[ORM\Column(length: 255)]
  52.     private ?string $status = null;
  53.     #[ORM\Column(length: 10, nullable: true)]
  54.     #[Assert\NotBlank(message: "ce champ est obligatoire.")]
  55.     private ?string $heureReunion = null;
  56.     #[ORM\OneToMany(mappedBy: 'meet', targetEntity: MeetParticipant::class, cascade: ['persist', 'remove'])]
  57.     private Collection $meetParticipants;
  58.     #[ORM\ManyToOne(inversedBy: 'meetings')]
  59.     #[Assert\NotBlank(message: "ce champ est obligatoire.")]
  60.     private ?MeetingCategory $meetingCategories = null;
  61.     #[ORM\OneToMany(mappedBy: 'meeting', targetEntity: Agenda::class, cascade: ['persist', 'remove'])]
  62.     private Collection $agendas;
  63.     #[ORM\Column]
  64.     private ?bool $isConfirmed = null;
  65.     public function __construct()
  66.     {
  67.         $this->createdAt = new \DateTimeImmutable();
  68.         $this->status = "Brouillon";
  69.         $this->meetParticipants = new ArrayCollection();
  70.         $this->agendas = new ArrayCollection();
  71.         $this->isConfirmed = false;
  72.     }
  73.     public function getId(): ?int
  74.     {
  75.         return $this->id;
  76.     }
  77.     public function getExpectedStartDate(): ?\DateTimeImmutable
  78.     {
  79.         return $this->expectedStartDate;
  80.     }
  81.     public function setExpectedStartDate(?\DateTimeImmutable $expectedStartDate): self
  82.     {
  83.         $this->expectedStartDate = $expectedStartDate;
  84.         return $this;
  85.     }
  86.     public function getEffectiveStartDate(): ?\DateTimeImmutable
  87.     {
  88.         return $this->effectiveStartDate;
  89.     }
  90.     public function setEffectiveStartDate(?\DateTimeImmutable $effectiveStartDate): self
  91.     {
  92.         $this->effectiveStartDate = $effectiveStartDate;
  93.         return $this;
  94.     }
  95.     public function getEstimatedDuration(): ?string
  96.     {
  97.         return $this->estimatedDuration;
  98.     }
  99.     public function setEstimatedDuration(?string $estimatedDuration): self
  100.     {
  101.         $this->estimatedDuration = $estimatedDuration;
  102.         return $this;
  103.     }
  104.     public function getEffectiveDuration(): ?string
  105.     {
  106.         return $this->effectiveDuration;
  107.     }
  108.     public function setEffectiveDuration(?string $effectiveDuration): self
  109.     {
  110.         $this->effectiveDuration = $effectiveDuration;
  111.         return $this;
  112.     }
  113.     public function getObservation(): ?string
  114.     {
  115.         return $this->observation;
  116.     }
  117.     public function setObservation(?string $observation): self
  118.     {
  119.         $this->observation = $observation;
  120.         return $this;
  121.     }
  122.     public function getCreatedBy(): ?User
  123.     {
  124.         return $this->createdBy;
  125.     }
  126.     public function setCreatedBy(?User $createdBy): self
  127.     {
  128.         $this->createdBy = $createdBy;
  129.         return $this;
  130.     }
  131.     public function getLocation(): ?string
  132.     {
  133.         return $this->location;
  134.     }
  135.     public function setLocation(?string $location): self
  136.     {
  137.         $this->location = $location;
  138.         return $this;
  139.     }
  140.     
  141.     public function getStructure(): ?Structure
  142.     {
  143.         return $this->structure;
  144.     }
  145.     
  146.     public function setStructure(?Structure $structure): self
  147.     {
  148.         $this->structure = $structure;
  149.         $this->user = null; // S'assurer qu'on ne garde pas les deux
  150.         return $this;
  151.     }
  152.     public function getUser(): ?User
  153.     {
  154.         return $this->user;
  155.     }
  156.     
  157.     public function setUser(?User $user): self
  158.     {
  159.         $this->user = $user;
  160.         $this->structure = null; // S'assurer qu'on ne garde pas les deux
  161.         return $this;
  162.     }
  163.     public function getReportFilename(): ?string
  164.     {
  165.         return $this->reportFilename;
  166.     }
  167.     public function setReportFilename(?string $reportFilename): self
  168.     {
  169.         $this->reportFilename = $reportFilename;
  170.         return $this;
  171.     }
  172.     public function getObjet(): ?string
  173.     {
  174.         return $this->objet;
  175.     }
  176.     public function setObjet(string $objet): self
  177.     {
  178.         $this->objet = $objet;
  179.         return $this;
  180.     }
  181.     public function getStatus(): ?string
  182.     {
  183.         return $this->status;
  184.     }
  185.     public function setStatus(string $status): self
  186.     {
  187.         $this->status = $status;
  188.         return $this;
  189.     }
  190.     public function getHeureReunion(): ?string
  191.     {
  192.         return $this->heureReunion;
  193.     }
  194.     public function setHeureReunion(?string $heureReunion): self
  195.     {
  196.         $this->heureReunion = $heureReunion;
  197.         return $this;
  198.     }
  199.     public function __toString(): string
  200.     {
  201.         return $this->objet;
  202.     }
  203.     /**
  204.      * @return Collection<int, MeetParticipant>
  205.      */
  206.     public function getMeetParticipants(): Collection
  207.     {
  208.         return $this->meetParticipants;
  209.     }
  210.     public function addMeetParticipant(MeetParticipant $meetParticipant): self
  211.     {
  212.         if (!$this->meetParticipants->contains($meetParticipant)) {
  213.             $this->meetParticipants->add($meetParticipant);
  214.             $meetParticipant->setMeet($this);
  215.         }
  216.         return $this;
  217.     }
  218.     public function removeMeetParticipant(MeetParticipant $meetParticipant): self
  219.     {
  220.         if ($this->meetParticipants->removeElement($meetParticipant)) {
  221.             // set the owning side to null (unless already changed)
  222.             if ($meetParticipant->getMeet() === $this) {
  223.                 $meetParticipant->setMeet(null);
  224.             }
  225.         }
  226.         return $this;
  227.     }
  228.     public function getMeetingCategories(): ?MeetingCategory
  229.     {
  230.         return $this->meetingCategories;
  231.     }
  232.     public function setMeetingCategories(?MeetingCategory $meetingCategories): self
  233.     {
  234.         $this->meetingCategories = $meetingCategories;
  235.         $this->meetingCategories->setIsDeleted(false);
  236.         return $this;
  237.     }
  238.     /**
  239.      * @return Collection<int, Agenda>
  240.      */
  241.     public function getAgendas(): Collection
  242.     {
  243.         return $this->agendas;
  244.     }
  245.     public function addAgenda(Agenda $agenda): self
  246.     {
  247.         if (!$this->agendas->contains($agenda)) {
  248.             $this->agendas->add($agenda);
  249.             $agenda->setMeeting($this);
  250.         }
  251.         return $this;
  252.     }
  253.     public function removeAgenda(Agenda $agenda): self
  254.     {
  255.         if ($this->agendas->removeElement($agenda)) {
  256.             // set the owning side to null (unless already changed)
  257.             if ($agenda->getMeeting() === $this) {
  258.                 $agenda->setMeeting(null);
  259.             }
  260.         }
  261.         return $this;
  262.     }
  263.     public function isIsConfirmed(): ?bool
  264.     {
  265.         return $this->isConfirmed;
  266.     }
  267.     public function setIsConfirmed(bool $isConfirmed): self
  268.     {
  269.         $this->isConfirmed = $isConfirmed;
  270.         return $this;
  271.     }
  272.     public function getUsersAssign(): array
  273.     {
  274.         $participants = [];
  275.         foreach ($this->meetParticipants as $participant) {
  276.             $participants[] = $participant->getParticipants();
  277.         }
  278.         return $participants;
  279.     }
  280.     public function getUserNotAssign(array $users): array
  281.     {
  282.         $userAssign = $this->getUsersAssign();
  283.         $userNotAssing = array_diff($users, $userAssign);
  284.         return $userNotAssing;
  285.     }
  286.     /**
  287.      * Convertit l'heure et les minutes en format heureReunion (HH:mm)
  288.      */
  289.     public function setHeureFromDateTime(\DateTimeInterface $dateTime): self
  290.     {
  291.         $this->heureReunion = $dateTime->format('H:i');
  292.         return $this;
  293.     }
  294.     /**
  295.      * Retourne l'heure au format DateTime
  296.      */
  297.     public function getHeureAsDateTime(): ?\DateTime
  298.     {
  299.         if (!$this->heureReunion) {
  300.             return null;
  301.         }
  302.         return \DateTime::createFromFormat('H:i', $this->heureReunion);
  303.     }
  304. }