Exemplo n.º 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;
     }
 }
Exemplo n.º 2
0
 private function MigrateSchedules(Database $legacyDatabase, Database $currentDatabase)
 {
     $schedulesMigrated = MigrationSession::GetLastScheduleRow();
     Log::Debug('Start migrating schedules. Starting at row %s', $schedulesMigrated);
     $scheduleRepo = new ScheduleRepository();
     $getLegacySchedules = new AdHocCommand("select scheduleid, scheduletitle, daystart, dayend, timespan,\n                timeformat, weekdaystart, viewdays, usepermissions, ishidden, showsummary, adminemail, isdefault\n                from schedules order by scheduleid limit {$schedulesMigrated}, 500");
     $getExistingSchedules = new AdHocCommand('select legacyid from schedules');
     $reader = $currentDatabase->Query($getExistingSchedules);
     $knownIds = array();
     while ($row = $reader->GetRow()) {
         $knownIds[] = $row['legacyid'];
     }
     $reader = $legacyDatabase->Query($getLegacySchedules);
     while ($row = $reader->GetRow()) {
         $legacyScheduleId = $row['scheduleid'];
         if (in_array($legacyScheduleId, $knownIds)) {
             continue;
         }
         $newId = $scheduleRepo->Add(new Schedule(null, $row['scheduletitle'], false, $row['weekdaystart'], $row['viewdays']), 1);
         $currentDatabase->Execute(new AdHocCommand("update schedules set legacyid = \"{$row['scheduleid']}\" where schedule_id = {$newId}"));
         $timezone = Configuration::Instance()->GetDefaultTimezone();
         $available = $this->CreateAvailableTimeSlots($row['daystart'], $row['dayend'], $row['timespan']);
         $unavailable = $this->CreateUnavailableTimeSlots($row['daystart'], $row['dayend'], $row['timespan']);
         $layout = ScheduleLayout::Parse($timezone, $available, $unavailable);
         $scheduleRepo->AddScheduleLayout($newId, $layout);
         $schedulesMigrated++;
         MigrationSession::SetLastScheduleRow($schedulesMigrated);
     }
     Log::Debug('Done migrating schedules (%s schedules)', $schedulesMigrated);
     $getLegacyCount = new AdHocCommand('select count(*) as count from schedules');
     $getMigratedCount = new AdHocCommand('select count(*) as count from schedules where legacyid is not null');
     $progressCounts = $this->GetProgressCounts($getLegacyCount, $getMigratedCount);
     $this->page->SetProgress($progressCounts);
     $this->page->SetSchedulesMigrated($progressCounts->MigratedCount);
     MigrationSession::SetLastScheduleRow($progressCounts->MigratedCount);
 }
