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/Models/CalendarSlot.php +85 -17 1.10.0 → 2.5.0 View file →
@@ -2,8 +2,9 @@
2 2
3 3 namespace FluentBooking\App\Models;
4 4
5 5 use FluentBooking\App\Models\Model;
6 +use FluentBooking\Framework\Support\Arr;
6 7 use FluentBooking\App\Services\SanitizeService;
7 8 use FluentBooking\App\Services\AvailabilityService;
8 9 use FluentBooking\App\Services\BookingFieldService;
9 10 use FluentBooking\App\Services\DateTimeHelper;
@@ -9,9 +10,9 @@
9 10 use FluentBooking\App\Services\DateTimeHelper;
10 11 use FluentBooking\App\Services\Helper;
11 12 use FluentBooking\App\Services\CurrenciesHelper;
12 13 use FluentBooking\App\Services\LocationService;
13 -use FluentBooking\Framework\Support\Arr;
14 +use FluentBooking\App\Services\Integrations\FluentCart\CartHelper;
14 15
15 16 class CalendarSlot extends Model
16 17 {
17 18 protected $table = 'fcal_calendar_events';
@@ -117,8 +118,13 @@
117 118 return $this->hasMany(Meta::class, 'object_id', 'id')
118 119 ->whereIn('object_type', ['calendar_event', 'integration']);
119 120 }
120 121
122 + public function isOneToOne()
123 + {
124 + return $this->event_type == 'single';
125 + }
126 +
121 127 public function isGroup()
122 128 {
123 129 return $this->event_type == 'group';
124 130 }
@@ -132,8 +138,18 @@
132 138 {
133 139 return $this->event_type == 'group_event';
134 140 }
135 141
142 + /**
143 + * Every value event_type can hold, on both fcal_calendar_slots and fcal_bookings.
144 + *
145 + * @return array
146 + */
147 + public static function getEventTypes()
148 + {
149 + return ['single', 'group', 'round_robin', 'collective', 'single_event', 'group_event'];
150 + }
151 +
136 152 public function isRoundRobin()
137 153 {
138 154 return $this->event_type == 'round_robin';
139 155 }
@@ -167,16 +183,26 @@
167 183 {
168 184 return $this->isGroup() || $this->isGroupEvent();
169 185 }
170 186
187 + public function isRecurringEvent()
188 + {
189 + return Arr::isTrue($this->getRecurringConfig(), 'enabled');
190 + }
191 +
171 192 public function isProEvent()
172 193 {
173 194 return $this->isGroup() || $this->isTeamEvent() || $this->isOneOffEvent() || $this->allowMultiBooking();
174 195 }
175 196
197 + public function isMultiBooking()
198 + {
199 + return Arr::isTrue($this->settings, 'multiple_booking.enabled');
200 + }
201 +
176 202 public function allowMultiBooking()
177 203 {
178 - return Arr::isTrue($this->settings, 'multiple_booking.enabled');
204 + return $this->isMultiBooking() || $this->isRecurringEvent();
179 205 }
180 206
181 207 public function multiBookingLimit()
182 208 {
@@ -215,11 +241,19 @@
215 241 {
216 242 $teamMembers = [];
217 243 $teamMemberIds = $this->getHostIds();
218 244
245 + cache_users($teamMemberIds);
246 +
247 + $calendars = Calendar::whereIn('user_id', $teamMemberIds)
248 + ->where('type', 'simple')
249 + ->orderBy('id', 'desc')
250 + ->with(['metas', 'user', 'user.metas'])
251 + ->get()
252 + ->keyBy('user_id');
253 +
219 254 foreach ($teamMemberIds as $teamMemberId) {
220 - $calendar = Calendar::where('user_id', $teamMemberId)->where('type', 'simple')->first();
221 - if ($calendar) {
255 + if ($calendar = $calendars->get($teamMemberId)) {
222 256 $teamMembers[] = $calendar->getAuthorProfile($public);
223 257 }
224 258 }
225 259
@@ -225,8 +259,13 @@
225 259
226 260 return $teamMembers;
227 261 }
228 262
263 + public function getRecurringConfig()
264 + {
265 + return Arr::get($this->settings, 'recurring_config', []);
266 + }
267 +
229 268 public function isLocationFieldRequired()
230 269 {
231 270 $locationSettings = Arr::get($this, 'location_settings');
232 271
@@ -417,10 +456,12 @@
417 456 return Arr::get($schedule, 'value.timezone', 'UTC');
418 457 }
419 458
420 459 if ($this->availability_type == 'existing_schedule') {
421 - $schedule = Availability::findOrFail($this->availability_id);
422 - return Arr::get($schedule, 'value.timezone', 'UTC');
460 + $schedule = Availability::find($this->availability_id);
461 + if ($schedule) {
462 + return Arr::get($schedule, 'value.timezone', 'UTC');
463 + }
423 464 }
424 465
425 466 return $this->calendar->author_timezone;
426 467 }
@@ -614,9 +655,11 @@
614 655 if (!$conditions || empty($conditions['unit'])) {
615 656 return 0;
616 657 }
617 658
618 - return strtotime('+' . $conditions['value'] . ' ' . $conditions['unit'], 0) - strtotime('+0 seconds', 0);
659 + $value = max(0, (int) Arr::get($conditions, 'value', 0));
660 +
661 + return strtotime('+' . $value . ' ' . $conditions['unit'], 0) - strtotime('+0 seconds', 0);
619 662 }
620 663
621 664 public function getHostIds($hostId = null)
622 665 {
@@ -792,8 +835,10 @@
792 835
793 836 $conditionTime = $conditionValue * 60;
794 837 if ($conditionUnit == 'hours') {
795 838 $conditionTime = $conditionTime * 60;
839 + } elseif ($conditionUnit == 'days') {
840 + $conditionTime = $conditionTime * 60 * 24;
796 841 }
797 842
798 843 return $bookingStartTime - $bookingCreatedTime < $conditionTime;
799 844 }
@@ -882,9 +927,9 @@
882 927
883 928 $isMultiEnabled = Arr::get($paymentSettings, 'multi_payment_enabled') == 'yes';
884 929
885 930 if ($this->isMultiDurationEnabled() && $isMultiEnabled) {
886 - $duration = $duration ?? $this->getDefaultDuration();
931 + $duration = $duration ?: $this->getDefaultDuration();
887 932 return [Arr::get($paymentSettings, 'multi_payment_items.' . $duration)];
888 933 }
889 934
890 935 return Arr::get($paymentSettings, 'items', []);
@@ -889,16 +934,35 @@
889 934
890 935 return Arr::get($paymentSettings, 'items', []);
891 936 }
892 937
893 - public function getPricingTotal()
938 + public function getEventPrice($duration = null)
894 939 {
940 + if (!$this->isPaidEvent()) {
941 + return 0;
942 + }
943 +
944 + $paymentSettings = $this->getPaymentSettings();
945 +
946 + if ($this->isCartEnabled()) {
947 + return CartHelper::getCartProductPrice($paymentSettings, $duration, false);
948 + }
949 +
950 + if ($this->isWooEnabled()) {
951 + return $this->getWooProductPrice($duration);
952 + }
953 +
954 + return $this->getPricingTotal($duration);
955 + }
956 +
957 + public function getPricingTotal($duration = null)
958 + {
895 959 if (!$this->isPaymentEnabled()) {
896 960 return 0;
897 961 }
898 962
899 963 $total = 0;
900 - $items = $this->getPaymentItems();
964 + $items = $this->getPaymentItems($duration);
901 965 foreach ($items as $item) {
902 966 $total += $item['value'];
903 967 }
904 968
@@ -904,9 +968,9 @@
904 968
905 969 return $total;
906 970 }
907 971
908 - public function getWooProductPrice()
972 + public function getWooProductPrice($duration = null)
909 973 {
910 974 $paymentSettings = $this->getPaymentSettings();
911 975
912 976 $productId = $paymentSettings['woo_product_id'];
@@ -911,9 +975,9 @@
911 975
912 976 $productId = $paymentSettings['woo_product_id'];
913 977
914 978 if (Arr::get($paymentSettings, 'multi_payment_enabled') == 'yes') {
915 - $duration = $this->getDefaultDuration();
979 + $duration = $duration ?? $this->getDefaultDuration();
916 980 $productId = Arr::get($paymentSettings, 'multi_payment_woo_ids.' . $duration);
917 981 }
918 982
919 983 $price = 0;
@@ -1021,10 +1085,12 @@
1021 1085 return $this->getProcessedWeeklySlots($schedule);
1022 1086 }
1023 1087
1024 1088 if ($this->availability_type === 'existing_schedule') {
1025 - $schedule = Availability::findOrFail($this->availability_id);
1026 - return $this->getProcessedWeeklySlots($schedule);
1089 + $schedule = Availability::find($this->availability_id);
1090 + if ($schedule) {
1091 + return $this->getProcessedWeeklySlots($schedule);
1092 + }
1027 1093 }
1028 1094
1029 1095 $scheduleData = Arr::get($this->settings, 'weekly_schedules', []);
1030 1096 $schedule = SanitizeService::weeklySchedules($scheduleData, 'UTC', $this->calendar->author_timezone);
@@ -1038,10 +1104,12 @@
1038 1104 return $this->getProcessedDateOverrides($schedule);
1039 1105 }
1040 1106
1041 1107 if ($this->availability_type === 'existing_schedule') {
1042 - $schedule = Availability::findOrFail($this->availability_id);
1043 - return $this->getProcessedDateOverrides($schedule);
1108 + $schedule = Availability::find($this->availability_id);
1109 + if ($schedule) {
1110 + return $this->getProcessedDateOverrides($schedule);
1111 + }
1044 1112 }
1045 1113
1046 1114 $scheduleData = Arr::get($this->settings, 'date_overrides', []);
1047 1115 $schedule = SanitizeService::slotDateOverrides($scheduleData, 'UTC', $this->calendar->author_timezone);
@@ -1116,9 +1184,9 @@
1116 1184
1117 1185 return apply_filters('fluent_booking/get_event_payment_settings', $settings, $this);
1118 1186 }
1119 1187
1120 - public function getHostSchedule($hostId)
1188 + public function getHostSchedule($hostId)
1121 1189 {
1122 1190 $hostSchedules = Arr::get($this->settings, 'hosts_schedules', []);
1123 1191 if (isset($hostSchedules[$hostId])) {
1124 1192 return Availability::find($hostSchedules[$hostId]);