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