1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace EventEspresso\modules\ticket_selector; |
4
|
|
|
|
5
|
|
|
use EE_Error; |
6
|
|
|
use EE_Tax_Config; |
7
|
|
|
use EEH_HTML; |
8
|
|
|
use EventEspresso\core\exceptions\UnexpectedEntityException; |
9
|
|
|
|
10
|
|
|
/** |
11
|
|
|
* Class TicketSelectorRowStandard |
12
|
|
|
* class for loading template and resolving template args for a single ticket row within a standard ticket selector |
13
|
|
|
* |
14
|
|
|
* @package Event Espresso |
15
|
|
|
* @author Brent Christensen |
16
|
|
|
*/ |
17
|
|
|
class TicketSelectorRowStandard extends TicketSelectorRow |
18
|
|
|
{ |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* @var TicketDetails $ticket_details |
22
|
|
|
*/ |
23
|
|
|
protected $ticket_details; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* @var \EE_Ticket_Selector_Config $template_settings |
27
|
|
|
*/ |
28
|
|
|
protected $template_settings; |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* @var EE_Tax_Config $tax_settings |
32
|
|
|
*/ |
33
|
|
|
protected $tax_settings; |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* @var boolean $prices_displayed_including_taxes |
37
|
|
|
*/ |
38
|
|
|
protected $prices_displayed_including_taxes; |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* @var int $row |
42
|
|
|
*/ |
43
|
|
|
protected $row; |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* @var int $cols |
47
|
|
|
*/ |
48
|
|
|
protected $cols; |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* @var boolean $hidden_input_qty |
52
|
|
|
*/ |
53
|
|
|
protected $hidden_input_qty; |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* @var string $ticket_datetime_classes |
57
|
|
|
*/ |
58
|
|
|
protected $ticket_datetime_classes; |
59
|
|
|
|
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* TicketDetails constructor. |
63
|
|
|
* |
64
|
|
|
* @param TicketDetails $ticket_details |
65
|
|
|
* @param EE_Tax_Config $tax_settings |
66
|
|
|
* @param int $total_tickets |
67
|
|
|
* @param int $max_attendees |
68
|
|
|
* @param int $row |
69
|
|
|
* @param int $cols |
70
|
|
|
* @param boolean $required_ticket_sold_out |
71
|
|
|
* @param string $event_status |
72
|
|
|
* @param string $ticket_datetime_classes |
73
|
|
|
* @throws EE_Error |
74
|
|
|
* @throws UnexpectedEntityException |
75
|
|
|
*/ |
76
|
|
|
public function __construct( |
77
|
|
|
TicketDetails $ticket_details, |
78
|
|
|
EE_Tax_Config $tax_settings, |
79
|
|
|
$total_tickets, |
80
|
|
|
$max_attendees, |
81
|
|
|
$row, |
82
|
|
|
$cols, |
83
|
|
|
$required_ticket_sold_out, |
84
|
|
|
$event_status, |
85
|
|
|
$ticket_datetime_classes |
86
|
|
|
) { |
87
|
|
|
$this->ticket_details = $ticket_details; |
88
|
|
|
$this->template_settings = $ticket_details->getTemplateSettings(); |
89
|
|
|
$this->tax_settings = $tax_settings; |
90
|
|
|
$this->row = $row; |
91
|
|
|
$this->cols = $cols; |
92
|
|
|
$this->ticket_datetime_classes = $ticket_datetime_classes; |
93
|
|
|
parent::__construct( |
94
|
|
|
$ticket_details->getTicket(), |
95
|
|
|
$max_attendees, |
96
|
|
|
$ticket_details->getDateFormat(), |
97
|
|
|
$event_status, |
98
|
|
|
$required_ticket_sold_out, |
99
|
|
|
$total_tickets |
100
|
|
|
); |
101
|
|
|
} |
102
|
|
|
|
103
|
|
|
|
104
|
|
|
/** |
105
|
|
|
* other ticket rows will need to know if a required ticket is sold out, |
106
|
|
|
* so that they are not offered for sale |
107
|
|
|
* |
108
|
|
|
* @return boolean |
109
|
|
|
*/ |
110
|
|
|
public function getRequiredTicketSoldOut() |
111
|
|
|
{ |
112
|
|
|
return $this->required_ticket_sold_out; |
113
|
|
|
} |
114
|
|
|
|
115
|
|
|
|
116
|
|
|
/** |
117
|
|
|
* @return int |
118
|
|
|
*/ |
119
|
|
|
public function getCols() |
120
|
|
|
{ |
121
|
|
|
return $this->cols; |
122
|
|
|
} |
123
|
|
|
|
124
|
|
|
|
125
|
|
|
/** |
126
|
|
|
* getHtml |
127
|
|
|
* |
128
|
|
|
* @return string |
129
|
|
|
* @throws EE_Error |
130
|
|
|
*/ |
131
|
|
|
public function getHtml() |
132
|
|
|
{ |
133
|
|
|
$this->min = 0; |
134
|
|
|
$this->max = $this->ticket->max(); |
135
|
|
|
$remaining = $this->ticket->remaining(); |
136
|
|
|
if ($this->ticket->is_on_sale() && $this->ticket->is_remaining()) { |
137
|
|
|
$this->setTicketMinAndMax($remaining); |
138
|
|
|
} else { |
139
|
|
|
// set flag if ticket is required (flag is set to start date so that future tickets are not blocked) |
140
|
|
|
$this->required_ticket_sold_out = $this->ticket->required() && ! $remaining |
141
|
|
|
? $this->ticket->start_date() |
142
|
|
|
: $this->required_ticket_sold_out; |
143
|
|
|
} |
144
|
|
|
$this->setTicketPriceDetails(); |
145
|
|
|
$this->setTicketStatusClasses($remaining); |
146
|
|
|
$filtered_row_html = $this->getFilteredRowHtml(); |
147
|
|
|
if ($filtered_row_html !== false) { |
148
|
|
|
return $filtered_row_html; |
149
|
|
|
} |
150
|
|
|
$ticket_selector_row_html = EEH_HTML::tr( |
151
|
|
|
'', |
152
|
|
|
'', |
153
|
|
|
"tckt-slctr-tbl-tr {$this->status_class}{$this->ticket_datetime_classes} " |
154
|
|
|
. espresso_get_object_css_class($this->ticket) |
155
|
|
|
); |
156
|
|
|
$filtered_row_content = $this->getFilteredRowContents(); |
157
|
|
|
if ($filtered_row_content !== false && $this->max_attendees === 1) { |
158
|
|
|
return $ticket_selector_row_html |
159
|
|
|
. $filtered_row_content |
160
|
|
|
. $this->ticketQtyAndIdHiddenInputs() |
161
|
|
|
. EEH_HTML::trx(); |
162
|
|
|
} |
163
|
|
|
if ($filtered_row_content !== false) { |
164
|
|
|
return $ticket_selector_row_html |
165
|
|
|
. $filtered_row_content |
166
|
|
|
. EEH_HTML::trx(); |
167
|
|
|
} |
168
|
|
|
$this->hidden_input_qty = $this->max_attendees > 1; |
169
|
|
|
|
170
|
|
|
$ticket_selector_row_html .= $this->ticketNameTableCell(); |
171
|
|
|
$ticket_selector_row_html .= $this->ticketPriceTableCell(); |
172
|
|
|
$ticket_selector_row_html .= EEH_HTML::td( |
173
|
|
|
'', |
174
|
|
|
'', |
175
|
|
|
'tckt-slctr-tbl-td-qty cntr', |
176
|
|
|
'', |
177
|
|
|
'headers="quantity-' . $this->EVT_ID . '"' |
178
|
|
|
); |
179
|
|
|
$this->setTicketStatusDisplay($remaining); |
180
|
|
|
if (empty($this->ticket_status_display)) { |
181
|
|
|
if ($this->max_attendees === 1) { |
182
|
|
|
// only ONE attendee is allowed to register at a time |
183
|
|
|
$ticket_selector_row_html .= $this->onlyOneAttendeeCanRegister(); |
184
|
|
|
} elseif ($this->max > 0) { |
185
|
|
|
$ticket_selector_row_html .= $this->ticketQuantitySelector(); |
186
|
|
|
} |
187
|
|
|
} |
188
|
|
|
$ticket_selector_row_html .= $this->ticket_status_display; |
189
|
|
|
$ticket_selector_row_html .= $this->ticketQtyAndIdHiddenInputs(); |
190
|
|
|
$ticket_selector_row_html .= $this->ticket_details->display( |
191
|
|
|
$this->ticket_price, |
192
|
|
|
$remaining, |
193
|
|
|
$this->cols |
194
|
|
|
); |
195
|
|
|
$ticket_selector_row_html .= EEH_HTML::tdx(); |
196
|
|
|
$ticket_selector_row_html .= EEH_HTML::trx(); |
197
|
|
|
|
198
|
|
|
|
199
|
|
|
$this->row++; |
200
|
|
|
return $ticket_selector_row_html; |
201
|
|
|
} |
202
|
|
|
|
203
|
|
|
|
204
|
|
|
/** |
205
|
|
|
* getTicketPriceDetails |
206
|
|
|
* |
207
|
|
|
* @return void |
208
|
|
|
* @throws EE_Error |
209
|
|
|
*/ |
210
|
|
|
protected function setTicketPriceDetails() |
211
|
|
|
{ |
212
|
|
|
$this->ticket_price = $this->tax_settings->prices_displayed_including_taxes |
213
|
|
|
? $this->ticket->get_ticket_total_with_taxes() |
214
|
|
|
: $this->ticket->get_ticket_subtotal(); |
215
|
|
|
$this->ticket_bundle = false; |
216
|
|
|
$ticket_min = $this->ticket->min(); |
217
|
|
|
// for ticket bundles, set min and max qty the same |
218
|
|
|
if ($ticket_min !== 0 && $ticket_min === $this->ticket->max()) { |
219
|
|
|
$this->ticket_price *= $ticket_min; |
220
|
|
|
$this->ticket_bundle = true; |
221
|
|
|
} |
222
|
|
|
$this->ticket_price = apply_filters( |
223
|
|
|
'FHEE__ticket_selector_chart_template__ticket_price', |
224
|
|
|
$this->ticket_price, |
225
|
|
|
$this->ticket |
226
|
|
|
); |
227
|
|
|
} |
228
|
|
|
|
229
|
|
|
|
230
|
|
|
/** |
231
|
|
|
* ticketNameTableCell |
232
|
|
|
* |
233
|
|
|
* @return string |
234
|
|
|
* @throws EE_Error |
235
|
|
|
*/ |
236
|
|
|
protected function ticketNameTableCell() |
237
|
|
|
{ |
238
|
|
|
$html = EEH_HTML::td( |
239
|
|
|
'', |
240
|
|
|
'', |
241
|
|
|
'tckt-slctr-tbl-td-name', |
242
|
|
|
'', |
243
|
|
|
'headers="details-' . $this->EVT_ID . '"' |
244
|
|
|
); |
245
|
|
|
$html .= EEH_HTML::strong($this->ticket->get_pretty('TKT_name')); |
246
|
|
|
$html .= $this->ticket_details->getShowHideLinks(); |
247
|
|
|
if ($this->ticket->required()) { |
248
|
|
|
$html .= EEH_HTML::p( |
249
|
|
|
apply_filters( |
250
|
|
|
'FHEE__ticket_selector_chart_template__ticket_required_message', |
251
|
|
|
esc_html__('This ticket is required and must be purchased.', 'event_espresso') |
252
|
|
|
), |
253
|
|
|
'', |
254
|
|
|
'ticket-required-pg' |
255
|
|
|
); |
256
|
|
|
} |
257
|
|
|
$html .= EEH_HTML::tdx(); |
258
|
|
|
return $html; |
259
|
|
|
} |
260
|
|
|
|
261
|
|
|
|
262
|
|
|
/** |
263
|
|
|
* ticketPriceTableCell |
264
|
|
|
* |
265
|
|
|
* @return string |
266
|
|
|
* @throws EE_Error |
267
|
|
|
*/ |
268
|
|
|
protected function ticketPriceTableCell() |
269
|
|
|
{ |
270
|
|
|
$html = ''; |
271
|
|
|
if (apply_filters('FHEE__ticket_selector_chart_template__display_ticket_price_details', true)) { |
272
|
|
|
$html .= EEH_HTML::td( |
273
|
|
|
'', |
274
|
|
|
'', |
275
|
|
|
'tckt-slctr-tbl-td-price jst-rght', |
276
|
|
|
'', |
277
|
|
|
'headers="price-' . $this->EVT_ID . '"' |
278
|
|
|
); |
279
|
|
|
$html .= \EEH_Template::format_currency($this->ticket_price); |
280
|
|
|
$html .= $this->ticket->taxable() |
281
|
|
|
? EEH_HTML::span('*', '', 'taxable-tickets-asterisk grey-text') |
282
|
|
|
: ''; |
283
|
|
|
$html .= ' '; |
284
|
|
|
// phpcs:disable WordPress.WP.I18n.NoEmptyStrings |
285
|
|
|
$html .= EEH_HTML::span( |
286
|
|
|
$this->ticket_bundle |
287
|
|
|
? apply_filters( |
288
|
|
|
'FHEE__ticket_selector_chart_template__per_ticket_bundle_text', |
289
|
|
|
__(' / bundle', 'event_espresso') |
290
|
|
|
) |
291
|
|
|
: apply_filters( |
292
|
|
|
'FHEE__ticket_selector_chart_template__per_ticket_text', |
293
|
|
|
__('', 'event_espresso') |
294
|
|
|
), |
295
|
|
|
'', |
296
|
|
|
'smaller-text no-bold' |
297
|
|
|
); |
298
|
|
|
$html .= ' '; |
299
|
|
|
$html .= EEH_HTML::tdx(); |
300
|
|
|
$this->cols++; |
301
|
|
|
} |
302
|
|
|
return $html; |
303
|
|
|
} |
304
|
|
|
|
305
|
|
|
|
306
|
|
|
/** |
307
|
|
|
* onlyOneAttendeeCanRegister |
308
|
|
|
* |
309
|
|
|
* @return string |
310
|
|
|
*/ |
311
|
|
|
protected function onlyOneAttendeeCanRegister() |
312
|
|
|
{ |
313
|
|
|
// display submit button since we have tickets available |
314
|
|
|
add_filter('FHEE__EE_Ticket_Selector__display_ticket_selector_submit', '__return_true'); |
315
|
|
|
$this->hidden_input_qty = false; |
316
|
|
|
$id = 'ticket-selector-tbl-qty-slct-' . $this->EVT_ID . '-' . $this->row; |
317
|
|
|
$html = '<label class="ee-a11y-screen-reader-text" for="' . $id . '">'; |
318
|
|
|
$html .= esc_html__('Select this ticket', 'event_espresso') . '</label>'; |
319
|
|
|
$html .= '<input type="radio" name="tkt-slctr-qty-' . $this->EVT_ID . '"'; |
320
|
|
|
$html .= ' id="' . $id . '"'; |
321
|
|
|
$html .= ' class="ticket-selector-tbl-qty-slct" value="' . $this->row . '-1"'; |
322
|
|
|
$html .= $this->total_tickets === 1 ? ' checked="checked"' : ''; |
323
|
|
|
$html .= ' title=""/>'; |
324
|
|
|
return $html; |
325
|
|
|
} |
326
|
|
|
|
327
|
|
|
|
328
|
|
|
/** |
329
|
|
|
* ticketQuantitySelector |
330
|
|
|
* |
331
|
|
|
* @return string |
332
|
|
|
* @throws EE_Error |
333
|
|
|
*/ |
334
|
|
|
protected function ticketQuantitySelector() |
335
|
|
|
{ |
336
|
|
|
// display submit button since we have tickets available |
337
|
|
|
add_filter('FHEE__EE_Ticket_Selector__display_ticket_selector_submit', '__return_true'); |
338
|
|
|
$this->hidden_input_qty = false; |
339
|
|
|
$id = 'ticket-selector-tbl-qty-slct-' . $this->EVT_ID . '-' . $this->row; |
340
|
|
|
$html = '<label class="ee-a11y-screen-reader-text" for="' . $id . '">'; |
341
|
|
|
$html .= esc_html__('Quantity', 'event_espresso') . '</label>'; |
342
|
|
|
$html .= '<select name="tkt-slctr-qty-' . $this->EVT_ID . '[]"'; |
343
|
|
|
$html .= ' id="' . $id . '"'; |
344
|
|
|
$html .= ' class="ticket-selector-tbl-qty-slct">'; |
345
|
|
|
// this ensures that non-required tickets with non-zero MIN QTYs don't HAVE to be purchased |
346
|
|
|
if ($this->min !== 0 && ! $this->ticket->required()) { |
347
|
|
|
$html .= '<option value="0"> 0 </option>'; |
348
|
|
|
} |
349
|
|
|
// offer ticket quantities from the min to the max |
350
|
|
|
for ($i = $this->min; $i <= $this->max; $i++) { |
351
|
|
|
$html .= '<option value="' . $i . '"> ' . $i . ' </option>'; |
352
|
|
|
} |
353
|
|
|
$html .= '</select>'; |
354
|
|
|
return $html; |
355
|
|
|
} |
356
|
|
|
|
357
|
|
|
|
358
|
|
|
/** |
359
|
|
|
* getHiddenInputs |
360
|
|
|
* |
361
|
|
|
* @return string |
362
|
|
|
* @throws EE_Error |
363
|
|
|
*/ |
364
|
|
|
protected function ticketQtyAndIdHiddenInputs() |
365
|
|
|
{ |
366
|
|
|
$html = ''; |
367
|
|
|
// depending on group reg we need to change the format for qty |
368
|
|
|
if ($this->hidden_input_qty) { |
369
|
|
|
$html .= '<input type="hidden" name="tkt-slctr-qty-' . $this->EVT_ID . '[]" value="0"/>'; |
370
|
|
|
} |
371
|
|
|
$html .= '<input type="hidden" name="tkt-slctr-ticket-id-' . $this->EVT_ID . '[]"'; |
372
|
|
|
$html .= ' value="' . $this->ticket->ID() . '"/>'; |
373
|
|
|
return $html; |
374
|
|
|
} |
375
|
|
|
} |
376
|
|
|
|