ScheduleController
extends DefaultController
in package
Controller responsible for managing schedules.
Displays group schedules using FullCalendar.
Tags
Table of Contents
Constants
- GROUPS = ['1ere' => ['name' => '1ère année', 'groups' => ['G1A' => 'Groupe 1A', 'G1B' => 'Groupe 1B', 'G2A' => 'Groupe 2A', 'G2B' => 'Groupe 2B', 'G3A' => 'Groupe 3A', 'G3B' => 'Groupe 3B', 'G4A' => 'Groupe 4A', 'G4B' => 'Groupe 4B']], '2eme' => ['name' => '2ème année', 'groups' => ['GA1-1' => 'Groupe A1-1', 'GA1-2' => 'Groupe A1-2', 'GA2-1' => 'Groupe A2-1', 'GA2-2' => 'Groupe A2-2', 'GB-1' => 'Groupe B-1', 'GB-2' => 'Groupe B-2']], '3eme' => ['name' => '3ème année', 'groups' => ['GA1-1' => 'Groupe A1-1', 'GA1-2' => 'Groupe A1-2', 'GA2-1' => 'Groupe A2-1', 'GA2-2' => 'Groupe A2-2', 'GB-1' => 'Groupe B-1', 'GB-2' => 'Groupe B-2']]]
- ICS_DIRECTORY = __DIR__ . '/../../../Schedule/'
Properties
- $app : Application
- $auth : AuthManager
- $csrf : CsrfProtection
- $request : Request
- $response : Response
- $session : SessionManager
Methods
- __construct() : void
- Initializes the controller.
- 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
- cleanIcsText() : string
- Cleans text extracted from an .ics file.
- eventMatchesGroup() : bool
- Checks if an event belongs to the specified half-group.
- formatEventForFullCalendar() : array<string, mixed>
- Formats an .ics event for FullCalendar.
- getEventColor() : string
- Returns a color based on the course type.
- getEvents() : void
- API: Returns events in JSON format for FullCalendar.
- getEventsForDay() : array<int, array<string, mixed>>
- Retrieves events for a specific day.
- getEventsForNativeCalendar() : array<int, array<string, mixed>>
- Retrieves events for the native calendar (filtered by month).
- getEventsForWeeklySchedule() : array<int, array<string, mixed>>
- Retrieves events for the weekly view (filtered by week).
- getEventType() : string
- Determines the event type from the title.
- loadViewAjax() : void
- Loads a specific view via AJAX (returns only the HTML of the view).
- parseIcsDate() : string
- Parses a date in .ics format (YYYYMMDDTHHMMSSZ) and converts UTC → Europe/Paris.
- parseIcsFile() : array<int, array<string, mixed>>
- Parses an .ics file and returns events filtered by group.
- showSchedulePage() : void
- Displays the main schedule selection and visualization page.
Constants
GROUPS
private
mixed
GROUPS
= ['1ere' => ['name' => '1ère année', 'groups' => ['G1A' => 'Groupe 1A', 'G1B' => 'Groupe 1B', 'G2A' => 'Groupe 2A', 'G2B' => 'Groupe 2B', 'G3A' => 'Groupe 3A', 'G3B' => 'Groupe 3B', 'G4A' => 'Groupe 4A', 'G4B' => 'Groupe 4B']], '2eme' => ['name' => '2ème année', 'groups' => ['GA1-1' => 'Groupe A1-1', 'GA1-2' => 'Groupe A1-2', 'GA2-1' => 'Groupe A2-1', 'GA2-2' => 'Groupe A2-2', 'GB-1' => 'Groupe B-1', 'GB-2' => 'Groupe B-2']], '3eme' => ['name' => '3ème année', 'groups' => ['GA1-1' => 'Groupe A1-1', 'GA1-2' => 'Groupe A1-2', 'GA2-1' => 'Groupe A2-1', 'GA2-2' => 'Groupe A2-2', 'GB-1' => 'Groupe B-1', 'GB-2' => 'Groupe B-2']]]
ICS_DIRECTORY
private
mixed
ICS_DIRECTORY
= __DIR__ . '/../../../Schedule/'
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
Methods
__construct()
Initializes the controller.
public
__construct() : void
Handles API requests for events and AJAX requests for views. Starts the session and sets up the environment.
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
cleanIcsText()
Cleans text extracted from an .ics file.
private
cleanIcsText(string $text) : string
Parameters
- $text : string
-
Raw text from .ics
Return values
string —Cleaned text
eventMatchesGroup()
Checks if an event belongs to the specified half-group.
private
eventMatchesGroup(array<string, string> $event, string $group, string $year) : bool
For a selected half-group (e.g., "G1A"), matches:
- Specific courses for the half-group: "G1A"
- Whole group courses: "G1", "Groupe 1"
Parameters
- $event : array<string, string>
-
.ics event data
- $group : string
-
Selected half-group (e.g., "G1A")
- $year : string
-
Selected year (e.g., "1ere")
Return values
bool —True if the event matches the group
formatEventForFullCalendar()
Formats an .ics event for FullCalendar.
private
formatEventForFullCalendar(array<string, string> $event) : array<string, mixed>
Parameters
- $event : array<string, string>
-
.ics event data (key/value)
Return values
array<string, mixed> —Event formatted for FullCalendar
getEventColor()
Returns a color based on the course type.
private
getEventColor(string $summary) : string
Parameters
- $summary : string
-
Event summary/title
Return values
string —Hex color code
getEvents()
API: Returns events in JSON format for FullCalendar.
private
getEvents() : void
getEventsForDay()
Retrieves events for a specific day.
private
getEventsForDay(string $yearLevel, string $group, string $date) : array<int, array<string, mixed>>
Parameters
- $yearLevel : string
-
Year level (e.g., '1ere', '2eme')
- $group : string
-
Group identifier
- $date : string
-
Date string (YYYY-MM-DD)
Return values
array<int, array<string, mixed>> —List of events for the day
getEventsForNativeCalendar()
Retrieves events for the native calendar (filtered by month).
private
getEventsForNativeCalendar(string $year, string $group, int $month, int $calYear) : array<int, array<string, mixed>>
Parameters
- $year : string
-
Year group ('1ere', '2eme', '3eme')
- $group : string
-
Selected group
- $month : int
-
Month (1-12)
- $calYear : int
-
Calendar year (e.g., 2026)
Return values
array<int, array<string, mixed>> —Events formatted for native calendar
getEventsForWeeklySchedule()
Retrieves events for the weekly view (filtered by week).
private
getEventsForWeeklySchedule(string $year, string $group, int $week, int $calYear) : array<int, array<string, mixed>>
Parameters
- $year : string
-
Year group ('1ere', '2eme', '3eme')
- $group : string
-
Selected group
- $week : int
-
Week number (1-53)
- $calYear : int
-
Calendar year (e.g. 2026)
Return values
array<int, array<string, mixed>> —Events formatted for weekly view
getEventType()
Determines the event type from the title.
private
getEventType(string $title) : string
Parameters
- $title : string
-
Event title
Return values
string —Event type
loadViewAjax()
Loads a specific view via AJAX (returns only the HTML of the view).
private
loadViewAjax() : void
parseIcsDate()
Parses a date in .ics format (YYYYMMDDTHHMMSSZ) and converts UTC → Europe/Paris.
private
parseIcsDate(string $icsDate) : string
Parameters
- $icsDate : string
-
Date string in .ics format
Return values
string —Formatted date string (YYYY-MM-DDTHH:MM:SS) in local timezone
parseIcsFile()
Parses an .ics file and returns events filtered by group.
private
parseIcsFile(string $filePath, string $group, string $year) : array<int, array<string, mixed>>
Parameters
- $filePath : string
-
Path to the .ics file
- $group : string
-
Group to filter (e.g., 'G1A')
- $year : string
-
Selected year (e.g., '1ere')
Return values
array<int, array<string, mixed>> —Events formatted for FullCalendar
showSchedulePage()
Displays the main schedule selection and visualization page.
private
showSchedulePage() : void