PluginProbe
Fluent Booking – The Ultimate Appointments Scheduling, Events Booking, Events Calendar Solution / 2.5.0
Fluent Booking – The Ultimate Appointments Scheduling, Events Booking, Events Calendar Solution v2.5.0
2.5.0 2.4.0 2.3.0 2.2.5 2.2.0 2.1.2 2.1.1 trunk 1.10.0 1.10.01 1.10.02 1.5.0 1.5.01 1.5.02 1.5.1 1.5.10 1.5.20 1.5.21 1.5.22 1.5.23 1.5.24 1.5.25 1.6.0 1.7.0 1.7.1 All 34 releases
← All changes | app/Services/AvailabilityService.php +14 -5 2.2.0 → 2.5.0 View file →
@@ -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 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;
@@ -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 }