Documentation

EventModel
in package

EventModel - Unified model for event management

This model centralizes all operations on events (read and write) following the Repository pattern taught in the course (CM4 Slide 22).

Responsibilities:

  • Read: Retrieve events with pagination, filters, etc.
  • Write: Create, update and delete events
Tags
author

BdeLive - Group 8

version
2.0.0

Table of Contents

Properties

$pdo  : PDO

Methods

__construct()  : mixed
Constructor - PDO dependency injection
count()  : int
Count total number of events in the database
deleteEvent()  : bool
Delete an event from the database
findAll()  : array<int, array<string, mixed>>
Retrieve all events for calendar display
findById()  : array<string, mixed>|null
Retrieve an event by its identifier
findBySlug()  : array<string, mixed>|null
Retrieve an event by its SEO-friendly slug
findLatestEvents()  : array<int, array<string, mixed>>
Retrieve upcoming events
findPaginated()  : array<int, array<string, mixed>>
Retrieve a paginated list of events
insertEvent()  : bool
Insert a new event into the database
updateEvent()  : bool
Update an existing event in the database
updateEventImages()  : bool
Update only images associated with an event
slugExists()  : bool
Check if a slug already exists in the database
slugExistsExcludingId()  : bool
Check if a slug exists excluding a specific event ID

Properties

Methods

__construct()

Constructor - PDO dependency injection

public __construct(PDO $pdo) : mixed

Following best practices (CM4 Slide 22), the PDO connection is injected via the constructor to simplify testing and respect the dependency inversion principle.

Parameters
$pdo : PDO

Database connection instance

count()

Count total number of events in the database

public count() : int

Counts all events present in the EVENTS table.

Return values
int

Total number of events

deleteEvent()

Delete an event from the database

public deleteEvent(int $eventId) : bool

Permanently deletes an event identified by its ID. This operation is irreversible.

Parameters
$eventId : int

Identifier of the event to delete

Return values
bool

True on success, false on failure

findAll()

Retrieve all events for calendar display

public findAll() : array<int, array<string, mixed>>
Return values
array<int, array<string, mixed>>

Array of all events

findById()

Retrieve an event by its identifier

public findById(int $id) : array<string, mixed>|null
Parameters
$id : int

Unique event identifier

Return values
array<string, mixed>|null

Event data or null if not found

findBySlug()

Retrieve an event by its SEO-friendly slug

public findBySlug(string $slug) : array<string, mixed>|null

Searches for an event using its URL-friendly slug identifier. This method is used for SEO-optimized URLs instead of numeric IDs.

Parameters
$slug : string

URL-friendly slug (e.g., "mon-evenement-special")

Return values
array<string, mixed>|null

Event data or null if not found

findLatestEvents()

Retrieve upcoming events

public findLatestEvents(int $limit) : array<int, array<string, mixed>>

Retrieves upcoming events sorted by date (ascending) to display the next events first. Returns only events with a date greater than or equal to today.

Parameters
$limit : int

Maximum number of events to retrieve

Return values
array<int, array<string, mixed>>

Array of upcoming events

findPaginated()

Retrieve a paginated list of events

public findPaginated(int $offset, int $limit) : array<int, array<string, mixed>>

Retrieves events with pagination support. Results are sorted by event date and time (descending).

Parameters
$offset : int

Offset calculated by the pagination system

$limit : int

Number of items per page

Return values
array<int, array<string, mixed>>

Array of events for the requested page

insertEvent()

Insert a new event into the database

public insertEvent(string $eventName, DateTime $eventDate, DateTime $eventTime, string $eventLocation, string $eventTheme, string $statusParticipating, string $description[, string $images = '' ][, bool $isGroupEvent = false ][, int $teamSize = 1 ]) : bool

Creates a new event record with all provided information, including Cloudinary images and group registration options.

Parameters
$eventName : string

Event name/title

$eventDate : DateTime

Event date

$eventTime : DateTime

Event time

$eventLocation : string

Event location/venue

$eventTheme : string

Event theme/category

$statusParticipating : string

Allowed participant statuses (comma-separated)

$description : string

Event description

$images : string = ''

JSON string of Cloudinary image URLs

$isGroupEvent : bool = false

Whether this is a group event

$teamSize : int = 1

Maximum team size (for group events)

Return values
bool

True on success, false on failure

updateEvent()

Update an existing event in the database

public updateEvent(int $eventId, string $eventName, DateTime $eventDate, DateTime $eventTime, string $eventLocation, string $eventTheme, string $statusParticipating, string $description, string $images[, bool $isGroupEvent = false ][, int $teamSize = 1 ]) : bool

Updates all information of an existing event identified by its ID. All fields are updated, including images and group registration settings.

Parameters
$eventId : int

Identifier of the event to update

$eventName : string

New event name/title

$eventDate : DateTime

New event date

$eventTime : DateTime

New event time

$eventLocation : string

New event location

$eventTheme : string

New event theme

$statusParticipating : string

New allowed participant statuses

$description : string

New event description

$images : string

New JSON string of image URLs

$isGroupEvent : bool = false

Whether this is a group event

$teamSize : int = 1

Maximum team size

Return values
bool

True on success, false on failure

updateEventImages()

Update only images associated with an event

public updateEventImages(int $eventId, string $imageJson) : bool

Updates the images field of an event without changing other information. Useful after uploading additional images.

Parameters
$eventId : int

Unique event identifier

$imageJson : string

JSON string of image URLs

Return values
bool

True on success, false on failure

slugExists()

Check if a slug already exists in the database

private slugExists(string $slug) : bool

Used to ensure slug uniqueness when creating new events. If a slug exists, SlugGenerator will append a number (e.g., "event-2").

Parameters
$slug : string

The slug to check

Return values
bool

True if exists, false otherwise

slugExistsExcludingId()

Check if a slug exists excluding a specific event ID

private slugExistsExcludingId(string $slug, int $excludeId) : bool

Used during event updates to allow keeping the same slug while preventing conflicts with other events.

Parameters
$slug : string

The slug to check

$excludeId : int

Event ID to exclude from check

Return values
bool

True if exists, false otherwise


        
On this page

Search results