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 | * The following constants are used by the ticket_status() method to indicate whether a ticket is on sale or not. |
||
| 19 | */ |
||
| 20 | const sold_out = 'TKS'; |
||
| 21 | |||
| 22 | /** |
||
| 23 | * |
||
| 24 | */ |
||
| 25 | const expired = 'TKE'; |
||
| 26 | |||
| 27 | /** |
||
| 28 | * |
||
| 29 | */ |
||
| 30 | const archived = 'TKA'; |
||
| 31 | |||
| 32 | /** |
||
| 33 | * |
||
| 34 | */ |
||
| 35 | const pending = 'TKP'; |
||
| 36 | |||
| 37 | /** |
||
| 38 | * |
||
| 39 | */ |
||
| 40 | const onsale = 'TKO'; |
||
| 41 | |||
| 42 | /** |
||
| 43 | * extra meta key for tracking ticket reservations |
||
| 44 | * |
||
| 45 | * @type string |
||
| 46 | */ |
||
| 47 | const META_KEY_TICKET_RESERVATIONS = 'ticket_reservations'; |
||
| 48 | |||
| 49 | /** |
||
| 50 | * cached result from method of the same name |
||
| 51 | * |
||
| 52 | * @var float $_ticket_total_with_taxes |
||
| 53 | */ |
||
| 54 | private $_ticket_total_with_taxes; |
||
| 55 | |||
| 56 | |||
| 57 | /** |
||
| 58 | * @param array $props_n_values incoming values |
||
| 59 | * @param string $timezone incoming timezone (if not set the timezone set for the website will be |
||
| 60 | * used.) |
||
| 61 | * @param array $date_formats incoming date_formats in an array where the first value is the |
||
| 62 | * date_format and the second value is the time format |
||
| 63 | * @return EE_Ticket |
||
| 64 | * @throws \EE_Error |
||
| 65 | */ |
||
| 66 | public static function new_instance($props_n_values = array(), $timezone = null, $date_formats = array()) |
||
| 71 | |||
| 72 | |||
| 73 | /** |
||
| 74 | * @param array $props_n_values incoming values from the database |
||
| 75 | * @param string $timezone incoming timezone as set by the model. If not set the timezone for |
||
| 76 | * the website will be used. |
||
| 77 | * @return EE_Ticket |
||
| 78 | * @throws \EE_Error |
||
| 79 | */ |
||
| 80 | public static function new_instance_from_db($props_n_values = array(), $timezone = null) |
||
| 84 | |||
| 85 | |||
| 86 | /** |
||
| 87 | * @return bool |
||
| 88 | * @throws \EE_Error |
||
| 89 | */ |
||
| 90 | public function parent() |
||
| 94 | |||
| 95 | |||
| 96 | /** |
||
| 97 | * return if a ticket has quantities available for purchase |
||
| 98 | * |
||
| 99 | * @param int $DTT_ID the primary key for a particular datetime |
||
| 100 | * @return boolean |
||
| 101 | * @throws \EE_Error |
||
| 102 | */ |
||
| 103 | public function available($DTT_ID = 0) |
||
| 117 | |||
| 118 | |||
| 119 | /** |
||
| 120 | * Using the start date and end date this method calculates whether the ticket is On Sale, Pending, or Expired |
||
| 121 | * |
||
| 122 | * @param bool $display true = we'll return a localized string, otherwise we just return the value of the |
||
| 123 | * relevant status const |
||
| 124 | * @param bool | null $remaining if it is already known that tickets are available, then simply pass a bool to save |
||
| 125 | * further processing |
||
| 126 | * @return mixed status int if the display string isn't requested |
||
| 127 | * @throws \EE_Error |
||
| 128 | */ |
||
| 129 | public function ticket_status($display = false, $remaining = null) |
||
| 149 | |||
| 150 | |||
| 151 | /** |
||
| 152 | * The purpose of this method is to simply return a boolean for whether there are any tickets remaining for sale |
||
| 153 | * considering ALL the factors used for figuring that out. |
||
| 154 | * |
||
| 155 | * @access public |
||
| 156 | * @param int $DTT_ID if an int above 0 is included here then we get a specific dtt. |
||
| 157 | * @return boolean true = tickets remaining, false not. |
||
| 158 | * @throws \EE_Error |
||
| 159 | */ |
||
| 160 | public function is_remaining($DTT_ID = 0) |
||
| 171 | |||
| 172 | |||
| 173 | /** |
||
| 174 | * return the total number of tickets available for purchase |
||
| 175 | * |
||
| 176 | * @param int $DTT_ID the primary key for a particular datetime. |
||
| 177 | * set to 0 for all related datetimes |
||
| 178 | * @return int |
||
| 179 | * @throws \EE_Error |
||
| 180 | */ |
||
| 181 | public function remaining($DTT_ID = 0) |
||
| 185 | |||
| 186 | |||
| 187 | /** |
||
| 188 | * Gets min |
||
| 189 | * |
||
| 190 | * @return int |
||
| 191 | * @throws \EE_Error |
||
| 192 | */ |
||
| 193 | public function min() |
||
| 197 | |||
| 198 | |||
| 199 | /** |
||
| 200 | * return if a ticket is no longer available cause its available dates have expired. |
||
| 201 | * |
||
| 202 | * @return boolean |
||
| 203 | * @throws \EE_Error |
||
| 204 | */ |
||
| 205 | public function is_expired() |
||
| 209 | |||
| 210 | |||
| 211 | /** |
||
| 212 | * Return if a ticket is yet to go on sale or not |
||
| 213 | * |
||
| 214 | * @return boolean |
||
| 215 | * @throws \EE_Error |
||
| 216 | */ |
||
| 217 | public function is_pending() |
||
| 221 | |||
| 222 | |||
| 223 | /** |
||
| 224 | * Return if a ticket is on sale or not |
||
| 225 | * |
||
| 226 | * @return boolean |
||
| 227 | * @throws \EE_Error |
||
| 228 | */ |
||
| 229 | public function is_on_sale() |
||
| 233 | |||
| 234 | |||
| 235 | /** |
||
| 236 | * This returns the chronologically last datetime that this ticket is associated with |
||
| 237 | * |
||
| 238 | * @param string $dt_frmt |
||
| 239 | * @param string $conjunction - conjunction junction what's your function ? this string joins the start date with |
||
| 240 | * the end date ie: Jan 01 "to" Dec 31 |
||
| 241 | * @return string |
||
| 242 | * @throws \EE_Error |
||
| 243 | */ |
||
| 244 | public function date_range($dt_frmt = '', $conjunction = ' - ') |
||
| 252 | |||
| 253 | |||
| 254 | /** |
||
| 255 | * This returns the chronologically first datetime that this ticket is associated with |
||
| 256 | * |
||
| 257 | * @return EE_Datetime |
||
| 258 | * @throws \EE_Error |
||
| 259 | */ |
||
| 260 | public function first_datetime() |
||
| 265 | |||
| 266 | |||
| 267 | /** |
||
| 268 | * Gets all the datetimes this ticket can be used for attending. |
||
| 269 | * Unless otherwise specified, orders datetimes by start date. |
||
| 270 | * |
||
| 271 | * @param array $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md |
||
| 272 | * @return EE_Datetime[]|EE_Base_Class[] |
||
| 273 | * @throws \EE_Error |
||
| 274 | */ |
||
| 275 | public function datetimes($query_params = array()) |
||
| 282 | |||
| 283 | |||
| 284 | /** |
||
| 285 | * This returns the chronologically last datetime that this ticket is associated with |
||
| 286 | * |
||
| 287 | * @return EE_Datetime |
||
| 288 | * @throws \EE_Error |
||
| 289 | */ |
||
| 290 | public function last_datetime() |
||
| 295 | |||
| 296 | |||
| 297 | /** |
||
| 298 | * This returns the total tickets sold depending on the given parameters. |
||
| 299 | * |
||
| 300 | * @param string $what Can be one of two options: 'ticket', 'datetime'. |
||
| 301 | * 'ticket' = total ticket sales for all datetimes this ticket is related to |
||
| 302 | * 'datetime' = total ticket sales for a specified datetime (required $dtt_id) |
||
| 303 | * 'datetime' = total ticket sales in the datetime_ticket table. |
||
| 304 | * If $dtt_id is not given then we return an array of sales indexed by datetime. |
||
| 305 | * If $dtt_id IS given then we return the tickets sold for that given datetime. |
||
| 306 | * @param int $dtt_id [optional] include the dtt_id with $what = 'datetime'. |
||
| 307 | * @return mixed (array|int) how many tickets have sold |
||
| 308 | * @throws \EE_Error |
||
| 309 | */ |
||
| 310 | public function tickets_sold($what = 'ticket', $dtt_id = null) |
||
| 340 | |||
| 341 | |||
| 342 | /** |
||
| 343 | * This returns an array indexed by datetime_id for tickets sold with this ticket. |
||
| 344 | * |
||
| 345 | * @return EE_Ticket[] |
||
| 346 | * @throws \EE_Error |
||
| 347 | */ |
||
| 348 | protected function _all_tickets_sold() |
||
| 361 | |||
| 362 | |||
| 363 | /** |
||
| 364 | * This returns the base price object for the ticket. |
||
| 365 | * |
||
| 366 | * @param bool $return_array whether to return as an array indexed by price id or just the object. |
||
| 367 | * @return EE_Price|EE_Base_Class|EE_Price[]|EE_Base_Class[] |
||
| 368 | * @throws \EE_Error |
||
| 369 | */ |
||
| 370 | public function base_price($return_array = false) |
||
| 377 | |||
| 378 | |||
| 379 | /** |
||
| 380 | * This returns ONLY the price modifiers for the ticket (i.e. no taxes or base price) |
||
| 381 | * |
||
| 382 | * @access public |
||
| 383 | * @return EE_Price[] |
||
| 384 | * @throws \EE_Error |
||
| 385 | */ |
||
| 386 | public function price_modifiers() |
||
| 398 | |||
| 399 | |||
| 400 | /** |
||
| 401 | * Gets all the prices that combine to form the final price of this ticket |
||
| 402 | * |
||
| 403 | * @param array $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md |
||
| 404 | * @return EE_Price[]|EE_Base_Class[] |
||
| 405 | * @throws \EE_Error |
||
| 406 | */ |
||
| 407 | public function prices($query_params = array()) |
||
| 411 | |||
| 412 | |||
| 413 | /** |
||
| 414 | * Gets all the ticket applicabilities (ie, relations between datetimes and tickets) |
||
| 415 | * |
||
| 416 | * @param array $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md |
||
| 417 | * @return EE_Datetime_Ticket|EE_Base_Class[] |
||
| 418 | * @throws \EE_Error |
||
| 419 | */ |
||
| 420 | public function datetime_tickets($query_params = array()) |
||
| 424 | |||
| 425 | |||
| 426 | /** |
||
| 427 | * Gets all the datetimes from the db ordered by DTT_order |
||
| 428 | * |
||
| 429 | * @param boolean $show_expired |
||
| 430 | * @param boolean $show_deleted |
||
| 431 | * @return EE_Datetime[] |
||
| 432 | * @throws \EE_Error |
||
| 433 | */ |
||
| 434 | public function datetimes_ordered($show_expired = true, $show_deleted = false) |
||
| 442 | |||
| 443 | |||
| 444 | /** |
||
| 445 | * Gets ID |
||
| 446 | * |
||
| 447 | * @return string |
||
| 448 | * @throws \EE_Error |
||
| 449 | */ |
||
| 450 | public function ID() |
||
| 454 | |||
| 455 | |||
| 456 | /** |
||
| 457 | * get the author of the ticket. |
||
| 458 | * |
||
| 459 | * @since 4.5.0 |
||
| 460 | * @return int |
||
| 461 | * @throws \EE_Error |
||
| 462 | */ |
||
| 463 | public function wp_user() |
||
| 467 | |||
| 468 | |||
| 469 | /** |
||
| 470 | * Gets the template for the ticket |
||
| 471 | * |
||
| 472 | * @return EE_Ticket_Template|EE_Base_Class |
||
| 473 | * @throws \EE_Error |
||
| 474 | */ |
||
| 475 | public function template() |
||
| 479 | |||
| 480 | |||
| 481 | /** |
||
| 482 | * Simply returns an array of EE_Price objects that are taxes. |
||
| 483 | * |
||
| 484 | * @return EE_Price[] |
||
| 485 | * @throws \EE_Error |
||
| 486 | */ |
||
| 487 | public function get_ticket_taxes_for_admin() |
||
| 491 | |||
| 492 | |||
| 493 | /** |
||
| 494 | * @return float |
||
| 495 | * @throws \EE_Error |
||
| 496 | */ |
||
| 497 | public function ticket_price() |
||
| 501 | |||
| 502 | |||
| 503 | /** |
||
| 504 | * @return mixed |
||
| 505 | * @throws \EE_Error |
||
| 506 | */ |
||
| 507 | public function pretty_price() |
||
| 511 | |||
| 512 | |||
| 513 | /** |
||
| 514 | * @return bool |
||
| 515 | * @throws \EE_Error |
||
| 516 | */ |
||
| 517 | public function is_free() |
||
| 521 | |||
| 522 | |||
| 523 | /** |
||
| 524 | * get_ticket_total_with_taxes |
||
| 525 | * |
||
| 526 | * @param bool $no_cache |
||
| 527 | * @return float |
||
| 528 | * @throws \EE_Error |
||
| 529 | */ |
||
| 530 | public function get_ticket_total_with_taxes($no_cache = false) |
||
| 537 | |||
| 538 | |||
| 539 | public function ensure_TKT_Price_correct() |
||
| 544 | |||
| 545 | |||
| 546 | /** |
||
| 547 | * @return float |
||
| 548 | * @throws \EE_Error |
||
| 549 | */ |
||
| 550 | public function get_ticket_subtotal() |
||
| 554 | |||
| 555 | |||
| 556 | /** |
||
| 557 | * Returns the total taxes applied to this ticket |
||
| 558 | * |
||
| 559 | * @return float |
||
| 560 | * @throws \EE_Error |
||
| 561 | */ |
||
| 562 | public function get_ticket_taxes_total_for_admin() |
||
| 566 | |||
| 567 | |||
| 568 | /** |
||
| 569 | * Sets name |
||
| 570 | * |
||
| 571 | * @param string $name |
||
| 572 | * @throws \EE_Error |
||
| 573 | */ |
||
| 574 | public function set_name($name) |
||
| 578 | |||
| 579 | |||
| 580 | /** |
||
| 581 | * Gets description |
||
| 582 | * |
||
| 583 | * @return string |
||
| 584 | * @throws \EE_Error |
||
| 585 | */ |
||
| 586 | public function description() |
||
| 590 | |||
| 591 | |||
| 592 | /** |
||
| 593 | * Sets description |
||
| 594 | * |
||
| 595 | * @param string $description |
||
| 596 | * @throws \EE_Error |
||
| 597 | */ |
||
| 598 | public function set_description($description) |
||
| 602 | |||
| 603 | |||
| 604 | /** |
||
| 605 | * Gets start_date |
||
| 606 | * |
||
| 607 | * @param string $dt_frmt |
||
| 608 | * @param string $tm_frmt |
||
| 609 | * @return string |
||
| 610 | * @throws \EE_Error |
||
| 611 | */ |
||
| 612 | public function start_date($dt_frmt = '', $tm_frmt = '') |
||
| 616 | |||
| 617 | |||
| 618 | /** |
||
| 619 | * Sets start_date |
||
| 620 | * |
||
| 621 | * @param string $start_date |
||
| 622 | * @return void |
||
| 623 | * @throws \EE_Error |
||
| 624 | */ |
||
| 625 | public function set_start_date($start_date) |
||
| 629 | |||
| 630 | |||
| 631 | /** |
||
| 632 | * Gets end_date |
||
| 633 | * |
||
| 634 | * @param string $dt_frmt |
||
| 635 | * @param string $tm_frmt |
||
| 636 | * @return string |
||
| 637 | * @throws \EE_Error |
||
| 638 | */ |
||
| 639 | public function end_date($dt_frmt = '', $tm_frmt = '') |
||
| 643 | |||
| 644 | |||
| 645 | /** |
||
| 646 | * Sets end_date |
||
| 647 | * |
||
| 648 | * @param string $end_date |
||
| 649 | * @return void |
||
| 650 | * @throws \EE_Error |
||
| 651 | */ |
||
| 652 | public function set_end_date($end_date) |
||
| 656 | |||
| 657 | |||
| 658 | /** |
||
| 659 | * Sets sell until time |
||
| 660 | * |
||
| 661 | * @since 4.5.0 |
||
| 662 | * @param string $time a string representation of the sell until time (ex 9am or 7:30pm) |
||
| 663 | * @throws \EE_Error |
||
| 664 | */ |
||
| 665 | public function set_end_time($time) |
||
| 669 | |||
| 670 | |||
| 671 | /** |
||
| 672 | * Sets min |
||
| 673 | * |
||
| 674 | * @param int $min |
||
| 675 | * @return void |
||
| 676 | * @throws \EE_Error |
||
| 677 | */ |
||
| 678 | public function set_min($min) |
||
| 682 | |||
| 683 | |||
| 684 | /** |
||
| 685 | * Gets max |
||
| 686 | * |
||
| 687 | * @return int |
||
| 688 | * @throws \EE_Error |
||
| 689 | */ |
||
| 690 | public function max() |
||
| 694 | |||
| 695 | |||
| 696 | /** |
||
| 697 | * Sets max |
||
| 698 | * |
||
| 699 | * @param int $max |
||
| 700 | * @return void |
||
| 701 | * @throws \EE_Error |
||
| 702 | */ |
||
| 703 | public function set_max($max) |
||
| 707 | |||
| 708 | |||
| 709 | /** |
||
| 710 | * Sets price |
||
| 711 | * |
||
| 712 | * @param float $price |
||
| 713 | * @return void |
||
| 714 | * @throws \EE_Error |
||
| 715 | */ |
||
| 716 | public function set_price($price) |
||
| 720 | |||
| 721 | |||
| 722 | /** |
||
| 723 | * Gets sold |
||
| 724 | * |
||
| 725 | * @return int |
||
| 726 | * @throws \EE_Error |
||
| 727 | */ |
||
| 728 | public function sold() |
||
| 732 | |||
| 733 | |||
| 734 | /** |
||
| 735 | * Sets sold |
||
| 736 | * |
||
| 737 | * @param int $sold |
||
| 738 | * @return void |
||
| 739 | * @throws \EE_Error |
||
| 740 | */ |
||
| 741 | public function set_sold($sold) |
||
| 747 | |||
| 748 | |||
| 749 | /** |
||
| 750 | * Increments sold by amount passed by $qty AND decrements the reserved count on both this ticket and its |
||
| 751 | * associated datetimes. |
||
| 752 | * |
||
| 753 | * @param int $qty |
||
| 754 | * @return void |
||
| 755 | * @throws EE_Error |
||
| 756 | * @throws InvalidArgumentException |
||
| 757 | * @throws InvalidDataTypeException |
||
| 758 | * @throws InvalidInterfaceException |
||
| 759 | * @throws ReflectionException |
||
| 760 | */ |
||
| 761 | public function increase_sold($qty = 1) |
||
| 781 | |||
| 782 | /** |
||
| 783 | * On each datetiem related to this ticket, increases its sold count and decreases its reserved count by $qty. |
||
| 784 | * @since $VID:$ |
||
| 785 | * @param int $qty positive or negative. Positive means to increase sold counts (and decrease reserved counts), |
||
| 786 | * Negative means to decreases old counts (and increase reserved counts). |
||
| 787 | * @throws EE_Error |
||
| 788 | * @throws InvalidArgumentException |
||
| 789 | * @throws InvalidDataTypeException |
||
| 790 | * @throws InvalidInterfaceException |
||
| 791 | * @throws ReflectionException |
||
| 792 | */ |
||
| 793 | protected function sellDatetimes($qty) |
||
| 805 | |||
| 806 | |||
| 807 | /** |
||
| 808 | * Decrements (subtracts) sold by amount passed by $qty on both the ticket and its related datetimes directly in the |
||
| 809 | * DB and then updates the model objects. |
||
| 810 | * Does not affect the reserved counts. |
||
| 811 | * |
||
| 812 | * @param int $qty |
||
| 813 | * @return void |
||
| 814 | * @throws EE_Error |
||
| 815 | * @throws InvalidArgumentException |
||
| 816 | * @throws InvalidDataTypeException |
||
| 817 | * @throws InvalidInterfaceException |
||
| 818 | * @throws ReflectionException |
||
| 819 | */ |
||
| 820 | public function decrease_sold($qty = 1) |
||
| 838 | |||
| 839 | |||
| 840 | /** |
||
| 841 | * Gets qty of reserved tickets |
||
| 842 | * |
||
| 843 | * @return int |
||
| 844 | * @throws \EE_Error |
||
| 845 | */ |
||
| 846 | public function reserved() |
||
| 850 | |||
| 851 | |||
| 852 | /** |
||
| 853 | * Sets reserved |
||
| 854 | * |
||
| 855 | * @param int $reserved |
||
| 856 | * @return void |
||
| 857 | * @throws \EE_Error |
||
| 858 | */ |
||
| 859 | public function set_reserved($reserved) |
||
| 865 | |||
| 866 | |||
| 867 | /** |
||
| 868 | * Increments reserved by amount passed by $qty, and persists it immediately to the database. |
||
| 869 | * |
||
| 870 | * @param int $qty |
||
| 871 | * @param string $source |
||
| 872 | * @return bool whether we successfully reserved the ticket or not. |
||
| 873 | * @throws EE_Error |
||
| 874 | * @throws InvalidArgumentException |
||
| 875 | * @throws ReflectionException |
||
| 876 | * @throws InvalidDataTypeException |
||
| 877 | * @throws InvalidInterfaceException |
||
| 878 | */ |
||
| 879 | public function increase_reserved($qty = 1, $source = 'unknown') |
||
| 919 | |||
| 920 | |||
| 921 | /** |
||
| 922 | * Increases sold on related datetimes |
||
| 923 | * |
||
| 924 | * @param int $qty |
||
| 925 | * @return boolean indicating success |
||
| 926 | * @throws \EE_Error |
||
| 927 | */ |
||
| 928 | protected function _increase_reserved_for_datetimes($qty = 1) |
||
| 953 | |||
| 954 | /** |
||
| 955 | * Decreases the reserved count on the specified datetimes. |
||
| 956 | * @since $VID:$ |
||
| 957 | * @param EE_Datetime[] $datetimes |
||
| 958 | * @param int $qty |
||
| 959 | * @throws EE_Error |
||
| 960 | * @throws InvalidArgumentException |
||
| 961 | * @throws ReflectionException |
||
| 962 | * @throws InvalidDataTypeException |
||
| 963 | * @throws InvalidInterfaceException |
||
| 964 | */ |
||
| 965 | protected function decreaseReservedForDatetimes($datetimes, $qty = 1) { |
||
| 972 | |||
| 973 | |||
| 974 | /** |
||
| 975 | * Decrements (subtracts) reserved by amount passed by $qty, and persists it immediately to the database. |
||
| 976 | * |
||
| 977 | * @param int $qty |
||
| 978 | * @param bool $adjust_datetimes |
||
| 979 | * @param string $source |
||
| 980 | * @return void |
||
| 981 | * @throws EE_Error |
||
| 982 | * @throws InvalidArgumentException |
||
| 983 | * @throws ReflectionException |
||
| 984 | * @throws InvalidDataTypeException |
||
| 985 | * @throws InvalidInterfaceException |
||
| 986 | */ |
||
| 987 | public function decrease_reserved($qty = 1, $adjust_datetimes = true, $source = 'unknown') |
||
| 1011 | |||
| 1012 | |||
| 1013 | /** |
||
| 1014 | * Decreases reserved on related datetimes |
||
| 1015 | * |
||
| 1016 | * @param int $qty |
||
| 1017 | * @return void |
||
| 1018 | * @throws EE_Error |
||
| 1019 | * @throws InvalidArgumentException |
||
| 1020 | * @throws ReflectionException |
||
| 1021 | * @throws InvalidDataTypeException |
||
| 1022 | * @throws InvalidInterfaceException |
||
| 1023 | */ |
||
| 1024 | protected function _decrease_reserved_for_datetimes($qty = 1) |
||
| 1028 | |||
| 1029 | |||
| 1030 | /** |
||
| 1031 | * Gets ticket quantity |
||
| 1032 | * |
||
| 1033 | * @param string $context ticket quantity is somewhat subjective depending on the exact information sought |
||
| 1034 | * therefore $context can be one of three values: '', 'reg_limit', or 'saleable' |
||
| 1035 | * '' (default) quantity is the actual db value for TKT_qty, unaffected by other objects |
||
| 1036 | * REG LIMIT: caps qty based on DTT_reg_limit for ALL related datetimes |
||
| 1037 | * SALEABLE: also considers datetime sold and returns zero if ANY DTT is sold out, and |
||
| 1038 | * is therefore the truest measure of tickets that can be purchased at the moment |
||
| 1039 | * @return int |
||
| 1040 | * @throws \EE_Error |
||
| 1041 | */ |
||
| 1042 | public function qty($context = '') |
||
| 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 two values: 'reg_limit', or 'saleable' |
||
| 1060 | * REG LIMIT: caps qty based on DTT_reg_limit for ALL related datetimes |
||
| 1061 | * SALEABLE: also considers datetime sold and returns zero if ANY DTT is sold out, and |
||
| 1062 | * is therefore the truest measure of tickets that can be purchased at the moment |
||
| 1063 | * @param int $DTT_ID the primary key for a particular datetime. |
||
| 1064 | * set to 0 for all related datetimes |
||
| 1065 | * @return int |
||
| 1066 | * @throws \EE_Error |
||
| 1067 | */ |
||
| 1068 | public function real_quantity_on_ticket($context = 'reg_limit', $DTT_ID = 0) |
||
| 1129 | |||
| 1130 | |||
| 1131 | /** |
||
| 1132 | * Sets qty - IMPORTANT!!! Does NOT allow QTY to be set higher than the lowest reg limit of any related datetimes |
||
| 1133 | * |
||
| 1134 | * @param int $qty |
||
| 1135 | * @return void |
||
| 1136 | * @throws \EE_Error |
||
| 1137 | */ |
||
| 1138 | public function set_qty($qty) |
||
| 1148 | |||
| 1149 | |||
| 1150 | /** |
||
| 1151 | * Gets uses |
||
| 1152 | * |
||
| 1153 | * @return int |
||
| 1154 | * @throws \EE_Error |
||
| 1155 | */ |
||
| 1156 | public function uses() |
||
| 1160 | |||
| 1161 | |||
| 1162 | /** |
||
| 1163 | * Sets uses |
||
| 1164 | * |
||
| 1165 | * @param int $uses |
||
| 1166 | * @return void |
||
| 1167 | * @throws \EE_Error |
||
| 1168 | */ |
||
| 1169 | public function set_uses($uses) |
||
| 1173 | |||
| 1174 | |||
| 1175 | /** |
||
| 1176 | * returns whether ticket is required or not. |
||
| 1177 | * |
||
| 1178 | * @return boolean |
||
| 1179 | * @throws \EE_Error |
||
| 1180 | */ |
||
| 1181 | public function required() |
||
| 1185 | |||
| 1186 | |||
| 1187 | /** |
||
| 1188 | * sets the TKT_required property |
||
| 1189 | * |
||
| 1190 | * @param boolean $required |
||
| 1191 | * @return void |
||
| 1192 | * @throws \EE_Error |
||
| 1193 | */ |
||
| 1194 | public function set_required($required) |
||
| 1198 | |||
| 1199 | |||
| 1200 | /** |
||
| 1201 | * Gets taxable |
||
| 1202 | * |
||
| 1203 | * @return boolean |
||
| 1204 | * @throws \EE_Error |
||
| 1205 | */ |
||
| 1206 | public function taxable() |
||
| 1210 | |||
| 1211 | |||
| 1212 | /** |
||
| 1213 | * Sets taxable |
||
| 1214 | * |
||
| 1215 | * @param boolean $taxable |
||
| 1216 | * @return void |
||
| 1217 | * @throws \EE_Error |
||
| 1218 | */ |
||
| 1219 | public function set_taxable($taxable) |
||
| 1223 | |||
| 1224 | |||
| 1225 | /** |
||
| 1226 | * Gets is_default |
||
| 1227 | * |
||
| 1228 | * @return boolean |
||
| 1229 | * @throws \EE_Error |
||
| 1230 | */ |
||
| 1231 | public function is_default() |
||
| 1235 | |||
| 1236 | |||
| 1237 | /** |
||
| 1238 | * Sets is_default |
||
| 1239 | * |
||
| 1240 | * @param boolean $is_default |
||
| 1241 | * @return void |
||
| 1242 | * @throws \EE_Error |
||
| 1243 | */ |
||
| 1244 | public function set_is_default($is_default) |
||
| 1248 | |||
| 1249 | |||
| 1250 | /** |
||
| 1251 | * Gets order |
||
| 1252 | * |
||
| 1253 | * @return int |
||
| 1254 | * @throws \EE_Error |
||
| 1255 | */ |
||
| 1256 | public function order() |
||
| 1260 | |||
| 1261 | |||
| 1262 | /** |
||
| 1263 | * Sets order |
||
| 1264 | * |
||
| 1265 | * @param int $order |
||
| 1266 | * @return void |
||
| 1267 | * @throws \EE_Error |
||
| 1268 | */ |
||
| 1269 | public function set_order($order) |
||
| 1273 | |||
| 1274 | |||
| 1275 | /** |
||
| 1276 | * Gets row |
||
| 1277 | * |
||
| 1278 | * @return int |
||
| 1279 | * @throws \EE_Error |
||
| 1280 | */ |
||
| 1281 | public function row() |
||
| 1285 | |||
| 1286 | |||
| 1287 | /** |
||
| 1288 | * Sets row |
||
| 1289 | * |
||
| 1290 | * @param int $row |
||
| 1291 | * @return void |
||
| 1292 | * @throws \EE_Error |
||
| 1293 | */ |
||
| 1294 | public function set_row($row) |
||
| 1298 | |||
| 1299 | |||
| 1300 | /** |
||
| 1301 | * Gets deleted |
||
| 1302 | * |
||
| 1303 | * @return boolean |
||
| 1304 | * @throws \EE_Error |
||
| 1305 | */ |
||
| 1306 | public function deleted() |
||
| 1310 | |||
| 1311 | |||
| 1312 | /** |
||
| 1313 | * Sets deleted |
||
| 1314 | * |
||
| 1315 | * @param boolean $deleted |
||
| 1316 | * @return void |
||
| 1317 | * @throws \EE_Error |
||
| 1318 | */ |
||
| 1319 | public function set_deleted($deleted) |
||
| 1323 | |||
| 1324 | |||
| 1325 | /** |
||
| 1326 | * Gets parent |
||
| 1327 | * |
||
| 1328 | * @return int |
||
| 1329 | * @throws \EE_Error |
||
| 1330 | */ |
||
| 1331 | public function parent_ID() |
||
| 1335 | |||
| 1336 | |||
| 1337 | /** |
||
| 1338 | * Sets parent |
||
| 1339 | * |
||
| 1340 | * @param int $parent |
||
| 1341 | * @return void |
||
| 1342 | * @throws \EE_Error |
||
| 1343 | */ |
||
| 1344 | public function set_parent_ID($parent) |
||
| 1348 | |||
| 1349 | |||
| 1350 | /** |
||
| 1351 | * Gets a string which is handy for showing in gateways etc that describes the ticket. |
||
| 1352 | * |
||
| 1353 | * @return string |
||
| 1354 | * @throws \EE_Error |
||
| 1355 | */ |
||
| 1356 | public function name_and_info() |
||
| 1364 | |||
| 1365 | |||
| 1366 | /** |
||
| 1367 | * Gets name |
||
| 1368 | * |
||
| 1369 | * @return string |
||
| 1370 | * @throws \EE_Error |
||
| 1371 | */ |
||
| 1372 | public function name() |
||
| 1376 | |||
| 1377 | |||
| 1378 | /** |
||
| 1379 | * Gets price |
||
| 1380 | * |
||
| 1381 | * @return float |
||
| 1382 | * @throws \EE_Error |
||
| 1383 | */ |
||
| 1384 | public function price() |
||
| 1388 | |||
| 1389 | |||
| 1390 | /** |
||
| 1391 | * Gets all the registrations for this ticket |
||
| 1392 | * |
||
| 1393 | * @param array $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md |
||
| 1394 | * @return EE_Registration[]|EE_Base_Class[] |
||
| 1395 | * @throws \EE_Error |
||
| 1396 | */ |
||
| 1397 | public function registrations($query_params = array()) |
||
| 1401 | |||
| 1402 | |||
| 1403 | /** |
||
| 1404 | * Updates the TKT_sold attribute (and saves) based on the number of APPROVED registrations for this ticket. |
||
| 1405 | * into account |
||
| 1406 | * |
||
| 1407 | * @return int |
||
| 1408 | * @throws \EE_Error |
||
| 1409 | */ |
||
| 1410 | View Code Duplication | public function update_tickets_sold() |
|
| 1428 | |||
| 1429 | |||
| 1430 | /** |
||
| 1431 | * Counts the registrations for this ticket |
||
| 1432 | * |
||
| 1433 | * @param array $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md |
||
| 1434 | * @return int |
||
| 1435 | */ |
||
| 1436 | public function count_registrations($query_params = array()) |
||
| 1440 | |||
| 1441 | |||
| 1442 | /** |
||
| 1443 | * Implementation for EEI_Has_Icon interface method. |
||
| 1444 | * |
||
| 1445 | * @see EEI_Visual_Representation for comments |
||
| 1446 | * @return string |
||
| 1447 | */ |
||
| 1448 | public function get_icon() |
||
| 1452 | |||
| 1453 | |||
| 1454 | /** |
||
| 1455 | * Implementation of the EEI_Event_Relation interface method |
||
| 1456 | * |
||
| 1457 | * @see EEI_Event_Relation for comments |
||
| 1458 | * @return EE_Event |
||
| 1459 | * @throws \EE_Error |
||
| 1460 | * @throws UnexpectedEntityException |
||
| 1461 | */ |
||
| 1462 | public function get_related_event() |
||
| 1489 | |||
| 1490 | |||
| 1491 | /** |
||
| 1492 | * Implementation of the EEI_Event_Relation interface method |
||
| 1493 | * |
||
| 1494 | * @see EEI_Event_Relation for comments |
||
| 1495 | * @return string |
||
| 1496 | * @throws UnexpectedEntityException |
||
| 1497 | * @throws \EE_Error |
||
| 1498 | */ |
||
| 1499 | public function get_event_name() |
||
| 1504 | |||
| 1505 | |||
| 1506 | /** |
||
| 1507 | * Implementation of the EEI_Event_Relation interface method |
||
| 1508 | * |
||
| 1509 | * @see EEI_Event_Relation for comments |
||
| 1510 | * @return int |
||
| 1511 | * @throws UnexpectedEntityException |
||
| 1512 | * @throws \EE_Error |
||
| 1513 | */ |
||
| 1514 | public function get_event_ID() |
||
| 1519 | |||
| 1520 | |||
| 1521 | /** |
||
| 1522 | * This simply returns whether a ticket can be permanently deleted or not. |
||
| 1523 | * The criteria for determining this is whether the ticket has any related registrations. |
||
| 1524 | * If there are none then it can be permanently deleted. |
||
| 1525 | * |
||
| 1526 | * @return bool |
||
| 1527 | */ |
||
| 1528 | public function is_permanently_deleteable() |
||
| 1532 | } |
||
| 1533 |