Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.
Common duplication problems, and corresponding solutions are:
Complex classes like EE_Registration often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use EE_Registration, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
17 | class EE_Registration extends EE_Soft_Delete_Base_Class implements EEI_Registration, EEI_Admin_Links |
||
18 | { |
||
19 | |||
20 | |||
21 | /** |
||
22 | * Used to reference when a registration has never been checked in. |
||
23 | * |
||
24 | * @deprecated use \EE_Checkin::status_checked_never instead |
||
25 | * @type int |
||
26 | */ |
||
27 | const checkin_status_never = 2; |
||
28 | |||
29 | /** |
||
30 | * Used to reference when a registration has been checked in. |
||
31 | * |
||
32 | * @deprecated use \EE_Checkin::status_checked_in instead |
||
33 | * @type int |
||
34 | */ |
||
35 | const checkin_status_in = 1; |
||
36 | |||
37 | |||
38 | /** |
||
39 | * Used to reference when a registration has been checked out. |
||
40 | * |
||
41 | * @deprecated use \EE_Checkin::status_checked_out instead |
||
42 | * @type int |
||
43 | */ |
||
44 | const checkin_status_out = 0; |
||
45 | |||
46 | |||
47 | /** |
||
48 | * extra meta key for tracking reg status os trashed registrations |
||
49 | * |
||
50 | * @type string |
||
51 | */ |
||
52 | const PRE_TRASH_REG_STATUS_KEY = 'pre_trash_registration_status'; |
||
53 | |||
54 | |||
55 | /** |
||
56 | * extra meta key for tracking if registration has reserved ticket |
||
57 | * |
||
58 | * @type string |
||
59 | */ |
||
60 | const HAS_RESERVED_TICKET_KEY = 'has_reserved_ticket'; |
||
61 | |||
62 | |||
63 | /** |
||
64 | * @param array $props_n_values incoming values |
||
65 | * @param string $timezone incoming timezone (if not set the timezone set for the website will be |
||
66 | * used.) |
||
67 | * @param array $date_formats incoming date_formats in an array where the first value is the |
||
68 | * date_format and the second value is the time format |
||
69 | * @return EE_Registration |
||
70 | * @throws EE_Error |
||
71 | */ |
||
72 | public static function new_instance($props_n_values = array(), $timezone = null, $date_formats = array()) |
||
77 | |||
78 | |||
79 | /** |
||
80 | * @param array $props_n_values incoming values from the database |
||
81 | * @param string $timezone incoming timezone as set by the model. If not set the timezone for |
||
82 | * the website will be used. |
||
83 | * @return EE_Registration |
||
84 | */ |
||
85 | public static function new_instance_from_db($props_n_values = array(), $timezone = null) |
||
89 | |||
90 | |||
91 | /** |
||
92 | * Set Event ID |
||
93 | * |
||
94 | * @param int $EVT_ID Event ID |
||
95 | * @throws EE_Error |
||
96 | * @throws RuntimeException |
||
97 | */ |
||
98 | public function set_event($EVT_ID = 0) |
||
102 | |||
103 | |||
104 | /** |
||
105 | * Overrides parent set() method so that all calls to set( 'REG_code', $REG_code ) OR set( 'STS_ID', $STS_ID ) can |
||
106 | * be routed to internal methods |
||
107 | * |
||
108 | * @param string $field_name |
||
109 | * @param mixed $field_value |
||
110 | * @param bool $use_default |
||
111 | * @throws EE_Error |
||
112 | * @throws EntityNotFoundException |
||
113 | * @throws InvalidArgumentException |
||
114 | * @throws InvalidDataTypeException |
||
115 | * @throws InvalidInterfaceException |
||
116 | * @throws ReflectionException |
||
117 | * @throws RuntimeException |
||
118 | */ |
||
119 | public function set($field_name, $field_value, $use_default = false) |
||
134 | |||
135 | |||
136 | /** |
||
137 | * Set Status ID |
||
138 | * updates the registration status and ALSO... |
||
139 | * calls reserve_registration_space() if the reg status changes TO approved from any other reg status |
||
140 | * calls release_registration_space() if the reg status changes FROM approved to any other reg status |
||
141 | * |
||
142 | * @param string $new_STS_ID |
||
143 | * @param boolean $use_default |
||
144 | * @param Context|null $context |
||
145 | * @return bool |
||
146 | * @throws EE_Error |
||
147 | * @throws EntityNotFoundException |
||
148 | * @throws InvalidArgumentException |
||
149 | * @throws ReflectionException |
||
150 | * @throws RuntimeException |
||
151 | * @throws InvalidDataTypeException |
||
152 | * @throws InvalidInterfaceException |
||
153 | */ |
||
154 | public function set_status($new_STS_ID = null, $use_default = false, Context $context = null) |
||
195 | |||
196 | |||
197 | /** |
||
198 | * update REGs and TXN when cancelled or declined registrations involved |
||
199 | * |
||
200 | * @param string $new_STS_ID |
||
201 | * @param string $old_STS_ID |
||
202 | * @param Context|null $context |
||
203 | * @throws EE_Error |
||
204 | * @throws InvalidArgumentException |
||
205 | * @throws InvalidDataTypeException |
||
206 | * @throws InvalidInterfaceException |
||
207 | * @throws ReflectionException |
||
208 | */ |
||
209 | private function _update_if_canceled_or_declined($new_STS_ID, $old_STS_ID, Context $context = null) |
||
227 | |||
228 | |||
229 | /** |
||
230 | * update REGs and TXN when cancelled or declined registrations involved |
||
231 | * |
||
232 | * @param array $closed_reg_statuses |
||
233 | * @param string $new_STS_ID |
||
234 | * @param string $old_STS_ID |
||
235 | * @param Context|null $context |
||
236 | * @throws EE_Error |
||
237 | * @throws InvalidArgumentException |
||
238 | * @throws InvalidDataTypeException |
||
239 | * @throws InvalidInterfaceException |
||
240 | * @throws ReflectionException |
||
241 | */ |
||
242 | View Code Duplication | private function updateIfCanceled(array $closed_reg_statuses, $new_STS_ID, $old_STS_ID, Context $context = null) |
|
272 | |||
273 | |||
274 | /** |
||
275 | * update REGs and TXN when cancelled or declined registrations involved |
||
276 | * |
||
277 | * @param array $closed_reg_statuses |
||
278 | * @param string $new_STS_ID |
||
279 | * @param string $old_STS_ID |
||
280 | * @param Context|null $context |
||
281 | * @throws EE_Error |
||
282 | * @throws InvalidArgumentException |
||
283 | * @throws InvalidDataTypeException |
||
284 | * @throws InvalidInterfaceException |
||
285 | * @throws ReflectionException |
||
286 | */ |
||
287 | View Code Duplication | private function updateIfDeclined(array $closed_reg_statuses, $new_STS_ID, $old_STS_ID, Context $context = null) |
|
316 | |||
317 | |||
318 | /** |
||
319 | * @param Context|null $context |
||
320 | * @return bool |
||
321 | */ |
||
322 | private function statusChangeUpdatesTransaction(Context $context = null) |
||
335 | |||
336 | |||
337 | /** |
||
338 | * @throws EE_Error |
||
339 | * @throws EntityNotFoundException |
||
340 | * @throws InvalidArgumentException |
||
341 | * @throws InvalidDataTypeException |
||
342 | * @throws InvalidInterfaceException |
||
343 | * @throws ReflectionException |
||
344 | * @throws RuntimeException |
||
345 | */ |
||
346 | private function updateTransactionAfterStatusChange() |
||
353 | |||
354 | |||
355 | /** |
||
356 | * get Status ID |
||
357 | */ |
||
358 | public function status_ID() |
||
362 | |||
363 | |||
364 | /** |
||
365 | * increments this registration's related ticket sold and corresponding datetime sold values |
||
366 | * |
||
367 | * @return void |
||
368 | * @throws EE_Error |
||
369 | * @throws EntityNotFoundException |
||
370 | */ |
||
371 | private function _reserve_registration_space() |
||
382 | |||
383 | |||
384 | /** |
||
385 | * Gets the ticket this registration is for |
||
386 | * |
||
387 | * @param boolean $include_archived whether to include archived tickets or not. |
||
388 | * @return EE_Ticket|EE_Base_Class |
||
389 | * @throws \EE_Error |
||
390 | */ |
||
391 | public function ticket($include_archived = true) |
||
399 | |||
400 | |||
401 | /** |
||
402 | * Gets the event this registration is for |
||
403 | * |
||
404 | * @return EE_Event |
||
405 | * @throws EE_Error |
||
406 | * @throws EntityNotFoundException |
||
407 | */ |
||
408 | public function event() |
||
416 | |||
417 | |||
418 | /** |
||
419 | * Gets the "author" of the registration. Note that for the purposes of registrations, the author will correspond |
||
420 | * with the author of the event this registration is for. |
||
421 | * |
||
422 | * @since 4.5.0 |
||
423 | * @return int |
||
424 | * @throws EE_Error |
||
425 | * @throws EntityNotFoundException |
||
426 | */ |
||
427 | public function wp_user() |
||
435 | |||
436 | |||
437 | /** |
||
438 | * decrements (subtracts) this registration's related ticket sold and corresponding datetime sold values |
||
439 | * |
||
440 | * @return void |
||
441 | * @throws \EE_Error |
||
442 | */ |
||
443 | private function _release_registration_space() |
||
449 | |||
450 | |||
451 | /** |
||
452 | * tracks this registration's ticket reservation in extra meta |
||
453 | * and can increment related ticket reserved and corresponding datetime reserved values |
||
454 | * |
||
455 | * @param bool $update_ticket if true, will increment ticket and datetime reserved count |
||
456 | * @return void |
||
457 | * @throws \EE_Error |
||
458 | */ |
||
459 | public function reserve_ticket($update_ticket = false) |
||
471 | |||
472 | |||
473 | /** |
||
474 | * stops tracking this registration's ticket reservation in extra meta |
||
475 | * decrements (subtracts) related ticket reserved and corresponding datetime reserved values |
||
476 | * |
||
477 | * @param bool $update_ticket if true, will decrement ticket and datetime reserved count |
||
478 | * @return void |
||
479 | * @throws \EE_Error |
||
480 | */ |
||
481 | public function release_reserved_ticket($update_ticket = false) |
||
493 | |||
494 | |||
495 | /** |
||
496 | * Set Attendee ID |
||
497 | * |
||
498 | * @param int $ATT_ID Attendee ID |
||
499 | * @throws EE_Error |
||
500 | * @throws RuntimeException |
||
501 | */ |
||
502 | public function set_attendee_id($ATT_ID = 0) |
||
506 | |||
507 | |||
508 | /** |
||
509 | * Set Transaction ID |
||
510 | * |
||
511 | * @param int $TXN_ID Transaction ID |
||
512 | * @throws EE_Error |
||
513 | * @throws RuntimeException |
||
514 | */ |
||
515 | public function set_transaction_id($TXN_ID = 0) |
||
519 | |||
520 | |||
521 | /** |
||
522 | * Set Session |
||
523 | * |
||
524 | * @param string $REG_session PHP Session ID |
||
525 | * @throws EE_Error |
||
526 | * @throws RuntimeException |
||
527 | */ |
||
528 | public function set_session($REG_session = '') |
||
532 | |||
533 | |||
534 | /** |
||
535 | * Set Registration URL Link |
||
536 | * |
||
537 | * @param string $REG_url_link Registration URL Link |
||
538 | * @throws EE_Error |
||
539 | * @throws RuntimeException |
||
540 | */ |
||
541 | public function set_reg_url_link($REG_url_link = '') |
||
545 | |||
546 | |||
547 | /** |
||
548 | * Set Attendee Counter |
||
549 | * |
||
550 | * @param int $REG_count Primary Attendee |
||
551 | * @throws EE_Error |
||
552 | * @throws RuntimeException |
||
553 | */ |
||
554 | public function set_count($REG_count = 1) |
||
558 | |||
559 | |||
560 | /** |
||
561 | * Set Group Size |
||
562 | * |
||
563 | * @param boolean $REG_group_size Group Registration |
||
564 | * @throws EE_Error |
||
565 | * @throws RuntimeException |
||
566 | */ |
||
567 | public function set_group_size($REG_group_size = false) |
||
571 | |||
572 | |||
573 | /** |
||
574 | * is_not_approved - convenience method that returns TRUE if REG status ID == |
||
575 | * EEM_Registration::status_id_not_approved |
||
576 | * |
||
577 | * @return boolean |
||
578 | */ |
||
579 | public function is_not_approved() |
||
583 | |||
584 | |||
585 | /** |
||
586 | * is_pending_payment - convenience method that returns TRUE if REG status ID == |
||
587 | * EEM_Registration::status_id_pending_payment |
||
588 | * |
||
589 | * @return boolean |
||
590 | */ |
||
591 | public function is_pending_payment() |
||
595 | |||
596 | |||
597 | /** |
||
598 | * is_approved - convenience method that returns TRUE if REG status ID == EEM_Registration::status_id_approved |
||
599 | * |
||
600 | * @return boolean |
||
601 | */ |
||
602 | public function is_approved() |
||
606 | |||
607 | |||
608 | /** |
||
609 | * is_cancelled - convenience method that returns TRUE if REG status ID == EEM_Registration::status_id_cancelled |
||
610 | * |
||
611 | * @return boolean |
||
612 | */ |
||
613 | public function is_cancelled() |
||
617 | |||
618 | |||
619 | /** |
||
620 | * is_declined - convenience method that returns TRUE if REG status ID == EEM_Registration::status_id_declined |
||
621 | * |
||
622 | * @return boolean |
||
623 | */ |
||
624 | public function is_declined() |
||
628 | |||
629 | |||
630 | /** |
||
631 | * is_incomplete - convenience method that returns TRUE if REG status ID == |
||
632 | * EEM_Registration::status_id_incomplete |
||
633 | * |
||
634 | * @return boolean |
||
635 | */ |
||
636 | public function is_incomplete() |
||
640 | |||
641 | |||
642 | /** |
||
643 | * Set Registration Date |
||
644 | * |
||
645 | * @param mixed ( int or string ) $REG_date Registration Date - Unix timestamp or string representation of |
||
646 | * Date |
||
647 | * @throws EE_Error |
||
648 | * @throws RuntimeException |
||
649 | */ |
||
650 | public function set_reg_date($REG_date = false) |
||
654 | |||
655 | |||
656 | /** |
||
657 | * Set final price owing for this registration after all ticket/price modifications |
||
658 | * |
||
659 | * @access public |
||
660 | * @param float $REG_final_price |
||
661 | * @throws EE_Error |
||
662 | * @throws RuntimeException |
||
663 | */ |
||
664 | public function set_final_price($REG_final_price = 0.00) |
||
668 | |||
669 | |||
670 | /** |
||
671 | * Set amount paid towards this registration's final price |
||
672 | * |
||
673 | * @access public |
||
674 | * @param float $REG_paid |
||
675 | * @throws EE_Error |
||
676 | * @throws RuntimeException |
||
677 | */ |
||
678 | public function set_paid($REG_paid = 0.00) |
||
682 | |||
683 | |||
684 | /** |
||
685 | * Attendee Is Going |
||
686 | * |
||
687 | * @param boolean $REG_att_is_going Attendee Is Going |
||
688 | * @throws EE_Error |
||
689 | * @throws RuntimeException |
||
690 | */ |
||
691 | public function set_att_is_going($REG_att_is_going = false) |
||
695 | |||
696 | |||
697 | /** |
||
698 | * Gets the related attendee |
||
699 | * |
||
700 | * @return EE_Attendee |
||
701 | * @throws EE_Error |
||
702 | */ |
||
703 | public function attendee() |
||
707 | |||
708 | |||
709 | /** |
||
710 | * get Event ID |
||
711 | */ |
||
712 | public function event_ID() |
||
716 | |||
717 | |||
718 | /** |
||
719 | * get Event ID |
||
720 | */ |
||
721 | public function event_name() |
||
730 | |||
731 | |||
732 | /** |
||
733 | * Fetches the event this registration is for |
||
734 | * |
||
735 | * @return EE_Event |
||
736 | * @throws EE_Error |
||
737 | */ |
||
738 | public function event_obj() |
||
742 | |||
743 | |||
744 | /** |
||
745 | * get Attendee ID |
||
746 | */ |
||
747 | public function attendee_ID() |
||
751 | |||
752 | |||
753 | /** |
||
754 | * get PHP Session ID |
||
755 | */ |
||
756 | public function session_ID() |
||
760 | |||
761 | |||
762 | /** |
||
763 | * Gets the string which represents the URL trigger for the receipt template in the message template system. |
||
764 | * |
||
765 | * @param string $messenger 'pdf' or 'html'. Default 'html'. |
||
766 | * @return string |
||
767 | */ |
||
768 | public function receipt_url($messenger = 'html') |
||
791 | |||
792 | |||
793 | /** |
||
794 | * Gets the string which represents the URL trigger for the invoice template in the message template system. |
||
795 | * |
||
796 | * @param string $messenger 'pdf' or 'html'. Default 'html'. |
||
797 | * @return string |
||
798 | * @throws EE_Error |
||
799 | */ |
||
800 | public function invoice_url($messenger = 'html') |
||
831 | |||
832 | |||
833 | /** |
||
834 | * get Registration URL Link |
||
835 | * |
||
836 | * @access public |
||
837 | * @return string |
||
838 | * @throws \EE_Error |
||
839 | */ |
||
840 | public function reg_url_link() |
||
844 | |||
845 | |||
846 | /** |
||
847 | * Echoes out invoice_url() |
||
848 | * |
||
849 | * @param string $type 'download','launch', or 'html' (default is 'launch') |
||
850 | * @return void |
||
851 | * @throws EE_Error |
||
852 | */ |
||
853 | public function e_invoice_url($type = 'launch') |
||
857 | |||
858 | |||
859 | /** |
||
860 | * Echoes out payment_overview_url |
||
861 | */ |
||
862 | public function e_payment_overview_url() |
||
866 | |||
867 | |||
868 | /** |
||
869 | * Gets the URL of the thank you page with this registration REG_url_link added as |
||
870 | * a query parameter |
||
871 | * |
||
872 | * @param bool $clear_session Set to true when you want to clear the session on revisiting the |
||
873 | * payment overview url. |
||
874 | * @return string |
||
875 | * @throws EE_Error |
||
876 | */ |
||
877 | View Code Duplication | public function payment_overview_url($clear_session = false) |
|
886 | |||
887 | |||
888 | /** |
||
889 | * Gets the URL of the thank you page with this registration REG_url_link added as |
||
890 | * a query parameter |
||
891 | * |
||
892 | * @return string |
||
893 | * @throws EE_Error |
||
894 | */ |
||
895 | View Code Duplication | public function edit_attendee_information_url() |
|
903 | |||
904 | |||
905 | /** |
||
906 | * Simply generates and returns the appropriate admin_url link to edit this registration |
||
907 | * |
||
908 | * @return string |
||
909 | * @throws EE_Error |
||
910 | */ |
||
911 | public function get_admin_edit_url() |
||
919 | |||
920 | |||
921 | /** |
||
922 | * is_primary_registrant? |
||
923 | */ |
||
924 | public function is_primary_registrant() |
||
928 | |||
929 | |||
930 | /** |
||
931 | * This returns the primary registration object for this registration group (which may be this object). |
||
932 | * |
||
933 | * @return EE_Registration |
||
934 | * @throws EE_Error |
||
935 | */ |
||
936 | public function get_primary_registration() |
||
952 | |||
953 | |||
954 | /** |
||
955 | * get Attendee Number |
||
956 | * |
||
957 | * @access public |
||
958 | */ |
||
959 | public function count() |
||
963 | |||
964 | |||
965 | /** |
||
966 | * get Group Size |
||
967 | */ |
||
968 | public function group_size() |
||
972 | |||
973 | |||
974 | /** |
||
975 | * get Registration Date |
||
976 | */ |
||
977 | public function date() |
||
981 | |||
982 | |||
983 | /** |
||
984 | * gets a pretty date |
||
985 | * |
||
986 | * @param string $date_format |
||
987 | * @param string $time_format |
||
988 | * @return string |
||
989 | * @throws EE_Error |
||
990 | */ |
||
991 | public function pretty_date($date_format = null, $time_format = null) |
||
995 | |||
996 | |||
997 | /** |
||
998 | * final_price |
||
999 | * the registration's share of the transaction total, so that the |
||
1000 | * sum of all the transaction's REG_final_prices equal the transaction's total |
||
1001 | * |
||
1002 | * @return float |
||
1003 | * @throws EE_Error |
||
1004 | */ |
||
1005 | public function final_price() |
||
1009 | |||
1010 | |||
1011 | /** |
||
1012 | * pretty_final_price |
||
1013 | * final price as formatted string, with correct decimal places and currency symbol |
||
1014 | * |
||
1015 | * @return string |
||
1016 | * @throws EE_Error |
||
1017 | */ |
||
1018 | public function pretty_final_price() |
||
1022 | |||
1023 | |||
1024 | /** |
||
1025 | * get paid (yeah) |
||
1026 | * |
||
1027 | * @return float |
||
1028 | * @throws EE_Error |
||
1029 | */ |
||
1030 | public function paid() |
||
1034 | |||
1035 | |||
1036 | /** |
||
1037 | * pretty_paid |
||
1038 | * |
||
1039 | * @return float |
||
1040 | * @throws EE_Error |
||
1041 | */ |
||
1042 | public function pretty_paid() |
||
1046 | |||
1047 | |||
1048 | /** |
||
1049 | * owes_monies_and_can_pay |
||
1050 | * whether or not this registration has monies owing and it's' status allows payment |
||
1051 | * |
||
1052 | * @param array $requires_payment |
||
1053 | * @return bool |
||
1054 | * @throws EE_Error |
||
1055 | */ |
||
1056 | public function owes_monies_and_can_pay($requires_payment = array()) |
||
1071 | |||
1072 | |||
1073 | /** |
||
1074 | * Prints out the return value of $this->pretty_status() |
||
1075 | * |
||
1076 | * @param bool $show_icons |
||
1077 | * @return void |
||
1078 | * @throws EE_Error |
||
1079 | */ |
||
1080 | public function e_pretty_status($show_icons = false) |
||
1084 | |||
1085 | |||
1086 | /** |
||
1087 | * Returns a nice version of the status for displaying to customers |
||
1088 | * |
||
1089 | * @param bool $show_icons |
||
1090 | * @return string |
||
1091 | * @throws EE_Error |
||
1092 | */ |
||
1093 | public function pretty_status($show_icons = false) |
||
1140 | |||
1141 | |||
1142 | /** |
||
1143 | * get Attendee Is Going |
||
1144 | */ |
||
1145 | public function att_is_going() |
||
1149 | |||
1150 | |||
1151 | /** |
||
1152 | * Gets related answers |
||
1153 | * |
||
1154 | * @param array $query_params like EEM_Base::get_all |
||
1155 | * @return EE_Answer[] |
||
1156 | * @throws EE_Error |
||
1157 | */ |
||
1158 | public function answers($query_params = null) |
||
1162 | |||
1163 | |||
1164 | /** |
||
1165 | * Gets the registration's answer value to the specified question |
||
1166 | * (either the question's ID or a question object) |
||
1167 | * |
||
1168 | * @param EE_Question|int $question |
||
1169 | * @param bool $pretty_value |
||
1170 | * @return array|string if pretty_value= true, the result will always be a string |
||
1171 | * (because the answer might be an array of answer values, so passing pretty_value=true |
||
1172 | * will convert it into some kind of string) |
||
1173 | * @throws EE_Error |
||
1174 | */ |
||
1175 | public function answer_value_to_question($question, $pretty_value = true) |
||
1180 | |||
1181 | |||
1182 | /** |
||
1183 | * question_groups |
||
1184 | * returns an array of EE_Question_Group objects for this registration |
||
1185 | * |
||
1186 | * @return EE_Question_Group[] |
||
1187 | * @throws EE_Error |
||
1188 | * @throws EntityNotFoundException |
||
1189 | */ |
||
1190 | public function question_groups() |
||
1205 | |||
1206 | |||
1207 | /** |
||
1208 | * count_question_groups |
||
1209 | * returns a count of the number of EE_Question_Group objects for this registration |
||
1210 | * |
||
1211 | * @return int |
||
1212 | * @throws EE_Error |
||
1213 | * @throws EntityNotFoundException |
||
1214 | */ |
||
1215 | public function count_question_groups() |
||
1230 | |||
1231 | |||
1232 | /** |
||
1233 | * Returns the registration date in the 'standard' string format |
||
1234 | * (function may be improved in the future to allow for different formats and timezones) |
||
1235 | * |
||
1236 | * @return string |
||
1237 | * @throws EE_Error |
||
1238 | */ |
||
1239 | public function reg_date() |
||
1243 | |||
1244 | |||
1245 | /** |
||
1246 | * Gets the datetime-ticket for this registration (ie, it can be used to isolate |
||
1247 | * the ticket this registration purchased, or the datetime they have registered |
||
1248 | * to attend) |
||
1249 | * |
||
1250 | * @return EE_Datetime_Ticket |
||
1251 | * @throws EE_Error |
||
1252 | */ |
||
1253 | public function datetime_ticket() |
||
1257 | |||
1258 | |||
1259 | /** |
||
1260 | * Sets the registration's datetime_ticket. |
||
1261 | * |
||
1262 | * @param EE_Datetime_Ticket $datetime_ticket |
||
1263 | * @return EE_Datetime_Ticket |
||
1264 | * @throws EE_Error |
||
1265 | */ |
||
1266 | public function set_datetime_ticket($datetime_ticket) |
||
1270 | |||
1271 | /** |
||
1272 | * Gets deleted |
||
1273 | * |
||
1274 | * @return bool |
||
1275 | * @throws EE_Error |
||
1276 | */ |
||
1277 | public function deleted() |
||
1281 | |||
1282 | /** |
||
1283 | * Sets deleted |
||
1284 | * |
||
1285 | * @param boolean $deleted |
||
1286 | * @return bool |
||
1287 | * @throws EE_Error |
||
1288 | * @throws RuntimeException |
||
1289 | */ |
||
1290 | public function set_deleted($deleted) |
||
1298 | |||
1299 | |||
1300 | /** |
||
1301 | * Get the status object of this object |
||
1302 | * |
||
1303 | * @return EE_Status |
||
1304 | * @throws EE_Error |
||
1305 | */ |
||
1306 | public function status_obj() |
||
1310 | |||
1311 | |||
1312 | /** |
||
1313 | * Returns the number of times this registration has checked into any of the datetimes |
||
1314 | * its available for |
||
1315 | * |
||
1316 | * @return int |
||
1317 | * @throws EE_Error |
||
1318 | */ |
||
1319 | public function count_checkins() |
||
1323 | |||
1324 | |||
1325 | /** |
||
1326 | * Returns the number of current Check-ins this registration is checked into for any of the datetimes the |
||
1327 | * registration is for. Note, this is ONLY checked in (does not include checkedout) |
||
1328 | * |
||
1329 | * @return int |
||
1330 | * @throws EE_Error |
||
1331 | */ |
||
1332 | public function count_checkins_not_checkedout() |
||
1336 | |||
1337 | |||
1338 | /** |
||
1339 | * The purpose of this method is simply to check whether this registration can checkin to the given datetime. |
||
1340 | * |
||
1341 | * @param int | EE_Datetime $DTT_OR_ID The datetime the registration is being checked against |
||
1342 | * @param bool $check_approved This is used to indicate whether the caller wants can_checkin to also |
||
1343 | * consider registration status as well as datetime access. |
||
1344 | * @return bool |
||
1345 | * @throws EE_Error |
||
1346 | */ |
||
1347 | public function can_checkin($DTT_OR_ID, $check_approved = true) |
||
1369 | |||
1370 | |||
1371 | /** |
||
1372 | * This method verifies whether the user can checkin for the given datetime considering the max uses value set on |
||
1373 | * the ticket. To do this, a query is done to get the count of the datetime records already checked into. If the |
||
1374 | * datetime given does not have a check-in record and checking in for that datetime will exceed the allowed uses, |
||
1375 | * then return false. Otherwise return true. |
||
1376 | * |
||
1377 | * @param int | EE_Datetime $DTT_OR_ID The datetime the registration is being checked against |
||
1378 | * @return bool true means can checkin. false means cannot checkin. |
||
1379 | * @throws EE_Error |
||
1380 | */ |
||
1381 | public function verify_can_checkin_against_TKT_uses($DTT_OR_ID) |
||
1427 | |||
1428 | |||
1429 | /** |
||
1430 | * toggle Check-in status for this registration |
||
1431 | * Check-ins are toggled in the following order: |
||
1432 | * never checked in -> checked in |
||
1433 | * checked in -> checked out |
||
1434 | * checked out -> checked in |
||
1435 | * |
||
1436 | * @param int $DTT_ID include specific datetime to toggle Check-in for. |
||
1437 | * If not included or null, then it is assumed latest datetime is being toggled. |
||
1438 | * @param bool $verify If true then can_checkin() is used to verify whether the person |
||
1439 | * can be checked in or not. Otherwise this forces change in checkin status. |
||
1440 | * @return bool|int the chk_in status toggled to OR false if nothing got changed. |
||
1441 | * @throws EE_Error |
||
1442 | */ |
||
1443 | public function toggle_checkin_status($DTT_ID = null, $verify = false) |
||
1444 | { |
||
1445 | if (empty($DTT_ID)) { |
||
1446 | $datetime = $this->get_latest_related_datetime(); |
||
1447 | $DTT_ID = $datetime instanceof EE_Datetime ? $datetime->ID() : 0; |
||
1448 | // verify the registration can checkin for the given DTT_ID |
||
1449 | } elseif (! $this->can_checkin($DTT_ID, $verify)) { |
||
1450 | EE_Error::add_error( |
||
1451 | sprintf( |
||
1452 | esc_html__( |
||
1453 | 'The given registration (ID:%1$d) can not be checked in to the given DTT_ID (%2$d), because the registration does not have access', |
||
1454 | 'event_espresso' |
||
1455 | ), |
||
1456 | $this->ID(), |
||
1457 | $DTT_ID |
||
1458 | ), |
||
1459 | __FILE__, |
||
1460 | __FUNCTION__, |
||
1461 | __LINE__ |
||
1462 | ); |
||
1463 | return false; |
||
1464 | } |
||
1465 | $status_paths = array( |
||
1466 | EE_Checkin::status_checked_never => EE_Checkin::status_checked_in, |
||
1467 | EE_Checkin::status_checked_in => EE_Checkin::status_checked_out, |
||
1468 | EE_Checkin::status_checked_out => EE_Checkin::status_checked_in, |
||
1469 | ); |
||
1470 | //start by getting the current status so we know what status we'll be changing to. |
||
1471 | $cur_status = $this->check_in_status_for_datetime($DTT_ID, null); |
||
1472 | $status_to = $status_paths[$cur_status]; |
||
1473 | // database only records true for checked IN or false for checked OUT |
||
1474 | // no record ( null ) means checked in NEVER, but we obviously don't save that |
||
1475 | $new_status = $status_to === EE_Checkin::status_checked_in ? true : false; |
||
1476 | // add relation - note Check-ins are always creating new rows |
||
1477 | // because we are keeping track of Check-ins over time. |
||
1478 | // Eventually we'll probably want to show a list table |
||
1479 | // for the individual Check-ins so that they can be managed. |
||
1480 | $checkin = EE_Checkin::new_instance(array( |
||
1481 | 'REG_ID' => $this->ID(), |
||
1482 | 'DTT_ID' => $DTT_ID, |
||
1483 | 'CHK_in' => $new_status, |
||
1484 | )); |
||
1485 | // if the record could not be saved then return false |
||
1486 | if ($checkin->save() === 0) { |
||
1487 | if (WP_DEBUG) { |
||
1488 | global $wpdb; |
||
1489 | $error = sprintf( |
||
1490 | esc_html__( |
||
1491 | 'Registration check in update failed because of the following database error: %1$s%2$s', |
||
1492 | 'event_espresso' |
||
1493 | ), |
||
1494 | '<br />', |
||
1495 | $wpdb->last_error |
||
1496 | ); |
||
1497 | } else { |
||
1498 | $error = esc_html__( |
||
1499 | 'Registration check in update failed because of an unknown database error', |
||
1500 | 'event_espresso' |
||
1501 | ); |
||
1502 | } |
||
1503 | EE_Error::add_error($error, __FILE__, __FUNCTION__, __LINE__); |
||
1504 | return false; |
||
1505 | } |
||
1506 | return $status_to; |
||
1507 | } |
||
1508 | |||
1509 | |||
1510 | /** |
||
1511 | * Returns the latest datetime related to this registration (via the ticket attached to the registration). |
||
1512 | * "Latest" is defined by the `DTT_EVT_start` column. |
||
1513 | * |
||
1514 | * @return EE_Datetime|null |
||
1515 | * @throws \EE_Error |
||
1516 | */ |
||
1517 | View Code Duplication | public function get_latest_related_datetime() |
|
1528 | |||
1529 | |||
1530 | /** |
||
1531 | * Returns the earliest datetime related to this registration (via the ticket attached to the registration). |
||
1532 | * "Earliest" is defined by the `DTT_EVT_start` column. |
||
1533 | * |
||
1534 | * @throws \EE_Error |
||
1535 | */ |
||
1536 | View Code Duplication | public function get_earliest_related_datetime() |
|
1547 | |||
1548 | |||
1549 | /** |
||
1550 | * This method simply returns the check-in status for this registration and the given datetime. |
||
1551 | * If neither the datetime nor the checkin values are provided as arguments, |
||
1552 | * then this will return the LATEST check-in status for the registration across all datetimes it belongs to. |
||
1553 | * |
||
1554 | * @param int $DTT_ID The ID of the datetime we're checking against |
||
1555 | * (if empty we'll get the primary datetime for |
||
1556 | * this registration (via event) and use it's ID); |
||
1557 | * @param EE_Checkin $checkin If present, we use the given checkin object rather than the dtt_id. |
||
1558 | * @return int Integer representing Check-in status. |
||
1559 | * @throws \EE_Error |
||
1560 | */ |
||
1561 | public function check_in_status_for_datetime($DTT_ID = 0, $checkin = null) |
||
1583 | |||
1584 | |||
1585 | /** |
||
1586 | * This method returns a localized message for the toggled Check-in message. |
||
1587 | * |
||
1588 | * @param int $DTT_ID include specific datetime to get the correct Check-in message. If not included or null, |
||
1589 | * then it is assumed Check-in for primary datetime was toggled. |
||
1590 | * @param bool $error This just flags that you want an error message returned. This is put in so that the error |
||
1591 | * message can be customized with the attendee name. |
||
1592 | * @return string internationalized message |
||
1593 | * @throws EE_Error |
||
1594 | */ |
||
1595 | public function get_checkin_msg($DTT_ID, $error = false) |
||
1620 | |||
1621 | |||
1622 | /** |
||
1623 | * Returns the related EE_Transaction to this registration |
||
1624 | * |
||
1625 | * @return EE_Transaction |
||
1626 | * @throws EE_Error |
||
1627 | * @throws EntityNotFoundException |
||
1628 | */ |
||
1629 | public function transaction() |
||
1637 | |||
1638 | |||
1639 | /** |
||
1640 | * get Registration Code |
||
1641 | */ |
||
1642 | public function reg_code() |
||
1646 | |||
1647 | |||
1648 | /** |
||
1649 | * get Transaction ID |
||
1650 | */ |
||
1651 | public function transaction_ID() |
||
1655 | |||
1656 | |||
1657 | /** |
||
1658 | * @return int |
||
1659 | * @throws EE_Error |
||
1660 | */ |
||
1661 | public function ticket_ID() |
||
1665 | |||
1666 | |||
1667 | /** |
||
1668 | * Set Registration Code |
||
1669 | * |
||
1670 | * @access public |
||
1671 | * @param string $REG_code Registration Code |
||
1672 | * @param boolean $use_default |
||
1673 | * @throws EE_Error |
||
1674 | */ |
||
1675 | public function set_reg_code($REG_code, $use_default = false) |
||
1696 | |||
1697 | |||
1698 | /** |
||
1699 | * Returns all other registrations in the same group as this registrant who have the same ticket option. |
||
1700 | * Note, if you want to just get all registrations in the same transaction (group), use: |
||
1701 | * $registration->transaction()->registrations(); |
||
1702 | * |
||
1703 | * @since 4.5.0 |
||
1704 | * @return EE_Registration[] or empty array if this isn't a group registration. |
||
1705 | * @throws EE_Error |
||
1706 | */ |
||
1707 | public function get_all_other_registrations_in_group() |
||
1722 | |||
1723 | /** |
||
1724 | * Return the link to the admin details for the object. |
||
1725 | * |
||
1726 | * @return string |
||
1727 | * @throws EE_Error |
||
1728 | */ |
||
1729 | View Code Duplication | public function get_admin_details_link() |
|
1741 | |||
1742 | /** |
||
1743 | * Returns the link to the editor for the object. Sometimes this is the same as the details. |
||
1744 | * |
||
1745 | * @return string |
||
1746 | * @throws EE_Error |
||
1747 | */ |
||
1748 | public function get_admin_edit_link() |
||
1752 | |||
1753 | /** |
||
1754 | * Returns the link to a settings page for the object. |
||
1755 | * |
||
1756 | * @return string |
||
1757 | * @throws EE_Error |
||
1758 | */ |
||
1759 | public function get_admin_settings_link() |
||
1763 | |||
1764 | /** |
||
1765 | * Returns the link to the "overview" for the object (typically the "list table" view). |
||
1766 | * |
||
1767 | * @return string |
||
1768 | */ |
||
1769 | public function get_admin_overview_link() |
||
1779 | |||
1780 | |||
1781 | /** |
||
1782 | * @param array $query_params |
||
1783 | * @return \EE_Registration[] |
||
1784 | * @throws \EE_Error |
||
1785 | */ |
||
1786 | public function payments($query_params = array()) |
||
1790 | |||
1791 | |||
1792 | /** |
||
1793 | * @param array $query_params |
||
1794 | * @return \EE_Registration_Payment[] |
||
1795 | * @throws \EE_Error |
||
1796 | */ |
||
1797 | public function registration_payments($query_params = array()) |
||
1801 | |||
1802 | |||
1803 | /** |
||
1804 | * This grabs the payment method corresponding to the last payment made for the amount owing on the registration. |
||
1805 | * Note: if there are no payments on the registration there will be no payment method returned. |
||
1806 | * |
||
1807 | * @return EE_Payment_Method|null |
||
1808 | */ |
||
1809 | public function payment_method() |
||
1813 | |||
1814 | |||
1815 | /** |
||
1816 | * @return \EE_Line_Item |
||
1817 | * @throws EntityNotFoundException |
||
1818 | * @throws \EE_Error |
||
1819 | */ |
||
1820 | public function ticket_line_item() |
||
1845 | |||
1846 | |||
1847 | /** |
||
1848 | * Soft Deletes this model object. |
||
1849 | * |
||
1850 | * @return boolean | int |
||
1851 | * @throws \RuntimeException |
||
1852 | * @throws \EE_Error |
||
1853 | */ |
||
1854 | public function delete() |
||
1861 | |||
1862 | |||
1863 | /** |
||
1864 | * Restores whatever the previous status was on a registration before it was trashed (if possible) |
||
1865 | * |
||
1866 | * @throws \EE_Error |
||
1867 | * @throws \RuntimeException |
||
1868 | */ |
||
1869 | public function restore() |
||
1882 | |||
1883 | |||
1884 | |||
1885 | /*************************** DEPRECATED ***************************/ |
||
1886 | |||
1887 | |||
1888 | /** |
||
1889 | * @deprecated |
||
1890 | * @since 4.7.0 |
||
1891 | * @access public |
||
1892 | */ |
||
1893 | public function price_paid() |
||
1900 | |||
1901 | |||
1902 | /** |
||
1903 | * @deprecated |
||
1904 | * @since 4.7.0 |
||
1905 | * @access public |
||
1906 | * @param float $REG_final_price |
||
1907 | * @throws EE_Error |
||
1908 | * @throws RuntimeException |
||
1909 | */ |
||
1910 | public function set_price_paid($REG_final_price = 0.00) |
||
1917 | |||
1918 | |||
1919 | /** |
||
1920 | * @deprecated |
||
1921 | * @since 4.7.0 |
||
1922 | * @return string |
||
1923 | * @throws EE_Error |
||
1924 | */ |
||
1925 | public function pretty_price_paid() |
||
1932 | |||
1933 | |||
1934 | /** |
||
1935 | * Gets the primary datetime related to this registration via the related Event to this registration |
||
1936 | * |
||
1937 | * @deprecated 4.9.17 |
||
1938 | * @return EE_Datetime |
||
1939 | * @throws EE_Error |
||
1940 | * @throws EntityNotFoundException |
||
1941 | */ |
||
1942 | public function get_related_primary_datetime() |
||
1955 | |||
1956 | |||
1957 | } |
||
1958 |
The break statement is not necessary if it is preceded for example by a return statement:
If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.