-
Notifications
You must be signed in to change notification settings - Fork 42
/
Tickets.php
4725 lines (4026 loc) · 141 KB
/
Tickets.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?php
use TEC\Events\Custom_Tables\V1\Models\Occurrence;
use Tribe__Utils__Array as Arr;
if ( ! class_exists( 'Tribe__Tickets__Tickets' ) ) {
/**
* Class with the API definition and common functionality for Tribe Tickets. Providers for this functionality need
* to extend this class.
*
* The relationship between orders, attendees, and event posts is
* maintained through post meta fields set for the attendee object.
* Implementing classes are expected to provide the following class
* constants detailing those meta keys:
*
* ATTENDEE_ORDER_KEY
* ATTENDEE_EVENT_KEY
* ATTENDEE_PRODUCT_KEY
*
* The post type name used for the attendee object should also be
* made available via:
*
* ATTENDEE_OBJECT
*
*
* @since 4.5.0.1 Due to a fatal between Event Ticket Plus extending commerces and this class,
* we changed this from an Abstract to a normal parent class.
*/
class Tribe__Tickets__Tickets {
/**
* Flag used to track if the registration form link has been displayed or not.
*
* @var boolean
*/
private static $have_displayed_reg_link = false;
/**
* Function that is used to store the cache of a specific post associated with a set of tickets, where %d is the
* ID of the post being affected.
*
* @since 4.7.1
*
* @var string
*/
private static $cache_key_prefix = 'tribe_event_tickets_from_';
/**
* All Tribe__Tickets__Tickets api consumers. It's static, so it's shared across all children.
*
* @var array
*/
protected static $active_modules = [];
/**
* Default Tribe__Tickets__Tickets ecommerce module.
* It's static, so it's shared across all children.
*
* @var string
*/
protected static $default_module = 'Tribe__Tickets__RSVP';
/**
* Indicates if the frontend ticket form script has already been enqueued (or not).
*
* @var bool
*/
public static $frontend_script_enqueued = false;
/**
* Collection of ticket objects for which we wish to make global stock data available
* on the frontend.
*
* @var array
*/
protected static $frontend_ticket_data = [];
/**
* Name of this class. Note that it refers to the child class.
*
* @var string
*/
public $class_name;
/**
* Path of the parent class
*
* @var string
*/
private $parent_path;
/**
* URL of the parent class
*
* @var string
*/
private $parent_url;
/**
* Records batches of tickets that are currently unavailable (used for
* displaying the correct "tickets are unavailable" message).
*
* @var array
*/
protected static $currently_unavailable_tickets = [];
/**
* Records posts for which tickets *are* available (used to determine if
* a "tickets are unavailable" message should even display).
*
* @var array
*/
protected static $posts_with_available_tickets = [];
// start API Definitions
// Child classes must implement all these functions / properties
/**
* Name of the provider
*
* @var string
*/
public $plugin_name;
/**
* Path of the child class
*
* @var string
*/
protected $plugin_path;
/**
* URL of the child class
*
* @var string
*/
protected $plugin_url;
/**
* The name of the post type representing a ticket.
*
* @var string
*/
public $ticket_object = '';
/**
* The name of the meta key used to store whether an attendee is subscribed to updates.
*
* @since 5.0.3
*
* @var string
*/
public $attendee_subscribed = '_tribe_tickets_subscribed';
/* Deprecated vars */
/**
* Name of this class. Note that it refers to the child class.
* deprecated - use $class_name
*
* @deprecated 4.6
*
* @var string
*/
public $className;
/**
* Path of the parent class
* deprecated - use $parent_path
*
* @deprecated 4.6
*
* @var string
*/
private $parentPath;
/**
* URL of the parent class
* deprecated - use $parent_url
*
* @deprecated 4.6
*
* @var string
*/
private $parentUrl;
/**
* Name of the provider
* deprecated - use $plugin_name
*
* @deprecated 4.6
*
* @var string
*/
public $pluginName;
/**
* Path of the child class
* deprecated - use $plugin_path
*
* @deprecated 4.6
*
* @var string
*/
protected $pluginPath;
/**
* URL of the child class
* deprecated - use $plugin_url
*
* @deprecated 4.6
*
* @var string
*/
protected $pluginUrl;
/**
* Constant with the Transient Key for Attendees Cache
*/
const ATTENDEES_CACHE = 'tribe_attendees';
/**
* Meta key that contains the user id
*
* @deprecated 4.7 Use the $attendee_user_id variable instead
*
* @var string
*/
const ATTENDEE_USER_ID = '_tribe_tickets_attendee_user_id';
/**
* Meta key that contains the user id
*
* @var string
*/
public $attendee_user_id = '_tribe_tickets_attendee_user_id';
/**
* Name of the CPT that holds Orders
*/
public $order_object = '';
/**
* Name of the CPT that holds Attendees.
*
* @var string
*/
public $attendee_object = '';
/**
* Meta key that relates Attendees and Events.
*
* @var string
*/
public $attendee_event_key = '';
/**
* Meta key that relates Attendees and Products.
*
* @var string
*/
public $attendee_product_key = '';
/**
* Indicates if a ticket for this attendee was sent out via email.
*
* @var boolean
*/
public $attendee_ticket_sent = '_tribe_attendee_ticket_sent';
/**
* Logs the attendee notification email activity.
*
* @var array
*
* @since 5.1.0
*/
public $attendee_activity_log = '_tribe_attendee_activity_log';
/**
* Meta key that if this attendee wants to show on the attendee list
*
* @var string
*/
public $attendee_optout_key = '';
/**
* Meta key that holds the full name of the ticket attendee.
*
* @since 5.0.3
*
* @var string
*/
public $full_name = '_tribe_tickets_full_name';
/**
* Meta key that holds the email of the ticket attendee.
*
* @since 5.0.3
*
* @var string
*/
public $email = '_tribe_tickets_email';
/**
* Meta key that holds the security code that is used for printed tickets and QR codes.
*
* @since 5.0.3
*
* @var string
*/
public $security_code = '_tribe_tickets_security_code';
/**
* Meta key that holds the price paid for the ticket.
*
* @since 5.1.0
*
* @var string
*/
public $price_paid = '_paid_price';
/**
* Meta key that holds the price currency symbol used during payment.
*
* @since 5.1.0
*
* @var string
*/
public $price_currency = '_price_currency_symbol';
/**
* The provider used for Attendees and Tickets ORM.
*
* @var string
*/
public $orm_provider = 'default';
/**
* Meta key that stores if an attendee has checked in to a ticketed post.
*
* @since 5.8.2
*
* @var string
*/
public $checkin_key = '';
/**
* Returns link to the report interface for sales for an event or
* null if the provider doesn't have reporting capabilities.
*
* @abstract
*
* @param int $post_id ID of parent "event" post
* @return mixed
*/
public function get_event_reports_link( $post_id ) {}
/**
* Returns link to the report interface for sales for a single ticket or
* null if the provider doesn't have reporting capabilities.
* As of 4.6 we reversed the params and deprecated $post_id as it was never used
*
* @abstract
*
* @param deprecated $post_id ID of parent "event" post
* @param int $ticket_id ID of ticket post
* @return mixed
*/
public function get_ticket_reports_link( $post_id_deprecated, $ticket_id ) {}
/**
* Returns a single ticket.
*
* @param int $post_id ID of parent "event" post.
* @param int $ticket_id ID of ticket post.
*
* @return Tribe__Tickets__Ticket_Object|null
*/
public function get_ticket( $post_id, $ticket_id ) {
return null;
}
/**
* Set the Query args to fetch all the Tickets.
*
* @since 5.5.0 refactored to use the tickets ORM.
* @since 4.6
* @since 5.5.2 Set default query args.
* @since 5.8.0 Added the `$context` parameter.
*
* @param int|WP_Post $post_id Build the args to query only
* for tickets related to this post ID.
* @param string|null $context The context of the query.
*
* @return Tribe__Repository__Interface
*/
public function set_tickets_query_args( $post_id = null, string $context = null ) {
$repository = tribe_tickets( $this->orm_provider );
$repository->set_request_context( $context );
$repository->by( 'event', $post_id );
$repository->by( 'status', 'publish' );
$repository->by( 'posts_per_page', -1 );
$repository->order_by( 'menu_order' );
$repository->order( 'ASC' );
$default_args = $repository->get_query();
/**
* Filters the query arguments that will be used to fetch tickets.
*
* @since 4.8
*
* @param array $args
*/
$vars = apply_filters( 'tribe_tickets_get_tickets_query_args', $default_args->query_vars );
if ( $default_args->query_vars !== $vars ) {
$repository->by_args( $vars );
}
return $repository;
}
/**
* Retrieve the ID numbers of all tickets assigned to an event.
*
* @since 4.6
* @since 5.5.0 refactored to use the tickets ORM.
* @since 5.8.0 Added the `$context` parameter.
*
* @param int|WP_Post $post Only get tickets assigned to this post ID.
*
* @return array|false
*/
public function get_tickets_ids( $post = 0, string $context = null ) {
$post_id = 0;
if ( is_numeric( $post ) ) {
$post_id = (int) $post;
}
if ( ! empty( $post ) ) {
if ( ! $post instanceof WP_Post ) {
$post = get_post( $post );
}
if ( ! $post instanceof WP_Post ) {
return false;
}
if ( class_exists( Occurrence::class, false ) ) {
/**
* Filters the post ID to use when fetching tickets for an Occurrence.
*
* @since 5.8.0
*
* @param int $post_id The post ID to use when fetching tickets for an Occurrence; this might
* be a real post ID, or a provisional one.
*/
$post_id = apply_filters( 'tec_tickets_normalize_occurrence_id', Occurrence::normalize_id( $post->ID ) );
}
}
return $this->set_tickets_query_args( $post_id, $context )->get_ids();
}
/**
* Returns the html for the delete ticket link
*
* @since 4.6
*
* @param object $ticket Ticket object
*
* @return string HTML link
*/
public function get_ticket_delete_link( $ticket = null ) {
if ( empty( $ticket ) ) {
return '';
}
$delete_text = _x( 'Delete %s', 'delete link', 'event-tickets' );
$button_text = ( 'Tribe__Tickets__RSVP' === $ticket->provider_class )
? sprintf( $delete_text, tribe_get_rsvp_label_singular( 'delete_link' ) )
: sprintf( $delete_text, tribe_get_ticket_label_singular( 'delete_link' ) );
/**
* Allows for the filtering and testing if a user can delete tickets
*
* @since 4.6
*
* @param bool true
* @param int ticket post ID
*
* @return string HTML link | void HTML link
*/
if ( apply_filters( 'tribe_tickets_current_user_can_delete_ticket', true, $ticket->ID, $ticket->provider_class ) ) {
$delete_link = sprintf(
'<span><a href="#" attr-provider="%1$s" attr-ticket-id="%2$s" id="ticket_delete_%2$s" class="ticket_delete">%3$s</a></span>',
$ticket->provider_class,
$ticket->ID,
esc_html( $button_text )
);
return $delete_link;
}
$delete_link = sprintf(
'<span><a href="#" attr-provider="%1$s" attr-ticket-id="%2$s" id="ticket_delete_%2$s" class="ticket_delete">%3$s</a></span>',
$ticket->provider_class,
$ticket->ID,
esc_html__( $button_text )
);
return $delete_link;
}
/**
* Returns the url for the move ticket link
*
* @since 4.6
*
* @param int $post_id ID of parent "event" post
* @param object $ticket Ticket object
*
* @return string HTML link | void HTML link
*/
public function get_ticket_move_url( $post_id, $ticket = null ) {
if ( empty( $ticket ) || empty( $post_id ) ) {
return '';
}
$post_url = get_edit_post_link( $post_id, 'admin' );
$move_type_url = add_query_arg(
[
'dialog' => Tribe__Tickets__Main::instance()->move_ticket_types()->dialog_name(),
'ticket_type_id' => $ticket->ID,
'check' => wp_create_nonce( 'move_tickets' ),
'TB_iframe' => 'true',
],
$post_url
);
return $move_type_url;
}
/**
* Returns the html for the move ticket link
*
* @since 4.6
*
* @param int $post_id ID of parent "event" post
* @param object $ticket Ticket object
*
* @return string HTML link | void HTML link
*/
public function get_ticket_move_link( $post_id, $ticket = null ) {
if ( empty( $ticket ) ) {
return '';
}
$move_text = __( 'Move %s', 'event-tickets' );
$button_text = ( 'Tribe__Tickets__RSVP' === $ticket->provider_class ) ? sprintf( $move_text, tribe_get_rsvp_label_singular( 'move_ticket_button_text' ) ) : sprintf( $move_text, tribe_get_ticket_label_singular( 'move_ticket_button_text' ) ) ;
$move_url = $this->get_ticket_move_url( $post_id, $ticket );
if ( empty( $move_url ) ) {
return '';
}
// Make sure Thickbox is available regardless of which admin page we're on.
add_thickbox();
$move_link = sprintf( '<a href="%1$s" class="thickbox tribe-ticket-move-link">%2$s</a>', $move_url, esc_html( $button_text ) );
return $move_link;
}
/**
* Get the controls (move, delete) as a string and add to our ajax return
*
* @deprecated 4.6.2
* @since 4.6
*
* @param array $return the ajax return data
* @return array $return modified data
*/
public function ajax_ticket_edit_controls( $return ) {
$ticket = $this->get_ticket( $return['post_id'], $return['ID'] );
if ( empty( $ticket ) ) {
return $return;
}
$controls = [];
if ( tribe_is_truthy( tribe_get_request_var( 'is_admin' ) ) ) {
$controls[] = $this->get_ticket_move_link( $return['post_id'], $ticket );
}
$controls[] = $this->get_ticket_delete_link( $ticket );
if ( ! empty( $controls ) ) {
$return['controls'] = join( ' | ', $controls );
}
return $return;
}
/**
* Attempts to load the specified ticket type post object.
*
* @param int $ticket_id ID of ticket post
* @return Tribe__Tickets__Ticket_Object|null
*/
public static function load_ticket_object( $ticket_id ) {
foreach ( self::modules() as $provider_class => $name ) {
$provider = static::get_ticket_provider_instance( $provider_class );
if ( empty( $provider ) ) {
continue;
}
$event = $provider->get_event_for_ticket( $ticket_id );
if ( empty( $event ) ) {
continue;
}
$ticket_object = $provider->get_ticket( $event->ID, $ticket_id );
if ( $ticket_object ) {
return $ticket_object;
}
}
return null;
}
/**
* Returns the event post corresponding to the possible ticket object/ticket ID.
*
* This is used to help differentiate between products which act as tickets for an
* event and those which do not. If $possible_ticket is not related to any events
* then boolean false will be returned.
*
* This stub method should be treated as if it were an abstract method - ie, the
* concrete class ought to provide the implementation.
*
* @param $ticket_product
*
* @return bool|WP_Post
*/
public function get_event_for_ticket( $ticket_product ) {
if ( is_object( $ticket_product ) && isset( $ticket_product->ID ) ) {
$ticket_product = $ticket_product->ID;
}
if ( null === get_post( $ticket_product ) ) {
return false;
}
$event_id = get_post_meta( $ticket_product, $this->get_event_key(), true );
if ( ! empty( $this->attendee_event_key ) && ! $event_id && '' === ( $event_id = get_post_meta( $ticket_product, $this->attendee_event_key, true ) ) ) {
return false;
}
$post_types = Tribe__Tickets__Main::instance()->post_types();
if ( in_array( get_post_type( $event_id ), $post_types ) ) {
return get_post( $event_id );
}
return false;
}
/**
* Deletes a ticket
*
* @abstract
*
* @param int $post_id ID of parent "event" post
* @param int $ticket_id ID of ticket post
* @return mixed
*/
public function delete_ticket( $post_id, $ticket_id ) {
/**
* Trigger action when any attendee is deleted.
*
* @since 5.1.5
*
* @param int $post_id Post or Event ID.
* @param int $ticket_id Attendee ID.
*/
do_action( 'event_tickets_attendee_ticket_deleted', $post_id, $ticket_id );
$this->clear_ticket_cache_for_post( $post_id );
$this->clear_attendees_cache( $post_id );
}
/**
* Saves a ticket.
*
* @abstract
*
* @param int $post_id Post ID.
* @param Tribe__Tickets__Ticket_Object $ticket Ticket object.
* @param array $raw_data Ticket data.
*
* @return int|false The updated/created ticket post ID or false if no ticket ID.
*/
public function save_ticket( $post_id, $ticket, $raw_data = [] ) {
$this->clear_ticket_cache_for_post( $post_id );
return false;
}
/**
* Whether a post has tickets from this provider, even if this provider is not the default provider.
*
* @since 4.12.3
*
* @param int|WP_Post $post
*
* @return bool True if this post has any tickets from this provider.
*/
public function post_has_tickets( $post ) {
$post_id = Tribe__Main::post_id_helper( $post );
if ( empty( $post_id ) ) {
return false;
}
return ! empty( $this->get_tickets_ids( $post_id ) );
}
/**
* Clear the ticket cache for a specific post ID.
*
* @since 5.1.0
*
* @param int $post_id The post ID.
*/
public function clear_ticket_cache_for_post( $post_id ) {
/** @var Tribe__Cache $cache */
$cache = tribe( 'cache' );
$class = __CLASS__;
$methods = [
'get_tickets',
];
foreach ( $methods as $method ) {
$key = $class . '::' . $method . '-' . $this->orm_provider . '-' . $post_id;
unset( $cache[ $key ] );
}
$static_methods = [
'get_all_event_tickets',
'get_event_attendees_count',
];
foreach ( $static_methods as $method ) {
$key = $class . '::' . $method . '-' . $post_id;
unset( $cache[ $key ] );
}
$ticket_ids = $this->get_tickets_ids( $post_id );
foreach ( (array) $ticket_ids as $ticket_id ) {
clean_post_cache( $ticket_id );
}
}
/**
* Returns all the tickets for an event, of the active ticket providers.
*
* @since 4.12.0 Changed from protected abstract to public with duplicated child classes' logic consolidated here.
* @since 5.8.0 Added the `$context` parameter.
*
* @param int $post_id ID of parent "event" post.
* @param string|null $context The context of the request.
*
* @return Tribe__Tickets__Ticket_Object[] List of ticket objects.
*/
public function get_tickets( $post_id, string $context = null ) {
/** @var Tribe__Cache $cache */
$cache = tribe( 'cache' );
$key = __METHOD__ . '-' . $this->orm_provider . '-' . $post_id;
if ( isset( $cache[ $key ] ) && is_array( $cache[ $key ] ) ) {
return $cache[ $key ];
}
$default_provider = static::get_event_ticket_provider( $post_id );
if ( empty( $default_provider ) ) {
return [];
}
// If the post's provider doesn't match.
if (
$this->class_name !== $default_provider
&& ! is_admin()
) {
return [];
}
$ticket_ids = $this->get_tickets_ids( $post_id, $context );
if ( ! $ticket_ids ) {
return [];
}
$tickets = [];
foreach ( $ticket_ids as $post ) {
$ticket = $this->get_ticket( $post_id, $post );
if (
! $ticket instanceof Tribe__Tickets__Ticket_Object
|| $this->class_name !== $ticket->provider_class
) {
continue;
}
$tickets[] = $ticket;
}
$cache[ $key ] = $tickets;
return $tickets;
}
/**
* Get attendees for a Post ID / Post type.
*
* @param int $post_id Post ID.
* @param null|string $post_type Post type.
*
* @return array List of attendees.
*/
public function get_attendees_by_id( $post_id, $post_type = null ) {
return $this->get_attendees_by_post_id( $post_id );
}
/**
* Get attendees for an event ID.
*
* @param int $event_id Event post ID.
*
* @return array List of attendees.
*/
protected function get_attendees_by_post_id( $event_id ) {
/** @var Tribe__Tickets__Attendee_Repository $repository */
$repository = tribe_attendees( $this->orm_provider );
return $this->get_attendees_from_module( $repository->by( 'event', $event_id )->all(), $event_id );
}
/**
* Get attendees for a ticket ID.
*
* @since 4.10.6
*
* @param int $ticket_id Ticket ID.
*
* @return array List of attendees.
*/
protected function get_attendees_by_ticket_id( $ticket_id ) {
/** @var Tribe__Tickets__Attendee_Repository $repository */
$repository = tribe_attendees( $this->orm_provider );
return $this->get_attendees_from_module( $repository->by( 'ticket', $ticket_id )->all() );
}
/**
* Get attendees for a ticket ID.
*
* @since 4.10.6
*
* @param int $ticket_id Ticket ID.
*
* @return array List of attendees.
*/
protected function get_attendees_by_product_id( $ticket_id ) {
return $this->get_attendees_by_ticket_id( $ticket_id );
}
/**
* Get attendees for a ticket by order ID, optionally by ticket ID.
*
* @since 4.6
*
* @param int|string $order_id Order ID.
* @param null|int $ticket_id (optional) Ticket ID.
*
* @return array List of attendees.
*/
public function get_attendees_by_order_id( $order_id ) {
$ticket_id = null;
// Support an optional second argument while not causing warnings from other ticket provider classes.
if ( 1 < func_num_args() ) {
$ticket_id = func_get_arg( 1 );
}
/** @var Tribe__Tickets__Attendee_Repository $repository */
$repository = tribe_attendees( $this->orm_provider );
$repository->by( 'order', $order_id );
if ( $ticket_id ) {
$repository->by( 'ticket', $ticket_id );
}
return $this->get_attendees_from_module( $repository->all() );
}
/**
* Get attendees for a ticket by attendee ID.
*
* @since 4.6
*
* @param int $attendee_id Attendee ID.
*
* @return array List of attendees.
*/
protected function get_attendees_by_attendee_id( $attendee_id ) {
/** @var Tribe__Tickets__Attendee_Repository $repository */
$repository = tribe_attendees( $this->orm_provider );
return $this->get_attendees_from_module( $repository->by( 'id', $attendee_id )->all() );
}
/**
* Get attendees for a ticket by user ID.
*
* @since 4.10.6
*
* @param int $user_id User ID.
* @param int $post_id Post or Event ID.
*
* @return array List of attendees.
*/
public function get_attendees_by_user_id( $user_id, $post_id = 0 ) {
/** @var Tribe__Tickets__Attendee_Repository $repository */
$repository = tribe_attendees( $this->orm_provider );
$repository->by( 'user', $user_id );
if ( $post_id ) {
$repository->by( 'event', $post_id );
}
return $this->get_attendees_from_module( $repository->all() );
}
/**
* Get All Attendees by ticket/attendee ID
*
* @since 4.8.0
*
* @param int $attendee_id
* @return array
*/
public function get_all_attendees_by_attendee_id( $attendee_id ) {
return $this->get_attendees_by_attendee_id( $attendee_id );
}
/**
* Get attendees from provided query
*
* @param WP_Query $attendees_query
* @param int $post_id ID of parent "event" post
* @return mixed
*/
protected function get_attendees( $attendees_query, $post_id ) {
$attendees = [];
foreach ( $attendees_query->posts as $attendee ) {
$attendee_data = $this->get_attendee( $attendee, $post_id );
if ( ! $attendee_data ) {
continue;
}
$attendees[] = $attendee_data;
}
return $attendees;
}
/**
* Whether a specific attendee is valid toward inventory decrease or not.
*