PluginProbe ʕ •ᴥ•ʔ
LatePoint – Calendar Booking Plugin for Appointments and Events / 5.4.2
LatePoint – Calendar Booking Plugin for Appointments and Events v5.4.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 3 months ago booked_period.php 3 months ago booking_request.php 3 months ago booking_resource.php 3 months ago booking_slot.php 3 months ago filter.php 3 months ago process_action.php 3 months ago process_event.php 3 months ago role.php 3 months ago router.php 3 months ago step.php 3 months ago stripe_connect_customer.php 3 months ago time_period.php 3 months ago user.php 3 months ago work_period.php 3 months ago
booking_slot.php
77 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 ) ) {
21 $this->$key = $arg;
22 }
23 }
24 }
25
26 /**
27 * @param \LatePoint\Misc\BookingSlot[] $booking_slots
28 * @return int
29 */
30 public static function find_minimum_gap_between_slots( array $booking_slots ): int {
31 $minimum_slot_gap = 0;
32 // calculate minimum gap between slots
33 if ( count( $booking_slots ) > 1 ) {
34 $prev_start_time = $booking_slots[0]->start_time;
35 $intervals = [];
36 foreach ( $booking_slots as $booking_slot ) {
37 if ( $prev_start_time ) {
38 $gap = $booking_slot->start_time - $prev_start_time;
39 if ( $gap ) {
40 $intervals[] = $gap;
41 }
42 }
43 $prev_start_time = $booking_slot->start_time;
44 }
45 if ( $intervals ) {
46 $minimum_slot_gap = min( $intervals );
47 }
48 }
49 return $minimum_slot_gap;
50 }
51
52 public function can_accomodate( $total_attendees ) {
53 if ( $this->booked_capacity >= $this->min_capacity_to_be_blocked ) {
54 return false;
55 } else {
56 return $this->available_capacity() >= $total_attendees;
57 }
58 }
59
60 public function available_capacity() {
61 return $this->max_capacity - $this->booked_capacity;
62 }
63
64 public static function allowed_props(): array {
65 return [
66 'start_time',
67 'start_date',
68 'min_capacity',
69 'max_capacity',
70 'min_capacity_to_be_blocked',
71 'booked_capacity',
72 'available_capacity',
73 'price',
74 ];
75 }
76 }
77