Completed
Branch BUG-9467-never-double-install-... (7d31d4)
by
unknown
358:28 queued 341:17
created
core/db_models/EEM_Base.model.php 1 patch
Spacing   +955 added lines, -955 removed lines patch added patch discarded remove patch
@@ -23,7 +23,7 @@  discard block
 block discarded – undo
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
@@ -235,7 +235,7 @@  discard block
 block discarded – undo
235 235
 	 * Flag indicating whether this model has a primary key or not
236 236
 	 * @var boolean
237 237
 	 */
238
-	protected $_has_primary_key_field=null;
238
+	protected $_has_primary_key_field = null;
239 239
 
240 240
 	/**
241 241
 	 * Whether or not this model is based off a table in WP core only (CPTs should set
@@ -297,19 +297,19 @@  discard block
 block discarded – undo
297 297
 	 * operators that work like 'BETWEEN'.  Typically used for datetime calculations, i.e. "BETWEEN '12-1-2011' AND '12-31-2012'"
298 298
 	 * @var array
299 299
 	 */
300
-	protected $_between_style_operators = array( 'BETWEEN' );
300
+	protected $_between_style_operators = array('BETWEEN');
301 301
 
302 302
 	/**
303 303
 	 * operators that are used for handling NUll and !NULL queries.  Typically used for when checking if a row exists on a join table.
304 304
 	 * @var array
305 305
 	 */
306
-	protected $_null_style_operators = array( 'IS NOT NULL', 'IS NULL');
306
+	protected $_null_style_operators = array('IS NOT NULL', 'IS NULL');
307 307
 
308 308
 	/**
309 309
 	 * Allowed values for $query_params['order'] for ordering in queries
310 310
 	 * @var array
311 311
 	 */
312
-	protected $_allowed_order_values = array('asc','desc','ASC','DESC');
312
+	protected $_allowed_order_values = array('asc', 'desc', 'ASC', 'DESC');
313 313
 
314 314
 	/**
315 315
 	 * When these are keys in a WHERE or HAVING clause, they are handled much differently
@@ -323,13 +323,13 @@  discard block
 block discarded – undo
323 323
 	 * 'where', but 'where' clauses are so common that we thought we'd omit it
324 324
 	 * @var array
325 325
 	 */
326
-	private $_allowed_query_params = array(0, 'limit','order_by','group_by','having','force_join','order','on_join_limit','default_where_conditions', 'caps');
326
+	private $_allowed_query_params = array(0, 'limit', 'order_by', 'group_by', 'having', 'force_join', 'order', 'on_join_limit', 'default_where_conditions', 'caps');
327 327
 
328 328
 	/**
329 329
 	 * All the data types that can be used in $wpdb->prepare statements.
330 330
 	 * @var array
331 331
 	 */
332
-	private $_valid_wpdb_data_types = array('%d','%s','%f');
332
+	private $_valid_wpdb_data_types = array('%d', '%s', '%f');
333 333
 
334 334
 	/**
335 335
 	 * 	EE_Registry Object
@@ -362,17 +362,17 @@  discard block
 block discarded – undo
362 362
 	/**
363 363
 	 * constant used to show EEM_Base has not yet verified the db on this http request
364 364
 	 */
365
-	const db_verified_none 		= 0;
365
+	const db_verified_none = 0;
366 366
 	/**
367 367
 	 * constant used to show EEM_Base has verified the EE core db on this http request,
368 368
 	 * but not the addons' dbs
369 369
 	 */
370
-	const db_verified_core 		= 1;
370
+	const db_verified_core = 1;
371 371
 	/**
372 372
 	 * constant used to show EEM_Base has verified the addons' dbs (and implicitly
373 373
 	 * the EE core db too)
374 374
 	 */
375
-	const db_verified_addons 	= 2;
375
+	const db_verified_addons = 2;
376 376
 
377 377
 	/**
378 378
 	 * indicates whether an EEM_Base child has already re-verified the DB
@@ -403,13 +403,13 @@  discard block
 block discarded – undo
403 403
 	 * @param null $timezone
404 404
 	 * @throws \EE_Error
405 405
 	 */
