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