CoolCMS API

InitTrait

Prepares the data of the month grid (step 1) and the day panel (step 2) for the template.

Shared with FormTrait, which needs the starts of the chosen day (see fetchDayData()).

Table of Contents

Constants

MONTH_KEYS  : array<string|int, mixed> = ['01' => 'jan', '02' => 'feb', '03' => 'mar', '...
`MM` mapped to a short key under `calendar.months.*` (own keys; there is no system month localization).

Methods

buildWeeks()  : array<int, array<int, array{date: string, dayNumber: int, state: string, freeMinutesLabel: string|null, isPast: bool, isToday: bool}|null>>
Builds the month grid by weeks (Monday first); a `null` cell is padding outside the month.
currentMonth()  : string
fetchAvailability()  : array<string, mixed>
Returns `TimeSlotManager::availability()` for `$this->month`, memoized for the lifetime of this component instance (one request). Required because the step 2 form can be created before `render()` (a form POST calls `createComponent*()` first, and `render()` would not run at all on a redirect or an error), so `prepareCalendar()` alone cannot be relied on.
fetchDayData()  : array<string, mixed>|null
Returns the data of the chosen day (`starts`/`free`/`busy`/...), or `null` when no day is chosen or it does not exist.
formatMinutes()  : string
Minutes since midnight to `H:MM` (same as the Api `TimeSlotManager::formatMinutes()`, without a cross-module import).
prepareCalendar()  : void
resolveDay()  : string|null
Accepts the chosen day only when it belongs to the displayed month and exists in the Api response; otherwise a day from another month would stay in the URL after switching months.
resolveMonth()  : string
`YYYY-MM`; empty, invalid or past input falls back to the server's current month.
shiftMonth()  : string

Constants

MONTH_KEYS

`MM` mapped to a short key under `calendar.months.*` (own keys; there is no system month localization).

private array<string|int, mixed> MONTH_KEYS = ['01' => 'jan', '02' => 'feb', '03' => 'mar', '04' => 'apr', '05' => 'may', '06' => 'jun', '07' => 'jul', '08' => 'aug', '09' => 'sep', '10' => 'oct', '11' => 'nov', '12' => 'dec']

Methods

buildWeeks()

Builds the month grid by weeks (Monday first); a `null` cell is padding outside the month.

private static buildWeeks(string $month, array<string, mixed> $days) : array<int, array<int, array{date: string, dayNumber: int, state: string, freeMinutesLabel: string|null, isPast: bool, isToday: bool}|null>>
Parameters
$month : string
$days : array<string, mixed>
Return values
array<int, array<int, array{date: string, dayNumber: int, state: string, freeMinutesLabel: string|null, isPast: bool, isToday: bool}|null>>

currentMonth()

private static currentMonth() : string
Return values
string

fetchAvailability()

Returns `TimeSlotManager::availability()` for `$this->month`, memoized for the lifetime of this component instance (one request). Required because the step 2 form can be created before `render()` (a form POST calls `createComponent*()` first, and `render()` would not run at all on a redirect or an error), so `prepareCalendar()` alone cannot be relied on.

private fetchAvailability() : array<string, mixed>

The return type is deliberately loose: availability is fail-soft (a read error gives an empty payload), so consumers guard the keys themselves.

Return values
array<string, mixed>

fetchDayData()

Returns the data of the chosen day (`starts`/`free`/`busy`/...), or `null` when no day is chosen or it does not exist.

private fetchDayData() : array<string, mixed>|null
Return values
array<string, mixed>|null

formatMinutes()

Minutes since midnight to `H:MM` (same as the Api `TimeSlotManager::formatMinutes()`, without a cross-module import).

private static formatMinutes(int $minutes) : string
Parameters
$minutes : int
Return values
string

prepareCalendar()

private prepareCalendar() : void

resolveDay()

Accepts the chosen day only when it belongs to the displayed month and exists in the Api response; otherwise a day from another month would stay in the URL after switching months.

private resolveDay(array<string, mixed> $days) : string|null
Parameters
$days : array<string, mixed>
Return values
string|null

resolveMonth()

`YYYY-MM`; empty, invalid or past input falls back to the server's current month.

private static resolveMonth(string|null $month) : string
Parameters
$month : string|null
Return values
string

shiftMonth()

private static shiftMonth(string $month, int $delta) : string
Parameters
$month : string
$delta : int
Return values
string
On this page

Search results