Completed
Branch dev (0911a7)
by
unknown
08:01 queued 05:53
created
single_page_checkout/templates/registration_page_wrapper.template.php 1 patch
Indentation   +48 added lines, -48 removed lines patch added patch discarded remove patch
@@ -1,91 +1,91 @@
 block discarded – undo
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
-                                        '&nbsp;',
38
-                                        '<br/>&nbsp;',
39
-                                        $reg_step->name()
40
-                                    ); ?>
37
+										'&nbsp;',
38
+										'<br/>&nbsp;',
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">&raquo;</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
 
Please login to merge, or discard this patch.
modules/ticket_selector/TicketSelectorRowStandard.php 2 patches
Indentation   +356 added lines, -356 removed lines patch added patch discarded remove patch
@@ -18,360 +18,360 @@
 block discarded – undo
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 .= '&nbsp;';
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 .= '&nbsp;';
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">&nbsp;0&nbsp;</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 . '">&nbsp;' . $i . '&nbsp;</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 .= '&nbsp;';
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 .= '&nbsp;';
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">&nbsp;0&nbsp;</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 . '">&nbsp;' . $i . '&nbsp;</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
 }
Please login to merge, or discard this patch.
Spacing   +18 added lines, -18 removed lines patch added patch discarded remove patch
@@ -172,7 +172,7 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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 . '">&nbsp;' . $i . '&nbsp;</option>';
353
+            $html .= '<option value="'.$i.'">&nbsp;'.$i.'&nbsp;</option>';
354 354
         }
355 355
         $html .= '</select>';
356 356
         return $html;
@@ -368,10 +368,10 @@  discard block
 block discarded – undo
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
 }
Please login to merge, or discard this patch.
core/libraries/shortcodes/EE_Line_Item_List_Shortcodes.lib.php 2 patches
Indentation   +197 added lines, -197 removed lines patch added patch discarded remove patch
@@ -22,201 +22,201 @@
 block discarded – undo
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
 }
Please login to merge, or discard this patch.
Spacing   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -71,7 +71,7 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 
Please login to merge, or discard this patch.
core/domain/services/registration/form/v1/RegistrantForm.php 1 patch
Indentation   +188 added lines, -188 removed lines patch added patch discarded remove patch
@@ -17,192 +17,192 @@
 block discarded – undo
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
 }
Please login to merge, or discard this patch.
reg_steps/attendee_information/attendee_info_main.template.php 2 patches
Indentation   +32 added lines, -32 removed lines patch added patch discarded remove patch
@@ -6,16 +6,16 @@  discard block
 block discarded – undo
6 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
-            'FHEE__registration_page_attendee_information__attendee_information_pg',
10
-            sprintf(
11
-                __(
12
-                    'In order to process your registration, we ask you to provide the following information.%1$sPlease note that all fields marked with an asterisk (%2$s) are required.',
13
-                    'event_espresso'
14
-                ),
15
-                '<br />',
16
-                '<span class="asterisk">*</span>'
17
-            )
18
-        ); ?>
9
+			'FHEE__registration_page_attendee_information__attendee_information_pg',
10
+			sprintf(
11
+				__(
12
+					'In order to process your registration, we ask you to provide the following information.%1$sPlease note that all fields marked with an asterisk (%2$s) are required.',
13
+					'event_espresso'
14
+				),
15
+				'<br />',
16
+				'<span class="asterisk">*</span>'
17
+			)
18
+		); ?>
19 19
 </p>
20 20
 <?php endif; ?>
21 21
 
@@ -25,10 +25,10 @@  discard block
 block discarded – undo
25 25
 $prev_ticket = 0;
26 26
 
27 27
 if (count($registrations) > 0) {
28
-    foreach ($registrations as $registration) {
29
-        if ($registration instanceof EE_Registration) {
30
-            $att_nmbr++;
31
-            ?>
28
+	foreach ($registrations as $registration) {
29
+		if ($registration instanceof EE_Registration) {
30
+			$att_nmbr++;
31
+			?>
32 32
 
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(); ?>">
@@ -47,19 +47,19 @@  discard block
 block discarded – undo
47 47
                                     <th scope="col" width="" class="jst-left"></th>
48 48
                                     <th scope="col" width="7.5%" class="jst-rght">
49 49
                                         <?php _e(
50
-                                            'Qty',
51
-                                            'event_espresso'
52
-                                        ); ?></th>
50
+											'Qty',
51
+											'event_espresso'
52
+										); ?></th>
53 53
                                     <th scope="col" width="17.5%" class="jst-rght">
54 54
                                         <?php _e(
55
-                                            'Price',
56
-                                            'event_espresso'
57
-                                        ); ?></th>
55
+											'Price',
56
+											'event_espresso'
57
+										); ?></th>
58 58
                                     <th scope="col" width="17.5%" class="jst-rght">
59 59
                                         <?php _e(
60
-                                            'Total',
61
-                                            'event_espresso'
62
-                                        ); ?></th>
60
+											'Total',
61
+											'event_espresso'
62
+										); ?></th>
63 63
                                 </tr>
64 64
                                 </thead>
65 65
                                 <tbody>
@@ -71,19 +71,19 @@  discard block
 block discarded – undo
71 71
                 <?php } ?>
72 72
 
73 73
                 <?php
74
-                // ATTENDEE QUESTIONS
75
-                $reg_form = EE_Template_Layout::get_subform_name($registration->reg_url_link());
76
-                echo ${$reg_form};
77
-                ?>
74
+				// ATTENDEE QUESTIONS
75
+				$reg_form = EE_Template_Layout::get_subform_name($registration->reg_url_link());
76
+				echo ${$reg_form};
77
+				?>
78 78
 
79 79
             </div>
80 80
             <?php
81
-            $prev_event = $registration->event()->ID();
82
-            $prev_ticket = $registration->ticket()->ID();
83
-        } // if ( $registration instanceof EE_Registration )
84
-    } // end foreach ( $registrations as $registration )
81
+			$prev_event = $registration->event()->ID();
82
+			$prev_ticket = $registration->ticket()->ID();
83
+		} // if ( $registration instanceof EE_Registration )
84
+	} // end foreach ( $registrations as $registration )
85 85
 
86
-    echo $default_hidden_inputs;
86
+	echo $default_hidden_inputs;
87 87
 } // end if ( count( $registrations ) > 0 )
88 88
 
89 89
 ?>
Please login to merge, or discard this patch.
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -3,7 +3,7 @@  discard block
 block discarded – undo
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,13 +33,13 @@  discard block
 block discarded – undo
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 44
                             <table class="spco-ticket-details">
45 45
                                 <thead>
@@ -63,7 +63,7 @@  discard block
 block discarded – undo
63 63
                                 </tr>
64 64
                                 </thead>
65 65
                                 <tbody>
66
-                                <?php echo $ticket_line_item[ $registration->ticket()->ID() ]; ?>
66
+                                <?php echo $ticket_line_item[$registration->ticket()->ID()]; ?>
67 67
                                 </tbody>
68 68
                             </table>
69 69
                         </div>
Please login to merge, or discard this patch.
reg_steps/attendee_information/attendee_info_single.template.php 2 patches
Indentation   +43 added lines, -43 removed lines patch added patch discarded remove patch
@@ -6,16 +6,16 @@  discard block
 block discarded – undo
6 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
-            'FHEE__registration_page_attendee_information__attendee_information_pg',
10
-            sprintf(
11
-                esc_html__(
12
-                    'In order to process your registration, we ask you to provide the following information.%1$sPlease note that all fields marked with an asterisk (%2$s) are required.',
13
-                    'event_espresso'
14
-                ),
15
-                '<br />',
16
-                '<span class="asterisk">*</span>'
17
-            )
18
-        ); ?>
9
+			'FHEE__registration_page_attendee_information__attendee_information_pg',
10
+			sprintf(
11
+				esc_html__(
12
+					'In order to process your registration, we ask you to provide the following information.%1$sPlease note that all fields marked with an asterisk (%2$s) are required.',
13
+					'event_espresso'
14
+				),
15
+				'<br />',
16
+				'<span class="asterisk">*</span>'
17
+			)
18
+		); ?>
19 19
 </p>
20 20
 <?php endif; ?>
21 21
 
@@ -25,8 +25,8 @@  discard block
 block discarded – undo
25 25
 $prev_ticket = 0;
26 26
 
27 27
 if (count($registrations) > 0) {
28
-    $ticketID = key($template_args['ticket_count']);
29
-    ?>
28
+	$ticketID = key($template_args['ticket_count']);
29
+	?>
30 30
 
31 31
     <div id="spco-attendee-panel-dv-<?php echo $ticketID; ?>"
32 32
         class="spco-attendee-panel-dv spco-attendee-ticket-<?php echo $ticketID; ?>">
@@ -38,54 +38,54 @@  discard block
 block discarded – undo
38 38
                     <th scope="col" width="" class="jst-left"></th>
39 39
                     <th scope="col" width="7.5%" class="jst-rght">
40 40
                         <?php esc_html_e(
41
-                            'Qty',
42
-                            'event_espresso'
43
-                        ); ?></th>
41
+							'Qty',
42
+							'event_espresso'
43
+						); ?></th>
44 44
                     <th scope="col" width="17.5%" class="jst-rght">
45 45
                         <?php esc_html_e(
46
-                            'Price',
47
-                            'event_espresso'
48
-                        ); ?></th>
46
+							'Price',
47
+							'event_espresso'
48
+						); ?></th>
49 49
                     <th scope="col" width="17.5%" class="jst-rght">
50 50
                         <?php esc_html_e(
51
-                            'Total',
52
-                            'event_espresso'
53
-                        ); ?></th>
51
+							'Total',
52
+							'event_espresso'
53
+						); ?></th>
54 54
                 </tr>
55 55
                 </thead>
56 56
                 <tbody>
57 57
                 <?php
58
-                // Store previous values to avoid duplicated rows.
59
-                $prev_ticket = 0;
60
-                // Display all tickets inside.
61
-                foreach ($registrations as $registration) {
62
-                    if ($registration instanceof EE_Registration) {
63
-                        if ($registration->ticket()->ID() !== $prev_ticket) {
64
-                            echo $ticket_line_item[ $registration->ticket()->ID() ];
65
-                        }
58
+				// Store previous values to avoid duplicated rows.
59
+				$prev_ticket = 0;
60
+				// Display all tickets inside.
61
+				foreach ($registrations as $registration) {
62
+					if ($registration instanceof EE_Registration) {
63
+						if ($registration->ticket()->ID() !== $prev_ticket) {
64
+							echo $ticket_line_item[ $registration->ticket()->ID() ];
65
+						}
66 66
 
67
-                        $prev_ticket = $registration->ticket()->ID();
68
-                    }
69
-                }
70
-                ?>
67
+						$prev_ticket = $registration->ticket()->ID();
68
+					}
69
+				}
70
+				?>
71 71
                 </tbody>
72 72
             </table>
73 73
         </div><!-- close spco-ticket-info-dv -->
74 74
 
75 75
         <?php
76
-        // Display the forms below the table.
77
-        foreach ($registrations as $registration) {
78
-            if ($registration instanceof EE_Registration) {
79
-                // Attendee Questions.
80
-                $reg_form = EE_Template_Layout::get_subform_name($registration->reg_url_link());
81
-                echo ${$reg_form};
82
-            } // if ( $registration instanceof EE_Registration )
83
-        } // end foreach ( $registrations as $registration )
76
+		// Display the forms below the table.
77
+		foreach ($registrations as $registration) {
78
+			if ($registration instanceof EE_Registration) {
79
+				// Attendee Questions.
80
+				$reg_form = EE_Template_Layout::get_subform_name($registration->reg_url_link());
81
+				echo ${$reg_form};
82
+			} // if ( $registration instanceof EE_Registration )
83
+		} // end foreach ( $registrations as $registration )
84 84
 
85
-        ?>
85
+		?>
86 86
     </div><!-- close spco-attendee-panel-dv -->
87 87
     <?php
88
-    echo $default_hidden_inputs;
88
+	echo $default_hidden_inputs;
89 89
 } // end if ( count( $registrations ) > 0 )
90 90
 
91 91
 ?>
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -3,7 +3,7 @@  discard block
 block discarded – undo
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',
@@ -61,7 +61,7 @@  discard block
 block discarded – undo
