PluginProbe
Appointment Booking Plugin – LatePoint | Calendar & Scheduling for WordPress / 5.1.92
Appointment Booking Plugin – LatePoint | Calendar & Scheduling for WordPress v5.1.92
5.6.11 5.6.10 5.6.9 5.6.8 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 All 48 releases
latepoint / lib / misc / filter.php
filter.php
111 lines 3.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
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[] = [ 'AND' => [ 'agent_id' => [ 0, $connection->agent_id ],
58 'service_id' => [ 0, $connection->service_id ],
59 'location_id' => [ 0, $connection->location_id ]
60 ]
61 ];
62 }
63 $query_args['AND'][] = [ 'OR' => $connection_conditions ];
64 } else {
65 // Service query
66 if ( $this->exact_match ) {
67 // search only for schedules that belong to passed service_id
68 $query_args['service_id'] = $this->service_id;
69 } else {
70 $query_args['service_id'] = array_unique( is_array( $this->service_id ) ? array_merge( $this->service_id, [ 0 ] ) : [ $this->service_id, 0 ] );
71 }
72
73 // Location query
74 if ( $this->exact_match ) {
75 // search only for schedules that belong to passed location_id
76 $query_args['location_id'] = $this->location_id;
77 } else {
78 $query_args['location_id'] = array_unique( is_array( $this->location_id ) ? array_merge( $this->location_id, [ 0 ] ) : [ $this->location_id, 0 ] );
79 }
80
81 // Agent query
82 if ( $this->exact_match ) {
83 // search only for schedules that belong to passed agent_id
84 $query_args['agent_id'] = $this->agent_id;
85 } else {
86 $query_args['agent_id'] = array_unique( is_array( $this->agent_id ) ? array_merge( $this->agent_id, [ 0 ] ) : [ $this->agent_id, 0 ] );
87 }
88 }
89
90
91 if ( $this->date_from ) {
92 $query_args['start_date >='] = $this->date_from;
93 $query_args['start_date <='] = $this->date_to;
94 }
95
96 return $query_args;
97 }
98
99 public static function create_from_booking_request( BookingRequest $booking_request ): Filter {
100 return new self( [
101 'date_from' => $booking_request->start_date,
102 'start_time' => $booking_request->start_time,
103 'end_time' => $booking_request->end_time,
104 'agent_id' => $booking_request->agent_id,
105 'location_id' => $booking_request->location_id,
106 'service_id' => $booking_request->service_id
107 ] );
108 }
109
110 }
111