Documentation

Event
in package

Class Event

Represents a single event in the system. Maps directly to the 'events' table in the database. Handles data validation, hydration, and CRUD operations.

Table of Contents

Properties

$capacity  : int|null
$description  : string|null
$id  : int|null
$image_filename  : string|null
$location  : string|null
$name  : string|null
$price  : int|null
$registration_deadline  : string|null
$start_datetime  : string|null

Methods

countEvents()  : int
Counts the total number of events in the database.
deleteById()  : bool
Deletes an event from the database by its ID.
fill()  : array<string|int, mixed>
Populates the object properties using an associative array (usually from $_POST).
getAllOrdered()  : array<string|int, Event>
Retrieves all events from the database, ordered by start datetime descending.
getById()  : Event|null
Retrieves a single event from the database by its ID.
getPage()  : array<string|int, Event>
Retrieves a specific page of events for pagination.
insert()  : bool
Inserts the current event object as a new record in the database.
update()  : bool
Updates an existing event record in the database.
validate()  : array<string|int, mixed>
Validates the logical constraints of the object properties.
hydrate()  : Event
Internal helper method to hydrate an object instance from a database row.

Properties

$capacity

public int|null $capacity = null

Maximum number of attendees allowed.

$description

public string|null $description = null

Detailed description of the event.

$id

public int|null $id = null

The unique identifier of the event (Primary Key).

$image_filename

public string|null $image_filename = null

The filename of the associated image (e.g., 'event_123.jpg').

$location

public string|null $location = null

Physical location or address where the event takes place.

$name

public string|null $name = null

The name or title of the event.

$price

public int|null $price = null

The price of admission (0 usually implies free).

$registration_deadline

public string|null $registration_deadline = null

The deadline for user registration (format: Y-m-d H:i:s).

$start_datetime

public string|null $start_datetime = null

The start date and time of the event (format: Y-m-d H:i:s).

Methods

countEvents()

Counts the total number of events in the database.

public static countEvents() : int
Tags
throws
Exception

If there is a database error.

Return values
int

The total count of events.

deleteById()

Deletes an event from the database by its ID.

public static deleteById(int $id) : bool
Parameters
$id : int

The ID of the event to delete.

Tags
throws
Exception

If there is a database error.

Return values
bool

True on success, false on failure.

fill()

Populates the object properties using an associative array (usually from $_POST).

public fill(array<string|int, mixed> $formData[, bool $update = false ]) : array<string|int, mixed>

performs initial type checking and existence validation.

Parameters
$formData : array<string|int, mixed>

The raw data from the form.

$update : bool = false

Indicates if this is an update operation (defaults to false).

Return values
array<string|int, mixed>

An associative array of error messages. If empty, population was successful.

getAllOrdered()

Retrieves all events from the database, ordered by start datetime descending.

public static getAllOrdered() : array<string|int, Event>
Tags
throws
Exception

If there is a database error.

Return values
array<string|int, Event>

An array of Event objects.

getById()

Retrieves a single event from the database by its ID.

public static getById(int $id) : Event|null
Parameters
$id : int

The unique identifier of the event.

Tags
throws
Exception

If there is a database error.

Return values
Event|null

Returns the Event object if found, or null if not.

getPage()

Retrieves a specific page of events for pagination.

public static getPage(int $pageSize, int $page) : array<string|int, Event>
Parameters
$pageSize : int

The number of events per page.

$page : int

The current page number (1-based index).

Tags
throws
Exception

If there is a database error.

Return values
array<string|int, Event>

An array of Event objects for the requested page.

insert()

Inserts the current event object as a new record in the database.

public insert() : bool

Upon success, the object's ID property is updated with the new insert ID.

Tags
throws
Exception

If there is a database insert error.

Return values
bool

True on success, false on failure.

update()

Updates an existing event record in the database.

public update() : bool

The object must have a valid ID set.

Tags
throws
Exception

If the ID is missing or a database error occurs.

Return values
bool

True on success, false on failure.

validate()

Validates the logical constraints of the object properties.

public validate([bool $update = false ]) : array<string|int, mixed>

Checks string lengths, numeric ranges, and date logical order (e.g., start date > deadline).

Parameters
$update : bool = false

If set to true, certain date checks might be skipped or handled differently.

Return values
array<string|int, mixed>

An associative array of validation errors.

hydrate()

Internal helper method to hydrate an object instance from a database row.

private static hydrate(array<string|int, mixed> $row) : Event
Parameters
$row : array<string|int, mixed>

Associative array representing a database row.

Return values
Event

A populated instance of the Event class.


        
On this page

Search results