| 1 |
<?php |
| 2 |
namespace Booktics\Appointment\Schedule; |
| 3 |
|
| 4 |
/** |
| 5 |
* Strategy that generates time slots based only on the default schedule entry. |
| 6 |
* This class implements the Time_Slot_Strategy interface and provides a basic |
| 7 |
* slot generation algorithm that ignores service and team member schedules. |
| 8 |
*/ |
| 9 |
class Default_Only_Strategy implements Time_Slot_Strategy { |
| 10 |
/** |
| 11 |
* Generates time slots based on the default schedule entry only. |
| 12 |
* |
| 13 |
* @param Schedule_Entry|null $service_entry The service schedule entry (not used) |
| 14 |
* @param Schedule_Entry|null $team_entry The team member schedule entry (not used) |
| 15 |
* @param Schedule_Entry|null $default_entry The default schedule entry |
| 16 |
* @param Time_Slot_Manager $manager The time slot manager instance |
| 17 |
* @param \DateTime $date The date for which to generate slots |
| 18 |
* |
| 19 |
* @return array Array of Time_Slot objects representing available time slots |
| 20 |
*/ |
| 21 |
public function generate_slots( |
| 22 |
?Schedule_Entry $service_entry, |
| 23 |
?Schedule_Entry $team_entry, |
| 24 |
?Schedule_Entry $default_entry, |
| 25 |
Time_Slot_Manager $manager, |
| 26 |
\DateTime $date |
| 27 |
): array { |
| 28 |
if (!$default_entry || $default_entry->is_holiday()) { |
| 29 |
return []; |
| 30 |
} |
| 31 |
$start_time = strtotime($default_entry->get_start_time()); |
| 32 |
$end_time = strtotime($default_entry->get_end_time()); |
| 33 |
$duration = $manager->get_slot_length() * 60; |
| 34 |
$slots = []; |
| 35 |
|
| 36 |
while ($start_time + $duration <= $end_time) { |
| 37 |
$slot_start = gmdate('H:i', $start_time); |
| 38 |
$slot_end = gmdate('H:i', $start_time + $duration); |
| 39 |
|
| 40 |
$slots[] = new Time_Slot($slot_start, $slot_end, true); |
| 41 |
$start_time += $duration; |
| 42 |
} |
| 43 |
|
| 44 |
return $slots; |
| 45 |
} |
| 46 |
} |