PluginProbe
Timetics – Appointment Booking Calendar & Scheduling / 1.0.22
Timetics – Appointment Booking Calendar & Scheduling v1.0.22
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.22, at core/bookings/booking-entry.php

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