Completed
Branch decaf-fixes/replace-request-ha... (dd0ac0)
by
unknown
04:45 queued 03:02
created
modules/ticket_selector/DisplayTicketSelector.php 2 patches
Indentation   +799 added lines, -799 removed lines patch added patch discarded remove patch
@@ -39,806 +39,806 @@
 block discarded – undo
39 39
  */
40 40
 class DisplayTicketSelector
41 41
 {
42
-    /**
43
-     * @var RequestInterface
44
-     */
45
-    protected $request;
46
-
47
-    /**
48
-     * @var EE_Ticket_Selector_Config
49
-     */
50
-    protected $config;
51
-
52
-    /**
53
-     * event that ticket selector is being generated for
54
-     *
55
-     * @access protected
56
-     * @var EE_Event $event
57
-     */
58
-    protected $event;
59
-
60
-    /**
61
-     * Used to flag when the ticket selector is being called from an external iframe.
62
-     *
63
-     * @var bool $iframe
64
-     */
65
-    protected $iframe = false;
66
-
67
-    /**
68
-     * max attendees that can register for event at one time
69
-     *
70
-     * @var int $max_attendees
71
-     */
72
-    private $max_attendees = EE_INF;
73
-
74
-    /**
75
-     * @var string $date_format
76
-     */
77
-    private $date_format;
78
-
79
-    /**
80
-     * @var string $time_format
81
-     */
82
-    private $time_format;
83
-
84
-    /**
85
-     * @var boolean $display_full_ui
86
-     */
87
-    private $display_full_ui;
88
-
89
-
90
-    /**
91
-     * DisplayTicketSelector constructor.
92
-     *
93
-     * @param bool $iframe
94
-     */
95
-    public function __construct(RequestInterface $request, EE_Ticket_Selector_Config $config, $iframe = false)
96
-    {
97
-        $this->request     = $request;
98
-        $this->config      = $config;
99
-        $this->iframe      = $iframe;
100
-        $this->date_format = apply_filters(
101
-            'FHEE__EED_Ticket_Selector__display_ticket_selector__date_format',
102
-            get_option('date_format')
103
-        );
104
-        $this->time_format = apply_filters(
105
-            'FHEE__EED_Ticket_Selector__display_ticket_selector__time_format',
106
-            get_option('time_format')
107
-        );
108
-    }
109
-
110
-
111
-    /**
112
-     * @return bool
113
-     */
114
-    public function isIframe()
115
-    {
116
-        return $this->iframe;
117
-    }
118
-
119
-
120
-    /**
121
-     * @param boolean $iframe
122
-     */
123
-    public function setIframe($iframe = true)
124
-    {
125
-        $this->iframe = filter_var($iframe, FILTER_VALIDATE_BOOLEAN);
126
-    }
127
-
128
-
129
-    /**
130
-     * finds and sets the \EE_Event object for use throughout class
131
-     *
132
-     * @param mixed $event
133
-     * @return bool
134
-     * @throws EE_Error
135
-     * @throws InvalidDataTypeException
136
-     * @throws InvalidInterfaceException
137
-     * @throws InvalidArgumentException
138
-     */
139
-    protected function setEvent($event = null)
140
-    {
141
-        if ($event === null) {
142
-            global $post;
143
-            $event = $post;
144
-        }
145
-        if ($event instanceof EE_Event) {
146
-            $this->event = $event;
147
-        } elseif ($event instanceof WP_Post) {
148
-            if (isset($event->EE_Event) && $event->EE_Event instanceof EE_Event) {
149
-                $this->event = $event->EE_Event;
150
-            } elseif ($event->post_type === 'espresso_events') {
151
-                $event->EE_Event = EEM_Event::instance()->instantiate_class_from_post_object($event);
152
-                $this->event     = $event->EE_Event;
153
-            }
154
-        } else {
155
-            $user_msg = __('No Event object or an invalid Event object was supplied.', 'event_espresso');
156
-            $dev_msg  = $user_msg . __(
157
-                    '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.',
158
-                    'event_espresso'
159
-                );
160
-            EE_Error::add_error($user_msg . '||' . $dev_msg, __FILE__, __FUNCTION__, __LINE__);
161
-            return false;
162
-        }
163
-        return true;
164
-    }
165
-
166
-
167
-    /**
168
-     * @return int
169
-     */
170
-    public function getMaxAttendees()
171
-    {
172
-        return $this->max_attendees;
173
-    }
174
-
175
-
176
-    /**
177
-     * @param int $max_attendees
178
-     */
179
-    public function setMaxAttendees($max_attendees)
180
-    {
181
-        $this->max_attendees = absint(
182
-            apply_filters(
183
-                'FHEE__EE_Ticket_Selector__display_ticket_selector__max_tickets',
184
-                $max_attendees
185
-            )
186
-        );
187
-    }
188
-
189
-
190
-    /**
191
-     * Returns whether or not the full ticket selector should be shown or not.
192
-     * Currently, it displays on the frontend (including ajax requests) but not the backend
193
-     *
194
-     * @return bool
195
-     */
196
-    private function display_full_ui()
197
-    {
198
-        if ($this->display_full_ui === null) {
199
-            $this->display_full_ui = ! is_admin() || (defined('DOING_AJAX') && DOING_AJAX);
200
-        }
201
-        return $this->display_full_ui;
202
-    }
203
-
204
-
205
-    /**
206
-     * creates buttons for selecting number of attendees for an event
207
-     *
208
-     * @param WP_Post|int $event
209
-     * @param bool        $view_details
210
-     * @return string
211
-     * @throws EE_Error
212
-     * @throws InvalidArgumentException
213
-     * @throws InvalidDataTypeException
214
-     * @throws InvalidInterfaceException
215
-     * @throws ReflectionException
216
-     * @throws Exception
217
-     */
218
-    public function display($event = null, $view_details = false)
219
-    {
220
-        // reset filter for displaying submit button
221
-        remove_filter('FHEE__EE_Ticket_Selector__display_ticket_selector_submit', '__return_true');
222
-        // poke and prod incoming event till it tells us what it is
223
-        if (! $this->setEvent($event)) {
224
-            return $this->handleMissingEvent();
225
-        }
226
-        // is the event expired ?
227
-        $template_args['event_is_expired'] = ! is_admin() && $this->event->is_expired();
228
-        if ($template_args['event_is_expired']) {
229
-            return is_single()
230
-                ? $this->expiredEventMessage()
231
-                : $this->expiredEventMessage()
232
-                  . $this->displayViewDetailsButton();
233
-        }
234
-        // begin gathering template arguments by getting event status
235
-        $template_args = ['event_status' => $this->event->get_active_status()];
236
-        if ($this->activeEventAndShowTicketSelector(
237
-            $event,
238
-            $template_args['event_status'],
239
-            $view_details
240
-        )) {
241
-            return ! is_single() ? $this->displayViewDetailsButton() : '';
242
-        }
243
-        // filter the maximum qty that can appear in the Ticket Selector qty dropdowns
244
-        $this->setMaxAttendees($this->event->additional_limit());
245
-        if ($this->getMaxAttendees() < 1) {
246
-            return $this->ticketSalesClosedMessage();
247
-        }
248
-        // get all tickets for this event ordered by the datetime
249
-        $tickets = $this->getTickets();
250
-        if (count($tickets) < 1) {
251
-            return $this->noTicketAvailableMessage();
252
-        }
253
-        // redirecting to another site for registration ??
254
-        $external_url = (string) $this->event->external_url()
255
-                        && $this->event->external_url() !== get_the_permalink()
256
-            ? $this->event->external_url()
257
-            : '';
258
-        // if redirecting to another site for registration, then we don't load the TS
259
-        $ticket_selector = $external_url
260
-            ? $this->externalEventRegistration()
261
-            : $this->loadTicketSelector($tickets, $template_args);
262
-        // now set up the form (but not for the admin)
263
-        $ticket_selector = $this->display_full_ui()
264
-            ? $this->formOpen($this->event->ID(), $external_url) . $ticket_selector
265
-            : $ticket_selector;
266
-        // submit button and form close tag
267
-        $ticket_selector .= $this->display_full_ui() ? $this->displaySubmitButton($external_url) : '';
268
-        return $ticket_selector;
269
-    }
270
-
271
-
272
-    /**
273
-     * displayTicketSelector
274
-     * examines the event properties and determines whether a Ticket Selector should be displayed
275
-     *
276
-     * @param WP_Post|int $event
277
-     * @param string      $_event_active_status
278
-     * @param bool        $view_details
279
-     * @return bool
280
-     * @throws EE_Error
281
-     * @throws ReflectionException
282
-     */
283
-    protected function activeEventAndShowTicketSelector($event, $_event_active_status, $view_details)
284
-    {
285
-        $event_post = $this->event instanceof EE_Event ? $this->event->ID() : $event;
286
-        return $this->display_full_ui()
287
-               && (
288
-                   ! $this->event->display_ticket_selector()
289
-                   || $view_details
290
-                   || post_password_required($event_post)
291
-                   || (
292
-                       $_event_active_status !== EE_Datetime::active
293
-                       && $_event_active_status !== EE_Datetime::upcoming
294
-                       && $_event_active_status !== EE_Datetime::sold_out
295
-                       && ! (
296
-                           $_event_active_status === EE_Datetime::inactive
297
-                           && is_user_logged_in()
298
-                       )
299
-                   )
300
-               );
301
-    }
302
-
303
-
304
-    /**
305
-     * noTicketAvailableMessage
306
-     * notice displayed if event is expired
307
-     *
308
-     * @return string
309
-     */
310
-    protected function expiredEventMessage()
311
-    {
312
-        return '<div class="ee-event-expired-notice"><span class="important-notice">' . esc_html__(
313
-                'We\'re sorry, but all tickets sales have ended because the event is expired.',
314
-                'event_espresso'
315
-            ) . '</span></div><!-- .ee-event-expired-notice -->';
316
-    }
317
-
318
-
319
-    /**
320
-     * noTicketAvailableMessage
321
-     * notice displayed if event has no more tickets available
322
-     *
323
-     * @return string
324
-     * @throws EE_Error
325
-     * @throws ReflectionException
326
-     */
327
-    protected function noTicketAvailableMessage()
328
-    {
329
-        $no_ticket_available_msg = esc_html__('We\'re sorry, but all ticket sales have ended.', 'event_espresso');
330
-        if (current_user_can('edit_post', $this->event->ID())) {
331
-            $no_ticket_available_msg .= sprintf(
332
-                esc_html__(
333
-                    '%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',
334
-                    'event_espresso'
335
-                ),
336
-                '<div class="ee-attention" style="text-align: left;"><b>',
337
-                '</b><br />',
338
-                '<span class="edit-link"><a class="post-edit-link" href="'
339
-                . get_edit_post_link($this->event->ID())
340
-                . '">',
341
-                '</a></span></div><!-- .ee-attention noTicketAvailableMessage -->'
342
-            );
343
-        }
344
-        return '
42
+	/**
43
+	 * @var RequestInterface
44
+	 */
45
+	protected $request;
46
+
47
+	/**
48
+	 * @var EE_Ticket_Selector_Config
49
+	 */
50
+	protected $config;
51
+
52
+	/**
53
+	 * event that ticket selector is being generated for
54
+	 *
55
+	 * @access protected
56
+	 * @var EE_Event $event
57
+	 */
58
+	protected $event;
59
+
60
+	/**
61
+	 * Used to flag when the ticket selector is being called from an external iframe.
62
+	 *
63
+	 * @var bool $iframe
64
+	 */
65
+	protected $iframe = false;
66
+
67
+	/**
68
+	 * max attendees that can register for event at one time
69
+	 *
70
+	 * @var int $max_attendees
71
+	 */
72
+	private $max_attendees = EE_INF;
73
+
74
+	/**
75
+	 * @var string $date_format
76
+	 */
77
+	private $date_format;
78
+
79
+	/**
80
+	 * @var string $time_format
81
+	 */
82
+	private $time_format;
83
+
84
+	/**
85
+	 * @var boolean $display_full_ui
86
+	 */
87
+	private $display_full_ui;
88
+
89
+
90
+	/**
91
+	 * DisplayTicketSelector constructor.
92
+	 *
93
+	 * @param bool $iframe
94
+	 */
95
+	public function __construct(RequestInterface $request, EE_Ticket_Selector_Config $config, $iframe = false)
96
+	{
97
+		$this->request     = $request;
98
+		$this->config      = $config;
99
+		$this->iframe      = $iframe;
100
+		$this->date_format = apply_filters(
101
+			'FHEE__EED_Ticket_Selector__display_ticket_selector__date_format',
102
+			get_option('date_format')
103
+		);
104
+		$this->time_format = apply_filters(
105
+			'FHEE__EED_Ticket_Selector__display_ticket_selector__time_format',
106
+			get_option('time_format')
107
+		);
108
+	}
109
+
110
+
111
+	/**
112
+	 * @return bool
113
+	 */
114
+	public function isIframe()
115
+	{
116
+		return $this->iframe;
117
+	}
118
+
119
+
120
+	/**
121
+	 * @param boolean $iframe
122
+	 */
123
+	public function setIframe($iframe = true)
124
+	{
125
+		$this->iframe = filter_var($iframe, FILTER_VALIDATE_BOOLEAN);
126
+	}
127
+
128
+
129
+	/**
130
+	 * finds and sets the \EE_Event object for use throughout class
131
+	 *
132
+	 * @param mixed $event
133
+	 * @return bool
134
+	 * @throws EE_Error
135
+	 * @throws InvalidDataTypeException
136
+	 * @throws InvalidInterfaceException
137
+	 * @throws InvalidArgumentException
138
+	 */
139
+	protected function setEvent($event = null)
140
+	{
141
+		if ($event === null) {
142
+			global $post;
143
+			$event = $post;
144
+		}
145
+		if ($event instanceof EE_Event) {
146
+			$this->event = $event;
147
+		} elseif ($event instanceof WP_Post) {
148
+			if (isset($event->EE_Event) && $event->EE_Event instanceof EE_Event) {
149
+				$this->event = $event->EE_Event;
150
+			} elseif ($event->post_type === 'espresso_events') {
151
+				$event->EE_Event = EEM_Event::instance()->instantiate_class_from_post_object($event);
152
+				$this->event     = $event->EE_Event;
153
+			}
154
+		} else {
155
+			$user_msg = __('No Event object or an invalid Event object was supplied.', 'event_espresso');
156
+			$dev_msg  = $user_msg . __(
157
+					'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.',
158
+					'event_espresso'
159
+				);
160
+			EE_Error::add_error($user_msg . '||' . $dev_msg, __FILE__, __FUNCTION__, __LINE__);
161
+			return false;
162
+		}
163
+		return true;
164
+	}
165
+
166
+
167
+	/**
168
+	 * @return int
169
+	 */
170
+	public function getMaxAttendees()
171
+	{
172
+		return $this->max_attendees;
173
+	}
174
+
175
+
176
+	/**
177
+	 * @param int $max_attendees
178
+	 */
179
+	public function setMaxAttendees($max_attendees)
180
+	{
181
+		$this->max_attendees = absint(
182
+			apply_filters(
183
+				'FHEE__EE_Ticket_Selector__display_ticket_selector__max_tickets',
184
+				$max_attendees
185
+			)
186
+		);
187
+	}
188
+
189
+
190
+	/**
191
+	 * Returns whether or not the full ticket selector should be shown or not.
192
+	 * Currently, it displays on the frontend (including ajax requests) but not the backend
193
+	 *
194
+	 * @return bool
195
+	 */
196
+	private function display_full_ui()
197
+	{
198
+		if ($this->display_full_ui === null) {
199
+			$this->display_full_ui = ! is_admin() || (defined('DOING_AJAX') && DOING_AJAX);
200
+		}
201
+		return $this->display_full_ui;
202
+	}
203
+
204
+
205
+	/**
206
+	 * creates buttons for selecting number of attendees for an event
207
+	 *
208
+	 * @param WP_Post|int $event
209
+	 * @param bool        $view_details
210
+	 * @return string
211
+	 * @throws EE_Error
212
+	 * @throws InvalidArgumentException
213
+	 * @throws InvalidDataTypeException
214
+	 * @throws InvalidInterfaceException
215
+	 * @throws ReflectionException
216
+	 * @throws Exception
217
+	 */
218
+	public function display($event = null, $view_details = false)
219
+	{
220
+		// reset filter for displaying submit button
221
+		remove_filter('FHEE__EE_Ticket_Selector__display_ticket_selector_submit', '__return_true');
222
+		// poke and prod incoming event till it tells us what it is
223
+		if (! $this->setEvent($event)) {
224
+			return $this->handleMissingEvent();
225
+		}
226
+		// is the event expired ?
227
+		$template_args['event_is_expired'] = ! is_admin() && $this->event->is_expired();
228
+		if ($template_args['event_is_expired']) {
229
+			return is_single()
230
+				? $this->expiredEventMessage()
231
+				: $this->expiredEventMessage()
232
+				  . $this->displayViewDetailsButton();
233
+		}
234
+		// begin gathering template arguments by getting event status
235
+		$template_args = ['event_status' => $this->event->get_active_status()];
236
+		if ($this->activeEventAndShowTicketSelector(
237
+			$event,
238
+			$template_args['event_status'],
239
+			$view_details
240
+		)) {
241
+			return ! is_single() ? $this->displayViewDetailsButton() : '';
242
+		}
243
+		// filter the maximum qty that can appear in the Ticket Selector qty dropdowns
244
+		$this->setMaxAttendees($this->event->additional_limit());
245
+		if ($this->getMaxAttendees() < 1) {
246
+			return $this->ticketSalesClosedMessage();
247
+		}
248
+		// get all tickets for this event ordered by the datetime
249
+		$tickets = $this->getTickets();
250
+		if (count($tickets) < 1) {
251
+			return $this->noTicketAvailableMessage();
252
+		}
253
+		// redirecting to another site for registration ??
254
+		$external_url = (string) $this->event->external_url()
255
+						&& $this->event->external_url() !== get_the_permalink()
256
+			? $this->event->external_url()
257
+			: '';
258
+		// if redirecting to another site for registration, then we don't load the TS
259
+		$ticket_selector = $external_url
260
+			? $this->externalEventRegistration()
261
+			: $this->loadTicketSelector($tickets, $template_args);
262
+		// now set up the form (but not for the admin)
263
+		$ticket_selector = $this->display_full_ui()
264
+			? $this->formOpen($this->event->ID(), $external_url) . $ticket_selector
265
+			: $ticket_selector;
266
+		// submit button and form close tag
267
+		$ticket_selector .= $this->display_full_ui() ? $this->displaySubmitButton($external_url) : '';
268
+		return $ticket_selector;
269
+	}
270
+
271
+
272
+	/**
273
+	 * displayTicketSelector
274
+	 * examines the event properties and determines whether a Ticket Selector should be displayed
275
+	 *
276
+	 * @param WP_Post|int $event
277
+	 * @param string      $_event_active_status
278
+	 * @param bool        $view_details
279
+	 * @return bool
280
+	 * @throws EE_Error
281
+	 * @throws ReflectionException
282
+	 */
283
+	protected function activeEventAndShowTicketSelector($event, $_event_active_status, $view_details)
284
+	{
285
+		$event_post = $this->event instanceof EE_Event ? $this->event->ID() : $event;
286
+		return $this->display_full_ui()
287
+			   && (
288
+				   ! $this->event->display_ticket_selector()
289
+				   || $view_details
290
+				   || post_password_required($event_post)
291
+				   || (
292
+					   $_event_active_status !== EE_Datetime::active
293
+					   && $_event_active_status !== EE_Datetime::upcoming
294
+					   && $_event_active_status !== EE_Datetime::sold_out
295
+					   && ! (
296
+						   $_event_active_status === EE_Datetime::inactive
297
+						   && is_user_logged_in()
298
+					   )
299
+				   )
300
+			   );
301
+	}
302
+
303
+
304
+	/**
305
+	 * noTicketAvailableMessage
306
+	 * notice displayed if event is expired
307
+	 *
308
+	 * @return string
309
+	 */
310
+	protected function expiredEventMessage()
311
+	{
312
+		return '<div class="ee-event-expired-notice"><span class="important-notice">' . esc_html__(
313
+				'We\'re sorry, but all tickets sales have ended because the event is expired.',
314
+				'event_espresso'
315
+			) . '</span></div><!-- .ee-event-expired-notice -->';
316
+	}
317
+
318
+
319
+	/**
320
+	 * noTicketAvailableMessage
321
+	 * notice displayed if event has no more tickets available
322
+	 *
323
+	 * @return string
324
+	 * @throws EE_Error
325
+	 * @throws ReflectionException
326
+	 */
327
+	protected function noTicketAvailableMessage()
328
+	{
329
+		$no_ticket_available_msg = esc_html__('We\'re sorry, but all ticket sales have ended.', 'event_espresso');
330
+		if (current_user_can('edit_post', $this->event->ID())) {
331
+			$no_ticket_available_msg .= sprintf(
332
+				esc_html__(
333
+					'%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',
334
+					'event_espresso'
335
+				),
336
+				'<div class="ee-attention" style="text-align: left;"><b>',
337
+				'</b><br />',
338
+				'<span class="edit-link"><a class="post-edit-link" href="'
339
+				. get_edit_post_link($this->event->ID())
340
+				. '">',
341
+				'</a></span></div><!-- .ee-attention noTicketAvailableMessage -->'
342
+			);
343
+		}
344
+		return '
345 345
             <div class="ee-event-expired-notice">
346 346
                 <span class="important-notice">' . $no_ticket_available_msg . '</span>
347 347
             </div><!-- .ee-event-expired-notice -->';
348
-    }
349
-
350
-
351
-    /**
352
-     * ticketSalesClosed
353
-     * notice displayed if event ticket sales are turned off
354
-     *
355
-     * @return string
356
-     * @throws EE_Error
357
-     * @throws ReflectionException
358
-     */
359
-    protected function ticketSalesClosedMessage()
360
-    {
361
-        $sales_closed_msg = esc_html__(
362
-            'We\'re sorry, but ticket sales have been closed at this time. Please check back again later.',
363
-            'event_espresso'
364
-        );
365
-        if (current_user_can('edit_post', $this->event->ID())) {
366
-            $sales_closed_msg .= sprintf(
367
-                esc_html__(
368
-                    '%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',
369
-                    'event_espresso'
370
-                ),
371
-                '<div class="ee-attention" style="text-align: left;"><b>',
372
-                '</b><br />',
373
-                '<span class="edit-link"><a class="post-edit-link" href="'
374
-                . get_edit_post_link($this->event->ID())
375
-                . '">',
376
-                '</a></span></div><!-- .ee-attention ticketSalesClosedMessage -->'
377
-            );
378
-        }
379
-        return '<p><span class="important-notice">' . $sales_closed_msg . '</span></p>';
380
-    }
381
-
382
-
383
-    /**
384
-     * getTickets
385
-     *
386
-     * @return EE_Base_Class[]|EE_Ticket[]
387
-     * @throws EE_Error
388
-     * @throws InvalidDataTypeException
389
-     * @throws InvalidInterfaceException
390
-     * @throws InvalidArgumentException
391
-     * @throws ReflectionException
392
-     */
393
-    protected function getTickets()
394
-    {
395
-        $show_expired_tickets = is_admin() || $this->config->show_expired_tickets;
396
-
397
-        $ticket_query_args = [
398
-            ['Datetime.EVT_ID' => $this->event->ID()],
399
-            'order_by' => [
400
-                'TKT_order'              => 'ASC',
401
-                'TKT_required'           => 'DESC',
402
-                'TKT_start_date'         => 'ASC',
403
-                'TKT_end_date'           => 'ASC',
404
-                'Datetime.DTT_EVT_start' => 'DESC',
405
-            ],
406
-        ];
407
-        if (! $show_expired_tickets) {
408
-            // use the correct applicable time query depending on what version of core is being run.
409
-            $current_time                         = method_exists('EEM_Datetime', 'current_time_for_query')
410
-                ? time()
411
-                : current_time('timestamp');
412
-            $ticket_query_args[0]['TKT_end_date'] = ['>', $current_time];
413
-        }
414
-        return EEM_Ticket::instance()->get_all($ticket_query_args);
415
-    }
416
-
417
-
418
-    /**
419
-     * loadTicketSelector
420
-     * begins to assemble template arguments
421
-     * and decides whether to load a "simple" ticket selector, or the standard
422
-     *
423
-     * @param EE_Ticket[] $tickets
424
-     * @param array       $template_args
425
-     * @return TicketSelectorSimple|TicketSelectorStandard
426
-     * @throws EE_Error
427
-     * @throws ReflectionException
428
-     */
429
-    protected function loadTicketSelector(array $tickets, array $template_args)
430
-    {
431
-        $template_args['event']            = $this->event;
432
-        $template_args['EVT_ID']           = $this->event->ID();
433
-        $template_args['event_is_expired'] = $this->event->is_expired();
434
-        $template_args['max_atndz']        = $this->getMaxAttendees();
435
-        $template_args['date_format']      = $this->date_format;
436
-        $template_args['time_format']      = $this->time_format;
437
-        /**
438
-         * Filters the anchor ID used when redirecting to the Ticket Selector if no quantity selected
439
-         *
440
-         * @param string  '#tkt-slctr-tbl-' . $EVT_ID The html ID to anchor to
441
-         * @param int $EVT_ID The Event ID
442
-         * @since 4.9.13
443
-         */
444
-        $template_args['anchor_id']    = apply_filters(
445
-            'FHEE__EE_Ticket_Selector__redirect_anchor_id',
446
-            '#tkt-slctr-tbl-' . $this->event->ID(),
447
-            $this->event->ID()
448
-        );
449
-        $template_args['tickets']      = $tickets;
450
-        $template_args['ticket_count'] = count($tickets);
451
-        $ticket_selector               = $this->simpleTicketSelector($tickets, $template_args);
452
-        if ($ticket_selector instanceof TicketSelectorSimple) {
453
-            return $ticket_selector;
454
-        }
455
-        return new TicketSelectorStandard(
456
-            $this->config,
457
-            $this->getTaxConfig(),
458
-            $this->event,
459
-            $tickets,
460
-            $this->getMaxAttendees(),
461
-            $template_args,
462
-            $this->date_format,
463
-            $this->time_format
464
-        );
465
-    }
466
-
467
-
468
-    /**
469
-     * simpleTicketSelector
470
-     * there's one ticket, and max attendees is set to one,
471
-     * so if the event is free, then this is a "simple" ticket selector
472
-     * a.k.a. "Dude Where's my Ticket Selector?"
473
-     *
474
-     * @param EE_Ticket[] $tickets
475
-     * @param array       $template_args
476
-     * @return string
477
-     * @throws EE_Error
478
-     * @throws ReflectionException
479
-     */
480
-    protected function simpleTicketSelector($tickets, array $template_args)
481
-    {
482
-        // if there is only ONE ticket with a max qty of ONE
483
-        if (count($tickets) > 1 || $this->getMaxAttendees() !== 1) {
484
-            return '';
485
-        }
486
-        /** @var EE_Ticket $ticket */
487
-        $ticket = reset($tickets);
488
-        // if the ticket is free... then not much need for the ticket selector
489
-        if (apply_filters(
490
-            'FHEE__ticket_selector_chart_template__hide_ticket_selector',
491
-            $ticket->is_free(),
492
-            $this->event->ID()
493
-        )) {
494
-            return new TicketSelectorSimple(
495
-                $this->event,
496
-                $ticket,
497
-                $this->getMaxAttendees(),
498
-                $template_args
499
-            );
500
-        }
501
-        return '';
502
-    }
503
-
504
-
505
-    /**
506
-     * externalEventRegistration
507
-     *
508
-     * @return string
509
-     */
510
-    public function externalEventRegistration()
511
-    {
512
-        // if not we still need to trigger the display of the submit button
513
-        add_filter('FHEE__EE_Ticket_Selector__display_ticket_selector_submit', '__return_true');
514
-        // display notice to admin that registration is external
515
-        return $this->display_full_ui()
516
-            ? esc_html__(
517
-                'Registration is at an external URL for this event.',
518
-                'event_espresso'
519
-            )
520
-            : '';
521
-    }
522
-
523
-
524
-    /**
525
-     * formOpen
526
-     *
527
-     * @param int    $ID
528
-     * @param string $external_url
529
-     * @return        string
530
-     */
531
-    public function formOpen($ID = 0, $external_url = '')
532
-    {
533
-        // if redirecting, we don't need any anything else
534
-        if ($external_url) {
535
-            $html = '<form method="GET" ';
536
-            $html .= 'action="' . EEH_URL::refactor_url($external_url) . '" ';
537
-            $html .= 'name="ticket-selector-form-' . $ID . '"';
538
-            // open link in new window ?
539
-            $html       .= apply_filters(
540
-                'FHEE__EventEspresso_modules_ticket_selector_DisplayTicketSelector__formOpen__external_url_target_blank',
541
-                $this->isIframe(),
542
-                $this
543
-            )
544
-                ? ' target="_blank"'
545
-                : '';
546
-            $html       .= '>';
547
-            $query_args = EEH_URL::get_query_string($external_url);
548
-            foreach ((array) $query_args as $query_arg => $value) {
549
-                $html .= '<input type="hidden" name="' . $query_arg . '" value="' . $value . '">';
550
-            }
551
-            return $html;
552
-        }
553
-        // if there is no submit button, then don't start building a form
554
-        // because the "View Details" button will build its own form
555
-        if (! apply_filters('FHEE__EE_Ticket_Selector__display_ticket_selector_submit', false)) {
556
-            return '';
557
-        }
558
-        $checkout_url = EEH_Event_View::event_link_url($ID);
559
-        if (! $checkout_url) {
560
-            EE_Error::add_error(
561
-                esc_html__('The URL for the Event Details page could not be retrieved.', 'event_espresso'),
562
-                __FILE__,
563
-                __FUNCTION__,
564
-                __LINE__
565
-            );
566
-        }
567
-        // set no cache headers and constants
568
-        EE_System::do_not_cache();
569
-        $html = '<form method="POST" ';
570
-        $html .= 'action="' . $checkout_url . '" ';
571
-        $html .= 'name="ticket-selector-form-' . $ID . '"';
572
-        $html .= $this->iframe ? ' target="_blank"' : '';
573
-        $html .= '>';
574
-        $html .= '<input type="hidden" name="ee" value="process_ticket_selections">';
575
-        return apply_filters('FHEE__EE_Ticket_Selector__ticket_selector_form_open__html', $html, $this->event);
576
-    }
577
-
578
-
579
-    /**
580
-     * displaySubmitButton
581
-     *
582
-     * @param string $external_url
583
-     * @return string
584
-     * @throws EE_Error
585
-     * @throws ReflectionException
586
-     */
587
-    public function displaySubmitButton($external_url = '')
588
-    {
589
-        $html = '';
590
-        if ($this->display_full_ui()) {
591
-            // standard TS displayed with submit button, ie: "Register Now"
592
-            if (apply_filters('FHEE__EE_Ticket_Selector__display_ticket_selector_submit', false)) {
593
-                $html .= $this->displayRegisterNowButton();
594
-                $html .= empty($external_url)
595
-                    ? $this->ticketSelectorEndDiv()
596
-                    : $this->clearTicketSelector();
597
-                $html .= '<br/>' . $this->formClose();
598
-            } elseif ($this->getMaxAttendees() === 1) {
599
-                // its a "Dude Where's my Ticket Selector?" (DWMTS) type event (ie: $_max_atndz === 1)
600
-                if ($this->event->is_sold_out()) {
601
-                    // then instead of a View Details or Submit button, just display a "Sold Out" message
602
-                    $html .= apply_filters(
603
-                        'FHEE__EE_Ticket_Selector__display_ticket_selector_submit__sold_out_msg',
604
-                        sprintf(
605
-                            __(
606
-                                '%1$s"%2$s" is currently sold out.%4$sPlease check back again later, as spots may become available.%3$s',
607
-                                'event_espresso'
608
-                            ),
609
-                            '<p class="no-ticket-selector-msg clear-float">',
610
-                            $this->event->name(),
611
-                            '</p>',
612
-                            '<br />'
613
-                        ),
614
-                        $this->event
615
-                    );
616
-                    if (apply_filters(
617
-                        'FHEE__EE_Ticket_Selector__display_ticket_selector_submit__no_tickets_but_display_register_now_button',
618
-                        false,
619
-                        $this->event
620
-                    )) {
621
-                        $html .= $this->displayRegisterNowButton();
622
-                    }
623
-                    // sold out DWMTS event, no TS, no submit or view details button, but has additional content
624
-                    $html .= $this->ticketSelectorEndDiv();
625
-                } elseif (apply_filters('FHEE__EE_Ticket_Selector__hide_ticket_selector', false)
626
-                          && ! is_single()
627
-                ) {
628
-                    // this is a "Dude Where's my Ticket Selector?" (DWMTS) type event,
629
-                    // but no tickets are available, so display event's "View Details" button.
630
-                    // it is being viewed via somewhere other than a single post
631
-                    $html .= $this->displayViewDetailsButton(true);
632
-                } else {
633
-                    $html .= $this->ticketSelectorEndDiv();
634
-                }
635
-            } elseif (is_archive()) {
636
-                // event list, no tickets available so display event's "View Details" button
637
-                $html .= $this->ticketSelectorEndDiv();
638
-                $html .= $this->displayViewDetailsButton();
639
-            } else {
640
-                if (apply_filters(
641
-                    'FHEE__EE_Ticket_Selector__display_ticket_selector_submit__no_tickets_but_display_register_now_button',
642
-                    false,
643
-                    $this->event
644
-                )) {
645
-                    $html .= $this->displayRegisterNowButton();
646
-                }
647
-                // no submit or view details button, and no additional content
648
-                $html .= $this->ticketSelectorEndDiv();
649
-            }
650
-            if (! $this->iframe && ! is_archive()) {
651
-                $html .= EEH_Template::powered_by_event_espresso('', '', ['utm_content' => 'ticket_selector']);
652
-            }
653
-        }
654
-        return apply_filters(
655
-            'FHEE__EventEspresso_modules_ticket_selector_DisplayTicketSelector__displaySubmitButton__html',
656
-            $html,
657
-            $this->event,
658
-            $this
659
-        );
660
-    }
661
-
662
-
663
-    /**
664
-     * @return string
665
-     * @throws EE_Error
666
-     * @throws ReflectionException
667
-     */
668
-    public function displayRegisterNowButton()
669
-    {
670
-        $btn_text     = apply_filters(
671
-            'FHEE__EE_Ticket_Selector__display_ticket_selector_submit__btn_text',
672
-            __('Register Now', 'event_espresso'),
673
-            $this->event
674
-        );
675
-        $external_url = (string) $this->event->external_url()
676
-                        && $this->event->external_url() !== get_the_permalink()
677
-            ? $this->event->external_url()
678
-            : '';
679
-        $html         = EEH_HTML::div(
680
-            '',
681
-            'ticket-selector-submit-' . $this->event->ID() . '-btn-wrap',
682
-            'ticket-selector-submit-btn-wrap'
683
-        );
684
-        $html         .= '<input id="ticket-selector-submit-' . $this->event->ID() . '-btn"';
685
-        $html         .= ' class="ticket-selector-submit-btn ';
686
-        $html         .= empty($external_url) ? 'ticket-selector-submit-ajax"' : '"';
687
-        $html         .= ' type="submit" value="' . $btn_text . '" data-ee-disable-after-recaptcha="true" />';
688
-        $html         .= EEH_HTML::divx() . '<!-- .ticket-selector-submit-btn-wrap -->';
689
-        $html         .= apply_filters(
690
-            'FHEE__EE_Ticket_Selector__after_ticket_selector_submit',
691
-            '',
692
-            $this->event,
693
-            $this->iframe
694
-        );
695
-        return $html;
696
-    }
697
-
698
-
699
-    /**
700
-     * displayViewDetailsButton
701
-     *
702
-     * @param bool $DWMTS indicates a "Dude Where's my Ticket Selector?" (DWMTS) type event
703
-     *                    (ie: $_max_atndz === 1) where there are no available tickets,
704
-     *                    either because they are sold out, expired, or not yet on sale.
705
-     *                    In this case, we need to close the form BEFORE adding any closing divs
706
-     * @return string
707
-     * @throws EE_Error
708
-     * @throws ReflectionException
709
-     */
710
-    public function displayViewDetailsButton($DWMTS = false)
711
-    {
712
-        if (! $this->event->get_permalink()) {
713
-            EE_Error::add_error(
714
-                esc_html__('The URL for the Event Details page could not be retrieved.', 'event_espresso'),
715
-                __FILE__,
716
-                __FUNCTION__,
717
-                __LINE__
718
-            );
719
-        }
720
-        $view_details_btn = '<form method="GET" action="';
721
-        $view_details_btn .= apply_filters(
722
-            'FHEE__EE_Ticket_Selector__display_view_details_btn__btn_url',
723
-            $this->event->get_permalink(),
724
-            $this->event
725
-        );
726
-        $view_details_btn .= '"';
727
-        // open link in new window ?
728
-        $view_details_btn .= apply_filters(
729
-            'FHEE__EventEspresso_modules_ticket_selector_DisplayTicketSelector__displayViewDetailsButton__url_target_blank',
730
-            $this->isIframe(),
731
-            $this
732
-        )
733
-            ? ' target="_blank"'
734
-            : '';
735
-        $view_details_btn .= '>';
736
-        $btn_text         = apply_filters(
737
-            'FHEE__EE_Ticket_Selector__display_view_details_btn__btn_text',
738
-            esc_html__('View Details', 'event_espresso'),
739
-            $this->event
740
-        );
741
-        $view_details_btn .= '<input id="ticket-selector-submit-'
742
-                             . $this->event->ID()
743
-                             . '-btn" class="ticket-selector-submit-btn view-details-btn" type="submit" value="'
744
-                             . $btn_text
745
-                             . '" />';
746
-        $view_details_btn .= apply_filters('FHEE__EE_Ticket_Selector__after_view_details_btn', '', $this->event);
747
-        if ($DWMTS) {
748
-            $view_details_btn .= $this->formClose();
749
-            $view_details_btn .= $this->ticketSelectorEndDiv();
750
-            $view_details_btn .= '<br/>';
751
-        } else {
752
-            $view_details_btn .= $this->clearTicketSelector();
753
-            $view_details_btn .= '<br/>';
754
-            $view_details_btn .= $this->formClose();
755
-        }
756
-        return $view_details_btn;
757
-    }
758
-
759
-
760
-    /**
761
-     * @return string
762
-     */
763
-    public function ticketSelectorEndDiv()
764
-    {
765
-        return $this->clearTicketSelector() . '</div><!-- ticketSelectorEndDiv -->';
766
-    }
767
-
768
-
769
-    /**
770
-     * @return string
771
-     */
772
-    public function clearTicketSelector()
773
-    {
774
-        // standard TS displayed, appears after a "Register Now" or "view Details" button
775
-        return '<div class="clear"></div><!-- clearTicketSelector -->';
776
-    }
777
-
778
-
779
-    /**
780
-     * @access        public
781
-     * @return        string
782
-     */
783
-    public function formClose()
784
-    {
785
-        return '</form>';
786
-    }
787
-
788
-
789
-    /**
790
-     * handleMissingEvent
791
-     * Returns either false or an error to display when no valid event is passed.
792
-     *
793
-     * @return string
794
-     * @throws ExceptionStackTraceDisplay
795
-     * @throws InvalidInterfaceException
796
-     * @throws Exception
797
-     */
798
-    protected function handleMissingEvent()
799
-    {
800
-        // If this is not an iFrame request, simply return false.
801
-        if (! $this->isIframe()) {
802
-            return '';
803
-        }
804
-        // This is an iFrame so return an error.
805
-        // Display stack trace if WP_DEBUG is enabled.
806
-        if (WP_DEBUG === true && current_user_can('edit_pages')) {
807
-            $event_id = $this->request->getRequestParam('event', 0, 'int');
808
-            new ExceptionStackTraceDisplay(
809
-                new InvalidArgumentException(
810
-                    sprintf(
811
-                        esc_html__(
812
-                            'A valid Event ID is required to display the ticket selector.%3$sAn Event with an ID of "%1$s" could not be found.%3$sPlease verify that the embed code added to this post\'s content includes an "%2$s" argument and that its value corresponds to a valid Event ID.',
813
-                            'event_espresso'
814
-                        ),
815
-                        $event_id,
816
-                        'event',
817
-                        '<br />'
818
-                    )
819
-                )
820
-            );
821
-            return '';
822
-        }
823
-        // If WP_DEBUG is not enabled, display a message stating the event could not be found.
824
-        return EEH_HTML::p(
825
-            esc_html__(
826
-                'A valid Event could not be found. Please contact the event administrator for assistance.',
827
-                'event_espresso'
828
-            )
829
-        );
830
-    }
831
-
832
-
833
-    /**
834
-     * @return EE_Tax_Config
835
-     * @since   $VID:$
836
-     */
837
-    protected function getTaxConfig()
838
-    {
839
-        return isset(EE_Registry::instance()->CFG->tax_settings)
840
-               && EE_Registry::instance()->CFG->tax_settings instanceof EE_Tax_Config
841
-            ? EE_Registry::instance()->CFG->tax_settings
842
-            : new EE_Tax_Config();
843
-    }
348
+	}
349
+
350
+
351
+	/**
352
+	 * ticketSalesClosed
353
+	 * notice displayed if event ticket sales are turned off
354
+	 *
355
+	 * @return string
356
+	 * @throws EE_Error
357
+	 * @throws ReflectionException
358
+	 */
359
+	protected function ticketSalesClosedMessage()
360
+	{
361
+		$sales_closed_msg = esc_html__(
362
+			'We\'re sorry, but ticket sales have been closed at this time. Please check back again later.',
363
+			'event_espresso'
364
+		);
365
+		if (current_user_can('edit_post', $this->event->ID())) {
366
+			$sales_closed_msg .= sprintf(
367
+				esc_html__(
368
+					'%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',
369
+					'event_espresso'
370
+				),
371
+				'<div class="ee-attention" style="text-align: left;"><b>',
372
+				'</b><br />',
373
+				'<span class="edit-link"><a class="post-edit-link" href="'
374
+				. get_edit_post_link($this->event->ID())
375
+				. '">',
376
+				'</a></span></div><!-- .ee-attention ticketSalesClosedMessage -->'
377
+			);
378
+		}
379
+		return '<p><span class="important-notice">' . $sales_closed_msg . '</span></p>';
380
+	}
381
+
382
+
383
+	/**
384
+	 * getTickets
385
+	 *
386
+	 * @return EE_Base_Class[]|EE_Ticket[]
387
+	 * @throws EE_Error
388
+	 * @throws InvalidDataTypeException
389
+	 * @throws InvalidInterfaceException
390
+	 * @throws InvalidArgumentException
391
+	 * @throws ReflectionException
392
+	 */
393
+	protected function getTickets()
394
+	{
395
+		$show_expired_tickets = is_admin() || $this->config->show_expired_tickets;
396
+
397
+		$ticket_query_args = [
398
+			['Datetime.EVT_ID' => $this->event->ID()],
399
+			'order_by' => [
400
+				'TKT_order'              => 'ASC',
401
+				'TKT_required'           => 'DESC',
402
+				'TKT_start_date'         => 'ASC',
403
+				'TKT_end_date'           => 'ASC',
404
+				'Datetime.DTT_EVT_start' => 'DESC',
405
+			],
406
+		];
407
+		if (! $show_expired_tickets) {
408
+			// use the correct applicable time query depending on what version of core is being run.
409
+			$current_time                         = method_exists('EEM_Datetime', 'current_time_for_query')
410
+				? time()
411
+				: current_time('timestamp');
412
+			$ticket_query_args[0]['TKT_end_date'] = ['>', $current_time];
413
+		}
414
+		return EEM_Ticket::instance()->get_all($ticket_query_args);
415
+	}
416
+
417
+
418
+	/**
419
+	 * loadTicketSelector
420
+	 * begins to assemble template arguments
421
+	 * and decides whether to load a "simple" ticket selector, or the standard
422
+	 *
423
+	 * @param EE_Ticket[] $tickets
424
+	 * @param array       $template_args
425
+	 * @return TicketSelectorSimple|TicketSelectorStandard
426
+	 * @throws EE_Error
427
+	 * @throws ReflectionException
428
+	 */
429
+	protected function loadTicketSelector(array $tickets, array $template_args)
430
+	{
431
+		$template_args['event']            = $this->event;
432
+		$template_args['EVT_ID']           = $this->event->ID();
433
+		$template_args['event_is_expired'] = $this->event->is_expired();
434
+		$template_args['max_atndz']        = $this->getMaxAttendees();
435
+		$template_args['date_format']      = $this->date_format;
436
+		$template_args['time_format']      = $this->time_format;
437
+		/**
438
+		 * Filters the anchor ID used when redirecting to the Ticket Selector if no quantity selected
439
+		 *
440
+		 * @param string  '#tkt-slctr-tbl-' . $EVT_ID The html ID to anchor to
441
+		 * @param int $EVT_ID The Event ID
442
+		 * @since 4.9.13
443
+		 */
444
+		$template_args['anchor_id']    = apply_filters(
445
+			'FHEE__EE_Ticket_Selector__redirect_anchor_id',
446
+			'#tkt-slctr-tbl-' . $this->event->ID(),
447
+			$this->event->ID()
448
+		);
449
+		$template_args['tickets']      = $tickets;
450
+		$template_args['ticket_count'] = count($tickets);
451
+		$ticket_selector               = $this->simpleTicketSelector($tickets, $template_args);
452
+		if ($ticket_selector instanceof TicketSelectorSimple) {
453
+			return $ticket_selector;
454
+		}
455
+		return new TicketSelectorStandard(
456
+			$this->config,
457
+			$this->getTaxConfig(),
458
+			$this->event,
459
+			$tickets,
460
+			$this->getMaxAttendees(),
461
+			$template_args,
462
+			$this->date_format,
463
+			$this->time_format
464
+		);
465
+	}
466
+
467
+
468
+	/**
469
+	 * simpleTicketSelector
470
+	 * there's one ticket, and max attendees is set to one,
471
+	 * so if the event is free, then this is a "simple" ticket selector
472
+	 * a.k.a. "Dude Where's my Ticket Selector?"
473
+	 *
474
+	 * @param EE_Ticket[] $tickets
475
+	 * @param array       $template_args
476
+	 * @return string
477
+	 * @throws EE_Error
478
+	 * @throws ReflectionException
479
+	 */
480
+	protected function simpleTicketSelector($tickets, array $template_args)
481
+	{
482
+		// if there is only ONE ticket with a max qty of ONE
483
+		if (count($tickets) > 1 || $this->getMaxAttendees() !== 1) {
484
+			return '';
485
+		}
486
+		/** @var EE_Ticket $ticket */
487
+		$ticket = reset($tickets);
488
+		// if the ticket is free... then not much need for the ticket selector
489
+		if (apply_filters(
490
+			'FHEE__ticket_selector_chart_template__hide_ticket_selector',
491
+			$ticket->is_free(),
492
+			$this->event->ID()
493
+		)) {
494
+			return new TicketSelectorSimple(
495
+				$this->event,
496
+				$ticket,
497
+				$this->getMaxAttendees(),
498
+				$template_args
499
+			);
500
+		}
501
+		return '';
502
+	}
503
+
504
+
505
+	/**
506
+	 * externalEventRegistration
507
+	 *
508
+	 * @return string
509
+	 */
510
+	public function externalEventRegistration()
511
+	{
512
+		// if not we still need to trigger the display of the submit button
513
+		add_filter('FHEE__EE_Ticket_Selector__display_ticket_selector_submit', '__return_true');
514
+		// display notice to admin that registration is external
515
+		return $this->display_full_ui()
516
+			? esc_html__(
517
+				'Registration is at an external URL for this event.',
518
+				'event_espresso'
519
+			)
520
+			: '';
521
+	}
522
+
523
+
524
+	/**
525
+	 * formOpen
526
+	 *
527
+	 * @param int    $ID
528
+	 * @param string $external_url
529
+	 * @return        string
530
+	 */
531
+	public function formOpen($ID = 0, $external_url = '')
532
+	{
533
+		// if redirecting, we don't need any anything else
534
+		if ($external_url) {
535
+			$html = '<form method="GET" ';
536
+			$html .= 'action="' . EEH_URL::refactor_url($external_url) . '" ';
537
+			$html .= 'name="ticket-selector-form-' . $ID . '"';
538
+			// open link in new window ?
539
+			$html       .= apply_filters(
540
+				'FHEE__EventEspresso_modules_ticket_selector_DisplayTicketSelector__formOpen__external_url_target_blank',
541
+				$this->isIframe(),
542
+				$this
543
+			)
544
+				? ' target="_blank"'
545
+				: '';
546
+			$html       .= '>';
547
+			$query_args = EEH_URL::get_query_string($external_url);
548
+			foreach ((array) $query_args as $query_arg => $value) {
549
+				$html .= '<input type="hidden" name="' . $query_arg . '" value="' . $value . '">';
550
+			}
551
+			return $html;
552
+		}
553
+		// if there is no submit button, then don't start building a form
554
+		// because the "View Details" button will build its own form
555
+		if (! apply_filters('FHEE__EE_Ticket_Selector__display_ticket_selector_submit', false)) {
556
+			return '';
557
+		}
558
+		$checkout_url = EEH_Event_View::event_link_url($ID);
559
+		if (! $checkout_url) {
560
+			EE_Error::add_error(
561
+				esc_html__('The URL for the Event Details page could not be retrieved.', 'event_espresso'),
562
+				__FILE__,
563
+				__FUNCTION__,
564
+				__LINE__
565
+			);
566
+		}
567
+		// set no cache headers and constants
568
+		EE_System::do_not_cache();
569
+		$html = '<form method="POST" ';
570
+		$html .= 'action="' . $checkout_url . '" ';
571
+		$html .= 'name="ticket-selector-form-' . $ID . '"';
572
+		$html .= $this->iframe ? ' target="_blank"' : '';
573
+		$html .= '>';
574
+		$html .= '<input type="hidden" name="ee" value="process_ticket_selections">';
575
+		return apply_filters('FHEE__EE_Ticket_Selector__ticket_selector_form_open__html', $html, $this->event);
576
+	}
577
+
578
+
579
+	/**
580
+	 * displaySubmitButton
581
+	 *
582
+	 * @param string $external_url
583
+	 * @return string
584
+	 * @throws EE_Error
585
+	 * @throws ReflectionException
586
+	 */
587
+	public function displaySubmitButton($external_url = '')
588
+	{
589
+		$html = '';
590
+		if ($this->display_full_ui()) {
591
+			// standard TS displayed with submit button, ie: "Register Now"
592
+			if (apply_filters('FHEE__EE_Ticket_Selector__display_ticket_selector_submit', false)) {
593
+				$html .= $this->displayRegisterNowButton();
594
+				$html .= empty($external_url)
595
+					? $this->ticketSelectorEndDiv()
596
+					: $this->clearTicketSelector();
597
+				$html .= '<br/>' . $this->formClose();
598
+			} elseif ($this->getMaxAttendees() === 1) {
599
+				// its a "Dude Where's my Ticket Selector?" (DWMTS) type event (ie: $_max_atndz === 1)
600
+				if ($this->event->is_sold_out()) {
601
+					// then instead of a View Details or Submit button, just display a "Sold Out" message
602
+					$html .= apply_filters(
603
+						'FHEE__EE_Ticket_Selector__display_ticket_selector_submit__sold_out_msg',
604
+						sprintf(
605
+							__(
606
+								'%1$s"%2$s" is currently sold out.%4$sPlease check back again later, as spots may become available.%3$s',
607
+								'event_espresso'
608
+							),
609
+							'<p class="no-ticket-selector-msg clear-float">',
610
+							$this->event->name(),
611
+							'</p>',
612
+							'<br />'
613
+						),
614
+						$this->event
615
+					);
616
+					if (apply_filters(
617
+						'FHEE__EE_Ticket_Selector__display_ticket_selector_submit__no_tickets_but_display_register_now_button',
618
+						false,
619
+						$this->event
620
+					)) {
621
+						$html .= $this->displayRegisterNowButton();
622
+					}
623
+					// sold out DWMTS event, no TS, no submit or view details button, but has additional content
624
+					$html .= $this->ticketSelectorEndDiv();
625
+				} elseif (apply_filters('FHEE__EE_Ticket_Selector__hide_ticket_selector', false)
626
+						  && ! is_single()
627
+				) {
628
+					// this is a "Dude Where's my Ticket Selector?" (DWMTS) type event,
629
+					// but no tickets are available, so display event's "View Details" button.
630
+					// it is being viewed via somewhere other than a single post
631
+					$html .= $this->displayViewDetailsButton(true);
632
+				} else {
633
+					$html .= $this->ticketSelectorEndDiv();
634
+				}
635
+			} elseif (is_archive()) {
636
+				// event list, no tickets available so display event's "View Details" button
637
+				$html .= $this->ticketSelectorEndDiv();
638
+				$html .= $this->displayViewDetailsButton();
639
+			} else {
640
+				if (apply_filters(
641
+					'FHEE__EE_Ticket_Selector__display_ticket_selector_submit__no_tickets_but_display_register_now_button',
642
+					false,
643
+					$this->event
644
+				)) {
645
+					$html .= $this->displayRegisterNowButton();
646
+				}
647
+				// no submit or view details button, and no additional content
648
+				$html .= $this->ticketSelectorEndDiv();
649
+			}
650
+			if (! $this->iframe && ! is_archive()) {
651
+				$html .= EEH_Template::powered_by_event_espresso('', '', ['utm_content' => 'ticket_selector']);
652
+			}
653
+		}
654
+		return apply_filters(
655
+			'FHEE__EventEspresso_modules_ticket_selector_DisplayTicketSelector__displaySubmitButton__html',
656
+			$html,
657
+			$this->event,
658
+			$this
659
+		);
660
+	}
661
+
662
+
663
+	/**
664
+	 * @return string
665
+	 * @throws EE_Error
666
+	 * @throws ReflectionException
667
+	 */
668
+	public function displayRegisterNowButton()
669
+	{
670
+		$btn_text     = apply_filters(
671
+			'FHEE__EE_Ticket_Selector__display_ticket_selector_submit__btn_text',
672
+			__('Register Now', 'event_espresso'),
673
+			$this->event
674
+		);
675
+		$external_url = (string) $this->event->external_url()
676
+						&& $this->event->external_url() !== get_the_permalink()
677
+			? $this->event->external_url()
678
+			: '';
679
+		$html         = EEH_HTML::div(
680
+			'',
681
+			'ticket-selector-submit-' . $this->event->ID() . '-btn-wrap',
682
+			'ticket-selector-submit-btn-wrap'
683
+		);
684
+		$html         .= '<input id="ticket-selector-submit-' . $this->event->ID() . '-btn"';
685
+		$html         .= ' class="ticket-selector-submit-btn ';
686
+		$html         .= empty($external_url) ? 'ticket-selector-submit-ajax"' : '"';
687
+		$html         .= ' type="submit" value="' . $btn_text . '" data-ee-disable-after-recaptcha="true" />';
688
+		$html         .= EEH_HTML::divx() . '<!-- .ticket-selector-submit-btn-wrap -->';
689
+		$html         .= apply_filters(
690
+			'FHEE__EE_Ticket_Selector__after_ticket_selector_submit',
691
+			'',
692
+			$this->event,
693
+			$this->iframe
694
+		);
695
+		return $html;
696
+	}
697
+
698
+
699
+	/**
700
+	 * displayViewDetailsButton
701
+	 *
702
+	 * @param bool $DWMTS indicates a "Dude Where's my Ticket Selector?" (DWMTS) type event
703
+	 *                    (ie: $_max_atndz === 1) where there are no available tickets,
704
+	 *                    either because they are sold out, expired, or not yet on sale.
705
+	 *                    In this case, we need to close the form BEFORE adding any closing divs
706
+	 * @return string
707
+	 * @throws EE_Error
708
+	 * @throws ReflectionException
709
+	 */
710
+	public function displayViewDetailsButton($DWMTS = false)
711
+	{
712
+		if (! $this->event->get_permalink()) {
713
+			EE_Error::add_error(
714
+				esc_html__('The URL for the Event Details page could not be retrieved.', 'event_espresso'),
715
+				__FILE__,
716
+				__FUNCTION__,
717
+				__LINE__
718
+			);
719
+		}
720
+		$view_details_btn = '<form method="GET" action="';
721
+		$view_details_btn .= apply_filters(
722
+			'FHEE__EE_Ticket_Selector__display_view_details_btn__btn_url',
723
+			$this->event->get_permalink(),
724
+			$this->event
725
+		);
726
+		$view_details_btn .= '"';
727
+		// open link in new window ?
728
+		$view_details_btn .= apply_filters(
729
+			'FHEE__EventEspresso_modules_ticket_selector_DisplayTicketSelector__displayViewDetailsButton__url_target_blank',
730
+			$this->isIframe(),
731
+			$this
732
+		)
733
+			? ' target="_blank"'
734
+			: '';
735
+		$view_details_btn .= '>';
736
+		$btn_text         = apply_filters(
737
+			'FHEE__EE_Ticket_Selector__display_view_details_btn__btn_text',
738
+			esc_html__('View Details', 'event_espresso'),
739
+			$this->event
740
+		);
741
+		$view_details_btn .= '<input id="ticket-selector-submit-'
742
+							 . $this->event->ID()
743
+							 . '-btn" class="ticket-selector-submit-btn view-details-btn" type="submit" value="'
744
+							 . $btn_text
745
+							 . '" />';
746
+		$view_details_btn .= apply_filters('FHEE__EE_Ticket_Selector__after_view_details_btn', '', $this->event);
747
+		if ($DWMTS) {
748
+			$view_details_btn .= $this->formClose();
749
+			$view_details_btn .= $this->ticketSelectorEndDiv();
750
+			$view_details_btn .= '<br/>';
751
+		} else {
752
+			$view_details_btn .= $this->clearTicketSelector();
753
+			$view_details_btn .= '<br/>';
754
+			$view_details_btn .= $this->formClose();
755
+		}
756
+		return $view_details_btn;
757
+	}
758
+
759
+
760
+	/**
761
+	 * @return string
762
+	 */
763
+	public function ticketSelectorEndDiv()
764
+	{
765
+		return $this->clearTicketSelector() . '</div><!-- ticketSelectorEndDiv -->';
766
+	}
767
+
768
+
769
+	/**
770
+	 * @return string
771
+	 */
772
+	public function clearTicketSelector()
773
+	{
774
+		// standard TS displayed, appears after a "Register Now" or "view Details" button
775
+		return '<div class="clear"></div><!-- clearTicketSelector -->';
776
+	}
777
+
778
+
779
+	/**
780
+	 * @access        public
781
+	 * @return        string
782
+	 */
783
+	public function formClose()
784
+	{
785
+		return '</form>';
786
+	}
787
+
788
+
789
+	/**
790
+	 * handleMissingEvent
791
+	 * Returns either false or an error to display when no valid event is passed.
792
+	 *
793
+	 * @return string
794
+	 * @throws ExceptionStackTraceDisplay
795
+	 * @throws InvalidInterfaceException
796
+	 * @throws Exception
797
+	 */
798
+	protected function handleMissingEvent()
799
+	{
800
+		// If this is not an iFrame request, simply return false.
801
+		if (! $this->isIframe()) {
802
+			return '';
803
+		}
804
+		// This is an iFrame so return an error.
805
+		// Display stack trace if WP_DEBUG is enabled.
806
+		if (WP_DEBUG === true && current_user_can('edit_pages')) {
807
+			$event_id = $this->request->getRequestParam('event', 0, 'int');
808
+			new ExceptionStackTraceDisplay(
809
+				new InvalidArgumentException(
810
+					sprintf(
811
+						esc_html__(
812
+							'A valid Event ID is required to display the ticket selector.%3$sAn Event with an ID of "%1$s" could not be found.%3$sPlease verify that the embed code added to this post\'s content includes an "%2$s" argument and that its value corresponds to a valid Event ID.',
813
+							'event_espresso'
814
+						),
815
+						$event_id,
816
+						'event',
817
+						'<br />'
818
+					)
819
+				)
820
+			);
821
+			return '';
822
+		}
823
+		// If WP_DEBUG is not enabled, display a message stating the event could not be found.
824
+		return EEH_HTML::p(
825
+			esc_html__(
826
+				'A valid Event could not be found. Please contact the event administrator for assistance.',
827
+				'event_espresso'
828
+			)
829
+		);
830
+	}
831
+
832
+
833
+	/**
834
+	 * @return EE_Tax_Config
835
+	 * @since   $VID:$
836
+	 */
837
+	protected function getTaxConfig()
838
+	{
839
+		return isset(EE_Registry::instance()->CFG->tax_settings)
840
+			   && EE_Registry::instance()->CFG->tax_settings instanceof EE_Tax_Config
841
+			? EE_Registry::instance()->CFG->tax_settings
842
+			: new EE_Tax_Config();
843
+	}
844 844
 }
Please login to merge, or discard this patch.
Spacing   +32 added lines, -32 removed lines patch added patch discarded remove patch
@@ -153,11 +153,11 @@  discard block
 block discarded – undo
153 153
             }
154 154
         } else {
155 155
             $user_msg = __('No Event object or an invalid Event object was supplied.', 'event_espresso');
156
-            $dev_msg  = $user_msg . __(
156
+            $dev_msg  = $user_msg.__(
157 157
                     '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.',
158 158
                     'event_espresso'
159 159
                 );
160
-            EE_Error::add_error($user_msg . '||' . $dev_msg, __FILE__, __FUNCTION__, __LINE__);
160
+            EE_Error::add_error($user_msg.'||'.$dev_msg, __FILE__, __FUNCTION__, __LINE__);
161 161
             return false;
162 162
         }
163 163
         return true;
@@ -220,7 +220,7 @@  discard block
 block discarded – undo
220 220
         // reset filter for displaying submit button
221 221
         remove_filter('FHEE__EE_Ticket_Selector__display_ticket_selector_submit', '__return_true');
222 222
         // poke and prod incoming event till it tells us what it is
223
-        if (! $this->setEvent($event)) {
223
+        if ( ! $this->setEvent($event)) {
224 224
             return $this->handleMissingEvent();
225 225
         }
226 226
         // is the event expired ?
@@ -261,7 +261,7 @@  discard block
 block discarded – undo
261 261
             : $this->loadTicketSelector($tickets, $template_args);
262 262
         // now set up the form (but not for the admin)
263 263
         $ticket_selector = $this->display_full_ui()
264
-            ? $this->formOpen($this->event->ID(), $external_url) . $ticket_selector
264
+            ? $this->formOpen($this->event->ID(), $external_url).$ticket_selector
265 265
             : $ticket_selector;
266 266
         // submit button and form close tag
267 267
         $ticket_selector .= $this->display_full_ui() ? $this->displaySubmitButton($external_url) : '';
@@ -309,10 +309,10 @@  discard block
 block discarded – undo
309 309
      */
310 310
     protected function expiredEventMessage()
311 311
     {
312
-        return '<div class="ee-event-expired-notice"><span class="important-notice">' . esc_html__(
312
+        return '<div class="ee-event-expired-notice"><span class="important-notice">'.esc_html__(
313 313
                 'We\'re sorry, but all tickets sales have ended because the event is expired.',
314 314
                 'event_espresso'
315
-            ) . '</span></div><!-- .ee-event-expired-notice -->';
315
+            ).'</span></div><!-- .ee-event-expired-notice -->';
316 316
     }
317 317
 
318 318
 
@@ -343,7 +343,7 @@  discard block
 block discarded – undo
343 343
         }
344 344
         return '
345 345
             <div class="ee-event-expired-notice">
346
-                <span class="important-notice">' . $no_ticket_available_msg . '</span>
346
+                <span class="important-notice">' . $no_ticket_available_msg.'</span>
347 347
             </div><!-- .ee-event-expired-notice -->';
348 348
     }
349 349
 
@@ -376,7 +376,7 @@  discard block
 block discarded – undo
376 376
                 '</a></span></div><!-- .ee-attention ticketSalesClosedMessage -->'
377 377
             );
378 378
         }
379
-        return '<p><span class="important-notice">' . $sales_closed_msg . '</span></p>';
379
+        return '<p><span class="important-notice">'.$sales_closed_msg.'</span></p>';
380 380
     }
381 381
 
382 382
 
@@ -404,7 +404,7 @@  discard block
 block discarded – undo
404 404
                 'Datetime.DTT_EVT_start' => 'DESC',
405 405
             ],
406 406
         ];
407
-        if (! $show_expired_tickets) {
407
+        if ( ! $show_expired_tickets) {
408 408
             // use the correct applicable time query depending on what version of core is being run.
409 409
             $current_time                         = method_exists('EEM_Datetime', 'current_time_for_query')
410 410
                 ? time()
@@ -441,9 +441,9 @@  discard block
 block discarded – undo
441 441
          * @param int $EVT_ID The Event ID
442 442
          * @since 4.9.13
443 443
          */
444
-        $template_args['anchor_id']    = apply_filters(
444
+        $template_args['anchor_id'] = apply_filters(
445 445
             'FHEE__EE_Ticket_Selector__redirect_anchor_id',
446
-            '#tkt-slctr-tbl-' . $this->event->ID(),
446
+            '#tkt-slctr-tbl-'.$this->event->ID(),
447 447
             $this->event->ID()
448 448
         );
449 449
         $template_args['tickets']      = $tickets;
@@ -533,30 +533,30 @@  discard block
 block discarded – undo
533 533
         // if redirecting, we don't need any anything else
534 534
         if ($external_url) {
535 535
             $html = '<form method="GET" ';
536
-            $html .= 'action="' . EEH_URL::refactor_url($external_url) . '" ';
537
-            $html .= 'name="ticket-selector-form-' . $ID . '"';
536
+            $html .= 'action="'.EEH_URL::refactor_url($external_url).'" ';
537
+            $html .= 'name="ticket-selector-form-'.$ID.'"';
538 538
             // open link in new window ?
539
-            $html       .= apply_filters(
539
+            $html .= apply_filters(
540 540
                 'FHEE__EventEspresso_modules_ticket_selector_DisplayTicketSelector__formOpen__external_url_target_blank',
541 541
                 $this->isIframe(),
542 542
                 $this
543 543
             )
544 544
                 ? ' target="_blank"'
545 545
                 : '';
546
-            $html       .= '>';
546
+            $html .= '>';
547 547
             $query_args = EEH_URL::get_query_string($external_url);
548 548
             foreach ((array) $query_args as $query_arg => $value) {
549
-                $html .= '<input type="hidden" name="' . $query_arg . '" value="' . $value . '">';
549
+                $html .= '<input type="hidden" name="'.$query_arg.'" value="'.$value.'">';
550 550
             }
551 551
             return $html;
552 552
         }
553 553
         // if there is no submit button, then don't start building a form
554 554
         // because the "View Details" button will build its own form
555
-        if (! apply_filters('FHEE__EE_Ticket_Selector__display_ticket_selector_submit', false)) {
555
+        if ( ! apply_filters('FHEE__EE_Ticket_Selector__display_ticket_selector_submit', false)) {
556 556
             return '';
557 557
         }
558 558
         $checkout_url = EEH_Event_View::event_link_url($ID);
559
-        if (! $checkout_url) {
559
+        if ( ! $checkout_url) {
560 560
             EE_Error::add_error(
561 561
                 esc_html__('The URL for the Event Details page could not be retrieved.', 'event_espresso'),
562 562
                 __FILE__,
@@ -567,8 +567,8 @@  discard block
 block discarded – undo
567 567
         // set no cache headers and constants
568 568
         EE_System::do_not_cache();
569 569
         $html = '<form method="POST" ';
570
-        $html .= 'action="' . $checkout_url . '" ';
571
-        $html .= 'name="ticket-selector-form-' . $ID . '"';
570
+        $html .= 'action="'.$checkout_url.'" ';
571
+        $html .= 'name="ticket-selector-form-'.$ID.'"';
572 572
         $html .= $this->iframe ? ' target="_blank"' : '';
573 573
         $html .= '>';
574 574
         $html .= '<input type="hidden" name="ee" value="process_ticket_selections">';
@@ -594,7 +594,7 @@  discard block
 block discarded – undo
594 594
                 $html .= empty($external_url)
595 595
                     ? $this->ticketSelectorEndDiv()
596 596
                     : $this->clearTicketSelector();
597
-                $html .= '<br/>' . $this->formClose();
597
+                $html .= '<br/>'.$this->formClose();
598 598
             } elseif ($this->getMaxAttendees() === 1) {
599 599
                 // its a "Dude Where's my Ticket Selector?" (DWMTS) type event (ie: $_max_atndz === 1)
600 600
                 if ($this->event->is_sold_out()) {
@@ -647,7 +647,7 @@  discard block
 block discarded – undo
647 647
                 // no submit or view details button, and no additional content
648 648
                 $html .= $this->ticketSelectorEndDiv();
649 649
             }
650
-            if (! $this->iframe && ! is_archive()) {
650
+            if ( ! $this->iframe && ! is_archive()) {
651 651
                 $html .= EEH_Template::powered_by_event_espresso('', '', ['utm_content' => 'ticket_selector']);
652 652
             }
653 653
         }
@@ -667,7 +667,7 @@  discard block
 block discarded – undo
667 667
      */
668 668
     public function displayRegisterNowButton()
669 669
     {
670
-        $btn_text     = apply_filters(
670
+        $btn_text = apply_filters(
671 671
             'FHEE__EE_Ticket_Selector__display_ticket_selector_submit__btn_text',
672 672
             __('Register Now', 'event_espresso'),
673 673
             $this->event
@@ -676,16 +676,16 @@  discard block
 block discarded – undo
676 676
                         && $this->event->external_url() !== get_the_permalink()
677 677
             ? $this->event->external_url()
678 678
             : '';
679
-        $html         = EEH_HTML::div(
679
+        $html = EEH_HTML::div(
680 680
             '',
681
-            'ticket-selector-submit-' . $this->event->ID() . '-btn-wrap',
681
+            'ticket-selector-submit-'.$this->event->ID().'-btn-wrap',
682 682
             'ticket-selector-submit-btn-wrap'
683 683
         );
684
-        $html         .= '<input id="ticket-selector-submit-' . $this->event->ID() . '-btn"';
684
+        $html         .= '<input id="ticket-selector-submit-'.$this->event->ID().'-btn"';
685 685
         $html         .= ' class="ticket-selector-submit-btn ';
686 686
         $html         .= empty($external_url) ? 'ticket-selector-submit-ajax"' : '"';
687
-        $html         .= ' type="submit" value="' . $btn_text . '" data-ee-disable-after-recaptcha="true" />';
688
-        $html         .= EEH_HTML::divx() . '<!-- .ticket-selector-submit-btn-wrap -->';
687
+        $html         .= ' type="submit" value="'.$btn_text.'" data-ee-disable-after-recaptcha="true" />';
688
+        $html         .= EEH_HTML::divx().'<!-- .ticket-selector-submit-btn-wrap -->';
689 689
         $html         .= apply_filters(
690 690
             'FHEE__EE_Ticket_Selector__after_ticket_selector_submit',
691 691
             '',
@@ -709,7 +709,7 @@  discard block
 block discarded – undo
709 709
      */
710 710
     public function displayViewDetailsButton($DWMTS = false)
711 711
     {
712
-        if (! $this->event->get_permalink()) {
712
+        if ( ! $this->event->get_permalink()) {
713 713
             EE_Error::add_error(
714 714
                 esc_html__('The URL for the Event Details page could not be retrieved.', 'event_espresso'),
715 715
                 __FILE__,
@@ -733,7 +733,7 @@  discard block
 block discarded – undo
733 733
             ? ' target="_blank"'
734 734
             : '';
735 735
         $view_details_btn .= '>';
736
-        $btn_text         = apply_filters(
736
+        $btn_text = apply_filters(
737 737
             'FHEE__EE_Ticket_Selector__display_view_details_btn__btn_text',
738 738
             esc_html__('View Details', 'event_espresso'),
739 739
             $this->event
@@ -762,7 +762,7 @@  discard block
 block discarded – undo
762 762
      */
763 763
     public function ticketSelectorEndDiv()
764 764
     {
765
-        return $this->clearTicketSelector() . '</div><!-- ticketSelectorEndDiv -->';
765
+        return $this->clearTicketSelector().'</div><!-- ticketSelectorEndDiv -->';
766 766
     }
767 767
 
768 768
 
@@ -798,7 +798,7 @@  discard block
 block discarded – undo
798 798
     protected function handleMissingEvent()
799 799
     {
800 800
         // If this is not an iFrame request, simply return false.
801
-        if (! $this->isIframe()) {
801
+        if ( ! $this->isIframe()) {
802 802
             return '';
803 803
         }
804 804
         // This is an iFrame so return an error.
Please login to merge, or discard this patch.
modules/ticket_selector/EED_Ticket_Selector.module.php 2 patches
Indentation   +486 added lines, -486 removed lines patch added patch discarded remove patch
@@ -19,490 +19,490 @@
 block discarded – undo
19 19
 class EED_Ticket_Selector extends EED_Module
20 20
 {
21 21
 
22
-    /**
23
-     * @var DisplayTicketSelector $ticket_selector
24
-     */
25
-    private static $ticket_selector;
26
-
27
-    /**
28
-     * @var TicketSelectorIframeEmbedButton $iframe_embed_button
29
-     */
30
-    private static $iframe_embed_button;
31
-
32
-
33
-    /**
34
-     * @return EED_Module|EED_Ticket_Selector
35
-     * @throws EE_Error
36
-     * @throws ReflectionException
37
-     */
38
-    public static function instance()
39
-    {
40
-        return parent::get_instance(__CLASS__);
41
-    }
42
-
43
-
44
-    /**
45
-     * @return EE_Ticket_Selector_Config
46
-     * @throws EE_Error
47
-     * @throws ReflectionException
48
-     */
49
-    public static function ticketConfig()
50
-    {
51
-        EED_Ticket_Selector::instance()->set_config();
52
-        return EED_Ticket_Selector::instance()->config();
53
-    }
54
-
55
-
56
-    /**
57
-     * @return void
58
-     */
59
-    protected function set_config()
60
-    {
61
-        if ($this->_config instanceof EE_Ticket_Selector_Config) {
62
-            return;
63
-        }
64
-        $this->set_config_section('template_settings');
65
-        $this->set_config_class('EE_Ticket_Selector_Config');
66
-        $this->set_config_name('EED_Ticket_Selector');
67
-    }
68
-
69
-
70
-    /**
71
-     *    set_hooks - for hooking into EE Core, other modules, etc
72
-     *
73
-     * @return void
74
-     */
75
-    public static function set_hooks()
76
-    {
77
-        // routing
78
-        EE_Config::register_route(
79
-            'iframe',
80
-            'EED_Ticket_Selector',
81
-            'ticket_selector_iframe',
82
-            'ticket_selector'
83
-        );
84
-        EE_Config::register_route(
85
-            'process_ticket_selections',
86
-            'EED_Ticket_Selector',
87
-            'process_ticket_selections'
88
-        );
89
-        EE_Config::register_route(
90
-            'cancel_ticket_selections',
91
-            'EED_Ticket_Selector',
92
-            'cancel_ticket_selections'
93
-        );
94
-        add_action('wp_loaded', ['EED_Ticket_Selector', 'set_definitions'], 2);
95
-        add_action('AHEE_event_details_header_bottom', ['EED_Ticket_Selector', 'display_ticket_selector'], 10, 1);
96
-        add_action('wp_enqueue_scripts', ['EED_Ticket_Selector', 'translate_js_strings'], 0);
97
-        add_action('wp_enqueue_scripts', ['EED_Ticket_Selector', 'load_tckt_slctr_assets'], 10);
98
-        EED_Ticket_Selector::loadIframeAssets();
99
-    }
100
-
101
-
102
-    /**
103
-     *    set_hooks_admin - for hooking into EE Admin Core, other modules, etc
104
-     *
105
-     * @return void
106
-     */
107
-    public static function set_hooks_admin()
108
-    {
109
-        // hook into the end of the \EE_Admin_Page::_load_page_dependencies()
110
-        // to load assets for "espresso_events" page on the "edit" route (action)
111
-        add_action(
112
-            'FHEE__EE_Admin_Page___load_page_dependencies__after_load__espresso_events__edit',
113
-            ['EED_Ticket_Selector', 'ticket_selector_iframe_embed_button'],
114
-            10
115
-        );
116
-        /**
117
-         * Make sure assets for the ticket selector are loaded on the espresso registrations route so  admin side
118
-         * registrations work.
119
-         */
120
-        add_action(
121
-            'FHEE__EE_Admin_Page___load_page_dependencies__after_load__espresso_registrations__new_registration',
122
-            ['EED_Ticket_Selector', 'set_definitions'],
123
-            10
124
-        );
125
-    }
126
-
127
-
128
-    /**
129
-     *    set_definitions
130
-     *
131
-     * @return void
132
-     * @throws EE_Error
133
-     * @throws ReflectionException
134
-     */
135
-    public static function set_definitions()
136
-    {
137
-        // don't do this twice
138
-        if (defined('TICKET_SELECTOR_ASSETS_URL')) {
139
-            return;
140
-        }
141
-        define('TICKET_SELECTOR_ASSETS_URL', plugin_dir_url(__FILE__) . 'assets/');
142
-        define(
143
-            'TICKET_SELECTOR_TEMPLATES_PATH',
144
-            str_replace('\\', '/', plugin_dir_path(__FILE__)) . 'templates/'
145
-        );
146
-        // initialize config
147
-        EED_Ticket_Selector::instance()->set_config();
148
-        // if config is not set, initialize
149
-        if (! EE_Registry::instance()->CFG->template_settings->EED_Ticket_Selector instanceof EE_Ticket_Selector_Config
150
-        ) {
151
-            EED_Ticket_Selector::instance()->set_config();
152
-            EE_Registry::instance()->CFG->template_settings->EED_Ticket_Selector =
153
-                EED_Ticket_Selector::instance()->config();
154
-        }
155
-    }
156
-
157
-
158
-    /**
159
-     * @return DisplayTicketSelector
160
-     * @throws EE_Error
161
-     * @throws ReflectionException
162
-     */
163
-    public static function ticketSelector()
164
-    {
165
-        if (! EED_Ticket_Selector::$ticket_selector instanceof DisplayTicketSelector) {
166
-            EED_Ticket_Selector::$ticket_selector = new DisplayTicketSelector(
167
-                EED_Ticket_Selector::getRequest(),
168
-                EED_Ticket_Selector::ticketConfig(),
169
-                EED_Events_Archive::is_iframe()
170
-            );
171
-        }
172
-        return EED_Ticket_Selector::$ticket_selector;
173
-    }
174
-
175
-
176
-    /**
177
-     * gets the ball rolling
178
-     *
179
-     * @param WP $WP
180
-     * @return void
181
-     */
182
-    public function run($WP)
183
-    {
184
-    }
185
-
186
-
187
-    /**
188
-     * @return TicketSelectorIframeEmbedButton
189
-     */
190
-    public static function getIframeEmbedButton()
191
-    {
192
-        if (! self::$iframe_embed_button instanceof TicketSelectorIframeEmbedButton) {
193
-            self::$iframe_embed_button = new TicketSelectorIframeEmbedButton();
194
-        }
195
-        return self::$iframe_embed_button;
196
-    }
197
-
198
-
199
-    /**
200
-     * ticket_selector_iframe_embed_button
201
-     *
202
-     * @return void
203
-     */
204
-    public static function ticket_selector_iframe_embed_button()
205
-    {
206
-        $iframe_embed_button = EED_Ticket_Selector::getIframeEmbedButton();
207
-        $iframe_embed_button->addEventEditorIframeEmbedButton();
208
-    }
209
-
210
-
211
-    /**
212
-     * ticket_selector_iframe
213
-     *
214
-     * @return void
215
-     * @throws DomainException
216
-     */
217
-    public function ticket_selector_iframe()
218
-    {
219
-        EE_Dependency_Map::register_dependencies(
220
-            TicketSelectorIframe::class,
221
-            [
222
-                'EEM_Event'                                            => EE_Dependency_Map::load_from_cache,
223
-                'EventEspresso\core\services\request\CurrentPage'      => EE_Dependency_Map::load_from_cache,
224
-                'EventEspresso\core\services\request\RequestInterface' => EE_Dependency_Map::load_from_cache,
225
-            ]
226
-        );
227
-        $ticket_selector_iframe = LoaderFactory::getLoader()->getNew(TicketSelectorIframe::class);
228
-        $ticket_selector_iframe->display();
229
-    }
230
-
231
-
232
-    /**
233
-     * creates buttons for selecting number of attendees for an event
234
-     *
235
-     * @param WP_Post|int $event
236
-     * @param bool        $view_details
237
-     * @return string
238
-     * @throws EE_Error
239
-     * @throws ReflectionException
240
-     */
241
-    public static function display_ticket_selector($event = null, $view_details = false)
242
-    {
243
-        return EED_Ticket_Selector::ticketSelector()->display($event, $view_details);
244
-    }
245
-
246
-
247
-    /**
248
-     * @return bool  or FALSE
249
-     * @throws EE_Error
250
-     * @throws InvalidArgumentException
251
-     * @throws InvalidInterfaceException
252
-     * @throws InvalidDataTypeException
253
-     * @throws ReflectionException
254
-     */
255
-    public function process_ticket_selections()
256
-    {
257
-        /** @var EventEspresso\modules\ticket_selector\ProcessTicketSelector $form */
258
-        $form = LoaderFactory::getLoader()->getShared('EventEspresso\modules\ticket_selector\ProcessTicketSelector');
259
-        return $form->processTicketSelections();
260
-    }
261
-
262
-
263
-    /**
264
-     * @return bool
265
-     * @throws InvalidArgumentException
266
-     * @throws InvalidInterfaceException
267
-     * @throws InvalidDataTypeException
268
-     * @throws EE_Error
269
-     * @throws ReflectionException
270
-     */
271
-    public static function cancel_ticket_selections()
272
-    {
273
-        /** @var EventEspresso\modules\ticket_selector\ProcessTicketSelector $form */
274
-        $form = LoaderFactory::getLoader()->getShared('EventEspresso\modules\ticket_selector\ProcessTicketSelector');
275
-        return $form->cancelTicketSelections();
276
-    }
277
-
278
-
279
-    /**
280
-     * @return void
281
-     */
282
-    public static function translate_js_strings()
283
-    {
284
-        EE_Registry::$i18n_js_strings['please_select_date_filter_notice'] = esc_html__(
285
-            'please select a datetime',
286
-            'event_espresso'
287
-        );
288
-    }
289
-
290
-
291
-    /**
292
-     * @return void
293
-     */
294
-    public static function load_tckt_slctr_assets()
295
-    {
296
-        if (apply_filters('FHEE__EED_Ticket_Selector__load_tckt_slctr_assets', false)) {
297
-            // add some style
298
-            wp_register_style(
299
-                'ticket_selector',
300
-                TICKET_SELECTOR_ASSETS_URL . 'ticket_selector.css',
301
-                [],
302
-                EVENT_ESPRESSO_VERSION
303
-            );
304
-            wp_enqueue_style('ticket_selector');
305
-            // make it dance
306
-            wp_register_script(
307
-                'ticket_selector',
308
-                TICKET_SELECTOR_ASSETS_URL . 'ticket_selector.js',
309
-                ['espresso_core'],
310
-                EVENT_ESPRESSO_VERSION,
311
-                true
312
-            );
313
-            wp_enqueue_script('ticket_selector');
314
-            require_once EE_LIBRARIES
315
-                         . 'form_sections/strategies/display/EE_Checkbox_Dropdown_Selector_Display_Strategy.strategy.php';
316
-            EE_Checkbox_Dropdown_Selector_Display_Strategy::enqueue_styles_and_scripts();
317
-        }
318
-    }
319
-
320
-
321
-    /**
322
-     * @return void
323
-     */
324
-    public static function loadIframeAssets()
325
-    {
326
-        // for event lists
327
-        add_filter(
328
-            'FHEE__EventEspresso_modules_events_archive_EventsArchiveIframe__display__css',
329
-            ['EED_Ticket_Selector', 'iframeCss']
330
-        );
331
-        add_filter(
332
-            'FHEE__EventEspresso_modules_events_archive_EventsArchiveIframe__display__js',
333
-            ['EED_Ticket_Selector', 'iframeJs']
334
-        );
335
-        // for ticket selectors
336
-        add_filter(
337
-            'FHEE__EED_Ticket_Selector__ticket_selector_iframe__css',
338
-            ['EED_Ticket_Selector', 'iframeCss']
339
-        );
340
-        add_filter(
341
-            'FHEE__EED_Ticket_Selector__ticket_selector_iframe__js',
342
-            ['EED_Ticket_Selector', 'iframeJs']
343
-        );
344
-    }
345
-
346
-
347
-    /**
348
-     * Informs the rest of the forms system what CSS and JS is needed to display the input
349
-     *
350
-     * @param array $iframe_css
351
-     * @return array
352
-     */
353
-    public static function iframeCss(array $iframe_css)
354
-    {
355
-        $iframe_css['ticket_selector'] = TICKET_SELECTOR_ASSETS_URL . 'ticket_selector.css';
356
-        return $iframe_css;
357
-    }
358
-
359
-
360
-    /**
361
-     * Informs the rest of the forms system what CSS and JS is needed to display the input
362
-     *
363
-     * @param array $iframe_js
364
-     * @return array
365
-     */
366
-    public static function iframeJs(array $iframe_js)
367
-    {
368
-        $iframe_js['ticket_selector'] = TICKET_SELECTOR_ASSETS_URL . 'ticket_selector.js';
369
-        return $iframe_js;
370
-    }
371
-
372
-
373
-    /****************************** DEPRECATED ******************************/
374
-
375
-
376
-    /**
377
-     * @return string
378
-     * @throws EE_Error
379
-     * @throws ReflectionException
380
-     * @deprecated
381
-     */
382
-    public static function display_view_details_btn()
383
-    {
384
-        // todo add doing_it_wrong() notice during next major version
385
-        return EED_Ticket_Selector::ticketSelector()->displayViewDetailsButton();
386
-    }
387
-
388
-
389
-    /**
390
-     * @return string
391
-     * @throws EE_Error
392
-     * @throws ReflectionException
393
-     * @deprecated
394
-     */
395
-    public static function display_ticket_selector_submit()
396
-    {
397
-        // todo add doing_it_wrong() notice during next major version
398
-        return EED_Ticket_Selector::ticketSelector()->displaySubmitButton();
399
-    }
400
-
401
-
402
-    /**
403
-     * @param string $permalink_string
404
-     * @param int    $id
405
-     * @param string $new_title
406
-     * @param string $new_slug
407
-     * @return string
408
-     * @throws InvalidArgumentException
409
-     * @throws InvalidDataTypeException
410
-     * @throws InvalidInterfaceException
411
-     * @deprecated
412
-     */
413
-    public static function iframe_code_button($permalink_string, $id, $new_title = '', $new_slug = '')
414
-    {
415
-        $request = self::getRequest();
416
-        // todo add doing_it_wrong() notice during next major version
417
-        if (
418
-            $request->getRequestParam('page') === 'espresso_events'
419
-            && $request->getRequestParam('action') === 'edit'
420
-        ) {
421
-            $iframe_embed_button = EED_Ticket_Selector::getIframeEmbedButton();
422
-            $iframe_embed_button->addEventEditorIframeEmbedButton();
423
-        }
424
-        return '';
425
-    }
426
-
427
-
428
-    /**
429
-     * @param int    $ID
430
-     * @param string $external_url
431
-     * @return string
432
-     * @throws EE_Error
433
-     * @throws ReflectionException
434
-     * @deprecated
435
-     */
436
-    public static function ticket_selector_form_open($ID = 0, $external_url = '')
437
-    {
438
-        // todo add doing_it_wrong() notice during next major version
439
-        return EED_Ticket_Selector::ticketSelector()->formOpen($ID, $external_url);
440
-    }
441
-
442
-
443
-    /**
444
-     * @return string
445
-     * @throws EE_Error
446
-     * @throws ReflectionException
447
-     * @deprecated
448
-     */
449
-    public static function ticket_selector_form_close()
450
-    {
451
-        // todo add doing_it_wrong() notice during next major version
452
-        return EED_Ticket_Selector::ticketSelector()->formClose();
453
-    }
454
-
455
-
456
-    /**
457
-     * @return string
458
-     * @throws EE_Error
459
-     * @throws ReflectionException
460
-     * @deprecated
461
-     */
462
-    public static function no_tkt_slctr_end_dv()
463
-    {
464
-        // todo add doing_it_wrong() notice during next major version
465
-        return EED_Ticket_Selector::ticketSelector()->ticketSelectorEndDiv();
466
-    }
467
-
468
-
469
-    /**
470
-     * @return string
471
-     * @throws EE_Error
472
-     * @throws ReflectionException
473
-     * @deprecated 4.9.13
474
-     */
475
-    public static function tkt_slctr_end_dv()
476
-    {
477
-        return EED_Ticket_Selector::ticketSelector()->clearTicketSelector();
478
-    }
479
-
480
-
481
-    /**
482
-     * @return string
483
-     * @throws EE_Error
484
-     * @throws ReflectionException
485
-     * @deprecated
486
-     */
487
-    public static function clear_tkt_slctr()
488
-    {
489
-        return EED_Ticket_Selector::ticketSelector()->clearTicketSelector();
490
-    }
491
-
492
-
493
-    /**
494
-     * @deprecated
495
-     */
496
-    public static function load_tckt_slctr_assets_admin()
497
-    {
498
-        $request = self::getRequest();
499
-        // todo add doing_it_wrong() notice during next major version
500
-        if (
501
-            $request->getRequestParam('page') === 'espresso_events'
502
-            && $request->getRequestParam('action') === 'edit'
503
-        ) {
504
-            $iframe_embed_button = EED_Ticket_Selector::getIframeEmbedButton();
505
-            $iframe_embed_button->embedButtonAssets();
506
-        }
507
-    }
22
+	/**
23
+	 * @var DisplayTicketSelector $ticket_selector
24
+	 */
25
+	private static $ticket_selector;
26
+
27
+	/**
28
+	 * @var TicketSelectorIframeEmbedButton $iframe_embed_button
29
+	 */
30
+	private static $iframe_embed_button;
31
+
32
+
33
+	/**
34
+	 * @return EED_Module|EED_Ticket_Selector
35
+	 * @throws EE_Error
36
+	 * @throws ReflectionException
37
+	 */
38
+	public static function instance()
39
+	{
40
+		return parent::get_instance(__CLASS__);
41
+	}
42
+
43
+
44
+	/**
45
+	 * @return EE_Ticket_Selector_Config
46
+	 * @throws EE_Error
47
+	 * @throws ReflectionException
48
+	 */
49
+	public static function ticketConfig()
50
+	{
51
+		EED_Ticket_Selector::instance()->set_config();
52
+		return EED_Ticket_Selector::instance()->config();
53
+	}
54
+
55
+
56
+	/**
57
+	 * @return void
58
+	 */
59
+	protected function set_config()
60
+	{
61
+		if ($this->_config instanceof EE_Ticket_Selector_Config) {
62
+			return;
63
+		}
64
+		$this->set_config_section('template_settings');
65
+		$this->set_config_class('EE_Ticket_Selector_Config');
66
+		$this->set_config_name('EED_Ticket_Selector');
67
+	}
68
+
69
+
70
+	/**
71
+	 *    set_hooks - for hooking into EE Core, other modules, etc
72
+	 *
73
+	 * @return void
74
+	 */
75
+	public static function set_hooks()
76
+	{
77
+		// routing
78
+		EE_Config::register_route(
79
+			'iframe',
80
+			'EED_Ticket_Selector',
81
+			'ticket_selector_iframe',
82
+			'ticket_selector'
83
+		);
84
+		EE_Config::register_route(
85
+			'process_ticket_selections',
86
+			'EED_Ticket_Selector',
87
+			'process_ticket_selections'
88
+		);
89
+		EE_Config::register_route(
90
+			'cancel_ticket_selections',
91
+			'EED_Ticket_Selector',
92
+			'cancel_ticket_selections'
93
+		);
94
+		add_action('wp_loaded', ['EED_Ticket_Selector', 'set_definitions'], 2);
95
+		add_action('AHEE_event_details_header_bottom', ['EED_Ticket_Selector', 'display_ticket_selector'], 10, 1);
96
+		add_action('wp_enqueue_scripts', ['EED_Ticket_Selector', 'translate_js_strings'], 0);
97
+		add_action('wp_enqueue_scripts', ['EED_Ticket_Selector', 'load_tckt_slctr_assets'], 10);
98
+		EED_Ticket_Selector::loadIframeAssets();
99
+	}
100
+
101
+
102
+	/**
103
+	 *    set_hooks_admin - for hooking into EE Admin Core, other modules, etc
104
+	 *
105
+	 * @return void
106
+	 */
107
+	public static function set_hooks_admin()
108
+	{
109
+		// hook into the end of the \EE_Admin_Page::_load_page_dependencies()
110
+		// to load assets for "espresso_events" page on the "edit" route (action)
111
+		add_action(
112
+			'FHEE__EE_Admin_Page___load_page_dependencies__after_load__espresso_events__edit',
113
+			['EED_Ticket_Selector', 'ticket_selector_iframe_embed_button'],
114
+			10
115
+		);
116
+		/**
117
+		 * Make sure assets for the ticket selector are loaded on the espresso registrations route so  admin side
118
+		 * registrations work.
119
+		 */
120
+		add_action(
121
+			'FHEE__EE_Admin_Page___load_page_dependencies__after_load__espresso_registrations__new_registration',
122
+			['EED_Ticket_Selector', 'set_definitions'],
123
+			10
124
+		);
125
+	}
126
+
127
+
128
+	/**
129
+	 *    set_definitions
130
+	 *
131
+	 * @return void
132
+	 * @throws EE_Error
133
+	 * @throws ReflectionException
134
+	 */
135
+	public static function set_definitions()
136
+	{
137
+		// don't do this twice
138
+		if (defined('TICKET_SELECTOR_ASSETS_URL')) {
139
+			return;
140
+		}
141
+		define('TICKET_SELECTOR_ASSETS_URL', plugin_dir_url(__FILE__) . 'assets/');
142
+		define(
143
+			'TICKET_SELECTOR_TEMPLATES_PATH',
144
+			str_replace('\\', '/', plugin_dir_path(__FILE__)) . 'templates/'
145
+		);
146
+		// initialize config
147
+		EED_Ticket_Selector::instance()->set_config();
148
+		// if config is not set, initialize
149
+		if (! EE_Registry::instance()->CFG->template_settings->EED_Ticket_Selector instanceof EE_Ticket_Selector_Config
150
+		) {
151
+			EED_Ticket_Selector::instance()->set_config();
152
+			EE_Registry::instance()->CFG->template_settings->EED_Ticket_Selector =
153
+				EED_Ticket_Selector::instance()->config();
154
+		}
155
+	}
156
+
157
+
158
+	/**
159
+	 * @return DisplayTicketSelector
160
+	 * @throws EE_Error
161
+	 * @throws ReflectionException
162
+	 */
163
+	public static function ticketSelector()
164
+	{
165
+		if (! EED_Ticket_Selector::$ticket_selector instanceof DisplayTicketSelector) {
166
+			EED_Ticket_Selector::$ticket_selector = new DisplayTicketSelector(
167
+				EED_Ticket_Selector::getRequest(),
168
+				EED_Ticket_Selector::ticketConfig(),
169
+				EED_Events_Archive::is_iframe()
170
+			);
171
+		}
172
+		return EED_Ticket_Selector::$ticket_selector;
173
+	}
174
+
175
+
176
+	/**
177
+	 * gets the ball rolling
178
+	 *
179
+	 * @param WP $WP
180
+	 * @return void
181
+	 */
182
+	public function run($WP)
183
+	{
184
+	}
185
+
186
+
187
+	/**
188
+	 * @return TicketSelectorIframeEmbedButton
189
+	 */
190
+	public static function getIframeEmbedButton()
191
+	{
192
+		if (! self::$iframe_embed_button instanceof TicketSelectorIframeEmbedButton) {
193
+			self::$iframe_embed_button = new TicketSelectorIframeEmbedButton();
194
+		}
195
+		return self::$iframe_embed_button;
196
+	}
197
+
198
+
199
+	/**
200
+	 * ticket_selector_iframe_embed_button
201
+	 *
202
+	 * @return void
203
+	 */
204
+	public static function ticket_selector_iframe_embed_button()
205
+	{
206
+		$iframe_embed_button = EED_Ticket_Selector::getIframeEmbedButton();
207
+		$iframe_embed_button->addEventEditorIframeEmbedButton();
208
+	}
209
+
210
+
211
+	/**
212
+	 * ticket_selector_iframe
213
+	 *
214
+	 * @return void
215
+	 * @throws DomainException
216
+	 */
217
+	public function ticket_selector_iframe()
218
+	{
219
+		EE_Dependency_Map::register_dependencies(
220
+			TicketSelectorIframe::class,
221
+			[
222
+				'EEM_Event'                                            => EE_Dependency_Map::load_from_cache,
223
+				'EventEspresso\core\services\request\CurrentPage'      => EE_Dependency_Map::load_from_cache,
224
+				'EventEspresso\core\services\request\RequestInterface' => EE_Dependency_Map::load_from_cache,
225
+			]
226
+		);
227
+		$ticket_selector_iframe = LoaderFactory::getLoader()->getNew(TicketSelectorIframe::class);
228
+		$ticket_selector_iframe->display();
229
+	}
230
+
231
+
232
+	/**
233
+	 * creates buttons for selecting number of attendees for an event
234
+	 *
235
+	 * @param WP_Post|int $event
236
+	 * @param bool        $view_details
237
+	 * @return string
238
+	 * @throws EE_Error
239
+	 * @throws ReflectionException
240
+	 */
241
+	public static function display_ticket_selector($event = null, $view_details = false)
242
+	{
243
+		return EED_Ticket_Selector::ticketSelector()->display($event, $view_details);
244
+	}
245
+
246
+
247
+	/**
248
+	 * @return bool  or FALSE
249
+	 * @throws EE_Error
250
+	 * @throws InvalidArgumentException
251
+	 * @throws InvalidInterfaceException
252
+	 * @throws InvalidDataTypeException
253
+	 * @throws ReflectionException
254
+	 */
255
+	public function process_ticket_selections()
256
+	{
257
+		/** @var EventEspresso\modules\ticket_selector\ProcessTicketSelector $form */
258
+		$form = LoaderFactory::getLoader()->getShared('EventEspresso\modules\ticket_selector\ProcessTicketSelector');
259
+		return $form->processTicketSelections();
260
+	}
261
+
262
+
263
+	/**
264
+	 * @return bool
265
+	 * @throws InvalidArgumentException
266
+	 * @throws InvalidInterfaceException
267
+	 * @throws InvalidDataTypeException
268
+	 * @throws EE_Error
269
+	 * @throws ReflectionException
270
+	 */
271
+	public static function cancel_ticket_selections()
272
+	{
273
+		/** @var EventEspresso\modules\ticket_selector\ProcessTicketSelector $form */
274
+		$form = LoaderFactory::getLoader()->getShared('EventEspresso\modules\ticket_selector\ProcessTicketSelector');
275
+		return $form->cancelTicketSelections();
276
+	}
277
+
278
+
279
+	/**
280
+	 * @return void
281
+	 */
282
+	public static function translate_js_strings()
283
+	{
284
+		EE_Registry::$i18n_js_strings['please_select_date_filter_notice'] = esc_html__(
285
+			'please select a datetime',
286
+			'event_espresso'
287
+		);
288
+	}
289
+
290
+
291
+	/**
292
+	 * @return void
293
+	 */
294
+	public static function load_tckt_slctr_assets()
295
+	{
296
+		if (apply_filters('FHEE__EED_Ticket_Selector__load_tckt_slctr_assets', false)) {
297
+			// add some style
298
+			wp_register_style(
299
+				'ticket_selector',
300
+				TICKET_SELECTOR_ASSETS_URL . 'ticket_selector.css',
301
+				[],
302
+				EVENT_ESPRESSO_VERSION
303
+			);
304
+			wp_enqueue_style('ticket_selector');
305
+			// make it dance
306
+			wp_register_script(
307
+				'ticket_selector',
308
+				TICKET_SELECTOR_ASSETS_URL . 'ticket_selector.js',
309
+				['espresso_core'],
310
+				EVENT_ESPRESSO_VERSION,
311
+				true
312
+			);
313
+			wp_enqueue_script('ticket_selector');
314
+			require_once EE_LIBRARIES
315
+						 . 'form_sections/strategies/display/EE_Checkbox_Dropdown_Selector_Display_Strategy.strategy.php';
316
+			EE_Checkbox_Dropdown_Selector_Display_Strategy::enqueue_styles_and_scripts();
317
+		}
318
+	}
319
+
320
+
321
+	/**
322
+	 * @return void
323
+	 */
324
+	public static function loadIframeAssets()
325
+	{
326
+		// for event lists
327
+		add_filter(
328
+			'FHEE__EventEspresso_modules_events_archive_EventsArchiveIframe__display__css',
329
+			['EED_Ticket_Selector', 'iframeCss']
330
+		);
331
+		add_filter(
332
+			'FHEE__EventEspresso_modules_events_archive_EventsArchiveIframe__display__js',
333
+			['EED_Ticket_Selector', 'iframeJs']
334
+		);
335
+		// for ticket selectors
336
+		add_filter(
337
+			'FHEE__EED_Ticket_Selector__ticket_selector_iframe__css',
338
+			['EED_Ticket_Selector', 'iframeCss']
339
+		);
340
+		add_filter(
341
+			'FHEE__EED_Ticket_Selector__ticket_selector_iframe__js',
342
+			['EED_Ticket_Selector', 'iframeJs']
343
+		);
344
+	}
345
+
346
+
347
+	/**
348
+	 * Informs the rest of the forms system what CSS and JS is needed to display the input
349
+	 *
350
+	 * @param array $iframe_css
351
+	 * @return array
352
+	 */
353
+	public static function iframeCss(array $iframe_css)
354
+	{
355
+		$iframe_css['ticket_selector'] = TICKET_SELECTOR_ASSETS_URL . 'ticket_selector.css';
356
+		return $iframe_css;
357
+	}
358
+
359
+
360
+	/**
361
+	 * Informs the rest of the forms system what CSS and JS is needed to display the input
362
+	 *
363
+	 * @param array $iframe_js
364
+	 * @return array
365
+	 */
366
+	public static function iframeJs(array $iframe_js)
367
+	{
368
+		$iframe_js['ticket_selector'] = TICKET_SELECTOR_ASSETS_URL . 'ticket_selector.js';
369
+		return $iframe_js;
370
+	}
371
+
372
+
373
+	/****************************** DEPRECATED ******************************/
374
+
375
+
376
+	/**
377
+	 * @return string
378
+	 * @throws EE_Error
379
+	 * @throws ReflectionException
380
+	 * @deprecated
381
+	 */
382
+	public static function display_view_details_btn()
383
+	{
384
+		// todo add doing_it_wrong() notice during next major version
385
+		return EED_Ticket_Selector::ticketSelector()->displayViewDetailsButton();
386
+	}
387
+
388
+
389
+	/**
390
+	 * @return string
391
+	 * @throws EE_Error
392
+	 * @throws ReflectionException
393
+	 * @deprecated
394
+	 */
395
+	public static function display_ticket_selector_submit()
396
+	{
397
+		// todo add doing_it_wrong() notice during next major version
398
+		return EED_Ticket_Selector::ticketSelector()->displaySubmitButton();
399
+	}
400
+
401
+
402
+	/**
403
+	 * @param string $permalink_string
404
+	 * @param int    $id
405
+	 * @param string $new_title
406
+	 * @param string $new_slug
407
+	 * @return string
408
+	 * @throws InvalidArgumentException
409
+	 * @throws InvalidDataTypeException
410
+	 * @throws InvalidInterfaceException
411
+	 * @deprecated
412
+	 */
413
+	public static function iframe_code_button($permalink_string, $id, $new_title = '', $new_slug = '')
414
+	{
415
+		$request = self::getRequest();
416
+		// todo add doing_it_wrong() notice during next major version
417
+		if (
418
+			$request->getRequestParam('page') === 'espresso_events'
419
+			&& $request->getRequestParam('action') === 'edit'
420
+		) {
421
+			$iframe_embed_button = EED_Ticket_Selector::getIframeEmbedButton();
422
+			$iframe_embed_button->addEventEditorIframeEmbedButton();
423
+		}
424
+		return '';
425
+	}
426
+
427
+
428
+	/**
429
+	 * @param int    $ID
430
+	 * @param string $external_url
431
+	 * @return string
432
+	 * @throws EE_Error
433
+	 * @throws ReflectionException
434
+	 * @deprecated
435
+	 */
436
+	public static function ticket_selector_form_open($ID = 0, $external_url = '')
437
+	{
438
+		// todo add doing_it_wrong() notice during next major version
439
+		return EED_Ticket_Selector::ticketSelector()->formOpen($ID, $external_url);
440
+	}
441
+
442
+
443
+	/**
444
+	 * @return string
445
+	 * @throws EE_Error
446
+	 * @throws ReflectionException
447
+	 * @deprecated
448
+	 */
449
+	public static function ticket_selector_form_close()
450
+	{
451
+		// todo add doing_it_wrong() notice during next major version
452
+		return EED_Ticket_Selector::ticketSelector()->formClose();
453
+	}
454
+
455
+
456
+	/**
457
+	 * @return string
458
+	 * @throws EE_Error
459
+	 * @throws ReflectionException
460
+	 * @deprecated
461
+	 */
462
+	public static function no_tkt_slctr_end_dv()
463
+	{
464
+		// todo add doing_it_wrong() notice during next major version
465
+		return EED_Ticket_Selector::ticketSelector()->ticketSelectorEndDiv();
466
+	}
467
+
468
+
469
+	/**
470
+	 * @return string
471
+	 * @throws EE_Error
472
+	 * @throws ReflectionException
473
+	 * @deprecated 4.9.13
474
+	 */
475
+	public static function tkt_slctr_end_dv()
476
+	{
477
+		return EED_Ticket_Selector::ticketSelector()->clearTicketSelector();
478
+	}
479
+
480
+
481
+	/**
482
+	 * @return string
483
+	 * @throws EE_Error
484
+	 * @throws ReflectionException
485
+	 * @deprecated
486
+	 */
487
+	public static function clear_tkt_slctr()
488
+	{
489
+		return EED_Ticket_Selector::ticketSelector()->clearTicketSelector();
490
+	}
491
+
492
+
493
+	/**
494
+	 * @deprecated
495
+	 */
496
+	public static function load_tckt_slctr_assets_admin()
497
+	{
498
+		$request = self::getRequest();
499
+		// todo add doing_it_wrong() notice during next major version
500
+		if (
501
+			$request->getRequestParam('page') === 'espresso_events'
502
+			&& $request->getRequestParam('action') === 'edit'
503
+		) {
504
+			$iframe_embed_button = EED_Ticket_Selector::getIframeEmbedButton();
505
+			$iframe_embed_button->embedButtonAssets();
506
+		}
507
+	}
508 508
 }
Please login to merge, or discard this patch.
Spacing   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -138,15 +138,15 @@  discard block
 block discarded – undo
138 138
         if (defined('TICKET_SELECTOR_ASSETS_URL')) {
139 139
             return;
140 140
         }
141
-        define('TICKET_SELECTOR_ASSETS_URL', plugin_dir_url(__FILE__) . 'assets/');
141
+        define('TICKET_SELECTOR_ASSETS_URL', plugin_dir_url(__FILE__).'assets/');
142 142
         define(
143 143
             'TICKET_SELECTOR_TEMPLATES_PATH',
144
-            str_replace('\\', '/', plugin_dir_path(__FILE__)) . 'templates/'
144
+            str_replace('\\', '/', plugin_dir_path(__FILE__)).'templates/'
145 145
         );
146 146
         // initialize config
147 147
         EED_Ticket_Selector::instance()->set_config();
148 148
         // if config is not set, initialize
149
-        if (! EE_Registry::instance()->CFG->template_settings->EED_Ticket_Selector instanceof EE_Ticket_Selector_Config
149
+        if ( ! EE_Registry::instance()->CFG->template_settings->EED_Ticket_Selector instanceof EE_Ticket_Selector_Config
150 150
         ) {
151 151
             EED_Ticket_Selector::instance()->set_config();
152 152
             EE_Registry::instance()->CFG->template_settings->EED_Ticket_Selector =
@@ -162,7 +162,7 @@  discard block
 block discarded – undo
162 162
      */
163 163
     public static function ticketSelector()
164 164
     {
165
-        if (! EED_Ticket_Selector::$ticket_selector instanceof DisplayTicketSelector) {
165
+        if ( ! EED_Ticket_Selector::$ticket_selector instanceof DisplayTicketSelector) {
166 166
             EED_Ticket_Selector::$ticket_selector = new DisplayTicketSelector(
167 167
                 EED_Ticket_Selector::getRequest(),
168 168
                 EED_Ticket_Selector::ticketConfig(),
@@ -189,7 +189,7 @@  discard block
 block discarded – undo
189 189
      */
190 190
     public static function getIframeEmbedButton()
191 191
     {
192
-        if (! self::$iframe_embed_button instanceof TicketSelectorIframeEmbedButton) {
192
+        if ( ! self::$iframe_embed_button instanceof TicketSelectorIframeEmbedButton) {
193 193
             self::$iframe_embed_button = new TicketSelectorIframeEmbedButton();
194 194
         }
195 195
         return self::$iframe_embed_button;
@@ -297,7 +297,7 @@  discard block
 block discarded – undo
297 297
             // add some style
298 298
             wp_register_style(
299 299
                 'ticket_selector',
300
-                TICKET_SELECTOR_ASSETS_URL . 'ticket_selector.css',
300
+                TICKET_SELECTOR_ASSETS_URL.'ticket_selector.css',
301 301
                 [],
302 302
                 EVENT_ESPRESSO_VERSION
303 303
             );
@@ -305,7 +305,7 @@  discard block
 block discarded – undo
305 305
             // make it dance
306 306
             wp_register_script(
307 307
                 'ticket_selector',
308
-                TICKET_SELECTOR_ASSETS_URL . 'ticket_selector.js',
308
+                TICKET_SELECTOR_ASSETS_URL.'ticket_selector.js',
309 309
                 ['espresso_core'],
310 310
                 EVENT_ESPRESSO_VERSION,
311 311
                 true
@@ -352,7 +352,7 @@  discard block
 block discarded – undo
352 352
      */
353 353
     public static function iframeCss(array $iframe_css)
354 354
     {
355
-        $iframe_css['ticket_selector'] = TICKET_SELECTOR_ASSETS_URL . 'ticket_selector.css';
355
+        $iframe_css['ticket_selector'] = TICKET_SELECTOR_ASSETS_URL.'ticket_selector.css';
356 356
         return $iframe_css;
357 357
     }
358 358
 
@@ -365,7 +365,7 @@  discard block
 block discarded – undo
365 365
      */
366 366
     public static function iframeJs(array $iframe_js)
367 367
     {
368
-        $iframe_js['ticket_selector'] = TICKET_SELECTOR_ASSETS_URL . 'ticket_selector.js';
368
+        $iframe_js['ticket_selector'] = TICKET_SELECTOR_ASSETS_URL.'ticket_selector.js';
369 369
         return $iframe_js;
370 370
     }
371 371
 
Please login to merge, or discard this patch.
modules/ticket_selector/ProcessTicketSelector.php 2 patches
Indentation   +492 added lines, -492 removed lines patch added patch discarded remove patch
@@ -33,521 +33,521 @@
 block discarded – undo
33 33
 class ProcessTicketSelector
34 34
 {
35 35
 
36
-    /**
37
-     * @var EE_Cart $cart
38
-     */
39
-    private $cart;
36
+	/**
37
+	 * @var EE_Cart $cart
38
+	 */
39
+	private $cart;
40 40
 
41
-    /**
42
-     * @var EE_Core_Config $core_config
43
-     */
44
-    private $core_config;
41
+	/**
42
+	 * @var EE_Core_Config $core_config
43
+	 */
44
+	private $core_config;
45 45
 
46
-    /**
47
-     * @var Request $request
48
-     */
49
-    private $request;
46
+	/**
47
+	 * @var Request $request
48
+	 */
49
+	private $request;
50 50
 
51
-    /**
52
-     * @var EE_Session $session
53
-     */
54
-    private $session;
51
+	/**
52
+	 * @var EE_Session $session
53
+	 */
54
+	private $session;
55 55
 
56
-    /**
57
-     * @var EEM_Ticket $ticket_model
58
-     */
59
-    private $ticket_model;
56
+	/**
57
+	 * @var EEM_Ticket $ticket_model
58
+	 */
59
+	private $ticket_model;
60 60
 
61
-    /**
62
-     * @var TicketDatetimeAvailabilityTracker $tracker
63
-     */
64
-    private $tracker;
61
+	/**
62
+	 * @var TicketDatetimeAvailabilityTracker $tracker
63
+	 */
64
+	private $tracker;
65 65
 
66 66
 
67
-    /**
68
-     * ProcessTicketSelector constructor.
69
-     * NOTE: PLZ use the Loader to instantiate this class if need be
70
-     * so that all dependencies get injected correctly (which will happen automatically)
71
-     * Null values for parameters are only for backwards compatibility but will be removed later on.
72
-     *
73
-     * @param EE_Core_Config                    $core_config
74
-     * @param Request                           $request
75
-     * @param EE_Session                        $session
76
-     * @param EEM_Ticket                        $ticket_model
77
-     * @param TicketDatetimeAvailabilityTracker $tracker
78
-     * @throws InvalidArgumentException
79
-     * @throws InvalidDataTypeException
80
-     * @throws InvalidInterfaceException
81
-     */
82
-    public function __construct(
83
-        EE_Core_Config $core_config = null,
84
-        Request $request = null,
85
-        EE_Session $session = null,
86
-        EEM_Ticket $ticket_model = null,
87
-        TicketDatetimeAvailabilityTracker $tracker = null
88
-    ) {
89
-        $loader = LoaderFactory::getLoader();
90
-        $this->core_config = $core_config instanceof EE_Core_Config
91
-            ? $core_config
92
-            : $loader->getShared('EE_Core_Config');
93
-        $this->request = $request instanceof Request
94
-            ? $request
95
-            : $loader->getShared('EventEspresso\core\services\request\Request');
96
-        $this->session = $session instanceof EE_Session
97
-            ? $session
98
-            : $loader->getShared('EE_Session');
99
-        $this->ticket_model = $ticket_model instanceof EEM_Ticket
100
-            ? $ticket_model
101
-            : $loader->getShared('EEM_Ticket');
102
-        $this->tracker = $tracker instanceof TicketDatetimeAvailabilityTracker
103
-            ? $tracker
104
-            : $loader->getShared('EventEspresso\modules\ticket_selector\TicketDatetimeAvailabilityTracker');
105
-    }
67
+	/**
68
+	 * ProcessTicketSelector constructor.
69
+	 * NOTE: PLZ use the Loader to instantiate this class if need be
70
+	 * so that all dependencies get injected correctly (which will happen automatically)
71
+	 * Null values for parameters are only for backwards compatibility but will be removed later on.
72
+	 *
73
+	 * @param EE_Core_Config                    $core_config
74
+	 * @param Request                           $request
75
+	 * @param EE_Session                        $session
76
+	 * @param EEM_Ticket                        $ticket_model
77
+	 * @param TicketDatetimeAvailabilityTracker $tracker
78
+	 * @throws InvalidArgumentException
79
+	 * @throws InvalidDataTypeException
80
+	 * @throws InvalidInterfaceException
81
+	 */
82
+	public function __construct(
83
+		EE_Core_Config $core_config = null,
84
+		Request $request = null,
85
+		EE_Session $session = null,
86
+		EEM_Ticket $ticket_model = null,
87
+		TicketDatetimeAvailabilityTracker $tracker = null
88
+	) {
89
+		$loader = LoaderFactory::getLoader();
90
+		$this->core_config = $core_config instanceof EE_Core_Config
91
+			? $core_config
92
+			: $loader->getShared('EE_Core_Config');
93
+		$this->request = $request instanceof Request
94
+			? $request
95
+			: $loader->getShared('EventEspresso\core\services\request\Request');
96
+		$this->session = $session instanceof EE_Session
97
+			? $session
98
+			: $loader->getShared('EE_Session');
99
+		$this->ticket_model = $ticket_model instanceof EEM_Ticket
100
+			? $ticket_model
101
+			: $loader->getShared('EEM_Ticket');
102
+		$this->tracker = $tracker instanceof TicketDatetimeAvailabilityTracker
103
+			? $tracker
104
+			: $loader->getShared('EventEspresso\modules\ticket_selector\TicketDatetimeAvailabilityTracker');
105
+	}
106 106
 
107 107
 
108
-    /**
109
-     * cancelTicketSelections
110
-     *
111
-     * @return bool
112
-     * @throws EE_Error
113
-     * @throws InvalidArgumentException
114
-     * @throws InvalidInterfaceException
115
-     * @throws InvalidDataTypeException
116
-     * @throws ReflectionException
117
-     */
118
-    public function cancelTicketSelections()
119
-    {
120
-        // check nonce
121
-        if (! $this->processTicketSelectorNonce('cancel_ticket_selections')) {
122
-            return false;
123
-        }
124
-        $this->session->clear_session(__CLASS__, __FUNCTION__);
125
-        if ($this->request->requestParamIsSet('event_id')) {
126
-            EEH_URL::safeRedirectAndExit(
127
-                EEH_Event_View::event_link_url(
128
-                    $this->request->getRequestParam('event_id')
129
-                )
130
-            );
131
-        }
132
-        EEH_URL::safeRedirectAndExit(
133
-            site_url('/' . $this->core_config->event_cpt_slug . '/')
134
-        );
135
-        return true;
136
-    }
108
+	/**
109
+	 * cancelTicketSelections
110
+	 *
111
+	 * @return bool
112
+	 * @throws EE_Error
113
+	 * @throws InvalidArgumentException
114
+	 * @throws InvalidInterfaceException
115
+	 * @throws InvalidDataTypeException
116
+	 * @throws ReflectionException
117
+	 */
118
+	public function cancelTicketSelections()
119
+	{
120
+		// check nonce
121
+		if (! $this->processTicketSelectorNonce('cancel_ticket_selections')) {
122
+			return false;
123
+		}
124
+		$this->session->clear_session(__CLASS__, __FUNCTION__);
125
+		if ($this->request->requestParamIsSet('event_id')) {
126
+			EEH_URL::safeRedirectAndExit(
127
+				EEH_Event_View::event_link_url(
128
+					$this->request->getRequestParam('event_id')
129
+				)
130
+			);
131
+		}
132
+		EEH_URL::safeRedirectAndExit(
133
+			site_url('/' . $this->core_config->event_cpt_slug . '/')
134
+		);
135
+		return true;
136
+	}
137 137
 
138 138
 
139
-    /**
140
-     * processTicketSelectorNonce
141
-     *
142
-     * @param  string $nonce_name
143
-     * @param string  $id
144
-     * @return bool
145
-     */
146
-    private function processTicketSelectorNonce($nonce_name, $id = '')
147
-    {
148
-        $nonce_name_with_id = ! empty($id) ? "{$nonce_name}_nonce_{$id}" : "{$nonce_name}_nonce";
149
-        if (! $this->request->isAdmin()
150
-            && (
151
-                ! $this->request->is_set($nonce_name_with_id)
152
-                || ! wp_verify_nonce(
153
-                    $this->request->get($nonce_name_with_id),
154
-                    $nonce_name
155
-                )
156
-            )
157
-        ) {
158
-            EE_Error::add_error(
159
-                sprintf(
160
-                    esc_html__(
161
-                        'We\'re sorry but your request failed to pass a security check.%sPlease click the back button on your browser and try again.',
162
-                        'event_espresso'
163
-                    ),
164
-                    '<br/>'
165
-                ),
166
-                __FILE__,
167
-                __FUNCTION__,
168
-                __LINE__
169
-            );
170
-            return false;
171
-        }
172
-        return true;
173
-    }
139
+	/**
140
+	 * processTicketSelectorNonce
141
+	 *
142
+	 * @param  string $nonce_name
143
+	 * @param string  $id
144
+	 * @return bool
145
+	 */
146
+	private function processTicketSelectorNonce($nonce_name, $id = '')
147
+	{
148
+		$nonce_name_with_id = ! empty($id) ? "{$nonce_name}_nonce_{$id}" : "{$nonce_name}_nonce";
149
+		if (! $this->request->isAdmin()
150
+			&& (
151
+				! $this->request->is_set($nonce_name_with_id)
152
+				|| ! wp_verify_nonce(
153
+					$this->request->get($nonce_name_with_id),
154
+					$nonce_name
155
+				)
156
+			)
157
+		) {
158
+			EE_Error::add_error(
159
+				sprintf(
160
+					esc_html__(
161
+						'We\'re sorry but your request failed to pass a security check.%sPlease click the back button on your browser and try again.',
162
+						'event_espresso'
163
+					),
164
+					'<br/>'
165
+				),
166
+				__FILE__,
167
+				__FUNCTION__,
168
+				__LINE__
169
+			);
170
+			return false;
171
+		}
172
+		return true;
173
+	}
174 174
 
175 175
 
176
-    /**
177
-     * process_ticket_selections
178
-     *
179
-     * @return bool
180
-     * @throws EE_Error
181
-     * @throws InvalidArgumentException
182
-     * @throws InvalidDataTypeException
183
-     * @throws InvalidInterfaceException
184
-     * @throws ReflectionException
185
-     */
186
-    public function processTicketSelections()
187
-    {
188
-        do_action('EED_Ticket_Selector__process_ticket_selections__before');
189
-        if ($this->request->isBot()) {
190
-            EEH_URL::safeRedirectAndExit(
191
-                apply_filters(
192
-                    'FHEE__EE_Ticket_Selector__process_ticket_selections__bot_redirect_url',
193
-                    site_url()
194
-                )
195
-            );
196
-        }
197
-        // do we have an event id?
198
-        $id = $this->getEventId();
199
-        // we should really only have 1 registration in the works now
200
-        // (ie, no MER) so unless otherwise requested, clear the session
201
-        if (apply_filters('FHEE__EE_Ticket_Selector__process_ticket_selections__clear_session', true)) {
202
-            $this->session->clear_session(__CLASS__, __FUNCTION__);
203
-        }
204
-        // validate/sanitize/filter data
205
-        $valid = apply_filters(
206
-            'FHEE__EED_Ticket_Selector__process_ticket_selections__valid_post_data',
207
-            $this->validatePostData($id)
208
-        );
209
-        // check total tickets ordered vs max number of attendees that can register
210
-        if (! empty($valid) && $valid['total_tickets'] > $valid['max_atndz']) {
211
-            $this->maxAttendeesViolation($valid);
212
-        } else {
213
-            // all data appears to be valid
214
-            if ($this->processSuccessfulCart($this->addTicketsToCart($valid))) {
215
-                return true;
216
-            }
217
-        }
218
-        // die(); // <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< KILL BEFORE REDIRECT
219
-        // at this point, just return if registration is being made from admin
220
-        if ($this->request->isAdmin() || $this->request->isFrontAjax()) {
221
-            return false;
222
-        }
223
-        if ($valid['return_url']) {
224
-            EEH_URL::safeRedirectAndExit($valid['return_url']);
225
-        }
226
-        if ($id) {
227
-            EEH_URL::safeRedirectAndExit(get_permalink($id));
228
-        }
229
-        echo EE_Error::get_notices();
230
-        return false;
231
-    }
176
+	/**
177
+	 * process_ticket_selections
178
+	 *
179
+	 * @return bool
180
+	 * @throws EE_Error
181
+	 * @throws InvalidArgumentException
182
+	 * @throws InvalidDataTypeException
183
+	 * @throws InvalidInterfaceException
184
+	 * @throws ReflectionException
185
+	 */
186
+	public function processTicketSelections()
187
+	{
188
+		do_action('EED_Ticket_Selector__process_ticket_selections__before');
189
+		if ($this->request->isBot()) {
190
+			EEH_URL::safeRedirectAndExit(
191
+				apply_filters(
192
+					'FHEE__EE_Ticket_Selector__process_ticket_selections__bot_redirect_url',
193
+					site_url()
194
+				)
195
+			);
196
+		}
197
+		// do we have an event id?
198
+		$id = $this->getEventId();
199
+		// we should really only have 1 registration in the works now
200
+		// (ie, no MER) so unless otherwise requested, clear the session
201
+		if (apply_filters('FHEE__EE_Ticket_Selector__process_ticket_selections__clear_session', true)) {
202
+			$this->session->clear_session(__CLASS__, __FUNCTION__);
203
+		}
204
+		// validate/sanitize/filter data
205
+		$valid = apply_filters(
206
+			'FHEE__EED_Ticket_Selector__process_ticket_selections__valid_post_data',
207
+			$this->validatePostData($id)
208
+		);
209
+		// check total tickets ordered vs max number of attendees that can register
210
+		if (! empty($valid) && $valid['total_tickets'] > $valid['max_atndz']) {
211
+			$this->maxAttendeesViolation($valid);
212
+		} else {
213
+			// all data appears to be valid
214
+			if ($this->processSuccessfulCart($this->addTicketsToCart($valid))) {
215
+				return true;
216
+			}
217
+		}
218
+		// die(); // <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< KILL BEFORE REDIRECT
219
+		// at this point, just return if registration is being made from admin
220
+		if ($this->request->isAdmin() || $this->request->isFrontAjax()) {
221
+			return false;
222
+		}
223
+		if ($valid['return_url']) {
224
+			EEH_URL::safeRedirectAndExit($valid['return_url']);
225
+		}
226
+		if ($id) {
227
+			EEH_URL::safeRedirectAndExit(get_permalink($id));
228
+		}
229
+		echo EE_Error::get_notices();
230
+		return false;
231
+	}
232 232
 
233 233
 
234
-    /**
235
-     * @return int
236
-     */
237
-    private function getEventId()
238
-    {
239
-        // do we have an event id?
240
-        if (! $this->request->requestParamIsSet('tkt-slctr-event-id')) {
241
-            // $_POST['tkt-slctr-event-id'] was not set ?!?!?!?
242
-            EE_Error::add_error(
243
-                sprintf(
244
-                    esc_html__(
245
-                        'An event id was not provided or was not received.%sPlease click the back button on your browser and try again.',
246
-                        'event_espresso'
247
-                    ),
248
-                    '<br/>'
249
-                ),
250
-                __FILE__,
251
-                __FUNCTION__,
252
-                __LINE__
253
-            );
254
-        }
255
-        // if event id is valid
256
-        return absint($this->request->getRequestParam('tkt-slctr-event-id'));
257
-    }
234
+	/**
235
+	 * @return int
236
+	 */
237
+	private function getEventId()
238
+	{
239
+		// do we have an event id?
240
+		if (! $this->request->requestParamIsSet('tkt-slctr-event-id')) {
241
+			// $_POST['tkt-slctr-event-id'] was not set ?!?!?!?
242
+			EE_Error::add_error(
243
+				sprintf(
244
+					esc_html__(
245
+						'An event id was not provided or was not received.%sPlease click the back button on your browser and try again.',
246
+						'event_espresso'
247
+					),
248
+					'<br/>'
249
+				),
250
+				__FILE__,
251
+				__FUNCTION__,
252
+				__LINE__
253
+			);
254
+		}
255
+		// if event id is valid
256
+		return absint($this->request->getRequestParam('tkt-slctr-event-id'));
257
+	}
258 258
 
259 259
 
260
-    /**
261
-     * validate_post_data
262
-     *
263
-     * @param int $id
264
-     * @return array
265
-     */
266
-    private function validatePostData($id = 0)
267
-    {
268
-        if (! $id) {
269
-            EE_Error::add_error(
270
-                esc_html__('The event id provided was not valid.', 'event_espresso'),
271
-                __FILE__,
272
-                __FUNCTION__,
273
-                __LINE__
274
-            );
275
-            return array();
276
-        }
277
-        // start with an empty array()
278
-        $valid_data = array();
279
-        // grab valid id
280
-        $valid_data['id'] = $id;
281
-        // array of other form names
282
-        $inputs_to_clean = array(
283
-            'max_atndz'  => 'tkt-slctr-max-atndz-',
284
-            'rows'       => 'tkt-slctr-rows-',
285
-            'qty'        => 'tkt-slctr-qty-',
286
-            'ticket_id'  => 'tkt-slctr-ticket-id-',
287
-            'return_url' => 'tkt-slctr-return-url-',
288
-        );
289
-        // let's track the total number of tickets ordered.'
290
-        $valid_data['total_tickets'] = 0;
291
-        // cycle through $inputs_to_clean array
292
-        foreach ($inputs_to_clean as $what => $input_to_clean) {
293
-            // check for POST data
294
-            if ($this->request->requestParamIsSet($input_to_clean . $id)) {
295
-                // grab value
296
-                switch ($what) {
297
-                    // integers
298
-                    case 'event_id':
299
-                    case 'rows':
300
-                    case 'max_atndz':
301
-                        $valid_data[ $what ] = $this->request->getRequestParam($input_to_clean . $id, 0, 'int');
302
-                        break;
303
-                    // arrays of integers
304
-                    case 'qty':
305
-                        /** @var array $row_qty */
306
-                        $row_qty = $this->request->getRequestParam($input_to_clean . $id, [], 'arrayOf|int');
307
-                        // if qty is coming from a radio button input, then we need to assemble an array of rows
308
-                        if (! is_array($row_qty)) {
309
-                            /** @var string $row_qty */
310
-                            // get number of rows
311
-                            $rows = $this->request->getRequestParam('tkt-slctr-rows-' . $id, 1, 'int');
312
-                            // explode integers by the dash
313
-                            $row_qty = explode('-', $row_qty);
314
-                            $row = isset($row_qty[0]) ? absint($row_qty[0]) : 1;
315
-                            $qty = isset($row_qty[1]) ? absint($row_qty[1]) : 0;
316
-                            $row_qty = array($row => $qty);
317
-                            for ($x = 1; $x <= $rows; $x++) {
318
-                                if (! isset($row_qty[ $x ])) {
319
-                                    $row_qty[ $x ] = 0;
320
-                                }
321
-                            }
322
-                        }
323
-                        ksort($row_qty);
324
-                        // cycle thru values
325
-                        foreach ($row_qty as $qty) {
326
-                            $qty = absint($qty);
327
-                            // sanitize as integers
328
-                            $valid_data[ $what ][] = $qty;
329
-                            $valid_data['total_tickets'] += $qty;
330
-                        }
331
-                        break;
332
-                    // array of integers
333
-                    case 'ticket_id':
334
-                        $ticket_ids = (array) $this->request->getRequestParam($input_to_clean . $id, [], 'arrayOf|int');
335
-                        // cycle thru values
336
-                        foreach ($ticket_ids as $key => $value) {
337
-                            // allow only integers
338
-                            $valid_data[ $what ][ $key ] = absint($value);
339
-                        }
340
-                        break;
341
-                    case 'return_url':
342
-                        // grab and sanitize return-url
343
-                        $input_value = $this->request->getRequestParam($input_to_clean . $id, '', 'url');
344
-                        // was the request coming from an iframe ? if so, then:
345
-                        if (strpos($input_value, 'event_list=iframe')) {
346
-                            // get anchor fragment
347
-                            $input_value = explode('#', $input_value);
348
-                            $input_value = end($input_value);
349
-                            // use event list url instead, but append anchor
350
-                            $input_value = EEH_Event_View::event_archive_url() . '#' . $input_value;
351
-                        }
352
-                        $valid_data[ $what ] = $input_value;
353
-                        break;
354
-                }    // end switch $what
355
-            }
356
-        }    // end foreach $inputs_to_clean
357
-        return $valid_data;
358
-    }
260
+	/**
261
+	 * validate_post_data
262
+	 *
263
+	 * @param int $id
264
+	 * @return array
265
+	 */
266
+	private function validatePostData($id = 0)
267
+	{
268
+		if (! $id) {
269
+			EE_Error::add_error(
270
+				esc_html__('The event id provided was not valid.', 'event_espresso'),
271
+				__FILE__,
272
+				__FUNCTION__,
273
+				__LINE__
274
+			);
275
+			return array();
276
+		}
277
+		// start with an empty array()
278
+		$valid_data = array();
279
+		// grab valid id
280
+		$valid_data['id'] = $id;
281
+		// array of other form names
282
+		$inputs_to_clean = array(
283
+			'max_atndz'  => 'tkt-slctr-max-atndz-',
284
+			'rows'       => 'tkt-slctr-rows-',
285
+			'qty'        => 'tkt-slctr-qty-',
286
+			'ticket_id'  => 'tkt-slctr-ticket-id-',
287
+			'return_url' => 'tkt-slctr-return-url-',
288
+		);
289
+		// let's track the total number of tickets ordered.'
290
+		$valid_data['total_tickets'] = 0;
291
+		// cycle through $inputs_to_clean array
292
+		foreach ($inputs_to_clean as $what => $input_to_clean) {
293
+			// check for POST data
294
+			if ($this->request->requestParamIsSet($input_to_clean . $id)) {
295
+				// grab value
296
+				switch ($what) {
297
+					// integers
298
+					case 'event_id':
299
+					case 'rows':
300
+					case 'max_atndz':
301
+						$valid_data[ $what ] = $this->request->getRequestParam($input_to_clean . $id, 0, 'int');
302
+						break;
303
+					// arrays of integers
304
+					case 'qty':
305
+						/** @var array $row_qty */
306
+						$row_qty = $this->request->getRequestParam($input_to_clean . $id, [], 'arrayOf|int');
307
+						// if qty is coming from a radio button input, then we need to assemble an array of rows
308
+						if (! is_array($row_qty)) {
309
+							/** @var string $row_qty */
310
+							// get number of rows
311
+							$rows = $this->request->getRequestParam('tkt-slctr-rows-' . $id, 1, 'int');
312
+							// explode integers by the dash
313
+							$row_qty = explode('-', $row_qty);
314
+							$row = isset($row_qty[0]) ? absint($row_qty[0]) : 1;
315
+							$qty = isset($row_qty[1]) ? absint($row_qty[1]) : 0;
316
+							$row_qty = array($row => $qty);
317
+							for ($x = 1; $x <= $rows; $x++) {
318
+								if (! isset($row_qty[ $x ])) {
319
+									$row_qty[ $x ] = 0;
320
+								}
321
+							}
322
+						}
323
+						ksort($row_qty);
324
+						// cycle thru values
325
+						foreach ($row_qty as $qty) {
326
+							$qty = absint($qty);
327
+							// sanitize as integers
328
+							$valid_data[ $what ][] = $qty;
329
+							$valid_data['total_tickets'] += $qty;
330
+						}
331
+						break;
332
+					// array of integers
333
+					case 'ticket_id':
334
+						$ticket_ids = (array) $this->request->getRequestParam($input_to_clean . $id, [], 'arrayOf|int');
335
+						// cycle thru values
336
+						foreach ($ticket_ids as $key => $value) {
337
+							// allow only integers
338
+							$valid_data[ $what ][ $key ] = absint($value);
339
+						}
340
+						break;
341
+					case 'return_url':
342
+						// grab and sanitize return-url
343
+						$input_value = $this->request->getRequestParam($input_to_clean . $id, '', 'url');
344
+						// was the request coming from an iframe ? if so, then:
345
+						if (strpos($input_value, 'event_list=iframe')) {
346
+							// get anchor fragment
347
+							$input_value = explode('#', $input_value);
348
+							$input_value = end($input_value);
349
+							// use event list url instead, but append anchor
350
+							$input_value = EEH_Event_View::event_archive_url() . '#' . $input_value;
351
+						}
352
+						$valid_data[ $what ] = $input_value;
353
+						break;
354
+				}    // end switch $what
355
+			}
356
+		}    // end foreach $inputs_to_clean
357
+		return $valid_data;
358
+	}
359 359
 
360 360
 
361
-    /**
362
-     * @param array $valid
363
-     */
364
-    private function maxAttendeesViolation(array $valid)
365
-    {
366
-        // ordering too many tickets !!!
367
-        $total_tickets_string = esc_html(
368
-            _n(
369
-                'You have attempted to purchase %s ticket.',
370
-                'You have attempted to purchase %s tickets.',
371
-                $valid['total_tickets'],
372
-                'event_espresso'
373
-            )
374
-        );
375
-        $limit_error_1 = sprintf($total_tickets_string, $valid['total_tickets']);
376
-        // dev only message
377
-        $max_attendees_string = esc_html(
378
-            _n(
379
-                'The registration limit for this event is %s ticket per registration, therefore the total number of tickets you may purchase at a time can not exceed %s.',
380
-                'The registration limit for this event is %s tickets per registration, therefore the total number of tickets you may purchase at a time can not exceed %s.',
381
-                $valid['max_atndz'],
382
-                'event_espresso'
383
-            )
384
-        );
385
-        $limit_error_2 = sprintf($max_attendees_string, $valid['max_atndz'], $valid['max_atndz']);
386
-        EE_Error::add_error($limit_error_1 . '<br/>' . $limit_error_2, __FILE__, __FUNCTION__, __LINE__);
387
-    }
361
+	/**
362
+	 * @param array $valid
363
+	 */
364
+	private function maxAttendeesViolation(array $valid)
365
+	{
366
+		// ordering too many tickets !!!
367
+		$total_tickets_string = esc_html(
368
+			_n(
369
+				'You have attempted to purchase %s ticket.',
370
+				'You have attempted to purchase %s tickets.',
371
+				$valid['total_tickets'],
372
+				'event_espresso'
373
+			)
374
+		);
375
+		$limit_error_1 = sprintf($total_tickets_string, $valid['total_tickets']);
376
+		// dev only message
377
+		$max_attendees_string = esc_html(
378
+			_n(
379
+				'The registration limit for this event is %s ticket per registration, therefore the total number of tickets you may purchase at a time can not exceed %s.',
380
+				'The registration limit for this event is %s tickets per registration, therefore the total number of tickets you may purchase at a time can not exceed %s.',
381
+				$valid['max_atndz'],
382
+				'event_espresso'
383
+			)
384
+		);
385
+		$limit_error_2 = sprintf($max_attendees_string, $valid['max_atndz'], $valid['max_atndz']);
386
+		EE_Error::add_error($limit_error_1 . '<br/>' . $limit_error_2, __FILE__, __FUNCTION__, __LINE__);
387
+	}
388 388
 
389 389
 
390
-    /**
391
-     * @param array $valid
392
-     * @return int
393
-     * @throws EE_Error
394
-     * @throws InvalidArgumentException
395
-     * @throws InvalidDataTypeException
396
-     * @throws InvalidInterfaceException
397
-     */
398
-    private function addTicketsToCart(array $valid)
399
-    {
400
-        $tickets_added = 0;
401
-        $tickets_selected = false;
402
-        if (! empty($valid) && $valid['total_tickets'] > 0) {
403
-            // load cart using factory because we don't want to do so until actually needed
404
-            $this->cart = CartFactory::getCart();
405
-            // if the user is an admin that can edit registrations,
406
-            // then we'll also allow them to add any tickets, even if they are expired
407
-            $current_user_is_admin = current_user_can('ee_edit_registrations');
408
-            \EEH_Debug_Tools::printr($current_user_is_admin, '$current_user_is_admin', __FILE__, __LINE__);
409
-            // cycle thru the number of data rows sent from the event listing
410
-            for ($x = 0; $x < $valid['rows']; $x++) {
411
-                // does this row actually contain a ticket quantity?
412
-                if (isset($valid['qty'][ $x ]) && $valid['qty'][ $x ] > 0) {
413
-                    // YES we have a ticket quantity
414
-                    $tickets_selected = true;
415
-                    $valid_ticket = false;
416
-                    if (isset($valid['ticket_id'][ $x ])) {
417
-                        // get ticket via the ticket id we put in the form
418
-                        $ticket = $this->ticket_model->get_one_by_ID($valid['ticket_id'][ $x ]);
419
-                        \EEH_Debug_Tools::printr($ticket->is_on_sale(), '$ticket->is_on_sale()', __FILE__, __LINE__);
420
-                        if ($ticket instanceof EE_Ticket && ($ticket->is_on_sale() || $current_user_is_admin)) {
421
-                            $valid_ticket = true;
422
-                            $tickets_added += $this->addTicketToCart(
423
-                                $ticket,
424
-                                $valid['qty'][ $x ]
425
-                            );
426
-                        }
427
-                    }
428
-                    if ($valid_ticket !== true) {
429
-                        // nothing added to cart retrieved
430
-                        EE_Error::add_error(
431
-                            sprintf(
432
-                                esc_html__(
433
-                                    'A valid ticket could not be retrieved for the event.%sPlease click the back button on your browser and try again.',
434
-                                    'event_espresso'
435
-                                ),
436
-                                '<br/>'
437
-                            ),
438
-                            __FILE__,
439
-                            __FUNCTION__,
440
-                            __LINE__
441
-                        );
442
-                    }
443
-                    if (EE_Error::has_error()) {
444
-                        break;
445
-                    }
446
-                }
447
-            }
448
-        }
449
-        do_action(
450
-            'AHEE__EE_Ticket_Selector__process_ticket_selections__after_tickets_added_to_cart',
451
-            $this->cart,
452
-            $this
453
-        );
454
-        if (! apply_filters('FHEE__EED_Ticket_Selector__process_ticket_selections__tckts_slctd', $tickets_selected)) {
455
-            // no ticket quantities were selected
456
-            EE_Error::add_error(
457
-                esc_html__('You need to select a ticket quantity before you can proceed.', 'event_espresso'),
458
-                __FILE__,
459
-                __FUNCTION__,
460
-                __LINE__
461
-            );
462
-        }
463
-        return $tickets_added;
464
-    }
390
+	/**
391
+	 * @param array $valid
392
+	 * @return int
393
+	 * @throws EE_Error
394
+	 * @throws InvalidArgumentException
395
+	 * @throws InvalidDataTypeException
396
+	 * @throws InvalidInterfaceException
397
+	 */
398
+	private function addTicketsToCart(array $valid)
399
+	{
400
+		$tickets_added = 0;
401
+		$tickets_selected = false;
402
+		if (! empty($valid) && $valid['total_tickets'] > 0) {
403
+			// load cart using factory because we don't want to do so until actually needed
404
+			$this->cart = CartFactory::getCart();
405
+			// if the user is an admin that can edit registrations,
406
+			// then we'll also allow them to add any tickets, even if they are expired
407
+			$current_user_is_admin = current_user_can('ee_edit_registrations');
408
+			\EEH_Debug_Tools::printr($current_user_is_admin, '$current_user_is_admin', __FILE__, __LINE__);
409
+			// cycle thru the number of data rows sent from the event listing
410
+			for ($x = 0; $x < $valid['rows']; $x++) {
411
+				// does this row actually contain a ticket quantity?
412
+				if (isset($valid['qty'][ $x ]) && $valid['qty'][ $x ] > 0) {
413
+					// YES we have a ticket quantity
414
+					$tickets_selected = true;
415
+					$valid_ticket = false;
416
+					if (isset($valid['ticket_id'][ $x ])) {
417
+						// get ticket via the ticket id we put in the form
418
+						$ticket = $this->ticket_model->get_one_by_ID($valid['ticket_id'][ $x ]);
419
+						\EEH_Debug_Tools::printr($ticket->is_on_sale(), '$ticket->is_on_sale()', __FILE__, __LINE__);
420
+						if ($ticket instanceof EE_Ticket && ($ticket->is_on_sale() || $current_user_is_admin)) {
421
+							$valid_ticket = true;
422
+							$tickets_added += $this->addTicketToCart(
423
+								$ticket,
424
+								$valid['qty'][ $x ]
425
+							);
426
+						}
427
+					}
428
+					if ($valid_ticket !== true) {
429
+						// nothing added to cart retrieved
430
+						EE_Error::add_error(
431
+							sprintf(
432
+								esc_html__(
433
+									'A valid ticket could not be retrieved for the event.%sPlease click the back button on your browser and try again.',
434
+									'event_espresso'
435
+								),
436
+								'<br/>'
437
+							),
438
+							__FILE__,
439
+							__FUNCTION__,
440
+							__LINE__
441
+						);
442
+					}
443
+					if (EE_Error::has_error()) {
444
+						break;
445
+					}
446
+				}
447
+			}
448
+		}
449
+		do_action(
450
+			'AHEE__EE_Ticket_Selector__process_ticket_selections__after_tickets_added_to_cart',
451
+			$this->cart,
452
+			$this
453
+		);
454
+		if (! apply_filters('FHEE__EED_Ticket_Selector__process_ticket_selections__tckts_slctd', $tickets_selected)) {
455
+			// no ticket quantities were selected
456
+			EE_Error::add_error(
457
+				esc_html__('You need to select a ticket quantity before you can proceed.', 'event_espresso'),
458
+				__FILE__,
459
+				__FUNCTION__,
460
+				__LINE__
461
+			);
462
+		}
463
+		return $tickets_added;
464
+	}
465 465
 
466 466
 
467
-    /**
468
-     * adds a ticket to the cart
469
-     *
470
-     * @param EE_Ticket $ticket
471
-     * @param int       $qty
472
-     * @return bool TRUE on success, FALSE on fail
473
-     * @throws InvalidArgumentException
474
-     * @throws InvalidInterfaceException
475
-     * @throws InvalidDataTypeException
476
-     * @throws EE_Error
477
-     */
478
-    private function addTicketToCart(EE_Ticket $ticket, $qty = 1)
479
-    {
480
-        // get the number of spaces left for this datetime ticket
481
-        $available_spaces = $this->tracker->ticketDatetimeAvailability($ticket);
482
-        // compare available spaces against the number of tickets being purchased
483
-        if ($available_spaces >= $qty) {
484
-            // allow addons to prevent a ticket from being added to cart
485
-            if (! apply_filters(
486
-                'FHEE__EE_Ticket_Selector___add_ticket_to_cart__allow_add_to_cart',
487
-                true,
488
-                $ticket,
489
-                $qty,
490
-                $available_spaces
491
-            )) {
492
-                return false;
493
-            }
494
-            $qty = absint(apply_filters('FHEE__EE_Ticket_Selector___add_ticket_to_cart__ticket_qty', $qty, $ticket));
495
-            // add event to cart
496
-            if ($this->cart->add_ticket_to_cart($ticket, $qty)) {
497
-                $this->tracker->recalculateTicketDatetimeAvailability($ticket, $qty);
498
-                return true;
499
-            }
500
-            return false;
501
-        }
502
-        $this->tracker->processAvailabilityError($ticket, $qty, $this->cart->all_ticket_quantity_count());
503
-        return false;
504
-    }
467
+	/**
468
+	 * adds a ticket to the cart
469
+	 *
470
+	 * @param EE_Ticket $ticket
471
+	 * @param int       $qty
472
+	 * @return bool TRUE on success, FALSE on fail
473
+	 * @throws InvalidArgumentException
474
+	 * @throws InvalidInterfaceException
475
+	 * @throws InvalidDataTypeException
476
+	 * @throws EE_Error
477
+	 */
478
+	private function addTicketToCart(EE_Ticket $ticket, $qty = 1)
479
+	{
480
+		// get the number of spaces left for this datetime ticket
481
+		$available_spaces = $this->tracker->ticketDatetimeAvailability($ticket);
482
+		// compare available spaces against the number of tickets being purchased
483
+		if ($available_spaces >= $qty) {
484
+			// allow addons to prevent a ticket from being added to cart
485
+			if (! apply_filters(
486
+				'FHEE__EE_Ticket_Selector___add_ticket_to_cart__allow_add_to_cart',
487
+				true,
488
+				$ticket,
489
+				$qty,
490
+				$available_spaces
491
+			)) {
492
+				return false;
493
+			}
494
+			$qty = absint(apply_filters('FHEE__EE_Ticket_Selector___add_ticket_to_cart__ticket_qty', $qty, $ticket));
495
+			// add event to cart
496
+			if ($this->cart->add_ticket_to_cart($ticket, $qty)) {
497
+				$this->tracker->recalculateTicketDatetimeAvailability($ticket, $qty);
498
+				return true;
499
+			}
500
+			return false;
501
+		}
502
+		$this->tracker->processAvailabilityError($ticket, $qty, $this->cart->all_ticket_quantity_count());
503
+		return false;
504
+	}
505 505
 
506 506
 
507
-    /**
508
-     * @param $tickets_added
509
-     * @return bool
510
-     * @throws InvalidInterfaceException
511
-     * @throws InvalidDataTypeException
512
-     * @throws EE_Error
513
-     * @throws InvalidArgumentException
514
-     */
515
-    private function processSuccessfulCart($tickets_added)
516
-    {
517
-        // exit('KILL REDIRECT BEFORE CART UPDATE'); // <<<<<<<<<<<<<<<<< KILL REDIRECT HERE BEFORE CART UPDATE
518
-        if (apply_filters('FHEE__EED_Ticket_Selector__process_ticket_selections__success', $tickets_added)) {
519
-            // make sure cart is loaded
520
-            if (! $this->cart instanceof EE_Cart) {
521
-                $this->cart = CartFactory::getCart();
522
-            }
523
-            do_action(
524
-                'FHEE__EE_Ticket_Selector__process_ticket_selections__before_redirecting_to_checkout',
525
-                $this->cart,
526
-                $this
527
-            );
528
-            $this->cart->recalculate_all_cart_totals();
529
-            $this->cart->save_cart(false);
530
-            // exit('KILL REDIRECT AFTER CART UPDATE'); // <<<<<<<<  OR HERE TO KILL REDIRECT AFTER CART UPDATE
531
-            // just return TRUE for registrations being made from admin
532
-            if ($this->request->isAdmin() || $this->request->isFrontAjax()) {
533
-                return true;
534
-            }
535
-            EEH_URL::safeRedirectAndExit(
536
-                apply_filters(
537
-                    'FHEE__EE_Ticket_Selector__process_ticket_selections__success_redirect_url',
538
-                    $this->core_config->reg_page_url()
539
-                )
540
-            );
541
-        }
542
-        if (! EE_Error::has_error() && ! EE_Error::has_error(true, 'attention')) {
543
-            // nothing added to cart
544
-            EE_Error::add_attention(
545
-                esc_html__('No tickets were added for the event', 'event_espresso'),
546
-                __FILE__,
547
-                __FUNCTION__,
548
-                __LINE__
549
-            );
550
-        }
551
-        return false;
552
-    }
507
+	/**
508
+	 * @param $tickets_added
509
+	 * @return bool
510
+	 * @throws InvalidInterfaceException
511
+	 * @throws InvalidDataTypeException
512
+	 * @throws EE_Error
513
+	 * @throws InvalidArgumentException
514
+	 */
515
+	private function processSuccessfulCart($tickets_added)
516
+	{
517
+		// exit('KILL REDIRECT BEFORE CART UPDATE'); // <<<<<<<<<<<<<<<<< KILL REDIRECT HERE BEFORE CART UPDATE
518
+		if (apply_filters('FHEE__EED_Ticket_Selector__process_ticket_selections__success', $tickets_added)) {
519
+			// make sure cart is loaded
520
+			if (! $this->cart instanceof EE_Cart) {
521
+				$this->cart = CartFactory::getCart();
522
+			}
523
+			do_action(
524
+				'FHEE__EE_Ticket_Selector__process_ticket_selections__before_redirecting_to_checkout',
525
+				$this->cart,
526
+				$this
527
+			);
528
+			$this->cart->recalculate_all_cart_totals();
529
+			$this->cart->save_cart(false);
530
+			// exit('KILL REDIRECT AFTER CART UPDATE'); // <<<<<<<<  OR HERE TO KILL REDIRECT AFTER CART UPDATE
531
+			// just return TRUE for registrations being made from admin
532
+			if ($this->request->isAdmin() || $this->request->isFrontAjax()) {
533
+				return true;
534
+			}
535
+			EEH_URL::safeRedirectAndExit(
536
+				apply_filters(
537
+					'FHEE__EE_Ticket_Selector__process_ticket_selections__success_redirect_url',
538
+					$this->core_config->reg_page_url()
539
+				)
540
+			);
541
+		}
542
+		if (! EE_Error::has_error() && ! EE_Error::has_error(true, 'attention')) {
543
+			// nothing added to cart
544
+			EE_Error::add_attention(
545
+				esc_html__('No tickets were added for the event', 'event_espresso'),
546
+				__FILE__,
547
+				__FUNCTION__,
548
+				__LINE__
549
+			);
550
+		}
551
+		return false;
552
+	}
553 553
 }
Please login to merge, or discard this patch.
Spacing   +29 added lines, -29 removed lines patch added patch discarded remove patch
@@ -118,7 +118,7 @@  discard block
 block discarded – undo
118 118
     public function cancelTicketSelections()
119 119
     {
120 120
         // check nonce
121
-        if (! $this->processTicketSelectorNonce('cancel_ticket_selections')) {
121
+        if ( ! $this->processTicketSelectorNonce('cancel_ticket_selections')) {
122 122
             return false;
123 123
         }
124 124
         $this->session->clear_session(__CLASS__, __FUNCTION__);
@@ -130,7 +130,7 @@  discard block
 block discarded – undo
130 130
             );
131 131
         }
132 132
         EEH_URL::safeRedirectAndExit(
133
-            site_url('/' . $this->core_config->event_cpt_slug . '/')
133
+            site_url('/'.$this->core_config->event_cpt_slug.'/')
134 134
         );
135 135
         return true;
136 136
     }
@@ -146,7 +146,7 @@  discard block
 block discarded – undo
146 146
     private function processTicketSelectorNonce($nonce_name, $id = '')
147 147
     {
148 148
         $nonce_name_with_id = ! empty($id) ? "{$nonce_name}_nonce_{$id}" : "{$nonce_name}_nonce";
149
-        if (! $this->request->isAdmin()
149
+        if ( ! $this->request->isAdmin()
150 150
             && (
151 151
                 ! $this->request->is_set($nonce_name_with_id)
152 152
                 || ! wp_verify_nonce(
@@ -207,7 +207,7 @@  discard block
 block discarded – undo
207 207
             $this->validatePostData($id)
208 208
         );
209 209
         // check total tickets ordered vs max number of attendees that can register
210
-        if (! empty($valid) && $valid['total_tickets'] > $valid['max_atndz']) {
210
+        if ( ! empty($valid) && $valid['total_tickets'] > $valid['max_atndz']) {
211 211
             $this->maxAttendeesViolation($valid);
212 212
         } else {
213 213
             // all data appears to be valid
@@ -237,7 +237,7 @@  discard block
 block discarded – undo
237 237
     private function getEventId()
238 238
     {
239 239
         // do we have an event id?
240
-        if (! $this->request->requestParamIsSet('tkt-slctr-event-id')) {
240
+        if ( ! $this->request->requestParamIsSet('tkt-slctr-event-id')) {
241 241
             // $_POST['tkt-slctr-event-id'] was not set ?!?!?!?
242 242
             EE_Error::add_error(
243 243
                 sprintf(
@@ -265,7 +265,7 @@  discard block
 block discarded – undo
265 265
      */
266 266
     private function validatePostData($id = 0)
267 267
     {
268
-        if (! $id) {
268
+        if ( ! $id) {
269 269
             EE_Error::add_error(
270 270
                 esc_html__('The event id provided was not valid.', 'event_espresso'),
271 271
                 __FILE__,
@@ -291,32 +291,32 @@  discard block
 block discarded – undo
291 291
         // cycle through $inputs_to_clean array
292 292
         foreach ($inputs_to_clean as $what => $input_to_clean) {
293 293
             // check for POST data
294
-            if ($this->request->requestParamIsSet($input_to_clean . $id)) {
294
+            if ($this->request->requestParamIsSet($input_to_clean.$id)) {
295 295
                 // grab value
296 296
                 switch ($what) {
297 297
                     // integers
298 298
                     case 'event_id':
299 299
                     case 'rows':
300 300
                     case 'max_atndz':
301
-                        $valid_data[ $what ] = $this->request->getRequestParam($input_to_clean . $id, 0, 'int');
301
+                        $valid_data[$what] = $this->request->getRequestParam($input_to_clean.$id, 0, 'int');
302 302
                         break;
303 303
                     // arrays of integers
304 304
                     case 'qty':
305 305
                         /** @var array $row_qty */
306
-                        $row_qty = $this->request->getRequestParam($input_to_clean . $id, [], 'arrayOf|int');
306
+                        $row_qty = $this->request->getRequestParam($input_to_clean.$id, [], 'arrayOf|int');
307 307
                         // if qty is coming from a radio button input, then we need to assemble an array of rows
308
-                        if (! is_array($row_qty)) {
308
+                        if ( ! is_array($row_qty)) {
309 309
                             /** @var string $row_qty */
310 310
                             // get number of rows
311
-                            $rows = $this->request->getRequestParam('tkt-slctr-rows-' . $id, 1, 'int');
311
+                            $rows = $this->request->getRequestParam('tkt-slctr-rows-'.$id, 1, 'int');
312 312
                             // explode integers by the dash
313 313
                             $row_qty = explode('-', $row_qty);
314 314
                             $row = isset($row_qty[0]) ? absint($row_qty[0]) : 1;
315 315
                             $qty = isset($row_qty[1]) ? absint($row_qty[1]) : 0;
316 316
                             $row_qty = array($row => $qty);
317 317
                             for ($x = 1; $x <= $rows; $x++) {
318
-                                if (! isset($row_qty[ $x ])) {
319
-                                    $row_qty[ $x ] = 0;
318
+                                if ( ! isset($row_qty[$x])) {
319
+                                    $row_qty[$x] = 0;
320 320
                                 }
321 321
                             }
322 322
                         }
@@ -325,31 +325,31 @@  discard block
 block discarded – undo
325 325
                         foreach ($row_qty as $qty) {
326 326
                             $qty = absint($qty);
327 327
                             // sanitize as integers
328
-                            $valid_data[ $what ][] = $qty;
328
+                            $valid_data[$what][] = $qty;
329 329
                             $valid_data['total_tickets'] += $qty;
330 330
                         }
331 331
                         break;
332 332
                     // array of integers
333 333
                     case 'ticket_id':
334
-                        $ticket_ids = (array) $this->request->getRequestParam($input_to_clean . $id, [], 'arrayOf|int');
334
+                        $ticket_ids = (array) $this->request->getRequestParam($input_to_clean.$id, [], 'arrayOf|int');
335 335
                         // cycle thru values
336 336
                         foreach ($ticket_ids as $key => $value) {
337 337
                             // allow only integers
338
-                            $valid_data[ $what ][ $key ] = absint($value);
338
+                            $valid_data[$what][$key] = absint($value);
339 339
                         }
340 340
                         break;
341 341
                     case 'return_url':
342 342
                         // grab and sanitize return-url
343
-                        $input_value = $this->request->getRequestParam($input_to_clean . $id, '', 'url');
343
+                        $input_value = $this->request->getRequestParam($input_to_clean.$id, '', 'url');
344 344
                         // was the request coming from an iframe ? if so, then:
345 345
                         if (strpos($input_value, 'event_list=iframe')) {
346 346
                             // get anchor fragment
347 347
                             $input_value = explode('#', $input_value);
348 348
                             $input_value = end($input_value);
349 349
                             // use event list url instead, but append anchor
350
-                            $input_value = EEH_Event_View::event_archive_url() . '#' . $input_value;
350
+                            $input_value = EEH_Event_View::event_archive_url().'#'.$input_value;
351 351
                         }
352
-                        $valid_data[ $what ] = $input_value;
352
+                        $valid_data[$what] = $input_value;
353 353
                         break;
354 354
                 }    // end switch $what
355 355
             }
@@ -383,7 +383,7 @@  discard block
 block discarded – undo
383 383
             )
384 384
         );
385 385
         $limit_error_2 = sprintf($max_attendees_string, $valid['max_atndz'], $valid['max_atndz']);
386
-        EE_Error::add_error($limit_error_1 . '<br/>' . $limit_error_2, __FILE__, __FUNCTION__, __LINE__);
386
+        EE_Error::add_error($limit_error_1.'<br/>'.$limit_error_2, __FILE__, __FUNCTION__, __LINE__);
387 387
     }
388 388
 
389 389
 
@@ -399,7 +399,7 @@  discard block
 block discarded – undo
399 399
     {
400 400
         $tickets_added = 0;
401 401
         $tickets_selected = false;
402
-        if (! empty($valid) && $valid['total_tickets'] > 0) {
402
+        if ( ! empty($valid) && $valid['total_tickets'] > 0) {
403 403
             // load cart using factory because we don't want to do so until actually needed
404 404
             $this->cart = CartFactory::getCart();
405 405
             // if the user is an admin that can edit registrations,
@@ -409,19 +409,19 @@  discard block
 block discarded – undo
409 409
             // cycle thru the number of data rows sent from the event listing
410 410
             for ($x = 0; $x < $valid['rows']; $x++) {
411 411
                 // does this row actually contain a ticket quantity?
412
-                if (isset($valid['qty'][ $x ]) && $valid['qty'][ $x ] > 0) {
412
+                if (isset($valid['qty'][$x]) && $valid['qty'][$x] > 0) {
413 413
                     // YES we have a ticket quantity
414 414
                     $tickets_selected = true;
415 415
                     $valid_ticket = false;
416
-                    if (isset($valid['ticket_id'][ $x ])) {
416
+                    if (isset($valid['ticket_id'][$x])) {
417 417
                         // get ticket via the ticket id we put in the form
418
-                        $ticket = $this->ticket_model->get_one_by_ID($valid['ticket_id'][ $x ]);
418
+                        $ticket = $this->ticket_model->get_one_by_ID($valid['ticket_id'][$x]);
419 419
                         \EEH_Debug_Tools::printr($ticket->is_on_sale(), '$ticket->is_on_sale()', __FILE__, __LINE__);
420 420
                         if ($ticket instanceof EE_Ticket && ($ticket->is_on_sale() || $current_user_is_admin)) {
421 421
                             $valid_ticket = true;
422 422
                             $tickets_added += $this->addTicketToCart(
423 423
                                 $ticket,
424
-                                $valid['qty'][ $x ]
424
+                                $valid['qty'][$x]
425 425
                             );
426 426
                         }
427 427
                     }
@@ -451,7 +451,7 @@  discard block
 block discarded – undo
451 451
             $this->cart,
452 452
             $this
453 453
         );
454
-        if (! apply_filters('FHEE__EED_Ticket_Selector__process_ticket_selections__tckts_slctd', $tickets_selected)) {
454
+        if ( ! apply_filters('FHEE__EED_Ticket_Selector__process_ticket_selections__tckts_slctd', $tickets_selected)) {
455 455
             // no ticket quantities were selected
456 456
             EE_Error::add_error(
457 457
                 esc_html__('You need to select a ticket quantity before you can proceed.', 'event_espresso'),
@@ -482,7 +482,7 @@  discard block
 block discarded – undo
482 482
         // compare available spaces against the number of tickets being purchased
483 483
         if ($available_spaces >= $qty) {
484 484
             // allow addons to prevent a ticket from being added to cart
485
-            if (! apply_filters(
485
+            if ( ! apply_filters(
486 486
                 'FHEE__EE_Ticket_Selector___add_ticket_to_cart__allow_add_to_cart',
487 487
                 true,
488 488
                 $ticket,
@@ -517,7 +517,7 @@  discard block
 block discarded – undo
517 517
         // exit('KILL REDIRECT BEFORE CART UPDATE'); // <<<<<<<<<<<<<<<<< KILL REDIRECT HERE BEFORE CART UPDATE
518 518
         if (apply_filters('FHEE__EED_Ticket_Selector__process_ticket_selections__success', $tickets_added)) {
519 519
             // make sure cart is loaded
520
-            if (! $this->cart instanceof EE_Cart) {
520
+            if ( ! $this->cart instanceof EE_Cart) {
521 521
                 $this->cart = CartFactory::getCart();
522 522
             }
523 523
             do_action(
@@ -539,7 +539,7 @@  discard block
 block discarded – undo
539 539
                 )
540 540
             );
541 541
         }
542
-        if (! EE_Error::has_error() && ! EE_Error::has_error(true, 'attention')) {
542
+        if ( ! EE_Error::has_error() && ! EE_Error::has_error(true, 'attention')) {
543 543
             // nothing added to cart
544 544
             EE_Error::add_attention(
545 545
                 esc_html__('No tickets were added for the event', 'event_espresso'),
Please login to merge, or discard this patch.
modules/thank_you_page/EED_Thank_You_Page.module.php 2 patches
Indentation   +786 added lines, -786 removed lines patch added patch discarded remove patch
@@ -11,611 +11,611 @@  discard block
 block discarded – undo
11 11
 class EED_Thank_You_Page extends EED_Module
12 12
 {
13 13
 
14
-    /**
15
-     * time in seconds to wait for the IPN to arrive before telling the registrant to bugger off ( 1200s = 20 minutes )
16
-     */
17
-    const IPN_wait_time = 1200;
18
-
19
-    /**
20
-     * The transaction specified by the reg_url_link passed from the Request, or from the Session
21
-     *
22
-     * @var EE_Transaction $_current_txn
23
-     */
24
-    private $_current_txn;
25
-
26
-    /**
27
-     * @var EE_Registration $_primary_registrant
28
-     */
29
-    private $_primary_registrant;
30
-
31
-    /**
32
-     * The reg_url_link passed from the Request, or from the Session
33
-     *
34
-     * @var string $_reg_url_link
35
-     */
36
-    private $_reg_url_link;
37
-
38
-    /**
39
-     * whether the incoming reg_url_link is for the primary registrant or not
40
-     *
41
-     * @var boolean $_is_primary
42
-     */
43
-    private $_is_primary;
44
-
45
-    /**
46
-     * The URL for revisiting the SPCO attendee information step
47
-     *
48
-     * @var string $_SPCO_attendee_information_url
49
-     */
50
-    private $_SPCO_attendee_information_url;
51
-
52
-    /**
53
-     * The URL for revisiting the SPCO payment options step
54
-     *
55
-     * @var string $_SPCO_payment_options_url
56
-     */
57
-    private $_SPCO_payment_options_url;
58
-
59
-    /**
60
-     * whether to display the Payment Options link
61
-     *
62
-     * @var boolean $_show_try_pay_again_link
63
-     */
64
-    private $_show_try_pay_again_link = false;
65
-
66
-    /**
67
-     * whether payments are allowed at this time
68
-     *
69
-     * @var boolean $_payments_closed
70
-     */
71
-    private $_payments_closed = false;
72
-
73
-    /**
74
-     * whether the selected payment method is Bank, Check , Invoice, etc
75
-     *
76
-     * @var boolean $_is_offline_payment_method
77
-     */
78
-    private $_is_offline_payment_method = true;
79
-
80
-
81
-    /**
82
-     * @return EED_Module|EED_Thank_You_Page
83
-     * @throws EE_Error
84
-     * @throws ReflectionException
85
-     */
86
-    public static function instance()
87
-    {
88
-        return parent::get_instance(__CLASS__);
89
-    }
90
-
91
-
92
-    /**
93
-     * set_hooks - for hooking into EE Core, modules, etc
94
-     *
95
-     * @return void
96
-     */
97
-    public static function set_hooks()
98
-    {
99
-        add_action('wp_loaded', array('EED_Thank_You_Page', 'set_definitions'), 2);
100
-    }
101
-
102
-
103
-    /**
104
-     * set_hooks_admin - for hooking into EE Admin Core, modules, etc
105
-     *
106
-     * @return void
107
-     */
108
-    public static function set_hooks_admin()
109
-    {
110
-        add_action(
111
-            'wp_ajax_espresso_resend_reg_confirmation_email',
112
-            array('EED_Thank_You_Page', 'resend_reg_confirmation_email'),
113
-            10,
114
-            2
115
-        );
116
-        add_action(
117
-            'wp_ajax_nopriv_espresso_resend_reg_confirmation_email',
118
-            array('EED_Thank_You_Page', 'resend_reg_confirmation_email'),
119
-            10,
120
-            2
121
-        );
122
-    }
123
-
124
-
125
-    /**
126
-     * set_definitions
127
-     *
128
-     * @return void
129
-     */
130
-    public static function set_definitions()
131
-    {
132
-        define('THANK_YOU_ASSETS_URL', plugin_dir_url(__FILE__) . 'assets/');
133
-        define('THANK_YOU_TEMPLATES_PATH', str_replace('\\', '/', plugin_dir_path(__FILE__)) . 'templates/');
134
-    }
135
-
136
-
137
-    /**
138
-     * get_txn
139
-     *
140
-     * @return EE_Transaction
141
-     * @throws EE_Error
142
-     * @throws ReflectionException
143
-     */
144
-    public function get_txn()
145
-    {
146
-        if ($this->_current_txn instanceof EE_Transaction) {
147
-            return $this->_current_txn;
148
-        }
149
-        $TXN_model = EE_Registry::instance()->load_model('Transaction');
150
-        if (! $TXN_model instanceof EEM_Transaction) {
151
-            EE_Error::add_error(
152
-                __('The transaction model could not be established.', 'event_espresso'),
153
-                __FILE__,
154
-                __FUNCTION__,
155
-                __LINE__
156
-            );
157
-            return null;
158
-        }
159
-        // get the transaction. yes, we may have just loaded it, but it may have been updated, or this may be via an ajax request
160
-        $this->_current_txn = $TXN_model->get_transaction_from_reg_url_link($this->_reg_url_link);
161
-        // verify TXN
162
-        if (WP_DEBUG && ! $this->_current_txn instanceof EE_Transaction) {
163
-            EE_Error::add_error(
164
-                __(
165
-                    'No transaction information could be retrieved or the transaction data is not of the correct type.',
166
-                    'event_espresso'
167
-                ),
168
-                __FILE__,
169
-                __FUNCTION__,
170
-                __LINE__
171
-            );
172
-            return null;
173
-        }
174
-        return $this->_current_txn;
175
-    }
176
-
177
-
178
-    /**
179
-     * get_txn_payments
180
-     *
181
-     * @param int $since
182
-     * @return EE_Payment[]
183
-     * @throws EE_Error
184
-     * @throws ReflectionException
185
-     */
186
-    public function get_txn_payments($since = 0)
187
-    {
188
-        if (! $this->get_txn()) {
189
-            return [];
190
-        }
191
-        $args = array('order_by' => array('PAY_timestamp' => 'ASC'));
192
-        if ($since > 0) {
193
-            $args[0] = array('PAY_timestamp' => array('>', $since));
194
-        }
195
-        // get array of payments with most recent first
196
-        return $this->_current_txn->payments($args);
197
-    }
198
-
199
-
200
-    /**
201
-     * @return bool
202
-     */
203
-    public function isOfflinePaymentMethod()
204
-    {
205
-        return $this->_is_offline_payment_method;
206
-    }
207
-
208
-
209
-
210
-
211
-    /**
212
-     * get_reg_url_link
213
-     *
214
-     * @return void
215
-     */
216
-    private function _get_reg_url_link()
217
-    {
218
-        if ($this->_reg_url_link){
219
-            return;
220
-        }
221
-        // check for reg_url_link
222
-        $reg_url_link = self::getRequest()->getRequestParam('e_reg_url_link');
223
-        // only do thank you page stuff if we have a REG_url_link in the url
224
-        if (WP_DEBUG && ! $reg_url_link) {
225
-            EE_Error::add_error(
226
-                __(
227
-                    'No transaction information could be retrieved because the registration URL link is missing or invalid.',
228
-                    'event_espresso'
229
-                ),
230
-                __FILE__,
231
-                __FUNCTION__,
232
-                __LINE__
233
-            );
234
-        }
235
-        $this->set_reg_url_link($reg_url_link);
236
-    }
237
-
238
-
239
-    /**
240
-     * set_reg_url_link
241
-     *
242
-     * @param string $reg_url_link
243
-     */
244
-    public function set_reg_url_link($reg_url_link = null)
245
-    {
246
-        $this->_reg_url_link = ! empty($reg_url_link) ? $reg_url_link : $this->_reg_url_link;
247
-    }
248
-
249
-
250
-    /**
251
-     * run - initial module setup
252
-     * this method is primarily used for activating resources in the EE_Front_Controller thru the use of filters
253
-     *
254
-     * @param WP $WP
255
-     * @return void
256
-     */
257
-    public function run($WP)
258
-    {
259
-    }
260
-
261
-
262
-    /**
263
-     * load_resources
264
-     *
265
-     * @return void
266
-     * @throws EE_Error
267
-     * @throws ReflectionException
268
-     */
269
-    public function load_resources()
270
-    {
271
-        $this->_get_reg_url_link();
272
-        // resend_reg_confirmation_email ?
273
-        if (self::getRequest()->requestParamIsSet('resend')) {
274
-            EED_Thank_You_Page::resend_reg_confirmation_email();
275
-        }
276
-        EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__);
277
-        $this->_translate_strings();
278
-        // load assets
279
-        add_action('wp_enqueue_scripts', array($this, 'load_js'), 10);
280
-    }
281
-
282
-
283
-    /**
284
-     * load_js
285
-     *
286
-     * @return void
287
-     */
288
-    protected function _translate_strings()
289
-    {
290
-        EE_Registry::$i18n_js_strings['e_reg_url_link'] = $this->_reg_url_link;
291
-        EE_Registry::$i18n_js_strings['initial_access'] = time();
292
-        EE_Registry::$i18n_js_strings['IPN_wait_time'] = EED_Thank_You_Page::IPN_wait_time;
293
-        EE_Registry::$i18n_js_strings['TXN_complete'] = EEM_Transaction::complete_status_code;
294
-        EE_Registry::$i18n_js_strings['TXN_incomplete'] = EEM_Transaction::incomplete_status_code;
295
-        EE_Registry::$i18n_js_strings['checking_for_new_payments'] = __(
296
-            'checking for new payments...',
297
-            'event_espresso'
298
-        );
299
-        EE_Registry::$i18n_js_strings['loading_payment_info'] = __(
300
-            'loading payment information...',
301
-            'event_espresso'
302
-        );
303
-        EE_Registry::$i18n_js_strings['server_error'] = __(
304
-            'An unknown error occurred on the server while attempting to process your request. Please refresh the page and try again.',
305
-            'event_espresso'
306
-        );
307
-        EE_Registry::$i18n_js_strings['slow_IPN'] = apply_filters(
308
-            'EED_Thank_You_Page__load_js__slow_IPN',
309
-            sprintf(
310
-                __(
311
-                    '%sThe Payment Notification appears to be taking longer than usual to arrive. Maybe check back later or just wait for your payment and registration confirmation results to be sent to you via email. We apologize for any inconvenience this may have caused.%s',
312
-                    'event_espresso'
313
-                ),
314
-                '<div id="espresso-thank-you-page-slow-IPN-dv" class="ee-attention jst-left">',
315
-                '</div>'
316
-            )
317
-        );
318
-    }
319
-
320
-
321
-    /**
322
-     * load_js
323
-     *
324
-     * @return void
325
-     */
326
-    public function load_js()
327
-    {
328
-        wp_register_script(
329
-            'thank_you_page',
330
-            THANK_YOU_ASSETS_URL . 'thank_you_page.js',
331
-            array('espresso_core', 'heartbeat'),
332
-            EVENT_ESPRESSO_VERSION,
333
-            true
334
-        );
335
-        wp_enqueue_script('thank_you_page');
336
-        wp_enqueue_style('espresso_default');
337
-    }
338
-
339
-
340
-    /**
341
-     * init
342
-     *
343
-     * @return void
344
-     * @throws EE_Error
345
-     * @throws ReflectionException
346
-     */
347
-    public function init()
348
-    {
349
-        $this->_get_reg_url_link();
350
-        if (! $this->get_txn()) {
351
-            echo EEH_HTML::div(
352
-                EEH_HTML::h4(__('We\'re sorry...', 'event_espresso')) .
353
-                sprintf(
354
-                    __(
355
-                        'This is a system page for displaying transaction information after a purchase.%1$sYou are most likely seeing this notice because you have navigated to this page%1$sthrough some means other than completing a transaction.%1$sSorry for the disappointment, but you will most likely find nothing of interest here.%1$s%1$s',
356
-                        'event_espresso'
357
-                    ),
358
-                    '<br/>'
359
-                ),
360
-                '',
361
-                'ee-attention'
362
-            );
363
-            return;
364
-        }
365
-        // if we've made it to the Thank You page, then let's toggle any "Failed" transactions to "Incomplete"
366
-        if ($this->_current_txn->status_ID() === EEM_Transaction::failed_status_code) {
367
-            $this->_current_txn->set_status(EEM_Transaction::incomplete_status_code);
368
-            $this->_current_txn->save();
369
-        }
370
-        $this->_primary_registrant = $this->_current_txn->primary_registration() instanceof EE_Registration
371
-            ? $this->_current_txn->primary_registration()
372
-            : null;
373
-        $this->_is_primary = $this->_primary_registrant->reg_url_link() === $this->_reg_url_link;
374
-        $show_try_pay_again_link_default = apply_filters(
375
-            'AFEE__EED_Thank_You_Page__init__show_try_pay_again_link_default',
376
-            true
377
-        );
378
-        $this->_show_try_pay_again_link = $show_try_pay_again_link_default;
379
-        // txn status ?
380
-        if ($this->_current_txn->is_completed()) {
381
-            $this->_show_try_pay_again_link = $show_try_pay_again_link_default;
382
-        } elseif ($this->_current_txn->is_incomplete()
383
-            && ($this->_primary_registrant->is_approved()
384
-                || $this->_primary_registrant->is_pending_payment())
385
-        ) {
386
-            $this->_show_try_pay_again_link = true;
387
-        } elseif ($this->_primary_registrant->is_approved() || $this->_primary_registrant->is_pending_payment()) {
388
-            // its pending
389
-            $this->_show_try_pay_again_link = isset(
390
-                EE_Registry::instance()->CFG->registration->show_pending_payment_options
391
-            )
392
-                                              && EE_Registry::instance()->CFG
393
-                                                  ->registration->show_pending_payment_options
394
-                ? true
395
-                : $show_try_pay_again_link_default;
396
-        }
397
-        $this->_payments_closed = ! $this->_current_txn->payment_method() instanceof EE_Payment_Method;
398
-        $this->_is_offline_payment_method = false;
399
-        if (// if payment method is unknown
400
-            ! $this->_current_txn->payment_method() instanceof EE_Payment_Method
401
-            || (
402
-                // or is an offline payment method
403
-                $this->_current_txn->payment_method() instanceof EE_Payment_Method
404
-                && $this->_current_txn->payment_method()->is_off_line()
405
-            )
406
-        ) {
407
-            $this->_is_offline_payment_method = true;
408
-        }
409
-        // link to SPCO
410
-        $revisit_spco_url = add_query_arg(
411
-            array('ee' => '_register', 'revisit' => true, 'e_reg_url_link' => $this->_reg_url_link),
412
-            EE_Registry::instance()->CFG->core->reg_page_url()
413
-        );
414
-        // link to SPCO payment_options
415
-        $this->_SPCO_payment_options_url = $this->_primary_registrant instanceof EE_Registration
416
-            ? $this->_primary_registrant->payment_overview_url()
417
-            : add_query_arg(
418
-                array('step' => 'payment_options'),
419
-                $revisit_spco_url
420
-            );
421
-        // link to SPCO attendee_information
422
-        $this->_SPCO_attendee_information_url = $this->_primary_registrant instanceof EE_Registration
423
-            ? $this->_primary_registrant->edit_attendee_information_url()
424
-            : false;
425
-        do_action('AHEE__EED_Thank_You_Page__init_end', $this->_current_txn);
426
-        // set no cache headers and constants
427
-        EE_System::do_not_cache();
428
-    }
429
-
430
-
431
-    /**
432
-     * display_thank_you_page_results
433
-     *
434
-     * @return string
435
-     * @throws EE_Error
436
-     * @throws ReflectionException
437
-     */
438
-    public function thank_you_page_results()
439
-    {
440
-        $this->init();
441
-        if (! $this->_current_txn instanceof EE_Transaction) {
442
-            return EE_Error::get_notices();
443
-        }
444
-        // link to receipt
445
-        $template_args['TXN_receipt_url'] = $this->_current_txn->receipt_url();
446
-        if (! empty($template_args['TXN_receipt_url'])) {
447
-            $template_args['order_conf_desc'] = __(
448
-                '%1$sCongratulations%2$sYour registration has been successfully processed.%3$sCheck your email for your registration confirmation or click the button below to view / download / print a full description of your purchases and registration information.',
449
-                'event_espresso'
450
-            );
451
-        } else {
452
-            $template_args['order_conf_desc'] = __(
453
-                '%1$sCongratulations%2$sYour registration has been successfully processed.%3$sCheck your email for your registration confirmation.',
454
-                'event_espresso'
455
-            );
456
-        }
457
-        $template_args['transaction'] = $this->_current_txn;
458
-        $template_args['revisit'] = self::getRequest()->getRequestParam('revisit', false, 'bool');
459
-        add_action('AHEE__thank_you_page_overview_template__content', array($this, 'get_registration_details'));
460
-        if ($this->_is_primary && ! $this->_current_txn->is_free()) {
461
-            add_action('AHEE__thank_you_page_overview_template__content', array($this, 'get_ajax_content'));
462
-        }
463
-        return EEH_Template::locate_template(
464
-            THANK_YOU_TEMPLATES_PATH . 'thank-you-page-overview.template.php',
465
-            $template_args
466
-        );
467
-    }
468
-
469
-
470
-    /**
471
-     * _update_server_wait_time
472
-     *
473
-     * @param array $thank_you_page_data thank you page portion of the incoming JSON array from the WP heartbeat data
474
-     * @return array
475
-     * @throws EE_Error
476
-     * @throws ReflectionException
477
-     */
478
-    private function _update_server_wait_time($thank_you_page_data = array())
479
-    {
480
-        $response['espresso_thank_you_page'] = array(
481
-            'still_waiting' => isset($thank_you_page_data['initial_access'])
482
-                ? time() - $thank_you_page_data['initial_access']
483
-                : 0,
484
-            'txn_status'    => $this->_current_txn->status_ID(),
485
-        );
486
-        return $response;
487
-    }
488
-
489
-
490
-    /**
491
-     * get_registration_details
492
-     *
493
-     * @throws EE_Error
494
-     */
495
-    public function get_registration_details()
496
-    {
497
-        // prepare variables for displaying
498
-        $template_args = array();
499
-        $template_args['transaction'] = $this->_current_txn;
500
-        $template_args['reg_url_link'] = $this->_reg_url_link;
501
-        $template_args['is_primary'] = $this->_is_primary;
502
-        $template_args['SPCO_attendee_information_url'] = $this->_SPCO_attendee_information_url;
503
-        $template_args['resend_reg_confirmation_url'] = add_query_arg(
504
-            array('token' => $this->_reg_url_link, 'resend_reg_confirmation' => 'true'),
505
-            EE_Registry::instance()->CFG->core->thank_you_page_url()
506
-        );
507
-        // verify template arguments
508
-        EEH_Template_Validator::verify_instanceof($template_args['transaction'], '$transaction', 'EE_Transaction');
509
-        EEH_Template_Validator::verify_isnt_null(
510
-            $template_args['SPCO_attendee_information_url'],
511
-            '$SPCO_attendee_information_url'
512
-        );
513
-        echo EEH_Template::locate_template(
514
-            THANK_YOU_TEMPLATES_PATH . 'thank-you-page-registration-details.template.php',
515
-            $template_args
516
-        );
517
-    }
518
-
519
-
520
-    /**
521
-     * resend_reg_confirmation_email
522
-     *
523
-     * @throws EE_Error
524
-     * @throws ReflectionException
525
-     */
526
-    public static function resend_reg_confirmation_email()
527
-    {
528
-        $reg_url_link = self::getRequest()->getRequestParam('token');
529
-        // was a REG_ID passed ?
530
-        if ($reg_url_link) {
531
-            $registration = EEM_Registration::instance()->get_one(
532
-                array(array('REG_url_link' => $reg_url_link))
533
-            );
534
-            if ($registration instanceof EE_Registration) {
535
-                // resend email
536
-                EED_Messages::process_resend(array('_REG_ID' => $registration->ID()));
537
-            } else {
538
-                EE_Error::add_error(
539
-                    __(
540
-                        'The Registration Confirmation email could not be sent because a valid Registration could not be retrieved from the database.',
541
-                        'event_espresso'
542
-                    ),
543
-                    __FILE__,
544
-                    __FUNCTION__,
545
-                    __LINE__
546
-                );
547
-            }
548
-        } else {
549
-            EE_Error::add_error(
550
-                __(
551
-                    'The Registration Confirmation email could not be sent because a registration token is missing or invalid.',
552
-                    'event_espresso'
553
-                ),
554
-                __FILE__,
555
-                __FUNCTION__,
556
-                __LINE__
557
-            );
558
-        }
559
-        // request sent via AJAX ?
560
-        if (EE_FRONT_AJAX) {
561
-            echo wp_json_encode(EE_Error::get_notices(false));
562
-            die();
563
-            // or was JS disabled ?
564
-        } else {
565
-            // save errors so that they get picked up on the next request
566
-            EE_Error::get_notices(true, true);
567
-            wp_safe_redirect(
568
-                add_query_arg(
569
-                    array('e_reg_url_link' => $reg_url_link),
570
-                    EE_Registry::instance()->CFG->core->thank_you_page_url()
571
-                )
572
-            );
573
-        }
574
-    }
575
-
576
-
577
-    /**
578
-     * get_ajax_content
579
-     *
580
-     * @return void
581
-     * @throws EE_Error
582
-     * @throws ReflectionException
583
-     */
584
-    public function get_ajax_content()
585
-    {
586
-        if (! $this->get_txn()) {
587
-            return;
588
-        }
589
-        // first determine which event(s) require pre-approval or not
590
-        $events = array();
591
-        $events_requiring_pre_approval = array();
592
-        foreach ($this->_current_txn->registrations() as $registration) {
593
-            if ($registration instanceof EE_Registration) {
594
-                $event = $registration->event();
595
-                if ($event instanceof EE_Event) {
596
-                    if ($registration->is_not_approved() && $registration->event() instanceof EE_Event) {
597
-                        $events_requiring_pre_approval[ $event->ID() ] = $event;
598
-                    } else {
599
-                        $events[ $event->ID() ] = $event;
600
-                    }
601
-                }
602
-            }
603
-        }
604
-        $this->display_details_for_events_requiring_pre_approval($events_requiring_pre_approval);
605
-        $this->display_details_for_events($events);
606
-    }
607
-
608
-
609
-    /**
610
-     * display_details_for_events
611
-     *
612
-     * @param EE_Event[] $events
613
-     * @return void
614
-     */
615
-    public function display_details_for_events($events = array())
616
-    {
617
-        if (! empty($events)) {
618
-            ?>
14
+	/**
15
+	 * time in seconds to wait for the IPN to arrive before telling the registrant to bugger off ( 1200s = 20 minutes )
16
+	 */
17
+	const IPN_wait_time = 1200;
18
+
19
+	/**
20
+	 * The transaction specified by the reg_url_link passed from the Request, or from the Session
21
+	 *
22
+	 * @var EE_Transaction $_current_txn
23
+	 */
24
+	private $_current_txn;
25
+
26
+	/**
27
+	 * @var EE_Registration $_primary_registrant
28
+	 */
29
+	private $_primary_registrant;
30
+
31
+	/**
32
+	 * The reg_url_link passed from the Request, or from the Session
33
+	 *
34
+	 * @var string $_reg_url_link
35
+	 */
36
+	private $_reg_url_link;
37
+
38
+	/**
39
+	 * whether the incoming reg_url_link is for the primary registrant or not
40
+	 *
41
+	 * @var boolean $_is_primary
42
+	 */
43
+	private $_is_primary;
44
+
45
+	/**
46
+	 * The URL for revisiting the SPCO attendee information step
47
+	 *
48
+	 * @var string $_SPCO_attendee_information_url
49
+	 */
50
+	private $_SPCO_attendee_information_url;
51
+
52
+	/**
53
+	 * The URL for revisiting the SPCO payment options step
54
+	 *
55
+	 * @var string $_SPCO_payment_options_url
56
+	 */
57
+	private $_SPCO_payment_options_url;
58
+
59
+	/**
60
+	 * whether to display the Payment Options link
61
+	 *
62
+	 * @var boolean $_show_try_pay_again_link
63
+	 */
64
+	private $_show_try_pay_again_link = false;
65
+
66
+	/**
67
+	 * whether payments are allowed at this time
68
+	 *
69
+	 * @var boolean $_payments_closed
70
+	 */
71
+	private $_payments_closed = false;
72
+
73
+	/**
74
+	 * whether the selected payment method is Bank, Check , Invoice, etc
75
+	 *
76
+	 * @var boolean $_is_offline_payment_method
77
+	 */
78
+	private $_is_offline_payment_method = true;
79
+
80
+
81
+	/**
82
+	 * @return EED_Module|EED_Thank_You_Page
83
+	 * @throws EE_Error
84
+	 * @throws ReflectionException
85
+	 */
86
+	public static function instance()
87
+	{
88
+		return parent::get_instance(__CLASS__);
89
+	}
90
+
91
+
92
+	/**
93
+	 * set_hooks - for hooking into EE Core, modules, etc
94
+	 *
95
+	 * @return void
96
+	 */
97
+	public static function set_hooks()
98
+	{
99
+		add_action('wp_loaded', array('EED_Thank_You_Page', 'set_definitions'), 2);
100
+	}
101
+
102
+
103
+	/**
104
+	 * set_hooks_admin - for hooking into EE Admin Core, modules, etc
105
+	 *
106
+	 * @return void
107
+	 */
108
+	public static function set_hooks_admin()
109
+	{
110
+		add_action(
111
+			'wp_ajax_espresso_resend_reg_confirmation_email',
112
+			array('EED_Thank_You_Page', 'resend_reg_confirmation_email'),
113
+			10,
114
+			2
115
+		);
116
+		add_action(
117
+			'wp_ajax_nopriv_espresso_resend_reg_confirmation_email',
118
+			array('EED_Thank_You_Page', 'resend_reg_confirmation_email'),
119
+			10,
120
+			2
121
+		);
122
+	}
123
+
124
+
125
+	/**
126
+	 * set_definitions
127
+	 *
128
+	 * @return void
129
+	 */
130
+	public static function set_definitions()
131
+	{
132
+		define('THANK_YOU_ASSETS_URL', plugin_dir_url(__FILE__) . 'assets/');
133
+		define('THANK_YOU_TEMPLATES_PATH', str_replace('\\', '/', plugin_dir_path(__FILE__)) . 'templates/');
134
+	}
135
+
136
+
137
+	/**
138
+	 * get_txn
139
+	 *
140
+	 * @return EE_Transaction
141
+	 * @throws EE_Error
142
+	 * @throws ReflectionException
143
+	 */
144
+	public function get_txn()
145
+	{
146
+		if ($this->_current_txn instanceof EE_Transaction) {
147
+			return $this->_current_txn;
148
+		}
149
+		$TXN_model = EE_Registry::instance()->load_model('Transaction');
150
+		if (! $TXN_model instanceof EEM_Transaction) {
151
+			EE_Error::add_error(
152
+				__('The transaction model could not be established.', 'event_espresso'),
153
+				__FILE__,
154
+				__FUNCTION__,
155
+				__LINE__
156
+			);
157
+			return null;
158
+		}
159
+		// get the transaction. yes, we may have just loaded it, but it may have been updated, or this may be via an ajax request
160
+		$this->_current_txn = $TXN_model->get_transaction_from_reg_url_link($this->_reg_url_link);
161
+		// verify TXN
162
+		if (WP_DEBUG && ! $this->_current_txn instanceof EE_Transaction) {
163
+			EE_Error::add_error(
164
+				__(
165
+					'No transaction information could be retrieved or the transaction data is not of the correct type.',
166
+					'event_espresso'
167
+				),
168
+				__FILE__,
169
+				__FUNCTION__,
170
+				__LINE__
171
+			);
172
+			return null;
173
+		}
174
+		return $this->_current_txn;
175
+	}
176
+
177
+
178
+	/**
179
+	 * get_txn_payments
180
+	 *
181
+	 * @param int $since
182
+	 * @return EE_Payment[]
183
+	 * @throws EE_Error
184
+	 * @throws ReflectionException
185
+	 */
186
+	public function get_txn_payments($since = 0)
187
+	{
188
+		if (! $this->get_txn()) {
189
+			return [];
190
+		}
191
+		$args = array('order_by' => array('PAY_timestamp' => 'ASC'));
192
+		if ($since > 0) {
193
+			$args[0] = array('PAY_timestamp' => array('>', $since));
194
+		}
195
+		// get array of payments with most recent first
196
+		return $this->_current_txn->payments($args);
197
+	}
198
+
199
+
200
+	/**
201
+	 * @return bool
202
+	 */
203
+	public function isOfflinePaymentMethod()
204
+	{
205
+		return $this->_is_offline_payment_method;
206
+	}
207
+
208
+
209
+
210
+
211
+	/**
212
+	 * get_reg_url_link
213
+	 *
214
+	 * @return void
215
+	 */
216
+	private function _get_reg_url_link()
217
+	{
218
+		if ($this->_reg_url_link){
219
+			return;
220
+		}
221
+		// check for reg_url_link
222
+		$reg_url_link = self::getRequest()->getRequestParam('e_reg_url_link');
223
+		// only do thank you page stuff if we have a REG_url_link in the url
224
+		if (WP_DEBUG && ! $reg_url_link) {
225
+			EE_Error::add_error(
226
+				__(
227
+					'No transaction information could be retrieved because the registration URL link is missing or invalid.',
228
+					'event_espresso'
229
+				),
230
+				__FILE__,
231
+				__FUNCTION__,
232
+				__LINE__
233
+			);
234
+		}
235
+		$this->set_reg_url_link($reg_url_link);
236
+	}
237
+
238
+
239
+	/**
240
+	 * set_reg_url_link
241
+	 *
242
+	 * @param string $reg_url_link
243
+	 */
244
+	public function set_reg_url_link($reg_url_link = null)
245
+	{
246
+		$this->_reg_url_link = ! empty($reg_url_link) ? $reg_url_link : $this->_reg_url_link;
247
+	}
248
+
249
+
250
+	/**
251
+	 * run - initial module setup
252
+	 * this method is primarily used for activating resources in the EE_Front_Controller thru the use of filters
253
+	 *
254
+	 * @param WP $WP
255
+	 * @return void
256
+	 */
257
+	public function run($WP)
258
+	{
259
+	}
260
+
261
+
262
+	/**
263
+	 * load_resources
264
+	 *
265
+	 * @return void
266
+	 * @throws EE_Error
267
+	 * @throws ReflectionException
268
+	 */
269
+	public function load_resources()
270
+	{
271
+		$this->_get_reg_url_link();
272
+		// resend_reg_confirmation_email ?
273
+		if (self::getRequest()->requestParamIsSet('resend')) {
274
+			EED_Thank_You_Page::resend_reg_confirmation_email();
275
+		}
276
+		EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__);
277
+		$this->_translate_strings();
278
+		// load assets
279
+		add_action('wp_enqueue_scripts', array($this, 'load_js'), 10);
280
+	}
281
+
282
+
283
+	/**
284
+	 * load_js
285
+	 *
286
+	 * @return void
287
+	 */
288
+	protected function _translate_strings()
289
+	{
290
+		EE_Registry::$i18n_js_strings['e_reg_url_link'] = $this->_reg_url_link;
291
+		EE_Registry::$i18n_js_strings['initial_access'] = time();
292
+		EE_Registry::$i18n_js_strings['IPN_wait_time'] = EED_Thank_You_Page::IPN_wait_time;
293
+		EE_Registry::$i18n_js_strings['TXN_complete'] = EEM_Transaction::complete_status_code;
294
+		EE_Registry::$i18n_js_strings['TXN_incomplete'] = EEM_Transaction::incomplete_status_code;
295
+		EE_Registry::$i18n_js_strings['checking_for_new_payments'] = __(
296
+			'checking for new payments...',
297
+			'event_espresso'
298
+		);
299
+		EE_Registry::$i18n_js_strings['loading_payment_info'] = __(
300
+			'loading payment information...',
301
+			'event_espresso'
302
+		);
303
+		EE_Registry::$i18n_js_strings['server_error'] = __(
304
+			'An unknown error occurred on the server while attempting to process your request. Please refresh the page and try again.',
305
+			'event_espresso'
306
+		);
307
+		EE_Registry::$i18n_js_strings['slow_IPN'] = apply_filters(
308
+			'EED_Thank_You_Page__load_js__slow_IPN',
309
+			sprintf(
310
+				__(
311
+					'%sThe Payment Notification appears to be taking longer than usual to arrive. Maybe check back later or just wait for your payment and registration confirmation results to be sent to you via email. We apologize for any inconvenience this may have caused.%s',
312
+					'event_espresso'
313
+				),
314
+				'<div id="espresso-thank-you-page-slow-IPN-dv" class="ee-attention jst-left">',
315
+				'</div>'
316
+			)
317
+		);
318
+	}
319
+
320
+
321
+	/**
322
+	 * load_js
323
+	 *
324
+	 * @return void
325
+	 */
326
+	public function load_js()
327
+	{
328
+		wp_register_script(
329
+			'thank_you_page',
330
+			THANK_YOU_ASSETS_URL . 'thank_you_page.js',
331
+			array('espresso_core', 'heartbeat'),
332
+			EVENT_ESPRESSO_VERSION,
333
+			true
334
+		);
335
+		wp_enqueue_script('thank_you_page');
336
+		wp_enqueue_style('espresso_default');
337
+	}
338
+
339
+
340
+	/**
341
+	 * init
342
+	 *
343
+	 * @return void
344
+	 * @throws EE_Error
345
+	 * @throws ReflectionException
346
+	 */
347
+	public function init()
348
+	{
349
+		$this->_get_reg_url_link();
350
+		if (! $this->get_txn()) {
351
+			echo EEH_HTML::div(
352
+				EEH_HTML::h4(__('We\'re sorry...', 'event_espresso')) .
353
+				sprintf(
354
+					__(
355
+						'This is a system page for displaying transaction information after a purchase.%1$sYou are most likely seeing this notice because you have navigated to this page%1$sthrough some means other than completing a transaction.%1$sSorry for the disappointment, but you will most likely find nothing of interest here.%1$s%1$s',
356
+						'event_espresso'
357
+					),
358
+					'<br/>'
359
+				),
360
+				'',
361
+				'ee-attention'
362
+			);
363
+			return;
364
+		}
365
+		// if we've made it to the Thank You page, then let's toggle any "Failed" transactions to "Incomplete"
366
+		if ($this->_current_txn->status_ID() === EEM_Transaction::failed_status_code) {
367
+			$this->_current_txn->set_status(EEM_Transaction::incomplete_status_code);
368
+			$this->_current_txn->save();
369
+		}
370
+		$this->_primary_registrant = $this->_current_txn->primary_registration() instanceof EE_Registration
371
+			? $this->_current_txn->primary_registration()
372
+			: null;
373
+		$this->_is_primary = $this->_primary_registrant->reg_url_link() === $this->_reg_url_link;
374
+		$show_try_pay_again_link_default = apply_filters(
375
+			'AFEE__EED_Thank_You_Page__init__show_try_pay_again_link_default',
376
+			true
377
+		);
378
+		$this->_show_try_pay_again_link = $show_try_pay_again_link_default;
379
+		// txn status ?
380
+		if ($this->_current_txn->is_completed()) {
381
+			$this->_show_try_pay_again_link = $show_try_pay_again_link_default;
382
+		} elseif ($this->_current_txn->is_incomplete()
383
+			&& ($this->_primary_registrant->is_approved()
384
+				|| $this->_primary_registrant->is_pending_payment())
385
+		) {
386
+			$this->_show_try_pay_again_link = true;
387
+		} elseif ($this->_primary_registrant->is_approved() || $this->_primary_registrant->is_pending_payment()) {
388
+			// its pending
389
+			$this->_show_try_pay_again_link = isset(
390
+				EE_Registry::instance()->CFG->registration->show_pending_payment_options
391
+			)
392
+											  && EE_Registry::instance()->CFG
393
+												  ->registration->show_pending_payment_options
394
+				? true
395
+				: $show_try_pay_again_link_default;
396
+		}
397
+		$this->_payments_closed = ! $this->_current_txn->payment_method() instanceof EE_Payment_Method;
398
+		$this->_is_offline_payment_method = false;
399
+		if (// if payment method is unknown
400
+			! $this->_current_txn->payment_method() instanceof EE_Payment_Method
401
+			|| (
402
+				// or is an offline payment method
403
+				$this->_current_txn->payment_method() instanceof EE_Payment_Method
404
+				&& $this->_current_txn->payment_method()->is_off_line()
405
+			)
406
+		) {
407
+			$this->_is_offline_payment_method = true;
408
+		}
409
+		// link to SPCO
410
+		$revisit_spco_url = add_query_arg(
411
+			array('ee' => '_register', 'revisit' => true, 'e_reg_url_link' => $this->_reg_url_link),
412
+			EE_Registry::instance()->CFG->core->reg_page_url()
413
+		);
414
+		// link to SPCO payment_options
415
+		$this->_SPCO_payment_options_url = $this->_primary_registrant instanceof EE_Registration
416
+			? $this->_primary_registrant->payment_overview_url()
417
+			: add_query_arg(
418
+				array('step' => 'payment_options'),
419
+				$revisit_spco_url
420
+			);
421
+		// link to SPCO attendee_information
422
+		$this->_SPCO_attendee_information_url = $this->_primary_registrant instanceof EE_Registration
423
+			? $this->_primary_registrant->edit_attendee_information_url()
424
+			: false;
425
+		do_action('AHEE__EED_Thank_You_Page__init_end', $this->_current_txn);
426
+		// set no cache headers and constants
427
+		EE_System::do_not_cache();
428
+	}
429
+
430
+
431
+	/**
432
+	 * display_thank_you_page_results
433
+	 *
434
+	 * @return string
435
+	 * @throws EE_Error
436
+	 * @throws ReflectionException
437
+	 */
438
+	public function thank_you_page_results()
439
+	{
440
+		$this->init();
441
+		if (! $this->_current_txn instanceof EE_Transaction) {
442
+			return EE_Error::get_notices();
443
+		}
444
+		// link to receipt
445
+		$template_args['TXN_receipt_url'] = $this->_current_txn->receipt_url();
446
+		if (! empty($template_args['TXN_receipt_url'])) {
447
+			$template_args['order_conf_desc'] = __(
448
+				'%1$sCongratulations%2$sYour registration has been successfully processed.%3$sCheck your email for your registration confirmation or click the button below to view / download / print a full description of your purchases and registration information.',
449
+				'event_espresso'
450
+			);
451
+		} else {
452
+			$template_args['order_conf_desc'] = __(
453
+				'%1$sCongratulations%2$sYour registration has been successfully processed.%3$sCheck your email for your registration confirmation.',
454
+				'event_espresso'
455
+			);
456
+		}
457
+		$template_args['transaction'] = $this->_current_txn;
458
+		$template_args['revisit'] = self::getRequest()->getRequestParam('revisit', false, 'bool');
459
+		add_action('AHEE__thank_you_page_overview_template__content', array($this, 'get_registration_details'));
460
+		if ($this->_is_primary && ! $this->_current_txn->is_free()) {
461
+			add_action('AHEE__thank_you_page_overview_template__content', array($this, 'get_ajax_content'));
462
+		}
463
+		return EEH_Template::locate_template(
464
+			THANK_YOU_TEMPLATES_PATH . 'thank-you-page-overview.template.php',
465
+			$template_args
466
+		);
467
+	}
468
+
469
+
470
+	/**
471
+	 * _update_server_wait_time
472
+	 *
473
+	 * @param array $thank_you_page_data thank you page portion of the incoming JSON array from the WP heartbeat data
474
+	 * @return array
475
+	 * @throws EE_Error
476
+	 * @throws ReflectionException
477
+	 */
478
+	private function _update_server_wait_time($thank_you_page_data = array())
479
+	{
480
+		$response['espresso_thank_you_page'] = array(
481
+			'still_waiting' => isset($thank_you_page_data['initial_access'])
482
+				? time() - $thank_you_page_data['initial_access']
483
+				: 0,
484
+			'txn_status'    => $this->_current_txn->status_ID(),
485
+		);
486
+		return $response;
487
+	}
488
+
489
+
490
+	/**
491
+	 * get_registration_details
492
+	 *
493
+	 * @throws EE_Error
494
+	 */
495
+	public function get_registration_details()
496
+	{
497
+		// prepare variables for displaying
498
+		$template_args = array();
499
+		$template_args['transaction'] = $this->_current_txn;
500
+		$template_args['reg_url_link'] = $this->_reg_url_link;
501
+		$template_args['is_primary'] = $this->_is_primary;
502
+		$template_args['SPCO_attendee_information_url'] = $this->_SPCO_attendee_information_url;
503
+		$template_args['resend_reg_confirmation_url'] = add_query_arg(
504
+			array('token' => $this->_reg_url_link, 'resend_reg_confirmation' => 'true'),
505
+			EE_Registry::instance()->CFG->core->thank_you_page_url()
506
+		);
507
+		// verify template arguments
508
+		EEH_Template_Validator::verify_instanceof($template_args['transaction'], '$transaction', 'EE_Transaction');
509
+		EEH_Template_Validator::verify_isnt_null(
510
+			$template_args['SPCO_attendee_information_url'],
511
+			'$SPCO_attendee_information_url'
512
+		);
513
+		echo EEH_Template::locate_template(
514
+			THANK_YOU_TEMPLATES_PATH . 'thank-you-page-registration-details.template.php',
515
+			$template_args
516
+		);
517
+	}
518
+
519
+
520
+	/**
521
+	 * resend_reg_confirmation_email
522
+	 *
523
+	 * @throws EE_Error
524
+	 * @throws ReflectionException
525
+	 */
526
+	public static function resend_reg_confirmation_email()
527
+	{
528
+		$reg_url_link = self::getRequest()->getRequestParam('token');
529
+		// was a REG_ID passed ?
530
+		if ($reg_url_link) {
531
+			$registration = EEM_Registration::instance()->get_one(
532
+				array(array('REG_url_link' => $reg_url_link))
533
+			);
534
+			if ($registration instanceof EE_Registration) {
535
+				// resend email
536
+				EED_Messages::process_resend(array('_REG_ID' => $registration->ID()));
537
+			} else {
538
+				EE_Error::add_error(
539
+					__(
540
+						'The Registration Confirmation email could not be sent because a valid Registration could not be retrieved from the database.',
541
+						'event_espresso'
542
+					),
543
+					__FILE__,
544
+					__FUNCTION__,
545
+					__LINE__
546
+				);
547
+			}
548
+		} else {
549
+			EE_Error::add_error(
550
+				__(
551
+					'The Registration Confirmation email could not be sent because a registration token is missing or invalid.',
552
+					'event_espresso'
553
+				),
554
+				__FILE__,
555
+				__FUNCTION__,
556
+				__LINE__
557
+			);
558
+		}
559
+		// request sent via AJAX ?
560
+		if (EE_FRONT_AJAX) {
561
+			echo wp_json_encode(EE_Error::get_notices(false));
562
+			die();
563
+			// or was JS disabled ?
564
+		} else {
565
+			// save errors so that they get picked up on the next request
566
+			EE_Error::get_notices(true, true);
567
+			wp_safe_redirect(
568
+				add_query_arg(
569
+					array('e_reg_url_link' => $reg_url_link),
570
+					EE_Registry::instance()->CFG->core->thank_you_page_url()
571
+				)
572
+			);
573
+		}
574
+	}
575
+
576
+
577
+	/**
578
+	 * get_ajax_content
579
+	 *
580
+	 * @return void
581
+	 * @throws EE_Error
582
+	 * @throws ReflectionException
583
+	 */
584
+	public function get_ajax_content()
585
+	{
586
+		if (! $this->get_txn()) {
587
+			return;
588
+		}
589
+		// first determine which event(s) require pre-approval or not
590
+		$events = array();
591
+		$events_requiring_pre_approval = array();
592
+		foreach ($this->_current_txn->registrations() as $registration) {
593
+			if ($registration instanceof EE_Registration) {
594
+				$event = $registration->event();
595
+				if ($event instanceof EE_Event) {
596
+					if ($registration->is_not_approved() && $registration->event() instanceof EE_Event) {
597
+						$events_requiring_pre_approval[ $event->ID() ] = $event;
598
+					} else {
599
+						$events[ $event->ID() ] = $event;
600
+					}
601
+				}
602
+			}
603
+		}
604
+		$this->display_details_for_events_requiring_pre_approval($events_requiring_pre_approval);
605
+		$this->display_details_for_events($events);
606
+	}
607
+
608
+
609
+	/**
610
+	 * display_details_for_events
611
+	 *
612
+	 * @param EE_Event[] $events
613
+	 * @return void
614
+	 */
615
+	public function display_details_for_events($events = array())
616
+	{
617
+		if (! empty($events)) {
618
+			?>
619 619
             <div id="espresso-thank-you-page-ajax-content-dv">
620 620
                 <div id="espresso-thank-you-page-ajax-transaction-dv"></div>
621 621
                 <div id="espresso-thank-you-page-ajax-payment-dv"></div>
@@ -623,19 +623,19 @@  discard block
 block discarded – undo
623 623
                     <div id="ee-ajax-loading-dv" class="float-left lt-blue-text">
624 624
                         <span class="dashicons dashicons-upload"></span><span id="ee-ajax-loading-msg-spn">
625 625
                             <?php _e(
626
-                                'loading transaction and payment information...',
627
-                                'event_espresso'
628
-                            ); ?></span>
626
+								'loading transaction and payment information...',
627
+								'event_espresso'
628
+							); ?></span>
629 629
                     </div>
630 630
                     <?php if (! $this->_is_offline_payment_method && ! $this->_payments_closed) : ?>
631 631
                         <p id="ee-ajax-loading-pg" class="highlight-bg small-text clear">
632 632
                             <?php echo apply_filters(
633
-                                'EED_Thank_You_Page__get_ajax_content__waiting_for_IPN_msg',
634
-                                __(
635
-                                    'Some payment gateways can take 15 minutes or more to return their payment notification, so please be patient if you require payment confirmation as soon as possible. Please note that as soon as everything is finalized, we will send your full payment and registration confirmation results to you via email.',
636
-                                    'event_espresso'
637
-                                )
638
-                            ); ?>
633
+								'EED_Thank_You_Page__get_ajax_content__waiting_for_IPN_msg',
634
+								__(
635
+									'Some payment gateways can take 15 minutes or more to return their payment notification, so please be patient if you require payment confirmation as soon as possible. Please note that as soon as everything is finalized, we will send your full payment and registration confirmation results to you via email.',
636
+									'event_espresso'
637
+								)
638
+							); ?>
639 639
                             <br/>
640 640
                             <span class="jst-rght ee-block small-text lt-grey-text">
641 641
                                 <?php _e('current wait time ', 'event_espresso'); ?>
@@ -646,117 +646,117 @@  discard block
 block discarded – undo
646 646
                 <div class="clear"></div>
647 647
             </div>
648 648
             <?php
649
-        }
650
-    }
651
-
652
-
653
-    /**
654
-     * display_details_for_events_requiring_pre_approval
655
-     *
656
-     * @param EE_Event[] $events
657
-     * @return void
658
-     * @throws EE_Error
659
-     * @throws EE_Error
660
-     */
661
-    public function display_details_for_events_requiring_pre_approval($events = array())
662
-    {
663
-        if (! empty($events)) {
664
-            ?>
649
+		}
650
+	}
651
+
652
+
653
+	/**
654
+	 * display_details_for_events_requiring_pre_approval
655
+	 *
656
+	 * @param EE_Event[] $events
657
+	 * @return void
658
+	 * @throws EE_Error
659
+	 * @throws EE_Error
660
+	 */
661
+	public function display_details_for_events_requiring_pre_approval($events = array())
662
+	{
663
+		if (! empty($events)) {
664
+			?>
665 665
             <div id="espresso-thank-you-page-not-approved-message-dv">
666 666
                 <h4 class="orange-text"><?php _e('Important Notice:', 'event_espresso'); ?></h4>
667 667
                 <p id="events-requiring-pre-approval-pg" class="small-text">
668 668
                     <?php echo apply_filters(
669
-                        'AHEE__EED_Thank_You_Page__get_ajax_content__not_approved_message',
670
-                        __(
671
-                            'The following Event(s) you have registered for do not require payment at this time and will not be billed for during this transaction. Billing will only occur after all attendees have been approved by the event organizer. You will be notified when your registration has been processed. If this is a free event, then no billing will occur.',
672
-                            'event_espresso'
673
-                        )
674
-                    ); ?>
669
+						'AHEE__EED_Thank_You_Page__get_ajax_content__not_approved_message',
670
+						__(
671
+							'The following Event(s) you have registered for do not require payment at this time and will not be billed for during this transaction. Billing will only occur after all attendees have been approved by the event organizer. You will be notified when your registration has been processed. If this is a free event, then no billing will occur.',
672
+							'event_espresso'
673
+						)
674
+					); ?>
675 675
                 </p>
676 676
                 <ul class="events-requiring-pre-approval-ul">
677 677
                     <?php
678
-                    foreach ($events as $event) {
679
-                        if ($event instanceof EE_Event) {
680
-                            echo '<li><span class="dashicons dashicons-marker ee-icon-size-16 orange-text"></span>',
681
-                            $event->name(),
682
-                            '</li>';
683
-                        }
684
-                    } ?>
678
+					foreach ($events as $event) {
679
+						if ($event instanceof EE_Event) {
680
+							echo '<li><span class="dashicons dashicons-marker ee-icon-size-16 orange-text"></span>',
681
+							$event->name(),
682
+							'</li>';
683
+						}
684
+					} ?>
685 685
                 </ul>
686 686
                 <div class="clear"></div>
687 687
             </div>
688 688
             <?php
689
-        }
690
-    }
691
-
692
-
693
-    /**
694
-     * get_transaction_details
695
-     *
696
-     * @return string
697
-     * @throws EE_Error
698
-     */
699
-    public function get_transaction_details()
700
-    {
701
-        // prepare variables for displaying
702
-        $template_args = array();
703
-        $template_args['transaction'] = $this->_current_txn;
704
-        $template_args['reg_url_link'] = $this->_reg_url_link;
705
-        $template_args['primary_registrant_name'] = $this->_primary_registrant->attendee()->full_name(true);
706
-        // link to SPCO payment_options
707
-        $template_args['show_try_pay_again_link'] = $this->_show_try_pay_again_link;
708
-        $template_args['SPCO_payment_options_url'] = $this->_SPCO_payment_options_url;
709
-        // verify template arguments
710
-        EEH_Template_Validator::verify_instanceof($template_args['transaction'], '$transaction', 'EE_Transaction');
711
-        EEH_Template_Validator::verify_isnt_null(
712
-            $template_args['show_try_pay_again_link'],
713
-            '$show_try_pay_again_link'
714
-        );
715
-        EEH_Template_Validator::verify_isnt_null(
716
-            $template_args['SPCO_payment_options_url'],
717
-            '$SPCO_payment_options_url'
718
-        );
719
-        return EEH_Template::locate_template(
720
-            THANK_YOU_TEMPLATES_PATH . 'thank-you-page-transaction-details.template.php',
721
-            $template_args
722
-        );
723
-    }
724
-
725
-
726
-    /**
727
-     * get_payment_row_html
728
-     *
729
-     * @param EE_Payment $payment
730
-     * @return string
731
-     * @throws EE_Error
732
-     */
733
-    public function get_payment_row_html($payment = null)
734
-    {
735
-        $html = '';
736
-        if ($payment instanceof EE_Payment) {
737
-            if ($payment->payment_method() instanceof EE_Payment_Method
738
-                && $payment->status() === EEM_Payment::status_id_failed
739
-                && $payment->payment_method()->is_off_site()
740
-            ) {
741
-                // considering the registrant has made it to the Thank You page,
742
-                // any failed payments may actually be pending and the IPN is just slow
743
-                // so let's
744
-                $payment->set_status(EEM_Payment::status_id_pending);
745
-            }
746
-            $payment_declined_msg = $payment->STS_ID() === EEM_Payment::status_id_declined
747
-                ? '<br /><span class="small-text">' . $payment->gateway_response() . '</span>'
748
-                : '';
749
-            $html .= '
689
+		}
690
+	}
691
+
692
+
693
+	/**
694
+	 * get_transaction_details
695
+	 *
696
+	 * @return string
697
+	 * @throws EE_Error
698
+	 */
699
+	public function get_transaction_details()
700
+	{
701
+		// prepare variables for displaying
702
+		$template_args = array();
703
+		$template_args['transaction'] = $this->_current_txn;
704
+		$template_args['reg_url_link'] = $this->_reg_url_link;
705
+		$template_args['primary_registrant_name'] = $this->_primary_registrant->attendee()->full_name(true);
706
+		// link to SPCO payment_options
707
+		$template_args['show_try_pay_again_link'] = $this->_show_try_pay_again_link;
708
+		$template_args['SPCO_payment_options_url'] = $this->_SPCO_payment_options_url;
709
+		// verify template arguments
710
+		EEH_Template_Validator::verify_instanceof($template_args['transaction'], '$transaction', 'EE_Transaction');
711
+		EEH_Template_Validator::verify_isnt_null(
712
+			$template_args['show_try_pay_again_link'],
713
+			'$show_try_pay_again_link'
714
+		);
715
+		EEH_Template_Validator::verify_isnt_null(
716
+			$template_args['SPCO_payment_options_url'],
717
+			'$SPCO_payment_options_url'
718
+		);
719
+		return EEH_Template::locate_template(
720
+			THANK_YOU_TEMPLATES_PATH . 'thank-you-page-transaction-details.template.php',
721
+			$template_args
722
+		);
723
+	}
724
+
725
+
726
+	/**
727
+	 * get_payment_row_html
728
+	 *
729
+	 * @param EE_Payment $payment
730
+	 * @return string
731
+	 * @throws EE_Error
732
+	 */
733
+	public function get_payment_row_html($payment = null)
734
+	{
735
+		$html = '';
736
+		if ($payment instanceof EE_Payment) {
737
+			if ($payment->payment_method() instanceof EE_Payment_Method
738
+				&& $payment->status() === EEM_Payment::status_id_failed
739
+				&& $payment->payment_method()->is_off_site()
740
+			) {
741
+				// considering the registrant has made it to the Thank You page,
742
+				// any failed payments may actually be pending and the IPN is just slow
743
+				// so let's
744
+				$payment->set_status(EEM_Payment::status_id_pending);
745
+			}
746
+			$payment_declined_msg = $payment->STS_ID() === EEM_Payment::status_id_declined
747
+				? '<br /><span class="small-text">' . $payment->gateway_response() . '</span>'
748
+				: '';
749
+			$html .= '
750 750
 				<tr>
751 751
 					<td>
752 752
 						' . $payment->timestamp() . '
753 753
 					</td>
754 754
 					<td>
755 755
 						' . (
756
-                $payment->payment_method() instanceof EE_Payment_Method
757
-                    ? $payment->payment_method()->name()
758
-                    : __('Unknown', 'event_espresso')
759
-                ) . '
756
+				$payment->payment_method() instanceof EE_Payment_Method
757
+					? $payment->payment_method()->name()
758
+					: __('Unknown', 'event_espresso')
759
+				) . '
760 760
 					</td>
761 761
 					<td class="jst-rght">
762 762
 						' . EEH_Template::format_currency($payment->amount()) . '
@@ -765,82 +765,82 @@  discard block
 block discarded – undo
765 765
 						' . $payment->pretty_status(true) . $payment_declined_msg . '
766 766
 					</td>
767 767
 				</tr>';
768
-            do_action('AHEE__thank_you_page_payment_details_template__after_each_payment', $payment);
769
-        }
770
-        return $html;
771
-    }
772
-
773
-
774
-    /**
775
-     * get_payment_details
776
-     *
777
-     * @param array $payments
778
-     * @return string
779
-     * @throws EE_Error
780
-     * @throws ReflectionException
781
-     */
782
-    public function get_payment_details($payments = array())
783
-    {
784
-        // prepare variables for displaying
785
-        $template_args = array();
786
-        $template_args['transaction'] = $this->_current_txn;
787
-        $template_args['reg_url_link'] = $this->_reg_url_link;
788
-        $template_args['payments'] = array();
789
-        foreach ($payments as $payment) {
790
-            $template_args['payments'][] = $this->get_payment_row_html($payment);
791
-        }
792
-        // create a hacky payment object, but dont save it
793
-        $payment = EE_Payment::new_instance(
794
-            array(
795
-                'TXN_ID'        => $this->_current_txn->ID(),
796
-                'STS_ID'        => EEM_Payment::status_id_pending,
797
-                'PAY_timestamp' => time(),
798
-                'PAY_amount'    => $this->_current_txn->total(),
799
-                'PMD_ID'        => $this->_current_txn->payment_method_ID(),
800
-            )
801
-        );
802
-        $payment_method = $this->_current_txn->payment_method();
803
-        if ($payment_method instanceof EE_Payment_Method && $payment_method->type_obj() instanceof EE_PMT_Base) {
804
-            $template_args['gateway_content'] = $payment_method->type_obj()->payment_overview_content($payment);
805
-        } else {
806
-            $template_args['gateway_content'] = '';
807
-        }
808
-        // link to SPCO payment_options
809
-        $template_args['show_try_pay_again_link'] = $this->_show_try_pay_again_link;
810
-        $template_args['SPCO_payment_options_url'] = $this->_SPCO_payment_options_url;
811
-        // verify template arguments
812
-        EEH_Template_Validator::verify_instanceof($template_args['transaction'], '$transaction', 'EE_Transaction');
813
-        EEH_Template_Validator::verify_isnt_null($template_args['payments'], '$payments');
814
-        EEH_Template_Validator::verify_isnt_null(
815
-            $template_args['show_try_pay_again_link'],
816
-            '$show_try_pay_again_link'
817
-        );
818
-        EEH_Template_Validator::verify_isnt_null($template_args['gateway_content'], '$gateway_content');
819
-        EEH_Template_Validator::verify_isnt_null(
820
-            $template_args['SPCO_payment_options_url'],
821
-            '$SPCO_payment_options_url'
822
-        );
823
-        return EEH_Template::locate_template(
824
-            THANK_YOU_TEMPLATES_PATH . 'thank-you-page-payment-details.template.php',
825
-            $template_args
826
-        );
827
-    }
828
-
829
-
830
-    /**
831
-     * get_payment_details
832
-     *
833
-     * @param array $payments
834
-     * @return string
835
-     * @throws EE_Error
836
-     */
837
-    public function get_new_payments($payments = array())
838
-    {
839
-        $payments_html = '';
840
-        // prepare variables for displaying
841
-        foreach ($payments as $payment) {
842
-            $payments_html .= $this->get_payment_row_html($payment);
843
-        }
844
-        return $payments_html;
845
-    }
768
+			do_action('AHEE__thank_you_page_payment_details_template__after_each_payment', $payment);
769
+		}
770
+		return $html;
771
+	}
772
+
773
+
774
+	/**
775
+	 * get_payment_details
776
+	 *
777
+	 * @param array $payments
778
+	 * @return string
779
+	 * @throws EE_Error
780
+	 * @throws ReflectionException
781
+	 */
782
+	public function get_payment_details($payments = array())
783
+	{
784
+		// prepare variables for displaying
785
+		$template_args = array();
786
+		$template_args['transaction'] = $this->_current_txn;
787
+		$template_args['reg_url_link'] = $this->_reg_url_link;
788
+		$template_args['payments'] = array();
789
+		foreach ($payments as $payment) {
790
+			$template_args['payments'][] = $this->get_payment_row_html($payment);
791
+		}
792
+		// create a hacky payment object, but dont save it
793
+		$payment = EE_Payment::new_instance(
794
+			array(
795
+				'TXN_ID'        => $this->_current_txn->ID(),
796
+				'STS_ID'        => EEM_Payment::status_id_pending,
797
+				'PAY_timestamp' => time(),
798
+				'PAY_amount'    => $this->_current_txn->total(),
799
+				'PMD_ID'        => $this->_current_txn->payment_method_ID(),
800
+			)
801
+		);
802
+		$payment_method = $this->_current_txn->payment_method();
803
+		if ($payment_method instanceof EE_Payment_Method && $payment_method->type_obj() instanceof EE_PMT_Base) {
804
+			$template_args['gateway_content'] = $payment_method->type_obj()->payment_overview_content($payment);
805
+		} else {
806
+			$template_args['gateway_content'] = '';
807
+		}
808
+		// link to SPCO payment_options
809
+		$template_args['show_try_pay_again_link'] = $this->_show_try_pay_again_link;
810
+		$template_args['SPCO_payment_options_url'] = $this->_SPCO_payment_options_url;
811
+		// verify template arguments
812
+		EEH_Template_Validator::verify_instanceof($template_args['transaction'], '$transaction', 'EE_Transaction');
813
+		EEH_Template_Validator::verify_isnt_null($template_args['payments'], '$payments');
814
+		EEH_Template_Validator::verify_isnt_null(
815
+			$template_args['show_try_pay_again_link'],
816
+			'$show_try_pay_again_link'
817
+		);
818
+		EEH_Template_Validator::verify_isnt_null($template_args['gateway_content'], '$gateway_content');
819
+		EEH_Template_Validator::verify_isnt_null(
820
+			$template_args['SPCO_payment_options_url'],
821
+			'$SPCO_payment_options_url'
822
+		);
823
+		return EEH_Template::locate_template(
824
+			THANK_YOU_TEMPLATES_PATH . 'thank-you-page-payment-details.template.php',
825
+			$template_args
826
+		);
827
+	}
828
+
829
+
830
+	/**
831
+	 * get_payment_details
832
+	 *
833
+	 * @param array $payments
834
+	 * @return string
835
+	 * @throws EE_Error
836
+	 */
837
+	public function get_new_payments($payments = array())
838
+	{
839
+		$payments_html = '';
840
+		// prepare variables for displaying
841
+		foreach ($payments as $payment) {
842
+			$payments_html .= $this->get_payment_row_html($payment);
843
+		}
844
+		return $payments_html;
845
+	}
846 846
 }
Please login to merge, or discard this patch.
Spacing   +25 added lines, -25 removed lines patch added patch discarded remove patch
@@ -129,8 +129,8 @@  discard block
 block discarded – undo
129 129
      */
130 130
     public static function set_definitions()
131 131
     {
132
-        define('THANK_YOU_ASSETS_URL', plugin_dir_url(__FILE__) . 'assets/');
133
-        define('THANK_YOU_TEMPLATES_PATH', str_replace('\\', '/', plugin_dir_path(__FILE__)) . 'templates/');
132
+        define('THANK_YOU_ASSETS_URL', plugin_dir_url(__FILE__).'assets/');
133
+        define('THANK_YOU_TEMPLATES_PATH', str_replace('\\', '/', plugin_dir_path(__FILE__)).'templates/');
134 134
     }
135 135
 
136 136
 
@@ -147,7 +147,7 @@  discard block
 block discarded – undo
147 147
             return $this->_current_txn;
148 148
         }
149 149
         $TXN_model = EE_Registry::instance()->load_model('Transaction');
150
-        if (! $TXN_model instanceof EEM_Transaction) {
150
+        if ( ! $TXN_model instanceof EEM_Transaction) {
151 151
             EE_Error::add_error(
152 152
                 __('The transaction model could not be established.', 'event_espresso'),
153 153
                 __FILE__,
@@ -185,7 +185,7 @@  discard block
 block discarded – undo
185 185
      */
186 186
     public function get_txn_payments($since = 0)
187 187
     {
188
-        if (! $this->get_txn()) {
188
+        if ( ! $this->get_txn()) {
189 189
             return [];
190 190
         }
191 191
         $args = array('order_by' => array('PAY_timestamp' => 'ASC'));
@@ -215,7 +215,7 @@  discard block
 block discarded – undo
215 215
      */
216 216
     private function _get_reg_url_link()
217 217
     {
218
-        if ($this->_reg_url_link){
218
+        if ($this->_reg_url_link) {
219 219
             return;
220 220
         }
221 221
         // check for reg_url_link
@@ -327,7 +327,7 @@  discard block
 block discarded – undo
327 327
     {
328 328
         wp_register_script(
329 329
             'thank_you_page',
330
-            THANK_YOU_ASSETS_URL . 'thank_you_page.js',
330
+            THANK_YOU_ASSETS_URL.'thank_you_page.js',
331 331
             array('espresso_core', 'heartbeat'),
332 332
             EVENT_ESPRESSO_VERSION,
333 333
             true
@@ -347,9 +347,9 @@  discard block
 block discarded – undo
347 347
     public function init()
348 348
     {
349 349
         $this->_get_reg_url_link();
350
-        if (! $this->get_txn()) {
350
+        if ( ! $this->get_txn()) {
351 351
             echo EEH_HTML::div(
352
-                EEH_HTML::h4(__('We\'re sorry...', 'event_espresso')) .
352
+                EEH_HTML::h4(__('We\'re sorry...', 'event_espresso')).
353 353
                 sprintf(
354 354
                     __(
355 355
                         'This is a system page for displaying transaction information after a purchase.%1$sYou are most likely seeing this notice because you have navigated to this page%1$sthrough some means other than completing a transaction.%1$sSorry for the disappointment, but you will most likely find nothing of interest here.%1$s%1$s',
@@ -438,12 +438,12 @@  discard block
 block discarded – undo
438 438
     public function thank_you_page_results()
439 439
     {
440 440
         $this->init();
441
-        if (! $this->_current_txn instanceof EE_Transaction) {
441
+        if ( ! $this->_current_txn instanceof EE_Transaction) {
442 442
             return EE_Error::get_notices();
443 443
         }
444 444
         // link to receipt
445 445
         $template_args['TXN_receipt_url'] = $this->_current_txn->receipt_url();
446
-        if (! empty($template_args['TXN_receipt_url'])) {
446
+        if ( ! empty($template_args['TXN_receipt_url'])) {
447 447
             $template_args['order_conf_desc'] = __(
448 448
                 '%1$sCongratulations%2$sYour registration has been successfully processed.%3$sCheck your email for your registration confirmation or click the button below to view / download / print a full description of your purchases and registration information.',
449 449
                 'event_espresso'
@@ -461,7 +461,7 @@  discard block
 block discarded – undo
461 461
             add_action('AHEE__thank_you_page_overview_template__content', array($this, 'get_ajax_content'));
462 462
         }
463 463
         return EEH_Template::locate_template(
464
-            THANK_YOU_TEMPLATES_PATH . 'thank-you-page-overview.template.php',
464
+            THANK_YOU_TEMPLATES_PATH.'thank-you-page-overview.template.php',
465 465
             $template_args
466 466
         );
467 467
     }
@@ -511,7 +511,7 @@  discard block
 block discarded – undo
511 511
             '$SPCO_attendee_information_url'
512 512
         );
513 513
         echo EEH_Template::locate_template(
514
-            THANK_YOU_TEMPLATES_PATH . 'thank-you-page-registration-details.template.php',
514
+            THANK_YOU_TEMPLATES_PATH.'thank-you-page-registration-details.template.php',
515 515
             $template_args
516 516
         );
517 517
     }
@@ -583,7 +583,7 @@  discard block
 block discarded – undo
583 583
      */
584 584
     public function get_ajax_content()
585 585
     {
586
-        if (! $this->get_txn()) {
586
+        if ( ! $this->get_txn()) {
587 587
             return;
588 588
         }
589 589
         // first determine which event(s) require pre-approval or not
@@ -594,9 +594,9 @@  discard block
 block discarded – undo
594 594
                 $event = $registration->event();
595 595
                 if ($event instanceof EE_Event) {
596 596
                     if ($registration->is_not_approved() && $registration->event() instanceof EE_Event) {
597
-                        $events_requiring_pre_approval[ $event->ID() ] = $event;
597
+                        $events_requiring_pre_approval[$event->ID()] = $event;
598 598
                     } else {
599
-                        $events[ $event->ID() ] = $event;
599
+                        $events[$event->ID()] = $event;
600 600
                     }
601 601
                 }
602 602
             }
@@ -614,7 +614,7 @@  discard block
 block discarded – undo
614 614
      */
615 615
     public function display_details_for_events($events = array())
616 616
     {
617
-        if (! empty($events)) {
617
+        if ( ! empty($events)) {
618 618
             ?>
619 619
             <div id="espresso-thank-you-page-ajax-content-dv">
620 620
                 <div id="espresso-thank-you-page-ajax-transaction-dv"></div>
@@ -627,7 +627,7 @@  discard block
 block discarded – undo
627 627
                                 'event_espresso'
628 628
                             ); ?></span>
629 629
                     </div>
630
-                    <?php if (! $this->_is_offline_payment_method && ! $this->_payments_closed) : ?>
630
+                    <?php if ( ! $this->_is_offline_payment_method && ! $this->_payments_closed) : ?>
631 631
                         <p id="ee-ajax-loading-pg" class="highlight-bg small-text clear">
632 632
                             <?php echo apply_filters(
633 633
                                 'EED_Thank_You_Page__get_ajax_content__waiting_for_IPN_msg',
@@ -660,7 +660,7 @@  discard block
 block discarded – undo
660 660
      */
661 661
     public function display_details_for_events_requiring_pre_approval($events = array())
662 662
     {
663
-        if (! empty($events)) {
663
+        if ( ! empty($events)) {
664 664
             ?>
665 665
             <div id="espresso-thank-you-page-not-approved-message-dv">
666 666
                 <h4 class="orange-text"><?php _e('Important Notice:', 'event_espresso'); ?></h4>
@@ -717,7 +717,7 @@  discard block
 block discarded – undo
717 717
             '$SPCO_payment_options_url'
718 718
         );
719 719
         return EEH_Template::locate_template(
720
-            THANK_YOU_TEMPLATES_PATH . 'thank-you-page-transaction-details.template.php',
720
+            THANK_YOU_TEMPLATES_PATH.'thank-you-page-transaction-details.template.php',
721 721
             $template_args
722 722
         );
723 723
     }
@@ -744,25 +744,25 @@  discard block
 block discarded – undo
744 744
                 $payment->set_status(EEM_Payment::status_id_pending);
745 745
             }
746 746
             $payment_declined_msg = $payment->STS_ID() === EEM_Payment::status_id_declined
747
-                ? '<br /><span class="small-text">' . $payment->gateway_response() . '</span>'
747
+                ? '<br /><span class="small-text">'.$payment->gateway_response().'</span>'
748 748
                 : '';
749 749
             $html .= '
750 750
 				<tr>
751 751
 					<td>
752
-						' . $payment->timestamp() . '
752
+						' . $payment->timestamp().'
753 753
 					</td>
754 754
 					<td>
755 755
 						' . (
756 756
                 $payment->payment_method() instanceof EE_Payment_Method
757 757
                     ? $payment->payment_method()->name()
758 758
                     : __('Unknown', 'event_espresso')
759
-                ) . '
759
+                ).'
760 760
 					</td>
761 761
 					<td class="jst-rght">
762
-						' . EEH_Template::format_currency($payment->amount()) . '
762
+						' . EEH_Template::format_currency($payment->amount()).'
763 763
 					</td>
764 764
 					<td class="jst-rght" style="line-height:1;">
765
-						' . $payment->pretty_status(true) . $payment_declined_msg . '
765
+						' . $payment->pretty_status(true).$payment_declined_msg.'
766 766
 					</td>
767 767
 				</tr>';
768 768
             do_action('AHEE__thank_you_page_payment_details_template__after_each_payment', $payment);
@@ -821,7 +821,7 @@  discard block
 block discarded – undo
821 821
             '$SPCO_payment_options_url'
822 822
         );
823 823
         return EEH_Template::locate_template(
824
-            THANK_YOU_TEMPLATES_PATH . 'thank-you-page-payment-details.template.php',
824
+            THANK_YOU_TEMPLATES_PATH.'thank-you-page-payment-details.template.php',
825 825
             $template_args
826 826
         );
827 827
     }
Please login to merge, or discard this patch.
modules/certificate/EED_Certificate.module.php 1 patch
Indentation   +81 added lines, -81 removed lines patch added patch discarded remove patch
@@ -11,98 +11,98 @@
 block discarded – undo
11 11
 {
12 12
 
13 13
 
14
-    /**
15
-     * @return EED_Module|EED_Certificate
16
-     * @throws EE_Error
17
-     * @throws ReflectionException
18
-     */
19
-    public static function instance()
20
-    {
21
-        return parent::get_instance(__CLASS__);
22
-    }
14
+	/**
15
+	 * @return EED_Module|EED_Certificate
16
+	 * @throws EE_Error
17
+	 * @throws ReflectionException
18
+	 */
19
+	public static function instance()
20
+	{
21
+		return parent::get_instance(__CLASS__);
22
+	}
23 23
 
24 24
 
25
-    /**
26
-     *    set_hooks - for hooking into EE Core, other modules, etc
27
-     *
28
-     * @access    public
29
-     * @return    void
30
-     */
31
-    public static function set_hooks()
32
-    {
33
-    }
25
+	/**
26
+	 *    set_hooks - for hooking into EE Core, other modules, etc
27
+	 *
28
+	 * @access    public
29
+	 * @return    void
30
+	 */
31
+	public static function set_hooks()
32
+	{
33
+	}
34 34
 
35
-    /**
36
-     *    set_hooks_admin - for hooking into EE Admin Core, other modules, etc
37
-     *
38
-     * @access    public
39
-     * @return    void
40
-     */
41
-    public static function set_hooks_admin()
42
-    {
43
-    }
35
+	/**
36
+	 *    set_hooks_admin - for hooking into EE Admin Core, other modules, etc
37
+	 *
38
+	 * @access    public
39
+	 * @return    void
40
+	 */
41
+	public static function set_hooks_admin()
42
+	{
43
+	}
44 44
 
45 45
 
46
-    /**
47
-     *    run - initial module setup
48
-     *
49
-     * @access    public
50
-     * @return    void
51
-     */
52
-    public function run($WP)
53
-    {
54
-    }
46
+	/**
47
+	 *    run - initial module setup
48
+	 *
49
+	 * @access    public
50
+	 * @return    void
51
+	 */
52
+	public function run($WP)
53
+	{
54
+	}
55 55
 
56 56
 
57
-    /**
58
-     *    certificate_launch
59
-     *
60
-     * @access    public
61
-     * @return    void
62
-     */
63
-    public function certificate_launch()
64
-    {
65
-        $request = self::getRequest();
66
-        if ($request->requestParamIsSet('id') && $request->requestParamIsSet('r_id')) {
67
-            echo espresso_certificate_launch(
68
-                $request->getRequestParam('id'),
69
-                $request->getRequestParam('r_id')
70
-            );
71
-        }
72
-    }
57
+	/**
58
+	 *    certificate_launch
59
+	 *
60
+	 * @access    public
61
+	 * @return    void
62
+	 */
63
+	public function certificate_launch()
64
+	{
65
+		$request = self::getRequest();
66
+		if ($request->requestParamIsSet('id') && $request->requestParamIsSet('r_id')) {
67
+			echo espresso_certificate_launch(
68
+				$request->getRequestParam('id'),
69
+				$request->getRequestParam('r_id')
70
+			);
71
+		}
72
+	}
73 73
 
74 74
 
75
-    /**
76
-     *    wp_loaded
77
-     *
78
-     * @access    public
79
-     * @return    void
80
-     */
81
-    public function wp_loaded()
82
-    {
83
-    }
75
+	/**
76
+	 *    wp_loaded
77
+	 *
78
+	 * @access    public
79
+	 * @return    void
80
+	 */
81
+	public function wp_loaded()
82
+	{
83
+	}
84 84
 
85 85
 
86
-    /**
87
-     *    wp
88
-     *
89
-     * @access    public
90
-     * @return    void
91
-     */
92
-    public function wp()
93
-    {
94
-    }
86
+	/**
87
+	 *    wp
88
+	 *
89
+	 * @access    public
90
+	 * @return    void
91
+	 */
92
+	public function wp()
93
+	{
94
+	}
95 95
 
96 96
 
97
-    /**
98
-     *    the_content
99
-     *
100
-     * @access    public
101
-     * @return    string
102
-     */
103
-    public function the_content($content)
104
-    {
105
-        $content .= $this->ouput;
106
-        return $content;
107
-    }
97
+	/**
98
+	 *    the_content
99
+	 *
100
+	 * @access    public
101
+	 * @return    string
102
+	 */
103
+	public function the_content($content)
104
+	{
105
+		$content .= $this->ouput;
106
+		return $content;
107
+	}
108 108
 }
Please login to merge, or discard this patch.
modules/invoice/EED_Invoice.module.php 1 patch
Indentation   +77 added lines, -77 removed lines patch added patch discarded remove patch
@@ -11,91 +11,91 @@
 block discarded – undo
11 11
 {
12 12
 
13 13
 
14
-    /**
15
-     * @return EED_Invoice|EED_Module
16
-     * @throws EE_Error
17
-     * @throws ReflectionException
18
-     */
19
-    public static function instance()
20
-    {
21
-        return parent::get_instance(__CLASS__);
22
-    }
14
+	/**
15
+	 * @return EED_Invoice|EED_Module
16
+	 * @throws EE_Error
17
+	 * @throws ReflectionException
18
+	 */
19
+	public static function instance()
20
+	{
21
+		return parent::get_instance(__CLASS__);
22
+	}
23 23
 
24 24
 
25
-    /**
26
-     *    set_hooks - for hooking into EE Core, other modules, etc
27
-     *
28
-     * @access    public
29
-     * @return    void
30
-     */
31
-    public static function set_hooks()
32
-    {
33
-        EE_Config::register_route('download_invoice', 'EED_Invoice', 'download_invoice');
34
-        EE_Config::register_route('launch_invoice', 'EED_Invoice', 'launch_invoice');
35
-    }
25
+	/**
26
+	 *    set_hooks - for hooking into EE Core, other modules, etc
27
+	 *
28
+	 * @access    public
29
+	 * @return    void
30
+	 */
31
+	public static function set_hooks()
32
+	{
33
+		EE_Config::register_route('download_invoice', 'EED_Invoice', 'download_invoice');
34
+		EE_Config::register_route('launch_invoice', 'EED_Invoice', 'launch_invoice');
35
+	}
36 36
 
37 37
 
38
-    /**
39
-     *    set_hooks_admin - for hooking into EE Admin Core, other modules, etc
40
-     *
41
-     * @access    public
42
-     * @return    void
43
-     */
44
-    public static function set_hooks_admin()
45
-    {
46
-    }
38
+	/**
39
+	 *    set_hooks_admin - for hooking into EE Admin Core, other modules, etc
40
+	 *
41
+	 * @access    public
42
+	 * @return    void
43
+	 */
44
+	public static function set_hooks_admin()
45
+	{
46
+	}
47 47
 
48 48
 
49
-    /**
50
-     *    run - initial module setup
51
-     *
52
-     * @access    public
53
-     * @return    void
54
-     */
55
-    public function run($WP)
56
-    {
57
-        if (is_readable(EE_MODULES . 'gateways/Invoice/lib/Invoice.class.php')) {
58
-            require_once(EE_MODULES . 'gateways/Invoice/lib/Invoice.class.php');
59
-        } else {
60
-            $msg = __('The Invoice.class.php file could not be loaded.', 'event_espresso');
61
-            EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
62
-        }
63
-    }
49
+	/**
50
+	 *    run - initial module setup
51
+	 *
52
+	 * @access    public
53
+	 * @return    void
54
+	 */
55
+	public function run($WP)
56
+	{
57
+		if (is_readable(EE_MODULES . 'gateways/Invoice/lib/Invoice.class.php')) {
58
+			require_once(EE_MODULES . 'gateways/Invoice/lib/Invoice.class.php');
59
+		} else {
60
+			$msg = __('The Invoice.class.php file could not be loaded.', 'event_espresso');
61
+			EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
62
+		}
63
+	}
64 64
 
65 65
 
66
-    /**
67
-     *    invoice_launch
68
-     *
69
-     * @access    public
70
-     * @return    void
71
-     */
72
-    public function launch_invoice()
73
-    {
74
-        $this->run(null);
75
-        $request = self::getRequest();
76
-        if ($request->requestParamIsSet('id')) {
77
-            $id = $request->getRequestParam('id', '', 'key');
78
-            $invoice = new Invoice($id);
79
-            $invoice->send_invoice();
80
-        }
81
-    }
66
+	/**
67
+	 *    invoice_launch
68
+	 *
69
+	 * @access    public
70
+	 * @return    void
71
+	 */
72
+	public function launch_invoice()
73
+	{
74
+		$this->run(null);
75
+		$request = self::getRequest();
76
+		if ($request->requestParamIsSet('id')) {
77
+			$id = $request->getRequestParam('id', '', 'key');
78
+			$invoice = new Invoice($id);
79
+			$invoice->send_invoice();
80
+		}
81
+	}
82 82
 
83 83
 
84
-    /**
85
-     *    download_invoice
86
-     *
87
-     * @access    public
88
-     * @return    void
89
-     */
90
-    public function download_invoice()
91
-    {
92
-        $this->run(null);
93
-        $request = self::getRequest();
94
-        if ($request->requestParamIsSet('id')) {
95
-            $id = $request->getRequestParam('id', '', 'key');
96
-            $invoice = new Invoice($_REQUEST['id']);
97
-            // send invoice but force download
98
-            $invoice->send_invoice(true);
99
-        }
100
-    }
84
+	/**
85
+	 *    download_invoice
86
+	 *
87
+	 * @access    public
88
+	 * @return    void
89
+	 */
90
+	public function download_invoice()
91
+	{
92
+		$this->run(null);
93
+		$request = self::getRequest();
94
+		if ($request->requestParamIsSet('id')) {
95
+			$id = $request->getRequestParam('id', '', 'key');
96
+			$invoice = new Invoice($_REQUEST['id']);
97
+			// send invoice but force download
98
+			$invoice->send_invoice(true);
99
+		}
100
+	}
101 101
 }
Please login to merge, or discard this patch.
modules/feeds/EED_Feeds.module.php 2 patches
Indentation   +214 added lines, -214 removed lines patch added patch discarded remove patch
@@ -12,218 +12,218 @@
 block discarded – undo
12 12
 {
13 13
 
14 14
 
15
-    /**
16
-     * @return EED_Feeds
17
-     */
18
-    public static function instance()
19
-    {
20
-        return parent::get_instance(__CLASS__);
21
-    }
22
-
23
-
24
-    /**
25
-     *    set_hooks - for hooking into EE Core, other modules, etc
26
-     *
27
-     * @access    public
28
-     * @return    void
29
-     */
30
-    public static function set_hooks()
31
-    {
32
-        add_action('parse_request', array('EED_Feeds', 'parse_request'), 10);
33
-        add_filter('default_feed', array('EED_Feeds', 'default_feed'), 10, 1);
34
-        add_filter('comment_feed_join', array('EED_Feeds', 'comment_feed_join'), 10, 2);
35
-        add_filter('comment_feed_where', array('EED_Feeds', 'comment_feed_where'), 10, 2);
36
-    }
37
-
38
-    /**
39
-     *    set_hooks_admin - for hooking into EE Admin Core, other modules, etc
40
-     *
41
-     * @access    public
42
-     * @return    void
43
-     */
44
-    public static function set_hooks_admin()
45
-    {
46
-    }
47
-
48
-
49
-    /**
50
-     *    run - initial module setup
51
-     *
52
-     * @access    public
53
-     * @return    void
54
-     */
55
-    public function run($WP)
56
-    {
57
-    }
58
-
59
-
60
-    /**
61
-     *    default_feed
62
-     *
63
-     * @access    public
64
-     * @param    type    rss2, atom, rss, rdf, rssjs
65
-     * @return    string
66
-     */
67
-    public static function default_feed($type = 'rss2')
68
-    {
69
-        // rss2, atom, rss, rdf, rssjs
70
-        $type = 'rss2';
71
-        return $type;
72
-    }
73
-
74
-
75
-    /**
76
-     *    parse_request
77
-     *
78
-     * @access    public
79
-     * @return    void
80
-     */
81
-    public static function parse_request()
82
-    {
83
-        $request = self::getRequest();
84
-        if ($request->requestParamIsSet('post_type')) {
85
-            // define path to templates
86
-            define('RSS_FEEDS_TEMPLATES_PATH', str_replace('\\', '/', plugin_dir_path(__FILE__)) . 'templates/');
87
-            // what kinda post_type are we dealing with ?
88
-            switch ($request->getRequestParam('post_type')) {
89
-                case 'espresso_events':
90
-                    // for rss2, atom, rss, rdf
91
-                    add_filter('the_excerpt_rss', array('EED_Feeds', 'the_event_feed'), 10, 1);
92
-                    add_filter('the_content_feed', array('EED_Feeds', 'the_event_feed'), 10, 1);
93
-                    // for json ( also uses the above filter )
94
-                    add_filter('rssjs_feed_item', array('EED_Feeds', 'the_event_rssjs_feed'), 10, 1);
95
-                    break;
96
-                case 'espresso_venues':
97
-                    // for rss2, atom, rss, rdf
98
-                    add_filter('the_excerpt_rss', array('EED_Feeds', 'the_venue_feed'), 10, 1);
99
-                    add_filter('the_content_feed', array('EED_Feeds', 'the_venue_feed'), 10, 1);
100
-                    // for json ( also uses the above filter )
101
-                    add_filter('rssjs_feed_item', array('EED_Feeds', 'the_venue_rssjs_feed'), 10, 1);
102
-                    break;
103
-            }
104
-        }
105
-    }
106
-
107
-
108
-    /**
109
-     *    comment_feed_join - EVEN THOUGH... our espresso_attendees custom post type is set to NOT PUBLIC
110
-     *    WordPress thought it would be a good idea to display the comments for them in the RSS feeds... we think NOT
111
-     *    so this little snippet of SQL taps into the comment feed query and removes comments for the
112
-     *    espresso_attendees post_type
113
-     *
114
-     * @access    public
115
-     * @param    string $SQL the JOIN clause for the comment feed query
116
-     * @return    void
117
-     */
118
-    public static function comment_feed_join($SQL)
119
-    {
120
-        global $wpdb;
121
-        // check for wp_posts table in JOIN clause
122
-        if (strpos($SQL, $wpdb->posts) !== false) {
123
-            add_filter('EED_Feeds__comment_feed_where__espresso_attendees', '__return_true');
124
-        }
125
-        return $SQL;
126
-    }
127
-
128
-
129
-    /**
130
-     *    comment_feed_where - EVEN THOUGH... our espresso_attendees custom post type is set to NOT PUBLIC
131
-     *    WordPress thought it would be a good idea to display the comments for them in the RSS feeds... we think NOT
132
-     *    so this little snippet of SQL taps into the comment feed query and removes comments for the
133
-     *    espresso_attendees post_type
134
-     *
135
-     * @access    public
136
-     * @param    string $SQL the WHERE clause for the comment feed query
137
-     * @return    void
138
-     */
139
-    public static function comment_feed_where($SQL)
140
-    {
141
-        global $wp_query, $wpdb;
142
-        if ($wp_query->is_comment_feed && apply_filters('EED_Feeds__comment_feed_where__espresso_attendees', false)) {
143
-            $SQL .= " AND $wpdb->posts.post_type != 'espresso_attendees'";
144
-        }
145
-        return $SQL;
146
-    }
147
-
148
-
149
-    /**
150
-     *    the_event_feed
151
-     *
152
-     * @access    public
153
-     * @param    string $content
154
-     * @return    void
155
-     */
156
-    public static function the_event_feed($content)
157
-    {
158
-        if (is_feed() && is_readable(RSS_FEEDS_TEMPLATES_PATH . 'espresso_events_feed.template.php')) {
159
-            global $post;
160
-            $template_args = array(
161
-                'EVT_ID'            => $post->ID,
162
-                'event_description' => get_option('rss_use_excerpt') ? $post->post_excerpt : $post->post_content,
163
-            );
164
-            $content = EEH_Template::display_template(
165
-                RSS_FEEDS_TEMPLATES_PATH . 'espresso_events_feed.template.php',
166
-                $template_args,
167
-                true
168
-            );
169
-        }
170
-        return $content;
171
-    }
172
-
173
-
174
-    /**
175
-     *    the_event_rssjs_feed
176
-     *
177
-     * @access    public
178
-     * @param    object $item
179
-     * @return    void
180
-     */
181
-    public static function the_event_rssjs_feed($item)
182
-    {
183
-        if (is_feed() && isset($item->description)) {
184
-            $item->description = EED_Feeds::the_event_feed($item->description);
185
-        }
186
-        return $item;
187
-    }
188
-
189
-
190
-    /**
191
-     *    the_venue_feed
192
-     *
193
-     * @access    public
194
-     * @param    string $content
195
-     * @return    void
196
-     */
197
-    public static function the_venue_feed($content)
198
-    {
199
-        if (is_feed() && is_readable(RSS_FEEDS_TEMPLATES_PATH . 'espresso_venues_feed.template.php')) {
200
-            global $post;
201
-            $template_args = array(
202
-                'VNU_ID'            => $post->ID,
203
-                'venue_description' => get_option('rss_use_excerpt') ? $post->post_excerpt : $post->post_content,
204
-            );
205
-            $content = EEH_Template::display_template(
206
-                RSS_FEEDS_TEMPLATES_PATH . 'espresso_venues_feed.template.php',
207
-                $template_args,
208
-                true
209
-            );
210
-        }
211
-        return $content;
212
-    }
213
-
214
-
215
-    /**
216
-     *    the_venue_rssjs_feed
217
-     *
218
-     * @access    public
219
-     * @param    object $item
220
-     * @return    void
221
-     */
222
-    public static function the_venue_rssjs_feed($item)
223
-    {
224
-        if (is_feed() && isset($item->description)) {
225
-            $item->description = EED_Feeds::the_venue_feed($item->description);
226
-        }
227
-        return $item;
228
-    }
15
+	/**
16
+	 * @return EED_Feeds
17
+	 */
18
+	public static function instance()
19
+	{
20
+		return parent::get_instance(__CLASS__);
21
+	}
22
+
23
+
24
+	/**
25
+	 *    set_hooks - for hooking into EE Core, other modules, etc
26
+	 *
27
+	 * @access    public
28
+	 * @return    void
29
+	 */
30
+	public static function set_hooks()
31
+	{
32
+		add_action('parse_request', array('EED_Feeds', 'parse_request'), 10);
33
+		add_filter('default_feed', array('EED_Feeds', 'default_feed'), 10, 1);
34
+		add_filter('comment_feed_join', array('EED_Feeds', 'comment_feed_join'), 10, 2);
35
+		add_filter('comment_feed_where', array('EED_Feeds', 'comment_feed_where'), 10, 2);
36
+	}
37
+
38
+	/**
39
+	 *    set_hooks_admin - for hooking into EE Admin Core, other modules, etc
40
+	 *
41
+	 * @access    public
42
+	 * @return    void
43
+	 */
44
+	public static function set_hooks_admin()
45
+	{
46
+	}
47
+
48
+
49
+	/**
50
+	 *    run - initial module setup
51
+	 *
52
+	 * @access    public
53
+	 * @return    void
54
+	 */
55
+	public function run($WP)
56
+	{
57
+	}
58
+
59
+
60
+	/**
61
+	 *    default_feed
62
+	 *
63
+	 * @access    public
64
+	 * @param    type    rss2, atom, rss, rdf, rssjs
65
+	 * @return    string
66
+	 */
67
+	public static function default_feed($type = 'rss2')
68
+	{
69
+		// rss2, atom, rss, rdf, rssjs
70
+		$type = 'rss2';
71
+		return $type;
72
+	}
73
+
74
+
75
+	/**
76
+	 *    parse_request
77
+	 *
78
+	 * @access    public
79
+	 * @return    void
80
+	 */
81
+	public static function parse_request()
82
+	{
83
+		$request = self::getRequest();
84
+		if ($request->requestParamIsSet('post_type')) {
85
+			// define path to templates
86
+			define('RSS_FEEDS_TEMPLATES_PATH', str_replace('\\', '/', plugin_dir_path(__FILE__)) . 'templates/');
87
+			// what kinda post_type are we dealing with ?
88
+			switch ($request->getRequestParam('post_type')) {
89
+				case 'espresso_events':
90
+					// for rss2, atom, rss, rdf
91
+					add_filter('the_excerpt_rss', array('EED_Feeds', 'the_event_feed'), 10, 1);
92
+					add_filter('the_content_feed', array('EED_Feeds', 'the_event_feed'), 10, 1);
93
+					// for json ( also uses the above filter )
94
+					add_filter('rssjs_feed_item', array('EED_Feeds', 'the_event_rssjs_feed'), 10, 1);
95
+					break;
96
+				case 'espresso_venues':
97
+					// for rss2, atom, rss, rdf
98
+					add_filter('the_excerpt_rss', array('EED_Feeds', 'the_venue_feed'), 10, 1);
99
+					add_filter('the_content_feed', array('EED_Feeds', 'the_venue_feed'), 10, 1);
100
+					// for json ( also uses the above filter )
101
+					add_filter('rssjs_feed_item', array('EED_Feeds', 'the_venue_rssjs_feed'), 10, 1);
102
+					break;
103
+			}
104
+		}
105
+	}
106
+
107
+
108
+	/**
109
+	 *    comment_feed_join - EVEN THOUGH... our espresso_attendees custom post type is set to NOT PUBLIC
110
+	 *    WordPress thought it would be a good idea to display the comments for them in the RSS feeds... we think NOT
111
+	 *    so this little snippet of SQL taps into the comment feed query and removes comments for the
112
+	 *    espresso_attendees post_type
113
+	 *
114
+	 * @access    public
115
+	 * @param    string $SQL the JOIN clause for the comment feed query
116
+	 * @return    void
117
+	 */
118
+	public static function comment_feed_join($SQL)
119
+	{
120
+		global $wpdb;
121
+		// check for wp_posts table in JOIN clause
122
+		if (strpos($SQL, $wpdb->posts) !== false) {
123
+			add_filter('EED_Feeds__comment_feed_where__espresso_attendees', '__return_true');
124
+		}
125
+		return $SQL;
126
+	}
127
+
128
+
129
+	/**
130
+	 *    comment_feed_where - EVEN THOUGH... our espresso_attendees custom post type is set to NOT PUBLIC
131
+	 *    WordPress thought it would be a good idea to display the comments for them in the RSS feeds... we think NOT
132
+	 *    so this little snippet of SQL taps into the comment feed query and removes comments for the
133
+	 *    espresso_attendees post_type
134
+	 *
135
+	 * @access    public
136
+	 * @param    string $SQL the WHERE clause for the comment feed query
137
+	 * @return    void
138
+	 */
139
+	public static function comment_feed_where($SQL)
140
+	{
141
+		global $wp_query, $wpdb;
142
+		if ($wp_query->is_comment_feed && apply_filters('EED_Feeds__comment_feed_where__espresso_attendees', false)) {
143
+			$SQL .= " AND $wpdb->posts.post_type != 'espresso_attendees'";
144
+		}
145
+		return $SQL;
146
+	}
147
+
148
+
149
+	/**
150
+	 *    the_event_feed
151
+	 *
152
+	 * @access    public
153
+	 * @param    string $content
154
+	 * @return    void
155
+	 */
156
+	public static function the_event_feed($content)
157
+	{
158
+		if (is_feed() && is_readable(RSS_FEEDS_TEMPLATES_PATH . 'espresso_events_feed.template.php')) {
159
+			global $post;
160
+			$template_args = array(
161
+				'EVT_ID'            => $post->ID,
162
+				'event_description' => get_option('rss_use_excerpt') ? $post->post_excerpt : $post->post_content,
163
+			);
164
+			$content = EEH_Template::display_template(
165
+				RSS_FEEDS_TEMPLATES_PATH . 'espresso_events_feed.template.php',
166
+				$template_args,
167
+				true
168
+			);
169
+		}
170
+		return $content;
171
+	}
172
+
173
+
174
+	/**
175
+	 *    the_event_rssjs_feed
176
+	 *
177
+	 * @access    public
178
+	 * @param    object $item
179
+	 * @return    void
180
+	 */
181
+	public static function the_event_rssjs_feed($item)
182
+	{
183
+		if (is_feed() && isset($item->description)) {
184
+			$item->description = EED_Feeds::the_event_feed($item->description);
185
+		}
186
+		return $item;
187
+	}
188
+
189
+
190
+	/**
191
+	 *    the_venue_feed
192
+	 *
193
+	 * @access    public
194
+	 * @param    string $content
195
+	 * @return    void
196
+	 */
197
+	public static function the_venue_feed($content)
198
+	{
199
+		if (is_feed() && is_readable(RSS_FEEDS_TEMPLATES_PATH . 'espresso_venues_feed.template.php')) {
200
+			global $post;
201
+			$template_args = array(
202
+				'VNU_ID'            => $post->ID,
203
+				'venue_description' => get_option('rss_use_excerpt') ? $post->post_excerpt : $post->post_content,
204
+			);
205
+			$content = EEH_Template::display_template(
206
+				RSS_FEEDS_TEMPLATES_PATH . 'espresso_venues_feed.template.php',
207
+				$template_args,
208
+				true
209
+			);
210
+		}
211
+		return $content;
212
+	}
213
+
214
+
215
+	/**
216
+	 *    the_venue_rssjs_feed
217
+	 *
218
+	 * @access    public
219
+	 * @param    object $item
220
+	 * @return    void
221
+	 */
222
+	public static function the_venue_rssjs_feed($item)
223
+	{
224
+		if (is_feed() && isset($item->description)) {
225
+			$item->description = EED_Feeds::the_venue_feed($item->description);
226
+		}
227
+		return $item;
228
+	}
229 229
 }
Please login to merge, or discard this patch.
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -83,7 +83,7 @@  discard block
 block discarded – undo
83 83
         $request = self::getRequest();
84 84
         if ($request->requestParamIsSet('post_type')) {
85 85
             // define path to templates
86
-            define('RSS_FEEDS_TEMPLATES_PATH', str_replace('\\', '/', plugin_dir_path(__FILE__)) . 'templates/');
86
+            define('RSS_FEEDS_TEMPLATES_PATH', str_replace('\\', '/', plugin_dir_path(__FILE__)).'templates/');
87 87
             // what kinda post_type are we dealing with ?
88 88
             switch ($request->getRequestParam('post_type')) {
89 89
                 case 'espresso_events':
@@ -155,14 +155,14 @@  discard block
 block discarded – undo
155 155
      */
156 156
     public static function the_event_feed($content)
157 157
     {
158
-        if (is_feed() && is_readable(RSS_FEEDS_TEMPLATES_PATH . 'espresso_events_feed.template.php')) {
158
+        if (is_feed() && is_readable(RSS_FEEDS_TEMPLATES_PATH.'espresso_events_feed.template.php')) {
159 159
             global $post;
160 160
             $template_args = array(
161 161
                 'EVT_ID'            => $post->ID,
162 162
                 'event_description' => get_option('rss_use_excerpt') ? $post->post_excerpt : $post->post_content,
163 163
             );
164 164
             $content = EEH_Template::display_template(
165
-                RSS_FEEDS_TEMPLATES_PATH . 'espresso_events_feed.template.php',
165
+                RSS_FEEDS_TEMPLATES_PATH.'espresso_events_feed.template.php',
166 166
                 $template_args,
167 167
                 true
168 168
             );
@@ -196,14 +196,14 @@  discard block
 block discarded – undo
196 196
      */
197 197
     public static function the_venue_feed($content)
198 198
     {
199
-        if (is_feed() && is_readable(RSS_FEEDS_TEMPLATES_PATH . 'espresso_venues_feed.template.php')) {
199
+        if (is_feed() && is_readable(RSS_FEEDS_TEMPLATES_PATH.'espresso_venues_feed.template.php')) {
200 200
             global $post;
201 201
             $template_args = array(
202 202
                 'VNU_ID'            => $post->ID,
203 203
                 'venue_description' => get_option('rss_use_excerpt') ? $post->post_excerpt : $post->post_content,
204 204
             );
205 205
             $content = EEH_Template::display_template(
206
-                RSS_FEEDS_TEMPLATES_PATH . 'espresso_venues_feed.template.php',
206
+                RSS_FEEDS_TEMPLATES_PATH.'espresso_venues_feed.template.php',
207 207
                 $template_args,
208 208
                 true
209 209
             );
Please login to merge, or discard this patch.
modules/single_page_checkout/inc/EE_Checkout.class.php 1 patch
Indentation   +1426 added lines, -1426 removed lines patch added patch discarded remove patch
@@ -15,1430 +15,1430 @@
 block discarded – undo
15 15
 class EE_Checkout
16 16
 {
17 17
 
18
-    /**
19
-     *    whether current request originated from the EE admin
20
-     *
21
-     * @type bool
22
-     */
23
-    public $admin_request = false;
24
-
25
-    /**
26
-     * whether returning to edit attendee information or to retry a payment
27
-     *
28
-     * @type bool
29
-     */
30
-    public $revisit = false;
31
-
32
-    /**
33
-     * whether the primary registrant is returning to edit attendee information or to retry a payment
34
-     *
35
-     * @type bool
36
-     */
37
-    public $primary_revisit = false;
38
-
39
-    /**
40
-     * is registration allowed to progress or halted for some reason such as failing to pass recaptcha?
41
-     *
42
-     * @type bool
43
-     */
44
-    public $continue_reg = true;
45
-
46
-    /**
47
-     * redirect to thank you page ?
48
-     *
49
-     * @type bool
50
-     */
51
-    public $redirect = false;
52
-
53
-    /**
54
-     * generate the reg form or not ?
55
-     *
56
-     * @type bool
57
-     */
58
-    public $generate_reg_form = true;
59
-
60
-    /**
61
-     * process a reg form submission or not ?
62
-     *
63
-     * @type bool
64
-     */
65
-    public $process_form_submission = false;
66
-
67
-    /**
68
-     * tracks whether the TXN status modified during this checkout
69
-     *
70
-     * @type bool
71
-     */
72
-    public $txn_status_updated = false;
73
-
74
-    /**
75
-     * only triggered to true after absolutely everything has finished.
76
-     *
77
-     * @type bool
78
-     */
79
-    protected $exit_spco = false;
80
-
81
-    /**
82
-     * tracks whether any of the TXN's Registrations statuses modified during this checkout
83
-     * indexed by registration ID
84
-     *
85
-     * @type array
86
-     */
87
-    protected $reg_status_updated = array();
88
-
89
-    /**
90
-     * timestamp when redirected from Ticket Selector to the checkout
91
-     *
92
-     * @type int
93
-     */
94
-    public $uts = 0;
95
-
96
-    /**
97
-     * total number of tickets that were in the cart
98
-     *
99
-     * @type int
100
-     */
101
-    public $total_ticket_count = 0;
102
-
103
-    /**
104
-     * corresponds loosely to EE_Transaction::remaining()
105
-     * but can be modified by SPCO
106
-     *
107
-     * @type float
108
-     */
109
-    public $amount_owing = 0;
110
-
111
-    /**
112
-     * the reg step slug from the incoming request
113
-     *
114
-     * @type string
115
-     */
116
-    public $step = '';
117
-
118
-    /**
119
-     * the reg step slug for a step being edited
120
-     *
121
-     * @type string
122
-     */
123
-    public $edit_step = '';
124
-
125
-    /**
126
-     * the action being performed on the current step
127
-     *
128
-     * @type string
129
-     */
130
-    public $action = '';
131
-
132
-    /**
133
-     * reg_url_link for a previously saved registration
134
-     *
135
-     * @type string
136
-     */
137
-    public $reg_url_link = '';
138
-
139
-    /**
140
-     * string slug for the payment method that was selected during the payment options step
141
-     *
142
-     * @type string
143
-     */
144
-    public $selected_method_of_payment = '';
145
-
146
-    /**
147
-     * base url for the site's registration checkout page - additional url params will be added to this
148
-     *
149
-     * @type string
150
-     */
151
-    public $reg_page_base_url = '';
152
-
153
-    /**
154
-     * base url for the site's registration cancelled page - additional url params will be added to this
155
-     *
156
-     * @type string
157
-     */
158
-    public $cancel_page_url = '';
159
-
160
-    /**
161
-     * base url for the site's thank you page - additional url params will be added to this
162
-     *
163
-     * @type string
164
-     */
165
-    public $thank_you_page_url = '';
166
-
167
-    /**
168
-     * base url for any redirects - additional url params will be added to this
169
-     *
170
-     * @type string
171
-     */
172
-    public $redirect_url = '';
173
-
174
-    /**
175
-     * form of POST data for use with off-site gateways
176
-     *
177
-     * @type string
178
-     */
179
-    public $redirect_form = '';
180
-
181
-    /**
182
-     * array of query where params to use when retrieving cached registrations from $this->checkout->transaction
183
-     *
184
-     * @type array
185
-     */
186
-    public $reg_cache_where_params = array();
187
-
188
-    /**
189
-     * a class for managing and creating the JSON encoded array of data that gets passed back to the client during AJAX
190
-     * requests
191
-     *
192
-     * @type EE_SPCO_JSON_Response
193
-     */
194
-    public $json_response;
195
-
196
-    /**
197
-     * where we are going next in the reg process
198
-     *
199
-     * @type EE_SPCO_Reg_Step
200
-     */
201
-    public $next_step;
202
-
203
-    /**
204
-     * where we are in the reg process
205
-     *
206
-     * @type EE_SPCO_Reg_Step
207
-     */
208
-    public $current_step;
209
-
210
-    /**
211
-     *    $_cart - the current cart object
212
-     *
213
-     * @var EE_CART
214
-     */
215
-    public $cart;
216
-
217
-    /**
218
-     *    $_transaction - the current transaction object
219
-     *
220
-     * @var EE_Transaction
221
-     */
222
-    public $transaction;
223
-
224
-    /**
225
-     *    the related attendee object for the primary registrant
226
-     *
227
-     * @type EE_Attendee
228
-     */
229
-    public $primary_attendee_obj;
230
-
231
-    /**
232
-     *    $payment_method - the payment method object for the selected method of payment
233
-     *
234
-     * @type EE_Payment_Method
235
-     */
236
-    public $payment_method;
237
-
238
-    /**
239
-     *    $payment - if a payment was successfully made during the reg process,
240
-     *    then here it is !!!
241
-     *
242
-     * @type EE_Payment
243
-     */
244
-    public $payment;
245
-
246
-    /**
247
-     *    if a payment method was selected that uses an on-site gateway, then this is the billing form
248
-     *
249
-     * @type EE_Billing_Info_Form | EE_Billing_Attendee_Info_Form
250
-     */
251
-    public $billing_form;
252
-
253
-    /**
254
-     *    the entire registration form composed of ALL of the subsections generated by the various reg steps
255
-     *
256
-     * @type EE_Form_Section_Proper
257
-     */
258
-    public $registration_form;
259
-
260
-    /**
261
-     * array of EE_SPCO_Reg_Step objects
262
-     *
263
-     * @type EE_SPCO_Reg_Step[]
264
-     */
265
-    public $reg_steps = array();
266
-
267
-    /**
268
-     * array of EE_Payment_Method objects
269
-     *
270
-     * @type EE_Payment_Method[]
271
-     */
272
-    public $available_payment_methods = array();
273
-
274
-
275
-    /**
276
-     *    class constructor
277
-     *
278
-     * @access    public
279
-     */
280
-    public function __construct()
281
-    {
282
-        $this->reg_page_base_url = EE_Registry::instance()->CFG->core->reg_page_url();
283
-        $this->thank_you_page_url = EE_Registry::instance()->CFG->core->thank_you_page_url();
284
-        $this->cancel_page_url = EE_Registry::instance()->CFG->core->cancel_page_url();
285
-        $this->continue_reg = apply_filters('FHEE__EE_Checkout___construct___continue_reg', true);
286
-
287
-        $this->admin_request = is_admin() && ! EED_Single_Page_Checkout::getRequest()->isAjax();
288
-        $this->reg_cache_where_params = array(
289
-            0          => array('REG_deleted' => false),
290
-            'order_by' => array('REG_count' => 'ASC'),
291
-        );
292
-    }
293
-
294
-
295
-    /**
296
-     * returns true if ANY reg status was updated during checkout
297
-     *
298
-     * @return boolean
299
-     */
300
-    public function any_reg_status_updated()
301
-    {
302
-        foreach ($this->reg_status_updated as $reg_status) {
303
-            if ($reg_status) {
304
-                return true;
305
-            }
306
-        }
307
-        return false;
308
-    }
309
-
310
-
311
-    /**
312
-     * @param $REG_ID
313
-     * @return boolean
314
-     */
315
-    public function reg_status_updated($REG_ID)
316
-    {
317
-        return isset($this->reg_status_updated[ $REG_ID ]) ? $this->reg_status_updated[ $REG_ID ] : false;
318
-    }
319
-
320
-
321
-    /**
322
-     * @param $REG_ID
323
-     * @param $reg_status
324
-     */
325
-    public function set_reg_status_updated($REG_ID, $reg_status)
326
-    {
327
-        $this->reg_status_updated[ $REG_ID ] = filter_var($reg_status, FILTER_VALIDATE_BOOLEAN);
328
-    }
329
-
330
-
331
-    /**
332
-     * exit_spco
333
-     *
334
-     * @return bool
335
-     */
336
-    public function exit_spco()
337
-    {
338
-        return $this->exit_spco;
339
-    }
340
-
341
-
342
-    /**
343
-     * set_exit_spco
344
-     * can ONLY be set by the  Finalize_Registration reg step
345
-     */
346
-    public function set_exit_spco()
347
-    {
348
-        if ($this->current_step instanceof EE_SPCO_Reg_Step_Finalize_Registration) {
349
-            $this->exit_spco = true;
350
-        }
351
-    }
352
-
353
-
354
-    /**
355
-     *    reset_for_current_request
356
-     *
357
-     * @access    public
358
-     * @return    void
359
-     */
360
-    public function reset_for_current_request()
361
-    {
362
-        $this->process_form_submission = false;
363
-        $this->continue_reg = apply_filters('FHEE__EE_Checkout___construct___continue_reg', true);
364
-        $this->admin_request = is_admin() && ! EED_Single_Page_Checkout::getRequest()->isFrontAjax();
365
-        $this->continue_reg = true;
366
-        $this->redirect = false;
367
-        // don't reset the cached redirect form if we're about to be asked to display it !!!
368
-        $action = EED_Single_Page_Checkout::getRequest()->getRequestParam('action', 'display_spco_reg_step');
369
-        if ($action !== 'redirect_form') {
370
-            $this->redirect_form = '';
371
-        }
372
-        $this->redirect_url = '';
373
-        $this->json_response = new EE_SPCO_JSON_Response();
374
-        EE_Form_Section_Proper::reset_js_localization();
375
-    }
376
-
377
-
378
-    /**
379
-     *    add_reg_step
380
-     *
381
-     * @access    public
382
-     * @param EE_SPCO_Reg_Step $reg_step_obj
383
-     * @return    void
384
-     */
385
-    public function add_reg_step(EE_SPCO_Reg_Step $reg_step_obj)
386
-    {
387
-        $this->reg_steps[ $reg_step_obj->slug() ] = $reg_step_obj;
388
-    }
389
-
390
-
391
-    /**
392
-     * skip_reg_step
393
-     * if the current reg step does not need to run for some reason,
394
-     * then this will advance SPCO to the next reg step,
395
-     * and mark the skipped step as completed
396
-     *
397
-     * @access    public
398
-     * @param string $reg_step_slug
399
-     * @return    void
400
-     * @throws \EE_Error
401
-     */
402
-    public function skip_reg_step($reg_step_slug = '')
403
-    {
404
-        $step_to_skip = $this->find_reg_step($reg_step_slug);
405
-        if ($step_to_skip instanceof EE_SPCO_Reg_Step && $step_to_skip->is_current_step()) {
406
-            $step_to_skip->set_is_current_step(false);
407
-            $step_to_skip->set_completed();
408
-            // advance to the next step
409
-            $this->set_current_step($this->next_step->slug());
410
-            // also reset the step param in the request in case any other code references that directly
411
-            EED_Single_Page_Checkout::getRequest()->setRequestParam('step', $this->current_step->slug());
412
-            // since we are skipping a step and setting the current step to be what was previously the next step,
413
-            // we need to check that the next step is now correct, and not still set to the current step.
414
-            if ($this->current_step->slug() === $this->next_step->slug()) {
415
-                // correctly setup the next step
416
-                $this->set_next_step();
417
-            }
418
-            $this->set_reg_step_initiated($this->current_step);
419
-        }
420
-    }
421
-
422
-
423
-    /**
424
-     *    remove_reg_step
425
-     *
426
-     * @access    public
427
-     * @param string $reg_step_slug
428
-     * @param bool   $reset whether to reset reg steps after removal
429
-     * @throws EE_Error
430
-     */
431
-    public function remove_reg_step($reg_step_slug = '', $reset = true)
432
-    {
433
-        unset($this->reg_steps[ $reg_step_slug ]);
434
-        if ($this->transaction instanceof EE_Transaction) {
435
-            // now remove reg step from TXN and save
436
-            $this->transaction->remove_reg_step($reg_step_slug);
437
-            $this->transaction->save();
438
-        }
439
-        if ($reset) {
440
-            $this->reset_reg_steps();
441
-        }
442
-    }
443
-
444
-
445
-    /**
446
-     *    set_reg_step_order
447
-     *
448
-     * @access    public
449
-     * @param string $reg_step_slug
450
-     * @param int    $order
451
-     * @return    void
452
-     */
453
-    public function set_reg_step_order($reg_step_slug = '', $order = 100)
454
-    {
455
-        if (isset($this->reg_steps[ $reg_step_slug ])) {
456
-            $this->reg_steps[ $reg_step_slug ]->set_order($order);
457
-        }
458
-    }
459
-
460
-
461
-    /**
462
-     *    set_current_step
463
-     *
464
-     * @access    public
465
-     * @param string $current_step
466
-     * @return    void
467
-     */
468
-    public function set_current_step($current_step)
469
-    {
470
-        // grab what step we're on
471
-        $this->current_step = isset($this->reg_steps[ $current_step ])
472
-            ? $this->reg_steps[ $current_step ]
473
-            : reset(
474
-                $this->reg_steps
475
-            );
476
-        // verify instance
477
-        if ($this->current_step instanceof EE_SPCO_Reg_Step) {
478
-            // we don't want to repeat completed steps if this is the first time through SPCO
479
-            if ($this->continue_reg && ! $this->revisit && $this->current_step->completed()) {
480
-                // so advance to the next step
481
-                $this->set_next_step();
482
-                if ($this->next_step instanceof EE_SPCO_Reg_Step) {
483
-                    // and attempt to set it as the current step
484
-                    $this->set_current_step($this->next_step->slug());
485
-                }
486
-                return;
487
-            }
488
-            $this->current_step->set_is_current_step(true);
489
-        } else {
490
-            EE_Error::add_error(
491
-                __('The current step could not be set.', 'event_espresso'),
492
-                __FILE__,
493
-                __FUNCTION__,
494
-                __LINE__
495
-            );
496
-        }
497
-    }
498
-
499
-
500
-    /**
501
-     *    set_next_step
502
-     * advances the reg_steps array pointer and sets the next step, then reverses pointer back to the current step
503
-     *
504
-     * @access    public
505
-     * @return    void
506
-     */
507
-    public function set_next_step()
508
-    {
509
-        // set pointer to start of array
510
-        reset($this->reg_steps);
511
-        // if there is more than one step
512
-        if (count($this->reg_steps) > 1) {
513
-            // advance to the current step and set pointer
514
-            while (key($this->reg_steps) !== $this->current_step->slug() && key($this->reg_steps) !== '') {
515
-                next($this->reg_steps);
516
-            }
517
-        }
518
-        // advance one more spot ( if it exists )
519
-        $this->next_step = next($this->reg_steps);
520
-        // verify instance
521
-        $this->next_step = $this->next_step instanceof EE_SPCO_Reg_Step ? $this->next_step : null;
522
-        // then back to current step to reset
523
-        prev($this->reg_steps);
524
-    }
525
-
526
-
527
-    /**
528
-     *    get_next_reg_step
529
-     *    this simply returns the next step from reg_steps array
530
-     *
531
-     * @access    public
532
-     * @return    EE_SPCO_Reg_Step | null
533
-     */
534
-    public function get_next_reg_step()
535
-    {
536
-        $next = next($this->reg_steps);
537
-        prev($this->reg_steps);
538
-        return $next instanceof EE_SPCO_Reg_Step ? $next : null;
539
-    }
540
-
541
-
542
-    /**
543
-     * get_prev_reg_step
544
-     *    this simply returns the previous step from reg_steps array
545
-     *
546
-     * @access    public
547
-     * @return    EE_SPCO_Reg_Step | null
548
-     */
549
-    public function get_prev_reg_step()
550
-    {
551
-        $prev = prev($this->reg_steps);
552
-        next($this->reg_steps);
553
-        return $prev instanceof EE_SPCO_Reg_Step ? $prev : null;
554
-    }
555
-
556
-
557
-    /**
558
-     * sort_reg_steps
559
-     *
560
-     * @access public
561
-     * @return void
562
-     */
563
-    public function sort_reg_steps()
564
-    {
565
-        $reg_step_sorting_callback = apply_filters(
566
-            'FHEE__EE_Checkout__sort_reg_steps__reg_step_sorting_callback',
567
-            'reg_step_sorting_callback'
568
-        );
569
-        uasort($this->reg_steps, array($this, $reg_step_sorting_callback));
570
-    }
571
-
572
-
573
-    /**
574
-     * find_reg_step
575
-     * finds a reg step by the given slug
576
-     *
577
-     * @access    public
578
-     * @param string $reg_step_slug
579
-     * @return EE_SPCO_Reg_Step|null
580
-     */
581
-    public function find_reg_step($reg_step_slug = '')
582
-    {
583
-        if (! empty($reg_step_slug)) {
584
-            // copy reg step array
585
-            $reg_steps = $this->reg_steps;
586
-            // set pointer to start of array
587
-            reset($reg_steps);
588
-            // if there is more than one step
589
-            if (count($reg_steps) > 1) {
590
-                // advance to the current step and set pointer
591
-                while (key($reg_steps) !== $reg_step_slug && key($reg_steps) !== '') {
592
-                    next($reg_steps);
593
-                }
594
-                return current($reg_steps);
595
-            }
596
-        }
597
-        return null;
598
-    }
599
-
600
-
601
-    /**
602
-     * reg_step_sorting_callback
603
-     *
604
-     * @access public
605
-     * @param EE_SPCO_Reg_Step $reg_step_A
606
-     * @param EE_SPCO_Reg_Step $reg_step_B
607
-     * @return int
608
-     */
609
-    public function reg_step_sorting_callback(EE_SPCO_Reg_Step $reg_step_A, EE_SPCO_Reg_Step $reg_step_B)
610
-    {
611
-        // send finalize_registration step to the end of the array
612
-        if ($reg_step_A->slug() === 'finalize_registration') {
613
-            return 1;
614
-        } elseif ($reg_step_B->slug() === 'finalize_registration') {
615
-            return -1;
616
-        }
617
-        if ($reg_step_A->order() === $reg_step_B->order()) {
618
-            return 0;
619
-        }
620
-        return ($reg_step_A->order() > $reg_step_B->order()) ? 1 : -1;
621
-    }
622
-
623
-
624
-    /**
625
-     * set_reg_step_initiated
626
-     *
627
-     * @access    public
628
-     * @param    EE_SPCO_Reg_Step $reg_step
629
-     * @throws \EE_Error
630
-     */
631
-    public function set_reg_step_initiated(EE_SPCO_Reg_Step $reg_step)
632
-    {
633
-        // call set_reg_step_initiated ???
634
-        if (// first time visiting SPCO ?
635
-            ! $this->revisit
636
-            && (
637
-                // and displaying the reg step form for the first time ?
638
-                $this->action === 'display_spco_reg_step'
639
-                // or initializing the final step
640
-                || $reg_step instanceof EE_SPCO_Reg_Step_Finalize_Registration
641
-            )
642
-        ) {
643
-            // set the start time for this reg step
644
-            if (! $this->transaction->set_reg_step_initiated($reg_step->slug())) {
645
-                if (WP_DEBUG) {
646
-                    EE_Error::add_error(
647
-                        sprintf(
648
-                            __('The "%1$s" registration step was not initialized properly.', 'event_espresso'),
649
-                            $reg_step->name()
650
-                        ),
651
-                        __FILE__,
652
-                        __FUNCTION__,
653
-                        __LINE__
654
-                    );
655
-                }
656
-            }
657
-        }
658
-    }
659
-
660
-
661
-    /**
662
-     *    set_reg_step_JSON_info
663
-     *
664
-     * @access public
665
-     * @return    void
666
-     */
667
-    public function set_reg_step_JSON_info()
668
-    {
669
-        EE_Registry::$i18n_js_strings['reg_steps'] = array();
670
-        // pass basic reg step data to JS
671
-        foreach ($this->reg_steps as $reg_step) {
672
-            EE_Registry::$i18n_js_strings['reg_steps'][] = $reg_step->slug();
673
-        }
674
-        // reset reg step html
675
-        // $this->json_response->set_reg_step_html('');
676
-    }
677
-
678
-
679
-    /**
680
-     *    reset_reg_steps
681
-     *
682
-     * @access public
683
-     * @return void
684
-     */
685
-    public function reset_reg_steps()
686
-    {
687
-        $this->sort_reg_steps();
688
-        $this->set_current_step(EED_Single_Page_Checkout::getRequest()->getRequestParam('step'));
689
-        $this->set_next_step();
690
-        // the text that appears on the reg step form submit button
691
-        $this->current_step->set_submit_button_text();
692
-        $this->set_reg_step_JSON_info();
693
-    }
694
-
695
-
696
-    /**
697
-     *    get_registration_time_limit
698
-     *
699
-     * @access    public
700
-     * @return        string
701
-     */
702
-    public function get_registration_time_limit()
703
-    {
704
-
705
-        $registration_time_limit = (float) (EE_Registry::instance()->SSN->expiration() - time());
706
-        $time_limit_format = $registration_time_limit > 60 * MINUTE_IN_SECONDS ? 'H:i:s' : 'i:s';
707
-        $registration_time_limit = date($time_limit_format, $registration_time_limit);
708
-        return apply_filters(
709
-            'FHEE__EE_Checkout__get_registration_time_limit__registration_time_limit',
710
-            $registration_time_limit
711
-        );
712
-    }
713
-
714
-
715
-    /**
716
-     * payment_required
717
-     *
718
-     * @return boolean
719
-     */
720
-    public function payment_required()
721
-    {
722
-        // if NOT:
723
-        //     registration via admin
724
-        //      completed TXN
725
-        //      overpaid TXN
726
-        //      free TXN(total = 0.00)
727
-        //      then payment required is TRUE
728
-        return ! ($this->admin_request
729
-                  || $this->transaction->is_completed()
730
-                  || $this->transaction->is_overpaid()
731
-                  || $this->transaction->is_free()) ? true : false;
732
-    }
733
-
734
-
735
-    /**
736
-     * get_cart_for_transaction
737
-     *
738
-     * @access public
739
-     * @param EE_Transaction $transaction
740
-     * @return EE_Cart
741
-     */
742
-    public function get_cart_for_transaction($transaction)
743
-    {
744
-        $session = EE_Registry::instance()->load_core('Session');
745
-        $cart = $transaction instanceof EE_Transaction ? EE_Cart::get_cart_from_txn($transaction, $session) : null;
746
-        // verify cart
747
-        if (! $cart instanceof EE_Cart) {
748
-            $cart = EE_Registry::instance()->load_core('Cart');
749
-        }
750
-
751
-        return $cart;
752
-    }
753
-
754
-
755
-    /**
756
-     *    initialize_txn_reg_steps_array
757
-     *
758
-     * @access public
759
-     * @return    array
760
-     */
761
-    public function initialize_txn_reg_steps_array()
762
-    {
763
-        $txn_reg_steps_array = array();
764
-        foreach ($this->reg_steps as $reg_step) {
765
-            $txn_reg_steps_array[ $reg_step->slug() ] = false;
766
-        }
767
-        return $txn_reg_steps_array;
768
-    }
769
-
770
-
771
-    /**
772
-     *    update_txn_reg_steps_array
773
-     *
774
-     * @access public
775
-     * @return    bool
776
-     * @throws \EE_Error
777
-     */
778
-    public function update_txn_reg_steps_array()
779
-    {
780
-        $updated = false;
781
-        foreach ($this->reg_steps as $reg_step) {
782
-            if ($reg_step->completed()) {
783
-                $updated = $this->transaction->set_reg_step_completed($reg_step->slug())
784
-                    ? true
785
-                    : $updated;
786
-            }
787
-        }
788
-        if ($updated) {
789
-            $this->transaction->save();
790
-        }
791
-        return $updated;
792
-    }
793
-
794
-
795
-    /**
796
-     *    stash_transaction_and_checkout
797
-     *
798
-     * @access public
799
-     * @return    void
800
-     * @throws \EE_Error
801
-     */
802
-    public function stash_transaction_and_checkout()
803
-    {
804
-        if (! $this->revisit) {
805
-            $this->update_txn_reg_steps_array();
806
-        }
807
-        $this->track_transaction_and_registration_status_updates();
808
-        // save all data to the db, but suppress errors
809
-        // $this->save_all_data( FALSE );
810
-        // cache the checkout in the session
811
-        EE_Registry::instance()->SSN->set_checkout($this);
812
-    }
813
-
814
-
815
-    /**
816
-     *    track_transaction_and_registration_status_updates
817
-     *    stores whether any updates were made to the TXN or it's related registrations
818
-     *
819
-     * @access public
820
-     * @return void
821
-     * @throws \EE_Error
822
-     */
823
-    public function track_transaction_and_registration_status_updates()
824
-    {
825
-        // verify the transaction
826
-        if ($this->transaction instanceof EE_Transaction) {
827
-            // has there been a TXN status change during this checkout?
828
-            $this->txn_status_updated = $this->transaction->txn_status_updated();
829
-            /** @type EE_Registration_Processor $registration_processor */
830
-            $registration_processor = EE_Registry::instance()->load_class('Registration_Processor');
831
-            // grab the saved registrations from the transaction
832
-            foreach ($this->transaction->registrations($this->reg_cache_where_params) as $registration) {
833
-                if ($registration_processor->reg_status_updated($registration->ID())) {
834
-                    $this->set_reg_status_updated($registration->ID(), true);
835
-                }
836
-            }
837
-        }
838
-    }
839
-
840
-
841
-    /**
842
-     *    visit_allows_processing_of_this_registration
843
-     *    determines if the current SPCO visit should allow the passed EE_Registration to be used in processing.
844
-     *    one of the following conditions must be met:
845
-     *        EITHER:    A) first time thru SPCO -> process ALL registrations ( NOT a revisit )
846
-     *        OR :        B) primary registrant is editing info -> process ALL registrations ( primary_revisit )
847
-     *        OR :        C) another registrant is editing info -> ONLY process their registration ( revisit AND their
848
-     *        reg_url_link matches )
849
-     *
850
-     * @access public
851
-     * @param    EE_Registration $registration
852
-     * @return    bool
853
-     * @throws \EE_Error
854
-     */
855
-    public function visit_allows_processing_of_this_registration(EE_Registration $registration)
856
-    {
857
-        return ! $this->revisit
858
-               || $this->primary_revisit
859
-               || (
860
-                   $this->revisit && $this->reg_url_link === $registration->reg_url_link()
861
-               )
862
-            ? true
863
-            : false;
864
-    }
865
-
866
-
867
-    /**
868
-     *    _transaction_has_primary_registration
869
-     *
870
-     * @access        private
871
-     * @return        bool
872
-     */
873
-    public function transaction_has_primary_registrant()
874
-    {
875
-        return $this->primary_attendee_obj instanceof EE_Attendee ? true : false;
876
-    }
877
-
878
-
879
-    /**
880
-     *    save_all_data
881
-     *    simply loops through the current transaction and saves all data for each registration
882
-     *
883
-     * @access public
884
-     * @param bool $show_errors
885
-     * @return bool
886
-     * @throws \EE_Error
887
-     */
888
-    public function save_all_data($show_errors = true)
889
-    {
890
-        // verify the transaction
891
-        if ($this->transaction instanceof EE_Transaction) {
892
-            // save to ensure that TXN has ID
893
-            $this->transaction->save();
894
-            // grab the saved registrations from the transaction
895
-            foreach ($this->transaction->registrations($this->reg_cache_where_params) as $registration) {
896
-                $this->_save_registration($registration, $show_errors);
897
-            }
898
-        } else {
899
-            if ($show_errors) {
900
-                EE_Error::add_error(
901
-                    __(
902
-                        'A valid Transaction was not found when attempting to save your registration information.',
903
-                        'event_espresso'
904
-                    ),
905
-                    __FILE__,
906
-                    __FUNCTION__,
907
-                    __LINE__
908
-                );
909
-            }
910
-            return false;
911
-        }
912
-        return true;
913
-    }
914
-
915
-
916
-    /**
917
-     * _save_registration_attendee
918
-     *
919
-     * @param    EE_Registration $registration
920
-     * @param bool               $show_errors
921
-     * @return void
922
-     * @throws \EE_Error
923
-     */
924
-    private function _save_registration($registration, $show_errors = true)
925
-    {
926
-        // verify object
927
-        if ($registration instanceof EE_Registration) {
928
-            // should this registration be processed during this visit ?
929
-            if ($this->visit_allows_processing_of_this_registration($registration)) {
930
-                // set TXN ID
931
-                if (! $registration->transaction_ID()) {
932
-                    $registration->set_transaction_id($this->transaction->ID());
933
-                }
934
-                // verify and save the attendee
935
-                $this->_save_registration_attendee($registration, $show_errors);
936
-                // save answers to reg form questions
937
-                $this->_save_registration_answers($registration, $show_errors);
938
-                // save changes
939
-                $registration->save();
940
-                // update txn cache
941
-                if (! $this->transaction->update_cache_after_object_save('Registration', $registration)) {
942
-                    if ($show_errors) {
943
-                        EE_Error::add_error(
944
-                            __(
945
-                                'The newly saved Registration object could not be cached on the Transaction.',
946
-                                'event_espresso'
947
-                            ),
948
-                            __FILE__,
949
-                            __FUNCTION__,
950
-                            __LINE__
951
-                        );
952
-                    }
953
-                }
954
-            }
955
-        } else {
956
-            if ($show_errors) {
957
-                EE_Error::add_error(
958
-                    __(
959
-                        'An invalid Registration object was discovered when attempting to save your registration information.',
960
-                        'event_espresso'
961
-                    ),
962
-                    __FILE__,
963
-                    __FUNCTION__,
964
-                    __LINE__
965
-                );
966
-            }
967
-        }
968
-    }
969
-
970
-
971
-    /**
972
-     * _save_registration_attendee
973
-     *
974
-     * @param    EE_Registration $registration
975
-     * @param bool               $show_errors
976
-     * @return void
977
-     * @throws \EE_Error
978
-     */
979
-    private function _save_registration_attendee($registration, $show_errors = true)
980
-    {
981
-        if ($registration->attendee() instanceof EE_Attendee) {
982
-            // save so that ATT has ID
983
-            $registration->attendee()->save();
984
-            if (! $registration->update_cache_after_object_save('Attendee', $registration->attendee())) {
985
-                if ($show_errors) {
986
-                    EE_Error::add_error(
987
-                        __(
988
-                            'The newly saved Attendee object could not be cached on the registration.',
989
-                            'event_espresso'
990
-                        ),
991
-                        __FILE__,
992
-                        __FUNCTION__,
993
-                        __LINE__
994
-                    );
995
-                }
996
-            }
997
-        } else {
998
-            if ($show_errors) {
999
-                EE_Error::add_error(
1000
-                    sprintf(
1001
-                        '%1$s||%1$s $attendee = %2$s',
1002
-                        __(
1003
-                            'Either no Attendee information was found, or an invalid Attendee object was discovered when attempting to save your registration information.',
1004
-                            'event_espresso'
1005
-                        ),
1006
-                        var_export($registration->attendee(), true)
1007
-                    ),
1008
-                    __FILE__,
1009
-                    __FUNCTION__,
1010
-                    __LINE__
1011
-                );
1012
-            }
1013
-        }
1014
-    }
1015
-
1016
-
1017
-    /**
1018
-     * _save_question_answers
1019
-     *
1020
-     * @param    EE_Registration $registration
1021
-     * @param bool               $show_errors
1022
-     * @return void
1023
-     * @throws \EE_Error
1024
-     */
1025
-    private function _save_registration_answers($registration, $show_errors = true)
1026
-    {
1027
-        // now save the answers
1028
-        foreach ($registration->answers() as $cache_key => $answer) {
1029
-            // verify object
1030
-            if ($answer instanceof EE_Answer) {
1031
-                $answer->set_registration($registration->ID());
1032
-                $answer->save();
1033
-                if (! $registration->update_cache_after_object_save('Answer', $answer, $cache_key)) {
1034
-                    if ($show_errors) {
1035
-                        EE_Error::add_error(
1036
-                            __(
1037
-                                'The newly saved Answer object could not be cached on the registration.',
1038
-                                'event_espresso'
1039
-                            ),
1040
-                            __FILE__,
1041
-                            __FUNCTION__,
1042
-                            __LINE__
1043
-                        );
1044
-                    }
1045
-                }
1046
-            } else {
1047
-                if ($show_errors) {
1048
-                    EE_Error::add_error(
1049
-                        __(
1050
-                            'An invalid Answer object was discovered when attempting to save your registration information.',
1051
-                            'event_espresso'
1052
-                        ),
1053
-                        __FILE__,
1054
-                        __FUNCTION__,
1055
-                        __LINE__
1056
-                    );
1057
-                }
1058
-            }
1059
-        }
1060
-    }
1061
-
1062
-
1063
-    /**
1064
-     *    refresh_all_entities
1065
-     *   will either refresh the entity map with objects form the db or from the checkout cache
1066
-     *
1067
-     * @access public
1068
-     * @param bool $from_db
1069
-     * @return bool
1070
-     * @throws \EE_Error
1071
-     */
1072
-    public function refresh_all_entities($from_db = false)
1073
-    {
1074
-        $from_db = $this->current_step->is_final_step() || $this->action === 'process_gateway_response'
1075
-            ? true
1076
-            : $from_db;
1077
-        // $this->log(
1078
-        //     __CLASS__,
1079
-        //     __FUNCTION__,
1080
-        //     __LINE__,
1081
-        //     array('from_db' => $from_db)
1082
-        // );
1083
-        return $from_db ? $this->refresh_from_db() : $this->refresh_entity_map();
1084
-    }
1085
-
1086
-
1087
-    /**
1088
-     *  refresh_entity_map
1089
-     *  simply loops through the current transaction and updates each
1090
-     *  model's entity map using EEM_Base::refresh_entity_map_from_db()
1091
-     *
1092
-     * @access public
1093
-     * @return bool
1094
-     * @throws \EE_Error
1095
-     */
1096
-    protected function refresh_from_db()
1097
-    {
1098
-        // verify the transaction
1099
-        if ($this->transaction instanceof EE_Transaction && $this->transaction->ID()) {
1100
-            // pull fresh TXN data from the db
1101
-            $this->transaction = $this->transaction->get_model()->refresh_entity_map_from_db($this->transaction->ID());
1102
-            // update EE_Checkout's cached primary_attendee object
1103
-            $this->primary_attendee_obj = $this->_refresh_primary_attendee_obj_from_db($this->transaction);
1104
-            // update EE_Checkout's cached payment object
1105
-            $payment = $this->transaction->last_payment();
1106
-            $this->payment = $payment instanceof EE_Payment ? $payment : $this->payment;
1107
-            // update EE_Checkout's cached payment_method object
1108
-            $payment_method = $this->payment instanceof EE_Payment ? $this->payment->payment_method() : null;
1109
-            $this->payment_method = $payment_method instanceof EE_Payment_Method ? $payment_method
1110
-                : $this->payment_method;
1111
-            // now refresh the cart, based on the TXN
1112
-            $this->cart = $this->get_cart_for_transaction($this->transaction);
1113
-        } else {
1114
-            EE_Error::add_error(
1115
-                __(
1116
-                    'A valid Transaction was not found when attempting to update the model entity mapper.',
1117
-                    'event_espresso'
1118
-                ),
1119
-                __FILE__,
1120
-                __FUNCTION__,
1121
-                __LINE__
1122
-            );
1123
-            return false;
1124
-        }
1125
-        return true;
1126
-    }
1127
-
1128
-
1129
-    /**
1130
-     * _refresh_primary_attendee_obj_from_db
1131
-     *
1132
-     * @param   EE_Transaction $transaction
1133
-     * @return  EE_Attendee | null
1134
-     * @throws \EE_Error
1135
-     */
1136
-    protected function _refresh_primary_attendee_obj_from_db(EE_Transaction $transaction)
1137
-    {
1138
-
1139
-        $primary_attendee_obj = null;
1140
-        // grab the saved registrations from the transaction
1141
-        foreach ($transaction->registrations($this->reg_cache_where_params, true) as $registration) {
1142
-            // verify object
1143
-            if ($registration instanceof EE_Registration) {
1144
-                $attendee = $registration->attendee();
1145
-                // verify object && maybe cache primary_attendee_obj ?
1146
-                if ($attendee instanceof EE_Attendee && $registration->is_primary_registrant()) {
1147
-                    $primary_attendee_obj = $attendee;
1148
-                }
1149
-            } else {
1150
-                EE_Error::add_error(
1151
-                    __(
1152
-                        'An invalid Registration object was discovered when attempting to update the model entity mapper.',
1153
-                        'event_espresso'
1154
-                    ),
1155
-                    __FILE__,
1156
-                    __FUNCTION__,
1157
-                    __LINE__
1158
-                );
1159
-            }
1160
-        }
1161
-        return $primary_attendee_obj;
1162
-    }
1163
-
1164
-
1165
-    /**
1166
-     *  refresh_entity_map
1167
-     *  simply loops through the current transaction and updates
1168
-     *  each model's entity map using EEM_Base::refresh_entity_map_with()
1169
-     *
1170
-     * @access public
1171
-     * @return bool
1172
-     * @throws \EE_Error
1173
-     */
1174
-    protected function refresh_entity_map()
1175
-    {
1176
-        // verify the transaction
1177
-        if ($this->transaction instanceof EE_Transaction && $this->transaction->ID()) {
1178
-            // never cache payment info
1179
-            $this->transaction->clear_cache('Payment');
1180
-            // is the Payment Options Reg Step completed ?
1181
-            if ($this->transaction->reg_step_completed('payment_options')) {
1182
-                // then check for payments and update TXN accordingly
1183
-                /** @type EE_Transaction_Payments $transaction_payments */
1184
-                $transaction_payments = EE_Registry::instance()->load_class('Transaction_Payments');
1185
-                $transaction_payments->calculate_total_payments_and_update_status($this->transaction);
1186
-            }
1187
-            // grab the saved registrations from the transaction
1188
-            foreach ($this->transaction->registrations($this->reg_cache_where_params) as $reg_cache_ID => $registration) {
1189
-                $this->_refresh_registration($reg_cache_ID, $registration);
1190
-            }
1191
-            // make sure our cached TXN is added to the model entity mapper
1192
-            $this->transaction = $this->transaction->get_model()->refresh_entity_map_with(
1193
-                $this->transaction->ID(),
1194
-                $this->transaction
1195
-            );
1196
-        } else {
1197
-            EE_Error::add_error(
1198
-                __(
1199
-                    'A valid Transaction was not found when attempting to update the model entity mapper.',
1200
-                    'event_espresso'
1201
-                ),
1202
-                __FILE__,
1203
-                __FUNCTION__,
1204
-                __LINE__
1205
-            );
1206
-            return false;
1207
-        }
1208
-        // verify and update the cart because inaccurate totals are not so much fun
1209
-        if ($this->cart instanceof EE_Cart) {
1210
-            $grand_total = $this->cart->get_grand_total();
1211
-            if ($grand_total instanceof EE_Line_Item && $grand_total->ID()) {
1212
-                $grand_total->recalculate_total_including_taxes();
1213
-                $grand_total = $grand_total->get_model()->refresh_entity_map_with(
1214
-                    $this->cart->get_grand_total()->ID(),
1215
-                    $this->cart->get_grand_total()
1216
-                );
1217
-            }
1218
-            if ($grand_total instanceof EE_Line_Item) {
1219
-                $this->cart = EE_Cart::instance($grand_total);
1220
-            } else {
1221
-                EE_Error::add_error(
1222
-                    __(
1223
-                        'A valid Cart was not found when attempting to update the model entity mapper.',
1224
-                        'event_espresso'
1225
-                    ),
1226
-                    __FILE__,
1227
-                    __FUNCTION__,
1228
-                    __LINE__
1229
-                );
1230
-                return false;
1231
-            }
1232
-        }
1233
-        return true;
1234
-    }
1235
-
1236
-
1237
-    /**
1238
-     * _refresh_registration
1239
-     *
1240
-     * @param    string | int    $reg_cache_ID
1241
-     * @param    EE_Registration $registration
1242
-     * @return void
1243
-     * @throws \EE_Error
1244
-     */
1245
-    protected function _refresh_registration($reg_cache_ID, $registration)
1246
-    {
1247
-
1248
-        // verify object
1249
-        if ($registration instanceof EE_Registration) {
1250
-            // update the entity mapper attendee
1251
-            $this->_refresh_registration_attendee($registration);
1252
-            // update the entity mapper answers for reg form questions
1253
-            $this->_refresh_registration_answers($registration);
1254
-            // make sure the cached registration is added to the model entity mapper
1255
-            $registration->get_model()->refresh_entity_map_with($reg_cache_ID, $registration);
1256
-        } else {
1257
-            EE_Error::add_error(
1258
-                __(
1259
-                    'An invalid Registration object was discovered when attempting to update the model entity mapper.',
1260
-                    'event_espresso'
1261
-                ),
1262
-                __FILE__,
1263
-                __FUNCTION__,
1264
-                __LINE__
1265
-            );
1266
-        }
1267
-    }
1268
-
1269
-
1270
-    /**
1271
-     * _save_registration_attendee
1272
-     *
1273
-     * @param    EE_Registration $registration
1274
-     * @return void
1275
-     * @throws \EE_Error
1276
-     */
1277
-    protected function _refresh_registration_attendee($registration)
1278
-    {
1279
-
1280
-        $attendee = $registration->attendee();
1281
-        // verify object
1282
-        if ($attendee instanceof EE_Attendee && $attendee->ID()) {
1283
-            // make sure the cached attendee is added to the model entity mapper
1284
-            $registration->attendee()->get_model()->refresh_entity_map_with($attendee->ID(), $attendee);
1285
-            // maybe cache primary_attendee_obj ?
1286
-            if ($registration->is_primary_registrant()) {
1287
-                $this->primary_attendee_obj = $attendee;
1288
-            }
1289
-        }
1290
-    }
1291
-
1292
-
1293
-    /**
1294
-     * _refresh_registration_answers
1295
-     *
1296
-     * @param    EE_Registration $registration
1297
-     * @return void
1298
-     * @throws \EE_Error
1299
-     */
1300
-    protected function _refresh_registration_answers($registration)
1301
-    {
1302
-
1303
-        // now update the answers
1304
-        foreach ($registration->answers() as $cache_key => $answer) {
1305
-            // verify object
1306
-            if ($answer instanceof EE_Answer) {
1307
-                if ($answer->ID()) {
1308
-                    // make sure the cached answer is added to the model entity mapper
1309
-                    $answer->get_model()->refresh_entity_map_with($answer->ID(), $answer);
1310
-                }
1311
-            } else {
1312
-                EE_Error::add_error(
1313
-                    __(
1314
-                        'An invalid Answer object was discovered when attempting to update the model entity mapper.',
1315
-                        'event_espresso'
1316
-                    ),
1317
-                    __FILE__,
1318
-                    __FUNCTION__,
1319
-                    __LINE__
1320
-                );
1321
-            }
1322
-        }
1323
-    }
1324
-
1325
-
1326
-    /**
1327
-     *    __sleep
1328
-     * to conserve db space, let's remove the reg_form and the EE_Checkout object from EE_SPCO_Reg_Step objects upon
1329
-     * serialization EE_Checkout will handle the reimplementation of itself upon waking, but we won't bother with the
1330
-     * reg form, because if needed, it will be regenerated anyways
1331
-     *
1332
-     * @return array
1333
-     * @throws \EE_Error
1334
-     */
1335
-    public function __sleep()
1336
-    {
1337
-        if ($this->primary_attendee_obj instanceof EE_Attendee && $this->primary_attendee_obj->ID()) {
1338
-            $this->primary_attendee_obj = $this->primary_attendee_obj->ID();
1339
-        }        // remove the reg form and the checkout
1340
-        if ($this->transaction instanceof EE_Transaction && $this->transaction->ID()) {
1341
-            $this->transaction = $this->transaction->ID();
1342
-        }        // remove the reg form and the checkout
1343
-        return array_diff(array_keys(get_object_vars($this)), array('billing_form', 'registration_form'));
1344
-    }
1345
-
1346
-
1347
-    /**
1348
-     *    __wakeup
1349
-     * to conserve db space, we are removing the EE_Checkout object from EE_SPCO_Reg_Step objects upon serialization
1350
-     * this will reinstate the EE_Checkout object on each EE_SPCO_Reg_Step object
1351
-     */
1352
-    public function __wakeup()
1353
-    {
1354
-        if (! $this->primary_attendee_obj instanceof EE_Attendee && absint($this->primary_attendee_obj) !== 0) {
1355
-            // $this->primary_attendee_obj is actually just an ID, so use it to get the object from the db
1356
-            $this->primary_attendee_obj = EEM_Attendee::instance()->get_one_by_ID($this->primary_attendee_obj);
1357
-        }
1358
-        if (! $this->transaction instanceof EE_Transaction && absint($this->transaction) !== 0) {
1359
-            // $this->transaction is actually just an ID, so use it to get the object from the db
1360
-            $this->transaction = EEM_Transaction::instance()->get_one_by_ID($this->transaction);
1361
-        }
1362
-        foreach ($this->reg_steps as $reg_step) {
1363
-            $reg_step->checkout = $this;
1364
-        }
1365
-    }
1366
-
1367
-
1368
-    /**
1369
-     * debug
1370
-     *
1371
-     * @param string $class
1372
-     * @param string $func
1373
-     * @param string $line
1374
-     * @param array  $info
1375
-     * @param bool   $display_request
1376
-     * @throws \EE_Error
1377
-     */
1378
-    public function log($class = '', $func = '', $line = '', $info = array(), $display_request = false)
1379
-    {
1380
-        $disabled = true;
1381
-        if (WP_DEBUG && ! $disabled) {
1382
-            $debug_data = get_option('EE_DEBUG_SPCO_' . EE_Session::instance()->id(), array());
1383
-            $default_data = array(
1384
-                $class                    => $func . '() : ' . $line,
1385
-                'request->step'           => $this->step,
1386
-                'request->action'         => $this->action,
1387
-                'current_step->slug'      => $this->current_step instanceof EE_SPCO_Reg_Step ?
1388
-                    $this->current_step->slug() : '',
1389
-                'current_step->completed' => $this->current_step instanceof EE_SPCO_Reg_Step ?
1390
-                    $this->current_step->completed() : '',
1391
-                'txn_status_updated'      => $this->transaction->txn_status_updated(),
1392
-                'reg_status_updated'      => $this->reg_status_updated,
1393
-                'reg_url_link'            => $this->reg_url_link,
1394
-            );
1395
-            if ($this->transaction instanceof EE_Transaction) {
1396
-                $default_data['TXN_status'] = $this->transaction->status_ID();
1397
-                $default_data['TXN_reg_steps'] = $this->transaction->reg_steps();
1398
-                foreach ($this->transaction->registrations($this->reg_cache_where_params) as $REG_ID => $registration) {
1399
-                    $default_data['registrations'][ $REG_ID ] = $registration->status_ID();
1400
-                }
1401
-                if ($this->transaction->ID()) {
1402
-                    $TXN_ID = 'EE_Transaction: ' . $this->transaction->ID();
1403
-                    // don't serialize objects
1404
-                    $info = $this->_strip_objects($info);
1405
-                    if (! isset($debug_data[ $TXN_ID ])) {
1406
-                        $debug_data[ $TXN_ID ] = array();
1407
-                    }
1408
-                    $debug_data[ $TXN_ID ][ microtime() ] = array_merge(
1409
-                        $default_data,
1410
-                        $info
1411
-                    );
1412
-                    update_option('EE_DEBUG_SPCO_' . EE_Session::instance()->id(), $debug_data);
1413
-                }
1414
-            }
1415
-        }
1416
-    }
1417
-
1418
-
1419
-    /**
1420
-     * _strip_objects
1421
-     *
1422
-     * @param array $info
1423
-     * @return array
1424
-     */
1425
-    public function _strip_objects($info = array())
1426
-    {
1427
-        foreach ((array) $info as $key => $value) {
1428
-            if (is_array($value)) {
1429
-                $info[ $key ] = $this->_strip_objects($value);
1430
-            } elseif (is_object($value)) {
1431
-                $object_class = get_class($value);
1432
-                $info[ $object_class ] = array();
1433
-                $info[ $object_class ]['ID'] = method_exists($value, 'ID') ? $value->ID() : 0;
1434
-                if (method_exists($value, 'status')) {
1435
-                    $info[ $object_class ]['status'] = $value->status();
1436
-                } elseif (method_exists($value, 'status_ID')) {
1437
-                    $info[ $object_class ]['status'] = $value->status_ID();
1438
-                }
1439
-                unset($info[ $key ]);
1440
-            }
1441
-        }
1442
-        return (array) $info;
1443
-    }
18
+	/**
19
+	 *    whether current request originated from the EE admin
20
+	 *
21
+	 * @type bool
22
+	 */
23
+	public $admin_request = false;
24
+
25
+	/**
26
+	 * whether returning to edit attendee information or to retry a payment
27
+	 *
28
+	 * @type bool
29
+	 */
30
+	public $revisit = false;
31
+
32
+	/**
33
+	 * whether the primary registrant is returning to edit attendee information or to retry a payment
34
+	 *
35
+	 * @type bool
36
+	 */
37
+	public $primary_revisit = false;
38
+
39
+	/**
40
+	 * is registration allowed to progress or halted for some reason such as failing to pass recaptcha?
41
+	 *
42
+	 * @type bool
43
+	 */
44
+	public $continue_reg = true;
45
+
46
+	/**
47
+	 * redirect to thank you page ?
48
+	 *
49
+	 * @type bool
50
+	 */
51
+	public $redirect = false;
52
+
53
+	/**
54
+	 * generate the reg form or not ?
55
+	 *
56
+	 * @type bool
57
+	 */
58
+	public $generate_reg_form = true;
59
+
60
+	/**
61
+	 * process a reg form submission or not ?
62
+	 *
63
+	 * @type bool
64
+	 */
65
+	public $process_form_submission = false;
66
+
67
+	/**
68
+	 * tracks whether the TXN status modified during this checkout
69
+	 *
70
+	 * @type bool
71
+	 */
72
+	public $txn_status_updated = false;
73
+
74
+	/**
75
+	 * only triggered to true after absolutely everything has finished.
76
+	 *
77
+	 * @type bool
78
+	 */
79
+	protected $exit_spco = false;
80
+
81
+	/**
82
+	 * tracks whether any of the TXN's Registrations statuses modified during this checkout
83
+	 * indexed by registration ID
84
+	 *
85
+	 * @type array
86
+	 */
87
+	protected $reg_status_updated = array();
88
+
89
+	/**
90
+	 * timestamp when redirected from Ticket Selector to the checkout
91
+	 *
92
+	 * @type int
93
+	 */
94
+	public $uts = 0;
95
+
96
+	/**
97
+	 * total number of tickets that were in the cart
98
+	 *
99
+	 * @type int
100
+	 */
101
+	public $total_ticket_count = 0;
102
+
103
+	/**
104
+	 * corresponds loosely to EE_Transaction::remaining()
105
+	 * but can be modified by SPCO
106
+	 *
107
+	 * @type float
108
+	 */
109
+	public $amount_owing = 0;
110
+
111
+	/**
112
+	 * the reg step slug from the incoming request
113
+	 *
114
+	 * @type string
115
+	 */
116
+	public $step = '';
117
+
118
+	/**
119
+	 * the reg step slug for a step being edited
120
+	 *
121
+	 * @type string
122
+	 */
123
+	public $edit_step = '';
124
+
125
+	/**
126
+	 * the action being performed on the current step
127
+	 *
128
+	 * @type string
129
+	 */
130
+	public $action = '';
131
+
132
+	/**
133
+	 * reg_url_link for a previously saved registration
134
+	 *
135
+	 * @type string
136
+	 */
137
+	public $reg_url_link = '';
138
+
139
+	/**
140
+	 * string slug for the payment method that was selected during the payment options step
141
+	 *
142
+	 * @type string
143
+	 */
144
+	public $selected_method_of_payment = '';
145
+
146
+	/**
147
+	 * base url for the site's registration checkout page - additional url params will be added to this
148
+	 *
149
+	 * @type string
150
+	 */
151
+	public $reg_page_base_url = '';
152
+
153
+	/**
154
+	 * base url for the site's registration cancelled page - additional url params will be added to this
155
+	 *
156
+	 * @type string
157
+	 */
158
+	public $cancel_page_url = '';
159
+
160
+	/**
161
+	 * base url for the site's thank you page - additional url params will be added to this
162
+	 *
163
+	 * @type string
164
+	 */
165
+	public $thank_you_page_url = '';
166
+
167
+	/**
168
+	 * base url for any redirects - additional url params will be added to this
169
+	 *
170
+	 * @type string
171
+	 */
172
+	public $redirect_url = '';
173
+
174
+	/**
175
+	 * form of POST data for use with off-site gateways
176
+	 *
177
+	 * @type string
178
+	 */
179
+	public $redirect_form = '';
180
+
181
+	/**
182
+	 * array of query where params to use when retrieving cached registrations from $this->checkout->transaction
183
+	 *
184
+	 * @type array
185
+	 */
186
+	public $reg_cache_where_params = array();
187
+
188
+	/**
189
+	 * a class for managing and creating the JSON encoded array of data that gets passed back to the client during AJAX
190
+	 * requests
191
+	 *
192
+	 * @type EE_SPCO_JSON_Response
193
+	 */
194
+	public $json_response;
195
+
196
+	/**
197
+	 * where we are going next in the reg process
198
+	 *
199
+	 * @type EE_SPCO_Reg_Step
200
+	 */
201
+	public $next_step;
202
+
203
+	/**
204
+	 * where we are in the reg process
205
+	 *
206
+	 * @type EE_SPCO_Reg_Step
207
+	 */
208
+	public $current_step;
209
+
210
+	/**
211
+	 *    $_cart - the current cart object
212
+	 *
213
+	 * @var EE_CART
214
+	 */
215
+	public $cart;
216
+
217
+	/**
218
+	 *    $_transaction - the current transaction object
219
+	 *
220
+	 * @var EE_Transaction
221
+	 */
222
+	public $transaction;
223
+
224
+	/**
225
+	 *    the related attendee object for the primary registrant
226
+	 *
227
+	 * @type EE_Attendee
228
+	 */
229
+	public $primary_attendee_obj;
230
+
231
+	/**
232
+	 *    $payment_method - the payment method object for the selected method of payment
233
+	 *
234
+	 * @type EE_Payment_Method
235
+	 */
236
+	public $payment_method;
237
+
238
+	/**
239
+	 *    $payment - if a payment was successfully made during the reg process,
240
+	 *    then here it is !!!
241
+	 *
242
+	 * @type EE_Payment
243
+	 */
244
+	public $payment;
245
+
246
+	/**
247
+	 *    if a payment method was selected that uses an on-site gateway, then this is the billing form
248
+	 *
249
+	 * @type EE_Billing_Info_Form | EE_Billing_Attendee_Info_Form
250
+	 */
251
+	public $billing_form;
252
+
253
+	/**
254
+	 *    the entire registration form composed of ALL of the subsections generated by the various reg steps
255
+	 *
256
+	 * @type EE_Form_Section_Proper
257
+	 */
258
+	public $registration_form;
259
+
260
+	/**
261
+	 * array of EE_SPCO_Reg_Step objects
262
+	 *
263
+	 * @type EE_SPCO_Reg_Step[]
264
+	 */
265
+	public $reg_steps = array();
266
+
267
+	/**
268
+	 * array of EE_Payment_Method objects
269
+	 *
270
+	 * @type EE_Payment_Method[]
271
+	 */
272
+	public $available_payment_methods = array();
273
+
274
+
275
+	/**
276
+	 *    class constructor
277
+	 *
278
+	 * @access    public
279
+	 */
280
+	public function __construct()
281
+	{
282
+		$this->reg_page_base_url = EE_Registry::instance()->CFG->core->reg_page_url();
283
+		$this->thank_you_page_url = EE_Registry::instance()->CFG->core->thank_you_page_url();
284
+		$this->cancel_page_url = EE_Registry::instance()->CFG->core->cancel_page_url();
285
+		$this->continue_reg = apply_filters('FHEE__EE_Checkout___construct___continue_reg', true);
286
+
287
+		$this->admin_request = is_admin() && ! EED_Single_Page_Checkout::getRequest()->isAjax();
288
+		$this->reg_cache_where_params = array(
289
+			0          => array('REG_deleted' => false),
290
+			'order_by' => array('REG_count' => 'ASC'),
291
+		);
292
+	}
293
+
294
+
295
+	/**
296
+	 * returns true if ANY reg status was updated during checkout
297
+	 *
298
+	 * @return boolean
299
+	 */
300
+	public function any_reg_status_updated()
301
+	{
302
+		foreach ($this->reg_status_updated as $reg_status) {
303
+			if ($reg_status) {
304
+				return true;
305
+			}
306
+		}
307
+		return false;
308
+	}
309
+
310
+
311
+	/**
312
+	 * @param $REG_ID
313
+	 * @return boolean
314
+	 */
315
+	public function reg_status_updated($REG_ID)
316
+	{
317
+		return isset($this->reg_status_updated[ $REG_ID ]) ? $this->reg_status_updated[ $REG_ID ] : false;
318
+	}
319
+
320
+
321
+	/**
322
+	 * @param $REG_ID
323
+	 * @param $reg_status
324
+	 */
325
+	public function set_reg_status_updated($REG_ID, $reg_status)
326
+	{
327
+		$this->reg_status_updated[ $REG_ID ] = filter_var($reg_status, FILTER_VALIDATE_BOOLEAN);
328
+	}
329
+
330
+
331
+	/**
332
+	 * exit_spco
333
+	 *
334
+	 * @return bool
335
+	 */
336
+	public function exit_spco()
337
+	{
338
+		return $this->exit_spco;
339
+	}
340
+
341
+
342
+	/**
343
+	 * set_exit_spco
344
+	 * can ONLY be set by the  Finalize_Registration reg step
345
+	 */
346
+	public function set_exit_spco()
347
+	{
348
+		if ($this->current_step instanceof EE_SPCO_Reg_Step_Finalize_Registration) {
349
+			$this->exit_spco = true;
350
+		}
351
+	}
352
+
353
+
354
+	/**
355
+	 *    reset_for_current_request
356
+	 *
357
+	 * @access    public
358
+	 * @return    void
359
+	 */
360
+	public function reset_for_current_request()
361
+	{
362
+		$this->process_form_submission = false;
363
+		$this->continue_reg = apply_filters('FHEE__EE_Checkout___construct___continue_reg', true);
364
+		$this->admin_request = is_admin() && ! EED_Single_Page_Checkout::getRequest()->isFrontAjax();
365
+		$this->continue_reg = true;
366
+		$this->redirect = false;
367
+		// don't reset the cached redirect form if we're about to be asked to display it !!!
368
+		$action = EED_Single_Page_Checkout::getRequest()->getRequestParam('action', 'display_spco_reg_step');
369
+		if ($action !== 'redirect_form') {
370
+			$this->redirect_form = '';
371
+		}
372
+		$this->redirect_url = '';
373
+		$this->json_response = new EE_SPCO_JSON_Response();
374
+		EE_Form_Section_Proper::reset_js_localization();
375
+	}
376
+
377
+
378
+	/**
379
+	 *    add_reg_step
380
+	 *
381
+	 * @access    public
382
+	 * @param EE_SPCO_Reg_Step $reg_step_obj
383
+	 * @return    void
384
+	 */
385
+	public function add_reg_step(EE_SPCO_Reg_Step $reg_step_obj)
386
+	{
387
+		$this->reg_steps[ $reg_step_obj->slug() ] = $reg_step_obj;
388
+	}
389
+
390
+
391
+	/**
392
+	 * skip_reg_step
393
+	 * if the current reg step does not need to run for some reason,
394
+	 * then this will advance SPCO to the next reg step,
395
+	 * and mark the skipped step as completed
396
+	 *
397
+	 * @access    public
398
+	 * @param string $reg_step_slug
399
+	 * @return    void
400
+	 * @throws \EE_Error
401
+	 */
402
+	public function skip_reg_step($reg_step_slug = '')
403
+	{
404
+		$step_to_skip = $this->find_reg_step($reg_step_slug);
405
+		if ($step_to_skip instanceof EE_SPCO_Reg_Step && $step_to_skip->is_current_step()) {
406
+			$step_to_skip->set_is_current_step(false);
407
+			$step_to_skip->set_completed();
408
+			// advance to the next step
409
+			$this->set_current_step($this->next_step->slug());
410
+			// also reset the step param in the request in case any other code references that directly
411
+			EED_Single_Page_Checkout::getRequest()->setRequestParam('step', $this->current_step->slug());
412
+			// since we are skipping a step and setting the current step to be what was previously the next step,
413
+			// we need to check that the next step is now correct, and not still set to the current step.
414
+			if ($this->current_step->slug() === $this->next_step->slug()) {
415
+				// correctly setup the next step
416
+				$this->set_next_step();
417
+			}
418
+			$this->set_reg_step_initiated($this->current_step);
419
+		}
420
+	}
421
+
422
+
423
+	/**
424
+	 *    remove_reg_step
425
+	 *
426
+	 * @access    public
427
+	 * @param string $reg_step_slug
428
+	 * @param bool   $reset whether to reset reg steps after removal
429
+	 * @throws EE_Error
430
+	 */
431
+	public function remove_reg_step($reg_step_slug = '', $reset = true)
432
+	{
433
+		unset($this->reg_steps[ $reg_step_slug ]);
434
+		if ($this->transaction instanceof EE_Transaction) {
435
+			// now remove reg step from TXN and save
436
+			$this->transaction->remove_reg_step($reg_step_slug);
437
+			$this->transaction->save();
438
+		}
439
+		if ($reset) {
440
+			$this->reset_reg_steps();
441
+		}
442
+	}
443
+
444
+
445
+	/**
446
+	 *    set_reg_step_order
447
+	 *
448
+	 * @access    public
449
+	 * @param string $reg_step_slug
450
+	 * @param int    $order
451
+	 * @return    void
452
+	 */
453
+	public function set_reg_step_order($reg_step_slug = '', $order = 100)
454
+	{
455
+		if (isset($this->reg_steps[ $reg_step_slug ])) {
456
+			$this->reg_steps[ $reg_step_slug ]->set_order($order);
457
+		}
458
+	}
459
+
460
+
461
+	/**
462
+	 *    set_current_step
463
+	 *
464
+	 * @access    public
465
+	 * @param string $current_step
466
+	 * @return    void
467
+	 */
468
+	public function set_current_step($current_step)
469
+	{
470
+		// grab what step we're on
471
+		$this->current_step = isset($this->reg_steps[ $current_step ])
472
+			? $this->reg_steps[ $current_step ]
473
+			: reset(
474
+				$this->reg_steps
475
+			);
476
+		// verify instance
477
+		if ($this->current_step instanceof EE_SPCO_Reg_Step) {
478
+			// we don't want to repeat completed steps if this is the first time through SPCO
479
+			if ($this->continue_reg && ! $this->revisit && $this->current_step->completed()) {
480
+				// so advance to the next step
481
+				$this->set_next_step();
482
+				if ($this->next_step instanceof EE_SPCO_Reg_Step) {
483
+					// and attempt to set it as the current step
484
+					$this->set_current_step($this->next_step->slug());
485
+				}
486
+				return;
487
+			}
488
+			$this->current_step->set_is_current_step(true);
489
+		} else {
490
+			EE_Error::add_error(
491
+				__('The current step could not be set.', 'event_espresso'),
492
+				__FILE__,
493
+				__FUNCTION__,
494
+				__LINE__
495
+			);
496
+		}
497
+	}
498
+
499
+
500
+	/**
501
+	 *    set_next_step
502
+	 * advances the reg_steps array pointer and sets the next step, then reverses pointer back to the current step
503
+	 *
504
+	 * @access    public
505
+	 * @return    void
506
+	 */
507
+	public function set_next_step()
508
+	{
509
+		// set pointer to start of array
510
+		reset($this->reg_steps);
511
+		// if there is more than one step
512
+		if (count($this->reg_steps) > 1) {
513
+			// advance to the current step and set pointer
514
+			while (key($this->reg_steps) !== $this->current_step->slug() && key($this->reg_steps) !== '') {
515
+				next($this->reg_steps);
516
+			}
517
+		}
518
+		// advance one more spot ( if it exists )
519
+		$this->next_step = next($this->reg_steps);
520
+		// verify instance
521
+		$this->next_step = $this->next_step instanceof EE_SPCO_Reg_Step ? $this->next_step : null;
522
+		// then back to current step to reset
523
+		prev($this->reg_steps);
524
+	}
525
+
526
+
527
+	/**
528
+	 *    get_next_reg_step
529
+	 *    this simply returns the next step from reg_steps array
530
+	 *
531
+	 * @access    public
532
+	 * @return    EE_SPCO_Reg_Step | null
533
+	 */
534
+	public function get_next_reg_step()
535
+	{
536
+		$next = next($this->reg_steps);
537
+		prev($this->reg_steps);
538
+		return $next instanceof EE_SPCO_Reg_Step ? $next : null;
539
+	}
540
+
541
+
542
+	/**
543
+	 * get_prev_reg_step
544
+	 *    this simply returns the previous step from reg_steps array
545
+	 *
546
+	 * @access    public
547
+	 * @return    EE_SPCO_Reg_Step | null
548
+	 */
549
+	public function get_prev_reg_step()
550
+	{
551
+		$prev = prev($this->reg_steps);
552
+		next($this->reg_steps);
553
+		return $prev instanceof EE_SPCO_Reg_Step ? $prev : null;
554
+	}
555
+
556
+
557
+	/**
558
+	 * sort_reg_steps
559
+	 *
560
+	 * @access public
561
+	 * @return void
562
+	 */
563
+	public function sort_reg_steps()
564
+	{
565
+		$reg_step_sorting_callback = apply_filters(
566
+			'FHEE__EE_Checkout__sort_reg_steps__reg_step_sorting_callback',
567
+			'reg_step_sorting_callback'
568
+		);
569
+		uasort($this->reg_steps, array($this, $reg_step_sorting_callback));
570
+	}
571
+
572
+
573
+	/**
574
+	 * find_reg_step
575
+	 * finds a reg step by the given slug
576
+	 *
577
+	 * @access    public
578
+	 * @param string $reg_step_slug
579
+	 * @return EE_SPCO_Reg_Step|null
580
+	 */
581
+	public function find_reg_step($reg_step_slug = '')
582
+	{
583
+		if (! empty($reg_step_slug)) {
584
+			// copy reg step array
585
+			$reg_steps = $this->reg_steps;
586
+			// set pointer to start of array
587
+			reset($reg_steps);
588
+			// if there is more than one step
589
+			if (count($reg_steps) > 1) {
590
+				// advance to the current step and set pointer
591
+				while (key($reg_steps) !== $reg_step_slug && key($reg_steps) !== '') {
592
+					next($reg_steps);
593
+				}
594
+				return current($reg_steps);
595
+			}
596
+		}
597
+		return null;
598
+	}
599
+
600
+
601
+	/**
602
+	 * reg_step_sorting_callback
603
+	 *
604
+	 * @access public
605
+	 * @param EE_SPCO_Reg_Step $reg_step_A
606
+	 * @param EE_SPCO_Reg_Step $reg_step_B
607
+	 * @return int
608
+	 */
609
+	public function reg_step_sorting_callback(EE_SPCO_Reg_Step $reg_step_A, EE_SPCO_Reg_Step $reg_step_B)
610
+	{
611
+		// send finalize_registration step to the end of the array
612
+		if ($reg_step_A->slug() === 'finalize_registration') {
613
+			return 1;
614
+		} elseif ($reg_step_B->slug() === 'finalize_registration') {
615
+			return -1;
616
+		}
617
+		if ($reg_step_A->order() === $reg_step_B->order()) {
618
+			return 0;
619
+		}
620
+		return ($reg_step_A->order() > $reg_step_B->order()) ? 1 : -1;
621
+	}
622
+
623
+
624
+	/**
625
+	 * set_reg_step_initiated
626
+	 *
627
+	 * @access    public
628
+	 * @param    EE_SPCO_Reg_Step $reg_step
629
+	 * @throws \EE_Error
630
+	 */
631
+	public function set_reg_step_initiated(EE_SPCO_Reg_Step $reg_step)
632
+	{
633
+		// call set_reg_step_initiated ???
634
+		if (// first time visiting SPCO ?
635
+			! $this->revisit
636
+			&& (
637
+				// and displaying the reg step form for the first time ?
638
+				$this->action === 'display_spco_reg_step'
639
+				// or initializing the final step
640
+				|| $reg_step instanceof EE_SPCO_Reg_Step_Finalize_Registration
641
+			)
642
+		) {
643
+			// set the start time for this reg step
644
+			if (! $this->transaction->set_reg_step_initiated($reg_step->slug())) {
645
+				if (WP_DEBUG) {
646
+					EE_Error::add_error(
647
+						sprintf(
648
+							__('The "%1$s" registration step was not initialized properly.', 'event_espresso'),
649
+							$reg_step->name()
650
+						),
651
+						__FILE__,
652
+						__FUNCTION__,
653
+						__LINE__
654
+					);
655
+				}
656
+			}
657
+		}
658
+	}
659
+
660
+
661
+	/**
662
+	 *    set_reg_step_JSON_info
663
+	 *
664
+	 * @access public
665
+	 * @return    void
666
+	 */
667
+	public function set_reg_step_JSON_info()
668
+	{
669
+		EE_Registry::$i18n_js_strings['reg_steps'] = array();
670
+		// pass basic reg step data to JS
671
+		foreach ($this->reg_steps as $reg_step) {
672
+			EE_Registry::$i18n_js_strings['reg_steps'][] = $reg_step->slug();
673
+		}
674
+		// reset reg step html
675
+		// $this->json_response->set_reg_step_html('');
676
+	}
677
+
678
+
679
+	/**
680
+	 *    reset_reg_steps
681
+	 *
682
+	 * @access public
683
+	 * @return void
684
+	 */
685
+	public function reset_reg_steps()
686
+	{
687
+		$this->sort_reg_steps();
688
+		$this->set_current_step(EED_Single_Page_Checkout::getRequest()->getRequestParam('step'));
689
+		$this->set_next_step();
690
+		// the text that appears on the reg step form submit button
691
+		$this->current_step->set_submit_button_text();
692
+		$this->set_reg_step_JSON_info();
693
+	}
694
+
695
+
696
+	/**
697
+	 *    get_registration_time_limit
698
+	 *
699
+	 * @access    public
700
+	 * @return        string
701
+	 */
702
+	public function get_registration_time_limit()
703
+	{
704
+
705
+		$registration_time_limit = (float) (EE_Registry::instance()->SSN->expiration() - time());
706
+		$time_limit_format = $registration_time_limit > 60 * MINUTE_IN_SECONDS ? 'H:i:s' : 'i:s';
707
+		$registration_time_limit = date($time_limit_format, $registration_time_limit);
708
+		return apply_filters(
709
+			'FHEE__EE_Checkout__get_registration_time_limit__registration_time_limit',
710
+			$registration_time_limit
711
+		);
712
+	}
713
+
714
+
715
+	/**
716
+	 * payment_required
717
+	 *
718
+	 * @return boolean
719
+	 */
720
+	public function payment_required()
721
+	{
722
+		// if NOT:
723
+		//     registration via admin
724
+		//      completed TXN
725
+		//      overpaid TXN
726
+		//      free TXN(total = 0.00)
727
+		//      then payment required is TRUE
728
+		return ! ($this->admin_request
729
+				  || $this->transaction->is_completed()
730
+				  || $this->transaction->is_overpaid()
731
+				  || $this->transaction->is_free()) ? true : false;
732
+	}
733
+
734
+
735
+	/**
736
+	 * get_cart_for_transaction
737
+	 *
738
+	 * @access public
739
+	 * @param EE_Transaction $transaction
740
+	 * @return EE_Cart
741
+	 */
742
+	public function get_cart_for_transaction($transaction)
743
+	{
744
+		$session = EE_Registry::instance()->load_core('Session');
745
+		$cart = $transaction instanceof EE_Transaction ? EE_Cart::get_cart_from_txn($transaction, $session) : null;
746
+		// verify cart
747
+		if (! $cart instanceof EE_Cart) {
748
+			$cart = EE_Registry::instance()->load_core('Cart');
749
+		}
750
+
751
+		return $cart;
752
+	}
753
+
754
+
755
+	/**
756
+	 *    initialize_txn_reg_steps_array
757
+	 *
758
+	 * @access public
759
+	 * @return    array
760
+	 */
761
+	public function initialize_txn_reg_steps_array()
762
+	{
763
+		$txn_reg_steps_array = array();
764
+		foreach ($this->reg_steps as $reg_step) {
765
+			$txn_reg_steps_array[ $reg_step->slug() ] = false;
766
+		}
767
+		return $txn_reg_steps_array;
768
+	}
769
+
770
+
771
+	/**
772
+	 *    update_txn_reg_steps_array
773
+	 *
774
+	 * @access public
775
+	 * @return    bool
776
+	 * @throws \EE_Error
777
+	 */
778
+	public function update_txn_reg_steps_array()
779
+	{
780
+		$updated = false;
781
+		foreach ($this->reg_steps as $reg_step) {
782
+			if ($reg_step->completed()) {
783
+				$updated = $this->transaction->set_reg_step_completed($reg_step->slug())
784
+					? true
785
+					: $updated;
786
+			}
787
+		}
788
+		if ($updated) {
789
+			$this->transaction->save();
790
+		}
791
+		return $updated;
792
+	}
793
+
794
+
795
+	/**
796
+	 *    stash_transaction_and_checkout
797
+	 *
798
+	 * @access public
799
+	 * @return    void
800
+	 * @throws \EE_Error
801
+	 */
802
+	public function stash_transaction_and_checkout()
803
+	{
804
+		if (! $this->revisit) {
805
+			$this->update_txn_reg_steps_array();
806
+		}
807
+		$this->track_transaction_and_registration_status_updates();
808
+		// save all data to the db, but suppress errors
809
+		// $this->save_all_data( FALSE );
810
+		// cache the checkout in the session
811
+		EE_Registry::instance()->SSN->set_checkout($this);
812
+	}
813
+
814
+
815
+	/**
816
+	 *    track_transaction_and_registration_status_updates
817
+	 *    stores whether any updates were made to the TXN or it's related registrations
818
+	 *
819
+	 * @access public
820
+	 * @return void
821
+	 * @throws \EE_Error
822
+	 */
823
+	public function track_transaction_and_registration_status_updates()
824
+	{
825
+		// verify the transaction
826
+		if ($this->transaction instanceof EE_Transaction) {
827
+			// has there been a TXN status change during this checkout?
828
+			$this->txn_status_updated = $this->transaction->txn_status_updated();
829
+			/** @type EE_Registration_Processor $registration_processor */
830
+			$registration_processor = EE_Registry::instance()->load_class('Registration_Processor');
831
+			// grab the saved registrations from the transaction
832
+			foreach ($this->transaction->registrations($this->reg_cache_where_params) as $registration) {
833
+				if ($registration_processor->reg_status_updated($registration->ID())) {
834
+					$this->set_reg_status_updated($registration->ID(), true);
835
+				}
836
+			}
837
+		}
838
+	}
839
+
840
+
841
+	/**
842
+	 *    visit_allows_processing_of_this_registration
843
+	 *    determines if the current SPCO visit should allow the passed EE_Registration to be used in processing.
844
+	 *    one of the following conditions must be met:
845
+	 *        EITHER:    A) first time thru SPCO -> process ALL registrations ( NOT a revisit )
846
+	 *        OR :        B) primary registrant is editing info -> process ALL registrations ( primary_revisit )
847
+	 *        OR :        C) another registrant is editing info -> ONLY process their registration ( revisit AND their
848
+	 *        reg_url_link matches )
849
+	 *
850
+	 * @access public
851
+	 * @param    EE_Registration $registration
852
+	 * @return    bool
853
+	 * @throws \EE_Error
854
+	 */
855
+	public function visit_allows_processing_of_this_registration(EE_Registration $registration)
856
+	{
857
+		return ! $this->revisit
858
+			   || $this->primary_revisit
859
+			   || (
860
+				   $this->revisit && $this->reg_url_link === $registration->reg_url_link()
861
+			   )
862
+			? true
863
+			: false;
864
+	}
865
+
866
+
867
+	/**
868
+	 *    _transaction_has_primary_registration
869
+	 *
870
+	 * @access        private
871
+	 * @return        bool
872
+	 */
873
+	public function transaction_has_primary_registrant()
874
+	{
875
+		return $this->primary_attendee_obj instanceof EE_Attendee ? true : false;
876
+	}
877
+
878
+
879
+	/**
880
+	 *    save_all_data
881
+	 *    simply loops through the current transaction and saves all data for each registration
882
+	 *
883
+	 * @access public
884
+	 * @param bool $show_errors
885
+	 * @return bool
886
+	 * @throws \EE_Error
887
+	 */
888
+	public function save_all_data($show_errors = true)
889
+	{
890
+		// verify the transaction
891
+		if ($this->transaction instanceof EE_Transaction) {
892
+			// save to ensure that TXN has ID
893
+			$this->transaction->save();
894
+			// grab the saved registrations from the transaction
895
+			foreach ($this->transaction->registrations($this->reg_cache_where_params) as $registration) {
896
+				$this->_save_registration($registration, $show_errors);
897
+			}
898
+		} else {
899
+			if ($show_errors) {
900
+				EE_Error::add_error(
901
+					__(
902
+						'A valid Transaction was not found when attempting to save your registration information.',
903
+						'event_espresso'
904
+					),
905
+					__FILE__,
906
+					__FUNCTION__,
907
+					__LINE__
908
+				);
909
+			}
910
+			return false;
911
+		}
912
+		return true;
913
+	}
914
+
915
+
916
+	/**
917
+	 * _save_registration_attendee
918
+	 *
919
+	 * @param    EE_Registration $registration
920
+	 * @param bool               $show_errors
921
+	 * @return void
922
+	 * @throws \EE_Error
923
+	 */
924
+	private function _save_registration($registration, $show_errors = true)
925
+	{
926
+		// verify object
927
+		if ($registration instanceof EE_Registration) {
928
+			// should this registration be processed during this visit ?
929
+			if ($this->visit_allows_processing_of_this_registration($registration)) {
930
+				// set TXN ID
931
+				if (! $registration->transaction_ID()) {
932
+					$registration->set_transaction_id($this->transaction->ID());
933
+				}
934
+				// verify and save the attendee
935
+				$this->_save_registration_attendee($registration, $show_errors);
936
+				// save answers to reg form questions
937
+				$this->_save_registration_answers($registration, $show_errors);
938
+				// save changes
939
+				$registration->save();
940
+				// update txn cache
941
+				if (! $this->transaction->update_cache_after_object_save('Registration', $registration)) {
942
+					if ($show_errors) {
943
+						EE_Error::add_error(
944
+							__(
945
+								'The newly saved Registration object could not be cached on the Transaction.',
946
+								'event_espresso'
947
+							),
948
+							__FILE__,
949
+							__FUNCTION__,
950
+							__LINE__
951
+						);
952
+					}
953
+				}
954
+			}
955
+		} else {
956
+			if ($show_errors) {
957
+				EE_Error::add_error(
958
+					__(
959
+						'An invalid Registration object was discovered when attempting to save your registration information.',
960
+						'event_espresso'
961
+					),
962
+					__FILE__,
963
+					__FUNCTION__,
964
+					__LINE__
965
+				);
966
+			}
967
+		}
968
+	}
969
+
970
+
971
+	/**
972
+	 * _save_registration_attendee
973
+	 *
974
+	 * @param    EE_Registration $registration
975
+	 * @param bool               $show_errors
976
+	 * @return void
977
+	 * @throws \EE_Error
978
+	 */
979
+	private function _save_registration_attendee($registration, $show_errors = true)
980
+	{
981
+		if ($registration->attendee() instanceof EE_Attendee) {
982
+			// save so that ATT has ID
983
+			$registration->attendee()->save();
984
+			if (! $registration->update_cache_after_object_save('Attendee', $registration->attendee())) {
985
+				if ($show_errors) {
986
+					EE_Error::add_error(
987
+						__(
988
+							'The newly saved Attendee object could not be cached on the registration.',
989
+							'event_espresso'
990
+						),
991
+						__FILE__,
992
+						__FUNCTION__,
993
+						__LINE__
994
+					);
995
+				}
996
+			}
997
+		} else {
998
+			if ($show_errors) {
999
+				EE_Error::add_error(
1000
+					sprintf(
1001
+						'%1$s||%1$s $attendee = %2$s',
1002
+						__(
1003
+							'Either no Attendee information was found, or an invalid Attendee object was discovered when attempting to save your registration information.',
1004
+							'event_espresso'
1005
+						),
1006
+						var_export($registration->attendee(), true)
1007
+					),
1008
+					__FILE__,
1009
+					__FUNCTION__,
1010
+					__LINE__
1011
+				);
1012
+			}
1013
+		}
1014
+	}
1015
+
1016
+
1017
+	/**
1018
+	 * _save_question_answers
1019
+	 *
1020
+	 * @param    EE_Registration $registration
1021
+	 * @param bool               $show_errors
1022
+	 * @return void
1023
+	 * @throws \EE_Error
1024
+	 */
1025
+	private function _save_registration_answers($registration, $show_errors = true)
1026
+	{
1027
+		// now save the answers
1028
+		foreach ($registration->answers() as $cache_key => $answer) {
1029
+			// verify object
1030
+			if ($answer instanceof EE_Answer) {
1031
+				$answer->set_registration($registration->ID());
1032
+				$answer->save();
1033
+				if (! $registration->update_cache_after_object_save('Answer', $answer, $cache_key)) {
1034
+					if ($show_errors) {
1035
+						EE_Error::add_error(
1036
+							__(
1037
+								'The newly saved Answer object could not be cached on the registration.',
1038
+								'event_espresso'
1039
+							),
1040
+							__FILE__,
1041
+							__FUNCTION__,
1042
+							__LINE__
1043
+						);
1044
+					}
1045
+				}
1046
+			} else {
1047
+				if ($show_errors) {
1048
+					EE_Error::add_error(
1049
+						__(
1050
+							'An invalid Answer object was discovered when attempting to save your registration information.',
1051
+							'event_espresso'
1052
+						),
1053
+						__FILE__,
1054
+						__FUNCTION__,
1055
+						__LINE__
1056
+					);
1057
+				}
1058
+			}
1059
+		}
1060
+	}
1061
+
1062
+
1063
+	/**
1064
+	 *    refresh_all_entities
1065
+	 *   will either refresh the entity map with objects form the db or from the checkout cache
1066
+	 *
1067
+	 * @access public
1068
+	 * @param bool $from_db
1069
+	 * @return bool
1070
+	 * @throws \EE_Error
1071
+	 */
1072
+	public function refresh_all_entities($from_db = false)
1073
+	{
1074
+		$from_db = $this->current_step->is_final_step() || $this->action === 'process_gateway_response'
1075
+			? true
1076
+			: $from_db;
1077
+		// $this->log(
1078
+		//     __CLASS__,
1079
+		//     __FUNCTION__,
1080
+		//     __LINE__,
1081
+		//     array('from_db' => $from_db)
1082
+		// );
1083
+		return $from_db ? $this->refresh_from_db() : $this->refresh_entity_map();
1084
+	}
1085
+
1086
+
1087
+	/**
1088
+	 *  refresh_entity_map
1089
+	 *  simply loops through the current transaction and updates each
1090
+	 *  model's entity map using EEM_Base::refresh_entity_map_from_db()
1091
+	 *
1092
+	 * @access public
1093
+	 * @return bool
1094
+	 * @throws \EE_Error
1095
+	 */
1096
+	protected function refresh_from_db()
1097
+	{
1098
+		// verify the transaction
1099
+		if ($this->transaction instanceof EE_Transaction && $this->transaction->ID()) {
1100
+			// pull fresh TXN data from the db
1101
+			$this->transaction = $this->transaction->get_model()->refresh_entity_map_from_db($this->transaction->ID());
1102
+			// update EE_Checkout's cached primary_attendee object
1103
+			$this->primary_attendee_obj = $this->_refresh_primary_attendee_obj_from_db($this->transaction);
1104
+			// update EE_Checkout's cached payment object
1105
+			$payment = $this->transaction->last_payment();
1106
+			$this->payment = $payment instanceof EE_Payment ? $payment : $this->payment;
1107
+			// update EE_Checkout's cached payment_method object
1108
+			$payment_method = $this->payment instanceof EE_Payment ? $this->payment->payment_method() : null;
1109
+			$this->payment_method = $payment_method instanceof EE_Payment_Method ? $payment_method
1110
+				: $this->payment_method;
1111
+			// now refresh the cart, based on the TXN
1112
+			$this->cart = $this->get_cart_for_transaction($this->transaction);
1113
+		} else {
1114
+			EE_Error::add_error(
1115
+				__(
1116
+					'A valid Transaction was not found when attempting to update the model entity mapper.',
1117
+					'event_espresso'
1118
+				),
1119
+				__FILE__,
1120
+				__FUNCTION__,
1121
+				__LINE__
1122
+			);
1123
+			return false;
1124
+		}
1125
+		return true;
1126
+	}
1127
+
1128
+
1129
+	/**
1130
+	 * _refresh_primary_attendee_obj_from_db
1131
+	 *
1132
+	 * @param   EE_Transaction $transaction
1133
+	 * @return  EE_Attendee | null
1134
+	 * @throws \EE_Error
1135
+	 */
1136
+	protected function _refresh_primary_attendee_obj_from_db(EE_Transaction $transaction)
1137
+	{
1138
+
1139
+		$primary_attendee_obj = null;
1140
+		// grab the saved registrations from the transaction
1141
+		foreach ($transaction->registrations($this->reg_cache_where_params, true) as $registration) {
1142
+			// verify object
1143
+			if ($registration instanceof EE_Registration) {
1144
+				$attendee = $registration->attendee();
1145
+				// verify object && maybe cache primary_attendee_obj ?
1146
+				if ($attendee instanceof EE_Attendee && $registration->is_primary_registrant()) {
1147
+					$primary_attendee_obj = $attendee;
1148
+				}
1149
+			} else {
1150
+				EE_Error::add_error(
1151
+					__(
1152
+						'An invalid Registration object was discovered when attempting to update the model entity mapper.',
1153
+						'event_espresso'
1154
+					),
1155
+					__FILE__,
1156
+					__FUNCTION__,
1157
+					__LINE__
1158
+				);
1159
+			}
1160
+		}
1161
+		return $primary_attendee_obj;
1162
+	}
1163
+
1164
+
1165
+	/**
1166
+	 *  refresh_entity_map
1167
+	 *  simply loops through the current transaction and updates
1168
+	 *  each model's entity map using EEM_Base::refresh_entity_map_with()
1169
+	 *
1170
+	 * @access public
1171
+	 * @return bool
1172
+	 * @throws \EE_Error
1173
+	 */
1174
+	protected function refresh_entity_map()
1175
+	{
1176
+		// verify the transaction
1177
+		if ($this->transaction instanceof EE_Transaction && $this->transaction->ID()) {
1178
+			// never cache payment info
1179
+			$this->transaction->clear_cache('Payment');
1180
+			// is the Payment Options Reg Step completed ?
1181
+			if ($this->transaction->reg_step_completed('payment_options')) {
1182
+				// then check for payments and update TXN accordingly
1183
+				/** @type EE_Transaction_Payments $transaction_payments */
1184
+				$transaction_payments = EE_Registry::instance()->load_class('Transaction_Payments');
1185
+				$transaction_payments->calculate_total_payments_and_update_status($this->transaction);
1186
+			}
1187
+			// grab the saved registrations from the transaction
1188
+			foreach ($this->transaction->registrations($this->reg_cache_where_params) as $reg_cache_ID => $registration) {
1189
+				$this->_refresh_registration($reg_cache_ID, $registration);
1190
+			}
1191
+			// make sure our cached TXN is added to the model entity mapper
1192
+			$this->transaction = $this->transaction->get_model()->refresh_entity_map_with(
1193
+				$this->transaction->ID(),
1194
+				$this->transaction
1195
+			);
1196
+		} else {
1197
+			EE_Error::add_error(
1198
+				__(
1199
+					'A valid Transaction was not found when attempting to update the model entity mapper.',
1200
+					'event_espresso'
1201
+				),
1202
+				__FILE__,
1203
+				__FUNCTION__,
1204
+				__LINE__
1205
+			);
1206
+			return false;
1207
+		}
1208
+		// verify and update the cart because inaccurate totals are not so much fun
1209
+		if ($this->cart instanceof EE_Cart) {
1210
+			$grand_total = $this->cart->get_grand_total();
1211
+			if ($grand_total instanceof EE_Line_Item && $grand_total->ID()) {
1212
+				$grand_total->recalculate_total_including_taxes();
1213
+				$grand_total = $grand_total->get_model()->refresh_entity_map_with(
1214
+					$this->cart->get_grand_total()->ID(),
1215
+					$this->cart->get_grand_total()
1216
+				);
1217
+			}
1218
+			if ($grand_total instanceof EE_Line_Item) {
1219
+				$this->cart = EE_Cart::instance($grand_total);
1220
+			} else {
1221
+				EE_Error::add_error(
1222
+					__(
1223
+						'A valid Cart was not found when attempting to update the model entity mapper.',
1224
+						'event_espresso'
1225
+					),
1226
+					__FILE__,
1227
+					__FUNCTION__,
1228
+					__LINE__
1229
+				);
1230
+				return false;
1231
+			}
1232
+		}
1233
+		return true;
1234
+	}
1235
+
1236
+
1237
+	/**
1238
+	 * _refresh_registration
1239
+	 *
1240
+	 * @param    string | int    $reg_cache_ID
1241
+	 * @param    EE_Registration $registration
1242
+	 * @return void
1243
+	 * @throws \EE_Error
1244
+	 */
1245
+	protected function _refresh_registration($reg_cache_ID, $registration)
1246
+	{
1247
+
1248
+		// verify object
1249
+		if ($registration instanceof EE_Registration) {
1250
+			// update the entity mapper attendee
1251
+			$this->_refresh_registration_attendee($registration);
1252
+			// update the entity mapper answers for reg form questions
1253
+			$this->_refresh_registration_answers($registration);
1254
+			// make sure the cached registration is added to the model entity mapper
1255
+			$registration->get_model()->refresh_entity_map_with($reg_cache_ID, $registration);
1256
+		} else {
1257
+			EE_Error::add_error(
1258
+				__(
1259
+					'An invalid Registration object was discovered when attempting to update the model entity mapper.',
1260
+					'event_espresso'
1261
+				),
1262
+				__FILE__,
1263
+				__FUNCTION__,
1264
+				__LINE__
1265
+			);
1266
+		}
1267
+	}
1268
+
1269
+
1270
+	/**
1271
+	 * _save_registration_attendee
1272
+	 *
1273
+	 * @param    EE_Registration $registration
1274
+	 * @return void
1275
+	 * @throws \EE_Error
1276
+	 */
1277
+	protected function _refresh_registration_attendee($registration)
1278
+	{
1279
+
1280
+		$attendee = $registration->attendee();
1281
+		// verify object
1282
+		if ($attendee instanceof EE_Attendee && $attendee->ID()) {
1283
+			// make sure the cached attendee is added to the model entity mapper
1284
+			$registration->attendee()->get_model()->refresh_entity_map_with($attendee->ID(), $attendee);
1285
+			// maybe cache primary_attendee_obj ?
1286
+			if ($registration->is_primary_registrant()) {
1287
+				$this->primary_attendee_obj = $attendee;
1288
+			}
1289
+		}
1290
+	}
1291
+
1292
+
1293
+	/**
1294
+	 * _refresh_registration_answers
1295
+	 *
1296
+	 * @param    EE_Registration $registration
1297
+	 * @return void
1298
+	 * @throws \EE_Error
1299
+	 */
1300
+	protected function _refresh_registration_answers($registration)
1301
+	{
1302
+
1303
+		// now update the answers
1304
+		foreach ($registration->answers() as $cache_key => $answer) {
1305
+			// verify object
1306
+			if ($answer instanceof EE_Answer) {
1307
+				if ($answer->ID()) {
1308
+					// make sure the cached answer is added to the model entity mapper
1309
+					$answer->get_model()->refresh_entity_map_with($answer->ID(), $answer);
1310
+				}
1311
+			} else {
1312
+				EE_Error::add_error(
1313
+					__(
1314
+						'An invalid Answer object was discovered when attempting to update the model entity mapper.',
1315
+						'event_espresso'
1316
+					),
1317
+					__FILE__,
1318
+					__FUNCTION__,
1319
+					__LINE__
1320
+				);
1321
+			}
1322
+		}
1323
+	}
1324
+
1325
+
1326
+	/**
1327
+	 *    __sleep
1328
+	 * to conserve db space, let's remove the reg_form and the EE_Checkout object from EE_SPCO_Reg_Step objects upon
1329
+	 * serialization EE_Checkout will handle the reimplementation of itself upon waking, but we won't bother with the
1330
+	 * reg form, because if needed, it will be regenerated anyways
1331
+	 *
1332
+	 * @return array
1333
+	 * @throws \EE_Error
1334
+	 */
1335
+	public function __sleep()
1336
+	{
1337
+		if ($this->primary_attendee_obj instanceof EE_Attendee && $this->primary_attendee_obj->ID()) {
1338
+			$this->primary_attendee_obj = $this->primary_attendee_obj->ID();
1339
+		}        // remove the reg form and the checkout
1340
+		if ($this->transaction instanceof EE_Transaction && $this->transaction->ID()) {
1341
+			$this->transaction = $this->transaction->ID();
1342
+		}        // remove the reg form and the checkout
1343
+		return array_diff(array_keys(get_object_vars($this)), array('billing_form', 'registration_form'));
1344
+	}
1345
+
1346
+
1347
+	/**
1348
+	 *    __wakeup
1349
+	 * to conserve db space, we are removing the EE_Checkout object from EE_SPCO_Reg_Step objects upon serialization
1350
+	 * this will reinstate the EE_Checkout object on each EE_SPCO_Reg_Step object
1351
+	 */
1352
+	public function __wakeup()
1353
+	{
1354
+		if (! $this->primary_attendee_obj instanceof EE_Attendee && absint($this->primary_attendee_obj) !== 0) {
1355
+			// $this->primary_attendee_obj is actually just an ID, so use it to get the object from the db
1356
+			$this->primary_attendee_obj = EEM_Attendee::instance()->get_one_by_ID($this->primary_attendee_obj);
1357
+		}
1358
+		if (! $this->transaction instanceof EE_Transaction && absint($this->transaction) !== 0) {
1359
+			// $this->transaction is actually just an ID, so use it to get the object from the db
1360
+			$this->transaction = EEM_Transaction::instance()->get_one_by_ID($this->transaction);
1361
+		}
1362
+		foreach ($this->reg_steps as $reg_step) {
1363
+			$reg_step->checkout = $this;
1364
+		}
1365
+	}
1366
+
1367
+
1368
+	/**
1369
+	 * debug
1370
+	 *
1371
+	 * @param string $class
1372
+	 * @param string $func
1373
+	 * @param string $line
1374
+	 * @param array  $info
1375
+	 * @param bool   $display_request
1376
+	 * @throws \EE_Error
1377
+	 */
1378
+	public function log($class = '', $func = '', $line = '', $info = array(), $display_request = false)
1379
+	{
1380
+		$disabled = true;
1381
+		if (WP_DEBUG && ! $disabled) {
1382
+			$debug_data = get_option('EE_DEBUG_SPCO_' . EE_Session::instance()->id(), array());
1383
+			$default_data = array(
1384
+				$class                    => $func . '() : ' . $line,
1385
+				'request->step'           => $this->step,
1386
+				'request->action'         => $this->action,
1387
+				'current_step->slug'      => $this->current_step instanceof EE_SPCO_Reg_Step ?
1388
+					$this->current_step->slug() : '',
1389
+				'current_step->completed' => $this->current_step instanceof EE_SPCO_Reg_Step ?
1390
+					$this->current_step->completed() : '',
1391
+				'txn_status_updated'      => $this->transaction->txn_status_updated(),
1392
+				'reg_status_updated'      => $this->reg_status_updated,
1393
+				'reg_url_link'            => $this->reg_url_link,
1394
+			);
1395
+			if ($this->transaction instanceof EE_Transaction) {
1396
+				$default_data['TXN_status'] = $this->transaction->status_ID();
1397
+				$default_data['TXN_reg_steps'] = $this->transaction->reg_steps();
1398
+				foreach ($this->transaction->registrations($this->reg_cache_where_params) as $REG_ID => $registration) {
1399
+					$default_data['registrations'][ $REG_ID ] = $registration->status_ID();
1400
+				}
1401
+				if ($this->transaction->ID()) {
1402
+					$TXN_ID = 'EE_Transaction: ' . $this->transaction->ID();
1403
+					// don't serialize objects
1404
+					$info = $this->_strip_objects($info);
1405
+					if (! isset($debug_data[ $TXN_ID ])) {
1406
+						$debug_data[ $TXN_ID ] = array();
1407
+					}
1408
+					$debug_data[ $TXN_ID ][ microtime() ] = array_merge(
1409
+						$default_data,
1410
+						$info
1411
+					);
1412
+					update_option('EE_DEBUG_SPCO_' . EE_Session::instance()->id(), $debug_data);
1413
+				}
1414
+			}
1415
+		}
1416
+	}
1417
+
1418
+
1419
+	/**
1420
+	 * _strip_objects
1421
+	 *
1422
+	 * @param array $info
1423
+	 * @return array
1424
+	 */
1425
+	public function _strip_objects($info = array())
1426
+	{
1427
+		foreach ((array) $info as $key => $value) {
1428
+			if (is_array($value)) {
1429
+				$info[ $key ] = $this->_strip_objects($value);
1430
+			} elseif (is_object($value)) {
1431
+				$object_class = get_class($value);
1432
+				$info[ $object_class ] = array();
1433
+				$info[ $object_class ]['ID'] = method_exists($value, 'ID') ? $value->ID() : 0;
1434
+				if (method_exists($value, 'status')) {
1435
+					$info[ $object_class ]['status'] = $value->status();
1436
+				} elseif (method_exists($value, 'status_ID')) {
1437
+					$info[ $object_class ]['status'] = $value->status_ID();
1438
+				}
1439
+				unset($info[ $key ]);
1440
+			}
1441
+		}
1442
+		return (array) $info;
1443
+	}
1444 1444
 }
Please login to merge, or discard this patch.
modules/single_page_checkout/inc/EE_SPCO_Reg_Step.class.php 2 patches
Indentation   +635 added lines, -635 removed lines patch added patch discarded remove patch
@@ -14,639 +14,639 @@
 block discarded – undo
14 14
 abstract class EE_SPCO_Reg_Step
15 15
 {
16 16
 
17
-    /**
18
-     *    $_completed - TRUE if this step has fully completed it's duties
19
-     *
20
-     * @access protected
21
-     * @type bool $_completed
22
-     */
23
-    protected $_completed = false;
24
-
25
-    /**
26
-     *    $_is_current_step - TRUE if this is the current step
27
-     *
28
-     * @access protected
29
-     * @type bool $_is_current_step
30
-     */
31
-    protected $_is_current_step = false;
32
-
33
-    /**
34
-     *    $_order - when the reg step should be run relative to other steps
35
-     *
36
-     * @access protected
37
-     * @type int $_template
38
-     */
39
-    protected $_order = 0;
40
-
41
-    /**
42
-     *    $_slug - URL param for this step
43
-     *
44
-     * @access protected
45
-     * @type string $_slug
46
-     */
47
-    protected $_slug;
48
-
49
-    /**
50
-     *    $_name - Step Name - translatable string
51
-     *
52
-     * @access protected
53
-     * @type string $_slug
54
-     */
55
-    protected $_name;
56
-
57
-    /**
58
-     *    $_submit_button_text - translatable string that appears on this step's submit button
59
-     *
60
-     * @access protected
61
-     * @type string $_slug
62
-     */
63
-    protected $_submit_button_text;
64
-
65
-    /**
66
-     *    $_template - template name
67
-     *
68
-     * @access protected
69
-     * @type string $_template
70
-     */
71
-    protected $_template;
72
-
73
-    /**
74
-     *    $_reg_form_name - the form input name and id attribute
75
-     *
76
-     * @access protected
77
-     * @var string $_reg_form_name
78
-     */
79
-    protected $_reg_form_name;
80
-
81
-    /**
82
-     *    $_success_message - text to display upon successful form submission
83
-     *
84
-     * @access private
85
-     * @var string $_success_message
86
-     */
87
-    protected $_success_message;
88
-
89
-    /**
90
-     *    $_instructions - a brief description of how to complete the reg step.
91
-     *    Usually displayed in conjunction with the previous step's success message.
92
-     *
93
-     * @access private
94
-     * @var string $_instructions
95
-     */
96
-    protected $_instructions;
97
-
98
-    /**
99
-     *    $_valid_data - the normalized and validated data for this step
100
-     *
101
-     * @access public
102
-     * @var array $_valid_data
103
-     */
104
-    protected $_valid_data = [];
105
-
106
-    /**
107
-     *    $reg_form - the registration form for this step
108
-     *
109
-     * @access public
110
-     * @var EE_Form_Section_Proper $reg_form
111
-     */
112
-    public $reg_form;
113
-
114
-    /**
115
-     *    $checkout - EE_Checkout object for handling the properties of the current checkout process
116
-     *
117
-     * @access public
118
-     * @var EE_Checkout $checkout
119
-     */
120
-    public $checkout;
121
-
122
-    /**
123
-     * @var RequestInterface $request
124
-     */
125
-    protected $request;
126
-
127
-
128
-    /**
129
-     * @return void
130
-     */
131
-    abstract public function translate_js_strings();
132
-
133
-
134
-    /**
135
-     * @return void
136
-     */
137
-    abstract public function enqueue_styles_and_scripts();
138
-
139
-
140
-    /**
141
-     * @return boolean
142
-     */
143
-    abstract public function initialize_reg_step();
144
-
145
-
146
-    /**
147
-     * @return string
148
-     */
149
-    abstract public function generate_reg_form();
150
-
151
-
152
-    /**
153
-     * @return boolean
154
-     */
155
-    abstract public function process_reg_step();
156
-
157
-
158
-    /**
159
-     * @return boolean
160
-     */
161
-    abstract public function update_reg_step();
162
-
163
-
164
-    /**
165
-     * @return boolean
166
-     */
167
-    public function completed()
168
-    {
169
-        return $this->_completed;
170
-    }
171
-
172
-
173
-    /**
174
-     * set_completed - toggles $_completed to TRUE
175
-     */
176
-    public function set_completed()
177
-    {
178
-        // DEBUG LOG
179
-        // $this->checkout->log( __CLASS__, __FUNCTION__, __LINE__ );
180
-        $this->_completed = apply_filters('FHEE__EE_SPCO_Reg_Step__set_completed___completed', true, $this);
181
-    }
182
-
183
-
184
-    /**
185
-     * set_completed - toggles $_completed to FALSE
186
-     */
187
-    public function set_not_completed()
188
-    {
189
-        $this->_completed = false;
190
-    }
191
-
192
-
193
-    /**
194
-     * @return string
195
-     */
196
-    public function name()
197
-    {
198
-        return $this->_name;
199
-    }
200
-
201
-
202
-    /**
203
-     * @return string
204
-     */
205
-    public function slug()
206
-    {
207
-        return $this->_slug;
208
-    }
209
-
210
-
211
-    /**
212
-     * submit_button_text
213
-     * the text that appears on the reg step form submit button
214
-     *
215
-     * @return string
216
-     */
217
-    public function submit_button_text()
218
-    {
219
-        return $this->_submit_button_text;
220
-    }
221
-
222
-
223
-    /**
224
-     * set_submit_button_text
225
-     * sets the text that appears on the reg step form submit button
226
-     *
227
-     * @param string $submit_button_text
228
-     */
229
-    public function set_submit_button_text($submit_button_text = '')
230
-    {
231
-        if (! empty($submit_button_text)) {
232
-            $this->_submit_button_text = $submit_button_text;
233
-        } elseif ($this->checkout->next_step instanceof EE_SPCO_Reg_Step) {
234
-            if ($this->checkout->revisit) {
235
-                $this->_submit_button_text = sprintf(
236
-                    __('Update %s', 'event_espresso'),
237
-                    $this->checkout->current_step->name()
238
-                );
239
-            } else {
240
-                $this->_submit_button_text = sprintf(
241
-                    __('Proceed to %s', 'event_espresso'),
242
-                    $this->checkout->next_step->name()
243
-                );
244
-            }
245
-        }
246
-        // filters the submit button text
247
-        $this->_submit_button_text = apply_filters(
248
-            'FHEE__EE_SPCO_Reg_Step__set_submit_button_text___submit_button_text',
249
-            $this->_submit_button_text,
250
-            $this->checkout
251
-        );
252
-    }
253
-
254
-
255
-    /**
256
-     * @param boolean $is_current_step
257
-     */
258
-    public function set_is_current_step($is_current_step)
259
-    {
260
-        $this->_is_current_step = $is_current_step;
261
-    }
262
-
263
-
264
-    /**
265
-     * @return boolean
266
-     */
267
-    public function is_current_step()
268
-    {
269
-        return $this->_is_current_step;
270
-    }
271
-
272
-
273
-    /**
274
-     * @return boolean
275
-     */
276
-    public function is_final_step()
277
-    {
278
-        return $this instanceof EE_SPCO_Reg_Step_Finalize_Registration;
279
-    }
280
-
281
-
282
-    /**
283
-     * @param int $order
284
-     */
285
-    public function set_order($order)
286
-    {
287
-        $this->_order = $order;
288
-    }
289
-
290
-
291
-    /**
292
-     * @return int
293
-     */
294
-    public function order()
295
-    {
296
-        return $this->_order;
297
-    }
298
-
299
-
300
-    /**
301
-     * @return string
302
-     */
303
-    public function template()
304
-    {
305
-        return $this->_template;
306
-    }
307
-
308
-
309
-    /**
310
-     * @return string
311
-     */
312
-    public function success_message()
313
-    {
314
-        return $this->_success_message;
315
-    }
316
-
317
-
318
-    /**
319
-     * _set_success_message
320
-     *
321
-     * @param string $success_message
322
-     */
323
-    protected function _set_success_message($success_message)
324
-    {
325
-        $this->_success_message = $success_message;
326
-    }
327
-
328
-
329
-    /**
330
-     * _reset_success_message
331
-     *
332
-     * @return void
333
-     */
334
-    protected function _reset_success_message()
335
-    {
336
-        $this->_success_message = '';
337
-    }
338
-
339
-
340
-    /**
341
-     * @return string
342
-     */
343
-    public function _instructions()
344
-    {
345
-        return $this->_instructions;
346
-    }
347
-
348
-
349
-    /**
350
-     * @param string $instructions
351
-     */
352
-    public function set_instructions($instructions)
353
-    {
354
-        $this->_instructions = apply_filters(
355
-            'FHEE__EE_SPCO_Reg_Step__set_instructions__instructions',
356
-            $instructions,
357
-            $this
358
-        );
359
-    }
360
-
361
-
362
-    /**
363
-     * @param array $valid_data
364
-     */
365
-    public function set_valid_data($valid_data)
366
-    {
367
-        $this->_valid_data = $valid_data;
368
-    }
369
-
370
-
371
-    /**
372
-     * @return array
373
-     * @throws EE_Error
374
-     * @throws EE_Error
375
-     */
376
-    public function valid_data()
377
-    {
378
-        if (empty($this->_valid_data)) {
379
-            $this->_valid_data = $this->reg_form->valid_data();
380
-        }
381
-        return $this->_valid_data;
382
-    }
383
-
384
-
385
-    /**
386
-     * @return string
387
-     */
388
-    public function reg_form_name()
389
-    {
390
-        if (empty($this->_reg_form_name)) {
391
-            $this->set_reg_form_name('ee-spco-' . $this->slug() . '-reg-step-form');
392
-        }
393
-        return $this->_reg_form_name;
394
-    }
395
-
396
-
397
-    /**
398
-     * @param string $reg_form_name
399
-     */
400
-    protected function set_reg_form_name($reg_form_name)
401
-    {
402
-        $this->_reg_form_name = $reg_form_name;
403
-    }
404
-
405
-
406
-    /**
407
-     * reg_step_url
408
-     *
409
-     * @param string $action
410
-     * @return string
411
-     */
412
-    public function reg_step_url($action = '')
413
-    {
414
-        $query_args = ['step' => $this->slug()];
415
-        if (! empty($action)) {
416
-            $query_args['action'] = $action;
417
-        }
418
-        // final step has no display
419
-        if ($this instanceof EE_SPCO_Reg_Step_Finalize_Registration && $action === 'display_spco_reg_step') {
420
-            $query_args['action'] = 'process_reg_step';
421
-        }
422
-        if ($this->checkout->revisit) {
423
-            $query_args['revisit'] = true;
424
-        }
425
-        if ($this->checkout->reg_url_link) {
426
-            $query_args['e_reg_url_link'] = $this->checkout->reg_url_link;
427
-        }
428
-        return add_query_arg($query_args, $this->checkout->reg_page_base_url);
429
-    }
430
-
431
-
432
-    /**
433
-     * creates the default hidden inputs section
434
-     *
435
-     * @return EE_Form_Section_Proper
436
-     * @throws EE_Error
437
-     */
438
-    public function reg_step_hidden_inputs()
439
-    {
440
-        // hidden inputs for admin registrations
441
-        if ($this->checkout->admin_request) {
442
-            return new EE_Form_Section_Proper(
443
-                [
444
-                    'layout_strategy' => new EE_Div_Per_Section_Layout(),
445
-                    'html_id'         => 'ee-' . $this->slug() . '-hidden-inputs',
446
-                    'subsections'     => [
447
-                        'next_step' => new EE_Fixed_Hidden_Input(
448
-                            [
449
-                                'html_name' => 'next_step',
450
-                                'html_id'   => 'spco-' . $this->slug() . '-next-step',
451
-                                'default'   => $this->checkout->next_step instanceof EE_SPCO_Reg_Step
452
-                                    ? $this->checkout->next_step->slug()
453
-                                    : '',
454
-                            ]
455
-                        ),
456
-                    ],
457
-                ]
458
-            );
459
-        }
460
-        // hidden inputs for frontend registrations
461
-        return new EE_Form_Section_Proper(
462
-            [
463
-                'layout_strategy' => new EE_Div_Per_Section_Layout(),
464
-                'html_id'         => 'ee-' . $this->slug() . '-hidden-inputs',
465
-                'subsections'     => [
466
-                    'action'         => new EE_Fixed_Hidden_Input(
467
-                        [
468
-                            'html_name' => 'action',
469
-                            'html_id'   => 'spco-' . $this->slug() . '-action',
470
-                            'default'   => apply_filters(
471
-                                'FHEE__EE_SPCO_Reg_Step__reg_step_hidden_inputs__default_form_action',
472
-                                empty($this->checkout->reg_url_link)
473
-                                    ? 'process_reg_step'
474
-                                    : 'update_reg_step',
475
-                                $this
476
-                            ),
477
-                        ]
478
-                    ),
479
-                    'next_step'      => new EE_Fixed_Hidden_Input(
480
-                        [
481
-                            'html_name' => 'next_step',
482
-                            'html_id'   => 'spco-' . $this->slug() . '-next-step',
483
-                            'default'   => $this->checkout->next_step instanceof EE_SPCO_Reg_Step
484
-                                ? $this->checkout->next_step->slug()
485
-                                : '',
486
-                        ]
487
-                    ),
488
-                    'e_reg_url_link' => new EE_Fixed_Hidden_Input(
489
-                        [
490
-                            'html_name' => 'e_reg_url_link',
491
-                            'html_id'   => 'spco-reg_url_link',
492
-                            'default'   => $this->checkout->reg_url_link,
493
-                        ]
494
-                    ),
495
-                    'revisit'        => new EE_Fixed_Hidden_Input(
496
-                        [
497
-                            'html_name' => 'revisit',
498
-                            'html_id'   => 'spco-revisit',
499
-                            'default'   => $this->checkout->revisit,
500
-                        ]
501
-                    ),
502
-                ],
503
-            ]
504
-        );
505
-    }
506
-
507
-
508
-    /**
509
-     * generate_reg_form_for_actions
510
-     *
511
-     * @param array $actions
512
-     * @return void
513
-     */
514
-    public function generate_reg_form_for_actions($actions = [])
515
-    {
516
-        $actions                           = array_merge(
517
-            [
518
-                'generate_reg_form',
519
-                'display_spco_reg_step',
520
-                'process_reg_step',
521
-                'update_reg_step',
522
-            ],
523
-            $actions
524
-        );
525
-        $this->checkout->generate_reg_form = in_array($this->checkout->action, $actions, true);
526
-    }
527
-
528
-
529
-    /**
530
-     * @return string
531
-     * @throws EE_Error
532
-     */
533
-    public function display_reg_form()
534
-    {
535
-        $html = '';
536
-        if ($this->reg_form instanceof EE_Form_Section_Proper) {
537
-            do_action('AHEE__EE_SPCO_Reg_Step__display_reg_form__reg_form', $this->reg_form, $this);
538
-            $html .= ! $this->checkout->admin_request ? $this->reg_form->form_open($this->reg_step_url()) : '';
539
-            if ($this->request->isAjax()) {
540
-                $this->reg_form->localize_validation_rules();
541
-                $this->checkout->json_response->add_validation_rules(EE_Form_Section_Proper::js_localization());
542
-            }
543
-            $html .= $this->reg_form->get_html();
544
-            $html .= ! $this->checkout->admin_request ? $this->reg_step_submit_button() : '';
545
-            $html .= ! $this->checkout->admin_request ? $this->reg_form->form_close() : '';
546
-        }
547
-        return $html;
548
-    }
549
-
550
-
551
-    /**
552
-     * div_class - returns nothing for current step, but a css class of "hidden" for others
553
-     *
554
-     * @return string
555
-     * @throws EE_Error
556
-     */
557
-    public function reg_step_submit_button()
558
-    {
559
-        if (! $this->checkout->next_step instanceof EE_SPCO_Reg_Step) {
560
-            return '';
561
-        }
562
-        ob_start();
563
-        do_action(
564
-            'AHEE__before_spco_whats_next_buttons',
565
-            $this->slug(),
566
-            $this->checkout->next_step->slug(),
567
-            $this->checkout
568
-        );
569
-        $html = ob_get_clean();
570
-        // generate submit button
571
-        $submit_btn = new EE_Submit_Input(
572
-            [
573
-                'html_name'             => 'spco-go-to-step-' . $this->checkout->next_step->slug(),
574
-                'html_id'               => 'spco-go-to-step-' . $this->checkout->next_step->slug(),
575
-                'html_class'            => 'spco-next-step-btn',
576
-                'other_html_attributes' => ' rel="' . $this->slug() . '"',
577
-                'default'               => $this->submit_button_text(),
578
-            ]
579
-        );
580
-        $submit_btn->set_button_css_attributes(true, 'large');
581
-        $submit_btn_html = $submit_btn->get_html_for_input();
582
-        $html            .= EEH_HTML::div(
583
-            apply_filters('FHEE__EE_SPCO_Reg_Step__reg_step_submit_button__sbmt_btn_html', $submit_btn_html, $this),
584
-            'spco-' . $this->slug() . '-whats-next-buttons-dv',
585
-            'spco-whats-next-buttons'
586
-        );
587
-        return $html;
588
-    }
589
-
590
-
591
-    /**
592
-     * div_class - returns nothing for current step, but a css class of "hidden" for others
593
-     *
594
-     * @return string
595
-     */
596
-    public function div_class()
597
-    {
598
-        return $this->is_current_step() ? '' : ' hidden';
599
-    }
600
-
601
-
602
-    /**
603
-     * div_class - returns  a css class of "hidden" for current step, but nothing for others
604
-     *
605
-     * @return string
606
-     */
607
-    public function edit_lnk_url()
608
-    {
609
-        return add_query_arg(['step' => $this->slug()], $this->checkout->reg_page_base_url);
610
-    }
611
-
612
-
613
-    /**
614
-     * div_class - returns  a css class of "hidden" for current step, but nothing for others
615
-     *
616
-     * @return string
617
-     */
618
-    public function edit_link_class()
619
-    {
620
-        return $this->is_current_step() ? ' hidden' : '';
621
-    }
622
-
623
-
624
-    /**
625
-     * update_checkout with changes that have been made to the cart
626
-     *
627
-     * @return void
628
-     * @throws EE_Error
629
-     * @throws ReflectionException
630
-     */
631
-    public function update_checkout()
632
-    {
633
-        // grab the cart grand total and reset TXN total
634
-        $this->checkout->transaction->set_total($this->checkout->cart->get_cart_grand_total());
635
-        $this->checkout->stash_transaction_and_checkout();
636
-    }
637
-
638
-
639
-    /**
640
-     *    __sleep
641
-     * to conserve db space, let's remove the reg_form and the EE_Checkout object from EE_SPCO_Reg_Step objects upon
642
-     * serialization EE_Checkout will handle the reimplementation of itself upon waking, but we won't bother with the
643
-     * reg form, because if needed, it will be regenerated anyways
644
-     *
645
-     * @return array
646
-     */
647
-    public function __sleep()
648
-    {
649
-        // remove the reg form and the checkout
650
-        return array_diff(array_keys(get_object_vars($this)), ['reg_form', 'checkout']);
651
-    }
17
+	/**
18
+	 *    $_completed - TRUE if this step has fully completed it's duties
19
+	 *
20
+	 * @access protected
21
+	 * @type bool $_completed
22
+	 */
23
+	protected $_completed = false;
24
+
25
+	/**
26
+	 *    $_is_current_step - TRUE if this is the current step
27
+	 *
28
+	 * @access protected
29
+	 * @type bool $_is_current_step
30
+	 */
31
+	protected $_is_current_step = false;
32
+
33
+	/**
34
+	 *    $_order - when the reg step should be run relative to other steps
35
+	 *
36
+	 * @access protected
37
+	 * @type int $_template
38
+	 */
39
+	protected $_order = 0;
40
+
41
+	/**
42
+	 *    $_slug - URL param for this step
43
+	 *
44
+	 * @access protected
45
+	 * @type string $_slug
46
+	 */
47
+	protected $_slug;
48
+
49
+	/**
50
+	 *    $_name - Step Name - translatable string
51
+	 *
52
+	 * @access protected
53
+	 * @type string $_slug
54
+	 */
55
+	protected $_name;
56
+
57
+	/**
58
+	 *    $_submit_button_text - translatable string that appears on this step's submit button
59
+	 *
60
+	 * @access protected
61
+	 * @type string $_slug
62
+	 */
63
+	protected $_submit_button_text;
64
+
65
+	/**
66
+	 *    $_template - template name
67
+	 *
68
+	 * @access protected
69
+	 * @type string $_template
70
+	 */
71
+	protected $_template;
72
+
73
+	/**
74
+	 *    $_reg_form_name - the form input name and id attribute
75
+	 *
76
+	 * @access protected
77
+	 * @var string $_reg_form_name
78
+	 */
79
+	protected $_reg_form_name;
80
+
81
+	/**
82
+	 *    $_success_message - text to display upon successful form submission
83
+	 *
84
+	 * @access private
85
+	 * @var string $_success_message
86
+	 */
87
+	protected $_success_message;
88
+
89
+	/**
90
+	 *    $_instructions - a brief description of how to complete the reg step.
91
+	 *    Usually displayed in conjunction with the previous step's success message.
92
+	 *
93
+	 * @access private
94
+	 * @var string $_instructions
95
+	 */
96
+	protected $_instructions;
97
+
98
+	/**
99
+	 *    $_valid_data - the normalized and validated data for this step
100
+	 *
101
+	 * @access public
102
+	 * @var array $_valid_data
103
+	 */
104
+	protected $_valid_data = [];
105
+
106
+	/**
107
+	 *    $reg_form - the registration form for this step
108
+	 *
109
+	 * @access public
110
+	 * @var EE_Form_Section_Proper $reg_form
111
+	 */
112
+	public $reg_form;
113
+
114
+	/**
115
+	 *    $checkout - EE_Checkout object for handling the properties of the current checkout process
116
+	 *
117
+	 * @access public
118
+	 * @var EE_Checkout $checkout
119
+	 */
120
+	public $checkout;
121
+
122
+	/**
123
+	 * @var RequestInterface $request
124
+	 */
125
+	protected $request;
126
+
127
+
128
+	/**
129
+	 * @return void
130
+	 */
131
+	abstract public function translate_js_strings();
132
+
133
+
134
+	/**
135
+	 * @return void
136
+	 */
137
+	abstract public function enqueue_styles_and_scripts();
138
+
139
+
140
+	/**
141
+	 * @return boolean
142
+	 */
143
+	abstract public function initialize_reg_step();
144
+
145
+
146
+	/**
147
+	 * @return string
148
+	 */
149
+	abstract public function generate_reg_form();
150
+
151
+
152
+	/**
153
+	 * @return boolean
154
+	 */
155
+	abstract public function process_reg_step();
156
+
157
+
158
+	/**
159
+	 * @return boolean
160
+	 */
161
+	abstract public function update_reg_step();
162
+
163
+
164
+	/**
165
+	 * @return boolean
166
+	 */
167
+	public function completed()
168
+	{
169
+		return $this->_completed;
170
+	}
171
+
172
+
173
+	/**
174
+	 * set_completed - toggles $_completed to TRUE
175
+	 */
176
+	public function set_completed()
177
+	{
178
+		// DEBUG LOG
179
+		// $this->checkout->log( __CLASS__, __FUNCTION__, __LINE__ );
180
+		$this->_completed = apply_filters('FHEE__EE_SPCO_Reg_Step__set_completed___completed', true, $this);
181
+	}
182
+
183
+
184
+	/**
185
+	 * set_completed - toggles $_completed to FALSE
186
+	 */
187
+	public function set_not_completed()
188
+	{
189
+		$this->_completed = false;
190
+	}
191
+
192
+
193
+	/**
194
+	 * @return string
195
+	 */
196
+	public function name()
197
+	{
198
+		return $this->_name;
199
+	}
200
+
201
+
202
+	/**
203
+	 * @return string
204
+	 */
205
+	public function slug()
206
+	{
207
+		return $this->_slug;
208
+	}
209
+
210
+
211
+	/**
212
+	 * submit_button_text
213
+	 * the text that appears on the reg step form submit button
214
+	 *
215
+	 * @return string
216
+	 */
217
+	public function submit_button_text()
218
+	{
219
+		return $this->_submit_button_text;
220
+	}
221
+
222
+
223
+	/**
224
+	 * set_submit_button_text
225
+	 * sets the text that appears on the reg step form submit button
226
+	 *
227
+	 * @param string $submit_button_text
228
+	 */
229
+	public function set_submit_button_text($submit_button_text = '')
230
+	{
231
+		if (! empty($submit_button_text)) {
232
+			$this->_submit_button_text = $submit_button_text;
233
+		} elseif ($this->checkout->next_step instanceof EE_SPCO_Reg_Step) {
234
+			if ($this->checkout->revisit) {
235
+				$this->_submit_button_text = sprintf(
236
+					__('Update %s', 'event_espresso'),
237
+					$this->checkout->current_step->name()
238
+				);
239
+			} else {
240
+				$this->_submit_button_text = sprintf(
241
+					__('Proceed to %s', 'event_espresso'),
242
+					$this->checkout->next_step->name()
243
+				);
244
+			}
245
+		}
246
+		// filters the submit button text
247
+		$this->_submit_button_text = apply_filters(
248
+			'FHEE__EE_SPCO_Reg_Step__set_submit_button_text___submit_button_text',
249
+			$this->_submit_button_text,
250
+			$this->checkout
251
+		);
252
+	}
253
+
254
+
255
+	/**
256
+	 * @param boolean $is_current_step
257
+	 */
258
+	public function set_is_current_step($is_current_step)
259
+	{
260
+		$this->_is_current_step = $is_current_step;
261
+	}
262
+
263
+
264
+	/**
265
+	 * @return boolean
266
+	 */
267
+	public function is_current_step()
268
+	{
269
+		return $this->_is_current_step;
270
+	}
271
+
272
+
273
+	/**
274
+	 * @return boolean
275
+	 */
276
+	public function is_final_step()
277
+	{
278
+		return $this instanceof EE_SPCO_Reg_Step_Finalize_Registration;
279
+	}
280
+
281
+
282
+	/**
283
+	 * @param int $order
284
+	 */
285
+	public function set_order($order)
286
+	{
287
+		$this->_order = $order;
288
+	}
289
+
290
+
291
+	/**
292
+	 * @return int
293
+	 */
294
+	public function order()
295
+	{
296
+		return $this->_order;
297
+	}
298
+
299
+
300
+	/**
301
+	 * @return string
302
+	 */
303
+	public function template()
304
+	{
305
+		return $this->_template;
306
+	}
307
+
308
+
309
+	/**
310
+	 * @return string
311
+	 */
312
+	public function success_message()
313
+	{
314
+		return $this->_success_message;
315
+	}
316
+
317
+
318
+	/**
319
+	 * _set_success_message
320
+	 *
321
+	 * @param string $success_message
322
+	 */
323
+	protected function _set_success_message($success_message)
324
+	{
325
+		$this->_success_message = $success_message;
326
+	}
327
+
328
+
329
+	/**
330
+	 * _reset_success_message
331
+	 *
332
+	 * @return void
333
+	 */
334
+	protected function _reset_success_message()
335
+	{
336
+		$this->_success_message = '';
337
+	}
338
+
339
+
340
+	/**
341
+	 * @return string
342
+	 */
343
+	public function _instructions()
344
+	{
345
+		return $this->_instructions;
346
+	}
347
+
348
+
349
+	/**
350
+	 * @param string $instructions
351
+	 */
352
+	public function set_instructions($instructions)
353
+	{
354
+		$this->_instructions = apply_filters(
355
+			'FHEE__EE_SPCO_Reg_Step__set_instructions__instructions',
356
+			$instructions,
357
+			$this
358
+		);
359
+	}
360
+
361
+
362
+	/**
363
+	 * @param array $valid_data
364
+	 */
365
+	public function set_valid_data($valid_data)
366
+	{
367
+		$this->_valid_data = $valid_data;
368
+	}
369
+
370
+
371
+	/**
372
+	 * @return array
373
+	 * @throws EE_Error
374
+	 * @throws EE_Error
375
+	 */
376
+	public function valid_data()
377
+	{
378
+		if (empty($this->_valid_data)) {
379
+			$this->_valid_data = $this->reg_form->valid_data();
380
+		}
381
+		return $this->_valid_data;
382
+	}
383
+
384
+
385
+	/**
386
+	 * @return string
387
+	 */
388
+	public function reg_form_name()
389
+	{
390
+		if (empty($this->_reg_form_name)) {
391
+			$this->set_reg_form_name('ee-spco-' . $this->slug() . '-reg-step-form');
392
+		}
393
+		return $this->_reg_form_name;
394
+	}
395
+
396
+
397
+	/**
398
+	 * @param string $reg_form_name
399
+	 */
400
+	protected function set_reg_form_name($reg_form_name)
401
+	{
402
+		$this->_reg_form_name = $reg_form_name;
403
+	}
404
+
405
+
406
+	/**
407
+	 * reg_step_url
408
+	 *
409
+	 * @param string $action
410
+	 * @return string
411
+	 */
412
+	public function reg_step_url($action = '')
413
+	{
414
+		$query_args = ['step' => $this->slug()];
415
+		if (! empty($action)) {
416
+			$query_args['action'] = $action;
417
+		}
418
+		// final step has no display
419
+		if ($this instanceof EE_SPCO_Reg_Step_Finalize_Registration && $action === 'display_spco_reg_step') {
420
+			$query_args['action'] = 'process_reg_step';
421
+		}
422
+		if ($this->checkout->revisit) {
423
+			$query_args['revisit'] = true;
424
+		}
425
+		if ($this->checkout->reg_url_link) {
426
+			$query_args['e_reg_url_link'] = $this->checkout->reg_url_link;
427
+		}
428
+		return add_query_arg($query_args, $this->checkout->reg_page_base_url);
429
+	}
430
+
431
+
432
+	/**
433
+	 * creates the default hidden inputs section
434
+	 *
435
+	 * @return EE_Form_Section_Proper
436
+	 * @throws EE_Error
437
+	 */
438
+	public function reg_step_hidden_inputs()
439
+	{
440
+		// hidden inputs for admin registrations
441
+		if ($this->checkout->admin_request) {
442
+			return new EE_Form_Section_Proper(
443
+				[
444
+					'layout_strategy' => new EE_Div_Per_Section_Layout(),
445
+					'html_id'         => 'ee-' . $this->slug() . '-hidden-inputs',
446
+					'subsections'     => [
447
+						'next_step' => new EE_Fixed_Hidden_Input(
448
+							[
449
+								'html_name' => 'next_step',
450
+								'html_id'   => 'spco-' . $this->slug() . '-next-step',
451
+								'default'   => $this->checkout->next_step instanceof EE_SPCO_Reg_Step
452
+									? $this->checkout->next_step->slug()
453
+									: '',
454
+							]
455
+						),
456
+					],
457
+				]
458
+			);
459
+		}
460
+		// hidden inputs for frontend registrations
461
+		return new EE_Form_Section_Proper(
462
+			[
463
+				'layout_strategy' => new EE_Div_Per_Section_Layout(),
464
+				'html_id'         => 'ee-' . $this->slug() . '-hidden-inputs',
465
+				'subsections'     => [
466
+					'action'         => new EE_Fixed_Hidden_Input(
467
+						[
468
+							'html_name' => 'action',
469
+							'html_id'   => 'spco-' . $this->slug() . '-action',
470
+							'default'   => apply_filters(
471
+								'FHEE__EE_SPCO_Reg_Step__reg_step_hidden_inputs__default_form_action',
472
+								empty($this->checkout->reg_url_link)
473
+									? 'process_reg_step'
474
+									: 'update_reg_step',
475
+								$this
476
+							),
477
+						]
478
+					),
479
+					'next_step'      => new EE_Fixed_Hidden_Input(
480
+						[
481
+							'html_name' => 'next_step',
482
+							'html_id'   => 'spco-' . $this->slug() . '-next-step',
483
+							'default'   => $this->checkout->next_step instanceof EE_SPCO_Reg_Step
484
+								? $this->checkout->next_step->slug()
485
+								: '',
486
+						]
487
+					),
488
+					'e_reg_url_link' => new EE_Fixed_Hidden_Input(
489
+						[
490
+							'html_name' => 'e_reg_url_link',
491
+							'html_id'   => 'spco-reg_url_link',
492
+							'default'   => $this->checkout->reg_url_link,
493
+						]
494
+					),
495
+					'revisit'        => new EE_Fixed_Hidden_Input(
496
+						[
497
+							'html_name' => 'revisit',
498
+							'html_id'   => 'spco-revisit',
499
+							'default'   => $this->checkout->revisit,
500
+						]
501
+					),
502
+				],
503
+			]
504
+		);
505
+	}
506
+
507
+
508
+	/**
509
+	 * generate_reg_form_for_actions
510
+	 *
511
+	 * @param array $actions
512
+	 * @return void
513
+	 */
514
+	public function generate_reg_form_for_actions($actions = [])
515
+	{
516
+		$actions                           = array_merge(
517
+			[
518
+				'generate_reg_form',
519
+				'display_spco_reg_step',
520
+				'process_reg_step',
521
+				'update_reg_step',
522
+			],
523
+			$actions
524
+		);
525
+		$this->checkout->generate_reg_form = in_array($this->checkout->action, $actions, true);
526
+	}
527
+
528
+
529
+	/**
530
+	 * @return string
531
+	 * @throws EE_Error
532
+	 */
533
+	public function display_reg_form()
534
+	{
535
+		$html = '';
536
+		if ($this->reg_form instanceof EE_Form_Section_Proper) {
537
+			do_action('AHEE__EE_SPCO_Reg_Step__display_reg_form__reg_form', $this->reg_form, $this);
538
+			$html .= ! $this->checkout->admin_request ? $this->reg_form->form_open($this->reg_step_url()) : '';
539
+			if ($this->request->isAjax()) {
540
+				$this->reg_form->localize_validation_rules();
541
+				$this->checkout->json_response->add_validation_rules(EE_Form_Section_Proper::js_localization());
542
+			}
543
+			$html .= $this->reg_form->get_html();
544
+			$html .= ! $this->checkout->admin_request ? $this->reg_step_submit_button() : '';
545
+			$html .= ! $this->checkout->admin_request ? $this->reg_form->form_close() : '';
546
+		}
547
+		return $html;
548
+	}
549
+
550
+
551
+	/**
552
+	 * div_class - returns nothing for current step, but a css class of "hidden" for others
553
+	 *
554
+	 * @return string
555
+	 * @throws EE_Error
556
+	 */
557
+	public function reg_step_submit_button()
558
+	{
559
+		if (! $this->checkout->next_step instanceof EE_SPCO_Reg_Step) {
560
+			return '';
561
+		}
562
+		ob_start();
563
+		do_action(
564
+			'AHEE__before_spco_whats_next_buttons',
565
+			$this->slug(),
566
+			$this->checkout->next_step->slug(),
567
+			$this->checkout
568
+		);
569
+		$html = ob_get_clean();
570
+		// generate submit button
571
+		$submit_btn = new EE_Submit_Input(
572
+			[
573
+				'html_name'             => 'spco-go-to-step-' . $this->checkout->next_step->slug(),
574
+				'html_id'               => 'spco-go-to-step-' . $this->checkout->next_step->slug(),
575
+				'html_class'            => 'spco-next-step-btn',
576
+				'other_html_attributes' => ' rel="' . $this->slug() . '"',
577
+				'default'               => $this->submit_button_text(),
578
+			]
579
+		);
580
+		$submit_btn->set_button_css_attributes(true, 'large');
581
+		$submit_btn_html = $submit_btn->get_html_for_input();
582
+		$html            .= EEH_HTML::div(
583
+			apply_filters('FHEE__EE_SPCO_Reg_Step__reg_step_submit_button__sbmt_btn_html', $submit_btn_html, $this),
584
+			'spco-' . $this->slug() . '-whats-next-buttons-dv',
585
+			'spco-whats-next-buttons'
586
+		);
587
+		return $html;
588
+	}
589
+
590
+
591
+	/**
592
+	 * div_class - returns nothing for current step, but a css class of "hidden" for others
593
+	 *
594
+	 * @return string
595
+	 */
596
+	public function div_class()
597
+	{
598
+		return $this->is_current_step() ? '' : ' hidden';
599
+	}
600
+
601
+
602
+	/**
603
+	 * div_class - returns  a css class of "hidden" for current step, but nothing for others
604
+	 *
605
+	 * @return string
606
+	 */
607
+	public function edit_lnk_url()
608
+	{
609
+		return add_query_arg(['step' => $this->slug()], $this->checkout->reg_page_base_url);
610
+	}
611
+
612
+
613
+	/**
614
+	 * div_class - returns  a css class of "hidden" for current step, but nothing for others
615
+	 *
616
+	 * @return string
617
+	 */
618
+	public function edit_link_class()
619
+	{
620
+		return $this->is_current_step() ? ' hidden' : '';
621
+	}
622
+
623
+
624
+	/**
625
+	 * update_checkout with changes that have been made to the cart
626
+	 *
627
+	 * @return void
628
+	 * @throws EE_Error
629
+	 * @throws ReflectionException
630
+	 */
631
+	public function update_checkout()
632
+	{
633
+		// grab the cart grand total and reset TXN total
634
+		$this->checkout->transaction->set_total($this->checkout->cart->get_cart_grand_total());
635
+		$this->checkout->stash_transaction_and_checkout();
636
+	}
637
+
638
+
639
+	/**
640
+	 *    __sleep
641
+	 * to conserve db space, let's remove the reg_form and the EE_Checkout object from EE_SPCO_Reg_Step objects upon
642
+	 * serialization EE_Checkout will handle the reimplementation of itself upon waking, but we won't bother with the
643
+	 * reg form, because if needed, it will be regenerated anyways
644
+	 *
645
+	 * @return array
646
+	 */
647
+	public function __sleep()
648
+	{
649
+		// remove the reg form and the checkout
650
+		return array_diff(array_keys(get_object_vars($this)), ['reg_form', 'checkout']);
651
+	}
652 652
 }
Please login to merge, or discard this patch.
Spacing   +15 added lines, -15 removed lines patch added patch discarded remove patch
@@ -228,7 +228,7 @@  discard block
 block discarded – undo
228 228
      */
229 229
     public function set_submit_button_text($submit_button_text = '')
230 230
     {
231
-        if (! empty($submit_button_text)) {
231
+        if ( ! empty($submit_button_text)) {
232 232
             $this->_submit_button_text = $submit_button_text;
233 233
         } elseif ($this->checkout->next_step instanceof EE_SPCO_Reg_Step) {
234 234
             if ($this->checkout->revisit) {
@@ -388,7 +388,7 @@  discard block
 block discarded – undo
388 388
     public function reg_form_name()
389 389
     {
390 390
         if (empty($this->_reg_form_name)) {
391
-            $this->set_reg_form_name('ee-spco-' . $this->slug() . '-reg-step-form');
391
+            $this->set_reg_form_name('ee-spco-'.$this->slug().'-reg-step-form');
392 392
         }
393 393
         return $this->_reg_form_name;
394 394
     }
@@ -412,7 +412,7 @@  discard block
 block discarded – undo
412 412
     public function reg_step_url($action = '')
413 413
     {
414 414
         $query_args = ['step' => $this->slug()];
415
-        if (! empty($action)) {
415
+        if ( ! empty($action)) {
416 416
             $query_args['action'] = $action;
417 417
         }
418 418
         // final step has no display
@@ -442,12 +442,12 @@  discard block
 block discarded – undo
442 442
             return new EE_Form_Section_Proper(
443 443
                 [
444 444
                     'layout_strategy' => new EE_Div_Per_Section_Layout(),
445
-                    'html_id'         => 'ee-' . $this->slug() . '-hidden-inputs',
445
+                    'html_id'         => 'ee-'.$this->slug().'-hidden-inputs',
446 446
                     'subsections'     => [
447 447
                         'next_step' => new EE_Fixed_Hidden_Input(
448 448
                             [
449 449
                                 'html_name' => 'next_step',
450
-                                'html_id'   => 'spco-' . $this->slug() . '-next-step',
450
+                                'html_id'   => 'spco-'.$this->slug().'-next-step',
451 451
                                 'default'   => $this->checkout->next_step instanceof EE_SPCO_Reg_Step
452 452
                                     ? $this->checkout->next_step->slug()
453 453
                                     : '',
@@ -461,12 +461,12 @@  discard block
 block discarded – undo
461 461
         return new EE_Form_Section_Proper(
462 462
             [
463 463
                 'layout_strategy' => new EE_Div_Per_Section_Layout(),
464
-                'html_id'         => 'ee-' . $this->slug() . '-hidden-inputs',
464
+                'html_id'         => 'ee-'.$this->slug().'-hidden-inputs',
465 465
                 'subsections'     => [
466 466
                     'action'         => new EE_Fixed_Hidden_Input(
467 467
                         [
468 468
                             'html_name' => 'action',
469
-                            'html_id'   => 'spco-' . $this->slug() . '-action',
469
+                            'html_id'   => 'spco-'.$this->slug().'-action',
470 470
                             'default'   => apply_filters(
471 471
                                 'FHEE__EE_SPCO_Reg_Step__reg_step_hidden_inputs__default_form_action',
472 472
                                 empty($this->checkout->reg_url_link)
@@ -479,7 +479,7 @@  discard block
 block discarded – undo
479 479
                     'next_step'      => new EE_Fixed_Hidden_Input(
480 480
                         [
481 481
                             'html_name' => 'next_step',
482
-                            'html_id'   => 'spco-' . $this->slug() . '-next-step',
482
+                            'html_id'   => 'spco-'.$this->slug().'-next-step',
483 483
                             'default'   => $this->checkout->next_step instanceof EE_SPCO_Reg_Step
484 484
                                 ? $this->checkout->next_step->slug()
485 485
                                 : '',
@@ -513,7 +513,7 @@  discard block
 block discarded – undo
513 513
      */
514 514
     public function generate_reg_form_for_actions($actions = [])
515 515
     {
516
-        $actions                           = array_merge(
516
+        $actions = array_merge(
517 517
             [
518 518
                 'generate_reg_form',
519 519
                 'display_spco_reg_step',
@@ -556,7 +556,7 @@  discard block
 block discarded – undo
556 556
      */
557 557
     public function reg_step_submit_button()
558 558
     {
559
-        if (! $this->checkout->next_step instanceof EE_SPCO_Reg_Step) {
559
+        if ( ! $this->checkout->next_step instanceof EE_SPCO_Reg_Step) {
560 560
             return '';
561 561
         }
562 562
         ob_start();
@@ -570,18 +570,18 @@  discard block
 block discarded – undo
570 570
         // generate submit button
571 571
         $submit_btn = new EE_Submit_Input(
572 572
             [
573
-                'html_name'             => 'spco-go-to-step-' . $this->checkout->next_step->slug(),
574
-                'html_id'               => 'spco-go-to-step-' . $this->checkout->next_step->slug(),
573
+                'html_name'             => 'spco-go-to-step-'.$this->checkout->next_step->slug(),
574
+                'html_id'               => 'spco-go-to-step-'.$this->checkout->next_step->slug(),
575 575
                 'html_class'            => 'spco-next-step-btn',
576
-                'other_html_attributes' => ' rel="' . $this->slug() . '"',
576
+                'other_html_attributes' => ' rel="'.$this->slug().'"',
577 577
                 'default'               => $this->submit_button_text(),
578 578
             ]
579 579
         );
580 580
         $submit_btn->set_button_css_attributes(true, 'large');
581 581
         $submit_btn_html = $submit_btn->get_html_for_input();
582
-        $html            .= EEH_HTML::div(
582
+        $html .= EEH_HTML::div(
583 583
             apply_filters('FHEE__EE_SPCO_Reg_Step__reg_step_submit_button__sbmt_btn_html', $submit_btn_html, $this),
584
-            'spco-' . $this->slug() . '-whats-next-buttons-dv',
584
+            'spco-'.$this->slug().'-whats-next-buttons-dv',
585 585
             'spco-whats-next-buttons'
586 586
         );
587 587
         return $html;
Please login to merge, or discard this patch.