PluginProbe
Timetics – Appointment Booking Calendar & Scheduling / 1.0.13
Timetics – Appointment Booking Calendar & Scheduling v1.0.13
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 1.0.23 1.0.24 All 62 releases
timetics / core / bookings / booking-entry.php

booking-entry.php in Timetics – Appointment Booking Calendar & Scheduling 1.0.13, at core/bookings/booking-entry.php

392 lines 7.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Booking entry
4 *
5 * @package Timetics
6 */
7
8 namespace Timetics\Core\Bookings;
9
10 /**
11 * Class Booking Entry
12 */
13 class Booking_Entry {
14
15 /**
16 * Store post type
17 *
18 * @var string
19 */
20 private $post_type = 'timetics-schedule';
21
22 /**
23 * Store prefix
24 *
25 * @var string
26 */
27 private $prefix = '_timetics_schedule_';
28
29 /**
30 * Store entry id
31 *
32 * @var string
33 */
34 private $id;
35
36 /**
37 * Store entries
38 *
39 * @var array
40 */
41 private $entries = [];
42
43 /**
44 * Store entry data
45 *
46 * @var array
47 */
48 private $data = [
49 'meeting_id' => '',
50 'staff_id' => '',
51 'customer_id' => '',
52 'booking_id' => '',
53 'booked' => '',
54 'date' => '',
55 'start' => '',
56 'end' => '',
57 'seats' => '',
58 'google_event' => '',
59 'zoom' => '',
60 ];
61
62 /**
63 * Constructor for Booking Entry
64 *
65 * @param integer | Object $entry
66 *
67 * @return void
68 */
69 public function __construct( $entry = 0 ) {
70 if ( $entry instanceof self ) {
71 $this->set_id( $entry->get_id() );
72 } elseif ( ! empty( $entry->ID ) ) {
73 $this->set_id( $entry->ID );
74 } elseif ( is_numeric( $entry ) && $entry > 0 ) {
75 $this->set_id( $entry );
76 }
77 }
78
79 /**
80 * Get booking entry id
81 *
82 * @return integer
83 */
84 public function get_id() {
85 return $this->id;
86 }
87
88 /**
89 * Get meeting id
90 *
91 * @return integer
92 */
93 public function get_meeting_id() {
94 return $this->get_prop( 'meeting_id' );
95 }
96
97 /**
98 * Get staff id
99 *
100 * @return integer
101 */
102 public function get_staff_id() {
103 return $this->get_prop( 'staff_id' );
104 }
105
106 /**
107 * Get customer id
108 *
109 * @return integer
110 */
111 public function get_customer_id() {
112 return $this->get_prop( 'customer_id' );
113 }
114
115 /**
116 * Get booking id
117 *
118 * @return integer
119 */
120 public function get_booking_id() {
121 return $this->get_prop( 'booking_id' );
122 }
123
124 /**
125 * Get booked
126 *
127 * @return integer
128 */
129 public function get_booked() {
130 return $this->get_prop( 'booked' );
131 }
132
133 /**
134 * Get start time
135 *
136 * @return string
137 */
138 public function get_start() {
139 return $this->get_prop( 'start' );
140 }
141
142 /**
143 * Get end time
144 *
145 * @return string
146 */
147 public function get_end() {
148 return $this->get_prop( 'end' );
149 }
150
151 /**
152 * Get date
153 *
154 * @return string
155 */
156 public function get_date() {
157 return $this->get_prop( 'date' );
158 }
159
160 /**
161 * Get google calender event with google meet link
162 *
163 * @return array
164 */
165 public function get_google_event() {
166 return $this->get_prop( 'google_event' );
167 }
168
169 /**
170 * Get zoom link
171 *
172 * @return array
173 */
174 public function get_zoom() {
175 return $this->get_prop( 'zoom' );
176 }
177
178 /**
179 * Get seats
180 *
181 * @return array
182 */
183 public function get_seats() {
184 return $this->get_prop( 'seats' );
185 }
186
187 /**
188 * Get entry data
189 *
190 * @return array
191 */
192 public function get_data() {
193 return [
194 'id' => $this->get_id(),
195 'meeting_id' => $this->get_meeting_id(),
196 'staff_id' => $this->get_staff_id(),
197 'booking_id' => $this->get_booking_id(),
198 'customer_id' => $this->get_customer_id(),
199 'booked' => $this->get_booked(),
200 'date' => $this->get_date(),
201 'start' => $this->get_start(),
202 'end' => $this->get_end(),
203 ];
204 }
205
206 /**
207 * Get prop
208 *
209 * @param string $name
210 *
211 * @return mixed
212 */
213 public function get_prop( $name ) {
214 $key = $this->prefix . $name;
215
216 return get_post_meta( $this->id, $key, true );
217 }
218
219 /**
220 * Find booking entry
221 *
222 * @param array $args
223 *
224 * @return array
225 */
226 public function find( $args = [] ) {
227 $data = [
228 'post_type' => $this->post_type,
229 'post_status' => 'publish',
230 'numberposts' => -1,
231 ];
232
233 if ( $args ) {
234 $query = [
235 'relation' => 'AND',
236 ];
237 foreach ( $args as $key => $value ) {
238 $meta_key = $this->prefix . $key;
239 $meta_query = [
240 'key' => $meta_key,
241 'value' => $value,
242 'compare' => '=',
243 ];
244
245 $query[] = $meta_query;
246 }
247
248 // @codingStandardsIgnoreStart
249 $data['meta_query'] = $query;
250 // @codingStandardsIgnoreEnd
251 }
252
253 $entries = $this->collection( get_posts( $data ) );
254
255 $this->entries = $entries;
256
257 return $entries;
258 }
259
260 /**
261 * Get all booking entries
262 *
263 * @return array
264 */
265 public function all() {
266 $entries = get_posts(
267 [
268 'post_type' => $this->post_type,
269 'post_status' => 'publish',
270 'numberposts' => -1,
271 ]
272 );
273
274 $this->entries = $entries;
275 $entries = $this->collection( $entries );
276
277 return $entries;
278 }
279
280 /**
281 * Get first entry from the entries
282 *
283 * @return Object | null
284 */
285 public function first() {
286 if ( $this->entries ) {
287 return $this->entries[0];
288 }
289
290 return null;
291 }
292
293 /**
294 * Get instance of the current entry
295 *
296 * @param mixed $entry
297 *
298 * @return Object
299 */
300 private function get_instance( $entry ) {
301 return new self( $entry );
302 }
303
304 /**
305 * Get collection of object
306 *
307 * @param array $data
308 *
309 * @return array
310 */
311 private function collection( $data = [] ) {
312 return array_map( [$this, 'get_instance'], $data );
313 }
314
315 /**
316 * Set entry id
317 *
318 * @param integer $id
319 *
320 * @return void
321 */
322 private function set_id( $id ) {
323 $this->id = $id;
324 }
325
326 /**
327 * Create booking entry
328 *
329 * @param array $args
330 *
331 * @return integer
332 */
333 public function create( $args = [] ) {
334 $args = wp_parse_args( $args, $this->data );
335
336 $entry = wp_insert_post(
337 [
338 'post_title' => $this->post_type . $args['start'],
339 'post_type' => $this->post_type,
340 'post_status' => 'publish',
341 'post_author' => 1,
342 ]
343 );
344
345 if ( ! is_wp_error( $entry ) ) {
346 $this->set_id( $entry );
347 $this->update_metadata( $args );
348 }
349
350 return $entry;
351 }
352
353 /**
354 * Update booking entry
355 *
356 * @param array $args
357 *
358 * @return void
359 */
360 public function update( $args ) {
361 $this->update_metadata( $args );
362 }
363
364 /**
365 * Update metadata
366 *
367 * @param array $data
368 *
369 * @return void
370 */
371 private function update_metadata( $data = [] ) {
372 foreach ( $data as $key => $value ) {
373 if ( ! array_key_exists( $key, $this->data ) ) {
374 continue;
375 }
376
377 $meta_key = $this->prefix . $key;
378
379 update_post_meta( $this->id, $meta_key, $value );
380 }
381 }
382
383 /**
384 * Delete booking
385 *
386 * @return bool | WP_Error
387 */
388 public function delete() {
389 return wp_delete_post( $this->id, true );
390 }
391 }
392