Guest User

Untitled

a guest
Oct 19th, 2018
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 5.97 KB | None | 0 0
  1. To use any of these functions, just add the following to the top of your script:
  2.  
  3. include '/modules/API.php';
  4.  
  5.  
  6.  
  7. makeReservation( roomid, roomname, username, start, end)
  8.  
  9. cancelReservation( reservationid )
  10.  
  11. getReservationSet( roomid, afterdate, beforedate, group, byuser, reservationid )
  12.  
  13. makeCollisionReservation( roomid, roomname, username, start, end)
  14.  
  15. _collider( roomid, start, end )
  16.  
  17. getRooms(roomgroup)
  18.  
  19.  
  20.  
  21. makeReservation( roomid, roomname, username, start, end)
  22.  
  23. Reserves a room for the passed parameters. Does not check for collisions.
  24.  
  25. Parameters:
  26.  
  27. $roomid - The roomid to where the reservation will be made. Either this or roomname must be specified.
  28.  
  29. $roomname - The roomane of where the reservation will be made. Either this or roomid must be specified.
  30.  
  31. $username - The username of the person making the reservation, this should be unhashed. The standard is studentid, but a general username is also fine.
  32.  
  33. $start - The start time of the reservation, should be formatted either as Y-m-d H:i:s OR as a Unix timestamp.
  34.  
  35. $end - The end time of the reservation, should be formatted either as Y-m-d H:i:s OR as a Unix timestamp.
  36.  
  37. Returns:
  38.  
  39. A boolean representing if the reservation was successful or not.
  40.  
  41. Throws:
  42.  
  43. InvalidTimeSelections if the start time is after the end time.
  44.  
  45. InvalidTimeFormat if $start or $end are not in the specified formats
  46.  
  47. NoRoomSpecified if  roomid and roomname were both left blank.
  48.  
  49.  
  50.  
  51. cancelReservation( reservationid )
  52.  
  53. Cancels the specified reservation.
  54.  
  55. Parameters:
  56.  
  57. $reservationid - the reservationid of the reservation to be cancelled. You may pull this from the database manually or from getReservations()
  58.  
  59. Returns:
  60.  
  61. A boolean representing if the cancellation was successful or not.
  62.  
  63. Throws:
  64.  
  65. RoomDoesNotExist if the reservationid was not found in the database
  66.  
  67.  
  68.  
  69. getReservationSet( roomid, afterdate, beforedate, group, byuser, reservationid )
  70.  
  71. 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.
  72.  
  73. Parameters:
  74.  
  75. $roomid - A specific room to gather reservations from.
  76.  
  77. $afterdate - All reservations after specified date. Should be formatted either as Y-m-d H:i:s OR as a Unix timestamp.
  78.  
  79. $beforedate - All reservations before specified date. Should be formatted either as Y-m-d H:i:s OR as a Unix timestamp
  80.  
  81. $group - All reservations on a specific floor.
  82.  
  83. $byuser - Only gathers reservations that were made by the specified user; Unhashed username.
  84.  
  85. $reservationid - Only get the reservation of this id.
  86.  
  87. Returns:
  88.  
  89. 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.
  90.  
  91. Throws:
  92.  
  93. InvalidTimeSelections if beforedate occurs before afterdate.
  94.  
  95. InvalidReservationid if the passed reservationid does not exist.
  96.  
  97.  
  98.  
  99. makeCollisionReservation( roomid, roomname, username, start, end)
  100.  
  101. Reserves a room for the passed parameters. Checks for collisions with both room hours and other reservations. Calls _collider().
  102.  
  103. Parameters:
  104.  
  105. $roomid - The roomid to where the reservation will be made. Either this or roomname must be specified.
  106.  
  107. $roomname - The roomane of where the reservation will be made. Either this or roomid must be specified.
  108.  
  109. $username - The username of the person making the reservation, this should be unhashed. The standard is studentid, but a general username is also fine.
  110.  
  111. $start - The start time of the reservation, should be formatted either as Y-m-d H:i:s OR as a Unix timestamp.
  112.  
  113. $end - The end time of the reservation, should be formatted either as Y-m-d H:i:s OR as a Unix timestamp.
  114.  
  115. Returns:
  116.  
  117. A boolean representing if the reservation was successful or not.
  118.  
  119. Throws:
  120.  
  121. InvalidTimeSelections if the start time is after the end time.
  122.  
  123. InvalidTimeFormat if $start or $end are not in the specified formats
  124.  
  125. NoRoomSpecified if  roomid and roomname were both left blank.
  126.  
  127. CollisionDetected if the reservations collided.
  128.  
  129.  
  130.  
  131. _collider( roomid, start, end )
  132.  
  133. Checks for a collision for a potential reservation. Helper function for makeCollisionReservation(). May have uses elsewhere.
  134.  
  135. Parameters:
  136.  
  137. $roomid - The roomid to where the reservation will be made. Either this or roomname must be specified.
  138.  
  139. $start - The start time of the reservation, should be formatted as a Unix timestamp.
  140.  
  141. $end - The end time of the reservation, should be formatted as a Unix timestamp.
  142.  
  143. Returns:
  144.  
  145. A boolean representing if the reservation collides with "something" or not.
  146.  
  147. Throws:
  148.  
  149. InvalidTimeSelections if the start time is after the end time.
  150.  
  151. InvalidTimeFormat if $start or $end are not in the specified formats.
  152.  
  153. NoRoomSpecified if  roomid and roomname were both left blank.
  154.  
  155.  
  156.  
  157. getRooms(roomgroup)
  158.  
  159. Gets a set of rooms and their corresponding attributes.
  160.  
  161. Parameters:
  162.  
  163. $roomgroup -The specific floor/group to grab the rooms from
  164.  
  165. Returns:
  166.  
  167. 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)
  168.  
  169. roomhours; such that $array[n]['roomhours'] = $hours[d]['attributes'] where d is 0-6 day of the week, attributes are 'start', 'end',
  170.  
  171. 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)
  172.  
  173. Throws:
  174.  
  175. InvalidRoomGroup if the floor/group does not exist.
Add Comment
Please, Sign In to add comment