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 / bookings / booking-entry.php

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

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