Registration
in package
Class Registration
Manages the many-to-many relationship between Users and Events. This class handles the creation, deletion, and retrieval of registration records, including logic for enforcing event capacities and preventing duplicate sign-ups.
Table of Contents
Properties
- $event : Event
- $id : int
- $id_event : int
- $id_user : int
- $registration_datetime : string
- $user : User
Methods
- createRegistration() : bool
- Creates a new registration record transactionally.
- deleteRegistration() : bool
- Removes a registration record from the database.
- existsByUserIdAndEventId() : bool|null
- Checks if a specific user is already registered for a specific event.
- findEventRegistrationsByEventId() : array<string|int, User>
- Retrieves all users registered for a specific event.
- getAllOrdered() : array<string|int, Registration>
- Retrieves all registrations existing in the system, ordered by ID descending.
- getEventsByUser() : array<string|int, Event>
- Retrieves a list of events that a specific user has registered for.
- getRegistrationById() : Registration|null
- Retrieves a single registration record by its ID.
- hydrate() : Registration
- Creates a Registration object instance from a database row.
- isUserRegistered() : bool
- Determines if a user is currently registered for an event.
- numberOfRegistrationsByEventId() : int|null
- Counts the total number of registrations for a specific event.
Properties
$event
public
Event
$event
The full Event object associated with this registration.
$id
public
int
$id
The unique identifier for the registration record.
$id_event
public
int
$id_event
The ID of the event associated with this registration.
$id_user
public
int
$id_user
The ID of the user associated with this registration.
$registration_datetime
public
string
$registration_datetime
The timestamp of when the registration was created.
$user
public
User
$user
The full User object associated with this registration.
Methods
createRegistration()
Creates a new registration record transactionally.
public
static createRegistration(Registration $registration) : bool
This method utilizes database row locking (FOR UPDATE) to prevent race conditions where multiple users might try to register for the last available slot simultaneously.
Parameters
- $registration : Registration
-
The registration object containing the user and event IDs.
Tags
Return values
bool —True if the registration was successful.
deleteRegistration()
Removes a registration record from the database.
public
static deleteRegistration(Registration $registration) : bool
Parameters
- $registration : Registration
-
The registration object to delete.
Tags
Return values
bool —True if the deletion was successful.
existsByUserIdAndEventId()
Checks if a specific user is already registered for a specific event.
public
static existsByUserIdAndEventId(int $userId, int $eventId) : bool|null
Parameters
- $userId : int
-
The ID of the user.
- $eventId : int
-
The ID of the event.
Tags
Return values
bool|null —True if a registration exists, false otherwise.
findEventRegistrationsByEventId()
Retrieves all users registered for a specific event.
public
static findEventRegistrationsByEventId(int $eventId) : array<string|int, User>
Parameters
- $eventId : int
-
The ID of the event.
Tags
Return values
array<string|int, User> —An array of User objects, keyed by the registration ID.
getAllOrdered()
Retrieves all registrations existing in the system, ordered by ID descending.
public
static getAllOrdered() : array<string|int, Registration>
Tags
Return values
array<string|int, Registration> —An array of Registration objects.
getEventsByUser()
Retrieves a list of events that a specific user has registered for.
public
static getEventsByUser(int $userId) : array<string|int, Event>
Parameters
- $userId : int
-
The ID of the user.
Tags
Return values
array<string|int, Event> —An array of Event objects.
getRegistrationById()
Retrieves a single registration record by its ID.
public
static getRegistrationById(int $id) : Registration|null
Parameters
- $id : int
-
The ID of the registration.
Tags
Return values
Registration|null —The Registration object, or null if not found.
hydrate()
Creates a Registration object instance from a database row.
public
static hydrate(array<string|int, mixed> $data) : Registration
Note: This method automatically fetches the associated User and Event objects.
Parameters
- $data : array<string|int, mixed>
-
Associative array containing database column data.
Return values
Registration —The hydrated Registration object.
isUserRegistered()
Determines if a user is currently registered for an event.
public
static isUserRegistered(int $userId, int $eventId) : bool
Parameters
- $userId : int
-
The ID of the user.
- $eventId : int
-
The ID of the event.
Tags
Return values
bool —True if the user is registered, false otherwise.
numberOfRegistrationsByEventId()
Counts the total number of registrations for a specific event.
public
static numberOfRegistrationsByEventId(int $eventId) : int|null
Parameters
- $eventId : int
-
The ID of the event to count.
Tags
Return values
int|null —The count of registrations, or null on error context.