@@ -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 | /** |
@@ -209,7 +209,7 @@ discard block |
||
209 | 209 | * constructor |
210 | 210 | * @param EE_Admin_Page $admin_page the calling admin_page_object |
211 | 211 | */ |
212 | - public function __construct( EE_Admin_Page $adminpage ) { |
|
212 | + public function __construct(EE_Admin_Page $adminpage) { |
|
213 | 213 | |
214 | 214 | $this->_adminpage_obj = $adminpage; |
215 | 215 | $this->_req_data = array_merge($_GET, $_POST); |
@@ -217,11 +217,11 @@ discard block |
||
217 | 217 | $this->_set_hooks_properties(); |
218 | 218 | |
219 | 219 | //first let's verify we're on the right page |
220 | - if ( !isset( $this->_req_data['page'] ) || ( isset( $this->_req_data['page'] ) && $this->_adminpage_obj->page_slug != $this->_req_data['page'] ) ) |
|
220 | + if ( ! isset($this->_req_data['page']) || (isset($this->_req_data['page']) && $this->_adminpage_obj->page_slug != $this->_req_data['page'])) |
|
221 | 221 | return; //get out nothing more to be done here. |
222 | 222 | |
223 | 223 | //allow for extends to modify properties |
224 | - if ( method_exists( $this, '_extend_properties' ) ) |
|
224 | + if (method_exists($this, '_extend_properties')) |
|
225 | 225 | $this->_extend_properties(); |
226 | 226 | |
227 | 227 | $this->_set_page_object(); |
@@ -229,9 +229,9 @@ discard block |
||
229 | 229 | $this->_load_custom_methods(); |
230 | 230 | $this->_load_routed_hooks(); |
231 | 231 | |
232 | - add_action( 'admin_enqueue_scripts', array($this, 'enqueue_scripts_styles' ) ); |
|
233 | - add_action( 'admin_enqueue_scripts', array($this, 'add_metaboxes'), 20 ); |
|
234 | - add_action( 'admin_enqueue_scripts', array($this, 'remove_metaboxes'), 15 ); |
|
232 | + add_action('admin_enqueue_scripts', array($this, 'enqueue_scripts_styles')); |
|
233 | + add_action('admin_enqueue_scripts', array($this, 'add_metaboxes'), 20); |
|
234 | + add_action('admin_enqueue_scripts', array($this, 'remove_metaboxes'), 15); |
|
235 | 235 | |
236 | 236 | $this->_ajax_hooks(); |
237 | 237 | |
@@ -272,15 +272,15 @@ discard block |
||
272 | 272 | */ |
273 | 273 | public function enqueue_scripts_styles() { |
274 | 274 | |
275 | - if ( !empty( $this->_scripts_styles ) ) { |
|
275 | + if ( ! empty($this->_scripts_styles)) { |
|
276 | 276 | //first let's do all the registrations |
277 | - if ( !isset($this->_scripts_styles['registers'] ) ) { |
|
277 | + if ( ! isset($this->_scripts_styles['registers'])) { |
|
278 | 278 | $msg[] = __('There is no "registers" index in the <code>$this->_scripts_styles</code> property.', 'event_espresso'); |
279 | - $msg[] = sprintf ( __('Make sure you read the phpdoc comments above the definition of the $_scripts_styles property in the <code>EE_Admin_Hooks</code> class and modify according in the %s child', 'event_espresso'), '<strong>' . $this->caller . '</strong>' ); |
|
280 | - throw new EE_Error( implode( '||', $msg ) ); |
|
279 | + $msg[] = sprintf(__('Make sure you read the phpdoc comments above the definition of the $_scripts_styles property in the <code>EE_Admin_Hooks</code> class and modify according in the %s child', 'event_espresso'), '<strong>'.$this->caller.'</strong>'); |
|
280 | + throw new EE_Error(implode('||', $msg)); |
|
281 | 281 | } |
282 | 282 | |
283 | - foreach( $this->_scripts_styles['registers'] as $ref => $details ) { |
|
283 | + foreach ($this->_scripts_styles['registers'] as $ref => $details) { |
|
284 | 284 | $defaults = array( |
285 | 285 | 'type' => 'js', |
286 | 286 | 'url' => '', |
@@ -289,48 +289,48 @@ discard block |
||
289 | 289 | 'footer' => TRUE |
290 | 290 | ); |
291 | 291 | $details = wp_parse_args($details, $defaults); |
292 | - extract( $details ); |
|
292 | + extract($details); |
|
293 | 293 | |
294 | 294 | //let's make sure that we set the 'registers' type if it's not set! We need it later to determine whhich enqueu we do |
295 | 295 | $this->_scripts_styles['registers'][$ref]['type'] = $type; |
296 | 296 | |
297 | 297 | //let's make sure we're not missing any REQUIRED parameters |
298 | - if ( empty($url) ) { |
|
299 | - $msg[] = sprintf( __('Missing the url for the requested %s', 'event_espresso'), $type == 'js' ? 'script' : 'stylesheet' ); |
|
300 | - $msg[] = sprintf( __('Doublecheck your <code>$this->_scripts_styles</code> array in %s and make sure that there is a "url" set for the %s ref', 'event_espresso'), '<strong>' . $this->caller . '</strong>', $ref ); |
|
301 | - throw new EE_Error( implode( '||', $msg ) ); |
|
298 | + if (empty($url)) { |
|
299 | + $msg[] = sprintf(__('Missing the url for the requested %s', 'event_espresso'), $type == 'js' ? 'script' : 'stylesheet'); |
|
300 | + $msg[] = sprintf(__('Doublecheck your <code>$this->_scripts_styles</code> array in %s and make sure that there is a "url" set for the %s ref', 'event_espresso'), '<strong>'.$this->caller.'</strong>', $ref); |
|
301 | + throw new EE_Error(implode('||', $msg)); |
|
302 | 302 | } |
303 | 303 | //made it here so let's do the appropriate registration |
304 | - $type == 'js' ? wp_register_script( $ref, $url, $depends, $version, $footer ) : wp_register_style( $ref, $url, $depends, $version ); |
|
304 | + $type == 'js' ? wp_register_script($ref, $url, $depends, $version, $footer) : wp_register_style($ref, $url, $depends, $version); |
|
305 | 305 | } |
306 | 306 | |
307 | 307 | //k now lets do the enqueues |
308 | - if( !isset( $this->_scripts_styles['enqueues'] ) ) |
|
309 | - return; //not sure if we should throw an error here or not. |
|
310 | - foreach( $this->_scripts_styles['enqueues'] as $ref => $routes ) { |
|
308 | + if ( ! isset($this->_scripts_styles['enqueues'])) |
|
309 | + return; //not sure if we should throw an error here or not. |
|
310 | + foreach ($this->_scripts_styles['enqueues'] as $ref => $routes) { |
|
311 | 311 | //make sure $routes is an array |
312 | 312 | $routes = (array) $routes; |
313 | 313 | |
314 | - if ( in_array($this->_current_route, $routes ) ) { |
|
314 | + if (in_array($this->_current_route, $routes)) { |
|
315 | 315 | $this->_scripts_styles['registers'][$ref]['type'] == 'js' ? wp_enqueue_script($ref) : wp_enqueue_style($ref); |
316 | 316 | //if we have a localization for the script let's do that too. |
317 | - if ( isset( $this->_scripts_styles['localize'][$ref] ) ) { |
|
318 | - foreach ( $this->_scripts_styles['localize'][$ref] as $object_name => $indexes ) { |
|
319 | - wp_localize_script($ref, $object_name , $this->_scripts_styles['localize'][$ref][$object_name] ); |
|
317 | + if (isset($this->_scripts_styles['localize'][$ref])) { |
|
318 | + foreach ($this->_scripts_styles['localize'][$ref] as $object_name => $indexes) { |
|
319 | + wp_localize_script($ref, $object_name, $this->_scripts_styles['localize'][$ref][$object_name]); |
|
320 | 320 | } |
321 | 321 | } |
322 | 322 | } |
323 | 323 | } |
324 | 324 | |
325 | 325 | //let's do the deregisters |
326 | - if ( !isset( $this->_scripts_styles['deregisters'] ) ) |
|
326 | + if ( ! isset($this->_scripts_styles['deregisters'])) |
|
327 | 327 | return; |
328 | - foreach ( $this->_scripts_styles['deregisters'] as $ref => $details ) { |
|
328 | + foreach ($this->_scripts_styles['deregisters'] as $ref => $details) { |
|
329 | 329 | $defaults = array( |
330 | 330 | 'type' => 'js' |
331 | 331 | ); |
332 | - $details = wp_parse_args( $details, $defaults ); |
|
333 | - extract( $details ); |
|
332 | + $details = wp_parse_args($details, $defaults); |
|
333 | + extract($details); |
|
334 | 334 | |
335 | 335 | $type == 'js' ? wp_deregister_script($ref) : wp_deregister_style($ref); |
336 | 336 | |
@@ -349,7 +349,7 @@ discard block |
||
349 | 349 | */ |
350 | 350 | private function _set_defaults() { |
351 | 351 | $this->_ajax_func = $this->_init_func = $this->_metaboxes = $this->_scripts = $this->_styles = $this->_wp_action_filters_priority = array(); |
352 | - $this->_current_route = isset( $_REQUEST['action'] ) ? $_REQUEST['action'] : 'default'; |
|
352 | + $this->_current_route = isset($_REQUEST['action']) ? $_REQUEST['action'] : 'default'; |
|
353 | 353 | $this->caller = get_class($this); |
354 | 354 | $this->_extend = stripos($this->caller, 'Extend') ? TRUE : FALSE; |
355 | 355 | } |
@@ -364,34 +364,34 @@ discard block |
||
364 | 364 | */ |
365 | 365 | protected function _set_page_object() { |
366 | 366 | //first make sure $this->_name is set |
367 | - if ( empty( $this->_name ) ) { |
|
367 | + if (empty($this->_name)) { |
|
368 | 368 | $msg[] = __('We can\'t load the page object', 'event_espresso'); |
369 | - $msg[] = sprintf( __("This is because the %s child class has not set the '_name' property", 'event_espresso'), $this->caller ); |
|
370 | - throw new EE_Error( implode( '||', $msg ) ); |
|
369 | + $msg[] = sprintf(__("This is because the %s child class has not set the '_name' property", 'event_espresso'), $this->caller); |
|
370 | + throw new EE_Error(implode('||', $msg)); |
|
371 | 371 | } |
372 | 372 | |
373 | - $ref = str_replace('_' , ' ', $this->_name); //take the_message -> the message |
|
374 | - $ref = str_replace(' ', '_', ucwords($ref) ) . '_Admin_Page'; //take the message -> The_Message |
|
373 | + $ref = str_replace('_', ' ', $this->_name); //take the_message -> the message |
|
374 | + $ref = str_replace(' ', '_', ucwords($ref)).'_Admin_Page'; //take the message -> The_Message |
|
375 | 375 | |
376 | 376 | //first default file (if exists) |
377 | - $decaf_file = EE_ADMIN_PAGES . $this->_name . DS . $ref . '.core.php'; |
|
378 | - if ( is_readable( $decaf_file ) ) |
|
379 | - require_once( $decaf_file ); |
|
377 | + $decaf_file = EE_ADMIN_PAGES.$this->_name.DS.$ref.'.core.php'; |
|
378 | + if (is_readable($decaf_file)) |
|
379 | + require_once($decaf_file); |
|
380 | 380 | |
381 | 381 | //now we have to do require for extended file (if needed) |
382 | - if ( $this->_extend ) { |
|
383 | - require_once( EE_CORE_CAF_ADMIN_EXTEND . $this->_name . DS . 'Extend_' . $ref . '.core.php' ); |
|
382 | + if ($this->_extend) { |
|
383 | + require_once(EE_CORE_CAF_ADMIN_EXTEND.$this->_name.DS.'Extend_'.$ref.'.core.php'); |
|
384 | 384 | } |
385 | 385 | |
386 | 386 | |
387 | 387 | //if we've got an extended class we use that! |
388 | - $ref = $this->_extend ? 'Extend_' . $ref : $ref; |
|
388 | + $ref = $this->_extend ? 'Extend_'.$ref : $ref; |
|
389 | 389 | |
390 | 390 | //let's make sure the class exists |
391 | - if ( !class_exists( $ref ) ) { |
|
391 | + if ( ! class_exists($ref)) { |
|
392 | 392 | $msg[] = __('We can\'t load the page object', 'event_espresso'); |
393 | - $msg[] = sprintf( __('The class name that was given is %s. Check the spelling and make sure its correct, also there needs to be an autoloader setup for the class', 'event_espresso'), $ref ); |
|
394 | - throw new EE_Error( implode( '||', $msg ) ); |
|
393 | + $msg[] = sprintf(__('The class name that was given is %s. Check the spelling and make sure its correct, also there needs to be an autoloader setup for the class', 'event_espresso'), $ref); |
|
394 | + throw new EE_Error(implode('||', $msg)); |
|
395 | 395 | } |
396 | 396 | |
397 | 397 | $a = new ReflectionClass($ref); |
@@ -416,27 +416,27 @@ discard block |
||
416 | 416 | $method_callback = $this->_current_route == 'default' ? 'default_callback' : $this->_current_route; |
417 | 417 | |
418 | 418 | //these run before the Admin_Page route executes. |
419 | - if ( method_exists( $this, $method_callback ) ) { |
|
420 | - call_user_func( array( $this, $method_callback) ); |
|
419 | + if (method_exists($this, $method_callback)) { |
|
420 | + call_user_func(array($this, $method_callback)); |
|
421 | 421 | } |
422 | 422 | |
423 | 423 | |
424 | 424 | //these run via the _redirect_after_action method in EE_Admin_Page which usually happens after non_UI methods in EE_Admin_Page classes. There are two redirect actions, the first fires before $query_args might be manipulated by "save and close" actions and the seond fires right before the actual redirect happens. |
425 | 425 | //first the actions |
426 | 426 | //note that these action hooks will have the $query_args value available. |
427 | - $admin_class_name = get_class( $this->_adminpage_obj ); |
|
427 | + $admin_class_name = get_class($this->_adminpage_obj); |
|
428 | 428 | |
429 | - if ( method_exists( $this, '_redirect_action_early_' . $this->_current_route ) ) { |
|
430 | - add_action( 'AHEE__' . $admin_class_name . '___redirect_after_action__before_redirect_modification_' . $this->_current_route, array( $this, '_redirect_action_early_' . $this->_current_route ), 10 ); |
|
429 | + if (method_exists($this, '_redirect_action_early_'.$this->_current_route)) { |
|
430 | + add_action('AHEE__'.$admin_class_name.'___redirect_after_action__before_redirect_modification_'.$this->_current_route, array($this, '_redirect_action_early_'.$this->_current_route), 10); |
|
431 | 431 | } |
432 | 432 | |
433 | - if ( method_exists( $this, '_redirect_action_' . $this->_current_route ) ) { |
|
434 | - add_action( 'AHEE_redirect_' . $admin_class_name . $this->_current_route, array( $this, '_redirect_action_' . $this->_current_route ), 10 ); |
|
433 | + if (method_exists($this, '_redirect_action_'.$this->_current_route)) { |
|
434 | + add_action('AHEE_redirect_'.$admin_class_name.$this->_current_route, array($this, '_redirect_action_'.$this->_current_route), 10); |
|
435 | 435 | } |
436 | 436 | |
437 | 437 | //let's hook into the _redirect itself and allow for changing where the user goes after redirect. This will have $query_args and $redirect_url available. |
438 | - if ( method_exists( $this, '_redirect_filter_' . $this->_current_route ) ) { |
|
439 | - add_filter( 'FHEE_redirect_' . $admin_class_name . $this->_current_route, array( $this, '_redirect_filter_' . $this->_current_route ), 10, 2 ); |
|
438 | + if (method_exists($this, '_redirect_filter_'.$this->_current_route)) { |
|
439 | + add_filter('FHEE_redirect_'.$admin_class_name.$this->_current_route, array($this, '_redirect_filter_'.$this->_current_route), 10, 2); |
|
440 | 440 | } |
441 | 441 | |
442 | 442 | } |
@@ -459,12 +459,12 @@ discard block |
||
459 | 459 | 'argnum' => 1, |
460 | 460 | 'priority' => 10 |
461 | 461 | ), |
462 | - 'FHEE_list_table_views_' . $this->_adminpage_obj->page_slug . '_' . $this->_current_route => array( |
|
462 | + 'FHEE_list_table_views_'.$this->_adminpage_obj->page_slug.'_'.$this->_current_route => array( |
|
463 | 463 | 'type' => 'filter', |
464 | 464 | 'argnum' => 1, |
465 | 465 | 'priority' => 10 |
466 | 466 | ), |
467 | - 'FHEE_list_table_views_' . $this->_adminpage_obj->page_slug => array( |
|
467 | + 'FHEE_list_table_views_'.$this->_adminpage_obj->page_slug => array( |
|
468 | 468 | 'type' => 'filter', |
469 | 469 | 'argnum' => 1, |
470 | 470 | 'priority' => 10 |
@@ -483,14 +483,14 @@ discard block |
||
483 | 483 | |
484 | 484 | |
485 | 485 | |
486 | - foreach ( $hook_filter_array as $hook => $args ) { |
|
487 | - if ( method_exists( $this, $this->_current_route . '_' . $hook ) ) { |
|
488 | - if ( isset( $this->_wp_action_filters_priority[$hook] ) ) |
|
486 | + foreach ($hook_filter_array as $hook => $args) { |
|
487 | + if (method_exists($this, $this->_current_route.'_'.$hook)) { |
|
488 | + if (isset($this->_wp_action_filters_priority[$hook])) |
|
489 | 489 | $args['priority'] = $this->_wp_action_filters_priority[$hook]; |
490 | - if ( $args['type'] == 'action' ) |
|
491 | - add_action( $hook, array( $this, $this->_current_route . '_' . $hook ), $args['priority'], $args['argnum'] ); |
|
490 | + if ($args['type'] == 'action') |
|
491 | + add_action($hook, array($this, $this->_current_route.'_'.$hook), $args['priority'], $args['argnum']); |
|
492 | 492 | else |
493 | - add_filter( $hook, array( $this, $this->_current_route . '_' . $hook ), $args['priority'], $args['argnum'] ); |
|
493 | + add_filter($hook, array($this, $this->_current_route.'_'.$hook), $args['priority'], $args['argnum']); |
|
494 | 494 | } |
495 | 495 | } |
496 | 496 | |
@@ -503,18 +503,18 @@ discard block |
||
503 | 503 | */ |
504 | 504 | private function _ajax_hooks() { |
505 | 505 | |
506 | - if ( empty( $this->_ajax_func) ) |
|
506 | + if (empty($this->_ajax_func)) |
|
507 | 507 | return; //get out there's nothing to take care of. |
508 | 508 | |
509 | - foreach ( $this->_ajax_func as $action => $method ) { |
|
509 | + foreach ($this->_ajax_func as $action => $method) { |
|
510 | 510 | //make sure method exists |
511 | - if ( !method_exists($this, $method) ) { |
|
512 | - $msg[] = __('There is no corresponding method for the hook labeled in the _ajax_func array', 'event_espresso') . '<br />'; |
|
513 | - $msg[] = sprintf( __('The method name given in the array is %s, check the spelling and make sure it exists in the %s class', 'event_espresso' ), $method, $this->caller ); |
|
514 | - throw new EE_Error( implode('||', $msg ) ); |
|
511 | + if ( ! method_exists($this, $method)) { |
|
512 | + $msg[] = __('There is no corresponding method for the hook labeled in the _ajax_func array', 'event_espresso').'<br />'; |
|
513 | + $msg[] = sprintf(__('The method name given in the array is %s, check the spelling and make sure it exists in the %s class', 'event_espresso'), $method, $this->caller); |
|
514 | + throw new EE_Error(implode('||', $msg)); |
|
515 | 515 | } |
516 | 516 | |
517 | - add_action('wp_ajax_' . $action, array( $this, $method ) ); |
|
517 | + add_action('wp_ajax_'.$action, array($this, $method)); |
|
518 | 518 | } |
519 | 519 | |
520 | 520 | } |
@@ -527,21 +527,21 @@ discard block |
||
527 | 527 | * @return void |
528 | 528 | */ |
529 | 529 | protected function _init_hooks() { |
530 | - if ( empty( $this->_init_func) ) |
|
530 | + if (empty($this->_init_func)) |
|
531 | 531 | return; //get out there's nothing to take care of. |
532 | 532 | |
533 | 533 | //We need to determine what page_route we are on! |
534 | - $current_route = isset ( $_REQUEST['action'] ) ? $_REQUEST['action'] : 'default'; |
|
534 | + $current_route = isset ($_REQUEST['action']) ? $_REQUEST['action'] : 'default'; |
|
535 | 535 | |
536 | - foreach ( $this->_init_func as $route => $method ) { |
|
536 | + foreach ($this->_init_func as $route => $method) { |
|
537 | 537 | //make sure method exists |
538 | - if ( !method_exists($this, $method) ) { |
|
539 | - $msg[] = __('There is no corresponding method for the hook labeled in the _init_func array', 'event_espresso') . '<br />'; |
|
540 | - $msg[] = sprintf( __('The method name given in the array is %s, check the spelling and make sure it exists in the %s class', 'event_espresso' ), $method, $this->caller ); |
|
541 | - throw new EE_Error( implode('||', $msg ) ); |
|
538 | + if ( ! method_exists($this, $method)) { |
|
539 | + $msg[] = __('There is no corresponding method for the hook labeled in the _init_func array', 'event_espresso').'<br />'; |
|
540 | + $msg[] = sprintf(__('The method name given in the array is %s, check the spelling and make sure it exists in the %s class', 'event_espresso'), $method, $this->caller); |
|
541 | + throw new EE_Error(implode('||', $msg)); |
|
542 | 542 | } |
543 | - if ( $route == $this->_current_route ) |
|
544 | - add_action('admin_init', array( $this, $method ) ); |
|
543 | + if ($route == $this->_current_route) |
|
544 | + add_action('admin_init', array($this, $method)); |
|
545 | 545 | } |
546 | 546 | |
547 | 547 | } |
@@ -556,28 +556,28 @@ discard block |
||
556 | 556 | * @return void |
557 | 557 | */ |
558 | 558 | public function add_metaboxes() { |
559 | - if ( empty( $this->_metaboxes ) ) |
|
559 | + if (empty($this->_metaboxes)) |
|
560 | 560 | return; //get out we don't have any metaboxes to set for this connection |
561 | 561 | |
562 | - $this->_handle_metabox_array( $this->_metaboxes ); |
|
562 | + $this->_handle_metabox_array($this->_metaboxes); |
|
563 | 563 | |
564 | 564 | } |
565 | 565 | |
566 | 566 | |
567 | 567 | |
568 | - private function _handle_metabox_array( $boxes, $add = TRUE ) { |
|
568 | + private function _handle_metabox_array($boxes, $add = TRUE) { |
|
569 | 569 | |
570 | - foreach ( $boxes as $box ) { |
|
571 | - if ( !isset($box['page_route']) ) |
|
570 | + foreach ($boxes as $box) { |
|
571 | + if ( ! isset($box['page_route'])) |
|
572 | 572 | continue; //we dont' have a valid array |
573 | 573 | |
574 | 574 | //let's make sure $box['page_route'] is an array so the "foreach" will work. |
575 | 575 | $box['page_route'] = (array) $box['page_route']; |
576 | 576 | |
577 | - foreach ( $box['page_route'] as $route ) { |
|
578 | - if ( $route != $this->_current_route ) |
|
577 | + foreach ($box['page_route'] as $route) { |
|
578 | + if ($route != $this->_current_route) |
|
579 | 579 | continue; //get out we only add metaboxes for set route. |
580 | - if ( $add ) |
|
580 | + if ($add) |
|
581 | 581 | $this->_add_metabox($box); |
582 | 582 | else |
583 | 583 | $this->_remove_metabox($box); |
@@ -595,10 +595,10 @@ discard block |
||
595 | 595 | */ |
596 | 596 | public function remove_metaboxes() { |
597 | 597 | |
598 | - if ( empty( $this->_remove_metaboxes ) ) |
|
598 | + if (empty($this->_remove_metaboxes)) |
|
599 | 599 | return; //get out there are no metaboxes to remove |
600 | 600 | |
601 | - $this->_handle_metabox_array( $this->_remove_metaboxes, FALSE ); |
|
601 | + $this->_handle_metabox_array($this->_remove_metaboxes, FALSE); |
|
602 | 602 | } |
603 | 603 | |
604 | 604 | |
@@ -608,53 +608,53 @@ discard block |
||
608 | 608 | * @access private |
609 | 609 | * @param array $args an array of args that have been set for this metabox by the child class |
610 | 610 | */ |
611 | - private function _add_metabox( $args ) { |
|
611 | + private function _add_metabox($args) { |
|
612 | 612 | $current_screen = get_current_screen(); |
613 | - $screen_id = is_object( $current_screen ) ? $current_screen->id : NULL; |
|
614 | - $func = isset( $args['func'] ) ? $args['func'] : 'some_invalid_callback'; |
|
613 | + $screen_id = is_object($current_screen) ? $current_screen->id : NULL; |
|
614 | + $func = isset($args['func']) ? $args['func'] : 'some_invalid_callback'; |
|
615 | 615 | |
616 | 616 | //set defaults |
617 | 617 | $defaults = array( |
618 | 618 | 'func' => $func, |
619 | - 'id' => $this->caller . '_' . $func . '_metabox', |
|
619 | + 'id' => $this->caller.'_'.$func.'_metabox', |
|
620 | 620 | 'priority' => 'default', |
621 | 621 | 'label' => $this->caller, |
622 | 622 | 'context' => 'advanced', |
623 | 623 | 'callback_args' => array(), |
624 | - 'page' => isset( $args['page'] ) ? $args['page'] : $screen_id |
|
624 | + 'page' => isset($args['page']) ? $args['page'] : $screen_id |
|
625 | 625 | ); |
626 | 626 | |
627 | - $args = wp_parse_args( $args, $defaults ); |
|
627 | + $args = wp_parse_args($args, $defaults); |
|
628 | 628 | extract($args); |
629 | 629 | |
630 | 630 | |
631 | 631 | //make sure method exists |
632 | - if ( !method_exists($this, $func) ) { |
|
633 | - $msg[] = __('There is no corresponding method to display the metabox content', 'event_espresso') . '<br />'; |
|
634 | - $msg[] = sprintf( __('The method name given in the array is %s, check the spelling and make sure it exists in the %s class', 'event_espresso' ), $func, $this->caller ); |
|
635 | - throw new EE_Error( implode('||', $msg ) ); |
|
632 | + if ( ! method_exists($this, $func)) { |
|
633 | + $msg[] = __('There is no corresponding method to display the metabox content', 'event_espresso').'<br />'; |
|
634 | + $msg[] = sprintf(__('The method name given in the array is %s, check the spelling and make sure it exists in the %s class', 'event_espresso'), $func, $this->caller); |
|
635 | + throw new EE_Error(implode('||', $msg)); |
|
636 | 636 | } |
637 | 637 | |
638 | 638 | //everything checks out so lets add the metabox |
639 | - add_meta_box( $id, $label, array( $this, $func ), $page, $context, $priority, $callback_args); |
|
639 | + add_meta_box($id, $label, array($this, $func), $page, $context, $priority, $callback_args); |
|
640 | 640 | } |
641 | 641 | |
642 | 642 | |
643 | 643 | |
644 | - private function _remove_metabox( $args ) { |
|
644 | + private function _remove_metabox($args) { |
|
645 | 645 | $current_screen = get_current_screen(); |
646 | - $screen_id = is_object( $current_screen ) ? $current_screen->id : NULL; |
|
647 | - $func = isset( $args['func'] ) ? $args['func'] : 'some_invalid_callback'; |
|
646 | + $screen_id = is_object($current_screen) ? $current_screen->id : NULL; |
|
647 | + $func = isset($args['func']) ? $args['func'] : 'some_invalid_callback'; |
|
648 | 648 | |
649 | 649 | //set defaults |
650 | 650 | $defaults = array( |
651 | - 'id' => isset( $args['id'] ) ? $args['id'] : $this->_current_route . '_' . $this->caller . '_' . $func . '_metabox', |
|
651 | + 'id' => isset($args['id']) ? $args['id'] : $this->_current_route.'_'.$this->caller.'_'.$func.'_metabox', |
|
652 | 652 | 'context' => 'default', |
653 | - 'screen' => isset( $args['screen'] ) ? $args['screen'] : $screen_id |
|
653 | + 'screen' => isset($args['screen']) ? $args['screen'] : $screen_id |
|
654 | 654 | ); |
655 | 655 | |
656 | - $args = wp_parse_args( $args, $defaults ); |
|
657 | - extract( $args ); |
|
656 | + $args = wp_parse_args($args, $defaults); |
|
657 | + extract($args); |
|
658 | 658 | |
659 | 659 | //everything checks out so lets remove the box! |
660 | 660 | remove_meta_box($id, $screen, $context); |
@@ -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_Processor |
@@ -50,10 +50,10 @@ discard block |
||
50 | 50 | * @param array $registration_query_params |
51 | 51 | *@return EE_Transaction_Processor instance |
52 | 52 | */ |
53 | - public static function instance( $registration_query_params = array() ) { |
|
53 | + public static function instance($registration_query_params = array()) { |
|
54 | 54 | // check if class object is instantiated |
55 | - if ( ! self::$_instance instanceof EE_Transaction_Processor ) { |
|
56 | - self::$_instance = new self( $registration_query_params ); |
|
55 | + if ( ! self::$_instance instanceof EE_Transaction_Processor) { |
|
56 | + self::$_instance = new self($registration_query_params); |
|
57 | 57 | } |
58 | 58 | return self::$_instance; |
59 | 59 | } |
@@ -64,9 +64,9 @@ discard block |
||
64 | 64 | * @param array $registration_query_params |
65 | 65 | * @return EE_Transaction_Processor |
66 | 66 | */ |
67 | - private function __construct( $registration_query_params = array() ) { |
|
67 | + private function __construct($registration_query_params = array()) { |
|
68 | 68 | // make sure some query params are set for retrieving registrations |
69 | - $this->_set_registration_query_params( $registration_query_params ); |
|
69 | + $this->_set_registration_query_params($registration_query_params); |
|
70 | 70 | } |
71 | 71 | |
72 | 72 | |
@@ -75,8 +75,8 @@ discard block |
||
75 | 75 | * @access private |
76 | 76 | * @param array $registration_query_params |
77 | 77 | */ |
78 | - private function _set_registration_query_params( $registration_query_params ) { |
|
79 | - $this->_registration_query_params = ! empty( $registration_query_params ) ? $registration_query_params : array( 'order_by' => array( 'REG_count' => 'ASC' )); |
|
78 | + private function _set_registration_query_params($registration_query_params) { |
|
79 | + $this->_registration_query_params = ! empty($registration_query_params) ? $registration_query_params : array('order_by' => array('REG_count' => 'ASC')); |
|
80 | 80 | } |
81 | 81 | |
82 | 82 | |
@@ -93,9 +93,9 @@ discard block |
||
93 | 93 | /** |
94 | 94 | * @param string $old_txn_status |
95 | 95 | */ |
96 | - public function set_old_txn_status( $old_txn_status ) { |
|
96 | + public function set_old_txn_status($old_txn_status) { |
|
97 | 97 | // only set the first time |
98 | - if ( $this->_old_txn_status === null ) { |
|
98 | + if ($this->_old_txn_status === null) { |
|
99 | 99 | $this->_old_txn_status = $old_txn_status; |
100 | 100 | } |
101 | 101 | } |
@@ -114,7 +114,7 @@ discard block |
||
114 | 114 | /** |
115 | 115 | * @param string $new_txn_status |
116 | 116 | */ |
117 | - public function set_new_txn_status( $new_txn_status ) { |
|
117 | + public function set_new_txn_status($new_txn_status) { |
|
118 | 118 | $this->_new_txn_status = $new_txn_status; |
119 | 119 | } |
120 | 120 | |
@@ -145,17 +145,17 @@ discard block |
||
145 | 145 | * @param bool $check_all |
146 | 146 | * @return boolean | int |
147 | 147 | */ |
148 | - private function _reg_steps_completed( EE_Transaction $transaction, $reg_step_slug = '', $check_all = TRUE ) { |
|
148 | + private function _reg_steps_completed(EE_Transaction $transaction, $reg_step_slug = '', $check_all = TRUE) { |
|
149 | 149 | $reg_steps = $transaction->reg_steps(); |
150 | - if ( ! is_array( $reg_steps ) || empty( $reg_steps )) { |
|
150 | + if ( ! is_array($reg_steps) || empty($reg_steps)) { |
|
151 | 151 | return false; |
152 | 152 | } |
153 | 153 | // loop thru reg steps array) |
154 | - foreach ( $reg_steps as $slug => $reg_step_completed ) { |
|
154 | + foreach ($reg_steps as $slug => $reg_step_completed) { |
|
155 | 155 | // if NOT checking ALL steps (only checking one step) |
156 | - if ( ! $check_all ) { |
|
156 | + if ( ! $check_all) { |
|
157 | 157 | // and this is the one |
158 | - if ( $slug == $reg_step_slug ) { |
|
158 | + if ($slug == $reg_step_slug) { |
|
159 | 159 | return $reg_step_completed; |
160 | 160 | } else { |
161 | 161 | // skip to next reg step in loop |
@@ -163,9 +163,9 @@ discard block |
||
163 | 163 | } |
164 | 164 | } |
165 | 165 | // if any reg step is NOT completed (ignoring any specific steps), then just leave |
166 | - if ( $reg_step_completed !== true && $slug != $reg_step_slug ) { |
|
166 | + if ($reg_step_completed !== true && $slug != $reg_step_slug) { |
|
167 | 167 | return false; |
168 | - } else if ( $slug == $reg_step_slug ) { |
|
168 | + } else if ($slug == $reg_step_slug) { |
|
169 | 169 | // if we reach this point, then we are testing either: |
170 | 170 | // all_reg_steps_completed_except() or |
171 | 171 | // all_reg_steps_completed_except_final_step(), |
@@ -190,8 +190,8 @@ discard block |
||
190 | 190 | * @param EE_Transaction $transaction |
191 | 191 | * @return boolean |
192 | 192 | */ |
193 | - public function all_reg_steps_completed( EE_Transaction $transaction ) { |
|
194 | - return $this->_reg_steps_completed( $transaction ); |
|
193 | + public function all_reg_steps_completed(EE_Transaction $transaction) { |
|
194 | + return $this->_reg_steps_completed($transaction); |
|
195 | 195 | } |
196 | 196 | |
197 | 197 | |
@@ -208,8 +208,8 @@ discard block |
||
208 | 208 | * @param string $exception |
209 | 209 | * @return boolean |
210 | 210 | */ |
211 | - public function all_reg_steps_completed_except( EE_Transaction $transaction, $exception = '' ) { |
|
212 | - return $this->_reg_steps_completed( $transaction, $exception ); |
|
211 | + public function all_reg_steps_completed_except(EE_Transaction $transaction, $exception = '') { |
|
212 | + return $this->_reg_steps_completed($transaction, $exception); |
|
213 | 213 | } |
214 | 214 | |
215 | 215 | |
@@ -225,8 +225,8 @@ discard block |
||
225 | 225 | * @param EE_Transaction $transaction |
226 | 226 | * @return boolean |
227 | 227 | */ |
228 | - public function all_reg_steps_completed_except_final_step( EE_Transaction $transaction ) { |
|
229 | - return $this->_reg_steps_completed( $transaction, 'finalize_registration' ); |
|
228 | + public function all_reg_steps_completed_except_final_step(EE_Transaction $transaction) { |
|
229 | + return $this->_reg_steps_completed($transaction, 'finalize_registration'); |
|
230 | 230 | } |
231 | 231 | |
232 | 232 | |
@@ -243,8 +243,8 @@ discard block |
||
243 | 243 | * @param string $reg_step_slug |
244 | 244 | * @return boolean | int |
245 | 245 | */ |
246 | - public function reg_step_completed( EE_Transaction $transaction, $reg_step_slug ) { |
|
247 | - return $this->_reg_steps_completed( $transaction, $reg_step_slug, FALSE ); |
|
246 | + public function reg_step_completed(EE_Transaction $transaction, $reg_step_slug) { |
|
247 | + return $this->_reg_steps_completed($transaction, $reg_step_slug, FALSE); |
|
248 | 248 | } |
249 | 249 | |
250 | 250 | |
@@ -260,8 +260,8 @@ discard block |
||
260 | 260 | * @param EE_Transaction $transaction |
261 | 261 | * @return boolean | int |
262 | 262 | */ |
263 | - public function final_reg_step_completed( EE_Transaction $transaction ) { |
|
264 | - return $this->_reg_steps_completed( $transaction, 'finalize_registration', FALSE ); |
|
263 | + public function final_reg_step_completed(EE_Transaction $transaction) { |
|
264 | + return $this->_reg_steps_completed($transaction, 'finalize_registration', FALSE); |
|
265 | 265 | } |
266 | 266 | |
267 | 267 | |
@@ -275,9 +275,9 @@ discard block |
||
275 | 275 | * @param string $reg_step_slug |
276 | 276 | * @return boolean |
277 | 277 | */ |
278 | - public function set_reg_step_initiated( EE_Transaction $transaction, $reg_step_slug ) { |
|
278 | + public function set_reg_step_initiated(EE_Transaction $transaction, $reg_step_slug) { |
|
279 | 279 | $current_time = time(); |
280 | - return $this->_set_reg_step_completed_status( $transaction, $reg_step_slug, $current_time ); |
|
280 | + return $this->_set_reg_step_completed_status($transaction, $reg_step_slug, $current_time); |
|
281 | 281 | } |
282 | 282 | |
283 | 283 | |
@@ -291,8 +291,8 @@ discard block |
||
291 | 291 | * @param string $reg_step_slug |
292 | 292 | * @return boolean |
293 | 293 | */ |
294 | - public function set_reg_step_completed( EE_Transaction $transaction, $reg_step_slug ) { |
|
295 | - return $this->_set_reg_step_completed_status( $transaction, $reg_step_slug, TRUE ); |
|
294 | + public function set_reg_step_completed(EE_Transaction $transaction, $reg_step_slug) { |
|
295 | + return $this->_set_reg_step_completed_status($transaction, $reg_step_slug, TRUE); |
|
296 | 296 | } |
297 | 297 | |
298 | 298 | |
@@ -306,8 +306,8 @@ discard block |
||
306 | 306 | * @param string $reg_step_slug |
307 | 307 | * @return boolean |
308 | 308 | */ |
309 | - public function set_reg_step_not_completed( EE_Transaction $transaction, $reg_step_slug ) { |
|
310 | - return $this->_set_reg_step_completed_status( $transaction, $reg_step_slug, FALSE ); |
|
309 | + public function set_reg_step_not_completed(EE_Transaction $transaction, $reg_step_slug) { |
|
310 | + return $this->_set_reg_step_completed_status($transaction, $reg_step_slug, FALSE); |
|
311 | 311 | } |
312 | 312 | |
313 | 313 | |
@@ -323,36 +323,36 @@ discard block |
||
323 | 323 | * @param boolean | int $status |
324 | 324 | * @return boolean |
325 | 325 | */ |
326 | - private function _set_reg_step_completed_status( EE_Transaction $transaction, $reg_step_slug, $status ) { |
|
326 | + private function _set_reg_step_completed_status(EE_Transaction $transaction, $reg_step_slug, $status) { |
|
327 | 327 | // validate status |
328 | - $status = is_bool( $status ) || is_numeric( $status ) ? $status : false; |
|
328 | + $status = is_bool($status) || is_numeric($status) ? $status : false; |
|
329 | 329 | // get reg steps array |
330 | 330 | $txn_reg_steps = $transaction->reg_steps(); |
331 | 331 | // if reg step does NOT exist |
332 | - if ( ! isset( $txn_reg_steps[ $reg_step_slug ] )) { |
|
332 | + if ( ! isset($txn_reg_steps[$reg_step_slug])) { |
|
333 | 333 | return false; |
334 | 334 | } |
335 | 335 | // if we're trying to complete a step that is already completed |
336 | - if ( $txn_reg_steps[ $reg_step_slug ] === true ) { |
|
336 | + if ($txn_reg_steps[$reg_step_slug] === true) { |
|
337 | 337 | return true; |
338 | 338 | } |
339 | 339 | // if we're trying to complete a step that hasn't even started |
340 | - if ( $status === true && $txn_reg_steps[ $reg_step_slug ] === false ) { |
|
340 | + if ($status === true && $txn_reg_steps[$reg_step_slug] === false) { |
|
341 | 341 | return false; |
342 | 342 | } |
343 | 343 | // if current status value matches the incoming value (no change) |
344 | - if ( $txn_reg_steps[ $reg_step_slug ] === $status ) { |
|
344 | + if ($txn_reg_steps[$reg_step_slug] === $status) { |
|
345 | 345 | // this will happen in cases where multiple AJAX requests occur during the same step |
346 | 346 | return true; |
347 | 347 | } |
348 | 348 | // if we're trying to set a start time |
349 | - if ( is_numeric( $status ) && is_numeric( $txn_reg_steps[ $reg_step_slug ] )) { |
|
349 | + if (is_numeric($status) && is_numeric($txn_reg_steps[$reg_step_slug])) { |
|
350 | 350 | // skip the update below, but don't return FALSE so that errors won't be displayed |
351 | 351 | return true; |
352 | 352 | } |
353 | 353 | // update completed status |
354 | - $txn_reg_steps[ $reg_step_slug ] = $status; |
|
355 | - $transaction->set_reg_steps( $txn_reg_steps ); |
|
354 | + $txn_reg_steps[$reg_step_slug] = $status; |
|
355 | + $transaction->set_reg_steps($txn_reg_steps); |
|
356 | 356 | $transaction->save(); |
357 | 357 | // DEBUG LOG |
358 | 358 | //$this->log( |
@@ -378,11 +378,11 @@ discard block |
||
378 | 378 | * @param string $reg_step_slug |
379 | 379 | * @return void |
380 | 380 | */ |
381 | - public function remove_reg_step( EE_Transaction $transaction, $reg_step_slug ) { |
|
381 | + public function remove_reg_step(EE_Transaction $transaction, $reg_step_slug) { |
|
382 | 382 | // get reg steps array |
383 | 383 | $txn_reg_steps = $transaction->reg_steps(); |
384 | - unset( $txn_reg_steps[ $reg_step_slug ] ); |
|
385 | - $transaction->set_reg_steps( $txn_reg_steps ); |
|
384 | + unset($txn_reg_steps[$reg_step_slug]); |
|
385 | + $transaction->set_reg_steps($txn_reg_steps); |
|
386 | 386 | } |
387 | 387 | |
388 | 388 | |
@@ -396,14 +396,14 @@ discard block |
||
396 | 396 | * @param EE_Transaction $transaction |
397 | 397 | * @return boolean |
398 | 398 | */ |
399 | - public function toggle_failed_transaction_status( EE_Transaction $transaction ) { |
|
399 | + public function toggle_failed_transaction_status(EE_Transaction $transaction) { |
|
400 | 400 | // set incoming TXN_Status |
401 | - $this->set_old_txn_status( $transaction->status_ID() ); |
|
401 | + $this->set_old_txn_status($transaction->status_ID()); |
|
402 | 402 | // if TXN status is still set as "failed"... |
403 | - if ( $transaction->status_ID() == EEM_Transaction::failed_status_code ) { |
|
403 | + if ($transaction->status_ID() == EEM_Transaction::failed_status_code) { |
|
404 | 404 | // set incoming TXN_Status |
405 | - $this->set_new_txn_status( EEM_Transaction::abandoned_status_code ); |
|
406 | - $transaction->set_status( EEM_Transaction::abandoned_status_code ); |
|
405 | + $this->set_new_txn_status(EEM_Transaction::abandoned_status_code); |
|
406 | + $transaction->set_status(EEM_Transaction::abandoned_status_code); |
|
407 | 407 | return TRUE; |
408 | 408 | } |
409 | 409 | return FALSE; |
@@ -419,20 +419,20 @@ discard block |
||
419 | 419 | * @param EE_Transaction $transaction |
420 | 420 | * @return boolean |
421 | 421 | */ |
422 | - public function toggle_abandoned_transaction_status( EE_Transaction $transaction ) { |
|
422 | + public function toggle_abandoned_transaction_status(EE_Transaction $transaction) { |
|
423 | 423 | // set incoming TXN_Status |
424 | - $this->set_old_txn_status( $transaction->status_ID() ); |
|
424 | + $this->set_old_txn_status($transaction->status_ID()); |
|
425 | 425 | // if TXN status has not been updated already due to a payment, and is still set as "failed" or "abandoned"... |
426 | - if ( $transaction->status_ID() == EEM_Transaction::failed_status_code || $transaction->status_ID() == EEM_Transaction::abandoned_status_code ) { |
|
427 | - $this->set_new_txn_status( EEM_Transaction::incomplete_status_code ); |
|
426 | + if ($transaction->status_ID() == EEM_Transaction::failed_status_code || $transaction->status_ID() == EEM_Transaction::abandoned_status_code) { |
|
427 | + $this->set_new_txn_status(EEM_Transaction::incomplete_status_code); |
|
428 | 428 | // if a contact record for the primary registrant has been created |
429 | - if ( $transaction->primary_registration() instanceof EE_Registration && $transaction->primary_registration()->attendee() instanceof EE_Attendee ) { |
|
430 | - $transaction->set_status( EEM_Transaction::incomplete_status_code ); |
|
431 | - $this->set_new_txn_status( EEM_Transaction::incomplete_status_code ); |
|
429 | + if ($transaction->primary_registration() instanceof EE_Registration && $transaction->primary_registration()->attendee() instanceof EE_Attendee) { |
|
430 | + $transaction->set_status(EEM_Transaction::incomplete_status_code); |
|
431 | + $this->set_new_txn_status(EEM_Transaction::incomplete_status_code); |
|
432 | 432 | } else { |
433 | 433 | // no contact record? yer abandoned! |
434 | - $transaction->set_status( EEM_Transaction::abandoned_status_code ); |
|
435 | - $this->set_new_txn_status( EEM_Transaction::abandoned_status_code ); |
|
434 | + $transaction->set_status(EEM_Transaction::abandoned_status_code); |
|
435 | + $this->set_new_txn_status(EEM_Transaction::abandoned_status_code); |
|
436 | 436 | } |
437 | 437 | return TRUE; |
438 | 438 | } |
@@ -450,16 +450,16 @@ discard block |
||
450 | 450 | * @param array $registration_query_params - array of query WHERE params to use when retrieving cached registrations from a transaction |
451 | 451 | * @return boolean |
452 | 452 | */ |
453 | - public function manually_update_registration_statuses( EE_Transaction $transaction, $new_reg_status = '', $registration_query_params = array() ) { |
|
454 | - $status_updates = $this->_call_method_on_registrations_via_Registration_Processor( 'manually_update_registration_status', $transaction, $registration_query_params, $new_reg_status ); |
|
453 | + public function manually_update_registration_statuses(EE_Transaction $transaction, $new_reg_status = '', $registration_query_params = array()) { |
|
454 | + $status_updates = $this->_call_method_on_registrations_via_Registration_Processor('manually_update_registration_status', $transaction, $registration_query_params, $new_reg_status); |
|
455 | 455 | // send messages |
456 | 456 | /** @type EE_Registration_Processor $registration_processor */ |
457 | - $registration_processor = EE_Registry::instance()->load_class( 'Registration_Processor' ); |
|
457 | + $registration_processor = EE_Registry::instance()->load_class('Registration_Processor'); |
|
458 | 458 | $registration_processor->trigger_registration_update_notifications( |
459 | 459 | $transaction->primary_registration(), |
460 | - array( 'manually_updated' => true ) |
|
460 | + array('manually_updated' => true) |
|
461 | 461 | ); |
462 | - do_action( 'AHEE__EE_Transaction_Processor__manually_update_registration_statuses', $transaction, $status_updates ); |
|
462 | + do_action('AHEE__EE_Transaction_Processor__manually_update_registration_statuses', $transaction, $status_updates); |
|
463 | 463 | return $status_updates; |
464 | 464 | } |
465 | 465 | |
@@ -473,9 +473,9 @@ discard block |
||
473 | 473 | * @param array $registration_query_params - array of query WHERE params to use when retrieving cached registrations from a transaction |
474 | 474 | * @return boolean |
475 | 475 | */ |
476 | - public function toggle_registration_statuses_for_default_approved_events( EE_Transaction $transaction, $registration_query_params = array() ) { |
|
477 | - $status_updates = $this->_call_method_on_registrations_via_Registration_Processor( 'toggle_registration_status_for_default_approved_events', $transaction, $registration_query_params ); |
|
478 | - do_action( 'AHEE__EE_Transaction_Processor__toggle_registration_statuses_for_default_approved_events', $transaction, $status_updates ); |
|
476 | + public function toggle_registration_statuses_for_default_approved_events(EE_Transaction $transaction, $registration_query_params = array()) { |
|
477 | + $status_updates = $this->_call_method_on_registrations_via_Registration_Processor('toggle_registration_status_for_default_approved_events', $transaction, $registration_query_params); |
|
478 | + do_action('AHEE__EE_Transaction_Processor__toggle_registration_statuses_for_default_approved_events', $transaction, $status_updates); |
|
479 | 479 | return $status_updates; |
480 | 480 | } |
481 | 481 | |
@@ -489,9 +489,9 @@ discard block |
||
489 | 489 | * @param array $registration_query_params - array of query WHERE params to use when retrieving cached registrations from a transaction |
490 | 490 | * @return boolean |
491 | 491 | */ |
492 | - public function toggle_registration_statuses_if_no_monies_owing( EE_Transaction $transaction, $registration_query_params = array() ) { |
|
493 | - $status_updates = $this->_call_method_on_registrations_via_Registration_Processor( 'toggle_registration_status_if_no_monies_owing', $transaction, $registration_query_params ); |
|
494 | - do_action( 'AHEE__EE_Transaction_Processor__toggle_registration_statuses_if_no_monies_owing', $transaction, $status_updates ); |
|
492 | + public function toggle_registration_statuses_if_no_monies_owing(EE_Transaction $transaction, $registration_query_params = array()) { |
|
493 | + $status_updates = $this->_call_method_on_registrations_via_Registration_Processor('toggle_registration_status_if_no_monies_owing', $transaction, $registration_query_params); |
|
494 | + do_action('AHEE__EE_Transaction_Processor__toggle_registration_statuses_if_no_monies_owing', $transaction, $status_updates); |
|
495 | 495 | return $status_updates; |
496 | 496 | } |
497 | 497 | |
@@ -507,17 +507,17 @@ discard block |
||
507 | 507 | * @throws \EE_Error |
508 | 508 | * @return array |
509 | 509 | */ |
510 | - public function update_transaction_and_registrations_after_checkout_or_payment( EE_Transaction $transaction, $payment = NULL, $registration_query_params = array() ) { |
|
510 | + public function update_transaction_and_registrations_after_checkout_or_payment(EE_Transaction $transaction, $payment = NULL, $registration_query_params = array()) { |
|
511 | 511 | // set incoming TXN_Status, and consider it new since old status should have been set |
512 | - $this->set_new_txn_status( $transaction->status_ID() ); |
|
513 | - do_action( 'AHEE_log', __FILE__, __FUNCTION__, $transaction->status_ID(), '$transaction->status_ID()' ); |
|
512 | + $this->set_new_txn_status($transaction->status_ID()); |
|
513 | + do_action('AHEE_log', __FILE__, __FUNCTION__, $transaction->status_ID(), '$transaction->status_ID()'); |
|
514 | 514 | // make sure some query params are set for retrieving registrations |
515 | - $this->_set_registration_query_params( $registration_query_params ); |
|
515 | + $this->_set_registration_query_params($registration_query_params); |
|
516 | 516 | // get final reg step status |
517 | - $finalized = $this->final_reg_step_completed( $transaction ); |
|
517 | + $finalized = $this->final_reg_step_completed($transaction); |
|
518 | 518 | // if the 'finalize_registration' step has been initiated (has a timestamp) but has not yet been fully completed (TRUE) |
519 | - if ( is_numeric( $finalized ) && $finalized !== true ) { |
|
520 | - $this->set_reg_step_completed( $transaction, 'finalize_registration' ); |
|
519 | + if (is_numeric($finalized) && $finalized !== true) { |
|
520 | + $this->set_reg_step_completed($transaction, 'finalize_registration'); |
|
521 | 521 | $finalized = true; |
522 | 522 | } |
523 | 523 | $transaction->save(); |
@@ -540,13 +540,13 @@ discard block |
||
540 | 540 | |
541 | 541 | // send messages |
542 | 542 | /** @type EE_Registration_Processor $registration_processor */ |
543 | - $registration_processor = EE_Registry::instance()->load_class( 'Registration_Processor' ); |
|
543 | + $registration_processor = EE_Registry::instance()->load_class('Registration_Processor'); |
|
544 | 544 | $registration_processor->trigger_registration_update_notifications( |
545 | 545 | $transaction->primary_registration(), |
546 | 546 | $update_params |
547 | 547 | ); |
548 | 548 | |
549 | - do_action( 'AHEE__EE_Transaction_Processor__update_transaction_and_registrations_after_checkout_or_payment', $transaction, $update_params ); |
|
549 | + do_action('AHEE__EE_Transaction_Processor__update_transaction_and_registrations_after_checkout_or_payment', $transaction, $update_params); |
|
550 | 550 | return $update_params; |
551 | 551 | } |
552 | 552 | |
@@ -564,23 +564,23 @@ discard block |
||
564 | 564 | * @throws \EE_Error |
565 | 565 | * @return boolean |
566 | 566 | */ |
567 | - private function _call_method_on_registrations_via_Registration_Processor( $method_name, EE_Transaction $transaction, $registration_query_params = array(), $additional_param = NULL ) { |
|
567 | + private function _call_method_on_registrations_via_Registration_Processor($method_name, EE_Transaction $transaction, $registration_query_params = array(), $additional_param = NULL) { |
|
568 | 568 | $response = FALSE; |
569 | 569 | /** @type EE_Registration_Processor $registration_processor */ |
570 | - $registration_processor = EE_Registry::instance()->load_class( 'Registration_Processor' ); |
|
570 | + $registration_processor = EE_Registry::instance()->load_class('Registration_Processor'); |
|
571 | 571 | // check that method exists |
572 | - if ( ! method_exists( $registration_processor, $method_name )) { |
|
573 | - throw new EE_Error( __( 'Method does not exist.', 'event_espresso' )); |
|
572 | + if ( ! method_exists($registration_processor, $method_name)) { |
|
573 | + throw new EE_Error(__('Method does not exist.', 'event_espresso')); |
|
574 | 574 | } |
575 | 575 | // make sure some query params are set for retrieving registrations |
576 | - $this->_set_registration_query_params( $registration_query_params ); |
|
576 | + $this->_set_registration_query_params($registration_query_params); |
|
577 | 577 | // loop through cached registrations |
578 | - foreach ( $transaction->registrations( $this->_registration_query_params ) as $registration ) { |
|
579 | - if ( $registration instanceof EE_Registration ) { |
|
580 | - if ( $additional_param ) { |
|
581 | - $response = $registration_processor->$method_name( $registration, $additional_param ) ? TRUE : $response; |
|
578 | + foreach ($transaction->registrations($this->_registration_query_params) as $registration) { |
|
579 | + if ($registration instanceof EE_Registration) { |
|
580 | + if ($additional_param) { |
|
581 | + $response = $registration_processor->$method_name($registration, $additional_param) ? TRUE : $response; |
|
582 | 582 | } else { |
583 | - $response = $registration_processor->$method_name( $registration ) ? TRUE : $response; |
|
583 | + $response = $registration_processor->$method_name($registration) ? TRUE : $response; |
|
584 | 584 | } |
585 | 585 | } |
586 | 586 | } |
@@ -605,46 +605,46 @@ discard block |
||
605 | 605 | public function set_transaction_payment_method_based_on_registration_statuses( |
606 | 606 | EE_Registration $edited_registration |
607 | 607 | ) { |
608 | - if ( $edited_registration instanceof EE_Registration ) { |
|
608 | + if ($edited_registration instanceof EE_Registration) { |
|
609 | 609 | $transaction = $edited_registration->transaction(); |
610 | - if ( $transaction instanceof EE_Transaction ) { |
|
610 | + if ($transaction instanceof EE_Transaction) { |
|
611 | 611 | $all_not_approved = true; |
612 | - foreach ( $transaction->registrations() as $registration ) { |
|
613 | - if ( $registration instanceof EE_Registration ) { |
|
612 | + foreach ($transaction->registrations() as $registration) { |
|
613 | + if ($registration instanceof EE_Registration) { |
|
614 | 614 | // if any REG != "Not Approved" then toggle to false |
615 | 615 | $all_not_approved = $registration->is_not_approved() ? $all_not_approved : false; |
616 | 616 | } |
617 | 617 | } |
618 | 618 | // if ALL Registrations are "Not Approved" |
619 | - if ( $all_not_approved ) { |
|
620 | - $transaction->set_payment_method_ID( null ); |
|
619 | + if ($all_not_approved) { |
|
620 | + $transaction->set_payment_method_ID(null); |
|
621 | 621 | $transaction->save(); |
622 | 622 | } else { |
623 | - $available_payment_methods = EEM_Payment_Method::instance()->get_all_for_transaction( $transaction, EEM_Payment_Method::scope_cart ); |
|
624 | - if ( ! empty( $available_payment_methods ) ) { |
|
623 | + $available_payment_methods = EEM_Payment_Method::instance()->get_all_for_transaction($transaction, EEM_Payment_Method::scope_cart); |
|
624 | + if ( ! empty($available_payment_methods)) { |
|
625 | 625 | $PMD_ID = 0; |
626 | - foreach ( $available_payment_methods as $available_payment_method ) { |
|
627 | - if ( $available_payment_method instanceof EE_Payment_Method && $available_payment_method->open_by_default() ) { |
|
626 | + foreach ($available_payment_methods as $available_payment_method) { |
|
627 | + if ($available_payment_method instanceof EE_Payment_Method && $available_payment_method->open_by_default()) { |
|
628 | 628 | $PMD_ID = $available_payment_method->ID(); |
629 | 629 | break; |
630 | 630 | } |
631 | 631 | } |
632 | - if ( ! $PMD_ID ) { |
|
633 | - $first_payment_method = reset( $available_payment_methods ); |
|
634 | - if ( $first_payment_method instanceof EE_Payment_Method ) { |
|
632 | + if ( ! $PMD_ID) { |
|
633 | + $first_payment_method = reset($available_payment_methods); |
|
634 | + if ($first_payment_method instanceof EE_Payment_Method) { |
|
635 | 635 | $PMD_ID = $first_payment_method->ID(); |
636 | 636 | } else { |
637 | 637 | EE_Error::add_error( |
638 | - __( 'A valid Payment Method could not be determined. Please ensure that at least one Payment Method is activated.', 'event_espresso' ), |
|
638 | + __('A valid Payment Method could not be determined. Please ensure that at least one Payment Method is activated.', 'event_espresso'), |
|
639 | 639 | __FILE__, __LINE__, __FUNCTION__ |
640 | 640 | ); |
641 | 641 | } |
642 | 642 | } |
643 | - $transaction->set_payment_method_ID( $PMD_ID ); |
|
643 | + $transaction->set_payment_method_ID($PMD_ID); |
|
644 | 644 | $transaction->save(); |
645 | 645 | } else { |
646 | 646 | EE_Error::add_error( |
647 | - __( 'Please activate at least one Payment Method in order for things to operate correctly.', 'event_espresso' ), |
|
647 | + __('Please activate at least one Payment Method in order for things to operate correctly.', 'event_espresso'), |
|
648 | 648 | __FILE__, __LINE__, __FUNCTION__ |
649 | 649 | ); |
650 | 650 | } |
@@ -16,7 +16,7 @@ discard block |
||
16 | 16 | * @return EED_Add_New_State |
17 | 17 | */ |
18 | 18 | public static function instance() { |
19 | - return parent::get_instance( __CLASS__ ); |
|
19 | + return parent::get_instance(__CLASS__); |
|
20 | 20 | } |
21 | 21 | |
22 | 22 | |
@@ -27,16 +27,16 @@ discard block |
||
27 | 27 | * @return void |
28 | 28 | */ |
29 | 29 | public static function set_hooks() { |
30 | - add_action( 'wp_loaded', array( 'EED_Add_New_State', 'set_definitions' ), 2 ); |
|
31 | - add_action( 'wp_enqueue_scripts', array( 'EED_Add_New_State', 'translate_js_strings' ), 0 ); |
|
32 | - add_action( 'wp_enqueue_scripts', array( 'EED_Add_New_State', 'wp_enqueue_scripts' ), 10 ); |
|
33 | - add_filter( 'FHEE__EE_SPCO_Reg_Step_Attendee_Information___question_group_reg_form__question_group_reg_form', array( 'EED_Add_New_State', 'display_add_new_state_micro_form' ), 1, 1 ); |
|
34 | - add_filter( 'FHEE__EE_SPCO_Reg_Step_Payment_Options___get_billing_form_for_payment_method__billing_form', array( 'EED_Add_New_State', 'display_add_new_state_micro_form' ), 1, 1 ); |
|
35 | - add_filter( 'FHEE__EE_Single_Page_Checkout__process_attendee_information__valid_data_line_item', array( 'EED_Add_New_State', 'unset_new_state_request_params' ), 10, 1 ); |
|
36 | - add_filter( 'FHEE__EE_SPCO_Reg_Step_Attendee_Information___generate_question_input__state_options', array( 'EED_Add_New_State', 'inject_new_reg_state_into_options' ), 10, 5 ); |
|
37 | - add_filter( 'FHEE__EE_SPCO_Reg_Step_Attendee_Information___generate_question_input__country_options', array( 'EED_Add_New_State', 'inject_new_reg_country_into_options' ), 10, 5 ); |
|
38 | - add_filter( 'FHEE__EE_State_Select_Input____construct__state_options', array( 'EED_Add_New_State', 'state_options' ), 10, 1 ); |
|
39 | - add_filter( 'FHEE__EE_Country_Select_Input____construct__country_options', array( 'EED_Add_New_State', 'country_options' ), 10, 1 ); |
|
30 | + add_action('wp_loaded', array('EED_Add_New_State', 'set_definitions'), 2); |
|
31 | + add_action('wp_enqueue_scripts', array('EED_Add_New_State', 'translate_js_strings'), 0); |
|
32 | + add_action('wp_enqueue_scripts', array('EED_Add_New_State', 'wp_enqueue_scripts'), 10); |
|
33 | + add_filter('FHEE__EE_SPCO_Reg_Step_Attendee_Information___question_group_reg_form__question_group_reg_form', array('EED_Add_New_State', 'display_add_new_state_micro_form'), 1, 1); |
|
34 | + add_filter('FHEE__EE_SPCO_Reg_Step_Payment_Options___get_billing_form_for_payment_method__billing_form', array('EED_Add_New_State', 'display_add_new_state_micro_form'), 1, 1); |
|
35 | + add_filter('FHEE__EE_Single_Page_Checkout__process_attendee_information__valid_data_line_item', array('EED_Add_New_State', 'unset_new_state_request_params'), 10, 1); |
|
36 | + add_filter('FHEE__EE_SPCO_Reg_Step_Attendee_Information___generate_question_input__state_options', array('EED_Add_New_State', 'inject_new_reg_state_into_options'), 10, 5); |
|
37 | + add_filter('FHEE__EE_SPCO_Reg_Step_Attendee_Information___generate_question_input__country_options', array('EED_Add_New_State', 'inject_new_reg_country_into_options'), 10, 5); |
|
38 | + add_filter('FHEE__EE_State_Select_Input____construct__state_options', array('EED_Add_New_State', 'state_options'), 10, 1); |
|
39 | + add_filter('FHEE__EE_Country_Select_Input____construct__country_options', array('EED_Add_New_State', 'country_options'), 10, 1); |
|
40 | 40 | } |
41 | 41 | |
42 | 42 | /** |
@@ -46,19 +46,19 @@ discard block |
||
46 | 46 | * @return void |
47 | 47 | */ |
48 | 48 | public static function set_hooks_admin() { |
49 | - add_action( 'wp_loaded', array( 'EED_Add_New_State', 'set_definitions' ), 2 ); |
|
50 | - add_filter( 'FHEE__EE_SPCO_Reg_Step_Attendee_Information___question_group_reg_form__question_group_reg_form', array( 'EED_Add_New_State', 'display_add_new_state_micro_form' ), 1, 1 ); |
|
51 | - add_filter( 'FHEE__EE_SPCO_Reg_Step_Payment_Options___get_billing_form_for_payment_method__billing_form', array( 'EED_Add_New_State', 'display_add_new_state_micro_form' ), 1, 1 ); |
|
52 | - add_action( 'wp_ajax_espresso_add_new_state', array( 'EED_Add_New_State', 'add_new_state' )); |
|
53 | - add_action( 'wp_ajax_nopriv_espresso_add_new_state', array( 'EED_Add_New_State', 'add_new_state' )); |
|
54 | - add_filter( 'FHEE__EE_Single_Page_Checkout__process_attendee_information__valid_data_line_item', array( 'EED_Add_New_State', 'unset_new_state_request_params' ), 10, 1 ); |
|
55 | - add_action( 'AHEE__General_Settings_Admin_Page__update_country_settings__state_saved', array( 'EED_Add_New_State', 'update_country_settings' ), 10, 3 ); |
|
56 | - add_action( 'AHEE__General_Settings_Admin_Page__delete_state__state_deleted', array( 'EED_Add_New_State', 'update_country_settings' ), 10, 3 ); |
|
57 | - add_filter( 'FHEE__EE_State_Select_Input____construct__state_options', array( 'EED_Add_New_State', 'state_options' ), 10, 1 ); |
|
58 | - add_filter( 'FHEE__EE_Country_Select_Input____construct__country_options', array( 'EED_Add_New_State', 'country_options' ), 10, 1 ); |
|
59 | - add_filter( 'FHEE__Single_Page_Checkout___check_form_submission__request_params', array( 'EED_Add_New_State', 'filter_checkout_request_params' ), 10, 1 ); |
|
60 | - add_filter( 'FHEE__EE_SPCO_Reg_Step_Attendee_Information___generate_question_input__state_options', array( 'EED_Add_New_State', 'inject_new_reg_state_into_options' ), 10, 5 ); |
|
61 | - add_filter( 'FHEE__EE_SPCO_Reg_Step_Attendee_Information___generate_question_input__country_options', array( 'EED_Add_New_State', 'inject_new_reg_country_into_options' ), 10, 5 ); |
|
49 | + add_action('wp_loaded', array('EED_Add_New_State', 'set_definitions'), 2); |
|
50 | + add_filter('FHEE__EE_SPCO_Reg_Step_Attendee_Information___question_group_reg_form__question_group_reg_form', array('EED_Add_New_State', 'display_add_new_state_micro_form'), 1, 1); |
|
51 | + add_filter('FHEE__EE_SPCO_Reg_Step_Payment_Options___get_billing_form_for_payment_method__billing_form', array('EED_Add_New_State', 'display_add_new_state_micro_form'), 1, 1); |
|
52 | + add_action('wp_ajax_espresso_add_new_state', array('EED_Add_New_State', 'add_new_state')); |
|
53 | + add_action('wp_ajax_nopriv_espresso_add_new_state', array('EED_Add_New_State', 'add_new_state')); |
|
54 | + add_filter('FHEE__EE_Single_Page_Checkout__process_attendee_information__valid_data_line_item', array('EED_Add_New_State', 'unset_new_state_request_params'), 10, 1); |
|
55 | + add_action('AHEE__General_Settings_Admin_Page__update_country_settings__state_saved', array('EED_Add_New_State', 'update_country_settings'), 10, 3); |
|
56 | + add_action('AHEE__General_Settings_Admin_Page__delete_state__state_deleted', array('EED_Add_New_State', 'update_country_settings'), 10, 3); |
|
57 | + add_filter('FHEE__EE_State_Select_Input____construct__state_options', array('EED_Add_New_State', 'state_options'), 10, 1); |
|
58 | + add_filter('FHEE__EE_Country_Select_Input____construct__country_options', array('EED_Add_New_State', 'country_options'), 10, 1); |
|
59 | + add_filter('FHEE__Single_Page_Checkout___check_form_submission__request_params', array('EED_Add_New_State', 'filter_checkout_request_params'), 10, 1); |
|
60 | + add_filter('FHEE__EE_SPCO_Reg_Step_Attendee_Information___generate_question_input__state_options', array('EED_Add_New_State', 'inject_new_reg_state_into_options'), 10, 5); |
|
61 | + add_filter('FHEE__EE_SPCO_Reg_Step_Attendee_Information___generate_question_input__country_options', array('EED_Add_New_State', 'inject_new_reg_country_into_options'), 10, 5); |
|
62 | 62 | } |
63 | 63 | |
64 | 64 | |
@@ -70,8 +70,8 @@ discard block |
||
70 | 70 | * @return void |
71 | 71 | */ |
72 | 72 | public static function set_definitions() { |
73 | - define( 'ANS_ASSETS_URL', plugin_dir_url( __FILE__ ) . 'assets' . DS ); |
|
74 | - define( 'ANS_TEMPLATES_PATH', str_replace( '\\', DS, plugin_dir_path( __FILE__ )) . 'templates' . DS ); |
|
73 | + define('ANS_ASSETS_URL', plugin_dir_url(__FILE__).'assets'.DS); |
|
74 | + define('ANS_TEMPLATES_PATH', str_replace('\\', DS, plugin_dir_path(__FILE__)).'templates'.DS); |
|
75 | 75 | } |
76 | 76 | |
77 | 77 | |
@@ -83,7 +83,7 @@ discard block |
||
83 | 83 | * @param \WP $WP |
84 | 84 | * @return void |
85 | 85 | */ |
86 | - public function run( $WP ) { |
|
86 | + public function run($WP) { |
|
87 | 87 | } |
88 | 88 | |
89 | 89 | |
@@ -111,9 +111,9 @@ discard block |
||
111 | 111 | * @return void |
112 | 112 | */ |
113 | 113 | public static function wp_enqueue_scripts() { |
114 | - if ( apply_filters( 'EED_Single_Page_Checkout__SPCO_active', false ) ) { |
|
115 | - wp_register_script( 'add_new_state', ANS_ASSETS_URL . 'add_new_state.js', array( 'espresso_core', 'single_page_checkout' ), EVENT_ESPRESSO_VERSION, true ); |
|
116 | - wp_enqueue_script( 'add_new_state' ); |
|
114 | + if (apply_filters('EED_Single_Page_Checkout__SPCO_active', false)) { |
|
115 | + wp_register_script('add_new_state', ANS_ASSETS_URL.'add_new_state.js', array('espresso_core', 'single_page_checkout'), EVENT_ESPRESSO_VERSION, true); |
|
116 | + wp_enqueue_script('add_new_state'); |
|
117 | 117 | } |
118 | 118 | } |
119 | 119 | |
@@ -127,30 +127,30 @@ discard block |
||
127 | 127 | * @return string |
128 | 128 | */ |
129 | 129 | // public static function display_add_new_state_micro_form( $html, EE_Form_Input_With_Options_Base $input ){ |
130 | - public static function display_add_new_state_micro_form( EE_Form_Section_Proper $question_group_reg_form ){ |
|
130 | + public static function display_add_new_state_micro_form(EE_Form_Section_Proper $question_group_reg_form) { |
|
131 | 131 | // only add the 'new_state_micro_form' when displaying reg forms, |
132 | 132 | // not during processing since we process the 'new_state_micro_form' in it's own AJAX request |
133 | - $action = EE_Registry::instance()->REQ->get( 'action', '' ); |
|
134 | - if ( $action === 'process_reg_step' || $action === 'update_reg_step' ) { |
|
133 | + $action = EE_Registry::instance()->REQ->get('action', ''); |
|
134 | + if ($action === 'process_reg_step' || $action === 'update_reg_step') { |
|
135 | 135 | return $question_group_reg_form; |
136 | 136 | } |
137 | 137 | // is the "state" question in this form section? |
138 | - $input = $question_group_reg_form->get_subsection( 'state' ); |
|
138 | + $input = $question_group_reg_form->get_subsection('state'); |
|
139 | 139 | // we're only doing this for state select inputs |
140 | - if ( $input instanceof EE_State_Select_Input ) { |
|
140 | + if ($input instanceof EE_State_Select_Input) { |
|
141 | 141 | // load helpers |
142 | - EE_Registry::instance()->load_helper( 'HTML' ); |
|
142 | + EE_Registry::instance()->load_helper('HTML'); |
|
143 | 143 | // grab any set values from the request |
144 | - $country_name = str_replace( 'state', 'new_state_country', $input->html_name() ); |
|
145 | - $state_name = str_replace( 'state', 'new_state_name', $input->html_name() ); |
|
146 | - $abbrv_name = str_replace( 'state', 'new_state_abbrv', $input->html_name() ); |
|
147 | - $new_state_submit_id = str_replace( 'state', 'new_state', $input->html_id() ); |
|
144 | + $country_name = str_replace('state', 'new_state_country', $input->html_name()); |
|
145 | + $state_name = str_replace('state', 'new_state_name', $input->html_name()); |
|
146 | + $abbrv_name = str_replace('state', 'new_state_abbrv', $input->html_name()); |
|
147 | + $new_state_submit_id = str_replace('state', 'new_state', $input->html_id()); |
|
148 | 148 | $country_options = array(); |
149 | 149 | $countries = EEM_Country::instance()->get_all_countries(); |
150 | - if ( ! empty( $countries )) { |
|
151 | - foreach( $countries as $country ){ |
|
152 | - if ( $country instanceof EE_Country ) { |
|
153 | - $country_options[ $country->ID() ] = $country->name(); |
|
150 | + if ( ! empty($countries)) { |
|
151 | + foreach ($countries as $country) { |
|
152 | + if ($country instanceof EE_Country) { |
|
153 | + $country_options[$country->ID()] = $country->name(); |
|
154 | 154 | } |
155 | 155 | } |
156 | 156 | } |
@@ -163,8 +163,8 @@ discard block |
||
163 | 163 | // add hidden input to indicate that a new state is being added |
164 | 164 | 'add_new_state' => new EE_Hidden_Input( |
165 | 165 | array( |
166 | - 'html_name' => str_replace( 'state', 'add_new_state', $input->html_name() ), |
|
167 | - 'html_id' => str_replace( 'state', 'add_new_state', $input->html_id() ), |
|
166 | + 'html_name' => str_replace('state', 'add_new_state', $input->html_name()), |
|
167 | + 'html_id' => str_replace('state', 'add_new_state', $input->html_id()), |
|
168 | 168 | 'default' => 0 |
169 | 169 | ) |
170 | 170 | ), |
@@ -176,10 +176,10 @@ discard block |
||
176 | 176 | '', |
177 | 177 | __('click here to add a new state/province', 'event_espresso'), |
178 | 178 | '', |
179 | - 'display-' . $input->html_id(), |
|
179 | + 'display-'.$input->html_id(), |
|
180 | 180 | 'ee-form-add-new-state-lnk display-the-hidden smaller-text hide-if-no-js', |
181 | 181 | '', |
182 | - 'rel="' . $input->html_id() . '"' |
|
182 | + 'rel="'.$input->html_id().'"' |
|
183 | 183 | ) |
184 | 184 | ) |
185 | 185 | ), |
@@ -187,13 +187,13 @@ discard block |
||
187 | 187 | 'add_new_state_micro_form' =>new EE_Form_Section_HTML( |
188 | 188 | apply_filters( |
189 | 189 | 'FHEE__EED_Add_New_State__display_add_new_state_micro_form__add_new_state_micro_form', |
190 | - EEH_HTML::div( '', $input->html_id() . '-dv', 'ee-form-add-new-state-dv', 'display: none;' ) . |
|
191 | - EEH_HTML::h6( __('If your State/Province does not appear in the list above, you can easily add it by doing the following:', 'event_espresso')) . |
|
192 | - EEH_HTML::ul() . |
|
193 | - EEH_HTML::li( __('first select the Country that your State/Province belongs to', 'event_espresso') ) . |
|
194 | - EEH_HTML::li( __('enter the name of your State/Province', 'event_espresso') ) . |
|
195 | - EEH_HTML::li( __('enter a two to six letter abbreviation for the name of your State/Province', 'event_espresso') ) . |
|
196 | - EEH_HTML::li( __('click the ADD button', 'event_espresso') ) . |
|
190 | + EEH_HTML::div('', $input->html_id().'-dv', 'ee-form-add-new-state-dv', 'display: none;'). |
|
191 | + EEH_HTML::h6(__('If your State/Province does not appear in the list above, you can easily add it by doing the following:', 'event_espresso')). |
|
192 | + EEH_HTML::ul(). |
|
193 | + EEH_HTML::li(__('first select the Country that your State/Province belongs to', 'event_espresso')). |
|
194 | + EEH_HTML::li(__('enter the name of your State/Province', 'event_espresso')). |
|
195 | + EEH_HTML::li(__('enter a two to six letter abbreviation for the name of your State/Province', 'event_espresso')). |
|
196 | + EEH_HTML::li(__('click the ADD button', 'event_espresso')). |
|
197 | 197 | EEH_HTML::ulx() |
198 | 198 | ) |
199 | 199 | ), |
@@ -202,10 +202,10 @@ discard block |
||
202 | 202 | $country_options, |
203 | 203 | array( |
204 | 204 | 'html_name' => $country_name, |
205 | - 'html_id' => str_replace( 'state', 'new_state_country', $input->html_id() ), |
|
206 | - 'html_class' => $input->html_class() . ' new-state-country', |
|
205 | + 'html_id' => str_replace('state', 'new_state_country', $input->html_id()), |
|
206 | + 'html_class' => $input->html_class().' new-state-country', |
|
207 | 207 | 'html_label_text' => __('New State/Province Country', 'event_espresso'), |
208 | - 'default' => EE_Registry::instance()->REQ->get( $country_name, '' ), |
|
208 | + 'default' => EE_Registry::instance()->REQ->get($country_name, ''), |
|
209 | 209 | 'required' => false |
210 | 210 | ) |
211 | 211 | ), |
@@ -213,23 +213,23 @@ discard block |
||
213 | 213 | 'new_state_name' => new EE_Text_Input( |
214 | 214 | array( |
215 | 215 | 'html_name' => $state_name, |
216 | - 'html_id' => str_replace( 'state', 'new_state_name', $input->html_id() ), |
|
217 | - 'html_class' => $input->html_class() . ' new-state-state', |
|
216 | + 'html_id' => str_replace('state', 'new_state_name', $input->html_id()), |
|
217 | + 'html_class' => $input->html_class().' new-state-state', |
|
218 | 218 | 'html_label_text' => __('New State/Province Name', 'event_espresso'), |
219 | - 'default' => EE_Registry::instance()->REQ->get( $state_name, '' ), |
|
219 | + 'default' => EE_Registry::instance()->REQ->get($state_name, ''), |
|
220 | 220 | 'required' => false |
221 | 221 | ) |
222 | 222 | ), |
223 | - 'spacer' => new EE_Form_Section_HTML( EEH_HTML::br() ), |
|
223 | + 'spacer' => new EE_Form_Section_HTML(EEH_HTML::br()), |
|
224 | 224 | // NEW STATE NAME |
225 | 225 | 'new_state_abbrv' => new EE_Text_Input( |
226 | 226 | array( |
227 | 227 | 'html_name' => $abbrv_name, |
228 | - 'html_id' => str_replace( 'state', 'new_state_abbrv', $input->html_id() ), |
|
229 | - 'html_class' => $input->html_class() . ' new-state-abbrv', |
|
228 | + 'html_id' => str_replace('state', 'new_state_abbrv', $input->html_id()), |
|
229 | + 'html_class' => $input->html_class().' new-state-abbrv', |
|
230 | 230 | 'html_label_text' => __('New State/Province Abbreviation', 'event_espresso'), |
231 | 231 | 'html_other_attributes' => 'size="24"', |
232 | - 'default' => EE_Registry::instance()->REQ->get( $abbrv_name, '' ), |
|
232 | + 'default' => EE_Registry::instance()->REQ->get($abbrv_name, ''), |
|
233 | 233 | 'required' => false |
234 | 234 | ) |
235 | 235 | ), |
@@ -237,26 +237,26 @@ discard block |
||
237 | 237 | 'add_new_state_submit_button' => new EE_Form_Section_HTML( |
238 | 238 | apply_filters( |
239 | 239 | 'FHEE__EED_Add_New_State__display_add_new_state_micro_form__add_new_state_submit_button', |
240 | - EEH_HTML::nbsp(3) . |
|
241 | - EEH_HTML::link( '', __('ADD', 'event_espresso'), '', 'submit-' . $new_state_submit_id, 'ee-form-add-new-state-submit button button-secondary', '', 'rel="' . $new_state_submit_id . '"' ) |
|
240 | + EEH_HTML::nbsp(3). |
|
241 | + EEH_HTML::link('', __('ADD', 'event_espresso'), '', 'submit-'.$new_state_submit_id, 'ee-form-add-new-state-submit button button-secondary', '', 'rel="'.$new_state_submit_id.'"') |
|
242 | 242 | ) |
243 | 243 | ), |
244 | 244 | // extra info |
245 | 245 | 'add_new_state_extra' => new EE_Form_Section_HTML( |
246 | 246 | apply_filters( |
247 | 247 | 'FHEE__EED_Add_New_State__display_add_new_state_micro_form__add_new_state_extra', |
248 | - EEH_HTML::br(2) . |
|
249 | - EEH_HTML::div( '', '', 'small-text' ) . |
|
250 | - EEH_HTML::strong( __('Don\'t know your State/Province Abbreviation?', 'event_espresso') ) . |
|
251 | - EEH_HTML::br() . |
|
248 | + EEH_HTML::br(2). |
|
249 | + EEH_HTML::div('', '', 'small-text'). |
|
250 | + EEH_HTML::strong(__('Don\'t know your State/Province Abbreviation?', 'event_espresso')). |
|
251 | + EEH_HTML::br(). |
|
252 | 252 | sprintf( |
253 | 253 | __('You can look here: %s, for a list of Countries and links to their State/Province Abbreviations ("Subdivisions assigned codes" column).', 'event_espresso'), |
254 | - EEH_HTML::link( 'http://en.wikipedia.org/wiki/ISO_3166-2', 'http://en.wikipedia.org/wiki/ISO_3166-2', '', '', 'ee-form-add-new-state-wiki-lnk' ) |
|
255 | - ) . |
|
256 | - EEH_HTML::divx() . |
|
257 | - EEH_HTML::br() . |
|
258 | - EEH_HTML::link( '', __('cancel new state/province', 'event_espresso'), '', 'hide-' . $input->html_id(), 'ee-form-cancel-new-state-lnk smaller-text', '', 'rel="' . $input->html_id() . '"' ) . |
|
259 | - EEH_HTML::divx() . |
|
254 | + EEH_HTML::link('http://en.wikipedia.org/wiki/ISO_3166-2', 'http://en.wikipedia.org/wiki/ISO_3166-2', '', '', 'ee-form-add-new-state-wiki-lnk') |
|
255 | + ). |
|
256 | + EEH_HTML::divx(). |
|
257 | + EEH_HTML::br(). |
|
258 | + EEH_HTML::link('', __('cancel new state/province', 'event_espresso'), '', 'hide-'.$input->html_id(), 'ee-form-cancel-new-state-lnk smaller-text', '', 'rel="'.$input->html_id().'"'). |
|
259 | + EEH_HTML::divx(). |
|
260 | 260 | EEH_HTML::br() |
261 | 261 | ) |
262 | 262 | ) |
@@ -264,7 +264,7 @@ discard block |
||
264 | 264 | ) |
265 | 265 | ) |
266 | 266 | ); |
267 | - $question_group_reg_form->add_subsections( array( 'new_state_micro_form' => $new_state_micro_form ), 'state', false ); |
|
267 | + $question_group_reg_form->add_subsections(array('new_state_micro_form' => $new_state_micro_form), 'state', false); |
|
268 | 268 | } |
269 | 269 | return $question_group_reg_form; |
270 | 270 | } |
@@ -281,41 +281,41 @@ discard block |
||
281 | 281 | */ |
282 | 282 | public static function add_new_state() { |
283 | 283 | $REQ = EE_Registry::instance()->load_core('Request_Handler'); |
284 | - if ( $REQ->is_set( 'add_new_state' ) && $REQ->get( 'add_new_state' ) == 1 ) { |
|
284 | + if ($REQ->is_set('add_new_state') && $REQ->get('add_new_state') == 1) { |
|
285 | 285 | EE_Registry::instance()->load_model('State'); |
286 | 286 | // grab country ISO code, new state name, and new state abbreviation |
287 | - $state_country = $REQ->is_set( 'new_state_country' ) ? sanitize_text_field( $REQ->get( 'new_state_country' )) : FALSE; |
|
288 | - $state_name = $REQ->is_set( 'new_state_name' ) ? sanitize_text_field( $REQ->get( 'new_state_name' )) : FALSE; |
|
289 | - $state_abbr = $REQ->is_set( 'new_state_abbrv' ) ? sanitize_text_field( $REQ->get( 'new_state_abbrv' )) : FALSE; |
|
287 | + $state_country = $REQ->is_set('new_state_country') ? sanitize_text_field($REQ->get('new_state_country')) : FALSE; |
|
288 | + $state_name = $REQ->is_set('new_state_name') ? sanitize_text_field($REQ->get('new_state_name')) : FALSE; |
|
289 | + $state_abbr = $REQ->is_set('new_state_abbrv') ? sanitize_text_field($REQ->get('new_state_abbrv')) : FALSE; |
|
290 | 290 | |
291 | 291 | //echo '<h4>$state_country : ' . $state_country . ' <br /><span style="font-size:10px;font-weight:normal;">' . __FILE__ . '<br />line no: ' . __LINE__ . '</span></h4>'; |
292 | 292 | //echo '<h4>$state_name : ' . $state_name . ' <br /><span style="font-size:10px;font-weight:normal;">' . __FILE__ . '<br />line no: ' . __LINE__ . '</span></h4>'; |
293 | 293 | //echo '<h4>$state_abbr : ' . $state_abbr . ' <br /><span style="font-size:10px;font-weight:normal;">' . __FILE__ . '<br />line no: ' . __LINE__ . '</span></h4>'; |
294 | 294 | |
295 | - if ( $state_country && $state_name && $state_abbr ) { |
|
296 | - $new_state = EED_Add_New_State::save_new_state_to_db( array( |
|
297 | - 'CNT_ISO'=> strtoupper( $state_country ), |
|
298 | - 'STA_abbrev' => strtoupper( $state_abbr ), |
|
299 | - 'STA_name' => ucwords( $state_name ), |
|
295 | + if ($state_country && $state_name && $state_abbr) { |
|
296 | + $new_state = EED_Add_New_State::save_new_state_to_db(array( |
|
297 | + 'CNT_ISO'=> strtoupper($state_country), |
|
298 | + 'STA_abbrev' => strtoupper($state_abbr), |
|
299 | + 'STA_name' => ucwords($state_name), |
|
300 | 300 | 'STA_active' => FALSE |
301 | 301 | )); |
302 | 302 | |
303 | - if ( $new_state instanceof EE_State ) { |
|
303 | + if ($new_state instanceof EE_State) { |
|
304 | 304 | // clean house |
305 | - EE_Registry::instance()->REQ->un_set( 'add_new_state' ); |
|
306 | - EE_Registry::instance()->REQ->un_set( 'new_state_country' ); |
|
307 | - EE_Registry::instance()->REQ->un_set( 'new_state_name' ); |
|
308 | - EE_Registry::instance()->REQ->un_set( 'new_state_abbrv' ); |
|
305 | + EE_Registry::instance()->REQ->un_set('add_new_state'); |
|
306 | + EE_Registry::instance()->REQ->un_set('new_state_country'); |
|
307 | + EE_Registry::instance()->REQ->un_set('new_state_name'); |
|
308 | + EE_Registry::instance()->REQ->un_set('new_state_abbrv'); |
|
309 | 309 | |
310 | 310 | // get any existing new states |
311 | 311 | $new_states = EE_Registry::instance()->SSN->get_session_data( |
312 | 312 | 'new_states' |
313 | 313 | ); |
314 | - $new_states[ $new_state->ID() ] = $new_state; |
|
315 | - EE_Registry::instance()->SSN->set_session_data( array( 'new_states' => $new_states )); |
|
314 | + $new_states[$new_state->ID()] = $new_state; |
|
315 | + EE_Registry::instance()->SSN->set_session_data(array('new_states' => $new_states)); |
|
316 | 316 | |
317 | - if ( EE_Registry::instance()->REQ->ajax ) { |
|
318 | - echo json_encode( array( |
|
317 | + if (EE_Registry::instance()->REQ->ajax) { |
|
318 | + echo json_encode(array( |
|
319 | 319 | 'success' => TRUE, |
320 | 320 | 'id' => $new_state->ID(), |
321 | 321 | 'name' => $new_state->name(), |
@@ -330,12 +330,12 @@ discard block |
||
330 | 330 | } |
331 | 331 | |
332 | 332 | } else { |
333 | - $error = __( 'A new State/Province could not be added because invalid or missing data was received.', 'event_espresso' ); |
|
334 | - if ( EE_Registry::instance()->REQ->ajax ) { |
|
335 | - echo json_encode( array( 'error' => $error )); |
|
333 | + $error = __('A new State/Province could not be added because invalid or missing data was received.', 'event_espresso'); |
|
334 | + if (EE_Registry::instance()->REQ->ajax) { |
|
335 | + echo json_encode(array('error' => $error)); |
|
336 | 336 | exit(); |
337 | 337 | } else { |
338 | - EE_Error::add_error( $error, __FILE__, __FUNCTION__, __LINE__ ); |
|
338 | + EE_Error::add_error($error, __FILE__, __FUNCTION__, __LINE__); |
|
339 | 339 | } |
340 | 340 | } |
341 | 341 | } |
@@ -353,11 +353,11 @@ discard block |
||
353 | 353 | * @param array $request_params |
354 | 354 | * @return array |
355 | 355 | */ |
356 | - public static function filter_checkout_request_params ( $request_params ) { |
|
357 | - foreach ( $request_params as $form_section ) { |
|
358 | - if ( is_array( $form_section )) { |
|
359 | - EED_Add_New_State::unset_new_state_request_params( $form_section ); |
|
360 | - EED_Add_New_State::filter_checkout_request_params( $form_section ); |
|
356 | + public static function filter_checkout_request_params($request_params) { |
|
357 | + foreach ($request_params as $form_section) { |
|
358 | + if (is_array($form_section)) { |
|
359 | + EED_Add_New_State::unset_new_state_request_params($form_section); |
|
360 | + EED_Add_New_State::filter_checkout_request_params($form_section); |
|
361 | 361 | } |
362 | 362 | } |
363 | 363 | return $request_params; |
@@ -372,12 +372,12 @@ discard block |
||
372 | 372 | * @param array $request_params |
373 | 373 | * @return boolean |
374 | 374 | */ |
375 | - public static function unset_new_state_request_params ( $request_params ) { |
|
376 | - unset( $request_params[ 'new_state_micro_form' ] ); |
|
377 | - unset( $request_params[ 'add_new_state' ] ); |
|
378 | - unset( $request_params[ 'new_state_country' ] ); |
|
379 | - unset( $request_params[ 'new_state_name' ] ); |
|
380 | - unset( $request_params[ 'new_state_abbrv' ] ); |
|
375 | + public static function unset_new_state_request_params($request_params) { |
|
376 | + unset($request_params['new_state_micro_form']); |
|
377 | + unset($request_params['add_new_state']); |
|
378 | + unset($request_params['new_state_country']); |
|
379 | + unset($request_params['new_state_name']); |
|
380 | + unset($request_params['new_state_abbrv']); |
|
381 | 381 | return $request_params; |
382 | 382 | } |
383 | 383 | |
@@ -390,25 +390,25 @@ discard block |
||
390 | 390 | * @param array $props_n_values |
391 | 391 | * @return boolean |
392 | 392 | */ |
393 | - public static function save_new_state_to_db ( $props_n_values = array() ) { |
|
393 | + public static function save_new_state_to_db($props_n_values = array()) { |
|
394 | 394 | // EEH_Debug_Tools::printr( $props_n_values, '$props_n_values <br /><span style="font-size:10px;font-weight:normal;">' . __FILE__ . '<br />line no: ' . __LINE__ . '</span>', 'auto' ); |
395 | - $existing_state = EEM_State::instance()->get_all( array( $props_n_values, 'limit' => 1 )); |
|
396 | - if ( ! empty( $existing_state )) { |
|
397 | - return array_pop( $existing_state ); |
|
395 | + $existing_state = EEM_State::instance()->get_all(array($props_n_values, 'limit' => 1)); |
|
396 | + if ( ! empty($existing_state)) { |
|
397 | + return array_pop($existing_state); |
|
398 | 398 | } |
399 | - $new_state = EE_State::new_instance( $props_n_values ); |
|
400 | - if ( $new_state instanceof EE_State ) { |
|
399 | + $new_state = EE_State::new_instance($props_n_values); |
|
400 | + if ($new_state instanceof EE_State) { |
|
401 | 401 | // if not non-ajax admin |
402 | - $new_state_key = $new_state->country_iso() . '-' . $new_state->abbrev(); |
|
402 | + $new_state_key = $new_state->country_iso().'-'.$new_state->abbrev(); |
|
403 | 403 | $new_state_notice = sprintf( |
404 | - __( 'A new State named "%1$s (%2$s)" was dynamically added from an Event Espresso form for the Country of "%3$s".%5$sTo verify, edit, and/or delete this new State, please go to the %4$s and update the States / Provinces section.%5$sCheck "Yes" to have this new State added to dropdown select lists in forms.', 'event_espresso' ), |
|
405 | - '<b>' . $new_state->name() . '</b>', |
|
406 | - '<b>' . $new_state->abbrev() . '</b>', |
|
407 | - '<b>' . $new_state->country()->name() . '</b>', |
|
408 | - '<a href="' . add_query_arg( array( 'page' => 'espresso_general_settings', 'action' => 'country_settings', 'country' => $new_state->country_iso() ), admin_url( 'admin.php' )) . '">' . __( 'Event Espresso - General Settings > Countries Tab', 'event_espresso' ) . '</a>', |
|
404 | + __('A new State named "%1$s (%2$s)" was dynamically added from an Event Espresso form for the Country of "%3$s".%5$sTo verify, edit, and/or delete this new State, please go to the %4$s and update the States / Provinces section.%5$sCheck "Yes" to have this new State added to dropdown select lists in forms.', 'event_espresso'), |
|
405 | + '<b>'.$new_state->name().'</b>', |
|
406 | + '<b>'.$new_state->abbrev().'</b>', |
|
407 | + '<b>'.$new_state->country()->name().'</b>', |
|
408 | + '<a href="'.add_query_arg(array('page' => 'espresso_general_settings', 'action' => 'country_settings', 'country' => $new_state->country_iso()), admin_url('admin.php')).'">'.__('Event Espresso - General Settings > Countries Tab', 'event_espresso').'</a>', |
|
409 | 409 | '<br />' |
410 | 410 | ); |
411 | - EE_Error::add_persistent_admin_notice( $new_state_key, $new_state_notice ); |
|
411 | + EE_Error::add_persistent_admin_notice($new_state_key, $new_state_notice); |
|
412 | 412 | $new_state->save(); |
413 | 413 | EEM_State::instance()->reset_cached_states(); |
414 | 414 | return $new_state; |
@@ -427,22 +427,22 @@ discard block |
||
427 | 427 | * @param array $cols_n_values |
428 | 428 | * @return boolean |
429 | 429 | */ |
430 | - public static function update_country_settings( $CNT_ISO = '', $STA_ID = '', $cols_n_values = array() ) { |
|
431 | - $CNT_ISO = ! empty( $CNT_ISO ) ? $CNT_ISO : FALSE; |
|
432 | - if ( ! $CNT_ISO ) { |
|
433 | - EE_Error::add_error( __( 'An invalid or missing Country ISO Code was received.', 'event_espresso' ), __FILE__, __FUNCTION__, __LINE__ ); |
|
430 | + public static function update_country_settings($CNT_ISO = '', $STA_ID = '', $cols_n_values = array()) { |
|
431 | + $CNT_ISO = ! empty($CNT_ISO) ? $CNT_ISO : FALSE; |
|
432 | + if ( ! $CNT_ISO) { |
|
433 | + EE_Error::add_error(__('An invalid or missing Country ISO Code was received.', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__); |
|
434 | 434 | } |
435 | - $STA_abbrev = is_array( $cols_n_values ) && isset( $cols_n_values['STA_abbrev'] ) ? $cols_n_values['STA_abbrev'] : FALSE; |
|
436 | - if ( ! $STA_abbrev && ! empty( $STA_ID )) { |
|
437 | - $state = EEM_State::instance()->get_one_by_ID( $STA_ID ); |
|
438 | - if ( $state instanceof EE_State ) { |
|
435 | + $STA_abbrev = is_array($cols_n_values) && isset($cols_n_values['STA_abbrev']) ? $cols_n_values['STA_abbrev'] : FALSE; |
|
436 | + if ( ! $STA_abbrev && ! empty($STA_ID)) { |
|
437 | + $state = EEM_State::instance()->get_one_by_ID($STA_ID); |
|
438 | + if ($state instanceof EE_State) { |
|
439 | 439 | $STA_abbrev = $state->abbrev(); |
440 | 440 | } |
441 | 441 | } |
442 | - if ( ! $STA_abbrev ) { |
|
443 | - EE_Error::add_error( __( 'An invalid or missing State Abbreviation was received.', 'event_espresso' ), __FILE__, __FUNCTION__, __LINE__ ); |
|
442 | + if ( ! $STA_abbrev) { |
|
443 | + EE_Error::add_error(__('An invalid or missing State Abbreviation was received.', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__); |
|
444 | 444 | } |
445 | - EE_Error::dismiss_persistent_admin_notice( $CNT_ISO . '-' . $STA_abbrev, TRUE, TRUE ); |
|
445 | + EE_Error::dismiss_persistent_admin_notice($CNT_ISO.'-'.$STA_abbrev, TRUE, TRUE); |
|
446 | 446 | } |
447 | 447 | |
448 | 448 | |
@@ -458,19 +458,19 @@ discard block |
||
458 | 458 | * @param $answer |
459 | 459 | * @return bool |
460 | 460 | */ |
461 | - public static function inject_new_reg_state_into_options( $state_options = array(), EE_SPCO_Reg_Step_Attendee_Information $reg_step, EE_Registration $registration, EE_Question $question, $answer ) { |
|
462 | - if ( $answer instanceof EE_Answer && $question instanceof EE_Question && $question->type() === EEM_Question::QST_type_state ) { |
|
461 | + public static function inject_new_reg_state_into_options($state_options = array(), EE_SPCO_Reg_Step_Attendee_Information $reg_step, EE_Registration $registration, EE_Question $question, $answer) { |
|
462 | + if ($answer instanceof EE_Answer && $question instanceof EE_Question && $question->type() === EEM_Question::QST_type_state) { |
|
463 | 463 | $STA_ID = $answer->value(); |
464 | - if ( ! empty( $STA_ID ) ) { |
|
465 | - $state = EEM_State::instance()->get_one_by_ID( $STA_ID ); |
|
466 | - if ( $state instanceof EE_State ) { |
|
464 | + if ( ! empty($STA_ID)) { |
|
465 | + $state = EEM_State::instance()->get_one_by_ID($STA_ID); |
|
466 | + if ($state instanceof EE_State) { |
|
467 | 467 | $country = $state->country(); |
468 | - if ( $country instanceof EE_Country ) { |
|
469 | - if ( ! isset( $state_options[ $country->name() ] )) { |
|
470 | - $state_options[ $country->name() ] = array(); |
|
468 | + if ($country instanceof EE_Country) { |
|
469 | + if ( ! isset($state_options[$country->name()])) { |
|
470 | + $state_options[$country->name()] = array(); |
|
471 | 471 | } |
472 | - if ( ! isset( $state_options[ $country->name() ][ $STA_ID ] )) { |
|
473 | - $state_options[ $country->name() ][ $STA_ID ] = $state->name(); |
|
472 | + if ( ! isset($state_options[$country->name()][$STA_ID])) { |
|
473 | + $state_options[$country->name()][$STA_ID] = $state->name(); |
|
474 | 474 | } |
475 | 475 | } |
476 | 476 | } |
@@ -492,14 +492,14 @@ discard block |
||
492 | 492 | * @param $answer |
493 | 493 | * @return bool |
494 | 494 | */ |
495 | - public static function inject_new_reg_country_into_options( $country_options = array(), EE_SPCO_Reg_Step_Attendee_Information $reg_step, EE_Registration $registration, EE_Question $question, $answer ) { |
|
496 | - if ( $answer instanceof EE_Answer && $question instanceof EE_Question && $question->type() === EEM_Question::QST_type_country ) { |
|
495 | + public static function inject_new_reg_country_into_options($country_options = array(), EE_SPCO_Reg_Step_Attendee_Information $reg_step, EE_Registration $registration, EE_Question $question, $answer) { |
|
496 | + if ($answer instanceof EE_Answer && $question instanceof EE_Question && $question->type() === EEM_Question::QST_type_country) { |
|
497 | 497 | $CNT_ISO = $answer->value(); |
498 | - if ( ! empty( $CNT_ISO ) ) { |
|
499 | - $country = EEM_Country::instance()->get_one_by_ID( $CNT_ISO ); |
|
500 | - if ( $country instanceof EE_Country ) { |
|
501 | - if ( ! isset( $country_options[ $CNT_ISO ] ) ) { |
|
502 | - $country_options[ $CNT_ISO ] = $country->name(); |
|
498 | + if ( ! empty($CNT_ISO)) { |
|
499 | + $country = EEM_Country::instance()->get_one_by_ID($CNT_ISO); |
|
500 | + if ($country instanceof EE_Country) { |
|
501 | + if ( ! isset($country_options[$CNT_ISO])) { |
|
502 | + $country_options[$CNT_ISO] = $country->name(); |
|
503 | 503 | } |
504 | 504 | } |
505 | 505 | } |
@@ -516,17 +516,17 @@ discard block |
||
516 | 516 | * @param EE_State[] $state_options |
517 | 517 | * @return boolean |
518 | 518 | */ |
519 | - public static function state_options( $state_options = array() ) { |
|
519 | + public static function state_options($state_options = array()) { |
|
520 | 520 | $new_states = EE_Registry::instance()->SSN->get_session_data( |
521 | 521 | 'new_states' |
522 | 522 | ); |
523 | - if ( is_array( $new_states ) && ! empty( $new_states )) { |
|
524 | - foreach ( $new_states as $new_state ) { |
|
523 | + if (is_array($new_states) && ! empty($new_states)) { |
|
524 | + foreach ($new_states as $new_state) { |
|
525 | 525 | if ( |
526 | 526 | $new_state instanceof EE_State |
527 | 527 | && $new_state->country() instanceof EE_Country |
528 | 528 | ) { |
529 | - $state_options[ $new_state->country()->name() ][ $new_state->ID() ] = $new_state->name(); |
|
529 | + $state_options[$new_state->country()->name()][$new_state->ID()] = $new_state->name(); |
|
530 | 530 | } |
531 | 531 | } |
532 | 532 | } |
@@ -542,17 +542,17 @@ discard block |
||
542 | 542 | * @param EE_Country[] $country_options |
543 | 543 | * @return boolean |
544 | 544 | */ |
545 | - public static function country_options( $country_options = array() ) { |
|
545 | + public static function country_options($country_options = array()) { |
|
546 | 546 | $new_states = EE_Registry::instance()->SSN->get_session_data( |
547 | 547 | 'new_states' |
548 | 548 | ); |
549 | - if ( is_array( $new_states ) && ! empty( $new_states )) { |
|
550 | - foreach ( $new_states as $new_state ) { |
|
549 | + if (is_array($new_states) && ! empty($new_states)) { |
|
550 | + foreach ($new_states as $new_state) { |
|
551 | 551 | if ( |
552 | 552 | $new_state instanceof EE_State |
553 | 553 | && $new_state->country() instanceof EE_Country |
554 | 554 | ) { |
555 | - $country_options[ $new_state->country()->ID() ] = $new_state->country()->name(); |
|
555 | + $country_options[$new_state->country()->ID()] = $new_state->country()->name(); |
|
556 | 556 | } |
557 | 557 | } |
558 | 558 | } |
@@ -1,13 +1,13 @@ |
||
1 | 1 | <?php if ( ! defined('EVENT_ESPRESSO_VERSION')) exit('No direct script access allowed'); |
2 | 2 | /** |
3 | - * |
|
4 | - * EED_Add_New_State class |
|
5 | - * |
|
6 | - * @package Event Espresso |
|
7 | - * @subpackage /modules/add_new_state/ |
|
8 | - * @author Brent Christensen |
|
9 | - * |
|
10 | - */ |
|
3 | + * |
|
4 | + * EED_Add_New_State class |
|
5 | + * |
|
6 | + * @package Event Espresso |
|
7 | + * @subpackage /modules/add_new_state/ |
|
8 | + * @author Brent Christensen |
|
9 | + * |
|
10 | + */ |
|
11 | 11 | class EED_Add_New_State extends EED_Module { |
12 | 12 | |
13 | 13 |
@@ -57,15 +57,15 @@ discard block |
||
57 | 57 | * @return EED_Ticket_Selector |
58 | 58 | */ |
59 | 59 | public static function instance() { |
60 | - return parent::get_instance( __CLASS__ ); |
|
60 | + return parent::get_instance(__CLASS__); |
|
61 | 61 | } |
62 | 62 | |
63 | 63 | |
64 | 64 | |
65 | - protected function set_config(){ |
|
66 | - $this->set_config_section( 'template_settings' ); |
|
67 | - $this->set_config_class( 'EE_Ticket_Selector_Config' ); |
|
68 | - $this->set_config_name( 'EED_Ticket_Selector' ); |
|
65 | + protected function set_config() { |
|
66 | + $this->set_config_section('template_settings'); |
|
67 | + $this->set_config_class('EE_Ticket_Selector_Config'); |
|
68 | + $this->set_config_name('EED_Ticket_Selector'); |
|
69 | 69 | } |
70 | 70 | |
71 | 71 | |
@@ -80,14 +80,14 @@ discard block |
||
80 | 80 | */ |
81 | 81 | public static function set_hooks() { |
82 | 82 | // routing |
83 | - EE_Config::register_route( 'iframe', 'EED_Ticket_Selector', 'ticket_selector_iframe', 'ticket_selector' ); |
|
84 | - EE_Config::register_route( 'process_ticket_selections', 'EED_Ticket_Selector', 'process_ticket_selections' ); |
|
85 | - add_action( 'wp_loaded', array( 'EED_Ticket_Selector', 'set_definitions' ), 2 ); |
|
83 | + EE_Config::register_route('iframe', 'EED_Ticket_Selector', 'ticket_selector_iframe', 'ticket_selector'); |
|
84 | + EE_Config::register_route('process_ticket_selections', 'EED_Ticket_Selector', 'process_ticket_selections'); |
|
85 | + add_action('wp_loaded', array('EED_Ticket_Selector', 'set_definitions'), 2); |
|
86 | 86 | //add_action( 'AHEE_event_details_before_post', array( 'EED_Ticket_Selector', 'ticket_selector_form_open' ), 10, 1 ); |
87 | - add_action( 'AHEE_event_details_header_bottom', array( 'EED_Ticket_Selector', 'display_ticket_selector' ), 10, 1 ); |
|
87 | + add_action('AHEE_event_details_header_bottom', array('EED_Ticket_Selector', 'display_ticket_selector'), 10, 1); |
|
88 | 88 | //add_action( 'AHEE__ticket_selector_chart__template__after_ticket_selector', array( 'EED_Ticket_Selector', 'display_ticket_selector_submit' ), 10, 1 ); |
89 | 89 | //add_action( 'AHEE_event_details_after_post', array( 'EED_Ticket_Selector', 'ticket_selector_form_close' ), 10 ); |
90 | - add_action( 'wp_enqueue_scripts', array( 'EED_Ticket_Selector', 'load_tckt_slctr_assets' ), 10 ); |
|
90 | + add_action('wp_enqueue_scripts', array('EED_Ticket_Selector', 'load_tckt_slctr_assets'), 10); |
|
91 | 91 | } |
92 | 92 | |
93 | 93 | |
@@ -99,10 +99,10 @@ discard block |
||
99 | 99 | * @return void |
100 | 100 | */ |
101 | 101 | public static function set_hooks_admin() { |
102 | - add_action( 'wp_loaded', array( 'EED_Ticket_Selector', 'set_definitions' ), 2 ); |
|
102 | + add_action('wp_loaded', array('EED_Ticket_Selector', 'set_definitions'), 2); |
|
103 | 103 | //add button for iframe code to event editor. |
104 | - add_filter( 'get_sample_permalink_html', array( 'EED_Ticket_Selector', 'iframe_code_button' ), 10, 4 ); |
|
105 | - add_action( 'admin_enqueue_scripts', array( 'EED_Ticket_Selector', 'load_tckt_slctr_assets_admin' ), 10 ); |
|
104 | + add_filter('get_sample_permalink_html', array('EED_Ticket_Selector', 'iframe_code_button'), 10, 4); |
|
105 | + add_action('admin_enqueue_scripts', array('EED_Ticket_Selector', 'load_tckt_slctr_assets_admin'), 10); |
|
106 | 106 | } |
107 | 107 | |
108 | 108 | |
@@ -114,15 +114,15 @@ discard block |
||
114 | 114 | * @return void |
115 | 115 | */ |
116 | 116 | public static function set_definitions() { |
117 | - define( 'TICKET_SELECTOR_ASSETS_URL', plugin_dir_url( __FILE__ ) . 'assets' . DS ); |
|
118 | - define( 'TICKET_SELECTOR_TEMPLATES_PATH', str_replace( '\\', DS, plugin_dir_path( __FILE__ )) . 'templates' . DS ); |
|
117 | + define('TICKET_SELECTOR_ASSETS_URL', plugin_dir_url(__FILE__).'assets'.DS); |
|
118 | + define('TICKET_SELECTOR_TEMPLATES_PATH', str_replace('\\', DS, plugin_dir_path(__FILE__)).'templates'.DS); |
|
119 | 119 | |
120 | 120 | //if config is not set, initialize |
121 | 121 | //If config is not set, set it. |
122 | - if ( ! isset( EE_Registry::instance()->CFG->template_settings->EED_Ticket_Selector ) ) { |
|
122 | + if ( ! isset(EE_Registry::instance()->CFG->template_settings->EED_Ticket_Selector)) { |
|
123 | 123 | EE_Registry::instance()->CFG->template_settings->EED_Ticket_Selector = new EE_Ticket_Selector_Config(); |
124 | 124 | } |
125 | - EE_Registry::$i18n_js_strings[ 'ts_embed_iframe_title' ] = __( 'Copy and Paste the following:', 'event_espresso' ); |
|
125 | + EE_Registry::$i18n_js_strings['ts_embed_iframe_title'] = __('Copy and Paste the following:', 'event_espresso'); |
|
126 | 126 | } |
127 | 127 | |
128 | 128 | |
@@ -133,7 +133,7 @@ discard block |
||
133 | 133 | * @param object $WP |
134 | 134 | * @return void |
135 | 135 | */ |
136 | - public function run( $WP ) {} |
|
136 | + public function run($WP) {} |
|
137 | 137 | |
138 | 138 | |
139 | 139 | /** |
@@ -145,23 +145,23 @@ discard block |
||
145 | 145 | public function ticket_selector_iframe() { |
146 | 146 | self::$_in_iframe = true; |
147 | 147 | /** @type EEM_Event $EEM_Event */ |
148 | - $EEM_Event = EE_Registry::instance()->load_model( 'Event' ); |
|
148 | + $EEM_Event = EE_Registry::instance()->load_model('Event'); |
|
149 | 149 | $event = $EEM_Event->get_one_by_ID( |
150 | - EE_Registry::instance()->REQ->get( 'event', 0 ) |
|
150 | + EE_Registry::instance()->REQ->get('event', 0) |
|
151 | 151 | ); |
152 | - EE_Registry::instance()->REQ->set_espresso_page( true ); |
|
153 | - $template_args['ticket_selector'] = EED_Ticket_Selector::display_ticket_selector( $event ); |
|
152 | + EE_Registry::instance()->REQ->set_espresso_page(true); |
|
153 | + $template_args['ticket_selector'] = EED_Ticket_Selector::display_ticket_selector($event); |
|
154 | 154 | $template_args['css'] = apply_filters( |
155 | 155 | 'FHEE__EED_Ticket_Selector__ticket_selector_iframe__css', |
156 | 156 | array( |
157 | - TICKET_SELECTOR_ASSETS_URL . 'ticket_selector_embed.css?ver=' . EVENT_ESPRESSO_VERSION, |
|
158 | - TICKET_SELECTOR_ASSETS_URL . 'ticket_selector.css?ver=' . EVENT_ESPRESSO_VERSION, |
|
159 | - includes_url( 'css/dashicons.min.css?ver=' . $GLOBALS['wp_version'] ), |
|
160 | - EE_GLOBAL_ASSETS_URL . 'css/espresso_default.css?ver=' . EVENT_ESPRESSO_VERSION |
|
157 | + TICKET_SELECTOR_ASSETS_URL.'ticket_selector_embed.css?ver='.EVENT_ESPRESSO_VERSION, |
|
158 | + TICKET_SELECTOR_ASSETS_URL.'ticket_selector.css?ver='.EVENT_ESPRESSO_VERSION, |
|
159 | + includes_url('css/dashicons.min.css?ver='.$GLOBALS['wp_version']), |
|
160 | + EE_GLOBAL_ASSETS_URL.'css/espresso_default.css?ver='.EVENT_ESPRESSO_VERSION |
|
161 | 161 | ) |
162 | 162 | ); |
163 | - EE_Registry::$i18n_js_strings[ 'ticket_selector_iframe' ] = true; |
|
164 | - EE_Registry::$i18n_js_strings[ 'EEDTicketSelectorMsg' ] = __( 'Please choose at least one ticket before continuing.', 'event_espresso' ); |
|
163 | + EE_Registry::$i18n_js_strings['ticket_selector_iframe'] = true; |
|
164 | + EE_Registry::$i18n_js_strings['EEDTicketSelectorMsg'] = __('Please choose at least one ticket before continuing.', 'event_espresso'); |
|
165 | 165 | $template_args['eei18n'] = apply_filters( |
166 | 166 | 'FHEE__EED_Ticket_Selector__ticket_selector_iframe__eei18n_js_strings', |
167 | 167 | EE_Registry::localize_i18n_js_strings() |
@@ -169,19 +169,19 @@ discard block |
||
169 | 169 | $template_args['js'] = apply_filters( |
170 | 170 | 'FHEE__EED_Ticket_Selector__ticket_selector_iframe__js', |
171 | 171 | array( |
172 | - includes_url( 'js/jquery/jquery.js?ver=' . $GLOBALS['wp_version'] ), |
|
173 | - EE_GLOBAL_ASSETS_URL . 'scripts/espresso_core.js?ver=' . EVENT_ESPRESSO_VERSION, |
|
174 | - TICKET_SELECTOR_ASSETS_URL . 'ticket_selector_iframe_embed.js?ver=' . EVENT_ESPRESSO_VERSION |
|
172 | + includes_url('js/jquery/jquery.js?ver='.$GLOBALS['wp_version']), |
|
173 | + EE_GLOBAL_ASSETS_URL.'scripts/espresso_core.js?ver='.EVENT_ESPRESSO_VERSION, |
|
174 | + TICKET_SELECTOR_ASSETS_URL.'ticket_selector_iframe_embed.js?ver='.EVENT_ESPRESSO_VERSION |
|
175 | 175 | ) |
176 | 176 | ); |
177 | 177 | EE_Registry::instance()->load_helper('Template'); |
178 | - $template_args[ 'notices' ] = EEH_Template::display_template( |
|
179 | - EE_TEMPLATES . 'espresso-ajax-notices.template.php', |
|
178 | + $template_args['notices'] = EEH_Template::display_template( |
|
179 | + EE_TEMPLATES.'espresso-ajax-notices.template.php', |
|
180 | 180 | array(), |
181 | 181 | true |
182 | 182 | ); |
183 | 183 | EEH_Template::display_template( |
184 | - TICKET_SELECTOR_TEMPLATES_PATH . 'ticket_selector_chart_iframe.template.php', |
|
184 | + TICKET_SELECTOR_TEMPLATES_PATH.'ticket_selector_chart_iframe.template.php', |
|
185 | 185 | $template_args |
186 | 186 | ); |
187 | 187 | exit; |
@@ -200,23 +200,23 @@ discard block |
||
200 | 200 | * |
201 | 201 | * @return string The new html string for the permalink area. |
202 | 202 | */ |
203 | - public static function iframe_code_button( $permalink_string, $id, $new_title, $new_slug ) { |
|
203 | + public static function iframe_code_button($permalink_string, $id, $new_title, $new_slug) { |
|
204 | 204 | //make sure this is ONLY when editing and the event id has been set. |
205 | - if ( ! empty( $id ) ) { |
|
206 | - $post = get_post( $id ); |
|
205 | + if ( ! empty($id)) { |
|
206 | + $post = get_post($id); |
|
207 | 207 | |
208 | 208 | //if NOT event then let's get out. |
209 | - if ( $post->post_type !== 'espresso_events' ) { |
|
209 | + if ($post->post_type !== 'espresso_events') { |
|
210 | 210 | return $permalink_string; |
211 | 211 | } |
212 | 212 | |
213 | - $ticket_selector_url = add_query_arg( array( 'ticket_selector' => 'iframe', 'event' => $id ), site_url() ); |
|
213 | + $ticket_selector_url = add_query_arg(array('ticket_selector' => 'iframe', 'event' => $id), site_url()); |
|
214 | 214 | |
215 | - $permalink_string .= '<a id="js-ticket-selector-embed-trigger" class="button button-small" href="#" tabindex="-1">' . __('Embed', 'event_espresso') . '</a> '; |
|
215 | + $permalink_string .= '<a id="js-ticket-selector-embed-trigger" class="button button-small" href="#" tabindex="-1">'.__('Embed', 'event_espresso').'</a> '; |
|
216 | 216 | $permalink_string .= ' |
217 | 217 | <div id="js-ts-iframe" style="display:none"> |
218 | 218 | <div style="width:100%; height: 500px;"> |
219 | - <iframe src="' . $ticket_selector_url . '" width="100%" height="100%"></iframe> |
|
219 | + <iframe src="' . $ticket_selector_url.'" width="100%" height="100%"></iframe> |
|
220 | 220 | </div> |
221 | 221 | </div>'; |
222 | 222 | } |
@@ -235,22 +235,22 @@ discard block |
||
235 | 235 | * @param mixed $event |
236 | 236 | * @return bool |
237 | 237 | */ |
238 | - protected static function set_event( $event = null ) { |
|
239 | - if( $event === null ) { |
|
238 | + protected static function set_event($event = null) { |
|
239 | + if ($event === null) { |
|
240 | 240 | global $post; |
241 | 241 | $event = $post; |
242 | 242 | } |
243 | - if ( $event instanceof EE_Event ) { |
|
243 | + if ($event instanceof EE_Event) { |
|
244 | 244 | self::$_event = $event; |
245 | - } else if ( $event instanceof WP_Post && isset( $event->EE_Event ) && $event->EE_Event instanceof EE_Event ) { |
|
245 | + } else if ($event instanceof WP_Post && isset($event->EE_Event) && $event->EE_Event instanceof EE_Event) { |
|
246 | 246 | self::$_event = $event->EE_Event; |
247 | - } else if ( $event instanceof WP_Post && $event->post_type == 'espresso_events' ) { |
|
248 | - $event->EE_Event = EEM_Event::instance()->instantiate_class_from_post_object( $event ); |
|
247 | + } else if ($event instanceof WP_Post && $event->post_type == 'espresso_events') { |
|
248 | + $event->EE_Event = EEM_Event::instance()->instantiate_class_from_post_object($event); |
|
249 | 249 | self::$_event = $event->EE_Event; |
250 | 250 | } else { |
251 | - $user_msg = __( 'No Event object or an invalid Event object was supplied.', 'event_espresso' ); |
|
252 | - $dev_msg = $user_msg . __( 'In order to generate a ticket selector, please ensure you are passing either an EE_Event object or a WP_Post object of the post type "espresso_event" to the EE_Ticket_Selector class constructor.', 'event_espresso' ); |
|
253 | - EE_Error::add_error( $user_msg . '||' . $dev_msg, __FILE__, __FUNCTION__, __LINE__ ); |
|
251 | + $user_msg = __('No Event object or an invalid Event object was supplied.', 'event_espresso'); |
|
252 | + $dev_msg = $user_msg.__('In order to generate a ticket selector, please ensure you are passing either an EE_Event object or a WP_Post object of the post type "espresso_event" to the EE_Ticket_Selector class constructor.', 'event_espresso'); |
|
253 | + EE_Error::add_error($user_msg.'||'.$dev_msg, __FILE__, __FUNCTION__, __LINE__); |
|
254 | 254 | return false; |
255 | 255 | } |
256 | 256 | return true; |
@@ -269,11 +269,11 @@ discard block |
||
269 | 269 | * @param bool $view_details |
270 | 270 | * @return string |
271 | 271 | */ |
272 | - public static function display_ticket_selector( $event = NULL, $view_details = FALSE ) { |
|
272 | + public static function display_ticket_selector($event = NULL, $view_details = FALSE) { |
|
273 | 273 | // reset filter for displaying submit button |
274 | - remove_filter( 'FHEE__EE_Ticket_Selector__display_ticket_selector_submit', '__return_true' ); |
|
274 | + remove_filter('FHEE__EE_Ticket_Selector__display_ticket_selector_submit', '__return_true'); |
|
275 | 275 | // poke and prod incoming event till it tells us what it is |
276 | - if ( ! EED_Ticket_Selector::set_event( $event )) { |
|
276 | + if ( ! EED_Ticket_Selector::set_event($event)) { |
|
277 | 277 | return false; |
278 | 278 | } |
279 | 279 | $event_post = self::$_event instanceof EE_Event ? self::$_event->ID() : $event; |
@@ -284,7 +284,7 @@ discard block |
||
284 | 284 | && ( |
285 | 285 | ! self::$_event->display_ticket_selector() |
286 | 286 | || $view_details |
287 | - || post_password_required( $event_post ) |
|
287 | + || post_password_required($event_post) |
|
288 | 288 | || ( |
289 | 289 | $_event_active_status != EE_Datetime::active |
290 | 290 | && $_event_active_status != EE_Datetime::upcoming |
@@ -302,70 +302,70 @@ discard block |
||
302 | 302 | $template_args = array(); |
303 | 303 | $template_args['event_status'] = $_event_active_status; |
304 | 304 | |
305 | - $template_args['date_format'] = apply_filters( 'FHEE__EED_Ticket_Selector__display_ticket_selector__date_format', get_option( 'date_format' ) ); |
|
306 | - $template_args['time_format'] = apply_filters( 'FHEE__EED_Ticket_Selector__display_ticket_selector__time_format', get_option( 'time_format' ) ); |
|
305 | + $template_args['date_format'] = apply_filters('FHEE__EED_Ticket_Selector__display_ticket_selector__date_format', get_option('date_format')); |
|
306 | + $template_args['time_format'] = apply_filters('FHEE__EED_Ticket_Selector__display_ticket_selector__time_format', get_option('time_format')); |
|
307 | 307 | |
308 | 308 | $template_args['EVT_ID'] = self::$_event->ID(); |
309 | 309 | $template_args['event'] = self::$_event; |
310 | 310 | |
311 | 311 | // is the event expired ? |
312 | 312 | $template_args['event_is_expired'] = self::$_event->is_expired(); |
313 | - if ( $template_args['event_is_expired'] ) { |
|
314 | - return '<div class="ee-event-expired-notice"><span class="important-notice">' . __( 'We\'re sorry, but all tickets sales have ended because the event is expired.', 'event_espresso' ) . '</span></div>'; |
|
313 | + if ($template_args['event_is_expired']) { |
|
314 | + return '<div class="ee-event-expired-notice"><span class="important-notice">'.__('We\'re sorry, but all tickets sales have ended because the event is expired.', 'event_espresso').'</span></div>'; |
|
315 | 315 | } |
316 | 316 | |
317 | 317 | $ticket_query_args = array( |
318 | - array( 'Datetime.EVT_ID' => self::$_event->ID() ), |
|
319 | - 'order_by' => array( 'TKT_order' => 'ASC', 'TKT_required' => 'DESC', 'TKT_start_date' => 'ASC', 'TKT_end_date' => 'ASC' , 'Datetime.DTT_EVT_start' => 'DESC' ) |
|
318 | + array('Datetime.EVT_ID' => self::$_event->ID()), |
|
319 | + 'order_by' => array('TKT_order' => 'ASC', 'TKT_required' => 'DESC', 'TKT_start_date' => 'ASC', 'TKT_end_date' => 'ASC', 'Datetime.DTT_EVT_start' => 'DESC') |
|
320 | 320 | ); |
321 | 321 | |
322 | - if ( ! EE_Registry::instance()->CFG->template_settings->EED_Ticket_Selector->show_expired_tickets ) { |
|
322 | + if ( ! EE_Registry::instance()->CFG->template_settings->EED_Ticket_Selector->show_expired_tickets) { |
|
323 | 323 | //use the correct applicable time query depending on what version of core is being run. |
324 | - $current_time = method_exists( 'EEM_Datetime', 'current_time_for_query' ) ? time() : current_time('timestamp'); |
|
325 | - $ticket_query_args[0]['TKT_end_date'] = array( '>', $current_time ); |
|
324 | + $current_time = method_exists('EEM_Datetime', 'current_time_for_query') ? time() : current_time('timestamp'); |
|
325 | + $ticket_query_args[0]['TKT_end_date'] = array('>', $current_time); |
|
326 | 326 | } |
327 | 327 | |
328 | 328 | // get all tickets for this event ordered by the datetime |
329 | - $template_args['tickets'] = EEM_Ticket::instance()->get_all( $ticket_query_args ); |
|
329 | + $template_args['tickets'] = EEM_Ticket::instance()->get_all($ticket_query_args); |
|
330 | 330 | |
331 | - if ( count( $template_args['tickets'] ) < 1 ) { |
|
332 | - return '<div class="ee-event-expired-notice"><span class="important-notice">' . __( 'We\'re sorry, but all ticket sales have ended.', 'event_espresso' ) . '</span></div>'; |
|
331 | + if (count($template_args['tickets']) < 1) { |
|
332 | + return '<div class="ee-event-expired-notice"><span class="important-notice">'.__('We\'re sorry, but all ticket sales have ended.', 'event_espresso').'</span></div>'; |
|
333 | 333 | } |
334 | 334 | |
335 | 335 | // filter the maximum qty that can appear in the Ticket Selector qty dropdowns |
336 | - $template_args['max_atndz'] = apply_filters('FHEE__EE_Ticket_Selector__display_ticket_selector__max_tickets', self::$_event->additional_limit() ); |
|
337 | - if ( $template_args['max_atndz'] < 1 ) { |
|
338 | - $sales_closed_msg = __( 'We\'re sorry, but ticket sales have been closed at this time. Please check back again later.', 'event_espresso' ); |
|
339 | - if ( current_user_can( 'edit_post', self::$_event->ID() )) { |
|
340 | - $sales_closed_msg .= sprintf( |
|
341 | - __( '%sNote to Event Admin:%sThe "Maximum number of tickets allowed per order for this event" in the Event Registration Options has been set to "0". This effectively turns off ticket sales. %s(click to edit this event)%s', 'event_espresso' ), |
|
336 | + $template_args['max_atndz'] = apply_filters('FHEE__EE_Ticket_Selector__display_ticket_selector__max_tickets', self::$_event->additional_limit()); |
|
337 | + if ($template_args['max_atndz'] < 1) { |
|
338 | + $sales_closed_msg = __('We\'re sorry, but ticket sales have been closed at this time. Please check back again later.', 'event_espresso'); |
|
339 | + if (current_user_can('edit_post', self::$_event->ID())) { |
|
340 | + $sales_closed_msg .= sprintf( |
|
341 | + __('%sNote to Event Admin:%sThe "Maximum number of tickets allowed per order for this event" in the Event Registration Options has been set to "0". This effectively turns off ticket sales. %s(click to edit this event)%s', 'event_espresso'), |
|
342 | 342 | '<div class="ee-attention" style="text-align: left;"><b>', |
343 | 343 | '</b><br />', |
344 | - $link = '<span class="edit-link"><a class="post-edit-link" href="' . get_edit_post_link( self::$_event->ID() ) . '">', |
|
344 | + $link = '<span class="edit-link"><a class="post-edit-link" href="'.get_edit_post_link(self::$_event->ID()).'">', |
|
345 | 345 | '</a></span></div>' |
346 | 346 | ); |
347 | 347 | } |
348 | - return '<p><span class="important-notice">' . $sales_closed_msg . '</span></p>'; |
|
348 | + return '<p><span class="important-notice">'.$sales_closed_msg.'</span></p>'; |
|
349 | 349 | } |
350 | 350 | |
351 | - $templates['ticket_selector'] = TICKET_SELECTOR_TEMPLATES_PATH . 'ticket_selector_chart.template.php'; |
|
352 | - $templates['ticket_selector'] = apply_filters( 'FHEE__EE_Ticket_Selector__display_ticket_selector__template_path', $templates['ticket_selector'], self::$_event ); |
|
351 | + $templates['ticket_selector'] = TICKET_SELECTOR_TEMPLATES_PATH.'ticket_selector_chart.template.php'; |
|
352 | + $templates['ticket_selector'] = apply_filters('FHEE__EE_Ticket_Selector__display_ticket_selector__template_path', $templates['ticket_selector'], self::$_event); |
|
353 | 353 | |
354 | 354 | // redirecting to another site for registration ?? |
355 | 355 | $external_url = self::$_event->external_url() !== NULL || self::$_event->external_url() !== '' ? self::$_event->external_url() : FALSE; |
356 | 356 | // set up the form (but not for the admin) |
357 | - $ticket_selector = ! is_admin() ? EED_Ticket_Selector::ticket_selector_form_open( self::$_event->ID(), $external_url ) : ''; |
|
357 | + $ticket_selector = ! is_admin() ? EED_Ticket_Selector::ticket_selector_form_open(self::$_event->ID(), $external_url) : ''; |
|
358 | 358 | // if not redirecting to another site for registration |
359 | - if ( ! $external_url ) { |
|
360 | - EE_Registry::instance()->load_helper( 'Template' ); |
|
361 | - EE_Registry::instance()->load_helper( 'URL' ); |
|
359 | + if ( ! $external_url) { |
|
360 | + EE_Registry::instance()->load_helper('Template'); |
|
361 | + EE_Registry::instance()->load_helper('URL'); |
|
362 | 362 | // then display the ticket selector |
363 | - $ticket_selector .= EEH_Template::locate_template( $templates['ticket_selector'], $template_args ); |
|
363 | + $ticket_selector .= EEH_Template::locate_template($templates['ticket_selector'], $template_args); |
|
364 | 364 | } else { |
365 | 365 | // if not we still need to trigger the display of the submit button |
366 | - add_filter( 'FHEE__EE_Ticket_Selector__display_ticket_selector_submit', '__return_true' ); |
|
366 | + add_filter('FHEE__EE_Ticket_Selector__display_ticket_selector_submit', '__return_true'); |
|
367 | 367 | //display notice to admin that registration is external |
368 | - $ticket_selector .= ! is_admin() ? '' : __( 'Registration is at an external URL for this event.', 'event_espresso' ); |
|
368 | + $ticket_selector .= ! is_admin() ? '' : __('Registration is at an external URL for this event.', 'event_espresso'); |
|
369 | 369 | } |
370 | 370 | // submit button and form close tag |
371 | 371 | $ticket_selector .= ! is_admin() ? EED_Ticket_Selector::display_ticket_selector_submit() : ''; |
@@ -385,27 +385,27 @@ discard block |
||
385 | 385 | * @param string $external_url |
386 | 386 | * @return string |
387 | 387 | */ |
388 | - public static function ticket_selector_form_open( $ID = 0, $external_url = '' ) { |
|
388 | + public static function ticket_selector_form_open($ID = 0, $external_url = '') { |
|
389 | 389 | // if redirecting, we don't need any anything else |
390 | - if ( $external_url ) { |
|
391 | - EE_Registry::instance()->load_helper( 'URL' ); |
|
392 | - $html = '<form method="GET" action="' . EEH_URL::refactor_url( $external_url ) . '">'; |
|
393 | - $query_args = EEH_URL::get_query_string( $external_url ); |
|
394 | - foreach ( $query_args as $query_arg => $value ) { |
|
395 | - $html .= '<input type="hidden" name="' . $query_arg . '" value="' . $value . '">'; |
|
390 | + if ($external_url) { |
|
391 | + EE_Registry::instance()->load_helper('URL'); |
|
392 | + $html = '<form method="GET" action="'.EEH_URL::refactor_url($external_url).'">'; |
|
393 | + $query_args = EEH_URL::get_query_string($external_url); |
|
394 | + foreach ($query_args as $query_arg => $value) { |
|
395 | + $html .= '<input type="hidden" name="'.$query_arg.'" value="'.$value.'">'; |
|
396 | 396 | } |
397 | 397 | return $html; |
398 | 398 | } |
399 | - EE_Registry::instance()->load_helper( 'Event_View' ); |
|
400 | - $checkout_url = EEH_Event_View::event_link_url( $ID ); |
|
401 | - if ( ! $checkout_url ) { |
|
402 | - EE_Error::add_error( __('The URL for the Event Details page could not be retrieved.', 'event_espresso' ), __FILE__, __FUNCTION__, __LINE__ ); |
|
399 | + EE_Registry::instance()->load_helper('Event_View'); |
|
400 | + $checkout_url = EEH_Event_View::event_link_url($ID); |
|
401 | + if ( ! $checkout_url) { |
|
402 | + EE_Error::add_error(__('The URL for the Event Details page could not be retrieved.', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__); |
|
403 | 403 | } |
404 | 404 | $extra_params = self::$_in_iframe ? ' target="_blank"' : ''; |
405 | - $html = '<form method="POST" action="' . $checkout_url . '"' . $extra_params . '>'; |
|
406 | - $html .= wp_nonce_field( 'process_ticket_selections', 'process_ticket_selections_nonce', TRUE, FALSE ); |
|
405 | + $html = '<form method="POST" action="'.$checkout_url.'"'.$extra_params.'>'; |
|
406 | + $html .= wp_nonce_field('process_ticket_selections', 'process_ticket_selections_nonce', TRUE, FALSE); |
|
407 | 407 | $html .= '<input type="hidden" name="ee" value="process_ticket_selections">'; |
408 | - $html = apply_filters( 'FHEE__EE_Ticket_Selector__ticket_selector_form_open__html', $html, self::$_event ); |
|
408 | + $html = apply_filters('FHEE__EE_Ticket_Selector__ticket_selector_form_open__html', $html, self::$_event); |
|
409 | 409 | return $html; |
410 | 410 | } |
411 | 411 | |
@@ -420,21 +420,21 @@ discard block |
||
420 | 420 | * @return string |
421 | 421 | */ |
422 | 422 | public static function display_ticket_selector_submit() { |
423 | - if ( ! is_admin() ) { |
|
424 | - if ( apply_filters( 'FHEE__EE_Ticket_Selector__display_ticket_selector_submit', FALSE ) ) { |
|
423 | + if ( ! is_admin()) { |
|
424 | + if (apply_filters('FHEE__EE_Ticket_Selector__display_ticket_selector_submit', FALSE)) { |
|
425 | 425 | $btn_text = apply_filters( |
426 | 426 | 'FHEE__EE_Ticket_Selector__display_ticket_selector_submit__btn_text', |
427 | - __('Register Now', 'event_espresso' ), |
|
427 | + __('Register Now', 'event_espresso'), |
|
428 | 428 | self::$_event |
429 | 429 | ); |
430 | - $html = '<input id="ticket-selector-submit-'. self::$_event->ID() .'-btn"'; |
|
430 | + $html = '<input id="ticket-selector-submit-'.self::$_event->ID().'-btn"'; |
|
431 | 431 | $html .= ' class="ticket-selector-submit-btn ticket-selector-submit-ajax"'; |
432 | - $html .= ' type="submit" value="' . $btn_text . '" />'; |
|
433 | - $html .= apply_filters( 'FHEE__EE_Ticket_Selector__after_ticket_selector_submit', '', self::$_event ); |
|
432 | + $html .= ' type="submit" value="'.$btn_text.'" />'; |
|
433 | + $html .= apply_filters('FHEE__EE_Ticket_Selector__after_ticket_selector_submit', '', self::$_event); |
|
434 | 434 | $html .= '<div class="clear"><br/></div></form>'; |
435 | 435 | return $html; |
436 | - } else if ( is_archive() ) { |
|
437 | - return EED_Ticket_Selector::ticket_selector_form_close() . EED_Ticket_Selector::display_view_details_btn(); |
|
436 | + } else if (is_archive()) { |
|
437 | + return EED_Ticket_Selector::ticket_selector_form_close().EED_Ticket_Selector::display_view_details_btn(); |
|
438 | 438 | } |
439 | 439 | } |
440 | 440 | return ''; |
@@ -466,13 +466,13 @@ discard block |
||
466 | 466 | * @return string |
467 | 467 | */ |
468 | 468 | public static function display_view_details_btn() { |
469 | - if ( ! self::$_event->get_permalink() ) { |
|
470 | - EE_Error::add_error( __('The URL for the Event Details page could not be retrieved.', 'event_espresso' ), __FILE__, __FUNCTION__, __LINE__ ); |
|
469 | + if ( ! self::$_event->get_permalink()) { |
|
470 | + EE_Error::add_error(__('The URL for the Event Details page could not be retrieved.', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__); |
|
471 | 471 | } |
472 | - $view_details_btn = '<form method="POST" action="' . self::$_event->get_permalink() . '">'; |
|
473 | - $btn_text = apply_filters( 'FHEE__EE_Ticket_Selector__display_view_details_btn__btn_text', __( 'View Details', 'event_espresso' ), self::$_event ); |
|
474 | - $view_details_btn .= '<input id="ticket-selector-submit-'. self::$_event->ID() .'-btn" class="ticket-selector-submit-btn view-details-btn" type="submit" value="' . $btn_text . '" />'; |
|
475 | - $view_details_btn .= apply_filters( 'FHEE__EE_Ticket_Selector__after_view_details_btn', '', self::$_event ); |
|
472 | + $view_details_btn = '<form method="POST" action="'.self::$_event->get_permalink().'">'; |
|
473 | + $btn_text = apply_filters('FHEE__EE_Ticket_Selector__display_view_details_btn__btn_text', __('View Details', 'event_espresso'), self::$_event); |
|
474 | + $view_details_btn .= '<input id="ticket-selector-submit-'.self::$_event->ID().'-btn" class="ticket-selector-submit-btn view-details-btn" type="submit" value="'.$btn_text.'" />'; |
|
475 | + $view_details_btn .= apply_filters('FHEE__EE_Ticket_Selector__after_view_details_btn', '', self::$_event); |
|
476 | 476 | $view_details_btn .= '<div class="clear"><br/></div>'; |
477 | 477 | $view_details_btn .= '</form>'; |
478 | 478 | return $view_details_btn; |
@@ -491,11 +491,11 @@ discard block |
||
491 | 491 | * @return array or FALSE |
492 | 492 | */ |
493 | 493 | public function process_ticket_selections() { |
494 | - do_action( 'EED_Ticket_Selector__process_ticket_selections__before' ); |
|
494 | + do_action('EED_Ticket_Selector__process_ticket_selections__before'); |
|
495 | 495 | // check nonce |
496 | - if ( ! is_admin() && ( ! EE_Registry::instance()->REQ->is_set( 'process_ticket_selections_nonce' ) || ! wp_verify_nonce( EE_Registry::instance()->REQ->get( 'process_ticket_selections_nonce' ), 'process_ticket_selections' ))) { |
|
496 | + if ( ! is_admin() && ( ! EE_Registry::instance()->REQ->is_set('process_ticket_selections_nonce') || ! wp_verify_nonce(EE_Registry::instance()->REQ->get('process_ticket_selections_nonce'), 'process_ticket_selections'))) { |
|
497 | 497 | EE_Error::add_error( |
498 | - sprintf( __( 'We\'re sorry but your request failed to pass a security check.%sPlease click the back button on your browser and try again.', 'event_espresso' ), '<br/>' ), |
|
498 | + sprintf(__('We\'re sorry but your request failed to pass a security check.%sPlease click the back button on your browser and try again.', 'event_espresso'), '<br/>'), |
|
499 | 499 | __FILE__, __FUNCTION__, __LINE__ |
500 | 500 | ); |
501 | 501 | return FALSE; |
@@ -509,16 +509,16 @@ discard block |
||
509 | 509 | |
510 | 510 | //we should really only have 1 registration in the works now (ie, no MER) so clear any previous items in the cart. |
511 | 511 | // When MER happens this will probably need to be tweaked, possibly wrapped in a conditional checking for some constant defined in MER etc. |
512 | - EE_Registry::instance()->load_core( 'Session' ); |
|
512 | + EE_Registry::instance()->load_core('Session'); |
|
513 | 513 | // unless otherwise requested, clear the session |
514 | - if ( apply_filters( 'FHEE__EE_Ticket_Selector__process_ticket_selections__clear_session', TRUE )) { |
|
515 | - EE_Registry::instance()->SSN->clear_session( __CLASS__, __FUNCTION__ ); |
|
514 | + if (apply_filters('FHEE__EE_Ticket_Selector__process_ticket_selections__clear_session', TRUE)) { |
|
515 | + EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__); |
|
516 | 516 | } |
517 | 517 | //d( EE_Registry::instance()->SSN ); |
518 | 518 | |
519 | - do_action( 'AHEE_log', __FILE__, __FUNCTION__, '' ); |
|
519 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
520 | 520 | // do we have an event id? |
521 | - if ( EE_Registry::instance()->REQ->is_set( 'tkt-slctr-event-id' ) ) { |
|
521 | + if (EE_Registry::instance()->REQ->is_set('tkt-slctr-event-id')) { |
|
522 | 522 | // validate/sanitize data |
523 | 523 | $valid = self::_validate_post_data(); |
524 | 524 | |
@@ -528,43 +528,43 @@ discard block |
||
528 | 528 | //EEH_Debug_Tools::printr( $valid[ 'max_atndz' ], 'max_atndz', __FILE__, __LINE__ ); |
529 | 529 | |
530 | 530 | //check total tickets ordered vs max number of attendees that can register |
531 | - if ( $valid['total_tickets'] > $valid['max_atndz'] ) { |
|
531 | + if ($valid['total_tickets'] > $valid['max_atndz']) { |
|
532 | 532 | |
533 | 533 | // ordering too many tickets !!! |
534 | 534 | $singular = 'You have attempted to purchase %s ticket.'; |
535 | 535 | $plural = 'You have attempted to purchase %s tickets.'; |
536 | - $limit_error_1 = sprintf( _n( $singular, $plural, $valid['total_tickets'], 'event_espresso' ), $valid['total_tickets'], $valid['total_tickets'] ); |
|
536 | + $limit_error_1 = sprintf(_n($singular, $plural, $valid['total_tickets'], 'event_espresso'), $valid['total_tickets'], $valid['total_tickets']); |
|
537 | 537 | // dev only message |
538 | 538 | $singular = 'The registration limit for this event is %s ticket per registration, therefore the total number of tickets you may purchase at a time can not exceed %s.'; |
539 | 539 | $plural = 'The registration limit for this event is %s tickets per registration, therefore the total number of tickets you may purchase at a time can not exceed %s.'; |
540 | - $limit_error_2 = sprintf( _n( $singular, $plural, $valid['max_atndz'], 'event_espresso' ), $valid['max_atndz'], $valid['max_atndz'] ); |
|
541 | - EE_Error::add_error( $limit_error_1 . '<br/>' . $limit_error_2, __FILE__, __FUNCTION__, __LINE__ ); |
|
540 | + $limit_error_2 = sprintf(_n($singular, $plural, $valid['max_atndz'], 'event_espresso'), $valid['max_atndz'], $valid['max_atndz']); |
|
541 | + EE_Error::add_error($limit_error_1.'<br/>'.$limit_error_2, __FILE__, __FUNCTION__, __LINE__); |
|
542 | 542 | } else { |
543 | 543 | |
544 | 544 | // all data appears to be valid |
545 | 545 | $tckts_slctd = FALSE; |
546 | 546 | $success = TRUE; |
547 | 547 | // load cart |
548 | - EE_Registry::instance()->load_core( 'Cart' ); |
|
548 | + EE_Registry::instance()->load_core('Cart'); |
|
549 | 549 | |
550 | 550 | // cycle thru the number of data rows sent from the event listing |
551 | - for ( $x = 0; $x < $valid['rows']; $x++ ) { |
|
551 | + for ($x = 0; $x < $valid['rows']; $x++) { |
|
552 | 552 | // does this row actually contain a ticket quantity? |
553 | - if ( isset( $valid['qty'][$x] ) && $valid['qty'][$x] > 0 ) { |
|
553 | + if (isset($valid['qty'][$x]) && $valid['qty'][$x] > 0) { |
|
554 | 554 | // YES we have a ticket quantity |
555 | 555 | $tckts_slctd = TRUE; |
556 | 556 | // d( $valid['ticket_obj'][$x] ); |
557 | - if ( $valid['ticket_obj'][$x] instanceof EE_Ticket ) { |
|
557 | + if ($valid['ticket_obj'][$x] instanceof EE_Ticket) { |
|
558 | 558 | // then add ticket to cart |
559 | - $ticket_added = self::_add_ticket_to_cart( $valid['ticket_obj'][$x], $valid['qty'][$x] ); |
|
559 | + $ticket_added = self::_add_ticket_to_cart($valid['ticket_obj'][$x], $valid['qty'][$x]); |
|
560 | 560 | $success = ! $ticket_added ? FALSE : $success; |
561 | - if ( EE_Error::has_error() ) { |
|
561 | + if (EE_Error::has_error()) { |
|
562 | 562 | break; |
563 | 563 | } |
564 | 564 | } else { |
565 | 565 | // nothing added to cart retrieved |
566 | 566 | EE_Error::add_error( |
567 | - sprintf( __( 'A valid ticket could not be retrieved for the event.%sPlease click the back button on your browser and try again.', 'event_espresso' ), '<br/>' ), |
|
567 | + sprintf(__('A valid ticket could not be retrieved for the event.%sPlease click the back button on your browser and try again.', 'event_espresso'), '<br/>'), |
|
568 | 568 | __FILE__, __FUNCTION__, __LINE__ |
569 | 569 | ); |
570 | 570 | } |
@@ -573,45 +573,45 @@ discard block |
||
573 | 573 | //d( EE_Registry::instance()->CART ); |
574 | 574 | //die(); // <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< KILL REDIRECT HERE BEFORE CART UPDATE |
575 | 575 | |
576 | - if ( $tckts_slctd ) { |
|
577 | - if ( $success ) { |
|
578 | - do_action( 'FHEE__EE_Ticket_Selector__process_ticket_selections__before_redirecting_to_checkout', EE_Registry::instance()->CART, $this ); |
|
576 | + if ($tckts_slctd) { |
|
577 | + if ($success) { |
|
578 | + do_action('FHEE__EE_Ticket_Selector__process_ticket_selections__before_redirecting_to_checkout', EE_Registry::instance()->CART, $this); |
|
579 | 579 | EE_Registry::instance()->CART->recalculate_all_cart_totals(); |
580 | - EE_Registry::instance()->CART->save_cart( FALSE ); |
|
580 | + EE_Registry::instance()->CART->save_cart(FALSE); |
|
581 | 581 | EE_Registry::instance()->SSN->update(); |
582 | 582 | //d( EE_Registry::instance()->CART ); |
583 | 583 | //die(); // <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< OR HERE TO KILL REDIRECT AFTER CART UPDATE |
584 | 584 | // just return TRUE for registrations being made from admin |
585 | - if ( is_admin() ) { |
|
585 | + if (is_admin()) { |
|
586 | 586 | return TRUE; |
587 | 587 | } |
588 | - wp_safe_redirect( apply_filters( 'FHEE__EE_Ticket_Selector__process_ticket_selections__success_redirect_url', EE_Registry::instance()->CFG->core->reg_page_url() )); |
|
588 | + wp_safe_redirect(apply_filters('FHEE__EE_Ticket_Selector__process_ticket_selections__success_redirect_url', EE_Registry::instance()->CFG->core->reg_page_url())); |
|
589 | 589 | exit(); |
590 | 590 | |
591 | 591 | } else { |
592 | - if ( ! EE_Error::has_error() ) { |
|
592 | + if ( ! EE_Error::has_error()) { |
|
593 | 593 | // nothing added to cart |
594 | - EE_Error::add_attention( __( 'No tickets were added for the event', 'event_espresso' ), __FILE__, __FUNCTION__, __LINE__ ); |
|
594 | + EE_Error::add_attention(__('No tickets were added for the event', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__); |
|
595 | 595 | } |
596 | 596 | } |
597 | 597 | |
598 | 598 | } else { |
599 | 599 | // no ticket quantities were selected |
600 | - EE_Error::add_error( __( 'You need to select a ticket quantity before you can proceed.', 'event_espresso' ), __FILE__, __FUNCTION__, __LINE__ ); |
|
600 | + EE_Error::add_error(__('You need to select a ticket quantity before you can proceed.', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__); |
|
601 | 601 | } |
602 | 602 | } |
603 | 603 | //die(); // <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< KILL BEFORE REDIRECT |
604 | 604 | // at this point, just return if registration is being made from admin |
605 | - if ( is_admin() ) { |
|
605 | + if (is_admin()) { |
|
606 | 606 | return FALSE; |
607 | 607 | } |
608 | - if ( $valid['return_url'] ) { |
|
609 | - EE_Error::get_notices( FALSE, TRUE ); |
|
610 | - wp_safe_redirect( $valid['return_url'] ); |
|
608 | + if ($valid['return_url']) { |
|
609 | + EE_Error::get_notices(FALSE, TRUE); |
|
610 | + wp_safe_redirect($valid['return_url']); |
|
611 | 611 | exit(); |
612 | - } elseif ( isset( $event_to_add['id'] )) { |
|
613 | - EE_Error::get_notices( FALSE, TRUE ); |
|
614 | - wp_safe_redirect( get_permalink( $event_to_add['id'] )); |
|
612 | + } elseif (isset($event_to_add['id'])) { |
|
613 | + EE_Error::get_notices(FALSE, TRUE); |
|
614 | + wp_safe_redirect(get_permalink($event_to_add['id'])); |
|
615 | 615 | exit(); |
616 | 616 | } else { |
617 | 617 | echo EE_Error::get_notices(); |
@@ -620,7 +620,7 @@ discard block |
||
620 | 620 | } else { |
621 | 621 | // $_POST['tkt-slctr-event-id'] was not set ?!?!?!? |
622 | 622 | EE_Error::add_error( |
623 | - sprintf( __( 'An event id was not provided or was not received.%sPlease click the back button on your browser and try again.', 'event_espresso' ), '<br/>' ), |
|
623 | + sprintf(__('An event id was not provided or was not received.%sPlease click the back button on your browser and try again.', 'event_espresso'), '<br/>'), |
|
624 | 624 | __FILE__, __FUNCTION__, __LINE__ |
625 | 625 | ); |
626 | 626 | } |
@@ -638,18 +638,18 @@ discard block |
||
638 | 638 | * @return array or FALSE |
639 | 639 | */ |
640 | 640 | private static function _validate_post_data() { |
641 | - do_action( 'AHEE_log', __FILE__, __FUNCTION__, '' ); |
|
641 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
642 | 642 | |
643 | 643 | // start with an empty array() |
644 | 644 | $valid_data = array(); |
645 | 645 | // d( $_POST ); |
646 | 646 | //if event id is valid |
647 | - $id = absint( EE_Registry::instance()->REQ->get( 'tkt-slctr-event-id' )); |
|
648 | - if ( $id ) { |
|
647 | + $id = absint(EE_Registry::instance()->REQ->get('tkt-slctr-event-id')); |
|
648 | + if ($id) { |
|
649 | 649 | // grab valid id |
650 | 650 | $valid_data['id'] = $id; |
651 | 651 | // grab and sanitize return-url |
652 | - $valid_data['return_url'] = esc_url_raw( EE_Registry::instance()->REQ->get( 'tkt-slctr-return-url-' . $id )); |
|
652 | + $valid_data['return_url'] = esc_url_raw(EE_Registry::instance()->REQ->get('tkt-slctr-return-url-'.$id)); |
|
653 | 653 | // array of other form names |
654 | 654 | $inputs_to_clean = array( |
655 | 655 | 'event_id' => 'tkt-slctr-event-id', |
@@ -662,22 +662,22 @@ discard block |
||
662 | 662 | // let's track the total number of tickets ordered.' |
663 | 663 | $valid_data['total_tickets'] = 0; |
664 | 664 | // cycle through $inputs_to_clean array |
665 | - foreach ( $inputs_to_clean as $what => $input_to_clean ) { |
|
665 | + foreach ($inputs_to_clean as $what => $input_to_clean) { |
|
666 | 666 | // check for POST data |
667 | - if ( EE_Registry::instance()->REQ->is_set( $input_to_clean . $id )) { |
|
667 | + if (EE_Registry::instance()->REQ->is_set($input_to_clean.$id)) { |
|
668 | 668 | // grab value |
669 | - $input_value = EE_Registry::instance()->REQ->get( $input_to_clean . $id ); |
|
669 | + $input_value = EE_Registry::instance()->REQ->get($input_to_clean.$id); |
|
670 | 670 | switch ($what) { |
671 | 671 | |
672 | 672 | // integers |
673 | 673 | case 'event_id': |
674 | - $valid_data[$what] = absint( $input_value ); |
|
674 | + $valid_data[$what] = absint($input_value); |
|
675 | 675 | // get event via the event id we put in the form |
676 | - $valid_data['event'] = EE_Registry::instance()->load_model( 'Event' )->get_one_by_ID( $valid_data['event_id'] ); |
|
676 | + $valid_data['event'] = EE_Registry::instance()->load_model('Event')->get_one_by_ID($valid_data['event_id']); |
|
677 | 677 | break; |
678 | 678 | case 'rows': |
679 | 679 | case 'max_atndz': |
680 | - $valid_data[$what] = absint( $input_value ); |
|
680 | + $valid_data[$what] = absint($input_value); |
|
681 | 681 | break; |
682 | 682 | |
683 | 683 | // arrays of integers |
@@ -685,27 +685,27 @@ discard block |
||
685 | 685 | // d( $input_value ); |
686 | 686 | $row_qty = $input_value; |
687 | 687 | // if qty is coming from a radio button input, then we need to assemble an array of rows |
688 | - if( ! is_array( $row_qty )) { |
|
688 | + if ( ! is_array($row_qty)) { |
|
689 | 689 | // get number of rows |
690 | - $rows = EE_Registry::instance()->REQ->is_set( 'tkt-slctr-rows-' . $id ) ? absint( EE_Registry::instance()->REQ->get( 'tkt-slctr-rows-' . $id )) : 1; |
|
690 | + $rows = EE_Registry::instance()->REQ->is_set('tkt-slctr-rows-'.$id) ? absint(EE_Registry::instance()->REQ->get('tkt-slctr-rows-'.$id)) : 1; |
|
691 | 691 | // d( $rows ); |
692 | 692 | // explode ints by the dash |
693 | - $row_qty = explode( '-', $row_qty ); |
|
694 | - $row = isset( $row_qty[0] ) ? ( absint( $row_qty[0] )) : 1; |
|
695 | - $qty = isset( $row_qty[1] ) ? absint( $row_qty[1] ) : 0; |
|
696 | - $row_qty = array( $row => $qty ); |
|
693 | + $row_qty = explode('-', $row_qty); |
|
694 | + $row = isset($row_qty[0]) ? (absint($row_qty[0])) : 1; |
|
695 | + $qty = isset($row_qty[1]) ? absint($row_qty[1]) : 0; |
|
696 | + $row_qty = array($row => $qty); |
|
697 | 697 | // d( $row_qty ); |
698 | - for( $x = 1; $x <= $rows; $x++ ) { |
|
699 | - if ( ! isset( $row_qty[$x] )) { |
|
698 | + for ($x = 1; $x <= $rows; $x++) { |
|
699 | + if ( ! isset($row_qty[$x])) { |
|
700 | 700 | $row_qty[$x] = 0; |
701 | 701 | } |
702 | 702 | } |
703 | 703 | } |
704 | - ksort( $row_qty ); |
|
704 | + ksort($row_qty); |
|
705 | 705 | // d( $row_qty ); |
706 | 706 | // cycle thru values |
707 | - foreach ( $row_qty as $qty ) { |
|
708 | - $qty = absint( $qty ); |
|
707 | + foreach ($row_qty as $qty) { |
|
708 | + $qty = absint($qty); |
|
709 | 709 | // sanitize as integers |
710 | 710 | $valid_data[$what][] = $qty; |
711 | 711 | $valid_data['total_tickets'] += $qty; |
@@ -716,19 +716,19 @@ discard block |
||
716 | 716 | case 'ticket_id': |
717 | 717 | $value_array = array(); |
718 | 718 | // cycle thru values |
719 | - foreach ( $input_value as $key=>$value ) { |
|
719 | + foreach ($input_value as $key=>$value) { |
|
720 | 720 | // allow only numbers, letters, spaces, commas and dashes |
721 | - $value_array[ $key ] = wp_strip_all_tags( $value ); |
|
721 | + $value_array[$key] = wp_strip_all_tags($value); |
|
722 | 722 | // get ticket via the ticket id we put in the form |
723 | - $ticket_obj = EE_Registry::instance()->load_model( 'Ticket' )->get_one_by_ID( $value ); |
|
724 | - $valid_data['ticket_obj'][ $key ] = $ticket_obj; |
|
723 | + $ticket_obj = EE_Registry::instance()->load_model('Ticket')->get_one_by_ID($value); |
|
724 | + $valid_data['ticket_obj'][$key] = $ticket_obj; |
|
725 | 725 | } |
726 | - $valid_data[ $what ] = $value_array; |
|
726 | + $valid_data[$what] = $value_array; |
|
727 | 727 | break; |
728 | 728 | |
729 | 729 | case 'return_url' : |
730 | 730 | // grab and sanitize return-url |
731 | - $valid_data[$what] = esc_url_raw( $input_value ); |
|
731 | + $valid_data[$what] = esc_url_raw($input_value); |
|
732 | 732 | break; |
733 | 733 | |
734 | 734 | } // end switch $what |
@@ -736,7 +736,7 @@ discard block |
||
736 | 736 | } // end foreach $inputs_to_clean |
737 | 737 | |
738 | 738 | } else { |
739 | - EE_Error::add_error( __('The event id provided was not valid.', 'event_espresso' ), __FILE__, __FUNCTION__, __LINE__ ); |
|
739 | + EE_Error::add_error(__('The event id provided was not valid.', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__); |
|
740 | 740 | return FALSE; |
741 | 741 | } |
742 | 742 | |
@@ -754,28 +754,28 @@ discard block |
||
754 | 754 | * @param int $qty |
755 | 755 | * @return TRUE on success, FALSE on fail |
756 | 756 | */ |
757 | - private static function _add_ticket_to_cart( EE_Ticket $ticket = NULL, $qty = 1 ) { |
|
758 | - do_action( 'AHEE_log', __FILE__, __FUNCTION__, '' ); |
|
757 | + private static function _add_ticket_to_cart(EE_Ticket $ticket = NULL, $qty = 1) { |
|
758 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
759 | 759 | // get the number of spaces left for this datetime ticket |
760 | - $available_spaces = self::_ticket_datetime_availability( $ticket ); |
|
760 | + $available_spaces = self::_ticket_datetime_availability($ticket); |
|
761 | 761 | // compare available spaces against the number of tickets being purchased |
762 | - if ( $available_spaces >= $qty ) { |
|
762 | + if ($available_spaces >= $qty) { |
|
763 | 763 | // allow addons to prevent a ticket from being added to cart |
764 | - if ( ! apply_filters( 'FHEE__EE_Ticket_Selector___add_ticket_to_cart__allow_add_to_cart', true, $ticket, $qty, $available_spaces ) ) { |
|
764 | + if ( ! apply_filters('FHEE__EE_Ticket_Selector___add_ticket_to_cart__allow_add_to_cart', true, $ticket, $qty, $available_spaces)) { |
|
765 | 765 | return false; |
766 | 766 | } |
767 | 767 | // add event to cart |
768 | - if( EE_Registry::instance()->CART->add_ticket_to_cart( $ticket, $qty )) { |
|
769 | - self::_recalculate_ticket_datetime_availability( $ticket, $qty ); |
|
768 | + if (EE_Registry::instance()->CART->add_ticket_to_cart($ticket, $qty)) { |
|
769 | + self::_recalculate_ticket_datetime_availability($ticket, $qty); |
|
770 | 770 | return true; |
771 | 771 | } else { |
772 | 772 | return false; |
773 | 773 | } |
774 | 774 | } else { |
775 | 775 | // tickets can not be purchased but let's find the exact number left for the last ticket selected PRIOR to subtracting tickets |
776 | - $available_spaces = self::_ticket_datetime_availability( $ticket, true ); |
|
776 | + $available_spaces = self::_ticket_datetime_availability($ticket, true); |
|
777 | 777 | // greedy greedy greedy eh? |
778 | - if ( $available_spaces > 0 ) { |
|
778 | + if ($available_spaces > 0) { |
|
779 | 779 | // add error messaging - we're using the _n function that will generate the appropriate singular or plural message based on the number of $available_spaces |
780 | 780 | EE_Error::add_error( |
781 | 781 | sprintf( |
@@ -791,7 +791,7 @@ discard block |
||
791 | 791 | __FILE__, __FUNCTION__, __LINE__ |
792 | 792 | ); |
793 | 793 | } else { |
794 | - EE_Error::add_error( __('We\'re sorry, but there are no available spaces left for this event at this particular date and time.', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__ ); |
|
794 | + EE_Error::add_error(__('We\'re sorry, but there are no available spaces left for this event at this particular date and time.', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__); |
|
795 | 795 | } |
796 | 796 | return false; |
797 | 797 | } |
@@ -809,22 +809,22 @@ discard block |
||
809 | 809 | * @param bool $get_original_ticket_spaces |
810 | 810 | * @return int |
811 | 811 | */ |
812 | - private static function _ticket_datetime_availability( EE_Ticket $ticket, $get_original_ticket_spaces = FALSE ) { |
|
812 | + private static function _ticket_datetime_availability(EE_Ticket $ticket, $get_original_ticket_spaces = FALSE) { |
|
813 | 813 | // if the $_available_spaces array has not been set up yet... |
814 | - if ( ! isset( self::$_available_spaces['tickets'][ $ticket->ID() ] )) { |
|
815 | - self::_set_initial_ticket_datetime_availability( $ticket ); |
|
814 | + if ( ! isset(self::$_available_spaces['tickets'][$ticket->ID()])) { |
|
815 | + self::_set_initial_ticket_datetime_availability($ticket); |
|
816 | 816 | } |
817 | 817 | $available_spaces = $ticket->qty() - $ticket->sold(); |
818 | - if ( isset( self::$_available_spaces['tickets'][ $ticket->ID() ] )) { |
|
818 | + if (isset(self::$_available_spaces['tickets'][$ticket->ID()])) { |
|
819 | 819 | // loop thru tickets, which will ALSO include individual ticket records AND a total |
820 | - foreach ( self::$_available_spaces['tickets'][ $ticket->ID() ] as $DTD_ID => $spaces ) { |
|
820 | + foreach (self::$_available_spaces['tickets'][$ticket->ID()] as $DTD_ID => $spaces) { |
|
821 | 821 | // if we want the original datetime availability BEFORE we started subtracting tickets ? |
822 | - if ( $get_original_ticket_spaces ) { |
|
822 | + if ($get_original_ticket_spaces) { |
|
823 | 823 | // then grab the available spaces from the "tickets" array and compare with the above to get the lowest number |
824 | - $available_spaces = min( $available_spaces, self::$_available_spaces['tickets'][ $ticket->ID() ][ $DTD_ID ] ); |
|
824 | + $available_spaces = min($available_spaces, self::$_available_spaces['tickets'][$ticket->ID()][$DTD_ID]); |
|
825 | 825 | } else { |
826 | 826 | // we want the updated ticket availability as stored in the "datetimes" array |
827 | - $available_spaces = min( $available_spaces, self::$_available_spaces['datetimes'][ $DTD_ID ] ); |
|
827 | + $available_spaces = min($available_spaces, self::$_available_spaces['datetimes'][$DTD_ID]); |
|
828 | 828 | } |
829 | 829 | } |
830 | 830 | } |
@@ -840,23 +840,23 @@ discard block |
||
840 | 840 | * @param EE_Ticket $ticket |
841 | 841 | * @return int |
842 | 842 | */ |
843 | - private static function _set_initial_ticket_datetime_availability( EE_Ticket $ticket ) { |
|
843 | + private static function _set_initial_ticket_datetime_availability(EE_Ticket $ticket) { |
|
844 | 844 | // first, get all of the datetimes that are available to this ticket |
845 | 845 | $datetimes = $ticket->get_many_related( |
846 | 846 | 'Datetime', |
847 | - array( array( 'DTT_EVT_end' => array( '>=', EEM_Datetime::instance()->current_time_for_query( 'DTT_EVT_end' ) ) ), 'order_by' => array( 'DTT_EVT_start' => 'ASC' )) |
|
847 | + array(array('DTT_EVT_end' => array('>=', EEM_Datetime::instance()->current_time_for_query('DTT_EVT_end'))), 'order_by' => array('DTT_EVT_start' => 'ASC')) |
|
848 | 848 | ); |
849 | - if ( ! empty( $datetimes )) { |
|
849 | + if ( ! empty($datetimes)) { |
|
850 | 850 | // now loop thru all of the datetimes |
851 | - foreach ( $datetimes as $datetime ) { |
|
852 | - if ( $datetime instanceof EE_Datetime ) { |
|
851 | + foreach ($datetimes as $datetime) { |
|
852 | + if ($datetime instanceof EE_Datetime) { |
|
853 | 853 | // the number of spaces available for the datetime without considering individual ticket quantities |
854 | 854 | $spaces_remaining = $datetime->spaces_remaining(); |
855 | 855 | // save the total available spaces ( the lesser of the ticket qty minus the number of tickets sold or the datetime spaces remaining) to this ticket using the datetime ID as the key |
856 | - self::$_available_spaces['tickets'][ $ticket->ID() ][ $datetime->ID() ] = min(( $ticket->qty() - $ticket->sold() ), $spaces_remaining ); |
|
856 | + self::$_available_spaces['tickets'][$ticket->ID()][$datetime->ID()] = min(($ticket->qty() - $ticket->sold()), $spaces_remaining); |
|
857 | 857 | // if the remaining spaces for this datetime is already set, then compare that against the datetime spaces remaining, and take the lowest number, |
858 | 858 | // else just take the datetime spaces remaining, and assign to the datetimes array |
859 | - self::$_available_spaces['datetimes'][ $datetime->ID() ] = isset( self::$_available_spaces['datetimes'][ $datetime->ID() ] ) ? min( self::$_available_spaces['datetimes'][ $datetime->ID() ], $spaces_remaining ) : $spaces_remaining; |
|
859 | + self::$_available_spaces['datetimes'][$datetime->ID()] = isset(self::$_available_spaces['datetimes'][$datetime->ID()]) ? min(self::$_available_spaces['datetimes'][$datetime->ID()], $spaces_remaining) : $spaces_remaining; |
|
860 | 860 | } |
861 | 861 | } |
862 | 862 | } |
@@ -872,12 +872,12 @@ discard block |
||
872 | 872 | * @param int $qty |
873 | 873 | * @return int |
874 | 874 | */ |
875 | - private static function _recalculate_ticket_datetime_availability( EE_Ticket $ticket, $qty = 0 ) { |
|
876 | - if ( isset( self::$_available_spaces['tickets'][ $ticket->ID() ] )) { |
|
875 | + private static function _recalculate_ticket_datetime_availability(EE_Ticket $ticket, $qty = 0) { |
|
876 | + if (isset(self::$_available_spaces['tickets'][$ticket->ID()])) { |
|
877 | 877 | // loop thru tickets, which will ALSO include individual ticket records AND a total |
878 | - foreach ( self::$_available_spaces['tickets'][ $ticket->ID() ] as $DTD_ID => $spaces ) { |
|
878 | + foreach (self::$_available_spaces['tickets'][$ticket->ID()] as $DTD_ID => $spaces) { |
|
879 | 879 | // subtract the qty of selected tickets from each datetime's available spaces this ticket has access to, |
880 | - self::$_available_spaces['datetimes'][ $DTD_ID ] = self::$_available_spaces['datetimes'][ $DTD_ID ] - $qty; |
|
880 | + self::$_available_spaces['datetimes'][$DTD_ID] = self::$_available_spaces['datetimes'][$DTD_ID] - $qty; |
|
881 | 881 | } |
882 | 882 | } |
883 | 883 | } |
@@ -894,8 +894,8 @@ discard block |
||
894 | 894 | */ |
895 | 895 | public static function load_tckt_slctr_assets() { |
896 | 896 | // add some style |
897 | - if ( apply_filters( 'FHEE__EED_Ticket_Selector__load_tckt_slctr_assets', FALSE ) ) { |
|
898 | - wp_register_style('ticket_selector', TICKET_SELECTOR_ASSETS_URL . 'ticket_selector.css'); |
|
897 | + if (apply_filters('FHEE__EED_Ticket_Selector__load_tckt_slctr_assets', FALSE)) { |
|
898 | + wp_register_style('ticket_selector', TICKET_SELECTOR_ASSETS_URL.'ticket_selector.css'); |
|
899 | 899 | wp_enqueue_style('ticket_selector'); |
900 | 900 | // make it dance |
901 | 901 | // wp_register_script('ticket_selector', TICKET_SELECTOR_ASSETS_URL . 'ticket_selector.js', array('espresso_core'), '', TRUE); |
@@ -909,9 +909,9 @@ discard block |
||
909 | 909 | |
910 | 910 | public static function load_tckt_slctr_assets_admin() { |
911 | 911 | //iframe button js on admin event editor page |
912 | - if ( EE_Registry::instance()->REQ->get('page') == 'espresso_events' && EE_Registry::instance()->REQ->get('action') == 'edit' ) { |
|
913 | - wp_register_script( 'ticket_selector_embed', TICKET_SELECTOR_ASSETS_URL . 'ticket-selector-embed.js', array( 'ee-dialog' ), EVENT_ESPRESSO_VERSION, true ); |
|
914 | - wp_enqueue_script( 'ticket_selector_embed' ); |
|
912 | + if (EE_Registry::instance()->REQ->get('page') == 'espresso_events' && EE_Registry::instance()->REQ->get('action') == 'edit') { |
|
913 | + wp_register_script('ticket_selector_embed', TICKET_SELECTOR_ASSETS_URL.'ticket-selector-embed.js', array('ee-dialog'), EVENT_ESPRESSO_VERSION, true); |
|
914 | + wp_enqueue_script('ticket_selector_embed'); |
|
915 | 915 | } |
916 | 916 | } |
917 | 917 |
@@ -19,7 +19,7 @@ discard block |
||
19 | 19 | * @param WP $WP |
20 | 20 | * @return void |
21 | 21 | */ |
22 | - public function run( WP $WP ) {} |
|
22 | + public function run(WP $WP) {} |
|
23 | 23 | |
24 | 24 | |
25 | 25 | /** |
@@ -69,14 +69,14 @@ discard block |
||
69 | 69 | * @param array $attributes |
70 | 70 | * @return string |
71 | 71 | */ |
72 | - public function process_shortcode( $attributes = array() ) { |
|
72 | + public function process_shortcode($attributes = array()) { |
|
73 | 73 | |
74 | 74 | //load helpers |
75 | - EE_Registry::instance()->load_helper( 'Event_View' ); |
|
76 | - EE_Registry::instance()->load_helper( 'Template' ); |
|
75 | + EE_Registry::instance()->load_helper('Event_View'); |
|
76 | + EE_Registry::instance()->load_helper('Template'); |
|
77 | 77 | |
78 | 78 | // merge in any attributes passed via fallback shortcode processor |
79 | - $attributes = array_merge( (array) $attributes, (array) $this->_attributes ); |
|
79 | + $attributes = array_merge((array) $attributes, (array) $this->_attributes); |
|
80 | 80 | |
81 | 81 | //set default attributes |
82 | 82 | $default_shortcode_attributes = array( |
@@ -88,9 +88,9 @@ discard block |
||
88 | 88 | ); |
89 | 89 | |
90 | 90 | // allow the defaults to be filtered |
91 | - $default_shortcode_attributes = apply_filters( 'EES_Espresso_Event_Attendees__process_shortcode__default_shortcode_atts', $default_shortcode_attributes ); |
|
91 | + $default_shortcode_attributes = apply_filters('EES_Espresso_Event_Attendees__process_shortcode__default_shortcode_atts', $default_shortcode_attributes); |
|
92 | 92 | // grab attributes and merge with defaults, then extract |
93 | - $attributes = array_merge( $default_shortcode_attributes, $attributes ); |
|
93 | + $attributes = array_merge($default_shortcode_attributes, $attributes); |
|
94 | 94 | |
95 | 95 | $template_args = array( |
96 | 96 | 'contacts' => array(), |
@@ -106,31 +106,31 @@ discard block |
||
106 | 106 | $error = false; |
107 | 107 | |
108 | 108 | //what event? |
109 | - if ( empty( $attributes['event_id'] ) && empty( $attributes['datetime_id'] ) && empty( $attributes['ticket_id'] ) ) { |
|
109 | + if (empty($attributes['event_id']) && empty($attributes['datetime_id']) && empty($attributes['ticket_id'])) { |
|
110 | 110 | //seems like is_espresso_event_single() isn't working as expected. So using alternate method. |
111 | - if ( is_single() && is_espresso_event() ) { |
|
111 | + if (is_single() && is_espresso_event()) { |
|
112 | 112 | $event = EEH_Event_View::get_event(); |
113 | - if ( $event instanceof EE_Event ) { |
|
113 | + if ($event instanceof EE_Event) { |
|
114 | 114 | $template_args['event'] = $event; |
115 | 115 | $query[0]['Registration.EVT_ID'] = $event->ID(); |
116 | 116 | } |
117 | 117 | } else { |
118 | 118 | //try getting the earliest active event if none then get the |
119 | - $events = EEM_Event::instance()->get_active_events( array( 'limit' => 1, |
|
120 | - 'order_by' => array( 'Datetime.DTT_EVT_start' => 'ASC' ) |
|
121 | - ) ); |
|
122 | - $events = empty( $events ) ? EEM_Event::instance()->get_upcoming_events( array( 'limit' => 1, |
|
123 | - 'order_by' => array( 'Datetime.DTT_EVT_start' => 'ASC' ) |
|
124 | - ) ) : $events; |
|
125 | - $event = reset( $events ); |
|
126 | - if ( $event instanceof EE_Event ) { |
|
119 | + $events = EEM_Event::instance()->get_active_events(array('limit' => 1, |
|
120 | + 'order_by' => array('Datetime.DTT_EVT_start' => 'ASC') |
|
121 | + )); |
|
122 | + $events = empty($events) ? EEM_Event::instance()->get_upcoming_events(array('limit' => 1, |
|
123 | + 'order_by' => array('Datetime.DTT_EVT_start' => 'ASC') |
|
124 | + )) : $events; |
|
125 | + $event = reset($events); |
|
126 | + if ($event instanceof EE_Event) { |
|
127 | 127 | $query[0]['Registration.EVT_ID'] = $event->ID(); |
128 | 128 | $template_args['event'] = $event; |
129 | 129 | } |
130 | 130 | } |
131 | - } elseif ( ! empty( $attributes['event_id'] ) ) { |
|
132 | - $event = EEM_Event::instance()->get_one_by_ID( $attributes['event_id'] ); |
|
133 | - if ( $event instanceof EE_Event ) { |
|
131 | + } elseif ( ! empty($attributes['event_id'])) { |
|
132 | + $event = EEM_Event::instance()->get_one_by_ID($attributes['event_id']); |
|
133 | + if ($event instanceof EE_Event) { |
|
134 | 134 | $query[0]['Registration.EVT_ID'] = $attributes['event_id']; |
135 | 135 | $template_args['event'] = $event; |
136 | 136 | } else { |
@@ -139,9 +139,9 @@ discard block |
||
139 | 139 | } |
140 | 140 | |
141 | 141 | //datetime? |
142 | - if ( ! empty( $attributes['datetime_id'] ) && empty( $attributes['event_id'] ) ) { |
|
143 | - $datetime = EEM_Datetime::instance()->get_one_by_ID( $attributes['datetime_id'] ); |
|
144 | - if ( $datetime instanceof EE_Datetime ) { |
|
142 | + if ( ! empty($attributes['datetime_id']) && empty($attributes['event_id'])) { |
|
143 | + $datetime = EEM_Datetime::instance()->get_one_by_ID($attributes['datetime_id']); |
|
144 | + if ($datetime instanceof EE_Datetime) { |
|
145 | 145 | $query[0]['Registration.Ticket.Datetime.DTT_ID'] = $attributes['datetime_id']; |
146 | 146 | $query['default_where_conditions'] = 'this_model_only'; |
147 | 147 | $template_args['datetime'] = $datetime; |
@@ -152,9 +152,9 @@ discard block |
||
152 | 152 | } |
153 | 153 | |
154 | 154 | //ticket?just |
155 | - if ( ! empty( $attributes['ticket_id'] ) && empty( $attributes['event_id'] ) && empty( $attributes['datetime_id'] ) ) { |
|
156 | - $ticket = EEM_Ticket::instance()->get_one_by_ID( $attributes['ticket_id'] ); |
|
157 | - if ( $ticket instanceof EE_Ticket ) { |
|
155 | + if ( ! empty($attributes['ticket_id']) && empty($attributes['event_id']) && empty($attributes['datetime_id'])) { |
|
156 | + $ticket = EEM_Ticket::instance()->get_one_by_ID($attributes['ticket_id']); |
|
157 | + if ($ticket instanceof EE_Ticket) { |
|
158 | 158 | $query[0]['Registration.TKT_ID'] = $attributes['ticket_id']; |
159 | 159 | $template_args['ticket'] = $ticket; |
160 | 160 | $template_args['event'] = $ticket->first_datetime() instanceof EE_Datetime ? $ticket->first_datetime()->event() : null; |
@@ -165,17 +165,17 @@ discard block |
||
165 | 165 | |
166 | 166 | //status |
167 | 167 | $reg_status_array = EEM_Registration::reg_status_array(); |
168 | - if ( $attributes['status'] != 'all' && isset( $reg_status_array[$attributes['status']] ) ) { |
|
168 | + if ($attributes['status'] != 'all' && isset($reg_status_array[$attributes['status']])) { |
|
169 | 169 | $query[0]['Registration.STS_ID'] = $attributes['status']; |
170 | 170 | } |
171 | - $query['group_by'] = array( 'ATT_ID' ); |
|
172 | - $query['order_by'] = apply_filters( 'FHEE__EES_Espresso_Event_Attendees__process_shortcode__order_by', array( 'ATT_lname' => 'ASC', 'ATT_fname' => 'ASC' ) ); |
|
171 | + $query['group_by'] = array('ATT_ID'); |
|
172 | + $query['order_by'] = apply_filters('FHEE__EES_Espresso_Event_Attendees__process_shortcode__order_by', array('ATT_lname' => 'ASC', 'ATT_fname' => 'ASC')); |
|
173 | 173 | |
174 | 174 | //if we have NO query where conditions, then there was an invalid parameter or the shortcode was used incorrectly |
175 | 175 | //so when WP_DEBUG is set and true, we'll show a message, otherwise we'll just return an empty string. |
176 | - if ( ( ! isset( $query[0] ) || ! is_array( $query[0] ) ) || $error ) { |
|
177 | - if ( WP_DEBUG ) { |
|
178 | - return '<div class="important-notice ee-attention">' . __( 'The [ESPRESSO_EVENT_ATTENDEES] shortcode has been used incorrectly. Please double check the arguments you used for any typos. In the case of ID type arguments, its possible the given ID does not correspond to existing data in the database.', 'event_espresso' ) . '</div>'; |
|
176 | + if (( ! isset($query[0]) || ! is_array($query[0])) || $error) { |
|
177 | + if (WP_DEBUG) { |
|
178 | + return '<div class="important-notice ee-attention">'.__('The [ESPRESSO_EVENT_ATTENDEES] shortcode has been used incorrectly. Please double check the arguments you used for any typos. In the case of ID type arguments, its possible the given ID does not correspond to existing data in the database.', 'event_espresso').'</div>'; |
|
179 | 179 | } else { |
180 | 180 | return ''; |
181 | 181 | } |
@@ -183,11 +183,11 @@ discard block |
||
183 | 183 | |
184 | 184 | |
185 | 185 | //get contacts! |
186 | - $template_args['contacts'] = EEM_Attendee::instance()->get_all( $query ); |
|
186 | + $template_args['contacts'] = EEM_Attendee::instance()->get_all($query); |
|
187 | 187 | |
188 | 188 | |
189 | 189 | //all set let's load up the template and return. |
190 | - return EEH_Template::locate_template( 'loop-espresso_event_attendees.php', $template_args, true, true ); |
|
190 | + return EEH_Template::locate_template('loop-espresso_event_attendees.php', $template_args, true, true); |
|
191 | 191 | |
192 | 192 | } |
193 | 193 |
@@ -1,4 +1,4 @@ discard block |
||
1 | -<?php if (!defined('EVENT_ESPRESSO_VERSION')) exit('No direct script access allowed'); |
|
1 | +<?php if ( ! defined('EVENT_ESPRESSO_VERSION')) exit('No direct script access allowed'); |
|
2 | 2 | /** |
3 | 3 | * |
4 | 4 | * Class EE_Log |
@@ -62,7 +62,7 @@ discard block |
||
62 | 62 | * @return EE_Log |
63 | 63 | */ |
64 | 64 | public static function instance() { |
65 | - if ( ! self::$_instance instanceof EE_Log ) { |
|
65 | + if ( ! self::$_instance instanceof EE_Log) { |
|
66 | 66 | self::$_instance = new self(); |
67 | 67 | } |
68 | 68 | return self::$_instance; |
@@ -74,11 +74,11 @@ discard block |
||
74 | 74 | */ |
75 | 75 | private function __construct() { |
76 | 76 | |
77 | - if ( ! EE_Registry::instance()->CFG->admin->use_full_logging && ! EE_Registry::instance()->CFG->admin->use_remote_logging ) { |
|
77 | + if ( ! EE_Registry::instance()->CFG->admin->use_full_logging && ! EE_Registry::instance()->CFG->admin->use_remote_logging) { |
|
78 | 78 | return; |
79 | 79 | } |
80 | 80 | |
81 | - $this->_logs_folder = EVENT_ESPRESSO_UPLOAD_DIR . 'logs' . DS; |
|
81 | + $this->_logs_folder = EVENT_ESPRESSO_UPLOAD_DIR.'logs'.DS; |
|
82 | 82 | $this->_log_file = EE_Registry::instance()->CFG->admin->log_file_name(); |
83 | 83 | $this->_log = ''; |
84 | 84 | $this->_debug_file = EE_Registry::instance()->CFG->admin->debug_file_name(); |
@@ -86,15 +86,15 @@ discard block |
||
86 | 86 | $this->_remote_logging_url = EE_Registry::instance()->CFG->admin->remote_logging_url; |
87 | 87 | $this->_remote_log = ''; |
88 | 88 | |
89 | - add_action( 'admin_init', array( $this, 'verify_filesystem' ), -10 ); |
|
90 | - add_action( 'AHEE_log', array( $this, 'log' ), 10, 4 ); |
|
91 | - if ( EE_Registry::instance()->CFG->admin->use_full_logging ) { |
|
92 | - add_action( 'shutdown', array( $this, 'write_log' ), 9999 ); |
|
89 | + add_action('admin_init', array($this, 'verify_filesystem'), -10); |
|
90 | + add_action('AHEE_log', array($this, 'log'), 10, 4); |
|
91 | + if (EE_Registry::instance()->CFG->admin->use_full_logging) { |
|
92 | + add_action('shutdown', array($this, 'write_log'), 9999); |
|
93 | 93 | // if WP_DEBUG |
94 | - add_action( 'shutdown', array( $this, 'write_debug' ), 9999 ); |
|
94 | + add_action('shutdown', array($this, 'write_debug'), 9999); |
|
95 | 95 | } |
96 | - if ( EE_Registry::instance()->CFG->admin->use_remote_logging ) { |
|
97 | - add_action( 'shutdown', array( $this, 'send_log' ), 9999 ); |
|
96 | + if (EE_Registry::instance()->CFG->admin->use_remote_logging) { |
|
97 | + add_action('shutdown', array($this, 'send_log'), 9999); |
|
98 | 98 | } |
99 | 99 | |
100 | 100 | } |
@@ -108,12 +108,12 @@ discard block |
||
108 | 108 | */ |
109 | 109 | public function verify_filesystem() { |
110 | 110 | try { |
111 | - EE_Registry::instance()->load_helper( 'File' ); |
|
112 | - EEH_File::ensure_file_exists_and_is_writable( $this->_logs_folder . $this->_log_file ); |
|
113 | - EEH_File::ensure_file_exists_and_is_writable( $this->_logs_folder . $this->_debug_file ); |
|
114 | - EEH_File::add_htaccess_deny_from_all( $this->_logs_folder ); |
|
115 | - } catch( EE_Error $e ){ |
|
116 | - EE_Error::add_error( sprintf( __( 'Event Espresso logging could not be setup because: %s', 'event_espresso' ), ' ' . $e->getMessage() ), __FILE__, __FUNCTION__, __LINE__ ); |
|
111 | + EE_Registry::instance()->load_helper('File'); |
|
112 | + EEH_File::ensure_file_exists_and_is_writable($this->_logs_folder.$this->_log_file); |
|
113 | + EEH_File::ensure_file_exists_and_is_writable($this->_logs_folder.$this->_debug_file); |
|
114 | + EEH_File::add_htaccess_deny_from_all($this->_logs_folder); |
|
115 | + } catch (EE_Error $e) { |
|
116 | + EE_Error::add_error(sprintf(__('Event Espresso logging could not be setup because: %s', 'event_espresso'), ' '.$e->getMessage()), __FILE__, __FUNCTION__, __LINE__); |
|
117 | 117 | return; |
118 | 118 | } |
119 | 119 | } |
@@ -130,15 +130,15 @@ discard block |
||
130 | 130 | * @param string $type |
131 | 131 | * @return string |
132 | 132 | */ |
133 | - private function _format_message( $file = '', $function = '', $message = '', $type = '' ) { |
|
134 | - $msg = '----------------------------------------------------------------------------------------' . PHP_EOL; |
|
135 | - $msg .= '[' . current_time( 'mysql' ) . '] '; |
|
136 | - $msg .= ! empty( $file ) ? basename( $file ) : ''; |
|
137 | - $msg .= ! empty( $file ) && ! empty( $function ) ? ' -> ' : ''; |
|
138 | - $msg .= ! empty( $function ) ? $function . '()' : ''; |
|
133 | + private function _format_message($file = '', $function = '', $message = '', $type = '') { |
|
134 | + $msg = '----------------------------------------------------------------------------------------'.PHP_EOL; |
|
135 | + $msg .= '['.current_time('mysql').'] '; |
|
136 | + $msg .= ! empty($file) ? basename($file) : ''; |
|
137 | + $msg .= ! empty($file) && ! empty($function) ? ' -> ' : ''; |
|
138 | + $msg .= ! empty($function) ? $function.'()' : ''; |
|
139 | 139 | $msg .= PHP_EOL; |
140 | - $type = ! empty( $type ) ? $type : 'log message'; |
|
141 | - $msg .= ! empty( $message ) ? "\t" . '[' . $type . '] ' . $message . PHP_EOL : ''; |
|
140 | + $type = ! empty($type) ? $type : 'log message'; |
|
141 | + $msg .= ! empty($message) ? "\t".'['.$type.'] '.$message.PHP_EOL : ''; |
|
142 | 142 | return $msg; |
143 | 143 | } |
144 | 144 | |
@@ -153,8 +153,8 @@ discard block |
||
153 | 153 | * @param string $message |
154 | 154 | * @param string $type |
155 | 155 | */ |
156 | - public function log( $file = '', $function = '', $message = '', $type = '' ) { |
|
157 | - $this->_log .= $this->_format_message( $file, $function, $message, $type ); |
|
156 | + public function log($file = '', $function = '', $message = '', $type = '') { |
|
157 | + $this->_log .= $this->_format_message($file, $function, $message, $type); |
|
158 | 158 | } |
159 | 159 | |
160 | 160 | |
@@ -166,10 +166,10 @@ discard block |
||
166 | 166 | public function write_log() { |
167 | 167 | try { |
168 | 168 | //get existing log file and append new log info |
169 | - $this->_log = EEH_File::get_file_contents( $this->_logs_folder . $this->_log_file ) . $this->_log; |
|
170 | - EEH_File::write_to_file( $this->_logs_folder . $this->_log_file, $this->_log, 'Event Espresso Log' ); |
|
171 | - } catch( EE_Error $e ){ |
|
172 | - EE_Error::add_error( sprintf( __( 'Could not write to the Event Espresso log file because: %s', 'event_espresso' ), ' ' . $e->getMessage() ), __FILE__, __FUNCTION__, __LINE__ ); |
|
169 | + $this->_log = EEH_File::get_file_contents($this->_logs_folder.$this->_log_file).$this->_log; |
|
170 | + EEH_File::write_to_file($this->_logs_folder.$this->_log_file, $this->_log, 'Event Espresso Log'); |
|
171 | + } catch (EE_Error $e) { |
|
172 | + EE_Error::add_error(sprintf(__('Could not write to the Event Espresso log file because: %s', 'event_espresso'), ' '.$e->getMessage()), __FILE__, __FUNCTION__, __LINE__); |
|
173 | 173 | return; |
174 | 174 | } |
175 | 175 | } |
@@ -182,31 +182,31 @@ discard block |
||
182 | 182 | */ |
183 | 183 | public function send_log() { |
184 | 184 | |
185 | - if ( empty( $this->_remote_logging_url )) { |
|
185 | + if (empty($this->_remote_logging_url)) { |
|
186 | 186 | return; |
187 | 187 | } |
188 | 188 | |
189 | - $data = 'domain=' . $_SERVER['HTTP_HOST']; |
|
190 | - $data .= '&ip=' . $_SERVER['SERVER_ADDR']; |
|
191 | - $data .= '&server_type=' . $_SERVER['SERVER_SOFTWARE']; |
|
192 | - $data .= '&time=' . time(); |
|
193 | - $data .= '&remote_log=' . $this->_log; |
|
194 | - $data .= '&request_array=' . json_encode( $_REQUEST ); |
|
189 | + $data = 'domain='.$_SERVER['HTTP_HOST']; |
|
190 | + $data .= '&ip='.$_SERVER['SERVER_ADDR']; |
|
191 | + $data .= '&server_type='.$_SERVER['SERVER_SOFTWARE']; |
|
192 | + $data .= '&time='.time(); |
|
193 | + $data .= '&remote_log='.$this->_log; |
|
194 | + $data .= '&request_array='.json_encode($_REQUEST); |
|
195 | 195 | $data .= '&action=save'; |
196 | 196 | |
197 | - if ( defined( 'EELOGGING_PASS' )) { |
|
198 | - $data .= '&pass=' . EELOGGING_PASS; |
|
197 | + if (defined('EELOGGING_PASS')) { |
|
198 | + $data .= '&pass='.EELOGGING_PASS; |
|
199 | 199 | } |
200 | - if ( defined( 'EELOGGING_KEY' )) { |
|
201 | - $data .= '&key=' . EELOGGING_KEY; |
|
200 | + if (defined('EELOGGING_KEY')) { |
|
201 | + $data .= '&key='.EELOGGING_KEY; |
|
202 | 202 | } |
203 | 203 | |
204 | - $c = curl_init( $this->_remote_logging_url ); |
|
205 | - curl_setopt( $c, CURLOPT_POST, TRUE ); |
|
206 | - curl_setopt( $c, CURLOPT_POSTFIELDS, $data ); |
|
207 | - curl_setopt( $c, CURLOPT_RETURNTRANSFER, TRUE ); |
|
208 | - curl_exec( $c ); |
|
209 | - curl_close( $c ); |
|
204 | + $c = curl_init($this->_remote_logging_url); |
|
205 | + curl_setopt($c, CURLOPT_POST, TRUE); |
|
206 | + curl_setopt($c, CURLOPT_POSTFIELDS, $data); |
|
207 | + curl_setopt($c, CURLOPT_RETURNTRANSFER, TRUE); |
|
208 | + curl_exec($c); |
|
209 | + curl_close($c); |
|
210 | 210 | } |
211 | 211 | |
212 | 212 | |
@@ -217,18 +217,18 @@ discard block |
||
217 | 217 | * previous entries are overwritten |
218 | 218 | */ |
219 | 219 | public function write_debug() { |
220 | - if ( defined( 'WP_DEBUG' ) && WP_DEBUG ) { |
|
220 | + if (defined('WP_DEBUG') && WP_DEBUG) { |
|
221 | 221 | $this->_debug_log = ''; |
222 | - foreach ( $_GET as $key => $value ) { |
|
223 | - $this->_debug_log .= '$_GET["' . $key . '"] = "' . serialize($value) . '"' . PHP_EOL; |
|
222 | + foreach ($_GET as $key => $value) { |
|
223 | + $this->_debug_log .= '$_GET["'.$key.'"] = "'.serialize($value).'"'.PHP_EOL; |
|
224 | 224 | } |
225 | - foreach ( $_POST as $key => $value ) { |
|
226 | - $this->_debug_log .= '$_POST["' . $key . '"] = "' . serialize($value) . '"' . PHP_EOL; |
|
225 | + foreach ($_POST as $key => $value) { |
|
226 | + $this->_debug_log .= '$_POST["'.$key.'"] = "'.serialize($value).'"'.PHP_EOL; |
|
227 | 227 | } |
228 | 228 | try { |
229 | - EEH_File::write_to_file( $this->_logs_folder . $this->_debug_file, $this->_debug_log, 'Event Espresso Debug Log' ); |
|
230 | - } catch( EE_Error $e ){ |
|
231 | - EE_Error::add_error( sprintf( __( 'Could not write to the Event Espresso debug log file because: %s', 'event_espresso' ), ' ' . $e->getMessage() ), __FILE__, __FUNCTION__, __LINE__ ); |
|
229 | + EEH_File::write_to_file($this->_logs_folder.$this->_debug_file, $this->_debug_log, 'Event Espresso Debug Log'); |
|
230 | + } catch (EE_Error $e) { |
|
231 | + EE_Error::add_error(sprintf(__('Could not write to the Event Espresso debug log file because: %s', 'event_espresso'), ' '.$e->getMessage()), __FILE__, __FUNCTION__, __LINE__); |
|
232 | 232 | return; |
233 | 233 | } |
234 | 234 | } |
@@ -240,7 +240,7 @@ discard block |
||
240 | 240 | * __clone |
241 | 241 | */ |
242 | 242 | public function __clone() { |
243 | - trigger_error( __( 'Clone is not allowed.', 'event_espresso' ), E_USER_ERROR ); |
|
243 | + trigger_error(__('Clone is not allowed.', 'event_espresso'), E_USER_ERROR); |
|
244 | 244 | } |
245 | 245 | |
246 | 246 |
@@ -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 | /** |
@@ -46,22 +46,22 @@ discard block |
||
46 | 46 | * @return string the assembled html string containing the tabbed content for display. |
47 | 47 | * @throws \EE_Error |
48 | 48 | */ |
49 | - public static function display($tabs_contents, $tabs_names = array(), $small_tabs = true, $tabs_content = TRUE ) { |
|
49 | + public static function display($tabs_contents, $tabs_names = array(), $small_tabs = true, $tabs_content = TRUE) { |
|
50 | 50 | |
51 | 51 | //first check if $tabs_names is not empty then the count must match the count of $tabs_content otherwise we've got a problem houston |
52 | - if ( !empty( $tabs_names) && ( count( (array) $tabs_names) != count( (array) $tabs_content) ) ) { |
|
53 | - throw new EE_Error( __('The count for $tabs_names and $tabs_content does not match.', 'event_espresso') ); |
|
52 | + if ( ! empty($tabs_names) && (count((array) $tabs_names) != count((array) $tabs_content))) { |
|
53 | + throw new EE_Error(__('The count for $tabs_names and $tabs_content does not match.', 'event_espresso')); |
|
54 | 54 | } |
55 | 55 | |
56 | 56 | //make sure we've got incoming data setup properly |
57 | - $tabs = !empty( $tabs_names ) ? (array) $tabs_names : array_keys( (array) $tabs_contents ); |
|
58 | - $tabs_content = !empty( $tabs_names ) ? array_combine( (array) $tabs_names, (array) $tabs_content ) : $tabs_contents; |
|
57 | + $tabs = ! empty($tabs_names) ? (array) $tabs_names : array_keys((array) $tabs_contents); |
|
58 | + $tabs_content = ! empty($tabs_names) ? array_combine((array) $tabs_names, (array) $tabs_content) : $tabs_contents; |
|
59 | 59 | |
60 | - $all_tabs = '<h2 class="nav-tab-wrapper">' . "\n"; |
|
60 | + $all_tabs = '<h2 class="nav-tab-wrapper">'."\n"; |
|
61 | 61 | $all_tabs_content = ''; |
62 | 62 | |
63 | 63 | $index = 0; |
64 | - foreach ( $tabs as $tab ) { |
|
64 | + foreach ($tabs as $tab) { |
|
65 | 65 | $active = $index === 0 ? true : false; |
66 | 66 | $all_tabs .= self::tab($tab, $active); |
67 | 67 | $all_tabs_content .= self::tab_content($tab, $tabs_content[$tab], $active); |
@@ -78,7 +78,7 @@ discard block |
||
78 | 78 | |
79 | 79 | $tab_container_class = $small_tabs ? 'ee-nav-tabs ee-nav-tabs-small' : 'ee-nav-tabs'; |
80 | 80 | |
81 | - return '<div class="'. $tab_container_class . '">' . "\n\t" . $all_tabs . $all_tabs_content . "\n" . '</div>'; |
|
81 | + return '<div class="'.$tab_container_class.'">'."\n\t".$all_tabs.$all_tabs_content."\n".'</div>'; |
|
82 | 82 | } |
83 | 83 | |
84 | 84 | |
@@ -102,11 +102,11 @@ discard block |
||
102 | 102 | * @throws \EE_Error |
103 | 103 | */ |
104 | 104 | public static function display_admin_nav_tabs($nav_tabs = array()) { |
105 | - if ( empty($nav_tabs) ) |
|
106 | - throw new EE_Error( __('Nav Tabs cannot be generated because the tab array is missing', 'event_espresso' ) ); |
|
105 | + if (empty($nav_tabs)) |
|
106 | + throw new EE_Error(__('Nav Tabs cannot be generated because the tab array is missing', 'event_espresso')); |
|
107 | 107 | |
108 | - $all_tabs = '<h2 class="nav-tab-wrapper">' . "\n"; |
|
109 | - foreach ( $nav_tabs as $slug => $tab ) { |
|
108 | + $all_tabs = '<h2 class="nav-tab-wrapper">'."\n"; |
|
109 | + foreach ($nav_tabs as $slug => $tab) { |
|
110 | 110 | $all_tabs .= self::tab($slug, false, $tab['link_text'], $tab['url'], $tab['css_class']); |
111 | 111 | } |
112 | 112 | $all_tabs .= '</h2>'; |
@@ -122,13 +122,13 @@ discard block |
||
122 | 122 | * @param bool|string $css If string given then the generated tab will include that as the class. |
123 | 123 | * @return string html for tab |
124 | 124 | */ |
125 | - private static function tab($name, $active = false, $nice_name = FALSE, $url = FALSE, $css = FALSE ) { |
|
125 | + private static function tab($name, $active = false, $nice_name = FALSE, $url = FALSE, $css = FALSE) { |
|
126 | 126 | $name = str_replace(' ', '-', $name); |
127 | 127 | $class = $active ? 'nav-tab nav-tab-active' : 'nav-tab'; |
128 | - $class = $css ? $class . ' ' . $css : $class; |
|
129 | - $nice_name = $nice_name ? $nice_name : ucwords( preg_replace('/(-|_)/', ' ', $name) ); |
|
130 | - $url = $url ? $url : '#' . $name; |
|
131 | - $tab = '<a class="' . $class . '" rel="ee-tab-' . $name . '" href="' . $url . '">' . $nice_name . '</a>' . "\n\t"; |
|
128 | + $class = $css ? $class.' '.$css : $class; |
|
129 | + $nice_name = $nice_name ? $nice_name : ucwords(preg_replace('/(-|_)/', ' ', $name)); |
|
130 | + $url = $url ? $url : '#'.$name; |
|
131 | + $tab = '<a class="'.$class.'" rel="ee-tab-'.$name.'" href="'.$url.'">'.$nice_name.'</a>'."\n\t"; |
|
132 | 132 | return $tab; |
133 | 133 | } |
134 | 134 | |
@@ -144,9 +144,9 @@ discard block |
||
144 | 144 | */ |
145 | 145 | private static function tab_content($name, $tab_content, $active = false) { |
146 | 146 | $class = $active ? 'nav-tab-content' : 'nav-tab-content hidden'; |
147 | - $name = str_replace( ' ', '-', $name); |
|
148 | - $content = "\t" . '<div class="'. $class . '" id="ee-tab-' . $name . '">' . "\n"; |
|
149 | - $content .= "\t" . $tab_content . "\n"; |
|
147 | + $name = str_replace(' ', '-', $name); |
|
148 | + $content = "\t".'<div class="'.$class.'" id="ee-tab-'.$name.'">'."\n"; |
|
149 | + $content .= "\t".$tab_content."\n"; |
|
150 | 150 | $content .= '<div style="clear:both"></div></div>'; |
151 | 151 | return $content; |
152 | 152 | } |
@@ -172,9 +172,9 @@ discard block |
||
172 | 172 | * @param string $default You can include a string for the item that will receive the "item_display" class for the js. |
173 | 173 | * @return string a html snippet of of all the formatted link elements. |
174 | 174 | */ |
175 | - public static function tab_text_links( $item_array, $container_class = '', $sep = '|', $default = '' ) { |
|
176 | - $item_array = apply_filters( 'FHEE__EEH_Tabbed_Content__tab_text_links', $item_array, $container_class ); |
|
177 | - if ( !is_array($item_array) || empty( $item_array ) ) |
|
175 | + public static function tab_text_links($item_array, $container_class = '', $sep = '|', $default = '') { |
|
176 | + $item_array = apply_filters('FHEE__EEH_Tabbed_Content__tab_text_links', $item_array, $container_class); |
|
177 | + if ( ! is_array($item_array) || empty($item_array)) |
|
178 | 178 | return false; //get out we don't have even the basic thing we need! |
179 | 179 | |
180 | 180 | |
@@ -185,15 +185,15 @@ discard block |
||
185 | 185 | 'title' => esc_attr__('Link for Item', 'event_espresso'), |
186 | 186 | 'slug' => 'item_slug' |
187 | 187 | ); |
188 | - $container_class = !empty($container_class) ? 'ee-text-links ' . $container_class : 'ee-text-links'; |
|
189 | - $list = '<ul class="' . $container_class . '">'; |
|
188 | + $container_class = ! empty($container_class) ? 'ee-text-links '.$container_class : 'ee-text-links'; |
|
189 | + $list = '<ul class="'.$container_class.'">'; |
|
190 | 190 | |
191 | 191 | $ci = 1; |
192 | - foreach ( $item_array as $item ) { |
|
193 | - $item = wp_parse_args( $item, $defaults ); |
|
194 | - $item['class'] = !empty($default) && $default == $item['slug'] ? 'item_display ' . $item['class'] : $item['class']; |
|
192 | + foreach ($item_array as $item) { |
|
193 | + $item = wp_parse_args($item, $defaults); |
|
194 | + $item['class'] = ! empty($default) && $default == $item['slug'] ? 'item_display '.$item['class'] : $item['class']; |
|
195 | 195 | $list .= self::_text_link_item($item); |
196 | - if ( !empty($sep) && $ci != count($item_array) ) |
|
196 | + if ( ! empty($sep) && $ci != count($item_array)) |
|
197 | 197 | $list .= self::_text_link_item($sep); |
198 | 198 | $ci++; |
199 | 199 | } |
@@ -204,9 +204,9 @@ discard block |
||
204 | 204 | |
205 | 205 | |
206 | 206 | |
207 | - private static function _text_link_item( $item ) { |
|
207 | + private static function _text_link_item($item) { |
|
208 | 208 | //if this isn't an array then we're doing a separator |
209 | - if ( !is_array( $item ) ) { |
|
209 | + if ( ! is_array($item)) { |
|
210 | 210 | $label = $item; |
211 | 211 | $class = 'ee-text-link-sep'; |
212 | 212 | $href = ''; |
@@ -215,12 +215,12 @@ discard block |
||
215 | 215 | extract($item); |
216 | 216 | } |
217 | 217 | |
218 | - $class = $class != 'ee-text-link-sep' ? 'class="ee-text-link-li ' . $class . '"' : 'class="ee-text-link-sep"'; |
|
218 | + $class = $class != 'ee-text-link-sep' ? 'class="ee-text-link-li '.$class.'"' : 'class="ee-text-link-sep"'; |
|
219 | 219 | |
220 | - $content = '<li ' . $class . '>'; |
|
221 | - $content .= !empty($href) ? '<a class="ee-text-link" href="#' . $href . '" title="' . $title . '">' : ''; |
|
220 | + $content = '<li '.$class.'>'; |
|
221 | + $content .= ! empty($href) ? '<a class="ee-text-link" href="#'.$href.'" title="'.$title.'">' : ''; |
|
222 | 222 | $content .= $label; |
223 | - $content .= !empty($href) ? '</a>' : ''; |
|
223 | + $content .= ! empty($href) ? '</a>' : ''; |
|
224 | 224 | $content .= '</li>'; |
225 | 225 | return $content; |
226 | 226 | } |
@@ -1,29 +1,29 @@ |
||
1 | 1 | <?php if ( ! defined('EVENT_ESPRESSO_VERSION')) { exit('No direct script access allowed'); } |
2 | 2 | /** |
3 | - * Event Espresso |
|
4 | - * |
|
5 | - * Event Registration and Ticketing Management Plugin for WordPress |
|
6 | - * |
|
7 | - * @ package Event Espresso |
|
8 | - * @ author Event Espresso |
|
9 | - * @ copyright (c) 2008-2014 Event Espresso All Rights Reserved. |
|
10 | - * @ license http://eventespresso.com/support/terms-conditions/ * see Plugin Licensing * |
|
11 | - * @ link http://www.eventespresso.com |
|
12 | - * @ version $VID:$ |
|
13 | - * |
|
14 | - * ------------------------------------------------------------------------ |
|
15 | - */ |
|
3 | + * Event Espresso |
|
4 | + * |
|
5 | + * Event Registration and Ticketing Management Plugin for WordPress |
|
6 | + * |
|
7 | + * @ package Event Espresso |
|
8 | + * @ author Event Espresso |
|
9 | + * @ copyright (c) 2008-2014 Event Espresso All Rights Reserved. |
|
10 | + * @ license http://eventespresso.com/support/terms-conditions/ * see Plugin Licensing * |
|
11 | + * @ link http://www.eventespresso.com |
|
12 | + * @ version $VID:$ |
|
13 | + * |
|
14 | + * ------------------------------------------------------------------------ |
|
15 | + */ |
|
16 | 16 | /** |
17 | - * Class EE_Register_Shortcode |
|
18 | - * |
|
19 | - * EEI_Plugin_API class for registering shortcodes for use with EE core. |
|
20 | - * Receives an array of shortcode details and takes care of adding all of the necessary hooks and filters to integrate with EE core |
|
21 | - * |
|
22 | - * @package Event Espresso |
|
23 | - * @subpackage plugin api |
|
24 | - * @since 4.3.0 |
|
25 | - * @author Brent Christensen |
|
26 | - */ |
|
17 | + * Class EE_Register_Shortcode |
|
18 | + * |
|
19 | + * EEI_Plugin_API class for registering shortcodes for use with EE core. |
|
20 | + * Receives an array of shortcode details and takes care of adding all of the necessary hooks and filters to integrate with EE core |
|
21 | + * |
|
22 | + * @package Event Espresso |
|
23 | + * @subpackage plugin api |
|
24 | + * @since 4.3.0 |
|
25 | + * @author Brent Christensen |
|
26 | + */ |
|
27 | 27 | class EE_Register_Shortcode implements EEI_Plugin_API { |
28 | 28 | |
29 | 29 | /** |
@@ -1,28 +1,28 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | /** |
3 | - * |
|
4 | - * Class EEM_Base |
|
5 | - * |
|
6 | - * Multi-table model. Especially handles joins when querying. |
|
7 | - * An important note about values dealt with in models and model objects: |
|
8 | - * values used by models exist in basically 3 different domains, which the EE_Model_Fields help convert between: |
|
9 | - * 1. Client-code values (eg, controller code may refer to a date as "March 21, 2013") |
|
10 | - * 2. Model object values (eg, after the model object has called set() on the value and saves it onto the model object, it may become a unix timestamp, eg 12312412412) |
|
11 | - * 3. Database values (eg, we may later decide to store dates as mysql dates, in which case they'd be stored as '2013-03-21 00:00:00') |
|
12 | - * Sometimes these values are the same, but often they are not. When your client code is using a model's functions, you need to be aware |
|
13 | - * which domain your data exists in. If it is client-code values (ie, it hasn't had a EE_Model_Field call prepare_for_set on it) then use the |
|
14 | - * model functions as normal. However, if you are calling the model functions with values from the model object domain (ie, the code your writing is |
|
15 | - * probably within a model object, and all the values you're dealing with have had an EE_Model_Field call prepare_for_set on them), then you'll want |
|
16 | - * to set $values_already_prepared_by_model_object to FALSE within the argument-list of the functions you call (in order to avoid re-processing those values). |
|
17 | - * If your values are already in the database values domain, you'll either way to convert them into the model object domain by creating model objects |
|
18 | - * from those raw db values (ie,using EEM_Base::_create_objects), or just use $wpdb directly. |
|
19 | - * |
|
20 | - * @package Event Espresso |
|
21 | - * @subpackage core |
|
22 | - * @author Michael Nelson |
|
23 | - * @since EE4 |
|
24 | - * |
|
25 | - */ |
|
3 | + * |
|
4 | + * Class EEM_Base |
|
5 | + * |
|
6 | + * Multi-table model. Especially handles joins when querying. |
|
7 | + * An important note about values dealt with in models and model objects: |
|
8 | + * values used by models exist in basically 3 different domains, which the EE_Model_Fields help convert between: |
|
9 | + * 1. Client-code values (eg, controller code may refer to a date as "March 21, 2013") |
|
10 | + * 2. Model object values (eg, after the model object has called set() on the value and saves it onto the model object, it may become a unix timestamp, eg 12312412412) |
|
11 | + * 3. Database values (eg, we may later decide to store dates as mysql dates, in which case they'd be stored as '2013-03-21 00:00:00') |
|
12 | + * Sometimes these values are the same, but often they are not. When your client code is using a model's functions, you need to be aware |
|
13 | + * which domain your data exists in. If it is client-code values (ie, it hasn't had a EE_Model_Field call prepare_for_set on it) then use the |
|
14 | + * model functions as normal. However, if you are calling the model functions with values from the model object domain (ie, the code your writing is |
|
15 | + * probably within a model object, and all the values you're dealing with have had an EE_Model_Field call prepare_for_set on them), then you'll want |
|
16 | + * to set $values_already_prepared_by_model_object to FALSE within the argument-list of the functions you call (in order to avoid re-processing those values). |
|
17 | + * If your values are already in the database values domain, you'll either way to convert them into the model object domain by creating model objects |
|
18 | + * from those raw db values (ie,using EEM_Base::_create_objects), or just use $wpdb directly. |
|
19 | + * |
|
20 | + * @package Event Espresso |
|
21 | + * @subpackage core |
|
22 | + * @author Michael Nelson |
|
23 | + * @since EE4 |
|
24 | + * |
|
25 | + */ |
|
26 | 26 | abstract class EEM_Base extends EE_Base{ |
27 | 27 | |
28 | 28 | //admin posty |
@@ -578,10 +578,10 @@ discard block |
||
578 | 578 | $stati = EEM_Status::instance()->get_all(array(array('STS_type' => $status_type) ) ); |
579 | 579 | $status_array = array(); |
580 | 580 | foreach ( $stati as $status ) { |
581 | - $status_array[ $status->ID() ] = $status->get('STS_code'); |
|
582 | - } |
|
583 | - return $translated ? EEM_Status::instance()->localized_status($status_array, FALSE, 'sentence') : $status_array; |
|
584 | - } |
|
581 | + $status_array[ $status->ID() ] = $status->get('STS_code'); |
|
582 | + } |
|
583 | + return $translated ? EEM_Status::instance()->localized_status($status_array, FALSE, 'sentence') : $status_array; |
|
584 | + } |
|
585 | 585 | |
586 | 586 | |
587 | 587 |
@@ -741,7 +741,7 @@ discard block |
||
741 | 741 | * Returns the name of the field's name that points to the WP_User table |
742 | 742 | * on this model (or follows the _model_chain_to_wp_user and uses that model's |
743 | 743 | * foreign key to the WP_User table) |
744 | - * @return string|boolean string on success, boolean false when there is no |
|
744 | + * @return string|false string on success, boolean false when there is no |
|
745 | 745 | * foreign key to the WP_User table |
746 | 746 | */ |
747 | 747 | function wp_user_field_name() { |
@@ -837,6 +837,7 @@ discard block |
||
837 | 837 | * If you would like to use these custom selections in WHERE, GROUP_BY, or HAVING clauses, you must instead provide an array. |
838 | 838 | * Array keys are the aliases used to refer to this selection, and values are to be numerically-indexed arrays, where 0 is the selection |
839 | 839 | * and 1 is the data type. Eg, array('count'=>array('COUNT(REG_ID)','%d')) |
840 | + * @param string $columns_to_select |
|
840 | 841 | * @return stdClass[] like results of $wpdb->get_results($sql,OBJECT), (ie, output type is OBJECT) |
841 | 842 | */ |
842 | 843 | public function get_all_wpdb_results($query_params = array(), $output = ARRAY_A, $columns_to_select = null){ |
@@ -1139,7 +1140,7 @@ discard block |
||
1139 | 1140 | * @param bool $pretty Whether to return the pretty formats (true) or not (false). |
1140 | 1141 | * @throws EE_Error If the given field_name is not of the EE_Datetime_Field type. |
1141 | 1142 | * |
1142 | - * @return array formats in an array with the date format first, and the time format last. |
|
1143 | + * @return string[] formats in an array with the date format first, and the time format last. |
|
1143 | 1144 | */ |
1144 | 1145 | public function get_formats_for( $field_name, $pretty = false ) { |
1145 | 1146 | $field_settings = $this->field_settings_for( $field_name ); |
@@ -1174,7 +1175,7 @@ discard block |
||
1174 | 1175 | * |
1175 | 1176 | * @throws EE_Error If the given field_name is not of the EE_Datetime_Field type. |
1176 | 1177 | * |
1177 | - * @return int|string If the given field_name is not of the EE_Datetime_Field type, then an EE_Error |
|
1178 | + * @return string|null If the given field_name is not of the EE_Datetime_Field type, then an EE_Error |
|
1178 | 1179 | * exception is triggered. |
1179 | 1180 | */ |
1180 | 1181 | public function current_time_for_query( $field_name, $timestamp = false, $what = 'both' ) { |
@@ -1474,7 +1475,7 @@ discard block |
||
1474 | 1475 | * Deletes a single row from the DB given the model object's primary key value. (eg, EE_Attendee->ID()'s value). |
1475 | 1476 | * Wrapper for EEM_Base::delete() |
1476 | 1477 | * @param mixed $id |
1477 | - * @return boolean whether the row got deleted or not |
|
1478 | + * @return integer whether the row got deleted or not |
|
1478 | 1479 | */ |
1479 | 1480 | public function delete_by_ID( $id ){ |
1480 | 1481 | return $this->delete( array( |
@@ -1834,7 +1835,7 @@ discard block |
||
1834 | 1835 | /** |
1835 | 1836 | * Verifies the EE addons' database is up-to-date and records that we've done it on |
1836 | 1837 | * EEM_Base::$_db_verification_level |
1837 | - * @param $wpdb_method |
|
1838 | + * @param string $wpdb_method |
|
1838 | 1839 | * @param $arguments_to_provide |
1839 | 1840 | * @return string |
1840 | 1841 | */ |
@@ -1902,7 +1903,6 @@ discard block |
||
1902 | 1903 | * 'hasAndBelongsToMany' relationships: checks that there isn't already an entry in the join table, and adds one. |
1903 | 1904 | * If one of the model Objects has not yet been saved to the database, it is saved before adding the entry in the join table |
1904 | 1905 | * |
1905 | - * @param EE_Base_Class/int $thisModelObject |
|
1906 | 1906 | * @param EE_Base_Class/int $id_or_obj EE_base_Class or ID of other Model Object |
1907 | 1907 | * @param string $relationName, key in EEM_Base::_relations |
1908 | 1908 | * an attendee to a group, you also want to specify which role they will have in that group. So you would use this parameter to specify array('role-column-name'=>'role-id') |
@@ -1924,8 +1924,8 @@ discard block |
||
1924 | 1924 | * |
1925 | 1925 | * 'hasAndBelongsToMany' relationships:removes any existing entry in the join table between the two models. |
1926 | 1926 | * |
1927 | - * @param EE_Base_Class/int $id_or_obj |
|
1928 | - * @param EE_Base_Class/int $other_model_id_or_obj EE_Base_Class or ID of other Model Object |
|
1927 | + * @param EE_CPT_Base $id_or_obj |
|
1928 | + * @param EE_Term_Taxonomy $other_model_id_or_obj EE_Base_Class or ID of other Model Object |
|
1929 | 1929 | * @param string $relationName key in EEM_Base::_relations |
1930 | 1930 | * @return boolean of success |
1931 | 1931 | * @param array $where_query This allows you to enter further query params for the relation to for relation to methods that allow you to further specify extra columns to join by (such as HABTM). Keep in mind that the only acceptable query_params is strict "col" => "value" pairs because these will be inserted in any new rows created as well. |
@@ -2001,7 +2001,7 @@ discard block |
||
2001 | 2001 | /** |
2002 | 2002 | * Instead of getting the related model objects, simply counts them. Ignores default_where_conditions by default, |
2003 | 2003 | * unless otherwise specified in the $query_params |
2004 | - * @param int/EE_Base_Class $id_or_obj |
|
2004 | + * @param EE_Event $id_or_obj |
|
2005 | 2005 | * @param string $model_name like 'Event', or 'Registration' |
2006 | 2006 | * @param array $query_params like EEM_Base::get_all's |
2007 | 2007 | * @param string $field_to_count name of field to count by. By default, uses primary key |
@@ -2390,7 +2390,7 @@ discard block |
||
2390 | 2390 | /** |
2391 | 2391 | * Finds all the fields that correspond to the given table |
2392 | 2392 | * @param string $table_alias, array key in EEM_Base::_tables |
2393 | - * @return EE_Model_Field_Base[] |
|
2393 | + * @return EE_Model_Field_Base |
|
2394 | 2394 | */ |
2395 | 2395 | function _get_fields_for_table($table_alias){ |
2396 | 2396 | return $this->_fields[$table_alias]; |
@@ -3454,8 +3454,8 @@ discard block |
||
3454 | 3454 | /** |
3455 | 3455 | * gets the field object of type 'primary_key' from the fieldsSettings attribute. |
3456 | 3456 | * Eg, on EE_Answer that would be ANS_ID field object |
3457 | - * @param $field_obj |
|
3458 | - * @return EE_Model_Field_Base |
|
3457 | + * @param EE_Model_Field_Base $field_obj |
|
3458 | + * @return boolean |
|
3459 | 3459 | */ |
3460 | 3460 | public function is_primary_key_field( $field_obj ){ |
3461 | 3461 | return $field_obj instanceof EE_Primary_Key_Field_Base ? TRUE : FALSE; |
@@ -3549,7 +3549,7 @@ discard block |
||
3549 | 3549 | * Gets the actual table for the table alias |
3550 | 3550 | * @param string $table_alias eg Event, Event_Meta, Registration, Transaction, but maybe |
3551 | 3551 | * a table alias with a model chain prefix, like 'Venue__Event_Venue___Event_Meta'. Either one works |
3552 | - * @return EE_Table_Base |
|
3552 | + * @return string |
|
3553 | 3553 | */ |
3554 | 3554 | function get_table_for_alias($table_alias){ |
3555 | 3555 | $table_alias_sans_model_relation_chain_prefix = EE_Model_Parser::remove_table_alias_model_relation_chain_prefix($table_alias); |
@@ -3676,7 +3676,7 @@ discard block |
||
3676 | 3676 | * The purpose of this method is to allow us to create a model object that is not in the db that holds default values. |
3677 | 3677 | * A typical example of where this is used is when creating a new item and the initial load of a form. We dont' necessarily want to test for if the object is present but just assume it is BUT load the defaults from the object (as set in the model_field!). |
3678 | 3678 | * |
3679 | - * @return EE_Base_Class single EE_Base_Class object with default values for the properties. |
|
3679 | + * @return boolean single EE_Base_Class object with default values for the properties. |
|
3680 | 3680 | */ |
3681 | 3681 | public function create_default_object() { |
3682 | 3682 | |
@@ -4066,7 +4066,7 @@ discard block |
||
4066 | 4066 | } |
4067 | 4067 | /** |
4068 | 4068 | * Read comments for assume_values_already_prepared_by_model_object() |
4069 | - * @return int |
|
4069 | + * @return boolean |
|
4070 | 4070 | */ |
4071 | 4071 | public function get_assumption_concerning_values_already_prepared_by_model_object(){ |
4072 | 4072 | return $this->_values_already_prepared_by_model_object; |
@@ -23,7 +23,7 @@ discard block |
||
23 | 23 | * @since EE4 |
24 | 24 | * |
25 | 25 | */ |
26 | -abstract class EEM_Base extends EE_Base{ |
|
26 | +abstract class EEM_Base extends EE_Base { |
|
27 | 27 | |
28 | 28 | //admin posty |
29 | 29 | //basic -> grants access to mine -> if they don't have it, select none |
@@ -228,7 +228,7 @@ discard block |
||
228 | 228 | * Flag indicating whether this model has a primary key or not |
229 | 229 | * @var boolean |
230 | 230 | */ |
231 | - protected $_has_primary_key_field=null; |
|
231 | + protected $_has_primary_key_field = null; |
|
232 | 232 | |
233 | 233 | /** |
234 | 234 | * Whether or not this model is based off a table in WP core only (CPTs should set |
@@ -290,19 +290,19 @@ discard block |
||
290 | 290 | * operators that work like 'BETWEEN'. Typically used for datetime calculations, i.e. "BETWEEN '12-1-2011' AND '12-31-2012'" |
291 | 291 | * @var array |
292 | 292 | */ |
293 | - protected $_between_style_operators = array( 'BETWEEN' ); |
|
293 | + protected $_between_style_operators = array('BETWEEN'); |
|
294 | 294 | |
295 | 295 | /** |
296 | 296 | * operators that are used for handling NUll and !NULL queries. Typically used for when checking if a row exists on a join table. |
297 | 297 | * @var array |
298 | 298 | */ |
299 | - protected $_null_style_operators = array( 'IS NOT NULL', 'IS NULL'); |
|
299 | + protected $_null_style_operators = array('IS NOT NULL', 'IS NULL'); |
|
300 | 300 | |
301 | 301 | /** |
302 | 302 | * Allowed values for $query_params['order'] for ordering in queries |
303 | 303 | * @var array |
304 | 304 | */ |
305 | - protected $_allowed_order_values = array('asc','desc','ASC','DESC'); |
|
305 | + protected $_allowed_order_values = array('asc', 'desc', 'ASC', 'DESC'); |
|
306 | 306 | |
307 | 307 | /** |
308 | 308 | * When these are keys in a WHERE or HAVING clause, they are handled much differently |
@@ -316,13 +316,13 @@ discard block |
||
316 | 316 | * 'where', but 'where' clauses are so common that we thought we'd omit it |
317 | 317 | * @var array |
318 | 318 | */ |
319 | - private $_allowed_query_params = array(0, 'limit','order_by','group_by','having','force_join','order','on_join_limit','default_where_conditions', 'caps'); |
|
319 | + private $_allowed_query_params = array(0, 'limit', 'order_by', 'group_by', 'having', 'force_join', 'order', 'on_join_limit', 'default_where_conditions', 'caps'); |
|
320 | 320 | |
321 | 321 | /** |
322 | 322 | * All the data types that can be used in $wpdb->prepare statements. |
323 | 323 | * @var array |
324 | 324 | */ |
325 | - private $_valid_wpdb_data_types = array('%d','%s','%f'); |
|
325 | + private $_valid_wpdb_data_types = array('%d', '%s', '%f'); |
|
326 | 326 | |
327 | 327 | /** |
328 | 328 | * EE_Registry Object |
@@ -355,17 +355,17 @@ discard block |
||
355 | 355 | /** |
356 | 356 | * constant used to show EEM_Base has not yet verified the db on this http request |
357 | 357 | */ |
358 | - const db_verified_none = 0; |
|
358 | + const db_verified_none = 0; |
|
359 | 359 | /** |
360 | 360 | * constant used to show EEM_Base has verified the EE core db on this http request, |
361 | 361 | * but not the addons' dbs |
362 | 362 | */ |
363 | - const db_verified_core = 1; |
|
363 | + const db_verified_core = 1; |
|
364 | 364 | /** |
365 | 365 | * constant used to show EEM_Base has verified the addons' dbs (and implicitly |
366 | 366 | * the EE core db too) |
367 | 367 | */ |
368 | - const db_verified_addons = 2; |
|
368 | + const db_verified_addons = 2; |
|
369 | 369 | |
370 | 370 | /** |
371 | 371 | * indicates whether an EEM_Base child has already re-verified the DB |
@@ -396,13 +396,13 @@ discard block |
||
396 | 396 | * @param null $timezone |
397 | 397 | * @throws \EE_Error |
398 | 398 | */ |
399 | - protected function __construct( $timezone = NULL ){ |
|
399 | + protected function __construct($timezone = NULL) { |
|
400 | 400 | // check that the model has not been loaded too soon |
401 | - if ( ! did_action( 'AHEE__EE_System__load_espresso_addons' )) { |
|
402 | - throw new EE_Error ( |
|
401 | + if ( ! did_action('AHEE__EE_System__load_espresso_addons')) { |
|
402 | + throw new EE_Error( |
|
403 | 403 | sprintf( |
404 | - __( 'The %1$s model can not be loaded before the "AHEE__EE_System__load_espresso_addons" hook has been called. This gives other addons a chance to extend this model.', 'event_espresso' ), |
|
405 | - get_class( $this ) |
|
404 | + __('The %1$s model can not be loaded before the "AHEE__EE_System__load_espresso_addons" hook has been called. This gives other addons a chance to extend this model.', 'event_espresso'), |
|
405 | + get_class($this) |
|
406 | 406 | ) |
407 | 407 | ); |
408 | 408 | } |
@@ -412,11 +412,11 @@ discard block |
||
412 | 412 | * just use EE_Register_Model_Extension |
413 | 413 | * @var EE_Table_Base[] $_tables |
414 | 414 | */ |
415 | - $this->_tables = apply_filters( 'FHEE__'.get_class($this).'__construct__tables', $this->_tables ); |
|
416 | - foreach($this->_tables as $table_alias => $table_obj){ |
|
415 | + $this->_tables = apply_filters('FHEE__'.get_class($this).'__construct__tables', $this->_tables); |
|
416 | + foreach ($this->_tables as $table_alias => $table_obj) { |
|
417 | 417 | /** @var $table_obj EE_Table_Base */ |
418 | 418 | $table_obj->_construct_finalize_with_alias($table_alias); |
419 | - if( $table_obj instanceof EE_Secondary_Table ){ |
|
419 | + if ($table_obj instanceof EE_Secondary_Table) { |
|
420 | 420 | /** @var $table_obj EE_Secondary_Table */ |
421 | 421 | $table_obj->_construct_finalize_set_table_to_join_with($this->_get_main_table()); |
422 | 422 | } |
@@ -426,48 +426,48 @@ discard block |
||
426 | 426 | * EE_Register_Model_Extension |
427 | 427 | * @param EE_Model_Field_Base[] $_fields |
428 | 428 | */ |
429 | - $this->_fields = apply_filters('FHEE__'.get_class($this).'__construct__fields',$this->_fields); |
|
430 | - foreach($this->_fields as $table_alias => $fields_for_table){ |
|
431 | - if ( ! array_key_exists( $table_alias, $this->_tables )){ |
|
432 | - throw new EE_Error(sprintf(__("Table alias %s does not exist in EEM_Base child's _tables array. Only tables defined are %s",'event_espresso'),$table_alias,implode(",",$this->_fields))); |
|
429 | + $this->_fields = apply_filters('FHEE__'.get_class($this).'__construct__fields', $this->_fields); |
|
430 | + foreach ($this->_fields as $table_alias => $fields_for_table) { |
|
431 | + if ( ! array_key_exists($table_alias, $this->_tables)) { |
|
432 | + throw new EE_Error(sprintf(__("Table alias %s does not exist in EEM_Base child's _tables array. Only tables defined are %s", 'event_espresso'), $table_alias, implode(",", $this->_fields))); |
|
433 | 433 | } |
434 | - foreach($fields_for_table as $field_name => $field_obj){ |
|
434 | + foreach ($fields_for_table as $field_name => $field_obj) { |
|
435 | 435 | /** @var $field_obj EE_Model_Field_Base | EE_Primary_Key_Field_Base */ |
436 | 436 | //primary key field base has a slightly different _construct_finalize |
437 | 437 | /** @var $field_obj EE_Model_Field_Base */ |
438 | - $field_obj->_construct_finalize( $table_alias, $field_name, $this->get_this_model_name() ); |
|
438 | + $field_obj->_construct_finalize($table_alias, $field_name, $this->get_this_model_name()); |
|
439 | 439 | } |
440 | 440 | } |
441 | 441 | |
442 | 442 | // everything is related to Extra_Meta |
443 | - if( get_class($this) != 'EEM_Extra_Meta'){ |
|
443 | + if (get_class($this) != 'EEM_Extra_Meta') { |
|
444 | 444 | //make extra meta related to everything, but don't block deleting things just |
445 | 445 | //because they have related extra meta info. For now just orphan those extra meta |
446 | 446 | //in the future we should automatically delete them |
447 | - $this->_model_relations['Extra_Meta'] = new EE_Has_Many_Any_Relation( FALSE ); |
|
447 | + $this->_model_relations['Extra_Meta'] = new EE_Has_Many_Any_Relation(FALSE); |
|
448 | 448 | } |
449 | 449 | //and change logs |
450 | - if( get_class( $this) != 'EEM_Change_Log' ) { |
|
451 | - $this->_model_relations[ 'Change_Log' ] = new EE_Has_Many_Any_Relation( FALSE ); |
|
450 | + if (get_class($this) != 'EEM_Change_Log') { |
|
451 | + $this->_model_relations['Change_Log'] = new EE_Has_Many_Any_Relation(FALSE); |
|
452 | 452 | } |
453 | 453 | /** |
454 | 454 | * Filters the list of relations on a model. It is best to NOT use this directly and instead just use |
455 | 455 | * EE_Register_Model_Extension |
456 | 456 | * @param EE_Model_Relation_Base[] $_model_relations |
457 | 457 | */ |
458 | - $this->_model_relations = apply_filters('FHEE__'.get_class($this).'__construct__model_relations',$this->_model_relations); |
|
459 | - foreach($this->_model_relations as $model_name => $relation_obj){ |
|
458 | + $this->_model_relations = apply_filters('FHEE__'.get_class($this).'__construct__model_relations', $this->_model_relations); |
|
459 | + foreach ($this->_model_relations as $model_name => $relation_obj) { |
|
460 | 460 | /** @var $relation_obj EE_Model_Relation_Base */ |
461 | 461 | $relation_obj->_construct_finalize_set_models($this->get_this_model_name(), $model_name); |
462 | 462 | } |
463 | - foreach($this->_indexes as $index_name => $index_obj){ |
|
463 | + foreach ($this->_indexes as $index_name => $index_obj) { |
|
464 | 464 | /** @var $index_obj EE_Index */ |
465 | 465 | $index_obj->_construct_finalize($index_name, $this->get_this_model_name()); |
466 | 466 | } |
467 | 467 | |
468 | 468 | $this->set_timezone($timezone); |
469 | 469 | //finalize default where condition strategy, or set default |
470 | - if( ! $this->_default_where_conditions_strategy){ |
|
470 | + if ( ! $this->_default_where_conditions_strategy) { |
|
471 | 471 | //nothing was set during child constructor, so set default |
472 | 472 | $this->_default_where_conditions_strategy = new EE_Default_Where_Conditions(); |
473 | 473 | } |
@@ -475,15 +475,15 @@ discard block |
||
475 | 475 | |
476 | 476 | //if the cap slug hasn't been set, and we haven't set it to false on purpose |
477 | 477 | //to indicate to NOT set it, set it to the logical default |
478 | - if( $this->_caps_slug === null ) { |
|
479 | - EE_Registry::instance()->load_helper( 'Inflector' ); |
|
480 | - $this->_caps_slug = EEH_Inflector::pluralize_and_lower( $this->get_this_model_name() ); |
|
478 | + if ($this->_caps_slug === null) { |
|
479 | + EE_Registry::instance()->load_helper('Inflector'); |
|
480 | + $this->_caps_slug = EEH_Inflector::pluralize_and_lower($this->get_this_model_name()); |
|
481 | 481 | } |
482 | 482 | //initialize the standard cap restriction generators if none were specified by the child constructor |
483 | - if( $this->_cap_restriction_generators !== false ){ |
|
484 | - foreach( $this->cap_contexts_to_cap_action_map() as $cap_context => $action ){ |
|
485 | - if( ! isset( $this->_cap_restriction_generators[ $cap_context ] ) ) { |
|
486 | - $this->_cap_restriction_generators[ $cap_context ] = apply_filters( |
|
483 | + if ($this->_cap_restriction_generators !== false) { |
|
484 | + foreach ($this->cap_contexts_to_cap_action_map() as $cap_context => $action) { |
|
485 | + if ( ! isset($this->_cap_restriction_generators[$cap_context])) { |
|
486 | + $this->_cap_restriction_generators[$cap_context] = apply_filters( |
|
487 | 487 | 'FHEE__EEM_Base___construct__standard_cap_restriction_generator', |
488 | 488 | new EE_Restriction_Generator_Protected(), |
489 | 489 | $cap_context, |
@@ -493,23 +493,23 @@ discard block |
||
493 | 493 | } |
494 | 494 | } |
495 | 495 | //if there are cap restriction generators, use them to make the default cap restrictions |
496 | - if( $this->_cap_restriction_generators !== false ){ |
|
497 | - foreach( $this->_cap_restriction_generators as $context => $generator_object ) { |
|
498 | - if( ! $generator_object ){ |
|
496 | + if ($this->_cap_restriction_generators !== false) { |
|
497 | + foreach ($this->_cap_restriction_generators as $context => $generator_object) { |
|
498 | + if ( ! $generator_object) { |
|
499 | 499 | continue; |
500 | 500 | } |
501 | - if( ! $generator_object instanceof EE_Restriction_Generator_Base ){ |
|
501 | + if ( ! $generator_object instanceof EE_Restriction_Generator_Base) { |
|
502 | 502 | throw new EE_Error( |
503 | 503 | sprintf( |
504 | - __( 'Index "%1$s" in the model %2$s\'s _cap_restriction_generators is not a child of EE_Restriction_Generator_Base. It should be that or NULL.', 'event_espresso' ), |
|
504 | + __('Index "%1$s" in the model %2$s\'s _cap_restriction_generators is not a child of EE_Restriction_Generator_Base. It should be that or NULL.', 'event_espresso'), |
|
505 | 505 | $context, |
506 | 506 | $this->get_this_model_name() |
507 | 507 | ) |
508 | 508 | ); |
509 | 509 | } |
510 | - $action = $this->cap_action_for_context( $context ); |
|
511 | - if( ! $generator_object->construction_finalized() ){ |
|
512 | - $generator_object->_construct_finalize( $this, $action ); |
|
510 | + $action = $this->cap_action_for_context($context); |
|
511 | + if ( ! $generator_object->construction_finalized()) { |
|
512 | + $generator_object->_construct_finalize($this, $action); |
|
513 | 513 | } |
514 | 514 | |
515 | 515 | } |
@@ -523,11 +523,11 @@ discard block |
||
523 | 523 | * @param string $context one of EEM_Base::valid_cap_contexts() |
524 | 524 | * @return EE_Default_Where_Conditions[] |
525 | 525 | */ |
526 | - protected function _generate_cap_restrictions( $context ){ |
|
527 | - if( isset( $this->_cap_restriction_generators[ $context ] ) && |
|
528 | - $this->_cap_restriction_generators[ $context ] instanceof EE_Restriction_Generator_Base ) { |
|
529 | - return $this->_cap_restriction_generators[ $context ]->generate_restrictions(); |
|
530 | - }else{ |
|
526 | + protected function _generate_cap_restrictions($context) { |
|
527 | + if (isset($this->_cap_restriction_generators[$context]) && |
|
528 | + $this->_cap_restriction_generators[$context] instanceof EE_Restriction_Generator_Base) { |
|
529 | + return $this->_cap_restriction_generators[$context]->generate_restrictions(); |
|
530 | + } else { |
|
531 | 531 | return array(); |
532 | 532 | } |
533 | 533 | } |
@@ -540,16 +540,16 @@ discard block |
||
540 | 540 | * @param string $timezone string representing the timezone we want to set for returned Date Time Strings (and any incoming timezone data that gets saved). Note this just sends the timezone info to the date time model field objects. Default is NULL (and will be assumed using the set timezone in the 'timezone_string' wp option) |
541 | 541 | * @return static (as in the concrete child class) |
542 | 542 | */ |
543 | - public static function instance( $timezone = NULL ){ |
|
543 | + public static function instance($timezone = NULL) { |
|
544 | 544 | |
545 | 545 | // check if instance of Espresso_model already exists |
546 | 546 | if ( ! static::$_instance instanceof static) { |
547 | 547 | // instantiate Espresso_model |
548 | - static::$_instance = new static( $timezone ); |
|
548 | + static::$_instance = new static($timezone); |
|
549 | 549 | } |
550 | 550 | |
551 | 551 | //we might have a timezone set, let set_timezone decide what to do with it |
552 | - static::$_instance->set_timezone( $timezone ); |
|
552 | + static::$_instance->set_timezone($timezone); |
|
553 | 553 | |
554 | 554 | // Espresso_model object |
555 | 555 | return static::$_instance; |
@@ -562,11 +562,11 @@ discard block |
||
562 | 562 | * @param null | string $timezone |
563 | 563 | * @return static |
564 | 564 | */ |
565 | - public static function reset( $timezone = NULL ){ |
|
566 | - if ( ! is_null( static::$_instance ) ) { |
|
565 | + public static function reset($timezone = NULL) { |
|
566 | + if ( ! is_null(static::$_instance)) { |
|
567 | 567 | static::$_instance = null; |
568 | 568 | |
569 | - return self::instance( $timezone ); |
|
569 | + return self::instance($timezone); |
|
570 | 570 | } |
571 | 571 | return null; |
572 | 572 | } |
@@ -577,15 +577,15 @@ discard block |
||
577 | 577 | * @param boolean $translated return localized strings or JUST the array. |
578 | 578 | * @return array |
579 | 579 | */ |
580 | - public function status_array( $translated = FALSE ) { |
|
581 | - if ( !array_key_exists('Status', $this->_model_relations ) ) |
|
580 | + public function status_array($translated = FALSE) { |
|
581 | + if ( ! array_key_exists('Status', $this->_model_relations)) |
|
582 | 582 | return array(); |
583 | 583 | $model_name = $this->get_this_model_name(); |
584 | - $status_type = str_replace(' ', '_', strtolower( str_replace('_', ' ', $model_name) ) ); |
|
585 | - $stati = EEM_Status::instance()->get_all(array(array('STS_type' => $status_type) ) ); |
|
584 | + $status_type = str_replace(' ', '_', strtolower(str_replace('_', ' ', $model_name))); |
|
585 | + $stati = EEM_Status::instance()->get_all(array(array('STS_type' => $status_type))); |
|
586 | 586 | $status_array = array(); |
587 | - foreach ( $stati as $status ) { |
|
588 | - $status_array[ $status->ID() ] = $status->get('STS_code'); |
|
587 | + foreach ($stati as $status) { |
|
588 | + $status_array[$status->ID()] = $status->get('STS_code'); |
|
589 | 589 | } |
590 | 590 | return $translated ? EEM_Status::instance()->localized_status($status_array, FALSE, 'sentence') : $status_array; |
591 | 591 | } |
@@ -726,7 +726,7 @@ discard block |
||
726 | 726 | * 'order_by'=>array('ANS_value'=>'ASC') |
727 | 727 | * )); |
728 | 728 | */ |
729 | - function get_all($query_params = array()){ |
|
729 | + function get_all($query_params = array()) { |
|
730 | 730 | return $this->_create_objects($this->_get_all_wpdb_results($query_params, ARRAY_A, NULL)); |
731 | 731 | } |
732 | 732 | |
@@ -736,10 +736,10 @@ discard block |
||
736 | 736 | * @param array $query_params @see EEM_Base::get_all() |
737 | 737 | * @return array like EEM_Base::get_all |
738 | 738 | */ |
739 | - function alter_query_params_to_only_include_mine( $query_params = array() ) { |
|
739 | + function alter_query_params_to_only_include_mine($query_params = array()) { |
|
740 | 740 | $wp_user_field_name = $this->wp_user_field_name(); |
741 | - if( $wp_user_field_name ){ |
|
742 | - $query_params[0][ $wp_user_field_name ] = get_current_user_id(); |
|
741 | + if ($wp_user_field_name) { |
|
742 | + $query_params[0][$wp_user_field_name] = get_current_user_id(); |
|
743 | 743 | } |
744 | 744 | return $query_params; |
745 | 745 | } |
@@ -752,19 +752,19 @@ discard block |
||
752 | 752 | * foreign key to the WP_User table |
753 | 753 | */ |
754 | 754 | function wp_user_field_name() { |
755 | - try{ |
|
756 | - if( ! empty( $this->_model_chain_to_wp_user ) ) { |
|
757 | - $models_to_follow_to_wp_users = explode( '.', $this->_model_chain_to_wp_user ); |
|
758 | - $last_model_name = end( $models_to_follow_to_wp_users ); |
|
759 | - $model_with_fk_to_wp_users = EE_Registry::instance()->load_model( $last_model_name ); |
|
760 | - $model_chain_to_wp_user = $this->_model_chain_to_wp_user . '.'; |
|
761 | - }else{ |
|
755 | + try { |
|
756 | + if ( ! empty($this->_model_chain_to_wp_user)) { |
|
757 | + $models_to_follow_to_wp_users = explode('.', $this->_model_chain_to_wp_user); |
|
758 | + $last_model_name = end($models_to_follow_to_wp_users); |
|
759 | + $model_with_fk_to_wp_users = EE_Registry::instance()->load_model($last_model_name); |
|
760 | + $model_chain_to_wp_user = $this->_model_chain_to_wp_user.'.'; |
|
761 | + } else { |
|
762 | 762 | $model_with_fk_to_wp_users = $this; |
763 | 763 | $model_chain_to_wp_user = ''; |
764 | 764 | } |
765 | - $wp_user_field = $model_with_fk_to_wp_users->get_foreign_key_to( 'WP_User' ); |
|
766 | - return $model_chain_to_wp_user . $wp_user_field->get_name(); |
|
767 | - }catch( EE_Error $e ) { |
|
765 | + $wp_user_field = $model_with_fk_to_wp_users->get_foreign_key_to('WP_User'); |
|
766 | + return $model_chain_to_wp_user.$wp_user_field->get_name(); |
|
767 | + } catch (EE_Error $e) { |
|
768 | 768 | return false; |
769 | 769 | } |
770 | 770 | } |
@@ -778,7 +778,7 @@ discard block |
||
778 | 778 | * (or transiently-related model) |
779 | 779 | * @return string |
780 | 780 | */ |
781 | - public function model_chain_to_wp_user(){ |
|
781 | + public function model_chain_to_wp_user() { |
|
782 | 782 | return $this->_model_chain_to_wp_user; |
783 | 783 | } |
784 | 784 | |
@@ -790,13 +790,13 @@ discard block |
||
790 | 790 | * @return boolean |
791 | 791 | */ |
792 | 792 | public function is_owned() { |
793 | - if( $this->model_chain_to_wp_user() ){ |
|
793 | + if ($this->model_chain_to_wp_user()) { |
|
794 | 794 | return true; |
795 | - }else{ |
|
796 | - try{ |
|
797 | - $this->get_foreign_key_to( 'WP_User' ); |
|
795 | + } else { |
|
796 | + try { |
|
797 | + $this->get_foreign_key_to('WP_User'); |
|
798 | 798 | return true; |
799 | - }catch( EE_Error $e ){ |
|
799 | + } catch (EE_Error $e) { |
|
800 | 800 | return false; |
801 | 801 | } |
802 | 802 | } |
@@ -815,21 +815,21 @@ discard block |
||
815 | 815 | * and 1 is the data type. Eg, array('count'=>array('COUNT(REG_ID)','%d')) |
816 | 816 | * @return array | stdClass[] like results of $wpdb->get_results($sql,OBJECT), (ie, output type is OBJECT) |
817 | 817 | */ |
818 | - protected function _get_all_wpdb_results($query_params = array(), $output = ARRAY_A, $columns_to_select = null){ |
|
818 | + protected function _get_all_wpdb_results($query_params = array(), $output = ARRAY_A, $columns_to_select = null) { |
|
819 | 819 | //remember the custom selections, if any |
820 | - if(is_array($columns_to_select)){ |
|
820 | + if (is_array($columns_to_select)) { |
|
821 | 821 | $this->_custom_selections = $columns_to_select; |
822 | - }elseif(is_string($columns_to_select)){ |
|
822 | + }elseif (is_string($columns_to_select)) { |
|
823 | 823 | $this->_custom_selections = array($this->_custom_selections); |
824 | - }else{ |
|
824 | + } else { |
|
825 | 825 | $this->_custom_selections = array(); |
826 | 826 | } |
827 | 827 | |
828 | 828 | $model_query_info = $this->_create_model_query_info_carrier($query_params); |
829 | 829 | $select_expressions = $columns_to_select ? $this->_construct_select_from_input($columns_to_select) : $this->_construct_default_select_sql($model_query_info); |
830 | - $SQL ="SELECT $select_expressions ".$this->_construct_2nd_half_of_select_query($model_query_info); |
|
830 | + $SQL = "SELECT $select_expressions ".$this->_construct_2nd_half_of_select_query($model_query_info); |
|
831 | 831 | // echo "sql:$SQL"; |
832 | - $results = $this->_do_wpdb_query( 'get_results', array($SQL, $output ) );// $wpdb->get_results($SQL, $output); |
|
832 | + $results = $this->_do_wpdb_query('get_results', array($SQL, $output)); // $wpdb->get_results($SQL, $output); |
|
833 | 833 | return $results; |
834 | 834 | } |
835 | 835 | |
@@ -847,7 +847,7 @@ discard block |
||
847 | 847 | * and 1 is the data type. Eg, array('count'=>array('COUNT(REG_ID)','%d')) |
848 | 848 | * @return array|stdClass[] like results of $wpdb->get_results($sql,OBJECT), (ie, output type is OBJECT) |
849 | 849 | */ |
850 | - public function get_all_wpdb_results($query_params = array(), $output = ARRAY_A, $columns_to_select = null){ |
|
850 | + public function get_all_wpdb_results($query_params = array(), $output = ARRAY_A, $columns_to_select = null) { |
|
851 | 851 | return $this->_get_all_wpdb_results($query_params, $output, $columns_to_select); |
852 | 852 | } |
853 | 853 | |
@@ -859,12 +859,12 @@ discard block |
||
859 | 859 | * @throws EE_Error |
860 | 860 | * @return string |
861 | 861 | */ |
862 | - private function _construct_select_from_input($columns_to_select){ |
|
863 | - if(is_array($columns_to_select)){ |
|
862 | + private function _construct_select_from_input($columns_to_select) { |
|
863 | + if (is_array($columns_to_select)) { |
|
864 | 864 | $select_sql_array = array(); |
865 | 865 | |
866 | - foreach($columns_to_select as $alias => $selection_and_datatype){ |
|
867 | - if( ! is_array($selection_and_datatype) || ! isset($selection_and_datatype[1])){ |
|
866 | + foreach ($columns_to_select as $alias => $selection_and_datatype) { |
|
867 | + if ( ! is_array($selection_and_datatype) || ! isset($selection_and_datatype[1])) { |
|
868 | 868 | throw new EE_Error( |
869 | 869 | sprintf( |
870 | 870 | __( |
@@ -876,24 +876,24 @@ discard block |
||
876 | 876 | ) |
877 | 877 | ); |
878 | 878 | } |
879 | - if( ! in_array( $selection_and_datatype[1],$this->_valid_wpdb_data_types)){ |
|
879 | + if ( ! in_array($selection_and_datatype[1], $this->_valid_wpdb_data_types)) { |
|
880 | 880 | throw new EE_Error( |
881 | 881 | sprintf( |
882 | 882 | __( |
883 | 883 | "Datatype %s (for selection '%s' and alias '%s') is not a valid wpdb datatype (eg %%s)", |
884 | 884 | "event_espresso" |
885 | 885 | ), |
886 | - $selection_and_datatype[ 1 ], |
|
887 | - $selection_and_datatype[ 0 ], |
|
886 | + $selection_and_datatype[1], |
|
887 | + $selection_and_datatype[0], |
|
888 | 888 | $alias, |
889 | - implode( ",", $this->_valid_wpdb_data_types ) |
|
889 | + implode(",", $this->_valid_wpdb_data_types) |
|
890 | 890 | ) |
891 | 891 | ); |
892 | 892 | } |
893 | 893 | $select_sql_array[] = "{$selection_and_datatype[0]} AS $alias"; |
894 | 894 | } |
895 | - $columns_to_select_string = implode(", ",$select_sql_array); |
|
896 | - }else{ |
|
895 | + $columns_to_select_string = implode(", ", $select_sql_array); |
|
896 | + } else { |
|
897 | 897 | $columns_to_select_string = $columns_to_select; |
898 | 898 | } |
899 | 899 | return $columns_to_select_string; |
@@ -906,7 +906,7 @@ discard block |
||
906 | 906 | * Convenient wrapper for getting the primary key field's name. Eg, on Registration, this would be 'REG_ID' |
907 | 907 | * @return string |
908 | 908 | */ |
909 | - function primary_key_name(){ |
|
909 | + function primary_key_name() { |
|
910 | 910 | return $this->get_primary_key_field()->get_name(); |
911 | 911 | } |
912 | 912 | |
@@ -918,15 +918,15 @@ discard block |
||
918 | 918 | * @param mixed $id int or string, depending on the type of the model's primary key |
919 | 919 | * @return EE_Base_Class |
920 | 920 | */ |
921 | - function get_one_by_ID($id){ |
|
922 | - if( $this->get_from_entity_map( $id ) ){ |
|
923 | - return $this->get_from_entity_map( $id ); |
|
924 | - }elseif( $this->has_primary_key_field ( ) ) { |
|
921 | + function get_one_by_ID($id) { |
|
922 | + if ($this->get_from_entity_map($id)) { |
|
923 | + return $this->get_from_entity_map($id); |
|
924 | + }elseif ($this->has_primary_key_field( )) { |
|
925 | 925 | $primary_key_name = $this->get_primary_key_field()->get_name(); |
926 | 926 | return $this->get_one(array(array($primary_key_name => $id))); |
927 | - }else{ |
|
927 | + } else { |
|
928 | 928 | //no primary key, so the $id must be from the get_index_primary_key_string() |
929 | - return $this->get_one( array( $this->parse_index_primary_key_string( $id ) ) ); |
|
929 | + return $this->get_one(array($this->parse_index_primary_key_string($id))); |
|
930 | 930 | } |
931 | 931 | } |
932 | 932 | |
@@ -937,16 +937,16 @@ discard block |
||
937 | 937 | * @param array $query_params like EEM_Base's $query_params variable. |
938 | 938 | * @return EE_Base_Class | NULL |
939 | 939 | */ |
940 | - function get_one($query_params = array()){ |
|
941 | - if( ! is_array( $query_params ) ){ |
|
942 | - EE_Error::doing_it_wrong('EEM_Base::get_one', sprintf( __( '$query_params should be an array, you passed a variable of type %s', 'event_espresso' ), gettype( $query_params ) ), '4.6.0' ); |
|
940 | + function get_one($query_params = array()) { |
|
941 | + if ( ! is_array($query_params)) { |
|
942 | + EE_Error::doing_it_wrong('EEM_Base::get_one', sprintf(__('$query_params should be an array, you passed a variable of type %s', 'event_espresso'), gettype($query_params)), '4.6.0'); |
|
943 | 943 | $query_params = array(); |
944 | 944 | } |
945 | 945 | $query_params['limit'] = 1; |
946 | 946 | $items = $this->get_all($query_params); |
947 | - if(empty($items)){ |
|
947 | + if (empty($items)) { |
|
948 | 948 | return null; |
949 | - }else{ |
|
949 | + } else { |
|
950 | 950 | return array_shift($items); |
951 | 951 | } |
952 | 952 | } |
@@ -970,8 +970,8 @@ discard block |
||
970 | 970 | * |
971 | 971 | * @return EE_Base_Class[]|array |
972 | 972 | */ |
973 | - public function next_x( $current_field_value, $field_to_order_by = null, $limit = 1, $query_params = array(), $columns_to_select = null ) { |
|
974 | - return $this->_get_consecutive( $current_field_value, '>', $field_to_order_by, $limit, $query_params, $columns_to_select ); |
|
973 | + public function next_x($current_field_value, $field_to_order_by = null, $limit = 1, $query_params = array(), $columns_to_select = null) { |
|
974 | + return $this->_get_consecutive($current_field_value, '>', $field_to_order_by, $limit, $query_params, $columns_to_select); |
|
975 | 975 | } |
976 | 976 | |
977 | 977 | |
@@ -994,8 +994,8 @@ discard block |
||
994 | 994 | * |
995 | 995 | * @return EE_Base_Class[]|array |
996 | 996 | */ |
997 | - public function previous_x( $current_field_value, $field_to_order_by = null, $limit = 1, $query_params = array(), $columns_to_select = null ) { |
|
998 | - return $this->_get_consecutive( $current_field_value, '<', $field_to_order_by, $limit, $query_params, $columns_to_select ); |
|
997 | + public function previous_x($current_field_value, $field_to_order_by = null, $limit = 1, $query_params = array(), $columns_to_select = null) { |
|
998 | + return $this->_get_consecutive($current_field_value, '<', $field_to_order_by, $limit, $query_params, $columns_to_select); |
|
999 | 999 | } |
1000 | 1000 | |
1001 | 1001 | |
@@ -1017,9 +1017,9 @@ discard block |
||
1017 | 1017 | * |
1018 | 1018 | * @return EE_Base_Class|null|array() |
1019 | 1019 | */ |
1020 | - public function next( $current_field_value, $field_to_order_by = null, $query_params = array(), $columns_to_select = null ) { |
|
1021 | - $results = $this->_get_consecutive( $current_field_value, '>', $field_to_order_by, 1, $query_params, $columns_to_select ); |
|
1022 | - return empty( $results ) ? null : reset( $results ); |
|
1020 | + public function next($current_field_value, $field_to_order_by = null, $query_params = array(), $columns_to_select = null) { |
|
1021 | + $results = $this->_get_consecutive($current_field_value, '>', $field_to_order_by, 1, $query_params, $columns_to_select); |
|
1022 | + return empty($results) ? null : reset($results); |
|
1023 | 1023 | } |
1024 | 1024 | |
1025 | 1025 | |
@@ -1041,9 +1041,9 @@ discard block |
||
1041 | 1041 | * |
1042 | 1042 | * @return EE_Base_Class|null|array() |
1043 | 1043 | */ |
1044 | - public function previous( $current_field_value, $field_to_order_by = null, $query_params = array(), $columns_to_select = null ) { |
|
1045 | - $results = $this->_get_consecutive( $current_field_value, '<', $field_to_order_by, 1, $query_params, $columns_to_select ); |
|
1046 | - return empty( $results ) ? null : reset( $results ); |
|
1044 | + public function previous($current_field_value, $field_to_order_by = null, $query_params = array(), $columns_to_select = null) { |
|
1045 | + $results = $this->_get_consecutive($current_field_value, '<', $field_to_order_by, 1, $query_params, $columns_to_select); |
|
1046 | + return empty($results) ? null : reset($results); |
|
1047 | 1047 | } |
1048 | 1048 | |
1049 | 1049 | |
@@ -1069,40 +1069,40 @@ discard block |
||
1069 | 1069 | * @return EE_Base_Class[]|array |
1070 | 1070 | * @throws EE_Error |
1071 | 1071 | */ |
1072 | - protected function _get_consecutive( $current_field_value, $operand = '>', $field_to_order_by = null, $limit = 1, $query_params = array(), $columns_to_select = null ) { |
|
1072 | + protected function _get_consecutive($current_field_value, $operand = '>', $field_to_order_by = null, $limit = 1, $query_params = array(), $columns_to_select = null) { |
|
1073 | 1073 | //if $field_to_order_by is empty then let's assume we're ordering by the primary key. |
1074 | - if ( empty( $field_to_order_by ) ) { |
|
1075 | - if ( $this->has_primary_key_field() ) { |
|
1074 | + if (empty($field_to_order_by)) { |
|
1075 | + if ($this->has_primary_key_field()) { |
|
1076 | 1076 | $field_to_order_by = $this->get_primary_key_field()->get_name(); |
1077 | 1077 | } else { |
1078 | 1078 | |
1079 | - if ( WP_DEBUG ) { |
|
1080 | - throw new EE_Error( __( 'EEM_Base::_get_consecutive() has been called with no $field_to_order_by argument and there is no primary key on the field. Please provide the field you would like to use as the base for retrieving the next item(s).', 'event_espresso' ) ); |
|
1079 | + if (WP_DEBUG) { |
|
1080 | + throw new EE_Error(__('EEM_Base::_get_consecutive() has been called with no $field_to_order_by argument and there is no primary key on the field. Please provide the field you would like to use as the base for retrieving the next item(s).', 'event_espresso')); |
|
1081 | 1081 | } |
1082 | - EE_Error::add_error( __('There was an error with the query.', 'event_espresso') ); |
|
1082 | + EE_Error::add_error(__('There was an error with the query.', 'event_espresso')); |
|
1083 | 1083 | return array(); |
1084 | 1084 | } |
1085 | 1085 | } |
1086 | 1086 | |
1087 | - if( ! is_array( $query_params ) ){ |
|
1088 | - EE_Error::doing_it_wrong('EEM_Base::_get_consecutive', sprintf( __( '$query_params should be an array, you passed a variable of type %s', 'event_espresso' ), gettype( $query_params ) ), '4.6.0' ); |
|
1087 | + if ( ! is_array($query_params)) { |
|
1088 | + EE_Error::doing_it_wrong('EEM_Base::_get_consecutive', sprintf(__('$query_params should be an array, you passed a variable of type %s', 'event_espresso'), gettype($query_params)), '4.6.0'); |
|
1089 | 1089 | $query_params = array(); |
1090 | 1090 | } |
1091 | 1091 | |
1092 | 1092 | //let's add the where query param for consecutive look up. |
1093 | - $query_params[0][ $field_to_order_by ] = array( $operand, $current_field_value ); |
|
1093 | + $query_params[0][$field_to_order_by] = array($operand, $current_field_value); |
|
1094 | 1094 | $query_params['limit'] = $limit; |
1095 | 1095 | |
1096 | 1096 | //set direction |
1097 | - $incoming_orderby = isset( $query_params['order_by'] ) ? $query_params['order_by'] : array(); |
|
1098 | - $query_params['order_by'] = $operand == '>' ? array( $field_to_order_by => 'ASC' ) + $incoming_orderby : array( $field_to_order_by => 'DESC') + $incoming_orderby; |
|
1097 | + $incoming_orderby = isset($query_params['order_by']) ? $query_params['order_by'] : array(); |
|
1098 | + $query_params['order_by'] = $operand == '>' ? array($field_to_order_by => 'ASC') + $incoming_orderby : array($field_to_order_by => 'DESC') + $incoming_orderby; |
|
1099 | 1099 | |
1100 | 1100 | //if $columns_to_select is empty then that means we're returning EE_Base_Class objects |
1101 | - if ( empty( $columns_to_select ) ) { |
|
1102 | - return $this->get_all( $query_params ); |
|
1101 | + if (empty($columns_to_select)) { |
|
1102 | + return $this->get_all($query_params); |
|
1103 | 1103 | } else { |
1104 | 1104 | //getting just the fields |
1105 | - return $this->_get_all_wpdb_results( $query_params, ARRAY_A, $columns_to_select ); |
|
1105 | + return $this->_get_all_wpdb_results($query_params, ARRAY_A, $columns_to_select); |
|
1106 | 1106 | } |
1107 | 1107 | } |
1108 | 1108 | |
@@ -1113,18 +1113,18 @@ discard block |
||
1113 | 1113 | * This sets the _timezone property after model object has been instantiated. |
1114 | 1114 | * @param null | string $timezone valid PHP DateTimeZone timezone string |
1115 | 1115 | */ |
1116 | - public function set_timezone( $timezone ) { |
|
1117 | - if ( $timezone !== null ) { |
|
1116 | + public function set_timezone($timezone) { |
|
1117 | + if ($timezone !== null) { |
|
1118 | 1118 | $this->_timezone = $timezone; |
1119 | 1119 | } |
1120 | 1120 | //note we need to loop through relations and set the timezone on those objects as well. |
1121 | - foreach ( $this->_model_relations as $relation ) { |
|
1122 | - $relation->set_timezone( $timezone ); |
|
1121 | + foreach ($this->_model_relations as $relation) { |
|
1122 | + $relation->set_timezone($timezone); |
|
1123 | 1123 | } |
1124 | 1124 | //and finally we do the same for any datetime fields |
1125 | - foreach ( $this->_fields as $field ) { |
|
1126 | - if ( $field instanceof EE_Datetime_Field ) { |
|
1127 | - $field->set_timezone( $timezone ); |
|
1125 | + foreach ($this->_fields as $field) { |
|
1126 | + if ($field instanceof EE_Datetime_Field) { |
|
1127 | + $field->set_timezone($timezone); |
|
1128 | 1128 | } |
1129 | 1129 | } |
1130 | 1130 | } |
@@ -1139,9 +1139,9 @@ discard block |
||
1139 | 1139 | */ |
1140 | 1140 | public function get_timezone() { |
1141 | 1141 | //first validate if timezone is set. If not, then let's set it be whatever is set on the model fields. |
1142 | - if ( empty( $this->_timezone ) ) { |
|
1143 | - foreach( $this->_fields as $field ) { |
|
1144 | - if ( $field instanceof EE_Datetime_Field ) { |
|
1142 | + if (empty($this->_timezone)) { |
|
1143 | + foreach ($this->_fields as $field) { |
|
1144 | + if ($field instanceof EE_Datetime_Field) { |
|
1145 | 1145 | $this->set_timezone($field->get_timezone()); |
1146 | 1146 | break; |
1147 | 1147 | } |
@@ -1149,9 +1149,9 @@ discard block |
||
1149 | 1149 | } |
1150 | 1150 | |
1151 | 1151 | //if timezone STILL empty then return the default timezone for the site. |
1152 | - if ( empty( $this->_timezone ) ) { |
|
1153 | - EE_Registry::instance()->load_helper( 'DTT_Helper' ); |
|
1154 | - $this->set_timezone( EEH_DTT_Helper::get_timezone() ); |
|
1152 | + if (empty($this->_timezone)) { |
|
1153 | + EE_Registry::instance()->load_helper('DTT_Helper'); |
|
1154 | + $this->set_timezone(EEH_DTT_Helper::get_timezone()); |
|
1155 | 1155 | } |
1156 | 1156 | return $this->_timezone; |
1157 | 1157 | } |
@@ -1169,19 +1169,19 @@ discard block |
||
1169 | 1169 | * |
1170 | 1170 | * @return array formats in an array with the date format first, and the time format last. |
1171 | 1171 | */ |
1172 | - public function get_formats_for( $field_name, $pretty = false ) { |
|
1173 | - $field_settings = $this->field_settings_for( $field_name ); |
|
1172 | + public function get_formats_for($field_name, $pretty = false) { |
|
1173 | + $field_settings = $this->field_settings_for($field_name); |
|
1174 | 1174 | |
1175 | 1175 | //if not a valid EE_Datetime_Field then throw error |
1176 | - if ( ! $field_settings instanceof EE_Datetime_Field ) { |
|
1177 | - throw new EE_Error( sprintf( __('The field sent into EEM_Base::get_formats_for (%s) is not registered as a EE_Datetime_Field. Please check the spelling and make sure you are submitting the right field name to retrieve date_formats for.', 'event_espresso' ), $field_name ) ); |
|
1176 | + if ( ! $field_settings instanceof EE_Datetime_Field) { |
|
1177 | + throw new EE_Error(sprintf(__('The field sent into EEM_Base::get_formats_for (%s) is not registered as a EE_Datetime_Field. Please check the spelling and make sure you are submitting the right field name to retrieve date_formats for.', 'event_espresso'), $field_name)); |
|
1178 | 1178 | } |
1179 | 1179 | |
1180 | 1180 | //while we are here, let's make sure the timezone internally in EEM_Base matches what is stored on |
1181 | 1181 | //the field. |
1182 | 1182 | $this->_timezone = $field_settings->get_timezone(); |
1183 | 1183 | |
1184 | - return array( $field_settings->get_date_format( $pretty ), $field_settings->get_time_format( $pretty ) ); |
|
1184 | + return array($field_settings->get_date_format($pretty), $field_settings->get_time_format($pretty)); |
|
1185 | 1185 | } |
1186 | 1186 | |
1187 | 1187 | |
@@ -1205,25 +1205,25 @@ discard block |
||
1205 | 1205 | * @return int|string If the given field_name is not of the EE_Datetime_Field type, then an EE_Error |
1206 | 1206 | * exception is triggered. |
1207 | 1207 | */ |
1208 | - public function current_time_for_query( $field_name, $timestamp = false, $what = 'both' ) { |
|
1209 | - $formats = $this->get_formats_for( $field_name ); |
|
1208 | + public function current_time_for_query($field_name, $timestamp = false, $what = 'both') { |
|
1209 | + $formats = $this->get_formats_for($field_name); |
|
1210 | 1210 | |
1211 | - $DateTime = new DateTime( "now", new DateTimeZone( $this->_timezone ) ); |
|
1211 | + $DateTime = new DateTime("now", new DateTimeZone($this->_timezone)); |
|
1212 | 1212 | |
1213 | - if ( $timestamp ) { |
|
1214 | - return $DateTime->format( 'U' ); |
|
1213 | + if ($timestamp) { |
|
1214 | + return $DateTime->format('U'); |
|
1215 | 1215 | } |
1216 | 1216 | |
1217 | 1217 | //not returning timestamp, so return formatted string in timezone. |
1218 | - switch( $what ) { |
|
1218 | + switch ($what) { |
|
1219 | 1219 | case 'time' : |
1220 | - return $DateTime->format( $formats[1] ); |
|
1220 | + return $DateTime->format($formats[1]); |
|
1221 | 1221 | break; |
1222 | 1222 | case 'date' : |
1223 | - return $DateTime->format( $formats[0] ); |
|
1223 | + return $DateTime->format($formats[0]); |
|
1224 | 1224 | break; |
1225 | 1225 | default : |
1226 | - return $DateTime->format( implode( ' ', $formats ) ); |
|
1226 | + return $DateTime->format(implode(' ', $formats)); |
|
1227 | 1227 | break; |
1228 | 1228 | } |
1229 | 1229 | } |
@@ -1247,18 +1247,18 @@ discard block |
||
1247 | 1247 | * 'U', this is ignored. |
1248 | 1248 | * @return DateTime |
1249 | 1249 | */ |
1250 | - public function convert_datetime_for_query( $field_name, $timestring, $incoming_format, $timezone = '' ) { |
|
1250 | + public function convert_datetime_for_query($field_name, $timestring, $incoming_format, $timezone = '') { |
|
1251 | 1251 | |
1252 | 1252 | //just using this to ensure the timezone is set correctly internally |
1253 | - $this->get_formats_for( $field_name ); |
|
1253 | + $this->get_formats_for($field_name); |
|
1254 | 1254 | |
1255 | 1255 | //load EEH_DTT_Helper |
1256 | - EE_Registry::instance()->load_helper( 'DTT_Helper' ); |
|
1257 | - $set_timezone = empty( $timezone ) ? EEH_DTT_Helper::get_timezone() : $timezone; |
|
1256 | + EE_Registry::instance()->load_helper('DTT_Helper'); |
|
1257 | + $set_timezone = empty($timezone) ? EEH_DTT_Helper::get_timezone() : $timezone; |
|
1258 | 1258 | |
1259 | - $incomingDateTime = date_create_from_format( $incoming_format, $timestring, new DateTimeZone( $set_timezone ) ); |
|
1259 | + $incomingDateTime = date_create_from_format($incoming_format, $timestring, new DateTimeZone($set_timezone)); |
|
1260 | 1260 | |
1261 | - return $incomingDateTime->setTimeZone( new DateTimeZone( $this->_timezone ) ); |
|
1261 | + return $incomingDateTime->setTimeZone(new DateTimeZone($this->_timezone)); |
|
1262 | 1262 | } |
1263 | 1263 | |
1264 | 1264 | |
@@ -1268,7 +1268,7 @@ discard block |
||
1268 | 1268 | * Gets all the tables comprising this model. Array keys are the table aliases, and values are EE_Table objects |
1269 | 1269 | * @return EE_Table_Base[] |
1270 | 1270 | */ |
1271 | - function get_tables(){ |
|
1271 | + function get_tables() { |
|
1272 | 1272 | return $this->_tables; |
1273 | 1273 | } |
1274 | 1274 | |
@@ -1302,9 +1302,9 @@ discard block |
||
1302 | 1302 | * be aware that model objects being used could get out-of-sync with the database |
1303 | 1303 | * @return int how many rows got updated or FALSE if something went wrong with the query (wp returns FALSE or num rows affected which *could* include 0 which DOES NOT mean the query was bad) |
1304 | 1304 | */ |
1305 | - function update($fields_n_values, $query_params, $keep_model_objs_in_sync = TRUE){ |
|
1306 | - if( ! is_array( $query_params ) ){ |
|
1307 | - EE_Error::doing_it_wrong('EEM_Base::update', sprintf( __( '$query_params should be an array, you passed a variable of type %s', 'event_espresso' ), gettype( $query_params ) ), '4.6.0' ); |
|
1305 | + function update($fields_n_values, $query_params, $keep_model_objs_in_sync = TRUE) { |
|
1306 | + if ( ! is_array($query_params)) { |
|
1307 | + EE_Error::doing_it_wrong('EEM_Base::update', sprintf(__('$query_params should be an array, you passed a variable of type %s', 'event_espresso'), gettype($query_params)), '4.6.0'); |
|
1308 | 1308 | $query_params = array(); |
1309 | 1309 | } |
1310 | 1310 | /** |
@@ -1314,7 +1314,7 @@ discard block |
||
1314 | 1314 | * @param array $fields_n_values the updated fields and their new values |
1315 | 1315 | * @param array $query_params @see EEM_Base::get_all() |
1316 | 1316 | */ |
1317 | - do_action( 'AHEE__EEM_Base__update__begin',$this, $fields_n_values, $query_params ); |
|
1317 | + do_action('AHEE__EEM_Base__update__begin', $this, $fields_n_values, $query_params); |
|
1318 | 1318 | /** |
1319 | 1319 | * Filters the fields about to be updated given the query parameters. You can provide the |
1320 | 1320 | * $query_params to $this->get_all() to find exactly which records will be updated |
@@ -1322,10 +1322,10 @@ discard block |
||
1322 | 1322 | * @param EEM_Base $model the model being queried |
1323 | 1323 | * @param array $query_params see EEM_Base::get_all() |
1324 | 1324 | */ |
1325 | - $fields_n_values = apply_filters( 'FHEE__EEM_Base__update__fields_n_values', $fields_n_values, $this, $query_params ); |
|
1325 | + $fields_n_values = apply_filters('FHEE__EEM_Base__update__fields_n_values', $fields_n_values, $this, $query_params); |
|
1326 | 1326 | //need to verify that, for any entry we want to update, there are entries in each secondary table. |
1327 | 1327 | //to do that, for each table, verify that it's PK isn't null. |
1328 | - $tables= $this->get_tables(); |
|
1328 | + $tables = $this->get_tables(); |
|
1329 | 1329 | |
1330 | 1330 | //and if the other tables don't have a row for each table-to-be-updated, we'll insert one with whatever values available in the current update query |
1331 | 1331 | //NOTE: we should make this code more efficient by NOT querying twice |
@@ -1335,29 +1335,29 @@ discard block |
||
1335 | 1335 | //we want to make sure the default_where strategy is ignored |
1336 | 1336 | $this->_ignore_where_strategy = TRUE; |
1337 | 1337 | $wpdb_select_results = $this->_get_all_wpdb_results($query_params); |
1338 | - foreach( $wpdb_select_results as $wpdb_result ){ |
|
1338 | + foreach ($wpdb_select_results as $wpdb_result) { |
|
1339 | 1339 | // type cast stdClass as array |
1340 | - $wpdb_result = (array)$wpdb_result; |
|
1340 | + $wpdb_result = (array) $wpdb_result; |
|
1341 | 1341 | //get the model object's PK, as we'll want this if we need to insert a row into secondary tables |
1342 | - if( $this->has_primary_key_field() ){ |
|
1343 | - $main_table_pk_value = $wpdb_result[ $this->get_primary_key_field()->get_qualified_column() ]; |
|
1344 | - }else{ |
|
1342 | + if ($this->has_primary_key_field()) { |
|
1343 | + $main_table_pk_value = $wpdb_result[$this->get_primary_key_field()->get_qualified_column()]; |
|
1344 | + } else { |
|
1345 | 1345 | //if there's no primary key, we basically can't support having a 2nd table on the model (we could but it would be lots of work) |
1346 | 1346 | $main_table_pk_value = null; |
1347 | 1347 | } |
1348 | 1348 | //if there are more than 1 tables, we'll want to verify that each table for this model has an entry in the other tables |
1349 | 1349 | //and if the other tables don't have a row for each table-to-be-updated, we'll insert one with whatever values available in the current update query |
1350 | - if(count($tables) > 1){ |
|
1350 | + if (count($tables) > 1) { |
|
1351 | 1351 | //foreach matching row in the DB, ensure that each table's PK isn't null. If so, there must not be an entry |
1352 | 1352 | //in that table, and so we'll want to insert one |
1353 | - foreach($tables as $table_obj){ |
|
1353 | + foreach ($tables as $table_obj) { |
|
1354 | 1354 | $this_table_pk_column = $table_obj->get_fully_qualified_pk_column(); |
1355 | 1355 | //if there is no private key for this table on the results, it means there's no entry |
1356 | 1356 | //in this table, right? so insert a row in the current table, using any fields available |
1357 | - if( ! ( array_key_exists( $this_table_pk_column, $wpdb_result) && $wpdb_result[ $this_table_pk_column ] )){ |
|
1357 | + if ( ! (array_key_exists($this_table_pk_column, $wpdb_result) && $wpdb_result[$this_table_pk_column])) { |
|
1358 | 1358 | $success = $this->_insert_into_specific_table($table_obj, $fields_n_values, $main_table_pk_value); |
1359 | 1359 | //if we died here, report the error |
1360 | - if( ! $success ) { |
|
1360 | + if ( ! $success) { |
|
1361 | 1361 | return false; |
1362 | 1362 | } |
1363 | 1363 | } |
@@ -1377,44 +1377,44 @@ discard block |
||
1377 | 1377 | //if this wasn't called from a model object (to update itself) |
1378 | 1378 | //then we want to make sure we keep all the existing |
1379 | 1379 | //model objects in sync with the db |
1380 | - if( $keep_model_objs_in_sync && ! $this->_values_already_prepared_by_model_object ){ |
|
1381 | - if( $this->has_primary_key_field() ){ |
|
1382 | - $model_objs_affected_ids = $this->get_col( $query_params ); |
|
1383 | - }else{ |
|
1380 | + if ($keep_model_objs_in_sync && ! $this->_values_already_prepared_by_model_object) { |
|
1381 | + if ($this->has_primary_key_field()) { |
|
1382 | + $model_objs_affected_ids = $this->get_col($query_params); |
|
1383 | + } else { |
|
1384 | 1384 | //we need to select a bunch of columns and then combine them into the the "index primary key string"s |
1385 | - $models_affected_key_columns = $this->_get_all_wpdb_results($query_params, ARRAY_A ); |
|
1385 | + $models_affected_key_columns = $this->_get_all_wpdb_results($query_params, ARRAY_A); |
|
1386 | 1386 | $model_objs_affected_ids = array(); |
1387 | - foreach( $models_affected_key_columns as $row ){ |
|
1388 | - $combined_index_key = $this->get_index_primary_key_string( $row ); |
|
1389 | - $model_objs_affected_ids[ $combined_index_key ] = $combined_index_key; |
|
1387 | + foreach ($models_affected_key_columns as $row) { |
|
1388 | + $combined_index_key = $this->get_index_primary_key_string($row); |
|
1389 | + $model_objs_affected_ids[$combined_index_key] = $combined_index_key; |
|
1390 | 1390 | } |
1391 | 1391 | |
1392 | 1392 | } |
1393 | 1393 | |
1394 | - if( ! $model_objs_affected_ids ){ |
|
1394 | + if ( ! $model_objs_affected_ids) { |
|
1395 | 1395 | //wait wait wait- if nothing was affected let's stop here |
1396 | 1396 | return 0; |
1397 | 1397 | } |
1398 | - foreach( $model_objs_affected_ids as $id ){ |
|
1399 | - $model_obj_in_entity_map = $this->get_from_entity_map( $id ); |
|
1400 | - if( $model_obj_in_entity_map ){ |
|
1401 | - foreach( $fields_n_values as $field => $new_value ){ |
|
1402 | - $model_obj_in_entity_map->set( $field, $new_value ); |
|
1398 | + foreach ($model_objs_affected_ids as $id) { |
|
1399 | + $model_obj_in_entity_map = $this->get_from_entity_map($id); |
|
1400 | + if ($model_obj_in_entity_map) { |
|
1401 | + foreach ($fields_n_values as $field => $new_value) { |
|
1402 | + $model_obj_in_entity_map->set($field, $new_value); |
|
1403 | 1403 | } |
1404 | 1404 | } |
1405 | 1405 | } |
1406 | 1406 | //if there is a primary key on this model, we can now do a slight optimization |
1407 | - if( $this->has_primary_key_field() ){ |
|
1407 | + if ($this->has_primary_key_field()) { |
|
1408 | 1408 | //we already know what we want to update. So let's make the query simpler so it's a little more efficient |
1409 | 1409 | $query_params = array( |
1410 | - array( $this->primary_key_name() => array( 'IN', $model_objs_affected_ids ) ), |
|
1411 | - 'limit' => count( $model_objs_affected_ids ), 'default_where_conditions' => 'none' ); |
|
1410 | + array($this->primary_key_name() => array('IN', $model_objs_affected_ids)), |
|
1411 | + 'limit' => count($model_objs_affected_ids), 'default_where_conditions' => 'none' ); |
|
1412 | 1412 | } |
1413 | 1413 | } |
1414 | 1414 | |
1415 | - $model_query_info = $this->_create_model_query_info_carrier( $query_params ); |
|
1416 | - $SQL = "UPDATE ".$model_query_info->get_full_join_sql()." SET ".$this->_construct_update_sql($fields_n_values).$model_query_info->get_where_sql();//note: doesn't use _construct_2nd_half_of_select_query() because doesn't accept LIMIT, ORDER BY, etc. |
|
1417 | - $rows_affected = $this->_do_wpdb_query('query', array( $SQL ) ); |
|
1415 | + $model_query_info = $this->_create_model_query_info_carrier($query_params); |
|
1416 | + $SQL = "UPDATE ".$model_query_info->get_full_join_sql()." SET ".$this->_construct_update_sql($fields_n_values).$model_query_info->get_where_sql(); //note: doesn't use _construct_2nd_half_of_select_query() because doesn't accept LIMIT, ORDER BY, etc. |
|
1417 | + $rows_affected = $this->_do_wpdb_query('query', array($SQL)); |
|
1418 | 1418 | /** |
1419 | 1419 | * Action called after a model update call has been made. |
1420 | 1420 | * |
@@ -1423,8 +1423,8 @@ discard block |
||
1423 | 1423 | * @param array $query_params @see EEM_Base::get_all() |
1424 | 1424 | * @param int $rows_affected |
1425 | 1425 | */ |
1426 | - do_action( 'AHEE__EEM_Base__update__end',$this, $fields_n_values, $query_params, $rows_affected ); |
|
1427 | - return $rows_affected;//how many supposedly got updated |
|
1426 | + do_action('AHEE__EEM_Base__update__end', $this, $fields_n_values, $query_params, $rows_affected); |
|
1427 | + return $rows_affected; //how many supposedly got updated |
|
1428 | 1428 | } |
1429 | 1429 | |
1430 | 1430 | /** |
@@ -1436,22 +1436,22 @@ discard block |
||
1436 | 1436 | * @param string $field_to_select |
1437 | 1437 | * @return array just like $wpdb->get_col() |
1438 | 1438 | */ |
1439 | - public function get_col( $query_params = array(), $field_to_select = NULL ){ |
|
1439 | + public function get_col($query_params = array(), $field_to_select = NULL) { |
|
1440 | 1440 | |
1441 | - if( $field_to_select ){ |
|
1442 | - $field = $this->field_settings_for( $field_to_select ); |
|
1443 | - }elseif( $this->has_primary_key_field ( ) ){ |
|
1441 | + if ($field_to_select) { |
|
1442 | + $field = $this->field_settings_for($field_to_select); |
|
1443 | + }elseif ($this->has_primary_key_field( )) { |
|
1444 | 1444 | $field = $this->get_primary_key_field(); |
1445 | - }else{ |
|
1445 | + } else { |
|
1446 | 1446 | //no primary key, just grab the first column |
1447 | - $field = reset( $this->field_settings()); |
|
1447 | + $field = reset($this->field_settings()); |
|
1448 | 1448 | } |
1449 | 1449 | |
1450 | 1450 | |
1451 | 1451 | $model_query_info = $this->_create_model_query_info_carrier($query_params); |
1452 | 1452 | $select_expressions = $field->get_qualified_column(); |
1453 | - $SQL ="SELECT $select_expressions ".$this->_construct_2nd_half_of_select_query($model_query_info); |
|
1454 | - $results = $this->_do_wpdb_query('get_col', array( $SQL ) ); |
|
1453 | + $SQL = "SELECT $select_expressions ".$this->_construct_2nd_half_of_select_query($model_query_info); |
|
1454 | + $results = $this->_do_wpdb_query('get_col', array($SQL)); |
|
1455 | 1455 | return $results; |
1456 | 1456 | } |
1457 | 1457 | |
@@ -1461,12 +1461,12 @@ discard block |
||
1461 | 1461 | * @param string $field_to_select @see EEM_Base::get_col() |
1462 | 1462 | * @return string |
1463 | 1463 | */ |
1464 | - public function get_var( $query_params = array(), $field_to_select = NULL ) { |
|
1465 | - $query_params[ 'limit' ] = 1; |
|
1466 | - $col = $this->get_col( $query_params, $field_to_select ); |
|
1467 | - if( ! empty( $col ) ) { |
|
1468 | - return reset( $col ); |
|
1469 | - }else{ |
|
1464 | + public function get_var($query_params = array(), $field_to_select = NULL) { |
|
1465 | + $query_params['limit'] = 1; |
|
1466 | + $col = $this->get_col($query_params, $field_to_select); |
|
1467 | + if ( ! empty($col)) { |
|
1468 | + return reset($col); |
|
1469 | + } else { |
|
1470 | 1470 | return NULL; |
1471 | 1471 | } |
1472 | 1472 | } |
@@ -1480,19 +1480,19 @@ discard block |
||
1480 | 1480 | * @param array $fields_n_values array keys are field names on this model, and values are what those fields should be updated to in the DB |
1481 | 1481 | * @return string of SQL |
1482 | 1482 | */ |
1483 | - function _construct_update_sql($fields_n_values){ |
|
1483 | + function _construct_update_sql($fields_n_values) { |
|
1484 | 1484 | /** @type WPDB $wpdb */ |
1485 | 1485 | global $wpdb; |
1486 | 1486 | $cols_n_values = array(); |
1487 | - foreach($fields_n_values as $field_name => $value){ |
|
1487 | + foreach ($fields_n_values as $field_name => $value) { |
|
1488 | 1488 | $field_obj = $this->field_settings_for($field_name); |
1489 | 1489 | //if the value is NULL, we want to assign the value to that. |
1490 | 1490 | //wpdb->prepare doesn't really handle that properly |
1491 | - $prepared_value = $this->_prepare_value_or_use_default( $field_obj, $fields_n_values ); |
|
1492 | - $value_sql = $prepared_value===NULL ? 'NULL' : $wpdb->prepare( $field_obj->get_wpdb_data_type(), $prepared_value ); |
|
1491 | + $prepared_value = $this->_prepare_value_or_use_default($field_obj, $fields_n_values); |
|
1492 | + $value_sql = $prepared_value === NULL ? 'NULL' : $wpdb->prepare($field_obj->get_wpdb_data_type(), $prepared_value); |
|
1493 | 1493 | $cols_n_values[] = $field_obj->get_qualified_column()."=".$value_sql; |
1494 | 1494 | } |
1495 | - return implode(",",$cols_n_values); |
|
1495 | + return implode(",", $cols_n_values); |
|
1496 | 1496 | |
1497 | 1497 | } |
1498 | 1498 | |
@@ -1504,11 +1504,11 @@ discard block |
||
1504 | 1504 | * @param mixed $id |
1505 | 1505 | * @return boolean whether the row got deleted or not |
1506 | 1506 | */ |
1507 | - public function delete_by_ID( $id ){ |
|
1508 | - return $this->delete( array( |
|
1509 | - array( $this->get_primary_key_field()->get_name() => $id ), |
|
1507 | + public function delete_by_ID($id) { |
|
1508 | + return $this->delete(array( |
|
1509 | + array($this->get_primary_key_field()->get_name() => $id), |
|
1510 | 1510 | 'limit' => 1 |
1511 | - ) ); |
|
1511 | + )); |
|
1512 | 1512 | } |
1513 | 1513 | |
1514 | 1514 | |
@@ -1523,7 +1523,7 @@ discard block |
||
1523 | 1523 | * which may depend on it. Its generally advisable to always leave this as TRUE, otherwise you could easily corrupt your DB |
1524 | 1524 | * @return int how many rows got deleted |
1525 | 1525 | */ |
1526 | - function delete($query_params,$allow_blocking = true){ |
|
1526 | + function delete($query_params, $allow_blocking = true) { |
|
1527 | 1527 | /** |
1528 | 1528 | * Action called just before performing a real deletion query. You can use the |
1529 | 1529 | * model and its $query_params to find exactly which items will be deleted |
@@ -1532,34 +1532,34 @@ discard block |
||
1532 | 1532 | * @param boolean $allow_blocking whether or not to allow related model objects |
1533 | 1533 | * to block (prevent) this deletion |
1534 | 1534 | */ |
1535 | - do_action( 'AHEE__EEM_Base__delete__begin', $this, $query_params, $allow_blocking ); |
|
1535 | + do_action('AHEE__EEM_Base__delete__begin', $this, $query_params, $allow_blocking); |
|
1536 | 1536 | //some MySQL databases may be running safe mode, which may restrict |
1537 | 1537 | //deletion if there is no KEY column used in the WHERE statement of a deletion. |
1538 | 1538 | //to get around this, we first do a SELECT, get all the IDs, and then run another query |
1539 | 1539 | //to delete them |
1540 | 1540 | $items_for_deletion = $this->_get_all_wpdb_results($query_params); |
1541 | - $deletion_where = $this->_setup_ids_for_delete( $items_for_deletion, $allow_blocking); |
|
1542 | - if($deletion_where){ |
|
1541 | + $deletion_where = $this->_setup_ids_for_delete($items_for_deletion, $allow_blocking); |
|
1542 | + if ($deletion_where) { |
|
1543 | 1543 | //echo "objects for deletion:";var_dump($objects_for_deletion); |
1544 | 1544 | $model_query_info = $this->_create_model_query_info_carrier($query_params); |
1545 | 1545 | $table_aliases = array(); |
1546 | - foreach(array_keys($this->_tables) as $table_alias){ |
|
1546 | + foreach (array_keys($this->_tables) as $table_alias) { |
|
1547 | 1547 | $table_aliases[] = $table_alias; |
1548 | 1548 | } |
1549 | - $SQL = "DELETE ".implode(", ",$table_aliases)." FROM ".$model_query_info->get_full_join_sql()." WHERE ".$deletion_where; |
|
1549 | + $SQL = "DELETE ".implode(", ", $table_aliases)." FROM ".$model_query_info->get_full_join_sql()." WHERE ".$deletion_where; |
|
1550 | 1550 | |
1551 | 1551 | // /echo "delete sql:$SQL"; |
1552 | - $rows_deleted = $this->_do_wpdb_query( 'query', array( $SQL ) ); |
|
1553 | - }else{ |
|
1552 | + $rows_deleted = $this->_do_wpdb_query('query', array($SQL)); |
|
1553 | + } else { |
|
1554 | 1554 | $rows_deleted = 0; |
1555 | 1555 | } |
1556 | 1556 | |
1557 | 1557 | //and lastly make sure those items are removed from the entity map; if they could be put into it at all |
1558 | - if( $this->has_primary_key_field() ){ |
|
1559 | - foreach($items_for_deletion as $item_for_deletion_row ){ |
|
1560 | - $pk_value = $item_for_deletion_row[ $this->get_primary_key_field()->get_qualified_column() ]; |
|
1561 | - if( isset( $this->_entity_map[ $pk_value ] ) ){ |
|
1562 | - unset( $this->_entity_map[ $pk_value ] ); |
|
1558 | + if ($this->has_primary_key_field()) { |
|
1559 | + foreach ($items_for_deletion as $item_for_deletion_row) { |
|
1560 | + $pk_value = $item_for_deletion_row[$this->get_primary_key_field()->get_qualified_column()]; |
|
1561 | + if (isset($this->_entity_map[$pk_value])) { |
|
1562 | + unset($this->_entity_map[$pk_value]); |
|
1563 | 1563 | } |
1564 | 1564 | } |
1565 | 1565 | } |
@@ -1571,8 +1571,8 @@ discard block |
||
1571 | 1571 | * @param array $query_params @see EEM_Base::get_all() |
1572 | 1572 | * @param int $rows_deleted |
1573 | 1573 | */ |
1574 | - do_action( 'AHEE__EEM_Base__delete__end', $this, $query_params, $rows_deleted ); |
|
1575 | - return $rows_deleted;//how many supposedly got deleted |
|
1574 | + do_action('AHEE__EEM_Base__delete__end', $this, $query_params, $rows_deleted); |
|
1575 | + return $rows_deleted; //how many supposedly got deleted |
|
1576 | 1576 | } |
1577 | 1577 | |
1578 | 1578 | |
@@ -1588,28 +1588,28 @@ discard block |
||
1588 | 1588 | * blocking its deletion before removing the relation between A and B |
1589 | 1589 | * @return boolean |
1590 | 1590 | */ |
1591 | - public function delete_is_blocked_by_related_models($this_model_obj_or_id, $ignore_this_model_obj = null){ |
|
1591 | + public function delete_is_blocked_by_related_models($this_model_obj_or_id, $ignore_this_model_obj = null) { |
|
1592 | 1592 | //first, if $ignore_this_model_obj was supplied, get its model |
1593 | - if($ignore_this_model_obj && $ignore_this_model_obj instanceof EE_Base_Class){ |
|
1593 | + if ($ignore_this_model_obj && $ignore_this_model_obj instanceof EE_Base_Class) { |
|
1594 | 1594 | $ignored_model = $ignore_this_model_obj->get_model(); |
1595 | - }else{ |
|
1595 | + } else { |
|
1596 | 1596 | $ignored_model = null; |
1597 | 1597 | } |
1598 | 1598 | //now check all the relations of $this_model_obj_or_id and see if there |
1599 | 1599 | //are any related model objects blocking it? |
1600 | 1600 | $is_blocked = false; |
1601 | - foreach($this->_model_relations as $relation_name => $relation_obj){ |
|
1602 | - if( $relation_obj->block_delete_if_related_models_exist()){ |
|
1601 | + foreach ($this->_model_relations as $relation_name => $relation_obj) { |
|
1602 | + if ($relation_obj->block_delete_if_related_models_exist()) { |
|
1603 | 1603 | //if $ignore_this_model_obj was supplied, then for the query |
1604 | 1604 | //on that model needs to be told to ignore $ignore_this_model_obj |
1605 | - if($ignored_model && $relation_name == $ignored_model->get_this_model_name()){ |
|
1606 | - $related_model_objects = $relation_obj->get_all_related($this_model_obj_or_id,array( |
|
1607 | - array($ignored_model->get_primary_key_field()->get_name() => array('!=',$ignore_this_model_obj->ID())))); |
|
1608 | - }else{ |
|
1605 | + if ($ignored_model && $relation_name == $ignored_model->get_this_model_name()) { |
|
1606 | + $related_model_objects = $relation_obj->get_all_related($this_model_obj_or_id, array( |
|
1607 | + array($ignored_model->get_primary_key_field()->get_name() => array('!=', $ignore_this_model_obj->ID())))); |
|
1608 | + } else { |
|
1609 | 1609 | $related_model_objects = $relation_obj->get_all_related($this_model_obj_or_id); |
1610 | 1610 | } |
1611 | 1611 | |
1612 | - if($related_model_objects){ |
|
1612 | + if ($related_model_objects) { |
|
1613 | 1613 | EE_Error::add_error($relation_obj->get_deletion_error_message(), __FILE__, __FUNCTION__, __LINE__); |
1614 | 1614 | $is_blocked = true; |
1615 | 1615 | } |
@@ -1629,65 +1629,65 @@ discard block |
||
1629 | 1629 | * @throws EE_Error |
1630 | 1630 | * @return string everything that comes after the WHERE statement. |
1631 | 1631 | */ |
1632 | - protected function _setup_ids_for_delete( $objects_for_deletion, $allow_blocking = true) { |
|
1633 | - if($this->has_primary_key_field()){ |
|
1632 | + protected function _setup_ids_for_delete($objects_for_deletion, $allow_blocking = true) { |
|
1633 | + if ($this->has_primary_key_field()) { |
|
1634 | 1634 | $primary_table = $this->_get_main_table(); |
1635 | 1635 | $other_tables = $this->_get_other_tables(); |
1636 | 1636 | $deletes = $query = array(); |
1637 | - foreach ( $objects_for_deletion as $delete_object ) { |
|
1637 | + foreach ($objects_for_deletion as $delete_object) { |
|
1638 | 1638 | //before we mark this object for deletion, |
1639 | 1639 | //make sure there's no related objects blocking its deletion (if we're checking) |
1640 | - if( $allow_blocking && $this->delete_is_blocked_by_related_models($delete_object[$primary_table->get_fully_qualified_pk_column()]) ){ |
|
1640 | + if ($allow_blocking && $this->delete_is_blocked_by_related_models($delete_object[$primary_table->get_fully_qualified_pk_column()])) { |
|
1641 | 1641 | continue; |
1642 | 1642 | } |
1643 | 1643 | |
1644 | 1644 | //primary table deletes |
1645 | - if ( isset( $delete_object[$primary_table->get_fully_qualified_pk_column()] ) ) |
|
1645 | + if (isset($delete_object[$primary_table->get_fully_qualified_pk_column()])) |
|
1646 | 1646 | $deletes[$primary_table->get_fully_qualified_pk_column()][] = $delete_object[$primary_table->get_fully_qualified_pk_column()]; |
1647 | 1647 | |
1648 | 1648 | //other tables |
1649 | - if ( !empty( $other_tables ) ) { |
|
1650 | - foreach ( $other_tables as $ot ) { |
|
1649 | + if ( ! empty($other_tables)) { |
|
1650 | + foreach ($other_tables as $ot) { |
|
1651 | 1651 | |
1652 | 1652 | //first check if we've got the foreign key column here. |
1653 | - if ( isset( $delete_object[$ot->get_fully_qualified_fk_column()] ) ) |
|
1653 | + if (isset($delete_object[$ot->get_fully_qualified_fk_column()])) |
|
1654 | 1654 | $deletes[$ot->get_fully_qualified_pk_column()][] = $delete_object[$ot->get_fully_qualified_fk_column()]; |
1655 | 1655 | |
1656 | 1656 | //wait! it's entirely possible that we'll have a the primary key for this table in here if it's a foreign key for one of the other secondary tables |
1657 | - if ( isset( $delete_object[$ot->get_fully_qualified_pk_column()] ) ) |
|
1657 | + if (isset($delete_object[$ot->get_fully_qualified_pk_column()])) |
|
1658 | 1658 | $deletes[$ot->get_fully_qualified_pk_column()][] = $delete_object[$ot->get_fully_qualified_pk_column()]; |
1659 | 1659 | |
1660 | 1660 | //finally, it is possible that the fk for this table is found in the fully qualified pk column for the fk table, so let's see if that's there! |
1661 | - if ( isset( $delete_object[$ot->get_fully_qualified_pk_on_fk_table()]) ) |
|
1661 | + if (isset($delete_object[$ot->get_fully_qualified_pk_on_fk_table()])) |
|
1662 | 1662 | $deletes[$ot->get_fully_qualified_pk_column()][] = $delete_object[$ot->get_fully_qualified_pk_column()]; |
1663 | 1663 | } |
1664 | 1664 | } |
1665 | 1665 | } |
1666 | 1666 | |
1667 | 1667 | //we should have deletes now, so let's just go through and setup the where statement |
1668 | - foreach ( $deletes as $column => $values ) { |
|
1668 | + foreach ($deletes as $column => $values) { |
|
1669 | 1669 | //make sure we have unique $values; |
1670 | 1670 | $values = array_unique($values); |
1671 | - $query[] = $column . ' IN(' . implode(",",$values) . ')'; |
|
1671 | + $query[] = $column.' IN('.implode(",", $values).')'; |
|
1672 | 1672 | } |
1673 | 1673 | |
1674 | - return !empty($query) ? implode(' AND ', $query ) : ''; |
|
1675 | - }elseif(count($this->get_combined_primary_key_fields()) > 1){ |
|
1674 | + return ! empty($query) ? implode(' AND ', $query) : ''; |
|
1675 | + }elseif (count($this->get_combined_primary_key_fields()) > 1) { |
|
1676 | 1676 | $ways_to_identify_a_row = array(); |
1677 | 1677 | $fields = $this->get_combined_primary_key_fields(); |
1678 | 1678 | //note: because there' sno primary key, that means nothing else can be pointing to this model, right? |
1679 | - foreach($objects_for_deletion as $delete_object){ |
|
1679 | + foreach ($objects_for_deletion as $delete_object) { |
|
1680 | 1680 | $values_for_each_cpk_for_a_row = array(); |
1681 | - foreach($fields as $cpk_field){ |
|
1681 | + foreach ($fields as $cpk_field) { |
|
1682 | 1682 | $values_for_each_cpk_for_a_row[] = $cpk_field->get_qualified_column()."=".$delete_object[$cpk_field->get_qualified_column()]; |
1683 | 1683 | } |
1684 | - $ways_to_identify_a_row[] = "(".implode(" AND ",$values_for_each_cpk_for_a_row).")"; |
|
1684 | + $ways_to_identify_a_row[] = "(".implode(" AND ", $values_for_each_cpk_for_a_row).")"; |
|
1685 | 1685 | } |
1686 | - return implode(" OR ",$ways_to_identify_a_row); |
|
1687 | - }else{ |
|
1686 | + return implode(" OR ", $ways_to_identify_a_row); |
|
1687 | + } else { |
|
1688 | 1688 | //so there's no primary key and no combined key... |
1689 | 1689 | //sorry, can't help you |
1690 | - throw new EE_Error(sprintf(__("Cannot delete objects of type %s because there is no primary key NOR combined key", "event_espresso"),get_class($this))); |
|
1690 | + throw new EE_Error(sprintf(__("Cannot delete objects of type %s because there is no primary key NOR combined key", "event_espresso"), get_class($this))); |
|
1691 | 1691 | } |
1692 | 1692 | } |
1693 | 1693 | |
@@ -1701,21 +1701,21 @@ discard block |
||
1701 | 1701 | * @param bool $distinct if we want to only count the distinct values for the column then you can trigger that by the setting $distinct to TRUE; |
1702 | 1702 | * @return int |
1703 | 1703 | */ |
1704 | - function count($query_params =array(),$field_to_count = NULL, $distinct = FALSE){ |
|
1704 | + function count($query_params = array(), $field_to_count = NULL, $distinct = FALSE) { |
|
1705 | 1705 | $model_query_info = $this->_create_model_query_info_carrier($query_params); |
1706 | - if($field_to_count){ |
|
1706 | + if ($field_to_count) { |
|
1707 | 1707 | $field_obj = $this->field_settings_for($field_to_count); |
1708 | 1708 | $column_to_count = $field_obj->get_qualified_column(); |
1709 | - }elseif($this->has_primary_key_field ()){ |
|
1709 | + }elseif ($this->has_primary_key_field()) { |
|
1710 | 1710 | $pk_field_obj = $this->get_primary_key_field(); |
1711 | 1711 | $column_to_count = $pk_field_obj->get_qualified_column(); |
1712 | - }else{//there's no primary key |
|
1712 | + } else {//there's no primary key |
|
1713 | 1713 | $column_to_count = '*'; |
1714 | 1714 | } |
1715 | 1715 | |
1716 | - $column_to_count = $distinct ? "DISTINCT (" . $column_to_count . " )" : $column_to_count; |
|
1717 | - $SQL ="SELECT COUNT(".$column_to_count.")" . $this->_construct_2nd_half_of_select_query($model_query_info); |
|
1718 | - return (int)$this->_do_wpdb_query( 'get_var', array( $SQL) ); |
|
1716 | + $column_to_count = $distinct ? "DISTINCT (".$column_to_count." )" : $column_to_count; |
|
1717 | + $SQL = "SELECT COUNT(".$column_to_count.")".$this->_construct_2nd_half_of_select_query($model_query_info); |
|
1718 | + return (int) $this->_do_wpdb_query('get_var', array($SQL)); |
|
1719 | 1719 | } |
1720 | 1720 | |
1721 | 1721 | /** |
@@ -1725,23 +1725,23 @@ discard block |
||
1725 | 1725 | * @param string $field_to_sum name of field (array key in $_fields array) |
1726 | 1726 | * @return float |
1727 | 1727 | */ |
1728 | - function sum($query_params, $field_to_sum = NULL){ |
|
1728 | + function sum($query_params, $field_to_sum = NULL) { |
|
1729 | 1729 | $model_query_info = $this->_create_model_query_info_carrier($query_params); |
1730 | 1730 | |
1731 | - if($field_to_sum){ |
|
1731 | + if ($field_to_sum) { |
|
1732 | 1732 | $field_obj = $this->field_settings_for($field_to_sum); |
1733 | 1733 | |
1734 | - }else{ |
|
1734 | + } else { |
|
1735 | 1735 | $field_obj = $this->get_primary_key_field(); |
1736 | 1736 | } |
1737 | 1737 | $column_to_count = $field_obj->get_qualified_column(); |
1738 | 1738 | |
1739 | - $SQL ="SELECT SUM(".$column_to_count.")" . $this->_construct_2nd_half_of_select_query($model_query_info); |
|
1740 | - $return_value = $this->_do_wpdb_query('get_var',array( $SQL ) ); |
|
1741 | - if($field_obj->get_wpdb_data_type() == '%d' || $field_obj->get_wpdb_data_type() == '%s' ){ |
|
1742 | - return (float)$return_value; |
|
1743 | - }else{//must be %f |
|
1744 | - return (float)$return_value; |
|
1739 | + $SQL = "SELECT SUM(".$column_to_count.")".$this->_construct_2nd_half_of_select_query($model_query_info); |
|
1740 | + $return_value = $this->_do_wpdb_query('get_var', array($SQL)); |
|
1741 | + if ($field_obj->get_wpdb_data_type() == '%d' || $field_obj->get_wpdb_data_type() == '%s') { |
|
1742 | + return (float) $return_value; |
|
1743 | + } else {//must be %f |
|
1744 | + return (float) $return_value; |
|
1745 | 1745 | } |
1746 | 1746 | } |
1747 | 1747 | |
@@ -1756,33 +1756,33 @@ discard block |
||
1756 | 1756 | * @global wpdb $wpdb |
1757 | 1757 | * @return mixed |
1758 | 1758 | */ |
1759 | - protected function _do_wpdb_query( $wpdb_method, $arguments_to_provide ){ |
|
1759 | + protected function _do_wpdb_query($wpdb_method, $arguments_to_provide) { |
|
1760 | 1760 | //if we're in maintenance mode level 2, DON'T run any queries |
1761 | 1761 | //because level 2 indicates the database needs updating and |
1762 | 1762 | //is probably out of sync with the code |
1763 | - if( ! EE_Maintenance_Mode::instance()->models_can_query()){ |
|
1763 | + if ( ! EE_Maintenance_Mode::instance()->models_can_query()) { |
|
1764 | 1764 | throw new EE_Error(sprintf(__("Event Espresso Level 2 Maintenance mode is active. That means EE can not run ANY database queries until the necessary migration scripts have run which will take EE out of maintenance mode level 2. Please inform support of this error.", "event_espresso"))); |
1765 | 1765 | } |
1766 | 1766 | /** @type WPDB $wpdb */ |
1767 | 1767 | global $wpdb; |
1768 | - if( ! method_exists( $wpdb, $wpdb_method ) ){ |
|
1769 | - throw new EE_Error( sprintf( __( 'There is no method named "%s" on Wordpress\' $wpdb object','event_espresso' ), $wpdb_method ) ); |
|
1768 | + if ( ! method_exists($wpdb, $wpdb_method)) { |
|
1769 | + throw new EE_Error(sprintf(__('There is no method named "%s" on Wordpress\' $wpdb object', 'event_espresso'), $wpdb_method)); |
|
1770 | 1770 | } |
1771 | - if( WP_DEBUG ){ |
|
1771 | + if (WP_DEBUG) { |
|
1772 | 1772 | $old_show_errors_value = $wpdb->show_errors; |
1773 | - $wpdb->show_errors( FALSE ); |
|
1774 | - } |
|
1775 | - $result = $this->_process_wpdb_query( $wpdb_method, $arguments_to_provide ); |
|
1776 | - $this->show_db_query_if_previously_requested( $wpdb->last_query ); |
|
1777 | - if( WP_DEBUG ){ |
|
1778 | - $wpdb->show_errors( $old_show_errors_value ); |
|
1779 | - if( ! empty( $wpdb->last_error ) ){ |
|
1780 | - throw new EE_Error( sprintf( __( 'WPDB Error: "%s"', 'event_espresso' ), $wpdb->last_error ) ); |
|
1781 | - }elseif( $result === false ){ |
|
1782 | - throw new EE_Error( sprintf( __( 'WPDB Error occurred, but no error message was logged by wpdb! The wpdb method called was "%1$s" and the arguments were "%2$s"', 'event_espresso' ), $wpdb_method, var_export( $arguments_to_provide, true ) ) ); |
|
1773 | + $wpdb->show_errors(FALSE); |
|
1774 | + } |
|
1775 | + $result = $this->_process_wpdb_query($wpdb_method, $arguments_to_provide); |
|
1776 | + $this->show_db_query_if_previously_requested($wpdb->last_query); |
|
1777 | + if (WP_DEBUG) { |
|
1778 | + $wpdb->show_errors($old_show_errors_value); |
|
1779 | + if ( ! empty($wpdb->last_error)) { |
|
1780 | + throw new EE_Error(sprintf(__('WPDB Error: "%s"', 'event_espresso'), $wpdb->last_error)); |
|
1781 | + }elseif ($result === false) { |
|
1782 | + throw new EE_Error(sprintf(__('WPDB Error occurred, but no error message was logged by wpdb! The wpdb method called was "%1$s" and the arguments were "%2$s"', 'event_espresso'), $wpdb_method, var_export($arguments_to_provide, true))); |
|
1783 | 1783 | } |
1784 | - }elseif( $result === false ) { |
|
1785 | - EE_Error::add_error( sprintf( __( 'A database error has occurred. Turn on WP_DEBUG for more information.', 'event_espresso' )), __FILE__, __FUNCTION__, __LINE__); |
|
1784 | + }elseif ($result === false) { |
|
1785 | + EE_Error::add_error(sprintf(__('A database error has occurred. Turn on WP_DEBUG for more information.', 'event_espresso')), __FILE__, __FUNCTION__, __LINE__); |
|
1786 | 1786 | } |
1787 | 1787 | return $result; |
1788 | 1788 | } |
@@ -1798,23 +1798,23 @@ discard block |
||
1798 | 1798 | * @param array $arguments_to_provide |
1799 | 1799 | * @return mixed |
1800 | 1800 | */ |
1801 | - private function _process_wpdb_query( $wpdb_method, $arguments_to_provide ) { |
|
1801 | + private function _process_wpdb_query($wpdb_method, $arguments_to_provide) { |
|
1802 | 1802 | /** @type WPDB $wpdb */ |
1803 | 1803 | global $wpdb; |
1804 | 1804 | $wpdb->last_error = null; |
1805 | - $result = call_user_func_array( array( $wpdb, $wpdb_method ), $arguments_to_provide ); |
|
1805 | + $result = call_user_func_array(array($wpdb, $wpdb_method), $arguments_to_provide); |
|
1806 | 1806 | // was there an error running the query? |
1807 | - if ( ( $result === false || ! empty( $wpdb->last_error ) ) ) { |
|
1808 | - switch ( EEM_Base::$_db_verification_level ) { |
|
1807 | + if (($result === false || ! empty($wpdb->last_error))) { |
|
1808 | + switch (EEM_Base::$_db_verification_level) { |
|
1809 | 1809 | |
1810 | 1810 | case EEM_Base::db_verified_none : |
1811 | 1811 | // let's double-check core's DB |
1812 | - $error_message = $this->_verify_core_db( $wpdb_method, $arguments_to_provide ); |
|
1812 | + $error_message = $this->_verify_core_db($wpdb_method, $arguments_to_provide); |
|
1813 | 1813 | break; |
1814 | 1814 | |
1815 | 1815 | case EEM_Base::db_verified_core : |
1816 | 1816 | // STILL NO LOVE?? verify all the addons too. Maybe they need to be fixed |
1817 | - $error_message = $this->_verify_addons_db( $wpdb_method, $arguments_to_provide ); |
|
1817 | + $error_message = $this->_verify_addons_db($wpdb_method, $arguments_to_provide); |
|
1818 | 1818 | break; |
1819 | 1819 | |
1820 | 1820 | case EEM_Base::db_verified_addons : |
@@ -1822,11 +1822,11 @@ discard block |
||
1822 | 1822 | return $result; |
1823 | 1823 | break; |
1824 | 1824 | } |
1825 | - if ( ! empty( $error_message ) ) { |
|
1826 | - EE_Log::instance()->log( __FILE__, __FUNCTION__, $error_message, 'error' ); |
|
1827 | - trigger_error( $error_message ); |
|
1825 | + if ( ! empty($error_message)) { |
|
1826 | + EE_Log::instance()->log(__FILE__, __FUNCTION__, $error_message, 'error'); |
|
1827 | + trigger_error($error_message); |
|
1828 | 1828 | } |
1829 | - return $this->_process_wpdb_query( $wpdb_method, $arguments_to_provide ); |
|
1829 | + return $this->_process_wpdb_query($wpdb_method, $arguments_to_provide); |
|
1830 | 1830 | |
1831 | 1831 | } |
1832 | 1832 | |
@@ -1842,18 +1842,18 @@ discard block |
||
1842 | 1842 | * @param array $arguments_to_provide |
1843 | 1843 | * @return string |
1844 | 1844 | */ |
1845 | - private function _verify_core_db( $wpdb_method, $arguments_to_provide ){ |
|
1845 | + private function _verify_core_db($wpdb_method, $arguments_to_provide) { |
|
1846 | 1846 | /** @type WPDB $wpdb */ |
1847 | 1847 | global $wpdb; |
1848 | 1848 | //ok remember that we've already attempted fixing the core db, in case the problem persists |
1849 | 1849 | EEM_Base::$_db_verification_level = EEM_Base::db_verified_core; |
1850 | 1850 | $error_message = sprintf( |
1851 | - __( 'WPDB Error "%1$s" while running wpdb method "%2$s" with arguments %3$s. Automatically attempting to fix EE Core DB', 'event_espresso' ), |
|
1851 | + __('WPDB Error "%1$s" while running wpdb method "%2$s" with arguments %3$s. Automatically attempting to fix EE Core DB', 'event_espresso'), |
|
1852 | 1852 | $wpdb->last_error, |
1853 | 1853 | $wpdb_method, |
1854 | - json_encode( $arguments_to_provide ) |
|
1854 | + json_encode($arguments_to_provide) |
|
1855 | 1855 | ); |
1856 | - EE_System::instance()->initialize_db_if_no_migrations_required( false, true ); |
|
1856 | + EE_System::instance()->initialize_db_if_no_migrations_required(false, true); |
|
1857 | 1857 | return $error_message; |
1858 | 1858 | } |
1859 | 1859 | |
@@ -1866,16 +1866,16 @@ discard block |
||
1866 | 1866 | * @param $arguments_to_provide |
1867 | 1867 | * @return string |
1868 | 1868 | */ |
1869 | - private function _verify_addons_db( $wpdb_method, $arguments_to_provide ) { |
|
1869 | + private function _verify_addons_db($wpdb_method, $arguments_to_provide) { |
|
1870 | 1870 | /** @type WPDB $wpdb */ |
1871 | 1871 | global $wpdb; |
1872 | 1872 | //ok remember that we've already attempted fixing the addons dbs, in case the problem persists |
1873 | 1873 | EEM_Base::$_db_verification_level = EEM_Base::db_verified_addons; |
1874 | 1874 | $error_message = sprintf( |
1875 | - __( 'WPDB AGAIN: Error "%1$s" while running the same method and arguments as before. Automatically attempting to fix EE Addons DB', 'event_espresso' ), |
|
1875 | + __('WPDB AGAIN: Error "%1$s" while running the same method and arguments as before. Automatically attempting to fix EE Addons DB', 'event_espresso'), |
|
1876 | 1876 | $wpdb->last_error, |
1877 | 1877 | $wpdb_method, |
1878 | - json_encode( $arguments_to_provide ) |
|
1878 | + json_encode($arguments_to_provide) |
|
1879 | 1879 | ); |
1880 | 1880 | EE_System::instance()->initialize_addons(); |
1881 | 1881 | return $error_message; |
@@ -1890,7 +1890,7 @@ discard block |
||
1890 | 1890 | * @param EE_Model_Query_Info_Carrier $model_query_info |
1891 | 1891 | * @return string |
1892 | 1892 | */ |
1893 | - private function _construct_2nd_half_of_select_query(EE_Model_Query_Info_Carrier $model_query_info){ |
|
1893 | + private function _construct_2nd_half_of_select_query(EE_Model_Query_Info_Carrier $model_query_info) { |
|
1894 | 1894 | return " FROM ".$model_query_info->get_full_join_sql(). |
1895 | 1895 | $model_query_info->get_where_sql(). |
1896 | 1896 | $model_query_info->get_group_by_sql(). |
@@ -1903,7 +1903,7 @@ discard block |
||
1903 | 1903 | * Set to easily debug the next X queries ran from this model. |
1904 | 1904 | * @param int $count |
1905 | 1905 | */ |
1906 | - function show_next_x_db_queries($count = 1){ |
|
1906 | + function show_next_x_db_queries($count = 1) { |
|
1907 | 1907 | $this->_show_next_x_db_queries = $count; |
1908 | 1908 | } |
1909 | 1909 | |
@@ -1912,8 +1912,8 @@ discard block |
||
1912 | 1912 | /** |
1913 | 1913 | * @param $sql_query |
1914 | 1914 | */ |
1915 | - function show_db_query_if_previously_requested($sql_query){ |
|
1916 | - if($this->_show_next_x_db_queries > 0){ |
|
1915 | + function show_db_query_if_previously_requested($sql_query) { |
|
1916 | + if ($this->_show_next_x_db_queries > 0) { |
|
1917 | 1917 | echo $sql_query; |
1918 | 1918 | $this->_show_next_x_db_queries--; |
1919 | 1919 | } |
@@ -1937,9 +1937,9 @@ discard block |
||
1937 | 1937 | * @param array $extra_join_model_fields_n_values This allows you to enter further query params for the relation to for relation to methods that allow you to further specify extra columns to join by (such as HABTM). Keep in mind that the only acceptable query_params is strict "col" => "value" pairs because these will be inserted in any new rows created as well. |
1938 | 1938 | * @return EE_Base_Class which was added as a relation. Object referred to by $other_model_id_or_obj |
1939 | 1939 | */ |
1940 | - public function add_relationship_to($id_or_obj,$other_model_id_or_obj, $relationName, $extra_join_model_fields_n_values = array()){ |
|
1940 | + public function add_relationship_to($id_or_obj, $other_model_id_or_obj, $relationName, $extra_join_model_fields_n_values = array()) { |
|
1941 | 1941 | $relation_obj = $this->related_settings_for($relationName); |
1942 | - return $relation_obj->add_relation_to( $id_or_obj, $other_model_id_or_obj, $extra_join_model_fields_n_values); |
|
1942 | + return $relation_obj->add_relation_to($id_or_obj, $other_model_id_or_obj, $extra_join_model_fields_n_values); |
|
1943 | 1943 | } |
1944 | 1944 | |
1945 | 1945 | /** |
@@ -1958,9 +1958,9 @@ discard block |
||
1958 | 1958 | * @return boolean of success |
1959 | 1959 | * @param array $where_query This allows you to enter further query params for the relation to for relation to methods that allow you to further specify extra columns to join by (such as HABTM). Keep in mind that the only acceptable query_params is strict "col" => "value" pairs because these will be inserted in any new rows created as well. |
1960 | 1960 | */ |
1961 | - public function remove_relationship_to($id_or_obj, $other_model_id_or_obj, $relationName, $where_query= array() ){ |
|
1961 | + public function remove_relationship_to($id_or_obj, $other_model_id_or_obj, $relationName, $where_query = array()) { |
|
1962 | 1962 | $relation_obj = $this->related_settings_for($relationName); |
1963 | - return $relation_obj->remove_relation_to($id_or_obj, $other_model_id_or_obj, $where_query ); |
|
1963 | + return $relation_obj->remove_relation_to($id_or_obj, $other_model_id_or_obj, $where_query); |
|
1964 | 1964 | } |
1965 | 1965 | |
1966 | 1966 | |
@@ -1973,9 +1973,9 @@ discard block |
||
1973 | 1973 | * @param EE_Base_Class[] objects to which relations were removed |
1974 | 1974 | * @return \EE_Base_Class[] |
1975 | 1975 | */ |
1976 | - public function remove_relations($id_or_obj,$relationName,$where_query_params = array()){ |
|
1976 | + public function remove_relations($id_or_obj, $relationName, $where_query_params = array()) { |
|
1977 | 1977 | $relation_obj = $this->related_settings_for($relationName); |
1978 | - return $relation_obj->remove_relations($id_or_obj, $where_query_params ); |
|
1978 | + return $relation_obj->remove_relations($id_or_obj, $where_query_params); |
|
1979 | 1979 | } |
1980 | 1980 | |
1981 | 1981 | |
@@ -1988,10 +1988,10 @@ discard block |
||
1988 | 1988 | * @param array $query_params like EEM_Base::get_all |
1989 | 1989 | * @return EE_Base_Class[] |
1990 | 1990 | */ |
1991 | - function get_all_related($id_or_obj, $model_name, $query_params = null){ |
|
1991 | + function get_all_related($id_or_obj, $model_name, $query_params = null) { |
|
1992 | 1992 | $model_obj = $this->ensure_is_obj($id_or_obj); |
1993 | 1993 | $relation_settings = $this->related_settings_for($model_name); |
1994 | - return $relation_settings->get_all_related($model_obj,$query_params); |
|
1994 | + return $relation_settings->get_all_related($model_obj, $query_params); |
|
1995 | 1995 | } |
1996 | 1996 | |
1997 | 1997 | /** |
@@ -2004,10 +2004,10 @@ discard block |
||
2004 | 2004 | * @param array $query_params |
2005 | 2005 | * @return int how many deleted |
2006 | 2006 | */ |
2007 | - public function delete_related($id_or_obj,$model_name, $query_params = array()){ |
|
2007 | + public function delete_related($id_or_obj, $model_name, $query_params = array()) { |
|
2008 | 2008 | $model_obj = $this->ensure_is_obj($id_or_obj); |
2009 | 2009 | $relation_settings = $this->related_settings_for($model_name); |
2010 | - return $relation_settings->delete_all_related($model_obj,$query_params); |
|
2010 | + return $relation_settings->delete_all_related($model_obj, $query_params); |
|
2011 | 2011 | } |
2012 | 2012 | |
2013 | 2013 | /** |
@@ -2020,10 +2020,10 @@ discard block |
||
2020 | 2020 | * @param array $query_params |
2021 | 2021 | * @return int how many deleted |
2022 | 2022 | */ |
2023 | - public function delete_related_permanently($id_or_obj,$model_name, $query_params = array()){ |
|
2023 | + public function delete_related_permanently($id_or_obj, $model_name, $query_params = array()) { |
|
2024 | 2024 | $model_obj = $this->ensure_is_obj($id_or_obj); |
2025 | 2025 | $relation_settings = $this->related_settings_for($model_name); |
2026 | - return $relation_settings->delete_related_permanently($model_obj,$query_params); |
|
2026 | + return $relation_settings->delete_related_permanently($model_obj, $query_params); |
|
2027 | 2027 | } |
2028 | 2028 | |
2029 | 2029 | /** |
@@ -2036,17 +2036,17 @@ discard block |
||
2036 | 2036 | * @param bool $distinct if we want to only count the distinct values for the column then you can trigger that by the setting $distinct to TRUE; |
2037 | 2037 | * @return int |
2038 | 2038 | */ |
2039 | - function count_related($id_or_obj,$model_name,$query_params = array(),$field_to_count = null, $distinct = FALSE){ |
|
2039 | + function count_related($id_or_obj, $model_name, $query_params = array(), $field_to_count = null, $distinct = FALSE) { |
|
2040 | 2040 | $related_model = $this->get_related_model_obj($model_name); |
2041 | 2041 | //we're just going to use the query params on the related model's normal get_all query, |
2042 | 2042 | //except add a condition to say to match the current mod |
2043 | - if( ! isset($query_params['default_where_conditions'])){ |
|
2044 | - $query_params['default_where_conditions']='none'; |
|
2043 | + if ( ! isset($query_params['default_where_conditions'])) { |
|
2044 | + $query_params['default_where_conditions'] = 'none'; |
|
2045 | 2045 | } |
2046 | 2046 | $this_model_name = $this->get_this_model_name(); |
2047 | 2047 | $this_pk_field_name = $this->get_primary_key_field()->get_name(); |
2048 | - $query_params[0][$this_model_name.".".$this_pk_field_name]=$id_or_obj; |
|
2049 | - return $related_model->count($query_params,$field_to_count,$distinct); |
|
2048 | + $query_params[0][$this_model_name.".".$this_pk_field_name] = $id_or_obj; |
|
2049 | + return $related_model->count($query_params, $field_to_count, $distinct); |
|
2050 | 2050 | } |
2051 | 2051 | |
2052 | 2052 | |
@@ -2060,21 +2060,21 @@ discard block |
||
2060 | 2060 | * @param string $field_to_sum name of field to count by. By default, uses primary key |
2061 | 2061 | * @return float |
2062 | 2062 | */ |
2063 | - function sum_related($id_or_obj,$model_name,$query_params,$field_to_sum = null){ |
|
2063 | + function sum_related($id_or_obj, $model_name, $query_params, $field_to_sum = null) { |
|
2064 | 2064 | $related_model = $this->get_related_model_obj($model_name); |
2065 | - if( ! is_array( $query_params ) ){ |
|
2066 | - EE_Error::doing_it_wrong('EEM_Base::sum_related', sprintf( __( '$query_params should be an array, you passed a variable of type %s', 'event_espresso' ), gettype( $query_params ) ), '4.6.0' ); |
|
2065 | + if ( ! is_array($query_params)) { |
|
2066 | + EE_Error::doing_it_wrong('EEM_Base::sum_related', sprintf(__('$query_params should be an array, you passed a variable of type %s', 'event_espresso'), gettype($query_params)), '4.6.0'); |
|
2067 | 2067 | $query_params = array(); |
2068 | 2068 | } |
2069 | 2069 | //we're just going to use the query params on the related model's normal get_all query, |
2070 | 2070 | //except add a condition to say to match the current mod |
2071 | - if( ! isset($query_params['default_where_conditions'])){ |
|
2072 | - $query_params['default_where_conditions']='none'; |
|
2071 | + if ( ! isset($query_params['default_where_conditions'])) { |
|
2072 | + $query_params['default_where_conditions'] = 'none'; |
|
2073 | 2073 | } |
2074 | 2074 | $this_model_name = $this->get_this_model_name(); |
2075 | 2075 | $this_pk_field_name = $this->get_primary_key_field()->get_name(); |
2076 | - $query_params[0][$this_model_name.".".$this_pk_field_name]=$id_or_obj; |
|
2077 | - return $related_model->sum($query_params,$field_to_sum); |
|
2076 | + $query_params[0][$this_model_name.".".$this_pk_field_name] = $id_or_obj; |
|
2077 | + return $related_model->sum($query_params, $field_to_sum); |
|
2078 | 2078 | } |
2079 | 2079 | |
2080 | 2080 | |
@@ -2086,12 +2086,12 @@ discard block |
||
2086 | 2086 | * @param array $query_params like EEM_Base::get_all's |
2087 | 2087 | * @return EE_Base_Class |
2088 | 2088 | */ |
2089 | - public function get_first_related( EE_Base_Class $id_or_obj, $other_model_name, $query_params ){ |
|
2090 | - $query_params['limit']=1; |
|
2091 | - $results = $this->get_all_related($id_or_obj,$other_model_name,$query_params); |
|
2092 | - if( $results ){ |
|
2089 | + public function get_first_related(EE_Base_Class $id_or_obj, $other_model_name, $query_params) { |
|
2090 | + $query_params['limit'] = 1; |
|
2091 | + $results = $this->get_all_related($id_or_obj, $other_model_name, $query_params); |
|
2092 | + if ($results) { |
|
2093 | 2093 | return array_shift($results); |
2094 | - }else{ |
|
2094 | + } else { |
|
2095 | 2095 | return null; |
2096 | 2096 | } |
2097 | 2097 | |
@@ -2101,8 +2101,8 @@ discard block |
||
2101 | 2101 | * Gets the model's name as it's expected in queries. For example, if this is EEM_Event model, that would be Event |
2102 | 2102 | * @return string |
2103 | 2103 | */ |
2104 | - function get_this_model_name(){ |
|
2105 | - return str_replace("EEM_","",get_class($this)); |
|
2104 | + function get_this_model_name() { |
|
2105 | + return str_replace("EEM_", "", get_class($this)); |
|
2106 | 2106 | } |
2107 | 2107 | |
2108 | 2108 | /** |
@@ -2110,14 +2110,14 @@ discard block |
||
2110 | 2110 | * @return EE_Any_Foreign_Model_Name_Field |
2111 | 2111 | * @throws EE_Error |
2112 | 2112 | */ |
2113 | - public function get_field_containing_related_model_name(){ |
|
2114 | - foreach($this->field_settings(true) as $field){ |
|
2115 | - if($field instanceof EE_Any_Foreign_Model_Name_Field){ |
|
2113 | + public function get_field_containing_related_model_name() { |
|
2114 | + foreach ($this->field_settings(true) as $field) { |
|
2115 | + if ($field instanceof EE_Any_Foreign_Model_Name_Field) { |
|
2116 | 2116 | $field_with_model_name = $field; |
2117 | 2117 | } |
2118 | 2118 | } |
2119 | - if( !isset($field_with_model_name) || !$field_with_model_name ){ |
|
2120 | - throw new EE_Error(sprintf(__("There is no EE_Any_Foreign_Model_Name field on model %s", "event_espresso"), $this->get_this_model_name() )); |
|
2119 | + if ( ! isset($field_with_model_name) || ! $field_with_model_name) { |
|
2120 | + throw new EE_Error(sprintf(__("There is no EE_Any_Foreign_Model_Name field on model %s", "event_espresso"), $this->get_this_model_name())); |
|
2121 | 2121 | } |
2122 | 2122 | return $field_with_model_name; |
2123 | 2123 | } |
@@ -2138,19 +2138,19 @@ discard block |
||
2138 | 2138 | * @return int new primary key on main table that got inserted |
2139 | 2139 | * @throws EE_Error |
2140 | 2140 | */ |
2141 | - function insert($field_n_values){ |
|
2141 | + function insert($field_n_values) { |
|
2142 | 2142 | /** |
2143 | 2143 | * Filters the fields and their values before inserting an item using the models |
2144 | 2144 | * @param array $fields_n_values keys are the fields and values are their new values |
2145 | 2145 | * @param EEM_Base $model the model used |
2146 | 2146 | */ |
2147 | - $field_n_values = apply_filters( 'FHEE__EEM_Base__insert__fields_n_values', $field_n_values, $this ); |
|
2148 | - if($this->_satisfies_unique_indexes($field_n_values)){ |
|
2147 | + $field_n_values = apply_filters('FHEE__EEM_Base__insert__fields_n_values', $field_n_values, $this); |
|
2148 | + if ($this->_satisfies_unique_indexes($field_n_values)) { |
|
2149 | 2149 | $main_table = $this->_get_main_table(); |
2150 | 2150 | $new_id = $this->_insert_into_specific_table($main_table, $field_n_values, false); |
2151 | - if( $new_id !== false ) { |
|
2152 | - foreach($this->_get_other_tables() as $other_table){ |
|
2153 | - $this->_insert_into_specific_table($other_table, $field_n_values,$new_id); |
|
2151 | + if ($new_id !== false) { |
|
2152 | + foreach ($this->_get_other_tables() as $other_table) { |
|
2153 | + $this->_insert_into_specific_table($other_table, $field_n_values, $new_id); |
|
2154 | 2154 | } |
2155 | 2155 | } |
2156 | 2156 | /** |
@@ -2160,9 +2160,9 @@ discard block |
||
2160 | 2160 | * @param array $fields_n_values fields and their values |
2161 | 2161 | * @param int|string the ID of the newly-inserted model object |
2162 | 2162 | */ |
2163 | - do_action( 'AHEE__EEM_Base__insert__end', $this, $field_n_values, $new_id ); |
|
2163 | + do_action('AHEE__EEM_Base__insert__end', $this, $field_n_values, $new_id); |
|
2164 | 2164 | return $new_id; |
2165 | - }else{ |
|
2165 | + } else { |
|
2166 | 2166 | return FALSE; |
2167 | 2167 | } |
2168 | 2168 | } |
@@ -2175,11 +2175,11 @@ discard block |
||
2175 | 2175 | * @param string $action |
2176 | 2176 | * @return boolean |
2177 | 2177 | */ |
2178 | - protected function _satisfies_unique_indexes($field_n_values,$action = 'insert'){ |
|
2179 | - foreach($this->unique_indexes() as $index_name => $index){ |
|
2178 | + protected function _satisfies_unique_indexes($field_n_values, $action = 'insert') { |
|
2179 | + foreach ($this->unique_indexes() as $index_name => $index) { |
|
2180 | 2180 | $uniqueness_where_params = array_intersect_key($field_n_values, $index->fields()); |
2181 | - if($this->exists(array($uniqueness_where_params))){ |
|
2182 | - EE_Error::add_error(sprintf(__("Could not %s %s. %s uniqueness index failed. Fields %s must form a unique set, but an entry already exists with values %s.", "event_espresso"),$action,$this->_get_class_name(),$index_name,implode(",",$index->field_names()),http_build_query($uniqueness_where_params)), __FILE__, __FUNCTION__, __LINE__ ); |
|
2181 | + if ($this->exists(array($uniqueness_where_params))) { |
|
2182 | + EE_Error::add_error(sprintf(__("Could not %s %s. %s uniqueness index failed. Fields %s must form a unique set, but an entry already exists with values %s.", "event_espresso"), $action, $this->_get_class_name(), $index_name, implode(",", $index->field_names()), http_build_query($uniqueness_where_params)), __FILE__, __FUNCTION__, __LINE__); |
|
2183 | 2183 | return false; |
2184 | 2184 | } |
2185 | 2185 | } |
@@ -2200,28 +2200,28 @@ discard block |
||
2200 | 2200 | * @throws EE_Error |
2201 | 2201 | * @return EE_Base_Class |
2202 | 2202 | */ |
2203 | - public function get_one_conflicting($obj_or_fields_array, $include_primary_key = true ){ |
|
2204 | - if($obj_or_fields_array instanceof EE_Base_Class){ |
|
2203 | + public function get_one_conflicting($obj_or_fields_array, $include_primary_key = true) { |
|
2204 | + if ($obj_or_fields_array instanceof EE_Base_Class) { |
|
2205 | 2205 | $fields_n_values = $obj_or_fields_array->model_field_array(); |
2206 | - }elseif( is_array($obj_or_fields_array)){ |
|
2206 | + }elseif (is_array($obj_or_fields_array)) { |
|
2207 | 2207 | $fields_n_values = $obj_or_fields_array; |
2208 | - }else{ |
|
2209 | - throw new EE_Error(sprintf(__("%s get_all_conflicting should be called with a model object or an array of field names and values, you provided %d", "event_espresso"),get_class($this),$obj_or_fields_array)); |
|
2208 | + } else { |
|
2209 | + throw new EE_Error(sprintf(__("%s get_all_conflicting should be called with a model object or an array of field names and values, you provided %d", "event_espresso"), get_class($this), $obj_or_fields_array)); |
|
2210 | 2210 | } |
2211 | 2211 | $query_params = array(); |
2212 | - if( $this->has_primary_key_field() && |
|
2213 | - ( $include_primary_key || $this->get_primary_key_field() instanceof EE_Primary_Key_String_Field) && |
|
2214 | - isset($fields_n_values[$this->primary_key_name()])){ |
|
2212 | + if ($this->has_primary_key_field() && |
|
2213 | + ($include_primary_key || $this->get_primary_key_field() instanceof EE_Primary_Key_String_Field) && |
|
2214 | + isset($fields_n_values[$this->primary_key_name()])) { |
|
2215 | 2215 | $query_params[0]['OR'][$this->primary_key_name()] = $fields_n_values[$this->primary_key_name()]; |
2216 | 2216 | } |
2217 | - foreach($this->unique_indexes() as $unique_index_name=>$unique_index){ |
|
2217 | + foreach ($this->unique_indexes() as $unique_index_name=>$unique_index) { |
|
2218 | 2218 | $uniqueness_where_params = array_intersect_key($fields_n_values, $unique_index->fields()); |
2219 | 2219 | $query_params[0]['OR']['AND*'.$unique_index_name] = $uniqueness_where_params; |
2220 | 2220 | } |
2221 | 2221 | //if there is nothing to base this search on, then we shouldn't find anything |
2222 | - if( empty( $query_params ) ){ |
|
2222 | + if (empty($query_params)) { |
|
2223 | 2223 | return array(); |
2224 | - }else{ |
|
2224 | + } else { |
|
2225 | 2225 | return $this->get_one($query_params); |
2226 | 2226 | } |
2227 | 2227 | } |
@@ -2231,7 +2231,7 @@ discard block |
||
2231 | 2231 | * @param array $query_params |
2232 | 2232 | * @return boolean |
2233 | 2233 | */ |
2234 | - function exists($query_params){ |
|
2234 | + function exists($query_params) { |
|
2235 | 2235 | $query_params['limit'] = 1; |
2236 | 2236 | return $this->count($query_params) > 0; |
2237 | 2237 | } |
@@ -2241,7 +2241,7 @@ discard block |
||
2241 | 2241 | * @param int|string $id |
2242 | 2242 | * @return boolean |
2243 | 2243 | */ |
2244 | - function exists_by_ID($id){ |
|
2244 | + function exists_by_ID($id) { |
|
2245 | 2245 | return $this->exists(array('default_where_conditions'=>'none', array($this->primary_key_name() => $id))); |
2246 | 2246 | } |
2247 | 2247 | |
@@ -2261,45 +2261,45 @@ discard block |
||
2261 | 2261 | * @global WPDB $wpdb only used to get the $wpdb->insert_id after performing an insert |
2262 | 2262 | * @return int ID of new row inserted, or FALSE on failure |
2263 | 2263 | */ |
2264 | - protected function _insert_into_specific_table(EE_Table_Base $table, $fields_n_values, $new_id = 0 ){ |
|
2264 | + protected function _insert_into_specific_table(EE_Table_Base $table, $fields_n_values, $new_id = 0) { |
|
2265 | 2265 | global $wpdb; |
2266 | 2266 | $insertion_col_n_values = array(); |
2267 | 2267 | $format_for_insertion = array(); |
2268 | 2268 | $fields_on_table = $this->_get_fields_for_table($table->get_table_alias()); |
2269 | - foreach($fields_on_table as $field_name => $field_obj){ |
|
2269 | + foreach ($fields_on_table as $field_name => $field_obj) { |
|
2270 | 2270 | //check if its an auto-incrementing column, in which case we should just leave it to do its autoincrement thing |
2271 | - if($field_obj->is_auto_increment()){ |
|
2271 | + if ($field_obj->is_auto_increment()) { |
|
2272 | 2272 | continue; |
2273 | 2273 | } |
2274 | 2274 | $prepared_value = $this->_prepare_value_or_use_default($field_obj, $fields_n_values); |
2275 | 2275 | //if the value we want to assign it to is NULL, just don't mention it for the insertion |
2276 | - if( $prepared_value !== NULL ){ |
|
2277 | - $insertion_col_n_values[ $field_obj->get_table_column() ] = $prepared_value; |
|
2276 | + if ($prepared_value !== NULL) { |
|
2277 | + $insertion_col_n_values[$field_obj->get_table_column()] = $prepared_value; |
|
2278 | 2278 | $format_for_insertion[] = $field_obj->get_wpdb_data_type(); |
2279 | 2279 | } |
2280 | 2280 | } |
2281 | 2281 | |
2282 | - if($table instanceof EE_Secondary_Table && $new_id){ |
|
2282 | + if ($table instanceof EE_Secondary_Table && $new_id) { |
|
2283 | 2283 | //its not the main table, so we should have already saved the main table's PK which we just inserted |
2284 | 2284 | //so add the fk to the main table as a column |
2285 | 2285 | $insertion_col_n_values[$table->get_fk_on_table()] = $new_id; |
2286 | - $format_for_insertion[]='%d';//yes right now we're only allowing these foreign keys to be INTs |
|
2286 | + $format_for_insertion[] = '%d'; //yes right now we're only allowing these foreign keys to be INTs |
|
2287 | 2287 | } |
2288 | 2288 | //insert the new entry |
2289 | - $result = $this->_do_wpdb_query( 'insert', array( $table->get_table_name(), $insertion_col_n_values, $format_for_insertion ) ); |
|
2290 | - if( $result === false ) { |
|
2289 | + $result = $this->_do_wpdb_query('insert', array($table->get_table_name(), $insertion_col_n_values, $format_for_insertion)); |
|
2290 | + if ($result === false) { |
|
2291 | 2291 | return false; |
2292 | 2292 | } |
2293 | 2293 | //ok, now what do we return for the ID of the newly-inserted thing? |
2294 | - if($this->has_primary_key_field()){ |
|
2295 | - if($this->get_primary_key_field()->is_auto_increment()){ |
|
2294 | + if ($this->has_primary_key_field()) { |
|
2295 | + if ($this->get_primary_key_field()->is_auto_increment()) { |
|
2296 | 2296 | return $wpdb->insert_id; |
2297 | - }else{ |
|
2297 | + } else { |
|
2298 | 2298 | //it's not an auto-increment primary key, so |
2299 | 2299 | //it must have been supplied |
2300 | 2300 | return $fields_n_values[$this->get_primary_key_field()->get_name()]; |
2301 | 2301 | } |
2302 | - }else{ |
|
2302 | + } else { |
|
2303 | 2303 | //we can't return a primary key because there is none. instead return |
2304 | 2304 | //a unique string indicating this model |
2305 | 2305 | return $this->get_index_primary_key_string($fields_n_values); |
@@ -2314,15 +2314,15 @@ discard block |
||
2314 | 2314 | * @param array $fields_n_values |
2315 | 2315 | * @return mixed string|int|float depending on what the table column will be expecting |
2316 | 2316 | */ |
2317 | - protected function _prepare_value_or_use_default( $field_obj, $fields_n_values ){ |
|
2317 | + protected function _prepare_value_or_use_default($field_obj, $fields_n_values) { |
|
2318 | 2318 | //if this field doesn't allow nullable, don't allow it |
2319 | - if( ! $field_obj->is_nullable() && ( |
|
2320 | - ! isset( $fields_n_values[ $field_obj->get_name() ] ) || |
|
2321 | - $fields_n_values[ $field_obj->get_name() ] === NULL ) ){ |
|
2322 | - $fields_n_values[ $field_obj->get_name() ] = $field_obj->get_default_value(); |
|
2319 | + if ( ! $field_obj->is_nullable() && ( |
|
2320 | + ! isset($fields_n_values[$field_obj->get_name()]) || |
|
2321 | + $fields_n_values[$field_obj->get_name()] === NULL )) { |
|
2322 | + $fields_n_values[$field_obj->get_name()] = $field_obj->get_default_value(); |
|
2323 | 2323 | } |
2324 | - $unprepared_value = isset( $fields_n_values[ $field_obj->get_name() ] ) ? $fields_n_values[ $field_obj->get_name() ] : NULL; |
|
2325 | - return $this->_prepare_value_for_use_in_db( $unprepared_value, $field_obj); |
|
2324 | + $unprepared_value = isset($fields_n_values[$field_obj->get_name()]) ? $fields_n_values[$field_obj->get_name()] : NULL; |
|
2325 | + return $this->_prepare_value_for_use_in_db($unprepared_value, $field_obj); |
|
2326 | 2326 | } |
2327 | 2327 | |
2328 | 2328 | |
@@ -2334,9 +2334,9 @@ discard block |
||
2334 | 2334 | * @param EE_Model_Field_Base $field field which will be doing the preparing of the value. If null, we assume $value is a custom selection |
2335 | 2335 | * @return mixed a value ready for use in the database for insertions, updating, or in a where clause |
2336 | 2336 | */ |
2337 | - private function _prepare_value_for_use_in_db($value, $field){ |
|
2338 | - if($field && $field instanceof EE_Model_Field_Base){ |
|
2339 | - switch( $this->_values_already_prepared_by_model_object ){ |
|
2337 | + private function _prepare_value_for_use_in_db($value, $field) { |
|
2338 | + if ($field && $field instanceof EE_Model_Field_Base) { |
|
2339 | + switch ($this->_values_already_prepared_by_model_object) { |
|
2340 | 2340 | /** @noinspection PhpMissingBreakStatementInspection */ |
2341 | 2341 | case self::not_prepared_by_model_object: |
2342 | 2342 | $value = $field->prepare_for_set($value); |
@@ -2347,7 +2347,7 @@ discard block |
||
2347 | 2347 | //leave the value alone |
2348 | 2348 | } |
2349 | 2349 | return $value; |
2350 | - }else{ |
|
2350 | + } else { |
|
2351 | 2351 | return $value; |
2352 | 2352 | } |
2353 | 2353 | } |
@@ -2357,13 +2357,13 @@ discard block |
||
2357 | 2357 | * @return EE_Primary_Table |
2358 | 2358 | * @throws EE_Error |
2359 | 2359 | */ |
2360 | - protected function _get_main_table(){ |
|
2361 | - foreach($this->_tables as $table){ |
|
2362 | - if($table instanceof EE_Primary_Table){ |
|
2360 | + protected function _get_main_table() { |
|
2361 | + foreach ($this->_tables as $table) { |
|
2362 | + if ($table instanceof EE_Primary_Table) { |
|
2363 | 2363 | return $table; |
2364 | 2364 | } |
2365 | 2365 | } |
2366 | - throw new EE_Error(sprintf(__('There are no main tables on %s. They should be added to _tables array in the constructor','event_espresso'),get_class($this))); |
|
2366 | + throw new EE_Error(sprintf(__('There are no main tables on %s. They should be added to _tables array in the constructor', 'event_espresso'), get_class($this))); |
|
2367 | 2367 | } |
2368 | 2368 | |
2369 | 2369 | /** |
@@ -2382,7 +2382,7 @@ discard block |
||
2382 | 2382 | */ |
2383 | 2383 | public function second_table() { |
2384 | 2384 | // grab second table from tables array |
2385 | - $second_table = end( $this->_tables ); |
|
2385 | + $second_table = end($this->_tables); |
|
2386 | 2386 | return $second_table instanceof EE_Secondary_Table ? $second_table->get_table_name() : NULL; |
2387 | 2387 | } |
2388 | 2388 | |
@@ -2395,8 +2395,8 @@ discard block |
||
2395 | 2395 | * @param string $table_alias |
2396 | 2396 | * @return EE_Primary_Table | EE_Secondary_Table |
2397 | 2397 | */ |
2398 | - public function get_table_obj_by_alias( $table_alias = '' ) { |
|
2399 | - return isset( $this->_tables[ $table_alias ] ) ? $this->_tables[ $table_alias ] : NULL; |
|
2398 | + public function get_table_obj_by_alias($table_alias = '') { |
|
2399 | + return isset($this->_tables[$table_alias]) ? $this->_tables[$table_alias] : NULL; |
|
2400 | 2400 | } |
2401 | 2401 | |
2402 | 2402 | |
@@ -2405,10 +2405,10 @@ discard block |
||
2405 | 2405 | * Gets all the tables of type EE_Other_Table from EEM_CPT_Basel_Model::_tables |
2406 | 2406 | * @return EE_Secondary_Table[] |
2407 | 2407 | */ |
2408 | - protected function _get_other_tables(){ |
|
2409 | - $other_tables =array(); |
|
2410 | - foreach($this->_tables as $table_alias => $table){ |
|
2411 | - if($table instanceof EE_Secondary_Table){ |
|
2408 | + protected function _get_other_tables() { |
|
2409 | + $other_tables = array(); |
|
2410 | + foreach ($this->_tables as $table_alias => $table) { |
|
2411 | + if ($table instanceof EE_Secondary_Table) { |
|
2412 | 2412 | $other_tables[$table_alias] = $table; |
2413 | 2413 | } |
2414 | 2414 | } |
@@ -2420,7 +2420,7 @@ discard block |
||
2420 | 2420 | * @param string $table_alias, array key in EEM_Base::_tables |
2421 | 2421 | * @return EE_Model_Field_Base[] |
2422 | 2422 | */ |
2423 | - function _get_fields_for_table($table_alias){ |
|
2423 | + function _get_fields_for_table($table_alias) { |
|
2424 | 2424 | return $this->_fields[$table_alias]; |
2425 | 2425 | } |
2426 | 2426 | |
@@ -2432,29 +2432,29 @@ discard block |
||
2432 | 2432 | * @param array $query_params like EEM_Base::get_all's $query_parameters['where'] |
2433 | 2433 | * @return EE_Model_Query_Info_Carrier |
2434 | 2434 | */ |
2435 | - function _extract_related_models_from_query($query_params){ |
|
2435 | + function _extract_related_models_from_query($query_params) { |
|
2436 | 2436 | $query_info_carrier = new EE_Model_Query_Info_Carrier(); |
2437 | - if(array_key_exists(0,$query_params)){ |
|
2438 | - $this->_extract_related_models_from_sub_params_array_keys($query_params[0], $query_info_carrier,0); |
|
2439 | - } |
|
2440 | - if(array_key_exists('group_by', $query_params)){ |
|
2441 | - if(is_array($query_params['group_by'])){ |
|
2442 | - $this->_extract_related_models_from_sub_params_array_values($query_params['group_by'],$query_info_carrier,'group_by'); |
|
2443 | - }elseif( ! empty ( $query_params['group_by'] )){ |
|
2444 | - $this->_extract_related_model_info_from_query_param( $query_params['group_by'],$query_info_carrier,'group_by'); |
|
2437 | + if (array_key_exists(0, $query_params)) { |
|
2438 | + $this->_extract_related_models_from_sub_params_array_keys($query_params[0], $query_info_carrier, 0); |
|
2439 | + } |
|
2440 | + if (array_key_exists('group_by', $query_params)) { |
|
2441 | + if (is_array($query_params['group_by'])) { |
|
2442 | + $this->_extract_related_models_from_sub_params_array_values($query_params['group_by'], $query_info_carrier, 'group_by'); |
|
2443 | + }elseif ( ! empty ($query_params['group_by'])) { |
|
2444 | + $this->_extract_related_model_info_from_query_param($query_params['group_by'], $query_info_carrier, 'group_by'); |
|
2445 | 2445 | } |
2446 | 2446 | } |
2447 | - if(array_key_exists('having',$query_params)){ |
|
2448 | - $this->_extract_related_models_from_sub_params_array_keys($query_params[0], $query_info_carrier,'having'); |
|
2447 | + if (array_key_exists('having', $query_params)) { |
|
2448 | + $this->_extract_related_models_from_sub_params_array_keys($query_params[0], $query_info_carrier, 'having'); |
|
2449 | 2449 | } |
2450 | - if(array_key_exists('order_by', $query_params)){ |
|
2451 | - if ( is_array( $query_params['order_by'] ) ) |
|
2452 | - $this->_extract_related_models_from_sub_params_array_keys($query_params['order_by'],$query_info_carrier,'order_by'); |
|
2453 | - elseif( ! empty( $query_params['order_by'] )) |
|
2454 | - $this->_extract_related_model_info_from_query_param( $query_params['order_by'], $query_info_carrier,'order_by'); |
|
2450 | + if (array_key_exists('order_by', $query_params)) { |
|
2451 | + if (is_array($query_params['order_by'])) |
|
2452 | + $this->_extract_related_models_from_sub_params_array_keys($query_params['order_by'], $query_info_carrier, 'order_by'); |
|
2453 | + elseif ( ! empty($query_params['order_by'])) |
|
2454 | + $this->_extract_related_model_info_from_query_param($query_params['order_by'], $query_info_carrier, 'order_by'); |
|
2455 | 2455 | } |
2456 | - if(array_key_exists('force_join', $query_params)){ |
|
2457 | - $this->_extract_related_models_from_sub_params_array_values($query_params['force_join'],$query_info_carrier,'force_join'); |
|
2456 | + if (array_key_exists('force_join', $query_params)) { |
|
2457 | + $this->_extract_related_models_from_sub_params_array_values($query_params['force_join'], $query_info_carrier, 'force_join'); |
|
2458 | 2458 | } |
2459 | 2459 | return $query_info_carrier; |
2460 | 2460 | } |
@@ -2467,34 +2467,34 @@ discard block |
||
2467 | 2467 | * @throws EE_Error |
2468 | 2468 | * @return \EE_Model_Query_Info_Carrier |
2469 | 2469 | */ |
2470 | - private function _extract_related_models_from_sub_params_array_keys($sub_query_params, EE_Model_Query_Info_Carrier $model_query_info_carrier,$query_param_type){ |
|
2471 | - if (!empty($sub_query_params)){ |
|
2470 | + private function _extract_related_models_from_sub_params_array_keys($sub_query_params, EE_Model_Query_Info_Carrier $model_query_info_carrier, $query_param_type) { |
|
2471 | + if ( ! empty($sub_query_params)) { |
|
2472 | 2472 | $sub_query_params = (array) $sub_query_params; |
2473 | - foreach($sub_query_params as $param => $possibly_array_of_params){ |
|
2473 | + foreach ($sub_query_params as $param => $possibly_array_of_params) { |
|
2474 | 2474 | //$param could be simply 'EVT_ID', or it could be 'Registrations.REG_ID', or even 'Registrations.Transactions.Payments.PAY_amount' |
2475 | - $this->_extract_related_model_info_from_query_param( $param, $model_query_info_carrier,$query_param_type); |
|
2475 | + $this->_extract_related_model_info_from_query_param($param, $model_query_info_carrier, $query_param_type); |
|
2476 | 2476 | |
2477 | 2477 | //if $possibly_array_of_params is an array, try recursing into it, searching for keys which |
2478 | 2478 | //indicate needed joins. Eg, array('NOT'=>array('Registration.TXN_ID'=>23)). In this case, we tried |
2479 | 2479 | //extracting models out of the 'NOT', which obviously wasn't successful, and then we recurse into the value |
2480 | 2480 | //of array('Registration.TXN_ID'=>23) |
2481 | 2481 | $query_param_sans_stars = $this->_remove_stars_and_anything_after_from_condition_query_param_key($param); |
2482 | - if(in_array($query_param_sans_stars, $this->_logic_query_param_keys,true)){ |
|
2483 | - if (! is_array($possibly_array_of_params)){ |
|
2482 | + if (in_array($query_param_sans_stars, $this->_logic_query_param_keys, true)) { |
|
2483 | + if ( ! is_array($possibly_array_of_params)) { |
|
2484 | 2484 | throw new EE_Error(sprintf(__("You used a special where query param %s, but the value isn't an array of where query params, it's just %s'. It should be an array, eg array('EVT_ID'=>23,'OR'=>array('Venue.VNU_ID'=>32,'Venue.VNU_name'=>'monkey_land'))", "event_espresso"), |
2485 | - $param,$possibly_array_of_params)); |
|
2486 | - }else{ |
|
2487 | - $this->_extract_related_models_from_sub_params_array_keys($possibly_array_of_params, $model_query_info_carrier,$query_param_type); |
|
2485 | + $param, $possibly_array_of_params)); |
|
2486 | + } else { |
|
2487 | + $this->_extract_related_models_from_sub_params_array_keys($possibly_array_of_params, $model_query_info_carrier, $query_param_type); |
|
2488 | 2488 | } |
2489 | - }elseif($query_param_type === 0 //ie WHERE |
|
2489 | + }elseif ($query_param_type === 0 //ie WHERE |
|
2490 | 2490 | && is_array($possibly_array_of_params) |
2491 | 2491 | && isset($possibly_array_of_params[2]) |
2492 | - && $possibly_array_of_params[2] == true){ |
|
2492 | + && $possibly_array_of_params[2] == true) { |
|
2493 | 2493 | //then $possible_array_of_params looks something like array('<','DTT_sold',true) |
2494 | 2494 | //indicating that $possible_array_of_params[1] is actually a field name, |
2495 | 2495 | //from which we should extract query parameters! |
2496 | - if(! isset($possibly_array_of_params[0]) || ! isset($possibly_array_of_params[1])){ |
|
2497 | - throw new EE_Error(sprintf(__("Improperly formed query parameter %s. It should be numerically indexed like array('<','DTT_sold',true); but you provided %s", "event_espresso"),$query_param_type,implode(",",$possibly_array_of_params))); |
|
2496 | + if ( ! isset($possibly_array_of_params[0]) || ! isset($possibly_array_of_params[1])) { |
|
2497 | + throw new EE_Error(sprintf(__("Improperly formed query parameter %s. It should be numerically indexed like array('<','DTT_sold',true); but you provided %s", "event_espresso"), $query_param_type, implode(",", $possibly_array_of_params))); |
|
2498 | 2498 | } |
2499 | 2499 | $this->_extract_related_model_info_from_query_param($possibly_array_of_params[1], $model_query_info_carrier, $query_param_type); |
2500 | 2500 | } |
@@ -2513,14 +2513,14 @@ discard block |
||
2513 | 2513 | * @throws EE_Error |
2514 | 2514 | * @return \EE_Model_Query_Info_Carrier |
2515 | 2515 | */ |
2516 | - private function _extract_related_models_from_sub_params_array_values($sub_query_params, EE_Model_Query_Info_Carrier $model_query_info_carrier,$query_param_type){ |
|
2517 | - if (!empty($sub_query_params)){ |
|
2518 | - if(!is_array($sub_query_params)){ |
|
2519 | - throw new EE_Error(sprintf(__("Query parameter %s should be an array, but it isn't.", "event_espresso"),$sub_query_params)); |
|
2516 | + private function _extract_related_models_from_sub_params_array_values($sub_query_params, EE_Model_Query_Info_Carrier $model_query_info_carrier, $query_param_type) { |
|
2517 | + if ( ! empty($sub_query_params)) { |
|
2518 | + if ( ! is_array($sub_query_params)) { |
|
2519 | + throw new EE_Error(sprintf(__("Query parameter %s should be an array, but it isn't.", "event_espresso"), $sub_query_params)); |
|
2520 | 2520 | } |
2521 | - foreach($sub_query_params as $param){ |
|
2521 | + foreach ($sub_query_params as $param) { |
|
2522 | 2522 | //$param could be simply 'EVT_ID', or it could be 'Registrations.REG_ID', or even 'Registrations.Transactions.Payments.PAY_amount' |
2523 | - $this->_extract_related_model_info_from_query_param( $param, $model_query_info_carrier, $query_param_type); |
|
2523 | + $this->_extract_related_model_info_from_query_param($param, $model_query_info_carrier, $query_param_type); |
|
2524 | 2524 | } |
2525 | 2525 | } |
2526 | 2526 | return $model_query_info_carrier; |
@@ -2539,81 +2539,81 @@ discard block |
||
2539 | 2539 | * @throws EE_Error |
2540 | 2540 | * @return EE_Model_Query_Info_Carrier |
2541 | 2541 | */ |
2542 | - function _create_model_query_info_carrier($query_params){ |
|
2543 | - if( ! is_array( $query_params ) ){ |
|
2544 | - EE_Error::doing_it_wrong('EEM_Base::_create_model_query_info_carrier', sprintf( __( '$query_params should be an array, you passed a variable of type %s', 'event_espresso' ), gettype( $query_params ) ), '4.6.0' ); |
|
2542 | + function _create_model_query_info_carrier($query_params) { |
|
2543 | + if ( ! is_array($query_params)) { |
|
2544 | + EE_Error::doing_it_wrong('EEM_Base::_create_model_query_info_carrier', sprintf(__('$query_params should be an array, you passed a variable of type %s', 'event_espresso'), gettype($query_params)), '4.6.0'); |
|
2545 | 2545 | $query_params = array(); |
2546 | 2546 | } |
2547 | - if( isset( $query_params[0] ) ) { |
|
2547 | + if (isset($query_params[0])) { |
|
2548 | 2548 | $where_query_params = $query_params[0]; |
2549 | - }else{ |
|
2549 | + } else { |
|
2550 | 2550 | $where_query_params = array(); |
2551 | 2551 | } |
2552 | 2552 | //first check if we should alter the query to account for caps or not |
2553 | 2553 | //because the caps might require us to do extra joins |
2554 | - if( isset( $query_params[ 'caps' ] ) && $query_params[ 'caps' ] != 'none' ) { |
|
2555 | - $query_params[0] = $where_query_params = array_replace_recursive( $where_query_params, $this->caps_where_conditions( $query_params[ 'caps' ] ) ); |
|
2554 | + if (isset($query_params['caps']) && $query_params['caps'] != 'none') { |
|
2555 | + $query_params[0] = $where_query_params = array_replace_recursive($where_query_params, $this->caps_where_conditions($query_params['caps'])); |
|
2556 | 2556 | } |
2557 | 2557 | $query_object = $this->_extract_related_models_from_query($query_params); |
2558 | 2558 | |
2559 | 2559 | //verify where_query_params has NO numeric indexes.... that's simply not how you use it! |
2560 | - foreach($where_query_params as $key => $value){ |
|
2561 | - if(is_int($key)){ |
|
2562 | - throw new EE_Error(sprintf(__("WHERE query params must NOT be numerically-indexed. You provided the array key '%s' for value '%s' while querying model %s. All the query params provided were '%s' Please read documentation on EEM_Base::get_all.", "event_espresso"),$key, var_export( $value, true ), var_export( $query_params, true ), get_class($this))); |
|
2560 | + foreach ($where_query_params as $key => $value) { |
|
2561 | + if (is_int($key)) { |
|
2562 | + throw new EE_Error(sprintf(__("WHERE query params must NOT be numerically-indexed. You provided the array key '%s' for value '%s' while querying model %s. All the query params provided were '%s' Please read documentation on EEM_Base::get_all.", "event_espresso"), $key, var_export($value, true), var_export($query_params, true), get_class($this))); |
|
2563 | 2563 | } |
2564 | 2564 | } |
2565 | - if( array_key_exists( 'default_where_conditions',$query_params) && ! empty( $query_params['default_where_conditions'] )){ |
|
2565 | + if (array_key_exists('default_where_conditions', $query_params) && ! empty($query_params['default_where_conditions'])) { |
|
2566 | 2566 | $use_default_where_conditions = $query_params['default_where_conditions']; |
2567 | - }else{ |
|
2567 | + } else { |
|
2568 | 2568 | $use_default_where_conditions = 'all'; |
2569 | 2569 | } |
2570 | - $where_query_params = array_merge($this->_get_default_where_conditions_for_models_in_query($query_object,$use_default_where_conditions,$where_query_params), $where_query_params ); |
|
2571 | - $query_object->set_where_sql( $this->_construct_where_clause($where_query_params)); |
|
2570 | + $where_query_params = array_merge($this->_get_default_where_conditions_for_models_in_query($query_object, $use_default_where_conditions, $where_query_params), $where_query_params); |
|
2571 | + $query_object->set_where_sql($this->_construct_where_clause($where_query_params)); |
|
2572 | 2572 | |
2573 | 2573 | |
2574 | 2574 | //if this is a "on_join_limit" then we are limiting on on a specific table in a multi_table join. So we need to setup a subquery and use that for the main join. Note for now this only works on the primary table for the model. So for instance, you could set the limit array like this: |
2575 | 2575 | //array( 'on_join_limit' => array('Primary_Table_Alias', array(1,10) ) ) |
2576 | - if ( array_key_exists('on_join_limit', $query_params ) && ! empty( $query_params['on_join_limit'] )) { |
|
2577 | - $query_object->set_main_model_join_sql( $this->_construct_limit_join_select( $query_params['on_join_limit'][0], $query_params['on_join_limit'][1] ) ); |
|
2576 | + if (array_key_exists('on_join_limit', $query_params) && ! empty($query_params['on_join_limit'])) { |
|
2577 | + $query_object->set_main_model_join_sql($this->_construct_limit_join_select($query_params['on_join_limit'][0], $query_params['on_join_limit'][1])); |
|
2578 | 2578 | } |
2579 | 2579 | |
2580 | 2580 | |
2581 | 2581 | //set limit |
2582 | - if(array_key_exists('limit',$query_params)){ |
|
2583 | - if(is_array($query_params['limit'])){ |
|
2584 | - if( ! isset($query_params['limit'][0]) || ! isset($query_params['limit'][1])){ |
|
2585 | - $e = sprintf(__("Invalid DB query. You passed '%s' for the LIMIT, but only the following are valid: an integer, string representing an integer, a string like 'int,int', or an array like array(int,int)", "event_espresso"), http_build_query($query_params['limit'])); |
|
2582 | + if (array_key_exists('limit', $query_params)) { |
|
2583 | + if (is_array($query_params['limit'])) { |
|
2584 | + if ( ! isset($query_params['limit'][0]) || ! isset($query_params['limit'][1])) { |
|
2585 | + $e = sprintf(__("Invalid DB query. You passed '%s' for the LIMIT, but only the following are valid: an integer, string representing an integer, a string like 'int,int', or an array like array(int,int)", "event_espresso"), http_build_query($query_params['limit'])); |
|
2586 | 2586 | throw new EE_Error($e."|".$e); |
2587 | 2587 | } |
2588 | 2588 | //they passed us an array for the limit. Assume it's like array(50,25), meaning offset by 50, and get 25 |
2589 | 2589 | $query_object->set_limit_sql(" LIMIT ".$query_params['limit'][0].",".$query_params['limit'][1]); |
2590 | - }elseif( ! empty ( $query_params['limit'] )){ |
|
2590 | + }elseif ( ! empty ($query_params['limit'])) { |
|
2591 | 2591 | $query_object->set_limit_sql((" LIMIT ".$query_params['limit'])); |
2592 | 2592 | } |
2593 | 2593 | } |
2594 | 2594 | //set order by |
2595 | - if(array_key_exists('order_by',$query_params)){ |
|
2596 | - if(is_array($query_params['order_by'])){ |
|
2595 | + if (array_key_exists('order_by', $query_params)) { |
|
2596 | + if (is_array($query_params['order_by'])) { |
|
2597 | 2597 | //if they're using 'order_by' as an array, they can't use 'order' (because 'order_by' must |
2598 | 2598 | //specify whether to ascend or descend on each field. Eg 'order_by'=>array('EVT_ID'=>'ASC'). So |
2599 | 2599 | //including 'order' wouldn't make any sense if 'order_by' has already specified which way to order! |
2600 | - if(array_key_exists('order', $query_params)){ |
|
2600 | + if (array_key_exists('order', $query_params)) { |
|
2601 | 2601 | throw new EE_Error(sprintf(__("In querying %s, we are using query parameter 'order_by' as an array (keys:%s,values:%s), and so we can't use query parameter 'order' (value %s). You should just use the 'order_by' parameter ", "event_espresso"), |
2602 | - get_class($this),implode(", ",array_keys($query_params['order_by'])),implode(", ",$query_params['order_by']),$query_params['order'])); |
|
2602 | + get_class($this), implode(", ", array_keys($query_params['order_by'])), implode(", ", $query_params['order_by']), $query_params['order'])); |
|
2603 | 2603 | } |
2604 | - $this->_extract_related_models_from_sub_params_array_keys($query_params['order_by'],$query_object,'order_by'); |
|
2604 | + $this->_extract_related_models_from_sub_params_array_keys($query_params['order_by'], $query_object, 'order_by'); |
|
2605 | 2605 | //assume it's an array of fields to order by |
2606 | 2606 | $order_array = array(); |
2607 | - foreach($query_params['order_by'] as $field_name_to_order_by => $order){ |
|
2607 | + foreach ($query_params['order_by'] as $field_name_to_order_by => $order) { |
|
2608 | 2608 | $order = $this->_extract_order($order); |
2609 | 2609 | $order_array[] = $this->_deduce_column_name_from_query_param($field_name_to_order_by).SP.$order; |
2610 | 2610 | } |
2611 | - $query_object->set_order_by_sql(" ORDER BY ".implode(",",$order_array)); |
|
2612 | - }elseif( ! empty ( $query_params['order_by'] )){ |
|
2613 | - $this->_extract_related_model_info_from_query_param($query_params['order_by'],$query_object,'order',$query_params['order_by']); |
|
2614 | - if(isset($query_params['order'])){ |
|
2611 | + $query_object->set_order_by_sql(" ORDER BY ".implode(",", $order_array)); |
|
2612 | + }elseif ( ! empty ($query_params['order_by'])) { |
|
2613 | + $this->_extract_related_model_info_from_query_param($query_params['order_by'], $query_object, 'order', $query_params['order_by']); |
|
2614 | + if (isset($query_params['order'])) { |
|
2615 | 2615 | $order = $this->_extract_order($query_params['order']); |
2616 | - }else{ |
|
2616 | + } else { |
|
2617 | 2617 | $order = 'DESC'; |
2618 | 2618 | } |
2619 | 2619 | $query_object->set_order_by_sql(" ORDER BY ".$this->_deduce_column_name_from_query_param($query_params['order_by']).SP.$order); |
@@ -2621,46 +2621,46 @@ discard block |
||
2621 | 2621 | } |
2622 | 2622 | |
2623 | 2623 | //if 'order_by' wasn't set, maybe they are just using 'order' on its own? |
2624 | - if( ! array_key_exists('order_by',$query_params) && array_key_exists('order',$query_params) && ! empty( $query_params['order'] )){ |
|
2624 | + if ( ! array_key_exists('order_by', $query_params) && array_key_exists('order', $query_params) && ! empty($query_params['order'])) { |
|
2625 | 2625 | $pk_field = $this->get_primary_key_field(); |
2626 | 2626 | $order = $this->_extract_order($query_params['order']); |
2627 | 2627 | $query_object->set_order_by_sql(" ORDER BY ".$pk_field->get_qualified_column().SP.$order); |
2628 | 2628 | } |
2629 | 2629 | |
2630 | 2630 | //set group by |
2631 | - if(array_key_exists('group_by',$query_params)){ |
|
2632 | - if(is_array($query_params['group_by'])){ |
|
2631 | + if (array_key_exists('group_by', $query_params)) { |
|
2632 | + if (is_array($query_params['group_by'])) { |
|
2633 | 2633 | //it's an array, so assume we'll be grouping by a bunch of stuff |
2634 | 2634 | $group_by_array = array(); |
2635 | - foreach($query_params['group_by'] as $field_name_to_group_by){ |
|
2635 | + foreach ($query_params['group_by'] as $field_name_to_group_by) { |
|
2636 | 2636 | $group_by_array[] = $this->_deduce_column_name_from_query_param($field_name_to_group_by); |
2637 | 2637 | } |
2638 | - $query_object->set_group_by_sql(" GROUP BY ".implode(", ",$group_by_array)); |
|
2639 | - }elseif( ! empty ( $query_params['group_by'] )){ |
|
2638 | + $query_object->set_group_by_sql(" GROUP BY ".implode(", ", $group_by_array)); |
|
2639 | + }elseif ( ! empty ($query_params['group_by'])) { |
|
2640 | 2640 | $query_object->set_group_by_sql(" GROUP BY ".$this->_deduce_column_name_from_query_param($query_params['group_by'])); |
2641 | 2641 | } |
2642 | 2642 | } |
2643 | 2643 | //set having |
2644 | - if(array_key_exists('having',$query_params) && $query_params['having']){ |
|
2645 | - $query_object->set_having_sql( $this->_construct_having_clause($query_params['having'])); |
|
2644 | + if (array_key_exists('having', $query_params) && $query_params['having']) { |
|
2645 | + $query_object->set_having_sql($this->_construct_having_clause($query_params['having'])); |
|
2646 | 2646 | } |
2647 | 2647 | |
2648 | 2648 | //now, just verify they didn't pass anything wack |
2649 | - foreach($query_params as $query_key => $query_value){ |
|
2650 | - if( ! in_array($query_key,$this->_allowed_query_params,true)){ |
|
2649 | + foreach ($query_params as $query_key => $query_value) { |
|
2650 | + if ( ! in_array($query_key, $this->_allowed_query_params, true)) { |
|
2651 | 2651 | throw new EE_Error( |
2652 | 2652 | sprintf( |
2653 | - __("You passed %s as a query parameter to %s, which is illegal! The allowed query parameters are %s",'event_espresso'), |
|
2653 | + __("You passed %s as a query parameter to %s, which is illegal! The allowed query parameters are %s", 'event_espresso'), |
|
2654 | 2654 | $query_key, |
2655 | 2655 | get_class($this), |
2656 | 2656 | // print_r( $this->_allowed_query_params, TRUE ) |
2657 | - implode( ',', $this->_allowed_query_params ) |
|
2657 | + implode(',', $this->_allowed_query_params) |
|
2658 | 2658 | ) |
2659 | 2659 | ); |
2660 | 2660 | } |
2661 | 2661 | } |
2662 | 2662 | $main_model_join_sql = $query_object->get_main_model_join_sql(); |
2663 | - if ( empty( $main_model_join_sql ) ) |
|
2663 | + if (empty($main_model_join_sql)) |
|
2664 | 2664 | $query_object->set_main_model_join_sql($this->_construct_internal_join()); |
2665 | 2665 | return $query_object; |
2666 | 2666 | } |
@@ -2671,17 +2671,17 @@ discard block |
||
2671 | 2671 | * @param string $context one of EEM_Base::valid_cap_contexts() |
2672 | 2672 | * @return array like EEM_Base::get_all() 's $query_params[0] |
2673 | 2673 | */ |
2674 | - public function caps_where_conditions( $context = self::caps_read ) { |
|
2675 | - EEM_Base::verify_is_valid_cap_context( $context ); |
|
2674 | + public function caps_where_conditions($context = self::caps_read) { |
|
2675 | + EEM_Base::verify_is_valid_cap_context($context); |
|
2676 | 2676 | $cap_where_conditions = array(); |
2677 | - $cap_restrictions = $this->caps_missing( $context ); |
|
2677 | + $cap_restrictions = $this->caps_missing($context); |
|
2678 | 2678 | /** |
2679 | 2679 | * @var $cap_restrictions EE_Default_Where_Conditions[] |
2680 | 2680 | */ |
2681 | - foreach( $cap_restrictions as $cap => $restriction_if_no_cap ) { |
|
2682 | - $cap_where_conditions = array_replace_recursive( $cap_where_conditions, $restriction_if_no_cap->get_default_where_conditions() ); |
|
2681 | + foreach ($cap_restrictions as $cap => $restriction_if_no_cap) { |
|
2682 | + $cap_where_conditions = array_replace_recursive($cap_where_conditions, $restriction_if_no_cap->get_default_where_conditions()); |
|
2683 | 2683 | } |
2684 | - return apply_filters( 'FHEE__EEM_Base__caps_where_conditions__return', $cap_where_conditions, $this, $context, $cap_restrictions ); |
|
2684 | + return apply_filters('FHEE__EEM_Base__caps_where_conditions__return', $cap_where_conditions, $this, $context, $cap_restrictions); |
|
2685 | 2685 | } |
2686 | 2686 | |
2687 | 2687 | /** |
@@ -2691,11 +2691,11 @@ discard block |
||
2691 | 2691 | * @return string either ASC, asc, DESC or desc |
2692 | 2692 | * @throws EE_Error |
2693 | 2693 | */ |
2694 | - private function _extract_order($should_be_order_string){ |
|
2695 | - if(in_array($should_be_order_string, $this->_allowed_order_values)){ |
|
2694 | + private function _extract_order($should_be_order_string) { |
|
2695 | + if (in_array($should_be_order_string, $this->_allowed_order_values)) { |
|
2696 | 2696 | return $should_be_order_string; |
2697 | - }else{ |
|
2698 | - throw new EE_Error(sprintf(__("While performing a query on '%s', tried to use '%s' as an order parameter. ", "event_espresso"),get_class($this),$should_be_order_string)); |
|
2697 | + } else { |
|
2698 | + throw new EE_Error(sprintf(__("While performing a query on '%s', tried to use '%s' as an order parameter. ", "event_espresso"), get_class($this), $should_be_order_string)); |
|
2699 | 2699 | } |
2700 | 2700 | } |
2701 | 2701 | |
@@ -2713,19 +2713,19 @@ discard block |
||
2713 | 2713 | * @throws EE_Error |
2714 | 2714 | * @return array like $query_params[0], see EEM_Base::get_all for documentation |
2715 | 2715 | */ |
2716 | - private function _get_default_where_conditions_for_models_in_query(EE_Model_Query_Info_Carrier $query_info_carrier,$use_default_where_conditions = 'all',$where_query_params = array()){ |
|
2717 | - $allowed_used_default_where_conditions_values = array('all','this_model_only', 'other_models_only','none'); |
|
2718 | - if( ! in_array($use_default_where_conditions,$allowed_used_default_where_conditions_values)){ |
|
2719 | - throw new EE_Error(sprintf(__("You passed an invalid value to the query parameter 'default_where_conditions' of '%s'. Allowed values are %s", "event_espresso"),$use_default_where_conditions,implode(", ",$allowed_used_default_where_conditions_values))); |
|
2716 | + private function _get_default_where_conditions_for_models_in_query(EE_Model_Query_Info_Carrier $query_info_carrier, $use_default_where_conditions = 'all', $where_query_params = array()) { |
|
2717 | + $allowed_used_default_where_conditions_values = array('all', 'this_model_only', 'other_models_only', 'none'); |
|
2718 | + if ( ! in_array($use_default_where_conditions, $allowed_used_default_where_conditions_values)) { |
|
2719 | + throw new EE_Error(sprintf(__("You passed an invalid value to the query parameter 'default_where_conditions' of '%s'. Allowed values are %s", "event_espresso"), $use_default_where_conditions, implode(", ", $allowed_used_default_where_conditions_values))); |
|
2720 | 2720 | } |
2721 | - if( in_array($use_default_where_conditions, array('all','this_model_only')) ){ |
|
2721 | + if (in_array($use_default_where_conditions, array('all', 'this_model_only'))) { |
|
2722 | 2722 | $universal_query_params = $this->_get_default_where_conditions(); |
2723 | - }else{ |
|
2723 | + } else { |
|
2724 | 2724 | $universal_query_params = array(); |
2725 | 2725 | } |
2726 | 2726 | |
2727 | - if(in_array($use_default_where_conditions,array('all','other_models_only'))){ |
|
2728 | - foreach($query_info_carrier->get_model_names_included() as $model_relation_path => $model_name){ |
|
2727 | + if (in_array($use_default_where_conditions, array('all', 'other_models_only'))) { |
|
2728 | + foreach ($query_info_carrier->get_model_names_included() as $model_relation_path => $model_name) { |
|
2729 | 2729 | $related_model = $this->get_related_model_obj($model_name); |
2730 | 2730 | $related_model_universal_where_params = $related_model->_get_default_where_conditions($model_relation_path); |
2731 | 2731 | |
@@ -2752,22 +2752,22 @@ discard block |
||
2752 | 2752 | * @param string $model_relation_path like 'Transaction.Payment.' |
2753 | 2753 | * @return array like EEM_Base::get_all's $query_params[0] |
2754 | 2754 | */ |
2755 | - private function _override_defaults_or_make_null_friendly($default_where_conditions,$provided_where_conditions,$model,$model_relation_path){ |
|
2755 | + private function _override_defaults_or_make_null_friendly($default_where_conditions, $provided_where_conditions, $model, $model_relation_path) { |
|
2756 | 2756 | $null_friendly_where_conditions = array(); |
2757 | 2757 | $none_overridden = true; |
2758 | 2758 | $or_condition_key_for_defaults = 'OR*'.get_class($model); |
2759 | 2759 | |
2760 | - foreach($default_where_conditions as $key => $val){ |
|
2761 | - if( isset($provided_where_conditions[$key])){ |
|
2760 | + foreach ($default_where_conditions as $key => $val) { |
|
2761 | + if (isset($provided_where_conditions[$key])) { |
|
2762 | 2762 | $none_overridden = false; |
2763 | - }else{ |
|
2763 | + } else { |
|
2764 | 2764 | $null_friendly_where_conditions[$or_condition_key_for_defaults]['AND'][$key] = $val; |
2765 | 2765 | } |
2766 | 2766 | } |
2767 | - if( $none_overridden && $default_where_conditions){ |
|
2768 | - if($model->has_primary_key_field()){ |
|
2767 | + if ($none_overridden && $default_where_conditions) { |
|
2768 | + if ($model->has_primary_key_field()) { |
|
2769 | 2769 | $null_friendly_where_conditions[$or_condition_key_for_defaults][$model_relation_path.".".$model->primary_key_name()] = array('IS NULL'); |
2770 | - }else{ |
|
2770 | + } else { |
|
2771 | 2771 | //@todo NO PK, use other defaults |
2772 | 2772 | } |
2773 | 2773 | } |
@@ -2782,8 +2782,8 @@ discard block |
||
2782 | 2782 | * @param string $model_relation_path eg, path from Event to Payment is "Registration.Transaction.Payment." |
2783 | 2783 | * @return array like EEM_Base::get_all's $query_params[0] (where conditions) |
2784 | 2784 | */ |
2785 | - private function _get_default_where_conditions($model_relation_path = null){ |
|
2786 | - if ( $this->_ignore_where_strategy ) |
|
2785 | + private function _get_default_where_conditions($model_relation_path = null) { |
|
2786 | + if ($this->_ignore_where_strategy) |
|
2787 | 2787 | return array(); |
2788 | 2788 | |
2789 | 2789 | return $this->_default_where_conditions_strategy->get_default_where_conditions($model_relation_path); |
@@ -2794,13 +2794,13 @@ discard block |
||
2794 | 2794 | * @param EE_Model_Query_Info_Carrier $model_query_info |
2795 | 2795 | * @return string |
2796 | 2796 | */ |
2797 | - private function _construct_default_select_sql(EE_Model_Query_Info_Carrier $model_query_info){ |
|
2797 | + private function _construct_default_select_sql(EE_Model_Query_Info_Carrier $model_query_info) { |
|
2798 | 2798 | $selects = $this->_get_columns_to_select_for_this_model(); |
2799 | - foreach($model_query_info->get_model_names_included() as $model_relation_chain => $name_of_other_model_included){ |
|
2799 | + foreach ($model_query_info->get_model_names_included() as $model_relation_chain => $name_of_other_model_included) { |
|
2800 | 2800 | $other_model_included = $this->get_related_model_obj($name_of_other_model_included); |
2801 | 2801 | $selects = array_merge($selects, $other_model_included->_get_columns_to_select_for_this_model($model_relation_chain)); |
2802 | 2802 | } |
2803 | - return implode(", ",$selects); |
|
2803 | + return implode(", ", $selects); |
|
2804 | 2804 | } |
2805 | 2805 | |
2806 | 2806 | /** |
@@ -2809,19 +2809,19 @@ discard block |
||
2809 | 2809 | * @param string $model_relation_chain like 'Question.Question_Group.Event' |
2810 | 2810 | * @return array numerically indexed, values are columns to select and rename, eg "Event.ID AS 'Event.ID'" |
2811 | 2811 | */ |
2812 | - public function _get_columns_to_select_for_this_model($model_relation_chain = ''){ |
|
2812 | + public function _get_columns_to_select_for_this_model($model_relation_chain = '') { |
|
2813 | 2813 | $fields = $this->field_settings(); |
2814 | 2814 | $selects = array(); |
2815 | 2815 | $table_alias_with_model_relation_chain_prefix = EE_Model_Parser::extract_table_alias_model_relation_chain_prefix($model_relation_chain, $this->get_this_model_name()); |
2816 | - foreach($fields as $field_obj){ |
|
2817 | - $selects[] = $table_alias_with_model_relation_chain_prefix . $field_obj->get_table_alias().".".$field_obj->get_table_column()." AS '".$table_alias_with_model_relation_chain_prefix.$field_obj->get_table_alias().".".$field_obj->get_table_column()."'"; |
|
2816 | + foreach ($fields as $field_obj) { |
|
2817 | + $selects[] = $table_alias_with_model_relation_chain_prefix.$field_obj->get_table_alias().".".$field_obj->get_table_column()." AS '".$table_alias_with_model_relation_chain_prefix.$field_obj->get_table_alias().".".$field_obj->get_table_column()."'"; |
|
2818 | 2818 | } |
2819 | 2819 | //make sure we are also getting the PKs of each table |
2820 | 2820 | $tables = $this->get_tables(); |
2821 | - if(count($tables) > 1){ |
|
2822 | - foreach($tables as $table_obj){ |
|
2823 | - $qualified_pk_column = $table_alias_with_model_relation_chain_prefix . $table_obj->get_fully_qualified_pk_column(); |
|
2824 | - if( ! in_array($qualified_pk_column,$selects)){ |
|
2821 | + if (count($tables) > 1) { |
|
2822 | + foreach ($tables as $table_obj) { |
|
2823 | + $qualified_pk_column = $table_alias_with_model_relation_chain_prefix.$table_obj->get_fully_qualified_pk_column(); |
|
2824 | + if ( ! in_array($qualified_pk_column, $selects)) { |
|
2825 | 2825 | $selects[] = "$qualified_pk_column AS '$qualified_pk_column'"; |
2826 | 2826 | } |
2827 | 2827 | } |
@@ -2845,66 +2845,66 @@ discard block |
||
2845 | 2845 | * @throws EE_Error |
2846 | 2846 | * @return void only modifies the EEM_Related_Model_Info_Carrier passed into it |
2847 | 2847 | */ |
2848 | - private function _extract_related_model_info_from_query_param( $query_param, EE_Model_Query_Info_Carrier $passed_in_query_info, $query_param_type, $original_query_param = NULL ){ |
|
2849 | - if($original_query_param == NULL){ |
|
2848 | + private function _extract_related_model_info_from_query_param($query_param, EE_Model_Query_Info_Carrier $passed_in_query_info, $query_param_type, $original_query_param = NULL) { |
|
2849 | + if ($original_query_param == NULL) { |
|
2850 | 2850 | $original_query_param = $query_param; |
2851 | 2851 | } |
2852 | 2852 | $query_param = $this->_remove_stars_and_anything_after_from_condition_query_param_key($query_param); |
2853 | 2853 | /** @var $allow_logic_query_params bool whether or not to allow logic_query_params like 'NOT','OR', or 'AND' */ |
2854 | - $allow_logic_query_params = in_array($query_param_type,array('where','having')); |
|
2855 | - $allow_fields = in_array($query_param_type,array('where','having','order_by','group_by','order')); |
|
2854 | + $allow_logic_query_params = in_array($query_param_type, array('where', 'having')); |
|
2855 | + $allow_fields = in_array($query_param_type, array('where', 'having', 'order_by', 'group_by', 'order')); |
|
2856 | 2856 | //check to see if we have a field on this model |
2857 | 2857 | $this_model_fields = $this->field_settings(true); |
2858 | - if(array_key_exists($query_param,$this_model_fields)){ |
|
2859 | - if($allow_fields){ |
|
2858 | + if (array_key_exists($query_param, $this_model_fields)) { |
|
2859 | + if ($allow_fields) { |
|
2860 | 2860 | return; |
2861 | - }else{ |
|
2861 | + } else { |
|
2862 | 2862 | throw new EE_Error(sprintf(__("Using a field name (%s) on model %s is not allowed on this query param type '%s'. Original query param was %s", "event_espresso"), |
2863 | - $query_param,get_class($this),$query_param_type,$original_query_param)); |
|
2863 | + $query_param, get_class($this), $query_param_type, $original_query_param)); |
|
2864 | 2864 | } |
2865 | 2865 | } |
2866 | 2866 | //check if this is a special logic query param |
2867 | - elseif(in_array($query_param, $this->_logic_query_param_keys, TRUE)){ |
|
2868 | - if($allow_logic_query_params){ |
|
2867 | + elseif (in_array($query_param, $this->_logic_query_param_keys, TRUE)) { |
|
2868 | + if ($allow_logic_query_params) { |
|
2869 | 2869 | return; |
2870 | - }else{ |
|
2870 | + } else { |
|
2871 | 2871 | throw new EE_Error( |
2872 | 2872 | sprintf( |
2873 | - __( 'Logic query params ("%1$s") are being used incorrectly with the following query param ("%2$s") on model %3$s. %4$sAdditional Info:%4$s%5$s', 'event_espresso' ), |
|
2874 | - implode( '", "', $this->_logic_query_param_keys ), |
|
2875 | - $query_param , |
|
2876 | - get_class( $this ), |
|
2873 | + __('Logic query params ("%1$s") are being used incorrectly with the following query param ("%2$s") on model %3$s. %4$sAdditional Info:%4$s%5$s', 'event_espresso'), |
|
2874 | + implode('", "', $this->_logic_query_param_keys), |
|
2875 | + $query_param, |
|
2876 | + get_class($this), |
|
2877 | 2877 | '<br />', |
2878 | - "\t" . ' $passed_in_query_info = <pre>' . print_r( $passed_in_query_info, TRUE ) . '</pre>' . "\n\t" . ' $query_param_type = ' . $query_param_type . "\n\t" . ' $original_query_param = ' . $original_query_param |
|
2878 | + "\t".' $passed_in_query_info = <pre>'.print_r($passed_in_query_info, TRUE).'</pre>'."\n\t".' $query_param_type = '.$query_param_type."\n\t".' $original_query_param = '.$original_query_param |
|
2879 | 2879 | ) |
2880 | 2880 | ); |
2881 | 2881 | } |
2882 | 2882 | } |
2883 | 2883 | |
2884 | 2884 | //check if it's a custom selection |
2885 | - elseif(array_key_exists($query_param,$this->_custom_selections)){ |
|
2885 | + elseif (array_key_exists($query_param, $this->_custom_selections)) { |
|
2886 | 2886 | return; |
2887 | 2887 | } |
2888 | 2888 | |
2889 | 2889 | //check if has a model name at the beginning |
2890 | 2890 | //and |
2891 | 2891 | //check if it's a field on a related model |
2892 | - foreach($this->_model_relations as $valid_related_model_name=>$relation_obj){ |
|
2893 | - if(strpos($query_param, $valid_related_model_name.".") === 0){ |
|
2894 | - $this->_add_join_to_model($valid_related_model_name, $passed_in_query_info,$original_query_param); |
|
2892 | + foreach ($this->_model_relations as $valid_related_model_name=>$relation_obj) { |
|
2893 | + if (strpos($query_param, $valid_related_model_name.".") === 0) { |
|
2894 | + $this->_add_join_to_model($valid_related_model_name, $passed_in_query_info, $original_query_param); |
|
2895 | 2895 | $query_param = substr($query_param, strlen($valid_related_model_name.".")); |
2896 | - if($query_param == ''){ |
|
2896 | + if ($query_param == '') { |
|
2897 | 2897 | //nothing left to $query_param |
2898 | 2898 | //we should actually end in a field name, not a model like this! |
2899 | 2899 | throw new EE_Error(sprintf(__("Query param '%s' (of type %s on model %s) shouldn't end on a period (.) ", "event_espresso"), |
2900 | - $query_param,$query_param_type,get_class($this),$valid_related_model_name)); |
|
2901 | - }else{ |
|
2900 | + $query_param, $query_param_type, get_class($this), $valid_related_model_name)); |
|
2901 | + } else { |
|
2902 | 2902 | $related_model_obj = $this->get_related_model_obj($valid_related_model_name); |
2903 | 2903 | $related_model_obj->_extract_related_model_info_from_query_param($query_param, $passed_in_query_info, $query_param_type, $original_query_param); |
2904 | 2904 | return; |
2905 | 2905 | } |
2906 | - }elseif($query_param == $valid_related_model_name){ |
|
2907 | - $this->_add_join_to_model($valid_related_model_name, $passed_in_query_info,$original_query_param); |
|
2906 | + }elseif ($query_param == $valid_related_model_name) { |
|
2907 | + $this->_add_join_to_model($valid_related_model_name, $passed_in_query_info, $original_query_param); |
|
2908 | 2908 | return; |
2909 | 2909 | } |
2910 | 2910 | } |
@@ -2914,7 +2914,7 @@ discard block |
||
2914 | 2914 | //and we previously confirmed it wasn't a logic query param or field on the current model |
2915 | 2915 | //it's wack, that's what it is |
2916 | 2916 | throw new EE_Error(sprintf(__("There is no model named '%s' related to %s. Query param type is %s and original query param is %s", "event_espresso"), |
2917 | - $query_param,get_class($this),$query_param_type,$original_query_param)); |
|
2917 | + $query_param, get_class($this), $query_param_type, $original_query_param)); |
|
2918 | 2918 | |
2919 | 2919 | } |
2920 | 2920 | |
@@ -2931,26 +2931,26 @@ discard block |
||
2931 | 2931 | * what models to prepend onto its default query params or in case it wants to rename tables (in case there are multiple joins to the same table) |
2932 | 2932 | * @return void |
2933 | 2933 | */ |
2934 | - private function _add_join_to_model($model_name, EE_Model_Query_Info_Carrier $passed_in_query_info,$original_query_param){ |
|
2934 | + private function _add_join_to_model($model_name, EE_Model_Query_Info_Carrier $passed_in_query_info, $original_query_param) { |
|
2935 | 2935 | $relation_obj = $this->related_settings_for($model_name); |
2936 | 2936 | |
2937 | 2937 | $model_relation_chain = EE_Model_Parser::extract_model_relation_chain($model_name, $original_query_param); |
2938 | 2938 | //check if the relation is HABTM, because then we're essentially doing two joins |
2939 | 2939 | //If so, join first to the JOIN table, and add its data types, and then continue as normal |
2940 | - if($relation_obj instanceof EE_HABTM_Relation){ |
|
2940 | + if ($relation_obj instanceof EE_HABTM_Relation) { |
|
2941 | 2941 | $join_model_obj = $relation_obj->get_join_model(); |
2942 | 2942 | //replace the model specified with the join model for this relation chain, whi |
2943 | 2943 | $relation_chain_to_join_model = EE_Model_Parser::replace_model_name_with_join_model_name_in_model_relation_chain($model_name, $join_model_obj->get_this_model_name(), $model_relation_chain); |
2944 | 2944 | $new_query_info = new EE_Model_Query_Info_Carrier( |
2945 | 2945 | array($relation_chain_to_join_model => $join_model_obj->get_this_model_name()), |
2946 | 2946 | $relation_obj->get_join_to_intermediate_model_statement($relation_chain_to_join_model)); |
2947 | - $passed_in_query_info->merge( $new_query_info ); |
|
2947 | + $passed_in_query_info->merge($new_query_info); |
|
2948 | 2948 | } |
2949 | 2949 | //now just join to the other table pointed to by the relation object, and add its data types |
2950 | 2950 | $new_query_info = new EE_Model_Query_Info_Carrier( |
2951 | 2951 | array($model_relation_chain=>$model_name), |
2952 | 2952 | $relation_obj->get_join_statement($model_relation_chain)); |
2953 | - $passed_in_query_info->merge( $new_query_info ); |
|
2953 | + $passed_in_query_info->merge($new_query_info); |
|
2954 | 2954 | } |
2955 | 2955 | |
2956 | 2956 | |
@@ -2959,11 +2959,11 @@ discard block |
||
2959 | 2959 | * @param array $where_params like EEM_Base::get_all |
2960 | 2960 | * @return string of SQL |
2961 | 2961 | */ |
2962 | - private function _construct_where_clause($where_params){ |
|
2962 | + private function _construct_where_clause($where_params) { |
|
2963 | 2963 | $SQL = $this->_construct_condition_clause_recursive($where_params, ' AND '); |
2964 | - if($SQL){ |
|
2965 | - return " WHERE ". $SQL; |
|
2966 | - }else{ |
|
2964 | + if ($SQL) { |
|
2965 | + return " WHERE ".$SQL; |
|
2966 | + } else { |
|
2967 | 2967 | return ''; |
2968 | 2968 | } |
2969 | 2969 | } |
@@ -2974,11 +2974,11 @@ discard block |
||
2974 | 2974 | * @param array $having_params |
2975 | 2975 | * @return string |
2976 | 2976 | */ |
2977 | - private function _construct_having_clause($having_params){ |
|
2977 | + private function _construct_having_clause($having_params) { |
|
2978 | 2978 | $SQL = $this->_construct_condition_clause_recursive($having_params, ' AND '); |
2979 | - if($SQL){ |
|
2980 | - return " HAVING ". $SQL; |
|
2981 | - }else{ |
|
2979 | + if ($SQL) { |
|
2980 | + return " HAVING ".$SQL; |
|
2981 | + } else { |
|
2982 | 2982 | return ''; |
2983 | 2983 | } |
2984 | 2984 | |
@@ -2992,17 +2992,17 @@ discard block |
||
2992 | 2992 | * @return EE_Model_Field_Base |
2993 | 2993 | * @throws EE_Error |
2994 | 2994 | */ |
2995 | - protected function _get_field_on_model($field_name,$model_name){ |
|
2995 | + protected function _get_field_on_model($field_name, $model_name) { |
|
2996 | 2996 | $model_class = 'EEM_'.$model_name; |
2997 | 2997 | $model_filepath = $model_class.".model.php"; |
2998 | - EE_Registry::instance()->load_helper( 'File' ); |
|
2999 | - if ( is_readable($model_filepath)){ |
|
2998 | + EE_Registry::instance()->load_helper('File'); |
|
2999 | + if (is_readable($model_filepath)) { |
|
3000 | 3000 | require_once($model_filepath); |
3001 | - $model_instance=call_user_func($model_name."::instance"); |
|
3001 | + $model_instance = call_user_func($model_name."::instance"); |
|
3002 | 3002 | /* @var $model_instance EEM_Base */ |
3003 | 3003 | return $model_instance->field_settings_for($field_name); |
3004 | - }else{ |
|
3005 | - throw new EE_Error(sprintf(__('No model named %s exists, with classname %s and filepath %s','event_espresso'),$model_name,$model_class,$model_filepath)); |
|
3004 | + } else { |
|
3005 | + throw new EE_Error(sprintf(__('No model named %s exists, with classname %s and filepath %s', 'event_espresso'), $model_name, $model_class, $model_filepath)); |
|
3006 | 3006 | } |
3007 | 3007 | } |
3008 | 3008 | |
@@ -3015,43 +3015,43 @@ discard block |
||
3015 | 3015 | * @throws EE_Error |
3016 | 3016 | * @return string of SQL |
3017 | 3017 | */ |
3018 | - private function _construct_condition_clause_recursive($where_params, $glue = ' AND'){ |
|
3019 | - $where_clauses=array(); |
|
3020 | - foreach($where_params as $query_param => $op_and_value_or_sub_condition){ |
|
3021 | - $query_param = $this->_remove_stars_and_anything_after_from_condition_query_param_key($query_param);//str_replace("*",'',$query_param); |
|
3022 | - if(in_array($query_param,$this->_logic_query_param_keys)){ |
|
3023 | - switch($query_param){ |
|
3018 | + private function _construct_condition_clause_recursive($where_params, $glue = ' AND') { |
|
3019 | + $where_clauses = array(); |
|
3020 | + foreach ($where_params as $query_param => $op_and_value_or_sub_condition) { |
|
3021 | + $query_param = $this->_remove_stars_and_anything_after_from_condition_query_param_key($query_param); //str_replace("*",'',$query_param); |
|
3022 | + if (in_array($query_param, $this->_logic_query_param_keys)) { |
|
3023 | + switch ($query_param) { |
|
3024 | 3024 | case 'not': |
3025 | 3025 | case 'NOT': |
3026 | - $where_clauses[] = "! (". $this->_construct_condition_clause_recursive($op_and_value_or_sub_condition, $glue).")"; |
|
3026 | + $where_clauses[] = "! (".$this->_construct_condition_clause_recursive($op_and_value_or_sub_condition, $glue).")"; |
|
3027 | 3027 | break; |
3028 | 3028 | case 'and': |
3029 | 3029 | case 'AND': |
3030 | - $where_clauses[] = " (". $this->_construct_condition_clause_recursive($op_and_value_or_sub_condition, ' AND ') .")"; |
|
3030 | + $where_clauses[] = " (".$this->_construct_condition_clause_recursive($op_and_value_or_sub_condition, ' AND ').")"; |
|
3031 | 3031 | break; |
3032 | 3032 | case 'or': |
3033 | 3033 | case 'OR': |
3034 | - $where_clauses[] = " (". $this->_construct_condition_clause_recursive($op_and_value_or_sub_condition, ' OR ') .")"; |
|
3034 | + $where_clauses[] = " (".$this->_construct_condition_clause_recursive($op_and_value_or_sub_condition, ' OR ').")"; |
|
3035 | 3035 | break; |
3036 | 3036 | } |
3037 | - }else{ |
|
3037 | + } else { |
|
3038 | 3038 | $field_obj = $this->_deduce_field_from_query_param($query_param); |
3039 | 3039 | |
3040 | 3040 | //if it's not a normal field, maybe it's a custom selection? |
3041 | - if( ! $field_obj){ |
|
3042 | - if(isset( $this->_custom_selections[$query_param][1])){ |
|
3041 | + if ( ! $field_obj) { |
|
3042 | + if (isset($this->_custom_selections[$query_param][1])) { |
|
3043 | 3043 | $field_obj = $this->_custom_selections[$query_param][1]; |
3044 | - }else{ |
|
3045 | - throw new EE_Error(sprintf(__("%s is neither a valid model field name, nor a custom selection", "event_espresso"),$query_param)); |
|
3044 | + } else { |
|
3045 | + throw new EE_Error(sprintf(__("%s is neither a valid model field name, nor a custom selection", "event_espresso"), $query_param)); |
|
3046 | 3046 | } |
3047 | 3047 | } |
3048 | 3048 | $op_and_value_sql = $this->_construct_op_and_value($op_and_value_or_sub_condition, $field_obj); |
3049 | - $where_clauses[]=$this->_deduce_column_name_from_query_param($query_param).SP.$op_and_value_sql; |
|
3049 | + $where_clauses[] = $this->_deduce_column_name_from_query_param($query_param).SP.$op_and_value_sql; |
|
3050 | 3050 | } |
3051 | 3051 | } |
3052 | - if($where_clauses){ |
|
3053 | - $SQL = implode($glue,$where_clauses); |
|
3054 | - }else{ |
|
3052 | + if ($where_clauses) { |
|
3053 | + $SQL = implode($glue, $where_clauses); |
|
3054 | + } else { |
|
3055 | 3055 | $SQL = ''; |
3056 | 3056 | } |
3057 | 3057 | return $SQL; |
@@ -3065,18 +3065,18 @@ discard block |
||
3065 | 3065 | * @throws EE_Error |
3066 | 3066 | * @return string table alias and column name for SQL, eg "Transaction.TXN_ID" |
3067 | 3067 | */ |
3068 | - private function _deduce_column_name_from_query_param($query_param){ |
|
3068 | + private function _deduce_column_name_from_query_param($query_param) { |
|
3069 | 3069 | $field = $this->_deduce_field_from_query_param($query_param); |
3070 | 3070 | |
3071 | - if( $field ){ |
|
3072 | - $table_alias_prefix = EE_Model_Parser::extract_table_alias_model_relation_chain_from_query_param( $field->get_model_name(), $query_param ); |
|
3073 | - return $table_alias_prefix . $field->get_qualified_column(); |
|
3074 | - }elseif(array_key_exists($query_param,$this->_custom_selections)){ |
|
3071 | + if ($field) { |
|
3072 | + $table_alias_prefix = EE_Model_Parser::extract_table_alias_model_relation_chain_from_query_param($field->get_model_name(), $query_param); |
|
3073 | + return $table_alias_prefix.$field->get_qualified_column(); |
|
3074 | + }elseif (array_key_exists($query_param, $this->_custom_selections)) { |
|
3075 | 3075 | //maybe it's custom selection item? |
3076 | 3076 | //if so, just use it as the "column name" |
3077 | 3077 | return $query_param; |
3078 | - }else{ |
|
3079 | - throw new EE_Error(sprintf(__("%s is not a valid field on this model, nor a custom selection (%s)", "event_espresso"),$query_param,implode(",",$this->_custom_selections))); |
|
3078 | + } else { |
|
3079 | + throw new EE_Error(sprintf(__("%s is not a valid field on this model, nor a custom selection (%s)", "event_espresso"), $query_param, implode(",", $this->_custom_selections))); |
|
3080 | 3080 | } |
3081 | 3081 | } |
3082 | 3082 | |
@@ -3088,11 +3088,11 @@ discard block |
||
3088 | 3088 | * @param string $condition_query_param_key |
3089 | 3089 | * @return string |
3090 | 3090 | */ |
3091 | - private function _remove_stars_and_anything_after_from_condition_query_param_key($condition_query_param_key){ |
|
3091 | + private function _remove_stars_and_anything_after_from_condition_query_param_key($condition_query_param_key) { |
|
3092 | 3092 | $pos_of_star = strpos($condition_query_param_key, '*'); |
3093 | - if($pos_of_star === FALSE){ |
|
3093 | + if ($pos_of_star === FALSE) { |
|
3094 | 3094 | return $condition_query_param_key; |
3095 | - }else{ |
|
3095 | + } else { |
|
3096 | 3096 | $condition_query_param_sans_star = substr($condition_query_param_key, 0, $pos_of_star); |
3097 | 3097 | return $condition_query_param_sans_star; |
3098 | 3098 | } |
@@ -3107,54 +3107,54 @@ discard block |
||
3107 | 3107 | * @throws EE_Error |
3108 | 3108 | * @return string |
3109 | 3109 | */ |
3110 | - private function _construct_op_and_value($op_and_value, $field_obj){ |
|
3111 | - if(is_array( $op_and_value )){ |
|
3110 | + private function _construct_op_and_value($op_and_value, $field_obj) { |
|
3111 | + if (is_array($op_and_value)) { |
|
3112 | 3112 | $operator = isset($op_and_value[0]) ? $this->_prepare_operator_for_sql($op_and_value[0]) : null; |
3113 | - if( ! $operator){ |
|
3113 | + if ( ! $operator) { |
|
3114 | 3114 | $php_array_like_string = array(); |
3115 | - foreach($op_and_value as $key => $value){ |
|
3115 | + foreach ($op_and_value as $key => $value) { |
|
3116 | 3116 | $php_array_like_string[] = "$key=>$value"; |
3117 | 3117 | } |
3118 | - throw new EE_Error(sprintf(__("You setup a query parameter like you were going to specify an operator, but didn't. You provided '(%s)', but the operator should be at array key index 0 (eg array('>',32))", "event_espresso"), implode(",",$php_array_like_string))); |
|
3118 | + throw new EE_Error(sprintf(__("You setup a query parameter like you were going to specify an operator, but didn't. You provided '(%s)', but the operator should be at array key index 0 (eg array('>',32))", "event_espresso"), implode(",", $php_array_like_string))); |
|
3119 | 3119 | } |
3120 | 3120 | $value = isset($op_and_value[1]) ? $op_and_value[1] : null; |
3121 | - }else{ |
|
3121 | + } else { |
|
3122 | 3122 | $operator = '='; |
3123 | 3123 | $value = $op_and_value; |
3124 | 3124 | } |
3125 | 3125 | |
3126 | 3126 | //check to see if the value is actually another field |
3127 | - if(is_array($op_and_value) && isset($op_and_value[2]) && $op_and_value[2] == true){ |
|
3127 | + if (is_array($op_and_value) && isset($op_and_value[2]) && $op_and_value[2] == true) { |
|
3128 | 3128 | return $operator.SP.$this->_deduce_column_name_from_query_param($value); |
3129 | - }elseif(in_array($operator, $this->_in_style_operators) && is_array($value)){ |
|
3129 | + }elseif (in_array($operator, $this->_in_style_operators) && is_array($value)) { |
|
3130 | 3130 | //in this case, the value should be an array, or at least a comma-separated list |
3131 | 3131 | //it will need to handle a little differently |
3132 | 3132 | $cleaned_value = $this->_construct_in_value($value, $field_obj); |
3133 | 3133 | //note: $cleaned_value has already been run through $wpdb->prepare() |
3134 | 3134 | return $operator.SP.$cleaned_value; |
3135 | - } elseif( in_array( $operator, $this->_between_style_operators ) && is_array( $value ) ) { |
|
3135 | + } elseif (in_array($operator, $this->_between_style_operators) && is_array($value)) { |
|
3136 | 3136 | //the value should be an array with count of two. |
3137 | - if ( count($value) !== 2 ) |
|
3138 | - throw new EE_Error( sprintf( __("The '%s' operator must be used with an array of values and there must be exactly TWO values in that array.", 'event_espresso'), "BETWEEN" ) ); |
|
3139 | - $cleaned_value = $this->_construct_between_value( $value, $field_obj ); |
|
3137 | + if (count($value) !== 2) |
|
3138 | + throw new EE_Error(sprintf(__("The '%s' operator must be used with an array of values and there must be exactly TWO values in that array.", 'event_espresso'), "BETWEEN")); |
|
3139 | + $cleaned_value = $this->_construct_between_value($value, $field_obj); |
|
3140 | 3140 | return $operator.SP.$cleaned_value; |
3141 | - } elseif( in_array( $operator, $this->_null_style_operators ) ) { |
|
3142 | - if($value != NULL){ |
|
3143 | - throw new EE_Error(sprintf(__("You attempted to give a value (%s) while using a NULL-style operator (%s). That isn't valid", "event_espresso"),$value,$operator)); |
|
3141 | + } elseif (in_array($operator, $this->_null_style_operators)) { |
|
3142 | + if ($value != NULL) { |
|
3143 | + throw new EE_Error(sprintf(__("You attempted to give a value (%s) while using a NULL-style operator (%s). That isn't valid", "event_espresso"), $value, $operator)); |
|
3144 | 3144 | } |
3145 | 3145 | return $operator; |
3146 | - }elseif( $operator == 'LIKE' && ! is_array($value)){ |
|
3146 | + }elseif ($operator == 'LIKE' && ! is_array($value)) { |
|
3147 | 3147 | //if the operator is 'LIKE', we want to allow percent signs (%) and not |
3148 | 3148 | //remove other junk. So just treat it as a string. |
3149 | 3149 | return $operator.SP.$this->_wpdb_prepare_using_field($value, '%s'); |
3150 | - }elseif( ! in_array($operator, $this->_in_style_operators) && ! is_array($value)){ |
|
3151 | - return $operator.SP.$this->_wpdb_prepare_using_field($value,$field_obj); |
|
3152 | - }elseif(in_array($operator, $this->_in_style_operators) && ! is_array($value)){ |
|
3153 | - throw new EE_Error(sprintf(__("Operator '%s' must be used with an array of values, eg 'Registration.REG_ID' => array('%s',array(1,2,3))",'event_espresso'),$operator, $operator)); |
|
3154 | - }elseif( ! in_array($operator, $this->_in_style_operators) && is_array($value)){ |
|
3155 | - throw new EE_Error(sprintf(__("Operator '%s' must be used with a single value, not an array. Eg 'Registration.REG_ID => array('%s',23))",'event_espresso'),$operator,$operator)); |
|
3156 | - }else{ |
|
3157 | - throw new EE_Error(sprintf(__("It appears you've provided some totally invalid query parameters. Operator and value were:'%s', which isn't right at all", "event_espresso"), http_build_query($op_and_value))); |
|
3150 | + }elseif ( ! in_array($operator, $this->_in_style_operators) && ! is_array($value)) { |
|
3151 | + return $operator.SP.$this->_wpdb_prepare_using_field($value, $field_obj); |
|
3152 | + }elseif (in_array($operator, $this->_in_style_operators) && ! is_array($value)) { |
|
3153 | + throw new EE_Error(sprintf(__("Operator '%s' must be used with an array of values, eg 'Registration.REG_ID' => array('%s',array(1,2,3))", 'event_espresso'), $operator, $operator)); |
|
3154 | + }elseif ( ! in_array($operator, $this->_in_style_operators) && is_array($value)) { |
|
3155 | + throw new EE_Error(sprintf(__("Operator '%s' must be used with a single value, not an array. Eg 'Registration.REG_ID => array('%s',23))", 'event_espresso'), $operator, $operator)); |
|
3156 | + } else { |
|
3157 | + throw new EE_Error(sprintf(__("It appears you've provided some totally invalid query parameters. Operator and value were:'%s', which isn't right at all", "event_espresso"), http_build_query($op_and_value))); |
|
3158 | 3158 | } |
3159 | 3159 | } |
3160 | 3160 | |
@@ -3166,12 +3166,12 @@ discard block |
||
3166 | 3166 | * @param EE_Model_Field_Base|string $field_obj if string, it should be the datatype to be used when querying, eg '%s' |
3167 | 3167 | * @return string |
3168 | 3168 | */ |
3169 | - function _construct_between_value( $values, $field_obj ) { |
|
3169 | + function _construct_between_value($values, $field_obj) { |
|
3170 | 3170 | $cleaned_values = array(); |
3171 | - foreach ( $values as $value ) { |
|
3172 | - $cleaned_values[] = $this->_wpdb_prepare_using_field($value,$field_obj); |
|
3171 | + foreach ($values as $value) { |
|
3172 | + $cleaned_values[] = $this->_wpdb_prepare_using_field($value, $field_obj); |
|
3173 | 3173 | } |
3174 | - return $cleaned_values[0] . " AND " . $cleaned_values[1]; |
|
3174 | + return $cleaned_values[0]." AND ".$cleaned_values[1]; |
|
3175 | 3175 | } |
3176 | 3176 | |
3177 | 3177 | |
@@ -3187,26 +3187,26 @@ discard block |
||
3187 | 3187 | * @param EE_Model_Field_Base|string $field_obj if string, it should be a wpdb data type like '%s', or '%d' |
3188 | 3188 | * @return string of SQL to follow an 'IN' or 'NOT IN' operator |
3189 | 3189 | */ |
3190 | - function _construct_in_value($values, $field_obj){ |
|
3190 | + function _construct_in_value($values, $field_obj) { |
|
3191 | 3191 | //check if the value is a CSV list |
3192 | - if(is_string($values)){ |
|
3192 | + if (is_string($values)) { |
|
3193 | 3193 | //in which case, turn it into an array |
3194 | - $values = explode(",",$values); |
|
3194 | + $values = explode(",", $values); |
|
3195 | 3195 | } |
3196 | 3196 | $cleaned_values = array(); |
3197 | - foreach($values as $value){ |
|
3198 | - $cleaned_values[] = $this->_wpdb_prepare_using_field($value,$field_obj); |
|
3197 | + foreach ($values as $value) { |
|
3198 | + $cleaned_values[] = $this->_wpdb_prepare_using_field($value, $field_obj); |
|
3199 | 3199 | } |
3200 | 3200 | //we would just LOVE to leave $cleaned_values as an empty array, and return the value as "()", |
3201 | 3201 | //but unfortunately that's invalid SQL. So instead we return a string which we KNOW will evaluate to be the empty set |
3202 | 3202 | //which is effectively equivalent to returning "()". We don't return "(0)" because that only works for auto-incrementing columns |
3203 | - if(empty($cleaned_values)){ |
|
3203 | + if (empty($cleaned_values)) { |
|
3204 | 3204 | $all_fields = $this->field_settings(); |
3205 | 3205 | $a_field = array_shift($all_fields); |
3206 | 3206 | $main_table = $this->_get_main_table(); |
3207 | 3207 | $cleaned_values[] = "SELECT ".$a_field->get_table_column()." FROM ".$main_table->get_table_name()." WHERE FALSE"; |
3208 | 3208 | } |
3209 | - return "(".implode(",",$cleaned_values).")"; |
|
3209 | + return "(".implode(",", $cleaned_values).")"; |
|
3210 | 3210 | } |
3211 | 3211 | |
3212 | 3212 | |
@@ -3218,16 +3218,16 @@ discard block |
||
3218 | 3218 | * @throws EE_Error |
3219 | 3219 | * @return false|null|string |
3220 | 3220 | */ |
3221 | - private function _wpdb_prepare_using_field($value,$field_obj){ |
|
3221 | + private function _wpdb_prepare_using_field($value, $field_obj) { |
|
3222 | 3222 | /** @type WPDB $wpdb */ |
3223 | 3223 | global $wpdb; |
3224 | - if($field_obj instanceof EE_Model_Field_Base){ |
|
3225 | - return $wpdb->prepare($field_obj->get_wpdb_data_type(),$this->_prepare_value_for_use_in_db($value, $field_obj)); |
|
3226 | - }else{//$field_obj should really just be a data type |
|
3227 | - if( ! in_array($field_obj,$this->_valid_wpdb_data_types)){ |
|
3228 | - throw new EE_Error(sprintf(__("%s is not a valid wpdb datatype. Valid ones are %s", "event_espresso"),$field_obj,implode(",",$this->_valid_wpdb_data_types))); |
|
3224 | + if ($field_obj instanceof EE_Model_Field_Base) { |
|
3225 | + return $wpdb->prepare($field_obj->get_wpdb_data_type(), $this->_prepare_value_for_use_in_db($value, $field_obj)); |
|
3226 | + } else {//$field_obj should really just be a data type |
|
3227 | + if ( ! in_array($field_obj, $this->_valid_wpdb_data_types)) { |
|
3228 | + throw new EE_Error(sprintf(__("%s is not a valid wpdb datatype. Valid ones are %s", "event_espresso"), $field_obj, implode(",", $this->_valid_wpdb_data_types))); |
|
3229 | 3229 | } |
3230 | - return $wpdb->prepare($field_obj,$value); |
|
3230 | + return $wpdb->prepare($field_obj, $value); |
|
3231 | 3231 | } |
3232 | 3232 | } |
3233 | 3233 | |
@@ -3239,27 +3239,27 @@ discard block |
||
3239 | 3239 | * @throws EE_Error |
3240 | 3240 | * @return EE_Model_Field_Base |
3241 | 3241 | */ |
3242 | - protected function _deduce_field_from_query_param($query_param_name){ |
|
3242 | + protected function _deduce_field_from_query_param($query_param_name) { |
|
3243 | 3243 | //ok, now proceed with deducing which part is the model's name, and which is the field's name |
3244 | 3244 | //which will help us find the database table and column |
3245 | 3245 | |
3246 | - $query_param_parts = explode(".",$query_param_name); |
|
3247 | - if(empty($query_param_parts)){ |
|
3248 | - throw new EE_Error(sprintf(__("_extract_column_name is empty when trying to extract column and table name from %s",'event_espresso'),$query_param_name)); |
|
3246 | + $query_param_parts = explode(".", $query_param_name); |
|
3247 | + if (empty($query_param_parts)) { |
|
3248 | + throw new EE_Error(sprintf(__("_extract_column_name is empty when trying to extract column and table name from %s", 'event_espresso'), $query_param_name)); |
|
3249 | 3249 | } |
3250 | 3250 | $number_of_parts = count($query_param_parts); |
3251 | - $last_query_param_part = $query_param_parts[ count($query_param_parts) - 1 ]; |
|
3252 | - if($number_of_parts == 1){ |
|
3251 | + $last_query_param_part = $query_param_parts[count($query_param_parts) - 1]; |
|
3252 | + if ($number_of_parts == 1) { |
|
3253 | 3253 | $field_name = $last_query_param_part; |
3254 | 3254 | $model_obj = $this; |
3255 | - }else{// $number_of_parts >= 2 |
|
3255 | + } else {// $number_of_parts >= 2 |
|
3256 | 3256 | //the last part is the column name, and there are only 2parts. therefore... |
3257 | 3257 | $field_name = $last_query_param_part; |
3258 | - $model_obj = $this->get_related_model_obj( $query_param_parts[ $number_of_parts - 2 ]); |
|
3258 | + $model_obj = $this->get_related_model_obj($query_param_parts[$number_of_parts - 2]); |
|
3259 | 3259 | } |
3260 | - try{ |
|
3260 | + try { |
|
3261 | 3261 | return $model_obj->field_settings_for($field_name); |
3262 | - }catch(EE_Error $e){ |
|
3262 | + } catch (EE_Error $e) { |
|
3263 | 3263 | return null; |
3264 | 3264 | } |
3265 | 3265 | } |
@@ -3273,13 +3273,13 @@ discard block |
||
3273 | 3273 | * @throws EE_Error |
3274 | 3274 | * @return string |
3275 | 3275 | */ |
3276 | - function _get_qualified_column_for_field($field_name){ |
|
3276 | + function _get_qualified_column_for_field($field_name) { |
|
3277 | 3277 | $all_fields = $this->field_settings(); |
3278 | 3278 | $field = isset($all_fields[$field_name]) ? $all_fields[$field_name] : FALSE; |
3279 | - if($field){ |
|
3279 | + if ($field) { |
|
3280 | 3280 | return $field->get_qualified_column(); |
3281 | - }else{ |
|
3282 | - throw new EE_Error(sprintf(__("There is no field titled %s on model %s. Either the query trying to use it is bad, or you need to add it to the list of fields on the model.",'event_espresso'),$field_name,get_class($this))); |
|
3281 | + } else { |
|
3282 | + throw new EE_Error(sprintf(__("There is no field titled %s on model %s. Either the query trying to use it is bad, or you need to add it to the list of fields on the model.", 'event_espresso'), $field_name, get_class($this))); |
|
3283 | 3283 | } |
3284 | 3284 | } |
3285 | 3285 | |
@@ -3293,14 +3293,14 @@ discard block |
||
3293 | 3293 | * @param mixed|string $limit The limit for this select |
3294 | 3294 | * @return string The final select join element for the query. |
3295 | 3295 | */ |
3296 | - function _construct_limit_join_select( $table_alias, $limit ) { |
|
3296 | + function _construct_limit_join_select($table_alias, $limit) { |
|
3297 | 3297 | $SQL = ''; |
3298 | 3298 | |
3299 | - foreach ( $this->_tables as $table_obj ) { |
|
3300 | - if ( $table_obj instanceof EE_Primary_Table ) { |
|
3301 | - $SQL .= $table_alias == $table_obj->get_table_alias() ? $table_obj->get_select_join_limit( $limit ) : SP.$table_obj->get_table_name()." AS ".$table_obj->get_table_alias().SP; |
|
3302 | - } elseif ( $table_obj instanceof EE_Secondary_Table ) { |
|
3303 | - $SQL .= $table_alias == $table_obj->get_table_alias() ? $table_obj->get_select_join_limit_join($limit) : SP . $table_obj->get_join_sql( $table_alias ).SP; |
|
3299 | + foreach ($this->_tables as $table_obj) { |
|
3300 | + if ($table_obj instanceof EE_Primary_Table) { |
|
3301 | + $SQL .= $table_alias == $table_obj->get_table_alias() ? $table_obj->get_select_join_limit($limit) : SP.$table_obj->get_table_name()." AS ".$table_obj->get_table_alias().SP; |
|
3302 | + } elseif ($table_obj instanceof EE_Secondary_Table) { |
|
3303 | + $SQL .= $table_alias == $table_obj->get_table_alias() ? $table_obj->get_select_join_limit_join($limit) : SP.$table_obj->get_join_sql($table_alias).SP; |
|
3304 | 3304 | } |
3305 | 3305 | } |
3306 | 3306 | return $SQL; |
@@ -3313,7 +3313,7 @@ discard block |
||
3313 | 3313 | * Eg "wp_post AS Event" or "wp_post AS Event INNER JOIN wp_postmeta Event_Meta ON Event.ID = Event_Meta.post_id" |
3314 | 3314 | * @return string SQL |
3315 | 3315 | */ |
3316 | - function _construct_internal_join(){ |
|
3316 | + function _construct_internal_join() { |
|
3317 | 3317 | $SQL = $this->_get_main_table()->get_table_sql(); |
3318 | 3318 | $SQL .= $this->_construct_internal_join_to_table_with_alias($this->_get_main_table()->get_table_alias()); |
3319 | 3319 | return $SQL; |
@@ -3334,17 +3334,17 @@ discard block |
||
3334 | 3334 | * @param string $alias_prefixed table alias to join to (this table should already be in the FROM SQL clause) |
3335 | 3335 | * @return string |
3336 | 3336 | */ |
3337 | - function _construct_internal_join_to_table_with_alias($alias_prefixed){ |
|
3337 | + function _construct_internal_join_to_table_with_alias($alias_prefixed) { |
|
3338 | 3338 | $SQL = ''; |
3339 | 3339 | $alias_sans_prefix = EE_Model_Parser::remove_table_alias_model_relation_chain_prefix($alias_prefixed); |
3340 | - foreach($this->_tables as $table_obj){ |
|
3341 | - if($table_obj instanceof EE_Secondary_Table){//table is secondary table |
|
3342 | - if($alias_sans_prefix == $table_obj->get_table_alias()){ |
|
3340 | + foreach ($this->_tables as $table_obj) { |
|
3341 | + if ($table_obj instanceof EE_Secondary_Table) {//table is secondary table |
|
3342 | + if ($alias_sans_prefix == $table_obj->get_table_alias()) { |
|
3343 | 3343 | //so we're joining to this table, meaning the table is already in |
3344 | 3344 | //the FROM statement, BUT the primary table isn't. So we want |
3345 | 3345 | //to add the inverse join sql |
3346 | 3346 | $SQL .= $table_obj->get_inverse_join_sql($alias_prefixed); |
3347 | - }else{ |
|
3347 | + } else { |
|
3348 | 3348 | //just add a regular JOIN to this table from the primary table |
3349 | 3349 | $SQL .= $table_obj->get_join_sql($alias_prefixed); |
3350 | 3350 | } |
@@ -3358,9 +3358,9 @@ discard block |
||
3358 | 3358 | * This should be a growing array of keys being table-columns (eg 'EVT_ID' and 'Event.EVT_ID'), and values being their data type (eg, '%s', '%d', etc) |
3359 | 3359 | * @return array |
3360 | 3360 | */ |
3361 | - function _get_data_types(){ |
|
3361 | + function _get_data_types() { |
|
3362 | 3362 | $data_types = array(); |
3363 | - foreach(array_values($this->field_settings()) as $field_obj){ |
|
3363 | + foreach (array_values($this->field_settings()) as $field_obj) { |
|
3364 | 3364 | //$data_types[$field_obj->get_table_column()] = $field_obj->get_wpdb_data_type(); |
3365 | 3365 | /** @var $field_obj EE_Model_Field_Base */ |
3366 | 3366 | $data_types[$field_obj->get_qualified_column()] = $field_obj->get_wpdb_data_type(); |
@@ -3376,11 +3376,11 @@ discard block |
||
3376 | 3376 | * @throws EE_Error |
3377 | 3377 | * @return EEM_Base |
3378 | 3378 | */ |
3379 | - function get_related_model_obj($model_name){ |
|
3379 | + function get_related_model_obj($model_name) { |
|
3380 | 3380 | |
3381 | 3381 | $model_classname = "EEM_".$model_name; |
3382 | - if(!class_exists($model_classname)){ |
|
3383 | - throw new EE_Error(sprintf(__("You specified a related model named %s in your query. No such model exists, if it did, it would have the classname %s",'event_espresso'),$model_name,$model_classname)); |
|
3382 | + if ( ! class_exists($model_classname)) { |
|
3383 | + throw new EE_Error(sprintf(__("You specified a related model named %s in your query. No such model exists, if it did, it would have the classname %s", 'event_espresso'), $model_name, $model_classname)); |
|
3384 | 3384 | } |
3385 | 3385 | $model_obj = call_user_func($model_classname."::instance"); |
3386 | 3386 | return $model_obj; |
@@ -3391,7 +3391,7 @@ discard block |
||
3391 | 3391 | * Returns the array of EE_ModelRelations for this model. |
3392 | 3392 | * @return EE_Model_Relation_Base[] |
3393 | 3393 | */ |
3394 | - public function relation_settings(){ |
|
3394 | + public function relation_settings() { |
|
3395 | 3395 | return $this->_model_relations; |
3396 | 3396 | } |
3397 | 3397 | |
@@ -3401,10 +3401,10 @@ discard block |
||
3401 | 3401 | * (Eg, without an event, datetimes have little purpose.) |
3402 | 3402 | * @return EE_Belongs_To_Relation[] |
3403 | 3403 | */ |
3404 | - public function belongs_to_relations(){ |
|
3404 | + public function belongs_to_relations() { |
|
3405 | 3405 | $belongs_to_relations = array(); |
3406 | - foreach($this->relation_settings() as $model_name => $relation_obj){ |
|
3407 | - if($relation_obj instanceof EE_Belongs_To_Relation){ |
|
3406 | + foreach ($this->relation_settings() as $model_name => $relation_obj) { |
|
3407 | + if ($relation_obj instanceof EE_Belongs_To_Relation) { |
|
3408 | 3408 | $belongs_to_relations[$model_name] = $relation_obj; |
3409 | 3409 | } |
3410 | 3410 | } |
@@ -3419,15 +3419,15 @@ discard block |
||
3419 | 3419 | * @throws EE_Error |
3420 | 3420 | * @return EE_Model_Relation_Base |
3421 | 3421 | */ |
3422 | - public function related_settings_for($relation_name){ |
|
3423 | - $relatedModels=$this->relation_settings(); |
|
3424 | - if(!array_key_exists($relation_name,$relatedModels)){ |
|
3422 | + public function related_settings_for($relation_name) { |
|
3423 | + $relatedModels = $this->relation_settings(); |
|
3424 | + if ( ! array_key_exists($relation_name, $relatedModels)) { |
|
3425 | 3425 | throw new EE_Error( |
3426 | 3426 | sprintf( |
3427 | - __('Cannot get %s related to %s. There is no model relation of that type. There is, however, %s...','event_espresso'), |
|
3427 | + __('Cannot get %s related to %s. There is no model relation of that type. There is, however, %s...', 'event_espresso'), |
|
3428 | 3428 | $relation_name, |
3429 | 3429 | $this->_get_class_name(), |
3430 | - implode( ', ', array_keys( $relatedModels )) |
|
3430 | + implode(', ', array_keys($relatedModels)) |
|
3431 | 3431 | ) |
3432 | 3432 | ); |
3433 | 3433 | } |
@@ -3442,10 +3442,10 @@ discard block |
||
3442 | 3442 | * @throws EE_Error |
3443 | 3443 | * @return EE_Model_Field_Base |
3444 | 3444 | */ |
3445 | - public function field_settings_for($fieldName){ |
|
3446 | - $fieldSettings=$this->field_settings(true); |
|
3447 | - if( ! array_key_exists($fieldName,$fieldSettings)){ |
|
3448 | - throw new EE_Error(sprintf(__("There is no field/column '%s' on '%s'",'event_espresso'),$fieldName,get_class($this))); |
|
3445 | + public function field_settings_for($fieldName) { |
|
3446 | + $fieldSettings = $this->field_settings(true); |
|
3447 | + if ( ! array_key_exists($fieldName, $fieldSettings)) { |
|
3448 | + throw new EE_Error(sprintf(__("There is no field/column '%s' on '%s'", 'event_espresso'), $fieldName, get_class($this))); |
|
3449 | 3449 | } |
3450 | 3450 | return $fieldSettings[$fieldName]; |
3451 | 3451 | } |
@@ -3455,11 +3455,11 @@ discard block |
||
3455 | 3455 | * @param string $fieldName a key in the model's _field_settings array |
3456 | 3456 | * @return boolean |
3457 | 3457 | */ |
3458 | - public function has_field($fieldName){ |
|
3458 | + public function has_field($fieldName) { |
|
3459 | 3459 | $fieldSettings = $this->field_settings(true); |
3460 | - if( isset($fieldSettings[$fieldName])){ |
|
3460 | + if (isset($fieldSettings[$fieldName])) { |
|
3461 | 3461 | return true; |
3462 | - }else{ |
|
3462 | + } else { |
|
3463 | 3463 | return false; |
3464 | 3464 | } |
3465 | 3465 | } |
@@ -3469,11 +3469,11 @@ discard block |
||
3469 | 3469 | * @param string $relation_name possibly one of the keys in the relation_settings array |
3470 | 3470 | * @return boolean |
3471 | 3471 | */ |
3472 | - public function has_relation($relation_name){ |
|
3472 | + public function has_relation($relation_name) { |
|
3473 | 3473 | $relations = $this->relation_settings(); |
3474 | - if(isset($relations[$relation_name])){ |
|
3474 | + if (isset($relations[$relation_name])) { |
|
3475 | 3475 | return true; |
3476 | - }else{ |
|
3476 | + } else { |
|
3477 | 3477 | return false; |
3478 | 3478 | } |
3479 | 3479 | } |
@@ -3485,7 +3485,7 @@ discard block |
||
3485 | 3485 | * @param $field_obj |
3486 | 3486 | * @return EE_Model_Field_Base |
3487 | 3487 | */ |
3488 | - public function is_primary_key_field( $field_obj ){ |
|
3488 | + public function is_primary_key_field($field_obj) { |
|
3489 | 3489 | return $field_obj instanceof EE_Primary_Key_Field_Base ? TRUE : FALSE; |
3490 | 3490 | } |
3491 | 3491 | |
@@ -3497,16 +3497,16 @@ discard block |
||
3497 | 3497 | * @return EE_Model_Field_Base |
3498 | 3498 | * @throws EE_Error |
3499 | 3499 | */ |
3500 | - public function get_primary_key_field(){ |
|
3501 | - if( $this->_primary_key_field === NULL ){ |
|
3502 | - foreach( $this->field_settings( TRUE ) as $field_obj ){ |
|
3503 | - if( $this->is_primary_key_field( $field_obj )){ |
|
3500 | + public function get_primary_key_field() { |
|
3501 | + if ($this->_primary_key_field === NULL) { |
|
3502 | + foreach ($this->field_settings(TRUE) as $field_obj) { |
|
3503 | + if ($this->is_primary_key_field($field_obj)) { |
|
3504 | 3504 | $this->_primary_key_field = $field_obj; |
3505 | 3505 | break; |
3506 | 3506 | } |
3507 | 3507 | } |
3508 | - if( ! $this->_primary_key_field instanceof EE_Primary_Key_Field_Base ){ |
|
3509 | - throw new EE_Error(sprintf(__("There is no Primary Key defined on model %s",'event_espresso'),get_class($this))); |
|
3508 | + if ( ! $this->_primary_key_field instanceof EE_Primary_Key_Field_Base) { |
|
3509 | + throw new EE_Error(sprintf(__("There is no Primary Key defined on model %s", 'event_espresso'), get_class($this))); |
|
3510 | 3510 | } |
3511 | 3511 | } |
3512 | 3512 | return $this->_primary_key_field; |
@@ -3519,12 +3519,12 @@ discard block |
||
3519 | 3519 | * Internally does some caching. |
3520 | 3520 | * @return boolean |
3521 | 3521 | */ |
3522 | - public function has_primary_key_field(){ |
|
3523 | - if($this->_has_primary_key_field === null){ |
|
3524 | - try{ |
|
3522 | + public function has_primary_key_field() { |
|
3523 | + if ($this->_has_primary_key_field === null) { |
|
3524 | + try { |
|
3525 | 3525 | $this->get_primary_key_field(); |
3526 | 3526 | $this->_has_primary_key_field = true; |
3527 | - }catch(EE_Error $e){ |
|
3527 | + } catch (EE_Error $e) { |
|
3528 | 3528 | $this->_has_primary_key_field = false; |
3529 | 3529 | } |
3530 | 3530 | } |
@@ -3538,9 +3538,9 @@ discard block |
||
3538 | 3538 | * @param string $field_class_name class name of field that you want to find. Eg, EE_Datetime_Field, EE_Foreign_Key_Field, etc |
3539 | 3539 | * @return EE_Model_Field_Base or null if none is found |
3540 | 3540 | */ |
3541 | - public function get_a_field_of_type($field_class_name){ |
|
3542 | - foreach($this->field_settings() as $field){ |
|
3543 | - if( $field instanceof $field_class_name ){ |
|
3541 | + public function get_a_field_of_type($field_class_name) { |
|
3542 | + foreach ($this->field_settings() as $field) { |
|
3543 | + if ($field instanceof $field_class_name) { |
|
3544 | 3544 | return $field; |
3545 | 3545 | } |
3546 | 3546 | } |
@@ -3554,21 +3554,21 @@ discard block |
||
3554 | 3554 | * @return EE_Foreign_Key_Field_Base |
3555 | 3555 | * @throws EE_Error |
3556 | 3556 | */ |
3557 | - public function get_foreign_key_to($model_name){ |
|
3558 | - if( ! isset( $this->_cache_foreign_key_to_fields[ $model_name ] ) ){ |
|
3559 | - foreach($this->field_settings() as $field){ |
|
3557 | + public function get_foreign_key_to($model_name) { |
|
3558 | + if ( ! isset($this->_cache_foreign_key_to_fields[$model_name])) { |
|
3559 | + foreach ($this->field_settings() as $field) { |
|
3560 | 3560 | // if(is_subclass_of($field, 'EE_Foreign_Key_Field_Base')){ |
3561 | - if( $field instanceof EE_Foreign_Key_Field_Base ){ |
|
3562 | - if (in_array($model_name,$field->get_model_names_pointed_to() ) ) { |
|
3563 | - $this->_cache_foreign_key_to_fields[ $model_name ] = $field; |
|
3561 | + if ($field instanceof EE_Foreign_Key_Field_Base) { |
|
3562 | + if (in_array($model_name, $field->get_model_names_pointed_to())) { |
|
3563 | + $this->_cache_foreign_key_to_fields[$model_name] = $field; |
|
3564 | 3564 | } |
3565 | 3565 | } |
3566 | 3566 | } |
3567 | - if( ! isset( $this->_cache_foreign_key_to_fields[ $model_name ] ) ){ |
|
3568 | - throw new EE_Error(sprintf(__("There is no foreign key field pointing to model %s on model %s",'event_espresso'),$model_name,get_class($this))); |
|
3567 | + if ( ! isset($this->_cache_foreign_key_to_fields[$model_name])) { |
|
3568 | + throw new EE_Error(sprintf(__("There is no foreign key field pointing to model %s on model %s", 'event_espresso'), $model_name, get_class($this))); |
|
3569 | 3569 | } |
3570 | 3570 | } |
3571 | - return $this->_cache_foreign_key_to_fields[ $model_name ]; |
|
3571 | + return $this->_cache_foreign_key_to_fields[$model_name]; |
|
3572 | 3572 | } |
3573 | 3573 | |
3574 | 3574 | |
@@ -3579,7 +3579,7 @@ discard block |
||
3579 | 3579 | * a table alias with a model chain prefix, like 'Venue__Event_Venue___Event_Meta'. Either one works |
3580 | 3580 | * @return EE_Table_Base |
3581 | 3581 | */ |
3582 | - function get_table_for_alias($table_alias){ |
|
3582 | + function get_table_for_alias($table_alias) { |
|
3583 | 3583 | $table_alias_sans_model_relation_chain_prefix = EE_Model_Parser::remove_table_alias_model_relation_chain_prefix($table_alias); |
3584 | 3584 | return $this->_tables[$table_alias_sans_model_relation_chain_prefix]->get_table_name(); |
3585 | 3585 | } |
@@ -3592,25 +3592,25 @@ discard block |
||
3592 | 3592 | * @param bool $include_db_only_fields flag indicating whether or not to include the db-only fields |
3593 | 3593 | * @return EE_Model_Field_Base[] where the keys are the field's name |
3594 | 3594 | */ |
3595 | - public function field_settings($include_db_only_fields = false){ |
|
3596 | - if( $include_db_only_fields ){ |
|
3597 | - if( $this->_cached_fields === NULL ){ |
|
3595 | + public function field_settings($include_db_only_fields = false) { |
|
3596 | + if ($include_db_only_fields) { |
|
3597 | + if ($this->_cached_fields === NULL) { |
|
3598 | 3598 | $this->_cached_fields = array(); |
3599 | - foreach($this->_fields as $fields_corresponding_to_table){ |
|
3600 | - foreach($fields_corresponding_to_table as $field_name => $field_obj){ |
|
3601 | - $this->_cached_fields[$field_name]=$field_obj; |
|
3599 | + foreach ($this->_fields as $fields_corresponding_to_table) { |
|
3600 | + foreach ($fields_corresponding_to_table as $field_name => $field_obj) { |
|
3601 | + $this->_cached_fields[$field_name] = $field_obj; |
|
3602 | 3602 | } |
3603 | 3603 | } |
3604 | 3604 | } |
3605 | 3605 | return $this->_cached_fields; |
3606 | - }else{ |
|
3607 | - if( $this->_cached_fields_non_db_only === NULL ){ |
|
3606 | + } else { |
|
3607 | + if ($this->_cached_fields_non_db_only === NULL) { |
|
3608 | 3608 | $this->_cached_fields_non_db_only = array(); |
3609 | - foreach($this->_fields as $fields_corresponding_to_table){ |
|
3610 | - foreach($fields_corresponding_to_table as $field_name => $field_obj){ |
|
3609 | + foreach ($this->_fields as $fields_corresponding_to_table) { |
|
3610 | + foreach ($fields_corresponding_to_table as $field_name => $field_obj) { |
|
3611 | 3611 | /** @var $field_obj EE_Model_Field_Base */ |
3612 | - if( ! $field_obj->is_db_only_field() ){ |
|
3613 | - $this->_cached_fields_non_db_only[$field_name]=$field_obj; |
|
3612 | + if ( ! $field_obj->is_db_only_field()) { |
|
3613 | + $this->_cached_fields_non_db_only[$field_name] = $field_obj; |
|
3614 | 3614 | } |
3615 | 3615 | } |
3616 | 3616 | } |
@@ -3629,67 +3629,67 @@ discard block |
||
3629 | 3629 | * @return \EE_Base_Class[] array keys are primary keys (if there is a primary key on the model. if not, numerically indexed) |
3630 | 3630 | * @throws \EE_Error |
3631 | 3631 | */ |
3632 | - protected function _create_objects( $rows = array() ) { |
|
3633 | - $array_of_objects=array(); |
|
3634 | - if(empty($rows)){ |
|
3632 | + protected function _create_objects($rows = array()) { |
|
3633 | + $array_of_objects = array(); |
|
3634 | + if (empty($rows)) { |
|
3635 | 3635 | return array(); |
3636 | 3636 | } |
3637 | 3637 | $count_if_model_has_no_primary_key = 0; |
3638 | 3638 | $has_primary_key = $this->has_primary_key_field(); |
3639 | - if( $has_primary_key ) { |
|
3639 | + if ($has_primary_key) { |
|
3640 | 3640 | $primary_key_field = $this->get_primary_key_field(); |
3641 | 3641 | } else { |
3642 | 3642 | $primary_key_field = null; |
3643 | 3643 | } |
3644 | - foreach ( $rows as $row ) { |
|
3645 | - if(empty($row)){ |
|
3644 | + foreach ($rows as $row) { |
|
3645 | + if (empty($row)) { |
|
3646 | 3646 | //wp did its weird thing where it returns an array like array(0=>null), which is totally not helpful... |
3647 | 3647 | return array(); |
3648 | 3648 | } |
3649 | 3649 | //check if we've already set this object in the results array, |
3650 | 3650 | //in which case there's no need to process it further (again) |
3651 | - if( $has_primary_key ) { |
|
3651 | + if ($has_primary_key) { |
|
3652 | 3652 | $table_pk_value = $this->_get_column_value_with_table_alias_or_not( |
3653 | 3653 | $row, |
3654 | 3654 | $primary_key_field->get_qualified_column(), |
3655 | 3655 | $primary_key_field->get_table_column() |
3656 | 3656 | ); |
3657 | - if( $table_pk_value && |
|
3658 | - isset( $array_of_objects[ $table_pk_value ] ) ) { |
|
3657 | + if ($table_pk_value && |
|
3658 | + isset($array_of_objects[$table_pk_value])) { |
|
3659 | 3659 | continue; |
3660 | 3660 | } |
3661 | 3661 | } |
3662 | - $classInstance=$this->instantiate_class_from_array_or_object($row); |
|
3663 | - if( ! $classInstance ) { |
|
3662 | + $classInstance = $this->instantiate_class_from_array_or_object($row); |
|
3663 | + if ( ! $classInstance) { |
|
3664 | 3664 | throw new EE_Error( |
3665 | 3665 | sprintf( |
3666 | - __( 'Could not create instance of class %s from row %s', 'event_espresso' ), |
|
3666 | + __('Could not create instance of class %s from row %s', 'event_espresso'), |
|
3667 | 3667 | $this->get_this_model_name(), |
3668 | - http_build_query( $row ) |
|
3668 | + http_build_query($row) |
|
3669 | 3669 | ) |
3670 | 3670 | ); |
3671 | 3671 | } |
3672 | 3672 | //set the timezone on the instantiated objects |
3673 | - $classInstance->set_timezone( $this->_timezone ); |
|
3673 | + $classInstance->set_timezone($this->_timezone); |
|
3674 | 3674 | //make sure if there is any timezone setting present that we set the timezone for the object |
3675 | 3675 | $key = $has_primary_key ? $classInstance->ID() : $count_if_model_has_no_primary_key++; |
3676 | - $array_of_objects[ $key ] = $classInstance; |
|
3676 | + $array_of_objects[$key] = $classInstance; |
|
3677 | 3677 | //also, for all the relations of type BelongsTo, see if we can cache |
3678 | 3678 | //those related models |
3679 | 3679 | //(we could do this for other relations too, but if there are conditions |
3680 | 3680 | //that filtered out some fo the results, then we'd be caching an incomplete set |
3681 | 3681 | //so it requires a little more thought than just caching them immediately...) |
3682 | - foreach($this->_model_relations as $modelName => $relation_obj){ |
|
3683 | - if( $relation_obj instanceof EE_Belongs_To_Relation){ |
|
3682 | + foreach ($this->_model_relations as $modelName => $relation_obj) { |
|
3683 | + if ($relation_obj instanceof EE_Belongs_To_Relation) { |
|
3684 | 3684 | //check if this model's INFO is present. If so, cache it on the model |
3685 | 3685 | $other_model = $relation_obj->get_other_model(); |
3686 | 3686 | |
3687 | 3687 | $other_model_obj_maybe = $other_model->instantiate_class_from_array_or_object($row); |
3688 | 3688 | |
3689 | 3689 | //if we managed to make a model object from the results, cache it on the main model object |
3690 | - if( $other_model_obj_maybe ){ |
|
3690 | + if ($other_model_obj_maybe) { |
|
3691 | 3691 | //set timezone on these other model objects if they are present |
3692 | - $other_model_obj_maybe->set_timezone( $this->_timezone ); |
|
3692 | + $other_model_obj_maybe->set_timezone($this->_timezone); |
|
3693 | 3693 | $classInstance->cache($modelName, $other_model_obj_maybe); |
3694 | 3694 | } |
3695 | 3695 | } |
@@ -3710,12 +3710,12 @@ discard block |
||
3710 | 3710 | |
3711 | 3711 | $this_model_fields_and_values = array(); |
3712 | 3712 | //setup the row using default values; |
3713 | - foreach ( $this->field_settings() as $field_name => $field_obj ) { |
|
3713 | + foreach ($this->field_settings() as $field_name => $field_obj) { |
|
3714 | 3714 | $this_model_fields_and_values[$field_name] = $field_obj->get_default_value(); |
3715 | 3715 | } |
3716 | 3716 | |
3717 | 3717 | $className = $this->_get_class_name(); |
3718 | - $classInstance = EE_Registry::instance()->load_class( $className, array( $this_model_fields_and_values ), FALSE, FALSE ); |
|
3718 | + $classInstance = EE_Registry::instance()->load_class($className, array($this_model_fields_and_values), FALSE, FALSE); |
|
3719 | 3719 | |
3720 | 3720 | return $classInstance; |
3721 | 3721 | } |
@@ -3728,45 +3728,45 @@ discard block |
||
3728 | 3728 | * or an stdClass where each property is the name of a column, |
3729 | 3729 | * @return EE_Base_Class |
3730 | 3730 | */ |
3731 | - public function instantiate_class_from_array_or_object($cols_n_values){ |
|
3732 | - if( ! is_array( $cols_n_values ) && is_object( $cols_n_values )) { |
|
3733 | - $cols_n_values = get_object_vars( $cols_n_values ); |
|
3731 | + public function instantiate_class_from_array_or_object($cols_n_values) { |
|
3732 | + if ( ! is_array($cols_n_values) && is_object($cols_n_values)) { |
|
3733 | + $cols_n_values = get_object_vars($cols_n_values); |
|
3734 | 3734 | } |
3735 | 3735 | $primary_key = NULL; |
3736 | 3736 | //make sure the array only has keys that are fields/columns on this model |
3737 | - $this_model_fields_n_values = $this->_deduce_fields_n_values_from_cols_n_values( $cols_n_values ); |
|
3738 | - if( $this->has_primary_key_field() && isset( $this_model_fields_n_values[ $this->primary_key_name() ] ) ){ |
|
3739 | - $primary_key = $this_model_fields_n_values[ $this->primary_key_name() ]; |
|
3737 | + $this_model_fields_n_values = $this->_deduce_fields_n_values_from_cols_n_values($cols_n_values); |
|
3738 | + if ($this->has_primary_key_field() && isset($this_model_fields_n_values[$this->primary_key_name()])) { |
|
3739 | + $primary_key = $this_model_fields_n_values[$this->primary_key_name()]; |
|
3740 | 3740 | } |
3741 | - $className=$this->_get_class_name(); |
|
3741 | + $className = $this->_get_class_name(); |
|
3742 | 3742 | |
3743 | 3743 | //check we actually found results that we can use to build our model object |
3744 | 3744 | //if not, return null |
3745 | - if( $this->has_primary_key_field()){ |
|
3746 | - if(empty( $this_model_fields_n_values[$this->primary_key_name()] )){ |
|
3745 | + if ($this->has_primary_key_field()) { |
|
3746 | + if (empty($this_model_fields_n_values[$this->primary_key_name()])) { |
|
3747 | 3747 | return NULL; |
3748 | 3748 | } |
3749 | - }else if($this->unique_indexes()){ |
|
3749 | + } else if ($this->unique_indexes()) { |
|
3750 | 3750 | $first_column = reset($this_model_fields_n_values); |
3751 | - if(empty($first_column)){ |
|
3751 | + if (empty($first_column)) { |
|
3752 | 3752 | return NULL; |
3753 | 3753 | } |
3754 | 3754 | } |
3755 | 3755 | |
3756 | 3756 | // if there is no primary key or the object doesn't already exist in the entity map, then create a new instance |
3757 | - if ( $primary_key){ |
|
3758 | - $classInstance = $this->get_from_entity_map( $primary_key ); |
|
3759 | - if( ! $classInstance) { |
|
3760 | - $classInstance = EE_Registry::instance()->load_class( $className, array( $this_model_fields_n_values, $this->_timezone ), TRUE, FALSE ); |
|
3757 | + if ($primary_key) { |
|
3758 | + $classInstance = $this->get_from_entity_map($primary_key); |
|
3759 | + if ( ! $classInstance) { |
|
3760 | + $classInstance = EE_Registry::instance()->load_class($className, array($this_model_fields_n_values, $this->_timezone), TRUE, FALSE); |
|
3761 | 3761 | // add this new object to the entity map |
3762 | - $classInstance = $this->add_to_entity_map( $classInstance ); |
|
3762 | + $classInstance = $this->add_to_entity_map($classInstance); |
|
3763 | 3763 | } |
3764 | - }else{ |
|
3765 | - $classInstance = EE_Registry::instance()->load_class( $className, array( $this_model_fields_n_values, $this->_timezone ), TRUE, FALSE ); |
|
3764 | + } else { |
|
3765 | + $classInstance = EE_Registry::instance()->load_class($className, array($this_model_fields_n_values, $this->_timezone), TRUE, FALSE); |
|
3766 | 3766 | } |
3767 | 3767 | |
3768 | 3768 | //it is entirely possible that the instantiated class object has a set timezone_string db field and has set it's internal _timezone property accordingly (see new_instance_from_db in model objects particularly EE_Event for example). In this case, we want to make sure the model object doesn't have its timezone string overwritten by any timezone property currently set here on the model so, we intentionally override the model _timezone property with the model_object timezone property. |
3769 | - $this->set_timezone( $classInstance->get_timezone() ); |
|
3769 | + $this->set_timezone($classInstance->get_timezone()); |
|
3770 | 3770 | return $classInstance; |
3771 | 3771 | } |
3772 | 3772 | /** |
@@ -3774,8 +3774,8 @@ discard block |
||
3774 | 3774 | * @param int|string $id the ID of the model object |
3775 | 3775 | * @return EE_Base_Class |
3776 | 3776 | */ |
3777 | - public function get_from_entity_map( $id ){ |
|
3778 | - return isset( $this->_entity_map[ $id ] ) ? $this->_entity_map[ $id ] : NULL; |
|
3777 | + public function get_from_entity_map($id) { |
|
3778 | + return isset($this->_entity_map[$id]) ? $this->_entity_map[$id] : NULL; |
|
3779 | 3779 | } |
3780 | 3780 | |
3781 | 3781 | |
@@ -3794,21 +3794,21 @@ discard block |
||
3794 | 3794 | * @throws EE_Error |
3795 | 3795 | * @return \EE_Base_Class |
3796 | 3796 | */ |
3797 | - public function add_to_entity_map( EE_Base_Class $object) { |
|
3797 | + public function add_to_entity_map(EE_Base_Class $object) { |
|
3798 | 3798 | $className = $this->_get_class_name(); |
3799 | - if( ! $object instanceof $className ){ |
|
3800 | - throw new EE_Error(sprintf(__("You tried adding a %s to a mapping of %ss", "event_espresso"),is_object( $object ) ? get_class( $object ) : $object, $className ) ); |
|
3799 | + if ( ! $object instanceof $className) { |
|
3800 | + throw new EE_Error(sprintf(__("You tried adding a %s to a mapping of %ss", "event_espresso"), is_object($object) ? get_class($object) : $object, $className)); |
|
3801 | 3801 | } |
3802 | 3802 | /** @var $object EE_Base_Class */ |
3803 | - if ( ! $object->ID() ){ |
|
3804 | - throw new EE_Error(sprintf(__("You tried storing a model object with NO ID in the %s entity mapper.", "event_espresso"),get_class($this))); |
|
3803 | + if ( ! $object->ID()) { |
|
3804 | + throw new EE_Error(sprintf(__("You tried storing a model object with NO ID in the %s entity mapper.", "event_espresso"), get_class($this))); |
|
3805 | 3805 | } |
3806 | 3806 | // double check it's not already there |
3807 | - $classInstance = $this->get_from_entity_map( $object->ID() ); |
|
3808 | - if ( $classInstance ) { |
|
3807 | + $classInstance = $this->get_from_entity_map($object->ID()); |
|
3808 | + if ($classInstance) { |
|
3809 | 3809 | return $classInstance; |
3810 | 3810 | } else { |
3811 | - $this->_entity_map[ $object->ID() ] = $object; |
|
3811 | + $this->_entity_map[$object->ID()] = $object; |
|
3812 | 3812 | return $object; |
3813 | 3813 | } |
3814 | 3814 | } |
@@ -3821,8 +3821,8 @@ discard block |
||
3821 | 3821 | * @param array $cols_n_values |
3822 | 3822 | * @return array |
3823 | 3823 | */ |
3824 | - public function deduce_fields_n_values_from_cols_n_values( $cols_n_values ) { |
|
3825 | - return $this->_deduce_fields_n_values_from_cols_n_values( $cols_n_values ); |
|
3824 | + public function deduce_fields_n_values_from_cols_n_values($cols_n_values) { |
|
3825 | + return $this->_deduce_fields_n_values_from_cols_n_values($cols_n_values); |
|
3826 | 3826 | } |
3827 | 3827 | |
3828 | 3828 | |
@@ -3835,40 +3835,40 @@ discard block |
||
3835 | 3835 | * @param string $cols_n_values |
3836 | 3836 | * @return array |
3837 | 3837 | */ |
3838 | - protected function _deduce_fields_n_values_from_cols_n_values( $cols_n_values ){ |
|
3838 | + protected function _deduce_fields_n_values_from_cols_n_values($cols_n_values) { |
|
3839 | 3839 | $this_model_fields_n_values = array(); |
3840 | - foreach( $this->get_tables() as $table_alias => $table_obj ) { |
|
3841 | - $table_pk_value = $this->_get_column_value_with_table_alias_or_not($cols_n_values, $table_obj->get_fully_qualified_pk_column(), $table_obj->get_pk_column() ); |
|
3840 | + foreach ($this->get_tables() as $table_alias => $table_obj) { |
|
3841 | + $table_pk_value = $this->_get_column_value_with_table_alias_or_not($cols_n_values, $table_obj->get_fully_qualified_pk_column(), $table_obj->get_pk_column()); |
|
3842 | 3842 | //there is a primary key on this table and its not set. Use defaults for all its columns |
3843 | - if( $table_obj->get_pk_column() && $table_pk_value === NULL ){ |
|
3844 | - foreach( $this->_get_fields_for_table( $table_alias ) as $field_name => $field_obj ) { |
|
3845 | - if( ! $field_obj->is_db_only_field() ){ |
|
3843 | + if ($table_obj->get_pk_column() && $table_pk_value === NULL) { |
|
3844 | + foreach ($this->_get_fields_for_table($table_alias) as $field_name => $field_obj) { |
|
3845 | + if ( ! $field_obj->is_db_only_field()) { |
|
3846 | 3846 | //prepare field as if its coming from db |
3847 | - $prepared_value = $field_obj->prepare_for_set( $field_obj->get_default_value() ); |
|
3848 | - $this_model_fields_n_values[$field_name] = $field_obj->prepare_for_use_in_db( $prepared_value ); |
|
3847 | + $prepared_value = $field_obj->prepare_for_set($field_obj->get_default_value()); |
|
3848 | + $this_model_fields_n_values[$field_name] = $field_obj->prepare_for_use_in_db($prepared_value); |
|
3849 | 3849 | } |
3850 | 3850 | } |
3851 | - }else{ |
|
3851 | + } else { |
|
3852 | 3852 | //the table's rows existed. Use their values |
3853 | - foreach( $this->_get_fields_for_table( $table_alias ) as $field_name => $field_obj ) { |
|
3854 | - if( ! $field_obj->is_db_only_field() ) |
|
3855 | - $this_model_fields_n_values[$field_name] = $this->_get_column_value_with_table_alias_or_not($cols_n_values, $field_obj->get_qualified_column(), $field_obj->get_table_column() ); |
|
3853 | + foreach ($this->_get_fields_for_table($table_alias) as $field_name => $field_obj) { |
|
3854 | + if ( ! $field_obj->is_db_only_field()) |
|
3855 | + $this_model_fields_n_values[$field_name] = $this->_get_column_value_with_table_alias_or_not($cols_n_values, $field_obj->get_qualified_column(), $field_obj->get_table_column()); |
|
3856 | 3856 | } |
3857 | 3857 | } |
3858 | 3858 | } |
3859 | 3859 | return $this_model_fields_n_values; |
3860 | 3860 | } |
3861 | 3861 | |
3862 | - protected function _get_column_value_with_table_alias_or_not( $cols_n_values, $qualified_column, $regular_column ){ |
|
3862 | + protected function _get_column_value_with_table_alias_or_not($cols_n_values, $qualified_column, $regular_column) { |
|
3863 | 3863 | //ask the field what it think it's table_name.column_name should be, and call it the "qualified column" |
3864 | 3864 | //does the field on the model relate to this column retrieved from the db? |
3865 | 3865 | //or is it a db-only field? (not relating to the model) |
3866 | - if( isset( $cols_n_values[ $qualified_column ] ) ){ |
|
3867 | - $value = $cols_n_values[ $qualified_column ]; |
|
3866 | + if (isset($cols_n_values[$qualified_column])) { |
|
3867 | + $value = $cols_n_values[$qualified_column]; |
|
3868 | 3868 | |
3869 | - }elseif( isset( $cols_n_values[ $regular_column ] ) ){ |
|
3870 | - $value = $cols_n_values[ $regular_column ]; |
|
3871 | - }else{ |
|
3869 | + }elseif (isset($cols_n_values[$regular_column])) { |
|
3870 | + $value = $cols_n_values[$regular_column]; |
|
3871 | + } else { |
|
3872 | 3872 | $value = NULL; |
3873 | 3873 | } |
3874 | 3874 | |
@@ -3886,23 +3886,23 @@ discard block |
||
3886 | 3886 | * @param int|string $id |
3887 | 3887 | * @return EE_Base_Class |
3888 | 3888 | */ |
3889 | - public function refresh_entity_map_from_db( $id ){ |
|
3890 | - $obj_in_map = $this->get_from_entity_map( $id ); |
|
3891 | - if( $obj_in_map ){ |
|
3892 | - $wpdb_results = $this->_get_all_wpdb_results( array( array ( $this->get_primary_key_field()->get_name() => $id ), 'limit' => 1 ) ); |
|
3893 | - if( $wpdb_results && is_array( $wpdb_results ) ){ |
|
3894 | - $one_row = reset( $wpdb_results ); |
|
3895 | - foreach( $this->_deduce_fields_n_values_from_cols_n_values($one_row ) as $field_name => $db_value ) { |
|
3896 | - $obj_in_map->set_from_db( $field_name, $db_value ); |
|
3889 | + public function refresh_entity_map_from_db($id) { |
|
3890 | + $obj_in_map = $this->get_from_entity_map($id); |
|
3891 | + if ($obj_in_map) { |
|
3892 | + $wpdb_results = $this->_get_all_wpdb_results(array(array($this->get_primary_key_field()->get_name() => $id), 'limit' => 1)); |
|
3893 | + if ($wpdb_results && is_array($wpdb_results)) { |
|
3894 | + $one_row = reset($wpdb_results); |
|
3895 | + foreach ($this->_deduce_fields_n_values_from_cols_n_values($one_row) as $field_name => $db_value) { |
|
3896 | + $obj_in_map->set_from_db($field_name, $db_value); |
|
3897 | 3897 | } |
3898 | 3898 | //clear the cache of related model objects |
3899 | - foreach ( $this->relation_settings() as $relation_name => $relation_obj ){ |
|
3900 | - $obj_in_map->clear_cache($relation_name, NULL, TRUE ); |
|
3899 | + foreach ($this->relation_settings() as $relation_name => $relation_obj) { |
|
3900 | + $obj_in_map->clear_cache($relation_name, NULL, TRUE); |
|
3901 | 3901 | } |
3902 | 3902 | } |
3903 | 3903 | return $obj_in_map; |
3904 | - }else{ |
|
3905 | - return $this->get_one_by_ID( $id ); |
|
3904 | + } else { |
|
3905 | + return $this->get_one_by_ID($id); |
|
3906 | 3906 | } |
3907 | 3907 | } |
3908 | 3908 | |
@@ -3920,24 +3920,24 @@ discard block |
||
3920 | 3920 | * @param EE_Base_Class $replacing_model_obj |
3921 | 3921 | * @return \EE_Base_Class |
3922 | 3922 | */ |
3923 | - public function refresh_entity_map_with( $id, $replacing_model_obj ) { |
|
3924 | - $obj_in_map = $this->get_from_entity_map( $id ); |
|
3925 | - if( $obj_in_map ){ |
|
3926 | - if( $replacing_model_obj instanceof EE_Base_Class ){ |
|
3927 | - foreach( $replacing_model_obj->model_field_array() as $field_name => $value ) { |
|
3928 | - $obj_in_map->set( $field_name, $value ); |
|
3923 | + public function refresh_entity_map_with($id, $replacing_model_obj) { |
|
3924 | + $obj_in_map = $this->get_from_entity_map($id); |
|
3925 | + if ($obj_in_map) { |
|
3926 | + if ($replacing_model_obj instanceof EE_Base_Class) { |
|
3927 | + foreach ($replacing_model_obj->model_field_array() as $field_name => $value) { |
|
3928 | + $obj_in_map->set($field_name, $value); |
|
3929 | 3929 | } |
3930 | 3930 | //make the model object in the entity map's cache match the $replacing_model_obj |
3931 | - foreach ( $this->relation_settings() as $relation_name => $relation_obj ){ |
|
3932 | - $obj_in_map->clear_cache($relation_name, NULL, TRUE ); |
|
3933 | - foreach( $replacing_model_obj->get_all_from_cache( $relation_name ) as $cache_id => $cached_obj ) { |
|
3934 | - $obj_in_map->cache( $relation_name, $cached_obj, $cache_id ); |
|
3931 | + foreach ($this->relation_settings() as $relation_name => $relation_obj) { |
|
3932 | + $obj_in_map->clear_cache($relation_name, NULL, TRUE); |
|
3933 | + foreach ($replacing_model_obj->get_all_from_cache($relation_name) as $cache_id => $cached_obj) { |
|
3934 | + $obj_in_map->cache($relation_name, $cached_obj, $cache_id); |
|
3935 | 3935 | } |
3936 | 3936 | } |
3937 | 3937 | } |
3938 | 3938 | return $obj_in_map; |
3939 | - }else{ |
|
3940 | - $this->add_to_entity_map( $replacing_model_obj ); |
|
3939 | + } else { |
|
3940 | + $this->add_to_entity_map($replacing_model_obj); |
|
3941 | 3941 | return $replacing_model_obj; |
3942 | 3942 | } |
3943 | 3943 | } |
@@ -3950,7 +3950,7 @@ discard block |
||
3950 | 3950 | * require_once($this->_getClassName().".class.php"); |
3951 | 3951 | * @return string |
3952 | 3952 | */ |
3953 | - private function _get_class_name(){ |
|
3953 | + private function _get_class_name() { |
|
3954 | 3954 | return "EE_".$this->get_this_model_name(); |
3955 | 3955 | } |
3956 | 3956 | |
@@ -3963,10 +3963,10 @@ discard block |
||
3963 | 3963 | * @param int $quantity |
3964 | 3964 | * @return string |
3965 | 3965 | */ |
3966 | - public function item_name($quantity = 1){ |
|
3967 | - if($quantity == 1){ |
|
3966 | + public function item_name($quantity = 1) { |
|
3967 | + if ($quantity == 1) { |
|
3968 | 3968 | return $this->singular_item; |
3969 | - }else{ |
|
3969 | + } else { |
|
3970 | 3970 | return $this->plural_item; |
3971 | 3971 | } |
3972 | 3972 | } |
@@ -3995,13 +3995,13 @@ discard block |
||
3995 | 3995 | * @throws EE_Error |
3996 | 3996 | * @return mixed whatever the plugin which calls add_filter decides |
3997 | 3997 | */ |
3998 | - public function __call($methodName,$args){ |
|
3999 | - $className=get_class($this); |
|
4000 | - $tagName="FHEE__{$className}__{$methodName}"; |
|
4001 | - if(!has_filter($tagName)){ |
|
3998 | + public function __call($methodName, $args) { |
|
3999 | + $className = get_class($this); |
|
4000 | + $tagName = "FHEE__{$className}__{$methodName}"; |
|
4001 | + if ( ! has_filter($tagName)) { |
|
4002 | 4002 | throw new EE_Error( |
4003 | 4003 | sprintf( |
4004 | - __( 'Method %1$s on model %2$s does not exist! You can create one with the following code in functions.php or in a plugin: %4$s function my_callback(%4$s \$previousReturnValue, EEM_Base \$object\ $argsArray=NULL ){%4$s /*function body*/%4$s return \$whatever;%4$s }%4$s add_filter( \'%3$s\', \'my_callback\', 10, 3 );', 'event_espresso' ), |
|
4004 | + __('Method %1$s on model %2$s does not exist! You can create one with the following code in functions.php or in a plugin: %4$s function my_callback(%4$s \$previousReturnValue, EEM_Base \$object\ $argsArray=NULL ){%4$s /*function body*/%4$s return \$whatever;%4$s }%4$s add_filter( \'%3$s\', \'my_callback\', 10, 3 );', 'event_espresso'), |
|
4005 | 4005 | $methodName, |
4006 | 4006 | $className, |
4007 | 4007 | $tagName, |
@@ -4010,7 +4010,7 @@ discard block |
||
4010 | 4010 | ); |
4011 | 4011 | } |
4012 | 4012 | |
4013 | - return apply_filters($tagName,null,$this,$args); |
|
4013 | + return apply_filters($tagName, null, $this, $args); |
|
4014 | 4014 | } |
4015 | 4015 | |
4016 | 4016 | |
@@ -4023,22 +4023,22 @@ discard block |
||
4023 | 4023 | * @throws EE_Error |
4024 | 4024 | * @return EE_Base_Class |
4025 | 4025 | */ |
4026 | - public function ensure_is_obj( $base_class_obj_or_id, $ensure_is_in_db = FALSE ){ |
|
4026 | + public function ensure_is_obj($base_class_obj_or_id, $ensure_is_in_db = FALSE) { |
|
4027 | 4027 | $className = $this->_get_class_name(); |
4028 | 4028 | $primary_key_field = $this->get_primary_key_field(); |
4029 | - if( $base_class_obj_or_id instanceof $className ){ |
|
4029 | + if ($base_class_obj_or_id instanceof $className) { |
|
4030 | 4030 | $model_object = $base_class_obj_or_id; |
4031 | - }elseif( $primary_key_field instanceof EE_Primary_Key_Int_Field && ( |
|
4032 | - is_int( $base_class_obj_or_id ) || |
|
4033 | - is_string( $base_class_obj_or_id ) )){//assume it's an ID. either a proper integer or a string representing an integer (eg "101" instead of 101) |
|
4031 | + }elseif ($primary_key_field instanceof EE_Primary_Key_Int_Field && ( |
|
4032 | + is_int($base_class_obj_or_id) || |
|
4033 | + is_string($base_class_obj_or_id) )) {//assume it's an ID. either a proper integer or a string representing an integer (eg "101" instead of 101) |
|
4034 | 4034 | $model_object = $this->get_one_by_ID($base_class_obj_or_id); |
4035 | - }elseif( $primary_key_field instanceof EE_Primary_Key_String_Field && is_string($base_class_obj_or_id) ){ |
|
4035 | + }elseif ($primary_key_field instanceof EE_Primary_Key_String_Field && is_string($base_class_obj_or_id)) { |
|
4036 | 4036 | //assume its a string representation of the object |
4037 | 4037 | $model_object = $this->get_one_by_ID($base_class_obj_or_id); |
4038 | - }else{ |
|
4039 | - throw new EE_Error(sprintf(__("'%s' is neither an object of type %s, nor an ID! Its full value is '%s'",'event_espresso'),$base_class_obj_or_id,$this->_get_class_name(),print_r($base_class_obj_or_id,true))); |
|
4038 | + } else { |
|
4039 | + throw new EE_Error(sprintf(__("'%s' is neither an object of type %s, nor an ID! Its full value is '%s'", 'event_espresso'), $base_class_obj_or_id, $this->_get_class_name(), print_r($base_class_obj_or_id, true))); |
|
4040 | 4040 | } |
4041 | - if( $model_object->ID() == NULL && $ensure_is_in_db){ |
|
4041 | + if ($model_object->ID() == NULL && $ensure_is_in_db) { |
|
4042 | 4042 | $model_object->save(); |
4043 | 4043 | } |
4044 | 4044 | return $model_object; |
@@ -4054,19 +4054,19 @@ discard block |
||
4054 | 4054 | * @return int|string depending on the type of this model object's ID |
4055 | 4055 | * @throws EE_Error |
4056 | 4056 | */ |
4057 | - public function ensure_is_ID($base_class_obj_or_id){ |
|
4057 | + public function ensure_is_ID($base_class_obj_or_id) { |
|
4058 | 4058 | $className = $this->_get_class_name(); |
4059 | - if( $base_class_obj_or_id instanceof $className ){ |
|
4059 | + if ($base_class_obj_or_id instanceof $className) { |
|
4060 | 4060 | /** @var $base_class_obj_or_id EE_Base_Class */ |
4061 | 4061 | $id = $base_class_obj_or_id->ID(); |
4062 | - }elseif(is_int($base_class_obj_or_id)){ |
|
4062 | + }elseif (is_int($base_class_obj_or_id)) { |
|
4063 | 4063 | //assume it's an ID |
4064 | 4064 | $id = $base_class_obj_or_id; |
4065 | - }elseif(is_string($base_class_obj_or_id)){ |
|
4065 | + }elseif (is_string($base_class_obj_or_id)) { |
|
4066 | 4066 | //assume its a string representation of the object |
4067 | 4067 | $id = $base_class_obj_or_id; |
4068 | - }else{ |
|
4069 | - throw new EE_Error(sprintf(__("'%s' is neither an object of type %s, nor an ID! Its full value is '%s'",'event_espresso'),$base_class_obj_or_id,$this->_get_class_name(),print_r($base_class_obj_or_id,true))); |
|
4068 | + } else { |
|
4069 | + throw new EE_Error(sprintf(__("'%s' is neither an object of type %s, nor an ID! Its full value is '%s'", 'event_espresso'), $base_class_obj_or_id, $this->_get_class_name(), print_r($base_class_obj_or_id, true))); |
|
4070 | 4070 | } |
4071 | 4071 | return $id; |
4072 | 4072 | } |
@@ -4089,14 +4089,14 @@ discard block |
||
4089 | 4089 | * @param int $values_already_prepared like one of the constants on EEM_Base |
4090 | 4090 | * @return void |
4091 | 4091 | */ |
4092 | - public function assume_values_already_prepared_by_model_object($values_already_prepared = self::not_prepared_by_model_object){ |
|
4092 | + public function assume_values_already_prepared_by_model_object($values_already_prepared = self::not_prepared_by_model_object) { |
|
4093 | 4093 | $this->_values_already_prepared_by_model_object = $values_already_prepared; |
4094 | 4094 | } |
4095 | 4095 | /** |
4096 | 4096 | * Read comments for assume_values_already_prepared_by_model_object() |
4097 | 4097 | * @return int |
4098 | 4098 | */ |
4099 | - public function get_assumption_concerning_values_already_prepared_by_model_object(){ |
|
4099 | + public function get_assumption_concerning_values_already_prepared_by_model_object() { |
|
4100 | 4100 | return $this->_values_already_prepared_by_model_object; |
4101 | 4101 | } |
4102 | 4102 | |
@@ -4104,17 +4104,17 @@ discard block |
||
4104 | 4104 | * Gets all the indexes on this model |
4105 | 4105 | * @return EE_Index[] |
4106 | 4106 | */ |
4107 | - public function indexes(){ |
|
4107 | + public function indexes() { |
|
4108 | 4108 | return $this->_indexes; |
4109 | 4109 | } |
4110 | 4110 | /** |
4111 | 4111 | * Gets all the Unique Indexes on this model |
4112 | 4112 | * @return EE_Unique_Index[] |
4113 | 4113 | */ |
4114 | - public function unique_indexes(){ |
|
4114 | + public function unique_indexes() { |
|
4115 | 4115 | $unique_indexes = array(); |
4116 | - foreach($this->_indexes as $name => $index){ |
|
4117 | - if($index instanceof EE_Unique_Index){ |
|
4116 | + foreach ($this->_indexes as $name => $index) { |
|
4117 | + if ($index instanceof EE_Unique_Index) { |
|
4118 | 4118 | $unique_indexes [$name] = $index; |
4119 | 4119 | } |
4120 | 4120 | } |
@@ -4127,9 +4127,9 @@ discard block |
||
4127 | 4127 | * on a primary index |
4128 | 4128 | * @return EE_Model_Field_Base[] |
4129 | 4129 | */ |
4130 | - public function get_combined_primary_key_fields(){ |
|
4131 | - foreach($this->indexes() as $index){ |
|
4132 | - if($index instanceof EE_Primary_Key_Index){ |
|
4130 | + public function get_combined_primary_key_fields() { |
|
4131 | + foreach ($this->indexes() as $index) { |
|
4132 | + if ($index instanceof EE_Primary_Key_Index) { |
|
4133 | 4133 | return $index->fields(); |
4134 | 4134 | } |
4135 | 4135 | } |
@@ -4142,7 +4142,7 @@ discard block |
||
4142 | 4142 | * @param array $cols_n_values keys are field names, values are their values |
4143 | 4143 | * @return string |
4144 | 4144 | */ |
4145 | - public function get_index_primary_key_string($cols_n_values){ |
|
4145 | + public function get_index_primary_key_string($cols_n_values) { |
|
4146 | 4146 | $cols_n_values_for_primary_key_index = array_intersect_key($cols_n_values, $this->get_combined_primary_key_fields()); |
4147 | 4147 | return http_build_query($cols_n_values_for_primary_key_index); |
4148 | 4148 | } |
@@ -4154,13 +4154,13 @@ discard block |
||
4154 | 4154 | * @param string $index_primary_key_string |
4155 | 4155 | * @return null|array |
4156 | 4156 | */ |
4157 | - function parse_index_primary_key_string( $index_primary_key_string) { |
|
4157 | + function parse_index_primary_key_string($index_primary_key_string) { |
|
4158 | 4158 | $key_fields = $this->get_combined_primary_key_fields(); |
4159 | 4159 | //check all of them are in the $id |
4160 | 4160 | $key_vals_in_combined_pk = array(); |
4161 | - parse_str( $index_primary_key_string, $key_vals_in_combined_pk ); |
|
4162 | - foreach( $key_fields as $key_field_name => $field_obj ) { |
|
4163 | - if( ! isset( $key_vals_in_combined_pk[ $key_field_name ] ) ){ |
|
4161 | + parse_str($index_primary_key_string, $key_vals_in_combined_pk); |
|
4162 | + foreach ($key_fields as $key_field_name => $field_obj) { |
|
4163 | + if ( ! isset($key_vals_in_combined_pk[$key_field_name])) { |
|
4164 | 4164 | return NULL; |
4165 | 4165 | } |
4166 | 4166 | } |
@@ -4173,10 +4173,10 @@ discard block |
||
4173 | 4173 | * @param array $key_vals |
4174 | 4174 | * @return boolean |
4175 | 4175 | */ |
4176 | - function has_all_combined_primary_key_fields( $key_vals ) { |
|
4177 | - $keys_it_should_have = array_keys( $this->get_combined_primary_key_fields() ); |
|
4178 | - foreach( $keys_it_should_have as $key ){ |
|
4179 | - if( ! isset( $key_vals[ $key ] ) ){ |
|
4176 | + function has_all_combined_primary_key_fields($key_vals) { |
|
4177 | + $keys_it_should_have = array_keys($this->get_combined_primary_key_fields()); |
|
4178 | + foreach ($keys_it_should_have as $key) { |
|
4179 | + if ( ! isset($key_vals[$key])) { |
|
4180 | 4180 | return false; |
4181 | 4181 | } |
4182 | 4182 | } |
@@ -4192,23 +4192,23 @@ discard block |
||
4192 | 4192 | * @throws EE_Error |
4193 | 4193 | * @return \EE_Base_Class[] Array keys are object IDs (if there is a primary key on the model. if not, numerically indexed) |
4194 | 4194 | */ |
4195 | - public function get_all_copies($model_object_or_attributes_array, $query_params = array()){ |
|
4195 | + public function get_all_copies($model_object_or_attributes_array, $query_params = array()) { |
|
4196 | 4196 | |
4197 | - if($model_object_or_attributes_array instanceof EE_Base_Class){ |
|
4197 | + if ($model_object_or_attributes_array instanceof EE_Base_Class) { |
|
4198 | 4198 | $attributes_array = $model_object_or_attributes_array->model_field_array(); |
4199 | - }elseif(is_array($model_object_or_attributes_array)){ |
|
4199 | + }elseif (is_array($model_object_or_attributes_array)) { |
|
4200 | 4200 | $attributes_array = $model_object_or_attributes_array; |
4201 | - }else{ |
|
4202 | - throw new EE_Error(sprintf(__("get_all_copies should be provided with either a model object or an array of field-value-pairs, but was given %s", "event_espresso"),$model_object_or_attributes_array)); |
|
4201 | + } else { |
|
4202 | + throw new EE_Error(sprintf(__("get_all_copies should be provided with either a model object or an array of field-value-pairs, but was given %s", "event_espresso"), $model_object_or_attributes_array)); |
|
4203 | 4203 | } |
4204 | 4204 | //even copies obviously won't have the same ID, so remove the primary key |
4205 | 4205 | //from the WHERE conditions for finding copies (if there is a primary key, of course) |
4206 | - if($this->has_primary_key_field() && isset($attributes_array[$this->primary_key_name()])){ |
|
4206 | + if ($this->has_primary_key_field() && isset($attributes_array[$this->primary_key_name()])) { |
|
4207 | 4207 | unset($attributes_array[$this->primary_key_name()]); |
4208 | 4208 | } |
4209 | - if(isset($query_params[0])){ |
|
4210 | - $query_params[0] = array_merge($attributes_array,$query_params); |
|
4211 | - }else{ |
|
4209 | + if (isset($query_params[0])) { |
|
4210 | + $query_params[0] = array_merge($attributes_array, $query_params); |
|
4211 | + } else { |
|
4212 | 4212 | $query_params[0] = $attributes_array; |
4213 | 4213 | } |
4214 | 4214 | return $this->get_all($query_params); |
@@ -4222,16 +4222,16 @@ discard block |
||
4222 | 4222 | * @param array $query_params |
4223 | 4223 | * @return EE_Base_Class |
4224 | 4224 | */ |
4225 | - function get_one_copy($model_object_or_attributes_array,$query_params = array()){ |
|
4226 | - if( ! is_array( $query_params ) ){ |
|
4227 | - EE_Error::doing_it_wrong('EEM_Base::get_one_copy', sprintf( __( '$query_params should be an array, you passed a variable of type %s', 'event_espresso' ), gettype( $query_params ) ), '4.6.0' ); |
|
4225 | + function get_one_copy($model_object_or_attributes_array, $query_params = array()) { |
|
4226 | + if ( ! is_array($query_params)) { |
|
4227 | + EE_Error::doing_it_wrong('EEM_Base::get_one_copy', sprintf(__('$query_params should be an array, you passed a variable of type %s', 'event_espresso'), gettype($query_params)), '4.6.0'); |
|
4228 | 4228 | $query_params = array(); |
4229 | 4229 | } |
4230 | 4230 | $query_params['limit'] = 1; |
4231 | - $copies = $this->get_all_copies($model_object_or_attributes_array,$query_params); |
|
4232 | - if(is_array($copies)){ |
|
4231 | + $copies = $this->get_all_copies($model_object_or_attributes_array, $query_params); |
|
4232 | + if (is_array($copies)) { |
|
4233 | 4233 | return array_shift($copies); |
4234 | - }else{ |
|
4234 | + } else { |
|
4235 | 4235 | return null; |
4236 | 4236 | } |
4237 | 4237 | } |
@@ -4245,10 +4245,10 @@ discard block |
||
4245 | 4245 | * @param int|string $id the value of the primary key to update |
4246 | 4246 | * @return int number of rows updated |
4247 | 4247 | */ |
4248 | - public function update_by_ID($fields_n_values,$id){ |
|
4248 | + public function update_by_ID($fields_n_values, $id) { |
|
4249 | 4249 | $query_params = array(0=>array($this->get_primary_key_field()->get_name() => $id), |
4250 | 4250 | 'default_where_conditions'=>'other_models_only',); |
4251 | - return $this->update($fields_n_values,$query_params); |
|
4251 | + return $this->update($fields_n_values, $query_params); |
|
4252 | 4252 | } |
4253 | 4253 | |
4254 | 4254 | |
@@ -4259,12 +4259,12 @@ discard block |
||
4259 | 4259 | * @return string an operator which can be used in SQL |
4260 | 4260 | * @throws EE_Error |
4261 | 4261 | */ |
4262 | - private function _prepare_operator_for_sql($operator_supplied){ |
|
4262 | + private function _prepare_operator_for_sql($operator_supplied) { |
|
4263 | 4263 | $sql_operator = isset($this->_valid_operators[$operator_supplied]) ? $this->_valid_operators[$operator_supplied] : null; |
4264 | - if($sql_operator){ |
|
4264 | + if ($sql_operator) { |
|
4265 | 4265 | return $sql_operator; |
4266 | - }else{ |
|
4267 | - throw new EE_Error(sprintf(__("The operator '%s' is not in the list of valid operators: %s", "event_espresso"),$operator_supplied,implode(",",array_keys($this->_valid_operators)))); |
|
4266 | + } else { |
|
4267 | + throw new EE_Error(sprintf(__("The operator '%s' is not in the list of valid operators: %s", "event_espresso"), $operator_supplied, implode(",", array_keys($this->_valid_operators)))); |
|
4268 | 4268 | } |
4269 | 4269 | } |
4270 | 4270 | |
@@ -4274,10 +4274,10 @@ discard block |
||
4274 | 4274 | * @param array $query_params like get_all's |
4275 | 4275 | * @return string[] |
4276 | 4276 | */ |
4277 | - public function get_all_names($query_params = array()){ |
|
4277 | + public function get_all_names($query_params = array()) { |
|
4278 | 4278 | $objs = $this->get_all($query_params); |
4279 | 4279 | $names = array(); |
4280 | - foreach($objs as $obj){ |
|
4280 | + foreach ($objs as $obj) { |
|
4281 | 4281 | $names[$obj->ID()] = $obj->name(); |
4282 | 4282 | } |
4283 | 4283 | return $names; |
@@ -4292,22 +4292,22 @@ discard block |
||
4292 | 4292 | * @param boolean $filter_out_empty_ids if a model object has an ID of '' or 0, don't bother including it in the returned array |
4293 | 4293 | * @return array |
4294 | 4294 | */ |
4295 | - public function get_IDs( $model_objects, $filter_out_empty_ids = false) { |
|
4296 | - if( ! $this->has_primary_key_field() ) { |
|
4297 | - if( WP_DEBUG ) { |
|
4298 | - EE_Error::add_error( __( 'Trying to get IDs from a model than has no primary key', 'event_espresso' ), __FILE__, __FUNCTION__, __LINE__ ); |
|
4295 | + public function get_IDs($model_objects, $filter_out_empty_ids = false) { |
|
4296 | + if ( ! $this->has_primary_key_field()) { |
|
4297 | + if (WP_DEBUG) { |
|
4298 | + EE_Error::add_error(__('Trying to get IDs from a model than has no primary key', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__); |
|
4299 | 4299 | return array(); |
4300 | 4300 | } |
4301 | 4301 | } |
4302 | 4302 | $IDs = array(); |
4303 | - foreach( $model_objects as $model_object ) { |
|
4303 | + foreach ($model_objects as $model_object) { |
|
4304 | 4304 | $id = $model_object->ID(); |
4305 | - if( ! $id ) { |
|
4306 | - if( $filter_out_empty_ids ) { |
|
4305 | + if ( ! $id) { |
|
4306 | + if ($filter_out_empty_ids) { |
|
4307 | 4307 | continue; |
4308 | 4308 | } |
4309 | - if( WP_DEBUG ) { |
|
4310 | - EE_Error::add_error(__( 'Called %1$s on a model object that has no ID and so probably hasn\'t been saved to the database', 'event_espresso' ), __FILE__, __FUNCTION__, __LINE__ ); |
|
4309 | + if (WP_DEBUG) { |
|
4310 | + EE_Error::add_error(__('Called %1$s on a model object that has no ID and so probably hasn\'t been saved to the database', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__); |
|
4311 | 4311 | } |
4312 | 4312 | } |
4313 | 4313 | $IDs[] = $id; |
@@ -4320,8 +4320,8 @@ discard block |
||
4320 | 4320 | * are no capabilities that relate to this model returns false |
4321 | 4321 | * @return string|false |
4322 | 4322 | */ |
4323 | - public function cap_slug(){ |
|
4324 | - return apply_filters( 'FHEE__EEM_Base__cap_slug', $this->_caps_slug, $this); |
|
4323 | + public function cap_slug() { |
|
4324 | + return apply_filters('FHEE__EEM_Base__cap_slug', $this->_caps_slug, $this); |
|
4325 | 4325 | } |
4326 | 4326 | |
4327 | 4327 | /** |
@@ -4333,27 +4333,27 @@ discard block |
||
4333 | 4333 | * @param string $context |
4334 | 4334 | * @return EE_Default_Where_Conditions[] indexed by associated capability |
4335 | 4335 | */ |
4336 | - public function cap_restrictions( $context = EEM_Base::caps_read ) { |
|
4337 | - EEM_Base::verify_is_valid_cap_context( $context ); |
|
4336 | + public function cap_restrictions($context = EEM_Base::caps_read) { |
|
4337 | + EEM_Base::verify_is_valid_cap_context($context); |
|
4338 | 4338 | //check if we ought to run the restriction generator first |
4339 | - if( isset( $this->_cap_restriction_generators[ $context ] ) && |
|
4340 | - $this->_cap_restriction_generators[ $context ] instanceof EE_Restriction_Generator_Base && |
|
4341 | - ! $this->_cap_restriction_generators[ $context ]->has_generated_cap_restrictions() ) { |
|
4342 | - $this->_cap_restrictions[ $context ] = array_merge( $this->_cap_restrictions[ $context ], $this->_cap_restriction_generators[ $context ]->generate_restrictions() ); |
|
4339 | + if (isset($this->_cap_restriction_generators[$context]) && |
|
4340 | + $this->_cap_restriction_generators[$context] instanceof EE_Restriction_Generator_Base && |
|
4341 | + ! $this->_cap_restriction_generators[$context]->has_generated_cap_restrictions()) { |
|
4342 | + $this->_cap_restrictions[$context] = array_merge($this->_cap_restrictions[$context], $this->_cap_restriction_generators[$context]->generate_restrictions()); |
|
4343 | 4343 | } |
4344 | 4344 | //and make sure we've finalized the construction of each restriction |
4345 | - foreach( $this->_cap_restrictions[ $context ] as $where_conditions_obj ) { |
|
4346 | - $where_conditions_obj->_finalize_construct( $this ); |
|
4345 | + foreach ($this->_cap_restrictions[$context] as $where_conditions_obj) { |
|
4346 | + $where_conditions_obj->_finalize_construct($this); |
|
4347 | 4347 | } |
4348 | 4348 | |
4349 | - return $this->_cap_restrictions[ $context ]; |
|
4349 | + return $this->_cap_restrictions[$context]; |
|
4350 | 4350 | } |
4351 | 4351 | |
4352 | 4352 | /** |
4353 | 4353 | * Indicating whether or not this model thinks its a wp core model |
4354 | 4354 | * @return boolean |
4355 | 4355 | */ |
4356 | - public function is_wp_core_model(){ |
|
4356 | + public function is_wp_core_model() { |
|
4357 | 4357 | return $this->_wp_core_model; |
4358 | 4358 | } |
4359 | 4359 | |
@@ -4363,12 +4363,12 @@ discard block |
||
4363 | 4363 | * @param string $context one of EEM_Base::caps_ constants |
4364 | 4364 | * @return EE_Default_Where_Conditions[] indexed by capability name |
4365 | 4365 | */ |
4366 | - public function caps_missing( $context = EEM_Base::caps_read ) { |
|
4366 | + public function caps_missing($context = EEM_Base::caps_read) { |
|
4367 | 4367 | $missing_caps = array(); |
4368 | - $cap_restrictions = $this->cap_restrictions( $context ); |
|
4369 | - foreach( $cap_restrictions as $cap => $restriction_if_no_cap ) { |
|
4370 | - if( ! EE_Capabilities::instance()->current_user_can( $cap, $this->get_this_model_name() . '_model_applying_caps') ) { |
|
4371 | - $missing_caps[ $cap ] = $restriction_if_no_cap; |
|
4368 | + $cap_restrictions = $this->cap_restrictions($context); |
|
4369 | + foreach ($cap_restrictions as $cap => $restriction_if_no_cap) { |
|
4370 | + if ( ! EE_Capabilities::instance()->current_user_can($cap, $this->get_this_model_name().'_model_applying_caps')) { |
|
4371 | + $missing_caps[$cap] = $restriction_if_no_cap; |
|
4372 | 4372 | } |
4373 | 4373 | } |
4374 | 4374 | return $missing_caps; |
@@ -4380,7 +4380,7 @@ discard block |
||
4380 | 4380 | * one of 'read', 'edit', or 'delete' |
4381 | 4381 | */ |
4382 | 4382 | public function cap_contexts_to_cap_action_map() { |
4383 | - return apply_filters( 'FHEE__EEM_Base__cap_contexts_to_cap_action_map', $this->_cap_contexts_to_cap_action_map, $this ); |
|
4383 | + return apply_filters('FHEE__EEM_Base__cap_contexts_to_cap_action_map', $this->_cap_contexts_to_cap_action_map, $this); |
|
4384 | 4384 | } |
4385 | 4385 | |
4386 | 4386 | |
@@ -4391,19 +4391,19 @@ discard block |
||
4391 | 4391 | * @return string one of EEM_Base::cap_contexts_to_cap_action_map() values |
4392 | 4392 | * @throws \EE_Error |
4393 | 4393 | */ |
4394 | - public function cap_action_for_context( $context ) { |
|
4394 | + public function cap_action_for_context($context) { |
|
4395 | 4395 | $mapping = $this->cap_contexts_to_cap_action_map(); |
4396 | - if( isset( $mapping[ $context ] ) ) { |
|
4397 | - return $mapping[ $context ]; |
|
4396 | + if (isset($mapping[$context])) { |
|
4397 | + return $mapping[$context]; |
|
4398 | 4398 | } |
4399 | - if( $action = apply_filters( 'FHEE__EEM_Base__cap_action_for_context', null, $this, $mapping, $context ) ) { |
|
4399 | + if ($action = apply_filters('FHEE__EEM_Base__cap_action_for_context', null, $this, $mapping, $context)) { |
|
4400 | 4400 | return $action; |
4401 | 4401 | } |
4402 | 4402 | throw new EE_Error( |
4403 | 4403 | sprintf( |
4404 | - __( 'Cannot find capability restrictions for context "%1$s", allowed values are:%2$s', 'event_espresso' ), |
|
4404 | + __('Cannot find capability restrictions for context "%1$s", allowed values are:%2$s', 'event_espresso'), |
|
4405 | 4405 | $context, |
4406 | - implode(',', array_keys( $this->cap_contexts_to_cap_action_map() ) ) |
|
4406 | + implode(',', array_keys($this->cap_contexts_to_cap_action_map())) |
|
4407 | 4407 | ) |
4408 | 4408 | ); |
4409 | 4409 | |
@@ -4414,7 +4414,7 @@ discard block |
||
4414 | 4414 | * @return array |
4415 | 4415 | */ |
4416 | 4416 | static public function valid_cap_contexts() { |
4417 | - return apply_filters( 'FHEE__EEM_Base__valid_cap_contexts', array( |
|
4417 | + return apply_filters('FHEE__EEM_Base__valid_cap_contexts', array( |
|
4418 | 4418 | self::caps_read, |
4419 | 4419 | self::caps_read_admin, |
4420 | 4420 | self::caps_edit, |
@@ -4430,17 +4430,17 @@ discard block |
||
4430 | 4430 | * @return bool |
4431 | 4431 | * @throws \EE_Error |
4432 | 4432 | */ |
4433 | - static public function verify_is_valid_cap_context( $context ) { |
|
4433 | + static public function verify_is_valid_cap_context($context) { |
|
4434 | 4434 | $valid_cap_contexts = EEM_Base::valid_cap_contexts(); |
4435 | - if( in_array( $context, $valid_cap_contexts ) ) { |
|
4435 | + if (in_array($context, $valid_cap_contexts)) { |
|
4436 | 4436 | return true; |
4437 | - }else{ |
|
4437 | + } else { |
|
4438 | 4438 | throw new EE_Error( |
4439 | 4439 | sprintf( |
4440 | - __( 'Context "%1$s" passed into model "%2$s" is not a valid context. They are: %3$s', 'event_espresso' ), |
|
4440 | + __('Context "%1$s" passed into model "%2$s" is not a valid context. They are: %3$s', 'event_espresso'), |
|
4441 | 4441 | $context, |
4442 | - 'EEM_Base' , |
|
4443 | - implode(',', $valid_cap_contexts ) |
|
4442 | + 'EEM_Base', |
|
4443 | + implode(',', $valid_cap_contexts) |
|
4444 | 4444 | ) |
4445 | 4445 | ); |
4446 | 4446 | } |