2025-09-28 13:31:43 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace App\Domain\Trip\Observers;
|
|
|
|
|
|
|
|
|
|
use App\Models\Trip;
|
|
|
|
|
use App\Domain\Trip\Services\CalendarSlotService;
|
|
|
|
|
|
|
|
|
|
class TripObserver
|
|
|
|
|
{
|
|
|
|
|
protected CalendarSlotService $calendarSlotService;
|
|
|
|
|
|
|
|
|
|
public function __construct(CalendarSlotService $calendarSlotService)
|
|
|
|
|
{
|
|
|
|
|
$this->calendarSlotService = $calendarSlotService;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function created(Trip $trip): void
|
|
|
|
|
{
|
2025-09-30 08:29:17 +02:00
|
|
|
if ($trip->start_date && $trip->end_date) {
|
|
|
|
|
$this->calendarSlotService->createOrUpdateSlotsForTrip($trip);
|
|
|
|
|
}
|
2025-09-28 13:31:43 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function updated(Trip $trip): void
|
|
|
|
|
{
|
|
|
|
|
if ($trip->isDirty(['start_date', 'end_date'])) {
|
|
|
|
|
$this->calendarSlotService->createOrUpdateSlotsForTrip($trip);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function deleted(Trip $trip): void
|
|
|
|
|
{
|
|
|
|
|
$this->calendarSlotService->deleteSlotsForTrip($trip);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function restored(Trip $trip): void
|
|
|
|
|
{
|
|
|
|
|
$this->calendarSlotService->createOrUpdateSlotsForTrip($trip);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function forceDeleted(Trip $trip): void
|
|
|
|
|
{
|
|
|
|
|
$this->calendarSlotService->deleteSlotsForTrip($trip);
|
|
|
|
|
}
|
|
|
|
|
}
|