PluginProbe
Timetics – Appointment Booking Calendar & Scheduling / 1.0.63
Timetics – Appointment Booking Calendar & Scheduling v1.0.63
1.0.62 1.0.63 1.0.61 1.0.60 1.0.59 1.0.58 1.0.57 1.0.56 trunk 1.0.0 1.0.1 1.0.10 1.0.11 1.0.12 1.0.13 1.0.14 1.0.15 1.0.16 1.0.17 1.0.18 1.0.19 1.0.2 1.0.20 1.0.21 1.0.22 All 64 releases
timetics / core / staffs / calendars / CalendarSyncFacade.php

CalendarSyncFacade.php in Timetics – Appointment Booking Calendar & Scheduling 1.0.63, at core/staffs/calendars/CalendarSyncFacade.php

85 lines 2.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 namespace Timetics\Core\Staffs\Calendars;
3
4 defined( 'ABSPATH' ) || exit;
5
6 use Timetics\Core\Bookings\Booking;
7
8 /**
9 * Calendar sync with timetics booking
10 */
11 class CalendarSyncFacade {
12 /**
13 * Store staff id
14 *
15 * @var integer
16 */
17 private static $staff_id;
18
19 /**
20 * Sync booking
21 *
22 * @param string $teamMemberId [$teamMemberId description]
23 * @param array $bookingData [$bookingData description]
24 *
25 * @return bool [return description]
26 */
27 public static function syncBooking(string $teamMemberId, array $bookingData): bool {
28 $services = CalendarSyncFactory::getSyncServices( $teamMemberId );
29 $status = true;
30
31 foreach ( $services as $service ) {
32 $status = $status && $service->syncToCalendar( $bookingData );
33 }
34
35 return $status;
36 }
37
38 /**
39 * Fetch booking with calendar services
40 *
41 * @param string $teamMemberId
42 *
43 * @return array
44 */
45 public static function fetchBookings( string $teamMemberId ): array {
46 $services = CalendarSyncFactory::getSyncServices($teamMemberId);
47 $allBookings = [];
48 self::$staff_id = $teamMemberId;
49
50 foreach ( $services as $service ) {
51 $allBookings = array_merge( $allBookings, $service->fetchBookings( $teamMemberId ) );
52
53 self::create_bookings( $allBookings );
54 }
55
56 return $allBookings;
57 }
58
59 /**
60 * Create bookings with calendar events
61 *
62 * @param array $bookings Booking list from calendar
63 *
64 * @return bool
65 */
66 private static function create_bookings( $bookings ) {
67 if ( $bookings ) {
68 foreach ( $bookings as $booking_data ) {
69 $booking = new Booking();
70 $booking->set_props([
71 'staff' => self::$staff_id,
72 'start_date' => $booking_data['start_date'],
73 'start_time' => $booking_data['start_time'],
74 'end_date' => $booking_data['end_date'],
75 'end_time' => $booking_data['end_time'],
76 'description' => $booking_data['description'],
77 'post_status' => 'pending'
78 ]);
79 $booking->save();
80 }
81 }
82 }
83 }
84
85