PluginProbe ʕ •ᴥ•ʔ
LatePoint – Calendar Booking Plugin for Appointments and Events / trunk
LatePoint – Calendar Booking Plugin for Appointments and Events vtrunk
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_request.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 1 month ago process_event.php 1 month ago role.php 2 weeks 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_request.php
111 lines
1 <?php
2 /*
3 * Copyright (c) 2022 LatePoint LLC. All rights reserved.
4 *
5 * This class is used to create booking requests, they are useful for getting availability information on the calendar
6 * and checking if a timeslot is available.
7 */
8
9 namespace LatePoint\Misc;
10
11 class BookingRequest {
12 public ?string $start_date;
13 public ?string $end_date;
14 public ?int $start_time = 0;
15 public ?int $end_time = 0;
16 public ?int $duration = 0;
17 public ?int $buffer_before = 0;
18 public ?int $buffer_after = 0;
19 public ?int $total_attendees = 1;
20 public $service_id = 0;
21 public $agent_id = 0;
22 public $location_id = 0;
23
24 function __construct( $args = [] ) {
25 $allowed_props = self::allowed_props();
26 foreach ( $args as $key => $arg ) {
27 if ( in_array( $key, $allowed_props ) ) {
28 $this->$key = $arg;
29 }
30 }
31 }
32
33
34 public static function create_from_booking_model( \OsBookingModel $booking ): BookingRequest {
35 $booking_request = new BookingRequest(
36 [
37 'start_date' => $booking->start_date,
38 'end_date' => $booking->end_date ? $booking->end_date : $booking->start_date,
39 'start_time' => (int) $booking->start_time,
40 'end_time' => (int) $booking->end_time,
41 'duration' => (int) $booking->get_total_duration(),
42 'buffer_before' => (int) $booking->buffer_before,
43 'buffer_after' => (int) $booking->buffer_after,
44 'total_attendees' => (int) $booking->total_attendees,
45 'agent_id' => ( $booking->agent_id == LATEPOINT_ANY_AGENT ) ? 0 : $booking->agent_id,
46 'service_id' => $booking->service_id,
47 'location_id' => ( $booking->location_id == LATEPOINT_ANY_LOCATION ) ? 0 : $booking->location_id,
48 ]
49 );
50 return apply_filters( 'latepoint_create_booking_request_from_booking_model', $booking_request, $booking );
51 }
52
53 public function get_start_time_with_buffer(): int {
54 return $this->start_time - $this->buffer_before;
55 }
56
57 public function get_end_time_with_buffer(): int {
58 return $this->end_time + $this->buffer_after;
59 }
60
61
62 public function get_start_datetime( string $set_timezone = '' ): \OsWpDateTime {
63 try {
64 // start_time and start_date is legacy stored in wordpress timezone
65 $dateTime = new \OsWpDateTime( $this->start_date . ' 00:00:00', \OsTimeHelper::get_wp_timezone() );
66 if ( $this->start_time > 0 ) {
67 $dateTime->modify( '+' . $this->start_time . ' minutes' );
68 }
69 if ( ! empty( $set_timezone ) ) {
70 $dateTime->setTimezone( new \DateTimeZone( $set_timezone ) );
71 }
72 return $dateTime;
73 } catch ( \Exception $e ) {
74 return new \OsWpDateTime( 'now' );
75 }
76 }
77
78 public function get_end_datetime( string $set_timezone = '' ): \OsWpDateTime {
79 try {
80 // start_time and start_date is legacy stored in wordpress timezone
81 $dateTime = new \OsWpDateTime( $this->end_date . ' 00:00:00', \OsTimeHelper::get_wp_timezone() );
82 if ( $this->end_time > 0 ) {
83 $dateTime->modify( '+' . $this->end_time . ' minutes' );
84 }
85 if ( ! empty( $set_timezone ) ) {
86 $dateTime->setTimezone( new \DateTimeZone( $set_timezone ) );
87 }
88 return $dateTime;
89 } catch ( \Exception $e ) {
90 return new \OsWpDateTime( 'now' );
91 }
92 }
93
94
95 public static function allowed_props(): array {
96 return [
97 'start_date',
98 'end_date',
99 'start_time',
100 'end_time',
101 'duration',
102 'buffer_before',
103 'buffer_after',
104 'total_attendees',
105 'agent_id',
106 'service_id',
107 'location_id',
108 ];
109 }
110 }
111