PluginProbe ʕ •ᴥ•ʔ
LatePoint – Calendar Booking Plugin for Appointments and Events / 5.1.2
LatePoint – Calendar Booking Plugin for Appointments and Events v5.1.2
5.6.7 5.6.6 5.6.5 5.6.4 5.6.3 5.6.2 5.6.1 5.6.0 5.5.2 5.5.1 5.5.0 5.4.2 trunk 5.1.0 5.1.1 5.1.2 5.1.3 5.1.4 5.1.5 5.1.6 5.1.7 5.1.8 5.1.9 5.1.91 5.1.92 5.1.93 5.1.94 5.2.0 5.2.1 5.2.10 5.2.11 5.2.2 5.2.3 5.2.4 5.2.5 5.2.6 5.2.7 5.2.8 5.2.9 5.3.0 5.3.1 5.3.2 5.4.0 5.4.1
latepoint / lib / misc / booking_slot.php
latepoint / lib / misc Last commit date
blocked_period.php 1 year ago booked_period.php 1 year ago booking_request.php 1 year ago booking_resource.php 1 year ago booking_slot.php 1 year ago filter.php 1 year ago process_action.php 1 year ago process_event.php 1 year ago role.php 1 year ago router.php 1 year ago step.php 1 year ago stripe_connect_customer.php 1 year ago time_period.php 1 year ago user.php 1 year ago work_period.php 1 year ago
booking_slot.php
68 lines
1 <?php
2 /*
3 * Copyright (c) 2022 LatePoint LLC. All rights reserved.
4 */
5
6 namespace LatePoint\Misc;
7
8 class BookingSlot{
9 public string $start_date;
10 public int $start_time;
11 public int $min_capacity = 1;
12 public int $max_capacity = 1;
13 public int $min_capacity_to_be_blocked = 1;
14 public int $booked_capacity = 0;
15 public int $price;
16
17 function __construct($args = []){
18 $allowed_props = self::allowed_props();
19 foreach($args as $key => $arg){
20 if(in_array($key, $allowed_props)) $this->$key = $arg;
21 }
22 }
23
24 /**
25 * @param \LatePoint\Misc\BookingSlot[] $booking_slots
26 * @return int
27 */
28 public static function find_minimum_gap_between_slots(array $booking_slots): int{
29 $minimum_slot_gap = 0;
30 // calculate minimum gap between slots
31 if(count($booking_slots) > 1){
32 $prev_start_time = $booking_slots[0]->start_time;
33 $intervals = [];
34 foreach($booking_slots as $booking_slot){
35 if($prev_start_time){
36 $gap = $booking_slot->start_time - $prev_start_time;
37 if($gap) $intervals[] = $gap;
38 }
39 $prev_start_time = $booking_slot->start_time;
40 }
41 if($intervals) $minimum_slot_gap = min($intervals);
42 }
43 return $minimum_slot_gap;
44 }
45
46 public function can_accomodate($total_attendees){
47 if($this->booked_capacity >= $this->min_capacity_to_be_blocked){
48 return false;
49 }else{
50 return $this->available_capacity() >= $total_attendees;
51 }
52 }
53
54 public function available_capacity(){
55 return $this->max_capacity - $this->booked_capacity;
56 }
57
58 public static function allowed_props(): array{
59 return ['start_time',
60 'start_date',
61 'min_capacity',
62 'max_capacity',
63 'min_capacity_to_be_blocked',
64 'booked_capacity',
65 'available_capacity',
66 'price'];
67 }
68 }