Completed
Branch FET-10486-add-timestamp-checki... (611b15)
by
unknown
136:24 queued 121:17
created

TicketSelectorRow::getTicketStatusClasses()   D

Complexity

Conditions 9
Paths 48

Size

Total Lines 44
Code Lines 32

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 9
eloc 32
nc 48
nop 1
dl 0
loc 44
rs 4.909
c 0
b 0
f 0
1
<?php
2
namespace EventEspresso\modules\ticket_selector;
3
4
use EE_Error;
5
use EventEspresso\core\exceptions\UnexpectedEntityException;
6
7
defined('ABSPATH') || exit;
8
9
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
 * @since         $VID:$
18
 */
19
abstract class TicketSelectorRow
20
{
21
22
    /**
23
     * @var \EE_Ticket $ticket
24
     */
25
    protected $ticket;
26
27
    /**
28
     * @var int $total_tickets
29
     */
30
    protected $total_tickets;
31
32
    /**
33
     * @var int $max_atndz
34
     */
35
    protected $max_atndz;
36
37
    /**
38
     * @var string $date_format
39
     */
40
    protected $date_format;
41
42
    /**
43
     * @var int $EVT_ID
44
     */
45
    protected $EVT_ID;
46
47
    /**
48
     * @var string $event_status
49
     */
50
    protected $event_status;
51
52
    /**
53
     * @var boolean $required_ticket_sold_out
54
     */
55
    protected $required_ticket_sold_out;
56
57
    /**
58
     * @var string $ticket_status_display
59
     */
60
    protected $ticket_status_display;
61
62
63
64
    /**
65
     * @param \EE_Ticket $ticket
66
     * @param int        $max_atndz
67
     * @param string     $date_format
68
     * @param string     $event_status
69
     * @param bool       $required_ticket_sold_out
70
     * @throws EE_Error
71
     * @throws UnexpectedEntityException
72
     */
73
    public function __construct(
74
        \EE_Ticket $ticket,
75
        $max_atndz,
76
        $date_format,
77
        $event_status,
78
        $required_ticket_sold_out = false
79
    ) {
80
        $this->ticket = $ticket;
81
        $this->max_atndz = $max_atndz;
82
        $this->date_format = $date_format;
83
        $this->EVT_ID = $this->ticket->get_event_ID();
84
        $this->event_status = $event_status;
85
        $this->required_ticket_sold_out = $required_ticket_sold_out;
86
    }
87
88
89
90
    /**
91
     * getTicketStatusClasses
92
     *
93
     * @param int $remaining
94
     * @return array
95
     * @throws EE_Error
96
     */
97
    protected function getTicketStatusClasses($remaining = 0)
98
    {
99
        // if a previous required ticket with the same sale start date is sold out,
100
        // then mark this ticket as sold out as well.
101
        // tickets that go on sale at a later date than the required ticket  will NOT be affected
102
        $tkt_status = $this->required_ticket_sold_out !== false
103
                      && $this->required_ticket_sold_out === $this->ticket->start_date()
104
            ? \EE_Ticket::sold_out
105
            : $this->ticket->ticket_status();
106
        $tkt_status = $this->event_status === \EE_Datetime::sold_out
107
            ? \EE_Ticket::sold_out
108
            : $tkt_status;
109
        // check ticket status
110
        switch ($tkt_status) {
111
            // sold_out
112
            case \EE_Ticket::sold_out :
113
                $ticket_status = 'ticket-sales-sold-out';
114
                $status_class = 'ticket-sales-sold-out lt-grey-text';
115
                break;
116
            // expired
117
            case \EE_Ticket::expired :
118
                $ticket_status = 'ticket-sales-expired';
119
                $status_class = 'ticket-sales-expired lt-grey-text';
120
                break;
121
            // archived
122
            case \EE_Ticket::archived :
123
                $ticket_status = 'archived-ticket';
124
                $status_class = 'archived-ticket hidden';
125
                break;
126
            // pending
127
            case \EE_Ticket::pending :
128
                $ticket_status = 'ticket-pending';
129
                $status_class = 'ticket-pending';
130
                break;
131
            // onsale
132
            case \EE_Ticket::onsale :
133
            default :
134
                $ticket_status = 'ticket-on-sale';
135
                $status_class = 'ticket-on-sale';
136
                break;
137
        }
138
        $ticket_status = \EEH_HTML::span($this->ticket->ticket_status(true, ($remaining > 0)), '', $ticket_status);
139
        return array($tkt_status, $ticket_status, $status_class);
140
    }
141
142
143
    /**
144
     * @return string
145
     */
146
    public function getTicketStatusDisplay()
147
    {
148
        return $this->ticket_status_display;
149
    }
150
151
152
153
    /**
154
     * setTicketStatusDisplay
155
     *
156
     * @param string $tkt_status
157
     * @param string $ticket_status
158
     * @param int    $remaining
159
     * @throws EE_Error
160
     */
161
    protected function setTicketStatusDisplay($tkt_status, $ticket_status, $remaining) {
162
        $this->ticket_status_display = '';
163
        // now depending on the ticket and other circumstances...
164
        if ($this->max_atndz === 0) {
165
            // registration is CLOSED because admin set max attendees to ZERO
166
            $this->ticket_status_display = $this->registrationClosed();
167
        } else if ($tkt_status === \EE_Ticket::sold_out || $remaining === 0) {
168
            // SOLD OUT - no tickets remaining
169
            $this->ticket_status_display = $this->ticketsSoldOut();
170
        } else if ($tkt_status === \EE_Ticket::expired || $tkt_status === \EE_Ticket::archived) {
171
            // expired or archived ticket
172
            $this->ticket_status_display = $ticket_status;
173
        } else if ($tkt_status === \EE_Ticket::pending) {
174
            // ticket not on sale yet
175
            $this->ticket_status_display = $this->ticketsSalesPending();
176
        } else if ($this->ticket->min() > $remaining) {
177
            // min qty purchasable is less than tickets available
178
            $this->ticket_status_display = $this->notEnoughTicketsAvailable();
179
        }
180
    }
181
182
183
184
    /**
185
     * registrationClosed
186
     */
187
    protected function registrationClosed()
188
    {
189
        return \EEH_HTML::span(
190
            apply_filters(
191
                'FHEE__ticket_selector_chart_template__ticket_closed_msg',
192
                __('Closed', 'event_espresso')
193
            ),
194
            '', 'sold-out'
195
        );
196
    }
197
198
199
200
    /**
201
     * ticketsSoldOut
202
     */
203
    protected function ticketsSoldOut()
204
    {
205
        return \EEH_HTML::span(
206
            apply_filters(
207
                'FHEE__ticket_selector_chart_template__ticket_sold_out_msg',
208
                __('Sold&nbsp;Out', 'event_espresso')
209
            ),
210
            '', 'sold-out'
211
        );
212
    }
213
214
215
216
    /**
217
     * ticketsSalesPending
218
     *
219
     * @throws EE_Error
220
     */
221
    protected function ticketsSalesPending()
222
    {
223
        return \EEH_HTML::span(
224
            \EEH_HTML::span(
225
                apply_filters(
226
                    'FHEE__ticket_selector_chart_template__ticket_goes_on_sale_msg',
227
                    __('Goes&nbsp;On&nbsp;Sale', 'event_espresso')
228
                ),
229
                '', 'ticket-pending'
230
            )
231
            . \EEH_HTML::br()
232
            . \EEH_HTML::span(
233
                $this->ticket->get_i18n_datetime(
234
                    'TKT_start_date',
235
                    apply_filters(
236
                        'FHEE__EED_Ticket_Selector__display_goes_on_sale__date_format',
237
                        $this->date_format
238
                    )
239
                ),
240
                '', 'small-text'
241
            ),
242
            '', 'ticket-pending-pg'
243
        );
244
    }
245
246
247
248
    /**
249
     * notEnoughTicketsAvailable
250
     */
251
    protected function notEnoughTicketsAvailable()
252
    {
253
        return \EEH_HTML::div(
254
            \EEH_HTML::span(
255
                apply_filters(
256
                    'FHEE__ticket_selector_chart_template__ticket_not_available_msg',
257
                    __('Not Available', 'event_espresso')
258
                ),
259
                '', 'archived-ticket small-text'
260
            )
261
            . \EEH_HTML::br(),
262
            '', 'archived-ticket-pg'
263
        );
264
    }
265
266
267
268
}
269
// End of file TicketSelectorRow.php
270
// Location: EventEspresso\modules\ticket_selector/TicketSelectorRow.php