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