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

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