Completed
Branch BUG-10381-asset-loading (189bf4)
by
unknown
13:54
created

TicketSelectorRow::setTicketStatusDisplay()   B

Complexity

Conditions 8
Paths 6

Size

Total Lines 20
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 8
eloc 12
nc 6
nop 3
dl 0
loc 20
rs 7.7777
c 0
b 0
f 0
1
<?php
2
namespace EventEspresso\modules\ticket_selector;
3
4
defined('ABSPATH') || exit;
5
6
7
8
/**
9
 * Class TicketSelectorRow
10
 * abstract parent class for a single ticket selector ticket row
11
 *
12
 * @package       Event Espresso
13
 * @author        Brent Christensen
14
 * @since         $VID:$
15
 */
16
abstract class TicketSelectorRow
17
{
18
19
    /**
20
     * @var \EE_Ticket $ticket
21
     */
22
    protected $ticket;
23
24
    /**
25
     * @var int $max_atndz
26
     */
27
    protected $max_atndz;
28
29
    /**
30
     * @var string $date_format
31
     */
32
    protected $date_format;
33
34
    /**
35
     * @var int $EVT_ID
36
     */
37
    protected $EVT_ID;
38
39
    /**
40
     * @var string $ticket_status_display
41
     */
42
    protected $ticket_status_display;
43
44
45
46
    /**
47
     * TicketDetails constructor.
48
     *
49
     * @param \EE_Ticket                 $ticket
50
     * @param int                        $max_atndz
51
     * @param string                     $date_format
52
     */
53
    public function __construct(
54
        \EE_Ticket $ticket,
55
        $max_atndz,
56
        $date_format
57
    ) {
58
        $this->ticket = $ticket;
59
        $this->max_atndz = $max_atndz;
60
        $this->date_format = $date_format;
61
        $this->EVT_ID = $this->ticket->get_event_ID();
62
    }
63
64
65
66
    /**
67
     * @return string
68
     */
69
    public function getTicketStatusDisplay()
70
    {
71
        return $this->ticket_status_display;
72
    }
73
74
75
76
    /**
77
     * setTicketStatusDisplay
78
     *
79
     * @param string $tkt_status
80
     * @param string $ticket_status
81
     * @param int    $remaining
82
     * @throws \EE_Error
83
     */
84
    protected function setTicketStatusDisplay($tkt_status, $ticket_status, $remaining) {
85
        $this->ticket_status_display = '';
86
        // now depending on the ticket and other circumstances...
87
        if ($this->max_atndz === 0) {
88
            // registration is CLOSED because admin set max attendees to ZERO
89
            $this->ticket_status_display = $this->registrationClosed();
90
        } else if ($tkt_status === \EE_Ticket::sold_out || $remaining === 0) {
91
            // SOLD OUT - no tickets remaining
92
            $this->ticket_status_display = $this->ticketsSoldOut();
93
        } else if ($tkt_status === \EE_Ticket::expired || $tkt_status === \EE_Ticket::archived) {
94
            // expired or archived ticket
95
            $this->ticket_status_display = $ticket_status;
96
        } else if ($tkt_status === \EE_Ticket::pending) {
97
            // ticket not on sale yet
98
            $this->ticket_status_display = $this->ticketsSalesPending();
99
        } else if ($this->ticket->min() > $remaining) {
100
            // min qty purchasable is less than tickets available
101
            $this->ticket_status_display = $this->notEnoughTicketsAvailable();
102
        }
103
    }
104
105
106
107
    /**
108
     * registrationClosed
109
     */
110
    protected function registrationClosed()
111
    {
112
        return \EEH_HTML::span(
113
            apply_filters(
114
                'FHEE__ticket_selector_chart_template__ticket_closed_msg',
115
                __('Closed', 'event_espresso')
116
            ),
117
            '', 'sold-out'
118
        );
119
    }
120
121
122
123
    /**
124
     * ticketsSoldOut
125
     */
126
    protected function ticketsSoldOut()
127
    {
128
        return \EEH_HTML::span(
129
            apply_filters(
130
                'FHEE__ticket_selector_chart_template__ticket_sold_out_msg',
131
                __('Sold&nbsp;Out', 'event_espresso')
132
            ),
133
            '', 'sold-out'
134
        );
135
    }
136
137
138
139
    /**
140
     * ticketsSalesPending
141
     *
142
     * @throws \EE_Error
143
     */
144
    protected function ticketsSalesPending()
145
    {
146
        return \EEH_HTML::span(
147
            \EEH_HTML::span(
148
                apply_filters(
149
                    'FHEE__ticket_selector_chart_template__ticket_goes_on_sale_msg',
150
                    __('Goes&nbsp;On&nbsp;Sale', 'event_espresso')
151
                ),
152
                '', 'ticket-pending'
153
            )
154
            . \EEH_HTML::br()
155
            . \EEH_HTML::span(
156
                $this->ticket->get_i18n_datetime(
157
                    'TKT_start_date',
158
                    apply_filters(
159
                        'FHEE__EED_Ticket_Selector__display_goes_on_sale__date_format',
160
                        $this->date_format
161
                    )
162
                ),
163
                '', 'small-text'
164
            ),
165
            '', 'ticket-pending-pg'
166
        );
167
    }
168
169
170
171
    /**
172
     * notEnoughTicketsAvailable
173
     */
174
    protected function notEnoughTicketsAvailable()
175
    {
176
        return \EEH_HTML::div(
177
            \EEH_HTML::span(
178
                apply_filters(
179
                    'FHEE__ticket_selector_chart_template__ticket_not_available_msg',
180
                    __('Not Available', 'event_espresso')
181
                ),
182
                '', 'archived-ticket small-text'
183
            )
184
            . \EEH_HTML::br(),
185
            '', 'archived-ticket-pg'
186
        );
187
    }
188
189
190
191
    /**
192
     * getHiddenInputs
193
     *
194
     * @param string $anchor_id
195
     * @param int    $row
196
     * @param int    $max_atndz
197
     * @return string
198
     */
199
    protected function getHiddenInputs($anchor_id, $row, $max_atndz)
200
    {
201
        $html = '<input type="hidden" name="noheader" value="true"/>';
202
        $html .= '<input type="hidden" name="tkt-slctr-return-url-' . $this->EVT_ID . '"';
203
        $html .= ' value="' . \EEH_URL::current_url() . $anchor_id . '"/>';
204
        $html .= '<input type="hidden" name="tkt-slctr-rows-' . $this->EVT_ID . '" value="' . $row - 1 . '"/>';
205
        $html .= '<input type="hidden" name="tkt-slctr-max-atndz-' . $this->EVT_ID . '" value="' . $max_atndz . '"/>';
206
        $html .= '<input type="hidden" name="tkt-slctr-event-id" value="' . $this->EVT_ID . '"/>';
207
        return $html;
208
    }
209
210
211
212
}
213
// End of file TicketSelectorRow.php
214
// Location: EventEspresso\modules\ticket_selector/TicketSelectorRow.php