Completed
Branch FET-8385-datetime-ticket-selec... (04c1c3)
by
unknown
107:49 queued 96:22
created
modules/ticket_selector/DisplayTicketSelector.php 2 patches
Indentation   +655 added lines, -655 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,663 +19,663 @@  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($external_url) : '';
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($external_url) : '';
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
-     * loadTicketSelector
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
-        $ticket_selector = $this->simpleTicketSelector( $tickets, $template_args);
368
-        return $ticket_selector instanceof TicketSelectorSimple
369
-            ? $ticket_selector
370
-            : new TicketSelectorStandard(
371
-                $this->event,
372
-                $tickets,
373
-                $this->getMaxAttendees(),
374
-                $template_args,
375
-                $this->date_format,
376
-                $this->time_format
377
-            );
378
-    }
379
-
380
-
381
-
382
-    /**
383
-     * simpleTicketSelector
384
-     * there's one ticket, and max attendees is set to one,
385
-     * so if the event is free, then this is a "simple" ticket selector
386
-     * a.k.a. "Dude Where's my Ticket Selector?"
387
-     *
388
-     * @param \EE_Ticket[] $tickets
389
-     * @param array  $template_args
390
-     * @return string
391
-     * @throws \EE_Error
392
-     */
393
-    protected function simpleTicketSelector($tickets, array $template_args)
394
-    {
395
-        // if there is only ONE ticket with a max qty of ONE
396
-        if (count($tickets) > 1 || $this->getMaxAttendees() !== 1) {
397
-            return '';
398
-        }
399
-        /** @var \EE_Ticket $ticket */
400
-        $ticket = reset($tickets);
401
-        // if the ticket is free... then not much need for the ticket selector
402
-        if (
403
-            apply_filters(
404
-                'FHEE__ticket_selector_chart_template__hide_ticket_selector',
405
-                $ticket->is_free(),
406
-                $this->event->ID()
407
-            )
408
-        ) {
409
-            return new TicketSelectorSimple(
410
-                $this->event,
411
-                $ticket,
412
-                $this->getMaxAttendees(),
413
-                $template_args
414
-            );
415
-        }
416
-        return '';
417
-    }
418
-
419
-
420
-
421
-    /**
422
-     * externalEventRegistration
423
-     *
424
-     * @return string
425
-     */
426
-    public function externalEventRegistration()
427
-    {
428
-        // if not we still need to trigger the display of the submit button
429
-        add_filter('FHEE__EE_Ticket_Selector__display_ticket_selector_submit', '__return_true');
430
-        //display notice to admin that registration is external
431
-        return is_admin()
432
-            ? esc_html__(
433
-                'Registration is at an external URL for this event.',
434
-                'event_espresso'
435
-            )
436
-            : '';
437
-    }
438
-
439
-
440
-
441
-    /**
442
-     * formOpen
443
-     *
444
-     * @param        int    $ID
445
-     * @param        string $external_url
446
-     * @return        string
447
-     */
448
-    public function formOpen( $ID = 0, $external_url = '' )
449
-    {
450
-        // if redirecting, we don't need any anything else
451
-        if ( $external_url ) {
452
-            $html = '<form method="GET" action="' . \EEH_URL::refactor_url( $external_url ) . '">';
453
-            $query_args = \EEH_URL::get_query_string( $external_url );
454
-            foreach ( (array)$query_args as $query_arg => $value ) {
455
-                $html .= '<input type="hidden" name="' . $query_arg . '" value="' . $value . '">';
456
-            }
457
-            return $html;
458
-        }
459
-        // if there is no submit button, then don't start building a form
460
-        // because the "View Details" button will build its own form
461
-        if ( ! apply_filters( 'FHEE__EE_Ticket_Selector__display_ticket_selector_submit', false ) ) {
462
-            return '';
463
-        }
464
-        $checkout_url = \EEH_Event_View::event_link_url( $ID );
465
-        if ( ! $checkout_url ) {
466
-            \EE_Error::add_error(
467
-                esc_html__( 'The URL for the Event Details page could not be retrieved.', 'event_espresso' ),
468
-                __FILE__,
469
-                __FUNCTION__,
470
-                __LINE__
471
-            );
472
-        }
473
-        // set no cache headers and constants
474
-        \EE_System::do_not_cache();
475
-        $extra_params = $this->iframe ? ' target="_blank"' : '';
476
-        $html = '<form method="POST" action="' . $checkout_url . '"' . $extra_params . '>';
477
-        $html .= wp_nonce_field( 'process_ticket_selections', 'process_ticket_selections_nonce_' . $ID, true, false );
478
-        $html .= '<input type="hidden" name="ee" value="process_ticket_selections">';
479
-        $html = apply_filters( 'FHEE__EE_Ticket_Selector__ticket_selector_form_open__html', $html, $this->event );
480
-        return $html;
481
-    }
482
-
483
-
484
-
485
-    /**
486
-     * displaySubmitButton
487
-     *
488
-     * @param  string $external_url
489
-     * @return string
490
-     * @throws \EE_Error
491
-     */
492
-    public function displaySubmitButton($external_url = '')
493
-    {
494
-        $html = '';
495
-        if ( ! is_admin()) {
496
-            // standard TS displayed with submit button, ie: "Register Now"
497
-            if (apply_filters('FHEE__EE_Ticket_Selector__display_ticket_selector_submit', false)) {
498
-                $html .= $this->displayRegisterNowButton();
499
-                $html .= empty($external_url)
500
-                    ? $this->ticketSelectorEndDiv()
501
-                    : $this->clearTicketSelector();
502
-                $html .= '<br/>' . $this->formClose();
503
-            } else if ($this->getMaxAttendees() === 1) {
504
-                // its a "Dude Where's my Ticket Selector?" (DWMTS) type event (ie: $_max_atndz === 1)
505
-                if ($this->event->is_sold_out()) {
506
-                    // then instead of a View Details or Submit button, just display a "Sold Out" message
507
-                    $html .= apply_filters(
508
-                        'FHEE__EE_Ticket_Selector__display_ticket_selector_submit__sold_out_msg',
509
-                        sprintf(
510
-                            __(
511
-                                '%1$s"%2$s" is currently sold out.%4$sPlease check back again later, as spots may become available.%3$s',
512
-                                'event_espresso'
513
-                            ),
514
-                            '<p class="no-ticket-selector-msg clear-float">',
515
-                            $this->event->name(),
516
-                            '</p>',
517
-                            '<br />'
518
-                        ),
519
-                        $this->event
520
-                    );
521
-                    if (
522
-                    apply_filters(
523
-                        'FHEE__EE_Ticket_Selector__display_ticket_selector_submit__no_tickets_but_display_register_now_button',
524
-                        false,
525
-                        $this->event
526
-                    )
527
-                    ) {
528
-                        $html .= $this->displayRegisterNowButton();
529
-                    }
530
-                    // sold out DWMTS event, no TS, no submit or view details button, but has additional content
531
-                    $html .= $this->ticketSelectorEndDiv();
532
-                } else if (
533
-                    apply_filters('FHEE__EE_Ticket_Selector__hide_ticket_selector', false)
534
-                    && ! is_single()
535
-                ) {
536
-                    // this is a "Dude Where's my Ticket Selector?" (DWMTS) type event,
537
-                    // but no tickets are available, so display event's "View Details" button.
538
-                    // it is being viewed via somewhere other than a single post
539
-                    $html .= $this->displayViewDetailsButton(true);
540
-                }
541
-            } else if (is_archive()) {
542
-                // event list, no tickets available so display event's "View Details" button
543
-                $html .= $this->ticketSelectorEndDiv();
544
-                $html .= $this->displayViewDetailsButton();
545
-            } else {
546
-                if (
547
-                apply_filters(
548
-                    'FHEE__EE_Ticket_Selector__display_ticket_selector_submit__no_tickets_but_display_register_now_button',
549
-                    false,
550
-                    $this->event
551
-                )
552
-                ) {
553
-                    $html .= $this->displayRegisterNowButton();
554
-                }
555
-                // no submit or view details button, and no additional content
556
-                $html .= $this->ticketSelectorEndDiv();
557
-            }
558
-            if ( ! is_archive()) {
559
-                $html .= \EEH_Template::powered_by_event_espresso('', '', array('utm_content' => 'ticket_selector'));
560
-            }
561
-        }
562
-        return $html;
563
-    }
564
-
565
-
566
-
567
-    /**
568
-     * @return string
569
-     * @throws \EE_Error
570
-     */
571
-    public function displayRegisterNowButton()
572
-    {
573
-        $btn_text = apply_filters(
574
-            'FHEE__EE_Ticket_Selector__display_ticket_selector_submit__btn_text',
575
-            __('Register Now', 'event_espresso'),
576
-            $this->event
577
-        );
578
-        $external_url = $this->event->external_url();
579
-        $html = \EEH_HTML::div(
580
-            '', 'ticket-selector-submit-' . $this->event->ID() . '-btn-wrap', 'ticket-selector-submit-btn-wrap'
581
-        );
582
-        $html .= \EEH_HTML::span(
583
-            esc_html__('please select a datetime', 'event_espresso'),
584
-            '', 'ticket-selector-disabled-submit-btn-msg important-notice'
585
-        );
586
-        $html .= '<input id="ticket-selector-submit-' . $this->event->ID() . '-btn"';
587
-        $html .= ' class="ticket-selector-submit-btn ';
588
-        $html .= empty($external_url) ? 'ticket-selector-submit-ajax"' : '"';
589
-        $html .= ' type="submit" value="' . $btn_text . '" />';
590
-        $html .= \EEH_HTML::divx();
591
-        $html .= apply_filters(
592
-            'FHEE__EE_Ticket_Selector__after_ticket_selector_submit',
593
-            '',
594
-            $this->event
595
-        );
596
-        return $html;
597
-    }
598
-
599
-
600
-    /**
601
-     * displayViewDetailsButton
602
-     *
603
-     * @param bool $DWMTS indicates a "Dude Where's my Ticket Selector?" (DWMTS) type event
604
-     *                    (ie: $_max_atndz === 1) where there are no available tickets,
605
-     *                    either because they are sold out, expired, or not yet on sale.
606
-     *                    In this case, we need to close the form BEFORE adding any closing divs
607
-     * @return string
608
-     * @throws \EE_Error
609
-     */
610
-    public function displayViewDetailsButton( $DWMTS = false )
611
-    {
612
-        if ( ! $this->event->get_permalink() ) {
613
-            \EE_Error::add_error(
614
-                esc_html__( 'The URL for the Event Details page could not be retrieved.', 'event_espresso' ),
615
-                __FILE__, __FUNCTION__, __LINE__
616
-            );
617
-        }
618
-        $view_details_btn = '<form method="POST" action="';
619
-        $view_details_btn .= apply_filters(
620
-            'FHEE__EE_Ticket_Selector__display_view_details_btn__btn_url',
621
-            $this->event->get_permalink(),
622
-            $this->event
623
-        );
624
-        $view_details_btn .= '">';
625
-        $btn_text = apply_filters(
626
-            'FHEE__EE_Ticket_Selector__display_view_details_btn__btn_text',
627
-            esc_html__('View Details', 'event_espresso'),
628
-            $this->event
629
-        );
630
-        $view_details_btn .= '<input id="ticket-selector-submit-'
631
-                             . $this->event->ID()
632
-                             . '-btn" class="ticket-selector-submit-btn view-details-btn" type="submit" value="'
633
-                             . $btn_text
634
-                             . '" />';
635
-        $view_details_btn .= apply_filters( 'FHEE__EE_Ticket_Selector__after_view_details_btn', '', $this->event );
636
-        if ($DWMTS) {
637
-            $view_details_btn .= $this->formClose();
638
-            $view_details_btn .= $this->ticketSelectorEndDiv();
639
-            $view_details_btn .= '<br/>';
640
-        } else {
641
-            $view_details_btn .= $this->clearTicketSelector();
642
-            $view_details_btn .= '<br/>';
643
-            $view_details_btn .= $this->formClose();
644
-        }
645
-        return $view_details_btn;
646
-    }
647
-
648
-
649
-
650
-    /**
651
-     * @return string
652
-     */
653
-    public function ticketSelectorEndDiv()
654
-    {
655
-        return '<div class="clear"></div></div>';
656
-    }
657
-
658
-
659
-
660
-    /**
661
-     * @return string
662
-     */
663
-    public function clearTicketSelector()
664
-    {
665
-        // standard TS displayed, appears after a "Register Now" or "view Details" button
666
-        return '<div class="clear"></div>';
667
-    }
668
-
669
-
670
-
671
-    /**
672
-     * @access        public
673
-     * @return        string
674
-     */
675
-    public function formClose()
676
-    {
677
-        return '</form>';
678
-    }
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
+	 * loadTicketSelector
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
+		$ticket_selector = $this->simpleTicketSelector( $tickets, $template_args);
368
+		return $ticket_selector instanceof TicketSelectorSimple
369
+			? $ticket_selector
370
+			: new TicketSelectorStandard(
371
+				$this->event,
372
+				$tickets,
373
+				$this->getMaxAttendees(),
374
+				$template_args,
375
+				$this->date_format,
376
+				$this->time_format
377
+			);
378
+	}
379
+
380
+
381
+
382
+	/**
383
+	 * simpleTicketSelector
384
+	 * there's one ticket, and max attendees is set to one,
385
+	 * so if the event is free, then this is a "simple" ticket selector
386
+	 * a.k.a. "Dude Where's my Ticket Selector?"
387
+	 *
388
+	 * @param \EE_Ticket[] $tickets
389
+	 * @param array  $template_args
390
+	 * @return string
391
+	 * @throws \EE_Error
392
+	 */
393
+	protected function simpleTicketSelector($tickets, array $template_args)
394
+	{
395
+		// if there is only ONE ticket with a max qty of ONE
396
+		if (count($tickets) > 1 || $this->getMaxAttendees() !== 1) {
397
+			return '';
398
+		}
399
+		/** @var \EE_Ticket $ticket */
400
+		$ticket = reset($tickets);
401
+		// if the ticket is free... then not much need for the ticket selector
402
+		if (
403
+			apply_filters(
404
+				'FHEE__ticket_selector_chart_template__hide_ticket_selector',
405
+				$ticket->is_free(),
406
+				$this->event->ID()
407
+			)
408
+		) {
409
+			return new TicketSelectorSimple(
410
+				$this->event,
411
+				$ticket,
412
+				$this->getMaxAttendees(),
413
+				$template_args
414
+			);
415
+		}
416
+		return '';
417
+	}
418
+
419
+
420
+
421
+	/**
422
+	 * externalEventRegistration
423
+	 *
424
+	 * @return string
425
+	 */
426
+	public function externalEventRegistration()
427
+	{
428
+		// if not we still need to trigger the display of the submit button
429
+		add_filter('FHEE__EE_Ticket_Selector__display_ticket_selector_submit', '__return_true');
430
+		//display notice to admin that registration is external
431
+		return is_admin()
432
+			? esc_html__(
433
+				'Registration is at an external URL for this event.',
434
+				'event_espresso'
435
+			)
436
+			: '';
437
+	}
438
+
439
+
440
+
441
+	/**
442
+	 * formOpen
443
+	 *
444
+	 * @param        int    $ID
445
+	 * @param        string $external_url
446
+	 * @return        string
447
+	 */
448
+	public function formOpen( $ID = 0, $external_url = '' )
449
+	{
450
+		// if redirecting, we don't need any anything else
451
+		if ( $external_url ) {
452
+			$html = '<form method="GET" action="' . \EEH_URL::refactor_url( $external_url ) . '">';
453
+			$query_args = \EEH_URL::get_query_string( $external_url );
454
+			foreach ( (array)$query_args as $query_arg => $value ) {
455
+				$html .= '<input type="hidden" name="' . $query_arg . '" value="' . $value . '">';
456
+			}
457
+			return $html;
458
+		}
459
+		// if there is no submit button, then don't start building a form
460
+		// because the "View Details" button will build its own form
461
+		if ( ! apply_filters( 'FHEE__EE_Ticket_Selector__display_ticket_selector_submit', false ) ) {
462
+			return '';
463
+		}
464
+		$checkout_url = \EEH_Event_View::event_link_url( $ID );
465
+		if ( ! $checkout_url ) {
466
+			\EE_Error::add_error(
467
+				esc_html__( 'The URL for the Event Details page could not be retrieved.', 'event_espresso' ),
468
+				__FILE__,
469
+				__FUNCTION__,
470
+				__LINE__
471
+			);
472
+		}
473
+		// set no cache headers and constants
474
+		\EE_System::do_not_cache();
475
+		$extra_params = $this->iframe ? ' target="_blank"' : '';
476
+		$html = '<form method="POST" action="' . $checkout_url . '"' . $extra_params . '>';
477
+		$html .= wp_nonce_field( 'process_ticket_selections', 'process_ticket_selections_nonce_' . $ID, true, false );
478
+		$html .= '<input type="hidden" name="ee" value="process_ticket_selections">';
479
+		$html = apply_filters( 'FHEE__EE_Ticket_Selector__ticket_selector_form_open__html', $html, $this->event );
480
+		return $html;
481
+	}
482
+
483
+
484
+
485
+	/**
486
+	 * displaySubmitButton
487
+	 *
488
+	 * @param  string $external_url
489
+	 * @return string
490
+	 * @throws \EE_Error
491
+	 */
492
+	public function displaySubmitButton($external_url = '')
493
+	{
494
+		$html = '';
495
+		if ( ! is_admin()) {
496
+			// standard TS displayed with submit button, ie: "Register Now"
497
+			if (apply_filters('FHEE__EE_Ticket_Selector__display_ticket_selector_submit', false)) {
498
+				$html .= $this->displayRegisterNowButton();
499
+				$html .= empty($external_url)
500
+					? $this->ticketSelectorEndDiv()
501
+					: $this->clearTicketSelector();
502
+				$html .= '<br/>' . $this->formClose();
503
+			} else if ($this->getMaxAttendees() === 1) {
504
+				// its a "Dude Where's my Ticket Selector?" (DWMTS) type event (ie: $_max_atndz === 1)
505
+				if ($this->event->is_sold_out()) {
506
+					// then instead of a View Details or Submit button, just display a "Sold Out" message
507
+					$html .= apply_filters(
508
+						'FHEE__EE_Ticket_Selector__display_ticket_selector_submit__sold_out_msg',
509
+						sprintf(
510
+							__(
511
+								'%1$s"%2$s" is currently sold out.%4$sPlease check back again later, as spots may become available.%3$s',
512
+								'event_espresso'
513
+							),
514
+							'<p class="no-ticket-selector-msg clear-float">',
515
+							$this->event->name(),
516
+							'</p>',
517
+							'<br />'
518
+						),
519
+						$this->event
520
+					);
521
+					if (
522
+					apply_filters(
523
+						'FHEE__EE_Ticket_Selector__display_ticket_selector_submit__no_tickets_but_display_register_now_button',
524
+						false,
525
+						$this->event
526
+					)
527
+					) {
528
+						$html .= $this->displayRegisterNowButton();
529
+					}
530
+					// sold out DWMTS event, no TS, no submit or view details button, but has additional content
531
+					$html .= $this->ticketSelectorEndDiv();
532
+				} else if (
533
+					apply_filters('FHEE__EE_Ticket_Selector__hide_ticket_selector', false)
534
+					&& ! is_single()
535
+				) {
536
+					// this is a "Dude Where's my Ticket Selector?" (DWMTS) type event,
537
+					// but no tickets are available, so display event's "View Details" button.
538
+					// it is being viewed via somewhere other than a single post
539
+					$html .= $this->displayViewDetailsButton(true);
540
+				}
541
+			} else if (is_archive()) {
542
+				// event list, no tickets available so display event's "View Details" button
543
+				$html .= $this->ticketSelectorEndDiv();
544
+				$html .= $this->displayViewDetailsButton();
545
+			} else {
546
+				if (
547
+				apply_filters(
548
+					'FHEE__EE_Ticket_Selector__display_ticket_selector_submit__no_tickets_but_display_register_now_button',
549
+					false,
550
+					$this->event
551
+				)
552
+				) {
553
+					$html .= $this->displayRegisterNowButton();
554
+				}
555
+				// no submit or view details button, and no additional content
556
+				$html .= $this->ticketSelectorEndDiv();
557
+			}
558
+			if ( ! is_archive()) {
559
+				$html .= \EEH_Template::powered_by_event_espresso('', '', array('utm_content' => 'ticket_selector'));
560
+			}
561
+		}
562
+		return $html;
563
+	}
564
+
565
+
566
+
567
+	/**
568
+	 * @return string
569
+	 * @throws \EE_Error
570
+	 */
571
+	public function displayRegisterNowButton()
572
+	{
573
+		$btn_text = apply_filters(
574
+			'FHEE__EE_Ticket_Selector__display_ticket_selector_submit__btn_text',
575
+			__('Register Now', 'event_espresso'),
576
+			$this->event
577
+		);
578
+		$external_url = $this->event->external_url();
579
+		$html = \EEH_HTML::div(
580
+			'', 'ticket-selector-submit-' . $this->event->ID() . '-btn-wrap', 'ticket-selector-submit-btn-wrap'
581
+		);
582
+		$html .= \EEH_HTML::span(
583
+			esc_html__('please select a datetime', 'event_espresso'),
584
+			'', 'ticket-selector-disabled-submit-btn-msg important-notice'
585
+		);
586
+		$html .= '<input id="ticket-selector-submit-' . $this->event->ID() . '-btn"';
587
+		$html .= ' class="ticket-selector-submit-btn ';
588
+		$html .= empty($external_url) ? 'ticket-selector-submit-ajax"' : '"';
589
+		$html .= ' type="submit" value="' . $btn_text . '" />';
590
+		$html .= \EEH_HTML::divx();
591
+		$html .= apply_filters(
592
+			'FHEE__EE_Ticket_Selector__after_ticket_selector_submit',
593
+			'',
594
+			$this->event
595
+		);
596
+		return $html;
597
+	}
598
+
599
+
600
+	/**
601
+	 * displayViewDetailsButton
602
+	 *
603
+	 * @param bool $DWMTS indicates a "Dude Where's my Ticket Selector?" (DWMTS) type event
604
+	 *                    (ie: $_max_atndz === 1) where there are no available tickets,
605
+	 *                    either because they are sold out, expired, or not yet on sale.
606
+	 *                    In this case, we need to close the form BEFORE adding any closing divs
607
+	 * @return string
608
+	 * @throws \EE_Error
609
+	 */
610
+	public function displayViewDetailsButton( $DWMTS = false )
611
+	{
612
+		if ( ! $this->event->get_permalink() ) {
613
+			\EE_Error::add_error(
614
+				esc_html__( 'The URL for the Event Details page could not be retrieved.', 'event_espresso' ),
615
+				__FILE__, __FUNCTION__, __LINE__
616
+			);
617
+		}
618
+		$view_details_btn = '<form method="POST" action="';
619
+		$view_details_btn .= apply_filters(
620
+			'FHEE__EE_Ticket_Selector__display_view_details_btn__btn_url',
621
+			$this->event->get_permalink(),
622
+			$this->event
623
+		);
624
+		$view_details_btn .= '">';
625
+		$btn_text = apply_filters(
626
+			'FHEE__EE_Ticket_Selector__display_view_details_btn__btn_text',
627
+			esc_html__('View Details', 'event_espresso'),
628
+			$this->event
629
+		);
630
+		$view_details_btn .= '<input id="ticket-selector-submit-'
631
+							 . $this->event->ID()
632
+							 . '-btn" class="ticket-selector-submit-btn view-details-btn" type="submit" value="'
633
+							 . $btn_text
634
+							 . '" />';
635
+		$view_details_btn .= apply_filters( 'FHEE__EE_Ticket_Selector__after_view_details_btn', '', $this->event );
636
+		if ($DWMTS) {
637
+			$view_details_btn .= $this->formClose();
638
+			$view_details_btn .= $this->ticketSelectorEndDiv();
639
+			$view_details_btn .= '<br/>';
640
+		} else {
641
+			$view_details_btn .= $this->clearTicketSelector();
642
+			$view_details_btn .= '<br/>';
643
+			$view_details_btn .= $this->formClose();
644
+		}
645
+		return $view_details_btn;
646
+	}
647
+
648
+
649
+
650
+	/**
651
+	 * @return string
652
+	 */
653
+	public function ticketSelectorEndDiv()
654
+	{
655
+		return '<div class="clear"></div></div>';
656
+	}
657
+
658
+
659
+
660
+	/**
661
+	 * @return string
662
+	 */
663
+	public function clearTicketSelector()
664
+	{
665
+		// standard TS displayed, appears after a "Register Now" or "view Details" button
666
+		return '<div class="clear"></div>';
667
+	}
668
+
669
+
670
+
671
+	/**
672
+	 * @access        public
673
+	 * @return        string
674
+	 */
675
+	public function formClose()
676
+	{
677
+		return '</form>';
678
+	}
679 679
 
