Exemplo n.º 1
0
 /**
  * Calendrier constructor.
  *
  * Génère chaque jours du calendrier pour une période scolaire donnée
  *
  * @param PeriodInterface $period
  * @param function - $closureIsDayOff
  */
 public function __construct(PeriodInterface $yearPeriod, $closureIsDayOff)
 {
     $this->yearPeriod = $yearPeriod;
     $this->days = array();
     $period = new Period($this->yearPeriod->getFirstDate(), new \DateTimeImmutable($this->yearPeriod->getLastDate()->format('Y-m') . '-31'));
     foreach ($period->getDayIterator() as $currentDay) {
         $d = new Day($currentDay);
         $d->setOff($closureIsDayOff($d));
         if (!$yearPeriod->isIncluded($d->getDate())) {
             $d->setOff(true);
         }
         $this->days[$d->getMonth()][$d->getDay()] = $d;
     }
 }
Exemplo n.º 2
0
 /**
  * @param PeriodInterface $period
  */
 public function addPeriodDayOffs(PeriodInterface $period)
 {
     $d = new Day($period->getFirstDate());
     if ($this->saturdayOff && $d->equalsWeekDay(Day::WEEK_SATURDAY)) {
         $firstDate = $period->getFirstDate();
     } else {
         $firstDate = $period->getFirstDate()->add(new \DateInterval('P1D'));
     }
     $newPeriod = new Period($firstDate, $period->getLastDate(), $period->getDescription());
     $this->periodsDayOff[] = $newPeriod;
     \usort($this->periodsDayOff, function (PeriodInterface $periodA, PeriodInterface $periodB) {
         return $periodA->getFirstDate() > $periodB->getFirstDate() ? +1 : -1;
     });
 }