Exemplo n.º 3
0
 public function testGetsDailySummaryForResource()
 {
     $targetTimezone = 'America/Chicago';
     $date = Date::Parse('2009-09-02', $targetTimezone);
     $start = $date->SetTime(Time::Parse('04:00'));
     $end = $date->SetTime(Time::Parse('05:00'));
     $resourceId = 1;
     $scheduleLayout = new ScheduleLayout($targetTimezone);
     $scheduleLayout->AppendPeriod(new Time(4, 0, 0, $targetTimezone), new Time(5, 0, 0, $targetTimezone));
     $listing = $this->getMock('IReservationListing');
     $firstReservation = new TestReservationListItem($start, $end, $resourceId);
     $reservations = array($firstReservation, new TestReservationListItem($start, $end, $resourceId), new TestBlackoutListItem($start, $end, $resourceId));
     $listing->expects($this->once())->method('OnDateForResource')->with($this->equalTo($date), $this->equalTo($resourceId))->will($this->returnValue($reservations));
     $layout = new DailyLayout($listing, $scheduleLayout);
     $summary = $layout->GetSummary($date, $resourceId);
     $this->assertEquals(2, $summary->NumberOfReservations());
     $this->assertEquals($firstReservation, $summary->FirstReservation());
 }
 public function testSkipsAddingBufferSlotsIfThereIsAnotherItemAtThatTime()
 {
     $tz = 'America/Chicago';
     $listDate = Date::Parse('2011-02-08', $tz);
     $layout = new ScheduleLayout($tz);
     $layout->AppendPeriod(Time::Parse('0:00', $tz), Time::Parse('0:30', $tz));
     $layout->AppendPeriod(Time::Parse('0:30', $tz), Time::Parse('1:00', $tz));
     $layout->AppendPeriod(Time::Parse('1:00', $tz), Time::Parse('1:30', $tz));
     $layout->AppendPeriod(Time::Parse('1:30', $tz), Time::Parse('2:00', $tz));
     $layout->AppendPeriod(Time::Parse('2:00', $tz), Time::Parse('6:00', $tz));
     $layout->AppendPeriod(Time::Parse('6:00', $tz), Time::Parse('0:00', $tz));
     $item1 = new TestReservationItemView(1, Date::Parse('2011-02-08 0:30', $tz)->ToUtc(), Date::Parse('2011-02-08 1:00', $tz)->ToUtc(), 1);
     $item2 = new TestReservationItemView(2, Date::Parse('2011-02-08 1:30', $tz)->ToUtc(), Date::Parse('2011-02-08 2:00', $tz)->ToUtc(), 1);
     $item1->WithBufferTime(60 * 60);
     $item2->WithBufferTime(60 * 60);
     $r1 = new ReservationListItem($item1);
     $r2 = new ReservationListItem($item2);
     $list = new ScheduleReservationList(array($r1, $r2), $layout, $listDate, false);
     /** @var IReservationSlot[] $slots */
     $slots = $list->BuildSlots();
     $this->assertTrue($slots[0]->Begin()->Equals(Time::Parse('0:00', $tz)));
     $this->assertTrue($slots[0]->End()->Equals(Time::Parse('0:30', $tz)));
     $this->assertInstanceOf('BufferSlot', $slots[0]);
     $this->assertTrue($slots[1]->Begin()->Equals(Time::Parse('0:30', $tz)));
     $this->assertTrue($slots[1]->End()->Equals(Time::Parse('1:00', $tz)));
     $this->assertInstanceOf('ReservationSlot', $slots[1]);
     $this->assertTrue($slots[2]->Begin()->Equals(Time::Parse('1:00', $tz)));
     $this->assertTrue($slots[2]->End()->Equals(Time::Parse('1:30', $tz)));
     $this->assertInstanceOf('EmptyReservationSlot', $slots[2]);
     $this->assertTrue($slots[3]->Begin()->Equals(Time::Parse('1:30', $tz)));
     $this->assertTrue($slots[3]->End()->Equals(Time::Parse('2:00', $tz)));
     $this->assertInstanceOf('ReservationSlot', $slots[3]);
     $this->assertTrue($slots[4]->Begin()->Equals(Time::Parse('2:00', $tz)));
     $this->assertTrue($slots[4]->End()->Equals(Time::Parse('6:00', $tz)));
     $this->assertInstanceOf('BufferSlot', $slots[0]);
 }
Exemplo n.º 5
0
 public function testFullDayPeriod()
 {
     $utc = 'UTC';
     $sunday = Date::Parse('2013-01-06 00:00', 'America/Chicago');
     $utcDate = $sunday->ToUtc();
     $midnight = Time::Parse('00:00', $utc);
     $layout = new ScheduleLayout($utc);
     $layout->AppendPeriod($midnight, $midnight);
     $periods = $layout->GetLayout($sunday);
     $this->assertEquals(1, count($periods));
     $period1 = new SchedulePeriod($utcDate->SetTime($midnight), $utcDate->SetTime($midnight, true));
     $this->assertEquals($period1, $periods[0], 'Expected ' . $period1 . ' Actual ' . $periods[0]);
 }
Exemplo n.º 6
0
 /**
  * @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);
 }