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_Ticket 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_Ticket, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
14 | class EE_Ticket extends EE_Soft_Delete_Base_Class implements EEI_Line_Item_Object, EEI_Event_Relation, EEI_Has_Icon |
||
15 | { |
||
16 | |||
17 | /** |
||
18 | * TicKet Sold out: |
||
19 | * constant used by ticket_status() to indicate that a ticket is sold out |
||
20 | * and no longer available for purchases |
||
21 | */ |
||
22 | const sold_out = 'TKS'; |
||
23 | |||
24 | /** |
||
25 | * TicKet Expired: |
||
26 | * constant used by ticket_status() to indicate that a ticket is expired |
||
27 | * and no longer available for purchase |
||
28 | */ |
||
29 | const expired = 'TKE'; |
||
30 | |||
31 | /** |
||
32 | * TicKet Archived: |
||
33 | * constant used by ticket_status() to indicate that a ticket is archived |
||
34 | * and no longer available for purchase |
||
35 | */ |
||
36 | const archived = 'TKA'; |
||
37 | |||
38 | /** |
||
39 | * TicKet Pending: |
||
40 | * constant used by ticket_status() to indicate that a ticket is pending |
||
41 | * and is NOT YET available for purchase |
||
42 | */ |
||
43 | const pending = 'TKP'; |
||
44 | |||
45 | /** |
||
46 | * TicKet On sale: |
||
47 | * constant used by ticket_status() to indicate that a ticket is On Sale |
||
48 | * and IS available for purchase |
||
49 | */ |
||
50 | const onsale = 'TKO'; |
||
51 | |||
52 | /** |
||
53 | * extra meta key for tracking ticket reservations |
||
54 | * |
||
55 | * @type string |
||
56 | */ |
||
57 | const META_KEY_TICKET_RESERVATIONS = 'ticket_reservations'; |
||
58 | |||
59 | /** |
||
60 | * cached result from method of the same name |
||
61 | * |
||
62 | * @var float $_ticket_total_with_taxes |
||
63 | */ |
||
64 | private $_ticket_total_with_taxes; |
||
65 | |||
66 | |||
67 | /** |
||
68 | * @param array $props_n_values incoming values |
||
69 | * @param string $timezone incoming timezone (if not set the timezone set for the website will be |
||
70 | * used.) |
||
71 | * @param array $date_formats incoming date_formats in an array where the first value is the |
||
72 | * date_format and the second value is the time format |
||
73 | * @return EE_Ticket |
||
74 | * @throws EE_Error |
||
75 | * @throws ReflectionException |
||
76 | */ |
||
77 | public static function new_instance($props_n_values = [], $timezone = null, $date_formats = []) |
||
82 | |||
83 | |||
84 | /** |
||
85 | * @param array $props_n_values incoming values from the database |
||
86 | * @param string $timezone incoming timezone as set by the model. If not set the timezone for |
||
87 | * the website will be used. |
||
88 | * @return EE_Ticket |
||
89 | * @throws EE_Error |
||
90 | * @throws ReflectionException |
||
91 | */ |
||
92 | public static function new_instance_from_db($props_n_values = [], $timezone = null) |
||
96 | |||
97 | |||
98 | /** |
||
99 | * @return bool |
||
100 | * @throws EE_Error |
||
101 | * @throws ReflectionException |
||
102 | */ |
||
103 | public function parent() |
||
107 | |||
108 | |||
109 | /** |
||
110 | * return if a ticket has quantities available for purchase |
||
111 | * |
||
112 | * @param int $DTT_ID the primary key for a particular datetime |
||
113 | * @return boolean |
||
114 | * @throws EE_Error |
||
115 | * @throws ReflectionException |
||
116 | */ |
||
117 | public function available($DTT_ID = 0) |
||
131 | |||
132 | |||
133 | /** |
||
134 | * Using the start date and end date this method calculates whether the ticket is On Sale, Pending, or Expired |
||
135 | * |
||
136 | * @param bool $display true = we'll return a localized string, otherwise we just return the value of the |
||
137 | * relevant status const |
||
138 | * @param bool | null $remaining if it is already known that tickets are available, then simply pass a bool to save |
||
139 | * further processing |
||
140 | * @return mixed status int if the display string isn't requested |
||
141 | * @throws EE_Error |
||
142 | * @throws ReflectionException |
||
143 | */ |
||
144 | public function ticket_status($display = false, $remaining = null) |
||
164 | |||
165 | |||
166 | /** |
||
167 | * The purpose of this method is to simply return a boolean for whether there are any tickets remaining for sale |
||
168 | * considering ALL the factors used for figuring that out. |
||
169 | * |
||
170 | * @access public |
||
171 | * @param int $DTT_ID if an int above 0 is included here then we get a specific dtt. |
||
172 | * @return boolean true = tickets remaining, false not. |
||
173 | * @throws EE_Error |
||
174 | * @throws ReflectionException |
||
175 | */ |
||
176 | public function is_remaining($DTT_ID = 0) |
||
187 | |||
188 | |||
189 | /** |
||
190 | * return the total number of tickets available for purchase |
||
191 | * |
||
192 | * @param int $DTT_ID the primary key for a particular datetime. |
||
193 | * set to 0 for all related datetimes |
||
194 | * @return int |
||
195 | * @throws EE_Error |
||
196 | * @throws ReflectionException |
||
197 | */ |
||
198 | public function remaining($DTT_ID = 0) |
||
202 | |||
203 | |||
204 | /** |
||
205 | * Gets min |
||
206 | * |
||
207 | * @return int |
||
208 | * @throws EE_Error |
||
209 | * @throws ReflectionException |
||
210 | */ |
||
211 | public function min() |
||
215 | |||
216 | |||
217 | /** |
||
218 | * return if a ticket is no longer available cause its available dates have expired. |
||
219 | * |
||
220 | * @return boolean |
||
221 | * @throws EE_Error |
||
222 | * @throws ReflectionException |
||
223 | */ |
||
224 | public function is_expired() |
||
228 | |||
229 | |||
230 | /** |
||
231 | * Return if a ticket is yet to go on sale or not |
||
232 | * |
||
233 | * @return boolean |
||
234 | * @throws EE_Error |
||
235 | * @throws ReflectionException |
||
236 | */ |
||
237 | public function is_pending() |
||
241 | |||
242 | |||
243 | /** |
||
244 | * Return if a ticket is on sale or not |
||
245 | * |
||
246 | * @return boolean |
||
247 | * @throws EE_Error |
||
248 | * @throws ReflectionException |
||
249 | */ |
||
250 | public function is_on_sale() |
||
254 | |||
255 | |||
256 | /** |
||
257 | * This returns the chronologically last datetime that this ticket is associated with |
||
258 | * |
||
259 | * @param string $date_format |
||
260 | * @param string $conjunction - conjunction junction what's your function ? this string joins the start date with |
||
261 | * the end date ie: Jan 01 "to" Dec 31 |
||
262 | * @return string |
||
263 | * @throws EE_Error |
||
264 | * @throws ReflectionException |
||
265 | */ |
||
266 | public function date_range($date_format = '', $conjunction = ' - ') |
||
278 | |||
279 | |||
280 | /** |
||
281 | * This returns the chronologically first datetime that this ticket is associated with |
||
282 | * |
||
283 | * @return EE_Datetime |
||
284 | * @throws EE_Error |
||
285 | * @throws ReflectionException |
||
286 | */ |
||
287 | public function first_datetime() |
||
292 | |||
293 | |||
294 | /** |
||
295 | * Gets all the datetimes this ticket can be used for attending. |
||
296 | * Unless otherwise specified, orders datetimes by start date. |
||
297 | * |
||
298 | * @param array $query_params @see |
||
299 | * https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md |
||
300 | * @return EE_Datetime[]|EE_Base_Class[] |
||
301 | * @throws EE_Error |
||
302 | * @throws ReflectionException |
||
303 | */ |
||
304 | public function datetimes($query_params = []) |
||
311 | |||
312 | |||
313 | /** |
||
314 | * This returns the chronologically last datetime that this ticket is associated with |
||
315 | * |
||
316 | * @return EE_Datetime |
||
317 | * @throws EE_Error |
||
318 | * @throws ReflectionException |
||
319 | */ |
||
320 | public function last_datetime() |
||
325 | |||
326 | |||
327 | /** |
||
328 | * This returns the total tickets sold depending on the given parameters. |
||
329 | * |
||
330 | * @param string $what Can be one of two options: 'ticket', 'datetime'. |
||
331 | * 'ticket' = total ticket sales for all datetimes this ticket is related to |
||
332 | * 'datetime' = total ticket sales for a specified datetime (required $dtt_id) |
||
333 | * 'datetime' = total ticket sales in the datetime_ticket table. |
||
334 | * If $dtt_id is not given then we return an array of sales indexed by datetime. |
||
335 | * If $dtt_id IS given then we return the tickets sold for that given datetime. |
||
336 | * @param int $dtt_id [optional] include the dtt_id with $what = 'datetime'. |
||
337 | * @return mixed (array|int) how many tickets have sold |
||
338 | * @throws EE_Error |
||
339 | * @throws ReflectionException |
||
340 | */ |
||
341 | public function tickets_sold($what = 'ticket', $dtt_id = null) |
||
371 | |||
372 | |||
373 | /** |
||
374 | * This returns an array indexed by datetime_id for tickets sold with this ticket. |
||
375 | * |
||
376 | * @return EE_Ticket[] |
||
377 | * @throws EE_Error |
||
378 | * @throws ReflectionException |
||
379 | */ |
||
380 | protected function _all_tickets_sold() |
||
393 | |||
394 | |||
395 | /** |
||
396 | * This returns the base price object for the ticket. |
||
397 | * |
||
398 | * @param bool $return_array whether to return as an array indexed by price id or just the object. |
||
399 | * @return EE_Price|EE_Base_Class|EE_Price[]|EE_Base_Class[] |
||
400 | * @throws EE_Error |
||
401 | * @throws ReflectionException |
||
402 | */ |
||
403 | public function base_price($return_array = false) |
||
410 | |||
411 | |||
412 | /** |
||
413 | * This returns ONLY the price modifiers for the ticket (i.e. no taxes or base price) |
||
414 | * |
||
415 | * @access public |
||
416 | * @return EE_Price[] |
||
417 | * @throws EE_Error |
||
418 | * @throws ReflectionException |
||
419 | */ |
||
420 | public function price_modifiers() |
||
432 | |||
433 | |||
434 | /** |
||
435 | * This returns ONLY the price modifiers for the ticket (i.e. no taxes or base price) |
||
436 | * |
||
437 | * @access public |
||
438 | * @return EE_Price[] |
||
439 | * @throws EE_Error |
||
440 | * @throws ReflectionException |
||
441 | */ |
||
442 | public function tax_price_modifiers() |
||
451 | |||
452 | |||
453 | /** |
||
454 | * Gets all the prices that combine to form the final price of this ticket |
||
455 | * |
||
456 | * @param array $query_params @see |
||
457 | * https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md |
||
458 | * @return EE_Price[]|EE_Base_Class[] |
||
459 | * @throws EE_Error |
||
460 | * @throws ReflectionException |
||
461 | */ |
||
462 | public function prices($query_params = []) |
||
466 | |||
467 | |||
468 | /** |
||
469 | * Gets all the ticket datetimes (ie, relations between datetimes and tickets) |
||
470 | * |
||
471 | * @param array $query_params @see |
||
472 | * https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md |
||
473 | * @return EE_Datetime_Ticket|EE_Base_Class[] |
||
474 | * @throws EE_Error |
||
475 | * @throws ReflectionException |
||
476 | */ |
||
477 | public function datetime_tickets($query_params = []) |
||
481 | |||
482 | |||
483 | /** |
||
484 | * Gets all the datetimes from the db ordered by DTT_order |
||
485 | * |
||
486 | * @param boolean $show_expired |
||
487 | * @param boolean $show_deleted |
||
488 | * @return EE_Datetime[] |
||
489 | * @throws EE_Error |
||
490 | * @throws ReflectionException |
||
491 | */ |
||
492 | public function datetimes_ordered($show_expired = true, $show_deleted = false) |
||
500 | |||
501 | |||
502 | /** |
||
503 | * Gets ID |
||
504 | * |
||
505 | * @return string |
||
506 | * @throws EE_Error |
||
507 | * @throws ReflectionException |
||
508 | */ |
||
509 | public function ID() |
||
513 | |||
514 | |||
515 | /** |
||
516 | * get the author of the ticket. |
||
517 | * |
||
518 | * @return int |
||
519 | * @throws EE_Error |
||
520 | * @throws ReflectionException |
||
521 | * @since 4.5.0 |
||
522 | */ |
||
523 | public function wp_user() |
||
527 | |||
528 | |||
529 | /** |
||
530 | * Gets the template for the ticket |
||
531 | * |
||
532 | * @return EE_Ticket_Template|EE_Base_Class |
||
533 | * @throws EE_Error |
||
534 | * @throws ReflectionException |
||
535 | */ |
||
536 | public function template() |
||
540 | |||
541 | |||
542 | /** |
||
543 | * Simply returns an array of EE_Price objects that are taxes. |
||
544 | * |
||
545 | * @return EE_Price[] |
||
546 | * @throws EE_Error |
||
547 | */ |
||
548 | public function get_ticket_taxes_for_admin() |
||
552 | |||
553 | |||
554 | /** |
||
555 | * @return float |
||
556 | * @throws EE_Error |
||
557 | * @throws ReflectionException |
||
558 | */ |
||
559 | public function ticket_price() |
||
563 | |||
564 | |||
565 | /** |
||
566 | * @return mixed |
||
567 | * @throws EE_Error |
||
568 | * @throws ReflectionException |
||
569 | */ |
||
570 | public function pretty_price() |
||
574 | |||
575 | |||
576 | /** |
||
577 | * @return bool |
||
578 | * @throws EE_Error |
||
579 | * @throws ReflectionException |
||
580 | */ |
||
581 | public function is_free() |
||
585 | |||
586 | |||
587 | /** |
||
588 | * get_ticket_total_with_taxes |
||
589 | * |
||
590 | * @param bool $no_cache |
||
591 | * @return float |
||
592 | * @throws EE_Error |
||
593 | * @throws ReflectionException |
||
594 | */ |
||
595 | public function get_ticket_total_with_taxes($no_cache = false) |
||
602 | |||
603 | |||
604 | /** |
||
605 | * @throws EE_Error |
||
606 | * @throws ReflectionException |
||
607 | */ |
||
608 | public function ensure_TKT_Price_correct() |
||
613 | |||
614 | |||
615 | /** |
||
616 | * @return float |
||
617 | * @throws EE_Error |
||
618 | * @throws ReflectionException |
||
619 | */ |
||
620 | public function get_ticket_subtotal() |
||
624 | |||
625 | |||
626 | /** |
||
627 | * Returns the total taxes applied to this ticket |
||
628 | * |
||
629 | * @return float |
||
630 | * @throws EE_Error |
||
631 | * @throws ReflectionException |
||
632 | */ |
||
633 | public function get_ticket_taxes_total_for_admin() |
||
637 | |||
638 | |||
639 | /** |
||
640 | * Sets name |
||
641 | * |
||
642 | * @param string $name |
||
643 | * @throws EE_Error |
||
644 | * @throws ReflectionException |
||
645 | */ |
||
646 | public function set_name($name) |
||
650 | |||
651 | |||
652 | /** |
||
653 | * Gets description |
||
654 | * |
||
655 | * @return string |
||
656 | * @throws EE_Error |
||
657 | * @throws ReflectionException |
||
658 | */ |
||
659 | public function description() |
||
663 | |||
664 | |||
665 | /** |
||
666 | * Sets description |
||
667 | * |
||
668 | * @param string $description |
||
669 | * @throws EE_Error |
||
670 | * @throws ReflectionException |
||
671 | */ |
||
672 | public function set_description($description) |
||
676 | |||
677 | |||
678 | /** |
||
679 | * Gets start_date |
||
680 | * |
||
681 | * @param string $date_format |
||
682 | * @param string $time_format |
||
683 | * @return string |
||
684 | * @throws EE_Error |
||
685 | * @throws ReflectionException |
||
686 | */ |
||
687 | public function start_date($date_format = '', $time_format = '') |
||
691 | |||
692 | |||
693 | /** |
||
694 | * Sets start_date |
||
695 | * |
||
696 | * @param string $start_date |
||
697 | * @return void |
||
698 | * @throws EE_Error |
||
699 | * @throws ReflectionException |
||
700 | */ |
||
701 | public function set_start_date($start_date) |
||
705 | |||
706 | |||
707 | /** |
||
708 | * Gets end_date |
||
709 | * |
||
710 | * @param string $date_format |
||
711 | * @param string $time_format |
||
712 | * @return string |
||
713 | * @throws EE_Error |
||
714 | * @throws ReflectionException |
||
715 | */ |
||
716 | public function end_date($date_format = '', $time_format = '') |
||
720 | |||
721 | |||
722 | /** |
||
723 | * Sets end_date |
||
724 | * |
||
725 | * @param string $end_date |
||
726 | * @return void |
||
727 | * @throws EE_Error |
||
728 | * @throws ReflectionException |
||
729 | */ |
||
730 | public function set_end_date($end_date) |
||
734 | |||
735 | |||
736 | /** |
||
737 | * Sets sell until time |
||
738 | * |
||
739 | * @param string $time a string representation of the sell until time (ex 9am or 7:30pm) |
||
740 | * @throws EE_Error |
||
741 | * @throws ReflectionException |
||
742 | * @since 4.5.0 |
||
743 | */ |
||
744 | public function set_end_time($time) |
||
748 | |||
749 | |||
750 | /** |
||
751 | * Sets min |
||
752 | * |
||
753 | * @param int $min |
||
754 | * @return void |
||
755 | * @throws EE_Error |
||
756 | * @throws ReflectionException |
||
757 | */ |
||
758 | public function set_min($min) |
||
762 | |||
763 | |||
764 | /** |
||
765 | * Gets max |
||
766 | * |
||
767 | * @return int |
||
768 | * @throws EE_Error |
||
769 | * @throws ReflectionException |
||
770 | */ |
||
771 | public function max() |
||
775 | |||
776 | |||
777 | /** |
||
778 | * Sets max |
||
779 | * |
||
780 | * @param int $max |
||
781 | * @return void |
||
782 | * @throws EE_Error |
||
783 | * @throws ReflectionException |
||
784 | */ |
||
785 | public function set_max($max) |
||
789 | |||
790 | |||
791 | /** |
||
792 | * Sets price |
||
793 | * |
||
794 | * @param float $price |
||
795 | * @return void |
||
796 | * @throws EE_Error |
||
797 | * @throws ReflectionException |
||
798 | */ |
||
799 | public function set_price($price) |
||
803 | |||
804 | |||
805 | /** |
||
806 | * Gets sold |
||
807 | * |
||
808 | * @return int |
||
809 | * @throws EE_Error |
||
810 | * @throws ReflectionException |
||
811 | */ |
||
812 | public function sold() |
||
816 | |||
817 | |||
818 | /** |
||
819 | * Sets sold |
||
820 | * |
||
821 | * @param int $sold |
||
822 | * @return void |
||
823 | * @throws EE_Error |
||
824 | * @throws ReflectionException |
||
825 | */ |
||
826 | public function set_sold($sold) |
||
832 | |||
833 | |||
834 | /** |
||
835 | * Increments sold by amount passed by $qty AND decrements the reserved count on both this ticket and its |
||
836 | * associated datetimes. |
||
837 | * |
||
838 | * @param int $qty |
||
839 | * @return boolean |
||
840 | * @throws EE_Error |
||
841 | * @throws InvalidArgumentException |
||
842 | * @throws InvalidDataTypeException |
||
843 | * @throws InvalidInterfaceException |
||
844 | * @throws ReflectionException |
||
845 | * @since 4.9.80.p |
||
846 | */ |
||
847 | View Code Duplication | public function increaseSold($qty = 1) |
|
869 | |||
870 | |||
871 | /** |
||
872 | * On each datetime related to this ticket, increases its sold count and decreases its reserved count by $qty. |
||
873 | * |
||
874 | * @param int $qty positive or negative. Positive means to increase sold counts (and decrease reserved |
||
875 | * counts), Negative means to decreases old counts (and increase reserved counts). |
||
876 | * @param EE_Datetime[] $datetimes |
||
877 | * @throws EE_Error |
||
878 | * @throws InvalidArgumentException |
||
879 | * @throws InvalidDataTypeException |
||
880 | * @throws InvalidInterfaceException |
||
881 | * @throws ReflectionException |
||
882 | * @since 4.9.80.p |
||
883 | */ |
||
884 | protected function increaseSoldForDatetimes($qty, array $datetimes = []) |
||
891 | |||
892 | |||
893 | /** |
||
894 | * Decrements (subtracts) sold by amount passed by $qty on both the ticket and its related datetimes directly in the |
||
895 | * DB and then updates the model objects. |
||
896 | * Does not affect the reserved counts. |
||
897 | * |
||
898 | * @param int $qty |
||
899 | * @return boolean |
||
900 | * @throws EE_Error |
||
901 | * @throws InvalidArgumentException |
||
902 | * @throws InvalidDataTypeException |
||
903 | * @throws InvalidInterfaceException |
||
904 | * @throws ReflectionException |
||
905 | * @since 4.9.80.p |
||
906 | */ |
||
907 | View Code Duplication | public function decreaseSold($qty = 1) |
|
925 | |||
926 | |||
927 | /** |
||
928 | * Decreases sold on related datetimes |
||
929 | * |
||
930 | * @param int $qty |
||
931 | * @param EE_Datetime[] $datetimes |
||
932 | * @return void |
||
933 | * @throws EE_Error |
||
934 | * @throws InvalidArgumentException |
||
935 | * @throws InvalidDataTypeException |
||
936 | * @throws InvalidInterfaceException |
||
937 | * @throws ReflectionException |
||
938 | * @since 4.9.80.p |
||
939 | */ |
||
940 | View Code Duplication | protected function decreaseSoldForDatetimes($qty = 1, array $datetimes = []) |
|
951 | |||
952 | |||
953 | /** |
||
954 | * Gets qty of reserved tickets |
||
955 | * |
||
956 | * @return int |
||
957 | * @throws EE_Error |
||
958 | * @throws ReflectionException |
||
959 | */ |
||
960 | public function reserved() |
||
964 | |||
965 | |||
966 | /** |
||
967 | * Sets reserved |
||
968 | * |
||
969 | * @param int $reserved |
||
970 | * @return void |
||
971 | * @throws EE_Error |
||
972 | * @throws ReflectionException |
||
973 | */ |
||
974 | public function set_reserved($reserved) |
||
980 | |||
981 | |||
982 | /** |
||
983 | * Increments reserved by amount passed by $qty, and persists it immediately to the database. |
||
984 | * |
||
985 | * @param int $qty |
||
986 | * @param string $source |
||
987 | * @return bool whether we successfully reserved the ticket or not. |
||
988 | * @throws EE_Error |
||
989 | * @throws InvalidArgumentException |
||
990 | * @throws ReflectionException |
||
991 | * @throws InvalidDataTypeException |
||
992 | * @throws InvalidInterfaceException |
||
993 | * @since 4.9.80.p |
||
994 | */ |
||
995 | public function increaseReserved($qty = 1, $source = 'unknown') |
||
1029 | |||
1030 | |||
1031 | /** |
||
1032 | * Increases reserved counts on related datetimes |
||
1033 | * |
||
1034 | * @param int $qty |
||
1035 | * @param EE_Datetime[] $datetimes |
||
1036 | * @return boolean indicating success |
||
1037 | * @throws EE_Error |
||
1038 | * @throws InvalidArgumentException |
||
1039 | * @throws InvalidDataTypeException |
||
1040 | * @throws InvalidInterfaceException |
||
1041 | * @throws ReflectionException |
||
1042 | * @since 4.9.80.p |
||
1043 | */ |
||
1044 | protected function increaseReservedForDatetimes($qty = 1, array $datetimes = []) |
||
1069 | |||
1070 | |||
1071 | /** |
||
1072 | * Decrements (subtracts) reserved by amount passed by $qty, and persists it immediately to the database. |
||
1073 | * |
||
1074 | * @param int $qty |
||
1075 | * @param bool $adjust_datetimes |
||
1076 | * @param string $source |
||
1077 | * @return boolean |
||
1078 | * @throws EE_Error |
||
1079 | * @throws InvalidArgumentException |
||
1080 | * @throws ReflectionException |
||
1081 | * @throws InvalidDataTypeException |
||
1082 | * @throws InvalidInterfaceException |
||
1083 | * @since 4.9.80.p |
||
1084 | */ |
||
1085 | public function decreaseReserved($qty = 1, $adjust_datetimes = true, $source = 'unknown') |
||
1106 | |||
1107 | |||
1108 | /** |
||
1109 | * Decreases the reserved count on the specified datetimes. |
||
1110 | * |
||
1111 | * @param int $qty |
||
1112 | * @param EE_Datetime[] $datetimes |
||
1113 | * @throws EE_Error |
||
1114 | * @throws InvalidArgumentException |
||
1115 | * @throws ReflectionException |
||
1116 | * @throws InvalidDataTypeException |
||
1117 | * @throws InvalidInterfaceException |
||
1118 | * @since 4.9.80.p |
||
1119 | */ |
||
1120 | View Code Duplication | protected function decreaseReservedForDatetimes($qty = 1, array $datetimes = []) |
|
1129 | |||
1130 | |||
1131 | /** |
||
1132 | * Gets ticket quantity |
||
1133 | * |
||
1134 | * @param string $context ticket quantity is somewhat subjective depending on the exact information sought |
||
1135 | * therefore $context can be one of three values: '', 'reg_limit', or 'saleable' |
||
1136 | * '' (default) quantity is the actual db value for TKT_qty, unaffected by other objects |
||
1137 | * REG LIMIT: caps qty based on DTT_reg_limit for ALL related datetimes |
||
1138 | * SALEABLE: also considers datetime sold and returns zero if ANY DTT is sold out, and |
||
1139 | * is therefore the truest measure of tickets that can be purchased at the moment |
||
1140 | * @return int |
||
1141 | * @throws EE_Error |
||
1142 | * @throws ReflectionException |
||
1143 | */ |
||
1144 | public function qty($context = '') |
||
1155 | |||
1156 | |||
1157 | /** |
||
1158 | * Gets ticket quantity |
||
1159 | * |
||
1160 | * @param string $context ticket quantity is somewhat subjective depending on the exact information sought |
||
1161 | * therefore $context can be one of two values: 'reg_limit', or 'saleable' |
||
1162 | * REG LIMIT: caps qty based on DTT_reg_limit for ALL related datetimes |
||
1163 | * SALEABLE: also considers datetime sold and returns zero if ANY DTT is sold out, and |
||
1164 | * is therefore the truest measure of tickets that can be purchased at the moment |
||
1165 | * @param int $DTT_ID the primary key for a particular datetime. |
||
1166 | * set to 0 for all related datetimes |
||
1167 | * @return int |
||
1168 | * @throws EE_Error |
||
1169 | * @throws ReflectionException |
||
1170 | */ |
||
1171 | public function real_quantity_on_ticket($context = 'reg_limit', $DTT_ID = 0) |
||
1232 | |||
1233 | |||
1234 | /** |
||
1235 | * Sets qty - IMPORTANT!!! Does NOT allow QTY to be set higher than the lowest reg limit of any related datetimes |
||
1236 | * |
||
1237 | * @param int $qty |
||
1238 | * @return void |
||
1239 | * @throws EE_Error |
||
1240 | * @throws ReflectionException |
||
1241 | */ |
||
1242 | public function set_qty($qty) |
||
1252 | |||
1253 | |||
1254 | /** |
||
1255 | * Gets uses |
||
1256 | * |
||
1257 | * @return int |
||
1258 | * @throws EE_Error |
||
1259 | * @throws ReflectionException |
||
1260 | */ |
||
1261 | public function uses() |
||
1265 | |||
1266 | |||
1267 | /** |
||
1268 | * Sets uses |
||
1269 | * |
||
1270 | * @param int $uses |
||
1271 | * @return void |
||
1272 | * @throws EE_Error |
||
1273 | * @throws ReflectionException |
||
1274 | */ |
||
1275 | public function set_uses($uses) |
||
1279 | |||
1280 | |||
1281 | /** |
||
1282 | * returns whether ticket is required or not. |
||
1283 | * |
||
1284 | * @return boolean |
||
1285 | * @throws EE_Error |
||
1286 | * @throws ReflectionException |
||
1287 | */ |
||
1288 | public function required() |
||
1292 | |||
1293 | |||
1294 | /** |
||
1295 | * sets the TKT_required property |
||
1296 | * |
||
1297 | * @param boolean $required |
||
1298 | * @return void |
||
1299 | * @throws EE_Error |
||
1300 | * @throws ReflectionException |
||
1301 | */ |
||
1302 | public function set_required($required) |
||
1306 | |||
1307 | |||
1308 | /** |
||
1309 | * Gets taxable |
||
1310 | * |
||
1311 | * @return boolean |
||
1312 | * @throws EE_Error |
||
1313 | * @throws ReflectionException |
||
1314 | */ |
||
1315 | public function taxable() |
||
1319 | |||
1320 | |||
1321 | /** |
||
1322 | * Sets taxable |
||
1323 | * |
||
1324 | * @param boolean $taxable |
||
1325 | * @return void |
||
1326 | * @throws EE_Error |
||
1327 | * @throws ReflectionException |
||
1328 | */ |
||
1329 | public function set_taxable($taxable) |
||
1333 | |||
1334 | |||
1335 | /** |
||
1336 | * Gets is_default |
||
1337 | * |
||
1338 | * @return boolean |
||
1339 | * @throws EE_Error |
||
1340 | * @throws ReflectionException |
||
1341 | */ |
||
1342 | public function is_default() |
||
1346 | |||
1347 | |||
1348 | /** |
||
1349 | * Sets is_default |
||
1350 | * |
||
1351 | * @param boolean $is_default |
||
1352 | * @return void |
||
1353 | * @throws EE_Error |
||
1354 | * @throws ReflectionException |
||
1355 | */ |
||
1356 | public function set_is_default($is_default) |
||
1360 | |||
1361 | |||
1362 | /** |
||
1363 | * Gets order |
||
1364 | * |
||
1365 | * @return int |
||
1366 | * @throws EE_Error |
||
1367 | * @throws ReflectionException |
||
1368 | */ |
||
1369 | public function order() |
||
1373 | |||
1374 | |||
1375 | /** |
||
1376 | * Sets order |
||
1377 | * |
||
1378 | * @param int $order |
||
1379 | * @return void |
||
1380 | * @throws EE_Error |
||
1381 | * @throws ReflectionException |
||
1382 | */ |
||
1383 | public function set_order($order) |
||
1387 | |||
1388 | |||
1389 | /** |
||
1390 | * Gets row |
||
1391 | * |
||
1392 | * @return int |
||
1393 | * @throws EE_Error |
||
1394 | * @throws ReflectionException |
||
1395 | */ |
||
1396 | public function row() |
||
1400 | |||
1401 | |||
1402 | /** |
||
1403 | * Sets row |
||
1404 | * |
||
1405 | * @param int $row |
||
1406 | * @return void |
||
1407 | * @throws EE_Error |
||
1408 | * @throws ReflectionException |
||
1409 | */ |
||
1410 | public function set_row($row) |
||
1414 | |||
1415 | |||
1416 | /** |
||
1417 | * Gets deleted |
||
1418 | * |
||
1419 | * @return boolean |
||
1420 | * @throws EE_Error |
||
1421 | * @throws ReflectionException |
||
1422 | */ |
||
1423 | public function deleted() |
||
1427 | |||
1428 | |||
1429 | /** |
||
1430 | * Sets deleted |
||
1431 | * |
||
1432 | * @param boolean $deleted |
||
1433 | * @return void |
||
1434 | * @throws EE_Error |
||
1435 | * @throws ReflectionException |
||
1436 | */ |
||
1437 | public function set_deleted($deleted) |
||
1441 | |||
1442 | |||
1443 | /** |
||
1444 | * Gets parent |
||
1445 | * |
||
1446 | * @return int |
||
1447 | * @throws EE_Error |
||
1448 | * @throws ReflectionException |
||
1449 | */ |
||
1450 | public function parent_ID() |
||
1454 | |||
1455 | |||
1456 | /** |
||
1457 | * Sets parent |
||
1458 | * |
||
1459 | * @param int $parent |
||
1460 | * @return void |
||
1461 | * @throws EE_Error |
||
1462 | * @throws ReflectionException |
||
1463 | */ |
||
1464 | public function set_parent_ID($parent) |
||
1468 | |||
1469 | |||
1470 | /** |
||
1471 | * @return boolean |
||
1472 | * @throws EE_Error |
||
1473 | * @throws InvalidArgumentException |
||
1474 | * @throws InvalidDataTypeException |
||
1475 | * @throws InvalidInterfaceException |
||
1476 | * @throws ReflectionException |
||
1477 | */ |
||
1478 | public function reverse_calculate() |
||
1482 | |||
1483 | |||
1484 | /** |
||
1485 | * @param boolean $reverse_calculate |
||
1486 | * @throws EE_Error |
||
1487 | * @throws InvalidArgumentException |
||
1488 | * @throws InvalidDataTypeException |
||
1489 | * @throws InvalidInterfaceException |
||
1490 | * @throws ReflectionException |
||
1491 | */ |
||
1492 | public function set_reverse_calculate($reverse_calculate) |
||
1496 | |||
1497 | |||
1498 | /** |
||
1499 | * Gets a string which is handy for showing in gateways etc that describes the ticket. |
||
1500 | * |
||
1501 | * @return string |
||
1502 | * @throws EE_Error |
||
1503 | * @throws ReflectionException |
||
1504 | */ |
||
1505 | public function name_and_info() |
||
1513 | |||
1514 | |||
1515 | /** |
||
1516 | * Gets name |
||
1517 | * |
||
1518 | * @return string |
||
1519 | * @throws EE_Error |
||
1520 | * @throws ReflectionException |
||
1521 | */ |
||
1522 | public function name() |
||
1526 | |||
1527 | |||
1528 | /** |
||
1529 | * Gets price |
||
1530 | * |
||
1531 | * @return float |
||
1532 | * @throws EE_Error |
||
1533 | * @throws ReflectionException |
||
1534 | */ |
||
1535 | public function price() |
||
1539 | |||
1540 | |||
1541 | /** |
||
1542 | * Gets all the registrations for this ticket |
||
1543 | * |
||
1544 | * @param array $query_params @see |
||
1545 | * https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md |
||
1546 | * @return EE_Registration[]|EE_Base_Class[] |
||
1547 | * @throws EE_Error |
||
1548 | * @throws ReflectionException |
||
1549 | */ |
||
1550 | public function registrations($query_params = []) |
||
1554 | |||
1555 | |||
1556 | /** |
||
1557 | * Updates the TKT_sold attribute (and saves) based on the number of APPROVED registrations for this ticket. |
||
1558 | * |
||
1559 | * @return int |
||
1560 | * @throws EE_Error |
||
1561 | * @throws ReflectionException |
||
1562 | */ |
||
1563 | View Code Duplication | public function update_tickets_sold() |
|
1577 | |||
1578 | |||
1579 | /** |
||
1580 | * Counts the registrations for this ticket |
||
1581 | * |
||
1582 | * @param array $query_params @see |
||
1583 | * https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md |
||
1584 | * @return int |
||
1585 | * @throws EE_Error |
||
1586 | * @throws ReflectionException |
||
1587 | */ |
||
1588 | public function count_registrations($query_params = []) |
||
1592 | |||
1593 | |||
1594 | /** |
||
1595 | * Implementation for EEI_Has_Icon interface method. |
||
1596 | * |
||
1597 | * @return string |
||
1598 | * @see EEI_Visual_Representation for comments |
||
1599 | */ |
||
1600 | public function get_icon() |
||
1604 | |||
1605 | |||
1606 | /** |
||
1607 | * Implementation of the EEI_Event_Relation interface method |
||
1608 | * |
||
1609 | * @return EE_Event |
||
1610 | * @throws EE_Error |
||
1611 | * @throws UnexpectedEntityException |
||
1612 | * @throws ReflectionException |
||
1613 | * @see EEI_Event_Relation for comments |
||
1614 | */ |
||
1615 | public function get_related_event() |
||
1642 | |||
1643 | |||
1644 | /** |
||
1645 | * Implementation of the EEI_Event_Relation interface method |
||
1646 | * |
||
1647 | * @return string |
||
1648 | * @throws UnexpectedEntityException |
||
1649 | * @throws EE_Error |
||
1650 | * @throws ReflectionException |
||
1651 | * @see EEI_Event_Relation for comments |
||
1652 | */ |
||
1653 | public function get_event_name() |
||
1658 | |||
1659 | |||
1660 | /** |
||
1661 | * Implementation of the EEI_Event_Relation interface method |
||
1662 | * |
||
1663 | * @return int |
||
1664 | * @throws UnexpectedEntityException |
||
1665 | * @throws EE_Error |
||
1666 | * @throws ReflectionException |
||
1667 | * @see EEI_Event_Relation for comments |
||
1668 | */ |
||
1669 | public function get_event_ID() |
||
1674 | |||
1675 | |||
1676 | /** |
||
1677 | * This simply returns whether a ticket can be permanently deleted or not. |
||
1678 | * The criteria for determining this is whether the ticket has any related registrations. |
||
1679 | * If there are none then it can be permanently deleted. |
||
1680 | * |
||
1681 | * @return bool |
||
1682 | * @throws EE_Error |
||
1683 | * @throws ReflectionException |
||
1684 | */ |
||
1685 | public function is_permanently_deleteable() |
||
1689 | |||
1690 | |||
1691 | /******************************************************************* |
||
1692 | *********************** DEPRECATED METHODS ********************** |
||
1693 | *******************************************************************/ |
||
1694 | |||
1695 | |||
1696 | /** |
||
1697 | * Increments sold by amount passed by $qty AND decrements the reserved count on both this ticket and its |
||
1698 | * associated datetimes. |
||
1699 | * |
||
1700 | * @param int $qty |
||
1701 | * @return void |
||
1702 | * @throws EE_Error |
||
1703 | * @throws InvalidArgumentException |
||
1704 | * @throws InvalidDataTypeException |
||
1705 | * @throws InvalidInterfaceException |
||
1706 | * @throws ReflectionException |
||
1707 | * @deprecated 4.9.80.p |
||
1708 | */ |
||
1709 | public function increase_sold($qty = 1) |
||
1719 | |||
1720 | |||
1721 | /** |
||
1722 | * On each datetime related to this ticket, increases its sold count and decreases its reserved count by $qty. |
||
1723 | * |
||
1724 | * @param int $qty positive or negative. Positive means to increase sold counts (and decrease reserved counts), |
||
1725 | * Negative means to decreases old counts (and increase reserved counts). |
||
1726 | * @throws EE_Error |
||
1727 | * @throws InvalidArgumentException |
||
1728 | * @throws InvalidDataTypeException |
||
1729 | * @throws InvalidInterfaceException |
||
1730 | * @throws ReflectionException |
||
1731 | * @deprecated 4.9.80.p |
||
1732 | */ |
||
1733 | protected function _increase_sold_for_datetimes($qty) |
||
1743 | |||
1744 | |||
1745 | /** |
||
1746 | * Decrements (subtracts) sold by amount passed by $qty on both the ticket and its related datetimes directly in the |
||
1747 | * DB and then updates the model objects. |
||
1748 | * Does not affect the reserved counts. |
||
1749 | * |
||
1750 | * @param int $qty |
||
1751 | * @return void |
||
1752 | * @throws EE_Error |
||
1753 | * @throws InvalidArgumentException |
||
1754 | * @throws InvalidDataTypeException |
||
1755 | * @throws InvalidInterfaceException |
||
1756 | * @throws ReflectionException |
||
1757 | * @deprecated 4.9.80.p |
||
1758 | */ |
||
1759 | public function decrease_sold($qty = 1) |
||
1769 | |||
1770 | |||
1771 | /** |
||
1772 | * Decreases sold on related datetimes |
||
1773 | * |
||
1774 | * @param int $qty |
||
1775 | * @return void |
||
1776 | * @throws EE_Error |
||
1777 | * @throws InvalidArgumentException |
||
1778 | * @throws InvalidDataTypeException |
||
1779 | * @throws InvalidInterfaceException |
||
1780 | * @throws ReflectionException |
||
1781 | * @deprecated 4.9.80.p |
||
1782 | */ |
||
1783 | protected function _decrease_sold_for_datetimes($qty = 1) |
||
1793 | |||
1794 | |||
1795 | /** |
||
1796 | * Increments reserved by amount passed by $qty, and persists it immediately to the database. |
||
1797 | * |
||
1798 | * @param int $qty |
||
1799 | * @param string $source |
||
1800 | * @return bool whether we successfully reserved the ticket or not. |
||
1801 | * @throws EE_Error |
||
1802 | * @throws InvalidArgumentException |
||
1803 | * @throws ReflectionException |
||
1804 | * @throws InvalidDataTypeException |
||
1805 | * @throws InvalidInterfaceException |
||
1806 | * @deprecated 4.9.80.p |
||
1807 | */ |
||
1808 | public function increase_reserved($qty = 1, $source = 'unknown') |
||
1818 | |||
1819 | |||
1820 | /** |
||
1821 | * Increases sold on related datetimes |
||
1822 | * |
||
1823 | * @param int $qty |
||
1824 | * @return boolean indicating success |
||
1825 | * @throws EE_Error |
||
1826 | * @throws InvalidArgumentException |
||
1827 | * @throws InvalidDataTypeException |
||
1828 | * @throws InvalidInterfaceException |
||
1829 | * @throws ReflectionException |
||
1830 | * @deprecated 4.9.80.p |
||
1831 | */ |
||
1832 | protected function _increase_reserved_for_datetimes($qty = 1) |
||
1842 | |||
1843 | |||
1844 | /** |
||
1845 | * Decrements (subtracts) reserved by amount passed by $qty, and persists it immediately to the database. |
||
1846 | * |
||
1847 | * @param int $qty |
||
1848 | * @param bool $adjust_datetimes |
||
1849 | * @param string $source |
||
1850 | * @return void |
||
1851 | * @throws EE_Error |
||
1852 | * @throws InvalidArgumentException |
||
1853 | * @throws ReflectionException |
||
1854 | * @throws InvalidDataTypeException |
||
1855 | * @throws InvalidInterfaceException |
||
1856 | * @deprecated 4.9.80.p |
||
1857 | */ |
||
1858 | public function decrease_reserved($qty = 1, $adjust_datetimes = true, $source = 'unknown') |
||
1868 | |||
1869 | |||
1870 | /** |
||
1871 | * Decreases reserved on related datetimes |
||
1872 | * |
||
1873 | * @param int $qty |
||
1874 | * @return void |
||
1875 | * @throws EE_Error |
||
1876 | * @throws InvalidArgumentException |
||
1877 | * @throws ReflectionException |
||
1878 | * @throws InvalidDataTypeException |
||
1879 | * @throws InvalidInterfaceException |
||
1880 | * @deprecated 4.9.80.p |
||
1881 | */ |
||
1882 | protected function _decrease_reserved_for_datetimes($qty = 1) |
||
1892 | } |
||
1893 |