src/Entity/Gestiform/Formations/Session/Planning/Planning.php line 16

  1. <?php
  2. namespace App\Entity\Gestiform\Formations\Session\Planning;
  3. use DateTime;
  4. use DateMalformedStringException;
  5. use App\Entity\AbstractEntity;
  6. use App\Entity\Gestiform\Formations\Dossier\Dossier;
  7. use App\Entity\Gestiform\Formations\Session\Session;
  8. use App\Repository\Gestiform\Formations\Session\Planning\PlanningRepository;
  9. use Doctrine\Common\Collections\ArrayCollection;
  10. use Doctrine\Common\Collections\Collection;
  11. use Doctrine\ORM\Mapping as ORM;
  12. #[ORM\Entity(repositoryClassPlanningRepository::class)]
  13. class Planning extends AbstractEntity
  14. {
  15.     #[ORM\Column(type'datetime'nullabletrue)]
  16.     private ?DateTime $start null;
  17.     #[ORM\Column(type'datetime'nullabletrue)]
  18.     private ?DateTime $end null;
  19.     #[ORM\Column(type'integer'nullabletrue)]
  20.     private ?int $totalDays;
  21.     #[ORM\Column(type'integer'nullabletrue)]
  22.     private ?int $stageDuration null;
  23.     #[ORM\Column(type'integer'nullabletrue)]
  24.     private ?int $accompanimentDuration null;
  25.     #[ORM\Column(type'integer'nullabletrue)]
  26.     private ?int $centerDuration null;
  27.     #[ORM\Column(type'integer'nullabletrue)]
  28.     private ?int $juryDuration null;
  29.     #[ORM\Column(type'boolean')]
  30.     private bool $strictMode false;
  31.     #[ORM\OneToOne(mappedBy'planning'targetEntitySession::class)]
  32.     private ?Session $session null;
  33.     #[ORM\ManyToOne(targetEntityPlanning::class, cascade: ['persist''remove'], inversedBy'plannings')]
  34.     private ?Planning $parent null;
  35.     #[ORM\OneToMany(mappedBy'parent'targetEntityPlanning::class)]
  36.     private Collection $plannings;
  37.     #[ORM\OneToOne(mappedBy'planning'targetEntityDossier::class)]
  38.     private ?Dossier $dossier;
  39.     #[ORM\OneToMany(mappedBy'planning'targetEntityPlanningEvent::class, cascade: ['persist''remove'])]
  40.     private Collection $planningEvents;
  41.     public function __construct()
  42.     {
  43.         $this->plannings = new ArrayCollection();
  44.         $this->planningEvents = new ArrayCollection();
  45.     }
  46.     public function getTotalDays(): ?int
  47.     {
  48.         return $this->totalDays;
  49.     }
  50.     public function setTotalDays(?int $totalDays): self
  51.     {
  52.         $this->totalDays $totalDays;
  53.         return $this;
  54.     }
  55.     public function getStrictMode(): bool
  56.     {
  57.         return $this->strictMode;
  58.     }
  59.     public function setStrictMode(bool $strictMode): self
  60.     {
  61.         $this->strictMode $strictMode;
  62.         return $this;
  63.     }
  64.     public function getSessionOrParentSession(): ?Session
  65.     {
  66.         return $this->session ?? $this->getParent()?->getSession();
  67.     }
  68.     public function getSession(): ?Session
  69.     {
  70.         return $this->session;
  71.     }
  72.     public function setSession(?Session $session): self
  73.     {
  74.         $this->session $session;
  75.         return $this;
  76.     }
  77.     public function getParent(): ?self
  78.     {
  79.         return $this->parent;
  80.     }
  81.     public function setParent(?self $parent): self
  82.     {
  83.         $this->parent $parent;
  84.         return $this;
  85.     }
  86.     /**
  87.      * @return Collection<int, Planning>
  88.      */
  89.     public function getPlannings(): Collection
  90.     {
  91.         return $this->plannings;
  92.     }
  93.     public function addPlanning(Planning $planning): self
  94.     {
  95.         if (!$this->plannings->contains($planning)) {
  96.             $this->plannings->add($planning);
  97.             $planning->setParent($this);
  98.         }
  99.         return $this;
  100.     }
  101.     public function removePlanning(Planning $planning): self
  102.     {
  103.         // set the owning side to null (unless already changed)
  104.         if ($this->plannings->removeElement($planning) && $planning->getParent() === $this) {
  105.             $planning->setParent(null);
  106.         }
  107.         return $this;
  108.     }
  109.     public function getDossier(): ?Dossier
  110.     {
  111.         return $this->dossier;
  112.     }
  113.     public function setDossier(?Dossier $dossier): self
  114.     {
  115.         // unset the owning side of the relation if necessary
  116.         if (!$dossier instanceof \App\Entity\Gestiform\Formations\Dossier\Dossier && $this->dossier instanceof \App\Entity\Gestiform\Formations\Dossier\Dossier) {
  117.             $this->dossier->setPlanning(null);
  118.         }
  119.         // set the owning side of the relation if necessary
  120.         if ($dossier instanceof \App\Entity\Gestiform\Formations\Dossier\Dossier && $dossier->getPlanning() !== $this) {
  121.             $dossier->setPlanning($this);
  122.         }
  123.         $this->dossier $dossier;
  124.         return $this;
  125.     }
  126.     public function getPlanningEvents(): Collection
  127.     {
  128.         return $this->planningEvents;
  129.     }
  130.     public function addPlanningEvent(PlanningEvent $planningEvent): self
  131.     {
  132.         if (!$this->planningEvents->contains($planningEvent)) {
  133.             $this->planningEvents[] = $planningEvent;
  134.             $planningEvent->setPlanning($this);
  135.         }
  136.         return $this;
  137.     }
  138.     public function removePlanningEvent(PlanningEvent $planningEvent): self
  139.     {
  140.         $this->planningEvents->removeElement($planningEvent);
  141.         return $this;
  142.     }
  143.     public function getStageDuration(): ?int
  144.     {
  145.         return $this->stageDuration;
  146.     }
  147.     public function setStageDuration(?int $stageDuration): self
  148.     {
  149.         $this->stageDuration $stageDuration;
  150.         return $this;
  151.     }
  152.     public function getAccompanimentDuration(): ?int
  153.     {
  154.         return $this->accompanimentDuration;
  155.     }
  156.     public function setAccompanimentDuration(?int $accompanimentDuration): self
  157.     {
  158.         $this->accompanimentDuration $accompanimentDuration;
  159.         return $this;
  160.     }
  161.     public function getCenterDuration(): ?int
  162.     {
  163.         return $this->centerDuration;
  164.     }
  165.     public function setCenterDuration(?int $centerDuration): self
  166.     {
  167.         $this->centerDuration $centerDuration;
  168.         return $this;
  169.     }
  170.     public function getJuryDuration(): ?int
  171.     {
  172.         return $this->juryDuration;
  173.     }
  174.     public function setJuryDuration(?int $juryDuration): self
  175.     {
  176.         $this->juryDuration $juryDuration;
  177.         return $this;
  178.     }
  179.     /**
  180.      * @throws DateMalformedStringException
  181.      */
  182.     public function getAllMoisFormationModule(): array
  183.     {
  184.         $resultat = [];
  185.         if (!is_null($this->getFirstMoisFormation()) && !is_null($this->getLastMoisFormation())) {
  186.             $madatedebut = clone $this->getFirstMoisFormation();
  187.             $madatefin = clone $this->getLastMoisFormation();
  188. //          $interval = new \DateInterval('P1M');
  189.             if ($madatefin >= $madatedebut) {
  190.                 $moiscourant = clone $this->getFirstMoisFormation();
  191.                 while ($moiscourant <= $madatefin) {
  192.                     $monmois = clone $moiscourant;
  193.                     $resultat[] = $monmois;
  194.                     $moiscourant->modify('first day of next month');
  195.                 }
  196.             }
  197.         }
  198.         return $resultat;
  199.     }
  200.     /**
  201.      * @throws DateMalformedStringException
  202.      */
  203.     public function getFirstMoisFormation(): ?DateTime
  204.     {
  205.         if (!is_null($this->getStart())) {
  206.             $madate = clone $this->getStart();
  207.             $madate->modify('First day of this month');
  208.             $madate->setTime(00);
  209.             return $madate;
  210.         }
  211.         return null;
  212.     }
  213.     public function getStart(): ?DateTime
  214.     {
  215.         return $this->start;
  216.     }
  217.     public function setStart(DateTime $start): self
  218.     {
  219.         $this->start $start;
  220.         return $this;
  221.     }
  222.     /**
  223.      * @throws DateMalformedStringException
  224.      */
  225.     public function getLastMoisFormation(): ?DateTime
  226.     {
  227.         if (!is_null($this->getEnd())) {
  228.             $madate = clone $this->getEnd();
  229.             $madate->modify('First day of this month');
  230.             $madate->setTime(00);
  231.             return $madate;
  232.         }
  233.         return null;
  234.     }
  235.     public function getEnd(): ?DateTime
  236.     {
  237.         return $this->end;
  238.     }
  239.     public function setEnd(?DateTime $end): self
  240.     {
  241.         $this->end $end;
  242.         return $this;
  243.     }
  244.     public function getAllMoisFormationStage(): array
  245.     {
  246.         $resultat = [];
  247.         foreach ($this->planningEvents as $planningEvent) {
  248.             if ($planningEvent->getEvent()->getStageOrParentStage()) {
  249.                 $moiscourant = clone $planningEvent->getEvent()->getStart();
  250.                 $dateFin $planningEvent->getEvent()->getEnd();
  251.                 while ($moiscourant <= $dateFin) {
  252.                     $monmois = clone $moiscourant;
  253.                     $resultat[] = $monmois;
  254.                     $moiscourant->modify('first day of next month');
  255.                 }
  256.             }
  257.         }
  258.         return $resultat;
  259.     }
  260.     public function removeAllPlanningEvent(): self
  261.     {
  262.         foreach ($this->planningEvents as $planningEvent) {
  263.             $this->removePlanningEvent($planningEvent);
  264.         }
  265.         return $this;
  266.     }
  267. }