406
-	protected function __construct( $timezone = NULL ){
406
+	protected function __construct($timezone = NULL) {
407 407
 		// check that the model has not been loaded too soon
408
-		if ( ! did_action( 'AHEE__EE_System__load_espresso_addons' )) {
409
-			throw new EE_Error (
408
+		if ( ! did_action('AHEE__EE_System__load_espresso_addons')) {
409
+			throw new EE_Error(
410 410
 				sprintf(
411
-					__( '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' ),
412
-					get_class( $this )
411
+					__('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'),
412
+					get_class($this)
413 413
 				)
414 414
 			);
415 415
 		}
@@ -419,11 +419,11 @@  discard block
 block discarded – undo
419 419
 		 * just use EE_Register_Model_Extension
420 420
 		 * @var EE_Table_Base[] $_tables
421 421
 		 */
422
-		$this->_tables = apply_filters( 'FHEE__'.get_class($this).'__construct__tables', $this->_tables );
423
-		foreach($this->_tables as $table_alias => $table_obj){
422
+		$this->_tables = apply_filters('FHEE__'.get_class($this).'__construct__tables', $this->_tables);
423
+		foreach ($this->_tables as $table_alias => $table_obj) {
424 424
 			/** @var $table_obj EE_Table_Base */
425 425
 			$table_obj->_construct_finalize_with_alias($table_alias);
426
-			if( $table_obj instanceof EE_Secondary_Table ){
426
+			if ($table_obj instanceof EE_Secondary_Table) {
427 427
 				/** @var $table_obj EE_Secondary_Table */
428 428
 				$table_obj->_construct_finalize_set_table_to_join_with($this->_get_main_table());
429 429
 			}
@@ -433,54 +433,54 @@  discard block
 block discarded – undo
433 433
 		 * EE_Register_Model_Extension
434 434
 		 * @param EE_Model_Field_Base[] $_fields
435 435
 		 */
436
-		$this->_fields = apply_filters('FHEE__'.get_class($this).'__construct__fields',$this->_fields);
436
+		$this->_fields = apply_filters('FHEE__'.get_class($this).'__construct__fields', $this->_fields);
437 437
 		$this->_invalidate_field_caches();
438
-		foreach($this->_fields as $table_alias => $fields_for_table){
439
-			if ( ! array_key_exists( $table_alias, $this->_tables )){
440
-				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)));
438
+		foreach ($this->_fields as $table_alias => $fields_for_table) {
439
+			if ( ! array_key_exists($table_alias, $this->_tables)) {
440
+				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)));
441 441
 			}
442
-			foreach($fields_for_table as $field_name => $field_obj){
442
+			foreach ($fields_for_table as $field_name => $field_obj) {
443 443
 				/** @var $field_obj EE_Model_Field_Base | EE_Primary_Key_Field_Base */
444 444
 				//primary key field base has a slightly different _construct_finalize
445 445
 				/** @var $field_obj EE_Model_Field_Base */
446
-				$field_obj->_construct_finalize( $table_alias, $field_name, $this->get_this_model_name() );
446
+				$field_obj->_construct_finalize($table_alias, $field_name, $this->get_this_model_name());
447 447
 			}
448 448
 		}
449 449
 
450 450
 		// everything is related to Extra_Meta
451
-		if( get_class($this) != 'EEM_Extra_Meta'){
451
+		if (get_class($this) != 'EEM_Extra_Meta') {
452 452
 			//make extra meta related to everything, but don't block deleting things just
453 453
 			//because they have related extra meta info. For now just orphan those extra meta
454 454
 			//in the future we should automatically delete them
455
-			$this->_model_relations['Extra_Meta'] = new EE_Has_Many_Any_Relation( FALSE );
455
+			$this->_model_relations['Extra_Meta'] = new EE_Has_Many_Any_Relation(FALSE);
456 456
 		}
457 457
 		//and change logs
458
-		if( get_class( $this) !=  'EEM_Change_Log' ) {
459
-			$this->_model_relations[ 'Change_Log' ] = new EE_Has_Many_Any_Relation( FALSE );
458
+		if (get_class($this) != 'EEM_Change_Log') {
459
+			$this->_model_relations['Change_Log'] = new EE_Has_Many_Any_Relation(FALSE);
460 460
 		}
461 461
 		/**
462 462
 		 * Filters the list of relations on a model. It is best to NOT use this directly and instead just use
463 463
 		 * EE_Register_Model_Extension
464 464
 		 * @param EE_Model_Relation_Base[] $_model_relations
465 465
 		 */
466
-		$this->_model_relations = apply_filters('FHEE__'.get_class($this).'__construct__model_relations',$this->_model_relations);
467
-		foreach($this->_model_relations as $model_name => $relation_obj){
466
+		$this->_model_relations = apply_filters('FHEE__'.get_class($this).'__construct__model_relations', $this->_model_relations);
467
+		foreach ($this->_model_relations as $model_name => $relation_obj) {
468 468
 			/** @var $relation_obj EE_Model_Relation_Base */
469 469
 			$relation_obj->_construct_finalize_set_models($this->get_this_model_name(), $model_name);
470 470
 		}
471
-		foreach($this->_indexes as $index_name => $index_obj){
471
+		foreach ($this->_indexes as $index_name => $index_obj) {
472 472
 			/** @var $index_obj EE_Index */
473 473
 			$index_obj->_construct_finalize($index_name, $this->get_this_model_name());
474 474
 		}
475 475
 
476 476
 		$this->set_timezone($timezone);
477 477
 		//finalize default where condition strategy, or set default
478
-		if( ! $this->_default_where_conditions_strategy){
478
+		if ( ! $this->_default_where_conditions_strategy) {
479 479
 			//nothing was set during child constructor, so set default
480 480
 			$this->_default_where_conditions_strategy = new EE_Default_Where_Conditions();
481 481
 		}
482 482
 		$this->_default_where_conditions_strategy->_finalize_construct($this);
483
-		if( ! $this->_minimum_where_conditions_strategy){
483
+		if ( ! $this->_minimum_where_conditions_strategy) {
484 484
 			//nothing was set during child constructor, so set default
485 485
 			$this->_minimum_where_conditions_strategy = new EE_Default_Where_Conditions();
486 486
 		}
@@ -488,15 +488,15 @@  discard block
 block discarded – undo
488 488
 
489 489
 		//if the cap slug hasn't been set, and we haven't set it to false on purpose
490 490
 		//to indicate to NOT set it, set it to the logical default
491
-		if( $this->_caps_slug === null ) {
492
-			EE_Registry::instance()->load_helper( 'Inflector' );
493
-			$this->_caps_slug = EEH_Inflector::pluralize_and_lower( $this->get_this_model_name() );
491
+		if ($this->_caps_slug === null) {
492
+			EE_Registry::instance()->load_helper('Inflector');
493
+			$this->_caps_slug = EEH_Inflector::pluralize_and_lower($this->get_this_model_name());
494 494
 		}
495 495
 		//initialize the standard cap restriction generators if none were specified by the child constructor
496
-		if( $this->_cap_restriction_generators !== false ){
497
-			foreach( $this->cap_contexts_to_cap_action_map() as $cap_context => $action ){
498
-				if( ! isset( $this->_cap_restriction_generators[ $cap_context ] ) ) {
499
-					$this->_cap_restriction_generators[ $cap_context ] = apply_filters(
496
+		if ($this->_cap_restriction_generators !== false) {
497
+			foreach ($this->cap_contexts_to_cap_action_map() as $cap_context => $action) {
498
+				if ( ! isset($this->_cap_restriction_generators[$cap_context])) {
499
+					$this->_cap_restriction_generators[$cap_context] = apply_filters(
500 500
 						'FHEE__EEM_Base___construct__standard_cap_restriction_generator',
501 501
 						new EE_Restriction_Generator_Protected(),
502 502
 						$cap_context,
@@ -506,23 +506,23 @@  discard block
 block discarded – undo
506 506
 			}
507 507
 		}
508 508
 		//if there are cap restriction generators, use them to make the default cap restrictions
509
-		if( $this->_cap_restriction_generators !== false ){
510
-			foreach( $this->_cap_restriction_generators as $context => $generator_object ) {
511
-				if( ! $generator_object ){
509
+		if ($this->_cap_restriction_generators !== false) {
510
+			foreach ($this->_cap_restriction_generators as $context => $generator_object) {
511
+				if ( ! $generator_object) {
512 512
 					continue;
513 513
 				}
514
-				if( ! $generator_object instanceof EE_Restriction_Generator_Base ){
514
+				if ( ! $generator_object instanceof EE_Restriction_Generator_Base) {
515 515
 					throw new EE_Error(
516 516
 						sprintf(
517
-							__( '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' ),
517
+							__('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'),
518 518
 							$context,
519 519
 							$this->get_this_model_name()
520 520
 						)
521 521
 					);
522 522
 				}
523
-				$action = $this->cap_action_for_context( $context );
524
-				if( ! $generator_object->construction_finalized() ){
525
-					$generator_object->_construct_finalize( $this, $action );
523
+				$action = $this->cap_action_for_context($context);
524
+				if ( ! $generator_object->construction_finalized()) {
525
+					$generator_object->_construct_finalize($this, $action);
526 526
 				}
527 527
 
528 528
 			}
@@ -536,11 +536,11 @@  discard block
 block discarded – undo
536 536
 	 * @param string $context one of EEM_Base::valid_cap_contexts()
537 537
 	 * @return EE_Default_Where_Conditions[]
538 538
 	 */
539
-	protected function _generate_cap_restrictions( $context ){
540
-		if( isset( $this->_cap_restriction_generators[ $context ] ) &&
541
-				$this->_cap_restriction_generators[ $context ] instanceof EE_Restriction_Generator_Base ) {
542
-			return $this->_cap_restriction_generators[ $context ]->generate_restrictions();
543
-		}else{
539
+	protected function _generate_cap_restrictions($context) {
540
+		if (isset($this->_cap_restriction_generators[$context]) &&
541
+				$this->_cap_restriction_generators[$context] instanceof EE_Restriction_Generator_Base) {
542
+			return $this->_cap_restriction_generators[$context]->generate_restrictions();
543
+		} else {
544 544
 			return array();
545 545
 		}
546 546
 }
@@ -553,16 +553,16 @@  discard block
 block discarded – undo
553 553
 	 *		@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)
554 554
 	 *		@return static (as in the concrete child class)
555 555
 	 */
556
-	public static function instance( $timezone = NULL ){
556
+	public static function instance($timezone = NULL) {
557 557
 
558 558
 		// check if instance of Espresso_model already exists
559 559
 		if ( ! static::$_instance instanceof static) {
560 560
 			// instantiate Espresso_model
561
-			static::$_instance = new static( $timezone );
561
+			static::$_instance = new static($timezone);
562 562
 		}
563 563
 
564 564
 		//we might have a timezone set, let set_timezone decide what to do with it
565
-		static::$_instance->set_timezone( $timezone );
565
+		static::$_instance->set_timezone($timezone);
566 566
 
567 567
 		// Espresso_model object
568 568
 		return static::$_instance;
@@ -575,11 +575,11 @@  discard block
 block discarded – undo
575 575
 	 * @param null | string $timezone
576 576
 	 * @return static
577 577
 	 */
578
-	public static function reset(  $timezone = NULL ){
579
-		if ( ! is_null( static::$_instance ) ) {
578
+	public static function reset($timezone = NULL) {
579
+		if ( ! is_null(static::$_instance)) {
580 580
 			static::$_instance = null;
581 581
 
582
-			return self::instance( $timezone );
582
+			return self::instance($timezone);
583 583
 		}
584 584
 		return null;
585 585
 	}
@@ -590,15 +590,15 @@  discard block
 block discarded – undo
590 590
 	 * @param  boolean $translated return localized strings or JUST the array.
591 591
 	 * @return array
592 592
 	 */
593
-	 public function status_array( $translated = FALSE ) {
594
-	 	if ( !array_key_exists('Status', $this->_model_relations ) )
593
+	 public function status_array($translated = FALSE) {
594
+	 	if ( ! array_key_exists('Status', $this->_model_relations))
595 595
 	 		return array();
596 596
 	 	$model_name = $this->get_this_model_name();
597
-	 	$status_type = str_replace(' ', '_', strtolower( str_replace('_', ' ', $model_name) ) );
598
-	 	$stati = EEM_Status::instance()->get_all(array(array('STS_type' => $status_type) ) );
597
+	 	$status_type = str_replace(' ', '_', strtolower(str_replace('_', ' ', $model_name)));
598
+	 	$stati = EEM_Status::instance()->get_all(array(array('STS_type' => $status_type)));
599 599
 	 	$status_array = array();
600
-	 	foreach ( $stati as $status ) {
601
-            $status_array[ $status->ID() ] = $status->get('STS_code');
600
+	 	foreach ($stati as $status) {
601
+            $status_array[$status->ID()] = $status->get('STS_code');
602 602
         }
603 603
         return $translated ? EEM_Status::instance()->localized_status($status_array, FALSE, 'sentence') : $status_array;
604 604
     }
@@ -738,7 +738,7 @@  discard block
 block discarded – undo
738 738
 	 *			'order_by'=>array('ANS_value'=>'ASC')
739 739
 	 *		));
740 740
 	 */
741
-	function get_all($query_params = array()){
741
+	function get_all($query_params = array()) {
742 742
 		return $this->_create_objects($this->_get_all_wpdb_results($query_params, ARRAY_A, NULL));
743 743
 	}
744 744
 
@@ -748,10 +748,10 @@  discard block
 block discarded – undo
748 748
 	 * @param array $query_params @see EEM_Base::get_all()
749 749
 	 * @return array like EEM_Base::get_all
750 750
 	 */
751
-	function alter_query_params_to_only_include_mine( $query_params = array() ) {
751
+	function alter_query_params_to_only_include_mine($query_params = array()) {
752 752
 		$wp_user_field_name = $this->wp_user_field_name();
753
-		if( $wp_user_field_name ){
754
-			$query_params[0][ $wp_user_field_name ] = get_current_user_id();
753
+		if ($wp_user_field_name) {
754
+			$query_params[0][$wp_user_field_name] = get_current_user_id();
755 755
 		}
756 756
 		return $query_params;
757 757
 	}
@@ -764,19 +764,19 @@  discard block
 block discarded – undo
764 764
 	 * foreign key to the WP_User table
765 765
 	 */
766 766
 	function wp_user_field_name() {
767
-		try{
768
-			if( ! empty( $this->_model_chain_to_wp_user ) ) {
769
-				$models_to_follow_to_wp_users = explode( '.', $this->_model_chain_to_wp_user );
770
-				$last_model_name = end( $models_to_follow_to_wp_users );
771
-				$model_with_fk_to_wp_users = EE_Registry::instance()->load_model( $last_model_name );
772
-				$model_chain_to_wp_user = $this->_model_chain_to_wp_user . '.';
773
-			}else{
767
+		try {
768
+			if ( ! empty($this->_model_chain_to_wp_user)) {
769
+				$models_to_follow_to_wp_users = explode('.', $this->_model_chain_to_wp_user);
770
+				$last_model_name = end($models_to_follow_to_wp_users);
771
+				$model_with_fk_to_wp_users = EE_Registry::instance()->load_model($last_model_name);
772
+				$model_chain_to_wp_user = $this->_model_chain_to_wp_user.'.';
773
+			} else {
774 774
 				$model_with_fk_to_wp_users = $this;
775 775
 				$model_chain_to_wp_user = '';
776 776
 			}
777
-			$wp_user_field = $model_with_fk_to_wp_users->get_foreign_key_to( 'WP_User' );
778
-			return $model_chain_to_wp_user . $wp_user_field->get_name();
779
-		}catch( EE_Error $e ) {
777
+			$wp_user_field = $model_with_fk_to_wp_users->get_foreign_key_to('WP_User');
778
+			return $model_chain_to_wp_user.$wp_user_field->get_name();
779
+		} catch (EE_Error $e) {
780 780
 			return false;
781 781
 		}
782 782
 	}
@@ -790,7 +790,7 @@  discard block
 block discarded – undo
790 790
 	 * (or transiently-related model)
791 791
 	 * @return string
792 792
 	 */
793
-	public function model_chain_to_wp_user(){
793
+	public function model_chain_to_wp_user() {
794 794
 		return $this->_model_chain_to_wp_user;
795 795
 	}
796 796
 
@@ -802,13 +802,13 @@  discard block
 block discarded – undo
802 802
 	 * @return boolean
803 803
 	 */
804 804
 	public function is_owned() {
805
-		if( $this->model_chain_to_wp_user() ){
805
+		if ($this->model_chain_to_wp_user()) {
806 806
 			return true;
807
-		}else{
808
-			try{
809
-				$this->get_foreign_key_to( 'WP_User' );
807
+		} else {
808
+			try {
809
+				$this->get_foreign_key_to('WP_User');
810 810
 				return true;
811
-			}catch( EE_Error $e ){
811
+			} catch (EE_Error $e) {
812 812
 				return false;
813 813
 			}
814 814
 		}
@@ -827,21 +827,21 @@  discard block
 block discarded – undo
827 827
 	 * and 1 is the data type. Eg, array('count'=>array('COUNT(REG_ID)','%d'))
828 828
 	 * @return array | stdClass[] like results of $wpdb->get_results($sql,OBJECT), (ie, output type is OBJECT)
829 829
 	 */
830
-	protected function  _get_all_wpdb_results($query_params = array(), $output = ARRAY_A, $columns_to_select = null){
830
+	protected function  _get_all_wpdb_results($query_params = array(), $output = ARRAY_A, $columns_to_select = null) {
831 831
 		//remember the custom selections, if any
832
-		if(is_array($columns_to_select)){
832
+		if (is_array($columns_to_select)) {
833 833
 			$this->_custom_selections = $columns_to_select;
834
-		}elseif(is_string($columns_to_select)){
834
+		}elseif (is_string($columns_to_select)) {
835 835
 			$this->_custom_selections = array($this->_custom_selections);
836
-		}else{
836
+		} else {
837 837
 			$this->_custom_selections = array();
838 838
 		}
839 839
 
840 840
 		$model_query_info = $this->_create_model_query_info_carrier($query_params);
841 841
 		$select_expressions = $columns_to_select ? $this->_construct_select_from_input($columns_to_select) : $this->_construct_default_select_sql($model_query_info);
842
-		$SQL ="SELECT $select_expressions ".$this->_construct_2nd_half_of_select_query($model_query_info);
842
+		$SQL = "SELECT $select_expressions ".$this->_construct_2nd_half_of_select_query($model_query_info);
843 843
 //		echo "sql:$SQL";
844
-		$results =  $this->_do_wpdb_query( 'get_results', array($SQL, $output ) );// $wpdb->get_results($SQL, $output);
844
+		$results = $this->_do_wpdb_query('get_results', array($SQL, $output)); // $wpdb->get_results($SQL, $output);
845 845
 		return $results;
846 846
 	}
847 847
 
@@ -859,7 +859,7 @@  discard block
 block discarded – undo
859 859
 	 * and 1 is the data type. Eg, array('count'=>array('COUNT(REG_ID)','%d'))
860 860
 	 * @return array|stdClass[] like results of $wpdb->get_results($sql,OBJECT), (ie, output type is OBJECT)
861 861
 	 */
862
-	public function  get_all_wpdb_results($query_params = array(), $output = ARRAY_A, $columns_to_select = null){
862
+	public function  get_all_wpdb_results($query_params = array(), $output = ARRAY_A, $columns_to_select = null) {
863 863
 		return $this->_get_all_wpdb_results($query_params, $output, $columns_to_select);
864 864
 	}
865 865
 
@@ -871,12 +871,12 @@  discard block
 block discarded – undo
871 871
 	 * @throws EE_Error
872 872
 	 * @return string
873 873
 	 */
874
-	private function _construct_select_from_input($columns_to_select){
875
-		if(is_array($columns_to_select)){
874
+	private function _construct_select_from_input($columns_to_select) {
875
+		if (is_array($columns_to_select)) {
876 876
 			$select_sql_array = array();
877 877
 
878
-			foreach($columns_to_select as $alias => $selection_and_datatype){
879
-				if( ! is_array($selection_and_datatype) || ! isset($selection_and_datatype[1])){
878
+			foreach ($columns_to_select as $alias => $selection_and_datatype) {
879
+				if ( ! is_array($selection_and_datatype) || ! isset($selection_and_datatype[1])) {
880 880
 					throw new EE_Error(
881 881
 						sprintf(
882 882
 							__(
@@ -888,24 +888,24 @@  discard block
 block discarded – undo
888 888
 						)
889 889
 					);
890 890
 				}
891
-				if( ! in_array( $selection_and_datatype[1],$this->_valid_wpdb_data_types)){
891
+				if ( ! in_array($selection_and_datatype[1], $this->_valid_wpdb_data_types)) {
892 892
 					throw new EE_Error(
893 893
 						sprintf(
894 894
 							__(
895 895
 								"Datatype %s (for selection '%s' and alias '%s') is not a valid wpdb datatype (eg %%s)",
896 896
 								"event_espresso"
897 897
 							),
898
-							$selection_and_datatype[ 1 ],
899
-							$selection_and_datatype[ 0 ],
898
+							$selection_and_datatype[1],
899
+							$selection_and_datatype[0],
900 900
 							$alias,
901
-							implode( ",", $this->_valid_wpdb_data_types )
901
+							implode(",", $this->_valid_wpdb_data_types)
902 902
 						)
903 903
 					);
904 904
 				}
905 905
 				$select_sql_array[] = "{$selection_and_datatype[0]} AS $alias";
906 906
 			}
907
-			$columns_to_select_string = implode(", ",$select_sql_array);
908
-		}else{
907
+			$columns_to_select_string = implode(", ", $select_sql_array);
908
+		} else {
909 909
 			$columns_to_select_string = $columns_to_select;
910 910
 		}
911 911
 		return $columns_to_select_string;
@@ -918,7 +918,7 @@  discard block
 block discarded – undo
918 918
 	 * Convenient wrapper for getting the primary key field's name. Eg, on Registration, this would be 'REG_ID'
919 919
 	 * @return string
920 920
 	 */
921
-	function primary_key_name(){
921
+	function primary_key_name() {
922 922
 		return $this->get_primary_key_field()->get_name();
923 923
 	}
924 924
 
@@ -930,14 +930,14 @@  discard block
 block discarded – undo
930 930
 	 * @param mixed $id int or string, depending on the type of the model's primary key
931 931
 	 * @return EE_Base_Class
932 932
 	 */
933
-	function get_one_by_ID($id){
934
-		if( $this->get_from_entity_map( $id ) ){
935
-			return $this->get_from_entity_map( $id );
933
+	function get_one_by_ID($id) {
934
+		if ($this->get_from_entity_map($id)) {
935
+			return $this->get_from_entity_map($id);
936 936
 		}
937 937
 		return $this->get_one( 
938 938
 			$this->alter_query_params_to_restrict_by_ID( 
939 939
 				$id,
940
-				array( 'default_where_conditions' => 'minimum' )
940
+				array('default_where_conditions' => 'minimum')
941 941
 			) 
942 942
 		);
943 943
 	}
@@ -949,15 +949,15 @@  discard block
 block discarded – undo
949 949
 	 * @param array $query_params
950 950
 	 * @return array of normal query params, @see EEM_Base::get_all
951 951
 	 */
952
-	public function alter_query_params_to_restrict_by_ID( $id, $query_params = array() ) {
953
-		if( ! isset( $query_params[ 0 ] ) ) {
954
-			$query_params[ 0 ] = array();
952
+	public function alter_query_params_to_restrict_by_ID($id, $query_params = array()) {
953
+		if ( ! isset($query_params[0])) {
954
+			$query_params[0] = array();
955 955
 		}
956
-		if( $this->has_primary_key_field ( ) ) {
957
-			$query_params[ 0 ][ $this->primary_key_name() ] = $id ;
958
-		}else{
956
+		if ($this->has_primary_key_field( )) {
957
+			$query_params[0][$this->primary_key_name()] = $id;
958
+		} else {
959 959
 			//no primary key, so the $id must be from the get_index_primary_key_string()
960
-			$query_params[0] = array_replace_recursive( $query_params[ 0 ], $this->parse_index_primary_key_string( $id ) );
960
+			$query_params[0] = array_replace_recursive($query_params[0], $this->parse_index_primary_key_string($id));
961 961
 		}
962 962
 		return $query_params;
963 963
 	}
@@ -969,16 +969,16 @@  discard block
 block discarded – undo
969 969
 	 * @param array $query_params like EEM_Base's $query_params variable.
970 970
 	 * @return EE_Base_Class | NULL
971 971
 	 */
972
-	function get_one($query_params = array()){
973
-		if( ! is_array( $query_params ) ){
974
-			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' );
972
+	function get_one($query_params = array()) {
973
+		if ( ! is_array($query_params)) {
974
+			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');
975 975
 			$query_params = array();
976 976
 		}
977 977
 		$query_params['limit'] = 1;
978 978
 		$items = $this->get_all($query_params);
979
-		if(empty($items)){
979
+		if (empty($items)) {
980 980
 			return null;
981
-		}else{
981
+		} else {
982 982
 			return array_shift($items);
983 983
 		}
984 984
 	}
@@ -1002,8 +1002,8 @@  discard block
 block discarded – undo
1002 1002
 	 *
1003 1003
 	 * @return EE_Base_Class[]|array
1004 1004
 	 */
1005
-	public function next_x( $current_field_value, $field_to_order_by = null, $limit = 1, $query_params = array(), $columns_to_select = null ) {
1006
-		return $this->_get_consecutive( $current_field_value, '>', $field_to_order_by, $limit, $query_params, $columns_to_select );
1005
+	public function next_x($current_field_value, $field_to_order_by = null, $limit = 1, $query_params = array(), $columns_to_select = null) {
1006
+		return $this->_get_consecutive($current_field_value, '>', $field_to_order_by, $limit, $query_params, $columns_to_select);
1007 1007
 	}
1008 1008
 
1009 1009
 
@@ -1026,8 +1026,8 @@  discard block
 block discarded – undo
1026 1026
 	 *
1027 1027
 	 * @return EE_Base_Class[]|array
1028 1028
 	 */
1029
-	public function previous_x( $current_field_value, $field_to_order_by = null, $limit = 1, $query_params = array(), $columns_to_select = null ) {
1030
-		return $this->_get_consecutive( $current_field_value, '<', $field_to_order_by, $limit, $query_params, $columns_to_select );
1029
+	public function previous_x($current_field_value, $field_to_order_by = null, $limit = 1, $query_params = array(), $columns_to_select = null) {
1030
+		return $this->_get_consecutive($current_field_value, '<', $field_to_order_by, $limit, $query_params, $columns_to_select);
1031 1031
 	}
1032 1032
 
1033 1033
 
@@ -1049,9 +1049,9 @@  discard block
 block discarded – undo
1049 1049
 	 *
1050 1050
 	 * @return EE_Base_Class|null|array()
1051 1051
 	 */
1052
-	public function next( $current_field_value, $field_to_order_by = null, $query_params = array(), $columns_to_select = null ) {
1053
-		$results = $this->_get_consecutive( $current_field_value, '>', $field_to_order_by, 1, $query_params, $columns_to_select );
1054
-		return empty( $results ) ? null : reset( $results );
1052
+	public function next($current_field_value, $field_to_order_by = null, $query_params = array(), $columns_to_select = null) {
1053
+		$results = $this->_get_consecutive($current_field_value, '>', $field_to_order_by, 1, $query_params, $columns_to_select);
1054
+		return empty($results) ? null : reset($results);
1055 1055
 	}
1056 1056
 
1057 1057
 
@@ -1073,9 +1073,9 @@  discard block
 block discarded – undo
1073 1073
 	 *
1074 1074
 	 * @return EE_Base_Class|null|array()
1075 1075
 	 */
1076
-	public function previous( $current_field_value, $field_to_order_by = null, $query_params = array(), $columns_to_select = null ) {
1077
-		$results = $this->_get_consecutive( $current_field_value, '<', $field_to_order_by, 1, $query_params, $columns_to_select );
1078
-		return empty( $results ) ? null : reset( $results );
1076
+	public function previous($current_field_value, $field_to_order_by = null, $query_params = array(), $columns_to_select = null) {
1077
+		$results = $this->_get_consecutive($current_field_value, '<', $field_to_order_by, 1, $query_params, $columns_to_select);
1078
+		return empty($results) ? null : reset($results);
1079 1079
 	}
1080 1080
 
1081 1081
 
@@ -1101,40 +1101,40 @@  discard block
 block discarded – undo
1101 1101
 	 * @return EE_Base_Class[]|array
1102 1102
 	 * @throws EE_Error
1103 1103
 	 */
1104
-	protected function _get_consecutive( $current_field_value, $operand = '>', $field_to_order_by = null, $limit = 1, $query_params = array(), $columns_to_select = null ) {
1104
+	protected function _get_consecutive($current_field_value, $operand = '>', $field_to_order_by = null, $limit = 1, $query_params = array(), $columns_to_select = null) {
1105 1105
 		//if $field_to_order_by is empty then let's assume we're ordering by the primary key.
1106
-		if ( empty( $field_to_order_by ) ) {
1107
-			if ( $this->has_primary_key_field() ) {
1106
+		if (empty($field_to_order_by)) {
1107
+			if ($this->has_primary_key_field()) {
1108 1108
 				$field_to_order_by = $this->get_primary_key_field()->get_name();
1109 1109
 			} else {
1110 1110
 
1111
-				if ( WP_DEBUG ) {
1112
-					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' ) );
1111
+				if (WP_DEBUG) {
1112
+					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'));
1113 1113
 				}
1114
-				EE_Error::add_error( __('There was an error with the query.', 'event_espresso') );
1114
+				EE_Error::add_error(__('There was an error with the query.', 'event_espresso'));
1115 1115
 				return array();
1116 1116
 			}
1117 1117
 		}
1118 1118
 
1119
-		if( ! is_array( $query_params ) ){
1120
-			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' );
1119
+		if ( ! is_array($query_params)) {
1120
+			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');
1121 1121
 			$query_params = array();
1122 1122
 		}
1123 1123
 
1124 1124
 		//let's add the where query param for consecutive look up.
1125
-		$query_params[0][ $field_to_order_by ] = array( $operand, $current_field_value );
1125
+		$query_params[0][$field_to_order_by] = array($operand, $current_field_value);
1126 1126
 		$query_params['limit'] = $limit;
1127 1127
 
1128 1128
 		//set direction
1129
-		$incoming_orderby = isset( $query_params['order_by'] ) ? $query_params['order_by'] : array();
1130
-		$query_params['order_by'] = $operand == '>' ? array( $field_to_order_by => 'ASC' ) + $incoming_orderby : array( $field_to_order_by => 'DESC') + $incoming_orderby;
1129
+		$incoming_orderby = isset($query_params['order_by']) ? $query_params['order_by'] : array();
1130
+		$query_params['order_by'] = $operand == '>' ? array($field_to_order_by => 'ASC') + $incoming_orderby : array($field_to_order_by => 'DESC') + $incoming_orderby;
1131 1131
 
1132 1132
 		//if $columns_to_select is empty then that means we're returning EE_Base_Class objects
1133
-		if ( empty( $columns_to_select ) ) {
1134
-			return $this->get_all( $query_params );
1133
+		if (empty($columns_to_select)) {
1134
+			return $this->get_all($query_params);
1135 1135
 		} else {
1136 1136
 			//getting just the fields
1137
-			return $this->_get_all_wpdb_results( $query_params, ARRAY_A, $columns_to_select );
1137
+			return $this->_get_all_wpdb_results($query_params, ARRAY_A, $columns_to_select);
1138 1138
 		}
1139 1139
 	}
1140 1140
 
@@ -1145,18 +1145,18 @@  discard block
 block discarded – undo
1145 1145
 	 * This sets the _timezone property after model object has been instantiated.
1146 1146
 	 * @param null | string $timezone valid PHP DateTimeZone timezone string
1147 1147
 	 */
1148
-	public function set_timezone( $timezone ) {
1149
-		if ( $timezone !== null ) {
1148
+	public function set_timezone($timezone) {
1149
+		if ($timezone !== null) {
1150 1150
 			$this->_timezone = $timezone;
1151 1151
 		}
1152 1152
 		//note we need to loop through relations and set the timezone on those objects as well.
1153
-		foreach ( $this->_model_relations as $relation ) {
1154
-			$relation->set_timezone( $timezone );
1153
+		foreach ($this->_model_relations as $relation) {
1154
+			$relation->set_timezone($timezone);
1155 1155
 		}
1156 1156
 		//and finally we do the same for any datetime fields
1157
-		foreach ( $this->_fields as $field ) {
1158
-			if ( $field instanceof EE_Datetime_Field ) {
1159
-				$field->set_timezone( $timezone );
1157
+		foreach ($this->_fields as $field) {
1158
+			if ($field instanceof EE_Datetime_Field) {
1159
+				$field->set_timezone($timezone);
1160 1160
 			}
1161 1161
 		}
1162 1162
 	}
@@ -1171,9 +1171,9 @@  discard block
 block discarded – undo
1171 1171
 	 */
1172 1172
 	public function get_timezone() {
1173 1173
 		//first validate if timezone is set.  If not, then let's set it be whatever is set on the model fields.
1174
-		if ( empty( $this->_timezone ) ) {
1175
-			foreach( $this->_fields as $field ) {
1176
-				if ( $field instanceof EE_Datetime_Field ) {
1174
+		if (empty($this->_timezone)) {
1175
+			foreach ($this->_fields as $field) {
1176
+				if ($field instanceof EE_Datetime_Field) {
1177 1177
 					$this->set_timezone($field->get_timezone());
1178 1178
 					break;
1179 1179
 				}
@@ -1181,9 +1181,9 @@  discard block
 block discarded – undo
1181 1181
 		}
1182 1182
 
1183 1183
 		//if timezone STILL empty then return the default timezone for the site.
1184
-		if ( empty( $this->_timezone ) ) {
1185
-			EE_Registry::instance()->load_helper( 'DTT_Helper' );
1186
-			$this->set_timezone( EEH_DTT_Helper::get_timezone() );
1184
+		if (empty($this->_timezone)) {
1185
+			EE_Registry::instance()->load_helper('DTT_Helper');
1186
+			$this->set_timezone(EEH_DTT_Helper::get_timezone());
1187 1187
 		}
1188 1188
 		return $this->_timezone;
1189 1189
 	}
@@ -1201,19 +1201,19 @@  discard block
 block discarded – undo
1201 1201
 	 *
1202 1202
 	 * @return array formats in an array with the date format first, and the time format last.
1203 1203
 	 */
1204
-	public function get_formats_for( $field_name, $pretty = false ) {
1205
-		$field_settings = $this->field_settings_for( $field_name );
1204
+	public function get_formats_for($field_name, $pretty = false) {
1205
+		$field_settings = $this->field_settings_for($field_name);
1206 1206
 
1207 1207
 		//if not a valid EE_Datetime_Field then throw error
1208
-		if ( ! $field_settings instanceof EE_Datetime_Field ) {
1209
-			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 ) );
1208
+		if ( ! $field_settings instanceof EE_Datetime_Field) {
1209
+			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));
1210 1210
 		}
1211 1211
 
1212 1212
 		//while we are here, let's make sure the timezone internally in EEM_Base matches what is stored on
1213 1213
 		//the field.
1214 1214
 		$this->_timezone = $field_settings->get_timezone();
1215 1215
 
1216
-		return array( $field_settings->get_date_format( $pretty ), $field_settings->get_time_format( $pretty ) );
1216
+		return array($field_settings->get_date_format($pretty), $field_settings->get_time_format($pretty));
1217 1217
 	}
1218 1218
 
1219 1219
 
@@ -1237,25 +1237,25 @@  discard block
 block discarded – undo
1237 1237
 	 * @return int|string  If the given field_name is not of the EE_Datetime_Field type, then an EE_Error
1238 1238
 	 *                    	     exception is triggered.
1239 1239
 	 */
1240
-	public function current_time_for_query( $field_name, $timestamp = false, $what = 'both' ) {
1241
-		$formats = $this->get_formats_for( $field_name );
1240
+	public function current_time_for_query($field_name, $timestamp = false, $what = 'both') {
1241
+		$formats = $this->get_formats_for($field_name);
1242 1242
 
1243
-		$DateTime = new DateTime( "now", new DateTimeZone( $this->_timezone ) );
1243
+		$DateTime = new DateTime("now", new DateTimeZone($this->_timezone));
1244 1244
 
1245
-		if ( $timestamp ) {
1246
-			return $DateTime->format( 'U' );
1245
+		if ($timestamp) {
1246
+			return $DateTime->format('U');
1247 1247
 		}
1248 1248
 
1249 1249
 		//not returning timestamp, so return formatted string in timezone.
1250
-		switch( $what ) {
1250
+		switch ($what) {
1251 1251
 			case 'time' :
1252
-				return $DateTime->format( $formats[1] );
1252
+				return $DateTime->format($formats[1]);
1253 1253
 				break;
1254 1254
 			case 'date' :
1255
-				return $DateTime->format( $formats[0] );
1255
+				return $DateTime->format($formats[0]);
1256 1256
 				break;
1257 1257
 			default :
1258
-				return $DateTime->format( implode( ' ', $formats ) );
1258
+				return $DateTime->format(implode(' ', $formats));
1259 1259
 				break;
1260 1260
 		}
1261 1261
 	}
@@ -1279,18 +1279,18 @@  discard block
 block discarded – undo
1279 1279
 	 *                           		'U', this is ignored.
1280 1280
 	 * @return DateTime
1281 1281
 	 */
1282
-	public function convert_datetime_for_query( $field_name, $timestring, $incoming_format, $timezone = '' ) {
1282
+	public function convert_datetime_for_query($field_name, $timestring, $incoming_format, $timezone = '') {
1283 1283
 
1284 1284
 		//just using this to ensure the timezone is set correctly internally
1285
-		$this->get_formats_for( $field_name );
1285
+		$this->get_formats_for($field_name);
1286 1286
 
1287 1287
 		//load EEH_DTT_Helper
1288
-		EE_Registry::instance()->load_helper( 'DTT_Helper' );
1289
-		$set_timezone = empty( $timezone ) ? EEH_DTT_Helper::get_timezone() : $timezone;
1288
+		EE_Registry::instance()->load_helper('DTT_Helper');
1289
+		$set_timezone = empty($timezone) ? EEH_DTT_Helper::get_timezone() : $timezone;
1290 1290
 
1291
-		$incomingDateTime = date_create_from_format( $incoming_format, $timestring, new DateTimeZone( $set_timezone ) );
1291
+		$incomingDateTime = date_create_from_format($incoming_format, $timestring, new DateTimeZone($set_timezone));
1292 1292
 
1293
-		return $incomingDateTime->setTimeZone( new DateTimeZone( $this->_timezone ) );
1293
+		return $incomingDateTime->setTimeZone(new DateTimeZone($this->_timezone));
1294 1294
 	}
1295 1295
 
1296 1296
 
@@ -1300,7 +1300,7 @@  discard block
 block discarded – undo
1300 1300
 	 * Gets all the tables comprising this model. Array keys are the table aliases, and values are EE_Table objects
1301 1301
 	 * @return EE_Table_Base[]
1302 1302
 	 */
1303
-	function get_tables(){
1303
+	function get_tables() {
1304 1304
 		return $this->_tables;
1305 1305
 	}
1306 1306
 
@@ -1334,9 +1334,9 @@  discard block
 block discarded – undo
1334 1334
 	 * be aware that model objects being used could get out-of-sync with the database
1335 1335
 	 * @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)
1336 1336
 	 */
1337
-	function update($fields_n_values, $query_params, $keep_model_objs_in_sync = TRUE){
1338
-		if( ! is_array( $query_params ) ){
1339
-			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' );
1337
+	function update($fields_n_values, $query_params, $keep_model_objs_in_sync = TRUE) {
1338
+		if ( ! is_array($query_params)) {
1339
+			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');
1340 1340
 			$query_params = array();
1341 1341
 		}
1342 1342
 		/**
@@ -1346,7 +1346,7 @@  discard block
 block discarded – undo
1346 1346
 		 * @param array $fields_n_values the updated fields and their new values
1347 1347
 		 * @param array $query_params @see EEM_Base::get_all()
1348 1348
 		 */
1349
-		do_action( 'AHEE__EEM_Base__update__begin',$this, $fields_n_values, $query_params );
1349
+		do_action('AHEE__EEM_Base__update__begin', $this, $fields_n_values, $query_params);
1350 1350
 		/**
1351 1351
 		 * Filters the fields about to be updated given the query parameters. You can provide the
1352 1352
 		 * $query_params to $this->get_all() to find exactly which records will be updated
@@ -1354,10 +1354,10 @@  discard block
 block discarded – undo
1354 1354
 		 * @param EEM_Base $model the model being queried
1355 1355
 		 * @param array $query_params see EEM_Base::get_all()
1356 1356
 		 */
1357
-		$fields_n_values = apply_filters( 'FHEE__EEM_Base__update__fields_n_values', $fields_n_values, $this, $query_params );
1357
+		$fields_n_values = apply_filters('FHEE__EEM_Base__update__fields_n_values', $fields_n_values, $this, $query_params);
1358 1358
 		//need to verify that, for any entry we want to update, there are entries in each secondary table.
1359 1359
 		//to do that, for each table, verify that it's PK isn't null.
1360
-		$tables= $this->get_tables();
1360
+		$tables = $this->get_tables();
1361 1361
 
1362 1362
 		//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
1363 1363
 		//NOTE: we should make this code more efficient by NOT querying twice
@@ -1367,29 +1367,29 @@  discard block
 block discarded – undo
1367 1367
 			//we want to make sure the default_where strategy is ignored
1368 1368
 			$this->_ignore_where_strategy = TRUE;
1369 1369
 			$wpdb_select_results = $this->_get_all_wpdb_results($query_params);
1370
-			foreach( $wpdb_select_results as $wpdb_result ){
1370
+			foreach ($wpdb_select_results as $wpdb_result) {
1371 1371
 				// type cast stdClass as array
1372
-				$wpdb_result = (array)$wpdb_result;
1372
+				$wpdb_result = (array) $wpdb_result;
1373 1373
 				//get the model object's PK, as we'll want this if we need to insert a row into secondary tables
1374
-				if( $this->has_primary_key_field() ){
1375
-					$main_table_pk_value = $wpdb_result[ $this->get_primary_key_field()->get_qualified_column() ];
1376
-				}else{
1374
+				if ($this->has_primary_key_field()) {
1375
+					$main_table_pk_value = $wpdb_result[$this->get_primary_key_field()->get_qualified_column()];
1376
+				} else {
1377 1377
 					//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)
1378 1378
 					$main_table_pk_value = null;
1379 1379
 				}
1380 1380
 				//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
1381 1381
 				//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
1382
-				if(count($tables) > 1){
1382
+				if (count($tables) > 1) {
1383 1383
 					//foreach matching row in the DB, ensure that each table's PK isn't null. If so, there must not be an entry
1384 1384
 					//in that table, and so we'll want to insert one
1385
-					foreach($tables as $table_obj){
1385
+					foreach ($tables as $table_obj) {
1386 1386
 						$this_table_pk_column = $table_obj->get_fully_qualified_pk_column();
1387 1387
 						//if there is no private key for this table on the results, it means there's no entry
1388 1388
 						//in this table, right? so insert a row in the current table, using any fields available
1389
-						if( ! ( array_key_exists( $this_table_pk_column, $wpdb_result) && $wpdb_result[ $this_table_pk_column ] )){
1389
+						if ( ! (array_key_exists($this_table_pk_column, $wpdb_result) && $wpdb_result[$this_table_pk_column])) {
1390 1390
 							$success = $this->_insert_into_specific_table($table_obj, $fields_n_values, $main_table_pk_value);
1391 1391
 							//if we died here, report the error
1392
-							if( ! $success ) {
1392
+							if ( ! $success) {
1393 1393
 								return false;
1394 1394
 							}
1395 1395
 						}
@@ -1409,44 +1409,44 @@  discard block
 block discarded – undo
1409 1409
 		//if this wasn't called from a model object (to update itself)
1410 1410
 		//then we want to make sure we keep all the existing
1411 1411
 		//model objects in sync with the db
1412
-		if( $keep_model_objs_in_sync && ! $this->_values_already_prepared_by_model_object ){
1413
-			if( $this->has_primary_key_field() ){
1414
-				$model_objs_affected_ids = $this->get_col( $query_params );
1415
-			}else{
1412
+		if ($keep_model_objs_in_sync && ! $this->_values_already_prepared_by_model_object) {
1413
+			if ($this->has_primary_key_field()) {
1414
+				$model_objs_affected_ids = $this->get_col($query_params);
1415
+			} else {
1416 1416
 				//we need to select a bunch of columns and then combine them into the the "index primary key string"s
1417
-				$models_affected_key_columns = $this->_get_all_wpdb_results($query_params, ARRAY_A );
1417
+				$models_affected_key_columns = $this->_get_all_wpdb_results($query_params, ARRAY_A);
1418 1418
 				$model_objs_affected_ids = array();
1419
-				foreach( $models_affected_key_columns as $row ){
1420
-					$combined_index_key = $this->get_index_primary_key_string( $row );
1421
-					$model_objs_affected_ids[ $combined_index_key ] = $combined_index_key;
1419
+				foreach ($models_affected_key_columns as $row) {
1420
+					$combined_index_key = $this->get_index_primary_key_string($row);
1421
+					$model_objs_affected_ids[$combined_index_key] = $combined_index_key;
1422 1422
 				}
1423 1423
 
1424 1424
 			}
1425 1425
 
1426
-			if( ! $model_objs_affected_ids ){
1426
+			if ( ! $model_objs_affected_ids) {
1427 1427
 				//wait wait wait- if nothing was affected let's stop here
1428 1428
 				return 0;
1429 1429
 			}
1430
-			foreach( $model_objs_affected_ids as $id ){
1431
-				$model_obj_in_entity_map = $this->get_from_entity_map( $id );
1432
-				if( $model_obj_in_entity_map ){
1433
-					foreach( $fields_n_values as $field => $new_value ){
1434
-						$model_obj_in_entity_map->set( $field, $new_value );
1430
+			foreach ($model_objs_affected_ids as $id) {
1431
+				$model_obj_in_entity_map = $this->get_from_entity_map($id);
1432
+				if ($model_obj_in_entity_map) {
1433
+					foreach ($fields_n_values as $field => $new_value) {
1434
+						$model_obj_in_entity_map->set($field, $new_value);
1435 1435
 					}
1436 1436
 				}
1437 1437
 			}
1438 1438
 			//if there is a primary key on this model, we can now do a slight optimization
1439
-			if( $this->has_primary_key_field() ){
1439
+			if ($this->has_primary_key_field()) {
1440 1440
 				//we already know what we want to update. So let's make the query simpler so it's a little more efficient
1441 1441
 				$query_params = array(
1442
-					array( $this->primary_key_name() => array( 'IN', $model_objs_affected_ids ) ),
1443
-					'limit' => count( $model_objs_affected_ids ), 'default_where_conditions' => 'none' );
1442
+					array($this->primary_key_name() => array('IN', $model_objs_affected_ids)),
1443
+					'limit' => count($model_objs_affected_ids), 'default_where_conditions' => 'none' );
1444 1444
 			}
1445 1445
 		}
1446 1446
 
1447
-		$model_query_info = $this->_create_model_query_info_carrier( $query_params );
1448
-		$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.
1449
-		$rows_affected = $this->_do_wpdb_query('query', array( $SQL ) );
1447
+		$model_query_info = $this->_create_model_query_info_carrier($query_params);
1448
+		$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.
1449
+		$rows_affected = $this->_do_wpdb_query('query', array($SQL));
1450 1450
 		/**
1451 1451
 		 * Action called after a model update call has been made.
1452 1452
 		 *
@@ -1455,8 +1455,8 @@  discard block
 block discarded – undo
1455 1455
 		 * @param array $query_params @see EEM_Base::get_all()
1456 1456
 		 * @param int $rows_affected
1457 1457
 		 */
1458
-		do_action( 'AHEE__EEM_Base__update__end',$this, $fields_n_values, $query_params, $rows_affected );
1459
-		return $rows_affected;//how many supposedly got updated
1458
+		do_action('AHEE__EEM_Base__update__end', $this, $fields_n_values, $query_params, $rows_affected);
1459
+		return $rows_affected; //how many supposedly got updated
1460 1460
 	}
1461 1461
 
1462 1462
 	/**
@@ -1468,22 +1468,22 @@  discard block
 block discarded – undo
1468 1468
 	 * @param string $field_to_select
1469 1469
 	 * @return array just like $wpdb->get_col()
1470 1470
 	 */
1471
-	public function get_col( $query_params  = array(), $field_to_select = NULL ){
1471
+	public function get_col($query_params = array(), $field_to_select = NULL) {
1472 1472
 
1473
-		if( $field_to_select ){
1474
-			$field = $this->field_settings_for( $field_to_select );
1475
-		}elseif( $this->has_primary_key_field ( ) ){
1473
+		if ($field_to_select) {
1474
+			$field = $this->field_settings_for($field_to_select);
1475
+		}elseif ($this->has_primary_key_field( )) {
1476 1476
 			$field = $this->get_primary_key_field();
1477
-		}else{
1477
+		} else {
1478 1478
 			//no primary key, just grab the first column
1479
-			$field = reset( $this->field_settings());
1479
+			$field = reset($this->field_settings());
1480 1480
 		}
1481 1481
 
1482 1482
 
1483 1483
 		$model_query_info = $this->_create_model_query_info_carrier($query_params);
1484 1484
 		$select_expressions = $field->get_qualified_column();
1485
-		$SQL ="SELECT $select_expressions ".$this->_construct_2nd_half_of_select_query($model_query_info);
1486
-		$results =  $this->_do_wpdb_query('get_col', array( $SQL ) );
1485
+		$SQL = "SELECT $select_expressions ".$this->_construct_2nd_half_of_select_query($model_query_info);
1486
+		$results = $this->_do_wpdb_query('get_col', array($SQL));
1487 1487
 		return $results;
1488 1488
 	}
1489 1489
 
@@ -1493,12 +1493,12 @@  discard block
 block discarded – undo
1493 1493
 	 * @param string $field_to_select @see EEM_Base::get_col()
1494 1494
 	 * @return string
1495 1495
 	 */
1496
-	public function get_var( $query_params = array(), $field_to_select = NULL ) {
1497
-		$query_params[ 'limit' ] = 1;
1498
-		$col = $this->get_col( $query_params, $field_to_select );
1499
-		if( ! empty( $col ) ) {
1500
-			return reset( $col );
1501
-		}else{
1496
+	public function get_var($query_params = array(), $field_to_select = NULL) {
1497
+		$query_params['limit'] = 1;
1498
+		$col = $this->get_col($query_params, $field_to_select);
1499
+		if ( ! empty($col)) {
1500
+			return reset($col);
1501
+		} else {
1502 1502
 			return NULL;
1503 1503
 		}
1504 1504
 	}
@@ -1512,19 +1512,19 @@  discard block
 block discarded – undo
1512 1512
 	 * @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
1513 1513
 	 * @return string of SQL
1514 1514
 	 */
1515
-	function _construct_update_sql($fields_n_values){
1515
+	function _construct_update_sql($fields_n_values) {
1516 1516
 		/** @type WPDB $wpdb */
1517 1517
 		global $wpdb;
1518 1518
 		$cols_n_values = array();
1519
-		foreach($fields_n_values as $field_name => $value){
1519
+		foreach ($fields_n_values as $field_name => $value) {
1520 1520
 			$field_obj = $this->field_settings_for($field_name);
1521 1521
 			//if the value is NULL, we want to assign the value to that.
1522 1522
 			//wpdb->prepare doesn't really handle that properly
1523
-			$prepared_value = $this->_prepare_value_or_use_default( $field_obj, $fields_n_values );
1524
-			$value_sql = $prepared_value===NULL ? 'NULL' : $wpdb->prepare( $field_obj->get_wpdb_data_type(), $prepared_value );
1523
+			$prepared_value = $this->_prepare_value_or_use_default($field_obj, $fields_n_values);
1524
+			$value_sql = $prepared_value === NULL ? 'NULL' : $wpdb->prepare($field_obj->get_wpdb_data_type(), $prepared_value);
1525 1525
 			$cols_n_values[] = $field_obj->get_qualified_column()."=".$value_sql;
1526 1526
 		}
1527
-		return implode(",",$cols_n_values);
1527
+		return implode(",", $cols_n_values);
1528 1528
 
1529 1529
 	}
1530 1530
 	
@@ -1536,10 +1536,10 @@  discard block
 block discarded – undo
1536 1536
 	 * @param mixed $id
1537 1537
 	 * @return boolean whether the row got deleted or not
1538 1538
 	 */
1539
-	public function delete_permanently_by_ID( $id ) {
1539
+	public function delete_permanently_by_ID($id) {
1540 1540
 		return $this->delete_permanently( 
1541 1541
 			array(
1542
-				array( $this->get_primary_key_field()->get_name() => $id ),
1542
+				array($this->get_primary_key_field()->get_name() => $id),
1543 1543
 				'limit' 	=> 1
1544 1544
 			) 
1545 1545
 		);
@@ -1553,10 +1553,10 @@  discard block
 block discarded – undo
1553 1553
 	 * @param mixed $id
1554 1554
 	 * @return boolean whether the row got deleted or not
1555 1555
 	 */
1556
-	public function delete_by_ID( $id ){
1556
+	public function delete_by_ID($id) {
1557 1557
 		return $this->delete( 
1558 1558
 			array(
1559
-				array( $this->get_primary_key_field()->get_name() => $id ),
1559
+				array($this->get_primary_key_field()->get_name() => $id),
1560 1560
 				'limit' 	=> 1
1561 1561
 			) 
1562 1562
 		);
@@ -1570,7 +1570,7 @@  discard block
 block discarded – undo
1570 1570
 	 * @param boolean $allow_blocking
1571 1571
 	 * @return @see EEM_Base::delete_permanently
1572 1572
 	 */
1573
-	function delete($query_params,$allow_blocking = true){
1573
+	function delete($query_params, $allow_blocking = true) {
1574 1574
 		return $this->delete_permanently($query_params, $allow_blocking);
1575 1575
 	}
1576 1576
 
@@ -1586,7 +1586,7 @@  discard block
 block discarded – undo
1586 1586
 	 * which may depend on it. Its generally advisable to always leave this as TRUE, otherwise you could easily corrupt your DB
1587 1587
 	 * @return int how many rows got deleted
1588 1588
 	 */
1589
-	function delete_permanently($query_params,$allow_blocking = true){
1589
+	function delete_permanently($query_params, $allow_blocking = true) {
1590 1590
 		/**
1591 1591
 		 * Action called just before performing a real deletion query. You can use the
1592 1592
 		 * model and its $query_params to find exactly which items will be deleted
@@ -1595,34 +1595,34 @@  discard block
 block discarded – undo
1595 1595
 		 * @param boolean $allow_blocking whether or not to allow related model objects
1596 1596
 		 * to block (prevent) this deletion
1597 1597
 		 */
1598
-		do_action( 'AHEE__EEM_Base__delete__begin', $this, $query_params, $allow_blocking );
1598
+		do_action('AHEE__EEM_Base__delete__begin', $this, $query_params, $allow_blocking);
1599 1599
 		//some MySQL databases may be running safe mode, which may restrict
1600 1600
 		//deletion if there is no KEY column used in the WHERE statement of a deletion.
1601 1601
 		//to get around this, we first do a SELECT, get all the IDs, and then run another query
1602 1602
 		//to delete them
1603 1603
 		$items_for_deletion = $this->_get_all_wpdb_results($query_params);
1604
-		$deletion_where = $this->_setup_ids_for_delete( $items_for_deletion, $allow_blocking);
1605
-		if($deletion_where){
1604
+		$deletion_where = $this->_setup_ids_for_delete($items_for_deletion, $allow_blocking);
1605
+		if ($deletion_where) {
1606 1606
 			//echo "objects for deletion:";var_dump($objects_for_deletion);
1607 1607
 			$model_query_info = $this->_create_model_query_info_carrier($query_params);
1608 1608
 			$table_aliases = array();
1609
-			foreach(array_keys($this->_tables) as $table_alias){
1609
+			foreach (array_keys($this->_tables) as $table_alias) {
1610 1610
 				$table_aliases[] = $table_alias;
1611 1611
 			}
1612
-			$SQL = "DELETE ".implode(", ",$table_aliases)." FROM ".$model_query_info->get_full_join_sql()." WHERE ".$deletion_where;
1612
+			$SQL = "DELETE ".implode(", ", $table_aliases)." FROM ".$model_query_info->get_full_join_sql()." WHERE ".$deletion_where;
1613 1613
 
1614 1614
 			//		/echo "delete sql:$SQL";
1615
-			$rows_deleted = $this->_do_wpdb_query( 'query', array( $SQL ) );
1616
-		}else{
1615
+			$rows_deleted = $this->_do_wpdb_query('query', array($SQL));
1616
+		} else {
1617 1617
 			$rows_deleted = 0;
1618 1618
 		}
1619 1619
 
1620 1620
 		//and lastly make sure those items are removed from the entity map; if they could be put into it at all
1621
-		if( $this->has_primary_key_field() ){
1622
-			foreach($items_for_deletion as $item_for_deletion_row ){
1623
-				$pk_value = $item_for_deletion_row[ $this->get_primary_key_field()->get_qualified_column() ];
1624
-				if( isset( $this->_entity_map[ $pk_value ] ) ){
1625
-					unset( $this->_entity_map[ $pk_value ] );
1621
+		if ($this->has_primary_key_field()) {
1622
+			foreach ($items_for_deletion as $item_for_deletion_row) {
1623
+				$pk_value = $item_for_deletion_row[$this->get_primary_key_field()->get_qualified_column()];
1624
+				if (isset($this->_entity_map[$pk_value])) {
1625
+					unset($this->_entity_map[$pk_value]);
1626 1626
 				}
1627 1627
 			}
1628 1628
 		}
@@ -1634,8 +1634,8 @@  discard block
 block discarded – undo
1634 1634
 		 * @param array $query_params @see EEM_Base::get_all()
1635 1635
 		 * @param int $rows_deleted
1636 1636
 		 */
1637
-		do_action( 'AHEE__EEM_Base__delete__end', $this, $query_params, $rows_deleted );
1638
-		return $rows_deleted;//how many supposedly got deleted
1637
+		do_action('AHEE__EEM_Base__delete__end', $this, $query_params, $rows_deleted);
1638
+		return $rows_deleted; //how many supposedly got deleted
1639 1639
 	}
1640 1640
 
1641 1641
 
@@ -1651,28 +1651,28 @@  discard block
 block discarded – undo
1651 1651
 	 * blocking its deletion before removing the relation between A and B
1652 1652
 	 * @return boolean
1653 1653
 	 */
1654
-	public function delete_is_blocked_by_related_models($this_model_obj_or_id, $ignore_this_model_obj = null){
1654
+	public function delete_is_blocked_by_related_models($this_model_obj_or_id, $ignore_this_model_obj = null) {
1655 1655
 		//first, if $ignore_this_model_obj was supplied, get its model
1656
-		if($ignore_this_model_obj && $ignore_this_model_obj instanceof EE_Base_Class){
1656
+		if ($ignore_this_model_obj && $ignore_this_model_obj instanceof EE_Base_Class) {
1657 1657
 			$ignored_model = $ignore_this_model_obj->get_model();
1658
-		}else{
1658
+		} else {
1659 1659
 			$ignored_model = null;
1660 1660
 		}
1661 1661
 		//now check all the relations of $this_model_obj_or_id and see if there
1662 1662
 		//are any related model objects blocking it?
1663 1663
 		$is_blocked = false;
1664
-		foreach($this->_model_relations as $relation_name => $relation_obj){
1665
-			if( $relation_obj->block_delete_if_related_models_exist()){
1664
+		foreach ($this->_model_relations as $relation_name => $relation_obj) {
1665
+			if ($relation_obj->block_delete_if_related_models_exist()) {
1666 1666
 				//if $ignore_this_model_obj was supplied, then for the query
1667 1667
 				//on that model needs to be told to ignore $ignore_this_model_obj
1668
-				if($ignored_model && $relation_name == $ignored_model->get_this_model_name()){
1669
-					$related_model_objects = $relation_obj->get_all_related($this_model_obj_or_id,array(
1670
-					array($ignored_model->get_primary_key_field()->get_name() => array('!=',$ignore_this_model_obj->ID()))));
1671
-				}else{
1668
+				if ($ignored_model && $relation_name == $ignored_model->get_this_model_name()) {
1669
+					$related_model_objects = $relation_obj->get_all_related($this_model_obj_or_id, array(
1670
+					array($ignored_model->get_primary_key_field()->get_name() => array('!=', $ignore_this_model_obj->ID()))));
1671
+				} else {
1672 1672
 					$related_model_objects = $relation_obj->get_all_related($this_model_obj_or_id);
1673 1673
 				}
1674 1674
 
1675
-				if($related_model_objects){
1675
+				if ($related_model_objects) {
1676 1676
 					EE_Error::add_error($relation_obj->get_deletion_error_message(), __FILE__, __FUNCTION__, __LINE__);
1677 1677
 					$is_blocked = true;
1678 1678
 				}
@@ -1692,65 +1692,65 @@  discard block
 block discarded – undo
1692 1692
 	 * @throws EE_Error
1693 1693
 	 * @return string    everything that comes after the WHERE statement.
1694 1694
 	 */
1695
-	protected function _setup_ids_for_delete( $objects_for_deletion, $allow_blocking = true) {
1696
-		if($this->has_primary_key_field()){
1695
+	protected function _setup_ids_for_delete($objects_for_deletion, $allow_blocking = true) {
1696
+		if ($this->has_primary_key_field()) {
1697 1697
 			$primary_table = $this->_get_main_table();
1698 1698
 			$other_tables = $this->_get_other_tables();
1699 1699
 			$deletes = $query = array();
1700
-			foreach ( $objects_for_deletion as $delete_object ) {
1700
+			foreach ($objects_for_deletion as $delete_object) {
1701 1701
 				//before we mark this object for deletion,
1702 1702
 				//make sure there's no related objects blocking its deletion (if we're checking)
1703
-				if( $allow_blocking && $this->delete_is_blocked_by_related_models($delete_object[$primary_table->get_fully_qualified_pk_column()]) ){
1703
+				if ($allow_blocking && $this->delete_is_blocked_by_related_models($delete_object[$primary_table->get_fully_qualified_pk_column()])) {
1704 1704
 					continue;
1705 1705
 				}
1706 1706
 
1707 1707
 				//primary table deletes
1708
-				if ( isset( $delete_object[$primary_table->get_fully_qualified_pk_column()] ) )
1708
+				if (isset($delete_object[$primary_table->get_fully_qualified_pk_column()]))
1709 1709
 					$deletes[$primary_table->get_fully_qualified_pk_column()][] = $delete_object[$primary_table->get_fully_qualified_pk_column()];
1710 1710
 
1711 1711
 				//other tables
1712
-				if ( !empty( $other_tables ) ) {
1713
-					foreach ( $other_tables as $ot ) {
1712
+				if ( ! empty($other_tables)) {
1713
+					foreach ($other_tables as $ot) {
1714 1714
 
1715 1715
 						//first check if we've got the foreign key column here.
1716
-						if ( isset( $delete_object[$ot->get_fully_qualified_fk_column()] ) )
1716
+						if (isset($delete_object[$ot->get_fully_qualified_fk_column()]))
1717 1717
 							$deletes[$ot->get_fully_qualified_pk_column()][] = $delete_object[$ot->get_fully_qualified_fk_column()];
1718 1718
 
1719 1719
 						//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
1720
-						if ( isset( $delete_object[$ot->get_fully_qualified_pk_column()] ) )
1720
+						if (isset($delete_object[$ot->get_fully_qualified_pk_column()]))
1721 1721
 							$deletes[$ot->get_fully_qualified_pk_column()][] = $delete_object[$ot->get_fully_qualified_pk_column()];
1722 1722
 
1723 1723
 						//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!
1724
-						if ( isset( $delete_object[$ot->get_fully_qualified_pk_on_fk_table()]) )
1724
+						if (isset($delete_object[$ot->get_fully_qualified_pk_on_fk_table()]))
1725 1725
 							$deletes[$ot->get_fully_qualified_pk_column()][] = $delete_object[$ot->get_fully_qualified_pk_column()];
1726 1726
 					}
1727 1727
 				}
1728 1728
 			}
1729 1729
 
1730 1730
 			//we should have deletes now, so let's just go through and setup the where statement
1731
-			foreach ( $deletes as $column => $values ) {
1731
+			foreach ($deletes as $column => $values) {
1732 1732
 				//make sure we have unique $values;
1733 1733
 				$values = array_unique($values);
1734
-				$query[] = $column . ' IN(' . implode(",",$values) . ')';
1734
+				$query[] = $column.' IN('.implode(",", $values).')';
1735 1735
 			}
1736 1736
 
1737
-			return !empty($query) ? implode(' AND ', $query ) : '';
1738
-		}elseif(count($this->get_combined_primary_key_fields()) > 1){
1737
+			return ! empty($query) ? implode(' AND ', $query) : '';
1738
+		}elseif (count($this->get_combined_primary_key_fields()) > 1) {
1739 1739
 			$ways_to_identify_a_row = array();
1740 1740
 			$fields = $this->get_combined_primary_key_fields();
1741 1741
 			//note: because there' sno primary key, that means nothing else  can be pointing to this model, right?
1742
-			foreach($objects_for_deletion as  $delete_object){
1742
+			foreach ($objects_for_deletion as  $delete_object) {
1743 1743
 				$values_for_each_cpk_for_a_row = array();
1744
-				foreach($fields as $cpk_field){
1744
+				foreach ($fields as $cpk_field) {
1745 1745
 					$values_for_each_cpk_for_a_row[] = $cpk_field->get_qualified_column()."=".$delete_object[$cpk_field->get_qualified_column()];
1746 1746
 				}
1747
-				$ways_to_identify_a_row[] = "(".implode(" AND ",$values_for_each_cpk_for_a_row).")";
1747
+				$ways_to_identify_a_row[] = "(".implode(" AND ", $values_for_each_cpk_for_a_row).")";
1748 1748
 			}
1749
-			return implode(" OR ",$ways_to_identify_a_row);
1750
-		}else{
1749
+			return implode(" OR ", $ways_to_identify_a_row);
1750
+		} else {
1751 1751
 			//so there's no primary key and no combined key...
1752 1752
 			//sorry, can't help you
1753
-			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)));
1753
+			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)));
1754 1754
 		}
1755 1755
 	}
1756 1756
 
@@ -1764,21 +1764,21 @@  discard block
 block discarded – undo
1764 1764
 	 * @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;
1765 1765
 	 * @return int
1766 1766
 	 */
1767
-	function count($query_params =array(),$field_to_count = NULL, $distinct = FALSE){
1767
+	function count($query_params = array(), $field_to_count = NULL, $distinct = FALSE) {
1768 1768
 		$model_query_info = $this->_create_model_query_info_carrier($query_params);
1769
-		if($field_to_count){
1769
+		if ($field_to_count) {
1770 1770
 			$field_obj = $this->field_settings_for($field_to_count);
1771 1771
 			$column_to_count = $field_obj->get_qualified_column();
1772
-		}elseif($this->has_primary_key_field ()){
1772
+		}elseif ($this->has_primary_key_field()) {
1773 1773
 			$pk_field_obj = $this->get_primary_key_field();
1774 1774
 			$column_to_count = $pk_field_obj->get_qualified_column();
1775
-		}else{//there's no primary key
1775
+		} else {//there's no primary key
1776 1776
 			$column_to_count = '*';
1777 1777
 		}
1778 1778
 
1779
-		$column_to_count = $distinct ? "DISTINCT (" . $column_to_count . " )" : $column_to_count;
1780
-		$SQL ="SELECT COUNT(".$column_to_count.")" . $this->_construct_2nd_half_of_select_query($model_query_info);
1781
-		return (int)$this->_do_wpdb_query( 'get_var', array( $SQL) );
1779
+		$column_to_count = $distinct ? "DISTINCT (".$column_to_count." )" : $column_to_count;
1780
+		$SQL = "SELECT COUNT(".$column_to_count.")".$this->_construct_2nd_half_of_select_query($model_query_info);
1781
+		return (int) $this->_do_wpdb_query('get_var', array($SQL));
1782 1782
 	}
1783 1783
 
1784 1784
 	/**
@@ -1788,23 +1788,23 @@  discard block
 block discarded – undo
1788 1788
 	 * @param string $field_to_sum name of field (array key in $_fields array)
1789 1789
 	 * @return float
1790 1790
 	 */
1791
-	function sum($query_params, $field_to_sum = NULL){
1791
+	function sum($query_params, $field_to_sum = NULL) {
1792 1792
 		$model_query_info = $this->_create_model_query_info_carrier($query_params);
1793 1793
 
1794
-		if($field_to_sum){
1794
+		if ($field_to_sum) {
1795 1795
 			$field_obj = $this->field_settings_for($field_to_sum);
1796 1796
 
1797
-		}else{
1797
+		} else {
1798 1798
 			$field_obj = $this->get_primary_key_field();
1799 1799
 		}
1800 1800
 		$column_to_count = $field_obj->get_qualified_column();
1801 1801
 
1802
-		$SQL ="SELECT SUM(".$column_to_count.")" . $this->_construct_2nd_half_of_select_query($model_query_info);
1803
-		$return_value = $this->_do_wpdb_query('get_var',array( $SQL ) );
1804
-		if($field_obj->get_wpdb_data_type() == '%d' || $field_obj->get_wpdb_data_type() == '%s' ){
1805
-			return (float)$return_value;
1806
-		}else{//must be %f
1807
-			return (float)$return_value;
1802
+		$SQL = "SELECT SUM(".$column_to_count.")".$this->_construct_2nd_half_of_select_query($model_query_info);
1803
+		$return_value = $this->_do_wpdb_query('get_var', array($SQL));
1804
+		if ($field_obj->get_wpdb_data_type() == '%d' || $field_obj->get_wpdb_data_type() == '%s') {
1805
+			return (float) $return_value;
1806
+		} else {//must be %f
1807
+			return (float) $return_value;
1808 1808
 		}
1809 1809
 	}
1810 1810
 
@@ -1819,33 +1819,33 @@  discard block
 block discarded – undo
1819 1819
 	 * @global wpdb $wpdb
1820 1820
 	 * @return mixed
1821 1821
 	 */
1822
-	protected function _do_wpdb_query( $wpdb_method, $arguments_to_provide ){
1822
+	protected function _do_wpdb_query($wpdb_method, $arguments_to_provide) {
1823 1823
 		//if we're in maintenance mode level 2, DON'T run any queries
1824 1824
 		//because level 2 indicates the database needs updating and
1825 1825
 		//is probably out of sync with the code
1826
-		if( ! EE_Maintenance_Mode::instance()->models_can_query()){
1826
+		if ( ! EE_Maintenance_Mode::instance()->models_can_query()) {
1827 1827
 			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")));
1828 1828
 		}
1829 1829
 		/** @type WPDB $wpdb */
1830 1830
 		global $wpdb;
1831
-		if( ! method_exists( $wpdb, $wpdb_method ) ){
1832
-			throw new EE_Error( sprintf( __( 'There is no method named "%s" on Wordpress\' $wpdb object','event_espresso' ), $wpdb_method ) );
1831
+		if ( ! method_exists($wpdb, $wpdb_method)) {
1832
+			throw new EE_Error(sprintf(__('There is no method named "%s" on Wordpress\' $wpdb object', 'event_espresso'), $wpdb_method));
1833 1833
 		}
1834
-		if( WP_DEBUG ){
1834
+		if (WP_DEBUG) {
1835 1835
 			$old_show_errors_value = $wpdb->show_errors;
1836
-			$wpdb->show_errors( FALSE );
1837
-		}
1838
-		$result = $this->_process_wpdb_query( $wpdb_method, $arguments_to_provide );
1839
-		$this->show_db_query_if_previously_requested( $wpdb->last_query );
1840
-		if( WP_DEBUG ){
1841
-			$wpdb->show_errors( $old_show_errors_value );
1842
-			if( ! empty( $wpdb->last_error ) ){
1843
-				throw new EE_Error( sprintf( __( 'WPDB Error: "%s"', 'event_espresso' ), $wpdb->last_error ) );
1844
-			}elseif( $result === false ){
1845
-				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 ) ) );
1836
+			$wpdb->show_errors(FALSE);
1837
+		}
1838
+		$result = $this->_process_wpdb_query($wpdb_method, $arguments_to_provide);
1839
+		$this->show_db_query_if_previously_requested($wpdb->last_query);
1840
+		if (WP_DEBUG) {
1841
+			$wpdb->show_errors($old_show_errors_value);
1842
+			if ( ! empty($wpdb->last_error)) {
1843
+				throw new EE_Error(sprintf(__('WPDB Error: "%s"', 'event_espresso'), $wpdb->last_error));
1844
+			}elseif ($result === false) {
1845
+				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)));
1846 1846
 			}
1847
-		}elseif( $result === false ) {
1848
-			EE_Error::add_error( sprintf( __( 'A database error has occurred. Turn on WP_DEBUG for more information.', 'event_espresso' )), __FILE__, __FUNCTION__, __LINE__);
1847
+		}elseif ($result === false) {
1848
+			EE_Error::add_error(sprintf(__('A database error has occurred. Turn on WP_DEBUG for more information.', 'event_espresso')), __FILE__, __FUNCTION__, __LINE__);
1849 1849
 		}
1850 1850
 		return $result;
1851 1851
 	}
@@ -1861,26 +1861,26 @@  discard block
 block discarded – undo
1861 1861
 	 * @param array $arguments_to_provide
1862 1862
 	 * @return mixed
1863 1863
 	 */
1864
-	private function _process_wpdb_query( $wpdb_method, $arguments_to_provide ) {
1864
+	private function _process_wpdb_query($wpdb_method, $arguments_to_provide) {
1865 1865
 		/** @type WPDB $wpdb */
1866 1866
 		global $wpdb;
1867 1867
 		$wpdb->last_error = null;
1868
-		$result = call_user_func_array( array( $wpdb, $wpdb_method ), $arguments_to_provide );
1868
+		$result = call_user_func_array(array($wpdb, $wpdb_method), $arguments_to_provide);
1869 1869
 		// was there an error running the query? but we don't care on new activations
1870 1870
 		// (we're going to setup the DB anyway on new activations)
1871
-		if ( ( $result === false || ! empty( $wpdb->last_error ) )
1871
+		if (($result === false || ! empty($wpdb->last_error))
1872 1872
 			&& EE_System::instance()->detect_req_type() != EE_System::req_type_new_activation
1873 1873
 		) {
1874
-			switch ( EEM_Base::$_db_verification_level ) {
1874
+			switch (EEM_Base::$_db_verification_level) {
1875 1875
 
1876 1876
 				case EEM_Base::db_verified_none :
1877 1877
 					// let's double-check core's DB
1878
-					$error_message = $this->_verify_core_db( $wpdb_method, $arguments_to_provide );
1878
+					$error_message = $this->_verify_core_db($wpdb_method, $arguments_to_provide);
1879 1879
 					break;
1880 1880
 
1881 1881
 				case EEM_Base::db_verified_core :
1882 1882
 					// STILL NO LOVE?? verify all the addons too. Maybe they need to be fixed
1883
-					$error_message = $this->_verify_addons_db( $wpdb_method, $arguments_to_provide );
1883
+					$error_message = $this->_verify_addons_db($wpdb_method, $arguments_to_provide);
1884 1884
 					break;
1885 1885
 
1886 1886
 				case EEM_Base::db_verified_addons :
@@ -1888,11 +1888,11 @@  discard block
 block discarded – undo
1888 1888
 					return $result;
1889 1889
 					break;
1890 1890
 			}
1891
-			if ( ! empty( $error_message ) ) {
1892
-				EE_Log::instance()->log( __FILE__, __FUNCTION__, $error_message, 'error' );
1893
-				trigger_error( $error_message );
1891
+			if ( ! empty($error_message)) {
1892
+				EE_Log::instance()->log(__FILE__, __FUNCTION__, $error_message, 'error');
1893
+				trigger_error($error_message);
1894 1894
 			}
1895
-			return $this->_process_wpdb_query( $wpdb_method, $arguments_to_provide );
1895
+			return $this->_process_wpdb_query($wpdb_method, $arguments_to_provide);
1896 1896
 
1897 1897
 		}
1898 1898
 
@@ -1908,18 +1908,18 @@  discard block
 block discarded – undo
1908 1908
 	 * @param array $arguments_to_provide
1909 1909
 	 * @return string
1910 1910
 	 */
1911
-	private function _verify_core_db( $wpdb_method, $arguments_to_provide ){
1911
+	private function _verify_core_db($wpdb_method, $arguments_to_provide) {
1912 1912
 		/** @type WPDB $wpdb */
1913 1913
 		global $wpdb;
1914 1914
 		//ok remember that we've already attempted fixing the core db, in case the problem persists
1915 1915
 		EEM_Base::$_db_verification_level = EEM_Base::db_verified_core;
1916 1916
 		$error_message = sprintf(
1917
-			__( 'WPDB Error "%1$s" while running wpdb method "%2$s" with arguments %3$s. Automatically attempting to fix EE Core DB', 'event_espresso' ),
1917
+			__('WPDB Error "%1$s" while running wpdb method "%2$s" with arguments %3$s. Automatically attempting to fix EE Core DB', 'event_espresso'),
1918 1918
 			$wpdb->last_error,
1919 1919
 			$wpdb_method,
1920
-			json_encode( $arguments_to_provide )
1920
+			json_encode($arguments_to_provide)
1921 1921
 		);
1922
-		EE_System::instance()->initialize_db_if_no_migrations_required( false, true );
1922
+		EE_System::instance()->initialize_db_if_no_migrations_required(false, true);
1923 1923
 		return $error_message;
1924 1924
 	}
1925 1925
 
@@ -1932,16 +1932,16 @@  discard block
 block discarded – undo
1932 1932
 	 * @param $arguments_to_provide
1933 1933
 	 * @return string
1934 1934
 	 */
1935
-	private function _verify_addons_db( $wpdb_method, $arguments_to_provide ) {
1935
+	private function _verify_addons_db($wpdb_method, $arguments_to_provide) {
1936 1936
 		/** @type WPDB $wpdb */
1937 1937
 		global $wpdb;
1938 1938
 		//ok remember that we've already attempted fixing the addons dbs, in case the problem persists
1939 1939
 		EEM_Base::$_db_verification_level = EEM_Base::db_verified_addons;
1940 1940
 		$error_message = sprintf(
1941
-			__( 'WPDB AGAIN: Error "%1$s" while running the same method and arguments as before. Automatically attempting to fix EE Addons DB', 'event_espresso' ),
1941
+			__('WPDB AGAIN: Error "%1$s" while running the same method and arguments as before. Automatically attempting to fix EE Addons DB', 'event_espresso'),
1942 1942
 			$wpdb->last_error,
1943 1943
 			$wpdb_method,
1944
-			json_encode( $arguments_to_provide )
1944
+			json_encode($arguments_to_provide)
1945 1945
 		);
1946 1946
 		EE_System::instance()->initialize_addons();
1947 1947
 		return $error_message;
@@ -1956,7 +1956,7 @@  discard block
 block discarded – undo
1956 1956
 	 * @param EE_Model_Query_Info_Carrier $model_query_info
1957 1957
 	 * @return string
1958 1958
 	 */
1959
-	private function _construct_2nd_half_of_select_query(EE_Model_Query_Info_Carrier $model_query_info){
1959
+	private function _construct_2nd_half_of_select_query(EE_Model_Query_Info_Carrier $model_query_info) {
1960 1960
 		return " FROM ".$model_query_info->get_full_join_sql().
1961 1961
 				$model_query_info->get_where_sql().
1962 1962
 				$model_query_info->get_group_by_sql().
@@ -1969,7 +1969,7 @@  discard block
 block discarded – undo
1969 1969
 	 * Set to easily debug the next X queries ran from this model.
1970 1970
 	 * @param int $count
1971 1971
 	 */
1972
-	function show_next_x_db_queries($count = 1){
1972
+	function show_next_x_db_queries($count = 1) {
1973 1973
 		$this->_show_next_x_db_queries = $count;
1974 1974
 	}
1975 1975
 
@@ -1978,8 +1978,8 @@  discard block
 block discarded – undo
1978 1978
 	/**
1979 1979
 	 * @param $sql_query
1980 1980
 	 */
1981
-	function show_db_query_if_previously_requested($sql_query){
1982
-		if($this->_show_next_x_db_queries > 0){
1981
+	function show_db_query_if_previously_requested($sql_query) {
1982
+		if ($this->_show_next_x_db_queries > 0) {
1983 1983
 			echo $sql_query;
1984 1984
 			$this->_show_next_x_db_queries--;
1985 1985
 		}
@@ -2003,9 +2003,9 @@  discard block
 block discarded – undo
2003 2003
 	 * @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.
2004 2004
 	 * @return EE_Base_Class which was added as a relation. Object referred to by $other_model_id_or_obj
2005 2005
 	 */
2006
-	public function add_relationship_to($id_or_obj,$other_model_id_or_obj, $relationName, $extra_join_model_fields_n_values = array()){
2006
+	public function add_relationship_to($id_or_obj, $other_model_id_or_obj, $relationName, $extra_join_model_fields_n_values = array()) {
2007 2007
 		$relation_obj = $this->related_settings_for($relationName);
2008
-		return $relation_obj->add_relation_to( $id_or_obj, $other_model_id_or_obj, $extra_join_model_fields_n_values);
2008
+		return $relation_obj->add_relation_to($id_or_obj, $other_model_id_or_obj, $extra_join_model_fields_n_values);
2009 2009
 	}
2010 2010
 
2011 2011
 	/**
@@ -2024,9 +2024,9 @@  discard block
 block discarded – undo
2024 2024
 	 * @return boolean of success
2025 2025
 	 * @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.
2026 2026
 	 */
2027
-	public function remove_relationship_to($id_or_obj,  $other_model_id_or_obj, $relationName, $where_query= array() ){
2027
+	public function remove_relationship_to($id_or_obj, $other_model_id_or_obj, $relationName, $where_query = array()) {
2028 2028
 		$relation_obj = $this->related_settings_for($relationName);
2029
-		return $relation_obj->remove_relation_to($id_or_obj, $other_model_id_or_obj, $where_query );
2029
+		return $relation_obj->remove_relation_to($id_or_obj, $other_model_id_or_obj, $where_query);
2030 2030
 	}
2031 2031
 
2032 2032
 
@@ -2039,9 +2039,9 @@  discard block
 block discarded – undo
2039 2039
 	 * @param EE_Base_Class[] objects to which relations were removed
2040 2040
 	 * @return \EE_Base_Class[]
2041 2041
 	 */
2042
-	public function remove_relations($id_or_obj,$relationName,$where_query_params = array()){
2042
+	public function remove_relations($id_or_obj, $relationName, $where_query_params = array()) {
2043 2043
 		$relation_obj = $this->related_settings_for($relationName);
2044
-		return $relation_obj->remove_relations($id_or_obj, $where_query_params );
2044
+		return $relation_obj->remove_relations($id_or_obj, $where_query_params);
2045 2045
 	}
2046 2046
 
2047 2047
 
@@ -2054,10 +2054,10 @@  discard block
 block discarded – undo
2054 2054
 	 * @param array $query_params like EEM_Base::get_all
2055 2055
 	 * @return EE_Base_Class[]
2056 2056
 	 */
2057
-	function get_all_related($id_or_obj, $model_name, $query_params = null){
2057
+	function get_all_related($id_or_obj, $model_name, $query_params = null) {
2058 2058
 		$model_obj = $this->ensure_is_obj($id_or_obj);
2059 2059
 		$relation_settings = $this->related_settings_for($model_name);
2060
-		return $relation_settings->get_all_related($model_obj,$query_params);
2060
+		return $relation_settings->get_all_related($model_obj, $query_params);
2061 2061
 	}
2062 2062
 
2063 2063
 	/**
@@ -2070,10 +2070,10 @@  discard block
 block discarded – undo
2070 2070
 	 * @param array $query_params
2071 2071
 	 * @return int how many deleted
2072 2072
 	 */
2073
-	public function delete_related($id_or_obj,$model_name, $query_params = array()){
2073
+	public function delete_related($id_or_obj, $model_name, $query_params = array()) {
2074 2074
 		$model_obj = $this->ensure_is_obj($id_or_obj);
2075 2075
 		$relation_settings = $this->related_settings_for($model_name);
2076
-		return $relation_settings->delete_all_related($model_obj,$query_params);
2076
+		return $relation_settings->delete_all_related($model_obj, $query_params);
2077 2077
 	}
2078 2078
 
2079 2079
 	/**
@@ -2086,10 +2086,10 @@  discard block
 block discarded – undo
2086 2086
 	 * @param array $query_params
2087 2087
 	 * @return int how many deleted
2088 2088
 	 */
2089
-	public function delete_related_permanently($id_or_obj,$model_name, $query_params = array()){
2089
+	public function delete_related_permanently($id_or_obj, $model_name, $query_params = array()) {
2090 2090
 		$model_obj = $this->ensure_is_obj($id_or_obj);
2091 2091
 		$relation_settings = $this->related_settings_for($model_name);
2092
-		return $relation_settings->delete_related_permanently($model_obj,$query_params);
2092
+		return $relation_settings->delete_related_permanently($model_obj, $query_params);
2093 2093
 	}
2094 2094
 
2095 2095
 	/**
@@ -2102,17 +2102,17 @@  discard block
 block discarded – undo
2102 2102
 	 * @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;
2103 2103
 	 * @return int
2104 2104
 	 */
2105
-	function count_related($id_or_obj,$model_name,$query_params = array(),$field_to_count = null, $distinct = FALSE){
2105
+	function count_related($id_or_obj, $model_name, $query_params = array(), $field_to_count = null, $distinct = FALSE) {
2106 2106
 		$related_model = $this->get_related_model_obj($model_name);
2107 2107
 		//we're just going to use the query params on the related model's normal get_all query,
2108 2108
 		//except add a condition to say to match the current mod
2109
-		if( ! isset($query_params['default_where_conditions'])){
2110
-			$query_params['default_where_conditions']='none';
2109
+		if ( ! isset($query_params['default_where_conditions'])) {
2110
+			$query_params['default_where_conditions'] = 'none';
2111 2111
 		}
2112 2112
 		$this_model_name = $this->get_this_model_name();
2113 2113
 		$this_pk_field_name = $this->get_primary_key_field()->get_name();
2114
-		$query_params[0][$this_model_name.".".$this_pk_field_name]=$id_or_obj;
2115
-		return $related_model->count($query_params,$field_to_count,$distinct);
2114
+		$query_params[0][$this_model_name.".".$this_pk_field_name] = $id_or_obj;
2115
+		return $related_model->count($query_params, $field_to_count, $distinct);
2116 2116
 	}
2117 2117
 
2118 2118
 
@@ -2126,21 +2126,21 @@  discard block
 block discarded – undo
2126 2126
 	 * @param string $field_to_sum name of field to count by. By default, uses primary key
2127 2127
 	 * @return float
2128 2128
 	 */
2129
-	function sum_related($id_or_obj,$model_name,$query_params,$field_to_sum = null){
2129
+	function sum_related($id_or_obj, $model_name, $query_params, $field_to_sum = null) {
2130 2130
 		$related_model = $this->get_related_model_obj($model_name);
2131
-		if( ! is_array( $query_params ) ){
2132
-			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' );
2131
+		if ( ! is_array($query_params)) {
2132
+			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');
2133 2133
 			$query_params = array();
2134 2134
 		}
2135 2135
 		//we're just going to use the query params on the related model's normal get_all query,
2136 2136
 		//except add a condition to say to match the current mod
2137
-		if( ! isset($query_params['default_where_conditions'])){
2138
-			$query_params['default_where_conditions']='none';
2137
+		if ( ! isset($query_params['default_where_conditions'])) {
2138
+			$query_params['default_where_conditions'] = 'none';
2139 2139
 		}
2140 2140
 		$this_model_name = $this->get_this_model_name();
2141 2141
 		$this_pk_field_name = $this->get_primary_key_field()->get_name();
2142
-		$query_params[0][$this_model_name.".".$this_pk_field_name]=$id_or_obj;
2143
-		return $related_model->sum($query_params,$field_to_sum);
2142
+		$query_params[0][$this_model_name.".".$this_pk_field_name] = $id_or_obj;
2143
+		return $related_model->sum($query_params, $field_to_sum);
2144 2144
 	}
2145 2145
 
2146 2146
 
@@ -2152,12 +2152,12 @@  discard block
 block discarded – undo
2152 2152
 	 * @param array $query_params like EEM_Base::get_all's
2153 2153
 	 * @return EE_Base_Class
2154 2154
 	 */
2155
-	public function get_first_related( EE_Base_Class $id_or_obj, $other_model_name, $query_params ){
2156
-		$query_params['limit']=1;
2157
-		$results = $this->get_all_related($id_or_obj,$other_model_name,$query_params);
2158
-		if( $results ){
2155
+	public function get_first_related(EE_Base_Class $id_or_obj, $other_model_name, $query_params) {
2156
+		$query_params['limit'] = 1;
2157
+		$results = $this->get_all_related($id_or_obj, $other_model_name, $query_params);
2158
+		if ($results) {
2159 2159
 			return array_shift($results);
2160
-		}else{
2160
+		} else {
2161 2161
 			return null;
2162 2162
 		}
2163 2163
 
@@ -2167,8 +2167,8 @@  discard block
 block discarded – undo
2167 2167
 	 * Gets the model's name as it's expected in queries. For example, if this is EEM_Event model, that would be Event
2168 2168
 	 * @return string
2169 2169
 	 */
2170
-	function get_this_model_name(){
2171
-		return str_replace("EEM_","",get_class($this));
2170
+	function get_this_model_name() {
2171
+		return str_replace("EEM_", "", get_class($this));
2172 2172
 	}
2173 2173
 
2174 2174
 	/**
@@ -2176,14 +2176,14 @@  discard block
 block discarded – undo
2176 2176
 	 * @return EE_Any_Foreign_Model_Name_Field
2177 2177
 	 * @throws EE_Error
2178 2178
 	 */
2179
-	public function get_field_containing_related_model_name(){
2180
-		foreach($this->field_settings(true) as $field){
2181
-			if($field instanceof EE_Any_Foreign_Model_Name_Field){
2179
+	public function get_field_containing_related_model_name() {
2180
+		foreach ($this->field_settings(true) as $field) {
2181
+			if ($field instanceof EE_Any_Foreign_Model_Name_Field) {
2182 2182
 				$field_with_model_name = $field;
2183 2183
 			}
2184 2184
 		}
2185
-		if( !isset($field_with_model_name) || !$field_with_model_name ){
2186
-			throw new EE_Error(sprintf(__("There is no EE_Any_Foreign_Model_Name field on model %s", "event_espresso"), $this->get_this_model_name() ));
2185
+		if ( ! isset($field_with_model_name) || ! $field_with_model_name) {
2186
+			throw new EE_Error(sprintf(__("There is no EE_Any_Foreign_Model_Name field on model %s", "event_espresso"), $this->get_this_model_name()));
2187 2187
 		}
2188 2188
 		return $field_with_model_name;
2189 2189
 	}
@@ -2204,19 +2204,19 @@  discard block
 block discarded – undo
2204 2204
 	 * @return int new primary key on main table that got inserted
2205 2205
 	 * @throws EE_Error
2206 2206
 	 */
2207
-	function insert($field_n_values){
2207
+	function insert($field_n_values) {
2208 2208
 		/**
2209 2209
 		 * Filters the fields and their values before inserting an item using the models
2210 2210
 		 * @param array $fields_n_values keys are the fields and values are their new values
2211 2211
 		 * @param EEM_Base $model the model used
2212 2212
 		 */
2213
-		$field_n_values = apply_filters( 'FHEE__EEM_Base__insert__fields_n_values', $field_n_values, $this );
2214
-		if($this->_satisfies_unique_indexes($field_n_values)){
2213
+		$field_n_values = apply_filters('FHEE__EEM_Base__insert__fields_n_values', $field_n_values, $this);
2214
+		if ($this->_satisfies_unique_indexes($field_n_values)) {
2215 2215
 			$main_table = $this->_get_main_table();
2216 2216
 			$new_id = $this->_insert_into_specific_table($main_table, $field_n_values, false);
2217
-			if( $new_id !== false ) {
2218
-				foreach($this->_get_other_tables() as $other_table){
2219
-					$this->_insert_into_specific_table($other_table, $field_n_values,$new_id);
2217
+			if ($new_id !== false) {
2218
+				foreach ($this->_get_other_tables() as $other_table) {
2219
+					$this->_insert_into_specific_table($other_table, $field_n_values, $new_id);
2220 2220
 				}
2221 2221
 			}
2222 2222
 			/**
@@ -2226,9 +2226,9 @@  discard block
 block discarded – undo
2226 2226
 			 * @param array $fields_n_values fields and their values
2227 2227
 			 * @param int|string the ID of the newly-inserted model object
2228 2228
 			 */
2229
-			do_action( 'AHEE__EEM_Base__insert__end', $this, $field_n_values, $new_id );
2229
+			do_action('AHEE__EEM_Base__insert__end', $this, $field_n_values, $new_id);
2230 2230
 			return $new_id;
2231
-		}else{
2231
+		} else {
2232 2232
 			return FALSE;
2233 2233
 		}
2234 2234
 	}
@@ -2241,11 +2241,11 @@  discard block
 block discarded – undo
2241 2241
 	 * @param string $action
2242 2242
 	 * @return boolean
2243 2243
 	 */
2244
-	protected function _satisfies_unique_indexes($field_n_values,$action = 'insert'){
2245
-		foreach($this->unique_indexes() as $index_name => $index){
2244
+	protected function _satisfies_unique_indexes($field_n_values, $action = 'insert') {
2245
+		foreach ($this->unique_indexes() as $index_name => $index) {
2246 2246
 			$uniqueness_where_params = array_intersect_key($field_n_values, $index->fields());
2247
-			if($this->exists(array($uniqueness_where_params))){
2248
-				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__ );
2247
+			if ($this->exists(array($uniqueness_where_params))) {
2248
+				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__);
2249 2249
 				return false;
2250 2250
 			}
2251 2251
 		}
@@ -2266,28 +2266,28 @@  discard block
 block discarded – undo
2266 2266
 	 * @throws EE_Error
2267 2267
 	 * @return EE_Base_Class
2268 2268
 	 */
2269
-	public function get_one_conflicting($obj_or_fields_array, $include_primary_key = true ){
2270
-		if($obj_or_fields_array instanceof EE_Base_Class){
2269
+	public function get_one_conflicting($obj_or_fields_array, $include_primary_key = true) {
2270
+		if ($obj_or_fields_array instanceof EE_Base_Class) {
2271 2271
 			$fields_n_values = $obj_or_fields_array->model_field_array();
2272
-		}elseif( is_array($obj_or_fields_array)){
2272
+		}elseif (is_array($obj_or_fields_array)) {
2273 2273
 			$fields_n_values = $obj_or_fields_array;
2274
-		}else{
2275
-			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));
2274
+		} else {
2275
+			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));
2276 2276
 		}
2277 2277
 		$query_params = array();
2278
-		if( $this->has_primary_key_field() &&
2279
-				( $include_primary_key || $this->get_primary_key_field() instanceof EE_Primary_Key_String_Field) &&
2280
-				isset($fields_n_values[$this->primary_key_name()])){
2278
+		if ($this->has_primary_key_field() &&
2279
+				($include_primary_key || $this->get_primary_key_field() instanceof EE_Primary_Key_String_Field) &&
2280
+				isset($fields_n_values[$this->primary_key_name()])) {
2281 2281
 			$query_params[0]['OR'][$this->primary_key_name()] = $fields_n_values[$this->primary_key_name()];
2282 2282
 		}
2283
-		foreach($this->unique_indexes() as $unique_index_name=>$unique_index){
2283
+		foreach ($this->unique_indexes() as $unique_index_name=>$unique_index) {
2284 2284
 			$uniqueness_where_params = array_intersect_key($fields_n_values, $unique_index->fields());
2285 2285
 			$query_params[0]['OR']['AND*'.$unique_index_name] = $uniqueness_where_params;
2286 2286
 		}
2287 2287
 		//if there is nothing to base this search on, then we shouldn't find anything
2288
-		if( empty( $query_params ) ){
2288
+		if (empty($query_params)) {
2289 2289
 			return array();
2290
-		}else{
2290
+		} else {
2291 2291
 			return $this->get_one($query_params);
2292 2292
 		}
2293 2293
 	}
@@ -2297,7 +2297,7 @@  discard block
 block discarded – undo
2297 2297
 	 * @param array $query_params
2298 2298
 	 * @return boolean
2299 2299
 	 */
2300
-	function exists($query_params){
2300
+	function exists($query_params) {
2301 2301
 		$query_params['limit'] = 1;
2302 2302
 		return $this->count($query_params) > 0;
2303 2303
 	}
@@ -2307,7 +2307,7 @@  discard block
 block discarded – undo
2307 2307
 	 * @param int|string $id
2308 2308
 	 * @return boolean
2309 2309
 	 */
2310
-	function exists_by_ID($id){
2310
+	function exists_by_ID($id) {
2311 2311
 		return $this->exists(array('default_where_conditions'=>'none', array($this->primary_key_name() => $id)));
2312 2312
 	}
2313 2313
 
@@ -2327,45 +2327,45 @@  discard block
 block discarded – undo
2327 2327
 	 * @global WPDB $wpdb only used to get the $wpdb->insert_id after performing an insert
2328 2328
 	 * @return int ID of new row inserted, or FALSE on failure
2329 2329
 	 */
2330
-	protected function _insert_into_specific_table(EE_Table_Base $table, $fields_n_values, $new_id = 0 ){
2330
+	protected function _insert_into_specific_table(EE_Table_Base $table, $fields_n_values, $new_id = 0) {
2331 2331
 		global $wpdb;
2332 2332
 		$insertion_col_n_values = array();
2333 2333
 		$format_for_insertion = array();
2334 2334
 		$fields_on_table = $this->_get_fields_for_table($table->get_table_alias());
2335
-		foreach($fields_on_table as $field_name => $field_obj){
2335
+		foreach ($fields_on_table as $field_name => $field_obj) {
2336 2336
 			//check if its an auto-incrementing column, in which case we should just leave it to do its autoincrement thing
2337
-			if($field_obj->is_auto_increment()){
2337
+			if ($field_obj->is_auto_increment()) {
2338 2338
 				continue;
2339 2339
 			}
2340 2340
 			$prepared_value = $this->_prepare_value_or_use_default($field_obj, $fields_n_values);
2341 2341
 			//if the value we want to assign it to is NULL, just don't mention it for the insertion
2342
-			if( $prepared_value !== NULL ){
2343
-				$insertion_col_n_values[ $field_obj->get_table_column() ] = $prepared_value;
2342
+			if ($prepared_value !== NULL) {
2343
+				$insertion_col_n_values[$field_obj->get_table_column()] = $prepared_value;
2344 2344
 				$format_for_insertion[] = $field_obj->get_wpdb_data_type();
2345 2345
 			}
2346 2346
 		}
2347 2347
 
2348
-		if($table instanceof EE_Secondary_Table && $new_id){
2348
+		if ($table instanceof EE_Secondary_Table && $new_id) {
2349 2349
 			//its not the main table, so we should have already saved the main table's PK which we just inserted
2350 2350
 			//so add the fk to the main table as a column
2351 2351
 			$insertion_col_n_values[$table->get_fk_on_table()] = $new_id;
2352
-			$format_for_insertion[]='%d';//yes right now we're only allowing these foreign keys to be INTs
2352
+			$format_for_insertion[] = '%d'; //yes right now we're only allowing these foreign keys to be INTs
2353 2353
 		}
2354 2354
 		//insert the new entry
2355
-		$result = $this->_do_wpdb_query( 'insert', array( $table->get_table_name(), $insertion_col_n_values, $format_for_insertion ) );
2356
-		if( $result === false ) {
2355
+		$result = $this->_do_wpdb_query('insert', array($table->get_table_name(), $insertion_col_n_values, $format_for_insertion));
2356
+		if ($result === false) {
2357 2357
 			return false;
2358 2358
 		}
2359 2359
 		//ok, now what do we return for the ID of the newly-inserted thing?
2360
-		if($this->has_primary_key_field()){
2361
-			if($this->get_primary_key_field()->is_auto_increment()){
2360
+		if ($this->has_primary_key_field()) {
2361
+			if ($this->get_primary_key_field()->is_auto_increment()) {
2362 2362
 				return $wpdb->insert_id;
2363
-			}else{
2363
+			} else {
2364 2364
 				//it's not an auto-increment primary key, so
2365 2365
 				//it must have been supplied
2366 2366
 				return $fields_n_values[$this->get_primary_key_field()->get_name()];
2367 2367
 			}
2368
-		}else{
2368
+		} else {
2369 2369
 			//we can't return a  primary key because there is none. instead return
2370 2370
 			//a unique string indicating this model
2371 2371
 			return $this->get_index_primary_key_string($fields_n_values);
@@ -2380,15 +2380,15 @@  discard block
 block discarded – undo
2380 2380
 	 * @param array $fields_n_values
2381 2381
 	 * @return mixed string|int|float depending on what the table column will be expecting
2382 2382
 	 */
2383
-	protected function _prepare_value_or_use_default( $field_obj, $fields_n_values ){
2383
+	protected function _prepare_value_or_use_default($field_obj, $fields_n_values) {
2384 2384
 		//if this field doesn't allow nullable, don't allow it
2385
-		if( ! $field_obj->is_nullable() && (
2386
-				! isset( $fields_n_values[ $field_obj->get_name() ] ) ||
2387
-				$fields_n_values[ $field_obj->get_name() ] === NULL ) ){
2388
-			$fields_n_values[ $field_obj->get_name() ] = $field_obj->get_default_value();
2385
+		if ( ! $field_obj->is_nullable() && (
2386
+				! isset($fields_n_values[$field_obj->get_name()]) ||
2387
+				$fields_n_values[$field_obj->get_name()] === NULL )) {
2388
+			$fields_n_values[$field_obj->get_name()] = $field_obj->get_default_value();
2389 2389
 		}
2390
-		$unprepared_value = isset( $fields_n_values[ $field_obj->get_name() ] ) ? $fields_n_values[ $field_obj->get_name() ] : NULL;
2391
-		return $this->_prepare_value_for_use_in_db( $unprepared_value, $field_obj);
2390
+		$unprepared_value = isset($fields_n_values[$field_obj->get_name()]) ? $fields_n_values[$field_obj->get_name()] : NULL;
2391
+		return $this->_prepare_value_for_use_in_db($unprepared_value, $field_obj);
2392 2392
 	}
2393 2393
 
2394 2394
 
@@ -2400,9 +2400,9 @@  discard block
 block discarded – undo
2400 2400
 	 * @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
2401 2401
 	 * @return mixed a value ready for use in the database for insertions, updating, or in a where clause
2402 2402
 	 */
2403
-	private function _prepare_value_for_use_in_db($value, $field){
2404
-		if($field && $field instanceof EE_Model_Field_Base){
2405
-			switch( $this->_values_already_prepared_by_model_object ){
2403
+	private function _prepare_value_for_use_in_db($value, $field) {
2404
+		if ($field && $field instanceof EE_Model_Field_Base) {
2405
+			switch ($this->_values_already_prepared_by_model_object) {
2406 2406
 				/** @noinspection PhpMissingBreakStatementInspection */
2407 2407
 				case self::not_prepared_by_model_object:
2408 2408
 					$value = $field->prepare_for_set($value);
@@ -2413,7 +2413,7 @@  discard block
 block discarded – undo
2413 2413
 					//leave the value alone
2414 2414
 			}
2415 2415
 			return $value;
2416
-		}else{
2416
+		} else {
2417 2417
 			return $value;
2418 2418
 		}
2419 2419
 	}
@@ -2423,13 +2423,13 @@  discard block
 block discarded – undo
2423 2423
 	 * @return EE_Primary_Table
2424 2424
 	 * @throws EE_Error
2425 2425
 	 */
2426
-	protected function _get_main_table(){
2427
-		foreach($this->_tables as $table){
2428
-			if($table instanceof EE_Primary_Table){
2426
+	protected function _get_main_table() {
2427
+		foreach ($this->_tables as $table) {
2428
+			if ($table instanceof EE_Primary_Table) {
2429 2429
 				return $table;
2430 2430
 			}
2431 2431
 		}
2432
-		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)));
2432
+		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)));
2433 2433
 	}
2434 2434
 
2435 2435
 	/**
@@ -2448,7 +2448,7 @@  discard block
 block discarded – undo
2448 2448
 	 */
2449 2449
 	public function second_table() {
2450 2450
 		// grab second table from tables array
2451
-		$second_table = end( $this->_tables );
2451
+		$second_table = end($this->_tables);
2452 2452
 		return $second_table instanceof EE_Secondary_Table ? $second_table->get_table_name() : NULL;
2453 2453
 	}
2454 2454
 
@@ -2461,8 +2461,8 @@  discard block
 block discarded – undo
2461 2461
 	 * @param string $table_alias
2462 2462
 	 * @return EE_Primary_Table | EE_Secondary_Table
2463 2463
 	 */
2464
-	public function get_table_obj_by_alias( $table_alias = '' ) {
2465
-		return isset( $this->_tables[ $table_alias ] ) ? $this->_tables[ $table_alias ] : NULL;
2464
+	public function get_table_obj_by_alias($table_alias = '') {
2465
+		return isset($this->_tables[$table_alias]) ? $this->_tables[$table_alias] : NULL;
2466 2466
 	}
2467 2467
 
2468 2468
 
@@ -2471,10 +2471,10 @@  discard block
 block discarded – undo
2471 2471
 	 * Gets all the tables of type EE_Other_Table from EEM_CPT_Basel_Model::_tables
2472 2472
 	 * @return EE_Secondary_Table[]
2473 2473
 	 */
2474
-	protected function _get_other_tables(){
2475
-		$other_tables =array();
2476
-		foreach($this->_tables as $table_alias => $table){
2477
-			if($table instanceof EE_Secondary_Table){
2474
+	protected function _get_other_tables() {
2475
+		$other_tables = array();
2476
+		foreach ($this->_tables as $table_alias => $table) {
2477
+			if ($table instanceof EE_Secondary_Table) {
2478 2478
 				$other_tables[$table_alias] = $table;
2479 2479
 			}
2480 2480
 		}
@@ -2486,7 +2486,7 @@  discard block
 block discarded – undo
2486 2486
 	 * @param string $table_alias, array key in EEM_Base::_tables
2487 2487
 	 * @return EE_Model_Field_Base[]
2488 2488
 	 */
2489
-	function _get_fields_for_table($table_alias){
2489
+	function _get_fields_for_table($table_alias) {
2490 2490
 		return $this->_fields[$table_alias];
2491 2491
 	}
2492 2492
 
@@ -2498,29 +2498,29 @@  discard block
 block discarded – undo
2498 2498
 	 * @param array $query_params like EEM_Base::get_all's $query_parameters['where']
2499 2499
 	 * @return EE_Model_Query_Info_Carrier
2500 2500
 	 */
2501
-	function _extract_related_models_from_query($query_params){
2501
+	function _extract_related_models_from_query($query_params) {
2502 2502
 		$query_info_carrier = new EE_Model_Query_Info_Carrier();
2503
-		if(array_key_exists(0,$query_params)){
2504
-			$this->_extract_related_models_from_sub_params_array_keys($query_params[0], $query_info_carrier,0);
2505
-		}
2506
-		if(array_key_exists('group_by', $query_params)){
2507
-			if(is_array($query_params['group_by'])){
2508
-				$this->_extract_related_models_from_sub_params_array_values($query_params['group_by'],$query_info_carrier,'group_by');
2509
-			}elseif( ! empty ( $query_params['group_by'] )){
2510
-				$this->_extract_related_model_info_from_query_param( $query_params['group_by'],$query_info_carrier,'group_by');
2503
+		if (array_key_exists(0, $query_params)) {
2504
+			$this->_extract_related_models_from_sub_params_array_keys($query_params[0], $query_info_carrier, 0);
2505
+		}
2506
+		if (array_key_exists('group_by', $query_params)) {
2507
+			if (is_array($query_params['group_by'])) {
2508
+				$this->_extract_related_models_from_sub_params_array_values($query_params['group_by'], $query_info_carrier, 'group_by');
2509
+			}elseif ( ! empty ($query_params['group_by'])) {
2510
+				$this->_extract_related_model_info_from_query_param($query_params['group_by'], $query_info_carrier, 'group_by');
2511 2511
 			}
2512 2512
 		}
2513
-		if(array_key_exists('having',$query_params)){
2514
-			$this->_extract_related_models_from_sub_params_array_keys($query_params[0], $query_info_carrier,'having');
2513
+		if (array_key_exists('having', $query_params)) {
2514
+			$this->_extract_related_models_from_sub_params_array_keys($query_params[0], $query_info_carrier, 'having');
2515 2515
 		}
2516
-		if(array_key_exists('order_by', $query_params)){
2517
-			if ( is_array( $query_params['order_by'] ) )
2518
-				$this->_extract_related_models_from_sub_params_array_keys($query_params['order_by'],$query_info_carrier,'order_by');
2519
-			elseif( ! empty( $query_params['order_by'] ))
2520
-				$this->_extract_related_model_info_from_query_param( $query_params['order_by'], $query_info_carrier,'order_by');
2516
+		if (array_key_exists('order_by', $query_params)) {
2517
+			if (is_array($query_params['order_by']))
2518
+				$this->_extract_related_models_from_sub_params_array_keys($query_params['order_by'], $query_info_carrier, 'order_by');
2519
+			elseif ( ! empty($query_params['order_by']))
2520
+				$this->_extract_related_model_info_from_query_param($query_params['order_by'], $query_info_carrier, 'order_by');
2521 2521
 		}
2522
-		if(array_key_exists('force_join', $query_params)){
2523
-			$this->_extract_related_models_from_sub_params_array_values($query_params['force_join'],$query_info_carrier,'force_join');
2522
+		if (array_key_exists('force_join', $query_params)) {
2523
+			$this->_extract_related_models_from_sub_params_array_values($query_params['force_join'], $query_info_carrier, 'force_join');
2524 2524
 		}
2525 2525
 		return $query_info_carrier;
2526 2526
 	}
@@ -2533,34 +2533,34 @@  discard block
 block discarded – undo
2533 2533
 	 * @throws EE_Error
2534 2534
 	 * @return \EE_Model_Query_Info_Carrier
2535 2535
 	 */
2536
-	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){
2537
-		if (!empty($sub_query_params)){
2536
+	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) {
2537
+		if ( ! empty($sub_query_params)) {
2538 2538
 			$sub_query_params = (array) $sub_query_params;
2539
-			foreach($sub_query_params as $param => $possibly_array_of_params){
2539
+			foreach ($sub_query_params as $param => $possibly_array_of_params) {
2540 2540
 				//$param could be simply 'EVT_ID', or it could be 'Registrations.REG_ID', or even 'Registrations.Transactions.Payments.PAY_amount'
2541
-				$this->_extract_related_model_info_from_query_param( $param, $model_query_info_carrier,$query_param_type);
2541
+				$this->_extract_related_model_info_from_query_param($param, $model_query_info_carrier, $query_param_type);
2542 2542
 
2543 2543
 				//if $possibly_array_of_params is an array, try recursing into it, searching for keys which
2544 2544
 				//indicate needed joins. Eg, array('NOT'=>array('Registration.TXN_ID'=>23)). In this case, we tried
2545 2545
 				//extracting models out of the 'NOT', which obviously wasn't successful, and then we recurse into the value
2546 2546
 				//of array('Registration.TXN_ID'=>23)
2547 2547
 				$query_param_sans_stars = $this->_remove_stars_and_anything_after_from_condition_query_param_key($param);
2548
-				if(in_array($query_param_sans_stars, $this->_logic_query_param_keys,true)){
2549
-					if (! is_array($possibly_array_of_params)){
2548
+				if (in_array($query_param_sans_stars, $this->_logic_query_param_keys, true)) {
2549
+					if ( ! is_array($possibly_array_of_params)) {
2550 2550
 						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"),
2551
-							$param,$possibly_array_of_params));
2552
-					}else{
2553
-						$this->_extract_related_models_from_sub_params_array_keys($possibly_array_of_params, $model_query_info_carrier,$query_param_type);
2551
+							$param, $possibly_array_of_params));
2552
+					} else {
2553
+						$this->_extract_related_models_from_sub_params_array_keys($possibly_array_of_params, $model_query_info_carrier, $query_param_type);
2554 2554
 					}
2555
-				}elseif($query_param_type === 0 //ie WHERE
2555
+				}elseif ($query_param_type === 0 //ie WHERE
2556 2556
 						&& is_array($possibly_array_of_params)
2557 2557
 						&& isset($possibly_array_of_params[2])
2558
-						&& $possibly_array_of_params[2] == true){
2558
+						&& $possibly_array_of_params[2] == true) {
2559 2559
 					//then $possible_array_of_params looks something like array('<','DTT_sold',true)
2560 2560
 					//indicating that $possible_array_of_params[1] is actually a field name,
2561 2561
 					//from which we should extract query parameters!
2562
-					if(! isset($possibly_array_of_params[0]) || ! isset($possibly_array_of_params[1])){
2563
-						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)));
2562
+					if ( ! isset($possibly_array_of_params[0]) || ! isset($possibly_array_of_params[1])) {
2563
+						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)));
2564 2564
 					}
2565 2565
 					$this->_extract_related_model_info_from_query_param($possibly_array_of_params[1], $model_query_info_carrier, $query_param_type);
2566 2566
 				}
@@ -2579,14 +2579,14 @@  discard block
 block discarded – undo
2579 2579
 	 * @throws EE_Error
2580 2580
 	 * @return \EE_Model_Query_Info_Carrier
2581 2581
 	 */
2582
-	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){
2583
-		if (!empty($sub_query_params)){
2584
-			if(!is_array($sub_query_params)){
2585
-				throw new EE_Error(sprintf(__("Query parameter %s should be an array, but it isn't.", "event_espresso"),$sub_query_params));
2582
+	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) {
2583
+		if ( ! empty($sub_query_params)) {
2584
+			if ( ! is_array($sub_query_params)) {
2585
+				throw new EE_Error(sprintf(__("Query parameter %s should be an array, but it isn't.", "event_espresso"), $sub_query_params));
2586 2586
 			}
2587
-			foreach($sub_query_params as $param){
2587
+			foreach ($sub_query_params as $param) {
2588 2588
 				//$param could be simply 'EVT_ID', or it could be 'Registrations.REG_ID', or even 'Registrations.Transactions.Payments.PAY_amount'
2589
-				$this->_extract_related_model_info_from_query_param( $param, $model_query_info_carrier, $query_param_type);
2589
+				$this->_extract_related_model_info_from_query_param($param, $model_query_info_carrier, $query_param_type);
2590 2590
 			}
2591 2591
 		}
2592 2592
 		return $model_query_info_carrier;
@@ -2605,81 +2605,81 @@  discard block
 block discarded – undo
2605 2605
 	 * @throws EE_Error
2606 2606
 	 * @return EE_Model_Query_Info_Carrier
2607 2607
 	 */
2608
-	function _create_model_query_info_carrier($query_params){
2609
-		if( ! is_array( $query_params ) ){
2610
-			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' );
2608
+	function _create_model_query_info_carrier($query_params) {
2609
+		if ( ! is_array($query_params)) {
2610
+			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');
2611 2611
 			$query_params = array();
2612 2612
 		}
2613
-		if( isset( $query_params[0] ) ) {
2613
+		if (isset($query_params[0])) {
2614 2614
 			$where_query_params = $query_params[0];
2615
-		}else{
2615
+		} else {
2616 2616
 			$where_query_params = array();
2617 2617
 		}
2618 2618
 		//first check if we should alter the query to account for caps or not
2619 2619
 		//because the caps might require us to do extra joins
2620
-		if( isset( $query_params[ 'caps' ] ) && $query_params[ 'caps' ] != 'none' ) {
2621
-			$query_params[0] = $where_query_params = array_replace_recursive( $where_query_params, $this->caps_where_conditions( $query_params[ 'caps' ] ) );
2620
+		if (isset($query_params['caps']) && $query_params['caps'] != 'none') {
2621
+			$query_params[0] = $where_query_params = array_replace_recursive($where_query_params, $this->caps_where_conditions($query_params['caps']));
2622 2622
 		}
2623 2623
 		$query_object = $this->_extract_related_models_from_query($query_params);
2624 2624
 
2625 2625
 		//verify where_query_params has NO numeric indexes.... that's simply not how you use it!
2626
-		foreach($where_query_params as $key => $value){
2627
-			if(is_int($key)){
2628
-				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)));
2626
+		foreach ($where_query_params as $key => $value) {
2627
+			if (is_int($key)) {
2628
+				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)));
2629 2629
 			}
2630 2630
 		}
2631
-		if( array_key_exists( 'default_where_conditions',$query_params) && ! empty( $query_params['default_where_conditions'] )){
2631
+		if (array_key_exists('default_where_conditions', $query_params) && ! empty($query_params['default_where_conditions'])) {
2632 2632
 			$use_default_where_conditions = $query_params['default_where_conditions'];
2633
-		}else{
2633
+		} else {
2634 2634
 			$use_default_where_conditions = 'all';
2635 2635
 		}
2636
-		$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 );
2637
-		$query_object->set_where_sql( $this->_construct_where_clause($where_query_params));
2636
+		$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);
2637
+		$query_object->set_where_sql($this->_construct_where_clause($where_query_params));
2638 2638
 
2639 2639
 
2640 2640
 		//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:
2641 2641
 		//array( 'on_join_limit' => array('Primary_Table_Alias', array(1,10) ) )
2642
-		if ( array_key_exists('on_join_limit', $query_params ) && ! empty( $query_params['on_join_limit'] )) {
2643
-			$query_object->set_main_model_join_sql( $this->_construct_limit_join_select( $query_params['on_join_limit'][0], $query_params['on_join_limit'][1] ) );
2642
+		if (array_key_exists('on_join_limit', $query_params) && ! empty($query_params['on_join_limit'])) {
2643
+			$query_object->set_main_model_join_sql($this->_construct_limit_join_select($query_params['on_join_limit'][0], $query_params['on_join_limit'][1]));
2644 2644
 		}
2645 2645
 
2646 2646
 
2647 2647
 		//set limit
2648
-		if(array_key_exists('limit',$query_params)){
2649
-			if(is_array($query_params['limit'])){
2650
-				if( ! isset($query_params['limit'][0]) || ! isset($query_params['limit'][1])){
2651
-					$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']));
2648
+		if (array_key_exists('limit', $query_params)) {
2649
+			if (is_array($query_params['limit'])) {
2650
+				if ( ! isset($query_params['limit'][0]) || ! isset($query_params['limit'][1])) {
2651
+					$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']));
2652 2652
 					throw new EE_Error($e."|".$e);
2653 2653
 				}
2654 2654
 				//they passed us an array for the limit. Assume it's like array(50,25), meaning offset by 50, and get 25
2655 2655
 				$query_object->set_limit_sql(" LIMIT ".$query_params['limit'][0].",".$query_params['limit'][1]);
2656
-			}elseif( ! empty ( $query_params['limit'] )){
2656
+			}elseif ( ! empty ($query_params['limit'])) {
2657 2657
 				$query_object->set_limit_sql((" LIMIT ".$query_params['limit']));
2658 2658
 			}
2659 2659
 		}
2660 2660
 		//set order by
2661
-		if(array_key_exists('order_by',$query_params)){
2662
-			if(is_array($query_params['order_by'])){
2661
+		if (array_key_exists('order_by', $query_params)) {
2662
+			if (is_array($query_params['order_by'])) {
2663 2663
 				//if they're using 'order_by' as an array, they can't use 'order' (because 'order_by' must
2664 2664
 				//specify whether to ascend or descend on each field. Eg 'order_by'=>array('EVT_ID'=>'ASC'). So
2665 2665
 				//including 'order' wouldn't make any sense if 'order_by' has already specified which way to order!
2666
-				if(array_key_exists('order', $query_params)){
2666
+				if (array_key_exists('order', $query_params)) {
2667 2667
 					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"),
2668
-							get_class($this),implode(", ",array_keys($query_params['order_by'])),implode(", ",$query_params['order_by']),$query_params['order']));
2668
+							get_class($this), implode(", ", array_keys($query_params['order_by'])), implode(", ", $query_params['order_by']), $query_params['order']));
2669 2669
 				}
2670
-				 $this->_extract_related_models_from_sub_params_array_keys($query_params['order_by'],$query_object,'order_by');
2670
+				 $this->_extract_related_models_from_sub_params_array_keys($query_params['order_by'], $query_object, 'order_by');
2671 2671
 				//assume it's an array of fields to order by
2672 2672
 				$order_array = array();
2673
-				foreach($query_params['order_by'] as $field_name_to_order_by => $order){
2673
+				foreach ($query_params['order_by'] as $field_name_to_order_by => $order) {
2674 2674
 					$order = $this->_extract_order($order);
2675 2675
 					$order_array[] = $this->_deduce_column_name_from_query_param($field_name_to_order_by).SP.$order;
2676 2676
 				}
2677
-				$query_object->set_order_by_sql(" ORDER BY ".implode(",",$order_array));
2678
-			}elseif( ! empty ( $query_params['order_by'] )){
2679
-				$this->_extract_related_model_info_from_query_param($query_params['order_by'],$query_object,'order',$query_params['order_by']);
2680
-				if(isset($query_params['order'])){
2677
+				$query_object->set_order_by_sql(" ORDER BY ".implode(",", $order_array));
2678
+			}elseif ( ! empty ($query_params['order_by'])) {
2679
+				$this->_extract_related_model_info_from_query_param($query_params['order_by'], $query_object, 'order', $query_params['order_by']);
2680
+				if (isset($query_params['order'])) {
2681 2681
 					$order = $this->_extract_order($query_params['order']);
2682
-				}else{
2682
+				} else {
2683 2683
 					$order = 'DESC';
2684 2684
 				}
2685 2685
 				$query_object->set_order_by_sql(" ORDER BY ".$this->_deduce_column_name_from_query_param($query_params['order_by']).SP.$order);
@@ -2687,46 +2687,46 @@  discard block
 block discarded – undo
2687 2687
 		}
2688 2688
 
2689 2689
 		//if 'order_by' wasn't set, maybe they are just using 'order' on its own?
2690
-		if( ! array_key_exists('order_by',$query_params) && array_key_exists('order',$query_params) && ! empty( $query_params['order'] )){
2690
+		if ( ! array_key_exists('order_by', $query_params) && array_key_exists('order', $query_params) && ! empty($query_params['order'])) {
2691 2691
 			$pk_field = $this->get_primary_key_field();
2692 2692
 			$order = $this->_extract_order($query_params['order']);
2693 2693
 			$query_object->set_order_by_sql(" ORDER BY ".$pk_field->get_qualified_column().SP.$order);
2694 2694
 		}
2695 2695
 
2696 2696
 		//set group by
2697
-		if(array_key_exists('group_by',$query_params)){
2698
-			if(is_array($query_params['group_by'])){
2697
+		if (array_key_exists('group_by', $query_params)) {
2698
+			if (is_array($query_params['group_by'])) {
2699 2699
 				//it's an array, so assume we'll be grouping by a bunch of stuff
2700 2700
 				$group_by_array = array();
2701
-				foreach($query_params['group_by'] as $field_name_to_group_by){
2701
+				foreach ($query_params['group_by'] as $field_name_to_group_by) {
2702 2702
 					$group_by_array[] = $this->_deduce_column_name_from_query_param($field_name_to_group_by);
2703 2703
 				}
2704
-				$query_object->set_group_by_sql(" GROUP BY ".implode(", ",$group_by_array));
2705
-			}elseif( ! empty ( $query_params['group_by'] )){
2704
+				$query_object->set_group_by_sql(" GROUP BY ".implode(", ", $group_by_array));
2705
+			}elseif ( ! empty ($query_params['group_by'])) {
2706 2706
 				$query_object->set_group_by_sql(" GROUP BY ".$this->_deduce_column_name_from_query_param($query_params['group_by']));
2707 2707
 			}
2708 2708
 		}
2709 2709
 		//set having
2710
-		if(array_key_exists('having',$query_params) && $query_params['having']){
2711
-			$query_object->set_having_sql( $this->_construct_having_clause($query_params['having']));
2710
+		if (array_key_exists('having', $query_params) && $query_params['having']) {
2711
+			$query_object->set_having_sql($this->_construct_having_clause($query_params['having']));
2712 2712
 		}
2713 2713
 
2714 2714
 		//now, just verify they didn't pass anything wack
2715
-		foreach($query_params as $query_key => $query_value){
2716
-			if( ! in_array($query_key,$this->_allowed_query_params,true)){
2715
+		foreach ($query_params as $query_key => $query_value) {
2716
+			if ( ! in_array($query_key, $this->_allowed_query_params, true)) {
2717 2717
 				throw new EE_Error(
2718 2718
 					sprintf(
2719
-						__("You passed %s as a query parameter to %s, which is illegal! The allowed query parameters are %s",'event_espresso'),
2719
+						__("You passed %s as a query parameter to %s, which is illegal! The allowed query parameters are %s", 'event_espresso'),
2720 2720
 						$query_key,
2721 2721
 						get_class($this),
2722 2722
 //						print_r( $this->_allowed_query_params, TRUE )
2723
-						implode( ',', $this->_allowed_query_params )
2723
+						implode(',', $this->_allowed_query_params)
2724 2724
 					)
2725 2725
 				);
2726 2726
 			}
2727 2727
 		}
2728 2728
 		$main_model_join_sql = $query_object->get_main_model_join_sql();
2729
-		if ( empty( $main_model_join_sql ) )
2729
+		if (empty($main_model_join_sql))
2730 2730
 			$query_object->set_main_model_join_sql($this->_construct_internal_join());
2731 2731
 		return $query_object;
2732 2732
 	}
@@ -2737,17 +2737,17 @@  discard block
 block discarded – undo
2737 2737
 	 * @param string $context one of EEM_Base::valid_cap_contexts()
2738 2738
 	 * @return array like EEM_Base::get_all() 's $query_params[0]
2739 2739
 	 */
2740
-	public function caps_where_conditions( $context = self::caps_read ) {
2741
-		EEM_Base::verify_is_valid_cap_context( $context );
2740
+	public function caps_where_conditions($context = self::caps_read) {
2741
+		EEM_Base::verify_is_valid_cap_context($context);
2742 2742
 		$cap_where_conditions = array();
2743
-		$cap_restrictions = $this->caps_missing( $context );
2743
+		$cap_restrictions = $this->caps_missing($context);
2744 2744
 		/**
2745 2745
 		 * @var $cap_restrictions EE_Default_Where_Conditions[]
2746 2746
 		 */
2747
-		foreach( $cap_restrictions as $cap => $restriction_if_no_cap ) {
2748
-				$cap_where_conditions = array_replace_recursive( $cap_where_conditions, $restriction_if_no_cap->get_default_where_conditions() );
2747
+		foreach ($cap_restrictions as $cap => $restriction_if_no_cap) {
2748
+				$cap_where_conditions = array_replace_recursive($cap_where_conditions, $restriction_if_no_cap->get_default_where_conditions());
2749 2749
 		}
2750
-		return apply_filters( 'FHEE__EEM_Base__caps_where_conditions__return', $cap_where_conditions, $this, $context, $cap_restrictions );
2750
+		return apply_filters('FHEE__EEM_Base__caps_where_conditions__return', $cap_where_conditions, $this, $context, $cap_restrictions);
2751 2751
 	}
2752 2752
 
2753 2753
 	/**
@@ -2757,11 +2757,11 @@  discard block
 block discarded – undo
2757 2757
 	 * @return string either ASC, asc, DESC or desc
2758 2758
 	 * @throws EE_Error
2759 2759
 	 */
2760
-	private function _extract_order($should_be_order_string){
2761
-		if(in_array($should_be_order_string, $this->_allowed_order_values)){
2760
+	private function _extract_order($should_be_order_string) {
2761
+		if (in_array($should_be_order_string, $this->_allowed_order_values)) {
2762 2762
 			return $should_be_order_string;
2763
-		}else{
2764
-			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));
2763
+		} else {
2764
+			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));
2765 2765
 		}
2766 2766
 	}
2767 2767
 
@@ -2779,7 +2779,7 @@  discard block
 block discarded – undo
2779 2779
 	 * @throws EE_Error
2780 2780
 	 * @return array like $query_params[0], see EEM_Base::get_all for documentation
2781 2781
 	 */
2782
-	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()){
2782
+	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()) {
2783 2783
 		$allowed_used_default_where_conditions_values = array(
2784 2784
 				'all',
2785 2785
 				'this_model_only', 
@@ -2787,19 +2787,19 @@  discard block
 block discarded – undo
2787 2787
 				'minimum',
2788 2788
 				'none'
2789 2789
 			);
2790
-		if( ! in_array($use_default_where_conditions,$allowed_used_default_where_conditions_values)){
2791
-			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)));
2790
+		if ( ! in_array($use_default_where_conditions, $allowed_used_default_where_conditions_values)) {
2791
+			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)));
2792 2792
 		}
2793
-		if( in_array($use_default_where_conditions, array('all','this_model_only')) ){
2793
+		if (in_array($use_default_where_conditions, array('all', 'this_model_only'))) {
2794 2794
 			$universal_query_params = $this->_get_default_where_conditions();
2795
-		}elseif( in_array( $use_default_where_conditions, array( 'minimum' ) ) ) {
2795
+		}elseif (in_array($use_default_where_conditions, array('minimum'))) {
2796 2796
 			$universal_query_params = $this->_get_minimum_where_conditions();
2797
-		}else{
2797
+		} else {
2798 2798
 			$universal_query_params = array();
2799 2799
 		}
2800 2800
 
2801
-		if(in_array($use_default_where_conditions,array('all','other_models_only'))){
2802
-			foreach($query_info_carrier->get_model_names_included() as $model_relation_path => $model_name){
2801
+		if (in_array($use_default_where_conditions, array('all', 'other_models_only'))) {
2802
+			foreach ($query_info_carrier->get_model_names_included() as $model_relation_path => $model_name) {
2803 2803
 				$related_model = $this->get_related_model_obj($model_name);
2804 2804
 				$related_model_universal_where_params = $related_model->_get_default_where_conditions($model_relation_path);
2805 2805
 
@@ -2826,22 +2826,22 @@  discard block
 block discarded – undo
2826 2826
 	 * @param string $model_relation_path like 'Transaction.Payment.'
2827 2827
 	 * @return array like EEM_Base::get_all's $query_params[0]
2828 2828
 	 */
2829
-	private function _override_defaults_or_make_null_friendly($default_where_conditions,$provided_where_conditions,$model,$model_relation_path){
2829
+	private function _override_defaults_or_make_null_friendly($default_where_conditions, $provided_where_conditions, $model, $model_relation_path) {
2830 2830
 		$null_friendly_where_conditions = array();
2831 2831
 		$none_overridden = true;
2832 2832
 		$or_condition_key_for_defaults = 'OR*'.get_class($model);
2833 2833
 
2834
-		foreach($default_where_conditions as $key => $val){
2835
-			if( isset($provided_where_conditions[$key])){
2834
+		foreach ($default_where_conditions as $key => $val) {
2835
+			if (isset($provided_where_conditions[$key])) {
2836 2836
 				$none_overridden = false;
2837
-			}else{
2837
+			} else {
2838 2838
 				$null_friendly_where_conditions[$or_condition_key_for_defaults]['AND'][$key] = $val;
2839 2839
 			}
2840 2840
 		}
2841
-		if( $none_overridden && $default_where_conditions){
2842
-			if($model->has_primary_key_field()){
2841
+		if ($none_overridden && $default_where_conditions) {
2842
+			if ($model->has_primary_key_field()) {
2843 2843
 				$null_friendly_where_conditions[$or_condition_key_for_defaults][$model_relation_path.".".$model->primary_key_name()] = array('IS NULL');
2844
-			}else{
2844
+			} else {
2845 2845
 				//@todo NO PK, use other defaults
2846 2846
 			}
2847 2847
 		}
@@ -2856,8 +2856,8 @@  discard block
 block discarded – undo
2856 2856
 	 * @param string $model_relation_path eg, path from Event to Payment is "Registration.Transaction.Payment."
2857 2857
 	 * @return array like EEM_Base::get_all's $query_params[0] (where conditions)
2858 2858
 	 */
2859
-	private function _get_default_where_conditions($model_relation_path = null){
2860
-		if ( $this->_ignore_where_strategy )
2859
+	private function _get_default_where_conditions($model_relation_path = null) {
2860
+		if ($this->_ignore_where_strategy)
2861 2861
 			return array();
2862 2862
 
2863 2863
 		return $this->_default_where_conditions_strategy->get_default_where_conditions($model_relation_path);
@@ -2871,8 +2871,8 @@  discard block
 block discarded – undo
2871 2871
 	 * @param string $model_relation_path eg, path from Event to Payment is "Registration.Transaction.Payment."
2872 2872
 	 * @return array like EEM_Base::get_all's $query_params[0] (where conditions)
2873 2873
 	 */
2874
-	protected function _get_minimum_where_conditions($model_relation_path = null){
2875
-		if ( $this->_ignore_where_strategy )
2874
+	protected function _get_minimum_where_conditions($model_relation_path = null) {
2875
+		if ($this->_ignore_where_strategy)
2876 2876
 			return array();
2877 2877
 
2878 2878
 		return $this->_minimum_where_conditions_strategy->get_default_where_conditions($model_relation_path);
@@ -2883,13 +2883,13 @@  discard block
 block discarded – undo
2883 2883
 	 * @param EE_Model_Query_Info_Carrier $model_query_info
2884 2884
 	 * @return string
2885 2885
 	 */
2886
-	private function _construct_default_select_sql(EE_Model_Query_Info_Carrier $model_query_info){
2886
+	private function _construct_default_select_sql(EE_Model_Query_Info_Carrier $model_query_info) {
2887 2887
 		$selects = $this->_get_columns_to_select_for_this_model();
2888
-		foreach($model_query_info->get_model_names_included() as $model_relation_chain => $name_of_other_model_included){
2888
+		foreach ($model_query_info->get_model_names_included() as $model_relation_chain => $name_of_other_model_included) {
2889 2889
 			$other_model_included = $this->get_related_model_obj($name_of_other_model_included);
2890 2890
 			$selects = array_merge($selects, $other_model_included->_get_columns_to_select_for_this_model($model_relation_chain));
2891 2891
 		}
2892
-		return implode(", ",$selects);
2892
+		return implode(", ", $selects);
2893 2893
 	}
2894 2894
 
2895 2895
 	/**
@@ -2898,19 +2898,19 @@  discard block
 block discarded – undo
2898 2898
 	 * @param string $model_relation_chain like 'Question.Question_Group.Event'
2899 2899
 	 * @return array numerically indexed, values are columns to select and rename, eg "Event.ID AS 'Event.ID'"
2900 2900
 	 */
2901
-	public function _get_columns_to_select_for_this_model($model_relation_chain = ''){
2901
+	public function _get_columns_to_select_for_this_model($model_relation_chain = '') {
2902 2902
 		$fields = $this->field_settings();
2903 2903
 		$selects = array();
2904 2904
 		$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());
2905
-		foreach($fields as $field_obj){
2906
-			$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()."'";
2905
+		foreach ($fields as $field_obj) {
2906
+			$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()."'";
2907 2907
 		}
2908 2908
 		//make sure we are also getting the PKs of each table
2909 2909
 		$tables = $this->get_tables();
2910
-		if(count($tables) > 1){
2911
-			foreach($tables as $table_obj){
2912
-				$qualified_pk_column = $table_alias_with_model_relation_chain_prefix . $table_obj->get_fully_qualified_pk_column();
2913
-				if( ! in_array($qualified_pk_column,$selects)){
2910
+		if (count($tables) > 1) {
2911
+			foreach ($tables as $table_obj) {
2912
+				$qualified_pk_column = $table_alias_with_model_relation_chain_prefix.$table_obj->get_fully_qualified_pk_column();
2913
+				if ( ! in_array($qualified_pk_column, $selects)) {
2914 2914
 					$selects[] = "$qualified_pk_column AS '$qualified_pk_column'";
2915 2915
 				}
2916 2916
 			}
@@ -2934,66 +2934,66 @@  discard block
 block discarded – undo
2934 2934
 	 * @throws EE_Error
2935 2935
 	 * @return void only modifies the EEM_Related_Model_Info_Carrier passed into it
2936 2936
 	 */
2937
-	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 ){
2938
-		if($original_query_param == NULL){
2937
+	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) {
2938
+		if ($original_query_param == NULL) {
2939 2939
 			$original_query_param = $query_param;
2940 2940
 		}
2941 2941
 		$query_param = $this->_remove_stars_and_anything_after_from_condition_query_param_key($query_param);
2942 2942
 		/** @var $allow_logic_query_params bool whether or not to allow logic_query_params like 'NOT','OR', or 'AND' */
2943
-		$allow_logic_query_params = in_array($query_param_type,array('where','having'));
2944
-		$allow_fields = in_array($query_param_type,array('where','having','order_by','group_by','order'));
2943
+		$allow_logic_query_params = in_array($query_param_type, array('where', 'having'));
2944
+		$allow_fields = in_array($query_param_type, array('where', 'having', 'order_by', 'group_by', 'order'));
2945 2945
 		//check to see if we have a field on this model
2946 2946
 		$this_model_fields = $this->field_settings(true);
2947
-		if(array_key_exists($query_param,$this_model_fields)){
2948
-			if($allow_fields){
2947
+		if (array_key_exists($query_param, $this_model_fields)) {
2948
+			if ($allow_fields) {
2949 2949
 				return;
2950
-			}else{
2950
+			} else {
2951 2951
 				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"),
2952
-						$query_param,get_class($this),$query_param_type,$original_query_param));
2952
+						$query_param, get_class($this), $query_param_type, $original_query_param));
2953 2953
 			}
2954 2954
 		}
2955 2955
 		//check if this is a special logic query param
2956
-		elseif(in_array($query_param, $this->_logic_query_param_keys, TRUE)){
2957
-			if($allow_logic_query_params){
2956
+		elseif (in_array($query_param, $this->_logic_query_param_keys, TRUE)) {
2957
+			if ($allow_logic_query_params) {
2958 2958
 				return;
2959
-			}else{
2959
+			} else {
2960 2960
 				throw new EE_Error(
2961 2961
 					sprintf(
2962
-						__( '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' ),
2963
-						implode( '", "', $this->_logic_query_param_keys ),
2964
-						$query_param ,
2965
-						get_class( $this ),
2962
+						__('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'),
2963
+						implode('", "', $this->_logic_query_param_keys),
2964
+						$query_param,
2965
+						get_class($this),
2966 2966
 						'<br />',
2967
-						"\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
2967
+						"\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
2968 2968
 					)
2969 2969
 				);
2970 2970
 			}
2971 2971
 		}
2972 2972
 
2973 2973
 		//check if it's a custom selection
2974
-		elseif(array_key_exists($query_param,$this->_custom_selections)){
2974
+		elseif (array_key_exists($query_param, $this->_custom_selections)) {
2975 2975
 			return;
2976 2976
 		}
2977 2977
 
2978 2978
 		//check if has a model name at the beginning
2979 2979
 		//and
2980 2980
 		//check if it's a field on a related model
2981
-		foreach($this->_model_relations as $valid_related_model_name=>$relation_obj){
2982
-			if(strpos($query_param, $valid_related_model_name.".") === 0){
2983
-				$this->_add_join_to_model($valid_related_model_name, $passed_in_query_info,$original_query_param);
2981
+		foreach ($this->_model_relations as $valid_related_model_name=>$relation_obj) {
2982
+			if (strpos($query_param, $valid_related_model_name.".") === 0) {
2983
+				$this->_add_join_to_model($valid_related_model_name, $passed_in_query_info, $original_query_param);
2984 2984
 				$query_param = substr($query_param, strlen($valid_related_model_name."."));
2985
-				if($query_param == ''){
2985
+				if ($query_param == '') {
2986 2986
 					//nothing left to $query_param
2987 2987
 					//we should actually end in a field name, not a model like this!
2988 2988
 					throw new EE_Error(sprintf(__("Query param '%s' (of type %s on model %s) shouldn't end on a period (.) ", "event_espresso"),
2989
-					$query_param,$query_param_type,get_class($this),$valid_related_model_name));
2990
-				}else{
2989
+					$query_param, $query_param_type, get_class($this), $valid_related_model_name));
2990
+				} else {
2991 2991
 					$related_model_obj = $this->get_related_model_obj($valid_related_model_name);
2992 2992
 					$related_model_obj->_extract_related_model_info_from_query_param($query_param, $passed_in_query_info, $query_param_type, $original_query_param);
2993 2993
 					return;
2994 2994
 				}
2995
-			}elseif($query_param == $valid_related_model_name){
2996
-				$this->_add_join_to_model($valid_related_model_name, $passed_in_query_info,$original_query_param);
2995
+			}elseif ($query_param == $valid_related_model_name) {
2996
+				$this->_add_join_to_model($valid_related_model_name, $passed_in_query_info, $original_query_param);
2997 2997
 				return;
2998 2998
 			}
2999 2999
 		}
@@ -3003,7 +3003,7 @@  discard block
 block discarded – undo
3003 3003
 		//and we previously confirmed it wasn't a logic query param or field on the current model
3004 3004
 		//it's wack, that's what it is
3005 3005
 		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"),
3006
-				$query_param,get_class($this),$query_param_type,$original_query_param));
3006
+				$query_param, get_class($this), $query_param_type, $original_query_param));
3007 3007
 
3008 3008
 	}
3009 3009
 
@@ -3020,26 +3020,26 @@  discard block
 block discarded – undo
3020 3020
 	 * 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)
3021 3021
 	 * @return void
3022 3022
 	 */
3023
-	private function _add_join_to_model($model_name, EE_Model_Query_Info_Carrier $passed_in_query_info,$original_query_param){
3023
+	private function _add_join_to_model($model_name, EE_Model_Query_Info_Carrier $passed_in_query_info, $original_query_param) {
3024 3024
 		$relation_obj = $this->related_settings_for($model_name);
3025 3025
 
3026 3026
 		$model_relation_chain = EE_Model_Parser::extract_model_relation_chain($model_name, $original_query_param);
3027 3027
 		//check if the relation is HABTM, because then we're essentially doing two joins
3028 3028
 		//If so, join first to the JOIN table, and add its data types, and then continue as normal
3029
-		if($relation_obj instanceof EE_HABTM_Relation){
3029
+		if ($relation_obj instanceof EE_HABTM_Relation) {
3030 3030
 			$join_model_obj = $relation_obj->get_join_model();
3031 3031
 			//replace the model specified with the join model for this relation chain, whi
3032 3032
 			$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);
3033 3033
 			$new_query_info = new EE_Model_Query_Info_Carrier(
3034 3034
 					array($relation_chain_to_join_model => $join_model_obj->get_this_model_name()),
3035 3035
 					$relation_obj->get_join_to_intermediate_model_statement($relation_chain_to_join_model));
3036
-			$passed_in_query_info->merge( $new_query_info  );
3036
+			$passed_in_query_info->merge($new_query_info);
3037 3037
 		}
3038 3038
 		//now just join to the other table pointed to by the relation object, and add its data types
3039 3039
 		$new_query_info = new EE_Model_Query_Info_Carrier(
3040 3040
 				array($model_relation_chain=>$model_name),
3041 3041
 				$relation_obj->get_join_statement($model_relation_chain));
3042
-		$passed_in_query_info->merge( $new_query_info  );
3042
+		$passed_in_query_info->merge($new_query_info);
3043 3043
 	}
3044 3044
 
3045 3045
 
@@ -3048,11 +3048,11 @@  discard block
 block discarded – undo
3048 3048
 	 * @param array $where_params like EEM_Base::get_all
3049 3049
 	 * @return string of SQL
3050 3050
 	 */
3051
-	private function _construct_where_clause($where_params){
3051
+	private function _construct_where_clause($where_params) {
3052 3052
 		$SQL = $this->_construct_condition_clause_recursive($where_params, ' AND ');
3053
-		if($SQL){
3054
-			return " WHERE ". $SQL;
3055
-		}else{
3053
+		if ($SQL) {
3054
+			return " WHERE ".$SQL;
3055
+		} else {
3056 3056
 			return '';
3057 3057
 		}
3058 3058
 	}
@@ -3063,11 +3063,11 @@  discard block
 block discarded – undo
3063 3063
 	 * @param array $having_params
3064 3064
 	 * @return string
3065 3065
 	 */
3066
-	private function _construct_having_clause($having_params){
3066
+	private function _construct_having_clause($having_params) {
3067 3067
 		$SQL = $this->_construct_condition_clause_recursive($having_params, ' AND ');
3068
-		if($SQL){
3069
-			return " HAVING ". $SQL;
3070
-		}else{
3068
+		if ($SQL) {
3069
+			return " HAVING ".$SQL;
3070
+		} else {
3071 3071
 			return '';
3072 3072
 		}
3073 3073
 
@@ -3081,17 +3081,17 @@  discard block
 block discarded – undo
3081 3081
 	 * @return EE_Model_Field_Base
3082 3082
 	 * @throws EE_Error
3083 3083
 	 */
3084
-	protected function _get_field_on_model($field_name,$model_name){
3084
+	protected function _get_field_on_model($field_name, $model_name) {
3085 3085
 		$model_class = 'EEM_'.$model_name;
3086 3086
 		$model_filepath = $model_class.".model.php";
3087
-		EE_Registry::instance()->load_helper( 'File' );
3088
-		if ( is_readable($model_filepath)){
3087
+		EE_Registry::instance()->load_helper('File');
3088
+		if (is_readable($model_filepath)) {
3089 3089
 			require_once($model_filepath);
3090
-			$model_instance=call_user_func($model_name."::instance");
3090
+			$model_instance = call_user_func($model_name."::instance");
3091 3091
 			/* @var $model_instance EEM_Base */
3092 3092
 			return $model_instance->field_settings_for($field_name);
3093
-		}else{
3094
-			throw new EE_Error(sprintf(__('No model named %s exists, with classname %s and filepath %s','event_espresso'),$model_name,$model_class,$model_filepath));
3093
+		} else {
3094
+			throw new EE_Error(sprintf(__('No model named %s exists, with classname %s and filepath %s', 'event_espresso'), $model_name, $model_class, $model_filepath));
3095 3095
 		}
3096 3096
 	}
3097 3097
 
@@ -3104,43 +3104,43 @@  discard block
 block discarded – undo
3104 3104
 	 * @throws EE_Error
3105 3105
 	 * @return string of SQL
3106 3106
 	 */
3107
-	private function _construct_condition_clause_recursive($where_params, $glue = ' AND'){
3108
-		$where_clauses=array();
3109
-		foreach($where_params as $query_param => $op_and_value_or_sub_condition){
3110
-			$query_param = $this->_remove_stars_and_anything_after_from_condition_query_param_key($query_param);//str_replace("*",'',$query_param);
3111
-			if(in_array($query_param,$this->_logic_query_param_keys)){
3112
-				switch($query_param){
3107
+	private function _construct_condition_clause_recursive($where_params, $glue = ' AND') {
3108
+		$where_clauses = array();
3109
+		foreach ($where_params as $query_param => $op_and_value_or_sub_condition) {
3110
+			$query_param = $this->_remove_stars_and_anything_after_from_condition_query_param_key($query_param); //str_replace("*",'',$query_param);
3111
+			if (in_array($query_param, $this->_logic_query_param_keys)) {
3112
+				switch ($query_param) {
3113 3113
 					case 'not':
3114 3114
 					case 'NOT':
3115
-						$where_clauses[] = "! (". $this->_construct_condition_clause_recursive($op_and_value_or_sub_condition, $glue).")";
3115
+						$where_clauses[] = "! (".$this->_construct_condition_clause_recursive($op_and_value_or_sub_condition, $glue).")";
3116 3116
 						break;
3117 3117
 					case 'and':
3118 3118
 					case 'AND':
3119
-						$where_clauses[] = " (". $this->_construct_condition_clause_recursive($op_and_value_or_sub_condition, ' AND ') .")";
3119
+						$where_clauses[] = " (".$this->_construct_condition_clause_recursive($op_and_value_or_sub_condition, ' AND ').")";
3120 3120
 						break;
3121 3121
 					case 'or':
3122 3122
 					case 'OR':
3123
-						$where_clauses[] = " (". $this->_construct_condition_clause_recursive($op_and_value_or_sub_condition, ' OR ') .")";
3123
+						$where_clauses[] = " (".$this->_construct_condition_clause_recursive($op_and_value_or_sub_condition, ' OR ').")";
3124 3124
 						break;
3125 3125
 				}
3126
-			}else{
3126
+			} else {
3127 3127
 				$field_obj = $this->_deduce_field_from_query_param($query_param);
3128 3128
 
3129 3129
 				//if it's not a normal field, maybe it's a custom selection?
3130
-				if( ! $field_obj){
3131
-					if(isset( $this->_custom_selections[$query_param][1])){
3130
+				if ( ! $field_obj) {
3131
+					if (isset($this->_custom_selections[$query_param][1])) {
3132 3132
 						$field_obj = $this->_custom_selections[$query_param][1];
3133
-					}else{
3134
-						throw new EE_Error(sprintf(__("%s is neither a valid model field name, nor a custom selection", "event_espresso"),$query_param));
3133
+					} else {
3134
+						throw new EE_Error(sprintf(__("%s is neither a valid model field name, nor a custom selection", "event_espresso"), $query_param));
3135 3135
 					}
3136 3136
 				}
3137 3137
 				$op_and_value_sql = $this->_construct_op_and_value($op_and_value_or_sub_condition, $field_obj);
3138
-				$where_clauses[]=$this->_deduce_column_name_from_query_param($query_param).SP.$op_and_value_sql;
3138
+				$where_clauses[] = $this->_deduce_column_name_from_query_param($query_param).SP.$op_and_value_sql;
3139 3139
 			}
3140 3140
 		}
3141
-		if($where_clauses){
3142
-			$SQL = implode($glue,$where_clauses);
3143
-		}else{
3141
+		if ($where_clauses) {
3142
+			$SQL = implode($glue, $where_clauses);
3143
+		} else {
3144 3144
 			$SQL = '';
3145 3145
 		}
3146 3146
 		return $SQL;
@@ -3154,18 +3154,18 @@  discard block
 block discarded – undo
3154 3154
 	 * @throws EE_Error
3155 3155
 	 * @return string table alias and column name for SQL, eg "Transaction.TXN_ID"
3156 3156
 	 */
3157
-	private function _deduce_column_name_from_query_param($query_param){
3157
+	private function _deduce_column_name_from_query_param($query_param) {
3158 3158
 		$field = $this->_deduce_field_from_query_param($query_param);
3159 3159
 
3160
-		if( $field ){
3161
-			$table_alias_prefix = EE_Model_Parser::extract_table_alias_model_relation_chain_from_query_param( $field->get_model_name(), $query_param );
3162
-			return $table_alias_prefix . $field->get_qualified_column();
3163
-		}elseif(array_key_exists($query_param,$this->_custom_selections)){
3160
+		if ($field) {
3161
+			$table_alias_prefix = EE_Model_Parser::extract_table_alias_model_relation_chain_from_query_param($field->get_model_name(), $query_param);
3162
+			return $table_alias_prefix.$field->get_qualified_column();
3163
+		}elseif (array_key_exists($query_param, $this->_custom_selections)) {
3164 3164
 			//maybe it's custom selection item?
3165 3165
 			//if so, just use it as the "column name"
3166 3166
 			return $query_param;
3167
-		}else{
3168
-			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)));
3167
+		} else {
3168
+			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)));
3169 3169
 		}
3170 3170
 	}
3171 3171
 
@@ -3177,11 +3177,11 @@  discard block
 block discarded – undo
3177 3177
 	 * @param string $condition_query_param_key
3178 3178
 	 * @return string
3179 3179
 	 */
3180
-	private function _remove_stars_and_anything_after_from_condition_query_param_key($condition_query_param_key){
3180
+	private function _remove_stars_and_anything_after_from_condition_query_param_key($condition_query_param_key) {
3181 3181
 		$pos_of_star = strpos($condition_query_param_key, '*');
3182
-		if($pos_of_star === FALSE){
3182
+		if ($pos_of_star === FALSE) {
3183 3183
 			return $condition_query_param_key;
3184
-		}else{
3184
+		} else {
3185 3185
 			$condition_query_param_sans_star = substr($condition_query_param_key, 0, $pos_of_star);
3186 3186
 			return $condition_query_param_sans_star;
3187 3187
 		}
@@ -3196,54 +3196,54 @@  discard block
 block discarded – undo
3196 3196
 	 * @throws EE_Error
3197 3197
 	 * @return string
3198 3198
 	 */
3199
-	private function _construct_op_and_value($op_and_value, $field_obj){
3200
-		if(is_array( $op_and_value )){
3199
+	private function _construct_op_and_value($op_and_value, $field_obj) {
3200
+		if (is_array($op_and_value)) {
3201 3201
 			$operator = isset($op_and_value[0]) ? $this->_prepare_operator_for_sql($op_and_value[0]) : null;
3202
-			if( ! $operator){
3202
+			if ( ! $operator) {
3203 3203
 				$php_array_like_string = array();
3204
-				foreach($op_and_value as $key => $value){
3204
+				foreach ($op_and_value as $key => $value) {
3205 3205
 					$php_array_like_string[] = "$key=>$value";
3206 3206
 				}
3207
-				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)));
3207
+				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)));
3208 3208
 			}
3209 3209
 			$value = isset($op_and_value[1]) ? $op_and_value[1] : null;
3210
-		}else{
3210
+		} else {
3211 3211
 			$operator = '=';
3212 3212
 			$value = $op_and_value;
3213 3213
 		}
3214 3214
 
3215 3215
 		//check to see if the value is actually another field
3216
-		if(is_array($op_and_value) && isset($op_and_value[2]) && $op_and_value[2] == true){
3216
+		if (is_array($op_and_value) && isset($op_and_value[2]) && $op_and_value[2] == true) {
3217 3217
 			return $operator.SP.$this->_deduce_column_name_from_query_param($value);
3218
-		}elseif(in_array($operator, $this->_in_style_operators) && is_array($value)){
3218
+		}elseif (in_array($operator, $this->_in_style_operators) && is_array($value)) {
3219 3219
 			//in this case, the value should be an array, or at least a comma-separated list
3220 3220
 			//it will need to handle a little differently
3221 3221
 			$cleaned_value = $this->_construct_in_value($value, $field_obj);
3222 3222
 			//note: $cleaned_value has already been run through $wpdb->prepare()
3223 3223
 			return $operator.SP.$cleaned_value;
3224
-		} elseif( in_array( $operator, $this->_between_style_operators ) && is_array( $value ) ) {
3224
+		} elseif (in_array($operator, $this->_between_style_operators) && is_array($value)) {
3225 3225
 			//the value should be an array with count of two.
3226
-			if ( count($value) !== 2 )
3227
-				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" ) );
3228
-			$cleaned_value = $this->_construct_between_value( $value, $field_obj );
3226
+			if (count($value) !== 2)
3227
+				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"));
3228
+			$cleaned_value = $this->_construct_between_value($value, $field_obj);
3229 3229
 			return $operator.SP.$cleaned_value;
3230
-		} elseif( in_array( $operator, $this->_null_style_operators ) ) {
3231
-			if($value != NULL){
3232
-				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));
3230
+		} elseif (in_array($operator, $this->_null_style_operators)) {
3231
+			if ($value != NULL) {
3232
+				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));
3233 3233
 			}
3234 3234
 			return $operator;
3235
-		}elseif( $operator == 'LIKE' && ! is_array($value)){
3235
+		}elseif ($operator == 'LIKE' && ! is_array($value)) {
3236 3236
 			//if the operator is 'LIKE', we want to allow percent signs (%) and not
3237 3237
 			//remove other junk. So just treat it as a string.
3238 3238
 			return $operator.SP.$this->_wpdb_prepare_using_field($value, '%s');
3239
-		}elseif( ! in_array($operator, $this->_in_style_operators) && ! is_array($value)){
3240
-			return $operator.SP.$this->_wpdb_prepare_using_field($value,$field_obj);
3241
-		}elseif(in_array($operator, $this->_in_style_operators) && ! is_array($value)){
3242
-			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));
3243
-		}elseif( ! in_array($operator, $this->_in_style_operators) && is_array($value)){
3244
-			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));
3245
-		}else{
3246
-			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)));
3239
+		}elseif ( ! in_array($operator, $this->_in_style_operators) && ! is_array($value)) {
3240
+			return $operator.SP.$this->_wpdb_prepare_using_field($value, $field_obj);
3241
+		}elseif (in_array($operator, $this->_in_style_operators) && ! is_array($value)) {
3242
+			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));
3243
+		}elseif ( ! in_array($operator, $this->_in_style_operators) && is_array($value)) {
3244
+			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));
3245
+		} else {
3246
+			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)));
3247 3247
 		}
3248 3248
 	}
3249 3249
 
@@ -3255,12 +3255,12 @@  discard block
 block discarded – undo
3255 3255
 	 * @param EE_Model_Field_Base|string $field_obj if string, it should be the datatype to be used when querying, eg '%s'
3256 3256
 	 * @return string
3257 3257
 	 */
3258
-	function _construct_between_value( $values, $field_obj ) {
3258
+	function _construct_between_value($values, $field_obj) {
3259 3259
 		$cleaned_values = array();
3260
-		foreach ( $values as $value ) {
3261
-			$cleaned_values[] = $this->_wpdb_prepare_using_field($value,$field_obj);
3260
+		foreach ($values as $value) {
3261
+			$cleaned_values[] = $this->_wpdb_prepare_using_field($value, $field_obj);
3262 3262
 		}
3263
-		return  $cleaned_values[0] . " AND " . $cleaned_values[1];
3263
+		return  $cleaned_values[0]." AND ".$cleaned_values[1];
3264 3264
 	}
3265 3265
 
3266 3266
 
@@ -3276,26 +3276,26 @@  discard block
 block discarded – undo
3276 3276
 	 * @param EE_Model_Field_Base|string $field_obj if string, it should be a wpdb data type like '%s', or '%d'
3277 3277
 	 * @return string of SQL to follow an 'IN' or 'NOT IN' operator
3278 3278
 	 */
3279
-	function _construct_in_value($values,  $field_obj){
3279
+	function _construct_in_value($values, $field_obj) {
3280 3280
 		//check if the value is a CSV list
3281
-		if(is_string($values)){
3281
+		if (is_string($values)) {
3282 3282
 			//in which case, turn it into an array
3283
-			$values = explode(",",$values);
3283
+			$values = explode(",", $values);
3284 3284
 		}
3285 3285
 		$cleaned_values = array();
3286
-		foreach($values as $value){
3287
-			$cleaned_values[] = $this->_wpdb_prepare_using_field($value,$field_obj);
3286
+		foreach ($values as $value) {
3287
+			$cleaned_values[] = $this->_wpdb_prepare_using_field($value, $field_obj);
3288 3288
 		}
3289 3289
 		//we would just LOVE to leave $cleaned_values as an empty array, and return the value as "()",
3290 3290
 		//but unfortunately that's invalid SQL. So instead we return a string which we KNOW will evaluate to be the empty set
3291 3291
 		//which is effectively equivalent to returning "()". We don't return "(0)" because that only works for auto-incrementing columns
3292
-		if(empty($cleaned_values)){
3292
+		if (empty($cleaned_values)) {
3293 3293
 			$all_fields = $this->field_settings();
3294 3294
 			$a_field = array_shift($all_fields);
3295 3295
 			$main_table = $this->_get_main_table();
3296 3296
 			$cleaned_values[] = "SELECT ".$a_field->get_table_column()." FROM ".$main_table->get_table_name()." WHERE FALSE";
3297 3297
 		}
3298
-		return "(".implode(",",$cleaned_values).")";
3298
+		return "(".implode(",", $cleaned_values).")";
3299 3299
 	}
3300 3300
 
3301 3301
 
@@ -3307,16 +3307,16 @@  discard block
 block discarded – undo
3307 3307
 	 * @throws EE_Error
3308 3308
 	 * @return false|null|string
3309 3309
 	 */
3310
-	private function _wpdb_prepare_using_field($value,$field_obj){
3310
+	private function _wpdb_prepare_using_field($value, $field_obj) {
3311 3311
 		/** @type WPDB $wpdb */
3312 3312
 		global $wpdb;
3313
-		if($field_obj instanceof EE_Model_Field_Base){
3314
-			return $wpdb->prepare($field_obj->get_wpdb_data_type(),$this->_prepare_value_for_use_in_db($value, $field_obj));
3315
-		}else{//$field_obj should really just be a data type
3316
-			if( ! in_array($field_obj,$this->_valid_wpdb_data_types)){
3317
-				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)));
3313
+		if ($field_obj instanceof EE_Model_Field_Base) {
3314
+			return $wpdb->prepare($field_obj->get_wpdb_data_type(), $this->_prepare_value_for_use_in_db($value, $field_obj));
3315
+		} else {//$field_obj should really just be a data type
3316
+			if ( ! in_array($field_obj, $this->_valid_wpdb_data_types)) {
3317
+				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)));
3318 3318
 			}
3319
-			return $wpdb->prepare($field_obj,$value);
3319
+			return $wpdb->prepare($field_obj, $value);
3320 3320
 		}
3321 3321
 	}
3322 3322
 
@@ -3328,27 +3328,27 @@  discard block
 block discarded – undo
3328 3328
 	 * @throws EE_Error
3329 3329
 	 * @return EE_Model_Field_Base
3330 3330
 	 */
3331
-	protected function _deduce_field_from_query_param($query_param_name){
3331
+	protected function _deduce_field_from_query_param($query_param_name) {
3332 3332
 		//ok, now proceed with deducing which part is the model's name, and which is the field's name
3333 3333
 		//which will help us find the database table and column
3334 3334
 
3335
-		$query_param_parts = explode(".",$query_param_name);
3336
-		if(empty($query_param_parts)){
3337
-			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));
3335
+		$query_param_parts = explode(".", $query_param_name);
3336
+		if (empty($query_param_parts)) {
3337
+			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));
3338 3338
 		}
3339 3339
 		$number_of_parts = count($query_param_parts);
3340
-		$last_query_param_part = $query_param_parts[ count($query_param_parts) - 1 ];
3341
-		if($number_of_parts == 1){
3340
+		$last_query_param_part = $query_param_parts[count($query_param_parts) - 1];
3341
+		if ($number_of_parts == 1) {
3342 3342
 			$field_name = $last_query_param_part;
3343 3343
 			$model_obj = $this;
3344
-		}else{// $number_of_parts >= 2
3344
+		} else {// $number_of_parts >= 2
3345 3345
 			//the last part is the column name, and there are only 2parts. therefore...
3346 3346
 			$field_name = $last_query_param_part;
3347
-			$model_obj = $this->get_related_model_obj( $query_param_parts[ $number_of_parts - 2 ]);
3347
+			$model_obj = $this->get_related_model_obj($query_param_parts[$number_of_parts - 2]);
3348 3348
 		}
3349
-		try{
3349
+		try {
3350 3350
 			return $model_obj->field_settings_for($field_name);
3351
-		}catch(EE_Error $e){
3351
+		} catch (EE_Error $e) {
3352 3352
 			return null;
3353 3353
 		}
3354 3354
 	}
@@ -3362,13 +3362,13 @@  discard block
 block discarded – undo
3362 3362
 	 * @throws EE_Error
3363 3363
 	 * @return string
3364 3364
 	 */
3365
-	function _get_qualified_column_for_field($field_name){
3365
+	function _get_qualified_column_for_field($field_name) {
3366 3366
 		$all_fields = $this->field_settings();
3367 3367
 		$field = isset($all_fields[$field_name]) ? $all_fields[$field_name] : FALSE;
3368
-		if($field){
3368
+		if ($field) {
3369 3369
 			return $field->get_qualified_column();
3370
-		}else{
3371
-			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)));
3370
+		} else {
3371
+			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)));
3372 3372
 		}
3373 3373
 	}
3374 3374
 
@@ -3382,14 +3382,14 @@  discard block
 block discarded – undo
3382 3382
 	 * @param  mixed|string $limit The limit for this select
3383 3383
 	 * @return string 				The final select join element for the query.
3384 3384
 	 */
3385
-	function _construct_limit_join_select( $table_alias, $limit ) {
3385
+	function _construct_limit_join_select($table_alias, $limit) {
3386 3386
 		$SQL = '';
3387 3387
 
3388
-		foreach ( $this->_tables as $table_obj ) {
3389
-			if ( $table_obj instanceof EE_Primary_Table ) {
3390
-				$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;
3391
-			} elseif ( $table_obj instanceof EE_Secondary_Table ) {
3392
-				$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;
3388
+		foreach ($this->_tables as $table_obj) {
3389
+			if ($table_obj instanceof EE_Primary_Table) {
3390
+				$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;
3391
+			} elseif ($table_obj instanceof EE_Secondary_Table) {
3392
+				$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;
3393 3393
 			}
3394 3394
 		}
3395 3395
 		return $SQL;
@@ -3402,7 +3402,7 @@  discard block
 block discarded – undo
3402 3402
 	 * Eg "wp_post AS Event" or "wp_post AS Event INNER JOIN wp_postmeta Event_Meta ON Event.ID = Event_Meta.post_id"
3403 3403
 	 * @return string SQL
3404 3404
 	 */
3405
-	function _construct_internal_join(){
3405
+	function _construct_internal_join() {
3406 3406
 		$SQL = $this->_get_main_table()->get_table_sql();
3407 3407
 		$SQL .= $this->_construct_internal_join_to_table_with_alias($this->_get_main_table()->get_table_alias());
3408 3408
 		return $SQL;
@@ -3423,17 +3423,17 @@  discard block
 block discarded – undo
3423 3423
 	 * @param string $alias_prefixed table alias to join to (this table should already be in the FROM SQL clause)
3424 3424
 	 * @return string
3425 3425
 	 */
3426
-	function _construct_internal_join_to_table_with_alias($alias_prefixed){
3426
+	function _construct_internal_join_to_table_with_alias($alias_prefixed) {
3427 3427
 		$SQL = '';
3428 3428
 		$alias_sans_prefix = EE_Model_Parser::remove_table_alias_model_relation_chain_prefix($alias_prefixed);
3429
-		foreach($this->_tables as $table_obj){
3430
-			if($table_obj instanceof EE_Secondary_Table){//table is secondary table
3431
-				if($alias_sans_prefix == $table_obj->get_table_alias()){
3429
+		foreach ($this->_tables as $table_obj) {
3430
+			if ($table_obj instanceof EE_Secondary_Table) {//table is secondary table
3431
+				if ($alias_sans_prefix == $table_obj->get_table_alias()) {
3432 3432
 					//so we're joining to this table, meaning the table is already in
3433 3433
 					//the FROM statement, BUT the primary table isn't. So we want
3434 3434
 					//to add the inverse join sql
3435 3435
 					$SQL .= $table_obj->get_inverse_join_sql($alias_prefixed);
3436
-				}else{
3436
+				} else {
3437 3437
 					//just add a regular JOIN to this table from the primary table
3438 3438
 					$SQL .= $table_obj->get_join_sql($alias_prefixed);
3439 3439
 				}
@@ -3447,9 +3447,9 @@  discard block
 block discarded – undo
3447 3447
 	 * 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)
3448 3448
 	 * @return array
3449 3449
 	 */
3450
-	function _get_data_types(){
3450
+	function _get_data_types() {
3451 3451
 		$data_types = array();
3452
-		foreach(array_values($this->field_settings()) as $field_obj){
3452
+		foreach (array_values($this->field_settings()) as $field_obj) {
3453 3453
 			//$data_types[$field_obj->get_table_column()] = $field_obj->get_wpdb_data_type();
3454 3454
 			/** @var $field_obj EE_Model_Field_Base */
3455 3455
 			$data_types[$field_obj->get_qualified_column()] = $field_obj->get_wpdb_data_type();
@@ -3465,11 +3465,11 @@  discard block
 block discarded – undo
3465 3465
 	 * @throws EE_Error
3466 3466
 	 * @return EEM_Base
3467 3467
 	 */
3468
-	function get_related_model_obj($model_name){
3468
+	function get_related_model_obj($model_name) {
3469 3469
 
3470 3470
 		$model_classname = "EEM_".$model_name;
3471
-		if(!class_exists($model_classname)){
3472
-			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));
3471
+		if ( ! class_exists($model_classname)) {
3472
+			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));
3473 3473
 		}
3474 3474
 		$model_obj = call_user_func($model_classname."::instance");
3475 3475
 		return $model_obj;
@@ -3480,7 +3480,7 @@  discard block
 block discarded – undo
3480 3480
 	 * Returns the array of EE_ModelRelations for this model.
3481 3481
 	 * @return EE_Model_Relation_Base[]
3482 3482
 	 */
3483
-	public function relation_settings(){
3483
+	public function relation_settings() {
3484 3484
 		return $this->_model_relations;
3485 3485
 	}
3486 3486
 
@@ -3490,10 +3490,10 @@  discard block
 block discarded – undo
3490 3490
 	 * (Eg, without an event, datetimes have little purpose.)
3491 3491
 	 * @return EE_Belongs_To_Relation[]
3492 3492
 	 */
3493
-	public function belongs_to_relations(){
3493
+	public function belongs_to_relations() {
3494 3494
 		$belongs_to_relations = array();
3495
-		foreach($this->relation_settings() as $model_name => $relation_obj){
3496
-			if($relation_obj instanceof EE_Belongs_To_Relation){
3495
+		foreach ($this->relation_settings() as $model_name => $relation_obj) {
3496
+			if ($relation_obj instanceof EE_Belongs_To_Relation) {
3497 3497
 				$belongs_to_relations[$model_name] = $relation_obj;
3498 3498
 			}
3499 3499
 		}
@@ -3508,15 +3508,15 @@  discard block
 block discarded – undo
3508 3508
 	 * @throws EE_Error
3509 3509
 	 * @return EE_Model_Relation_Base
3510 3510
 	 */
3511
-	public function related_settings_for($relation_name){
3512
-		$relatedModels=$this->relation_settings();
3513
-		if(!array_key_exists($relation_name,$relatedModels)){
3511
+	public function related_settings_for($relation_name) {
3512
+		$relatedModels = $this->relation_settings();
3513
+		if ( ! array_key_exists($relation_name, $relatedModels)) {
3514 3514
 			throw new EE_Error(
3515 3515
 				sprintf(
3516
-					__('Cannot get %s related to %s. There is no model relation of that type. There is, however, %s...','event_espresso'),
3516
+					__('Cannot get %s related to %s. There is no model relation of that type. There is, however, %s...', 'event_espresso'),
3517 3517
 					$relation_name,
3518 3518
 					$this->_get_class_name(),
3519
-					implode( ', ', array_keys( $relatedModels ))
3519
+					implode(', ', array_keys($relatedModels))
3520 3520
 				)
3521 3521
 			);
3522 3522
 		}
@@ -3531,10 +3531,10 @@  discard block
 block discarded – undo
3531 3531
 	 * @throws EE_Error
3532 3532
 	 * @return EE_Model_Field_Base
3533 3533
 	 */
3534
-	public function field_settings_for($fieldName){
3535
-		$fieldSettings=$this->field_settings(true);
3536
-		if( ! array_key_exists($fieldName,$fieldSettings)){
3537
-			throw new EE_Error(sprintf(__("There is no field/column '%s' on '%s'",'event_espresso'),$fieldName,get_class($this)));
3534
+	public function field_settings_for($fieldName) {
3535
+		$fieldSettings = $this->field_settings(true);
3536
+		if ( ! array_key_exists($fieldName, $fieldSettings)) {
3537
+			throw new EE_Error(sprintf(__("There is no field/column '%s' on '%s'", 'event_espresso'), $fieldName, get_class($this)));
3538 3538
 		}
3539 3539
 		return $fieldSettings[$fieldName];
3540 3540
 	}
@@ -3544,11 +3544,11 @@  discard block
 block discarded – undo
3544 3544
 	 * @param string $fieldName a key in the model's _field_settings array
3545 3545
 	 * @return boolean
3546 3546
 	 */
3547
-	public function has_field($fieldName){
3547
+	public function has_field($fieldName) {
3548 3548
 		$fieldSettings = $this->field_settings(true);
3549
-		if( isset($fieldSettings[$fieldName])){
3549
+		if (isset($fieldSettings[$fieldName])) {
3550 3550
 			return true;
3551
-		}else{
3551
+		} else {
3552 3552
 			return false;
3553 3553
 		}
3554 3554
 	}
@@ -3558,11 +3558,11 @@  discard block
 block discarded – undo
3558 3558
 	 * @param string $relation_name possibly one of the keys in the relation_settings array
3559 3559
 	 * @return boolean
3560 3560
 	 */
3561
-	public function has_relation($relation_name){
3561
+	public function has_relation($relation_name) {
3562 3562
 		$relations = $this->relation_settings();
3563
-		if(isset($relations[$relation_name])){
3563
+		if (isset($relations[$relation_name])) {
3564 3564
 			return true;
3565
-		}else{
3565
+		} else {
3566 3566
 			return false;
3567 3567
 		}
3568 3568
 	}
@@ -3574,7 +3574,7 @@  discard block
 block discarded – undo
3574 3574
 	 * @param $field_obj
3575 3575
 	 * @return EE_Model_Field_Base
3576 3576
 	 */
3577
-	public function is_primary_key_field( $field_obj ){
3577
+	public function is_primary_key_field($field_obj) {
3578 3578
 		return $field_obj instanceof EE_Primary_Key_Field_Base ? TRUE : FALSE;
3579 3579
 	}
3580 3580
 
@@ -3586,16 +3586,16 @@  discard block
 block discarded – undo
3586 3586
 	 * @return EE_Model_Field_Base
3587 3587
 	 * @throws EE_Error
3588 3588
 	 */
3589
-	public function get_primary_key_field(){
3590
-		if( $this->_primary_key_field === NULL ){
3591
-			foreach( $this->field_settings( TRUE ) as $field_obj ){
3592
-				if( $this->is_primary_key_field( $field_obj )){
3589
+	public function get_primary_key_field() {
3590
+		if ($this->_primary_key_field === NULL) {
3591
+			foreach ($this->field_settings(TRUE) as $field_obj) {
3592
+				if ($this->is_primary_key_field($field_obj)) {
3593 3593
 					$this->_primary_key_field = $field_obj;
3594 3594
 					break;
3595 3595
 				}
3596 3596
 			}
3597
-			if( ! $this->_primary_key_field instanceof EE_Primary_Key_Field_Base ){
3598
-				throw new EE_Error(sprintf(__("There is no Primary Key defined on model %s",'event_espresso'),get_class($this)));
3597
+			if ( ! $this->_primary_key_field instanceof EE_Primary_Key_Field_Base) {
3598
+				throw new EE_Error(sprintf(__("There is no Primary Key defined on model %s", 'event_espresso'), get_class($this)));
3599 3599
 			}
3600 3600
 		}
3601 3601
 		return $this->_primary_key_field;
@@ -3608,12 +3608,12 @@  discard block
 block discarded – undo
3608 3608
 	 * Internally does some caching.
3609 3609
 	 * @return boolean
3610 3610
 	 */
3611
-	public function has_primary_key_field(){
3612
-		if($this->_has_primary_key_field === null){
3613
-			try{
3611
+	public function has_primary_key_field() {
3612
+		if ($this->_has_primary_key_field === null) {
3613
+			try {
3614 3614
 				$this->get_primary_key_field();
3615 3615
 				$this->_has_primary_key_field = true;
3616
-			}catch(EE_Error $e){
3616
+			} catch (EE_Error $e) {
3617 3617
 				$this->_has_primary_key_field = false;
3618 3618
 			}
3619 3619
 		}
@@ -3627,9 +3627,9 @@  discard block
 block discarded – undo
3627 3627
 	 * @param string $field_class_name class name of field that you want to find. Eg, EE_Datetime_Field, EE_Foreign_Key_Field, etc
3628 3628
 	 * @return EE_Model_Field_Base or null if none is found
3629 3629
 	 */
3630
-	public function get_a_field_of_type($field_class_name){
3631
-		foreach($this->field_settings() as $field){
3632
-			if( $field instanceof $field_class_name ){
3630
+	public function get_a_field_of_type($field_class_name) {
3631
+		foreach ($this->field_settings() as $field) {
3632
+			if ($field instanceof $field_class_name) {
3633 3633
 				return $field;
3634 3634
 			}
3635 3635
 		}
@@ -3643,21 +3643,21 @@  discard block
 block discarded – undo
3643 3643
 	 * @return EE_Foreign_Key_Field_Base
3644 3644
 	 * @throws EE_Error
3645 3645
 	 */
3646
-	public function get_foreign_key_to($model_name){
3647
-		if( ! isset( $this->_cache_foreign_key_to_fields[ $model_name ] ) ){
3648
-			foreach($this->field_settings() as $field){
3646
+	public function get_foreign_key_to($model_name) {
3647
+		if ( ! isset($this->_cache_foreign_key_to_fields[$model_name])) {
3648
+			foreach ($this->field_settings() as $field) {
3649 3649
 //				if(is_subclass_of($field, 'EE_Foreign_Key_Field_Base')){
3650
-				if( $field instanceof EE_Foreign_Key_Field_Base ){
3651
-					if (in_array($model_name,$field->get_model_names_pointed_to() ) ) {
3652
-						$this->_cache_foreign_key_to_fields[ $model_name ] = $field;
3650
+				if ($field instanceof EE_Foreign_Key_Field_Base) {
3651
+					if (in_array($model_name, $field->get_model_names_pointed_to())) {
3652
+						$this->_cache_foreign_key_to_fields[$model_name] = $field;
3653 3653
 					}
3654 3654
 				}
3655 3655
 			}
3656
-			if( ! isset( $this->_cache_foreign_key_to_fields[ $model_name ] ) ){
3657
-				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)));
3656
+			if ( ! isset($this->_cache_foreign_key_to_fields[$model_name])) {
3657
+				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)));
3658 3658
 			}
3659 3659
 		}
3660
-		return $this->_cache_foreign_key_to_fields[ $model_name ];
3660
+		return $this->_cache_foreign_key_to_fields[$model_name];
3661 3661
 	}
3662 3662
 
3663 3663
 
@@ -3668,7 +3668,7 @@  discard block
 block discarded – undo
3668 3668
 	 * a table alias with a model chain prefix, like 'Venue__Event_Venue___Event_Meta'. Either one works
3669 3669
 	 * @return EE_Table_Base
3670 3670
 	 */
3671
-	function get_table_for_alias($table_alias){
3671
+	function get_table_for_alias($table_alias) {
3672 3672
 		$table_alias_sans_model_relation_chain_prefix = EE_Model_Parser::remove_table_alias_model_relation_chain_prefix($table_alias);
3673 3673
 		return $this->_tables[$table_alias_sans_model_relation_chain_prefix]->get_table_name();
3674 3674
 	}
@@ -3681,25 +3681,25 @@  discard block
 block discarded – undo
3681 3681
 	 * @param bool $include_db_only_fields flag indicating whether or not to include the db-only fields
3682 3682
 	 * @return EE_Model_Field_Base[] where the keys are the field's name
3683 3683
 	 */
3684
-	public function field_settings($include_db_only_fields = false){
3685
-		if( $include_db_only_fields ){
3686
-			if( $this->_cached_fields === NULL ){
3684
+	public function field_settings($include_db_only_fields = false) {
3685
+		if ($include_db_only_fields) {
3686
+			if ($this->_cached_fields === NULL) {
3687 3687
 				$this->_cached_fields = array();
3688
-				foreach($this->_fields as $fields_corresponding_to_table){
3689
-					foreach($fields_corresponding_to_table as $field_name => $field_obj){
3690
-						$this->_cached_fields[$field_name]=$field_obj;
3688
+				foreach ($this->_fields as $fields_corresponding_to_table) {
3689
+					foreach ($fields_corresponding_to_table as $field_name => $field_obj) {
3690
+						$this->_cached_fields[$field_name] = $field_obj;
3691 3691
 					}
3692 3692
 				}
3693 3693
 			}
3694 3694
 			return $this->_cached_fields;
3695
-		}else{
3696
-			if( $this->_cached_fields_non_db_only === NULL ){
3695
+		} else {
3696
+			if ($this->_cached_fields_non_db_only === NULL) {
3697 3697
 				$this->_cached_fields_non_db_only = array();
3698
-				foreach($this->_fields as $fields_corresponding_to_table){
3699
-					foreach($fields_corresponding_to_table as $field_name => $field_obj){
3698
+				foreach ($this->_fields as $fields_corresponding_to_table) {
3699
+					foreach ($fields_corresponding_to_table as $field_name => $field_obj) {
3700 3700
 						/** @var $field_obj EE_Model_Field_Base */
3701
-						if( ! $field_obj->is_db_only_field() ){
3702
-							$this->_cached_fields_non_db_only[$field_name]=$field_obj;
3701
+						if ( ! $field_obj->is_db_only_field()) {
3702
+							$this->_cached_fields_non_db_only[$field_name] = $field_obj;
3703 3703
 						}
3704 3704
 					}
3705 3705
 				}
@@ -3718,67 +3718,67 @@  discard block
 block discarded – undo
3718 3718
 	 * @return \EE_Base_Class[] array keys are primary keys (if there is a primary key on the model. if not, numerically indexed)
3719 3719
 	 * @throws \EE_Error
3720 3720
 	 */
3721
-	protected function _create_objects( $rows = array() ) {
3722
-		$array_of_objects=array();
3723
-		if(empty($rows)){
3721
+	protected function _create_objects($rows = array()) {
3722
+		$array_of_objects = array();
3723
+		if (empty($rows)) {
3724 3724
 			return array();
3725 3725
 		}
3726 3726
 		$count_if_model_has_no_primary_key = 0;
3727 3727
 		$has_primary_key = $this->has_primary_key_field();
3728
-		if( $has_primary_key ) {
3728
+		if ($has_primary_key) {
3729 3729
 			$primary_key_field = $this->get_primary_key_field();
3730 3730
 		} else {
3731 3731
 			$primary_key_field = null;
3732 3732
 		}
3733
-		foreach ( $rows as $row ) {
3734
-			if(empty($row)){
3733
+		foreach ($rows as $row) {
3734
+			if (empty($row)) {
3735 3735
 				//wp did its weird thing where it returns an array like array(0=>null), which is totally not helpful...
3736 3736
 				return array();
3737 3737
 			}
3738 3738
 			//check if we've already set this object in the results array,
3739 3739
 			//in which case there's no need to process it further (again)
3740
-			if( $has_primary_key ) {
3740
+			if ($has_primary_key) {
3741 3741
 				$table_pk_value = $this->_get_column_value_with_table_alias_or_not(
3742 3742
 					$row,
3743 3743
 					$primary_key_field->get_qualified_column(),
3744 3744
 					$primary_key_field->get_table_column()
3745 3745
 				);
3746
-				if( $table_pk_value &&
3747
-					isset( $array_of_objects[ $table_pk_value ] ) ) {
3746
+				if ($table_pk_value &&
3747
+					isset($array_of_objects[$table_pk_value])) {
3748 3748
 					continue;
3749 3749
 				}
3750 3750
 			}
3751
-			$classInstance=$this->instantiate_class_from_array_or_object($row);
3752
-			if( ! $classInstance ) {
3751
+			$classInstance = $this->instantiate_class_from_array_or_object($row);
3752
+			if ( ! $classInstance) {
3753 3753
 				throw new EE_Error(
3754 3754
 					sprintf(
3755
-						__( 'Could not create instance of class %s from row %s', 'event_espresso' ),
3755
+						__('Could not create instance of class %s from row %s', 'event_espresso'),
3756 3756
 						$this->get_this_model_name(),
3757
-						http_build_query( $row )
3757
+						http_build_query($row)
3758 3758
 					)
3759 3759
 				);
3760 3760
 			}
3761 3761
 			//set the timezone on the instantiated objects
3762
-			$classInstance->set_timezone( $this->_timezone );
3762
+			$classInstance->set_timezone($this->_timezone);
3763 3763
 			//make sure if there is any timezone setting present that we set the timezone for the object
3764 3764
 			$key = $has_primary_key ? $classInstance->ID() : $count_if_model_has_no_primary_key++;
3765
-			$array_of_objects[ $key ] = $classInstance;
3765
+			$array_of_objects[$key] = $classInstance;
3766 3766
 			//also, for all the relations of type BelongsTo, see if we can cache
3767 3767
 			//those related models
3768 3768
 			//(we could do this for other relations too, but if there are conditions
3769 3769
 			//that filtered out some fo the results, then we'd be caching an incomplete set
3770 3770
 			//so it requires a little more thought than just caching them immediately...)
3771
-			foreach($this->_model_relations as $modelName => $relation_obj){
3772
-				if( $relation_obj instanceof EE_Belongs_To_Relation){
3771
+			foreach ($this->_model_relations as $modelName => $relation_obj) {
3772
+				if ($relation_obj instanceof EE_Belongs_To_Relation) {
3773 3773
 					//check if this model's INFO is present. If so, cache it on the model
3774 3774
 					$other_model = $relation_obj->get_other_model();
3775 3775
 
3776 3776
 					$other_model_obj_maybe = $other_model->instantiate_class_from_array_or_object($row);
3777 3777
 
3778 3778
 					//if we managed to make a model object from the results, cache it on the main model object
3779
-					if( $other_model_obj_maybe ){
3779
+					if ($other_model_obj_maybe) {
3780 3780
 						//set timezone on these other model objects if they are present
3781
-						$other_model_obj_maybe->set_timezone( $this->_timezone );
3781
+						$other_model_obj_maybe->set_timezone($this->_timezone);
3782 3782
 						$classInstance->cache($modelName, $other_model_obj_maybe);
3783 3783
 					}
3784 3784
 				}
@@ -3799,12 +3799,12 @@  discard block
 block discarded – undo
3799 3799
 
3800 3800
 		$this_model_fields_and_values = array();
3801 3801
 		//setup the row using default values;
3802
-		foreach ( $this->field_settings() as $field_name => $field_obj ) {
3802
+		foreach ($this->field_settings() as $field_name => $field_obj) {
3803 3803
 			$this_model_fields_and_values[$field_name] = $field_obj->get_default_value();
3804 3804
 		}
3805 3805
 
3806 3806
 		$className = $this->_get_class_name();
3807
-		$classInstance = EE_Registry::instance()->load_class( $className, array( $this_model_fields_and_values ), FALSE, FALSE );
3807
+		$classInstance = EE_Registry::instance()->load_class($className, array($this_model_fields_and_values), FALSE, FALSE);
3808 3808
 
3809 3809
 		return $classInstance;
3810 3810
 	}
@@ -3817,45 +3817,45 @@  discard block
 block discarded – undo
3817 3817
 	 * or an stdClass where each property is the name of a column,
3818 3818
 	 * @return EE_Base_Class
3819 3819
 	 */
3820
-	public function instantiate_class_from_array_or_object($cols_n_values){
3821
-		if( ! is_array( $cols_n_values ) && is_object( $cols_n_values )) {
3822
-			$cols_n_values = get_object_vars( $cols_n_values );
3820
+	public function instantiate_class_from_array_or_object($cols_n_values) {
3821
+		if ( ! is_array($cols_n_values) && is_object($cols_n_values)) {
3822
+			$cols_n_values = get_object_vars($cols_n_values);
3823 3823
 		}
3824 3824
 		$primary_key = NULL;
3825 3825
 		//make sure the array only has keys that are fields/columns on this model
3826
-		$this_model_fields_n_values = $this->_deduce_fields_n_values_from_cols_n_values( $cols_n_values );
3827
-		if( $this->has_primary_key_field() && isset( $this_model_fields_n_values[ $this->primary_key_name() ] ) ){
3828
-			$primary_key = $this_model_fields_n_values[ $this->primary_key_name() ];
3826
+		$this_model_fields_n_values = $this->_deduce_fields_n_values_from_cols_n_values($cols_n_values);
3827
+		if ($this->has_primary_key_field() && isset($this_model_fields_n_values[$this->primary_key_name()])) {
3828
+			$primary_key = $this_model_fields_n_values[$this->primary_key_name()];
3829 3829
 		}
3830
-		$className=$this->_get_class_name();
3830
+		$className = $this->_get_class_name();
3831 3831
 
3832 3832
 		//check we actually found results that we can use to build our model object
3833 3833
 		//if not, return null
3834
-		if( $this->has_primary_key_field()){
3835
-			if(empty( $this_model_fields_n_values[$this->primary_key_name()] )){
3834
+		if ($this->has_primary_key_field()) {
3835
+			if (empty($this_model_fields_n_values[$this->primary_key_name()])) {
3836 3836
 				return NULL;
3837 3837
 			}
3838
-		}else if($this->unique_indexes()){
3838
+		} else if ($this->unique_indexes()) {
3839 3839
 			$first_column = reset($this_model_fields_n_values);
3840
-			if(empty($first_column)){
3840
+			if (empty($first_column)) {
3841 3841
 				return NULL;
3842 3842
 			}
3843 3843
 		}
3844 3844
 
3845 3845
 		// if there is no primary key or the object doesn't already exist in the entity map, then create a new instance
3846
-		if ( $primary_key){
3847
-			$classInstance = $this->get_from_entity_map( $primary_key );
3848
-			if( ! $classInstance) {
3849
-				$classInstance = EE_Registry::instance()->load_class( $className, array( $this_model_fields_n_values, $this->_timezone ), TRUE, FALSE );
3846
+		if ($primary_key) {
3847
+			$classInstance = $this->get_from_entity_map($primary_key);
3848
+			if ( ! $classInstance) {
3849
+				$classInstance = EE_Registry::instance()->load_class($className, array($this_model_fields_n_values, $this->_timezone), TRUE, FALSE);
3850 3850
 				// add this new object to the entity map
3851
-				$classInstance = $this->add_to_entity_map( $classInstance );
3851
+				$classInstance = $this->add_to_entity_map($classInstance);
3852 3852
 			}
3853
-		}else{
3854
-			$classInstance = EE_Registry::instance()->load_class( $className, array( $this_model_fields_n_values, $this->_timezone ), TRUE, FALSE );
3853
+		} else {
3854
+			$classInstance = EE_Registry::instance()->load_class($className, array($this_model_fields_n_values, $this->_timezone), TRUE, FALSE);
3855 3855
 		}
3856 3856
 
3857 3857
 			//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.
3858
-		$this->set_timezone( $classInstance->get_timezone() );
3858
+		$this->set_timezone($classInstance->get_timezone());
3859 3859
 		return $classInstance;
3860 3860
 	}
3861 3861
 	/**
@@ -3863,8 +3863,8 @@  discard block
 block discarded – undo
3863 3863
 	 * @param int|string $id the ID of the model object
3864 3864
 	 * @return EE_Base_Class
3865 3865
 	 */
3866
-	public function get_from_entity_map( $id ){
3867
-		return isset( $this->_entity_map[ $id ] ) ? $this->_entity_map[ $id ] : NULL;
3866
+	public function get_from_entity_map($id) {
3867
+		return isset($this->_entity_map[$id]) ? $this->_entity_map[$id] : NULL;
3868 3868
 	}
3869 3869
 
3870 3870
 
@@ -3883,21 +3883,21 @@  discard block
 block discarded – undo
3883 3883
 	 * @throws EE_Error
3884 3884
 	 * @return \EE_Base_Class
3885 3885
 	 */
3886
-	public function add_to_entity_map( EE_Base_Class $object) {
3886
+	public function add_to_entity_map(EE_Base_Class $object) {
3887 3887
 		$className = $this->_get_class_name();
3888
-		if( ! $object instanceof $className ){
3889
-			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 ) );
3888
+		if ( ! $object instanceof $className) {
3889
+			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));
3890 3890
 		}
3891 3891
 		/** @var $object EE_Base_Class */
3892
-		if ( ! $object->ID() ){
3893
-			throw new EE_Error(sprintf(__("You tried storing a model object with NO ID in the %s entity mapper.", "event_espresso"),get_class($this)));
3892
+		if ( ! $object->ID()) {
3893
+			throw new EE_Error(sprintf(__("You tried storing a model object with NO ID in the %s entity mapper.", "event_espresso"), get_class($this)));
3894 3894
 		}
3895 3895
 		// double check it's not already there
3896
-		$classInstance = $this->get_from_entity_map( $object->ID() );
3897
-		if ( $classInstance ) {
3896
+		$classInstance = $this->get_from_entity_map($object->ID());
3897
+		if ($classInstance) {
3898 3898
 			return $classInstance;
3899 3899
 		} else {
3900
-			$this->_entity_map[ $object->ID() ] = $object;
3900
+			$this->_entity_map[$object->ID()] = $object;
3901 3901
 			return $object;
3902 3902
 		}
3903 3903
 	}
@@ -3910,8 +3910,8 @@  discard block
 block discarded – undo
3910 3910
 	 * @param array $cols_n_values
3911 3911
 	 * @return array
3912 3912
 	 */
3913
-	public function deduce_fields_n_values_from_cols_n_values( $cols_n_values ) {
3914
-		return $this->_deduce_fields_n_values_from_cols_n_values( $cols_n_values );
3913
+	public function deduce_fields_n_values_from_cols_n_values($cols_n_values) {
3914
+		return $this->_deduce_fields_n_values_from_cols_n_values($cols_n_values);
3915 3915
 	}
3916 3916
 
3917 3917
 
@@ -3924,40 +3924,40 @@  discard block
 block discarded – undo
3924 3924
 	 * @param string $cols_n_values
3925 3925
 	 * @return array
3926 3926
 	 */
3927
-	protected function _deduce_fields_n_values_from_cols_n_values( $cols_n_values ){
3927
+	protected function _deduce_fields_n_values_from_cols_n_values($cols_n_values) {
3928 3928
 		$this_model_fields_n_values = array();
3929
-		foreach( $this->get_tables() as $table_alias => $table_obj ) {
3930
-			$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() );
3929
+		foreach ($this->get_tables() as $table_alias => $table_obj) {
3930
+			$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());
3931 3931
 			//there is a primary key on this table and its not set. Use defaults for all its columns
3932
-			if( $table_obj->get_pk_column() && $table_pk_value === NULL ){
3933
-				foreach( $this->_get_fields_for_table( $table_alias ) as $field_name => $field_obj ) {
3934
-					if( ! $field_obj->is_db_only_field() ){
3932
+			if ($table_obj->get_pk_column() && $table_pk_value === NULL) {
3933
+				foreach ($this->_get_fields_for_table($table_alias) as $field_name => $field_obj) {
3934
+					if ( ! $field_obj->is_db_only_field()) {
3935 3935
 						//prepare field as if its coming from db
3936
-						$prepared_value = $field_obj->prepare_for_set( $field_obj->get_default_value() );
3937
-						$this_model_fields_n_values[$field_name] = $field_obj->prepare_for_use_in_db( $prepared_value );
3936
+						$prepared_value = $field_obj->prepare_for_set($field_obj->get_default_value());
3937
+						$this_model_fields_n_values[$field_name] = $field_obj->prepare_for_use_in_db($prepared_value);
3938 3938
 					}
3939 3939
 				}
3940
-			}else{
3940
+			} else {
3941 3941
 				//the table's rows existed. Use their values
3942
-				foreach( $this->_get_fields_for_table( $table_alias ) as $field_name => $field_obj ) {
3943
-					if( ! $field_obj->is_db_only_field() )
3944
-					$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() );
3942
+				foreach ($this->_get_fields_for_table($table_alias) as $field_name => $field_obj) {
3943
+					if ( ! $field_obj->is_db_only_field())
3944
+					$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());
3945 3945
 				}
3946 3946
 			}
3947 3947
 		}
3948 3948
 		return $this_model_fields_n_values;
3949 3949
 	}
3950 3950
 
3951
-	protected function _get_column_value_with_table_alias_or_not( $cols_n_values, $qualified_column, $regular_column ){
3951
+	protected function _get_column_value_with_table_alias_or_not($cols_n_values, $qualified_column, $regular_column) {
3952 3952
 		//ask the field what it think it's table_name.column_name should be, and call it the "qualified column"
3953 3953
 		//does the field on the model relate to this column retrieved from the db?
3954 3954
 		//or is it a db-only field? (not relating to the model)
3955
-		if( isset( $cols_n_values[ $qualified_column ] ) ){
3956
-			$value = $cols_n_values[ $qualified_column ];
3955
+		if (isset($cols_n_values[$qualified_column])) {
3956
+			$value = $cols_n_values[$qualified_column];
3957 3957
 
3958
-		}elseif( isset( $cols_n_values[ $regular_column ] ) ){
3959
-			$value = $cols_n_values[ $regular_column ];
3960
-		}else{
3958
+		}elseif (isset($cols_n_values[$regular_column])) {
3959
+			$value = $cols_n_values[$regular_column];
3960
+		} else {
3961 3961
 			$value = NULL;
3962 3962
 		}
3963 3963
 
@@ -3975,23 +3975,23 @@  discard block
 block discarded – undo
3975 3975
 	 * @param int|string $id
3976 3976
 	 * @return EE_Base_Class
3977 3977
 	 */
3978
-	public function refresh_entity_map_from_db( $id ){
3979
-		$obj_in_map = $this->get_from_entity_map( $id );
3980
-		if( $obj_in_map ){
3981
-			$wpdb_results = $this->_get_all_wpdb_results( array( array ( $this->get_primary_key_field()->get_name() => $id ), 'limit' => 1 ) );
3982
-			if( $wpdb_results && is_array( $wpdb_results ) ){
3983
-				$one_row = reset( $wpdb_results );
3984
-				foreach( $this->_deduce_fields_n_values_from_cols_n_values($one_row ) as $field_name => $db_value ) {
3985
-					$obj_in_map->set_from_db( $field_name, $db_value );
3978
+	public function refresh_entity_map_from_db($id) {
3979
+		$obj_in_map = $this->get_from_entity_map($id);
3980
+		if ($obj_in_map) {
3981
+			$wpdb_results = $this->_get_all_wpdb_results(array(array($this->get_primary_key_field()->get_name() => $id), 'limit' => 1));
3982
+			if ($wpdb_results && is_array($wpdb_results)) {
3983
+				$one_row = reset($wpdb_results);
3984
+				foreach ($this->_deduce_fields_n_values_from_cols_n_values($one_row) as $field_name => $db_value) {
3985
+					$obj_in_map->set_from_db($field_name, $db_value);
3986 3986
 				}
3987 3987
 				//clear the cache of related model objects
3988
-				foreach ( $this->relation_settings() as $relation_name => $relation_obj ){
3989
-					$obj_in_map->clear_cache($relation_name, NULL, TRUE );
3988
+				foreach ($this->relation_settings() as $relation_name => $relation_obj) {
3989
+					$obj_in_map->clear_cache($relation_name, NULL, TRUE);
3990 3990
 				}
3991 3991
 			}
3992 3992
 			return $obj_in_map;
3993
-		}else{
3994
-			return $this->get_one_by_ID( $id );
3993
+		} else {
3994
+			return $this->get_one_by_ID($id);
3995 3995
 		}
3996 3996
 	}
3997 3997
 
@@ -4009,24 +4009,24 @@  discard block
 block discarded – undo
4009 4009
 	 * @param EE_Base_Class $replacing_model_obj
4010 4010
 	 * @return \EE_Base_Class
4011 4011
 	 */
4012
-	public function refresh_entity_map_with( $id, $replacing_model_obj ) {
4013
-		$obj_in_map = $this->get_from_entity_map( $id );
4014
-		if( $obj_in_map ){
4015
-			if( $replacing_model_obj instanceof EE_Base_Class ){
4016
-				foreach( $replacing_model_obj->model_field_array() as $field_name => $value ) {
4017
-					$obj_in_map->set( $field_name, $value );
4012
+	public function refresh_entity_map_with($id, $replacing_model_obj) {
4013
+		$obj_in_map = $this->get_from_entity_map($id);
4014
+		if ($obj_in_map) {
4015
+			if ($replacing_model_obj instanceof EE_Base_Class) {
4016
+				foreach ($replacing_model_obj->model_field_array() as $field_name => $value) {
4017
+					$obj_in_map->set($field_name, $value);
4018 4018
 				}
4019 4019
 				//make the model object in the entity map's cache match the $replacing_model_obj
4020
-				foreach ( $this->relation_settings() as $relation_name => $relation_obj ){
4021
-					$obj_in_map->clear_cache($relation_name, NULL, TRUE );
4022
-					foreach( $replacing_model_obj->get_all_from_cache( $relation_name ) as $cache_id => $cached_obj ) {
4023
-						$obj_in_map->cache( $relation_name, $cached_obj, $cache_id );
4020
+				foreach ($this->relation_settings() as $relation_name => $relation_obj) {
4021
+					$obj_in_map->clear_cache($relation_name, NULL, TRUE);
4022
+					foreach ($replacing_model_obj->get_all_from_cache($relation_name) as $cache_id => $cached_obj) {
4023
+						$obj_in_map->cache($relation_name, $cached_obj, $cache_id);
4024 4024
 					}
4025 4025
 				}
4026 4026
 			}
4027 4027
 			return $obj_in_map;
4028
-		}else{
4029
-			$this->add_to_entity_map( $replacing_model_obj );
4028
+		} else {
4029
+			$this->add_to_entity_map($replacing_model_obj);
4030 4030
 			return $replacing_model_obj;
4031 4031
 		}
4032 4032
 	}
@@ -4039,7 +4039,7 @@  discard block
 block discarded – undo
4039 4039
 	 * require_once($this->_getClassName().".class.php");
4040 4040
 	 * @return string
4041 4041
 	 */
4042
-	private function _get_class_name(){
4042
+	private function _get_class_name() {
4043 4043
 		return "EE_".$this->get_this_model_name();
4044 4044
 	}
4045 4045
 
@@ -4052,10 +4052,10 @@  discard block
 block discarded – undo
4052 4052
 	 * @param int $quantity
4053 4053
 	 * @return string
4054 4054
 	 */
4055
-	public function item_name($quantity = 1){
4056
-		if($quantity == 1){
4055
+	public function item_name($quantity = 1) {
4056
+		if ($quantity == 1) {
4057 4057
 			return $this->singular_item;
4058
-		}else{
4058
+		} else {
4059 4059
 			return $this->plural_item;
4060 4060
 		}
4061 4061
 	}
@@ -4084,13 +4084,13 @@  discard block
 block discarded – undo
4084 4084
 	 * @throws EE_Error
4085 4085
 	 * @return mixed whatever the plugin which calls add_filter decides
4086 4086
 	 */
4087
-	public function __call($methodName,$args){
4088
-		$className=get_class($this);
4089
-		$tagName="FHEE__{$className}__{$methodName}";
4090
-		if(!has_filter($tagName)){
4087
+	public function __call($methodName, $args) {
4088
+		$className = get_class($this);
4089
+		$tagName = "FHEE__{$className}__{$methodName}";
4090
+		if ( ! has_filter($tagName)) {
4091 4091
 			throw new EE_Error(
4092 4092
 				sprintf(
4093
-					__( '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' ),
4093
+					__('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'),
4094 4094
 					$methodName,
4095 4095
 					$className,
4096 4096
 					$tagName,
@@ -4099,7 +4099,7 @@  discard block
 block discarded – undo
4099 4099
 			);
4100 4100
 		}
4101 4101
 
4102
-		return apply_filters($tagName,null,$this,$args);
4102
+		return apply_filters($tagName, null, $this, $args);
4103 4103
 	}
4104 4104
 
4105 4105
 
@@ -4112,22 +4112,22 @@  discard block
 block discarded – undo
4112 4112
 	 * @throws EE_Error
4113 4113
 	 * @return EE_Base_Class
4114 4114
 	 */
4115
-	public function ensure_is_obj( $base_class_obj_or_id, $ensure_is_in_db = FALSE ){
4115
+	public function ensure_is_obj($base_class_obj_or_id, $ensure_is_in_db = FALSE) {
4116 4116
 		$className = $this->_get_class_name();
4117 4117
 		$primary_key_field = $this->get_primary_key_field();
4118
-		if( $base_class_obj_or_id instanceof $className ){
4118
+		if ($base_class_obj_or_id instanceof $className) {
4119 4119
 			$model_object = $base_class_obj_or_id;
4120
-		}elseif( $primary_key_field instanceof EE_Primary_Key_Int_Field && (
4121
-				is_int( $base_class_obj_or_id ) ||
4122
-				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)
4120
+		}elseif ($primary_key_field instanceof EE_Primary_Key_Int_Field && (
4121
+				is_int($base_class_obj_or_id) ||
4122
+				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)
4123 4123
 			$model_object = $this->get_one_by_ID($base_class_obj_or_id);
4124
-		}elseif( $primary_key_field instanceof EE_Primary_Key_String_Field && is_string($base_class_obj_or_id) ){
4124
+		}elseif ($primary_key_field instanceof EE_Primary_Key_String_Field && is_string($base_class_obj_or_id)) {
4125 4125
 			//assume its a string representation of the object
4126 4126
 			$model_object = $this->get_one_by_ID($base_class_obj_or_id);
4127
-		}else{
4128
-			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)));
4127
+		} else {
4128
+			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)));
4129 4129
 		}
4130
-		if( $model_object->ID() == NULL && $ensure_is_in_db){
4130
+		if ($model_object->ID() == NULL && $ensure_is_in_db) {
4131 4131
 			$model_object->save();
4132 4132
 		}
4133 4133
 		return $model_object;
@@ -4143,19 +4143,19 @@  discard block
 block discarded – undo
4143 4143
 	 * @return int|string depending on the type of this model object's ID
4144 4144
 	 * @throws EE_Error
4145 4145
 	 */
4146
-	public function ensure_is_ID($base_class_obj_or_id){
4146
+	public function ensure_is_ID($base_class_obj_or_id) {
4147 4147
 		$className = $this->_get_class_name();
4148
-		if( $base_class_obj_or_id instanceof $className ){
4148
+		if ($base_class_obj_or_id instanceof $className) {
4149 4149
 			/** @var $base_class_obj_or_id EE_Base_Class */
4150 4150
 			$id = $base_class_obj_or_id->ID();
4151
-		}elseif(is_int($base_class_obj_or_id)){
4151
+		}elseif (is_int($base_class_obj_or_id)) {
4152 4152
 			//assume it's an ID
4153 4153
 			$id = $base_class_obj_or_id;
4154
-		}elseif(is_string($base_class_obj_or_id)){
4154
+		}elseif (is_string($base_class_obj_or_id)) {
4155 4155
 			//assume its a string representation of the object
4156 4156
 			$id = $base_class_obj_or_id;
4157
-		}else{
4158
-			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)));
4157
+		} else {
4158
+			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)));
4159 4159
 		}
4160 4160
 		return $id;
4161 4161
 	}
@@ -4178,14 +4178,14 @@  discard block
 block discarded – undo
4178 4178
 	 * @param int $values_already_prepared like one of the constants on EEM_Base
4179 4179
 	 * @return void
4180 4180
 	 */
4181
-	public function assume_values_already_prepared_by_model_object($values_already_prepared = self::not_prepared_by_model_object){
4181
+	public function assume_values_already_prepared_by_model_object($values_already_prepared = self::not_prepared_by_model_object) {
4182 4182
 		$this->_values_already_prepared_by_model_object = $values_already_prepared;
4183 4183
 	}
4184 4184
 	/**
4185 4185
 	 * Read comments for assume_values_already_prepared_by_model_object()
4186 4186
 	 * @return int
4187 4187
 	 */
4188
-	public function get_assumption_concerning_values_already_prepared_by_model_object(){
4188
+	public function get_assumption_concerning_values_already_prepared_by_model_object() {
4189 4189
 		return $this->_values_already_prepared_by_model_object;
4190 4190
 	}
4191 4191
 
@@ -4193,17 +4193,17 @@  discard block
 block discarded – undo
4193 4193
 	 * Gets all the indexes on this model
4194 4194
 	 * @return EE_Index[]
4195 4195
 	 */
4196
-	public function indexes(){
4196
+	public function indexes() {
4197 4197
 		return $this->_indexes;
4198 4198
 	}
4199 4199
 	/**
4200 4200
 	 * Gets all the Unique Indexes on this model
4201 4201
 	 * @return EE_Unique_Index[]
4202 4202
 	 */
4203
-	public function unique_indexes(){
4203
+	public function unique_indexes() {
4204 4204
 		$unique_indexes = array();
4205
-		foreach($this->_indexes as $name => $index){
4206
-			if($index instanceof EE_Unique_Index){
4205
+		foreach ($this->_indexes as $name => $index) {
4206
+			if ($index instanceof EE_Unique_Index) {
4207 4207
 				$unique_indexes [$name] = $index;
4208 4208
 			}
4209 4209
 		}
@@ -4216,9 +4216,9 @@  discard block
 block discarded – undo
4216 4216
 	 * on a primary index
4217 4217
 	 * @return EE_Model_Field_Base[]
4218 4218
 	 */
4219
-	public function get_combined_primary_key_fields(){
4220
-		foreach($this->indexes() as $index){
4221
-			if($index instanceof EE_Primary_Key_Index){
4219
+	public function get_combined_primary_key_fields() {
4220
+		foreach ($this->indexes() as $index) {
4221
+			if ($index instanceof EE_Primary_Key_Index) {
4222 4222
 				return $index->fields();
4223 4223
 			}
4224 4224
 		}
@@ -4231,7 +4231,7 @@  discard block
 block discarded – undo
4231 4231
 	 * @param array $cols_n_values keys are field names, values are their values
4232 4232
 	 * @return string
4233 4233
 	 */
4234
-	public function get_index_primary_key_string($cols_n_values){
4234
+	public function get_index_primary_key_string($cols_n_values) {
4235 4235
 		$cols_n_values_for_primary_key_index = array_intersect_key($cols_n_values, $this->get_combined_primary_key_fields());
4236 4236
 		return http_build_query($cols_n_values_for_primary_key_index);
4237 4237
 	}
@@ -4243,13 +4243,13 @@  discard block
 block discarded – undo
4243 4243
 	 * @param string $index_primary_key_string
4244 4244
 	 * @return null|array
4245 4245
 	 */
4246
-	function parse_index_primary_key_string( $index_primary_key_string) {
4246
+	function parse_index_primary_key_string($index_primary_key_string) {
4247 4247
 		$key_fields = $this->get_combined_primary_key_fields();
4248 4248
 		//check all of them are in the $id
4249 4249
 		$key_vals_in_combined_pk = array();
4250
-		parse_str( $index_primary_key_string, $key_vals_in_combined_pk );
4251
-		foreach( $key_fields as $key_field_name => $field_obj ) {
4252
-			if( ! isset( $key_vals_in_combined_pk[ $key_field_name ] ) ){
4250
+		parse_str($index_primary_key_string, $key_vals_in_combined_pk);
4251
+		foreach ($key_fields as $key_field_name => $field_obj) {
4252
+			if ( ! isset($key_vals_in_combined_pk[$key_field_name])) {
4253 4253
 				return NULL;
4254 4254
 			}
4255 4255
 		}
@@ -4262,10 +4262,10 @@  discard block
 block discarded – undo
4262 4262
 	 * @param array $key_vals
4263 4263
 	 * @return boolean
4264 4264
 	 */
4265
-	function has_all_combined_primary_key_fields( $key_vals ) {
4266
-		$keys_it_should_have = array_keys( $this->get_combined_primary_key_fields() );
4267
-		foreach( $keys_it_should_have as $key ){
4268
-			if( ! isset( $key_vals[ $key ] ) ){
4265
+	function has_all_combined_primary_key_fields($key_vals) {
4266
+		$keys_it_should_have = array_keys($this->get_combined_primary_key_fields());
4267
+		foreach ($keys_it_should_have as $key) {
4268
+			if ( ! isset($key_vals[$key])) {
4269 4269
 				return false;
4270 4270
 			}
4271 4271
 		}
@@ -4281,23 +4281,23 @@  discard block
 block discarded – undo
4281 4281
 	 * @throws EE_Error
4282 4282
 	 * @return \EE_Base_Class[] Array keys are object IDs (if there is a primary key on the model. if not, numerically indexed)
4283 4283
 	 */
4284
-	public function get_all_copies($model_object_or_attributes_array, $query_params = array()){
4284
+	public function get_all_copies($model_object_or_attributes_array, $query_params = array()) {
4285 4285
 
4286
-		if($model_object_or_attributes_array instanceof EE_Base_Class){
4286
+		if ($model_object_or_attributes_array instanceof EE_Base_Class) {
4287 4287
 			$attributes_array = $model_object_or_attributes_array->model_field_array();
4288
-		}elseif(is_array($model_object_or_attributes_array)){
4288
+		}elseif (is_array($model_object_or_attributes_array)) {
4289 4289
 			$attributes_array = $model_object_or_attributes_array;
4290
-		}else{
4291
-			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));
4290
+		} else {
4291
+			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));
4292 4292
 		}
4293 4293
 		//even copies obviously won't have the same ID, so remove the primary key
4294 4294
 		//from the WHERE conditions for finding copies (if there is a primary key, of course)
4295
-		if($this->has_primary_key_field() && isset($attributes_array[$this->primary_key_name()])){
4295
+		if ($this->has_primary_key_field() && isset($attributes_array[$this->primary_key_name()])) {
4296 4296
 			unset($attributes_array[$this->primary_key_name()]);
4297 4297
 		}
4298
-		if(isset($query_params[0])){
4299
-			$query_params[0] = array_merge($attributes_array,$query_params);
4300
-		}else{
4298
+		if (isset($query_params[0])) {
4299
+			$query_params[0] = array_merge($attributes_array, $query_params);
4300
+		} else {
4301 4301
 			$query_params[0] = $attributes_array;
4302 4302
 		}
4303 4303
 		return $this->get_all($query_params);
@@ -4311,16 +4311,16 @@  discard block
 block discarded – undo
4311 4311
 	 * @param array $query_params
4312 4312
 	 * @return EE_Base_Class
4313 4313
 	 */
4314
-	function get_one_copy($model_object_or_attributes_array,$query_params = array()){
4315
-		if( ! is_array( $query_params ) ){
4316
-			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' );
4314
+	function get_one_copy($model_object_or_attributes_array, $query_params = array()) {
4315
+		if ( ! is_array($query_params)) {
4316
+			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');
4317 4317
 			$query_params = array();
4318 4318
 		}
4319 4319
 		$query_params['limit'] = 1;
4320
-		$copies = $this->get_all_copies($model_object_or_attributes_array,$query_params);
4321
-		if(is_array($copies)){
4320
+		$copies = $this->get_all_copies($model_object_or_attributes_array, $query_params);
4321
+		if (is_array($copies)) {
4322 4322
 			return array_shift($copies);
4323
-		}else{
4323
+		} else {
4324 4324
 			return null;
4325 4325
 		}
4326 4326
 	}
@@ -4334,10 +4334,10 @@  discard block
 block discarded – undo
4334 4334
 	 * @param int|string $id the value of the primary key to update
4335 4335
 	 * @return int number of rows updated
4336 4336
 	 */
4337
-	public function update_by_ID($fields_n_values,$id){
4337
+	public function update_by_ID($fields_n_values, $id) {
4338 4338
 		$query_params = array(0=>array($this->get_primary_key_field()->get_name() => $id),
4339 4339
 			'default_where_conditions'=>'other_models_only',);
4340
-		return $this->update($fields_n_values,$query_params);
4340
+		return $this->update($fields_n_values, $query_params);
4341 4341
 	}
4342 4342
 
4343 4343
 
@@ -4348,12 +4348,12 @@  discard block
 block discarded – undo
4348 4348
 	 * @return string an operator which can be used in SQL
4349 4349
 	 * @throws EE_Error
4350 4350
 	 */
4351
-	private function _prepare_operator_for_sql($operator_supplied){
4351
+	private function _prepare_operator_for_sql($operator_supplied) {
4352 4352
 		$sql_operator = isset($this->_valid_operators[$operator_supplied]) ? $this->_valid_operators[$operator_supplied] : null;
4353
-		if($sql_operator){
4353
+		if ($sql_operator) {
4354 4354
 			return $sql_operator;
4355
-		}else{
4356
-			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))));
4355
+		} else {
4356
+			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))));
4357 4357
 		}
4358 4358
 	}
4359 4359
 
@@ -4363,10 +4363,10 @@  discard block
 block discarded – undo
4363 4363
 	 * @param array $query_params like get_all's
4364 4364
 	 * @return string[]
4365 4365
 	 */
4366
-	public function get_all_names($query_params = array()){
4366
+	public function get_all_names($query_params = array()) {
4367 4367
 		$objs = $this->get_all($query_params);
4368 4368
 		$names = array();
4369
-		foreach($objs as $obj){
4369
+		foreach ($objs as $obj) {
4370 4370
 			$names[$obj->ID()] = $obj->name();
4371 4371
 		}
4372 4372
 		return $names;
@@ -4381,22 +4381,22 @@  discard block
 block discarded – undo
4381 4381
 	 * @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
4382 4382
 	 * @return array
4383 4383
 	 */
4384
-	public function get_IDs( $model_objects, $filter_out_empty_ids = false) {
4385
-		if( ! $this->has_primary_key_field() ) {
4386
-			if( WP_DEBUG ) {
4387
-				EE_Error::add_error( __( 'Trying to get IDs from a model than has no primary key', 'event_espresso' ), __FILE__, __FUNCTION__, __LINE__ );
4384
+	public function get_IDs($model_objects, $filter_out_empty_ids = false) {
4385
+		if ( ! $this->has_primary_key_field()) {
4386
+			if (WP_DEBUG) {
4387
+				EE_Error::add_error(__('Trying to get IDs from a model than has no primary key', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__);
4388 4388
 				return array();
4389 4389
 			}
4390 4390
 		}
4391 4391
 		$IDs = array();
4392
-		foreach( $model_objects as $model_object ) {
4392
+		foreach ($model_objects as $model_object) {
4393 4393
 			$id = $model_object->ID();
4394
-			if( ! $id ) {
4395
-				if( $filter_out_empty_ids ) {
4394
+			if ( ! $id) {
4395
+				if ($filter_out_empty_ids) {
4396 4396
 					continue;
4397 4397
 				}
4398
-				if( WP_DEBUG ) {
4399
-					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__ );
4398
+				if (WP_DEBUG) {
4399
+					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__);
4400 4400
 				}
4401 4401
 			}
4402 4402
 			$IDs[] = $id;
@@ -4409,8 +4409,8 @@  discard block
 block discarded – undo
4409 4409
 	 * are no capabilities that relate to this model returns false
4410 4410
 	 * @return string|false
4411 4411
 	 */
4412
-	public function cap_slug(){
4413
-		return apply_filters( 'FHEE__EEM_Base__cap_slug', $this->_caps_slug, $this);
4412
+	public function cap_slug() {
4413
+		return apply_filters('FHEE__EEM_Base__cap_slug', $this->_caps_slug, $this);
4414 4414
 	}
4415 4415
 
4416 4416
 	/**
@@ -4422,27 +4422,27 @@  discard block
 block discarded – undo
4422 4422
 	 * @param string $context
4423 4423
 	 * @return EE_Default_Where_Conditions[] indexed by associated capability
4424 4424
 	 */
4425
-	public function cap_restrictions( $context = EEM_Base::caps_read ) {
4426
-		EEM_Base::verify_is_valid_cap_context( $context );
4425
+	public function cap_restrictions($context = EEM_Base::caps_read) {
4426
+		EEM_Base::verify_is_valid_cap_context($context);
4427 4427
 		//check if we ought to run the restriction generator first
4428
-		if( isset( $this->_cap_restriction_generators[ $context ] ) &&
4429
-				$this->_cap_restriction_generators[ $context ] instanceof EE_Restriction_Generator_Base &&
4430
-				! $this->_cap_restriction_generators[ $context ]->has_generated_cap_restrictions() ) {
4431
-			$this->_cap_restrictions[ $context ] = array_merge( $this->_cap_restrictions[ $context ],  $this->_cap_restriction_generators[ $context ]->generate_restrictions() );
4428
+		if (isset($this->_cap_restriction_generators[$context]) &&
4429
+				$this->_cap_restriction_generators[$context] instanceof EE_Restriction_Generator_Base &&
4430
+				! $this->_cap_restriction_generators[$context]->has_generated_cap_restrictions()) {
4431
+			$this->_cap_restrictions[$context] = array_merge($this->_cap_restrictions[$context], $this->_cap_restriction_generators[$context]->generate_restrictions());
4432 4432
 		}
4433 4433
 		//and make sure we've finalized the construction of each restriction
4434
-		foreach( $this->_cap_restrictions[ $context ] as $where_conditions_obj ) {
4435
-			$where_conditions_obj->_finalize_construct( $this );
4434
+		foreach ($this->_cap_restrictions[$context] as $where_conditions_obj) {
4435
+			$where_conditions_obj->_finalize_construct($this);
4436 4436
 		}
4437 4437
 
4438
-		return $this->_cap_restrictions[ $context ];
4438
+		return $this->_cap_restrictions[$context];
4439 4439
 	}
4440 4440
 
4441 4441
 	/**
4442 4442
 	 * Indicating whether or not this model thinks its a wp core model
4443 4443
 	 * @return boolean
4444 4444
 	 */
4445
-	public function is_wp_core_model(){
4445
+	public function is_wp_core_model() {
4446 4446
 		return $this->_wp_core_model;
4447 4447
 	}
4448 4448
 
@@ -4452,12 +4452,12 @@  discard block
 block discarded – undo
4452 4452
 	 * @param string $context one of EEM_Base::caps_ constants
4453 4453
 	 * @return EE_Default_Where_Conditions[] indexed by capability name
4454 4454
 	 */
4455
-	public function caps_missing( $context = EEM_Base::caps_read ) {
4455
+	public function caps_missing($context = EEM_Base::caps_read) {
4456 4456
 		$missing_caps = array();
4457
-		$cap_restrictions = $this->cap_restrictions( $context );
4458
-		foreach( $cap_restrictions as $cap => $restriction_if_no_cap ) {
4459
-			if( ! EE_Capabilities::instance()->current_user_can( $cap, $this->get_this_model_name() . '_model_applying_caps') ) {
4460
-				$missing_caps[ $cap ] = $restriction_if_no_cap;
4457
+		$cap_restrictions = $this->cap_restrictions($context);
4458
+		foreach ($cap_restrictions as $cap => $restriction_if_no_cap) {
4459
+			if ( ! EE_Capabilities::instance()->current_user_can($cap, $this->get_this_model_name().'_model_applying_caps')) {
4460
+				$missing_caps[$cap] = $restriction_if_no_cap;
4461 4461
 			}
4462 4462
 		}
4463 4463
 		return $missing_caps;
@@ -4469,7 +4469,7 @@  discard block
 block discarded – undo
4469 4469
 	 * one of 'read', 'edit', or 'delete'
4470 4470
 	 */
4471 4471
 	public function cap_contexts_to_cap_action_map() {
4472
-		return apply_filters( 'FHEE__EEM_Base__cap_contexts_to_cap_action_map', $this->_cap_contexts_to_cap_action_map, $this );
4472
+		return apply_filters('FHEE__EEM_Base__cap_contexts_to_cap_action_map', $this->_cap_contexts_to_cap_action_map, $this);
4473 4473
 	}
4474 4474
 
4475 4475
 
@@ -4480,19 +4480,19 @@  discard block
 block discarded – undo
4480 4480
 	 * @return string one of EEM_Base::cap_contexts_to_cap_action_map() values
4481 4481
 	 * @throws \EE_Error
4482 4482
 	 */
4483
-	public function cap_action_for_context( $context ) {
4483
+	public function cap_action_for_context($context) {
4484 4484
 		$mapping = $this->cap_contexts_to_cap_action_map();
4485
-		if( isset( $mapping[ $context ] ) ) {
4486
-			return $mapping[ $context ];
4485
+		if (isset($mapping[$context])) {
4486
+			return $mapping[$context];
4487 4487
 		}
4488
-		if( $action = apply_filters( 'FHEE__EEM_Base__cap_action_for_context', null, $this, $mapping, $context ) ) {
4488
+		if ($action = apply_filters('FHEE__EEM_Base__cap_action_for_context', null, $this, $mapping, $context)) {
4489 4489
 			return $action;
4490 4490
 		}
4491 4491
 		throw new EE_Error(
4492 4492
 			sprintf(
4493
-				__( 'Cannot find capability restrictions for context "%1$s", allowed values are:%2$s', 'event_espresso' ),
4493
+				__('Cannot find capability restrictions for context "%1$s", allowed values are:%2$s', 'event_espresso'),
4494 4494
 				$context,
4495
-				implode(',', array_keys( $this->cap_contexts_to_cap_action_map() ) )
4495
+				implode(',', array_keys($this->cap_contexts_to_cap_action_map()))
4496 4496
 			)
4497 4497
 		);
4498 4498
 
@@ -4503,7 +4503,7 @@  discard block
 block discarded – undo
4503 4503
 	 * @return array
4504 4504
 	 */
4505 4505
 	static public function valid_cap_contexts() {
4506
-		return apply_filters( 'FHEE__EEM_Base__valid_cap_contexts', array(
4506
+		return apply_filters('FHEE__EEM_Base__valid_cap_contexts', array(
4507 4507
 			self::caps_read,
4508 4508
 			self::caps_read_admin,
4509 4509
 			self::caps_edit,
@@ -4519,17 +4519,17 @@  discard block
 block discarded – undo
4519 4519
 	 * @return bool
4520 4520
 	 * @throws \EE_Error
4521 4521
 	 */
4522
-	static public function verify_is_valid_cap_context( $context ) {
4522
+	static public function verify_is_valid_cap_context($context) {
4523 4523
 		$valid_cap_contexts = EEM_Base::valid_cap_contexts();
4524
-		if( in_array( $context, $valid_cap_contexts ) ) {
4524
+		if (in_array($context, $valid_cap_contexts)) {
4525 4525
 			return true;
4526
-		}else{
4526
+		} else {
4527 4527
 			throw new EE_Error(
4528 4528
 				sprintf(
4529
-					__( 'Context "%1$s" passed into model "%2$s" is not a valid context. They are: %3$s', 'event_espresso' ),
4529
+					__('Context "%1$s" passed into model "%2$s" is not a valid context. They are: %3$s', 'event_espresso'),
4530 4530
 					$context,
4531
-					'EEM_Base' ,
4532
-					implode(',', $valid_cap_contexts )
4531
+					'EEM_Base',
4532
+					implode(',', $valid_cap_contexts)
4533 4533
 				)
4534 4534
 			);
4535 4535
 		}
Please login to merge, or discard this patch.