@@ -22,15 +22,15 @@ discard block |
||
22 | 22 | */ |
23 | 23 | class EED_Ticket_Selector extends EED_Module { |
24 | 24 | |
25 | - /** |
|
26 | - * @var EventEspresso\modules\ticket_selector\DisplayTicketSelector $ticket_selector |
|
27 | - */ |
|
28 | - private static $ticket_selector; |
|
25 | + /** |
|
26 | + * @var EventEspresso\modules\ticket_selector\DisplayTicketSelector $ticket_selector |
|
27 | + */ |
|
28 | + private static $ticket_selector; |
|
29 | 29 | |
30 | - /** |
|
31 | - * @var EventEspresso\modules\ticket_selector\TicketSelectorIframeEmbedButton $iframe_embed_button |
|
32 | - */ |
|
33 | - private static $iframe_embed_button; |
|
30 | + /** |
|
31 | + * @var EventEspresso\modules\ticket_selector\TicketSelectorIframeEmbedButton $iframe_embed_button |
|
32 | + */ |
|
33 | + private static $iframe_embed_button; |
|
34 | 34 | |
35 | 35 | |
36 | 36 | |
@@ -61,13 +61,13 @@ discard block |
||
61 | 61 | // routing |
62 | 62 | EE_Config::register_route( 'iframe', 'EED_Ticket_Selector', 'ticket_selector_iframe', 'ticket_selector' ); |
63 | 63 | EE_Config::register_route( 'process_ticket_selections', 'EED_Ticket_Selector', 'process_ticket_selections' ); |
64 | - EE_Config::register_route('cancel_ticket_selections', 'EED_Ticket_Selector', 'cancel_ticket_selections'); |
|
65 | - add_action( 'wp_loaded', array( 'EED_Ticket_Selector', 'set_definitions' ), 2 ); |
|
64 | + EE_Config::register_route('cancel_ticket_selections', 'EED_Ticket_Selector', 'cancel_ticket_selections'); |
|
65 | + add_action( 'wp_loaded', array( 'EED_Ticket_Selector', 'set_definitions' ), 2 ); |
|
66 | 66 | add_action( 'AHEE_event_details_header_bottom', array( 'EED_Ticket_Selector', 'display_ticket_selector' ), 10, 1 ); |
67 | - add_action( 'wp_enqueue_scripts', array( 'EED_Ticket_Selector', 'translate_js_strings' ), 0 ); |
|
68 | - add_action( 'wp_enqueue_scripts', array( 'EED_Ticket_Selector', 'load_tckt_slctr_assets' ), 10 ); |
|
69 | - EED_Ticket_Selector::loadIframeAssets(); |
|
70 | - } |
|
67 | + add_action( 'wp_enqueue_scripts', array( 'EED_Ticket_Selector', 'translate_js_strings' ), 0 ); |
|
68 | + add_action( 'wp_enqueue_scripts', array( 'EED_Ticket_Selector', 'load_tckt_slctr_assets' ), 10 ); |
|
69 | + EED_Ticket_Selector::loadIframeAssets(); |
|
70 | + } |
|
71 | 71 | |
72 | 72 | |
73 | 73 | |
@@ -86,16 +86,16 @@ discard block |
||
86 | 86 | 10 |
87 | 87 | ); |
88 | 88 | |
89 | - /** |
|
90 | - * Make sure assets for the ticket selector are loaded on the espresso registrations route so admin side |
|
91 | - * registrations work. |
|
92 | - */ |
|
89 | + /** |
|
90 | + * Make sure assets for the ticket selector are loaded on the espresso registrations route so admin side |
|
91 | + * registrations work. |
|
92 | + */ |
|
93 | 93 | add_action( |
94 | - 'FHEE__EE_Admin_Page___load_page_dependencies__after_load__espresso_registrations__new_registration', |
|
95 | - array('EED_Ticket_Selector', 'set_definitions'), |
|
96 | - 10 |
|
97 | - ); |
|
98 | - } |
|
94 | + 'FHEE__EE_Admin_Page___load_page_dependencies__after_load__espresso_registrations__new_registration', |
|
95 | + array('EED_Ticket_Selector', 'set_definitions'), |
|
96 | + 10 |
|
97 | + ); |
|
98 | + } |
|
99 | 99 | |
100 | 100 | |
101 | 101 | |
@@ -111,23 +111,23 @@ discard block |
||
111 | 111 | |
112 | 112 | //if config is not set, initialize |
113 | 113 | if ( ! EE_Registry::instance()->CFG->template_settings->EED_Ticket_Selector instanceof EE_Ticket_Selector_Config ) { |
114 | - \EED_Ticket_Selector::instance()->set_config(); |
|
115 | - \EE_Registry::instance()->CFG->template_settings->EED_Ticket_Selector = \EED_Ticket_Selector::instance()->config(); |
|
114 | + \EED_Ticket_Selector::instance()->set_config(); |
|
115 | + \EE_Registry::instance()->CFG->template_settings->EED_Ticket_Selector = \EED_Ticket_Selector::instance()->config(); |
|
116 | 116 | } |
117 | 117 | } |
118 | 118 | |
119 | 119 | |
120 | 120 | |
121 | 121 | /** |
122 | - * @return \EventEspresso\modules\ticket_selector\DisplayTicketSelector |
|
123 | - */ |
|
124 | - public static function ticketSelector() |
|
125 | - { |
|
126 | - if ( ! EED_Ticket_Selector::$ticket_selector instanceof DisplayTicketSelector) { |
|
127 | - EED_Ticket_Selector::$ticket_selector = new DisplayTicketSelector(); |
|
128 | - } |
|
129 | - return EED_Ticket_Selector::$ticket_selector; |
|
130 | - } |
|
122 | + * @return \EventEspresso\modules\ticket_selector\DisplayTicketSelector |
|
123 | + */ |
|
124 | + public static function ticketSelector() |
|
125 | + { |
|
126 | + if ( ! EED_Ticket_Selector::$ticket_selector instanceof DisplayTicketSelector) { |
|
127 | + EED_Ticket_Selector::$ticket_selector = new DisplayTicketSelector(); |
|
128 | + } |
|
129 | + return EED_Ticket_Selector::$ticket_selector; |
|
130 | + } |
|
131 | 131 | |
132 | 132 | |
133 | 133 | /** |
@@ -180,15 +180,15 @@ discard block |
||
180 | 180 | |
181 | 181 | |
182 | 182 | |
183 | - /** |
|
184 | - * creates buttons for selecting number of attendees for an event |
|
185 | - * |
|
186 | - * @access public |
|
187 | - * @param WP_Post|int $event |
|
188 | - * @param bool $view_details |
|
189 | - * @return string |
|
190 | - * @throws \EE_Error |
|
191 | - */ |
|
183 | + /** |
|
184 | + * creates buttons for selecting number of attendees for an event |
|
185 | + * |
|
186 | + * @access public |
|
187 | + * @param WP_Post|int $event |
|
188 | + * @param bool $view_details |
|
189 | + * @return string |
|
190 | + * @throws \EE_Error |
|
191 | + */ |
|
192 | 192 | public static function display_ticket_selector( $event = NULL, $view_details = FALSE ) { |
193 | 193 | return EED_Ticket_Selector::ticketSelector()->display( $event, $view_details ); |
194 | 194 | } |
@@ -209,244 +209,244 @@ discard block |
||
209 | 209 | |
210 | 210 | |
211 | 211 | |
212 | - /** |
|
213 | - * cancel_ticket_selections |
|
214 | - * |
|
215 | - * @access public |
|
216 | - * @return string |
|
217 | - */ |
|
218 | - public static function cancel_ticket_selections() |
|
219 | - { |
|
220 | - $form = new ProcessTicketSelector(); |
|
221 | - return $form->cancelTicketSelections(); |
|
222 | - } |
|
212 | + /** |
|
213 | + * cancel_ticket_selections |
|
214 | + * |
|
215 | + * @access public |
|
216 | + * @return string |
|
217 | + */ |
|
218 | + public static function cancel_ticket_selections() |
|
219 | + { |
|
220 | + $form = new ProcessTicketSelector(); |
|
221 | + return $form->cancelTicketSelections(); |
|
222 | + } |
|
223 | 223 | |
224 | 224 | |
225 | 225 | |
226 | 226 | /** |
227 | - * @return void |
|
228 | - */ |
|
227 | + * @return void |
|
228 | + */ |
|
229 | 229 | public static function translate_js_strings() { |
230 | - EE_Registry::$i18n_js_strings['please_select_date_filter_notice'] = esc_html__( |
|
231 | - 'please select a datetime', 'event_espresso' |
|
232 | - ); |
|
233 | - } |
|
230 | + EE_Registry::$i18n_js_strings['please_select_date_filter_notice'] = esc_html__( |
|
231 | + 'please select a datetime', 'event_espresso' |
|
232 | + ); |
|
233 | + } |
|
234 | 234 | |
235 | 235 | |
236 | 236 | |
237 | 237 | /** |
238 | - * load js |
|
239 | - * |
|
240 | - * @access public |
|
241 | - * @return void |
|
242 | - */ |
|
238 | + * load js |
|
239 | + * |
|
240 | + * @access public |
|
241 | + * @return void |
|
242 | + */ |
|
243 | 243 | public static function load_tckt_slctr_assets() { |
244 | 244 | if ( apply_filters( 'FHEE__EED_Ticket_Selector__load_tckt_slctr_assets', FALSE ) ) { |
245 | - // add some style |
|
246 | - wp_register_style( |
|
247 | - 'ticket_selector', |
|
248 | - TICKET_SELECTOR_ASSETS_URL . 'ticket_selector.css', |
|
249 | - array(), |
|
250 | - EVENT_ESPRESSO_VERSION |
|
251 | - ); |
|
252 | - wp_enqueue_style('ticket_selector'); |
|
253 | - // make it dance |
|
254 | - wp_register_script( |
|
255 | - 'ticket_selector', |
|
256 | - TICKET_SELECTOR_ASSETS_URL . 'ticket_selector.js', |
|
257 | - array('espresso_core'), |
|
258 | - EVENT_ESPRESSO_VERSION, |
|
259 | - TRUE |
|
260 | - ); |
|
245 | + // add some style |
|
246 | + wp_register_style( |
|
247 | + 'ticket_selector', |
|
248 | + TICKET_SELECTOR_ASSETS_URL . 'ticket_selector.css', |
|
249 | + array(), |
|
250 | + EVENT_ESPRESSO_VERSION |
|
251 | + ); |
|
252 | + wp_enqueue_style('ticket_selector'); |
|
253 | + // make it dance |
|
254 | + wp_register_script( |
|
255 | + 'ticket_selector', |
|
256 | + TICKET_SELECTOR_ASSETS_URL . 'ticket_selector.js', |
|
257 | + array('espresso_core'), |
|
258 | + EVENT_ESPRESSO_VERSION, |
|
259 | + TRUE |
|
260 | + ); |
|
261 | 261 | wp_enqueue_script('ticket_selector'); |
262 | - require_once( EE_LIBRARIES.'form_sections/strategies/display/EE_Checkbox_Dropdown_Selector_Display_Strategy.strategy.php'); |
|
263 | - \EE_Checkbox_Dropdown_Selector_Display_Strategy::enqueue_styles_and_scripts(); |
|
264 | - } |
|
262 | + require_once( EE_LIBRARIES.'form_sections/strategies/display/EE_Checkbox_Dropdown_Selector_Display_Strategy.strategy.php'); |
|
263 | + \EE_Checkbox_Dropdown_Selector_Display_Strategy::enqueue_styles_and_scripts(); |
|
264 | + } |
|
265 | + } |
|
266 | + |
|
267 | + |
|
268 | + |
|
269 | + /** |
|
270 | + * @return void |
|
271 | + */ |
|
272 | + public static function loadIframeAssets() |
|
273 | + { |
|
274 | + // for event lists |
|
275 | + add_filter( |
|
276 | + 'FHEE__EventEspresso_modules_events_archive_EventsArchiveIframe__display__css', |
|
277 | + array('EED_Ticket_Selector', 'iframeCss') |
|
278 | + ); |
|
279 | + add_filter( |
|
280 | + 'FHEE__EventEspresso_modules_events_archive_EventsArchiveIframe__display__js', |
|
281 | + array('EED_Ticket_Selector', 'iframeJs') |
|
282 | + ); |
|
283 | + // for ticket selectors |
|
284 | + add_filter( |
|
285 | + 'FHEE__EED_Ticket_Selector__ticket_selector_iframe__css', |
|
286 | + array('EED_Ticket_Selector', 'iframeCss') |
|
287 | + ); |
|
288 | + add_filter( |
|
289 | + 'FHEE__EED_Ticket_Selector__ticket_selector_iframe__js', |
|
290 | + array('EED_Ticket_Selector', 'iframeJs') |
|
291 | + ); |
|
292 | + } |
|
293 | + |
|
294 | + |
|
295 | + |
|
296 | + /** |
|
297 | + * Informs the rest of the forms system what CSS and JS is needed to display the input |
|
298 | + * |
|
299 | + * @param array $iframe_css |
|
300 | + * @return array |
|
301 | + */ |
|
302 | + public static function iframeCss(array $iframe_css) |
|
303 | + { |
|
304 | + $iframe_css['ticket_selector'] = TICKET_SELECTOR_ASSETS_URL . 'ticket_selector.css'; |
|
305 | + return $iframe_css; |
|
265 | 306 | } |
266 | 307 | |
267 | 308 | |
268 | 309 | |
269 | - /** |
|
270 | - * @return void |
|
271 | - */ |
|
272 | - public static function loadIframeAssets() |
|
273 | - { |
|
274 | - // for event lists |
|
275 | - add_filter( |
|
276 | - 'FHEE__EventEspresso_modules_events_archive_EventsArchiveIframe__display__css', |
|
277 | - array('EED_Ticket_Selector', 'iframeCss') |
|
278 | - ); |
|
279 | - add_filter( |
|
280 | - 'FHEE__EventEspresso_modules_events_archive_EventsArchiveIframe__display__js', |
|
281 | - array('EED_Ticket_Selector', 'iframeJs') |
|
282 | - ); |
|
283 | - // for ticket selectors |
|
284 | - add_filter( |
|
285 | - 'FHEE__EED_Ticket_Selector__ticket_selector_iframe__css', |
|
286 | - array('EED_Ticket_Selector', 'iframeCss') |
|
287 | - ); |
|
288 | - add_filter( |
|
289 | - 'FHEE__EED_Ticket_Selector__ticket_selector_iframe__js', |
|
290 | - array('EED_Ticket_Selector', 'iframeJs') |
|
291 | - ); |
|
292 | - } |
|
293 | - |
|
294 | - |
|
295 | - |
|
296 | - /** |
|
297 | - * Informs the rest of the forms system what CSS and JS is needed to display the input |
|
298 | - * |
|
299 | - * @param array $iframe_css |
|
300 | - * @return array |
|
301 | - */ |
|
302 | - public static function iframeCss(array $iframe_css) |
|
303 | - { |
|
304 | - $iframe_css['ticket_selector'] = TICKET_SELECTOR_ASSETS_URL . 'ticket_selector.css'; |
|
305 | - return $iframe_css; |
|
306 | - } |
|
307 | - |
|
308 | - |
|
309 | - |
|
310 | - /** |
|
311 | - * Informs the rest of the forms system what CSS and JS is needed to display the input |
|
312 | - * |
|
313 | - * @param array $iframe_js |
|
314 | - * @return array |
|
315 | - */ |
|
316 | - public static function iframeJs(array $iframe_js) |
|
317 | - { |
|
318 | - $iframe_js['ticket_selector'] = TICKET_SELECTOR_ASSETS_URL . 'ticket_selector.js'; |
|
319 | - return $iframe_js; |
|
320 | - } |
|
310 | + /** |
|
311 | + * Informs the rest of the forms system what CSS and JS is needed to display the input |
|
312 | + * |
|
313 | + * @param array $iframe_js |
|
314 | + * @return array |
|
315 | + */ |
|
316 | + public static function iframeJs(array $iframe_js) |
|
317 | + { |
|
318 | + $iframe_js['ticket_selector'] = TICKET_SELECTOR_ASSETS_URL . 'ticket_selector.js'; |
|
319 | + return $iframe_js; |
|
320 | + } |
|
321 | 321 | |
322 | 322 | |
323 | 323 | /****************************** DEPRECATED ******************************/ |
324 | 324 | |
325 | 325 | |
326 | 326 | |
327 | - /** |
|
328 | - * @deprecated |
|
329 | - * @return string |
|
330 | - * @throws \EE_Error |
|
331 | - */ |
|
332 | - public static function display_view_details_btn() |
|
333 | - { |
|
334 | - // todo add doing_it_wrong() notice during next major version |
|
335 | - return EED_Ticket_Selector::ticketSelector()->displayViewDetailsButton(); |
|
336 | - } |
|
337 | - |
|
338 | - |
|
339 | - |
|
340 | - /** |
|
341 | - * @deprecated |
|
342 | - * @return string |
|
343 | - * @throws \EE_Error |
|
344 | - */ |
|
345 | - public static function display_ticket_selector_submit() |
|
346 | - { |
|
347 | - // todo add doing_it_wrong() notice during next major version |
|
348 | - return EED_Ticket_Selector::ticketSelector()->displaySubmitButton(); |
|
349 | - } |
|
350 | - |
|
351 | - |
|
352 | - |
|
353 | - /** |
|
354 | - * @deprecated |
|
355 | - * @param string $permalink_string |
|
356 | - * @param int $id |
|
357 | - * @param string $new_title |
|
358 | - * @param string $new_slug |
|
359 | - * @return string |
|
360 | - */ |
|
361 | - public static function iframe_code_button($permalink_string, $id, $new_title = '', $new_slug = '') |
|
362 | - { |
|
363 | - // todo add doing_it_wrong() notice during next major version |
|
364 | - if ( |
|
365 | - \EE_Registry::instance()->REQ->get('page') === 'espresso_events' |
|
366 | - && \EE_Registry::instance()->REQ->get('action') === 'edit' |
|
367 | - ) { |
|
368 | - $iframe_embed_button = \EED_Ticket_Selector::getIframeEmbedButton(); |
|
369 | - $iframe_embed_button->addEventEditorIframeEmbedButton(); |
|
370 | - } |
|
371 | - return ''; |
|
372 | - } |
|
373 | - |
|
374 | - |
|
375 | - |
|
376 | - /** |
|
377 | - * @deprecated |
|
378 | - * @param int $ID |
|
379 | - * @param string $external_url |
|
380 | - * @return string |
|
381 | - */ |
|
382 | - public static function ticket_selector_form_open($ID = 0, $external_url = '') |
|
383 | - { |
|
384 | - // todo add doing_it_wrong() notice during next major version |
|
385 | - return EED_Ticket_Selector::ticketSelector()->formOpen($ID, $external_url); |
|
386 | - } |
|
387 | - |
|
388 | - |
|
389 | - |
|
390 | - /** |
|
391 | - * @deprecated |
|
392 | - * @return string |
|
393 | - */ |
|
394 | - public static function ticket_selector_form_close() |
|
395 | - { |
|
396 | - // todo add doing_it_wrong() notice during next major version |
|
397 | - return EED_Ticket_Selector::ticketSelector()->formClose(); |
|
398 | - } |
|
399 | - |
|
400 | - |
|
401 | - |
|
402 | - /** |
|
403 | - * @deprecated |
|
404 | - * @return string |
|
405 | - */ |
|
406 | - public static function no_tkt_slctr_end_dv() |
|
407 | - { |
|
408 | - // todo add doing_it_wrong() notice during next major version |
|
409 | - return EED_Ticket_Selector::ticketSelector()->ticketSelectorEndDiv(); |
|
410 | - } |
|
411 | - |
|
412 | - |
|
413 | - |
|
414 | - /** |
|
415 | - * @deprecated 4.9.13 |
|
416 | - * @return string |
|
417 | - */ |
|
418 | - public static function tkt_slctr_end_dv() |
|
419 | - { |
|
420 | - return EED_Ticket_Selector::ticketSelector()->clearTicketSelector(); |
|
421 | - } |
|
422 | - |
|
423 | - |
|
424 | - |
|
425 | - /** |
|
426 | - * @deprecated |
|
427 | - * @return string |
|
428 | - */ |
|
429 | - public static function clear_tkt_slctr() |
|
430 | - { |
|
431 | - return EED_Ticket_Selector::ticketSelector()->clearTicketSelector(); |
|
432 | - } |
|
433 | - |
|
434 | - |
|
435 | - |
|
436 | - /** |
|
437 | - * @deprecated |
|
438 | - */ |
|
439 | - public static function load_tckt_slctr_assets_admin() |
|
440 | - { |
|
441 | - // todo add doing_it_wrong() notice during next major version |
|
442 | - if ( |
|
443 | - \EE_Registry::instance()->REQ->get( 'page' ) === 'espresso_events' |
|
444 | - && \EE_Registry::instance()->REQ->get( 'action' ) === 'edit' |
|
445 | - ) { |
|
446 | - $iframe_embed_button = \EED_Ticket_Selector::getIframeEmbedButton(); |
|
447 | - $iframe_embed_button->embedButtonAssets(); |
|
448 | - } |
|
449 | - } |
|
327 | + /** |
|
328 | + * @deprecated |
|
329 | + * @return string |
|
330 | + * @throws \EE_Error |
|
331 | + */ |
|
332 | + public static function display_view_details_btn() |
|
333 | + { |
|
334 | + // todo add doing_it_wrong() notice during next major version |
|
335 | + return EED_Ticket_Selector::ticketSelector()->displayViewDetailsButton(); |
|
336 | + } |
|
337 | + |
|
338 | + |
|
339 | + |
|
340 | + /** |
|
341 | + * @deprecated |
|
342 | + * @return string |
|
343 | + * @throws \EE_Error |
|
344 | + */ |
|
345 | + public static function display_ticket_selector_submit() |
|
346 | + { |
|
347 | + // todo add doing_it_wrong() notice during next major version |
|
348 | + return EED_Ticket_Selector::ticketSelector()->displaySubmitButton(); |
|
349 | + } |
|
350 | + |
|
351 | + |
|
352 | + |
|
353 | + /** |
|
354 | + * @deprecated |
|
355 | + * @param string $permalink_string |
|
356 | + * @param int $id |
|
357 | + * @param string $new_title |
|
358 | + * @param string $new_slug |
|
359 | + * @return string |
|
360 | + */ |
|
361 | + public static function iframe_code_button($permalink_string, $id, $new_title = '', $new_slug = '') |
|
362 | + { |
|
363 | + // todo add doing_it_wrong() notice during next major version |
|
364 | + if ( |
|
365 | + \EE_Registry::instance()->REQ->get('page') === 'espresso_events' |
|
366 | + && \EE_Registry::instance()->REQ->get('action') === 'edit' |
|
367 | + ) { |
|
368 | + $iframe_embed_button = \EED_Ticket_Selector::getIframeEmbedButton(); |
|
369 | + $iframe_embed_button->addEventEditorIframeEmbedButton(); |
|
370 | + } |
|
371 | + return ''; |
|
372 | + } |
|
373 | + |
|
374 | + |
|
375 | + |
|
376 | + /** |
|
377 | + * @deprecated |
|
378 | + * @param int $ID |
|
379 | + * @param string $external_url |
|
380 | + * @return string |
|
381 | + */ |
|
382 | + public static function ticket_selector_form_open($ID = 0, $external_url = '') |
|
383 | + { |
|
384 | + // todo add doing_it_wrong() notice during next major version |
|
385 | + return EED_Ticket_Selector::ticketSelector()->formOpen($ID, $external_url); |
|
386 | + } |
|
387 | + |
|
388 | + |
|
389 | + |
|
390 | + /** |
|
391 | + * @deprecated |
|
392 | + * @return string |
|
393 | + */ |
|
394 | + public static function ticket_selector_form_close() |
|
395 | + { |
|
396 | + // todo add doing_it_wrong() notice during next major version |
|
397 | + return EED_Ticket_Selector::ticketSelector()->formClose(); |
|
398 | + } |
|
399 | + |
|
400 | + |
|
401 | + |
|
402 | + /** |
|
403 | + * @deprecated |
|
404 | + * @return string |
|
405 | + */ |
|
406 | + public static function no_tkt_slctr_end_dv() |
|
407 | + { |
|
408 | + // todo add doing_it_wrong() notice during next major version |
|
409 | + return EED_Ticket_Selector::ticketSelector()->ticketSelectorEndDiv(); |
|
410 | + } |
|
411 | + |
|
412 | + |
|
413 | + |
|
414 | + /** |
|
415 | + * @deprecated 4.9.13 |
|
416 | + * @return string |
|
417 | + */ |
|
418 | + public static function tkt_slctr_end_dv() |
|
419 | + { |
|
420 | + return EED_Ticket_Selector::ticketSelector()->clearTicketSelector(); |
|
421 | + } |
|
422 | + |
|
423 | + |
|
424 | + |
|
425 | + /** |
|
426 | + * @deprecated |
|
427 | + * @return string |
|
428 | + */ |
|
429 | + public static function clear_tkt_slctr() |
|
430 | + { |
|
431 | + return EED_Ticket_Selector::ticketSelector()->clearTicketSelector(); |
|
432 | + } |
|
433 | + |
|
434 | + |
|
435 | + |
|
436 | + /** |
|
437 | + * @deprecated |
|
438 | + */ |
|
439 | + public static function load_tckt_slctr_assets_admin() |
|
440 | + { |
|
441 | + // todo add doing_it_wrong() notice during next major version |
|
442 | + if ( |
|
443 | + \EE_Registry::instance()->REQ->get( 'page' ) === 'espresso_events' |
|
444 | + && \EE_Registry::instance()->REQ->get( 'action' ) === 'edit' |
|
445 | + ) { |
|
446 | + $iframe_embed_button = \EED_Ticket_Selector::getIframeEmbedButton(); |
|
447 | + $iframe_embed_button->embedButtonAssets(); |
|
448 | + } |
|
449 | + } |
|
450 | 450 | |
451 | 451 | |
452 | 452 | } |
@@ -3,8 +3,8 @@ discard block |
||
3 | 3 | use EventEspresso\modules\ticket_selector\TicketSelectorIframe; |
4 | 4 | use EventEspresso\modules\ticket_selector\TicketSelectorIframeEmbedButton; |
5 | 5 | |
6 | -if ( ! defined( 'EVENT_ESPRESSO_VERSION' ) ) { |
|
7 | - exit( 'No direct script access allowed' ); |
|
6 | +if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
|
7 | + exit('No direct script access allowed'); |
|
8 | 8 | } |
9 | 9 | |
10 | 10 | |
@@ -38,15 +38,15 @@ discard block |
||
38 | 38 | * @return EED_Ticket_Selector |
39 | 39 | */ |
40 | 40 | public static function instance() { |
41 | - return parent::get_instance( __CLASS__ ); |
|
41 | + return parent::get_instance(__CLASS__); |
|
42 | 42 | } |
43 | 43 | |
44 | 44 | |
45 | 45 | |
46 | - protected function set_config(){ |
|
47 | - $this->set_config_section( 'template_settings' ); |
|
48 | - $this->set_config_class( 'EE_Ticket_Selector_Config' ); |
|
49 | - $this->set_config_name( 'EED_Ticket_Selector' ); |
|
46 | + protected function set_config() { |
|
47 | + $this->set_config_section('template_settings'); |
|
48 | + $this->set_config_class('EE_Ticket_Selector_Config'); |
|
49 | + $this->set_config_name('EED_Ticket_Selector'); |
|
50 | 50 | } |
51 | 51 | |
52 | 52 | |
@@ -59,13 +59,13 @@ discard block |
||
59 | 59 | */ |
60 | 60 | public static function set_hooks() { |
61 | 61 | // routing |
62 | - EE_Config::register_route( 'iframe', 'EED_Ticket_Selector', 'ticket_selector_iframe', 'ticket_selector' ); |
|
63 | - EE_Config::register_route( 'process_ticket_selections', 'EED_Ticket_Selector', 'process_ticket_selections' ); |
|
62 | + EE_Config::register_route('iframe', 'EED_Ticket_Selector', 'ticket_selector_iframe', 'ticket_selector'); |
|
63 | + EE_Config::register_route('process_ticket_selections', 'EED_Ticket_Selector', 'process_ticket_selections'); |
|
64 | 64 | EE_Config::register_route('cancel_ticket_selections', 'EED_Ticket_Selector', 'cancel_ticket_selections'); |
65 | - add_action( 'wp_loaded', array( 'EED_Ticket_Selector', 'set_definitions' ), 2 ); |
|
66 | - add_action( 'AHEE_event_details_header_bottom', array( 'EED_Ticket_Selector', 'display_ticket_selector' ), 10, 1 ); |
|
67 | - add_action( 'wp_enqueue_scripts', array( 'EED_Ticket_Selector', 'translate_js_strings' ), 0 ); |
|
68 | - add_action( 'wp_enqueue_scripts', array( 'EED_Ticket_Selector', 'load_tckt_slctr_assets' ), 10 ); |
|
65 | + add_action('wp_loaded', array('EED_Ticket_Selector', 'set_definitions'), 2); |
|
66 | + add_action('AHEE_event_details_header_bottom', array('EED_Ticket_Selector', 'display_ticket_selector'), 10, 1); |
|
67 | + add_action('wp_enqueue_scripts', array('EED_Ticket_Selector', 'translate_js_strings'), 0); |
|
68 | + add_action('wp_enqueue_scripts', array('EED_Ticket_Selector', 'load_tckt_slctr_assets'), 10); |
|
69 | 69 | EED_Ticket_Selector::loadIframeAssets(); |
70 | 70 | } |
71 | 71 | |
@@ -82,7 +82,7 @@ discard block |
||
82 | 82 | // to load assets for "espresso_events" page on the "edit" route (action) |
83 | 83 | add_action( |
84 | 84 | 'FHEE__EE_Admin_Page___load_page_dependencies__after_load__espresso_events__edit', |
85 | - array( 'EED_Ticket_Selector', 'ticket_selector_iframe_embed_button' ), |
|
85 | + array('EED_Ticket_Selector', 'ticket_selector_iframe_embed_button'), |
|
86 | 86 | 10 |
87 | 87 | ); |
88 | 88 | |
@@ -106,11 +106,11 @@ discard block |
||
106 | 106 | * @return void |
107 | 107 | */ |
108 | 108 | public static function set_definitions() { |
109 | - define( 'TICKET_SELECTOR_ASSETS_URL', plugin_dir_url( __FILE__ ) . 'assets' . DS ); |
|
110 | - define( 'TICKET_SELECTOR_TEMPLATES_PATH', str_replace( '\\', DS, plugin_dir_path( __FILE__ )) . 'templates' . DS ); |
|
109 | + define('TICKET_SELECTOR_ASSETS_URL', plugin_dir_url(__FILE__).'assets'.DS); |
|
110 | + define('TICKET_SELECTOR_TEMPLATES_PATH', str_replace('\\', DS, plugin_dir_path(__FILE__)).'templates'.DS); |
|
111 | 111 | |
112 | 112 | //if config is not set, initialize |
113 | - if ( ! EE_Registry::instance()->CFG->template_settings->EED_Ticket_Selector instanceof EE_Ticket_Selector_Config ) { |
|
113 | + if ( ! EE_Registry::instance()->CFG->template_settings->EED_Ticket_Selector instanceof EE_Ticket_Selector_Config) { |
|
114 | 114 | \EED_Ticket_Selector::instance()->set_config(); |
115 | 115 | \EE_Registry::instance()->CFG->template_settings->EED_Ticket_Selector = \EED_Ticket_Selector::instance()->config(); |
116 | 116 | } |
@@ -137,7 +137,7 @@ discard block |
||
137 | 137 | * @param WP $WP |
138 | 138 | * @return void |
139 | 139 | */ |
140 | - public function run( $WP ) {} |
|
140 | + public function run($WP) {} |
|
141 | 141 | |
142 | 142 | |
143 | 143 | |
@@ -145,7 +145,7 @@ discard block |
||
145 | 145 | * @return \EventEspresso\modules\ticket_selector\TicketSelectorIframeEmbedButton |
146 | 146 | */ |
147 | 147 | public static function getIframeEmbedButton() { |
148 | - if ( ! self::$iframe_embed_button instanceof TicketSelectorIframeEmbedButton ) { |
|
148 | + if ( ! self::$iframe_embed_button instanceof TicketSelectorIframeEmbedButton) { |
|
149 | 149 | self::$iframe_embed_button = new TicketSelectorIframeEmbedButton(); |
150 | 150 | } |
151 | 151 | return self::$iframe_embed_button; |
@@ -189,8 +189,8 @@ discard block |
||
189 | 189 | * @return string |
190 | 190 | * @throws \EE_Error |
191 | 191 | */ |
192 | - public static function display_ticket_selector( $event = NULL, $view_details = FALSE ) { |
|
193 | - return EED_Ticket_Selector::ticketSelector()->display( $event, $view_details ); |
|
192 | + public static function display_ticket_selector($event = NULL, $view_details = FALSE) { |
|
193 | + return EED_Ticket_Selector::ticketSelector()->display($event, $view_details); |
|
194 | 194 | } |
195 | 195 | |
196 | 196 | |
@@ -241,11 +241,11 @@ discard block |
||
241 | 241 | * @return void |
242 | 242 | */ |
243 | 243 | public static function load_tckt_slctr_assets() { |
244 | - if ( apply_filters( 'FHEE__EED_Ticket_Selector__load_tckt_slctr_assets', FALSE ) ) { |
|
244 | + if (apply_filters('FHEE__EED_Ticket_Selector__load_tckt_slctr_assets', FALSE)) { |
|
245 | 245 | // add some style |
246 | 246 | wp_register_style( |
247 | 247 | 'ticket_selector', |
248 | - TICKET_SELECTOR_ASSETS_URL . 'ticket_selector.css', |
|
248 | + TICKET_SELECTOR_ASSETS_URL.'ticket_selector.css', |
|
249 | 249 | array(), |
250 | 250 | EVENT_ESPRESSO_VERSION |
251 | 251 | ); |
@@ -253,13 +253,13 @@ discard block |
||
253 | 253 | // make it dance |
254 | 254 | wp_register_script( |
255 | 255 | 'ticket_selector', |
256 | - TICKET_SELECTOR_ASSETS_URL . 'ticket_selector.js', |
|
256 | + TICKET_SELECTOR_ASSETS_URL.'ticket_selector.js', |
|
257 | 257 | array('espresso_core'), |
258 | 258 | EVENT_ESPRESSO_VERSION, |
259 | 259 | TRUE |
260 | 260 | ); |
261 | 261 | wp_enqueue_script('ticket_selector'); |
262 | - require_once( EE_LIBRARIES.'form_sections/strategies/display/EE_Checkbox_Dropdown_Selector_Display_Strategy.strategy.php'); |
|
262 | + require_once(EE_LIBRARIES.'form_sections/strategies/display/EE_Checkbox_Dropdown_Selector_Display_Strategy.strategy.php'); |
|
263 | 263 | \EE_Checkbox_Dropdown_Selector_Display_Strategy::enqueue_styles_and_scripts(); |
264 | 264 | } |
265 | 265 | } |
@@ -301,7 +301,7 @@ discard block |
||
301 | 301 | */ |
302 | 302 | public static function iframeCss(array $iframe_css) |
303 | 303 | { |
304 | - $iframe_css['ticket_selector'] = TICKET_SELECTOR_ASSETS_URL . 'ticket_selector.css'; |
|
304 | + $iframe_css['ticket_selector'] = TICKET_SELECTOR_ASSETS_URL.'ticket_selector.css'; |
|
305 | 305 | return $iframe_css; |
306 | 306 | } |
307 | 307 | |
@@ -315,7 +315,7 @@ discard block |
||
315 | 315 | */ |
316 | 316 | public static function iframeJs(array $iframe_js) |
317 | 317 | { |
318 | - $iframe_js['ticket_selector'] = TICKET_SELECTOR_ASSETS_URL . 'ticket_selector.js'; |
|
318 | + $iframe_js['ticket_selector'] = TICKET_SELECTOR_ASSETS_URL.'ticket_selector.js'; |
|
319 | 319 | return $iframe_js; |
320 | 320 | } |
321 | 321 | |
@@ -440,8 +440,8 @@ discard block |
||
440 | 440 | { |
441 | 441 | // todo add doing_it_wrong() notice during next major version |
442 | 442 | if ( |
443 | - \EE_Registry::instance()->REQ->get( 'page' ) === 'espresso_events' |
|
444 | - && \EE_Registry::instance()->REQ->get( 'action' ) === 'edit' |
|
443 | + \EE_Registry::instance()->REQ->get('page') === 'espresso_events' |
|
444 | + && \EE_Registry::instance()->REQ->get('action') === 'edit' |
|
445 | 445 | ) { |
446 | 446 | $iframe_embed_button = \EED_Ticket_Selector::getIframeEmbedButton(); |
447 | 447 | $iframe_embed_button->embedButtonAssets(); |
@@ -19,404 +19,404 @@ |
||
19 | 19 | class TicketSelectorRowStandard extends TicketSelectorRow |
20 | 20 | { |
21 | 21 | |
22 | - /** |
|
23 | - * @var TicketDetails $ticket_details |
|
24 | - */ |
|
25 | - protected $ticket_details; |
|
26 | - |
|
27 | - /** |
|
28 | - * @var \EE_Ticket_Selector_Config $template_settings |
|
29 | - */ |
|
30 | - protected $template_settings; |
|
31 | - |
|
32 | - /** |
|
33 | - * @var \EE_Tax_Config $tax_settings |
|
34 | - */ |
|
35 | - protected $tax_settings; |
|
36 | - |
|
37 | - /** |
|
38 | - * @var boolean $prices_displayed_including_taxes |
|
39 | - */ |
|
40 | - protected $prices_displayed_including_taxes; |
|
41 | - |
|
42 | - /** |
|
43 | - * @var int $row |
|
44 | - */ |
|
45 | - protected $row; |
|
46 | - |
|
47 | - /** |
|
48 | - * @var int $cols |
|
49 | - */ |
|
50 | - protected $cols; |
|
51 | - |
|
52 | - /** |
|
53 | - * @var boolean $hidden_input_qty |
|
54 | - */ |
|
55 | - protected $hidden_input_qty; |
|
56 | - |
|
57 | - /** |
|
58 | - * @var string $ticket_datetime_classes |
|
59 | - */ |
|
60 | - protected $ticket_datetime_classes; |
|
61 | - |
|
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_atndz |
|
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_atndz, |
|
84 | - $row, |
|
85 | - $cols, |
|
86 | - $required_ticket_sold_out, |
|
87 | - $event_status, |
|
88 | - $ticket_datetime_classes |
|
89 | - ) { |
|
90 | - $this->ticket = $ticket_details->getTicket(); |
|
91 | - $this->ticket_details = $ticket_details; |
|
92 | - $this->template_settings = $ticket_details->getTemplateSettings(); |
|
93 | - $this->tax_settings = $tax_settings; |
|
94 | - $this->total_tickets = $total_tickets; |
|
95 | - $this->max_atndz = $max_atndz; |
|
96 | - $this->row = $row; |
|
97 | - $this->cols = $cols; |
|
98 | - $this->date_format = $ticket_details->getDateFormat(); |
|
99 | - $this->ticket_datetime_classes = $ticket_datetime_classes; |
|
100 | - parent::__construct($this->ticket, $max_atndz, $this->date_format, $event_status, $required_ticket_sold_out); |
|
101 | - } |
|
102 | - |
|
103 | - |
|
104 | - |
|
105 | - /** |
|
106 | - * other ticket rows will need to know if a required ticket is sold out, |
|
107 | - * so that they are not offered for sale |
|
108 | - * |
|
109 | - * @return boolean |
|
110 | - */ |
|
111 | - public function getRequiredTicketSoldOut() |
|
112 | - { |
|
113 | - return $this->required_ticket_sold_out; |
|
114 | - } |
|
115 | - |
|
116 | - |
|
117 | - |
|
118 | - /** |
|
119 | - * @return int |
|
120 | - */ |
|
121 | - public function getCols() |
|
122 | - { |
|
123 | - return $this->cols; |
|
124 | - } |
|
125 | - |
|
126 | - |
|
127 | - |
|
128 | - /** |
|
129 | - * getHtml |
|
130 | - * |
|
131 | - * @return string |
|
132 | - * @throws EE_Error |
|
133 | - */ |
|
134 | - public function getHtml() |
|
135 | - { |
|
136 | - $min = 0; |
|
137 | - $max = $this->ticket->max(); |
|
138 | - $remaining = $this->ticket->remaining(); |
|
139 | - if ($this->ticket->is_on_sale() && $this->ticket->is_remaining()) { |
|
140 | - list($min, $max) = $this->setTicketMinAndMax($remaining); |
|
141 | - } else { |
|
142 | - // set flag if ticket is required (flag is set to start date so that future tickets are not blocked) |
|
143 | - $this->required_ticket_sold_out = $this->ticket->required() && ! $remaining |
|
144 | - ? $this->ticket->start_date() |
|
145 | - : $this->required_ticket_sold_out; |
|
146 | - } |
|
147 | - list($ticket_price, $ticket_bundle) = $this->getTicketPriceDetails(); |
|
148 | - list($tkt_status, $ticket_status, $status_class) = $this->getTicketStatusClasses($remaining); |
|
149 | - /** |
|
150 | - * Allow plugins to hook in and abort the generation and display of this row to do |
|
151 | - * something else if they want. |
|
152 | - * For an addon to abort things, all they have to do is register a filter with this hook, and |
|
153 | - * return a value that is NOT false. Whatever is returned gets echoed instead of the |
|
154 | - * current row. |
|
155 | - * |
|
156 | - * @var string|bool |
|
157 | - */ |
|
158 | - $ticket_selector_row_html = apply_filters( |
|
159 | - 'FHEE__ticket_selector_chart_template__do_ticket_entire_row', |
|
160 | - false, |
|
161 | - $this->ticket, |
|
162 | - $max, |
|
163 | - $min, |
|
164 | - $this->required_ticket_sold_out, |
|
165 | - $ticket_price, |
|
166 | - $ticket_bundle, |
|
167 | - $ticket_status, |
|
168 | - $status_class |
|
169 | - ); |
|
170 | - if ($ticket_selector_row_html !== false) { |
|
171 | - return $ticket_selector_row_html; |
|
172 | - } |
|
173 | - $ticket_selector_row_html = \EEH_HTML::tr( |
|
174 | - '', '', |
|
175 | - "tckt-slctr-tbl-tr {$status_class}{$this->ticket_datetime_classes} " . espresso_get_object_css_class($this->ticket) |
|
176 | - ); |
|
177 | - /** |
|
178 | - * Allow plugins to hook in and abort the generation and display of the contents of this |
|
179 | - * row to do something else if they want. |
|
180 | - * For an addon to abort things, all they have to do is register a filter with this hook, and |
|
181 | - * return a value that is NOT false. Whatever is returned gets echoed instead of the |
|
182 | - * current row. |
|
183 | - * |
|
184 | - * @var string|bool |
|
185 | - */ |
|
186 | - $new_row_cells_content = apply_filters( |
|
187 | - 'FHEE__ticket_selector_chart_template__do_ticket_inside_row', |
|
188 | - false, |
|
189 | - $this->ticket, |
|
190 | - $max, |
|
191 | - $min, |
|
192 | - $this->required_ticket_sold_out, |
|
193 | - $ticket_price, |
|
194 | - $ticket_bundle, |
|
195 | - $ticket_status, |
|
196 | - $status_class |
|
197 | - ); |
|
198 | - if ($new_row_cells_content !== false && $this->max_atndz === 1) { |
|
199 | - return $ticket_selector_row_html |
|
200 | - . $new_row_cells_content |
|
201 | - . $this->ticketQtyAndIdHiddenInputs() |
|
202 | - . \EEH_HTML::trx(); |
|
203 | - } |
|
204 | - if ($new_row_cells_content !== false) { |
|
205 | - return $ticket_selector_row_html |
|
206 | - . $new_row_cells_content |
|
207 | - . \EEH_HTML::trx(); |
|
208 | - } |
|
209 | - $this->hidden_input_qty = $this->max_atndz > 1 ? true : false; |
|
210 | - |
|
211 | - $ticket_selector_row_html .= $this->ticketNameTableCell(); |
|
212 | - $ticket_selector_row_html .= $this->ticketPriceTableCell($ticket_price, $ticket_bundle); |
|
213 | - $ticket_selector_row_html .= \EEH_HTML::td('', '', 'tckt-slctr-tbl-td-qty cntr'); |
|
214 | - $this->setTicketStatusDisplay($tkt_status, $ticket_status, $remaining); |
|
215 | - if (empty($this->ticket_status_display)) { |
|
216 | - if ($this->max_atndz === 1) { |
|
217 | - // only ONE attendee is allowed to register at a time |
|
218 | - $ticket_selector_row_html .= $this->onlyOneAttendeeCanRegister(); |
|
219 | - } else if ($max > 0) { |
|
220 | - $ticket_selector_row_html .= $this->ticketQuantitySelector($min, $max); |
|
221 | - } |
|
222 | - } |
|
223 | - $ticket_selector_row_html .= $this->ticket_status_display; |
|
224 | - $ticket_selector_row_html .= $this->ticketQtyAndIdHiddenInputs(); |
|
225 | - $ticket_selector_row_html .= $this->ticket_details->display($ticket_price, $remaining, $this->cols); |
|
226 | - $ticket_selector_row_html .= \EEH_HTML::tdx(); |
|
227 | - $ticket_selector_row_html .= \EEH_HTML::trx(); |
|
228 | - |
|
229 | - |
|
230 | - $this->row++; |
|
231 | - return $ticket_selector_row_html; |
|
232 | - } |
|
233 | - |
|
234 | - |
|
235 | - |
|
236 | - /** |
|
237 | - * setTicketMinAndMax |
|
238 | - * |
|
239 | - * @param int $remaining |
|
240 | - * @return array |
|
241 | - * @throws EE_Error |
|
242 | - */ |
|
243 | - protected function setTicketMinAndMax($remaining) |
|
244 | - { |
|
245 | - // offer the number of $tickets_remaining or $this->max_atndz, whichever is smaller |
|
246 | - $max = min($remaining, $this->max_atndz); |
|
247 | - // but... we also want to restrict the number of tickets by the ticket max setting, |
|
248 | - // however, the max still can't be higher than what was just set above |
|
249 | - $max = $this->ticket->max() > 0 ? min($this->ticket->max(), $max) : $max; |
|
250 | - // and we also want to restrict the minimum number of tickets by the ticket min setting |
|
251 | - $min = $this->ticket->min() > 0 ? $this->ticket->min() : 0; |
|
252 | - // and if the ticket is required, then make sure that min qty is at least 1 |
|
253 | - $min = $this->ticket->required() ? max($min, 1) : $min; |
|
254 | - return array($min, $max); |
|
255 | - } |
|
256 | - |
|
257 | - |
|
258 | - |
|
259 | - /** |
|
260 | - * getTicketPriceDetails |
|
261 | - * |
|
262 | - * @return array |
|
263 | - * @throws EE_Error |
|
264 | - */ |
|
265 | - protected function getTicketPriceDetails() |
|
266 | - { |
|
267 | - $ticket_price = $this->tax_settings->prices_displayed_including_taxes |
|
268 | - ? $this->ticket->get_ticket_total_with_taxes() |
|
269 | - : $this->ticket->get_ticket_subtotal(); |
|
270 | - $ticket_bundle = false; |
|
271 | - $ticket_min = $this->ticket->min(); |
|
272 | - // for ticket bundles, set min and max qty the same |
|
273 | - if ($ticket_min !== 0 && $ticket_min === $this->ticket->max()) { |
|
274 | - $ticket_price *= $ticket_min; |
|
275 | - $ticket_bundle = true; |
|
276 | - } |
|
277 | - $ticket_price = apply_filters( |
|
278 | - 'FHEE__ticket_selector_chart_template__ticket_price', |
|
279 | - $ticket_price, |
|
280 | - $this->ticket |
|
281 | - ); |
|
282 | - return array($ticket_price, $ticket_bundle); |
|
283 | - } |
|
284 | - |
|
285 | - |
|
286 | - |
|
287 | - |
|
288 | - /** |
|
289 | - * ticketNameTableCell |
|
290 | - * |
|
291 | - * @return string |
|
292 | - * @throws EE_Error |
|
293 | - */ |
|
294 | - protected function ticketNameTableCell() |
|
295 | - { |
|
296 | - $html = \EEH_HTML::td('', '', 'tckt-slctr-tbl-td-name'); |
|
297 | - $html .= \EEH_HTML::strong($this->ticket->get_pretty('TKT_name')); |
|
298 | - $html .= $this->ticket_details->getShowHideLinks(); |
|
299 | - if ($this->ticket->required()) { |
|
300 | - $html .= \EEH_HTML::p( |
|
301 | - apply_filters( |
|
302 | - 'FHEE__ticket_selector_chart_template__ticket_required_message', |
|
303 | - esc_html__('This ticket is required and must be purchased.', 'event_espresso') |
|
304 | - ), |
|
305 | - '', 'ticket-required-pg' |
|
306 | - ); |
|
307 | - } |
|
308 | - $html .= \EEH_HTML::tdx(); |
|
309 | - return $html; |
|
310 | - } |
|
311 | - |
|
312 | - |
|
313 | - |
|
314 | - /** |
|
315 | - * ticketPriceTableCell |
|
316 | - * |
|
317 | - * @param float $ticket_price |
|
318 | - * @param bool $ticket_bundle |
|
319 | - * @return string |
|
320 | - * @throws EE_Error |
|
321 | - */ |
|
322 | - protected function ticketPriceTableCell($ticket_price, $ticket_bundle) |
|
323 | - { |
|
324 | - $html = ''; |
|
325 | - if (apply_filters('FHEE__ticket_selector_chart_template__display_ticket_price_details', true)) { |
|
326 | - $html .= \EEH_HTML::td('', '', 'tckt-slctr-tbl-td-price jst-rght'); |
|
327 | - $html .= \EEH_Template::format_currency($ticket_price); |
|
328 | - $html .= $this->ticket->taxable() |
|
329 | - ? \EEH_HTML::span( '*', '', 'taxable-tickets-asterisk grey-text' ) |
|
330 | - : ''; |
|
331 | - $html .= ' '; |
|
332 | - $html .= \EEH_HTML::span( |
|
333 | - $ticket_bundle |
|
334 | - ? apply_filters( |
|
335 | - 'FHEE__ticket_selector_chart_template__per_ticket_bundle_text', |
|
336 | - __(' / bundle', 'event_espresso') |
|
337 | - ) |
|
338 | - : apply_filters( |
|
339 | - 'FHEE__ticket_selector_chart_template__per_ticket_text', |
|
340 | - __('', 'event_espresso') |
|
341 | - ), |
|
342 | - '', 'smaller-text no-bold' |
|
343 | - ); |
|
344 | - $html .= ' '; |
|
345 | - $html .= \EEH_HTML::tdx(); |
|
346 | - $this->cols++; |
|
347 | - } |
|
348 | - return $html; |
|
349 | - } |
|
350 | - |
|
351 | - |
|
352 | - |
|
353 | - /** |
|
354 | - * onlyOneAttendeeCanRegister |
|
355 | - * |
|
356 | - * @return string |
|
357 | - */ |
|
358 | - protected function onlyOneAttendeeCanRegister() |
|
359 | - { |
|
360 | - // display submit button since we have tickets available |
|
361 | - add_filter('FHEE__EE_Ticket_Selector__display_ticket_selector_submit', '__return_true'); |
|
362 | - $this->hidden_input_qty = false; |
|
363 | - $html = '<input type="radio" name="tkt-slctr-qty-' . $this->EVT_ID . '"'; |
|
364 | - $html .= ' id="ticket-selector-tbl-qty-slct-' . $this->EVT_ID . '-' . $this->row . '"'; |
|
365 | - $html .= ' class="ticket-selector-tbl-qty-slct" value="' . $this->row . '-1"'; |
|
366 | - $html .= $this->total_tickets === 1 ? ' checked="checked"' : ''; |
|
367 | - $html .= ' title=""/>'; |
|
368 | - return $html; |
|
369 | - } |
|
370 | - |
|
371 | - |
|
372 | - |
|
373 | - /** |
|
374 | - * ticketQuantitySelector |
|
375 | - * |
|
376 | - * @param int $min |
|
377 | - * @param int $max |
|
378 | - * @return string |
|
379 | - * @throws EE_Error |
|
380 | - */ |
|
381 | - protected function ticketQuantitySelector($min = 0, $max = 0) |
|
382 | - { |
|
383 | - // display submit button since we have tickets available |
|
384 | - add_filter('FHEE__EE_Ticket_Selector__display_ticket_selector_submit', '__return_true'); |
|
385 | - $this->hidden_input_qty = false; |
|
386 | - $html = '<select name="tkt-slctr-qty-' . $this->EVT_ID . '[]"'; |
|
387 | - $html .= ' id="ticket-selector-tbl-qty-slct-' . $this->EVT_ID . '-' . $this->row . '"'; |
|
388 | - $html .= ' class="ticket-selector-tbl-qty-slct">'; |
|
389 | - // this ensures that non-required tickets with non-zero MIN QTYs don't HAVE to be purchased |
|
390 | - if ($min !== 0 && ! $this->ticket->required()) { |
|
391 | - $html .= '<option value="0"> 0 </option>'; |
|
392 | - } |
|
393 | - // offer ticket quantities from the min to the max |
|
394 | - for ($i = $min; $i <= $max; $i++) { |
|
395 | - $html .= '<option value="' . $i . '"> ' . $i . ' </option>'; |
|
396 | - } |
|
397 | - $html .= '</select>'; |
|
398 | - return $html; |
|
399 | - } |
|
400 | - |
|
401 | - |
|
402 | - |
|
403 | - /** |
|
404 | - * getHiddenInputs |
|
405 | - * |
|
406 | - * @return string |
|
407 | - * @throws EE_Error |
|
408 | - */ |
|
409 | - protected function ticketQtyAndIdHiddenInputs() |
|
410 | - { |
|
411 | - $html = ''; |
|
412 | - // depending on group reg we need to change the format for qty |
|
413 | - if ($this->hidden_input_qty) { |
|
414 | - $html .= '<input type="hidden" name="tkt-slctr-qty-' . $this->EVT_ID . '[]" value="0"/>'; |
|
415 | - } |
|
416 | - $html .= '<input type="hidden" name="tkt-slctr-ticket-id-' . $this->EVT_ID . '[]"'; |
|
417 | - $html .= ' value="' . $this->ticket->ID() . '"/>'; |
|
418 | - return $html; |
|
419 | - } |
|
22 | + /** |
|
23 | + * @var TicketDetails $ticket_details |
|
24 | + */ |
|
25 | + protected $ticket_details; |
|
26 | + |
|
27 | + /** |
|
28 | + * @var \EE_Ticket_Selector_Config $template_settings |
|
29 | + */ |
|
30 | + protected $template_settings; |
|
31 | + |
|
32 | + /** |
|
33 | + * @var \EE_Tax_Config $tax_settings |
|
34 | + */ |
|
35 | + protected $tax_settings; |
|
36 | + |
|
37 | + /** |
|
38 | + * @var boolean $prices_displayed_including_taxes |
|
39 | + */ |
|
40 | + protected $prices_displayed_including_taxes; |
|
41 | + |
|
42 | + /** |
|
43 | + * @var int $row |
|
44 | + */ |
|
45 | + protected $row; |
|
46 | + |
|
47 | + /** |
|
48 | + * @var int $cols |
|
49 | + */ |
|
50 | + protected $cols; |
|
51 | + |
|
52 | + /** |
|
53 | + * @var boolean $hidden_input_qty |
|
54 | + */ |
|
55 | + protected $hidden_input_qty; |
|
56 | + |
|
57 | + /** |
|
58 | + * @var string $ticket_datetime_classes |
|
59 | + */ |
|
60 | + protected $ticket_datetime_classes; |
|
61 | + |
|
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_atndz |
|
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_atndz, |
|
84 | + $row, |
|
85 | + $cols, |
|
86 | + $required_ticket_sold_out, |
|
87 | + $event_status, |
|
88 | + $ticket_datetime_classes |
|
89 | + ) { |
|
90 | + $this->ticket = $ticket_details->getTicket(); |
|
91 | + $this->ticket_details = $ticket_details; |
|
92 | + $this->template_settings = $ticket_details->getTemplateSettings(); |
|
93 | + $this->tax_settings = $tax_settings; |
|
94 | + $this->total_tickets = $total_tickets; |
|
95 | + $this->max_atndz = $max_atndz; |
|
96 | + $this->row = $row; |
|
97 | + $this->cols = $cols; |
|
98 | + $this->date_format = $ticket_details->getDateFormat(); |
|
99 | + $this->ticket_datetime_classes = $ticket_datetime_classes; |
|
100 | + parent::__construct($this->ticket, $max_atndz, $this->date_format, $event_status, $required_ticket_sold_out); |
|
101 | + } |
|
102 | + |
|
103 | + |
|
104 | + |
|
105 | + /** |
|
106 | + * other ticket rows will need to know if a required ticket is sold out, |
|
107 | + * so that they are not offered for sale |
|
108 | + * |
|
109 | + * @return boolean |
|
110 | + */ |
|
111 | + public function getRequiredTicketSoldOut() |
|
112 | + { |
|
113 | + return $this->required_ticket_sold_out; |
|
114 | + } |
|
115 | + |
|
116 | + |
|
117 | + |
|
118 | + /** |
|
119 | + * @return int |
|
120 | + */ |
|
121 | + public function getCols() |
|
122 | + { |
|
123 | + return $this->cols; |
|
124 | + } |
|
125 | + |
|
126 | + |
|
127 | + |
|
128 | + /** |
|
129 | + * getHtml |
|
130 | + * |
|
131 | + * @return string |
|
132 | + * @throws EE_Error |
|
133 | + */ |
|
134 | + public function getHtml() |
|
135 | + { |
|
136 | + $min = 0; |
|
137 | + $max = $this->ticket->max(); |
|
138 | + $remaining = $this->ticket->remaining(); |
|
139 | + if ($this->ticket->is_on_sale() && $this->ticket->is_remaining()) { |
|
140 | + list($min, $max) = $this->setTicketMinAndMax($remaining); |
|
141 | + } else { |
|
142 | + // set flag if ticket is required (flag is set to start date so that future tickets are not blocked) |
|
143 | + $this->required_ticket_sold_out = $this->ticket->required() && ! $remaining |
|
144 | + ? $this->ticket->start_date() |
|
145 | + : $this->required_ticket_sold_out; |
|
146 | + } |
|
147 | + list($ticket_price, $ticket_bundle) = $this->getTicketPriceDetails(); |
|
148 | + list($tkt_status, $ticket_status, $status_class) = $this->getTicketStatusClasses($remaining); |
|
149 | + /** |
|
150 | + * Allow plugins to hook in and abort the generation and display of this row to do |
|
151 | + * something else if they want. |
|
152 | + * For an addon to abort things, all they have to do is register a filter with this hook, and |
|
153 | + * return a value that is NOT false. Whatever is returned gets echoed instead of the |
|
154 | + * current row. |
|
155 | + * |
|
156 | + * @var string|bool |
|
157 | + */ |
|
158 | + $ticket_selector_row_html = apply_filters( |
|
159 | + 'FHEE__ticket_selector_chart_template__do_ticket_entire_row', |
|
160 | + false, |
|
161 | + $this->ticket, |
|
162 | + $max, |
|
163 | + $min, |
|
164 | + $this->required_ticket_sold_out, |
|
165 | + $ticket_price, |
|
166 | + $ticket_bundle, |
|
167 | + $ticket_status, |
|
168 | + $status_class |
|
169 | + ); |
|
170 | + if ($ticket_selector_row_html !== false) { |
|
171 | + return $ticket_selector_row_html; |
|
172 | + } |
|
173 | + $ticket_selector_row_html = \EEH_HTML::tr( |
|
174 | + '', '', |
|
175 | + "tckt-slctr-tbl-tr {$status_class}{$this->ticket_datetime_classes} " . espresso_get_object_css_class($this->ticket) |
|
176 | + ); |
|
177 | + /** |
|
178 | + * Allow plugins to hook in and abort the generation and display of the contents of this |
|
179 | + * row to do something else if they want. |
|
180 | + * For an addon to abort things, all they have to do is register a filter with this hook, and |
|
181 | + * return a value that is NOT false. Whatever is returned gets echoed instead of the |
|
182 | + * current row. |
|
183 | + * |
|
184 | + * @var string|bool |
|
185 | + */ |
|
186 | + $new_row_cells_content = apply_filters( |
|
187 | + 'FHEE__ticket_selector_chart_template__do_ticket_inside_row', |
|
188 | + false, |
|
189 | + $this->ticket, |
|
190 | + $max, |
|
191 | + $min, |
|
192 | + $this->required_ticket_sold_out, |
|
193 | + $ticket_price, |
|
194 | + $ticket_bundle, |
|
195 | + $ticket_status, |
|
196 | + $status_class |
|
197 | + ); |
|
198 | + if ($new_row_cells_content !== false && $this->max_atndz === 1) { |
|
199 | + return $ticket_selector_row_html |
|
200 | + . $new_row_cells_content |
|
201 | + . $this->ticketQtyAndIdHiddenInputs() |
|
202 | + . \EEH_HTML::trx(); |
|
203 | + } |
|
204 | + if ($new_row_cells_content !== false) { |
|
205 | + return $ticket_selector_row_html |
|
206 | + . $new_row_cells_content |
|
207 | + . \EEH_HTML::trx(); |
|
208 | + } |
|
209 | + $this->hidden_input_qty = $this->max_atndz > 1 ? true : false; |
|
210 | + |
|
211 | + $ticket_selector_row_html .= $this->ticketNameTableCell(); |
|
212 | + $ticket_selector_row_html .= $this->ticketPriceTableCell($ticket_price, $ticket_bundle); |
|
213 | + $ticket_selector_row_html .= \EEH_HTML::td('', '', 'tckt-slctr-tbl-td-qty cntr'); |
|
214 | + $this->setTicketStatusDisplay($tkt_status, $ticket_status, $remaining); |
|
215 | + if (empty($this->ticket_status_display)) { |
|
216 | + if ($this->max_atndz === 1) { |
|
217 | + // only ONE attendee is allowed to register at a time |
|
218 | + $ticket_selector_row_html .= $this->onlyOneAttendeeCanRegister(); |
|
219 | + } else if ($max > 0) { |
|
220 | + $ticket_selector_row_html .= $this->ticketQuantitySelector($min, $max); |
|
221 | + } |
|
222 | + } |
|
223 | + $ticket_selector_row_html .= $this->ticket_status_display; |
|
224 | + $ticket_selector_row_html .= $this->ticketQtyAndIdHiddenInputs(); |
|
225 | + $ticket_selector_row_html .= $this->ticket_details->display($ticket_price, $remaining, $this->cols); |
|
226 | + $ticket_selector_row_html .= \EEH_HTML::tdx(); |
|
227 | + $ticket_selector_row_html .= \EEH_HTML::trx(); |
|
228 | + |
|
229 | + |
|
230 | + $this->row++; |
|
231 | + return $ticket_selector_row_html; |
|
232 | + } |
|
233 | + |
|
234 | + |
|
235 | + |
|
236 | + /** |
|
237 | + * setTicketMinAndMax |
|
238 | + * |
|
239 | + * @param int $remaining |
|
240 | + * @return array |
|
241 | + * @throws EE_Error |
|
242 | + */ |
|
243 | + protected function setTicketMinAndMax($remaining) |
|
244 | + { |
|
245 | + // offer the number of $tickets_remaining or $this->max_atndz, whichever is smaller |
|
246 | + $max = min($remaining, $this->max_atndz); |
|
247 | + // but... we also want to restrict the number of tickets by the ticket max setting, |
|
248 | + // however, the max still can't be higher than what was just set above |
|
249 | + $max = $this->ticket->max() > 0 ? min($this->ticket->max(), $max) : $max; |
|
250 | + // and we also want to restrict the minimum number of tickets by the ticket min setting |
|
251 | + $min = $this->ticket->min() > 0 ? $this->ticket->min() : 0; |
|
252 | + // and if the ticket is required, then make sure that min qty is at least 1 |
|
253 | + $min = $this->ticket->required() ? max($min, 1) : $min; |
|
254 | + return array($min, $max); |
|
255 | + } |
|
256 | + |
|
257 | + |
|
258 | + |
|
259 | + /** |
|
260 | + * getTicketPriceDetails |
|
261 | + * |
|
262 | + * @return array |
|
263 | + * @throws EE_Error |
|
264 | + */ |
|
265 | + protected function getTicketPriceDetails() |
|
266 | + { |
|
267 | + $ticket_price = $this->tax_settings->prices_displayed_including_taxes |
|
268 | + ? $this->ticket->get_ticket_total_with_taxes() |
|
269 | + : $this->ticket->get_ticket_subtotal(); |
|
270 | + $ticket_bundle = false; |
|
271 | + $ticket_min = $this->ticket->min(); |
|
272 | + // for ticket bundles, set min and max qty the same |
|
273 | + if ($ticket_min !== 0 && $ticket_min === $this->ticket->max()) { |
|
274 | + $ticket_price *= $ticket_min; |
|
275 | + $ticket_bundle = true; |
|
276 | + } |
|
277 | + $ticket_price = apply_filters( |
|
278 | + 'FHEE__ticket_selector_chart_template__ticket_price', |
|
279 | + $ticket_price, |
|
280 | + $this->ticket |
|
281 | + ); |
|
282 | + return array($ticket_price, $ticket_bundle); |
|
283 | + } |
|
284 | + |
|
285 | + |
|
286 | + |
|
287 | + |
|
288 | + /** |
|
289 | + * ticketNameTableCell |
|
290 | + * |
|
291 | + * @return string |
|
292 | + * @throws EE_Error |
|
293 | + */ |
|
294 | + protected function ticketNameTableCell() |
|
295 | + { |
|
296 | + $html = \EEH_HTML::td('', '', 'tckt-slctr-tbl-td-name'); |
|
297 | + $html .= \EEH_HTML::strong($this->ticket->get_pretty('TKT_name')); |
|
298 | + $html .= $this->ticket_details->getShowHideLinks(); |
|
299 | + if ($this->ticket->required()) { |
|
300 | + $html .= \EEH_HTML::p( |
|
301 | + apply_filters( |
|
302 | + 'FHEE__ticket_selector_chart_template__ticket_required_message', |
|
303 | + esc_html__('This ticket is required and must be purchased.', 'event_espresso') |
|
304 | + ), |
|
305 | + '', 'ticket-required-pg' |
|
306 | + ); |
|
307 | + } |
|
308 | + $html .= \EEH_HTML::tdx(); |
|
309 | + return $html; |
|
310 | + } |
|
311 | + |
|
312 | + |
|
313 | + |
|
314 | + /** |
|
315 | + * ticketPriceTableCell |
|
316 | + * |
|
317 | + * @param float $ticket_price |
|
318 | + * @param bool $ticket_bundle |
|
319 | + * @return string |
|
320 | + * @throws EE_Error |
|
321 | + */ |
|
322 | + protected function ticketPriceTableCell($ticket_price, $ticket_bundle) |
|
323 | + { |
|
324 | + $html = ''; |
|
325 | + if (apply_filters('FHEE__ticket_selector_chart_template__display_ticket_price_details', true)) { |
|
326 | + $html .= \EEH_HTML::td('', '', 'tckt-slctr-tbl-td-price jst-rght'); |
|
327 | + $html .= \EEH_Template::format_currency($ticket_price); |
|
328 | + $html .= $this->ticket->taxable() |
|
329 | + ? \EEH_HTML::span( '*', '', 'taxable-tickets-asterisk grey-text' ) |
|
330 | + : ''; |
|
331 | + $html .= ' '; |
|
332 | + $html .= \EEH_HTML::span( |
|
333 | + $ticket_bundle |
|
334 | + ? apply_filters( |
|
335 | + 'FHEE__ticket_selector_chart_template__per_ticket_bundle_text', |
|
336 | + __(' / bundle', 'event_espresso') |
|
337 | + ) |
|
338 | + : apply_filters( |
|
339 | + 'FHEE__ticket_selector_chart_template__per_ticket_text', |
|
340 | + __('', 'event_espresso') |
|
341 | + ), |
|
342 | + '', 'smaller-text no-bold' |
|
343 | + ); |
|
344 | + $html .= ' '; |
|
345 | + $html .= \EEH_HTML::tdx(); |
|
346 | + $this->cols++; |
|
347 | + } |
|
348 | + return $html; |
|
349 | + } |
|
350 | + |
|
351 | + |
|
352 | + |
|
353 | + /** |
|
354 | + * onlyOneAttendeeCanRegister |
|
355 | + * |
|
356 | + * @return string |
|
357 | + */ |
|
358 | + protected function onlyOneAttendeeCanRegister() |
|
359 | + { |
|
360 | + // display submit button since we have tickets available |
|
361 | + add_filter('FHEE__EE_Ticket_Selector__display_ticket_selector_submit', '__return_true'); |
|
362 | + $this->hidden_input_qty = false; |
|
363 | + $html = '<input type="radio" name="tkt-slctr-qty-' . $this->EVT_ID . '"'; |
|
364 | + $html .= ' id="ticket-selector-tbl-qty-slct-' . $this->EVT_ID . '-' . $this->row . '"'; |
|
365 | + $html .= ' class="ticket-selector-tbl-qty-slct" value="' . $this->row . '-1"'; |
|
366 | + $html .= $this->total_tickets === 1 ? ' checked="checked"' : ''; |
|
367 | + $html .= ' title=""/>'; |
|
368 | + return $html; |
|
369 | + } |
|
370 | + |
|
371 | + |
|
372 | + |
|
373 | + /** |
|
374 | + * ticketQuantitySelector |
|
375 | + * |
|
376 | + * @param int $min |
|
377 | + * @param int $max |
|
378 | + * @return string |
|
379 | + * @throws EE_Error |
|
380 | + */ |
|
381 | + protected function ticketQuantitySelector($min = 0, $max = 0) |
|
382 | + { |
|
383 | + // display submit button since we have tickets available |
|
384 | + add_filter('FHEE__EE_Ticket_Selector__display_ticket_selector_submit', '__return_true'); |
|
385 | + $this->hidden_input_qty = false; |
|
386 | + $html = '<select name="tkt-slctr-qty-' . $this->EVT_ID . '[]"'; |
|
387 | + $html .= ' id="ticket-selector-tbl-qty-slct-' . $this->EVT_ID . '-' . $this->row . '"'; |
|
388 | + $html .= ' class="ticket-selector-tbl-qty-slct">'; |
|
389 | + // this ensures that non-required tickets with non-zero MIN QTYs don't HAVE to be purchased |
|
390 | + if ($min !== 0 && ! $this->ticket->required()) { |
|
391 | + $html .= '<option value="0"> 0 </option>'; |
|
392 | + } |
|
393 | + // offer ticket quantities from the min to the max |
|
394 | + for ($i = $min; $i <= $max; $i++) { |
|
395 | + $html .= '<option value="' . $i . '"> ' . $i . ' </option>'; |
|
396 | + } |
|
397 | + $html .= '</select>'; |
|
398 | + return $html; |
|
399 | + } |
|
400 | + |
|
401 | + |
|
402 | + |
|
403 | + /** |
|
404 | + * getHiddenInputs |
|
405 | + * |
|
406 | + * @return string |
|
407 | + * @throws EE_Error |
|
408 | + */ |
|
409 | + protected function ticketQtyAndIdHiddenInputs() |
|
410 | + { |
|
411 | + $html = ''; |
|
412 | + // depending on group reg we need to change the format for qty |
|
413 | + if ($this->hidden_input_qty) { |
|
414 | + $html .= '<input type="hidden" name="tkt-slctr-qty-' . $this->EVT_ID . '[]" value="0"/>'; |
|
415 | + } |
|
416 | + $html .= '<input type="hidden" name="tkt-slctr-ticket-id-' . $this->EVT_ID . '[]"'; |
|
417 | + $html .= ' value="' . $this->ticket->ID() . '"/>'; |
|
418 | + return $html; |
|
419 | + } |
|
420 | 420 | |
421 | 421 | } |
422 | 422 | // End of file TicketSelectorRowStandard.php |
@@ -14,7 +14,7 @@ discard block |
||
14 | 14 | use EventEspresso\core\libraries\rest_api\controllers\model\Read; |
15 | 15 | |
16 | 16 | if (! defined('EVENT_ESPRESSO_VERSION')) { |
17 | - exit('No direct script access allowed'); |
|
17 | + exit('No direct script access allowed'); |
|
18 | 18 | } |
19 | 19 | |
20 | 20 | |
@@ -31,116 +31,116 @@ discard block |
||
31 | 31 | class Checkin extends Base |
32 | 32 | { |
33 | 33 | |
34 | - /** |
|
35 | - * @param WP_REST_Request $request |
|
36 | - * @return WP_Error|WP_REST_Response |
|
37 | - */ |
|
38 | - public static function handle_request_toggle_checkin(WP_REST_Request $request) |
|
39 | - { |
|
40 | - $controller = new Checkin(); |
|
41 | - return $controller->_create_checkin_checkout_object($request); |
|
42 | - } |
|
34 | + /** |
|
35 | + * @param WP_REST_Request $request |
|
36 | + * @return WP_Error|WP_REST_Response |
|
37 | + */ |
|
38 | + public static function handle_request_toggle_checkin(WP_REST_Request $request) |
|
39 | + { |
|
40 | + $controller = new Checkin(); |
|
41 | + return $controller->_create_checkin_checkout_object($request); |
|
42 | + } |
|
43 | 43 | |
44 | 44 | |
45 | 45 | |
46 | - /** |
|
47 | - * Toggles whether the user is checked in or not. |
|
48 | - * |
|
49 | - * @param WP_REST_Request $request |
|
50 | - * @return WP_Error|WP_REST_Response |
|
51 | - */ |
|
52 | - protected function _create_checkin_checkout_object(WP_REST_Request $request) |
|
53 | - { |
|
54 | - $reg_id = $request->get_param('REG_ID'); |
|
55 | - $dtt_id = $request->get_param('DTT_ID'); |
|
56 | - $force = $request->get_param('force'); |
|
57 | - if ($force == 'true') { |
|
58 | - $force = true; |
|
59 | - } else { |
|
60 | - $force = false; |
|
61 | - } |
|
62 | - $reg = EEM_Registration::instance()->get_one_by_ID($reg_id); |
|
63 | - if (! $reg instanceof EE_Registration) { |
|
64 | - return $this->send_response( |
|
65 | - new WP_Error( |
|
66 | - 'rest_registration_toggle_checkin_invalid_id', |
|
67 | - sprintf( |
|
68 | - __('You cannot checkin registration with ID %1$s because it doesn\'t exist.', |
|
69 | - 'event_espresso'), |
|
70 | - $reg_id |
|
71 | - ), |
|
72 | - array('status' => 422) |
|
73 | - ) |
|
74 | - ); |
|
75 | - } |
|
76 | - if (! EE_Capabilities::instance() |
|
77 | - ->current_user_can('ee_edit_checkin', 'rest_api_checkin_endpoint', $reg_id) |
|
78 | - ) { |
|
79 | - return $this->send_response( |
|
80 | - new WP_Error( |
|
81 | - 'rest_user_cannot_toggle_checkin', |
|
82 | - sprintf( |
|
83 | - __('You are not allowed to checkin registration with ID %1$s.', 'event_espresso'), |
|
84 | - $reg_id |
|
85 | - ), |
|
86 | - array('status' => 403) |
|
87 | - ) |
|
88 | - ); |
|
89 | - } |
|
90 | - $success = $reg->toggle_checkin_status($dtt_id, ! $force); |
|
91 | - if ($success === false) { |
|
92 | - //check if we know they can't check in because they're not approved and we aren't forcing |
|
93 | - if (! $reg->is_approved() && ! $force) { |
|
94 | - //rely on EE_Error::add_error messages to have been added to give more data about why it failed |
|
95 | - return $this->send_response( |
|
96 | - new WP_Error( |
|
97 | - 'rest_toggle_checkin_failed', |
|
98 | - __('Registration check-in failed because the registration is not approved. You may attempt to force checking in though.', |
|
99 | - 'event_espresso') |
|
100 | - ) |
|
101 | - ); |
|
102 | - } |
|
103 | - return $this->send_response( |
|
104 | - new WP_Error( |
|
105 | - 'rest_toggle_checkin_failed_not_forceable', |
|
106 | - __('Registration checkin failed. Please see additional error data.', 'event_espresso') |
|
107 | - ) |
|
108 | - ); |
|
109 | - } |
|
110 | - $checkin = EEM_Checkin::instance()->get_one( |
|
111 | - array( |
|
112 | - array( |
|
113 | - 'REG_ID' => $reg_id, |
|
114 | - 'DTT_ID' => $dtt_id, |
|
115 | - ), |
|
116 | - 'order_by' => array( |
|
117 | - 'CHK_timestamp' => 'DESC', |
|
118 | - ), |
|
119 | - ) |
|
120 | - ); |
|
121 | - if (! $checkin instanceof EE_Checkin) { |
|
122 | - return $this->send_response( |
|
123 | - new WP_Error( |
|
124 | - 'rest_toggle_checkin_error', |
|
125 | - sprintf( |
|
126 | - __('Supposedly we created a new checkin object for registration %1$s at datetime %2$s, but we can\'t find it.', |
|
127 | - 'event_espresso'), |
|
128 | - $reg_id, |
|
129 | - $dtt_id |
|
130 | - ) |
|
131 | - ) |
|
132 | - ); |
|
133 | - } |
|
134 | - $requested_version = $this->get_requested_version($request->get_route()); |
|
135 | - $get_request = new WP_REST_Request( |
|
136 | - 'GET', |
|
137 | - EED_Core_Rest_Api::ee_api_namespace . $requested_version . '/checkins/' . $checkin->ID() |
|
138 | - ); |
|
139 | - $get_request->set_url_params( |
|
140 | - array( |
|
141 | - 'id' => $checkin->ID(), |
|
142 | - ) |
|
143 | - ); |
|
144 | - return Read::handle_request_get_one($get_request); |
|
145 | - } |
|
46 | + /** |
|
47 | + * Toggles whether the user is checked in or not. |
|
48 | + * |
|
49 | + * @param WP_REST_Request $request |
|
50 | + * @return WP_Error|WP_REST_Response |
|
51 | + */ |
|
52 | + protected function _create_checkin_checkout_object(WP_REST_Request $request) |
|
53 | + { |
|
54 | + $reg_id = $request->get_param('REG_ID'); |
|
55 | + $dtt_id = $request->get_param('DTT_ID'); |
|
56 | + $force = $request->get_param('force'); |
|
57 | + if ($force == 'true') { |
|
58 | + $force = true; |
|
59 | + } else { |
|
60 | + $force = false; |
|
61 | + } |
|
62 | + $reg = EEM_Registration::instance()->get_one_by_ID($reg_id); |
|
63 | + if (! $reg instanceof EE_Registration) { |
|
64 | + return $this->send_response( |
|
65 | + new WP_Error( |
|
66 | + 'rest_registration_toggle_checkin_invalid_id', |
|
67 | + sprintf( |
|
68 | + __('You cannot checkin registration with ID %1$s because it doesn\'t exist.', |
|
69 | + 'event_espresso'), |
|
70 | + $reg_id |
|
71 | + ), |
|
72 | + array('status' => 422) |
|
73 | + ) |
|
74 | + ); |
|
75 | + } |
|
76 | + if (! EE_Capabilities::instance() |
|
77 | + ->current_user_can('ee_edit_checkin', 'rest_api_checkin_endpoint', $reg_id) |
|
78 | + ) { |
|
79 | + return $this->send_response( |
|
80 | + new WP_Error( |
|
81 | + 'rest_user_cannot_toggle_checkin', |
|
82 | + sprintf( |
|
83 | + __('You are not allowed to checkin registration with ID %1$s.', 'event_espresso'), |
|
84 | + $reg_id |
|
85 | + ), |
|
86 | + array('status' => 403) |
|
87 | + ) |
|
88 | + ); |
|
89 | + } |
|
90 | + $success = $reg->toggle_checkin_status($dtt_id, ! $force); |
|
91 | + if ($success === false) { |
|
92 | + //check if we know they can't check in because they're not approved and we aren't forcing |
|
93 | + if (! $reg->is_approved() && ! $force) { |
|
94 | + //rely on EE_Error::add_error messages to have been added to give more data about why it failed |
|
95 | + return $this->send_response( |
|
96 | + new WP_Error( |
|
97 | + 'rest_toggle_checkin_failed', |
|
98 | + __('Registration check-in failed because the registration is not approved. You may attempt to force checking in though.', |
|
99 | + 'event_espresso') |
|
100 | + ) |
|
101 | + ); |
|
102 | + } |
|
103 | + return $this->send_response( |
|
104 | + new WP_Error( |
|
105 | + 'rest_toggle_checkin_failed_not_forceable', |
|
106 | + __('Registration checkin failed. Please see additional error data.', 'event_espresso') |
|
107 | + ) |
|
108 | + ); |
|
109 | + } |
|
110 | + $checkin = EEM_Checkin::instance()->get_one( |
|
111 | + array( |
|
112 | + array( |
|
113 | + 'REG_ID' => $reg_id, |
|
114 | + 'DTT_ID' => $dtt_id, |
|
115 | + ), |
|
116 | + 'order_by' => array( |
|
117 | + 'CHK_timestamp' => 'DESC', |
|
118 | + ), |
|
119 | + ) |
|
120 | + ); |
|
121 | + if (! $checkin instanceof EE_Checkin) { |
|
122 | + return $this->send_response( |
|
123 | + new WP_Error( |
|
124 | + 'rest_toggle_checkin_error', |
|
125 | + sprintf( |
|
126 | + __('Supposedly we created a new checkin object for registration %1$s at datetime %2$s, but we can\'t find it.', |
|
127 | + 'event_espresso'), |
|
128 | + $reg_id, |
|
129 | + $dtt_id |
|
130 | + ) |
|
131 | + ) |
|
132 | + ); |
|
133 | + } |
|
134 | + $requested_version = $this->get_requested_version($request->get_route()); |
|
135 | + $get_request = new WP_REST_Request( |
|
136 | + 'GET', |
|
137 | + EED_Core_Rest_Api::ee_api_namespace . $requested_version . '/checkins/' . $checkin->ID() |
|
138 | + ); |
|
139 | + $get_request->set_url_params( |
|
140 | + array( |
|
141 | + 'id' => $checkin->ID(), |
|
142 | + ) |
|
143 | + ); |
|
144 | + return Read::handle_request_get_one($get_request); |
|
145 | + } |
|
146 | 146 | } |
147 | 147 | \ No newline at end of file |
@@ -13,7 +13,7 @@ discard block |
||
13 | 13 | use EventEspresso\core\libraries\rest_api\controllers\Base as Base; |
14 | 14 | use EventEspresso\core\libraries\rest_api\controllers\model\Read; |
15 | 15 | |
16 | -if (! defined('EVENT_ESPRESSO_VERSION')) { |
|
16 | +if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
|
17 | 17 | exit('No direct script access allowed'); |
18 | 18 | } |
19 | 19 | |
@@ -60,7 +60,7 @@ discard block |
||
60 | 60 | $force = false; |
61 | 61 | } |
62 | 62 | $reg = EEM_Registration::instance()->get_one_by_ID($reg_id); |
63 | - if (! $reg instanceof EE_Registration) { |
|
63 | + if ( ! $reg instanceof EE_Registration) { |
|
64 | 64 | return $this->send_response( |
65 | 65 | new WP_Error( |
66 | 66 | 'rest_registration_toggle_checkin_invalid_id', |
@@ -73,7 +73,7 @@ discard block |
||
73 | 73 | ) |
74 | 74 | ); |
75 | 75 | } |
76 | - if (! EE_Capabilities::instance() |
|
76 | + if ( ! EE_Capabilities::instance() |
|
77 | 77 | ->current_user_can('ee_edit_checkin', 'rest_api_checkin_endpoint', $reg_id) |
78 | 78 | ) { |
79 | 79 | return $this->send_response( |
@@ -90,7 +90,7 @@ discard block |
||
90 | 90 | $success = $reg->toggle_checkin_status($dtt_id, ! $force); |
91 | 91 | if ($success === false) { |
92 | 92 | //check if we know they can't check in because they're not approved and we aren't forcing |
93 | - if (! $reg->is_approved() && ! $force) { |
|
93 | + if ( ! $reg->is_approved() && ! $force) { |
|
94 | 94 | //rely on EE_Error::add_error messages to have been added to give more data about why it failed |
95 | 95 | return $this->send_response( |
96 | 96 | new WP_Error( |
@@ -118,7 +118,7 @@ discard block |
||
118 | 118 | ), |
119 | 119 | ) |
120 | 120 | ); |
121 | - if (! $checkin instanceof EE_Checkin) { |
|
121 | + if ( ! $checkin instanceof EE_Checkin) { |
|
122 | 122 | return $this->send_response( |
123 | 123 | new WP_Error( |
124 | 124 | 'rest_toggle_checkin_error', |
@@ -134,7 +134,7 @@ discard block |
||
134 | 134 | $requested_version = $this->get_requested_version($request->get_route()); |
135 | 135 | $get_request = new WP_REST_Request( |
136 | 136 | 'GET', |
137 | - EED_Core_Rest_Api::ee_api_namespace . $requested_version . '/checkins/' . $checkin->ID() |
|
137 | + EED_Core_Rest_Api::ee_api_namespace.$requested_version.'/checkins/'.$checkin->ID() |
|
138 | 138 | ); |
139 | 139 | $get_request->set_url_params( |
140 | 140 | array( |
@@ -1,6 +1,6 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | if (! defined('EVENT_ESPRESSO_VERSION')) { |
3 | - exit('NO direct script access allowed'); |
|
3 | + exit('NO direct script access allowed'); |
|
4 | 4 | } |
5 | 5 | |
6 | 6 | |
@@ -28,616 +28,616 @@ discard block |
||
28 | 28 | class EE_Transaction_Shortcodes extends EE_Shortcodes |
29 | 29 | { |
30 | 30 | |
31 | - /** |
|
32 | - * @var EE_Payment_Method $_invoice_pm the invoiec payment method for use in invoices etc |
|
33 | - */ |
|
34 | - protected $_invoice_pm; |
|
35 | - |
|
36 | - |
|
37 | - |
|
38 | - /** |
|
39 | - * EE_Transaction_Shortcodes constructor. |
|
40 | - */ |
|
41 | - public function __construct() |
|
42 | - { |
|
43 | - parent::__construct(); |
|
44 | - } |
|
45 | - |
|
46 | - |
|
47 | - |
|
48 | - protected function _init_props() |
|
49 | - { |
|
50 | - $this->label = esc_html__('Transaction Shortcodes', 'event_espresso'); |
|
51 | - $this->description = esc_html__('All shortcodes specific to transaction related data', 'event_espresso'); |
|
52 | - $this->_shortcodes = array( |
|
53 | - '[TXN_ID]' => esc_html__('The transaction id for the purchase.', 'event_espresso'), |
|
54 | - '[PAYMENT_URL]' => esc_html__('This is a link to make a payment for the event', |
|
55 | - 'event_espresso'), |
|
56 | - '[PAYMENT_LINK_IF_NEEDED_*]' => esc_html__('This is a special dynamic shortcode that allows one to insert a payment link conditional on there being amount owing on the transaction. Three params are available on this shortcode:', |
|
57 | - 'event_espresso') |
|
58 | - . '<ul>' |
|
59 | - . '<li>' |
|
60 | - . sprintf(esc_html__('%sclass:%s This can be used to indicate css class is given to the containing css element (default is "callout").', |
|
61 | - 'event_espresso'), '<strong>', '</strong>') |
|
62 | - . '</li>' |
|
63 | - . '<li>' |
|
64 | - . sprintf(esc_html__('%scustom_text:%s This should be a sprintf format text string (with %%s for where the hyperlink tags go) that is used for the generated link text (The default is "You can %%smake a payment here »%%s.)', |
|
65 | - 'event_espresso'), '<strong>', '</strong>') |
|
66 | - . '</li>' |
|
67 | - . '<li>' |
|
68 | - . sprintf(esc_html__('%scontainer_tag:%s Use this to indicate what container tag you want surrounding the payment link (default is "p").', |
|
69 | - 'event_espresso'), '<strong>', '</strong>') |
|
70 | - . '</li>' |
|
71 | - . '</ul>', |
|
72 | - '[PAYMENT_DUE_DATE_*]' => esc_html__('This is a special dynamic shortcode that allows one to output a payment due date. It will only result in a date shown if there is money owing. Three parameters are available on this shortcode:', |
|
73 | - 'event_espresso') |
|
74 | - . '<ul>' |
|
75 | - . '<li>' |
|
76 | - . sprintf(esc_html__('%sformat:%s This is used to indicate what format the date is in. Default is whatever is set as date formats for your website.', |
|
77 | - 'event_espresso'), '<strong>', '</strong>') |
|
78 | - . '</li>' |
|
79 | - . '<li>' |
|
80 | - . sprintf(esc_html__('%sdays_until_due:%s This is the number of days form the transaction creation date that the payment is due. Defaults to 30.', |
|
81 | - 'event_espresso'), '<strong>', '</strong>') |
|
82 | - . '</li>' |
|
83 | - . '<li>' |
|
84 | - . sprintf(esc_html__('%sprefix_text:%s You can use this to indicate what text will prefix the date string. Defaults to "Payment in full due by:"', |
|
85 | - 'event_espresso'), '<strong>', '</strong>') |
|
86 | - . '</li>', |
|
87 | - '[INVOICE_LINK]' => esc_html__('This is a full html link to the invoice', |
|
88 | - 'event_espresso'), |
|
89 | - '[INVOICE_URL]' => esc_html__('This is just the url for the invoice', 'event_espresso'), |
|
90 | - '[INVOICE_LOGO_URL]' => esc_html__('This returns the url for the logo uploaded via the invoice settings page.', |
|
91 | - 'event_espresso'), |
|
92 | - '[INVOICE_LOGO]' => esc_html__('This returns the logo uploaded via the invoice settings page wrapped in img_tags and with a "logo screen" classes. The image size is also set in the img tags automatically to match the uploaded logo.', |
|
93 | - 'event_espresso'), |
|
94 | - '[INVOICE_PAYEE_NAME]' => esc_html__('This will parse to either: the value of the "Company Name" field in the invoice payment method settings; if that is blank, then the value of the Company Name in the "Your Organization Settings", if that is blank then an empty string.', |
|
95 | - 'event_espresso'), |
|
96 | - '[INVOICE_PAYEE_ADDRESS]' => esc_html__('This will parse to either: the value of the "Company Address" field in the invoice payment method settings; if that is blank, then the value of the Company Address in the "Your Organization Settings", if that is blank then an empty string.', |
|
97 | - 'event_espresso'), |
|
98 | - '[INVOICE_PAYMENT_INSTRUCTIONS]' => esc_html__('This will parse to the value of the "Payment Instructions" field found on the Invoice payment methods settings page', |
|
99 | - 'event_espresso'), |
|
100 | - '[INVOICE_PAYEE_EMAIL]' => esc_html__('This will parse to either: the value of the "Company Email" field in the invoice payment method settings; if that is blank, then the value of the Company Email in the "Your Organization Settings", if that is blank then an empty string.', |
|
101 | - 'event_espresso'), |
|
102 | - '[INVOICE_PAYEE_TAX_NUMBER_*]' => sprintf(esc_html__('This will parse to either: the value of the "Company Tax Number" field in the invoice payment method settings; if that is blank, then the value of the Company Tax Number in the "Your Organization Settings", if that is blank then an empty string. Note this is also a special dynamic shortcode. You can use the "prefix" parameter to indicate what text you want to use as a prefix before this tax number. It defaults to "VAT/Tax Number:". To change this prefix you do the following format for this shortcode: %1$s[INVOICE_PAYEE_TAX_NUMBER_* prefix="GST:"]%2$s and that will output: GST: 12345t56. If you have no tax number in your settings, then no prefix will be output either.', |
|
103 | - 'event_espresso'), '<code>', '</code>'), |
|
104 | - '[TOTAL_COST]' => esc_html__('The total cost for the transaction', 'event_espresso'), |
|
105 | - '[TXN_STATUS]' => esc_html__('The transaction status for the transaction.', |
|
106 | - 'event_espresso'), |
|
107 | - '[TXN_STATUS_ID]' => esc_html__('The ID representing the transaction status as saved in the db. This tends to be useful for including with css classes for styling certain statuses differently from others.', |
|
108 | - 'event_espresso'), |
|
109 | - '[PAYMENT_STATUS]' => esc_html__('The transaction status for the transaction. This parses to the same value as the [TXN_STATUS] shortcode and still remains here for legacy support.', |
|
110 | - 'event_espresso'), |
|
111 | - '[PAYMENT_GATEWAY]' => esc_html__('The payment gateway used for the transaction', |
|
112 | - 'event_espresso'), |
|
113 | - '[AMOUNT_PAID]' => esc_html__('The amount paid or refunded. This will only have a value if there was a payment or refund at the time of generating the message.', |
|
114 | - 'event_espresso'), |
|
115 | - '[LAST_AMOUNT_PAID]' => esc_html__('This is the last payment or refund made on the transaction related to the message being generated.', |
|
116 | - 'event_espresso'), |
|
117 | - '[TOTAL_AMOUNT_PAID]' => esc_html__('This parses to the total amount paid over all payments', |
|
118 | - 'event_espresso'), |
|
119 | - '[TOTAL_OWING]' => esc_html__('The total owing on a transaction with no attributes.', |
|
120 | - 'event_espresso'), |
|
121 | - '[TXN_SUBTOTAL]' => esc_html__('The subtotal for all txn line items.', 'event_espresso'), |
|
122 | - '[TXN_TAX_SUBTOTAL]' => esc_html__('The subtotal for all tax line items.', 'event_espresso'), |
|
123 | - '[OWING_STATUS_MESSAGE_*]' => esc_html__('A dynamic shortcode for adjusting how total owing gets shown. The acceptable attributes on the shortcode are:', |
|
124 | - 'event_espresso') |
|
125 | - . '<p></ul>' |
|
126 | - . |
|
127 | - '<li><strong>still_owing</strong>:' |
|
128 | - . esc_html__('If the transaction is not paid in full, then whatever is set for this attribute is shown (otherwise its just the amount owing). The default is:', |
|
129 | - 'event_espresso') |
|
130 | - . sprintf(esc_html__('%sPlease make a payment.%s', 'event_espresso'), |
|
131 | - '<a href="[PAYMENT_URL]" class="noPrint">', '</a>') |
|
132 | - . '</li>' |
|
133 | - . |
|
134 | - '<li><strong>none_owing</strong>:' |
|
135 | - . esc_html__('If the transaction is paid in full, then you can indicate how this gets displayed. Note, that it defaults to just be the total owing.', |
|
136 | - 'event_espresso') |
|
137 | - . '</li></ul></p>', |
|
138 | - '[TXN_TOTAL_TICKETS]' => esc_html__('The total number of all tickets purchased in a transaction', |
|
139 | - 'event_espresso'), |
|
140 | - '[TKT_QTY_PURCHASED]' => sprintf(esc_html__('The total number of all tickets purchased in a transaction. %1$sNOTE: This shortcode is good to use in the "[TICKET_LIST]" field but has been deprecated from all other contexts in favor of the more explicit [TXN_TOTAL_TICKETS] shortcode.%2$s', |
|
141 | - 'event_espresso'), '<strong>', '</strong>'), |
|
142 | - '[TRANSACTION_ADMIN_URL]' => esc_html__('The url to the admin page for this transaction', |
|
143 | - 'event_espresso'), |
|
144 | - '[RECEIPT_URL]' => esc_html__('This parses to the generated url for retrieving the receipt for the transaction', |
|
145 | - 'event_espresso'), |
|
146 | - '[INVOICE_RECEIPT_SWITCHER_URL]' => esc_html__('This parses to the url that will switch to the receipt if an invoice is displayed, and switch to the invoice if receipt is displayed. If a message type OTHER than invoice or receipt is displayed then this will just return the url for the invoice. If the related message type is not active then will parse to an empty string.', |
|
147 | - 'event_espresso'), |
|
148 | - '[INVOICE_RECEIPT_SWITCHER_BUTTON]' => sprintf(esc_html__('The same as %1$s[INVOICE_RECEIPT_SWITCHER_URL]%2$s except this returns the html for a button linked to the invoice or receipt.', |
|
149 | - 'event_espresso'), '<code>', '</code>'), |
|
150 | - ); |
|
151 | - } |
|
152 | - |
|
153 | - |
|
154 | - |
|
155 | - /** |
|
156 | - * @access protected |
|
157 | - * @param string $shortcode the shortcode to be parsed. |
|
158 | - * @return string parsed shortcode |
|
159 | - */ |
|
160 | - protected function _parser($shortcode) |
|
161 | - { |
|
162 | - //attempt to get the transaction. Since this is potentially used in more fields, we may have to look in the _extra_data for the transaction. |
|
163 | - $transaction = $this->_data->txn instanceof EE_Transaction ? $this->_data->txn : null; |
|
164 | - $transaction = ! $transaction instanceof EE_Transaction |
|
165 | - && is_array($this->_extra_data) |
|
166 | - && isset($this->_extra_data['data']) |
|
167 | - && $this->_extra_data['data'] instanceof EE_Messages_Addressee ? $this->_extra_data['data']->txn |
|
168 | - : $transaction; |
|
169 | - //payment |
|
170 | - $payment = $this->_data->payment instanceof EE_Payment ? $this->_data->payment : null; |
|
171 | - $payment = ! $payment instanceof EE_Payment |
|
172 | - && is_array($this->_extra_data) |
|
173 | - && isset($this->_extra_data['data']) |
|
174 | - && $this->_extra_data['data'] instanceof EE_Messages_Addressee ? $this->_extra_data['data']->payment |
|
175 | - : $payment; |
|
176 | - if (! $transaction instanceof EE_Transaction) { |
|
177 | - return ''; |
|
178 | - } |
|
179 | - switch ($shortcode) { |
|
180 | - case '[TXN_ID]' : |
|
181 | - return $transaction->ID(); |
|
182 | - break; |
|
183 | - case '[PAYMENT_URL]' : |
|
184 | - $payment_url = $transaction->payment_overview_url(); |
|
185 | - return empty($payment_url) ? esc_html__('http://dummypaymenturlforpreview.com', 'event_espresso') |
|
186 | - : $payment_url; |
|
187 | - break; |
|
188 | - case '[INVOICE_LINK]' : |
|
189 | - $invoice_url = $transaction->invoice_url(); |
|
190 | - $invoice_url = empty($invoice_url) ? 'http://dummyinvoicelinksforpreview.com' : $invoice_url; |
|
191 | - return sprintf(esc_html__('%sClick here for Invoice%s', 'event_espresso'), |
|
192 | - '<a href="' . $invoice_url . '">', '</a>'); |
|
193 | - break; /**/ |
|
194 | - case '[INVOICE_URL]' : |
|
195 | - $invoice_url = $transaction->invoice_url(); |
|
196 | - return empty($invoice_url) ? 'http://dummyinvoicelinksforpreview.com' : $invoice_url; |
|
197 | - break; |
|
198 | - case '[INVOICE_LOGO_URL]' : |
|
199 | - return $this->_get_invoice_logo(); |
|
200 | - break; |
|
201 | - case '[INVOICE_LOGO]' : |
|
202 | - return $this->_get_invoice_logo(true); |
|
203 | - break; |
|
204 | - case '[INVOICE_PAYEE_NAME]' : |
|
205 | - return $this->_get_invoice_payee_name(); |
|
206 | - break; |
|
207 | - case '[INVOICE_PAYEE_ADDRESS]' : |
|
208 | - return $this->_get_invoice_payee_address(); |
|
209 | - break; |
|
210 | - case '[INVOICE_PAYMENT_INSTRUCTIONS]' : |
|
211 | - return $this->_get_invoice_payment_instructions(); |
|
212 | - break; |
|
213 | - case '[INVOICE_PAYEE_EMAIL]' : |
|
214 | - return $this->_get_invoice_payee_email(); |
|
215 | - break; |
|
216 | - case '[TOTAL_COST]' : |
|
217 | - $total = $transaction->total(); |
|
218 | - return ! empty($total) ? EEH_Template::format_currency($total) : ''; |
|
219 | - break; |
|
220 | - case '[PAYMENT_STATUS]' : |
|
221 | - $status = $transaction->pretty_status(); |
|
222 | - return ! empty($status) ? $status : esc_html__('Unknown', 'event_espresso'); |
|
223 | - break; /**/ |
|
224 | - // note the [payment_status] shortcode is kind of misleading because payment status might be different from txn status so I'm adding this here for clarity. |
|
225 | - case '[TXN_STATUS]': |
|
226 | - $status = $transaction->pretty_status(); |
|
227 | - return ! empty($status) ? $status : esc_html__('Unknown', 'event_espresso'); |
|
228 | - break; |
|
229 | - case '[TXN_STATUS_ID]' : |
|
230 | - return $transaction->status_ID(); |
|
231 | - break; |
|
232 | - case '[PAYMENT_GATEWAY]' : |
|
233 | - return $this->_get_payment_gateway($transaction); |
|
234 | - break; |
|
235 | - case '[AMOUNT_PAID]' : |
|
236 | - return $payment instanceof EE_Payment |
|
237 | - ? EEH_Template::format_currency($payment->amount()) |
|
238 | - : EEH_Template::format_currency(0); |
|
239 | - break; |
|
240 | - case '[LAST_AMOUNT_PAID]' : |
|
241 | - $last_payment = $transaction->last_payment(); |
|
242 | - return $last_payment instanceof EE_Payment |
|
243 | - ? EEH_Template::format_currency($last_payment->amount()) |
|
244 | - : EEH_Template::format_currency(0); |
|
245 | - case '[TOTAL_AMOUNT_PAID]' : |
|
246 | - return EEH_Template::format_currency($transaction->paid()); |
|
247 | - break; |
|
248 | - case '[TOTAL_OWING]' : |
|
249 | - $total_owing = $transaction->remaining(); |
|
250 | - return EEH_Template::format_currency($total_owing); |
|
251 | - break; |
|
252 | - case '[TXN_SUBTOTAL]' : |
|
253 | - return EEH_Template::format_currency($this->_get_subtotal()); |
|
254 | - break; |
|
255 | - case '[TXN_TAX_SUBTOTAL]' : |
|
256 | - return EEH_Template::format_currency($this->_get_subtotal(true)); |
|
257 | - break; |
|
258 | - case '[TKT_QTY_PURCHASED]' : |
|
259 | - case '[TXN_TOTAL_TICKETS]' : |
|
260 | - return $this->_data->total_ticket_count; |
|
261 | - break; |
|
262 | - case '[TRANSACTION_ADMIN_URL]' : |
|
263 | - require_once EE_CORE . 'admin/EE_Admin_Page.core.php'; |
|
264 | - $query_args = array( |
|
265 | - 'page' => 'espresso_transactions', |
|
266 | - 'action' => 'view_transaction', |
|
267 | - 'TXN_ID' => $transaction->ID(), |
|
268 | - ); |
|
269 | - $url = EE_Admin_Page::add_query_args_and_nonce($query_args, admin_url('admin.php')); |
|
270 | - return $url; |
|
271 | - break; |
|
272 | - case '[RECEIPT_URL]' : |
|
273 | - //get primary_registration |
|
274 | - $reg = $this->_data->primary_reg_obj; |
|
275 | - if (! $reg instanceof EE_Registration) { |
|
276 | - return ''; |
|
277 | - } |
|
278 | - return $reg->receipt_url(); |
|
279 | - break; |
|
280 | - case '[INVOICE_RECEIPT_SWITCHER_URL]' : |
|
281 | - return $this->_get_invoice_receipt_switcher(false); |
|
282 | - break; |
|
283 | - case '[INVOICE_RECEIPT_SWITCHER_BUTTON]' : |
|
284 | - return $this->_get_invoice_receipt_switcher(); |
|
285 | - break; |
|
286 | - } |
|
287 | - if (strpos($shortcode, '[OWING_STATUS_MESSAGE_*') !== false) { |
|
288 | - return $this->_get_custom_total_owing($shortcode); |
|
289 | - } |
|
290 | - if (strpos($shortcode, '[INVOICE_PAYEE_TAX_NUMBER_*') !== false) { |
|
291 | - return $this->_get_invoice_payee_tax_number($shortcode); |
|
292 | - } |
|
293 | - if (strpos($shortcode, '[PAYMENT_LINK_IF_NEEDED_*') !== false) { |
|
294 | - return $this->_get_payment_link_if_needed($shortcode); |
|
295 | - } |
|
296 | - if (strpos($shortcode, '[PAYMENT_DUE_DATE_*') !== false) { |
|
297 | - return $this->_get_payment_due_date($shortcode, $transaction); |
|
298 | - } |
|
299 | - return ''; |
|
300 | - } |
|
301 | - |
|
302 | - |
|
303 | - |
|
304 | - /** |
|
305 | - * parser for the [OWING_STATUS_MESSAGE_*] attribute type shortcode |
|
306 | - * |
|
307 | - * @since 4.5.0 |
|
308 | - * @param string $shortcode the incoming shortcode |
|
309 | - * @return string parsed. |
|
310 | - */ |
|
311 | - private function _get_custom_total_owing($shortcode) |
|
312 | - { |
|
313 | - $valid_shortcodes = array('transaction'); |
|
314 | - $attrs = $this->_get_shortcode_attrs($shortcode); |
|
315 | - //ensure default is set. |
|
316 | - $addressee = $this->_data instanceof EE_Messages_Addressee ? $this->_data : null; |
|
317 | - $total_owing = $addressee instanceof EE_Messages_Addressee && $addressee->txn instanceof EE_Transaction |
|
318 | - ? $addressee->txn->remaining() : 0; |
|
319 | - if ($total_owing > 0) { |
|
320 | - $owing_content = ! empty($attrs['still_owing']) |
|
321 | - ? $attrs['still_owing'] |
|
322 | - : sprintf(esc_html__('%sPlease make a payment.%s', 'event_espresso'), |
|
323 | - '<a href="[PAYMENT_URL]" class="noPrint">', '</a>'); |
|
324 | - $owing_content = $this->_shortcode_helper->parse_message_template($owing_content, $addressee, |
|
325 | - $valid_shortcodes, $this->_message_type, $this->_messenger, $this->_message); |
|
326 | - } else { |
|
327 | - $owing_content = ! empty($attrs['none_owing']) ? $attrs['none_owing'] : ''; |
|
328 | - } |
|
329 | - return $owing_content; |
|
330 | - } |
|
331 | - |
|
332 | - |
|
333 | - |
|
334 | - /** |
|
335 | - * @param EE_Transaction $transaction |
|
336 | - * @return string |
|
337 | - */ |
|
338 | - private function _get_payment_gateway($transaction) |
|
339 | - { |
|
340 | - if($transaction instanceof EE_Transaction){ |
|
341 | - $pm = $transaction->payment_method(); |
|
342 | - } else { |
|
343 | - $pm = null; |
|
344 | - } |
|
345 | - return $pm instanceof EE_Payment_Method ? $pm->name() : ''; |
|
346 | - } |
|
347 | - |
|
348 | - |
|
349 | - |
|
350 | - /** |
|
351 | - * This retrieves a logo to be used for the invoice from whatever is set on the invoice logo settings page. If its |
|
352 | - * not present then the organization logo is used if its found (set on the organization settings page). |
|
353 | - * |
|
354 | - * @since 4.5.0 |
|
355 | - * @param bool $img_tags TRUE means to return with the img tag wrappers. False just returns the url to the image. |
|
356 | - * @return string url or html |
|
357 | - */ |
|
358 | - private function _get_invoice_logo($img_tags = false) |
|
359 | - { |
|
360 | - //try to get the invoice payment method's logo for this transaction image first |
|
361 | - $pm = $this->_get_invoice_payment_method(); |
|
362 | - if ($pm instanceof EE_Payment_Method) { |
|
363 | - $invoice_logo_url = $pm->get_extra_meta('pdf_logo_image', true); |
|
364 | - } else { |
|
365 | - $invoice_logo_url = null; |
|
366 | - } |
|
367 | - if (empty($invoice_logo_url)) { |
|
368 | - $invoice_logo_url = EE_Registry::instance()->CFG->organization->logo_url; |
|
369 | - } |
|
370 | - if (empty($invoice_logo_url)) { |
|
371 | - return ''; |
|
372 | - } |
|
373 | - if (! $img_tags) { |
|
374 | - return $invoice_logo_url; |
|
375 | - } |
|
376 | - //image tags have been requested. |
|
377 | - $image_size = getimagesize($invoice_logo_url); |
|
378 | - //if image is wider than 300px, set the width to 300 |
|
379 | - if ($image_size[0] > 300) { |
|
380 | - $image_width = 300; |
|
381 | - } else { |
|
382 | - $image_width = $image_size[0]; |
|
383 | - } |
|
384 | - return '<img class="logo screen" src="' . $invoice_logo_url . '" width="' . $image_width . '" alt="logo" />'; |
|
385 | - } |
|
386 | - |
|
387 | - |
|
388 | - |
|
389 | - /** |
|
390 | - * Used to retrieve the appropriate content for the invoice payee name shortcode |
|
391 | - * |
|
392 | - * @since 4.5.0 |
|
393 | - * @return string |
|
394 | - */ |
|
395 | - private function _get_invoice_payee_name() |
|
396 | - { |
|
397 | - $payee_name = null; |
|
398 | - $pm = $this->_get_invoice_payment_method(); |
|
399 | - if ($pm instanceof EE_Payment_Method) { |
|
400 | - $payee_name = $pm->get_extra_meta('pdf_payee_name', true); |
|
401 | - } |
|
402 | - $payee_name = empty($payee_name) ? EE_Registry::instance()->CFG->organization->get_pretty('name') : $payee_name; |
|
403 | - return $payee_name; |
|
404 | - } |
|
405 | - |
|
406 | - |
|
407 | - |
|
408 | - /** |
|
409 | - * gets the default invoice payment method, but has a filter so it can be overridden |
|
410 | - * |
|
411 | - * @return \EE_Payment_Method|null |
|
412 | - */ |
|
413 | - private function _get_invoice_payment_method() |
|
414 | - { |
|
415 | - if (! $this->_invoice_pm instanceof EE_Payment_Method) { |
|
416 | - $transaction = $this->_data->txn instanceof EE_Transaction ? $this->_data->txn : null; |
|
417 | - $transaction = ! $transaction instanceof EE_Transaction |
|
418 | - && is_array($this->_extra_data) |
|
419 | - && isset($this->_extra_data['data']) |
|
420 | - && $this->_extra_data['data'] instanceof EE_Messages_Addressee |
|
421 | - ? $this->_extra_data['data']->txn : $transaction; |
|
422 | - //get the invoice payment method, and remember it for the next call too |
|
423 | - $this->_invoice_pm = apply_filters('FHEE__EE_Transaction_Shortcodes__get_payment_method__default', |
|
424 | - EEM_Payment_Method::instance()->get_one_of_type('Invoice'), $transaction); |
|
425 | - } |
|
426 | - return $this->_invoice_pm; |
|
427 | - } |
|
428 | - |
|
429 | - |
|
430 | - |
|
431 | - /** |
|
432 | - * Used to retrieve the appropriate content for the invoice payee email shortcode |
|
433 | - * |
|
434 | - * @since 4.5.0 |
|
435 | - * @return string |
|
436 | - */ |
|
437 | - private function _get_invoice_payee_email() |
|
438 | - { |
|
439 | - $payee_email = null; |
|
440 | - $pm = $this->_get_invoice_payment_method(); |
|
441 | - if ($pm instanceof EE_Payment_Method) { |
|
442 | - $payee_email = $pm->get_extra_meta('pdf_payee_email', true); |
|
443 | - } |
|
444 | - $payee_email = empty($payee_email) ? EE_Registry::instance()->CFG->organization->get_pretty('email') |
|
445 | - : $payee_email; |
|
446 | - return $payee_email; |
|
447 | - } |
|
448 | - |
|
449 | - |
|
450 | - |
|
451 | - /** |
|
452 | - * Used to retrieve the appropriate content for the invoice payee tax number shortcode |
|
453 | - * |
|
454 | - * @since 4.5.0 |
|
455 | - * @param string $shortcode |
|
456 | - * @return string |
|
457 | - */ |
|
458 | - private function _get_invoice_payee_tax_number($shortcode) |
|
459 | - { |
|
460 | - $payee_tax_number = null; |
|
461 | - $pm = $this->_get_invoice_payment_method(); |
|
462 | - if ($pm instanceof EE_Payment_Method) { |
|
463 | - $payee_tax_number = $pm->get_extra_meta('pdf_payee_tax_number', true); |
|
464 | - } |
|
465 | - $payee_tax_number = empty($payee_tax_number) ? EE_Registry::instance()->CFG->organization->vat |
|
466 | - : $payee_tax_number; |
|
467 | - if (empty($payee_tax_number)) { |
|
468 | - return ''; |
|
469 | - } |
|
470 | - //any attributes? |
|
471 | - $attrs = $this->_get_shortcode_attrs($shortcode); |
|
472 | - //prefix? |
|
473 | - $prefix = isset($attrs['prefix']) ? $attrs['prefix'] : esc_html__('VAT/Tax Number: ', 'event_espresso'); |
|
474 | - return $prefix . $payee_tax_number; |
|
475 | - } |
|
476 | - |
|
477 | - |
|
478 | - |
|
479 | - /** |
|
480 | - * Used to retrieve the appropriate content for the invoice payee address shortcode. |
|
481 | - * |
|
482 | - * @since 4.5.0 |
|
483 | - * @return string |
|
484 | - */ |
|
485 | - private function _get_invoice_payee_address() |
|
486 | - { |
|
487 | - $payee_address = null; |
|
488 | - $pm = $this->_get_invoice_payment_method(); |
|
489 | - if ($pm instanceof EE_Payment_Method) { |
|
490 | - $payee_address = $pm->get_extra_meta('pdf_payee_address', true); |
|
491 | - } |
|
492 | - if (empty($payee_address)) { |
|
493 | - $organization = EE_Registry::instance()->CFG->organization; |
|
494 | - $payee_address = $organization->get_pretty('address_1') . '<br>'; |
|
495 | - $payee_address .= ! empty($organization->address_2) ? $organization->get_pretty('address_2') . '<br>' : ''; |
|
496 | - $payee_address .= $organization->get_pretty('city') . '<br>'; |
|
497 | - //state |
|
498 | - $state = EE_Registry::instance()->load_model('State')->get_one_by_ID($organization->STA_ID); |
|
499 | - $payee_address .= $state instanceof EE_State ? $state->name() : ''; |
|
500 | - //Country |
|
501 | - $payee_address .= ! empty($organization->CNT_ISO) ? ', ' . $organization->CNT_ISO . '<br>' : ''; |
|
502 | - $payee_address .= ! empty($organization->zip) ? $organization->zip : ''; |
|
503 | - } |
|
504 | - return $payee_address; |
|
505 | - } |
|
506 | - |
|
507 | - |
|
508 | - |
|
509 | - /** |
|
510 | - * Used to retrieve the appropriate content for the invoice payment instructions shortcode. |
|
511 | - * |
|
512 | - * @since 4.5.0 |
|
513 | - * @return string |
|
514 | - */ |
|
515 | - private function _get_invoice_payment_instructions() |
|
516 | - { |
|
517 | - $instructions = null; |
|
518 | - $pm = $this->_get_invoice_payment_method(); |
|
519 | - return ($pm instanceof EE_Payment_Method) ? $pm->get_extra_meta('pdf_instructions', true) : ''; |
|
520 | - } |
|
521 | - |
|
522 | - |
|
523 | - |
|
524 | - /** |
|
525 | - * get invoice/receipt switch button or url. |
|
526 | - * |
|
527 | - * @param bool $button true (default) returns the html for a button, false just returns the url. |
|
528 | - * @return string |
|
529 | - */ |
|
530 | - protected function _get_invoice_receipt_switcher($button = true) |
|
531 | - { |
|
532 | - $reg = $this->_data->primary_reg_obj; |
|
533 | - $message_type = isset($this->_extra_data['message_type']) ? $this->_extra_data['message_type'] : ''; |
|
534 | - if (! $reg instanceof EE_Registration || empty($message_type)) { |
|
535 | - return ''; |
|
536 | - } |
|
537 | - $switch_to_invoice = ! $message_type instanceof EE_Invoice_message_type ? true : false; |
|
538 | - $switch_to_label = $switch_to_invoice && ! $message_type instanceof EE_Receipt_message_type |
|
539 | - ? esc_html__('View Invoice', 'event_espresso') : esc_html__('Switch to Invoice', 'event_espresso'); |
|
540 | - $switch_to_label = ! $switch_to_invoice ? esc_html__('Switch to Receipt', 'event_espresso') : $switch_to_label; |
|
541 | - $switch_to_url = $switch_to_invoice ? $reg->invoice_url() : $reg->receipt_url(); |
|
542 | - if (! $button) { |
|
543 | - return $switch_to_url; |
|
544 | - } |
|
545 | - if (! empty($switch_to_url)) { |
|
546 | - return ' |
|
31 | + /** |
|
32 | + * @var EE_Payment_Method $_invoice_pm the invoiec payment method for use in invoices etc |
|
33 | + */ |
|
34 | + protected $_invoice_pm; |
|
35 | + |
|
36 | + |
|
37 | + |
|
38 | + /** |
|
39 | + * EE_Transaction_Shortcodes constructor. |
|
40 | + */ |
|
41 | + public function __construct() |
|
42 | + { |
|
43 | + parent::__construct(); |
|
44 | + } |
|
45 | + |
|
46 | + |
|
47 | + |
|
48 | + protected function _init_props() |
|
49 | + { |
|
50 | + $this->label = esc_html__('Transaction Shortcodes', 'event_espresso'); |
|
51 | + $this->description = esc_html__('All shortcodes specific to transaction related data', 'event_espresso'); |
|
52 | + $this->_shortcodes = array( |
|
53 | + '[TXN_ID]' => esc_html__('The transaction id for the purchase.', 'event_espresso'), |
|
54 | + '[PAYMENT_URL]' => esc_html__('This is a link to make a payment for the event', |
|
55 | + 'event_espresso'), |
|
56 | + '[PAYMENT_LINK_IF_NEEDED_*]' => esc_html__('This is a special dynamic shortcode that allows one to insert a payment link conditional on there being amount owing on the transaction. Three params are available on this shortcode:', |
|
57 | + 'event_espresso') |
|
58 | + . '<ul>' |
|
59 | + . '<li>' |
|
60 | + . sprintf(esc_html__('%sclass:%s This can be used to indicate css class is given to the containing css element (default is "callout").', |
|
61 | + 'event_espresso'), '<strong>', '</strong>') |
|
62 | + . '</li>' |
|
63 | + . '<li>' |
|
64 | + . sprintf(esc_html__('%scustom_text:%s This should be a sprintf format text string (with %%s for where the hyperlink tags go) that is used for the generated link text (The default is "You can %%smake a payment here »%%s.)', |
|
65 | + 'event_espresso'), '<strong>', '</strong>') |
|
66 | + . '</li>' |
|
67 | + . '<li>' |
|
68 | + . sprintf(esc_html__('%scontainer_tag:%s Use this to indicate what container tag you want surrounding the payment link (default is "p").', |
|
69 | + 'event_espresso'), '<strong>', '</strong>') |
|
70 | + . '</li>' |
|
71 | + . '</ul>', |
|
72 | + '[PAYMENT_DUE_DATE_*]' => esc_html__('This is a special dynamic shortcode that allows one to output a payment due date. It will only result in a date shown if there is money owing. Three parameters are available on this shortcode:', |
|
73 | + 'event_espresso') |
|
74 | + . '<ul>' |
|
75 | + . '<li>' |
|
76 | + . sprintf(esc_html__('%sformat:%s This is used to indicate what format the date is in. Default is whatever is set as date formats for your website.', |
|
77 | + 'event_espresso'), '<strong>', '</strong>') |
|
78 | + . '</li>' |
|
79 | + . '<li>' |
|
80 | + . sprintf(esc_html__('%sdays_until_due:%s This is the number of days form the transaction creation date that the payment is due. Defaults to 30.', |
|
81 | + 'event_espresso'), '<strong>', '</strong>') |
|
82 | + . '</li>' |
|
83 | + . '<li>' |
|
84 | + . sprintf(esc_html__('%sprefix_text:%s You can use this to indicate what text will prefix the date string. Defaults to "Payment in full due by:"', |
|
85 | + 'event_espresso'), '<strong>', '</strong>') |
|
86 | + . '</li>', |
|
87 | + '[INVOICE_LINK]' => esc_html__('This is a full html link to the invoice', |
|
88 | + 'event_espresso'), |
|
89 | + '[INVOICE_URL]' => esc_html__('This is just the url for the invoice', 'event_espresso'), |
|
90 | + '[INVOICE_LOGO_URL]' => esc_html__('This returns the url for the logo uploaded via the invoice settings page.', |
|
91 | + 'event_espresso'), |
|
92 | + '[INVOICE_LOGO]' => esc_html__('This returns the logo uploaded via the invoice settings page wrapped in img_tags and with a "logo screen" classes. The image size is also set in the img tags automatically to match the uploaded logo.', |
|
93 | + 'event_espresso'), |
|
94 | + '[INVOICE_PAYEE_NAME]' => esc_html__('This will parse to either: the value of the "Company Name" field in the invoice payment method settings; if that is blank, then the value of the Company Name in the "Your Organization Settings", if that is blank then an empty string.', |
|
95 | + 'event_espresso'), |
|
96 | + '[INVOICE_PAYEE_ADDRESS]' => esc_html__('This will parse to either: the value of the "Company Address" field in the invoice payment method settings; if that is blank, then the value of the Company Address in the "Your Organization Settings", if that is blank then an empty string.', |
|
97 | + 'event_espresso'), |
|
98 | + '[INVOICE_PAYMENT_INSTRUCTIONS]' => esc_html__('This will parse to the value of the "Payment Instructions" field found on the Invoice payment methods settings page', |
|
99 | + 'event_espresso'), |
|
100 | + '[INVOICE_PAYEE_EMAIL]' => esc_html__('This will parse to either: the value of the "Company Email" field in the invoice payment method settings; if that is blank, then the value of the Company Email in the "Your Organization Settings", if that is blank then an empty string.', |
|
101 | + 'event_espresso'), |
|
102 | + '[INVOICE_PAYEE_TAX_NUMBER_*]' => sprintf(esc_html__('This will parse to either: the value of the "Company Tax Number" field in the invoice payment method settings; if that is blank, then the value of the Company Tax Number in the "Your Organization Settings", if that is blank then an empty string. Note this is also a special dynamic shortcode. You can use the "prefix" parameter to indicate what text you want to use as a prefix before this tax number. It defaults to "VAT/Tax Number:". To change this prefix you do the following format for this shortcode: %1$s[INVOICE_PAYEE_TAX_NUMBER_* prefix="GST:"]%2$s and that will output: GST: 12345t56. If you have no tax number in your settings, then no prefix will be output either.', |
|
103 | + 'event_espresso'), '<code>', '</code>'), |
|
104 | + '[TOTAL_COST]' => esc_html__('The total cost for the transaction', 'event_espresso'), |
|
105 | + '[TXN_STATUS]' => esc_html__('The transaction status for the transaction.', |
|
106 | + 'event_espresso'), |
|
107 | + '[TXN_STATUS_ID]' => esc_html__('The ID representing the transaction status as saved in the db. This tends to be useful for including with css classes for styling certain statuses differently from others.', |
|
108 | + 'event_espresso'), |
|
109 | + '[PAYMENT_STATUS]' => esc_html__('The transaction status for the transaction. This parses to the same value as the [TXN_STATUS] shortcode and still remains here for legacy support.', |
|
110 | + 'event_espresso'), |
|
111 | + '[PAYMENT_GATEWAY]' => esc_html__('The payment gateway used for the transaction', |
|
112 | + 'event_espresso'), |
|
113 | + '[AMOUNT_PAID]' => esc_html__('The amount paid or refunded. This will only have a value if there was a payment or refund at the time of generating the message.', |
|
114 | + 'event_espresso'), |
|
115 | + '[LAST_AMOUNT_PAID]' => esc_html__('This is the last payment or refund made on the transaction related to the message being generated.', |
|
116 | + 'event_espresso'), |
|
117 | + '[TOTAL_AMOUNT_PAID]' => esc_html__('This parses to the total amount paid over all payments', |
|
118 | + 'event_espresso'), |
|
119 | + '[TOTAL_OWING]' => esc_html__('The total owing on a transaction with no attributes.', |
|
120 | + 'event_espresso'), |
|
121 | + '[TXN_SUBTOTAL]' => esc_html__('The subtotal for all txn line items.', 'event_espresso'), |
|
122 | + '[TXN_TAX_SUBTOTAL]' => esc_html__('The subtotal for all tax line items.', 'event_espresso'), |
|
123 | + '[OWING_STATUS_MESSAGE_*]' => esc_html__('A dynamic shortcode for adjusting how total owing gets shown. The acceptable attributes on the shortcode are:', |
|
124 | + 'event_espresso') |
|
125 | + . '<p></ul>' |
|
126 | + . |
|
127 | + '<li><strong>still_owing</strong>:' |
|
128 | + . esc_html__('If the transaction is not paid in full, then whatever is set for this attribute is shown (otherwise its just the amount owing). The default is:', |
|
129 | + 'event_espresso') |
|
130 | + . sprintf(esc_html__('%sPlease make a payment.%s', 'event_espresso'), |
|
131 | + '<a href="[PAYMENT_URL]" class="noPrint">', '</a>') |
|
132 | + . '</li>' |
|
133 | + . |
|
134 | + '<li><strong>none_owing</strong>:' |
|
135 | + . esc_html__('If the transaction is paid in full, then you can indicate how this gets displayed. Note, that it defaults to just be the total owing.', |
|
136 | + 'event_espresso') |
|
137 | + . '</li></ul></p>', |
|
138 | + '[TXN_TOTAL_TICKETS]' => esc_html__('The total number of all tickets purchased in a transaction', |
|
139 | + 'event_espresso'), |
|
140 | + '[TKT_QTY_PURCHASED]' => sprintf(esc_html__('The total number of all tickets purchased in a transaction. %1$sNOTE: This shortcode is good to use in the "[TICKET_LIST]" field but has been deprecated from all other contexts in favor of the more explicit [TXN_TOTAL_TICKETS] shortcode.%2$s', |
|
141 | + 'event_espresso'), '<strong>', '</strong>'), |
|
142 | + '[TRANSACTION_ADMIN_URL]' => esc_html__('The url to the admin page for this transaction', |
|
143 | + 'event_espresso'), |
|
144 | + '[RECEIPT_URL]' => esc_html__('This parses to the generated url for retrieving the receipt for the transaction', |
|
145 | + 'event_espresso'), |
|
146 | + '[INVOICE_RECEIPT_SWITCHER_URL]' => esc_html__('This parses to the url that will switch to the receipt if an invoice is displayed, and switch to the invoice if receipt is displayed. If a message type OTHER than invoice or receipt is displayed then this will just return the url for the invoice. If the related message type is not active then will parse to an empty string.', |
|
147 | + 'event_espresso'), |
|
148 | + '[INVOICE_RECEIPT_SWITCHER_BUTTON]' => sprintf(esc_html__('The same as %1$s[INVOICE_RECEIPT_SWITCHER_URL]%2$s except this returns the html for a button linked to the invoice or receipt.', |
|
149 | + 'event_espresso'), '<code>', '</code>'), |
|
150 | + ); |
|
151 | + } |
|
152 | + |
|
153 | + |
|
154 | + |
|
155 | + /** |
|
156 | + * @access protected |
|
157 | + * @param string $shortcode the shortcode to be parsed. |
|
158 | + * @return string parsed shortcode |
|
159 | + */ |
|
160 | + protected function _parser($shortcode) |
|
161 | + { |
|
162 | + //attempt to get the transaction. Since this is potentially used in more fields, we may have to look in the _extra_data for the transaction. |
|
163 | + $transaction = $this->_data->txn instanceof EE_Transaction ? $this->_data->txn : null; |
|
164 | + $transaction = ! $transaction instanceof EE_Transaction |
|
165 | + && is_array($this->_extra_data) |
|
166 | + && isset($this->_extra_data['data']) |
|
167 | + && $this->_extra_data['data'] instanceof EE_Messages_Addressee ? $this->_extra_data['data']->txn |
|
168 | + : $transaction; |
|
169 | + //payment |
|
170 | + $payment = $this->_data->payment instanceof EE_Payment ? $this->_data->payment : null; |
|
171 | + $payment = ! $payment instanceof EE_Payment |
|
172 | + && is_array($this->_extra_data) |
|
173 | + && isset($this->_extra_data['data']) |
|
174 | + && $this->_extra_data['data'] instanceof EE_Messages_Addressee ? $this->_extra_data['data']->payment |
|
175 | + : $payment; |
|
176 | + if (! $transaction instanceof EE_Transaction) { |
|
177 | + return ''; |
|
178 | + } |
|
179 | + switch ($shortcode) { |
|
180 | + case '[TXN_ID]' : |
|
181 | + return $transaction->ID(); |
|
182 | + break; |
|
183 | + case '[PAYMENT_URL]' : |
|
184 | + $payment_url = $transaction->payment_overview_url(); |
|
185 | + return empty($payment_url) ? esc_html__('http://dummypaymenturlforpreview.com', 'event_espresso') |
|
186 | + : $payment_url; |
|
187 | + break; |
|
188 | + case '[INVOICE_LINK]' : |
|
189 | + $invoice_url = $transaction->invoice_url(); |
|
190 | + $invoice_url = empty($invoice_url) ? 'http://dummyinvoicelinksforpreview.com' : $invoice_url; |
|
191 | + return sprintf(esc_html__('%sClick here for Invoice%s', 'event_espresso'), |
|
192 | + '<a href="' . $invoice_url . '">', '</a>'); |
|
193 | + break; /**/ |
|
194 | + case '[INVOICE_URL]' : |
|
195 | + $invoice_url = $transaction->invoice_url(); |
|
196 | + return empty($invoice_url) ? 'http://dummyinvoicelinksforpreview.com' : $invoice_url; |
|
197 | + break; |
|
198 | + case '[INVOICE_LOGO_URL]' : |
|
199 | + return $this->_get_invoice_logo(); |
|
200 | + break; |
|
201 | + case '[INVOICE_LOGO]' : |
|
202 | + return $this->_get_invoice_logo(true); |
|
203 | + break; |
|
204 | + case '[INVOICE_PAYEE_NAME]' : |
|
205 | + return $this->_get_invoice_payee_name(); |
|
206 | + break; |
|
207 | + case '[INVOICE_PAYEE_ADDRESS]' : |
|
208 | + return $this->_get_invoice_payee_address(); |
|
209 | + break; |
|
210 | + case '[INVOICE_PAYMENT_INSTRUCTIONS]' : |
|
211 | + return $this->_get_invoice_payment_instructions(); |
|
212 | + break; |
|
213 | + case '[INVOICE_PAYEE_EMAIL]' : |
|
214 | + return $this->_get_invoice_payee_email(); |
|
215 | + break; |
|
216 | + case '[TOTAL_COST]' : |
|
217 | + $total = $transaction->total(); |
|
218 | + return ! empty($total) ? EEH_Template::format_currency($total) : ''; |
|
219 | + break; |
|
220 | + case '[PAYMENT_STATUS]' : |
|
221 | + $status = $transaction->pretty_status(); |
|
222 | + return ! empty($status) ? $status : esc_html__('Unknown', 'event_espresso'); |
|
223 | + break; /**/ |
|
224 | + // note the [payment_status] shortcode is kind of misleading because payment status might be different from txn status so I'm adding this here for clarity. |
|
225 | + case '[TXN_STATUS]': |
|
226 | + $status = $transaction->pretty_status(); |
|
227 | + return ! empty($status) ? $status : esc_html__('Unknown', 'event_espresso'); |
|
228 | + break; |
|
229 | + case '[TXN_STATUS_ID]' : |
|
230 | + return $transaction->status_ID(); |
|
231 | + break; |
|
232 | + case '[PAYMENT_GATEWAY]' : |
|
233 | + return $this->_get_payment_gateway($transaction); |
|
234 | + break; |
|
235 | + case '[AMOUNT_PAID]' : |
|
236 | + return $payment instanceof EE_Payment |
|
237 | + ? EEH_Template::format_currency($payment->amount()) |
|
238 | + : EEH_Template::format_currency(0); |
|
239 | + break; |
|
240 | + case '[LAST_AMOUNT_PAID]' : |
|
241 | + $last_payment = $transaction->last_payment(); |
|
242 | + return $last_payment instanceof EE_Payment |
|
243 | + ? EEH_Template::format_currency($last_payment->amount()) |
|
244 | + : EEH_Template::format_currency(0); |
|
245 | + case '[TOTAL_AMOUNT_PAID]' : |
|
246 | + return EEH_Template::format_currency($transaction->paid()); |
|
247 | + break; |
|
248 | + case '[TOTAL_OWING]' : |
|
249 | + $total_owing = $transaction->remaining(); |
|
250 | + return EEH_Template::format_currency($total_owing); |
|
251 | + break; |
|
252 | + case '[TXN_SUBTOTAL]' : |
|
253 | + return EEH_Template::format_currency($this->_get_subtotal()); |
|
254 | + break; |
|
255 | + case '[TXN_TAX_SUBTOTAL]' : |
|
256 | + return EEH_Template::format_currency($this->_get_subtotal(true)); |
|
257 | + break; |
|
258 | + case '[TKT_QTY_PURCHASED]' : |
|
259 | + case '[TXN_TOTAL_TICKETS]' : |
|
260 | + return $this->_data->total_ticket_count; |
|
261 | + break; |
|
262 | + case '[TRANSACTION_ADMIN_URL]' : |
|
263 | + require_once EE_CORE . 'admin/EE_Admin_Page.core.php'; |
|
264 | + $query_args = array( |
|
265 | + 'page' => 'espresso_transactions', |
|
266 | + 'action' => 'view_transaction', |
|
267 | + 'TXN_ID' => $transaction->ID(), |
|
268 | + ); |
|
269 | + $url = EE_Admin_Page::add_query_args_and_nonce($query_args, admin_url('admin.php')); |
|
270 | + return $url; |
|
271 | + break; |
|
272 | + case '[RECEIPT_URL]' : |
|
273 | + //get primary_registration |
|
274 | + $reg = $this->_data->primary_reg_obj; |
|
275 | + if (! $reg instanceof EE_Registration) { |
|
276 | + return ''; |
|
277 | + } |
|
278 | + return $reg->receipt_url(); |
|
279 | + break; |
|
280 | + case '[INVOICE_RECEIPT_SWITCHER_URL]' : |
|
281 | + return $this->_get_invoice_receipt_switcher(false); |
|
282 | + break; |
|
283 | + case '[INVOICE_RECEIPT_SWITCHER_BUTTON]' : |
|
284 | + return $this->_get_invoice_receipt_switcher(); |
|
285 | + break; |
|
286 | + } |
|
287 | + if (strpos($shortcode, '[OWING_STATUS_MESSAGE_*') !== false) { |
|
288 | + return $this->_get_custom_total_owing($shortcode); |
|
289 | + } |
|
290 | + if (strpos($shortcode, '[INVOICE_PAYEE_TAX_NUMBER_*') !== false) { |
|
291 | + return $this->_get_invoice_payee_tax_number($shortcode); |
|
292 | + } |
|
293 | + if (strpos($shortcode, '[PAYMENT_LINK_IF_NEEDED_*') !== false) { |
|
294 | + return $this->_get_payment_link_if_needed($shortcode); |
|
295 | + } |
|
296 | + if (strpos($shortcode, '[PAYMENT_DUE_DATE_*') !== false) { |
|
297 | + return $this->_get_payment_due_date($shortcode, $transaction); |
|
298 | + } |
|
299 | + return ''; |
|
300 | + } |
|
301 | + |
|
302 | + |
|
303 | + |
|
304 | + /** |
|
305 | + * parser for the [OWING_STATUS_MESSAGE_*] attribute type shortcode |
|
306 | + * |
|
307 | + * @since 4.5.0 |
|
308 | + * @param string $shortcode the incoming shortcode |
|
309 | + * @return string parsed. |
|
310 | + */ |
|
311 | + private function _get_custom_total_owing($shortcode) |
|
312 | + { |
|
313 | + $valid_shortcodes = array('transaction'); |
|
314 | + $attrs = $this->_get_shortcode_attrs($shortcode); |
|
315 | + //ensure default is set. |
|
316 | + $addressee = $this->_data instanceof EE_Messages_Addressee ? $this->_data : null; |
|
317 | + $total_owing = $addressee instanceof EE_Messages_Addressee && $addressee->txn instanceof EE_Transaction |
|
318 | + ? $addressee->txn->remaining() : 0; |
|
319 | + if ($total_owing > 0) { |
|
320 | + $owing_content = ! empty($attrs['still_owing']) |
|
321 | + ? $attrs['still_owing'] |
|
322 | + : sprintf(esc_html__('%sPlease make a payment.%s', 'event_espresso'), |
|
323 | + '<a href="[PAYMENT_URL]" class="noPrint">', '</a>'); |
|
324 | + $owing_content = $this->_shortcode_helper->parse_message_template($owing_content, $addressee, |
|
325 | + $valid_shortcodes, $this->_message_type, $this->_messenger, $this->_message); |
|
326 | + } else { |
|
327 | + $owing_content = ! empty($attrs['none_owing']) ? $attrs['none_owing'] : ''; |
|
328 | + } |
|
329 | + return $owing_content; |
|
330 | + } |
|
331 | + |
|
332 | + |
|
333 | + |
|
334 | + /** |
|
335 | + * @param EE_Transaction $transaction |
|
336 | + * @return string |
|
337 | + */ |
|
338 | + private function _get_payment_gateway($transaction) |
|
339 | + { |
|
340 | + if($transaction instanceof EE_Transaction){ |
|
341 | + $pm = $transaction->payment_method(); |
|
342 | + } else { |
|
343 | + $pm = null; |
|
344 | + } |
|
345 | + return $pm instanceof EE_Payment_Method ? $pm->name() : ''; |
|
346 | + } |
|
347 | + |
|
348 | + |
|
349 | + |
|
350 | + /** |
|
351 | + * This retrieves a logo to be used for the invoice from whatever is set on the invoice logo settings page. If its |
|
352 | + * not present then the organization logo is used if its found (set on the organization settings page). |
|
353 | + * |
|
354 | + * @since 4.5.0 |
|
355 | + * @param bool $img_tags TRUE means to return with the img tag wrappers. False just returns the url to the image. |
|
356 | + * @return string url or html |
|
357 | + */ |
|
358 | + private function _get_invoice_logo($img_tags = false) |
|
359 | + { |
|
360 | + //try to get the invoice payment method's logo for this transaction image first |
|
361 | + $pm = $this->_get_invoice_payment_method(); |
|
362 | + if ($pm instanceof EE_Payment_Method) { |
|
363 | + $invoice_logo_url = $pm->get_extra_meta('pdf_logo_image', true); |
|
364 | + } else { |
|
365 | + $invoice_logo_url = null; |
|
366 | + } |
|
367 | + if (empty($invoice_logo_url)) { |
|
368 | + $invoice_logo_url = EE_Registry::instance()->CFG->organization->logo_url; |
|
369 | + } |
|
370 | + if (empty($invoice_logo_url)) { |
|
371 | + return ''; |
|
372 | + } |
|
373 | + if (! $img_tags) { |
|
374 | + return $invoice_logo_url; |
|
375 | + } |
|
376 | + //image tags have been requested. |
|
377 | + $image_size = getimagesize($invoice_logo_url); |
|
378 | + //if image is wider than 300px, set the width to 300 |
|
379 | + if ($image_size[0] > 300) { |
|
380 | + $image_width = 300; |
|
381 | + } else { |
|
382 | + $image_width = $image_size[0]; |
|
383 | + } |
|
384 | + return '<img class="logo screen" src="' . $invoice_logo_url . '" width="' . $image_width . '" alt="logo" />'; |
|
385 | + } |
|
386 | + |
|
387 | + |
|
388 | + |
|
389 | + /** |
|
390 | + * Used to retrieve the appropriate content for the invoice payee name shortcode |
|
391 | + * |
|
392 | + * @since 4.5.0 |
|
393 | + * @return string |
|
394 | + */ |
|
395 | + private function _get_invoice_payee_name() |
|
396 | + { |
|
397 | + $payee_name = null; |
|
398 | + $pm = $this->_get_invoice_payment_method(); |
|
399 | + if ($pm instanceof EE_Payment_Method) { |
|
400 | + $payee_name = $pm->get_extra_meta('pdf_payee_name', true); |
|
401 | + } |
|
402 | + $payee_name = empty($payee_name) ? EE_Registry::instance()->CFG->organization->get_pretty('name') : $payee_name; |
|
403 | + return $payee_name; |
|
404 | + } |
|
405 | + |
|
406 | + |
|
407 | + |
|
408 | + /** |
|
409 | + * gets the default invoice payment method, but has a filter so it can be overridden |
|
410 | + * |
|
411 | + * @return \EE_Payment_Method|null |
|
412 | + */ |
|
413 | + private function _get_invoice_payment_method() |
|
414 | + { |
|
415 | + if (! $this->_invoice_pm instanceof EE_Payment_Method) { |
|
416 | + $transaction = $this->_data->txn instanceof EE_Transaction ? $this->_data->txn : null; |
|
417 | + $transaction = ! $transaction instanceof EE_Transaction |
|
418 | + && is_array($this->_extra_data) |
|
419 | + && isset($this->_extra_data['data']) |
|
420 | + && $this->_extra_data['data'] instanceof EE_Messages_Addressee |
|
421 | + ? $this->_extra_data['data']->txn : $transaction; |
|
422 | + //get the invoice payment method, and remember it for the next call too |
|
423 | + $this->_invoice_pm = apply_filters('FHEE__EE_Transaction_Shortcodes__get_payment_method__default', |
|
424 | + EEM_Payment_Method::instance()->get_one_of_type('Invoice'), $transaction); |
|
425 | + } |
|
426 | + return $this->_invoice_pm; |
|
427 | + } |
|
428 | + |
|
429 | + |
|
430 | + |
|
431 | + /** |
|
432 | + * Used to retrieve the appropriate content for the invoice payee email shortcode |
|
433 | + * |
|
434 | + * @since 4.5.0 |
|
435 | + * @return string |
|
436 | + */ |
|
437 | + private function _get_invoice_payee_email() |
|
438 | + { |
|
439 | + $payee_email = null; |
|
440 | + $pm = $this->_get_invoice_payment_method(); |
|
441 | + if ($pm instanceof EE_Payment_Method) { |
|
442 | + $payee_email = $pm->get_extra_meta('pdf_payee_email', true); |
|
443 | + } |
|
444 | + $payee_email = empty($payee_email) ? EE_Registry::instance()->CFG->organization->get_pretty('email') |
|
445 | + : $payee_email; |
|
446 | + return $payee_email; |
|
447 | + } |
|
448 | + |
|
449 | + |
|
450 | + |
|
451 | + /** |
|
452 | + * Used to retrieve the appropriate content for the invoice payee tax number shortcode |
|
453 | + * |
|
454 | + * @since 4.5.0 |
|
455 | + * @param string $shortcode |
|
456 | + * @return string |
|
457 | + */ |
|
458 | + private function _get_invoice_payee_tax_number($shortcode) |
|
459 | + { |
|
460 | + $payee_tax_number = null; |
|
461 | + $pm = $this->_get_invoice_payment_method(); |
|
462 | + if ($pm instanceof EE_Payment_Method) { |
|
463 | + $payee_tax_number = $pm->get_extra_meta('pdf_payee_tax_number', true); |
|
464 | + } |
|
465 | + $payee_tax_number = empty($payee_tax_number) ? EE_Registry::instance()->CFG->organization->vat |
|
466 | + : $payee_tax_number; |
|
467 | + if (empty($payee_tax_number)) { |
|
468 | + return ''; |
|
469 | + } |
|
470 | + //any attributes? |
|
471 | + $attrs = $this->_get_shortcode_attrs($shortcode); |
|
472 | + //prefix? |
|
473 | + $prefix = isset($attrs['prefix']) ? $attrs['prefix'] : esc_html__('VAT/Tax Number: ', 'event_espresso'); |
|
474 | + return $prefix . $payee_tax_number; |
|
475 | + } |
|
476 | + |
|
477 | + |
|
478 | + |
|
479 | + /** |
|
480 | + * Used to retrieve the appropriate content for the invoice payee address shortcode. |
|
481 | + * |
|
482 | + * @since 4.5.0 |
|
483 | + * @return string |
|
484 | + */ |
|
485 | + private function _get_invoice_payee_address() |
|
486 | + { |
|
487 | + $payee_address = null; |
|
488 | + $pm = $this->_get_invoice_payment_method(); |
|
489 | + if ($pm instanceof EE_Payment_Method) { |
|
490 | + $payee_address = $pm->get_extra_meta('pdf_payee_address', true); |
|
491 | + } |
|
492 | + if (empty($payee_address)) { |
|
493 | + $organization = EE_Registry::instance()->CFG->organization; |
|
494 | + $payee_address = $organization->get_pretty('address_1') . '<br>'; |
|
495 | + $payee_address .= ! empty($organization->address_2) ? $organization->get_pretty('address_2') . '<br>' : ''; |
|
496 | + $payee_address .= $organization->get_pretty('city') . '<br>'; |
|
497 | + //state |
|
498 | + $state = EE_Registry::instance()->load_model('State')->get_one_by_ID($organization->STA_ID); |
|
499 | + $payee_address .= $state instanceof EE_State ? $state->name() : ''; |
|
500 | + //Country |
|
501 | + $payee_address .= ! empty($organization->CNT_ISO) ? ', ' . $organization->CNT_ISO . '<br>' : ''; |
|
502 | + $payee_address .= ! empty($organization->zip) ? $organization->zip : ''; |
|
503 | + } |
|
504 | + return $payee_address; |
|
505 | + } |
|
506 | + |
|
507 | + |
|
508 | + |
|
509 | + /** |
|
510 | + * Used to retrieve the appropriate content for the invoice payment instructions shortcode. |
|
511 | + * |
|
512 | + * @since 4.5.0 |
|
513 | + * @return string |
|
514 | + */ |
|
515 | + private function _get_invoice_payment_instructions() |
|
516 | + { |
|
517 | + $instructions = null; |
|
518 | + $pm = $this->_get_invoice_payment_method(); |
|
519 | + return ($pm instanceof EE_Payment_Method) ? $pm->get_extra_meta('pdf_instructions', true) : ''; |
|
520 | + } |
|
521 | + |
|
522 | + |
|
523 | + |
|
524 | + /** |
|
525 | + * get invoice/receipt switch button or url. |
|
526 | + * |
|
527 | + * @param bool $button true (default) returns the html for a button, false just returns the url. |
|
528 | + * @return string |
|
529 | + */ |
|
530 | + protected function _get_invoice_receipt_switcher($button = true) |
|
531 | + { |
|
532 | + $reg = $this->_data->primary_reg_obj; |
|
533 | + $message_type = isset($this->_extra_data['message_type']) ? $this->_extra_data['message_type'] : ''; |
|
534 | + if (! $reg instanceof EE_Registration || empty($message_type)) { |
|
535 | + return ''; |
|
536 | + } |
|
537 | + $switch_to_invoice = ! $message_type instanceof EE_Invoice_message_type ? true : false; |
|
538 | + $switch_to_label = $switch_to_invoice && ! $message_type instanceof EE_Receipt_message_type |
|
539 | + ? esc_html__('View Invoice', 'event_espresso') : esc_html__('Switch to Invoice', 'event_espresso'); |
|
540 | + $switch_to_label = ! $switch_to_invoice ? esc_html__('Switch to Receipt', 'event_espresso') : $switch_to_label; |
|
541 | + $switch_to_url = $switch_to_invoice ? $reg->invoice_url() : $reg->receipt_url(); |
|
542 | + if (! $button) { |
|
543 | + return $switch_to_url; |
|
544 | + } |
|
545 | + if (! empty($switch_to_url)) { |
|
546 | + return ' |
|
547 | 547 | <form method="post" action="' . $switch_to_url . '" > |
548 | 548 | <input class="print_button" type="submit" value="' . $switch_to_label . '" /> |
549 | 549 | </form> |
550 | 550 | '; |
551 | - } |
|
552 | - return ''; |
|
553 | - } |
|
554 | - |
|
555 | - |
|
556 | - |
|
557 | - /** |
|
558 | - * This returns a subtotal. |
|
559 | - * |
|
560 | - * @param bool $tax if true then return the subtotal for tax otherwise return subtotal. |
|
561 | - * @return int |
|
562 | - */ |
|
563 | - private function _get_subtotal($tax = false) |
|
564 | - { |
|
565 | - $grand_total = isset($this->_data->grand_total_line_item) ? $this->_data->grand_total_line_item : null; |
|
566 | - if (! $grand_total instanceof EE_Line_Item) { |
|
567 | - return 0; |
|
568 | - } |
|
569 | - return $tax ? $grand_total->get_total_tax() : $grand_total->get_items_total(); |
|
570 | - } |
|
571 | - |
|
572 | - |
|
573 | - |
|
574 | - /** |
|
575 | - * parser for the [PAYMENT_LINK_IF_NEEDED_*] attribute type shortcode |
|
576 | - * |
|
577 | - * @since 4.7.0 |
|
578 | - * @param string $shortcode the incoming shortcode |
|
579 | - * @return string parsed. |
|
580 | - */ |
|
581 | - private function _get_payment_link_if_needed($shortcode) |
|
582 | - { |
|
583 | - $valid_shortcodes = array('transaction'); |
|
584 | - $attrs = $this->_get_shortcode_attrs($shortcode); |
|
585 | - //ensure default is set. |
|
586 | - $addressee = $this->_data instanceof EE_Messages_Addressee ? $this->_data : null; |
|
587 | - $total_owing = $addressee instanceof EE_Messages_Addressee && $addressee->txn instanceof EE_Transaction |
|
588 | - ? $addressee->txn->remaining() : 0; |
|
589 | - if ($total_owing > 0) { |
|
590 | - $class = isset($attrs['class']) ? $attrs['class'] : 'callout'; |
|
591 | - $custom_text = isset($attrs['custom_text']) ? $attrs['custom_text'] : 'You can %smake a payment here »%s.'; |
|
592 | - $container_tag = isset($attrs['container_tag']) ? $attrs['container_tag'] : 'p'; |
|
593 | - $opening_tag = ! empty($container_tag) ? '<' . $container_tag : ''; |
|
594 | - $opening_tag .= ! empty($opening_tag) && ! empty($class) ? ' class="' . $class . '"' : $opening_tag; |
|
595 | - $opening_tag .= ! empty($opening_tag) ? '>' : $opening_tag; |
|
596 | - $closing_tag = ! empty($container_tag) ? '</' . $container_tag . '>' : ''; |
|
597 | - $content = $opening_tag . sprintf($custom_text, '<a href="[PAYMENT_URL]">', '</a>') . $closing_tag; |
|
598 | - //we need to re run this string through the parser to catch any shortcodes that are in it. |
|
599 | - $owing_content = $this->_shortcode_helper->parse_message_template($content, $addressee, $valid_shortcodes, |
|
600 | - $this->_message_type, $this->_messenger, $this->_message); |
|
601 | - } else { |
|
602 | - return ''; |
|
603 | - } |
|
604 | - return $owing_content; |
|
605 | - } |
|
606 | - |
|
607 | - |
|
608 | - |
|
609 | - /** |
|
610 | - * Parser for the [PAYMENT_DUE_DATE_*] attribute type shortcode |
|
611 | - * |
|
612 | - * @since 4.8.28.rc.011 |
|
613 | - * @param string $shortcode The shortcode being parsed. |
|
614 | - * @param EE_Transaction $transaction |
|
615 | - * @return string |
|
616 | - */ |
|
617 | - protected function _get_payment_due_date($shortcode, EE_Transaction $transaction) |
|
618 | - { |
|
619 | - //if transaction is paid in full then we can just return an empty string |
|
620 | - if ($transaction->remaining() === 0) { |
|
621 | - return ''; |
|
622 | - } |
|
623 | - $attrs = $this->_get_shortcode_attrs($shortcode); |
|
624 | - $format = isset($attrs['format']) ? $attrs['format'] : get_option('date_format'); |
|
625 | - $days_until_due = isset($attrs['days_until_due']) ? (int)$attrs['days_until_due'] : 30; |
|
626 | - $prefix_text = isset($attrs['prefix_text']) ? $attrs['prefix_text'] |
|
627 | - : esc_html__('Payment in full due by: ', 'event_espresso'); |
|
628 | - $transaction_created = $transaction->get_DateTime_object('TXN_timestamp'); |
|
629 | - //setup date due: |
|
630 | - try { |
|
631 | - if ($transaction_created instanceof DateTime) { |
|
632 | - $date_due = $transaction_created->add(new DateInterval('P' . $days_until_due . 'D'))->format($format); |
|
633 | - } else { |
|
634 | - throw new Exception(); |
|
635 | - } |
|
636 | - } catch (Exception $e) { |
|
637 | - //format was likely invalid. |
|
638 | - $date_due = 'Unable to calculate date due, likely the format string is invalid.'; |
|
639 | - } |
|
640 | - return $prefix_text . $date_due; |
|
641 | - } |
|
551 | + } |
|
552 | + return ''; |
|
553 | + } |
|
554 | + |
|
555 | + |
|
556 | + |
|
557 | + /** |
|
558 | + * This returns a subtotal. |
|
559 | + * |
|
560 | + * @param bool $tax if true then return the subtotal for tax otherwise return subtotal. |
|
561 | + * @return int |
|
562 | + */ |
|
563 | + private function _get_subtotal($tax = false) |
|
564 | + { |
|
565 | + $grand_total = isset($this->_data->grand_total_line_item) ? $this->_data->grand_total_line_item : null; |
|
566 | + if (! $grand_total instanceof EE_Line_Item) { |
|
567 | + return 0; |
|
568 | + } |
|
569 | + return $tax ? $grand_total->get_total_tax() : $grand_total->get_items_total(); |
|
570 | + } |
|
571 | + |
|
572 | + |
|
573 | + |
|
574 | + /** |
|
575 | + * parser for the [PAYMENT_LINK_IF_NEEDED_*] attribute type shortcode |
|
576 | + * |
|
577 | + * @since 4.7.0 |
|
578 | + * @param string $shortcode the incoming shortcode |
|
579 | + * @return string parsed. |
|
580 | + */ |
|
581 | + private function _get_payment_link_if_needed($shortcode) |
|
582 | + { |
|
583 | + $valid_shortcodes = array('transaction'); |
|
584 | + $attrs = $this->_get_shortcode_attrs($shortcode); |
|
585 | + //ensure default is set. |
|
586 | + $addressee = $this->_data instanceof EE_Messages_Addressee ? $this->_data : null; |
|
587 | + $total_owing = $addressee instanceof EE_Messages_Addressee && $addressee->txn instanceof EE_Transaction |
|
588 | + ? $addressee->txn->remaining() : 0; |
|
589 | + if ($total_owing > 0) { |
|
590 | + $class = isset($attrs['class']) ? $attrs['class'] : 'callout'; |
|
591 | + $custom_text = isset($attrs['custom_text']) ? $attrs['custom_text'] : 'You can %smake a payment here »%s.'; |
|
592 | + $container_tag = isset($attrs['container_tag']) ? $attrs['container_tag'] : 'p'; |
|
593 | + $opening_tag = ! empty($container_tag) ? '<' . $container_tag : ''; |
|
594 | + $opening_tag .= ! empty($opening_tag) && ! empty($class) ? ' class="' . $class . '"' : $opening_tag; |
|
595 | + $opening_tag .= ! empty($opening_tag) ? '>' : $opening_tag; |
|
596 | + $closing_tag = ! empty($container_tag) ? '</' . $container_tag . '>' : ''; |
|
597 | + $content = $opening_tag . sprintf($custom_text, '<a href="[PAYMENT_URL]">', '</a>') . $closing_tag; |
|
598 | + //we need to re run this string through the parser to catch any shortcodes that are in it. |
|
599 | + $owing_content = $this->_shortcode_helper->parse_message_template($content, $addressee, $valid_shortcodes, |
|
600 | + $this->_message_type, $this->_messenger, $this->_message); |
|
601 | + } else { |
|
602 | + return ''; |
|
603 | + } |
|
604 | + return $owing_content; |
|
605 | + } |
|
606 | + |
|
607 | + |
|
608 | + |
|
609 | + /** |
|
610 | + * Parser for the [PAYMENT_DUE_DATE_*] attribute type shortcode |
|
611 | + * |
|
612 | + * @since 4.8.28.rc.011 |
|
613 | + * @param string $shortcode The shortcode being parsed. |
|
614 | + * @param EE_Transaction $transaction |
|
615 | + * @return string |
|
616 | + */ |
|
617 | + protected function _get_payment_due_date($shortcode, EE_Transaction $transaction) |
|
618 | + { |
|
619 | + //if transaction is paid in full then we can just return an empty string |
|
620 | + if ($transaction->remaining() === 0) { |
|
621 | + return ''; |
|
622 | + } |
|
623 | + $attrs = $this->_get_shortcode_attrs($shortcode); |
|
624 | + $format = isset($attrs['format']) ? $attrs['format'] : get_option('date_format'); |
|
625 | + $days_until_due = isset($attrs['days_until_due']) ? (int)$attrs['days_until_due'] : 30; |
|
626 | + $prefix_text = isset($attrs['prefix_text']) ? $attrs['prefix_text'] |
|
627 | + : esc_html__('Payment in full due by: ', 'event_espresso'); |
|
628 | + $transaction_created = $transaction->get_DateTime_object('TXN_timestamp'); |
|
629 | + //setup date due: |
|
630 | + try { |
|
631 | + if ($transaction_created instanceof DateTime) { |
|
632 | + $date_due = $transaction_created->add(new DateInterval('P' . $days_until_due . 'D'))->format($format); |
|
633 | + } else { |
|
634 | + throw new Exception(); |
|
635 | + } |
|
636 | + } catch (Exception $e) { |
|
637 | + //format was likely invalid. |
|
638 | + $date_due = 'Unable to calculate date due, likely the format string is invalid.'; |
|
639 | + } |
|
640 | + return $prefix_text . $date_due; |
|
641 | + } |
|
642 | 642 | |
643 | 643 | } //end EE_Transaction Shortcodes library |
@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php |
2 | -if (! defined('EVENT_ESPRESSO_VERSION')) { |
|
2 | +if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
|
3 | 3 | exit('NO direct script access allowed'); |
4 | 4 | } |
5 | 5 | |
@@ -173,7 +173,7 @@ discard block |
||
173 | 173 | && isset($this->_extra_data['data']) |
174 | 174 | && $this->_extra_data['data'] instanceof EE_Messages_Addressee ? $this->_extra_data['data']->payment |
175 | 175 | : $payment; |
176 | - if (! $transaction instanceof EE_Transaction) { |
|
176 | + if ( ! $transaction instanceof EE_Transaction) { |
|
177 | 177 | return ''; |
178 | 178 | } |
179 | 179 | switch ($shortcode) { |
@@ -189,7 +189,7 @@ discard block |
||
189 | 189 | $invoice_url = $transaction->invoice_url(); |
190 | 190 | $invoice_url = empty($invoice_url) ? 'http://dummyinvoicelinksforpreview.com' : $invoice_url; |
191 | 191 | return sprintf(esc_html__('%sClick here for Invoice%s', 'event_espresso'), |
192 | - '<a href="' . $invoice_url . '">', '</a>'); |
|
192 | + '<a href="'.$invoice_url.'">', '</a>'); |
|
193 | 193 | break; /**/ |
194 | 194 | case '[INVOICE_URL]' : |
195 | 195 | $invoice_url = $transaction->invoice_url(); |
@@ -260,7 +260,7 @@ discard block |
||
260 | 260 | return $this->_data->total_ticket_count; |
261 | 261 | break; |
262 | 262 | case '[TRANSACTION_ADMIN_URL]' : |
263 | - require_once EE_CORE . 'admin/EE_Admin_Page.core.php'; |
|
263 | + require_once EE_CORE.'admin/EE_Admin_Page.core.php'; |
|
264 | 264 | $query_args = array( |
265 | 265 | 'page' => 'espresso_transactions', |
266 | 266 | 'action' => 'view_transaction', |
@@ -272,7 +272,7 @@ discard block |
||
272 | 272 | case '[RECEIPT_URL]' : |
273 | 273 | //get primary_registration |
274 | 274 | $reg = $this->_data->primary_reg_obj; |
275 | - if (! $reg instanceof EE_Registration) { |
|
275 | + if ( ! $reg instanceof EE_Registration) { |
|
276 | 276 | return ''; |
277 | 277 | } |
278 | 278 | return $reg->receipt_url(); |
@@ -337,7 +337,7 @@ discard block |
||
337 | 337 | */ |
338 | 338 | private function _get_payment_gateway($transaction) |
339 | 339 | { |
340 | - if($transaction instanceof EE_Transaction){ |
|
340 | + if ($transaction instanceof EE_Transaction) { |
|
341 | 341 | $pm = $transaction->payment_method(); |
342 | 342 | } else { |
343 | 343 | $pm = null; |
@@ -370,7 +370,7 @@ discard block |
||
370 | 370 | if (empty($invoice_logo_url)) { |
371 | 371 | return ''; |
372 | 372 | } |
373 | - if (! $img_tags) { |
|
373 | + if ( ! $img_tags) { |
|
374 | 374 | return $invoice_logo_url; |
375 | 375 | } |
376 | 376 | //image tags have been requested. |
@@ -381,7 +381,7 @@ discard block |
||
381 | 381 | } else { |
382 | 382 | $image_width = $image_size[0]; |
383 | 383 | } |
384 | - return '<img class="logo screen" src="' . $invoice_logo_url . '" width="' . $image_width . '" alt="logo" />'; |
|
384 | + return '<img class="logo screen" src="'.$invoice_logo_url.'" width="'.$image_width.'" alt="logo" />'; |
|
385 | 385 | } |
386 | 386 | |
387 | 387 | |
@@ -412,7 +412,7 @@ discard block |
||
412 | 412 | */ |
413 | 413 | private function _get_invoice_payment_method() |
414 | 414 | { |
415 | - if (! $this->_invoice_pm instanceof EE_Payment_Method) { |
|
415 | + if ( ! $this->_invoice_pm instanceof EE_Payment_Method) { |
|
416 | 416 | $transaction = $this->_data->txn instanceof EE_Transaction ? $this->_data->txn : null; |
417 | 417 | $transaction = ! $transaction instanceof EE_Transaction |
418 | 418 | && is_array($this->_extra_data) |
@@ -471,7 +471,7 @@ discard block |
||
471 | 471 | $attrs = $this->_get_shortcode_attrs($shortcode); |
472 | 472 | //prefix? |
473 | 473 | $prefix = isset($attrs['prefix']) ? $attrs['prefix'] : esc_html__('VAT/Tax Number: ', 'event_espresso'); |
474 | - return $prefix . $payee_tax_number; |
|
474 | + return $prefix.$payee_tax_number; |
|
475 | 475 | } |
476 | 476 | |
477 | 477 | |
@@ -491,14 +491,14 @@ discard block |
||
491 | 491 | } |
492 | 492 | if (empty($payee_address)) { |
493 | 493 | $organization = EE_Registry::instance()->CFG->organization; |
494 | - $payee_address = $organization->get_pretty('address_1') . '<br>'; |
|
495 | - $payee_address .= ! empty($organization->address_2) ? $organization->get_pretty('address_2') . '<br>' : ''; |
|
496 | - $payee_address .= $organization->get_pretty('city') . '<br>'; |
|
494 | + $payee_address = $organization->get_pretty('address_1').'<br>'; |
|
495 | + $payee_address .= ! empty($organization->address_2) ? $organization->get_pretty('address_2').'<br>' : ''; |
|
496 | + $payee_address .= $organization->get_pretty('city').'<br>'; |
|
497 | 497 | //state |
498 | 498 | $state = EE_Registry::instance()->load_model('State')->get_one_by_ID($organization->STA_ID); |
499 | 499 | $payee_address .= $state instanceof EE_State ? $state->name() : ''; |
500 | 500 | //Country |
501 | - $payee_address .= ! empty($organization->CNT_ISO) ? ', ' . $organization->CNT_ISO . '<br>' : ''; |
|
501 | + $payee_address .= ! empty($organization->CNT_ISO) ? ', '.$organization->CNT_ISO.'<br>' : ''; |
|
502 | 502 | $payee_address .= ! empty($organization->zip) ? $organization->zip : ''; |
503 | 503 | } |
504 | 504 | return $payee_address; |
@@ -531,7 +531,7 @@ discard block |
||
531 | 531 | { |
532 | 532 | $reg = $this->_data->primary_reg_obj; |
533 | 533 | $message_type = isset($this->_extra_data['message_type']) ? $this->_extra_data['message_type'] : ''; |
534 | - if (! $reg instanceof EE_Registration || empty($message_type)) { |
|
534 | + if ( ! $reg instanceof EE_Registration || empty($message_type)) { |
|
535 | 535 | return ''; |
536 | 536 | } |
537 | 537 | $switch_to_invoice = ! $message_type instanceof EE_Invoice_message_type ? true : false; |
@@ -539,13 +539,13 @@ discard block |
||
539 | 539 | ? esc_html__('View Invoice', 'event_espresso') : esc_html__('Switch to Invoice', 'event_espresso'); |
540 | 540 | $switch_to_label = ! $switch_to_invoice ? esc_html__('Switch to Receipt', 'event_espresso') : $switch_to_label; |
541 | 541 | $switch_to_url = $switch_to_invoice ? $reg->invoice_url() : $reg->receipt_url(); |
542 | - if (! $button) { |
|
542 | + if ( ! $button) { |
|
543 | 543 | return $switch_to_url; |
544 | 544 | } |
545 | - if (! empty($switch_to_url)) { |
|
545 | + if ( ! empty($switch_to_url)) { |
|
546 | 546 | return ' |
547 | - <form method="post" action="' . $switch_to_url . '" > |
|
548 | - <input class="print_button" type="submit" value="' . $switch_to_label . '" /> |
|
547 | + <form method="post" action="' . $switch_to_url.'" > |
|
548 | + <input class="print_button" type="submit" value="' . $switch_to_label.'" /> |
|
549 | 549 | </form> |
550 | 550 | '; |
551 | 551 | } |
@@ -563,7 +563,7 @@ discard block |
||
563 | 563 | private function _get_subtotal($tax = false) |
564 | 564 | { |
565 | 565 | $grand_total = isset($this->_data->grand_total_line_item) ? $this->_data->grand_total_line_item : null; |
566 | - if (! $grand_total instanceof EE_Line_Item) { |
|
566 | + if ( ! $grand_total instanceof EE_Line_Item) { |
|
567 | 567 | return 0; |
568 | 568 | } |
569 | 569 | return $tax ? $grand_total->get_total_tax() : $grand_total->get_items_total(); |
@@ -590,11 +590,11 @@ discard block |
||
590 | 590 | $class = isset($attrs['class']) ? $attrs['class'] : 'callout'; |
591 | 591 | $custom_text = isset($attrs['custom_text']) ? $attrs['custom_text'] : 'You can %smake a payment here »%s.'; |
592 | 592 | $container_tag = isset($attrs['container_tag']) ? $attrs['container_tag'] : 'p'; |
593 | - $opening_tag = ! empty($container_tag) ? '<' . $container_tag : ''; |
|
594 | - $opening_tag .= ! empty($opening_tag) && ! empty($class) ? ' class="' . $class . '"' : $opening_tag; |
|
593 | + $opening_tag = ! empty($container_tag) ? '<'.$container_tag : ''; |
|
594 | + $opening_tag .= ! empty($opening_tag) && ! empty($class) ? ' class="'.$class.'"' : $opening_tag; |
|
595 | 595 | $opening_tag .= ! empty($opening_tag) ? '>' : $opening_tag; |
596 | - $closing_tag = ! empty($container_tag) ? '</' . $container_tag . '>' : ''; |
|
597 | - $content = $opening_tag . sprintf($custom_text, '<a href="[PAYMENT_URL]">', '</a>') . $closing_tag; |
|
596 | + $closing_tag = ! empty($container_tag) ? '</'.$container_tag.'>' : ''; |
|
597 | + $content = $opening_tag.sprintf($custom_text, '<a href="[PAYMENT_URL]">', '</a>').$closing_tag; |
|
598 | 598 | //we need to re run this string through the parser to catch any shortcodes that are in it. |
599 | 599 | $owing_content = $this->_shortcode_helper->parse_message_template($content, $addressee, $valid_shortcodes, |
600 | 600 | $this->_message_type, $this->_messenger, $this->_message); |
@@ -622,14 +622,14 @@ discard block |
||
622 | 622 | } |
623 | 623 | $attrs = $this->_get_shortcode_attrs($shortcode); |
624 | 624 | $format = isset($attrs['format']) ? $attrs['format'] : get_option('date_format'); |
625 | - $days_until_due = isset($attrs['days_until_due']) ? (int)$attrs['days_until_due'] : 30; |
|
625 | + $days_until_due = isset($attrs['days_until_due']) ? (int) $attrs['days_until_due'] : 30; |
|
626 | 626 | $prefix_text = isset($attrs['prefix_text']) ? $attrs['prefix_text'] |
627 | 627 | : esc_html__('Payment in full due by: ', 'event_espresso'); |
628 | 628 | $transaction_created = $transaction->get_DateTime_object('TXN_timestamp'); |
629 | 629 | //setup date due: |
630 | 630 | try { |
631 | 631 | if ($transaction_created instanceof DateTime) { |
632 | - $date_due = $transaction_created->add(new DateInterval('P' . $days_until_due . 'D'))->format($format); |
|
632 | + $date_due = $transaction_created->add(new DateInterval('P'.$days_until_due.'D'))->format($format); |
|
633 | 633 | } else { |
634 | 634 | throw new Exception(); |
635 | 635 | } |
@@ -637,7 +637,7 @@ discard block |
||
637 | 637 | //format was likely invalid. |
638 | 638 | $date_due = 'Unable to calculate date due, likely the format string is invalid.'; |
639 | 639 | } |
640 | - return $prefix_text . $date_due; |
|
640 | + return $prefix_text.$date_due; |
|
641 | 641 | } |
642 | 642 | |
643 | 643 | } //end EE_Transaction Shortcodes library |
@@ -1,5 +1,5 @@ discard block |
||
1 | -<?php if ( ! defined( 'EVENT_ESPRESSO_VERSION' ) ) { |
|
2 | - exit( 'No direct script access allowed' ); |
|
1 | +<?php if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
|
2 | + exit('No direct script access allowed'); |
|
3 | 3 | } |
4 | 4 | /** |
5 | 5 | * |
@@ -37,33 +37,33 @@ discard block |
||
37 | 37 | * @access protected |
38 | 38 | * @return EEM_Payment_Method |
39 | 39 | */ |
40 | - protected function __construct( $timezone = NULL ) { |
|
41 | - $this->singlular_item = __( 'Payment Method', 'event_espresso' ); |
|
42 | - $this->plural_item = __( 'Payment Methods', 'event_espresso' ); |
|
43 | - $this->_tables = array( 'Payment_Method' => new EE_Primary_Table( 'esp_payment_method', 'PMD_ID' ) ); |
|
40 | + protected function __construct($timezone = NULL) { |
|
41 | + $this->singlular_item = __('Payment Method', 'event_espresso'); |
|
42 | + $this->plural_item = __('Payment Methods', 'event_espresso'); |
|
43 | + $this->_tables = array('Payment_Method' => new EE_Primary_Table('esp_payment_method', 'PMD_ID')); |
|
44 | 44 | $this->_fields = array( |
45 | 45 | 'Payment_Method' => array( |
46 | - 'PMD_ID' => new EE_Primary_Key_Int_Field( 'PMD_ID', __( "ID", 'event_espresso' ) ), |
|
47 | - 'PMD_type' => new EE_Plain_Text_Field( 'PMD_type', __( "Payment Method Type", 'event_espresso' ), FALSE, 'Admin_Only' ), |
|
48 | - 'PMD_name' => new EE_Plain_Text_Field( 'PMD_name', __( "Name", 'event_espresso' ), FALSE ), |
|
49 | - 'PMD_desc' => new EE_Post_Content_Field( 'PMD_desc', __( "Description", 'event_espresso' ), FALSE, '' ), |
|
50 | - 'PMD_admin_name' => new EE_Plain_Text_Field( 'PMD_admin_name', __( "Admin-Only Name", 'event_espresso' ), TRUE ), |
|
51 | - 'PMD_admin_desc' => new EE_Post_Content_Field( 'PMD_admin_desc', __( "Admin-Only Description", 'event_espresso' ), TRUE ), |
|
52 | - 'PMD_slug' => new EE_Slug_Field( 'PMD_slug', __( "Slug", 'event_espresso' ), FALSE ), |
|
53 | - 'PMD_order' => new EE_Integer_Field( 'PMD_order', __( "Order", 'event_espresso' ), FALSE, 0 ), |
|
54 | - 'PMD_debug_mode' => new EE_Boolean_Field( 'PMD_debug_mode', __( "Debug Mode On?", 'event_espresso' ), FALSE, FALSE ), |
|
55 | - 'PMD_wp_user' => new EE_WP_User_Field( 'PMD_wp_user', __( "Payment Method Creator ID", 'event_espresso' ), FALSE ), |
|
56 | - 'PMD_open_by_default' => new EE_Boolean_Field( 'PMD_open_by_default', __( "Open by Default?", 'event_espresso' ), FALSE, FALSE ), 'PMD_button_url' => new EE_Plain_Text_Field( 'PMD_button_url', __( "Button URL", 'event_espresso' ), TRUE, '' ), |
|
57 | - 'PMD_scope' => new EE_Serialized_Text_Field( 'PMD_scope', __( "Usable From?", 'event_espresso' ), FALSE, array() ), //possible values currently are 'CART','ADMIN','API' |
|
46 | + 'PMD_ID' => new EE_Primary_Key_Int_Field('PMD_ID', __("ID", 'event_espresso')), |
|
47 | + 'PMD_type' => new EE_Plain_Text_Field('PMD_type', __("Payment Method Type", 'event_espresso'), FALSE, 'Admin_Only'), |
|
48 | + 'PMD_name' => new EE_Plain_Text_Field('PMD_name', __("Name", 'event_espresso'), FALSE), |
|
49 | + 'PMD_desc' => new EE_Post_Content_Field('PMD_desc', __("Description", 'event_espresso'), FALSE, ''), |
|
50 | + 'PMD_admin_name' => new EE_Plain_Text_Field('PMD_admin_name', __("Admin-Only Name", 'event_espresso'), TRUE), |
|
51 | + 'PMD_admin_desc' => new EE_Post_Content_Field('PMD_admin_desc', __("Admin-Only Description", 'event_espresso'), TRUE), |
|
52 | + 'PMD_slug' => new EE_Slug_Field('PMD_slug', __("Slug", 'event_espresso'), FALSE), |
|
53 | + 'PMD_order' => new EE_Integer_Field('PMD_order', __("Order", 'event_espresso'), FALSE, 0), |
|
54 | + 'PMD_debug_mode' => new EE_Boolean_Field('PMD_debug_mode', __("Debug Mode On?", 'event_espresso'), FALSE, FALSE), |
|
55 | + 'PMD_wp_user' => new EE_WP_User_Field('PMD_wp_user', __("Payment Method Creator ID", 'event_espresso'), FALSE), |
|
56 | + 'PMD_open_by_default' => new EE_Boolean_Field('PMD_open_by_default', __("Open by Default?", 'event_espresso'), FALSE, FALSE), 'PMD_button_url' => new EE_Plain_Text_Field('PMD_button_url', __("Button URL", 'event_espresso'), TRUE, ''), |
|
57 | + 'PMD_scope' => new EE_Serialized_Text_Field('PMD_scope', __("Usable From?", 'event_espresso'), FALSE, array()), //possible values currently are 'CART','ADMIN','API' |
|
58 | 58 | ) ); |
59 | 59 | $this->_model_relations = array( |
60 | 60 | // 'Event'=>new EE_HABTM_Relation('Event_Payment_Method'), |
61 | 61 | 'Payment' => new EE_Has_Many_Relation(), |
62 | - 'Currency' => new EE_HABTM_Relation( 'Currency_Payment_Method' ), |
|
62 | + 'Currency' => new EE_HABTM_Relation('Currency_Payment_Method'), |
|
63 | 63 | 'Transaction' => new EE_Has_Many_Relation(), |
64 | 64 | 'WP_User' => new EE_Belongs_To_Relation(), |
65 | 65 | ); |
66 | - parent::__construct( $timezone ); |
|
66 | + parent::__construct($timezone); |
|
67 | 67 | } |
68 | 68 | |
69 | 69 | |
@@ -73,8 +73,8 @@ discard block |
||
73 | 73 | * @param string $slug |
74 | 74 | * @return EE_Payment_Method |
75 | 75 | */ |
76 | - public function get_one_by_slug( $slug ) { |
|
77 | - return $this->get_one( array( array( 'PMD_slug' => $slug ) ) ); |
|
76 | + public function get_one_by_slug($slug) { |
|
77 | + return $this->get_one(array(array('PMD_slug' => $slug))); |
|
78 | 78 | } |
79 | 79 | |
80 | 80 | |
@@ -88,8 +88,8 @@ discard block |
||
88 | 88 | return apply_filters( |
89 | 89 | 'FHEE__EEM_Payment_Method__scopes', |
90 | 90 | array( |
91 | - self::scope_cart => __( "Front-end Registration Page", 'event_espresso' ), |
|
92 | - self::scope_admin => __( "Admin Registration Page (no online processing)", 'event_espresso' ) |
|
91 | + self::scope_cart => __("Front-end Registration Page", 'event_espresso'), |
|
92 | + self::scope_admin => __("Admin Registration Page (no online processing)", 'event_espresso') |
|
93 | 93 | ) |
94 | 94 | ); |
95 | 95 | } |
@@ -101,9 +101,9 @@ discard block |
||
101 | 101 | * @param string $scope like one of EEM_Payment_Method::instance()->scopes() |
102 | 102 | * @return boolean |
103 | 103 | */ |
104 | - public function is_valid_scope( $scope ) { |
|
104 | + public function is_valid_scope($scope) { |
|
105 | 105 | $scopes = $this->scopes(); |
106 | - if ( isset( $scopes[ $scope ] ) ) { |
|
106 | + if (isset($scopes[$scope])) { |
|
107 | 107 | return TRUE; |
108 | 108 | } else { |
109 | 109 | return FALSE; |
@@ -119,11 +119,11 @@ discard block |
||
119 | 119 | * @throws EE_Error |
120 | 120 | * @return EE_Payment_Method[] |
121 | 121 | */ |
122 | - public function get_all_active( $scope = NULL, $query_params = array() ) { |
|
123 | - if( ! isset( $query_params[ 'order_by' ] ) && ! isset( $query_params[ 'order' ] ) ) { |
|
124 | - $query_params['order_by'] = array( 'PMD_order' => 'ASC', 'PMD_ID' => 'ASC' ); |
|
122 | + public function get_all_active($scope = NULL, $query_params = array()) { |
|
123 | + if ( ! isset($query_params['order_by']) && ! isset($query_params['order'])) { |
|
124 | + $query_params['order_by'] = array('PMD_order' => 'ASC', 'PMD_ID' => 'ASC'); |
|
125 | 125 | } |
126 | - return $this->get_all( $this->_get_query_params_for_all_active( $scope, $query_params ) ); |
|
126 | + return $this->get_all($this->_get_query_params_for_all_active($scope, $query_params)); |
|
127 | 127 | } |
128 | 128 | |
129 | 129 | /** |
@@ -132,8 +132,8 @@ discard block |
||
132 | 132 | * @param array $query_params |
133 | 133 | * @return int |
134 | 134 | */ |
135 | - public function count_active( $scope = NULL, $query_params = array() ){ |
|
136 | - return $this->count( $this->_get_query_params_for_all_active( $scope, $query_params ) ); |
|
135 | + public function count_active($scope = NULL, $query_params = array()) { |
|
136 | + return $this->count($this->_get_query_params_for_all_active($scope, $query_params)); |
|
137 | 137 | } |
138 | 138 | |
139 | 139 | /** |
@@ -144,21 +144,21 @@ discard block |
||
144 | 144 | * @return array like param of EEM_Base::get_all() |
145 | 145 | * @throws EE_Error |
146 | 146 | */ |
147 | - protected function _get_query_params_for_all_active( $scope = NULL, $query_params = array() ){ |
|
148 | - if ( $scope ) { |
|
149 | - if ( $this->is_valid_scope( $scope ) ) { |
|
150 | - return array_replace_recursive( array( array( 'PMD_scope' => array( 'LIKE', "%$scope%" ) ) ), $query_params ); |
|
147 | + protected function _get_query_params_for_all_active($scope = NULL, $query_params = array()) { |
|
148 | + if ($scope) { |
|
149 | + if ($this->is_valid_scope($scope)) { |
|
150 | + return array_replace_recursive(array(array('PMD_scope' => array('LIKE', "%$scope%"))), $query_params); |
|
151 | 151 | } else { |
152 | - throw new EE_Error( sprintf( __( "'%s' is not a valid scope for a payment method", "event_espresso" ), $scope ) ); |
|
152 | + throw new EE_Error(sprintf(__("'%s' is not a valid scope for a payment method", "event_espresso"), $scope)); |
|
153 | 153 | } |
154 | 154 | } else { |
155 | 155 | $acceptable_scopes = array(); |
156 | 156 | $count = 0; |
157 | - foreach ( $this->scopes() as $scope_name => $desc ) { |
|
157 | + foreach ($this->scopes() as $scope_name => $desc) { |
|
158 | 158 | $count++; |
159 | - $acceptable_scopes[ 'PMD_scope*' . $count ] = array( 'LIKE', '%' . $scope_name . '%' ); |
|
159 | + $acceptable_scopes['PMD_scope*'.$count] = array('LIKE', '%'.$scope_name.'%'); |
|
160 | 160 | } |
161 | - return array_replace_recursive( array( array( 'OR*active_scope' => $acceptable_scopes ) ), $query_params ); |
|
161 | + return array_replace_recursive(array(array('OR*active_scope' => $acceptable_scopes)), $query_params); |
|
162 | 162 | } |
163 | 163 | } |
164 | 164 | |
@@ -170,8 +170,8 @@ discard block |
||
170 | 170 | * @return array like param of EEM_Base::get_all() |
171 | 171 | * @throws EE_Error |
172 | 172 | */ |
173 | - public function get_query_params_for_all_active( $scope = NULL, $query_params = array() ) { |
|
174 | - return $this->_get_query_params_for_all_active( $scope, $query_params ); |
|
173 | + public function get_query_params_for_all_active($scope = NULL, $query_params = array()) { |
|
174 | + return $this->_get_query_params_for_all_active($scope, $query_params); |
|
175 | 175 | } |
176 | 176 | |
177 | 177 | |
@@ -181,8 +181,8 @@ discard block |
||
181 | 181 | * @param array $query_params |
182 | 182 | * @return EE_Payment_Method |
183 | 183 | */ |
184 | - public function get_one_active( $scope = NULL, $query_params = array() ) { |
|
185 | - return $this->get_one( $this->_get_query_params_for_all_active( $scope, $query_params ) ); |
|
184 | + public function get_one_active($scope = NULL, $query_params = array()) { |
|
185 | + return $this->get_one($this->_get_query_params_for_all_active($scope, $query_params)); |
|
186 | 186 | } |
187 | 187 | |
188 | 188 | |
@@ -192,8 +192,8 @@ discard block |
||
192 | 192 | * @param string $type |
193 | 193 | * @return EE_Payment_Method |
194 | 194 | */ |
195 | - public function get_one_of_type( $type ) { |
|
196 | - return $this->get_one( array( array( 'PMD_type' => $type ) ) ); |
|
195 | + public function get_one_of_type($type) { |
|
196 | + return $this->get_one(array(array('PMD_type' => $type))); |
|
197 | 197 | } |
198 | 198 | |
199 | 199 | |
@@ -206,22 +206,22 @@ discard block |
||
206 | 206 | * @return EE_Payment_Method |
207 | 207 | * @throws EE_Error |
208 | 208 | */ |
209 | - public function ensure_is_obj( $base_class_obj_or_id, $ensure_is_in_db = FALSE ) { |
|
209 | + public function ensure_is_obj($base_class_obj_or_id, $ensure_is_in_db = FALSE) { |
|
210 | 210 | //first: check if it's a slug |
211 | - if( is_string( $base_class_obj_or_id ) ) { |
|
212 | - $obj = $this->get_one_by_slug( $base_class_obj_or_id ); |
|
213 | - if( $obj ) { |
|
211 | + if (is_string($base_class_obj_or_id)) { |
|
212 | + $obj = $this->get_one_by_slug($base_class_obj_or_id); |
|
213 | + if ($obj) { |
|
214 | 214 | return $obj; |
215 | 215 | } |
216 | 216 | } |
217 | 217 | //ok so it wasn't a slug we were passed. try the usual then (ie, it's an object or an ID) |
218 | 218 | try { |
219 | - return parent::ensure_is_obj( $base_class_obj_or_id, $ensure_is_in_db ); |
|
219 | + return parent::ensure_is_obj($base_class_obj_or_id, $ensure_is_in_db); |
|
220 | 220 | } |
221 | - catch ( EE_Error $e ) { |
|
221 | + catch (EE_Error $e) { |
|
222 | 222 | //handle it outside the catch |
223 | 223 | } |
224 | - throw new EE_Error( sprintf( __( "'%s' is neither a Payment Method ID, slug, nor object.", "event_espresso" ), $base_class_obj_or_id ) ); |
|
224 | + throw new EE_Error(sprintf(__("'%s' is neither a Payment Method ID, slug, nor object.", "event_espresso"), $base_class_obj_or_id)); |
|
225 | 225 | } |
226 | 226 | |
227 | 227 | |
@@ -232,12 +232,12 @@ discard block |
||
232 | 232 | * @param mixed $base_obj_or_id_or_slug |
233 | 233 | * @return int |
234 | 234 | */ |
235 | - function ensure_is_ID( $base_obj_or_id_or_slug ) { |
|
236 | - if ( is_string( $base_obj_or_id_or_slug ) ) { |
|
235 | + function ensure_is_ID($base_obj_or_id_or_slug) { |
|
236 | + if (is_string($base_obj_or_id_or_slug)) { |
|
237 | 237 | //assume it's a slug |
238 | - $base_obj_or_id_or_slug = $this->get_one_by_slug( $base_obj_or_id_or_slug ); |
|
238 | + $base_obj_or_id_or_slug = $this->get_one_by_slug($base_obj_or_id_or_slug); |
|
239 | 239 | } |
240 | - return parent::ensure_is_ID( $base_obj_or_id_or_slug ); |
|
240 | + return parent::ensure_is_ID($base_obj_or_id_or_slug); |
|
241 | 241 | } |
242 | 242 | |
243 | 243 | |
@@ -246,36 +246,36 @@ discard block |
||
246 | 246 | * Verifies the button urls on all the passed payment methods have a valid button url. If not, resets them to their default. |
247 | 247 | * @param EE_Payment_Method[] $payment_methods. If NULL is provided defaults to all payment methods active in the cart |
248 | 248 | */ |
249 | - function verify_button_urls( $payment_methods = NULL ) { |
|
250 | - $payment_methods = is_array( $payment_methods ) ? $payment_methods : $this->get_all_active(EEM_Payment_Method::scope_cart); |
|
251 | - foreach ( $payment_methods as $payment_method ) { |
|
249 | + function verify_button_urls($payment_methods = NULL) { |
|
250 | + $payment_methods = is_array($payment_methods) ? $payment_methods : $this->get_all_active(EEM_Payment_Method::scope_cart); |
|
251 | + foreach ($payment_methods as $payment_method) { |
|
252 | 252 | try { |
253 | 253 | $current_button_url = $payment_method->button_url(); |
254 | - $buttons_urls_to_try = apply_filters( 'FHEE__EEM_Payment_Method__verify_button_urls__button_urls_to_try', array( |
|
255 | - 'current_ssl' => str_replace( "http://", "https://", $current_button_url ), |
|
256 | - 'current' => str_replace( "https://", "http://", $current_button_url ), |
|
257 | - 'default_ssl' => str_replace( "http://", "https://", $payment_method->type_obj()->default_button_url() ), |
|
258 | - 'default' => str_replace( "https://", "http://", $payment_method->type_obj()->default_button_url() ), |
|
259 | - ) ); |
|
260 | - foreach( $buttons_urls_to_try as $button_url_to_try ) { |
|
261 | - if( |
|
254 | + $buttons_urls_to_try = apply_filters('FHEE__EEM_Payment_Method__verify_button_urls__button_urls_to_try', array( |
|
255 | + 'current_ssl' => str_replace("http://", "https://", $current_button_url), |
|
256 | + 'current' => str_replace("https://", "http://", $current_button_url), |
|
257 | + 'default_ssl' => str_replace("http://", "https://", $payment_method->type_obj()->default_button_url()), |
|
258 | + 'default' => str_replace("https://", "http://", $payment_method->type_obj()->default_button_url()), |
|
259 | + )); |
|
260 | + foreach ($buttons_urls_to_try as $button_url_to_try) { |
|
261 | + if ( |
|
262 | 262 | (//this is the current url and it exists, regardless of SSL issues |
263 | 263 | $button_url_to_try == $current_button_url && |
264 | 264 | EEH_URL::remote_file_exists( |
265 | 265 | $button_url_to_try, |
266 | 266 | array( |
267 | 267 | 'sslverify' => false, |
268 | - 'limit_response_size' => 4095,//we don't really care for a full response, but we do want headers at least. Lets just ask for a one block |
|
268 | + 'limit_response_size' => 4095, //we don't really care for a full response, but we do want headers at least. Lets just ask for a one block |
|
269 | 269 | ) ) |
270 | 270 | ) |
271 | 271 | || |
272 | 272 | (//this is NOT the current url and it exists with a working SSL cert |
273 | 273 | $button_url_to_try != $current_button_url && |
274 | - EEH_URL::remote_file_exists( $button_url_to_try ) |
|
274 | + EEH_URL::remote_file_exists($button_url_to_try) |
|
275 | 275 | ) ) { |
276 | - if( $current_button_url != $button_url_to_try ){ |
|
277 | - $payment_method->save( array( 'PMD_button_url' => $button_url_to_try ) ); |
|
278 | - EE_Error::add_attention( sprintf( __( "Payment Method %s's button url was set to %s, because the old image either didnt exist or SSL was recently enabled.", "event_espresso" ), $payment_method->name(), $button_url_to_try ) ); |
|
276 | + if ($current_button_url != $button_url_to_try) { |
|
277 | + $payment_method->save(array('PMD_button_url' => $button_url_to_try)); |
|
278 | + EE_Error::add_attention(sprintf(__("Payment Method %s's button url was set to %s, because the old image either didnt exist or SSL was recently enabled.", "event_espresso"), $payment_method->name(), $button_url_to_try)); |
|
279 | 279 | } |
280 | 280 | //this image exists. So if wasn't set before, now it is; |
281 | 281 | //or if it was already set, we have nothing to do |
@@ -283,8 +283,8 @@ discard block |
||
283 | 283 | } |
284 | 284 | } |
285 | 285 | } |
286 | - catch ( EE_Error $e ) { |
|
287 | - $payment_method->set_active( FALSE ); |
|
286 | + catch (EE_Error $e) { |
|
287 | + $payment_method->set_active(FALSE); |
|
288 | 288 | } |
289 | 289 | } |
290 | 290 | } |
@@ -298,29 +298,29 @@ discard block |
||
298 | 298 | * @param array $rows |
299 | 299 | * @return EE_Payment_Method[] |
300 | 300 | */ |
301 | - protected function _create_objects( $rows = array() ) { |
|
302 | - EE_Registry::instance()->load_lib( 'Payment_Method_Manager' ); |
|
303 | - $payment_methods = parent::_create_objects( $rows ); |
|
301 | + protected function _create_objects($rows = array()) { |
|
302 | + EE_Registry::instance()->load_lib('Payment_Method_Manager'); |
|
303 | + $payment_methods = parent::_create_objects($rows); |
|
304 | 304 | /* @var $payment_methods EE_Payment_Method[] */ |
305 | 305 | $usable_payment_methods = array(); |
306 | - foreach ( $payment_methods as $key => $payment_method ) { |
|
307 | - if ( EE_Payment_Method_Manager::instance()->payment_method_type_exists( $payment_method->type() ) ) { |
|
308 | - $usable_payment_methods[ $key ] = $payment_method; |
|
306 | + foreach ($payment_methods as $key => $payment_method) { |
|
307 | + if (EE_Payment_Method_Manager::instance()->payment_method_type_exists($payment_method->type())) { |
|
308 | + $usable_payment_methods[$key] = $payment_method; |
|
309 | 309 | //some payment methods enqueue their scripts in EE_PMT_*::__construct |
310 | 310 | //which is kinda a no-no (just because it's being constructed doesn't mean we need to enqueue |
311 | 311 | //its scripts). but for backwards-compat we should continue to do that |
312 | 312 | $payment_method->type_obj(); |
313 | - } elseif( $payment_method->active() ) { |
|
313 | + } elseif ($payment_method->active()) { |
|
314 | 314 | //only deactivate and notify the admin if the payment is active somewhere |
315 | 315 | $payment_method->deactivate(); |
316 | 316 | $payment_method->save(); |
317 | 317 | EE_Error::add_persistent_admin_notice( |
318 | - 'auto-deactivated-' . $payment_method->type(), |
|
318 | + 'auto-deactivated-'.$payment_method->type(), |
|
319 | 319 | sprintf( |
320 | - __( 'The payment method %1$s was automatically deactivated because it appears its associated Event Espresso Addon was recently deactivated.%2$sIt can be reactivated on the %3$sPlugins admin page%4$s, then you can reactivate the payment method.', 'event_espresso' ), |
|
320 | + __('The payment method %1$s was automatically deactivated because it appears its associated Event Espresso Addon was recently deactivated.%2$sIt can be reactivated on the %3$sPlugins admin page%4$s, then you can reactivate the payment method.', 'event_espresso'), |
|
321 | 321 | $payment_method->admin_name(), |
322 | 322 | '<br />', |
323 | - '<a href="' . admin_url('plugins.php') . '">', |
|
323 | + '<a href="'.admin_url('plugins.php').'">', |
|
324 | 324 | '</a>' |
325 | 325 | ), |
326 | 326 | true |
@@ -340,11 +340,11 @@ discard block |
||
340 | 340 | * @param string $scope @see EEM_Payment_Method::get_all_for_events |
341 | 341 | * @return EE_Payment_Method[] |
342 | 342 | */ |
343 | - public function get_all_for_transaction( $transaction, $scope ) { |
|
343 | + public function get_all_for_transaction($transaction, $scope) { |
|
344 | 344 | //give addons a chance to override what payment methods are chosen based on the transaction |
345 | 345 | return apply_filters( |
346 | 346 | 'FHEE__EEM_Payment_Method__get_all_for_transaction__payment_methods', |
347 | - $this->get_all_active( $scope, array( 'group_by' => 'PMD_type' ) ), |
|
347 | + $this->get_all_active($scope, array('group_by' => 'PMD_type')), |
|
348 | 348 | $transaction, |
349 | 349 | $scope |
350 | 350 | ); |
@@ -360,16 +360,16 @@ discard block |
||
360 | 360 | * @param EE_Registration|int $registration_or_reg_id Either the EE_Registration object or the id for the registration. |
361 | 361 | * @return EE_Payment|null |
362 | 362 | */ |
363 | - public function get_last_used_for_registration( $registration_or_reg_id ) { |
|
364 | - $registration_id = EEM_Registration::instance()->ensure_is_ID( $registration_or_reg_id ); |
|
363 | + public function get_last_used_for_registration($registration_or_reg_id) { |
|
364 | + $registration_id = EEM_Registration::instance()->ensure_is_ID($registration_or_reg_id); |
|
365 | 365 | |
366 | 366 | $query_params = array( |
367 | 367 | 0 => array( |
368 | 368 | 'Payment.Registration.REG_ID' => $registration_id, |
369 | 369 | ), |
370 | - 'order_by' => array( 'Payment.PAY_ID' => 'DESC' ) |
|
370 | + 'order_by' => array('Payment.PAY_ID' => 'DESC') |
|
371 | 371 | ); |
372 | - return $this->get_one( $query_params ); |
|
372 | + return $this->get_one($query_params); |
|
373 | 373 | } |
374 | 374 | |
375 | 375 | } |
@@ -233,8 +233,8 @@ |
||
233 | 233 | if ( $registration instanceof EE_Registration ) { |
234 | 234 | $registration->set_paid( $registration->paid() - $amount_paid ); |
235 | 235 | if ($registration->save() !== false) { |
236 | - $registration_payment->delete_permanently(); |
|
237 | - $save_payment = true; |
|
236 | + $registration_payment->delete_permanently(); |
|
237 | + $save_payment = true; |
|
238 | 238 | } |
239 | 239 | } else { |
240 | 240 | EE_Error::add_error( |
@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php if ( ! defined('EVENT_ESPRESSO_VERSION')) { exit('No direct script access allowed'); } |
2 | -EE_Registry::instance()->load_class( 'Processor_Base' ); |
|
2 | +EE_Registry::instance()->load_class('Processor_Base'); |
|
3 | 3 | |
4 | 4 | /** |
5 | 5 | * Class EE_Transaction_Payments |
@@ -42,7 +42,7 @@ discard block |
||
42 | 42 | */ |
43 | 43 | public static function instance() { |
44 | 44 | // check if class object is instantiated |
45 | - if ( ! self::$_instance instanceof EE_Transaction_Payments ) { |
|
45 | + if ( ! self::$_instance instanceof EE_Transaction_Payments) { |
|
46 | 46 | self::$_instance = new self(); |
47 | 47 | } |
48 | 48 | return self::$_instance; |
@@ -59,18 +59,18 @@ discard block |
||
59 | 59 | * @return bool true if TXN total was updated, false if not |
60 | 60 | * @throws \EE_Error |
61 | 61 | */ |
62 | - public function recalculate_transaction_total( EE_Transaction $transaction, $update_txn = true ) { |
|
62 | + public function recalculate_transaction_total(EE_Transaction $transaction, $update_txn = true) { |
|
63 | 63 | $total_line_item = $transaction->total_line_item(); |
64 | - if ( ! $total_line_item instanceof EE_Line_Item ) { |
|
64 | + if ( ! $total_line_item instanceof EE_Line_Item) { |
|
65 | 65 | EE_Error::add_error( |
66 | - sprintf( __( 'The Total Line Item for Transaction %1$d\'s was not found or is invalid.', 'event_espresso' ), $transaction->ID() ), |
|
66 | + sprintf(__('The Total Line Item for Transaction %1$d\'s was not found or is invalid.', 'event_espresso'), $transaction->ID()), |
|
67 | 67 | __FILE__, __FUNCTION__, __LINE__ |
68 | 68 | ); |
69 | 69 | return false; |
70 | 70 | } |
71 | 71 | $new_total = $total_line_item->recalculate_total_including_taxes(); |
72 | - $transaction->set_total( $new_total ); |
|
73 | - if ( $update_txn ) { |
|
72 | + $transaction->set_total($new_total); |
|
73 | + if ($update_txn) { |
|
74 | 74 | return $transaction->save() ? true : false; |
75 | 75 | } |
76 | 76 | return false; |
@@ -93,20 +93,20 @@ discard block |
||
93 | 93 | * @return boolean whether the TXN was saved |
94 | 94 | * @throws \EE_Error |
95 | 95 | */ |
96 | - public function calculate_total_payments_and_update_status( EE_Transaction $transaction, $update_txn = true ){ |
|
96 | + public function calculate_total_payments_and_update_status(EE_Transaction $transaction, $update_txn = true) { |
|
97 | 97 | // verify transaction |
98 | - if ( ! $transaction instanceof EE_Transaction ) { |
|
99 | - EE_Error::add_error( __( 'Please provide a valid EE_Transaction object.', 'event_espresso' ), __FILE__, __FUNCTION__, __LINE__ ); |
|
98 | + if ( ! $transaction instanceof EE_Transaction) { |
|
99 | + EE_Error::add_error(__('Please provide a valid EE_Transaction object.', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__); |
|
100 | 100 | return false; |
101 | 101 | } |
102 | 102 | // calculate total paid |
103 | - $total_paid = $this->recalculate_total_payments_for_transaction( $transaction ); |
|
103 | + $total_paid = $this->recalculate_total_payments_for_transaction($transaction); |
|
104 | 104 | // if total paid has changed |
105 | - if ( $total_paid !== false && (float)$total_paid !== $transaction->paid() ) { |
|
106 | - $transaction->set_paid( $total_paid ); |
|
105 | + if ($total_paid !== false && (float) $total_paid !== $transaction->paid()) { |
|
106 | + $transaction->set_paid($total_paid); |
|
107 | 107 | // maybe update status, and make sure to save transaction if not done already |
108 | - if ( ! $transaction->update_status_based_on_total_paid( $update_txn ) ) { |
|
109 | - if ( $update_txn ) { |
|
108 | + if ( ! $transaction->update_status_based_on_total_paid($update_txn)) { |
|
109 | + if ($update_txn) { |
|
110 | 110 | return $transaction->save() ? true : false; |
111 | 111 | } |
112 | 112 | } else { |
@@ -130,18 +130,18 @@ discard block |
||
130 | 130 | * @return float|false float on success, false on fail |
131 | 131 | * @throws \EE_Error |
132 | 132 | */ |
133 | - public function recalculate_total_payments_for_transaction( EE_Transaction $transaction, $payment_status = EEM_Payment::status_id_approved ) { |
|
133 | + public function recalculate_total_payments_for_transaction(EE_Transaction $transaction, $payment_status = EEM_Payment::status_id_approved) { |
|
134 | 134 | // verify transaction |
135 | - if ( ! $transaction instanceof EE_Transaction ) { |
|
136 | - EE_Error::add_error( __( 'Please provide a valid EE_Transaction object.', 'event_espresso' ), __FILE__, __FUNCTION__, __LINE__ ); |
|
135 | + if ( ! $transaction instanceof EE_Transaction) { |
|
136 | + EE_Error::add_error(__('Please provide a valid EE_Transaction object.', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__); |
|
137 | 137 | return false; |
138 | 138 | } |
139 | 139 | // ensure Payment model is loaded |
140 | - EE_Registry::instance()->load_model( 'Payment' ); |
|
140 | + EE_Registry::instance()->load_model('Payment'); |
|
141 | 141 | // calls EEM_Base::sum() |
142 | 142 | return EEM_Payment::instance()->sum( |
143 | 143 | // query params |
144 | - array( array( 'TXN_ID' => $transaction->ID(), 'STS_ID' => $payment_status )), |
|
144 | + array(array('TXN_ID' => $transaction->ID(), 'STS_ID' => $payment_status)), |
|
145 | 145 | // field to sum |
146 | 146 | 'PAY_amount' |
147 | 147 | ); |
@@ -159,17 +159,17 @@ discard block |
||
159 | 159 | * @return boolean |
160 | 160 | * @throws \EE_Error |
161 | 161 | */ |
162 | - public function delete_payment_and_update_transaction( EE_Payment $payment ) { |
|
162 | + public function delete_payment_and_update_transaction(EE_Payment $payment) { |
|
163 | 163 | // verify payment |
164 | - if ( ! $payment instanceof EE_Payment ) { |
|
165 | - EE_Error::add_error( __( 'A valid Payment object was not received.', 'event_espresso' ), __FILE__, __FUNCTION__, __LINE__ ); |
|
164 | + if ( ! $payment instanceof EE_Payment) { |
|
165 | + EE_Error::add_error(__('A valid Payment object was not received.', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__); |
|
166 | 166 | return false; |
167 | 167 | } |
168 | - if ( ! $this->delete_registration_payments_and_update_registrations( $payment ) ) { |
|
168 | + if ( ! $this->delete_registration_payments_and_update_registrations($payment)) { |
|
169 | 169 | return false; |
170 | 170 | } |
171 | - if ( ! $payment->delete() ) { |
|
172 | - EE_Error::add_error( __( 'The payment could not be deleted.', 'event_espresso' ), __FILE__, __FUNCTION__, __LINE__ ); |
|
171 | + if ( ! $payment->delete()) { |
|
172 | + EE_Error::add_error(__('The payment could not be deleted.', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__); |
|
173 | 173 | return false; |
174 | 174 | } |
175 | 175 | |
@@ -180,14 +180,14 @@ discard block |
||
180 | 180 | || $TXN_status === EEM_Transaction::failed_status_code |
181 | 181 | || $payment->amount() === 0 |
182 | 182 | ) { |
183 | - EE_Error::add_success( __( 'The Payment was successfully deleted.', 'event_espresso' ) ); |
|
183 | + EE_Error::add_success(__('The Payment was successfully deleted.', 'event_espresso')); |
|
184 | 184 | return true; |
185 | 185 | } |
186 | 186 | |
187 | 187 | |
188 | 188 | //if this fails, that just means that the transaction didn't get its status changed and/or updated. |
189 | 189 | //however the payment was still deleted. |
190 | - if ( ! $this->calculate_total_payments_and_update_status( $transaction ) ) { |
|
190 | + if ( ! $this->calculate_total_payments_and_update_status($transaction)) { |
|
191 | 191 | |
192 | 192 | EE_Error::add_attention( |
193 | 193 | __( |
@@ -221,17 +221,17 @@ discard block |
||
221 | 221 | * @return bool |
222 | 222 | * @throws \EE_Error |
223 | 223 | */ |
224 | - public function delete_registration_payments_and_update_registrations( EE_Payment $payment, $reg_payment_query_params = array() ) { |
|
224 | + public function delete_registration_payments_and_update_registrations(EE_Payment $payment, $reg_payment_query_params = array()) { |
|
225 | 225 | $save_payment = false; |
226 | - $reg_payment_query_params = ! empty( $reg_payment_query_params ) ? $reg_payment_query_params : array( array( 'PAY_ID' => $payment->ID() ) ); |
|
227 | - $registration_payments = EEM_Registration_Payment::instance()->get_all( $reg_payment_query_params ); |
|
228 | - if ( ! empty( $registration_payments )) { |
|
229 | - foreach ( $registration_payments as $registration_payment ) { |
|
230 | - if ( $registration_payment instanceof EE_Registration_Payment ) { |
|
226 | + $reg_payment_query_params = ! empty($reg_payment_query_params) ? $reg_payment_query_params : array(array('PAY_ID' => $payment->ID())); |
|
227 | + $registration_payments = EEM_Registration_Payment::instance()->get_all($reg_payment_query_params); |
|
228 | + if ( ! empty($registration_payments)) { |
|
229 | + foreach ($registration_payments as $registration_payment) { |
|
230 | + if ($registration_payment instanceof EE_Registration_Payment) { |
|
231 | 231 | $amount_paid = $registration_payment->amount(); |
232 | 232 | $registration = $registration_payment->registration(); |
233 | - if ( $registration instanceof EE_Registration ) { |
|
234 | - $registration->set_paid( $registration->paid() - $amount_paid ); |
|
233 | + if ($registration instanceof EE_Registration) { |
|
234 | + $registration->set_paid($registration->paid() - $amount_paid); |
|
235 | 235 | if ($registration->save() !== false) { |
236 | 236 | $registration_payment->delete_permanently(); |
237 | 237 | $save_payment = true; |
@@ -239,7 +239,7 @@ discard block |
||
239 | 239 | } else { |
240 | 240 | EE_Error::add_error( |
241 | 241 | sprintf( |
242 | - __( 'An invalid Registration object was associated with Registration Payment ID# %1$d.', 'event_espresso' ), |
|
242 | + __('An invalid Registration object was associated with Registration Payment ID# %1$d.', 'event_espresso'), |
|
243 | 243 | $registration_payment->ID() |
244 | 244 | ), |
245 | 245 | __FILE__, __FUNCTION__, __LINE__ |
@@ -249,7 +249,7 @@ discard block |
||
249 | 249 | } else { |
250 | 250 | EE_Error::add_error( |
251 | 251 | sprintf( |
252 | - __( 'An invalid Registration Payment object was associated with payment ID# %1$d.', 'event_espresso' ), |
|
252 | + __('An invalid Registration Payment object was associated with payment ID# %1$d.', 'event_espresso'), |
|
253 | 253 | $payment->ID() |
254 | 254 | ), |
255 | 255 | __FILE__, __FUNCTION__, __LINE__ |
@@ -258,7 +258,7 @@ discard block |
||
258 | 258 | } |
259 | 259 | } |
260 | 260 | } |
261 | - if ( $save_payment ) { |
|
261 | + if ($save_payment) { |
|
262 | 262 | $payment->save(); |
263 | 263 | } |
264 | 264 | return true; |
@@ -282,7 +282,7 @@ discard block |
||
282 | 282 | public function update_transaction_status_based_on_total_paid(EE_Transaction $transaction, $update_txn = true) |
283 | 283 | { |
284 | 284 | EE_Error::doing_it_wrong( |
285 | - __CLASS__ . '::' . __FUNCTION__, |
|
285 | + __CLASS__.'::'.__FUNCTION__, |
|
286 | 286 | sprintf(__('This method is deprecated. Please use "%s" instead', 'event_espresso'), |
287 | 287 | 'EE_Transaction::update_status_based_on_total_paid()'), |
288 | 288 | '4.9.1', |
@@ -324,7 +324,7 @@ discard block |
||
324 | 324 | * @deprecated 4.9.12 |
325 | 325 | * @param string $old_txn_status |
326 | 326 | */ |
327 | - public function set_old_txn_status( $old_txn_status ) { |
|
327 | + public function set_old_txn_status($old_txn_status) { |
|
328 | 328 | EE_Error::doing_it_wrong( |
329 | 329 | __METHOD__, |
330 | 330 | esc_html__( |
@@ -334,7 +334,7 @@ discard block |
||
334 | 334 | '4.9.12' |
335 | 335 | ); |
336 | 336 | // only set the first time |
337 | - if ( $this->_old_txn_status === null ) { |
|
337 | + if ($this->_old_txn_status === null) { |
|
338 | 338 | $this->_old_txn_status = $old_txn_status; |
339 | 339 | } |
340 | 340 | } |
@@ -363,7 +363,7 @@ discard block |
||
363 | 363 | * @deprecated 4.9.12 |
364 | 364 | * @param string $new_txn_status |
365 | 365 | */ |
366 | - public function set_new_txn_status( $new_txn_status ) { |
|
366 | + public function set_new_txn_status($new_txn_status) { |
|
367 | 367 | EE_Error::doing_it_wrong( |
368 | 368 | __METHOD__, |
369 | 369 | esc_html__( |
@@ -23,49 +23,49 @@ |
||
23 | 23 | class VsprintfFilter extends FormHtmlFilter |
24 | 24 | { |
25 | 25 | |
26 | - /** |
|
27 | - * @var string $format |
|
28 | - */ |
|
29 | - protected $format = ''; |
|
30 | - |
|
31 | - |
|
32 | - /** |
|
33 | - * @var array $args |
|
34 | - */ |
|
35 | - protected $args = array(); |
|
36 | - |
|
37 | - |
|
38 | - |
|
39 | - /** |
|
40 | - * SprintfFormHtmlParser constructor. |
|
41 | - * |
|
42 | - * @param string $format |
|
43 | - * @param array $args |
|
44 | - */ |
|
45 | - public function __construct($format, array $args) |
|
46 | - { |
|
47 | - $this->format = $format; |
|
48 | - $this->args = $args; |
|
49 | - } |
|
50 | - |
|
51 | - |
|
52 | - |
|
53 | - /** |
|
54 | - * @param $html |
|
55 | - * @param EE_Form_Section_Validatable $form_section |
|
56 | - * @return string |
|
57 | - */ |
|
58 | - public function filterHtml($html, EE_Form_Section_Validatable $form_section) |
|
59 | - { |
|
60 | - $this->args[] = $html; |
|
61 | - if ($form_section instanceof EE_Form_Section_Proper) { |
|
62 | - $subsections = $form_section->subsections(); |
|
63 | - foreach ((array)$subsections as $subsection) { |
|
64 | - $this->args[] = $subsection->get_html(); |
|
65 | - } |
|
66 | - } |
|
67 | - return vsprintf($this->format, $this->args); |
|
68 | - } |
|
26 | + /** |
|
27 | + * @var string $format |
|
28 | + */ |
|
29 | + protected $format = ''; |
|
30 | + |
|
31 | + |
|
32 | + /** |
|
33 | + * @var array $args |
|
34 | + */ |
|
35 | + protected $args = array(); |
|
36 | + |
|
37 | + |
|
38 | + |
|
39 | + /** |
|
40 | + * SprintfFormHtmlParser constructor. |
|
41 | + * |
|
42 | + * @param string $format |
|
43 | + * @param array $args |
|
44 | + */ |
|
45 | + public function __construct($format, array $args) |
|
46 | + { |
|
47 | + $this->format = $format; |
|
48 | + $this->args = $args; |
|
49 | + } |
|
50 | + |
|
51 | + |
|
52 | + |
|
53 | + /** |
|
54 | + * @param $html |
|
55 | + * @param EE_Form_Section_Validatable $form_section |
|
56 | + * @return string |
|
57 | + */ |
|
58 | + public function filterHtml($html, EE_Form_Section_Validatable $form_section) |
|
59 | + { |
|
60 | + $this->args[] = $html; |
|
61 | + if ($form_section instanceof EE_Form_Section_Proper) { |
|
62 | + $subsections = $form_section->subsections(); |
|
63 | + foreach ((array)$subsections as $subsection) { |
|
64 | + $this->args[] = $subsection->get_html(); |
|
65 | + } |
|
66 | + } |
|
67 | + return vsprintf($this->format, $this->args); |
|
68 | + } |
|
69 | 69 | |
70 | 70 | |
71 | 71 |
@@ -60,7 +60,7 @@ |
||
60 | 60 | $this->args[] = $html; |
61 | 61 | if ($form_section instanceof EE_Form_Section_Proper) { |
62 | 62 | $subsections = $form_section->subsections(); |
63 | - foreach ((array)$subsections as $subsection) { |
|
63 | + foreach ((array) $subsections as $subsection) { |
|
64 | 64 | $this->args[] = $subsection->get_html(); |
65 | 65 | } |
66 | 66 | } |
@@ -84,7 +84,7 @@ |
||
84 | 84 | * Checks if that value is the one selected |
85 | 85 | * |
86 | 86 | * @param string|int $option_value unnormalized value option (string). How it will appear in the HTML. |
87 | - * @return string |
|
87 | + * @return boolean |
|
88 | 88 | */ |
89 | 89 | protected function _check_if_option_selected($option_value ){ |
90 | 90 | return $option_value === $this->_input->raw_value(); |
@@ -38,15 +38,15 @@ discard block |
||
38 | 38 | if ( EEH_Array::is_multi_dimensional_array( $this->_input->options() )) { |
39 | 39 | EEH_HTML::indent( 1, 'optgroup' ); |
40 | 40 | foreach( $this->_input->options() as $opt_group_label => $opt_group ){ |
41 | - if ( ! empty($opt_group_label)) { |
|
42 | - $html .= EEH_HTML::nl(0, 'optgroup') . '<optgroup label="' . esc_attr($opt_group_label) . '">'; |
|
43 | - } |
|
41 | + if ( ! empty($opt_group_label)) { |
|
42 | + $html .= EEH_HTML::nl(0, 'optgroup') . '<optgroup label="' . esc_attr($opt_group_label) . '">'; |
|
43 | + } |
|
44 | 44 | EEH_HTML::indent( 1, 'option' ); |
45 | 45 | $html .= $this->_display_options( $opt_group ); |
46 | 46 | EEH_HTML::indent( -1, 'option' ); |
47 | - if ( ! empty($opt_group_label)) { |
|
48 | - $html .= EEH_HTML::nl( 0, 'optgroup' ) . '</optgroup>'; |
|
49 | - } |
|
47 | + if ( ! empty($opt_group_label)) { |
|
48 | + $html .= EEH_HTML::nl( 0, 'optgroup' ) . '</optgroup>'; |
|
49 | + } |
|
50 | 50 | } |
51 | 51 | EEH_HTML::indent( -1, 'optgroup' ); |
52 | 52 | } else { |
@@ -68,11 +68,11 @@ discard block |
||
68 | 68 | $html = ''; |
69 | 69 | EEH_HTML::indent( 1, 'option' ); |
70 | 70 | foreach( $options as $value => $display_text ){ |
71 | - //even if this input uses EE_Text_Normalization if one of the array keys is a numeric string, like "123", |
|
72 | - //PHP will have converted it to a PHP integer (eg 123). So we need to make sure it's a string |
|
73 | - $unnormalized_value = $this->_input->get_normalization_strategy()->unnormalize_one( $value ); |
|
74 | - $selected = $this->_check_if_option_selected($unnormalized_value ) ? ' selected="selected"' : ''; |
|
75 | - $html.= EEH_HTML::nl( 0, 'option' ) . '<option value="' . esc_attr($unnormalized_value ) . '"' . $selected . '>' . $display_text . '</option>'; |
|
71 | + //even if this input uses EE_Text_Normalization if one of the array keys is a numeric string, like "123", |
|
72 | + //PHP will have converted it to a PHP integer (eg 123). So we need to make sure it's a string |
|
73 | + $unnormalized_value = $this->_input->get_normalization_strategy()->unnormalize_one( $value ); |
|
74 | + $selected = $this->_check_if_option_selected($unnormalized_value ) ? ' selected="selected"' : ''; |
|
75 | + $html.= EEH_HTML::nl( 0, 'option' ) . '<option value="' . esc_attr($unnormalized_value ) . '"' . $selected . '>' . $display_text . '</option>'; |
|
76 | 76 | } |
77 | 77 | EEH_HTML::indent( -1, 'option' ); |
78 | 78 | return $html; |
@@ -11,49 +11,49 @@ discard block |
||
11 | 11 | * @since $VID:$ |
12 | 12 | * |
13 | 13 | */ |
14 | -class EE_Select_Display_Strategy extends EE_Display_Strategy_Base{ |
|
14 | +class EE_Select_Display_Strategy extends EE_Display_Strategy_Base { |
|
15 | 15 | |
16 | 16 | /** |
17 | 17 | * |
18 | 18 | * @throws EE_Error |
19 | 19 | * @return string of html to display the field |
20 | 20 | */ |
21 | - function display(){ |
|
22 | - if( ! $this->_input instanceof EE_Form_Input_With_Options_Base){ |
|
23 | - throw new EE_Error( sprintf( __( 'Cannot use Select Display Strategy with an input that doesn\'t have options', 'event_espresso' ))); |
|
21 | + function display() { |
|
22 | + if ( ! $this->_input instanceof EE_Form_Input_With_Options_Base) { |
|
23 | + throw new EE_Error(sprintf(__('Cannot use Select Display Strategy with an input that doesn\'t have options', 'event_espresso'))); |
|
24 | 24 | } |
25 | 25 | |
26 | - $html = EEH_HTML::nl( 0, 'select' ); |
|
26 | + $html = EEH_HTML::nl(0, 'select'); |
|
27 | 27 | $html .= '<select'; |
28 | - $html .= ' id="' . $this->_input->html_id() . '"'; |
|
29 | - $html .= ' name="' . $this->_input->html_name() . '"'; |
|
30 | - $class = $this->_input->required() ? $this->_input->required_css_class() . ' ' . $this->_input->html_class() : $this->_input->html_class(); |
|
31 | - $html .= ' class="' . $class . '"'; |
|
28 | + $html .= ' id="'.$this->_input->html_id().'"'; |
|
29 | + $html .= ' name="'.$this->_input->html_name().'"'; |
|
30 | + $class = $this->_input->required() ? $this->_input->required_css_class().' '.$this->_input->html_class() : $this->_input->html_class(); |
|
31 | + $html .= ' class="'.$class.'"'; |
|
32 | 32 | // add html5 required |
33 | 33 | $html .= $this->_input->required() ? ' required' : ''; |
34 | - $html .= ' style="' . $this->_input->html_style() . '"'; |
|
35 | - $html .= ' ' . $this->_input->other_html_attributes(); |
|
34 | + $html .= ' style="'.$this->_input->html_style().'"'; |
|
35 | + $html .= ' '.$this->_input->other_html_attributes(); |
|
36 | 36 | $html .= '>'; |
37 | 37 | |
38 | - if ( EEH_Array::is_multi_dimensional_array( $this->_input->options() )) { |
|
39 | - EEH_HTML::indent( 1, 'optgroup' ); |
|
40 | - foreach( $this->_input->options() as $opt_group_label => $opt_group ){ |
|
38 | + if (EEH_Array::is_multi_dimensional_array($this->_input->options())) { |
|
39 | + EEH_HTML::indent(1, 'optgroup'); |
|
40 | + foreach ($this->_input->options() as $opt_group_label => $opt_group) { |
|
41 | 41 | if ( ! empty($opt_group_label)) { |
42 | - $html .= EEH_HTML::nl(0, 'optgroup') . '<optgroup label="' . esc_attr($opt_group_label) . '">'; |
|
42 | + $html .= EEH_HTML::nl(0, 'optgroup').'<optgroup label="'.esc_attr($opt_group_label).'">'; |
|
43 | 43 | } |
44 | - EEH_HTML::indent( 1, 'option' ); |
|
45 | - $html .= $this->_display_options( $opt_group ); |
|
44 | + EEH_HTML::indent(1, 'option'); |
|
45 | + $html .= $this->_display_options($opt_group); |
|
46 | 46 | EEH_HTML::indent( -1, 'option' ); |
47 | 47 | if ( ! empty($opt_group_label)) { |
48 | - $html .= EEH_HTML::nl( 0, 'optgroup' ) . '</optgroup>'; |
|
48 | + $html .= EEH_HTML::nl(0, 'optgroup').'</optgroup>'; |
|
49 | 49 | } |
50 | 50 | } |
51 | 51 | EEH_HTML::indent( -1, 'optgroup' ); |
52 | 52 | } else { |
53 | - $html.=$this->_display_options( $this->_input->options() ); |
|
53 | + $html .= $this->_display_options($this->_input->options()); |
|
54 | 54 | } |
55 | 55 | |
56 | - $html.= EEH_HTML::nl( 0, 'select' ) . '</select>'; |
|
56 | + $html .= EEH_HTML::nl(0, 'select').'</select>'; |
|
57 | 57 | return $html; |
58 | 58 | } |
59 | 59 | |
@@ -64,15 +64,15 @@ discard block |
||
64 | 64 | * @param array $options |
65 | 65 | * @return string |
66 | 66 | */ |
67 | - protected function _display_options($options){ |
|
67 | + protected function _display_options($options) { |
|
68 | 68 | $html = ''; |
69 | - EEH_HTML::indent( 1, 'option' ); |
|
70 | - foreach( $options as $value => $display_text ){ |
|
69 | + EEH_HTML::indent(1, 'option'); |
|
70 | + foreach ($options as $value => $display_text) { |
|
71 | 71 | //even if this input uses EE_Text_Normalization if one of the array keys is a numeric string, like "123", |
72 | 72 | //PHP will have converted it to a PHP integer (eg 123). So we need to make sure it's a string |
73 | - $unnormalized_value = $this->_input->get_normalization_strategy()->unnormalize_one( $value ); |
|
74 | - $selected = $this->_check_if_option_selected($unnormalized_value ) ? ' selected="selected"' : ''; |
|
75 | - $html.= EEH_HTML::nl( 0, 'option' ) . '<option value="' . esc_attr($unnormalized_value ) . '"' . $selected . '>' . $display_text . '</option>'; |
|
73 | + $unnormalized_value = $this->_input->get_normalization_strategy()->unnormalize_one($value); |
|
74 | + $selected = $this->_check_if_option_selected($unnormalized_value) ? ' selected="selected"' : ''; |
|
75 | + $html .= EEH_HTML::nl(0, 'option').'<option value="'.esc_attr($unnormalized_value).'"'.$selected.'>'.$display_text.'</option>'; |
|
76 | 76 | } |
77 | 77 | EEH_HTML::indent( -1, 'option' ); |
78 | 78 | return $html; |
@@ -86,7 +86,7 @@ discard block |
||
86 | 86 | * @param string|int $option_value unnormalized value option (string). How it will appear in the HTML. |
87 | 87 | * @return string |
88 | 88 | */ |
89 | - protected function _check_if_option_selected($option_value ){ |
|
89 | + protected function _check_if_option_selected($option_value) { |
|
90 | 90 | return $option_value === $this->_input->raw_value(); |
91 | 91 | } |
92 | 92 |
@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
2 | - exit('No direct script access allowed'); |
|
2 | + exit('No direct script access allowed'); |
|
3 | 3 | } |
4 | 4 | |
5 | 5 | |
@@ -16,320 +16,320 @@ discard block |
||
16 | 16 | class EE_Form_Input_With_Options_Base extends EE_Form_Input_Base |
17 | 17 | { |
18 | 18 | |
19 | - /** |
|
20 | - * array of available options to choose as an answer |
|
21 | - * |
|
22 | - * @var array |
|
23 | - */ |
|
24 | - protected $_options = array(); |
|
25 | - |
|
26 | - /** |
|
27 | - * whether to display the html_label_text above the checkbox/radio button options |
|
28 | - * |
|
29 | - * @var boolean |
|
30 | - */ |
|
31 | - protected $_display_html_label_text = true; |
|
32 | - |
|
33 | - /** |
|
34 | - * whether to display an question option description as part of the input label |
|
35 | - * |
|
36 | - * @var boolean |
|
37 | - */ |
|
38 | - protected $_use_desc_in_label = true; |
|
39 | - |
|
40 | - /** |
|
41 | - * strlen() result for the longest input value (what gets displayed in the label) |
|
42 | - * this is used to apply a css class to the input label |
|
43 | - * |
|
44 | - * @var int |
|
45 | - */ |
|
46 | - protected $_label_size = 0; |
|
47 | - |
|
48 | - /** |
|
49 | - * whether to enforce the label size value passed in the constructor |
|
50 | - * |
|
51 | - * @var boolean |
|
52 | - */ |
|
53 | - protected $_enforce_label_size = false; |
|
54 | - |
|
55 | - /** |
|
56 | - * whether to allow multiple selections (ie, the value of this input should be an array) |
|
57 | - * or not (ie, the value should be a simple int, string, etc) |
|
58 | - * |
|
59 | - * @var boolean |
|
60 | - */ |
|
61 | - protected $_multiple_selections = false; |
|
62 | - |
|
63 | - |
|
64 | - |
|
65 | - /** |
|
66 | - * @param array $answer_options |
|
67 | - * @param array $input_settings { |
|
68 | - * @type int|string $label_size |
|
69 | - * @type boolean $display_html_label_text |
|
70 | - * } |
|
71 | - * And all the options accepted by EE_Form_Input_Base |
|
72 | - */ |
|
73 | - public function __construct($answer_options = array(), $input_settings = array()) |
|
74 | - { |
|
75 | - if (isset($input_settings['label_size'])) { |
|
76 | - $this->_set_label_size($input_settings['label_size']); |
|
77 | - if (isset($input_settings['enforce_label_size']) && $input_settings['enforce_label_size']) { |
|
78 | - $this->_enforce_label_size = true; |
|
79 | - } |
|
80 | - } |
|
81 | - if (isset($input_settings['display_html_label_text'])) { |
|
82 | - $this->set_display_html_label_text($input_settings['display_html_label_text']); |
|
83 | - } |
|
84 | - $this->set_select_options($answer_options); |
|
85 | - parent::__construct($input_settings); |
|
86 | - } |
|
87 | - |
|
88 | - |
|
89 | - |
|
90 | - /** |
|
91 | - * Sets the allowed options for this input. Also has the side-effect of |
|
92 | - * updating the normalization strategy to match the keys provided in the array |
|
93 | - * |
|
94 | - * @param array $answer_options |
|
95 | - * @return void just has the side-effect of setting the options for this input |
|
96 | - */ |
|
97 | - public function set_select_options($answer_options = array()) |
|
98 | - { |
|
99 | - $answer_options = is_array($answer_options) ? $answer_options : array($answer_options); |
|
100 | - //get the first item in the select options and check it's type |
|
101 | - $this->_options = reset($answer_options) instanceof EE_Question_Option |
|
102 | - ? $this->_process_question_options($answer_options) |
|
103 | - : $answer_options; |
|
104 | - //d( $this->_options ); |
|
105 | - $select_option_keys = array_keys($this->_options); |
|
106 | - // attempt to determine data type for values in order to set normalization type |
|
107 | - //purposefully only |
|
108 | - if ( |
|
109 | - count($this->_options) === 2 |
|
110 | - && ( |
|
111 | - (in_array(true, $select_option_keys, true) && in_array(false, $select_option_keys, true)) |
|
112 | - || (in_array(1, $select_option_keys, true) && in_array(0, $select_option_keys, true)) |
|
113 | - ) |
|
114 | - ) { |
|
115 | - // values appear to be boolean, like TRUE, FALSE, 1, 0 |
|
116 | - $normalization = new EE_Boolean_Normalization(); |
|
117 | - } else { |
|
118 | - //are ALL the options ints (even if we're using a multi-dimensional array)? If so use int validation |
|
119 | - $all_ints = true; |
|
120 | - array_walk_recursive( |
|
121 | - $this->_options, |
|
122 | - function($value,$key) use (&$all_ints){ |
|
123 | - //is this a top-level key? ignore it |
|
124 | - if(! is_array($value) |
|
125 | - && ! is_int($key) |
|
126 | - && $key !== '' |
|
127 | - && $key !== null){ |
|
128 | - $all_ints = false; |
|
129 | - } |
|
130 | - } |
|
131 | - ); |
|
132 | - if ($all_ints) { |
|
133 | - $normalization = new EE_Int_Normalization(); |
|
134 | - } else { |
|
135 | - $normalization = new EE_Text_Normalization(); |
|
136 | - } |
|
137 | - } |
|
138 | - // does input type have multiple options ? |
|
139 | - if ($this->_multiple_selections) { |
|
140 | - $this->_set_normalization_strategy(new EE_Many_Valued_Normalization($normalization)); |
|
141 | - } else { |
|
142 | - $this->_set_normalization_strategy($normalization); |
|
143 | - } |
|
144 | - } |
|
145 | - |
|
146 | - |
|
147 | - |
|
148 | - /** |
|
149 | - * @return array |
|
150 | - */ |
|
151 | - public function options() |
|
152 | - { |
|
153 | - return $this->_options; |
|
154 | - } |
|
155 | - |
|
156 | - |
|
157 | - |
|
158 | - /** |
|
159 | - * Returns an array which is guaranteed to not be multidimensional |
|
160 | - * |
|
161 | - * @return array |
|
162 | - */ |
|
163 | - public function flat_options() |
|
164 | - { |
|
165 | - return $this->_flatten_select_options($this->options()); |
|
166 | - } |
|
167 | - |
|
168 | - |
|
169 | - |
|
170 | - /** |
|
171 | - * Makes sure $arr is a flat array, not a multidimensional one |
|
172 | - * |
|
173 | - * @param array $arr |
|
174 | - * @return array |
|
175 | - */ |
|
176 | - protected function _flatten_select_options($arr) |
|
177 | - { |
|
178 | - $flat_array = array(); |
|
179 | - if (EEH_Array::is_multi_dimensional_array($arr)) { |
|
180 | - foreach ($arr as $sub_array) { |
|
181 | - foreach ((array)$sub_array as $key => $value) { |
|
182 | - $flat_array[$key] = $value; |
|
183 | - $this->_set_label_size($value); |
|
184 | - } |
|
185 | - } |
|
186 | - } else { |
|
187 | - foreach ($arr as $key => $value) { |
|
188 | - $flat_array[$key] = $value; |
|
189 | - $this->_set_label_size($value); |
|
190 | - } |
|
191 | - } |
|
192 | - return $flat_array; |
|
193 | - } |
|
194 | - |
|
195 | - |
|
196 | - |
|
197 | - /** |
|
198 | - * @param EE_Question_Option[] $question_options_array |
|
199 | - * @return array |
|
200 | - */ |
|
201 | - protected function _process_question_options($question_options_array = array()) |
|
202 | - { |
|
203 | - $flat_array = array(); |
|
204 | - foreach ($question_options_array as $question_option) { |
|
205 | - if ($question_option instanceof EE_Question_Option) { |
|
206 | - $desc = ''; |
|
207 | - if ($this->_use_desc_in_label) { |
|
208 | - $desc = $question_option->desc(); |
|
209 | - $desc = ! empty($desc) ? '<span class="ee-question-option-desc">' . $desc . '</span>' : ''; |
|
210 | - } |
|
211 | - $value = $question_option->value(); |
|
212 | - // add value even if it's empty |
|
213 | - $flat_array[$value] = $value; |
|
214 | - // if both value and desc are not empty, then separate with a dash |
|
215 | - if ( ! empty($value) && ! empty($desc)) { |
|
216 | - $flat_array[$value] .= ' - ' . $desc; |
|
217 | - } else { |
|
218 | - // otherwise, just add desc, since either or both of the vars is empty, and no dash is necessary |
|
219 | - $flat_array[$value] .= $desc; |
|
220 | - } |
|
221 | - } elseif (is_array($question_option)) { |
|
222 | - $flat_array += $this->_flatten_select_options($question_option); |
|
223 | - } |
|
224 | - } |
|
225 | - return $flat_array; |
|
226 | - } |
|
227 | - |
|
228 | - |
|
229 | - |
|
230 | - /** |
|
231 | - * set_label_sizes |
|
232 | - * |
|
233 | - * @return void |
|
234 | - */ |
|
235 | - public function set_label_sizes() |
|
236 | - { |
|
237 | - // did the input settings specifically say to NOT set the label size dynamically ? |
|
238 | - if ( ! $this->_enforce_label_size) { |
|
239 | - foreach ($this->_options as $option) { |
|
240 | - // calculate the strlen of the label |
|
241 | - $this->_set_label_size($option); |
|
242 | - } |
|
243 | - } |
|
244 | - } |
|
245 | - |
|
246 | - |
|
247 | - |
|
248 | - /** |
|
249 | - * _set_label_size_class |
|
250 | - * |
|
251 | - * @param int|string $value |
|
252 | - * @return void |
|
253 | - */ |
|
254 | - private function _set_label_size($value = '') |
|
255 | - { |
|
256 | - // determine length of option value |
|
257 | - $val_size = is_int($value) ? $value : strlen($value); |
|
258 | - // use new value if bigger than existing |
|
259 | - $this->_label_size = $val_size > $this->_label_size ? $val_size : $this->_label_size; |
|
260 | - } |
|
261 | - |
|
262 | - |
|
263 | - |
|
264 | - /** |
|
265 | - * get_label_size_class |
|
266 | - * |
|
267 | - * @return string |
|
268 | - */ |
|
269 | - public function get_label_size_class() |
|
270 | - { |
|
271 | - $size = ' medium-lbl'; |
|
272 | - // use maximum option value length to determine label size |
|
273 | - if ($this->_label_size < 3) { |
|
274 | - $size = ' nano-lbl'; |
|
275 | - } else if ($this->_label_size < 6) { |
|
276 | - $size = ' micro-lbl'; |
|
277 | - } else if ($this->_label_size < 12) { |
|
278 | - $size = ' tiny-lbl'; |
|
279 | - } else if ($this->_label_size < 25) { |
|
280 | - $size = ' small-lbl'; |
|
281 | - } else if ($this->_label_size < 50) { |
|
282 | - $size = ' medium-lbl'; |
|
283 | - } else if ($this->_label_size >= 100) { |
|
284 | - $size = ' big-lbl'; |
|
285 | - } |
|
286 | - return $size; |
|
287 | - } |
|
288 | - |
|
289 | - |
|
290 | - |
|
291 | - /** |
|
292 | - * Returns the pretty value for the normalized value |
|
293 | - * |
|
294 | - * @return string |
|
295 | - */ |
|
296 | - public function pretty_value() |
|
297 | - { |
|
298 | - $options = $this->flat_options(); |
|
299 | - $unnormalized_value_choices = $this->get_normalization_strategy()->unnormalize($this->_normalized_value); |
|
300 | - if ( ! $this->_multiple_selections) { |
|
301 | - $unnormalized_value_choices = array($unnormalized_value_choices); |
|
302 | - } |
|
303 | - $pretty_strings = array(); |
|
304 | - foreach ((array)$unnormalized_value_choices as $unnormalized_value_choice) { |
|
305 | - if (isset($options[$unnormalized_value_choice])) { |
|
306 | - $pretty_strings[] = $options[$unnormalized_value_choice]; |
|
307 | - } else { |
|
308 | - $pretty_strings[] = $this->normalized_value(); |
|
309 | - } |
|
310 | - } |
|
311 | - return implode(', ', $pretty_strings); |
|
312 | - } |
|
313 | - |
|
314 | - |
|
315 | - |
|
316 | - /** |
|
317 | - * @return boolean |
|
318 | - */ |
|
319 | - public function display_html_label_text() |
|
320 | - { |
|
321 | - return $this->_display_html_label_text; |
|
322 | - } |
|
323 | - |
|
324 | - |
|
325 | - |
|
326 | - /** |
|
327 | - * @param boolean $display_html_label_text |
|
328 | - */ |
|
329 | - public function set_display_html_label_text($display_html_label_text) |
|
330 | - { |
|
331 | - $this->_display_html_label_text = filter_var($display_html_label_text, FILTER_VALIDATE_BOOLEAN); |
|
332 | - } |
|
19 | + /** |
|
20 | + * array of available options to choose as an answer |
|
21 | + * |
|
22 | + * @var array |
|
23 | + */ |
|
24 | + protected $_options = array(); |
|
25 | + |
|
26 | + /** |
|
27 | + * whether to display the html_label_text above the checkbox/radio button options |
|
28 | + * |
|
29 | + * @var boolean |
|
30 | + */ |
|
31 | + protected $_display_html_label_text = true; |
|
32 | + |
|
33 | + /** |
|
34 | + * whether to display an question option description as part of the input label |
|
35 | + * |
|
36 | + * @var boolean |
|
37 | + */ |
|
38 | + protected $_use_desc_in_label = true; |
|
39 | + |
|
40 | + /** |
|
41 | + * strlen() result for the longest input value (what gets displayed in the label) |
|
42 | + * this is used to apply a css class to the input label |
|
43 | + * |
|
44 | + * @var int |
|
45 | + */ |
|
46 | + protected $_label_size = 0; |
|
47 | + |
|
48 | + /** |
|
49 | + * whether to enforce the label size value passed in the constructor |
|
50 | + * |
|
51 | + * @var boolean |
|
52 | + */ |
|
53 | + protected $_enforce_label_size = false; |
|
54 | + |
|
55 | + /** |
|
56 | + * whether to allow multiple selections (ie, the value of this input should be an array) |
|
57 | + * or not (ie, the value should be a simple int, string, etc) |
|
58 | + * |
|
59 | + * @var boolean |
|
60 | + */ |
|
61 | + protected $_multiple_selections = false; |
|
62 | + |
|
63 | + |
|
64 | + |
|
65 | + /** |
|
66 | + * @param array $answer_options |
|
67 | + * @param array $input_settings { |
|
68 | + * @type int|string $label_size |
|
69 | + * @type boolean $display_html_label_text |
|
70 | + * } |
|
71 | + * And all the options accepted by EE_Form_Input_Base |
|
72 | + */ |
|
73 | + public function __construct($answer_options = array(), $input_settings = array()) |
|
74 | + { |
|
75 | + if (isset($input_settings['label_size'])) { |
|
76 | + $this->_set_label_size($input_settings['label_size']); |
|
77 | + if (isset($input_settings['enforce_label_size']) && $input_settings['enforce_label_size']) { |
|
78 | + $this->_enforce_label_size = true; |
|
79 | + } |
|
80 | + } |
|
81 | + if (isset($input_settings['display_html_label_text'])) { |
|
82 | + $this->set_display_html_label_text($input_settings['display_html_label_text']); |
|
83 | + } |
|
84 | + $this->set_select_options($answer_options); |
|
85 | + parent::__construct($input_settings); |
|
86 | + } |
|
87 | + |
|
88 | + |
|
89 | + |
|
90 | + /** |
|
91 | + * Sets the allowed options for this input. Also has the side-effect of |
|
92 | + * updating the normalization strategy to match the keys provided in the array |
|
93 | + * |
|
94 | + * @param array $answer_options |
|
95 | + * @return void just has the side-effect of setting the options for this input |
|
96 | + */ |
|
97 | + public function set_select_options($answer_options = array()) |
|
98 | + { |
|
99 | + $answer_options = is_array($answer_options) ? $answer_options : array($answer_options); |
|
100 | + //get the first item in the select options and check it's type |
|
101 | + $this->_options = reset($answer_options) instanceof EE_Question_Option |
|
102 | + ? $this->_process_question_options($answer_options) |
|
103 | + : $answer_options; |
|
104 | + //d( $this->_options ); |
|
105 | + $select_option_keys = array_keys($this->_options); |
|
106 | + // attempt to determine data type for values in order to set normalization type |
|
107 | + //purposefully only |
|
108 | + if ( |
|
109 | + count($this->_options) === 2 |
|
110 | + && ( |
|
111 | + (in_array(true, $select_option_keys, true) && in_array(false, $select_option_keys, true)) |
|
112 | + || (in_array(1, $select_option_keys, true) && in_array(0, $select_option_keys, true)) |
|
113 | + ) |
|
114 | + ) { |
|
115 | + // values appear to be boolean, like TRUE, FALSE, 1, 0 |
|
116 | + $normalization = new EE_Boolean_Normalization(); |
|
117 | + } else { |
|
118 | + //are ALL the options ints (even if we're using a multi-dimensional array)? If so use int validation |
|
119 | + $all_ints = true; |
|
120 | + array_walk_recursive( |
|
121 | + $this->_options, |
|
122 | + function($value,$key) use (&$all_ints){ |
|
123 | + //is this a top-level key? ignore it |
|
124 | + if(! is_array($value) |
|
125 | + && ! is_int($key) |
|
126 | + && $key !== '' |
|
127 | + && $key !== null){ |
|
128 | + $all_ints = false; |
|
129 | + } |
|
130 | + } |
|
131 | + ); |
|
132 | + if ($all_ints) { |
|
133 | + $normalization = new EE_Int_Normalization(); |
|
134 | + } else { |
|
135 | + $normalization = new EE_Text_Normalization(); |
|
136 | + } |
|
137 | + } |
|
138 | + // does input type have multiple options ? |
|
139 | + if ($this->_multiple_selections) { |
|
140 | + $this->_set_normalization_strategy(new EE_Many_Valued_Normalization($normalization)); |
|
141 | + } else { |
|
142 | + $this->_set_normalization_strategy($normalization); |
|
143 | + } |
|
144 | + } |
|
145 | + |
|
146 | + |
|
147 | + |
|
148 | + /** |
|
149 | + * @return array |
|
150 | + */ |
|
151 | + public function options() |
|
152 | + { |
|
153 | + return $this->_options; |
|
154 | + } |
|
155 | + |
|
156 | + |
|
157 | + |
|
158 | + /** |
|
159 | + * Returns an array which is guaranteed to not be multidimensional |
|
160 | + * |
|
161 | + * @return array |
|
162 | + */ |
|
163 | + public function flat_options() |
|
164 | + { |
|
165 | + return $this->_flatten_select_options($this->options()); |
|
166 | + } |
|
167 | + |
|
168 | + |
|
169 | + |
|
170 | + /** |
|
171 | + * Makes sure $arr is a flat array, not a multidimensional one |
|
172 | + * |
|
173 | + * @param array $arr |
|
174 | + * @return array |
|
175 | + */ |
|
176 | + protected function _flatten_select_options($arr) |
|
177 | + { |
|
178 | + $flat_array = array(); |
|
179 | + if (EEH_Array::is_multi_dimensional_array($arr)) { |
|
180 | + foreach ($arr as $sub_array) { |
|
181 | + foreach ((array)$sub_array as $key => $value) { |
|
182 | + $flat_array[$key] = $value; |
|
183 | + $this->_set_label_size($value); |
|
184 | + } |
|
185 | + } |
|
186 | + } else { |
|
187 | + foreach ($arr as $key => $value) { |
|
188 | + $flat_array[$key] = $value; |
|
189 | + $this->_set_label_size($value); |
|
190 | + } |
|
191 | + } |
|
192 | + return $flat_array; |
|
193 | + } |
|
194 | + |
|
195 | + |
|
196 | + |
|
197 | + /** |
|
198 | + * @param EE_Question_Option[] $question_options_array |
|
199 | + * @return array |
|
200 | + */ |
|
201 | + protected function _process_question_options($question_options_array = array()) |
|
202 | + { |
|
203 | + $flat_array = array(); |
|
204 | + foreach ($question_options_array as $question_option) { |
|
205 | + if ($question_option instanceof EE_Question_Option) { |
|
206 | + $desc = ''; |
|
207 | + if ($this->_use_desc_in_label) { |
|
208 | + $desc = $question_option->desc(); |
|
209 | + $desc = ! empty($desc) ? '<span class="ee-question-option-desc">' . $desc . '</span>' : ''; |
|
210 | + } |
|
211 | + $value = $question_option->value(); |
|
212 | + // add value even if it's empty |
|
213 | + $flat_array[$value] = $value; |
|
214 | + // if both value and desc are not empty, then separate with a dash |
|
215 | + if ( ! empty($value) && ! empty($desc)) { |
|
216 | + $flat_array[$value] .= ' - ' . $desc; |
|
217 | + } else { |
|
218 | + // otherwise, just add desc, since either or both of the vars is empty, and no dash is necessary |
|
219 | + $flat_array[$value] .= $desc; |
|
220 | + } |
|
221 | + } elseif (is_array($question_option)) { |
|
222 | + $flat_array += $this->_flatten_select_options($question_option); |
|
223 | + } |
|
224 | + } |
|
225 | + return $flat_array; |
|
226 | + } |
|
227 | + |
|
228 | + |
|
229 | + |
|
230 | + /** |
|
231 | + * set_label_sizes |
|
232 | + * |
|
233 | + * @return void |
|
234 | + */ |
|
235 | + public function set_label_sizes() |
|
236 | + { |
|
237 | + // did the input settings specifically say to NOT set the label size dynamically ? |
|
238 | + if ( ! $this->_enforce_label_size) { |
|
239 | + foreach ($this->_options as $option) { |
|
240 | + // calculate the strlen of the label |
|
241 | + $this->_set_label_size($option); |
|
242 | + } |
|
243 | + } |
|
244 | + } |
|
245 | + |
|
246 | + |
|
247 | + |
|
248 | + /** |
|
249 | + * _set_label_size_class |
|
250 | + * |
|
251 | + * @param int|string $value |
|
252 | + * @return void |
|
253 | + */ |
|
254 | + private function _set_label_size($value = '') |
|
255 | + { |
|
256 | + // determine length of option value |
|
257 | + $val_size = is_int($value) ? $value : strlen($value); |
|
258 | + // use new value if bigger than existing |
|
259 | + $this->_label_size = $val_size > $this->_label_size ? $val_size : $this->_label_size; |
|
260 | + } |
|
261 | + |
|
262 | + |
|
263 | + |
|
264 | + /** |
|
265 | + * get_label_size_class |
|
266 | + * |
|
267 | + * @return string |
|
268 | + */ |
|
269 | + public function get_label_size_class() |
|
270 | + { |
|
271 | + $size = ' medium-lbl'; |
|
272 | + // use maximum option value length to determine label size |
|
273 | + if ($this->_label_size < 3) { |
|
274 | + $size = ' nano-lbl'; |
|
275 | + } else if ($this->_label_size < 6) { |
|
276 | + $size = ' micro-lbl'; |
|
277 | + } else if ($this->_label_size < 12) { |
|
278 | + $size = ' tiny-lbl'; |
|
279 | + } else if ($this->_label_size < 25) { |
|
280 | + $size = ' small-lbl'; |
|
281 | + } else if ($this->_label_size < 50) { |
|
282 | + $size = ' medium-lbl'; |
|
283 | + } else if ($this->_label_size >= 100) { |
|
284 | + $size = ' big-lbl'; |
|
285 | + } |
|
286 | + return $size; |
|
287 | + } |
|
288 | + |
|
289 | + |
|
290 | + |
|
291 | + /** |
|
292 | + * Returns the pretty value for the normalized value |
|
293 | + * |
|
294 | + * @return string |
|
295 | + */ |
|
296 | + public function pretty_value() |
|
297 | + { |
|
298 | + $options = $this->flat_options(); |
|
299 | + $unnormalized_value_choices = $this->get_normalization_strategy()->unnormalize($this->_normalized_value); |
|
300 | + if ( ! $this->_multiple_selections) { |
|
301 | + $unnormalized_value_choices = array($unnormalized_value_choices); |
|
302 | + } |
|
303 | + $pretty_strings = array(); |
|
304 | + foreach ((array)$unnormalized_value_choices as $unnormalized_value_choice) { |
|
305 | + if (isset($options[$unnormalized_value_choice])) { |
|
306 | + $pretty_strings[] = $options[$unnormalized_value_choice]; |
|
307 | + } else { |
|
308 | + $pretty_strings[] = $this->normalized_value(); |
|
309 | + } |
|
310 | + } |
|
311 | + return implode(', ', $pretty_strings); |
|
312 | + } |
|
313 | + |
|
314 | + |
|
315 | + |
|
316 | + /** |
|
317 | + * @return boolean |
|
318 | + */ |
|
319 | + public function display_html_label_text() |
|
320 | + { |
|
321 | + return $this->_display_html_label_text; |
|
322 | + } |
|
323 | + |
|
324 | + |
|
325 | + |
|
326 | + /** |
|
327 | + * @param boolean $display_html_label_text |
|
328 | + */ |
|
329 | + public function set_display_html_label_text($display_html_label_text) |
|
330 | + { |
|
331 | + $this->_display_html_label_text = filter_var($display_html_label_text, FILTER_VALIDATE_BOOLEAN); |
|
332 | + } |
|
333 | 333 | |
334 | 334 | |
335 | 335 |
@@ -119,12 +119,12 @@ discard block |
||
119 | 119 | $all_ints = true; |
120 | 120 | array_walk_recursive( |
121 | 121 | $this->_options, |
122 | - function($value,$key) use (&$all_ints){ |
|
122 | + function($value, $key) use (&$all_ints){ |
|
123 | 123 | //is this a top-level key? ignore it |
124 | - if(! is_array($value) |
|
124 | + if ( ! is_array($value) |
|
125 | 125 | && ! is_int($key) |
126 | 126 | && $key !== '' |
127 | - && $key !== null){ |
|
127 | + && $key !== null) { |
|
128 | 128 | $all_ints = false; |
129 | 129 | } |
130 | 130 | } |
@@ -178,7 +178,7 @@ discard block |
||
178 | 178 | $flat_array = array(); |
179 | 179 | if (EEH_Array::is_multi_dimensional_array($arr)) { |
180 | 180 | foreach ($arr as $sub_array) { |
181 | - foreach ((array)$sub_array as $key => $value) { |
|
181 | + foreach ((array) $sub_array as $key => $value) { |
|
182 | 182 | $flat_array[$key] = $value; |
183 | 183 | $this->_set_label_size($value); |
184 | 184 | } |
@@ -206,14 +206,14 @@ discard block |
||
206 | 206 | $desc = ''; |
207 | 207 | if ($this->_use_desc_in_label) { |
208 | 208 | $desc = $question_option->desc(); |
209 | - $desc = ! empty($desc) ? '<span class="ee-question-option-desc">' . $desc . '</span>' : ''; |
|
209 | + $desc = ! empty($desc) ? '<span class="ee-question-option-desc">'.$desc.'</span>' : ''; |
|
210 | 210 | } |
211 | 211 | $value = $question_option->value(); |
212 | 212 | // add value even if it's empty |
213 | 213 | $flat_array[$value] = $value; |
214 | 214 | // if both value and desc are not empty, then separate with a dash |
215 | 215 | if ( ! empty($value) && ! empty($desc)) { |
216 | - $flat_array[$value] .= ' - ' . $desc; |
|
216 | + $flat_array[$value] .= ' - '.$desc; |
|
217 | 217 | } else { |
218 | 218 | // otherwise, just add desc, since either or both of the vars is empty, and no dash is necessary |
219 | 219 | $flat_array[$value] .= $desc; |
@@ -301,7 +301,7 @@ discard block |
||
301 | 301 | $unnormalized_value_choices = array($unnormalized_value_choices); |
302 | 302 | } |
303 | 303 | $pretty_strings = array(); |
304 | - foreach ((array)$unnormalized_value_choices as $unnormalized_value_choice) { |
|
304 | + foreach ((array) $unnormalized_value_choices as $unnormalized_value_choice) { |
|
305 | 305 | if (isset($options[$unnormalized_value_choice])) { |
306 | 306 | $pretty_strings[] = $options[$unnormalized_value_choice]; |
307 | 307 | } else { |