Exemple #1
0
 /**
  * @return void
  */
 public function Validate()
 {
     try {
         $this->isValid = true;
         $days = array(null);
         if (!$this->validateSingle) {
             Log::Debug('Validating daily layout');
             Log::Debug(var_export($this->reservableSlots, true));
             if (count($this->reservableSlots) != DayOfWeek::NumberOfDays || count($this->blockedSlots) != DayOfWeek::NumberOfDays) {
                 $this->isValid = false;
                 return;
             }
             $layout = ScheduleLayout::ParseDaily('UTC', $this->reservableSlots, $this->blockedSlots);
             $days = DayOfWeek::Days();
         } else {
             Log::Debug('Validating single layout');
             $layout = ScheduleLayout::Parse('UTC', $this->reservableSlots, $this->blockedSlots);
         }
         foreach ($days as $day) {
             if (is_null($day)) {
                 $day = 0;
             }
             $slots = $layout->GetLayout(Date::Now()->AddDays($day)->ToUtc());
             /** @var $firstDate Date */
             $firstDate = $slots[0]->BeginDate();
             /** @var $lastDate Date */
             $lastDate = $slots[count($slots) - 1]->EndDate();
             if (!$firstDate->IsMidnight() || !$lastDate->IsMidnight()) {
                 Log::Debug('Dates are not midnight');
                 $this->isValid = false;
             }
             for ($i = 0; $i < count($slots) - 1; $i++) {
                 if (!$slots[$i]->EndDate()->Equals($slots[$i + 1]->BeginDate())) {
                     $this->isValid = false;
                 }
             }
         }
     } catch (Exception $ex) {
         Log::Error('Error during LayoutValidator', $ex);
         $this->isValid = false;
     }
 }
 public function testCanParseDailyFromStrings()
 {
     $timezone = 'America/Chicago';
     $days = DayOfWeek::Days();
     $reservableSlots = array();
     $blockedSlots = array();
     foreach ($days as $day) {
         $reservableSlots[$day] = "00:00 - 01:00 Label {$day} A\n1:00- 2:00\r\n02:00 -3:30\n03:30-12:00\r\n";
         $blockedSlots[$day] = "12:00 - 15:00 Blocked {$day} A\n15:00- 20:00\r\n20:00 -0:00\n";
     }
     $layout = ScheduleLayout::ParseDaily($timezone, $reservableSlots, $blockedSlots);
     $this->assertTrue($layout->UsesDailyLayouts());
     $this->assertEquals($timezone, $layout->Timezone());
     foreach ($days as $day) {
         $slots = $layout->GetSlots($day);
         $this->assertEquals(7, count($slots));
         $start1 = Time::Parse("00:00", $timezone);
         $end1 = Time::Parse("01:00", $timezone);
         $start4 = Time::Parse("12:00", $timezone);
         $end4 = Time::Parse("15:00", $timezone);
         $this->assertEquals(new LayoutPeriod($start1, $end1, PeriodTypes::RESERVABLE, "Label {$day} A"), $slots[0]);
         $this->assertEquals(new LayoutPeriod($start4, $end4, PeriodTypes::NONRESERVABLE, "Blocked {$day} A"), $slots[4]);
     }
 }
 /**
  * @param int $scheduleId
  * @param string $timezone
  * @param string[] $reservableSlots
  * @param string[] $blockedSlots
  */
 public function ChangeDailyLayout($scheduleId, $timezone, $reservableSlots, $blockedSlots)
 {
     $layout = ScheduleLayout::ParseDaily($timezone, $reservableSlots, $blockedSlots);
     $this->scheduleRepository->AddScheduleLayout($scheduleId, $layout);
 }