Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- To use any of these functions, just add the following to the top of your script:
- include '/modules/API.php';
- makeReservation( roomid, roomname, username, start, end)
- cancelReservation( reservationid )
- getReservationSet( roomid, afterdate, beforedate, group, byuser, reservationid )
- makeCollisionReservation( roomid, roomname, username, start, end)
- _collider( roomid, start, end )
- getRooms(roomgroup)
- makeReservation( roomid, roomname, username, start, end)
- Reserves a room for the passed parameters. Does not check for collisions.
- Parameters:
- $roomid - The roomid to where the reservation will be made. Either this or roomname must be specified.
- $roomname - The roomane of where the reservation will be made. Either this or roomid must be specified.
- $username - The username of the person making the reservation, this should be unhashed. The standard is studentid, but a general username is also fine.
- $start - The start time of the reservation, should be formatted either as Y-m-d H:i:s OR as a Unix timestamp.
- $end - The end time of the reservation, should be formatted either as Y-m-d H:i:s OR as a Unix timestamp.
- Returns:
- A boolean representing if the reservation was successful or not.
- Throws:
- InvalidTimeSelections if the start time is after the end time.
- InvalidTimeFormat if $start or $end are not in the specified formats
- NoRoomSpecified if roomid and roomname were both left blank.
- cancelReservation( reservationid )
- Cancels the specified reservation.
- Parameters:
- $reservationid - the reservationid of the reservation to be cancelled. You may pull this from the database manually or from getReservations()
- Returns:
- A boolean representing if the cancellation was successful or not.
- Throws:
- RoomDoesNotExist if the reservationid was not found in the database
- getReservationSet( roomid, afterdate, beforedate, group, byuser, reservationid )
- Gets a set of reservations and their corresponding attributes. All parameters are optional, and each will be seen as an additional constraint when returning the set; reservationid is exclusive. If no parameter is defined it will return all reservations (may be very large). Does not return cleaning reservations.
- Parameters:
- $roomid - A specific room to gather reservations from.
- $afterdate - All reservations after specified date. Should be formatted either as Y-m-d H:i:s OR as a Unix timestamp.
- $beforedate - All reservations before specified date. Should be formatted either as Y-m-d H:i:s OR as a Unix timestamp
- $group - All reservations on a specific floor.
- $byuser - Only gathers reservations that were made by the specified user; Unhashed username.
- $reservationid - Only get the reservation of this id.
- Returns:
- A multi-dimensional array containing all reservations that fall within the constraints and their attributes. The array looks like $array[n]['attribute']. The first index is just normal array style, numerical, the second part is associative. The returned attributes are: reservationid, start (Y-m-d H:i:s), end (Y-m-d H:i:s), roomid, username, timeofrequest, email, name, description.
- Throws:
- InvalidTimeSelections if beforedate occurs before afterdate.
- InvalidReservationid if the passed reservationid does not exist.
- makeCollisionReservation( roomid, roomname, username, start, end)
- Reserves a room for the passed parameters. Checks for collisions with both room hours and other reservations. Calls _collider().
- Parameters:
- $roomid - The roomid to where the reservation will be made. Either this or roomname must be specified.
- $roomname - The roomane of where the reservation will be made. Either this or roomid must be specified.
- $username - The username of the person making the reservation, this should be unhashed. The standard is studentid, but a general username is also fine.
- $start - The start time of the reservation, should be formatted either as Y-m-d H:i:s OR as a Unix timestamp.
- $end - The end time of the reservation, should be formatted either as Y-m-d H:i:s OR as a Unix timestamp.
- Returns:
- A boolean representing if the reservation was successful or not.
- Throws:
- InvalidTimeSelections if the start time is after the end time.
- InvalidTimeFormat if $start or $end are not in the specified formats
- NoRoomSpecified if roomid and roomname were both left blank.
- CollisionDetected if the reservations collided.
- _collider( roomid, start, end )
- Checks for a collision for a potential reservation. Helper function for makeCollisionReservation(). May have uses elsewhere.
- Parameters:
- $roomid - The roomid to where the reservation will be made. Either this or roomname must be specified.
- $start - The start time of the reservation, should be formatted as a Unix timestamp.
- $end - The end time of the reservation, should be formatted as a Unix timestamp.
- Returns:
- A boolean representing if the reservation collides with "something" or not.
- Throws:
- InvalidTimeSelections if the start time is after the end time.
- InvalidTimeFormat if $start or $end are not in the specified formats.
- NoRoomSpecified if roomid and roomname were both left blank.
- getRooms(roomgroup)
- Gets a set of rooms and their corresponding attributes.
- Parameters:
- $roomgroup -The specific floor/group to grab the rooms from
- Returns:
- A multi-dimensional array representing all the rooms and their attributes such that $array[n]['attribute']. The first part being numeric and the second part being associative. The attributes it returns are: roomid, roomname, roomgroupid, roomdescription, array(roomhours), array(specialhours)
- roomhours; such that $array[n]['roomhours'] = $hours[d]['attributes'] where d is 0-6 day of the week, attributes are 'start', 'end',
- specialhours; such that $array[n]['specialhours'] = $specialhours['attributes'] where attributes are fromrange (Y-m-d H:i:s), torange (Y-m-d H:i:s), start (H:i:s), end (H:i:s)
- Throws:
- InvalidRoomGroup if the floor/group does not exist.
Add Comment
Please, Sign In to add comment