Completed
Branch BUG-7537 (260ea4)
by
unknown
15:53
created
core/db_classes/EE_Import.class.php 2 patches
Indentation   +62 added lines, -62 removed lines patch added patch discarded remove patch
@@ -146,43 +146,43 @@  discard block
 block discarded – undo
146 146
 		if ( isset( $_REQUEST['import'] )) {
147 147
 			if( isset( $_POST['csv_submitted'] )) {
148 148
 
149
-			    switch ( $_FILES['file']['error'][0] ) {
150
-			        case UPLOAD_ERR_OK:
151
-			            $error_msg = FALSE;
152
-			            break;
153
-			        case UPLOAD_ERR_INI_SIZE:
154
-			            $error_msg = __("'The uploaded file exceeds the upload_max_filesize directive in php.ini.'", "event_espresso");
155
-			            break;
156
-			        case UPLOAD_ERR_FORM_SIZE:
157
-			            $error_msg = __('The uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the HTML form.', "event_espresso");
158
-			            break;
159
-			        case UPLOAD_ERR_PARTIAL:
160
-			            $error_msg = __('The uploaded file was only partially uploaded.', "event_espresso");
161
-			            break;
162
-			        case UPLOAD_ERR_NO_FILE:
163
-			            $error_msg = __('No file was uploaded.', "event_espresso");
164
-			            break;
165
-			        case UPLOAD_ERR_NO_TMP_DIR:
166
-			            $error_msg = __('Missing a temporary folder.', "event_espresso");
167
-			            break;
168
-			        case UPLOAD_ERR_CANT_WRITE:
169
-			            $error_msg = __('Failed to write file to disk.', "event_espresso");
170
-			            break;
171
-			        case UPLOAD_ERR_EXTENSION:
172
-			            $error_msg = __('File upload stopped by extension.', "event_espresso");
173
-			            break;
174
-			        default:
175
-			            $error_msg = __('An unknown error occurred and the file could not be uploaded', "event_espresso");
176
-			            break;
177
-			    }
149
+				switch ( $_FILES['file']['error'][0] ) {
150
+					case UPLOAD_ERR_OK:
151
+						$error_msg = FALSE;
152
+						break;
153
+					case UPLOAD_ERR_INI_SIZE:
154
+						$error_msg = __("'The uploaded file exceeds the upload_max_filesize directive in php.ini.'", "event_espresso");
155
+						break;
156
+					case UPLOAD_ERR_FORM_SIZE:
157
+						$error_msg = __('The uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the HTML form.', "event_espresso");
158
+						break;
159
+					case UPLOAD_ERR_PARTIAL:
160
+						$error_msg = __('The uploaded file was only partially uploaded.', "event_espresso");
161
+						break;
162
+					case UPLOAD_ERR_NO_FILE:
163
+						$error_msg = __('No file was uploaded.', "event_espresso");
164
+						break;
165
+					case UPLOAD_ERR_NO_TMP_DIR:
166
+						$error_msg = __('Missing a temporary folder.', "event_espresso");
167
+						break;
168
+					case UPLOAD_ERR_CANT_WRITE:
169
+						$error_msg = __('Failed to write file to disk.', "event_espresso");
170
+						break;
171
+					case UPLOAD_ERR_EXTENSION:
172
+						$error_msg = __('File upload stopped by extension.', "event_espresso");
173
+						break;
174
+					default:
175
+						$error_msg = __('An unknown error occurred and the file could not be uploaded', "event_espresso");
176
+						break;
177
+				}
178 178
 
179 179
 				if ( ! $error_msg ) {
180 180
 
181
-				    $filename	= $_FILES['file']['name'][0];
181
+					$filename	= $_FILES['file']['name'][0];
182 182
 					$file_ext 		= substr( strrchr( $filename, '.' ), 1 );
183
-				    //$file_type 	= $_FILES['file']['type'][0];
184
-				    $temp_file	= $_FILES['file']['tmp_name'][0];
185
-				    $filesize    	= $_FILES['file']['size'][0] / 1024;//convert from bytes to KB
183
+					//$file_type 	= $_FILES['file']['type'][0];
184
+					$temp_file	= $_FILES['file']['tmp_name'][0];
185
+					$filesize    	= $_FILES['file']['size'][0] / 1024;//convert from bytes to KB
186 186
 
187 187
 					if ( $file_ext=='csv' ) {
188 188
 
@@ -331,10 +331,10 @@  discard block
 block discarded – undo
331 331
 			unset($csv_data_array[EE_CSV::metadata_header]);
332 332
 		}
333 333
 		/**
334
-		* @var $old_db_to_new_db_mapping 2d array: top level keys being model names, bottom-level keys being the original key, and
335
-		* the value will be the newly-inserted ID.
336
-		* If we have already imported data from the same website via CSV, it should be kept in this wp option
337
-		*/
334
+		 * @var $old_db_to_new_db_mapping 2d array: top level keys being model names, bottom-level keys being the original key, and
335
+		 * the value will be the newly-inserted ID.
336
+		 * If we have already imported data from the same website via CSV, it should be kept in this wp option
337
+		 */
338 338
 	   $old_db_to_new_db_mapping = get_option('ee_id_mapping_from'.sanitize_title($old_site_url),array());
339 339
 	   if( $old_db_to_new_db_mapping){
340 340
 		   EE_Error::add_attention(
@@ -435,7 +435,7 @@  discard block
 block discarded – undo
435 435
 				foreach($model_object_data as $field){
436 436
 					if($field){
437 437
 						$row_is_completely_empty = false;
438
-                                                break;
438
+												break;
439 439
 					}
440 440
 				}
441 441
 				if($row_is_completely_empty){
@@ -453,7 +453,7 @@  discard block
 block discarded – undo
453 453
 
454 454
 
455 455
 				$model_object_data = $this->_replace_temp_ids_with_mappings( $model_object_data, $model, $old_db_to_new_db_mapping, $export_from_site_a_to_b );
456
-                $model_object_data = $this->_prepare_data_for_use_in_db( $model_object_data, $model, $export_from_site_a_to_b );
456
+				$model_object_data = $this->_prepare_data_for_use_in_db( $model_object_data, $model, $export_from_site_a_to_b );
457 457
 //now we need to decide if we're going to add a new model object given the $model_object_data,
458 458
 				//or just update.
459 459
 				if($export_from_site_a_to_b){
@@ -638,27 +638,27 @@  discard block
 block discarded – undo
638 638
 		return apply_filters( 'FHEE__EE_Import___replace_temp_ids_with_mappings__model_object_data__end', $model_object_data, $model );
639 639
 	}
640 640
         
641
-        /**
642
-         * Does a little extra processing on the data to maintain data consistency
643
-         * @param array $original_data_row
644
-         * @param EEM_Base $model
645
-         * @param boolean $export_from_site_a_to_b
646
-         */
647
-        protected function _prepare_data_for_use_in_db( $original_data_row, $model, $export_from_site_a_to_b ) {
648
-            $altered_data_row = $original_data_row;
649
-            switch( $model->get_this_model_name() ) {
650
-                case 'Message_Template_Group':
651
-                    if( isset( $original_data_row[ 'MTP_is_global' ] ) && 
652
-                            intval( $original_data_row[ 'MTP_is_global' ] ) == 1 && 
653
-                            apply_filters( 'FHEE__EE_Import___prepare_data_for_use_in_db__tweak_global_message_template_groups', true, $original_data_row, $model, $export_from_site_a_to_b ) &&
654
-                            ! $export_from_site_a_to_b ) {
655
-                        $altered_data_row[ 'MTP_is_global' ] = 0;
656
-                        $message_type = isset( $altered_data_row[ 'MTP_message_type' ] ) ? $altered_data_row[ 'MTP_message_type' ] : __( 'Unknown', 'event_espresso' );
657
-                        $altered_data_row[ 'MTP_name' ] = sprintf( __( 'Global %1$s message template from %2$s', 'event_espresso'), $message_type, $this->_csv_import_metadata_row[ 'site_url' ] );
658
-                        global $current_user;
659
-                        $altered_data_row[ 'MTP_description' ] = sprintf( __( 'Imported at %1$s by user %2$s', 'event_espresso' ), current_time( 'mysql' ), $current_user->user_nicename );
660
-                    }
661
-            }
641
+		/**
642
+		 * Does a little extra processing on the data to maintain data consistency
643
+		 * @param array $original_data_row
644
+		 * @param EEM_Base $model
645
+		 * @param boolean $export_from_site_a_to_b
646
+		 */
647
+		protected function _prepare_data_for_use_in_db( $original_data_row, $model, $export_from_site_a_to_b ) {
648
+			$altered_data_row = $original_data_row;
649
+			switch( $model->get_this_model_name() ) {
650
+				case 'Message_Template_Group':
651
+					if( isset( $original_data_row[ 'MTP_is_global' ] ) && 
652
+							intval( $original_data_row[ 'MTP_is_global' ] ) == 1 && 
653
+							apply_filters( 'FHEE__EE_Import___prepare_data_for_use_in_db__tweak_global_message_template_groups', true, $original_data_row, $model, $export_from_site_a_to_b ) &&
654
+							! $export_from_site_a_to_b ) {
655
+						$altered_data_row[ 'MTP_is_global' ] = 0;
656
+						$message_type = isset( $altered_data_row[ 'MTP_message_type' ] ) ? $altered_data_row[ 'MTP_message_type' ] : __( 'Unknown', 'event_espresso' );
657
+						$altered_data_row[ 'MTP_name' ] = sprintf( __( 'Global %1$s message template from %2$s', 'event_espresso'), $message_type, $this->_csv_import_metadata_row[ 'site_url' ] );
658
+						global $current_user;
659
+						$altered_data_row[ 'MTP_description' ] = sprintf( __( 'Imported at %1$s by user %2$s', 'event_espresso' ), current_time( 'mysql' ), $current_user->user_nicename );
660
+					}
661
+			}
662 662
 			foreach( $model->field_settings() as $field_name => $field_obj ) {
663 663
 				if( $field_obj instanceof EE_Datetime_Field ) {
664 664
 					$altered_data_row[ $field_name ] = $model->convert_datetime_for_query( 
@@ -668,8 +668,8 @@  discard block
 block discarded – undo
668 668
 							isset( $this->_csv_import_metadata_row[ 'timezone' ] ) ? $this->_csv_import_metadata_row[ 'timezone' ] : '' );
669 669
 				}
670 670
 			}
671
-            return apply_filters( 'FHEE__EE_Import___prepare_data_for_use_in_db__return', $altered_data_row, $original_data_row, $model, $this );
672
-        }
671
+			return apply_filters( 'FHEE__EE_Import___prepare_data_for_use_in_db__return', $altered_data_row, $original_data_row, $model, $this );
672
+		}
673 673
 
674 674
 	/**
675 675
 	 * If the data was exported PRE-4.2, but then imported POST-4.2, then the term_id
Please login to merge, or discard this patch.
Spacing   +222 added lines, -222 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1
-<?php if (!defined('EVENT_ESPRESSO_VERSION')) exit('No direct script access allowed');
2
-do_action( 'AHEE_log', __FILE__, __FUNCTION__, '' );
1
+<?php if ( ! defined('EVENT_ESPRESSO_VERSION')) exit('No direct script access allowed');
2
+do_action('AHEE_log', __FILE__, __FUNCTION__, '');
3 3
 /**
4 4
  * EE_Import class
5 5
  *
@@ -69,10 +69,10 @@  discard block
 block discarded – undo
69 69
 	 */
70 70
 	public static function instance() {
71 71
 		// check if class object is instantiated
72
-		if ( self::$_instance === NULL  or ! is_object( self::$_instance ) or ! ( self::$_instance instanceof EE_Import )) {
72
+		if (self::$_instance === NULL or ! is_object(self::$_instance) or ! (self::$_instance instanceof EE_Import)) {
73 73
 			self::$_instance = new self();
74 74
 		}
75
-		add_filter( 'FHEE__EE_Import___replace_temp_ids_with_mappings__model_object_data__end', array( self::$_instance, 'handle_split_term_ids' ), 10, 2 );
75
+		add_filter('FHEE__EE_Import___replace_temp_ids_with_mappings__model_object_data__end', array(self::$_instance, 'handle_split_term_ids'), 10, 2);
76 76
 		return self::$_instance;
77 77
 	}
78 78
 
@@ -80,7 +80,7 @@  discard block
 block discarded – undo
80 80
 	 * Resets the importer
81 81
 	 * @return EE_Import
82 82
 	 */
83
-	public static function reset(){
83
+	public static function reset() {
84 84
 		self::$_instance = null;
85 85
 		return self::instance();
86 86
 	}
@@ -99,27 +99,27 @@  discard block
 block discarded – undo
99 99
 	  *
100 100
 *@return string
101 101
 	  */
102
-	public function upload_form ( $title, $intro, $form_url, $action, $type  ) {
102
+	public function upload_form($title, $intro, $form_url, $action, $type) {
103 103
 
104
-		$form_url = EE_Admin_Page::add_query_args_and_nonce( array( 'action' => $action ), $form_url );
104
+		$form_url = EE_Admin_Page::add_query_args_and_nonce(array('action' => $action), $form_url);
105 105
 
106 106
 		ob_start();
107 107
 ?>
108 108
 	<div class="ee-upload-form-dv">
109
-		<h3><?php echo $title;?></h3>
110
-		<p><?php echo $intro;?></p>
109
+		<h3><?php echo $title; ?></h3>
110
+		<p><?php echo $intro; ?></p>
111 111
 
112 112
 		<form action="<?php echo $form_url?>" method="post" enctype="multipart/form-data">
113
-			<input type="hidden" name="csv_submitted" value="TRUE" id="<?php echo time();?>">
114
-			<input name="import" type="hidden" value="<?php echo $type;?>" />
113
+			<input type="hidden" name="csv_submitted" value="TRUE" id="<?php echo time(); ?>">
114
+			<input name="import" type="hidden" value="<?php echo $type; ?>" />
115 115
 			<input type="file" name="file[]" size="90" >
116
-			<input class="button-primary" type="submit" value="<?php _e( 'Upload File', 'event_espresso' );?>">
116
+			<input class="button-primary" type="submit" value="<?php _e('Upload File', 'event_espresso'); ?>">
117 117
 		</form>
118 118
 
119 119
 		<p class="ee-attention">
120
-			<b><?php _e( 'Attention', 'event_espresso' );?></b><br/>
121
-			<?php echo sprintf( __( 'Accepts .%s file types only.', 'event_espresso' ), $type ) ;?>
122
-			<?php echo __( 'Please only import CSV files exported from Event Espresso, or compatible 3rd-party software.', 'event_espresso' );?>
120
+			<b><?php _e('Attention', 'event_espresso'); ?></b><br/>
121
+			<?php echo sprintf(__('Accepts .%s file types only.', 'event_espresso'), $type); ?>
122
+			<?php echo __('Please only import CSV files exported from Event Espresso, or compatible 3rd-party software.', 'event_espresso'); ?>
123 123
 		</p>
124 124
 
125 125
 	</div>
@@ -140,13 +140,13 @@  discard block
 block discarded – undo
140 140
 	 */
141 141
 	public function import() {
142 142
 
143
-		require_once( EE_CLASSES . 'EE_CSV.class.php' );
143
+		require_once(EE_CLASSES.'EE_CSV.class.php');
144 144
 		$this->EE_CSV = EE_CSV::instance();
145 145
 		$success = true;
146
-		if ( isset( $_REQUEST['import'] )) {
147
-			if( isset( $_POST['csv_submitted'] )) {
146
+		if (isset($_REQUEST['import'])) {
147
+			if (isset($_POST['csv_submitted'])) {
148 148
 
149
-			    switch ( $_FILES['file']['error'][0] ) {
149
+			    switch ($_FILES['file']['error'][0]) {
150 150
 			        case UPLOAD_ERR_OK:
151 151
 			            $error_msg = FALSE;
152 152
 			            break;
@@ -176,29 +176,29 @@  discard block
 block discarded – undo
176 176
 			            break;
177 177
 			    }
178 178
 
179
-				if ( ! $error_msg ) {
179
+				if ( ! $error_msg) {
180 180
 
181
-				    $filename	= $_FILES['file']['name'][0];
182
-					$file_ext 		= substr( strrchr( $filename, '.' ), 1 );
181
+				    $filename = $_FILES['file']['name'][0];
182
+					$file_ext = substr(strrchr($filename, '.'), 1);
183 183
 				    //$file_type 	= $_FILES['file']['type'][0];
184
-				    $temp_file	= $_FILES['file']['tmp_name'][0];
185
-				    $filesize    	= $_FILES['file']['size'][0] / 1024;//convert from bytes to KB
184
+				    $temp_file = $_FILES['file']['tmp_name'][0];
185
+				    $filesize = $_FILES['file']['size'][0] / 1024; //convert from bytes to KB
186 186
 
187
-					if ( $file_ext=='csv' ) {
187
+					if ($file_ext == 'csv') {
188 188
 
189
-						$max_upload = $this->EE_CSV->get_max_upload_size();//max upload size in KB
190
-						if ( $filesize < $max_upload || true) {
189
+						$max_upload = $this->EE_CSV->get_max_upload_size(); //max upload size in KB
190
+						if ($filesize < $max_upload || true) {
191 191
 
192
-							$wp_upload_dir = str_replace( array( '\\', '/' ), DS, wp_upload_dir());
193
-							$path_to_file = $wp_upload_dir['basedir'] . DS . 'espresso' . DS . $filename;
192
+							$wp_upload_dir = str_replace(array('\\', '/'), DS, wp_upload_dir());
193
+							$path_to_file = $wp_upload_dir['basedir'].DS.'espresso'.DS.$filename;
194 194
 
195
-							if( move_uploaded_file( $temp_file, $path_to_file )) {
195
+							if (move_uploaded_file($temp_file, $path_to_file)) {
196 196
 								// convert csv to array
197
-								$this->csv_array = $this->EE_CSV->import_csv_to_model_data_array( $path_to_file );
197
+								$this->csv_array = $this->EE_CSV->import_csv_to_model_data_array($path_to_file);
198 198
 								// was data successfully stored in an array?
199
-								if ( is_array( $this->csv_array ) ) {
199
+								if (is_array($this->csv_array)) {
200 200
 									// save processed codes to db
201
-									if ( $this->save_csv_data_array_to_db( $this->csv_array, false ) ) {
201
+									if ($this->save_csv_data_array_to_db($this->csv_array, false)) {
202 202
 										$success = TRUE;
203 203
 									}
204 204
 								} else {
@@ -245,7 +245,7 @@  discard block
 block discarded – undo
245 245
 					}
246 246
 
247 247
 				} else {
248
-					$this->_add_general_error( $error_msg, __FILE__, __FUNCTION__, __LINE__ );
248
+					$this->_add_general_error($error_msg, __FILE__, __FUNCTION__, __LINE__);
249 249
 					$success = FALSE;
250 250
 				}
251 251
 
@@ -288,14 +288,14 @@  discard block
 block discarded – undo
288 288
 	 * @param bool | string $model_name - an array containing the csv column names as keys with the corresponding db table fields they will be saved to
289 289
 	 * @return TRUE on success, FALSE on fail
290 290
 	 */
291
-	public function save_csv_data_array_to_db( $csv_data_array, $model_name = FALSE ) {
291
+	public function save_csv_data_array_to_db($csv_data_array, $model_name = FALSE) {
292 292
 
293 293
 		//whether to treat this import as if it's data from a different database or not
294 294
 		//ie, if it IS from a different database, ignore foreign keys
295 295
 		$export_from_site_a_to_b = true;
296 296
 		// first level of array is not table information but a table name was passed to the function
297 297
 		// array is only two levels deep, so let's fix that by adding a level, else the next steps will fail
298
-		if($model_name){
298
+		if ($model_name) {
299 299
 			$csv_data_array = array($csv_data_array);
300 300
 		}
301 301
 		//what models we want to update
@@ -309,14 +309,14 @@  discard block
 block discarded – undo
309 309
 		$old_site_url = 'none-specified';
310 310
 
311 311
 		//handle metadata
312
-		if(isset($csv_data_array[EE_CSV::metadata_header]) ){
312
+		if (isset($csv_data_array[EE_CSV::metadata_header])) {
313 313
 			$this->_csv_import_metadata_row = array_shift($csv_data_array[EE_CSV::metadata_header]);
314 314
 			//ok so its metadata, dont try to save it to the db obviously...
315
-			if(isset($this->_csv_import_metadata_row['site_url']) && $this->_csv_import_metadata_row['site_url'] == site_url()){
316
-				EE_Error::add_attention( __("CSV Data appears to be from the same database, so attempting to update data", "event_espresso") );
315
+			if (isset($this->_csv_import_metadata_row['site_url']) && $this->_csv_import_metadata_row['site_url'] == site_url()) {
316
+				EE_Error::add_attention(__("CSV Data appears to be from the same database, so attempting to update data", "event_espresso"));
317 317
 				$export_from_site_a_to_b = false;
318
-			}else{
319
-				$old_site_url = isset( $this->_csv_import_metadata_row['site_url']) ? $this->_csv_import_metadata_row['site_url'] : $old_site_url;
318
+			} else {
319
+				$old_site_url = isset($this->_csv_import_metadata_row['site_url']) ? $this->_csv_import_metadata_row['site_url'] : $old_site_url;
320 320
 				EE_Error::add_attention(
321 321
 					sprintf(
322 322
 						__('CSV Data appears to be from a different database (%1$s instead of %2$s), so we assume IDs in the CSV data DO NOT correspond to IDs in this database', "event_espresso"),
@@ -325,8 +325,8 @@  discard block
 block discarded – undo
325 325
 					)
326 326
 				);
327 327
 			};
328
-			if( ! empty( $this->_csv_import_metadata_row['models_to_update'] )){
329
-				$models_to_update = explode(",", $this->_csv_import_metadata_row['models_to_update' ] );
328
+			if ( ! empty($this->_csv_import_metadata_row['models_to_update'])) {
329
+				$models_to_update = explode(",", $this->_csv_import_metadata_row['models_to_update']);
330 330
 			}
331 331
 			unset($csv_data_array[EE_CSV::metadata_header]);
332 332
 		}
@@ -335,8 +335,8 @@  discard block
 block discarded – undo
335 335
 		* the value will be the newly-inserted ID.
336 336
 		* If we have already imported data from the same website via CSV, it should be kept in this wp option
337 337
 		*/
338
-	   $old_db_to_new_db_mapping = get_option('ee_id_mapping_from'.sanitize_title($old_site_url),array());
339
-	   if( $old_db_to_new_db_mapping){
338
+	   $old_db_to_new_db_mapping = get_option('ee_id_mapping_from'.sanitize_title($old_site_url), array());
339
+	   if ($old_db_to_new_db_mapping) {
340 340
 		   EE_Error::add_attention(
341 341
 			   sprintf(
342 342
 				   __('We noticed you have imported data via CSV from %1$s before. Because of this, IDs in your CSV have been mapped to their new IDs in %2$s', "event_espresso"),
@@ -345,23 +345,23 @@  discard block
 block discarded – undo
345 345
 			   )
346 346
 		   );
347 347
 	   }
348
-	   $old_db_to_new_db_mapping = $this->save_data_rows_to_db($csv_data_array, $export_from_site_a_to_b, $old_db_to_new_db_mapping, $models_to_update );
348
+	   $old_db_to_new_db_mapping = $this->save_data_rows_to_db($csv_data_array, $export_from_site_a_to_b, $old_db_to_new_db_mapping, $models_to_update);
349 349
 
350 350
 		//save the mapping from old db to new db in case they try re-importing the same data from the same website again
351
-		update_option('ee_id_mapping_from'.sanitize_title($old_site_url),$old_db_to_new_db_mapping);
351
+		update_option('ee_id_mapping_from'.sanitize_title($old_site_url), $old_db_to_new_db_mapping);
352 352
 
353 353
 
354 354
 		//lastly, we need to update the datetime and ticket sold amounts
355 355
 		//as those may have been affected by this
356
-		EEM_Datetime::instance()->update_sold( EEM_Datetime::instance()->get_all() );
356
+		EEM_Datetime::instance()->update_sold(EEM_Datetime::instance()->get_all());
357 357
 		EEM_Ticket::instance()->update_tickets_sold(EEM_Ticket::instance()->get_all());
358 358
 
359 359
 		// if there was at least one success and absolutely no errors
360
-		if (	! $this->get_total_general_errors() &&
361
-				! $this->get_total_insert_errors()  &&
360
+		if ( ! $this->get_total_general_errors() &&
361
+				! $this->get_total_insert_errors() &&
362 362
 				! $this->get_total_update_errors() &&
363 363
 				$this->get_total_inserts() &&
364
-				$this->get_total_updates() ) {
364
+				$this->get_total_updates()) {
365 365
 			return TRUE;
366 366
 		} else {
367 367
 			return FALSE;
@@ -401,23 +401,23 @@  discard block
 block discarded – undo
401 401
 	  * @return array updated $old_db_to_new_db_mapping
402 402
 	  * @throws \EE_Error
403 403
 	  */
404
-	public function save_data_rows_to_db( $csv_data_array, $export_from_site_a_to_b, $old_db_to_new_db_mapping, $models_to_update = NULL ) {
405
-		foreach ( $csv_data_array as $model_name_in_csv_data => $model_data_from_import ) {
404
+	public function save_data_rows_to_db($csv_data_array, $export_from_site_a_to_b, $old_db_to_new_db_mapping, $models_to_update = NULL) {
405
+		foreach ($csv_data_array as $model_name_in_csv_data => $model_data_from_import) {
406 406
 			//now check that assumption was correct. If
407
-			if ( EE_Registry::instance()->is_model_name($model_name_in_csv_data)) {
407
+			if (EE_Registry::instance()->is_model_name($model_name_in_csv_data)) {
408 408
 				$model_name = $model_name_in_csv_data;
409
-			}elseif( empty( $model_name_in_csv_data ) ) {
409
+			}elseif (empty($model_name_in_csv_data)) {
410 410
 				// no table info in the array and no table name passed to the function?? FAIL
411 411
 				$this->_add_general_error(
412
-					__('No table information was specified and/or found, therefore the import could not be completed','event_espresso'),
412
+					__('No table information was specified and/or found, therefore the import could not be completed', 'event_espresso'),
413 413
 					__FILE__, __FUNCTION__, __LINE__
414 414
 				);
415 415
 				return FALSE;
416
-			}else{
416
+			} else {
417 417
 				//what is this model name??
418 418
 				$this->_add_general_error(
419 419
 					sprintf(
420
-						__( 'The model "%1$s" is not recognized so its data cannot be imported', 'event_espresso' ),
420
+						__('The model "%1$s" is not recognized so its data cannot be imported', 'event_espresso'),
421 421
 						$model_name_in_csv_data
422 422
 					),
423 423
 					__FILE__, __FUNCTION__, __LINE__
@@ -429,77 +429,77 @@  discard block
 block discarded – undo
429 429
 			$model = EE_Registry::instance()->load_model($model_name);
430 430
 
431 431
 			//so without further ado, scanning all the data provided for primary keys and their inital values
432
-			foreach ( $model_data_from_import as $model_object_data ) {
432
+			foreach ($model_data_from_import as $model_object_data) {
433 433
 				//before we do ANYTHING, make sure the csv row wasn't just completely blank
434 434
 				$row_is_completely_empty = true;
435
-				foreach($model_object_data as $field){
436
-					if($field){
435
+				foreach ($model_object_data as $field) {
436
+					if ($field) {
437 437
 						$row_is_completely_empty = false;
438 438
                                                 break;
439 439
 					}
440 440
 				}
441
-				if($row_is_completely_empty){
441
+				if ($row_is_completely_empty) {
442 442
 					continue;
443 443
 				}
444 444
 				//make sure there is no data for fields we don't recognize
445
-				$model_object_data = array_intersect_key( $model_object_data, $model->field_settings() );
445
+				$model_object_data = array_intersect_key($model_object_data, $model->field_settings());
446 446
 				//find the PK in the row of data (or a combined key if
447 447
 				//there is no primary key)
448
-				if($model->has_primary_key_field()){
449
-					$id_in_csv =  $model_object_data[$model->primary_key_name()];
450
-				}else{
448
+				if ($model->has_primary_key_field()) {
449
+					$id_in_csv = $model_object_data[$model->primary_key_name()];
450
+				} else {
451 451
 					$id_in_csv = $model->get_index_primary_key_string($model_object_data);
452 452
 				}
453 453
 
454 454
 
455
-				$model_object_data = $this->_replace_temp_ids_with_mappings( $model_object_data, $model, $old_db_to_new_db_mapping, $export_from_site_a_to_b );
456
-                $model_object_data = $this->_prepare_data_for_use_in_db( $model_object_data, $model, $export_from_site_a_to_b );
455
+				$model_object_data = $this->_replace_temp_ids_with_mappings($model_object_data, $model, $old_db_to_new_db_mapping, $export_from_site_a_to_b);
456
+                $model_object_data = $this->_prepare_data_for_use_in_db($model_object_data, $model, $export_from_site_a_to_b);
457 457
 //now we need to decide if we're going to add a new model object given the $model_object_data,
458 458
 				//or just update.
459
-				if($export_from_site_a_to_b){
460
-					$what_to_do = $this->_decide_whether_to_insert_or_update_given_data_from_other_db( $id_in_csv, $model_object_data, $model, $old_db_to_new_db_mapping );
461
-				}else{//this is just a re-import
462
-					$what_to_do = $this->_decide_whether_to_insert_or_update_given_data_from_same_db( $id_in_csv, $model_object_data, $model, $old_db_to_new_db_mapping );
459
+				if ($export_from_site_a_to_b) {
460
+					$what_to_do = $this->_decide_whether_to_insert_or_update_given_data_from_other_db($id_in_csv, $model_object_data, $model, $old_db_to_new_db_mapping);
461
+				} else {//this is just a re-import
462
+					$what_to_do = $this->_decide_whether_to_insert_or_update_given_data_from_same_db($id_in_csv, $model_object_data, $model, $old_db_to_new_db_mapping);
463 463
 				}
464
-				if( $what_to_do == self::do_nothing ) {
464
+				if ($what_to_do == self::do_nothing) {
465 465
 					continue;
466 466
 				}
467 467
 
468 468
 				//double-check we actually want to insert, if that's what we're planning
469 469
 				//based on whether this item would be unique in the DB or not
470
-				if( $what_to_do == self::do_insert ) {
470
+				if ($what_to_do == self::do_insert) {
471 471
 					//we're supposed to be inserting. But wait, will this thing
472 472
 					//be acceptable if inserted?
473
-					$conflicting = $model->get_one_conflicting( $model_object_data, false );
474
-					if($conflicting){
473
+					$conflicting = $model->get_one_conflicting($model_object_data, false);
474
+					if ($conflicting) {
475 475
 						//ok, this item would conflict if inserted. Just update the item that it conflicts with.
476 476
 						$what_to_do = self::do_update;
477 477
 						//and if this model has a primary key, remember its mapping
478
-						if($model->has_primary_key_field()){
478
+						if ($model->has_primary_key_field()) {
479 479
 							$old_db_to_new_db_mapping[$model_name][$id_in_csv] = $conflicting->ID();
480 480
 							$model_object_data[$model->primary_key_name()] = $conflicting->ID();
481
-						}else{
481
+						} else {
482 482
 							//we want to update this conflicting item, instead of inserting a conflicting item
483 483
 							//so we need to make sure they match entirely (its possible that they only conflicted on one field, but we need them to match on other fields
484 484
 							//for the WHERE conditions in the update). At the time of this comment, there were no models like this
485
-							foreach($model->get_combined_primary_key_fields() as $key_field){
485
+							foreach ($model->get_combined_primary_key_fields() as $key_field) {
486 486
 								$model_object_data[$key_field->get_name()] = $conflicting->get($key_field->get_name());
487 487
 							}
488 488
 						}
489 489
 					}
490 490
 				}
491
-				if( $what_to_do == self::do_insert ) {
492
-					$old_db_to_new_db_mapping = $this->_insert_from_data_array( $id_in_csv, $model_object_data, $model, $old_db_to_new_db_mapping );
493
-				}elseif( $what_to_do == self::do_update ) {
494
-					if( $models_to_update === null || in_array( $model_name_in_csv_data, $models_to_update ) ){
495
-						$old_db_to_new_db_mapping = $this->_update_from_data_array( $id_in_csv, $model_object_data, $model, $old_db_to_new_db_mapping );
496
-					}else{
491
+				if ($what_to_do == self::do_insert) {
492
+					$old_db_to_new_db_mapping = $this->_insert_from_data_array($id_in_csv, $model_object_data, $model, $old_db_to_new_db_mapping);
493
+				}elseif ($what_to_do == self::do_update) {
494
+					if ($models_to_update === null || in_array($model_name_in_csv_data, $models_to_update)) {
495
+						$old_db_to_new_db_mapping = $this->_update_from_data_array($id_in_csv, $model_object_data, $model, $old_db_to_new_db_mapping);
496
+					} else {
497 497
 						//we would have updated this, but the export data indicated we ought not
498 498
 					}
499
-				}else{
499
+				} else {
500 500
 					throw new EE_Error(
501 501
 						sprintf(
502
-							__( 'Programming error. We should be inserting or updating, but instead we are being told to "%1$s", which is invalid', 'event_espresso' ),
502
+							__('Programming error. We should be inserting or updating, but instead we are being told to "%1$s", which is invalid', 'event_espresso'),
503 503
 							$what_to_do
504 504
 						)
505 505
 					);
@@ -523,20 +523,20 @@  discard block
 block discarded – undo
523 523
 	 * @param array $old_db_to_new_db_mapping by reference so it can be modified
524 524
 	 * @return string one of the constants on this class that starts with do_*
525 525
 	 */
526
-	protected function _decide_whether_to_insert_or_update_given_data_from_other_db( $id_in_csv, $model_object_data, $model, $old_db_to_new_db_mapping ) {
526
+	protected function _decide_whether_to_insert_or_update_given_data_from_other_db($id_in_csv, $model_object_data, $model, $old_db_to_new_db_mapping) {
527 527
 		$model_name = $model->get_this_model_name();
528 528
 		//if it's a site-to-site export-and-import, see if this model object's id
529 529
 		//in the old data that we know of
530 530
 		
531
-		if( isset($old_db_to_new_db_mapping[$model_name][$id_in_csv]) ){
532
-			$what_to_do =  self::do_update;
533
-		}else{
534
-			$what_to_do =  self::do_insert;
531
+		if (isset($old_db_to_new_db_mapping[$model_name][$id_in_csv])) {
532
+			$what_to_do = self::do_update;
533
+		} else {
534
+			$what_to_do = self::do_insert;
535 535
 		}
536 536
 		//consider any exceptions, usually where there are other uniqueness constraints
537
-		if( $model instanceof EEM_Question_Group ) {
538
-			if( isset( $model_object_data[ 'QSG_system' ] ) &&
539
-					$model_object_data[ 'QSG_system' ] ) {
537
+		if ($model instanceof EEM_Question_Group) {
538
+			if (isset($model_object_data['QSG_system']) &&
539
+					$model_object_data['QSG_system']) {
540 540
 				$what_to_do = self::do_update;
541 541
 			}
542 542
 		}
@@ -558,11 +558,11 @@  discard block
 block discarded – undo
558 558
 	  * @throws \EE_Error
559 559
 	  * @internal param \type $old_db_to_new_db_mapping
560 560
 	  */
561
-	protected function _decide_whether_to_insert_or_update_given_data_from_same_db( $id_in_csv, $model_object_data, $model ) {
561
+	protected function _decide_whether_to_insert_or_update_given_data_from_same_db($id_in_csv, $model_object_data, $model) {
562 562
 		//in this case, check if this thing ACTUALLY exists in the database
563
-		if( $model->get_one_conflicting( $model_object_data ) ){
563
+		if ($model->get_one_conflicting($model_object_data)) {
564 564
 			return self::do_update;
565
-		}else{
565
+		} else {
566 566
 			return self::do_insert;
567 567
 		}
568 568
 	}
@@ -583,32 +583,32 @@  discard block
 block discarded – undo
583 583
 	 *
584 584
 *@return array updated model object data with temp IDs removed
585 585
 	 */
586
-	protected function _replace_temp_ids_with_mappings( $model_object_data, $model, $old_db_to_new_db_mapping, $export_from_site_a_to_b ) {
586
+	protected function _replace_temp_ids_with_mappings($model_object_data, $model, $old_db_to_new_db_mapping, $export_from_site_a_to_b) {
587 587
 		//if this model object's primary key is in the mapping, replace it
588
-		if( $model->has_primary_key_field() &&
588
+		if ($model->has_primary_key_field() &&
589 589
 				$model->get_primary_key_field()->is_auto_increment() &&
590
-				isset( $old_db_to_new_db_mapping[ $model->get_this_model_name() ] ) &&
591
-				isset( $old_db_to_new_db_mapping[ $model->get_this_model_name() ][ $model_object_data[ $model->primary_key_name() ] ] ) ) {
592
-			$model_object_data[ $model->primary_key_name() ] = $old_db_to_new_db_mapping[ $model->get_this_model_name() ][ $model_object_data[ $model->primary_key_name() ] ];
590
+				isset($old_db_to_new_db_mapping[$model->get_this_model_name()]) &&
591
+				isset($old_db_to_new_db_mapping[$model->get_this_model_name()][$model_object_data[$model->primary_key_name()]])) {
592
+			$model_object_data[$model->primary_key_name()] = $old_db_to_new_db_mapping[$model->get_this_model_name()][$model_object_data[$model->primary_key_name()]];
593 593
 		}
594 594
 
595
-		try{
595
+		try {
596 596
 			$model_name_field = $model->get_field_containing_related_model_name();
597 597
 			//$models_pointed_to_by_model_name_field = $model_name_field->get_model_names_pointed_to();
598
-		}catch( EE_Error $e ){
598
+		} catch (EE_Error $e) {
599 599
 			$model_name_field = NULL;
600 600
 			//$models_pointed_to_by_model_name_field = array();
601 601
 		}
602
-		foreach( $model->field_settings( true )  as $field_obj ){
603
-			if( $field_obj instanceof EE_Foreign_Key_Int_Field ) {
602
+		foreach ($model->field_settings(true)  as $field_obj) {
603
+			if ($field_obj instanceof EE_Foreign_Key_Int_Field) {
604 604
 				$models_pointed_to = $field_obj->get_model_names_pointed_to();
605
-				foreach( $models_pointed_to as $model_pointed_to_by_fk ) {
605
+				foreach ($models_pointed_to as $model_pointed_to_by_fk) {
606 606
 
607
-					if( $model_name_field ){
608
-						$value_of_model_name_field = $model_object_data[ $model_name_field->get_name() ];
609
-						if( $value_of_model_name_field == $model_pointed_to_by_fk ) {
610
-							$model_object_data[ $field_obj->get_name() ] = $this->_find_mapping_in(
611
-								$model_object_data[ $field_obj->get_name() ],
607
+					if ($model_name_field) {
608
+						$value_of_model_name_field = $model_object_data[$model_name_field->get_name()];
609
+						if ($value_of_model_name_field == $model_pointed_to_by_fk) {
610
+							$model_object_data[$field_obj->get_name()] = $this->_find_mapping_in(
611
+								$model_object_data[$field_obj->get_name()],
612 612
 								$model_pointed_to_by_fk,
613 613
 								$old_db_to_new_db_mapping,
614 614
 								$export_from_site_a_to_b
@@ -616,9 +616,9 @@  discard block
 block discarded – undo
616 616
 							//once we've found a mapping for this field no need to continue
617 617
 							break;
618 618
 						}
619
-					}else{
620
-						$model_object_data[ $field_obj->get_name() ] = $this->_find_mapping_in(
621
-							$model_object_data[ $field_obj->get_name() ],
619
+					} else {
620
+						$model_object_data[$field_obj->get_name()] = $this->_find_mapping_in(
621
+							$model_object_data[$field_obj->get_name()],
622 622
 							$model_pointed_to_by_fk,
623 623
 							$old_db_to_new_db_mapping,
624 624
 							$export_from_site_a_to_b
@@ -627,7 +627,7 @@  discard block
 block discarded – undo
627 627
 						break;
628 628
 					}
629 629
 				}
630
-			}else{
630
+			} else {
631 631
 				//it's a string foreign key (which we leave alone, because those are things
632 632
 				//like country names, which we'd really rather not make 2 USAs etc (we'd actually
633 633
 				//prefer to just update one)
@@ -635,7 +635,7 @@  discard block
 block discarded – undo
635 635
 			}
636 636
 		}
637 637
 		//allow for any other value replacement
638
-		return apply_filters( 'FHEE__EE_Import___replace_temp_ids_with_mappings__model_object_data__end', $model_object_data, $model );
638
+		return apply_filters('FHEE__EE_Import___replace_temp_ids_with_mappings__model_object_data__end', $model_object_data, $model);
639 639
 	}
640 640
         
641 641
         /**
@@ -644,31 +644,31 @@  discard block
 block discarded – undo
644 644
          * @param EEM_Base $model
645 645
          * @param boolean $export_from_site_a_to_b
646 646
          */
647
-        protected function _prepare_data_for_use_in_db( $original_data_row, $model, $export_from_site_a_to_b ) {
647
+        protected function _prepare_data_for_use_in_db($original_data_row, $model, $export_from_site_a_to_b) {
648 648
             $altered_data_row = $original_data_row;
649
-            switch( $model->get_this_model_name() ) {
649
+            switch ($model->get_this_model_name()) {
650 650
                 case 'Message_Template_Group':
651
-                    if( isset( $original_data_row[ 'MTP_is_global' ] ) && 
652
-                            intval( $original_data_row[ 'MTP_is_global' ] ) == 1 && 
653
-                            apply_filters( 'FHEE__EE_Import___prepare_data_for_use_in_db__tweak_global_message_template_groups', true, $original_data_row, $model, $export_from_site_a_to_b ) &&
654
-                            ! $export_from_site_a_to_b ) {
655
-                        $altered_data_row[ 'MTP_is_global' ] = 0;
656
-                        $message_type = isset( $altered_data_row[ 'MTP_message_type' ] ) ? $altered_data_row[ 'MTP_message_type' ] : __( 'Unknown', 'event_espresso' );
657
-                        $altered_data_row[ 'MTP_name' ] = sprintf( __( 'Global %1$s message template from %2$s', 'event_espresso'), $message_type, $this->_csv_import_metadata_row[ 'site_url' ] );
651
+                    if (isset($original_data_row['MTP_is_global']) && 
652
+                            intval($original_data_row['MTP_is_global']) == 1 && 
653
+                            apply_filters('FHEE__EE_Import___prepare_data_for_use_in_db__tweak_global_message_template_groups', true, $original_data_row, $model, $export_from_site_a_to_b) &&
654
+                            ! $export_from_site_a_to_b) {
655
+                        $altered_data_row['MTP_is_global'] = 0;
656
+                        $message_type = isset($altered_data_row['MTP_message_type']) ? $altered_data_row['MTP_message_type'] : __('Unknown', 'event_espresso');
657
+                        $altered_data_row['MTP_name'] = sprintf(__('Global %1$s message template from %2$s', 'event_espresso'), $message_type, $this->_csv_import_metadata_row['site_url']);
658 658
                         global $current_user;
659
-                        $altered_data_row[ 'MTP_description' ] = sprintf( __( 'Imported at %1$s by user %2$s', 'event_espresso' ), current_time( 'mysql' ), $current_user->user_nicename );
659
+                        $altered_data_row['MTP_description'] = sprintf(__('Imported at %1$s by user %2$s', 'event_espresso'), current_time('mysql'), $current_user->user_nicename);
660 660
                     }
661 661
             }
662
-			foreach( $model->field_settings() as $field_name => $field_obj ) {
663
-				if( $field_obj instanceof EE_Datetime_Field ) {
664
-					$altered_data_row[ $field_name ] = $model->convert_datetime_for_query( 
662
+			foreach ($model->field_settings() as $field_name => $field_obj) {
663
+				if ($field_obj instanceof EE_Datetime_Field) {
664
+					$altered_data_row[$field_name] = $model->convert_datetime_for_query( 
665 665
 							$field_name, 
666
-							$original_data_row[ $field_name ], 
667
-							apply_filters( 'FHEE__EE_Import___prepare_data_for_use_in_db__datetime_format_in_csv', 'Y-m-d H:i:s' ),
668
-							isset( $this->_csv_import_metadata_row[ 'timezone' ] ) ? $this->_csv_import_metadata_row[ 'timezone' ] : '' );
666
+							$original_data_row[$field_name], 
667
+							apply_filters('FHEE__EE_Import___prepare_data_for_use_in_db__datetime_format_in_csv', 'Y-m-d H:i:s'),
668
+							isset($this->_csv_import_metadata_row['timezone']) ? $this->_csv_import_metadata_row['timezone'] : '' );
669 669
 				}
670 670
 			}
671
-            return apply_filters( 'FHEE__EE_Import___prepare_data_for_use_in_db__return', $altered_data_row, $original_data_row, $model, $this );
671
+            return apply_filters('FHEE__EE_Import___prepare_data_for_use_in_db__return', $altered_data_row, $original_data_row, $model, $this);
672 672
         }
673 673
 
674 674
 	/**
@@ -679,14 +679,14 @@  discard block
 block discarded – undo
679 679
 	 * @param EEM_Base $model
680 680
 	 * @return array new model object data
681 681
 	 */
682
-	public function handle_split_term_ids( $model_object_data, $model ){
683
-		if( $model instanceof EEM_Term_Taxonomy &&
684
-				isset( $model_object_data['term_id'] ) &&
685
-				isset( $model_object_data[ 'taxonomy' ]) &&
686
-				apply_filters( 'FHEE__EE_Import__handle_split_term_ids__function_exists', function_exists( 'wp_get_split_term' ), $model_object_data ) ) {
687
-			$new_term_id = wp_get_split_term( $model_object_data[ 'term_id' ], $model_object_data[ 'taxonomy' ] );
688
-			if( $new_term_id ){
689
-				$model_object_data[ 'term_id' ] = $new_term_id;
682
+	public function handle_split_term_ids($model_object_data, $model) {
683
+		if ($model instanceof EEM_Term_Taxonomy &&
684
+				isset($model_object_data['term_id']) &&
685
+				isset($model_object_data['taxonomy']) &&
686
+				apply_filters('FHEE__EE_Import__handle_split_term_ids__function_exists', function_exists('wp_get_split_term'), $model_object_data)) {
687
+			$new_term_id = wp_get_split_term($model_object_data['term_id'], $model_object_data['taxonomy']);
688
+			if ($new_term_id) {
689
+				$model_object_data['term_id'] = $new_term_id;
690 690
 			}
691 691
 		}
692 692
 		return $model_object_data;
@@ -700,17 +700,17 @@  discard block
 block discarded – undo
700 700
 	 * @param bool $export_from_site_a_to_b
701 701
 	 * @return int
702 702
 	 */
703
-	protected function _find_mapping_in( $object_id, $model_name, $old_db_to_new_db_mapping, $export_from_site_a_to_b) {
704
-		if(	isset( $old_db_to_new_db_mapping[ $model_name ][ $object_id ] ) ){
705
-			return $old_db_to_new_db_mapping[ $model_name ][ $object_id ];
706
-		}elseif( $object_id == '0' || $object_id == '' ) {
703
+	protected function _find_mapping_in($object_id, $model_name, $old_db_to_new_db_mapping, $export_from_site_a_to_b) {
704
+		if (isset($old_db_to_new_db_mapping[$model_name][$object_id])) {
705
+			return $old_db_to_new_db_mapping[$model_name][$object_id];
706
+		}elseif ($object_id == '0' || $object_id == '') {
707 707
 			//leave as-is
708 708
 			return $object_id;
709
-		}elseif( $export_from_site_a_to_b ){
709
+		}elseif ($export_from_site_a_to_b) {
710 710
 			//we couldn't find a mapping for this, and it's from a different site,
711 711
 			//so blank it out
712 712
 			return null;
713
-		}elseif( ! $export_from_site_a_to_b ) {
713
+		}elseif ( ! $export_from_site_a_to_b) {
714 714
 			//we couldn't find a mapping for this, but it's from this DB anyway
715 715
 			//so let's just leave it as-is
716 716
 			return $object_id;
@@ -726,19 +726,19 @@  discard block
 block discarded – undo
726 726
 	 * @param array $old_db_to_new_db_mapping
727 727
 	 * @return array updated $old_db_to_new_db_mapping
728 728
 	 */
729
-	protected function _insert_from_data_array( $id_in_csv, $model_object_data, $model, $old_db_to_new_db_mapping ) {
729
+	protected function _insert_from_data_array($id_in_csv, $model_object_data, $model, $old_db_to_new_db_mapping) {
730 730
 		//remove the primary key, if there is one (we don't want it for inserts OR updates)
731 731
 		//we'll put it back in if we need it
732
-		if($model->has_primary_key_field() && $model->get_primary_key_field()->is_auto_increment()){
732
+		if ($model->has_primary_key_field() && $model->get_primary_key_field()->is_auto_increment()) {
733 733
 			$effective_id = $model_object_data[$model->primary_key_name()];
734 734
 			unset($model_object_data[$model->primary_key_name()]);
735
-		}else{
736
-			$effective_id = $model->get_index_primary_key_string( $model_object_data );
735
+		} else {
736
+			$effective_id = $model->get_index_primary_key_string($model_object_data);
737 737
 		}
738 738
 		//the model takes care of validating the CSV's input
739
-		try{
739
+		try {
740 740
 			$new_id = $model->insert($model_object_data);
741
-			if( $new_id ){
741
+			if ($new_id) {
742 742
 				$old_db_to_new_db_mapping[$model->get_this_model_name()][$id_in_csv] = $new_id;
743 743
 				$this->_add_insert_success(
744 744
 					sprintf(
@@ -747,15 +747,15 @@  discard block
 block discarded – undo
747 747
 						$new_id
748 748
 					)
749 749
 				);
750
-			}else{
750
+			} else {
751 751
 				//put the ID used back in there for the error message
752
-				if($model->has_primary_key_field()){
752
+				if ($model->has_primary_key_field()) {
753 753
 					$model_object_data[$model->primary_key_name()] = $effective_id;
754 754
 				}
755 755
 				global $wpdb;
756 756
 				$this->_add_insert_error(
757 757
 					sprintf(
758
-						__('Could not insert new %1$s with ID in file %2$s because %3$s', "event_espresso" ),
758
+						__('Could not insert new %1$s with ID in file %2$s because %3$s', "event_espresso"),
759 759
 						$model->get_this_model_name(),
760 760
 						$id_in_csv,
761 761
 						$wpdb->last_error
@@ -763,8 +763,8 @@  discard block
 block discarded – undo
763 763
 					__FILE__, __FUNCTION__, __LINE__
764 764
 				);
765 765
 			}
766
-		}catch(EE_Error $e){
767
-			if($model->has_primary_key_field()){
766
+		} catch (EE_Error $e) {
767
+			if ($model->has_primary_key_field()) {
768 768
 				$model_object_data[$model->primary_key_name()] = $effective_id;
769 769
 			}
770 770
 			$this->_add_insert_error(
@@ -788,29 +788,29 @@  discard block
 block discarded – undo
788 788
 	 * @param array $old_db_to_new_db_mapping
789 789
 	 * @return array updated $old_db_to_new_db_mapping
790 790
 	 */
791
-	protected function _update_from_data_array( $id_in_csv,  $original_model_object_data, $model, $old_db_to_new_db_mapping ) {
792
-		try{
791
+	protected function _update_from_data_array($id_in_csv, $original_model_object_data, $model, $old_db_to_new_db_mapping) {
792
+		try {
793 793
 			//let's keep two copies of the model object data:
794 794
 			//one for performing an update, one for everything else
795 795
 			$model_object_data_for_update = $original_model_object_data;
796
-			if ( $model->has_primary_key_field() ) {
796
+			if ($model->has_primary_key_field()) {
797 797
 				//wait- will this update cause a conflict with other data?
798
-				$conflicting = $model->get_one_conflicting( $original_model_object_data, false );
799
-				if ( $conflicting ) {
798
+				$conflicting = $model->get_one_conflicting($original_model_object_data, false);
799
+				if ($conflicting) {
800 800
 					//if so, just update the thing it would conflict with, dont cause a conflict
801 801
 					$pk_value = $conflicting->ID();
802 802
 				} else {
803
-					$pk_value = $model_object_data_for_update[ $model->primary_key_name() ];
803
+					$pk_value = $model_object_data_for_update[$model->primary_key_name()];
804 804
 				}
805
-				$conditions = array( $model->primary_key_name() => $pk_value );
805
+				$conditions = array($model->primary_key_name() => $pk_value);
806 806
 				//remove the primary key because we shouldn't use it for updating
807
-				unset( $model_object_data_for_update[ $model->primary_key_name() ] );
808
-			} elseif ( $model->get_combined_primary_key_fields() > 1 ) {
807
+				unset($model_object_data_for_update[$model->primary_key_name()]);
808
+			} elseif ($model->get_combined_primary_key_fields() > 1) {
809 809
 				$conditions = array();
810
-				foreach ( $model->get_combined_primary_key_fields() as $key_field ) {
811
-					$conditions[ $key_field->get_name() ] = $model_object_data_for_update[ $key_field->get_name() ];
810
+				foreach ($model->get_combined_primary_key_fields() as $key_field) {
811
+					$conditions[$key_field->get_name()] = $model_object_data_for_update[$key_field->get_name()];
812 812
 				}
813
-				$pk_value = $model->get_index_primary_key_string( $original_model_object_data );
813
+				$pk_value = $model->get_index_primary_key_string($original_model_object_data);
814 814
 			} else {
815 815
 				//this should just throw an exception, explaining that we dont have a primary key (or a combined key)
816 816
 				$model->primary_key_name();
@@ -821,8 +821,8 @@  discard block
 block discarded – undo
821 821
 				$conditions,
822 822
 				'default_where_conditions' => 'minimum'
823 823
 			);
824
-			$success = $model->update($model_object_data_for_update,$query_params);
825
-			if($success){
824
+			$success = $model->update($model_object_data_for_update, $query_params);
825
+			if ($success) {
826 826
 				$this->_add_update_success(
827 827
 					sprintf(
828 828
 						__('Successfully updated %1$s (with ID %2$s).', "event_espresso"),
@@ -834,10 +834,10 @@  discard block
 block discarded – undo
834 834
 				//because if we were going to insert something but it was going to conflict
835 835
 				//we would have last-minute decided to update. So we'd like to know what we updated
836 836
 				//and so we record what record ended up being updated using the mapping
837
-				$old_db_to_new_db_mapping[ $model->get_this_model_name() ][ $id_in_csv ] = $pk_value;
838
-			}else{
837
+				$old_db_to_new_db_mapping[$model->get_this_model_name()][$id_in_csv] = $pk_value;
838
+			} else {
839 839
 				$matched_items = $model->get_all($query_params);
840
-				if( ! $matched_items){
840
+				if ( ! $matched_items) {
841 841
 					//no items were matched (so we shouldn't have updated)... but then we should have inserted? what the heck?
842 842
 					$this->_add_update_error(
843 843
 						sprintf(
@@ -852,15 +852,15 @@  discard block
 block discarded – undo
852 852
 					//wasn't an error, just didn't need updating
853 853
 				}
854 854
 			}
855
-		}catch(EE_Error $e){
855
+		} catch (EE_Error $e) {
856 856
 			$basic_message = sprintf(
857 857
 				__('Could not update %1$s with ID %2$s because %3$s', "event_espresso"),
858 858
 				$model->get_this_model_name(),
859 859
 				$pk_value,
860 860
 				$e->getMessage()
861 861
 			);
862
-			$debug_message = $basic_message . ' Stack trace: ' . $e->getTraceAsString();
863
-			$this->_add_general_error( "$basic_message | $debug_message", __FILE__, __FUNCTION__, __LINE__ );
862
+			$debug_message = $basic_message.' Stack trace: '.$e->getTraceAsString();
863
+			$this->_add_general_error("$basic_message | $debug_message", __FILE__, __FUNCTION__, __LINE__);
864 864
 		}
865 865
 		return $old_db_to_new_db_mapping;
866 866
 	}
@@ -869,52 +869,52 @@  discard block
 block discarded – undo
869 869
 	 * Gets the number of inserts performed since importer was instantiated or reset
870 870
 	 * @return int
871 871
 	 */
872
-	public function get_total_inserts(){
873
-		return count( $this->_inserts );
872
+	public function get_total_inserts() {
873
+		return count($this->_inserts);
874 874
 	}
875 875
 	/**
876 876
 	 *  Gets the number of insert errors since importer was instantiated or reset
877 877
 	 * @return int
878 878
 	 */
879
-	public function get_total_insert_errors(){
880
-		return count( $this->_insert_errors );
879
+	public function get_total_insert_errors() {
880
+		return count($this->_insert_errors);
881 881
 	}
882 882
 	/**
883 883
 	 *  Gets the number of updates performed since importer was instantiated or reset
884 884
 	 * @return int
885 885
 	 */
886
-	public function get_total_updates(){
887
-		return count( $this->_updates );
886
+	public function get_total_updates() {
887
+		return count($this->_updates);
888 888
 	}
889 889
 	/**
890 890
 	 *  Gets the number of update errors since importer was instantiated or reset
891 891
 	 * @return int
892 892
 	 */
893
-	public function get_total_update_errors(){
894
-		return count( $this->_update_errors );
893
+	public function get_total_update_errors() {
894
+		return count($this->_update_errors);
895 895
 	}
896 896
 
897 897
 	/**
898 898
 	 * Gets count of general errors during import
899 899
 	 * @return int
900 900
 	 */
901
-	public function get_total_general_errors(){
902
-		return count( $this->_general_errors );
901
+	public function get_total_general_errors() {
902
+		return count($this->_general_errors);
903 903
 	}
904
-	protected function _add_update_success( $message ){
904
+	protected function _add_update_success($message) {
905 905
 		$this->_updates[] = $message;
906 906
 	}
907
-	protected function _add_insert_success( $message ){
907
+	protected function _add_insert_success($message) {
908 908
 		$this->_inserts[] = $message;
909 909
 	}
910
-	protected function _add_update_error( $message, $file, $function, $line ){
911
-		$this->_update_errors[] = array( $message, $file, $function, $line );
910
+	protected function _add_update_error($message, $file, $function, $line) {
911
+		$this->_update_errors[] = array($message, $file, $function, $line);
912 912
 	}
913
-	protected function _add_insert_error( $message, $file, $function, $line ){
914
-		$this->_insert_errors[] = array( $message, $file, $function, $line );
913
+	protected function _add_insert_error($message, $file, $function, $line) {
914
+		$this->_insert_errors[] = array($message, $file, $function, $line);
915 915
 	}
916
-	protected function _add_general_error( $message, $file, $function, $line ){
917
-		$this->_general_errors[] = array( $message, $file, $function, $line );
916
+	protected function _add_general_error($message, $file, $function, $line) {
917
+		$this->_general_errors[] = array($message, $file, $function, $line);
918 918
 	}
919 919
 
920 920
 	/**
@@ -924,7 +924,7 @@  discard block
 block discarded – undo
924 924
 	 * happened.
925 925
 	 * @return array
926 926
 	 */
927
-	public function get_update_errors(){
927
+	public function get_update_errors() {
928 928
 		return $this->_update_errors;
929 929
 	}
930 930
 	/**
@@ -934,7 +934,7 @@  discard block
 block discarded – undo
934 934
 	 * happened.
935 935
 	 * @return array
936 936
 	 */
937
-	public function get_insert_errors(){
937
+	public function get_insert_errors() {
938 938
 		return $this->_insert_errors;
939 939
 	}
940 940
 	/**
@@ -944,21 +944,21 @@  discard block
 block discarded – undo
944 944
 	 * happened.
945 945
 	 * @return array
946 946
 	 */
947
-	public function get_general_errors(){
947
+	public function get_general_errors() {
948 948
 		return $this->_general_errors;
949 949
 	}
950 950
 	/**
951 951
 	 * Gets a simple array where each item in the array is a string describing what was inserted
952 952
 	 * @return array
953 953
 	 */
954
-	public function get_inserts(){
954
+	public function get_inserts() {
955 955
 		return $this->_inserts;
956 956
 	}
957 957
 	/**
958 958
 	 * Gets a simple array where each item in the array is a string describing what was updated
959 959
 	 * @return array
960 960
 	 */
961
-	public function get_updates(){
961
+	public function get_updates() {
962 962
 		return $this->_updates;
963 963
 	}
964 964
 	/**
@@ -966,40 +966,40 @@  discard block
 block discarded – undo
966 966
 	 * normal EE_Error success and error messages.
967 967
 	 * @return boolean there were no errors and we successfully did something
968 968
 	 */
969
-	public function report_successes_and_errors(){
969
+	public function report_successes_and_errors() {
970 970
 		$success = false;
971 971
 		$error = false;
972
-		if ( $this->get_total_updates() ) {
973
-			EE_Error::add_success( sprintf(__("%s existing records in the database were updated.", "event_espresso"),$this->get_total_updates()));
972
+		if ($this->get_total_updates()) {
973
+			EE_Error::add_success(sprintf(__("%s existing records in the database were updated.", "event_espresso"), $this->get_total_updates()));
974 974
 			$success = true;
975 975
 		}
976
-		if ( $this->get_total_inserts() ) {
977
-			EE_Error::add_success(sprintf(__("%s new records were added to the database.", "event_espresso"),$this->get_total_inserts()));
976
+		if ($this->get_total_inserts()) {
977
+			EE_Error::add_success(sprintf(__("%s new records were added to the database.", "event_espresso"), $this->get_total_inserts()));
978 978
 			$success = true;
979 979
 		}
980 980
 
981
-		if ( $this->get_total_update_errors()) {
982
-			EE_Error::add_error(sprintf(__("'One or more errors occurred, and a total of %s existing records in the database were <strong>not</strong> updated.'", "event_espresso"),$this->get_total_update_errors() ), __FILE__, __FUNCTION__, __LINE__ );
981
+		if ($this->get_total_update_errors()) {
982
+			EE_Error::add_error(sprintf(__("'One or more errors occurred, and a total of %s existing records in the database were <strong>not</strong> updated.'", "event_espresso"), $this->get_total_update_errors()), __FILE__, __FUNCTION__, __LINE__);
983 983
 			$error = true;
984 984
 		}
985
-		if ( $this->get_total_insert_errors() ) {
986
-			EE_Error::add_error(sprintf(__("One or more errors occurred, and a total of %s new records were <strong>not</strong> added to the database.'", "event_espresso"),$this->get_total_insert_errors() ), __FILE__, __FUNCTION__, __LINE__ );
985
+		if ($this->get_total_insert_errors()) {
986
+			EE_Error::add_error(sprintf(__("One or more errors occurred, and a total of %s new records were <strong>not</strong> added to the database.'", "event_espresso"), $this->get_total_insert_errors()), __FILE__, __FUNCTION__, __LINE__);
987 987
 			$error = true;
988 988
 		}
989
-		foreach( $this->_general_errors as $message_data ){
990
-			EE_Error::add_error( $message_data[0], $message_data[1], $message_data[2], $message_data[3]);
989
+		foreach ($this->_general_errors as $message_data) {
990
+			EE_Error::add_error($message_data[0], $message_data[1], $message_data[2], $message_data[3]);
991 991
 		}
992
-		foreach( $this->_inserts as $insert ){
993
-			EE_Error::add_success( $insert );
992
+		foreach ($this->_inserts as $insert) {
993
+			EE_Error::add_success($insert);
994 994
 		}
995
-		foreach( $this->_updates as $update ){
996
-			EE_Error::add_success( $update );
995
+		foreach ($this->_updates as $update) {
996
+			EE_Error::add_success($update);
997 997
 		}
998
-		foreach( $this->_insert_errors as $message_data ){
999
-			EE_Error::add_error( $message_data[0], $message_data[1], $message_data[2], $message_data[3]);
998
+		foreach ($this->_insert_errors as $message_data) {
999
+			EE_Error::add_error($message_data[0], $message_data[1], $message_data[2], $message_data[3]);
1000 1000
 		}
1001
-		foreach( $this->_update_errors as $message_data ){
1002
-			EE_Error::add_error( $message_data[0], $message_data[1], $message_data[2], $message_data[3]);
1001
+		foreach ($this->_update_errors as $message_data) {
1002
+			EE_Error::add_error($message_data[0], $message_data[1], $message_data[2], $message_data[3]);
1003 1003
 		}
1004 1004
 		return $success && ! $error;
1005 1005
 	}
Please login to merge, or discard this patch.
core/db_models/EEM_Base.model.php 1 patch
Spacing   +947 added lines, -947 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
@@ -228,7 +228,7 @@  discard block
 block discarded – undo
228 228
 	 * Flag indicating whether this model has a primary key or not
229 229
 	 * @var boolean
230 230
 	 */
231
-	protected $_has_primary_key_field=null;
231
+	protected $_has_primary_key_field = null;
232 232
 
233 233
 	/**
234 234
 	 * Whether or not this model is based off a table in WP core only (CPTs should set
@@ -283,19 +283,19 @@  discard block
 block discarded – undo
283 283
 	 * operators that work like 'BETWEEN'.  Typically used for datetime calculations, i.e. "BETWEEN '12-1-2011' AND '12-31-2012'"
284 284
 	 * @var array
285 285
 	 */
286
-	protected $_between_style_operators = array( 'BETWEEN' );
286
+	protected $_between_style_operators = array('BETWEEN');
287 287
 
288 288
 	/**
289 289
 	 * operators that are used for handling NUll and !NULL queries.  Typically used for when checking if a row exists on a join table.
290 290
 	 * @var array
291 291
 	 */
292
-	protected $_null_style_operators = array( 'IS NOT NULL', 'IS NULL');
292
+	protected $_null_style_operators = array('IS NOT NULL', 'IS NULL');
293 293
 
294 294
 	/**
295 295
 	 * Allowed values for $query_params['order'] for ordering in queries
296 296
 	 * @var array
297 297
 	 */
298
-	protected $_allowed_order_values = array('asc','desc','ASC','DESC');
298
+	protected $_allowed_order_values = array('asc', 'desc', 'ASC', 'DESC');
299 299
 
300 300
 	/**
301 301
 	 * When these are keys in a WHERE or HAVING clause, they are handled much differently
@@ -309,13 +309,13 @@  discard block
 block discarded – undo
309 309
 	 * 'where', but 'where' clauses are so common that we thought we'd omit it
310 310
 	 * @var array
311 311
 	 */
312
-	private $_allowed_query_params = array(0, 'limit','order_by','group_by','having','force_join','order','on_join_limit','default_where_conditions', 'caps');
312
+	private $_allowed_query_params = array(0, 'limit', 'order_by', 'group_by', 'having', 'force_join', 'order', 'on_join_limit', 'default_where_conditions', 'caps');
313 313
 
314 314
 	/**
315 315
 	 * All the data types that can be used in $wpdb->prepare statements.
316 316
 	 * @var array
317 317
 	 */
318
-	private $_valid_wpdb_data_types = array('%d','%s','%f');
318
+	private $_valid_wpdb_data_types = array('%d', '%s', '%f');
319 319
 
320 320
 	/**
321 321
 	 * 	EE_Registry Object
@@ -348,17 +348,17 @@  discard block
 block discarded – undo
348 348
 	/**
349 349
 	 * constant used to show EEM_Base has not yet verified the db on this http request
350 350
 	 */
351
-	const db_verified_none 		= 0;
351
+	const db_verified_none = 0;
352 352
 	/**
353 353
 	 * constant used to show EEM_Base has verified the EE core db on this http request,
354 354
 	 * but not the addons' dbs
355 355
 	 */
356
-	const db_verified_core 		= 1;
356
+	const db_verified_core = 1;
357 357
 	/**
358 358
 	 * constant used to show EEM_Base has verified the addons' dbs (and implicitly
359 359
 	 * the EE core db too)
360 360
 	 */
361
-	const db_verified_addons 	= 2;
361
+	const db_verified_addons = 2;
362 362
 
363 363
 	/**
364 364
 	 * indicates whether an EEM_Base child has already re-verified the DB
@@ -395,13 +395,13 @@  discard block
 block discarded – undo
395 395
 	 * @param null $timezone
396 396
 	 * @throws \EE_Error
397 397
 	 */
398
-	protected function __construct( $timezone = NULL ){
398
+	protected function __construct($timezone = NULL) {
399 399
 		// check that the model has not been loaded too soon
400
-		if ( ! did_action( 'AHEE__EE_System__load_espresso_addons' )) {
401
-			throw new EE_Error (
400
+		if ( ! did_action('AHEE__EE_System__load_espresso_addons')) {
401
+			throw new EE_Error(
402 402
 				sprintf(
403
-					__( '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' ),
404
-					get_class( $this )
403
+					__('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'),
404
+					get_class($this)
405 405
 				)
406 406
 			);
407 407
 		}
@@ -411,11 +411,11 @@  discard block
 block discarded – undo
411 411
 		 * just use EE_Register_Model_Extension
412 412
 		 * @var EE_Table_Base[] $_tables
413 413
 		 */
414
-		$this->_tables = apply_filters( 'FHEE__'.get_class($this).'__construct__tables', $this->_tables );
415
-		foreach($this->_tables as $table_alias => $table_obj){
414
+		$this->_tables = apply_filters('FHEE__'.get_class($this).'__construct__tables', $this->_tables);
415
+		foreach ($this->_tables as $table_alias => $table_obj) {
416 416
 			/** @var $table_obj EE_Table_Base */
417 417
 			$table_obj->_construct_finalize_with_alias($table_alias);
418
-			if( $table_obj instanceof EE_Secondary_Table ){
418
+			if ($table_obj instanceof EE_Secondary_Table) {
419 419
 				/** @var $table_obj EE_Secondary_Table */
420 420
 				$table_obj->_construct_finalize_set_table_to_join_with($this->_get_main_table());
421 421
 			}
@@ -425,48 +425,48 @@  discard block
 block discarded – undo
425 425
 		 * EE_Register_Model_Extension
426 426
 		 * @param EE_Model_Field_Base[] $_fields
427 427
 		 */
428
-		$this->_fields = apply_filters('FHEE__'.get_class($this).'__construct__fields',$this->_fields);
429
-		foreach($this->_fields as $table_alias => $fields_for_table){
430
-			if ( ! array_key_exists( $table_alias, $this->_tables )){
431
-				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)));
428
+		$this->_fields = apply_filters('FHEE__'.get_class($this).'__construct__fields', $this->_fields);
429
+		foreach ($this->_fields as $table_alias => $fields_for_table) {
430
+			if ( ! array_key_exists($table_alias, $this->_tables)) {
431
+				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)));
432 432
 			}
433
-			foreach($fields_for_table as $field_name => $field_obj){
433
+			foreach ($fields_for_table as $field_name => $field_obj) {
434 434
 				/** @var $field_obj EE_Model_Field_Base | EE_Primary_Key_Field_Base */
435 435
 				//primary key field base has a slightly different _construct_finalize
436 436
 				/** @var $field_obj EE_Model_Field_Base */
437
-				$field_obj->_construct_finalize( $table_alias, $field_name, $this->get_this_model_name() );
437
+				$field_obj->_construct_finalize($table_alias, $field_name, $this->get_this_model_name());
438 438
 			}
439 439
 		}
440 440
 
441 441
 		// everything is related to Extra_Meta
442
-		if( get_class($this) != 'EEM_Extra_Meta'){
442
+		if (get_class($this) != 'EEM_Extra_Meta') {
443 443
 			//make extra meta related to everything, but don't block deleting things just
444 444
 			//because they have related extra meta info. For now just orphan those extra meta
445 445
 			//in the future we should automatically delete them
446
-			$this->_model_relations['Extra_Meta'] = new EE_Has_Many_Any_Relation( FALSE );
446
+			$this->_model_relations['Extra_Meta'] = new EE_Has_Many_Any_Relation(FALSE);
447 447
 		}
448 448
 		//and change logs
449
-		if( get_class( $this) !=  'EEM_Change_Log' ) {
450
-			$this->_model_relations[ 'Change_Log' ] = new EE_Has_Many_Any_Relation( FALSE );
449
+		if (get_class($this) != 'EEM_Change_Log') {
450
+			$this->_model_relations['Change_Log'] = new EE_Has_Many_Any_Relation(FALSE);
451 451
 		}
452 452
 		/**
453 453
 		 * Filters the list of relations on a model. It is best to NOT use this directly and instead just use
454 454
 		 * EE_Register_Model_Extension
455 455
 		 * @param EE_Model_Relation_Base[] $_model_relations
456 456
 		 */
457
-		$this->_model_relations = apply_filters('FHEE__'.get_class($this).'__construct__model_relations',$this->_model_relations);
458
-		foreach($this->_model_relations as $model_name => $relation_obj){
457
+		$this->_model_relations = apply_filters('FHEE__'.get_class($this).'__construct__model_relations', $this->_model_relations);
458
+		foreach ($this->_model_relations as $model_name => $relation_obj) {
459 459
 			/** @var $relation_obj EE_Model_Relation_Base */
460 460
 			$relation_obj->_construct_finalize_set_models($this->get_this_model_name(), $model_name);
461 461
 		}
462
-		foreach($this->_indexes as $index_name => $index_obj){
462
+		foreach ($this->_indexes as $index_name => $index_obj) {
463 463
 			/** @var $index_obj EE_Index */
464 464
 			$index_obj->_construct_finalize($index_name, $this->get_this_model_name());
465 465
 		}
466 466
 
467 467
 		$this->set_timezone($timezone);
468 468
 		//finalize default where condition strategy, or set default
469
-		if( ! $this->_default_where_conditions_strategy){
469
+		if ( ! $this->_default_where_conditions_strategy) {
470 470
 			//nothing was set during child constructor, so set default
471 471
 			$this->_default_where_conditions_strategy = new EE_Default_Where_Conditions();
472 472
 		}
@@ -474,15 +474,15 @@  discard block
 block discarded – undo
474 474
 
475 475
 		//if the cap slug hasn't been set, and we haven't set it to false on purpose
476 476
 		//to indicate to NOT set it, set it to the logical default
477
-		if( $this->_caps_slug === null ) {
478
-			EE_Registry::instance()->load_helper( 'Inflector' );
479
-			$this->_caps_slug = EEH_Inflector::pluralize_and_lower( $this->get_this_model_name() );
477
+		if ($this->_caps_slug === null) {
478
+			EE_Registry::instance()->load_helper('Inflector');
479
+			$this->_caps_slug = EEH_Inflector::pluralize_and_lower($this->get_this_model_name());
480 480
 		}
481 481
 		//initialize the standard cap restriction generators if none were specified by the child constructor
482
-		if( $this->_cap_restriction_generators !== false ){
483
-			foreach( $this->cap_contexts_to_cap_action_map() as $cap_context => $action ){
484
-				if( ! isset( $this->_cap_restriction_generators[ $cap_context ] ) ) {
485
-					$this->_cap_restriction_generators[ $cap_context ] = apply_filters(
482
+		if ($this->_cap_restriction_generators !== false) {
483
+			foreach ($this->cap_contexts_to_cap_action_map() as $cap_context => $action) {
484
+				if ( ! isset($this->_cap_restriction_generators[$cap_context])) {
485
+					$this->_cap_restriction_generators[$cap_context] = apply_filters(
486 486
 						'FHEE__EEM_Base___construct__standard_cap_restriction_generator',
487 487
 						new EE_Restriction_Generator_Protected(),
488 488
 						$cap_context,
@@ -492,23 +492,23 @@  discard block
 block discarded – undo
492 492
 			}
493 493
 		}
494 494
 		//if there are cap restriction generators, use them to make the default cap restrictions
495
-		if( $this->_cap_restriction_generators !== false ){
496
-			foreach( $this->_cap_restriction_generators as $context => $generator_object ) {
497
-				if( ! $generator_object ){
495
+		if ($this->_cap_restriction_generators !== false) {
496
+			foreach ($this->_cap_restriction_generators as $context => $generator_object) {
497
+				if ( ! $generator_object) {
498 498
 					continue;
499 499
 				}
500
-				if( ! $generator_object instanceof EE_Restriction_Generator_Base ){
500
+				if ( ! $generator_object instanceof EE_Restriction_Generator_Base) {
501 501
 					throw new EE_Error(
502 502
 						sprintf(
503
-							__( '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' ),
503
+							__('Index "%1$s" in the model %2$s\'s _cap_restriction_generators is not a child of EE_Restriction_Generator_Base. It should be that or NULL.', 'event_espresso'),
504 504
 							$context,
505 505
 							$this->get_this_model_name()
506 506
 						)
507 507
 					);
508 508
 				}
509
-				$action = $this->cap_action_for_context( $context );
510
-				if( ! $generator_object->construction_finalized() ){
511
-					$generator_object->_construct_finalize( $this, $action );
509
+				$action = $this->cap_action_for_context($context);
510
+				if ( ! $generator_object->construction_finalized()) {
511
+					$generator_object->_construct_finalize($this, $action);
512 512
 				}
513 513
 
514 514
 			}
@@ -522,11 +522,11 @@  discard block
 block discarded – undo
522 522
 	 * @param string $context one of EEM_Base::valid_cap_contexts()
523 523
 	 * @return EE_Default_Where_Conditions[]
524 524
 	 */
525
-	protected function _generate_cap_restrictions( $context ){
526
-		if( isset( $this->_cap_restriction_generators[ $context ] ) &&
527
-				$this->_cap_restriction_generators[ $context ] instanceof EE_Restriction_Generator_Base ) {
528
-			return $this->_cap_restriction_generators[ $context ]->generate_restrictions();
529
-		}else{
525
+	protected function _generate_cap_restrictions($context) {
526
+		if (isset($this->_cap_restriction_generators[$context]) &&
527
+				$this->_cap_restriction_generators[$context] instanceof EE_Restriction_Generator_Base) {
528
+			return $this->_cap_restriction_generators[$context]->generate_restrictions();
529
+		} else {
530 530
 			return array();
531 531
 		}
532 532
 }
@@ -539,16 +539,16 @@  discard block
 block discarded – undo
539 539
 	 *		@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)
540 540
 	 *		@return static (as in the concrete child class)
541 541
 	 */
542
-	public static function instance( $timezone = NULL ){
542
+	public static function instance($timezone = NULL) {
543 543
 
544 544
 		// check if instance of Espresso_model already exists
545 545
 		if ( ! static::$_instance instanceof static) {
546 546
 			// instantiate Espresso_model
547
-			static::$_instance = new static( $timezone );
547
+			static::$_instance = new static($timezone);
548 548
 		}
549 549
 
550 550
 		//we might have a timezone set, let set_timezone decide what to do with it
551
-		static::$_instance->set_timezone( $timezone );
551
+		static::$_instance->set_timezone($timezone);
552 552
 
553 553
 		// Espresso_model object
554 554
 		return static::$_instance;
@@ -561,11 +561,11 @@  discard block
 block discarded – undo
561 561
 	 * @param null | string $timezone
562 562
 	 * @return static
563 563
 	 */
564
-	public static function reset(  $timezone = NULL ){
565
-		if ( ! is_null( static::$_instance ) ) {
564
+	public static function reset($timezone = NULL) {
565
+		if ( ! is_null(static::$_instance)) {
566 566
 			static::$_instance = null;
567 567
 
568
-			return self::instance( $timezone );
568
+			return self::instance($timezone);
569 569
 		}
570 570
 		return null;
571 571
 	}
@@ -576,15 +576,15 @@  discard block
 block discarded – undo
576 576
 	 * @param  boolean $translated return localized strings or JUST the array.
577 577
 	 * @return array
578 578
 	 */
579
-	 public function status_array( $translated = FALSE ) {
580
-	 	if ( !array_key_exists('Status', $this->_model_relations ) )
579
+	 public function status_array($translated = FALSE) {
580
+	 	if ( ! array_key_exists('Status', $this->_model_relations))
581 581
 	 		return array();
582 582
 	 	$model_name = $this->get_this_model_name();
583
-	 	$status_type = str_replace(' ', '_', strtolower( str_replace('_', ' ', $model_name) ) );
584
-	 	$stati = EEM_Status::instance()->get_all(array(array('STS_type' => $status_type) ) );
583
+	 	$status_type = str_replace(' ', '_', strtolower(str_replace('_', ' ', $model_name)));
584
+	 	$stati = EEM_Status::instance()->get_all(array(array('STS_type' => $status_type)));
585 585
 	 	$status_array = array();
586
-	 	foreach ( $stati as $status ) {
587
-            $status_array[ $status->ID() ] = $status->get('STS_code');
586
+	 	foreach ($stati as $status) {
587
+            $status_array[$status->ID()] = $status->get('STS_code');
588 588
         }
589 589
         return $translated ? EEM_Status::instance()->localized_status($status_array, FALSE, 'sentence') : $status_array;
590 590
     }
@@ -767,7 +767,7 @@  discard block
 block discarded – undo
767 767
 	 *			'order_by'=>array('ANS_value'=>'ASC')
768 768
 	 *		));
769 769
 	 */
770
-	function get_all($query_params = array()){
770
+	function get_all($query_params = array()) {
771 771
 		return $this->_create_objects($this->_get_all_wpdb_results($query_params, ARRAY_A, NULL));
772 772
 	}
773 773
 
@@ -777,10 +777,10 @@  discard block
 block discarded – undo
777 777
 	 * @param array $query_params @see EEM_Base::get_all()
778 778
 	 * @return array like EEM_Base::get_all
779 779
 	 */
780
-	function alter_query_params_to_only_include_mine( $query_params = array() ) {
780
+	function alter_query_params_to_only_include_mine($query_params = array()) {
781 781
 		$wp_user_field_name = $this->wp_user_field_name();
782
-		if( $wp_user_field_name ){
783
-			$query_params[0][ $wp_user_field_name ] = get_current_user_id();
782
+		if ($wp_user_field_name) {
783
+			$query_params[0][$wp_user_field_name] = get_current_user_id();
784 784
 		}
785 785
 		return $query_params;
786 786
 	}
@@ -793,19 +793,19 @@  discard block
 block discarded – undo
793 793
 	 * foreign key to the WP_User table
794 794
 	 */
795 795
 	function wp_user_field_name() {
796
-		try{
797
-			if( ! empty( $this->_model_chain_to_wp_user ) ) {
798
-				$models_to_follow_to_wp_users = explode( '.', $this->_model_chain_to_wp_user );
799
-				$last_model_name = end( $models_to_follow_to_wp_users );
800
-				$model_with_fk_to_wp_users = EE_Registry::instance()->load_model( $last_model_name );
801
-				$model_chain_to_wp_user = $this->_model_chain_to_wp_user . '.';
802
-			}else{
796
+		try {
797
+			if ( ! empty($this->_model_chain_to_wp_user)) {
798
+				$models_to_follow_to_wp_users = explode('.', $this->_model_chain_to_wp_user);
799
+				$last_model_name = end($models_to_follow_to_wp_users);
800
+				$model_with_fk_to_wp_users = EE_Registry::instance()->load_model($last_model_name);
801
+				$model_chain_to_wp_user = $this->_model_chain_to_wp_user.'.';
802
+			} else {
803 803
 				$model_with_fk_to_wp_users = $this;
804 804
 				$model_chain_to_wp_user = '';
805 805
 			}
806
-			$wp_user_field = $model_with_fk_to_wp_users->get_foreign_key_to( 'WP_User' );
807
-			return $model_chain_to_wp_user . $wp_user_field->get_name();
808
-		}catch( EE_Error $e ) {
806
+			$wp_user_field = $model_with_fk_to_wp_users->get_foreign_key_to('WP_User');
807
+			return $model_chain_to_wp_user.$wp_user_field->get_name();
808
+		} catch (EE_Error $e) {
809 809
 			return false;
810 810
 		}
811 811
 	}
@@ -819,7 +819,7 @@  discard block
 block discarded – undo
819 819
 	 * (or transietly-related model)
820 820
 	 * @return string
821 821
 	 */
822
-	public function model_chain_to_wp_user(){
822
+	public function model_chain_to_wp_user() {
823 823
 		return $this->_model_chain_to_wp_user;
824 824
 	}
825 825
 
@@ -831,13 +831,13 @@  discard block
 block discarded – undo
831 831
 	 * @return boolean
832 832
 	 */
833 833
 	public function is_owned() {
834
-		if( $this->model_chain_to_wp_user() ){
834
+		if ($this->model_chain_to_wp_user()) {
835 835
 			return true;
836
-		}else{
837
-			try{
838
-				$this->get_foreign_key_to( 'WP_User' );
836
+		} else {
837
+			try {
838
+				$this->get_foreign_key_to('WP_User');
839 839
 				return true;
840
-			}catch( EE_Error $e ){
840
+			} catch (EE_Error $e) {
841 841
 				return false;
842 842
 			}
843 843
 		}
@@ -856,21 +856,21 @@  discard block
 block discarded – undo
856 856
 	 * and 1 is the data type. Eg, array('count'=>array('COUNT(REG_ID)','%d'))
857 857
 	 * @return array|stdClass[] like results of $wpdb->get_results($sql,OBJECT), (ie, output type is OBJECT)
858 858
 	 */
859
-	protected function  _get_all_wpdb_results($query_params = array(), $output = ARRAY_A, $columns_to_select = null){
859
+	protected function  _get_all_wpdb_results($query_params = array(), $output = ARRAY_A, $columns_to_select = null) {
860 860
 		//remember the custom selections, if any
861
-		if(is_array($columns_to_select)){
861
+		if (is_array($columns_to_select)) {
862 862
 			$this->_custom_selections = $columns_to_select;
863
-		}elseif(is_string($columns_to_select)){
863
+		}elseif (is_string($columns_to_select)) {
864 864
 			$this->_custom_selections = array($this->_custom_selections);
865
-		}else{
865
+		} else {
866 866
 			$this->_custom_selections = array();
867 867
 		}
868 868
 
869 869
 		$model_query_info = $this->_create_model_query_info_carrier($query_params);
870 870
 		$select_expressions = $columns_to_select ? $this->_construct_select_from_input($columns_to_select) : $this->_construct_default_select_sql($model_query_info);
871
-		$SQL ="SELECT $select_expressions ".$this->_construct_2nd_half_of_select_query($model_query_info);
871
+		$SQL = "SELECT $select_expressions ".$this->_construct_2nd_half_of_select_query($model_query_info);
872 872
 //		echo "sql:$SQL";
873
-		$results =  $this->_do_wpdb_query( 'get_results', array($SQL, $output ) );// $wpdb->get_results($SQL, $output);
873
+		$results = $this->_do_wpdb_query('get_results', array($SQL, $output)); // $wpdb->get_results($SQL, $output);
874 874
 		return $results;
875 875
 	}
876 876
 
@@ -887,7 +887,7 @@  discard block
 block discarded – undo
887 887
 	 * and 1 is the data type. Eg, array('count'=>array('COUNT(REG_ID)','%d'))
888 888
 	 * @return stdClass[] like results of $wpdb->get_results($sql,OBJECT), (ie, output type is OBJECT)
889 889
 	 */
890
-	public function  get_all_wpdb_results($query_params = array(), $output = ARRAY_A, $columns_to_select = null){
890
+	public function  get_all_wpdb_results($query_params = array(), $output = ARRAY_A, $columns_to_select = null) {
891 891
 		return $this->_get_all_wpdb_results($query_params, $output, $columns_to_select);
892 892
 	}
893 893
 
@@ -899,21 +899,21 @@  discard block
 block discarded – undo
899 899
 	 * @throws EE_Error
900 900
 	 * @return string
901 901
 	 */
902
-	private function _construct_select_from_input($columns_to_select){
903
-		if(is_array($columns_to_select)){
902
+	private function _construct_select_from_input($columns_to_select) {
903
+		if (is_array($columns_to_select)) {
904 904
 			$select_sql_array = array();
905 905
 
906
-			foreach($columns_to_select as $alias => $selection_and_datatype){
907
-				if( ! is_array($selection_and_datatype) || ! isset($selection_and_datatype[1])){
908
-					throw new EE_Error(sprintf(__("Custom selection %s (alias %s) needs to be an array like array('COUNT(REG_ID)','%%d')", "event_espresso"),$selection_and_datatype,$alias));
906
+			foreach ($columns_to_select as $alias => $selection_and_datatype) {
907
+				if ( ! is_array($selection_and_datatype) || ! isset($selection_and_datatype[1])) {
908
+					throw new EE_Error(sprintf(__("Custom selection %s (alias %s) needs to be an array like array('COUNT(REG_ID)','%%d')", "event_espresso"), $selection_and_datatype, $alias));
909 909
 				}
910
-				if( ! in_array( $selection_and_datatype[1],$this->_valid_wpdb_data_types)){
911
-					throw new EE_Error(sprintf(__("Datatype %s (for selection '%s' and alias '%s') is not a valid wpdb datatype (eg %%s)", "event_espresso"),$selection_and_datatype[1],$selection_and_datatype[0],$alias,implode(",",$this->_valid_wpdb_data_types)));
910
+				if ( ! in_array($selection_and_datatype[1], $this->_valid_wpdb_data_types)) {
911
+					throw new EE_Error(sprintf(__("Datatype %s (for selection '%s' and alias '%s') is not a valid wpdb datatype (eg %%s)", "event_espresso"), $selection_and_datatype[1], $selection_and_datatype[0], $alias, implode(",", $this->_valid_wpdb_data_types)));
912 912
 				}
913 913
 				$select_sql_array[] = "{$selection_and_datatype[0]} AS $alias";
914 914
 			}
915
-			$columns_to_select_string = implode(", ",$select_sql_array);
916
-		}else{
915
+			$columns_to_select_string = implode(", ", $select_sql_array);
916
+		} else {
917 917
 			$columns_to_select_string = $columns_to_select;
918 918
 		}
919 919
 		return $columns_to_select_string;
@@ -926,7 +926,7 @@  discard block
 block discarded – undo
926 926
 	 * Convenient wrapper for getting the primary key field's name. Eg, on Registration, this would be 'REG_ID'
927 927
 	 * @return string
928 928
 	 */
929
-	function primary_key_name(){
929
+	function primary_key_name() {
930 930
 		return $this->get_primary_key_field()->get_name();
931 931
 	}
932 932
 
@@ -938,15 +938,15 @@  discard block
 block discarded – undo
938 938
 	 * @param mixed $id int or string, depending on the type of the model's primary key
939 939
 	 * @return EE_Base_Class
940 940
 	 */
941
-	function get_one_by_ID($id){
942
-		if( $this->get_from_entity_map( $id ) ){
943
-			return $this->get_from_entity_map( $id );
944
-		}elseif( $this->has_primary_key_field ( ) ) {
941
+	function get_one_by_ID($id) {
942
+		if ($this->get_from_entity_map($id)) {
943
+			return $this->get_from_entity_map($id);
944
+		}elseif ($this->has_primary_key_field( )) {
945 945
 			$primary_key_name = $this->get_primary_key_field()->get_name();
946 946
 			return $this->get_one(array(array($primary_key_name => $id)));
947
-		}else{
947
+		} else {
948 948
 			//no primary key, so the $id must be from the get_index_primary_key_string()
949
-			return $this->get_one( array( $this->parse_index_primary_key_string( $id ) ) );
949
+			return $this->get_one(array($this->parse_index_primary_key_string($id)));
950 950
 		}
951 951
 	}
952 952
 
@@ -957,16 +957,16 @@  discard block
 block discarded – undo
957 957
 	 * @param array $query_params like EEM_Base's $query_params variable.
958 958
 	 * @return EE_Base_Class | NULL
959 959
 	 */
960
-	function get_one($query_params = array()){
961
-		if( ! is_array( $query_params ) ){
962
-			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' );
960
+	function get_one($query_params = array()) {
961
+		if ( ! is_array($query_params)) {
962
+			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');
963 963
 			$query_params = array();
964 964
 		}
965 965
 		$query_params['limit'] = 1;
966 966
 		$items = $this->get_all($query_params);
967
-		if(empty($items)){
967
+		if (empty($items)) {
968 968
 			return null;
969
-		}else{
969
+		} else {
970 970
 			return array_shift($items);
971 971
 		}
972 972
 	}
@@ -990,8 +990,8 @@  discard block
 block discarded – undo
990 990
 	 *
991 991
 	 * @return EE_Base_Class[]|array
992 992
 	 */
993
-	public function next_x( $current_field_value, $field_to_order_by = null, $limit = 1, $query_params = array(), $columns_to_select = null ) {
994
-		return $this->_get_consecutive( $current_field_value, '>', $field_to_order_by, $limit, $query_params, $columns_to_select );
993
+	public function next_x($current_field_value, $field_to_order_by = null, $limit = 1, $query_params = array(), $columns_to_select = null) {
994
+		return $this->_get_consecutive($current_field_value, '>', $field_to_order_by, $limit, $query_params, $columns_to_select);
995 995
 	}
996 996
 
997 997
 
@@ -1014,8 +1014,8 @@  discard block
 block discarded – undo
1014 1014
 	 *
1015 1015
 	 * @return EE_Base_Class[]|array
1016 1016
 	 */
1017
-	public function previous_x( $current_field_value, $field_to_order_by = null, $limit = 1, $query_params = array(), $columns_to_select = null ) {
1018
-		return $this->_get_consecutive( $current_field_value, '<', $field_to_order_by, $limit, $query_params, $columns_to_select );
1017
+	public function previous_x($current_field_value, $field_to_order_by = null, $limit = 1, $query_params = array(), $columns_to_select = null) {
1018
+		return $this->_get_consecutive($current_field_value, '<', $field_to_order_by, $limit, $query_params, $columns_to_select);
1019 1019
 	}
1020 1020
 
1021 1021
 
@@ -1037,9 +1037,9 @@  discard block
 block discarded – undo
1037 1037
 	 *
1038 1038
 	 * @return EE_Base_Class|null|array()
1039 1039
 	 */
1040
-	public function next( $current_field_value, $field_to_order_by = null, $query_params = array(), $columns_to_select = null ) {
1041
-		$results = $this->_get_consecutive( $current_field_value, '>', $field_to_order_by, 1, $query_params, $columns_to_select );
1042
-		return empty( $results ) ? null : reset( $results );
1040
+	public function next($current_field_value, $field_to_order_by = null, $query_params = array(), $columns_to_select = null) {
1041
+		$results = $this->_get_consecutive($current_field_value, '>', $field_to_order_by, 1, $query_params, $columns_to_select);
1042
+		return empty($results) ? null : reset($results);
1043 1043
 	}
1044 1044
 
1045 1045
 
@@ -1061,9 +1061,9 @@  discard block
 block discarded – undo
1061 1061
 	 *
1062 1062
 	 * @return EE_Base_Class|null|array()
1063 1063
 	 */
1064
-	public function previous( $current_field_value, $field_to_order_by = null, $query_params = array(), $columns_to_select = null ) {
1065
-		$results = $this->_get_consecutive( $current_field_value, '<', $field_to_order_by, 1, $query_params, $columns_to_select );
1066
-		return empty( $results ) ? null : reset( $results );
1064
+	public function previous($current_field_value, $field_to_order_by = null, $query_params = array(), $columns_to_select = null) {
1065
+		$results = $this->_get_consecutive($current_field_value, '<', $field_to_order_by, 1, $query_params, $columns_to_select);
1066
+		return empty($results) ? null : reset($results);
1067 1067
 	}
1068 1068
 
1069 1069
 
@@ -1089,40 +1089,40 @@  discard block
 block discarded – undo
1089 1089
 	 * @return EE_Base_Class[]|array
1090 1090
 	 * @throws EE_Error
1091 1091
 	 */
1092
-	protected function _get_consecutive( $current_field_value, $operand = '>', $field_to_order_by = null, $limit = 1, $query_params = array(), $columns_to_select = null ) {
1092
+	protected function _get_consecutive($current_field_value, $operand = '>', $field_to_order_by = null, $limit = 1, $query_params = array(), $columns_to_select = null) {
1093 1093
 		//if $field_to_order_by is empty then let's assume we're ordering by the primary key.
1094
-		if ( empty( $field_to_order_by ) ) {
1095
-			if ( $this->has_primary_key_field() ) {
1094
+		if (empty($field_to_order_by)) {
1095
+			if ($this->has_primary_key_field()) {
1096 1096
 				$field_to_order_by = $this->get_primary_key_field()->get_name();
1097 1097
 			} else {
1098 1098
 
1099
-				if ( WP_DEBUG ) {
1100
-					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' ) );
1099
+				if (WP_DEBUG) {
1100
+					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'));
1101 1101
 				}
1102
-				EE_Error::add_error( __('There was an error with the query.', 'event_espresso') );
1102
+				EE_Error::add_error(__('There was an error with the query.', 'event_espresso'));
1103 1103
 				return array();
1104 1104
 			}
1105 1105
 		}
1106 1106
 
1107
-		if( ! is_array( $query_params ) ){
1108
-			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' );
1107
+		if ( ! is_array($query_params)) {
1108
+			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');
1109 1109
 			$query_params = array();
1110 1110
 		}
1111 1111
 
1112 1112
 		//let's add the where query param for consecutive look up.
1113
-		$query_params[0][ $field_to_order_by ] = array( $operand, $current_field_value );
1113
+		$query_params[0][$field_to_order_by] = array($operand, $current_field_value);
1114 1114
 		$query_params['limit'] = $limit;
1115 1115
 
1116 1116
 		//set direction
1117
-		$incoming_orderby = isset( $query_params['order_by'] ) ? $query_params['order_by'] : array();
1118
-		$query_params['order_by'] = $operand == '>' ? array( $field_to_order_by => 'ASC' ) + $incoming_orderby : array( $field_to_order_by => 'DESC') + $incoming_orderby;
1117
+		$incoming_orderby = isset($query_params['order_by']) ? $query_params['order_by'] : array();
1118
+		$query_params['order_by'] = $operand == '>' ? array($field_to_order_by => 'ASC') + $incoming_orderby : array($field_to_order_by => 'DESC') + $incoming_orderby;
1119 1119
 
1120 1120
 		//if $columns_to_select is empty then that means we're returning EE_Base_Class objects
1121
-		if ( empty( $columns_to_select ) ) {
1122
-			return $this->get_all( $query_params );
1121
+		if (empty($columns_to_select)) {
1122
+			return $this->get_all($query_params);
1123 1123
 		} else {
1124 1124
 			//getting just the fields
1125
-			return $this->_get_all_wpdb_results( $query_params, ARRAY_A, $columns_to_select );
1125
+			return $this->_get_all_wpdb_results($query_params, ARRAY_A, $columns_to_select);
1126 1126
 		}
1127 1127
 	}
1128 1128
 
@@ -1133,18 +1133,18 @@  discard block
 block discarded – undo
1133 1133
 	 * This sets the _timezone property after model object has been instantiated.
1134 1134
 	 * @param null | string $timezone valid PHP DateTimeZone timezone string
1135 1135
 	 */
1136
-	public function set_timezone( $timezone ) {
1137
-		if ( $timezone !== null ) {
1136
+	public function set_timezone($timezone) {
1137
+		if ($timezone !== null) {
1138 1138
 			$this->_timezone = $timezone;
1139 1139
 		}
1140 1140
 		//note we need to loop through relations and set the timezone on those objects as well.
1141
-		foreach ( $this->_model_relations as $relation ) {
1142
-			$relation->set_timezone( $timezone );
1141
+		foreach ($this->_model_relations as $relation) {
1142
+			$relation->set_timezone($timezone);
1143 1143
 		}
1144 1144
 		//and finally we do the same for any datetime fields
1145
-		foreach ( $this->_fields as $field ) {
1146
-			if ( $field instanceof EE_Datetime_Field ) {
1147
-				$field->set_timezone( $timezone );
1145
+		foreach ($this->_fields as $field) {
1146
+			if ($field instanceof EE_Datetime_Field) {
1147
+				$field->set_timezone($timezone);
1148 1148
 			}
1149 1149
 		}
1150 1150
 	}
@@ -1159,9 +1159,9 @@  discard block
 block discarded – undo
1159 1159
 	 */
1160 1160
 	public function get_timezone() {
1161 1161
 		//first validate if timezone is set.  If not, then let's set it be whatever is set on the model fields.
1162
-		if ( empty( $this->_timezone ) ) {
1163
-			foreach( $this->_fields as $field ) {
1164
-				if ( $field instanceof EE_Datetime_Field ) {
1162
+		if (empty($this->_timezone)) {
1163
+			foreach ($this->_fields as $field) {
1164
+				if ($field instanceof EE_Datetime_Field) {
1165 1165
 					$this->set_timezone($field->get_timezone());
1166 1166
 					break;
1167 1167
 				}
@@ -1169,9 +1169,9 @@  discard block
 block discarded – undo
1169 1169
 		}
1170 1170
 
1171 1171
 		//if timezone STILL empty then return the default timezone for the site.
1172
-		if ( empty( $this->_timezone ) ) {
1173
-			EE_Registry::instance()->load_helper( 'DTT_Helper' );
1174
-			$this->set_timezone( EEH_DTT_Helper::get_timezone() );
1172
+		if (empty($this->_timezone)) {
1173
+			EE_Registry::instance()->load_helper('DTT_Helper');
1174
+			$this->set_timezone(EEH_DTT_Helper::get_timezone());
1175 1175
 		}
1176 1176
 		return $this->_timezone;
1177 1177
 	}
@@ -1189,19 +1189,19 @@  discard block
 block discarded – undo
1189 1189
 	 *
1190 1190
 	 * @return array formats in an array with the date format first, and the time format last.
1191 1191
 	 */
1192
-	public function get_formats_for( $field_name, $pretty = false ) {
1193
-		$field_settings = $this->field_settings_for( $field_name );
1192
+	public function get_formats_for($field_name, $pretty = false) {
1193
+		$field_settings = $this->field_settings_for($field_name);
1194 1194
 
1195 1195
 		//if not a valid EE_Datetime_Field then throw error
1196
-		if ( ! $field_settings instanceof EE_Datetime_Field ) {
1197
-			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 ) );
1196
+		if ( ! $field_settings instanceof EE_Datetime_Field) {
1197
+			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));
1198 1198
 		}
1199 1199
 
1200 1200
 		//while we are here, let's make sure the timezone internally in EEM_Base matches what is stored on
1201 1201
 		//the field.
1202 1202
 		$this->_timezone = $field_settings->get_timezone();
1203 1203
 
1204
-		return array( $field_settings->get_date_format( $pretty ), $field_settings->get_time_format( $pretty ) );
1204
+		return array($field_settings->get_date_format($pretty), $field_settings->get_time_format($pretty));
1205 1205
 	}
1206 1206
 
1207 1207
 
@@ -1225,25 +1225,25 @@  discard block
 block discarded – undo
1225 1225
 	 * @return int|string  If the given field_name is not of the EE_Datetime_Field type, then an EE_Error
1226 1226
 	 *                    	     exception is triggered.
1227 1227
 	 */
1228
-	public function current_time_for_query( $field_name, $timestamp = false, $what = 'both' ) {
1229
-		$formats = $this->get_formats_for( $field_name );
1228
+	public function current_time_for_query($field_name, $timestamp = false, $what = 'both') {
1229
+		$formats = $this->get_formats_for($field_name);
1230 1230
 
1231
-		$DateTime = new DateTime( "now", new DateTimeZone( $this->_timezone ) );
1231
+		$DateTime = new DateTime("now", new DateTimeZone($this->_timezone));
1232 1232
 
1233
-		if ( $timestamp ) {
1234
-			return $DateTime->format( 'U' );
1233
+		if ($timestamp) {
1234
+			return $DateTime->format('U');
1235 1235
 		}
1236 1236
 
1237 1237
 		//not returning timestamp, so return formatted string in timezone.
1238
-		switch( $what ) {
1238
+		switch ($what) {
1239 1239
 			case 'time' :
1240
-				return $DateTime->format( $formats[1] );
1240
+				return $DateTime->format($formats[1]);
1241 1241
 				break;
1242 1242
 			case 'date' :
1243
-				return $DateTime->format( $formats[0] );
1243
+				return $DateTime->format($formats[0]);
1244 1244
 				break;
1245 1245
 			default :
1246
-				return $DateTime->format( implode( ' ', $formats ) );
1246
+				return $DateTime->format(implode(' ', $formats));
1247 1247
 				break;
1248 1248
 		}
1249 1249
 	}
@@ -1267,20 +1267,20 @@  discard block
 block discarded – undo
1267 1267
 	 *                           		'U', this is ignored.
1268 1268
 	 * @return DateTime
1269 1269
 	 */
1270
-	public function convert_datetime_for_query( $field_name, $timestring, $incoming_format, $timezone = '' ) {
1270
+	public function convert_datetime_for_query($field_name, $timestring, $incoming_format, $timezone = '') {
1271 1271
 
1272 1272
 		//just using this to ensure the timezone is set correctly internally
1273
-		$this->get_formats_for( $field_name );
1273
+		$this->get_formats_for($field_name);
1274 1274
 
1275 1275
 		//load EEH_DTT_Helper
1276
-		EE_Registry::instance()->load_helper( 'DTT_Helper' );
1277
-		$set_timezone = empty( $timezone ) ? EEH_DTT_Helper::get_timezone() : $timezone;
1276
+		EE_Registry::instance()->load_helper('DTT_Helper');
1277
+		$set_timezone = empty($timezone) ? EEH_DTT_Helper::get_timezone() : $timezone;
1278 1278
 
1279
-		$incomingDateTime = date_create_from_format( $incoming_format, $timestring, new DateTimeZone( $set_timezone ) );
1280
-		if( $incomingDateTime ) {
1281
-			return $incomingDateTime->setTimeZone( new DateTimeZone( $this->_timezone ) );
1279
+		$incomingDateTime = date_create_from_format($incoming_format, $timestring, new DateTimeZone($set_timezone));
1280
+		if ($incomingDateTime) {
1281
+			return $incomingDateTime->setTimeZone(new DateTimeZone($this->_timezone));
1282 1282
 		} else {
1283
-			return new DateTime( null, new DateTimeZone( $set_timezone ) );
1283
+			return new DateTime(null, new DateTimeZone($set_timezone));
1284 1284
 		}
1285 1285
 	}
1286 1286
 
@@ -1291,7 +1291,7 @@  discard block
 block discarded – undo
1291 1291
 	 * Gets all the tables comprising this model. Array keys are the table aliases, and values are EE_Table objects
1292 1292
 	 * @return EE_Table_Base[]
1293 1293
 	 */
1294
-	function get_tables(){
1294
+	function get_tables() {
1295 1295
 		return $this->_tables;
1296 1296
 	}
1297 1297
 
@@ -1325,9 +1325,9 @@  discard block
 block discarded – undo
1325 1325
 	 * be aware that model objects being used could get out-of-sync with the database
1326 1326
 	 * @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)
1327 1327
 	 */
1328
-	function update($fields_n_values, $query_params, $keep_model_objs_in_sync = TRUE){
1329
-		if( ! is_array( $query_params ) ){
1330
-			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' );
1328
+	function update($fields_n_values, $query_params, $keep_model_objs_in_sync = TRUE) {
1329
+		if ( ! is_array($query_params)) {
1330
+			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');
1331 1331
 			$query_params = array();
1332 1332
 		}
1333 1333
 		/**
@@ -1337,7 +1337,7 @@  discard block
 block discarded – undo
1337 1337
 		 * @param array $fields_n_values the updated fields and their new values
1338 1338
 		 * @param array $query_params @see EEM_Base::get_all()
1339 1339
 		 */
1340
-		do_action( 'AHEE__EEM_Base__update__begin',$this, $fields_n_values, $query_params );
1340
+		do_action('AHEE__EEM_Base__update__begin', $this, $fields_n_values, $query_params);
1341 1341
 		/**
1342 1342
 		 * Filters the fields about to be updated given the query parameters. You can provide the
1343 1343
 		 * $query_params to $this->get_all() to find exactly which records will be updated
@@ -1345,10 +1345,10 @@  discard block
 block discarded – undo
1345 1345
 		 * @param EEM_Base $model the model being queried
1346 1346
 		 * @param array $query_params see EEM_Base::get_all()
1347 1347
 		 */
1348
-		$fields_n_values = apply_filters( 'FHEE__EEM_Base__update__fields_n_values', $fields_n_values, $this, $query_params );
1348
+		$fields_n_values = apply_filters('FHEE__EEM_Base__update__fields_n_values', $fields_n_values, $this, $query_params);
1349 1349
 		//need to verify that, for any entry we want to update, there are entries in each secondary table.
1350 1350
 		//to do that, for each table, verify that it's PK isn't null.
1351
-		$tables= $this->get_tables();
1351
+		$tables = $this->get_tables();
1352 1352
 
1353 1353
 		//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
1354 1354
 		//NOTE: we should make this code more efficient by NOT querying twice
@@ -1358,29 +1358,29 @@  discard block
 block discarded – undo
1358 1358
 			//we want to make sure the default_where strategy is ignored
1359 1359
 			$this->_ignore_where_strategy = TRUE;
1360 1360
 			$wpdb_select_results = $this->_get_all_wpdb_results($query_params);
1361
-			foreach( $wpdb_select_results as $wpdb_result ){
1361
+			foreach ($wpdb_select_results as $wpdb_result) {
1362 1362
 				// type cast stdClass as array
1363
-				$wpdb_result = (array)$wpdb_result;
1363
+				$wpdb_result = (array) $wpdb_result;
1364 1364
 				//get the model object's PK, as we'll want this if we need to insert a row into secondary tables
1365
-				if( $this->has_primary_key_field() ){
1366
-					$main_table_pk_value = $wpdb_result[ $this->get_primary_key_field()->get_qualified_column() ];
1367
-				}else{
1365
+				if ($this->has_primary_key_field()) {
1366
+					$main_table_pk_value = $wpdb_result[$this->get_primary_key_field()->get_qualified_column()];
1367
+				} else {
1368 1368
 					//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)
1369 1369
 					$main_table_pk_value = null;
1370 1370
 				}
1371 1371
 				//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
1372 1372
 				//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
1373
-				if(count($tables) > 1){
1373
+				if (count($tables) > 1) {
1374 1374
 					//foreach matching row in the DB, ensure that each table's PK isn't null. If so, there must not be an entry
1375 1375
 					//in that table, and so we'll want to insert one
1376
-					foreach($tables as $table_obj){
1376
+					foreach ($tables as $table_obj) {
1377 1377
 						$this_table_pk_column = $table_obj->get_fully_qualified_pk_column();
1378 1378
 						//if there is no private key for this table on the results, it means there's no entry
1379 1379
 						//in this table, right? so insert a row in the current table, using any fields available
1380
-						if( ! ( array_key_exists( $this_table_pk_column, $wpdb_result) && $wpdb_result[ $this_table_pk_column ] )){
1380
+						if ( ! (array_key_exists($this_table_pk_column, $wpdb_result) && $wpdb_result[$this_table_pk_column])) {
1381 1381
 							$success = $this->_insert_into_specific_table($table_obj, $fields_n_values, $main_table_pk_value);
1382 1382
 							//if we died here, report the error
1383
-							if( ! $success ) {
1383
+							if ( ! $success) {
1384 1384
 								return false;
1385 1385
 							}
1386 1386
 						}
@@ -1400,44 +1400,44 @@  discard block
 block discarded – undo
1400 1400
 		//if this wasn't called from a model object (to update itself)
1401 1401
 		//then we want to make sure we keep all the existing
1402 1402
 		//model objects in sync with the db
1403
-		if( $keep_model_objs_in_sync && ! $this->_values_already_prepared_by_model_object ){
1404
-			if( $this->has_primary_key_field() ){
1405
-				$model_objs_affected_ids = $this->get_col( $query_params );
1406
-			}else{
1403
+		if ($keep_model_objs_in_sync && ! $this->_values_already_prepared_by_model_object) {
1404
+			if ($this->has_primary_key_field()) {
1405
+				$model_objs_affected_ids = $this->get_col($query_params);
1406
+			} else {
1407 1407
 				//we need to select a bunch of columns and then combine them into the the "index primary key string"s
1408
-				$models_affected_key_columns = $this->_get_all_wpdb_results($query_params, ARRAY_A );
1408
+				$models_affected_key_columns = $this->_get_all_wpdb_results($query_params, ARRAY_A);
1409 1409
 				$model_objs_affected_ids = array();
1410
-				foreach( $models_affected_key_columns as $row ){
1411
-					$combined_index_key = $this->get_index_primary_key_string( $row );
1412
-					$model_objs_affected_ids[ $combined_index_key ] = $combined_index_key;
1410
+				foreach ($models_affected_key_columns as $row) {
1411
+					$combined_index_key = $this->get_index_primary_key_string($row);
1412
+					$model_objs_affected_ids[$combined_index_key] = $combined_index_key;
1413 1413
 				}
1414 1414
 
1415 1415
 			}
1416 1416
 
1417
-			if( ! $model_objs_affected_ids ){
1417
+			if ( ! $model_objs_affected_ids) {
1418 1418
 				//wait wait wait- if nothing was affected let's stop here
1419 1419
 				return 0;
1420 1420
 			}
1421
-			foreach( $model_objs_affected_ids as $id ){
1422
-				$model_obj_in_entity_map = $this->get_from_entity_map( $id );
1423
-				if( $model_obj_in_entity_map ){
1424
-					foreach( $fields_n_values as $field => $new_value ){
1425
-						$model_obj_in_entity_map->set( $field, $new_value );
1421
+			foreach ($model_objs_affected_ids as $id) {
1422
+				$model_obj_in_entity_map = $this->get_from_entity_map($id);
1423
+				if ($model_obj_in_entity_map) {
1424
+					foreach ($fields_n_values as $field => $new_value) {
1425
+						$model_obj_in_entity_map->set($field, $new_value);
1426 1426
 					}
1427 1427
 				}
1428 1428
 			}
1429 1429
 			//if there is a primary key on this model, we can now do a slight optimization
1430
-			if( $this->has_primary_key_field() ){
1430
+			if ($this->has_primary_key_field()) {
1431 1431
 				//we already know what we want to update. So let's make the query simpler so it's a little more efficient
1432 1432
 				$query_params = array(
1433
-					array( $this->primary_key_name() => array( 'IN', $model_objs_affected_ids ) ),
1434
-					'limit' => count( $model_objs_affected_ids ), 'default_where_conditions' => 'none' );
1433
+					array($this->primary_key_name() => array('IN', $model_objs_affected_ids)),
1434
+					'limit' => count($model_objs_affected_ids), 'default_where_conditions' => 'none' );
1435 1435
 			}
1436 1436
 		}
1437 1437
 
1438
-		$model_query_info = $this->_create_model_query_info_carrier( $query_params );
1439
-		$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.
1440
-		$rows_affected = $this->_do_wpdb_query('query', array( $SQL ) );
1438
+		$model_query_info = $this->_create_model_query_info_carrier($query_params);
1439
+		$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.
1440
+		$rows_affected = $this->_do_wpdb_query('query', array($SQL));
1441 1441
 		/**
1442 1442
 		 * Action called after a model update call has been made.
1443 1443
 		 *
@@ -1446,8 +1446,8 @@  discard block
 block discarded – undo
1446 1446
 		 * @param array $query_params @see EEM_Base::get_all()
1447 1447
 		 * @param int $rows_affected
1448 1448
 		 */
1449
-		do_action( 'AHEE__EEM_Base__update__end',$this, $fields_n_values, $query_params, $rows_affected );
1450
-		return $rows_affected;//how many supposedly got updated
1449
+		do_action('AHEE__EEM_Base__update__end', $this, $fields_n_values, $query_params, $rows_affected);
1450
+		return $rows_affected; //how many supposedly got updated
1451 1451
 	}
1452 1452
 
1453 1453
 	/**
@@ -1459,22 +1459,22 @@  discard block
 block discarded – undo
1459 1459
 	 * @param string $field_to_select
1460 1460
 	 * @return array just like $wpdb->get_col()
1461 1461
 	 */
1462
-	public function get_col( $query_params  = array(), $field_to_select = NULL ){
1462
+	public function get_col($query_params = array(), $field_to_select = NULL) {
1463 1463
 
1464
-		if( $field_to_select ){
1465
-			$field = $this->field_settings_for( $field_to_select );
1466
-		}elseif( $this->has_primary_key_field ( ) ){
1464
+		if ($field_to_select) {
1465
+			$field = $this->field_settings_for($field_to_select);
1466
+		}elseif ($this->has_primary_key_field( )) {
1467 1467
 			$field = $this->get_primary_key_field();
1468
-		}else{
1468
+		} else {
1469 1469
 			//no primary key, just grab the first column
1470
-			$field = reset( $this->field_settings());
1470
+			$field = reset($this->field_settings());
1471 1471
 		}
1472 1472
 
1473 1473
 
1474 1474
 		$model_query_info = $this->_create_model_query_info_carrier($query_params);
1475 1475
 		$select_expressions = $field->get_qualified_column();
1476
-		$SQL ="SELECT $select_expressions ".$this->_construct_2nd_half_of_select_query($model_query_info);
1477
-		$results =  $this->_do_wpdb_query('get_col', array( $SQL ) );
1476
+		$SQL = "SELECT $select_expressions ".$this->_construct_2nd_half_of_select_query($model_query_info);
1477
+		$results = $this->_do_wpdb_query('get_col', array($SQL));
1478 1478
 		return $results;
1479 1479
 	}
1480 1480
 
@@ -1484,12 +1484,12 @@  discard block
 block discarded – undo
1484 1484
 	 * @param string $field_to_select @see EEM_Base::get_col()
1485 1485
 	 * @return string
1486 1486
 	 */
1487
-	public function get_var( $query_params = array(), $field_to_select = NULL ) {
1488
-		$query_params[ 'limit' ] = 1;
1489
-		$col = $this->get_col( $query_params, $field_to_select );
1490
-		if( ! empty( $col ) ) {
1491
-			return reset( $col );
1492
-		}else{
1487
+	public function get_var($query_params = array(), $field_to_select = NULL) {
1488
+		$query_params['limit'] = 1;
1489
+		$col = $this->get_col($query_params, $field_to_select);
1490
+		if ( ! empty($col)) {
1491
+			return reset($col);
1492
+		} else {
1493 1493
 			return NULL;
1494 1494
 		}
1495 1495
 	}
@@ -1503,19 +1503,19 @@  discard block
 block discarded – undo
1503 1503
 	 * @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
1504 1504
 	 * @return string of SQL
1505 1505
 	 */
1506
-	function _construct_update_sql($fields_n_values){
1506
+	function _construct_update_sql($fields_n_values) {
1507 1507
 		/** @type WPDB $wpdb */
1508 1508
 		global $wpdb;
1509 1509
 		$cols_n_values = array();
1510
-		foreach($fields_n_values as $field_name => $value){
1510
+		foreach ($fields_n_values as $field_name => $value) {
1511 1511
 			$field_obj = $this->field_settings_for($field_name);
1512 1512
 			//if the value is NULL, we want to assign the value to that.
1513 1513
 			//wpdb->prepare doesn't really handle that properly
1514
-			$prepared_value = $this->_prepare_value_or_use_default( $field_obj, $fields_n_values );
1515
-			$value_sql = $prepared_value===NULL ? 'NULL' : $wpdb->prepare( $field_obj->get_wpdb_data_type(), $prepared_value );
1514
+			$prepared_value = $this->_prepare_value_or_use_default($field_obj, $fields_n_values);
1515
+			$value_sql = $prepared_value === NULL ? 'NULL' : $wpdb->prepare($field_obj->get_wpdb_data_type(), $prepared_value);
1516 1516
 			$cols_n_values[] = $field_obj->get_qualified_column()."=".$value_sql;
1517 1517
 		}
1518
-		return implode(",",$cols_n_values);
1518
+		return implode(",", $cols_n_values);
1519 1519
 
1520 1520
 	}
1521 1521
 
@@ -1530,11 +1530,11 @@  discard block
 block discarded – undo
1530 1530
 	 * which may depend on it. Its generally advisable to always leave this as TRUE, otherwise you could easily corrupt your DB
1531 1531
 	 * @return boolean whether the row got deleted or not
1532 1532
 	 */
1533
-	public function delete_by_ID( $id, $allow_blocking = true ){
1534
-		return $this->delete( array(
1535
-			array( $this->get_primary_key_field()->get_name() => $id ),
1533
+	public function delete_by_ID($id, $allow_blocking = true) {
1534
+		return $this->delete(array(
1535
+			array($this->get_primary_key_field()->get_name() => $id),
1536 1536
 			'limit' 	=> 1
1537
-		), $allow_blocking );
1537
+		), $allow_blocking);
1538 1538
 	}
1539 1539
 
1540 1540
 
@@ -1549,7 +1549,7 @@  discard block
 block discarded – undo
1549 1549
 	 * which may depend on it. Its generally advisable to always leave this as TRUE, otherwise you could easily corrupt your DB
1550 1550
 	 * @return int how many rows got deleted
1551 1551
 	 */
1552
-	function delete($query_params,$allow_blocking = true){
1552
+	function delete($query_params, $allow_blocking = true) {
1553 1553
 		/**
1554 1554
 		 * Action called just before performing a real deletion query. You can use the
1555 1555
 		 * model and its $query_params to find exactly which items will be deleted
@@ -1558,34 +1558,34 @@  discard block
 block discarded – undo
1558 1558
 		 * @param boolean $allow_blocking whether or not to allow related model objects
1559 1559
 		 * to block (prevent) this deletion
1560 1560
 		 */
1561
-		do_action( 'AHEE__EEM_Base__delete__begin', $this, $query_params, $allow_blocking );
1561
+		do_action('AHEE__EEM_Base__delete__begin', $this, $query_params, $allow_blocking);
1562 1562
 		//some MySQL databases may be running safe mode, which may restrict
1563 1563
 		//deletion if there is no KEY column used in the WHERE statement of a deletion.
1564 1564
 		//to get around this, we first do a SELECT, get all the IDs, and then run another query
1565 1565
 		//to delete them
1566 1566
 		$items_for_deletion = $this->_get_all_wpdb_results($query_params);
1567
-		$deletion_where = $this->_setup_ids_for_delete( $items_for_deletion, $allow_blocking);
1568
-		if($deletion_where){
1567
+		$deletion_where = $this->_setup_ids_for_delete($items_for_deletion, $allow_blocking);
1568
+		if ($deletion_where) {
1569 1569
 			//echo "objects for deletion:";var_dump($objects_for_deletion);
1570 1570
 			$model_query_info = $this->_create_model_query_info_carrier($query_params);
1571 1571
 			$table_aliases = array();
1572
-			foreach(array_keys($this->_tables) as $table_alias){
1572
+			foreach (array_keys($this->_tables) as $table_alias) {
1573 1573
 				$table_aliases[] = $table_alias;
1574 1574
 			}
1575
-			$SQL = "DELETE ".implode(", ",$table_aliases)." FROM ".$model_query_info->get_full_join_sql()." WHERE ".$deletion_where;
1575
+			$SQL = "DELETE ".implode(", ", $table_aliases)." FROM ".$model_query_info->get_full_join_sql()." WHERE ".$deletion_where;
1576 1576
 
1577 1577
 			//		/echo "delete sql:$SQL";
1578
-			$rows_deleted = $this->_do_wpdb_query( 'query', array( $SQL ) );
1579
-		}else{
1578
+			$rows_deleted = $this->_do_wpdb_query('query', array($SQL));
1579
+		} else {
1580 1580
 			$rows_deleted = 0;
1581 1581
 		}
1582 1582
 
1583 1583
 		//and lastly make sure those items are removed from the entity map; if they could be put into it at all
1584
-		if( $this->has_primary_key_field() ){
1585
-			foreach($items_for_deletion as $item_for_deletion_row ){
1586
-				$pk_value = $item_for_deletion_row[ $this->get_primary_key_field()->get_qualified_column() ];
1587
-				if( isset( $this->_entity_map[ $pk_value ] ) ){
1588
-					unset( $this->_entity_map[ $pk_value ] );
1584
+		if ($this->has_primary_key_field()) {
1585
+			foreach ($items_for_deletion as $item_for_deletion_row) {
1586
+				$pk_value = $item_for_deletion_row[$this->get_primary_key_field()->get_qualified_column()];
1587
+				if (isset($this->_entity_map[$pk_value])) {
1588
+					unset($this->_entity_map[$pk_value]);
1589 1589
 				}
1590 1590
 			}
1591 1591
 		}
@@ -1597,8 +1597,8 @@  discard block
 block discarded – undo
1597 1597
 		 * @param array $query_params @see EEM_Base::get_all()
1598 1598
 		 * @param int $rows_deleted
1599 1599
 		 */
1600
-		do_action( 'AHEE__EEM_Base__delete__end', $this, $query_params, $rows_deleted );
1601
-		return $rows_deleted;//how many supposedly got deleted
1600
+		do_action('AHEE__EEM_Base__delete__end', $this, $query_params, $rows_deleted);
1601
+		return $rows_deleted; //how many supposedly got deleted
1602 1602
 	}
1603 1603
 
1604 1604
 
@@ -1614,28 +1614,28 @@  discard block
 block discarded – undo
1614 1614
 	 * blocking its deletion before removing the relation between A and B
1615 1615
 	 * @return boolean
1616 1616
 	 */
1617
-	public function delete_is_blocked_by_related_models($this_model_obj_or_id, $ignore_this_model_obj = null){
1617
+	public function delete_is_blocked_by_related_models($this_model_obj_or_id, $ignore_this_model_obj = null) {
1618 1618
 		//first, if $ignore_this_model_obj was supplied, get its model
1619
-		if($ignore_this_model_obj && $ignore_this_model_obj instanceof EE_Base_Class){
1619
+		if ($ignore_this_model_obj && $ignore_this_model_obj instanceof EE_Base_Class) {
1620 1620
 			$ignored_model = $ignore_this_model_obj->get_model();
1621
-		}else{
1621
+		} else {
1622 1622
 			$ignored_model = null;
1623 1623
 		}
1624 1624
 		//now check all the relations of $this_model_obj_or_id and see if there
1625 1625
 		//are any related model objects blocking it?
1626 1626
 		$is_blocked = false;
1627
-		foreach($this->_model_relations as $relation_name => $relation_obj){
1628
-			if( $relation_obj->block_delete_if_related_models_exist()){
1627
+		foreach ($this->_model_relations as $relation_name => $relation_obj) {
1628
+			if ($relation_obj->block_delete_if_related_models_exist()) {
1629 1629
 				//if $ignore_this_model_obj was supplied, then for the query
1630 1630
 				//on that model needs to be told to ignore $ignore_this_model_obj
1631
-				if($ignored_model && $relation_name == $ignored_model->get_this_model_name()){
1632
-					$related_model_objects = $relation_obj->get_all_related($this_model_obj_or_id,array(
1633
-					array($ignored_model->get_primary_key_field()->get_name() => array('!=',$ignore_this_model_obj->ID()))));
1634
-				}else{
1631
+				if ($ignored_model && $relation_name == $ignored_model->get_this_model_name()) {
1632
+					$related_model_objects = $relation_obj->get_all_related($this_model_obj_or_id, array(
1633
+					array($ignored_model->get_primary_key_field()->get_name() => array('!=', $ignore_this_model_obj->ID()))));
1634
+				} else {
1635 1635
 					$related_model_objects = $relation_obj->get_all_related($this_model_obj_or_id);
1636 1636
 				}
1637 1637
 
1638
-				if($related_model_objects){
1638
+				if ($related_model_objects) {
1639 1639
 					EE_Error::add_error($relation_obj->get_deletion_error_message(), __FILE__, __FUNCTION__, __LINE__);
1640 1640
 					$is_blocked = true;
1641 1641
 				}
@@ -1655,65 +1655,65 @@  discard block
 block discarded – undo
1655 1655
 	 * @throws EE_Error
1656 1656
 	 * @return string    everything that comes after the WHERE statement.
1657 1657
 	 */
1658
-	protected function _setup_ids_for_delete( $objects_for_deletion, $allow_blocking = true) {
1659
-		if($this->has_primary_key_field()){
1658
+	protected function _setup_ids_for_delete($objects_for_deletion, $allow_blocking = true) {
1659
+		if ($this->has_primary_key_field()) {
1660 1660
 			$primary_table = $this->_get_main_table();
1661 1661
 			$other_tables = $this->_get_other_tables();
1662 1662
 			$deletes = $query = array();
1663
-			foreach ( $objects_for_deletion as $delete_object ) {
1663
+			foreach ($objects_for_deletion as $delete_object) {
1664 1664
 				//before we mark this object for deletion,
1665 1665
 				//make sure there's no related objects blocking its deletion (if we're checking)
1666
-				if( $allow_blocking && $this->delete_is_blocked_by_related_models($delete_object[$primary_table->get_fully_qualified_pk_column()]) ){
1666
+				if ($allow_blocking && $this->delete_is_blocked_by_related_models($delete_object[$primary_table->get_fully_qualified_pk_column()])) {
1667 1667
 					continue;
1668 1668
 				}
1669 1669
 
1670 1670
 				//primary table deletes
1671
-				if ( isset( $delete_object[$primary_table->get_fully_qualified_pk_column()] ) )
1671
+				if (isset($delete_object[$primary_table->get_fully_qualified_pk_column()]))
1672 1672
 					$deletes[$primary_table->get_fully_qualified_pk_column()][] = $delete_object[$primary_table->get_fully_qualified_pk_column()];
1673 1673
 
1674 1674
 				//other tables
1675
-				if ( !empty( $other_tables ) ) {
1676
-					foreach ( $other_tables as $ot ) {
1675
+				if ( ! empty($other_tables)) {
1676
+					foreach ($other_tables as $ot) {
1677 1677
 
1678 1678
 						//first check if we've got the foreign key column here.
1679
-						if ( isset( $delete_object[$ot->get_fully_qualified_fk_column()] ) )
1679
+						if (isset($delete_object[$ot->get_fully_qualified_fk_column()]))
1680 1680
 							$deletes[$ot->get_fully_qualified_pk_column()][] = $delete_object[$ot->get_fully_qualified_fk_column()];
1681 1681
 
1682 1682
 						//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
1683
-						if ( isset( $delete_object[$ot->get_fully_qualified_pk_column()] ) )
1683
+						if (isset($delete_object[$ot->get_fully_qualified_pk_column()]))
1684 1684
 							$deletes[$ot->get_fully_qualified_pk_column()][] = $delete_object[$ot->get_fully_qualified_pk_column()];
1685 1685
 
1686 1686
 						//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!
1687
-						if ( isset( $delete_object[$ot->get_fully_qualified_pk_on_fk_table()]) )
1687
+						if (isset($delete_object[$ot->get_fully_qualified_pk_on_fk_table()]))
1688 1688
 							$deletes[$ot->get_fully_qualified_pk_column()][] = $delete_object[$ot->get_fully_qualified_pk_column()];
1689 1689
 					}
1690 1690
 				}
1691 1691
 			}
1692 1692
 
1693 1693
 			//we should have deletes now, so let's just go through and setup the where statement
1694
-			foreach ( $deletes as $column => $values ) {
1694
+			foreach ($deletes as $column => $values) {
1695 1695
 				//make sure we have unique $values;
1696 1696
 				$values = array_unique($values);
1697
-				$query[] = $column . ' IN(' . implode(",",$values) . ')';
1697
+				$query[] = $column.' IN('.implode(",", $values).')';
1698 1698
 			}
1699 1699
 
1700
-			return !empty($query) ? implode(' AND ', $query ) : '';
1701
-		}elseif(count($this->get_combined_primary_key_fields()) > 1){
1700
+			return ! empty($query) ? implode(' AND ', $query) : '';
1701
+		}elseif (count($this->get_combined_primary_key_fields()) > 1) {
1702 1702
 			$ways_to_identify_a_row = array();
1703 1703
 			$fields = $this->get_combined_primary_key_fields();
1704 1704
 			//note: because there' sno primary key, that means nothing else  can be pointing to this model, right?
1705
-			foreach($objects_for_deletion as  $delete_object){
1705
+			foreach ($objects_for_deletion as  $delete_object) {
1706 1706
 				$values_for_each_cpk_for_a_row = array();
1707
-				foreach($fields as $cpk_field){
1707
+				foreach ($fields as $cpk_field) {
1708 1708
 					$values_for_each_cpk_for_a_row[] = $cpk_field->get_qualified_column()."=".$delete_object[$cpk_field->get_qualified_column()];
1709 1709
 				}
1710
-				$ways_to_identify_a_row[] = "(".implode(" AND ",$values_for_each_cpk_for_a_row).")";
1710
+				$ways_to_identify_a_row[] = "(".implode(" AND ", $values_for_each_cpk_for_a_row).")";
1711 1711
 			}
1712
-			return implode(" OR ",$ways_to_identify_a_row);
1713
-		}else{
1712
+			return implode(" OR ", $ways_to_identify_a_row);
1713
+		} else {
1714 1714
 			//so there's no primary key and no combined key...
1715 1715
 			//sorry, can't help you
1716
-			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)));
1716
+			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)));
1717 1717
 		}
1718 1718
 	}
1719 1719
 
@@ -1727,21 +1727,21 @@  discard block
 block discarded – undo
1727 1727
 	 * @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;
1728 1728
 	 * @return int
1729 1729
 	 */
1730
-	function count($query_params =array(),$field_to_count = NULL, $distinct = FALSE){
1730
+	function count($query_params = array(), $field_to_count = NULL, $distinct = FALSE) {
1731 1731
 		$model_query_info = $this->_create_model_query_info_carrier($query_params);
1732
-		if($field_to_count){
1732
+		if ($field_to_count) {
1733 1733
 			$field_obj = $this->field_settings_for($field_to_count);
1734 1734
 			$column_to_count = $field_obj->get_qualified_column();
1735
-		}elseif($this->has_primary_key_field ()){
1735
+		}elseif ($this->has_primary_key_field()) {
1736 1736
 			$pk_field_obj = $this->get_primary_key_field();
1737 1737
 			$column_to_count = $pk_field_obj->get_qualified_column();
1738
-		}else{//there's no primary key
1738
+		} else {//there's no primary key
1739 1739
 			$column_to_count = '*';
1740 1740
 		}
1741 1741
 
1742
-		$column_to_count = $distinct ? "DISTINCT (" . $column_to_count . " )" : $column_to_count;
1743
-		$SQL ="SELECT COUNT(".$column_to_count.")" . $this->_construct_2nd_half_of_select_query($model_query_info);
1744
-		return (int)$this->_do_wpdb_query( 'get_var', array( $SQL) );
1742
+		$column_to_count = $distinct ? "DISTINCT (".$column_to_count." )" : $column_to_count;
1743
+		$SQL = "SELECT COUNT(".$column_to_count.")".$this->_construct_2nd_half_of_select_query($model_query_info);
1744
+		return (int) $this->_do_wpdb_query('get_var', array($SQL));
1745 1745
 	}
1746 1746
 
1747 1747
 	/**
@@ -1751,23 +1751,23 @@  discard block
 block discarded – undo
1751 1751
 	 * @param string $field_to_sum name of field (array key in $_fields array)
1752 1752
 	 * @return float
1753 1753
 	 */
1754
-	function sum($query_params, $field_to_sum = NULL){
1754
+	function sum($query_params, $field_to_sum = NULL) {
1755 1755
 		$model_query_info = $this->_create_model_query_info_carrier($query_params);
1756 1756
 
1757
-		if($field_to_sum){
1757
+		if ($field_to_sum) {
1758 1758
 			$field_obj = $this->field_settings_for($field_to_sum);
1759 1759
 
1760
-		}else{
1760
+		} else {
1761 1761
 			$field_obj = $this->get_primary_key_field();
1762 1762
 		}
1763 1763
 		$column_to_count = $field_obj->get_qualified_column();
1764 1764
 
1765
-		$SQL ="SELECT SUM(".$column_to_count.")" . $this->_construct_2nd_half_of_select_query($model_query_info);
1766
-		$return_value = $this->_do_wpdb_query('get_var',array( $SQL ) );
1767
-		if($field_obj->get_wpdb_data_type() == '%d' || $field_obj->get_wpdb_data_type() == '%s' ){
1768
-			return (float)$return_value;
1769
-		}else{//must be %f
1770
-			return (float)$return_value;
1765
+		$SQL = "SELECT SUM(".$column_to_count.")".$this->_construct_2nd_half_of_select_query($model_query_info);
1766
+		$return_value = $this->_do_wpdb_query('get_var', array($SQL));
1767
+		if ($field_obj->get_wpdb_data_type() == '%d' || $field_obj->get_wpdb_data_type() == '%s') {
1768
+			return (float) $return_value;
1769
+		} else {//must be %f
1770
+			return (float) $return_value;
1771 1771
 		}
1772 1772
 	}
1773 1773
 
@@ -1782,33 +1782,33 @@  discard block
 block discarded – undo
1782 1782
 	 * @global wpdb $wpdb
1783 1783
 	 * @return mixed
1784 1784
 	 */
1785
-	protected function _do_wpdb_query( $wpdb_method, $arguments_to_provide ){
1785
+	protected function _do_wpdb_query($wpdb_method, $arguments_to_provide) {
1786 1786
 		//if we're in maintenance mode level 2, DON'T run any queries
1787 1787
 		//because level 2 indicates the database needs updating and
1788 1788
 		//is probably out of sync with the code
1789
-		if( ! EE_Maintenance_Mode::instance()->models_can_query()){
1789
+		if ( ! EE_Maintenance_Mode::instance()->models_can_query()) {
1790 1790
 			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")));
1791 1791
 		}
1792 1792
 		/** @type WPDB $wpdb */
1793 1793
 		global $wpdb;
1794
-		if( ! method_exists( $wpdb, $wpdb_method ) ){
1795
-			throw new EE_Error( sprintf( __( 'There is no method named "%s" on Wordpress\' $wpdb object','event_espresso' ), $wpdb_method ) );
1794
+		if ( ! method_exists($wpdb, $wpdb_method)) {
1795
+			throw new EE_Error(sprintf(__('There is no method named "%s" on Wordpress\' $wpdb object', 'event_espresso'), $wpdb_method));
1796 1796
 		}
1797
-		if( WP_DEBUG ){
1797
+		if (WP_DEBUG) {
1798 1798
 			$old_show_errors_value = $wpdb->show_errors;
1799
-			$wpdb->show_errors( FALSE );
1800
-		}
1801
-		$result = $this->_process_wpdb_query( $wpdb_method, $arguments_to_provide );
1802
-		$this->show_db_query_if_previously_requested( $wpdb->last_query );
1803
-		if( WP_DEBUG ){
1804
-			$wpdb->show_errors( $old_show_errors_value );
1805
-			if( ! empty( $wpdb->last_error ) ){
1806
-				throw new EE_Error( sprintf( __( 'WPDB Error: "%s"', 'event_espresso' ), $wpdb->last_error ) );
1807
-			}elseif( $result === false ){
1808
-				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 ) ) );
1799
+			$wpdb->show_errors(FALSE);
1800
+		}
1801
+		$result = $this->_process_wpdb_query($wpdb_method, $arguments_to_provide);
1802
+		$this->show_db_query_if_previously_requested($wpdb->last_query);
1803
+		if (WP_DEBUG) {
1804
+			$wpdb->show_errors($old_show_errors_value);
1805
+			if ( ! empty($wpdb->last_error)) {
1806
+				throw new EE_Error(sprintf(__('WPDB Error: "%s"', 'event_espresso'), $wpdb->last_error));
1807
+			}elseif ($result === false) {
1808
+				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)));
1809 1809
 			}
1810
-		}elseif( $result === false ) {
1811
-			EE_Error::add_error( sprintf( __( 'A database error has occurred. Turn on WP_DEBUG for more information.', 'event_espresso' )), __FILE__, __FUNCTION__, __LINE__);
1810
+		}elseif ($result === false) {
1811
+			EE_Error::add_error(sprintf(__('A database error has occurred. Turn on WP_DEBUG for more information.', 'event_espresso')), __FILE__, __FUNCTION__, __LINE__);
1812 1812
 		}
1813 1813
 		return $result;
1814 1814
 	}
@@ -1824,23 +1824,23 @@  discard block
 block discarded – undo
1824 1824
 	 * @param array $arguments_to_provide
1825 1825
 	 * @return mixed
1826 1826
 	 */
1827
-	private function _process_wpdb_query( $wpdb_method, $arguments_to_provide ) {
1827
+	private function _process_wpdb_query($wpdb_method, $arguments_to_provide) {
1828 1828
 		/** @type WPDB $wpdb */
1829 1829
 		global $wpdb;
1830 1830
 		$wpdb->last_error = null;
1831
-		$result = call_user_func_array( array( $wpdb, $wpdb_method ), $arguments_to_provide );
1831
+		$result = call_user_func_array(array($wpdb, $wpdb_method), $arguments_to_provide);
1832 1832
 		// was there an error running the query?
1833
-		if ( ( $result === false || ! empty( $wpdb->last_error ) ) ) {
1834
-			switch ( EEM_Base::$_db_verification_level ) {
1833
+		if (($result === false || ! empty($wpdb->last_error))) {
1834
+			switch (EEM_Base::$_db_verification_level) {
1835 1835
 
1836 1836
 				case EEM_Base::db_verified_none :
1837 1837
 					// let's double-check core's DB
1838
-					$error_message = $this->_verify_core_db( $wpdb_method, $arguments_to_provide );
1838
+					$error_message = $this->_verify_core_db($wpdb_method, $arguments_to_provide);
1839 1839
 					break;
1840 1840
 
1841 1841
 				case EEM_Base::db_verified_core :
1842 1842
 					// STILL NO LOVE?? verify all the addons too. Maybe they need to be fixed
1843
-					$error_message = $this->_verify_addons_db( $wpdb_method, $arguments_to_provide );
1843
+					$error_message = $this->_verify_addons_db($wpdb_method, $arguments_to_provide);
1844 1844
 					break;
1845 1845
 
1846 1846
 				case EEM_Base::db_verified_addons :
@@ -1848,11 +1848,11 @@  discard block
 block discarded – undo
1848 1848
 					return $result;
1849 1849
 					break;
1850 1850
 			}
1851
-			if ( ! empty( $error_message ) ) {
1852
-				EE_Log::instance()->log( __FILE__, __FUNCTION__, $error_message, 'error' );
1853
-				trigger_error( $error_message );
1851
+			if ( ! empty($error_message)) {
1852
+				EE_Log::instance()->log(__FILE__, __FUNCTION__, $error_message, 'error');
1853
+				trigger_error($error_message);
1854 1854
 			}
1855
-			return $this->_process_wpdb_query( $wpdb_method, $arguments_to_provide );
1855
+			return $this->_process_wpdb_query($wpdb_method, $arguments_to_provide);
1856 1856
 
1857 1857
 		}
1858 1858
 
@@ -1868,18 +1868,18 @@  discard block
 block discarded – undo
1868 1868
 	 * @param array $arguments_to_provide
1869 1869
 	 * @return string
1870 1870
 	 */
1871
-	private function _verify_core_db( $wpdb_method, $arguments_to_provide ){
1871
+	private function _verify_core_db($wpdb_method, $arguments_to_provide) {
1872 1872
 		/** @type WPDB $wpdb */
1873 1873
 		global $wpdb;
1874 1874
 		//ok remember that we've already attempted fixing the core db, in case the problem persists
1875 1875
 		EEM_Base::$_db_verification_level = EEM_Base::db_verified_core;
1876 1876
 		$error_message = sprintf(
1877
-			__( 'WPDB Error "%1$s" while running wpdb method "%2$s" with arguments %3$s. Automatically attempting to fix EE Core DB', 'event_espresso' ),
1877
+			__('WPDB Error "%1$s" while running wpdb method "%2$s" with arguments %3$s. Automatically attempting to fix EE Core DB', 'event_espresso'),
1878 1878
 			$wpdb->last_error,
1879 1879
 			$wpdb_method,
1880
-			json_encode( $arguments_to_provide )
1880
+			json_encode($arguments_to_provide)
1881 1881
 		);
1882
-		EE_System::instance()->initialize_db_if_no_migrations_required( false, true );
1882
+		EE_System::instance()->initialize_db_if_no_migrations_required(false, true);
1883 1883
 		return $error_message;
1884 1884
 	}
1885 1885
 
@@ -1892,16 +1892,16 @@  discard block
 block discarded – undo
1892 1892
 	 * @param $arguments_to_provide
1893 1893
 	 * @return string
1894 1894
 	 */
1895
-	private function _verify_addons_db( $wpdb_method, $arguments_to_provide ) {
1895
+	private function _verify_addons_db($wpdb_method, $arguments_to_provide) {
1896 1896
 		/** @type WPDB $wpdb */
1897 1897
 		global $wpdb;
1898 1898
 		//ok remember that we've already attempted fixing the addons dbs, in case the problem persists
1899 1899
 		EEM_Base::$_db_verification_level = EEM_Base::db_verified_addons;
1900 1900
 		$error_message = sprintf(
1901
-			__( 'WPDB AGAIN: Error "%1$s" while running the same method and arguments as before. Automatically attempting to fix EE Addons DB', 'event_espresso' ),
1901
+			__('WPDB AGAIN: Error "%1$s" while running the same method and arguments as before. Automatically attempting to fix EE Addons DB', 'event_espresso'),
1902 1902
 			$wpdb->last_error,
1903 1903
 			$wpdb_method,
1904
-			json_encode( $arguments_to_provide )
1904
+			json_encode($arguments_to_provide)
1905 1905
 		);
1906 1906
 		EE_System::instance()->initialize_addons();
1907 1907
 		return $error_message;
@@ -1916,7 +1916,7 @@  discard block
 block discarded – undo
1916 1916
 	 * @param EE_Model_Query_Info_Carrier $model_query_info
1917 1917
 	 * @return string
1918 1918
 	 */
1919
-	private function _construct_2nd_half_of_select_query(EE_Model_Query_Info_Carrier $model_query_info){
1919
+	private function _construct_2nd_half_of_select_query(EE_Model_Query_Info_Carrier $model_query_info) {
1920 1920
 		return " FROM ".$model_query_info->get_full_join_sql().
1921 1921
 				$model_query_info->get_where_sql().
1922 1922
 				$model_query_info->get_group_by_sql().
@@ -1929,7 +1929,7 @@  discard block
 block discarded – undo
1929 1929
 	 * Set to easily debug the next X queries ran from this model.
1930 1930
 	 * @param int $count
1931 1931
 	 */
1932
-	function show_next_x_db_queries($count = 1){
1932
+	function show_next_x_db_queries($count = 1) {
1933 1933
 		$this->_show_next_x_db_queries = $count;
1934 1934
 	}
1935 1935
 
@@ -1938,8 +1938,8 @@  discard block
 block discarded – undo
1938 1938
 	/**
1939 1939
 	 * @param $sql_query
1940 1940
 	 */
1941
-	function show_db_query_if_previously_requested($sql_query){
1942
-		if($this->_show_next_x_db_queries > 0){
1941
+	function show_db_query_if_previously_requested($sql_query) {
1942
+		if ($this->_show_next_x_db_queries > 0) {
1943 1943
 			echo $sql_query;
1944 1944
 			$this->_show_next_x_db_queries--;
1945 1945
 		}
@@ -1963,7 +1963,7 @@  discard block
 block discarded – undo
1963 1963
 	 * @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.
1964 1964
 	 * @return EE_Base_Class which was added as a relation. Object referred to by $other_model_id_or_obj
1965 1965
 	 */
1966
-	public function add_relationship_to($id_or_obj,$other_model_id_or_obj, $relationName, $extra_join_model_fields_n_values = array()){
1966
+	public function add_relationship_to($id_or_obj, $other_model_id_or_obj, $relationName, $extra_join_model_fields_n_values = array()) {
1967 1967
 		$relation_obj = $this->related_settings_for($relationName);
1968 1968
 		return $relation_obj->add_relation_to($id_or_obj, $other_model_id_or_obj, $extra_join_model_fields_n_values);
1969 1969
 	}
@@ -1984,9 +1984,9 @@  discard block
 block discarded – undo
1984 1984
 	 * @return boolean of success
1985 1985
 	 * @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.
1986 1986
 	 */
1987
-	public function remove_relationship_to($id_or_obj,  $other_model_id_or_obj, $relationName, $where_query= array() ){
1987
+	public function remove_relationship_to($id_or_obj, $other_model_id_or_obj, $relationName, $where_query = array()) {
1988 1988
 		$relation_obj = $this->related_settings_for($relationName);
1989
-		return $relation_obj->remove_relation_to($id_or_obj, $other_model_id_or_obj, $where_query );
1989
+		return $relation_obj->remove_relation_to($id_or_obj, $other_model_id_or_obj, $where_query);
1990 1990
 	}
1991 1991
 
1992 1992
 
@@ -1999,9 +1999,9 @@  discard block
 block discarded – undo
1999 1999
 	 * @param EE_Base_Class[] objects to which relations were removed
2000 2000
 	 * @return \EE_Base_Class[]
2001 2001
 	 */
2002
-	public function remove_relations($id_or_obj,$relationName,$where_query_params = array()){
2002
+	public function remove_relations($id_or_obj, $relationName, $where_query_params = array()) {
2003 2003
 		$relation_obj = $this->related_settings_for($relationName);
2004
-		return $relation_obj->remove_relations($id_or_obj, $where_query_params );
2004
+		return $relation_obj->remove_relations($id_or_obj, $where_query_params);
2005 2005
 	}
2006 2006
 
2007 2007
 
@@ -2014,10 +2014,10 @@  discard block
 block discarded – undo
2014 2014
 	 * @param array $query_params like EEM_Base::get_all
2015 2015
 	 * @return EE_Base_Class[]
2016 2016
 	 */
2017
-	function get_all_related($id_or_obj, $model_name, $query_params = null){
2017
+	function get_all_related($id_or_obj, $model_name, $query_params = null) {
2018 2018
 		$model_obj = $this->ensure_is_obj($id_or_obj);
2019 2019
 		$relation_settings = $this->related_settings_for($model_name);
2020
-		return $relation_settings->get_all_related($model_obj,$query_params);
2020
+		return $relation_settings->get_all_related($model_obj, $query_params);
2021 2021
 	}
2022 2022
 
2023 2023
 	/**
@@ -2030,10 +2030,10 @@  discard block
 block discarded – undo
2030 2030
 	 * @param array $query_params
2031 2031
 	 * @return int how many deleted
2032 2032
 	 */
2033
-	public function delete_related($id_or_obj,$model_name, $query_params = array()){
2033
+	public function delete_related($id_or_obj, $model_name, $query_params = array()) {
2034 2034
 		$model_obj = $this->ensure_is_obj($id_or_obj);
2035 2035
 		$relation_settings = $this->related_settings_for($model_name);
2036
-		return $relation_settings->delete_all_related($model_obj,$query_params);
2036
+		return $relation_settings->delete_all_related($model_obj, $query_params);
2037 2037
 	}
2038 2038
 
2039 2039
 	/**
@@ -2046,10 +2046,10 @@  discard block
 block discarded – undo
2046 2046
 	 * @param array $query_params
2047 2047
 	 * @return int how many deleted
2048 2048
 	 */
2049
-	public function delete_related_permanently($id_or_obj,$model_name, $query_params = array()){
2049
+	public function delete_related_permanently($id_or_obj, $model_name, $query_params = array()) {
2050 2050
 		$model_obj = $this->ensure_is_obj($id_or_obj);
2051 2051
 		$relation_settings = $this->related_settings_for($model_name);
2052
-		return $relation_settings->delete_related_permanently($model_obj,$query_params);
2052
+		return $relation_settings->delete_related_permanently($model_obj, $query_params);
2053 2053
 	}
2054 2054
 
2055 2055
 	/**
@@ -2062,17 +2062,17 @@  discard block
 block discarded – undo
2062 2062
 	 * @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;
2063 2063
 	 * @return int
2064 2064
 	 */
2065
-	function count_related($id_or_obj,$model_name,$query_params = array(),$field_to_count = null, $distinct = FALSE){
2065
+	function count_related($id_or_obj, $model_name, $query_params = array(), $field_to_count = null, $distinct = FALSE) {
2066 2066
 		$related_model = $this->get_related_model_obj($model_name);
2067 2067
 		//we're just going to use the query params on the related model's normal get_all query,
2068 2068
 		//except add a condition to say to match the current mod
2069
-		if( ! isset($query_params['default_where_conditions'])){
2070
-			$query_params['default_where_conditions']='none';
2069
+		if ( ! isset($query_params['default_where_conditions'])) {
2070
+			$query_params['default_where_conditions'] = 'none';
2071 2071
 		}
2072 2072
 		$this_model_name = $this->get_this_model_name();
2073 2073
 		$this_pk_field_name = $this->get_primary_key_field()->get_name();
2074
-		$query_params[0][$this_model_name.".".$this_pk_field_name]=$id_or_obj;
2075
-		return $related_model->count($query_params,$field_to_count,$distinct);
2074
+		$query_params[0][$this_model_name.".".$this_pk_field_name] = $id_or_obj;
2075
+		return $related_model->count($query_params, $field_to_count, $distinct);
2076 2076
 	}
2077 2077
 
2078 2078
 
@@ -2086,21 +2086,21 @@  discard block
 block discarded – undo
2086 2086
 	 * @param string $field_to_sum name of field to count by. By default, uses primary key
2087 2087
 	 * @return float
2088 2088
 	 */
2089
-	function sum_related($id_or_obj,$model_name,$query_params,$field_to_sum = null){
2089
+	function sum_related($id_or_obj, $model_name, $query_params, $field_to_sum = null) {
2090 2090
 		$related_model = $this->get_related_model_obj($model_name);
2091
-		if( ! is_array( $query_params ) ){
2092
-			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' );
2091
+		if ( ! is_array($query_params)) {
2092
+			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');
2093 2093
 			$query_params = array();
2094 2094
 		}
2095 2095
 		//we're just going to use the query params on the related model's normal get_all query,
2096 2096
 		//except add a condition to say to match the current mod
2097
-		if( ! isset($query_params['default_where_conditions'])){
2098
-			$query_params['default_where_conditions']='none';
2097
+		if ( ! isset($query_params['default_where_conditions'])) {
2098
+			$query_params['default_where_conditions'] = 'none';
2099 2099
 		}
2100 2100
 		$this_model_name = $this->get_this_model_name();
2101 2101
 		$this_pk_field_name = $this->get_primary_key_field()->get_name();
2102
-		$query_params[0][$this_model_name.".".$this_pk_field_name]=$id_or_obj;
2103
-		return $related_model->sum($query_params,$field_to_sum);
2102
+		$query_params[0][$this_model_name.".".$this_pk_field_name] = $id_or_obj;
2103
+		return $related_model->sum($query_params, $field_to_sum);
2104 2104
 	}
2105 2105
 
2106 2106
 
@@ -2112,12 +2112,12 @@  discard block
 block discarded – undo
2112 2112
 	 * @param array $query_params like EEM_Base::get_all's
2113 2113
 	 * @return EE_Base_Class
2114 2114
 	 */
2115
-	public function get_first_related( EE_Base_Class $id_or_obj, $other_model_name, $query_params ){
2116
-		$query_params['limit']=1;
2117
-		$results = $this->get_all_related($id_or_obj,$other_model_name,$query_params);
2118
-		if( $results ){
2115
+	public function get_first_related(EE_Base_Class $id_or_obj, $other_model_name, $query_params) {
2116
+		$query_params['limit'] = 1;
2117
+		$results = $this->get_all_related($id_or_obj, $other_model_name, $query_params);
2118
+		if ($results) {
2119 2119
 			return array_shift($results);
2120
-		}else{
2120
+		} else {
2121 2121
 			return null;
2122 2122
 		}
2123 2123
 
@@ -2127,8 +2127,8 @@  discard block
 block discarded – undo
2127 2127
 	 * Gets the model's name as it's expected in queries. For example, if this is EEM_Event model, that would be Event
2128 2128
 	 * @return string
2129 2129
 	 */
2130
-	function get_this_model_name(){
2131
-		return str_replace("EEM_","",get_class($this));
2130
+	function get_this_model_name() {
2131
+		return str_replace("EEM_", "", get_class($this));
2132 2132
 	}
2133 2133
 
2134 2134
 	/**
@@ -2136,14 +2136,14 @@  discard block
 block discarded – undo
2136 2136
 	 * @return EE_Any_Foreign_Model_Name_Field
2137 2137
 	 * @throws EE_Error
2138 2138
 	 */
2139
-	public function get_field_containing_related_model_name(){
2140
-		foreach($this->field_settings(true) as $field){
2141
-			if($field instanceof EE_Any_Foreign_Model_Name_Field){
2139
+	public function get_field_containing_related_model_name() {
2140
+		foreach ($this->field_settings(true) as $field) {
2141
+			if ($field instanceof EE_Any_Foreign_Model_Name_Field) {
2142 2142
 				$field_with_model_name = $field;
2143 2143
 			}
2144 2144
 		}
2145
-		if( !isset($field_with_model_name) || !$field_with_model_name ){
2146
-			throw new EE_Error(sprintf(__("There is no EE_Any_Foreign_Model_Name field on model %s", "event_espresso"), $this->get_this_model_name() ));
2145
+		if ( ! isset($field_with_model_name) || ! $field_with_model_name) {
2146
+			throw new EE_Error(sprintf(__("There is no EE_Any_Foreign_Model_Name field on model %s", "event_espresso"), $this->get_this_model_name()));
2147 2147
 		}
2148 2148
 		return $field_with_model_name;
2149 2149
 	}
@@ -2164,19 +2164,19 @@  discard block
 block discarded – undo
2164 2164
 	 * @return int new primary key on main table that got inserted
2165 2165
 	 * @throws EE_Error
2166 2166
 	 */
2167
-	function insert($field_n_values){
2167
+	function insert($field_n_values) {
2168 2168
 		/**
2169 2169
 		 * Filters the fields and their values before inserting an item using the models
2170 2170
 		 * @param array $fields_n_values keys are the fields and values are their new values
2171 2171
 		 * @param EEM_Base $model the model used
2172 2172
 		 */
2173
-		$field_n_values = apply_filters( 'FHEE__EEM_Base__insert__fields_n_values', $field_n_values, $this );
2174
-		if($this->_satisfies_unique_indexes($field_n_values)){
2173
+		$field_n_values = apply_filters('FHEE__EEM_Base__insert__fields_n_values', $field_n_values, $this);
2174
+		if ($this->_satisfies_unique_indexes($field_n_values)) {
2175 2175
 			$main_table = $this->_get_main_table();
2176 2176
 			$new_id = $this->_insert_into_specific_table($main_table, $field_n_values, false);
2177
-			if( $new_id !== false ) {
2178
-				foreach($this->_get_other_tables() as $other_table){
2179
-					$this->_insert_into_specific_table($other_table, $field_n_values,$new_id);
2177
+			if ($new_id !== false) {
2178
+				foreach ($this->_get_other_tables() as $other_table) {
2179
+					$this->_insert_into_specific_table($other_table, $field_n_values, $new_id);
2180 2180
 				}
2181 2181
 			}
2182 2182
 			/**
@@ -2186,9 +2186,9 @@  discard block
 block discarded – undo
2186 2186
 			 * @param array $fields_n_values fields and their values
2187 2187
 			 * @param int|string the ID of the newly-inserted model object
2188 2188
 			 */
2189
-			do_action( 'AHEE__EEM_Base__insert__end', $this, $field_n_values, $new_id );
2189
+			do_action('AHEE__EEM_Base__insert__end', $this, $field_n_values, $new_id);
2190 2190
 			return $new_id;
2191
-		}else{
2191
+		} else {
2192 2192
 			return FALSE;
2193 2193
 		}
2194 2194
 	}
@@ -2201,11 +2201,11 @@  discard block
 block discarded – undo
2201 2201
 	 * @param string $action
2202 2202
 	 * @return boolean
2203 2203
 	 */
2204
-	protected function _satisfies_unique_indexes($field_n_values,$action = 'insert'){
2205
-		foreach($this->unique_indexes() as $index_name => $index){
2204
+	protected function _satisfies_unique_indexes($field_n_values, $action = 'insert') {
2205
+		foreach ($this->unique_indexes() as $index_name => $index) {
2206 2206
 			$uniqueness_where_params = array_intersect_key($field_n_values, $index->fields());
2207
-			if($this->exists(array($uniqueness_where_params))){
2208
-				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__ );
2207
+			if ($this->exists(array($uniqueness_where_params))) {
2208
+				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__);
2209 2209
 				return false;
2210 2210
 			}
2211 2211
 		}
@@ -2226,28 +2226,28 @@  discard block
 block discarded – undo
2226 2226
 	 * @throws EE_Error
2227 2227
 	 * @return EE_Base_Class
2228 2228
 	 */
2229
-	public function get_one_conflicting($obj_or_fields_array, $include_primary_key = true ){
2230
-		if($obj_or_fields_array instanceof EE_Base_Class){
2229
+	public function get_one_conflicting($obj_or_fields_array, $include_primary_key = true) {
2230
+		if ($obj_or_fields_array instanceof EE_Base_Class) {
2231 2231
 			$fields_n_values = $obj_or_fields_array->model_field_array();
2232
-		}elseif( is_array($obj_or_fields_array)){
2232
+		}elseif (is_array($obj_or_fields_array)) {
2233 2233
 			$fields_n_values = $obj_or_fields_array;
2234
-		}else{
2235
-			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));
2234
+		} else {
2235
+			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));
2236 2236
 		}
2237
-		$query_params = array( 'default_where_conditions' => 'minimum' );
2238
-		if( $this->has_primary_key_field() &&
2239
-				( $include_primary_key || $this->get_primary_key_field() instanceof EE_Primary_Key_String_Field) &&
2240
-				isset($fields_n_values[$this->primary_key_name()])){
2237
+		$query_params = array('default_where_conditions' => 'minimum');
2238
+		if ($this->has_primary_key_field() &&
2239
+				($include_primary_key || $this->get_primary_key_field() instanceof EE_Primary_Key_String_Field) &&
2240
+				isset($fields_n_values[$this->primary_key_name()])) {
2241 2241
 			$query_params[0]['OR'][$this->primary_key_name()] = $fields_n_values[$this->primary_key_name()];
2242 2242
 		}
2243
-		foreach($this->unique_indexes() as $unique_index_name=>$unique_index){
2243
+		foreach ($this->unique_indexes() as $unique_index_name=>$unique_index) {
2244 2244
 			$uniqueness_where_params = array_intersect_key($fields_n_values, $unique_index->fields());
2245 2245
 			$query_params[0]['OR']['AND*'.$unique_index_name] = $uniqueness_where_params;
2246 2246
 		}
2247 2247
 		//if there is nothing to base this search on, then we shouldn't find anything
2248
-		if( ! isset( $query_params[0] ) || ( isset( $query_params[0] ) && empty( $query_params[0] ) ) ) {
2248
+		if ( ! isset($query_params[0]) || (isset($query_params[0]) && empty($query_params[0]))) {
2249 2249
 			return array();
2250
-		}else{
2250
+		} else {
2251 2251
 			return $this->get_one($query_params);
2252 2252
 		}
2253 2253
 	}
@@ -2257,7 +2257,7 @@  discard block
 block discarded – undo
2257 2257
 	 * @param array $query_params
2258 2258
 	 * @return boolean
2259 2259
 	 */
2260
-	function exists($query_params){
2260
+	function exists($query_params) {
2261 2261
 		$query_params['limit'] = 1;
2262 2262
 		return $this->count($query_params) > 0;
2263 2263
 	}
@@ -2267,7 +2267,7 @@  discard block
 block discarded – undo
2267 2267
 	 * @param int|string $id
2268 2268
 	 * @return boolean
2269 2269
 	 */
2270
-	function exists_by_ID($id){
2270
+	function exists_by_ID($id) {
2271 2271
 		return $this->exists(array('default_where_conditions'=>'none', array($this->primary_key_name() => $id)));
2272 2272
 	}
2273 2273
 
@@ -2287,45 +2287,45 @@  discard block
 block discarded – undo
2287 2287
 	 * @global WPDB $wpdb only used to get the $wpdb->insert_id after performing an insert
2288 2288
 	 * @return int ID of new row inserted, or FALSE on failure
2289 2289
 	 */
2290
-	protected function _insert_into_specific_table(EE_Table_Base $table, $fields_n_values, $new_id = 0 ){
2290
+	protected function _insert_into_specific_table(EE_Table_Base $table, $fields_n_values, $new_id = 0) {
2291 2291
 		global $wpdb;
2292 2292
 		$insertion_col_n_values = array();
2293 2293
 		$format_for_insertion = array();
2294 2294
 		$fields_on_table = $this->_get_fields_for_table($table->get_table_alias());
2295
-		foreach($fields_on_table as $field_name => $field_obj){
2295
+		foreach ($fields_on_table as $field_name => $field_obj) {
2296 2296
 			//check if its an auto-incrementing column, in which case we should just leave it to do its autoincrement thing
2297
-			if($field_obj->is_auto_increment()){
2297
+			if ($field_obj->is_auto_increment()) {
2298 2298
 				continue;
2299 2299
 			}
2300 2300
 			$prepared_value = $this->_prepare_value_or_use_default($field_obj, $fields_n_values);
2301 2301
 			//if the value we want to assign it to is NULL, just don't mention it for the insertion
2302
-			if( $prepared_value !== NULL ){
2303
-				$insertion_col_n_values[ $field_obj->get_table_column() ] = $prepared_value;
2302
+			if ($prepared_value !== NULL) {
2303
+				$insertion_col_n_values[$field_obj->get_table_column()] = $prepared_value;
2304 2304
 				$format_for_insertion[] = $field_obj->get_wpdb_data_type();
2305 2305
 			}
2306 2306
 		}
2307 2307
 
2308
-		if($table instanceof EE_Secondary_Table && $new_id){
2308
+		if ($table instanceof EE_Secondary_Table && $new_id) {
2309 2309
 			//its not the main table, so we should have already saved the main table's PK which we just inserted
2310 2310
 			//so add the fk to the main table as a column
2311 2311
 			$insertion_col_n_values[$table->get_fk_on_table()] = $new_id;
2312
-			$format_for_insertion[]='%d';//yes right now we're only allowing these foreign keys to be INTs
2312
+			$format_for_insertion[] = '%d'; //yes right now we're only allowing these foreign keys to be INTs
2313 2313
 		}
2314 2314
 		//insert the new entry
2315
-		$result = $this->_do_wpdb_query( 'insert', array( $table->get_table_name(), $insertion_col_n_values, $format_for_insertion ) );
2316
-		if( $result === false ) {
2315
+		$result = $this->_do_wpdb_query('insert', array($table->get_table_name(), $insertion_col_n_values, $format_for_insertion));
2316
+		if ($result === false) {
2317 2317
 			return false;
2318 2318
 		}
2319 2319
 		//ok, now what do we return for the ID of the newly-inserted thing?
2320
-		if($this->has_primary_key_field()){
2321
-			if($this->get_primary_key_field()->is_auto_increment()){
2320
+		if ($this->has_primary_key_field()) {
2321
+			if ($this->get_primary_key_field()->is_auto_increment()) {
2322 2322
 				return $wpdb->insert_id;
2323
-			}else{
2323
+			} else {
2324 2324
 				//it's not an auto-increment primary key, so
2325 2325
 				//it must have been supplied
2326 2326
 				return $fields_n_values[$this->get_primary_key_field()->get_name()];
2327 2327
 			}
2328
-		}else{
2328
+		} else {
2329 2329
 			//we can't return a  primary key because there is none. instead return
2330 2330
 			//a unique string indicating this model
2331 2331
 			return $this->get_index_primary_key_string($fields_n_values);
@@ -2340,15 +2340,15 @@  discard block
 block discarded – undo
2340 2340
 	 * @param array $fields_n_values
2341 2341
 	 * @return mixed string|int|float depending on what the table column will be expecting
2342 2342
 	 */
2343
-	protected function _prepare_value_or_use_default( $field_obj, $fields_n_values ){
2343
+	protected function _prepare_value_or_use_default($field_obj, $fields_n_values) {
2344 2344
 		//if this field doesn't allow nullable, don't allow it
2345
-		if( ! $field_obj->is_nullable() && (
2346
-				! isset( $fields_n_values[ $field_obj->get_name() ] ) ||
2347
-				$fields_n_values[ $field_obj->get_name() ] === NULL ) ){
2348
-			$fields_n_values[ $field_obj->get_name() ] = $field_obj->get_default_value();
2345
+		if ( ! $field_obj->is_nullable() && (
2346
+				! isset($fields_n_values[$field_obj->get_name()]) ||
2347
+				$fields_n_values[$field_obj->get_name()] === NULL )) {
2348
+			$fields_n_values[$field_obj->get_name()] = $field_obj->get_default_value();
2349 2349
 		}
2350
-		$unprepared_value = isset( $fields_n_values[ $field_obj->get_name() ] ) ? $fields_n_values[ $field_obj->get_name() ] : NULL;
2351
-		return $this->_prepare_value_for_use_in_db( $unprepared_value, $field_obj);
2350
+		$unprepared_value = isset($fields_n_values[$field_obj->get_name()]) ? $fields_n_values[$field_obj->get_name()] : NULL;
2351
+		return $this->_prepare_value_for_use_in_db($unprepared_value, $field_obj);
2352 2352
 	}
2353 2353
 
2354 2354
 
@@ -2360,9 +2360,9 @@  discard block
 block discarded – undo
2360 2360
 	 * @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
2361 2361
 	 * @return mixed a value ready for use in the database for insertions, updating, or in a where clause
2362 2362
 	 */
2363
-	private function _prepare_value_for_use_in_db($value, $field){
2364
-		if($field && $field instanceof EE_Model_Field_Base){
2365
-			switch( $this->_values_already_prepared_by_model_object ){
2363
+	private function _prepare_value_for_use_in_db($value, $field) {
2364
+		if ($field && $field instanceof EE_Model_Field_Base) {
2365
+			switch ($this->_values_already_prepared_by_model_object) {
2366 2366
 				/** @noinspection PhpMissingBreakStatementInspection */
2367 2367
 				case self::not_prepared_by_model_object:
2368 2368
 					$value = $field->prepare_for_set($value);
@@ -2373,7 +2373,7 @@  discard block
 block discarded – undo
2373 2373
 					//leave the value alone
2374 2374
 			}
2375 2375
 			return $value;
2376
-		}else{
2376
+		} else {
2377 2377
 			return $value;
2378 2378
 		}
2379 2379
 	}
@@ -2383,13 +2383,13 @@  discard block
 block discarded – undo
2383 2383
 	 * @return EE_Primary_Table
2384 2384
 	 * @throws EE_Error
2385 2385
 	 */
2386
-	protected function _get_main_table(){
2387
-		foreach($this->_tables as $table){
2388
-			if($table instanceof EE_Primary_Table){
2386
+	protected function _get_main_table() {
2387
+		foreach ($this->_tables as $table) {
2388
+			if ($table instanceof EE_Primary_Table) {
2389 2389
 				return $table;
2390 2390
 			}
2391 2391
 		}
2392
-		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)));
2392
+		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)));
2393 2393
 	}
2394 2394
 
2395 2395
 	/**
@@ -2408,7 +2408,7 @@  discard block
 block discarded – undo
2408 2408
 	 */
2409 2409
 	public function second_table() {
2410 2410
 		// grab second table from tables array
2411
-		$second_table = end( $this->_tables );
2411
+		$second_table = end($this->_tables);
2412 2412
 		return $second_table instanceof EE_Secondary_Table ? $second_table->get_table_name() : NULL;
2413 2413
 	}
2414 2414
 
@@ -2421,8 +2421,8 @@  discard block
 block discarded – undo
2421 2421
 	 * @param string $table_alias
2422 2422
 	 * @return EE_Primary_Table | EE_Secondary_Table
2423 2423
 	 */
2424
-	public function get_table_obj_by_alias( $table_alias = '' ) {
2425
-		return isset( $this->_tables[ $table_alias ] ) ? $this->_tables[ $table_alias ] : NULL;
2424
+	public function get_table_obj_by_alias($table_alias = '') {
2425
+		return isset($this->_tables[$table_alias]) ? $this->_tables[$table_alias] : NULL;
2426 2426
 	}
2427 2427
 
2428 2428
 
@@ -2431,10 +2431,10 @@  discard block
 block discarded – undo
2431 2431
 	 * Gets all the tables of type EE_Other_Table from EEM_CPT_Basel_Model::_tables
2432 2432
 	 * @return EE_Secondary_Table[]
2433 2433
 	 */
2434
-	protected function _get_other_tables(){
2435
-		$other_tables =array();
2436
-		foreach($this->_tables as $table_alias => $table){
2437
-			if($table instanceof EE_Secondary_Table){
2434
+	protected function _get_other_tables() {
2435
+		$other_tables = array();
2436
+		foreach ($this->_tables as $table_alias => $table) {
2437
+			if ($table instanceof EE_Secondary_Table) {
2438 2438
 				$other_tables[$table_alias] = $table;
2439 2439
 			}
2440 2440
 		}
@@ -2446,7 +2446,7 @@  discard block
 block discarded – undo
2446 2446
 	 * @param string $table_alias, array key in EEM_Base::_tables
2447 2447
 	 * @return EE_Model_Field_Base[]
2448 2448
 	 */
2449
-	function _get_fields_for_table($table_alias){
2449
+	function _get_fields_for_table($table_alias) {
2450 2450
 		return $this->_fields[$table_alias];
2451 2451
 	}
2452 2452
 
@@ -2458,29 +2458,29 @@  discard block
 block discarded – undo
2458 2458
 	 * @param array $query_params like EEM_Base::get_all's $query_parameters['where']
2459 2459
 	 * @return EE_Model_Query_Info_Carrier
2460 2460
 	 */
2461
-	function _extract_related_models_from_query($query_params){
2461
+	function _extract_related_models_from_query($query_params) {
2462 2462
 		$query_info_carrier = new EE_Model_Query_Info_Carrier();
2463
-		if(array_key_exists(0,$query_params)){
2464
-			$this->_extract_related_models_from_sub_params_array_keys($query_params[0], $query_info_carrier,0);
2465
-		}
2466
-		if(array_key_exists('group_by', $query_params)){
2467
-			if(is_array($query_params['group_by'])){
2468
-				$this->_extract_related_models_from_sub_params_array_values($query_params['group_by'],$query_info_carrier,'group_by');
2469
-			}elseif( ! empty ( $query_params['group_by'] )){
2470
-				$this->_extract_related_model_info_from_query_param( $query_params['group_by'],$query_info_carrier,'group_by');
2463
+		if (array_key_exists(0, $query_params)) {
2464
+			$this->_extract_related_models_from_sub_params_array_keys($query_params[0], $query_info_carrier, 0);
2465
+		}
2466
+		if (array_key_exists('group_by', $query_params)) {
2467
+			if (is_array($query_params['group_by'])) {
2468
+				$this->_extract_related_models_from_sub_params_array_values($query_params['group_by'], $query_info_carrier, 'group_by');
2469
+			}elseif ( ! empty ($query_params['group_by'])) {
2470
+				$this->_extract_related_model_info_from_query_param($query_params['group_by'], $query_info_carrier, 'group_by');
2471 2471
 			}
2472 2472
 		}
2473
-		if(array_key_exists('having',$query_params)){
2474
-			$this->_extract_related_models_from_sub_params_array_keys($query_params[0], $query_info_carrier,'having');
2473
+		if (array_key_exists('having', $query_params)) {
2474
+			$this->_extract_related_models_from_sub_params_array_keys($query_params[0], $query_info_carrier, 'having');
2475 2475
 		}
2476
-		if(array_key_exists('order_by', $query_params)){
2477
-			if ( is_array( $query_params['order_by'] ) )
2478
-				$this->_extract_related_models_from_sub_params_array_keys($query_params['order_by'],$query_info_carrier,'order_by');
2479
-			elseif( ! empty( $query_params['order_by'] ))
2480
-				$this->_extract_related_model_info_from_query_param( $query_params['order_by'], $query_info_carrier,'order_by');
2476
+		if (array_key_exists('order_by', $query_params)) {
2477
+			if (is_array($query_params['order_by']))
2478
+				$this->_extract_related_models_from_sub_params_array_keys($query_params['order_by'], $query_info_carrier, 'order_by');
2479
+			elseif ( ! empty($query_params['order_by']))
2480
+				$this->_extract_related_model_info_from_query_param($query_params['order_by'], $query_info_carrier, 'order_by');
2481 2481
 		}
2482
-		if(array_key_exists('force_join', $query_params)){
2483
-			$this->_extract_related_models_from_sub_params_array_values($query_params['force_join'],$query_info_carrier,'force_join');
2482
+		if (array_key_exists('force_join', $query_params)) {
2483
+			$this->_extract_related_models_from_sub_params_array_values($query_params['force_join'], $query_info_carrier, 'force_join');
2484 2484
 		}
2485 2485
 		return $query_info_carrier;
2486 2486
 	}
@@ -2493,34 +2493,34 @@  discard block
 block discarded – undo
2493 2493
 	 * @throws EE_Error
2494 2494
 	 * @return \EE_Model_Query_Info_Carrier
2495 2495
 	 */
2496
-	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){
2497
-		if (!empty($sub_query_params)){
2496
+	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) {
2497
+		if ( ! empty($sub_query_params)) {
2498 2498
 			$sub_query_params = (array) $sub_query_params;
2499
-			foreach($sub_query_params as $param => $possibly_array_of_params){
2499
+			foreach ($sub_query_params as $param => $possibly_array_of_params) {
2500 2500
 				//$param could be simply 'EVT_ID', or it could be 'Registrations.REG_ID', or even 'Registrations.Transactions.Payments.PAY_amount'
2501
-				$this->_extract_related_model_info_from_query_param( $param, $model_query_info_carrier,$query_param_type);
2501
+				$this->_extract_related_model_info_from_query_param($param, $model_query_info_carrier, $query_param_type);
2502 2502
 
2503 2503
 				//if $possibly_array_of_params is an array, try recursing into it, searching for keys which
2504 2504
 				//indicate needed joins. Eg, array('NOT'=>array('Registration.TXN_ID'=>23)). In this case, we tried
2505 2505
 				//extracting models out of the 'NOT', which obviously wasn't successful, and then we recurse into the value
2506 2506
 				//of array('Registration.TXN_ID'=>23)
2507 2507
 				$query_param_sans_stars = $this->_remove_stars_and_anything_after_from_condition_query_param_key($param);
2508
-				if(in_array($query_param_sans_stars, $this->_logic_query_param_keys,true)){
2509
-					if (! is_array($possibly_array_of_params)){
2508
+				if (in_array($query_param_sans_stars, $this->_logic_query_param_keys, true)) {
2509
+					if ( ! is_array($possibly_array_of_params)) {
2510 2510
 						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"),
2511
-							$param,$possibly_array_of_params));
2512
-					}else{
2513
-						$this->_extract_related_models_from_sub_params_array_keys($possibly_array_of_params, $model_query_info_carrier,$query_param_type);
2511
+							$param, $possibly_array_of_params));
2512
+					} else {
2513
+						$this->_extract_related_models_from_sub_params_array_keys($possibly_array_of_params, $model_query_info_carrier, $query_param_type);
2514 2514
 					}
2515
-				}elseif($query_param_type === 0 //ie WHERE
2515
+				}elseif ($query_param_type === 0 //ie WHERE
2516 2516
 						&& is_array($possibly_array_of_params)
2517 2517
 						&& isset($possibly_array_of_params[2])
2518
-						&& $possibly_array_of_params[2] == true){
2518
+						&& $possibly_array_of_params[2] == true) {
2519 2519
 					//then $possible_array_of_params looks something like array('<','DTT_sold',true)
2520 2520
 					//indicating that $possible_array_of_params[1] is actually a field name,
2521 2521
 					//from which we should extract query parameters!
2522
-					if(! isset($possibly_array_of_params[0]) || ! isset($possibly_array_of_params[1])){
2523
-						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)));
2522
+					if ( ! isset($possibly_array_of_params[0]) || ! isset($possibly_array_of_params[1])) {
2523
+						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)));
2524 2524
 					}
2525 2525
 					$this->_extract_related_model_info_from_query_param($possibly_array_of_params[1], $model_query_info_carrier, $query_param_type);
2526 2526
 				}
@@ -2539,14 +2539,14 @@  discard block
 block discarded – undo
2539 2539
 	 * @throws EE_Error
2540 2540
 	 * @return \EE_Model_Query_Info_Carrier
2541 2541
 	 */
2542
-	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){
2543
-		if (!empty($sub_query_params)){
2544
-			if(!is_array($sub_query_params)){
2545
-				throw new EE_Error(sprintf(__("Query parameter %s should be an array, but it isn't.", "event_espresso"),$sub_query_params));
2542
+	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) {
2543
+		if ( ! empty($sub_query_params)) {
2544
+			if ( ! is_array($sub_query_params)) {
2545
+				throw new EE_Error(sprintf(__("Query parameter %s should be an array, but it isn't.", "event_espresso"), $sub_query_params));
2546 2546
 			}
2547
-			foreach($sub_query_params as $param){
2547
+			foreach ($sub_query_params as $param) {
2548 2548
 				//$param could be simply 'EVT_ID', or it could be 'Registrations.REG_ID', or even 'Registrations.Transactions.Payments.PAY_amount'
2549
-				$this->_extract_related_model_info_from_query_param( $param, $model_query_info_carrier, $query_param_type);
2549
+				$this->_extract_related_model_info_from_query_param($param, $model_query_info_carrier, $query_param_type);
2550 2550
 			}
2551 2551
 		}
2552 2552
 		return $model_query_info_carrier;
@@ -2565,81 +2565,81 @@  discard block
 block discarded – undo
2565 2565
 	 * @throws EE_Error
2566 2566
 	 * @return EE_Model_Query_Info_Carrier
2567 2567
 	 */
2568
-	function _create_model_query_info_carrier($query_params){
2569
-		if( ! is_array( $query_params ) ){
2570
-			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' );
2568
+	function _create_model_query_info_carrier($query_params) {
2569
+		if ( ! is_array($query_params)) {
2570
+			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');
2571 2571
 			$query_params = array();
2572 2572
 		}
2573
-		if( isset( $query_params[0] ) ) {
2573
+		if (isset($query_params[0])) {
2574 2574
 			$where_query_params = $query_params[0];
2575
-		}else{
2575
+		} else {
2576 2576
 			$where_query_params = array();
2577 2577
 		}
2578 2578
 		//first check if we should alter the query to account for caps or not
2579 2579
 		//because the caps might require us to do extra joins
2580
-		if( isset( $query_params[ 'caps' ] ) && $query_params[ 'caps' ] != 'none' ) {
2581
-			$query_params[0] = $where_query_params = array_replace_recursive( $where_query_params, $this->caps_where_conditions( $query_params[ 'caps' ] ) );
2580
+		if (isset($query_params['caps']) && $query_params['caps'] != 'none') {
2581
+			$query_params[0] = $where_query_params = array_replace_recursive($where_query_params, $this->caps_where_conditions($query_params['caps']));
2582 2582
 		}
2583 2583
 		$query_object = $this->_extract_related_models_from_query($query_params);
2584 2584
 
2585 2585
 		//verify where_query_params has NO numeric indexes.... that's simply not how you use it!
2586
-		foreach($where_query_params as $key => $value){
2587
-			if(is_int($key)){
2588
-				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)));
2586
+		foreach ($where_query_params as $key => $value) {
2587
+			if (is_int($key)) {
2588
+				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)));
2589 2589
 			}
2590 2590
 		}
2591
-		if( array_key_exists( 'default_where_conditions',$query_params) && ! empty( $query_params['default_where_conditions'] )){
2591
+		if (array_key_exists('default_where_conditions', $query_params) && ! empty($query_params['default_where_conditions'])) {
2592 2592
 			$use_default_where_conditions = $query_params['default_where_conditions'];
2593
-		}else{
2593
+		} else {
2594 2594
 			$use_default_where_conditions = 'all';
2595 2595
 		}
2596
-		$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 );
2597
-		$query_object->set_where_sql( $this->_construct_where_clause($where_query_params));
2596
+		$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);
2597
+		$query_object->set_where_sql($this->_construct_where_clause($where_query_params));
2598 2598
 
2599 2599
 
2600 2600
 		//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:
2601 2601
 		//array( 'on_join_limit' => array('Primary_Table_Alias', array(1,10) ) )
2602
-		if ( array_key_exists('on_join_limit', $query_params ) && ! empty( $query_params['on_join_limit'] )) {
2603
-			$query_object->set_main_model_join_sql( $this->_construct_limit_join_select( $query_params['on_join_limit'][0], $query_params['on_join_limit'][1] ) );
2602
+		if (array_key_exists('on_join_limit', $query_params) && ! empty($query_params['on_join_limit'])) {
2603
+			$query_object->set_main_model_join_sql($this->_construct_limit_join_select($query_params['on_join_limit'][0], $query_params['on_join_limit'][1]));
2604 2604
 		}
2605 2605
 
2606 2606
 
2607 2607
 		//set limit
2608
-		if(array_key_exists('limit',$query_params)){
2609
-			if(is_array($query_params['limit'])){
2610
-				if( ! isset($query_params['limit'][0]) || ! isset($query_params['limit'][1])){
2611
-					$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']));
2608
+		if (array_key_exists('limit', $query_params)) {
2609
+			if (is_array($query_params['limit'])) {
2610
+				if ( ! isset($query_params['limit'][0]) || ! isset($query_params['limit'][1])) {
2611
+					$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']));
2612 2612
 					throw new EE_Error($e."|".$e);
2613 2613
 				}
2614 2614
 				//they passed us an array for the limit. Assume it's like array(50,25), meaning offset by 50, and get 25
2615 2615
 				$query_object->set_limit_sql(" LIMIT ".$query_params['limit'][0].",".$query_params['limit'][1]);
2616
-			}elseif( ! empty ( $query_params['limit'] )){
2616
+			}elseif ( ! empty ($query_params['limit'])) {
2617 2617
 				$query_object->set_limit_sql((" LIMIT ".$query_params['limit']));
2618 2618
 			}
2619 2619
 		}
2620 2620
 		//set order by
2621
-		if(array_key_exists('order_by',$query_params)){
2622
-			if(is_array($query_params['order_by'])){
2621
+		if (array_key_exists('order_by', $query_params)) {
2622
+			if (is_array($query_params['order_by'])) {
2623 2623
 				//if they're using 'order_by' as an array, they can't use 'order' (because 'order_by' must
2624 2624
 				//specify whether to ascend or descend on each field. Eg 'order_by'=>array('EVT_ID'=>'ASC'). So
2625 2625
 				//including 'order' wouldn't make any sense if 'order_by' has already specified which way to order!
2626
-				if(array_key_exists('order', $query_params)){
2626
+				if (array_key_exists('order', $query_params)) {
2627 2627
 					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"),
2628
-							get_class($this),implode(", ",array_keys($query_params['order_by'])),implode(", ",$query_params['order_by']),$query_params['order']));
2628
+							get_class($this), implode(", ", array_keys($query_params['order_by'])), implode(", ", $query_params['order_by']), $query_params['order']));
2629 2629
 				}
2630
-				 $this->_extract_related_models_from_sub_params_array_keys($query_params['order_by'],$query_object,'order_by');
2630
+				 $this->_extract_related_models_from_sub_params_array_keys($query_params['order_by'], $query_object, 'order_by');
2631 2631
 				//assume it's an array of fields to order by
2632 2632
 				$order_array = array();
2633
-				foreach($query_params['order_by'] as $field_name_to_order_by => $order){
2633
+				foreach ($query_params['order_by'] as $field_name_to_order_by => $order) {
2634 2634
 					$order = $this->_extract_order($order);
2635 2635
 					$order_array[] = $this->_deduce_column_name_from_query_param($field_name_to_order_by).SP.$order;
2636 2636
 				}
2637
-				$query_object->set_order_by_sql(" ORDER BY ".implode(",",$order_array));
2638
-			}elseif( ! empty ( $query_params['order_by'] )){
2639
-				$this->_extract_related_model_info_from_query_param($query_params['order_by'],$query_object,'order',$query_params['order_by']);
2640
-				if(isset($query_params['order'])){
2637
+				$query_object->set_order_by_sql(" ORDER BY ".implode(",", $order_array));
2638
+			}elseif ( ! empty ($query_params['order_by'])) {
2639
+				$this->_extract_related_model_info_from_query_param($query_params['order_by'], $query_object, 'order', $query_params['order_by']);
2640
+				if (isset($query_params['order'])) {
2641 2641
 					$order = $this->_extract_order($query_params['order']);
2642
-				}else{
2642
+				} else {
2643 2643
 					$order = 'DESC';
2644 2644
 				}
2645 2645
 				$query_object->set_order_by_sql(" ORDER BY ".$this->_deduce_column_name_from_query_param($query_params['order_by']).SP.$order);
@@ -2647,46 +2647,46 @@  discard block
 block discarded – undo
2647 2647
 		}
2648 2648
 
2649 2649
 		//if 'order_by' wasn't set, maybe they are just using 'order' on its own?
2650
-		if( ! array_key_exists('order_by',$query_params) && array_key_exists('order',$query_params) && ! empty( $query_params['order'] )){
2650
+		if ( ! array_key_exists('order_by', $query_params) && array_key_exists('order', $query_params) && ! empty($query_params['order'])) {
2651 2651
 			$pk_field = $this->get_primary_key_field();
2652 2652
 			$order = $this->_extract_order($query_params['order']);
2653 2653
 			$query_object->set_order_by_sql(" ORDER BY ".$pk_field->get_qualified_column().SP.$order);
2654 2654
 		}
2655 2655
 
2656 2656
 		//set group by
2657
-		if(array_key_exists('group_by',$query_params)){
2658
-			if(is_array($query_params['group_by'])){
2657
+		if (array_key_exists('group_by', $query_params)) {
2658
+			if (is_array($query_params['group_by'])) {
2659 2659
 				//it's an array, so assume we'll be grouping by a bunch of stuff
2660 2660
 				$group_by_array = array();
2661
-				foreach($query_params['group_by'] as $field_name_to_group_by){
2661
+				foreach ($query_params['group_by'] as $field_name_to_group_by) {
2662 2662
 					$group_by_array[] = $this->_deduce_column_name_from_query_param($field_name_to_group_by);
2663 2663
 				}
2664
-				$query_object->set_group_by_sql(" GROUP BY ".implode(", ",$group_by_array));
2665
-			}elseif( ! empty ( $query_params['group_by'] )){
2664
+				$query_object->set_group_by_sql(" GROUP BY ".implode(", ", $group_by_array));
2665
+			}elseif ( ! empty ($query_params['group_by'])) {
2666 2666
 				$query_object->set_group_by_sql(" GROUP BY ".$this->_deduce_column_name_from_query_param($query_params['group_by']));
2667 2667
 			}
2668 2668
 		}
2669 2669
 		//set having
2670
-		if(array_key_exists('having',$query_params) && $query_params['having']){
2671
-			$query_object->set_having_sql( $this->_construct_having_clause($query_params['having']));
2670
+		if (array_key_exists('having', $query_params) && $query_params['having']) {
2671
+			$query_object->set_having_sql($this->_construct_having_clause($query_params['having']));
2672 2672
 		}
2673 2673
 
2674 2674
 		//now, just verify they didn't pass anything wack
2675
-		foreach($query_params as $query_key => $query_value){
2676
-			if( ! in_array($query_key,$this->_allowed_query_params,true)){
2675
+		foreach ($query_params as $query_key => $query_value) {
2676
+			if ( ! in_array($query_key, $this->_allowed_query_params, true)) {
2677 2677
 				throw new EE_Error(
2678 2678
 					sprintf(
2679
-						__("You passed %s as a query parameter to %s, which is illegal! The allowed query parameters are %s",'event_espresso'),
2679
+						__("You passed %s as a query parameter to %s, which is illegal! The allowed query parameters are %s", 'event_espresso'),
2680 2680
 						$query_key,
2681 2681
 						get_class($this),
2682 2682
 //						print_r( $this->_allowed_query_params, TRUE )
2683
-						implode( ',', $this->_allowed_query_params )
2683
+						implode(',', $this->_allowed_query_params)
2684 2684
 					)
2685 2685
 				);
2686 2686
 			}
2687 2687
 		}
2688 2688
 		$main_model_join_sql = $query_object->get_main_model_join_sql();
2689
-		if ( empty( $main_model_join_sql ) )
2689
+		if (empty($main_model_join_sql))
2690 2690
 			$query_object->set_main_model_join_sql($this->_construct_internal_join());
2691 2691
 		return $query_object;
2692 2692
 	}
@@ -2697,17 +2697,17 @@  discard block
 block discarded – undo
2697 2697
 	 * @param string $context one of EEM_Base::valid_cap_contexts()
2698 2698
 	 * @return array like EEM_Base::get_all() 's $query_params[0]
2699 2699
 	 */
2700
-	public function caps_where_conditions( $context = self::caps_read ) {
2701
-		EEM_Base::verify_is_valid_cap_context( $context );
2700
+	public function caps_where_conditions($context = self::caps_read) {
2701
+		EEM_Base::verify_is_valid_cap_context($context);
2702 2702
 		$cap_where_conditions = array();
2703
-		$cap_restrictions = $this->caps_missing( $context );
2703
+		$cap_restrictions = $this->caps_missing($context);
2704 2704
 		/**
2705 2705
 		 * @var $cap_restrictions EE_Default_Where_Conditions[]
2706 2706
 		 */
2707
-		foreach( $cap_restrictions as $cap => $restriction_if_no_cap ) {
2708
-				$cap_where_conditions = array_replace_recursive( $cap_where_conditions, $restriction_if_no_cap->get_default_where_conditions() );
2707
+		foreach ($cap_restrictions as $cap => $restriction_if_no_cap) {
2708
+				$cap_where_conditions = array_replace_recursive($cap_where_conditions, $restriction_if_no_cap->get_default_where_conditions());
2709 2709
 		}
2710
-		return apply_filters( 'FHEE__EEM_Base__caps_where_conditions__return', $cap_where_conditions, $this, $context, $cap_restrictions );
2710
+		return apply_filters('FHEE__EEM_Base__caps_where_conditions__return', $cap_where_conditions, $this, $context, $cap_restrictions);
2711 2711
 	}
2712 2712
 
2713 2713
 	/**
@@ -2717,11 +2717,11 @@  discard block
 block discarded – undo
2717 2717
 	 * @return string either ASC, asc, DESC or desc
2718 2718
 	 * @throws EE_Error
2719 2719
 	 */
2720
-	private function _extract_order($should_be_order_string){
2721
-		if(in_array($should_be_order_string, $this->_allowed_order_values)){
2720
+	private function _extract_order($should_be_order_string) {
2721
+		if (in_array($should_be_order_string, $this->_allowed_order_values)) {
2722 2722
 			return $should_be_order_string;
2723
-		}else{
2724
-			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));
2723
+		} else {
2724
+			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));
2725 2725
 		}
2726 2726
 	}
2727 2727
 
@@ -2739,25 +2739,25 @@  discard block
 block discarded – undo
2739 2739
 	 * @throws EE_Error
2740 2740
 	 * @return array like $query_params[0], see EEM_Base::get_all for documentation
2741 2741
 	 */
2742
-	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()){
2743
-		$allowed_used_default_where_conditions_values = array('all', 'minimum', 'this_model_only', 'other_models_only','none');
2744
-		if( ! in_array($use_default_where_conditions,$allowed_used_default_where_conditions_values)){
2745
-			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)));
2742
+	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()) {
2743
+		$allowed_used_default_where_conditions_values = array('all', 'minimum', 'this_model_only', 'other_models_only', 'none');
2744
+		if ( ! in_array($use_default_where_conditions, $allowed_used_default_where_conditions_values)) {
2745
+			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)));
2746 2746
 		}
2747
-		if( in_array($use_default_where_conditions, array('all','this_model_only')) ){
2747
+		if (in_array($use_default_where_conditions, array('all', 'this_model_only'))) {
2748 2748
 			$universal_query_params = $this->_get_default_where_conditions();
2749
-		}elseif( $use_default_where_conditions == 'minimum' ) {
2749
+		}elseif ($use_default_where_conditions == 'minimum') {
2750 2750
 			$universal_query_params = $this->_get_minimum_where_conditions();
2751
-		}else{
2751
+		} else {
2752 2752
 			$universal_query_params = array();
2753 2753
 		}
2754 2754
 
2755
-		if(in_array($use_default_where_conditions,array('all', 'minimum',  'other_models_only'))){
2756
-			foreach($query_info_carrier->get_model_names_included() as $model_relation_path => $model_name){
2755
+		if (in_array($use_default_where_conditions, array('all', 'minimum', 'other_models_only'))) {
2756
+			foreach ($query_info_carrier->get_model_names_included() as $model_relation_path => $model_name) {
2757 2757
 				$related_model = $this->get_related_model_obj($model_name);
2758
-				if( $use_default_where_conditions == 'minimum' ) {
2758
+				if ($use_default_where_conditions == 'minimum') {
2759 2759
 					$related_model_universal_where_params = $related_model->_get_minimum_where_conditions($model_relation_path);
2760
-				}else{
2760
+				} else {
2761 2761
 					$related_model_universal_where_params = $related_model->_get_default_where_conditions($model_relation_path);
2762 2762
 				}
2763 2763
 
@@ -2784,22 +2784,22 @@  discard block
 block discarded – undo
2784 2784
 	 * @param string $model_relation_path like 'Transaction.Payment.'
2785 2785
 	 * @return array like EEM_Base::get_all's $query_params[0]
2786 2786
 	 */
2787
-	private function _override_defaults_or_make_null_friendly($default_where_conditions,$provided_where_conditions,$model,$model_relation_path){
2787
+	private function _override_defaults_or_make_null_friendly($default_where_conditions, $provided_where_conditions, $model, $model_relation_path) {
2788 2788
 		$null_friendly_where_conditions = array();
2789 2789
 		$none_overridden = true;
2790 2790
 		$or_condition_key_for_defaults = 'OR*'.get_class($model);
2791 2791
 
2792
-		foreach($default_where_conditions as $key => $val){
2793
-			if( isset($provided_where_conditions[$key])){
2792
+		foreach ($default_where_conditions as $key => $val) {
2793
+			if (isset($provided_where_conditions[$key])) {
2794 2794
 				$none_overridden = false;
2795
-			}else{
2795
+			} else {
2796 2796
 				$null_friendly_where_conditions[$or_condition_key_for_defaults]['AND'][$key] = $val;
2797 2797
 			}
2798 2798
 		}
2799
-		if( $none_overridden && $default_where_conditions){
2800
-			if($model->has_primary_key_field()){
2799
+		if ($none_overridden && $default_where_conditions) {
2800
+			if ($model->has_primary_key_field()) {
2801 2801
 				$null_friendly_where_conditions[$or_condition_key_for_defaults][$model_relation_path.".".$model->primary_key_name()] = array('IS NULL');
2802
-			}else{
2802
+			} else {
2803 2803
 				//@todo NO PK, use other defaults
2804 2804
 			}
2805 2805
 		}
@@ -2814,8 +2814,8 @@  discard block
 block discarded – undo
2814 2814
 	 * @param string $model_relation_path eg, path from Event to Payment is "Registration.Transaction.Payment."
2815 2815
 	 * @return array like EEM_Base::get_all's $query_params[0] (where conditions)
2816 2816
 	 */
2817
-	protected function _get_default_where_conditions($model_relation_path = null){
2818
-		if ( $this->_ignore_where_strategy )
2817
+	protected function _get_default_where_conditions($model_relation_path = null) {
2818
+		if ($this->_ignore_where_strategy)
2819 2819
 			return array();
2820 2820
 
2821 2821
 		return $this->_default_where_conditions_strategy->get_default_where_conditions($model_relation_path);
@@ -2829,8 +2829,8 @@  discard block
 block discarded – undo
2829 2829
 	 * @param string $model_relation_path eg, path from Event to Payment is "Registration.Transaction.Payment."
2830 2830
 	 * @return array like EEM_Base::get_all's $query_params[0] (where conditions)
2831 2831
 	 */
2832
-	private function _get_minimum_where_conditions($model_relation_path = null){
2833
-		if ( $this->_ignore_where_strategy )
2832
+	private function _get_minimum_where_conditions($model_relation_path = null) {
2833
+		if ($this->_ignore_where_strategy)
2834 2834
 			return array();
2835 2835
 
2836 2836
 		return $this->_default_where_conditions_strategy->get_minimum_where_conditions($model_relation_path);
@@ -2841,13 +2841,13 @@  discard block
 block discarded – undo
2841 2841
 	 * @param EE_Model_Query_Info_Carrier $model_query_info
2842 2842
 	 * @return string
2843 2843
 	 */
2844
-	private function _construct_default_select_sql(EE_Model_Query_Info_Carrier $model_query_info){
2844
+	private function _construct_default_select_sql(EE_Model_Query_Info_Carrier $model_query_info) {
2845 2845
 		$selects = $this->_get_columns_to_select_for_this_model();
2846
-		foreach($model_query_info->get_model_names_included() as $model_relation_chain => $name_of_other_model_included){
2846
+		foreach ($model_query_info->get_model_names_included() as $model_relation_chain => $name_of_other_model_included) {
2847 2847
 			$other_model_included = $this->get_related_model_obj($name_of_other_model_included);
2848 2848
 			$selects = array_merge($selects, $other_model_included->_get_columns_to_select_for_this_model($model_relation_chain));
2849 2849
 		}
2850
-		return implode(", ",$selects);
2850
+		return implode(", ", $selects);
2851 2851
 	}
2852 2852
 
2853 2853
 	/**
@@ -2856,19 +2856,19 @@  discard block
 block discarded – undo
2856 2856
 	 * @param string $model_relation_chain like 'Question.Question_Group.Event'
2857 2857
 	 * @return array numerically indexed, values are columns to select and rename, eg "Event.ID AS 'Event.ID'"
2858 2858
 	 */
2859
-	public function _get_columns_to_select_for_this_model($model_relation_chain = ''){
2859
+	public function _get_columns_to_select_for_this_model($model_relation_chain = '') {
2860 2860
 		$fields = $this->field_settings();
2861 2861
 		$selects = array();
2862 2862
 		$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());
2863
-		foreach($fields as $field_obj){
2864
-			$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()."'";
2863
+		foreach ($fields as $field_obj) {
2864
+			$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()."'";
2865 2865
 		}
2866 2866
 		//make sure we are also getting the PKs of each table
2867 2867
 		$tables = $this->get_tables();
2868
-		if(count($tables) > 1){
2869
-			foreach($tables as $table_obj){
2870
-				$qualified_pk_column = $table_alias_with_model_relation_chain_prefix . $table_obj->get_fully_qualified_pk_column();
2871
-				if( ! in_array($qualified_pk_column,$selects)){
2868
+		if (count($tables) > 1) {
2869
+			foreach ($tables as $table_obj) {
2870
+				$qualified_pk_column = $table_alias_with_model_relation_chain_prefix.$table_obj->get_fully_qualified_pk_column();
2871
+				if ( ! in_array($qualified_pk_column, $selects)) {
2872 2872
 					$selects[] = "$qualified_pk_column AS '$qualified_pk_column'";
2873 2873
 				}
2874 2874
 			}
@@ -2892,66 +2892,66 @@  discard block
 block discarded – undo
2892 2892
 	 * @throws EE_Error
2893 2893
 	 * @return void only modifies the EEM_Related_Model_Info_Carrier passed into it
2894 2894
 	 */
2895
-	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 ){
2896
-		if($original_query_param == NULL){
2895
+	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) {
2896
+		if ($original_query_param == NULL) {
2897 2897
 			$original_query_param = $query_param;
2898 2898
 		}
2899 2899
 		$query_param = $this->_remove_stars_and_anything_after_from_condition_query_param_key($query_param);
2900 2900
 		/** @var $allow_logic_query_params bool whether or not to allow logic_query_params like 'NOT','OR', or 'AND' */
2901
-		$allow_logic_query_params = in_array($query_param_type,array('where','having'));
2902
-		$allow_fields = in_array($query_param_type,array('where','having','order_by','group_by','order'));
2901
+		$allow_logic_query_params = in_array($query_param_type, array('where', 'having'));
2902
+		$allow_fields = in_array($query_param_type, array('where', 'having', 'order_by', 'group_by', 'order'));
2903 2903
 		//check to see if we have a field on this model
2904 2904
 		$this_model_fields = $this->field_settings(true);
2905
-		if(array_key_exists($query_param,$this_model_fields)){
2906
-			if($allow_fields){
2905
+		if (array_key_exists($query_param, $this_model_fields)) {
2906
+			if ($allow_fields) {
2907 2907
 				return;
2908
-			}else{
2908
+			} else {
2909 2909
 				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"),
2910
-						$query_param,get_class($this),$query_param_type,$original_query_param));
2910
+						$query_param, get_class($this), $query_param_type, $original_query_param));
2911 2911
 			}
2912 2912
 		}
2913 2913
 		//check if this is a special logic query param
2914
-		elseif(in_array($query_param, $this->_logic_query_param_keys, TRUE)){
2915
-			if($allow_logic_query_params){
2914
+		elseif (in_array($query_param, $this->_logic_query_param_keys, TRUE)) {
2915
+			if ($allow_logic_query_params) {
2916 2916
 				return;
2917
-			}else{
2917
+			} else {
2918 2918
 				throw new EE_Error(
2919 2919
 					sprintf(
2920
-						__( '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' ),
2921
-						implode( '", "', $this->_logic_query_param_keys ),
2922
-						$query_param ,
2923
-						get_class( $this ),
2920
+						__('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'),
2921
+						implode('", "', $this->_logic_query_param_keys),
2922
+						$query_param,
2923
+						get_class($this),
2924 2924
 						'<br />',
2925
-						"\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
2925
+						"\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
2926 2926
 					)
2927 2927
 				);
2928 2928
 			}
2929 2929
 		}
2930 2930
 
2931 2931
 		//check if it's a custom selection
2932
-		elseif(array_key_exists($query_param,$this->_custom_selections)){
2932
+		elseif (array_key_exists($query_param, $this->_custom_selections)) {
2933 2933
 			return;
2934 2934
 		}
2935 2935
 
2936 2936
 		//check if has a model name at the beginning
2937 2937
 		//and
2938 2938
 		//check if it's a field on a related model
2939
-		foreach($this->_model_relations as $valid_related_model_name=>$relation_obj){
2940
-			if(strpos($query_param, $valid_related_model_name.".") === 0){
2941
-				$this->_add_join_to_model($valid_related_model_name, $passed_in_query_info,$original_query_param);
2939
+		foreach ($this->_model_relations as $valid_related_model_name=>$relation_obj) {
2940
+			if (strpos($query_param, $valid_related_model_name.".") === 0) {
2941
+				$this->_add_join_to_model($valid_related_model_name, $passed_in_query_info, $original_query_param);
2942 2942
 				$query_param = substr($query_param, strlen($valid_related_model_name."."));
2943
-				if($query_param == ''){
2943
+				if ($query_param == '') {
2944 2944
 					//nothing left to $query_param
2945 2945
 					//we should actually end in a field name, not a model like this!
2946 2946
 					throw new EE_Error(sprintf(__("Query param '%s' (of type %s on model %s) shouldn't end on a period (.) ", "event_espresso"),
2947
-					$query_param,$query_param_type,get_class($this),$valid_related_model_name));
2948
-				}else{
2947
+					$query_param, $query_param_type, get_class($this), $valid_related_model_name));
2948
+				} else {
2949 2949
 					$related_model_obj = $this->get_related_model_obj($valid_related_model_name);
2950 2950
 					$related_model_obj->_extract_related_model_info_from_query_param($query_param, $passed_in_query_info, $query_param_type, $original_query_param);
2951 2951
 					return;
2952 2952
 				}
2953
-			}elseif($query_param == $valid_related_model_name){
2954
-				$this->_add_join_to_model($valid_related_model_name, $passed_in_query_info,$original_query_param);
2953
+			}elseif ($query_param == $valid_related_model_name) {
2954
+				$this->_add_join_to_model($valid_related_model_name, $passed_in_query_info, $original_query_param);
2955 2955
 				return;
2956 2956
 			}
2957 2957
 		}
@@ -2961,7 +2961,7 @@  discard block
 block discarded – undo
2961 2961
 		//and we previously confirmed it wasn't a logic query param or field on the current model
2962 2962
 		//it's wack, that's what it is
2963 2963
 		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"),
2964
-				$query_param,get_class($this),$query_param_type,$original_query_param));
2964
+				$query_param, get_class($this), $query_param_type, $original_query_param));
2965 2965
 
2966 2966
 	}
2967 2967
 
@@ -2978,26 +2978,26 @@  discard block
 block discarded – undo
2978 2978
 	 * 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)
2979 2979
 	 * @return void
2980 2980
 	 */
2981
-	private function _add_join_to_model($model_name, EE_Model_Query_Info_Carrier $passed_in_query_info,$original_query_param){
2981
+	private function _add_join_to_model($model_name, EE_Model_Query_Info_Carrier $passed_in_query_info, $original_query_param) {
2982 2982
 		$relation_obj = $this->related_settings_for($model_name);
2983 2983
 
2984 2984
 		$model_relation_chain = EE_Model_Parser::extract_model_relation_chain($model_name, $original_query_param);
2985 2985
 		//check if the relation is HABTM, because then we're essentially doing two joins
2986 2986
 		//If so, join first to the JOIN table, and add its data types, and then continue as normal
2987
-		if($relation_obj instanceof EE_HABTM_Relation){
2987
+		if ($relation_obj instanceof EE_HABTM_Relation) {
2988 2988
 			$join_model_obj = $relation_obj->get_join_model();
2989 2989
 			//replace the model specified with the join model for this relation chain, whi
2990 2990
 			$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);
2991 2991
 			$new_query_info = new EE_Model_Query_Info_Carrier(
2992 2992
 					array($relation_chain_to_join_model => $join_model_obj->get_this_model_name()),
2993 2993
 					$relation_obj->get_join_to_intermediate_model_statement($relation_chain_to_join_model));
2994
-			$passed_in_query_info->merge( $new_query_info  );
2994
+			$passed_in_query_info->merge($new_query_info);
2995 2995
 		}
2996 2996
 		//now just join to the other table pointed to by the relation object, and add its data types
2997 2997
 		$new_query_info = new EE_Model_Query_Info_Carrier(
2998 2998
 				array($model_relation_chain=>$model_name),
2999 2999
 				$relation_obj->get_join_statement($model_relation_chain));
3000
-		$passed_in_query_info->merge( $new_query_info  );
3000
+		$passed_in_query_info->merge($new_query_info);
3001 3001
 	}
3002 3002
 
3003 3003
 
@@ -3006,11 +3006,11 @@  discard block
 block discarded – undo
3006 3006
 	 * @param array $where_params like EEM_Base::get_all
3007 3007
 	 * @return string of SQL
3008 3008
 	 */
3009
-	private function _construct_where_clause($where_params){
3009
+	private function _construct_where_clause($where_params) {
3010 3010
 		$SQL = $this->_construct_condition_clause_recursive($where_params, ' AND ');
3011
-		if($SQL){
3012
-			return " WHERE ". $SQL;
3013
-		}else{
3011
+		if ($SQL) {
3012
+			return " WHERE ".$SQL;
3013
+		} else {
3014 3014
 			return '';
3015 3015
 		}
3016 3016
 	}
@@ -3021,11 +3021,11 @@  discard block
 block discarded – undo
3021 3021
 	 * @param array $having_params
3022 3022
 	 * @return string
3023 3023
 	 */
3024
-	private function _construct_having_clause($having_params){
3024
+	private function _construct_having_clause($having_params) {
3025 3025
 		$SQL = $this->_construct_condition_clause_recursive($having_params, ' AND ');
3026
-		if($SQL){
3027
-			return " HAVING ". $SQL;
3028
-		}else{
3026
+		if ($SQL) {
3027
+			return " HAVING ".$SQL;
3028
+		} else {
3029 3029
 			return '';
3030 3030
 		}
3031 3031
 
@@ -3039,17 +3039,17 @@  discard block
 block discarded – undo
3039 3039
 	 * @return EE_Model_Field_Base
3040 3040
 	 * @throws EE_Error
3041 3041
 	 */
3042
-	protected function _get_field_on_model($field_name,$model_name){
3042
+	protected function _get_field_on_model($field_name, $model_name) {
3043 3043
 		$model_class = 'EEM_'.$model_name;
3044 3044
 		$model_filepath = $model_class.".model.php";
3045
-		EE_Registry::instance()->load_helper( 'File' );
3046
-		if ( is_readable($model_filepath)){
3045
+		EE_Registry::instance()->load_helper('File');
3046
+		if (is_readable($model_filepath)) {
3047 3047
 			require_once($model_filepath);
3048
-			$model_instance=call_user_func($model_name."::instance");
3048
+			$model_instance = call_user_func($model_name."::instance");
3049 3049
 			/* @var $model_instance EEM_Base */
3050 3050
 			return $model_instance->field_settings_for($field_name);
3051
-		}else{
3052
-			throw new EE_Error(sprintf(__('No model named %s exists, with classname %s and filepath %s','event_espresso'),$model_name,$model_class,$model_filepath));
3051
+		} else {
3052
+			throw new EE_Error(sprintf(__('No model named %s exists, with classname %s and filepath %s', 'event_espresso'), $model_name, $model_class, $model_filepath));
3053 3053
 		}
3054 3054
 	}
3055 3055
 
@@ -3062,43 +3062,43 @@  discard block
 block discarded – undo
3062 3062
 	 * @throws EE_Error
3063 3063
 	 * @return string of SQL
3064 3064
 	 */
3065
-	private function _construct_condition_clause_recursive($where_params, $glue = ' AND'){
3066
-		$where_clauses=array();
3067
-		foreach($where_params as $query_param => $op_and_value_or_sub_condition){
3068
-			$query_param = $this->_remove_stars_and_anything_after_from_condition_query_param_key($query_param);//str_replace("*",'',$query_param);
3069
-			if(in_array($query_param,$this->_logic_query_param_keys)){
3070
-				switch($query_param){
3065
+	private function _construct_condition_clause_recursive($where_params, $glue = ' AND') {
3066
+		$where_clauses = array();
3067
+		foreach ($where_params as $query_param => $op_and_value_or_sub_condition) {
3068
+			$query_param = $this->_remove_stars_and_anything_after_from_condition_query_param_key($query_param); //str_replace("*",'',$query_param);
3069
+			if (in_array($query_param, $this->_logic_query_param_keys)) {
3070
+				switch ($query_param) {
3071 3071
 					case 'not':
3072 3072
 					case 'NOT':
3073
-						$where_clauses[] = "! (". $this->_construct_condition_clause_recursive($op_and_value_or_sub_condition, $glue).")";
3073
+						$where_clauses[] = "! (".$this->_construct_condition_clause_recursive($op_and_value_or_sub_condition, $glue).")";
3074 3074
 						break;
3075 3075
 					case 'and':
3076 3076
 					case 'AND':
3077
-						$where_clauses[] = " (". $this->_construct_condition_clause_recursive($op_and_value_or_sub_condition, ' AND ') .")";
3077
+						$where_clauses[] = " (".$this->_construct_condition_clause_recursive($op_and_value_or_sub_condition, ' AND ').")";
3078 3078
 						break;
3079 3079
 					case 'or':
3080 3080
 					case 'OR':
3081
-						$where_clauses[] = " (". $this->_construct_condition_clause_recursive($op_and_value_or_sub_condition, ' OR ') .")";
3081
+						$where_clauses[] = " (".$this->_construct_condition_clause_recursive($op_and_value_or_sub_condition, ' OR ').")";
3082 3082
 						break;
3083 3083
 				}
3084
-			}else{
3084
+			} else {
3085 3085
 				$field_obj = $this->_deduce_field_from_query_param($query_param);
3086 3086
 
3087 3087
 				//if it's not a normal field, maybe it's a custom selection?
3088
-				if( ! $field_obj){
3089
-					if(isset( $this->_custom_selections[$query_param][1])){
3088
+				if ( ! $field_obj) {
3089
+					if (isset($this->_custom_selections[$query_param][1])) {
3090 3090
 						$field_obj = $this->_custom_selections[$query_param][1];
3091
-					}else{
3092
-						throw new EE_Error(sprintf(__("%s is neither a valid model field name, nor a custom selection", "event_espresso"),$query_param));
3091
+					} else {
3092
+						throw new EE_Error(sprintf(__("%s is neither a valid model field name, nor a custom selection", "event_espresso"), $query_param));
3093 3093
 					}
3094 3094
 				}
3095 3095
 				$op_and_value_sql = $this->_construct_op_and_value($op_and_value_or_sub_condition, $field_obj);
3096
-				$where_clauses[]=$this->_deduce_column_name_from_query_param($query_param).SP.$op_and_value_sql;
3096
+				$where_clauses[] = $this->_deduce_column_name_from_query_param($query_param).SP.$op_and_value_sql;
3097 3097
 			}
3098 3098
 		}
3099
-		if($where_clauses){
3100
-			$SQL = implode($glue,$where_clauses);
3101
-		}else{
3099
+		if ($where_clauses) {
3100
+			$SQL = implode($glue, $where_clauses);
3101
+		} else {
3102 3102
 			$SQL = '';
3103 3103
 		}
3104 3104
 		return $SQL;
@@ -3112,18 +3112,18 @@  discard block
 block discarded – undo
3112 3112
 	 * @throws EE_Error
3113 3113
 	 * @return string table alias and column name for SQL, eg "Transaction.TXN_ID"
3114 3114
 	 */
3115
-	private function _deduce_column_name_from_query_param($query_param){
3115
+	private function _deduce_column_name_from_query_param($query_param) {
3116 3116
 		$field = $this->_deduce_field_from_query_param($query_param);
3117 3117
 
3118
-		if( $field ){
3119
-			$table_alias_prefix = EE_Model_Parser::extract_table_alias_model_relation_chain_from_query_param( $field->get_model_name(), $query_param );
3120
-			return $table_alias_prefix . $field->get_qualified_column();
3121
-		}elseif(array_key_exists($query_param,$this->_custom_selections)){
3118
+		if ($field) {
3119
+			$table_alias_prefix = EE_Model_Parser::extract_table_alias_model_relation_chain_from_query_param($field->get_model_name(), $query_param);
3120
+			return $table_alias_prefix.$field->get_qualified_column();
3121
+		}elseif (array_key_exists($query_param, $this->_custom_selections)) {
3122 3122
 			//maybe it's custom selection item?
3123 3123
 			//if so, just use it as the "column name"
3124 3124
 			return $query_param;
3125
-		}else{
3126
-			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)));
3125
+		} else {
3126
+			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)));
3127 3127
 		}
3128 3128
 	}
3129 3129
 
@@ -3135,11 +3135,11 @@  discard block
 block discarded – undo
3135 3135
 	 * @param string $condition_query_param_key
3136 3136
 	 * @return string
3137 3137
 	 */
3138
-	private function _remove_stars_and_anything_after_from_condition_query_param_key($condition_query_param_key){
3138
+	private function _remove_stars_and_anything_after_from_condition_query_param_key($condition_query_param_key) {
3139 3139
 		$pos_of_star = strpos($condition_query_param_key, '*');
3140
-		if($pos_of_star === FALSE){
3140
+		if ($pos_of_star === FALSE) {
3141 3141
 			return $condition_query_param_key;
3142
-		}else{
3142
+		} else {
3143 3143
 			$condition_query_param_sans_star = substr($condition_query_param_key, 0, $pos_of_star);
3144 3144
 			return $condition_query_param_sans_star;
3145 3145
 		}
@@ -3154,54 +3154,54 @@  discard block
 block discarded – undo
3154 3154
 	 * @throws EE_Error
3155 3155
 	 * @return string
3156 3156
 	 */
3157
-	private function _construct_op_and_value($op_and_value, $field_obj){
3158
-		if(is_array( $op_and_value )){
3157
+	private function _construct_op_and_value($op_and_value, $field_obj) {
3158
+		if (is_array($op_and_value)) {
3159 3159
 			$operator = isset($op_and_value[0]) ? $this->_prepare_operator_for_sql($op_and_value[0]) : null;
3160
-			if( ! $operator){
3160
+			if ( ! $operator) {
3161 3161
 				$php_array_like_string = array();
3162
-				foreach($op_and_value as $key => $value){
3162
+				foreach ($op_and_value as $key => $value) {
3163 3163
 					$php_array_like_string[] = "$key=>$value";
3164 3164
 				}
3165
-				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)));
3165
+				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)));
3166 3166
 			}
3167 3167
 			$value = isset($op_and_value[1]) ? $op_and_value[1] : null;
3168
-		}else{
3168
+		} else {
3169 3169
 			$operator = '=';
3170 3170
 			$value = $op_and_value;
3171 3171
 		}
3172 3172
 
3173 3173
 		//check to see if the value is actually another field
3174
-		if(is_array($op_and_value) && isset($op_and_value[2]) && $op_and_value[2] == true){
3174
+		if (is_array($op_and_value) && isset($op_and_value[2]) && $op_and_value[2] == true) {
3175 3175
 			return $operator.SP.$this->_deduce_column_name_from_query_param($value);
3176
-		}elseif(in_array($operator, $this->_in_style_operators) && is_array($value)){
3176
+		}elseif (in_array($operator, $this->_in_style_operators) && is_array($value)) {
3177 3177
 			//in this case, the value should be an array, or at least a comma-separated list
3178 3178
 			//it will need to handle a little differently
3179 3179
 			$cleaned_value = $this->_construct_in_value($value, $field_obj);
3180 3180
 			//note: $cleaned_value has already been run through $wpdb->prepare()
3181 3181
 			return $operator.SP.$cleaned_value;
3182
-		} elseif( in_array( $operator, $this->_between_style_operators ) && is_array( $value ) ) {
3182
+		} elseif (in_array($operator, $this->_between_style_operators) && is_array($value)) {
3183 3183
 			//the value should be an array with count of two.
3184
-			if ( count($value) !== 2 )
3185
-				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" ) );
3186
-			$cleaned_value = $this->_construct_between_value( $value, $field_obj );
3184
+			if (count($value) !== 2)
3185
+				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"));
3186
+			$cleaned_value = $this->_construct_between_value($value, $field_obj);
3187 3187
 			return $operator.SP.$cleaned_value;
3188
-		} elseif( in_array( $operator, $this->_null_style_operators ) ) {
3189
-			if($value != NULL){
3190
-				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));
3188
+		} elseif (in_array($operator, $this->_null_style_operators)) {
3189
+			if ($value != NULL) {
3190
+				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));
3191 3191
 			}
3192 3192
 			return $operator;
3193
-		}elseif( $operator == 'LIKE' && ! is_array($value)){
3193
+		}elseif ($operator == 'LIKE' && ! is_array($value)) {
3194 3194
 			//if the operator is 'LIKE', we want to allow percent signs (%) and not
3195 3195
 			//remove other junk. So just treat it as a string.
3196 3196
 			return $operator.SP.$this->_wpdb_prepare_using_field($value, '%s');
3197
-		}elseif( ! in_array($operator, $this->_in_style_operators) && ! is_array($value)){
3198
-			return $operator.SP.$this->_wpdb_prepare_using_field($value,$field_obj);
3199
-		}elseif(in_array($operator, $this->_in_style_operators) && ! is_array($value)){
3200
-			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));
3201
-		}elseif( ! in_array($operator, $this->_in_style_operators) && is_array($value)){
3202
-			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));
3203
-		}else{
3204
-			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)));
3197
+		}elseif ( ! in_array($operator, $this->_in_style_operators) && ! is_array($value)) {
3198
+			return $operator.SP.$this->_wpdb_prepare_using_field($value, $field_obj);
3199
+		}elseif (in_array($operator, $this->_in_style_operators) && ! is_array($value)) {
3200
+			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));
3201
+		}elseif ( ! in_array($operator, $this->_in_style_operators) && is_array($value)) {
3202
+			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));
3203
+		} else {
3204
+			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)));
3205 3205
 		}
3206 3206
 	}
3207 3207
 
@@ -3213,12 +3213,12 @@  discard block
 block discarded – undo
3213 3213
 	 * @param EE_Model_Field_Base|string $field_obj if string, it should be the datatype to be used when querying, eg '%s'
3214 3214
 	 * @return string
3215 3215
 	 */
3216
-	function _construct_between_value( $values, $field_obj ) {
3216
+	function _construct_between_value($values, $field_obj) {
3217 3217
 		$cleaned_values = array();
3218
-		foreach ( $values as $value ) {
3219
-			$cleaned_values[] = $this->_wpdb_prepare_using_field($value,$field_obj);
3218
+		foreach ($values as $value) {
3219
+			$cleaned_values[] = $this->_wpdb_prepare_using_field($value, $field_obj);
3220 3220
 		}
3221
-		return  $cleaned_values[0] . " AND " . $cleaned_values[1];
3221
+		return  $cleaned_values[0]." AND ".$cleaned_values[1];
3222 3222
 	}
3223 3223
 
3224 3224
 
@@ -3234,26 +3234,26 @@  discard block
 block discarded – undo
3234 3234
 	 * @param EE_Model_Field_Base|string $field_obj if string, it should be a wpdb data type like '%s', or '%d'
3235 3235
 	 * @return string of SQL to follow an 'IN' or 'NOT IN' operator
3236 3236
 	 */
3237
-	function _construct_in_value($values,  $field_obj){
3237
+	function _construct_in_value($values, $field_obj) {
3238 3238
 		//check if the value is a CSV list
3239
-		if(is_string($values)){
3239
+		if (is_string($values)) {
3240 3240
 			//in which case, turn it into an array
3241
-			$values = explode(",",$values);
3241
+			$values = explode(",", $values);
3242 3242
 		}
3243 3243
 		$cleaned_values = array();
3244
-		foreach($values as $value){
3245
-			$cleaned_values[] = $this->_wpdb_prepare_using_field($value,$field_obj);
3244
+		foreach ($values as $value) {
3245
+			$cleaned_values[] = $this->_wpdb_prepare_using_field($value, $field_obj);
3246 3246
 		}
3247 3247
 		//we would just LOVE to leave $cleaned_values as an empty array, and return the value as "()",
3248 3248
 		//but unfortunately that's invalid SQL. So instead we return a string which we KNOW will evaluate to be the empty set
3249 3249
 		//which is effectively equivalent to returning "()". We don't return "(0)" because that only works for auto-incrementing columns
3250
-		if(empty($cleaned_values)){
3250
+		if (empty($cleaned_values)) {
3251 3251
 			$all_fields = $this->field_settings();
3252 3252
 			$a_field = array_shift($all_fields);
3253 3253
 			$main_table = $this->_get_main_table();
3254 3254
 			$cleaned_values[] = "SELECT ".$a_field->get_table_column()." FROM ".$main_table->get_table_name()." WHERE FALSE";
3255 3255
 		}
3256
-		return "(".implode(",",$cleaned_values).")";
3256
+		return "(".implode(",", $cleaned_values).")";
3257 3257
 	}
3258 3258
 
3259 3259
 
@@ -3265,16 +3265,16 @@  discard block
 block discarded – undo
3265 3265
 	 * @throws EE_Error
3266 3266
 	 * @return false|null|string
3267 3267
 	 */
3268
-	private function _wpdb_prepare_using_field($value,$field_obj){
3268
+	private function _wpdb_prepare_using_field($value, $field_obj) {
3269 3269
 		/** @type WPDB $wpdb */
3270 3270
 		global $wpdb;
3271
-		if($field_obj instanceof EE_Model_Field_Base){
3272
-			return $wpdb->prepare($field_obj->get_wpdb_data_type(),$this->_prepare_value_for_use_in_db($value, $field_obj));
3273
-		}else{//$field_obj should really just be a data type
3274
-			if( ! in_array($field_obj,$this->_valid_wpdb_data_types)){
3275
-				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)));
3271
+		if ($field_obj instanceof EE_Model_Field_Base) {
3272
+			return $wpdb->prepare($field_obj->get_wpdb_data_type(), $this->_prepare_value_for_use_in_db($value, $field_obj));
3273
+		} else {//$field_obj should really just be a data type
3274
+			if ( ! in_array($field_obj, $this->_valid_wpdb_data_types)) {
3275
+				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)));
3276 3276
 			}
3277
-			return $wpdb->prepare($field_obj,$value);
3277
+			return $wpdb->prepare($field_obj, $value);
3278 3278
 		}
3279 3279
 	}
3280 3280
 
@@ -3286,27 +3286,27 @@  discard block
 block discarded – undo
3286 3286
 	 * @throws EE_Error
3287 3287
 	 * @return EE_Model_Field_Base
3288 3288
 	 */
3289
-	protected function _deduce_field_from_query_param($query_param_name){
3289
+	protected function _deduce_field_from_query_param($query_param_name) {
3290 3290
 		//ok, now proceed with deducing which part is the model's name, and which is the field's name
3291 3291
 		//which will help us find the database table and column
3292 3292
 
3293
-		$query_param_parts = explode(".",$query_param_name);
3294
-		if(empty($query_param_parts)){
3295
-			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));
3293
+		$query_param_parts = explode(".", $query_param_name);
3294
+		if (empty($query_param_parts)) {
3295
+			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));
3296 3296
 		}
3297 3297
 		$number_of_parts = count($query_param_parts);
3298
-		$last_query_param_part = $query_param_parts[ count($query_param_parts) - 1 ];
3299
-		if($number_of_parts == 1){
3298
+		$last_query_param_part = $query_param_parts[count($query_param_parts) - 1];
3299
+		if ($number_of_parts == 1) {
3300 3300
 			$field_name = $last_query_param_part;
3301 3301
 			$model_obj = $this;
3302
-		}else{// $number_of_parts >= 2
3302
+		} else {// $number_of_parts >= 2
3303 3303
 			//the last part is the column name, and there are only 2parts. therefore...
3304 3304
 			$field_name = $last_query_param_part;
3305
-			$model_obj = $this->get_related_model_obj( $query_param_parts[ $number_of_parts - 2 ]);
3305
+			$model_obj = $this->get_related_model_obj($query_param_parts[$number_of_parts - 2]);
3306 3306
 		}
3307
-		try{
3307
+		try {
3308 3308
 			return $model_obj->field_settings_for($field_name);
3309
-		}catch(EE_Error $e){
3309
+		} catch (EE_Error $e) {
3310 3310
 			return null;
3311 3311
 		}
3312 3312
 	}
@@ -3320,13 +3320,13 @@  discard block
 block discarded – undo
3320 3320
 	 * @throws EE_Error
3321 3321
 	 * @return string
3322 3322
 	 */
3323
-	function _get_qualified_column_for_field($field_name){
3323
+	function _get_qualified_column_for_field($field_name) {
3324 3324
 		$all_fields = $this->field_settings();
3325 3325
 		$field = isset($all_fields[$field_name]) ? $all_fields[$field_name] : FALSE;
3326
-		if($field){
3326
+		if ($field) {
3327 3327
 			return $field->get_qualified_column();
3328
-		}else{
3329
-			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)));
3328
+		} else {
3329
+			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)));
3330 3330
 		}
3331 3331
 	}
3332 3332
 
@@ -3340,14 +3340,14 @@  discard block
 block discarded – undo
3340 3340
 	 * @param  mixed|string $limit The limit for this select
3341 3341
 	 * @return string 				The final select join element for the query.
3342 3342
 	 */
3343
-	function _construct_limit_join_select( $table_alias, $limit ) {
3343
+	function _construct_limit_join_select($table_alias, $limit) {
3344 3344
 		$SQL = '';
3345 3345
 
3346
-		foreach ( $this->_tables as $table_obj ) {
3347
-			if ( $table_obj instanceof EE_Primary_Table ) {
3348
-				$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;
3349
-			} elseif ( $table_obj instanceof EE_Secondary_Table ) {
3350
-				$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;
3346
+		foreach ($this->_tables as $table_obj) {
3347
+			if ($table_obj instanceof EE_Primary_Table) {
3348
+				$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;
3349
+			} elseif ($table_obj instanceof EE_Secondary_Table) {
3350
+				$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;
3351 3351
 			}
3352 3352
 		}
3353 3353
 		return $SQL;
@@ -3360,7 +3360,7 @@  discard block
 block discarded – undo
3360 3360
 	 * Eg "wp_post AS Event" or "wp_post AS Event INNER JOIN wp_postmeta Event_Meta ON Event.ID = Event_Meta.post_id"
3361 3361
 	 * @return string SQL
3362 3362
 	 */
3363
-	function _construct_internal_join(){
3363
+	function _construct_internal_join() {
3364 3364
 		$SQL = $this->_get_main_table()->get_table_sql();
3365 3365
 		$SQL .= $this->_construct_internal_join_to_table_with_alias($this->_get_main_table()->get_table_alias());
3366 3366
 		return $SQL;
@@ -3381,17 +3381,17 @@  discard block
 block discarded – undo
3381 3381
 	 * @param string $alias_prefixed table alias to join to (this table should already be in the FROM SQL clause)
3382 3382
 	 * @return string
3383 3383
 	 */
3384
-	function _construct_internal_join_to_table_with_alias($alias_prefixed){
3384
+	function _construct_internal_join_to_table_with_alias($alias_prefixed) {
3385 3385
 		$SQL = '';
3386 3386
 		$alias_sans_prefix = EE_Model_Parser::remove_table_alias_model_relation_chain_prefix($alias_prefixed);
3387
-		foreach($this->_tables as $table_obj){
3388
-			if($table_obj instanceof EE_Secondary_Table){//table is secondary table
3389
-				if($alias_sans_prefix == $table_obj->get_table_alias()){
3387
+		foreach ($this->_tables as $table_obj) {
3388
+			if ($table_obj instanceof EE_Secondary_Table) {//table is secondary table
3389
+				if ($alias_sans_prefix == $table_obj->get_table_alias()) {
3390 3390
 					//so we're joining to this table, meaning the table is already in
3391 3391
 					//the FROM statement, BUT the primary table isn't. So we want
3392 3392
 					//to add the inverse join sql
3393 3393
 					$SQL .= $table_obj->get_inverse_join_sql($alias_prefixed);
3394
-				}else{
3394
+				} else {
3395 3395
 					//just add a regular JOIN to this table from the primary table
3396 3396
 					$SQL .= $table_obj->get_join_sql($alias_prefixed);
3397 3397
 				}
@@ -3405,9 +3405,9 @@  discard block
 block discarded – undo
3405 3405
 	 * 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)
3406 3406
 	 * @return array
3407 3407
 	 */
3408
-	function _get_data_types(){
3408
+	function _get_data_types() {
3409 3409
 		$data_types = array();
3410
-		foreach(array_values($this->field_settings()) as $field_obj){
3410
+		foreach (array_values($this->field_settings()) as $field_obj) {
3411 3411
 			//$data_types[$field_obj->get_table_column()] = $field_obj->get_wpdb_data_type();
3412 3412
 			/** @var $field_obj EE_Model_Field_Base */
3413 3413
 			$data_types[$field_obj->get_qualified_column()] = $field_obj->get_wpdb_data_type();
@@ -3423,11 +3423,11 @@  discard block
 block discarded – undo
3423 3423
 	 * @throws EE_Error
3424 3424
 	 * @return EEM_Base
3425 3425
 	 */
3426
-	function get_related_model_obj($model_name){
3426
+	function get_related_model_obj($model_name) {
3427 3427
 
3428 3428
 		$model_classname = "EEM_".$model_name;
3429
-		if(!class_exists($model_classname)){
3430
-			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));
3429
+		if ( ! class_exists($model_classname)) {
3430
+			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));
3431 3431
 		}
3432 3432
 		$model_obj = call_user_func($model_classname."::instance");
3433 3433
 		return $model_obj;
@@ -3438,7 +3438,7 @@  discard block
 block discarded – undo
3438 3438
 	 * Returns the array of EE_ModelRelations for this model.
3439 3439
 	 * @return EE_Model_Relation_Base[]
3440 3440
 	 */
3441
-	public function relation_settings(){
3441
+	public function relation_settings() {
3442 3442
 		return $this->_model_relations;
3443 3443
 	}
3444 3444
 
@@ -3448,10 +3448,10 @@  discard block
 block discarded – undo
3448 3448
 	 * (Eg, without an event, datetimes have little purpose.)
3449 3449
 	 * @return EE_Belongs_To_Relation[]
3450 3450
 	 */
3451
-	public function belongs_to_relations(){
3451
+	public function belongs_to_relations() {
3452 3452
 		$belongs_to_relations = array();
3453
-		foreach($this->relation_settings() as $model_name => $relation_obj){
3454
-			if($relation_obj instanceof EE_Belongs_To_Relation){
3453
+		foreach ($this->relation_settings() as $model_name => $relation_obj) {
3454
+			if ($relation_obj instanceof EE_Belongs_To_Relation) {
3455 3455
 				$belongs_to_relations[$model_name] = $relation_obj;
3456 3456
 			}
3457 3457
 		}
@@ -3466,15 +3466,15 @@  discard block
 block discarded – undo
3466 3466
 	 * @throws EE_Error
3467 3467
 	 * @return EE_Model_Relation_Base
3468 3468
 	 */
3469
-	public function related_settings_for($relation_name){
3470
-		$relatedModels=$this->relation_settings();
3471
-		if(!array_key_exists($relation_name,$relatedModels)){
3469
+	public function related_settings_for($relation_name) {
3470
+		$relatedModels = $this->relation_settings();
3471
+		if ( ! array_key_exists($relation_name, $relatedModels)) {
3472 3472
 			throw new EE_Error(
3473 3473
 				sprintf(
3474
-					__('Cannot get %s related to %s. There is no model relation of that type. There is, however, %s...','event_espresso'),
3474
+					__('Cannot get %s related to %s. There is no model relation of that type. There is, however, %s...', 'event_espresso'),
3475 3475
 					$relation_name,
3476 3476
 					$this->_get_class_name(),
3477
-					implode( ', ', array_keys( $relatedModels ))
3477
+					implode(', ', array_keys($relatedModels))
3478 3478
 				)
3479 3479
 			);
3480 3480
 		}
@@ -3489,10 +3489,10 @@  discard block
 block discarded – undo
3489 3489
 	 * @throws EE_Error
3490 3490
 	 * @return EE_Model_Field_Base
3491 3491
 	 */
3492
-	public function field_settings_for($fieldName){
3493
-		$fieldSettings=$this->field_settings(true);
3494
-		if( ! array_key_exists($fieldName,$fieldSettings)){
3495
-			throw new EE_Error(sprintf(__("There is no field/column '%s' on '%s'",'event_espresso'),$fieldName,get_class($this)));
3492
+	public function field_settings_for($fieldName) {
3493
+		$fieldSettings = $this->field_settings(true);
3494
+		if ( ! array_key_exists($fieldName, $fieldSettings)) {
3495
+			throw new EE_Error(sprintf(__("There is no field/column '%s' on '%s'", 'event_espresso'), $fieldName, get_class($this)));
3496 3496
 		}
3497 3497
 		return $fieldSettings[$fieldName];
3498 3498
 	}
@@ -3502,11 +3502,11 @@  discard block
 block discarded – undo
3502 3502
 	 * @param string $fieldName a key in the model's _field_settings array
3503 3503
 	 * @return boolean
3504 3504
 	 */
3505
-	public function has_field($fieldName){
3505
+	public function has_field($fieldName) {
3506 3506
 		$fieldSettings = $this->field_settings(true);
3507
-		if( isset($fieldSettings[$fieldName])){
3507
+		if (isset($fieldSettings[$fieldName])) {
3508 3508
 			return true;
3509
-		}else{
3509
+		} else {
3510 3510
 			return false;
3511 3511
 		}
3512 3512
 	}
@@ -3516,11 +3516,11 @@  discard block
 block discarded – undo
3516 3516
 	 * @param string $relation_name possibly one of the keys in the relation_settings array
3517 3517
 	 * @return boolean
3518 3518
 	 */
3519
-	public function has_relation($relation_name){
3519
+	public function has_relation($relation_name) {
3520 3520
 		$relations = $this->relation_settings();
3521
-		if(isset($relations[$relation_name])){
3521
+		if (isset($relations[$relation_name])) {
3522 3522
 			return true;
3523
-		}else{
3523
+		} else {
3524 3524
 			return false;
3525 3525
 		}
3526 3526
 	}
@@ -3532,7 +3532,7 @@  discard block
 block discarded – undo
3532 3532
 	 * @param $field_obj
3533 3533
 	 * @return EE_Model_Field_Base
3534 3534
 	 */
3535
-	public function is_primary_key_field( $field_obj ){
3535
+	public function is_primary_key_field($field_obj) {
3536 3536
 		return $field_obj instanceof EE_Primary_Key_Field_Base ? TRUE : FALSE;
3537 3537
 	}
3538 3538
 
@@ -3544,16 +3544,16 @@  discard block
 block discarded – undo
3544 3544
 	 * @return EE_Model_Field_Base
3545 3545
 	 * @throws EE_Error
3546 3546
 	 */
3547
-	public function get_primary_key_field(){
3548
-		if( $this->_primary_key_field === NULL ){
3549
-			foreach( $this->field_settings( TRUE ) as $field_obj ){
3550
-				if( $this->is_primary_key_field( $field_obj )){
3547
+	public function get_primary_key_field() {
3548
+		if ($this->_primary_key_field === NULL) {
3549
+			foreach ($this->field_settings(TRUE) as $field_obj) {
3550
+				if ($this->is_primary_key_field($field_obj)) {
3551 3551
 					$this->_primary_key_field = $field_obj;
3552 3552
 					break;
3553 3553
 				}
3554 3554
 			}
3555
-			if( ! $this->_primary_key_field instanceof EE_Primary_Key_Field_Base ){
3556
-				throw new EE_Error(sprintf(__("There is no Primary Key defined on model %s",'event_espresso'),get_class($this)));
3555
+			if ( ! $this->_primary_key_field instanceof EE_Primary_Key_Field_Base) {
3556
+				throw new EE_Error(sprintf(__("There is no Primary Key defined on model %s", 'event_espresso'), get_class($this)));
3557 3557
 			}
3558 3558
 		}
3559 3559
 		return $this->_primary_key_field;
@@ -3566,12 +3566,12 @@  discard block
 block discarded – undo
3566 3566
 	 * Internally does some caching.
3567 3567
 	 * @return boolean
3568 3568
 	 */
3569
-	public function has_primary_key_field(){
3570
-		if($this->_has_primary_key_field === null){
3571
-			try{
3569
+	public function has_primary_key_field() {
3570
+		if ($this->_has_primary_key_field === null) {
3571
+			try {
3572 3572
 				$this->get_primary_key_field();
3573 3573
 				$this->_has_primary_key_field = true;
3574
-			}catch(EE_Error $e){
3574
+			} catch (EE_Error $e) {
3575 3575
 				$this->_has_primary_key_field = false;
3576 3576
 			}
3577 3577
 		}
@@ -3585,9 +3585,9 @@  discard block
 block discarded – undo
3585 3585
 	 * @param string $field_class_name class name of field that you want to find. Eg, EE_Datetime_Field, EE_Foreign_Key_Field, etc
3586 3586
 	 * @return EE_Model_Field_Base or null if none is found
3587 3587
 	 */
3588
-	public function get_a_field_of_type($field_class_name){
3589
-		foreach($this->field_settings() as $field){
3590
-			if( $field instanceof $field_class_name ){
3588
+	public function get_a_field_of_type($field_class_name) {
3589
+		foreach ($this->field_settings() as $field) {
3590
+			if ($field instanceof $field_class_name) {
3591 3591
 				return $field;
3592 3592
 			}
3593 3593
 		}
@@ -3601,21 +3601,21 @@  discard block
 block discarded – undo
3601 3601
 	 * @return EE_Foreign_Key_Field_Base
3602 3602
 	 * @throws EE_Error
3603 3603
 	 */
3604
-	public function get_foreign_key_to($model_name){
3605
-		if( ! isset( $this->_cache_foreign_key_to_fields[ $model_name ] ) ){
3606
-			foreach($this->field_settings() as $field){
3604
+	public function get_foreign_key_to($model_name) {
3605
+		if ( ! isset($this->_cache_foreign_key_to_fields[$model_name])) {
3606
+			foreach ($this->field_settings() as $field) {
3607 3607
 //				if(is_subclass_of($field, 'EE_Foreign_Key_Field_Base')){
3608
-				if( $field instanceof EE_Foreign_Key_Field_Base ){
3609
-					if (in_array($model_name,$field->get_model_names_pointed_to() ) ) {
3610
-						$this->_cache_foreign_key_to_fields[ $model_name ] = $field;
3608
+				if ($field instanceof EE_Foreign_Key_Field_Base) {
3609
+					if (in_array($model_name, $field->get_model_names_pointed_to())) {
3610
+						$this->_cache_foreign_key_to_fields[$model_name] = $field;
3611 3611
 					}
3612 3612
 				}
3613 3613
 			}
3614
-			if( ! isset( $this->_cache_foreign_key_to_fields[ $model_name ] ) ){
3615
-				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)));
3614
+			if ( ! isset($this->_cache_foreign_key_to_fields[$model_name])) {
3615
+				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)));
3616 3616
 			}
3617 3617
 		}
3618
-		return $this->_cache_foreign_key_to_fields[ $model_name ];
3618
+		return $this->_cache_foreign_key_to_fields[$model_name];
3619 3619
 	}
3620 3620
 
3621 3621
 
@@ -3626,7 +3626,7 @@  discard block
 block discarded – undo
3626 3626
 	 * a table alias with a model chain prefix, like 'Venue__Event_Venue___Event_Meta'. Either one works
3627 3627
 	 * @return EE_Table_Base
3628 3628
 	 */
3629
-	function get_table_for_alias($table_alias){
3629
+	function get_table_for_alias($table_alias) {
3630 3630
 		$table_alias_sans_model_relation_chain_prefix = EE_Model_Parser::remove_table_alias_model_relation_chain_prefix($table_alias);
3631 3631
 		return $this->_tables[$table_alias_sans_model_relation_chain_prefix]->get_table_name();
3632 3632
 	}
@@ -3639,25 +3639,25 @@  discard block
 block discarded – undo
3639 3639
 	 * @param bool $include_db_only_fields flag indicating whether or not to include the db-only fields
3640 3640
 	 * @return EE_Model_Field_Base[] where the keys are the field's name
3641 3641
 	 */
3642
-	public function field_settings($include_db_only_fields = false){
3643
-		if( $include_db_only_fields ){
3644
-			if( $this->_cached_fields === NULL ){
3642
+	public function field_settings($include_db_only_fields = false) {
3643
+		if ($include_db_only_fields) {
3644
+			if ($this->_cached_fields === NULL) {
3645 3645
 				$this->_cached_fields = array();
3646
-				foreach($this->_fields as $fields_corresponding_to_table){
3647
-					foreach($fields_corresponding_to_table as $field_name => $field_obj){
3648
-						$this->_cached_fields[$field_name]=$field_obj;
3646
+				foreach ($this->_fields as $fields_corresponding_to_table) {
3647
+					foreach ($fields_corresponding_to_table as $field_name => $field_obj) {
3648
+						$this->_cached_fields[$field_name] = $field_obj;
3649 3649
 					}
3650 3650
 				}
3651 3651
 			}
3652 3652
 			return $this->_cached_fields;
3653
-		}else{
3654
-			if( $this->_cached_fields_non_db_only === NULL ){
3653
+		} else {
3654
+			if ($this->_cached_fields_non_db_only === NULL) {
3655 3655
 				$this->_cached_fields_non_db_only = array();
3656
-				foreach($this->_fields as $fields_corresponding_to_table){
3657
-					foreach($fields_corresponding_to_table as $field_name => $field_obj){
3656
+				foreach ($this->_fields as $fields_corresponding_to_table) {
3657
+					foreach ($fields_corresponding_to_table as $field_name => $field_obj) {
3658 3658
 						/** @var $field_obj EE_Model_Field_Base */
3659
-						if( ! $field_obj->is_db_only_field() ){
3660
-							$this->_cached_fields_non_db_only[$field_name]=$field_obj;
3659
+						if ( ! $field_obj->is_db_only_field()) {
3660
+							$this->_cached_fields_non_db_only[$field_name] = $field_obj;
3661 3661
 						}
3662 3662
 					}
3663 3663
 				}
@@ -3676,40 +3676,40 @@  discard block
 block discarded – undo
3676 3676
 	 * @return \EE_Base_Class[] array keys are primary keys (if there is a primary key on the model. if not, numerically indexed)
3677 3677
 	 * @throws \EE_Error
3678 3678
 	 */
3679
-	protected function _create_objects( $rows = array() ) {
3680
-		$array_of_objects=array();
3681
-		if(empty($rows)){
3679
+	protected function _create_objects($rows = array()) {
3680
+		$array_of_objects = array();
3681
+		if (empty($rows)) {
3682 3682
 			return array();
3683 3683
 		}
3684 3684
 		$count_if_model_has_no_primary_key = 0;
3685
-		foreach ( $rows as $row ) {
3686
-			if(empty($row)){//wp did its weird thing where it returns an array like array(0=>null), which is totally not helpful...
3685
+		foreach ($rows as $row) {
3686
+			if (empty($row)) {//wp did its weird thing where it returns an array like array(0=>null), which is totally not helpful...
3687 3687
 				return array();
3688 3688
 			}
3689
-			$classInstance=$this->instantiate_class_from_array_or_object($row);
3690
-			if( ! $classInstance ) {
3691
-				throw new EE_Error( sprintf( __( 'Could not create instance of class %s from row %s', 'event_espresso' ), $this->get_this_model_name(), http_build_query( $row ) ) );
3689
+			$classInstance = $this->instantiate_class_from_array_or_object($row);
3690
+			if ( ! $classInstance) {
3691
+				throw new EE_Error(sprintf(__('Could not create instance of class %s from row %s', 'event_espresso'), $this->get_this_model_name(), http_build_query($row)));
3692 3692
 			}
3693 3693
 			//set the timezone on the instantiated objects
3694
-			$classInstance->set_timezone( $this->_timezone );
3694
+			$classInstance->set_timezone($this->_timezone);
3695 3695
 			//make sure if there is any timezone setting present that we set the timezone for the object
3696
-			$array_of_objects[$this->has_primary_key_field() ? $classInstance->ID() : $count_if_model_has_no_primary_key++]=$classInstance;
3696
+			$array_of_objects[$this->has_primary_key_field() ? $classInstance->ID() : $count_if_model_has_no_primary_key++] = $classInstance;
3697 3697
 			//also, for all the relations of type BelongsTo, see if we can cache
3698 3698
 			//those related models
3699 3699
 			//(we could do this for other relations too, but if there are conditions
3700 3700
 			//that filtered out some fo the results, then we'd be caching an incomplete set
3701 3701
 			//so it requires a little more thought than just caching them immediately...)
3702
-			foreach($this->_model_relations as $modelName => $relation_obj){
3703
-				if( $relation_obj instanceof EE_Belongs_To_Relation){
3702
+			foreach ($this->_model_relations as $modelName => $relation_obj) {
3703
+				if ($relation_obj instanceof EE_Belongs_To_Relation) {
3704 3704
 					//check if this model's INFO is present. If so, cache it on the model
3705 3705
 					$other_model = $relation_obj->get_other_model();
3706 3706
 
3707 3707
 					$other_model_obj_maybe = $other_model->instantiate_class_from_array_or_object($row);
3708 3708
 
3709 3709
 					//if we managed to make a model object from the results, cache it on the main model object
3710
-					if( $other_model_obj_maybe ){
3710
+					if ($other_model_obj_maybe) {
3711 3711
 						//set timezone on these other model objects if they are present
3712
-						$other_model_obj_maybe->set_timezone( $this->_timezone );
3712
+						$other_model_obj_maybe->set_timezone($this->_timezone);
3713 3713
 						$classInstance->cache($modelName, $other_model_obj_maybe);
3714 3714
 					}
3715 3715
 				}
@@ -3730,12 +3730,12 @@  discard block
 block discarded – undo
3730 3730
 
3731 3731
 		$this_model_fields_and_values = array();
3732 3732
 		//setup the row using default values;
3733
-		foreach ( $this->field_settings() as $field_name => $field_obj ) {
3733
+		foreach ($this->field_settings() as $field_name => $field_obj) {
3734 3734
 			$this_model_fields_and_values[$field_name] = $field_obj->get_default_value();
3735 3735
 		}
3736 3736
 
3737 3737
 		$className = $this->_get_class_name();
3738
-		$classInstance = EE_Registry::instance()->load_class( $className, array( $this_model_fields_and_values ), FALSE, FALSE );
3738
+		$classInstance = EE_Registry::instance()->load_class($className, array($this_model_fields_and_values), FALSE, FALSE);
3739 3739
 
3740 3740
 		return $classInstance;
3741 3741
 	}
@@ -3748,45 +3748,45 @@  discard block
 block discarded – undo
3748 3748
 	 * or an stdClass where each property is the name of a column,
3749 3749
 	 * @return EE_Base_Class
3750 3750
 	 */
3751
-	public function instantiate_class_from_array_or_object($cols_n_values){
3752
-		if( ! is_array( $cols_n_values ) && is_object( $cols_n_values )) {
3753
-			$cols_n_values = get_object_vars( $cols_n_values );
3751
+	public function instantiate_class_from_array_or_object($cols_n_values) {
3752
+		if ( ! is_array($cols_n_values) && is_object($cols_n_values)) {
3753
+			$cols_n_values = get_object_vars($cols_n_values);
3754 3754
 		}
3755 3755
 		$primary_key = NULL;
3756 3756
 		//make sure the array only has keys that are fields/columns on this model
3757
-		$this_model_fields_n_values = $this->_deduce_fields_n_values_from_cols_n_values( $cols_n_values );
3758
-		if( $this->has_primary_key_field() && isset( $this_model_fields_n_values[ $this->primary_key_name() ] ) ){
3759
-			$primary_key = $this_model_fields_n_values[ $this->primary_key_name() ];
3757
+		$this_model_fields_n_values = $this->_deduce_fields_n_values_from_cols_n_values($cols_n_values);
3758
+		if ($this->has_primary_key_field() && isset($this_model_fields_n_values[$this->primary_key_name()])) {
3759
+			$primary_key = $this_model_fields_n_values[$this->primary_key_name()];
3760 3760
 		}
3761
-		$className=$this->_get_class_name();
3761
+		$className = $this->_get_class_name();
3762 3762
 
3763 3763
 		//check we actually found results that we can use to build our model object
3764 3764
 		//if not, return null
3765
-		if( $this->has_primary_key_field()){
3766
-			if(empty( $this_model_fields_n_values[$this->primary_key_name()] )){
3765
+		if ($this->has_primary_key_field()) {
3766
+			if (empty($this_model_fields_n_values[$this->primary_key_name()])) {
3767 3767
 				return NULL;
3768 3768
 			}
3769
-		}else if($this->unique_indexes()){
3769
+		} else if ($this->unique_indexes()) {
3770 3770
 			$first_column = reset($this_model_fields_n_values);
3771
-			if(empty($first_column)){
3771
+			if (empty($first_column)) {
3772 3772
 				return NULL;
3773 3773
 			}
3774 3774
 		}
3775 3775
 
3776 3776
 		// if there is no primary key or the object doesn't already exist in the entity map, then create a new instance
3777
-		if ( $primary_key){
3778
-			$classInstance = $this->get_from_entity_map( $primary_key );
3779
-			if( ! $classInstance) {
3780
-				$classInstance = EE_Registry::instance()->load_class( $className, array( $this_model_fields_n_values, $this->_timezone ), TRUE, FALSE );
3777
+		if ($primary_key) {
3778
+			$classInstance = $this->get_from_entity_map($primary_key);
3779
+			if ( ! $classInstance) {
3780
+				$classInstance = EE_Registry::instance()->load_class($className, array($this_model_fields_n_values, $this->_timezone), TRUE, FALSE);
3781 3781
 				// add this new object to the entity map
3782
-				$classInstance = $this->add_to_entity_map( $classInstance );
3782
+				$classInstance = $this->add_to_entity_map($classInstance);
3783 3783
 			}
3784
-		}else{
3785
-			$classInstance = EE_Registry::instance()->load_class( $className, array( $this_model_fields_n_values, $this->_timezone ), TRUE, FALSE );
3784
+		} else {
3785
+			$classInstance = EE_Registry::instance()->load_class($className, array($this_model_fields_n_values, $this->_timezone), TRUE, FALSE);
3786 3786
 		}
3787 3787
 
3788 3788
 			//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.
3789
-		$this->set_timezone( $classInstance->get_timezone() );
3789
+		$this->set_timezone($classInstance->get_timezone());
3790 3790
 		return $classInstance;
3791 3791
 	}
3792 3792
 	/**
@@ -3794,8 +3794,8 @@  discard block
 block discarded – undo
3794 3794
 	 * @param int|string $id the ID of the model object
3795 3795
 	 * @return EE_Base_Class
3796 3796
 	 */
3797
-	public function get_from_entity_map( $id ){
3798
-		return isset( $this->_entity_map[ $id ] ) ? $this->_entity_map[ $id ] : NULL;
3797
+	public function get_from_entity_map($id) {
3798
+		return isset($this->_entity_map[$id]) ? $this->_entity_map[$id] : NULL;
3799 3799
 	}
3800 3800
 
3801 3801
 
@@ -3814,21 +3814,21 @@  discard block
 block discarded – undo
3814 3814
 	 * @throws EE_Error
3815 3815
 	 * @return \EE_Base_Class
3816 3816
 	 */
3817
-	public function add_to_entity_map( EE_Base_Class $object) {
3817
+	public function add_to_entity_map(EE_Base_Class $object) {
3818 3818
 		$className = $this->_get_class_name();
3819
-		if( ! $object instanceof $className ){
3820
-			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 ) );
3819
+		if ( ! $object instanceof $className) {
3820
+			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));
3821 3821
 		}
3822 3822
 		/** @var $object EE_Base_Class */
3823
-		if ( ! $object->ID() ){
3824
-			throw new EE_Error(sprintf(__("You tried storing a model object with NO ID in the %s entity mapper.", "event_espresso"),get_class($this)));
3823
+		if ( ! $object->ID()) {
3824
+			throw new EE_Error(sprintf(__("You tried storing a model object with NO ID in the %s entity mapper.", "event_espresso"), get_class($this)));
3825 3825
 		}
3826 3826
 		// double check it's not already there
3827
-		$classInstance = $this->get_from_entity_map( $object->ID() );
3828
-		if ( $classInstance ) {
3827
+		$classInstance = $this->get_from_entity_map($object->ID());
3828
+		if ($classInstance) {
3829 3829
 			return $classInstance;
3830 3830
 		} else {
3831
-			$this->_entity_map[ $object->ID() ] = $object;
3831
+			$this->_entity_map[$object->ID()] = $object;
3832 3832
 			return $object;
3833 3833
 		}
3834 3834
 	}
@@ -3841,8 +3841,8 @@  discard block
 block discarded – undo
3841 3841
 	 * @param array $cols_n_values
3842 3842
 	 * @return array
3843 3843
 	 */
3844
-	public function deduce_fields_n_values_from_cols_n_values( $cols_n_values ) {
3845
-		return $this->_deduce_fields_n_values_from_cols_n_values( $cols_n_values );
3844
+	public function deduce_fields_n_values_from_cols_n_values($cols_n_values) {
3845
+		return $this->_deduce_fields_n_values_from_cols_n_values($cols_n_values);
3846 3846
 	}
3847 3847
 
3848 3848
 
@@ -3855,40 +3855,40 @@  discard block
 block discarded – undo
3855 3855
 	 * @param string $cols_n_values
3856 3856
 	 * @return array
3857 3857
 	 */
3858
-	protected function _deduce_fields_n_values_from_cols_n_values( $cols_n_values ){
3858
+	protected function _deduce_fields_n_values_from_cols_n_values($cols_n_values) {
3859 3859
 		$this_model_fields_n_values = array();
3860
-		foreach( $this->get_tables() as $table_alias => $table_obj ) {
3861
-			$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() );
3860
+		foreach ($this->get_tables() as $table_alias => $table_obj) {
3861
+			$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());
3862 3862
 			//there is a primary key on this table and its not set. Use defaults for all its columns
3863
-			if( $table_obj->get_pk_column() && $table_pk_value === NULL ){
3864
-				foreach( $this->_get_fields_for_table( $table_alias ) as $field_name => $field_obj ) {
3865
-					if( ! $field_obj->is_db_only_field() ){
3863
+			if ($table_obj->get_pk_column() && $table_pk_value === NULL) {
3864
+				foreach ($this->_get_fields_for_table($table_alias) as $field_name => $field_obj) {
3865
+					if ( ! $field_obj->is_db_only_field()) {
3866 3866
 						//prepare field as if its coming from db
3867
-						$prepared_value = $field_obj->prepare_for_set( $field_obj->get_default_value() );
3868
-						$this_model_fields_n_values[$field_name] = $field_obj->prepare_for_use_in_db( $prepared_value );
3867
+						$prepared_value = $field_obj->prepare_for_set($field_obj->get_default_value());
3868
+						$this_model_fields_n_values[$field_name] = $field_obj->prepare_for_use_in_db($prepared_value);
3869 3869
 					}
3870 3870
 				}
3871
-			}else{
3871
+			} else {
3872 3872
 				//the table's rows existed. Use their values
3873
-				foreach( $this->_get_fields_for_table( $table_alias ) as $field_name => $field_obj ) {
3874
-					if( ! $field_obj->is_db_only_field() )
3875
-					$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() );
3873
+				foreach ($this->_get_fields_for_table($table_alias) as $field_name => $field_obj) {
3874
+					if ( ! $field_obj->is_db_only_field())
3875
+					$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());
3876 3876
 				}
3877 3877
 			}
3878 3878
 		}
3879 3879
 		return $this_model_fields_n_values;
3880 3880
 	}
3881 3881
 
3882
-	protected function _get_column_value_with_table_alias_or_not( $cols_n_values, $qualified_column, $regular_column ){
3882
+	protected function _get_column_value_with_table_alias_or_not($cols_n_values, $qualified_column, $regular_column) {
3883 3883
 		//ask the field what it think it's table_name.column_name should be, and call it the "qualified column"
3884 3884
 		//does the field on the model relate to this column retrieved from the db?
3885 3885
 		//or is it a db-only field? (not relating to the model)
3886
-		if( isset( $cols_n_values[ $qualified_column ] ) ){
3887
-			$value = $cols_n_values[ $qualified_column ];
3886
+		if (isset($cols_n_values[$qualified_column])) {
3887
+			$value = $cols_n_values[$qualified_column];
3888 3888
 
3889
-		}elseif( isset( $cols_n_values[ $regular_column ] ) ){
3890
-			$value = $cols_n_values[ $regular_column ];
3891
-		}else{
3889
+		}elseif (isset($cols_n_values[$regular_column])) {
3890
+			$value = $cols_n_values[$regular_column];
3891
+		} else {
3892 3892
 			$value = NULL;
3893 3893
 		}
3894 3894
 
@@ -3906,23 +3906,23 @@  discard block
 block discarded – undo
3906 3906
 	 * @param int|string $id
3907 3907
 	 * @return EE_Base_Class
3908 3908
 	 */
3909
-	public function refresh_entity_map_from_db( $id ){
3910
-		$obj_in_map = $this->get_from_entity_map( $id );
3911
-		if( $obj_in_map ){
3912
-			$wpdb_results = $this->_get_all_wpdb_results( array( array ( $this->get_primary_key_field()->get_name() => $id ), 'limit' => 1 ) );
3913
-			if( $wpdb_results && is_array( $wpdb_results ) ){
3914
-				$one_row = reset( $wpdb_results );
3915
-				foreach( $this->_deduce_fields_n_values_from_cols_n_values($one_row ) as $field_name => $db_value ) {
3916
-					$obj_in_map->set_from_db( $field_name, $db_value );
3909
+	public function refresh_entity_map_from_db($id) {
3910
+		$obj_in_map = $this->get_from_entity_map($id);
3911
+		if ($obj_in_map) {
3912
+			$wpdb_results = $this->_get_all_wpdb_results(array(array($this->get_primary_key_field()->get_name() => $id), 'limit' => 1));
3913
+			if ($wpdb_results && is_array($wpdb_results)) {
3914
+				$one_row = reset($wpdb_results);
3915
+				foreach ($this->_deduce_fields_n_values_from_cols_n_values($one_row) as $field_name => $db_value) {
3916
+					$obj_in_map->set_from_db($field_name, $db_value);
3917 3917
 				}
3918 3918
 				//clear the cache of related model objects
3919
-				foreach ( $this->relation_settings() as $relation_name => $relation_obj ){
3920
-					$obj_in_map->clear_cache($relation_name, NULL, TRUE );
3919
+				foreach ($this->relation_settings() as $relation_name => $relation_obj) {
3920
+					$obj_in_map->clear_cache($relation_name, NULL, TRUE);
3921 3921
 				}
3922 3922
 			}
3923 3923
 			return $obj_in_map;
3924
-		}else{
3925
-			return $this->get_one_by_ID( $id );
3924
+		} else {
3925
+			return $this->get_one_by_ID($id);
3926 3926
 		}
3927 3927
 	}
3928 3928
 
@@ -3940,24 +3940,24 @@  discard block
 block discarded – undo
3940 3940
 	 * @param EE_Base_Class $replacing_model_obj
3941 3941
 	 * @return \EE_Base_Class
3942 3942
 	 */
3943
-	public function refresh_entity_map_with( $id, $replacing_model_obj ) {
3944
-		$obj_in_map = $this->get_from_entity_map( $id );
3945
-		if( $obj_in_map ){
3946
-			if( $replacing_model_obj instanceof EE_Base_Class ){
3947
-				foreach( $replacing_model_obj->model_field_array() as $field_name => $value ) {
3948
-					$obj_in_map->set( $field_name, $value );
3943
+	public function refresh_entity_map_with($id, $replacing_model_obj) {
3944
+		$obj_in_map = $this->get_from_entity_map($id);
3945
+		if ($obj_in_map) {
3946
+			if ($replacing_model_obj instanceof EE_Base_Class) {
3947
+				foreach ($replacing_model_obj->model_field_array() as $field_name => $value) {
3948
+					$obj_in_map->set($field_name, $value);
3949 3949
 				}
3950 3950
 				//make the model object in the entity map's cache match the $replacing_model_obj
3951
-				foreach ( $this->relation_settings() as $relation_name => $relation_obj ){
3952
-					$obj_in_map->clear_cache($relation_name, NULL, TRUE );
3953
-					foreach( $replacing_model_obj->get_all_from_cache( $relation_name ) as $cache_id => $cached_obj ) {
3954
-						$obj_in_map->cache( $relation_name, $cached_obj, $cache_id );
3951
+				foreach ($this->relation_settings() as $relation_name => $relation_obj) {
3952
+					$obj_in_map->clear_cache($relation_name, NULL, TRUE);
3953
+					foreach ($replacing_model_obj->get_all_from_cache($relation_name) as $cache_id => $cached_obj) {
3954
+						$obj_in_map->cache($relation_name, $cached_obj, $cache_id);
3955 3955
 					}
3956 3956
 				}
3957 3957
 			}
3958 3958
 			return $obj_in_map;
3959
-		}else{
3960
-			$this->add_to_entity_map( $replacing_model_obj );
3959
+		} else {
3960
+			$this->add_to_entity_map($replacing_model_obj);
3961 3961
 			return $replacing_model_obj;
3962 3962
 		}
3963 3963
 	}
@@ -3970,7 +3970,7 @@  discard block
 block discarded – undo
3970 3970
 	 * require_once($this->_getClassName().".class.php");
3971 3971
 	 * @return string
3972 3972
 	 */
3973
-	private function _get_class_name(){
3973
+	private function _get_class_name() {
3974 3974
 		return "EE_".$this->get_this_model_name();
3975 3975
 	}
3976 3976
 
@@ -3983,10 +3983,10 @@  discard block
 block discarded – undo
3983 3983
 	 * @param int $quantity
3984 3984
 	 * @return string
3985 3985
 	 */
3986
-	public function item_name($quantity = 1){
3987
-		if($quantity == 1){
3986
+	public function item_name($quantity = 1) {
3987
+		if ($quantity == 1) {
3988 3988
 			return $this->singular_item;
3989
-		}else{
3989
+		} else {
3990 3990
 			return $this->plural_item;
3991 3991
 		}
3992 3992
 	}
@@ -4015,13 +4015,13 @@  discard block
 block discarded – undo
4015 4015
 	 * @throws EE_Error
4016 4016
 	 * @return mixed whatever the plugin which calls add_filter decides
4017 4017
 	 */
4018
-	public function __call($methodName,$args){
4019
-		$className=get_class($this);
4020
-		$tagName="FHEE__{$className}__{$methodName}";
4021
-		if(!has_filter($tagName)){
4018
+	public function __call($methodName, $args) {
4019
+		$className = get_class($this);
4020
+		$tagName = "FHEE__{$className}__{$methodName}";
4021
+		if ( ! has_filter($tagName)) {
4022 4022
 			throw new EE_Error(
4023 4023
 				sprintf(
4024
-					__( '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' ),
4024
+					__('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'),
4025 4025
 					$methodName,
4026 4026
 					$className,
4027 4027
 					$tagName,
@@ -4030,7 +4030,7 @@  discard block
 block discarded – undo
4030 4030
 			);
4031 4031
 		}
4032 4032
 
4033
-		return apply_filters($tagName,null,$this,$args);
4033
+		return apply_filters($tagName, null, $this, $args);
4034 4034
 	}
4035 4035
 
4036 4036
 
@@ -4043,22 +4043,22 @@  discard block
 block discarded – undo
4043 4043
 	 * @throws EE_Error
4044 4044
 	 * @return EE_Base_Class
4045 4045
 	 */
4046
-	public function ensure_is_obj( $base_class_obj_or_id, $ensure_is_in_db = FALSE ){
4046
+	public function ensure_is_obj($base_class_obj_or_id, $ensure_is_in_db = FALSE) {
4047 4047
 		$className = $this->_get_class_name();
4048 4048
 		$primary_key_field = $this->get_primary_key_field();
4049
-		if( $base_class_obj_or_id instanceof $className ){
4049
+		if ($base_class_obj_or_id instanceof $className) {
4050 4050
 			$model_object = $base_class_obj_or_id;
4051
-		}elseif( $primary_key_field instanceof EE_Primary_Key_Int_Field && (
4052
-				is_int( $base_class_obj_or_id ) ||
4053
-				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)
4051
+		}elseif ($primary_key_field instanceof EE_Primary_Key_Int_Field && (
4052
+				is_int($base_class_obj_or_id) ||
4053
+				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)
4054 4054
 			$model_object = $this->get_one_by_ID($base_class_obj_or_id);
4055
-		}elseif( $primary_key_field instanceof EE_Primary_Key_String_Field && is_string($base_class_obj_or_id) ){
4055
+		}elseif ($primary_key_field instanceof EE_Primary_Key_String_Field && is_string($base_class_obj_or_id)) {
4056 4056
 			//assume its a string representation of the object
4057 4057
 			$model_object = $this->get_one_by_ID($base_class_obj_or_id);
4058
-		}else{
4059
-			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)));
4058
+		} else {
4059
+			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)));
4060 4060
 		}
4061
-		if( $model_object->ID() == NULL && $ensure_is_in_db){
4061
+		if ($model_object->ID() == NULL && $ensure_is_in_db) {
4062 4062
 			$model_object->save();
4063 4063
 		}
4064 4064
 		return $model_object;
@@ -4074,19 +4074,19 @@  discard block
 block discarded – undo
4074 4074
 	 * @return int|string depending on the type of this model object's ID
4075 4075
 	 * @throws EE_Error
4076 4076
 	 */
4077
-	public function ensure_is_ID($base_class_obj_or_id){
4077
+	public function ensure_is_ID($base_class_obj_or_id) {
4078 4078
 		$className = $this->_get_class_name();
4079
-		if( $base_class_obj_or_id instanceof $className ){
4079
+		if ($base_class_obj_or_id instanceof $className) {
4080 4080
 			/** @var $base_class_obj_or_id EE_Base_Class */
4081 4081
 			$id = $base_class_obj_or_id->ID();
4082
-		}elseif(is_int($base_class_obj_or_id)){
4082
+		}elseif (is_int($base_class_obj_or_id)) {
4083 4083
 			//assume it's an ID
4084 4084
 			$id = $base_class_obj_or_id;
4085
-		}elseif(is_string($base_class_obj_or_id)){
4085
+		}elseif (is_string($base_class_obj_or_id)) {
4086 4086
 			//assume its a string representation of the object
4087 4087
 			$id = $base_class_obj_or_id;
4088
-		}else{
4089
-			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)));
4088
+		} else {
4089
+			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)));
4090 4090
 		}
4091 4091
 		return $id;
4092 4092
 	}
@@ -4109,14 +4109,14 @@  discard block
 block discarded – undo
4109 4109
 	 * @param int $values_already_prepared like one of the constants on EEM_Base
4110 4110
 	 * @return void
4111 4111
 	 */
4112
-	public function assume_values_already_prepared_by_model_object($values_already_prepared = self::not_prepared_by_model_object){
4112
+	public function assume_values_already_prepared_by_model_object($values_already_prepared = self::not_prepared_by_model_object) {
4113 4113
 		$this->_values_already_prepared_by_model_object = $values_already_prepared;
4114 4114
 	}
4115 4115
 	/**
4116 4116
 	 * Read comments for assume_values_already_prepared_by_model_object()
4117 4117
 	 * @return int
4118 4118
 	 */
4119
-	public function get_assumption_concerning_values_already_prepared_by_model_object(){
4119
+	public function get_assumption_concerning_values_already_prepared_by_model_object() {
4120 4120
 		return $this->_values_already_prepared_by_model_object;
4121 4121
 	}
4122 4122
 
@@ -4124,17 +4124,17 @@  discard block
 block discarded – undo
4124 4124
 	 * Gets all the indexes on this model
4125 4125
 	 * @return EE_Index[]
4126 4126
 	 */
4127
-	public function indexes(){
4127
+	public function indexes() {
4128 4128
 		return $this->_indexes;
4129 4129
 	}
4130 4130
 	/**
4131 4131
 	 * Gets all the Unique Indexes on this model
4132 4132
 	 * @return EE_Unique_Index[]
4133 4133
 	 */
4134
-	public function unique_indexes(){
4134
+	public function unique_indexes() {
4135 4135
 		$unique_indexes = array();
4136
-		foreach($this->_indexes as $name => $index){
4137
-			if($index instanceof EE_Unique_Index){
4136
+		foreach ($this->_indexes as $name => $index) {
4137
+			if ($index instanceof EE_Unique_Index) {
4138 4138
 				$unique_indexes [$name] = $index;
4139 4139
 			}
4140 4140
 		}
@@ -4147,9 +4147,9 @@  discard block
 block discarded – undo
4147 4147
 	 * on a primary index
4148 4148
 	 * @return EE_Model_Field_Base[]
4149 4149
 	 */
4150
-	public function get_combined_primary_key_fields(){
4151
-		foreach($this->indexes() as $index){
4152
-			if($index instanceof EE_Primary_Key_Index){
4150
+	public function get_combined_primary_key_fields() {
4151
+		foreach ($this->indexes() as $index) {
4152
+			if ($index instanceof EE_Primary_Key_Index) {
4153 4153
 				return $index->fields();
4154 4154
 			}
4155 4155
 		}
@@ -4162,7 +4162,7 @@  discard block
 block discarded – undo
4162 4162
 	 * @param array $cols_n_values keys are field names, values are their values
4163 4163
 	 * @return string
4164 4164
 	 */
4165
-	public function get_index_primary_key_string($cols_n_values){
4165
+	public function get_index_primary_key_string($cols_n_values) {
4166 4166
 		$cols_n_values_for_primary_key_index = array_intersect_key($cols_n_values, $this->get_combined_primary_key_fields());
4167 4167
 		return http_build_query($cols_n_values_for_primary_key_index);
4168 4168
 	}
@@ -4174,13 +4174,13 @@  discard block
 block discarded – undo
4174 4174
 	 * @param string $index_primary_key_string
4175 4175
 	 * @return null|array
4176 4176
 	 */
4177
-	function parse_index_primary_key_string( $index_primary_key_string) {
4177
+	function parse_index_primary_key_string($index_primary_key_string) {
4178 4178
 		$key_fields = $this->get_combined_primary_key_fields();
4179 4179
 		//check all of them are in the $id
4180 4180
 		$key_vals_in_combined_pk = array();
4181
-		parse_str( $index_primary_key_string, $key_vals_in_combined_pk );
4182
-		foreach( $key_fields as $key_field_name => $field_obj ) {
4183
-			if( ! isset( $key_vals_in_combined_pk[ $key_field_name ] ) ){
4181
+		parse_str($index_primary_key_string, $key_vals_in_combined_pk);
4182
+		foreach ($key_fields as $key_field_name => $field_obj) {
4183
+			if ( ! isset($key_vals_in_combined_pk[$key_field_name])) {
4184 4184
 				return NULL;
4185 4185
 			}
4186 4186
 		}
@@ -4193,10 +4193,10 @@  discard block
 block discarded – undo
4193 4193
 	 * @param array $key_vals
4194 4194
 	 * @return boolean
4195 4195
 	 */
4196
-	function has_all_combined_primary_key_fields( $key_vals ) {
4197
-		$keys_it_should_have = array_keys( $this->get_combined_primary_key_fields() );
4198
-		foreach( $keys_it_should_have as $key ){
4199
-			if( ! isset( $key_vals[ $key ] ) ){
4196
+	function has_all_combined_primary_key_fields($key_vals) {
4197
+		$keys_it_should_have = array_keys($this->get_combined_primary_key_fields());
4198
+		foreach ($keys_it_should_have as $key) {
4199
+			if ( ! isset($key_vals[$key])) {
4200 4200
 				return false;
4201 4201
 			}
4202 4202
 		}
@@ -4212,23 +4212,23 @@  discard block
 block discarded – undo
4212 4212
 	 * @throws EE_Error
4213 4213
 	 * @return \EE_Base_Class[] Array keys are object IDs (if there is a primary key on the model. if not, numerically indexed)
4214 4214
 	 */
4215
-	public function get_all_copies($model_object_or_attributes_array, $query_params = array()){
4215
+	public function get_all_copies($model_object_or_attributes_array, $query_params = array()) {
4216 4216
 
4217
-		if($model_object_or_attributes_array instanceof EE_Base_Class){
4217
+		if ($model_object_or_attributes_array instanceof EE_Base_Class) {
4218 4218
 			$attributes_array = $model_object_or_attributes_array->model_field_array();
4219
-		}elseif(is_array($model_object_or_attributes_array)){
4219
+		}elseif (is_array($model_object_or_attributes_array)) {
4220 4220
 			$attributes_array = $model_object_or_attributes_array;
4221
-		}else{
4222
-			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));
4221
+		} else {
4222
+			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));
4223 4223
 		}
4224 4224
 		//even copies obviously won't have the same ID, so remove the primary key
4225 4225
 		//from the WHERE conditions for finding copies (if there is a primary key, of course)
4226
-		if($this->has_primary_key_field() && isset($attributes_array[$this->primary_key_name()])){
4226
+		if ($this->has_primary_key_field() && isset($attributes_array[$this->primary_key_name()])) {
4227 4227
 			unset($attributes_array[$this->primary_key_name()]);
4228 4228
 		}
4229
-		if(isset($query_params[0])){
4230
-			$query_params[0] = array_merge($attributes_array,$query_params);
4231
-		}else{
4229
+		if (isset($query_params[0])) {
4230
+			$query_params[0] = array_merge($attributes_array, $query_params);
4231
+		} else {
4232 4232
 			$query_params[0] = $attributes_array;
4233 4233
 		}
4234 4234
 		return $this->get_all($query_params);
@@ -4242,16 +4242,16 @@  discard block
 block discarded – undo
4242 4242
 	 * @param array $query_params
4243 4243
 	 * @return EE_Base_Class
4244 4244
 	 */
4245
-	function get_one_copy($model_object_or_attributes_array,$query_params = array()){
4246
-		if( ! is_array( $query_params ) ){
4247
-			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' );
4245
+	function get_one_copy($model_object_or_attributes_array, $query_params = array()) {
4246
+		if ( ! is_array($query_params)) {
4247
+			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');
4248 4248
 			$query_params = array();
4249 4249
 		}
4250 4250
 		$query_params['limit'] = 1;
4251
-		$copies = $this->get_all_copies($model_object_or_attributes_array,$query_params);
4252
-		if(is_array($copies)){
4251
+		$copies = $this->get_all_copies($model_object_or_attributes_array, $query_params);
4252
+		if (is_array($copies)) {
4253 4253
 			return array_shift($copies);
4254
-		}else{
4254
+		} else {
4255 4255
 			return null;
4256 4256
 		}
4257 4257
 	}
@@ -4265,10 +4265,10 @@  discard block
 block discarded – undo
4265 4265
 	 * @param int|string $id the value of the primary key to update
4266 4266
 	 * @return int number of rows updated
4267 4267
 	 */
4268
-	public function update_by_ID($fields_n_values,$id){
4268
+	public function update_by_ID($fields_n_values, $id) {
4269 4269
 		$query_params = array(0=>array($this->get_primary_key_field()->get_name() => $id),
4270 4270
 			'default_where_conditions'=>'other_models_only',);
4271
-		return $this->update($fields_n_values,$query_params);
4271
+		return $this->update($fields_n_values, $query_params);
4272 4272
 	}
4273 4273
 
4274 4274
 
@@ -4279,12 +4279,12 @@  discard block
 block discarded – undo
4279 4279
 	 * @return string an operator which can be used in SQL
4280 4280
 	 * @throws EE_Error
4281 4281
 	 */
4282
-	private function _prepare_operator_for_sql($operator_supplied){
4282
+	private function _prepare_operator_for_sql($operator_supplied) {
4283 4283
 		$sql_operator = isset($this->_valid_operators[$operator_supplied]) ? $this->_valid_operators[$operator_supplied] : null;
4284
-		if($sql_operator){
4284
+		if ($sql_operator) {
4285 4285
 			return $sql_operator;
4286
-		}else{
4287
-			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))));
4286
+		} else {
4287
+			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))));
4288 4288
 		}
4289 4289
 	}
4290 4290
 
@@ -4294,10 +4294,10 @@  discard block
 block discarded – undo
4294 4294
 	 * @param array $query_params like get_all's
4295 4295
 	 * @return string[]
4296 4296
 	 */
4297
-	public function get_all_names($query_params = array()){
4297
+	public function get_all_names($query_params = array()) {
4298 4298
 		$objs = $this->get_all($query_params);
4299 4299
 		$names = array();
4300
-		foreach($objs as $obj){
4300
+		foreach ($objs as $obj) {
4301 4301
 			$names[$obj->ID()] = $obj->name();
4302 4302
 		}
4303 4303
 		return $names;
@@ -4312,22 +4312,22 @@  discard block
 block discarded – undo
4312 4312
 	 * @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
4313 4313
 	 * @return array
4314 4314
 	 */
4315
-	public function get_IDs( $model_objects, $filter_out_empty_ids = false) {
4316
-		if( ! $this->has_primary_key_field() ) {
4317
-			if( WP_DEBUG ) {
4318
-				EE_Error::add_error( __( 'Trying to get IDs from a model than has no primary key', 'event_espresso' ), __FILE__, __FUNCTION__, __LINE__ );
4315
+	public function get_IDs($model_objects, $filter_out_empty_ids = false) {
4316
+		if ( ! $this->has_primary_key_field()) {
4317
+			if (WP_DEBUG) {
4318
+				EE_Error::add_error(__('Trying to get IDs from a model than has no primary key', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__);
4319 4319
 				return array();
4320 4320
 			}
4321 4321
 		}
4322 4322
 		$IDs = array();
4323
-		foreach( $model_objects as $model_object ) {
4323
+		foreach ($model_objects as $model_object) {
4324 4324
 			$id = $model_object->ID();
4325
-			if( ! $id ) {
4326
-				if( $filter_out_empty_ids ) {
4325
+			if ( ! $id) {
4326
+				if ($filter_out_empty_ids) {
4327 4327
 					continue;
4328 4328
 				}
4329
-				if( WP_DEBUG ) {
4330
-					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__ );
4329
+				if (WP_DEBUG) {
4330
+					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__);
4331 4331
 				}
4332 4332
 			}
4333 4333
 			$IDs[] = $id;
@@ -4340,8 +4340,8 @@  discard block
 block discarded – undo
4340 4340
 	 * are no capabilities that relate to this model returns false
4341 4341
 	 * @return string|false
4342 4342
 	 */
4343
-	public function cap_slug(){
4344
-		return apply_filters( 'FHEE__EEM_Base__cap_slug', $this->_caps_slug, $this);
4343
+	public function cap_slug() {
4344
+		return apply_filters('FHEE__EEM_Base__cap_slug', $this->_caps_slug, $this);
4345 4345
 	}
4346 4346
 
4347 4347
 	/**
@@ -4353,27 +4353,27 @@  discard block
 block discarded – undo
4353 4353
 	 * @param string $context
4354 4354
 	 * @return EE_Default_Where_Conditions[] indexed by associated capability
4355 4355
 	 */
4356
-	public function cap_restrictions( $context = EEM_Base::caps_read ) {
4357
-		EEM_Base::verify_is_valid_cap_context( $context );
4356
+	public function cap_restrictions($context = EEM_Base::caps_read) {
4357
+		EEM_Base::verify_is_valid_cap_context($context);
4358 4358
 		//check if we ought to run the restriction generator first
4359
-		if( isset( $this->_cap_restriction_generators[ $context ] ) &&
4360
-				$this->_cap_restriction_generators[ $context ] instanceof EE_Restriction_Generator_Base &&
4361
-				! $this->_cap_restriction_generators[ $context ]->has_generated_cap_restrictions() ) {
4362
-			$this->_cap_restrictions[ $context ] = array_merge( $this->_cap_restrictions[ $context ],  $this->_cap_restriction_generators[ $context ]->generate_restrictions() );
4359
+		if (isset($this->_cap_restriction_generators[$context]) &&
4360
+				$this->_cap_restriction_generators[$context] instanceof EE_Restriction_Generator_Base &&
4361
+				! $this->_cap_restriction_generators[$context]->has_generated_cap_restrictions()) {
4362
+			$this->_cap_restrictions[$context] = array_merge($this->_cap_restrictions[$context], $this->_cap_restriction_generators[$context]->generate_restrictions());
4363 4363
 		}
4364 4364
 		//and make sure we've finalized the construction of each restriction
4365
-		foreach( $this->_cap_restrictions[ $context ] as $where_conditions_obj ) {
4366
-			$where_conditions_obj->_finalize_construct( $this );
4365
+		foreach ($this->_cap_restrictions[$context] as $where_conditions_obj) {
4366
+			$where_conditions_obj->_finalize_construct($this);
4367 4367
 		}
4368 4368
 
4369
-		return $this->_cap_restrictions[ $context ];
4369
+		return $this->_cap_restrictions[$context];
4370 4370
 	}
4371 4371
 
4372 4372
 	/**
4373 4373
 	 * Indicating whether or not this model thinks its a wp core model
4374 4374
 	 * @return boolean
4375 4375
 	 */
4376
-	public function is_wp_core_model(){
4376
+	public function is_wp_core_model() {
4377 4377
 		return $this->_wp_core_model;
4378 4378
 	}
4379 4379
 
@@ -4383,12 +4383,12 @@  discard block
 block discarded – undo
4383 4383
 	 * @param string $context one of EEM_Base::caps_ constants
4384 4384
 	 * @return EE_Default_Where_Conditions[] indexed by capability name
4385 4385
 	 */
4386
-	public function caps_missing( $context = EEM_Base::caps_read ) {
4386
+	public function caps_missing($context = EEM_Base::caps_read) {
4387 4387
 		$missing_caps = array();
4388
-		$cap_restrictions = $this->cap_restrictions( $context );
4389
-		foreach( $cap_restrictions as $cap => $restriction_if_no_cap ) {
4390
-			if( ! EE_Capabilities::instance()->current_user_can( $cap, $this->get_this_model_name() . '_model_applying_caps') ) {
4391
-				$missing_caps[ $cap ] = $restriction_if_no_cap;
4388
+		$cap_restrictions = $this->cap_restrictions($context);
4389
+		foreach ($cap_restrictions as $cap => $restriction_if_no_cap) {
4390
+			if ( ! EE_Capabilities::instance()->current_user_can($cap, $this->get_this_model_name().'_model_applying_caps')) {
4391
+				$missing_caps[$cap] = $restriction_if_no_cap;
4392 4392
 			}
4393 4393
 		}
4394 4394
 		return $missing_caps;
@@ -4400,7 +4400,7 @@  discard block
 block discarded – undo
4400 4400
 	 * one of 'read', 'edit', or 'delete'
4401 4401
 	 */
4402 4402
 	public function cap_contexts_to_cap_action_map() {
4403
-		return apply_filters( 'FHEE__EEM_Base__cap_contexts_to_cap_action_map', $this->_cap_contexts_to_cap_action_map, $this );
4403
+		return apply_filters('FHEE__EEM_Base__cap_contexts_to_cap_action_map', $this->_cap_contexts_to_cap_action_map, $this);
4404 4404
 	}
4405 4405
 
4406 4406
 
@@ -4411,19 +4411,19 @@  discard block
 block discarded – undo
4411 4411
 	 * @return string one of EEM_Base::cap_contexts_to_cap_action_map() values
4412 4412
 	 * @throws \EE_Error
4413 4413
 	 */
4414
-	public function cap_action_for_context( $context ) {
4414
+	public function cap_action_for_context($context) {
4415 4415
 		$mapping = $this->cap_contexts_to_cap_action_map();
4416
-		if( isset( $mapping[ $context ] ) ) {
4417
-			return $mapping[ $context ];
4416
+		if (isset($mapping[$context])) {
4417
+			return $mapping[$context];
4418 4418
 		}
4419
-		if( $action = apply_filters( 'FHEE__EEM_Base__cap_action_for_context', null, $this, $mapping, $context ) ) {
4419
+		if ($action = apply_filters('FHEE__EEM_Base__cap_action_for_context', null, $this, $mapping, $context)) {
4420 4420
 			return $action;
4421 4421
 		}
4422 4422
 		throw new EE_Error(
4423 4423
 			sprintf(
4424
-				__( 'Cannot find capability restrictions for context "%1$s", allowed values are:%2$s', 'event_espresso' ),
4424
+				__('Cannot find capability restrictions for context "%1$s", allowed values are:%2$s', 'event_espresso'),
4425 4425
 				$context,
4426
-				implode(',', array_keys( $this->cap_contexts_to_cap_action_map() ) )
4426
+				implode(',', array_keys($this->cap_contexts_to_cap_action_map()))
4427 4427
 			)
4428 4428
 		);
4429 4429
 
@@ -4434,7 +4434,7 @@  discard block
 block discarded – undo
4434 4434
 	 * @return array
4435 4435
 	 */
4436 4436
 	static public function valid_cap_contexts() {
4437
-		return apply_filters( 'FHEE__EEM_Base__valid_cap_contexts', array(
4437
+		return apply_filters('FHEE__EEM_Base__valid_cap_contexts', array(
4438 4438
 			self::caps_read,
4439 4439
 			self::caps_read_admin,
4440 4440
 			self::caps_edit,
@@ -4450,17 +4450,17 @@  discard block
 block discarded – undo
4450 4450
 	 * @return bool
4451 4451
 	 * @throws \EE_Error
4452 4452
 	 */
4453
-	static public function verify_is_valid_cap_context( $context ) {
4453
+	static public function verify_is_valid_cap_context($context) {
4454 4454
 		$valid_cap_contexts = EEM_Base::valid_cap_contexts();
4455
-		if( in_array( $context, $valid_cap_contexts ) ) {
4455
+		if (in_array($context, $valid_cap_contexts)) {
4456 4456
 			return true;
4457
-		}else{
4457
+		} else {
4458 4458
 			throw new EE_Error(
4459 4459
 				sprintf(
4460
-					__( 'Context "%1$s" passed into model "%2$s" is not a valid context. They are: %3$s', 'event_espresso' ),
4460
+					__('Context "%1$s" passed into model "%2$s" is not a valid context. They are: %3$s', 'event_espresso'),
4461 4461
 					$context,
4462
-					'EEM_Base' ,
4463
-					implode(',', $valid_cap_contexts )
4462
+					'EEM_Base',
4463
+					implode(',', $valid_cap_contexts)
4464 4464
 				)
4465 4465
 			);
4466 4466
 		}
Please login to merge, or discard this patch.