PluginProbe
Booktics – Appointment Booking Calendar for Service Businesses / 1.0.20
Booktics – Appointment Booking Calendar for Service Businesses v1.0.20
1.0.29 1.0.28 1.0.27 1.0.26 1.0.25 1.0.24 1.0.23 1.0.22 1.0.21 1.0.20 1.0.19 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.2 1.0.3 All 31 releases
booktics / core / appointment / schedule / schedule-entry.php

schedule-entry.php in Booktics – Appointment Booking Calendar for Service Businesses 1.0.20, at core/appointment/schedule/schedule-entry.php

119 lines 2.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 namespace Booktics\Appointment\Schedule;
3
4 use DateTime;
5
6 /**
7 * Schedule Entry Class
8 */
9 class Schedule_Entry {
10 /**
11 * Store start time
12 *
13 * @var string
14 */
15 private string $start_time;
16
17 /**
18 * Store end time
19 *
20 * @var string
21 */
22 private string $end_time;
23
24 /**
25 * Store day of week
26 *
27 * @var int
28 */
29 private int $day_of_week;
30
31 /**
32 * Store custom date
33 *
34 * @var string|null
35 */
36 private ?string $custom_date;
37
38 /**
39 * Store holiday checking
40 *
41 * @var bool
42 */
43 private bool $is_holiday;
44
45 /**
46 * Constructor for ScheduleEntry
47 *
48 * @param array $data Schedule data
49 *
50 * @return void
51 */
52 public function __construct(array $data) {
53 $this->start_time = booktics_time_from_gmt( $data['start_time'], $data['custom_date'] ?? 0 );
54 $this->end_time = booktics_time_from_gmt( $data['end_time'], $data['custom_date'] ?? 0 );
55 $this->day_of_week = (int) $data['week_day'];
56 $this->custom_date = $data['custom_date'] ?? null;
57 $this->is_holiday = $this->start_time == 0 && $this->end_time == 0;
58 }
59
60 /**
61 * Get start time
62 *
63 * @return string Start time value
64 */
65 public function get_start_time(): string {
66 return $this->start_time;
67 }
68
69 /**
70 * Get end time
71 *
72 * @return string End time value
73 */
74 public function get_end_time(): string {
75 return $this->end_time;
76 }
77
78 /**
79 * Get day of week
80 *
81 * @return int Day of week value
82 */
83 public function get_day_of_week(): int {
84 return $this->day_of_week;
85 }
86
87 /**
88 * Get custom date
89 *
90 * @return string|null Custom date value
91 */
92 public function get_custom_date(): ?string {
93 return $this->custom_date;
94 }
95
96 /**
97 * Check if schedule entry is holiday
98 *
99 * @return bool True if holiday, false otherwise
100 */
101 public function is_holiday(): bool {
102 return $this->is_holiday;
103 }
104
105 /**
106 * Compare date
107 *
108 * @param DateTime $date Schedule date time
109 *
110 * @return bool Return True if match date otherwise false
111 */
112 public function matches_date( DateTime $date ): bool {
113 $dow = intval($date->format('N')); // 1 = Monday
114 return $this->custom_date === $date->format('Y-m-d') ||
115 ( $this->custom_date == 0 && (int)$this->day_of_week == $dow );
116 }
117 }
118
119