/**
  * Returns a new BookingSummary object for the given booking id.
  * $bookingId : id of booking to get
  * Returns non-null object. Throws DatabaseException if not found.
  */
 static function fetchBookingSummaryForId($bookingId)
 {
     global $wpdb;
     $resultset = $wpdb->get_results($wpdb->prepare("SELECT bk.booking_id, bk.firstname, bk.lastname, bk.referrer, bk.created_by, bk.created_date\r\n               FROM " . $wpdb->prefix . "booking bk\r\n              WHERE bk.booking_id = %d", $bookingId));
     if ($wpdb->last_error) {
         error_log("Failed to execute query " . $wpdb->last_query);
         throw new DatabaseException($wpdb->last_error);
     }
     foreach ($resultset as $res) {
         $summary = new BookingSummary($res->booking_id, $res->firstname, $res->lastname, $res->referrer, $res->created_by, new DateTime($res->created_date));
         $summary->guests = AllocationDBO::fetchGuestNamesForBookingId($res->booking_id);
         $summary->statuses = AllocationDBO::fetchStatusesForBookingId($res->booking_id);
         $summary->resources = ResourceDBO::fetchResourcesForBookingId($res->booking_id);
         $summary->comments = self::fetchBookingComments($res->booking_id, BookingComment::COMMENT_TYPE_USER);
         $summary->bookingDates = AllocationDBO::fetchDatesForBookingId($res->booking_id);
         $summary->isCheckoutAllowed = AllocationDBO::isCheckoutAllowedForBookingId($res->booking_id);
         return $summary;
     }
     throw new DatabaseException("Booking ID {$bookingId} not found!");
 }