PluginProbe
Booktics – Appointment Booking Calendar for Service Businesses / 1.0.2
Booktics – Appointment Booking Calendar for Service Businesses v1.0.2
1.0.29 1.0.28 1.0.27 1.0.26 1.0.25 1.0.24 1.0.23 1.0.22 1.0.21 1.0.20 1.0.19 trunk 1.0.0 1.0.1 1.0.10 1.0.11 1.0.12 1.0.13 1.0.14 1.0.15 1.0.16 1.0.17 1.0.18 1.0.2 1.0.3 All 31 releases
booktics / core / appointment / schedule / merged-default-team-strategy.php

merged-default-team-strategy.php in Booktics – Appointment Booking Calendar for Service Businesses 1.0.2, at core/appointment/schedule/merged-default-team-strategy.php

52 lines 1.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 namespace Booktics\Appointment\Schedule;
3
4 class Merged_Default_Team_Strategy implements Time_Slot_Strategy {
5 /**
6 * Generates time slots based on default and team schedule entries
7 *
8 * @param Schedule_Entry|null $service_entry Optional service schedule entry
9 * @param Schedule_Entry|null $team_entry Team member's schedule entry
10 * @param Schedule_Entry|null $default_entry Default schedule entry
11 * @param Time_Slot_Manager $manager Time slot manager instance
12 * @param \DateTime $date Date for which to generate slots
13 *
14 * @return array Array of Time_Slot objects representing available time slots
15 */
16 public function generate_slots(
17 ?Schedule_Entry $service_entry,
18 ?Schedule_Entry $team_entry,
19 ?Schedule_Entry $default_entry,
20 Time_Slot_Manager $manager,
21 \DateTime $date
22 ): array {
23 if (!$default_entry || !$team_entry || $default_entry->is_holiday() || $team_entry->is_holiday()) {
24 return [];
25 }
26 $default_start = strtotime($default_entry->get_start_time());
27 $default_end = strtotime($default_entry->get_end_time());
28 $team_start = strtotime($team_entry->get_start_time());
29 $team_end = strtotime($team_entry->get_end_time());
30
31 $start_time = max($default_start, $team_start);
32 $end_time = min($default_end, $team_end);
33
34 if ($start_time >= $end_time) {
35 return [];
36 }
37
38 $slots = [];
39 $current = $start_time;
40 $duration = $manager->get_slot_length() * 60;
41
42 while ($current + $duration <= $end_time) {
43 $slot_start = gmdate('H:i', $current);
44 $slot_end = gmdate('H:i', $current + $duration);
45
46 $slots[] = new Time_Slot($slot_start, $slot_end, true);
47 $current += $duration;
48 }
49
50 return $slots;
51 }
52 }