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 +18 -9 1.7.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 - $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 }
@@ -164,9 +173,9 @@
164 173 public static function createScheduleSchema($userId, $title, $default, $fromTimezone, $toTimezone = 'UTC', $weeklySchedule = [], $dateOverrides = [])
165 174 {
166 175 $weeklySchedule = $weeklySchedule ? $weeklySchedule : Helper::getWeeklyScheduleSchema();
167 176
168 - $dateOverrides = $dateOverrides ? SanitizeService::slotDateOverrides($dateOverrides, $fromTimezone, $toTimezone) : [];
177 + $dateOverrides = $dateOverrides ? SanitizeService::slotDateOverrides($dateOverrides, $fromTimezone, $toTimezone, null, true) : [];
169 178
170 179 $defaultSchedule = [
171 180 'object_id' => $userId,
172 181 'key' => sanitize_text_field($title),
@@ -173,9 +182,9 @@
173 182 'value' => [
174 183 'default' => (bool)$default,
175 184 'timezone' => sanitize_text_field($fromTimezone),
176 185 'date_overrides' => $dateOverrides,
177 - 'weekly_schedules' => SanitizeService::weeklySchedules($weeklySchedule, $fromTimezone, $toTimezone),
186 + 'weekly_schedules' => SanitizeService::weeklySchedules($weeklySchedule, $fromTimezone, $toTimezone, true),
178 187 ]
179 188 ];
180 189 return $defaultSchedule;
181 190 }