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 purchase |
||
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 | */ |
||
76 | public static function new_instance($props_n_values = array(), $timezone = null, $date_formats = array()) |
||
81 | |||
82 | |||
83 | /** |
||
84 | * @param array $props_n_values incoming values from the database |
||
85 | * @param string $timezone incoming timezone as set by the model. If not set the timezone for |
||
86 | * the website will be used. |
||
87 | * @return EE_Ticket |
||
88 | * @throws EE_Error |
||
89 | */ |
||
90 | public static function new_instance_from_db($props_n_values = array(), $timezone = null) |
||
94 | |||
95 | |||
96 | /** |
||
97 | * @return bool |
||
98 | * @throws EE_Error |
||
99 | */ |
||
100 | public function parent() |
||
104 | |||
105 | |||
106 | /** |
||
107 | * return if a ticket has quantities available for purchase |
||
108 | * |
||
109 | * @param int $DTT_ID the primary key for a particular datetime |
||
110 | * @return boolean |
||
111 | * @throws EE_Error |
||
112 | */ |
||
113 | public function available($DTT_ID = 0) |
||
127 | |||
128 | |||
129 | /** |
||
130 | * Using the start date and end date this method calculates whether the ticket is On Sale, Pending, or Expired |
||
131 | * |
||
132 | * @param bool $display true = we'll return a localized string, otherwise we just return the value of the |
||
133 | * relevant status const |
||
134 | * @param bool | null $remaining if it is already known that tickets are available, then simply pass a bool to save |
||
135 | * further processing |
||
136 | * @return mixed status int if the display string isn't requested |
||
137 | * @throws EE_Error |
||
138 | */ |
||
139 | public function ticket_status($display = false, $remaining = null) |
||
159 | |||
160 | |||
161 | /** |
||
162 | * The purpose of this method is to simply return a boolean for whether there are any tickets remaining for sale |
||
163 | * considering ALL the factors used for figuring that out. |
||
164 | * |
||
165 | * @access public |
||
166 | * @param int $DTT_ID if an int above 0 is included here then we get a specific dtt. |
||
167 | * @return boolean true = tickets remaining, false not. |
||
168 | * @throws EE_Error |
||
169 | */ |
||
170 | public function is_remaining($DTT_ID = 0) |
||
181 | |||
182 | |||
183 | /** |
||
184 | * return the total number of tickets available for purchase |
||
185 | * |
||
186 | * @param int $DTT_ID the primary key for a particular datetime. |
||
187 | * set to 0 for all related datetimes |
||
188 | * @return int |
||
189 | * @throws EE_Error |
||
190 | */ |
||
191 | public function remaining($DTT_ID = 0) |
||
195 | |||
196 | |||
197 | /** |
||
198 | * Gets min |
||
199 | * |
||
200 | * @return int |
||
201 | * @throws EE_Error |
||
202 | */ |
||
203 | public function min() |
||
207 | |||
208 | |||
209 | /** |
||
210 | * return if a ticket is no longer available cause its available dates have expired. |
||
211 | * |
||
212 | * @return boolean |
||
213 | * @throws EE_Error |
||
214 | */ |
||
215 | public function is_expired() |
||
219 | |||
220 | |||
221 | /** |
||
222 | * Return if a ticket is yet to go on sale or not |
||
223 | * |
||
224 | * @return boolean |
||
225 | * @throws EE_Error |
||
226 | */ |
||
227 | public function is_pending() |
||
231 | |||
232 | |||
233 | /** |
||
234 | * Return if a ticket is on sale or not |
||
235 | * |
||
236 | * @return boolean |
||
237 | * @throws EE_Error |
||
238 | */ |
||
239 | public function is_on_sale() |
||
243 | |||
244 | |||
245 | /** |
||
246 | * This returns the chronologically last datetime that this ticket is associated with |
||
247 | * |
||
248 | * @param string $dt_frmt |
||
249 | * @param string $conjunction - conjunction junction what's your function ? this string joins the start date with |
||
250 | * the end date ie: Jan 01 "to" Dec 31 |
||
251 | * @return string |
||
252 | * @throws EE_Error |
||
253 | */ |
||
254 | public function date_range($dt_frmt = '', $conjunction = ' - ') |
||
263 | |||
264 | |||
265 | /** |
||
266 | * This returns the chronologically first datetime that this ticket is associated with |
||
267 | * |
||
268 | * @return EE_Datetime |
||
269 | * @throws EE_Error |
||
270 | */ |
||
271 | public function first_datetime() |
||
276 | |||
277 | |||
278 | /** |
||
279 | * Gets all the datetimes this ticket can be used for attending. |
||
280 | * Unless otherwise specified, orders datetimes by start date. |
||
281 | * |
||
282 | * @param array $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md |
||
283 | * @return EE_Datetime[]|EE_Base_Class[] |
||
284 | * @throws EE_Error |
||
285 | */ |
||
286 | public function datetimes($query_params = array()) |
||
293 | |||
294 | |||
295 | /** |
||
296 | * This returns the chronologically last datetime that this ticket is associated with |
||
297 | * |
||
298 | * @return EE_Datetime |
||
299 | * @throws EE_Error |
||
300 | */ |
||
301 | public function last_datetime() |
||
306 | |||
307 | |||
308 | /** |
||
309 | * This returns the total tickets sold depending on the given parameters. |
||
310 | * |
||
311 | * @param string $what Can be one of two options: 'ticket', 'datetime'. |
||
312 | * 'ticket' = total ticket sales for all datetimes this ticket is related to |
||
313 | * 'datetime' = total ticket sales for a specified datetime (required $dtt_id) |
||
314 | * 'datetime' = total ticket sales in the datetime_ticket table. |
||
315 | * If $dtt_id is not given then we return an array of sales indexed by datetime. |
||
316 | * If $dtt_id IS given then we return the tickets sold for that given datetime. |
||
317 | * @param int $dtt_id [optional] include the dtt_id with $what = 'datetime'. |
||
318 | * @return mixed (array|int) how many tickets have sold |
||
319 | * @throws EE_Error |
||
320 | */ |
||
321 | public function tickets_sold($what = 'ticket', $dtt_id = null) |
||
351 | |||
352 | |||
353 | /** |
||
354 | * This returns an array indexed by datetime_id for tickets sold with this ticket. |
||
355 | * |
||
356 | * @return EE_Ticket[] |
||
357 | * @throws EE_Error |
||
358 | */ |
||
359 | protected function _all_tickets_sold() |
||
372 | |||
373 | |||
374 | /** |
||
375 | * This returns the base price object for the ticket. |
||
376 | * |
||
377 | * @param bool $return_array whether to return as an array indexed by price id or just the object. |
||
378 | * @return EE_Price|EE_Base_Class|EE_Price[]|EE_Base_Class[] |
||
379 | * @throws EE_Error |
||
380 | */ |
||
381 | public function base_price($return_array = false) |
||
388 | |||
389 | |||
390 | /** |
||
391 | * This returns ONLY the price modifiers for the ticket (i.e. no taxes or base price) |
||
392 | * |
||
393 | * @access public |
||
394 | * @return EE_Price[] |
||
395 | * @throws EE_Error |
||
396 | */ |
||
397 | public function price_modifiers() |
||
409 | |||
410 | |||
411 | /** |
||
412 | * Gets all the prices that combine to form the final price of this ticket |
||
413 | * |
||
414 | * @param array $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md |
||
415 | * @return EE_Price[]|EE_Base_Class[] |
||
416 | * @throws EE_Error |
||
417 | */ |
||
418 | public function prices($query_params = array()) |
||
422 | |||
423 | |||
424 | /** |
||
425 | * Gets all the ticket applicabilities (ie, relations between datetimes and tickets) |
||
426 | * |
||
427 | * @param array $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md |
||
428 | * @return EE_Datetime_Ticket|EE_Base_Class[] |
||
429 | * @throws EE_Error |
||
430 | */ |
||
431 | public function datetime_tickets($query_params = array()) |
||
435 | |||
436 | |||
437 | /** |
||
438 | * Gets all the datetimes from the db ordered by DTT_order |
||
439 | * |
||
440 | * @param boolean $show_expired |
||
441 | * @param boolean $show_deleted |
||
442 | * @return EE_Datetime[] |
||
443 | * @throws EE_Error |
||
444 | */ |
||
445 | public function datetimes_ordered($show_expired = true, $show_deleted = false) |
||
453 | |||
454 | |||
455 | /** |
||
456 | * Gets ID |
||
457 | * |
||
458 | * @return string |
||
459 | * @throws EE_Error |
||
460 | */ |
||
461 | public function ID() |
||
465 | |||
466 | |||
467 | /** |
||
468 | * get the author of the ticket. |
||
469 | * |
||
470 | * @since 4.5.0 |
||
471 | * @return int |
||
472 | * @throws EE_Error |
||
473 | */ |
||
474 | public function wp_user() |
||
478 | |||
479 | |||
480 | /** |
||
481 | * Gets the template for the ticket |
||
482 | * |
||
483 | * @return EE_Ticket_Template|EE_Base_Class |
||
484 | * @throws EE_Error |
||
485 | */ |
||
486 | public function template() |
||
490 | |||
491 | |||
492 | /** |
||
493 | * Simply returns an array of EE_Price objects that are taxes. |
||
494 | * |
||
495 | * @return EE_Price[] |
||
496 | * @throws EE_Error |
||
497 | */ |
||
498 | public function get_ticket_taxes_for_admin() |
||
502 | |||
503 | |||
504 | /** |
||
505 | * @return float |
||
506 | * @throws EE_Error |
||
507 | */ |
||
508 | public function ticket_price() |
||
512 | |||
513 | |||
514 | /** |
||
515 | * @return mixed |
||
516 | * @throws EE_Error |
||
517 | */ |
||
518 | public function pretty_price() |
||
522 | |||
523 | |||
524 | /** |
||
525 | * @return bool |
||
526 | * @throws EE_Error |
||
527 | */ |
||
528 | public function is_free() |
||
532 | |||
533 | |||
534 | /** |
||
535 | * get_ticket_total_with_taxes |
||
536 | * |
||
537 | * @param bool $no_cache |
||
538 | * @return float |
||
539 | * @throws EE_Error |
||
540 | */ |
||
541 | public function get_ticket_total_with_taxes($no_cache = false) |
||
548 | |||
549 | |||
550 | public function ensure_TKT_Price_correct() |
||
555 | |||
556 | |||
557 | /** |
||
558 | * @return float |
||
559 | * @throws EE_Error |
||
560 | */ |
||
561 | public function get_ticket_subtotal() |
||
565 | |||
566 | |||
567 | /** |
||
568 | * Returns the total taxes applied to this ticket |
||
569 | * |
||
570 | * @return float |
||
571 | * @throws EE_Error |
||
572 | */ |
||
573 | public function get_ticket_taxes_total_for_admin() |
||
577 | |||
578 | |||
579 | /** |
||
580 | * Sets name |
||
581 | * |
||
582 | * @param string $name |
||
583 | * @throws EE_Error |
||
584 | */ |
||
585 | public function set_name($name) |
||
589 | |||
590 | |||
591 | /** |
||
592 | * Gets description |
||
593 | * |
||
594 | * @return string |
||
595 | * @throws EE_Error |
||
596 | */ |
||
597 | public function description() |
||
601 | |||
602 | |||
603 | /** |
||
604 | * Sets description |
||
605 | * |
||
606 | * @param string $description |
||
607 | * @throws EE_Error |
||
608 | */ |
||
609 | public function set_description($description) |
||
613 | |||
614 | |||
615 | /** |
||
616 | * Gets start_date |
||
617 | * |
||
618 | * @param string $dt_frmt |
||
619 | * @param string $tm_frmt |
||
620 | * @return string |
||
621 | * @throws EE_Error |
||
622 | */ |
||
623 | public function start_date($dt_frmt = '', $tm_frmt = '') |
||
627 | |||
628 | |||
629 | /** |
||
630 | * Sets start_date |
||
631 | * |
||
632 | * @param string $start_date |
||
633 | * @return void |
||
634 | * @throws EE_Error |
||
635 | */ |
||
636 | public function set_start_date($start_date) |
||
640 | |||
641 | |||
642 | /** |
||
643 | * Gets end_date |
||
644 | * |
||
645 | * @param string $dt_frmt |
||
646 | * @param string $tm_frmt |
||
647 | * @return string |
||
648 | * @throws EE_Error |
||
649 | */ |
||
650 | public function end_date($dt_frmt = '', $tm_frmt = '') |
||
654 | |||
655 | |||
656 | /** |
||
657 | * Sets end_date |
||
658 | * |
||
659 | * @param string $end_date |
||
660 | * @return void |
||
661 | * @throws EE_Error |
||
662 | */ |
||
663 | public function set_end_date($end_date) |
||
667 | |||
668 | |||
669 | /** |
||
670 | * Sets sell until time |
||
671 | * |
||
672 | * @since 4.5.0 |
||
673 | * @param string $time a string representation of the sell until time (ex 9am or 7:30pm) |
||
674 | * @throws EE_Error |
||
675 | */ |
||
676 | public function set_end_time($time) |
||
680 | |||
681 | |||
682 | /** |
||
683 | * Sets min |
||
684 | * |
||
685 | * @param int $min |
||
686 | * @return void |
||
687 | * @throws EE_Error |
||
688 | */ |
||
689 | public function set_min($min) |
||
693 | |||
694 | |||
695 | /** |
||
696 | * Gets max |
||
697 | * |
||
698 | * @return int |
||
699 | * @throws EE_Error |
||
700 | */ |
||
701 | public function max() |
||
705 | |||
706 | |||
707 | /** |
||
708 | * Sets max |
||
709 | * |
||
710 | * @param int $max |
||
711 | * @return void |
||
712 | * @throws EE_Error |
||
713 | */ |
||
714 | public function set_max($max) |
||
718 | |||
719 | |||
720 | /** |
||
721 | * Sets price |
||
722 | * |
||
723 | * @param float $price |
||
724 | * @return void |
||
725 | * @throws EE_Error |
||
726 | */ |
||
727 | public function set_price($price) |
||
731 | |||
732 | |||
733 | /** |
||
734 | * Gets sold |
||
735 | * |
||
736 | * @return int |
||
737 | * @throws EE_Error |
||
738 | */ |
||
739 | public function sold() |
||
743 | |||
744 | |||
745 | /** |
||
746 | * Sets sold |
||
747 | * |
||
748 | * @param int $sold |
||
749 | * @return void |
||
750 | * @throws EE_Error |
||
751 | */ |
||
752 | public function set_sold($sold) |
||
758 | |||
759 | |||
760 | /** |
||
761 | * Increments sold by amount passed by $qty AND decrements the reserved count on both this ticket and its |
||
762 | * associated datetimes. |
||
763 | * |
||
764 | * @since 4.9.80.p |
||
765 | * @param int $qty |
||
766 | * @return boolean |
||
767 | * @throws EE_Error |
||
768 | * @throws InvalidArgumentException |
||
769 | * @throws InvalidDataTypeException |
||
770 | * @throws InvalidInterfaceException |
||
771 | * @throws ReflectionException |
||
772 | */ |
||
773 | View Code Duplication | public function increaseSold($qty = 1) |
|
795 | |||
796 | /** |
||
797 | * On each datetime related to this ticket, increases its sold count and decreases its reserved count by $qty. |
||
798 | * |
||
799 | * @since 4.9.80.p |
||
800 | * @param int $qty positive or negative. Positive means to increase sold counts (and decrease reserved counts), |
||
801 | * Negative means to decreases old counts (and increase reserved counts). |
||
802 | * @param EE_Datetime[] $datetimes |
||
803 | * @throws EE_Error |
||
804 | * @throws InvalidArgumentException |
||
805 | * @throws InvalidDataTypeException |
||
806 | * @throws InvalidInterfaceException |
||
807 | * @throws ReflectionException |
||
808 | */ |
||
809 | protected function increaseSoldForDatetimes($qty, array $datetimes = []) |
||
816 | |||
817 | |||
818 | |||
819 | /** |
||
820 | * Decrements (subtracts) sold by amount passed by $qty on both the ticket and its related datetimes directly in the |
||
821 | * DB and then updates the model objects. |
||
822 | * Does not affect the reserved counts. |
||
823 | * |
||
824 | * @since 4.9.80.p |
||
825 | * @param int $qty |
||
826 | * @return boolean |
||
827 | * @throws EE_Error |
||
828 | * @throws InvalidArgumentException |
||
829 | * @throws InvalidDataTypeException |
||
830 | * @throws InvalidInterfaceException |
||
831 | * @throws ReflectionException |
||
832 | */ |
||
833 | View Code Duplication | public function decreaseSold($qty = 1) |
|
851 | |||
852 | |||
853 | /** |
||
854 | * Decreases sold on related datetimes |
||
855 | * |
||
856 | * @since 4.9.80.p |
||
857 | * @param int $qty |
||
858 | * @param EE_Datetime[] $datetimes |
||
859 | * @return void |
||
860 | * @throws EE_Error |
||
861 | * @throws InvalidArgumentException |
||
862 | * @throws InvalidDataTypeException |
||
863 | * @throws InvalidInterfaceException |
||
864 | * @throws ReflectionException |
||
865 | */ |
||
866 | View Code Duplication | protected function decreaseSoldForDatetimes($qty = 1, array $datetimes = []) |
|
877 | |||
878 | |||
879 | /** |
||
880 | * Gets qty of reserved tickets |
||
881 | * |
||
882 | * @return int |
||
883 | * @throws EE_Error |
||
884 | */ |
||
885 | public function reserved() |
||
889 | |||
890 | |||
891 | /** |
||
892 | * Sets reserved |
||
893 | * |
||
894 | * @param int $reserved |
||
895 | * @return void |
||
896 | * @throws EE_Error |
||
897 | */ |
||
898 | public function set_reserved($reserved) |
||
904 | |||
905 | |||
906 | /** |
||
907 | * Increments reserved by amount passed by $qty, and persists it immediately to the database. |
||
908 | * |
||
909 | * @since 4.9.80.p |
||
910 | * @param int $qty |
||
911 | * @param string $source |
||
912 | * @return bool whether we successfully reserved the ticket or not. |
||
913 | * @throws EE_Error |
||
914 | * @throws InvalidArgumentException |
||
915 | * @throws ReflectionException |
||
916 | * @throws InvalidDataTypeException |
||
917 | * @throws InvalidInterfaceException |
||
918 | */ |
||
919 | public function increaseReserved($qty = 1, $source = 'unknown') |
||
953 | |||
954 | |||
955 | /** |
||
956 | * Increases reserved counts on related datetimes |
||
957 | * |
||
958 | * @since 4.9.80.p |
||
959 | * @param int $qty |
||
960 | * @param EE_Datetime[] $datetimes |
||
961 | * @return boolean indicating success |
||
962 | * @throws EE_Error |
||
963 | * @throws InvalidArgumentException |
||
964 | * @throws InvalidDataTypeException |
||
965 | * @throws InvalidInterfaceException |
||
966 | * @throws ReflectionException |
||
967 | */ |
||
968 | protected function increaseReservedForDatetimes($qty = 1, array $datetimes = []) |
||
993 | |||
994 | |||
995 | /** |
||
996 | * Decrements (subtracts) reserved by amount passed by $qty, and persists it immediately to the database. |
||
997 | * |
||
998 | * @since 4.9.80.p |
||
999 | * @param int $qty |
||
1000 | * @param bool $adjust_datetimes |
||
1001 | * @param string $source |
||
1002 | * @return boolean |
||
1003 | * @throws EE_Error |
||
1004 | * @throws InvalidArgumentException |
||
1005 | * @throws ReflectionException |
||
1006 | * @throws InvalidDataTypeException |
||
1007 | * @throws InvalidInterfaceException |
||
1008 | */ |
||
1009 | public function decreaseReserved($qty = 1, $adjust_datetimes = true, $source = 'unknown') |
||
1030 | |||
1031 | |||
1032 | /** |
||
1033 | * Decreases the reserved count on the specified datetimes. |
||
1034 | * |
||
1035 | * @since 4.9.80.p |
||
1036 | * @param int $qty |
||
1037 | * @param EE_Datetime[] $datetimes |
||
1038 | * @throws EE_Error |
||
1039 | * @throws InvalidArgumentException |
||
1040 | * @throws ReflectionException |
||
1041 | * @throws InvalidDataTypeException |
||
1042 | * @throws InvalidInterfaceException |
||
1043 | */ |
||
1044 | View Code Duplication | protected function decreaseReservedForDatetimes($qty = 1, array $datetimes = []) |
|
1053 | |||
1054 | |||
1055 | /** |
||
1056 | * Gets ticket quantity |
||
1057 | * |
||
1058 | * @param string $context ticket quantity is somewhat subjective depending on the exact information sought |
||
1059 | * therefore $context can be one of three values: '', 'reg_limit', or 'saleable' |
||
1060 | * '' (default) quantity is the actual db value for TKT_qty, unaffected by other objects |
||
1061 | * REG LIMIT: caps qty based on DTT_reg_limit for ALL related datetimes |
||
1062 | * SALEABLE: also considers datetime sold and returns zero if ANY DTT is sold out, and |
||
1063 | * is therefore the truest measure of tickets that can be purchased at the moment |
||
1064 | * @return int |
||
1065 | * @throws EE_Error |
||
1066 | */ |
||
1067 | public function qty($context = '') |
||
1078 | |||
1079 | |||
1080 | /** |
||
1081 | * Gets ticket quantity |
||
1082 | * |
||
1083 | * @param string $context ticket quantity is somewhat subjective depending on the exact information sought |
||
1084 | * therefore $context can be one of two values: 'reg_limit', or 'saleable' |
||
1085 | * REG LIMIT: caps qty based on DTT_reg_limit for ALL related datetimes |
||
1086 | * SALEABLE: also considers datetime sold and returns zero if ANY DTT is sold out, and |
||
1087 | * is therefore the truest measure of tickets that can be purchased at the moment |
||
1088 | * @param int $DTT_ID the primary key for a particular datetime. |
||
1089 | * set to 0 for all related datetimes |
||
1090 | * @return int |
||
1091 | * @throws EE_Error |
||
1092 | */ |
||
1093 | public function real_quantity_on_ticket($context = 'reg_limit', $DTT_ID = 0) |
||
1154 | |||
1155 | |||
1156 | /** |
||
1157 | * Sets qty - IMPORTANT!!! Does NOT allow QTY to be set higher than the lowest reg limit of any related datetimes |
||
1158 | * |
||
1159 | * @param int $qty |
||
1160 | * @return void |
||
1161 | * @throws EE_Error |
||
1162 | */ |
||
1163 | public function set_qty($qty) |
||
1173 | |||
1174 | |||
1175 | /** |
||
1176 | * Gets uses |
||
1177 | * |
||
1178 | * @return int |
||
1179 | * @throws EE_Error |
||
1180 | */ |
||
1181 | public function uses() |
||
1185 | |||
1186 | |||
1187 | /** |
||
1188 | * Sets uses |
||
1189 | * |
||
1190 | * @param int $uses |
||
1191 | * @return void |
||
1192 | * @throws EE_Error |
||
1193 | */ |
||
1194 | public function set_uses($uses) |
||
1198 | |||
1199 | |||
1200 | /** |
||
1201 | * returns whether ticket is required or not. |
||
1202 | * |
||
1203 | * @return boolean |
||
1204 | * @throws EE_Error |
||
1205 | */ |
||
1206 | public function required() |
||
1210 | |||
1211 | |||
1212 | /** |
||
1213 | * sets the TKT_required property |
||
1214 | * |
||
1215 | * @param boolean $required |
||
1216 | * @return void |
||
1217 | * @throws EE_Error |
||
1218 | */ |
||
1219 | public function set_required($required) |
||
1223 | |||
1224 | |||
1225 | /** |
||
1226 | * Gets taxable |
||
1227 | * |
||
1228 | * @return boolean |
||
1229 | * @throws EE_Error |
||
1230 | */ |
||
1231 | public function taxable() |
||
1235 | |||
1236 | |||
1237 | /** |
||
1238 | * Sets taxable |
||
1239 | * |
||
1240 | * @param boolean $taxable |
||
1241 | * @return void |
||
1242 | * @throws EE_Error |
||
1243 | */ |
||
1244 | public function set_taxable($taxable) |
||
1248 | |||
1249 | |||
1250 | /** |
||
1251 | * Gets is_default |
||
1252 | * |
||
1253 | * @return boolean |
||
1254 | * @throws EE_Error |
||
1255 | */ |
||
1256 | public function is_default() |
||
1260 | |||
1261 | |||
1262 | /** |
||
1263 | * Sets is_default |
||
1264 | * |
||
1265 | * @param boolean $is_default |
||
1266 | * @return void |
||
1267 | * @throws EE_Error |
||
1268 | */ |
||
1269 | public function set_is_default($is_default) |
||
1273 | |||
1274 | |||
1275 | /** |
||
1276 | * Gets order |
||
1277 | * |
||
1278 | * @return int |
||
1279 | * @throws EE_Error |
||
1280 | */ |
||
1281 | public function order() |
||
1285 | |||
1286 | |||
1287 | /** |
||
1288 | * Sets order |
||
1289 | * |
||
1290 | * @param int $order |
||
1291 | * @return void |
||
1292 | * @throws EE_Error |
||
1293 | */ |
||
1294 | public function set_order($order) |
||
1298 | |||
1299 | |||
1300 | /** |
||
1301 | * Gets row |
||
1302 | * |
||
1303 | * @return int |
||
1304 | * @throws EE_Error |
||
1305 | */ |
||
1306 | public function row() |
||
1310 | |||
1311 | |||
1312 | /** |
||
1313 | * Sets row |
||
1314 | * |
||
1315 | * @param int $row |
||
1316 | * @return void |
||
1317 | * @throws EE_Error |
||
1318 | */ |
||
1319 | public function set_row($row) |
||
1323 | |||
1324 | |||
1325 | /** |
||
1326 | * Gets deleted |
||
1327 | * |
||
1328 | * @return boolean |
||
1329 | * @throws EE_Error |
||
1330 | */ |
||
1331 | public function deleted() |
||
1335 | |||
1336 | |||
1337 | /** |
||
1338 | * Sets deleted |
||
1339 | * |
||
1340 | * @param boolean $deleted |
||
1341 | * @return void |
||
1342 | * @throws EE_Error |
||
1343 | */ |
||
1344 | public function set_deleted($deleted) |
||
1348 | |||
1349 | |||
1350 | /** |
||
1351 | * Gets parent |
||
1352 | * |
||
1353 | * @return int |
||
1354 | * @throws EE_Error |
||
1355 | */ |
||
1356 | public function parent_ID() |
||
1360 | |||
1361 | |||
1362 | /** |
||
1363 | * Sets parent |
||
1364 | * |
||
1365 | * @param int $parent |
||
1366 | * @return void |
||
1367 | * @throws EE_Error |
||
1368 | */ |
||
1369 | public function set_parent_ID($parent) |
||
1373 | |||
1374 | |||
1375 | /** |
||
1376 | * @return boolean |
||
1377 | * @throws EE_Error |
||
1378 | * @throws InvalidArgumentException |
||
1379 | * @throws InvalidDataTypeException |
||
1380 | * @throws InvalidInterfaceException |
||
1381 | * @throws ReflectionException |
||
1382 | */ |
||
1383 | public function reverse_calculate() |
||
1387 | |||
1388 | |||
1389 | /** |
||
1390 | * @param boolean $reverse_calculate |
||
1391 | * @throws EE_Error |
||
1392 | * @throws InvalidArgumentException |
||
1393 | * @throws InvalidDataTypeException |
||
1394 | * @throws InvalidInterfaceException |
||
1395 | * @throws ReflectionException |
||
1396 | */ |
||
1397 | public function set_reverse_calculate($reverse_calculate) |
||
1401 | |||
1402 | |||
1403 | /** |
||
1404 | * Gets a string which is handy for showing in gateways etc that describes the ticket. |
||
1405 | * |
||
1406 | * @return string |
||
1407 | * @throws EE_Error |
||
1408 | */ |
||
1409 | public function name_and_info() |
||
1417 | |||
1418 | |||
1419 | /** |
||
1420 | * Gets name |
||
1421 | * |
||
1422 | * @return string |
||
1423 | * @throws EE_Error |
||
1424 | */ |
||
1425 | public function name() |
||
1429 | |||
1430 | |||
1431 | /** |
||
1432 | * Gets price |
||
1433 | * |
||
1434 | * @return float |
||
1435 | * @throws EE_Error |
||
1436 | */ |
||
1437 | public function price() |
||
1441 | |||
1442 | |||
1443 | /** |
||
1444 | * Gets all the registrations for this ticket |
||
1445 | * |
||
1446 | * @param array $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md |
||
1447 | * @return EE_Registration[]|EE_Base_Class[] |
||
1448 | * @throws EE_Error |
||
1449 | */ |
||
1450 | public function registrations($query_params = array()) |
||
1454 | |||
1455 | |||
1456 | /** |
||
1457 | * Updates the TKT_sold attribute (and saves) based on the number of APPROVED registrations for this ticket. |
||
1458 | * |
||
1459 | * @return int |
||
1460 | * @throws EE_Error |
||
1461 | */ |
||
1462 | View Code Duplication | public function update_tickets_sold() |
|
1476 | |||
1477 | |||
1478 | /** |
||
1479 | * Counts the registrations for this ticket |
||
1480 | * |
||
1481 | * @param array $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md |
||
1482 | * @return int |
||
1483 | */ |
||
1484 | public function count_registrations($query_params = array()) |
||
1488 | |||
1489 | |||
1490 | /** |
||
1491 | * Implementation for EEI_Has_Icon interface method. |
||
1492 | * |
||
1493 | * @see EEI_Visual_Representation for comments |
||
1494 | * @return string |
||
1495 | */ |
||
1496 | public function get_icon() |
||
1500 | |||
1501 | |||
1502 | /** |
||
1503 | * Implementation of the EEI_Event_Relation interface method |
||
1504 | * |
||
1505 | * @see EEI_Event_Relation for comments |
||
1506 | * @return EE_Event |
||
1507 | * @throws EE_Error |
||
1508 | * @throws UnexpectedEntityException |
||
1509 | */ |
||
1510 | public function get_related_event() |
||
1537 | |||
1538 | |||
1539 | /** |
||
1540 | * Implementation of the EEI_Event_Relation interface method |
||
1541 | * |
||
1542 | * @see EEI_Event_Relation for comments |
||
1543 | * @return string |
||
1544 | * @throws UnexpectedEntityException |
||
1545 | * @throws EE_Error |
||
1546 | */ |
||
1547 | public function get_event_name() |
||
1552 | |||
1553 | |||
1554 | /** |
||
1555 | * Implementation of the EEI_Event_Relation interface method |
||
1556 | * |
||
1557 | * @see EEI_Event_Relation for comments |
||
1558 | * @return int |
||
1559 | * @throws UnexpectedEntityException |
||
1560 | * @throws EE_Error |
||
1561 | */ |
||
1562 | public function get_event_ID() |
||
1567 | |||
1568 | |||
1569 | /** |
||
1570 | * This simply returns whether a ticket can be permanently deleted or not. |
||
1571 | * The criteria for determining this is whether the ticket has any related registrations. |
||
1572 | * If there are none then it can be permanently deleted. |
||
1573 | * |
||
1574 | * @return bool |
||
1575 | */ |
||
1576 | public function is_permanently_deleteable() |
||
1580 | |||
1581 | |||
1582 | /******************************************************************* |
||
1583 | *********************** DEPRECATED METHODS ********************** |
||
1584 | *******************************************************************/ |
||
1585 | |||
1586 | |||
1587 | /** |
||
1588 | * Increments sold by amount passed by $qty AND decrements the reserved count on both this ticket and its |
||
1589 | * associated datetimes. |
||
1590 | * |
||
1591 | * @deprecated 4.9.80.p |
||
1592 | * @param int $qty |
||
1593 | * @return void |
||
1594 | * @throws EE_Error |
||
1595 | * @throws InvalidArgumentException |
||
1596 | * @throws InvalidDataTypeException |
||
1597 | * @throws InvalidInterfaceException |
||
1598 | * @throws ReflectionException |
||
1599 | */ |
||
1600 | public function increase_sold($qty = 1) |
||
1610 | |||
1611 | |||
1612 | /** |
||
1613 | * On each datetime related to this ticket, increases its sold count and decreases its reserved count by $qty. |
||
1614 | * |
||
1615 | * @deprecated 4.9.80.p |
||
1616 | * @param int $qty positive or negative. Positive means to increase sold counts (and decrease reserved counts), |
||
1617 | * Negative means to decreases old counts (and increase reserved counts). |
||
1618 | * @throws EE_Error |
||
1619 | * @throws InvalidArgumentException |
||
1620 | * @throws InvalidDataTypeException |
||
1621 | * @throws InvalidInterfaceException |
||
1622 | * @throws ReflectionException |
||
1623 | */ |
||
1624 | protected function _increase_sold_for_datetimes($qty) |
||
1634 | |||
1635 | |||
1636 | /** |
||
1637 | * Decrements (subtracts) sold by amount passed by $qty on both the ticket and its related datetimes directly in the |
||
1638 | * DB and then updates the model objects. |
||
1639 | * Does not affect the reserved counts. |
||
1640 | * |
||
1641 | * @deprecated 4.9.80.p |
||
1642 | * @param int $qty |
||
1643 | * @return void |
||
1644 | * @throws EE_Error |
||
1645 | * @throws InvalidArgumentException |
||
1646 | * @throws InvalidDataTypeException |
||
1647 | * @throws InvalidInterfaceException |
||
1648 | * @throws ReflectionException |
||
1649 | */ |
||
1650 | public function decrease_sold($qty = 1) |
||
1660 | |||
1661 | |||
1662 | /** |
||
1663 | * Decreases sold on related datetimes |
||
1664 | * |
||
1665 | * @deprecated 4.9.80.p |
||
1666 | * @param int $qty |
||
1667 | * @return void |
||
1668 | * @throws EE_Error |
||
1669 | * @throws InvalidArgumentException |
||
1670 | * @throws InvalidDataTypeException |
||
1671 | * @throws InvalidInterfaceException |
||
1672 | * @throws ReflectionException |
||
1673 | */ |
||
1674 | protected function _decrease_sold_for_datetimes($qty = 1) |
||
1684 | |||
1685 | |||
1686 | /** |
||
1687 | * Increments reserved by amount passed by $qty, and persists it immediately to the database. |
||
1688 | * |
||
1689 | * @deprecated 4.9.80.p |
||
1690 | * @param int $qty |
||
1691 | * @param string $source |
||
1692 | * @return bool whether we successfully reserved the ticket or not. |
||
1693 | * @throws EE_Error |
||
1694 | * @throws InvalidArgumentException |
||
1695 | * @throws ReflectionException |
||
1696 | * @throws InvalidDataTypeException |
||
1697 | * @throws InvalidInterfaceException |
||
1698 | */ |
||
1699 | public function increase_reserved($qty = 1, $source = 'unknown') |
||
1709 | |||
1710 | |||
1711 | /** |
||
1712 | * Increases sold on related datetimes |
||
1713 | * |
||
1714 | * @deprecated 4.9.80.p |
||
1715 | * @param int $qty |
||
1716 | * @return boolean indicating success |
||
1717 | * @throws EE_Error |
||
1718 | * @throws InvalidArgumentException |
||
1719 | * @throws InvalidDataTypeException |
||
1720 | * @throws InvalidInterfaceException |
||
1721 | * @throws ReflectionException |
||
1722 | */ |
||
1723 | protected function _increase_reserved_for_datetimes($qty = 1) |
||
1733 | |||
1734 | |||
1735 | /** |
||
1736 | * Decrements (subtracts) reserved by amount passed by $qty, and persists it immediately to the database. |
||
1737 | * |
||
1738 | * @deprecated 4.9.80.p |
||
1739 | * @param int $qty |
||
1740 | * @param bool $adjust_datetimes |
||
1741 | * @param string $source |
||
1742 | * @return void |
||
1743 | * @throws EE_Error |
||
1744 | * @throws InvalidArgumentException |
||
1745 | * @throws ReflectionException |
||
1746 | * @throws InvalidDataTypeException |
||
1747 | * @throws InvalidInterfaceException |
||
1748 | */ |
||
1749 | public function decrease_reserved($qty = 1, $adjust_datetimes = true, $source = 'unknown') |
||
1759 | |||
1760 | |||
1761 | /** |
||
1762 | * Decreases reserved on related datetimes |
||
1763 | * |
||
1764 | * @deprecated 4.9.80.p |
||
1765 | * @param int $qty |
||
1766 | * @return void |
||
1767 | * @throws EE_Error |
||
1768 | * @throws InvalidArgumentException |
||
1769 | * @throws ReflectionException |
||
1770 | * @throws InvalidDataTypeException |
||
1771 | * @throws InvalidInterfaceException |
||
1772 | */ |
||
1773 | protected function _decrease_reserved_for_datetimes($qty = 1) |
||
1783 | } |
||
1784 |