@@ -33,526 +33,526 @@ |
||
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 | - /** @var LoaderInterface $loader */ |
|
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 Request |
|
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 | - } |
|
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 | + /** @var LoaderInterface $loader */ |
|
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 Request |
|
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 | - */ |
|
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 | - } |
|
109 | + /** |
|
110 | + * cancelTicketSelections |
|
111 | + * |
|
112 | + * @return bool |
|
113 | + * @throws EE_Error |
|
114 | + * @throws InvalidArgumentException |
|
115 | + * @throws InvalidInterfaceException |
|
116 | + * @throws InvalidDataTypeException |
|
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 array|bool |
|
180 | - * @throws EE_Error |
|
181 | - * @throws InvalidArgumentException |
|
182 | - * @throws InvalidDataTypeException |
|
183 | - * @throws InvalidInterfaceException |
|
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 | - // do we have an event id? |
|
197 | - $id = $this->getEventId(); |
|
198 | - // we should really only have 1 registration in the works now |
|
199 | - // (ie, no MER) so unless otherwise requested, clear the session |
|
200 | - if (apply_filters('FHEE__EE_Ticket_Selector__process_ticket_selections__clear_session', true)) { |
|
201 | - $this->session->clear_session(__CLASS__, __FUNCTION__); |
|
202 | - } |
|
203 | - // validate/sanitize/filter data |
|
204 | - $valid = apply_filters( |
|
205 | - 'FHEE__EED_Ticket_Selector__process_ticket_selections__valid_post_data', |
|
206 | - $this->validatePostData($id) |
|
207 | - ); |
|
208 | - // check total tickets ordered vs max number of attendees that can register |
|
209 | - if ($valid['total_tickets'] > $valid['max_atndz']) { |
|
210 | - $this->maxAttendeesViolation($valid); |
|
211 | - } else { |
|
212 | - // all data appears to be valid |
|
213 | - if ($this->processSuccessfulCart($this->addTicketsToCart($valid))) { |
|
214 | - return true; |
|
215 | - } |
|
216 | - } |
|
217 | - // die(); // <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< KILL BEFORE REDIRECT |
|
218 | - // at this point, just return if registration is being made from admin |
|
219 | - if ($this->request->isAdmin() || $this->request->isFrontAjax()) { |
|
220 | - return false; |
|
221 | - } |
|
222 | - if ($valid['return_url']) { |
|
223 | - EEH_URL::safeRedirectAndExit($valid['return_url']); |
|
224 | - } |
|
225 | - if ($id) { |
|
226 | - EEH_URL::safeRedirectAndExit(get_permalink($id)); |
|
227 | - } |
|
228 | - echo EE_Error::get_notices(); |
|
229 | - return false; |
|
230 | - } |
|
176 | + /** |
|
177 | + * process_ticket_selections |
|
178 | + * |
|
179 | + * @return array|bool |
|
180 | + * @throws EE_Error |
|
181 | + * @throws InvalidArgumentException |
|
182 | + * @throws InvalidDataTypeException |
|
183 | + * @throws InvalidInterfaceException |
|
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 | + // do we have an event id? |
|
197 | + $id = $this->getEventId(); |
|
198 | + // we should really only have 1 registration in the works now |
|
199 | + // (ie, no MER) so unless otherwise requested, clear the session |
|
200 | + if (apply_filters('FHEE__EE_Ticket_Selector__process_ticket_selections__clear_session', true)) { |
|
201 | + $this->session->clear_session(__CLASS__, __FUNCTION__); |
|
202 | + } |
|
203 | + // validate/sanitize/filter data |
|
204 | + $valid = apply_filters( |
|
205 | + 'FHEE__EED_Ticket_Selector__process_ticket_selections__valid_post_data', |
|
206 | + $this->validatePostData($id) |
|
207 | + ); |
|
208 | + // check total tickets ordered vs max number of attendees that can register |
|
209 | + if ($valid['total_tickets'] > $valid['max_atndz']) { |
|
210 | + $this->maxAttendeesViolation($valid); |
|
211 | + } else { |
|
212 | + // all data appears to be valid |
|
213 | + if ($this->processSuccessfulCart($this->addTicketsToCart($valid))) { |
|
214 | + return true; |
|
215 | + } |
|
216 | + } |
|
217 | + // die(); // <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< KILL BEFORE REDIRECT |
|
218 | + // at this point, just return if registration is being made from admin |
|
219 | + if ($this->request->isAdmin() || $this->request->isFrontAjax()) { |
|
220 | + return false; |
|
221 | + } |
|
222 | + if ($valid['return_url']) { |
|
223 | + EEH_URL::safeRedirectAndExit($valid['return_url']); |
|
224 | + } |
|
225 | + if ($id) { |
|
226 | + EEH_URL::safeRedirectAndExit(get_permalink($id)); |
|
227 | + } |
|
228 | + echo EE_Error::get_notices(); |
|
229 | + return false; |
|
230 | + } |
|
231 | 231 | |
232 | 232 | |
233 | - /** |
|
234 | - * @return int |
|
235 | - */ |
|
236 | - private function getEventId() |
|
237 | - { |
|
238 | - // do we have an event id? |
|
239 | - if (! $this->request->requestParamIsSet('tkt-slctr-event-id')) { |
|
240 | - // $_POST['tkt-slctr-event-id'] was not set ?!?!?!? |
|
241 | - EE_Error::add_error( |
|
242 | - sprintf( |
|
243 | - esc_html__( |
|
244 | - 'An event id was not provided or was not received.%sPlease click the back button on your browser and try again.', |
|
245 | - 'event_espresso' |
|
246 | - ), |
|
247 | - '<br/>' |
|
248 | - ), |
|
249 | - __FILE__, |
|
250 | - __FUNCTION__, |
|
251 | - __LINE__ |
|
252 | - ); |
|
253 | - } |
|
254 | - // if event id is valid |
|
255 | - return absint($this->request->getRequestParam('tkt-slctr-event-id')); |
|
256 | - } |
|
233 | + /** |
|
234 | + * @return int |
|
235 | + */ |
|
236 | + private function getEventId() |
|
237 | + { |
|
238 | + // do we have an event id? |
|
239 | + if (! $this->request->requestParamIsSet('tkt-slctr-event-id')) { |
|
240 | + // $_POST['tkt-slctr-event-id'] was not set ?!?!?!? |
|
241 | + EE_Error::add_error( |
|
242 | + sprintf( |
|
243 | + esc_html__( |
|
244 | + 'An event id was not provided or was not received.%sPlease click the back button on your browser and try again.', |
|
245 | + 'event_espresso' |
|
246 | + ), |
|
247 | + '<br/>' |
|
248 | + ), |
|
249 | + __FILE__, |
|
250 | + __FUNCTION__, |
|
251 | + __LINE__ |
|
252 | + ); |
|
253 | + } |
|
254 | + // if event id is valid |
|
255 | + return absint($this->request->getRequestParam('tkt-slctr-event-id')); |
|
256 | + } |
|
257 | 257 | |
258 | 258 | |
259 | - /** |
|
260 | - * validate_post_data |
|
261 | - * |
|
262 | - * @param int $id |
|
263 | - * @return array |
|
264 | - */ |
|
265 | - private function validatePostData($id = 0) |
|
266 | - { |
|
267 | - if (! $id) { |
|
268 | - EE_Error::add_error( |
|
269 | - esc_html__('The event id provided was not valid.', 'event_espresso'), |
|
270 | - __FILE__, |
|
271 | - __FUNCTION__, |
|
272 | - __LINE__ |
|
273 | - ); |
|
274 | - return array(); |
|
275 | - } |
|
276 | - // start with an empty array() |
|
277 | - $valid_data = array(); |
|
278 | - // grab valid id |
|
279 | - $valid_data['id'] = $id; |
|
280 | - // array of other form names |
|
281 | - $inputs_to_clean = array( |
|
282 | - 'event_id' => 'tkt-slctr-event-id', |
|
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 | - $input_value = $this->request->getRequestParam($input_to_clean . $id); |
|
297 | - switch ($what) { |
|
298 | - // integers |
|
299 | - case 'event_id': |
|
300 | - $valid_data[ $what ] = absint($input_value); |
|
301 | - // get event via the event id we put in the form |
|
302 | - break; |
|
303 | - case 'rows': |
|
304 | - case 'max_atndz': |
|
305 | - $valid_data[ $what ] = absint($input_value); |
|
306 | - break; |
|
307 | - // arrays of integers |
|
308 | - case 'qty': |
|
309 | - /** @var array $row_qty */ |
|
310 | - $row_qty = $input_value; |
|
311 | - // if qty is coming from a radio button input, then we need to assemble an array of rows |
|
312 | - if (! is_array($row_qty)) { |
|
313 | - /** @var string $row_qty */ |
|
314 | - // get number of rows |
|
315 | - $rows = $this->request->requestParamIsSet('tkt-slctr-rows-' . $id) |
|
316 | - ? absint($this->request->getRequestParam('tkt-slctr-rows-' . $id)) |
|
317 | - : 1; |
|
318 | - // explode integers by the dash |
|
319 | - $row_qty = explode('-', $row_qty); |
|
320 | - $row = isset($row_qty[0]) ? absint($row_qty[0]) : 1; |
|
321 | - $qty = isset($row_qty[1]) ? absint($row_qty[1]) : 0; |
|
322 | - $row_qty = array($row => $qty); |
|
323 | - for ($x = 1; $x <= $rows; $x++) { |
|
324 | - if (! isset($row_qty[ $x ])) { |
|
325 | - $row_qty[ $x ] = 0; |
|
326 | - } |
|
327 | - } |
|
328 | - } |
|
329 | - ksort($row_qty); |
|
330 | - // cycle thru values |
|
331 | - foreach ($row_qty as $qty) { |
|
332 | - $qty = absint($qty); |
|
333 | - // sanitize as integers |
|
334 | - $valid_data[ $what ][] = $qty; |
|
335 | - $valid_data['total_tickets'] += $qty; |
|
336 | - } |
|
337 | - break; |
|
338 | - // array of integers |
|
339 | - case 'ticket_id': |
|
340 | - // cycle thru values |
|
341 | - foreach ((array) $input_value as $key => $value) { |
|
342 | - // allow only integers |
|
343 | - $valid_data[ $what ][ $key ] = absint($value); |
|
344 | - } |
|
345 | - break; |
|
346 | - case 'return_url': |
|
347 | - // grab and sanitize return-url |
|
348 | - $input_value = esc_url_raw($input_value); |
|
349 | - // was the request coming from an iframe ? if so, then: |
|
350 | - if (strpos($input_value, 'event_list=iframe')) { |
|
351 | - // get anchor fragment |
|
352 | - $input_value = explode('#', $input_value); |
|
353 | - $input_value = end($input_value); |
|
354 | - // use event list url instead, but append anchor |
|
355 | - $input_value = EEH_Event_View::event_archive_url() . '#' . $input_value; |
|
356 | - } |
|
357 | - $valid_data[ $what ] = $input_value; |
|
358 | - break; |
|
359 | - } // end switch $what |
|
360 | - } |
|
361 | - } // end foreach $inputs_to_clean |
|
362 | - return $valid_data; |
|
363 | - } |
|
259 | + /** |
|
260 | + * validate_post_data |
|
261 | + * |
|
262 | + * @param int $id |
|
263 | + * @return array |
|
264 | + */ |
|
265 | + private function validatePostData($id = 0) |
|
266 | + { |
|
267 | + if (! $id) { |
|
268 | + EE_Error::add_error( |
|
269 | + esc_html__('The event id provided was not valid.', 'event_espresso'), |
|
270 | + __FILE__, |
|
271 | + __FUNCTION__, |
|
272 | + __LINE__ |
|
273 | + ); |
|
274 | + return array(); |
|
275 | + } |
|
276 | + // start with an empty array() |
|
277 | + $valid_data = array(); |
|
278 | + // grab valid id |
|
279 | + $valid_data['id'] = $id; |
|
280 | + // array of other form names |
|
281 | + $inputs_to_clean = array( |
|
282 | + 'event_id' => 'tkt-slctr-event-id', |
|
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 | + $input_value = $this->request->getRequestParam($input_to_clean . $id); |
|
297 | + switch ($what) { |
|
298 | + // integers |
|
299 | + case 'event_id': |
|
300 | + $valid_data[ $what ] = absint($input_value); |
|
301 | + // get event via the event id we put in the form |
|
302 | + break; |
|
303 | + case 'rows': |
|
304 | + case 'max_atndz': |
|
305 | + $valid_data[ $what ] = absint($input_value); |
|
306 | + break; |
|
307 | + // arrays of integers |
|
308 | + case 'qty': |
|
309 | + /** @var array $row_qty */ |
|
310 | + $row_qty = $input_value; |
|
311 | + // if qty is coming from a radio button input, then we need to assemble an array of rows |
|
312 | + if (! is_array($row_qty)) { |
|
313 | + /** @var string $row_qty */ |
|
314 | + // get number of rows |
|
315 | + $rows = $this->request->requestParamIsSet('tkt-slctr-rows-' . $id) |
|
316 | + ? absint($this->request->getRequestParam('tkt-slctr-rows-' . $id)) |
|
317 | + : 1; |
|
318 | + // explode integers by the dash |
|
319 | + $row_qty = explode('-', $row_qty); |
|
320 | + $row = isset($row_qty[0]) ? absint($row_qty[0]) : 1; |
|
321 | + $qty = isset($row_qty[1]) ? absint($row_qty[1]) : 0; |
|
322 | + $row_qty = array($row => $qty); |
|
323 | + for ($x = 1; $x <= $rows; $x++) { |
|
324 | + if (! isset($row_qty[ $x ])) { |
|
325 | + $row_qty[ $x ] = 0; |
|
326 | + } |
|
327 | + } |
|
328 | + } |
|
329 | + ksort($row_qty); |
|
330 | + // cycle thru values |
|
331 | + foreach ($row_qty as $qty) { |
|
332 | + $qty = absint($qty); |
|
333 | + // sanitize as integers |
|
334 | + $valid_data[ $what ][] = $qty; |
|
335 | + $valid_data['total_tickets'] += $qty; |
|
336 | + } |
|
337 | + break; |
|
338 | + // array of integers |
|
339 | + case 'ticket_id': |
|
340 | + // cycle thru values |
|
341 | + foreach ((array) $input_value as $key => $value) { |
|
342 | + // allow only integers |
|
343 | + $valid_data[ $what ][ $key ] = absint($value); |
|
344 | + } |
|
345 | + break; |
|
346 | + case 'return_url': |
|
347 | + // grab and sanitize return-url |
|
348 | + $input_value = esc_url_raw($input_value); |
|
349 | + // was the request coming from an iframe ? if so, then: |
|
350 | + if (strpos($input_value, 'event_list=iframe')) { |
|
351 | + // get anchor fragment |
|
352 | + $input_value = explode('#', $input_value); |
|
353 | + $input_value = end($input_value); |
|
354 | + // use event list url instead, but append anchor |
|
355 | + $input_value = EEH_Event_View::event_archive_url() . '#' . $input_value; |
|
356 | + } |
|
357 | + $valid_data[ $what ] = $input_value; |
|
358 | + break; |
|
359 | + } // end switch $what |
|
360 | + } |
|
361 | + } // end foreach $inputs_to_clean |
|
362 | + return $valid_data; |
|
363 | + } |
|
364 | 364 | |
365 | 365 | |
366 | - /** |
|
367 | - * @param array $valid |
|
368 | - */ |
|
369 | - private function maxAttendeesViolation(array $valid) |
|
370 | - { |
|
371 | - // ordering too many tickets !!! |
|
372 | - $total_tickets_string = esc_html( |
|
373 | - _n( |
|
374 | - 'You have attempted to purchase %s ticket.', |
|
375 | - 'You have attempted to purchase %s tickets.', |
|
376 | - $valid['total_tickets'], |
|
377 | - 'event_espresso' |
|
378 | - ) |
|
379 | - ); |
|
380 | - $limit_error_1 = sprintf($total_tickets_string, $valid['total_tickets']); |
|
381 | - // dev only message |
|
382 | - $max_attendees_string = esc_html( |
|
383 | - _n( |
|
384 | - '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.', |
|
385 | - '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.', |
|
386 | - $valid['max_atndz'], |
|
387 | - 'event_espresso' |
|
388 | - ) |
|
389 | - ); |
|
390 | - $limit_error_2 = sprintf($max_attendees_string, $valid['max_atndz'], $valid['max_atndz']); |
|
391 | - EE_Error::add_error($limit_error_1 . '<br/>' . $limit_error_2, __FILE__, __FUNCTION__, __LINE__); |
|
392 | - } |
|
366 | + /** |
|
367 | + * @param array $valid |
|
368 | + */ |
|
369 | + private function maxAttendeesViolation(array $valid) |
|
370 | + { |
|
371 | + // ordering too many tickets !!! |
|
372 | + $total_tickets_string = esc_html( |
|
373 | + _n( |
|
374 | + 'You have attempted to purchase %s ticket.', |
|
375 | + 'You have attempted to purchase %s tickets.', |
|
376 | + $valid['total_tickets'], |
|
377 | + 'event_espresso' |
|
378 | + ) |
|
379 | + ); |
|
380 | + $limit_error_1 = sprintf($total_tickets_string, $valid['total_tickets']); |
|
381 | + // dev only message |
|
382 | + $max_attendees_string = esc_html( |
|
383 | + _n( |
|
384 | + '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.', |
|
385 | + '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.', |
|
386 | + $valid['max_atndz'], |
|
387 | + 'event_espresso' |
|
388 | + ) |
|
389 | + ); |
|
390 | + $limit_error_2 = sprintf($max_attendees_string, $valid['max_atndz'], $valid['max_atndz']); |
|
391 | + EE_Error::add_error($limit_error_1 . '<br/>' . $limit_error_2, __FILE__, __FUNCTION__, __LINE__); |
|
392 | + } |
|
393 | 393 | |
394 | 394 | |
395 | - /** |
|
396 | - * @param array $valid |
|
397 | - * @return int |
|
398 | - * @throws EE_Error |
|
399 | - * @throws InvalidArgumentException |
|
400 | - * @throws InvalidDataTypeException |
|
401 | - * @throws InvalidInterfaceException |
|
402 | - */ |
|
403 | - private function addTicketsToCart(array $valid) |
|
404 | - { |
|
405 | - $tickets_added = 0; |
|
406 | - $tickets_selected = false; |
|
407 | - if (! empty($valid) && $valid['total_tickets'] > 0) { |
|
408 | - // load cart using factory because we don't want to do so until actually needed |
|
409 | - $this->cart = CartFactory::getCart(); |
|
410 | - // cycle thru the number of data rows sent from the event listing |
|
411 | - for ($x = 0; $x < $valid['rows']; $x++) { |
|
412 | - // does this row actually contain a ticket quantity? |
|
413 | - if (isset($valid['qty'][ $x ]) && $valid['qty'][ $x ] > 0) { |
|
414 | - // YES we have a ticket quantity |
|
415 | - $tickets_selected = true; |
|
416 | - $valid_ticket = false; |
|
417 | - // \EEH_Debug_Tools::printr( |
|
418 | - // $valid['ticket_id'][ $x ], |
|
419 | - // '$valid[\'ticket_id\'][ $x ]', |
|
420 | - // __FILE__, __LINE__ |
|
421 | - // ); |
|
422 | - if (isset($valid['ticket_id'][ $x ])) { |
|
423 | - // get ticket via the ticket id we put in the form |
|
424 | - $ticket = $this->ticket_model->get_one_by_ID($valid['ticket_id'][ $x ]); |
|
425 | - if ($ticket instanceof EE_Ticket) { |
|
426 | - $valid_ticket = true; |
|
427 | - $tickets_added += $this->addTicketToCart( |
|
428 | - $ticket, |
|
429 | - $valid['qty'][ $x ] |
|
430 | - ); |
|
431 | - } |
|
432 | - } |
|
433 | - if ($valid_ticket !== true) { |
|
434 | - // nothing added to cart retrieved |
|
435 | - EE_Error::add_error( |
|
436 | - sprintf( |
|
437 | - esc_html__( |
|
438 | - 'A valid ticket could not be retrieved for the event.%sPlease click the back button on your browser and try again.', |
|
439 | - 'event_espresso' |
|
440 | - ), |
|
441 | - '<br/>' |
|
442 | - ), |
|
443 | - __FILE__, |
|
444 | - __FUNCTION__, |
|
445 | - __LINE__ |
|
446 | - ); |
|
447 | - } |
|
448 | - if (EE_Error::has_error()) { |
|
449 | - break; |
|
450 | - } |
|
451 | - } |
|
452 | - } |
|
453 | - } |
|
454 | - do_action( |
|
455 | - 'AHEE__EE_Ticket_Selector__process_ticket_selections__after_tickets_added_to_cart', |
|
456 | - $this->cart, |
|
457 | - $this |
|
458 | - ); |
|
459 | - if (! apply_filters('FHEE__EED_Ticket_Selector__process_ticket_selections__tckts_slctd', $tickets_selected)) { |
|
460 | - // no ticket quantities were selected |
|
461 | - EE_Error::add_error( |
|
462 | - esc_html__('You need to select a ticket quantity before you can proceed.', 'event_espresso'), |
|
463 | - __FILE__, |
|
464 | - __FUNCTION__, |
|
465 | - __LINE__ |
|
466 | - ); |
|
467 | - } |
|
468 | - return $tickets_added; |
|
469 | - } |
|
395 | + /** |
|
396 | + * @param array $valid |
|
397 | + * @return int |
|
398 | + * @throws EE_Error |
|
399 | + * @throws InvalidArgumentException |
|
400 | + * @throws InvalidDataTypeException |
|
401 | + * @throws InvalidInterfaceException |
|
402 | + */ |
|
403 | + private function addTicketsToCart(array $valid) |
|
404 | + { |
|
405 | + $tickets_added = 0; |
|
406 | + $tickets_selected = false; |
|
407 | + if (! empty($valid) && $valid['total_tickets'] > 0) { |
|
408 | + // load cart using factory because we don't want to do so until actually needed |
|
409 | + $this->cart = CartFactory::getCart(); |
|
410 | + // cycle thru the number of data rows sent from the event listing |
|
411 | + for ($x = 0; $x < $valid['rows']; $x++) { |
|
412 | + // does this row actually contain a ticket quantity? |
|
413 | + if (isset($valid['qty'][ $x ]) && $valid['qty'][ $x ] > 0) { |
|
414 | + // YES we have a ticket quantity |
|
415 | + $tickets_selected = true; |
|
416 | + $valid_ticket = false; |
|
417 | + // \EEH_Debug_Tools::printr( |
|
418 | + // $valid['ticket_id'][ $x ], |
|
419 | + // '$valid[\'ticket_id\'][ $x ]', |
|
420 | + // __FILE__, __LINE__ |
|
421 | + // ); |
|
422 | + if (isset($valid['ticket_id'][ $x ])) { |
|
423 | + // get ticket via the ticket id we put in the form |
|
424 | + $ticket = $this->ticket_model->get_one_by_ID($valid['ticket_id'][ $x ]); |
|
425 | + if ($ticket instanceof EE_Ticket) { |
|
426 | + $valid_ticket = true; |
|
427 | + $tickets_added += $this->addTicketToCart( |
|
428 | + $ticket, |
|
429 | + $valid['qty'][ $x ] |
|
430 | + ); |
|
431 | + } |
|
432 | + } |
|
433 | + if ($valid_ticket !== true) { |
|
434 | + // nothing added to cart retrieved |
|
435 | + EE_Error::add_error( |
|
436 | + sprintf( |
|
437 | + esc_html__( |
|
438 | + 'A valid ticket could not be retrieved for the event.%sPlease click the back button on your browser and try again.', |
|
439 | + 'event_espresso' |
|
440 | + ), |
|
441 | + '<br/>' |
|
442 | + ), |
|
443 | + __FILE__, |
|
444 | + __FUNCTION__, |
|
445 | + __LINE__ |
|
446 | + ); |
|
447 | + } |
|
448 | + if (EE_Error::has_error()) { |
|
449 | + break; |
|
450 | + } |
|
451 | + } |
|
452 | + } |
|
453 | + } |
|
454 | + do_action( |
|
455 | + 'AHEE__EE_Ticket_Selector__process_ticket_selections__after_tickets_added_to_cart', |
|
456 | + $this->cart, |
|
457 | + $this |
|
458 | + ); |
|
459 | + if (! apply_filters('FHEE__EED_Ticket_Selector__process_ticket_selections__tckts_slctd', $tickets_selected)) { |
|
460 | + // no ticket quantities were selected |
|
461 | + EE_Error::add_error( |
|
462 | + esc_html__('You need to select a ticket quantity before you can proceed.', 'event_espresso'), |
|
463 | + __FILE__, |
|
464 | + __FUNCTION__, |
|
465 | + __LINE__ |
|
466 | + ); |
|
467 | + } |
|
468 | + return $tickets_added; |
|
469 | + } |
|
470 | 470 | |
471 | 471 | |
472 | - /** |
|
473 | - * adds a ticket to the cart |
|
474 | - * |
|
475 | - * @param EE_Ticket $ticket |
|
476 | - * @param int $qty |
|
477 | - * @return TRUE on success, FALSE on fail |
|
478 | - * @throws InvalidArgumentException |
|
479 | - * @throws InvalidInterfaceException |
|
480 | - * @throws InvalidDataTypeException |
|
481 | - * @throws EE_Error |
|
482 | - */ |
|
483 | - private function addTicketToCart(EE_Ticket $ticket, $qty = 1) |
|
484 | - { |
|
485 | - // get the number of spaces left for this datetime ticket |
|
486 | - $available_spaces = $this->tracker->ticketDatetimeAvailability($ticket); |
|
487 | - // compare available spaces against the number of tickets being purchased |
|
488 | - if ($available_spaces >= $qty) { |
|
489 | - // allow addons to prevent a ticket from being added to cart |
|
490 | - if (! apply_filters( |
|
491 | - 'FHEE__EE_Ticket_Selector___add_ticket_to_cart__allow_add_to_cart', |
|
492 | - true, |
|
493 | - $ticket, |
|
494 | - $qty, |
|
495 | - $available_spaces |
|
496 | - )) { |
|
497 | - return false; |
|
498 | - } |
|
499 | - $qty = absint(apply_filters('FHEE__EE_Ticket_Selector___add_ticket_to_cart__ticket_qty', $qty, $ticket)); |
|
500 | - // add event to cart |
|
501 | - if ($this->cart->add_ticket_to_cart($ticket, $qty)) { |
|
502 | - $this->tracker->recalculateTicketDatetimeAvailability($ticket, $qty); |
|
503 | - return true; |
|
504 | - } |
|
505 | - return false; |
|
506 | - } |
|
507 | - $this->tracker->processAvailabilityError($ticket, $qty, $this->cart->all_ticket_quantity_count()); |
|
508 | - return false; |
|
509 | - } |
|
472 | + /** |
|
473 | + * adds a ticket to the cart |
|
474 | + * |
|
475 | + * @param EE_Ticket $ticket |
|
476 | + * @param int $qty |
|
477 | + * @return TRUE on success, FALSE on fail |
|
478 | + * @throws InvalidArgumentException |
|
479 | + * @throws InvalidInterfaceException |
|
480 | + * @throws InvalidDataTypeException |
|
481 | + * @throws EE_Error |
|
482 | + */ |
|
483 | + private function addTicketToCart(EE_Ticket $ticket, $qty = 1) |
|
484 | + { |
|
485 | + // get the number of spaces left for this datetime ticket |
|
486 | + $available_spaces = $this->tracker->ticketDatetimeAvailability($ticket); |
|
487 | + // compare available spaces against the number of tickets being purchased |
|
488 | + if ($available_spaces >= $qty) { |
|
489 | + // allow addons to prevent a ticket from being added to cart |
|
490 | + if (! apply_filters( |
|
491 | + 'FHEE__EE_Ticket_Selector___add_ticket_to_cart__allow_add_to_cart', |
|
492 | + true, |
|
493 | + $ticket, |
|
494 | + $qty, |
|
495 | + $available_spaces |
|
496 | + )) { |
|
497 | + return false; |
|
498 | + } |
|
499 | + $qty = absint(apply_filters('FHEE__EE_Ticket_Selector___add_ticket_to_cart__ticket_qty', $qty, $ticket)); |
|
500 | + // add event to cart |
|
501 | + if ($this->cart->add_ticket_to_cart($ticket, $qty)) { |
|
502 | + $this->tracker->recalculateTicketDatetimeAvailability($ticket, $qty); |
|
503 | + return true; |
|
504 | + } |
|
505 | + return false; |
|
506 | + } |
|
507 | + $this->tracker->processAvailabilityError($ticket, $qty, $this->cart->all_ticket_quantity_count()); |
|
508 | + return false; |
|
509 | + } |
|
510 | 510 | |
511 | 511 | |
512 | - /** |
|
513 | - * @param $tickets_added |
|
514 | - * @return bool |
|
515 | - * @throws InvalidInterfaceException |
|
516 | - * @throws InvalidDataTypeException |
|
517 | - * @throws EE_Error |
|
518 | - * @throws InvalidArgumentException |
|
519 | - */ |
|
520 | - private function processSuccessfulCart($tickets_added) |
|
521 | - { |
|
522 | - // exit('KILL REDIRECT BEFORE CART UPDATE'); // <<<<<<<<<<<<<<<<< KILL REDIRECT HERE BEFORE CART UPDATE |
|
523 | - if (apply_filters('FHEE__EED_Ticket_Selector__process_ticket_selections__success', $tickets_added)) { |
|
524 | - // make sure cart is loaded |
|
525 | - if (! $this->cart instanceof EE_Cart) { |
|
526 | - $this->cart = CartFactory::getCart(); |
|
527 | - } |
|
528 | - do_action( |
|
529 | - 'FHEE__EE_Ticket_Selector__process_ticket_selections__before_redirecting_to_checkout', |
|
530 | - $this->cart, |
|
531 | - $this |
|
532 | - ); |
|
533 | - $this->cart->recalculate_all_cart_totals(); |
|
534 | - $this->cart->save_cart(false); |
|
535 | - // exit('KILL REDIRECT AFTER CART UPDATE'); // <<<<<<<< OR HERE TO KILL REDIRECT AFTER CART UPDATE |
|
536 | - // just return TRUE for registrations being made from admin |
|
537 | - if ($this->request->isAdmin() || $this->request->isFrontAjax()) { |
|
538 | - return true; |
|
539 | - } |
|
540 | - EEH_URL::safeRedirectAndExit( |
|
541 | - apply_filters( |
|
542 | - 'FHEE__EE_Ticket_Selector__process_ticket_selections__success_redirect_url', |
|
543 | - $this->core_config->reg_page_url() |
|
544 | - ) |
|
545 | - ); |
|
546 | - } |
|
547 | - if (! EE_Error::has_error() && ! EE_Error::has_error(true, 'attention')) { |
|
548 | - // nothing added to cart |
|
549 | - EE_Error::add_attention( |
|
550 | - esc_html__('No tickets were added for the event', 'event_espresso'), |
|
551 | - __FILE__, |
|
552 | - __FUNCTION__, |
|
553 | - __LINE__ |
|
554 | - ); |
|
555 | - } |
|
556 | - return false; |
|
557 | - } |
|
512 | + /** |
|
513 | + * @param $tickets_added |
|
514 | + * @return bool |
|
515 | + * @throws InvalidInterfaceException |
|
516 | + * @throws InvalidDataTypeException |
|
517 | + * @throws EE_Error |
|
518 | + * @throws InvalidArgumentException |
|
519 | + */ |
|
520 | + private function processSuccessfulCart($tickets_added) |
|
521 | + { |
|
522 | + // exit('KILL REDIRECT BEFORE CART UPDATE'); // <<<<<<<<<<<<<<<<< KILL REDIRECT HERE BEFORE CART UPDATE |
|
523 | + if (apply_filters('FHEE__EED_Ticket_Selector__process_ticket_selections__success', $tickets_added)) { |
|
524 | + // make sure cart is loaded |
|
525 | + if (! $this->cart instanceof EE_Cart) { |
|
526 | + $this->cart = CartFactory::getCart(); |
|
527 | + } |
|
528 | + do_action( |
|
529 | + 'FHEE__EE_Ticket_Selector__process_ticket_selections__before_redirecting_to_checkout', |
|
530 | + $this->cart, |
|
531 | + $this |
|
532 | + ); |
|
533 | + $this->cart->recalculate_all_cart_totals(); |
|
534 | + $this->cart->save_cart(false); |
|
535 | + // exit('KILL REDIRECT AFTER CART UPDATE'); // <<<<<<<< OR HERE TO KILL REDIRECT AFTER CART UPDATE |
|
536 | + // just return TRUE for registrations being made from admin |
|
537 | + if ($this->request->isAdmin() || $this->request->isFrontAjax()) { |
|
538 | + return true; |
|
539 | + } |
|
540 | + EEH_URL::safeRedirectAndExit( |
|
541 | + apply_filters( |
|
542 | + 'FHEE__EE_Ticket_Selector__process_ticket_selections__success_redirect_url', |
|
543 | + $this->core_config->reg_page_url() |
|
544 | + ) |
|
545 | + ); |
|
546 | + } |
|
547 | + if (! EE_Error::has_error() && ! EE_Error::has_error(true, 'attention')) { |
|
548 | + // nothing added to cart |
|
549 | + EE_Error::add_attention( |
|
550 | + esc_html__('No tickets were added for the event', 'event_espresso'), |
|
551 | + __FILE__, |
|
552 | + __FUNCTION__, |
|
553 | + __LINE__ |
|
554 | + ); |
|
555 | + } |
|
556 | + return false; |
|
557 | + } |
|
558 | 558 | } |
@@ -118,7 +118,7 @@ discard block |
||
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 |
||
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 |
||
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( |
@@ -236,7 +236,7 @@ discard block |
||
236 | 236 | private function getEventId() |
237 | 237 | { |
238 | 238 | // do we have an event id? |
239 | - if (! $this->request->requestParamIsSet('tkt-slctr-event-id')) { |
|
239 | + if ( ! $this->request->requestParamIsSet('tkt-slctr-event-id')) { |
|
240 | 240 | // $_POST['tkt-slctr-event-id'] was not set ?!?!?!? |
241 | 241 | EE_Error::add_error( |
242 | 242 | sprintf( |
@@ -264,7 +264,7 @@ discard block |
||
264 | 264 | */ |
265 | 265 | private function validatePostData($id = 0) |
266 | 266 | { |
267 | - if (! $id) { |
|
267 | + if ( ! $id) { |
|
268 | 268 | EE_Error::add_error( |
269 | 269 | esc_html__('The event id provided was not valid.', 'event_espresso'), |
270 | 270 | __FILE__, |
@@ -291,29 +291,29 @@ discard block |
||
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 | - $input_value = $this->request->getRequestParam($input_to_clean . $id); |
|
296 | + $input_value = $this->request->getRequestParam($input_to_clean.$id); |
|
297 | 297 | switch ($what) { |
298 | 298 | // integers |
299 | 299 | case 'event_id': |
300 | - $valid_data[ $what ] = absint($input_value); |
|
300 | + $valid_data[$what] = absint($input_value); |
|
301 | 301 | // get event via the event id we put in the form |
302 | 302 | break; |
303 | 303 | case 'rows': |
304 | 304 | case 'max_atndz': |
305 | - $valid_data[ $what ] = absint($input_value); |
|
305 | + $valid_data[$what] = absint($input_value); |
|
306 | 306 | break; |
307 | 307 | // arrays of integers |
308 | 308 | case 'qty': |
309 | 309 | /** @var array $row_qty */ |
310 | 310 | $row_qty = $input_value; |
311 | 311 | // if qty is coming from a radio button input, then we need to assemble an array of rows |
312 | - if (! is_array($row_qty)) { |
|
312 | + if ( ! is_array($row_qty)) { |
|
313 | 313 | /** @var string $row_qty */ |
314 | 314 | // get number of rows |
315 | - $rows = $this->request->requestParamIsSet('tkt-slctr-rows-' . $id) |
|
316 | - ? absint($this->request->getRequestParam('tkt-slctr-rows-' . $id)) |
|
315 | + $rows = $this->request->requestParamIsSet('tkt-slctr-rows-'.$id) |
|
316 | + ? absint($this->request->getRequestParam('tkt-slctr-rows-'.$id)) |
|
317 | 317 | : 1; |
318 | 318 | // explode integers by the dash |
319 | 319 | $row_qty = explode('-', $row_qty); |
@@ -321,8 +321,8 @@ discard block |
||
321 | 321 | $qty = isset($row_qty[1]) ? absint($row_qty[1]) : 0; |
322 | 322 | $row_qty = array($row => $qty); |
323 | 323 | for ($x = 1; $x <= $rows; $x++) { |
324 | - if (! isset($row_qty[ $x ])) { |
|
325 | - $row_qty[ $x ] = 0; |
|
324 | + if ( ! isset($row_qty[$x])) { |
|
325 | + $row_qty[$x] = 0; |
|
326 | 326 | } |
327 | 327 | } |
328 | 328 | } |
@@ -331,7 +331,7 @@ discard block |
||
331 | 331 | foreach ($row_qty as $qty) { |
332 | 332 | $qty = absint($qty); |
333 | 333 | // sanitize as integers |
334 | - $valid_data[ $what ][] = $qty; |
|
334 | + $valid_data[$what][] = $qty; |
|
335 | 335 | $valid_data['total_tickets'] += $qty; |
336 | 336 | } |
337 | 337 | break; |
@@ -340,7 +340,7 @@ discard block |
||
340 | 340 | // cycle thru values |
341 | 341 | foreach ((array) $input_value as $key => $value) { |
342 | 342 | // allow only integers |
343 | - $valid_data[ $what ][ $key ] = absint($value); |
|
343 | + $valid_data[$what][$key] = absint($value); |
|
344 | 344 | } |
345 | 345 | break; |
346 | 346 | case 'return_url': |
@@ -352,9 +352,9 @@ discard block |
||
352 | 352 | $input_value = explode('#', $input_value); |
353 | 353 | $input_value = end($input_value); |
354 | 354 | // use event list url instead, but append anchor |
355 | - $input_value = EEH_Event_View::event_archive_url() . '#' . $input_value; |
|
355 | + $input_value = EEH_Event_View::event_archive_url().'#'.$input_value; |
|
356 | 356 | } |
357 | - $valid_data[ $what ] = $input_value; |
|
357 | + $valid_data[$what] = $input_value; |
|
358 | 358 | break; |
359 | 359 | } // end switch $what |
360 | 360 | } |
@@ -388,7 +388,7 @@ discard block |
||
388 | 388 | ) |
389 | 389 | ); |
390 | 390 | $limit_error_2 = sprintf($max_attendees_string, $valid['max_atndz'], $valid['max_atndz']); |
391 | - EE_Error::add_error($limit_error_1 . '<br/>' . $limit_error_2, __FILE__, __FUNCTION__, __LINE__); |
|
391 | + EE_Error::add_error($limit_error_1.'<br/>'.$limit_error_2, __FILE__, __FUNCTION__, __LINE__); |
|
392 | 392 | } |
393 | 393 | |
394 | 394 | |
@@ -404,13 +404,13 @@ discard block |
||
404 | 404 | { |
405 | 405 | $tickets_added = 0; |
406 | 406 | $tickets_selected = false; |
407 | - if (! empty($valid) && $valid['total_tickets'] > 0) { |
|
407 | + if ( ! empty($valid) && $valid['total_tickets'] > 0) { |
|
408 | 408 | // load cart using factory because we don't want to do so until actually needed |
409 | 409 | $this->cart = CartFactory::getCart(); |
410 | 410 | // cycle thru the number of data rows sent from the event listing |
411 | 411 | for ($x = 0; $x < $valid['rows']; $x++) { |
412 | 412 | // does this row actually contain a ticket quantity? |
413 | - if (isset($valid['qty'][ $x ]) && $valid['qty'][ $x ] > 0) { |
|
413 | + if (isset($valid['qty'][$x]) && $valid['qty'][$x] > 0) { |
|
414 | 414 | // YES we have a ticket quantity |
415 | 415 | $tickets_selected = true; |
416 | 416 | $valid_ticket = false; |
@@ -419,14 +419,14 @@ discard block |
||
419 | 419 | // '$valid[\'ticket_id\'][ $x ]', |
420 | 420 | // __FILE__, __LINE__ |
421 | 421 | // ); |
422 | - if (isset($valid['ticket_id'][ $x ])) { |
|
422 | + if (isset($valid['ticket_id'][$x])) { |
|
423 | 423 | // get ticket via the ticket id we put in the form |
424 | - $ticket = $this->ticket_model->get_one_by_ID($valid['ticket_id'][ $x ]); |
|
424 | + $ticket = $this->ticket_model->get_one_by_ID($valid['ticket_id'][$x]); |
|
425 | 425 | if ($ticket instanceof EE_Ticket) { |
426 | 426 | $valid_ticket = true; |
427 | 427 | $tickets_added += $this->addTicketToCart( |
428 | 428 | $ticket, |
429 | - $valid['qty'][ $x ] |
|
429 | + $valid['qty'][$x] |
|
430 | 430 | ); |
431 | 431 | } |
432 | 432 | } |
@@ -456,7 +456,7 @@ discard block |
||
456 | 456 | $this->cart, |
457 | 457 | $this |
458 | 458 | ); |
459 | - if (! apply_filters('FHEE__EED_Ticket_Selector__process_ticket_selections__tckts_slctd', $tickets_selected)) { |
|
459 | + if ( ! apply_filters('FHEE__EED_Ticket_Selector__process_ticket_selections__tckts_slctd', $tickets_selected)) { |
|
460 | 460 | // no ticket quantities were selected |
461 | 461 | EE_Error::add_error( |
462 | 462 | esc_html__('You need to select a ticket quantity before you can proceed.', 'event_espresso'), |
@@ -487,7 +487,7 @@ discard block |
||
487 | 487 | // compare available spaces against the number of tickets being purchased |
488 | 488 | if ($available_spaces >= $qty) { |
489 | 489 | // allow addons to prevent a ticket from being added to cart |
490 | - if (! apply_filters( |
|
490 | + if ( ! apply_filters( |
|
491 | 491 | 'FHEE__EE_Ticket_Selector___add_ticket_to_cart__allow_add_to_cart', |
492 | 492 | true, |
493 | 493 | $ticket, |
@@ -522,7 +522,7 @@ discard block |
||
522 | 522 | // exit('KILL REDIRECT BEFORE CART UPDATE'); // <<<<<<<<<<<<<<<<< KILL REDIRECT HERE BEFORE CART UPDATE |
523 | 523 | if (apply_filters('FHEE__EED_Ticket_Selector__process_ticket_selections__success', $tickets_added)) { |
524 | 524 | // make sure cart is loaded |
525 | - if (! $this->cart instanceof EE_Cart) { |
|
525 | + if ( ! $this->cart instanceof EE_Cart) { |
|
526 | 526 | $this->cart = CartFactory::getCart(); |
527 | 527 | } |
528 | 528 | do_action( |
@@ -544,7 +544,7 @@ discard block |
||
544 | 544 | ) |
545 | 545 | ); |
546 | 546 | } |
547 | - if (! EE_Error::has_error() && ! EE_Error::has_error(true, 'attention')) { |
|
547 | + if ( ! EE_Error::has_error() && ! EE_Error::has_error(true, 'attention')) { |
|
548 | 548 | // nothing added to cart |
549 | 549 | EE_Error::add_attention( |
550 | 550 | esc_html__('No tickets were added for the event', 'event_espresso'), |