feat: enhance DateOverride functionality with SessionConfig support and update SlotCalculatorService for backward compatibility
This commit is contained in:
@@ -127,27 +127,35 @@ class SlotCalculatorService
|
||||
}
|
||||
|
||||
/**
|
||||
* Build slots from flat date-override format: [{start, end, duration}]
|
||||
* Kept for backward-compatibility with DateOverride.custom_slots.
|
||||
* Build slots from date-override custom_slots.
|
||||
* Supports new SessionConfig format {start_time, end_time, duration_per_patient, ...}
|
||||
* and legacy flat format {start, end, duration} for backward compatibility.
|
||||
*/
|
||||
private function buildFlatSlots(array $slotConfigs, int $dayStart): array
|
||||
{
|
||||
$slots = [];
|
||||
foreach ($slotConfigs as $config) {
|
||||
$startSec = $this->parseTime($config['start'] ?? '00:00');
|
||||
$endSec = $this->parseTime($config['end'] ?? '00:00');
|
||||
$duration = (int)($config['duration'] ?? 30) * 60;
|
||||
|
||||
if ($duration <= 0 || $endSec <= $startSec) continue;
|
||||
|
||||
for ($t = $startSec; $t + $duration <= $endSec; $t += $duration) {
|
||||
$slots[] = [
|
||||
'start' => $dayStart + $t,
|
||||
'end' => $dayStart + $t + $duration,
|
||||
'start_time' => gmdate('H:i', $t),
|
||||
'end_time' => gmdate('H:i', $t + $duration),
|
||||
'location_id' => null,
|
||||
];
|
||||
if (isset($config['start_time'])) {
|
||||
// New SessionConfig format — reuse the same logic as weekly sessions
|
||||
$slots = array_merge($slots, $this->buildSessionSlots(
|
||||
array_merge(['active' => true], $config),
|
||||
$dayStart
|
||||
));
|
||||
} else {
|
||||
// Legacy flat format: {start, end, duration}
|
||||
$startSec = $this->parseTime($config['start'] ?? '00:00');
|
||||
$endSec = $this->parseTime($config['end'] ?? '00:00');
|
||||
$duration = (int)($config['duration'] ?? 30) * 60;
|
||||
if ($duration <= 0 || $endSec <= $startSec) continue;
|
||||
for ($t = $startSec; $t + $duration <= $endSec; $t += $duration) {
|
||||
$slots[] = [
|
||||
'start' => $dayStart + $t,
|
||||
'end' => $dayStart + $t + $duration,
|
||||
'start_time' => gmdate('H:i', $t),
|
||||
'end_time' => gmdate('H:i', $t + $duration),
|
||||
'location_id' => null,
|
||||
];
|
||||
}
|
||||
}
|
||||
}
|
||||
return $slots;
|
||||
|
||||
Reference in New Issue
Block a user