43 lines
1 KiB
PHP
43 lines
1 KiB
PHP
|
|
<?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
|
||
|
|
{
|
||
|
|
$this->calendarSlotService->createOrUpdateSlotsForTrip($trip);
|
||
|
|
}
|
||
|
|
|
||
|
|
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);
|
||
|
|
}
|
||
|
|
}
|