trip-planner/backend/app/Domain/PlannedItem/Policies/PlannedItemPolicy.php
myrmidex 935162ea70 Implement timeline scheduling feature with hour-based calendar slots
- Add CalendarSlotService methods for slot order calculation
  - Update PlannedItemController to create slots from datetime
  - Update CalendarSlotController with proper eager loading
  - Create timeline UI components (TripTimeline, DaySection, HourRow, ScheduleItemModal)
  - Add comprehensive PHPUnit tests (PlannedItemTest, CalendarSlotServiceTest)
  - Add comprehensive Selenium E2E tests (timeline-scheduling.test.js)
  - Update PlannablesList to support onItemsChange callback
2025-10-07 22:54:09 +02:00

54 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();
}
}