X-Git-Url: https://git.rohieb.name/iserv-mod-room-reservation.git/blobdiff_plain/7d874525c50d509f90a4949563fe11a36cdd0357..HEAD:/inc/mod_roomReservationBookingsManager.inc?ds=sidebyside diff --git a/inc/mod_roomReservationBookingsManager.inc b/inc/mod_roomReservationBookingsManager.inc index 124068d..d05b4c7 100644 --- a/inc/mod_roomReservationBookingsManager.inc +++ b/inc/mod_roomReservationBookingsManager.inc @@ -98,10 +98,13 @@ class mod_roomReservationBookingsManager { * Get all bookings in database which overlap with the given booking. * @param $ob (mod_roomReservationBooking) New booking that should be tested * if it overlaps + * @param $bUnblocks (bool) If true, consider $ob as a unblock of a specific + * booking. In this case, you have to specify the Unique ID of the original + * booking in $ob-> * @return array with elements of type mod_roomReservationBooking */ public static function getOverlappingBookings( - mod_roomReservationBooking $ob) { + mod_roomReservationBooking $ob, $bUnblocks = false) { // TODO: Test for bookings that only take place every n.th week (modulo n) // Two bookings overlap, when they are on the same day and if @@ -135,7 +138,6 @@ class mod_roomReservationBookingsManager { * @param $ob (mod_roomReservationBooking) Booking to write to the database * @return (int) The UID of the written booking * @throws SQLException, AccessException - * @todo document */ function write(mod_roomReservationBooking $ob) { // protect access @@ -184,7 +186,7 @@ class mod_roomReservationBookingsManager { // No UID yet, insert new booking // @todo write interval and user if interval > 0 $strLog = sprintf("Raum „%s“ am %s von %s bis %s gebucht ". - "(Begründung: %s)", $ob->getRoom(), date("d\.m\.Y", $ob->getDate()), + "(Begründung: %s)", $ob->getRoom(), date("d\.m\.Y", $ob->getDate()), gmdate("G:i", $oTsB[$ob->getTsFirst()]), gmdate("G:i", $oTsE[$ob->getTsLast()]), $ob->getReason()); } else { @@ -221,7 +223,6 @@ class mod_roomReservationBookingsManager { * Delete a booking from the database * @param $nUid (int) Unique ID of the booking * @return (bool) true on success, otherwise false. - * @todo test */ public function delete($nUid) { // Only administrators and owners are allowed to delete bookings @@ -240,7 +241,7 @@ class mod_roomReservationBookingsManager { $oTsE[$ob->getTsLast()]), $ob->getReason()); // Delete it from the database if(!db_query("DELETE FROM mod_roomreservation_bookings WHERE ". - "rrb_uid = $1;", $nUid)) { + "rrb_uid = $1;", $nUid)) { throw new SQLException(MOD_ROOM_RESERVATION_ERROR_SQL); return false; } else { @@ -248,6 +249,37 @@ class mod_roomReservationBookingsManager { return true; } } + + /** + * Unblocks a booking for a specific time. Useful to release a room for a + * specific time if it has been blocked by a recurring booking + * @param $nUid Unique ID of the booking to be unblocked + * @param $tsStart The timestamp when the unblock starts + * @param $tsEnd The timestamp when the unblock ends + * @return bool + * @todo implement this + */ + function unblock($nUid, $tsStart, $tsEnd) { + // unblocking only allowed to owners and admins + if(!$this->userIsOwner($nUid) || !$this->cfg->userIsAdmin()) { + throw new AccessException(MOD_ROOM_RESERVATION_ERROR_ACCESS_DENIED); + } + return false; + } + + /** + * Re-blocks a booking that has been unblocked by unblock(). + * @param $nUid Unique ID of the booking to be unblocked + * @return bool + * @todo implement this + */ + function reblock($nUid, $tsStart, $tsEnd) { + // re-blocking only allowed to owners and admins + if(!$this->userIsOwner($nUid) || !$this->cfg->userIsAdmin()) { + throw new AccessException(MOD_ROOM_RESERVATION_ERROR_ACCESS_DENIED); + } + return false; + } /** * Determine if the current user is the owner of a specified error report. @@ -261,7 +293,7 @@ class mod_roomReservationBookingsManager { return false; // user is not logged in } else { $hQuery = db_query("SELECT rrb_act FROM mod_roomreservation_bookings WHERE ". - "rrb_uid = $1;", intval($nID)); + "rrb_uid = $1;", intval($nID)); if(!is_resource($hQuery)) { throw new SQLException(MOD_ROOM_RESERVATION_ERROR_SQL); return false;