Completed
Branch BUG/ticket-selector-caps (3acd3b)
by
unknown
04:11 queued 02:22
created
modules/ticket_selector/ProcessTicketSelector.php 2 patches
Indentation   +368 added lines, -368 removed lines patch added patch discarded remove patch
@@ -34,393 +34,393 @@
 block discarded – undo
34 34
 class ProcessTicketSelector
35 35
 {
36 36
 
37
-    /**
38
-     * @var EE_Cart $cart
39
-     */
40
-    private $cart;
37
+	/**
38
+	 * @var EE_Cart $cart
39
+	 */
40
+	private $cart;
41 41
 
42
-    /**
43
-     * @var EE_Core_Config $core_config
44
-     */
45
-    private $core_config;
42
+	/**
43
+	 * @var EE_Core_Config $core_config
44
+	 */
45
+	private $core_config;
46 46
 
47
-    /**
48
-     * @var RequestInterface $request
49
-     */
50
-    private $request;
47
+	/**
48
+	 * @var RequestInterface $request
49
+	 */
50
+	private $request;
51 51
 
52
-    /**
53
-     * @var EE_Session $session
54
-     */
55
-    private $session;
52
+	/**
53
+	 * @var EE_Session $session
54
+	 */
55
+	private $session;
56 56
 
57
-    /**
58
-     * @var EEM_Ticket $ticket_model
59
-     */
60
-    private $ticket_model;
57
+	/**
58
+	 * @var EEM_Ticket $ticket_model
59
+	 */
60
+	private $ticket_model;
61 61
 
62
-    /**
63
-     * @var TicketDatetimeAvailabilityTracker $tracker
64
-     */
65
-    private $tracker;
62
+	/**
63
+	 * @var TicketDatetimeAvailabilityTracker $tracker
64
+	 */
65
+	private $tracker;
66 66
 
67 67
 
68
-    /**
69
-     * ProcessTicketSelector constructor.
70
-     * NOTE: PLZ use the Loader to instantiate this class if need be
71
-     * so that all dependencies get injected correctly (which will happen automatically)
72
-     * Null values for parameters are only for backwards compatibility but will be removed later on.
73
-     *
74
-     * @param EE_Core_Config                    $core_config
75
-     * @param RequestInterface                           $request
76
-     * @param EE_Session                        $session
77
-     * @param EEM_Ticket                        $ticket_model
78
-     * @param TicketDatetimeAvailabilityTracker $tracker
79
-     * @throws InvalidArgumentException
80
-     * @throws InvalidDataTypeException
81
-     * @throws InvalidInterfaceException
82
-     */
83
-    public function __construct(
84
-        EE_Core_Config $core_config = null,
85
-        RequestInterface $request = null,
86
-        EE_Session $session = null,
87
-        EEM_Ticket $ticket_model = null,
88
-        TicketDatetimeAvailabilityTracker $tracker = null
89
-    ) {
90
-        $loader = LoaderFactory::getLoader();
91
-        $this->core_config = $core_config instanceof EE_Core_Config
92
-            ? $core_config
93
-            : $loader->getShared('EE_Core_Config');
94
-        $this->request = $request instanceof RequestInterface
95
-            ? $request
96
-            : $loader->getShared('EventEspresso\core\services\request\Request');
97
-        $this->session = $session instanceof EE_Session
98
-            ? $session
99
-            : $loader->getShared('EE_Session');
100
-        $this->ticket_model = $ticket_model instanceof EEM_Ticket
101
-            ? $ticket_model
102
-            : $loader->getShared('EEM_Ticket');
103
-        $this->tracker = $tracker instanceof TicketDatetimeAvailabilityTracker
104
-            ? $tracker
105
-            : $loader->getShared('EventEspresso\modules\ticket_selector\TicketDatetimeAvailabilityTracker');
106
-    }
68
+	/**
69
+	 * ProcessTicketSelector constructor.
70
+	 * NOTE: PLZ use the Loader to instantiate this class if need be
71
+	 * so that all dependencies get injected correctly (which will happen automatically)
72
+	 * Null values for parameters are only for backwards compatibility but will be removed later on.
73
+	 *
74
+	 * @param EE_Core_Config                    $core_config
75
+	 * @param RequestInterface                           $request
76
+	 * @param EE_Session                        $session
77
+	 * @param EEM_Ticket                        $ticket_model
78
+	 * @param TicketDatetimeAvailabilityTracker $tracker
79
+	 * @throws InvalidArgumentException
80
+	 * @throws InvalidDataTypeException
81
+	 * @throws InvalidInterfaceException
82
+	 */
83
+	public function __construct(
84
+		EE_Core_Config $core_config = null,
85
+		RequestInterface $request = null,
86
+		EE_Session $session = null,
87
+		EEM_Ticket $ticket_model = null,
88
+		TicketDatetimeAvailabilityTracker $tracker = null
89
+	) {
90
+		$loader = LoaderFactory::getLoader();
91
+		$this->core_config = $core_config instanceof EE_Core_Config
92
+			? $core_config
93
+			: $loader->getShared('EE_Core_Config');
94
+		$this->request = $request instanceof RequestInterface
95
+			? $request
96
+			: $loader->getShared('EventEspresso\core\services\request\Request');
97
+		$this->session = $session instanceof EE_Session
98
+			? $session
99
+			: $loader->getShared('EE_Session');
100
+		$this->ticket_model = $ticket_model instanceof EEM_Ticket
101
+			? $ticket_model
102
+			: $loader->getShared('EEM_Ticket');
103
+		$this->tracker = $tracker instanceof TicketDatetimeAvailabilityTracker
104
+			? $tracker
105
+			: $loader->getShared('EventEspresso\modules\ticket_selector\TicketDatetimeAvailabilityTracker');
106
+	}
107 107
 
108 108
 
109
-    /**
110
-     * cancelTicketSelections
111
-     *
112
-     * @return bool
113
-     * @throws EE_Error
114
-     * @throws InvalidArgumentException
115
-     * @throws InvalidInterfaceException
116
-     * @throws InvalidDataTypeException
117
-     * @throws ReflectionException
118
-     */
119
-    public function cancelTicketSelections()
120
-    {
121
-        // check nonce
122
-        if (! $this->processTicketSelectorNonce()) {
123
-            return false;
124
-        }
125
-        $this->session->clear_session(__CLASS__, __FUNCTION__);
126
-        if ($this->request->requestParamIsSet('event_id')) {
127
-            EEH_URL::safeRedirectAndExit(
128
-                EEH_Event_View::event_link_url(
129
-                    $this->request->getRequestParam('event_id', 0, 'int')
130
-                )
131
-            );
132
-        }
133
-        EEH_URL::safeRedirectAndExit(
134
-            site_url('/' . $this->core_config->event_cpt_slug . '/')
135
-        );
136
-        return true;
137
-    }
109
+	/**
110
+	 * cancelTicketSelections
111
+	 *
112
+	 * @return bool
113
+	 * @throws EE_Error
114
+	 * @throws InvalidArgumentException
115
+	 * @throws InvalidInterfaceException
116
+	 * @throws InvalidDataTypeException
117
+	 * @throws ReflectionException
118
+	 */
119
+	public function cancelTicketSelections()
120
+	{
121
+		// check nonce
122
+		if (! $this->processTicketSelectorNonce()) {
123
+			return false;
124
+		}
125
+		$this->session->clear_session(__CLASS__, __FUNCTION__);
126
+		if ($this->request->requestParamIsSet('event_id')) {
127
+			EEH_URL::safeRedirectAndExit(
128
+				EEH_Event_View::event_link_url(
129
+					$this->request->getRequestParam('event_id', 0, 'int')
130
+				)
131
+			);
132
+		}
133
+		EEH_URL::safeRedirectAndExit(
134
+			site_url('/' . $this->core_config->event_cpt_slug . '/')
135
+		);
136
+		return true;
137
+	}
138 138
 
139 139
 
140
-    /**
141
-     * processTicketSelectorNonce
142
-     *
143
-     * @return bool
144
-     */
145
-    private function processTicketSelectorNonce()
146
-    {
147
-        if (
148
-            ! $this->request->isAdmin()
149
-            && (
150
-                ! $this->request->requestParamIsSet('cancel_ticket_selections_nonce')
151
-                || ! wp_verify_nonce(
152
-                    $this->request->getRequestParam('cancel_ticket_selections_nonce'),
153
-                    'cancel_ticket_selections'
154
-                )
155
-            )
156
-        ) {
157
-            EE_Error::add_error(
158
-                sprintf(
159
-                    esc_html__(
160
-                        'We\'re sorry but your request failed to pass a security check.%sPlease click the back button on your browser and try again.',
161
-                        'event_espresso'
162
-                    ),
163
-                    '<br/>'
164
-                ),
165
-                __FILE__,
166
-                __FUNCTION__,
167
-                __LINE__
168
-            );
169
-            return false;
170
-        }
171
-        return true;
172
-    }
140
+	/**
141
+	 * processTicketSelectorNonce
142
+	 *
143
+	 * @return bool
144
+	 */
145
+	private function processTicketSelectorNonce()
146
+	{
147
+		if (
148
+			! $this->request->isAdmin()
149
+			&& (
150
+				! $this->request->requestParamIsSet('cancel_ticket_selections_nonce')
151
+				|| ! wp_verify_nonce(
152
+					$this->request->getRequestParam('cancel_ticket_selections_nonce'),
153
+					'cancel_ticket_selections'
154
+				)
155
+			)
156
+		) {
157
+			EE_Error::add_error(
158
+				sprintf(
159
+					esc_html__(
160
+						'We\'re sorry but your request failed to pass a security check.%sPlease click the back button on your browser and try again.',
161
+						'event_espresso'
162
+					),
163
+					'<br/>'
164
+				),
165
+				__FILE__,
166
+				__FUNCTION__,
167
+				__LINE__
168
+			);
169
+			return false;
170
+		}
171
+		return true;
172
+	}
173 173
 
174 174
 
175
-    /**
176
-     * process_ticket_selections
177
-     *
178
-     * @return bool
179
-     * @throws EE_Error
180
-     * @throws InvalidArgumentException
181
-     * @throws InvalidDataTypeException
182
-     * @throws InvalidInterfaceException
183
-     * @throws ReflectionException
184
-     */
185
-    public function processTicketSelections()
186
-    {
187
-        do_action('EED_Ticket_Selector__process_ticket_selections__before');
188
-        if ($this->request->isBot()) {
189
-            EEH_URL::safeRedirectAndExit(
190
-                apply_filters(
191
-                    'FHEE__EE_Ticket_Selector__process_ticket_selections__bot_redirect_url',
192
-                    site_url()
193
-                )
194
-            );
195
-        }
196
-        // we should really only have 1 registration in the works now
197
-        // (ie, no MER) so unless otherwise requested, clear the session
198
-        if (apply_filters('FHEE__EE_Ticket_Selector__process_ticket_selections__clear_session', true)) {
199
-            $this->session->clear_session(__CLASS__, __FUNCTION__);
200
-        }
201
-        // validate/sanitize/filter data
202
-        $id = null;
203
-        $valid = [];
204
-        try {
205
-            $post_data_validator = new ProcessTicketSelectorPostData($this->request);
206
-            $id = $post_data_validator->getEventId();
207
-            $valid               = apply_filters(
208
-                'FHEE__EED_Ticket_Selector__process_ticket_selections__valid_post_data',
209
-                $post_data_validator->validatePostData()
210
-            );
211
-        } catch (Exception $exception) {
212
-            EE_Error::add_error($exception->getMessage(), __FILE__, __FUNCTION__, __LINE__);
213
-        }
214
-        // check total tickets ordered vs max number of attendees that can register
215
-        if (! empty($valid) && $valid['total_tickets'] > $valid['max_atndz']) {
216
-            $this->maxAttendeesViolation($valid);
217
-        } else {
218
-            // all data appears to be valid
219
-            if ($this->processSuccessfulCart($this->addTicketsToCart($valid))) {
220
-                return true;
221
-            }
222
-        }
223
-        // die(); // <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< KILL BEFORE REDIRECT
224
-        // at this point, just return if registration is being made from admin
225
-        if ($this->request->isAdmin() || $this->request->isFrontAjax()) {
226
-            return false;
227
-        }
228
-        if (! empty($valid['return_url'])) {
229
-            EEH_URL::safeRedirectAndExit($valid['return_url']);
230
-        }
231
-        // do we have an event id?
232
-        if ($id) {
233
-            EEH_URL::safeRedirectAndExit(get_permalink($id));
234
-        }
235
-        echo EE_Error::get_notices(); // already escaped
236
-        return false;
237
-    }
175
+	/**
176
+	 * process_ticket_selections
177
+	 *
178
+	 * @return bool
179
+	 * @throws EE_Error
180
+	 * @throws InvalidArgumentException
181
+	 * @throws InvalidDataTypeException
182
+	 * @throws InvalidInterfaceException
183
+	 * @throws ReflectionException
184
+	 */
185
+	public function processTicketSelections()
186
+	{
187
+		do_action('EED_Ticket_Selector__process_ticket_selections__before');
188
+		if ($this->request->isBot()) {
189
+			EEH_URL::safeRedirectAndExit(
190
+				apply_filters(
191
+					'FHEE__EE_Ticket_Selector__process_ticket_selections__bot_redirect_url',
192
+					site_url()
193
+				)
194
+			);
195
+		}
196
+		// we should really only have 1 registration in the works now
197
+		// (ie, no MER) so unless otherwise requested, clear the session
198
+		if (apply_filters('FHEE__EE_Ticket_Selector__process_ticket_selections__clear_session', true)) {
199
+			$this->session->clear_session(__CLASS__, __FUNCTION__);
200
+		}
201
+		// validate/sanitize/filter data
202
+		$id = null;
203
+		$valid = [];
204
+		try {
205
+			$post_data_validator = new ProcessTicketSelectorPostData($this->request);
206
+			$id = $post_data_validator->getEventId();
207
+			$valid               = apply_filters(
208
+				'FHEE__EED_Ticket_Selector__process_ticket_selections__valid_post_data',
209
+				$post_data_validator->validatePostData()
210
+			);
211
+		} catch (Exception $exception) {
212
+			EE_Error::add_error($exception->getMessage(), __FILE__, __FUNCTION__, __LINE__);
213
+		}
214
+		// check total tickets ordered vs max number of attendees that can register
215
+		if (! empty($valid) && $valid['total_tickets'] > $valid['max_atndz']) {
216
+			$this->maxAttendeesViolation($valid);
217
+		} else {
218
+			// all data appears to be valid
219
+			if ($this->processSuccessfulCart($this->addTicketsToCart($valid))) {
220
+				return true;
221
+			}
222
+		}
223
+		// die(); // <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< KILL BEFORE REDIRECT
224
+		// at this point, just return if registration is being made from admin
225
+		if ($this->request->isAdmin() || $this->request->isFrontAjax()) {
226
+			return false;
227
+		}
228
+		if (! empty($valid['return_url'])) {
229
+			EEH_URL::safeRedirectAndExit($valid['return_url']);
230
+		}
231
+		// do we have an event id?
232
+		if ($id) {
233
+			EEH_URL::safeRedirectAndExit(get_permalink($id));
234
+		}
235
+		echo EE_Error::get_notices(); // already escaped
236
+		return false;
237
+	}
238 238
 
239 239
 
240
-    /**
241
-     * @param array $valid
242
-     */
243
-    private function maxAttendeesViolation(array $valid)
244
-    {
245
-        // ordering too many tickets !!!
246
-        $total_tickets_string = esc_html(
247
-            _n(
248
-                'You have attempted to purchase %s ticket.',
249
-                'You have attempted to purchase %s tickets.',
250
-                $valid['total_tickets'],
251
-                'event_espresso'
252
-            )
253
-        );
254
-        $limit_error_1 = sprintf($total_tickets_string, $valid['total_tickets']);
255
-        // dev only message
256
-        $max_attendees_string = esc_html(
257
-            _n(
258
-                '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.',
259
-                '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.',
260
-                $valid['max_atndz'],
261
-                'event_espresso'
262
-            )
263
-        );
264
-        $limit_error_2 = sprintf($max_attendees_string, $valid['max_atndz'], $valid['max_atndz']);
265
-        EE_Error::add_error($limit_error_1 . '<br/>' . $limit_error_2, __FILE__, __FUNCTION__, __LINE__);
266
-    }
240
+	/**
241
+	 * @param array $valid
242
+	 */
243
+	private function maxAttendeesViolation(array $valid)
244
+	{
245
+		// ordering too many tickets !!!
246
+		$total_tickets_string = esc_html(
247
+			_n(
248
+				'You have attempted to purchase %s ticket.',
249
+				'You have attempted to purchase %s tickets.',
250
+				$valid['total_tickets'],
251
+				'event_espresso'
252
+			)
253
+		);
254
+		$limit_error_1 = sprintf($total_tickets_string, $valid['total_tickets']);
255
+		// dev only message
256
+		$max_attendees_string = esc_html(
257
+			_n(
258
+				'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.',
259
+				'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.',
260
+				$valid['max_atndz'],
261
+				'event_espresso'
262
+			)
263
+		);
264
+		$limit_error_2 = sprintf($max_attendees_string, $valid['max_atndz'], $valid['max_atndz']);
265
+		EE_Error::add_error($limit_error_1 . '<br/>' . $limit_error_2, __FILE__, __FUNCTION__, __LINE__);
266
+	}
267 267
 
268 268
 
269
-    /**
270
-     * @param array $valid
271
-     * @return int
272
-     * @throws EE_Error
273
-     * @throws InvalidArgumentException
274
-     * @throws InvalidDataTypeException
275
-     * @throws InvalidInterfaceException
276
-     */
277
-    private function addTicketsToCart(array $valid)
278
-    {
279
-        $tickets_added = 0;
280
-        $tickets_selected = false;
281
-        if (! empty($valid['ticket-selections']) && $valid['total_tickets'] > 0) {
282
-            // load cart using factory because we don't want to do so until actually needed
283
-            $this->cart = CartFactory::getCart();
284
-            // if the user is an admin that can edit registrations,
285
-            // then we'll also allow them to add any tickets, even if they are expired
286
-            $current_user_is_admin = current_user_can('ee_edit_registrations');
287
-            // cycle thru the number of data rows sent from the event listing
288
-            foreach ($valid['ticket-selections'] as $ticket_id => $qty) {
289
-                if ($qty) {
290
-                    // YES we have a ticket quantity
291
-                    $tickets_selected = true;
292
-                    $valid_ticket     = false;
293
-                    // get ticket via the ticket id we put in the form
294
-                    $ticket = $this->ticket_model->get_one_by_ID($ticket_id);
295
-                    if ($ticket instanceof EE_Ticket && ($ticket->is_on_sale() || $current_user_is_admin)) {
296
-                        $valid_ticket  = true;
297
-                        $tickets_added += $this->addTicketToCart($ticket, $qty);
298
-                    }
299
-                    if ($valid_ticket !== true) {
300
-                        // nothing added to cart retrieved
301
-                        EE_Error::add_error(
302
-                            sprintf(
303
-                                esc_html__(
304
-                                    'A valid ticket could not be retrieved for the event.%sPlease click the back button on your browser and try again.',
305
-                                    'event_espresso'
306
-                                ),
307
-                                '<br/>'
308
-                            ),
309
-                            __FILE__,
310
-                            __FUNCTION__,
311
-                            __LINE__
312
-                        );
313
-                    }
314
-                    if (EE_Error::has_error()) {
315
-                        break;
316
-                    }
317
-                }
318
-            }
319
-        }
320
-        do_action(
321
-            'AHEE__EE_Ticket_Selector__process_ticket_selections__after_tickets_added_to_cart',
322
-            $this->cart,
323
-            $this
324
-        );
325
-        if (! apply_filters('FHEE__EED_Ticket_Selector__process_ticket_selections__tckts_slctd', $tickets_selected)) {
326
-            // no ticket quantities were selected
327
-            EE_Error::add_error(
328
-                esc_html__('You need to select a ticket quantity before you can proceed.', 'event_espresso'),
329
-                __FILE__,
330
-                __FUNCTION__,
331
-                __LINE__
332
-            );
333
-        }
334
-        return $tickets_added;
335
-    }
269
+	/**
270
+	 * @param array $valid
271
+	 * @return int
272
+	 * @throws EE_Error
273
+	 * @throws InvalidArgumentException
274
+	 * @throws InvalidDataTypeException
275
+	 * @throws InvalidInterfaceException
276
+	 */
277
+	private function addTicketsToCart(array $valid)
278
+	{
279
+		$tickets_added = 0;
280
+		$tickets_selected = false;
281
+		if (! empty($valid['ticket-selections']) && $valid['total_tickets'] > 0) {
282
+			// load cart using factory because we don't want to do so until actually needed
283
+			$this->cart = CartFactory::getCart();
284
+			// if the user is an admin that can edit registrations,
285
+			// then we'll also allow them to add any tickets, even if they are expired
286
+			$current_user_is_admin = current_user_can('ee_edit_registrations');
287
+			// cycle thru the number of data rows sent from the event listing
288
+			foreach ($valid['ticket-selections'] as $ticket_id => $qty) {
289
+				if ($qty) {
290
+					// YES we have a ticket quantity
291
+					$tickets_selected = true;
292
+					$valid_ticket     = false;
293
+					// get ticket via the ticket id we put in the form
294
+					$ticket = $this->ticket_model->get_one_by_ID($ticket_id);
295
+					if ($ticket instanceof EE_Ticket && ($ticket->is_on_sale() || $current_user_is_admin)) {
296
+						$valid_ticket  = true;
297
+						$tickets_added += $this->addTicketToCart($ticket, $qty);
298
+					}
299
+					if ($valid_ticket !== true) {
300
+						// nothing added to cart retrieved
301
+						EE_Error::add_error(
302
+							sprintf(
303
+								esc_html__(
304
+									'A valid ticket could not be retrieved for the event.%sPlease click the back button on your browser and try again.',
305
+									'event_espresso'
306
+								),
307
+								'<br/>'
308
+							),
309
+							__FILE__,
310
+							__FUNCTION__,
311
+							__LINE__
312
+						);
313
+					}
314
+					if (EE_Error::has_error()) {
315
+						break;
316
+					}
317
+				}
318
+			}
319
+		}
320
+		do_action(
321
+			'AHEE__EE_Ticket_Selector__process_ticket_selections__after_tickets_added_to_cart',
322
+			$this->cart,
323
+			$this
324
+		);
325
+		if (! apply_filters('FHEE__EED_Ticket_Selector__process_ticket_selections__tckts_slctd', $tickets_selected)) {
326
+			// no ticket quantities were selected
327
+			EE_Error::add_error(
328
+				esc_html__('You need to select a ticket quantity before you can proceed.', 'event_espresso'),
329
+				__FILE__,
330
+				__FUNCTION__,
331
+				__LINE__
332
+			);
333
+		}
334
+		return $tickets_added;
335
+	}
336 336
 
337 337
 
338
-    /**
339
-     * adds a ticket to the cart
340
-     *
341
-     * @param EE_Ticket $ticket
342
-     * @param int       $qty
343
-     * @return bool TRUE on success, FALSE on fail
344
-     * @throws InvalidArgumentException
345
-     * @throws InvalidInterfaceException
346
-     * @throws InvalidDataTypeException
347
-     * @throws EE_Error
348
-     */
349
-    private function addTicketToCart(EE_Ticket $ticket, $qty = 1)
350
-    {
351
-        // get the number of spaces left for this datetime ticket
352
-        $available_spaces = $this->tracker->ticketDatetimeAvailability($ticket);
353
-        // compare available spaces against the number of tickets being purchased
354
-        if ($available_spaces >= $qty) {
355
-            // allow addons to prevent a ticket from being added to cart
356
-            if (
357
-                ! apply_filters(
358
-                    'FHEE__EE_Ticket_Selector___add_ticket_to_cart__allow_add_to_cart',
359
-                    true,
360
-                    $ticket,
361
-                    $qty,
362
-                    $available_spaces
363
-                )
364
-            ) {
365
-                return false;
366
-            }
367
-            $qty = absint(apply_filters('FHEE__EE_Ticket_Selector___add_ticket_to_cart__ticket_qty', $qty, $ticket));
368
-            // add event to cart
369
-            if ($this->cart->add_ticket_to_cart($ticket, $qty)) {
370
-                $this->tracker->recalculateTicketDatetimeAvailability($ticket, $qty);
371
-                return true;
372
-            }
373
-            return false;
374
-        }
375
-        $this->tracker->processAvailabilityError($ticket, $qty, $this->cart->all_ticket_quantity_count());
376
-        return false;
377
-    }
338
+	/**
339
+	 * adds a ticket to the cart
340
+	 *
341
+	 * @param EE_Ticket $ticket
342
+	 * @param int       $qty
343
+	 * @return bool TRUE on success, FALSE on fail
344
+	 * @throws InvalidArgumentException
345
+	 * @throws InvalidInterfaceException
346
+	 * @throws InvalidDataTypeException
347
+	 * @throws EE_Error
348
+	 */
349
+	private function addTicketToCart(EE_Ticket $ticket, $qty = 1)
350
+	{
351
+		// get the number of spaces left for this datetime ticket
352
+		$available_spaces = $this->tracker->ticketDatetimeAvailability($ticket);
353
+		// compare available spaces against the number of tickets being purchased
354
+		if ($available_spaces >= $qty) {
355
+			// allow addons to prevent a ticket from being added to cart
356
+			if (
357
+				! apply_filters(
358
+					'FHEE__EE_Ticket_Selector___add_ticket_to_cart__allow_add_to_cart',
359
+					true,
360
+					$ticket,
361
+					$qty,
362
+					$available_spaces
363
+				)
364
+			) {
365
+				return false;
366
+			}
367
+			$qty = absint(apply_filters('FHEE__EE_Ticket_Selector___add_ticket_to_cart__ticket_qty', $qty, $ticket));
368
+			// add event to cart
369
+			if ($this->cart->add_ticket_to_cart($ticket, $qty)) {
370
+				$this->tracker->recalculateTicketDatetimeAvailability($ticket, $qty);
371
+				return true;
372
+			}
373
+			return false;
374
+		}
375
+		$this->tracker->processAvailabilityError($ticket, $qty, $this->cart->all_ticket_quantity_count());
376
+		return false;
377
+	}
378 378
 
379 379
 
380
-    /**
381
-     * @param $tickets_added
382
-     * @return bool
383
-     * @throws InvalidInterfaceException
384
-     * @throws InvalidDataTypeException
385
-     * @throws EE_Error
386
-     * @throws InvalidArgumentException
387
-     */
388
-    private function processSuccessfulCart($tickets_added)
389
-    {
390
-        // exit('KILL REDIRECT BEFORE CART UPDATE'); // <<<<<<<<<<<<<<<<< KILL REDIRECT HERE BEFORE CART UPDATE
391
-        if (apply_filters('FHEE__EED_Ticket_Selector__process_ticket_selections__success', $tickets_added)) {
392
-            // make sure cart is loaded
393
-            if (! $this->cart instanceof EE_Cart) {
394
-                $this->cart = CartFactory::getCart();
395
-            }
396
-            do_action(
397
-                'FHEE__EE_Ticket_Selector__process_ticket_selections__before_redirecting_to_checkout',
398
-                $this->cart,
399
-                $this
400
-            );
401
-            $this->cart->recalculate_all_cart_totals();
402
-            $this->cart->save_cart(false);
403
-            // exit('KILL REDIRECT AFTER CART UPDATE'); // <<<<<<<<  OR HERE TO KILL REDIRECT AFTER CART UPDATE
404
-            // just return TRUE for registrations being made from admin
405
-            if ($this->request->isAdmin() || $this->request->isFrontAjax()) {
406
-                return true;
407
-            }
408
-            EEH_URL::safeRedirectAndExit(
409
-                apply_filters(
410
-                    'FHEE__EE_Ticket_Selector__process_ticket_selections__success_redirect_url',
411
-                    $this->core_config->reg_page_url()
412
-                )
413
-            );
414
-        }
415
-        if (! EE_Error::has_error() && ! EE_Error::has_error(true, 'attention')) {
416
-            // nothing added to cart
417
-            EE_Error::add_attention(
418
-                esc_html__('No tickets were added for the event', 'event_espresso'),
419
-                __FILE__,
420
-                __FUNCTION__,
421
-                __LINE__
422
-            );
423
-        }
424
-        return false;
425
-    }
380
+	/**
381
+	 * @param $tickets_added
382
+	 * @return bool
383
+	 * @throws InvalidInterfaceException
384
+	 * @throws InvalidDataTypeException
385
+	 * @throws EE_Error
386
+	 * @throws InvalidArgumentException
387
+	 */
388
+	private function processSuccessfulCart($tickets_added)
389
+	{
390
+		// exit('KILL REDIRECT BEFORE CART UPDATE'); // <<<<<<<<<<<<<<<<< KILL REDIRECT HERE BEFORE CART UPDATE
391
+		if (apply_filters('FHEE__EED_Ticket_Selector__process_ticket_selections__success', $tickets_added)) {
392
+			// make sure cart is loaded
393
+			if (! $this->cart instanceof EE_Cart) {
394
+				$this->cart = CartFactory::getCart();
395
+			}
396
+			do_action(
397
+				'FHEE__EE_Ticket_Selector__process_ticket_selections__before_redirecting_to_checkout',
398
+				$this->cart,
399
+				$this
400
+			);
401
+			$this->cart->recalculate_all_cart_totals();
402
+			$this->cart->save_cart(false);
403
+			// exit('KILL REDIRECT AFTER CART UPDATE'); // <<<<<<<<  OR HERE TO KILL REDIRECT AFTER CART UPDATE
404
+			// just return TRUE for registrations being made from admin
405
+			if ($this->request->isAdmin() || $this->request->isFrontAjax()) {
406
+				return true;
407
+			}
408
+			EEH_URL::safeRedirectAndExit(
409
+				apply_filters(
410
+					'FHEE__EE_Ticket_Selector__process_ticket_selections__success_redirect_url',
411
+					$this->core_config->reg_page_url()
412
+				)
413
+			);
414
+		}
415
+		if (! EE_Error::has_error() && ! EE_Error::has_error(true, 'attention')) {
416
+			// nothing added to cart
417
+			EE_Error::add_attention(
418
+				esc_html__('No tickets were added for the event', 'event_espresso'),
419
+				__FILE__,
420
+				__FUNCTION__,
421
+				__LINE__
422
+			);
423
+		}
424
+		return false;
425
+	}
426 426
 }
