CoolCMS API

TimeSlotFormTrait

Add/edit form for a calendar time slot: company, date and three modes in one form (`mode` switch).

  • TimeSlotType::Slot (public = 1): daily override replacing the default grid from working hours with custom offered windows.
  • TimeSlotType::Blocked: admin block occupying part of a day without a client. The Api guard (beforeSave) rejects it with VALIDATION_FAILED when it collides with a reservation or another block; this trait does not check that, saveTimeSlotForm() just lets the failure through.
  • TimeSlotType::ClosedDay: closes the whole day, time from/to is ignored and the server sets 00:00-00:00.

IMPORTANT: a row created by the admin form must have public = 1 in all three modes. For an override it flips the day into override mode, for a block it is the editability condition (see TimeSlotPresenter::actionEdit()). buildTimeSlotEntity() therefore ignores the POSTed hidden public field and sets true; never trust POST for contract-relevant flags.

Rows with public = 0 (materialized reservation carriers) are blocked from editing in the presenter.

calendarId is an optional select: left empty (0), TimeSlotManager::beforeSave() uses CalendarManager::resolveDefault(), so companies with several calendars can pick a non-default one here.

Table of Contents

Methods

createComponentEditForm()  : Form
addBasicFields()  : void
Adds company, date, mode switch (override / block / close day), time window (conditionally required) and note.
buildTimeSlotEntity()  : TimeSlot
modeOptions()  : array<string, string>
Returns mode options from the `TimeSlotType` enum, labeled by `form.fields.mode.items.<enum-value>`.
parseDate()  : DateTime|null
Converts an `<input type=date>` value to `DateTime`, or null when empty or invalid.
parseTime()  : DateTime|null
Converts an `<input type=time>` value (`H:i`) to `DateTime`, or null when empty or invalid.
saveTimeSlotForm()  : bool
setTimeSlotFormDefaults()  : void
tr()  : NotTranslate
Translates a key in the form domain to a ready string for fields with `setTranslator(null)`.

Methods

addBasicFields()

Adds company, date, mode switch (override / block / close day), time window (conditionally required) and note.

private addBasicFields(Form $form) : void
Parameters
$form : Form

buildTimeSlotEntity()

private buildTimeSlotEntity(ArrayHash<string|int, mixed> $values) : TimeSlot
Parameters
$values : ArrayHash<string|int, mixed>
Return values
TimeSlot

modeOptions()

Returns mode options from the `TimeSlotType` enum, labeled by `form.fields.mode.items.<enum-value>`.

private modeOptions() : array<string, string>
Return values
array<string, string>

parseDate()

Converts an `<input type=date>` value to `DateTime`, or null when empty or invalid.

private parseDate(mixed $value) : DateTime|null
Parameters
$value : mixed
Return values
DateTime|null

parseTime()

Converts an `<input type=time>` value (`H:i`) to `DateTime`, or null when empty or invalid.

private parseTime(mixed $value) : DateTime|null
Parameters
$value : mixed
Return values
DateTime|null

saveTimeSlotForm()

private saveTimeSlotForm(ArrayHash<string|int, mixed> $values) : bool
Parameters
$values : ArrayHash<string|int, mixed>
Return values
bool

tr()

Translates a key in the form domain to a ready string for fields with `setTranslator(null)`.

private tr(string $key) : NotTranslate

IMPORTANT: Nette getLabel() and Validator::formatMessage() always use the form's translator, not the per-control override. Without NotTranslate the finished text would be translated again as a key and Tracy would report a missing translation.

Parameters
$key : string
Return values
NotTranslate
On this page

Search results