| @@ -26,18 +26,27 @@ | ||
| 26 | 26 | |
| 27 | 27 | return Availability::create($defaultSchedule); |
| 28 | 28 | } |
| 29 | 29 | |
| 30 | - public static function availabilitySchedules() | |
| 30 | + /** | |
| 31 | + * Schedules the current user may read and attach, as a query so callers that only | |
| 32 | + * need ids can avoid formatting every schedule. | |
| 33 | + */ | |
| 34 | + public static function usableAvailabilityQuery() | |
| 31 | 35 | { |
| 32 | - $permissions = ['read_and_use_other_availabilities', 'manage_other_availabilities', 'read_other_calendars', 'manage_other_calendars']; | |
| 36 | + $permissions = ['manage_all_data', 'read_and_use_other_availabilities', 'manage_other_availabilities', 'read_other_calendars', 'manage_other_calendars']; | |
| 33 | 37 | |
| 34 | - $availabilities = Availability::when( | |
| 38 | + return Availability::when( | |
| 35 | 39 | !PermissionManager::userCan($permissions), |
| 36 | 40 | function ($query) { |
| 37 | 41 | return $query->where('object_id', get_current_user_id()); |
| 38 | - })->get()->toArray(); | |
| 42 | + }); | |
| 43 | + } | |
| 39 | 44 | |
| 45 | + public static function availabilitySchedules() | |
| 46 | + { | |
| 47 | + $availabilities = self::usableAvailabilityQuery()->get()->toArray(); | |
| 48 | + | |
| 40 | 49 | $formattedSchedules = []; |
| 41 | 50 | foreach ($availabilities as $availability) { |
| 42 | 51 | $toTimezone = Arr::get($availability, 'value.timezone', 'UTC'); |
| 43 | 52 | $formattedSchedules[] = [ |
| @@ -104,9 +113,9 @@ | ||
| 104 | 113 | $schedule = Availability::findOrFail($schedule->id); |
| 105 | 114 | $updatedSettings = [ |
| 106 | 115 | 'default' => false, |
| 107 | 116 | 'timezone' => Arr::get($schedule, 'value.timezone', 'UTC'), |
| 108 | - 'date_overrides' => Arr::get($schedule, 'value.data_overrides', []), | |
| 117 | + 'date_overrides' => Arr::get($schedule, 'value.date_overrides', []), | |
| 109 | 118 | 'weekly_schedules' => Arr::get($schedule, 'value.weekly_schedules'), |
| 110 | 119 | ]; |
| 111 | 120 | |
| 112 | 121 | $schedule->value = $updatedSettings; |
| @@ -115,9 +124,9 @@ | ||
| 115 | 124 | } |
| 116 | 125 | |
| 117 | 126 | public static function getScheduleOptions() |
| 118 | 127 | { |
| 119 | - $permissions = ['read_and_use_other_availabilities', 'manage_other_availabilities', 'read_other_calendars', 'manage_other_calendars']; | |
| 128 | + $permissions = ['manage_all_data', 'read_and_use_other_availabilities', 'manage_other_availabilities', 'read_other_calendars', 'manage_other_calendars']; | |
| 120 | 129 | |
| 121 | 130 | $availabilities = Availability::when( |
| 122 | 131 | !PermissionManager::userCan($permissions), |
| 123 | 132 | function ($query) { |
| @@ -130,9 +139,9 @@ | ||
| 130 | 139 | ->where('type', 'simple') |
| 131 | 140 | ->where('user_id', $availability->object_id) |
| 132 | 141 | ->first(); |
| 133 | 142 | |
| 134 | - if ($calendar) { | |
| 143 | + if ($calendar && $calendar->user) { | |
| 135 | 144 | $hostName = $calendar->user->full_name; |
| 136 | 145 | if ($calendar->user_id == get_current_user_id()) { |
| 137 | 146 | $hostName = __('My Schedules', 'fluent-booking'); |
| 138 | 147 | } |