Completed
Branch BUG/fix-ts-expired-event-messa... (22631c)
by
unknown
18:06 queued 09:54
created
modules/ticket_selector/DisplayTicketSelector.php 2 patches
Indentation   +718 added lines, -718 removed lines patch added patch discarded remove patch
@@ -33,725 +33,725 @@
 block discarded – undo
33 33
 class DisplayTicketSelector
34 34
 {
35 35
 
36
-    /**
37
-     * event that ticket selector is being generated for
38
-     *
39
-     * @access protected
40
-     * @var EE_Event $event
41
-     */
42
-    protected $event;
43
-
44
-    /**
45
-     * Used to flag when the ticket selector is being called from an external iframe.
46
-     *
47
-     * @var bool $iframe
48
-     */
49
-    protected $iframe = false;
50
-
51
-    /**
52
-     * max attendees that can register for event at one time
53
-     *
54
-     * @var int $max_attendees
55
-     */
56
-    private $max_attendees = EE_INF;
57
-
58
-    /**
59
-     * @var string $date_format
60
-     */
61
-    private $date_format;
62
-
63
-    /**
64
-     * @var string $time_format
65
-     */
66
-    private $time_format;
67
-
68
-    /**
69
-     * @var boolean $display_full_ui
70
-     */
71
-    private $display_full_ui;
72
-
73
-
74
-    /**
75
-     * DisplayTicketSelector constructor.
76
-     *
77
-     * @param bool $iframe
78
-     */
79
-    public function __construct($iframe = false)
80
-    {
81
-        $this->iframe = $iframe;
82
-        $this->date_format = apply_filters(
83
-            'FHEE__EED_Ticket_Selector__display_ticket_selector__date_format',
84
-            get_option('date_format')
85
-        );
86
-        $this->time_format = apply_filters(
87
-            'FHEE__EED_Ticket_Selector__display_ticket_selector__time_format',
88
-            get_option('time_format')
89
-        );
90
-    }
91
-
92
-
93
-    /**
94
-     * @return bool
95
-     */
96
-    public function isIframe()
97
-    {
98
-        return $this->iframe;
99
-    }
100
-
101
-
102
-    /**
103
-     * @param boolean $iframe
104
-     */
105
-    public function setIframe($iframe = true)
106
-    {
107
-        $this->iframe = filter_var($iframe, FILTER_VALIDATE_BOOLEAN);
108
-    }
109
-
110
-
111
-    /**
112
-     * finds and sets the \EE_Event object for use throughout class
113
-     *
114
-     * @param mixed $event
115
-     * @return bool
116
-     * @throws EE_Error
117
-     * @throws InvalidDataTypeException
118
-     * @throws InvalidInterfaceException
119
-     * @throws InvalidArgumentException
120
-     */
121
-    protected function setEvent($event = null)
122
-    {
123
-        if ($event === null) {
124
-            global $post;
125
-            $event = $post;
126
-        }
127
-        if ($event instanceof EE_Event) {
128
-            $this->event = $event;
129
-        } elseif ($event instanceof WP_Post) {
130
-            if (isset($event->EE_Event) && $event->EE_Event instanceof EE_Event) {
131
-                $this->event = $event->EE_Event;
132
-            } elseif ($event->post_type === 'espresso_events') {
133
-                $event->EE_Event = EEM_Event::instance()->instantiate_class_from_post_object($event);
134
-                $this->event = $event->EE_Event;
135
-            }
136
-        } else {
137
-            $user_msg = __('No Event object or an invalid Event object was supplied.', 'event_espresso');
138
-            $dev_msg = $user_msg . __(
139
-                'In order to generate a ticket selector, please ensure you are passing either an EE_Event object or a WP_Post object of the post type "espresso_event" to the EE_Ticket_Selector class constructor.',
140
-                'event_espresso'
141
-            );
142
-            EE_Error::add_error($user_msg . '||' . $dev_msg, __FILE__, __FUNCTION__, __LINE__);
143
-            return false;
144
-        }
145
-        return true;
146
-    }
147
-
148
-
149
-    /**
150
-     * @return int
151
-     */
152
-    public function getMaxAttendees()
153
-    {
154
-        return $this->max_attendees;
155
-    }
156
-
157
-
158
-    /**
159
-     * @param int $max_attendees
160
-     */
161
-    public function setMaxAttendees($max_attendees)
162
-    {
163
-        $this->max_attendees = absint(
164
-            apply_filters(
165
-                'FHEE__EE_Ticket_Selector__display_ticket_selector__max_tickets',
166
-                $max_attendees
167
-            )
168
-        );
169
-    }
170
-
171
-
172
-    /**
173
-     * Returns whether or not the full ticket selector should be shown or not.
174
-     * Currently, it displays on the frontend (including ajax requests) but not the backend
175
-     *
176
-     * @return bool
177
-     */
178
-    private function display_full_ui()
179
-    {
180
-        if ($this->display_full_ui === null) {
181
-            $this->display_full_ui = ! is_admin() || (defined('DOING_AJAX') && DOING_AJAX);
182
-        }
183
-        return $this->display_full_ui;
184
-    }
185
-
186
-
187
-    /**
188
-     * creates buttons for selecting number of attendees for an event
189
-     *
190
-     * @param WP_Post|int $event
191
-     * @param bool        $view_details
192
-     * @return string
193
-     * @throws EE_Error
194
-     * @throws InvalidArgumentException
195
-     * @throws InvalidDataTypeException
196
-     * @throws InvalidInterfaceException
197
-     */
198
-    public function display($event = null, $view_details = false)
199
-    {
200
-        // reset filter for displaying submit button
201
-        remove_filter('FHEE__EE_Ticket_Selector__display_ticket_selector_submit', '__return_true');
202
-        // poke and prod incoming event till it tells us what it is
203
-        if (! $this->setEvent($event)) {
204
-            return false;
205
-        }
206
-        // is the event expired ?
207
-        $template_args['event_is_expired'] = ! is_admin() ? $this->event->is_expired() : false;
208
-        if ($template_args['event_is_expired']) {
209
-            return $this->expiredEventMessage();
210
-        }
211
-        // begin gathering template arguments by getting event status
212
-        $template_args = array('event_status' => $this->event->get_active_status());
213
-        if ($this->activeEventAndShowTicketSelector(
214
-            $event,
215
-            $template_args['event_status'],
216
-            $view_details
217
-        )) {
218
-            return ! is_single() ? $this->displayViewDetailsButton() : '';
219
-        }
220
-        // filter the maximum qty that can appear in the Ticket Selector qty dropdowns
221
-        $this->setMaxAttendees($this->event->additional_limit());
222
-        if ($this->getMaxAttendees() < 1) {
223
-            return $this->ticketSalesClosedMessage();
224
-        }
225
-        // get all tickets for this event ordered by the datetime
226
-        $tickets = $this->getTickets();
227
-        if (count($tickets) < 1) {
228
-            return $this->noTicketAvailableMessage();
229
-        }
230
-        // redirecting to another site for registration ??
231
-        $external_url = (string) $this->event->external_url()
232
-            && $this->event->external_url() !== get_the_permalink()
233
-            ? $this->event->external_url()
234
-            : '';
235
-        // if redirecting to another site for registration, then we don't load the TS
236
-        $ticket_selector = $external_url
237
-            ? $this->externalEventRegistration()
238
-            : $this->loadTicketSelector($tickets, $template_args);
239
-        // now set up the form (but not for the admin)
240
-        $ticket_selector = $this->display_full_ui()
241
-            ? $this->formOpen($this->event->ID(), $external_url) . $ticket_selector
242
-            : $ticket_selector;
243
-        // submit button and form close tag
244
-        $ticket_selector .= $this->display_full_ui() ? $this->displaySubmitButton($external_url) : '';
245
-        return $ticket_selector;
246
-    }
247
-
248
-
249
-    /**
250
-     * displayTicketSelector
251
-     * examines the event properties and determines whether a Ticket Selector should be displayed
252
-     *
253
-     * @param WP_Post|int $event
254
-     * @param string      $_event_active_status
255
-     * @param bool        $view_details
256
-     * @return bool
257
-     * @throws EE_Error
258
-     */
259
-    protected function activeEventAndShowTicketSelector($event, $_event_active_status, $view_details)
260
-    {
261
-        $event_post = $this->event instanceof EE_Event ? $this->event->ID() : $event;
262
-        return $this->display_full_ui()
263
-               && (
264
-                   ! $this->event->display_ticket_selector()
265
-                   || $view_details
266
-                   || post_password_required($event_post)
267
-                   || (
268
-                       $_event_active_status !== EE_Datetime::active
269
-                       && $_event_active_status !== EE_Datetime::upcoming
270
-                       && $_event_active_status !== EE_Datetime::sold_out
271
-                       && ! (
272
-                           $_event_active_status === EE_Datetime::inactive
273
-                           && is_user_logged_in()
274
-                       )
275
-                   )
276
-               );
277
-    }
278
-
279
-
280
-    /**
281
-     * noTicketAvailableMessage
282
-     * notice displayed if event is expired
283
-     *
284
-     * @return string
285
-     * @throws EE_Error
286
-     */
287
-    protected function expiredEventMessage()
288
-    {
289
-        return '<div class="ee-event-expired-notice"><span class="important-notice">' . esc_html__(
290
-            'We\'re sorry, but all tickets sales have ended because the event is expired.',
291
-            'event_espresso'
292
-        ) . '</span></div><!-- .ee-event-expired-notice -->';
293
-    }
294
-
295
-
296
-    /**
297
-     * noTicketAvailableMessage
298
-     * notice displayed if event has no more tickets available
299
-     *
300
-     * @return string
301
-     * @throws EE_Error
302
-     */
303
-    protected function noTicketAvailableMessage()
304
-    {
305
-        $no_ticket_available_msg = esc_html__('We\'re sorry, but all ticket sales have ended.', 'event_espresso');
306
-        if (current_user_can('edit_post', $this->event->ID())) {
307
-            $no_ticket_available_msg .= sprintf(
308
-                esc_html__(
309
-                    '%1$sNote to Event Admin:%2$sNo tickets were found for this event. This effectively turns off ticket sales. Please ensure that at least one ticket is available for if you want people to be able to register.%3$s(click to edit this event)%4$s',
310
-                    'event_espresso'
311
-                ),
312
-                '<div class="ee-attention" style="text-align: left;"><b>',
313
-                '</b><br />',
314
-                '<span class="edit-link"><a class="post-edit-link" href="'
315
-                . get_edit_post_link($this->event->ID())
316
-                . '">',
317
-                '</a></span></div><!-- .ee-attention noTicketAvailableMessage -->'
318
-            );
319
-        }
320
-        return '
36
+	/**
37
+	 * event that ticket selector is being generated for
38
+	 *
39
+	 * @access protected
40
+	 * @var EE_Event $event
41
+	 */
42
+	protected $event;
43
+
44
+	/**
45
+	 * Used to flag when the ticket selector is being called from an external iframe.
46
+	 *
47
+	 * @var bool $iframe
48
+	 */
49
+	protected $iframe = false;
50
+
51
+	/**
52
+	 * max attendees that can register for event at one time
53
+	 *
54
+	 * @var int $max_attendees
55
+	 */
56
+	private $max_attendees = EE_INF;
57
+
58
+	/**
59
+	 * @var string $date_format
60
+	 */
61
+	private $date_format;
62
+
63
+	/**
64
+	 * @var string $time_format
65
+	 */
66
+	private $time_format;
67
+
68
+	/**
69
+	 * @var boolean $display_full_ui
70
+	 */
71
+	private $display_full_ui;
72
+
73
+
74
+	/**
75
+	 * DisplayTicketSelector constructor.
76
+	 *
77
+	 * @param bool $iframe
78
+	 */
79
+	public function __construct($iframe = false)
80
+	{
81
+		$this->iframe = $iframe;
82
+		$this->date_format = apply_filters(
83
+			'FHEE__EED_Ticket_Selector__display_ticket_selector__date_format',
84
+			get_option('date_format')
85
+		);
86
+		$this->time_format = apply_filters(
87
+			'FHEE__EED_Ticket_Selector__display_ticket_selector__time_format',
88
+			get_option('time_format')
89
+		);
90
+	}
91
+
92
+
93
+	/**
94
+	 * @return bool
95
+	 */
96
+	public function isIframe()
97
+	{
98
+		return $this->iframe;
99
+	}
100
+
101
+
102
+	/**
103
+	 * @param boolean $iframe
104
+	 */
105
+	public function setIframe($iframe = true)
106
+	{
107
+		$this->iframe = filter_var($iframe, FILTER_VALIDATE_BOOLEAN);
108
+	}
109
+
110
+
111
+	/**
112
+	 * finds and sets the \EE_Event object for use throughout class
113
+	 *
114
+	 * @param mixed $event
115
+	 * @return bool
116
+	 * @throws EE_Error
117
+	 * @throws InvalidDataTypeException
118
+	 * @throws InvalidInterfaceException
119
+	 * @throws InvalidArgumentException
120
+	 */
121
+	protected function setEvent($event = null)
122
+	{
123
+		if ($event === null) {
124
+			global $post;
125
+			$event = $post;
126
+		}
127
+		if ($event instanceof EE_Event) {
128
+			$this->event = $event;
129
+		} elseif ($event instanceof WP_Post) {
130
+			if (isset($event->EE_Event) && $event->EE_Event instanceof EE_Event) {
131
+				$this->event = $event->EE_Event;
132
+			} elseif ($event->post_type === 'espresso_events') {
133
+				$event->EE_Event = EEM_Event::instance()->instantiate_class_from_post_object($event);
134
+				$this->event = $event->EE_Event;
135
+			}
136
+		} else {
137
+			$user_msg = __('No Event object or an invalid Event object was supplied.', 'event_espresso');
138
+			$dev_msg = $user_msg . __(
139
+				'In order to generate a ticket selector, please ensure you are passing either an EE_Event object or a WP_Post object of the post type "espresso_event" to the EE_Ticket_Selector class constructor.',
140
+				'event_espresso'
141
+			);
142
+			EE_Error::add_error($user_msg . '||' . $dev_msg, __FILE__, __FUNCTION__, __LINE__);
143
+			return false;
144
+		}
145
+		return true;
146
+	}
147
+
148
+
149
+	/**
150
+	 * @return int
151
+	 */
152
+	public function getMaxAttendees()
153
+	{
154
+		return $this->max_attendees;
155
+	}
156
+
157
+
158
+	/**
159
+	 * @param int $max_attendees
160
+	 */
161
+	public function setMaxAttendees($max_attendees)
162
+	{
163
+		$this->max_attendees = absint(
164
+			apply_filters(
165
+				'FHEE__EE_Ticket_Selector__display_ticket_selector__max_tickets',
166
+				$max_attendees
167
+			)
168
+		);
169
+	}
170
+
171
+
172
+	/**
173
+	 * Returns whether or not the full ticket selector should be shown or not.
174
+	 * Currently, it displays on the frontend (including ajax requests) but not the backend
175
+	 *
176
+	 * @return bool
177
+	 */
178
+	private function display_full_ui()
179
+	{
180
+		if ($this->display_full_ui === null) {
181
+			$this->display_full_ui = ! is_admin() || (defined('DOING_AJAX') && DOING_AJAX);
182
+		}
183
+		return $this->display_full_ui;
184
+	}
185
+
186
+
187
+	/**
188
+	 * creates buttons for selecting number of attendees for an event
189
+	 *
190
+	 * @param WP_Post|int $event
191
+	 * @param bool        $view_details
192
+	 * @return string
193
+	 * @throws EE_Error
194
+	 * @throws InvalidArgumentException
195
+	 * @throws InvalidDataTypeException
196
+	 * @throws InvalidInterfaceException
197
+	 */
198
+	public function display($event = null, $view_details = false)
199
+	{
200
+		// reset filter for displaying submit button
201
+		remove_filter('FHEE__EE_Ticket_Selector__display_ticket_selector_submit', '__return_true');
202
+		// poke and prod incoming event till it tells us what it is
203
+		if (! $this->setEvent($event)) {
204
+			return false;
205
+		}
206
+		// is the event expired ?
207
+		$template_args['event_is_expired'] = ! is_admin() ? $this->event->is_expired() : false;
208
+		if ($template_args['event_is_expired']) {
209
+			return $this->expiredEventMessage();
210
+		}
211
+		// begin gathering template arguments by getting event status
212
+		$template_args = array('event_status' => $this->event->get_active_status());
213
+		if ($this->activeEventAndShowTicketSelector(
214
+			$event,
215
+			$template_args['event_status'],
216
+			$view_details
217
+		)) {
218
+			return ! is_single() ? $this->displayViewDetailsButton() : '';
219
+		}
220
+		// filter the maximum qty that can appear in the Ticket Selector qty dropdowns
221
+		$this->setMaxAttendees($this->event->additional_limit());
222
+		if ($this->getMaxAttendees() < 1) {
223
+			return $this->ticketSalesClosedMessage();
224
+		}
225
+		// get all tickets for this event ordered by the datetime
226
+		$tickets = $this->getTickets();
227
+		if (count($tickets) < 1) {
228
+			return $this->noTicketAvailableMessage();
229
+		}
230
+		// redirecting to another site for registration ??
231
+		$external_url = (string) $this->event->external_url()
232
+			&& $this->event->external_url() !== get_the_permalink()
233
+			? $this->event->external_url()
234
+			: '';
235
+		// if redirecting to another site for registration, then we don't load the TS
236
+		$ticket_selector = $external_url
237
+			? $this->externalEventRegistration()
238
+			: $this->loadTicketSelector($tickets, $template_args);
239
+		// now set up the form (but not for the admin)
240
+		$ticket_selector = $this->display_full_ui()
241
+			? $this->formOpen($this->event->ID(), $external_url) . $ticket_selector
242
+			: $ticket_selector;
243
+		// submit button and form close tag
244
+		$ticket_selector .= $this->display_full_ui() ? $this->displaySubmitButton($external_url) : '';
245
+		return $ticket_selector;
246
+	}
247
+
248
+
249
+	/**
250
+	 * displayTicketSelector
251
+	 * examines the event properties and determines whether a Ticket Selector should be displayed
252
+	 *
253
+	 * @param WP_Post|int $event
254
+	 * @param string      $_event_active_status
255
+	 * @param bool        $view_details
256
+	 * @return bool
257
+	 * @throws EE_Error
258
+	 */
259
+	protected function activeEventAndShowTicketSelector($event, $_event_active_status, $view_details)
260
+	{
261
+		$event_post = $this->event instanceof EE_Event ? $this->event->ID() : $event;
262
+		return $this->display_full_ui()
263
+			   && (
264
+				   ! $this->event->display_ticket_selector()
265
+				   || $view_details
266
+				   || post_password_required($event_post)
267
+				   || (
268
+					   $_event_active_status !== EE_Datetime::active
269
+					   && $_event_active_status !== EE_Datetime::upcoming
270
+					   && $_event_active_status !== EE_Datetime::sold_out
271
+					   && ! (
272
+						   $_event_active_status === EE_Datetime::inactive
273
+						   && is_user_logged_in()
274
+					   )
275
+				   )
276
+			   );
277
+	}
278
+
279
+
280
+	/**
281
+	 * noTicketAvailableMessage
282
+	 * notice displayed if event is expired
283
+	 *
284
+	 * @return string
285
+	 * @throws EE_Error
286
+	 */
287
+	protected function expiredEventMessage()
288
+	{
289
+		return '<div class="ee-event-expired-notice"><span class="important-notice">' . esc_html__(
290
+			'We\'re sorry, but all tickets sales have ended because the event is expired.',
291
+			'event_espresso'
292
+		) . '</span></div><!-- .ee-event-expired-notice -->';
293
+	}
294
+
295
+
296
+	/**
297
+	 * noTicketAvailableMessage
298
+	 * notice displayed if event has no more tickets available
299
+	 *
300
+	 * @return string
301
+	 * @throws EE_Error
302
+	 */
303
+	protected function noTicketAvailableMessage()
304
+	{
305
+		$no_ticket_available_msg = esc_html__('We\'re sorry, but all ticket sales have ended.', 'event_espresso');
306
+		if (current_user_can('edit_post', $this->event->ID())) {
307
+			$no_ticket_available_msg .= sprintf(
308
+				esc_html__(
309
+					'%1$sNote to Event Admin:%2$sNo tickets were found for this event. This effectively turns off ticket sales. Please ensure that at least one ticket is available for if you want people to be able to register.%3$s(click to edit this event)%4$s',
310
+					'event_espresso'
311
+				),
312
+				'<div class="ee-attention" style="text-align: left;"><b>',
313
+				'</b><br />',
314
+				'<span class="edit-link"><a class="post-edit-link" href="'
315
+				. get_edit_post_link($this->event->ID())
316
+				. '">',
317
+				'</a></span></div><!-- .ee-attention noTicketAvailableMessage -->'
318
+			);
319
+		}
320
+		return '
321 321
             <div class="ee-event-expired-notice">
322 322
                 <span class="important-notice">' . $no_ticket_available_msg . '</span>
323 323
             </div><!-- .ee-event-expired-notice -->';
324
-    }
325
-
326
-
327
-    /**
328
-     * ticketSalesClosed
329
-     * notice displayed if event ticket sales are turned off
330
-     *
331
-     * @return string
332
-     * @throws EE_Error
333
-     */
334
-    protected function ticketSalesClosedMessage()
335
-    {
336
-        $sales_closed_msg = esc_html__(
337
-            'We\'re sorry, but ticket sales have been closed at this time. Please check back again later.',
338
-            'event_espresso'
339
-        );
340
-        if (current_user_can('edit_post', $this->event->ID())) {
341
-            $sales_closed_msg .= sprintf(
342
-                esc_html__(
343
-                    '%sNote to Event Admin:%sThe "Maximum number of tickets allowed per order for this event" in the Event Registration Options has been set to "0". This effectively turns off ticket sales. %s(click to edit this event)%s',
344
-                    'event_espresso'
345
-                ),
346
-                '<div class="ee-attention" style="text-align: left;"><b>',
347
-                '</b><br />',
348
-                '<span class="edit-link"><a class="post-edit-link" href="'
349
-                . get_edit_post_link($this->event->ID())
350
-                . '">',
351
-                '</a></span></div><!-- .ee-attention ticketSalesClosedMessage -->'
352
-            );
353
-        }
354
-        return '<p><span class="important-notice">' . $sales_closed_msg . '</span></p>';
355
-    }
356
-
357
-
358
-    /**
359
-     * getTickets
360
-     *
361
-     * @return \EE_Base_Class[]|\EE_Ticket[]
362
-     * @throws EE_Error
363
-     * @throws InvalidDataTypeException
364
-     * @throws InvalidInterfaceException
365
-     * @throws InvalidArgumentException
366
-     */
367
-    protected function getTickets()
368
-    {
369
-        $show_expired_tickets = is_admin() || (
370
-            EE_Registry::instance()->CFG->template_settings->EED_Ticket_Selector instanceof EE_Ticket_Selector_Config
371
-            && EE_Registry::instance()->CFG->template_settings->EED_Ticket_Selector->show_expired_tickets
372
-        );
373
-
374
-        $ticket_query_args = array(
375
-            array('Datetime.EVT_ID' => $this->event->ID()),
376
-            'order_by' => array(
377
-                'TKT_order'              => 'ASC',
378
-                'TKT_required'           => 'DESC',
379
-                'TKT_start_date'         => 'ASC',
380
-                'TKT_end_date'           => 'ASC',
381
-                'Datetime.DTT_EVT_start' => 'DESC',
382
-            ),
383
-        );
384
-        if (! $show_expired_tickets) {
385
-            // use the correct applicable time query depending on what version of core is being run.
386
-            $current_time = method_exists('EEM_Datetime', 'current_time_for_query')
387
-                ? time()
388
-                : current_time('timestamp');
389
-            $ticket_query_args[0]['TKT_end_date'] = array('>', $current_time);
390
-        }
391
-        return EEM_Ticket::instance()->get_all($ticket_query_args);
392
-    }
393
-
394
-
395
-    /**
396
-     * loadTicketSelector
397
-     * begins to assemble template arguments
398
-     * and decides whether to load a "simple" ticket selector, or the standard
399
-     *
400
-     * @param \EE_Ticket[] $tickets
401
-     * @param array        $template_args
402
-     * @return string
403
-     * @throws EE_Error
404
-     */
405
-    protected function loadTicketSelector(array $tickets, array $template_args)
406
-    {
407
-        $template_args['event'] = $this->event;
408
-        $template_args['EVT_ID'] = $this->event->ID();
409
-        $template_args['event_is_expired'] = $this->event->is_expired();
410
-        $template_args['max_atndz'] = $this->getMaxAttendees();
411
-        $template_args['date_format'] = $this->date_format;
412
-        $template_args['time_format'] = $this->time_format;
413
-        /**
414
-         * Filters the anchor ID used when redirecting to the Ticket Selector if no quantity selected
415
-         *
416
-         * @since 4.9.13
417
-         * @param     string  '#tkt-slctr-tbl-' . $EVT_ID The html ID to anchor to
418
-         * @param int $EVT_ID The Event ID
419
-         */
420
-        $template_args['anchor_id'] = apply_filters(
421
-            'FHEE__EE_Ticket_Selector__redirect_anchor_id',
422
-            '#tkt-slctr-tbl-' . $this->event->ID(),
423
-            $this->event->ID()
424
-        );
425
-        $template_args['tickets'] = $tickets;
426
-        $template_args['ticket_count'] = count($tickets);
427
-        $ticket_selector = $this->simpleTicketSelector($tickets, $template_args);
428
-        return $ticket_selector instanceof TicketSelectorSimple
429
-            ? $ticket_selector
430
-            : new TicketSelectorStandard(
431
-                $this->event,
432
-                $tickets,
433
-                $this->getMaxAttendees(),
434
-                $template_args,
435
-                $this->date_format,
436
-                $this->time_format
437
-            );
438
-    }
439
-
440
-
441
-    /**
442
-     * simpleTicketSelector
443
-     * there's one ticket, and max attendees is set to one,
444
-     * so if the event is free, then this is a "simple" ticket selector
445
-     * a.k.a. "Dude Where's my Ticket Selector?"
446
-     *
447
-     * @param \EE_Ticket[] $tickets
448
-     * @param array        $template_args
449
-     * @return string
450
-     * @throws EE_Error
451
-     */
452
-    protected function simpleTicketSelector($tickets, array $template_args)
453
-    {
454
-        // if there is only ONE ticket with a max qty of ONE
455
-        if (count($tickets) > 1 || $this->getMaxAttendees() !== 1) {
456
-            return '';
457
-        }
458
-        /** @var \EE_Ticket $ticket */
459
-        $ticket = reset($tickets);
460
-        // if the ticket is free... then not much need for the ticket selector
461
-        if (apply_filters(
462
-            'FHEE__ticket_selector_chart_template__hide_ticket_selector',
463
-            $ticket->is_free(),
464
-            $this->event->ID()
465
-        )) {
466
-            return new TicketSelectorSimple(
467
-                $this->event,
468
-                $ticket,
469
-                $this->getMaxAttendees(),
470
-                $template_args
471
-            );
472
-        }
473
-        return '';
474
-    }
475
-
476
-
477
-    /**
478
-     * externalEventRegistration
479
-     *
480
-     * @return string
481
-     */
482
-    public function externalEventRegistration()
483
-    {
484
-        // if not we still need to trigger the display of the submit button
485
-        add_filter('FHEE__EE_Ticket_Selector__display_ticket_selector_submit', '__return_true');
486
-        // display notice to admin that registration is external
487
-        return $this->display_full_ui()
488
-            ? esc_html__(
489
-                'Registration is at an external URL for this event.',
490
-                'event_espresso'
491
-            )
492
-            : '';
493
-    }
494
-
495
-
496
-    /**
497
-     * formOpen
498
-     *
499
-     * @param        int    $ID
500
-     * @param        string $external_url
501
-     * @return        string
502
-     */
503
-    public function formOpen($ID = 0, $external_url = '')
504
-    {
505
-        // if redirecting, we don't need any anything else
506
-        if ($external_url) {
507
-            $html = '<form method="GET" ';
508
-            $html .= 'action="' . EEH_URL::refactor_url($external_url) . '" ';
509
-            $html .= 'name="ticket-selector-form-' . $ID . '"';
510
-            // open link in new window ?
511
-            $html .= apply_filters(
512
-                'FHEE__EventEspresso_modules_ticket_selector_DisplayTicketSelector__formOpen__external_url_target_blank',
513
-                $this->isIframe(),
514
-                $this
515
-            )
516
-                ? ' target="_blank"'
517
-                : '';
518
-            $html .= '>';
519
-            $query_args = EEH_URL::get_query_string($external_url);
520
-            foreach ((array) $query_args as $query_arg => $value) {
521
-                $html .= '<input type="hidden" name="' . $query_arg . '" value="' . $value . '">';
522
-            }
523
-            return $html;
524
-        }
525
-        // if there is no submit button, then don't start building a form
526
-        // because the "View Details" button will build its own form
527
-        if (! apply_filters('FHEE__EE_Ticket_Selector__display_ticket_selector_submit', false)) {
528
-            return '';
529
-        }
530
-        $checkout_url = EEH_Event_View::event_link_url($ID);
531
-        if (! $checkout_url) {
532
-            EE_Error::add_error(
533
-                esc_html__('The URL for the Event Details page could not be retrieved.', 'event_espresso'),
534
-                __FILE__,
535
-                __FUNCTION__,
536
-                __LINE__
537
-            );
538
-        }
539
-        // set no cache headers and constants
540
-        EE_System::do_not_cache();
541
-        $html = '<form method="POST" ';
542
-        $html .= 'action="' . $checkout_url . '" ';
543
-        $html .= 'name="ticket-selector-form-' . $ID . '"';
544
-        $html .= $this->iframe ? ' target="_blank"' : '';
545
-        $html .= '>';
546
-        $html .= '<input type="hidden" name="ee" value="process_ticket_selections">';
547
-        $html = apply_filters('FHEE__EE_Ticket_Selector__ticket_selector_form_open__html', $html, $this->event);
548
-        return $html;
549
-    }
550
-
551
-
552
-    /**
553
-     * displaySubmitButton
554
-     *
555
-     * @param  string $external_url
556
-     * @return string
557
-     * @throws EE_Error
558
-     */
559
-    public function displaySubmitButton($external_url = '')
560
-    {
561
-        $html = '';
562
-        if ($this->display_full_ui()) {
563
-            // standard TS displayed with submit button, ie: "Register Now"
564
-            if (apply_filters('FHEE__EE_Ticket_Selector__display_ticket_selector_submit', false)) {
565
-                $html .= $this->displayRegisterNowButton();
566
-                $html .= empty($external_url)
567
-                    ? $this->ticketSelectorEndDiv()
568
-                    : $this->clearTicketSelector();
569
-                $html .= '<br/>' . $this->formClose();
570
-            } elseif ($this->getMaxAttendees() === 1) {
571
-                // its a "Dude Where's my Ticket Selector?" (DWMTS) type event (ie: $_max_atndz === 1)
572
-                if ($this->event->is_sold_out()) {
573
-                    // then instead of a View Details or Submit button, just display a "Sold Out" message
574
-                    $html .= apply_filters(
575
-                        'FHEE__EE_Ticket_Selector__display_ticket_selector_submit__sold_out_msg',
576
-                        sprintf(
577
-                            __(
578
-                                '%1$s"%2$s" is currently sold out.%4$sPlease check back again later, as spots may become available.%3$s',
579
-                                'event_espresso'
580
-                            ),
581
-                            '<p class="no-ticket-selector-msg clear-float">',
582
-                            $this->event->name(),
583
-                            '</p>',
584
-                            '<br />'
585
-                        ),
586
-                        $this->event
587
-                    );
588
-                    if (apply_filters(
589
-                        'FHEE__EE_Ticket_Selector__display_ticket_selector_submit__no_tickets_but_display_register_now_button',
590
-                        false,
591
-                        $this->event
592
-                    )) {
593
-                        $html .= $this->displayRegisterNowButton();
594
-                    }
595
-                    // sold out DWMTS event, no TS, no submit or view details button, but has additional content
596
-                    $html .= $this->ticketSelectorEndDiv();
597
-                } elseif (apply_filters('FHEE__EE_Ticket_Selector__hide_ticket_selector', false)
598
-                          && ! is_single()
599
-                ) {
600
-                    // this is a "Dude Where's my Ticket Selector?" (DWMTS) type event,
601
-                    // but no tickets are available, so display event's "View Details" button.
602
-                    // it is being viewed via somewhere other than a single post
603
-                    $html .= $this->displayViewDetailsButton(true);
604
-                } else {
605
-                    $html .= $this->ticketSelectorEndDiv();
606
-                }
607
-            } elseif (is_archive()) {
608
-                // event list, no tickets available so display event's "View Details" button
609
-                $html .= $this->ticketSelectorEndDiv();
610
-                $html .= $this->displayViewDetailsButton();
611
-            } else {
612
-                if (apply_filters(
613
-                    'FHEE__EE_Ticket_Selector__display_ticket_selector_submit__no_tickets_but_display_register_now_button',
614
-                    false,
615
-                    $this->event
616
-                )) {
617
-                    $html .= $this->displayRegisterNowButton();
618
-                }
619
-                // no submit or view details button, and no additional content
620
-                $html .= $this->ticketSelectorEndDiv();
621
-            }
622
-            if (! $this->iframe && ! is_archive()) {
623
-                $html .= EEH_Template::powered_by_event_espresso('', '', array('utm_content' => 'ticket_selector'));
624
-            }
625
-        }
626
-        return apply_filters(
627
-            'FHEE__EventEspresso_modules_ticket_selector_DisplayTicketSelector__displaySubmitButton__html',
628
-            $html,
629
-            $this->event,
630
-            $this
631
-        );
632
-    }
633
-
634
-
635
-    /**
636
-     * @return string
637
-     * @throws EE_Error
638
-     */
639
-    public function displayRegisterNowButton()
640
-    {
641
-        $btn_text = apply_filters(
642
-            'FHEE__EE_Ticket_Selector__display_ticket_selector_submit__btn_text',
643
-            __('Register Now', 'event_espresso'),
644
-            $this->event
645
-        );
646
-        $external_url = (string) $this->event->external_url()
647
-            && $this->event->external_url() !== get_the_permalink()
648
-            ? $this->event->external_url()
649
-            : '';
650
-        $html = EEH_HTML::div(
651
-            '',
652
-            'ticket-selector-submit-' . $this->event->ID() . '-btn-wrap',
653
-            'ticket-selector-submit-btn-wrap'
654
-        );
655
-        $html .= '<input id="ticket-selector-submit-' . $this->event->ID() . '-btn"';
656
-        $html .= ' class="ticket-selector-submit-btn ';
657
-        $html .= empty($external_url) ? 'ticket-selector-submit-ajax"' : '"';
658
-        $html .= ' type="submit" value="' . $btn_text . '" data-ee-disable-after-recaptcha="true" />';
659
-        $html .= EEH_HTML::divx() . '<!-- .ticket-selector-submit-btn-wrap -->';
660
-        $html .= apply_filters(
661
-            'FHEE__EE_Ticket_Selector__after_ticket_selector_submit',
662
-            '',
663
-            $this->event,
664
-            $this->iframe
665
-        );
666
-        return $html;
667
-    }
668
-
669
-
670
-    /**
671
-     * displayViewDetailsButton
672
-     *
673
-     * @param bool $DWMTS indicates a "Dude Where's my Ticket Selector?" (DWMTS) type event
674
-     *                    (ie: $_max_atndz === 1) where there are no available tickets,
675
-     *                    either because they are sold out, expired, or not yet on sale.
676
-     *                    In this case, we need to close the form BEFORE adding any closing divs
677
-     * @return string
678
-     * @throws EE_Error
679
-     */
680
-    public function displayViewDetailsButton($DWMTS = false)
681
-    {
682
-        if (! $this->event->get_permalink()) {
683
-            EE_Error::add_error(
684
-                esc_html__('The URL for the Event Details page could not be retrieved.', 'event_espresso'),
685
-                __FILE__,
686
-                __FUNCTION__,
687
-                __LINE__
688
-            );
689
-        }
690
-        $view_details_btn = '<form method="GET" action="';
691
-        $view_details_btn .= apply_filters(
692
-            'FHEE__EE_Ticket_Selector__display_view_details_btn__btn_url',
693
-            $this->event->get_permalink(),
694
-            $this->event
695
-        );
696
-        $view_details_btn .= '"';
697
-        // open link in new window ?
698
-        $view_details_btn .= apply_filters(
699
-            'FHEE__EventEspresso_modules_ticket_selector_DisplayTicketSelector__displayViewDetailsButton__url_target_blank',
700
-            $this->isIframe(),
701
-            $this
702
-        )
703
-            ? ' target="_blank"'
704
-            : '';
705
-        $view_details_btn .= '>';
706
-        $btn_text = apply_filters(
707
-            'FHEE__EE_Ticket_Selector__display_view_details_btn__btn_text',
708
-            esc_html__('View Details', 'event_espresso'),
709
-            $this->event
710
-        );
711
-        $view_details_btn .= '<input id="ticket-selector-submit-'
712
-                             . $this->event->ID()
713
-                             . '-btn" class="ticket-selector-submit-btn view-details-btn" type="submit" value="'
714
-                             . $btn_text
715
-                             . '" />';
716
-        $view_details_btn .= apply_filters('FHEE__EE_Ticket_Selector__after_view_details_btn', '', $this->event);
717
-        if ($DWMTS) {
718
-            $view_details_btn .= $this->formClose();
719
-            $view_details_btn .= $this->ticketSelectorEndDiv();
720
-            $view_details_btn .= '<br/>';
721
-        } else {
722
-            $view_details_btn .= $this->clearTicketSelector();
723
-            $view_details_btn .= '<br/>';
724
-            $view_details_btn .= $this->formClose();
725
-        }
726
-        return $view_details_btn;
727
-    }
728
-
729
-
730
-    /**
731
-     * @return string
732
-     */
733
-    public function ticketSelectorEndDiv()
734
-    {
735
-        return $this->clearTicketSelector() . '</div><!-- ticketSelectorEndDiv -->';
736
-    }
737
-
738
-
739
-    /**
740
-     * @return string
741
-     */
742
-    public function clearTicketSelector()
743
-    {
744
-        // standard TS displayed, appears after a "Register Now" or "view Details" button
745
-        return '<div class="clear"></div><!-- clearTicketSelector -->';
746
-    }
747
-
748
-
749
-    /**
750
-     * @access        public
751
-     * @return        string
752
-     */
753
-    public function formClose()
754
-    {
755
-        return '</form>';
756
-    }
324
+	}
325
+
326
+
327
+	/**
328
+	 * ticketSalesClosed
329
+	 * notice displayed if event ticket sales are turned off
330
+	 *
331
+	 * @return string
332
+	 * @throws EE_Error
333
+	 */
334
+	protected function ticketSalesClosedMessage()
335
+	{
336
+		$sales_closed_msg = esc_html__(
337
+			'We\'re sorry, but ticket sales have been closed at this time. Please check back again later.',
338
+			'event_espresso'
339
+		);
340
+		if (current_user_can('edit_post', $this->event->ID())) {
341
+			$sales_closed_msg .= sprintf(
342
+				esc_html__(
343
+					'%sNote to Event Admin:%sThe "Maximum number of tickets allowed per order for this event" in the Event Registration Options has been set to "0". This effectively turns off ticket sales. %s(click to edit this event)%s',
344
+					'event_espresso'
345
+				),
346
+				'<div class="ee-attention" style="text-align: left;"><b>',
347
+				'</b><br />',
348
+				'<span class="edit-link"><a class="post-edit-link" href="'
349
+				. get_edit_post_link($this->event->ID())
350
+				. '">',
351
+				'</a></span></div><!-- .ee-attention ticketSalesClosedMessage -->'
352
+			);
353
+		}
354
+		return '<p><span class="important-notice">' . $sales_closed_msg . '</span></p>';
355
+	}
356
+
357
+
358
+	/**
359
+	 * getTickets
360
+	 *
361
+	 * @return \EE_Base_Class[]|\EE_Ticket[]
362
+	 * @throws EE_Error
363
+	 * @throws InvalidDataTypeException
364
+	 * @throws InvalidInterfaceException
365
+	 * @throws InvalidArgumentException
366
+	 */
367
+	protected function getTickets()
368
+	{
369
+		$show_expired_tickets = is_admin() || (
370
+			EE_Registry::instance()->CFG->template_settings->EED_Ticket_Selector instanceof EE_Ticket_Selector_Config
371
+			&& EE_Registry::instance()->CFG->template_settings->EED_Ticket_Selector->show_expired_tickets
372
+		);
373
+
374
+		$ticket_query_args = array(
375
+			array('Datetime.EVT_ID' => $this->event->ID()),
376
+			'order_by' => array(
377
+				'TKT_order'              => 'ASC',
378
+				'TKT_required'           => 'DESC',
379
+				'TKT_start_date'         => 'ASC',
380
+				'TKT_end_date'           => 'ASC',
381
+				'Datetime.DTT_EVT_start' => 'DESC',
382
+			),
383
+		);
384
+		if (! $show_expired_tickets) {
385
+			// use the correct applicable time query depending on what version of core is being run.
386
+			$current_time = method_exists('EEM_Datetime', 'current_time_for_query')
387
+				? time()
388
+				: current_time('timestamp');
389
+			$ticket_query_args[0]['TKT_end_date'] = array('>', $current_time);
390
+		}
391
+		return EEM_Ticket::instance()->get_all($ticket_query_args);
392
+	}
393
+
394
+
395
+	/**
396
+	 * loadTicketSelector
397
+	 * begins to assemble template arguments
398
+	 * and decides whether to load a "simple" ticket selector, or the standard
399
+	 *
400
+	 * @param \EE_Ticket[] $tickets
401
+	 * @param array        $template_args
402
+	 * @return string
403
+	 * @throws EE_Error
404
+	 */
405
+	protected function loadTicketSelector(array $tickets, array $template_args)
406
+	{
407
+		$template_args['event'] = $this->event;
408
+		$template_args['EVT_ID'] = $this->event->ID();
409
+		$template_args['event_is_expired'] = $this->event->is_expired();
410
+		$template_args['max_atndz'] = $this->getMaxAttendees();
411
+		$template_args['date_format'] = $this->date_format;
412
+		$template_args['time_format'] = $this->time_format;
413
+		/**
414
+		 * Filters the anchor ID used when redirecting to the Ticket Selector if no quantity selected
415
+		 *
416
+		 * @since 4.9.13
417
+		 * @param     string  '#tkt-slctr-tbl-' . $EVT_ID The html ID to anchor to
418
+		 * @param int $EVT_ID The Event ID
419
+		 */
420
+		$template_args['anchor_id'] = apply_filters(
421
+			'FHEE__EE_Ticket_Selector__redirect_anchor_id',
422
+			'#tkt-slctr-tbl-' . $this->event->ID(),
423
+			$this->event->ID()
424
+		);
425
+		$template_args['tickets'] = $tickets;
426
+		$template_args['ticket_count'] = count($tickets);
427
+		$ticket_selector = $this->simpleTicketSelector($tickets, $template_args);
428
+		return $ticket_selector instanceof TicketSelectorSimple
429
+			? $ticket_selector
430
+			: new TicketSelectorStandard(
431
+				$this->event,
432
+				$tickets,
433
+				$this->getMaxAttendees(),
434
+				$template_args,
435
+				$this->date_format,
436
+				$this->time_format
437
+			);
438
+	}
439
+
440
+
441
+	/**
442
+	 * simpleTicketSelector
443
+	 * there's one ticket, and max attendees is set to one,
444
+	 * so if the event is free, then this is a "simple" ticket selector
445
+	 * a.k.a. "Dude Where's my Ticket Selector?"
446
+	 *
447
+	 * @param \EE_Ticket[] $tickets
448
+	 * @param array        $template_args
449
+	 * @return string
450
+	 * @throws EE_Error
451
+	 */
452
+	protected function simpleTicketSelector($tickets, array $template_args)
453
+	{
454
+		// if there is only ONE ticket with a max qty of ONE
455
+		if (count($tickets) > 1 || $this->getMaxAttendees() !== 1) {
456
+			return '';
457
+		}
458
+		/** @var \EE_Ticket $ticket */
459
+		$ticket = reset($tickets);
460
+		// if the ticket is free... then not much need for the ticket selector
461
+		if (apply_filters(
462
+			'FHEE__ticket_selector_chart_template__hide_ticket_selector',
463
+			$ticket->is_free(),
464
+			$this->event->ID()
465
+		)) {
466
+			return new TicketSelectorSimple(
467
+				$this->event,
468
+				$ticket,
469
+				$this->getMaxAttendees(),
470
+				$template_args
471
+			);
472
+		}
473
+		return '';
474
+	}
475
+
476
+
477
+	/**
478
+	 * externalEventRegistration
479
+	 *
480
+	 * @return string
481
+	 */
482
+	public function externalEventRegistration()
483
+	{
484
+		// if not we still need to trigger the display of the submit button
485
+		add_filter('FHEE__EE_Ticket_Selector__display_ticket_selector_submit', '__return_true');
486
+		// display notice to admin that registration is external
487
+		return $this->display_full_ui()
488
+			? esc_html__(
489
+				'Registration is at an external URL for this event.',
490
+				'event_espresso'
491
+			)
492
+			: '';
493
+	}
494
+
495
+
496
+	/**
497
+	 * formOpen
498
+	 *
499
+	 * @param        int    $ID
500
+	 * @param        string $external_url
501
+	 * @return        string
502
+	 */
503
+	public function formOpen($ID = 0, $external_url = '')
504
+	{
505
+		// if redirecting, we don't need any anything else
506
+		if ($external_url) {
507
+			$html = '<form method="GET" ';
508
+			$html .= 'action="' . EEH_URL::refactor_url($external_url) . '" ';
509
+			$html .= 'name="ticket-selector-form-' . $ID . '"';
510
+			// open link in new window ?
511
+			$html .= apply_filters(
512
+				'FHEE__EventEspresso_modules_ticket_selector_DisplayTicketSelector__formOpen__external_url_target_blank',
513
+				$this->isIframe(),
514
+				$this
515
+			)
516
+				? ' target="_blank"'
517
+				: '';
518
+			$html .= '>';
519
+			$query_args = EEH_URL::get_query_string($external_url);
520
+			foreach ((array) $query_args as $query_arg => $value) {
521
+				$html .= '<input type="hidden" name="' . $query_arg . '" value="' . $value . '">';
522
+			}
523
+			return $html;
524
+		}
525
+		// if there is no submit button, then don't start building a form
526
+		// because the "View Details" button will build its own form
527
+		if (! apply_filters('FHEE__EE_Ticket_Selector__display_ticket_selector_submit', false)) {
528
+			return '';
529
+		}
530
+		$checkout_url = EEH_Event_View::event_link_url($ID);
531
+		if (! $checkout_url) {
532
+			EE_Error::add_error(
533
+				esc_html__('The URL for the Event Details page could not be retrieved.', 'event_espresso'),
534
+				__FILE__,
535
+				__FUNCTION__,
536
+				__LINE__
537
+			);
538
+		}
539
+		// set no cache headers and constants
540
+		EE_System::do_not_cache();
541
+		$html = '<form method="POST" ';
542
+		$html .= 'action="' . $checkout_url . '" ';
543
+		$html .= 'name="ticket-selector-form-' . $ID . '"';
544
+		$html .= $this->iframe ? ' target="_blank"' : '';
545
+		$html .= '>';
546
+		$html .= '<input type="hidden" name="ee" value="process_ticket_selections">';
547
+		$html = apply_filters('FHEE__EE_Ticket_Selector__ticket_selector_form_open__html', $html, $this->event);
548
+		return $html;
549
+	}
550
+
551
+
552
+	/**
553
+	 * displaySubmitButton
554
+	 *
555
+	 * @param  string $external_url
556
+	 * @return string
557
+	 * @throws EE_Error
558
+	 */
559
+	public function displaySubmitButton($external_url = '')
560
+	{
561
+		$html = '';
562
+		if ($this->display_full_ui()) {
563
+			// standard TS displayed with submit button, ie: "Register Now"
564
+			if (apply_filters('FHEE__EE_Ticket_Selector__display_ticket_selector_submit', false)) {
565
+				$html .= $this->displayRegisterNowButton();
566
+				$html .= empty($external_url)
567
+					? $this->ticketSelectorEndDiv()
568
+					: $this->clearTicketSelector();
569
+				$html .= '<br/>' . $this->formClose();
570
+			} elseif ($this->getMaxAttendees() === 1) {
571
+				// its a "Dude Where's my Ticket Selector?" (DWMTS) type event (ie: $_max_atndz === 1)
572
+				if ($this->event->is_sold_out()) {
573
+					// then instead of a View Details or Submit button, just display a "Sold Out" message
574
+					$html .= apply_filters(
575
+						'FHEE__EE_Ticket_Selector__display_ticket_selector_submit__sold_out_msg',
576
+						sprintf(
577
+							__(
578
+								'%1$s"%2$s" is currently sold out.%4$sPlease check back again later, as spots may become available.%3$s',
579
+								'event_espresso'
580
+							),
581
+							'<p class="no-ticket-selector-msg clear-float">',
582
+							$this->event->name(),
583
+							'</p>',
584
+							'<br />'
585
+						),
586
+						$this->event
587
+					);
588
+					if (apply_filters(
589
+						'FHEE__EE_Ticket_Selector__display_ticket_selector_submit__no_tickets_but_display_register_now_button',
590
+						false,
591
+						$this->event
592
+					)) {
593
+						$html .= $this->displayRegisterNowButton();
594
+					}
595
+					// sold out DWMTS event, no TS, no submit or view details button, but has additional content
596
+					$html .= $this->ticketSelectorEndDiv();
597
+				} elseif (apply_filters('FHEE__EE_Ticket_Selector__hide_ticket_selector', false)
598
+						  && ! is_single()
599
+				) {
600
+					// this is a "Dude Where's my Ticket Selector?" (DWMTS) type event,
601
+					// but no tickets are available, so display event's "View Details" button.
602
+					// it is being viewed via somewhere other than a single post
603
+					$html .= $this->displayViewDetailsButton(true);
604
+				} else {
605
+					$html .= $this->ticketSelectorEndDiv();
606
+				}
607
+			} elseif (is_archive()) {
608
+				// event list, no tickets available so display event's "View Details" button
609
+				$html .= $this->ticketSelectorEndDiv();
610
+				$html .= $this->displayViewDetailsButton();
611
+			} else {
612
+				if (apply_filters(
613
+					'FHEE__EE_Ticket_Selector__display_ticket_selector_submit__no_tickets_but_display_register_now_button',
614
+					false,
615
+					$this->event
616
+				)) {
617
+					$html .= $this->displayRegisterNowButton();
618
+				}
619
+				// no submit or view details button, and no additional content
620
+				$html .= $this->ticketSelectorEndDiv();
621
+			}
622
+			if (! $this->iframe && ! is_archive()) {
623
+				$html .= EEH_Template::powered_by_event_espresso('', '', array('utm_content' => 'ticket_selector'));
624
+			}
625
+		}
626
+		return apply_filters(
627
+			'FHEE__EventEspresso_modules_ticket_selector_DisplayTicketSelector__displaySubmitButton__html',
628
+			$html,
629
+			$this->event,
630
+			$this
631
+		);
632
+	}
633
+
634
+
635
+	/**
636
+	 * @return string
637
+	 * @throws EE_Error
638
+	 */
639
+	public function displayRegisterNowButton()
640
+	{
641
+		$btn_text = apply_filters(
642
+			'FHEE__EE_Ticket_Selector__display_ticket_selector_submit__btn_text',
643
+			__('Register Now', 'event_espresso'),
644
+			$this->event
645
+		);
646
+		$external_url = (string) $this->event->external_url()
647
+			&& $this->event->external_url() !== get_the_permalink()
648
+			? $this->event->external_url()
649
+			: '';
650
+		$html = EEH_HTML::div(
651
+			'',
652
+			'ticket-selector-submit-' . $this->event->ID() . '-btn-wrap',
653
+			'ticket-selector-submit-btn-wrap'
654
+		);
655
+		$html .= '<input id="ticket-selector-submit-' . $this->event->ID() . '-btn"';
656
+		$html .= ' class="ticket-selector-submit-btn ';
657
+		$html .= empty($external_url) ? 'ticket-selector-submit-ajax"' : '"';
658
+		$html .= ' type="submit" value="' . $btn_text . '" data-ee-disable-after-recaptcha="true" />';
659
+		$html .= EEH_HTML::divx() . '<!-- .ticket-selector-submit-btn-wrap -->';
660
+		$html .= apply_filters(
661
+			'FHEE__EE_Ticket_Selector__after_ticket_selector_submit',
662
+			'',
663
+			$this->event,
664
+			$this->iframe
665
+		);
666
+		return $html;
667
+	}
668
+
669
+
670
+	/**
671
+	 * displayViewDetailsButton
672
+	 *
673
+	 * @param bool $DWMTS indicates a "Dude Where's my Ticket Selector?" (DWMTS) type event
674
+	 *                    (ie: $_max_atndz === 1) where there are no available tickets,
675
+	 *                    either because they are sold out, expired, or not yet on sale.
676
+	 *                    In this case, we need to close the form BEFORE adding any closing divs
677
+	 * @return string
678
+	 * @throws EE_Error
679
+	 */
680
+	public function displayViewDetailsButton($DWMTS = false)
681
+	{
682
+		if (! $this->event->get_permalink()) {
683
+			EE_Error::add_error(
684
+				esc_html__('The URL for the Event Details page could not be retrieved.', 'event_espresso'),
685
+				__FILE__,
686
+				__FUNCTION__,
687
+				__LINE__
688
+			);
689
+		}
690
+		$view_details_btn = '<form method="GET" action="';
691
+		$view_details_btn .= apply_filters(
692
+			'FHEE__EE_Ticket_Selector__display_view_details_btn__btn_url',
693
+			$this->event->get_permalink(),
694
+			$this->event
695
+		);
696
+		$view_details_btn .= '"';
697
+		// open link in new window ?
698
+		$view_details_btn .= apply_filters(
699
+			'FHEE__EventEspresso_modules_ticket_selector_DisplayTicketSelector__displayViewDetailsButton__url_target_blank',
700
+			$this->isIframe(),
701
+			$this
702
+		)
703
+			? ' target="_blank"'
704
+			: '';
705
+		$view_details_btn .= '>';
706
+		$btn_text = apply_filters(
707
+			'FHEE__EE_Ticket_Selector__display_view_details_btn__btn_text',
708
+			esc_html__('View Details', 'event_espresso'),
709
+			$this->event
710
+		);
711
+		$view_details_btn .= '<input id="ticket-selector-submit-'
712
+							 . $this->event->ID()
713
+							 . '-btn" class="ticket-selector-submit-btn view-details-btn" type="submit" value="'
714
+							 . $btn_text
715
+							 . '" />';
716
+		$view_details_btn .= apply_filters('FHEE__EE_Ticket_Selector__after_view_details_btn', '', $this->event);
717
+		if ($DWMTS) {
718
+			$view_details_btn .= $this->formClose();
719
+			$view_details_btn .= $this->ticketSelectorEndDiv();
720
+			$view_details_btn .= '<br/>';
721
+		} else {
722
+			$view_details_btn .= $this->clearTicketSelector();
723
+			$view_details_btn .= '<br/>';
724
+			$view_details_btn .= $this->formClose();
725
+		}
726
+		return $view_details_btn;
727
+	}
728
+
729
+
730
+	/**
731
+	 * @return string
732
+	 */
733
+	public function ticketSelectorEndDiv()
734
+	{
735
+		return $this->clearTicketSelector() . '</div><!-- ticketSelectorEndDiv -->';
736
+	}
737
+
738
+
739
+	/**
740
+	 * @return string
741
+	 */
742
+	public function clearTicketSelector()
743
+	{
744
+		// standard TS displayed, appears after a "Register Now" or "view Details" button
745
+		return '<div class="clear"></div><!-- clearTicketSelector -->';
746
+	}
747
+
748
+
749
+	/**
750
+	 * @access        public
751
+	 * @return        string
752
+	 */
753
+	public function formClose()
754
+	{
755
+		return '</form>';
756
+	}
757 757
 }
