/**
  * 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;
     }
 }
 /**
  * Return the week dates (first day, last day, list of days) given options passed
  *
  * @param array $options with the following keys :
  * - date_day : \DateTimeInterface of the day of reference
  * - enable_next_week : boolean - True if the week to return is the next following
  *    the week containing the day of reference
  * - days_ofweek_off [optional] : Day::constants[] list of days generally off in the week.
  * - dates_off [optional] : \DateTime[] list of dates off in the week
  *
  * @return array associative array with the following keys :
  * - first_day : \DateTimeImmutable of the first day of the week (the monday)
  * - last_day : \DateTimeImmutable of the last day of the week (the friday)
  * - days : \DateTimeImmutable[] index array of days in the week that take in account
  *  the closed days passed in options
  */
 public function getWeekDates($options)
 {
     $options = $this->weekMealResolver->resolve($options);
     if (true === $options['enable_next_week']) {
         $firstDayFormat = ' next monday';
         $lastDayFormat = ' next friday';
     } else {
         $firstDayFormat = ' monday this week';
         $lastDayFormat = ' friday this week';
     }
     $firstDay = new \DateTimeImmutable($options['date_day']->format('Y-m-d') . $firstDayFormat);
     $lastDay = new \DateTimeImmutable($firstDay->format('Y-m-d') . $lastDayFormat);
     $periode = new Period($firstDay, $lastDay);
     $days = [];
     foreach ($periode->getDayIterator() as $date) {
         if (false === \in_array(Day::getWeekDayFrom($date), $options['days_ofweek_off']) && false === \in_array($date, $options['dates_off'])) {
             $days[] = $date;
         }
     }
     return array('first_day' => $firstDay, 'last_day' => $lastDay, 'days' => $days);
 }
 /**
  * @param SchoolYear $schoolYear
  */
 private function addEventWithin(Period $event, SchoolYear $schoolYear)
 {
     if ($event->getFirstDate() > $schoolYear->getDateStart() && $event->getLastDate() < $schoolYear->getDateEnd()) {
         $holiday = new SchoolHoliday();
         $holiday->setDateStart($event->getFirstDate());
         $holiday->setDateEnd($event->getLastDate());
         $holiday->setDescription($event->getDescription());
         $holiday->setSchoolYear($schoolYear);
         $schoolYear->addSchoolHoliday($holiday);
         $this->getEntityManager()->persist($holiday);
     }
 }
 /**
  * Ensure arbitrary periods are correctly read.
  *
  * @dataProvider providerPeriods
  * @param string $startingDate
  * @param string $endingDate
  * @param string $desc
  * @param integer $indexInCalendar
  *
  * @uses \Scheduler\Component\FileReader\ICalendarFileReader
  * @uses \Scheduler\Component\DateContainer\Period
  */
 public function testShouldHaveCorrectPeriod($startingDate, $endingDate, $desc, $indexInCalendar)
 {
     $expected = new Period(new \DateTime($startingDate), new \DateTime($endingDate), $desc);
     $event = self::$events[$indexInCalendar];
     $this->assertEquals($expected->getFirstDate(), $event->getFirstDate(), "Starting date");
     $this->assertEquals($expected->getLastDate(), $event->getLastDate(), "End date");
     $this->assertEquals($expected->getDescription(), $event->getDescription(), "Description");
 }
 /**
  * @covers ::getIterator
  * @uses \Scheduler\Component\DateContainer\PeriodIterator
  */
 public function testGetIterator()
 {
     $this->assertInstanceOf(PeriodIterator::class, self::$period->getIterator(new \DateInterval('P1W')));
 }
 /**
  * Return all "garderies" registered for a given pupil and period.
  *
  * @param Eleve $eleve
  * @param Period $periode
  * @param boolean $subscribed_by_parent_only
  * @return \Doctrine\Common\Collections\ArrayCollection
  */
 public function findAllGarderiesForPeriode(Eleve $eleve, Period $periode, $subscribed_by_parent_only)
 {
     $em = $this->getEntityManager();
     $query = $em->createQueryBuilder()->select('t')->from('WCSCantineBundle:Garderie', 't')->where('t.eleve = :eleve')->andWhere('t.date >= :dateDebut')->andWhere('t.date <= :dateFin')->orderBy('t.date', 'ASC');
     if ($subscribed_by_parent_only) {
         $query->andWhere('t.subscribed_by_parent = TRUE');
     }
     $query->setParameter(':eleve', $eleve)->setParameter(':dateDebut', $periode->getFirstDate())->setParameter(':dateFin', $periode->getLastDate());
     return $query->getQuery()->getResult();
 }