1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace EventEspresso\modules\ticket_selector; |
4
|
|
|
|
5
|
|
|
use EE_Datetime; |
6
|
|
|
use EE_Error; |
7
|
|
|
use EE_Ticket; |
8
|
|
|
use EEH_HTML; |
9
|
|
|
use EventEspresso\core\exceptions\UnexpectedEntityException; |
10
|
|
|
|
11
|
|
|
/** |
12
|
|
|
* Class TicketSelectorRow |
13
|
|
|
* abstract parent class for a single ticket selector ticket row |
14
|
|
|
* |
15
|
|
|
* @package Event Espresso |
16
|
|
|
* @author Brent Christensen |
17
|
|
|
*/ |
18
|
|
|
abstract class TicketSelectorRow |
19
|
|
|
{ |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* @var EE_Ticket $ticket |
23
|
|
|
*/ |
24
|
|
|
protected $ticket; |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* @var int $total_tickets |
28
|
|
|
*/ |
29
|
|
|
protected $total_tickets; |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* @var int $max_attendees |
33
|
|
|
*/ |
34
|
|
|
protected $max_attendees; |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* @var string $date_format |
38
|
|
|
*/ |
39
|
|
|
protected $date_format; |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* @var int $EVT_ID |
43
|
|
|
*/ |
44
|
|
|
protected $EVT_ID; |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* @var string $event_status |
48
|
|
|
*/ |
49
|
|
|
protected $event_status; |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* @var boolean $required_ticket_sold_out |
53
|
|
|
*/ |
54
|
|
|
protected $required_ticket_sold_out; |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* @var string $ticket_status_display |
58
|
|
|
*/ |
59
|
|
|
protected $ticket_status_display; |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* @var int $max |
63
|
|
|
*/ |
64
|
|
|
protected $max = 0; |
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* @var int $min |
68
|
|
|
*/ |
69
|
|
|
protected $min = 0; |
70
|
|
|
|
71
|
|
|
/** |
72
|
|
|
* @var float $ticket_price |
73
|
|
|
*/ |
74
|
|
|
protected $ticket_price = 0.00; |
75
|
|
|
|
76
|
|
|
/** |
77
|
|
|
* @var bool $ticket_bundle |
78
|
|
|
*/ |
79
|
|
|
protected $ticket_bundle = false; |
80
|
|
|
|
81
|
|
|
/** |
82
|
|
|
* @var string $ticket_status_id |
83
|
|
|
*/ |
84
|
|
|
protected $ticket_status_id = EE_Ticket::sold_out; |
85
|
|
|
|
86
|
|
|
/** |
87
|
|
|
* @var string $ticket_status_html |
88
|
|
|
*/ |
89
|
|
|
protected $ticket_status_html = 'ticket-sales-sold-out'; |
90
|
|
|
|
91
|
|
|
/** |
92
|
|
|
* @var string $status_class |
93
|
|
|
*/ |
94
|
|
|
protected $status_class = 'ticket-sales-sold-out lt-grey-text'; |
95
|
|
|
|
96
|
|
|
|
97
|
|
|
/** |
98
|
|
|
* @param EE_Ticket $ticket |
99
|
|
|
* @param int $max_attendees |
100
|
|
|
* @param string $date_format |
101
|
|
|
* @param string $event_status |
102
|
|
|
* @param bool $required_ticket_sold_out |
103
|
|
|
* @param int $total_tickets |
104
|
|
|
* @throws EE_Error |
105
|
|
|
* @throws UnexpectedEntityException |
106
|
|
|
*/ |
107
|
|
|
public function __construct( |
108
|
|
|
EE_Ticket $ticket, |
109
|
|
|
$max_attendees, |
110
|
|
|
$date_format, |
111
|
|
|
$event_status, |
112
|
|
|
$required_ticket_sold_out = false, |
113
|
|
|
$total_tickets = 1 |
114
|
|
|
) { |
115
|
|
|
$this->ticket = $ticket; |
116
|
|
|
$this->max_attendees = $max_attendees; |
117
|
|
|
$this->date_format = $date_format; |
118
|
|
|
$this->EVT_ID = $this->ticket->get_event_ID(); |
119
|
|
|
$this->event_status = $event_status; |
120
|
|
|
$this->required_ticket_sold_out = $required_ticket_sold_out; |
121
|
|
|
$this->total_tickets = $total_tickets; |
122
|
|
|
} |
123
|
|
|
|
124
|
|
|
|
125
|
|
|
/** |
126
|
|
|
* getTicketStatusClasses |
127
|
|
|
* |
128
|
|
|
* @param int $remaining |
129
|
|
|
* @return void |
130
|
|
|
* @throws EE_Error |
131
|
|
|
*/ |
132
|
|
|
protected function setTicketStatusClasses($remaining = 0) |
133
|
|
|
{ |
134
|
|
|
// if a previous required ticket with the same sale start date is sold out, |
135
|
|
|
// then mark this ticket as sold out as well. |
136
|
|
|
// tickets that go on sale at a later date than the required ticket will NOT be affected |
137
|
|
|
$this->ticket_status_id = $this->required_ticket_sold_out !== false |
138
|
|
|
&& $this->required_ticket_sold_out === $this->ticket->start_date() |
139
|
|
|
? EE_Ticket::sold_out |
140
|
|
|
: $this->ticket->ticket_status(); |
141
|
|
|
$this->ticket_status_id = $this->event_status === EE_Datetime::sold_out |
142
|
|
|
? EE_Ticket::sold_out |
143
|
|
|
: $this->ticket_status_id; |
144
|
|
|
// If at admin area, display expired tickets as on sale. |
145
|
|
|
$this->ticket_status_id = is_admin() && $this->ticket_status_id === EE_Ticket::expired |
146
|
|
|
? EE_Ticket::onsale |
147
|
|
|
: $this->ticket_status_id; |
148
|
|
|
// check ticket status |
149
|
|
|
switch ($this->ticket_status_id) { |
150
|
|
|
// sold_out |
151
|
|
|
case EE_Ticket::sold_out: |
152
|
|
|
$ticket_status_class = 'ticket-sales-sold-out'; |
153
|
|
|
$this->status_class = 'ticket-sales-sold-out lt-grey-text'; |
154
|
|
|
break; |
155
|
|
|
// expired |
156
|
|
|
case EE_Ticket::expired: |
157
|
|
|
$ticket_status_class = 'ticket-sales-expired'; |
158
|
|
|
$this->status_class = 'ticket-sales-expired lt-grey-text'; |
159
|
|
|
break; |
160
|
|
|
// archived |
161
|
|
|
case EE_Ticket::archived: |
162
|
|
|
$ticket_status_class = 'archived-ticket'; |
163
|
|
|
$this->status_class = 'archived-ticket hidden'; |
164
|
|
|
break; |
165
|
|
|
// pending |
166
|
|
|
case EE_Ticket::pending: |
167
|
|
|
$ticket_status_class = 'ticket-pending'; |
168
|
|
|
$this->status_class = 'ticket-pending'; |
169
|
|
|
break; |
170
|
|
|
// on sale |
171
|
|
|
case EE_Ticket::onsale: |
172
|
|
|
default: |
173
|
|
|
$ticket_status_class = 'ticket-on-sale'; |
174
|
|
|
$this->status_class = 'ticket-on-sale'; |
175
|
|
|
break; |
176
|
|
|
} |
177
|
|
|
$this->ticket_status_html = EEH_HTML::span( |
178
|
|
|
$this->ticket->ticket_status(true, ($remaining > 0)), |
179
|
|
|
"{$ticket_status_class}-{$this->ticket->ID()}", |
180
|
|
|
$ticket_status_class |
181
|
|
|
); |
182
|
|
|
} |
183
|
|
|
|
184
|
|
|
|
185
|
|
|
/** |
186
|
|
|
* @return string |
187
|
|
|
*/ |
188
|
|
|
public function getTicketStatusDisplay() |
189
|
|
|
{ |
190
|
|
|
return $this->ticket_status_display; |
191
|
|
|
} |
192
|
|
|
|
193
|
|
|
|
194
|
|
|
/** |
195
|
|
|
* setTicketStatusDisplay |
196
|
|
|
* |
197
|
|
|
* @param int $remaining |
198
|
|
|
* @throws EE_Error |
199
|
|
|
*/ |
200
|
|
|
protected function setTicketStatusDisplay($remaining) |
201
|
|
|
{ |
202
|
|
|
$this->ticket_status_display = ''; |
203
|
|
|
|
204
|
|
|
// now depending on the ticket and other circumstances... |
205
|
|
|
if ($this->max_attendees === 0) { |
206
|
|
|
// registration is CLOSED because admin set max attendees to ZERO |
207
|
|
|
$this->ticket_status_display = $this->registrationClosed(); |
208
|
|
|
} elseif ($this->ticket_status_id === EE_Ticket::sold_out || $remaining === 0) { |
209
|
|
|
// SOLD OUT - no tickets remaining |
210
|
|
|
$this->ticket_status_display = $this->ticketsSoldOut(); |
211
|
|
|
} elseif ($this->ticket_status_id === EE_Ticket::expired || $this->ticket_status_id === EE_Ticket::archived) { |
212
|
|
|
// expired or archived ticket |
213
|
|
|
$this->ticket_status_display = $this->ticket_status_html; |
214
|
|
|
} elseif ($this->ticket_status_id === EE_Ticket::pending) { |
215
|
|
|
// ticket not on sale yet |
216
|
|
|
$this->ticket_status_display = $this->ticketsSalesPending(); |
217
|
|
|
} elseif ($this->ticket->min() > $remaining) { |
218
|
|
|
// min qty purchasable is less than tickets available |
219
|
|
|
$this->ticket_status_display = $this->notEnoughTicketsAvailable(); |
220
|
|
|
} |
221
|
|
|
} |
222
|
|
|
|
223
|
|
|
|
224
|
|
|
/** |
225
|
|
|
* registrationClosed |
226
|
|
|
*/ |
227
|
|
|
protected function registrationClosed() |
228
|
|
|
{ |
229
|
|
|
return EEH_HTML::span( |
230
|
|
|
apply_filters( |
231
|
|
|
'FHEE__ticket_selector_chart_template__ticket_closed_msg', |
232
|
|
|
__('Closed', 'event_espresso') |
233
|
|
|
), |
234
|
|
|
'', |
235
|
|
|
'sold-out' |
236
|
|
|
); |
237
|
|
|
} |
238
|
|
|
|
239
|
|
|
|
240
|
|
|
/** |
241
|
|
|
* ticketsSoldOut |
242
|
|
|
*/ |
243
|
|
|
protected function ticketsSoldOut() |
244
|
|
|
{ |
245
|
|
|
return EEH_HTML::span( |
246
|
|
|
apply_filters( |
247
|
|
|
'FHEE__ticket_selector_chart_template__ticket_sold_out_msg', |
248
|
|
|
__('Sold Out', 'event_espresso') |
249
|
|
|
), |
250
|
|
|
'', |
251
|
|
|
'sold-out' |
252
|
|
|
); |
253
|
|
|
} |
254
|
|
|
|
255
|
|
|
|
256
|
|
|
/** |
257
|
|
|
* ticketsSalesPending |
258
|
|
|
* |
259
|
|
|
* @throws EE_Error |
260
|
|
|
*/ |
261
|
|
|
protected function ticketsSalesPending() |
262
|
|
|
{ |
263
|
|
|
return EEH_HTML::span( |
264
|
|
|
EEH_HTML::span( |
265
|
|
|
apply_filters( |
266
|
|
|
'FHEE__ticket_selector_chart_template__ticket_goes_on_sale_msg', |
267
|
|
|
__('Goes On Sale', 'event_espresso') |
268
|
|
|
), |
269
|
|
|
'', |
270
|
|
|
'ticket-pending' |
271
|
|
|
) |
272
|
|
|
. EEH_HTML::br() |
273
|
|
|
. EEH_HTML::span( |
274
|
|
|
$this->ticket->get_i18n_datetime( |
275
|
|
|
'TKT_start_date', |
276
|
|
|
apply_filters( |
277
|
|
|
'FHEE__EED_Ticket_Selector__display_goes_on_sale__date_format', |
278
|
|
|
$this->date_format |
279
|
|
|
) |
280
|
|
|
), |
281
|
|
|
'', |
282
|
|
|
'small-text' |
283
|
|
|
), |
284
|
|
|
'', |
285
|
|
|
'ticket-pending-pg' |
286
|
|
|
); |
287
|
|
|
} |
288
|
|
|
|
289
|
|
|
|
290
|
|
|
/** |
291
|
|
|
* notEnoughTicketsAvailable |
292
|
|
|
*/ |
293
|
|
|
protected function notEnoughTicketsAvailable() |
294
|
|
|
{ |
295
|
|
|
return EEH_HTML::div( |
296
|
|
|
EEH_HTML::span( |
297
|
|
|
apply_filters( |
298
|
|
|
'FHEE__ticket_selector_chart_template__ticket_not_available_msg', |
299
|
|
|
__('Not Available', 'event_espresso') |
300
|
|
|
), |
301
|
|
|
'', |
302
|
|
|
'archived-ticket small-text' |
303
|
|
|
) |
304
|
|
|
. EEH_HTML::br(), |
305
|
|
|
'', |
306
|
|
|
'archived-ticket-pg' |
307
|
|
|
); |
308
|
|
|
} |
309
|
|
|
|
310
|
|
|
|
311
|
|
|
/** |
312
|
|
|
* setTicketMinAndMax |
313
|
|
|
* |
314
|
|
|
* @param int $remaining |
315
|
|
|
* @return void |
316
|
|
|
* @throws EE_Error |
317
|
|
|
*/ |
318
|
|
|
protected function setTicketMinAndMax($remaining) |
319
|
|
|
{ |
320
|
|
|
// offer the number of $tickets_remaining or $this->max_attendees, whichever is smaller |
321
|
|
|
$this->max = min($remaining, $this->max_attendees); |
322
|
|
|
// but... we also want to restrict the number of tickets by the ticket max setting, |
323
|
|
|
// however, the max still can't be higher than what was just set above |
324
|
|
|
$this->max = $this->ticket->max() > 0 |
325
|
|
|
? min($this->ticket->max(), $this->max) |
326
|
|
|
: $this->max; |
327
|
|
|
// and we also want to restrict the minimum number of tickets by the ticket min setting |
328
|
|
|
$this->min = $this->ticket->min() > 0 |
329
|
|
|
? $this->ticket->min() |
330
|
|
|
: 0; |
331
|
|
|
// and if the ticket is required, then make sure that min qty is at least 1 |
332
|
|
|
$this->min = $this->ticket->required() |
333
|
|
|
? max($this->min, 1) |
334
|
|
|
: $this->min; |
335
|
|
|
} |
336
|
|
|
|
337
|
|
|
|
338
|
|
|
/** |
339
|
|
|
* Allow plugins to hook in and abort the generation and display of this row to do |
340
|
|
|
* something elseif they want. |
341
|
|
|
* For an addon to abort things, all they have to do is register a filter with this hook, and |
342
|
|
|
* return a value that is NOT false. Whatever is returned gets echoed instead of the |
343
|
|
|
* current row. |
344
|
|
|
* |
345
|
|
|
* @return string|bool |
346
|
|
|
*/ |
347
|
|
View Code Duplication |
protected function getFilteredRowHtml() |
348
|
|
|
{ |
349
|
|
|
return apply_filters( |
350
|
|
|
'FHEE__ticket_selector_chart_template__do_ticket_entire_row', |
351
|
|
|
false, |
352
|
|
|
$this->ticket, |
353
|
|
|
$this->max, |
354
|
|
|
$this->min, |
355
|
|
|
$this->required_ticket_sold_out, |
356
|
|
|
$this->ticket_price, |
357
|
|
|
$this->ticket_bundle, |
358
|
|
|
$this->ticket_status_html, |
359
|
|
|
$this->status_class, |
360
|
|
|
$this |
361
|
|
|
); |
362
|
|
|
} |
363
|
|
|
|
364
|
|
|
|
365
|
|
|
/** |
366
|
|
|
* Allow plugins to hook in and abort the generation and display of the contents of this |
367
|
|
|
* row to do something elseif they want. |
368
|
|
|
* For an addon to abort things, all they have to do is register a filter with this hook, and |
369
|
|
|
* return a value that is NOT false. Whatever is returned gets echoed instead of the |
370
|
|
|
* current row. |
371
|
|
|
* |
372
|
|
|
* @return string|bool |
373
|
|
|
*/ |
374
|
|
View Code Duplication |
protected function getFilteredRowContents() |
375
|
|
|
{ |
376
|
|
|
return apply_filters( |
377
|
|
|
'FHEE__ticket_selector_chart_template__do_ticket_inside_row', |
378
|
|
|
false, |
379
|
|
|
$this->ticket, |
380
|
|
|
$this->max, |
381
|
|
|
$this->min, |
382
|
|
|
$this->required_ticket_sold_out, |
383
|
|
|
$this->ticket_price, |
384
|
|
|
$this->ticket_bundle, |
385
|
|
|
$this->ticket_status_html, |
386
|
|
|
$this->status_class, |
387
|
|
|
$this |
388
|
|
|
); |
389
|
|
|
} |
390
|
|
|
} |
391
|
|
|
|