@@ -1,91 +1,91 @@ |
||
| 1 | 1 | <div id="ee-single-page-checkout-dv" class=""> |
| 2 | 2 | <?php |
| 3 | - if (! $empty_cart) { |
|
| 4 | - if (apply_filters('FHEE__registration_page_wrapper_template__display_time_limit', false)) { ?> |
|
| 3 | + if (! $empty_cart) { |
|
| 4 | + if (apply_filters('FHEE__registration_page_wrapper_template__display_time_limit', false)) { ?> |
|
| 5 | 5 | <p id="spco-registration-time-limit-pg" class="spco-steps-pg ee-attention important-notice" |
| 6 | 6 | style="display: none;"> |
| 7 | 7 | <?php echo sprintf( |
| 8 | - apply_filters( |
|
| 9 | - 'FHEE__registration_page_wrapper_template___time_limit', |
|
| 10 | - __('You have %1$s to complete your registration.', 'event_espresso') |
|
| 11 | - ), |
|
| 12 | - '<span id="spco-registration-time-limit-spn" class="spco-registration-time-limit-spn">' . $registration_time_limit . '</span>' |
|
| 13 | - ); |
|
| 14 | - ?> |
|
| 8 | + apply_filters( |
|
| 9 | + 'FHEE__registration_page_wrapper_template___time_limit', |
|
| 10 | + __('You have %1$s to complete your registration.', 'event_espresso') |
|
| 11 | + ), |
|
| 12 | + '<span id="spco-registration-time-limit-spn" class="spco-registration-time-limit-spn">' . $registration_time_limit . '</span>' |
|
| 13 | + ); |
|
| 14 | + ?> |
|
| 15 | 15 | <span id="spco-registration-expiration-spn" class="" style="display:none;"></span> |
| 16 | 16 | </p> |
| 17 | 17 | <?php } |
| 18 | - if (! $revisit && apply_filters('FHEE__registration_page_wrapper_template__steps_display', true)) { |
|
| 19 | - ?> |
|
| 18 | + if (! $revisit && apply_filters('FHEE__registration_page_wrapper_template__steps_display', true)) { |
|
| 19 | + ?> |
|
| 20 | 20 | <h2 id="spco-steps-big-hdr" class="spco-steps-big-hdr"><?php _e(' Steps', 'event_espresso'); ?></h2> |
| 21 | 21 | |
| 22 | 22 | <div id="spco-steps-display-dv"> |
| 23 | 23 | <?php |
| 24 | - $step_nmbr = 1; |
|
| 25 | - $total_steps = count($reg_steps) - 1; |
|
| 26 | - foreach ($reg_steps as $reg_step) { |
|
| 27 | - if ($reg_step instanceof EE_SPCO_Reg_Step && $reg_step->slug() != 'finalize_registration') { |
|
| 28 | - $slug = $reg_step->slug(); |
|
| 29 | - $step_display_dv_class = $reg_step->is_current_step() ? 'active-step' : 'inactive-step'; |
|
| 30 | - ?> |
|
| 24 | + $step_nmbr = 1; |
|
| 25 | + $total_steps = count($reg_steps) - 1; |
|
| 26 | + foreach ($reg_steps as $reg_step) { |
|
| 27 | + if ($reg_step instanceof EE_SPCO_Reg_Step && $reg_step->slug() != 'finalize_registration') { |
|
| 28 | + $slug = $reg_step->slug(); |
|
| 29 | + $step_display_dv_class = $reg_step->is_current_step() ? 'active-step' : 'inactive-step'; |
|
| 30 | + ?> |
|
| 31 | 31 | <div id="spco-step-<?php echo $slug; ?>-display-dv" |
| 32 | 32 | class="spco-step-display-dv <?php echo $step_display_dv_class; ?> steps-<?php echo $total_steps; ?>"> |
| 33 | 33 | <h4 id="spco-step-<?php echo $slug; ?>-display-hdr" class="spco-steps-display-hdr"> |
| 34 | 34 | <span class="spco-step-big-nmbr"><?php echo $step_nmbr; ?></span> |
| 35 | 35 | <span class="spco-step-name"> |
| 36 | 36 | <?php echo str_replace( |
| 37 | - ' ', |
|
| 38 | - '<br/> ', |
|
| 39 | - $reg_step->name() |
|
| 40 | - ); ?> |
|
| 37 | + ' ', |
|
| 38 | + '<br/> ', |
|
| 39 | + $reg_step->name() |
|
| 40 | + ); ?> |
|
| 41 | 41 | </span> |
| 42 | 42 | </h4> |
| 43 | 43 | </div> |
| 44 | 44 | |
| 45 | 45 | <?php |
| 46 | - if ($step_nmbr < $total_steps) { ?> |
|
| 46 | + if ($step_nmbr < $total_steps) { ?> |
|
| 47 | 47 | <div class="spco-step-arrow-dv">»</div> |
| 48 | 48 | <?php |
| 49 | - } |
|
| 50 | - $step_nmbr++; |
|
| 51 | - } |
|
| 52 | - } |
|
| 53 | - ?> |
|
| 49 | + } |
|
| 50 | + $step_nmbr++; |
|
| 51 | + } |
|
| 52 | + } |
|
| 53 | + ?> |
|
| 54 | 54 | <div class="clear-float"></div> |
| 55 | 55 | </div> |
| 56 | 56 | |
| 57 | 57 | <?php |
| 58 | - } |
|
| 58 | + } |
|
| 59 | 59 | |
| 60 | - do_action('AHEE__SPCO__before_registration_steps'); |
|
| 61 | - $step_nmbr = 1; |
|
| 62 | - foreach ($reg_steps as $reg_step) { |
|
| 63 | - if ($reg_step instanceof EE_SPCO_Reg_Step && $reg_step->slug() != 'finalize_registration') { |
|
| 64 | - $slug = $reg_step->slug(); |
|
| 65 | - do_action('AHEE__' . $slug . '__reg_step_start', $reg_step); |
|
| 66 | - // todo: deprecate hook AHEE__registration_page_attendee_information__start |
|
| 67 | - ?> |
|
| 60 | + do_action('AHEE__SPCO__before_registration_steps'); |
|
| 61 | + $step_nmbr = 1; |
|
| 62 | + foreach ($reg_steps as $reg_step) { |
|
| 63 | + if ($reg_step instanceof EE_SPCO_Reg_Step && $reg_step->slug() != 'finalize_registration') { |
|
| 64 | + $slug = $reg_step->slug(); |
|
| 65 | + do_action('AHEE__' . $slug . '__reg_step_start', $reg_step); |
|
| 66 | + // todo: deprecate hook AHEE__registration_page_attendee_information__start |
|
| 67 | + ?> |
|
| 68 | 68 | <div id="spco-<?php echo $slug; ?>-dv" class="spco-step-dv <?php echo $reg_step->div_class(); ?>"> |
| 69 | 69 | <?php echo $reg_step->display_reg_form(); ?> |
| 70 | 70 | <?php do_action('AHEE__SPCO_after_reg_step_form', $slug, $next_step); ?> |
| 71 | 71 | </div> |
| 72 | 72 | <?php $step_nmbr++; |
| 73 | - } |
|
| 74 | - } |
|
| 75 | - do_action('AHEE__SPCO__after_registration_steps'); |
|
| 76 | - } else { |
|
| 77 | - ?> |
|
| 73 | + } |
|
| 74 | + } |
|
| 75 | + do_action('AHEE__SPCO__after_registration_steps'); |
|
| 76 | + } else { |
|
| 77 | + ?> |
|
| 78 | 78 | <h3 id="spco-empty-cart-hdr" class="spco-step-title-hdr"> |
| 79 | 79 | <?php esc_html_e( |
| 80 | - 'Nothing in your Event Queue', |
|
| 81 | - 'event_espresso' |
|
| 82 | - ); ?></h3> |
|
| 80 | + 'Nothing in your Event Queue', |
|
| 81 | + 'event_espresso' |
|
| 82 | + ); ?></h3> |
|
| 83 | 83 | <p><?php echo $empty_msg; ?></p> |
| 84 | 84 | <?php echo $cookies_not_set_msg; ?> |
| 85 | 85 | <?php |
| 86 | - } |
|
| 87 | - do_action('AHEE__SPCO__reg_form_footer'); |
|
| 88 | - ?> |
|
| 86 | + } |
|
| 87 | + do_action('AHEE__SPCO__reg_form_footer'); |
|
| 88 | + ?> |
|
| 89 | 89 | |
| 90 | 90 | </div> |
| 91 | 91 | |
@@ -3,7 +3,7 @@ discard block |
||
| 3 | 3 | /** @var array $ticket_line_item */ |
| 4 | 4 | /** @var string $default_hidden_inputs */ |
| 5 | 5 | ?> |
| 6 | -<?php if (!is_admin()) : ?> |
|
| 6 | +<?php if ( ! is_admin()) : ?> |
|
| 7 | 7 | <p id="spco-attendee_information-pg" class="spco-steps-pg small-text drk-grey-text"> |
| 8 | 8 | <?php echo apply_filters( |
| 9 | 9 | 'FHEE__registration_page_attendee_information__attendee_information_pg', |
@@ -33,15 +33,15 @@ discard block |
||
| 33 | 33 | <div id="spco-attendee-panel-dv-<?php echo $registration->reg_url_link(); ?>" |
| 34 | 34 | class="spco-attendee-panel-dv spco-attendee-ticket-<?php echo $registration->ticket()->ID(); ?>"> |
| 35 | 35 | |
| 36 | - <?php if (!is_admin() && $registration->event()->ID() !== $prev_event) { ?> |
|
| 36 | + <?php if ( ! is_admin() && $registration->event()->ID() !== $prev_event) { ?> |
|
| 37 | 37 | <h4 id="event_title-<?php echo $registration->event()->ID() ?>" class="big-event-title-hdr"> |
| 38 | 38 | <?php echo $registration->event()->name(); ?> |
| 39 | 39 | </h4> |
| 40 | 40 | <?php } ?> |
| 41 | 41 | <?php if ($registration->ticket()->ID() !== $prev_ticket) { ?> |
| 42 | - <?php if (! $revisit) { ?> |
|
| 42 | + <?php if ( ! $revisit) { ?> |
|
| 43 | 43 | <div class="spco-ticket-info-dv"> |
| 44 | - <?php if (!is_admin()) : ?> |
|
| 44 | + <?php if ( ! is_admin()) : ?> |
|
| 45 | 45 | <h5><?php _e('Details', 'event_espresso'); ?></h5> |
| 46 | 46 | <?php endif; ?> |
| 47 | 47 | <table class="spco-ticket-details"> |
@@ -66,7 +66,7 @@ discard block |
||
| 66 | 66 | </tr> |
| 67 | 67 | </thead> |
| 68 | 68 | <tbody> |
| 69 | - <?php echo $ticket_line_item[ $registration->ticket()->ID() ]; ?> |
|
| 69 | + <?php echo $ticket_line_item[$registration->ticket()->ID()]; ?> |
|
| 70 | 70 | </tbody> |
| 71 | 71 | </table> |
| 72 | 72 | </div> |
@@ -3,7 +3,7 @@ discard block |
||
| 3 | 3 | /** @var array $ticket_line_item */ |
| 4 | 4 | /** @var string $default_hidden_inputs */ |
| 5 | 5 | ?> |
| 6 | -<?php if (!is_admin()) : ?> |
|
| 6 | +<?php if ( ! is_admin()) : ?> |
|
| 7 | 7 | <p id="spco-attendee_information-pg" class="spco-steps-pg small-text drk-grey-text"> |
| 8 | 8 | <?php echo apply_filters( |
| 9 | 9 | 'FHEE__registration_page_attendee_information__attendee_information_pg', |
@@ -32,7 +32,7 @@ discard block |
||
| 32 | 32 | class="spco-attendee-panel-dv spco-attendee-ticket-<?php echo $ticketID; ?>"> |
| 33 | 33 | |
| 34 | 34 | <div class="spco-ticket-info-dv"> |
| 35 | - <?php if (!is_admin()) : ?> |
|
| 35 | + <?php if ( ! is_admin()) : ?> |
|
| 36 | 36 | <h5><?php esc_html_e('Details', 'event_espresso'); ?></h5> |
| 37 | 37 | <?php endif; ?> |
| 38 | 38 | <table class="spco-ticket-details"> |
@@ -64,7 +64,7 @@ discard block |
||
| 64 | 64 | foreach ($registrations as $registration) { |
| 65 | 65 | if ($registration instanceof EE_Registration) { |
| 66 | 66 | if ($registration->ticket()->ID() !== $prev_ticket) { |
| 67 | - echo $ticket_line_item[ $registration->ticket()->ID() ]; |
|
| 67 | + echo $ticket_line_item[$registration->ticket()->ID()]; |
|
| 68 | 68 | } |
| 69 | 69 | |
| 70 | 70 | $prev_ticket = $registration->ticket()->ID(); |
@@ -18,360 +18,360 @@ |
||
| 18 | 18 | class TicketSelectorRowStandard extends TicketSelectorRow |
| 19 | 19 | { |
| 20 | 20 | |
| 21 | - /** |
|
| 22 | - * @var TicketDetails $ticket_details |
|
| 23 | - */ |
|
| 24 | - protected $ticket_details; |
|
| 25 | - |
|
| 26 | - /** |
|
| 27 | - * @var \EE_Ticket_Selector_Config $template_settings |
|
| 28 | - */ |
|
| 29 | - protected $template_settings; |
|
| 30 | - |
|
| 31 | - /** |
|
| 32 | - * @var EE_Tax_Config $tax_settings |
|
| 33 | - */ |
|
| 34 | - protected $tax_settings; |
|
| 35 | - |
|
| 36 | - /** |
|
| 37 | - * @var boolean $prices_displayed_including_taxes |
|
| 38 | - */ |
|
| 39 | - protected $prices_displayed_including_taxes; |
|
| 40 | - |
|
| 41 | - /** |
|
| 42 | - * @var int $row |
|
| 43 | - */ |
|
| 44 | - protected $row; |
|
| 45 | - |
|
| 46 | - /** |
|
| 47 | - * @var int $cols |
|
| 48 | - */ |
|
| 49 | - protected $cols; |
|
| 50 | - |
|
| 51 | - /** |
|
| 52 | - * @var boolean $hidden_input_qty |
|
| 53 | - */ |
|
| 54 | - protected $hidden_input_qty; |
|
| 55 | - |
|
| 56 | - /** |
|
| 57 | - * @var string $ticket_datetime_classes |
|
| 58 | - */ |
|
| 59 | - protected $ticket_datetime_classes; |
|
| 60 | - |
|
| 61 | - |
|
| 62 | - /** |
|
| 63 | - * TicketDetails constructor. |
|
| 64 | - * |
|
| 65 | - * @param TicketDetails $ticket_details |
|
| 66 | - * @param EE_Tax_Config $tax_settings |
|
| 67 | - * @param int $total_tickets |
|
| 68 | - * @param int $max_attendees |
|
| 69 | - * @param int $row |
|
| 70 | - * @param int $cols |
|
| 71 | - * @param boolean $required_ticket_sold_out |
|
| 72 | - * @param string $event_status |
|
| 73 | - * @param string $ticket_datetime_classes |
|
| 74 | - * @throws EE_Error |
|
| 75 | - * @throws UnexpectedEntityException |
|
| 76 | - */ |
|
| 77 | - public function __construct( |
|
| 78 | - TicketDetails $ticket_details, |
|
| 79 | - EE_Tax_Config $tax_settings, |
|
| 80 | - $total_tickets, |
|
| 81 | - $max_attendees, |
|
| 82 | - $row, |
|
| 83 | - $cols, |
|
| 84 | - $required_ticket_sold_out, |
|
| 85 | - $event_status, |
|
| 86 | - $ticket_datetime_classes |
|
| 87 | - ) { |
|
| 88 | - $this->ticket_details = $ticket_details; |
|
| 89 | - $this->template_settings = $ticket_details->getTemplateSettings(); |
|
| 90 | - $this->tax_settings = $tax_settings; |
|
| 91 | - $this->row = $row; |
|
| 92 | - $this->cols = $cols; |
|
| 93 | - $this->ticket_datetime_classes = $ticket_datetime_classes; |
|
| 94 | - parent::__construct( |
|
| 95 | - $ticket_details->getTicket(), |
|
| 96 | - $max_attendees, |
|
| 97 | - $ticket_details->getDateFormat(), |
|
| 98 | - $event_status, |
|
| 99 | - $required_ticket_sold_out, |
|
| 100 | - $total_tickets |
|
| 101 | - ); |
|
| 102 | - } |
|
| 103 | - |
|
| 104 | - |
|
| 105 | - /** |
|
| 106 | - * other ticket rows will need to know if a required ticket is sold out, |
|
| 107 | - * so that they are not offered for sale |
|
| 108 | - * |
|
| 109 | - * @return boolean |
|
| 110 | - */ |
|
| 111 | - public function getRequiredTicketSoldOut() |
|
| 112 | - { |
|
| 113 | - return $this->required_ticket_sold_out; |
|
| 114 | - } |
|
| 115 | - |
|
| 116 | - |
|
| 117 | - /** |
|
| 118 | - * @return int |
|
| 119 | - */ |
|
| 120 | - public function getCols() |
|
| 121 | - { |
|
| 122 | - return $this->cols; |
|
| 123 | - } |
|
| 124 | - |
|
| 125 | - |
|
| 126 | - /** |
|
| 127 | - * getHtml |
|
| 128 | - * |
|
| 129 | - * @return string |
|
| 130 | - * @throws EE_Error |
|
| 131 | - */ |
|
| 132 | - public function getHtml() |
|
| 133 | - { |
|
| 134 | - $this->min = 0; |
|
| 135 | - $this->max = $this->ticket->max(); |
|
| 136 | - $remaining = $this->ticket->remaining(); |
|
| 137 | - $this->setTicketMinAndMax($remaining); |
|
| 138 | - // set flag if ticket is required (flag is set to start date so that future tickets are not blocked) |
|
| 139 | - $this->required_ticket_sold_out = $this->ticket->required() && ! $remaining |
|
| 140 | - ? $this->ticket->start_date() |
|
| 141 | - : $this->required_ticket_sold_out; |
|
| 142 | - $this->setTicketPriceDetails(); |
|
| 143 | - $this->setTicketStatusClasses($remaining); |
|
| 144 | - $filtered_row_html = $this->getFilteredRowHtml(); |
|
| 145 | - if ($filtered_row_html !== false) { |
|
| 146 | - return $filtered_row_html; |
|
| 147 | - } |
|
| 148 | - $ticket_selector_row_html = EEH_HTML::tr( |
|
| 149 | - '', |
|
| 150 | - '', |
|
| 151 | - "tckt-slctr-tbl-tr {$this->status_class}{$this->ticket_datetime_classes} " |
|
| 152 | - . espresso_get_object_css_class($this->ticket) |
|
| 153 | - ); |
|
| 154 | - $filtered_row_content = $this->getFilteredRowContents(); |
|
| 155 | - if ($filtered_row_content !== false && $this->max_attendees === 1) { |
|
| 156 | - return $ticket_selector_row_html |
|
| 157 | - . $filtered_row_content |
|
| 158 | - . $this->ticketQtyAndIdHiddenInputs() |
|
| 159 | - . EEH_HTML::trx(); |
|
| 160 | - } |
|
| 161 | - if ($filtered_row_content !== false) { |
|
| 162 | - return $ticket_selector_row_html |
|
| 163 | - . $filtered_row_content |
|
| 164 | - . EEH_HTML::trx(); |
|
| 165 | - } |
|
| 166 | - $this->hidden_input_qty = $this->max_attendees > 1; |
|
| 167 | - |
|
| 168 | - $ticket_selector_row_html .= $this->ticketNameTableCell(); |
|
| 169 | - $ticket_selector_row_html .= $this->ticketPriceTableCell(); |
|
| 170 | - $ticket_selector_row_html .= EEH_HTML::td( |
|
| 171 | - '', |
|
| 172 | - '', |
|
| 173 | - 'tckt-slctr-tbl-td-qty cntr', |
|
| 174 | - '', |
|
| 175 | - 'headers="quantity-' . $this->EVT_ID . '"' |
|
| 176 | - ); |
|
| 177 | - $this->setTicketStatusDisplay($remaining); |
|
| 178 | - if (empty($this->ticket_status_display)) { |
|
| 179 | - if ($this->max_attendees === 1) { |
|
| 180 | - // only ONE attendee is allowed to register at a time |
|
| 181 | - $ticket_selector_row_html .= $this->onlyOneAttendeeCanRegister(); |
|
| 182 | - } elseif ($this->max > 0) { |
|
| 183 | - $ticket_selector_row_html .= $this->ticketQuantitySelector(); |
|
| 184 | - } |
|
| 185 | - } |
|
| 186 | - $ticket_selector_row_html .= $this->ticket_status_display; |
|
| 187 | - $ticket_selector_row_html .= $this->ticketQtyAndIdHiddenInputs(); |
|
| 188 | - $ticket_selector_row_html .= $this->ticket_details->display( |
|
| 189 | - $this->ticket_price, |
|
| 190 | - $remaining, |
|
| 191 | - $this->cols |
|
| 192 | - ); |
|
| 193 | - $ticket_selector_row_html .= EEH_HTML::tdx(); |
|
| 194 | - $ticket_selector_row_html .= EEH_HTML::trx(); |
|
| 195 | - |
|
| 196 | - |
|
| 197 | - $this->row++; |
|
| 198 | - return $ticket_selector_row_html; |
|
| 199 | - } |
|
| 200 | - |
|
| 201 | - |
|
| 202 | - /** |
|
| 203 | - * getTicketPriceDetails |
|
| 204 | - * |
|
| 205 | - * @return void |
|
| 206 | - * @throws EE_Error |
|
| 207 | - */ |
|
| 208 | - protected function setTicketPriceDetails() |
|
| 209 | - { |
|
| 210 | - $this->ticket_price = $this->tax_settings->prices_displayed_including_taxes |
|
| 211 | - ? $this->ticket->get_ticket_total_with_taxes() |
|
| 212 | - : $this->ticket->get_ticket_subtotal(); |
|
| 213 | - $this->ticket_bundle = false; |
|
| 214 | - $ticket_min = $this->ticket->min(); |
|
| 215 | - // for ticket bundles, set min and max qty the same |
|
| 216 | - if ($ticket_min !== 0 && $ticket_min === $this->ticket->max()) { |
|
| 217 | - $this->ticket_price *= $ticket_min; |
|
| 218 | - $this->ticket_bundle = true; |
|
| 219 | - } |
|
| 220 | - $this->ticket_price = apply_filters( |
|
| 221 | - 'FHEE__ticket_selector_chart_template__ticket_price', |
|
| 222 | - $this->ticket_price, |
|
| 223 | - $this->ticket |
|
| 224 | - ); |
|
| 225 | - } |
|
| 226 | - |
|
| 227 | - |
|
| 228 | - /** |
|
| 229 | - * ticketNameTableCell |
|
| 230 | - * |
|
| 231 | - * @return string |
|
| 232 | - * @throws EE_Error |
|
| 233 | - */ |
|
| 234 | - protected function ticketNameTableCell() |
|
| 235 | - { |
|
| 236 | - $html = EEH_HTML::td( |
|
| 237 | - '', |
|
| 238 | - '', |
|
| 239 | - 'tckt-slctr-tbl-td-name', |
|
| 240 | - '', |
|
| 241 | - 'headers="details-' . $this->EVT_ID . '"' |
|
| 242 | - ); |
|
| 243 | - $html .= EEH_HTML::strong($this->ticket->get_pretty('TKT_name')); |
|
| 244 | - $html .= $this->ticket_details->getShowHideLinks(); |
|
| 245 | - if ($this->ticket->required()) { |
|
| 246 | - $html .= EEH_HTML::p( |
|
| 247 | - apply_filters( |
|
| 248 | - 'FHEE__ticket_selector_chart_template__ticket_required_message', |
|
| 249 | - esc_html__('This ticket is required and must be purchased.', 'event_espresso') |
|
| 250 | - ), |
|
| 251 | - '', |
|
| 252 | - 'ticket-required-pg' |
|
| 253 | - ); |
|
| 254 | - } |
|
| 255 | - $html .= EEH_HTML::tdx(); |
|
| 256 | - return $html; |
|
| 257 | - } |
|
| 258 | - |
|
| 259 | - |
|
| 260 | - /** |
|
| 261 | - * ticketPriceTableCell |
|
| 262 | - * |
|
| 263 | - * @return string |
|
| 264 | - * @throws EE_Error |
|
| 265 | - */ |
|
| 266 | - protected function ticketPriceTableCell() |
|
| 267 | - { |
|
| 268 | - $html = ''; |
|
| 269 | - if (apply_filters('FHEE__ticket_selector_chart_template__display_ticket_price_details', true)) { |
|
| 270 | - $html .= EEH_HTML::td( |
|
| 271 | - '', |
|
| 272 | - '', |
|
| 273 | - 'tckt-slctr-tbl-td-price jst-rght', |
|
| 274 | - '', |
|
| 275 | - 'headers="price-' . $this->EVT_ID . '"' |
|
| 276 | - ); |
|
| 277 | - $html .= EEH_HTML::span( |
|
| 278 | - EEH_Template::format_currency($this->ticket_price), |
|
| 279 | - '', |
|
| 280 | - 'tckt-price--nowrap' |
|
| 281 | - ); |
|
| 282 | - $html .= $this->ticket->taxable() |
|
| 283 | - ? EEH_HTML::span('*', '', 'taxable-tickets-asterisk grey-text') |
|
| 284 | - : ''; |
|
| 285 | - $html .= ' '; |
|
| 286 | - // phpcs:disable WordPress.WP.I18n.NoEmptyStrings |
|
| 287 | - $html .= EEH_HTML::span( |
|
| 288 | - $this->ticket_bundle |
|
| 289 | - ? apply_filters( |
|
| 290 | - 'FHEE__ticket_selector_chart_template__per_ticket_bundle_text', |
|
| 291 | - __(' / bundle', 'event_espresso') |
|
| 292 | - ) |
|
| 293 | - : apply_filters( |
|
| 294 | - 'FHEE__ticket_selector_chart_template__per_ticket_text', |
|
| 295 | - __('', 'event_espresso') |
|
| 296 | - ), |
|
| 297 | - '', |
|
| 298 | - 'smaller-text no-bold' |
|
| 299 | - ); |
|
| 300 | - $html .= ' '; |
|
| 301 | - $html .= EEH_HTML::tdx(); |
|
| 302 | - $this->cols++; |
|
| 303 | - } |
|
| 304 | - return $html; |
|
| 305 | - } |
|
| 306 | - |
|
| 307 | - |
|
| 308 | - /** |
|
| 309 | - * onlyOneAttendeeCanRegister |
|
| 310 | - * |
|
| 311 | - * @return string |
|
| 312 | - */ |
|
| 313 | - protected function onlyOneAttendeeCanRegister() |
|
| 314 | - { |
|
| 315 | - // display submit button since we have tickets available |
|
| 316 | - add_filter('FHEE__EE_Ticket_Selector__display_ticket_selector_submit', '__return_true'); |
|
| 317 | - $this->hidden_input_qty = false; |
|
| 318 | - $id = 'ticket-selector-tbl-qty-slct-' . $this->EVT_ID . '-' . $this->row; |
|
| 319 | - $html = '<label class="ee-a11y-screen-reader-text" for="' . $id . '">'; |
|
| 320 | - $html .= esc_html__('Select this ticket', 'event_espresso') . '</label>'; |
|
| 321 | - $html .= '<input type="radio" name="tkt-slctr-qty-' . $this->EVT_ID . '"'; |
|
| 322 | - $html .= ' id="' . $id . '"'; |
|
| 323 | - $html .= ' class="ticket-selector-tbl-qty-slct" value="' . $this->row . '-1"'; |
|
| 324 | - $html .= $this->total_tickets === 1 ? ' checked="checked"' : ''; |
|
| 325 | - $html .= ' title=""/>'; |
|
| 326 | - return $html; |
|
| 327 | - } |
|
| 328 | - |
|
| 329 | - |
|
| 330 | - /** |
|
| 331 | - * ticketQuantitySelector |
|
| 332 | - * |
|
| 333 | - * @return string |
|
| 334 | - * @throws EE_Error |
|
| 335 | - */ |
|
| 336 | - protected function ticketQuantitySelector() |
|
| 337 | - { |
|
| 338 | - // display submit button since we have tickets available |
|
| 339 | - add_filter('FHEE__EE_Ticket_Selector__display_ticket_selector_submit', '__return_true'); |
|
| 340 | - $this->hidden_input_qty = false; |
|
| 341 | - $id = 'ticket-selector-tbl-qty-slct-' . $this->EVT_ID . '-' . $this->row; |
|
| 342 | - $html = '<label class="ee-a11y-screen-reader-text" for="' . $id . '">'; |
|
| 343 | - $html .= esc_html__('Quantity', 'event_espresso') . '</label>'; |
|
| 344 | - $html .= '<select name="tkt-slctr-qty-' . $this->EVT_ID . '[]"'; |
|
| 345 | - $html .= ' id="' . $id . '"'; |
|
| 346 | - $html .= ' class="ticket-selector-tbl-qty-slct">'; |
|
| 347 | - // this ensures that non-required tickets with non-zero MIN QTYs don't HAVE to be purchased |
|
| 348 | - if ($this->min !== 0 && ! $this->ticket->required()) { |
|
| 349 | - $html .= '<option value="0"> 0 </option>'; |
|
| 350 | - } |
|
| 351 | - // offer ticket quantities from the min to the max |
|
| 352 | - for ($i = $this->min; $i <= $this->max; $i++) { |
|
| 353 | - $html .= '<option value="' . $i . '"> ' . $i . ' </option>'; |
|
| 354 | - } |
|
| 355 | - $html .= '</select>'; |
|
| 356 | - return $html; |
|
| 357 | - } |
|
| 358 | - |
|
| 359 | - |
|
| 360 | - /** |
|
| 361 | - * getHiddenInputs |
|
| 362 | - * |
|
| 363 | - * @return string |
|
| 364 | - * @throws EE_Error |
|
| 365 | - */ |
|
| 366 | - protected function ticketQtyAndIdHiddenInputs() |
|
| 367 | - { |
|
| 368 | - $html = ''; |
|
| 369 | - // depending on group reg we need to change the format for qty |
|
| 370 | - if ($this->hidden_input_qty) { |
|
| 371 | - $html .= '<input type="hidden" name="tkt-slctr-qty-' . $this->EVT_ID . '[]" value="0"/>'; |
|
| 372 | - } |
|
| 373 | - $html .= '<input type="hidden" name="tkt-slctr-ticket-id-' . $this->EVT_ID . '[]"'; |
|
| 374 | - $html .= ' value="' . $this->ticket->ID() . '"/>'; |
|
| 375 | - return $html; |
|
| 376 | - } |
|
| 21 | + /** |
|
| 22 | + * @var TicketDetails $ticket_details |
|
| 23 | + */ |
|
| 24 | + protected $ticket_details; |
|
| 25 | + |
|
| 26 | + /** |
|
| 27 | + * @var \EE_Ticket_Selector_Config $template_settings |
|
| 28 | + */ |
|
| 29 | + protected $template_settings; |
|
| 30 | + |
|
| 31 | + /** |
|
| 32 | + * @var EE_Tax_Config $tax_settings |
|
| 33 | + */ |
|
| 34 | + protected $tax_settings; |
|
| 35 | + |
|
| 36 | + /** |
|
| 37 | + * @var boolean $prices_displayed_including_taxes |
|
| 38 | + */ |
|
| 39 | + protected $prices_displayed_including_taxes; |
|
| 40 | + |
|
| 41 | + /** |
|
| 42 | + * @var int $row |
|
| 43 | + */ |
|
| 44 | + protected $row; |
|
| 45 | + |
|
| 46 | + /** |
|
| 47 | + * @var int $cols |
|
| 48 | + */ |
|
| 49 | + protected $cols; |
|
| 50 | + |
|
| 51 | + /** |
|
| 52 | + * @var boolean $hidden_input_qty |
|
| 53 | + */ |
|
| 54 | + protected $hidden_input_qty; |
|
| 55 | + |
|
| 56 | + /** |
|
| 57 | + * @var string $ticket_datetime_classes |
|
| 58 | + */ |
|
| 59 | + protected $ticket_datetime_classes; |
|
| 60 | + |
|
| 61 | + |
|
| 62 | + /** |
|
| 63 | + * TicketDetails constructor. |
|
| 64 | + * |
|
| 65 | + * @param TicketDetails $ticket_details |
|
| 66 | + * @param EE_Tax_Config $tax_settings |
|
| 67 | + * @param int $total_tickets |
|
| 68 | + * @param int $max_attendees |
|
| 69 | + * @param int $row |
|
| 70 | + * @param int $cols |
|
| 71 | + * @param boolean $required_ticket_sold_out |
|
| 72 | + * @param string $event_status |
|
| 73 | + * @param string $ticket_datetime_classes |
|
| 74 | + * @throws EE_Error |
|
| 75 | + * @throws UnexpectedEntityException |
|
| 76 | + */ |
|
| 77 | + public function __construct( |
|
| 78 | + TicketDetails $ticket_details, |
|
| 79 | + EE_Tax_Config $tax_settings, |
|
| 80 | + $total_tickets, |
|
| 81 | + $max_attendees, |
|
| 82 | + $row, |
|
| 83 | + $cols, |
|
| 84 | + $required_ticket_sold_out, |
|
| 85 | + $event_status, |
|
| 86 | + $ticket_datetime_classes |
|
| 87 | + ) { |
|
| 88 | + $this->ticket_details = $ticket_details; |
|
| 89 | + $this->template_settings = $ticket_details->getTemplateSettings(); |
|
| 90 | + $this->tax_settings = $tax_settings; |
|
| 91 | + $this->row = $row; |
|
| 92 | + $this->cols = $cols; |
|
| 93 | + $this->ticket_datetime_classes = $ticket_datetime_classes; |
|
| 94 | + parent::__construct( |
|
| 95 | + $ticket_details->getTicket(), |
|
| 96 | + $max_attendees, |
|
| 97 | + $ticket_details->getDateFormat(), |
|
| 98 | + $event_status, |
|
| 99 | + $required_ticket_sold_out, |
|
| 100 | + $total_tickets |
|
| 101 | + ); |
|
| 102 | + } |
|
| 103 | + |
|
| 104 | + |
|
| 105 | + /** |
|
| 106 | + * other ticket rows will need to know if a required ticket is sold out, |
|
| 107 | + * so that they are not offered for sale |
|
| 108 | + * |
|
| 109 | + * @return boolean |
|
| 110 | + */ |
|
| 111 | + public function getRequiredTicketSoldOut() |
|
| 112 | + { |
|
| 113 | + return $this->required_ticket_sold_out; |
|
| 114 | + } |
|
| 115 | + |
|
| 116 | + |
|
| 117 | + /** |
|
| 118 | + * @return int |
|
| 119 | + */ |
|
| 120 | + public function getCols() |
|
| 121 | + { |
|
| 122 | + return $this->cols; |
|
| 123 | + } |
|
| 124 | + |
|
| 125 | + |
|
| 126 | + /** |
|
| 127 | + * getHtml |
|
| 128 | + * |
|
| 129 | + * @return string |
|
| 130 | + * @throws EE_Error |
|
| 131 | + */ |
|
| 132 | + public function getHtml() |
|
| 133 | + { |
|
| 134 | + $this->min = 0; |
|
| 135 | + $this->max = $this->ticket->max(); |
|
| 136 | + $remaining = $this->ticket->remaining(); |
|
| 137 | + $this->setTicketMinAndMax($remaining); |
|
| 138 | + // set flag if ticket is required (flag is set to start date so that future tickets are not blocked) |
|
| 139 | + $this->required_ticket_sold_out = $this->ticket->required() && ! $remaining |
|
| 140 | + ? $this->ticket->start_date() |
|
| 141 | + : $this->required_ticket_sold_out; |
|
| 142 | + $this->setTicketPriceDetails(); |
|
| 143 | + $this->setTicketStatusClasses($remaining); |
|
| 144 | + $filtered_row_html = $this->getFilteredRowHtml(); |
|
| 145 | + if ($filtered_row_html !== false) { |
|
| 146 | + return $filtered_row_html; |
|
| 147 | + } |
|
| 148 | + $ticket_selector_row_html = EEH_HTML::tr( |
|
| 149 | + '', |
|
| 150 | + '', |
|
| 151 | + "tckt-slctr-tbl-tr {$this->status_class}{$this->ticket_datetime_classes} " |
|
| 152 | + . espresso_get_object_css_class($this->ticket) |
|
| 153 | + ); |
|
| 154 | + $filtered_row_content = $this->getFilteredRowContents(); |
|
| 155 | + if ($filtered_row_content !== false && $this->max_attendees === 1) { |
|
| 156 | + return $ticket_selector_row_html |
|
| 157 | + . $filtered_row_content |
|
| 158 | + . $this->ticketQtyAndIdHiddenInputs() |
|
| 159 | + . EEH_HTML::trx(); |
|
| 160 | + } |
|
| 161 | + if ($filtered_row_content !== false) { |
|
| 162 | + return $ticket_selector_row_html |
|
| 163 | + . $filtered_row_content |
|
| 164 | + . EEH_HTML::trx(); |
|
| 165 | + } |
|
| 166 | + $this->hidden_input_qty = $this->max_attendees > 1; |
|
| 167 | + |
|
| 168 | + $ticket_selector_row_html .= $this->ticketNameTableCell(); |
|
| 169 | + $ticket_selector_row_html .= $this->ticketPriceTableCell(); |
|
| 170 | + $ticket_selector_row_html .= EEH_HTML::td( |
|
| 171 | + '', |
|
| 172 | + '', |
|
| 173 | + 'tckt-slctr-tbl-td-qty cntr', |
|
| 174 | + '', |
|
| 175 | + 'headers="quantity-' . $this->EVT_ID . '"' |
|
| 176 | + ); |
|
| 177 | + $this->setTicketStatusDisplay($remaining); |
|
| 178 | + if (empty($this->ticket_status_display)) { |
|
| 179 | + if ($this->max_attendees === 1) { |
|
| 180 | + // only ONE attendee is allowed to register at a time |
|
| 181 | + $ticket_selector_row_html .= $this->onlyOneAttendeeCanRegister(); |
|
| 182 | + } elseif ($this->max > 0) { |
|
| 183 | + $ticket_selector_row_html .= $this->ticketQuantitySelector(); |
|
| 184 | + } |
|
| 185 | + } |
|
| 186 | + $ticket_selector_row_html .= $this->ticket_status_display; |
|
| 187 | + $ticket_selector_row_html .= $this->ticketQtyAndIdHiddenInputs(); |
|
| 188 | + $ticket_selector_row_html .= $this->ticket_details->display( |
|
| 189 | + $this->ticket_price, |
|
| 190 | + $remaining, |
|
| 191 | + $this->cols |
|
| 192 | + ); |
|
| 193 | + $ticket_selector_row_html .= EEH_HTML::tdx(); |
|
| 194 | + $ticket_selector_row_html .= EEH_HTML::trx(); |
|
| 195 | + |
|
| 196 | + |
|
| 197 | + $this->row++; |
|
| 198 | + return $ticket_selector_row_html; |
|
| 199 | + } |
|
| 200 | + |
|
| 201 | + |
|
| 202 | + /** |
|
| 203 | + * getTicketPriceDetails |
|
| 204 | + * |
|
| 205 | + * @return void |
|
| 206 | + * @throws EE_Error |
|
| 207 | + */ |
|
| 208 | + protected function setTicketPriceDetails() |
|
| 209 | + { |
|
| 210 | + $this->ticket_price = $this->tax_settings->prices_displayed_including_taxes |
|
| 211 | + ? $this->ticket->get_ticket_total_with_taxes() |
|
| 212 | + : $this->ticket->get_ticket_subtotal(); |
|
| 213 | + $this->ticket_bundle = false; |
|
| 214 | + $ticket_min = $this->ticket->min(); |
|
| 215 | + // for ticket bundles, set min and max qty the same |
|
| 216 | + if ($ticket_min !== 0 && $ticket_min === $this->ticket->max()) { |
|
| 217 | + $this->ticket_price *= $ticket_min; |
|
| 218 | + $this->ticket_bundle = true; |
|
| 219 | + } |
|
| 220 | + $this->ticket_price = apply_filters( |
|
| 221 | + 'FHEE__ticket_selector_chart_template__ticket_price', |
|
| 222 | + $this->ticket_price, |
|
| 223 | + $this->ticket |
|
| 224 | + ); |
|
| 225 | + } |
|
| 226 | + |
|
| 227 | + |
|
| 228 | + /** |
|
| 229 | + * ticketNameTableCell |
|
| 230 | + * |
|
| 231 | + * @return string |
|
| 232 | + * @throws EE_Error |
|
| 233 | + */ |
|
| 234 | + protected function ticketNameTableCell() |
|
| 235 | + { |
|
| 236 | + $html = EEH_HTML::td( |
|
| 237 | + '', |
|
| 238 | + '', |
|
| 239 | + 'tckt-slctr-tbl-td-name', |
|
| 240 | + '', |
|
| 241 | + 'headers="details-' . $this->EVT_ID . '"' |
|
| 242 | + ); |
|
| 243 | + $html .= EEH_HTML::strong($this->ticket->get_pretty('TKT_name')); |
|
| 244 | + $html .= $this->ticket_details->getShowHideLinks(); |
|
| 245 | + if ($this->ticket->required()) { |
|
| 246 | + $html .= EEH_HTML::p( |
|
| 247 | + apply_filters( |
|
| 248 | + 'FHEE__ticket_selector_chart_template__ticket_required_message', |
|
| 249 | + esc_html__('This ticket is required and must be purchased.', 'event_espresso') |
|
| 250 | + ), |
|
| 251 | + '', |
|
| 252 | + 'ticket-required-pg' |
|
| 253 | + ); |
|
| 254 | + } |
|
| 255 | + $html .= EEH_HTML::tdx(); |
|
| 256 | + return $html; |
|
| 257 | + } |
|
| 258 | + |
|
| 259 | + |
|
| 260 | + /** |
|
| 261 | + * ticketPriceTableCell |
|
| 262 | + * |
|
| 263 | + * @return string |
|
| 264 | + * @throws EE_Error |
|
| 265 | + */ |
|
| 266 | + protected function ticketPriceTableCell() |
|
| 267 | + { |
|
| 268 | + $html = ''; |
|
| 269 | + if (apply_filters('FHEE__ticket_selector_chart_template__display_ticket_price_details', true)) { |
|
| 270 | + $html .= EEH_HTML::td( |
|
| 271 | + '', |
|
| 272 | + '', |
|
| 273 | + 'tckt-slctr-tbl-td-price jst-rght', |
|
| 274 | + '', |
|
| 275 | + 'headers="price-' . $this->EVT_ID . '"' |
|
| 276 | + ); |
|
| 277 | + $html .= EEH_HTML::span( |
|
| 278 | + EEH_Template::format_currency($this->ticket_price), |
|
| 279 | + '', |
|
| 280 | + 'tckt-price--nowrap' |
|
| 281 | + ); |
|
| 282 | + $html .= $this->ticket->taxable() |
|
| 283 | + ? EEH_HTML::span('*', '', 'taxable-tickets-asterisk grey-text') |
|
| 284 | + : ''; |
|
| 285 | + $html .= ' '; |
|
| 286 | + // phpcs:disable WordPress.WP.I18n.NoEmptyStrings |
|
| 287 | + $html .= EEH_HTML::span( |
|
| 288 | + $this->ticket_bundle |
|
| 289 | + ? apply_filters( |
|
| 290 | + 'FHEE__ticket_selector_chart_template__per_ticket_bundle_text', |
|
| 291 | + __(' / bundle', 'event_espresso') |
|
| 292 | + ) |
|
| 293 | + : apply_filters( |
|
| 294 | + 'FHEE__ticket_selector_chart_template__per_ticket_text', |
|
| 295 | + __('', 'event_espresso') |
|
| 296 | + ), |
|
| 297 | + '', |
|
| 298 | + 'smaller-text no-bold' |
|
| 299 | + ); |
|
| 300 | + $html .= ' '; |
|
| 301 | + $html .= EEH_HTML::tdx(); |
|
| 302 | + $this->cols++; |
|
| 303 | + } |
|
| 304 | + return $html; |
|
| 305 | + } |
|
| 306 | + |
|
| 307 | + |
|
| 308 | + /** |
|
| 309 | + * onlyOneAttendeeCanRegister |
|
| 310 | + * |
|
| 311 | + * @return string |
|
| 312 | + */ |
|
| 313 | + protected function onlyOneAttendeeCanRegister() |
|
| 314 | + { |
|
| 315 | + // display submit button since we have tickets available |
|
| 316 | + add_filter('FHEE__EE_Ticket_Selector__display_ticket_selector_submit', '__return_true'); |
|
| 317 | + $this->hidden_input_qty = false; |
|
| 318 | + $id = 'ticket-selector-tbl-qty-slct-' . $this->EVT_ID . '-' . $this->row; |
|
| 319 | + $html = '<label class="ee-a11y-screen-reader-text" for="' . $id . '">'; |
|
| 320 | + $html .= esc_html__('Select this ticket', 'event_espresso') . '</label>'; |
|
| 321 | + $html .= '<input type="radio" name="tkt-slctr-qty-' . $this->EVT_ID . '"'; |
|
| 322 | + $html .= ' id="' . $id . '"'; |
|
| 323 | + $html .= ' class="ticket-selector-tbl-qty-slct" value="' . $this->row . '-1"'; |
|
| 324 | + $html .= $this->total_tickets === 1 ? ' checked="checked"' : ''; |
|
| 325 | + $html .= ' title=""/>'; |
|
| 326 | + return $html; |
|
| 327 | + } |
|
| 328 | + |
|
| 329 | + |
|
| 330 | + /** |
|
| 331 | + * ticketQuantitySelector |
|
| 332 | + * |
|
| 333 | + * @return string |
|
| 334 | + * @throws EE_Error |
|
| 335 | + */ |
|
| 336 | + protected function ticketQuantitySelector() |
|
| 337 | + { |
|
| 338 | + // display submit button since we have tickets available |
|
| 339 | + add_filter('FHEE__EE_Ticket_Selector__display_ticket_selector_submit', '__return_true'); |
|
| 340 | + $this->hidden_input_qty = false; |
|
| 341 | + $id = 'ticket-selector-tbl-qty-slct-' . $this->EVT_ID . '-' . $this->row; |
|
| 342 | + $html = '<label class="ee-a11y-screen-reader-text" for="' . $id . '">'; |
|
| 343 | + $html .= esc_html__('Quantity', 'event_espresso') . '</label>'; |
|
| 344 | + $html .= '<select name="tkt-slctr-qty-' . $this->EVT_ID . '[]"'; |
|
| 345 | + $html .= ' id="' . $id . '"'; |
|
| 346 | + $html .= ' class="ticket-selector-tbl-qty-slct">'; |
|
| 347 | + // this ensures that non-required tickets with non-zero MIN QTYs don't HAVE to be purchased |
|
| 348 | + if ($this->min !== 0 && ! $this->ticket->required()) { |
|
| 349 | + $html .= '<option value="0"> 0 </option>'; |
|
| 350 | + } |
|
| 351 | + // offer ticket quantities from the min to the max |
|
| 352 | + for ($i = $this->min; $i <= $this->max; $i++) { |
|
| 353 | + $html .= '<option value="' . $i . '"> ' . $i . ' </option>'; |
|
| 354 | + } |
|
| 355 | + $html .= '</select>'; |
|
| 356 | + return $html; |
|
| 357 | + } |
|
| 358 | + |
|
| 359 | + |
|
| 360 | + /** |
|
| 361 | + * getHiddenInputs |
|
| 362 | + * |
|
| 363 | + * @return string |
|
| 364 | + * @throws EE_Error |
|
| 365 | + */ |
|
| 366 | + protected function ticketQtyAndIdHiddenInputs() |
|
| 367 | + { |
|
| 368 | + $html = ''; |
|
| 369 | + // depending on group reg we need to change the format for qty |
|
| 370 | + if ($this->hidden_input_qty) { |
|
| 371 | + $html .= '<input type="hidden" name="tkt-slctr-qty-' . $this->EVT_ID . '[]" value="0"/>'; |
|
| 372 | + } |
|
| 373 | + $html .= '<input type="hidden" name="tkt-slctr-ticket-id-' . $this->EVT_ID . '[]"'; |
|
| 374 | + $html .= ' value="' . $this->ticket->ID() . '"/>'; |
|
| 375 | + return $html; |
|
| 376 | + } |
|
| 377 | 377 | } |
@@ -172,7 +172,7 @@ discard block |
||
| 172 | 172 | '', |
| 173 | 173 | 'tckt-slctr-tbl-td-qty cntr', |
| 174 | 174 | '', |
| 175 | - 'headers="quantity-' . $this->EVT_ID . '"' |
|
| 175 | + 'headers="quantity-'.$this->EVT_ID.'"' |
|
| 176 | 176 | ); |
| 177 | 177 | $this->setTicketStatusDisplay($remaining); |
| 178 | 178 | if (empty($this->ticket_status_display)) { |
@@ -238,7 +238,7 @@ discard block |
||
| 238 | 238 | '', |
| 239 | 239 | 'tckt-slctr-tbl-td-name', |
| 240 | 240 | '', |
| 241 | - 'headers="details-' . $this->EVT_ID . '"' |
|
| 241 | + 'headers="details-'.$this->EVT_ID.'"' |
|
| 242 | 242 | ); |
| 243 | 243 | $html .= EEH_HTML::strong($this->ticket->get_pretty('TKT_name')); |
| 244 | 244 | $html .= $this->ticket_details->getShowHideLinks(); |
@@ -272,7 +272,7 @@ discard block |
||
| 272 | 272 | '', |
| 273 | 273 | 'tckt-slctr-tbl-td-price jst-rght', |
| 274 | 274 | '', |
| 275 | - 'headers="price-' . $this->EVT_ID . '"' |
|
| 275 | + 'headers="price-'.$this->EVT_ID.'"' |
|
| 276 | 276 | ); |
| 277 | 277 | $html .= EEH_HTML::span( |
| 278 | 278 | EEH_Template::format_currency($this->ticket_price), |
@@ -315,12 +315,12 @@ discard block |
||
| 315 | 315 | // display submit button since we have tickets available |
| 316 | 316 | add_filter('FHEE__EE_Ticket_Selector__display_ticket_selector_submit', '__return_true'); |
| 317 | 317 | $this->hidden_input_qty = false; |
| 318 | - $id = 'ticket-selector-tbl-qty-slct-' . $this->EVT_ID . '-' . $this->row; |
|
| 319 | - $html = '<label class="ee-a11y-screen-reader-text" for="' . $id . '">'; |
|
| 320 | - $html .= esc_html__('Select this ticket', 'event_espresso') . '</label>'; |
|
| 321 | - $html .= '<input type="radio" name="tkt-slctr-qty-' . $this->EVT_ID . '"'; |
|
| 322 | - $html .= ' id="' . $id . '"'; |
|
| 323 | - $html .= ' class="ticket-selector-tbl-qty-slct" value="' . $this->row . '-1"'; |
|
| 318 | + $id = 'ticket-selector-tbl-qty-slct-'.$this->EVT_ID.'-'.$this->row; |
|
| 319 | + $html = '<label class="ee-a11y-screen-reader-text" for="'.$id.'">'; |
|
| 320 | + $html .= esc_html__('Select this ticket', 'event_espresso').'</label>'; |
|
| 321 | + $html .= '<input type="radio" name="tkt-slctr-qty-'.$this->EVT_ID.'"'; |
|
| 322 | + $html .= ' id="'.$id.'"'; |
|
| 323 | + $html .= ' class="ticket-selector-tbl-qty-slct" value="'.$this->row.'-1"'; |
|
| 324 | 324 | $html .= $this->total_tickets === 1 ? ' checked="checked"' : ''; |
| 325 | 325 | $html .= ' title=""/>'; |
| 326 | 326 | return $html; |
@@ -338,11 +338,11 @@ discard block |
||
| 338 | 338 | // display submit button since we have tickets available |
| 339 | 339 | add_filter('FHEE__EE_Ticket_Selector__display_ticket_selector_submit', '__return_true'); |
| 340 | 340 | $this->hidden_input_qty = false; |
| 341 | - $id = 'ticket-selector-tbl-qty-slct-' . $this->EVT_ID . '-' . $this->row; |
|
| 342 | - $html = '<label class="ee-a11y-screen-reader-text" for="' . $id . '">'; |
|
| 343 | - $html .= esc_html__('Quantity', 'event_espresso') . '</label>'; |
|
| 344 | - $html .= '<select name="tkt-slctr-qty-' . $this->EVT_ID . '[]"'; |
|
| 345 | - $html .= ' id="' . $id . '"'; |
|
| 341 | + $id = 'ticket-selector-tbl-qty-slct-'.$this->EVT_ID.'-'.$this->row; |
|
| 342 | + $html = '<label class="ee-a11y-screen-reader-text" for="'.$id.'">'; |
|
| 343 | + $html .= esc_html__('Quantity', 'event_espresso').'</label>'; |
|
| 344 | + $html .= '<select name="tkt-slctr-qty-'.$this->EVT_ID.'[]"'; |
|
| 345 | + $html .= ' id="'.$id.'"'; |
|
| 346 | 346 | $html .= ' class="ticket-selector-tbl-qty-slct">'; |
| 347 | 347 | // this ensures that non-required tickets with non-zero MIN QTYs don't HAVE to be purchased |
| 348 | 348 | if ($this->min !== 0 && ! $this->ticket->required()) { |
@@ -350,7 +350,7 @@ discard block |
||
| 350 | 350 | } |
| 351 | 351 | // offer ticket quantities from the min to the max |
| 352 | 352 | for ($i = $this->min; $i <= $this->max; $i++) { |
| 353 | - $html .= '<option value="' . $i . '"> ' . $i . ' </option>'; |
|
| 353 | + $html .= '<option value="'.$i.'"> '.$i.' </option>'; |
|
| 354 | 354 | } |
| 355 | 355 | $html .= '</select>'; |
| 356 | 356 | return $html; |
@@ -368,10 +368,10 @@ discard block |
||
| 368 | 368 | $html = ''; |
| 369 | 369 | // depending on group reg we need to change the format for qty |
| 370 | 370 | if ($this->hidden_input_qty) { |
| 371 | - $html .= '<input type="hidden" name="tkt-slctr-qty-' . $this->EVT_ID . '[]" value="0"/>'; |
|
| 371 | + $html .= '<input type="hidden" name="tkt-slctr-qty-'.$this->EVT_ID.'[]" value="0"/>'; |
|
| 372 | 372 | } |
| 373 | - $html .= '<input type="hidden" name="tkt-slctr-ticket-id-' . $this->EVT_ID . '[]"'; |
|
| 374 | - $html .= ' value="' . $this->ticket->ID() . '"/>'; |
|
| 373 | + $html .= '<input type="hidden" name="tkt-slctr-ticket-id-'.$this->EVT_ID.'[]"'; |
|
| 374 | + $html .= ' value="'.$this->ticket->ID().'"/>'; |
|
| 375 | 375 | return $html; |
| 376 | 376 | } |
| 377 | 377 | } |
@@ -12,149 +12,149 @@ |
||
| 12 | 12 | class EE_Taxes extends EE_Base |
| 13 | 13 | { |
| 14 | 14 | |
| 15 | - /** |
|
| 16 | - * This is used for when EE_Taxes is used statically by the admin |
|
| 17 | - * |
|
| 18 | - * @var array |
|
| 19 | - */ |
|
| 20 | - private static $_subtotal = []; |
|
| 15 | + /** |
|
| 16 | + * This is used for when EE_Taxes is used statically by the admin |
|
| 17 | + * |
|
| 18 | + * @var array |
|
| 19 | + */ |
|
| 20 | + private static $_subtotal = []; |
|
| 21 | 21 | |
| 22 | - /** |
|
| 23 | - * This holds an array of EE_Price objects that are of PRT_ID == 4 (tax price types) |
|
| 24 | - * |
|
| 25 | - * @var EE_Price[] |
|
| 26 | - */ |
|
| 27 | - private static $_default_taxes = []; |
|
| 22 | + /** |
|
| 23 | + * This holds an array of EE_Price objects that are of PRT_ID == 4 (tax price types) |
|
| 24 | + * |
|
| 25 | + * @var EE_Price[] |
|
| 26 | + */ |
|
| 27 | + private static $_default_taxes = []; |
|
| 28 | 28 | |
| 29 | 29 | |
| 30 | - /** |
|
| 31 | - * This method simply calculates the total taxes for a given ticket (by pulling the prices attached to the ticket |
|
| 32 | - * and applying default taxes to it). Note: this is just an intermediary helper method added to facilitate quick |
|
| 33 | - * calc of taxes for tickets listed in the event editor. |
|
| 34 | - * |
|
| 35 | - * @param EE_Ticket $ticket incoming EE_Ticket |
|
| 36 | - * @return float total taxes to apply to ticket. |
|
| 37 | - * @throws EE_Error |
|
| 38 | - * @throws ReflectionException |
|
| 39 | - */ |
|
| 40 | - public static function get_total_taxes_for_admin(EE_Ticket $ticket) |
|
| 41 | - { |
|
| 42 | - $tax = 0; |
|
| 43 | - $total_tax = 0; |
|
| 44 | - // This first checks to see if the given ticket is taxable. |
|
| 45 | - if (! $ticket->taxable()) { |
|
| 46 | - return $tax; |
|
| 47 | - } |
|
| 48 | - // get subtotal (notice we're only retrieving a subtotal if there isn't one given) |
|
| 49 | - $subtotal = EE_Taxes::get_subtotal_for_admin($ticket); |
|
| 50 | - // get taxes |
|
| 51 | - $taxes = EE_Taxes::get_taxes_for_admin(); |
|
| 52 | - // apply taxes to subtotal |
|
| 53 | - foreach ($taxes as $tax) { |
|
| 54 | - // assuming taxes are not cumulative |
|
| 55 | - $total_tax += $subtotal * $tax->amount() / 100; |
|
| 56 | - } |
|
| 57 | - return $total_tax; |
|
| 58 | - } |
|
| 30 | + /** |
|
| 31 | + * This method simply calculates the total taxes for a given ticket (by pulling the prices attached to the ticket |
|
| 32 | + * and applying default taxes to it). Note: this is just an intermediary helper method added to facilitate quick |
|
| 33 | + * calc of taxes for tickets listed in the event editor. |
|
| 34 | + * |
|
| 35 | + * @param EE_Ticket $ticket incoming EE_Ticket |
|
| 36 | + * @return float total taxes to apply to ticket. |
|
| 37 | + * @throws EE_Error |
|
| 38 | + * @throws ReflectionException |
|
| 39 | + */ |
|
| 40 | + public static function get_total_taxes_for_admin(EE_Ticket $ticket) |
|
| 41 | + { |
|
| 42 | + $tax = 0; |
|
| 43 | + $total_tax = 0; |
|
| 44 | + // This first checks to see if the given ticket is taxable. |
|
| 45 | + if (! $ticket->taxable()) { |
|
| 46 | + return $tax; |
|
| 47 | + } |
|
| 48 | + // get subtotal (notice we're only retrieving a subtotal if there isn't one given) |
|
| 49 | + $subtotal = EE_Taxes::get_subtotal_for_admin($ticket); |
|
| 50 | + // get taxes |
|
| 51 | + $taxes = EE_Taxes::get_taxes_for_admin(); |
|
| 52 | + // apply taxes to subtotal |
|
| 53 | + foreach ($taxes as $tax) { |
|
| 54 | + // assuming taxes are not cumulative |
|
| 55 | + $total_tax += $subtotal * $tax->amount() / 100; |
|
| 56 | + } |
|
| 57 | + return $total_tax; |
|
| 58 | + } |
|
| 59 | 59 | |
| 60 | 60 | |
| 61 | - /** |
|
| 62 | - * Gets the total percentage of tax that should be applied to taxable line items |
|
| 63 | - * |
|
| 64 | - * @return float the percentage of tax that should be added to taxable items |
|
| 65 | - * @throws EE_Error |
|
| 66 | - * @throws ReflectionException |
|
| 67 | - * eg 20 for %20 tax (NOT 0.20, which |
|
| 68 | - */ |
|
| 69 | - public static function get_total_taxes_percentage() |
|
| 70 | - { |
|
| 71 | - $total_tax_percent = 0; |
|
| 72 | - foreach (EE_Taxes::get_taxes_for_admin() as $tax_price) { |
|
| 73 | - $total_tax_percent += $tax_price->get('PRC_amount'); |
|
| 74 | - } |
|
| 75 | - return $total_tax_percent; |
|
| 76 | - } |
|
| 61 | + /** |
|
| 62 | + * Gets the total percentage of tax that should be applied to taxable line items |
|
| 63 | + * |
|
| 64 | + * @return float the percentage of tax that should be added to taxable items |
|
| 65 | + * @throws EE_Error |
|
| 66 | + * @throws ReflectionException |
|
| 67 | + * eg 20 for %20 tax (NOT 0.20, which |
|
| 68 | + */ |
|
| 69 | + public static function get_total_taxes_percentage() |
|
| 70 | + { |
|
| 71 | + $total_tax_percent = 0; |
|
| 72 | + foreach (EE_Taxes::get_taxes_for_admin() as $tax_price) { |
|
| 73 | + $total_tax_percent += $tax_price->get('PRC_amount'); |
|
| 74 | + } |
|
| 75 | + return $total_tax_percent; |
|
| 76 | + } |
|
| 77 | 77 | |
| 78 | 78 | |
| 79 | - /** |
|
| 80 | - * @param EE_Ticket $ticket |
|
| 81 | - * @return float |
|
| 82 | - * @throws EE_Error |
|
| 83 | - * @throws ReflectionException |
|
| 84 | - */ |
|
| 85 | - public static function get_subtotal_for_admin(EE_Ticket $ticket) |
|
| 86 | - { |
|
| 87 | - $TKT_ID = $ticket->ID(); |
|
| 88 | - return isset(EE_Taxes::$_subtotal[ $TKT_ID ]) |
|
| 89 | - ? EE_Taxes::$_subtotal[ $TKT_ID ] |
|
| 90 | - : EE_Taxes::_get_subtotal_for_admin($ticket); |
|
| 91 | - } |
|
| 79 | + /** |
|
| 80 | + * @param EE_Ticket $ticket |
|
| 81 | + * @return float |
|
| 82 | + * @throws EE_Error |
|
| 83 | + * @throws ReflectionException |
|
| 84 | + */ |
|
| 85 | + public static function get_subtotal_for_admin(EE_Ticket $ticket) |
|
| 86 | + { |
|
| 87 | + $TKT_ID = $ticket->ID(); |
|
| 88 | + return isset(EE_Taxes::$_subtotal[ $TKT_ID ]) |
|
| 89 | + ? EE_Taxes::$_subtotal[ $TKT_ID ] |
|
| 90 | + : EE_Taxes::_get_subtotal_for_admin($ticket); |
|
| 91 | + } |
|
| 92 | 92 | |
| 93 | 93 | |
| 94 | - /** |
|
| 95 | - * simply take an incoming ticket and calculate the subtotal for the ticket |
|
| 96 | - * |
|
| 97 | - * @param EE_Ticket $ticket |
|
| 98 | - * @return float subtotal calculated from all EE_Price[] on Ticket. |
|
| 99 | - * @throws EE_Error |
|
| 100 | - * @throws ReflectionException |
|
| 101 | - */ |
|
| 102 | - private static function _get_subtotal_for_admin(EE_Ticket $ticket) |
|
| 103 | - { |
|
| 104 | - $subtotal = 0; |
|
| 105 | - // get all prices |
|
| 106 | - $prices = $ticket->get_many_related( |
|
| 107 | - 'Price', |
|
| 108 | - [ |
|
| 109 | - 0 => [ |
|
| 110 | - 'Price_Type.PBT_ID' => ['NOT', EEM_Price_Type::base_type_tax], |
|
| 111 | - ], |
|
| 112 | - 'default_where_conditions' => 'none', |
|
| 113 | - 'order_by' => ['PRC_order' => 'ASC'], |
|
| 114 | - ] |
|
| 115 | - ); |
|
| 116 | - // let's loop through them (base price is always the first item) |
|
| 117 | - foreach ($prices as $price) { |
|
| 118 | - if ($price instanceof EE_Price) { |
|
| 119 | - $price_type = $price->type_obj(); |
|
| 120 | - if ($price_type instanceof EE_Price_Type) { |
|
| 121 | - switch ($price->type_obj()->base_type()) { |
|
| 122 | - case 1: // base price |
|
| 123 | - case 3: // surcharges |
|
| 124 | - $subtotal += $price->is_percent() |
|
| 125 | - ? $subtotal * $price->get('PRC_amount') / 100 |
|
| 126 | - : $price->get('PRC_amount'); |
|
| 127 | - break; |
|
| 128 | - case 2: // discounts |
|
| 129 | - $subtotal -= $price->is_percent() |
|
| 130 | - ? $subtotal * $price->get('PRC_amount') / 100 |
|
| 131 | - : $price->get('PRC_amount'); |
|
| 132 | - break; |
|
| 133 | - } |
|
| 134 | - } |
|
| 135 | - } |
|
| 136 | - } |
|
| 137 | - $TKT_ID = $ticket->ID(); |
|
| 138 | - EE_Taxes::$_subtotal[ $TKT_ID ] = $subtotal; |
|
| 139 | - return $subtotal; |
|
| 140 | - } |
|
| 94 | + /** |
|
| 95 | + * simply take an incoming ticket and calculate the subtotal for the ticket |
|
| 96 | + * |
|
| 97 | + * @param EE_Ticket $ticket |
|
| 98 | + * @return float subtotal calculated from all EE_Price[] on Ticket. |
|
| 99 | + * @throws EE_Error |
|
| 100 | + * @throws ReflectionException |
|
| 101 | + */ |
|
| 102 | + private static function _get_subtotal_for_admin(EE_Ticket $ticket) |
|
| 103 | + { |
|
| 104 | + $subtotal = 0; |
|
| 105 | + // get all prices |
|
| 106 | + $prices = $ticket->get_many_related( |
|
| 107 | + 'Price', |
|
| 108 | + [ |
|
| 109 | + 0 => [ |
|
| 110 | + 'Price_Type.PBT_ID' => ['NOT', EEM_Price_Type::base_type_tax], |
|
| 111 | + ], |
|
| 112 | + 'default_where_conditions' => 'none', |
|
| 113 | + 'order_by' => ['PRC_order' => 'ASC'], |
|
| 114 | + ] |
|
| 115 | + ); |
|
| 116 | + // let's loop through them (base price is always the first item) |
|
| 117 | + foreach ($prices as $price) { |
|
| 118 | + if ($price instanceof EE_Price) { |
|
| 119 | + $price_type = $price->type_obj(); |
|
| 120 | + if ($price_type instanceof EE_Price_Type) { |
|
| 121 | + switch ($price->type_obj()->base_type()) { |
|
| 122 | + case 1: // base price |
|
| 123 | + case 3: // surcharges |
|
| 124 | + $subtotal += $price->is_percent() |
|
| 125 | + ? $subtotal * $price->get('PRC_amount') / 100 |
|
| 126 | + : $price->get('PRC_amount'); |
|
| 127 | + break; |
|
| 128 | + case 2: // discounts |
|
| 129 | + $subtotal -= $price->is_percent() |
|
| 130 | + ? $subtotal * $price->get('PRC_amount') / 100 |
|
| 131 | + : $price->get('PRC_amount'); |
|
| 132 | + break; |
|
| 133 | + } |
|
| 134 | + } |
|
| 135 | + } |
|
| 136 | + } |
|
| 137 | + $TKT_ID = $ticket->ID(); |
|
| 138 | + EE_Taxes::$_subtotal[ $TKT_ID ] = $subtotal; |
|
| 139 | + return $subtotal; |
|
| 140 | + } |
|
| 141 | 141 | |
| 142 | 142 | |
| 143 | - /** |
|
| 144 | - * get all default prices that are a Tax price type (PRT_ID = 4) and return |
|
| 145 | - * |
|
| 146 | - * @return EE_Price[] EE_Price objects that have PRT_ID == 4 |
|
| 147 | - * @throws EE_Error |
|
| 148 | - */ |
|
| 149 | - public static function get_taxes_for_admin() |
|
| 150 | - { |
|
| 151 | - if (empty(EE_Taxes::$_default_taxes)) { |
|
| 152 | - /** @var EEM_Price $price_model */ |
|
| 153 | - $price_model = LoaderFactory::getLoader()->getShared('EEM_Price'); |
|
| 154 | - EE_Taxes::$_default_taxes = $price_model->get_all( |
|
| 155 | - [['Price_Type.PBT_ID' => 4]] |
|
| 156 | - ); |
|
| 157 | - } |
|
| 158 | - return EE_Taxes::$_default_taxes; |
|
| 159 | - } |
|
| 143 | + /** |
|
| 144 | + * get all default prices that are a Tax price type (PRT_ID = 4) and return |
|
| 145 | + * |
|
| 146 | + * @return EE_Price[] EE_Price objects that have PRT_ID == 4 |
|
| 147 | + * @throws EE_Error |
|
| 148 | + */ |
|
| 149 | + public static function get_taxes_for_admin() |
|
| 150 | + { |
|
| 151 | + if (empty(EE_Taxes::$_default_taxes)) { |
|
| 152 | + /** @var EEM_Price $price_model */ |
|
| 153 | + $price_model = LoaderFactory::getLoader()->getShared('EEM_Price'); |
|
| 154 | + EE_Taxes::$_default_taxes = $price_model->get_all( |
|
| 155 | + [['Price_Type.PBT_ID' => 4]] |
|
| 156 | + ); |
|
| 157 | + } |
|
| 158 | + return EE_Taxes::$_default_taxes; |
|
| 159 | + } |
|
| 160 | 160 | } |
@@ -15,2013 +15,2013 @@ |
||
| 15 | 15 | class EE_Ticket extends EE_Soft_Delete_Base_Class implements EEI_Line_Item_Object, EEI_Event_Relation, EEI_Has_Icon |
| 16 | 16 | { |
| 17 | 17 | |
| 18 | - /** |
|
| 19 | - * TicKet Sold out: |
|
| 20 | - * constant used by ticket_status() to indicate that a ticket is sold out |
|
| 21 | - * and no longer available for purchases |
|
| 22 | - */ |
|
| 23 | - const sold_out = 'TKS'; |
|
| 24 | - |
|
| 25 | - /** |
|
| 26 | - * TicKet Expired: |
|
| 27 | - * constant used by ticket_status() to indicate that a ticket is expired |
|
| 28 | - * and no longer available for purchase |
|
| 29 | - */ |
|
| 30 | - const expired = 'TKE'; |
|
| 31 | - |
|
| 32 | - /** |
|
| 33 | - * TicKet Archived: |
|
| 34 | - * constant used by ticket_status() to indicate that a ticket is archived |
|
| 35 | - * and no longer available for purchase |
|
| 36 | - */ |
|
| 37 | - const archived = 'TKA'; |
|
| 38 | - |
|
| 39 | - /** |
|
| 40 | - * TicKet Pending: |
|
| 41 | - * constant used by ticket_status() to indicate that a ticket is pending |
|
| 42 | - * and is NOT YET available for purchase |
|
| 43 | - */ |
|
| 44 | - const pending = 'TKP'; |
|
| 45 | - |
|
| 46 | - /** |
|
| 47 | - * TicKet On sale: |
|
| 48 | - * constant used by ticket_status() to indicate that a ticket is On Sale |
|
| 49 | - * and IS available for purchase |
|
| 50 | - */ |
|
| 51 | - const onsale = 'TKO'; |
|
| 52 | - |
|
| 53 | - /** |
|
| 54 | - * extra meta key for tracking ticket reservations |
|
| 55 | - * |
|
| 56 | - * @type string |
|
| 57 | - */ |
|
| 58 | - const META_KEY_TICKET_RESERVATIONS = 'ticket_reservations'; |
|
| 59 | - |
|
| 60 | - /** |
|
| 61 | - * override of parent property |
|
| 62 | - * |
|
| 63 | - * @var EEM_Ticket |
|
| 64 | - */ |
|
| 65 | - protected $_model; |
|
| 66 | - |
|
| 67 | - /** |
|
| 68 | - * cached result from method of the same name |
|
| 69 | - * |
|
| 70 | - * @var float $_ticket_total_with_taxes |
|
| 71 | - */ |
|
| 72 | - private $_ticket_total_with_taxes; |
|
| 73 | - |
|
| 74 | - |
|
| 75 | - /** |
|
| 76 | - * @param array $props_n_values incoming values |
|
| 77 | - * @param string $timezone incoming timezone (if not set the timezone set for the website will be |
|
| 78 | - * used.) |
|
| 79 | - * @param array $date_formats incoming date_formats in an array where the first value is the |
|
| 80 | - * date_format and the second value is the time format |
|
| 81 | - * @return EE_Ticket |
|
| 82 | - * @throws EE_Error |
|
| 83 | - * @throws ReflectionException |
|
| 84 | - */ |
|
| 85 | - public static function new_instance($props_n_values = [], $timezone = null, $date_formats = []) |
|
| 86 | - { |
|
| 87 | - $has_object = parent::_check_for_object($props_n_values, __CLASS__, $timezone, $date_formats); |
|
| 88 | - return $has_object ? $has_object : new self($props_n_values, false, $timezone, $date_formats); |
|
| 89 | - } |
|
| 90 | - |
|
| 91 | - |
|
| 92 | - /** |
|
| 93 | - * @param array $props_n_values incoming values from the database |
|
| 94 | - * @param string $timezone incoming timezone as set by the model. If not set the timezone for |
|
| 95 | - * the website will be used. |
|
| 96 | - * @return EE_Ticket |
|
| 97 | - * @throws EE_Error |
|
| 98 | - * @throws ReflectionException |
|
| 99 | - */ |
|
| 100 | - public static function new_instance_from_db($props_n_values = [], $timezone = null) |
|
| 101 | - { |
|
| 102 | - return new self($props_n_values, true, $timezone); |
|
| 103 | - } |
|
| 104 | - |
|
| 105 | - |
|
| 106 | - /** |
|
| 107 | - * @return bool |
|
| 108 | - * @throws EE_Error |
|
| 109 | - * @throws ReflectionException |
|
| 110 | - */ |
|
| 111 | - public function parent() |
|
| 112 | - { |
|
| 113 | - return $this->get('TKT_parent'); |
|
| 114 | - } |
|
| 115 | - |
|
| 116 | - |
|
| 117 | - /** |
|
| 118 | - * return if a ticket has quantities available for purchase |
|
| 119 | - * |
|
| 120 | - * @param int $DTT_ID the primary key for a particular datetime |
|
| 121 | - * @return boolean |
|
| 122 | - * @throws EE_Error |
|
| 123 | - * @throws ReflectionException |
|
| 124 | - */ |
|
| 125 | - public function available($DTT_ID = 0) |
|
| 126 | - { |
|
| 127 | - // are we checking availability for a particular datetime ? |
|
| 128 | - if ($DTT_ID) { |
|
| 129 | - // get that datetime object |
|
| 130 | - $datetime = $this->get_first_related('Datetime', [['DTT_ID' => $DTT_ID]]); |
|
| 131 | - // if ticket sales for this datetime have exceeded the reg limit... |
|
| 132 | - if ($datetime instanceof EE_Datetime && $datetime->sold_out()) { |
|
| 133 | - return false; |
|
| 134 | - } |
|
| 135 | - } |
|
| 136 | - // datetime is still open for registration, but is this ticket sold out ? |
|
| 137 | - return $this->qty() < 1 || $this->qty() > $this->sold(); |
|
| 138 | - } |
|
| 139 | - |
|
| 140 | - |
|
| 141 | - /** |
|
| 142 | - * Using the start date and end date this method calculates whether the ticket is On Sale, Pending, or Expired |
|
| 143 | - * |
|
| 144 | - * @param bool $display true = we'll return a localized string, otherwise we just return the value of the |
|
| 145 | - * relevant status const |
|
| 146 | - * @param bool | null $remaining if it is already known that tickets are available, then simply pass a bool to save |
|
| 147 | - * further processing |
|
| 148 | - * @return mixed status int if the display string isn't requested |
|
| 149 | - * @throws EE_Error |
|
| 150 | - * @throws ReflectionException |
|
| 151 | - */ |
|
| 152 | - public function ticket_status($display = false, $remaining = null) |
|
| 153 | - { |
|
| 154 | - $remaining = is_bool($remaining) ? $remaining : $this->is_remaining(); |
|
| 155 | - if (! $remaining) { |
|
| 156 | - return $display ? EEH_Template::pretty_status(EE_Ticket::sold_out, false, 'sentence') : EE_Ticket::sold_out; |
|
| 157 | - } |
|
| 158 | - if ($this->get('TKT_deleted')) { |
|
| 159 | - return $display ? EEH_Template::pretty_status(EE_Ticket::archived, false, 'sentence') : EE_Ticket::archived; |
|
| 160 | - } |
|
| 161 | - if ($this->is_expired()) { |
|
| 162 | - return $display ? EEH_Template::pretty_status(EE_Ticket::expired, false, 'sentence') : EE_Ticket::expired; |
|
| 163 | - } |
|
| 164 | - if ($this->is_pending()) { |
|
| 165 | - return $display ? EEH_Template::pretty_status(EE_Ticket::pending, false, 'sentence') : EE_Ticket::pending; |
|
| 166 | - } |
|
| 167 | - if ($this->is_on_sale()) { |
|
| 168 | - return $display ? EEH_Template::pretty_status(EE_Ticket::onsale, false, 'sentence') : EE_Ticket::onsale; |
|
| 169 | - } |
|
| 170 | - return ''; |
|
| 171 | - } |
|
| 172 | - |
|
| 173 | - |
|
| 174 | - /** |
|
| 175 | - * The purpose of this method is to simply return a boolean for whether there are any tickets remaining for sale |
|
| 176 | - * considering ALL the factors used for figuring that out. |
|
| 177 | - * |
|
| 178 | - * @access public |
|
| 179 | - * @param int $DTT_ID if an int above 0 is included here then we get a specific dtt. |
|
| 180 | - * @return boolean true = tickets remaining, false not. |
|
| 181 | - * @throws EE_Error |
|
| 182 | - * @throws ReflectionException |
|
| 183 | - */ |
|
| 184 | - public function is_remaining($DTT_ID = 0) |
|
| 185 | - { |
|
| 186 | - $num_remaining = $this->remaining($DTT_ID); |
|
| 187 | - if ($num_remaining === 0) { |
|
| 188 | - return false; |
|
| 189 | - } |
|
| 190 | - if ($num_remaining > 0 && $num_remaining < $this->min()) { |
|
| 191 | - return false; |
|
| 192 | - } |
|
| 193 | - return true; |
|
| 194 | - } |
|
| 195 | - |
|
| 196 | - |
|
| 197 | - /** |
|
| 198 | - * return the total number of tickets available for purchase |
|
| 199 | - * |
|
| 200 | - * @param int $DTT_ID the primary key for a particular datetime. |
|
| 201 | - * set to 0 for all related datetimes |
|
| 202 | - * @return int |
|
| 203 | - * @throws EE_Error |
|
| 204 | - * @throws ReflectionException |
|
| 205 | - */ |
|
| 206 | - public function remaining($DTT_ID = 0) |
|
| 207 | - { |
|
| 208 | - return $this->real_quantity_on_ticket('saleable', $DTT_ID); |
|
| 209 | - } |
|
| 210 | - |
|
| 211 | - |
|
| 212 | - /** |
|
| 213 | - * Gets min |
|
| 214 | - * |
|
| 215 | - * @return int |
|
| 216 | - * @throws EE_Error |
|
| 217 | - * @throws ReflectionException |
|
| 218 | - */ |
|
| 219 | - public function min() |
|
| 220 | - { |
|
| 221 | - return $this->get('TKT_min'); |
|
| 222 | - } |
|
| 223 | - |
|
| 224 | - |
|
| 225 | - /** |
|
| 226 | - * return if a ticket is no longer available cause its available dates have expired. |
|
| 227 | - * |
|
| 228 | - * @return boolean |
|
| 229 | - * @throws EE_Error |
|
| 230 | - * @throws ReflectionException |
|
| 231 | - */ |
|
| 232 | - public function is_expired() |
|
| 233 | - { |
|
| 234 | - return ($this->get_raw('TKT_end_date') < time()); |
|
| 235 | - } |
|
| 236 | - |
|
| 237 | - |
|
| 238 | - /** |
|
| 239 | - * Return if a ticket is yet to go on sale or not |
|
| 240 | - * |
|
| 241 | - * @return boolean |
|
| 242 | - * @throws EE_Error |
|
| 243 | - * @throws ReflectionException |
|
| 244 | - */ |
|
| 245 | - public function is_pending() |
|
| 246 | - { |
|
| 247 | - return ($this->get_raw('TKT_start_date') >= time()); |
|
| 248 | - } |
|
| 249 | - |
|
| 250 | - |
|
| 251 | - /** |
|
| 252 | - * Return if a ticket is on sale or not |
|
| 253 | - * |
|
| 254 | - * @return boolean |
|
| 255 | - * @throws EE_Error |
|
| 256 | - * @throws ReflectionException |
|
| 257 | - */ |
|
| 258 | - public function is_on_sale() |
|
| 259 | - { |
|
| 260 | - return ($this->get_raw('TKT_start_date') <= time() && $this->get_raw('TKT_end_date') >= time()); |
|
| 261 | - } |
|
| 262 | - |
|
| 263 | - |
|
| 264 | - /** |
|
| 265 | - * This returns the chronologically last datetime that this ticket is associated with |
|
| 266 | - * |
|
| 267 | - * @param string $date_format |
|
| 268 | - * @param string $conjunction - conjunction junction what's your function ? this string joins the start date with |
|
| 269 | - * the end date ie: Jan 01 "to" Dec 31 |
|
| 270 | - * @return string |
|
| 271 | - * @throws EE_Error |
|
| 272 | - * @throws ReflectionException |
|
| 273 | - */ |
|
| 274 | - public function date_range($date_format = '', $conjunction = ' - ') |
|
| 275 | - { |
|
| 276 | - $date_format = ! empty($date_format) ? $date_format : $this->_dt_frmt; |
|
| 277 | - $first_date = $this->first_datetime() instanceof EE_Datetime |
|
| 278 | - ? $this->first_datetime()->get_i18n_datetime('DTT_EVT_start', $date_format) |
|
| 279 | - : ''; |
|
| 280 | - $last_date = $this->last_datetime() instanceof EE_Datetime |
|
| 281 | - ? $this->last_datetime()->get_i18n_datetime('DTT_EVT_end', $date_format) |
|
| 282 | - : ''; |
|
| 283 | - |
|
| 284 | - return $first_date && $last_date ? $first_date . $conjunction . $last_date : ''; |
|
| 285 | - } |
|
| 286 | - |
|
| 287 | - |
|
| 288 | - /** |
|
| 289 | - * This returns the chronologically first datetime that this ticket is associated with |
|
| 290 | - * |
|
| 291 | - * @return EE_Datetime |
|
| 292 | - * @throws EE_Error |
|
| 293 | - * @throws ReflectionException |
|
| 294 | - */ |
|
| 295 | - public function first_datetime() |
|
| 296 | - { |
|
| 297 | - $datetimes = $this->datetimes(['limit' => 1]); |
|
| 298 | - return reset($datetimes); |
|
| 299 | - } |
|
| 300 | - |
|
| 301 | - |
|
| 302 | - /** |
|
| 303 | - * Gets all the datetimes this ticket can be used for attending. |
|
| 304 | - * Unless otherwise specified, orders datetimes by start date. |
|
| 305 | - * |
|
| 306 | - * @param array $query_params @see |
|
| 307 | - * https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md |
|
| 308 | - * @return EE_Datetime[]|EE_Base_Class[] |
|
| 309 | - * @throws EE_Error |
|
| 310 | - * @throws ReflectionException |
|
| 311 | - */ |
|
| 312 | - public function datetimes($query_params = []) |
|
| 313 | - { |
|
| 314 | - if (! isset($query_params['order_by'])) { |
|
| 315 | - $query_params['order_by']['DTT_order'] = 'ASC'; |
|
| 316 | - } |
|
| 317 | - return $this->get_many_related('Datetime', $query_params); |
|
| 318 | - } |
|
| 319 | - |
|
| 320 | - |
|
| 321 | - /** |
|
| 322 | - * This returns the chronologically last datetime that this ticket is associated with |
|
| 323 | - * |
|
| 324 | - * @return EE_Datetime |
|
| 325 | - * @throws EE_Error |
|
| 326 | - * @throws ReflectionException |
|
| 327 | - */ |
|
| 328 | - public function last_datetime() |
|
| 329 | - { |
|
| 330 | - $datetimes = $this->datetimes(['limit' => 1, 'order_by' => ['DTT_EVT_start' => 'DESC']]); |
|
| 331 | - return end($datetimes); |
|
| 332 | - } |
|
| 333 | - |
|
| 334 | - |
|
| 335 | - /** |
|
| 336 | - * This returns the total tickets sold depending on the given parameters. |
|
| 337 | - * |
|
| 338 | - * @param string $what Can be one of two options: 'ticket', 'datetime'. |
|
| 339 | - * 'ticket' = total ticket sales for all datetimes this ticket is related to |
|
| 340 | - * 'datetime' = total ticket sales for a specified datetime (required $dtt_id) |
|
| 341 | - * 'datetime' = total ticket sales in the datetime_ticket table. |
|
| 342 | - * If $dtt_id is not given then we return an array of sales indexed by datetime. |
|
| 343 | - * If $dtt_id IS given then we return the tickets sold for that given datetime. |
|
| 344 | - * @param int $dtt_id [optional] include the dtt_id with $what = 'datetime'. |
|
| 345 | - * @return mixed (array|int) how many tickets have sold |
|
| 346 | - * @throws EE_Error |
|
| 347 | - * @throws ReflectionException |
|
| 348 | - */ |
|
| 349 | - public function tickets_sold($what = 'ticket', $dtt_id = null) |
|
| 350 | - { |
|
| 351 | - $total = 0; |
|
| 352 | - $tickets_sold = $this->_all_tickets_sold(); |
|
| 353 | - switch ($what) { |
|
| 354 | - case 'ticket': |
|
| 355 | - return $tickets_sold['ticket']; |
|
| 356 | - break; |
|
| 357 | - case 'datetime': |
|
| 358 | - if (empty($tickets_sold['datetime'])) { |
|
| 359 | - return $total; |
|
| 360 | - } |
|
| 361 | - if (! empty($dtt_id) && ! isset($tickets_sold['datetime'][ $dtt_id ])) { |
|
| 362 | - EE_Error::add_error( |
|
| 363 | - __( |
|
| 364 | - 'You\'ve requested the amount of tickets sold for a given ticket and datetime, however there are no records for the datetime id you included. Are you SURE that is a datetime related to this ticket?', |
|
| 365 | - 'event_espresso' |
|
| 366 | - ), |
|
| 367 | - __FILE__, |
|
| 368 | - __FUNCTION__, |
|
| 369 | - __LINE__ |
|
| 370 | - ); |
|
| 371 | - return $total; |
|
| 372 | - } |
|
| 373 | - return empty($dtt_id) ? $tickets_sold['datetime'] : $tickets_sold['datetime'][ $dtt_id ]; |
|
| 374 | - break; |
|
| 375 | - default: |
|
| 376 | - return $total; |
|
| 377 | - } |
|
| 378 | - } |
|
| 379 | - |
|
| 380 | - |
|
| 381 | - /** |
|
| 382 | - * This returns an array indexed by datetime_id for tickets sold with this ticket. |
|
| 383 | - * |
|
| 384 | - * @return EE_Ticket[] |
|
| 385 | - * @throws EE_Error |
|
| 386 | - * @throws ReflectionException |
|
| 387 | - */ |
|
| 388 | - protected function _all_tickets_sold() |
|
| 389 | - { |
|
| 390 | - $datetimes = $this->get_many_related('Datetime'); |
|
| 391 | - $tickets_sold = []; |
|
| 392 | - if (! empty($datetimes)) { |
|
| 393 | - foreach ($datetimes as $datetime) { |
|
| 394 | - $tickets_sold['datetime'][ $datetime->ID() ] = $datetime->get('DTT_sold'); |
|
| 395 | - } |
|
| 396 | - } |
|
| 397 | - // Tickets sold |
|
| 398 | - $tickets_sold['ticket'] = $this->sold(); |
|
| 399 | - return $tickets_sold; |
|
| 400 | - } |
|
| 401 | - |
|
| 402 | - |
|
| 403 | - /** |
|
| 404 | - * This returns the base price object for the ticket. |
|
| 405 | - * |
|
| 406 | - * @param bool $return_array whether to return as an array indexed by price id or just the object. |
|
| 407 | - * @return EE_Price|EE_Base_Class|EE_Price[]|EE_Base_Class[] |
|
| 408 | - * @throws EE_Error |
|
| 409 | - * @throws ReflectionException |
|
| 410 | - */ |
|
| 411 | - public function base_price($return_array = false) |
|
| 412 | - { |
|
| 413 | - $_where = ['Price_Type.PBT_ID' => EEM_Price_Type::base_type_base_price]; |
|
| 414 | - return $return_array |
|
| 415 | - ? $this->get_many_related('Price', [$_where]) |
|
| 416 | - : $this->get_first_related('Price', [$_where]); |
|
| 417 | - } |
|
| 418 | - |
|
| 419 | - |
|
| 420 | - /** |
|
| 421 | - * This returns ONLY the price modifiers for the ticket (i.e. no taxes or base price) |
|
| 422 | - * |
|
| 423 | - * @access public |
|
| 424 | - * @return EE_Price[] |
|
| 425 | - * @throws EE_Error |
|
| 426 | - * @throws ReflectionException |
|
| 427 | - */ |
|
| 428 | - public function price_modifiers() |
|
| 429 | - { |
|
| 430 | - $query_params = [ |
|
| 431 | - 0 => [ |
|
| 432 | - 'Price_Type.PBT_ID' => [ |
|
| 433 | - 'NOT IN', |
|
| 434 | - [EEM_Price_Type::base_type_base_price, EEM_Price_Type::base_type_tax], |
|
| 435 | - ], |
|
| 436 | - ], |
|
| 437 | - ]; |
|
| 438 | - return $this->prices($query_params); |
|
| 439 | - } |
|
| 440 | - |
|
| 441 | - |
|
| 442 | - /** |
|
| 443 | - * This returns ONLY the price modifiers for the ticket (i.e. no taxes or base price) |
|
| 444 | - * |
|
| 445 | - * @access public |
|
| 446 | - * @return EE_Price[] |
|
| 447 | - * @throws EE_Error |
|
| 448 | - * @throws ReflectionException |
|
| 449 | - */ |
|
| 450 | - public function tax_price_modifiers() |
|
| 451 | - { |
|
| 452 | - $query_params = [ |
|
| 453 | - 0 => [ |
|
| 454 | - 'Price_Type.PBT_ID' => EEM_Price_Type::base_type_tax, |
|
| 455 | - ], |
|
| 456 | - ]; |
|
| 457 | - return $this->prices($query_params); |
|
| 458 | - } |
|
| 459 | - |
|
| 460 | - |
|
| 461 | - /** |
|
| 462 | - * Gets all the prices that combine to form the final price of this ticket |
|
| 463 | - * |
|
| 464 | - * @param array $query_params @see |
|
| 465 | - * https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md |
|
| 466 | - * @return EE_Price[]|EE_Base_Class[] |
|
| 467 | - * @throws EE_Error |
|
| 468 | - * @throws ReflectionException |
|
| 469 | - */ |
|
| 470 | - public function prices($query_params = []) |
|
| 471 | - { |
|
| 472 | - return $this->get_many_related('Price', $query_params); |
|
| 473 | - } |
|
| 474 | - |
|
| 475 | - |
|
| 476 | - /** |
|
| 477 | - * Gets all the ticket datetimes (ie, relations between datetimes and tickets) |
|
| 478 | - * |
|
| 479 | - * @param array $query_params @see |
|
| 480 | - * https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md |
|
| 481 | - * @return EE_Datetime_Ticket|EE_Base_Class[] |
|
| 482 | - * @throws EE_Error |
|
| 483 | - * @throws ReflectionException |
|
| 484 | - */ |
|
| 485 | - public function datetime_tickets($query_params = []) |
|
| 486 | - { |
|
| 487 | - return $this->get_many_related('Datetime_Ticket', $query_params); |
|
| 488 | - } |
|
| 489 | - |
|
| 490 | - |
|
| 491 | - /** |
|
| 492 | - * Gets all the datetimes from the db ordered by DTT_order |
|
| 493 | - * |
|
| 494 | - * @param boolean $show_expired |
|
| 495 | - * @param boolean $show_deleted |
|
| 496 | - * @return EE_Datetime[] |
|
| 497 | - * @throws EE_Error |
|
| 498 | - * @throws ReflectionException |
|
| 499 | - */ |
|
| 500 | - public function datetimes_ordered($show_expired = true, $show_deleted = false) |
|
| 501 | - { |
|
| 502 | - return EEM_Datetime::instance($this->_timezone)->get_datetimes_for_ticket_ordered_by_DTT_order( |
|
| 503 | - $this->ID(), |
|
| 504 | - $show_expired, |
|
| 505 | - $show_deleted |
|
| 506 | - ); |
|
| 507 | - } |
|
| 508 | - |
|
| 509 | - |
|
| 510 | - /** |
|
| 511 | - * Gets ID |
|
| 512 | - * |
|
| 513 | - * @return int |
|
| 514 | - * @throws EE_Error |
|
| 515 | - * @throws ReflectionException |
|
| 516 | - */ |
|
| 517 | - public function ID() |
|
| 518 | - { |
|
| 519 | - return $this->get('TKT_ID'); |
|
| 520 | - } |
|
| 521 | - |
|
| 522 | - |
|
| 523 | - /** |
|
| 524 | - * get the author of the ticket. |
|
| 525 | - * |
|
| 526 | - * @return int |
|
| 527 | - * @throws EE_Error |
|
| 528 | - * @throws ReflectionException |
|
| 529 | - * @since 4.5.0 |
|
| 530 | - */ |
|
| 531 | - public function wp_user() |
|
| 532 | - { |
|
| 533 | - return $this->get('TKT_wp_user'); |
|
| 534 | - } |
|
| 535 | - |
|
| 536 | - |
|
| 537 | - /** |
|
| 538 | - * Gets the template for the ticket |
|
| 539 | - * |
|
| 540 | - * @return EE_Ticket_Template|EE_Base_Class |
|
| 541 | - * @throws EE_Error |
|
| 542 | - * @throws ReflectionException |
|
| 543 | - */ |
|
| 544 | - public function template() |
|
| 545 | - { |
|
| 546 | - return $this->get_first_related('Ticket_Template'); |
|
| 547 | - } |
|
| 548 | - |
|
| 549 | - |
|
| 550 | - /** |
|
| 551 | - * Simply returns an array of EE_Price objects that are taxes. |
|
| 552 | - * |
|
| 553 | - * @return EE_Price[] |
|
| 554 | - * @throws EE_Error |
|
| 555 | - * @throws ReflectionException |
|
| 556 | - */ |
|
| 557 | - public function get_ticket_taxes_for_admin(): array |
|
| 558 | - { |
|
| 559 | - /** @var EE_Admin_Config $admin_config */ |
|
| 560 | - $admin_config = LoaderFactory::getShared(EE_Admin_Config::class); |
|
| 561 | - return $admin_config->useAdvancedEditor() ? $this->tax_price_modifiers() : EE_Taxes::get_taxes_for_admin(); |
|
| 562 | - } |
|
| 563 | - |
|
| 564 | - |
|
| 565 | - /** |
|
| 566 | - * @return float |
|
| 567 | - * @throws EE_Error |
|
| 568 | - * @throws ReflectionException |
|
| 569 | - */ |
|
| 570 | - public function ticket_price() |
|
| 571 | - { |
|
| 572 | - return $this->get('TKT_price'); |
|
| 573 | - } |
|
| 574 | - |
|
| 575 | - |
|
| 576 | - /** |
|
| 577 | - * @return mixed |
|
| 578 | - * @throws EE_Error |
|
| 579 | - * @throws ReflectionException |
|
| 580 | - */ |
|
| 581 | - public function pretty_price() |
|
| 582 | - { |
|
| 583 | - return $this->get_pretty('TKT_price'); |
|
| 584 | - } |
|
| 585 | - |
|
| 586 | - |
|
| 587 | - /** |
|
| 588 | - * @return bool |
|
| 589 | - * @throws EE_Error |
|
| 590 | - * @throws ReflectionException |
|
| 591 | - */ |
|
| 592 | - public function is_free() |
|
| 593 | - { |
|
| 594 | - return $this->get_ticket_total_with_taxes() === (float) 0; |
|
| 595 | - } |
|
| 596 | - |
|
| 597 | - |
|
| 598 | - /** |
|
| 599 | - * get_ticket_total_with_taxes |
|
| 600 | - * |
|
| 601 | - * @param bool $no_cache |
|
| 602 | - * @return float |
|
| 603 | - * @throws EE_Error |
|
| 604 | - * @throws ReflectionException |
|
| 605 | - */ |
|
| 606 | - public function get_ticket_total_with_taxes($no_cache = false) |
|
| 607 | - { |
|
| 608 | - if ($this->_ticket_total_with_taxes === null || $no_cache) { |
|
| 609 | - /** @var EE_Admin_Config $admin_config */ |
|
| 610 | - $admin_config = LoaderFactory::getShared(EE_Admin_Config::class); |
|
| 611 | - $this->_ticket_total_with_taxes = $admin_config->useAdvancedEditor() |
|
| 612 | - ? $this->ticket_price() |
|
| 613 | - : $this->get_ticket_subtotal() + $this->get_ticket_taxes_total_for_admin(); |
|
| 614 | - } |
|
| 615 | - return (float) $this->_ticket_total_with_taxes; |
|
| 616 | - } |
|
| 617 | - |
|
| 618 | - |
|
| 619 | - /** |
|
| 620 | - * @throws EE_Error |
|
| 621 | - * @throws ReflectionException |
|
| 622 | - */ |
|
| 623 | - public function ensure_TKT_Price_correct() |
|
| 624 | - { |
|
| 625 | - $this->set('TKT_price', EE_Taxes::get_subtotal_for_admin($this)); |
|
| 626 | - $this->save(); |
|
| 627 | - } |
|
| 628 | - |
|
| 629 | - |
|
| 630 | - /** |
|
| 631 | - * @return float |
|
| 632 | - * @throws EE_Error |
|
| 633 | - * @throws ReflectionException |
|
| 634 | - */ |
|
| 635 | - public function get_ticket_subtotal() |
|
| 636 | - { |
|
| 637 | - return EE_Taxes::get_subtotal_for_admin($this); |
|
| 638 | - } |
|
| 639 | - |
|
| 640 | - |
|
| 641 | - /** |
|
| 642 | - * Returns the total taxes applied to this ticket |
|
| 643 | - * |
|
| 644 | - * @return float |
|
| 645 | - * @throws EE_Error |
|
| 646 | - * @throws ReflectionException |
|
| 647 | - */ |
|
| 648 | - public function get_ticket_taxes_total_for_admin() |
|
| 649 | - { |
|
| 650 | - return EE_Taxes::get_total_taxes_for_admin($this); |
|
| 651 | - } |
|
| 652 | - |
|
| 653 | - |
|
| 654 | - /** |
|
| 655 | - * Sets name |
|
| 656 | - * |
|
| 657 | - * @param string $name |
|
| 658 | - * @throws EE_Error |
|
| 659 | - * @throws ReflectionException |
|
| 660 | - */ |
|
| 661 | - public function set_name($name) |
|
| 662 | - { |
|
| 663 | - $this->set('TKT_name', $name); |
|
| 664 | - } |
|
| 665 | - |
|
| 666 | - |
|
| 667 | - /** |
|
| 668 | - * Gets description |
|
| 669 | - * |
|
| 670 | - * @return string |
|
| 671 | - * @throws EE_Error |
|
| 672 | - * @throws ReflectionException |
|
| 673 | - */ |
|
| 674 | - public function description() |
|
| 675 | - { |
|
| 676 | - return $this->get('TKT_description'); |
|
| 677 | - } |
|
| 678 | - |
|
| 679 | - |
|
| 680 | - /** |
|
| 681 | - * Sets description |
|
| 682 | - * |
|
| 683 | - * @param string $description |
|
| 684 | - * @throws EE_Error |
|
| 685 | - * @throws ReflectionException |
|
| 686 | - */ |
|
| 687 | - public function set_description($description) |
|
| 688 | - { |
|
| 689 | - $this->set('TKT_description', $description); |
|
| 690 | - } |
|
| 691 | - |
|
| 692 | - |
|
| 693 | - /** |
|
| 694 | - * Gets start_date |
|
| 695 | - * |
|
| 696 | - * @param string $date_format |
|
| 697 | - * @param string $time_format |
|
| 698 | - * @return string |
|
| 699 | - * @throws EE_Error |
|
| 700 | - * @throws ReflectionException |
|
| 701 | - */ |
|
| 702 | - public function start_date($date_format = '', $time_format = '') |
|
| 703 | - { |
|
| 704 | - return $this->_get_datetime('TKT_start_date', $date_format, $time_format); |
|
| 705 | - } |
|
| 706 | - |
|
| 707 | - |
|
| 708 | - /** |
|
| 709 | - * Sets start_date |
|
| 710 | - * |
|
| 711 | - * @param string $start_date |
|
| 712 | - * @return void |
|
| 713 | - * @throws EE_Error |
|
| 714 | - * @throws ReflectionException |
|
| 715 | - */ |
|
| 716 | - public function set_start_date($start_date) |
|
| 717 | - { |
|
| 718 | - $this->_set_date_time('B', $start_date, 'TKT_start_date'); |
|
| 719 | - } |
|
| 720 | - |
|
| 721 | - |
|
| 722 | - /** |
|
| 723 | - * Gets end_date |
|
| 724 | - * |
|
| 725 | - * @param string $date_format |
|
| 726 | - * @param string $time_format |
|
| 727 | - * @return string |
|
| 728 | - * @throws EE_Error |
|
| 729 | - * @throws ReflectionException |
|
| 730 | - */ |
|
| 731 | - public function end_date($date_format = '', $time_format = '') |
|
| 732 | - { |
|
| 733 | - return $this->_get_datetime('TKT_end_date', $date_format, $time_format); |
|
| 734 | - } |
|
| 735 | - |
|
| 736 | - |
|
| 737 | - /** |
|
| 738 | - * Sets end_date |
|
| 739 | - * |
|
| 740 | - * @param string $end_date |
|
| 741 | - * @return void |
|
| 742 | - * @throws EE_Error |
|
| 743 | - * @throws ReflectionException |
|
| 744 | - */ |
|
| 745 | - public function set_end_date($end_date) |
|
| 746 | - { |
|
| 747 | - $this->_set_date_time('B', $end_date, 'TKT_end_date'); |
|
| 748 | - } |
|
| 749 | - |
|
| 750 | - |
|
| 751 | - /** |
|
| 752 | - * Sets sell until time |
|
| 753 | - * |
|
| 754 | - * @param string $time a string representation of the sell until time (ex 9am or 7:30pm) |
|
| 755 | - * @throws EE_Error |
|
| 756 | - * @throws ReflectionException |
|
| 757 | - * @since 4.5.0 |
|
| 758 | - */ |
|
| 759 | - public function set_end_time($time) |
|
| 760 | - { |
|
| 761 | - $this->_set_time_for($time, 'TKT_end_date'); |
|
| 762 | - } |
|
| 763 | - |
|
| 764 | - |
|
| 765 | - /** |
|
| 766 | - * Sets min |
|
| 767 | - * |
|
| 768 | - * @param int $min |
|
| 769 | - * @return void |
|
| 770 | - * @throws EE_Error |
|
| 771 | - * @throws ReflectionException |
|
| 772 | - */ |
|
| 773 | - public function set_min($min) |
|
| 774 | - { |
|
| 775 | - $this->set('TKT_min', $min); |
|
| 776 | - } |
|
| 777 | - |
|
| 778 | - |
|
| 779 | - /** |
|
| 780 | - * Gets max |
|
| 781 | - * |
|
| 782 | - * @return int |
|
| 783 | - * @throws EE_Error |
|
| 784 | - * @throws ReflectionException |
|
| 785 | - */ |
|
| 786 | - public function max() |
|
| 787 | - { |
|
| 788 | - return $this->get('TKT_max'); |
|
| 789 | - } |
|
| 790 | - |
|
| 791 | - |
|
| 792 | - /** |
|
| 793 | - * Sets max |
|
| 794 | - * |
|
| 795 | - * @param int $max |
|
| 796 | - * @return void |
|
| 797 | - * @throws EE_Error |
|
| 798 | - * @throws ReflectionException |
|
| 799 | - */ |
|
| 800 | - public function set_max($max) |
|
| 801 | - { |
|
| 802 | - $this->set('TKT_max', $max); |
|
| 803 | - } |
|
| 804 | - |
|
| 805 | - |
|
| 806 | - /** |
|
| 807 | - * Sets price |
|
| 808 | - * |
|
| 809 | - * @param float $price |
|
| 810 | - * @return void |
|
| 811 | - * @throws EE_Error |
|
| 812 | - * @throws ReflectionException |
|
| 813 | - */ |
|
| 814 | - public function set_price($price) |
|
| 815 | - { |
|
| 816 | - $this->set('TKT_price', $price); |
|
| 817 | - } |
|
| 818 | - |
|
| 819 | - |
|
| 820 | - /** |
|
| 821 | - * Gets sold |
|
| 822 | - * |
|
| 823 | - * @return int |
|
| 824 | - * @throws EE_Error |
|
| 825 | - * @throws ReflectionException |
|
| 826 | - */ |
|
| 827 | - public function sold() |
|
| 828 | - { |
|
| 829 | - return $this->get_raw('TKT_sold'); |
|
| 830 | - } |
|
| 831 | - |
|
| 832 | - |
|
| 833 | - /** |
|
| 834 | - * Sets sold |
|
| 835 | - * |
|
| 836 | - * @param int $sold |
|
| 837 | - * @return void |
|
| 838 | - * @throws EE_Error |
|
| 839 | - * @throws ReflectionException |
|
| 840 | - */ |
|
| 841 | - public function set_sold($sold) |
|
| 842 | - { |
|
| 843 | - // sold can not go below zero |
|
| 844 | - $sold = max(0, $sold); |
|
| 845 | - $this->set('TKT_sold', $sold); |
|
| 846 | - } |
|
| 847 | - |
|
| 848 | - |
|
| 849 | - /** |
|
| 850 | - * Increments sold by amount passed by $qty AND decrements the reserved count on both this ticket and its |
|
| 851 | - * associated datetimes. |
|
| 852 | - * |
|
| 853 | - * @param int $qty |
|
| 854 | - * @return boolean |
|
| 855 | - * @throws EE_Error |
|
| 856 | - * @throws InvalidArgumentException |
|
| 857 | - * @throws InvalidDataTypeException |
|
| 858 | - * @throws InvalidInterfaceException |
|
| 859 | - * @throws ReflectionException |
|
| 860 | - * @since 4.9.80.p |
|
| 861 | - */ |
|
| 862 | - public function increaseSold($qty = 1) |
|
| 863 | - { |
|
| 864 | - $qty = absint($qty); |
|
| 865 | - // increment sold and decrement reserved datetime quantities simultaneously |
|
| 866 | - // don't worry about failures, because they must have already had a spot reserved |
|
| 867 | - $this->increaseSoldForDatetimes($qty); |
|
| 868 | - // Increment and decrement ticket quantities simultaneously |
|
| 869 | - $success = $this->adjustNumericFieldsInDb( |
|
| 870 | - [ |
|
| 871 | - 'TKT_reserved' => $qty * -1, |
|
| 872 | - 'TKT_sold' => $qty, |
|
| 873 | - ] |
|
| 874 | - ); |
|
| 875 | - do_action( |
|
| 876 | - 'AHEE__EE_Ticket__increase_sold', |
|
| 877 | - $this, |
|
| 878 | - $qty, |
|
| 879 | - $this->sold(), |
|
| 880 | - $success |
|
| 881 | - ); |
|
| 882 | - return $success; |
|
| 883 | - } |
|
| 884 | - |
|
| 885 | - |
|
| 886 | - /** |
|
| 887 | - * On each datetime related to this ticket, increases its sold count and decreases its reserved count by $qty. |
|
| 888 | - * |
|
| 889 | - * @param int $qty positive or negative. Positive means to increase sold counts (and decrease reserved |
|
| 890 | - * counts), Negative means to decreases old counts (and increase reserved counts). |
|
| 891 | - * @param EE_Datetime[] $datetimes |
|
| 892 | - * @throws EE_Error |
|
| 893 | - * @throws InvalidArgumentException |
|
| 894 | - * @throws InvalidDataTypeException |
|
| 895 | - * @throws InvalidInterfaceException |
|
| 896 | - * @throws ReflectionException |
|
| 897 | - * @since 4.9.80.p |
|
| 898 | - */ |
|
| 899 | - protected function increaseSoldForDatetimes($qty, array $datetimes = []) |
|
| 900 | - { |
|
| 901 | - $datetimes = ! empty($datetimes) ? $datetimes : $this->datetimes(); |
|
| 902 | - foreach ($datetimes as $datetime) { |
|
| 903 | - $datetime->increaseSold($qty); |
|
| 904 | - } |
|
| 905 | - } |
|
| 906 | - |
|
| 907 | - |
|
| 908 | - /** |
|
| 909 | - * Decrements (subtracts) sold by amount passed by $qty on both the ticket and its related datetimes directly in the |
|
| 910 | - * DB and then updates the model objects. |
|
| 911 | - * Does not affect the reserved counts. |
|
| 912 | - * |
|
| 913 | - * @param int $qty |
|
| 914 | - * @return boolean |
|
| 915 | - * @throws EE_Error |
|
| 916 | - * @throws InvalidArgumentException |
|
| 917 | - * @throws InvalidDataTypeException |
|
| 918 | - * @throws InvalidInterfaceException |
|
| 919 | - * @throws ReflectionException |
|
| 920 | - * @since 4.9.80.p |
|
| 921 | - */ |
|
| 922 | - public function decreaseSold($qty = 1) |
|
| 923 | - { |
|
| 924 | - $qty = absint($qty); |
|
| 925 | - $this->decreaseSoldForDatetimes($qty); |
|
| 926 | - $success = $this->adjustNumericFieldsInDb( |
|
| 927 | - [ |
|
| 928 | - 'TKT_sold' => $qty * -1, |
|
| 929 | - ] |
|
| 930 | - ); |
|
| 931 | - do_action( |
|
| 932 | - 'AHEE__EE_Ticket__decrease_sold', |
|
| 933 | - $this, |
|
| 934 | - $qty, |
|
| 935 | - $this->sold(), |
|
| 936 | - $success |
|
| 937 | - ); |
|
| 938 | - return $success; |
|
| 939 | - } |
|
| 940 | - |
|
| 941 | - |
|
| 942 | - /** |
|
| 943 | - * Decreases sold on related datetimes |
|
| 944 | - * |
|
| 945 | - * @param int $qty |
|
| 946 | - * @param EE_Datetime[] $datetimes |
|
| 947 | - * @return void |
|
| 948 | - * @throws EE_Error |
|
| 949 | - * @throws InvalidArgumentException |
|
| 950 | - * @throws InvalidDataTypeException |
|
| 951 | - * @throws InvalidInterfaceException |
|
| 952 | - * @throws ReflectionException |
|
| 953 | - * @since 4.9.80.p |
|
| 954 | - */ |
|
| 955 | - protected function decreaseSoldForDatetimes($qty = 1, array $datetimes = []) |
|
| 956 | - { |
|
| 957 | - $datetimes = ! empty($datetimes) ? $datetimes : $this->datetimes(); |
|
| 958 | - if (is_array($datetimes)) { |
|
| 959 | - foreach ($datetimes as $datetime) { |
|
| 960 | - if ($datetime instanceof EE_Datetime) { |
|
| 961 | - $datetime->decreaseSold($qty); |
|
| 962 | - } |
|
| 963 | - } |
|
| 964 | - } |
|
| 965 | - } |
|
| 966 | - |
|
| 967 | - |
|
| 968 | - /** |
|
| 969 | - * Gets qty of reserved tickets |
|
| 970 | - * |
|
| 971 | - * @return int |
|
| 972 | - * @throws EE_Error |
|
| 973 | - * @throws ReflectionException |
|
| 974 | - */ |
|
| 975 | - public function reserved() |
|
| 976 | - { |
|
| 977 | - return $this->get_raw('TKT_reserved'); |
|
| 978 | - } |
|
| 979 | - |
|
| 980 | - |
|
| 981 | - /** |
|
| 982 | - * Sets reserved |
|
| 983 | - * |
|
| 984 | - * @param int $reserved |
|
| 985 | - * @return void |
|
| 986 | - * @throws EE_Error |
|
| 987 | - * @throws ReflectionException |
|
| 988 | - */ |
|
| 989 | - public function set_reserved($reserved) |
|
| 990 | - { |
|
| 991 | - // reserved can not go below zero |
|
| 992 | - $reserved = max(0, (int) $reserved); |
|
| 993 | - $this->set('TKT_reserved', $reserved); |
|
| 994 | - } |
|
| 995 | - |
|
| 996 | - |
|
| 997 | - /** |
|
| 998 | - * Increments reserved by amount passed by $qty, and persists it immediately to the database. |
|
| 999 | - * |
|
| 1000 | - * @param int $qty |
|
| 1001 | - * @param string $source |
|
| 1002 | - * @return bool whether we successfully reserved the ticket or not. |
|
| 1003 | - * @throws EE_Error |
|
| 1004 | - * @throws InvalidArgumentException |
|
| 1005 | - * @throws ReflectionException |
|
| 1006 | - * @throws InvalidDataTypeException |
|
| 1007 | - * @throws InvalidInterfaceException |
|
| 1008 | - * @since 4.9.80.p |
|
| 1009 | - */ |
|
| 1010 | - public function increaseReserved($qty = 1, $source = 'unknown') |
|
| 1011 | - { |
|
| 1012 | - $qty = absint($qty); |
|
| 1013 | - do_action( |
|
| 1014 | - 'AHEE__EE_Ticket__increase_reserved__begin', |
|
| 1015 | - $this, |
|
| 1016 | - $qty, |
|
| 1017 | - $source |
|
| 1018 | - ); |
|
| 1019 | - $this->add_extra_meta(EE_Ticket::META_KEY_TICKET_RESERVATIONS, "{$qty} from {$source}"); |
|
| 1020 | - $success = false; |
|
| 1021 | - $datetimes_adjusted_successfully = $this->increaseReservedForDatetimes($qty); |
|
| 1022 | - if ($datetimes_adjusted_successfully) { |
|
| 1023 | - $success = $this->incrementFieldConditionallyInDb( |
|
| 1024 | - 'TKT_reserved', |
|
| 1025 | - 'TKT_sold', |
|
| 1026 | - 'TKT_qty', |
|
| 1027 | - $qty |
|
| 1028 | - ); |
|
| 1029 | - if (! $success) { |
|
| 1030 | - // The datetimes were successfully bumped, but not the |
|
| 1031 | - // ticket. So we need to manually rollback the datetimes. |
|
| 1032 | - $this->decreaseReservedForDatetimes($qty); |
|
| 1033 | - } |
|
| 1034 | - } |
|
| 1035 | - do_action( |
|
| 1036 | - 'AHEE__EE_Ticket__increase_reserved', |
|
| 1037 | - $this, |
|
| 1038 | - $qty, |
|
| 1039 | - $this->reserved(), |
|
| 1040 | - $success |
|
| 1041 | - ); |
|
| 1042 | - return $success; |
|
| 1043 | - } |
|
| 1044 | - |
|
| 1045 | - |
|
| 1046 | - /** |
|
| 1047 | - * Increases reserved counts on related datetimes |
|
| 1048 | - * |
|
| 1049 | - * @param int $qty |
|
| 1050 | - * @param EE_Datetime[] $datetimes |
|
| 1051 | - * @return boolean indicating success |
|
| 1052 | - * @throws EE_Error |
|
| 1053 | - * @throws InvalidArgumentException |
|
| 1054 | - * @throws InvalidDataTypeException |
|
| 1055 | - * @throws InvalidInterfaceException |
|
| 1056 | - * @throws ReflectionException |
|
| 1057 | - * @since 4.9.80.p |
|
| 1058 | - */ |
|
| 1059 | - protected function increaseReservedForDatetimes($qty = 1, array $datetimes = []) |
|
| 1060 | - { |
|
| 1061 | - $datetimes = ! empty($datetimes) ? $datetimes : $this->datetimes(); |
|
| 1062 | - $datetimes_updated = []; |
|
| 1063 | - $limit_exceeded = false; |
|
| 1064 | - if (is_array($datetimes)) { |
|
| 1065 | - foreach ($datetimes as $datetime) { |
|
| 1066 | - if ($datetime instanceof EE_Datetime) { |
|
| 1067 | - if ($datetime->increaseReserved($qty)) { |
|
| 1068 | - $datetimes_updated[] = $datetime; |
|
| 1069 | - } else { |
|
| 1070 | - $limit_exceeded = true; |
|
| 1071 | - break; |
|
| 1072 | - } |
|
| 1073 | - } |
|
| 1074 | - } |
|
| 1075 | - // If somewhere along the way we detected a datetime whose |
|
| 1076 | - // limit was exceeded, do a manual rollback. |
|
| 1077 | - if ($limit_exceeded) { |
|
| 1078 | - $this->decreaseReservedForDatetimes($qty, $datetimes_updated); |
|
| 1079 | - return false; |
|
| 1080 | - } |
|
| 1081 | - } |
|
| 1082 | - return true; |
|
| 1083 | - } |
|
| 1084 | - |
|
| 1085 | - |
|
| 1086 | - /** |
|
| 1087 | - * Decrements (subtracts) reserved by amount passed by $qty, and persists it immediately to the database. |
|
| 1088 | - * |
|
| 1089 | - * @param int $qty |
|
| 1090 | - * @param bool $adjust_datetimes |
|
| 1091 | - * @param string $source |
|
| 1092 | - * @return boolean |
|
| 1093 | - * @throws EE_Error |
|
| 1094 | - * @throws InvalidArgumentException |
|
| 1095 | - * @throws ReflectionException |
|
| 1096 | - * @throws InvalidDataTypeException |
|
| 1097 | - * @throws InvalidInterfaceException |
|
| 1098 | - * @since 4.9.80.p |
|
| 1099 | - */ |
|
| 1100 | - public function decreaseReserved($qty = 1, $adjust_datetimes = true, $source = 'unknown') |
|
| 1101 | - { |
|
| 1102 | - $qty = absint($qty); |
|
| 1103 | - $this->add_extra_meta(EE_Ticket::META_KEY_TICKET_RESERVATIONS, "-{$qty} from {$source}"); |
|
| 1104 | - if ($adjust_datetimes) { |
|
| 1105 | - $this->decreaseReservedForDatetimes($qty); |
|
| 1106 | - } |
|
| 1107 | - $success = $this->adjustNumericFieldsInDb( |
|
| 1108 | - [ |
|
| 1109 | - 'TKT_reserved' => $qty * -1, |
|
| 1110 | - ] |
|
| 1111 | - ); |
|
| 1112 | - do_action( |
|
| 1113 | - 'AHEE__EE_Ticket__decrease_reserved', |
|
| 1114 | - $this, |
|
| 1115 | - $qty, |
|
| 1116 | - $this->reserved(), |
|
| 1117 | - $success |
|
| 1118 | - ); |
|
| 1119 | - return $success; |
|
| 1120 | - } |
|
| 1121 | - |
|
| 1122 | - |
|
| 1123 | - /** |
|
| 1124 | - * Decreases the reserved count on the specified datetimes. |
|
| 1125 | - * |
|
| 1126 | - * @param int $qty |
|
| 1127 | - * @param EE_Datetime[] $datetimes |
|
| 1128 | - * @throws EE_Error |
|
| 1129 | - * @throws InvalidArgumentException |
|
| 1130 | - * @throws ReflectionException |
|
| 1131 | - * @throws InvalidDataTypeException |
|
| 1132 | - * @throws InvalidInterfaceException |
|
| 1133 | - * @since 4.9.80.p |
|
| 1134 | - */ |
|
| 1135 | - protected function decreaseReservedForDatetimes($qty = 1, array $datetimes = []) |
|
| 1136 | - { |
|
| 1137 | - $datetimes = ! empty($datetimes) ? $datetimes : $this->datetimes(); |
|
| 1138 | - foreach ($datetimes as $datetime) { |
|
| 1139 | - if ($datetime instanceof EE_Datetime) { |
|
| 1140 | - $datetime->decreaseReserved($qty); |
|
| 1141 | - } |
|
| 1142 | - } |
|
| 1143 | - } |
|
| 1144 | - |
|
| 1145 | - |
|
| 1146 | - /** |
|
| 1147 | - * Gets ticket quantity |
|
| 1148 | - * |
|
| 1149 | - * @param string $context ticket quantity is somewhat subjective depending on the exact information sought |
|
| 1150 | - * therefore $context can be one of three values: '', 'reg_limit', or 'saleable' |
|
| 1151 | - * '' (default) quantity is the actual db value for TKT_qty, unaffected by other objects |
|
| 1152 | - * REG LIMIT: caps qty based on DTT_reg_limit for ALL related datetimes |
|
| 1153 | - * SALEABLE: also considers datetime sold and returns zero if ANY DTT is sold out, and |
|
| 1154 | - * is therefore the truest measure of tickets that can be purchased at the moment |
|
| 1155 | - * @return int |
|
| 1156 | - * @throws EE_Error |
|
| 1157 | - * @throws ReflectionException |
|
| 1158 | - */ |
|
| 1159 | - public function qty($context = '') |
|
| 1160 | - { |
|
| 1161 | - switch ($context) { |
|
| 1162 | - case 'reg_limit': |
|
| 1163 | - return $this->real_quantity_on_ticket(); |
|
| 1164 | - case 'saleable': |
|
| 1165 | - return $this->real_quantity_on_ticket('saleable'); |
|
| 1166 | - default: |
|
| 1167 | - return $this->get_raw('TKT_qty'); |
|
| 1168 | - } |
|
| 1169 | - } |
|
| 1170 | - |
|
| 1171 | - |
|
| 1172 | - /** |
|
| 1173 | - * Gets ticket quantity |
|
| 1174 | - * |
|
| 1175 | - * @param string $context ticket quantity is somewhat subjective depending on the exact information sought |
|
| 1176 | - * therefore $context can be one of two values: 'reg_limit', or 'saleable' |
|
| 1177 | - * REG LIMIT: caps qty based on DTT_reg_limit for ALL related datetimes |
|
| 1178 | - * SALEABLE: also considers datetime sold and returns zero if ANY DTT is sold out, and |
|
| 1179 | - * is therefore the truest measure of tickets that can be purchased at the moment |
|
| 1180 | - * @param int $DTT_ID the primary key for a particular datetime. |
|
| 1181 | - * set to 0 for all related datetimes |
|
| 1182 | - * @return int |
|
| 1183 | - * @throws EE_Error |
|
| 1184 | - * @throws ReflectionException |
|
| 1185 | - */ |
|
| 1186 | - public function real_quantity_on_ticket($context = 'reg_limit', $DTT_ID = 0) |
|
| 1187 | - { |
|
| 1188 | - $raw = $this->get_raw('TKT_qty'); |
|
| 1189 | - // return immediately if it's zero |
|
| 1190 | - if ($raw === 0) { |
|
| 1191 | - return $raw; |
|
| 1192 | - } |
|
| 1193 | - // echo "\n\n<br />Ticket: " . $this->name() . '<br />'; |
|
| 1194 | - // ensure qty doesn't exceed raw value for THIS ticket |
|
| 1195 | - $qty = min(EE_INF, $raw); |
|
| 1196 | - // echo "\n . qty: " . $qty . '<br />'; |
|
| 1197 | - // calculate this ticket's total sales and reservations |
|
| 1198 | - $sold_and_reserved_for_this_ticket = $this->sold() + $this->reserved(); |
|
| 1199 | - // echo "\n . sold: " . $this->sold() . '<br />'; |
|
| 1200 | - // echo "\n . reserved: " . $this->reserved() . '<br />'; |
|
| 1201 | - // echo "\n . sold_and_reserved_for_this_ticket: " . $sold_and_reserved_for_this_ticket . '<br />'; |
|
| 1202 | - // first we need to calculate the maximum number of tickets available for the datetime |
|
| 1203 | - // do we want data for one datetime or all of them ? |
|
| 1204 | - $query_params = $DTT_ID ? [['DTT_ID' => $DTT_ID]] : []; |
|
| 1205 | - $datetimes = $this->datetimes($query_params); |
|
| 1206 | - if (is_array($datetimes) && ! empty($datetimes)) { |
|
| 1207 | - foreach ($datetimes as $datetime) { |
|
| 1208 | - if ($datetime instanceof EE_Datetime) { |
|
| 1209 | - $datetime->refresh_from_db(); |
|
| 1210 | - // echo "\n . . datetime name: " . $datetime->name() . '<br />'; |
|
| 1211 | - // echo "\n . . datetime ID: " . $datetime->ID() . '<br />'; |
|
| 1212 | - // initialize with no restrictions for each datetime |
|
| 1213 | - // but adjust datetime qty based on datetime reg limit |
|
| 1214 | - $datetime_qty = min(EE_INF, $datetime->reg_limit()); |
|
| 1215 | - // echo "\n . . . datetime reg_limit: " . $datetime->reg_limit() . '<br />'; |
|
| 1216 | - // echo "\n . . . datetime_qty: " . $datetime_qty . '<br />'; |
|
| 1217 | - // if we want the actual saleable amount, then we need to consider OTHER ticket sales |
|
| 1218 | - // and reservations for this datetime, that do NOT include sales and reservations |
|
| 1219 | - // for this ticket (so we add $this->sold() and $this->reserved() back in) |
|
| 1220 | - if ($context === 'saleable') { |
|
| 1221 | - $datetime_qty = max( |
|
| 1222 | - $datetime_qty - $datetime->sold_and_reserved() + $sold_and_reserved_for_this_ticket, |
|
| 1223 | - 0 |
|
| 1224 | - ); |
|
| 1225 | - // echo "\n . . . datetime sold: " . $datetime->sold() . '<br />'; |
|
| 1226 | - // echo "\n . . . datetime reserved: " . $datetime->reserved() . '<br />'; |
|
| 1227 | - // echo "\n . . . datetime sold_and_reserved: " . $datetime->sold_and_reserved() . '<br />'; |
|
| 1228 | - // echo "\n . . . datetime_qty: " . $datetime_qty . '<br />'; |
|
| 1229 | - $datetime_qty = ! $datetime->sold_out() ? $datetime_qty : 0; |
|
| 1230 | - // echo "\n . . . datetime_qty: " . $datetime_qty . '<br />'; |
|
| 1231 | - } |
|
| 1232 | - $qty = min($datetime_qty, $qty); |
|
| 1233 | - // echo "\n . . qty: " . $qty . '<br />'; |
|
| 1234 | - } |
|
| 1235 | - } |
|
| 1236 | - } |
|
| 1237 | - // NOW that we know the maximum number of tickets available for the datetime |
|
| 1238 | - // we can finally factor in the details for this specific ticket |
|
| 1239 | - if ($qty > 0 && $context === 'saleable') { |
|
| 1240 | - // and subtract the sales for THIS ticket |
|
| 1241 | - $qty = max($qty - $sold_and_reserved_for_this_ticket, 0); |
|
| 1242 | - // echo "\n . qty: " . $qty . '<br />'; |
|
| 1243 | - } |
|
| 1244 | - // echo "\nFINAL QTY: " . $qty . "<br /><br />"; |
|
| 1245 | - return $qty; |
|
| 1246 | - } |
|
| 1247 | - |
|
| 1248 | - |
|
| 1249 | - /** |
|
| 1250 | - * Sets qty - IMPORTANT!!! Does NOT allow QTY to be set higher than the lowest reg limit of any related datetimes |
|
| 1251 | - * |
|
| 1252 | - * @param int $qty |
|
| 1253 | - * @return void |
|
| 1254 | - * @throws EE_Error |
|
| 1255 | - * @throws ReflectionException |
|
| 1256 | - */ |
|
| 1257 | - public function set_qty($qty) |
|
| 1258 | - { |
|
| 1259 | - $datetimes = $this->datetimes(); |
|
| 1260 | - foreach ($datetimes as $datetime) { |
|
| 1261 | - if ($datetime instanceof EE_Datetime) { |
|
| 1262 | - $qty = min($qty, $datetime->reg_limit()); |
|
| 1263 | - } |
|
| 1264 | - } |
|
| 1265 | - $this->set('TKT_qty', $qty); |
|
| 1266 | - } |
|
| 1267 | - |
|
| 1268 | - |
|
| 1269 | - /** |
|
| 1270 | - * Gets uses |
|
| 1271 | - * |
|
| 1272 | - * @return int |
|
| 1273 | - * @throws EE_Error |
|
| 1274 | - * @throws ReflectionException |
|
| 1275 | - */ |
|
| 1276 | - public function uses() |
|
| 1277 | - { |
|
| 1278 | - return $this->get('TKT_uses'); |
|
| 1279 | - } |
|
| 1280 | - |
|
| 1281 | - |
|
| 1282 | - /** |
|
| 1283 | - * Sets uses |
|
| 1284 | - * |
|
| 1285 | - * @param int $uses |
|
| 1286 | - * @return void |
|
| 1287 | - * @throws EE_Error |
|
| 1288 | - * @throws ReflectionException |
|
| 1289 | - */ |
|
| 1290 | - public function set_uses($uses) |
|
| 1291 | - { |
|
| 1292 | - $this->set('TKT_uses', $uses); |
|
| 1293 | - } |
|
| 1294 | - |
|
| 1295 | - |
|
| 1296 | - /** |
|
| 1297 | - * returns whether ticket is required or not. |
|
| 1298 | - * |
|
| 1299 | - * @return boolean |
|
| 1300 | - * @throws EE_Error |
|
| 1301 | - * @throws ReflectionException |
|
| 1302 | - */ |
|
| 1303 | - public function required() |
|
| 1304 | - { |
|
| 1305 | - return $this->get('TKT_required'); |
|
| 1306 | - } |
|
| 1307 | - |
|
| 1308 | - |
|
| 1309 | - /** |
|
| 1310 | - * sets the TKT_required property |
|
| 1311 | - * |
|
| 1312 | - * @param boolean $required |
|
| 1313 | - * @return void |
|
| 1314 | - * @throws EE_Error |
|
| 1315 | - * @throws ReflectionException |
|
| 1316 | - */ |
|
| 1317 | - public function set_required($required) |
|
| 1318 | - { |
|
| 1319 | - $this->set('TKT_required', $required); |
|
| 1320 | - } |
|
| 1321 | - |
|
| 1322 | - |
|
| 1323 | - /** |
|
| 1324 | - * Gets taxable |
|
| 1325 | - * |
|
| 1326 | - * @return boolean |
|
| 1327 | - * @throws EE_Error |
|
| 1328 | - * @throws ReflectionException |
|
| 1329 | - */ |
|
| 1330 | - public function taxable() |
|
| 1331 | - { |
|
| 1332 | - return $this->get('TKT_taxable'); |
|
| 1333 | - } |
|
| 1334 | - |
|
| 1335 | - |
|
| 1336 | - /** |
|
| 1337 | - * Sets taxable |
|
| 1338 | - * |
|
| 1339 | - * @param boolean $taxable |
|
| 1340 | - * @return void |
|
| 1341 | - * @throws EE_Error |
|
| 1342 | - * @throws ReflectionException |
|
| 1343 | - */ |
|
| 1344 | - public function set_taxable($taxable) |
|
| 1345 | - { |
|
| 1346 | - $this->set('TKT_taxable', $taxable); |
|
| 1347 | - } |
|
| 1348 | - |
|
| 1349 | - |
|
| 1350 | - /** |
|
| 1351 | - * Gets is_default |
|
| 1352 | - * |
|
| 1353 | - * @return boolean |
|
| 1354 | - * @throws EE_Error |
|
| 1355 | - * @throws ReflectionException |
|
| 1356 | - */ |
|
| 1357 | - public function is_default() |
|
| 1358 | - { |
|
| 1359 | - return $this->get('TKT_is_default'); |
|
| 1360 | - } |
|
| 1361 | - |
|
| 1362 | - |
|
| 1363 | - /** |
|
| 1364 | - * Sets is_default |
|
| 1365 | - * |
|
| 1366 | - * @param boolean $is_default |
|
| 1367 | - * @return void |
|
| 1368 | - * @throws EE_Error |
|
| 1369 | - * @throws ReflectionException |
|
| 1370 | - */ |
|
| 1371 | - public function set_is_default($is_default) |
|
| 1372 | - { |
|
| 1373 | - $this->set('TKT_is_default', $is_default); |
|
| 1374 | - } |
|
| 1375 | - |
|
| 1376 | - |
|
| 1377 | - /** |
|
| 1378 | - * Gets order |
|
| 1379 | - * |
|
| 1380 | - * @return int |
|
| 1381 | - * @throws EE_Error |
|
| 1382 | - * @throws ReflectionException |
|
| 1383 | - */ |
|
| 1384 | - public function order() |
|
| 1385 | - { |
|
| 1386 | - return $this->get('TKT_order'); |
|
| 1387 | - } |
|
| 1388 | - |
|
| 1389 | - |
|
| 1390 | - /** |
|
| 1391 | - * Sets order |
|
| 1392 | - * |
|
| 1393 | - * @param int $order |
|
| 1394 | - * @return void |
|
| 1395 | - * @throws EE_Error |
|
| 1396 | - * @throws ReflectionException |
|
| 1397 | - */ |
|
| 1398 | - public function set_order($order) |
|
| 1399 | - { |
|
| 1400 | - $this->set('TKT_order', $order); |
|
| 1401 | - } |
|
| 1402 | - |
|
| 1403 | - |
|
| 1404 | - /** |
|
| 1405 | - * Gets row |
|
| 1406 | - * |
|
| 1407 | - * @return int |
|
| 1408 | - * @throws EE_Error |
|
| 1409 | - * @throws ReflectionException |
|
| 1410 | - */ |
|
| 1411 | - public function row() |
|
| 1412 | - { |
|
| 1413 | - return $this->get('TKT_row'); |
|
| 1414 | - } |
|
| 1415 | - |
|
| 1416 | - |
|
| 1417 | - /** |
|
| 1418 | - * Sets row |
|
| 1419 | - * |
|
| 1420 | - * @param int $row |
|
| 1421 | - * @return void |
|
| 1422 | - * @throws EE_Error |
|
| 1423 | - * @throws ReflectionException |
|
| 1424 | - */ |
|
| 1425 | - public function set_row($row) |
|
| 1426 | - { |
|
| 1427 | - $this->set('TKT_row', $row); |
|
| 1428 | - } |
|
| 1429 | - |
|
| 1430 | - |
|
| 1431 | - /** |
|
| 1432 | - * Gets deleted |
|
| 1433 | - * |
|
| 1434 | - * @return boolean |
|
| 1435 | - * @throws EE_Error |
|
| 1436 | - * @throws ReflectionException |
|
| 1437 | - */ |
|
| 1438 | - public function deleted() |
|
| 1439 | - { |
|
| 1440 | - return $this->get('TKT_deleted'); |
|
| 1441 | - } |
|
| 1442 | - |
|
| 1443 | - |
|
| 1444 | - /** |
|
| 1445 | - * Sets deleted |
|
| 1446 | - * |
|
| 1447 | - * @param boolean $deleted |
|
| 1448 | - * @return void |
|
| 1449 | - * @throws EE_Error |
|
| 1450 | - * @throws ReflectionException |
|
| 1451 | - */ |
|
| 1452 | - public function set_deleted($deleted) |
|
| 1453 | - { |
|
| 1454 | - $this->set('TKT_deleted', $deleted); |
|
| 1455 | - } |
|
| 1456 | - |
|
| 1457 | - |
|
| 1458 | - /** |
|
| 1459 | - * Gets parent |
|
| 1460 | - * |
|
| 1461 | - * @return int |
|
| 1462 | - * @throws EE_Error |
|
| 1463 | - * @throws ReflectionException |
|
| 1464 | - */ |
|
| 1465 | - public function parent_ID() |
|
| 1466 | - { |
|
| 1467 | - return $this->get('TKT_parent'); |
|
| 1468 | - } |
|
| 1469 | - |
|
| 1470 | - |
|
| 1471 | - /** |
|
| 1472 | - * Sets parent |
|
| 1473 | - * |
|
| 1474 | - * @param int $parent |
|
| 1475 | - * @return void |
|
| 1476 | - * @throws EE_Error |
|
| 1477 | - * @throws ReflectionException |
|
| 1478 | - */ |
|
| 1479 | - public function set_parent_ID($parent) |
|
| 1480 | - { |
|
| 1481 | - $this->set('TKT_parent', $parent); |
|
| 1482 | - } |
|
| 1483 | - |
|
| 1484 | - |
|
| 1485 | - /** |
|
| 1486 | - * @return boolean |
|
| 1487 | - * @throws EE_Error |
|
| 1488 | - * @throws InvalidArgumentException |
|
| 1489 | - * @throws InvalidDataTypeException |
|
| 1490 | - * @throws InvalidInterfaceException |
|
| 1491 | - * @throws ReflectionException |
|
| 1492 | - */ |
|
| 1493 | - public function reverse_calculate() |
|
| 1494 | - { |
|
| 1495 | - return $this->get('TKT_reverse_calculate'); |
|
| 1496 | - } |
|
| 1497 | - |
|
| 1498 | - |
|
| 1499 | - /** |
|
| 1500 | - * @param boolean $reverse_calculate |
|
| 1501 | - * @throws EE_Error |
|
| 1502 | - * @throws InvalidArgumentException |
|
| 1503 | - * @throws InvalidDataTypeException |
|
| 1504 | - * @throws InvalidInterfaceException |
|
| 1505 | - * @throws ReflectionException |
|
| 1506 | - */ |
|
| 1507 | - public function set_reverse_calculate($reverse_calculate) |
|
| 1508 | - { |
|
| 1509 | - $this->set('TKT_reverse_calculate', $reverse_calculate); |
|
| 1510 | - } |
|
| 1511 | - |
|
| 1512 | - |
|
| 1513 | - /** |
|
| 1514 | - * Gets a string which is handy for showing in gateways etc that describes the ticket. |
|
| 1515 | - * |
|
| 1516 | - * @return string |
|
| 1517 | - * @throws EE_Error |
|
| 1518 | - * @throws ReflectionException |
|
| 1519 | - */ |
|
| 1520 | - public function name_and_info() |
|
| 1521 | - { |
|
| 1522 | - $times = []; |
|
| 1523 | - foreach ($this->datetimes() as $datetime) { |
|
| 1524 | - $times[] = $datetime->start_date_and_time(); |
|
| 1525 | - } |
|
| 1526 | - return $this->name() . ' @ ' . implode(', ', $times) . ' for ' . $this->pretty_price(); |
|
| 1527 | - } |
|
| 1528 | - |
|
| 1529 | - |
|
| 1530 | - /** |
|
| 1531 | - * Gets name |
|
| 1532 | - * |
|
| 1533 | - * @return string |
|
| 1534 | - * @throws EE_Error |
|
| 1535 | - * @throws ReflectionException |
|
| 1536 | - */ |
|
| 1537 | - public function name() |
|
| 1538 | - { |
|
| 1539 | - return $this->get('TKT_name'); |
|
| 1540 | - } |
|
| 1541 | - |
|
| 1542 | - |
|
| 1543 | - /** |
|
| 1544 | - * Gets price |
|
| 1545 | - * |
|
| 1546 | - * @return float |
|
| 1547 | - * @throws EE_Error |
|
| 1548 | - * @throws ReflectionException |
|
| 1549 | - */ |
|
| 1550 | - public function price() |
|
| 1551 | - { |
|
| 1552 | - return $this->get('TKT_price'); |
|
| 1553 | - } |
|
| 1554 | - |
|
| 1555 | - |
|
| 1556 | - /** |
|
| 1557 | - * Gets all the registrations for this ticket |
|
| 1558 | - * |
|
| 1559 | - * @param array $query_params @see |
|
| 1560 | - * https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md |
|
| 1561 | - * @return EE_Registration[]|EE_Base_Class[] |
|
| 1562 | - * @throws EE_Error |
|
| 1563 | - * @throws ReflectionException |
|
| 1564 | - */ |
|
| 1565 | - public function registrations($query_params = []) |
|
| 1566 | - { |
|
| 1567 | - return $this->get_many_related('Registration', $query_params); |
|
| 1568 | - } |
|
| 1569 | - |
|
| 1570 | - |
|
| 1571 | - /** |
|
| 1572 | - * Updates the TKT_sold attribute (and saves) based on the number of APPROVED registrations for this ticket. |
|
| 1573 | - * |
|
| 1574 | - * @return int |
|
| 1575 | - * @throws EE_Error |
|
| 1576 | - * @throws ReflectionException |
|
| 1577 | - */ |
|
| 1578 | - public function update_tickets_sold() |
|
| 1579 | - { |
|
| 1580 | - $count_regs_for_this_ticket = $this->count_registrations( |
|
| 1581 | - [ |
|
| 1582 | - [ |
|
| 1583 | - 'STS_ID' => EEM_Registration::status_id_approved, |
|
| 1584 | - 'REG_deleted' => 0, |
|
| 1585 | - ], |
|
| 1586 | - ] |
|
| 1587 | - ); |
|
| 1588 | - $this->set_sold($count_regs_for_this_ticket); |
|
| 1589 | - $this->save(); |
|
| 1590 | - return $count_regs_for_this_ticket; |
|
| 1591 | - } |
|
| 1592 | - |
|
| 1593 | - |
|
| 1594 | - /** |
|
| 1595 | - * Counts the registrations for this ticket |
|
| 1596 | - * |
|
| 1597 | - * @param array $query_params @see |
|
| 1598 | - * https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md |
|
| 1599 | - * @return int |
|
| 1600 | - * @throws EE_Error |
|
| 1601 | - * @throws ReflectionException |
|
| 1602 | - */ |
|
| 1603 | - public function count_registrations($query_params = []) |
|
| 1604 | - { |
|
| 1605 | - return $this->count_related('Registration', $query_params); |
|
| 1606 | - } |
|
| 1607 | - |
|
| 1608 | - |
|
| 1609 | - /** |
|
| 1610 | - * Implementation for EEI_Has_Icon interface method. |
|
| 1611 | - * |
|
| 1612 | - * @return string |
|
| 1613 | - * @see EEI_Visual_Representation for comments |
|
| 1614 | - */ |
|
| 1615 | - public function get_icon() |
|
| 1616 | - { |
|
| 1617 | - return '<span class="dashicons dashicons-tickets-alt"/>'; |
|
| 1618 | - } |
|
| 1619 | - |
|
| 1620 | - |
|
| 1621 | - /** |
|
| 1622 | - * Implementation of the EEI_Event_Relation interface method |
|
| 1623 | - * |
|
| 1624 | - * @return EE_Event |
|
| 1625 | - * @throws EE_Error |
|
| 1626 | - * @throws UnexpectedEntityException |
|
| 1627 | - * @throws ReflectionException |
|
| 1628 | - * @see EEI_Event_Relation for comments |
|
| 1629 | - */ |
|
| 1630 | - public function get_related_event() |
|
| 1631 | - { |
|
| 1632 | - // get one datetime to use for getting the event |
|
| 1633 | - $datetime = $this->first_datetime(); |
|
| 1634 | - if (! $datetime instanceof EE_Datetime) { |
|
| 1635 | - throw new UnexpectedEntityException( |
|
| 1636 | - $datetime, |
|
| 1637 | - 'EE_Datetime', |
|
| 1638 | - sprintf( |
|
| 1639 | - __('The ticket (%s) is not associated with any valid datetimes.', 'event_espresso'), |
|
| 1640 | - $this->name() |
|
| 1641 | - ) |
|
| 1642 | - ); |
|
| 1643 | - } |
|
| 1644 | - $event = $datetime->event(); |
|
| 1645 | - if (! $event instanceof EE_Event) { |
|
| 1646 | - throw new UnexpectedEntityException( |
|
| 1647 | - $event, |
|
| 1648 | - 'EE_Event', |
|
| 1649 | - sprintf( |
|
| 1650 | - __('The ticket (%s) is not associated with a valid event.', 'event_espresso'), |
|
| 1651 | - $this->name() |
|
| 1652 | - ) |
|
| 1653 | - ); |
|
| 1654 | - } |
|
| 1655 | - return $event; |
|
| 1656 | - } |
|
| 1657 | - |
|
| 1658 | - |
|
| 1659 | - /** |
|
| 1660 | - * Implementation of the EEI_Event_Relation interface method |
|
| 1661 | - * |
|
| 1662 | - * @return string |
|
| 1663 | - * @throws UnexpectedEntityException |
|
| 1664 | - * @throws EE_Error |
|
| 1665 | - * @throws ReflectionException |
|
| 1666 | - * @see EEI_Event_Relation for comments |
|
| 1667 | - */ |
|
| 1668 | - public function get_event_name() |
|
| 1669 | - { |
|
| 1670 | - $event = $this->get_related_event(); |
|
| 1671 | - return $event instanceof EE_Event ? $event->name() : ''; |
|
| 1672 | - } |
|
| 1673 | - |
|
| 1674 | - |
|
| 1675 | - /** |
|
| 1676 | - * Implementation of the EEI_Event_Relation interface method |
|
| 1677 | - * |
|
| 1678 | - * @return int |
|
| 1679 | - * @throws UnexpectedEntityException |
|
| 1680 | - * @throws EE_Error |
|
| 1681 | - * @throws ReflectionException |
|
| 1682 | - * @see EEI_Event_Relation for comments |
|
| 1683 | - */ |
|
| 1684 | - public function get_event_ID() |
|
| 1685 | - { |
|
| 1686 | - $event = $this->get_related_event(); |
|
| 1687 | - return $event instanceof EE_Event ? $event->ID() : 0; |
|
| 1688 | - } |
|
| 1689 | - |
|
| 1690 | - |
|
| 1691 | - /** |
|
| 1692 | - * This simply returns whether a ticket can be permanently deleted or not. |
|
| 1693 | - * The criteria for determining this is whether the ticket has any related registrations. |
|
| 1694 | - * If there are none then it can be permanently deleted. |
|
| 1695 | - * |
|
| 1696 | - * @return bool |
|
| 1697 | - * @throws EE_Error |
|
| 1698 | - * @throws ReflectionException |
|
| 1699 | - */ |
|
| 1700 | - public function is_permanently_deleteable() |
|
| 1701 | - { |
|
| 1702 | - return $this->count_registrations() === 0; |
|
| 1703 | - } |
|
| 1704 | - |
|
| 1705 | - |
|
| 1706 | - /** |
|
| 1707 | - * @return int |
|
| 1708 | - * @throws EE_Error |
|
| 1709 | - * @throws ReflectionException |
|
| 1710 | - * @since $VID:$ |
|
| 1711 | - */ |
|
| 1712 | - public function visibility(): int |
|
| 1713 | - { |
|
| 1714 | - return $this->get('TKT_visibility'); |
|
| 1715 | - } |
|
| 1716 | - |
|
| 1717 | - |
|
| 1718 | - /** |
|
| 1719 | - * @return int |
|
| 1720 | - * @throws EE_Error |
|
| 1721 | - * @throws ReflectionException |
|
| 1722 | - * @since $VID:$ |
|
| 1723 | - */ |
|
| 1724 | - public function isHidden(): int |
|
| 1725 | - { |
|
| 1726 | - return $this->visibility() === EEM_Ticket::TICKET_VISIBILITY_NONE_VALUE; |
|
| 1727 | - } |
|
| 1728 | - |
|
| 1729 | - |
|
| 1730 | - /** |
|
| 1731 | - * @return int |
|
| 1732 | - * @throws EE_Error |
|
| 1733 | - * @throws ReflectionException |
|
| 1734 | - * @since $VID:$ |
|
| 1735 | - */ |
|
| 1736 | - public function isNotHidden(): int |
|
| 1737 | - { |
|
| 1738 | - return $this->visibility() > EEM_Ticket::TICKET_VISIBILITY_NONE_VALUE; |
|
| 1739 | - } |
|
| 1740 | - |
|
| 1741 | - |
|
| 1742 | - /** |
|
| 1743 | - * @return int |
|
| 1744 | - * @throws EE_Error |
|
| 1745 | - * @throws ReflectionException |
|
| 1746 | - * @since $VID:$ |
|
| 1747 | - */ |
|
| 1748 | - public function isPublicOnly(): int |
|
| 1749 | - { |
|
| 1750 | - return $this->isNotHidden() && $this->visibility() <= EEM_Ticket::TICKET_VISIBILITY_PUBLIC_VALUE; |
|
| 1751 | - } |
|
| 1752 | - |
|
| 1753 | - |
|
| 1754 | - /** |
|
| 1755 | - * @return int |
|
| 1756 | - * @throws EE_Error |
|
| 1757 | - * @throws ReflectionException |
|
| 1758 | - * @since $VID:$ |
|
| 1759 | - */ |
|
| 1760 | - public function isMembersOnly(): int |
|
| 1761 | - { |
|
| 1762 | - return $this->visibility() > EEM_Ticket::TICKET_VISIBILITY_PUBLIC_VALUE |
|
| 1763 | - && $this->visibility() <= EEM_Ticket::TICKET_VISIBILITY_MEMBERS_ONLY_VALUE; |
|
| 1764 | - } |
|
| 1765 | - |
|
| 1766 | - |
|
| 1767 | - /** |
|
| 1768 | - * @return int |
|
| 1769 | - * @throws EE_Error |
|
| 1770 | - * @throws ReflectionException |
|
| 1771 | - * @since $VID:$ |
|
| 1772 | - */ |
|
| 1773 | - public function isAdminsOnly(): int |
|
| 1774 | - { |
|
| 1775 | - return $this->visibility() > EEM_Ticket::TICKET_VISIBILITY_MEMBERS_ONLY_VALUE |
|
| 1776 | - && $this->visibility() <= EEM_Ticket::TICKET_VISIBILITY_ADMINS_ONLY_VALUE; |
|
| 1777 | - } |
|
| 1778 | - |
|
| 1779 | - |
|
| 1780 | - /** |
|
| 1781 | - * @return int |
|
| 1782 | - * @throws EE_Error |
|
| 1783 | - * @throws ReflectionException |
|
| 1784 | - * @since $VID:$ |
|
| 1785 | - */ |
|
| 1786 | - public function isAdminUiOnly(): int |
|
| 1787 | - { |
|
| 1788 | - return $this->visibility() > EEM_Ticket::TICKET_VISIBILITY_ADMINS_ONLY_VALUE |
|
| 1789 | - && $this->visibility() <= EEM_Ticket::TICKET_VISIBILITY_ADMIN_UI_ONLY_VALUE; |
|
| 1790 | - } |
|
| 1791 | - |
|
| 1792 | - |
|
| 1793 | - /** |
|
| 1794 | - * @param int $visibility |
|
| 1795 | - * @throws EE_Error |
|
| 1796 | - * @throws ReflectionException |
|
| 1797 | - * @since $VID:$ |
|
| 1798 | - */ |
|
| 1799 | - public function set_visibility(int $visibility) |
|
| 1800 | - { |
|
| 1801 | - |
|
| 1802 | - $ticket_visibility_options = $this->_model->ticketVisibilityOptions(); |
|
| 1803 | - $ticket_visibility = -1; |
|
| 1804 | - foreach ($ticket_visibility_options as $ticket_visibility_option) { |
|
| 1805 | - if ($visibility === $ticket_visibility_option) { |
|
| 1806 | - $ticket_visibility = $visibility; |
|
| 1807 | - } |
|
| 1808 | - } |
|
| 1809 | - if ($ticket_visibility === -1) { |
|
| 1810 | - throw new DomainException( |
|
| 1811 | - sprintf( |
|
| 1812 | - esc_html__( |
|
| 1813 | - 'The supplied ticket visibility setting of "%1$s" is not valid. It needs to match one of the keys in the following array:%2$s %3$s ', |
|
| 1814 | - 'event_espresso' |
|
| 1815 | - ), |
|
| 1816 | - $visibility, |
|
| 1817 | - '<br />', |
|
| 1818 | - var_export($ticket_visibility_options, true) |
|
| 1819 | - ) |
|
| 1820 | - ); |
|
| 1821 | - } |
|
| 1822 | - $this->set('TKT_visibility', $ticket_visibility); |
|
| 1823 | - } |
|
| 1824 | - |
|
| 1825 | - |
|
| 1826 | - /******************************************************************* |
|
| 18 | + /** |
|
| 19 | + * TicKet Sold out: |
|
| 20 | + * constant used by ticket_status() to indicate that a ticket is sold out |
|
| 21 | + * and no longer available for purchases |
|
| 22 | + */ |
|
| 23 | + const sold_out = 'TKS'; |
|
| 24 | + |
|
| 25 | + /** |
|
| 26 | + * TicKet Expired: |
|
| 27 | + * constant used by ticket_status() to indicate that a ticket is expired |
|
| 28 | + * and no longer available for purchase |
|
| 29 | + */ |
|
| 30 | + const expired = 'TKE'; |
|
| 31 | + |
|
| 32 | + /** |
|
| 33 | + * TicKet Archived: |
|
| 34 | + * constant used by ticket_status() to indicate that a ticket is archived |
|
| 35 | + * and no longer available for purchase |
|
| 36 | + */ |
|
| 37 | + const archived = 'TKA'; |
|
| 38 | + |
|
| 39 | + /** |
|
| 40 | + * TicKet Pending: |
|
| 41 | + * constant used by ticket_status() to indicate that a ticket is pending |
|
| 42 | + * and is NOT YET available for purchase |
|
| 43 | + */ |
|
| 44 | + const pending = 'TKP'; |
|
| 45 | + |
|
| 46 | + /** |
|
| 47 | + * TicKet On sale: |
|
| 48 | + * constant used by ticket_status() to indicate that a ticket is On Sale |
|
| 49 | + * and IS available for purchase |
|
| 50 | + */ |
|
| 51 | + const onsale = 'TKO'; |
|
| 52 | + |
|
| 53 | + /** |
|
| 54 | + * extra meta key for tracking ticket reservations |
|
| 55 | + * |
|
| 56 | + * @type string |
|
| 57 | + */ |
|
| 58 | + const META_KEY_TICKET_RESERVATIONS = 'ticket_reservations'; |
|
| 59 | + |
|
| 60 | + /** |
|
| 61 | + * override of parent property |
|
| 62 | + * |
|
| 63 | + * @var EEM_Ticket |
|
| 64 | + */ |
|
| 65 | + protected $_model; |
|
| 66 | + |
|
| 67 | + /** |
|
| 68 | + * cached result from method of the same name |
|
| 69 | + * |
|
| 70 | + * @var float $_ticket_total_with_taxes |
|
| 71 | + */ |
|
| 72 | + private $_ticket_total_with_taxes; |
|
| 73 | + |
|
| 74 | + |
|
| 75 | + /** |
|
| 76 | + * @param array $props_n_values incoming values |
|
| 77 | + * @param string $timezone incoming timezone (if not set the timezone set for the website will be |
|
| 78 | + * used.) |
|
| 79 | + * @param array $date_formats incoming date_formats in an array where the first value is the |
|
| 80 | + * date_format and the second value is the time format |
|
| 81 | + * @return EE_Ticket |
|
| 82 | + * @throws EE_Error |
|
| 83 | + * @throws ReflectionException |
|
| 84 | + */ |
|
| 85 | + public static function new_instance($props_n_values = [], $timezone = null, $date_formats = []) |
|
| 86 | + { |
|
| 87 | + $has_object = parent::_check_for_object($props_n_values, __CLASS__, $timezone, $date_formats); |
|
| 88 | + return $has_object ? $has_object : new self($props_n_values, false, $timezone, $date_formats); |
|
| 89 | + } |
|
| 90 | + |
|
| 91 | + |
|
| 92 | + /** |
|
| 93 | + * @param array $props_n_values incoming values from the database |
|
| 94 | + * @param string $timezone incoming timezone as set by the model. If not set the timezone for |
|
| 95 | + * the website will be used. |
|
| 96 | + * @return EE_Ticket |
|
| 97 | + * @throws EE_Error |
|
| 98 | + * @throws ReflectionException |
|
| 99 | + */ |
|
| 100 | + public static function new_instance_from_db($props_n_values = [], $timezone = null) |
|
| 101 | + { |
|
| 102 | + return new self($props_n_values, true, $timezone); |
|
| 103 | + } |
|
| 104 | + |
|
| 105 | + |
|
| 106 | + /** |
|
| 107 | + * @return bool |
|
| 108 | + * @throws EE_Error |
|
| 109 | + * @throws ReflectionException |
|
| 110 | + */ |
|
| 111 | + public function parent() |
|
| 112 | + { |
|
| 113 | + return $this->get('TKT_parent'); |
|
| 114 | + } |
|
| 115 | + |
|
| 116 | + |
|
| 117 | + /** |
|
| 118 | + * return if a ticket has quantities available for purchase |
|
| 119 | + * |
|
| 120 | + * @param int $DTT_ID the primary key for a particular datetime |
|
| 121 | + * @return boolean |
|
| 122 | + * @throws EE_Error |
|
| 123 | + * @throws ReflectionException |
|
| 124 | + */ |
|
| 125 | + public function available($DTT_ID = 0) |
|
| 126 | + { |
|
| 127 | + // are we checking availability for a particular datetime ? |
|
| 128 | + if ($DTT_ID) { |
|
| 129 | + // get that datetime object |
|
| 130 | + $datetime = $this->get_first_related('Datetime', [['DTT_ID' => $DTT_ID]]); |
|
| 131 | + // if ticket sales for this datetime have exceeded the reg limit... |
|
| 132 | + if ($datetime instanceof EE_Datetime && $datetime->sold_out()) { |
|
| 133 | + return false; |
|
| 134 | + } |
|
| 135 | + } |
|
| 136 | + // datetime is still open for registration, but is this ticket sold out ? |
|
| 137 | + return $this->qty() < 1 || $this->qty() > $this->sold(); |
|
| 138 | + } |
|
| 139 | + |
|
| 140 | + |
|
| 141 | + /** |
|
| 142 | + * Using the start date and end date this method calculates whether the ticket is On Sale, Pending, or Expired |
|
| 143 | + * |
|
| 144 | + * @param bool $display true = we'll return a localized string, otherwise we just return the value of the |
|
| 145 | + * relevant status const |
|
| 146 | + * @param bool | null $remaining if it is already known that tickets are available, then simply pass a bool to save |
|
| 147 | + * further processing |
|
| 148 | + * @return mixed status int if the display string isn't requested |
|
| 149 | + * @throws EE_Error |
|
| 150 | + * @throws ReflectionException |
|
| 151 | + */ |
|
| 152 | + public function ticket_status($display = false, $remaining = null) |
|
| 153 | + { |
|
| 154 | + $remaining = is_bool($remaining) ? $remaining : $this->is_remaining(); |
|
| 155 | + if (! $remaining) { |
|
| 156 | + return $display ? EEH_Template::pretty_status(EE_Ticket::sold_out, false, 'sentence') : EE_Ticket::sold_out; |
|
| 157 | + } |
|
| 158 | + if ($this->get('TKT_deleted')) { |
|
| 159 | + return $display ? EEH_Template::pretty_status(EE_Ticket::archived, false, 'sentence') : EE_Ticket::archived; |
|
| 160 | + } |
|
| 161 | + if ($this->is_expired()) { |
|
| 162 | + return $display ? EEH_Template::pretty_status(EE_Ticket::expired, false, 'sentence') : EE_Ticket::expired; |
|
| 163 | + } |
|
| 164 | + if ($this->is_pending()) { |
|
| 165 | + return $display ? EEH_Template::pretty_status(EE_Ticket::pending, false, 'sentence') : EE_Ticket::pending; |
|
| 166 | + } |
|
| 167 | + if ($this->is_on_sale()) { |
|
| 168 | + return $display ? EEH_Template::pretty_status(EE_Ticket::onsale, false, 'sentence') : EE_Ticket::onsale; |
|
| 169 | + } |
|
| 170 | + return ''; |
|
| 171 | + } |
|
| 172 | + |
|
| 173 | + |
|
| 174 | + /** |
|
| 175 | + * The purpose of this method is to simply return a boolean for whether there are any tickets remaining for sale |
|
| 176 | + * considering ALL the factors used for figuring that out. |
|
| 177 | + * |
|
| 178 | + * @access public |
|
| 179 | + * @param int $DTT_ID if an int above 0 is included here then we get a specific dtt. |
|
| 180 | + * @return boolean true = tickets remaining, false not. |
|
| 181 | + * @throws EE_Error |
|
| 182 | + * @throws ReflectionException |
|
| 183 | + */ |
|
| 184 | + public function is_remaining($DTT_ID = 0) |
|
| 185 | + { |
|
| 186 | + $num_remaining = $this->remaining($DTT_ID); |
|
| 187 | + if ($num_remaining === 0) { |
|
| 188 | + return false; |
|
| 189 | + } |
|
| 190 | + if ($num_remaining > 0 && $num_remaining < $this->min()) { |
|
| 191 | + return false; |
|
| 192 | + } |
|
| 193 | + return true; |
|
| 194 | + } |
|
| 195 | + |
|
| 196 | + |
|
| 197 | + /** |
|
| 198 | + * return the total number of tickets available for purchase |
|
| 199 | + * |
|
| 200 | + * @param int $DTT_ID the primary key for a particular datetime. |
|
| 201 | + * set to 0 for all related datetimes |
|
| 202 | + * @return int |
|
| 203 | + * @throws EE_Error |
|
| 204 | + * @throws ReflectionException |
|
| 205 | + */ |
|
| 206 | + public function remaining($DTT_ID = 0) |
|
| 207 | + { |
|
| 208 | + return $this->real_quantity_on_ticket('saleable', $DTT_ID); |
|
| 209 | + } |
|
| 210 | + |
|
| 211 | + |
|
| 212 | + /** |
|
| 213 | + * Gets min |
|
| 214 | + * |
|
| 215 | + * @return int |
|
| 216 | + * @throws EE_Error |
|
| 217 | + * @throws ReflectionException |
|
| 218 | + */ |
|
| 219 | + public function min() |
|
| 220 | + { |
|
| 221 | + return $this->get('TKT_min'); |
|
| 222 | + } |
|
| 223 | + |
|
| 224 | + |
|
| 225 | + /** |
|
| 226 | + * return if a ticket is no longer available cause its available dates have expired. |
|
| 227 | + * |
|
| 228 | + * @return boolean |
|
| 229 | + * @throws EE_Error |
|
| 230 | + * @throws ReflectionException |
|
| 231 | + */ |
|
| 232 | + public function is_expired() |
|
| 233 | + { |
|
| 234 | + return ($this->get_raw('TKT_end_date') < time()); |
|
| 235 | + } |
|
| 236 | + |
|
| 237 | + |
|
| 238 | + /** |
|
| 239 | + * Return if a ticket is yet to go on sale or not |
|
| 240 | + * |
|
| 241 | + * @return boolean |
|
| 242 | + * @throws EE_Error |
|
| 243 | + * @throws ReflectionException |
|
| 244 | + */ |
|
| 245 | + public function is_pending() |
|
| 246 | + { |
|
| 247 | + return ($this->get_raw('TKT_start_date') >= time()); |
|
| 248 | + } |
|
| 249 | + |
|
| 250 | + |
|
| 251 | + /** |
|
| 252 | + * Return if a ticket is on sale or not |
|
| 253 | + * |
|
| 254 | + * @return boolean |
|
| 255 | + * @throws EE_Error |
|
| 256 | + * @throws ReflectionException |
|
| 257 | + */ |
|
| 258 | + public function is_on_sale() |
|
| 259 | + { |
|
| 260 | + return ($this->get_raw('TKT_start_date') <= time() && $this->get_raw('TKT_end_date') >= time()); |
|
| 261 | + } |
|
| 262 | + |
|
| 263 | + |
|
| 264 | + /** |
|
| 265 | + * This returns the chronologically last datetime that this ticket is associated with |
|
| 266 | + * |
|
| 267 | + * @param string $date_format |
|
| 268 | + * @param string $conjunction - conjunction junction what's your function ? this string joins the start date with |
|
| 269 | + * the end date ie: Jan 01 "to" Dec 31 |
|
| 270 | + * @return string |
|
| 271 | + * @throws EE_Error |
|
| 272 | + * @throws ReflectionException |
|
| 273 | + */ |
|
| 274 | + public function date_range($date_format = '', $conjunction = ' - ') |
|
| 275 | + { |
|
| 276 | + $date_format = ! empty($date_format) ? $date_format : $this->_dt_frmt; |
|
| 277 | + $first_date = $this->first_datetime() instanceof EE_Datetime |
|
| 278 | + ? $this->first_datetime()->get_i18n_datetime('DTT_EVT_start', $date_format) |
|
| 279 | + : ''; |
|
| 280 | + $last_date = $this->last_datetime() instanceof EE_Datetime |
|
| 281 | + ? $this->last_datetime()->get_i18n_datetime('DTT_EVT_end', $date_format) |
|
| 282 | + : ''; |
|
| 283 | + |
|
| 284 | + return $first_date && $last_date ? $first_date . $conjunction . $last_date : ''; |
|
| 285 | + } |
|
| 286 | + |
|
| 287 | + |
|
| 288 | + /** |
|
| 289 | + * This returns the chronologically first datetime that this ticket is associated with |
|
| 290 | + * |
|
| 291 | + * @return EE_Datetime |
|
| 292 | + * @throws EE_Error |
|
| 293 | + * @throws ReflectionException |
|
| 294 | + */ |
|
| 295 | + public function first_datetime() |
|
| 296 | + { |
|
| 297 | + $datetimes = $this->datetimes(['limit' => 1]); |
|
| 298 | + return reset($datetimes); |
|
| 299 | + } |
|
| 300 | + |
|
| 301 | + |
|
| 302 | + /** |
|
| 303 | + * Gets all the datetimes this ticket can be used for attending. |
|
| 304 | + * Unless otherwise specified, orders datetimes by start date. |
|
| 305 | + * |
|
| 306 | + * @param array $query_params @see |
|
| 307 | + * https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md |
|
| 308 | + * @return EE_Datetime[]|EE_Base_Class[] |
|
| 309 | + * @throws EE_Error |
|
| 310 | + * @throws ReflectionException |
|
| 311 | + */ |
|
| 312 | + public function datetimes($query_params = []) |
|
| 313 | + { |
|
| 314 | + if (! isset($query_params['order_by'])) { |
|
| 315 | + $query_params['order_by']['DTT_order'] = 'ASC'; |
|
| 316 | + } |
|
| 317 | + return $this->get_many_related('Datetime', $query_params); |
|
| 318 | + } |
|
| 319 | + |
|
| 320 | + |
|
| 321 | + /** |
|
| 322 | + * This returns the chronologically last datetime that this ticket is associated with |
|
| 323 | + * |
|
| 324 | + * @return EE_Datetime |
|
| 325 | + * @throws EE_Error |
|
| 326 | + * @throws ReflectionException |
|
| 327 | + */ |
|
| 328 | + public function last_datetime() |
|
| 329 | + { |
|
| 330 | + $datetimes = $this->datetimes(['limit' => 1, 'order_by' => ['DTT_EVT_start' => 'DESC']]); |
|
| 331 | + return end($datetimes); |
|
| 332 | + } |
|
| 333 | + |
|
| 334 | + |
|
| 335 | + /** |
|
| 336 | + * This returns the total tickets sold depending on the given parameters. |
|
| 337 | + * |
|
| 338 | + * @param string $what Can be one of two options: 'ticket', 'datetime'. |
|
| 339 | + * 'ticket' = total ticket sales for all datetimes this ticket is related to |
|
| 340 | + * 'datetime' = total ticket sales for a specified datetime (required $dtt_id) |
|
| 341 | + * 'datetime' = total ticket sales in the datetime_ticket table. |
|
| 342 | + * If $dtt_id is not given then we return an array of sales indexed by datetime. |
|
| 343 | + * If $dtt_id IS given then we return the tickets sold for that given datetime. |
|
| 344 | + * @param int $dtt_id [optional] include the dtt_id with $what = 'datetime'. |
|
| 345 | + * @return mixed (array|int) how many tickets have sold |
|
| 346 | + * @throws EE_Error |
|
| 347 | + * @throws ReflectionException |
|
| 348 | + */ |
|
| 349 | + public function tickets_sold($what = 'ticket', $dtt_id = null) |
|
| 350 | + { |
|
| 351 | + $total = 0; |
|
| 352 | + $tickets_sold = $this->_all_tickets_sold(); |
|
| 353 | + switch ($what) { |
|
| 354 | + case 'ticket': |
|
| 355 | + return $tickets_sold['ticket']; |
|
| 356 | + break; |
|
| 357 | + case 'datetime': |
|
| 358 | + if (empty($tickets_sold['datetime'])) { |
|
| 359 | + return $total; |
|
| 360 | + } |
|
| 361 | + if (! empty($dtt_id) && ! isset($tickets_sold['datetime'][ $dtt_id ])) { |
|
| 362 | + EE_Error::add_error( |
|
| 363 | + __( |
|
| 364 | + 'You\'ve requested the amount of tickets sold for a given ticket and datetime, however there are no records for the datetime id you included. Are you SURE that is a datetime related to this ticket?', |
|
| 365 | + 'event_espresso' |
|
| 366 | + ), |
|
| 367 | + __FILE__, |
|
| 368 | + __FUNCTION__, |
|
| 369 | + __LINE__ |
|
| 370 | + ); |
|
| 371 | + return $total; |
|
| 372 | + } |
|
| 373 | + return empty($dtt_id) ? $tickets_sold['datetime'] : $tickets_sold['datetime'][ $dtt_id ]; |
|
| 374 | + break; |
|
| 375 | + default: |
|
| 376 | + return $total; |
|
| 377 | + } |
|
| 378 | + } |
|
| 379 | + |
|
| 380 | + |
|
| 381 | + /** |
|
| 382 | + * This returns an array indexed by datetime_id for tickets sold with this ticket. |
|
| 383 | + * |
|
| 384 | + * @return EE_Ticket[] |
|
| 385 | + * @throws EE_Error |
|
| 386 | + * @throws ReflectionException |
|
| 387 | + */ |
|
| 388 | + protected function _all_tickets_sold() |
|
| 389 | + { |
|
| 390 | + $datetimes = $this->get_many_related('Datetime'); |
|
| 391 | + $tickets_sold = []; |
|
| 392 | + if (! empty($datetimes)) { |
|
| 393 | + foreach ($datetimes as $datetime) { |
|
| 394 | + $tickets_sold['datetime'][ $datetime->ID() ] = $datetime->get('DTT_sold'); |
|
| 395 | + } |
|
| 396 | + } |
|
| 397 | + // Tickets sold |
|
| 398 | + $tickets_sold['ticket'] = $this->sold(); |
|
| 399 | + return $tickets_sold; |
|
| 400 | + } |
|
| 401 | + |
|
| 402 | + |
|
| 403 | + /** |
|
| 404 | + * This returns the base price object for the ticket. |
|
| 405 | + * |
|
| 406 | + * @param bool $return_array whether to return as an array indexed by price id or just the object. |
|
| 407 | + * @return EE_Price|EE_Base_Class|EE_Price[]|EE_Base_Class[] |
|
| 408 | + * @throws EE_Error |
|
| 409 | + * @throws ReflectionException |
|
| 410 | + */ |
|
| 411 | + public function base_price($return_array = false) |
|
| 412 | + { |
|
| 413 | + $_where = ['Price_Type.PBT_ID' => EEM_Price_Type::base_type_base_price]; |
|
| 414 | + return $return_array |
|
| 415 | + ? $this->get_many_related('Price', [$_where]) |
|
| 416 | + : $this->get_first_related('Price', [$_where]); |
|
| 417 | + } |
|
| 418 | + |
|
| 419 | + |
|
| 420 | + /** |
|
| 421 | + * This returns ONLY the price modifiers for the ticket (i.e. no taxes or base price) |
|
| 422 | + * |
|
| 423 | + * @access public |
|
| 424 | + * @return EE_Price[] |
|
| 425 | + * @throws EE_Error |
|
| 426 | + * @throws ReflectionException |
|
| 427 | + */ |
|
| 428 | + public function price_modifiers() |
|
| 429 | + { |
|
| 430 | + $query_params = [ |
|
| 431 | + 0 => [ |
|
| 432 | + 'Price_Type.PBT_ID' => [ |
|
| 433 | + 'NOT IN', |
|
| 434 | + [EEM_Price_Type::base_type_base_price, EEM_Price_Type::base_type_tax], |
|
| 435 | + ], |
|
| 436 | + ], |
|
| 437 | + ]; |
|
| 438 | + return $this->prices($query_params); |
|
| 439 | + } |
|
| 440 | + |
|
| 441 | + |
|
| 442 | + /** |
|
| 443 | + * This returns ONLY the price modifiers for the ticket (i.e. no taxes or base price) |
|
| 444 | + * |
|
| 445 | + * @access public |
|
| 446 | + * @return EE_Price[] |
|
| 447 | + * @throws EE_Error |
|
| 448 | + * @throws ReflectionException |
|
| 449 | + */ |
|
| 450 | + public function tax_price_modifiers() |
|
| 451 | + { |
|
| 452 | + $query_params = [ |
|
| 453 | + 0 => [ |
|
| 454 | + 'Price_Type.PBT_ID' => EEM_Price_Type::base_type_tax, |
|
| 455 | + ], |
|
| 456 | + ]; |
|
| 457 | + return $this->prices($query_params); |
|
| 458 | + } |
|
| 459 | + |
|
| 460 | + |
|
| 461 | + /** |
|
| 462 | + * Gets all the prices that combine to form the final price of this ticket |
|
| 463 | + * |
|
| 464 | + * @param array $query_params @see |
|
| 465 | + * https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md |
|
| 466 | + * @return EE_Price[]|EE_Base_Class[] |
|
| 467 | + * @throws EE_Error |
|
| 468 | + * @throws ReflectionException |
|
| 469 | + */ |
|
| 470 | + public function prices($query_params = []) |
|
| 471 | + { |
|
| 472 | + return $this->get_many_related('Price', $query_params); |
|
| 473 | + } |
|
| 474 | + |
|
| 475 | + |
|
| 476 | + /** |
|
| 477 | + * Gets all the ticket datetimes (ie, relations between datetimes and tickets) |
|
| 478 | + * |
|
| 479 | + * @param array $query_params @see |
|
| 480 | + * https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md |
|
| 481 | + * @return EE_Datetime_Ticket|EE_Base_Class[] |
|
| 482 | + * @throws EE_Error |
|
| 483 | + * @throws ReflectionException |
|
| 484 | + */ |
|
| 485 | + public function datetime_tickets($query_params = []) |
|
| 486 | + { |
|
| 487 | + return $this->get_many_related('Datetime_Ticket', $query_params); |
|
| 488 | + } |
|
| 489 | + |
|
| 490 | + |
|
| 491 | + /** |
|
| 492 | + * Gets all the datetimes from the db ordered by DTT_order |
|
| 493 | + * |
|
| 494 | + * @param boolean $show_expired |
|
| 495 | + * @param boolean $show_deleted |
|
| 496 | + * @return EE_Datetime[] |
|
| 497 | + * @throws EE_Error |
|
| 498 | + * @throws ReflectionException |
|
| 499 | + */ |
|
| 500 | + public function datetimes_ordered($show_expired = true, $show_deleted = false) |
|
| 501 | + { |
|
| 502 | + return EEM_Datetime::instance($this->_timezone)->get_datetimes_for_ticket_ordered_by_DTT_order( |
|
| 503 | + $this->ID(), |
|
| 504 | + $show_expired, |
|
| 505 | + $show_deleted |
|
| 506 | + ); |
|
| 507 | + } |
|
| 508 | + |
|
| 509 | + |
|
| 510 | + /** |
|
| 511 | + * Gets ID |
|
| 512 | + * |
|
| 513 | + * @return int |
|
| 514 | + * @throws EE_Error |
|
| 515 | + * @throws ReflectionException |
|
| 516 | + */ |
|
| 517 | + public function ID() |
|
| 518 | + { |
|
| 519 | + return $this->get('TKT_ID'); |
|
| 520 | + } |
|
| 521 | + |
|
| 522 | + |
|
| 523 | + /** |
|
| 524 | + * get the author of the ticket. |
|
| 525 | + * |
|
| 526 | + * @return int |
|
| 527 | + * @throws EE_Error |
|
| 528 | + * @throws ReflectionException |
|
| 529 | + * @since 4.5.0 |
|
| 530 | + */ |
|
| 531 | + public function wp_user() |
|
| 532 | + { |
|
| 533 | + return $this->get('TKT_wp_user'); |
|
| 534 | + } |
|
| 535 | + |
|
| 536 | + |
|
| 537 | + /** |
|
| 538 | + * Gets the template for the ticket |
|
| 539 | + * |
|
| 540 | + * @return EE_Ticket_Template|EE_Base_Class |
|
| 541 | + * @throws EE_Error |
|
| 542 | + * @throws ReflectionException |
|
| 543 | + */ |
|
| 544 | + public function template() |
|
| 545 | + { |
|
| 546 | + return $this->get_first_related('Ticket_Template'); |
|
| 547 | + } |
|
| 548 | + |
|
| 549 | + |
|
| 550 | + /** |
|
| 551 | + * Simply returns an array of EE_Price objects that are taxes. |
|
| 552 | + * |
|
| 553 | + * @return EE_Price[] |
|
| 554 | + * @throws EE_Error |
|
| 555 | + * @throws ReflectionException |
|
| 556 | + */ |
|
| 557 | + public function get_ticket_taxes_for_admin(): array |
|
| 558 | + { |
|
| 559 | + /** @var EE_Admin_Config $admin_config */ |
|
| 560 | + $admin_config = LoaderFactory::getShared(EE_Admin_Config::class); |
|
| 561 | + return $admin_config->useAdvancedEditor() ? $this->tax_price_modifiers() : EE_Taxes::get_taxes_for_admin(); |
|
| 562 | + } |
|
| 563 | + |
|
| 564 | + |
|
| 565 | + /** |
|
| 566 | + * @return float |
|
| 567 | + * @throws EE_Error |
|
| 568 | + * @throws ReflectionException |
|
| 569 | + */ |
|
| 570 | + public function ticket_price() |
|
| 571 | + { |
|
| 572 | + return $this->get('TKT_price'); |
|
| 573 | + } |
|
| 574 | + |
|
| 575 | + |
|
| 576 | + /** |
|
| 577 | + * @return mixed |
|
| 578 | + * @throws EE_Error |
|
| 579 | + * @throws ReflectionException |
|
| 580 | + */ |
|
| 581 | + public function pretty_price() |
|
| 582 | + { |
|
| 583 | + return $this->get_pretty('TKT_price'); |
|
| 584 | + } |
|
| 585 | + |
|
| 586 | + |
|
| 587 | + /** |
|
| 588 | + * @return bool |
|
| 589 | + * @throws EE_Error |
|
| 590 | + * @throws ReflectionException |
|
| 591 | + */ |
|
| 592 | + public function is_free() |
|
| 593 | + { |
|
| 594 | + return $this->get_ticket_total_with_taxes() === (float) 0; |
|
| 595 | + } |
|
| 596 | + |
|
| 597 | + |
|
| 598 | + /** |
|
| 599 | + * get_ticket_total_with_taxes |
|
| 600 | + * |
|
| 601 | + * @param bool $no_cache |
|
| 602 | + * @return float |
|
| 603 | + * @throws EE_Error |
|
| 604 | + * @throws ReflectionException |
|
| 605 | + */ |
|
| 606 | + public function get_ticket_total_with_taxes($no_cache = false) |
|
| 607 | + { |
|
| 608 | + if ($this->_ticket_total_with_taxes === null || $no_cache) { |
|
| 609 | + /** @var EE_Admin_Config $admin_config */ |
|
| 610 | + $admin_config = LoaderFactory::getShared(EE_Admin_Config::class); |
|
| 611 | + $this->_ticket_total_with_taxes = $admin_config->useAdvancedEditor() |
|
| 612 | + ? $this->ticket_price() |
|
| 613 | + : $this->get_ticket_subtotal() + $this->get_ticket_taxes_total_for_admin(); |
|
| 614 | + } |
|
| 615 | + return (float) $this->_ticket_total_with_taxes; |
|
| 616 | + } |
|
| 617 | + |
|
| 618 | + |
|
| 619 | + /** |
|
| 620 | + * @throws EE_Error |
|
| 621 | + * @throws ReflectionException |
|
| 622 | + */ |
|
| 623 | + public function ensure_TKT_Price_correct() |
|
| 624 | + { |
|
| 625 | + $this->set('TKT_price', EE_Taxes::get_subtotal_for_admin($this)); |
|
| 626 | + $this->save(); |
|
| 627 | + } |
|
| 628 | + |
|
| 629 | + |
|
| 630 | + /** |
|
| 631 | + * @return float |
|
| 632 | + * @throws EE_Error |
|
| 633 | + * @throws ReflectionException |
|
| 634 | + */ |
|
| 635 | + public function get_ticket_subtotal() |
|
| 636 | + { |
|
| 637 | + return EE_Taxes::get_subtotal_for_admin($this); |
|
| 638 | + } |
|
| 639 | + |
|
| 640 | + |
|
| 641 | + /** |
|
| 642 | + * Returns the total taxes applied to this ticket |
|
| 643 | + * |
|
| 644 | + * @return float |
|
| 645 | + * @throws EE_Error |
|
| 646 | + * @throws ReflectionException |
|
| 647 | + */ |
|
| 648 | + public function get_ticket_taxes_total_for_admin() |
|
| 649 | + { |
|
| 650 | + return EE_Taxes::get_total_taxes_for_admin($this); |
|
| 651 | + } |
|
| 652 | + |
|
| 653 | + |
|
| 654 | + /** |
|
| 655 | + * Sets name |
|
| 656 | + * |
|
| 657 | + * @param string $name |
|
| 658 | + * @throws EE_Error |
|
| 659 | + * @throws ReflectionException |
|
| 660 | + */ |
|
| 661 | + public function set_name($name) |
|
| 662 | + { |
|
| 663 | + $this->set('TKT_name', $name); |
|
| 664 | + } |
|
| 665 | + |
|
| 666 | + |
|
| 667 | + /** |
|
| 668 | + * Gets description |
|
| 669 | + * |
|
| 670 | + * @return string |
|
| 671 | + * @throws EE_Error |
|
| 672 | + * @throws ReflectionException |
|
| 673 | + */ |
|
| 674 | + public function description() |
|
| 675 | + { |
|
| 676 | + return $this->get('TKT_description'); |
|
| 677 | + } |
|
| 678 | + |
|
| 679 | + |
|
| 680 | + /** |
|
| 681 | + * Sets description |
|
| 682 | + * |
|
| 683 | + * @param string $description |
|
| 684 | + * @throws EE_Error |
|
| 685 | + * @throws ReflectionException |
|
| 686 | + */ |
|
| 687 | + public function set_description($description) |
|
| 688 | + { |
|
| 689 | + $this->set('TKT_description', $description); |
|
| 690 | + } |
|
| 691 | + |
|
| 692 | + |
|
| 693 | + /** |
|
| 694 | + * Gets start_date |
|
| 695 | + * |
|
| 696 | + * @param string $date_format |
|
| 697 | + * @param string $time_format |
|
| 698 | + * @return string |
|
| 699 | + * @throws EE_Error |
|
| 700 | + * @throws ReflectionException |
|
| 701 | + */ |
|
| 702 | + public function start_date($date_format = '', $time_format = '') |
|
| 703 | + { |
|
| 704 | + return $this->_get_datetime('TKT_start_date', $date_format, $time_format); |
|
| 705 | + } |
|
| 706 | + |
|
| 707 | + |
|
| 708 | + /** |
|
| 709 | + * Sets start_date |
|
| 710 | + * |
|
| 711 | + * @param string $start_date |
|
| 712 | + * @return void |
|
| 713 | + * @throws EE_Error |
|
| 714 | + * @throws ReflectionException |
|
| 715 | + */ |
|
| 716 | + public function set_start_date($start_date) |
|
| 717 | + { |
|
| 718 | + $this->_set_date_time('B', $start_date, 'TKT_start_date'); |
|
| 719 | + } |
|
| 720 | + |
|
| 721 | + |
|
| 722 | + /** |
|
| 723 | + * Gets end_date |
|
| 724 | + * |
|
| 725 | + * @param string $date_format |
|
| 726 | + * @param string $time_format |
|
| 727 | + * @return string |
|
| 728 | + * @throws EE_Error |
|
| 729 | + * @throws ReflectionException |
|
| 730 | + */ |
|
| 731 | + public function end_date($date_format = '', $time_format = '') |
|
| 732 | + { |
|
| 733 | + return $this->_get_datetime('TKT_end_date', $date_format, $time_format); |
|
| 734 | + } |
|
| 735 | + |
|
| 736 | + |
|
| 737 | + /** |
|
| 738 | + * Sets end_date |
|
| 739 | + * |
|
| 740 | + * @param string $end_date |
|
| 741 | + * @return void |
|
| 742 | + * @throws EE_Error |
|
| 743 | + * @throws ReflectionException |
|
| 744 | + */ |
|
| 745 | + public function set_end_date($end_date) |
|
| 746 | + { |
|
| 747 | + $this->_set_date_time('B', $end_date, 'TKT_end_date'); |
|
| 748 | + } |
|
| 749 | + |
|
| 750 | + |
|
| 751 | + /** |
|
| 752 | + * Sets sell until time |
|
| 753 | + * |
|
| 754 | + * @param string $time a string representation of the sell until time (ex 9am or 7:30pm) |
|
| 755 | + * @throws EE_Error |
|
| 756 | + * @throws ReflectionException |
|
| 757 | + * @since 4.5.0 |
|
| 758 | + */ |
|
| 759 | + public function set_end_time($time) |
|
| 760 | + { |
|
| 761 | + $this->_set_time_for($time, 'TKT_end_date'); |
|
| 762 | + } |
|
| 763 | + |
|
| 764 | + |
|
| 765 | + /** |
|
| 766 | + * Sets min |
|
| 767 | + * |
|
| 768 | + * @param int $min |
|
| 769 | + * @return void |
|
| 770 | + * @throws EE_Error |
|
| 771 | + * @throws ReflectionException |
|
| 772 | + */ |
|
| 773 | + public function set_min($min) |
|
| 774 | + { |
|
| 775 | + $this->set('TKT_min', $min); |
|
| 776 | + } |
|
| 777 | + |
|
| 778 | + |
|
| 779 | + /** |
|
| 780 | + * Gets max |
|
| 781 | + * |
|
| 782 | + * @return int |
|
| 783 | + * @throws EE_Error |
|
| 784 | + * @throws ReflectionException |
|
| 785 | + */ |
|
| 786 | + public function max() |
|
| 787 | + { |
|
| 788 | + return $this->get('TKT_max'); |
|
| 789 | + } |
|
| 790 | + |
|
| 791 | + |
|
| 792 | + /** |
|
| 793 | + * Sets max |
|
| 794 | + * |
|
| 795 | + * @param int $max |
|
| 796 | + * @return void |
|
| 797 | + * @throws EE_Error |
|
| 798 | + * @throws ReflectionException |
|
| 799 | + */ |
|
| 800 | + public function set_max($max) |
|
| 801 | + { |
|
| 802 | + $this->set('TKT_max', $max); |
|
| 803 | + } |
|
| 804 | + |
|
| 805 | + |
|
| 806 | + /** |
|
| 807 | + * Sets price |
|
| 808 | + * |
|
| 809 | + * @param float $price |
|
| 810 | + * @return void |
|
| 811 | + * @throws EE_Error |
|
| 812 | + * @throws ReflectionException |
|
| 813 | + */ |
|
| 814 | + public function set_price($price) |
|
| 815 | + { |
|
| 816 | + $this->set('TKT_price', $price); |
|
| 817 | + } |
|
| 818 | + |
|
| 819 | + |
|
| 820 | + /** |
|
| 821 | + * Gets sold |
|
| 822 | + * |
|
| 823 | + * @return int |
|
| 824 | + * @throws EE_Error |
|
| 825 | + * @throws ReflectionException |
|
| 826 | + */ |
|
| 827 | + public function sold() |
|
| 828 | + { |
|
| 829 | + return $this->get_raw('TKT_sold'); |
|
| 830 | + } |
|
| 831 | + |
|
| 832 | + |
|
| 833 | + /** |
|
| 834 | + * Sets sold |
|
| 835 | + * |
|
| 836 | + * @param int $sold |
|
| 837 | + * @return void |
|
| 838 | + * @throws EE_Error |
|
| 839 | + * @throws ReflectionException |
|
| 840 | + */ |
|
| 841 | + public function set_sold($sold) |
|
| 842 | + { |
|
| 843 | + // sold can not go below zero |
|
| 844 | + $sold = max(0, $sold); |
|
| 845 | + $this->set('TKT_sold', $sold); |
|
| 846 | + } |
|
| 847 | + |
|
| 848 | + |
|
| 849 | + /** |
|
| 850 | + * Increments sold by amount passed by $qty AND decrements the reserved count on both this ticket and its |
|
| 851 | + * associated datetimes. |
|
| 852 | + * |
|
| 853 | + * @param int $qty |
|
| 854 | + * @return boolean |
|
| 855 | + * @throws EE_Error |
|
| 856 | + * @throws InvalidArgumentException |
|
| 857 | + * @throws InvalidDataTypeException |
|
| 858 | + * @throws InvalidInterfaceException |
|
| 859 | + * @throws ReflectionException |
|
| 860 | + * @since 4.9.80.p |
|
| 861 | + */ |
|
| 862 | + public function increaseSold($qty = 1) |
|
| 863 | + { |
|
| 864 | + $qty = absint($qty); |
|
| 865 | + // increment sold and decrement reserved datetime quantities simultaneously |
|
| 866 | + // don't worry about failures, because they must have already had a spot reserved |
|
| 867 | + $this->increaseSoldForDatetimes($qty); |
|
| 868 | + // Increment and decrement ticket quantities simultaneously |
|
| 869 | + $success = $this->adjustNumericFieldsInDb( |
|
| 870 | + [ |
|
| 871 | + 'TKT_reserved' => $qty * -1, |
|
| 872 | + 'TKT_sold' => $qty, |
|
| 873 | + ] |
|
| 874 | + ); |
|
| 875 | + do_action( |
|
| 876 | + 'AHEE__EE_Ticket__increase_sold', |
|
| 877 | + $this, |
|
| 878 | + $qty, |
|
| 879 | + $this->sold(), |
|
| 880 | + $success |
|
| 881 | + ); |
|
| 882 | + return $success; |
|
| 883 | + } |
|
| 884 | + |
|
| 885 | + |
|
| 886 | + /** |
|
| 887 | + * On each datetime related to this ticket, increases its sold count and decreases its reserved count by $qty. |
|
| 888 | + * |
|
| 889 | + * @param int $qty positive or negative. Positive means to increase sold counts (and decrease reserved |
|
| 890 | + * counts), Negative means to decreases old counts (and increase reserved counts). |
|
| 891 | + * @param EE_Datetime[] $datetimes |
|
| 892 | + * @throws EE_Error |
|
| 893 | + * @throws InvalidArgumentException |
|
| 894 | + * @throws InvalidDataTypeException |
|
| 895 | + * @throws InvalidInterfaceException |
|
| 896 | + * @throws ReflectionException |
|
| 897 | + * @since 4.9.80.p |
|
| 898 | + */ |
|
| 899 | + protected function increaseSoldForDatetimes($qty, array $datetimes = []) |
|
| 900 | + { |
|
| 901 | + $datetimes = ! empty($datetimes) ? $datetimes : $this->datetimes(); |
|
| 902 | + foreach ($datetimes as $datetime) { |
|
| 903 | + $datetime->increaseSold($qty); |
|
| 904 | + } |
|
| 905 | + } |
|
| 906 | + |
|
| 907 | + |
|
| 908 | + /** |
|
| 909 | + * Decrements (subtracts) sold by amount passed by $qty on both the ticket and its related datetimes directly in the |
|
| 910 | + * DB and then updates the model objects. |
|
| 911 | + * Does not affect the reserved counts. |
|
| 912 | + * |
|
| 913 | + * @param int $qty |
|
| 914 | + * @return boolean |
|
| 915 | + * @throws EE_Error |
|
| 916 | + * @throws InvalidArgumentException |
|
| 917 | + * @throws InvalidDataTypeException |
|
| 918 | + * @throws InvalidInterfaceException |
|
| 919 | + * @throws ReflectionException |
|
| 920 | + * @since 4.9.80.p |
|
| 921 | + */ |
|
| 922 | + public function decreaseSold($qty = 1) |
|
| 923 | + { |
|
| 924 | + $qty = absint($qty); |
|
| 925 | + $this->decreaseSoldForDatetimes($qty); |
|
| 926 | + $success = $this->adjustNumericFieldsInDb( |
|
| 927 | + [ |
|
| 928 | + 'TKT_sold' => $qty * -1, |
|
| 929 | + ] |
|
| 930 | + ); |
|
| 931 | + do_action( |
|
| 932 | + 'AHEE__EE_Ticket__decrease_sold', |
|
| 933 | + $this, |
|
| 934 | + $qty, |
|
| 935 | + $this->sold(), |
|
| 936 | + $success |
|
| 937 | + ); |
|
| 938 | + return $success; |
|
| 939 | + } |
|
| 940 | + |
|
| 941 | + |
|
| 942 | + /** |
|
| 943 | + * Decreases sold on related datetimes |
|
| 944 | + * |
|
| 945 | + * @param int $qty |
|
| 946 | + * @param EE_Datetime[] $datetimes |
|
| 947 | + * @return void |
|
| 948 | + * @throws EE_Error |
|
| 949 | + * @throws InvalidArgumentException |
|
| 950 | + * @throws InvalidDataTypeException |
|
| 951 | + * @throws InvalidInterfaceException |
|
| 952 | + * @throws ReflectionException |
|
| 953 | + * @since 4.9.80.p |
|
| 954 | + */ |
|
| 955 | + protected function decreaseSoldForDatetimes($qty = 1, array $datetimes = []) |
|
| 956 | + { |
|
| 957 | + $datetimes = ! empty($datetimes) ? $datetimes : $this->datetimes(); |
|
| 958 | + if (is_array($datetimes)) { |
|
| 959 | + foreach ($datetimes as $datetime) { |
|
| 960 | + if ($datetime instanceof EE_Datetime) { |
|
| 961 | + $datetime->decreaseSold($qty); |
|
| 962 | + } |
|
| 963 | + } |
|
| 964 | + } |
|
| 965 | + } |
|
| 966 | + |
|
| 967 | + |
|
| 968 | + /** |
|
| 969 | + * Gets qty of reserved tickets |
|
| 970 | + * |
|
| 971 | + * @return int |
|
| 972 | + * @throws EE_Error |
|
| 973 | + * @throws ReflectionException |
|
| 974 | + */ |
|
| 975 | + public function reserved() |
|
| 976 | + { |
|
| 977 | + return $this->get_raw('TKT_reserved'); |
|
| 978 | + } |
|
| 979 | + |
|
| 980 | + |
|
| 981 | + /** |
|
| 982 | + * Sets reserved |
|
| 983 | + * |
|
| 984 | + * @param int $reserved |
|
| 985 | + * @return void |
|
| 986 | + * @throws EE_Error |
|
| 987 | + * @throws ReflectionException |
|
| 988 | + */ |
|
| 989 | + public function set_reserved($reserved) |
|
| 990 | + { |
|
| 991 | + // reserved can not go below zero |
|
| 992 | + $reserved = max(0, (int) $reserved); |
|
| 993 | + $this->set('TKT_reserved', $reserved); |
|
| 994 | + } |
|
| 995 | + |
|
| 996 | + |
|
| 997 | + /** |
|
| 998 | + * Increments reserved by amount passed by $qty, and persists it immediately to the database. |
|
| 999 | + * |
|
| 1000 | + * @param int $qty |
|
| 1001 | + * @param string $source |
|
| 1002 | + * @return bool whether we successfully reserved the ticket or not. |
|
| 1003 | + * @throws EE_Error |
|
| 1004 | + * @throws InvalidArgumentException |
|
| 1005 | + * @throws ReflectionException |
|
| 1006 | + * @throws InvalidDataTypeException |
|
| 1007 | + * @throws InvalidInterfaceException |
|
| 1008 | + * @since 4.9.80.p |
|
| 1009 | + */ |
|
| 1010 | + public function increaseReserved($qty = 1, $source = 'unknown') |
|
| 1011 | + { |
|
| 1012 | + $qty = absint($qty); |
|
| 1013 | + do_action( |
|
| 1014 | + 'AHEE__EE_Ticket__increase_reserved__begin', |
|
| 1015 | + $this, |
|
| 1016 | + $qty, |
|
| 1017 | + $source |
|
| 1018 | + ); |
|
| 1019 | + $this->add_extra_meta(EE_Ticket::META_KEY_TICKET_RESERVATIONS, "{$qty} from {$source}"); |
|
| 1020 | + $success = false; |
|
| 1021 | + $datetimes_adjusted_successfully = $this->increaseReservedForDatetimes($qty); |
|
| 1022 | + if ($datetimes_adjusted_successfully) { |
|
| 1023 | + $success = $this->incrementFieldConditionallyInDb( |
|
| 1024 | + 'TKT_reserved', |
|
| 1025 | + 'TKT_sold', |
|
| 1026 | + 'TKT_qty', |
|
| 1027 | + $qty |
|
| 1028 | + ); |
|
| 1029 | + if (! $success) { |
|
| 1030 | + // The datetimes were successfully bumped, but not the |
|
| 1031 | + // ticket. So we need to manually rollback the datetimes. |
|
| 1032 | + $this->decreaseReservedForDatetimes($qty); |
|
| 1033 | + } |
|
| 1034 | + } |
|
| 1035 | + do_action( |
|
| 1036 | + 'AHEE__EE_Ticket__increase_reserved', |
|
| 1037 | + $this, |
|
| 1038 | + $qty, |
|
| 1039 | + $this->reserved(), |
|
| 1040 | + $success |
|
| 1041 | + ); |
|
| 1042 | + return $success; |
|
| 1043 | + } |
|
| 1044 | + |
|
| 1045 | + |
|
| 1046 | + /** |
|
| 1047 | + * Increases reserved counts on related datetimes |
|
| 1048 | + * |
|
| 1049 | + * @param int $qty |
|
| 1050 | + * @param EE_Datetime[] $datetimes |
|
| 1051 | + * @return boolean indicating success |
|
| 1052 | + * @throws EE_Error |
|
| 1053 | + * @throws InvalidArgumentException |
|
| 1054 | + * @throws InvalidDataTypeException |
|
| 1055 | + * @throws InvalidInterfaceException |
|
| 1056 | + * @throws ReflectionException |
|
| 1057 | + * @since 4.9.80.p |
|
| 1058 | + */ |
|
| 1059 | + protected function increaseReservedForDatetimes($qty = 1, array $datetimes = []) |
|
| 1060 | + { |
|
| 1061 | + $datetimes = ! empty($datetimes) ? $datetimes : $this->datetimes(); |
|
| 1062 | + $datetimes_updated = []; |
|
| 1063 | + $limit_exceeded = false; |
|
| 1064 | + if (is_array($datetimes)) { |
|
| 1065 | + foreach ($datetimes as $datetime) { |
|
| 1066 | + if ($datetime instanceof EE_Datetime) { |
|
| 1067 | + if ($datetime->increaseReserved($qty)) { |
|
| 1068 | + $datetimes_updated[] = $datetime; |
|
| 1069 | + } else { |
|
| 1070 | + $limit_exceeded = true; |
|
| 1071 | + break; |
|
| 1072 | + } |
|
| 1073 | + } |
|
| 1074 | + } |
|
| 1075 | + // If somewhere along the way we detected a datetime whose |
|
| 1076 | + // limit was exceeded, do a manual rollback. |
|
| 1077 | + if ($limit_exceeded) { |
|
| 1078 | + $this->decreaseReservedForDatetimes($qty, $datetimes_updated); |
|
| 1079 | + return false; |
|
| 1080 | + } |
|
| 1081 | + } |
|
| 1082 | + return true; |
|
| 1083 | + } |
|
| 1084 | + |
|
| 1085 | + |
|
| 1086 | + /** |
|
| 1087 | + * Decrements (subtracts) reserved by amount passed by $qty, and persists it immediately to the database. |
|
| 1088 | + * |
|
| 1089 | + * @param int $qty |
|
| 1090 | + * @param bool $adjust_datetimes |
|
| 1091 | + * @param string $source |
|
| 1092 | + * @return boolean |
|
| 1093 | + * @throws EE_Error |
|
| 1094 | + * @throws InvalidArgumentException |
|
| 1095 | + * @throws ReflectionException |
|
| 1096 | + * @throws InvalidDataTypeException |
|
| 1097 | + * @throws InvalidInterfaceException |
|
| 1098 | + * @since 4.9.80.p |
|
| 1099 | + */ |
|
| 1100 | + public function decreaseReserved($qty = 1, $adjust_datetimes = true, $source = 'unknown') |
|
| 1101 | + { |
|
| 1102 | + $qty = absint($qty); |
|
| 1103 | + $this->add_extra_meta(EE_Ticket::META_KEY_TICKET_RESERVATIONS, "-{$qty} from {$source}"); |
|
| 1104 | + if ($adjust_datetimes) { |
|
| 1105 | + $this->decreaseReservedForDatetimes($qty); |
|
| 1106 | + } |
|
| 1107 | + $success = $this->adjustNumericFieldsInDb( |
|
| 1108 | + [ |
|
| 1109 | + 'TKT_reserved' => $qty * -1, |
|
| 1110 | + ] |
|
| 1111 | + ); |
|
| 1112 | + do_action( |
|
| 1113 | + 'AHEE__EE_Ticket__decrease_reserved', |
|
| 1114 | + $this, |
|
| 1115 | + $qty, |
|
| 1116 | + $this->reserved(), |
|
| 1117 | + $success |
|
| 1118 | + ); |
|
| 1119 | + return $success; |
|
| 1120 | + } |
|
| 1121 | + |
|
| 1122 | + |
|
| 1123 | + /** |
|
| 1124 | + * Decreases the reserved count on the specified datetimes. |
|
| 1125 | + * |
|
| 1126 | + * @param int $qty |
|
| 1127 | + * @param EE_Datetime[] $datetimes |
|
| 1128 | + * @throws EE_Error |
|
| 1129 | + * @throws InvalidArgumentException |
|
| 1130 | + * @throws ReflectionException |
|
| 1131 | + * @throws InvalidDataTypeException |
|
| 1132 | + * @throws InvalidInterfaceException |
|
| 1133 | + * @since 4.9.80.p |
|
| 1134 | + */ |
|
| 1135 | + protected function decreaseReservedForDatetimes($qty = 1, array $datetimes = []) |
|
| 1136 | + { |
|
| 1137 | + $datetimes = ! empty($datetimes) ? $datetimes : $this->datetimes(); |
|
| 1138 | + foreach ($datetimes as $datetime) { |
|
| 1139 | + if ($datetime instanceof EE_Datetime) { |
|
| 1140 | + $datetime->decreaseReserved($qty); |
|
| 1141 | + } |
|
| 1142 | + } |
|
| 1143 | + } |
|
| 1144 | + |
|
| 1145 | + |
|
| 1146 | + /** |
|
| 1147 | + * Gets ticket quantity |
|
| 1148 | + * |
|
| 1149 | + * @param string $context ticket quantity is somewhat subjective depending on the exact information sought |
|
| 1150 | + * therefore $context can be one of three values: '', 'reg_limit', or 'saleable' |
|
| 1151 | + * '' (default) quantity is the actual db value for TKT_qty, unaffected by other objects |
|
| 1152 | + * REG LIMIT: caps qty based on DTT_reg_limit for ALL related datetimes |
|
| 1153 | + * SALEABLE: also considers datetime sold and returns zero if ANY DTT is sold out, and |
|
| 1154 | + * is therefore the truest measure of tickets that can be purchased at the moment |
|
| 1155 | + * @return int |
|
| 1156 | + * @throws EE_Error |
|
| 1157 | + * @throws ReflectionException |
|
| 1158 | + */ |
|
| 1159 | + public function qty($context = '') |
|
| 1160 | + { |
|
| 1161 | + switch ($context) { |
|
| 1162 | + case 'reg_limit': |
|
| 1163 | + return $this->real_quantity_on_ticket(); |
|
| 1164 | + case 'saleable': |
|
| 1165 | + return $this->real_quantity_on_ticket('saleable'); |
|
| 1166 | + default: |
|
| 1167 | + return $this->get_raw('TKT_qty'); |
|
| 1168 | + } |
|
| 1169 | + } |
|
| 1170 | + |
|
| 1171 | + |
|
| 1172 | + /** |
|
| 1173 | + * Gets ticket quantity |
|
| 1174 | + * |
|
| 1175 | + * @param string $context ticket quantity is somewhat subjective depending on the exact information sought |
|
| 1176 | + * therefore $context can be one of two values: 'reg_limit', or 'saleable' |
|
| 1177 | + * REG LIMIT: caps qty based on DTT_reg_limit for ALL related datetimes |
|
| 1178 | + * SALEABLE: also considers datetime sold and returns zero if ANY DTT is sold out, and |
|
| 1179 | + * is therefore the truest measure of tickets that can be purchased at the moment |
|
| 1180 | + * @param int $DTT_ID the primary key for a particular datetime. |
|
| 1181 | + * set to 0 for all related datetimes |
|
| 1182 | + * @return int |
|
| 1183 | + * @throws EE_Error |
|
| 1184 | + * @throws ReflectionException |
|
| 1185 | + */ |
|
| 1186 | + public function real_quantity_on_ticket($context = 'reg_limit', $DTT_ID = 0) |
|
| 1187 | + { |
|
| 1188 | + $raw = $this->get_raw('TKT_qty'); |
|
| 1189 | + // return immediately if it's zero |
|
| 1190 | + if ($raw === 0) { |
|
| 1191 | + return $raw; |
|
| 1192 | + } |
|
| 1193 | + // echo "\n\n<br />Ticket: " . $this->name() . '<br />'; |
|
| 1194 | + // ensure qty doesn't exceed raw value for THIS ticket |
|
| 1195 | + $qty = min(EE_INF, $raw); |
|
| 1196 | + // echo "\n . qty: " . $qty . '<br />'; |
|
| 1197 | + // calculate this ticket's total sales and reservations |
|
| 1198 | + $sold_and_reserved_for_this_ticket = $this->sold() + $this->reserved(); |
|
| 1199 | + // echo "\n . sold: " . $this->sold() . '<br />'; |
|
| 1200 | + // echo "\n . reserved: " . $this->reserved() . '<br />'; |
|
| 1201 | + // echo "\n . sold_and_reserved_for_this_ticket: " . $sold_and_reserved_for_this_ticket . '<br />'; |
|
| 1202 | + // first we need to calculate the maximum number of tickets available for the datetime |
|
| 1203 | + // do we want data for one datetime or all of them ? |
|
| 1204 | + $query_params = $DTT_ID ? [['DTT_ID' => $DTT_ID]] : []; |
|
| 1205 | + $datetimes = $this->datetimes($query_params); |
|
| 1206 | + if (is_array($datetimes) && ! empty($datetimes)) { |
|
| 1207 | + foreach ($datetimes as $datetime) { |
|
| 1208 | + if ($datetime instanceof EE_Datetime) { |
|
| 1209 | + $datetime->refresh_from_db(); |
|
| 1210 | + // echo "\n . . datetime name: " . $datetime->name() . '<br />'; |
|
| 1211 | + // echo "\n . . datetime ID: " . $datetime->ID() . '<br />'; |
|
| 1212 | + // initialize with no restrictions for each datetime |
|
| 1213 | + // but adjust datetime qty based on datetime reg limit |
|
| 1214 | + $datetime_qty = min(EE_INF, $datetime->reg_limit()); |
|
| 1215 | + // echo "\n . . . datetime reg_limit: " . $datetime->reg_limit() . '<br />'; |
|
| 1216 | + // echo "\n . . . datetime_qty: " . $datetime_qty . '<br />'; |
|
| 1217 | + // if we want the actual saleable amount, then we need to consider OTHER ticket sales |
|
| 1218 | + // and reservations for this datetime, that do NOT include sales and reservations |
|
| 1219 | + // for this ticket (so we add $this->sold() and $this->reserved() back in) |
|
| 1220 | + if ($context === 'saleable') { |
|
| 1221 | + $datetime_qty = max( |
|
| 1222 | + $datetime_qty - $datetime->sold_and_reserved() + $sold_and_reserved_for_this_ticket, |
|
| 1223 | + 0 |
|
| 1224 | + ); |
|
| 1225 | + // echo "\n . . . datetime sold: " . $datetime->sold() . '<br />'; |
|
| 1226 | + // echo "\n . . . datetime reserved: " . $datetime->reserved() . '<br />'; |
|
| 1227 | + // echo "\n . . . datetime sold_and_reserved: " . $datetime->sold_and_reserved() . '<br />'; |
|
| 1228 | + // echo "\n . . . datetime_qty: " . $datetime_qty . '<br />'; |
|
| 1229 | + $datetime_qty = ! $datetime->sold_out() ? $datetime_qty : 0; |
|
| 1230 | + // echo "\n . . . datetime_qty: " . $datetime_qty . '<br />'; |
|
| 1231 | + } |
|
| 1232 | + $qty = min($datetime_qty, $qty); |
|
| 1233 | + // echo "\n . . qty: " . $qty . '<br />'; |
|
| 1234 | + } |
|
| 1235 | + } |
|
| 1236 | + } |
|
| 1237 | + // NOW that we know the maximum number of tickets available for the datetime |
|
| 1238 | + // we can finally factor in the details for this specific ticket |
|
| 1239 | + if ($qty > 0 && $context === 'saleable') { |
|
| 1240 | + // and subtract the sales for THIS ticket |
|
| 1241 | + $qty = max($qty - $sold_and_reserved_for_this_ticket, 0); |
|
| 1242 | + // echo "\n . qty: " . $qty . '<br />'; |
|
| 1243 | + } |
|
| 1244 | + // echo "\nFINAL QTY: " . $qty . "<br /><br />"; |
|
| 1245 | + return $qty; |
|
| 1246 | + } |
|
| 1247 | + |
|
| 1248 | + |
|
| 1249 | + /** |
|
| 1250 | + * Sets qty - IMPORTANT!!! Does NOT allow QTY to be set higher than the lowest reg limit of any related datetimes |
|
| 1251 | + * |
|
| 1252 | + * @param int $qty |
|
| 1253 | + * @return void |
|
| 1254 | + * @throws EE_Error |
|
| 1255 | + * @throws ReflectionException |
|
| 1256 | + */ |
|
| 1257 | + public function set_qty($qty) |
|
| 1258 | + { |
|
| 1259 | + $datetimes = $this->datetimes(); |
|
| 1260 | + foreach ($datetimes as $datetime) { |
|
| 1261 | + if ($datetime instanceof EE_Datetime) { |
|
| 1262 | + $qty = min($qty, $datetime->reg_limit()); |
|
| 1263 | + } |
|
| 1264 | + } |
|
| 1265 | + $this->set('TKT_qty', $qty); |
|
| 1266 | + } |
|
| 1267 | + |
|
| 1268 | + |
|
| 1269 | + /** |
|
| 1270 | + * Gets uses |
|
| 1271 | + * |
|
| 1272 | + * @return int |
|
| 1273 | + * @throws EE_Error |
|
| 1274 | + * @throws ReflectionException |
|
| 1275 | + */ |
|
| 1276 | + public function uses() |
|
| 1277 | + { |
|
| 1278 | + return $this->get('TKT_uses'); |
|
| 1279 | + } |
|
| 1280 | + |
|
| 1281 | + |
|
| 1282 | + /** |
|
| 1283 | + * Sets uses |
|
| 1284 | + * |
|
| 1285 | + * @param int $uses |
|
| 1286 | + * @return void |
|
| 1287 | + * @throws EE_Error |
|
| 1288 | + * @throws ReflectionException |
|
| 1289 | + */ |
|
| 1290 | + public function set_uses($uses) |
|
| 1291 | + { |
|
| 1292 | + $this->set('TKT_uses', $uses); |
|
| 1293 | + } |
|
| 1294 | + |
|
| 1295 | + |
|
| 1296 | + /** |
|
| 1297 | + * returns whether ticket is required or not. |
|
| 1298 | + * |
|
| 1299 | + * @return boolean |
|
| 1300 | + * @throws EE_Error |
|
| 1301 | + * @throws ReflectionException |
|
| 1302 | + */ |
|
| 1303 | + public function required() |
|
| 1304 | + { |
|
| 1305 | + return $this->get('TKT_required'); |
|
| 1306 | + } |
|
| 1307 | + |
|
| 1308 | + |
|
| 1309 | + /** |
|
| 1310 | + * sets the TKT_required property |
|
| 1311 | + * |
|
| 1312 | + * @param boolean $required |
|
| 1313 | + * @return void |
|
| 1314 | + * @throws EE_Error |
|
| 1315 | + * @throws ReflectionException |
|
| 1316 | + */ |
|
| 1317 | + public function set_required($required) |
|
| 1318 | + { |
|
| 1319 | + $this->set('TKT_required', $required); |
|
| 1320 | + } |
|
| 1321 | + |
|
| 1322 | + |
|
| 1323 | + /** |
|
| 1324 | + * Gets taxable |
|
| 1325 | + * |
|
| 1326 | + * @return boolean |
|
| 1327 | + * @throws EE_Error |
|
| 1328 | + * @throws ReflectionException |
|
| 1329 | + */ |
|
| 1330 | + public function taxable() |
|
| 1331 | + { |
|
| 1332 | + return $this->get('TKT_taxable'); |
|
| 1333 | + } |
|
| 1334 | + |
|
| 1335 | + |
|
| 1336 | + /** |
|
| 1337 | + * Sets taxable |
|
| 1338 | + * |
|
| 1339 | + * @param boolean $taxable |
|
| 1340 | + * @return void |
|
| 1341 | + * @throws EE_Error |
|
| 1342 | + * @throws ReflectionException |
|
| 1343 | + */ |
|
| 1344 | + public function set_taxable($taxable) |
|
| 1345 | + { |
|
| 1346 | + $this->set('TKT_taxable', $taxable); |
|
| 1347 | + } |
|
| 1348 | + |
|
| 1349 | + |
|
| 1350 | + /** |
|
| 1351 | + * Gets is_default |
|
| 1352 | + * |
|
| 1353 | + * @return boolean |
|
| 1354 | + * @throws EE_Error |
|
| 1355 | + * @throws ReflectionException |
|
| 1356 | + */ |
|
| 1357 | + public function is_default() |
|
| 1358 | + { |
|
| 1359 | + return $this->get('TKT_is_default'); |
|
| 1360 | + } |
|
| 1361 | + |
|
| 1362 | + |
|
| 1363 | + /** |
|
| 1364 | + * Sets is_default |
|
| 1365 | + * |
|
| 1366 | + * @param boolean $is_default |
|
| 1367 | + * @return void |
|
| 1368 | + * @throws EE_Error |
|
| 1369 | + * @throws ReflectionException |
|
| 1370 | + */ |
|
| 1371 | + public function set_is_default($is_default) |
|
| 1372 | + { |
|
| 1373 | + $this->set('TKT_is_default', $is_default); |
|
| 1374 | + } |
|
| 1375 | + |
|
| 1376 | + |
|
| 1377 | + /** |
|
| 1378 | + * Gets order |
|
| 1379 | + * |
|
| 1380 | + * @return int |
|
| 1381 | + * @throws EE_Error |
|
| 1382 | + * @throws ReflectionException |
|
| 1383 | + */ |
|
| 1384 | + public function order() |
|
| 1385 | + { |
|
| 1386 | + return $this->get('TKT_order'); |
|
| 1387 | + } |
|
| 1388 | + |
|
| 1389 | + |
|
| 1390 | + /** |
|
| 1391 | + * Sets order |
|
| 1392 | + * |
|
| 1393 | + * @param int $order |
|
| 1394 | + * @return void |
|
| 1395 | + * @throws EE_Error |
|
| 1396 | + * @throws ReflectionException |
|
| 1397 | + */ |
|
| 1398 | + public function set_order($order) |
|
| 1399 | + { |
|
| 1400 | + $this->set('TKT_order', $order); |
|
| 1401 | + } |
|
| 1402 | + |
|
| 1403 | + |
|
| 1404 | + /** |
|
| 1405 | + * Gets row |
|
| 1406 | + * |
|
| 1407 | + * @return int |
|
| 1408 | + * @throws EE_Error |
|
| 1409 | + * @throws ReflectionException |
|
| 1410 | + */ |
|
| 1411 | + public function row() |
|
| 1412 | + { |
|
| 1413 | + return $this->get('TKT_row'); |
|
| 1414 | + } |
|
| 1415 | + |
|
| 1416 | + |
|
| 1417 | + /** |
|
| 1418 | + * Sets row |
|
| 1419 | + * |
|
| 1420 | + * @param int $row |
|
| 1421 | + * @return void |
|
| 1422 | + * @throws EE_Error |
|
| 1423 | + * @throws ReflectionException |
|
| 1424 | + */ |
|
| 1425 | + public function set_row($row) |
|
| 1426 | + { |
|
| 1427 | + $this->set('TKT_row', $row); |
|
| 1428 | + } |
|
| 1429 | + |
|
| 1430 | + |
|
| 1431 | + /** |
|
| 1432 | + * Gets deleted |
|
| 1433 | + * |
|
| 1434 | + * @return boolean |
|
| 1435 | + * @throws EE_Error |
|
| 1436 | + * @throws ReflectionException |
|
| 1437 | + */ |
|
| 1438 | + public function deleted() |
|
| 1439 | + { |
|
| 1440 | + return $this->get('TKT_deleted'); |
|
| 1441 | + } |
|
| 1442 | + |
|
| 1443 | + |
|
| 1444 | + /** |
|
| 1445 | + * Sets deleted |
|
| 1446 | + * |
|
| 1447 | + * @param boolean $deleted |
|
| 1448 | + * @return void |
|
| 1449 | + * @throws EE_Error |
|
| 1450 | + * @throws ReflectionException |
|
| 1451 | + */ |
|
| 1452 | + public function set_deleted($deleted) |
|
| 1453 | + { |
|
| 1454 | + $this->set('TKT_deleted', $deleted); |
|
| 1455 | + } |
|
| 1456 | + |
|
| 1457 | + |
|
| 1458 | + /** |
|
| 1459 | + * Gets parent |
|
| 1460 | + * |
|
| 1461 | + * @return int |
|
| 1462 | + * @throws EE_Error |
|
| 1463 | + * @throws ReflectionException |
|
| 1464 | + */ |
|
| 1465 | + public function parent_ID() |
|
| 1466 | + { |
|
| 1467 | + return $this->get('TKT_parent'); |
|
| 1468 | + } |
|
| 1469 | + |
|
| 1470 | + |
|
| 1471 | + /** |
|
| 1472 | + * Sets parent |
|
| 1473 | + * |
|
| 1474 | + * @param int $parent |
|
| 1475 | + * @return void |
|
| 1476 | + * @throws EE_Error |
|
| 1477 | + * @throws ReflectionException |
|
| 1478 | + */ |
|
| 1479 | + public function set_parent_ID($parent) |
|
| 1480 | + { |
|
| 1481 | + $this->set('TKT_parent', $parent); |
|
| 1482 | + } |
|
| 1483 | + |
|
| 1484 | + |
|
| 1485 | + /** |
|
| 1486 | + * @return boolean |
|
| 1487 | + * @throws EE_Error |
|
| 1488 | + * @throws InvalidArgumentException |
|
| 1489 | + * @throws InvalidDataTypeException |
|
| 1490 | + * @throws InvalidInterfaceException |
|
| 1491 | + * @throws ReflectionException |
|
| 1492 | + */ |
|
| 1493 | + public function reverse_calculate() |
|
| 1494 | + { |
|
| 1495 | + return $this->get('TKT_reverse_calculate'); |
|
| 1496 | + } |
|
| 1497 | + |
|
| 1498 | + |
|
| 1499 | + /** |
|
| 1500 | + * @param boolean $reverse_calculate |
|
| 1501 | + * @throws EE_Error |
|
| 1502 | + * @throws InvalidArgumentException |
|
| 1503 | + * @throws InvalidDataTypeException |
|
| 1504 | + * @throws InvalidInterfaceException |
|
| 1505 | + * @throws ReflectionException |
|
| 1506 | + */ |
|
| 1507 | + public function set_reverse_calculate($reverse_calculate) |
|
| 1508 | + { |
|
| 1509 | + $this->set('TKT_reverse_calculate', $reverse_calculate); |
|
| 1510 | + } |
|
| 1511 | + |
|
| 1512 | + |
|
| 1513 | + /** |
|
| 1514 | + * Gets a string which is handy for showing in gateways etc that describes the ticket. |
|
| 1515 | + * |
|
| 1516 | + * @return string |
|
| 1517 | + * @throws EE_Error |
|
| 1518 | + * @throws ReflectionException |
|
| 1519 | + */ |
|
| 1520 | + public function name_and_info() |
|
| 1521 | + { |
|
| 1522 | + $times = []; |
|
| 1523 | + foreach ($this->datetimes() as $datetime) { |
|
| 1524 | + $times[] = $datetime->start_date_and_time(); |
|
| 1525 | + } |
|
| 1526 | + return $this->name() . ' @ ' . implode(', ', $times) . ' for ' . $this->pretty_price(); |
|
| 1527 | + } |
|
| 1528 | + |
|
| 1529 | + |
|
| 1530 | + /** |
|
| 1531 | + * Gets name |
|
| 1532 | + * |
|
| 1533 | + * @return string |
|
| 1534 | + * @throws EE_Error |
|
| 1535 | + * @throws ReflectionException |
|
| 1536 | + */ |
|
| 1537 | + public function name() |
|
| 1538 | + { |
|
| 1539 | + return $this->get('TKT_name'); |
|
| 1540 | + } |
|
| 1541 | + |
|
| 1542 | + |
|
| 1543 | + /** |
|
| 1544 | + * Gets price |
|
| 1545 | + * |
|
| 1546 | + * @return float |
|
| 1547 | + * @throws EE_Error |
|
| 1548 | + * @throws ReflectionException |
|
| 1549 | + */ |
|
| 1550 | + public function price() |
|
| 1551 | + { |
|
| 1552 | + return $this->get('TKT_price'); |
|
| 1553 | + } |
|
| 1554 | + |
|
| 1555 | + |
|
| 1556 | + /** |
|
| 1557 | + * Gets all the registrations for this ticket |
|
| 1558 | + * |
|
| 1559 | + * @param array $query_params @see |
|
| 1560 | + * https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md |
|
| 1561 | + * @return EE_Registration[]|EE_Base_Class[] |
|
| 1562 | + * @throws EE_Error |
|
| 1563 | + * @throws ReflectionException |
|
| 1564 | + */ |
|
| 1565 | + public function registrations($query_params = []) |
|
| 1566 | + { |
|
| 1567 | + return $this->get_many_related('Registration', $query_params); |
|
| 1568 | + } |
|
| 1569 | + |
|
| 1570 | + |
|
| 1571 | + /** |
|
| 1572 | + * Updates the TKT_sold attribute (and saves) based on the number of APPROVED registrations for this ticket. |
|
| 1573 | + * |
|
| 1574 | + * @return int |
|
| 1575 | + * @throws EE_Error |
|
| 1576 | + * @throws ReflectionException |
|
| 1577 | + */ |
|
| 1578 | + public function update_tickets_sold() |
|
| 1579 | + { |
|
| 1580 | + $count_regs_for_this_ticket = $this->count_registrations( |
|
| 1581 | + [ |
|
| 1582 | + [ |
|
| 1583 | + 'STS_ID' => EEM_Registration::status_id_approved, |
|
| 1584 | + 'REG_deleted' => 0, |
|
| 1585 | + ], |
|
| 1586 | + ] |
|
| 1587 | + ); |
|
| 1588 | + $this->set_sold($count_regs_for_this_ticket); |
|
| 1589 | + $this->save(); |
|
| 1590 | + return $count_regs_for_this_ticket; |
|
| 1591 | + } |
|
| 1592 | + |
|
| 1593 | + |
|
| 1594 | + /** |
|
| 1595 | + * Counts the registrations for this ticket |
|
| 1596 | + * |
|
| 1597 | + * @param array $query_params @see |
|
| 1598 | + * https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md |
|
| 1599 | + * @return int |
|
| 1600 | + * @throws EE_Error |
|
| 1601 | + * @throws ReflectionException |
|
| 1602 | + */ |
|
| 1603 | + public function count_registrations($query_params = []) |
|
| 1604 | + { |
|
| 1605 | + return $this->count_related('Registration', $query_params); |
|
| 1606 | + } |
|
| 1607 | + |
|
| 1608 | + |
|
| 1609 | + /** |
|
| 1610 | + * Implementation for EEI_Has_Icon interface method. |
|
| 1611 | + * |
|
| 1612 | + * @return string |
|
| 1613 | + * @see EEI_Visual_Representation for comments |
|
| 1614 | + */ |
|
| 1615 | + public function get_icon() |
|
| 1616 | + { |
|
| 1617 | + return '<span class="dashicons dashicons-tickets-alt"/>'; |
|
| 1618 | + } |
|
| 1619 | + |
|
| 1620 | + |
|
| 1621 | + /** |
|
| 1622 | + * Implementation of the EEI_Event_Relation interface method |
|
| 1623 | + * |
|
| 1624 | + * @return EE_Event |
|
| 1625 | + * @throws EE_Error |
|
| 1626 | + * @throws UnexpectedEntityException |
|
| 1627 | + * @throws ReflectionException |
|
| 1628 | + * @see EEI_Event_Relation for comments |
|
| 1629 | + */ |
|
| 1630 | + public function get_related_event() |
|
| 1631 | + { |
|
| 1632 | + // get one datetime to use for getting the event |
|
| 1633 | + $datetime = $this->first_datetime(); |
|
| 1634 | + if (! $datetime instanceof EE_Datetime) { |
|
| 1635 | + throw new UnexpectedEntityException( |
|
| 1636 | + $datetime, |
|
| 1637 | + 'EE_Datetime', |
|
| 1638 | + sprintf( |
|
| 1639 | + __('The ticket (%s) is not associated with any valid datetimes.', 'event_espresso'), |
|
| 1640 | + $this->name() |
|
| 1641 | + ) |
|
| 1642 | + ); |
|
| 1643 | + } |
|
| 1644 | + $event = $datetime->event(); |
|
| 1645 | + if (! $event instanceof EE_Event) { |
|
| 1646 | + throw new UnexpectedEntityException( |
|
| 1647 | + $event, |
|
| 1648 | + 'EE_Event', |
|
| 1649 | + sprintf( |
|
| 1650 | + __('The ticket (%s) is not associated with a valid event.', 'event_espresso'), |
|
| 1651 | + $this->name() |
|
| 1652 | + ) |
|
| 1653 | + ); |
|
| 1654 | + } |
|
| 1655 | + return $event; |
|
| 1656 | + } |
|
| 1657 | + |
|
| 1658 | + |
|
| 1659 | + /** |
|
| 1660 | + * Implementation of the EEI_Event_Relation interface method |
|
| 1661 | + * |
|
| 1662 | + * @return string |
|
| 1663 | + * @throws UnexpectedEntityException |
|
| 1664 | + * @throws EE_Error |
|
| 1665 | + * @throws ReflectionException |
|
| 1666 | + * @see EEI_Event_Relation for comments |
|
| 1667 | + */ |
|
| 1668 | + public function get_event_name() |
|
| 1669 | + { |
|
| 1670 | + $event = $this->get_related_event(); |
|
| 1671 | + return $event instanceof EE_Event ? $event->name() : ''; |
|
| 1672 | + } |
|
| 1673 | + |
|
| 1674 | + |
|
| 1675 | + /** |
|
| 1676 | + * Implementation of the EEI_Event_Relation interface method |
|
| 1677 | + * |
|
| 1678 | + * @return int |
|
| 1679 | + * @throws UnexpectedEntityException |
|
| 1680 | + * @throws EE_Error |
|
| 1681 | + * @throws ReflectionException |
|
| 1682 | + * @see EEI_Event_Relation for comments |
|
| 1683 | + */ |
|
| 1684 | + public function get_event_ID() |
|
| 1685 | + { |
|
| 1686 | + $event = $this->get_related_event(); |
|
| 1687 | + return $event instanceof EE_Event ? $event->ID() : 0; |
|
| 1688 | + } |
|
| 1689 | + |
|
| 1690 | + |
|
| 1691 | + /** |
|
| 1692 | + * This simply returns whether a ticket can be permanently deleted or not. |
|
| 1693 | + * The criteria for determining this is whether the ticket has any related registrations. |
|
| 1694 | + * If there are none then it can be permanently deleted. |
|
| 1695 | + * |
|
| 1696 | + * @return bool |
|
| 1697 | + * @throws EE_Error |
|
| 1698 | + * @throws ReflectionException |
|
| 1699 | + */ |
|
| 1700 | + public function is_permanently_deleteable() |
|
| 1701 | + { |
|
| 1702 | + return $this->count_registrations() === 0; |
|
| 1703 | + } |
|
| 1704 | + |
|
| 1705 | + |
|
| 1706 | + /** |
|
| 1707 | + * @return int |
|
| 1708 | + * @throws EE_Error |
|
| 1709 | + * @throws ReflectionException |
|
| 1710 | + * @since $VID:$ |
|
| 1711 | + */ |
|
| 1712 | + public function visibility(): int |
|
| 1713 | + { |
|
| 1714 | + return $this->get('TKT_visibility'); |
|
| 1715 | + } |
|
| 1716 | + |
|
| 1717 | + |
|
| 1718 | + /** |
|
| 1719 | + * @return int |
|
| 1720 | + * @throws EE_Error |
|
| 1721 | + * @throws ReflectionException |
|
| 1722 | + * @since $VID:$ |
|
| 1723 | + */ |
|
| 1724 | + public function isHidden(): int |
|
| 1725 | + { |
|
| 1726 | + return $this->visibility() === EEM_Ticket::TICKET_VISIBILITY_NONE_VALUE; |
|
| 1727 | + } |
|
| 1728 | + |
|
| 1729 | + |
|
| 1730 | + /** |
|
| 1731 | + * @return int |
|
| 1732 | + * @throws EE_Error |
|
| 1733 | + * @throws ReflectionException |
|
| 1734 | + * @since $VID:$ |
|
| 1735 | + */ |
|
| 1736 | + public function isNotHidden(): int |
|
| 1737 | + { |
|
| 1738 | + return $this->visibility() > EEM_Ticket::TICKET_VISIBILITY_NONE_VALUE; |
|
| 1739 | + } |
|
| 1740 | + |
|
| 1741 | + |
|
| 1742 | + /** |
|
| 1743 | + * @return int |
|
| 1744 | + * @throws EE_Error |
|
| 1745 | + * @throws ReflectionException |
|
| 1746 | + * @since $VID:$ |
|
| 1747 | + */ |
|
| 1748 | + public function isPublicOnly(): int |
|
| 1749 | + { |
|
| 1750 | + return $this->isNotHidden() && $this->visibility() <= EEM_Ticket::TICKET_VISIBILITY_PUBLIC_VALUE; |
|
| 1751 | + } |
|
| 1752 | + |
|
| 1753 | + |
|
| 1754 | + /** |
|
| 1755 | + * @return int |
|
| 1756 | + * @throws EE_Error |
|
| 1757 | + * @throws ReflectionException |
|
| 1758 | + * @since $VID:$ |
|
| 1759 | + */ |
|
| 1760 | + public function isMembersOnly(): int |
|
| 1761 | + { |
|
| 1762 | + return $this->visibility() > EEM_Ticket::TICKET_VISIBILITY_PUBLIC_VALUE |
|
| 1763 | + && $this->visibility() <= EEM_Ticket::TICKET_VISIBILITY_MEMBERS_ONLY_VALUE; |
|
| 1764 | + } |
|
| 1765 | + |
|
| 1766 | + |
|
| 1767 | + /** |
|
| 1768 | + * @return int |
|
| 1769 | + * @throws EE_Error |
|
| 1770 | + * @throws ReflectionException |
|
| 1771 | + * @since $VID:$ |
|
| 1772 | + */ |
|
| 1773 | + public function isAdminsOnly(): int |
|
| 1774 | + { |
|
| 1775 | + return $this->visibility() > EEM_Ticket::TICKET_VISIBILITY_MEMBERS_ONLY_VALUE |
|
| 1776 | + && $this->visibility() <= EEM_Ticket::TICKET_VISIBILITY_ADMINS_ONLY_VALUE; |
|
| 1777 | + } |
|
| 1778 | + |
|
| 1779 | + |
|
| 1780 | + /** |
|
| 1781 | + * @return int |
|
| 1782 | + * @throws EE_Error |
|
| 1783 | + * @throws ReflectionException |
|
| 1784 | + * @since $VID:$ |
|
| 1785 | + */ |
|
| 1786 | + public function isAdminUiOnly(): int |
|
| 1787 | + { |
|
| 1788 | + return $this->visibility() > EEM_Ticket::TICKET_VISIBILITY_ADMINS_ONLY_VALUE |
|
| 1789 | + && $this->visibility() <= EEM_Ticket::TICKET_VISIBILITY_ADMIN_UI_ONLY_VALUE; |
|
| 1790 | + } |
|
| 1791 | + |
|
| 1792 | + |
|
| 1793 | + /** |
|
| 1794 | + * @param int $visibility |
|
| 1795 | + * @throws EE_Error |
|
| 1796 | + * @throws ReflectionException |
|
| 1797 | + * @since $VID:$ |
|
| 1798 | + */ |
|
| 1799 | + public function set_visibility(int $visibility) |
|
| 1800 | + { |
|
| 1801 | + |
|
| 1802 | + $ticket_visibility_options = $this->_model->ticketVisibilityOptions(); |
|
| 1803 | + $ticket_visibility = -1; |
|
| 1804 | + foreach ($ticket_visibility_options as $ticket_visibility_option) { |
|
| 1805 | + if ($visibility === $ticket_visibility_option) { |
|
| 1806 | + $ticket_visibility = $visibility; |
|
| 1807 | + } |
|
| 1808 | + } |
|
| 1809 | + if ($ticket_visibility === -1) { |
|
| 1810 | + throw new DomainException( |
|
| 1811 | + sprintf( |
|
| 1812 | + esc_html__( |
|
| 1813 | + 'The supplied ticket visibility setting of "%1$s" is not valid. It needs to match one of the keys in the following array:%2$s %3$s ', |
|
| 1814 | + 'event_espresso' |
|
| 1815 | + ), |
|
| 1816 | + $visibility, |
|
| 1817 | + '<br />', |
|
| 1818 | + var_export($ticket_visibility_options, true) |
|
| 1819 | + ) |
|
| 1820 | + ); |
|
| 1821 | + } |
|
| 1822 | + $this->set('TKT_visibility', $ticket_visibility); |
|
| 1823 | + } |
|
| 1824 | + |
|
| 1825 | + |
|
| 1826 | + /******************************************************************* |
|
| 1827 | 1827 | *********************** DEPRECATED METHODS ********************** |
| 1828 | 1828 | *******************************************************************/ |
| 1829 | 1829 | |
| 1830 | 1830 | |
| 1831 | - /** |
|
| 1832 | - * Increments sold by amount passed by $qty AND decrements the reserved count on both this ticket and its |
|
| 1833 | - * associated datetimes. |
|
| 1834 | - * |
|
| 1835 | - * @param int $qty |
|
| 1836 | - * @return void |
|
| 1837 | - * @throws EE_Error |
|
| 1838 | - * @throws InvalidArgumentException |
|
| 1839 | - * @throws InvalidDataTypeException |
|
| 1840 | - * @throws InvalidInterfaceException |
|
| 1841 | - * @throws ReflectionException |
|
| 1842 | - * @deprecated 4.9.80.p |
|
| 1843 | - */ |
|
| 1844 | - public function increase_sold($qty = 1) |
|
| 1845 | - { |
|
| 1846 | - EE_Error::doing_it_wrong( |
|
| 1847 | - __FUNCTION__, |
|
| 1848 | - esc_html__('Please use EE_Ticket::increaseSold() instead', 'event_espresso'), |
|
| 1849 | - '4.9.80.p', |
|
| 1850 | - '5.0.0.p' |
|
| 1851 | - ); |
|
| 1852 | - $this->increaseSold($qty); |
|
| 1853 | - } |
|
| 1854 | - |
|
| 1855 | - |
|
| 1856 | - /** |
|
| 1857 | - * On each datetime related to this ticket, increases its sold count and decreases its reserved count by $qty. |
|
| 1858 | - * |
|
| 1859 | - * @param int $qty positive or negative. Positive means to increase sold counts (and decrease reserved counts), |
|
| 1860 | - * Negative means to decreases old counts (and increase reserved counts). |
|
| 1861 | - * @throws EE_Error |
|
| 1862 | - * @throws InvalidArgumentException |
|
| 1863 | - * @throws InvalidDataTypeException |
|
| 1864 | - * @throws InvalidInterfaceException |
|
| 1865 | - * @throws ReflectionException |
|
| 1866 | - * @deprecated 4.9.80.p |
|
| 1867 | - */ |
|
| 1868 | - protected function _increase_sold_for_datetimes($qty) |
|
| 1869 | - { |
|
| 1870 | - EE_Error::doing_it_wrong( |
|
| 1871 | - __FUNCTION__, |
|
| 1872 | - esc_html__('Please use EE_Ticket::increaseSoldForDatetimes() instead', 'event_espresso'), |
|
| 1873 | - '4.9.80.p', |
|
| 1874 | - '5.0.0.p' |
|
| 1875 | - ); |
|
| 1876 | - $this->increaseSoldForDatetimes($qty); |
|
| 1877 | - } |
|
| 1878 | - |
|
| 1879 | - |
|
| 1880 | - /** |
|
| 1881 | - * Decrements (subtracts) sold by amount passed by $qty on both the ticket and its related datetimes directly in the |
|
| 1882 | - * DB and then updates the model objects. |
|
| 1883 | - * Does not affect the reserved counts. |
|
| 1884 | - * |
|
| 1885 | - * @param int $qty |
|
| 1886 | - * @return void |
|
| 1887 | - * @throws EE_Error |
|
| 1888 | - * @throws InvalidArgumentException |
|
| 1889 | - * @throws InvalidDataTypeException |
|
| 1890 | - * @throws InvalidInterfaceException |
|
| 1891 | - * @throws ReflectionException |
|
| 1892 | - * @deprecated 4.9.80.p |
|
| 1893 | - */ |
|
| 1894 | - public function decrease_sold($qty = 1) |
|
| 1895 | - { |
|
| 1896 | - EE_Error::doing_it_wrong( |
|
| 1897 | - __FUNCTION__, |
|
| 1898 | - esc_html__('Please use EE_Ticket::decreaseSold() instead', 'event_espresso'), |
|
| 1899 | - '4.9.80.p', |
|
| 1900 | - '5.0.0.p' |
|
| 1901 | - ); |
|
| 1902 | - $this->decreaseSold($qty); |
|
| 1903 | - } |
|
| 1904 | - |
|
| 1905 | - |
|
| 1906 | - /** |
|
| 1907 | - * Decreases sold on related datetimes |
|
| 1908 | - * |
|
| 1909 | - * @param int $qty |
|
| 1910 | - * @return void |
|
| 1911 | - * @throws EE_Error |
|
| 1912 | - * @throws InvalidArgumentException |
|
| 1913 | - * @throws InvalidDataTypeException |
|
| 1914 | - * @throws InvalidInterfaceException |
|
| 1915 | - * @throws ReflectionException |
|
| 1916 | - * @deprecated 4.9.80.p |
|
| 1917 | - */ |
|
| 1918 | - protected function _decrease_sold_for_datetimes($qty = 1) |
|
| 1919 | - { |
|
| 1920 | - EE_Error::doing_it_wrong( |
|
| 1921 | - __FUNCTION__, |
|
| 1922 | - esc_html__('Please use EE_Ticket::decreaseSoldForDatetimes() instead', 'event_espresso'), |
|
| 1923 | - '4.9.80.p', |
|
| 1924 | - '5.0.0.p' |
|
| 1925 | - ); |
|
| 1926 | - $this->decreaseSoldForDatetimes($qty); |
|
| 1927 | - } |
|
| 1928 | - |
|
| 1929 | - |
|
| 1930 | - /** |
|
| 1931 | - * Increments reserved by amount passed by $qty, and persists it immediately to the database. |
|
| 1932 | - * |
|
| 1933 | - * @param int $qty |
|
| 1934 | - * @param string $source |
|
| 1935 | - * @return bool whether we successfully reserved the ticket or not. |
|
| 1936 | - * @throws EE_Error |
|
| 1937 | - * @throws InvalidArgumentException |
|
| 1938 | - * @throws ReflectionException |
|
| 1939 | - * @throws InvalidDataTypeException |
|
| 1940 | - * @throws InvalidInterfaceException |
|
| 1941 | - * @deprecated 4.9.80.p |
|
| 1942 | - */ |
|
| 1943 | - public function increase_reserved($qty = 1, $source = 'unknown') |
|
| 1944 | - { |
|
| 1945 | - EE_Error::doing_it_wrong( |
|
| 1946 | - __FUNCTION__, |
|
| 1947 | - esc_html__('Please use EE_Ticket::increaseReserved() instead', 'event_espresso'), |
|
| 1948 | - '4.9.80.p', |
|
| 1949 | - '5.0.0.p' |
|
| 1950 | - ); |
|
| 1951 | - return $this->increaseReserved($qty); |
|
| 1952 | - } |
|
| 1953 | - |
|
| 1954 | - |
|
| 1955 | - /** |
|
| 1956 | - * Increases sold on related datetimes |
|
| 1957 | - * |
|
| 1958 | - * @param int $qty |
|
| 1959 | - * @return boolean indicating success |
|
| 1960 | - * @throws EE_Error |
|
| 1961 | - * @throws InvalidArgumentException |
|
| 1962 | - * @throws InvalidDataTypeException |
|
| 1963 | - * @throws InvalidInterfaceException |
|
| 1964 | - * @throws ReflectionException |
|
| 1965 | - * @deprecated 4.9.80.p |
|
| 1966 | - */ |
|
| 1967 | - protected function _increase_reserved_for_datetimes($qty = 1) |
|
| 1968 | - { |
|
| 1969 | - EE_Error::doing_it_wrong( |
|
| 1970 | - __FUNCTION__, |
|
| 1971 | - esc_html__('Please use EE_Ticket::increaseReservedForDatetimes() instead', 'event_espresso'), |
|
| 1972 | - '4.9.80.p', |
|
| 1973 | - '5.0.0.p' |
|
| 1974 | - ); |
|
| 1975 | - return $this->increaseReservedForDatetimes($qty); |
|
| 1976 | - } |
|
| 1977 | - |
|
| 1978 | - |
|
| 1979 | - /** |
|
| 1980 | - * Decrements (subtracts) reserved by amount passed by $qty, and persists it immediately to the database. |
|
| 1981 | - * |
|
| 1982 | - * @param int $qty |
|
| 1983 | - * @param bool $adjust_datetimes |
|
| 1984 | - * @param string $source |
|
| 1985 | - * @return void |
|
| 1986 | - * @throws EE_Error |
|
| 1987 | - * @throws InvalidArgumentException |
|
| 1988 | - * @throws ReflectionException |
|
| 1989 | - * @throws InvalidDataTypeException |
|
| 1990 | - * @throws InvalidInterfaceException |
|
| 1991 | - * @deprecated 4.9.80.p |
|
| 1992 | - */ |
|
| 1993 | - public function decrease_reserved($qty = 1, $adjust_datetimes = true, $source = 'unknown') |
|
| 1994 | - { |
|
| 1995 | - EE_Error::doing_it_wrong( |
|
| 1996 | - __FUNCTION__, |
|
| 1997 | - esc_html__('Please use EE_Ticket::decreaseReserved() instead', 'event_espresso'), |
|
| 1998 | - '4.9.80.p', |
|
| 1999 | - '5.0.0.p' |
|
| 2000 | - ); |
|
| 2001 | - $this->decreaseReserved($qty); |
|
| 2002 | - } |
|
| 2003 | - |
|
| 2004 | - |
|
| 2005 | - /** |
|
| 2006 | - * Decreases reserved on related datetimes |
|
| 2007 | - * |
|
| 2008 | - * @param int $qty |
|
| 2009 | - * @return void |
|
| 2010 | - * @throws EE_Error |
|
| 2011 | - * @throws InvalidArgumentException |
|
| 2012 | - * @throws ReflectionException |
|
| 2013 | - * @throws InvalidDataTypeException |
|
| 2014 | - * @throws InvalidInterfaceException |
|
| 2015 | - * @deprecated 4.9.80.p |
|
| 2016 | - */ |
|
| 2017 | - protected function _decrease_reserved_for_datetimes($qty = 1) |
|
| 2018 | - { |
|
| 2019 | - EE_Error::doing_it_wrong( |
|
| 2020 | - __FUNCTION__, |
|
| 2021 | - esc_html__('Please use EE_Ticket::decreaseReservedForDatetimes() instead', 'event_espresso'), |
|
| 2022 | - '4.9.80.p', |
|
| 2023 | - '5.0.0.p' |
|
| 2024 | - ); |
|
| 2025 | - $this->decreaseReservedForDatetimes($qty); |
|
| 2026 | - } |
|
| 1831 | + /** |
|
| 1832 | + * Increments sold by amount passed by $qty AND decrements the reserved count on both this ticket and its |
|
| 1833 | + * associated datetimes. |
|
| 1834 | + * |
|
| 1835 | + * @param int $qty |
|
| 1836 | + * @return void |
|
| 1837 | + * @throws EE_Error |
|
| 1838 | + * @throws InvalidArgumentException |
|
| 1839 | + * @throws InvalidDataTypeException |
|
| 1840 | + * @throws InvalidInterfaceException |
|
| 1841 | + * @throws ReflectionException |
|
| 1842 | + * @deprecated 4.9.80.p |
|
| 1843 | + */ |
|
| 1844 | + public function increase_sold($qty = 1) |
|
| 1845 | + { |
|
| 1846 | + EE_Error::doing_it_wrong( |
|
| 1847 | + __FUNCTION__, |
|
| 1848 | + esc_html__('Please use EE_Ticket::increaseSold() instead', 'event_espresso'), |
|
| 1849 | + '4.9.80.p', |
|
| 1850 | + '5.0.0.p' |
|
| 1851 | + ); |
|
| 1852 | + $this->increaseSold($qty); |
|
| 1853 | + } |
|
| 1854 | + |
|
| 1855 | + |
|
| 1856 | + /** |
|
| 1857 | + * On each datetime related to this ticket, increases its sold count and decreases its reserved count by $qty. |
|
| 1858 | + * |
|
| 1859 | + * @param int $qty positive or negative. Positive means to increase sold counts (and decrease reserved counts), |
|
| 1860 | + * Negative means to decreases old counts (and increase reserved counts). |
|
| 1861 | + * @throws EE_Error |
|
| 1862 | + * @throws InvalidArgumentException |
|
| 1863 | + * @throws InvalidDataTypeException |
|
| 1864 | + * @throws InvalidInterfaceException |
|
| 1865 | + * @throws ReflectionException |
|
| 1866 | + * @deprecated 4.9.80.p |
|
| 1867 | + */ |
|
| 1868 | + protected function _increase_sold_for_datetimes($qty) |
|
| 1869 | + { |
|
| 1870 | + EE_Error::doing_it_wrong( |
|
| 1871 | + __FUNCTION__, |
|
| 1872 | + esc_html__('Please use EE_Ticket::increaseSoldForDatetimes() instead', 'event_espresso'), |
|
| 1873 | + '4.9.80.p', |
|
| 1874 | + '5.0.0.p' |
|
| 1875 | + ); |
|
| 1876 | + $this->increaseSoldForDatetimes($qty); |
|
| 1877 | + } |
|
| 1878 | + |
|
| 1879 | + |
|
| 1880 | + /** |
|
| 1881 | + * Decrements (subtracts) sold by amount passed by $qty on both the ticket and its related datetimes directly in the |
|
| 1882 | + * DB and then updates the model objects. |
|
| 1883 | + * Does not affect the reserved counts. |
|
| 1884 | + * |
|
| 1885 | + * @param int $qty |
|
| 1886 | + * @return void |
|
| 1887 | + * @throws EE_Error |
|
| 1888 | + * @throws InvalidArgumentException |
|
| 1889 | + * @throws InvalidDataTypeException |
|
| 1890 | + * @throws InvalidInterfaceException |
|
| 1891 | + * @throws ReflectionException |
|
| 1892 | + * @deprecated 4.9.80.p |
|
| 1893 | + */ |
|
| 1894 | + public function decrease_sold($qty = 1) |
|
| 1895 | + { |
|
| 1896 | + EE_Error::doing_it_wrong( |
|
| 1897 | + __FUNCTION__, |
|
| 1898 | + esc_html__('Please use EE_Ticket::decreaseSold() instead', 'event_espresso'), |
|
| 1899 | + '4.9.80.p', |
|
| 1900 | + '5.0.0.p' |
|
| 1901 | + ); |
|
| 1902 | + $this->decreaseSold($qty); |
|
| 1903 | + } |
|
| 1904 | + |
|
| 1905 | + |
|
| 1906 | + /** |
|
| 1907 | + * Decreases sold on related datetimes |
|
| 1908 | + * |
|
| 1909 | + * @param int $qty |
|
| 1910 | + * @return void |
|
| 1911 | + * @throws EE_Error |
|
| 1912 | + * @throws InvalidArgumentException |
|
| 1913 | + * @throws InvalidDataTypeException |
|
| 1914 | + * @throws InvalidInterfaceException |
|
| 1915 | + * @throws ReflectionException |
|
| 1916 | + * @deprecated 4.9.80.p |
|
| 1917 | + */ |
|
| 1918 | + protected function _decrease_sold_for_datetimes($qty = 1) |
|
| 1919 | + { |
|
| 1920 | + EE_Error::doing_it_wrong( |
|
| 1921 | + __FUNCTION__, |
|
| 1922 | + esc_html__('Please use EE_Ticket::decreaseSoldForDatetimes() instead', 'event_espresso'), |
|
| 1923 | + '4.9.80.p', |
|
| 1924 | + '5.0.0.p' |
|
| 1925 | + ); |
|
| 1926 | + $this->decreaseSoldForDatetimes($qty); |
|
| 1927 | + } |
|
| 1928 | + |
|
| 1929 | + |
|
| 1930 | + /** |
|
| 1931 | + * Increments reserved by amount passed by $qty, and persists it immediately to the database. |
|
| 1932 | + * |
|
| 1933 | + * @param int $qty |
|
| 1934 | + * @param string $source |
|
| 1935 | + * @return bool whether we successfully reserved the ticket or not. |
|
| 1936 | + * @throws EE_Error |
|
| 1937 | + * @throws InvalidArgumentException |
|
| 1938 | + * @throws ReflectionException |
|
| 1939 | + * @throws InvalidDataTypeException |
|
| 1940 | + * @throws InvalidInterfaceException |
|
| 1941 | + * @deprecated 4.9.80.p |
|
| 1942 | + */ |
|
| 1943 | + public function increase_reserved($qty = 1, $source = 'unknown') |
|
| 1944 | + { |
|
| 1945 | + EE_Error::doing_it_wrong( |
|
| 1946 | + __FUNCTION__, |
|
| 1947 | + esc_html__('Please use EE_Ticket::increaseReserved() instead', 'event_espresso'), |
|
| 1948 | + '4.9.80.p', |
|
| 1949 | + '5.0.0.p' |
|
| 1950 | + ); |
|
| 1951 | + return $this->increaseReserved($qty); |
|
| 1952 | + } |
|
| 1953 | + |
|
| 1954 | + |
|
| 1955 | + /** |
|
| 1956 | + * Increases sold on related datetimes |
|
| 1957 | + * |
|
| 1958 | + * @param int $qty |
|
| 1959 | + * @return boolean indicating success |
|
| 1960 | + * @throws EE_Error |
|
| 1961 | + * @throws InvalidArgumentException |
|
| 1962 | + * @throws InvalidDataTypeException |
|
| 1963 | + * @throws InvalidInterfaceException |
|
| 1964 | + * @throws ReflectionException |
|
| 1965 | + * @deprecated 4.9.80.p |
|
| 1966 | + */ |
|
| 1967 | + protected function _increase_reserved_for_datetimes($qty = 1) |
|
| 1968 | + { |
|
| 1969 | + EE_Error::doing_it_wrong( |
|
| 1970 | + __FUNCTION__, |
|
| 1971 | + esc_html__('Please use EE_Ticket::increaseReservedForDatetimes() instead', 'event_espresso'), |
|
| 1972 | + '4.9.80.p', |
|
| 1973 | + '5.0.0.p' |
|
| 1974 | + ); |
|
| 1975 | + return $this->increaseReservedForDatetimes($qty); |
|
| 1976 | + } |
|
| 1977 | + |
|
| 1978 | + |
|
| 1979 | + /** |
|
| 1980 | + * Decrements (subtracts) reserved by amount passed by $qty, and persists it immediately to the database. |
|
| 1981 | + * |
|
| 1982 | + * @param int $qty |
|
| 1983 | + * @param bool $adjust_datetimes |
|
| 1984 | + * @param string $source |
|
| 1985 | + * @return void |
|
| 1986 | + * @throws EE_Error |
|
| 1987 | + * @throws InvalidArgumentException |
|
| 1988 | + * @throws ReflectionException |
|
| 1989 | + * @throws InvalidDataTypeException |
|
| 1990 | + * @throws InvalidInterfaceException |
|
| 1991 | + * @deprecated 4.9.80.p |
|
| 1992 | + */ |
|
| 1993 | + public function decrease_reserved($qty = 1, $adjust_datetimes = true, $source = 'unknown') |
|
| 1994 | + { |
|
| 1995 | + EE_Error::doing_it_wrong( |
|
| 1996 | + __FUNCTION__, |
|
| 1997 | + esc_html__('Please use EE_Ticket::decreaseReserved() instead', 'event_espresso'), |
|
| 1998 | + '4.9.80.p', |
|
| 1999 | + '5.0.0.p' |
|
| 2000 | + ); |
|
| 2001 | + $this->decreaseReserved($qty); |
|
| 2002 | + } |
|
| 2003 | + |
|
| 2004 | + |
|
| 2005 | + /** |
|
| 2006 | + * Decreases reserved on related datetimes |
|
| 2007 | + * |
|
| 2008 | + * @param int $qty |
|
| 2009 | + * @return void |
|
| 2010 | + * @throws EE_Error |
|
| 2011 | + * @throws InvalidArgumentException |
|
| 2012 | + * @throws ReflectionException |
|
| 2013 | + * @throws InvalidDataTypeException |
|
| 2014 | + * @throws InvalidInterfaceException |
|
| 2015 | + * @deprecated 4.9.80.p |
|
| 2016 | + */ |
|
| 2017 | + protected function _decrease_reserved_for_datetimes($qty = 1) |
|
| 2018 | + { |
|
| 2019 | + EE_Error::doing_it_wrong( |
|
| 2020 | + __FUNCTION__, |
|
| 2021 | + esc_html__('Please use EE_Ticket::decreaseReservedForDatetimes() instead', 'event_espresso'), |
|
| 2022 | + '4.9.80.p', |
|
| 2023 | + '5.0.0.p' |
|
| 2024 | + ); |
|
| 2025 | + $this->decreaseReservedForDatetimes($qty); |
|
| 2026 | + } |
|
| 2027 | 2027 | } |
@@ -22,201 +22,201 @@ |
||
| 22 | 22 | { |
| 23 | 23 | |
| 24 | 24 | |
| 25 | - protected function _init_props() |
|
| 26 | - { |
|
| 27 | - $this->label = __('Line Item List Shortcodes', 'event_espresso'); |
|
| 28 | - $this->description = __('All shortcodes specific to line item lists', 'event_espresso'); |
|
| 29 | - $this->_shortcodes = array( |
|
| 30 | - '[TICKET_LINE_ITEM_LIST]' => __('Outputs a list of ticket line items.', 'event_espresso'), |
|
| 31 | - '[TAX_LINE_ITEM_LIST]' => __('Outputs a list of tax line items.', 'event_espresso'), |
|
| 32 | - '[ADDITIONAL_LINE_ITEM_LIST]' => __( |
|
| 33 | - 'Outputs a list of additional line items (other charges or discounts)', |
|
| 34 | - 'event_espresso' |
|
| 35 | - ), |
|
| 36 | - '[PRICE_MODIFIER_LINE_ITEM_LIST]' => __('Outputs a list of price modifier line items', 'event_espresso'), |
|
| 37 | - ); |
|
| 38 | - } |
|
| 39 | - |
|
| 40 | - |
|
| 41 | - protected function _parser($shortcode) |
|
| 42 | - { |
|
| 43 | - |
|
| 44 | - switch ($shortcode) { |
|
| 45 | - case '[TICKET_LINE_ITEM_LIST]': |
|
| 46 | - return $this->_get_ticket_line_item_list(); |
|
| 47 | - |
|
| 48 | - case '[TAX_LINE_ITEM_LIST]': |
|
| 49 | - return $this->_get_tax_line_item_list(); |
|
| 50 | - |
|
| 51 | - case '[PRICE_MODIFIER_LINE_ITEM_LIST]': |
|
| 52 | - return $this->_get_price_mod_line_item_list(); |
|
| 53 | - |
|
| 54 | - case '[ADDITIONAL_LINE_ITEM_LIST]': |
|
| 55 | - return $this->_get_additional_line_item_list(); |
|
| 56 | - |
|
| 57 | - default: |
|
| 58 | - return ''; |
|
| 59 | - } |
|
| 60 | - } |
|
| 61 | - |
|
| 62 | - |
|
| 63 | - /** |
|
| 64 | - * verify incoming data contains what is needed for retrieving and parsing each ticket line item for an event. |
|
| 65 | - * |
|
| 66 | - * @since 4.5.0 |
|
| 67 | - * |
|
| 68 | - * @return string parsed ticket line item list. |
|
| 69 | - */ |
|
| 70 | - private function _get_ticket_line_item_list() |
|
| 71 | - { |
|
| 72 | - $this->_validate_list_requirements(); |
|
| 73 | - |
|
| 74 | - if (! $this->_data['data'] instanceof EE_Ticket) { |
|
| 75 | - return ''; |
|
| 76 | - } |
|
| 77 | - |
|
| 78 | - $valid_shortcodes = array('line_item', 'line_item_list', 'ticket'); |
|
| 79 | - |
|
| 80 | - $ticket = $this->_data['data']; |
|
| 81 | - $templates = $this->_extra_data['template']; |
|
| 82 | - $addressee_obj = $this->_extra_data['data']; |
|
| 83 | - |
|
| 84 | - // made it here so we have an EE_Ticket, so we should have what we need. |
|
| 85 | - $ticket_line_item = isset($addressee_obj->tickets[ $ticket->ID() ]['line_item']) |
|
| 86 | - ? $addressee_obj->tickets[ $ticket->ID() ]['line_item'] : null; |
|
| 87 | - $sub_line_items = isset($addressee_obj->tickets[ $ticket->ID() ]['sub_line_items']) |
|
| 88 | - ? $addressee_obj->tickets[ $ticket->ID() ]['sub_line_items'] : array(); |
|
| 89 | - |
|
| 90 | - $template = count($sub_line_items) < 2 ? $templates['ticket_line_item_no_pms'] |
|
| 91 | - : $templates['ticket_line_item_pms']; |
|
| 92 | - |
|
| 93 | - if (empty($ticket_line_item) || empty($sub_line_items)) { |
|
| 94 | - return ''; |
|
| 95 | - } |
|
| 96 | - |
|
| 97 | - // now we just return the appropriate template parsed for each ticket. |
|
| 98 | - return $this->_shortcode_helper->parse_line_item_list_template( |
|
| 99 | - $template, |
|
| 100 | - $ticket_line_item, |
|
| 101 | - $valid_shortcodes, |
|
| 102 | - $this->_extra_data |
|
| 103 | - ); |
|
| 104 | - } |
|
| 105 | - |
|
| 106 | - |
|
| 107 | - /** |
|
| 108 | - * Verify incoming data contains what is needed for retrieving and parsing each tax line item for a transaction. |
|
| 109 | - * |
|
| 110 | - * @return string parsed tax line item list. |
|
| 111 | - * @throws EE_Error |
|
| 112 | - * @since 4.5.0 |
|
| 113 | - */ |
|
| 114 | - private function _get_tax_line_item_list() |
|
| 115 | - { |
|
| 116 | - /** @var EE_Admin_Config $admin_config */ |
|
| 117 | - $admin_config = LoaderFactory::getShared(EE_Admin_Config::class); |
|
| 118 | - if ($admin_config->useAdvancedEditor()) { |
|
| 119 | - return ''; |
|
| 120 | - } |
|
| 121 | - $this->_validate_list_requirements(); |
|
| 122 | - |
|
| 123 | - if (! $this->_data['data'] instanceof EE_Messages_Addressee) { |
|
| 124 | - return ''; |
|
| 125 | - } |
|
| 126 | - |
|
| 127 | - // made it here so we're good to go. |
|
| 128 | - $valid_shortcodes = array('line_item'); |
|
| 129 | - $templates = $this->_data['template']; |
|
| 130 | - |
|
| 131 | - $tax_line_items = $this->_data['data']->tax_line_items; |
|
| 132 | - $line_item_list = ''; |
|
| 133 | - foreach ($tax_line_items as $line_item) { |
|
| 134 | - $line_item_list .= $this->_shortcode_helper->parse_line_item_list_template( |
|
| 135 | - $templates['tax_line_item_list'], |
|
| 136 | - $line_item, |
|
| 137 | - $valid_shortcodes, |
|
| 138 | - $this->_extra_data |
|
| 139 | - ); |
|
| 140 | - } |
|
| 141 | - |
|
| 142 | - return $line_item_list; |
|
| 143 | - } |
|
| 144 | - |
|
| 145 | - /** |
|
| 146 | - * Verify incoming data contains what is needed for retrieving and parsing each other line item for a transaction. |
|
| 147 | - * |
|
| 148 | - * @since 4.5.0 |
|
| 149 | - * |
|
| 150 | - * @return string parsed other line item list. |
|
| 151 | - */ |
|
| 152 | - private function _get_additional_line_item_list() |
|
| 153 | - { |
|
| 154 | - |
|
| 155 | - $this->_validate_list_requirements(); |
|
| 156 | - |
|
| 157 | - if (! $this->_data['data'] instanceof EE_Messages_Addressee) { |
|
| 158 | - return ''; |
|
| 159 | - } |
|
| 160 | - |
|
| 161 | - // made it here so we're good to go. |
|
| 162 | - $valid_shortcodes = array('line_item'); |
|
| 163 | - $templates = $this->_data['template']; |
|
| 164 | - |
|
| 165 | - $additional_line_items = $this->_data['data']->additional_line_items; |
|
| 166 | - $line_item_list = ''; |
|
| 167 | - foreach ($additional_line_items as $line_item) { |
|
| 168 | - $line_item_list .= $this->_shortcode_helper->parse_line_item_list_template( |
|
| 169 | - $templates['additional_line_item_list'], |
|
| 170 | - $line_item, |
|
| 171 | - $valid_shortcodes, |
|
| 172 | - $this->_extra_data |
|
| 173 | - ); |
|
| 174 | - } |
|
| 175 | - |
|
| 176 | - |
|
| 177 | - return $line_item_list; |
|
| 178 | - } |
|
| 179 | - |
|
| 180 | - |
|
| 181 | - /** |
|
| 182 | - * Verify incoming data contains what is needed for retrieving and parsing each price modifier line item for a |
|
| 183 | - * parent ticket line item. |
|
| 184 | - * |
|
| 185 | - * @since 4.5.0 |
|
| 186 | - * |
|
| 187 | - * @return string parsed price modifier line item list. |
|
| 188 | - */ |
|
| 189 | - private function _get_price_mod_line_item_list() |
|
| 190 | - { |
|
| 191 | - $this->_validate_list_requirements(); |
|
| 192 | - |
|
| 193 | - if (! $this->_data['data'] instanceof EE_Line_Item) { |
|
| 194 | - return ''; |
|
| 195 | - } |
|
| 196 | - |
|
| 197 | - // made it here so we're good to go. |
|
| 198 | - $main_line_item = $this->_data['data']; |
|
| 199 | - $templates = $this->_extra_data['template']; |
|
| 200 | - $addressee_obj = $this->_extra_data['data']; |
|
| 201 | - |
|
| 202 | - $valid_shortcodes = array('line_item'); |
|
| 203 | - |
|
| 204 | - $main_line_item_id = $main_line_item->ID(); |
|
| 205 | - |
|
| 206 | - $price_mod_line_items = ! empty($addressee_obj->line_items_with_children[ $main_line_item_id ]['children']) |
|
| 207 | - ? $addressee_obj->line_items_with_children[ $main_line_item_id ]['children'] : array(); |
|
| 208 | - |
|
| 209 | - $line_item_list = ''; |
|
| 210 | - |
|
| 211 | - foreach ($price_mod_line_items as $line_item) { |
|
| 212 | - $line_item_list .= $this->_shortcode_helper->parse_line_item_list_template( |
|
| 213 | - $templates['price_modifier_line_item_list'], |
|
| 214 | - $line_item, |
|
| 215 | - $valid_shortcodes, |
|
| 216 | - $this->_extra_data |
|
| 217 | - ); |
|
| 218 | - } |
|
| 219 | - |
|
| 220 | - return $line_item_list; |
|
| 221 | - } |
|
| 25 | + protected function _init_props() |
|
| 26 | + { |
|
| 27 | + $this->label = __('Line Item List Shortcodes', 'event_espresso'); |
|
| 28 | + $this->description = __('All shortcodes specific to line item lists', 'event_espresso'); |
|
| 29 | + $this->_shortcodes = array( |
|
| 30 | + '[TICKET_LINE_ITEM_LIST]' => __('Outputs a list of ticket line items.', 'event_espresso'), |
|
| 31 | + '[TAX_LINE_ITEM_LIST]' => __('Outputs a list of tax line items.', 'event_espresso'), |
|
| 32 | + '[ADDITIONAL_LINE_ITEM_LIST]' => __( |
|
| 33 | + 'Outputs a list of additional line items (other charges or discounts)', |
|
| 34 | + 'event_espresso' |
|
| 35 | + ), |
|
| 36 | + '[PRICE_MODIFIER_LINE_ITEM_LIST]' => __('Outputs a list of price modifier line items', 'event_espresso'), |
|
| 37 | + ); |
|
| 38 | + } |
|
| 39 | + |
|
| 40 | + |
|
| 41 | + protected function _parser($shortcode) |
|
| 42 | + { |
|
| 43 | + |
|
| 44 | + switch ($shortcode) { |
|
| 45 | + case '[TICKET_LINE_ITEM_LIST]': |
|
| 46 | + return $this->_get_ticket_line_item_list(); |
|
| 47 | + |
|
| 48 | + case '[TAX_LINE_ITEM_LIST]': |
|
| 49 | + return $this->_get_tax_line_item_list(); |
|
| 50 | + |
|
| 51 | + case '[PRICE_MODIFIER_LINE_ITEM_LIST]': |
|
| 52 | + return $this->_get_price_mod_line_item_list(); |
|
| 53 | + |
|
| 54 | + case '[ADDITIONAL_LINE_ITEM_LIST]': |
|
| 55 | + return $this->_get_additional_line_item_list(); |
|
| 56 | + |
|
| 57 | + default: |
|
| 58 | + return ''; |
|
| 59 | + } |
|
| 60 | + } |
|
| 61 | + |
|
| 62 | + |
|
| 63 | + /** |
|
| 64 | + * verify incoming data contains what is needed for retrieving and parsing each ticket line item for an event. |
|
| 65 | + * |
|
| 66 | + * @since 4.5.0 |
|
| 67 | + * |
|
| 68 | + * @return string parsed ticket line item list. |
|
| 69 | + */ |
|
| 70 | + private function _get_ticket_line_item_list() |
|
| 71 | + { |
|
| 72 | + $this->_validate_list_requirements(); |
|
| 73 | + |
|
| 74 | + if (! $this->_data['data'] instanceof EE_Ticket) { |
|
| 75 | + return ''; |
|
| 76 | + } |
|
| 77 | + |
|
| 78 | + $valid_shortcodes = array('line_item', 'line_item_list', 'ticket'); |
|
| 79 | + |
|
| 80 | + $ticket = $this->_data['data']; |
|
| 81 | + $templates = $this->_extra_data['template']; |
|
| 82 | + $addressee_obj = $this->_extra_data['data']; |
|
| 83 | + |
|
| 84 | + // made it here so we have an EE_Ticket, so we should have what we need. |
|
| 85 | + $ticket_line_item = isset($addressee_obj->tickets[ $ticket->ID() ]['line_item']) |
|
| 86 | + ? $addressee_obj->tickets[ $ticket->ID() ]['line_item'] : null; |
|
| 87 | + $sub_line_items = isset($addressee_obj->tickets[ $ticket->ID() ]['sub_line_items']) |
|
| 88 | + ? $addressee_obj->tickets[ $ticket->ID() ]['sub_line_items'] : array(); |
|
| 89 | + |
|
| 90 | + $template = count($sub_line_items) < 2 ? $templates['ticket_line_item_no_pms'] |
|
| 91 | + : $templates['ticket_line_item_pms']; |
|
| 92 | + |
|
| 93 | + if (empty($ticket_line_item) || empty($sub_line_items)) { |
|
| 94 | + return ''; |
|
| 95 | + } |
|
| 96 | + |
|
| 97 | + // now we just return the appropriate template parsed for each ticket. |
|
| 98 | + return $this->_shortcode_helper->parse_line_item_list_template( |
|
| 99 | + $template, |
|
| 100 | + $ticket_line_item, |
|
| 101 | + $valid_shortcodes, |
|
| 102 | + $this->_extra_data |
|
| 103 | + ); |
|
| 104 | + } |
|
| 105 | + |
|
| 106 | + |
|
| 107 | + /** |
|
| 108 | + * Verify incoming data contains what is needed for retrieving and parsing each tax line item for a transaction. |
|
| 109 | + * |
|
| 110 | + * @return string parsed tax line item list. |
|
| 111 | + * @throws EE_Error |
|
| 112 | + * @since 4.5.0 |
|
| 113 | + */ |
|
| 114 | + private function _get_tax_line_item_list() |
|
| 115 | + { |
|
| 116 | + /** @var EE_Admin_Config $admin_config */ |
|
| 117 | + $admin_config = LoaderFactory::getShared(EE_Admin_Config::class); |
|
| 118 | + if ($admin_config->useAdvancedEditor()) { |
|
| 119 | + return ''; |
|
| 120 | + } |
|
| 121 | + $this->_validate_list_requirements(); |
|
| 122 | + |
|
| 123 | + if (! $this->_data['data'] instanceof EE_Messages_Addressee) { |
|
| 124 | + return ''; |
|
| 125 | + } |
|
| 126 | + |
|
| 127 | + // made it here so we're good to go. |
|
| 128 | + $valid_shortcodes = array('line_item'); |
|
| 129 | + $templates = $this->_data['template']; |
|
| 130 | + |
|
| 131 | + $tax_line_items = $this->_data['data']->tax_line_items; |
|
| 132 | + $line_item_list = ''; |
|
| 133 | + foreach ($tax_line_items as $line_item) { |
|
| 134 | + $line_item_list .= $this->_shortcode_helper->parse_line_item_list_template( |
|
| 135 | + $templates['tax_line_item_list'], |
|
| 136 | + $line_item, |
|
| 137 | + $valid_shortcodes, |
|
| 138 | + $this->_extra_data |
|
| 139 | + ); |
|
| 140 | + } |
|
| 141 | + |
|
| 142 | + return $line_item_list; |
|
| 143 | + } |
|
| 144 | + |
|
| 145 | + /** |
|
| 146 | + * Verify incoming data contains what is needed for retrieving and parsing each other line item for a transaction. |
|
| 147 | + * |
|
| 148 | + * @since 4.5.0 |
|
| 149 | + * |
|
| 150 | + * @return string parsed other line item list. |
|
| 151 | + */ |
|
| 152 | + private function _get_additional_line_item_list() |
|
| 153 | + { |
|
| 154 | + |
|
| 155 | + $this->_validate_list_requirements(); |
|
| 156 | + |
|
| 157 | + if (! $this->_data['data'] instanceof EE_Messages_Addressee) { |
|
| 158 | + return ''; |
|
| 159 | + } |
|
| 160 | + |
|
| 161 | + // made it here so we're good to go. |
|
| 162 | + $valid_shortcodes = array('line_item'); |
|
| 163 | + $templates = $this->_data['template']; |
|
| 164 | + |
|
| 165 | + $additional_line_items = $this->_data['data']->additional_line_items; |
|
| 166 | + $line_item_list = ''; |
|
| 167 | + foreach ($additional_line_items as $line_item) { |
|
| 168 | + $line_item_list .= $this->_shortcode_helper->parse_line_item_list_template( |
|
| 169 | + $templates['additional_line_item_list'], |
|
| 170 | + $line_item, |
|
| 171 | + $valid_shortcodes, |
|
| 172 | + $this->_extra_data |
|
| 173 | + ); |
|
| 174 | + } |
|
| 175 | + |
|
| 176 | + |
|
| 177 | + return $line_item_list; |
|
| 178 | + } |
|
| 179 | + |
|
| 180 | + |
|
| 181 | + /** |
|
| 182 | + * Verify incoming data contains what is needed for retrieving and parsing each price modifier line item for a |
|
| 183 | + * parent ticket line item. |
|
| 184 | + * |
|
| 185 | + * @since 4.5.0 |
|
| 186 | + * |
|
| 187 | + * @return string parsed price modifier line item list. |
|
| 188 | + */ |
|
| 189 | + private function _get_price_mod_line_item_list() |
|
| 190 | + { |
|
| 191 | + $this->_validate_list_requirements(); |
|
| 192 | + |
|
| 193 | + if (! $this->_data['data'] instanceof EE_Line_Item) { |
|
| 194 | + return ''; |
|
| 195 | + } |
|
| 196 | + |
|
| 197 | + // made it here so we're good to go. |
|
| 198 | + $main_line_item = $this->_data['data']; |
|
| 199 | + $templates = $this->_extra_data['template']; |
|
| 200 | + $addressee_obj = $this->_extra_data['data']; |
|
| 201 | + |
|
| 202 | + $valid_shortcodes = array('line_item'); |
|
| 203 | + |
|
| 204 | + $main_line_item_id = $main_line_item->ID(); |
|
| 205 | + |
|
| 206 | + $price_mod_line_items = ! empty($addressee_obj->line_items_with_children[ $main_line_item_id ]['children']) |
|
| 207 | + ? $addressee_obj->line_items_with_children[ $main_line_item_id ]['children'] : array(); |
|
| 208 | + |
|
| 209 | + $line_item_list = ''; |
|
| 210 | + |
|
| 211 | + foreach ($price_mod_line_items as $line_item) { |
|
| 212 | + $line_item_list .= $this->_shortcode_helper->parse_line_item_list_template( |
|
| 213 | + $templates['price_modifier_line_item_list'], |
|
| 214 | + $line_item, |
|
| 215 | + $valid_shortcodes, |
|
| 216 | + $this->_extra_data |
|
| 217 | + ); |
|
| 218 | + } |
|
| 219 | + |
|
| 220 | + return $line_item_list; |
|
| 221 | + } |
|
| 222 | 222 | } |
@@ -71,7 +71,7 @@ discard block |
||
| 71 | 71 | { |
| 72 | 72 | $this->_validate_list_requirements(); |
| 73 | 73 | |
| 74 | - if (! $this->_data['data'] instanceof EE_Ticket) { |
|
| 74 | + if ( ! $this->_data['data'] instanceof EE_Ticket) { |
|
| 75 | 75 | return ''; |
| 76 | 76 | } |
| 77 | 77 | |
@@ -82,10 +82,10 @@ discard block |
||
| 82 | 82 | $addressee_obj = $this->_extra_data['data']; |
| 83 | 83 | |
| 84 | 84 | // made it here so we have an EE_Ticket, so we should have what we need. |
| 85 | - $ticket_line_item = isset($addressee_obj->tickets[ $ticket->ID() ]['line_item']) |
|
| 86 | - ? $addressee_obj->tickets[ $ticket->ID() ]['line_item'] : null; |
|
| 87 | - $sub_line_items = isset($addressee_obj->tickets[ $ticket->ID() ]['sub_line_items']) |
|
| 88 | - ? $addressee_obj->tickets[ $ticket->ID() ]['sub_line_items'] : array(); |
|
| 85 | + $ticket_line_item = isset($addressee_obj->tickets[$ticket->ID()]['line_item']) |
|
| 86 | + ? $addressee_obj->tickets[$ticket->ID()]['line_item'] : null; |
|
| 87 | + $sub_line_items = isset($addressee_obj->tickets[$ticket->ID()]['sub_line_items']) |
|
| 88 | + ? $addressee_obj->tickets[$ticket->ID()]['sub_line_items'] : array(); |
|
| 89 | 89 | |
| 90 | 90 | $template = count($sub_line_items) < 2 ? $templates['ticket_line_item_no_pms'] |
| 91 | 91 | : $templates['ticket_line_item_pms']; |
@@ -120,7 +120,7 @@ discard block |
||
| 120 | 120 | } |
| 121 | 121 | $this->_validate_list_requirements(); |
| 122 | 122 | |
| 123 | - if (! $this->_data['data'] instanceof EE_Messages_Addressee) { |
|
| 123 | + if ( ! $this->_data['data'] instanceof EE_Messages_Addressee) { |
|
| 124 | 124 | return ''; |
| 125 | 125 | } |
| 126 | 126 | |
@@ -154,7 +154,7 @@ discard block |
||
| 154 | 154 | |
| 155 | 155 | $this->_validate_list_requirements(); |
| 156 | 156 | |
| 157 | - if (! $this->_data['data'] instanceof EE_Messages_Addressee) { |
|
| 157 | + if ( ! $this->_data['data'] instanceof EE_Messages_Addressee) { |
|
| 158 | 158 | return ''; |
| 159 | 159 | } |
| 160 | 160 | |
@@ -190,7 +190,7 @@ discard block |
||
| 190 | 190 | { |
| 191 | 191 | $this->_validate_list_requirements(); |
| 192 | 192 | |
| 193 | - if (! $this->_data['data'] instanceof EE_Line_Item) { |
|
| 193 | + if ( ! $this->_data['data'] instanceof EE_Line_Item) { |
|
| 194 | 194 | return ''; |
| 195 | 195 | } |
| 196 | 196 | |
@@ -203,8 +203,8 @@ discard block |
||
| 203 | 203 | |
| 204 | 204 | $main_line_item_id = $main_line_item->ID(); |
| 205 | 205 | |
| 206 | - $price_mod_line_items = ! empty($addressee_obj->line_items_with_children[ $main_line_item_id ]['children']) |
|
| 207 | - ? $addressee_obj->line_items_with_children[ $main_line_item_id ]['children'] : array(); |
|
| 206 | + $price_mod_line_items = ! empty($addressee_obj->line_items_with_children[$main_line_item_id]['children']) |
|
| 207 | + ? $addressee_obj->line_items_with_children[$main_line_item_id]['children'] : array(); |
|
| 208 | 208 | |
| 209 | 209 | $line_item_list = ''; |
| 210 | 210 | |
@@ -12,663 +12,663 @@ |
||
| 12 | 12 | class EE_SPCO_Line_Item_Display_Strategy implements EEI_Line_Item_Display |
| 13 | 13 | { |
| 14 | 14 | |
| 15 | - /** |
|
| 16 | - * array of events |
|
| 17 | - * |
|
| 18 | - * @type EE_Line_Item[] $_events |
|
| 19 | - */ |
|
| 20 | - private $_events = array(); |
|
| 21 | - |
|
| 22 | - /** |
|
| 23 | - * whether to display the taxes row or not |
|
| 24 | - * |
|
| 25 | - * @type bool $_show_taxes |
|
| 26 | - */ |
|
| 27 | - private $_show_taxes = false; |
|
| 28 | - |
|
| 29 | - /** |
|
| 30 | - * html for any tax rows |
|
| 31 | - * |
|
| 32 | - * @type string $_show_taxes |
|
| 33 | - */ |
|
| 34 | - private $_taxes_html = ''; |
|
| 35 | - |
|
| 36 | - /** |
|
| 37 | - * total amount including tax we can bill for at this time |
|
| 38 | - * |
|
| 39 | - * @type float $_grand_total |
|
| 40 | - */ |
|
| 41 | - private $_grand_total = 0.00; |
|
| 42 | - |
|
| 43 | - /** |
|
| 44 | - * total number of items being billed for |
|
| 45 | - * |
|
| 46 | - * @type int $_total_items |
|
| 47 | - */ |
|
| 48 | - private $_total_items = 0; |
|
| 49 | - |
|
| 50 | - |
|
| 51 | - |
|
| 52 | - /** |
|
| 53 | - * @return float |
|
| 54 | - */ |
|
| 55 | - public function grand_total() |
|
| 56 | - { |
|
| 57 | - return $this->_grand_total; |
|
| 58 | - } |
|
| 59 | - |
|
| 60 | - |
|
| 61 | - |
|
| 62 | - /** |
|
| 63 | - * @return int |
|
| 64 | - */ |
|
| 65 | - public function total_items() |
|
| 66 | - { |
|
| 67 | - return $this->_total_items; |
|
| 68 | - } |
|
| 69 | - |
|
| 70 | - |
|
| 71 | - |
|
| 72 | - /** |
|
| 73 | - * @param EE_Line_Item $line_item |
|
| 74 | - * @param array $options |
|
| 75 | - * @param EE_Line_Item $parent_line_item |
|
| 76 | - * @return mixed |
|
| 77 | - * @throws EE_Error |
|
| 78 | - */ |
|
| 79 | - public function display_line_item( |
|
| 80 | - EE_Line_Item $line_item, |
|
| 81 | - $options = array(), |
|
| 82 | - EE_Line_Item $parent_line_item = null |
|
| 83 | - ) { |
|
| 84 | - $html = ''; |
|
| 85 | - // set some default options and merge with incoming |
|
| 86 | - $default_options = array( |
|
| 87 | - 'show_desc' => true, // true false |
|
| 88 | - 'odd' => false, |
|
| 89 | - ); |
|
| 90 | - $options = array_merge($default_options, (array) $options); |
|
| 91 | - switch ($line_item->type()) { |
|
| 92 | - case EEM_Line_Item::type_line_item: |
|
| 93 | - $this->_show_taxes = $line_item->is_taxable() ? true : $this->_show_taxes; |
|
| 94 | - if ($line_item->OBJ_type() === 'Ticket') { |
|
| 95 | - // item row |
|
| 96 | - $html .= $this->_ticket_row($line_item, $options); |
|
| 97 | - } else { |
|
| 98 | - // item row |
|
| 99 | - $html .= $this->_item_row($line_item, $options); |
|
| 100 | - } |
|
| 101 | - if ( |
|
| 102 | - apply_filters( |
|
| 103 | - 'FHEE__EE_SPCO_Line_Item_Display_Strategy__display_line_item__display_sub_line_items', |
|
| 104 | - true |
|
| 105 | - ) |
|
| 106 | - ) { |
|
| 107 | - // got any kids? |
|
| 108 | - foreach ($line_item->children() as $child_line_item) { |
|
| 109 | - $html .= $this->display_line_item($child_line_item, $options, $line_item); |
|
| 110 | - } |
|
| 111 | - } |
|
| 112 | - break; |
|
| 113 | - case EEM_Line_Item::type_sub_line_item: |
|
| 114 | - $html .= $this->_sub_item_row($line_item, $options, $parent_line_item); |
|
| 115 | - break; |
|
| 116 | - case EEM_Line_Item::type_sub_total: |
|
| 117 | - static $sub_total = 0; |
|
| 118 | - $event_sub_total = 0; |
|
| 119 | - $text = esc_html__('Sub-Total', 'event_espresso'); |
|
| 120 | - if ($line_item->OBJ_type() === 'Event') { |
|
| 121 | - $options['event_id'] = $event_id = $line_item->OBJ_ID(); |
|
| 122 | - if (! isset($this->_events[ $options['event_id'] ])) { |
|
| 123 | - $event = EEM_Event::instance()->get_one_by_ID($options['event_id']); |
|
| 124 | - // if event has default reg status of Not Approved, then don't display info on it |
|
| 125 | - if ( |
|
| 126 | - $event instanceof EE_Event |
|
| 127 | - && $event->default_registration_status() === EEM_Registration::status_id_not_approved |
|
| 128 | - ) { |
|
| 129 | - $display_event = false; |
|
| 130 | - // unless there are registrations for it that are returning to pay |
|
| 131 | - if (isset($options['registrations']) && is_array($options['registrations'])) { |
|
| 132 | - foreach ($options['registrations'] as $registration) { |
|
| 133 | - if (! $registration instanceof EE_Registration) { |
|
| 134 | - continue; |
|
| 135 | - } |
|
| 136 | - $display_event = $registration->event_ID() === $options['event_id'] |
|
| 137 | - && $registration->status_ID() !== EEM_Registration::status_id_not_approved |
|
| 138 | - ? true |
|
| 139 | - : $display_event; |
|
| 140 | - } |
|
| 141 | - } |
|
| 142 | - if (! $display_event) { |
|
| 143 | - return ''; |
|
| 144 | - } |
|
| 145 | - } |
|
| 146 | - $this->_events[ $options['event_id'] ] = 0; |
|
| 147 | - $html .= $this->_event_row($line_item); |
|
| 148 | - $text = esc_html__('Event Sub-Total', 'event_espresso'); |
|
| 149 | - } |
|
| 150 | - } |
|
| 151 | - $child_line_items = $line_item->children(); |
|
| 152 | - // loop thru children |
|
| 153 | - foreach ($child_line_items as $child_line_item) { |
|
| 154 | - // recursively feed children back into this method |
|
| 155 | - $html .= $this->display_line_item($child_line_item, $options, $line_item); |
|
| 156 | - } |
|
| 157 | - $event_sub_total += isset($options['event_id']) ? $this->_events[ $options['event_id'] ] : 0; |
|
| 158 | - $sub_total += $event_sub_total; |
|
| 159 | - if ( |
|
| 160 | - ( |
|
| 161 | - // event subtotals |
|
| 162 | - $line_item->code() !== 'pre-tax-subtotal' && count($child_line_items) > 1 |
|
| 163 | - ) |
|
| 164 | - || ( |
|
| 165 | - // pre-tax subtotals |
|
| 166 | - $line_item->code() === 'pre-tax-subtotal' && count($this->_events) > 1 |
|
| 167 | - ) |
|
| 168 | - ) { |
|
| 169 | - $options['sub_total'] = $line_item->OBJ_type() === 'Event' ? $event_sub_total : $sub_total; |
|
| 170 | - $html .= $this->_sub_total_row($line_item, $text, $options); |
|
| 171 | - } |
|
| 172 | - break; |
|
| 173 | - case EEM_Line_Item::type_tax: |
|
| 174 | - if ($this->_show_taxes) { |
|
| 175 | - $this->_taxes_html .= $this->_tax_row($line_item, $options); |
|
| 176 | - } |
|
| 177 | - break; |
|
| 178 | - case EEM_Line_Item::type_tax_sub_total: |
|
| 179 | - if ($this->_show_taxes) { |
|
| 180 | - $child_line_items = $line_item->children(); |
|
| 181 | - // loop thru children |
|
| 182 | - foreach ($child_line_items as $child_line_item) { |
|
| 183 | - // recursively feed children back into this method |
|
| 184 | - $html .= $this->display_line_item($child_line_item, $options, $line_item); |
|
| 185 | - } |
|
| 186 | - if (count($child_line_items) > 1) { |
|
| 187 | - $this->_taxes_html .= $this->_total_tax_row($line_item, esc_html__('Tax Total', 'event_espresso')); |
|
| 188 | - } |
|
| 189 | - } |
|
| 190 | - break; |
|
| 191 | - case EEM_Line_Item::type_total: |
|
| 192 | - // get all child line items |
|
| 193 | - $children = $line_item->children(); |
|
| 194 | - // loop thru all non-tax child line items |
|
| 195 | - foreach ($children as $child_line_item) { |
|
| 196 | - if ($child_line_item->type() !== EEM_Line_Item::type_tax_sub_total) { |
|
| 197 | - // recursively feed children back into this method |
|
| 198 | - $html .= $this->display_line_item($child_line_item, $options, $line_item); |
|
| 199 | - } |
|
| 200 | - } |
|
| 201 | - // now loop thru tax child line items |
|
| 202 | - foreach ($children as $child_line_item) { |
|
| 203 | - if ($child_line_item->type() === EEM_Line_Item::type_tax_sub_total) { |
|
| 204 | - // recursively feed children back into this method |
|
| 205 | - $html .= $this->display_line_item($child_line_item, $options, $line_item); |
|
| 206 | - } |
|
| 207 | - } |
|
| 208 | - $html .= $this->_taxes_html; |
|
| 209 | - $html .= $this->_total_row($line_item, esc_html__('Total', 'event_espresso')); |
|
| 210 | - $html .= $this->_payments_and_amount_owing_rows($line_item, $options); |
|
| 211 | - break; |
|
| 212 | - } |
|
| 213 | - return $html; |
|
| 214 | - } |
|
| 215 | - |
|
| 216 | - |
|
| 217 | - |
|
| 218 | - /** |
|
| 219 | - * _event_row - basically a Heading row displayed once above each event's ticket rows |
|
| 220 | - * |
|
| 221 | - * @param EE_Line_Item $line_item |
|
| 222 | - * @return mixed |
|
| 223 | - */ |
|
| 224 | - private function _event_row(EE_Line_Item $line_item) |
|
| 225 | - { |
|
| 226 | - // start of row |
|
| 227 | - $html = EEH_HTML::tr('', 'event-cart-total-row', 'total_tr odd'); |
|
| 228 | - // event name td |
|
| 229 | - $html .= EEH_HTML::td( |
|
| 230 | - EEH_HTML::strong($line_item->name()), |
|
| 231 | - '', |
|
| 232 | - 'event-header', |
|
| 233 | - '', |
|
| 234 | - ' colspan="4"' |
|
| 235 | - ); |
|
| 236 | - // end of row |
|
| 237 | - $html .= EEH_HTML::trx(); |
|
| 238 | - return $html; |
|
| 239 | - } |
|
| 240 | - |
|
| 241 | - |
|
| 242 | - |
|
| 243 | - /** |
|
| 244 | - * _ticket_row |
|
| 245 | - * |
|
| 246 | - * @param EE_Line_Item $line_item |
|
| 247 | - * @param array $options |
|
| 248 | - * @return mixed |
|
| 249 | - * @throws EE_Error |
|
| 250 | - */ |
|
| 251 | - private function _ticket_row(EE_Line_Item $line_item, $options = array()) |
|
| 252 | - { |
|
| 253 | - // start of row |
|
| 254 | - $row_class = $options['odd'] ? 'item odd' : 'item'; |
|
| 255 | - $html = EEH_HTML::tr('', '', $row_class); |
|
| 256 | - // name && desc |
|
| 257 | - $name_and_desc = apply_filters( |
|
| 258 | - 'FHEE__EE_SPCO_Line_Item_Display_Strategy__item_row__name', |
|
| 259 | - $line_item->name(), |
|
| 260 | - $line_item |
|
| 261 | - ); |
|
| 262 | - $name_and_desc .= apply_filters( |
|
| 263 | - 'FHEE__EE_SPCO_Line_Item_Display_Strategy__item_row__desc', |
|
| 264 | - ( |
|
| 265 | - $options['show_desc'] |
|
| 266 | - ? '<span class="line-item-desc-spn smaller-text">: ' . $line_item->desc() . '</span>' |
|
| 267 | - : '' |
|
| 268 | - ), |
|
| 269 | - $line_item, |
|
| 270 | - $options |
|
| 271 | - ); |
|
| 272 | - $name_and_desc .= $line_item->is_taxable() ? ' * ' : ''; |
|
| 273 | - $name_and_desc = apply_filters( |
|
| 274 | - 'FHEE__EE_SPCO_Line_Item_Display_Strategy___ticket_row__name_and_desc', |
|
| 275 | - $name_and_desc, |
|
| 276 | - $line_item, |
|
| 277 | - $options |
|
| 278 | - ); |
|
| 279 | - |
|
| 280 | - // name td |
|
| 281 | - $html .= EEH_HTML::td( /*__FUNCTION__ .*/ |
|
| 282 | - $name_and_desc, |
|
| 283 | - '', |
|
| 284 | - 'item_l' |
|
| 285 | - ); |
|
| 286 | - // price td |
|
| 287 | - $price = apply_filters( |
|
| 288 | - 'FHEE__EE_SPCO_Line_Item_Display_Strategy___ticket_row__price', |
|
| 289 | - $line_item->unit_price_no_code(), |
|
| 290 | - $line_item |
|
| 291 | - ); |
|
| 292 | - $html .= EEH_HTML::td($price, '', 'spco-nowrap item_c jst-rght'); |
|
| 293 | - // quantity td |
|
| 294 | - $html .= EEH_HTML::td($line_item->quantity(), '', 'spco-nowrap item_l jst-rght'); |
|
| 295 | - $this->_total_items += $line_item->quantity(); |
|
| 296 | - // determine total for line item |
|
| 297 | - $total = apply_filters( |
|
| 298 | - 'FHEE__EE_SPCO_Line_Item_Display_Strategy___ticket_row__total', |
|
| 299 | - $line_item->total(), |
|
| 300 | - $line_item |
|
| 301 | - ); |
|
| 302 | - $this->_events[ $options['event_id'] ] += $total; |
|
| 303 | - // total td |
|
| 304 | - $html .= EEH_HTML::td( |
|
| 305 | - EEH_Template::format_currency($total, false, false), |
|
| 306 | - '', |
|
| 307 | - 'spco-nowrap item_r jst-rght' |
|
| 308 | - ); |
|
| 309 | - // end of row |
|
| 310 | - $html .= EEH_HTML::trx(); |
|
| 311 | - return $html; |
|
| 312 | - } |
|
| 313 | - |
|
| 314 | - |
|
| 315 | - |
|
| 316 | - /** |
|
| 317 | - * _item_row |
|
| 318 | - * |
|
| 319 | - * @param EE_Line_Item $line_item |
|
| 320 | - * @param array $options |
|
| 321 | - * @return mixed |
|
| 322 | - * @throws EE_Error |
|
| 323 | - */ |
|
| 324 | - private function _item_row(EE_Line_Item $line_item, $options = array()) |
|
| 325 | - { |
|
| 326 | - // start of row |
|
| 327 | - $row_class = $options['odd'] ? 'item odd' : 'item'; |
|
| 328 | - $html = EEH_HTML::tr('', '', $row_class); |
|
| 329 | - $obj_name = $line_item->OBJ_type() ? $line_item->OBJ_type_i18n() . ': ' : ''; |
|
| 330 | - // name && desc |
|
| 331 | - $name_and_desc = apply_filters( |
|
| 332 | - 'FHEE__EE_SPCO_Line_Item_Display_Strategy__item_row__name', |
|
| 333 | - $obj_name . $line_item->name(), |
|
| 334 | - $line_item |
|
| 335 | - ); |
|
| 336 | - $name_and_desc .= apply_filters( |
|
| 337 | - 'FHEE__EE_SPCO_Line_Item_Display_Strategy__item_row__desc', |
|
| 338 | - ( |
|
| 339 | - $options['show_desc'] |
|
| 340 | - ? '<span class="line-item-desc-spn smaller-text">: ' . $line_item->desc() . '</span>' |
|
| 341 | - : '' |
|
| 342 | - ), |
|
| 343 | - $line_item, |
|
| 344 | - $options |
|
| 345 | - ); |
|
| 346 | - $name_and_desc .= $line_item->is_taxable() ? ' * ' : ''; |
|
| 347 | - $name_and_desc = apply_filters( |
|
| 348 | - 'FHEE__EE_SPCO_Line_Item_Display_Strategy___item_row__name_and_desc', |
|
| 349 | - $name_and_desc, |
|
| 350 | - $line_item, |
|
| 351 | - $options |
|
| 352 | - ); |
|
| 353 | - |
|
| 354 | - // name td |
|
| 355 | - $html .= EEH_HTML::td($name_and_desc, '', 'item_l'); |
|
| 356 | - // price td |
|
| 357 | - if ($line_item->is_percent()) { |
|
| 358 | - $html .= EEH_HTML::td($line_item->percent() . '%', '', 'spco-nowrap item_c jst-rght'); |
|
| 359 | - } else { |
|
| 360 | - $html .= EEH_HTML::td($line_item->unit_price_no_code(), '', 'spco-nowrap item_c jst-rght'); |
|
| 361 | - } |
|
| 362 | - // quantity td |
|
| 363 | - $html .= EEH_HTML::td($line_item->quantity(), '', 'spco-nowrap item_l jst-rght'); |
|
| 364 | - // $total = $line_item->total() * $line_item->quantity(); |
|
| 365 | - $total = $line_item->total(); |
|
| 366 | - if (isset($options['event_id'], $this->_events[ $options['event_id'] ])) { |
|
| 367 | - $this->_events[ $options['event_id'] ] += $total; |
|
| 368 | - } |
|
| 369 | - // total td |
|
| 370 | - $html .= EEH_HTML::td( |
|
| 371 | - EEH_Template::format_currency($total, false, false), |
|
| 372 | - '', |
|
| 373 | - 'spco-nowrap item_r jst-rght' |
|
| 374 | - ); |
|
| 375 | - // end of row |
|
| 376 | - $html .= EEH_HTML::trx(); |
|
| 377 | - return $html; |
|
| 378 | - } |
|
| 379 | - |
|
| 380 | - |
|
| 381 | - |
|
| 382 | - /** |
|
| 383 | - * _sub_item_row |
|
| 384 | - * |
|
| 385 | - * @param EE_Line_Item $line_item |
|
| 386 | - * @param array $options |
|
| 387 | - * @param EE_Line_Item $parent_line_item |
|
| 388 | - * @return mixed |
|
| 389 | - * @throws EE_Error |
|
| 390 | - */ |
|
| 391 | - private function _sub_item_row(EE_Line_Item $line_item, $options = array(), EE_Line_Item $parent_line_item = null) |
|
| 392 | - { |
|
| 393 | - if ( |
|
| 394 | - $parent_line_item instanceof EE_Line_Item |
|
| 395 | - && $line_item->children() === array() |
|
| 396 | - && $line_item->name() === $parent_line_item->name() |
|
| 397 | - && apply_filters( |
|
| 398 | - 'FHEE__EE_SPCO_Line_Item_Display_Strategy___sub_item_row__hide_main_sub_line_item', |
|
| 399 | - true |
|
| 400 | - ) |
|
| 401 | - ) { |
|
| 402 | - return ''; |
|
| 403 | - } |
|
| 404 | - // start of row |
|
| 405 | - $html = EEH_HTML::tr('', '', 'item sub-item-row'); |
|
| 406 | - // name && desc |
|
| 407 | - $name_and_desc = EEH_HTML::span('', '', 'sub-item-row-bullet dashicons dashicons-arrow-right') |
|
| 408 | - . $line_item->name(); |
|
| 409 | - $name_and_desc .= $options['show_desc'] ? '<span class="line-sub-item-desc-spn smaller-text">: ' |
|
| 410 | - . $line_item->desc() |
|
| 411 | - . '</span>' : ''; |
|
| 412 | - // name td |
|
| 413 | - $html .= EEH_HTML::td($name_and_desc, '', 'item_l sub-item'); |
|
| 414 | - $qty = $parent_line_item instanceof EE_Line_Item ? $parent_line_item->quantity() : 1; |
|
| 415 | - // discount/surcharge td |
|
| 416 | - if ($line_item->is_percent()) { |
|
| 417 | - $html .= EEH_HTML::td( |
|
| 418 | - EEH_Template::format_currency( |
|
| 419 | - $line_item->total() / $qty, |
|
| 420 | - false, |
|
| 421 | - false |
|
| 422 | - ), |
|
| 423 | - '', |
|
| 424 | - 'spco-nowrap item_c jst-rght' |
|
| 425 | - ); |
|
| 426 | - } else { |
|
| 427 | - $html .= EEH_HTML::td($line_item->unit_price_no_code(), '', 'spco-nowrap item_c jst-rght'); |
|
| 428 | - } |
|
| 429 | - // no quantity td |
|
| 430 | - $html .= EEH_HTML::td(); |
|
| 431 | - // no total td |
|
| 432 | - $html .= EEH_HTML::td(); |
|
| 433 | - // end of row |
|
| 434 | - $html .= EEH_HTML::trx(); |
|
| 435 | - $html = apply_filters( |
|
| 436 | - 'FHEE__EE_SPCO_Line_Item_Display_Strategy___sub_item_row__html', |
|
| 437 | - $html, |
|
| 438 | - $line_item, |
|
| 439 | - $options, |
|
| 440 | - $parent_line_item |
|
| 441 | - ); |
|
| 442 | - return $html; |
|
| 443 | - } |
|
| 444 | - |
|
| 445 | - |
|
| 446 | - |
|
| 447 | - /** |
|
| 448 | - * _tax_row |
|
| 449 | - * |
|
| 450 | - * @param EE_Line_Item $line_item |
|
| 451 | - * @param array $options |
|
| 452 | - * @return mixed |
|
| 453 | - * @throws EE_Error |
|
| 454 | - */ |
|
| 455 | - private function _tax_row(EE_Line_Item $line_item, $options = array()) |
|
| 456 | - { |
|
| 457 | - // start of row |
|
| 458 | - $html = EEH_HTML::tr('', 'item sub-item tax-total'); |
|
| 459 | - // name && desc |
|
| 460 | - $name_and_desc = $line_item->name(); |
|
| 461 | - $name_and_desc .= '<span class="smaller-text lt-grey-text" style="margin:0 0 0 2em;">' |
|
| 462 | - . esc_html__(' * taxable items', 'event_espresso') . '</span>'; |
|
| 463 | - $name_and_desc .= $options['show_desc'] ? '<br/>' . $line_item->desc() : ''; |
|
| 464 | - // name td |
|
| 465 | - $html .= EEH_HTML::td( /*__FUNCTION__ .*/ |
|
| 466 | - $name_and_desc, |
|
| 467 | - '', |
|
| 468 | - 'item_l sub-item' |
|
| 469 | - ); |
|
| 470 | - // percent td |
|
| 471 | - $html .= EEH_HTML::td($line_item->percent() . '%', '', 'spco-nowrap jst-rght', ''); |
|
| 472 | - // empty td (price) |
|
| 473 | - $html .= EEH_HTML::td(EEH_HTML::nbsp()); |
|
| 474 | - // total td |
|
| 475 | - $html .= EEH_HTML::td( |
|
| 476 | - EEH_Template::format_currency( |
|
| 477 | - $line_item->total(), |
|
| 478 | - false, |
|
| 479 | - false |
|
| 480 | - ), |
|
| 481 | - '', |
|
| 482 | - 'spco-nowrap item_r jst-rght' |
|
| 483 | - ); |
|
| 484 | - // end of row |
|
| 485 | - $html .= EEH_HTML::trx(); |
|
| 486 | - return $html; |
|
| 487 | - } |
|
| 488 | - |
|
| 489 | - |
|
| 490 | - |
|
| 491 | - /** |
|
| 492 | - * _total_row |
|
| 493 | - * |
|
| 494 | - * @param EE_Line_Item $line_item |
|
| 495 | - * @param string $text |
|
| 496 | - * @return mixed |
|
| 497 | - * @throws EE_Error |
|
| 498 | - */ |
|
| 499 | - private function _total_tax_row(EE_Line_Item $line_item, $text = '') |
|
| 500 | - { |
|
| 501 | - $html = ''; |
|
| 502 | - if ($line_item->total()) { |
|
| 503 | - // start of row |
|
| 504 | - $html = EEH_HTML::tr('', '', 'total_tr odd'); |
|
| 505 | - // total td |
|
| 506 | - $html .= EEH_HTML::td( |
|
| 507 | - $text, |
|
| 508 | - '', |
|
| 509 | - 'total_currency total jst-rght', |
|
| 510 | - '', |
|
| 511 | - ' colspan="2"' |
|
| 512 | - ); |
|
| 513 | - // empty td (price) |
|
| 514 | - $html .= EEH_HTML::td(EEH_HTML::nbsp()); |
|
| 515 | - // total td |
|
| 516 | - $html .= EEH_HTML::td( |
|
| 517 | - EEH_Template::format_currency($line_item->total(), false, false), |
|
| 518 | - '', |
|
| 519 | - 'spco-nowrap total jst-rght' |
|
| 520 | - ); |
|
| 521 | - // end of row |
|
| 522 | - $html .= EEH_HTML::trx(); |
|
| 523 | - } |
|
| 524 | - return $html; |
|
| 525 | - } |
|
| 526 | - |
|
| 527 | - |
|
| 528 | - |
|
| 529 | - /** |
|
| 530 | - * _total_row |
|
| 531 | - * |
|
| 532 | - * @param EE_Line_Item $line_item |
|
| 533 | - * @param string $text |
|
| 534 | - * @param array $options |
|
| 535 | - * @return mixed |
|
| 536 | - * @throws EE_Error |
|
| 537 | - */ |
|
| 538 | - private function _sub_total_row(EE_Line_Item $line_item, $text = '', $options = array()) |
|
| 539 | - { |
|
| 540 | - $html = ''; |
|
| 541 | - if ($line_item->total()) { |
|
| 542 | - // start of row |
|
| 543 | - $html = EEH_HTML::tr('', '', 'total_tr odd'); |
|
| 544 | - // total td |
|
| 545 | - $html .= EEH_HTML::td( |
|
| 546 | - $text, |
|
| 547 | - '', |
|
| 548 | - 'total_currency total jst-rght', |
|
| 549 | - '', |
|
| 550 | - ' colspan="3"' |
|
| 551 | - ); |
|
| 552 | - // total td |
|
| 553 | - $html .= EEH_HTML::td( |
|
| 554 | - EEH_Template::format_currency($options['sub_total'], false, false), |
|
| 555 | - '', |
|
| 556 | - 'spco-nowrap total jst-rght' |
|
| 557 | - ); |
|
| 558 | - // end of row |
|
| 559 | - $html .= EEH_HTML::trx(); |
|
| 560 | - } |
|
| 561 | - return $html; |
|
| 562 | - } |
|
| 563 | - |
|
| 564 | - |
|
| 565 | - |
|
| 566 | - /** |
|
| 567 | - * _total_row |
|
| 568 | - * |
|
| 569 | - * @param EE_Line_Item $line_item |
|
| 570 | - * @param string $text |
|
| 571 | - * @return mixed |
|
| 572 | - * @throws EE_Error |
|
| 573 | - */ |
|
| 574 | - private function _total_row(EE_Line_Item $line_item, $text = '') |
|
| 575 | - { |
|
| 576 | - // start of row |
|
| 577 | - $html = EEH_HTML::tr('', '', 'spco-grand-total total_tr odd'); |
|
| 578 | - // total td |
|
| 579 | - $html .= EEH_HTML::td($text, '', 'total_currency total jst-rght', '', ' colspan="3"'); |
|
| 580 | - // total td |
|
| 581 | - $html .= EEH_HTML::td( |
|
| 582 | - EEH_Template::format_currency($line_item->total(), false, false), |
|
| 583 | - '', |
|
| 584 | - 'spco-nowrap total jst-rght' |
|
| 585 | - ); |
|
| 586 | - // end of row |
|
| 587 | - $html .= EEH_HTML::trx(); |
|
| 588 | - return $html; |
|
| 589 | - } |
|
| 590 | - |
|
| 591 | - |
|
| 592 | - |
|
| 593 | - /** |
|
| 594 | - * _payments_and_amount_owing_rows |
|
| 595 | - * |
|
| 596 | - * @param EE_Line_Item $line_item |
|
| 597 | - * @param array $options |
|
| 598 | - * @return mixed |
|
| 599 | - * @throws EE_Error |
|
| 600 | - */ |
|
| 601 | - private function _payments_and_amount_owing_rows(EE_Line_Item $line_item, $options = array()) |
|
| 602 | - { |
|
| 603 | - $html = ''; |
|
| 604 | - $owing = $line_item->total(); |
|
| 605 | - $transaction = EEM_Transaction::instance()->get_one_by_ID($line_item->TXN_ID()); |
|
| 606 | - if ($transaction instanceof EE_Transaction) { |
|
| 607 | - $registration_payments = array(); |
|
| 608 | - $registrations = ! empty($options['registrations']) |
|
| 609 | - ? $options['registrations'] |
|
| 610 | - : $transaction->registrations(); |
|
| 611 | - foreach ($registrations as $registration) { |
|
| 612 | - if ($registration instanceof EE_Registration && $registration->owes_monies_and_can_pay()) { |
|
| 613 | - $registration_payments += $registration->registration_payments(); |
|
| 614 | - } |
|
| 615 | - } |
|
| 616 | - if (! empty($registration_payments)) { |
|
| 617 | - foreach ($registration_payments as $registration_payment) { |
|
| 618 | - if ($registration_payment instanceof EE_Registration_Payment) { |
|
| 619 | - $owing -= $registration_payment->amount(); |
|
| 620 | - $payment = $registration_payment->payment(); |
|
| 621 | - $payment_desc = ''; |
|
| 622 | - if ($payment instanceof EE_Payment) { |
|
| 623 | - $payment_desc = sprintf( |
|
| 624 | - esc_html__('Payment%1$s Received: %2$s', 'event_espresso'), |
|
| 625 | - $payment->txn_id_chq_nmbr() !== '' |
|
| 626 | - ? ' <span class="small-text">(#' . $payment->txn_id_chq_nmbr() . ')</span> ' |
|
| 627 | - : '', |
|
| 628 | - $payment->timestamp() |
|
| 629 | - ); |
|
| 630 | - } |
|
| 631 | - // start of row |
|
| 632 | - $html .= EEH_HTML::tr('', '', 'total_tr odd'); |
|
| 633 | - // payment desc |
|
| 634 | - $html .= EEH_HTML::td($payment_desc, '', '', '', ' colspan="3"'); |
|
| 635 | - // total td |
|
| 636 | - $html .= EEH_HTML::td( |
|
| 637 | - EEH_Template::format_currency( |
|
| 638 | - $registration_payment->amount(), |
|
| 639 | - false, |
|
| 640 | - false |
|
| 641 | - ), |
|
| 642 | - '', |
|
| 643 | - 'spco-nowrap total jst-rght' |
|
| 644 | - ); |
|
| 645 | - // end of row |
|
| 646 | - $html .= EEH_HTML::trx(); |
|
| 647 | - } |
|
| 648 | - } |
|
| 649 | - if ($line_item->total()) { |
|
| 650 | - // start of row |
|
| 651 | - $html .= EEH_HTML::tr('', '', 'total_tr odd'); |
|
| 652 | - // total td |
|
| 653 | - $html .= EEH_HTML::td( |
|
| 654 | - esc_html__('Amount Owing', 'event_espresso'), |
|
| 655 | - '', |
|
| 656 | - 'total_currency total jst-rght', |
|
| 657 | - '', |
|
| 658 | - ' colspan="3"' |
|
| 659 | - ); |
|
| 660 | - // total td |
|
| 661 | - $html .= EEH_HTML::td( |
|
| 662 | - EEH_Template::format_currency($owing, false, false), |
|
| 663 | - '', |
|
| 664 | - 'spco-nowrap total jst-rght' |
|
| 665 | - ); |
|
| 666 | - // end of row |
|
| 667 | - $html .= EEH_HTML::trx(); |
|
| 668 | - } |
|
| 669 | - } |
|
| 670 | - } |
|
| 671 | - $this->_grand_total = $owing; |
|
| 672 | - return $html; |
|
| 673 | - } |
|
| 15 | + /** |
|
| 16 | + * array of events |
|
| 17 | + * |
|
| 18 | + * @type EE_Line_Item[] $_events |
|
| 19 | + */ |
|
| 20 | + private $_events = array(); |
|
| 21 | + |
|
| 22 | + /** |
|
| 23 | + * whether to display the taxes row or not |
|
| 24 | + * |
|
| 25 | + * @type bool $_show_taxes |
|
| 26 | + */ |
|
| 27 | + private $_show_taxes = false; |
|
| 28 | + |
|
| 29 | + /** |
|
| 30 | + * html for any tax rows |
|
| 31 | + * |
|
| 32 | + * @type string $_show_taxes |
|
| 33 | + */ |
|
| 34 | + private $_taxes_html = ''; |
|
| 35 | + |
|
| 36 | + /** |
|
| 37 | + * total amount including tax we can bill for at this time |
|
| 38 | + * |
|
| 39 | + * @type float $_grand_total |
|
| 40 | + */ |
|
| 41 | + private $_grand_total = 0.00; |
|
| 42 | + |
|
| 43 | + /** |
|
| 44 | + * total number of items being billed for |
|
| 45 | + * |
|
| 46 | + * @type int $_total_items |
|
| 47 | + */ |
|
| 48 | + private $_total_items = 0; |
|
| 49 | + |
|
| 50 | + |
|
| 51 | + |
|
| 52 | + /** |
|
| 53 | + * @return float |
|
| 54 | + */ |
|
| 55 | + public function grand_total() |
|
| 56 | + { |
|
| 57 | + return $this->_grand_total; |
|
| 58 | + } |
|
| 59 | + |
|
| 60 | + |
|
| 61 | + |
|
| 62 | + /** |
|
| 63 | + * @return int |
|
| 64 | + */ |
|
| 65 | + public function total_items() |
|
| 66 | + { |
|
| 67 | + return $this->_total_items; |
|
| 68 | + } |
|
| 69 | + |
|
| 70 | + |
|
| 71 | + |
|
| 72 | + /** |
|
| 73 | + * @param EE_Line_Item $line_item |
|
| 74 | + * @param array $options |
|
| 75 | + * @param EE_Line_Item $parent_line_item |
|
| 76 | + * @return mixed |
|
| 77 | + * @throws EE_Error |
|
| 78 | + */ |
|
| 79 | + public function display_line_item( |
|
| 80 | + EE_Line_Item $line_item, |
|
| 81 | + $options = array(), |
|
| 82 | + EE_Line_Item $parent_line_item = null |
|
| 83 | + ) { |
|
| 84 | + $html = ''; |
|
| 85 | + // set some default options and merge with incoming |
|
| 86 | + $default_options = array( |
|
| 87 | + 'show_desc' => true, // true false |
|
| 88 | + 'odd' => false, |
|
| 89 | + ); |
|
| 90 | + $options = array_merge($default_options, (array) $options); |
|
| 91 | + switch ($line_item->type()) { |
|
| 92 | + case EEM_Line_Item::type_line_item: |
|
| 93 | + $this->_show_taxes = $line_item->is_taxable() ? true : $this->_show_taxes; |
|
| 94 | + if ($line_item->OBJ_type() === 'Ticket') { |
|
| 95 | + // item row |
|
| 96 | + $html .= $this->_ticket_row($line_item, $options); |
|
| 97 | + } else { |
|
| 98 | + // item row |
|
| 99 | + $html .= $this->_item_row($line_item, $options); |
|
| 100 | + } |
|
| 101 | + if ( |
|
| 102 | + apply_filters( |
|
| 103 | + 'FHEE__EE_SPCO_Line_Item_Display_Strategy__display_line_item__display_sub_line_items', |
|
| 104 | + true |
|
| 105 | + ) |
|
| 106 | + ) { |
|
| 107 | + // got any kids? |
|
| 108 | + foreach ($line_item->children() as $child_line_item) { |
|
| 109 | + $html .= $this->display_line_item($child_line_item, $options, $line_item); |
|
| 110 | + } |
|
| 111 | + } |
|
| 112 | + break; |
|
| 113 | + case EEM_Line_Item::type_sub_line_item: |
|
| 114 | + $html .= $this->_sub_item_row($line_item, $options, $parent_line_item); |
|
| 115 | + break; |
|
| 116 | + case EEM_Line_Item::type_sub_total: |
|
| 117 | + static $sub_total = 0; |
|
| 118 | + $event_sub_total = 0; |
|
| 119 | + $text = esc_html__('Sub-Total', 'event_espresso'); |
|
| 120 | + if ($line_item->OBJ_type() === 'Event') { |
|
| 121 | + $options['event_id'] = $event_id = $line_item->OBJ_ID(); |
|
| 122 | + if (! isset($this->_events[ $options['event_id'] ])) { |
|
| 123 | + $event = EEM_Event::instance()->get_one_by_ID($options['event_id']); |
|
| 124 | + // if event has default reg status of Not Approved, then don't display info on it |
|
| 125 | + if ( |
|
| 126 | + $event instanceof EE_Event |
|
| 127 | + && $event->default_registration_status() === EEM_Registration::status_id_not_approved |
|
| 128 | + ) { |
|
| 129 | + $display_event = false; |
|
| 130 | + // unless there are registrations for it that are returning to pay |
|
| 131 | + if (isset($options['registrations']) && is_array($options['registrations'])) { |
|
| 132 | + foreach ($options['registrations'] as $registration) { |
|
| 133 | + if (! $registration instanceof EE_Registration) { |
|
| 134 | + continue; |
|
| 135 | + } |
|
| 136 | + $display_event = $registration->event_ID() === $options['event_id'] |
|
| 137 | + && $registration->status_ID() !== EEM_Registration::status_id_not_approved |
|
| 138 | + ? true |
|
| 139 | + : $display_event; |
|
| 140 | + } |
|
| 141 | + } |
|
| 142 | + if (! $display_event) { |
|
| 143 | + return ''; |
|
| 144 | + } |
|
| 145 | + } |
|
| 146 | + $this->_events[ $options['event_id'] ] = 0; |
|
| 147 | + $html .= $this->_event_row($line_item); |
|
| 148 | + $text = esc_html__('Event Sub-Total', 'event_espresso'); |
|
| 149 | + } |
|
| 150 | + } |
|
| 151 | + $child_line_items = $line_item->children(); |
|
| 152 | + // loop thru children |
|
| 153 | + foreach ($child_line_items as $child_line_item) { |
|
| 154 | + // recursively feed children back into this method |
|
| 155 | + $html .= $this->display_line_item($child_line_item, $options, $line_item); |
|
| 156 | + } |
|
| 157 | + $event_sub_total += isset($options['event_id']) ? $this->_events[ $options['event_id'] ] : 0; |
|
| 158 | + $sub_total += $event_sub_total; |
|
| 159 | + if ( |
|
| 160 | + ( |
|
| 161 | + // event subtotals |
|
| 162 | + $line_item->code() !== 'pre-tax-subtotal' && count($child_line_items) > 1 |
|
| 163 | + ) |
|
| 164 | + || ( |
|
| 165 | + // pre-tax subtotals |
|
| 166 | + $line_item->code() === 'pre-tax-subtotal' && count($this->_events) > 1 |
|
| 167 | + ) |
|
| 168 | + ) { |
|
| 169 | + $options['sub_total'] = $line_item->OBJ_type() === 'Event' ? $event_sub_total : $sub_total; |
|
| 170 | + $html .= $this->_sub_total_row($line_item, $text, $options); |
|
| 171 | + } |
|
| 172 | + break; |
|
| 173 | + case EEM_Line_Item::type_tax: |
|
| 174 | + if ($this->_show_taxes) { |
|
| 175 | + $this->_taxes_html .= $this->_tax_row($line_item, $options); |
|
| 176 | + } |
|
| 177 | + break; |
|
| 178 | + case EEM_Line_Item::type_tax_sub_total: |
|
| 179 | + if ($this->_show_taxes) { |
|
| 180 | + $child_line_items = $line_item->children(); |
|
| 181 | + // loop thru children |
|
| 182 | + foreach ($child_line_items as $child_line_item) { |
|
| 183 | + // recursively feed children back into this method |
|
| 184 | + $html .= $this->display_line_item($child_line_item, $options, $line_item); |
|
| 185 | + } |
|
| 186 | + if (count($child_line_items) > 1) { |
|
| 187 | + $this->_taxes_html .= $this->_total_tax_row($line_item, esc_html__('Tax Total', 'event_espresso')); |
|
| 188 | + } |
|
| 189 | + } |
|
| 190 | + break; |
|
| 191 | + case EEM_Line_Item::type_total: |
|
| 192 | + // get all child line items |
|
| 193 | + $children = $line_item->children(); |
|
| 194 | + // loop thru all non-tax child line items |
|
| 195 | + foreach ($children as $child_line_item) { |
|
| 196 | + if ($child_line_item->type() !== EEM_Line_Item::type_tax_sub_total) { |
|
| 197 | + // recursively feed children back into this method |
|
| 198 | + $html .= $this->display_line_item($child_line_item, $options, $line_item); |
|
| 199 | + } |
|
| 200 | + } |
|
| 201 | + // now loop thru tax child line items |
|
| 202 | + foreach ($children as $child_line_item) { |
|
| 203 | + if ($child_line_item->type() === EEM_Line_Item::type_tax_sub_total) { |
|
| 204 | + // recursively feed children back into this method |
|
| 205 | + $html .= $this->display_line_item($child_line_item, $options, $line_item); |
|
| 206 | + } |
|
| 207 | + } |
|
| 208 | + $html .= $this->_taxes_html; |
|
| 209 | + $html .= $this->_total_row($line_item, esc_html__('Total', 'event_espresso')); |
|
| 210 | + $html .= $this->_payments_and_amount_owing_rows($line_item, $options); |
|
| 211 | + break; |
|
| 212 | + } |
|
| 213 | + return $html; |
|
| 214 | + } |
|
| 215 | + |
|
| 216 | + |
|
| 217 | + |
|
| 218 | + /** |
|
| 219 | + * _event_row - basically a Heading row displayed once above each event's ticket rows |
|
| 220 | + * |
|
| 221 | + * @param EE_Line_Item $line_item |
|
| 222 | + * @return mixed |
|
| 223 | + */ |
|
| 224 | + private function _event_row(EE_Line_Item $line_item) |
|
| 225 | + { |
|
| 226 | + // start of row |
|
| 227 | + $html = EEH_HTML::tr('', 'event-cart-total-row', 'total_tr odd'); |
|
| 228 | + // event name td |
|
| 229 | + $html .= EEH_HTML::td( |
|
| 230 | + EEH_HTML::strong($line_item->name()), |
|
| 231 | + '', |
|
| 232 | + 'event-header', |
|
| 233 | + '', |
|
| 234 | + ' colspan="4"' |
|
| 235 | + ); |
|
| 236 | + // end of row |
|
| 237 | + $html .= EEH_HTML::trx(); |
|
| 238 | + return $html; |
|
| 239 | + } |
|
| 240 | + |
|
| 241 | + |
|
| 242 | + |
|
| 243 | + /** |
|
| 244 | + * _ticket_row |
|
| 245 | + * |
|
| 246 | + * @param EE_Line_Item $line_item |
|
| 247 | + * @param array $options |
|
| 248 | + * @return mixed |
|
| 249 | + * @throws EE_Error |
|
| 250 | + */ |
|
| 251 | + private function _ticket_row(EE_Line_Item $line_item, $options = array()) |
|
| 252 | + { |
|
| 253 | + // start of row |
|
| 254 | + $row_class = $options['odd'] ? 'item odd' : 'item'; |
|
| 255 | + $html = EEH_HTML::tr('', '', $row_class); |
|
| 256 | + // name && desc |
|
| 257 | + $name_and_desc = apply_filters( |
|
| 258 | + 'FHEE__EE_SPCO_Line_Item_Display_Strategy__item_row__name', |
|
| 259 | + $line_item->name(), |
|
| 260 | + $line_item |
|
| 261 | + ); |
|
| 262 | + $name_and_desc .= apply_filters( |
|
| 263 | + 'FHEE__EE_SPCO_Line_Item_Display_Strategy__item_row__desc', |
|
| 264 | + ( |
|
| 265 | + $options['show_desc'] |
|
| 266 | + ? '<span class="line-item-desc-spn smaller-text">: ' . $line_item->desc() . '</span>' |
|
| 267 | + : '' |
|
| 268 | + ), |
|
| 269 | + $line_item, |
|
| 270 | + $options |
|
| 271 | + ); |
|
| 272 | + $name_and_desc .= $line_item->is_taxable() ? ' * ' : ''; |
|
| 273 | + $name_and_desc = apply_filters( |
|
| 274 | + 'FHEE__EE_SPCO_Line_Item_Display_Strategy___ticket_row__name_and_desc', |
|
| 275 | + $name_and_desc, |
|
| 276 | + $line_item, |
|
| 277 | + $options |
|
| 278 | + ); |
|
| 279 | + |
|
| 280 | + // name td |
|
| 281 | + $html .= EEH_HTML::td( /*__FUNCTION__ .*/ |
|
| 282 | + $name_and_desc, |
|
| 283 | + '', |
|
| 284 | + 'item_l' |
|
| 285 | + ); |
|
| 286 | + // price td |
|
| 287 | + $price = apply_filters( |
|
| 288 | + 'FHEE__EE_SPCO_Line_Item_Display_Strategy___ticket_row__price', |
|
| 289 | + $line_item->unit_price_no_code(), |
|
| 290 | + $line_item |
|
| 291 | + ); |
|
| 292 | + $html .= EEH_HTML::td($price, '', 'spco-nowrap item_c jst-rght'); |
|
| 293 | + // quantity td |
|
| 294 | + $html .= EEH_HTML::td($line_item->quantity(), '', 'spco-nowrap item_l jst-rght'); |
|
| 295 | + $this->_total_items += $line_item->quantity(); |
|
| 296 | + // determine total for line item |
|
| 297 | + $total = apply_filters( |
|
| 298 | + 'FHEE__EE_SPCO_Line_Item_Display_Strategy___ticket_row__total', |
|
| 299 | + $line_item->total(), |
|
| 300 | + $line_item |
|
| 301 | + ); |
|
| 302 | + $this->_events[ $options['event_id'] ] += $total; |
|
| 303 | + // total td |
|
| 304 | + $html .= EEH_HTML::td( |
|
| 305 | + EEH_Template::format_currency($total, false, false), |
|
| 306 | + '', |
|
| 307 | + 'spco-nowrap item_r jst-rght' |
|
| 308 | + ); |
|
| 309 | + // end of row |
|
| 310 | + $html .= EEH_HTML::trx(); |
|
| 311 | + return $html; |
|
| 312 | + } |
|
| 313 | + |
|
| 314 | + |
|
| 315 | + |
|
| 316 | + /** |
|
| 317 | + * _item_row |
|
| 318 | + * |
|
| 319 | + * @param EE_Line_Item $line_item |
|
| 320 | + * @param array $options |
|
| 321 | + * @return mixed |
|
| 322 | + * @throws EE_Error |
|
| 323 | + */ |
|
| 324 | + private function _item_row(EE_Line_Item $line_item, $options = array()) |
|
| 325 | + { |
|
| 326 | + // start of row |
|
| 327 | + $row_class = $options['odd'] ? 'item odd' : 'item'; |
|
| 328 | + $html = EEH_HTML::tr('', '', $row_class); |
|
| 329 | + $obj_name = $line_item->OBJ_type() ? $line_item->OBJ_type_i18n() . ': ' : ''; |
|
| 330 | + // name && desc |
|
| 331 | + $name_and_desc = apply_filters( |
|
| 332 | + 'FHEE__EE_SPCO_Line_Item_Display_Strategy__item_row__name', |
|
| 333 | + $obj_name . $line_item->name(), |
|
| 334 | + $line_item |
|
| 335 | + ); |
|
| 336 | + $name_and_desc .= apply_filters( |
|
| 337 | + 'FHEE__EE_SPCO_Line_Item_Display_Strategy__item_row__desc', |
|
| 338 | + ( |
|
| 339 | + $options['show_desc'] |
|
| 340 | + ? '<span class="line-item-desc-spn smaller-text">: ' . $line_item->desc() . '</span>' |
|
| 341 | + : '' |
|
| 342 | + ), |
|
| 343 | + $line_item, |
|
| 344 | + $options |
|
| 345 | + ); |
|
| 346 | + $name_and_desc .= $line_item->is_taxable() ? ' * ' : ''; |
|
| 347 | + $name_and_desc = apply_filters( |
|
| 348 | + 'FHEE__EE_SPCO_Line_Item_Display_Strategy___item_row__name_and_desc', |
|
| 349 | + $name_and_desc, |
|
| 350 | + $line_item, |
|
| 351 | + $options |
|
| 352 | + ); |
|
| 353 | + |
|
| 354 | + // name td |
|
| 355 | + $html .= EEH_HTML::td($name_and_desc, '', 'item_l'); |
|
| 356 | + // price td |
|
| 357 | + if ($line_item->is_percent()) { |
|
| 358 | + $html .= EEH_HTML::td($line_item->percent() . '%', '', 'spco-nowrap item_c jst-rght'); |
|
| 359 | + } else { |
|
| 360 | + $html .= EEH_HTML::td($line_item->unit_price_no_code(), '', 'spco-nowrap item_c jst-rght'); |
|
| 361 | + } |
|
| 362 | + // quantity td |
|
| 363 | + $html .= EEH_HTML::td($line_item->quantity(), '', 'spco-nowrap item_l jst-rght'); |
|
| 364 | + // $total = $line_item->total() * $line_item->quantity(); |
|
| 365 | + $total = $line_item->total(); |
|
| 366 | + if (isset($options['event_id'], $this->_events[ $options['event_id'] ])) { |
|
| 367 | + $this->_events[ $options['event_id'] ] += $total; |
|
| 368 | + } |
|
| 369 | + // total td |
|
| 370 | + $html .= EEH_HTML::td( |
|
| 371 | + EEH_Template::format_currency($total, false, false), |
|
| 372 | + '', |
|
| 373 | + 'spco-nowrap item_r jst-rght' |
|
| 374 | + ); |
|
| 375 | + // end of row |
|
| 376 | + $html .= EEH_HTML::trx(); |
|
| 377 | + return $html; |
|
| 378 | + } |
|
| 379 | + |
|
| 380 | + |
|
| 381 | + |
|
| 382 | + /** |
|
| 383 | + * _sub_item_row |
|
| 384 | + * |
|
| 385 | + * @param EE_Line_Item $line_item |
|
| 386 | + * @param array $options |
|
| 387 | + * @param EE_Line_Item $parent_line_item |
|
| 388 | + * @return mixed |
|
| 389 | + * @throws EE_Error |
|
| 390 | + */ |
|
| 391 | + private function _sub_item_row(EE_Line_Item $line_item, $options = array(), EE_Line_Item $parent_line_item = null) |
|
| 392 | + { |
|
| 393 | + if ( |
|
| 394 | + $parent_line_item instanceof EE_Line_Item |
|
| 395 | + && $line_item->children() === array() |
|
| 396 | + && $line_item->name() === $parent_line_item->name() |
|
| 397 | + && apply_filters( |
|
| 398 | + 'FHEE__EE_SPCO_Line_Item_Display_Strategy___sub_item_row__hide_main_sub_line_item', |
|
| 399 | + true |
|
| 400 | + ) |
|
| 401 | + ) { |
|
| 402 | + return ''; |
|
| 403 | + } |
|
| 404 | + // start of row |
|
| 405 | + $html = EEH_HTML::tr('', '', 'item sub-item-row'); |
|
| 406 | + // name && desc |
|
| 407 | + $name_and_desc = EEH_HTML::span('', '', 'sub-item-row-bullet dashicons dashicons-arrow-right') |
|
| 408 | + . $line_item->name(); |
|
| 409 | + $name_and_desc .= $options['show_desc'] ? '<span class="line-sub-item-desc-spn smaller-text">: ' |
|
| 410 | + . $line_item->desc() |
|
| 411 | + . '</span>' : ''; |
|
| 412 | + // name td |
|
| 413 | + $html .= EEH_HTML::td($name_and_desc, '', 'item_l sub-item'); |
|
| 414 | + $qty = $parent_line_item instanceof EE_Line_Item ? $parent_line_item->quantity() : 1; |
|
| 415 | + // discount/surcharge td |
|
| 416 | + if ($line_item->is_percent()) { |
|
| 417 | + $html .= EEH_HTML::td( |
|
| 418 | + EEH_Template::format_currency( |
|
| 419 | + $line_item->total() / $qty, |
|
| 420 | + false, |
|
| 421 | + false |
|
| 422 | + ), |
|
| 423 | + '', |
|
| 424 | + 'spco-nowrap item_c jst-rght' |
|
| 425 | + ); |
|
| 426 | + } else { |
|
| 427 | + $html .= EEH_HTML::td($line_item->unit_price_no_code(), '', 'spco-nowrap item_c jst-rght'); |
|
| 428 | + } |
|
| 429 | + // no quantity td |
|
| 430 | + $html .= EEH_HTML::td(); |
|
| 431 | + // no total td |
|
| 432 | + $html .= EEH_HTML::td(); |
|
| 433 | + // end of row |
|
| 434 | + $html .= EEH_HTML::trx(); |
|
| 435 | + $html = apply_filters( |
|
| 436 | + 'FHEE__EE_SPCO_Line_Item_Display_Strategy___sub_item_row__html', |
|
| 437 | + $html, |
|
| 438 | + $line_item, |
|
| 439 | + $options, |
|
| 440 | + $parent_line_item |
|
| 441 | + ); |
|
| 442 | + return $html; |
|
| 443 | + } |
|
| 444 | + |
|
| 445 | + |
|
| 446 | + |
|
| 447 | + /** |
|
| 448 | + * _tax_row |
|
| 449 | + * |
|
| 450 | + * @param EE_Line_Item $line_item |
|
| 451 | + * @param array $options |
|
| 452 | + * @return mixed |
|
| 453 | + * @throws EE_Error |
|
| 454 | + */ |
|
| 455 | + private function _tax_row(EE_Line_Item $line_item, $options = array()) |
|
| 456 | + { |
|
| 457 | + // start of row |
|
| 458 | + $html = EEH_HTML::tr('', 'item sub-item tax-total'); |
|
| 459 | + // name && desc |
|
| 460 | + $name_and_desc = $line_item->name(); |
|
| 461 | + $name_and_desc .= '<span class="smaller-text lt-grey-text" style="margin:0 0 0 2em;">' |
|
| 462 | + . esc_html__(' * taxable items', 'event_espresso') . '</span>'; |
|
| 463 | + $name_and_desc .= $options['show_desc'] ? '<br/>' . $line_item->desc() : ''; |
|
| 464 | + // name td |
|
| 465 | + $html .= EEH_HTML::td( /*__FUNCTION__ .*/ |
|
| 466 | + $name_and_desc, |
|
| 467 | + '', |
|
| 468 | + 'item_l sub-item' |
|
| 469 | + ); |
|
| 470 | + // percent td |
|
| 471 | + $html .= EEH_HTML::td($line_item->percent() . '%', '', 'spco-nowrap jst-rght', ''); |
|
| 472 | + // empty td (price) |
|
| 473 | + $html .= EEH_HTML::td(EEH_HTML::nbsp()); |
|
| 474 | + // total td |
|
| 475 | + $html .= EEH_HTML::td( |
|
| 476 | + EEH_Template::format_currency( |
|
| 477 | + $line_item->total(), |
|
| 478 | + false, |
|
| 479 | + false |
|
| 480 | + ), |
|
| 481 | + '', |
|
| 482 | + 'spco-nowrap item_r jst-rght' |
|
| 483 | + ); |
|
| 484 | + // end of row |
|
| 485 | + $html .= EEH_HTML::trx(); |
|
| 486 | + return $html; |
|
| 487 | + } |
|
| 488 | + |
|
| 489 | + |
|
| 490 | + |
|
| 491 | + /** |
|
| 492 | + * _total_row |
|
| 493 | + * |
|
| 494 | + * @param EE_Line_Item $line_item |
|
| 495 | + * @param string $text |
|
| 496 | + * @return mixed |
|
| 497 | + * @throws EE_Error |
|
| 498 | + */ |
|
| 499 | + private function _total_tax_row(EE_Line_Item $line_item, $text = '') |
|
| 500 | + { |
|
| 501 | + $html = ''; |
|
| 502 | + if ($line_item->total()) { |
|
| 503 | + // start of row |
|
| 504 | + $html = EEH_HTML::tr('', '', 'total_tr odd'); |
|
| 505 | + // total td |
|
| 506 | + $html .= EEH_HTML::td( |
|
| 507 | + $text, |
|
| 508 | + '', |
|
| 509 | + 'total_currency total jst-rght', |
|
| 510 | + '', |
|
| 511 | + ' colspan="2"' |
|
| 512 | + ); |
|
| 513 | + // empty td (price) |
|
| 514 | + $html .= EEH_HTML::td(EEH_HTML::nbsp()); |
|
| 515 | + // total td |
|
| 516 | + $html .= EEH_HTML::td( |
|
| 517 | + EEH_Template::format_currency($line_item->total(), false, false), |
|
| 518 | + '', |
|
| 519 | + 'spco-nowrap total jst-rght' |
|
| 520 | + ); |
|
| 521 | + // end of row |
|
| 522 | + $html .= EEH_HTML::trx(); |
|
| 523 | + } |
|
| 524 | + return $html; |
|
| 525 | + } |
|
| 526 | + |
|
| 527 | + |
|
| 528 | + |
|
| 529 | + /** |
|
| 530 | + * _total_row |
|
| 531 | + * |
|
| 532 | + * @param EE_Line_Item $line_item |
|
| 533 | + * @param string $text |
|
| 534 | + * @param array $options |
|
| 535 | + * @return mixed |
|
| 536 | + * @throws EE_Error |
|
| 537 | + */ |
|
| 538 | + private function _sub_total_row(EE_Line_Item $line_item, $text = '', $options = array()) |
|
| 539 | + { |
|
| 540 | + $html = ''; |
|
| 541 | + if ($line_item->total()) { |
|
| 542 | + // start of row |
|
| 543 | + $html = EEH_HTML::tr('', '', 'total_tr odd'); |
|
| 544 | + // total td |
|
| 545 | + $html .= EEH_HTML::td( |
|
| 546 | + $text, |
|
| 547 | + '', |
|
| 548 | + 'total_currency total jst-rght', |
|
| 549 | + '', |
|
| 550 | + ' colspan="3"' |
|
| 551 | + ); |
|
| 552 | + // total td |
|
| 553 | + $html .= EEH_HTML::td( |
|
| 554 | + EEH_Template::format_currency($options['sub_total'], false, false), |
|
| 555 | + '', |
|
| 556 | + 'spco-nowrap total jst-rght' |
|
| 557 | + ); |
|
| 558 | + // end of row |
|
| 559 | + $html .= EEH_HTML::trx(); |
|
| 560 | + } |
|
| 561 | + return $html; |
|
| 562 | + } |
|
| 563 | + |
|
| 564 | + |
|
| 565 | + |
|
| 566 | + /** |
|
| 567 | + * _total_row |
|
| 568 | + * |
|
| 569 | + * @param EE_Line_Item $line_item |
|
| 570 | + * @param string $text |
|
| 571 | + * @return mixed |
|
| 572 | + * @throws EE_Error |
|
| 573 | + */ |
|
| 574 | + private function _total_row(EE_Line_Item $line_item, $text = '') |
|
| 575 | + { |
|
| 576 | + // start of row |
|
| 577 | + $html = EEH_HTML::tr('', '', 'spco-grand-total total_tr odd'); |
|
| 578 | + // total td |
|
| 579 | + $html .= EEH_HTML::td($text, '', 'total_currency total jst-rght', '', ' colspan="3"'); |
|
| 580 | + // total td |
|
| 581 | + $html .= EEH_HTML::td( |
|
| 582 | + EEH_Template::format_currency($line_item->total(), false, false), |
|
| 583 | + '', |
|
| 584 | + 'spco-nowrap total jst-rght' |
|
| 585 | + ); |
|
| 586 | + // end of row |
|
| 587 | + $html .= EEH_HTML::trx(); |
|
| 588 | + return $html; |
|
| 589 | + } |
|
| 590 | + |
|
| 591 | + |
|
| 592 | + |
|
| 593 | + /** |
|
| 594 | + * _payments_and_amount_owing_rows |
|
| 595 | + * |
|
| 596 | + * @param EE_Line_Item $line_item |
|
| 597 | + * @param array $options |
|
| 598 | + * @return mixed |
|
| 599 | + * @throws EE_Error |
|
| 600 | + */ |
|
| 601 | + private function _payments_and_amount_owing_rows(EE_Line_Item $line_item, $options = array()) |
|
| 602 | + { |
|
| 603 | + $html = ''; |
|
| 604 | + $owing = $line_item->total(); |
|
| 605 | + $transaction = EEM_Transaction::instance()->get_one_by_ID($line_item->TXN_ID()); |
|
| 606 | + if ($transaction instanceof EE_Transaction) { |
|
| 607 | + $registration_payments = array(); |
|
| 608 | + $registrations = ! empty($options['registrations']) |
|
| 609 | + ? $options['registrations'] |
|
| 610 | + : $transaction->registrations(); |
|
| 611 | + foreach ($registrations as $registration) { |
|
| 612 | + if ($registration instanceof EE_Registration && $registration->owes_monies_and_can_pay()) { |
|
| 613 | + $registration_payments += $registration->registration_payments(); |
|
| 614 | + } |
|
| 615 | + } |
|
| 616 | + if (! empty($registration_payments)) { |
|
| 617 | + foreach ($registration_payments as $registration_payment) { |
|
| 618 | + if ($registration_payment instanceof EE_Registration_Payment) { |
|
| 619 | + $owing -= $registration_payment->amount(); |
|
| 620 | + $payment = $registration_payment->payment(); |
|
| 621 | + $payment_desc = ''; |
|
| 622 | + if ($payment instanceof EE_Payment) { |
|
| 623 | + $payment_desc = sprintf( |
|
| 624 | + esc_html__('Payment%1$s Received: %2$s', 'event_espresso'), |
|
| 625 | + $payment->txn_id_chq_nmbr() !== '' |
|
| 626 | + ? ' <span class="small-text">(#' . $payment->txn_id_chq_nmbr() . ')</span> ' |
|
| 627 | + : '', |
|
| 628 | + $payment->timestamp() |
|
| 629 | + ); |
|
| 630 | + } |
|
| 631 | + // start of row |
|
| 632 | + $html .= EEH_HTML::tr('', '', 'total_tr odd'); |
|
| 633 | + // payment desc |
|
| 634 | + $html .= EEH_HTML::td($payment_desc, '', '', '', ' colspan="3"'); |
|
| 635 | + // total td |
|
| 636 | + $html .= EEH_HTML::td( |
|
| 637 | + EEH_Template::format_currency( |
|
| 638 | + $registration_payment->amount(), |
|
| 639 | + false, |
|
| 640 | + false |
|
| 641 | + ), |
|
| 642 | + '', |
|
| 643 | + 'spco-nowrap total jst-rght' |
|
| 644 | + ); |
|
| 645 | + // end of row |
|
| 646 | + $html .= EEH_HTML::trx(); |
|
| 647 | + } |
|
| 648 | + } |
|
| 649 | + if ($line_item->total()) { |
|
| 650 | + // start of row |
|
| 651 | + $html .= EEH_HTML::tr('', '', 'total_tr odd'); |
|
| 652 | + // total td |
|
| 653 | + $html .= EEH_HTML::td( |
|
| 654 | + esc_html__('Amount Owing', 'event_espresso'), |
|
| 655 | + '', |
|
| 656 | + 'total_currency total jst-rght', |
|
| 657 | + '', |
|
| 658 | + ' colspan="3"' |
|
| 659 | + ); |
|
| 660 | + // total td |
|
| 661 | + $html .= EEH_HTML::td( |
|
| 662 | + EEH_Template::format_currency($owing, false, false), |
|
| 663 | + '', |
|
| 664 | + 'spco-nowrap total jst-rght' |
|
| 665 | + ); |
|
| 666 | + // end of row |
|
| 667 | + $html .= EEH_HTML::trx(); |
|
| 668 | + } |
|
| 669 | + } |
|
| 670 | + } |
|
| 671 | + $this->_grand_total = $owing; |
|
| 672 | + return $html; |
|
| 673 | + } |
|
| 674 | 674 | } |
@@ -84,7 +84,7 @@ discard block |
||
| 84 | 84 | $html = ''; |
| 85 | 85 | // set some default options and merge with incoming |
| 86 | 86 | $default_options = array( |
| 87 | - 'show_desc' => true, // true false |
|
| 87 | + 'show_desc' => true, // true false |
|
| 88 | 88 | 'odd' => false, |
| 89 | 89 | ); |
| 90 | 90 | $options = array_merge($default_options, (array) $options); |
@@ -119,7 +119,7 @@ discard block |
||
| 119 | 119 | $text = esc_html__('Sub-Total', 'event_espresso'); |
| 120 | 120 | if ($line_item->OBJ_type() === 'Event') { |
| 121 | 121 | $options['event_id'] = $event_id = $line_item->OBJ_ID(); |
| 122 | - if (! isset($this->_events[ $options['event_id'] ])) { |
|
| 122 | + if ( ! isset($this->_events[$options['event_id']])) { |
|
| 123 | 123 | $event = EEM_Event::instance()->get_one_by_ID($options['event_id']); |
| 124 | 124 | // if event has default reg status of Not Approved, then don't display info on it |
| 125 | 125 | if ( |
@@ -130,7 +130,7 @@ discard block |
||
| 130 | 130 | // unless there are registrations for it that are returning to pay |
| 131 | 131 | if (isset($options['registrations']) && is_array($options['registrations'])) { |
| 132 | 132 | foreach ($options['registrations'] as $registration) { |
| 133 | - if (! $registration instanceof EE_Registration) { |
|
| 133 | + if ( ! $registration instanceof EE_Registration) { |
|
| 134 | 134 | continue; |
| 135 | 135 | } |
| 136 | 136 | $display_event = $registration->event_ID() === $options['event_id'] |
@@ -139,11 +139,11 @@ discard block |
||
| 139 | 139 | : $display_event; |
| 140 | 140 | } |
| 141 | 141 | } |
| 142 | - if (! $display_event) { |
|
| 142 | + if ( ! $display_event) { |
|
| 143 | 143 | return ''; |
| 144 | 144 | } |
| 145 | 145 | } |
| 146 | - $this->_events[ $options['event_id'] ] = 0; |
|
| 146 | + $this->_events[$options['event_id']] = 0; |
|
| 147 | 147 | $html .= $this->_event_row($line_item); |
| 148 | 148 | $text = esc_html__('Event Sub-Total', 'event_espresso'); |
| 149 | 149 | } |
@@ -154,7 +154,7 @@ discard block |
||
| 154 | 154 | // recursively feed children back into this method |
| 155 | 155 | $html .= $this->display_line_item($child_line_item, $options, $line_item); |
| 156 | 156 | } |
| 157 | - $event_sub_total += isset($options['event_id']) ? $this->_events[ $options['event_id'] ] : 0; |
|
| 157 | + $event_sub_total += isset($options['event_id']) ? $this->_events[$options['event_id']] : 0; |
|
| 158 | 158 | $sub_total += $event_sub_total; |
| 159 | 159 | if ( |
| 160 | 160 | ( |
@@ -263,7 +263,7 @@ discard block |
||
| 263 | 263 | 'FHEE__EE_SPCO_Line_Item_Display_Strategy__item_row__desc', |
| 264 | 264 | ( |
| 265 | 265 | $options['show_desc'] |
| 266 | - ? '<span class="line-item-desc-spn smaller-text">: ' . $line_item->desc() . '</span>' |
|
| 266 | + ? '<span class="line-item-desc-spn smaller-text">: '.$line_item->desc().'</span>' |
|
| 267 | 267 | : '' |
| 268 | 268 | ), |
| 269 | 269 | $line_item, |
@@ -299,7 +299,7 @@ discard block |
||
| 299 | 299 | $line_item->total(), |
| 300 | 300 | $line_item |
| 301 | 301 | ); |
| 302 | - $this->_events[ $options['event_id'] ] += $total; |
|
| 302 | + $this->_events[$options['event_id']] += $total; |
|
| 303 | 303 | // total td |
| 304 | 304 | $html .= EEH_HTML::td( |
| 305 | 305 | EEH_Template::format_currency($total, false, false), |
@@ -326,18 +326,18 @@ discard block |
||
| 326 | 326 | // start of row |
| 327 | 327 | $row_class = $options['odd'] ? 'item odd' : 'item'; |
| 328 | 328 | $html = EEH_HTML::tr('', '', $row_class); |
| 329 | - $obj_name = $line_item->OBJ_type() ? $line_item->OBJ_type_i18n() . ': ' : ''; |
|
| 329 | + $obj_name = $line_item->OBJ_type() ? $line_item->OBJ_type_i18n().': ' : ''; |
|
| 330 | 330 | // name && desc |
| 331 | 331 | $name_and_desc = apply_filters( |
| 332 | 332 | 'FHEE__EE_SPCO_Line_Item_Display_Strategy__item_row__name', |
| 333 | - $obj_name . $line_item->name(), |
|
| 333 | + $obj_name.$line_item->name(), |
|
| 334 | 334 | $line_item |
| 335 | 335 | ); |
| 336 | 336 | $name_and_desc .= apply_filters( |
| 337 | 337 | 'FHEE__EE_SPCO_Line_Item_Display_Strategy__item_row__desc', |
| 338 | 338 | ( |
| 339 | 339 | $options['show_desc'] |
| 340 | - ? '<span class="line-item-desc-spn smaller-text">: ' . $line_item->desc() . '</span>' |
|
| 340 | + ? '<span class="line-item-desc-spn smaller-text">: '.$line_item->desc().'</span>' |
|
| 341 | 341 | : '' |
| 342 | 342 | ), |
| 343 | 343 | $line_item, |
@@ -355,7 +355,7 @@ discard block |
||
| 355 | 355 | $html .= EEH_HTML::td($name_and_desc, '', 'item_l'); |
| 356 | 356 | // price td |
| 357 | 357 | if ($line_item->is_percent()) { |
| 358 | - $html .= EEH_HTML::td($line_item->percent() . '%', '', 'spco-nowrap item_c jst-rght'); |
|
| 358 | + $html .= EEH_HTML::td($line_item->percent().'%', '', 'spco-nowrap item_c jst-rght'); |
|
| 359 | 359 | } else { |
| 360 | 360 | $html .= EEH_HTML::td($line_item->unit_price_no_code(), '', 'spco-nowrap item_c jst-rght'); |
| 361 | 361 | } |
@@ -363,8 +363,8 @@ discard block |
||
| 363 | 363 | $html .= EEH_HTML::td($line_item->quantity(), '', 'spco-nowrap item_l jst-rght'); |
| 364 | 364 | // $total = $line_item->total() * $line_item->quantity(); |
| 365 | 365 | $total = $line_item->total(); |
| 366 | - if (isset($options['event_id'], $this->_events[ $options['event_id'] ])) { |
|
| 367 | - $this->_events[ $options['event_id'] ] += $total; |
|
| 366 | + if (isset($options['event_id'], $this->_events[$options['event_id']])) { |
|
| 367 | + $this->_events[$options['event_id']] += $total; |
|
| 368 | 368 | } |
| 369 | 369 | // total td |
| 370 | 370 | $html .= EEH_HTML::td( |
@@ -459,8 +459,8 @@ discard block |
||
| 459 | 459 | // name && desc |
| 460 | 460 | $name_and_desc = $line_item->name(); |
| 461 | 461 | $name_and_desc .= '<span class="smaller-text lt-grey-text" style="margin:0 0 0 2em;">' |
| 462 | - . esc_html__(' * taxable items', 'event_espresso') . '</span>'; |
|
| 463 | - $name_and_desc .= $options['show_desc'] ? '<br/>' . $line_item->desc() : ''; |
|
| 462 | + . esc_html__(' * taxable items', 'event_espresso').'</span>'; |
|
| 463 | + $name_and_desc .= $options['show_desc'] ? '<br/>'.$line_item->desc() : ''; |
|
| 464 | 464 | // name td |
| 465 | 465 | $html .= EEH_HTML::td( /*__FUNCTION__ .*/ |
| 466 | 466 | $name_and_desc, |
@@ -468,7 +468,7 @@ discard block |
||
| 468 | 468 | 'item_l sub-item' |
| 469 | 469 | ); |
| 470 | 470 | // percent td |
| 471 | - $html .= EEH_HTML::td($line_item->percent() . '%', '', 'spco-nowrap jst-rght', ''); |
|
| 471 | + $html .= EEH_HTML::td($line_item->percent().'%', '', 'spco-nowrap jst-rght', ''); |
|
| 472 | 472 | // empty td (price) |
| 473 | 473 | $html .= EEH_HTML::td(EEH_HTML::nbsp()); |
| 474 | 474 | // total td |
@@ -613,7 +613,7 @@ discard block |
||
| 613 | 613 | $registration_payments += $registration->registration_payments(); |
| 614 | 614 | } |
| 615 | 615 | } |
| 616 | - if (! empty($registration_payments)) { |
|
| 616 | + if ( ! empty($registration_payments)) { |
|
| 617 | 617 | foreach ($registration_payments as $registration_payment) { |
| 618 | 618 | if ($registration_payment instanceof EE_Registration_Payment) { |
| 619 | 619 | $owing -= $registration_payment->amount(); |
@@ -623,7 +623,7 @@ discard block |
||
| 623 | 623 | $payment_desc = sprintf( |
| 624 | 624 | esc_html__('Payment%1$s Received: %2$s', 'event_espresso'), |
| 625 | 625 | $payment->txn_id_chq_nmbr() !== '' |
| 626 | - ? ' <span class="small-text">(#' . $payment->txn_id_chq_nmbr() . ')</span> ' |
|
| 626 | + ? ' <span class="small-text">(#'.$payment->txn_id_chq_nmbr().')</span> ' |
|
| 627 | 627 | : '', |
| 628 | 628 | $payment->timestamp() |
| 629 | 629 | ); |
@@ -17,192 +17,192 @@ |
||
| 17 | 17 | class RegistrantForm extends EE_Form_Section_Proper |
| 18 | 18 | { |
| 19 | 19 | |
| 20 | - /** |
|
| 21 | - * @var EEM_Event_Question_Group |
|
| 22 | - */ |
|
| 23 | - public $event_question_group_model; |
|
| 24 | - |
|
| 25 | - /** |
|
| 26 | - * @var bool |
|
| 27 | - */ |
|
| 28 | - private $has_questions = false; |
|
| 29 | - |
|
| 30 | - |
|
| 31 | - /** |
|
| 32 | - * RegistrantForm constructor. |
|
| 33 | - * |
|
| 34 | - * @param EE_Registration $registration |
|
| 35 | - * @param bool $admin_request |
|
| 36 | - * @param bool $copy_attendee_info |
|
| 37 | - * @param callable $enablePrintCopyInfo |
|
| 38 | - * @param EEM_Event_Question_Group $event_question_group_model |
|
| 39 | - * @throws EE_Error |
|
| 40 | - * @throws ReflectionException |
|
| 41 | - */ |
|
| 42 | - public function __construct( |
|
| 43 | - EE_Registration $registration, |
|
| 44 | - bool $admin_request, |
|
| 45 | - bool $copy_attendee_info, |
|
| 46 | - callable $enablePrintCopyInfo, |
|
| 47 | - EEM_Event_Question_Group $event_question_group_model |
|
| 48 | - ) { |
|
| 49 | - $this->event_question_group_model = $event_question_group_model; |
|
| 50 | - parent::__construct( |
|
| 51 | - $this->generateFormArgs($registration, $admin_request, $copy_attendee_info, $enablePrintCopyInfo) |
|
| 52 | - ); |
|
| 53 | - } |
|
| 54 | - |
|
| 55 | - |
|
| 56 | - /** |
|
| 57 | - * @return bool |
|
| 58 | - */ |
|
| 59 | - public function hasQuestions(): bool |
|
| 60 | - { |
|
| 61 | - return $this->has_questions; |
|
| 62 | - } |
|
| 63 | - |
|
| 64 | - |
|
| 65 | - /** |
|
| 66 | - * @param EE_Registration $registration |
|
| 67 | - * @param bool $admin_request |
|
| 68 | - * @param bool $copy_attendee_info |
|
| 69 | - * @param callable $enablePrintCopyInfo |
|
| 70 | - * @return array |
|
| 71 | - * @throws EE_Error |
|
| 72 | - * @throws ReflectionException |
|
| 73 | - */ |
|
| 74 | - private function generateFormArgs( |
|
| 75 | - EE_Registration $registration, |
|
| 76 | - bool $admin_request, |
|
| 77 | - bool $copy_attendee_info, |
|
| 78 | - callable $enablePrintCopyInfo |
|
| 79 | - ): array { |
|
| 80 | - static $attendee_nmbr = 1; |
|
| 81 | - $form_args = []; |
|
| 82 | - // verify that registration has valid event |
|
| 83 | - if ($registration->event() instanceof EE_Event) { |
|
| 84 | - $field_name = 'Event_Question_Group.' . $this->event_question_group_model->fieldNameForContext( |
|
| 85 | - $registration->is_primary_registrant() |
|
| 86 | - ); |
|
| 87 | - $question_groups = $registration->event()->question_groups( |
|
| 88 | - apply_filters( |
|
| 89 | - // @codingStandardsIgnoreStart |
|
| 90 | - 'FHEE__EE_SPCO_Reg_Step_Attendee_Information___registrations_reg_form__question_groups_query_parameters', |
|
| 91 | - // @codingStandardsIgnoreEnd |
|
| 92 | - [ |
|
| 93 | - [ |
|
| 94 | - 'Event.EVT_ID' => $registration->event()->ID(), |
|
| 95 | - $field_name => true, |
|
| 96 | - ], |
|
| 97 | - 'order_by' => ['QSG_order' => 'ASC'], |
|
| 98 | - ], |
|
| 99 | - $registration, |
|
| 100 | - $this |
|
| 101 | - ) |
|
| 102 | - ); |
|
| 103 | - if ($question_groups) { |
|
| 104 | - // array of params to pass to parent constructor |
|
| 105 | - $form_args = [ |
|
| 106 | - 'html_id' => 'ee-registration-' . $registration->reg_url_link(), |
|
| 107 | - 'html_class' => 'ee-reg-form-attendee-dv', |
|
| 108 | - 'html_style' => $admin_request |
|
| 109 | - ? 'padding:0em 2em 1em; margin:3em 0 0; border:1px solid #ddd;' |
|
| 110 | - : '', |
|
| 111 | - 'subsections' => [], |
|
| 112 | - 'layout_strategy' => new EE_Fieldset_Section_Layout( |
|
| 113 | - [ |
|
| 114 | - 'legend_class' => 'spco-attendee-lgnd', |
|
| 115 | - 'legend_text' => sprintf( |
|
| 116 | - esc_html_x( |
|
| 117 | - 'Attendee %d', |
|
| 118 | - 'Attendee 123', |
|
| 119 | - 'event_espresso' |
|
| 120 | - ), |
|
| 121 | - $attendee_nmbr |
|
| 122 | - ), |
|
| 123 | - ] |
|
| 124 | - ), |
|
| 125 | - ]; |
|
| 126 | - foreach ($question_groups as $question_group) { |
|
| 127 | - if ($question_group instanceof EE_Question_Group) { |
|
| 128 | - $question_group_reg_form = LoaderFactory::getNew( |
|
| 129 | - RegFormQuestionGroup::class, |
|
| 130 | - [$registration, $question_group, $admin_request] |
|
| 131 | - ); |
|
| 132 | - $form_args['subsections'][ $question_group->identifier() ] = apply_filters( |
|
| 133 | - 'FHEE__EE_SPCO_Reg_Step_Attendee_Information___question_group_reg_form__question_group_reg_form', |
|
| 134 | - $question_group_reg_form, |
|
| 135 | - $registration, |
|
| 136 | - $question_group, |
|
| 137 | - $this |
|
| 138 | - ); |
|
| 139 | - } |
|
| 140 | - } |
|
| 141 | - // add hidden input |
|
| 142 | - $form_args['subsections']['additional_attendee_reg_info'] = $this->additionalAttendeeRegInfoInput( |
|
| 143 | - $registration |
|
| 144 | - ); |
|
| 145 | - |
|
| 146 | - // If we have question groups for additional attendees, then display the copy options |
|
| 147 | - $printCopyInfo = apply_filters( |
|
| 148 | - 'FHEE__EE_SPCO_Reg_Step_Attendee_Information___registrations_reg_form___printCopyInfo', |
|
| 149 | - $attendee_nmbr > 1 && $copy_attendee_info, |
|
| 150 | - $attendee_nmbr |
|
| 151 | - ); |
|
| 152 | - if ($printCopyInfo) { |
|
| 153 | - $enablePrintCopyInfo(); |
|
| 154 | - } |
|
| 155 | - |
|
| 156 | - |
|
| 157 | - if ($registration->is_primary_registrant()) { |
|
| 158 | - // generate hidden input |
|
| 159 | - $form_args['subsections']['primary_registrant'] = $this->additionalPrimaryRegistrantInputs( |
|
| 160 | - $registration |
|
| 161 | - ); |
|
| 162 | - } |
|
| 163 | - } |
|
| 164 | - } |
|
| 165 | - $attendee_nmbr++; |
|
| 166 | - |
|
| 167 | - // Increment the reg forms number if form is valid. |
|
| 168 | - if (! empty($form_args)) { |
|
| 169 | - $this->has_questions = true; |
|
| 170 | - } |
|
| 171 | - |
|
| 172 | - return $form_args; |
|
| 173 | - } |
|
| 174 | - |
|
| 175 | - |
|
| 176 | - /** |
|
| 177 | - * @param EE_Registration $registration |
|
| 178 | - * @return EE_Form_Input_Base |
|
| 179 | - * @throws EE_Error |
|
| 180 | - */ |
|
| 181 | - private function additionalAttendeeRegInfoInput(EE_Registration $registration) |
|
| 182 | - { |
|
| 183 | - // generate hidden input |
|
| 184 | - return new EE_Hidden_Input( |
|
| 185 | - [ |
|
| 186 | - 'html_id' => 'additional-attendee-reg-info-' . $registration->reg_url_link(), |
|
| 187 | - 'default' => true, |
|
| 188 | - ] |
|
| 189 | - ); |
|
| 190 | - } |
|
| 191 | - |
|
| 192 | - |
|
| 193 | - /** |
|
| 194 | - * @param EE_Registration $registration |
|
| 195 | - * @return EE_Form_Input_Base |
|
| 196 | - * @throws EE_Error |
|
| 197 | - */ |
|
| 198 | - private function additionalPrimaryRegistrantInputs(EE_Registration $registration) |
|
| 199 | - { |
|
| 200 | - // generate hidden input |
|
| 201 | - return new EE_Hidden_Input( |
|
| 202 | - [ |
|
| 203 | - 'html_id' => 'primary_registrant', |
|
| 204 | - 'default' => $registration->reg_url_link(), |
|
| 205 | - ] |
|
| 206 | - ); |
|
| 207 | - } |
|
| 20 | + /** |
|
| 21 | + * @var EEM_Event_Question_Group |
|
| 22 | + */ |
|
| 23 | + public $event_question_group_model; |
|
| 24 | + |
|
| 25 | + /** |
|
| 26 | + * @var bool |
|
| 27 | + */ |
|
| 28 | + private $has_questions = false; |
|
| 29 | + |
|
| 30 | + |
|
| 31 | + /** |
|
| 32 | + * RegistrantForm constructor. |
|
| 33 | + * |
|
| 34 | + * @param EE_Registration $registration |
|
| 35 | + * @param bool $admin_request |
|
| 36 | + * @param bool $copy_attendee_info |
|
| 37 | + * @param callable $enablePrintCopyInfo |
|
| 38 | + * @param EEM_Event_Question_Group $event_question_group_model |
|
| 39 | + * @throws EE_Error |
|
| 40 | + * @throws ReflectionException |
|
| 41 | + */ |
|
| 42 | + public function __construct( |
|
| 43 | + EE_Registration $registration, |
|
| 44 | + bool $admin_request, |
|
| 45 | + bool $copy_attendee_info, |
|
| 46 | + callable $enablePrintCopyInfo, |
|
| 47 | + EEM_Event_Question_Group $event_question_group_model |
|
| 48 | + ) { |
|
| 49 | + $this->event_question_group_model = $event_question_group_model; |
|
| 50 | + parent::__construct( |
|
| 51 | + $this->generateFormArgs($registration, $admin_request, $copy_attendee_info, $enablePrintCopyInfo) |
|
| 52 | + ); |
|
| 53 | + } |
|
| 54 | + |
|
| 55 | + |
|
| 56 | + /** |
|
| 57 | + * @return bool |
|
| 58 | + */ |
|
| 59 | + public function hasQuestions(): bool |
|
| 60 | + { |
|
| 61 | + return $this->has_questions; |
|
| 62 | + } |
|
| 63 | + |
|
| 64 | + |
|
| 65 | + /** |
|
| 66 | + * @param EE_Registration $registration |
|
| 67 | + * @param bool $admin_request |
|
| 68 | + * @param bool $copy_attendee_info |
|
| 69 | + * @param callable $enablePrintCopyInfo |
|
| 70 | + * @return array |
|
| 71 | + * @throws EE_Error |
|
| 72 | + * @throws ReflectionException |
|
| 73 | + */ |
|
| 74 | + private function generateFormArgs( |
|
| 75 | + EE_Registration $registration, |
|
| 76 | + bool $admin_request, |
|
| 77 | + bool $copy_attendee_info, |
|
| 78 | + callable $enablePrintCopyInfo |
|
| 79 | + ): array { |
|
| 80 | + static $attendee_nmbr = 1; |
|
| 81 | + $form_args = []; |
|
| 82 | + // verify that registration has valid event |
|
| 83 | + if ($registration->event() instanceof EE_Event) { |
|
| 84 | + $field_name = 'Event_Question_Group.' . $this->event_question_group_model->fieldNameForContext( |
|
| 85 | + $registration->is_primary_registrant() |
|
| 86 | + ); |
|
| 87 | + $question_groups = $registration->event()->question_groups( |
|
| 88 | + apply_filters( |
|
| 89 | + // @codingStandardsIgnoreStart |
|
| 90 | + 'FHEE__EE_SPCO_Reg_Step_Attendee_Information___registrations_reg_form__question_groups_query_parameters', |
|
| 91 | + // @codingStandardsIgnoreEnd |
|
| 92 | + [ |
|
| 93 | + [ |
|
| 94 | + 'Event.EVT_ID' => $registration->event()->ID(), |
|
| 95 | + $field_name => true, |
|
| 96 | + ], |
|
| 97 | + 'order_by' => ['QSG_order' => 'ASC'], |
|
| 98 | + ], |
|
| 99 | + $registration, |
|
| 100 | + $this |
|
| 101 | + ) |
|
| 102 | + ); |
|
| 103 | + if ($question_groups) { |
|
| 104 | + // array of params to pass to parent constructor |
|
| 105 | + $form_args = [ |
|
| 106 | + 'html_id' => 'ee-registration-' . $registration->reg_url_link(), |
|
| 107 | + 'html_class' => 'ee-reg-form-attendee-dv', |
|
| 108 | + 'html_style' => $admin_request |
|
| 109 | + ? 'padding:0em 2em 1em; margin:3em 0 0; border:1px solid #ddd;' |
|
| 110 | + : '', |
|
| 111 | + 'subsections' => [], |
|
| 112 | + 'layout_strategy' => new EE_Fieldset_Section_Layout( |
|
| 113 | + [ |
|
| 114 | + 'legend_class' => 'spco-attendee-lgnd', |
|
| 115 | + 'legend_text' => sprintf( |
|
| 116 | + esc_html_x( |
|
| 117 | + 'Attendee %d', |
|
| 118 | + 'Attendee 123', |
|
| 119 | + 'event_espresso' |
|
| 120 | + ), |
|
| 121 | + $attendee_nmbr |
|
| 122 | + ), |
|
| 123 | + ] |
|
| 124 | + ), |
|
| 125 | + ]; |
|
| 126 | + foreach ($question_groups as $question_group) { |
|
| 127 | + if ($question_group instanceof EE_Question_Group) { |
|
| 128 | + $question_group_reg_form = LoaderFactory::getNew( |
|
| 129 | + RegFormQuestionGroup::class, |
|
| 130 | + [$registration, $question_group, $admin_request] |
|
| 131 | + ); |
|
| 132 | + $form_args['subsections'][ $question_group->identifier() ] = apply_filters( |
|
| 133 | + 'FHEE__EE_SPCO_Reg_Step_Attendee_Information___question_group_reg_form__question_group_reg_form', |
|
| 134 | + $question_group_reg_form, |
|
| 135 | + $registration, |
|
| 136 | + $question_group, |
|
| 137 | + $this |
|
| 138 | + ); |
|
| 139 | + } |
|
| 140 | + } |
|
| 141 | + // add hidden input |
|
| 142 | + $form_args['subsections']['additional_attendee_reg_info'] = $this->additionalAttendeeRegInfoInput( |
|
| 143 | + $registration |
|
| 144 | + ); |
|
| 145 | + |
|
| 146 | + // If we have question groups for additional attendees, then display the copy options |
|
| 147 | + $printCopyInfo = apply_filters( |
|
| 148 | + 'FHEE__EE_SPCO_Reg_Step_Attendee_Information___registrations_reg_form___printCopyInfo', |
|
| 149 | + $attendee_nmbr > 1 && $copy_attendee_info, |
|
| 150 | + $attendee_nmbr |
|
| 151 | + ); |
|
| 152 | + if ($printCopyInfo) { |
|
| 153 | + $enablePrintCopyInfo(); |
|
| 154 | + } |
|
| 155 | + |
|
| 156 | + |
|
| 157 | + if ($registration->is_primary_registrant()) { |
|
| 158 | + // generate hidden input |
|
| 159 | + $form_args['subsections']['primary_registrant'] = $this->additionalPrimaryRegistrantInputs( |
|
| 160 | + $registration |
|
| 161 | + ); |
|
| 162 | + } |
|
| 163 | + } |
|
| 164 | + } |
|
| 165 | + $attendee_nmbr++; |
|
| 166 | + |
|
| 167 | + // Increment the reg forms number if form is valid. |
|
| 168 | + if (! empty($form_args)) { |
|
| 169 | + $this->has_questions = true; |
|
| 170 | + } |
|
| 171 | + |
|
| 172 | + return $form_args; |
|
| 173 | + } |
|
| 174 | + |
|
| 175 | + |
|
| 176 | + /** |
|
| 177 | + * @param EE_Registration $registration |
|
| 178 | + * @return EE_Form_Input_Base |
|
| 179 | + * @throws EE_Error |
|
| 180 | + */ |
|
| 181 | + private function additionalAttendeeRegInfoInput(EE_Registration $registration) |
|
| 182 | + { |
|
| 183 | + // generate hidden input |
|
| 184 | + return new EE_Hidden_Input( |
|
| 185 | + [ |
|
| 186 | + 'html_id' => 'additional-attendee-reg-info-' . $registration->reg_url_link(), |
|
| 187 | + 'default' => true, |
|
| 188 | + ] |
|
| 189 | + ); |
|
| 190 | + } |
|
| 191 | + |
|
| 192 | + |
|
| 193 | + /** |
|
| 194 | + * @param EE_Registration $registration |
|
| 195 | + * @return EE_Form_Input_Base |
|
| 196 | + * @throws EE_Error |
|
| 197 | + */ |
|
| 198 | + private function additionalPrimaryRegistrantInputs(EE_Registration $registration) |
|
| 199 | + { |
|
| 200 | + // generate hidden input |
|
| 201 | + return new EE_Hidden_Input( |
|
| 202 | + [ |
|
| 203 | + 'html_id' => 'primary_registrant', |
|
| 204 | + 'default' => $registration->reg_url_link(), |
|
| 205 | + ] |
|
| 206 | + ); |
|
| 207 | + } |
|
| 208 | 208 | } |