Please login to merge, or discard this patch.
Spacing   +25 added lines, -25 removed lines patch added patch discarded remove patch
@@ -135,11 +135,11 @@  discard block
 block discarded – undo
135 135
             }
136 136
         } else {
137 137
             $user_msg = __('No Event object or an invalid Event object was supplied.', 'event_espresso');
138
-            $dev_msg = $user_msg . __(
138
+            $dev_msg = $user_msg.__(
139 139
                 'In order to generate a ticket selector, please ensure you are passing either an EE_Event object or a WP_Post object of the post type "espresso_event" to the EE_Ticket_Selector class constructor.',
140 140
                 'event_espresso'
141 141
             );
142
-            EE_Error::add_error($user_msg . '||' . $dev_msg, __FILE__, __FUNCTION__, __LINE__);
142
+            EE_Error::add_error($user_msg.'||'.$dev_msg, __FILE__, __FUNCTION__, __LINE__);
143 143
             return false;
144 144
         }
145 145
         return true;
@@ -200,7 +200,7 @@  discard block
 block discarded – undo
200 200
         // reset filter for displaying submit button
201 201
         remove_filter('FHEE__EE_Ticket_Selector__display_ticket_selector_submit', '__return_true');
202 202
         // poke and prod incoming event till it tells us what it is
203
-        if (! $this->setEvent($event)) {
203
+        if ( ! $this->setEvent($event)) {
204 204
             return false;
205 205
         }
206 206
         // is the event expired ?
@@ -238,7 +238,7 @@  discard block
 block discarded – undo
238 238
             : $this->loadTicketSelector($tickets, $template_args);
239 239
         // now set up the form (but not for the admin)
240 240
         $ticket_selector = $this->display_full_ui()
241
-            ? $this->formOpen($this->event->ID(), $external_url) . $ticket_selector
241
+            ? $this->formOpen($this->event->ID(), $external_url).$ticket_selector
242 242
             : $ticket_selector;
243 243
         // submit button and form close tag
244 244
         $ticket_selector .= $this->display_full_ui() ? $this->displaySubmitButton($external_url) : '';
@@ -286,10 +286,10 @@  discard block
 block discarded – undo
286 286
      */
287 287
     protected function expiredEventMessage()
288 288
     {
289
-        return '<div class="ee-event-expired-notice"><span class="important-notice">' . esc_html__(
289
+        return '<div class="ee-event-expired-notice"><span class="important-notice">'.esc_html__(
290 290
             'We\'re sorry, but all tickets sales have ended because the event is expired.',
291 291
             'event_espresso'
292
-        ) . '</span></div><!-- .ee-event-expired-notice -->';
292
+        ).'</span></div><!-- .ee-event-expired-notice -->';
293 293
     }
294 294
 
295 295
 
@@ -319,7 +319,7 @@  discard block
 block discarded – undo
319 319
         }
320 320
         return '
321 321
             <div class="ee-event-expired-notice">
322
-                <span class="important-notice">' . $no_ticket_available_msg . '</span>
322
+                <span class="important-notice">' . $no_ticket_available_msg.'</span>
323 323
             </div><!-- .ee-event-expired-notice -->';
324 324
     }
