PluginProbe
Timetics – Appointment Booking Calendar & Scheduling / 1.0.56
Timetics – Appointment Booking Calendar & Scheduling v1.0.56
1.0.64 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 All 65 releases
timetics / core / staffs / calendars / CalendarSyncFacade.php

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

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