| 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 |
array $service_entries, |
| 23 |
array $team_entries, |
| 24 |
array $default_entries, |
| 25 |
Time_Slot_Manager $manager, |
| 26 |
\DateTime $date |
| 27 |
): array { |
| 28 |
$slots = array(); |
| 29 |
if ( ! empty( $default_entries ) ) { |
| 30 |
foreach ( $default_entries as $default_entry ) { |
| 31 |
if ( ! $default_entry || $default_entry->is_holiday() ) { |
| 32 |
continue; |
| 33 |
} |
| 34 |
$start_time = strtotime( $default_entry->get_start_time() ); |
| 35 |
$end_time = strtotime( $default_entry->get_end_time() ); |
| 36 |
$slot_length = $manager->get_slot_length() * 60; |
| 37 |
$service_duration = $manager->get_service_duration() * 60; |
| 38 |
$before_buffer = $manager->get_before_buffer_time() * 60; |
| 39 |
$after_buffer = $manager->get_after_buffer_time() * 60; |
| 40 |
$gap = $before_buffer + $after_buffer; |
| 41 |
$current_start = $start_time; |
| 42 |
while ( $current_start + $service_duration <= $end_time ) { |
| 43 |
$slot_start = gmdate( 'H:i', $current_start ); |
| 44 |
$slot_end = gmdate( 'H:i', $current_start + $service_duration ); |
| 45 |
$max_capacity = $manager->get_service_max_capacity_for_timeslot(); // Get max capacity from group booking |
| 46 |
|
| 47 |
$slots[] = new Time_Slot( $slot_start, $slot_end, true, $max_capacity ); |
| 48 |
|
| 49 |
$current_start += $slot_length + $gap; |
| 50 |
} |
| 51 |
} |
| 52 |
} |
| 53 |
return $slots; |
| 54 |
} |
| 55 |
} |
| 56 |
|