Esempio n. 1
0
 public function testGetLayoutReturnsBuiltSlotsFromScheduleReservationList()
 {
     $date = Date::Parse('2009-09-02', 'UTC');
     $resourceId = 1;
     $targetTimezone = 'America/Chicago';
     $scheduleLayout = new ScheduleLayout($targetTimezone);
     $scheduleLayout->AppendPeriod(new Time(5, 0, 0, $targetTimezone), new Time(6, 0, 0, $targetTimezone));
     $listing = $this->getMock('IReservationListing');
     $startDate = Date::Parse('2009-09-02 17:00:00', 'UTC');
     $endDate = Date::Parse('2009-09-02 18:00:00', 'UTC');
     $reservation = new TestReservationListItem($startDate, $endDate, $resourceId);
     $reservations = array($reservation);
     $listing->expects($this->once())->method('OnDateForResource')->with($this->equalTo($date), $this->equalTo($resourceId))->will($this->returnValue($reservations));
     $layout = new DailyLayout($listing, $scheduleLayout);
     $layoutSlots = $layout->GetLayout($date, $resourceId);
     $reservationList = new ScheduleReservationList($reservations, $scheduleLayout, $date);
     $expectedSlots = $reservationList->BuildSlots();
     $this->assertEquals($expectedSlots, $layoutSlots);
 }
Esempio n. 2
0
 public function GetLayout(Date $date, $resourceId)
 {
     try {
         $hideBlocked = Configuration::Instance()->GetSectionKey(ConfigSection::SCHEDULE, ConfigKeys::SCHEDULE_HIDE_BLOCKED_PERIODS, new BooleanConverter());
         $sw = new StopWatch();
         $sw->Start();
         $items = $this->_reservationListing->OnDateForResource($date, $resourceId);
         $sw->Record('listing');
         $list = new ScheduleReservationList($items, $this->_scheduleLayout, $date, $hideBlocked);
         $slots = $list->BuildSlots();
         $sw->Record('slots');
         $sw->Stop();
         Log::Debug('DailyLayout::GetLayout - For resourceId %s on date %s, took %s seconds to get reservation listing, %s to build the slots, %s total seconds for %s reservations. Memory consumed=%sMB', $resourceId, $date->ToString(), $sw->GetRecordSeconds('listing'), $sw->TimeBetween('slots', 'listing'), $sw->GetTotalSeconds(), count($items), round(memory_get_usage() / 1048576, 2));
         return $slots;
     } catch (Exception $ex) {
         Log::Error('Error getting layout on date %s for resourceId %s. Exception=%s', $date->ToString(), $resourceId, $ex);
         throw $ex;
     }
 }
 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]);
 }