680 680
 
681 681
 
Please login to merge, or discard this patch.
Spacing   +50 added lines, -50 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($external_url) : '';
@@ -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,12 +359,12 @@  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
-        $ticket_selector = $this->simpleTicketSelector( $tickets, $template_args);
367
+        $ticket_selector = $this->simpleTicketSelector($tickets, $template_args);
368 368
         return $ticket_selector instanceof TicketSelectorSimple
369 369
             ? $ticket_selector
370 370
             : new TicketSelectorStandard(
@@ -445,26 +445,26 @@  discard block
 block discarded – undo
445 445
      * @param        string $external_url
446 446
      * @return        string
447 447
      */
448
-    public function formOpen( $ID = 0, $external_url = '' )
448
+    public function formOpen($ID = 0, $external_url = '')
449 449
     {
450 450
         // if redirecting, we don't need any anything else
451
-        if ( $external_url ) {
452
-            $html = '<form method="GET" action="' . \EEH_URL::refactor_url( $external_url ) . '">';
453
-            $query_args = \EEH_URL::get_query_string( $external_url );
454
-            foreach ( (array)$query_args as $query_arg => $value ) {
455
-                $html .= '<input type="hidden" name="' . $query_arg . '" value="' . $value . '">';
451
+        if ($external_url) {
452
+            $html = '<form method="GET" action="'.\EEH_URL::refactor_url($external_url).'">';
453
+            $query_args = \EEH_URL::get_query_string($external_url);
454
+            foreach ((array) $query_args as $query_arg => $value) {
455
+                $html .= '<input type="hidden" name="'.$query_arg.'" value="'.$value.'">';
456 456
             }
457 457
             return $html;
458 458
         }
459 459
         // if there is no submit button, then don't start building a form
460 460
         // because the "View Details" button will build its own form
461
-        if ( ! apply_filters( 'FHEE__EE_Ticket_Selector__display_ticket_selector_submit', false ) ) {
461
+        if ( ! apply_filters('FHEE__EE_Ticket_Selector__display_ticket_selector_submit', false)) {
462 462
             return '';
463 463
         }
464
-        $checkout_url = \EEH_Event_View::event_link_url( $ID );
465
-        if ( ! $checkout_url ) {
464
+        $checkout_url = \EEH_Event_View::event_link_url($ID);
465
+        if ( ! $checkout_url) {
466 466
             \EE_Error::add_error(
467
-                esc_html__( 'The URL for the Event Details page could not be retrieved.', 'event_espresso' ),
467
+                esc_html__('The URL for the Event Details page could not be retrieved.', 'event_espresso'),
468 468
                 __FILE__,
469 469
                 __FUNCTION__,
470 470
                 __LINE__
@@ -473,10 +473,10 @@  discard block
 block discarded – undo
473 473
         // set no cache headers and constants
474 474
         \EE_System::do_not_cache();
475 475
         $extra_params = $this->iframe ? ' target="_blank"' : '';
476
-        $html = '<form method="POST" action="' . $checkout_url . '"' . $extra_params . '>';
477
-        $html .= wp_nonce_field( 'process_ticket_selections', 'process_ticket_selections_nonce_' . $ID, true, false );
476
+        $html = '<form method="POST" action="'.$checkout_url.'"'.$extra_params.'>';
477
+        $html .= wp_nonce_field('process_ticket_selections', 'process_ticket_selections_nonce_'.$ID, true, false);
478 478
         $html .= '<input type="hidden" name="ee" value="process_ticket_selections">';
479
-        $html = apply_filters( 'FHEE__EE_Ticket_Selector__ticket_selector_form_open__html', $html, $this->event );
479
+        $html = apply_filters('FHEE__EE_Ticket_Selector__ticket_selector_form_open__html', $html, $this->event);
480 480
         return $html;
481 481
     }
482 482
 
@@ -499,7 +499,7 @@  discard block
 block discarded – undo
499 499
                 $html .= empty($external_url)
500 500
                     ? $this->ticketSelectorEndDiv()
501 501
                     : $this->clearTicketSelector();
502
-                $html .= '<br/>' . $this->formClose();
502
+                $html .= '<br/>'.$this->formClose();
503 503
             } else if ($this->getMaxAttendees() === 1) {
504 504
                 // its a "Dude Where's my Ticket Selector?" (DWMTS) type event (ie: $_max_atndz === 1)
505 505
                 if ($this->event->is_sold_out()) {
@@ -577,16 +577,16 @@  discard block
 block discarded – undo
577 577
         );
578 578
         $external_url = $this->event->external_url();
579 579
         $html = \EEH_HTML::div(
580
-            '', 'ticket-selector-submit-' . $this->event->ID() . '-btn-wrap', 'ticket-selector-submit-btn-wrap'
580
+            '', 'ticket-selector-submit-'.$this->event->ID().'-btn-wrap', 'ticket-selector-submit-btn-wrap'
581 581
         );
582 582
         $html .= \EEH_HTML::span(
583 583
             esc_html__('please select a datetime', 'event_espresso'),
584 584
             '', 'ticket-selector-disabled-submit-btn-msg important-notice'
585 585
         );
586
-        $html .= '<input id="ticket-selector-submit-' . $this->event->ID() . '-btn"';
586
+        $html .= '<input id="ticket-selector-submit-'.$this->event->ID().'-btn"';
587 587
         $html .= ' class="ticket-selector-submit-btn ';
588 588
         $html .= empty($external_url) ? 'ticket-selector-submit-ajax"' : '"';
589
-        $html .= ' type="submit" value="' . $btn_text . '" />';
589
+        $html .= ' type="submit" value="'.$btn_text.'" />';
590 590
         $html .= \EEH_HTML::divx();
591 591
         $html .= apply_filters(
592 592
             'FHEE__EE_Ticket_Selector__after_ticket_selector_submit',
@@ -607,11 +607,11 @@  discard block
 block discarded – undo
607 607
      * @return string
608 608
      * @throws \EE_Error
609 609
      */
610
-    public function displayViewDetailsButton( $DWMTS = false )
610
+    public function displayViewDetailsButton($DWMTS = false)
611 611
     {
612
-        if ( ! $this->event->get_permalink() ) {
612
+        if ( ! $this->event->get_permalink()) {
613 613
             \EE_Error::add_error(
614
-                esc_html__( 'The URL for the Event Details page could not be retrieved.', 'event_espresso' ),
614
+                esc_html__('The URL for the Event Details page could not be retrieved.', 'event_espresso'),
615 615
                 __FILE__, __FUNCTION__, __LINE__
616 616
             );
617 617
         }
@@ -632,7 +632,7 @@  discard block
 block discarded – undo
632 632
                              . '-btn" class="ticket-selector-submit-btn view-details-btn" type="submit" value="'
633 633
                              . $btn_text
634 634
                              . '" />';
635
-        $view_details_btn .= apply_filters( 'FHEE__EE_Ticket_Selector__after_view_details_btn', '', $this->event );
635
+        $view_details_btn .= apply_filters('FHEE__EE_Ticket_Selector__after_view_details_btn', '', $this->event);
636 636
         if ($DWMTS) {
637 637
             $view_details_btn .= $this->formClose();
638 638
             $view_details_btn .= $this->ticketSelectorEndDiv();
Please login to merge, or discard this patch.