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.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 / filter.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
filter.php
114 lines
1 <?php
2 /*
3 * Copyright (c) 2021 LatePoint LLC. All rights reserved.
4 */
5
6 namespace LatePoint\Misc;
7
8 class Filter {
9 public $service_id = 0;
10 public $agent_id = 0;
11 public $location_id = 0;
12
13 public $connections = [];
14
15 public ?int $week_day = null;
16 public ?string $date_from = null;
17 public ?string $date_to = null;
18
19 public ?int $start_time = null;
20 public ?int $end_time = null;
21
22 public array $statuses = [];
23 public array $exclude_booking_ids = [];
24 public bool $consider_cart_items = false;
25 public bool $exact_match = false;
26
27 function __construct( array $args = [] ) {
28 $allowed_args = [
29 'service_id',
30 'agent_id',
31 'location_id',
32 'connections',
33 'date_from',
34 'date_to',
35 'start_time',
36 'end_time',
37 'week_day',
38 'statuses',
39 'exclude_booking_ids',
40 'exact_match',
41 ];
42 foreach ( $args as $key => $arg ) {
43 if ( in_array( $key, $allowed_args ) ) {
44 $this->$key = $arg;
45 }
46 }
47 }
48
49 public function build_query_args_for_blocked_periods(): array {
50
51 $query_args = [];
52
53 // if connections are passed - query by connection
54 if ( $this->connections ) {
55 $connection_conditions = [];
56 foreach ( $this->connections as $connection ) {
57 $connection_conditions[] = [
58 'AND' => [
59 'agent_id' => [ 0, $connection->agent_id ],
60 'service_id' => [ 0, $connection->service_id ],
61 'location_id' => [ 0, $connection->location_id ],
62 ],
63 ];
64 }
65 $query_args['AND'][] = [ 'OR' => $connection_conditions ];
66 } else {
67 // Service query
68 if ( $this->exact_match ) {
69 // search only for schedules that belong to passed service_id
70 $query_args['service_id'] = $this->service_id;
71 } else {
72 $query_args['service_id'] = array_unique( is_array( $this->service_id ) ? array_merge( $this->service_id, [ 0 ] ) : [ $this->service_id, 0 ] );
73 }
74
75 // Location query
76 if ( $this->exact_match ) {
77 // search only for schedules that belong to passed location_id
78 $query_args['location_id'] = $this->location_id;
79 } else {
80 $query_args['location_id'] = array_unique( is_array( $this->location_id ) ? array_merge( $this->location_id, [ 0 ] ) : [ $this->location_id, 0 ] );
81 }
82
83 // Agent query
84 if ( $this->exact_match ) {
85 // search only for schedules that belong to passed agent_id
86 $query_args['agent_id'] = $this->agent_id;
87 } else {
88 $query_args['agent_id'] = array_unique( is_array( $this->agent_id ) ? array_merge( $this->agent_id, [ 0 ] ) : [ $this->agent_id, 0 ] );
89 }
90 }
91
92
93 if ( $this->date_from ) {
94 $query_args['start_date >='] = $this->date_from;
95 $query_args['start_date <='] = $this->date_to;
96 }
97
98 return $query_args;
99 }
100
101 public static function create_from_booking_request( BookingRequest $booking_request ): Filter {
102 return new self(
103 [
104 'date_from' => $booking_request->start_date,
105 'start_time' => $booking_request->start_time,
106 'end_time' => $booking_request->end_time,
107 'agent_id' => $booking_request->agent_id,
108 'location_id' => $booking_request->location_id,
109 'service_id' => $booking_request->service_id,
110 ]
111 );
112 }
113 }
114