RegisterEventController
extends AuthenticatedController
in package
RegisterEventController - Event Registration Management
Handles user registration and unregistration for events. Only accessible to authenticated users.
Refactored to use Data Mapper pattern with Event entities.
Features:
- User registration to events
- User unregistration from events (deletes entire team if group event)
- Duplicate registration prevention
- User authentication verification
- Success/error feedback with flash messages
Tags
Table of Contents
Properties
- $app : Application
- $auth : AuthManager
- $csrf : CsrfProtection
- $request : Request
- $response : Response
- $session : SessionManager
- $eventRepository : EventRepository
- $repo : EventRegistrationRepository
- Event registration repository instance
- $teamRepo : EventTeamRepository
- Event team repository instance
Methods
- __construct() : void
- Constructor - Handle event registration actions
- getCsrfTokenForJs() : string
- Get the CSRF token for JavaScript usage
- redirect() : never
- Redirect to a URL
- redirectWithError() : never
- Redirect with an error message
- redirectWithSuccess() : never
- Redirect with a success message
- render() : void
- Render a view with automatic variable injection
- setError() : void
- Set an error flash message
- setFlash() : void
- Set a flash message
- setInfo() : void
- Set an info flash message
- setSuccess() : void
- Set a success flash message
- setWarning() : void
- Set a warning flash message
- validateCsrf() : bool
- Validate the CSRF token from the request
- redirectWithMessage() : void
- Redirect with a flash message
- register() : void
- Register the current user to an event
- unregister() : void
- Unregister the current user from an event
Properties
$app
protected
Application
$app
$auth
protected
AuthManager
$auth
$csrf
protected
CsrfProtection
$csrf
$request
protected
Request
$request
$response
protected
Response
$response
$session
protected
SessionManager
$session
$eventRepository
private
EventRepository
$eventRepository
$repo
Event registration repository instance
private
EventRegistrationRepository
$repo
$teamRepo
Event team repository instance
private
EventTeamRepository
$teamRepo
Methods
__construct()
Constructor - Handle event registration actions
public
__construct() : void
Supports two actions via GET parameter 'action':
- register: Register current user to the event
- unregister: Unregister current user from the event
Requires GET parameter 'event_id' (positive integer).
Security: Validates event existence, registration status, and user eligibility.
Return values
void —Redirects with appropriate flash message
getCsrfTokenForJs()
Get the CSRF token for JavaScript usage
protected
getCsrfTokenForJs() : string
This method is useful for embedding the token in JavaScript or as a meta tag for automatic AJAX injection.
Return values
string —The current CSRF token
redirect()
Redirect to a URL
protected
redirect(string $url) : never
Parameters
- $url : string
-
Destination URL
Return values
never —Terminates execution
redirectWithError()
Redirect with an error message
protected
redirectWithError(string $url, string $message) : never
Parameters
- $url : string
-
Destination URL
- $message : string
-
Error message
Return values
never —Terminates execution
redirectWithSuccess()
Redirect with a success message
protected
redirectWithSuccess(string $url, string $message) : never
Parameters
- $url : string
-
Destination URL
- $message : string
-
Success message
Return values
never —Terminates execution
render()
Render a view with automatic variable injection
protected
render(string $viewPath[, array<string, mixed> $data = [] ]) : void
This method automatically injects services and data that all views need, eliminating the need to directly access $_SESSION or global functions.
Automatically injected variables:
- $csrf: CsrfProtection service
- $auth: AuthManager service
- $request: Request object
- $flash: Flash messages array (success, error, warning, info)
- $user: Current user data (null if not logged in)
Parameters
- $viewPath : string
-
View path (e.g., 'users/loginPageView')
- $data : array<string, mixed> = []
-
View-specific data
setError()
Set an error flash message
protected
setError(string $message) : void
Parameters
- $message : string
-
Error message
setFlash()
Set a flash message
protected
setFlash(string $type, string $message) : void
Parameters
- $type : string
-
Message type (success, error, warning, info)
- $message : string
-
Message to display
setInfo()
Set an info flash message
protected
setInfo(string $message) : void
Parameters
- $message : string
-
Info message
setSuccess()
Set a success flash message
protected
setSuccess(string $message) : void
Parameters
- $message : string
-
Success message
setWarning()
Set a warning flash message
protected
setWarning(string $message) : void
Parameters
- $message : string
-
Warning message
validateCsrf()
Validate the CSRF token from the request
protected
validateCsrf([string|null $token = null ]) : bool
Supports both traditional POST body tokens and modern AJAX header tokens. Checks in order:
- Provided token parameter
- POST body 'csrf_token' field
- X-CSRF-Token HTTP header (for AJAX requests)
Parameters
- $token : string|null = null
-
Token to validate (if null, retrieves from POST or header)
Return values
bool —True if valid, false otherwise
redirectWithMessage()
Redirect with a flash message
private
redirectWithMessage(int $eventId, string $message[, bool $success = true ]) : void
Helper method to redirect to event list with success or error message.
Parameters
- $eventId : int
- $message : string
-
The message to display
- $success : bool = true
-
True for success message, false for error message
Return values
void —Redirects to event page
register()
Register the current user to an event
private
register(int $eventId) : void
Verifies user authentication and checks for duplicate registration before adding the user to the event.
Parameters
- $eventId : int
-
The event ID to register to
Return values
void —Redirects to event page with flash message
unregister()
Unregister the current user from an event
private
unregister(int $eventId) : void
Security: If user is part of a team, only the team creator can delete the entire team. Other team members can only remove themselves from the team.
Parameters
- $eventId : int
-
The event ID to unregister from
Return values
void —Redirects to event page with flash message