325 325
 
@@ -351,7 +351,7 @@  discard block
 block discarded – undo
351 351
                 '</a></span></div><!-- .ee-attention ticketSalesClosedMessage -->'
352 352
             );
353 353
         }
354
-        return '<p><span class="important-notice">' . $sales_closed_msg . '</span></p>';
354
+        return '<p><span class="important-notice">'.$sales_closed_msg.'</span></p>';
355 355
     }
356 356
 
357 357
 
@@ -381,7 +381,7 @@  discard block
 block discarded – undo
381 381
                 'Datetime.DTT_EVT_start' => 'DESC',
382 382
             ),
383 383
         );
384
-        if (! $show_expired_tickets) {
384
+        if ( ! $show_expired_tickets) {
385 385
             // use the correct applicable time query depending on what version of core is being run.
386 386
             $current_time = method_exists('EEM_Datetime', 'current_time_for_query')
387 387
                 ? time()
@@ -419,7 +419,7 @@  discard block
 block discarded – undo
419 419
          */
420 420
         $template_args['anchor_id'] = apply_filters(
421 421
             'FHEE__EE_Ticket_Selector__redirect_anchor_id',
422
-            '#tkt-slctr-tbl-' . $this->event->ID(),
422
+            '#tkt-slctr-tbl-'.$this->event->ID(),
423 423
             $this->event->ID()
424 424
         );
425 425
         $template_args['tickets'] = $tickets;
@@ -505,8 +505,8 @@  discard block
 block discarded – undo
505 505
         // if redirecting, we don't need any anything else
506 506
         if ($external_url) {
507 507
             $html = '<form method="GET" ';
508
-            $html .= 'action="' . EEH_URL::refactor_url($external_url) . '" ';
509
-            $html .= 'name="ticket-selector-form-' . $ID . '"';
508
+            $html .= 'action="'.EEH_URL::refactor_url($external_url).'" ';
509
+            $html .= 'name="ticket-selector-form-'.$ID.'"';
510 510
             // open link in new window ?
511 511
             $html .= apply_filters(
512 512
                 'FHEE__EventEspresso_modules_ticket_selector_DisplayTicketSelector__formOpen__external_url_target_blank',
@@ -518,17 +518,17 @@  discard block
 block discarded – undo
518 518
             $html .= '>';
519 519
             $query_args = EEH_URL::get_query_string($external_url);
520 520
             foreach ((array) $query_args as $query_arg => $value) {
521
-                $html .= '<input type="hidden" name="' . $query_arg . '" value="' . $value . '">';
521
+                $html .= '<input type="hidden" name="'.$query_arg.'" value="'.$value.'">';
522 522
             }
523 523
             return $html;
524 524
         }
525 525
         // if there is no submit button, then don't start building a form
526 526
         // because the "View Details" button will build its own form
527
-        if (! apply_filters('FHEE__EE_Ticket_Selector__display_ticket_selector_submit', false)) {
527
+        if ( ! apply_filters('FHEE__EE_Ticket_Selector__display_ticket_selector_submit', false)) {
528 528
             return '';
529 529
         }
530 530
         $checkout_url = EEH_Event_View::event_link_url($ID);
531
-        if (! $checkout_url) {
531
+        if ( ! $checkout_url) {
532 532
             EE_Error::add_error(
533 533
                 esc_html__('The URL for the Event Details page could not be retrieved.', 'event_espresso'),
534 534
                 __FILE__,
@@ -539,8 +539,8 @@  discard block
 block discarded – undo
539 539
         // set no cache headers and constants
540 540
         EE_System::do_not_cache();
541 541
         $html = '<form method="POST" ';
542
-        $html .= 'action="' . $checkout_url . '" ';
543
-        $html .= 'name="ticket-selector-form-' . $ID . '"';
542
+        $html .= 'action="'.$checkout_url.'" ';
543
+        $html .= 'name="ticket-selector-form-'.$ID.'"';
544 544
         $html .= $this->iframe ? ' target="_blank"' : '';
545 545
         $html .= '>';
546 546
         $html .= '<input type="hidden" name="ee" value="process_ticket_selections">';
@@ -566,7 +566,7 @@  discard block
 block discarded – undo
566 566
                 $html .= empty($external_url)
567 567
                     ? $this->ticketSelectorEndDiv()
568 568
                     : $this->clearTicketSelector();
569
-                $html .= '<br/>' . $this->formClose();
569
+                $html .= '<br/>'.$this->formClose();
570 570
             } elseif ($this->getMaxAttendees() === 1) {
571 571
                 // its a "Dude Where's my Ticket Selector?" (DWMTS) type event (ie: $_max_atndz === 1)
572 572
                 if ($this->event->is_sold_out()) {
@@ -619,7 +619,7 @@  discard block
 block discarded – undo
619 619
                 // no submit or view details button, and no additional content
620 620
                 $html .= $this->ticketSelectorEndDiv();
621 621
             }
622
-            if (! $this->iframe && ! is_archive()) {
622
+            if ( ! $this->iframe && ! is_archive()) {
623 623
                 $html .= EEH_Template::powered_by_event_espresso('', '', array('utm_content' => 'ticket_selector'));
624 624
             }
625 625
         }
@@ -649,14 +649,14 @@  discard block
 block discarded – undo
649 649
             : '';
650 650
         $html = EEH_HTML::div(
651 651
             '',
652
-            'ticket-selector-submit-' . $this->event->ID() . '-btn-wrap',
652
+            'ticket-selector-submit-'.$this->event->ID().'-btn-wrap',
653 653
             'ticket-selector-submit-btn-wrap'
654 654
         );
655
-        $html .= '<input id="ticket-selector-submit-' . $this->event->ID() . '-btn"';
655
+        $html .= '<input id="ticket-selector-submit-'.$this->event->ID().'-btn"';
656 656
         $html .= ' class="ticket-selector-submit-btn ';
657 657
         $html .= empty($external_url) ? 'ticket-selector-submit-ajax"' : '"';
658
-        $html .= ' type="submit" value="' . $btn_text . '" data-ee-disable-after-recaptcha="true" />';
659
-        $html .= EEH_HTML::divx() . '<!-- .ticket-selector-submit-btn-wrap -->';
658
+        $html .= ' type="submit" value="'.$btn_text.'" data-ee-disable-after-recaptcha="true" />';
659
+        $html .= EEH_HTML::divx().'<!-- .ticket-selector-submit-btn-wrap -->';
660 660
         $html .= apply_filters(
661 661
             'FHEE__EE_Ticket_Selector__after_ticket_selector_submit',
662 662
             '',
@@ -679,7 +679,7 @@  discard block
 block discarded – undo
679 679
      */
680 680
     public function displayViewDetailsButton($DWMTS = false)
681 681
     {
682
-        if (! $this->event->get_permalink()) {
682
+        if ( ! $this->event->get_permalink()) {
683 683
             EE_Error::add_error(
684 684
                 esc_html__('The URL for the Event Details page could not be retrieved.', 'event_espresso'),
685 685
                 __FILE__,
@@ -732,7 +732,7 @@  discard block
 block discarded – undo
732 732
      */
733 733
     public function ticketSelectorEndDiv()
734 734
     {
735
-        return $this->clearTicketSelector() . '</div><!-- ticketSelectorEndDiv -->';
735
+        return $this->clearTicketSelector().'</div><!-- ticketSelectorEndDiv -->';
736 736
     }
737 737
 
738 738
 
Please login to merge, or discard this patch.