61 61
                 foreach ($registrations as $registration) {
62 62
                     if ($registration instanceof EE_Registration) {
63 63
                         if ($registration->ticket()->ID() !== $prev_ticket) {
64
-                            echo $ticket_line_item[ $registration->ticket()->ID() ];
64
+                            echo $ticket_line_item[$registration->ticket()->ID()];
65 65
                         }
66 66
 
67 67
                         $prev_ticket = $registration->ticket()->ID();
Please login to merge, or discard this patch.
admin_pages/payments/Payments_Admin_Page.core.php 2 patches
Indentation   +1158 added lines, -1158 removed lines patch added patch discarded remove patch
@@ -16,1162 +16,1162 @@
 block discarded – undo
16 16
 class Payments_Admin_Page extends EE_Admin_Page
17 17
 {
18 18
 
19
-    /**
20
-     * Variables used for when we're re-sorting the logs results, in case
21
-     * we needed to do two queries and we need to resort
22
-     *
23
-     * @var string
24
-     */
25
-    private $_sort_logs_again_direction;
26
-
27
-
28
-    /**
29
-     * @Constructor
30
-     * @access public
31
-     * @param bool $routing indicate whether we want to just load the object and handle routing or just load the object.
32
-     * @throws EE_Error
33
-     * @throws InvalidArgumentException
34
-     * @throws InvalidDataTypeException
35
-     * @throws InvalidInterfaceException
36
-     * @throws ReflectionException
37
-     */
38
-    public function __construct($routing = true)
39
-    {
40
-        parent::__construct($routing);
41
-    }
42
-
43
-
44
-    protected function _init_page_props()
45
-    {
46
-        $this->page_slug = EE_PAYMENTS_PG_SLUG;
47
-        $this->page_label = __('Payment Methods', 'event_espresso');
48
-        $this->_admin_base_url = EE_PAYMENTS_ADMIN_URL;
49
-        $this->_admin_base_path = EE_PAYMENTS_ADMIN;
50
-    }
51
-
52
-
53
-    protected function _ajax_hooks()
54
-    {
55
-        // todo: all hooks for ajax goes here.
56
-    }
57
-
58
-
59
-    protected function _define_page_props()
60
-    {
61
-        $this->_admin_page_title = $this->page_label;
62
-        $this->_labels = array(
63
-            'publishbox' => __('Update Settings', 'event_espresso'),
64
-        );
65
-    }
66
-
67
-
68
-    protected function _set_page_routes()
69
-    {
70
-        /**
71
-         * note that with payment method capabilities, although we've implemented
72
-         * capability mapping which will be used for accessing payment methods owned by
73
-         * other users.  This is not fully implemented yet in the payment method ui.
74
-         * Currently only the "plural" caps are in active use.
75
-         * When cap mapping is implemented, some routes will need to use the singular form of
76
-         * capability method and also include the $id of the payment method for the route.
77
-         **/
78
-        $this->_page_routes = array(
79
-            'default'                   => array(
80
-                'func'       => '_payment_methods_list',
81
-                'capability' => 'ee_edit_payment_methods',
82
-            ),
83
-            'payment_settings'          => array(
84
-                'func'       => '_payment_settings',
85
-                'capability' => 'ee_manage_gateways',
86
-            ),
87
-            'activate_payment_method'   => array(
88
-                'func'       => '_activate_payment_method',
89
-                'noheader'   => true,
90
-                'capability' => 'ee_edit_payment_methods',
91
-            ),
92
-            'deactivate_payment_method' => array(
93
-                'func'       => '_deactivate_payment_method',
94
-                'noheader'   => true,
95
-                'capability' => 'ee_delete_payment_methods',
96
-            ),
97
-            'update_payment_method'     => array(
98
-                'func'               => '_update_payment_method',
99
-                'noheader'           => true,
100
-                'headers_sent_route' => 'default',
101
-                'capability'         => 'ee_edit_payment_methods',
102
-            ),
103
-            'update_payment_settings'   => array(
104
-                'func'       => '_update_payment_settings',
105
-                'noheader'   => true,
106
-                'capability' => 'ee_manage_gateways',
107
-            ),
108
-            'payment_log'               => array(
109
-                'func'       => '_payment_log_overview_list_table',
110
-                'capability' => 'ee_read_payment_methods',
111
-            ),
112
-            'payment_log_details'       => array(
113
-                'func'       => '_payment_log_details',
114
-                'capability' => 'ee_read_payment_methods',
115
-            ),
116
-        );
117
-    }
118
-
119
-
120
-    protected function _set_page_config()
121
-    {
122
-        $payment_method_list_config = array(
123
-            'nav'           => array(
124
-                'label' => __('Payment Methods', 'event_espresso'),
125
-                'order' => 10,
126
-            ),
127
-            'metaboxes'     => $this->_default_espresso_metaboxes,
128
-            'help_tabs'     => array_merge(
129
-                array(
130
-                    'payment_methods_overview_help_tab' => array(
131
-                        'title'    => __('Payment Methods Overview', 'event_espresso'),
132
-                        'filename' => 'payment_methods_overview',
133
-                    ),
134
-                ),
135
-                $this->_add_payment_method_help_tabs()
136
-            ),
137
-            // disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836
138
-            // 'help_tour'     => array('Payment_Methods_Selection_Help_Tour'),
139
-            'require_nonce' => false,
140
-        );
141
-        $this->_page_config = array(
142
-            'default'          => $payment_method_list_config,
143
-            'payment_settings' => array(
144
-                'nav'           => array(
145
-                    'label' => __('Settings', 'event_espresso'),
146
-                    'order' => 20,
147
-                ),
148
-                'help_tabs'     => array(
149
-                    'payment_methods_settings_help_tab' => array(
150
-                        'title'    => __('Payment Method Settings', 'event_espresso'),
151
-                        'filename' => 'payment_methods_settings',
152
-                    ),
153
-                ),
154
-                // 'help_tour' => array( 'Payment_Methods_Settings_Help_Tour' ),
155
-                'metaboxes'     => array_merge($this->_default_espresso_metaboxes, array('_publish_post_box')),
156
-                'require_nonce' => false,
157
-            ),
158
-            'payment_log'      => array(
159
-                'nav'           => array(
160
-                    'label' => __("Logs", 'event_espresso'),
161
-                    'order' => 30,
162
-                ),
163
-                'list_table'    => 'Payment_Log_Admin_List_Table',
164
-                'metaboxes'     => $this->_default_espresso_metaboxes,
165
-                'require_nonce' => false,
166
-            ),
167
-        );
168
-    }
169
-
170
-
171
-    /**
172
-     * @return array
173
-     * @throws DomainException
174
-     * @throws EE_Error
175
-     * @throws InvalidArgumentException
176
-     * @throws InvalidDataTypeException
177
-     * @throws InvalidInterfaceException
178
-     * @throws ReflectionException
179
-     */
180
-    protected function _add_payment_method_help_tabs()
181
-    {
182
-        EE_Registry::instance()->load_lib('Payment_Method_Manager');
183
-        $payment_method_types = EE_Payment_Method_Manager::instance()->payment_method_types();
184
-        $all_pmt_help_tabs_config = array();
185
-        foreach ($payment_method_types as $payment_method_type) {
186
-            if (
187
-                ! EE_Registry::instance()->CAP->current_user_can(
188
-                    $payment_method_type->cap_name(),
189
-                    'specific_payment_method_type_access'
190
-                )
191
-            ) {
192
-                continue;
193
-            }
194
-            foreach ($payment_method_type->help_tabs_config() as $help_tab_name => $config) {
195
-                $template_args = isset($config['template_args']) ? $config['template_args'] : array();
196
-                $template_args['admin_page_obj'] = $this;
197
-                $all_pmt_help_tabs_config[ $help_tab_name ] = array(
198
-                    'title'   => $config['title'],
199
-                    'content' => EEH_Template::display_template(
200
-                        $payment_method_type->file_folder() . 'help_tabs/' . $config['filename'] . '.help_tab.php',
201
-                        $template_args,
202
-                        true
203
-                    ),
204
-                );
205
-            }
206
-        }
207
-        return $all_pmt_help_tabs_config;
208
-    }
209
-
210
-
211
-    // none of the below group are currently used for Gateway Settings
212
-    protected function _add_screen_options()
213
-    {
214
-    }
215
-
216
-
217
-    protected function _add_feature_pointers()
218
-    {
219
-    }
220
-
221
-
222
-    public function admin_init()
223
-    {
224
-    }
225
-
226
-
227
-    public function admin_notices()
228
-    {
229
-    }
230
-
231
-
232
-    public function admin_footer_scripts()
233
-    {
234
-    }
235
-
236
-
237
-    public function load_scripts_styles()
238
-    {
239
-        // styles
240
-        wp_enqueue_style('espresso-ui-theme');
241
-        wp_register_style(
242
-            'espresso_payments',
243
-            EE_PAYMENTS_ASSETS_URL . 'ee-payments.css',
244
-            [],
245
-            EVENT_ESPRESSO_VERSION
246
-        );
247
-        // scripts
248
-        wp_enqueue_script('ee_admin_js');
249
-        wp_enqueue_script('ee-text-links');
250
-        wp_enqueue_script(
251
-            'espresso_payments',
252
-            EE_PAYMENTS_ASSETS_URL . 'espresso_payments_admin.js',
253
-            ['ee-datepicker'],
254
-            EVENT_ESPRESSO_VERSION,
255
-            true
256
-        );
257
-    }
258
-
259
-
260
-    public function load_scripts_styles_default()
261
-    {
262
-        wp_enqueue_style('espresso_payments');
263
-        wp_enqueue_style('ee-text-links');
264
-    }
265
-
266
-
267
-    public function load_scripts_styles_payment_log_details()
268
-    {
269
-        wp_enqueue_style('espresso_payments');
270
-    }
271
-
272
-
273
-    protected function _payment_methods_list()
274
-    {
275
-        /**
276
-         * first let's ensure payment methods have been setup. We do this here because when people activate a
277
-         * payment method for the first time (as an addon), it may not setup its capabilities or get registered
278
-         * correctly due to the loading process.  However, people MUST setup the details for the payment method so its
279
-         * safe to do a recheck here.
280
-         */
281
-        EE_Registry::instance()->load_lib('Payment_Method_Manager');
282
-        EEM_Payment_Method::instance()->verify_button_urls();
283
-        // setup tabs, one for each payment method type
284
-        $tabs = array();
285
-        $payment_methods = array();
286
-        foreach (EE_Payment_Method_Manager::instance()->payment_method_types() as $pmt_obj) {
287
-            // we don't want to show admin-only PMTs for now
288
-            if ($pmt_obj instanceof EE_PMT_Admin_Only) {
289
-                continue;
290
-            }
291
-            // check access
292
-            if (
293
-                ! EE_Registry::instance()->CAP->current_user_can(
294
-                    $pmt_obj->cap_name(),
295
-                    'specific_payment_method_type_access'
296
-                )
297
-            ) {
298
-                continue;
299
-            }
300
-            // check for any active pms of that type
301
-            $payment_method = EEM_Payment_Method::instance()->get_one_of_type($pmt_obj->system_name());
302
-            if (! $payment_method instanceof EE_Payment_Method) {
303
-                $payment_method = EE_Payment_Method::new_instance(
304
-                    array(
305
-                        'PMD_slug'       => sanitize_key($pmt_obj->system_name()),
306
-                        'PMD_type'       => $pmt_obj->system_name(),
307
-                        'PMD_name'       => $pmt_obj->pretty_name(),
308
-                        'PMD_admin_name' => $pmt_obj->pretty_name(),
309
-                    )
310
-                );
311
-            }
312
-            $payment_methods[ $payment_method->slug() ] = $payment_method;
313
-        }
314
-        $payment_methods = apply_filters(
315
-            'FHEE__Payments_Admin_Page___payment_methods_list__payment_methods',
316
-            $payment_methods
317
-        );
318
-        foreach ($payment_methods as $payment_method) {
319
-            if ($payment_method instanceof EE_Payment_Method) {
320
-                add_meta_box(
321
-                    // html id
322
-                    'espresso_' . $payment_method->slug() . '_payment_settings',
323
-                    // title
324
-                    sprintf(__('%s Settings', 'event_espresso'), $payment_method->admin_name()),
325
-                    // callback
326
-                    array($this, 'payment_method_settings_meta_box'),
327
-                    // post type
328
-                    null,
329
-                    // context
330
-                    'normal',
331
-                    // priority
332
-                    'default',
333
-                    // callback args
334
-                    array('payment_method' => $payment_method)
335
-                );
336
-                // setup for tabbed content
337
-                $tabs[ $payment_method->slug() ] = array(
338
-                    'label' => $payment_method->admin_name(),
339
-                    'class' => $payment_method->active() ? 'gateway-active' : '',
340
-                    'href'  => 'espresso_' . $payment_method->slug() . '_payment_settings',
341
-                    'title' => __('Modify this Payment Method', 'event_espresso'),
342
-                    'slug'  => $payment_method->slug(),
343
-                );
344
-            }
345
-        }
346
-        $this->_template_args['admin_page_header'] = EEH_Tabbed_Content::tab_text_links(
347
-            $tabs,
348
-            'payment_method_links',
349
-            '|',
350
-            $this->_get_active_payment_method_slug()
351
-        );
352
-        $this->display_admin_page_with_sidebar();
353
-    }
354
-
355
-
356
-    /**
357
-     *   _get_active_payment_method_slug
358
-     *
359
-     * @return string
360
-     */
361
-    protected function _get_active_payment_method_slug()
362
-    {
363
-        $payment_method_slug = false;
364
-        // decide which payment method tab to open first, as dictated by the request's 'payment_method'
365
-        if (isset($this->_req_data['payment_method'])) {
366
-            // if they provided the current payment method, use it
367
-            $payment_method_slug = sanitize_key($this->_req_data['payment_method']);
368
-        }
369
-        $payment_method = EEM_Payment_Method::instance()->get_one(array(array('PMD_slug' => $payment_method_slug)));
370
-        // if that didn't work or wasn't provided, find another way to select the current pm
371
-        if (! $this->_verify_payment_method($payment_method)) {
372
-            // like, looking for an active one
373
-            $payment_method = EEM_Payment_Method::instance()->get_one_active('CART');
374
-            // test that one as well
375
-            if ($this->_verify_payment_method($payment_method)) {
376
-                $payment_method_slug = $payment_method->slug();
377
-            } else {
378
-                $payment_method_slug = 'paypal_standard';
379
-            }
380
-        }
381
-        return $payment_method_slug;
382
-    }
383
-
384
-
385
-    /**
386
-     *    payment_method_settings_meta_box
387
-     *    returns TRUE if the passed payment method is properly constructed and the logged in user has the correct
388
-     *    capabilities to access it
389
-     *
390
-     * @param EE_Payment_Method $payment_method
391
-     * @return boolean
392
-     */
393
-    protected function _verify_payment_method($payment_method)
394
-    {
395
-        if (
396
-            $payment_method instanceof EE_Payment_Method && $payment_method->type_obj() instanceof EE_PMT_Base
397
-            && EE_Registry::instance()->CAP->current_user_can(
398
-                $payment_method->type_obj()->cap_name(),
399
-                'specific_payment_method_type_access'
400
-            )
401
-        ) {
402
-            return true;
403
-        }
404
-        return false;
405
-    }
406
-
407
-
408
-    /**
409
-     *    payment_method_settings_meta_box
410
-     *
411
-     * @param NULL  $post_obj_which_is_null is an object containing the current post (as a $post object)
412
-     * @param array $metabox                is an array with metabox id, title, callback, and args elements. the value
413
-     *                                      at 'args' has key 'payment_method', as set within _payment_methods_list
414
-     * @return string
415
-     * @throws EE_Error
416
-     */
417
-    public function payment_method_settings_meta_box($post_obj_which_is_null, $metabox)
418
-    {
419
-        $payment_method = isset($metabox['args'], $metabox['args']['payment_method'])
420
-            ? $metabox['args']['payment_method'] : null;
421
-        if (! $payment_method instanceof EE_Payment_Method) {
422
-            throw new EE_Error(
423
-                sprintf(
424
-                    __(
425
-                        'Payment method metabox setup incorrectly. No Payment method object was supplied',
426
-                        'event_espresso'
427
-                    )
428
-                )
429
-            );
430
-        }
431
-        $payment_method_scopes = $payment_method->active();
432
-        // if the payment method really exists show its form, otherwise the activation template
433
-        if ($payment_method->ID() && ! empty($payment_method_scopes)) {
434
-            $form = $this->_generate_payment_method_settings_form($payment_method);
435
-            if ($form->form_data_present_in($this->_req_data)) {
436
-                $form->receive_form_submission($this->_req_data);
437
-            }
438
-            echo $form->form_open() . $form->get_html_and_js() . $form->form_close();
439
-        } else {
440
-            echo $this->_activate_payment_method_button($payment_method)->get_html_and_js();
441
-        }
442
-    }
443
-
444
-
445
-    /**
446
-     * Gets the form for all the settings related to this payment method type
447
-     *
448
-     * @access protected
449
-     * @param EE_Payment_Method $payment_method
450
-     * @return EE_Form_Section_Proper
451
-     */
452
-    protected function _generate_payment_method_settings_form(EE_Payment_Method $payment_method)
453
-    {
454
-        if (! $payment_method instanceof EE_Payment_Method) {
455
-            return new EE_Form_Section_Proper();
456
-        }
457
-        return new EE_Form_Section_Proper(
458
-            array(
459
-                'name'            => $payment_method->slug() . '_settings_form',
460
-                'html_id'         => $payment_method->slug() . '_settings_form',
461
-                'action'          => EE_Admin_Page::add_query_args_and_nonce(
462
-                    array(
463
-                        'action'         => 'update_payment_method',
464
-                        'payment_method' => $payment_method->slug(),
465
-                    ),
466
-                    EE_PAYMENTS_ADMIN_URL
467
-                ),
468
-                'layout_strategy' => new EE_Admin_Two_Column_Layout(),
469
-                'subsections'     => apply_filters(
470
-                    'FHEE__Payments_Admin_Page___generate_payment_method_settings_form__form_subsections',
471
-                    array(
472
-                        'pci_dss_compliance'      => $this->_pci_dss_compliance($payment_method),
473
-                        'currency_support'        => $this->_currency_support($payment_method),
474
-                        'payment_method_settings' => $this->_payment_method_settings($payment_method),
475
-                        'update'                  => $this->_update_payment_method_button($payment_method),
476
-                        'deactivate'              => $this->_deactivate_payment_method_button($payment_method),
477
-                        'fine_print'              => $this->_fine_print(),
478
-                    ),
479
-                    $payment_method
480
-                ),
481
-            )
482
-        );
483
-    }
484
-
485
-
486
-    /**
487
-     * _pci_dss_compliance
488
-     *
489
-     * @access protected
490
-     * @param EE_Payment_Method $payment_method
491
-     * @return EE_Form_Section_Proper
492
-     */
493
-    protected function _pci_dss_compliance(EE_Payment_Method $payment_method)
494
-    {
495
-        if ($payment_method->type_obj()->requires_https()) {
496
-            return new EE_Form_Section_HTML(
497
-                EEH_HTML::table(
498
-                    EEH_HTML::tr(
499
-                        EEH_HTML::th(
500
-                            EEH_HTML::label(
501
-                                EEH_HTML::strong(__('IMPORTANT', 'event_espresso'), '', 'important-notice')
502
-                            )
503
-                        ) .
504
-                        EEH_HTML::td(
505
-                            EEH_HTML::strong(
506
-                                __(
507
-                                    'You are responsible for your own website security and Payment Card Industry Data Security Standards (PCI DSS) compliance.',
508
-                                    'event_espresso'
509
-                                )
510
-                            )
511
-                            .
512
-                            EEH_HTML::br()
513
-                            .
514
-                            __('Learn more about ', 'event_espresso')
515
-                            . EEH_HTML::link(
516
-                                'https://www.pcisecuritystandards.org/merchants/index.php',
517
-                                __('PCI DSS compliance', 'event_espresso')
518
-                            )
519
-                        )
520
-                    )
521
-                )
522
-            );
523
-        } else {
524
-            return new EE_Form_Section_HTML('');
525
-        }
526
-    }
527
-
528
-
529
-    /**
530
-     * _currency_support
531
-     *
532
-     * @access protected
533
-     * @param EE_Payment_Method $payment_method
534
-     * @return EE_Form_Section_Proper
535
-     */
536
-    protected function _currency_support(EE_Payment_Method $payment_method)
537
-    {
538
-        if (! $payment_method->usable_for_currency(EE_Config::instance()->currency->code)) {
539
-            return new EE_Form_Section_HTML(
540
-                EEH_HTML::table(
541
-                    EEH_HTML::tr(
542
-                        EEH_HTML::th(
543
-                            EEH_HTML::label(
544
-                                EEH_HTML::strong(__('IMPORTANT', 'event_espresso'), '', 'important-notice')
545
-                            )
546
-                        ) .
547
-                        EEH_HTML::td(
548
-                            EEH_HTML::strong(
549
-                                sprintf(
550
-                                    __(
551
-                                        'This payment method does not support the currency set on your site (%1$s). Please activate a different payment method or change your site\'s country and associated currency.',
552
-                                        'event_espresso'
553
-                                    ),
554
-                                    EE_Config::instance()->currency->code
555
-                                )
556
-                            )
557
-                        )
558
-                    )
559
-                )
560
-            );
561
-        } else {
562
-            return new EE_Form_Section_HTML('');
563
-        }
564
-    }
565
-
566
-
567
-    /**
568
-     * _update_payment_method_button
569
-     *
570
-     * @access protected
571
-     * @param EE_Payment_Method $payment_method
572
-     * @return EE_Payment_Method_Form
573
-     */
574
-    protected function _payment_method_settings(EE_Payment_Method $payment_method)
575
-    {
576
-        // modify the form so we only have/show fields that will be implemented for this version
577
-        return $this->_simplify_form($payment_method->type_obj()->settings_form(), $payment_method->name());
578
-    }
579
-
580
-
581
-    /**
582
-     * Simplifies the form to merely reproduce 4.1's gateway settings functionality
583
-     *
584
-     * @param EE_Form_Section_Proper $form_section
585
-     * @param string                 $payment_method_name
586
-     * @return EE_Payment_Method_Form
587
-     * @throws EE_Error
588
-     */
589
-    protected function _simplify_form($form_section, $payment_method_name = '')
590
-    {
591
-        if ($form_section instanceof EE_Payment_Method_Form) {
592
-            $form_section->exclude(
593
-                array(
594
-                    'PMD_type', // dont want them changing the type
595
-                    'PMD_slug', // or the slug (probably never)
596
-                    'PMD_wp_user', // or the user's ID
597
-                    'Currency' // or the currency, until the rest of EE supports simultaneous currencies
598
-                )
599
-            );
600
-            return $form_section;
601
-        } else {
602
-            throw new EE_Error(
603
-                sprintf(
604
-                    __(
605
-                        'The EE_Payment_Method_Form for the "%1$s" payment method is missing or invalid.',
606
-                        'event_espresso'
607
-                    ),
608
-                    $payment_method_name
609
-                )
610
-            );
611
-        }
612
-    }
613
-
614
-
615
-    /**
616
-     * _update_payment_method_button
617
-     *
618
-     * @access protected
619
-     * @param EE_Payment_Method $payment_method
620
-     * @return EE_Form_Section_HTML
621
-     */
622
-    protected function _update_payment_method_button(EE_Payment_Method $payment_method)
623
-    {
624
-        $update_button = new EE_Submit_Input(
625
-            array(
626
-                'name'       => 'submit',
627
-                'html_id'    => 'save_' . $payment_method->slug() . '_settings',
628
-                'default'    => sprintf(
629
-                    __('Update %s Payment Settings', 'event_espresso'),
630
-                    $payment_method->admin_name()
631
-                ),
632
-                'html_label' => EEH_HTML::nbsp(),
633
-            )
634
-        );
635
-        return new EE_Form_Section_HTML(
636
-            EEH_HTML::table(
637
-                EEH_HTML::no_row(EEH_HTML::br(2)) .
638
-                EEH_HTML::tr(
639
-                    EEH_HTML::th(__('Update Settings', 'event_espresso')) .
640
-                    EEH_HTML::td(
641
-                        $update_button->get_html_for_input()
642
-                    )
643
-                )
644
-            )
645
-        );
646
-    }
647
-
648
-
649
-    /**
650
-     * _deactivate_payment_method_button
651
-     *
652
-     * @access protected
653
-     * @param EE_Payment_Method $payment_method
654
-     * @return EE_Form_Section_Proper
655
-     */
656
-    protected function _deactivate_payment_method_button(EE_Payment_Method $payment_method)
657
-    {
658
-        $link_text_and_title = sprintf(
659
-            __('Deactivate %1$s Payments?', 'event_espresso'),
660
-            $payment_method->admin_name()
661
-        );
662
-        return new EE_Form_Section_HTML(
663
-            EEH_HTML::table(
664
-                EEH_HTML::tr(
665
-                    EEH_HTML::th(__('Deactivate Payment Method', 'event_espresso')) .
666
-                    EEH_HTML::td(
667
-                        EEH_HTML::link(
668
-                            EE_Admin_Page::add_query_args_and_nonce(
669
-                                array(
670
-                                    'action'         => 'deactivate_payment_method',
671
-                                    'payment_method' => $payment_method->slug(),
672
-                                ),
673
-                                EE_PAYMENTS_ADMIN_URL
674
-                            ),
675
-                            $link_text_and_title,
676
-                            $link_text_and_title,
677
-                            'deactivate_' . $payment_method->slug(),
678
-                            'espresso-button button-secondary'
679
-                        )
680
-                    )
681
-                )
682
-            )
683
-        );
684
-    }
685
-
686
-
687
-    /**
688
-     * _activate_payment_method_button
689
-     *
690
-     * @access protected
691
-     * @param EE_Payment_Method $payment_method
692
-     * @return EE_Form_Section_Proper
693
-     */
694
-    protected function _activate_payment_method_button(EE_Payment_Method $payment_method)
695
-    {
696
-        $link_text_and_title = sprintf(
697
-            __('Activate %1$s Payment Method?', 'event_espresso'),
698
-            $payment_method->admin_name()
699
-        );
700
-        return new EE_Form_Section_Proper(
701
-            array(
702
-                'name'            => 'activate_' . $payment_method->slug() . '_settings_form',
703
-                'html_id'         => 'activate_' . $payment_method->slug() . '_settings_form',
704
-                'action'          => '#',
705
-                'layout_strategy' => new EE_Admin_Two_Column_Layout(),
706
-                'subsections'     => apply_filters(
707
-                    'FHEE__Payments_Admin_Page___activate_payment_method_button__form_subsections',
708
-                    array(
709
-                        new EE_Form_Section_HTML(
710
-                            EEH_HTML::table(
711
-                                EEH_HTML::tr(
712
-                                    EEH_HTML::td(
713
-                                        $payment_method->type_obj()->introductory_html(),
714
-                                        '',
715
-                                        '',
716
-                                        '',
717
-                                        'colspan="2"'
718
-                                    )
719
-                                ) .
720
-                                EEH_HTML::tr(
721
-                                    EEH_HTML::th(
722
-                                        EEH_HTML::label(__('Click to Activate ', 'event_espresso'))
723
-                                    ) .
724
-                                    EEH_HTML::td(
725
-                                        EEH_HTML::link(
726
-                                            EE_Admin_Page::add_query_args_and_nonce(
727
-                                                array(
728
-                                                    'action'              => 'activate_payment_method',
729
-                                                    'payment_method_type' => $payment_method->type(),
730
-                                                ),
731
-                                                EE_PAYMENTS_ADMIN_URL
732
-                                            ),
733
-                                            $link_text_and_title,
734
-                                            $link_text_and_title,
735
-                                            'activate_' . $payment_method->slug(),
736
-                                            'espresso-button-green button-primary'
737
-                                        )
738
-                                    )
739
-                                )
740
-                            )
741
-                        ),
742
-                    ),
743
-                    $payment_method
744
-                ),
745
-            )
746
-        );
747
-    }
748
-
749
-
750
-    /**
751
-     * _fine_print
752
-     *
753
-     * @access protected
754
-     * @return EE_Form_Section_HTML
755
-     */
756
-    protected function _fine_print()
757
-    {
758
-        return new EE_Form_Section_HTML(
759
-            EEH_HTML::table(
760
-                EEH_HTML::tr(
761
-                    EEH_HTML::th() .
762
-                    EEH_HTML::td(
763
-                        EEH_HTML::p(__('All fields marked with a * are required fields', 'event_espresso'), '', 'grey-text')
764
-                    )
765
-                )
766
-            )
767
-        );
768
-    }
769
-
770
-
771
-    /**
772
-     * Activates a payment method of that type. Mostly assuming there is only 1 of that type (or none so far)
773
-     *
774
-     * @global WP_User $current_user
775
-     */
776
-    protected function _activate_payment_method()
777
-    {
778
-        if (isset($this->_req_data['payment_method_type'])) {
779
-            $payment_method_type = sanitize_text_field($this->_req_data['payment_method_type']);
780
-            // see if one exists
781
-            EE_Registry::instance()->load_lib('Payment_Method_Manager');
782
-            $payment_method = EE_Payment_Method_Manager::instance()
783
-                                                       ->activate_a_payment_method_of_type($payment_method_type);
784
-            $this->_redirect_after_action(
785
-                1,
786
-                'Payment Method',
787
-                'activated',
788
-                array('action' => 'default', 'payment_method' => $payment_method->slug())
789
-            );
790
-        } else {
791
-            $this->_redirect_after_action(false, 'Payment Method', 'activated', array('action' => 'default'));
792
-        }
793
-    }
794
-
795
-
796
-    /**
797
-     * Deactivates the payment method with the specified slug, and redirects.
798
-     */
799
-    protected function _deactivate_payment_method()
800
-    {
801
-        if (isset($this->_req_data['payment_method'])) {
802
-            $payment_method_slug = sanitize_key($this->_req_data['payment_method']);
803
-            // deactivate it
804
-            EE_Registry::instance()->load_lib('Payment_Method_Manager');
805
-            $count_updated = EE_Payment_Method_Manager::instance()->deactivate_payment_method($payment_method_slug);
806
-            $this->_redirect_after_action(
807
-                $count_updated,
808
-                'Payment Method',
809
-                'deactivated',
810
-                array('action' => 'default', 'payment_method' => $payment_method_slug)
811
-            );
812
-        } else {
813
-            $this->_redirect_after_action(false, 'Payment Method', 'deactivated', array('action' => 'default'));
814
-        }
815
-    }
816
-
817
-
818
-    /**
819
-     * Processes the payment method form that was submitted. This is slightly trickier than usual form
820
-     * processing because we first need to identify WHICH form was processed and which payment method
821
-     * it corresponds to. Once we have done that, we see if the form is valid. If it is, the
822
-     * form's data is saved and we redirect to the default payment methods page, setting the updated payment method
823
-     * as the currently-selected one. If it DOESN'T validate, we render the page with the form's errors (in the
824
-     * subsequently called 'headers_sent_func' which is _payment_methods_list)
825
-     *
826
-     * @return void
827
-     */
828
-    protected function _update_payment_method()
829
-    {
830
-        if ($_SERVER['REQUEST_METHOD'] == 'POST') {
831
-            // ok let's find which gateway form to use based on the form input
832
-            EE_Registry::instance()->load_lib('Payment_Method_Manager');
833
-            /** @var $correct_pmt_form_to_use EE_Payment_Method_Form */
834
-            $correct_pmt_form_to_use = null;
835
-            $payment_method = null;
836
-            foreach (EEM_Payment_Method::instance()->get_all() as $payment_method) {
837
-                // get the form and simplify it, like what we do when we display it
838
-                $pmt_form = $this->_generate_payment_method_settings_form($payment_method);
839
-                if ($pmt_form->form_data_present_in($this->_req_data)) {
840
-                    $correct_pmt_form_to_use = $pmt_form;
841
-                    break;
842
-                }
843
-            }
844
-            // if we couldn't find the correct payment method type...
845
-            if (! $correct_pmt_form_to_use) {
846
-                EE_Error::add_error(
847
-                    __(
848
-                        "We could not find which payment method type your form submission related to. Please contact support",
849
-                        'event_espresso'
850
-                    ),
851
-                    __FILE__,
852
-                    __FUNCTION__,
853
-                    __LINE__
854
-                );
855
-                $this->_redirect_after_action(false, 'Payment Method', 'activated', array('action' => 'default'));
856
-            }
857
-            $correct_pmt_form_to_use->receive_form_submission($this->_req_data);
858
-            if ($correct_pmt_form_to_use->is_valid()) {
859
-                $payment_settings_subform = $correct_pmt_form_to_use->get_subsection('payment_method_settings');
860
-                if (! $payment_settings_subform instanceof EE_Payment_Method_Form) {
861
-                    throw new EE_Error(
862
-                        sprintf(
863
-                            __(
864
-                                'The payment method could not be saved because the form sections were misnamed. We expected to find %1$s, but did not.',
865
-                                'event_espresso'
866
-                            ),
867
-                            'payment_method_settings'
868
-                        )
869
-                    );
870
-                }
871
-                $payment_settings_subform->save();
872
-                /** @var $pm EE_Payment_Method */
873
-                $this->_redirect_after_action(
874
-                    true,
875
-                    'Payment Method',
876
-                    'updated',
877
-                    array('action' => 'default', 'payment_method' => $payment_method->slug())
878
-                );
879
-            } else {
880
-                EE_Error::add_error(
881
-                    sprintf(
882
-                        __(
883
-                            'Payment method of type %s was not saved because there were validation errors. They have been marked in the form',
884
-                            'event_espresso'
885
-                        ),
886
-                        $payment_method instanceof EE_Payment_Method ? $payment_method->type_obj()->pretty_name()
887
-                            : __('"(unknown)"', 'event_espresso')
888
-                    ),
889
-                    __FILE__,
890
-                    __FUNCTION__,
891
-                    __LINE__
892
-                );
893
-            }
894
-        }
895
-        return;
896
-    }
897
-
898
-
899
-    /**
900
-     * Displays payment settings (not payment METHOD settings, that's _payment_method_settings)
901
-     * @throws DomainException
902
-     * @throws EE_Error
903
-     * @throws InvalidArgumentException
904
-     * @throws InvalidDataTypeException
905
-     * @throws InvalidInterfaceException
906
-     */
907
-    protected function _payment_settings()
908
-    {
909
-        $form = $this->getPaymentSettingsForm();
910
-        $this->_set_add_edit_form_tags('update_payment_settings');
911
-        $this->_set_publish_post_box_vars(null, false, false, null, false);
912
-        $this->_template_args['admin_page_content'] =  $form->get_html_and_js();
913
-        $this->display_admin_page_with_sidebar();
914
-    }
915
-
916
-
917
-    /**
918
-     *        _update_payment_settings
919
-     *
920
-     * @access protected
921
-     * @return void
922
-     * @throws EE_Error
923
-     * @throws InvalidArgumentException
924
-     * @throws InvalidDataTypeException
925
-     * @throws InvalidInterfaceException
926
-     */
927
-    protected function _update_payment_settings()
928
-    {
929
-        $form = $this->getPaymentSettingsForm();
930
-        if ($form->was_submitted($this->_req_data)) {
931
-            $form->receive_form_submission($this->_req_data);
932
-            if ($form->is_valid()) {
933
-                /**
934
-                 * @var $reg_config EE_Registration_Config
935
-                 */
936
-                $loader = LoaderFactory::getLoader();
937
-                $reg_config = $loader->getShared('EE_Registration_Config');
938
-                $valid_data = $form->valid_data();
939
-                $reg_config->show_pending_payment_options = $valid_data['show_pending_payment_options'];
940
-                $reg_config->gateway_log_lifespan = $valid_data['gateway_log_lifespan'];
941
-            }
942
-        }
943
-        EE_Registry::instance()->CFG = apply_filters(
944
-            'FHEE__Payments_Admin_Page___update_payment_settings__CFG',
945
-            EE_Registry::instance()->CFG
946
-        );
947
-
948
-        $cfg =  EE_Registry::instance()->CFG ;
949
-
950
-        $what = __('Payment Settings', 'event_espresso');
951
-        $success = $this->_update_espresso_configuration(
952
-            $what,
953
-            EE_Registry::instance()->CFG,
954
-            __FILE__,
955
-            __FUNCTION__,
956
-            __LINE__
957
-        );
958
-        $this->_redirect_after_action(
959
-            $success,
960
-            $what,
961
-            __('updated', 'event_espresso'),
962
-            array('action' => 'payment_settings')
963
-        );
964
-    }
965
-
966
-
967
-    /**
968
-     * Gets the form used for updating payment settings
969
-     *
970
-     * @return EE_Form_Section_Proper
971
-     * @throws EE_Error
972
-     * @throws InvalidArgumentException
973
-     * @throws InvalidDataTypeException
974
-     * @throws InvalidInterfaceException
975
-     */
976
-    protected function getPaymentSettingsForm()
977
-    {
978
-        /**
979
-         * @var $reg_config EE_Registration_Config
980
-         */
981
-        $reg_config = LoaderFactory::getLoader()->getShared('EE_Registration_Config');
982
-        return new EE_Form_Section_Proper(
983
-            array(
984
-                'name' => 'payment-settings',
985
-                'layout_strategy' => new EE_Admin_Two_Column_Layout(),
986
-                'subsections' => array(
987
-                    'show_pending_payment_options' => new EE_Yes_No_Input(
988
-                        array(
989
-                            'html_name' => 'show_pending_payment_options',
990
-                            'default' => $reg_config->show_pending_payment_options,
991
-                            'html_help_text' => esc_html__(
992
-                                "If a payment is marked as 'Pending Payment', or if payment is deferred (ie, an offline gateway like Check, Bank, or Invoice is used), then give registrants the option to retry payment. ",
993
-                                'event_espresso'
994
-                            )
995
-                        )
996
-                    ),
997
-                    'gateway_log_lifespan' => new EE_Select_Input(
998
-                        $reg_config->gatewayLogLifespanOptions(),
999
-                        array(
1000
-                            'html_label_text' => esc_html__('Gateway Logs Lifespan', 'event_espresso'),
1001
-                            'html_help_text' => esc_html__('If issues arise with payments being made through a payment gateway, it\'s helpful to log non-sensitive communications with the payment gateway. But it\'s a security responsibility, so it\'s a good idea to not keep them for any longer than necessary.', 'event_espresso'),
1002
-                            'default' => $reg_config->gateway_log_lifespan,
1003
-                        )
1004
-                    )
1005
-                )
1006
-            )
1007
-        );
1008
-    }
1009
-
1010
-
1011
-    protected function _payment_log_overview_list_table()
1012
-    {
1013
-        $this->display_admin_list_table_page_with_sidebar();
1014
-    }
1015
-
1016
-
1017
-    protected function _set_list_table_views_payment_log()
1018
-    {
1019
-        $this->_views = array(
1020
-            'all' => array(
1021
-                'slug'  => 'all',
1022
-                'label' => __('View All Logs', 'event_espresso'),
1023
-                'count' => 0,
1024
-            ),
1025
-        );
1026
-    }
1027
-
1028
-
1029
-    /**
1030
-     * @param int  $per_page
1031
-     * @param int  $current_page
1032
-     * @param bool $count
1033
-     * @return array
1034
-     */
1035
-    public function get_payment_logs($per_page = 50, $current_page = 0, $count = false)
1036
-    {
1037
-        EE_Registry::instance()->load_model('Change_Log');
1038
-        // we may need to do multiple queries (joining differently), so we actually wan tan array of query params
1039
-        $query_params = array(array('LOG_type' => EEM_Change_Log::type_gateway));
1040
-        // check if they've selected a specific payment method
1041
-        if (isset($this->_req_data['_payment_method']) && $this->_req_data['_payment_method'] !== 'all') {
1042
-            $query_params[0]['OR*pm_or_pay_pm'] = array(
1043
-                'Payment.Payment_Method.PMD_ID' => $this->_req_data['_payment_method'],
1044
-                'Payment_Method.PMD_ID'         => $this->_req_data['_payment_method'],
1045
-            );
1046
-        }
1047
-        // take into account search
1048
-        if (isset($this->_req_data['s']) && $this->_req_data['s']) {
1049
-            $similarity_string = array('LIKE', '%' . str_replace("", "%", $this->_req_data['s']) . '%');
1050
-            $query_params[0]['OR*s']['Payment.Transaction.Registration.Attendee.ATT_fname'] = $similarity_string;
1051
-            $query_params[0]['OR*s']['Payment.Transaction.Registration.Attendee.ATT_lname'] = $similarity_string;
1052
-            $query_params[0]['OR*s']['Payment.Transaction.Registration.Attendee.ATT_email'] = $similarity_string;
1053
-            $query_params[0]['OR*s']['Payment.Payment_Method.PMD_name'] = $similarity_string;
1054
-            $query_params[0]['OR*s']['Payment.Payment_Method.PMD_admin_name'] = $similarity_string;
1055
-            $query_params[0]['OR*s']['Payment.Payment_Method.PMD_type'] = $similarity_string;
1056
-            $query_params[0]['OR*s']['LOG_message'] = $similarity_string;
1057
-            $query_params[0]['OR*s']['Payment_Method.PMD_name'] = $similarity_string;
1058
-            $query_params[0]['OR*s']['Payment_Method.PMD_admin_name'] = $similarity_string;
1059
-            $query_params[0]['OR*s']['Payment_Method.PMD_type'] = $similarity_string;
1060
-            $query_params[0]['OR*s']['LOG_message'] = $similarity_string;
1061
-        }
1062
-        if (
1063
-            isset($this->_req_data['payment-filter-start-date'])
1064
-            && isset($this->_req_data['payment-filter-end-date'])
1065
-        ) {
1066
-            // add date
1067
-            $start_date = wp_strip_all_tags($this->_req_data['payment-filter-start-date']);
1068
-            $end_date = wp_strip_all_tags($this->_req_data['payment-filter-end-date']);
1069
-            // make sure our timestamps start and end right at the boundaries for each day
1070
-            $start_date = date('Y-m-d', strtotime($start_date)) . ' 00:00:00';
1071
-            $end_date = date('Y-m-d', strtotime($end_date)) . ' 23:59:59';
1072
-            // convert to timestamps
1073
-            $start_date = strtotime($start_date);
1074
-            $end_date = strtotime($end_date);
1075
-            // makes sure start date is the lowest value and vice versa
1076
-            $start_date = min($start_date, $end_date);
1077
-            $end_date = max($start_date, $end_date);
1078
-            // convert for query
1079
-            $start_date = EEM_Change_Log::instance()
1080
-                                        ->convert_datetime_for_query(
1081
-                                            'LOG_time',
1082
-                                            date('Y-m-d H:i:s', $start_date),
1083
-                                            'Y-m-d H:i:s'
1084
-                                        );
1085
-            $end_date = EEM_Change_Log::instance()
1086
-                                      ->convert_datetime_for_query(
1087
-                                          'LOG_time',
1088
-                                          date('Y-m-d H:i:s', $end_date),
1089
-                                          'Y-m-d H:i:s'
1090
-                                      );
1091
-            $query_params[0]['LOG_time'] = array('BETWEEN', array($start_date, $end_date));
1092
-        }
1093
-        if ($count) {
1094
-            return EEM_Change_Log::instance()->count($query_params);
1095
-        }
1096
-        if (isset($this->_req_data['order'])) {
1097
-            $sort = (isset($this->_req_data['order']) && ! empty($this->_req_data['order'])) ? $this->_req_data['order']
1098
-                : 'DESC';
1099
-            $query_params['order_by'] = array('LOG_time' => $sort);
1100
-        } else {
1101
-            $query_params['order_by'] = array('LOG_time' => 'DESC');
1102
-        }
1103
-        $offset = ($current_page - 1) * $per_page;
1104
-        if (! isset($this->_req_data['download_results'])) {
1105
-            $query_params['limit'] = array($offset, $per_page);
1106
-        }
1107
-        // now they've requested to instead just download the file instead of viewing it.
1108
-        if (isset($this->_req_data['download_results'])) {
1109
-            $wpdb_results = EEM_Change_Log::instance()->get_all_efficiently($query_params);
1110
-            header('Content-Disposition: attachment');
1111
-            header("Content-Disposition: attachment; filename=ee_payment_logs_for_" . sanitize_key(site_url()));
1112
-            echo "<h1>Payment Logs for " . site_url() . "</h1>";
1113
-            echo "<h3>Query:</h3>";
1114
-            var_dump($query_params);
1115
-            echo "<h3>Results:</h3>";
1116
-            var_dump($wpdb_results);
1117
-            die;
1118
-        }
1119
-        $results = EEM_Change_Log::instance()->get_all($query_params);
1120
-        return $results;
1121
-    }
1122
-
1123
-
1124
-    /**
1125
-     * Used by usort to RE-sort log query results, because we lose the ordering
1126
-     * because we're possibly combining the results from two queries
1127
-     *
1128
-     * @param EE_Change_Log $logA
1129
-     * @param EE_Change_Log $logB
1130
-     * @return int
1131
-     */
1132
-    protected function _sort_logs_again($logA, $logB)
1133
-    {
1134
-        $timeA = $logA->get_raw('LOG_time');
1135
-        $timeB = $logB->get_raw('LOG_time');
1136
-        if ($timeA == $timeB) {
1137
-            return 0;
1138
-        }
1139
-        $comparison = $timeA < $timeB ? -1 : 1;
1140
-        if (strtoupper($this->_sort_logs_again_direction) == 'DESC') {
1141
-            return $comparison * -1;
1142
-        } else {
1143
-            return $comparison;
1144
-        }
1145
-    }
1146
-
1147
-
1148
-    protected function _payment_log_details()
1149
-    {
1150
-        EE_Registry::instance()->load_model('Change_Log');
1151
-        /** @var $payment_log EE_Change_Log */
1152
-        $payment_log = EEM_Change_Log::instance()->get_one_by_ID($this->_req_data['ID']);
1153
-        $payment_method = null;
1154
-        $transaction = null;
1155
-        if ($payment_log instanceof EE_Change_Log) {
1156
-            if ($payment_log->object() instanceof EE_Payment) {
1157
-                $payment_method = $payment_log->object()->payment_method();
1158
-                $transaction = $payment_log->object()->transaction();
1159
-            } elseif ($payment_log->object() instanceof EE_Payment_Method) {
1160
-                $payment_method = $payment_log->object();
1161
-            } elseif ($payment_log->object() instanceof EE_Transaction) {
1162
-                $transaction = $payment_log->object();
1163
-                $payment_method = $transaction->payment_method();
1164
-            }
1165
-        }
1166
-        $this->_template_args['admin_page_content'] = EEH_Template::display_template(
1167
-            EE_PAYMENTS_TEMPLATE_PATH . 'payment_log_details.template.php',
1168
-            array(
1169
-                'payment_log'    => $payment_log,
1170
-                'payment_method' => $payment_method,
1171
-                'transaction'    => $transaction,
1172
-            ),
1173
-            true
1174
-        );
1175
-        $this->display_admin_page_with_no_sidebar();
1176
-    }
19
+	/**
20
+	 * Variables used for when we're re-sorting the logs results, in case
21
+	 * we needed to do two queries and we need to resort
22
+	 *
23
+	 * @var string
24
+	 */
25
+	private $_sort_logs_again_direction;
26
+
27
+
28
+	/**
29
+	 * @Constructor
30
+	 * @access public
31
+	 * @param bool $routing indicate whether we want to just load the object and handle routing or just load the object.
32
+	 * @throws EE_Error
33
+	 * @throws InvalidArgumentException
34
+	 * @throws InvalidDataTypeException
35
+	 * @throws InvalidInterfaceException
36
+	 * @throws ReflectionException
37
+	 */
38
+	public function __construct($routing = true)
39
+	{
40
+		parent::__construct($routing);
41
+	}
42
+
43
+
44
+	protected function _init_page_props()
45
+	{
46
+		$this->page_slug = EE_PAYMENTS_PG_SLUG;
47
+		$this->page_label = __('Payment Methods', 'event_espresso');
48
+		$this->_admin_base_url = EE_PAYMENTS_ADMIN_URL;
49
+		$this->_admin_base_path = EE_PAYMENTS_ADMIN;
50
+	}
51
+
52
+
53
+	protected function _ajax_hooks()
54
+	{
55
+		// todo: all hooks for ajax goes here.
56
+	}
57
+
58
+
59
+	protected function _define_page_props()
60
+	{
61
+		$this->_admin_page_title = $this->page_label;
62
+		$this->_labels = array(
63
+			'publishbox' => __('Update Settings', 'event_espresso'),
64
+		);
65
+	}
66
+
67
+
68
+	protected function _set_page_routes()
69
+	{
70
+		/**
71
+		 * note that with payment method capabilities, although we've implemented
72
+		 * capability mapping which will be used for accessing payment methods owned by
73
+		 * other users.  This is not fully implemented yet in the payment method ui.
74
+		 * Currently only the "plural" caps are in active use.
75
+		 * When cap mapping is implemented, some routes will need to use the singular form of
76
+		 * capability method and also include the $id of the payment method for the route.
77
+		 **/
78
+		$this->_page_routes = array(
79
+			'default'                   => array(
80
+				'func'       => '_payment_methods_list',
81
+				'capability' => 'ee_edit_payment_methods',
82
+			),
83
+			'payment_settings'          => array(
84
+				'func'       => '_payment_settings',
85
+				'capability' => 'ee_manage_gateways',
86
+			),
87
+			'activate_payment_method'   => array(
88
+				'func'       => '_activate_payment_method',
89
+				'noheader'   => true,
90
+				'capability' => 'ee_edit_payment_methods',
91
+			),
92
+			'deactivate_payment_method' => array(
93
+				'func'       => '_deactivate_payment_method',
94
+				'noheader'   => true,
95
+				'capability' => 'ee_delete_payment_methods',
96
+			),
97
+			'update_payment_method'     => array(
98
+				'func'               => '_update_payment_method',
99
+				'noheader'           => true,
100
+				'headers_sent_route' => 'default',
101
+				'capability'         => 'ee_edit_payment_methods',
102
+			),
103
+			'update_payment_settings'   => array(
104
+				'func'       => '_update_payment_settings',
105
+				'noheader'   => true,
106
+				'capability' => 'ee_manage_gateways',
107
+			),
108
+			'payment_log'               => array(
109
+				'func'       => '_payment_log_overview_list_table',
110
+				'capability' => 'ee_read_payment_methods',
111
+			),
112
+			'payment_log_details'       => array(
113
+				'func'       => '_payment_log_details',
114
+				'capability' => 'ee_read_payment_methods',
115
+			),
116
+		);
117
+	}
118
+
119
+
120
+	protected function _set_page_config()
121
+	{
122
+		$payment_method_list_config = array(
123
+			'nav'           => array(
124
+				'label' => __('Payment Methods', 'event_espresso'),
125
+				'order' => 10,
126
+			),
127
+			'metaboxes'     => $this->_default_espresso_metaboxes,
128
+			'help_tabs'     => array_merge(
129
+				array(
130
+					'payment_methods_overview_help_tab' => array(
131
+						'title'    => __('Payment Methods Overview', 'event_espresso'),
132
+						'filename' => 'payment_methods_overview',
133
+					),
134
+				),
135
+				$this->_add_payment_method_help_tabs()
136
+			),
137
+			// disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836
138
+			// 'help_tour'     => array('Payment_Methods_Selection_Help_Tour'),
139
+			'require_nonce' => false,
140
+		);
141
+		$this->_page_config = array(
142
+			'default'          => $payment_method_list_config,
143
+			'payment_settings' => array(
144
+				'nav'           => array(
145
+					'label' => __('Settings', 'event_espresso'),
146
+					'order' => 20,
147
+				),
148
+				'help_tabs'     => array(
149
+					'payment_methods_settings_help_tab' => array(
150
+						'title'    => __('Payment Method Settings', 'event_espresso'),
151
+						'filename' => 'payment_methods_settings',
152
+					),
153
+				),
154
+				// 'help_tour' => array( 'Payment_Methods_Settings_Help_Tour' ),
155
+				'metaboxes'     => array_merge($this->_default_espresso_metaboxes, array('_publish_post_box')),
156
+				'require_nonce' => false,
157
+			),
158
+			'payment_log'      => array(
159
+				'nav'           => array(
160
+					'label' => __("Logs", 'event_espresso'),
161
+					'order' => 30,
162
+				),
163
+				'list_table'    => 'Payment_Log_Admin_List_Table',
164
+				'metaboxes'     => $this->_default_espresso_metaboxes,
165
+				'require_nonce' => false,
166
+			),
167
+		);
168
+	}
169
+
170
+
171
+	/**
172
+	 * @return array
173
+	 * @throws DomainException
174
+	 * @throws EE_Error
175
+	 * @throws InvalidArgumentException
176
+	 * @throws InvalidDataTypeException
177
+	 * @throws InvalidInterfaceException
178
+	 * @throws ReflectionException
179
+	 */
180
+	protected function _add_payment_method_help_tabs()
181
+	{
182
+		EE_Registry::instance()->load_lib('Payment_Method_Manager');
183
+		$payment_method_types = EE_Payment_Method_Manager::instance()->payment_method_types();
184
+		$all_pmt_help_tabs_config = array();
185
+		foreach ($payment_method_types as $payment_method_type) {
186
+			if (
187
+				! EE_Registry::instance()->CAP->current_user_can(
188
+					$payment_method_type->cap_name(),
189
+					'specific_payment_method_type_access'
190
+				)
191
+			) {
192
+				continue;
193
+			}
194
+			foreach ($payment_method_type->help_tabs_config() as $help_tab_name => $config) {
195
+				$template_args = isset($config['template_args']) ? $config['template_args'] : array();
196
+				$template_args['admin_page_obj'] = $this;
197
+				$all_pmt_help_tabs_config[ $help_tab_name ] = array(
198
+					'title'   => $config['title'],
199
+					'content' => EEH_Template::display_template(
200
+						$payment_method_type->file_folder() . 'help_tabs/' . $config['filename'] . '.help_tab.php',
201
+						$template_args,
202
+						true
203
+					),
204
+				);
205
+			}
206
+		}
207
+		return $all_pmt_help_tabs_config;
208
+	}
209
+
210
+
211
+	// none of the below group are currently used for Gateway Settings
212
+	protected function _add_screen_options()
213
+	{
214
+	}
215
+
216
+
217
+	protected function _add_feature_pointers()
218
+	{
219
+	}
220
+
221
+
222
+	public function admin_init()
223
+	{
224
+	}
225
+
226
+
227
+	public function admin_notices()
228
+	{
229
+	}
230
+
231
+
232
+	public function admin_footer_scripts()
233
+	{
234
+	}
235
+
236
+
237
+	public function load_scripts_styles()
238
+	{
239
+		// styles
240
+		wp_enqueue_style('espresso-ui-theme');
241
+		wp_register_style(
242
+			'espresso_payments',
243
+			EE_PAYMENTS_ASSETS_URL . 'ee-payments.css',
244
+			[],
245
+			EVENT_ESPRESSO_VERSION
246
+		);
247
+		// scripts
248
+		wp_enqueue_script('ee_admin_js');
249
+		wp_enqueue_script('ee-text-links');
250
+		wp_enqueue_script(
251
+			'espresso_payments',
252
+			EE_PAYMENTS_ASSETS_URL . 'espresso_payments_admin.js',
253
+			['ee-datepicker'],
254
+			EVENT_ESPRESSO_VERSION,
255
+			true
256
+		);
257
+	}
258
+
259
+
260
+	public function load_scripts_styles_default()
261
+	{
262
+		wp_enqueue_style('espresso_payments');
263
+		wp_enqueue_style('ee-text-links');
264
+	}
265
+
266
+
267
+	public function load_scripts_styles_payment_log_details()
268
+	{
269
+		wp_enqueue_style('espresso_payments');
270
+	}
271
+
272
+
273
+	protected function _payment_methods_list()
274
+	{
275
+		/**
276
+		 * first let's ensure payment methods have been setup. We do this here because when people activate a
277
+		 * payment method for the first time (as an addon), it may not setup its capabilities or get registered
278
+		 * correctly due to the loading process.  However, people MUST setup the details for the payment method so its
279
+		 * safe to do a recheck here.
280
+		 */
281
+		EE_Registry::instance()->load_lib('Payment_Method_Manager');
282
+		EEM_Payment_Method::instance()->verify_button_urls();
283
+		// setup tabs, one for each payment method type
284
+		$tabs = array();
285
+		$payment_methods = array();
286
+		foreach (EE_Payment_Method_Manager::instance()->payment_method_types() as $pmt_obj) {
287
+			// we don't want to show admin-only PMTs for now
288
+			if ($pmt_obj instanceof EE_PMT_Admin_Only) {
289
+				continue;
290
+			}
291
+			// check access
292
+			if (
293
+				! EE_Registry::instance()->CAP->current_user_can(
294
+					$pmt_obj->cap_name(),
295
+					'specific_payment_method_type_access'
296
+				)
297
+			) {
298
+				continue;
299
+			}
300
+			// check for any active pms of that type
301
+			$payment_method = EEM_Payment_Method::instance()->get_one_of_type($pmt_obj->system_name());
302
+			if (! $payment_method instanceof EE_Payment_Method) {
303
+				$payment_method = EE_Payment_Method::new_instance(
304
+					array(
305
+						'PMD_slug'       => sanitize_key($pmt_obj->system_name()),
306
+						'PMD_type'       => $pmt_obj->system_name(),
307
+						'PMD_name'       => $pmt_obj->pretty_name(),
308
+						'PMD_admin_name' => $pmt_obj->pretty_name(),
309
+					)
310
+				);
311
+			}
312
+			$payment_methods[ $payment_method->slug() ] = $payment_method;
313
+		}
314
+		$payment_methods = apply_filters(
315
+			'FHEE__Payments_Admin_Page___payment_methods_list__payment_methods',
316
+			$payment_methods
317
+		);
318
+		foreach ($payment_methods as $payment_method) {
319
+			if ($payment_method instanceof EE_Payment_Method) {
320
+				add_meta_box(
321
+					// html id
322
+					'espresso_' . $payment_method->slug() . '_payment_settings',
323
+					// title
324
+					sprintf(__('%s Settings', 'event_espresso'), $payment_method->admin_name()),
325
+					// callback
326
+					array($this, 'payment_method_settings_meta_box'),
327
+					// post type
328
+					null,
329
+					// context
330
+					'normal',
331
+					// priority
332
+					'default',
333
+					// callback args
334
+					array('payment_method' => $payment_method)
335
+				);
336
+				// setup for tabbed content
337
+				$tabs[ $payment_method->slug() ] = array(
338
+					'label' => $payment_method->admin_name(),
339
+					'class' => $payment_method->active() ? 'gateway-active' : '',
340
+					'href'  => 'espresso_' . $payment_method->slug() . '_payment_settings',
341
+					'title' => __('Modify this Payment Method', 'event_espresso'),
342
+					'slug'  => $payment_method->slug(),
343
+				);
344
+			}
345
+		}
346
+		$this->_template_args['admin_page_header'] = EEH_Tabbed_Content::tab_text_links(
347
+			$tabs,
348
+			'payment_method_links',
349
+			'|',
350
+			$this->_get_active_payment_method_slug()
351
+		);
352
+		$this->display_admin_page_with_sidebar();
353
+	}
354
+
355
+
356
+	/**
357
+	 *   _get_active_payment_method_slug
358
+	 *
359
+	 * @return string
360
+	 */
361
+	protected function _get_active_payment_method_slug()
362
+	{
363
+		$payment_method_slug = false;
364
+		// decide which payment method tab to open first, as dictated by the request's 'payment_method'
365
+		if (isset($this->_req_data['payment_method'])) {
366
+			// if they provided the current payment method, use it
367
+			$payment_method_slug = sanitize_key($this->_req_data['payment_method']);
368
+		}
369
+		$payment_method = EEM_Payment_Method::instance()->get_one(array(array('PMD_slug' => $payment_method_slug)));
370
+		// if that didn't work or wasn't provided, find another way to select the current pm
371
+		if (! $this->_verify_payment_method($payment_method)) {
372
+			// like, looking for an active one
373
+			$payment_method = EEM_Payment_Method::instance()->get_one_active('CART');
374
+			// test that one as well
375
+			if ($this->_verify_payment_method($payment_method)) {
376
+				$payment_method_slug = $payment_method->slug();
377
+			} else {
378
+				$payment_method_slug = 'paypal_standard';
379
+			}
380
+		}
381
+		return $payment_method_slug;
382
+	}
383
+
384
+
385
+	/**
386
+	 *    payment_method_settings_meta_box
387
+	 *    returns TRUE if the passed payment method is properly constructed and the logged in user has the correct
388
+	 *    capabilities to access it
389
+	 *
390
+	 * @param EE_Payment_Method $payment_method
391
+	 * @return boolean
392
+	 */
393
+	protected function _verify_payment_method($payment_method)
394
+	{
395
+		if (
396
+			$payment_method instanceof EE_Payment_Method && $payment_method->type_obj() instanceof EE_PMT_Base
397
+			&& EE_Registry::instance()->CAP->current_user_can(
398
+				$payment_method->type_obj()->cap_name(),
399
+				'specific_payment_method_type_access'
400
+			)
401
+		) {
402
+			return true;
403
+		}
404
+		return false;
405
+	}
406
+
407
+
408
+	/**
409
+	 *    payment_method_settings_meta_box
410
+	 *
411
+	 * @param NULL  $post_obj_which_is_null is an object containing the current post (as a $post object)
412
+	 * @param array $metabox                is an array with metabox id, title, callback, and args elements. the value
413
+	 *                                      at 'args' has key 'payment_method', as set within _payment_methods_list
414
+	 * @return string
415
+	 * @throws EE_Error
416
+	 */
417
+	public function payment_method_settings_meta_box($post_obj_which_is_null, $metabox)
418
+	{
419
+		$payment_method = isset($metabox['args'], $metabox['args']['payment_method'])
420
+			? $metabox['args']['payment_method'] : null;
421
+		if (! $payment_method instanceof EE_Payment_Method) {
422
+			throw new EE_Error(
423
+				sprintf(
424
+					__(
425
+						'Payment method metabox setup incorrectly. No Payment method object was supplied',
426
+						'event_espresso'
427
+					)
428
+				)
429
+			);
430
+		}
431
+		$payment_method_scopes = $payment_method->active();
432
+		// if the payment method really exists show its form, otherwise the activation template
433
+		if ($payment_method->ID() && ! empty($payment_method_scopes)) {
434
+			$form = $this->_generate_payment_method_settings_form($payment_method);
435
+			if ($form->form_data_present_in($this->_req_data)) {
436
+				$form->receive_form_submission($this->_req_data);
437
+			}
438
+			echo $form->form_open() . $form->get_html_and_js() . $form->form_close();
439
+		} else {
440
+			echo $this->_activate_payment_method_button($payment_method)->get_html_and_js();
441
+		}
442
+	}
443
+
444
+
445
+	/**
446
+	 * Gets the form for all the settings related to this payment method type
447
+	 *
448
+	 * @access protected
449
+	 * @param EE_Payment_Method $payment_method
450
+	 * @return EE_Form_Section_Proper
451
+	 */
452
+	protected function _generate_payment_method_settings_form(EE_Payment_Method $payment_method)
453
+	{
454
+		if (! $payment_method instanceof EE_Payment_Method) {
455
+			return new EE_Form_Section_Proper();
456
+		}
457
+		return new EE_Form_Section_Proper(
458
+			array(
459
+				'name'            => $payment_method->slug() . '_settings_form',
460
+				'html_id'         => $payment_method->slug() . '_settings_form',
461
+				'action'          => EE_Admin_Page::add_query_args_and_nonce(
462
+					array(
463
+						'action'         => 'update_payment_method',
464
+						'payment_method' => $payment_method->slug(),
465
+					),
466
+					EE_PAYMENTS_ADMIN_URL
467
+				),
468
+				'layout_strategy' => new EE_Admin_Two_Column_Layout(),
469
+				'subsections'     => apply_filters(
470
+					'FHEE__Payments_Admin_Page___generate_payment_method_settings_form__form_subsections',
471
+					array(
472
+						'pci_dss_compliance'      => $this->_pci_dss_compliance($payment_method),
473
+						'currency_support'        => $this->_currency_support($payment_method),
474
+						'payment_method_settings' => $this->_payment_method_settings($payment_method),
475
+						'update'                  => $this->_update_payment_method_button($payment_method),
476
+						'deactivate'              => $this->_deactivate_payment_method_button($payment_method),
477
+						'fine_print'              => $this->_fine_print(),
478
+					),
479
+					$payment_method
480
+				),
481
+			)
482
+		);
483
+	}
484
+
485
+
486
+	/**
487
+	 * _pci_dss_compliance
488
+	 *
489
+	 * @access protected
490
+	 * @param EE_Payment_Method $payment_method
491
+	 * @return EE_Form_Section_Proper
492
+	 */
493
+	protected function _pci_dss_compliance(EE_Payment_Method $payment_method)
494
+	{
495
+		if ($payment_method->type_obj()->requires_https()) {
496
+			return new EE_Form_Section_HTML(
497
+				EEH_HTML::table(
498
+					EEH_HTML::tr(
499
+						EEH_HTML::th(
500
+							EEH_HTML::label(
501
+								EEH_HTML::strong(__('IMPORTANT', 'event_espresso'), '', 'important-notice')
502
+							)
503
+						) .
504
+						EEH_HTML::td(
505
+							EEH_HTML::strong(
506
+								__(
507
+									'You are responsible for your own website security and Payment Card Industry Data Security Standards (PCI DSS) compliance.',
508
+									'event_espresso'
509
+								)
510
+							)
511
+							.
512
+							EEH_HTML::br()
513
+							.
514
+							__('Learn more about ', 'event_espresso')
515
+							. EEH_HTML::link(
516
+								'https://www.pcisecuritystandards.org/merchants/index.php',
517
+								__('PCI DSS compliance', 'event_espresso')
518
+							)
519
+						)
520
+					)
521
+				)
522
+			);
523
+		} else {
524
+			return new EE_Form_Section_HTML('');
525
+		}
526
+	}
527
+
528
+
529
+	/**
530
+	 * _currency_support
531
+	 *
532
+	 * @access protected
533
+	 * @param EE_Payment_Method $payment_method
534
+	 * @return EE_Form_Section_Proper
535
+	 */
536
+	protected function _currency_support(EE_Payment_Method $payment_method)
537
+	{
538
+		if (! $payment_method->usable_for_currency(EE_Config::instance()->currency->code)) {
539
+			return new EE_Form_Section_HTML(
540
+				EEH_HTML::table(
541
+					EEH_HTML::tr(
542
+						EEH_HTML::th(
543
+							EEH_HTML::label(
544
+								EEH_HTML::strong(__('IMPORTANT', 'event_espresso'), '', 'important-notice')
545
+							)
546
+						) .
547
+						EEH_HTML::td(
548
+							EEH_HTML::strong(
549
+								sprintf(
550
+									__(
551
+										'This payment method does not support the currency set on your site (%1$s). Please activate a different payment method or change your site\'s country and associated currency.',
552
+										'event_espresso'
553
+									),
554
+									EE_Config::instance()->currency->code
555
+								)
556
+							)
557
+						)
558
+					)
559
+				)
560
+			);
561
+		} else {
562
+			return new EE_Form_Section_HTML('');
563
+		}
564
+	}
565
+
566
+
567
+	/**
568
+	 * _update_payment_method_button
569
+	 *
570
+	 * @access protected
571
+	 * @param EE_Payment_Method $payment_method
572
+	 * @return EE_Payment_Method_Form
573
+	 */
574
+	protected function _payment_method_settings(EE_Payment_Method $payment_method)
575
+	{
576
+		// modify the form so we only have/show fields that will be implemented for this version
577
+		return $this->_simplify_form($payment_method->type_obj()->settings_form(), $payment_method->name());
578
+	}
579
+
580
+
581
+	/**
582
+	 * Simplifies the form to merely reproduce 4.1's gateway settings functionality
583
+	 *
584
+	 * @param EE_Form_Section_Proper $form_section
585
+	 * @param string                 $payment_method_name
586
+	 * @return EE_Payment_Method_Form
587
+	 * @throws EE_Error
588
+	 */
589
+	protected function _simplify_form($form_section, $payment_method_name = '')
590
+	{
591
+		if ($form_section instanceof EE_Payment_Method_Form) {
592
+			$form_section->exclude(
593
+				array(
594
+					'PMD_type', // dont want them changing the type
595
+					'PMD_slug', // or the slug (probably never)
596
+					'PMD_wp_user', // or the user's ID
597
+					'Currency' // or the currency, until the rest of EE supports simultaneous currencies
598
+				)
599
+			);
600
+			return $form_section;
601
+		} else {
602
+			throw new EE_Error(
603
+				sprintf(
604
+					__(
605
+						'The EE_Payment_Method_Form for the "%1$s" payment method is missing or invalid.',
606
+						'event_espresso'
607
+					),
608
+					$payment_method_name
609
+				)
610
+			);
611
+		}
612
+	}
613
+
614
+
615
+	/**
616
+	 * _update_payment_method_button
617
+	 *
618
+	 * @access protected
619
+	 * @param EE_Payment_Method $payment_method
620
+	 * @return EE_Form_Section_HTML
621
+	 */
622
+	protected function _update_payment_method_button(EE_Payment_Method $payment_method)
623
+	{
624
+		$update_button = new EE_Submit_Input(
625
+			array(
626
+				'name'       => 'submit',
627
+				'html_id'    => 'save_' . $payment_method->slug() . '_settings',
628
+				'default'    => sprintf(
629
+					__('Update %s Payment Settings', 'event_espresso'),
630
+					$payment_method->admin_name()
631
+				),
632
+				'html_label' => EEH_HTML::nbsp(),
633
+			)
634
+		);
635
+		return new EE_Form_Section_HTML(
636
+			EEH_HTML::table(
637
+				EEH_HTML::no_row(EEH_HTML::br(2)) .
638
+				EEH_HTML::tr(
639
+					EEH_HTML::th(__('Update Settings', 'event_espresso')) .
640
+					EEH_HTML::td(
641
+						$update_button->get_html_for_input()
642
+					)
643
+				)
644
+			)
645
+		);
646
+	}
647
+
648
+
649
+	/**
650
+	 * _deactivate_payment_method_button
651
+	 *
652
+	 * @access protected
653
+	 * @param EE_Payment_Method $payment_method
654
+	 * @return EE_Form_Section_Proper
655
+	 */
656
+	protected function _deactivate_payment_method_button(EE_Payment_Method $payment_method)
657
+	{
658
+		$link_text_and_title = sprintf(
659
+			__('Deactivate %1$s Payments?', 'event_espresso'),
660
+			$payment_method->admin_name()
661
+		);
662
+		return new EE_Form_Section_HTML(
663
+			EEH_HTML::table(
664
+				EEH_HTML::tr(
665
+					EEH_HTML::th(__('Deactivate Payment Method', 'event_espresso')) .
666
+					EEH_HTML::td(
667
+						EEH_HTML::link(
668
+							EE_Admin_Page::add_query_args_and_nonce(
669
+								array(
670
+									'action'         => 'deactivate_payment_method',
671
+									'payment_method' => $payment_method->slug(),
672
+								),
673
+								EE_PAYMENTS_ADMIN_URL
674
+							),
675
+							$link_text_and_title,
676
+							$link_text_and_title,
677
+							'deactivate_' . $payment_method->slug(),
678
+							'espresso-button button-secondary'
679
+						)
680
+					)
681
+				)
682
+			)
683
+		);
684
+	}
685
+
686
+
687
+	/**
688
+	 * _activate_payment_method_button
689
+	 *
690
+	 * @access protected
691
+	 * @param EE_Payment_Method $payment_method
692
+	 * @return EE_Form_Section_Proper
693
+	 */
694
+	protected function _activate_payment_method_button(EE_Payment_Method $payment_method)
695
+	{
696
+		$link_text_and_title = sprintf(
697
+			__('Activate %1$s Payment Method?', 'event_espresso'),
698
+			$payment_method->admin_name()
699
+		);
700
+		return new EE_Form_Section_Proper(
701
+			array(
702
+				'name'            => 'activate_' . $payment_method->slug() . '_settings_form',
703
+				'html_id'         => 'activate_' . $payment_method->slug() . '_settings_form',
704
+				'action'          => '#',
705
+				'layout_strategy' => new EE_Admin_Two_Column_Layout(),
706
+				'subsections'     => apply_filters(
707
+					'FHEE__Payments_Admin_Page___activate_payment_method_button__form_subsections',
708
+					array(
709
+						new EE_Form_Section_HTML(
710
+							EEH_HTML::table(
711
+								EEH_HTML::tr(
712
+									EEH_HTML::td(
713
+										$payment_method->type_obj()->introductory_html(),
714
+										'',
715
+										'',
716
+										'',
717
+										'colspan="2"'
718
+									)
719
+								) .
720
+								EEH_HTML::tr(
721
+									EEH_HTML::th(
722
+										EEH_HTML::label(__('Click to Activate ', 'event_espresso'))
723
+									) .
724
+									EEH_HTML::td(
725
+										EEH_HTML::link(
726
+											EE_Admin_Page::add_query_args_and_nonce(
727
+												array(
728
+													'action'              => 'activate_payment_method',
729
+													'payment_method_type' => $payment_method->type(),
730
+												),
731
+												EE_PAYMENTS_ADMIN_URL
732
+											),
733
+											$link_text_and_title,
734
+											$link_text_and_title,
735
+											'activate_' . $payment_method->slug(),
736
+											'espresso-button-green button-primary'
737
+										)
738
+									)
739
+								)
740
+							)
741
+						),
742
+					),
743
+					$payment_method
744
+				),
745
+			)
746
+		);
747
+	}
748
+
749
+
750
+	/**
751
+	 * _fine_print
752
+	 *
753
+	 * @access protected
754
+	 * @return EE_Form_Section_HTML
755
+	 */
756
+	protected function _fine_print()
757
+	{
758
+		return new EE_Form_Section_HTML(
759
+			EEH_HTML::table(
760
+				EEH_HTML::tr(
761
+					EEH_HTML::th() .
762
+					EEH_HTML::td(
763
+						EEH_HTML::p(__('All fields marked with a * are required fields', 'event_espresso'), '', 'grey-text')
764
+					)
765
+				)
766
+			)
767
+		);
768
+	}
769
+
770
+
771
+	/**
772
+	 * Activates a payment method of that type. Mostly assuming there is only 1 of that type (or none so far)
773
+	 *
774
+	 * @global WP_User $current_user
775
+	 */
776
+	protected function _activate_payment_method()
777
+	{
778
+		if (isset($this->_req_data['payment_method_type'])) {
779
+			$payment_method_type = sanitize_text_field($this->_req_data['payment_method_type']);
780
+			// see if one exists
781
+			EE_Registry::instance()->load_lib('Payment_Method_Manager');
782
+			$payment_method = EE_Payment_Method_Manager::instance()
783
+													   ->activate_a_payment_method_of_type($payment_method_type);
784
+			$this->_redirect_after_action(
785
+				1,
786
+				'Payment Method',
787
+				'activated',
788
+				array('action' => 'default', 'payment_method' => $payment_method->slug())
789
+			);
790
+		} else {
791
+			$this->_redirect_after_action(false, 'Payment Method', 'activated', array('action' => 'default'));
792
+		}
793
+	}
794
+
795
+
796
+	/**
797
+	 * Deactivates the payment method with the specified slug, and redirects.
798
+	 */
799
+	protected function _deactivate_payment_method()
800
+	{
801
+		if (isset($this->_req_data['payment_method'])) {
802
+			$payment_method_slug = sanitize_key($this->_req_data['payment_method']);
803
+			// deactivate it
804
+			EE_Registry::instance()->load_lib('Payment_Method_Manager');
805
+			$count_updated = EE_Payment_Method_Manager::instance()->deactivate_payment_method($payment_method_slug);
806
+			$this->_redirect_after_action(
807
+				$count_updated,
808
+				'Payment Method',
809
+				'deactivated',
810
+				array('action' => 'default', 'payment_method' => $payment_method_slug)
811
+			);
812
+		} else {
813
+			$this->_redirect_after_action(false, 'Payment Method', 'deactivated', array('action' => 'default'));
814
+		}
815
+	}
816
+
817
+
818
+	/**
819
+	 * Processes the payment method form that was submitted. This is slightly trickier than usual form
820
+	 * processing because we first need to identify WHICH form was processed and which payment method
821
+	 * it corresponds to. Once we have done that, we see if the form is valid. If it is, the
822
+	 * form's data is saved and we redirect to the default payment methods page, setting the updated payment method
823
+	 * as the currently-selected one. If it DOESN'T validate, we render the page with the form's errors (in the
824
+	 * subsequently called 'headers_sent_func' which is _payment_methods_list)
825
+	 *
826
+	 * @return void
827
+	 */
828
+	protected function _update_payment_method()
829
+	{
830
+		if ($_SERVER['REQUEST_METHOD'] == 'POST') {
831
+			// ok let's find which gateway form to use based on the form input
832
+			EE_Registry::instance()->load_lib('Payment_Method_Manager');
833
+			/** @var $correct_pmt_form_to_use EE_Payment_Method_Form */
834
+			$correct_pmt_form_to_use = null;
835
+			$payment_method = null;
836
+			foreach (EEM_Payment_Method::instance()->get_all() as $payment_method) {
837
+				// get the form and simplify it, like what we do when we display it
838
+				$pmt_form = $this->_generate_payment_method_settings_form($payment_method);
839
+				if ($pmt_form->form_data_present_in($this->_req_data)) {
840
+					$correct_pmt_form_to_use = $pmt_form;
841
+					break;
842
+				}
843
+			}
844
+			// if we couldn't find the correct payment method type...
845
+			if (! $correct_pmt_form_to_use) {
846
+				EE_Error::add_error(
847
+					__(
848
+						"We could not find which payment method type your form submission related to. Please contact support",
849
+						'event_espresso'
850
+					),
851
+					__FILE__,
852
+					__FUNCTION__,
853
+					__LINE__
854
+				);
855
+				$this->_redirect_after_action(false, 'Payment Method', 'activated', array('action' => 'default'));
856
+			}
857
+			$correct_pmt_form_to_use->receive_form_submission($this->_req_data);
858
+			if ($correct_pmt_form_to_use->is_valid()) {
859
+				$payment_settings_subform = $correct_pmt_form_to_use->get_subsection('payment_method_settings');
860
+				if (! $payment_settings_subform instanceof EE_Payment_Method_Form) {
861
+					throw new EE_Error(
862
+						sprintf(
863
+							__(
864
+								'The payment method could not be saved because the form sections were misnamed. We expected to find %1$s, but did not.',
865
+								'event_espresso'
866
+							),
867
+							'payment_method_settings'
868
+						)
869
+					);
870
+				}
871
+				$payment_settings_subform->save();
872
+				/** @var $pm EE_Payment_Method */
873
+				$this->_redirect_after_action(
874
+					true,
875
+					'Payment Method',
876
+					'updated',
877
+					array('action' => 'default', 'payment_method' => $payment_method->slug())
878
+				);
879
+			} else {
880
+				EE_Error::add_error(
881
+					sprintf(
882
+						__(
883
+							'Payment method of type %s was not saved because there were validation errors. They have been marked in the form',
884
+							'event_espresso'
885
+						),
886
+						$payment_method instanceof EE_Payment_Method ? $payment_method->type_obj()->pretty_name()
887
+							: __('"(unknown)"', 'event_espresso')
888
+					),
889
+					__FILE__,
890
+					__FUNCTION__,
891
+					__LINE__
892
+				);
893
+			}
894
+		}
895
+		return;
896
+	}
897
+
898
+
899
+	/**
900
+	 * Displays payment settings (not payment METHOD settings, that's _payment_method_settings)
901
+	 * @throws DomainException
902
+	 * @throws EE_Error
903
+	 * @throws InvalidArgumentException
904
+	 * @throws InvalidDataTypeException
905
+	 * @throws InvalidInterfaceException
906
+	 */
907
+	protected function _payment_settings()
908
+	{
909
+		$form = $this->getPaymentSettingsForm();
910
+		$this->_set_add_edit_form_tags('update_payment_settings');
911
+		$this->_set_publish_post_box_vars(null, false, false, null, false);
912
+		$this->_template_args['admin_page_content'] =  $form->get_html_and_js();
913
+		$this->display_admin_page_with_sidebar();
914
+	}
915
+
916
+
917
+	/**
918
+	 *        _update_payment_settings
919
+	 *
920
+	 * @access protected
921
+	 * @return void
922
+	 * @throws EE_Error
923
+	 * @throws InvalidArgumentException
924
+	 * @throws InvalidDataTypeException
925
+	 * @throws InvalidInterfaceException
926
+	 */
927
+	protected function _update_payment_settings()
928
+	{
929
+		$form = $this->getPaymentSettingsForm();
930
+		if ($form->was_submitted($this->_req_data)) {
931
+			$form->receive_form_submission($this->_req_data);
932
+			if ($form->is_valid()) {
933
+				/**
934
+				 * @var $reg_config EE_Registration_Config
935
+				 */
936
+				$loader = LoaderFactory::getLoader();
937
+				$reg_config = $loader->getShared('EE_Registration_Config');
938
+				$valid_data = $form->valid_data();
939
+				$reg_config->show_pending_payment_options = $valid_data['show_pending_payment_options'];
940
+				$reg_config->gateway_log_lifespan = $valid_data['gateway_log_lifespan'];
941
+			}
942
+		}
943
+		EE_Registry::instance()->CFG = apply_filters(
944
+			'FHEE__Payments_Admin_Page___update_payment_settings__CFG',
945
+			EE_Registry::instance()->CFG
946
+		);
947
+
948
+		$cfg =  EE_Registry::instance()->CFG ;
949
+
950
+		$what = __('Payment Settings', 'event_espresso');
951
+		$success = $this->_update_espresso_configuration(
952
+			$what,
953
+			EE_Registry::instance()->CFG,
954
+			__FILE__,
955
+			__FUNCTION__,
956
+			__LINE__
957
+		);
958
+		$this->_redirect_after_action(
959
+			$success,
960
+			$what,
961
+			__('updated', 'event_espresso'),
962
+			array('action' => 'payment_settings')
963
+		);
964
+	}
965
+
966
+
967
+	/**
968
+	 * Gets the form used for updating payment settings
969
+	 *
970
+	 * @return EE_Form_Section_Proper
971
+	 * @throws EE_Error
972
+	 * @throws InvalidArgumentException
973
+	 * @throws InvalidDataTypeException
974
+	 * @throws InvalidInterfaceException
975
+	 */
976
+	protected function getPaymentSettingsForm()
977
+	{
978
+		/**
979
+		 * @var $reg_config EE_Registration_Config
980
+		 */
981
+		$reg_config = LoaderFactory::getLoader()->getShared('EE_Registration_Config');
982
+		return new EE_Form_Section_Proper(
983
+			array(
984
+				'name' => 'payment-settings',
985
+				'layout_strategy' => new EE_Admin_Two_Column_Layout(),
986
+				'subsections' => array(
987
+					'show_pending_payment_options' => new EE_Yes_No_Input(
988
+						array(
989
+							'html_name' => 'show_pending_payment_options',
990
+							'default' => $reg_config->show_pending_payment_options,
991
+							'html_help_text' => esc_html__(
992
+								"If a payment is marked as 'Pending Payment', or if payment is deferred (ie, an offline gateway like Check, Bank, or Invoice is used), then give registrants the option to retry payment. ",
993
+								'event_espresso'
994
+							)
995
+						)
996
+					),
997
+					'gateway_log_lifespan' => new EE_Select_Input(
998
+						$reg_config->gatewayLogLifespanOptions(),
999
+						array(
1000
+							'html_label_text' => esc_html__('Gateway Logs Lifespan', 'event_espresso'),
1001
+							'html_help_text' => esc_html__('If issues arise with payments being made through a payment gateway, it\'s helpful to log non-sensitive communications with the payment gateway. But it\'s a security responsibility, so it\'s a good idea to not keep them for any longer than necessary.', 'event_espresso'),
1002
+							'default' => $reg_config->gateway_log_lifespan,
1003
+						)
1004
+					)
1005
+				)
1006
+			)
1007
+		);
1008
+	}
1009
+
1010
+
1011
+	protected function _payment_log_overview_list_table()
1012
+	{
1013
+		$this->display_admin_list_table_page_with_sidebar();
1014
+	}
1015
+
1016
+
1017
+	protected function _set_list_table_views_payment_log()
1018
+	{
1019
+		$this->_views = array(
1020
+			'all' => array(
1021
+				'slug'  => 'all',
1022
+				'label' => __('View All Logs', 'event_espresso'),
1023
+				'count' => 0,
1024
+			),
1025
+		);
1026
+	}
1027
+
1028
+
1029
+	/**
1030
+	 * @param int  $per_page
1031
+	 * @param int  $current_page
1032
+	 * @param bool $count
1033
+	 * @return array
1034
+	 */
1035
+	public function get_payment_logs($per_page = 50, $current_page = 0, $count = false)
1036
+	{
1037
+		EE_Registry::instance()->load_model('Change_Log');
1038
+		// we may need to do multiple queries (joining differently), so we actually wan tan array of query params
1039
+		$query_params = array(array('LOG_type' => EEM_Change_Log::type_gateway));
1040
+		// check if they've selected a specific payment method
1041
+		if (isset($this->_req_data['_payment_method']) && $this->_req_data['_payment_method'] !== 'all') {
1042
+			$query_params[0]['OR*pm_or_pay_pm'] = array(
1043
+				'Payment.Payment_Method.PMD_ID' => $this->_req_data['_payment_method'],
1044
+				'Payment_Method.PMD_ID'         => $this->_req_data['_payment_method'],
1045
+			);
1046
+		}
1047
+		// take into account search
1048
+		if (isset($this->_req_data['s']) && $this->_req_data['s']) {
1049
+			$similarity_string = array('LIKE', '%' . str_replace("", "%", $this->_req_data['s']) . '%');
1050
+			$query_params[0]['OR*s']['Payment.Transaction.Registration.Attendee.ATT_fname'] = $similarity_string;
1051
+			$query_params[0]['OR*s']['Payment.Transaction.Registration.Attendee.ATT_lname'] = $similarity_string;
1052
+			$query_params[0]['OR*s']['Payment.Transaction.Registration.Attendee.ATT_email'] = $similarity_string;
1053
+			$query_params[0]['OR*s']['Payment.Payment_Method.PMD_name'] = $similarity_string;
1054
+			$query_params[0]['OR*s']['Payment.Payment_Method.PMD_admin_name'] = $similarity_string;
1055
+			$query_params[0]['OR*s']['Payment.Payment_Method.PMD_type'] = $similarity_string;
1056
+			$query_params[0]['OR*s']['LOG_message'] = $similarity_string;
1057
+			$query_params[0]['OR*s']['Payment_Method.PMD_name'] = $similarity_string;
1058
+			$query_params[0]['OR*s']['Payment_Method.PMD_admin_name'] = $similarity_string;
1059
+			$query_params[0]['OR*s']['Payment_Method.PMD_type'] = $similarity_string;
1060
+			$query_params[0]['OR*s']['LOG_message'] = $similarity_string;
1061
+		}
1062
+		if (
1063
+			isset($this->_req_data['payment-filter-start-date'])
1064
+			&& isset($this->_req_data['payment-filter-end-date'])
1065
+		) {
1066
+			// add date
1067
+			$start_date = wp_strip_all_tags($this->_req_data['payment-filter-start-date']);
1068
+			$end_date = wp_strip_all_tags($this->_req_data['payment-filter-end-date']);
1069
+			// make sure our timestamps start and end right at the boundaries for each day
1070
+			$start_date = date('Y-m-d', strtotime($start_date)) . ' 00:00:00';
1071
+			$end_date = date('Y-m-d', strtotime($end_date)) . ' 23:59:59';
1072
+			// convert to timestamps
1073
+			$start_date = strtotime($start_date);
1074
+			$end_date = strtotime($end_date);
1075
+			// makes sure start date is the lowest value and vice versa
1076
+			$start_date = min($start_date, $end_date);
1077
+			$end_date = max($start_date, $end_date);
1078
+			// convert for query
1079
+			$start_date = EEM_Change_Log::instance()
1080
+										->convert_datetime_for_query(
1081
+											'LOG_time',
1082
+											date('Y-m-d H:i:s', $start_date),
1083
+											'Y-m-d H:i:s'
1084
+										);
1085
+			$end_date = EEM_Change_Log::instance()
1086
+									  ->convert_datetime_for_query(
1087
+										  'LOG_time',
1088
+										  date('Y-m-d H:i:s', $end_date),
1089
+										  'Y-m-d H:i:s'
1090
+									  );
1091
+			$query_params[0]['LOG_time'] = array('BETWEEN', array($start_date, $end_date));
1092
+		}
1093
+		if ($count) {
1094
+			return EEM_Change_Log::instance()->count($query_params);
1095
+		}
1096
+		if (isset($this->_req_data['order'])) {
1097
+			$sort = (isset($this->_req_data['order']) && ! empty($this->_req_data['order'])) ? $this->_req_data['order']
1098
+				: 'DESC';
1099
+			$query_params['order_by'] = array('LOG_time' => $sort);
1100
+		} else {
1101
+			$query_params['order_by'] = array('LOG_time' => 'DESC');
1102
+		}
1103
+		$offset = ($current_page - 1) * $per_page;
1104
+		if (! isset($this->_req_data['download_results'])) {
1105
+			$query_params['limit'] = array($offset, $per_page);
1106
+		}
1107
+		// now they've requested to instead just download the file instead of viewing it.
1108
+		if (isset($this->_req_data['download_results'])) {
1109
+			$wpdb_results = EEM_Change_Log::instance()->get_all_efficiently($query_params);
1110
+			header('Content-Disposition: attachment');
1111
+			header("Content-Disposition: attachment; filename=ee_payment_logs_for_" . sanitize_key(site_url()));
1112
+			echo "<h1>Payment Logs for " . site_url() . "</h1>";
1113
+			echo "<h3>Query:</h3>";
1114
+			var_dump($query_params);
1115
+			echo "<h3>Results:</h3>";
1116
+			var_dump($wpdb_results);
1117
+			die;
1118
+		}
1119
+		$results = EEM_Change_Log::instance()->get_all($query_params);
1120
+		return $results;
1121
+	}
1122
+
1123
+
1124
+	/**
1125
+	 * Used by usort to RE-sort log query results, because we lose the ordering
1126
+	 * because we're possibly combining the results from two queries
1127
+	 *
1128
+	 * @param EE_Change_Log $logA
1129
+	 * @param EE_Change_Log $logB
1130
+	 * @return int
1131
+	 */
1132
+	protected function _sort_logs_again($logA, $logB)
1133
+	{
1134
+		$timeA = $logA->get_raw('LOG_time');
1135
+		$timeB = $logB->get_raw('LOG_time');
1136
+		if ($timeA == $timeB) {
1137
+			return 0;
1138
+		}
1139
+		$comparison = $timeA < $timeB ? -1 : 1;
1140
+		if (strtoupper($this->_sort_logs_again_direction) == 'DESC') {
1141
+			return $comparison * -1;
1142
+		} else {
1143
+			return $comparison;
1144
+		}
1145
+	}
1146
+
1147
+
1148
+	protected function _payment_log_details()
1149
+	{
1150
+		EE_Registry::instance()->load_model('Change_Log');
1151
+		/** @var $payment_log EE_Change_Log */
1152
+		$payment_log = EEM_Change_Log::instance()->get_one_by_ID($this->_req_data['ID']);
1153
+		$payment_method = null;
1154
+		$transaction = null;
1155
+		if ($payment_log instanceof EE_Change_Log) {
1156
+			if ($payment_log->object() instanceof EE_Payment) {
1157
+				$payment_method = $payment_log->object()->payment_method();
1158
+				$transaction = $payment_log->object()->transaction();
1159
+			} elseif ($payment_log->object() instanceof EE_Payment_Method) {
1160
+				$payment_method = $payment_log->object();
1161
+			} elseif ($payment_log->object() instanceof EE_Transaction) {
1162
+				$transaction = $payment_log->object();
1163
+				$payment_method = $transaction->payment_method();
1164
+			}
1165
+		}
1166
+		$this->_template_args['admin_page_content'] = EEH_Template::display_template(
1167
+			EE_PAYMENTS_TEMPLATE_PATH . 'payment_log_details.template.php',
1168
+			array(
1169
+				'payment_log'    => $payment_log,
1170
+				'payment_method' => $payment_method,
1171
+				'transaction'    => $transaction,
1172
+			),
1173
+			true
1174
+		);
1175
+		$this->display_admin_page_with_no_sidebar();
1176
+	}
1177 1177
 }
Please login to merge, or discard this patch.
Spacing   +40 added lines, -40 removed lines patch added patch discarded remove patch
@@ -194,10 +194,10 @@  discard block
 block discarded – undo
194 194
             foreach ($payment_method_type->help_tabs_config() as $help_tab_name => $config) {
195 195
                 $template_args = isset($config['template_args']) ? $config['template_args'] : array();
196 196
                 $template_args['admin_page_obj'] = $this;
197
-                $all_pmt_help_tabs_config[ $help_tab_name ] = array(
197
+                $all_pmt_help_tabs_config[$help_tab_name] = array(
198 198
                     'title'   => $config['title'],
199 199
                     'content' => EEH_Template::display_template(
200
-                        $payment_method_type->file_folder() . 'help_tabs/' . $config['filename'] . '.help_tab.php',
200
+                        $payment_method_type->file_folder().'help_tabs/'.$config['filename'].'.help_tab.php',
201 201
                         $template_args,
202 202
                         true
203 203
                     ),
@@ -240,7 +240,7 @@  discard block
 block discarded – undo
240 240
         wp_enqueue_style('espresso-ui-theme');
241 241
         wp_register_style(
242 242
             'espresso_payments',
243
-            EE_PAYMENTS_ASSETS_URL . 'ee-payments.css',
243
+            EE_PAYMENTS_ASSETS_URL.'ee-payments.css',
244 244
             [],
245 245
             EVENT_ESPRESSO_VERSION
246 246
         );
@@ -249,7 +249,7 @@  discard block
 block discarded – undo
249 249
         wp_enqueue_script('ee-text-links');
250 250
         wp_enqueue_script(
251 251
             'espresso_payments',
252
-            EE_PAYMENTS_ASSETS_URL . 'espresso_payments_admin.js',
252
+            EE_PAYMENTS_ASSETS_URL.'espresso_payments_admin.js',
253 253
             ['ee-datepicker'],
254 254
             EVENT_ESPRESSO_VERSION,
255 255
             true
@@ -299,7 +299,7 @@  discard block
 block discarded – undo
299 299
             }
300 300
             // check for any active pms of that type
301 301
             $payment_method = EEM_Payment_Method::instance()->get_one_of_type($pmt_obj->system_name());
302
-            if (! $payment_method instanceof EE_Payment_Method) {
302
+            if ( ! $payment_method instanceof EE_Payment_Method) {
303 303
                 $payment_method = EE_Payment_Method::new_instance(
304 304
                     array(
305 305
                         'PMD_slug'       => sanitize_key($pmt_obj->system_name()),
@@ -309,7 +309,7 @@  discard block
 block discarded – undo
309 309
                     )
310 310
                 );
311 311
             }
312
-            $payment_methods[ $payment_method->slug() ] = $payment_method;
312
+            $payment_methods[$payment_method->slug()] = $payment_method;
313 313
         }
314 314
         $payment_methods = apply_filters(
315 315
             'FHEE__Payments_Admin_Page___payment_methods_list__payment_methods',
@@ -319,7 +319,7 @@  discard block
 block discarded – undo
319 319
             if ($payment_method instanceof EE_Payment_Method) {
320 320
                 add_meta_box(
321 321
                     // html id
322
-                    'espresso_' . $payment_method->slug() . '_payment_settings',
322
+                    'espresso_'.$payment_method->slug().'_payment_settings',
323 323
                     // title
324 324
                     sprintf(__('%s Settings', 'event_espresso'), $payment_method->admin_name()),
325 325
                     // callback
@@ -334,10 +334,10 @@  discard block
 block discarded – undo
334 334
                     array('payment_method' => $payment_method)
335 335
                 );
336 336
                 // setup for tabbed content
337
-                $tabs[ $payment_method->slug() ] = array(
337
+                $tabs[$payment_method->slug()] = array(
338 338
                     'label' => $payment_method->admin_name(),
339 339
                     'class' => $payment_method->active() ? 'gateway-active' : '',
340
-                    'href'  => 'espresso_' . $payment_method->slug() . '_payment_settings',
340
+                    'href'  => 'espresso_'.$payment_method->slug().'_payment_settings',
341 341
                     'title' => __('Modify this Payment Method', 'event_espresso'),
342 342
                     'slug'  => $payment_method->slug(),
343 343
                 );
@@ -368,7 +368,7 @@  discard block
 block discarded – undo
368 368
         }
369 369
         $payment_method = EEM_Payment_Method::instance()->get_one(array(array('PMD_slug' => $payment_method_slug)));
370 370
         // if that didn't work or wasn't provided, find another way to select the current pm
371
-        if (! $this->_verify_payment_method($payment_method)) {
371
+        if ( ! $this->_verify_payment_method($payment_method)) {
372 372
             // like, looking for an active one
373 373
             $payment_method = EEM_Payment_Method::instance()->get_one_active('CART');
374 374
             // test that one as well
@@ -418,7 +418,7 @@  discard block
 block discarded – undo
418 418
     {
419 419
         $payment_method = isset($metabox['args'], $metabox['args']['payment_method'])
420 420
             ? $metabox['args']['payment_method'] : null;
421
-        if (! $payment_method instanceof EE_Payment_Method) {
421
+        if ( ! $payment_method instanceof EE_Payment_Method) {
422 422
             throw new EE_Error(
423 423
                 sprintf(
424 424
                     __(
@@ -435,7 +435,7 @@  discard block
 block discarded – undo
435 435
             if ($form->form_data_present_in($this->_req_data)) {
436 436
                 $form->receive_form_submission($this->_req_data);
437 437
             }
438
-            echo $form->form_open() . $form->get_html_and_js() . $form->form_close();
438
+            echo $form->form_open().$form->get_html_and_js().$form->form_close();
439 439
         } else {
440 440
             echo $this->_activate_payment_method_button($payment_method)->get_html_and_js();
441 441
         }
@@ -451,13 +451,13 @@  discard block
 block discarded – undo
451 451
      */
452 452
     protected function _generate_payment_method_settings_form(EE_Payment_Method $payment_method)
453 453
     {
454
-        if (! $payment_method instanceof EE_Payment_Method) {
454
+        if ( ! $payment_method instanceof EE_Payment_Method) {
455 455
             return new EE_Form_Section_Proper();
456 456
         }
457 457
         return new EE_Form_Section_Proper(
458 458
             array(
459
-                'name'            => $payment_method->slug() . '_settings_form',
460
-                'html_id'         => $payment_method->slug() . '_settings_form',
459
+                'name'            => $payment_method->slug().'_settings_form',
460
+                'html_id'         => $payment_method->slug().'_settings_form',
461 461
                 'action'          => EE_Admin_Page::add_query_args_and_nonce(
462 462
                     array(
463 463
                         'action'         => 'update_payment_method',
@@ -500,7 +500,7 @@  discard block
 block discarded – undo
500 500
                             EEH_HTML::label(
501 501
                                 EEH_HTML::strong(__('IMPORTANT', 'event_espresso'), '', 'important-notice')
502 502
                             )
503
-                        ) .
503
+                        ).
504 504
                         EEH_HTML::td(
505 505
                             EEH_HTML::strong(
506 506
                                 __(
@@ -535,7 +535,7 @@  discard block
 block discarded – undo
535 535
      */
536 536
     protected function _currency_support(EE_Payment_Method $payment_method)
537 537
     {
538
-        if (! $payment_method->usable_for_currency(EE_Config::instance()->currency->code)) {
538
+        if ( ! $payment_method->usable_for_currency(EE_Config::instance()->currency->code)) {
539 539
             return new EE_Form_Section_HTML(
540 540
                 EEH_HTML::table(
541 541
                     EEH_HTML::tr(
@@ -543,7 +543,7 @@  discard block
 block discarded – undo
543 543
                             EEH_HTML::label(
544 544
                                 EEH_HTML::strong(__('IMPORTANT', 'event_espresso'), '', 'important-notice')
545 545
                             )
546
-                        ) .
546
+                        ).
547 547
                         EEH_HTML::td(
548 548
                             EEH_HTML::strong(
549 549
                                 sprintf(
@@ -624,7 +624,7 @@  discard block
 block discarded – undo
624 624
         $update_button = new EE_Submit_Input(
625 625
             array(
626 626
                 'name'       => 'submit',
627
-                'html_id'    => 'save_' . $payment_method->slug() . '_settings',
627
+                'html_id'    => 'save_'.$payment_method->slug().'_settings',
628 628
                 'default'    => sprintf(
629 629
                     __('Update %s Payment Settings', 'event_espresso'),
630 630
                     $payment_method->admin_name()
@@ -634,9 +634,9 @@  discard block
 block discarded – undo
634 634
         );
635 635
         return new EE_Form_Section_HTML(
636 636
             EEH_HTML::table(
637
-                EEH_HTML::no_row(EEH_HTML::br(2)) .
637
+                EEH_HTML::no_row(EEH_HTML::br(2)).
638 638
                 EEH_HTML::tr(
639
-                    EEH_HTML::th(__('Update Settings', 'event_espresso')) .
639
+                    EEH_HTML::th(__('Update Settings', 'event_espresso')).
640 640
                     EEH_HTML::td(
641 641
                         $update_button->get_html_for_input()
642 642
                     )
@@ -662,7 +662,7 @@  discard block
 block discarded – undo
662 662
         return new EE_Form_Section_HTML(
663 663
             EEH_HTML::table(
664 664
                 EEH_HTML::tr(
665
-                    EEH_HTML::th(__('Deactivate Payment Method', 'event_espresso')) .
665
+                    EEH_HTML::th(__('Deactivate Payment Method', 'event_espresso')).
666 666
                     EEH_HTML::td(
667 667
                         EEH_HTML::link(
668 668
                             EE_Admin_Page::add_query_args_and_nonce(
@@ -674,7 +674,7 @@  discard block
 block discarded – undo
674 674
                             ),
675 675
                             $link_text_and_title,
676 676
                             $link_text_and_title,
677
-                            'deactivate_' . $payment_method->slug(),
677
+                            'deactivate_'.$payment_method->slug(),
678 678
                             'espresso-button button-secondary'
679 679
                         )
680 680
                     )
@@ -699,8 +699,8 @@  discard block
 block discarded – undo
699 699
         );
700 700
         return new EE_Form_Section_Proper(
701 701
             array(
702
-                'name'            => 'activate_' . $payment_method->slug() . '_settings_form',
703
-                'html_id'         => 'activate_' . $payment_method->slug() . '_settings_form',
702
+                'name'            => 'activate_'.$payment_method->slug().'_settings_form',
703
+                'html_id'         => 'activate_'.$payment_method->slug().'_settings_form',
704 704
                 'action'          => '#',
705 705
                 'layout_strategy' => new EE_Admin_Two_Column_Layout(),
706 706
                 'subsections'     => apply_filters(
@@ -716,11 +716,11 @@  discard block
 block discarded – undo
716 716
                                         '',
717 717
                                         'colspan="2"'
718 718
                                     )
719
-                                ) .
719
+                                ).
720 720
                                 EEH_HTML::tr(
721 721
                                     EEH_HTML::th(
722 722
                                         EEH_HTML::label(__('Click to Activate ', 'event_espresso'))
723
-                                    ) .
723
+                                    ).
724 724
                                     EEH_HTML::td(
725 725
                                         EEH_HTML::link(
726 726
                                             EE_Admin_Page::add_query_args_and_nonce(
@@ -732,7 +732,7 @@  discard block
 block discarded – undo
732 732
                                             ),
733 733
                                             $link_text_and_title,
734 734
                                             $link_text_and_title,
735
-                                            'activate_' . $payment_method->slug(),
735
+                                            'activate_'.$payment_method->slug(),
736 736
                                             'espresso-button-green button-primary'
737 737
                                         )
738 738
                                     )
@@ -758,7 +758,7 @@  discard block
 block discarded – undo
758 758
         return new EE_Form_Section_HTML(
759 759
             EEH_HTML::table(
760 760
                 EEH_HTML::tr(
761
-                    EEH_HTML::th() .
761
+                    EEH_HTML::th().
762 762
                     EEH_HTML::td(
763 763
                         EEH_HTML::p(__('All fields marked with a * are required fields', 'event_espresso'), '', 'grey-text')
764 764
                     )
@@ -842,7 +842,7 @@  discard block
 block discarded – undo
842 842
                 }
843 843
             }
844 844
             // if we couldn't find the correct payment method type...
845
-            if (! $correct_pmt_form_to_use) {
845
+            if ( ! $correct_pmt_form_to_use) {
846 846
                 EE_Error::add_error(
847 847
                     __(
848 848
                         "We could not find which payment method type your form submission related to. Please contact support",
@@ -857,7 +857,7 @@  discard block
 block discarded – undo
857 857
             $correct_pmt_form_to_use->receive_form_submission($this->_req_data);
858 858
             if ($correct_pmt_form_to_use->is_valid()) {
859 859
                 $payment_settings_subform = $correct_pmt_form_to_use->get_subsection('payment_method_settings');
860
-                if (! $payment_settings_subform instanceof EE_Payment_Method_Form) {
860
+                if ( ! $payment_settings_subform instanceof EE_Payment_Method_Form) {
861 861
                     throw new EE_Error(
862 862
                         sprintf(
863 863
                             __(
@@ -909,7 +909,7 @@  discard block
 block discarded – undo
909 909
         $form = $this->getPaymentSettingsForm();
910 910
         $this->_set_add_edit_form_tags('update_payment_settings');
911 911
         $this->_set_publish_post_box_vars(null, false, false, null, false);
912
-        $this->_template_args['admin_page_content'] =  $form->get_html_and_js();
912
+        $this->_template_args['admin_page_content'] = $form->get_html_and_js();
913 913
         $this->display_admin_page_with_sidebar();
914 914
     }
915 915
 
@@ -945,7 +945,7 @@  discard block
 block discarded – undo
945 945
             EE_Registry::instance()->CFG
946 946
         );
947 947
 
948
-        $cfg =  EE_Registry::instance()->CFG ;
948
+        $cfg = EE_Registry::instance()->CFG;
949 949
 
950 950
         $what = __('Payment Settings', 'event_espresso');
951 951
         $success = $this->_update_espresso_configuration(
@@ -1046,7 +1046,7 @@  discard block
 block discarded – undo
1046 1046
         }
1047 1047
         // take into account search
1048 1048
         if (isset($this->_req_data['s']) && $this->_req_data['s']) {
1049
-            $similarity_string = array('LIKE', '%' . str_replace("", "%", $this->_req_data['s']) . '%');
1049
+            $similarity_string = array('LIKE', '%'.str_replace("", "%", $this->_req_data['s']).'%');
1050 1050
             $query_params[0]['OR*s']['Payment.Transaction.Registration.Attendee.ATT_fname'] = $similarity_string;
1051 1051
             $query_params[0]['OR*s']['Payment.Transaction.Registration.Attendee.ATT_lname'] = $similarity_string;
1052 1052
             $query_params[0]['OR*s']['Payment.Transaction.Registration.Attendee.ATT_email'] = $similarity_string;
@@ -1067,8 +1067,8 @@  discard block
 block discarded – undo
1067 1067
             $start_date = wp_strip_all_tags($this->_req_data['payment-filter-start-date']);
1068 1068
             $end_date = wp_strip_all_tags($this->_req_data['payment-filter-end-date']);
1069 1069
             // make sure our timestamps start and end right at the boundaries for each day
1070
-            $start_date = date('Y-m-d', strtotime($start_date)) . ' 00:00:00';
1071
-            $end_date = date('Y-m-d', strtotime($end_date)) . ' 23:59:59';
1070
+            $start_date = date('Y-m-d', strtotime($start_date)).' 00:00:00';
1071
+            $end_date = date('Y-m-d', strtotime($end_date)).' 23:59:59';
1072 1072
             // convert to timestamps
1073 1073
             $start_date = strtotime($start_date);
1074 1074
             $end_date = strtotime($end_date);
@@ -1101,15 +1101,15 @@  discard block
 block discarded – undo
1101 1101
             $query_params['order_by'] = array('LOG_time' => 'DESC');
1102 1102
         }
1103 1103
         $offset = ($current_page - 1) * $per_page;
1104
-        if (! isset($this->_req_data['download_results'])) {
1104
+        if ( ! isset($this->_req_data['download_results'])) {
1105 1105
             $query_params['limit'] = array($offset, $per_page);
1106 1106
         }
1107 1107
         // now they've requested to instead just download the file instead of viewing it.
1108 1108
         if (isset($this->_req_data['download_results'])) {
1109 1109
             $wpdb_results = EEM_Change_Log::instance()->get_all_efficiently($query_params);
1110 1110
             header('Content-Disposition: attachment');
1111
-            header("Content-Disposition: attachment; filename=ee_payment_logs_for_" . sanitize_key(site_url()));
1112
-            echo "<h1>Payment Logs for " . site_url() . "</h1>";
1111
+            header("Content-Disposition: attachment; filename=ee_payment_logs_for_".sanitize_key(site_url()));
1112
+            echo "<h1>Payment Logs for ".site_url()."</h1>";
1113 1113
             echo "<h3>Query:</h3>";
1114 1114
             var_dump($query_params);
1115 1115
             echo "<h3>Results:</h3>";
@@ -1164,7 +1164,7 @@  discard block
 block discarded – undo
1164 1164
             }
1165 1165
         }
1166 1166
         $this->_template_args['admin_page_content'] = EEH_Template::display_template(
1167
-            EE_PAYMENTS_TEMPLATE_PATH . 'payment_log_details.template.php',
1167
+            EE_PAYMENTS_TEMPLATE_PATH.'payment_log_details.template.php',
1168 1168
             array(
1169 1169
                 'payment_log'    => $payment_log,
1170 1170
                 'payment_method' => $payment_method,
Please login to merge, or discard this patch.
admin_pages/payments/templates/payment_log_details.template.php 1 patch
Indentation   +14 added lines, -14 removed lines patch added patch discarded remove patch
@@ -33,17 +33,17 @@  discard block
 block discarded – undo
33 33
                 </th>
34 34
                 <td>
35 35
                     <?php
36
-                    if ($payment_log->object() instanceof EE_Transaction) {
37
-                        esc_html_e('Unknown', 'event_espresso');
38
-                    } else {
39
-                        echo $payment_method
40
-                        ? $payment_method->admin_name()
41
-                        : esc_html__(
42
-                            "No Longer Exists",
43
-                            'event_espresso'
44
-                        );
45
-                    }
46
-                    ?>
36
+					if ($payment_log->object() instanceof EE_Transaction) {
37
+						esc_html_e('Unknown', 'event_espresso');
38
+					} else {
39
+						echo $payment_method
40
+						? $payment_method->admin_name()
41
+						: esc_html__(
42
+							"No Longer Exists",
43
+							'event_espresso'
44
+						);
45
+					}
46
+					?>
47 47
 
48 48
                 </td>
49 49
             </tr>
@@ -66,9 +66,9 @@  discard block
 block discarded – undo
66 66
                 </th>
67 67
                 <td class='ee-payment-log-details__content'>
68 68
                     <?php
69
-                    echo $payment_log->e('LOG_message', 'as_table');
70
-                    // EEH_Template::layout_array_as_table($payment_log->content())
71
-                    ?>
69
+					echo $payment_log->e('LOG_message', 'as_table');
70
+					// EEH_Template::layout_array_as_table($payment_log->content())
71
+					?>
72 72
                 </td>
73 73
             </tr>
74 74
             </tbody>
Please login to merge, or discard this patch.
core/db_classes/EE_Ticket.class.php 2 patches
Spacing   +15 added lines, -15 removed lines patch added patch discarded remove patch
@@ -173,7 +173,7 @@  discard block
 block discarded – undo
173 173
     public function ticket_status($display = false, $remaining = null)
174 174
     {
175 175
         $remaining = is_bool($remaining) ? $remaining : $this->is_remaining();
176
-        if (! $remaining) {
176
+        if ( ! $remaining) {
177 177
             return $display ? EEH_Template::pretty_status(EE_Ticket::sold_out, false, 'sentence') : EE_Ticket::sold_out;
178 178
         }
179 179
         if ($this->get('TKT_deleted')) {
@@ -301,7 +301,7 @@  discard block
 block discarded – undo
301 301
             ? $this->last_datetime()->get_i18n_datetime('DTT_EVT_end', $date_format)
302 302
             : '';
303 303
 
304
-        return $first_date && $last_date ? $first_date . $conjunction . $last_date : '';
304
+        return $first_date && $last_date ? $first_date.$conjunction.$last_date : '';
305 305
     }
306 306
 
307 307
 
@@ -331,7 +331,7 @@  discard block
 block discarded – undo
331 331
      */
332 332
     public function datetimes($query_params = [])
333 333
     {
334
-        if (! isset($query_params['order_by'])) {
334
+        if ( ! isset($query_params['order_by'])) {
335 335
             $query_params['order_by']['DTT_order'] = 'ASC';
336 336
         }
337 337
         return $this->get_many_related('Datetime', $query_params);
@@ -378,7 +378,7 @@  discard block
 block discarded – undo
378 378
                 if (empty($tickets_sold['datetime'])) {
379 379
                     return $total;
380 380
                 }
381
-                if (! empty($dtt_id) && ! isset($tickets_sold['datetime'][ $dtt_id ])) {
381
+                if ( ! empty($dtt_id) && ! isset($tickets_sold['datetime'][$dtt_id])) {
382 382
                     EE_Error::add_error(
383 383
                         __(
384 384
                             '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?',
@@ -390,7 +390,7 @@  discard block
 block discarded – undo
390 390
                     );
391 391
                     return $total;
392 392
                 }
393
-                return empty($dtt_id) ? $tickets_sold['datetime'] : $tickets_sold['datetime'][ $dtt_id ];
393
+                return empty($dtt_id) ? $tickets_sold['datetime'] : $tickets_sold['datetime'][$dtt_id];
394 394
 
395 395
             default:
396 396
                 return $total;
@@ -409,9 +409,9 @@  discard block
 block discarded – undo
409 409
     {
410 410
         $datetimes    = $this->get_many_related('Datetime');
411 411
         $tickets_sold = [];
412
-        if (! empty($datetimes)) {
412
+        if ( ! empty($datetimes)) {
413 413
             foreach ($datetimes as $datetime) {
414
-                $tickets_sold['datetime'][ $datetime->ID() ] = $datetime->get('DTT_sold');
414
+                $tickets_sold['datetime'][$datetime->ID()] = $datetime->get('DTT_sold');
415 415
             }
416 416
         }
417 417
         // Tickets sold
@@ -431,7 +431,7 @@  discard block
 block discarded – undo
431 431
     public function base_price(bool $return_array = false)
432 432
     {
433 433
         $base_price = $this->ticket_price_modifiers->getBasePrice();
434
-        if (! empty($base_price)) {
434
+        if ( ! empty($base_price)) {
435 435
             return $return_array ? $base_price : reset($base_price);
436 436
         }
437 437
         $_where = ['Price_Type.PBT_ID' => EEM_Price_Type::base_type_base_price];
@@ -453,7 +453,7 @@  discard block
 block discarded – undo
453 453
         $price_modifiers = $this->usesGlobalTaxes()
454 454
             ? $this->ticket_price_modifiers->getAllDiscountAndSurchargeModifiersForTicket()
455 455
             : $this->ticket_price_modifiers ->getAllModifiersForTicket();
456
-        if (! empty($price_modifiers)) {
456
+        if ( ! empty($price_modifiers)) {
457 457
             return $price_modifiers;
458 458
         }
459 459
         return $this->prices(
@@ -479,7 +479,7 @@  discard block
 block discarded – undo
479 479
     public function tax_price_modifiers(): array
480 480
     {
481 481
         $tax_price_modifiers = $this->ticket_price_modifiers->getAllTaxesForTicket();
482
-        if (! empty($tax_price_modifiers)) {
482
+        if ( ! empty($tax_price_modifiers)) {
483 483
             return $tax_price_modifiers;
484 484
         }
485 485
         return $this->prices([['Price_Type.PBT_ID' => EEM_Price_Type::base_type_tax]]);
@@ -497,7 +497,7 @@  discard block
 block discarded – undo
497 497
      */
498 498
     public function prices(array $query_params = []): array
499 499
     {
500
-        if (! isset($query_params['order_by'])) {
500
+        if ( ! isset($query_params['order_by'])) {
501 501
             $query_params['order_by']['PRC_order'] = 'ASC';
502 502
         }
503 503
         return $this->get_many_related('Price', $query_params);
@@ -1068,7 +1068,7 @@  discard block
 block discarded – undo
1068 1068
                 'TKT_qty',
1069 1069
                 $qty
1070 1070
             );
1071
-            if (! $success) {
1071
+            if ( ! $success) {
1072 1072
                 // The datetimes were successfully bumped, but not the
1073 1073
                 // ticket. So we need to manually rollback the datetimes.
1074 1074
                 $this->decreaseReservedForDatetimes($qty);
@@ -1565,7 +1565,7 @@  discard block
 block discarded – undo
1565 1565
         foreach ($this->datetimes() as $datetime) {
1566 1566
             $times[] = $datetime->start_date_and_time();
1567 1567
         }
1568
-        return $this->name() . ' @ ' . implode(', ', $times) . ' for ' . $this->pretty_price();
1568
+        return $this->name().' @ '.implode(', ', $times).' for '.$this->pretty_price();
1569 1569
     }
1570 1570
 
1571 1571
 
@@ -1673,7 +1673,7 @@  discard block
 block discarded – undo
1673 1673
     {
1674 1674
         // get one datetime to use for getting the event
1675 1675
         $datetime = $this->first_datetime();
1676
-        if (! $datetime instanceof EE_Datetime) {
1676
+        if ( ! $datetime instanceof EE_Datetime) {
1677 1677
             throw new UnexpectedEntityException(
1678 1678
                 $datetime,
1679 1679
                 'EE_Datetime',
@@ -1684,7 +1684,7 @@  discard block
 block discarded – undo
1684 1684
             );
1685 1685
         }
1686 1686
         $event = $datetime->event();
1687
-        if (! $event instanceof EE_Event) {
1687
+        if ( ! $event instanceof EE_Event) {
1688 1688
             throw new UnexpectedEntityException(
1689 1689
                 $event,
1690 1690
                 'EE_Event',
Please login to merge, or discard this patch.
Indentation   +2134 added lines, -2134 removed lines patch added patch discarded remove patch
@@ -15,2142 +15,2142 @@
 block discarded – undo
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 Archived:
20
-     * constant used by ticket_status() to indicate that a ticket is archived
21
-     * and no longer available for purchase
22
-     */
23
-    const archived = 'TKA';
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 On sale:
34
-     * constant used by ticket_status() to indicate that a ticket is On Sale
35
-     * and IS available for purchase
36
-     */
37
-    const onsale = 'TKO';
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 Sold out:
48
-     * constant used by ticket_status() to indicate that a ticket is sold out
49
-     * and no longer available for purchases
50
-     */
51
-    const sold_out = 'TKS';
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
-     * @var TicketPriceModifiers
76
-     */
77
-    protected $ticket_price_modifiers;
78
-
79
-
80
-    /**
81
-     * @param array  $props_n_values          incoming values
82
-     * @param string $timezone                incoming timezone (if not set the timezone set for the website will be
83
-     *                                        used.)
84
-     * @param array  $date_formats            incoming date_formats in an array where the first value is the
85
-     *                                        date_format and the second value is the time format
86
-     * @return EE_Ticket
87
-     * @throws EE_Error
88
-     * @throws ReflectionException
89
-     */
90
-    public static function new_instance($props_n_values = [], $timezone = null, $date_formats = [])
91
-    {
92
-        $has_object = parent::_check_for_object($props_n_values, __CLASS__, $timezone, $date_formats);
93
-        return $has_object ?: new self($props_n_values, false, $timezone, $date_formats);
94
-    }
95
-
96
-
97
-    /**
98
-     * @param array  $props_n_values  incoming values from the database
99
-     * @param string $timezone        incoming timezone as set by the model.  If not set the timezone for
100
-     *                                the website will be used.
101
-     * @return EE_Ticket
102
-     * @throws EE_Error
103
-     * @throws ReflectionException
104
-     */
105
-    public static function new_instance_from_db($props_n_values = [], $timezone = null)
106
-    {
107
-        return new self($props_n_values, true, $timezone);
108
-    }
109
-
110
-
111
-    /**
112
-     * @param array  $fieldValues
113
-     * @param false  $bydb
114
-     * @param string $timezone
115
-     * @param array  $date_formats
116
-     * @throws EE_Error
117
-     * @throws ReflectionException
118
-     */
119
-    public function __construct($fieldValues = [], $bydb = false, $timezone = '', $date_formats = [])
120
-    {
121
-        parent::__construct($fieldValues, $bydb, $timezone, $date_formats);
122
-        $this->ticket_price_modifiers = new TicketPriceModifiers($this);
123
-    }
124
-
125
-
126
-    /**
127
-     * @return bool
128
-     * @throws EE_Error
129
-     * @throws ReflectionException
130
-     */
131
-    public function parent()
132
-    {
133
-        return $this->get('TKT_parent');
134
-    }
135
-
136
-
137
-    /**
138
-     * return if a ticket has quantities available for purchase
139
-     *
140
-     * @param int $DTT_ID the primary key for a particular datetime
141
-     * @return boolean
142
-     * @throws EE_Error
143
-     * @throws ReflectionException
144
-     */
145
-    public function available($DTT_ID = 0)
146
-    {
147
-        // are we checking availability for a particular datetime ?
148
-        if ($DTT_ID) {
149
-            // get that datetime object
150
-            $datetime = $this->get_first_related('Datetime', [['DTT_ID' => $DTT_ID]]);
151
-            // if  ticket sales for this datetime have exceeded the reg limit...
152
-            if ($datetime instanceof EE_Datetime && $datetime->sold_out()) {
153
-                return false;
154
-            }
155
-        }
156
-        // datetime is still open for registration, but is this ticket sold out ?
157
-        return $this->qty() < 1 || $this->qty() > $this->sold();
158
-    }
159
-
160
-
161
-    /**
162
-     * Using the start date and end date this method calculates whether the ticket is On Sale, Pending, or Expired
163
-     *
164
-     * @param bool        $display   true = we'll return a localized string, otherwise we just return the value of the
165
-     *                               relevant status const
166
-     * @param bool | null $remaining if it is already known that tickets are available, then simply pass a bool to save
167
-     *                               further processing
168
-     * @return mixed status int if the display string isn't requested
169
-     * @throws EE_Error
170
-     * @throws ReflectionException
171
-     */
172
-    public function ticket_status($display = false, $remaining = null)
173
-    {
174
-        $remaining = is_bool($remaining) ? $remaining : $this->is_remaining();
175
-        if (! $remaining) {
176
-            return $display ? EEH_Template::pretty_status(EE_Ticket::sold_out, false, 'sentence') : EE_Ticket::sold_out;
177
-        }
178
-        if ($this->get('TKT_deleted')) {
179
-            return $display ? EEH_Template::pretty_status(EE_Ticket::archived, false, 'sentence') : EE_Ticket::archived;
180
-        }
181
-        if ($this->is_expired()) {
182
-            return $display ? EEH_Template::pretty_status(EE_Ticket::expired, false, 'sentence') : EE_Ticket::expired;
183
-        }
184
-        if ($this->is_pending()) {
185
-            return $display ? EEH_Template::pretty_status(EE_Ticket::pending, false, 'sentence') : EE_Ticket::pending;
186
-        }
187
-        if ($this->is_on_sale()) {
188
-            return $display ? EEH_Template::pretty_status(EE_Ticket::onsale, false, 'sentence') : EE_Ticket::onsale;
189
-        }
190
-        return '';
191
-    }
192
-
193
-
194
-    /**
195
-     * The purpose of this method is to simply return a boolean for whether there are any tickets remaining for sale
196
-     * considering ALL the factors used for figuring that out.
197
-     *
198
-     * @param int $DTT_ID if an int above 0 is included here then we get a specific dtt.
199
-     * @return boolean         true = tickets remaining, false not.
200
-     * @throws EE_Error
201
-     * @throws ReflectionException
202
-     */
203
-    public function is_remaining($DTT_ID = 0)
204
-    {
205
-        $num_remaining = $this->remaining($DTT_ID);
206
-        if ($num_remaining === 0) {
207
-            return false;
208
-        }
209
-        if ($num_remaining > 0 && $num_remaining < $this->min()) {
210
-            return false;
211
-        }
212
-        return true;
213
-    }
214
-
215
-
216
-    /**
217
-     * return the total number of tickets available for purchase
218
-     *
219
-     * @param int $DTT_ID  the primary key for a particular datetime.
220
-     *                     set to 0 for all related datetimes
221
-     * @return int
222
-     * @throws EE_Error
223
-     * @throws ReflectionException
224
-     */
225
-    public function remaining($DTT_ID = 0)
226
-    {
227
-        return $this->real_quantity_on_ticket('saleable', $DTT_ID);
228
-    }
229
-
230
-
231
-    /**
232
-     * Gets min
233
-     *
234
-     * @return int
235
-     * @throws EE_Error
236
-     * @throws ReflectionException
237
-     */
238
-    public function min()
239
-    {
240
-        return $this->get('TKT_min');
241
-    }
242
-
243
-
244
-    /**
245
-     * return if a ticket is no longer available cause its available dates have expired.
246
-     *
247
-     * @return boolean
248
-     * @throws EE_Error
249
-     * @throws ReflectionException
250
-     */
251
-    public function is_expired()
252
-    {
253
-        return ($this->get_raw('TKT_end_date') < time());
254
-    }
255
-
256
-
257
-    /**
258
-     * Return if a ticket is yet to go on sale or not
259
-     *
260
-     * @return boolean
261
-     * @throws EE_Error
262
-     * @throws ReflectionException
263
-     */
264
-    public function is_pending()
265
-    {
266
-        return ($this->get_raw('TKT_start_date') >= time());
267
-    }
268
-
269
-
270
-    /**
271
-     * Return if a ticket is on sale or not
272
-     *
273
-     * @return boolean
274
-     * @throws EE_Error
275
-     * @throws ReflectionException
276
-     */
277
-    public function is_on_sale()
278
-    {
279
-        return ($this->get_raw('TKT_start_date') <= time() && $this->get_raw('TKT_end_date') >= time());
280
-    }
281
-
282
-
283
-    /**
284
-     * This returns the chronologically last datetime that this ticket is associated with
285
-     *
286
-     * @param string $date_format
287
-     * @param string $conjunction - conjunction junction what's your function ? this string joins the start date with
288
-     *                            the end date ie: Jan 01 "to" Dec 31
289
-     * @return string
290
-     * @throws EE_Error
291
-     * @throws ReflectionException
292
-     */
293
-    public function date_range($date_format = '', $conjunction = ' - ')
294
-    {
295
-        $date_format = ! empty($date_format) ? $date_format : $this->_dt_frmt;
296
-        $first_date  = $this->first_datetime() instanceof EE_Datetime
297
-            ? $this->first_datetime()->get_i18n_datetime('DTT_EVT_start', $date_format)
298
-            : '';
299
-        $last_date   = $this->last_datetime() instanceof EE_Datetime
300
-            ? $this->last_datetime()->get_i18n_datetime('DTT_EVT_end', $date_format)
301
-            : '';
302
-
303
-        return $first_date && $last_date ? $first_date . $conjunction . $last_date : '';
304
-    }
305
-
306
-
307
-    /**
308
-     * This returns the chronologically first datetime that this ticket is associated with
309
-     *
310
-     * @return EE_Datetime
311
-     * @throws EE_Error
312
-     * @throws ReflectionException
313
-     */
314
-    public function first_datetime()
315
-    {
316
-        $datetimes = $this->datetimes(['limit' => 1]);
317
-        return reset($datetimes);
318
-    }
319
-
320
-
321
-    /**
322
-     * Gets all the datetimes this ticket can be used for attending.
323
-     * Unless otherwise specified, orders datetimes by start date.
324
-     *
325
-     * @param array $query_params
326
-     * @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md
327
-     * @return EE_Datetime[]|EE_Base_Class[]
328
-     * @throws EE_Error
329
-     * @throws ReflectionException
330
-     */
331
-    public function datetimes($query_params = [])
332
-    {
333
-        if (! isset($query_params['order_by'])) {
334
-            $query_params['order_by']['DTT_order'] = 'ASC';
335
-        }
336
-        return $this->get_many_related('Datetime', $query_params);
337
-    }
338
-
339
-
340
-    /**
341
-     * This returns the chronologically last datetime that this ticket is associated with
342
-     *
343
-     * @return EE_Datetime
344
-     * @throws EE_Error
345
-     * @throws ReflectionException
346
-     */
347
-    public function last_datetime()
348
-    {
349
-        $datetimes = $this->datetimes(['limit' => 1, 'order_by' => ['DTT_EVT_start' => 'DESC']]);
350
-        return end($datetimes);
351
-    }
352
-
353
-
354
-    /**
355
-     * This returns the total tickets sold depending on the given parameters.
356
-     *
357
-     * @param string $what    Can be one of two options: 'ticket', 'datetime'.
358
-     *                        'ticket' = total ticket sales for all datetimes this ticket is related to
359
-     *                        'datetime' = total ticket sales for a specified datetime (required $dtt_id)
360
-     *                        'datetime' = total ticket sales in the datetime_ticket table.
361
-     *                        If $dtt_id is not given then we return an array of sales indexed by datetime.
362
-     *                        If $dtt_id IS given then we return the tickets sold for that given datetime.
363
-     * @param int    $dtt_id  [optional] include the dtt_id with $what = 'datetime'.
364
-     * @return mixed (array|int)          how many tickets have sold
365
-     * @throws EE_Error
366
-     * @throws ReflectionException
367
-     */
368
-    public function tickets_sold($what = 'ticket', $dtt_id = null)
369
-    {
370
-        $total        = 0;
371
-        $tickets_sold = $this->_all_tickets_sold();
372
-        switch ($what) {
373
-            case 'ticket':
374
-                return $tickets_sold['ticket'];
375
-
376
-            case 'datetime':
377
-                if (empty($tickets_sold['datetime'])) {
378
-                    return $total;
379
-                }
380
-                if (! empty($dtt_id) && ! isset($tickets_sold['datetime'][ $dtt_id ])) {
381
-                    EE_Error::add_error(
382
-                        __(
383
-                            '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?',
384
-                            'event_espresso'
385
-                        ),
386
-                        __FILE__,
387
-                        __FUNCTION__,
388
-                        __LINE__
389
-                    );
390
-                    return $total;
391
-                }
392
-                return empty($dtt_id) ? $tickets_sold['datetime'] : $tickets_sold['datetime'][ $dtt_id ];
393
-
394
-            default:
395
-                return $total;
396
-        }
397
-    }
398
-
399
-
400
-    /**
401
-     * This returns an array indexed by datetime_id for tickets sold with this ticket.
402
-     *
403
-     * @return EE_Ticket[]
404
-     * @throws EE_Error
405
-     * @throws ReflectionException
406
-     */
407
-    protected function _all_tickets_sold()
408
-    {
409
-        $datetimes    = $this->get_many_related('Datetime');
410
-        $tickets_sold = [];
411
-        if (! empty($datetimes)) {
412
-            foreach ($datetimes as $datetime) {
413
-                $tickets_sold['datetime'][ $datetime->ID() ] = $datetime->get('DTT_sold');
414
-            }
415
-        }
416
-        // Tickets sold
417
-        $tickets_sold['ticket'] = $this->sold();
418
-        return $tickets_sold;
419
-    }
420
-
421
-
422
-    /**
423
-     * This returns the base price object for the ticket.
424
-     *
425
-     * @param bool $return_array whether to return as an array indexed by price id or just the object.
426
-     * @return EE_Price|EE_Base_Class|EE_Price[]|EE_Base_Class[]
427
-     * @throws EE_Error
428
-     * @throws ReflectionException
429
-     */
430
-    public function base_price(bool $return_array = false)
431
-    {
432
-        $base_price = $this->ticket_price_modifiers->getBasePrice();
433
-        if (! empty($base_price)) {
434
-            return $return_array ? $base_price : reset($base_price);
435
-        }
436
-        $_where = ['Price_Type.PBT_ID' => EEM_Price_Type::base_type_base_price];
437
-        return $return_array
438
-            ? $this->get_many_related('Price', [$_where])
439
-            : $this->get_first_related('Price', [$_where]);
440
-    }
441
-
442
-
443
-    /**
444
-     * This returns ONLY the price modifiers for the ticket (i.e. no taxes or base price)
445
-     *
446
-     * @return EE_Price[]
447
-     * @throws EE_Error
448
-     * @throws ReflectionException
449
-     */
450
-    public function price_modifiers(): array
451
-    {
452
-        $price_modifiers = $this->usesGlobalTaxes()
453
-            ? $this->ticket_price_modifiers->getAllDiscountAndSurchargeModifiersForTicket()
454
-            : $this->ticket_price_modifiers ->getAllModifiersForTicket();
455
-        if (! empty($price_modifiers)) {
456
-            return $price_modifiers;
457
-        }
458
-        return $this->prices(
459
-            [
460
-                [
461
-                    'Price_Type.PBT_ID' => [
462
-                        'NOT IN',
463
-                        [EEM_Price_Type::base_type_base_price, EEM_Price_Type::base_type_tax],
464
-                    ]
465
-                ]
466
-            ]
467
-        );
468
-    }
469
-
470
-
471
-    /**
472
-     * This returns ONLY the TAX price modifiers for the ticket
473
-     *
474
-     * @return EE_Price[]
475
-     * @throws EE_Error
476
-     * @throws ReflectionException
477
-     */
478
-    public function tax_price_modifiers(): array
479
-    {
480
-        $tax_price_modifiers = $this->ticket_price_modifiers->getAllTaxesForTicket();
481
-        if (! empty($tax_price_modifiers)) {
482
-            return $tax_price_modifiers;
483
-        }
484
-        return $this->prices([['Price_Type.PBT_ID' => EEM_Price_Type::base_type_tax]]);
485
-    }
486
-
487
-
488
-    /**
489
-     * Gets all the prices that combine to form the final price of this ticket
490
-     *
491
-     * @param array $query_params
492
-     * @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md
493
-     * @return EE_Price[]|EE_Base_Class[]
494
-     * @throws EE_Error
495
-     * @throws ReflectionException
496
-     */
497
-    public function prices(array $query_params = []): array
498
-    {
499
-        if (! isset($query_params['order_by'])) {
500
-            $query_params['order_by']['PRC_order'] = 'ASC';
501
-        }
502
-        return $this->get_many_related('Price', $query_params);
503
-    }
504
-
505
-
506
-    /**
507
-     * Gets all the ticket datetimes (ie, relations between datetimes and tickets)
508
-     *
509
-     * @param array $query_params
510
-     * @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md
511
-     * @return EE_Datetime_Ticket|EE_Base_Class[]
512
-     * @throws EE_Error
513
-     * @throws ReflectionException
514
-     */
515
-    public function datetime_tickets($query_params = [])
516
-    {
517
-        return $this->get_many_related('Datetime_Ticket', $query_params);
518
-    }
519
-
520
-
521
-    /**
522
-     * Gets all the datetimes from the db ordered by DTT_order
523
-     *
524
-     * @param boolean $show_expired
525
-     * @param boolean $show_deleted
526
-     * @return EE_Datetime[]
527
-     * @throws EE_Error
528
-     * @throws ReflectionException
529
-     */
530
-    public function datetimes_ordered($show_expired = true, $show_deleted = false)
531
-    {
532
-        return EEM_Datetime::instance($this->_timezone)->get_datetimes_for_ticket_ordered_by_DTT_order(
533
-            $this->ID(),
534
-            $show_expired,
535
-            $show_deleted
536
-        );
537
-    }
538
-
539
-
540
-    /**
541
-     * Gets ID
542
-     *
543
-     * @return int
544
-     * @throws EE_Error
545
-     * @throws ReflectionException
546
-     */
547
-    public function ID()
548
-    {
549
-        return $this->get('TKT_ID');
550
-    }
551
-
552
-
553
-    /**
554
-     * get the author of the ticket.
555
-     *
556
-     * @return int
557
-     * @throws EE_Error
558
-     * @throws ReflectionException
559
-     * @since 4.5.0
560
-     */
561
-    public function wp_user()
562
-    {
563
-        return $this->get('TKT_wp_user');
564
-    }
565
-
566
-
567
-    /**
568
-     * Gets the template for the ticket
569
-     *
570
-     * @return EE_Ticket_Template|EE_Base_Class
571
-     * @throws EE_Error
572
-     * @throws ReflectionException
573
-     */
574
-    public function template()
575
-    {
576
-        return $this->get_first_related('Ticket_Template');
577
-    }
578
-
579
-
580
-    /**
581
-     * Simply returns an array of EE_Price objects that are taxes.
582
-     *
583
-     * @return EE_Price[]
584
-     * @throws EE_Error
585
-     * @throws ReflectionException
586
-     */
587
-    public function get_ticket_taxes_for_admin(): array
588
-    {
589
-        return $this->usesGlobalTaxes() ? EE_Taxes::get_taxes_for_admin() : $this->tax_price_modifiers();
590
-    }
591
-
592
-
593
-    /**
594
-     * alias of taxable() to better indicate that ticket uses the legacy method of applying default "global" taxes
595
-     * as opposed to having tax price modifiers added directly to each ticket
596
-     *
597
-     * @return bool
598
-     * @throws EE_Error
599
-     * @throws ReflectionException
600
-     * @since   $VID:$
601
-     */
602
-    public function usesGlobalTaxes(): bool
603
-    {
604
-        return $this->taxable();
605
-    }
606
-
607
-
608
-    /**
609
-     * @return float
610
-     * @throws EE_Error
611
-     * @throws ReflectionException
612
-     */
613
-    public function ticket_price()
614
-    {
615
-        return $this->get('TKT_price');
616
-    }
617
-
618
-
619
-    /**
620
-     * @return mixed
621
-     * @throws EE_Error
622
-     * @throws ReflectionException
623
-     */
624
-    public function pretty_price()
625
-    {
626
-        return $this->get_pretty('TKT_price');
627
-    }
628
-
629
-
630
-    /**
631
-     * @return bool
632
-     * @throws EE_Error
633
-     * @throws ReflectionException
634
-     */
635
-    public function is_free()
636
-    {
637
-        return $this->get_ticket_total_with_taxes() === (float) 0;
638
-    }
639
-
640
-
641
-    /**
642
-     * get_ticket_total_with_taxes
643
-     *
644
-     * @param bool $no_cache
645
-     * @return float
646
-     * @throws EE_Error
647
-     * @throws ReflectionException
648
-     */
649
-    public function get_ticket_total_with_taxes($no_cache = false)
650
-    {
651
-        if ($this->_ticket_total_with_taxes === null || $no_cache) {
652
-            $this->_ticket_total_with_taxes = $this->usesGlobalTaxes()
653
-                ? $this->get_ticket_subtotal() + $this->get_ticket_taxes_total_for_admin()
654
-                : $this->ticket_price();
655
-        }
656
-        return (float) $this->_ticket_total_with_taxes;
657
-    }
658
-
659
-
660
-    /**
661
-     * @throws EE_Error
662
-     * @throws ReflectionException
663
-     */
664
-    public function ensure_TKT_Price_correct()
665
-    {
666
-        $this->set('TKT_price', EE_Taxes::get_subtotal_for_admin($this));
667
-        $this->save();
668
-    }
669
-
670
-
671
-    /**
672
-     * @return float
673
-     * @throws EE_Error
674
-     * @throws ReflectionException
675
-     */
676
-    public function get_ticket_subtotal()
677
-    {
678
-        return EE_Taxes::get_subtotal_for_admin($this);
679
-    }
680
-
681
-
682
-    /**
683
-     * Returns the total taxes applied to this ticket
684
-     *
685
-     * @return float
686
-     * @throws EE_Error
687
-     * @throws ReflectionException
688
-     */
689
-    public function get_ticket_taxes_total_for_admin()
690
-    {
691
-        return EE_Taxes::get_total_taxes_for_admin($this);
692
-    }
693
-
694
-
695
-    /**
696
-     * Sets name
697
-     *
698
-     * @param string $name
699
-     * @throws EE_Error
700
-     * @throws ReflectionException
701
-     */
702
-    public function set_name($name)
703
-    {
704
-        $this->set('TKT_name', $name);
705
-    }
706
-
707
-
708
-    /**
709
-     * Gets description
710
-     *
711
-     * @return string
712
-     * @throws EE_Error
713
-     * @throws ReflectionException
714
-     */
715
-    public function description()
716
-    {
717
-        return $this->get('TKT_description');
718
-    }
719
-
720
-
721
-    /**
722
-     * Sets description
723
-     *
724
-     * @param string $description
725
-     * @throws EE_Error
726
-     * @throws ReflectionException
727
-     */
728
-    public function set_description($description)
729
-    {
730
-        $this->set('TKT_description', $description);
731
-    }
732
-
733
-
734
-    /**
735
-     * Gets start_date
736
-     *
737
-     * @param string $date_format
738
-     * @param string $time_format
739
-     * @return string
740
-     * @throws EE_Error
741
-     * @throws ReflectionException
742
-     */
743
-    public function start_date($date_format = '', $time_format = '')
744
-    {
745
-        return $this->_get_datetime('TKT_start_date', $date_format, $time_format);
746
-    }
747
-
748
-
749
-    /**
750
-     * Sets start_date
751
-     *
752
-     * @param string $start_date
753
-     * @return void
754
-     * @throws EE_Error
755
-     * @throws ReflectionException
756
-     */
757
-    public function set_start_date($start_date)
758
-    {
759
-        $this->_set_date_time('B', $start_date, 'TKT_start_date');
760
-    }
761
-
762
-
763
-    /**
764
-     * Gets end_date
765
-     *
766
-     * @param string $date_format
767
-     * @param string $time_format
768
-     * @return string
769
-     * @throws EE_Error
770
-     * @throws ReflectionException
771
-     */
772
-    public function end_date($date_format = '', $time_format = '')
773
-    {
774
-        return $this->_get_datetime('TKT_end_date', $date_format, $time_format);
775
-    }
776
-
777
-
778
-    /**
779
-     * Sets end_date
780
-     *
781
-     * @param string $end_date
782
-     * @return void
783
-     * @throws EE_Error
784
-     * @throws ReflectionException
785
-     */
786
-    public function set_end_date($end_date)
787
-    {
788
-        $this->_set_date_time('B', $end_date, 'TKT_end_date');
789
-    }
790
-
791
-
792
-    /**
793
-     * Sets sell until time
794
-     *
795
-     * @param string $time a string representation of the sell until time (ex 9am or 7:30pm)
796
-     * @throws EE_Error
797
-     * @throws ReflectionException
798
-     * @since 4.5.0
799
-     */
800
-    public function set_end_time($time)
801
-    {
802
-        $this->_set_time_for($time, 'TKT_end_date');
803
-    }
804
-
805
-
806
-    /**
807
-     * Sets min
808
-     *
809
-     * @param int $min
810
-     * @return void
811
-     * @throws EE_Error
812
-     * @throws ReflectionException
813
-     */
814
-    public function set_min($min)
815
-    {
816
-        $this->set('TKT_min', $min);
817
-    }
818
-
819
-
820
-    /**
821
-     * Gets max
822
-     *
823
-     * @return int
824
-     * @throws EE_Error
825
-     * @throws ReflectionException
826
-     */
827
-    public function max()
828
-    {
829
-        return $this->get('TKT_max');
830
-    }
831
-
832
-
833
-    /**
834
-     * Sets max
835
-     *
836
-     * @param int $max
837
-     * @return void
838
-     * @throws EE_Error
839
-     * @throws ReflectionException
840
-     */
841
-    public function set_max($max)
842
-    {
843
-        $this->set('TKT_max', $max);
844
-    }
845
-
846
-
847
-    /**
848
-     * Sets price
849
-     *
850
-     * @param float $price
851
-     * @return void
852
-     * @throws EE_Error
853
-     * @throws ReflectionException
854
-     */
855
-    public function set_price($price)
856
-    {
857
-        $this->set('TKT_price', $price);
858
-    }
859
-
860
-
861
-    /**
862
-     * Gets sold
863
-     *
864
-     * @return int
865
-     * @throws EE_Error
866
-     * @throws ReflectionException
867
-     */
868
-    public function sold()
869
-    {
870
-        return $this->get_raw('TKT_sold');
871
-    }
872
-
873
-
874
-    /**
875
-     * Sets sold
876
-     *
877
-     * @param int $sold
878
-     * @return void
879
-     * @throws EE_Error
880
-     * @throws ReflectionException
881
-     */
882
-    public function set_sold($sold)
883
-    {
884
-        // sold can not go below zero
885
-        $sold = max(0, $sold);
886
-        $this->set('TKT_sold', $sold);
887
-    }
888
-
889
-
890
-    /**
891
-     * Increments sold by amount passed by $qty AND decrements the reserved count on both this ticket and its
892
-     * associated datetimes.
893
-     *
894
-     * @param int $qty
895
-     * @return boolean
896
-     * @throws EE_Error
897
-     * @throws InvalidArgumentException
898
-     * @throws InvalidDataTypeException
899
-     * @throws InvalidInterfaceException
900
-     * @throws ReflectionException
901
-     * @since 4.9.80.p
902
-     */
903
-    public function increaseSold($qty = 1)
904
-    {
905
-        $qty = absint($qty);
906
-        // increment sold and decrement reserved datetime quantities simultaneously
907
-        // don't worry about failures, because they must have already had a spot reserved
908
-        $this->increaseSoldForDatetimes($qty);
909
-        // Increment and decrement ticket quantities simultaneously
910
-        $success = $this->adjustNumericFieldsInDb(
911
-            [
912
-                'TKT_reserved' => $qty * -1,
913
-                'TKT_sold'     => $qty,
914
-            ]
915
-        );
916
-        do_action(
917
-            'AHEE__EE_Ticket__increase_sold',
918
-            $this,
919
-            $qty,
920
-            $this->sold(),
921
-            $success
922
-        );
923
-        return $success;
924
-    }
925
-
926
-
927
-    /**
928
-     * On each datetime related to this ticket, increases its sold count and decreases its reserved count by $qty.
929
-     *
930
-     * @param int           $qty positive or negative. Positive means to increase sold counts (and decrease reserved
931
-     *                           counts), Negative means to decreases old counts (and increase reserved counts).
932
-     * @param EE_Datetime[] $datetimes
933
-     * @throws EE_Error
934
-     * @throws InvalidArgumentException
935
-     * @throws InvalidDataTypeException
936
-     * @throws InvalidInterfaceException
937
-     * @throws ReflectionException
938
-     * @since 4.9.80.p
939
-     */
940
-    protected function increaseSoldForDatetimes($qty, array $datetimes = [])
941
-    {
942
-        $datetimes = ! empty($datetimes) ? $datetimes : $this->datetimes();
943
-        foreach ($datetimes as $datetime) {
944
-            $datetime->increaseSold($qty);
945
-        }
946
-    }
947
-
948
-
949
-    /**
950
-     * Decrements (subtracts) sold by amount passed by $qty on both the ticket and its related datetimes directly in the
951
-     * DB and then updates the model objects.
952
-     * Does not affect the reserved counts.
953
-     *
954
-     * @param int $qty
955
-     * @return boolean
956
-     * @throws EE_Error
957
-     * @throws InvalidArgumentException
958
-     * @throws InvalidDataTypeException
959
-     * @throws InvalidInterfaceException
960
-     * @throws ReflectionException
961
-     * @since 4.9.80.p
962
-     */
963
-    public function decreaseSold($qty = 1)
964
-    {
965
-        $qty = absint($qty);
966
-        $this->decreaseSoldForDatetimes($qty);
967
-        $success = $this->adjustNumericFieldsInDb(
968
-            [
969
-                'TKT_sold' => $qty * -1,
970
-            ]
971
-        );
972
-        do_action(
973
-            'AHEE__EE_Ticket__decrease_sold',
974
-            $this,
975
-            $qty,
976
-            $this->sold(),
977
-            $success
978
-        );
979
-        return $success;
980
-    }
981
-
982
-
983
-    /**
984
-     * Decreases sold on related datetimes
985
-     *
986
-     * @param int           $qty
987
-     * @param EE_Datetime[] $datetimes
988
-     * @return void
989
-     * @throws EE_Error
990
-     * @throws InvalidArgumentException
991
-     * @throws InvalidDataTypeException
992
-     * @throws InvalidInterfaceException
993
-     * @throws ReflectionException
994
-     * @since 4.9.80.p
995
-     */
996
-    protected function decreaseSoldForDatetimes($qty = 1, array $datetimes = [])
997
-    {
998
-        $datetimes = ! empty($datetimes) ? $datetimes : $this->datetimes();
999
-        if (is_array($datetimes)) {
1000
-            foreach ($datetimes as $datetime) {
1001
-                if ($datetime instanceof EE_Datetime) {
1002
-                    $datetime->decreaseSold($qty);
1003
-                }
1004
-            }
1005
-        }
1006
-    }
1007
-
1008
-
1009
-    /**
1010
-     * Gets qty of reserved tickets
1011
-     *
1012
-     * @return int
1013
-     * @throws EE_Error
1014
-     * @throws ReflectionException
1015
-     */
1016
-    public function reserved()
1017
-    {
1018
-        return $this->get_raw('TKT_reserved');
1019
-    }
1020
-
1021
-
1022
-    /**
1023
-     * Sets reserved
1024
-     *
1025
-     * @param int $reserved
1026
-     * @return void
1027
-     * @throws EE_Error
1028
-     * @throws ReflectionException
1029
-     */
1030
-    public function set_reserved($reserved)
1031
-    {
1032
-        // reserved can not go below zero
1033
-        $reserved = max(0, (int) $reserved);
1034
-        $this->set('TKT_reserved', $reserved);
1035
-    }
1036
-
1037
-
1038
-    /**
1039
-     * Increments reserved by amount passed by $qty, and persists it immediately to the database.
1040
-     *
1041
-     * @param int    $qty
1042
-     * @param string $source
1043
-     * @return bool whether we successfully reserved the ticket or not.
1044
-     * @throws EE_Error
1045
-     * @throws InvalidArgumentException
1046
-     * @throws ReflectionException
1047
-     * @throws InvalidDataTypeException
1048
-     * @throws InvalidInterfaceException
1049
-     * @since 4.9.80.p
1050
-     */
1051
-    public function increaseReserved($qty = 1, $source = 'unknown')
1052
-    {
1053
-        $qty = absint($qty);
1054
-        do_action(
1055
-            'AHEE__EE_Ticket__increase_reserved__begin',
1056
-            $this,
1057
-            $qty,
1058
-            $source
1059
-        );
1060
-        $this->add_extra_meta(EE_Ticket::META_KEY_TICKET_RESERVATIONS, "{$qty} from {$source}");
1061
-        $success                         = false;
1062
-        $datetimes_adjusted_successfully = $this->increaseReservedForDatetimes($qty);
1063
-        if ($datetimes_adjusted_successfully) {
1064
-            $success = $this->incrementFieldConditionallyInDb(
1065
-                'TKT_reserved',
1066
-                'TKT_sold',
1067
-                'TKT_qty',
1068
-                $qty
1069
-            );
1070
-            if (! $success) {
1071
-                // The datetimes were successfully bumped, but not the
1072
-                // ticket. So we need to manually rollback the datetimes.
1073
-                $this->decreaseReservedForDatetimes($qty);
1074
-            }
1075
-        }
1076
-        do_action(
1077
-            'AHEE__EE_Ticket__increase_reserved',
1078
-            $this,
1079
-            $qty,
1080
-            $this->reserved(),
1081
-            $success
1082
-        );
1083
-        return $success;
1084
-    }
1085
-
1086
-
1087
-    /**
1088
-     * Increases reserved counts on related datetimes
1089
-     *
1090
-     * @param int           $qty
1091
-     * @param EE_Datetime[] $datetimes
1092
-     * @return boolean indicating success
1093
-     * @throws EE_Error
1094
-     * @throws InvalidArgumentException
1095
-     * @throws InvalidDataTypeException
1096
-     * @throws InvalidInterfaceException
1097
-     * @throws ReflectionException
1098
-     * @since 4.9.80.p
1099
-     */
1100
-    protected function increaseReservedForDatetimes($qty = 1, array $datetimes = [])
1101
-    {
1102
-        $datetimes         = ! empty($datetimes) ? $datetimes : $this->datetimes();
1103
-        $datetimes_updated = [];
1104
-        $limit_exceeded    = false;
1105
-        if (is_array($datetimes)) {
1106
-            foreach ($datetimes as $datetime) {
1107
-                if ($datetime instanceof EE_Datetime) {
1108
-                    if ($datetime->increaseReserved($qty)) {
1109
-                        $datetimes_updated[] = $datetime;
1110
-                    } else {
1111
-                        $limit_exceeded = true;
1112
-                        break;
1113
-                    }
1114
-                }
1115
-            }
1116
-            // If somewhere along the way we detected a datetime whose
1117
-            // limit was exceeded, do a manual rollback.
1118
-            if ($limit_exceeded) {
1119
-                $this->decreaseReservedForDatetimes($qty, $datetimes_updated);
1120
-                return false;
1121
-            }
1122
-        }
1123
-        return true;
1124
-    }
1125
-
1126
-
1127
-    /**
1128
-     * Decrements (subtracts) reserved by amount passed by $qty, and persists it immediately to the database.
1129
-     *
1130
-     * @param int    $qty
1131
-     * @param bool   $adjust_datetimes
1132
-     * @param string $source
1133
-     * @return boolean
1134
-     * @throws EE_Error
1135
-     * @throws InvalidArgumentException
1136
-     * @throws ReflectionException
1137
-     * @throws InvalidDataTypeException
1138
-     * @throws InvalidInterfaceException
1139
-     * @since 4.9.80.p
1140
-     */
1141
-    public function decreaseReserved($qty = 1, $adjust_datetimes = true, $source = 'unknown')
1142
-    {
1143
-        $qty = absint($qty);
1144
-        $this->add_extra_meta(EE_Ticket::META_KEY_TICKET_RESERVATIONS, "-{$qty} from {$source}");
1145
-        if ($adjust_datetimes) {
1146
-            $this->decreaseReservedForDatetimes($qty);
1147
-        }
1148
-        $success = $this->adjustNumericFieldsInDb(
1149
-            [
1150
-                'TKT_reserved' => $qty * -1,
1151
-            ]
1152
-        );
1153
-        do_action(
1154
-            'AHEE__EE_Ticket__decrease_reserved',
1155
-            $this,
1156
-            $qty,
1157
-            $this->reserved(),
1158
-            $success
1159
-        );
1160
-        return $success;
1161
-    }
1162
-
1163
-
1164
-    /**
1165
-     * Decreases the reserved count on the specified datetimes.
1166
-     *
1167
-     * @param int           $qty
1168
-     * @param EE_Datetime[] $datetimes
1169
-     * @throws EE_Error
1170
-     * @throws InvalidArgumentException
1171
-     * @throws ReflectionException
1172
-     * @throws InvalidDataTypeException
1173
-     * @throws InvalidInterfaceException
1174
-     * @since 4.9.80.p
1175
-     */
1176
-    protected function decreaseReservedForDatetimes($qty = 1, array $datetimes = [])
1177
-    {
1178
-        $datetimes = ! empty($datetimes) ? $datetimes : $this->datetimes();
1179
-        foreach ($datetimes as $datetime) {
1180
-            if ($datetime instanceof EE_Datetime) {
1181
-                $datetime->decreaseReserved($qty);
1182
-            }
1183
-        }
1184
-    }
1185
-
1186
-
1187
-    /**
1188
-     * Gets ticket quantity
1189
-     *
1190
-     * @param string $context     ticket quantity is somewhat subjective depending on the exact information sought
1191
-     *                            therefore $context can be one of three values: '', 'reg_limit', or 'saleable'
1192
-     *                            '' (default) quantity is the actual db value for TKT_qty, unaffected by other objects
1193
-     *                            REG LIMIT: caps qty based on DTT_reg_limit for ALL related datetimes
1194
-     *                            SALEABLE: also considers datetime sold and returns zero if ANY DTT is sold out, and
1195
-     *                            is therefore the truest measure of tickets that can be purchased at the moment
1196
-     * @return int
1197
-     * @throws EE_Error
1198
-     * @throws ReflectionException
1199
-     */
1200
-    public function qty($context = '')
1201
-    {
1202
-        switch ($context) {
1203
-            case 'reg_limit':
1204
-                return $this->real_quantity_on_ticket();
1205
-            case 'saleable':
1206
-                return $this->real_quantity_on_ticket('saleable');
1207
-            default:
1208
-                return $this->get_raw('TKT_qty');
1209
-        }
1210
-    }
1211
-
1212
-
1213
-    /**
1214
-     * Gets ticket quantity
1215
-     *
1216
-     * @param string $context     ticket quantity is somewhat subjective depending on the exact information sought
1217
-     *                            therefore $context can be one of two values: 'reg_limit', or 'saleable'
1218
-     *                            REG LIMIT: caps qty based on DTT_reg_limit for ALL related datetimes
1219
-     *                            SALEABLE: also considers datetime sold and returns zero if ANY DTT is sold out, and
1220
-     *                            is therefore the truest measure of tickets that can be purchased at the moment
1221
-     * @param int    $DTT_ID      the primary key for a particular datetime.
1222
-     *                            set to 0 for all related datetimes
1223
-     * @return int
1224
-     * @throws EE_Error
1225
-     * @throws ReflectionException
1226
-     */
1227
-    public function real_quantity_on_ticket($context = 'reg_limit', $DTT_ID = 0)
1228
-    {
1229
-        $raw = $this->get_raw('TKT_qty');
1230
-        // return immediately if it's zero
1231
-        if ($raw === 0) {
1232
-            return $raw;
1233
-        }
1234
-        // echo "\n\n<br />Ticket: " . $this->name() . '<br />';
1235
-        // ensure qty doesn't exceed raw value for THIS ticket
1236
-        $qty = min(EE_INF, $raw);
1237
-        // echo "\n . qty: " . $qty . '<br />';
1238
-        // calculate this ticket's total sales and reservations
1239
-        $sold_and_reserved_for_this_ticket = $this->sold() + $this->reserved();
1240
-        // echo "\n . sold: " . $this->sold() . '<br />';
1241
-        // echo "\n . reserved: " . $this->reserved() . '<br />';
1242
-        // echo "\n . sold_and_reserved_for_this_ticket: " . $sold_and_reserved_for_this_ticket . '<br />';
1243
-        // first we need to calculate the maximum number of tickets available for the datetime
1244
-        // do we want data for one datetime or all of them ?
1245
-        $query_params = $DTT_ID ? [['DTT_ID' => $DTT_ID]] : [];
1246
-        $datetimes    = $this->datetimes($query_params);
1247
-        if (is_array($datetimes) && ! empty($datetimes)) {
1248
-            foreach ($datetimes as $datetime) {
1249
-                if ($datetime instanceof EE_Datetime) {
1250
-                    $datetime->refresh_from_db();
1251
-                    // echo "\n . . datetime name: " . $datetime->name() . '<br />';
1252
-                    // echo "\n . . datetime ID: " . $datetime->ID() . '<br />';
1253
-                    // initialize with no restrictions for each datetime
1254
-                    // but adjust datetime qty based on datetime reg limit
1255
-                    $datetime_qty = min(EE_INF, $datetime->reg_limit());
1256
-                    // echo "\n . . . datetime reg_limit: " . $datetime->reg_limit() . '<br />';
1257
-                    // echo "\n . . . datetime_qty: " . $datetime_qty . '<br />';
1258
-                    // if we want the actual saleable amount, then we need to consider OTHER ticket sales
1259
-                    // and reservations for this datetime, that do NOT include sales and reservations
1260
-                    // for this ticket (so we add $this->sold() and $this->reserved() back in)
1261
-                    if ($context === 'saleable') {
1262
-                        $datetime_qty = max(
1263
-                            $datetime_qty - $datetime->sold_and_reserved() + $sold_and_reserved_for_this_ticket,
1264
-                            0
1265
-                        );
1266
-                        // echo "\n . . . datetime sold: " . $datetime->sold() . '<br />';
1267
-                        // echo "\n . . . datetime reserved: " . $datetime->reserved() . '<br />';
1268
-                        // echo "\n . . . datetime sold_and_reserved: " . $datetime->sold_and_reserved() . '<br />';
1269
-                        // echo "\n . . . datetime_qty: " . $datetime_qty . '<br />';
1270
-                        $datetime_qty = ! $datetime->sold_out() ? $datetime_qty : 0;
1271
-                        // echo "\n . . . datetime_qty: " . $datetime_qty . '<br />';
1272
-                    }
1273
-                    $qty = min($datetime_qty, $qty);
1274
-                    // echo "\n . . qty: " . $qty . '<br />';
1275
-                }
1276
-            }
1277
-        }
1278
-        // NOW that we know the  maximum number of tickets available for the datetime
1279
-        // we can finally factor in the details for this specific ticket
1280
-        if ($qty > 0 && $context === 'saleable') {
1281
-            // and subtract the sales for THIS ticket
1282
-            $qty = max($qty - $sold_and_reserved_for_this_ticket, 0);
1283
-            // echo "\n . qty: " . $qty . '<br />';
1284
-        }
1285
-        // echo "\nFINAL QTY: " . $qty . "<br /><br />";
1286
-        return $qty;
1287
-    }
1288
-
1289
-
1290
-    /**
1291
-     * Sets qty - IMPORTANT!!! Does NOT allow QTY to be set higher than the lowest reg limit of any related datetimes
1292
-     *
1293
-     * @param int $qty
1294
-     * @return void
1295
-     * @throws EE_Error
1296
-     * @throws ReflectionException
1297
-     */
1298
-    public function set_qty($qty)
1299
-    {
1300
-        $datetimes = $this->datetimes();
1301
-        foreach ($datetimes as $datetime) {
1302
-            if ($datetime instanceof EE_Datetime) {
1303
-                $qty = min($qty, $datetime->reg_limit());
1304
-            }
1305
-        }
1306
-        $this->set('TKT_qty', $qty);
1307
-    }
1308
-
1309
-
1310
-    /**
1311
-     * Gets uses
1312
-     *
1313
-     * @return int
1314
-     * @throws EE_Error
1315
-     * @throws ReflectionException
1316
-     */
1317
-    public function uses()
1318
-    {
1319
-        return $this->get('TKT_uses');
1320
-    }
1321
-
1322
-
1323
-    /**
1324
-     * Sets uses
1325
-     *
1326
-     * @param int $uses
1327
-     * @return void
1328
-     * @throws EE_Error
1329
-     * @throws ReflectionException
1330
-     */
1331
-    public function set_uses($uses)
1332
-    {
1333
-        $this->set('TKT_uses', $uses);
1334
-    }
1335
-
1336
-
1337
-    /**
1338
-     * returns whether ticket is required or not.
1339
-     *
1340
-     * @return boolean
1341
-     * @throws EE_Error
1342
-     * @throws ReflectionException
1343
-     */
1344
-    public function required()
1345
-    {
1346
-        return $this->get('TKT_required');
1347
-    }
1348
-
1349
-
1350
-    /**
1351
-     * sets the TKT_required property
1352
-     *
1353
-     * @param boolean $required
1354
-     * @return void
1355
-     * @throws EE_Error
1356
-     * @throws ReflectionException
1357
-     */
1358
-    public function set_required($required)
1359
-    {
1360
-        $this->set('TKT_required', $required);
1361
-    }
1362
-
1363
-
1364
-    /**
1365
-     * Gets taxable
1366
-     *
1367
-     * @return boolean
1368
-     * @throws EE_Error
1369
-     * @throws ReflectionException
1370
-     */
1371
-    public function taxable()
1372
-    {
1373
-        return $this->get('TKT_taxable');
1374
-    }
1375
-
1376
-
1377
-    /**
1378
-     * Sets taxable
1379
-     *
1380
-     * @param boolean $taxable
1381
-     * @return void
1382
-     * @throws EE_Error
1383
-     * @throws ReflectionException
1384
-     */
1385
-    public function set_taxable($taxable)
1386
-    {
1387
-        $this->set('TKT_taxable', $taxable);
1388
-    }
1389
-
1390
-
1391
-    /**
1392
-     * Gets is_default
1393
-     *
1394
-     * @return boolean
1395
-     * @throws EE_Error
1396
-     * @throws ReflectionException
1397
-     */
1398
-    public function is_default()
1399
-    {
1400
-        return $this->get('TKT_is_default');
1401
-    }
1402
-
1403
-
1404
-    /**
1405
-     * Sets is_default
1406
-     *
1407
-     * @param boolean $is_default
1408
-     * @return void
1409
-     * @throws EE_Error
1410
-     * @throws ReflectionException
1411
-     */
1412
-    public function set_is_default($is_default)
1413
-    {
1414
-        $this->set('TKT_is_default', $is_default);
1415
-    }
1416
-
1417
-
1418
-    /**
1419
-     * Gets order
1420
-     *
1421
-     * @return int
1422
-     * @throws EE_Error
1423
-     * @throws ReflectionException
1424
-     */
1425
-    public function order()
1426
-    {
1427
-        return $this->get('TKT_order');
1428
-    }
1429
-
1430
-
1431
-    /**
1432
-     * Sets order
1433
-     *
1434
-     * @param int $order
1435
-     * @return void
1436
-     * @throws EE_Error
1437
-     * @throws ReflectionException
1438
-     */
1439
-    public function set_order($order)
1440
-    {
1441
-        $this->set('TKT_order', $order);
1442
-    }
1443
-
1444
-
1445
-    /**
1446
-     * Gets row
1447
-     *
1448
-     * @return int
1449
-     * @throws EE_Error
1450
-     * @throws ReflectionException
1451
-     */
1452
-    public function row()
1453
-    {
1454
-        return $this->get('TKT_row');
1455
-    }
1456
-
1457
-
1458
-    /**
1459
-     * Sets row
1460
-     *
1461
-     * @param int $row
1462
-     * @return void
1463
-     * @throws EE_Error
1464
-     * @throws ReflectionException
1465
-     */
1466
-    public function set_row($row)
1467
-    {
1468
-        $this->set('TKT_row', $row);
1469
-    }
1470
-
1471
-
1472
-    /**
1473
-     * Gets deleted
1474
-     *
1475
-     * @return boolean
1476
-     * @throws EE_Error
1477
-     * @throws ReflectionException
1478
-     */
1479
-    public function deleted()
1480
-    {
1481
-        return $this->get('TKT_deleted');
1482
-    }
1483
-
1484
-
1485
-    /**
1486
-     * Sets deleted
1487
-     *
1488
-     * @param boolean $deleted
1489
-     * @return void
1490
-     * @throws EE_Error
1491
-     * @throws ReflectionException
1492
-     */
1493
-    public function set_deleted($deleted)
1494
-    {
1495
-        $this->set('TKT_deleted', $deleted);
1496
-    }
1497
-
1498
-
1499
-    /**
1500
-     * Gets parent
1501
-     *
1502
-     * @return int
1503
-     * @throws EE_Error
1504
-     * @throws ReflectionException
1505
-     */
1506
-    public function parent_ID()
1507
-    {
1508
-        return $this->get('TKT_parent');
1509
-    }
1510
-
1511
-
1512
-    /**
1513
-     * Sets parent
1514
-     *
1515
-     * @param int $parent
1516
-     * @return void
1517
-     * @throws EE_Error
1518
-     * @throws ReflectionException
1519
-     */
1520
-    public function set_parent_ID($parent)
1521
-    {
1522
-        $this->set('TKT_parent', $parent);
1523
-    }
1524
-
1525
-
1526
-    /**
1527
-     * @return boolean
1528
-     * @throws EE_Error
1529
-     * @throws InvalidArgumentException
1530
-     * @throws InvalidDataTypeException
1531
-     * @throws InvalidInterfaceException
1532
-     * @throws ReflectionException
1533
-     */
1534
-    public function reverse_calculate()
1535
-    {
1536
-        return $this->get('TKT_reverse_calculate');
1537
-    }
1538
-
1539
-
1540
-    /**
1541
-     * @param boolean $reverse_calculate
1542
-     * @throws EE_Error
1543
-     * @throws InvalidArgumentException
1544
-     * @throws InvalidDataTypeException
1545
-     * @throws InvalidInterfaceException
1546
-     * @throws ReflectionException
1547
-     */
1548
-    public function set_reverse_calculate($reverse_calculate)
1549
-    {
1550
-        $this->set('TKT_reverse_calculate', $reverse_calculate);
1551
-    }
1552
-
1553
-
1554
-    /**
1555
-     * Gets a string which is handy for showing in gateways etc that describes the ticket.
1556
-     *
1557
-     * @return string
1558
-     * @throws EE_Error
1559
-     * @throws ReflectionException
1560
-     */
1561
-    public function name_and_info()
1562
-    {
1563
-        $times = [];
1564
-        foreach ($this->datetimes() as $datetime) {
1565
-            $times[] = $datetime->start_date_and_time();
1566
-        }
1567
-        return $this->name() . ' @ ' . implode(', ', $times) . ' for ' . $this->pretty_price();
1568
-    }
1569
-
1570
-
1571
-    /**
1572
-     * Gets name
1573
-     *
1574
-     * @return string
1575
-     * @throws EE_Error
1576
-     * @throws ReflectionException
1577
-     */
1578
-    public function name()
1579
-    {
1580
-        return $this->get('TKT_name');
1581
-    }
1582
-
1583
-
1584
-    /**
1585
-     * Gets price
1586
-     *
1587
-     * @return float
1588
-     * @throws EE_Error
1589
-     * @throws ReflectionException
1590
-     */
1591
-    public function price()
1592
-    {
1593
-        return $this->get('TKT_price');
1594
-    }
1595
-
1596
-
1597
-    /**
1598
-     * Gets all the registrations for this ticket
1599
-     *
1600
-     * @param array $query_params
1601
-     * @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md
1602
-     * @return EE_Registration[]|EE_Base_Class[]
1603
-     * @throws EE_Error
1604
-     * @throws ReflectionException
1605
-     */
1606
-    public function registrations($query_params = [])
1607
-    {
1608
-        return $this->get_many_related('Registration', $query_params);
1609
-    }
1610
-
1611
-
1612
-    /**
1613
-     * Updates the TKT_sold attribute (and saves) based on the number of APPROVED registrations for this ticket.
1614
-     *
1615
-     * @return int
1616
-     * @throws EE_Error
1617
-     * @throws ReflectionException
1618
-     */
1619
-    public function update_tickets_sold()
1620
-    {
1621
-        $count_regs_for_this_ticket = $this->count_registrations(
1622
-            [
1623
-                [
1624
-                    'STS_ID'      => EEM_Registration::status_id_approved,
1625
-                    'REG_deleted' => 0,
1626
-                ],
1627
-            ]
1628
-        );
1629
-        $this->set_sold($count_regs_for_this_ticket);
1630
-        $this->save();
1631
-        return $count_regs_for_this_ticket;
1632
-    }
1633
-
1634
-
1635
-    /**
1636
-     * Counts the registrations for this ticket
1637
-     *
1638
-     * @param array $query_params
1639
-     * @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md
1640
-     * @return int
1641
-     * @throws EE_Error
1642
-     * @throws ReflectionException
1643
-     */
1644
-    public function count_registrations($query_params = [])
1645
-    {
1646
-        return $this->count_related('Registration', $query_params);
1647
-    }
1648
-
1649
-
1650
-    /**
1651
-     * Implementation for EEI_Has_Icon interface method.
1652
-     *
1653
-     * @return string
1654
-     * @see EEI_Visual_Representation for comments
1655
-     */
1656
-    public function get_icon()
1657
-    {
1658
-        return '<span class="dashicons dashicons-tickets-alt"/>';
1659
-    }
1660
-
1661
-
1662
-    /**
1663
-     * Implementation of the EEI_Event_Relation interface method
1664
-     *
1665
-     * @return EE_Event
1666
-     * @throws EE_Error
1667
-     * @throws UnexpectedEntityException
1668
-     * @throws ReflectionException
1669
-     * @see EEI_Event_Relation for comments
1670
-     */
1671
-    public function get_related_event()
1672
-    {
1673
-        // get one datetime to use for getting the event
1674
-        $datetime = $this->first_datetime();
1675
-        if (! $datetime instanceof EE_Datetime) {
1676
-            throw new UnexpectedEntityException(
1677
-                $datetime,
1678
-                'EE_Datetime',
1679
-                sprintf(
1680
-                    __('The ticket (%s) is not associated with any valid datetimes.', 'event_espresso'),
1681
-                    $this->name()
1682
-                )
1683
-            );
1684
-        }
1685
-        $event = $datetime->event();
1686
-        if (! $event instanceof EE_Event) {
1687
-            throw new UnexpectedEntityException(
1688
-                $event,
1689
-                'EE_Event',
1690
-                sprintf(
1691
-                    __('The ticket (%s) is not associated with a valid event.', 'event_espresso'),
1692
-                    $this->name()
1693
-                )
1694
-            );
1695
-        }
1696
-        return $event;
1697
-    }
1698
-
1699
-
1700
-    /**
1701
-     * Implementation of the EEI_Event_Relation interface method
1702
-     *
1703
-     * @return string
1704
-     * @throws UnexpectedEntityException
1705
-     * @throws EE_Error
1706
-     * @throws ReflectionException
1707
-     * @see EEI_Event_Relation for comments
1708
-     */
1709
-    public function get_event_name()
1710
-    {
1711
-        $event = $this->get_related_event();
1712
-        return $event instanceof EE_Event ? $event->name() : '';
1713
-    }
1714
-
1715
-
1716
-    /**
1717
-     * Implementation of the EEI_Event_Relation interface method
1718
-     *
1719
-     * @return int
1720
-     * @throws UnexpectedEntityException
1721
-     * @throws EE_Error
1722
-     * @throws ReflectionException
1723
-     * @see EEI_Event_Relation for comments
1724
-     */
1725
-    public function get_event_ID()
1726
-    {
1727
-        $event = $this->get_related_event();
1728
-        return $event instanceof EE_Event ? $event->ID() : 0;
1729
-    }
1730
-
1731
-
1732
-    /**
1733
-     * This simply returns whether a ticket can be permanently deleted or not.
1734
-     * The criteria for determining this is whether the ticket has any related registrations.
1735
-     * If there are none then it can be permanently deleted.
1736
-     *
1737
-     * @return bool
1738
-     * @throws EE_Error
1739
-     * @throws ReflectionException
1740
-     */
1741
-    public function is_permanently_deleteable()
1742
-    {
1743
-        return $this->count_registrations() === 0;
1744
-    }
1745
-
1746
-
1747
-    /**
1748
-     * @return int
1749
-     * @throws EE_Error
1750
-     * @throws ReflectionException
1751
-     * @since   $VID:$
1752
-     */
1753
-    public function visibility(): int
1754
-    {
1755
-        return $this->get('TKT_visibility');
1756
-    }
1757
-
1758
-
1759
-    /**
1760
-     * @return int
1761
-     * @throws EE_Error
1762
-     * @throws ReflectionException
1763
-     * @since   $VID:$
1764
-     */
1765
-    public function isHidden(): int
1766
-    {
1767
-        return $this->visibility() === EEM_Ticket::TICKET_VISIBILITY_NONE_VALUE;
1768
-    }
1769
-
1770
-
1771
-    /**
1772
-     * @return int
1773
-     * @throws EE_Error
1774
-     * @throws ReflectionException
1775
-     * @since   $VID:$
1776
-     */
1777
-    public function isNotHidden(): int
1778
-    {
1779
-        return $this->visibility() > EEM_Ticket::TICKET_VISIBILITY_NONE_VALUE;
1780
-    }
1781
-
1782
-
1783
-    /**
1784
-     * @return int
1785
-     * @throws EE_Error
1786
-     * @throws ReflectionException
1787
-     * @since   $VID:$
1788
-     */
1789
-    public function isPublicOnly(): int
1790
-    {
1791
-        return $this->isNotHidden() && $this->visibility() <= EEM_Ticket::TICKET_VISIBILITY_PUBLIC_VALUE;
1792
-    }
1793
-
1794
-
1795
-    /**
1796
-     * @return int
1797
-     * @throws EE_Error
1798
-     * @throws ReflectionException
1799
-     * @since   $VID:$
1800
-     */
1801
-    public function isMembersOnly(): int
1802
-    {
1803
-        return $this->visibility() > EEM_Ticket::TICKET_VISIBILITY_PUBLIC_VALUE
1804
-               && $this->visibility() <= EEM_Ticket::TICKET_VISIBILITY_MEMBERS_ONLY_VALUE;
1805
-    }
1806
-
1807
-
1808
-    /**
1809
-     * @return int
1810
-     * @throws EE_Error
1811
-     * @throws ReflectionException
1812
-     * @since   $VID:$
1813
-     */
1814
-    public function isAdminsOnly(): int
1815
-    {
1816
-        return $this->visibility() > EEM_Ticket::TICKET_VISIBILITY_MEMBERS_ONLY_VALUE
1817
-               && $this->visibility() <= EEM_Ticket::TICKET_VISIBILITY_ADMINS_ONLY_VALUE;
1818
-    }
1819
-
1820
-
1821
-    /**
1822
-     * @return int
1823
-     * @throws EE_Error
1824
-     * @throws ReflectionException
1825
-     * @since   $VID:$
1826
-     */
1827
-    public function isAdminUiOnly(): int
1828
-    {
1829
-        return $this->visibility() > EEM_Ticket::TICKET_VISIBILITY_ADMINS_ONLY_VALUE
1830
-               && $this->visibility() <= EEM_Ticket::TICKET_VISIBILITY_ADMIN_UI_ONLY_VALUE;
1831
-    }
1832
-
1833
-
1834
-    /**
1835
-     * @param int $visibility
1836
-     * @throws EE_Error
1837
-     * @throws ReflectionException
1838
-     * @since   $VID:$
1839
-     */
1840
-    public function set_visibility(int $visibility)
1841
-    {
1842
-
1843
-        $ticket_visibility_options = $this->_model->ticketVisibilityOptions();
1844
-        $ticket_visibility         = -1;
1845
-        foreach ($ticket_visibility_options as $ticket_visibility_option) {
1846
-            if ($visibility === $ticket_visibility_option) {
1847
-                $ticket_visibility = $visibility;
1848
-            }
1849
-        }
1850
-        if ($ticket_visibility === -1) {
1851
-            throw new DomainException(
1852
-                sprintf(
1853
-                    esc_html__(
1854
-                        '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 ',
1855
-                        'event_espresso'
1856
-                    ),
1857
-                    $visibility,
1858
-                    '<br />',
1859
-                    var_export($ticket_visibility_options, true)
1860
-                )
1861
-            );
1862
-        }
1863
-        $this->set('TKT_visibility', $ticket_visibility);
1864
-    }
1865
-
1866
-
1867
-    /**
1868
-     * @param EE_Base_Class|int|string $otherObjectModelObjectOrID
1869
-     * @param string                   $relationName
1870
-     * @param array                    $extra_join_model_fields_n_values
1871
-     * @param string|null              $cache_id
1872
-     * @return EE_Base_Class
1873
-     * @throws EE_Error
1874
-     * @throws ReflectionException
1875
-     * @since   $VID:$
1876
-     */
1877
-    public function _add_relation_to(
1878
-        $otherObjectModelObjectOrID,
1879
-        $relationName,
1880
-        $extra_join_model_fields_n_values = [],
1881
-        $cache_id = null
1882
-    ) {
1883
-        if ($relationName === 'Datetime' && ! $this->hasRelation($otherObjectModelObjectOrID, $relationName)) {
1884
-            /** @var EE_Datetime $datetime */
1885
-            $datetime = EEM_Datetime::instance()->ensure_is_obj($otherObjectModelObjectOrID);
1886
-            $datetime->increaseSold($this->sold(), false);
1887
-            $datetime->increaseReserved($this->reserved());
1888
-            $datetime->save();
1889
-            $otherObjectModelObjectOrID = $datetime;
1890
-        }
1891
-        return parent::_add_relation_to(
1892
-            $otherObjectModelObjectOrID,
1893
-            $relationName,
1894
-            $extra_join_model_fields_n_values,
1895
-            $cache_id
1896
-        );
1897
-    }
1898
-
1899
-
1900
-    /**
1901
-     * @param EE_Base_Class|int|string $otherObjectModelObjectOrID
1902
-     * @param string                   $relationName
1903
-     * @param array                    $where_query
1904
-     * @return bool|EE_Base_Class|null
1905
-     * @throws EE_Error
1906
-     * @throws ReflectionException
1907
-     * @since   $VID:$
1908
-     */
1909
-    public function _remove_relation_to($otherObjectModelObjectOrID, $relationName, $where_query = [])
1910
-    {
1911
-        // if we're adding a new relation to a datetime
1912
-        if ($relationName === 'Datetime' && $this->hasRelation($otherObjectModelObjectOrID, $relationName)) {
1913
-            /** @var EE_Datetime $datetime */
1914
-            $datetime = EEM_Datetime::instance()->ensure_is_obj($otherObjectModelObjectOrID);
1915
-            $datetime->decreaseSold($this->sold());
1916
-            $datetime->decreaseReserved($this->reserved());
1917
-            $datetime->save();
1918
-            $otherObjectModelObjectOrID = $datetime;
1919
-        }
1920
-        return parent::_remove_relation_to(
1921
-            $otherObjectModelObjectOrID,
1922
-            $relationName,
1923
-            $where_query
1924
-        );
1925
-    }
1926
-
1927
-
1928
-    /**
1929
-     * Removes ALL the related things for the $relationName.
1930
-     *
1931
-     * @param string $relationName
1932
-     * @param array  $where_query_params
1933
-     * @return EE_Base_Class
1934
-     * @throws ReflectionException
1935
-     * @throws InvalidArgumentException
1936
-     * @throws InvalidInterfaceException
1937
-     * @throws InvalidDataTypeException
1938
-     * @throws EE_Error
1939
-     * @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md#0-where-conditions
1940
-     */
1941
-    public function _remove_relations($relationName, $where_query_params = [])
1942
-    {
1943
-        if ($relationName === 'Datetime') {
1944
-            $datetimes = $this->datetimes();
1945
-            foreach ($datetimes as $datetime) {
1946
-                $datetime->decreaseSold($this->sold());
1947
-                $datetime->decreaseReserved($this->reserved());
1948
-                $datetime->save();
1949
-            }
1950
-        }
1951
-        return parent::_remove_relations($relationName, $where_query_params);
1952
-    }
1953
-
1954
-
1955
-    /*******************************************************************
18
+	/**
19
+	 * TicKet Archived:
20
+	 * constant used by ticket_status() to indicate that a ticket is archived
21
+	 * and no longer available for purchase
22
+	 */
23
+	const archived = 'TKA';
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 On sale:
34
+	 * constant used by ticket_status() to indicate that a ticket is On Sale
35
+	 * and IS available for purchase
36
+	 */
37
+	const onsale = 'TKO';
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 Sold out:
48
+	 * constant used by ticket_status() to indicate that a ticket is sold out
49
+	 * and no longer available for purchases
50
+	 */
51
+	const sold_out = 'TKS';
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
+	 * @var TicketPriceModifiers
76
+	 */
77
+	protected $ticket_price_modifiers;
78
+
79
+
80
+	/**
81
+	 * @param array  $props_n_values          incoming values
82
+	 * @param string $timezone                incoming timezone (if not set the timezone set for the website will be
83
+	 *                                        used.)
84
+	 * @param array  $date_formats            incoming date_formats in an array where the first value is the
85
+	 *                                        date_format and the second value is the time format
86
+	 * @return EE_Ticket
87
+	 * @throws EE_Error
88
+	 * @throws ReflectionException
89
+	 */
90
+	public static function new_instance($props_n_values = [], $timezone = null, $date_formats = [])
91
+	{
92
+		$has_object = parent::_check_for_object($props_n_values, __CLASS__, $timezone, $date_formats);
93
+		return $has_object ?: new self($props_n_values, false, $timezone, $date_formats);
94
+	}
95
+
96
+
97
+	/**
98
+	 * @param array  $props_n_values  incoming values from the database
99
+	 * @param string $timezone        incoming timezone as set by the model.  If not set the timezone for
100
+	 *                                the website will be used.
101
+	 * @return EE_Ticket
102
+	 * @throws EE_Error
103
+	 * @throws ReflectionException
104
+	 */
105
+	public static function new_instance_from_db($props_n_values = [], $timezone = null)
106
+	{
107
+		return new self($props_n_values, true, $timezone);
108
+	}
109
+
110
+
111
+	/**
112
+	 * @param array  $fieldValues
113
+	 * @param false  $bydb
114
+	 * @param string $timezone
115
+	 * @param array  $date_formats
116
+	 * @throws EE_Error
117
+	 * @throws ReflectionException
118
+	 */
119
+	public function __construct($fieldValues = [], $bydb = false, $timezone = '', $date_formats = [])
120
+	{
121
+		parent::__construct($fieldValues, $bydb, $timezone, $date_formats);
122
+		$this->ticket_price_modifiers = new TicketPriceModifiers($this);
123
+	}
124
+
125
+
126
+	/**
127
+	 * @return bool
128
+	 * @throws EE_Error
129
+	 * @throws ReflectionException
130
+	 */
131
+	public function parent()
132
+	{
133
+		return $this->get('TKT_parent');
134
+	}
135
+
136
+
137
+	/**
138
+	 * return if a ticket has quantities available for purchase
139
+	 *
140
+	 * @param int $DTT_ID the primary key for a particular datetime
141
+	 * @return boolean
142
+	 * @throws EE_Error
143
+	 * @throws ReflectionException
144
+	 */
145
+	public function available($DTT_ID = 0)
146
+	{
147
+		// are we checking availability for a particular datetime ?
148
+		if ($DTT_ID) {
149
+			// get that datetime object
150
+			$datetime = $this->get_first_related('Datetime', [['DTT_ID' => $DTT_ID]]);
151
+			// if  ticket sales for this datetime have exceeded the reg limit...
152
+			if ($datetime instanceof EE_Datetime && $datetime->sold_out()) {
153
+				return false;
154
+			}
155
+		}
156
+		// datetime is still open for registration, but is this ticket sold out ?
157
+		return $this->qty() < 1 || $this->qty() > $this->sold();
158
+	}
159
+
160
+
161
+	/**
162
+	 * Using the start date and end date this method calculates whether the ticket is On Sale, Pending, or Expired
163
+	 *
164
+	 * @param bool        $display   true = we'll return a localized string, otherwise we just return the value of the
165
+	 *                               relevant status const
166
+	 * @param bool | null $remaining if it is already known that tickets are available, then simply pass a bool to save
167
+	 *                               further processing
168
+	 * @return mixed status int if the display string isn't requested
169
+	 * @throws EE_Error
170
+	 * @throws ReflectionException
171
+	 */
172
+	public function ticket_status($display = false, $remaining = null)
173
+	{
174
+		$remaining = is_bool($remaining) ? $remaining : $this->is_remaining();
175
+		if (! $remaining) {
176
+			return $display ? EEH_Template::pretty_status(EE_Ticket::sold_out, false, 'sentence') : EE_Ticket::sold_out;
177
+		}
178
+		if ($this->get('TKT_deleted')) {
179
+			return $display ? EEH_Template::pretty_status(EE_Ticket::archived, false, 'sentence') : EE_Ticket::archived;
180
+		}
181
+		if ($this->is_expired()) {
182
+			return $display ? EEH_Template::pretty_status(EE_Ticket::expired, false, 'sentence') : EE_Ticket::expired;
183
+		}
184
+		if ($this->is_pending()) {
185
+			return $display ? EEH_Template::pretty_status(EE_Ticket::pending, false, 'sentence') : EE_Ticket::pending;
186
+		}
187
+		if ($this->is_on_sale()) {
188
+			return $display ? EEH_Template::pretty_status(EE_Ticket::onsale, false, 'sentence') : EE_Ticket::onsale;
189
+		}
190
+		return '';
191
+	}
192
+
193
+
194
+	/**
195
+	 * The purpose of this method is to simply return a boolean for whether there are any tickets remaining for sale
196
+	 * considering ALL the factors used for figuring that out.
197
+	 *
198
+	 * @param int $DTT_ID if an int above 0 is included here then we get a specific dtt.
199
+	 * @return boolean         true = tickets remaining, false not.
200
+	 * @throws EE_Error
201
+	 * @throws ReflectionException
202
+	 */
203
+	public function is_remaining($DTT_ID = 0)
204
+	{
205
+		$num_remaining = $this->remaining($DTT_ID);
206
+		if ($num_remaining === 0) {
207
+			return false;
208
+		}
209
+		if ($num_remaining > 0 && $num_remaining < $this->min()) {
210
+			return false;
211
+		}
212
+		return true;
213
+	}
214
+
215
+
216
+	/**
217
+	 * return the total number of tickets available for purchase
218
+	 *
219
+	 * @param int $DTT_ID  the primary key for a particular datetime.
220
+	 *                     set to 0 for all related datetimes
221
+	 * @return int
222
+	 * @throws EE_Error
223
+	 * @throws ReflectionException
224
+	 */
225
+	public function remaining($DTT_ID = 0)
226
+	{
227
+		return $this->real_quantity_on_ticket('saleable', $DTT_ID);
228
+	}
229
+
230
+
231
+	/**
232
+	 * Gets min
233
+	 *
234
+	 * @return int
235
+	 * @throws EE_Error
236
+	 * @throws ReflectionException
237
+	 */
238
+	public function min()
239
+	{
240
+		return $this->get('TKT_min');
241
+	}
242
+
243
+
244
+	/**
245
+	 * return if a ticket is no longer available cause its available dates have expired.
246
+	 *
247
+	 * @return boolean
248
+	 * @throws EE_Error
249
+	 * @throws ReflectionException
250
+	 */
251
+	public function is_expired()
252
+	{
253
+		return ($this->get_raw('TKT_end_date') < time());
254
+	}
255
+
256
+
257
+	/**
258
+	 * Return if a ticket is yet to go on sale or not
259
+	 *
260
+	 * @return boolean
261
+	 * @throws EE_Error
262
+	 * @throws ReflectionException
263
+	 */
264
+	public function is_pending()
265
+	{
266
+		return ($this->get_raw('TKT_start_date') >= time());
267
+	}
268
+
269
+
270
+	/**
271
+	 * Return if a ticket is on sale or not
272
+	 *
273
+	 * @return boolean
274
+	 * @throws EE_Error
275
+	 * @throws ReflectionException
276
+	 */
277
+	public function is_on_sale()
278
+	{
279
+		return ($this->get_raw('TKT_start_date') <= time() && $this->get_raw('TKT_end_date') >= time());
280
+	}
281
+
282
+
283
+	/**
284
+	 * This returns the chronologically last datetime that this ticket is associated with
285
+	 *
286
+	 * @param string $date_format
287
+	 * @param string $conjunction - conjunction junction what's your function ? this string joins the start date with
288
+	 *                            the end date ie: Jan 01 "to" Dec 31
289
+	 * @return string
290
+	 * @throws EE_Error
291
+	 * @throws ReflectionException
292
+	 */
293
+	public function date_range($date_format = '', $conjunction = ' - ')
294
+	{
295
+		$date_format = ! empty($date_format) ? $date_format : $this->_dt_frmt;
296
+		$first_date  = $this->first_datetime() instanceof EE_Datetime
297
+			? $this->first_datetime()->get_i18n_datetime('DTT_EVT_start', $date_format)
298
+			: '';
299
+		$last_date   = $this->last_datetime() instanceof EE_Datetime
300
+			? $this->last_datetime()->get_i18n_datetime('DTT_EVT_end', $date_format)
301
+			: '';
302
+
303
+		return $first_date && $last_date ? $first_date . $conjunction . $last_date : '';
304
+	}
305
+
306
+
307
+	/**
308
+	 * This returns the chronologically first datetime that this ticket is associated with
309
+	 *
310
+	 * @return EE_Datetime
311
+	 * @throws EE_Error
312
+	 * @throws ReflectionException
313
+	 */
314
+	public function first_datetime()
315
+	{
316
+		$datetimes = $this->datetimes(['limit' => 1]);
317
+		return reset($datetimes);
318
+	}
319
+
320
+
321
+	/**
322
+	 * Gets all the datetimes this ticket can be used for attending.
323
+	 * Unless otherwise specified, orders datetimes by start date.
324
+	 *
325
+	 * @param array $query_params
326
+	 * @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md
327
+	 * @return EE_Datetime[]|EE_Base_Class[]
328
+	 * @throws EE_Error
329
+	 * @throws ReflectionException
330
+	 */
331
+	public function datetimes($query_params = [])
332
+	{
333
+		if (! isset($query_params['order_by'])) {
334
+			$query_params['order_by']['DTT_order'] = 'ASC';
335
+		}
336
+		return $this->get_many_related('Datetime', $query_params);
337
+	}
338
+
339
+
340
+	/**
341
+	 * This returns the chronologically last datetime that this ticket is associated with
342
+	 *
343
+	 * @return EE_Datetime
344
+	 * @throws EE_Error
345
+	 * @throws ReflectionException
346
+	 */
347
+	public function last_datetime()
348
+	{
349
+		$datetimes = $this->datetimes(['limit' => 1, 'order_by' => ['DTT_EVT_start' => 'DESC']]);
350
+		return end($datetimes);
351
+	}
352
+
353
+
354
+	/**
355
+	 * This returns the total tickets sold depending on the given parameters.
356
+	 *
357
+	 * @param string $what    Can be one of two options: 'ticket', 'datetime'.
358
+	 *                        'ticket' = total ticket sales for all datetimes this ticket is related to
359
+	 *                        'datetime' = total ticket sales for a specified datetime (required $dtt_id)
360
+	 *                        'datetime' = total ticket sales in the datetime_ticket table.
361
+	 *                        If $dtt_id is not given then we return an array of sales indexed by datetime.
362
+	 *                        If $dtt_id IS given then we return the tickets sold for that given datetime.
363
+	 * @param int    $dtt_id  [optional] include the dtt_id with $what = 'datetime'.
364
+	 * @return mixed (array|int)          how many tickets have sold
365
+	 * @throws EE_Error
366
+	 * @throws ReflectionException
367
+	 */
368
+	public function tickets_sold($what = 'ticket', $dtt_id = null)
369
+	{
370
+		$total        = 0;
371
+		$tickets_sold = $this->_all_tickets_sold();
372
+		switch ($what) {
373
+			case 'ticket':
374
+				return $tickets_sold['ticket'];
375
+
376
+			case 'datetime':
377
+				if (empty($tickets_sold['datetime'])) {
378
+					return $total;
379
+				}
380
+				if (! empty($dtt_id) && ! isset($tickets_sold['datetime'][ $dtt_id ])) {
381
+					EE_Error::add_error(
382
+						__(
383
+							'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?',
384
+							'event_espresso'
385
+						),
386
+						__FILE__,
387
+						__FUNCTION__,
388
+						__LINE__
389
+					);
390
+					return $total;
391
+				}
392
+				return empty($dtt_id) ? $tickets_sold['datetime'] : $tickets_sold['datetime'][ $dtt_id ];
393
+
394
+			default:
395
+				return $total;
396
+		}
397
+	}
398
+
399
+
400
+	/**
401
+	 * This returns an array indexed by datetime_id for tickets sold with this ticket.
402
+	 *
403
+	 * @return EE_Ticket[]
404
+	 * @throws EE_Error
405
+	 * @throws ReflectionException
406
+	 */
407
+	protected function _all_tickets_sold()
408
+	{
409
+		$datetimes    = $this->get_many_related('Datetime');
410
+		$tickets_sold = [];
411
+		if (! empty($datetimes)) {
412
+			foreach ($datetimes as $datetime) {
413
+				$tickets_sold['datetime'][ $datetime->ID() ] = $datetime->get('DTT_sold');
414
+			}
415
+		}
416
+		// Tickets sold
417
+		$tickets_sold['ticket'] = $this->sold();
418
+		return $tickets_sold;
419
+	}
420
+
421
+
422
+	/**
423
+	 * This returns the base price object for the ticket.
424
+	 *
425
+	 * @param bool $return_array whether to return as an array indexed by price id or just the object.
426
+	 * @return EE_Price|EE_Base_Class|EE_Price[]|EE_Base_Class[]
427
+	 * @throws EE_Error
428
+	 * @throws ReflectionException
429
+	 */
430
+	public function base_price(bool $return_array = false)
431
+	{
432
+		$base_price = $this->ticket_price_modifiers->getBasePrice();
433
+		if (! empty($base_price)) {
434
+			return $return_array ? $base_price : reset($base_price);
435
+		}
436
+		$_where = ['Price_Type.PBT_ID' => EEM_Price_Type::base_type_base_price];
437
+		return $return_array
438
+			? $this->get_many_related('Price', [$_where])
439
+			: $this->get_first_related('Price', [$_where]);
440
+	}
441
+
442
+
443
+	/**
444
+	 * This returns ONLY the price modifiers for the ticket (i.e. no taxes or base price)
445
+	 *
446
+	 * @return EE_Price[]
447
+	 * @throws EE_Error
448
+	 * @throws ReflectionException
449
+	 */
450
+	public function price_modifiers(): array
451
+	{
452
+		$price_modifiers = $this->usesGlobalTaxes()
453
+			? $this->ticket_price_modifiers->getAllDiscountAndSurchargeModifiersForTicket()
454
+			: $this->ticket_price_modifiers ->getAllModifiersForTicket();
455
+		if (! empty($price_modifiers)) {
456
+			return $price_modifiers;
457
+		}
458
+		return $this->prices(
459
+			[
460
+				[
461
+					'Price_Type.PBT_ID' => [
462
+						'NOT IN',
463
+						[EEM_Price_Type::base_type_base_price, EEM_Price_Type::base_type_tax],
464
+					]
465
+				]
466
+			]
467
+		);
468
+	}
469
+
470
+
471
+	/**
472
+	 * This returns ONLY the TAX price modifiers for the ticket
473
+	 *
474
+	 * @return EE_Price[]
475
+	 * @throws EE_Error
476
+	 * @throws ReflectionException
477
+	 */
478
+	public function tax_price_modifiers(): array
479
+	{
480
+		$tax_price_modifiers = $this->ticket_price_modifiers->getAllTaxesForTicket();
481
+		if (! empty($tax_price_modifiers)) {
482
+			return $tax_price_modifiers;
483
+		}
484
+		return $this->prices([['Price_Type.PBT_ID' => EEM_Price_Type::base_type_tax]]);
485
+	}
486
+
487
+
488
+	/**
489
+	 * Gets all the prices that combine to form the final price of this ticket
490
+	 *
491
+	 * @param array $query_params
492
+	 * @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md
493
+	 * @return EE_Price[]|EE_Base_Class[]
494
+	 * @throws EE_Error
495
+	 * @throws ReflectionException
496
+	 */
497
+	public function prices(array $query_params = []): array
498
+	{
499
+		if (! isset($query_params['order_by'])) {
500
+			$query_params['order_by']['PRC_order'] = 'ASC';
501
+		}
502
+		return $this->get_many_related('Price', $query_params);
503
+	}
504
+
505
+
506
+	/**
507
+	 * Gets all the ticket datetimes (ie, relations between datetimes and tickets)
508
+	 *
509
+	 * @param array $query_params
510
+	 * @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md
511
+	 * @return EE_Datetime_Ticket|EE_Base_Class[]
512
+	 * @throws EE_Error
513
+	 * @throws ReflectionException
514
+	 */
515
+	public function datetime_tickets($query_params = [])
516
+	{
517
+		return $this->get_many_related('Datetime_Ticket', $query_params);
518
+	}
519
+
520
+
521
+	/**
522
+	 * Gets all the datetimes from the db ordered by DTT_order
523
+	 *
524
+	 * @param boolean $show_expired
525
+	 * @param boolean $show_deleted
526
+	 * @return EE_Datetime[]
527
+	 * @throws EE_Error
528
+	 * @throws ReflectionException
529
+	 */
530
+	public function datetimes_ordered($show_expired = true, $show_deleted = false)
531
+	{
532
+		return EEM_Datetime::instance($this->_timezone)->get_datetimes_for_ticket_ordered_by_DTT_order(
533
+			$this->ID(),
534
+			$show_expired,
535
+			$show_deleted
536
+		);
537
+	}
538
+
539
+
540
+	/**
541
+	 * Gets ID
542
+	 *
543
+	 * @return int
544
+	 * @throws EE_Error
545
+	 * @throws ReflectionException
546
+	 */
547
+	public function ID()
548
+	{
549
+		return $this->get('TKT_ID');
550
+	}
551
+
552
+
553
+	/**
554
+	 * get the author of the ticket.
555
+	 *
556
+	 * @return int
557
+	 * @throws EE_Error
558
+	 * @throws ReflectionException
559
+	 * @since 4.5.0
560
+	 */
561
+	public function wp_user()
562
+	{
563
+		return $this->get('TKT_wp_user');
564
+	}
565
+
566
+
567
+	/**
568
+	 * Gets the template for the ticket
569
+	 *
570
+	 * @return EE_Ticket_Template|EE_Base_Class
571
+	 * @throws EE_Error
572
+	 * @throws ReflectionException
573
+	 */
574
+	public function template()
575
+	{
576
+		return $this->get_first_related('Ticket_Template');
577
+	}
578
+
579
+
580
+	/**
581
+	 * Simply returns an array of EE_Price objects that are taxes.
582
+	 *
583
+	 * @return EE_Price[]
584
+	 * @throws EE_Error
585
+	 * @throws ReflectionException
586
+	 */
587
+	public function get_ticket_taxes_for_admin(): array
588
+	{
589
+		return $this->usesGlobalTaxes() ? EE_Taxes::get_taxes_for_admin() : $this->tax_price_modifiers();
590
+	}
591
+
592
+
593
+	/**
594
+	 * alias of taxable() to better indicate that ticket uses the legacy method of applying default "global" taxes
595
+	 * as opposed to having tax price modifiers added directly to each ticket
596
+	 *
597
+	 * @return bool
598
+	 * @throws EE_Error
599
+	 * @throws ReflectionException
600
+	 * @since   $VID:$
601
+	 */
602
+	public function usesGlobalTaxes(): bool
603
+	{
604
+		return $this->taxable();
605
+	}
606
+
607
+
608
+	/**
609
+	 * @return float
610
+	 * @throws EE_Error
611
+	 * @throws ReflectionException
612
+	 */
613
+	public function ticket_price()
614
+	{
615
+		return $this->get('TKT_price');
616
+	}
617
+
618
+
619
+	/**
620
+	 * @return mixed
621
+	 * @throws EE_Error
622
+	 * @throws ReflectionException
623
+	 */
624
+	public function pretty_price()
625
+	{
626
+		return $this->get_pretty('TKT_price');
627
+	}
628
+
629
+
630
+	/**
631
+	 * @return bool
632
+	 * @throws EE_Error
633
+	 * @throws ReflectionException
634
+	 */
635
+	public function is_free()
636
+	{
637
+		return $this->get_ticket_total_with_taxes() === (float) 0;
638
+	}
639
+
640
+
641
+	/**
642
+	 * get_ticket_total_with_taxes
643
+	 *
644
+	 * @param bool $no_cache
645
+	 * @return float
646
+	 * @throws EE_Error
647
+	 * @throws ReflectionException
648
+	 */
649
+	public function get_ticket_total_with_taxes($no_cache = false)
650
+	{
651
+		if ($this->_ticket_total_with_taxes === null || $no_cache) {
652
+			$this->_ticket_total_with_taxes = $this->usesGlobalTaxes()
653
+				? $this->get_ticket_subtotal() + $this->get_ticket_taxes_total_for_admin()
654
+				: $this->ticket_price();
655
+		}
656
+		return (float) $this->_ticket_total_with_taxes;
657
+	}
658
+
659
+
660
+	/**
661
+	 * @throws EE_Error
662
+	 * @throws ReflectionException
663
+	 */
664
+	public function ensure_TKT_Price_correct()
665
+	{
666
+		$this->set('TKT_price', EE_Taxes::get_subtotal_for_admin($this));
667
+		$this->save();
668
+	}
669
+
670
+
671
+	/**
672
+	 * @return float
673
+	 * @throws EE_Error
674
+	 * @throws ReflectionException
675
+	 */
676
+	public function get_ticket_subtotal()
677
+	{
678
+		return EE_Taxes::get_subtotal_for_admin($this);
679
+	}
680
+
681
+
682
+	/**
683
+	 * Returns the total taxes applied to this ticket
684
+	 *
685
+	 * @return float
686
+	 * @throws EE_Error
687
+	 * @throws ReflectionException
688
+	 */
689
+	public function get_ticket_taxes_total_for_admin()
690
+	{
691
+		return EE_Taxes::get_total_taxes_for_admin($this);
692
+	}
693
+
694
+
695
+	/**
696
+	 * Sets name
697
+	 *
698
+	 * @param string $name
699
+	 * @throws EE_Error
700
+	 * @throws ReflectionException
701
+	 */
702
+	public function set_name($name)
703
+	{
704
+		$this->set('TKT_name', $name);
705
+	}
706
+
707
+
708
+	/**
709
+	 * Gets description
710
+	 *
711
+	 * @return string
712
+	 * @throws EE_Error
713
+	 * @throws ReflectionException
714
+	 */
715
+	public function description()
716
+	{
717
+		return $this->get('TKT_description');
718
+	}
719
+
720
+
721
+	/**
722
+	 * Sets description
723
+	 *
724
+	 * @param string $description
725
+	 * @throws EE_Error
726
+	 * @throws ReflectionException
727
+	 */
728
+	public function set_description($description)
729
+	{
730
+		$this->set('TKT_description', $description);
731
+	}
732
+
733
+
734
+	/**
735
+	 * Gets start_date
736
+	 *
737
+	 * @param string $date_format
738
+	 * @param string $time_format
739
+	 * @return string
740
+	 * @throws EE_Error
741
+	 * @throws ReflectionException
742
+	 */
743
+	public function start_date($date_format = '', $time_format = '')
744
+	{
745
+		return $this->_get_datetime('TKT_start_date', $date_format, $time_format);
746
+	}
747
+
748
+
749
+	/**
750
+	 * Sets start_date
751
+	 *
752
+	 * @param string $start_date
753
+	 * @return void
754
+	 * @throws EE_Error
755
+	 * @throws ReflectionException
756
+	 */
757
+	public function set_start_date($start_date)
758
+	{
759
+		$this->_set_date_time('B', $start_date, 'TKT_start_date');
760
+	}
761
+
762
+
763
+	/**
764
+	 * Gets end_date
765
+	 *
766
+	 * @param string $date_format
767
+	 * @param string $time_format
768
+	 * @return string
769
+	 * @throws EE_Error
770
+	 * @throws ReflectionException
771
+	 */
772
+	public function end_date($date_format = '', $time_format = '')
773
+	{
774
+		return $this->_get_datetime('TKT_end_date', $date_format, $time_format);
775
+	}
776
+
777
+
778
+	/**
779
+	 * Sets end_date
780
+	 *
781
+	 * @param string $end_date
782
+	 * @return void
783
+	 * @throws EE_Error
784
+	 * @throws ReflectionException
785
+	 */
786
+	public function set_end_date($end_date)
787
+	{
788
+		$this->_set_date_time('B', $end_date, 'TKT_end_date');
789
+	}
790
+
791
+
792
+	/**
793
+	 * Sets sell until time
794
+	 *
795
+	 * @param string $time a string representation of the sell until time (ex 9am or 7:30pm)
796
+	 * @throws EE_Error
797
+	 * @throws ReflectionException
798
+	 * @since 4.5.0
799
+	 */
800
+	public function set_end_time($time)
801
+	{
802
+		$this->_set_time_for($time, 'TKT_end_date');
803
+	}
804
+
805
+
806
+	/**
807
+	 * Sets min
808
+	 *
809
+	 * @param int $min
810
+	 * @return void
811
+	 * @throws EE_Error
812
+	 * @throws ReflectionException
813
+	 */
814
+	public function set_min($min)
815
+	{
816
+		$this->set('TKT_min', $min);
817
+	}
818
+
819
+
820
+	/**
821
+	 * Gets max
822
+	 *
823
+	 * @return int
824
+	 * @throws EE_Error
825
+	 * @throws ReflectionException
826
+	 */
827
+	public function max()
828
+	{
829
+		return $this->get('TKT_max');
830
+	}
831
+
832
+
833
+	/**
834
+	 * Sets max
835
+	 *
836
+	 * @param int $max
837
+	 * @return void
838
+	 * @throws EE_Error
839
+	 * @throws ReflectionException
840
+	 */
841
+	public function set_max($max)
842
+	{
843
+		$this->set('TKT_max', $max);
844
+	}
845
+
846
+
847
+	/**
848
+	 * Sets price
849
+	 *
850
+	 * @param float $price
851
+	 * @return void
852
+	 * @throws EE_Error
853
+	 * @throws ReflectionException
854
+	 */
855
+	public function set_price($price)
856
+	{
857
+		$this->set('TKT_price', $price);
858
+	}
859
+
860
+
861
+	/**
862
+	 * Gets sold
863
+	 *
864
+	 * @return int
865
+	 * @throws EE_Error
866
+	 * @throws ReflectionException
867
+	 */
868
+	public function sold()
869
+	{
870
+		return $this->get_raw('TKT_sold');
871
+	}
872
+
873
+
874
+	/**
875
+	 * Sets sold
876
+	 *
877
+	 * @param int $sold
878
+	 * @return void
879
+	 * @throws EE_Error
880
+	 * @throws ReflectionException
881
+	 */
882
+	public function set_sold($sold)
883
+	{
884
+		// sold can not go below zero
885
+		$sold = max(0, $sold);
886
+		$this->set('TKT_sold', $sold);
887
+	}
888
+
889
+
890
+	/**
891
+	 * Increments sold by amount passed by $qty AND decrements the reserved count on both this ticket and its
892
+	 * associated datetimes.
893
+	 *
894
+	 * @param int $qty
895
+	 * @return boolean
896
+	 * @throws EE_Error
897
+	 * @throws InvalidArgumentException
898
+	 * @throws InvalidDataTypeException
899
+	 * @throws InvalidInterfaceException
900
+	 * @throws ReflectionException
901
+	 * @since 4.9.80.p
902
+	 */
903
+	public function increaseSold($qty = 1)
904
+	{
905
+		$qty = absint($qty);
906
+		// increment sold and decrement reserved datetime quantities simultaneously
907
+		// don't worry about failures, because they must have already had a spot reserved
908
+		$this->increaseSoldForDatetimes($qty);
909
+		// Increment and decrement ticket quantities simultaneously
910
+		$success = $this->adjustNumericFieldsInDb(
911
+			[
912
+				'TKT_reserved' => $qty * -1,
913
+				'TKT_sold'     => $qty,
914
+			]
915
+		);
916
+		do_action(
917
+			'AHEE__EE_Ticket__increase_sold',
918
+			$this,
919
+			$qty,
920
+			$this->sold(),
921
+			$success
922
+		);
923
+		return $success;
924
+	}
925
+
926
+
927
+	/**
928
+	 * On each datetime related to this ticket, increases its sold count and decreases its reserved count by $qty.
929
+	 *
930
+	 * @param int           $qty positive or negative. Positive means to increase sold counts (and decrease reserved
931
+	 *                           counts), Negative means to decreases old counts (and increase reserved counts).
932
+	 * @param EE_Datetime[] $datetimes
933
+	 * @throws EE_Error
934
+	 * @throws InvalidArgumentException
935
+	 * @throws InvalidDataTypeException
936
+	 * @throws InvalidInterfaceException
937
+	 * @throws ReflectionException
938
+	 * @since 4.9.80.p
939
+	 */
940
+	protected function increaseSoldForDatetimes($qty, array $datetimes = [])
941
+	{
942
+		$datetimes = ! empty($datetimes) ? $datetimes : $this->datetimes();
943
+		foreach ($datetimes as $datetime) {
944
+			$datetime->increaseSold($qty);
945
+		}
946
+	}
947
+
948
+
949
+	/**
950
+	 * Decrements (subtracts) sold by amount passed by $qty on both the ticket and its related datetimes directly in the
951
+	 * DB and then updates the model objects.
952
+	 * Does not affect the reserved counts.
953
+	 *
954
+	 * @param int $qty
955
+	 * @return boolean
956
+	 * @throws EE_Error
957
+	 * @throws InvalidArgumentException
958
+	 * @throws InvalidDataTypeException
959
+	 * @throws InvalidInterfaceException
960
+	 * @throws ReflectionException
961
+	 * @since 4.9.80.p
962
+	 */
963
+	public function decreaseSold($qty = 1)
964
+	{
965
+		$qty = absint($qty);
966
+		$this->decreaseSoldForDatetimes($qty);
967
+		$success = $this->adjustNumericFieldsInDb(
968
+			[
969
+				'TKT_sold' => $qty * -1,
970
+			]
971
+		);
972
+		do_action(
973
+			'AHEE__EE_Ticket__decrease_sold',
974
+			$this,
975
+			$qty,
976
+			$this->sold(),
977
+			$success
978
+		);
979
+		return $success;
980
+	}
981
+
982
+
983
+	/**
984
+	 * Decreases sold on related datetimes
985
+	 *
986
+	 * @param int           $qty
987
+	 * @param EE_Datetime[] $datetimes
988
+	 * @return void
989
+	 * @throws EE_Error
990
+	 * @throws InvalidArgumentException
991
+	 * @throws InvalidDataTypeException
992
+	 * @throws InvalidInterfaceException
993
+	 * @throws ReflectionException
994
+	 * @since 4.9.80.p
995
+	 */
996
+	protected function decreaseSoldForDatetimes($qty = 1, array $datetimes = [])
997
+	{
998
+		$datetimes = ! empty($datetimes) ? $datetimes : $this->datetimes();
999
+		if (is_array($datetimes)) {
1000
+			foreach ($datetimes as $datetime) {
1001
+				if ($datetime instanceof EE_Datetime) {
1002
+					$datetime->decreaseSold($qty);
1003
+				}
1004
+			}
1005
+		}
1006
+	}
1007
+
1008
+
1009
+	/**
1010
+	 * Gets qty of reserved tickets
1011
+	 *
1012
+	 * @return int
1013
+	 * @throws EE_Error
1014
+	 * @throws ReflectionException
1015
+	 */
1016
+	public function reserved()
1017
+	{
1018
+		return $this->get_raw('TKT_reserved');
1019
+	}
1020
+
1021
+
1022
+	/**
1023
+	 * Sets reserved
1024
+	 *
1025
+	 * @param int $reserved
1026
+	 * @return void
1027
+	 * @throws EE_Error
1028
+	 * @throws ReflectionException
1029
+	 */
1030
+	public function set_reserved($reserved)
1031
+	{
1032
+		// reserved can not go below zero
1033
+		$reserved = max(0, (int) $reserved);
1034
+		$this->set('TKT_reserved', $reserved);
1035
+	}
1036
+
1037
+
1038
+	/**
1039
+	 * Increments reserved by amount passed by $qty, and persists it immediately to the database.
1040
+	 *
1041
+	 * @param int    $qty
1042
+	 * @param string $source
1043
+	 * @return bool whether we successfully reserved the ticket or not.
1044
+	 * @throws EE_Error
1045
+	 * @throws InvalidArgumentException
1046
+	 * @throws ReflectionException
1047
+	 * @throws InvalidDataTypeException
1048
+	 * @throws InvalidInterfaceException
1049
+	 * @since 4.9.80.p
1050
+	 */
1051
+	public function increaseReserved($qty = 1, $source = 'unknown')
1052
+	{
1053
+		$qty = absint($qty);
1054
+		do_action(
1055
+			'AHEE__EE_Ticket__increase_reserved__begin',
1056
+			$this,
1057
+			$qty,
1058
+			$source
1059
+		);
1060
+		$this->add_extra_meta(EE_Ticket::META_KEY_TICKET_RESERVATIONS, "{$qty} from {$source}");
1061
+		$success                         = false;
1062
+		$datetimes_adjusted_successfully = $this->increaseReservedForDatetimes($qty);
1063
+		if ($datetimes_adjusted_successfully) {
1064
+			$success = $this->incrementFieldConditionallyInDb(
1065
+				'TKT_reserved',
1066
+				'TKT_sold',
1067
+				'TKT_qty',
1068
+				$qty
1069
+			);
1070
+			if (! $success) {
1071
+				// The datetimes were successfully bumped, but not the
1072
+				// ticket. So we need to manually rollback the datetimes.
1073
+				$this->decreaseReservedForDatetimes($qty);
1074
+			}
1075
+		}
1076
+		do_action(
1077
+			'AHEE__EE_Ticket__increase_reserved',
1078
+			$this,
1079
+			$qty,
1080
+			$this->reserved(),
1081
+			$success
1082
+		);
1083
+		return $success;
1084
+	}
1085
+
1086
+
1087
+	/**
1088
+	 * Increases reserved counts on related datetimes
1089
+	 *
1090
+	 * @param int           $qty
1091
+	 * @param EE_Datetime[] $datetimes
1092
+	 * @return boolean indicating success
1093
+	 * @throws EE_Error
1094
+	 * @throws InvalidArgumentException
1095
+	 * @throws InvalidDataTypeException
1096
+	 * @throws InvalidInterfaceException
1097
+	 * @throws ReflectionException
1098
+	 * @since 4.9.80.p
1099
+	 */
1100
+	protected function increaseReservedForDatetimes($qty = 1, array $datetimes = [])
1101
+	{
1102
+		$datetimes         = ! empty($datetimes) ? $datetimes : $this->datetimes();
1103
+		$datetimes_updated = [];
1104
+		$limit_exceeded    = false;
1105
+		if (is_array($datetimes)) {
1106
+			foreach ($datetimes as $datetime) {
1107
+				if ($datetime instanceof EE_Datetime) {
1108
+					if ($datetime->increaseReserved($qty)) {
1109
+						$datetimes_updated[] = $datetime;
1110
+					} else {
1111
+						$limit_exceeded = true;
1112
+						break;
1113
+					}
1114
+				}
1115
+			}
1116
+			// If somewhere along the way we detected a datetime whose
1117
+			// limit was exceeded, do a manual rollback.
1118
+			if ($limit_exceeded) {
1119
+				$this->decreaseReservedForDatetimes($qty, $datetimes_updated);
1120
+				return false;
1121
+			}
1122
+		}
1123
+		return true;
1124
+	}
1125
+
1126
+
1127
+	/**
1128
+	 * Decrements (subtracts) reserved by amount passed by $qty, and persists it immediately to the database.
1129
+	 *
1130
+	 * @param int    $qty
1131
+	 * @param bool   $adjust_datetimes
1132
+	 * @param string $source
1133
+	 * @return boolean
1134
+	 * @throws EE_Error
1135
+	 * @throws InvalidArgumentException
1136
+	 * @throws ReflectionException
1137
+	 * @throws InvalidDataTypeException
1138
+	 * @throws InvalidInterfaceException
1139
+	 * @since 4.9.80.p
1140
+	 */
1141
+	public function decreaseReserved($qty = 1, $adjust_datetimes = true, $source = 'unknown')
1142
+	{
1143
+		$qty = absint($qty);
1144
+		$this->add_extra_meta(EE_Ticket::META_KEY_TICKET_RESERVATIONS, "-{$qty} from {$source}");
1145
+		if ($adjust_datetimes) {
1146
+			$this->decreaseReservedForDatetimes($qty);
1147
+		}
1148
+		$success = $this->adjustNumericFieldsInDb(
1149
+			[
1150
+				'TKT_reserved' => $qty * -1,
1151
+			]
1152
+		);
1153
+		do_action(
1154
+			'AHEE__EE_Ticket__decrease_reserved',
1155
+			$this,
1156
+			$qty,
1157
+			$this->reserved(),
1158
+			$success
1159
+		);
1160
+		return $success;
1161
+	}
1162
+
1163
+
1164
+	/**
1165
+	 * Decreases the reserved count on the specified datetimes.
1166
+	 *
1167
+	 * @param int           $qty
1168
+	 * @param EE_Datetime[] $datetimes
1169
+	 * @throws EE_Error
1170
+	 * @throws InvalidArgumentException
1171
+	 * @throws ReflectionException
1172
+	 * @throws InvalidDataTypeException
1173
+	 * @throws InvalidInterfaceException
1174
+	 * @since 4.9.80.p
1175
+	 */
1176
+	protected function decreaseReservedForDatetimes($qty = 1, array $datetimes = [])
1177
+	{
1178
+		$datetimes = ! empty($datetimes) ? $datetimes : $this->datetimes();
1179
+		foreach ($datetimes as $datetime) {
1180
+			if ($datetime instanceof EE_Datetime) {
1181
+				$datetime->decreaseReserved($qty);
1182
+			}
1183
+		}
1184
+	}
1185
+
1186
+
1187
+	/**
1188
+	 * Gets ticket quantity
1189
+	 *
1190
+	 * @param string $context     ticket quantity is somewhat subjective depending on the exact information sought
1191
+	 *                            therefore $context can be one of three values: '', 'reg_limit', or 'saleable'
1192
+	 *                            '' (default) quantity is the actual db value for TKT_qty, unaffected by other objects
1193
+	 *                            REG LIMIT: caps qty based on DTT_reg_limit for ALL related datetimes
1194
+	 *                            SALEABLE: also considers datetime sold and returns zero if ANY DTT is sold out, and
1195
+	 *                            is therefore the truest measure of tickets that can be purchased at the moment
1196
+	 * @return int
1197
+	 * @throws EE_Error
1198
+	 * @throws ReflectionException
1199
+	 */
1200
+	public function qty($context = '')
1201
+	{
1202
+		switch ($context) {
1203
+			case 'reg_limit':
1204
+				return $this->real_quantity_on_ticket();
1205
+			case 'saleable':
1206
+				return $this->real_quantity_on_ticket('saleable');
1207
+			default:
1208
+				return $this->get_raw('TKT_qty');
1209
+		}
1210
+	}
1211
+
1212
+
1213
+	/**
1214
+	 * Gets ticket quantity
1215
+	 *
1216
+	 * @param string $context     ticket quantity is somewhat subjective depending on the exact information sought
1217
+	 *                            therefore $context can be one of two values: 'reg_limit', or 'saleable'
1218
+	 *                            REG LIMIT: caps qty based on DTT_reg_limit for ALL related datetimes
1219
+	 *                            SALEABLE: also considers datetime sold and returns zero if ANY DTT is sold out, and
1220
+	 *                            is therefore the truest measure of tickets that can be purchased at the moment
1221
+	 * @param int    $DTT_ID      the primary key for a particular datetime.
1222
+	 *                            set to 0 for all related datetimes
1223
+	 * @return int
1224
+	 * @throws EE_Error
1225
+	 * @throws ReflectionException
1226
+	 */
1227
+	public function real_quantity_on_ticket($context = 'reg_limit', $DTT_ID = 0)
1228
+	{
1229
+		$raw = $this->get_raw('TKT_qty');
1230
+		// return immediately if it's zero
1231
+		if ($raw === 0) {
1232
+			return $raw;
1233
+		}
1234
+		// echo "\n\n<br />Ticket: " . $this->name() . '<br />';
1235
+		// ensure qty doesn't exceed raw value for THIS ticket
1236
+		$qty = min(EE_INF, $raw);
1237
+		// echo "\n . qty: " . $qty . '<br />';
1238
+		// calculate this ticket's total sales and reservations
1239
+		$sold_and_reserved_for_this_ticket = $this->sold() + $this->reserved();
1240
+		// echo "\n . sold: " . $this->sold() . '<br />';
1241
+		// echo "\n . reserved: " . $this->reserved() . '<br />';
1242
+		// echo "\n . sold_and_reserved_for_this_ticket: " . $sold_and_reserved_for_this_ticket . '<br />';
1243
+		// first we need to calculate the maximum number of tickets available for the datetime
1244
+		// do we want data for one datetime or all of them ?
1245
+		$query_params = $DTT_ID ? [['DTT_ID' => $DTT_ID]] : [];
1246
+		$datetimes    = $this->datetimes($query_params);
1247
+		if (is_array($datetimes) && ! empty($datetimes)) {
1248
+			foreach ($datetimes as $datetime) {
1249
+				if ($datetime instanceof EE_Datetime) {
1250
+					$datetime->refresh_from_db();
1251
+					// echo "\n . . datetime name: " . $datetime->name() . '<br />';
1252
+					// echo "\n . . datetime ID: " . $datetime->ID() . '<br />';
1253
+					// initialize with no restrictions for each datetime
1254
+					// but adjust datetime qty based on datetime reg limit
1255
+					$datetime_qty = min(EE_INF, $datetime->reg_limit());
1256
+					// echo "\n . . . datetime reg_limit: " . $datetime->reg_limit() . '<br />';
1257
+					// echo "\n . . . datetime_qty: " . $datetime_qty . '<br />';
1258
+					// if we want the actual saleable amount, then we need to consider OTHER ticket sales
1259
+					// and reservations for this datetime, that do NOT include sales and reservations
1260
+					// for this ticket (so we add $this->sold() and $this->reserved() back in)
1261
+					if ($context === 'saleable') {
1262
+						$datetime_qty = max(
1263
+							$datetime_qty - $datetime->sold_and_reserved() + $sold_and_reserved_for_this_ticket,
1264
+							0
1265
+						);
1266
+						// echo "\n . . . datetime sold: " . $datetime->sold() . '<br />';
1267
+						// echo "\n . . . datetime reserved: " . $datetime->reserved() . '<br />';
1268
+						// echo "\n . . . datetime sold_and_reserved: " . $datetime->sold_and_reserved() . '<br />';
1269
+						// echo "\n . . . datetime_qty: " . $datetime_qty . '<br />';
1270
+						$datetime_qty = ! $datetime->sold_out() ? $datetime_qty : 0;
1271
+						// echo "\n . . . datetime_qty: " . $datetime_qty . '<br />';
1272
+					}
1273
+					$qty = min($datetime_qty, $qty);
1274
+					// echo "\n . . qty: " . $qty . '<br />';
1275
+				}
1276
+			}
1277
+		}
1278
+		// NOW that we know the  maximum number of tickets available for the datetime
1279
+		// we can finally factor in the details for this specific ticket
1280
+		if ($qty > 0 && $context === 'saleable') {
1281
+			// and subtract the sales for THIS ticket
1282
+			$qty = max($qty - $sold_and_reserved_for_this_ticket, 0);
1283
+			// echo "\n . qty: " . $qty . '<br />';
1284
+		}
1285
+		// echo "\nFINAL QTY: " . $qty . "<br /><br />";
1286
+		return $qty;
1287
+	}
1288
+
1289
+
1290
+	/**
1291
+	 * Sets qty - IMPORTANT!!! Does NOT allow QTY to be set higher than the lowest reg limit of any related datetimes
1292
+	 *
1293
+	 * @param int $qty
1294
+	 * @return void
1295
+	 * @throws EE_Error
1296
+	 * @throws ReflectionException
1297
+	 */
1298
+	public function set_qty($qty)
1299
+	{
1300
+		$datetimes = $this->datetimes();
1301
+		foreach ($datetimes as $datetime) {
1302
+			if ($datetime instanceof EE_Datetime) {
1303
+				$qty = min($qty, $datetime->reg_limit());
1304
+			}
1305
+		}
1306
+		$this->set('TKT_qty', $qty);
1307
+	}
1308
+
1309
+
1310
+	/**
1311
+	 * Gets uses
1312
+	 *
1313
+	 * @return int
1314
+	 * @throws EE_Error
1315
+	 * @throws ReflectionException
1316
+	 */
1317
+	public function uses()
1318
+	{
1319
+		return $this->get('TKT_uses');
1320
+	}
1321
+
1322
+
1323
+	/**
1324
+	 * Sets uses
1325
+	 *
1326
+	 * @param int $uses
1327
+	 * @return void
1328
+	 * @throws EE_Error
1329
+	 * @throws ReflectionException
1330
+	 */
1331
+	public function set_uses($uses)
1332
+	{
1333
+		$this->set('TKT_uses', $uses);
1334
+	}
1335
+
1336
+
1337
+	/**
1338
+	 * returns whether ticket is required or not.
1339
+	 *
1340
+	 * @return boolean
1341
+	 * @throws EE_Error
1342
+	 * @throws ReflectionException
1343
+	 */
1344
+	public function required()
1345
+	{
1346
+		return $this->get('TKT_required');
1347
+	}
1348
+
1349
+
1350
+	/**
1351
+	 * sets the TKT_required property
1352
+	 *
1353
+	 * @param boolean $required
1354
+	 * @return void
1355
+	 * @throws EE_Error
1356
+	 * @throws ReflectionException
1357
+	 */
1358
+	public function set_required($required)
1359
+	{
1360
+		$this->set('TKT_required', $required);
1361
+	}
1362
+
1363
+
1364
+	/**
1365
+	 * Gets taxable
1366
+	 *
1367
+	 * @return boolean
1368
+	 * @throws EE_Error
1369
+	 * @throws ReflectionException
1370
+	 */
1371
+	public function taxable()
1372
+	{
1373
+		return $this->get('TKT_taxable');
1374
+	}
1375
+
1376
+
1377
+	/**
1378
+	 * Sets taxable
1379
+	 *
1380
+	 * @param boolean $taxable
1381
+	 * @return void
1382
+	 * @throws EE_Error
1383
+	 * @throws ReflectionException
1384
+	 */
1385
+	public function set_taxable($taxable)
1386
+	{
1387
+		$this->set('TKT_taxable', $taxable);
1388
+	}
1389
+
1390
+
1391
+	/**
1392
+	 * Gets is_default
1393
+	 *
1394
+	 * @return boolean
1395
+	 * @throws EE_Error
1396
+	 * @throws ReflectionException
1397
+	 */
1398
+	public function is_default()
1399
+	{
1400
+		return $this->get('TKT_is_default');
1401
+	}
1402
+
1403
+
1404
+	/**
1405
+	 * Sets is_default
1406
+	 *
1407
+	 * @param boolean $is_default
1408
+	 * @return void
1409
+	 * @throws EE_Error
1410
+	 * @throws ReflectionException
1411
+	 */
1412
+	public function set_is_default($is_default)
1413
+	{
1414
+		$this->set('TKT_is_default', $is_default);
1415
+	}
1416
+
1417
+
1418
+	/**
1419
+	 * Gets order
1420
+	 *
1421
+	 * @return int
1422
+	 * @throws EE_Error
1423
+	 * @throws ReflectionException
1424
+	 */
1425
+	public function order()
1426
+	{
1427
+		return $this->get('TKT_order');
1428
+	}
1429
+
1430
+
1431
+	/**
1432
+	 * Sets order
1433
+	 *
1434
+	 * @param int $order
1435
+	 * @return void
1436
+	 * @throws EE_Error
1437
+	 * @throws ReflectionException
1438
+	 */
1439
+	public function set_order($order)
1440
+	{
1441
+		$this->set('TKT_order', $order);
1442
+	}
1443
+
1444
+
1445
+	/**
1446
+	 * Gets row
1447
+	 *
1448
+	 * @return int
1449
+	 * @throws EE_Error
1450
+	 * @throws ReflectionException
1451
+	 */
1452
+	public function row()
1453
+	{
1454
+		return $this->get('TKT_row');
1455
+	}
1456
+
1457
+
1458
+	/**
1459
+	 * Sets row
1460
+	 *
1461
+	 * @param int $row
1462
+	 * @return void
1463
+	 * @throws EE_Error
1464
+	 * @throws ReflectionException
1465
+	 */
1466
+	public function set_row($row)
1467
+	{
1468
+		$this->set('TKT_row', $row);
1469
+	}
1470
+
1471
+
1472
+	/**
1473
+	 * Gets deleted
1474
+	 *
1475
+	 * @return boolean
1476
+	 * @throws EE_Error
1477
+	 * @throws ReflectionException
1478
+	 */
1479
+	public function deleted()
1480
+	{
1481
+		return $this->get('TKT_deleted');
1482
+	}
1483
+
1484
+
1485
+	/**
1486
+	 * Sets deleted
1487
+	 *
1488
+	 * @param boolean $deleted
1489
+	 * @return void
1490
+	 * @throws EE_Error
1491
+	 * @throws ReflectionException
1492
+	 */
1493
+	public function set_deleted($deleted)
1494
+	{
1495
+		$this->set('TKT_deleted', $deleted);
1496
+	}
1497
+
1498
+
1499
+	/**
1500
+	 * Gets parent
1501
+	 *
1502
+	 * @return int
1503
+	 * @throws EE_Error
1504
+	 * @throws ReflectionException
1505
+	 */
1506
+	public function parent_ID()
1507
+	{
1508
+		return $this->get('TKT_parent');
1509
+	}
1510
+
1511
+
1512
+	/**
1513
+	 * Sets parent
1514
+	 *
1515
+	 * @param int $parent
1516
+	 * @return void
1517
+	 * @throws EE_Error
1518
+	 * @throws ReflectionException
1519
+	 */
1520
+	public function set_parent_ID($parent)
1521
+	{
1522
+		$this->set('TKT_parent', $parent);
1523
+	}
1524
+
1525
+
1526
+	/**
1527
+	 * @return boolean
1528
+	 * @throws EE_Error
1529
+	 * @throws InvalidArgumentException
1530
+	 * @throws InvalidDataTypeException
1531
+	 * @throws InvalidInterfaceException
1532
+	 * @throws ReflectionException
1533
+	 */
1534
+	public function reverse_calculate()
1535
+	{
1536
+		return $this->get('TKT_reverse_calculate');
1537
+	}
1538
+
1539
+
1540
+	/**
1541
+	 * @param boolean $reverse_calculate
1542
+	 * @throws EE_Error
1543
+	 * @throws InvalidArgumentException
1544
+	 * @throws InvalidDataTypeException
1545
+	 * @throws InvalidInterfaceException
1546
+	 * @throws ReflectionException
1547
+	 */
1548
+	public function set_reverse_calculate($reverse_calculate)
1549
+	{
1550
+		$this->set('TKT_reverse_calculate', $reverse_calculate);
1551
+	}
1552
+
1553
+
1554
+	/**
1555
+	 * Gets a string which is handy for showing in gateways etc that describes the ticket.
1556
+	 *
1557
+	 * @return string
1558
+	 * @throws EE_Error
1559
+	 * @throws ReflectionException
1560
+	 */
1561
+	public function name_and_info()
1562
+	{
1563
+		$times = [];
1564
+		foreach ($this->datetimes() as $datetime) {
1565
+			$times[] = $datetime->start_date_and_time();
1566
+		}
1567
+		return $this->name() . ' @ ' . implode(', ', $times) . ' for ' . $this->pretty_price();
1568
+	}
1569
+
1570
+
1571
+	/**
1572
+	 * Gets name
1573
+	 *
1574
+	 * @return string
1575
+	 * @throws EE_Error
1576
+	 * @throws ReflectionException
1577
+	 */
1578
+	public function name()
1579
+	{
1580
+		return $this->get('TKT_name');
1581
+	}
1582
+
1583
+
1584
+	/**
1585
+	 * Gets price
1586
+	 *
1587
+	 * @return float
1588
+	 * @throws EE_Error
1589
+	 * @throws ReflectionException
1590
+	 */
1591
+	public function price()
1592
+	{
1593
+		return $this->get('TKT_price');
1594
+	}
1595
+
1596
+
1597
+	/**
1598
+	 * Gets all the registrations for this ticket
1599
+	 *
1600
+	 * @param array $query_params
1601
+	 * @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md
1602
+	 * @return EE_Registration[]|EE_Base_Class[]
1603
+	 * @throws EE_Error
1604
+	 * @throws ReflectionException
1605
+	 */
1606
+	public function registrations($query_params = [])
1607
+	{
1608
+		return $this->get_many_related('Registration', $query_params);
1609
+	}
1610
+
1611
+
1612
+	/**
1613
+	 * Updates the TKT_sold attribute (and saves) based on the number of APPROVED registrations for this ticket.
1614
+	 *
1615
+	 * @return int
1616
+	 * @throws EE_Error
1617
+	 * @throws ReflectionException
1618
+	 */
1619
+	public function update_tickets_sold()
1620
+	{
1621
+		$count_regs_for_this_ticket = $this->count_registrations(
1622
+			[
1623
+				[
1624
+					'STS_ID'      => EEM_Registration::status_id_approved,
1625
+					'REG_deleted' => 0,
1626
+				],
1627
+			]
1628
+		);
1629
+		$this->set_sold($count_regs_for_this_ticket);
1630
+		$this->save();
1631
+		return $count_regs_for_this_ticket;
1632
+	}
1633
+
1634
+
1635
+	/**
1636
+	 * Counts the registrations for this ticket
1637
+	 *
1638
+	 * @param array $query_params
1639
+	 * @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md
1640
+	 * @return int
1641
+	 * @throws EE_Error
1642
+	 * @throws ReflectionException
1643
+	 */
1644
+	public function count_registrations($query_params = [])
1645
+	{
1646
+		return $this->count_related('Registration', $query_params);
1647
+	}
1648
+
1649
+
1650
+	/**
1651
+	 * Implementation for EEI_Has_Icon interface method.
1652
+	 *
1653
+	 * @return string
1654
+	 * @see EEI_Visual_Representation for comments
1655
+	 */
1656
+	public function get_icon()
1657
+	{
1658
+		return '<span class="dashicons dashicons-tickets-alt"/>';
1659
+	}
1660
+
1661
+
1662
+	/**
1663
+	 * Implementation of the EEI_Event_Relation interface method
1664
+	 *
1665
+	 * @return EE_Event
1666
+	 * @throws EE_Error
1667
+	 * @throws UnexpectedEntityException
1668
+	 * @throws ReflectionException
1669
+	 * @see EEI_Event_Relation for comments
1670
+	 */
1671
+	public function get_related_event()
1672
+	{
1673
+		// get one datetime to use for getting the event
1674
+		$datetime = $this->first_datetime();
1675
+		if (! $datetime instanceof EE_Datetime) {
1676
+			throw new UnexpectedEntityException(
1677
+				$datetime,
1678
+				'EE_Datetime',
1679
+				sprintf(
1680
+					__('The ticket (%s) is not associated with any valid datetimes.', 'event_espresso'),
1681
+					$this->name()
1682
+				)
1683
+			);
1684
+		}
1685
+		$event = $datetime->event();
1686
+		if (! $event instanceof EE_Event) {
1687
+			throw new UnexpectedEntityException(
1688
+				$event,
1689
+				'EE_Event',
1690
+				sprintf(
1691
+					__('The ticket (%s) is not associated with a valid event.', 'event_espresso'),
1692
+					$this->name()
1693
+				)
1694
+			);
1695
+		}
1696
+		return $event;
1697
+	}
1698
+
1699
+
1700
+	/**
1701
+	 * Implementation of the EEI_Event_Relation interface method
1702
+	 *
1703
+	 * @return string
1704
+	 * @throws UnexpectedEntityException
1705
+	 * @throws EE_Error
1706
+	 * @throws ReflectionException
1707
+	 * @see EEI_Event_Relation for comments
1708
+	 */
1709
+	public function get_event_name()
1710
+	{
1711
+		$event = $this->get_related_event();
1712
+		return $event instanceof EE_Event ? $event->name() : '';
1713
+	}
1714
+
1715
+
1716
+	/**
1717
+	 * Implementation of the EEI_Event_Relation interface method
1718
+	 *
1719
+	 * @return int
1720
+	 * @throws UnexpectedEntityException
1721
+	 * @throws EE_Error
1722
+	 * @throws ReflectionException
1723
+	 * @see EEI_Event_Relation for comments
1724
+	 */
1725
+	public function get_event_ID()
1726
+	{
1727
+		$event = $this->get_related_event();
1728
+		return $event instanceof EE_Event ? $event->ID() : 0;
1729
+	}
1730
+
1731
+
1732
+	/**
1733
+	 * This simply returns whether a ticket can be permanently deleted or not.
1734
+	 * The criteria for determining this is whether the ticket has any related registrations.
1735
+	 * If there are none then it can be permanently deleted.
1736
+	 *
1737
+	 * @return bool
1738
+	 * @throws EE_Error
1739
+	 * @throws ReflectionException
1740
+	 */
1741
+	public function is_permanently_deleteable()
1742
+	{
1743
+		return $this->count_registrations() === 0;
1744
+	}
1745
+
1746
+
1747
+	/**
1748
+	 * @return int
1749
+	 * @throws EE_Error
1750
+	 * @throws ReflectionException
1751
+	 * @since   $VID:$
1752
+	 */
1753
+	public function visibility(): int
1754
+	{
1755
+		return $this->get('TKT_visibility');
1756
+	}
1757
+
1758
+
1759
+	/**
1760
+	 * @return int
1761
+	 * @throws EE_Error
1762
+	 * @throws ReflectionException
1763
+	 * @since   $VID:$
1764
+	 */
1765
+	public function isHidden(): int
1766
+	{
1767
+		return $this->visibility() === EEM_Ticket::TICKET_VISIBILITY_NONE_VALUE;
1768
+	}
1769
+
1770
+
1771
+	/**
1772
+	 * @return int
1773
+	 * @throws EE_Error
1774
+	 * @throws ReflectionException
1775
+	 * @since   $VID:$
1776
+	 */
1777
+	public function isNotHidden(): int
1778
+	{
1779
+		return $this->visibility() > EEM_Ticket::TICKET_VISIBILITY_NONE_VALUE;
1780
+	}
1781
+
1782
+
1783
+	/**
1784
+	 * @return int
1785
+	 * @throws EE_Error
1786
+	 * @throws ReflectionException
1787
+	 * @since   $VID:$
1788
+	 */
1789
+	public function isPublicOnly(): int
1790
+	{
1791
+		return $this->isNotHidden() && $this->visibility() <= EEM_Ticket::TICKET_VISIBILITY_PUBLIC_VALUE;
1792
+	}
1793
+
1794
+
1795
+	/**
1796
+	 * @return int
1797
+	 * @throws EE_Error
1798
+	 * @throws ReflectionException
1799
+	 * @since   $VID:$
1800
+	 */
1801
+	public function isMembersOnly(): int
1802
+	{
1803
+		return $this->visibility() > EEM_Ticket::TICKET_VISIBILITY_PUBLIC_VALUE
1804
+			   && $this->visibility() <= EEM_Ticket::TICKET_VISIBILITY_MEMBERS_ONLY_VALUE;
1805
+	}
1806
+
1807
+
1808
+	/**
1809
+	 * @return int
1810
+	 * @throws EE_Error
1811
+	 * @throws ReflectionException
1812
+	 * @since   $VID:$
1813
+	 */
1814
+	public function isAdminsOnly(): int
1815
+	{
1816
+		return $this->visibility() > EEM_Ticket::TICKET_VISIBILITY_MEMBERS_ONLY_VALUE
1817
+			   && $this->visibility() <= EEM_Ticket::TICKET_VISIBILITY_ADMINS_ONLY_VALUE;
1818
+	}
1819
+
1820
+
1821
+	/**
1822
+	 * @return int
1823
+	 * @throws EE_Error
1824
+	 * @throws ReflectionException
1825
+	 * @since   $VID:$
1826
+	 */
1827
+	public function isAdminUiOnly(): int
1828
+	{
1829
+		return $this->visibility() > EEM_Ticket::TICKET_VISIBILITY_ADMINS_ONLY_VALUE
1830
+			   && $this->visibility() <= EEM_Ticket::TICKET_VISIBILITY_ADMIN_UI_ONLY_VALUE;
1831
+	}
1832
+
1833
+
1834
+	/**
1835
+	 * @param int $visibility
1836
+	 * @throws EE_Error
1837
+	 * @throws ReflectionException
1838
+	 * @since   $VID:$
1839
+	 */
1840
+	public function set_visibility(int $visibility)
1841
+	{
1842
+
1843
+		$ticket_visibility_options = $this->_model->ticketVisibilityOptions();
1844
+		$ticket_visibility         = -1;
1845
+		foreach ($ticket_visibility_options as $ticket_visibility_option) {
1846
+			if ($visibility === $ticket_visibility_option) {
1847
+				$ticket_visibility = $visibility;
1848
+			}
1849
+		}
1850
+		if ($ticket_visibility === -1) {
1851
+			throw new DomainException(
1852
+				sprintf(
1853
+					esc_html__(
1854
+						'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 ',
1855
+						'event_espresso'
1856
+					),
1857
+					$visibility,
1858
+					'<br />',
1859
+					var_export($ticket_visibility_options, true)
1860
+				)
1861
+			);
1862
+		}
1863
+		$this->set('TKT_visibility', $ticket_visibility);
1864
+	}
1865
+
1866
+
1867
+	/**
1868
+	 * @param EE_Base_Class|int|string $otherObjectModelObjectOrID
1869
+	 * @param string                   $relationName
1870
+	 * @param array                    $extra_join_model_fields_n_values
1871
+	 * @param string|null              $cache_id
1872
+	 * @return EE_Base_Class
1873
+	 * @throws EE_Error
1874
+	 * @throws ReflectionException
1875
+	 * @since   $VID:$
1876
+	 */
1877
+	public function _add_relation_to(
1878
+		$otherObjectModelObjectOrID,
1879
+		$relationName,
1880
+		$extra_join_model_fields_n_values = [],
1881
+		$cache_id = null
1882
+	) {
1883
+		if ($relationName === 'Datetime' && ! $this->hasRelation($otherObjectModelObjectOrID, $relationName)) {
1884
+			/** @var EE_Datetime $datetime */
1885
+			$datetime = EEM_Datetime::instance()->ensure_is_obj($otherObjectModelObjectOrID);
1886
+			$datetime->increaseSold($this->sold(), false);
1887
+			$datetime->increaseReserved($this->reserved());
1888
+			$datetime->save();
1889
+			$otherObjectModelObjectOrID = $datetime;
1890
+		}
1891
+		return parent::_add_relation_to(
1892
+			$otherObjectModelObjectOrID,
1893
+			$relationName,
1894
+			$extra_join_model_fields_n_values,
1895
+			$cache_id
1896
+		);
1897
+	}
1898
+
1899
+
1900
+	/**
1901
+	 * @param EE_Base_Class|int|string $otherObjectModelObjectOrID
1902
+	 * @param string                   $relationName
1903
+	 * @param array                    $where_query
1904
+	 * @return bool|EE_Base_Class|null
1905
+	 * @throws EE_Error
1906
+	 * @throws ReflectionException
1907
+	 * @since   $VID:$
1908
+	 */
1909
+	public function _remove_relation_to($otherObjectModelObjectOrID, $relationName, $where_query = [])
1910
+	{
1911
+		// if we're adding a new relation to a datetime
1912
+		if ($relationName === 'Datetime' && $this->hasRelation($otherObjectModelObjectOrID, $relationName)) {
1913
+			/** @var EE_Datetime $datetime */
1914
+			$datetime = EEM_Datetime::instance()->ensure_is_obj($otherObjectModelObjectOrID);
1915
+			$datetime->decreaseSold($this->sold());
1916
+			$datetime->decreaseReserved($this->reserved());
1917
+			$datetime->save();
1918
+			$otherObjectModelObjectOrID = $datetime;
1919
+		}
1920
+		return parent::_remove_relation_to(
1921
+			$otherObjectModelObjectOrID,
1922
+			$relationName,
1923
+			$where_query
1924
+		);
1925
+	}
1926
+
1927
+
1928
+	/**
1929
+	 * Removes ALL the related things for the $relationName.
1930
+	 *
1931
+	 * @param string $relationName
1932
+	 * @param array  $where_query_params
1933
+	 * @return EE_Base_Class
1934
+	 * @throws ReflectionException
1935
+	 * @throws InvalidArgumentException
1936
+	 * @throws InvalidInterfaceException
1937
+	 * @throws InvalidDataTypeException
1938
+	 * @throws EE_Error
1939
+	 * @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md#0-where-conditions
1940
+	 */
1941
+	public function _remove_relations($relationName, $where_query_params = [])
1942
+	{
1943
+		if ($relationName === 'Datetime') {
1944
+			$datetimes = $this->datetimes();
1945
+			foreach ($datetimes as $datetime) {
1946
+				$datetime->decreaseSold($this->sold());
1947
+				$datetime->decreaseReserved($this->reserved());
1948
+				$datetime->save();
1949
+			}
1950
+		}
1951
+		return parent::_remove_relations($relationName, $where_query_params);
1952
+	}
1953
+
1954
+
1955
+	/*******************************************************************
1956 1956
      ***********************  DEPRECATED METHODS  **********************
1957 1957
      *******************************************************************/
1958 1958
 
1959 1959
 
1960
-    /**
1961
-     * Increments sold by amount passed by $qty AND decrements the reserved count on both this ticket and its
1962
-     * associated datetimes.
1963
-     *
1964
-     * @param int $qty
1965
-     * @return void
1966
-     * @throws EE_Error
1967
-     * @throws InvalidArgumentException
1968
-     * @throws InvalidDataTypeException
1969
-     * @throws InvalidInterfaceException
1970
-     * @throws ReflectionException
1971
-     * @deprecated 4.9.80.p
1972
-     */
1973
-    public function increase_sold($qty = 1)
1974
-    {
1975
-        EE_Error::doing_it_wrong(
1976
-            __FUNCTION__,
1977
-            esc_html__('Please use EE_Ticket::increaseSold() instead', 'event_espresso'),
1978
-            '4.9.80.p',
1979
-            '5.0.0.p'
1980
-        );
1981
-        $this->increaseSold($qty);
1982
-    }
1983
-
1984
-
1985
-    /**
1986
-     * On each datetime related to this ticket, increases its sold count and decreases its reserved count by $qty.
1987
-     *
1988
-     * @param int $qty positive or negative. Positive means to increase sold counts (and decrease reserved counts),
1989
-     *                 Negative means to decreases old counts (and increase reserved counts).
1990
-     * @throws EE_Error
1991
-     * @throws InvalidArgumentException
1992
-     * @throws InvalidDataTypeException
1993
-     * @throws InvalidInterfaceException
1994
-     * @throws ReflectionException
1995
-     * @deprecated 4.9.80.p
1996
-     */
1997
-    protected function _increase_sold_for_datetimes($qty)
1998
-    {
1999
-        EE_Error::doing_it_wrong(
2000
-            __FUNCTION__,
2001
-            esc_html__('Please use EE_Ticket::increaseSoldForDatetimes() instead', 'event_espresso'),
2002
-            '4.9.80.p',
2003
-            '5.0.0.p'
2004
-        );
2005
-        $this->increaseSoldForDatetimes($qty);
2006
-    }
2007
-
2008
-
2009
-    /**
2010
-     * Decrements (subtracts) sold by amount passed by $qty on both the ticket and its related datetimes directly in the
2011
-     * DB and then updates the model objects.
2012
-     * Does not affect the reserved counts.
2013
-     *
2014
-     * @param int $qty
2015
-     * @return void
2016
-     * @throws EE_Error
2017
-     * @throws InvalidArgumentException
2018
-     * @throws InvalidDataTypeException
2019
-     * @throws InvalidInterfaceException
2020
-     * @throws ReflectionException
2021
-     * @deprecated 4.9.80.p
2022
-     */
2023
-    public function decrease_sold($qty = 1)
2024
-    {
2025
-        EE_Error::doing_it_wrong(
2026
-            __FUNCTION__,
2027
-            esc_html__('Please use EE_Ticket::decreaseSold() instead', 'event_espresso'),
2028
-            '4.9.80.p',
2029
-            '5.0.0.p'
2030
-        );
2031
-        $this->decreaseSold($qty);
2032
-    }
2033
-
2034
-
2035
-    /**
2036
-     * Decreases sold on related datetimes
2037
-     *
2038
-     * @param int $qty
2039
-     * @return void
2040
-     * @throws EE_Error
2041
-     * @throws InvalidArgumentException
2042
-     * @throws InvalidDataTypeException
2043
-     * @throws InvalidInterfaceException
2044
-     * @throws ReflectionException
2045
-     * @deprecated 4.9.80.p
2046
-     */
2047
-    protected function _decrease_sold_for_datetimes($qty = 1)
2048
-    {
2049
-        EE_Error::doing_it_wrong(
2050
-            __FUNCTION__,
2051
-            esc_html__('Please use EE_Ticket::decreaseSoldForDatetimes() instead', 'event_espresso'),
2052
-            '4.9.80.p',
2053
-            '5.0.0.p'
2054
-        );
2055
-        $this->decreaseSoldForDatetimes($qty);
2056
-    }
2057
-
2058
-
2059
-    /**
2060
-     * Increments reserved by amount passed by $qty, and persists it immediately to the database.
2061
-     *
2062
-     * @param int    $qty
2063
-     * @param string $source
2064
-     * @return bool whether we successfully reserved the ticket or not.
2065
-     * @throws EE_Error
2066
-     * @throws InvalidArgumentException
2067
-     * @throws ReflectionException
2068
-     * @throws InvalidDataTypeException
2069
-     * @throws InvalidInterfaceException
2070
-     * @deprecated 4.9.80.p
2071
-     */
2072
-    public function increase_reserved($qty = 1, $source = 'unknown')
2073
-    {
2074
-        EE_Error::doing_it_wrong(
2075
-            __FUNCTION__,
2076
-            esc_html__('Please use EE_Ticket::increaseReserved() instead', 'event_espresso'),
2077
-            '4.9.80.p',
2078
-            '5.0.0.p'
2079
-        );
2080
-        return $this->increaseReserved($qty);
2081
-    }
2082
-
2083
-
2084
-    /**
2085
-     * Increases sold on related datetimes
2086
-     *
2087
-     * @param int $qty
2088
-     * @return boolean indicating success
2089
-     * @throws EE_Error
2090
-     * @throws InvalidArgumentException
2091
-     * @throws InvalidDataTypeException
2092
-     * @throws InvalidInterfaceException
2093
-     * @throws ReflectionException
2094
-     * @deprecated 4.9.80.p
2095
-     */
2096
-    protected function _increase_reserved_for_datetimes($qty = 1)
2097
-    {
2098
-        EE_Error::doing_it_wrong(
2099
-            __FUNCTION__,
2100
-            esc_html__('Please use EE_Ticket::increaseReservedForDatetimes() instead', 'event_espresso'),
2101
-            '4.9.80.p',
2102
-            '5.0.0.p'
2103
-        );
2104
-        return $this->increaseReservedForDatetimes($qty);
2105
-    }
2106
-
2107
-
2108
-    /**
2109
-     * Decrements (subtracts) reserved by amount passed by $qty, and persists it immediately to the database.
2110
-     *
2111
-     * @param int    $qty
2112
-     * @param bool   $adjust_datetimes
2113
-     * @param string $source
2114
-     * @return void
2115
-     * @throws EE_Error
2116
-     * @throws InvalidArgumentException
2117
-     * @throws ReflectionException
2118
-     * @throws InvalidDataTypeException
2119
-     * @throws InvalidInterfaceException
2120
-     * @deprecated 4.9.80.p
2121
-     */
2122
-    public function decrease_reserved($qty = 1, $adjust_datetimes = true, $source = 'unknown')
2123
-    {
2124
-        EE_Error::doing_it_wrong(
2125
-            __FUNCTION__,
2126
-            esc_html__('Please use EE_Ticket::decreaseReserved() instead', 'event_espresso'),
2127
-            '4.9.80.p',
2128
-            '5.0.0.p'
2129
-        );
2130
-        $this->decreaseReserved($qty);
2131
-    }
2132
-
2133
-
2134
-    /**
2135
-     * Decreases reserved on related datetimes
2136
-     *
2137
-     * @param int $qty
2138
-     * @return void
2139
-     * @throws EE_Error
2140
-     * @throws InvalidArgumentException
2141
-     * @throws ReflectionException
2142
-     * @throws InvalidDataTypeException
2143
-     * @throws InvalidInterfaceException
2144
-     * @deprecated 4.9.80.p
2145
-     */
2146
-    protected function _decrease_reserved_for_datetimes($qty = 1)
2147
-    {
2148
-        EE_Error::doing_it_wrong(
2149
-            __FUNCTION__,
2150
-            esc_html__('Please use EE_Ticket::decreaseReservedForDatetimes() instead', 'event_espresso'),
2151
-            '4.9.80.p',
2152
-            '5.0.0.p'
2153
-        );
2154
-        $this->decreaseReservedForDatetimes($qty);
2155
-    }
1960
+	/**
1961
+	 * Increments sold by amount passed by $qty AND decrements the reserved count on both this ticket and its
1962
+	 * associated datetimes.
1963
+	 *
1964
+	 * @param int $qty
1965
+	 * @return void
1966
+	 * @throws EE_Error
1967
+	 * @throws InvalidArgumentException
1968
+	 * @throws InvalidDataTypeException
1969
+	 * @throws InvalidInterfaceException
1970
+	 * @throws ReflectionException
1971
+	 * @deprecated 4.9.80.p
1972
+	 */
1973
+	public function increase_sold($qty = 1)
1974
+	{
1975
+		EE_Error::doing_it_wrong(
1976
+			__FUNCTION__,
1977
+			esc_html__('Please use EE_Ticket::increaseSold() instead', 'event_espresso'),
1978
+			'4.9.80.p',
1979
+			'5.0.0.p'
1980
+		);
1981
+		$this->increaseSold($qty);
1982
+	}
1983
+
1984
+
1985
+	/**
1986
+	 * On each datetime related to this ticket, increases its sold count and decreases its reserved count by $qty.
1987
+	 *
1988
+	 * @param int $qty positive or negative. Positive means to increase sold counts (and decrease reserved counts),
1989
+	 *                 Negative means to decreases old counts (and increase reserved counts).
1990
+	 * @throws EE_Error
1991
+	 * @throws InvalidArgumentException
1992
+	 * @throws InvalidDataTypeException
1993
+	 * @throws InvalidInterfaceException
1994
+	 * @throws ReflectionException
1995
+	 * @deprecated 4.9.80.p
1996
+	 */
1997
+	protected function _increase_sold_for_datetimes($qty)
1998
+	{
1999
+		EE_Error::doing_it_wrong(
2000
+			__FUNCTION__,
2001
+			esc_html__('Please use EE_Ticket::increaseSoldForDatetimes() instead', 'event_espresso'),
2002
+			'4.9.80.p',
2003
+			'5.0.0.p'
2004
+		);
2005
+		$this->increaseSoldForDatetimes($qty);
2006
+	}
2007
+
2008
+
2009
+	/**
2010
+	 * Decrements (subtracts) sold by amount passed by $qty on both the ticket and its related datetimes directly in the
2011
+	 * DB and then updates the model objects.
2012
+	 * Does not affect the reserved counts.
2013
+	 *
2014
+	 * @param int $qty
2015
+	 * @return void
2016
+	 * @throws EE_Error
2017
+	 * @throws InvalidArgumentException
2018
+	 * @throws InvalidDataTypeException
2019
+	 * @throws InvalidInterfaceException
2020
+	 * @throws ReflectionException
2021
+	 * @deprecated 4.9.80.p
2022
+	 */
2023
+	public function decrease_sold($qty = 1)
2024
+	{
2025
+		EE_Error::doing_it_wrong(
2026
+			__FUNCTION__,
2027
+			esc_html__('Please use EE_Ticket::decreaseSold() instead', 'event_espresso'),
2028
+			'4.9.80.p',
2029
+			'5.0.0.p'
2030
+		);
2031
+		$this->decreaseSold($qty);
2032
+	}
2033
+
2034
+
2035
+	/**
2036
+	 * Decreases sold on related datetimes
2037
+	 *
2038
+	 * @param int $qty
2039
+	 * @return void
2040
+	 * @throws EE_Error
2041
+	 * @throws InvalidArgumentException
2042
+	 * @throws InvalidDataTypeException
2043
+	 * @throws InvalidInterfaceException
2044
+	 * @throws ReflectionException
2045
+	 * @deprecated 4.9.80.p
2046
+	 */
2047
+	protected function _decrease_sold_for_datetimes($qty = 1)
2048
+	{
2049
+		EE_Error::doing_it_wrong(
2050
+			__FUNCTION__,
2051
+			esc_html__('Please use EE_Ticket::decreaseSoldForDatetimes() instead', 'event_espresso'),
2052
+			'4.9.80.p',
2053
+			'5.0.0.p'
2054
+		);
2055
+		$this->decreaseSoldForDatetimes($qty);
2056
+	}
2057
+
2058
+
2059
+	/**
2060
+	 * Increments reserved by amount passed by $qty, and persists it immediately to the database.
2061
+	 *
2062
+	 * @param int    $qty
2063
+	 * @param string $source
2064
+	 * @return bool whether we successfully reserved the ticket or not.
2065
+	 * @throws EE_Error
2066
+	 * @throws InvalidArgumentException
2067
+	 * @throws ReflectionException
2068
+	 * @throws InvalidDataTypeException
2069
+	 * @throws InvalidInterfaceException
2070
+	 * @deprecated 4.9.80.p
2071
+	 */
2072
+	public function increase_reserved($qty = 1, $source = 'unknown')
2073
+	{
2074
+		EE_Error::doing_it_wrong(
2075
+			__FUNCTION__,
2076
+			esc_html__('Please use EE_Ticket::increaseReserved() instead', 'event_espresso'),
2077
+			'4.9.80.p',
2078
+			'5.0.0.p'
2079
+		);
2080
+		return $this->increaseReserved($qty);
2081
+	}
2082
+
2083
+
2084
+	/**
2085
+	 * Increases sold on related datetimes
2086
+	 *
2087
+	 * @param int $qty
2088
+	 * @return boolean indicating success
2089
+	 * @throws EE_Error
2090
+	 * @throws InvalidArgumentException
2091
+	 * @throws InvalidDataTypeException
2092
+	 * @throws InvalidInterfaceException
2093
+	 * @throws ReflectionException
2094
+	 * @deprecated 4.9.80.p
2095
+	 */
2096
+	protected function _increase_reserved_for_datetimes($qty = 1)
2097
+	{
2098
+		EE_Error::doing_it_wrong(
2099
+			__FUNCTION__,
2100
+			esc_html__('Please use EE_Ticket::increaseReservedForDatetimes() instead', 'event_espresso'),
2101
+			'4.9.80.p',
2102
+			'5.0.0.p'
2103
+		);
2104
+		return $this->increaseReservedForDatetimes($qty);
2105
+	}
2106
+
2107
+
2108
+	/**
2109
+	 * Decrements (subtracts) reserved by amount passed by $qty, and persists it immediately to the database.
2110
+	 *
2111
+	 * @param int    $qty
2112
+	 * @param bool   $adjust_datetimes
2113
+	 * @param string $source
2114
+	 * @return void
2115
+	 * @throws EE_Error
2116
+	 * @throws InvalidArgumentException
2117
+	 * @throws ReflectionException
2118
+	 * @throws InvalidDataTypeException
2119
+	 * @throws InvalidInterfaceException
2120
+	 * @deprecated 4.9.80.p
2121
+	 */
2122
+	public function decrease_reserved($qty = 1, $adjust_datetimes = true, $source = 'unknown')
2123
+	{
2124
+		EE_Error::doing_it_wrong(
2125
+			__FUNCTION__,
2126
+			esc_html__('Please use EE_Ticket::decreaseReserved() instead', 'event_espresso'),
2127
+			'4.9.80.p',
2128
+			'5.0.0.p'
2129
+		);
2130
+		$this->decreaseReserved($qty);
2131
+	}
2132
+
2133
+
2134
+	/**
2135
+	 * Decreases reserved on related datetimes
2136
+	 *
2137
+	 * @param int $qty
2138
+	 * @return void
2139
+	 * @throws EE_Error
2140
+	 * @throws InvalidArgumentException
2141
+	 * @throws ReflectionException
2142
+	 * @throws InvalidDataTypeException
2143
+	 * @throws InvalidInterfaceException
2144
+	 * @deprecated 4.9.80.p
2145
+	 */
2146
+	protected function _decrease_reserved_for_datetimes($qty = 1)
2147
+	{
2148
+		EE_Error::doing_it_wrong(
2149
+			__FUNCTION__,
2150
+			esc_html__('Please use EE_Ticket::decreaseReservedForDatetimes() instead', 'event_espresso'),
2151
+			'4.9.80.p',
2152
+			'5.0.0.p'
2153
+		);
2154
+		$this->decreaseReservedForDatetimes($qty);
2155
+	}
2156 2156
 }
Please login to merge, or discard this patch.