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