Please login to merge, or discard this patch.
Spacing   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -119,7 +119,7 @@  discard block
 block discarded – undo
119 119
     public function cancelTicketSelections()
120 120
     {
121 121
         // check nonce
122
-        if (! $this->processTicketSelectorNonce()) {
122
+        if ( ! $this->processTicketSelectorNonce()) {
123 123
             return false;
124 124
         }
125 125
         $this->session->clear_session(__CLASS__, __FUNCTION__);
@@ -131,7 +131,7 @@  discard block
 block discarded – undo
131 131
             );
132 132
         }
133 133
         EEH_URL::safeRedirectAndExit(
134
-            site_url('/' . $this->core_config->event_cpt_slug . '/')
134
+            site_url('/'.$this->core_config->event_cpt_slug.'/')
135 135
         );
136 136
         return true;
137 137
     }
@@ -212,7 +212,7 @@  discard block
 block discarded – undo
212 212
             EE_Error::add_error($exception->getMessage(), __FILE__, __FUNCTION__, __LINE__);
213 213
         }
214 214
         // check total tickets ordered vs max number of attendees that can register
215
-        if (! empty($valid) && $valid['total_tickets'] > $valid['max_atndz']) {
215
+        if ( ! empty($valid) && $valid['total_tickets'] > $valid['max_atndz']) {
216 216
             $this->maxAttendeesViolation($valid);
217 217
         } else {
218 218
             // all data appears to be valid
@@ -225,7 +225,7 @@  discard block
 block discarded – undo
225 225
         if ($this->request->isAdmin() || $this->request->isFrontAjax()) {
226 226
             return false;
227 227
         }
228
-        if (! empty($valid['return_url'])) {
228
+        if ( ! empty($valid['return_url'])) {
229 229
             EEH_URL::safeRedirectAndExit($valid['return_url']);
230 230
         }
231 231
         // do we have an event id?
@@ -262,7 +262,7 @@  discard block
 block discarded – undo
262 262
             )
263 263
         );
264 264
         $limit_error_2 = sprintf($max_attendees_string, $valid['max_atndz'], $valid['max_atndz']);
265
-        EE_Error::add_error($limit_error_1 . '<br/>' . $limit_error_2, __FILE__, __FUNCTION__, __LINE__);
265
+        EE_Error::add_error($limit_error_1.'<br/>'.$limit_error_2, __FILE__, __FUNCTION__, __LINE__);
266 266
     }
