Beispiel #1
0
 public function testConstruct()
 {
     $tenant = new Tenant(11, 'tenant name');
     $room = new Room(4, 1, 'room name');
     $startDate = new DateTime();
     $endDate = (new DateTime())->add(new DateInterval('P1M'));
     $booking = new Booking(123, $tenant, $room, $startDate, $endDate);
     $this->assertEquals(123, $booking->getId());
     $this->assertEquals($tenant, $booking->getTenant());
     $this->assertEquals($startDate, $booking->getStartDate());
     $this->assertEquals($endDate, $booking->getEndDate());
 }
Beispiel #2
0
 /**
  * Check if there's an overlap between the new reservation and the existing ones.
  *
  * @param Booking   $newBooking         The new Booking instance.
  * @param Booking[] $existingBookings   An array that contains the related reservations.
  *
  * @return bool   Return TRUE if there's an overlap, otherwise return FALSE.
  */
 private function isBookingTimeRangesOverlapped(Booking $newBooking, array $existingBookings)
 {
     foreach ($existingBookings as $existingBooking) {
         /** @var Booking $existingBooking */
         if ($newBooking->getId() == $existingBooking->getId()) {
             continue;
         }
         if ($newBooking->getStartDate() < $existingBooking->getEndDate() && $existingBooking->getStartDate() < $newBooking->getEndDate()) {
             return true;
         }
     }
     return false;
 }