Reservation Model
TheReservation model manages room reservation records (expedientes) in the system. It handles the creation, retrieval, and status management of reservations, as well as the association with materials and time slots.
Constructor
Methods
create()
Creates a new reservation record.ID of the user creating the reservation
ID of the room being reserved
Name of the event for this reservation
Optional notes or additional information about the reservation
int - The ID of the newly created reservation
SQL Query:
findById()
Retrieves a single reservation by its ID with joined user and room information.The reservation ID to retrieve
?array - Associative array with reservation data or null if not found
Reservation ID
ID of the user who created the reservation
ID of the reserved room
Name of the event
Reservation status: ‘pendiente’, ‘aprobado’, or ‘rechazado’
Additional notes about the reservation
Timestamp when the reservation was created
Username of the person who created the reservation
Name of the reserved room
getAll()
Retrieves all reservations with basic information. Primarily used by the Comunicación y Difusión department.array - Array of associative arrays containing reservation data
Reservation ID
Name of the event
Current reservation status
Creation timestamp
Name of the reserved room
Username of the requester
updateStatus()
Updates the status of a reservation. Used by administrators to approve or reject reservations.The ID of the reservation to update
The new status. Must be one of: ‘pendiente’, ‘aprobado’, ‘rechazado’
bool - true if the update was successful
Throws: InvalidArgumentException - If an invalid status is provided
The method validates that the status is one of the three allowed values before executing the update.
attachMaterials()
Assigns materials to a reservation. Replaces any previously assigned materials.The ID of the reservation
Array of material IDs to assign to the reservation
void
This method:
- Deletes all existing material assignments for the reservation
- Normalizes the input array (removes duplicates, filters invalid IDs)
- Inserts new material assignments
getMaterials()
Retrieves all materials assigned to a specific reservation.The ID of the reservation
array - Array of associative arrays containing material data
Material ID
Material name
getByStatus()
Retrieves reservations filtered by their status.The status to filter by: ‘pendiente’, ‘aprobado’, or ‘rechazado’
array - Array of reservations with the specified status, or empty array if invalid status
Reservation ID
Name of the event
Reservation status
Creation timestamp
Name of the reserved room
Username of the requester
getByUser()
Retrieves all reservations created by a specific user.The ID of the user
array - Array of reservations created by the user
Reservation ID
Name of the event
Current reservation status
Creation timestamp
Name of the reserved room
getSlots()
Retrieves all time slots associated with a reservation.The ID of the reservation
array - Array of time slot data ordered by date and start time
Date of the time slot (YYYY-MM-DD)
Start time of the slot (HH:MM:SS)
End time of the slot (HH:MM:SS)
Database Schema
The Reservation model interacts with the following database tables:- reservations - Main reservation records
- reservation_slots - Time slots for each reservation
- reservation_materials - Junction table linking reservations to materials
- users - User information
- rooms - Room information
- materials - Material catalog
Status Values
Reservations can have one of three statuses:pendiente- Pending approvalaprobado- Approved by Comunicación y Difusiónrechazado- Rejected