src/Entity/Gestiform/Formations/Session/Planning/Planning.php line 16
<?phpnamespace App\Entity\Gestiform\Formations\Session\Planning;use DateTime;use DateMalformedStringException;use App\Entity\AbstractEntity;use App\Entity\Gestiform\Formations\Dossier\Dossier;use App\Entity\Gestiform\Formations\Session\Session;use App\Repository\Gestiform\Formations\Session\Planning\PlanningRepository;use Doctrine\Common\Collections\ArrayCollection;use Doctrine\Common\Collections\Collection;use Doctrine\ORM\Mapping as ORM;#[ORM\Entity(repositoryClass: PlanningRepository::class)]class Planning extends AbstractEntity{#[ORM\Column(type: 'datetime', nullable: true)]private ?DateTime $start = null;#[ORM\Column(type: 'datetime', nullable: true)]private ?DateTime $end = null;#[ORM\Column(type: 'integer', nullable: true)]private ?int $totalDays;#[ORM\Column(type: 'integer', nullable: true)]private ?int $stageDuration = null;#[ORM\Column(type: 'integer', nullable: true)]private ?int $accompanimentDuration = null;#[ORM\Column(type: 'integer', nullable: true)]private ?int $centerDuration = null;#[ORM\Column(type: 'integer', nullable: true)]private ?int $juryDuration = null;#[ORM\Column(type: 'boolean')]private bool $strictMode = true;#[ORM\OneToOne(mappedBy: 'planning', targetEntity: Session::class)]private ?Session $session = null;#[ORM\ManyToOne(targetEntity: Planning::class, cascade: ['persist', 'remove'], inversedBy: 'plannings')]private ?Planning $parent = null;#[ORM\OneToMany(mappedBy: 'parent', targetEntity: Planning::class)]private Collection $plannings;#[ORM\OneToOne(mappedBy: 'planning', targetEntity: Dossier::class)]private ?Dossier $dossier;#[ORM\OneToMany(mappedBy: 'planning', targetEntity: PlanningEvent::class, cascade: ['persist', 'remove'])]private Collection $planningEvents;public function __construct(){$this->plannings = new ArrayCollection();$this->planningEvents = new ArrayCollection();}public function getTotalDays(): ?int{return $this->totalDays;}public function setTotalDays(?int $totalDays): self{$this->totalDays = $totalDays;return $this;}public function getStrictMode(): bool{return $this->strictMode;}public function setStrictMode(bool $strictMode): self{$this->strictMode = $strictMode;return $this;}public function getSessionOrParentSession(): ?Session{return $this->session ?? $this->getParent()?->getSession();}public function getSession(): ?Session{return $this->session;}public function setSession(?Session $session): self{$this->session = $session;return $this;}public function getParent(): ?self{return $this->parent;}public function setParent(?self $parent): self{$this->parent = $parent;return $this;}/*** @return Collection<int, Planning>*/public function getPlannings(): Collection{return $this->plannings;}public function addPlanning(Planning $planning): self{if (!$this->plannings->contains($planning)) {$this->plannings->add($planning);$planning->setParent($this);}return $this;}public function removePlanning(Planning $planning): self{// set the owning side to null (unless already changed)if ($this->plannings->removeElement($planning) && $planning->getParent() === $this) {$planning->setParent(null);}return $this;}public function getDossier(): ?Dossier{return $this->dossier;}public function setDossier(?Dossier $dossier): self{// unset the owning side of the relation if necessaryif (!$dossier instanceof \App\Entity\Gestiform\Formations\Dossier\Dossier && $this->dossier instanceof \App\Entity\Gestiform\Formations\Dossier\Dossier) {$this->dossier->setPlanning(null);}// set the owning side of the relation if necessaryif ($dossier instanceof \App\Entity\Gestiform\Formations\Dossier\Dossier && $dossier->getPlanning() !== $this) {$dossier->setPlanning($this);}$this->dossier = $dossier;return $this;}public function getPlanningEvents(): Collection{return $this->planningEvents;}public function addPlanningEvent(PlanningEvent $planningEvent): self{if (!$this->planningEvents->contains($planningEvent)) {$this->planningEvents[] = $planningEvent;$planningEvent->setPlanning($this);}return $this;}public function removePlanningEvent(PlanningEvent $planningEvent): self{$this->planningEvents->removeElement($planningEvent);return $this;}public function getStageDuration(): ?int{return $this->stageDuration;}public function setStageDuration(?int $stageDuration): self{$this->stageDuration = $stageDuration;return $this;}public function getAccompanimentDuration(): ?int{return $this->accompanimentDuration;}public function setAccompanimentDuration(?int $accompanimentDuration): self{$this->accompanimentDuration = $accompanimentDuration;return $this;}public function getCenterDuration(): ?int{return $this->centerDuration;}public function setCenterDuration(?int $centerDuration): self{$this->centerDuration = $centerDuration;return $this;}public function getJuryDuration(): ?int{return $this->juryDuration;}public function setJuryDuration(?int $juryDuration): self{$this->juryDuration = $juryDuration;return $this;}/*** @throws DateMalformedStringException*/public function getAllMoisFormationModule(): array{$resultat = [];if (!is_null($this->getFirstMoisFormation()) && !is_null($this->getLastMoisFormation())) {$madatedebut = clone $this->getFirstMoisFormation();$madatefin = clone $this->getLastMoisFormation();// $interval = new \DateInterval('P1M');if ($madatefin >= $madatedebut) {$moiscourant = clone $this->getFirstMoisFormation();while ($moiscourant <= $madatefin) {$monmois = clone $moiscourant;$resultat[] = $monmois;$moiscourant->modify('first day of next month');}}}return $resultat;}/*** @throws DateMalformedStringException*/public function getFirstMoisFormation(): ?DateTime{if (!is_null($this->getStart())) {$madate = clone $this->getStart();$madate->modify('First day of this month');$madate->setTime(0, 0);return $madate;}return null;}public function getStart(): ?DateTime{return $this->start;}public function setStart(DateTime $start): self{$this->start = $start;return $this;}/*** @throws DateMalformedStringException*/public function getLastMoisFormation(): ?DateTime{if (!is_null($this->getEnd())) {$madate = clone $this->getEnd();$madate->modify('First day of this month');$madate->setTime(0, 0);return $madate;}return null;}public function getEnd(): ?DateTime{return $this->end;}public function setEnd(?DateTime $end): self{$this->end = $end;return $this;}public function getAllMoisFormationStage(): array{$resultat = [];foreach ($this->planningEvents as $planningEvent) {if ($planningEvent->getEvent()->getStageOrParentStage()) {$moiscourant = clone $planningEvent->getEvent()->getStart();$dateFin = $planningEvent->getEvent()->getEnd();while ($moiscourant <= $dateFin) {$monmois = clone $moiscourant;$resultat[] = $monmois;$moiscourant->modify('first day of next month');}}}return $resultat;}public function removeAllPlanningEvent(): self{foreach ($this->planningEvents as $planningEvent) {$this->removePlanningEvent($planningEvent);}return $this;}}