55 lines
1.6 KiB
PHP
55 lines
1.6 KiB
PHP
|
|
<?php
|
||
|
|
|
||
|
|
namespace App\Domain\PlannedItem\Policies;
|
||
|
|
|
||
|
|
use App\Models\User;
|
||
|
|
use App\Models\PlannedItem;
|
||
|
|
use App\Models\Trip;
|
||
|
|
|
||
|
|
class PlannedItemPolicy
|
||
|
|
{
|
||
|
|
/**
|
||
|
|
* Determine if the user can create a planned item for the given trip
|
||
|
|
*/
|
||
|
|
public function create(User $user, int $tripId): bool
|
||
|
|
{
|
||
|
|
return \DB::table('trips')
|
||
|
|
->where('id', $tripId)
|
||
|
|
->where('created_by_user_id', $user->id)
|
||
|
|
->exists();
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* Determine if the user can update the planned item
|
||
|
|
*/
|
||
|
|
public function update(User $user, PlannedItem $plannedItem): bool
|
||
|
|
{
|
||
|
|
return \DB::table('planned_items')
|
||
|
|
->join('calendar_slots', 'planned_items.calendar_slot_id', '=', 'calendar_slots.id')
|
||
|
|
->join('trips', 'calendar_slots.trip_id', '=', 'trips.id')
|
||
|
|
->where('planned_items.id', $plannedItem->id)
|
||
|
|
->where('trips.created_by_user_id', $user->id)
|
||
|
|
->exists();
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* Determine if the user can delete the planned item
|
||
|
|
*/
|
||
|
|
public function delete(User $user, PlannedItem $plannedItem): bool
|
||
|
|
{
|
||
|
|
return $this->update($user, $plannedItem);
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* Determine if the user can move a planned item to a new calendar slot
|
||
|
|
*/
|
||
|
|
public function moveToSlot(User $user, int $calendarSlotId): bool
|
||
|
|
{
|
||
|
|
return \DB::table('calendar_slots')
|
||
|
|
->join('trips', 'calendar_slots.trip_id', '=', 'trips.id')
|
||
|
|
->where('calendar_slots.id', $calendarSlotId)
|
||
|
|
->where('trips.created_by_user_id', $user->id)
|
||
|
|
->exists();
|
||
|
|
}
|
||
|
|
}
|