267 267
 
268 268
 
@@ -278,7 +278,7 @@  discard block
 block discarded – undo
278 278
     {
279 279
         $tickets_added = 0;
280 280
         $tickets_selected = false;
281
-        if (! empty($valid['ticket-selections']) && $valid['total_tickets'] > 0) {
281
+        if ( ! empty($valid['ticket-selections']) && $valid['total_tickets'] > 0) {
282 282
             // load cart using factory because we don't want to do so until actually needed
283 283
             $this->cart = CartFactory::getCart();
284 284
             // if the user is an admin that can edit registrations,
@@ -293,7 +293,7 @@  discard block
 block discarded – undo
293 293
                     // get ticket via the ticket id we put in the form
294 294
                     $ticket = $this->ticket_model->get_one_by_ID($ticket_id);
295 295
                     if ($ticket instanceof EE_Ticket && ($ticket->is_on_sale() || $current_user_is_admin)) {
296
-                        $valid_ticket  = true;
296
+                        $valid_ticket = true;
297 297
                         $tickets_added += $this->addTicketToCart($ticket, $qty);
298 298
                     }
299 299
                     if ($valid_ticket !== true) {
@@ -322,7 +322,7 @@  discard block
 block discarded – undo
322 322
             $this->cart,
323 323
             $this
324 324
         );
325
-        if (! apply_filters('FHEE__EED_Ticket_Selector__process_ticket_selections__tckts_slctd', $tickets_selected)) {
325
+        if ( ! apply_filters('FHEE__EED_Ticket_Selector__process_ticket_selections__tckts_slctd', $tickets_selected)) {
326 326
             // no ticket quantities were selected
327 327
             EE_Error::add_error(
328 328
                 esc_html__('You need to select a ticket quantity before you can proceed.', 'event_espresso'),
@@ -390,7 +390,7 @@  discard block
 block discarded – undo
390 390
         // exit('KILL REDIRECT BEFORE CART UPDATE'); // <<<<<<<<<<<<<<<<< KILL REDIRECT HERE BEFORE CART UPDATE
391 391
         if (apply_filters('FHEE__EED_Ticket_Selector__process_ticket_selections__success', $tickets_added)) {
392 392
             // make sure cart is loaded
393
-            if (! $this->cart instanceof EE_Cart) {
393
+            if ( ! $this->cart instanceof EE_Cart) {
394 394
                 $this->cart = CartFactory::getCart();
395 395
             }
396 396
             do_action(
@@ -412,7 +412,7 @@  discard block
 block discarded – undo
412 412
                 )
413 413
             );
414 414
         }
415
-        if (! EE_Error::has_error() && ! EE_Error::has_error(true, 'attention')) {
415
+        if ( ! EE_Error::has_error() && ! EE_Error::has_error(true, 'attention')) {
416 416
             // nothing added to cart
417 417
             EE_Error::add_attention(
418 418
                 esc_html__('No tickets were added for the event', 'event_espresso'),
Please login to merge, or discard this patch.
modules/ticket_selector/TicketSelectorRowSimple.php 1 patch
Indentation   +25 added lines, -25 removed lines patch added patch discarded remove patch
@@ -15,31 +15,31 @@
 block discarded – undo
15 15
 class TicketSelectorRowSimple extends TicketSelectorRow
16 16
 {
17 17
 
18
-    /**
19
-     * @throws EE_Error
20
-     * @throws ReflectionException
21
-     */
22
-    public function setupTicketStatusDisplay()
23
-    {
24
-        $remaining = $this->ticket->remaining();
25
-        $this->setTicketMinAndMax($remaining);
26
-        $this->setTicketStatusClasses($remaining);
27
-        $this->setTicketStatusDisplay($remaining);
28
-    }
18
+	/**
19
+	 * @throws EE_Error
20
+	 * @throws ReflectionException
21
+	 */
22
+	public function setupTicketStatusDisplay()
23
+	{
24
+		$remaining = $this->ticket->remaining();
25
+		$this->setTicketMinAndMax($remaining);
26
+		$this->setTicketStatusClasses($remaining);
27
+		$this->setTicketStatusDisplay($remaining);
28
+	}
29 29
 
30 30
 
31
-    /**
32
-     * @return bool|string
33
-     * @throws EE_Error
34
-     */
35
-    public function getTicketDescription()
36
-    {
37
-        $filtered_row_content = $this->getFilteredRowContents();
38
-        if ($filtered_row_content !== false) {
39
-            remove_filter('FHEE__EE_Ticket_Selector__display_ticket_selector_submit', '__return_true');
40
-            add_filter('FHEE__EE_Ticket_Selector__display_ticket_selector_submit', '__return_false');
41
-            return $filtered_row_content;
42
-        }
43
-        return $this->ticket->description();
44
-    }
31
+	/**
32
+	 * @return bool|string
33
+	 * @throws EE_Error
34
+	 */
35
+	public function getTicketDescription()
36
+	{
37
+		$filtered_row_content = $this->getFilteredRowContents();
38
+		if ($filtered_row_content !== false) {
39
+			remove_filter('FHEE__EE_Ticket_Selector__display_ticket_selector_submit', '__return_true');
40
+			add_filter('FHEE__EE_Ticket_Selector__display_ticket_selector_submit', '__return_false');
41
+			return $filtered_row_content;
42
+		}
43
+		return $this->ticket->description();
44
+	}
45 45
 }
Please login to merge, or discard this patch.
modules/ticket_selector/ProcessTicketSelectorPostData.php 2 patches
Indentation   +221 added lines, -221 removed lines patch added patch discarded remove patch
@@ -16,225 +16,225 @@
 block discarded – undo
16 16
 class ProcessTicketSelectorPostData
17 17
 {
18 18
 
19
-    const DATA_KEY_EVENT_ID      = 'id';
20
-
21
-    const DATA_KEY_MAX_ATNDZ     = 'max_atndz';
22
-
23
-    const DATA_KEY_QUANTITY      = 'ticket-selections';
24
-
25
-    const DATA_KEY_RETURN_URL    = 'return_url';
26
-
27
-    const DATA_KEY_ROWS          = 'rows';
28
-
29
-    const DATA_KEY_TICKET_ID     = 'ticket_id';
30
-
31
-    const DATA_KEY_TOTAL_TICKETS = 'total_tickets';
32
-
33
-    const INPUT_KEY_EVENT_ID     = 'tkt-slctr-event-id';
34
-
35
-    const INPUT_KEY_MAX_ATNDZ    = 'tkt-slctr-max-atndz-';
36
-
37
-    const INPUT_KEY_ROWS         = 'tkt-slctr-rows-';
38
-
39
-    const INPUT_KEY_QTY          = 'tkt-slctr-qty-';
40
-
41
-    const INPUT_KEY_TICKET_ID    = 'tkt-slctr-ticket-id-';
42
-
43
-    const INPUT_KEY_RETURN_URL   = 'tkt-slctr-return-url-';
44
-
45
-
46
-    /**
47
-     * @var int
48
-     */
49
-    protected $event_id;
50
-
51
-    /**
52
-     * @var array
53
-     */
54
-    protected $inputs_to_clean = [];
55
-
56
-    /**
57
-     * @var array
58
-     */
59
-    protected $valid_data = [];
60
-
61
-    /**
62
-     * @var RequestInterface
63
-     */
64
-    protected $request;
65
-
66
-
67
-    /**
68
-     * @param RequestInterface $request
69
-     */
70
-    public function __construct(RequestInterface $request)
71
-    {
72
-        $this->request         = $request;
73
-        $this->inputs_to_clean = [
74
-            self::DATA_KEY_MAX_ATNDZ     => self::INPUT_KEY_MAX_ATNDZ,
75
-            self::DATA_KEY_RETURN_URL    => self::INPUT_KEY_RETURN_URL,
76
-            self::DATA_KEY_ROWS          => self::INPUT_KEY_ROWS,
77
-            self::DATA_KEY_TOTAL_TICKETS => self::INPUT_KEY_TICKET_ID,
78
-            self::DATA_KEY_QUANTITY      => self::INPUT_KEY_QTY,
79
-        ];
80
-    }
81
-
82
-
83
-    /**
84
-     * @return int
85
-     * @throws DomainException
86
-     */
87
-    public function getEventId()
88
-    {
89
-        // do we have an event id?
90
-        if ($this->event_id === null) {
91
-            $this->event_id = $this->request->getRequestParam(self::INPUT_KEY_EVENT_ID, 0, 'int');
92
-            if (! $this->event_id) {
93
-                // $_POST['tkt-slctr-event-id'] was not set ?!?!?!?
94
-                throw new DomainException(
95
-                    sprintf(
96
-                        esc_html__(
97
-                            'An event id was not provided or was not received.%sPlease click the back button on your browser and try again.',
98
-                            'event_espresso'
99
-                        ),
100
-                        '<br/>'
101
-                    )
102
-                );
103
-            }
104
-        }
105
-        // event id is valid
106
-        return $this->event_id;
107
-    }
108
-
109
-
110
-    /**
111
-     * @return array
112
-     * @throws DomainException
113
-     */
114
-    public function validatePostData()
115
-    {
116
-        // grab valid id
117
-        $this->valid_data[ self::DATA_KEY_EVENT_ID ] = $this->getEventId();
118
-        // let's track the total number of tickets ordered.'
119
-        $this->valid_data[ self:: DATA_KEY_TOTAL_TICKETS ] = 0;
120
-        // cycle through $inputs_to_clean array
121
-        foreach ($this->inputs_to_clean as $what => $input_to_clean) {
122
-            $input_key = "{$input_to_clean}{$this->event_id}";
123
-            // check for POST data
124
-            if ($this->request->requestParamIsSet($input_key)) {
125
-                switch ($what) {
126
-                    // integers
127
-                    case self::DATA_KEY_ROWS:
128
-                    case self::DATA_KEY_MAX_ATNDZ:
129
-                        $this->processInteger($what, $input_key);
130
-                        break;
131
-                    // arrays of integers
132
-                    case self::DATA_KEY_QUANTITY:
133
-                        $this->processQuantity($input_key);
134
-                        break;
135
-                    // array of integers
136
-                    case self::DATA_KEY_TOTAL_TICKETS:
137
-                        $this->processTicketIDs($input_key);
138
-                        break;
139
-                    case self::DATA_KEY_RETURN_URL:
140
-                        $this->processReturnURL($input_key);
141
-                        break;
142
-                }
143
-            }
144
-        }
145
-        return $this->valid_data;
146
-    }
147
-
148
-
149
-    /**
150
-     * @param string $what
151
-     * @param string $input_key
152
-     */
153
-    protected function processInteger($what, $input_key)
154
-    {
155
-        $this->valid_data[ $what ] = $this->request->getRequestParam($input_key, 0, 'int');
156
-    }
157
-
158
-
159
-    /**
160
-     * @param string $input_key
161
-     * @throws DomainException
162
-     */
163
-    protected function processQuantity($input_key)
164
-    {
165
-        /** @var array $row_qty */
166
-        $row_qty = $this->request->getRequestParam($input_key, [], 'int', true);
167
-        if (empty($row_qty) || ! is_array($row_qty)) {
168
-            throw new DomainException(
169
-                sprintf(
170
-                    esc_html__(
171
-                        'An error occurred while trying to retrieve the ticket selections for the event.%sPlease click the back button on your browser and try again.',
172
-                        'event_espresso'
173
-                    ),
174
-                    '<br/>'
175
-                )
176
-            );
177
-        }
178
-        $max_atndz = $this->valid_data[ self::DATA_KEY_MAX_ATNDZ ];
179
-        // if max attendees is 1 then the incoming row qty array
180
-        // will only have one element and the value will be the ticket ID
181
-        // ex: row qty = [ 0 => TKT_ID ]
182
-        if ($max_atndz === 1 && count($row_qty) === 1) {
183
-            // so we'll grab that ticket ID, use it as the key, and set the value to 1
184
-            // ex: row qty = [ TKT_ID => 1 ]
185
-            $ticket_id = array_pop($row_qty);
186
-            $row_qty = [ $ticket_id => 1 ];
187
-        }
188
-        foreach ($this->valid_data[ self::DATA_KEY_TICKET_ID ] as $ticket_id) {
189
-            $qty = isset($row_qty[ $ticket_id ]) ? $row_qty[ $ticket_id ] : 0;
190
-            $this->valid_data[ self::DATA_KEY_QUANTITY ][ $ticket_id ]     = $qty;
191
-            $this->valid_data[ self:: DATA_KEY_TOTAL_TICKETS ] += $qty;
192
-        }
193
-    }
194
-
195
-
196
-    /**
197
-     * @param string $input_key
198
-     */
199
-    protected function processReturnURL($input_key)
200
-    {
201
-        // grab and sanitize return-url
202
-        $input_value = $this->request->getRequestParam($input_key, '', 'url');
203
-        // was the request coming from an iframe ? if so, then:
204
-        if (strpos($input_value, 'event_list=iframe')) {
205
-            // get anchor fragment
206
-            $input_value = explode('#', $input_value);
207
-            $input_value = end($input_value);
208
-            // use event list url instead, but append anchor
209
-            $input_value = EEH_Event_View::event_archive_url() . '#' . $input_value;
210
-        }
211
-        $this->valid_data[ self::DATA_KEY_RETURN_URL ] = $input_value;
212
-    }
213
-
214
-
215
-    /**
216
-     * @param string $input_key
217
-     * @throws DomainException
218
-     */
219
-    protected function processTicketIDs($input_key)
220
-    {
221
-        $ticket_ids          = (array) $this->request->getRequestParam($input_key, [], 'int', true);
222
-        $filtered_ticket_ids = array_filter($ticket_ids);
223
-        if (empty($filtered_ticket_ids)) {
224
-            throw new DomainException(
225
-                sprintf(
226
-                    esc_html__(
227
-                        'An error occurred while trying to retrieve the ticket IDs for the event.%sPlease click the back button on your browser and try again.',
228
-                        'event_espresso'
229
-                    ),
230
-                    '<br/>'
231
-                )
232
-            );
233
-        }
234
-        // cycle thru values
235
-        foreach ($ticket_ids as $key => $value) {
236
-            // allow only integers
237
-            $this->valid_data[ self::DATA_KEY_TICKET_ID ][ $key ] = absint($value);
238
-        }
239
-    }
19
+	const DATA_KEY_EVENT_ID      = 'id';
20
+
21
+	const DATA_KEY_MAX_ATNDZ     = 'max_atndz';
22
+
23
+	const DATA_KEY_QUANTITY      = 'ticket-selections';
24
+
25
+	const DATA_KEY_RETURN_URL    = 'return_url';
26
+
27
+	const DATA_KEY_ROWS          = 'rows';
28
+
29
+	const DATA_KEY_TICKET_ID     = 'ticket_id';
30
+
31
+	const DATA_KEY_TOTAL_TICKETS = 'total_tickets';
32
+
33
+	const INPUT_KEY_EVENT_ID     = 'tkt-slctr-event-id';
34
+
35
+	const INPUT_KEY_MAX_ATNDZ    = 'tkt-slctr-max-atndz-';
36
+
37
+	const INPUT_KEY_ROWS         = 'tkt-slctr-rows-';
38
+
39
+	const INPUT_KEY_QTY          = 'tkt-slctr-qty-';
40
+
41
+	const INPUT_KEY_TICKET_ID    = 'tkt-slctr-ticket-id-';
42
+
43
+	const INPUT_KEY_RETURN_URL   = 'tkt-slctr-return-url-';
44
+
45
+
46
+	/**
47
+	 * @var int
48
+	 */
49
+	protected $event_id;
50
+
51
+	/**
52
+	 * @var array
53
+	 */
54
+	protected $inputs_to_clean = [];
55
+
56
+	/**
57
+	 * @var array
58
+	 */
59
+	protected $valid_data = [];
60
+
61
+	/**
62
+	 * @var RequestInterface
63
+	 */
64
+	protected $request;
65
+
66
+
67
+	/**
68
+	 * @param RequestInterface $request
69
+	 */
70
+	public function __construct(RequestInterface $request)
71
+	{
72
+		$this->request         = $request;
73
+		$this->inputs_to_clean = [
74
+			self::DATA_KEY_MAX_ATNDZ     => self::INPUT_KEY_MAX_ATNDZ,
75
+			self::DATA_KEY_RETURN_URL    => self::INPUT_KEY_RETURN_URL,
76
+			self::DATA_KEY_ROWS          => self::INPUT_KEY_ROWS,
77
+			self::DATA_KEY_TOTAL_TICKETS => self::INPUT_KEY_TICKET_ID,
78
+			self::DATA_KEY_QUANTITY      => self::INPUT_KEY_QTY,
79
+		];
80
+	}
81
+
82
+
83
+	/**
84
+	 * @return int
85
+	 * @throws DomainException
86
+	 */
87
+	public function getEventId()
88
+	{
89
+		// do we have an event id?
90
+		if ($this->event_id === null) {
91
+			$this->event_id = $this->request->getRequestParam(self::INPUT_KEY_EVENT_ID, 0, 'int');
92
+			if (! $this->event_id) {
93
+				// $_POST['tkt-slctr-event-id'] was not set ?!?!?!?
94
+				throw new DomainException(
95
+					sprintf(
96
+						esc_html__(
97
+							'An event id was not provided or was not received.%sPlease click the back button on your browser and try again.',
98
+							'event_espresso'
99
+						),
100
+						'<br/>'
101
+					)
102
+				);
103
+			}
104
+		}
105
+		// event id is valid
106
+		return $this->event_id;
107
+	}
108
+
109
+
110
+	/**
111
+	 * @return array
112
+	 * @throws DomainException
113
+	 */
114
+	public function validatePostData()
115
+	{
116
+		// grab valid id
117
+		$this->valid_data[ self::DATA_KEY_EVENT_ID ] = $this->getEventId();
118
+		// let's track the total number of tickets ordered.'
119
+		$this->valid_data[ self:: DATA_KEY_TOTAL_TICKETS ] = 0;
120
+		// cycle through $inputs_to_clean array
121
+		foreach ($this->inputs_to_clean as $what => $input_to_clean) {
122
+			$input_key = "{$input_to_clean}{$this->event_id}";
123
+			// check for POST data
124
+			if ($this->request->requestParamIsSet($input_key)) {
125
+				switch ($what) {
126
+					// integers
127
+					case self::DATA_KEY_ROWS:
128
+					case self::DATA_KEY_MAX_ATNDZ:
129
+						$this->processInteger($what, $input_key);
130
+						break;
131
+					// arrays of integers
132
+					case self::DATA_KEY_QUANTITY:
133
+						$this->processQuantity($input_key);
134
+						break;
135
+					// array of integers
136
+					case self::DATA_KEY_TOTAL_TICKETS:
137
+						$this->processTicketIDs($input_key);
138
+						break;
139
+					case self::DATA_KEY_RETURN_URL:
140
+						$this->processReturnURL($input_key);
141
+						break;
142
+				}
143
+			}
144
+		}
145
+		return $this->valid_data;
146
+	}
147
+
148
+
149
+	/**
150
+	 * @param string $what
151
+	 * @param string $input_key
152
+	 */
153
+	protected function processInteger($what, $input_key)
154
+	{
155
+		$this->valid_data[ $what ] = $this->request->getRequestParam($input_key, 0, 'int');
156
+	}
157
+
158
+
159
+	/**
160
+	 * @param string $input_key
161
+	 * @throws DomainException
162
+	 */
163
+	protected function processQuantity($input_key)
164
+	{
165
+		/** @var array $row_qty */
166
+		$row_qty = $this->request->getRequestParam($input_key, [], 'int', true);
167
+		if (empty($row_qty) || ! is_array($row_qty)) {
168
+			throw new DomainException(
169
+				sprintf(
170
+					esc_html__(
171
+						'An error occurred while trying to retrieve the ticket selections for the event.%sPlease click the back button on your browser and try again.',
172
+						'event_espresso'
173
+					),
174
+					'<br/>'
175
+				)
176
+			);
177
+		}
178
+		$max_atndz = $this->valid_data[ self::DATA_KEY_MAX_ATNDZ ];
179
+		// if max attendees is 1 then the incoming row qty array
180
+		// will only have one element and the value will be the ticket ID
181
+		// ex: row qty = [ 0 => TKT_ID ]
182
+		if ($max_atndz === 1 && count($row_qty) === 1) {
183
+			// so we'll grab that ticket ID, use it as the key, and set the value to 1
184
+			// ex: row qty = [ TKT_ID => 1 ]
185
+			$ticket_id = array_pop($row_qty);
186
+			$row_qty = [ $ticket_id => 1 ];
187
+		}
188
+		foreach ($this->valid_data[ self::DATA_KEY_TICKET_ID ] as $ticket_id) {
189
+			$qty = isset($row_qty[ $ticket_id ]) ? $row_qty[ $ticket_id ] : 0;
190
+			$this->valid_data[ self::DATA_KEY_QUANTITY ][ $ticket_id ]     = $qty;
191
+			$this->valid_data[ self:: DATA_KEY_TOTAL_TICKETS ] += $qty;
192
+		}
193
+	}
194
+
195
+
196
+	/**
197
+	 * @param string $input_key
198
+	 */
199
+	protected function processReturnURL($input_key)
200
+	{
201
+		// grab and sanitize return-url
202
+		$input_value = $this->request->getRequestParam($input_key, '', 'url');
203
+		// was the request coming from an iframe ? if so, then:
204
+		if (strpos($input_value, 'event_list=iframe')) {
205
+			// get anchor fragment
206
+			$input_value = explode('#', $input_value);
207
+			$input_value = end($input_value);
208
+			// use event list url instead, but append anchor
209
+			$input_value = EEH_Event_View::event_archive_url() . '#' . $input_value;
210
+		}
211
+		$this->valid_data[ self::DATA_KEY_RETURN_URL ] = $input_value;
212
+	}
213
+
214
+
215
+	/**
216
+	 * @param string $input_key
217
+	 * @throws DomainException
218
+	 */
219
+	protected function processTicketIDs($input_key)
220
+	{
221
+		$ticket_ids          = (array) $this->request->getRequestParam($input_key, [], 'int', true);
222
+		$filtered_ticket_ids = array_filter($ticket_ids);
223
+		if (empty($filtered_ticket_ids)) {
224
+			throw new DomainException(
225
+				sprintf(
226
+					esc_html__(
227
+						'An error occurred while trying to retrieve the ticket IDs for the event.%sPlease click the back button on your browser and try again.',
228
+						'event_espresso'
229
+					),
230
+					'<br/>'
231
+				)
232
+			);
233
+		}
234
+		// cycle thru values
235
+		foreach ($ticket_ids as $key => $value) {
236
+			// allow only integers
237
+			$this->valid_data[ self::DATA_KEY_TICKET_ID ][ $key ] = absint($value);
238
+		}
239
+	}
240 240
 }
Please login to merge, or discard this patch.
Spacing   +13 added lines, -13 removed lines patch added patch discarded remove patch
@@ -89,7 +89,7 @@  discard block
 block discarded – undo
89 89
         // do we have an event id?
90 90
         if ($this->event_id === null) {
91 91
             $this->event_id = $this->request->getRequestParam(self::INPUT_KEY_EVENT_ID, 0, 'int');
92
-            if (! $this->event_id) {
92
+            if ( ! $this->event_id) {
93 93
                 // $_POST['tkt-slctr-event-id'] was not set ?!?!?!?
94 94
                 throw new DomainException(
95 95
                     sprintf(
@@ -114,9 +114,9 @@  discard block
 block discarded – undo
114 114
     public function validatePostData()
115 115
     {
116 116
         // grab valid id
117
-        $this->valid_data[ self::DATA_KEY_EVENT_ID ] = $this->getEventId();
117
+        $this->valid_data[self::DATA_KEY_EVENT_ID] = $this->getEventId();
118 118
         // let's track the total number of tickets ordered.'
119
-        $this->valid_data[ self:: DATA_KEY_TOTAL_TICKETS ] = 0;
119
+        $this->valid_data[self:: DATA_KEY_TOTAL_TICKETS] = 0;
120 120
         // cycle through $inputs_to_clean array
121 121
         foreach ($this->inputs_to_clean as $what => $input_to_clean) {
122 122
             $input_key = "{$input_to_clean}{$this->event_id}";
@@ -152,7 +152,7 @@  discard block
 block discarded – undo
152 152
      */
153 153
     protected function processInteger($what, $input_key)
154 154
     {
155
-        $this->valid_data[ $what ] = $this->request->getRequestParam($input_key, 0, 'int');
155
+        $this->valid_data[$what] = $this->request->getRequestParam($input_key, 0, 'int');
156 156
     }
157 157
 
158 158
 
@@ -175,7 +175,7 @@  discard block
 block discarded – undo
175 175
                 )
176 176
             );
177 177
         }
178
-        $max_atndz = $this->valid_data[ self::DATA_KEY_MAX_ATNDZ ];
178
+        $max_atndz = $this->valid_data[self::DATA_KEY_MAX_ATNDZ];
179 179
         // if max attendees is 1 then the incoming row qty array
180 180
         // will only have one element and the value will be the ticket ID
181 181
         // ex: row qty = [ 0 => TKT_ID ]
@@ -183,12 +183,12 @@  discard block
 block discarded – undo
183 183
             // so we'll grab that ticket ID, use it as the key, and set the value to 1
184 184
             // ex: row qty = [ TKT_ID => 1 ]
185 185
             $ticket_id = array_pop($row_qty);
186
-            $row_qty = [ $ticket_id => 1 ];
186
+            $row_qty = [$ticket_id => 1];
187 187
         }
188
-        foreach ($this->valid_data[ self::DATA_KEY_TICKET_ID ] as $ticket_id) {
189
-            $qty = isset($row_qty[ $ticket_id ]) ? $row_qty[ $ticket_id ] : 0;
190
-            $this->valid_data[ self::DATA_KEY_QUANTITY ][ $ticket_id ]     = $qty;
191
-            $this->valid_data[ self:: DATA_KEY_TOTAL_TICKETS ] += $qty;
188
+        foreach ($this->valid_data[self::DATA_KEY_TICKET_ID] as $ticket_id) {
189
+            $qty = isset($row_qty[$ticket_id]) ? $row_qty[$ticket_id] : 0;
190
+            $this->valid_data[self::DATA_KEY_QUANTITY][$ticket_id] = $qty;
191
+            $this->valid_data[self:: DATA_KEY_TOTAL_TICKETS] += $qty;
192 192
         }
193 193
     }
194 194
 
@@ -206,9 +206,9 @@  discard block
 block discarded – undo
206 206
             $input_value = explode('#', $input_value);
207 207
             $input_value = end($input_value);
208 208
             // use event list url instead, but append anchor
209
-            $input_value = EEH_Event_View::event_archive_url() . '#' . $input_value;
209
+            $input_value = EEH_Event_View::event_archive_url().'#'.$input_value;
210 210
         }
211
-        $this->valid_data[ self::DATA_KEY_RETURN_URL ] = $input_value;
211
+        $this->valid_data[self::DATA_KEY_RETURN_URL] = $input_value;
212 212
     }
213 213
 
214 214
 
@@ -234,7 +234,7 @@  discard block
 block discarded – undo
234 234
         // cycle thru values
235 235
         foreach ($ticket_ids as $key => $value) {
236 236
             // allow only integers
237
-            $this->valid_data[ self::DATA_KEY_TICKET_ID ][ $key ] = absint($value);
237
+            $this->valid_data[self::DATA_KEY_TICKET_ID][$key] = absint($value);
238 238
         }
239 239
     }
240 240
 }
Please login to merge, or discard this patch.
modules/ticket_selector/TicketSelectorRowStandard.php 2 patches
Indentation   +360 added lines, -360 removed lines patch added patch discarded remove patch
@@ -20,364 +20,364 @@
 block discarded – undo
20 20
 class TicketSelectorRowStandard extends TicketSelectorRow
21 21
 {
22 22
 
23
-    /**
24
-     * @var TicketDetails
25
-     */
26
-    protected $ticket_details;
27
-
28
-    /**
29
-     * @var EE_Ticket_Selector_Config
30
-     */
31
-    protected $template_settings;
32
-
33
-    /**
34
-     * @var EE_Tax_Config
35
-     */
36
-    protected $tax_settings;
37
-
38
-    /**
39
-     * @var boolean
40
-     */
41
-    protected $prices_displayed_including_taxes;
42
-
43
-    /**
44
-     * @var int
45
-     */
46
-    protected $row;
47
-
48
-    /**
49
-     * @var int
50
-     */
51
-    protected $cols;
52
-
53
-    /**
54
-     * @var boolean
55
-     */
56
-    protected $hidden_input_qty = false;
57
-
58
-    /**
59
-     * @var string
60
-     */
61
-    protected $ticket_datetime_classes;
62
-
63
-
64
-    /**
65
-     * TicketDetails constructor.
66
-     *
67
-     * @param TicketDetails $ticket_details
68
-     * @param EE_Tax_Config $tax_settings
69
-     * @param int           $total_tickets
70
-     * @param int           $max_attendees
71
-     * @param int           $row
72
-     * @param int           $cols
73
-     * @param boolean       $required_ticket_sold_out
74
-     * @param string        $event_status
75
-     * @param string        $ticket_datetime_classes
76
-     * @throws EE_Error
77
-     * @throws UnexpectedEntityException
78
-     */
79
-    public function __construct(
80
-        TicketDetails $ticket_details,
81
-        EE_Tax_Config $tax_settings,
82
-        $total_tickets,
83
-        $max_attendees,
84
-        $row,
85
-        $cols,
86
-        $required_ticket_sold_out,
87
-        $event_status,
88
-        $ticket_datetime_classes
89
-    ) {
90
-        $this->ticket_details = $ticket_details;
91
-        $this->template_settings = $ticket_details->getTemplateSettings();
92
-        $this->tax_settings = $tax_settings;
93
-        $this->row = $row;
94
-        $this->cols = $cols;
95
-        $this->ticket_datetime_classes = $ticket_datetime_classes;
96
-        parent::__construct(
97
-            $ticket_details->getTicket(),
98
-            $max_attendees,
99
-            $ticket_details->getDateFormat(),
100
-            $event_status,
101
-            $required_ticket_sold_out,
102
-            $total_tickets
103
-        );
104
-    }
105
-
106
-
107
-    /**
108
-     * other ticket rows will need to know if a required ticket is sold out,
109
-     * so that they are not offered for sale
110
-     *
111
-     * @return boolean
112
-     */
113
-    public function getRequiredTicketSoldOut()
114
-    {
115
-        return $this->required_ticket_sold_out;
116
-    }
117
-
118
-
119
-    /**
120
-     * @return int
121
-     */
122
-    public function getCols()
123
-    {
124
-        return $this->cols;
125
-    }
126
-
127
-
128
-    /**
129
-     * getHtml
130
-     *
131
-     * @return string
132
-     * @throws EE_Error
133
-     * @throws ReflectionException
134
-     */
135
-    public function getHtml()
136
-    {
137
-        $this->min = 0;
138
-        $this->max = $this->ticket->max();
139
-        $remaining = $this->ticket->remaining();
140
-        $this->setTicketMinAndMax($remaining);
141
-        // set flag if ticket is required (flag is set to start date so that future tickets are not blocked)
142
-        $this->required_ticket_sold_out = $this->ticket->required() && ! $remaining
143
-            ? $this->ticket->start_date()
144
-            : $this->required_ticket_sold_out;
145
-        $this->setTicketPriceDetails();
146
-        $this->setTicketStatusClasses($remaining);
147
-        $filtered_row_html = $this->getFilteredRowHtml();
148
-        if ($filtered_row_html !== false) {
149
-            return $filtered_row_html;
150
-        }
151
-        $ticket_selector_row_html = EEH_HTML::tr(
152
-            '',
153
-            '',
154
-            "tckt-slctr-tbl-tr {$this->status_class}{$this->ticket_datetime_classes} "
155
-            . espresso_get_object_css_class($this->ticket)
156
-        );
157
-        $filtered_row_content = $this->getFilteredRowContents();
158
-        if ($filtered_row_content !== false) {
159
-            if ($this->max_attendees === 1) {
160
-                return $ticket_selector_row_html
161
-                       . $filtered_row_content
162
-                       . $this->ticketQtyAndIdHiddenInputs()
163
-                       . EEH_HTML::trx();
164
-            }
165
-            return $ticket_selector_row_html
166
-                   . $filtered_row_content
167
-                   . EEH_HTML::trx();
168
-        }
169
-        $this->hidden_input_qty = $this->max_attendees > 1;
170
-
171
-        $ticket_selector_row_html .= $this->ticketNameTableCell();
172
-        $ticket_selector_row_html .= $this->ticketPriceTableCell();
173
-        $ticket_selector_row_html .= EEH_HTML::td(
174
-            '',
175
-            '',
176
-            'tckt-slctr-tbl-td-qty cntr',
177
-            '',
178
-            'headers="quantity-' . $this->EVT_ID . '"'
179
-        );
180
-        $this->setTicketStatusDisplay($remaining);
181
-        if (empty($this->ticket_status_display)) {
182
-            if ($this->max_attendees === 1) {
183
-                // only ONE attendee is allowed to register at a time
184
-                $ticket_selector_row_html .= $this->onlyOneAttendeeCanRegister();
185
-            } elseif ($this->max > 0) {
186
-                $ticket_selector_row_html .= $this->ticketQuantitySelector();
187
-            }
188
-        }
189
-        $ticket_selector_row_html .= $this->ticket_status_display;
190
-        $ticket_selector_row_html .= $this->ticketQtyAndIdHiddenInputs();
191
-        $ticket_selector_row_html .= $this->ticket_details->display(
192
-            $this->ticket_price,
193
-            $remaining,
194
-            $this->cols
195
-        );
196
-        $ticket_selector_row_html .= EEH_HTML::tdx();
197
-        $ticket_selector_row_html .= EEH_HTML::trx();
198
-
199
-
200
-        $this->row++;
201
-        return $ticket_selector_row_html;
202
-    }
203
-
204
-
205
-    /**
206
-     * getTicketPriceDetails
207
-     *
208
-     * @return void
209
-     * @throws EE_Error
210
-     */
211
-    protected function setTicketPriceDetails()
212
-    {
213
-        $this->ticket_price = $this->tax_settings->prices_displayed_including_taxes
214
-            ? $this->ticket->get_ticket_total_with_taxes()
215
-            : $this->ticket->get_ticket_subtotal();
216
-        $this->ticket_bundle = false;
217
-        $ticket_min = $this->ticket->min();
218
-        // for ticket bundles, set min and max qty the same
219
-        if ($ticket_min !== 0 && $ticket_min === $this->ticket->max()) {
220
-            $this->ticket_price *= $ticket_min;
221
-            $this->ticket_bundle = true;
222
-        }
223
-        $this->ticket_price = apply_filters(
224
-            'FHEE__ticket_selector_chart_template__ticket_price',
225
-            $this->ticket_price,
226
-            $this->ticket
227
-        );
228
-    }
229
-
230
-
231
-    /**
232
-     * ticketNameTableCell
233
-     *
234
-     * @return string
235
-     * @throws EE_Error
236
-     * @throws ReflectionException
237
-     */
238
-    protected function ticketNameTableCell()
239
-    {
240
-        $html = EEH_HTML::td(
241
-            '',
242
-            '',
243
-            'tckt-slctr-tbl-td-name',
244
-            '',
245
-            'headers="details-' . $this->EVT_ID . '"'
246
-        );
247
-        $html .= EEH_HTML::strong($this->ticket->get_pretty('TKT_name'));
248
-        $html .= $this->ticket_details->getShowHideLinks();
249
-        if ($this->ticket->required()) {
250
-            $html .= EEH_HTML::p(
251
-                apply_filters(
252
-                    'FHEE__ticket_selector_chart_template__ticket_required_message',
253
-                    esc_html__('This ticket is required and must be purchased.', 'event_espresso')
254
-                ),
255
-                '',
256
-                'ticket-required-pg'
257
-            );
258
-        }
259
-        $html .= EEH_HTML::tdx();
260
-        return $html;
261
-    }
262
-
263
-
264
-    /**
265
-     * ticketPriceTableCell
266
-     *
267
-     * @return string
268
-     * @throws EE_Error
269
-     */
270
-    protected function ticketPriceTableCell()
271
-    {
272
-        $html = '';
273
-        if (apply_filters('FHEE__ticket_selector_chart_template__display_ticket_price_details', true)) {
274
-            $html .= EEH_HTML::td(
275
-                '',
276
-                '',
277
-                'tckt-slctr-tbl-td-price jst-rght',
278
-                '',
279
-                'headers="price-' . $this->EVT_ID . '"'
280
-            );
281
-            $html .= EEH_Template::format_currency($this->ticket_price);
282
-            $html .= $this->ticket->taxable()
283
-                ? EEH_HTML::span('*', '', 'taxable-tickets-asterisk grey-text')
284
-                : '';
285
-            $html .= '&nbsp;';
286
-            // phpcs:disable WordPress.WP.I18n.NoEmptyStrings
287
-            $html .= EEH_HTML::span(
288
-                $this->ticket_bundle
289
-                    ? apply_filters(
290
-                        'FHEE__ticket_selector_chart_template__per_ticket_bundle_text',
291
-                        esc_html__(' / bundle', 'event_espresso')
292
-                    )
293
-                    : apply_filters(
294
-                        'FHEE__ticket_selector_chart_template__per_ticket_text',
295
-                        esc_html__('', 'event_espresso')
296
-                    ),
297
-                '',
298
-                'smaller-text no-bold'
299
-            );
300
-            $html .= '&nbsp;';
301
-            $html .= EEH_HTML::tdx();
302
-            $this->cols++;
303
-        }
304
-        return $html;
305
-    }
306
-
307
-
308
-    /**
309
-     * onlyOneAttendeeCanRegister
310
-     *
311
-     * @return string
312
-     * @throws EE_Error
313
-     */
314
-    protected function onlyOneAttendeeCanRegister()
315
-    {
316
-        $this->hidden_input_qty = false;
317
-        // display submit button since we have tickets available
318
-        add_filter('FHEE__EE_Ticket_Selector__display_ticket_selector_submit', '__return_true');
319
-
320
-        $TKT   = $this->ticket->ID();
321
-        $label = esc_html__('Select this ticket', 'event_espresso');
322
-        $name  = "tkt-slctr-qty-{$this->EVT_ID}[]";
323
-        $class = "ticket-selector-tbl-qty-slct";
324
-        $id    = "{$class}-{$this->EVT_ID}-{$this->row}";
325
-        $checked = $this->total_tickets === 1 ? ' checked="checked"' : '';
326
-
327
-        $html = "<label class='ee-a11y-screen-reader-text' for='{$id}' >{$label}</label>";
328
-        $html .= "<input type='radio'{$checked} name='{$name}' id='{$id}' class='{$class}' value='{$TKT}' title='' />";
329
-        return $html;
330
-    }
331
-
332
-
333
-    /**
334
-     * ticketQuantitySelector
335
-     *
336
-     * @return string
337
-     * @throws EE_Error
338
-     */
339
-    protected function ticketQuantitySelector()
340
-    {
341
-        $this->hidden_input_qty = false;
342
-        // display submit button since we have tickets available
343
-        add_filter('FHEE__EE_Ticket_Selector__display_ticket_selector_submit', '__return_true');
344
-
345
-        $TKT = $this->ticket->ID();
346
-        $label = esc_html__('Quantity', 'event_espresso');
347
-        $class = 'ticket-selector-tbl-qty-slct';
348
-        $id = "{$class}-{$this->EVT_ID}-{$this->row}";
349
-
350
-        $html = "<label class='ee-a11y-screen-reader-text' for='{$id}' >{$label}</label>";
351
-        $html .= "<select name='tkt-slctr-qty-{$this->EVT_ID}[{$TKT}]' id='{$id}' class='{$class}'>";
352
-        // this ensures that non-required tickets with non-zero MIN QTYs don't HAVE to be purchased
353
-        if ($this->min !== 0 && ! $this->ticket->required()) {
354
-            $html .= "<option value='0'>&nbsp;0&nbsp;</option>";
355
-        }
356
-        // offer ticket quantities from the min to the max
357
-        for ($i = $this->min; $i <= $this->max; $i++) {
358
-            $html .= "<option value='{$i}'>&nbsp;{$i}&nbsp;</option>";
359
-        }
360
-        $html .= "</select>";
361
-        return $html;
362
-    }
363
-
364
-
365
-    /**
366
-     * getHiddenInputs
367
-     *
368
-     * @return string
369
-     * @throws EE_Error
370
-     */
371
-    protected function ticketQtyAndIdHiddenInputs()
372
-    {
373
-        $html = '';
374
-        $EVT = $this->EVT_ID;
375
-        $TKT = $this->ticket->ID();
376
-        // depending on group reg we need to change the format for qty
377
-        if ($this->hidden_input_qty) {
378
-            $html .= "<input type='hidden' name='tkt-slctr-qty-{$EVT}[]' value='0' />";
379
-        }
380
-        $html .= "<input type='hidden' name='tkt-slctr-ticket-id-{$EVT}[]' value='{$TKT}' />";
381
-        return $html;
382
-    }
23
+	/**
24
+	 * @var TicketDetails
25
+	 */
26
+	protected $ticket_details;
27
+
28
+	/**
29
+	 * @var EE_Ticket_Selector_Config
30
+	 */
31
+	protected $template_settings;
32
+
33
+	/**
34
+	 * @var EE_Tax_Config
35
+	 */
36
+	protected $tax_settings;
37
+
38
+	/**
39
+	 * @var boolean
40
+	 */
41
+	protected $prices_displayed_including_taxes;
42
+
43
+	/**
44
+	 * @var int
45
+	 */
46
+	protected $row;
47
+
48
+	/**
49
+	 * @var int
50
+	 */
51
+	protected $cols;
52
+
53
+	/**
54
+	 * @var boolean
55
+	 */
56
+	protected $hidden_input_qty = false;
57
+
58
+	/**
59
+	 * @var string
60
+	 */
61
+	protected $ticket_datetime_classes;
62
+
63
+
64
+	/**
65
+	 * TicketDetails constructor.
66
+	 *
67
+	 * @param TicketDetails $ticket_details
68
+	 * @param EE_Tax_Config $tax_settings
69
+	 * @param int           $total_tickets
70
+	 * @param int           $max_attendees
71
+	 * @param int           $row
72
+	 * @param int           $cols
73
+	 * @param boolean       $required_ticket_sold_out
74
+	 * @param string        $event_status
75
+	 * @param string        $ticket_datetime_classes
76
+	 * @throws EE_Error
77
+	 * @throws UnexpectedEntityException
78
+	 */
79
+	public function __construct(
80
+		TicketDetails $ticket_details,
81
+		EE_Tax_Config $tax_settings,
82
+		$total_tickets,
83
+		$max_attendees,
84
+		$row,
85
+		$cols,
86
+		$required_ticket_sold_out,
87
+		$event_status,
88
+		$ticket_datetime_classes
89
+	) {
90
+		$this->ticket_details = $ticket_details;
91
+		$this->template_settings = $ticket_details->getTemplateSettings();
92
+		$this->tax_settings = $tax_settings;
93
+		$this->row = $row;
94
+		$this->cols = $cols;
95
+		$this->ticket_datetime_classes = $ticket_datetime_classes;
96
+		parent::__construct(
97
+			$ticket_details->getTicket(),
98
+			$max_attendees,
99
+			$ticket_details->getDateFormat(),
100
+			$event_status,
101
+			$required_ticket_sold_out,
102
+			$total_tickets
103
+		);
104
+	}
105
+
106
+
107
+	/**
108
+	 * other ticket rows will need to know if a required ticket is sold out,
109
+	 * so that they are not offered for sale
110
+	 *
111
+	 * @return boolean
112
+	 */
113
+	public function getRequiredTicketSoldOut()
114
+	{
115
+		return $this->required_ticket_sold_out;
116
+	}
117
+
118
+
119
+	/**
120
+	 * @return int
121
+	 */
122
+	public function getCols()
123
+	{
124
+		return $this->cols;
125
+	}
126
+
127
+
128
+	/**
129
+	 * getHtml
130
+	 *
131
+	 * @return string
132
+	 * @throws EE_Error
133
+	 * @throws ReflectionException
134
+	 */
135
+	public function getHtml()
136
+	{
137
+		$this->min = 0;
138
+		$this->max = $this->ticket->max();
139
+		$remaining = $this->ticket->remaining();
140
+		$this->setTicketMinAndMax($remaining);
141
+		// set flag if ticket is required (flag is set to start date so that future tickets are not blocked)
142
+		$this->required_ticket_sold_out = $this->ticket->required() && ! $remaining
143
+			? $this->ticket->start_date()
144
+			: $this->required_ticket_sold_out;
145
+		$this->setTicketPriceDetails();
146
+		$this->setTicketStatusClasses($remaining);
147
+		$filtered_row_html = $this->getFilteredRowHtml();
148
+		if ($filtered_row_html !== false) {
149
+			return $filtered_row_html;
150
+		}
151
+		$ticket_selector_row_html = EEH_HTML::tr(
152
+			'',
153
+			'',
154
+			"tckt-slctr-tbl-tr {$this->status_class}{$this->ticket_datetime_classes} "
155
+			. espresso_get_object_css_class($this->ticket)
156
+		);
157
+		$filtered_row_content = $this->getFilteredRowContents();
158
+		if ($filtered_row_content !== false) {
159
+			if ($this->max_attendees === 1) {
160
+				return $ticket_selector_row_html
161
+					   . $filtered_row_content
162
+					   . $this->ticketQtyAndIdHiddenInputs()
163
+					   . EEH_HTML::trx();
164
+			}
165
+			return $ticket_selector_row_html
166
+				   . $filtered_row_content
167
+				   . EEH_HTML::trx();
168
+		}
169
+		$this->hidden_input_qty = $this->max_attendees > 1;
170
+
171
+		$ticket_selector_row_html .= $this->ticketNameTableCell();
172
+		$ticket_selector_row_html .= $this->ticketPriceTableCell();
173
+		$ticket_selector_row_html .= EEH_HTML::td(
174
+			'',
175
+			'',
176
+			'tckt-slctr-tbl-td-qty cntr',
177
+			'',
178
+			'headers="quantity-' . $this->EVT_ID . '"'
179
+		);
180
+		$this->setTicketStatusDisplay($remaining);
181
+		if (empty($this->ticket_status_display)) {
182
+			if ($this->max_attendees === 1) {
183
+				// only ONE attendee is allowed to register at a time
184
+				$ticket_selector_row_html .= $this->onlyOneAttendeeCanRegister();
185
+			} elseif ($this->max > 0) {
186
+				$ticket_selector_row_html .= $this->ticketQuantitySelector();
187
+			}
188
+		}
189
+		$ticket_selector_row_html .= $this->ticket_status_display;
190
+		$ticket_selector_row_html .= $this->ticketQtyAndIdHiddenInputs();
191
+		$ticket_selector_row_html .= $this->ticket_details->display(
192
+			$this->ticket_price,
193
+			$remaining,
194
+			$this->cols
195
+		);
196
+		$ticket_selector_row_html .= EEH_HTML::tdx();
197
+		$ticket_selector_row_html .= EEH_HTML::trx();
198
+
199
+
200
+		$this->row++;
201
+		return $ticket_selector_row_html;
202
+	}
203
+
204
+
205
+	/**
206
+	 * getTicketPriceDetails
207
+	 *
208
+	 * @return void
209
+	 * @throws EE_Error
210
+	 */
211
+	protected function setTicketPriceDetails()
212
+	{
213
+		$this->ticket_price = $this->tax_settings->prices_displayed_including_taxes
214
+			? $this->ticket->get_ticket_total_with_taxes()
215
+			: $this->ticket->get_ticket_subtotal();
216
+		$this->ticket_bundle = false;
217
+		$ticket_min = $this->ticket->min();
218
+		// for ticket bundles, set min and max qty the same
219
+		if ($ticket_min !== 0 && $ticket_min === $this->ticket->max()) {
220
+			$this->ticket_price *= $ticket_min;
221
+			$this->ticket_bundle = true;
222
+		}
223
+		$this->ticket_price = apply_filters(
224
+			'FHEE__ticket_selector_chart_template__ticket_price',
225
+			$this->ticket_price,
226
+			$this->ticket
227
+		);
228
+	}
229
+
230
+
231
+	/**
232
+	 * ticketNameTableCell
233
+	 *
234
+	 * @return string
235
+	 * @throws EE_Error
236
+	 * @throws ReflectionException
237
+	 */
238
+	protected function ticketNameTableCell()
239
+	{
240
+		$html = EEH_HTML::td(
241
+			'',
242
+			'',
243
+			'tckt-slctr-tbl-td-name',
244
+			'',
245
+			'headers="details-' . $this->EVT_ID . '"'
246
+		);
247
+		$html .= EEH_HTML::strong($this->ticket->get_pretty('TKT_name'));
248
+		$html .= $this->ticket_details->getShowHideLinks();
249
+		if ($this->ticket->required()) {
250
+			$html .= EEH_HTML::p(
251
+				apply_filters(
252
+					'FHEE__ticket_selector_chart_template__ticket_required_message',
253
+					esc_html__('This ticket is required and must be purchased.', 'event_espresso')
254
+				),
255
+				'',
256
+				'ticket-required-pg'
257
+			);
258
+		}
259
+		$html .= EEH_HTML::tdx();
260
+		return $html;
261
+	}
262
+
263
+
264
+	/**
265
+	 * ticketPriceTableCell
266
+	 *
267
+	 * @return string
268
+	 * @throws EE_Error
269
+	 */
270
+	protected function ticketPriceTableCell()
271
+	{
272
+		$html = '';
273
+		if (apply_filters('FHEE__ticket_selector_chart_template__display_ticket_price_details', true)) {
274
+			$html .= EEH_HTML::td(
275
+				'',
276
+				'',
277
+				'tckt-slctr-tbl-td-price jst-rght',
278
+				'',
279
+				'headers="price-' . $this->EVT_ID . '"'
280
+			);
281
+			$html .= EEH_Template::format_currency($this->ticket_price);
282
+			$html .= $this->ticket->taxable()
283
+				? EEH_HTML::span('*', '', 'taxable-tickets-asterisk grey-text')
284
+				: '';
285
+			$html .= '&nbsp;';
286
+			// phpcs:disable WordPress.WP.I18n.NoEmptyStrings
287
+			$html .= EEH_HTML::span(
288
+				$this->ticket_bundle
289
+					? apply_filters(
290
+						'FHEE__ticket_selector_chart_template__per_ticket_bundle_text',
291
+						esc_html__(' / bundle', 'event_espresso')
292
+					)
293
+					: apply_filters(
294
+						'FHEE__ticket_selector_chart_template__per_ticket_text',
295
+						esc_html__('', 'event_espresso')
296
+					),
297
+				'',
298
+				'smaller-text no-bold'
299
+			);
300
+			$html .= '&nbsp;';
301
+			$html .= EEH_HTML::tdx();
302
+			$this->cols++;
303
+		}
304
+		return $html;
305
+	}
306
+
307
+
308
+	/**
309
+	 * onlyOneAttendeeCanRegister
310
+	 *
311
+	 * @return string
312
+	 * @throws EE_Error
313
+	 */
314
+	protected function onlyOneAttendeeCanRegister()
315
+	{
316
+		$this->hidden_input_qty = false;
317
+		// display submit button since we have tickets available
318
+		add_filter('FHEE__EE_Ticket_Selector__display_ticket_selector_submit', '__return_true');
319
+
320
+		$TKT   = $this->ticket->ID();
321
+		$label = esc_html__('Select this ticket', 'event_espresso');
322
+		$name  = "tkt-slctr-qty-{$this->EVT_ID}[]";
323
+		$class = "ticket-selector-tbl-qty-slct";
324
+		$id    = "{$class}-{$this->EVT_ID}-{$this->row}";
325
+		$checked = $this->total_tickets === 1 ? ' checked="checked"' : '';
326
+
327
+		$html = "<label class='ee-a11y-screen-reader-text' for='{$id}' >{$label}</label>";
328
+		$html .= "<input type='radio'{$checked} name='{$name}' id='{$id}' class='{$class}' value='{$TKT}' title='' />";
329
+		return $html;
330
+	}
331
+
332
+
333
+	/**
334
+	 * ticketQuantitySelector
335
+	 *
336
+	 * @return string
337
+	 * @throws EE_Error
338
+	 */
339
+	protected function ticketQuantitySelector()
340
+	{
341
+		$this->hidden_input_qty = false;
342
+		// display submit button since we have tickets available
343
+		add_filter('FHEE__EE_Ticket_Selector__display_ticket_selector_submit', '__return_true');
344
+
345
+		$TKT = $this->ticket->ID();
346
+		$label = esc_html__('Quantity', 'event_espresso');
347
+		$class = 'ticket-selector-tbl-qty-slct';
348
+		$id = "{$class}-{$this->EVT_ID}-{$this->row}";
349
+
350
+		$html = "<label class='ee-a11y-screen-reader-text' for='{$id}' >{$label}</label>";
351
+		$html .= "<select name='tkt-slctr-qty-{$this->EVT_ID}[{$TKT}]' id='{$id}' class='{$class}'>";
352
+		// this ensures that non-required tickets with non-zero MIN QTYs don't HAVE to be purchased
353
+		if ($this->min !== 0 && ! $this->ticket->required()) {
354
+			$html .= "<option value='0'>&nbsp;0&nbsp;</option>";
355
+		}
356
+		// offer ticket quantities from the min to the max
357
+		for ($i = $this->min; $i <= $this->max; $i++) {
358
+			$html .= "<option value='{$i}'>&nbsp;{$i}&nbsp;</option>";
359
+		}
360
+		$html .= "</select>";
361
+		return $html;
362
+	}
363
+
364
+
365
+	/**
366
+	 * getHiddenInputs
367
+	 *
368
+	 * @return string
369
+	 * @throws EE_Error
370
+	 */
371
+	protected function ticketQtyAndIdHiddenInputs()
372
+	{
373
+		$html = '';
374
+		$EVT = $this->EVT_ID;
375
+		$TKT = $this->ticket->ID();
376
+		// depending on group reg we need to change the format for qty
377
+		if ($this->hidden_input_qty) {
378
+			$html .= "<input type='hidden' name='tkt-slctr-qty-{$EVT}[]' value='0' />";
379
+		}
380
+		$html .= "<input type='hidden' name='tkt-slctr-ticket-id-{$EVT}[]' value='{$TKT}' />";
381
+		return $html;
382
+	}
383 383
 }
Please login to merge, or discard this patch.
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -175,7 +175,7 @@  discard block
 block discarded – undo
175 175
             '',
176 176
             'tckt-slctr-tbl-td-qty cntr',
177 177
             '',
178
-            'headers="quantity-' . $this->EVT_ID . '"'
178
+            'headers="quantity-'.$this->EVT_ID.'"'
179 179
         );
180 180
         $this->setTicketStatusDisplay($remaining);
181 181
         if (empty($this->ticket_status_display)) {
@@ -242,7 +242,7 @@  discard block
 block discarded – undo
242 242
             '',
243 243
             'tckt-slctr-tbl-td-name',
244 244
             '',
245
-            'headers="details-' . $this->EVT_ID . '"'
245
+            'headers="details-'.$this->EVT_ID.'"'
246 246
         );
247 247
         $html .= EEH_HTML::strong($this->ticket->get_pretty('TKT_name'));
248 248
         $html .= $this->ticket_details->getShowHideLinks();
@@ -276,7 +276,7 @@  discard block
 block discarded – undo
276 276
                 '',
277 277
                 'tckt-slctr-tbl-td-price jst-rght',
278 278
                 '',
279
-                'headers="price-' . $this->EVT_ID . '"'
279
+                'headers="price-'.$this->EVT_ID.'"'
280 280
             );
281 281
             $html .= EEH_Template::format_currency($this->ticket_price);
282 282
             $html .= $this->ticket->taxable()
Please login to merge, or discard this patch.