PluginProbe ʕ •ᴥ•ʔ
Appointment Booking Plugin – LatePoint | Calendar & Scheduling for WordPress / 5.6.8
Appointment Booking Plugin – LatePoint | Calendar & Scheduling for WordPress v5.6.8
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 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 / abilities / calendar / check-slot-availability.php
latepoint / lib / abilities / calendar Last commit date
abstract-calendar-ability.php 4 months ago add-off-period.php 4 months ago check-slot-availability.php 4 months ago get-available-slots.php 4 months ago get-work-schedule.php 4 months ago list-off-periods.php 4 months ago remove-off-period.php 4 months ago
check-slot-availability.php
89 lines
1 <?php
2 if ( ! defined( 'ABSPATH' ) ) {
3 exit;
4 }
5
6 class LatePointAbilityCheckSlotAvailability extends LatePointAbstractCalendarAbility {
7
8 protected function configure(): void {
9 $this->id = 'latepoint/check-slot-availability';
10 $this->label = __( 'Check slot availability', 'latepoint' );
11 $this->description = __( 'Checks whether a specific time slot has no conflicting bookings.', 'latepoint' );
12 $this->permission = '';
13 $this->read_only = true;
14 }
15
16 public function check_permission(): bool {
17 return true;
18 }
19
20 public function get_input_schema(): array {
21 return [
22 'type' => 'object',
23 'properties' => [
24 'service_id' => [ 'type' => 'integer' ],
25 'date' => [
26 'type' => 'string',
27 'format' => 'date',
28 ],
29 'start_time' => [
30 'type' => 'integer',
31 'description' => __( 'Start time (minutes from midnight).', 'latepoint' ),
32 ],
33 'agent_id' => [ 'type' => 'integer' ],
34 'location_id' => [ 'type' => 'integer' ],
35 ],
36 'required' => [ 'service_id', 'date', 'start_time' ],
37 ];
38 }
39
40 public function get_output_schema(): array {
41 return [
42 'type' => 'object',
43 'properties' => [
44 'available' => [ 'type' => 'boolean' ],
45 'conflicts' => [
46 'type' => 'array',
47 'items' => [ 'type' => 'object' ],
48 ],
49 ],
50 ];
51 }
52
53 public function execute( array $args ) {
54 $service_id = (int) $args['service_id'];
55 $date = sanitize_text_field( $args['date'] );
56 $start_time = (int) $args['start_time'];
57 $agent_id = ! empty( $args['agent_id'] ) ? (int) $args['agent_id'] : 0;
58
59 if ( $service_id ) {
60 $service = new OsServiceModel( $service_id );
61 $duration = ( ! $service->is_new_record() && $service->duration ) ? (int) $service->duration : 60;
62 } else {
63 $duration = 60;
64 }
65 $end_time = $start_time + $duration;
66
67 $query = new OsBookingModel();
68 $query->where(
69 [
70 'start_date' => $date,
71 'status' => LATEPOINT_BOOKING_STATUS_APPROVED,
72 ]
73 );
74 if ( $agent_id ) {
75 $query->where( [ 'agent_id' => $agent_id ] );
76 }
77 $query->where( [ 'start_time <' => $end_time ] );
78 $query->where( [ 'end_time >' => $start_time ] );
79
80 $count = $query->count();
81 $available = ( $count === 0 );
82
83 return [
84 'available' => $available,
85 'conflicts' => [],
86 ];
87 }
88 }
89