ScheduleService
in package
Builds working hours for separate dates or date periods.
Tags
Table of Contents
- $locationId : int|array<string|int, int>
- One or more allowed location ID.
- $schedule : Schedule
- $workingHours : array<string|int, mixed>
- Timetable with filtered locations (only allowed locations) and activity (only working hours).
- $reservations : array<string|int, mixed>
- __construct() : mixed
- addReservation() : mixed
- buildWorkingHoursBySchedule() : array<string|int, mixed>
- filterActivity() : array<string|int, mixed>
- filterLocations() : array<string|int, mixed>
- getWorkingHoursForDate() : TimePeriods
- getWorkingHoursForPeriod() : array<string|int, mixed>
- pullPeriods() : array<string|int, mixed>
- splitScheduleByLocation() : array<string|int, static>
Properties
$locationId
One or more allowed location ID.
public
int|array<string|int, int>
$locationId
= 0
Tags
$schedule
public
Schedule
$schedule
= null
Tags
$workingHours
Timetable with filtered locations (only allowed locations) and activity (only working hours).
public
array<string|int, mixed>
$workingHours
= []
Tags
$reservations
protected
array<string|int, mixed>
$reservations
= []
Tags
Methods
__construct()
public
__construct(Schedule $schedule, int|array<string|int, int> $locationId) : mixed
Parameters
- $schedule : Schedule
- $locationId : int|array<string|int, int>
-
Optional. One or more allowed location ID. 0 by default (all allowed).
Tags
Return values
mixed —addReservation()
public
addReservation(DateTime|string $date, TimePeriod|string $time) : mixed
Parameters
- $date : DateTime|string
- $time : TimePeriod|string
-
The buffer time is preferred.
Tags
Return values
mixed —buildWorkingHoursBySchedule()
public
static buildWorkingHoursBySchedule(Schedule $schedule, int|array<string|int, int> $locationId) : array<string|int, mixed>
Parameters
- $schedule : Schedule
- $locationId : int|array<string|int, int>
-
Optional. One or more allowed location ID. 0 by default (all allowed).
Tags
Return values
array<string|int, mixed> —[Day (0-6) => TimePeriods] - only working hours.
filterActivity()
public
static filterActivity(array<string|int, mixed> $timetable[, string $activity = ACTIVITY_WORK ]) : array<string|int, mixed>
Parameters
- $timetable : array<string|int, mixed>
-
[Day => Array of [..., string 'activity']]
- $activity : string = ACTIVITY_WORK
-
Optional. Allowed activity. Working hours by default.
Tags
Return values
array<string|int, mixed> —Timetable that only consists of periods of that activity.
filterLocations()
public
static filterLocations(array<string|int, mixed> $timetable, int|array<string|int, int> $locations) : array<string|int, mixed>
Parameters
- $timetable : array<string|int, mixed>
-
[Day => Array of [..., int 'location']]
- $locations : int|array<string|int, int>
-
One or more allowed location ID.
Tags
Return values
array<string|int, mixed> —Timetable that only consists of periods for locations from
$locations
.
getWorkingHoursForDate()
public
getWorkingHoursForDate(DateTime $date) : TimePeriods
Parameters
- $date : DateTime
Tags
Return values
TimePeriods —getWorkingHoursForPeriod()
public
getWorkingHoursForPeriod(DateTime $fromDate, DateTime $toDate[, bool $skipEmpty = true ]) : array<string|int, mixed>
Parameters
- $fromDate : DateTime
- $toDate : DateTime
- $skipEmpty : bool = true
-
Optional. Skip empty days (days without periods). True by default.
Tags
Return values
array<string|int, mixed> —['Y-m-d' => TimePeriods]
pullPeriods()
public
static pullPeriods(array<string|int, mixed> $timetable[, bool $mergePeriods = false ]) : array<string|int, mixed>
Parameters
- $timetable : array<string|int, mixed>
-
[Day => Array of [TimePeriod 'time_period', ...]]
- $mergePeriods : bool = false
-
Optional. Merge TimePeriod[] into single object: TimePeriods. False by default.
Tags
Return values
array<string|int, mixed> —[Day => TimePeriod[]] or [Day => TimePeriods] if
$mergePeriods
is true.
splitScheduleByLocation()
public
static splitScheduleByLocation(Schedule $schedule, int|array<string|int, int> $locationId) : array<string|int, static>
Parameters
- $schedule : Schedule
- $locationId : int|array<string|int, int>
-
Optional. One or more allowed location ID. 0 by default (all allowed).
Tags
Return values
array<string|int, static> —[Location ID => Instance object] - separate instance of ScheduleService for each allowed location.