Completed
Branch BUG-8698-ticket-sellouts (4c4ee4)
by
unknown
125:44 queued 110:35
created
caffeinated/payment_methods/Aim/EEG_Aim.gateway.php 1 patch
Spacing   +37 added lines, -37 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 
3
-if (!defined('EVENT_ESPRESSO_VERSION'))
3
+if ( ! defined('EVENT_ESPRESSO_VERSION'))
4 4
 	exit('No direct script access allowed');
5 5
 
6 6
 /**
@@ -25,7 +25,7 @@  discard block
 block discarded – undo
25 25
  *
26 26
  * ------------------------------------------------------------------------
27 27
  */
28
-class EEG_Aim extends EE_Onsite_Gateway{
28
+class EEG_Aim extends EE_Onsite_Gateway {
29 29
 	protected $_login_id;
30 30
 	protected $_transaction_key;
31 31
 	protected $_currencies_supported = array(
@@ -98,21 +98,21 @@  discard block
 block discarded – undo
98 98
 			$primary_registrant = $transaction->primary_registration();
99 99
 			//if we're are charging for the full amount, show the normal line items
100 100
 			//and the itemized total adds up properly
101
-			if( $this->_can_easily_itemize_transaction_for( $payment ) ){
101
+			if ($this->_can_easily_itemize_transaction_for($payment)) {
102 102
 				$total_line_item = $transaction->total_line_item();
103 103
 				foreach ($total_line_item->get_items() as $line_item) {
104 104
 					//ignore line items with a quantity of 0
105
-					if( $line_item->quantity() == 0 ){
105
+					if ($line_item->quantity() == 0) {
106 106
 						continue;
107 107
 					}
108 108
 					$this->addLineItem($item_num++, $line_item->name(), $line_item->desc(), $line_item->quantity(), $line_item->unit_price(), 'N');
109 109
 					$order_description .= $line_item->desc().', ';
110 110
 				}
111
-				foreach($total_line_item->tax_descendants() as $tax_line_item){
111
+				foreach ($total_line_item->tax_descendants() as $tax_line_item) {
112 112
 					$this->addLineItem($item_num++, $tax_line_item->name(), $tax_line_item->desc(), 1, $tax_line_item->total(), 'N');
113 113
 				}
114
-			}else{//partial payment
115
-				$order_description = sprintf(__("Payment of %s for %s", "event_espresso"),$payment->amount(),$primary_registrant->reg_code());
114
+			} else {//partial payment
115
+				$order_description = sprintf(__("Payment of %s for %s", "event_espresso"), $payment->amount(), $primary_registrant->reg_code());
116 116
 			}
117 117
 
118 118
 
@@ -121,18 +121,18 @@  discard block
 block discarded – undo
121 121
 			//start transaction
122 122
 			//if in debug mode, use authorize.net's sandbox id; otherwise use the Event Espresso partner id
123 123
 			$partner_id = $this->_debug_mode ? 'AAA100302' : 'AAA105363';
124
-			$this->setField( 'solution_id', $partner_id );
124
+			$this->setField('solution_id', $partner_id);
125 125
 			$this->setField('amount', $this->format_currency($payment->amount()));
126
-			$this->setField('description',substr(rtrim($order_description, ', '), 0, 255));
127
-			$this->_set_sensitive_billing_data( $billing_info );
126
+			$this->setField('description', substr(rtrim($order_description, ', '), 0, 255));
127
+			$this->_set_sensitive_billing_data($billing_info);
128 128
 			$this->setField('first_name', $billing_info['first_name']);
129 129
 			$this->setField('last_name', $billing_info['last_name']);
130 130
 			$this->setField('email', $billing_info['email']);
131 131
 			$this->setField('company', $billing_info['company']);
132 132
 			$this->setField('address', $billing_info['address'].' '.$billing_info['address2']);
133 133
 			$this->setField('city', $billing_info['city']);
134
-			$this->setField('state', $billing_info['state'] );
135
-			$this->setField('country', $billing_info['country'] );
134
+			$this->setField('state', $billing_info['state']);
135
+			$this->setField('country', $billing_info['country']);
136 136
 			$this->setField('zip', $billing_info['zip']);
137 137
 			$this->setField('fax', $billing_info['fax']);
138 138
 			$this->setField('cust_id', $primary_registrant->ID());
@@ -140,9 +140,9 @@  discard block
 block discarded – undo
140 140
 			//invoice_num would be nice to have itbe unique per SPCO page-load, taht way if users
141 141
 			//press back, they don't submit a duplicate. However, we may be keepin gthe user on teh same spco page
142 142
 			//in which case, we need to generate teh invoice num per request right here...
143
-			$this->setField('invoice_num', wp_generate_password(12,false));//$billing_info['_reg-page-billing-invoice-'.$this->_gateway_name]['value']);
143
+			$this->setField('invoice_num', wp_generate_password(12, false)); //$billing_info['_reg-page-billing-invoice-'.$this->_gateway_name]['value']);
144 144
 			//tell AIM that any duplicates sent in the next 5 minutes are to be ignored
145
-            $this->setField('duplicate_window', 5 * MINUTE_IN_SECONDS );
145
+            $this->setField('duplicate_window', 5 * MINUTE_IN_SECONDS);
146 146
 
147 147
 
148 148
 			if ($this->_test_transactions) {
@@ -152,7 +152,7 @@  discard block
 block discarded – undo
152 152
 			//Capture response
153 153
 			$this->type = "AUTH_CAPTURE";
154 154
 			$response = $this->_sendRequest($payment);
155
-			if (!empty($response)){
155
+			if ( ! empty($response)) {
156 156
 				if ($this->_debug_mode) {
157 157
 					$txn_id = $response->invoice_number;
158 158
 				} else {
@@ -161,15 +161,15 @@  discard block
 block discarded – undo
161 161
 				$payment_status = $response->approved ? $this->_pay_model->approved_status() : $this->_pay_model->declined_status();
162 162
 				$payment->set_status($payment_status);
163 163
 				//make sure we interpret the AMT as a float, not an international string (where periods are thousand seperators)
164
-				$payment->set_amount( floatval( $response->amount ) );
165
-				$payment->set_gateway_response(sprintf("%s (code: %s)",$response->response_reason_text,$response->response_reason_code));
166
-				$payment->set_txn_id_chq_nmbr( $txn_id );
164
+				$payment->set_amount(floatval($response->amount));
165
+				$payment->set_gateway_response(sprintf("%s (code: %s)", $response->response_reason_text, $response->response_reason_code));
166
+				$payment->set_txn_id_chq_nmbr($txn_id);
167 167
 				$payment->set_extra_accntng($primary_registrant->reg_code());
168
-				$payment->set_details(print_r($response,true));
168
+				$payment->set_details(print_r($response, true));
169 169
 			} else {
170 170
 				$payment->set_status($this->_pay_model->failed_status());
171 171
 				$payment->set_gateway_response(__("There was no response from Authorize.net", 'event_espresso'));
172
-				$payment->set_details(print_r($response,true));
172
+				$payment->set_details(print_r($response, true));
173 173
 			}
174 174
 		return $payment;
175 175
 	}
@@ -180,7 +180,7 @@  discard block
 block discarded – undo
180 180
 	 * what billing data gets sent
181 181
 	 * @param array $billing_info
182 182
 	 */
183
-	protected function _set_sensitive_billing_data( $billing_info ) {
183
+	protected function _set_sensitive_billing_data($billing_info) {
184 184
 		$this->setField('card_num', $billing_info['credit_card']);
185 185
 		$this->setField('exp_date', $billing_info['exp_month'].$billing_info['exp_year']);
186 186
 		$this->setField('card_code', $billing_info['cvv']);
@@ -232,22 +232,22 @@  discard block
 block discarded – undo
232 232
 		$this->_x_post_fields['tran_key'] = $this->_transaction_key;
233 233
 		$x_keys = array();
234 234
 		foreach ($this->_x_post_fields as $key => $value) {
235
-			$x_keys[] = "x_$key=" . urlencode($value);
235
+			$x_keys[] = "x_$key=".urlencode($value);
236 236
 		}
237 237
 		// Add line items
238 238
 		foreach ($this->_additional_line_items as $key => $value) {
239
-			$x_keys[] =  "x_line_item=" . urlencode($value);
239
+			$x_keys[] = "x_line_item=".urlencode($value);
240 240
 		}
241 241
 		$this->_log_clean_request($x_keys, $payment);
242 242
 		$post_url = ($this->_debug_mode ? self::SANDBOX_URL : self::LIVE_URL);
243 243
 		$curl_request = curl_init($post_url);
244
-		curl_setopt($curl_request, CURLOPT_POSTFIELDS, implode("&",$x_keys));
244
+		curl_setopt($curl_request, CURLOPT_POSTFIELDS, implode("&", $x_keys));
245 245
 		curl_setopt($curl_request, CURLOPT_HEADER, 0);
246 246
 		curl_setopt($curl_request, CURLOPT_TIMEOUT, 45);
247 247
 		curl_setopt($curl_request, CURLOPT_RETURNTRANSFER, 1);
248 248
 		curl_setopt($curl_request, CURLOPT_SSL_VERIFYHOST, 2);
249 249
 		if ($this->VERIFY_PEER) {
250
-			curl_setopt($curl_request, CURLOPT_CAINFO, dirname(dirname(__FILE__)) . '/ssl/cert.pem');
250
+			curl_setopt($curl_request, CURLOPT_CAINFO, dirname(dirname(__FILE__)).'/ssl/cert.pem');
251 251
 		} else {
252 252
 			curl_setopt($curl_request, CURLOPT_SSL_VERIFYPEER, false);
253 253
 		}
@@ -259,7 +259,7 @@  discard block
 block discarded – undo
259 259
 		$response = curl_exec($curl_request);
260 260
 
261 261
 		curl_close($curl_request);
262
-		$response_obj =  new EE_AuthorizeNetAIM_Response($response);
262
+		$response_obj = new EE_AuthorizeNetAIM_Response($response);
263 263
 
264 264
 		return $this->_log_and_clean_response($response_obj, $payment);
265 265
 	}
@@ -268,18 +268,18 @@  discard block
 block discarded – undo
268 268
 	 * @param array $request_array
269 269
 	 * @param EEI_Payment $payment
270 270
 	 */
271
-	protected function _log_clean_request($request_array,$payment){
272
-		$keys_to_filter_out = array( 'x_card_num', 'x_card_code', 'x_exp_date' );
273
-		foreach($request_array as $index => $keyvaltogether ) {
274
-			foreach( $keys_to_filter_out as $key ) {
275
-				if( strpos( $keyvaltogether, $key ) === 0 ){
271
+	protected function _log_clean_request($request_array, $payment) {
272
+		$keys_to_filter_out = array('x_card_num', 'x_card_code', 'x_exp_date');
273
+		foreach ($request_array as $index => $keyvaltogether) {
274
+			foreach ($keys_to_filter_out as $key) {
275
+				if (strpos($keyvaltogether, $key) === 0) {
276 276
 					//found it at the first character
277 277
 					//so its one of them
278
-					unset( $request_array[ $index ] );
278
+					unset($request_array[$index]);
279 279
 				}
280 280
 			}
281 281
 		}
282
-		$this->log(array('AIM Request sent:'=>$request_array),$payment);
282
+		$this->log(array('AIM Request sent:'=>$request_array), $payment);
283 283
 	}
284 284
 
285 285
 	/**
@@ -287,9 +287,9 @@  discard block
 block discarded – undo
287 287
 	 * @param EE_AuthorizeNetAIM_Response $response_obj
288 288
 	 * @param EE_Payment $payment
289 289
 	 */
290
-	private function _log_and_clean_response($response_obj,$payment){
290
+	private function _log_and_clean_response($response_obj, $payment) {
291 291
 		$response_obj->account_number = '';
292
-		$this->log(array('AIM Response received:'=>$response_obj),$payment);
292
+		$this->log(array('AIM Response received:'=>$response_obj), $payment);
293 293
 		return $response_obj;
294 294
 	}
295 295
 
@@ -385,7 +385,7 @@  discard block
 block discarded – undo
385 385
 			// Split Array
386 386
 			$this->response = $response;
387 387
 			if ($encap_char) {
388
-				$this->_response_array = explode($encap_char . $delimiter . $encap_char, substr($response, 1, -1));
388
+				$this->_response_array = explode($encap_char.$delimiter.$encap_char, substr($response, 1, -1));
389 389
 			} else {
390 390
 				$this->_response_array = explode($delimiter, $response);
391 391
 			}
@@ -455,7 +455,7 @@  discard block
 block discarded – undo
455 455
 			$this->held = ($this->response_code == self::HELD);
456 456
 
457 457
 			if ($this->error || $this->declined || $this->held) {
458
-				$this->error_message = '<p><strong class="credit_card_failure">Attention: your transaction was declined for the following reason(s):</strong><br />' . $this->response_reason_text . '<br /><span class="response_code">Response Code: ' . $this->response_code . '<br /></span><span class="response_subcode">Response Subcode: ' . $this->response_subcode . '</span></p><p>To try again, <a href="#payment_options">please click here</a>.</p> ';
458
+				$this->error_message = '<p><strong class="credit_card_failure">Attention: your transaction was declined for the following reason(s):</strong><br />'.$this->response_reason_text.'<br /><span class="response_code">Response Code: '.$this->response_code.'<br /></span><span class="response_subcode">Response Subcode: '.$this->response_subcode.'</span></p><p>To try again, <a href="#payment_options">please click here</a>.</p> ';
459 459
 
460 460
 
461 461
 				/* $this->error_message = "AuthorizeNet Error:
Please login to merge, or discard this patch.
reg_steps/payment_options/EE_SPCO_Reg_Step_Payment_Options.class.php 1 patch
Spacing   +388 added lines, -388 removed lines patch added patch discarded remove patch
@@ -34,15 +34,15 @@  discard block
 block discarded – undo
34 34
 	 *  @return 	void
35 35
 	 */
36 36
 	public static function set_hooks() {
37
-		add_filter( 'FHEE__SPCO__EE_Line_Item_Filter_Collection', array( 'EE_SPCO_Reg_Step_Payment_Options', 'add_spco_line_item_filters' ) );
38
-		add_action( 'wp_ajax_switch_spco_billing_form', array( 'EE_SPCO_Reg_Step_Payment_Options', 'switch_spco_billing_form' ));
39
-		add_action( 'wp_ajax_nopriv_switch_spco_billing_form', array( 'EE_SPCO_Reg_Step_Payment_Options', 'switch_spco_billing_form' ));
40
-		add_action( 'wp_ajax_save_payer_details', array( 'EE_SPCO_Reg_Step_Payment_Options', 'save_payer_details' ));
41
-		add_action( 'wp_ajax_nopriv_save_payer_details', array( 'EE_SPCO_Reg_Step_Payment_Options', 'save_payer_details' ));
42
-		add_action( 'wp_ajax_get_transaction_details_for_gateways', array( 'EE_SPCO_Reg_Step_Payment_Options', 'get_transaction_details' ) );
43
-		add_action( 'wp_ajax_nopriv_get_transaction_details_for_gateways', array( 'EE_SPCO_Reg_Step_Payment_Options', 'get_transaction_details' )
37
+		add_filter('FHEE__SPCO__EE_Line_Item_Filter_Collection', array('EE_SPCO_Reg_Step_Payment_Options', 'add_spco_line_item_filters'));
38
+		add_action('wp_ajax_switch_spco_billing_form', array('EE_SPCO_Reg_Step_Payment_Options', 'switch_spco_billing_form'));
39
+		add_action('wp_ajax_nopriv_switch_spco_billing_form', array('EE_SPCO_Reg_Step_Payment_Options', 'switch_spco_billing_form'));
40
+		add_action('wp_ajax_save_payer_details', array('EE_SPCO_Reg_Step_Payment_Options', 'save_payer_details'));
41
+		add_action('wp_ajax_nopriv_save_payer_details', array('EE_SPCO_Reg_Step_Payment_Options', 'save_payer_details'));
42
+		add_action('wp_ajax_get_transaction_details_for_gateways', array('EE_SPCO_Reg_Step_Payment_Options', 'get_transaction_details'));
43
+		add_action('wp_ajax_nopriv_get_transaction_details_for_gateways', array('EE_SPCO_Reg_Step_Payment_Options', 'get_transaction_details')
44 44
 		);
45
-		add_filter( 'FHEE__EED_Recaptcha___bypass_recaptcha__bypass_request_params_array', array( 'EE_SPCO_Reg_Step_Payment_Options', 'bypass_recaptcha_for_load_payment_method' ), 10, 1 );
45
+		add_filter('FHEE__EED_Recaptcha___bypass_recaptcha__bypass_request_params_array', array('EE_SPCO_Reg_Step_Payment_Options', 'bypass_recaptcha_for_load_payment_method'), 10, 1);
46 46
 	}
47 47
 
48 48
 
@@ -51,7 +51,7 @@  discard block
 block discarded – undo
51 51
 	 * 	ajax switch_spco_billing_form
52 52
 	 */
53 53
 	public static function switch_spco_billing_form() {
54
-		EED_Single_Page_Checkout::process_ajax_request( 'switch_payment_method' );
54
+		EED_Single_Page_Checkout::process_ajax_request('switch_payment_method');
55 55
 	}
56 56
 
57 57
 
@@ -60,7 +60,7 @@  discard block
 block discarded – undo
60 60
 	 * 	ajax save_payer_details
61 61
 	 */
62 62
 	public static function save_payer_details() {
63
-		EED_Single_Page_Checkout::process_ajax_request( 'save_payer_details_via_ajax' );
63
+		EED_Single_Page_Checkout::process_ajax_request('save_payer_details_via_ajax');
64 64
 	}
65 65
 
66 66
 
@@ -69,7 +69,7 @@  discard block
 block discarded – undo
69 69
 	 * 	ajax get_transaction_details
70 70
 	 */
71 71
 	public static function get_transaction_details() {
72
-		EED_Single_Page_Checkout::process_ajax_request( 'get_transaction_details_for_gateways' );
72
+		EED_Single_Page_Checkout::process_ajax_request('get_transaction_details_for_gateways');
73 73
 	}
74 74
 
75 75
 
@@ -97,13 +97,13 @@  discard block
 block discarded – undo
97 97
 	 * @param    EE_Checkout $checkout
98 98
 	 * @return    \EE_SPCO_Reg_Step_Payment_Options
99 99
 	 */
100
-	public function __construct( EE_Checkout $checkout ) {
100
+	public function __construct(EE_Checkout $checkout) {
101 101
 		$this->_slug = 'payment_options';
102 102
 		$this->_name = __('Payment Options', 'event_espresso');
103
-		$this->_template = SPCO_REG_STEPS_PATH . $this->_slug . DS . 'payment_options_main.template.php';
103
+		$this->_template = SPCO_REG_STEPS_PATH.$this->_slug.DS.'payment_options_main.template.php';
104 104
 		$this->checkout = $checkout;
105 105
 		$this->_reset_success_message();
106
-		$this->set_instructions( __('Please select a method of payment and provide any necessary billing information before proceeding.', 'event_espresso'));
106
+		$this->set_instructions(__('Please select a method of payment and provide any necessary billing information before proceeding.', 'event_espresso'));
107 107
 	}
108 108
 
109 109
 
@@ -120,7 +120,7 @@  discard block
 block discarded – undo
120 120
 	/**
121 121
 	 * @param null $line_item_display
122 122
 	 */
123
-	public function set_line_item_display( $line_item_display ) {
123
+	public function set_line_item_display($line_item_display) {
124 124
 		$this->line_item_display = $line_item_display;
125 125
 	}
126 126
 
@@ -138,8 +138,8 @@  discard block
 block discarded – undo
138 138
 	/**
139 139
 	 * @param boolean $handle_IPN_in_this_request
140 140
 	 */
141
-	public function set_handle_IPN_in_this_request( $handle_IPN_in_this_request ) {
142
-		$this->handle_IPN_in_this_request = filter_var( $handle_IPN_in_this_request, FILTER_VALIDATE_BOOLEAN );
141
+	public function set_handle_IPN_in_this_request($handle_IPN_in_this_request) {
142
+		$this->handle_IPN_in_this_request = filter_var($handle_IPN_in_this_request, FILTER_VALIDATE_BOOLEAN);
143 143
 	}
144 144
 
145 145
 
@@ -149,9 +149,9 @@  discard block
 block discarded – undo
149 149
 	 * @return void
150 150
 	 */
151 151
 	public function translate_js_strings() {
152
-		EE_Registry::$i18n_js_strings['no_payment_method'] = __( 'Please select a method of payment in order to continue.', 'event_espresso' );
153
-		EE_Registry::$i18n_js_strings['invalid_payment_method'] = __( 'A valid method of payment could not be determined. Please refresh the page and try again.', 'event_espresso' );
154
-		EE_Registry::$i18n_js_strings['forwarding_to_offsite'] = __( 'Forwarding to Secure Payment Provider.', 'event_espresso' );
152
+		EE_Registry::$i18n_js_strings['no_payment_method'] = __('Please select a method of payment in order to continue.', 'event_espresso');
153
+		EE_Registry::$i18n_js_strings['invalid_payment_method'] = __('A valid method of payment could not be determined. Please refresh the page and try again.', 'event_espresso');
154
+		EE_Registry::$i18n_js_strings['forwarding_to_offsite'] = __('Forwarding to Secure Payment Provider.', 'event_espresso');
155 155
 	}
156 156
 
157 157
 
@@ -180,20 +180,20 @@  discard block
 block discarded – undo
180 180
 			// 	$ 0.00 transactions (no payment required)
181 181
 			! $this->checkout->payment_required()
182 182
 			// but do NOT remove if current action being called belongs to this reg step
183
-			&& ! is_callable( array( $this, $this->checkout->action ) )
183
+			&& ! is_callable(array($this, $this->checkout->action))
184 184
 			&& ! $this->completed()
185 185
 		) {
186 186
 			// and if so, then we no longer need the Payment Options step
187
-			if ( $this->is_current_step() ) {
187
+			if ($this->is_current_step()) {
188 188
 				$this->checkout->generate_reg_form = false;
189 189
 			}
190
-			$this->checkout->remove_reg_step( $this->_slug );
190
+			$this->checkout->remove_reg_step($this->_slug);
191 191
 			// DEBUG LOG
192 192
 			//$this->checkout->log( __CLASS__, __FUNCTION__, __LINE__ );
193 193
 			return false;
194 194
 		}
195 195
 		// load EEM_Payment_Method
196
-		EE_Registry::instance()->load_model( 'Payment_Method' );
196
+		EE_Registry::instance()->load_model('Payment_Method');
197 197
 		// get all active payment methods
198 198
 		$this->checkout->available_payment_methods = EEM_Payment_Method::instance()->get_all_for_transaction(
199 199
 			$this->checkout->transaction, EEM_Payment_Method::scope_cart
@@ -207,7 +207,7 @@  discard block
 block discarded – undo
207 207
 	 * @return bool
208 208
 	 */
209 209
 	public function generate_reg_form() {
210
-		EE_Registry::instance()->load_helper( 'HTML' );
210
+		EE_Registry::instance()->load_helper('HTML');
211 211
 		// reset in case someone changes their mind
212 212
 		$this->_reset_selected_method_of_payment();
213 213
 		// set some defaults
@@ -219,14 +219,14 @@  discard block
 block discarded – undo
219 219
 		$reg_count = 0;
220 220
 		$no_payment_required = true;
221 221
 		// loop thru registrations to gather info
222
-		$registrations = $this->checkout->transaction->registrations( $this->checkout->reg_cache_where_params );
223
-		foreach ( $registrations as $registration ) {
222
+		$registrations = $this->checkout->transaction->registrations($this->checkout->reg_cache_where_params);
223
+		foreach ($registrations as $registration) {
224 224
 			/** @var $registration EE_Registration */
225 225
 			$reg_count++;
226 226
 			// registrant is NOT Approved
227
-			if ( $registration->status_ID() === EEM_Registration::status_id_not_approved ) {
227
+			if ($registration->status_ID() === EEM_Registration::status_id_not_approved) {
228 228
 				// add event to list of events with pre-approval reg status
229
-				$registrations_requiring_pre_approval[ $registration->ID() ] = $registration;
229
+				$registrations_requiring_pre_approval[$registration->ID()] = $registration;
230 230
 				do_action(
231 231
 					'AHEE__EE_SPCO_Reg_Step_Payment_Options__generate_reg_form__event_requires_pre_approval',
232 232
 					$registration->event(),
@@ -240,10 +240,10 @@  discard block
 block discarded – undo
240 240
 				// anything other than Approved
241 241
 				&& $registration->status_ID() !== EEM_Registration::status_id_approved
242 242
 				// event hasn't sold out since initial visit
243
-				&& $registration->event()->is_sold_out( true )
243
+				&& $registration->event()->is_sold_out(true)
244 244
 			) {
245 245
 				// add event to list of events that are sold out
246
-				$sold_out_events[ $registration->event()->ID() ] = $registration->event();
246
+				$sold_out_events[$registration->event()->ID()] = $registration->event();
247 247
 				do_action(
248 248
 					'AHEE__EE_SPCO_Reg_Step_Payment_Options__generate_reg_form__sold_out_event',
249 249
 					$registration->event(),
@@ -252,29 +252,29 @@  discard block
 block discarded – undo
252 252
 				continue;
253 253
 			}
254 254
 			// are they allowed to pay now and is there monies owing?
255
-			if ( $registration->owes_monies_and_can_pay() ) {
256
-				$registrations_requiring_payment[ $registration->ID() ] = $registration;
255
+			if ($registration->owes_monies_and_can_pay()) {
256
+				$registrations_requiring_payment[$registration->ID()] = $registration;
257 257
 				do_action(
258 258
 					'AHEE__EE_SPCO_Reg_Step_Payment_Options__generate_reg_form__event_requires_payment',
259 259
 					$registration->event(),
260 260
 					$this
261 261
 				);
262
-			} else if ( ! $this->checkout->revisit && $registration->status_ID() != EEM_Registration::status_id_not_approved && $registration->ticket()->is_free()  ) {
263
-				$registrations_for_free_events[ $registration->event()->ID() ] = $registration;
262
+			} else if ( ! $this->checkout->revisit && $registration->status_ID() != EEM_Registration::status_id_not_approved && $registration->ticket()->is_free()) {
263
+				$registrations_for_free_events[$registration->event()->ID()] = $registration;
264 264
 			}
265 265
 		}
266 266
 		$subsections = array();
267 267
 		// now decide which template to load
268
-		if ( ! empty( $sold_out_events )) {
269
-			$subsections['sold_out_events'] = $this->_sold_out_events( $sold_out_events );
268
+		if ( ! empty($sold_out_events)) {
269
+			$subsections['sold_out_events'] = $this->_sold_out_events($sold_out_events);
270 270
 		}
271
-		if ( ! empty( $registrations_requiring_pre_approval )) {
272
-			$subsections['registrations_requiring_pre_approval'] = $this->_registrations_requiring_pre_approval( $registrations_requiring_pre_approval );
271
+		if ( ! empty($registrations_requiring_pre_approval)) {
272
+			$subsections['registrations_requiring_pre_approval'] = $this->_registrations_requiring_pre_approval($registrations_requiring_pre_approval);
273 273
 		}
274
-		if ( ! empty( $registrations_for_free_events ) ) {
275
-			$subsections[ 'no_payment_required' ] = $this->_no_payment_required( $registrations_for_free_events );
274
+		if ( ! empty($registrations_for_free_events)) {
275
+			$subsections['no_payment_required'] = $this->_no_payment_required($registrations_for_free_events);
276 276
 		}
277
-		if ( ! empty( $registrations_requiring_payment ) ) {
277
+		if ( ! empty($registrations_requiring_payment)) {
278 278
 			// autoload Line_Item_Display classes
279 279
 			EEH_Autoloader::register_line_item_filter_autoloaders();
280 280
 			$line_item_filter_processor = new EE_Line_Item_Filter_Processor(
@@ -285,17 +285,17 @@  discard block
 block discarded – undo
285 285
 				$this->checkout->cart->get_grand_total()
286 286
 			);
287 287
 			$filtered_line_item_tree = $line_item_filter_processor->process();
288
-			if ( $this->checkout->amount_owing > 0 ) {
288
+			if ($this->checkout->amount_owing > 0) {
289 289
 				EEH_Autoloader::register_line_item_display_autoloaders();
290
-				$this->set_line_item_display( new EE_Line_Item_Display( 'spco' ) );
291
-				$subsections[ 'payment_options' ] = $this->_display_payment_options(
290
+				$this->set_line_item_display(new EE_Line_Item_Display('spco'));
291
+				$subsections['payment_options'] = $this->_display_payment_options(
292 292
 					$this->line_item_display->display_line_item(
293 293
 						$filtered_line_item_tree,
294
-						array( 'registrations' => $registrations )
294
+						array('registrations' => $registrations)
295 295
 					)
296 296
 				);
297 297
 				$this->checkout->amount_owing = $filtered_line_item_tree->total();
298
-				$this->_apply_registration_payments_to_amount_owing( $registrations );
298
+				$this->_apply_registration_payments_to_amount_owing($registrations);
299 299
 			}
300 300
 			$no_payment_required = false;
301 301
 		} else {
@@ -304,7 +304,7 @@  discard block
 block discarded – undo
304 304
 		$this->_save_selected_method_of_payment();
305 305
 
306 306
 		$subsections['default_hidden_inputs'] = $this->reg_step_hidden_inputs();
307
-		$subsections['extra_hidden_inputs' ] = $this->_extra_hidden_inputs( $no_payment_required );
307
+		$subsections['extra_hidden_inputs'] = $this->_extra_hidden_inputs($no_payment_required);
308 308
 
309 309
 		return new EE_Form_Section_Proper(
310 310
 			array(
@@ -332,21 +332,21 @@  discard block
 block discarded – undo
332 332
 	 * @param \EE_Line_Item_Filter_Collection $line_item_filter_collection
333 333
 	 * @return \EE_Line_Item_Filter_Collection
334 334
 	 */
335
-	public static function add_spco_line_item_filters( EE_Line_Item_Filter_Collection $line_item_filter_collection ) {
336
-		if ( ! EE_Registry::instance()->SSN instanceof EE_Session ) {
335
+	public static function add_spco_line_item_filters(EE_Line_Item_Filter_Collection $line_item_filter_collection) {
336
+		if ( ! EE_Registry::instance()->SSN instanceof EE_Session) {
337 337
 			return $line_item_filter_collection;
338 338
 		}
339
-		if ( ! EE_Registry::instance()->SSN->checkout() instanceof EE_Checkout ) {
339
+		if ( ! EE_Registry::instance()->SSN->checkout() instanceof EE_Checkout) {
340 340
 			return $line_item_filter_collection;
341 341
 		}
342
-		if ( ! EE_Registry::instance()->SSN->checkout()->transaction instanceof EE_Transaction ) {
342
+		if ( ! EE_Registry::instance()->SSN->checkout()->transaction instanceof EE_Transaction) {
343 343
 			return $line_item_filter_collection;
344 344
 		}
345 345
 		$registrations = EE_Registry::instance()->SSN->checkout()->transaction->registrations(
346 346
 			EE_Registry::instance()->SSN->checkout()->reg_cache_where_params
347 347
 		);
348
-		$line_item_filter_collection->add( new EE_Billable_Line_Item_Filter( $registrations ) );
349
-		$line_item_filter_collection->add( new EE_Non_Zero_Line_Item_Filter() );
348
+		$line_item_filter_collection->add(new EE_Billable_Line_Item_Filter($registrations));
349
+		$line_item_filter_collection->add(new EE_Non_Zero_Line_Item_Filter());
350 350
 		return $line_item_filter_collection;
351 351
 	}
352 352
 
@@ -360,8 +360,8 @@  discard block
 block discarded – undo
360 360
 	 * @return void
361 361
 	 */
362 362
 	protected function _hide_reg_step_submit_button_if_revisit() {
363
-		if ( $this->checkout->revisit ) {
364
-			add_filter( 'FHEE__EE_SPCO_Reg_Step__reg_step_submit_button__sbmt_btn_html', '__return_empty_string' );
363
+		if ($this->checkout->revisit) {
364
+			add_filter('FHEE__EE_SPCO_Reg_Step__reg_step_submit_button__sbmt_btn_html', '__return_empty_string');
365 365
 		}
366 366
 	}
367 367
 
@@ -372,18 +372,18 @@  discard block
 block discarded – undo
372 372
 	 * @param \EE_Event[] $sold_out_events_array
373 373
 	 * @return \EE_Form_Section_Proper
374 374
 	 */
375
-	private function _sold_out_events( $sold_out_events_array = array() ) {
375
+	private function _sold_out_events($sold_out_events_array = array()) {
376 376
 		// set some defaults
377 377
 		$this->checkout->selected_method_of_payment = 'events_sold_out';
378 378
 		$sold_out_events = '';
379
-		foreach ( $sold_out_events_array as $sold_out_event ) {
380
-			$sold_out_events .= EEH_HTML::li( EEH_HTML::span( $sold_out_event->name(), '', 'dashicons dashicons-marker ee-icon-size-16 pink-text' ));
379
+		foreach ($sold_out_events_array as $sold_out_event) {
380
+			$sold_out_events .= EEH_HTML::li(EEH_HTML::span($sold_out_event->name(), '', 'dashicons dashicons-marker ee-icon-size-16 pink-text'));
381 381
 		}
382 382
 		return new EE_Form_Section_Proper(
383 383
 			array(
384 384
 				'layout_strategy'		=> new EE_Template_Layout(
385 385
 					array(
386
-						'layout_template_file' 	=> SPCO_REG_STEPS_PATH . $this->_slug . DS . 'sold_out_events.template.php', // layout_template
386
+						'layout_template_file' 	=> SPCO_REG_STEPS_PATH.$this->_slug.DS.'sold_out_events.template.php', // layout_template
387 387
 						'template_args'  				=> apply_filters(
388 388
 							'FHEE__EE_SPCO_Reg_Step_Payment_Options___sold_out_events__template_args',
389 389
 							array(
@@ -391,7 +391,7 @@  discard block
 block discarded – undo
391 391
 								'sold_out_events_msg' 	=> apply_filters(
392 392
 									'FHEE__EE_SPCO_Reg_Step_Payment_Options___sold_out_events__sold_out_events_msg',
393 393
 									sprintf(
394
-										__( 'It appears that the event you were about to make a payment for has sold out since you first registered. If you have already made a partial payment towards this event, please contact the event administrator for a refund.%3$s%3$s%1$sPlease note that availability can change at any time due to cancellations, so please check back again later if registration for this event(s) is important to you.%2$s', 'event_espresso' ),
394
+										__('It appears that the event you were about to make a payment for has sold out since you first registered. If you have already made a partial payment towards this event, please contact the event administrator for a refund.%3$s%3$s%1$sPlease note that availability can change at any time due to cancellations, so please check back again later if registration for this event(s) is important to you.%2$s', 'event_espresso'),
395 395
 										'<strong>',
396 396
 										'</strong>',
397 397
 										'<br />'
@@ -412,14 +412,14 @@  discard block
 block discarded – undo
412 412
 	 * @param array $registrations_requiring_pre_approval
413 413
 	 * @return \EE_Form_Section_Proper
414 414
 	 */
415
-	private function _registrations_requiring_pre_approval( $registrations_requiring_pre_approval = array()) {
415
+	private function _registrations_requiring_pre_approval($registrations_requiring_pre_approval = array()) {
416 416
 		$events_requiring_pre_approval = '';
417
-		foreach ( $registrations_requiring_pre_approval as $registration ) {
418
-			if ( $registration instanceof EE_Registration && $registration->event() instanceof EE_Event ) {
419
-				$events_requiring_pre_approval[ $registration->event()->ID() ] = EEH_HTML::li(
420
-					EEH_HTML::span( '', '', 'dashicons dashicons-marker ee-icon-size-16 orange-text'
417
+		foreach ($registrations_requiring_pre_approval as $registration) {
418
+			if ($registration instanceof EE_Registration && $registration->event() instanceof EE_Event) {
419
+				$events_requiring_pre_approval[$registration->event()->ID()] = EEH_HTML::li(
420
+					EEH_HTML::span('', '', 'dashicons dashicons-marker ee-icon-size-16 orange-text'
421 421
 					)
422
-					. EEH_HTML::span( $registration->event()->name(), '', 'orange-text' )
422
+					. EEH_HTML::span($registration->event()->name(), '', 'orange-text')
423 423
 				);
424 424
 			}
425 425
 		}
@@ -427,14 +427,14 @@  discard block
 block discarded – undo
427 427
 			array(
428 428
 				'layout_strategy'		=> new EE_Template_Layout(
429 429
 					array(
430
-						'layout_template_file' 	=> SPCO_REG_STEPS_PATH . $this->_slug . DS . 'events_requiring_pre_approval.template.php', // layout_template
430
+						'layout_template_file' 	=> SPCO_REG_STEPS_PATH.$this->_slug.DS.'events_requiring_pre_approval.template.php', // layout_template
431 431
 						'template_args'  				=> apply_filters(
432 432
 							'FHEE__EE_SPCO_Reg_Step_Payment_Options___sold_out_events__template_args',
433 433
 							array(
434
-								'events_requiring_pre_approval' 			=> implode( '', $events_requiring_pre_approval ),
434
+								'events_requiring_pre_approval' 			=> implode('', $events_requiring_pre_approval),
435 435
 								'events_requiring_pre_approval_msg' 	=> apply_filters(
436 436
 									'FHEE__EE_SPCO_Reg_Step_Payment_Options___events_requiring_pre_approval__events_requiring_pre_approval_msg',
437
-									__( 'The following events do not require payment at this time and will not be billed during this transaction. Billing will only occur after the attendee has been approved by the event organizer. You will be notified when your registration has been processed. If this is a free event, then no billing will occur.', 'event_espresso' )
437
+									__('The following events do not require payment at this time and will not be billed during this transaction. Billing will only occur after the attendee has been approved by the event organizer. You will be notified when your registration has been processed. If this is a free event, then no billing will occur.', 'event_espresso')
438 438
 								)
439 439
 							)
440 440
 						),
@@ -452,7 +452,7 @@  discard block
 block discarded – undo
452 452
 	 * @param \EE_Event[] $registrations_for_free_events
453 453
 	 * @return \EE_Form_Section_Proper
454 454
 	 */
455
-	private function _no_payment_required( $registrations_for_free_events = array() ) {
455
+	private function _no_payment_required($registrations_for_free_events = array()) {
456 456
 		// set some defaults
457 457
 		$this->checkout->selected_method_of_payment = 'no_payment_required';
458 458
 		// generate no_payment_required form
@@ -460,7 +460,7 @@  discard block
 block discarded – undo
460 460
 			array(
461 461
 				'layout_strategy' 	=> new EE_Template_Layout(
462 462
 					array(
463
-						'layout_template_file' 	=> SPCO_REG_STEPS_PATH . $this->_slug . DS . 'no_payment_required.template.php', // layout_template
463
+						'layout_template_file' 	=> SPCO_REG_STEPS_PATH.$this->_slug.DS.'no_payment_required.template.php', // layout_template
464 464
 						'template_args'  				=> apply_filters(
465 465
 							'FHEE__EE_SPCO_Reg_Step_Payment_Options___no_payment_required__template_args',
466 466
 							array(
@@ -468,7 +468,7 @@  discard block
 block discarded – undo
468 468
 								'registrations' => array(),
469 469
 								'ticket_count' 	=> array(),
470 470
 								'registrations_for_free_events' 	=> $registrations_for_free_events,
471
-								'no_payment_required_msg' => EEH_HTML::p( __( 'This is a free event, so no billing will occur.', 'event_espresso' ))
471
+								'no_payment_required_msg' => EEH_HTML::p(__('This is a free event, so no billing will occur.', 'event_espresso'))
472 472
 							)
473 473
 						),
474 474
 					)
@@ -485,7 +485,7 @@  discard block
 block discarded – undo
485 485
 	 * @param string $transaction_details
486 486
 	 * @return \EE_Form_Section_Proper
487 487
 	 */
488
-	private function _display_payment_options( $transaction_details = '' ) {
488
+	private function _display_payment_options($transaction_details = '') {
489 489
 		// has method_of_payment been set by no-js user?
490 490
 		$this->checkout->selected_method_of_payment = $this->_get_selected_method_of_payment();
491 491
 		// build payment options form
@@ -497,18 +497,18 @@  discard block
 block discarded – undo
497 497
 						'before_payment_options' => apply_filters(
498 498
 							'FHEE__EE_SPCO_Reg_Step_Payment_Options___display_payment_options__before_payment_options',
499 499
 							new EE_Form_Section_Proper(
500
-								array( 'layout_strategy'	=> new EE_Div_Per_Section_Layout() )
500
+								array('layout_strategy'	=> new EE_Div_Per_Section_Layout())
501 501
 							)
502 502
 						),
503 503
 						'payment_options' => $this->_setup_payment_options(),
504 504
 						'after_payment_options' => apply_filters(
505 505
 							'FHEE__EE_SPCO_Reg_Step_Payment_Options___display_payment_options__after_payment_options',
506 506
 							new EE_Form_Section_Proper(
507
-								array( 'layout_strategy'	=> new EE_Div_Per_Section_Layout() )
507
+								array('layout_strategy'	=> new EE_Div_Per_Section_Layout())
508 508
 							)
509 509
 						),
510 510
 					),
511
-					'layout_strategy'	=> new EE_Template_Layout( array(
511
+					'layout_strategy'	=> new EE_Template_Layout(array(
512 512
 							'layout_template_file' 	=> $this->_template,
513 513
 							'template_args'  				=> apply_filters(
514 514
 								'FHEE__EE_SPCO_Reg_Step_Payment_Options___display_payment_options__template_args',
@@ -532,11 +532,11 @@  discard block
 block discarded – undo
532 532
 	 * @param bool $no_payment_required
533 533
 	 * @return \EE_Form_Section_Proper
534 534
 	 */
535
-	private function _extra_hidden_inputs( $no_payment_required = TRUE ) {
535
+	private function _extra_hidden_inputs($no_payment_required = TRUE) {
536 536
 
537 537
 		return new EE_Form_Section_Proper(
538 538
 			array(
539
-				'html_id' 				=> 'ee-' . $this->slug() . '-extra-hidden-inputs',
539
+				'html_id' 				=> 'ee-'.$this->slug().'-extra-hidden-inputs',
540 540
 				'layout_strategy'	=> new EE_Div_Per_Section_Layout(),
541 541
 				'subsections' 		=> array(
542 542
 					'spco_no_payment_required' => new EE_Hidden_Input(
@@ -569,16 +569,16 @@  discard block
 block discarded – undo
569 569
 	 * @access    protected
570 570
 	 * @return    void
571 571
 	 */
572
-	protected function _apply_registration_payments_to_amount_owing( $registrations ) {
572
+	protected function _apply_registration_payments_to_amount_owing($registrations) {
573 573
 		$payments = array();
574
-		foreach ( $registrations as $registration ) {
575
-			if ( $registration instanceof EE_Registration && $registration->owes_monies_and_can_pay() ) {
574
+		foreach ($registrations as $registration) {
575
+			if ($registration instanceof EE_Registration && $registration->owes_monies_and_can_pay()) {
576 576
 				$payments = $payments + $registration->registration_payments();
577 577
 			}
578 578
 		}
579
-		if ( ! empty( $payments ) ) {
580
-			foreach ( $payments as $payment ) {
581
-				if ( $payment instanceof EE_Registration_Payment ) {
579
+		if ( ! empty($payments)) {
580
+			foreach ($payments as $payment) {
581
+				if ($payment instanceof EE_Registration_Payment) {
582 582
 					$this->checkout->amount_owing -= $payment->amount();
583 583
 				}
584 584
 			}
@@ -593,9 +593,9 @@  discard block
 block discarded – undo
593 593
 	 * @param 	bool $force_reset
594 594
 	 * @return 	void
595 595
 	 */
596
-	private function _reset_selected_method_of_payment( $force_reset = FALSE ) {
597
-		$reset_payment_method = $force_reset ? TRUE : sanitize_text_field( EE_Registry::instance()->REQ->get( 'reset_payment_method', FALSE ));
598
-		if ( $reset_payment_method ) {
596
+	private function _reset_selected_method_of_payment($force_reset = FALSE) {
597
+		$reset_payment_method = $force_reset ? TRUE : sanitize_text_field(EE_Registry::instance()->REQ->get('reset_payment_method', FALSE));
598
+		if ($reset_payment_method) {
599 599
 			$this->checkout->selected_method_of_payment = NULL;
600 600
 			$this->checkout->payment_method = NULL;
601 601
 			$this->checkout->billing_form = NULL;
@@ -614,9 +614,9 @@  discard block
 block discarded – undo
614 614
 	 * @param string $selected_method_of_payment
615 615
 	 * 	@return 		EE_Billing_Info_Form
616 616
 	 */
617
-	private function _save_selected_method_of_payment( $selected_method_of_payment = '' ) {
618
-		$selected_method_of_payment = ! empty( $selected_method_of_payment ) ? $selected_method_of_payment : $this->checkout->selected_method_of_payment;
619
-		EE_Registry::instance()->SSN->set_session_data( array( 'selected_method_of_payment' => $selected_method_of_payment ));
617
+	private function _save_selected_method_of_payment($selected_method_of_payment = '') {
618
+		$selected_method_of_payment = ! empty($selected_method_of_payment) ? $selected_method_of_payment : $this->checkout->selected_method_of_payment;
619
+		EE_Registry::instance()->SSN->set_session_data(array('selected_method_of_payment' => $selected_method_of_payment));
620 620
 	}
621 621
 
622 622
 
@@ -629,40 +629,40 @@  discard block
 block discarded – undo
629 629
 		// load payment method classes
630 630
 		$this->checkout->available_payment_methods = $this->_get_available_payment_methods();
631 631
 		// switch up header depending on number of available payment methods
632
-		$payment_method_header = count( $this->checkout->available_payment_methods ) > 1
633
-			? apply_filters( 'FHEE__registration_page_payment_options__method_of_payment_hdr', __( 'Please Select Your Method of Payment', 'event_espresso' ))
634
-			: apply_filters( 'FHEE__registration_page_payment_options__method_of_payment_hdr', __( 'Method of Payment', 'event_espresso' ));
632
+		$payment_method_header = count($this->checkout->available_payment_methods) > 1
633
+			? apply_filters('FHEE__registration_page_payment_options__method_of_payment_hdr', __('Please Select Your Method of Payment', 'event_espresso'))
634
+			: apply_filters('FHEE__registration_page_payment_options__method_of_payment_hdr', __('Method of Payment', 'event_espresso'));
635 635
 		$available_payment_methods = array(
636 636
 			// display the "Payment Method" header
637 637
 			'payment_method_header' => new EE_Form_Section_HTML(
638
-				EEH_HTML::h4 ( $payment_method_header, 'method-of-payment-hdr' )
638
+				EEH_HTML::h4($payment_method_header, 'method-of-payment-hdr')
639 639
 			)
640 640
 		);
641 641
 		// the list of actual payment methods ( invoice, paypal, etc ) in a  ( slug => HTML )  format
642 642
 		$available_payment_method_options = array();
643 643
 		$default_payment_method_option = array();
644 644
 		// additional instructions to be displayed and hidden below payment methods (adding a clearing div to start)
645
-		$payment_methods_billing_info = array( new EE_Form_Section_HTML( EEH_HTML::div ( '<br />', '', '', 'clear:both;' )));
645
+		$payment_methods_billing_info = array(new EE_Form_Section_HTML(EEH_HTML::div('<br />', '', '', 'clear:both;')));
646 646
 		// loop through payment methods
647
-		foreach( $this->checkout->available_payment_methods as $payment_method ) {
648
-			if ( $payment_method instanceof EE_Payment_Method ) {
649
-				$payment_method_button = EEH_HTML::img( $payment_method->button_url(), $payment_method->name(), 'spco-payment-method-' . $payment_method->slug() . '-btn-img', 'spco-payment-method-btn-img' );
647
+		foreach ($this->checkout->available_payment_methods as $payment_method) {
648
+			if ($payment_method instanceof EE_Payment_Method) {
649
+				$payment_method_button = EEH_HTML::img($payment_method->button_url(), $payment_method->name(), 'spco-payment-method-'.$payment_method->slug().'-btn-img', 'spco-payment-method-btn-img');
650 650
 				// check if any payment methods are set as default
651 651
 				// if payment method is already selected OR nothing is selected and this payment method should be open_by_default
652
-				if (( $this->checkout->selected_method_of_payment == $payment_method->slug() ) || ( ! $this->checkout->selected_method_of_payment && $payment_method->open_by_default() )) {
652
+				if (($this->checkout->selected_method_of_payment == $payment_method->slug()) || ( ! $this->checkout->selected_method_of_payment && $payment_method->open_by_default())) {
653 653
 					$this->checkout->selected_method_of_payment = $payment_method->slug();
654 654
 					$this->_save_selected_method_of_payment();
655
-					$default_payment_method_option[ $payment_method->slug() ] =  $payment_method_button;
655
+					$default_payment_method_option[$payment_method->slug()] = $payment_method_button;
656 656
 				} else {
657
-					$available_payment_method_options[ $payment_method->slug() ] =  $payment_method_button;
657
+					$available_payment_method_options[$payment_method->slug()] = $payment_method_button;
658 658
 				}
659
-				$payment_methods_billing_info[ $payment_method->slug() . '-info' ] = $this->_payment_method_billing_info( $payment_method );
659
+				$payment_methods_billing_info[$payment_method->slug().'-info'] = $this->_payment_method_billing_info($payment_method);
660 660
 			}
661 661
 		}
662 662
 		// prepend available_payment_method_options with default_payment_method_option so that it appears first in list of PMs
663 663
 		$available_payment_method_options = $default_payment_method_option + $available_payment_method_options;
664 664
 		// now generate the actual form  inputs
665
-		$available_payment_methods['available_payment_methods'] = $this->_available_payment_method_inputs( $available_payment_method_options );
665
+		$available_payment_methods['available_payment_methods'] = $this->_available_payment_method_inputs($available_payment_method_options);
666 666
 		$available_payment_methods = $available_payment_methods + $payment_methods_billing_info;
667 667
 
668 668
 		// build the available payment methods form
@@ -682,19 +682,19 @@  discard block
 block discarded – undo
682 682
 	 * @return EE_Payment_Method[]
683 683
 	 */
684 684
 	protected function _get_available_payment_methods() {
685
-		if ( ! empty( $this->checkout->available_payment_methods )) {
685
+		if ( ! empty($this->checkout->available_payment_methods)) {
686 686
 			return $this->checkout->available_payment_methods;
687 687
 		}
688 688
 		$available_payment_methods = array();
689 689
 		// load EEM_Payment_Method
690
-		EE_Registry::instance()->load_model( 'Payment_Method' );
690
+		EE_Registry::instance()->load_model('Payment_Method');
691 691
 		/** @type EEM_Payment_Method $EEM_Payment_Method */
692 692
 		$EEM_Payment_Method = EE_Registry::instance()->LIB->EEM_Payment_Method;
693 693
 		// get all active payment methods
694
-		$payment_methods = $EEM_Payment_Method->get_all_for_transaction( $this->checkout->transaction, EEM_Payment_Method::scope_cart );
695
-		foreach ( $payment_methods as $payment_method ) {
696
-			if ( $payment_method instanceof EE_Payment_Method ) {
697
-				$available_payment_methods[ $payment_method->slug() ] = $payment_method;
694
+		$payment_methods = $EEM_Payment_Method->get_all_for_transaction($this->checkout->transaction, EEM_Payment_Method::scope_cart);
695
+		foreach ($payment_methods as $payment_method) {
696
+			if ($payment_method instanceof EE_Payment_Method) {
697
+				$available_payment_methods[$payment_method->slug()] = $payment_method;
698 698
 			}
699 699
 		}
700 700
 		return $available_payment_methods;
@@ -710,14 +710,14 @@  discard block
 block discarded – undo
710 710
 	 * @param 	array $available_payment_method_options
711 711
 	 * @return 	\EE_Form_Section_Proper
712 712
 	 */
713
-	private function _available_payment_method_inputs( $available_payment_method_options = array() ) {
713
+	private function _available_payment_method_inputs($available_payment_method_options = array()) {
714 714
 		// generate inputs
715 715
 		return new EE_Form_Section_Proper(
716 716
 			array(
717 717
 				'html_id' 				=> 'ee-available-payment-method-inputs',
718 718
 				'layout_strategy'	=> new EE_Div_Per_Section_Layout(),
719 719
 				'subsections' 		=> array(
720
-					'' => new EE_Radio_Button_Input (
720
+					'' => new EE_Radio_Button_Input(
721 721
 						$available_payment_method_options,
722 722
 						array(
723 723
 							'html_name' 				=> 'selected_method_of_payment',
@@ -741,36 +741,36 @@  discard block
 block discarded – undo
741 741
 	 * @param 	EE_Payment_Method $payment_method
742 742
 	 * @return 	\EE_Form_Section_Proper
743 743
 	 */
744
-	private function _payment_method_billing_info( EE_Payment_Method $payment_method ) {
744
+	private function _payment_method_billing_info(EE_Payment_Method $payment_method) {
745 745
 		$currently_selected = $this->checkout->selected_method_of_payment == $payment_method->slug() ? TRUE : FALSE;
746 746
 		// generate the billing form for payment method
747
-		$billing_form = $currently_selected ? $this->_get_billing_form_for_payment_method( $payment_method ) : new EE_Form_Section_HTML();
747
+		$billing_form = $currently_selected ? $this->_get_billing_form_for_payment_method($payment_method) : new EE_Form_Section_HTML();
748 748
 		$this->checkout->billing_form = $currently_selected ? $billing_form : $this->checkout->billing_form;
749 749
 		// it's all in the details
750
-		$info_html = EEH_HTML::h3 ( __( 'Important information regarding your payment', 'event_espresso' ), '', 'spco-payment-method-hdr' );
750
+		$info_html = EEH_HTML::h3(__('Important information regarding your payment', 'event_espresso'), '', 'spco-payment-method-hdr');
751 751
 		// add some info regarding the step, either from what's saved in the admin, or a default string depending on whether the PM has a billing form or not
752
-		if ( $payment_method->description() ) {
752
+		if ($payment_method->description()) {
753 753
 			$payment_method_info = $payment_method->description();
754
-		} elseif ( $billing_form instanceof EE_Billing_Info_Form ) {
755
-			$payment_method_info = sprintf( __( 'Please provide the following billing information, then click the "%1$s" button below in order to proceed.', 'event_espresso' ), $this->submit_button_text() );
754
+		} elseif ($billing_form instanceof EE_Billing_Info_Form) {
755
+			$payment_method_info = sprintf(__('Please provide the following billing information, then click the "%1$s" button below in order to proceed.', 'event_espresso'), $this->submit_button_text());
756 756
 		} else {
757
-			$payment_method_info = sprintf( __( 'Please click the "%1$s" button below in order to proceed.', 'event_espresso' ), $this->submit_button_text() );
757
+			$payment_method_info = sprintf(__('Please click the "%1$s" button below in order to proceed.', 'event_espresso'), $this->submit_button_text());
758 758
 		}
759
-		$info_html .= EEH_HTML::p (
760
-			apply_filters( 'FHEE__EE_SPCO_Reg_Step_Payment_Options___payment_method_billing_info__payment_method_info', $payment_method_info ),
759
+		$info_html .= EEH_HTML::p(
760
+			apply_filters('FHEE__EE_SPCO_Reg_Step_Payment_Options___payment_method_billing_info__payment_method_info', $payment_method_info),
761 761
 			'',
762 762
 			'spco-payment-method-desc ee-attention'
763 763
 		);
764 764
 
765 765
 		return new EE_Form_Section_Proper(
766 766
 			array(
767
-				'html_id' 					=> 'spco-payment-method-info-' . $payment_method->slug(),
767
+				'html_id' 					=> 'spco-payment-method-info-'.$payment_method->slug(),
768 768
 				'html_class' 			=> 'spco-payment-method-info-dv',
769 769
 				// only display the selected or default PM
770 770
 				'html_style' 			=> $currently_selected ? '' : 'display:none;',
771 771
 				'layout_strategy'		=> new EE_Div_Per_Section_Layout(),
772 772
 				'subsections' 			=> array(
773
-					'info' 					=> new EE_Form_Section_HTML( $info_html ),
773
+					'info' 					=> new EE_Form_Section_HTML($info_html),
774 774
 					'billing_form' 		=> $currently_selected ? $billing_form : new EE_Form_Section_HTML()
775 775
 				)
776 776
 			)
@@ -788,12 +788,12 @@  discard block
 block discarded – undo
788 788
 	 */
789 789
 	public function get_billing_form_html_for_payment_method() {
790 790
 		// how have they chosen to pay?
791
-		$this->checkout->selected_method_of_payment = $this->_get_selected_method_of_payment( TRUE );
791
+		$this->checkout->selected_method_of_payment = $this->_get_selected_method_of_payment(TRUE);
792 792
 		$this->checkout->payment_method = $this->_get_payment_method_for_selected_method_of_payment();
793
-		if ( ! $this->checkout->payment_method instanceof EE_Payment_Method ) {
793
+		if ( ! $this->checkout->payment_method instanceof EE_Payment_Method) {
794 794
 			return FALSE;
795 795
 		}
796
-		if ( apply_filters( 'FHEE__EE_SPCO_Reg_Step_Payment_Options__registration_checkout__selected_payment_method__display_success', false ) ) {
796
+		if (apply_filters('FHEE__EE_SPCO_Reg_Step_Payment_Options__registration_checkout__selected_payment_method__display_success', false)) {
797 797
             EE_Error::add_success(
798 798
                 apply_filters(
799 799
                     'FHEE__Single_Page_Checkout__registration_checkout__selected_payment_method',
@@ -802,20 +802,20 @@  discard block
 block discarded – undo
802 802
             );
803 803
         }
804 804
 		// now generate billing form for selected method of payment
805
-		$payment_method_billing_form = $this->_get_billing_form_for_payment_method( $this->checkout->payment_method );
805
+		$payment_method_billing_form = $this->_get_billing_form_for_payment_method($this->checkout->payment_method);
806 806
 		// fill form with attendee info if applicable
807
-		if ( $payment_method_billing_form instanceof EE_Billing_Attendee_Info_Form && $this->checkout->transaction_has_primary_registrant() ) {
808
-			$payment_method_billing_form->populate_from_attendee( $this->checkout->transaction->primary_registration()->attendee() );
807
+		if ($payment_method_billing_form instanceof EE_Billing_Attendee_Info_Form && $this->checkout->transaction_has_primary_registrant()) {
808
+			$payment_method_billing_form->populate_from_attendee($this->checkout->transaction->primary_registration()->attendee());
809 809
 		}
810 810
 		// and debug content
811
-		if ( $payment_method_billing_form instanceof EE_Billing_Info_Form && $this->checkout->payment_method->type_obj() instanceof EE_PMT_Base ) {
812
-			$payment_method_billing_form = $this->checkout->payment_method->type_obj()->apply_billing_form_debug_settings( $payment_method_billing_form );
811
+		if ($payment_method_billing_form instanceof EE_Billing_Info_Form && $this->checkout->payment_method->type_obj() instanceof EE_PMT_Base) {
812
+			$payment_method_billing_form = $this->checkout->payment_method->type_obj()->apply_billing_form_debug_settings($payment_method_billing_form);
813 813
 		}
814 814
 		$billing_info = $payment_method_billing_form instanceof EE_Form_Section_Proper ? $payment_method_billing_form->get_html() : '';
815
-		$this->checkout->json_response->set_return_data( array( 'payment_method_info' => $billing_info ));
815
+		$this->checkout->json_response->set_return_data(array('payment_method_info' => $billing_info));
816 816
 		// localize validation rules for main form
817 817
 		$this->checkout->current_step->reg_form->localize_validation_rules();
818
-		$this->checkout->json_response->add_validation_rules( EE_Form_Section_Proper::js_localization() );
818
+		$this->checkout->json_response->add_validation_rules(EE_Form_Section_Proper::js_localization());
819 819
 		return TRUE;
820 820
 	}
821 821
 
@@ -828,15 +828,15 @@  discard block
 block discarded – undo
828 828
 	 * @param EE_Payment_Method $payment_method
829 829
 	 * @return \EE_Billing_Info_Form
830 830
 	 */
831
-	private function _get_billing_form_for_payment_method( EE_Payment_Method $payment_method ) {
832
-		$billing_form = $payment_method->type_obj()->billing_form( $this->checkout->transaction, array( 'amount_owing' => $this->checkout->amount_owing ) );
833
-		if ( $billing_form instanceof EE_Billing_Info_Form ) {
834
-			if ( EE_Registry::instance()->REQ->is_set( 'payment_method' )) {
835
-                if ( apply_filters('FHEE__EE_SPCO_Reg_Step_Payment_Options__registration_checkout__selected_payment_method__display_success', false )) {
831
+	private function _get_billing_form_for_payment_method(EE_Payment_Method $payment_method) {
832
+		$billing_form = $payment_method->type_obj()->billing_form($this->checkout->transaction, array('amount_owing' => $this->checkout->amount_owing));
833
+		if ($billing_form instanceof EE_Billing_Info_Form) {
834
+			if (EE_Registry::instance()->REQ->is_set('payment_method')) {
835
+                if (apply_filters('FHEE__EE_SPCO_Reg_Step_Payment_Options__registration_checkout__selected_payment_method__display_success', false)) {
836 836
                     EE_Error::add_success(
837 837
                         apply_filters(
838 838
                             'FHEE__Single_Page_Checkout__registration_checkout__selected_payment_method',
839
-                            sprintf( __( 'You have selected "%s" as your method of payment. Please note the important payment information below.', 'event_espresso' ), $payment_method->name() )
839
+                            sprintf(__('You have selected "%s" as your method of payment. Please note the important payment information below.', 'event_espresso'), $payment_method->name())
840 840
                         )
841 841
                     );
842 842
                 }
@@ -861,27 +861,27 @@  discard block
 block discarded – undo
861 861
 	 * @param string 		$request_param
862 862
 	 * @return NULL|string
863 863
 	 */
864
-	private function _get_selected_method_of_payment( $required = FALSE, $request_param = 'selected_method_of_payment' ) {
864
+	private function _get_selected_method_of_payment($required = FALSE, $request_param = 'selected_method_of_payment') {
865 865
 		// is selected_method_of_payment set in the request ?
866
-		$selected_method_of_payment = EE_Registry::instance()->REQ->get( $request_param, FALSE );
867
-		if ( $selected_method_of_payment ) {
866
+		$selected_method_of_payment = EE_Registry::instance()->REQ->get($request_param, FALSE);
867
+		if ($selected_method_of_payment) {
868 868
 			// sanitize it
869
-			$selected_method_of_payment = is_array( $selected_method_of_payment ) ? array_shift( $selected_method_of_payment ) : $selected_method_of_payment;
870
-			$selected_method_of_payment = sanitize_text_field( $selected_method_of_payment );
869
+			$selected_method_of_payment = is_array($selected_method_of_payment) ? array_shift($selected_method_of_payment) : $selected_method_of_payment;
870
+			$selected_method_of_payment = sanitize_text_field($selected_method_of_payment);
871 871
 			// store it in the session so that it's available for all subsequent requests including AJAX
872
-			$this->_save_selected_method_of_payment( $selected_method_of_payment );
872
+			$this->_save_selected_method_of_payment($selected_method_of_payment);
873 873
 		} else {
874 874
 			// or is is set in the session ?
875
-			$selected_method_of_payment = EE_Registry::instance()->SSN->get_session_data( 'selected_method_of_payment' );
875
+			$selected_method_of_payment = EE_Registry::instance()->SSN->get_session_data('selected_method_of_payment');
876 876
 		}
877 877
 		// do ya really really gotta have it?
878
-		if ( empty( $selected_method_of_payment ) && $required ) {
878
+		if (empty($selected_method_of_payment) && $required) {
879 879
 			EE_Error::add_error(
880 880
 				sprintf(
881
-					__( 'The selected method of payment could not be determined.%sPlease ensure that you have selected one before proceeding.%sIf you continue to experience difficulties, then refresh your browser and try again, or contact %s for assistance.', 'event_espresso' ),
881
+					__('The selected method of payment could not be determined.%sPlease ensure that you have selected one before proceeding.%sIf you continue to experience difficulties, then refresh your browser and try again, or contact %s for assistance.', 'event_espresso'),
882 882
 					'<br/>',
883 883
 					'<br/>',
884
-					EE_Registry::instance()->CFG->organization->get_pretty( 'email' )
884
+					EE_Registry::instance()->CFG->organization->get_pretty('email')
885 885
 				),
886 886
 				__FILE__, __FUNCTION__, __LINE__
887 887
 			);
@@ -907,37 +907,37 @@  discard block
 block discarded – undo
907 907
 	 * @return string
908 908
 	 */
909 909
 	public function switch_payment_method() {
910
-		if ( ! $this->_verify_payment_method_is_set() ) {
910
+		if ( ! $this->_verify_payment_method_is_set()) {
911 911
 			return false;
912 912
 		}
913
-		if ( apply_filters( 'FHEE__EE_SPCO_Reg_Step_Payment_Options__registration_checkout__selected_payment_method__display_success', false ) ) {
913
+		if (apply_filters('FHEE__EE_SPCO_Reg_Step_Payment_Options__registration_checkout__selected_payment_method__display_success', false)) {
914 914
 			EE_Error::add_success(
915 915
 				apply_filters(
916 916
 					'FHEE__Single_Page_Checkout__registration_checkout__selected_payment_method',
917
-					sprintf( __( 'You have selected "%s" as your method of payment. Please note the important payment information below.', 'event_espresso' ), $this->checkout->payment_method->name() )
917
+					sprintf(__('You have selected "%s" as your method of payment. Please note the important payment information below.', 'event_espresso'), $this->checkout->payment_method->name())
918 918
 				)
919 919
 			);
920 920
 		}
921 921
 		// generate billing form for selected method of payment if it hasn't been done already
922
-		if ( $this->checkout->payment_method->type_obj()->has_billing_form() ) {
923
-			$this->checkout->billing_form = $this->_get_billing_form_for_payment_method( $this->checkout->payment_method );
922
+		if ($this->checkout->payment_method->type_obj()->has_billing_form()) {
923
+			$this->checkout->billing_form = $this->_get_billing_form_for_payment_method($this->checkout->payment_method);
924 924
 		}
925 925
 		// fill form with attendee info if applicable
926
-		if ( $this->checkout->billing_form instanceof EE_Billing_Attendee_Info_Form && $this->checkout->transaction_has_primary_registrant() ) {
927
-			$this->checkout->billing_form->populate_from_attendee( $this->checkout->transaction->primary_registration()->attendee() );
926
+		if ($this->checkout->billing_form instanceof EE_Billing_Attendee_Info_Form && $this->checkout->transaction_has_primary_registrant()) {
927
+			$this->checkout->billing_form->populate_from_attendee($this->checkout->transaction->primary_registration()->attendee());
928 928
 		}
929 929
 		// and debug content
930
-		if ( $this->checkout->billing_form instanceof EE_Billing_Info_Form && $this->checkout->payment_method->type_obj() instanceof EE_PMT_Base ) {
931
-			$this->checkout->billing_form = $this->checkout->payment_method->type_obj()->apply_billing_form_debug_settings( $this->checkout->billing_form );
930
+		if ($this->checkout->billing_form instanceof EE_Billing_Info_Form && $this->checkout->payment_method->type_obj() instanceof EE_PMT_Base) {
931
+			$this->checkout->billing_form = $this->checkout->payment_method->type_obj()->apply_billing_form_debug_settings($this->checkout->billing_form);
932 932
 		}
933 933
 		// get html and validation rules for form
934
-		if ( $this->checkout->billing_form instanceof EE_Form_Section_Proper ) {
935
-			$this->checkout->json_response->set_return_data( array( 'payment_method_info' => $this->checkout->billing_form->get_html() ));
934
+		if ($this->checkout->billing_form instanceof EE_Form_Section_Proper) {
935
+			$this->checkout->json_response->set_return_data(array('payment_method_info' => $this->checkout->billing_form->get_html()));
936 936
 			// localize validation rules for main form
937
-			$this->checkout->billing_form->localize_validation_rules( TRUE );
938
-			$this->checkout->json_response->add_validation_rules( EE_Form_Section_Proper::js_localization() );
937
+			$this->checkout->billing_form->localize_validation_rules(TRUE);
938
+			$this->checkout->json_response->add_validation_rules(EE_Form_Section_Proper::js_localization());
939 939
 		} else {
940
-			$this->checkout->json_response->set_return_data( array( 'payment_method_info' => '' ));
940
+			$this->checkout->json_response->set_return_data(array('payment_method_info' => ''));
941 941
 		}
942 942
 		//prevents advancement to next step
943 943
 		$this->checkout->continue_reg = FALSE;
@@ -952,18 +952,18 @@  discard block
 block discarded – undo
952 952
 	 */
953 953
 	protected function _verify_payment_method_is_set() {
954 954
 		// generate billing form for selected method of payment if it hasn't been done already
955
-		if ( empty( $this->checkout->selected_method_of_payment )) {
955
+		if (empty($this->checkout->selected_method_of_payment)) {
956 956
 			// how have they chosen to pay?
957
-			$this->checkout->selected_method_of_payment = $this->_get_selected_method_of_payment( TRUE );
957
+			$this->checkout->selected_method_of_payment = $this->_get_selected_method_of_payment(TRUE);
958 958
 		} else {
959 959
 			// choose your own adventure based on method_of_payment
960
-			switch ( $this->checkout->selected_method_of_payment ) {
960
+			switch ($this->checkout->selected_method_of_payment) {
961 961
 				case 'events_sold_out' :
962 962
 					EE_Error::add_attention(
963 963
 						apply_filters(
964 964
 							'FHEE__EE_SPCO_Reg_Step_Payment_Options___verify_payment_method_is_set__sold_out_events_msg',
965
-							__( 'It appears that the event you were about to make a payment for has sold out since this form first loaded. Please contact the event administrator if you believe this is an error.',
966
-								'event_espresso' )
965
+							__('It appears that the event you were about to make a payment for has sold out since this form first loaded. Please contact the event administrator if you believe this is an error.',
966
+								'event_espresso')
967 967
 						),
968 968
 						__FILE__, __FUNCTION__, __LINE__
969 969
 					);
@@ -973,7 +973,7 @@  discard block
 block discarded – undo
973 973
 					EE_Error::add_attention(
974 974
 						apply_filters(
975 975
 							'FHEE__EE_SPCO_Reg_Step_Payment_Options___verify_payment_method_is_set__payments_closed_msg',
976
-							__( 'It appears that the event you were about to make a payment for is not accepting payments at this time. Please contact the event administrator if you believe this is an error.', 'event_espresso' )
976
+							__('It appears that the event you were about to make a payment for is not accepting payments at this time. Please contact the event administrator if you believe this is an error.', 'event_espresso')
977 977
 						),
978 978
 						__FILE__, __FUNCTION__, __LINE__
979 979
 					);
@@ -983,7 +983,7 @@  discard block
 block discarded – undo
983 983
 					EE_Error::add_attention(
984 984
 						apply_filters(
985 985
 							'FHEE__EE_SPCO_Reg_Step_Payment_Options___verify_payment_method_is_set__no_payment_required_msg',
986
-							__( 'It appears that the event you were about to make a payment for does not require payment. Please contact the event administrator if you believe this is an error.', 'event_espresso' )
986
+							__('It appears that the event you were about to make a payment for does not require payment. Please contact the event administrator if you believe this is an error.', 'event_espresso')
987 987
 						),
988 988
 						__FILE__, __FUNCTION__, __LINE__
989 989
 					);
@@ -993,7 +993,7 @@  discard block
 block discarded – undo
993 993
 			}
994 994
 		}
995 995
 		// verify payment method
996
-		if ( ! $this->checkout->payment_method instanceof EE_Payment_Method ) {
996
+		if ( ! $this->checkout->payment_method instanceof EE_Payment_Method) {
997 997
 			// get payment method for selected method of payment
998 998
 			$this->checkout->payment_method = $this->_get_payment_method_for_selected_method_of_payment();
999 999
 		}
@@ -1013,23 +1013,23 @@  discard block
 block discarded – undo
1013 1013
 	 * @return void
1014 1014
 	 */
1015 1015
 	public function save_payer_details_via_ajax() {
1016
-		if ( ! $this->_verify_payment_method_is_set() ) {
1016
+		if ( ! $this->_verify_payment_method_is_set()) {
1017 1017
 			return;
1018 1018
 		}
1019 1019
 		// generate billing form for selected method of payment if it hasn't been done already
1020
-		if ( $this->checkout->payment_method->type_obj()->has_billing_form() ) {
1021
-			$this->checkout->billing_form = $this->_get_billing_form_for_payment_method( $this->checkout->payment_method );
1020
+		if ($this->checkout->payment_method->type_obj()->has_billing_form()) {
1021
+			$this->checkout->billing_form = $this->_get_billing_form_for_payment_method($this->checkout->payment_method);
1022 1022
 		}
1023 1023
 		// generate primary attendee from payer info if applicable
1024 1024
 		if ( ! $this->checkout->transaction_has_primary_registrant()) {
1025 1025
 			$attendee = $this->_create_attendee_from_request_data();
1026
-			if ( $attendee instanceof EE_Attendee ) {
1027
-				foreach ( $this->checkout->transaction->registrations() as $registration ) {
1028
-					if ( $registration->is_primary_registrant() ) {
1026
+			if ($attendee instanceof EE_Attendee) {
1027
+				foreach ($this->checkout->transaction->registrations() as $registration) {
1028
+					if ($registration->is_primary_registrant()) {
1029 1029
 						$this->checkout->primary_attendee_obj = $attendee;
1030
-						$registration->_add_relation_to( $attendee, 'Attendee' );
1031
-						$registration->set_attendee_id( $attendee->ID() );
1032
-						$registration->update_cache_after_object_save( 'Attendee', $attendee );
1030
+						$registration->_add_relation_to($attendee, 'Attendee');
1031
+						$registration->set_attendee_id($attendee->ID());
1032
+						$registration->update_cache_after_object_save('Attendee', $attendee);
1033 1033
 					}
1034 1034
 				}
1035 1035
 			}
@@ -1042,56 +1042,56 @@  discard block
 block discarded – undo
1042 1042
 	 * uses info from alternate GET or POST data (such as AJAX) to create a new attendee
1043 1043
 	 * @return \EE_Attendee
1044 1044
 	 */
1045
-	protected function _create_attendee_from_request_data(){
1045
+	protected function _create_attendee_from_request_data() {
1046 1046
 		// get State ID
1047
-		$STA_ID = ! empty( $_REQUEST['state'] ) ? sanitize_text_field( $_REQUEST['state'] ) : '';
1048
-		if ( ! empty( $STA_ID )) {
1047
+		$STA_ID = ! empty($_REQUEST['state']) ? sanitize_text_field($_REQUEST['state']) : '';
1048
+		if ( ! empty($STA_ID)) {
1049 1049
 			// can we get state object from name ?
1050
-			EE_Registry::instance()->load_model( 'State' );
1051
-			$state = EEM_State::instance()->get_col( array( array( 'STA_name' => $STA_ID ), 'limit' => 1), 'STA_ID' );
1052
-			$STA_ID = is_array( $state ) && ! empty( $state ) ? reset( $state ) : $STA_ID;
1050
+			EE_Registry::instance()->load_model('State');
1051
+			$state = EEM_State::instance()->get_col(array(array('STA_name' => $STA_ID), 'limit' => 1), 'STA_ID');
1052
+			$STA_ID = is_array($state) && ! empty($state) ? reset($state) : $STA_ID;
1053 1053
 		}
1054 1054
 		// get Country ISO
1055
-		$CNT_ISO = ! empty( $_REQUEST['country'] ) ? sanitize_text_field( $_REQUEST['country'] ) : '';
1056
-		if ( ! empty( $CNT_ISO )) {
1055
+		$CNT_ISO = ! empty($_REQUEST['country']) ? sanitize_text_field($_REQUEST['country']) : '';
1056
+		if ( ! empty($CNT_ISO)) {
1057 1057
 			// can we get country object from name ?
1058
-			EE_Registry::instance()->load_model( 'Country' );
1059
-			$country = EEM_Country::instance()->get_col( array( array( 'CNT_name' => $CNT_ISO ), 'limit' => 1), 'CNT_ISO' );
1060
-			$CNT_ISO = is_array( $country ) && ! empty( $country ) ? reset( $country ) : $CNT_ISO;
1058
+			EE_Registry::instance()->load_model('Country');
1059
+			$country = EEM_Country::instance()->get_col(array(array('CNT_name' => $CNT_ISO), 'limit' => 1), 'CNT_ISO');
1060
+			$CNT_ISO = is_array($country) && ! empty($country) ? reset($country) : $CNT_ISO;
1061 1061
 		}
1062 1062
 		// grab attendee data
1063 1063
 		$attendee_data = array(
1064
-			'ATT_fname' 		=> ! empty( $_REQUEST['first_name'] ) ? sanitize_text_field( $_REQUEST['first_name'] ) : '',
1065
-			'ATT_lname' 		=> ! empty( $_REQUEST['last_name'] ) ? sanitize_text_field( $_REQUEST['last_name'] ) : '',
1066
-			'ATT_email' 		=> ! empty( $_REQUEST['email'] ) ? sanitize_email( $_REQUEST['email'] ) : '',
1067
-			'ATT_address' 		=> ! empty( $_REQUEST['address'] ) ? sanitize_text_field( $_REQUEST['address'] ) : '',
1068
-			'ATT_address2' 	=> ! empty( $_REQUEST['address2'] ) ? sanitize_text_field( $_REQUEST['address2'] ) : '',
1069
-			'ATT_city' 			=> ! empty( $_REQUEST['city'] ) ? sanitize_text_field( $_REQUEST['city'] ) : '',
1064
+			'ATT_fname' 		=> ! empty($_REQUEST['first_name']) ? sanitize_text_field($_REQUEST['first_name']) : '',
1065
+			'ATT_lname' 		=> ! empty($_REQUEST['last_name']) ? sanitize_text_field($_REQUEST['last_name']) : '',
1066
+			'ATT_email' 		=> ! empty($_REQUEST['email']) ? sanitize_email($_REQUEST['email']) : '',
1067
+			'ATT_address' 		=> ! empty($_REQUEST['address']) ? sanitize_text_field($_REQUEST['address']) : '',
1068
+			'ATT_address2' 	=> ! empty($_REQUEST['address2']) ? sanitize_text_field($_REQUEST['address2']) : '',
1069
+			'ATT_city' 			=> ! empty($_REQUEST['city']) ? sanitize_text_field($_REQUEST['city']) : '',
1070 1070
 			'STA_ID' 				=> $STA_ID,
1071 1071
 			'CNT_ISO' 			=> $CNT_ISO,
1072
-			'ATT_zip' 				=> ! empty( $_REQUEST['zip'] ) ? sanitize_text_field( $_REQUEST['zip'] ) : '',
1073
-			'ATT_phone' 		=> ! empty( $_REQUEST['phone'] ) ? sanitize_text_field( $_REQUEST['phone'] ) : '',
1072
+			'ATT_zip' 				=> ! empty($_REQUEST['zip']) ? sanitize_text_field($_REQUEST['zip']) : '',
1073
+			'ATT_phone' 		=> ! empty($_REQUEST['phone']) ? sanitize_text_field($_REQUEST['phone']) : '',
1074 1074
 		);
1075 1075
 		// validate the email address since it is the most important piece of info
1076
-		if ( empty( $attendee_data['ATT_email'] ) || $attendee_data['ATT_email'] != $_REQUEST['email'] ) {
1077
-			EE_Error::add_error( __( 'An invalid email address was submitted.', 'event_espresso' ), __FILE__, __FUNCTION__, __LINE__ );
1076
+		if (empty($attendee_data['ATT_email']) || $attendee_data['ATT_email'] != $_REQUEST['email']) {
1077
+			EE_Error::add_error(__('An invalid email address was submitted.', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__);
1078 1078
 		}
1079 1079
 		// does this attendee already exist in the db ? we're searching using a combination of first name, last name, AND email address
1080
-		if ( ! empty( $attendee_data['ATT_fname'] ) && ! empty( $attendee_data['ATT_lname'] ) && ! empty( $attendee_data['ATT_email'] ) ) {
1081
-			$existing_attendee = EE_Registry::instance()->LIB->EEM_Attendee->find_existing_attendee( array(
1080
+		if ( ! empty($attendee_data['ATT_fname']) && ! empty($attendee_data['ATT_lname']) && ! empty($attendee_data['ATT_email'])) {
1081
+			$existing_attendee = EE_Registry::instance()->LIB->EEM_Attendee->find_existing_attendee(array(
1082 1082
 				'ATT_fname' => $attendee_data['ATT_fname'],
1083 1083
 				'ATT_lname' => $attendee_data['ATT_lname'],
1084 1084
 				'ATT_email' => $attendee_data['ATT_email']
1085 1085
 			));
1086
-			if ( $existing_attendee instanceof EE_Attendee ) {
1086
+			if ($existing_attendee instanceof EE_Attendee) {
1087 1087
 				return $existing_attendee;
1088 1088
 			}
1089 1089
 		}
1090 1090
 		// no existing attendee? kk let's create a new one
1091 1091
 		// kinda lame, but we need a first and last name to create an attendee, so use the email address if those don't exist
1092
-		$attendee_data['ATT_fname'] = ! empty( $attendee_data['ATT_fname'] ) ? $attendee_data['ATT_fname'] : $attendee_data['ATT_email'];
1093
-		$attendee_data['ATT_lname'] = ! empty( $attendee_data['ATT_lname'] ) ? $attendee_data['ATT_lname'] : $attendee_data['ATT_email'];
1094
-		return EE_Attendee::new_instance( $attendee_data );
1092
+		$attendee_data['ATT_fname'] = ! empty($attendee_data['ATT_fname']) ? $attendee_data['ATT_fname'] : $attendee_data['ATT_email'];
1093
+		$attendee_data['ATT_lname'] = ! empty($attendee_data['ATT_lname']) ? $attendee_data['ATT_lname'] : $attendee_data['ATT_email'];
1094
+		return EE_Attendee::new_instance($attendee_data);
1095 1095
 	}
1096 1096
 
1097 1097
 
@@ -1111,22 +1111,22 @@  discard block
 block discarded – undo
1111 1111
 	 */
1112 1112
 	public function process_reg_step() {
1113 1113
 		// how have they chosen to pay?
1114
-		$this->checkout->selected_method_of_payment = $this->checkout->transaction->is_free() ? 'no_payment_required' : $this->_get_selected_method_of_payment( TRUE );
1114
+		$this->checkout->selected_method_of_payment = $this->checkout->transaction->is_free() ? 'no_payment_required' : $this->_get_selected_method_of_payment(TRUE);
1115 1115
 		// choose your own adventure based on method_of_payment
1116
-		switch(  $this->checkout->selected_method_of_payment ) {
1116
+		switch ($this->checkout->selected_method_of_payment) {
1117 1117
 
1118 1118
 			case 'events_sold_out' :
1119 1119
 				$this->checkout->redirect = TRUE;
1120 1120
 				$this->checkout->redirect_url = $this->checkout->cancel_page_url;
1121
-				$this->checkout->json_response->set_redirect_url( $this->checkout->redirect_url );
1121
+				$this->checkout->json_response->set_redirect_url($this->checkout->redirect_url);
1122 1122
 				// mark this reg step as completed
1123 1123
 				$this->set_completed();
1124 1124
 				return FALSE;
1125 1125
 				break;
1126 1126
 
1127 1127
 			case 'payments_closed' :
1128
-				if ( apply_filters( 'FHEE__EE_SPCO_Reg_Step_Payment_Options__process_reg_step__payments_closed__display_success', false ) ) {
1129
-					EE_Error::add_success( __( 'no payment required at this time.', 'event_espresso' ), __FILE__, __FUNCTION__, __LINE__ );
1128
+				if (apply_filters('FHEE__EE_SPCO_Reg_Step_Payment_Options__process_reg_step__payments_closed__display_success', false)) {
1129
+					EE_Error::add_success(__('no payment required at this time.', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__);
1130 1130
 				}
1131 1131
 				// mark this reg step as completed
1132 1132
 				$this->set_completed();
@@ -1134,8 +1134,8 @@  discard block
 block discarded – undo
1134 1134
 				break;
1135 1135
 
1136 1136
 			case 'no_payment_required' :
1137
-				if ( apply_filters( 'FHEE__EE_SPCO_Reg_Step_Payment_Options__process_reg_step__no_payment_required__display_success', false ) ) {
1138
-					EE_Error::add_success( __( 'no payment required.', 'event_espresso' ), __FILE__, __FUNCTION__, __LINE__ );
1137
+				if (apply_filters('FHEE__EE_SPCO_Reg_Step_Payment_Options__process_reg_step__no_payment_required__display_success', false)) {
1138
+					EE_Error::add_success(__('no payment required.', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__);
1139 1139
 				}
1140 1140
 				// mark this reg step as completed
1141 1141
 				$this->set_completed();
@@ -1144,9 +1144,9 @@  discard block
 block discarded – undo
1144 1144
 
1145 1145
 			default:
1146 1146
 				$payment_successful = $this->_process_payment();
1147
-				if ( $payment_successful ) {
1147
+				if ($payment_successful) {
1148 1148
 					$this->checkout->continue_reg = true;
1149
-					$this->_maybe_set_completed( $this->checkout->payment_method );
1149
+					$this->_maybe_set_completed($this->checkout->payment_method);
1150 1150
 				} else {
1151 1151
 					$this->checkout->continue_reg = false;
1152 1152
 				}
@@ -1164,8 +1164,8 @@  discard block
 block discarded – undo
1164 1164
 	 * @param \EE_Payment_Method $payment_method
1165 1165
 	 * @return void
1166 1166
 	 */
1167
-	protected function _maybe_set_completed( EE_Payment_Method $payment_method ) {
1168
-		switch ( $payment_method->type_obj()->payment_occurs() ) {
1167
+	protected function _maybe_set_completed(EE_Payment_Method $payment_method) {
1168
+		switch ($payment_method->type_obj()->payment_occurs()) {
1169 1169
 			case EE_PMT_Base::offsite :
1170 1170
 				break;
1171 1171
 			case EE_PMT_Base::onsite :
@@ -1188,15 +1188,15 @@  discard block
 block discarded – undo
1188 1188
 	public function update_reg_step() {
1189 1189
 		$success = TRUE;
1190 1190
 		// if payment required
1191
-		if ( $this->checkout->transaction->total() > 0 ) {
1192
-			do_action ('AHEE__EE_Single_Page_Checkout__process_finalize_registration__before_gateway', $this->checkout->transaction );
1191
+		if ($this->checkout->transaction->total() > 0) {
1192
+			do_action('AHEE__EE_Single_Page_Checkout__process_finalize_registration__before_gateway', $this->checkout->transaction);
1193 1193
 			// attempt payment via payment method
1194 1194
 			$success = $this->process_reg_step();
1195 1195
 		}
1196
-		if ( $success && ! $this->checkout->redirect ) {
1197
-			$this->checkout->cart->get_grand_total()->save_this_and_descendants_to_txn( $this->checkout->transaction->ID() );
1196
+		if ($success && ! $this->checkout->redirect) {
1197
+			$this->checkout->cart->get_grand_total()->save_this_and_descendants_to_txn($this->checkout->transaction->ID());
1198 1198
 			 // set return URL
1199
-			$this->checkout->redirect_url = add_query_arg( array( 'e_reg_url_link' => $this->checkout->reg_url_link ), $this->checkout->thank_you_page_url );
1199
+			$this->checkout->redirect_url = add_query_arg(array('e_reg_url_link' => $this->checkout->reg_url_link), $this->checkout->thank_you_page_url);
1200 1200
 		}
1201 1201
 		return $success;
1202 1202
 	}
@@ -1214,32 +1214,32 @@  discard block
 block discarded – undo
1214 1214
 	 */
1215 1215
 	private function _process_payment() {
1216 1216
 		// basically confirm that the event hasn't sold out since they hit the page
1217
-		if ( ! $this->_last_second_ticket_verifications() ) {
1217
+		if ( ! $this->_last_second_ticket_verifications()) {
1218 1218
 			return false;
1219 1219
 		}
1220 1220
 		// ya gotta make a choice man
1221
-		if ( empty( $this->checkout->selected_method_of_payment )) {
1222
-			$this->checkout->json_response->set_plz_select_method_of_payment( __( 'Please select a method of payment before proceeding.', 'event_espresso' ));
1221
+		if (empty($this->checkout->selected_method_of_payment)) {
1222
+			$this->checkout->json_response->set_plz_select_method_of_payment(__('Please select a method of payment before proceeding.', 'event_espresso'));
1223 1223
 			return FALSE;
1224 1224
 		}
1225 1225
 		// get EE_Payment_Method object
1226
-		if ( ! $this->checkout->payment_method = $this->_get_payment_method_for_selected_method_of_payment() ) {
1226
+		if ( ! $this->checkout->payment_method = $this->_get_payment_method_for_selected_method_of_payment()) {
1227 1227
 			return FALSE;
1228 1228
 		}
1229 1229
 		// setup billing form
1230
-		if ( $this->checkout->payment_method->is_on_site() ) {
1231
-			$this->checkout->billing_form = $this->_get_billing_form_for_payment_method( $this->checkout->payment_method );
1230
+		if ($this->checkout->payment_method->is_on_site()) {
1231
+			$this->checkout->billing_form = $this->_get_billing_form_for_payment_method($this->checkout->payment_method);
1232 1232
 			// bad billing form ?
1233
-			if ( ! $this->_billing_form_is_valid() ) {
1233
+			if ( ! $this->_billing_form_is_valid()) {
1234 1234
 				return FALSE;
1235 1235
 			}
1236 1236
 		}
1237 1237
 		// ensure primary registrant has been fully processed
1238
-		if ( ! $this->_setup_primary_registrant_prior_to_payment() ) {
1238
+		if ( ! $this->_setup_primary_registrant_prior_to_payment()) {
1239 1239
 			return FALSE;
1240 1240
 		}
1241 1241
 		// if session is close to expiring (under 10 minutes by default)
1242
-		if ( ( time() - EE_Registry::instance()->SSN->expiration() ) < EE_Registry::instance()->SSN->extension() ) {
1242
+		if ((time() - EE_Registry::instance()->SSN->expiration()) < EE_Registry::instance()->SSN->extension()) {
1243 1243
 			// add some time to session expiration so that payment can be completed
1244 1244
 			EE_Registry::instance()->SSN->extend_expiration();
1245 1245
 		}
@@ -1248,24 +1248,24 @@  discard block
 block discarded – undo
1248 1248
 		// in case a registrant leaves to an Off-Site Gateway and never returns, we want to approve any registrations for events with a default reg status of Approved
1249 1249
 		//$transaction_processor->toggle_registration_statuses_for_default_approved_events( $this->checkout->transaction, $this->checkout->reg_cache_where_params );
1250 1250
 		// attempt payment
1251
-		$payment = $this->_attempt_payment( $this->checkout->payment_method );
1251
+		$payment = $this->_attempt_payment($this->checkout->payment_method);
1252 1252
 		// process results
1253
-		$payment = $this->_validate_payment( $payment );
1254
-		$payment = $this->_post_payment_processing( $payment );
1253
+		$payment = $this->_validate_payment($payment);
1254
+		$payment = $this->_post_payment_processing($payment);
1255 1255
 		// verify payment
1256
-		if ( $payment instanceof EE_Payment ) {
1256
+		if ($payment instanceof EE_Payment) {
1257 1257
 			// store that for later
1258 1258
 			$this->checkout->payment = $payment;
1259 1259
 			/** @type EE_Transaction_Processor $transaction_processor */
1260
-			$transaction_processor = EE_Registry::instance()->load_class( 'Transaction_Processor' );
1260
+			$transaction_processor = EE_Registry::instance()->load_class('Transaction_Processor');
1261 1261
 			// we can also consider the TXN to not have been failed, so temporarily upgrade it's status to abandoned
1262
-			$transaction_processor->toggle_failed_transaction_status( $this->checkout->transaction );
1263
-			if ( $payment->status() == EEM_Payment::status_id_approved || $payment->status() == EEM_Payment::status_id_pending ) {
1262
+			$transaction_processor->toggle_failed_transaction_status($this->checkout->transaction);
1263
+			if ($payment->status() == EEM_Payment::status_id_approved || $payment->status() == EEM_Payment::status_id_pending) {
1264 1264
 				return true;
1265 1265
 			} else {
1266 1266
 				return false;
1267 1267
 			}
1268
-		} else if ( $payment === true ) {
1268
+		} else if ($payment === true) {
1269 1269
 			// please note that offline payment methods will NOT make a payment,
1270 1270
 			// but instead just mark themselves as the PMD_ID on the transaction, and return true
1271 1271
 			$this->checkout->payment = $payment;
@@ -1285,22 +1285,22 @@  discard block
 block discarded – undo
1285 1285
 	 */
1286 1286
 	protected function _last_second_ticket_verifications() {
1287 1287
 		// don't bother re-validating if not a return visit
1288
-		if ( ! $this->checkout->revisit ) {
1288
+		if ( ! $this->checkout->revisit) {
1289 1289
 			return true;
1290 1290
 		}
1291 1291
 		$registrations = $this->checkout->transaction->registrations();
1292
-		if ( empty( $registrations ) ) {
1292
+		if (empty($registrations)) {
1293 1293
 			return false;
1294 1294
 		}
1295
-		foreach ( $registrations as $registration ) {
1296
-			if ( $registration instanceof EE_Registration ) {
1295
+		foreach ($registrations as $registration) {
1296
+			if ($registration instanceof EE_Registration) {
1297 1297
 				$event = $registration->event_obj();
1298
-				if ( $event instanceof EE_Event && $event->is_sold_out( true ) ) {
1298
+				if ($event instanceof EE_Event && $event->is_sold_out(true)) {
1299 1299
 					EE_Error::add_error(
1300 1300
 						apply_filters(
1301 1301
 							'FHEE__EE_SPCO_Reg_Step_Payment_Options___last_second_ticket_verifications__sold_out_events_msg',
1302 1302
 							sprintf(
1303
-								__( 'It appears that the %1$s event that you were about to make a payment for has sold out since you first registered and/or arrived at this page. Please refresh the page and try again. If you have already made a partial payment towards this event, please contact the event administrator for a refund.', 'event_espresso' ),
1303
+								__('It appears that the %1$s event that you were about to make a payment for has sold out since you first registered and/or arrived at this page. Please refresh the page and try again. If you have already made a partial payment towards this event, please contact the event administrator for a refund.', 'event_espresso'),
1304 1304
 								$event->name()
1305 1305
 							)
1306 1306
 						),
@@ -1324,10 +1324,10 @@  discard block
 block discarded – undo
1324 1324
 	 * @return bool
1325 1325
 	 */
1326 1326
 	public function redirect_form() {
1327
-		$payment_method_billing_info = $this->_payment_method_billing_info( $this->_get_payment_method_for_selected_method_of_payment() );
1327
+		$payment_method_billing_info = $this->_payment_method_billing_info($this->_get_payment_method_for_selected_method_of_payment());
1328 1328
 		$html = $payment_method_billing_info->get_html_and_js();
1329 1329
 		$html .= $this->checkout->redirect_form;
1330
-		EE_Registry::instance()->REQ->add_output( $html );
1330
+		EE_Registry::instance()->REQ->add_output($html);
1331 1331
 		return TRUE;
1332 1332
 	}
1333 1333
 
@@ -1340,36 +1340,36 @@  discard block
 block discarded – undo
1340 1340
 	 * @return bool
1341 1341
 	 */
1342 1342
 	private function _billing_form_is_valid() {
1343
-		if ( ! $this->checkout->payment_method->type_obj()->has_billing_form() ) {
1343
+		if ( ! $this->checkout->payment_method->type_obj()->has_billing_form()) {
1344 1344
 			return TRUE;
1345 1345
 		}
1346
-		if ( $this->checkout->billing_form instanceof EE_Billing_Info_Form ) {
1347
-			if ( $this->checkout->billing_form->was_submitted() ) {
1346
+		if ($this->checkout->billing_form instanceof EE_Billing_Info_Form) {
1347
+			if ($this->checkout->billing_form->was_submitted()) {
1348 1348
 				$this->checkout->billing_form->receive_form_submission();
1349
-				if ( $this->checkout->billing_form->is_valid() ) {
1349
+				if ($this->checkout->billing_form->is_valid()) {
1350 1350
 					return TRUE;
1351 1351
 				}
1352 1352
 				$validation_errors = $this->checkout->billing_form->get_validation_errors_accumulated();
1353 1353
 				$error_strings = array();
1354
-				foreach( $validation_errors as $validation_error ){
1355
-					if( $validation_error instanceof EE_Validation_Error ){
1354
+				foreach ($validation_errors as $validation_error) {
1355
+					if ($validation_error instanceof EE_Validation_Error) {
1356 1356
 						$form_section = $validation_error->get_form_section();
1357
-						if( $form_section instanceof EE_Form_Input_Base ){
1357
+						if ($form_section instanceof EE_Form_Input_Base) {
1358 1358
 							$label = $form_section->html_label_text();
1359
-						}elseif( $form_section instanceof EE_Form_Section_Base ){
1359
+						}elseif ($form_section instanceof EE_Form_Section_Base) {
1360 1360
 							$label = $form_section->name();
1361
-						}else{
1362
-							$label = __( 'Validation Error', 'event_espresso' );
1361
+						} else {
1362
+							$label = __('Validation Error', 'event_espresso');
1363 1363
 						}
1364
-						$error_strings[] = sprintf('%1$s: %2$s', $label, $validation_error->getMessage() );
1364
+						$error_strings[] = sprintf('%1$s: %2$s', $label, $validation_error->getMessage());
1365 1365
 					}
1366 1366
 				}
1367
-				EE_Error::add_error( sprintf( __( 'One or more billing form inputs are invalid and require correction before proceeding. %1$s %2$s', 'event_espresso' ), '<br/>', implode( '<br/>', $error_strings )  ), __FILE__, __FUNCTION__, __LINE__ );
1367
+				EE_Error::add_error(sprintf(__('One or more billing form inputs are invalid and require correction before proceeding. %1$s %2$s', 'event_espresso'), '<br/>', implode('<br/>', $error_strings)), __FILE__, __FUNCTION__, __LINE__);
1368 1368
 			} else {
1369
-				EE_Error::add_error( __( 'The billing form was not submitted or something prevented it\'s submission.', 'event_espresso' ), __FILE__, __FUNCTION__, __LINE__ );
1369
+				EE_Error::add_error(__('The billing form was not submitted or something prevented it\'s submission.', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__);
1370 1370
 			}
1371 1371
 		} else {
1372
-			EE_Error::add_error( __( 'The submitted billing form is invalid possibly due to a technical reason.', 'event_espresso' ), __FILE__, __FUNCTION__, __LINE__ );
1372
+			EE_Error::add_error(__('The submitted billing form is invalid possibly due to a technical reason.', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__);
1373 1373
 		}
1374 1374
 		return FALSE;
1375 1375
 	}
@@ -1387,9 +1387,9 @@  discard block
 block discarded – undo
1387 1387
 	 */
1388 1388
 		private function _setup_primary_registrant_prior_to_payment() {
1389 1389
 			// check if transaction has a primary registrant and that it has a related Attendee object
1390
-			if ( ! $this->checkout->transaction_has_primary_registrant() ) {
1390
+			if ( ! $this->checkout->transaction_has_primary_registrant()) {
1391 1391
 				// need to at least gather some primary registrant data before attempting payment
1392
-				if ( $this->checkout->billing_form instanceof EE_Billing_Attendee_Info_Form && ! $this->_capture_primary_registration_data_from_billing_form() ) {
1392
+				if ($this->checkout->billing_form instanceof EE_Billing_Attendee_Info_Form && ! $this->_capture_primary_registration_data_from_billing_form()) {
1393 1393
 					return FALSE;
1394 1394
 				}
1395 1395
 			}
@@ -1397,13 +1397,13 @@  discard block
 block discarded – undo
1397 1397
 			// grab the primary_registration object
1398 1398
 			$primary_registration = $this->checkout->transaction->primary_registration();
1399 1399
 			/** @type EE_Transaction_Processor $transaction_processor */
1400
-			$transaction_processor = EE_Registry::instance()->load_class( 'Transaction_Processor' );
1400
+			$transaction_processor = EE_Registry::instance()->load_class('Transaction_Processor');
1401 1401
 			// at this point we'll consider a TXN to not have been failed
1402
-			$transaction_processor->toggle_failed_transaction_status( $this->checkout->transaction );
1402
+			$transaction_processor->toggle_failed_transaction_status($this->checkout->transaction);
1403 1403
 			// save the TXN ( which clears cached copy of primary_registration)
1404 1404
 			$this->checkout->transaction->save();
1405 1405
 			// grab TXN ID and save it to the primary_registration
1406
-			$primary_registration->set_transaction_id( $this->checkout->transaction->ID() );
1406
+			$primary_registration->set_transaction_id($this->checkout->transaction->ID());
1407 1407
 			// save what we have so far
1408 1408
 			$primary_registration->save();
1409 1409
 			return TRUE;
@@ -1420,41 +1420,41 @@  discard block
 block discarded – undo
1420 1420
 		private function _capture_primary_registration_data_from_billing_form() {
1421 1421
 			// convert billing form data into an attendee
1422 1422
 			$this->checkout->primary_attendee_obj = $this->checkout->billing_form->create_attendee_from_billing_form_data();
1423
-			if ( ! $this->checkout->primary_attendee_obj instanceof EE_Attendee ) {
1423
+			if ( ! $this->checkout->primary_attendee_obj instanceof EE_Attendee) {
1424 1424
 				EE_Error::add_error(
1425 1425
 					sprintf(
1426
-						__( 'The billing form details could not be used for attendee details due to a technical issue.%sPlease try again or contact %s for assistance.', 'event_espresso' ),
1426
+						__('The billing form details could not be used for attendee details due to a technical issue.%sPlease try again or contact %s for assistance.', 'event_espresso'),
1427 1427
 						'<br/>',
1428
-						EE_Registry::instance()->CFG->organization->get_pretty( 'email' )
1428
+						EE_Registry::instance()->CFG->organization->get_pretty('email')
1429 1429
 					), __FILE__, __FUNCTION__, __LINE__
1430 1430
 				);
1431 1431
 				return FALSE;
1432 1432
 			}
1433 1433
 			$primary_registration = $this->checkout->transaction->primary_registration();
1434
-			if ( ! $primary_registration instanceof EE_Registration ) {
1434
+			if ( ! $primary_registration instanceof EE_Registration) {
1435 1435
 				EE_Error::add_error(
1436 1436
 					sprintf(
1437
-						__( 'The primary registrant for this transaction could not be determined due to a technical issue.%sPlease try again or contact %s for assistance.', 'event_espresso' ),
1437
+						__('The primary registrant for this transaction could not be determined due to a technical issue.%sPlease try again or contact %s for assistance.', 'event_espresso'),
1438 1438
 						'<br/>',
1439
-						EE_Registry::instance()->CFG->organization->get_pretty( 'email' )
1439
+						EE_Registry::instance()->CFG->organization->get_pretty('email')
1440 1440
 					), __FILE__, __FUNCTION__, __LINE__
1441 1441
 				);
1442 1442
 				return FALSE;
1443 1443
 			}
1444
-			if ( ! $primary_registration->_add_relation_to( $this->checkout->primary_attendee_obj, 'Attendee' ) instanceof EE_Attendee ) {
1444
+			if ( ! $primary_registration->_add_relation_to($this->checkout->primary_attendee_obj, 'Attendee') instanceof EE_Attendee) {
1445 1445
 				EE_Error::add_error(
1446 1446
 					sprintf(
1447
-						__( 'The primary registrant could not be associated with this transaction due to a technical issue.%sPlease try again or contact %s for assistance.', 'event_espresso' ),
1447
+						__('The primary registrant could not be associated with this transaction due to a technical issue.%sPlease try again or contact %s for assistance.', 'event_espresso'),
1448 1448
 						'<br/>',
1449
-						EE_Registry::instance()->CFG->organization->get_pretty( 'email' )
1449
+						EE_Registry::instance()->CFG->organization->get_pretty('email')
1450 1450
 					), __FILE__, __FUNCTION__, __LINE__
1451 1451
 				);
1452 1452
 				return FALSE;
1453 1453
 			}
1454 1454
 			/** @type EE_Registration_Processor $registration_processor */
1455
-			$registration_processor = EE_Registry::instance()->load_class( 'Registration_Processor' );
1455
+			$registration_processor = EE_Registry::instance()->load_class('Registration_Processor');
1456 1456
 			// at this point, we should have enough details about the registrant to consider the registration NOT incomplete
1457
-			$registration_processor->toggle_incomplete_registration_status_to_default( $primary_registration );
1457
+			$registration_processor->toggle_incomplete_registration_status_to_default($primary_registration);
1458 1458
 
1459 1459
 			return TRUE;
1460 1460
 		}
@@ -1470,35 +1470,35 @@  discard block
 block discarded – undo
1470 1470
 	 */
1471 1471
 		private function _get_payment_method_for_selected_method_of_payment() {
1472 1472
 			// get EE_Payment_Method object
1473
-			if ( isset( $this->checkout->available_payment_methods[ $this->checkout->selected_method_of_payment ] )) {
1474
-				$payment_method = $this->checkout->available_payment_methods[ $this->checkout->selected_method_of_payment ];
1473
+			if (isset($this->checkout->available_payment_methods[$this->checkout->selected_method_of_payment])) {
1474
+				$payment_method = $this->checkout->available_payment_methods[$this->checkout->selected_method_of_payment];
1475 1475
 			} else {
1476 1476
 				// load EEM_Payment_Method
1477
-				EE_Registry::instance()->load_model( 'Payment_Method' );
1477
+				EE_Registry::instance()->load_model('Payment_Method');
1478 1478
 				/** @type EEM_Payment_Method $EEM_Payment_Method */
1479 1479
 				$EEM_Payment_Method = EE_Registry::instance()->LIB->EEM_Payment_Method;
1480
-				$payment_method = $EEM_Payment_Method->get_one_by_slug( $this->checkout->selected_method_of_payment );
1480
+				$payment_method = $EEM_Payment_Method->get_one_by_slug($this->checkout->selected_method_of_payment);
1481 1481
 			}
1482 1482
 			// verify $payment_method
1483
-			if ( ! $payment_method instanceof EE_Payment_Method ) {
1483
+			if ( ! $payment_method instanceof EE_Payment_Method) {
1484 1484
 				// not a payment
1485 1485
 				EE_Error::add_error(
1486 1486
 					sprintf(
1487
-						__( 'The selected method of payment could not be determined due to a technical issue.%sPlease try again or contact %s for assistance.', 'event_espresso' ),
1487
+						__('The selected method of payment could not be determined due to a technical issue.%sPlease try again or contact %s for assistance.', 'event_espresso'),
1488 1488
 						'<br/>',
1489
-						EE_Registry::instance()->CFG->organization->get_pretty( 'email' )
1489
+						EE_Registry::instance()->CFG->organization->get_pretty('email')
1490 1490
 					), __FILE__, __FUNCTION__, __LINE__
1491 1491
 				);
1492 1492
 				return NULL;
1493 1493
 			}
1494 1494
 			// and verify it has a valid Payment_Method Type object
1495
-			if ( ! $payment_method->type_obj() instanceof EE_PMT_Base ) {
1495
+			if ( ! $payment_method->type_obj() instanceof EE_PMT_Base) {
1496 1496
 				// not a payment
1497 1497
 				EE_Error::add_error(
1498 1498
 					sprintf(
1499
-						__( 'A valid payment method could not be determined due to a technical issue.%sPlease try again or contact %s for assistance.', 'event_espresso' ),
1499
+						__('A valid payment method could not be determined due to a technical issue.%sPlease try again or contact %s for assistance.', 'event_espresso'),
1500 1500
 						'<br/>',
1501
-						EE_Registry::instance()->CFG->organization->get_pretty( 'email' )
1501
+						EE_Registry::instance()->CFG->organization->get_pretty('email')
1502 1502
 					), __FILE__, __FUNCTION__, __LINE__
1503 1503
 				);
1504 1504
 				return NULL;
@@ -1517,30 +1517,30 @@  discard block
 block discarded – undo
1517 1517
 	 * 	@type 	EE_Payment_Method $payment_method
1518 1518
 	 * 	@return 	mixed	EE_Payment | boolean
1519 1519
 	 */
1520
-	private function _attempt_payment( EE_Payment_Method $payment_method ) {
1521
-		$payment =NULL;
1520
+	private function _attempt_payment(EE_Payment_Method $payment_method) {
1521
+		$payment = NULL;
1522 1522
 		$this->checkout->transaction->save();
1523
-		$payment_processor = EE_Registry::instance()->load_core( 'Payment_Processor' );
1524
-		if ( ! $payment_processor instanceof EE_Payment_Processor ) {
1523
+		$payment_processor = EE_Registry::instance()->load_core('Payment_Processor');
1524
+		if ( ! $payment_processor instanceof EE_Payment_Processor) {
1525 1525
 			return FALSE;
1526 1526
 		}
1527 1527
 		try {
1528
-			$payment_processor->set_revisit( $this->checkout->revisit );
1528
+			$payment_processor->set_revisit($this->checkout->revisit);
1529 1529
 			// generate payment object
1530 1530
 			$payment = $payment_processor->process_payment(
1531 1531
 				$payment_method,
1532 1532
 				$this->checkout->transaction,
1533 1533
 				$this->checkout->amount_owing,
1534 1534
 				$this->checkout->billing_form,
1535
-				$this->_get_return_url( $payment_method ),
1535
+				$this->_get_return_url($payment_method),
1536 1536
 				'CART',
1537 1537
 				$this->checkout->admin_request,
1538 1538
 				TRUE,
1539 1539
 				$this->reg_step_url()
1540 1540
 			);
1541 1541
 
1542
-		} catch( Exception $e ) {
1543
-			$this->_handle_payment_processor_exception( $e );
1542
+		} catch (Exception $e) {
1543
+			$this->_handle_payment_processor_exception($e);
1544 1544
 		}
1545 1545
 		return $payment;
1546 1546
 	}
@@ -1554,12 +1554,12 @@  discard block
 block discarded – undo
1554 1554
 	 * @param \Exception $e
1555 1555
 	 * @return void
1556 1556
 	 */
1557
-	protected function _handle_payment_processor_exception( Exception $e ) {
1557
+	protected function _handle_payment_processor_exception(Exception $e) {
1558 1558
 		EE_Error::add_error(
1559 1559
 			sprintf(
1560
-				__( 'The payment could not br processed due to a technical issue.%1$sPlease try again or contact %2$s for assistance.||The following Exception was thrown in %4$s on line %5$s:%1$s%3$s', 'event_espresso' ),
1560
+				__('The payment could not br processed due to a technical issue.%1$sPlease try again or contact %2$s for assistance.||The following Exception was thrown in %4$s on line %5$s:%1$s%3$s', 'event_espresso'),
1561 1561
 				'<br/>',
1562
-				EE_Registry::instance()->CFG->organization->get_pretty( 'email' ),
1562
+				EE_Registry::instance()->CFG->organization->get_pretty('email'),
1563 1563
 				$e->getMessage(),
1564 1564
 				$e->getFile(),
1565 1565
 				$e->getLine()
@@ -1576,9 +1576,9 @@  discard block
 block discarded – undo
1576 1576
 	 * @param \EE_Payment_Method $payment_method
1577 1577
 	 * @return string
1578 1578
 	 */
1579
-	protected function _get_return_url( EE_Payment_Method $payment_method ) {
1579
+	protected function _get_return_url(EE_Payment_Method $payment_method) {
1580 1580
 		$return_url = '';
1581
-		switch ( $payment_method->type_obj()->payment_occurs() ) {
1581
+		switch ($payment_method->type_obj()->payment_occurs()) {
1582 1582
 
1583 1583
 			case EE_PMT_Base::offsite :
1584 1584
 				$return_url = add_query_arg(
@@ -1609,18 +1609,18 @@  discard block
 block discarded – undo
1609 1609
 	 * @param EE_Payment $payment
1610 1610
 	 * @return EE_Payment | FALSE
1611 1611
 	 */
1612
-	private function _validate_payment( $payment = NULL ) {
1613
-		if (  $this->checkout->payment_method->is_off_line() ) {
1612
+	private function _validate_payment($payment = NULL) {
1613
+		if ($this->checkout->payment_method->is_off_line()) {
1614 1614
 			return TRUE;
1615 1615
 		}
1616 1616
 		// verify payment object
1617
-		if ( ! $payment instanceof EE_Payment ) {
1617
+		if ( ! $payment instanceof EE_Payment) {
1618 1618
 			// not a payment
1619 1619
 			EE_Error::add_error(
1620 1620
 				sprintf(
1621
-					__( 'A valid payment was not generated due to a technical issue.%1$sPlease try again or contact %2$s for assistance.', 'event_espresso' ),
1621
+					__('A valid payment was not generated due to a technical issue.%1$sPlease try again or contact %2$s for assistance.', 'event_espresso'),
1622 1622
 					'<br/>',
1623
-					EE_Registry::instance()->CFG->organization->get_pretty( 'email' )
1623
+					EE_Registry::instance()->CFG->organization->get_pretty('email')
1624 1624
 				), __FILE__, __FUNCTION__, __LINE__
1625 1625
 			);
1626 1626
 			return FALSE;
@@ -1637,23 +1637,23 @@  discard block
 block discarded – undo
1637 1637
 	 * @param EE_Payment $payment
1638 1638
 	 * @return bool
1639 1639
 	 */
1640
-	private function _post_payment_processing( $payment = NULL ) {
1640
+	private function _post_payment_processing($payment = NULL) {
1641 1641
 		// On-Site payment?
1642
-		if ( $this->checkout->payment_method->is_on_site() ) {
1643
-			if ( ! $this->_process_payment_status( $payment, EE_PMT_Base::onsite )) {
1642
+		if ($this->checkout->payment_method->is_on_site()) {
1643
+			if ( ! $this->_process_payment_status($payment, EE_PMT_Base::onsite)) {
1644 1644
 				//$this->_setup_redirect_for_next_step();
1645 1645
 				$this->checkout->continue_reg = false;
1646 1646
 			}
1647 1647
 			// Off-Site payment?
1648
-		} else if ( $this->checkout->payment_method->is_off_site() ) {
1648
+		} else if ($this->checkout->payment_method->is_off_site()) {
1649 1649
 			// if a payment object was made and it specifies a redirect url, then we'll setup that redirect info
1650
-			if ( $payment instanceof EE_Payment && $payment->redirect_url() ){
1651
-				do_action( 'AHEE_log', __CLASS__, __FUNCTION__, $payment->redirect_url(), '$payment->redirect_url()' );
1650
+			if ($payment instanceof EE_Payment && $payment->redirect_url()) {
1651
+				do_action('AHEE_log', __CLASS__, __FUNCTION__, $payment->redirect_url(), '$payment->redirect_url()');
1652 1652
 				$this->checkout->redirect = TRUE;
1653 1653
 				$this->checkout->redirect_form = $payment->redirect_form();
1654
-				$this->checkout->redirect_url = $this->reg_step_url( 'redirect_form' );
1654
+				$this->checkout->redirect_url = $this->reg_step_url('redirect_form');
1655 1655
 				// set JSON response
1656
-				$this->checkout->json_response->set_redirect_form( $this->checkout->redirect_form );
1656
+				$this->checkout->json_response->set_redirect_form($this->checkout->redirect_form);
1657 1657
 				// set cron job for finalizing the TXN
1658 1658
 				// in case the user does not return from the off-site gateway
1659 1659
 				EE_Cron_Tasks::schedule_finalize_abandoned_transactions_check(
@@ -1661,21 +1661,21 @@  discard block
 block discarded – undo
1661 1661
 					$this->checkout->transaction->ID()
1662 1662
 				);
1663 1663
 				// and lastly, let's bump the payment status to pending
1664
-				$payment->set_status( EEM_Payment::status_id_pending );
1664
+				$payment->set_status(EEM_Payment::status_id_pending);
1665 1665
 				$payment->save();
1666 1666
 			} else {
1667 1667
 				// not a payment
1668 1668
 				$this->checkout->continue_reg = false;
1669 1669
 				EE_Error::add_error(
1670 1670
 					sprintf(
1671
-						__( 'It appears the Off Site Payment Method was not configured properly.%sPlease try again or contact %s for assistance.', 'event_espresso' ),
1671
+						__('It appears the Off Site Payment Method was not configured properly.%sPlease try again or contact %s for assistance.', 'event_espresso'),
1672 1672
 						'<br/>',
1673
-						EE_Registry::instance()->CFG->organization->get_pretty( 'email' )
1673
+						EE_Registry::instance()->CFG->organization->get_pretty('email')
1674 1674
 					), __FILE__, __FUNCTION__, __LINE__
1675 1675
 				);
1676 1676
 			}
1677 1677
 			// Off-Line payment?
1678
-		} else if ( $payment === TRUE ) {
1678
+		} else if ($payment === TRUE) {
1679 1679
 			//$this->_setup_redirect_for_next_step();
1680 1680
 			return TRUE;
1681 1681
 		} else {
@@ -1711,65 +1711,65 @@  discard block
 block discarded – undo
1711 1711
 	 * @return bool
1712 1712
 	 * @throws \EE_Error
1713 1713
 	 */
1714
-	private function _process_payment_status( $payment, $payment_occurs = EE_PMT_Base::offline ) {
1714
+	private function _process_payment_status($payment, $payment_occurs = EE_PMT_Base::offline) {
1715 1715
 		// off-line payment? carry on
1716
-		if ( $payment_occurs == EE_PMT_Base::offline ) {
1716
+		if ($payment_occurs == EE_PMT_Base::offline) {
1717 1717
 			return true;
1718 1718
 		}
1719 1719
 		// verify payment validity
1720
-		if ( $payment instanceof EE_Payment ) {
1721
-			do_action( 'AHEE_log', __CLASS__, __FUNCTION__, $payment->status(), '$payment->status()' );
1720
+		if ($payment instanceof EE_Payment) {
1721
+			do_action('AHEE_log', __CLASS__, __FUNCTION__, $payment->status(), '$payment->status()');
1722 1722
 			$msg = $payment->gateway_response();
1723 1723
 			// check results
1724
-			switch ( $payment->status() ) {
1724
+			switch ($payment->status()) {
1725 1725
 
1726 1726
 				// good payment
1727 1727
 				case EEM_Payment::status_id_approved :
1728
-					EE_Error::add_success( __( 'Your payment was processed successfully.', 'event_espresso' ), __FILE__, __FUNCTION__, __LINE__ );
1728
+					EE_Error::add_success(__('Your payment was processed successfully.', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__);
1729 1729
 					return TRUE;
1730 1730
 					break;
1731 1731
 
1732 1732
 				// slow payment
1733 1733
 				case EEM_Payment::status_id_pending :
1734
-					if ( empty( $msg )) {
1735
-						$msg = __( 'Your payment appears to have been processed successfully, but the Instant Payment Notification has not yet been received. It should arrive shortly.', 'event_espresso' );
1734
+					if (empty($msg)) {
1735
+						$msg = __('Your payment appears to have been processed successfully, but the Instant Payment Notification has not yet been received. It should arrive shortly.', 'event_espresso');
1736 1736
 					}
1737
-					EE_Error::add_success( $msg, __FILE__, __FUNCTION__, __LINE__ );
1737
+					EE_Error::add_success($msg, __FILE__, __FUNCTION__, __LINE__);
1738 1738
 					return TRUE;
1739 1739
 					break;
1740 1740
 
1741 1741
 				// don't wanna payment
1742 1742
 				case EEM_Payment::status_id_cancelled :
1743
-					if ( empty( $msg )) {
1743
+					if (empty($msg)) {
1744 1744
 						$msg = _n(
1745 1745
 							'Payment cancelled. Please try again.',
1746 1746
 							'Payment cancelled. Please try again or select another method of payment.',
1747
-							count( $this->checkout->available_payment_methods ),
1747
+							count($this->checkout->available_payment_methods),
1748 1748
 							'event_espresso'
1749 1749
 						);
1750 1750
 					}
1751
-					EE_Error::add_attention( $msg, __FILE__, __FUNCTION__, __LINE__ );
1751
+					EE_Error::add_attention($msg, __FILE__, __FUNCTION__, __LINE__);
1752 1752
 					return FALSE;
1753 1753
 					break;
1754 1754
 
1755 1755
 				// not enough payment
1756 1756
 				case EEM_Payment::status_id_declined :
1757
-					if ( empty( $msg )) {
1757
+					if (empty($msg)) {
1758 1758
 						$msg = _n(
1759 1759
 							'We\'re sorry but your payment was declined. Please try again.',
1760 1760
 							'We\'re sorry but your payment was declined. Please try again or select another method of payment.',
1761
-							count( $this->checkout->available_payment_methods ),
1761
+							count($this->checkout->available_payment_methods),
1762 1762
 							'event_espresso'
1763 1763
 						);
1764 1764
 					}
1765
-					EE_Error::add_attention( $msg, __FILE__, __FUNCTION__, __LINE__ );
1765
+					EE_Error::add_attention($msg, __FILE__, __FUNCTION__, __LINE__);
1766 1766
 					return FALSE;
1767 1767
 					break;
1768 1768
 
1769 1769
 				// bad payment
1770 1770
 				case EEM_Payment::status_id_failed :
1771
-					if ( ! empty( $msg ) ) {
1772
-						EE_Error::add_error( $msg, __FILE__, __FUNCTION__, __LINE__ );
1771
+					if ( ! empty($msg)) {
1772
+						EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
1773 1773
 						return false;
1774 1774
 					}
1775 1775
 					// default to error below
@@ -1779,14 +1779,14 @@  discard block
 block discarded – undo
1779 1779
 		}
1780 1780
 		// off-site payment gateway responses are too unreliable, so let's just assume that
1781 1781
 		// the payment processing is just running slower than the registrant's request
1782
-		if ( $payment_occurs == EE_PMT_Base::offsite ) {
1782
+		if ($payment_occurs == EE_PMT_Base::offsite) {
1783 1783
 			return true;
1784 1784
 		}
1785 1785
 		EE_Error::add_error(
1786 1786
 				sprintf(
1787
-					__( 'Your payment could not be processed successfully due to a technical issue.%sPlease try again or contact %s for assistance.', 'event_espresso' ),
1787
+					__('Your payment could not be processed successfully due to a technical issue.%sPlease try again or contact %s for assistance.', 'event_espresso'),
1788 1788
 					'<br/>',
1789
-					EE_Registry::instance()->CFG->organization->get_pretty( 'email' )
1789
+					EE_Registry::instance()->CFG->organization->get_pretty('email')
1790 1790
 				),
1791 1791
 				__FILE__, __FUNCTION__, __LINE__
1792 1792
 			);
@@ -1817,13 +1817,13 @@  discard block
 block discarded – undo
1817 1817
 	public function process_gateway_response() {
1818 1818
 		$payment = null;
1819 1819
 		// how have they chosen to pay?
1820
-		$this->checkout->selected_method_of_payment = $this->_get_selected_method_of_payment( true );
1820
+		$this->checkout->selected_method_of_payment = $this->_get_selected_method_of_payment(true);
1821 1821
 		// get EE_Payment_Method object
1822
-		if ( ! $this->checkout->payment_method = $this->_get_payment_method_for_selected_method_of_payment() ) {
1822
+		if ( ! $this->checkout->payment_method = $this->_get_payment_method_for_selected_method_of_payment()) {
1823 1823
 			$this->checkout->continue_reg = false;
1824 1824
 			return false;
1825 1825
 		}
1826
-		if ( ! $this->checkout->payment_method->is_off_site() ) {
1826
+		if ( ! $this->checkout->payment_method->is_off_site()) {
1827 1827
 			return false;
1828 1828
 		}
1829 1829
 		$this->_validate_offsite_return();
@@ -1837,23 +1837,23 @@  discard block
 block discarded – undo
1837 1837
 		//	true
1838 1838
 		//);
1839 1839
 		// verify TXN
1840
-		if ( $this->checkout->transaction instanceof EE_Transaction ) {
1840
+		if ($this->checkout->transaction instanceof EE_Transaction) {
1841 1841
 			$gateway = $this->checkout->payment_method->type_obj()->get_gateway();
1842
-			if ( ! $gateway instanceof EE_Offsite_Gateway ) {
1842
+			if ( ! $gateway instanceof EE_Offsite_Gateway) {
1843 1843
 				$this->checkout->continue_reg = false;
1844 1844
 				return false;
1845 1845
 			}
1846
-			$payment = $this->_process_off_site_payment( $gateway );
1847
-			$payment = $this->_process_cancelled_payments( $payment );
1848
-			$payment = $this->_validate_payment( $payment );
1846
+			$payment = $this->_process_off_site_payment($gateway);
1847
+			$payment = $this->_process_cancelled_payments($payment);
1848
+			$payment = $this->_validate_payment($payment);
1849 1849
 			// if payment was not declined by the payment gateway or cancelled by the registrant
1850
-			if ( $this->_process_payment_status( $payment, EE_PMT_Base::offsite ) ) {
1850
+			if ($this->_process_payment_status($payment, EE_PMT_Base::offsite)) {
1851 1851
 				//$this->_setup_redirect_for_next_step();
1852 1852
 				// store that for later
1853 1853
 				$this->checkout->payment = $payment;
1854 1854
 				// mark this reg step as completed, as long as gateway doesn't use a separate IPN request,
1855 1855
 				// because we will complete this step during the IPN processing then
1856
-				if ( $gateway instanceof EE_Offsite_Gateway && ! $this->handle_IPN_in_this_request() ) {
1856
+				if ($gateway instanceof EE_Offsite_Gateway && ! $this->handle_IPN_in_this_request()) {
1857 1857
 					$this->set_completed();
1858 1858
 				}
1859 1859
 				return true;
@@ -1876,19 +1876,19 @@  discard block
 block discarded – undo
1876 1876
 	 * @return bool
1877 1877
 	 */
1878 1878
 	private function _validate_offsite_return() {
1879
-		$TXN_ID = (int)EE_Registry::instance()->REQ->get( 'spco_txn', 0 );
1880
-		if ( $TXN_ID != $this->checkout->transaction->ID() ) {
1879
+		$TXN_ID = (int) EE_Registry::instance()->REQ->get('spco_txn', 0);
1880
+		if ($TXN_ID != $this->checkout->transaction->ID()) {
1881 1881
 			// Houston... we might have a problem
1882 1882
 			$invalid_TXN = false;
1883 1883
 			// first gather some info
1884
-			$valid_TXN = EEM_Transaction::instance()->get_one_by_ID( $TXN_ID );
1884
+			$valid_TXN = EEM_Transaction::instance()->get_one_by_ID($TXN_ID);
1885 1885
 			$primary_registrant = $valid_TXN instanceof EE_Transaction ? $valid_TXN->primary_registration() : null;
1886 1886
 			// let's start by retrieving the cart for this TXN
1887
-			$cart = EE_Cart::get_cart_from_txn( $this->checkout->transaction );
1888
-			if ( $cart instanceof EE_Cart ) {
1887
+			$cart = EE_Cart::get_cart_from_txn($this->checkout->transaction);
1888
+			if ($cart instanceof EE_Cart) {
1889 1889
 				// verify that the current cart has tickets
1890 1890
 				$tickets = $cart->get_tickets();
1891
-				if ( empty( $tickets ) ) {
1891
+				if (empty($tickets)) {
1892 1892
 					$invalid_TXN = true;
1893 1893
 				}
1894 1894
 			} else {
@@ -1896,39 +1896,39 @@  discard block
 block discarded – undo
1896 1896
 			}
1897 1897
 			$valid_TXN_SID = $primary_registrant instanceof EE_Registration ? $primary_registrant->session_ID() : null;
1898 1898
 			// validate current Session ID and compare against valid TXN session ID
1899
-			if ( EE_Session::instance()->id() === null ) {
1899
+			if (EE_Session::instance()->id() === null) {
1900 1900
 				$invalid_TXN = true;
1901
-			} else if ( EE_Session::instance()->id() === $valid_TXN_SID ) {
1901
+			} else if (EE_Session::instance()->id() === $valid_TXN_SID) {
1902 1902
 				// WARNING !!!
1903 1903
 				// this could be PayPal sending back duplicate requests (ya they do that)
1904 1904
 				// or it **could** mean someone is simply registering AGAIN after having just done so
1905 1905
 				// so now we need to determine if this current TXN looks valid or not
1906 1906
 				/** @type EE_Transaction_Processor $transaction_processor */
1907
-				$transaction_processor = EE_Registry::instance()->load_class( 'Transaction_Processor' );
1907
+				$transaction_processor = EE_Registry::instance()->load_class('Transaction_Processor');
1908 1908
 				// has this step even been started ?
1909
-				if ( $transaction_processor->reg_step_completed( $this->checkout->transaction, $this->slug() === false )
1909
+				if ($transaction_processor->reg_step_completed($this->checkout->transaction, $this->slug() === false)
1910 1910
 				) {
1911 1911
 					// really? you're half way through this reg step, but you never started it ?
1912 1912
 					$invalid_TXN = true;
1913 1913
 				}
1914 1914
 			}
1915
-			if ( $invalid_TXN ) {
1915
+			if ($invalid_TXN) {
1916 1916
 				// is the valid TXN completed ?
1917
-				if ( $valid_TXN instanceof EE_Transaction ) {
1917
+				if ($valid_TXN instanceof EE_Transaction) {
1918 1918
 					/** @type EE_Transaction_Processor $transaction_processor */
1919
-					$transaction_processor = EE_Registry::instance()->load_class( 'Transaction_Processor' );
1919
+					$transaction_processor = EE_Registry::instance()->load_class('Transaction_Processor');
1920 1920
 					// has this step even been started ?
1921
-					$reg_step_completed = $transaction_processor->reg_step_completed( $valid_TXN, $this->slug() );
1922
-					if ( $reg_step_completed !== false && $reg_step_completed !== true ) {
1921
+					$reg_step_completed = $transaction_processor->reg_step_completed($valid_TXN, $this->slug());
1922
+					if ($reg_step_completed !== false && $reg_step_completed !== true) {
1923 1923
 						// so it **looks** like this is a double request from PayPal
1924 1924
 						// so let's try to pick up where we left off
1925 1925
 						$this->checkout->transaction = $valid_TXN;
1926
-						$this->checkout->refresh_all_entities( true );
1926
+						$this->checkout->refresh_all_entities(true);
1927 1927
 						return;
1928 1928
 					}
1929 1929
 				}
1930 1930
 				// you appear to be lost?
1931
-				$this->_redirect_wayward_request( $primary_registrant );
1931
+				$this->_redirect_wayward_request($primary_registrant);
1932 1932
 			}
1933 1933
 		}
1934 1934
 	}
@@ -1942,16 +1942,16 @@  discard block
 block discarded – undo
1942 1942
 	 * @param \EE_Registration $primary_registrant
1943 1943
 	 * @return bool
1944 1944
 	 */
1945
-	private function _redirect_wayward_request( EE_Registration $primary_registrant ) {
1946
-		if ( ! $primary_registrant instanceof EE_Registration ) {
1945
+	private function _redirect_wayward_request(EE_Registration $primary_registrant) {
1946
+		if ( ! $primary_registrant instanceof EE_Registration) {
1947 1947
 			// try redirecting based on the current TXN
1948 1948
 			$primary_registrant = $this->checkout->transaction instanceof EE_Transaction ? $this->checkout->transaction->primary_registration() : null;
1949
-			if ( ! $primary_registrant instanceof EE_Registration ) {
1949
+			if ( ! $primary_registrant instanceof EE_Registration) {
1950 1950
 				EE_Error::add_error(
1951 1951
 					sprintf(
1952
-						__( 'Invalid information was received from the Off-Site Payment Processor and your Transaction details could not be retrieved from the database.%1$sPlease try again or contact %2$s for assistance.', 'event_espresso' ),
1952
+						__('Invalid information was received from the Off-Site Payment Processor and your Transaction details could not be retrieved from the database.%1$sPlease try again or contact %2$s for assistance.', 'event_espresso'),
1953 1953
 						'<br/>',
1954
-						EE_Registry::instance()->CFG->organization->get_pretty( 'email' )
1954
+						EE_Registry::instance()->CFG->organization->get_pretty('email')
1955 1955
 					),
1956 1956
 					__FILE__, __FUNCTION__, __LINE__
1957 1957
 				);
@@ -1979,17 +1979,17 @@  discard block
 block discarded – undo
1979 1979
 	 * @param \EE_Offsite_Gateway $gateway
1980 1980
 	 * @return \EE_Payment
1981 1981
 	 */
1982
-	private function _process_off_site_payment( EE_Offsite_Gateway $gateway ) {
1982
+	private function _process_off_site_payment(EE_Offsite_Gateway $gateway) {
1983 1983
 		try {
1984 1984
 			$request_data = \EE_Registry::instance()->REQ->params();
1985 1985
 			// if gateway uses_separate_IPN_request, then we don't have to process the IPN manually
1986 1986
 			$this->set_handle_IPN_in_this_request(
1987
-				$gateway->handle_IPN_in_this_request( $request_data, false )
1987
+				$gateway->handle_IPN_in_this_request($request_data, false)
1988 1988
 			);
1989
-			if ( $this->handle_IPN_in_this_request() ) {
1989
+			if ($this->handle_IPN_in_this_request()) {
1990 1990
 				// get payment details and process results
1991 1991
 				/** @type EE_Payment_Processor $payment_processor */
1992
-				$payment_processor = EE_Registry::instance()->load_core( 'Payment_Processor' );
1992
+				$payment_processor = EE_Registry::instance()->load_core('Payment_Processor');
1993 1993
 				$payment = $payment_processor->process_ipn(
1994 1994
 					$request_data,
1995 1995
 					$this->checkout->transaction,
@@ -2002,14 +2002,14 @@  discard block
 block discarded – undo
2002 2002
 				$payment = $this->checkout->transaction->last_payment();
2003 2003
 				//$payment_source = 'last_payment';
2004 2004
 			}
2005
-		} catch ( Exception $e ) {
2005
+		} catch (Exception $e) {
2006 2006
 			// let's just eat the exception and try to move on using any previously set payment info
2007 2007
 			$payment = $this->checkout->transaction->last_payment();
2008 2008
 			//$payment_source = 'last_payment after Exception';
2009 2009
 			// but if we STILL don't have a payment object
2010
-			if ( ! $payment instanceof EE_Payment ) {
2010
+			if ( ! $payment instanceof EE_Payment) {
2011 2011
 				// then we'll object ! ( not object like a thing... but object like what a lawyer says ! )
2012
-				$this->_handle_payment_processor_exception( $e );
2012
+				$this->_handle_payment_processor_exception($e);
2013 2013
 			}
2014 2014
 		}
2015 2015
 		// DEBUG LOG
@@ -2033,13 +2033,13 @@  discard block
 block discarded – undo
2033 2033
 	 * @param EE_Payment $payment
2034 2034
 	 * @return EE_Payment | FALSE
2035 2035
 	 */
2036
-	private function _process_cancelled_payments( $payment = NULL ) {
2036
+	private function _process_cancelled_payments($payment = NULL) {
2037 2037
 		if (
2038
-			isset( $_REQUEST[ 'ee_cancel_payment' ] )
2038
+			isset($_REQUEST['ee_cancel_payment'])
2039 2039
 			&& $payment instanceof EE_Payment
2040 2040
 			&& $payment->status() == EEM_Payment::status_id_failed
2041 2041
 		) {
2042
-			$payment->set_status( EEM_Payment::status_id_cancelled );
2042
+			$payment->set_status(EEM_Payment::status_id_cancelled);
2043 2043
 		}
2044 2044
 		return $payment;
2045 2045
 	}
@@ -2056,23 +2056,23 @@  discard block
 block discarded – undo
2056 2056
 	public function get_transaction_details_for_gateways() {
2057 2057
 		$txn_details = array();
2058 2058
 		// ya gotta make a choice man
2059
-		if ( empty( $this->checkout->selected_method_of_payment ) ) {
2059
+		if (empty($this->checkout->selected_method_of_payment)) {
2060 2060
 			$txn_details = array(
2061
-				'error' => __( 'Please select a method of payment before proceeding.', 'event_espresso' )
2061
+				'error' => __('Please select a method of payment before proceeding.', 'event_espresso')
2062 2062
 			);
2063 2063
 		}
2064 2064
 		// get EE_Payment_Method object
2065 2065
 		if (
2066
-			empty( $txn_details ) &&
2066
+			empty($txn_details) &&
2067 2067
 			! $this->checkout->payment_method = $this->_get_payment_method_for_selected_method_of_payment()
2068 2068
 		) {
2069 2069
 			$txn_details = array(
2070 2070
 				'selected_method_of_payment' => $this->checkout->selected_method_of_payment,
2071
-				'error' => __( 'A valid Payment Method could not be determined.', 'event_espresso' )
2071
+				'error' => __('A valid Payment Method could not be determined.', 'event_espresso')
2072 2072
 			);
2073 2073
 		}
2074
-		if ( empty( $txn_details ) && $this->checkout->transaction instanceof EE_Transaction ) {
2075
-			$return_url = $this->_get_return_url( $this->checkout->payment_method );
2074
+		if (empty($txn_details) && $this->checkout->transaction instanceof EE_Transaction) {
2075
+			$return_url = $this->_get_return_url($this->checkout->payment_method);
2076 2076
 			$txn_details = array(
2077 2077
 				'TXN_ID'        			=> $this->checkout->transaction->ID(),
2078 2078
 				'TXN_timestamp' 	=> $this->checkout->transaction->datetime(),
@@ -2083,7 +2083,7 @@  discard block
 block discarded – undo
2083 2083
 				'PMD_ID'        			=> $this->checkout->transaction->payment_method_ID(),
2084 2084
 				'payment_amount' => $this->checkout->amount_owing,
2085 2085
 				'return_url' 				=> $return_url,
2086
-				'cancel_url' 				=> add_query_arg( array( 'ee_cancel_payment' => true ), $return_url ),
2086
+				'cancel_url' 				=> add_query_arg(array('ee_cancel_payment' => true), $return_url),
2087 2087
 				'notify_url' 				=> EE_Config::instance()->core->txn_page_url(
2088 2088
 					array(
2089 2089
 						'e_reg_url_link'    			=> $this->checkout->transaction->primary_registration()->reg_url_link(),
@@ -2092,7 +2092,7 @@  discard block
 block discarded – undo
2092 2092
 				)
2093 2093
 			);
2094 2094
 		}
2095
-		echo json_encode( $txn_details );
2095
+		echo json_encode($txn_details);
2096 2096
 		exit();
2097 2097
 	}
2098 2098
 
Please login to merge, or discard this patch.
core/EE_Cron_Tasks.core.php 1 patch
Spacing   +87 added lines, -87 removed lines patch added patch discarded remove patch
@@ -28,7 +28,7 @@  discard block
 block discarded – undo
28 28
 	 * @return EE_Cron_Tasks
29 29
 	 */
30 30
 	public static function instance() {
31
-		if ( ! self::$_instance instanceof EE_Cron_Tasks ) {
31
+		if ( ! self::$_instance instanceof EE_Cron_Tasks) {
32 32
 			self::$_instance = new self();
33 33
 		}
34 34
 		return self::$_instance;
@@ -41,9 +41,9 @@  discard block
 block discarded – undo
41 41
 	 * @return EE_Cron_Tasks
42 42
 	 */
43 43
 	private function __construct() {
44
-		do_action( 'AHEE_log', __CLASS__, __FUNCTION__ );
44
+		do_action('AHEE_log', __CLASS__, __FUNCTION__);
45 45
 		// verify that WP Cron is enabled
46
-		if ( defined( 'DISABLE_WP_CRON' ) && DISABLE_WP_CRON && is_admin() ) {
46
+		if (defined('DISABLE_WP_CRON') && DISABLE_WP_CRON && is_admin()) {
47 47
 			EE_Error::add_persistent_admin_notice(
48 48
 				'wp_cron_disabled',
49 49
 				sprintf(
@@ -58,30 +58,30 @@  discard block
 block discarded – undo
58 58
 		// UPDATE TRANSACTION WITH PAYMENT
59 59
 		add_action(
60 60
 			'AHEE__EE_Cron_Tasks__update_transaction_with_payment_2',
61
-			array( 'EE_Cron_Tasks', 'setup_update_for_transaction_with_payment' ),
61
+			array('EE_Cron_Tasks', 'setup_update_for_transaction_with_payment'),
62 62
 			10, 2
63 63
 		);
64 64
 		// FINALIZE ABANDONED TRANSACTIONS
65 65
 		add_action(
66 66
 			'AHEE__EE_Cron_Tasks__finalize_abandoned_transactions',
67
-			array( 'EE_Cron_Tasks', 'check_for_abandoned_transactions' ),
67
+			array('EE_Cron_Tasks', 'check_for_abandoned_transactions'),
68 68
 			10, 1
69 69
 		);
70 70
 		// EXPIRED TRANSACTION CHECK
71 71
 		add_action(
72 72
 			'AHEE__EE_Cron_Tasks__expired_transaction_check',
73
-			array( 'EE_Cron_Tasks', 'expired_transaction_check' ),
73
+			array('EE_Cron_Tasks', 'expired_transaction_check'),
74 74
 			10, 1
75 75
 		);
76 76
 		// CLEAN OUT JUNK TRANSACTIONS AND RELATED DATA
77 77
 		add_action(
78 78
 				'AHEE__EE_Cron_Tasks__clean_up_junk_transactions',
79
-				array( 'EE_Cron_Tasks', 'clean_out_junk_transactions' )
79
+				array('EE_Cron_Tasks', 'clean_out_junk_transactions')
80 80
 		);
81 81
 		// logging
82 82
 		add_action(
83 83
 			'AHEE__EE_System__load_core_configuration__complete',
84
-			array( 'EE_Cron_Tasks', 'log_scheduled_ee_crons' )
84
+			array('EE_Cron_Tasks', 'log_scheduled_ee_crons')
85 85
 		);
86 86
 	}
87 87
 
@@ -97,17 +97,17 @@  discard block
 block discarded – undo
97 97
 			'AHEE__EE_Cron_Tasks__finalize_abandoned_transactions',
98 98
 			'AHEE__EE_Cron_Tasks__clean_up_junk_transactions',
99 99
 		);
100
-		$crons = get_option( 'cron' );
101
-		if ( ! is_array( $crons ) ) {
100
+		$crons = get_option('cron');
101
+		if ( ! is_array($crons)) {
102 102
 			return;
103 103
 		}
104
-		foreach ( $crons as $timestamp => $cron ) {
105
-			foreach ( $ee_crons as $ee_cron ) {
106
-				if ( isset( $cron[ $ee_cron ] ) ) {
107
-					foreach ( $cron[ $ee_cron ] as $ee_cron_details ) {
108
-						do_action( 'AHEE_log', __CLASS__, __FUNCTION__, $ee_cron, 'scheduled EE cron' );
109
-						if ( ! empty( $ee_cron_details[ 'args' ] )) {
110
-							do_action( 'AHEE_log', __CLASS__, __FUNCTION__, print_r( $ee_cron_details[ 'args' ], true ), "$ee_cron args" );
104
+		foreach ($crons as $timestamp => $cron) {
105
+			foreach ($ee_crons as $ee_cron) {
106
+				if (isset($cron[$ee_cron])) {
107
+					foreach ($cron[$ee_cron] as $ee_cron_details) {
108
+						do_action('AHEE_log', __CLASS__, __FUNCTION__, $ee_cron, 'scheduled EE cron');
109
+						if ( ! empty($ee_cron_details['args'])) {
110
+							do_action('AHEE_log', __CLASS__, __FUNCTION__, print_r($ee_cron_details['args'], true), "$ee_cron args");
111 111
 						}
112 112
 					}
113 113
 				}
@@ -126,13 +126,13 @@  discard block
 block discarded – undo
126 126
 	 * @param array  $TXN_IDs
127 127
 	 * @return bool
128 128
 	 */
129
-	public static function reschedule_cron_for_transactions_if_maintenance_mode( $cron_task, $TXN_IDs ) {
129
+	public static function reschedule_cron_for_transactions_if_maintenance_mode($cron_task, $TXN_IDs) {
130 130
 		// reschedule the cron if we can't hit the db right now
131
-		if ( ! EE_Maintenance_Mode::instance()->models_can_query() ) {
132
-			foreach( $TXN_IDs as $TXN_ID => $some_unused_var ) {
131
+		if ( ! EE_Maintenance_Mode::instance()->models_can_query()) {
132
+			foreach ($TXN_IDs as $TXN_ID => $some_unused_var) {
133 133
 				// reset cron job for finalizing the TXN
134 134
 				EE_Cron_Tasks::$cron_task(
135
-					time() + ( 10 * MINUTE_IN_SECONDS ),
135
+					time() + (10 * MINUTE_IN_SECONDS),
136 136
 					$TXN_ID
137 137
 				);
138 138
 			}
@@ -170,15 +170,15 @@  discard block
 block discarded – undo
170 170
 		$TXN_ID,
171 171
 		$PAY_ID
172 172
 	) {
173
-		do_action( 'AHEE_log', __CLASS__, __FUNCTION__ );
173
+		do_action('AHEE_log', __CLASS__, __FUNCTION__);
174 174
 		// validate $TXN_ID and $timestamp
175
-		$TXN_ID = absint( $TXN_ID );
176
-		$timestamp = absint( $timestamp );
177
-		if ( $TXN_ID && $timestamp ) {
175
+		$TXN_ID = absint($TXN_ID);
176
+		$timestamp = absint($timestamp);
177
+		if ($TXN_ID && $timestamp) {
178 178
 			wp_schedule_single_event(
179 179
 				$timestamp,
180 180
 				'AHEE__EE_Cron_Tasks__update_transaction_with_payment_2',
181
-				array( $TXN_ID, $PAY_ID )
181
+				array($TXN_ID, $PAY_ID)
182 182
 			);
183 183
 		}
184 184
 	}
@@ -200,13 +200,13 @@  discard block
 block discarded – undo
200 200
 	 * @param int  $TXN_ID
201 201
 	 * @param int $PAY_ID
202 202
 	 */
203
-	public static function setup_update_for_transaction_with_payment( $TXN_ID = 0, $PAY_ID = 0 ) {
204
-            do_action( 'AHEE_log', __CLASS__, __FUNCTION__, $TXN_ID, '$TXN_ID' );
205
-		if ( absint( $TXN_ID )) {
206
-			self::$_update_transactions_with_payment[ $TXN_ID ] = $PAY_ID;
203
+	public static function setup_update_for_transaction_with_payment($TXN_ID = 0, $PAY_ID = 0) {
204
+            do_action('AHEE_log', __CLASS__, __FUNCTION__, $TXN_ID, '$TXN_ID');
205
+		if (absint($TXN_ID)) {
206
+			self::$_update_transactions_with_payment[$TXN_ID] = $PAY_ID;
207 207
 			add_action(
208 208
 				'shutdown',
209
-				array( 'EE_Cron_Tasks', 'update_transaction_with_payment' ),
209
+				array('EE_Cron_Tasks', 'update_transaction_with_payment'),
210 210
 				5
211 211
 			);
212 212
 		}
@@ -226,7 +226,7 @@  discard block
 block discarded – undo
226 226
 
227 227
 		if (
228 228
 			// are there any TXNs that need cleaning up ?
229
-			! empty( self::$_update_transactions_with_payment ) &&
229
+			! empty(self::$_update_transactions_with_payment) &&
230 230
 			// reschedule the cron if we can't hit the db right now
231 231
 			! EE_Cron_Tasks::reschedule_cron_for_transactions_if_maintenance_mode(
232 232
 				'schedule_update_transaction_with_payment',
@@ -234,21 +234,21 @@  discard block
 block discarded – undo
234 234
 			)
235 235
 		) {
236 236
 			/** @type EE_Payment_Processor $payment_processor */
237
-			$payment_processor = EE_Registry::instance()->load_core( 'Payment_Processor' );
237
+			$payment_processor = EE_Registry::instance()->load_core('Payment_Processor');
238 238
 			// set revisit flag for payment processor
239
-			$payment_processor->set_revisit( false );
239
+			$payment_processor->set_revisit(false);
240 240
 			// load EEM_Transaction
241
-			EE_Registry::instance()->load_model( 'Transaction' );
242
-			foreach ( self::$_update_transactions_with_payment as $TXN_ID => $PAY_ID ) {
243
-				$transaction = EEM_Transaction::instance()->get_one_by_ID( $TXN_ID );
244
-				$payment = EEM_Payment::instance()->get_one_by_ID( $PAY_ID );
241
+			EE_Registry::instance()->load_model('Transaction');
242
+			foreach (self::$_update_transactions_with_payment as $TXN_ID => $PAY_ID) {
243
+				$transaction = EEM_Transaction::instance()->get_one_by_ID($TXN_ID);
244
+				$payment = EEM_Payment::instance()->get_one_by_ID($PAY_ID);
245 245
 				// verify transaction
246
-				if ( $transaction instanceof EE_Transaction &&
247
-						$payment instanceof EE_Payment ) {
246
+				if ($transaction instanceof EE_Transaction &&
247
+						$payment instanceof EE_Payment) {
248 248
 					// now try to update the TXN with any payments
249
-					$payment_processor->update_txn_based_on_payment( $transaction, $payment, true, true );
249
+					$payment_processor->update_txn_based_on_payment($transaction, $payment, true, true);
250 250
 				}
251
-				unset( self::$_update_transactions_with_payment[ $TXN_ID ] );
251
+				unset(self::$_update_transactions_with_payment[$TXN_ID]);
252 252
 			}
253 253
 		}
254 254
 	}
@@ -285,10 +285,10 @@  discard block
 block discarded – undo
285 285
 		$TXN_ID
286 286
 	) {
287 287
 		// validate $TXN_ID and $timestamp
288
-		$TXN_ID = absint( $TXN_ID );
289
-		$timestamp = absint( $timestamp );
290
-		do_action( 'AHEE_log', __CLASS__, __FUNCTION__, $TXN_ID, '$TXN_ID' );
291
-		if ( $TXN_ID && $timestamp ) {
288
+		$TXN_ID = absint($TXN_ID);
289
+		$timestamp = absint($timestamp);
290
+		do_action('AHEE_log', __CLASS__, __FUNCTION__, $TXN_ID, '$TXN_ID');
291
+		if ($TXN_ID && $timestamp) {
292 292
 			// DEBUG LOG
293 293
 			//EEH_Debug_Tools::log(
294 294
 			//	__CLASS__, __FUNCTION__, __LINE__,
@@ -298,7 +298,7 @@  discard block
 block discarded – undo
298 298
 			wp_schedule_single_event(
299 299
 				$timestamp,
300 300
 				'AHEE__EE_Cron_Tasks__finalize_abandoned_transactions',
301
-				array( $TXN_ID )
301
+				array($TXN_ID)
302 302
 			);
303 303
 		}
304 304
 	}
@@ -320,13 +320,13 @@  discard block
 block discarded – undo
320 320
 	 *
321 321
 	 * @param int $TXN_ID
322 322
 	 */
323
-	public static function check_for_abandoned_transactions(	$TXN_ID = 0 ) {
324
-		do_action( 'AHEE_log', __CLASS__, __FUNCTION__, $TXN_ID, '$TXN_ID' );
325
-		if ( absint( $TXN_ID )) {
326
-			self::$_abandoned_transactions[ $TXN_ID ]  = $TXN_ID;
323
+	public static function check_for_abandoned_transactions($TXN_ID = 0) {
324
+		do_action('AHEE_log', __CLASS__, __FUNCTION__, $TXN_ID, '$TXN_ID');
325
+		if (absint($TXN_ID)) {
326
+			self::$_abandoned_transactions[$TXN_ID] = $TXN_ID;
327 327
 			add_action(
328 328
 				'shutdown',
329
-				array( 'EE_Cron_Tasks', 'finalize_abandoned_transactions' ),
329
+				array('EE_Cron_Tasks', 'finalize_abandoned_transactions'),
330 330
 				5
331 331
 			);
332 332
 		}
@@ -345,7 +345,7 @@  discard block
 block discarded – undo
345 345
 	public static function finalize_abandoned_transactions() {
346 346
 		if (
347 347
 			// are there any TXNs that need cleaning up ?
348
-			! empty( self::$_abandoned_transactions ) &&
348
+			! empty(self::$_abandoned_transactions) &&
349 349
 			// reschedule the cron if we can't hit the db right now
350 350
 			! EE_Cron_Tasks::reschedule_cron_for_transactions_if_maintenance_mode(
351 351
 				'schedule_finalize_abandoned_transactions_check',
@@ -353,33 +353,33 @@  discard block
 block discarded – undo
353 353
 			)
354 354
 		) {
355 355
 			/** @type EE_Transaction_Processor $transaction_processor */
356
-			$transaction_processor = EE_Registry::instance()->load_class( 'Transaction_Processor' );
356
+			$transaction_processor = EE_Registry::instance()->load_class('Transaction_Processor');
357 357
 			// set revisit flag for txn processor
358
-			$transaction_processor->set_revisit( false );
358
+			$transaction_processor->set_revisit(false);
359 359
 			/** @type EE_Payment_Processor $payment_processor */
360
-			$payment_processor = EE_Registry::instance()->load_core( 'Payment_Processor' );
360
+			$payment_processor = EE_Registry::instance()->load_core('Payment_Processor');
361 361
 			// load EEM_Transaction
362
-			EE_Registry::instance()->load_model( 'Transaction' );
363
-			foreach ( self::$_abandoned_transactions as $TXN_ID ) {
362
+			EE_Registry::instance()->load_model('Transaction');
363
+			foreach (self::$_abandoned_transactions as $TXN_ID) {
364 364
 				// DEBUG LOG
365 365
 				//EEH_Debug_Tools::log(
366 366
 				//	__CLASS__, __FUNCTION__, __LINE__,
367 367
 				//	array( '$TXN_ID' => $TXN_ID ),
368 368
 				//	false, 'EE_Transaction: ' . $TXN_ID
369 369
 				//);
370
-				do_action( 'AHEE_log', __CLASS__, __FUNCTION__, $TXN_ID, '$TXN_ID' );
371
-				$transaction = EEM_Transaction::instance()->get_one_by_ID( $TXN_ID );
370
+				do_action('AHEE_log', __CLASS__, __FUNCTION__, $TXN_ID, '$TXN_ID');
371
+				$transaction = EEM_Transaction::instance()->get_one_by_ID($TXN_ID);
372 372
 				// verify transaction
373
-				if ( $transaction instanceof EE_Transaction ) {
373
+				if ($transaction instanceof EE_Transaction) {
374 374
 					// don't finalize the TXN if it has already been completed
375
-					if ( $transaction_processor->all_reg_steps_completed( $transaction ) === true ) {
375
+					if ($transaction_processor->all_reg_steps_completed($transaction) === true) {
376 376
 						continue;
377 377
 					}
378 378
 					// let's simulate an IPN here which will trigger any notifications that need to go out
379
-					$payment_processor->update_txn_based_on_payment( $transaction, $transaction->last_payment(), true, true );
380
-					do_action( 'AHEE__EE_Cron_Tasks__finalize_abandoned_transactions__abandoned_transaction', $transaction );
379
+					$payment_processor->update_txn_based_on_payment($transaction, $transaction->last_payment(), true, true);
380
+					do_action('AHEE__EE_Cron_Tasks__finalize_abandoned_transactions__abandoned_transaction', $transaction);
381 381
 				}
382
-				unset( self::$_abandoned_transactions[ $TXN_ID ] );
382
+				unset(self::$_abandoned_transactions[$TXN_ID]);
383 383
 			}
384 384
 		}
385 385
 	}
@@ -413,13 +413,13 @@  discard block
 block discarded – undo
413 413
 		$TXN_ID
414 414
 	) {
415 415
 		// validate $TXN_ID and $timestamp
416
-		$TXN_ID = absint( $TXN_ID );
417
-		$timestamp = absint( $timestamp );
418
-		if ( $TXN_ID && $timestamp ) {
416
+		$TXN_ID = absint($TXN_ID);
417
+		$timestamp = absint($timestamp);
418
+		if ($TXN_ID && $timestamp) {
419 419
 			wp_schedule_single_event(
420 420
 				$timestamp,
421 421
 				'AHEE__EE_Cron_Tasks__expired_transaction_check',
422
-				array( $TXN_ID )
422
+				array($TXN_ID)
423 423
 			);
424 424
 		}
425 425
 	}
@@ -441,12 +441,12 @@  discard block
 block discarded – undo
441 441
 	 *
442 442
 	 * @param int $TXN_ID
443 443
 	 */
444
-	public static function expired_transaction_check(	$TXN_ID = 0 ) {
445
-		if ( absint( $TXN_ID )) {
446
-			self::$_expired_transactions[ $TXN_ID ]  = $TXN_ID;
444
+	public static function expired_transaction_check($TXN_ID = 0) {
445
+		if (absint($TXN_ID)) {
446
+			self::$_expired_transactions[$TXN_ID] = $TXN_ID;
447 447
 			add_action(
448 448
 				'shutdown',
449
-				array( 'EE_Cron_Tasks', 'process_expired_transactions' ),
449
+				array('EE_Cron_Tasks', 'process_expired_transactions'),
450 450
 				5
451 451
 			);
452 452
 		}
@@ -462,7 +462,7 @@  discard block
 block discarded – undo
462 462
 	public static function process_expired_transactions() {
463 463
 		if (
464 464
 			// are there any TXNs that need cleaning up ?
465
-			! empty( self::$_expired_transactions ) &&
465
+			! empty(self::$_expired_transactions) &&
466 466
 			// reschedule the cron if we can't hit the db right now
467 467
 			! EE_Cron_Tasks::reschedule_cron_for_transactions_if_maintenance_mode(
468 468
 				'schedule_expired_transaction_check',
@@ -470,33 +470,33 @@  discard block
 block discarded – undo
470 470
 			)
471 471
 		) {
472 472
 			/** @type EE_Transaction_Processor $transaction_processor */
473
-			$transaction_processor = EE_Registry::instance()->load_class( 'Transaction_Processor' );
473
+			$transaction_processor = EE_Registry::instance()->load_class('Transaction_Processor');
474 474
 			// set revisit flag for txn processor
475
-			$transaction_processor->set_revisit( false );
475
+			$transaction_processor->set_revisit(false);
476 476
 			 // load EEM_Transaction
477
-			EE_Registry::instance()->load_model( 'Transaction' );
478
-			foreach ( self::$_expired_transactions as $TXN_ID ) {
479
-				$transaction = EEM_Transaction::instance()->get_one_by_ID( $TXN_ID );
477
+			EE_Registry::instance()->load_model('Transaction');
478
+			foreach (self::$_expired_transactions as $TXN_ID) {
479
+				$transaction = EEM_Transaction::instance()->get_one_by_ID($TXN_ID);
480 480
 				// verify transaction and whether it is failed or not
481
-				if ( $transaction instanceof EE_Transaction) {
482
-					switch( $transaction->status_ID() ) {
481
+				if ($transaction instanceof EE_Transaction) {
482
+					switch ($transaction->status_ID()) {
483 483
 						// Completed TXNs
484 484
 						case EEM_Transaction::complete_status_code :
485
-							do_action( 'AHEE__EE_Cron_Tasks__process_expired_transactions__completed_transaction', $transaction );
485
+							do_action('AHEE__EE_Cron_Tasks__process_expired_transactions__completed_transaction', $transaction);
486 486
 							break;
487 487
 						// Overpaid TXNs
488 488
 						case EEM_Transaction::overpaid_status_code :
489
-							do_action( 'AHEE__EE_Cron_Tasks__process_expired_transactions__overpaid_transaction', $transaction );
489
+							do_action('AHEE__EE_Cron_Tasks__process_expired_transactions__overpaid_transaction', $transaction);
490 490
 							break;
491 491
 						// Incomplete TXNs
492 492
 						case EEM_Transaction::incomplete_status_code :
493
-							do_action( 'AHEE__EE_Cron_Tasks__process_expired_transactions__incomplete_transaction', $transaction );
493
+							do_action('AHEE__EE_Cron_Tasks__process_expired_transactions__incomplete_transaction', $transaction);
494 494
 							// todo : merge the finalize_abandoned_transactions cron into this one...
495 495
 							// todo : move business logic into EE_Transaction_Processor for finalizing abandoned transactions
496 496
 							break;
497 497
 						// Failed TXNs
498 498
 						case EEM_Transaction::failed_status_code :
499
-							do_action( 'AHEE__EE_Cron_Tasks__process_expired_transactions__failed_transaction', $transaction );
499
+							do_action('AHEE__EE_Cron_Tasks__process_expired_transactions__failed_transaction', $transaction);
500 500
 							// todo : perform garbage collection here and remove clean_out_junk_transactions()
501 501
 							//$registrations = $transaction->registrations();
502 502
 							//if ( ! empty( $registrations ) ) {
@@ -517,7 +517,7 @@  discard block
 block discarded – undo
517 517
 					}
518 518
 
519 519
 				}
520
-				unset( self::$_expired_transactions[ $TXN_ID ] );
520
+				unset(self::$_expired_transactions[$TXN_ID]);
521 521
 			}
522 522
 		}
523 523
 	}
@@ -531,7 +531,7 @@  discard block
 block discarded – undo
531 531
 	//when a transaction is initially made, schedule this check.
532 532
 	//if it has NO REG data by the time it has expired, forget about it
533 533
 	public static function clean_out_junk_transactions() {
534
-		if( EE_Maintenance_Mode::instance()->models_can_query() ) {
534
+		if (EE_Maintenance_Mode::instance()->models_can_query()) {
535 535
 			EEM_Transaction::instance('')->delete_junk_transactions();
536 536
 			EEM_Registration::instance('')->delete_registrations_with_no_transaction();
537 537
 			EEM_Line_Item::instance('')->delete_line_items_with_no_transaction();
Please login to merge, or discard this patch.
core/db_models/EEM_Base.model.php 1 patch
Spacing   +960 added lines, -960 removed lines patch added patch discarded remove patch
@@ -23,7 +23,7 @@  discard block
 block discarded – undo
23 23
  * @since 				EE4
24 24
  *
25 25
  */
26
-abstract class EEM_Base extends EE_Base{
26
+abstract class EEM_Base extends EE_Base {
27 27
 
28 28
 	//admin posty
29 29
 	//basic -> grants access to mine -> if they don't have it, select none
@@ -235,7 +235,7 @@  discard block
 block discarded – undo
235 235
 	 * Flag indicating whether this model has a primary key or not
236 236
 	 * @var boolean
237 237
 	 */
238
-	protected $_has_primary_key_field=null;
238
+	protected $_has_primary_key_field = null;
239 239
 
240 240
 	/**
241 241
 	 * Whether or not this model is based off a table in WP core only (CPTs should set
@@ -297,19 +297,19 @@  discard block
 block discarded – undo
297 297
 	 * operators that work like 'BETWEEN'.  Typically used for datetime calculations, i.e. "BETWEEN '12-1-2011' AND '12-31-2012'"
298 298
 	 * @var array
299 299
 	 */
300
-	protected $_between_style_operators = array( 'BETWEEN' );
300
+	protected $_between_style_operators = array('BETWEEN');
301 301
 
302 302
 	/**
303 303
 	 * operators that are used for handling NUll and !NULL queries.  Typically used for when checking if a row exists on a join table.
304 304
 	 * @var array
305 305
 	 */
306
-	protected $_null_style_operators = array( 'IS NOT NULL', 'IS NULL');
306
+	protected $_null_style_operators = array('IS NOT NULL', 'IS NULL');
307 307
 
308 308
 	/**
309 309
 	 * Allowed values for $query_params['order'] for ordering in queries
310 310
 	 * @var array
311 311
 	 */
312
-	protected $_allowed_order_values = array('asc','desc','ASC','DESC');
312
+	protected $_allowed_order_values = array('asc', 'desc', 'ASC', 'DESC');
313 313
 
314 314
 	/**
315 315
 	 * When these are keys in a WHERE or HAVING clause, they are handled much differently
@@ -323,13 +323,13 @@  discard block
 block discarded – undo
323 323
 	 * 'where', but 'where' clauses are so common that we thought we'd omit it
324 324
 	 * @var array
325 325
 	 */
326
-	private $_allowed_query_params = array(0, 'limit','order_by','group_by','having','force_join','order','on_join_limit','default_where_conditions', 'caps');
326
+	private $_allowed_query_params = array(0, 'limit', 'order_by', 'group_by', 'having', 'force_join', 'order', 'on_join_limit', 'default_where_conditions', 'caps');
327 327
 
328 328
 	/**
329 329
 	 * All the data types that can be used in $wpdb->prepare statements.
330 330
 	 * @var array
331 331
 	 */
332
-	private $_valid_wpdb_data_types = array('%d','%s','%f');
332
+	private $_valid_wpdb_data_types = array('%d', '%s', '%f');
333 333
 
334 334
 	/**
335 335
 	 * 	EE_Registry Object
@@ -362,17 +362,17 @@  discard block
 block discarded – undo
362 362
 	/**
363 363
 	 * constant used to show EEM_Base has not yet verified the db on this http request
364 364
 	 */
365
-	const db_verified_none 		= 0;
365
+	const db_verified_none = 0;
366 366
 	/**
367 367
 	 * constant used to show EEM_Base has verified the EE core db on this http request,
368 368
 	 * but not the addons' dbs
369 369
 	 */
370
-	const db_verified_core 		= 1;
370
+	const db_verified_core = 1;
371 371
 	/**
372 372
 	 * constant used to show EEM_Base has verified the addons' dbs (and implicitly
373 373
 	 * the EE core db too)
374 374
 	 */
375
-	const db_verified_addons 	= 2;
375
+	const db_verified_addons = 2;
376 376
 
377 377
 	/**
378 378
 	 * indicates whether an EEM_Base child has already re-verified the DB
@@ -403,13 +403,13 @@  discard block
 block discarded – undo
403 403
 	 * @param null $timezone
404 404
 	 * @throws \EE_Error
405 405
 	 */
406
-	protected function __construct( $timezone = NULL ){
406
+	protected function __construct($timezone = NULL) {
407 407
 		// check that the model has not been loaded too soon
408
-		if ( ! did_action( 'AHEE__EE_System__load_espresso_addons' )) {
409
-			throw new EE_Error (
408
+		if ( ! did_action('AHEE__EE_System__load_espresso_addons')) {
409
+			throw new EE_Error(
410 410
 				sprintf(
411
-					__( 'The %1$s model can not be loaded before the "AHEE__EE_System__load_espresso_addons" hook has been called. This gives other addons a chance to extend this model.', 'event_espresso' ),
412
-					get_class( $this )
411
+					__('The %1$s model can not be loaded before the "AHEE__EE_System__load_espresso_addons" hook has been called. This gives other addons a chance to extend this model.', 'event_espresso'),
412
+					get_class($this)
413 413
 				)
414 414
 			);
415 415
 		}
@@ -419,11 +419,11 @@  discard block
 block discarded – undo
419 419
 		 * just use EE_Register_Model_Extension
420 420
 		 * @var EE_Table_Base[] $_tables
421 421
 		 */
422
-		$this->_tables = apply_filters( 'FHEE__'.get_class($this).'__construct__tables', $this->_tables );
423
-		foreach($this->_tables as $table_alias => $table_obj){
422
+		$this->_tables = apply_filters('FHEE__'.get_class($this).'__construct__tables', $this->_tables);
423
+		foreach ($this->_tables as $table_alias => $table_obj) {
424 424
 			/** @var $table_obj EE_Table_Base */
425 425
 			$table_obj->_construct_finalize_with_alias($table_alias);
426
-			if( $table_obj instanceof EE_Secondary_Table ){
426
+			if ($table_obj instanceof EE_Secondary_Table) {
427 427
 				/** @var $table_obj EE_Secondary_Table */
428 428
 				$table_obj->_construct_finalize_set_table_to_join_with($this->_get_main_table());
429 429
 			}
@@ -433,54 +433,54 @@  discard block
 block discarded – undo
433 433
 		 * EE_Register_Model_Extension
434 434
 		 * @param EE_Model_Field_Base[] $_fields
435 435
 		 */
436
-		$this->_fields = apply_filters('FHEE__'.get_class($this).'__construct__fields',$this->_fields);
436
+		$this->_fields = apply_filters('FHEE__'.get_class($this).'__construct__fields', $this->_fields);
437 437
 		$this->_invalidate_field_caches();
438
-		foreach($this->_fields as $table_alias => $fields_for_table){
439
-			if ( ! array_key_exists( $table_alias, $this->_tables )){
440
-				throw new EE_Error(sprintf(__("Table alias %s does not exist in EEM_Base child's _tables array. Only tables defined are %s",'event_espresso'),$table_alias,implode(",",$this->_fields)));
438
+		foreach ($this->_fields as $table_alias => $fields_for_table) {
439
+			if ( ! array_key_exists($table_alias, $this->_tables)) {
440
+				throw new EE_Error(sprintf(__("Table alias %s does not exist in EEM_Base child's _tables array. Only tables defined are %s", 'event_espresso'), $table_alias, implode(",", $this->_fields)));
441 441
 			}
442
-			foreach($fields_for_table as $field_name => $field_obj){
442
+			foreach ($fields_for_table as $field_name => $field_obj) {
443 443
 				/** @var $field_obj EE_Model_Field_Base | EE_Primary_Key_Field_Base */
444 444
 				//primary key field base has a slightly different _construct_finalize
445 445
 				/** @var $field_obj EE_Model_Field_Base */
446
-				$field_obj->_construct_finalize( $table_alias, $field_name, $this->get_this_model_name() );
446
+				$field_obj->_construct_finalize($table_alias, $field_name, $this->get_this_model_name());
447 447
 			}
448 448
 		}
449 449
 
450 450
 		// everything is related to Extra_Meta
451
-		if( get_class($this) != 'EEM_Extra_Meta'){
451
+		if (get_class($this) != 'EEM_Extra_Meta') {
452 452
 			//make extra meta related to everything, but don't block deleting things just
453 453
 			//because they have related extra meta info. For now just orphan those extra meta
454 454
 			//in the future we should automatically delete them
455
-			$this->_model_relations['Extra_Meta'] = new EE_Has_Many_Any_Relation( FALSE );
455
+			$this->_model_relations['Extra_Meta'] = new EE_Has_Many_Any_Relation(FALSE);
456 456
 		}
457 457
 		//and change logs
458
-		if( get_class( $this) !=  'EEM_Change_Log' ) {
459
-			$this->_model_relations[ 'Change_Log' ] = new EE_Has_Many_Any_Relation( FALSE );
458
+		if (get_class($this) != 'EEM_Change_Log') {
459
+			$this->_model_relations['Change_Log'] = new EE_Has_Many_Any_Relation(FALSE);
460 460
 		}
461 461
 		/**
462 462
 		 * Filters the list of relations on a model. It is best to NOT use this directly and instead just use
463 463
 		 * EE_Register_Model_Extension
464 464
 		 * @param EE_Model_Relation_Base[] $_model_relations
465 465
 		 */
466
-		$this->_model_relations = apply_filters('FHEE__'.get_class($this).'__construct__model_relations',$this->_model_relations);
467
-		foreach($this->_model_relations as $model_name => $relation_obj){
466
+		$this->_model_relations = apply_filters('FHEE__'.get_class($this).'__construct__model_relations', $this->_model_relations);
467
+		foreach ($this->_model_relations as $model_name => $relation_obj) {
468 468
 			/** @var $relation_obj EE_Model_Relation_Base */
469 469
 			$relation_obj->_construct_finalize_set_models($this->get_this_model_name(), $model_name);
470 470
 		}
471
-		foreach($this->_indexes as $index_name => $index_obj){
471
+		foreach ($this->_indexes as $index_name => $index_obj) {
472 472
 			/** @var $index_obj EE_Index */
473 473
 			$index_obj->_construct_finalize($index_name, $this->get_this_model_name());
474 474
 		}
475 475
 
476 476
 		$this->set_timezone($timezone);
477 477
 		//finalize default where condition strategy, or set default
478
-		if( ! $this->_default_where_conditions_strategy){
478
+		if ( ! $this->_default_where_conditions_strategy) {
479 479
 			//nothing was set during child constructor, so set default
480 480
 			$this->_default_where_conditions_strategy = new EE_Default_Where_Conditions();
481 481
 		}
482 482
 		$this->_default_where_conditions_strategy->_finalize_construct($this);
483
-		if( ! $this->_minimum_where_conditions_strategy){
483
+		if ( ! $this->_minimum_where_conditions_strategy) {
484 484
 			//nothing was set during child constructor, so set default
485 485
 			$this->_minimum_where_conditions_strategy = new EE_Default_Where_Conditions();
486 486
 		}
@@ -488,15 +488,15 @@  discard block
 block discarded – undo
488 488
 
489 489
 		//if the cap slug hasn't been set, and we haven't set it to false on purpose
490 490
 		//to indicate to NOT set it, set it to the logical default
491
-		if( $this->_caps_slug === null ) {
492
-			EE_Registry::instance()->load_helper( 'Inflector' );
493
-			$this->_caps_slug = EEH_Inflector::pluralize_and_lower( $this->get_this_model_name() );
491
+		if ($this->_caps_slug === null) {
492
+			EE_Registry::instance()->load_helper('Inflector');
493
+			$this->_caps_slug = EEH_Inflector::pluralize_and_lower($this->get_this_model_name());
494 494
 		}
495 495
 		//initialize the standard cap restriction generators if none were specified by the child constructor
496
-		if( $this->_cap_restriction_generators !== false ){
497
-			foreach( $this->cap_contexts_to_cap_action_map() as $cap_context => $action ){
498
-				if( ! isset( $this->_cap_restriction_generators[ $cap_context ] ) ) {
499
-					$this->_cap_restriction_generators[ $cap_context ] = apply_filters(
496
+		if ($this->_cap_restriction_generators !== false) {
497
+			foreach ($this->cap_contexts_to_cap_action_map() as $cap_context => $action) {
498
+				if ( ! isset($this->_cap_restriction_generators[$cap_context])) {
499
+					$this->_cap_restriction_generators[$cap_context] = apply_filters(
500 500
 						'FHEE__EEM_Base___construct__standard_cap_restriction_generator',
501 501
 						new EE_Restriction_Generator_Protected(),
502 502
 						$cap_context,
@@ -506,23 +506,23 @@  discard block
 block discarded – undo
506 506
 			}
507 507
 		}
508 508
 		//if there are cap restriction generators, use them to make the default cap restrictions
509
-		if( $this->_cap_restriction_generators !== false ){
510
-			foreach( $this->_cap_restriction_generators as $context => $generator_object ) {
511
-				if( ! $generator_object ){
509
+		if ($this->_cap_restriction_generators !== false) {
510
+			foreach ($this->_cap_restriction_generators as $context => $generator_object) {
511
+				if ( ! $generator_object) {
512 512
 					continue;
513 513
 				}
514
-				if( ! $generator_object instanceof EE_Restriction_Generator_Base ){
514
+				if ( ! $generator_object instanceof EE_Restriction_Generator_Base) {
515 515
 					throw new EE_Error(
516 516
 						sprintf(
517
-							__( 'Index "%1$s" in the model %2$s\'s _cap_restriction_generators is not a child of EE_Restriction_Generator_Base. It should be that or NULL.', 'event_espresso' ),
517
+							__('Index "%1$s" in the model %2$s\'s _cap_restriction_generators is not a child of EE_Restriction_Generator_Base. It should be that or NULL.', 'event_espresso'),
518 518
 							$context,
519 519
 							$this->get_this_model_name()
520 520
 						)
521 521
 					);
522 522
 				}
523
-				$action = $this->cap_action_for_context( $context );
524
-				if( ! $generator_object->construction_finalized() ){
525
-					$generator_object->_construct_finalize( $this, $action );
523
+				$action = $this->cap_action_for_context($context);
524
+				if ( ! $generator_object->construction_finalized()) {
525
+					$generator_object->_construct_finalize($this, $action);
526 526
 				}
527 527
 
528 528
 			}
@@ -536,11 +536,11 @@  discard block
 block discarded – undo
536 536
 	 * @param string $context one of EEM_Base::valid_cap_contexts()
537 537
 	 * @return EE_Default_Where_Conditions[]
538 538
 	 */
539
-	protected function _generate_cap_restrictions( $context ){
540
-		if( isset( $this->_cap_restriction_generators[ $context ] ) &&
541
-				$this->_cap_restriction_generators[ $context ] instanceof EE_Restriction_Generator_Base ) {
542
-			return $this->_cap_restriction_generators[ $context ]->generate_restrictions();
543
-		}else{
539
+	protected function _generate_cap_restrictions($context) {
540
+		if (isset($this->_cap_restriction_generators[$context]) &&
541
+				$this->_cap_restriction_generators[$context] instanceof EE_Restriction_Generator_Base) {
542
+			return $this->_cap_restriction_generators[$context]->generate_restrictions();
543
+		} else {
544 544
 			return array();
545 545
 		}
546 546
 }
@@ -553,16 +553,16 @@  discard block
 block discarded – undo
553 553
 	 *		@param string $timezone string representing the timezone we want to set for returned Date Time Strings (and any incoming timezone data that gets saved).  Note this just sends the timezone info to the date time model field objects.  Default is NULL (and will be assumed using the set timezone in the 'timezone_string' wp option)
554 554
 	 *		@return static (as in the concrete child class)
555 555
 	 */
556
-	public static function instance( $timezone = NULL ){
556
+	public static function instance($timezone = NULL) {
557 557
 
558 558
 		// check if instance of Espresso_model already exists
559 559
 		if ( ! static::$_instance instanceof static) {
560 560
 			// instantiate Espresso_model
561
-			static::$_instance = new static( $timezone );
561
+			static::$_instance = new static($timezone);
562 562
 		}
563 563
 
564 564
 		//we might have a timezone set, let set_timezone decide what to do with it
565
-		static::$_instance->set_timezone( $timezone );
565
+		static::$_instance->set_timezone($timezone);
566 566
 
567 567
 		// Espresso_model object
568 568
 		return static::$_instance;
@@ -575,11 +575,11 @@  discard block
 block discarded – undo
575 575
 	 * @param null | string $timezone
576 576
 	 * @return static
577 577
 	 */
578
-	public static function reset(  $timezone = NULL ){
579
-		if ( ! is_null( static::$_instance ) ) {
578
+	public static function reset($timezone = NULL) {
579
+		if ( ! is_null(static::$_instance)) {
580 580
 			static::$_instance = null;
581 581
 
582
-			return self::instance( $timezone );
582
+			return self::instance($timezone);
583 583
 		}
584 584
 		return null;
585 585
 	}
@@ -590,15 +590,15 @@  discard block
 block discarded – undo
590 590
 	 * @param  boolean $translated return localized strings or JUST the array.
591 591
 	 * @return array
592 592
 	 */
593
-	 public function status_array( $translated = FALSE ) {
594
-	 	if ( !array_key_exists('Status', $this->_model_relations ) )
593
+	 public function status_array($translated = FALSE) {
594
+	 	if ( ! array_key_exists('Status', $this->_model_relations))
595 595
 	 		return array();
596 596
 	 	$model_name = $this->get_this_model_name();
597
-	 	$status_type = str_replace(' ', '_', strtolower( str_replace('_', ' ', $model_name) ) );
598
-	 	$stati = EEM_Status::instance()->get_all(array(array('STS_type' => $status_type) ) );
597
+	 	$status_type = str_replace(' ', '_', strtolower(str_replace('_', ' ', $model_name)));
598
+	 	$stati = EEM_Status::instance()->get_all(array(array('STS_type' => $status_type)));
599 599
 	 	$status_array = array();
600
-	 	foreach ( $stati as $status ) {
601
-            $status_array[ $status->ID() ] = $status->get('STS_code');
600
+	 	foreach ($stati as $status) {
601
+            $status_array[$status->ID()] = $status->get('STS_code');
602 602
         }
603 603
         return $translated ? EEM_Status::instance()->localized_status($status_array, FALSE, 'sentence') : $status_array;
604 604
     }
@@ -740,10 +740,10 @@  discard block
 block discarded – undo
740 740
 	 *			'order_by'=>array('ANS_value'=>'ASC')
741 741
 	 *		));
742 742
 	 */
743
-	function get_all($query_params = array()){
744
-		if( isset( $query_params[ 'limit' ] )
745
-			&& ! isset( $query_params[ 'group_by' ] ) ) {
746
-			$query_params[ 'group_by' ] = array_keys( $this->get_combined_primary_key_fields() );
743
+	function get_all($query_params = array()) {
744
+		if (isset($query_params['limit'])
745
+			&& ! isset($query_params['group_by'])) {
746
+			$query_params['group_by'] = array_keys($this->get_combined_primary_key_fields());
747 747
 		}
748 748
 		return $this->_create_objects($this->_get_all_wpdb_results($query_params, ARRAY_A, NULL));
749 749
 	}
@@ -754,10 +754,10 @@  discard block
 block discarded – undo
754 754
 	 * @param array $query_params @see EEM_Base::get_all()
755 755
 	 * @return array like EEM_Base::get_all
756 756
 	 */
757
-	function alter_query_params_to_only_include_mine( $query_params = array() ) {
757
+	function alter_query_params_to_only_include_mine($query_params = array()) {
758 758
 		$wp_user_field_name = $this->wp_user_field_name();
759
-		if( $wp_user_field_name ){
760
-			$query_params[0][ $wp_user_field_name ] = get_current_user_id();
759
+		if ($wp_user_field_name) {
760
+			$query_params[0][$wp_user_field_name] = get_current_user_id();
761 761
 		}
762 762
 		return $query_params;
763 763
 	}
@@ -770,19 +770,19 @@  discard block
 block discarded – undo
770 770
 	 * foreign key to the WP_User table
771 771
 	 */
772 772
 	function wp_user_field_name() {
773
-		try{
774
-			if( ! empty( $this->_model_chain_to_wp_user ) ) {
775
-				$models_to_follow_to_wp_users = explode( '.', $this->_model_chain_to_wp_user );
776
-				$last_model_name = end( $models_to_follow_to_wp_users );
777
-				$model_with_fk_to_wp_users = EE_Registry::instance()->load_model( $last_model_name );
778
-				$model_chain_to_wp_user = $this->_model_chain_to_wp_user . '.';
779
-			}else{
773
+		try {
774
+			if ( ! empty($this->_model_chain_to_wp_user)) {
775
+				$models_to_follow_to_wp_users = explode('.', $this->_model_chain_to_wp_user);
776
+				$last_model_name = end($models_to_follow_to_wp_users);
777
+				$model_with_fk_to_wp_users = EE_Registry::instance()->load_model($last_model_name);
778
+				$model_chain_to_wp_user = $this->_model_chain_to_wp_user.'.';
779
+			} else {
780 780
 				$model_with_fk_to_wp_users = $this;
781 781
 				$model_chain_to_wp_user = '';
782 782
 			}
783
-			$wp_user_field = $model_with_fk_to_wp_users->get_foreign_key_to( 'WP_User' );
784
-			return $model_chain_to_wp_user . $wp_user_field->get_name();
785
-		}catch( EE_Error $e ) {
783
+			$wp_user_field = $model_with_fk_to_wp_users->get_foreign_key_to('WP_User');
784
+			return $model_chain_to_wp_user.$wp_user_field->get_name();
785
+		} catch (EE_Error $e) {
786 786
 			return false;
787 787
 		}
788 788
 	}
@@ -796,7 +796,7 @@  discard block
 block discarded – undo
796 796
 	 * (or transiently-related model)
797 797
 	 * @return string
798 798
 	 */
799
-	public function model_chain_to_wp_user(){
799
+	public function model_chain_to_wp_user() {
800 800
 		return $this->_model_chain_to_wp_user;
801 801
 	}
802 802
 
@@ -808,13 +808,13 @@  discard block
 block discarded – undo
808 808
 	 * @return boolean
809 809
 	 */
810 810
 	public function is_owned() {
811
-		if( $this->model_chain_to_wp_user() ){
811
+		if ($this->model_chain_to_wp_user()) {
812 812
 			return true;
813
-		}else{
814
-			try{
815
-				$this->get_foreign_key_to( 'WP_User' );
813
+		} else {
814
+			try {
815
+				$this->get_foreign_key_to('WP_User');
816 816
 				return true;
817
-			}catch( EE_Error $e ){
817
+			} catch (EE_Error $e) {
818 818
 				return false;
819 819
 			}
820 820
 		}
@@ -833,21 +833,21 @@  discard block
 block discarded – undo
833 833
 	 * and 1 is the data type. Eg, array('count'=>array('COUNT(REG_ID)','%d'))
834 834
 	 * @return array | stdClass[] like results of $wpdb->get_results($sql,OBJECT), (ie, output type is OBJECT)
835 835
 	 */
836
-	protected function  _get_all_wpdb_results($query_params = array(), $output = ARRAY_A, $columns_to_select = null){
836
+	protected function  _get_all_wpdb_results($query_params = array(), $output = ARRAY_A, $columns_to_select = null) {
837 837
 		//remember the custom selections, if any
838
-		if(is_array($columns_to_select)){
838
+		if (is_array($columns_to_select)) {
839 839
 			$this->_custom_selections = $columns_to_select;
840
-		}elseif(is_string($columns_to_select)){
840
+		}elseif (is_string($columns_to_select)) {
841 841
 			$this->_custom_selections = array($this->_custom_selections);
842
-		}else{
842
+		} else {
843 843
 			$this->_custom_selections = array();
844 844
 		}
845 845
 
846 846
 		$model_query_info = $this->_create_model_query_info_carrier($query_params);
847 847
 		$select_expressions = $columns_to_select ? $this->_construct_select_from_input($columns_to_select) : $this->_construct_default_select_sql($model_query_info);
848
-		$SQL ="SELECT $select_expressions ".$this->_construct_2nd_half_of_select_query($model_query_info);
848
+		$SQL = "SELECT $select_expressions ".$this->_construct_2nd_half_of_select_query($model_query_info);
849 849
 //		echo "sql:$SQL";
850
-		$results =  $this->_do_wpdb_query( 'get_results', array($SQL, $output ) );// $wpdb->get_results($SQL, $output);
850
+		$results = $this->_do_wpdb_query('get_results', array($SQL, $output)); // $wpdb->get_results($SQL, $output);
851 851
 		return $results;
852 852
 	}
853 853
 
@@ -865,7 +865,7 @@  discard block
 block discarded – undo
865 865
 	 * and 1 is the data type. Eg, array('count'=>array('COUNT(REG_ID)','%d'))
866 866
 	 * @return array|stdClass[] like results of $wpdb->get_results($sql,OBJECT), (ie, output type is OBJECT)
867 867
 	 */
868
-	public function  get_all_wpdb_results($query_params = array(), $output = ARRAY_A, $columns_to_select = null){
868
+	public function  get_all_wpdb_results($query_params = array(), $output = ARRAY_A, $columns_to_select = null) {
869 869
 		return $this->_get_all_wpdb_results($query_params, $output, $columns_to_select);
870 870
 	}
871 871
 
@@ -877,12 +877,12 @@  discard block
 block discarded – undo
877 877
 	 * @throws EE_Error
878 878
 	 * @return string
879 879
 	 */
880
-	private function _construct_select_from_input($columns_to_select){
881
-		if(is_array($columns_to_select)){
880
+	private function _construct_select_from_input($columns_to_select) {
881
+		if (is_array($columns_to_select)) {
882 882
 			$select_sql_array = array();
883 883
 
884
-			foreach($columns_to_select as $alias => $selection_and_datatype){
885
-				if( ! is_array($selection_and_datatype) || ! isset($selection_and_datatype[1])){
884
+			foreach ($columns_to_select as $alias => $selection_and_datatype) {
885
+				if ( ! is_array($selection_and_datatype) || ! isset($selection_and_datatype[1])) {
886 886
 					throw new EE_Error(
887 887
 						sprintf(
888 888
 							__(
@@ -894,24 +894,24 @@  discard block
 block discarded – undo
894 894
 						)
895 895
 					);
896 896
 				}
897
-				if( ! in_array( $selection_and_datatype[1],$this->_valid_wpdb_data_types)){
897
+				if ( ! in_array($selection_and_datatype[1], $this->_valid_wpdb_data_types)) {
898 898
 					throw new EE_Error(
899 899
 						sprintf(
900 900
 							__(
901 901
 								"Datatype %s (for selection '%s' and alias '%s') is not a valid wpdb datatype (eg %%s)",
902 902
 								"event_espresso"
903 903
 							),
904
-							$selection_and_datatype[ 1 ],
905
-							$selection_and_datatype[ 0 ],
904
+							$selection_and_datatype[1],
905
+							$selection_and_datatype[0],
906 906
 							$alias,
907
-							implode( ",", $this->_valid_wpdb_data_types )
907
+							implode(",", $this->_valid_wpdb_data_types)
908 908
 						)
909 909
 					);
910 910
 				}
911 911
 				$select_sql_array[] = "{$selection_and_datatype[0]} AS $alias";
912 912
 			}
913
-			$columns_to_select_string = implode(", ",$select_sql_array);
914
-		}else{
913
+			$columns_to_select_string = implode(", ", $select_sql_array);
914
+		} else {
915 915
 			$columns_to_select_string = $columns_to_select;
916 916
 		}
917 917
 		return $columns_to_select_string;
@@ -924,7 +924,7 @@  discard block
 block discarded – undo
924 924
 	 * Convenient wrapper for getting the primary key field's name. Eg, on Registration, this would be 'REG_ID'
925 925
 	 * @return string
926 926
 	 */
927
-	function primary_key_name(){
927
+	function primary_key_name() {
928 928
 		return $this->get_primary_key_field()->get_name();
929 929
 	}
930 930
 
@@ -936,14 +936,14 @@  discard block
 block discarded – undo
936 936
 	 * @param mixed $id int or string, depending on the type of the model's primary key
937 937
 	 * @return EE_Base_Class
938 938
 	 */
939
-	function get_one_by_ID($id){
940
-		if( $this->get_from_entity_map( $id ) ){
941
-			return $this->get_from_entity_map( $id );
939
+	function get_one_by_ID($id) {
940
+		if ($this->get_from_entity_map($id)) {
941
+			return $this->get_from_entity_map($id);
942 942
 		}
943 943
 		return $this->get_one(
944 944
 			$this->alter_query_params_to_restrict_by_ID(
945 945
 				$id,
946
-				array( 'default_where_conditions' => 'minimum' )
946
+				array('default_where_conditions' => 'minimum')
947 947
 			)
948 948
 		);
949 949
 	}
@@ -955,15 +955,15 @@  discard block
 block discarded – undo
955 955
 	 * @param array $query_params
956 956
 	 * @return array of normal query params, @see EEM_Base::get_all
957 957
 	 */
958
-	public function alter_query_params_to_restrict_by_ID( $id, $query_params = array() ) {
959
-		if( ! isset( $query_params[ 0 ] ) ) {
960
-			$query_params[ 0 ] = array();
958
+	public function alter_query_params_to_restrict_by_ID($id, $query_params = array()) {
959
+		if ( ! isset($query_params[0])) {
960
+			$query_params[0] = array();
961 961
 		}
962
-		if( $this->has_primary_key_field ( ) ) {
963
-			$query_params[ 0 ][ $this->primary_key_name() ] = $id ;
964
-		}else{
962
+		if ($this->has_primary_key_field( )) {
963
+			$query_params[0][$this->primary_key_name()] = $id;
964
+		} else {
965 965
 			//no primary key, so the $id must be from the get_index_primary_key_string()
966
-			$query_params[0] = array_replace_recursive( $query_params[ 0 ], $this->parse_index_primary_key_string( $id ) );
966
+			$query_params[0] = array_replace_recursive($query_params[0], $this->parse_index_primary_key_string($id));
967 967
 		}
968 968
 		return $query_params;
969 969
 	}
@@ -975,16 +975,16 @@  discard block
 block discarded – undo
975 975
 	 * @param array $query_params like EEM_Base's $query_params variable.
976 976
 	 * @return EE_Base_Class | NULL
977 977
 	 */
978
-	function get_one($query_params = array()){
979
-		if( ! is_array( $query_params ) ){
980
-			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' );
978
+	function get_one($query_params = array()) {
979
+		if ( ! is_array($query_params)) {
980
+			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');
981 981
 			$query_params = array();
982 982
 		}
983 983
 		$query_params['limit'] = 1;
984 984
 		$items = $this->get_all($query_params);
985
-		if(empty($items)){
985
+		if (empty($items)) {
986 986
 			return null;
987
-		}else{
987
+		} else {
988 988
 			return array_shift($items);
989 989
 		}
990 990
 	}
@@ -1008,8 +1008,8 @@  discard block
 block discarded – undo
1008 1008
 	 *
1009 1009
 	 * @return EE_Base_Class[]|array
1010 1010
 	 */
1011
-	public function next_x( $current_field_value, $field_to_order_by = null, $limit = 1, $query_params = array(), $columns_to_select = null ) {
1012
-		return $this->_get_consecutive( $current_field_value, '>', $field_to_order_by, $limit, $query_params, $columns_to_select );
1011
+	public function next_x($current_field_value, $field_to_order_by = null, $limit = 1, $query_params = array(), $columns_to_select = null) {
1012
+		return $this->_get_consecutive($current_field_value, '>', $field_to_order_by, $limit, $query_params, $columns_to_select);
1013 1013
 	}
1014 1014
 
1015 1015
 
@@ -1032,8 +1032,8 @@  discard block
 block discarded – undo
1032 1032
 	 *
1033 1033
 	 * @return EE_Base_Class[]|array
1034 1034
 	 */
1035
-	public function previous_x( $current_field_value, $field_to_order_by = null, $limit = 1, $query_params = array(), $columns_to_select = null ) {
1036
-		return $this->_get_consecutive( $current_field_value, '<', $field_to_order_by, $limit, $query_params, $columns_to_select );
1035
+	public function previous_x($current_field_value, $field_to_order_by = null, $limit = 1, $query_params = array(), $columns_to_select = null) {
1036
+		return $this->_get_consecutive($current_field_value, '<', $field_to_order_by, $limit, $query_params, $columns_to_select);
1037 1037
 	}
1038 1038
 
1039 1039
 
@@ -1055,9 +1055,9 @@  discard block
 block discarded – undo
1055 1055
 	 *
1056 1056
 	 * @return EE_Base_Class|null|array()
1057 1057
 	 */
1058
-	public function next( $current_field_value, $field_to_order_by = null, $query_params = array(), $columns_to_select = null ) {
1059
-		$results = $this->_get_consecutive( $current_field_value, '>', $field_to_order_by, 1, $query_params, $columns_to_select );
1060
-		return empty( $results ) ? null : reset( $results );
1058
+	public function next($current_field_value, $field_to_order_by = null, $query_params = array(), $columns_to_select = null) {
1059
+		$results = $this->_get_consecutive($current_field_value, '>', $field_to_order_by, 1, $query_params, $columns_to_select);
1060
+		return empty($results) ? null : reset($results);
1061 1061
 	}
1062 1062
 
1063 1063
 
@@ -1079,9 +1079,9 @@  discard block
 block discarded – undo
1079 1079
 	 *
1080 1080
 	 * @return EE_Base_Class|null|array()
1081 1081
 	 */
1082
-	public function previous( $current_field_value, $field_to_order_by = null, $query_params = array(), $columns_to_select = null ) {
1083
-		$results = $this->_get_consecutive( $current_field_value, '<', $field_to_order_by, 1, $query_params, $columns_to_select );
1084
-		return empty( $results ) ? null : reset( $results );
1082
+	public function previous($current_field_value, $field_to_order_by = null, $query_params = array(), $columns_to_select = null) {
1083
+		$results = $this->_get_consecutive($current_field_value, '<', $field_to_order_by, 1, $query_params, $columns_to_select);
1084
+		return empty($results) ? null : reset($results);
1085 1085
 	}
1086 1086
 
1087 1087
 
@@ -1107,40 +1107,40 @@  discard block
 block discarded – undo
1107 1107
 	 * @return EE_Base_Class[]|array
1108 1108
 	 * @throws EE_Error
1109 1109
 	 */
1110
-	protected function _get_consecutive( $current_field_value, $operand = '>', $field_to_order_by = null, $limit = 1, $query_params = array(), $columns_to_select = null ) {
1110
+	protected function _get_consecutive($current_field_value, $operand = '>', $field_to_order_by = null, $limit = 1, $query_params = array(), $columns_to_select = null) {
1111 1111
 		//if $field_to_order_by is empty then let's assume we're ordering by the primary key.
1112
-		if ( empty( $field_to_order_by ) ) {
1113
-			if ( $this->has_primary_key_field() ) {
1112
+		if (empty($field_to_order_by)) {
1113
+			if ($this->has_primary_key_field()) {
1114 1114
 				$field_to_order_by = $this->get_primary_key_field()->get_name();
1115 1115
 			} else {
1116 1116
 
1117
-				if ( WP_DEBUG ) {
1118
-					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' ) );
1117
+				if (WP_DEBUG) {
1118
+					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'));
1119 1119
 				}
1120
-				EE_Error::add_error( __('There was an error with the query.', 'event_espresso') );
1120
+				EE_Error::add_error(__('There was an error with the query.', 'event_espresso'));
1121 1121
 				return array();
1122 1122
 			}
1123 1123
 		}
1124 1124
 
1125
-		if( ! is_array( $query_params ) ){
1126
-			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' );
1125
+		if ( ! is_array($query_params)) {
1126
+			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');
1127 1127
 			$query_params = array();
1128 1128
 		}
1129 1129
 
1130 1130
 		//let's add the where query param for consecutive look up.
1131
-		$query_params[0][ $field_to_order_by ] = array( $operand, $current_field_value );
1131
+		$query_params[0][$field_to_order_by] = array($operand, $current_field_value);
1132 1132
 		$query_params['limit'] = $limit;
1133 1133
 
1134 1134
 		//set direction
1135
-		$incoming_orderby = isset( $query_params['order_by'] ) ? $query_params['order_by'] : array();
1136
-		$query_params['order_by'] = $operand == '>' ? array( $field_to_order_by => 'ASC' ) + $incoming_orderby : array( $field_to_order_by => 'DESC') + $incoming_orderby;
1135
+		$incoming_orderby = isset($query_params['order_by']) ? $query_params['order_by'] : array();
1136
+		$query_params['order_by'] = $operand == '>' ? array($field_to_order_by => 'ASC') + $incoming_orderby : array($field_to_order_by => 'DESC') + $incoming_orderby;
1137 1137
 
1138 1138
 		//if $columns_to_select is empty then that means we're returning EE_Base_Class objects
1139
-		if ( empty( $columns_to_select ) ) {
1140
-			return $this->get_all( $query_params );
1139
+		if (empty($columns_to_select)) {
1140
+			return $this->get_all($query_params);
1141 1141
 		} else {
1142 1142
 			//getting just the fields
1143
-			return $this->_get_all_wpdb_results( $query_params, ARRAY_A, $columns_to_select );
1143
+			return $this->_get_all_wpdb_results($query_params, ARRAY_A, $columns_to_select);
1144 1144
 		}
1145 1145
 	}
1146 1146
 
@@ -1151,18 +1151,18 @@  discard block
 block discarded – undo
1151 1151
 	 * This sets the _timezone property after model object has been instantiated.
1152 1152
 	 * @param null | string $timezone valid PHP DateTimeZone timezone string
1153 1153
 	 */
1154
-	public function set_timezone( $timezone ) {
1155
-		if ( $timezone !== null ) {
1154
+	public function set_timezone($timezone) {
1155
+		if ($timezone !== null) {
1156 1156
 			$this->_timezone = $timezone;
1157 1157
 		}
1158 1158
 		//note we need to loop through relations and set the timezone on those objects as well.
1159
-		foreach ( $this->_model_relations as $relation ) {
1160
-			$relation->set_timezone( $timezone );
1159
+		foreach ($this->_model_relations as $relation) {
1160
+			$relation->set_timezone($timezone);
1161 1161
 		}
1162 1162
 		//and finally we do the same for any datetime fields
1163
-		foreach ( $this->_fields as $field ) {
1164
-			if ( $field instanceof EE_Datetime_Field ) {
1165
-				$field->set_timezone( $timezone );
1163
+		foreach ($this->_fields as $field) {
1164
+			if ($field instanceof EE_Datetime_Field) {
1165
+				$field->set_timezone($timezone);
1166 1166
 			}
1167 1167
 		}
1168 1168
 	}
@@ -1177,9 +1177,9 @@  discard block
 block discarded – undo
1177 1177
 	 */
1178 1178
 	public function get_timezone() {
1179 1179
 		//first validate if timezone is set.  If not, then let's set it be whatever is set on the model fields.
1180
-		if ( empty( $this->_timezone ) ) {
1181
-			foreach( $this->_fields as $field ) {
1182
-				if ( $field instanceof EE_Datetime_Field ) {
1180
+		if (empty($this->_timezone)) {
1181
+			foreach ($this->_fields as $field) {
1182
+				if ($field instanceof EE_Datetime_Field) {
1183 1183
 					$this->set_timezone($field->get_timezone());
1184 1184
 					break;
1185 1185
 				}
@@ -1187,9 +1187,9 @@  discard block
 block discarded – undo
1187 1187
 		}
1188 1188
 
1189 1189
 		//if timezone STILL empty then return the default timezone for the site.
1190
-		if ( empty( $this->_timezone ) ) {
1191
-			EE_Registry::instance()->load_helper( 'DTT_Helper' );
1192
-			$this->set_timezone( EEH_DTT_Helper::get_timezone() );
1190
+		if (empty($this->_timezone)) {
1191
+			EE_Registry::instance()->load_helper('DTT_Helper');
1192
+			$this->set_timezone(EEH_DTT_Helper::get_timezone());
1193 1193
 		}
1194 1194
 		return $this->_timezone;
1195 1195
 	}
@@ -1207,19 +1207,19 @@  discard block
 block discarded – undo
1207 1207
 	 *
1208 1208
 	 * @return array formats in an array with the date format first, and the time format last.
1209 1209
 	 */
1210
-	public function get_formats_for( $field_name, $pretty = false ) {
1211
-		$field_settings = $this->field_settings_for( $field_name );
1210
+	public function get_formats_for($field_name, $pretty = false) {
1211
+		$field_settings = $this->field_settings_for($field_name);
1212 1212
 
1213 1213
 		//if not a valid EE_Datetime_Field then throw error
1214
-		if ( ! $field_settings instanceof EE_Datetime_Field ) {
1215
-			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 ) );
1214
+		if ( ! $field_settings instanceof EE_Datetime_Field) {
1215
+			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));
1216 1216
 		}
1217 1217
 
1218 1218
 		//while we are here, let's make sure the timezone internally in EEM_Base matches what is stored on
1219 1219
 		//the field.
1220 1220
 		$this->_timezone = $field_settings->get_timezone();
1221 1221
 
1222
-		return array( $field_settings->get_date_format( $pretty ), $field_settings->get_time_format( $pretty ) );
1222
+		return array($field_settings->get_date_format($pretty), $field_settings->get_time_format($pretty));
1223 1223
 	}
1224 1224
 
1225 1225
 
@@ -1243,25 +1243,25 @@  discard block
 block discarded – undo
1243 1243
 	 * @return int|string  If the given field_name is not of the EE_Datetime_Field type, then an EE_Error
1244 1244
 	 *                    	     exception is triggered.
1245 1245
 	 */
1246
-	public function current_time_for_query( $field_name, $timestamp = false, $what = 'both' ) {
1247
-		$formats = $this->get_formats_for( $field_name );
1246
+	public function current_time_for_query($field_name, $timestamp = false, $what = 'both') {
1247
+		$formats = $this->get_formats_for($field_name);
1248 1248
 
1249
-		$DateTime = new DateTime( "now", new DateTimeZone( $this->_timezone ) );
1249
+		$DateTime = new DateTime("now", new DateTimeZone($this->_timezone));
1250 1250
 
1251
-		if ( $timestamp ) {
1252
-			return $DateTime->format( 'U' );
1251
+		if ($timestamp) {
1252
+			return $DateTime->format('U');
1253 1253
 		}
1254 1254
 
1255 1255
 		//not returning timestamp, so return formatted string in timezone.
1256
-		switch( $what ) {
1256
+		switch ($what) {
1257 1257
 			case 'time' :
1258
-				return $DateTime->format( $formats[1] );
1258
+				return $DateTime->format($formats[1]);
1259 1259
 				break;
1260 1260
 			case 'date' :
1261
-				return $DateTime->format( $formats[0] );
1261
+				return $DateTime->format($formats[0]);
1262 1262
 				break;
1263 1263
 			default :
1264
-				return $DateTime->format( implode( ' ', $formats ) );
1264
+				return $DateTime->format(implode(' ', $formats));
1265 1265
 				break;
1266 1266
 		}
1267 1267
 	}
@@ -1285,18 +1285,18 @@  discard block
 block discarded – undo
1285 1285
 	 *                           		'U', this is ignored.
1286 1286
 	 * @return DateTime
1287 1287
 	 */
1288
-	public function convert_datetime_for_query( $field_name, $timestring, $incoming_format, $timezone = '' ) {
1288
+	public function convert_datetime_for_query($field_name, $timestring, $incoming_format, $timezone = '') {
1289 1289
 
1290 1290
 		//just using this to ensure the timezone is set correctly internally
1291
-		$this->get_formats_for( $field_name );
1291
+		$this->get_formats_for($field_name);
1292 1292
 
1293 1293
 		//load EEH_DTT_Helper
1294
-		EE_Registry::instance()->load_helper( 'DTT_Helper' );
1295
-		$set_timezone = empty( $timezone ) ? EEH_DTT_Helper::get_timezone() : $timezone;
1294
+		EE_Registry::instance()->load_helper('DTT_Helper');
1295
+		$set_timezone = empty($timezone) ? EEH_DTT_Helper::get_timezone() : $timezone;
1296 1296
 
1297
-		$incomingDateTime = date_create_from_format( $incoming_format, $timestring, new DateTimeZone( $set_timezone ) );
1297
+		$incomingDateTime = date_create_from_format($incoming_format, $timestring, new DateTimeZone($set_timezone));
1298 1298
 
1299
-		return $incomingDateTime->setTimeZone( new DateTimeZone( $this->_timezone ) );
1299
+		return $incomingDateTime->setTimeZone(new DateTimeZone($this->_timezone));
1300 1300
 	}
1301 1301
 
1302 1302
 
@@ -1306,7 +1306,7 @@  discard block
 block discarded – undo
1306 1306
 	 * Gets all the tables comprising this model. Array keys are the table aliases, and values are EE_Table objects
1307 1307
 	 * @return EE_Table_Base[]
1308 1308
 	 */
1309
-	function get_tables(){
1309
+	function get_tables() {
1310 1310
 		return $this->_tables;
1311 1311
 	}
1312 1312
 
@@ -1340,9 +1340,9 @@  discard block
 block discarded – undo
1340 1340
 	 * be aware that model objects being used could get out-of-sync with the database
1341 1341
 	 * @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)
1342 1342
 	 */
1343
-	function update($fields_n_values, $query_params, $keep_model_objs_in_sync = TRUE){
1344
-		if( ! is_array( $query_params ) ){
1345
-			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' );
1343
+	function update($fields_n_values, $query_params, $keep_model_objs_in_sync = TRUE) {
1344
+		if ( ! is_array($query_params)) {
1345
+			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');
1346 1346
 			$query_params = array();
1347 1347
 		}
1348 1348
 		/**
@@ -1352,7 +1352,7 @@  discard block
 block discarded – undo
1352 1352
 		 * @param array $fields_n_values the updated fields and their new values
1353 1353
 		 * @param array $query_params @see EEM_Base::get_all()
1354 1354
 		 */
1355
-		do_action( 'AHEE__EEM_Base__update__begin',$this, $fields_n_values, $query_params );
1355
+		do_action('AHEE__EEM_Base__update__begin', $this, $fields_n_values, $query_params);
1356 1356
 		/**
1357 1357
 		 * Filters the fields about to be updated given the query parameters. You can provide the
1358 1358
 		 * $query_params to $this->get_all() to find exactly which records will be updated
@@ -1360,10 +1360,10 @@  discard block
 block discarded – undo
1360 1360
 		 * @param EEM_Base $model the model being queried
1361 1361
 		 * @param array $query_params see EEM_Base::get_all()
1362 1362
 		 */
1363
-		$fields_n_values = apply_filters( 'FHEE__EEM_Base__update__fields_n_values', $fields_n_values, $this, $query_params );
1363
+		$fields_n_values = apply_filters('FHEE__EEM_Base__update__fields_n_values', $fields_n_values, $this, $query_params);
1364 1364
 		//need to verify that, for any entry we want to update, there are entries in each secondary table.
1365 1365
 		//to do that, for each table, verify that it's PK isn't null.
1366
-		$tables= $this->get_tables();
1366
+		$tables = $this->get_tables();
1367 1367
 
1368 1368
 		//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
1369 1369
 		//NOTE: we should make this code more efficient by NOT querying twice
@@ -1373,29 +1373,29 @@  discard block
 block discarded – undo
1373 1373
 			//we want to make sure the default_where strategy is ignored
1374 1374
 			$this->_ignore_where_strategy = TRUE;
1375 1375
 			$wpdb_select_results = $this->_get_all_wpdb_results($query_params);
1376
-			foreach( $wpdb_select_results as $wpdb_result ){
1376
+			foreach ($wpdb_select_results as $wpdb_result) {
1377 1377
 				// type cast stdClass as array
1378
-				$wpdb_result = (array)$wpdb_result;
1378
+				$wpdb_result = (array) $wpdb_result;
1379 1379
 				//get the model object's PK, as we'll want this if we need to insert a row into secondary tables
1380
-				if( $this->has_primary_key_field() ){
1381
-					$main_table_pk_value = $wpdb_result[ $this->get_primary_key_field()->get_qualified_column() ];
1382
-				}else{
1380
+				if ($this->has_primary_key_field()) {
1381
+					$main_table_pk_value = $wpdb_result[$this->get_primary_key_field()->get_qualified_column()];
1382
+				} else {
1383 1383
 					//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)
1384 1384
 					$main_table_pk_value = null;
1385 1385
 				}
1386 1386
 				//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
1387 1387
 				//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
1388
-				if(count($tables) > 1){
1388
+				if (count($tables) > 1) {
1389 1389
 					//foreach matching row in the DB, ensure that each table's PK isn't null. If so, there must not be an entry
1390 1390
 					//in that table, and so we'll want to insert one
1391
-					foreach($tables as $table_obj){
1391
+					foreach ($tables as $table_obj) {
1392 1392
 						$this_table_pk_column = $table_obj->get_fully_qualified_pk_column();
1393 1393
 						//if there is no private key for this table on the results, it means there's no entry
1394 1394
 						//in this table, right? so insert a row in the current table, using any fields available
1395
-						if( ! ( array_key_exists( $this_table_pk_column, $wpdb_result) && $wpdb_result[ $this_table_pk_column ] )){
1395
+						if ( ! (array_key_exists($this_table_pk_column, $wpdb_result) && $wpdb_result[$this_table_pk_column])) {
1396 1396
 							$success = $this->_insert_into_specific_table($table_obj, $fields_n_values, $main_table_pk_value);
1397 1397
 							//if we died here, report the error
1398
-							if( ! $success ) {
1398
+							if ( ! $success) {
1399 1399
 								return false;
1400 1400
 							}
1401 1401
 						}
@@ -1415,44 +1415,44 @@  discard block
 block discarded – undo
1415 1415
 		//if this wasn't called from a model object (to update itself)
1416 1416
 		//then we want to make sure we keep all the existing
1417 1417
 		//model objects in sync with the db
1418
-		if( $keep_model_objs_in_sync && ! $this->_values_already_prepared_by_model_object ){
1419
-			if( $this->has_primary_key_field() ){
1420
-				$model_objs_affected_ids = $this->get_col( $query_params );
1421
-			}else{
1418
+		if ($keep_model_objs_in_sync && ! $this->_values_already_prepared_by_model_object) {
1419
+			if ($this->has_primary_key_field()) {
1420
+				$model_objs_affected_ids = $this->get_col($query_params);
1421
+			} else {
1422 1422
 				//we need to select a bunch of columns and then combine them into the the "index primary key string"s
1423
-				$models_affected_key_columns = $this->_get_all_wpdb_results($query_params, ARRAY_A );
1423
+				$models_affected_key_columns = $this->_get_all_wpdb_results($query_params, ARRAY_A);
1424 1424
 				$model_objs_affected_ids = array();
1425
-				foreach( $models_affected_key_columns as $row ){
1426
-					$combined_index_key = $this->get_index_primary_key_string( $row );
1427
-					$model_objs_affected_ids[ $combined_index_key ] = $combined_index_key;
1425
+				foreach ($models_affected_key_columns as $row) {
1426
+					$combined_index_key = $this->get_index_primary_key_string($row);
1427
+					$model_objs_affected_ids[$combined_index_key] = $combined_index_key;
1428 1428
 				}
1429 1429
 
1430 1430
 			}
1431 1431
 
1432
-			if( ! $model_objs_affected_ids ){
1432
+			if ( ! $model_objs_affected_ids) {
1433 1433
 				//wait wait wait- if nothing was affected let's stop here
1434 1434
 				return 0;
1435 1435
 			}
1436
-			foreach( $model_objs_affected_ids as $id ){
1437
-				$model_obj_in_entity_map = $this->get_from_entity_map( $id );
1438
-				if( $model_obj_in_entity_map ){
1439
-					foreach( $fields_n_values as $field => $new_value ){
1440
-						$model_obj_in_entity_map->set( $field, $new_value );
1436
+			foreach ($model_objs_affected_ids as $id) {
1437
+				$model_obj_in_entity_map = $this->get_from_entity_map($id);
1438
+				if ($model_obj_in_entity_map) {
1439
+					foreach ($fields_n_values as $field => $new_value) {
1440
+						$model_obj_in_entity_map->set($field, $new_value);
1441 1441
 					}
1442 1442
 				}
1443 1443
 			}
1444 1444
 			//if there is a primary key on this model, we can now do a slight optimization
1445
-			if( $this->has_primary_key_field() ){
1445
+			if ($this->has_primary_key_field()) {
1446 1446
 				//we already know what we want to update. So let's make the query simpler so it's a little more efficient
1447 1447
 				$query_params = array(
1448
-					array( $this->primary_key_name() => array( 'IN', $model_objs_affected_ids ) ),
1449
-					'limit' => count( $model_objs_affected_ids ), 'default_where_conditions' => 'none' );
1448
+					array($this->primary_key_name() => array('IN', $model_objs_affected_ids)),
1449
+					'limit' => count($model_objs_affected_ids), 'default_where_conditions' => 'none' );
1450 1450
 			}
1451 1451
 		}
1452 1452
 
1453
-		$model_query_info = $this->_create_model_query_info_carrier( $query_params );
1454
-		$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.
1455
-		$rows_affected = $this->_do_wpdb_query('query', array( $SQL ) );
1453
+		$model_query_info = $this->_create_model_query_info_carrier($query_params);
1454
+		$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.
1455
+		$rows_affected = $this->_do_wpdb_query('query', array($SQL));
1456 1456
 		/**
1457 1457
 		 * Action called after a model update call has been made.
1458 1458
 		 *
@@ -1461,8 +1461,8 @@  discard block
 block discarded – undo
1461 1461
 		 * @param array $query_params @see EEM_Base::get_all()
1462 1462
 		 * @param int $rows_affected
1463 1463
 		 */
1464
-		do_action( 'AHEE__EEM_Base__update__end',$this, $fields_n_values, $query_params, $rows_affected );
1465
-		return $rows_affected;//how many supposedly got updated
1464
+		do_action('AHEE__EEM_Base__update__end', $this, $fields_n_values, $query_params, $rows_affected);
1465
+		return $rows_affected; //how many supposedly got updated
1466 1466
 	}
1467 1467
 
1468 1468
 	/**
@@ -1474,22 +1474,22 @@  discard block
 block discarded – undo
1474 1474
 	 * @param string $field_to_select
1475 1475
 	 * @return array just like $wpdb->get_col()
1476 1476
 	 */
1477
-	public function get_col( $query_params  = array(), $field_to_select = NULL ){
1477
+	public function get_col($query_params = array(), $field_to_select = NULL) {
1478 1478
 
1479
-		if( $field_to_select ){
1480
-			$field = $this->field_settings_for( $field_to_select );
1481
-		}elseif( $this->has_primary_key_field ( ) ){
1479
+		if ($field_to_select) {
1480
+			$field = $this->field_settings_for($field_to_select);
1481
+		}elseif ($this->has_primary_key_field( )) {
1482 1482
 			$field = $this->get_primary_key_field();
1483
-		}else{
1483
+		} else {
1484 1484
 			//no primary key, just grab the first column
1485
-			$field = reset( $this->field_settings());
1485
+			$field = reset($this->field_settings());
1486 1486
 		}
1487 1487
 
1488 1488
 
1489 1489
 		$model_query_info = $this->_create_model_query_info_carrier($query_params);
1490 1490
 		$select_expressions = $field->get_qualified_column();
1491
-		$SQL ="SELECT $select_expressions ".$this->_construct_2nd_half_of_select_query($model_query_info);
1492
-		$results =  $this->_do_wpdb_query('get_col', array( $SQL ) );
1491
+		$SQL = "SELECT $select_expressions ".$this->_construct_2nd_half_of_select_query($model_query_info);
1492
+		$results = $this->_do_wpdb_query('get_col', array($SQL));
1493 1493
 		return $results;
1494 1494
 	}
1495 1495
 
@@ -1499,12 +1499,12 @@  discard block
 block discarded – undo
1499 1499
 	 * @param string $field_to_select @see EEM_Base::get_col()
1500 1500
 	 * @return string
1501 1501
 	 */
1502
-	public function get_var( $query_params = array(), $field_to_select = NULL ) {
1503
-		$query_params[ 'limit' ] = 1;
1504
-		$col = $this->get_col( $query_params, $field_to_select );
1505
-		if( ! empty( $col ) ) {
1506
-			return reset( $col );
1507
-		}else{
1502
+	public function get_var($query_params = array(), $field_to_select = NULL) {
1503
+		$query_params['limit'] = 1;
1504
+		$col = $this->get_col($query_params, $field_to_select);
1505
+		if ( ! empty($col)) {
1506
+			return reset($col);
1507
+		} else {
1508 1508
 			return NULL;
1509 1509
 		}
1510 1510
 	}
@@ -1518,19 +1518,19 @@  discard block
 block discarded – undo
1518 1518
 	 * @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
1519 1519
 	 * @return string of SQL
1520 1520
 	 */
1521
-	function _construct_update_sql($fields_n_values){
1521
+	function _construct_update_sql($fields_n_values) {
1522 1522
 		/** @type WPDB $wpdb */
1523 1523
 		global $wpdb;
1524 1524
 		$cols_n_values = array();
1525
-		foreach($fields_n_values as $field_name => $value){
1525
+		foreach ($fields_n_values as $field_name => $value) {
1526 1526
 			$field_obj = $this->field_settings_for($field_name);
1527 1527
 			//if the value is NULL, we want to assign the value to that.
1528 1528
 			//wpdb->prepare doesn't really handle that properly
1529
-			$prepared_value = $this->_prepare_value_or_use_default( $field_obj, $fields_n_values );
1530
-			$value_sql = $prepared_value===NULL ? 'NULL' : $wpdb->prepare( $field_obj->get_wpdb_data_type(), $prepared_value );
1529
+			$prepared_value = $this->_prepare_value_or_use_default($field_obj, $fields_n_values);
1530
+			$value_sql = $prepared_value === NULL ? 'NULL' : $wpdb->prepare($field_obj->get_wpdb_data_type(), $prepared_value);
1531 1531
 			$cols_n_values[] = $field_obj->get_qualified_column()."=".$value_sql;
1532 1532
 		}
1533
-		return implode(",",$cols_n_values);
1533
+		return implode(",", $cols_n_values);
1534 1534
 
1535 1535
 	}
1536 1536
 
@@ -1542,10 +1542,10 @@  discard block
 block discarded – undo
1542 1542
 	 * @param mixed $id
1543 1543
 	 * @return boolean whether the row got deleted or not
1544 1544
 	 */
1545
-	public function delete_permanently_by_ID( $id ) {
1545
+	public function delete_permanently_by_ID($id) {
1546 1546
 		return $this->delete_permanently(
1547 1547
 			array(
1548
-				array( $this->get_primary_key_field()->get_name() => $id ),
1548
+				array($this->get_primary_key_field()->get_name() => $id),
1549 1549
 				'limit' 	=> 1
1550 1550
 			)
1551 1551
 		);
@@ -1559,10 +1559,10 @@  discard block
 block discarded – undo
1559 1559
 	 * @param mixed $id
1560 1560
 	 * @return boolean whether the row got deleted or not
1561 1561
 	 */
1562
-	public function delete_by_ID( $id ){
1562
+	public function delete_by_ID($id) {
1563 1563
 		return $this->delete(
1564 1564
 			array(
1565
-				array( $this->get_primary_key_field()->get_name() => $id ),
1565
+				array($this->get_primary_key_field()->get_name() => $id),
1566 1566
 				'limit' 	=> 1
1567 1567
 			)
1568 1568
 		);
@@ -1576,7 +1576,7 @@  discard block
 block discarded – undo
1576 1576
 	 * @param boolean $allow_blocking
1577 1577
 	 * @return @see EEM_Base::delete_permanently
1578 1578
 	 */
1579
-	function delete($query_params,$allow_blocking = true){
1579
+	function delete($query_params, $allow_blocking = true) {
1580 1580
 		return $this->delete_permanently($query_params, $allow_blocking);
1581 1581
 	}
1582 1582
 
@@ -1592,7 +1592,7 @@  discard block
 block discarded – undo
1592 1592
 	 * which may depend on it. Its generally advisable to always leave this as TRUE, otherwise you could easily corrupt your DB
1593 1593
 	 * @return int how many rows got deleted
1594 1594
 	 */
1595
-	function delete_permanently($query_params,$allow_blocking = true){
1595
+	function delete_permanently($query_params, $allow_blocking = true) {
1596 1596
 		/**
1597 1597
 		 * Action called just before performing a real deletion query. You can use the
1598 1598
 		 * model and its $query_params to find exactly which items will be deleted
@@ -1601,34 +1601,34 @@  discard block
 block discarded – undo
1601 1601
 		 * @param boolean $allow_blocking whether or not to allow related model objects
1602 1602
 		 * to block (prevent) this deletion
1603 1603
 		 */
1604
-		do_action( 'AHEE__EEM_Base__delete__begin', $this, $query_params, $allow_blocking );
1604
+		do_action('AHEE__EEM_Base__delete__begin', $this, $query_params, $allow_blocking);
1605 1605
 		//some MySQL databases may be running safe mode, which may restrict
1606 1606
 		//deletion if there is no KEY column used in the WHERE statement of a deletion.
1607 1607
 		//to get around this, we first do a SELECT, get all the IDs, and then run another query
1608 1608
 		//to delete them
1609 1609
 		$items_for_deletion = $this->_get_all_wpdb_results($query_params);
1610
-		$deletion_where = $this->_setup_ids_for_delete( $items_for_deletion, $allow_blocking);
1611
-		if($deletion_where){
1610
+		$deletion_where = $this->_setup_ids_for_delete($items_for_deletion, $allow_blocking);
1611
+		if ($deletion_where) {
1612 1612
 			//echo "objects for deletion:";var_dump($objects_for_deletion);
1613 1613
 			$model_query_info = $this->_create_model_query_info_carrier($query_params);
1614 1614
 			$table_aliases = array();
1615
-			foreach(array_keys($this->_tables) as $table_alias){
1615
+			foreach (array_keys($this->_tables) as $table_alias) {
1616 1616
 				$table_aliases[] = $table_alias;
1617 1617
 			}
1618
-			$SQL = "DELETE ".implode(", ",$table_aliases)." FROM ".$model_query_info->get_full_join_sql()." WHERE ".$deletion_where;
1618
+			$SQL = "DELETE ".implode(", ", $table_aliases)." FROM ".$model_query_info->get_full_join_sql()." WHERE ".$deletion_where;
1619 1619
 
1620 1620
 			//		/echo "delete sql:$SQL";
1621
-			$rows_deleted = $this->_do_wpdb_query( 'query', array( $SQL ) );
1622
-		}else{
1621
+			$rows_deleted = $this->_do_wpdb_query('query', array($SQL));
1622
+		} else {
1623 1623
 			$rows_deleted = 0;
1624 1624
 		}
1625 1625
 
1626 1626
 		//and lastly make sure those items are removed from the entity map; if they could be put into it at all
1627
-		if( $this->has_primary_key_field() ){
1628
-			foreach($items_for_deletion as $item_for_deletion_row ){
1629
-				$pk_value = $item_for_deletion_row[ $this->get_primary_key_field()->get_qualified_column() ];
1630
-				if( isset( $this->_entity_map[ $pk_value ] ) ){
1631
-					unset( $this->_entity_map[ $pk_value ] );
1627
+		if ($this->has_primary_key_field()) {
1628
+			foreach ($items_for_deletion as $item_for_deletion_row) {
1629
+				$pk_value = $item_for_deletion_row[$this->get_primary_key_field()->get_qualified_column()];
1630
+				if (isset($this->_entity_map[$pk_value])) {
1631
+					unset($this->_entity_map[$pk_value]);
1632 1632
 				}
1633 1633
 			}
1634 1634
 		}
@@ -1640,8 +1640,8 @@  discard block
 block discarded – undo
1640 1640
 		 * @param array $query_params @see EEM_Base::get_all()
1641 1641
 		 * @param int $rows_deleted
1642 1642
 		 */
1643
-		do_action( 'AHEE__EEM_Base__delete__end', $this, $query_params, $rows_deleted );
1644
-		return $rows_deleted;//how many supposedly got deleted
1643
+		do_action('AHEE__EEM_Base__delete__end', $this, $query_params, $rows_deleted);
1644
+		return $rows_deleted; //how many supposedly got deleted
1645 1645
 	}
1646 1646
 
1647 1647
 
@@ -1657,28 +1657,28 @@  discard block
 block discarded – undo
1657 1657
 	 * blocking its deletion before removing the relation between A and B
1658 1658
 	 * @return boolean
1659 1659
 	 */
1660
-	public function delete_is_blocked_by_related_models($this_model_obj_or_id, $ignore_this_model_obj = null){
1660
+	public function delete_is_blocked_by_related_models($this_model_obj_or_id, $ignore_this_model_obj = null) {
1661 1661
 		//first, if $ignore_this_model_obj was supplied, get its model
1662
-		if($ignore_this_model_obj && $ignore_this_model_obj instanceof EE_Base_Class){
1662
+		if ($ignore_this_model_obj && $ignore_this_model_obj instanceof EE_Base_Class) {
1663 1663
 			$ignored_model = $ignore_this_model_obj->get_model();
1664
-		}else{
1664
+		} else {
1665 1665
 			$ignored_model = null;
1666 1666
 		}
1667 1667
 		//now check all the relations of $this_model_obj_or_id and see if there
1668 1668
 		//are any related model objects blocking it?
1669 1669
 		$is_blocked = false;
1670
-		foreach($this->_model_relations as $relation_name => $relation_obj){
1671
-			if( $relation_obj->block_delete_if_related_models_exist()){
1670
+		foreach ($this->_model_relations as $relation_name => $relation_obj) {
1671
+			if ($relation_obj->block_delete_if_related_models_exist()) {
1672 1672
 				//if $ignore_this_model_obj was supplied, then for the query
1673 1673
 				//on that model needs to be told to ignore $ignore_this_model_obj
1674
-				if($ignored_model && $relation_name == $ignored_model->get_this_model_name()){
1675
-					$related_model_objects = $relation_obj->get_all_related($this_model_obj_or_id,array(
1676
-					array($ignored_model->get_primary_key_field()->get_name() => array('!=',$ignore_this_model_obj->ID()))));
1677
-				}else{
1674
+				if ($ignored_model && $relation_name == $ignored_model->get_this_model_name()) {
1675
+					$related_model_objects = $relation_obj->get_all_related($this_model_obj_or_id, array(
1676
+					array($ignored_model->get_primary_key_field()->get_name() => array('!=', $ignore_this_model_obj->ID()))));
1677
+				} else {
1678 1678
 					$related_model_objects = $relation_obj->get_all_related($this_model_obj_or_id);
1679 1679
 				}
1680 1680
 
1681
-				if($related_model_objects){
1681
+				if ($related_model_objects) {
1682 1682
 					EE_Error::add_error($relation_obj->get_deletion_error_message(), __FILE__, __FUNCTION__, __LINE__);
1683 1683
 					$is_blocked = true;
1684 1684
 				}
@@ -1698,65 +1698,65 @@  discard block
 block discarded – undo
1698 1698
 	 * @throws EE_Error
1699 1699
 	 * @return string    everything that comes after the WHERE statement.
1700 1700
 	 */
1701
-	protected function _setup_ids_for_delete( $objects_for_deletion, $allow_blocking = true) {
1702
-		if($this->has_primary_key_field()){
1701
+	protected function _setup_ids_for_delete($objects_for_deletion, $allow_blocking = true) {
1702
+		if ($this->has_primary_key_field()) {
1703 1703
 			$primary_table = $this->_get_main_table();
1704 1704
 			$other_tables = $this->_get_other_tables();
1705 1705
 			$deletes = $query = array();
1706
-			foreach ( $objects_for_deletion as $delete_object ) {
1706
+			foreach ($objects_for_deletion as $delete_object) {
1707 1707
 				//before we mark this object for deletion,
1708 1708
 				//make sure there's no related objects blocking its deletion (if we're checking)
1709
-				if( $allow_blocking && $this->delete_is_blocked_by_related_models($delete_object[$primary_table->get_fully_qualified_pk_column()]) ){
1709
+				if ($allow_blocking && $this->delete_is_blocked_by_related_models($delete_object[$primary_table->get_fully_qualified_pk_column()])) {
1710 1710
 					continue;
1711 1711
 				}
1712 1712
 
1713 1713
 				//primary table deletes
1714
-				if ( isset( $delete_object[$primary_table->get_fully_qualified_pk_column()] ) )
1714
+				if (isset($delete_object[$primary_table->get_fully_qualified_pk_column()]))
1715 1715
 					$deletes[$primary_table->get_fully_qualified_pk_column()][] = $delete_object[$primary_table->get_fully_qualified_pk_column()];
1716 1716
 
1717 1717
 				//other tables
1718
-				if ( !empty( $other_tables ) ) {
1719
-					foreach ( $other_tables as $ot ) {
1718
+				if ( ! empty($other_tables)) {
1719
+					foreach ($other_tables as $ot) {
1720 1720
 
1721 1721
 						//first check if we've got the foreign key column here.
1722
-						if ( isset( $delete_object[$ot->get_fully_qualified_fk_column()] ) )
1722
+						if (isset($delete_object[$ot->get_fully_qualified_fk_column()]))
1723 1723
 							$deletes[$ot->get_fully_qualified_pk_column()][] = $delete_object[$ot->get_fully_qualified_fk_column()];
1724 1724
 
1725 1725
 						//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
1726
-						if ( isset( $delete_object[$ot->get_fully_qualified_pk_column()] ) )
1726
+						if (isset($delete_object[$ot->get_fully_qualified_pk_column()]))
1727 1727
 							$deletes[$ot->get_fully_qualified_pk_column()][] = $delete_object[$ot->get_fully_qualified_pk_column()];
1728 1728
 
1729 1729
 						//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!
1730
-						if ( isset( $delete_object[$ot->get_fully_qualified_pk_on_fk_table()]) )
1730
+						if (isset($delete_object[$ot->get_fully_qualified_pk_on_fk_table()]))
1731 1731
 							$deletes[$ot->get_fully_qualified_pk_column()][] = $delete_object[$ot->get_fully_qualified_pk_column()];
1732 1732
 					}
1733 1733
 				}
1734 1734
 			}
1735 1735
 
1736 1736
 			//we should have deletes now, so let's just go through and setup the where statement
1737
-			foreach ( $deletes as $column => $values ) {
1737
+			foreach ($deletes as $column => $values) {
1738 1738
 				//make sure we have unique $values;
1739 1739
 				$values = array_unique($values);
1740
-				$query[] = $column . ' IN(' . implode(",",$values) . ')';
1740
+				$query[] = $column.' IN('.implode(",", $values).')';
1741 1741
 			}
1742 1742
 
1743
-			return !empty($query) ? implode(' AND ', $query ) : '';
1744
-		}elseif(count($this->get_combined_primary_key_fields()) > 1){
1743
+			return ! empty($query) ? implode(' AND ', $query) : '';
1744
+		}elseif (count($this->get_combined_primary_key_fields()) > 1) {
1745 1745
 			$ways_to_identify_a_row = array();
1746 1746
 			$fields = $this->get_combined_primary_key_fields();
1747 1747
 			//note: because there' sno primary key, that means nothing else  can be pointing to this model, right?
1748
-			foreach($objects_for_deletion as  $delete_object){
1748
+			foreach ($objects_for_deletion as  $delete_object) {
1749 1749
 				$values_for_each_cpk_for_a_row = array();
1750
-				foreach($fields as $cpk_field){
1750
+				foreach ($fields as $cpk_field) {
1751 1751
 					$values_for_each_cpk_for_a_row[] = $cpk_field->get_qualified_column()."=".$delete_object[$cpk_field->get_qualified_column()];
1752 1752
 				}
1753
-				$ways_to_identify_a_row[] = "(".implode(" AND ",$values_for_each_cpk_for_a_row).")";
1753
+				$ways_to_identify_a_row[] = "(".implode(" AND ", $values_for_each_cpk_for_a_row).")";
1754 1754
 			}
1755
-			return implode(" OR ",$ways_to_identify_a_row);
1756
-		}else{
1755
+			return implode(" OR ", $ways_to_identify_a_row);
1756
+		} else {
1757 1757
 			//so there's no primary key and no combined key...
1758 1758
 			//sorry, can't help you
1759
-			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)));
1759
+			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)));
1760 1760
 		}
1761 1761
 	}
1762 1762
 
@@ -1770,21 +1770,21 @@  discard block
 block discarded – undo
1770 1770
 	 * @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;
1771 1771
 	 * @return int
1772 1772
 	 */
1773
-	function count($query_params =array(),$field_to_count = NULL, $distinct = FALSE){
1773
+	function count($query_params = array(), $field_to_count = NULL, $distinct = FALSE) {
1774 1774
 		$model_query_info = $this->_create_model_query_info_carrier($query_params);
1775
-		if($field_to_count){
1775
+		if ($field_to_count) {
1776 1776
 			$field_obj = $this->field_settings_for($field_to_count);
1777 1777
 			$column_to_count = $field_obj->get_qualified_column();
1778
-		}elseif($this->has_primary_key_field ()){
1778
+		}elseif ($this->has_primary_key_field()) {
1779 1779
 			$pk_field_obj = $this->get_primary_key_field();
1780 1780
 			$column_to_count = $pk_field_obj->get_qualified_column();
1781
-		}else{//there's no primary key
1781
+		} else {//there's no primary key
1782 1782
 			$column_to_count = '*';
1783 1783
 		}
1784 1784
 
1785
-		$column_to_count = $distinct ? "DISTINCT (" . $column_to_count . " )" : $column_to_count;
1786
-		$SQL ="SELECT COUNT(".$column_to_count.")" . $this->_construct_2nd_half_of_select_query($model_query_info);
1787
-		return (int)$this->_do_wpdb_query( 'get_var', array( $SQL) );
1785
+		$column_to_count = $distinct ? "DISTINCT (".$column_to_count." )" : $column_to_count;
1786
+		$SQL = "SELECT COUNT(".$column_to_count.")".$this->_construct_2nd_half_of_select_query($model_query_info);
1787
+		return (int) $this->_do_wpdb_query('get_var', array($SQL));
1788 1788
 	}
1789 1789
 
1790 1790
 	/**
@@ -1794,23 +1794,23 @@  discard block
 block discarded – undo
1794 1794
 	 * @param string $field_to_sum name of field (array key in $_fields array)
1795 1795
 	 * @return float
1796 1796
 	 */
1797
-	function sum($query_params, $field_to_sum = NULL){
1797
+	function sum($query_params, $field_to_sum = NULL) {
1798 1798
 		$model_query_info = $this->_create_model_query_info_carrier($query_params);
1799 1799
 
1800
-		if($field_to_sum){
1800
+		if ($field_to_sum) {
1801 1801
 			$field_obj = $this->field_settings_for($field_to_sum);
1802 1802
 
1803
-		}else{
1803
+		} else {
1804 1804
 			$field_obj = $this->get_primary_key_field();
1805 1805
 		}
1806 1806
 		$column_to_count = $field_obj->get_qualified_column();
1807 1807
 
1808
-		$SQL ="SELECT SUM(".$column_to_count.")" . $this->_construct_2nd_half_of_select_query($model_query_info);
1809
-		$return_value = $this->_do_wpdb_query('get_var',array( $SQL ) );
1810
-		if($field_obj->get_wpdb_data_type() == '%d' || $field_obj->get_wpdb_data_type() == '%s' ){
1811
-			return (float)$return_value;
1812
-		}else{//must be %f
1813
-			return (float)$return_value;
1808
+		$SQL = "SELECT SUM(".$column_to_count.")".$this->_construct_2nd_half_of_select_query($model_query_info);
1809
+		$return_value = $this->_do_wpdb_query('get_var', array($SQL));
1810
+		if ($field_obj->get_wpdb_data_type() == '%d' || $field_obj->get_wpdb_data_type() == '%s') {
1811
+			return (float) $return_value;
1812
+		} else {//must be %f
1813
+			return (float) $return_value;
1814 1814
 		}
1815 1815
 	}
1816 1816
 
@@ -1825,33 +1825,33 @@  discard block
 block discarded – undo
1825 1825
 	 * @global wpdb $wpdb
1826 1826
 	 * @return mixed
1827 1827
 	 */
1828
-	protected function _do_wpdb_query( $wpdb_method, $arguments_to_provide ){
1828
+	protected function _do_wpdb_query($wpdb_method, $arguments_to_provide) {
1829 1829
 		//if we're in maintenance mode level 2, DON'T run any queries
1830 1830
 		//because level 2 indicates the database needs updating and
1831 1831
 		//is probably out of sync with the code
1832
-		if( ! EE_Maintenance_Mode::instance()->models_can_query()){
1832
+		if ( ! EE_Maintenance_Mode::instance()->models_can_query()) {
1833 1833
 			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")));
1834 1834
 		}
1835 1835
 		/** @type WPDB $wpdb */
1836 1836
 		global $wpdb;
1837
-		if( ! method_exists( $wpdb, $wpdb_method ) ){
1838
-			throw new EE_Error( sprintf( __( 'There is no method named "%s" on Wordpress\' $wpdb object','event_espresso' ), $wpdb_method ) );
1837
+		if ( ! method_exists($wpdb, $wpdb_method)) {
1838
+			throw new EE_Error(sprintf(__('There is no method named "%s" on Wordpress\' $wpdb object', 'event_espresso'), $wpdb_method));
1839 1839
 		}
1840
-		if( WP_DEBUG ){
1840
+		if (WP_DEBUG) {
1841 1841
 			$old_show_errors_value = $wpdb->show_errors;
1842
-			$wpdb->show_errors( FALSE );
1843
-		}
1844
-		$result = $this->_process_wpdb_query( $wpdb_method, $arguments_to_provide );
1845
-		$this->show_db_query_if_previously_requested( $wpdb->last_query );
1846
-		if( WP_DEBUG ){
1847
-			$wpdb->show_errors( $old_show_errors_value );
1848
-			if( ! empty( $wpdb->last_error ) ){
1849
-				throw new EE_Error( sprintf( __( 'WPDB Error: "%s"', 'event_espresso' ), $wpdb->last_error ) );
1850
-			}elseif( $result === false ){
1851
-				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 ) ) );
1842
+			$wpdb->show_errors(FALSE);
1843
+		}
1844
+		$result = $this->_process_wpdb_query($wpdb_method, $arguments_to_provide);
1845
+		$this->show_db_query_if_previously_requested($wpdb->last_query);
1846
+		if (WP_DEBUG) {
1847
+			$wpdb->show_errors($old_show_errors_value);
1848
+			if ( ! empty($wpdb->last_error)) {
1849
+				throw new EE_Error(sprintf(__('WPDB Error: "%s"', 'event_espresso'), $wpdb->last_error));
1850
+			}elseif ($result === false) {
1851
+				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)));
1852 1852
 			}
1853
-		}elseif( $result === false ) {
1854
-			EE_Error::add_error( sprintf( __( 'A database error has occurred. Turn on WP_DEBUG for more information.', 'event_espresso' )), __FILE__, __FUNCTION__, __LINE__);
1853
+		}elseif ($result === false) {
1854
+			EE_Error::add_error(sprintf(__('A database error has occurred. Turn on WP_DEBUG for more information.', 'event_espresso')), __FILE__, __FUNCTION__, __LINE__);
1855 1855
 		}
1856 1856
 		return $result;
1857 1857
 	}
@@ -1867,26 +1867,26 @@  discard block
 block discarded – undo
1867 1867
 	 * @param array $arguments_to_provide
1868 1868
 	 * @return mixed
1869 1869
 	 */
1870
-	private function _process_wpdb_query( $wpdb_method, $arguments_to_provide ) {
1870
+	private function _process_wpdb_query($wpdb_method, $arguments_to_provide) {
1871 1871
 		/** @type WPDB $wpdb */
1872 1872
 		global $wpdb;
1873 1873
 		$wpdb->last_error = null;
1874
-		$result = call_user_func_array( array( $wpdb, $wpdb_method ), $arguments_to_provide );
1874
+		$result = call_user_func_array(array($wpdb, $wpdb_method), $arguments_to_provide);
1875 1875
 		// was there an error running the query? but we don't care on new activations
1876 1876
 		// (we're going to setup the DB anyway on new activations)
1877
-		if ( ( $result === false || ! empty( $wpdb->last_error ) )
1877
+		if (($result === false || ! empty($wpdb->last_error))
1878 1878
 			&& EE_System::instance()->detect_req_type() != EE_System::req_type_new_activation
1879 1879
 		) {
1880
-			switch ( EEM_Base::$_db_verification_level ) {
1880
+			switch (EEM_Base::$_db_verification_level) {
1881 1881
 
1882 1882
 				case EEM_Base::db_verified_none :
1883 1883
 					// let's double-check core's DB
1884
-					$error_message = $this->_verify_core_db( $wpdb_method, $arguments_to_provide );
1884
+					$error_message = $this->_verify_core_db($wpdb_method, $arguments_to_provide);
1885 1885
 					break;
1886 1886
 
1887 1887
 				case EEM_Base::db_verified_core :
1888 1888
 					// STILL NO LOVE?? verify all the addons too. Maybe they need to be fixed
1889
-					$error_message = $this->_verify_addons_db( $wpdb_method, $arguments_to_provide );
1889
+					$error_message = $this->_verify_addons_db($wpdb_method, $arguments_to_provide);
1890 1890
 					break;
1891 1891
 
1892 1892
 				case EEM_Base::db_verified_addons :
@@ -1894,11 +1894,11 @@  discard block
 block discarded – undo
1894 1894
 					return $result;
1895 1895
 					break;
1896 1896
 			}
1897
-			if ( ! empty( $error_message ) ) {
1898
-				EE_Log::instance()->log( __FILE__, __FUNCTION__, $error_message, 'error' );
1899
-				trigger_error( $error_message );
1897
+			if ( ! empty($error_message)) {
1898
+				EE_Log::instance()->log(__FILE__, __FUNCTION__, $error_message, 'error');
1899
+				trigger_error($error_message);
1900 1900
 			}
1901
-			return $this->_process_wpdb_query( $wpdb_method, $arguments_to_provide );
1901
+			return $this->_process_wpdb_query($wpdb_method, $arguments_to_provide);
1902 1902
 
1903 1903
 		}
1904 1904
 
@@ -1914,18 +1914,18 @@  discard block
 block discarded – undo
1914 1914
 	 * @param array $arguments_to_provide
1915 1915
 	 * @return string
1916 1916
 	 */
1917
-	private function _verify_core_db( $wpdb_method, $arguments_to_provide ){
1917
+	private function _verify_core_db($wpdb_method, $arguments_to_provide) {
1918 1918
 		/** @type WPDB $wpdb */
1919 1919
 		global $wpdb;
1920 1920
 		//ok remember that we've already attempted fixing the core db, in case the problem persists
1921 1921
 		EEM_Base::$_db_verification_level = EEM_Base::db_verified_core;
1922 1922
 		$error_message = sprintf(
1923
-			__( 'WPDB Error "%1$s" while running wpdb method "%2$s" with arguments %3$s. Automatically attempting to fix EE Core DB', 'event_espresso' ),
1923
+			__('WPDB Error "%1$s" while running wpdb method "%2$s" with arguments %3$s. Automatically attempting to fix EE Core DB', 'event_espresso'),
1924 1924
 			$wpdb->last_error,
1925 1925
 			$wpdb_method,
1926
-			json_encode( $arguments_to_provide )
1926
+			json_encode($arguments_to_provide)
1927 1927
 		);
1928
-		EE_System::instance()->initialize_db_if_no_migrations_required( false, true );
1928
+		EE_System::instance()->initialize_db_if_no_migrations_required(false, true);
1929 1929
 		return $error_message;
1930 1930
 	}
1931 1931
 
@@ -1938,16 +1938,16 @@  discard block
 block discarded – undo
1938 1938
 	 * @param $arguments_to_provide
1939 1939
 	 * @return string
1940 1940
 	 */
1941
-	private function _verify_addons_db( $wpdb_method, $arguments_to_provide ) {
1941
+	private function _verify_addons_db($wpdb_method, $arguments_to_provide) {
1942 1942
 		/** @type WPDB $wpdb */
1943 1943
 		global $wpdb;
1944 1944
 		//ok remember that we've already attempted fixing the addons dbs, in case the problem persists
1945 1945
 		EEM_Base::$_db_verification_level = EEM_Base::db_verified_addons;
1946 1946
 		$error_message = sprintf(
1947
-			__( 'WPDB AGAIN: Error "%1$s" while running the same method and arguments as before. Automatically attempting to fix EE Addons DB', 'event_espresso' ),
1947
+			__('WPDB AGAIN: Error "%1$s" while running the same method and arguments as before. Automatically attempting to fix EE Addons DB', 'event_espresso'),
1948 1948
 			$wpdb->last_error,
1949 1949
 			$wpdb_method,
1950
-			json_encode( $arguments_to_provide )
1950
+			json_encode($arguments_to_provide)
1951 1951
 		);
1952 1952
 		EE_System::instance()->initialize_addons();
1953 1953
 		return $error_message;
@@ -1962,7 +1962,7 @@  discard block
 block discarded – undo
1962 1962
 	 * @param EE_Model_Query_Info_Carrier $model_query_info
1963 1963
 	 * @return string
1964 1964
 	 */
1965
-	private function _construct_2nd_half_of_select_query(EE_Model_Query_Info_Carrier $model_query_info){
1965
+	private function _construct_2nd_half_of_select_query(EE_Model_Query_Info_Carrier $model_query_info) {
1966 1966
 		return " FROM ".$model_query_info->get_full_join_sql().
1967 1967
 				$model_query_info->get_where_sql().
1968 1968
 				$model_query_info->get_group_by_sql().
@@ -1975,7 +1975,7 @@  discard block
 block discarded – undo
1975 1975
 	 * Set to easily debug the next X queries ran from this model.
1976 1976
 	 * @param int $count
1977 1977
 	 */
1978
-	function show_next_x_db_queries($count = 1){
1978
+	function show_next_x_db_queries($count = 1) {
1979 1979
 		$this->_show_next_x_db_queries = $count;
1980 1980
 	}
1981 1981
 
@@ -1984,8 +1984,8 @@  discard block
 block discarded – undo
1984 1984
 	/**
1985 1985
 	 * @param $sql_query
1986 1986
 	 */
1987
-	function show_db_query_if_previously_requested($sql_query){
1988
-		if($this->_show_next_x_db_queries > 0){
1987
+	function show_db_query_if_previously_requested($sql_query) {
1988
+		if ($this->_show_next_x_db_queries > 0) {
1989 1989
 			echo $sql_query;
1990 1990
 			$this->_show_next_x_db_queries--;
1991 1991
 		}
@@ -2009,9 +2009,9 @@  discard block
 block discarded – undo
2009 2009
 	 * @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.
2010 2010
 	 * @return EE_Base_Class which was added as a relation. Object referred to by $other_model_id_or_obj
2011 2011
 	 */
2012
-	public function add_relationship_to($id_or_obj,$other_model_id_or_obj, $relationName, $extra_join_model_fields_n_values = array()){
2012
+	public function add_relationship_to($id_or_obj, $other_model_id_or_obj, $relationName, $extra_join_model_fields_n_values = array()) {
2013 2013
 		$relation_obj = $this->related_settings_for($relationName);
2014
-		return $relation_obj->add_relation_to( $id_or_obj, $other_model_id_or_obj, $extra_join_model_fields_n_values);
2014
+		return $relation_obj->add_relation_to($id_or_obj, $other_model_id_or_obj, $extra_join_model_fields_n_values);
2015 2015
 	}
2016 2016
 
2017 2017
 	/**
@@ -2030,9 +2030,9 @@  discard block
 block discarded – undo
2030 2030
 	 * @return boolean of success
2031 2031
 	 * @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.
2032 2032
 	 */
2033
-	public function remove_relationship_to($id_or_obj,  $other_model_id_or_obj, $relationName, $where_query= array() ){
2033
+	public function remove_relationship_to($id_or_obj, $other_model_id_or_obj, $relationName, $where_query = array()) {
2034 2034
 		$relation_obj = $this->related_settings_for($relationName);
2035
-		return $relation_obj->remove_relation_to($id_or_obj, $other_model_id_or_obj, $where_query );
2035
+		return $relation_obj->remove_relation_to($id_or_obj, $other_model_id_or_obj, $where_query);
2036 2036
 	}
2037 2037
 
2038 2038
 
@@ -2045,9 +2045,9 @@  discard block
 block discarded – undo
2045 2045
 	 * @param EE_Base_Class[] objects to which relations were removed
2046 2046
 	 * @return \EE_Base_Class[]
2047 2047
 	 */
2048
-	public function remove_relations($id_or_obj,$relationName,$where_query_params = array()){
2048
+	public function remove_relations($id_or_obj, $relationName, $where_query_params = array()) {
2049 2049
 		$relation_obj = $this->related_settings_for($relationName);
2050
-		return $relation_obj->remove_relations($id_or_obj, $where_query_params );
2050
+		return $relation_obj->remove_relations($id_or_obj, $where_query_params);
2051 2051
 	}
2052 2052
 
2053 2053
 
@@ -2060,10 +2060,10 @@  discard block
 block discarded – undo
2060 2060
 	 * @param array $query_params like EEM_Base::get_all
2061 2061
 	 * @return EE_Base_Class[]
2062 2062
 	 */
2063
-	function get_all_related($id_or_obj, $model_name, $query_params = null){
2063
+	function get_all_related($id_or_obj, $model_name, $query_params = null) {
2064 2064
 		$model_obj = $this->ensure_is_obj($id_or_obj);
2065 2065
 		$relation_settings = $this->related_settings_for($model_name);
2066
-		return $relation_settings->get_all_related($model_obj,$query_params);
2066
+		return $relation_settings->get_all_related($model_obj, $query_params);
2067 2067
 	}
2068 2068
 
2069 2069
 	/**
@@ -2076,10 +2076,10 @@  discard block
 block discarded – undo
2076 2076
 	 * @param array $query_params
2077 2077
 	 * @return int how many deleted
2078 2078
 	 */
2079
-	public function delete_related($id_or_obj,$model_name, $query_params = array()){
2079
+	public function delete_related($id_or_obj, $model_name, $query_params = array()) {
2080 2080
 		$model_obj = $this->ensure_is_obj($id_or_obj);
2081 2081
 		$relation_settings = $this->related_settings_for($model_name);
2082
-		return $relation_settings->delete_all_related($model_obj,$query_params);
2082
+		return $relation_settings->delete_all_related($model_obj, $query_params);
2083 2083
 	}
2084 2084
 
2085 2085
 	/**
@@ -2092,10 +2092,10 @@  discard block
 block discarded – undo
2092 2092
 	 * @param array $query_params
2093 2093
 	 * @return int how many deleted
2094 2094
 	 */
2095
-	public function delete_related_permanently($id_or_obj,$model_name, $query_params = array()){
2095
+	public function delete_related_permanently($id_or_obj, $model_name, $query_params = array()) {
2096 2096
 		$model_obj = $this->ensure_is_obj($id_or_obj);
2097 2097
 		$relation_settings = $this->related_settings_for($model_name);
2098
-		return $relation_settings->delete_related_permanently($model_obj,$query_params);
2098
+		return $relation_settings->delete_related_permanently($model_obj, $query_params);
2099 2099
 	}
2100 2100
 
2101 2101
 	/**
@@ -2108,17 +2108,17 @@  discard block
 block discarded – undo
2108 2108
 	 * @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;
2109 2109
 	 * @return int
2110 2110
 	 */
2111
-	function count_related($id_or_obj,$model_name,$query_params = array(),$field_to_count = null, $distinct = FALSE){
2111
+	function count_related($id_or_obj, $model_name, $query_params = array(), $field_to_count = null, $distinct = FALSE) {
2112 2112
 		$related_model = $this->get_related_model_obj($model_name);
2113 2113
 		//we're just going to use the query params on the related model's normal get_all query,
2114 2114
 		//except add a condition to say to match the current mod
2115
-		if( ! isset($query_params['default_where_conditions'])){
2116
-			$query_params['default_where_conditions']='none';
2115
+		if ( ! isset($query_params['default_where_conditions'])) {
2116
+			$query_params['default_where_conditions'] = 'none';
2117 2117
 		}
2118 2118
 		$this_model_name = $this->get_this_model_name();
2119 2119
 		$this_pk_field_name = $this->get_primary_key_field()->get_name();
2120
-		$query_params[0][$this_model_name.".".$this_pk_field_name]=$id_or_obj;
2121
-		return $related_model->count($query_params,$field_to_count,$distinct);
2120
+		$query_params[0][$this_model_name.".".$this_pk_field_name] = $id_or_obj;
2121
+		return $related_model->count($query_params, $field_to_count, $distinct);
2122 2122
 	}
2123 2123
 
2124 2124
 
@@ -2132,21 +2132,21 @@  discard block
 block discarded – undo
2132 2132
 	 * @param string $field_to_sum name of field to count by. By default, uses primary key
2133 2133
 	 * @return float
2134 2134
 	 */
2135
-	function sum_related($id_or_obj,$model_name,$query_params,$field_to_sum = null){
2135
+	function sum_related($id_or_obj, $model_name, $query_params, $field_to_sum = null) {
2136 2136
 		$related_model = $this->get_related_model_obj($model_name);
2137
-		if( ! is_array( $query_params ) ){
2138
-			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' );
2137
+		if ( ! is_array($query_params)) {
2138
+			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');
2139 2139
 			$query_params = array();
2140 2140
 		}
2141 2141
 		//we're just going to use the query params on the related model's normal get_all query,
2142 2142
 		//except add a condition to say to match the current mod
2143
-		if( ! isset($query_params['default_where_conditions'])){
2144
-			$query_params['default_where_conditions']='none';
2143
+		if ( ! isset($query_params['default_where_conditions'])) {
2144
+			$query_params['default_where_conditions'] = 'none';
2145 2145
 		}
2146 2146
 		$this_model_name = $this->get_this_model_name();
2147 2147
 		$this_pk_field_name = $this->get_primary_key_field()->get_name();
2148
-		$query_params[0][$this_model_name.".".$this_pk_field_name]=$id_or_obj;
2149
-		return $related_model->sum($query_params,$field_to_sum);
2148
+		$query_params[0][$this_model_name.".".$this_pk_field_name] = $id_or_obj;
2149
+		return $related_model->sum($query_params, $field_to_sum);
2150 2150
 	}
2151 2151
 
2152 2152
 
@@ -2158,12 +2158,12 @@  discard block
 block discarded – undo
2158 2158
 	 * @param array $query_params like EEM_Base::get_all's
2159 2159
 	 * @return EE_Base_Class
2160 2160
 	 */
2161
-	public function get_first_related( EE_Base_Class $id_or_obj, $other_model_name, $query_params ){
2162
-		$query_params['limit']=1;
2163
-		$results = $this->get_all_related($id_or_obj,$other_model_name,$query_params);
2164
-		if( $results ){
2161
+	public function get_first_related(EE_Base_Class $id_or_obj, $other_model_name, $query_params) {
2162
+		$query_params['limit'] = 1;
2163
+		$results = $this->get_all_related($id_or_obj, $other_model_name, $query_params);
2164
+		if ($results) {
2165 2165
 			return array_shift($results);
2166
-		}else{
2166
+		} else {
2167 2167
 			return null;
2168 2168
 		}
2169 2169
 
@@ -2173,8 +2173,8 @@  discard block
 block discarded – undo
2173 2173
 	 * Gets the model's name as it's expected in queries. For example, if this is EEM_Event model, that would be Event
2174 2174
 	 * @return string
2175 2175
 	 */
2176
-	function get_this_model_name(){
2177
-		return str_replace("EEM_","",get_class($this));
2176
+	function get_this_model_name() {
2177
+		return str_replace("EEM_", "", get_class($this));
2178 2178
 	}
2179 2179
 
2180 2180
 	/**
@@ -2182,14 +2182,14 @@  discard block
 block discarded – undo
2182 2182
 	 * @return EE_Any_Foreign_Model_Name_Field
2183 2183
 	 * @throws EE_Error
2184 2184
 	 */
2185
-	public function get_field_containing_related_model_name(){
2186
-		foreach($this->field_settings(true) as $field){
2187
-			if($field instanceof EE_Any_Foreign_Model_Name_Field){
2185
+	public function get_field_containing_related_model_name() {
2186
+		foreach ($this->field_settings(true) as $field) {
2187
+			if ($field instanceof EE_Any_Foreign_Model_Name_Field) {
2188 2188
 				$field_with_model_name = $field;
2189 2189
 			}
2190 2190
 		}
2191
-		if( !isset($field_with_model_name) || !$field_with_model_name ){
2192
-			throw new EE_Error(sprintf(__("There is no EE_Any_Foreign_Model_Name field on model %s", "event_espresso"), $this->get_this_model_name() ));
2191
+		if ( ! isset($field_with_model_name) || ! $field_with_model_name) {
2192
+			throw new EE_Error(sprintf(__("There is no EE_Any_Foreign_Model_Name field on model %s", "event_espresso"), $this->get_this_model_name()));
2193 2193
 		}
2194 2194
 		return $field_with_model_name;
2195 2195
 	}
@@ -2210,19 +2210,19 @@  discard block
 block discarded – undo
2210 2210
 	 * @return int new primary key on main table that got inserted
2211 2211
 	 * @throws EE_Error
2212 2212
 	 */
2213
-	function insert($field_n_values){
2213
+	function insert($field_n_values) {
2214 2214
 		/**
2215 2215
 		 * Filters the fields and their values before inserting an item using the models
2216 2216
 		 * @param array $fields_n_values keys are the fields and values are their new values
2217 2217
 		 * @param EEM_Base $model the model used
2218 2218
 		 */
2219
-		$field_n_values = apply_filters( 'FHEE__EEM_Base__insert__fields_n_values', $field_n_values, $this );
2220
-		if($this->_satisfies_unique_indexes($field_n_values)){
2219
+		$field_n_values = apply_filters('FHEE__EEM_Base__insert__fields_n_values', $field_n_values, $this);
2220
+		if ($this->_satisfies_unique_indexes($field_n_values)) {
2221 2221
 			$main_table = $this->_get_main_table();
2222 2222
 			$new_id = $this->_insert_into_specific_table($main_table, $field_n_values, false);
2223
-			if( $new_id !== false ) {
2224
-				foreach($this->_get_other_tables() as $other_table){
2225
-					$this->_insert_into_specific_table($other_table, $field_n_values,$new_id);
2223
+			if ($new_id !== false) {
2224
+				foreach ($this->_get_other_tables() as $other_table) {
2225
+					$this->_insert_into_specific_table($other_table, $field_n_values, $new_id);
2226 2226
 				}
2227 2227
 			}
2228 2228
 			/**
@@ -2232,9 +2232,9 @@  discard block
 block discarded – undo
2232 2232
 			 * @param array $fields_n_values fields and their values
2233 2233
 			 * @param int|string the ID of the newly-inserted model object
2234 2234
 			 */
2235
-			do_action( 'AHEE__EEM_Base__insert__end', $this, $field_n_values, $new_id );
2235
+			do_action('AHEE__EEM_Base__insert__end', $this, $field_n_values, $new_id);
2236 2236
 			return $new_id;
2237
-		}else{
2237
+		} else {
2238 2238
 			return FALSE;
2239 2239
 		}
2240 2240
 	}
@@ -2247,11 +2247,11 @@  discard block
 block discarded – undo
2247 2247
 	 * @param string $action
2248 2248
 	 * @return boolean
2249 2249
 	 */
2250
-	protected function _satisfies_unique_indexes($field_n_values,$action = 'insert'){
2251
-		foreach($this->unique_indexes() as $index_name => $index){
2250
+	protected function _satisfies_unique_indexes($field_n_values, $action = 'insert') {
2251
+		foreach ($this->unique_indexes() as $index_name => $index) {
2252 2252
 			$uniqueness_where_params = array_intersect_key($field_n_values, $index->fields());
2253
-			if($this->exists(array($uniqueness_where_params))){
2254
-				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__ );
2253
+			if ($this->exists(array($uniqueness_where_params))) {
2254
+				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__);
2255 2255
 				return false;
2256 2256
 			}
2257 2257
 		}
@@ -2272,28 +2272,28 @@  discard block
 block discarded – undo
2272 2272
 	 * @throws EE_Error
2273 2273
 	 * @return EE_Base_Class
2274 2274
 	 */
2275
-	public function get_one_conflicting($obj_or_fields_array, $include_primary_key = true ){
2276
-		if($obj_or_fields_array instanceof EE_Base_Class){
2275
+	public function get_one_conflicting($obj_or_fields_array, $include_primary_key = true) {
2276
+		if ($obj_or_fields_array instanceof EE_Base_Class) {
2277 2277
 			$fields_n_values = $obj_or_fields_array->model_field_array();
2278
-		}elseif( is_array($obj_or_fields_array)){
2278
+		}elseif (is_array($obj_or_fields_array)) {
2279 2279
 			$fields_n_values = $obj_or_fields_array;
2280
-		}else{
2281
-			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));
2280
+		} else {
2281
+			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));
2282 2282
 		}
2283 2283
 		$query_params = array();
2284
-		if( $this->has_primary_key_field() &&
2285
-				( $include_primary_key || $this->get_primary_key_field() instanceof EE_Primary_Key_String_Field) &&
2286
-				isset($fields_n_values[$this->primary_key_name()])){
2284
+		if ($this->has_primary_key_field() &&
2285
+				($include_primary_key || $this->get_primary_key_field() instanceof EE_Primary_Key_String_Field) &&
2286
+				isset($fields_n_values[$this->primary_key_name()])) {
2287 2287
 			$query_params[0]['OR'][$this->primary_key_name()] = $fields_n_values[$this->primary_key_name()];
2288 2288
 		}
2289
-		foreach($this->unique_indexes() as $unique_index_name=>$unique_index){
2289
+		foreach ($this->unique_indexes() as $unique_index_name=>$unique_index) {
2290 2290
 			$uniqueness_where_params = array_intersect_key($fields_n_values, $unique_index->fields());
2291 2291
 			$query_params[0]['OR']['AND*'.$unique_index_name] = $uniqueness_where_params;
2292 2292
 		}
2293 2293
 		//if there is nothing to base this search on, then we shouldn't find anything
2294
-		if( empty( $query_params ) ){
2294
+		if (empty($query_params)) {
2295 2295
 			return array();
2296
-		}else{
2296
+		} else {
2297 2297
 			return $this->get_one($query_params);
2298 2298
 		}
2299 2299
 	}
@@ -2303,7 +2303,7 @@  discard block
 block discarded – undo
2303 2303
 	 * @param array $query_params
2304 2304
 	 * @return boolean
2305 2305
 	 */
2306
-	function exists($query_params){
2306
+	function exists($query_params) {
2307 2307
 		$query_params['limit'] = 1;
2308 2308
 		return $this->count($query_params) > 0;
2309 2309
 	}
@@ -2313,7 +2313,7 @@  discard block
 block discarded – undo
2313 2313
 	 * @param int|string $id
2314 2314
 	 * @return boolean
2315 2315
 	 */
2316
-	function exists_by_ID($id){
2316
+	function exists_by_ID($id) {
2317 2317
 		return $this->exists(array('default_where_conditions'=>'none', array($this->primary_key_name() => $id)));
2318 2318
 	}
2319 2319
 
@@ -2333,45 +2333,45 @@  discard block
 block discarded – undo
2333 2333
 	 * @global WPDB $wpdb only used to get the $wpdb->insert_id after performing an insert
2334 2334
 	 * @return int ID of new row inserted, or FALSE on failure
2335 2335
 	 */
2336
-	protected function _insert_into_specific_table(EE_Table_Base $table, $fields_n_values, $new_id = 0 ){
2336
+	protected function _insert_into_specific_table(EE_Table_Base $table, $fields_n_values, $new_id = 0) {
2337 2337
 		global $wpdb;
2338 2338
 		$insertion_col_n_values = array();
2339 2339
 		$format_for_insertion = array();
2340 2340
 		$fields_on_table = $this->_get_fields_for_table($table->get_table_alias());
2341
-		foreach($fields_on_table as $field_name => $field_obj){
2341
+		foreach ($fields_on_table as $field_name => $field_obj) {
2342 2342
 			//check if its an auto-incrementing column, in which case we should just leave it to do its autoincrement thing
2343
-			if($field_obj->is_auto_increment()){
2343
+			if ($field_obj->is_auto_increment()) {
2344 2344
 				continue;
2345 2345
 			}
2346 2346
 			$prepared_value = $this->_prepare_value_or_use_default($field_obj, $fields_n_values);
2347 2347
 			//if the value we want to assign it to is NULL, just don't mention it for the insertion
2348
-			if( $prepared_value !== NULL ){
2349
-				$insertion_col_n_values[ $field_obj->get_table_column() ] = $prepared_value;
2348
+			if ($prepared_value !== NULL) {
2349
+				$insertion_col_n_values[$field_obj->get_table_column()] = $prepared_value;
2350 2350
 				$format_for_insertion[] = $field_obj->get_wpdb_data_type();
2351 2351
 			}
2352 2352
 		}
2353 2353
 
2354
-		if($table instanceof EE_Secondary_Table && $new_id){
2354
+		if ($table instanceof EE_Secondary_Table && $new_id) {
2355 2355
 			//its not the main table, so we should have already saved the main table's PK which we just inserted
2356 2356
 			//so add the fk to the main table as a column
2357 2357
 			$insertion_col_n_values[$table->get_fk_on_table()] = $new_id;
2358
-			$format_for_insertion[]='%d';//yes right now we're only allowing these foreign keys to be INTs
2358
+			$format_for_insertion[] = '%d'; //yes right now we're only allowing these foreign keys to be INTs
2359 2359
 		}
2360 2360
 		//insert the new entry
2361
-		$result = $this->_do_wpdb_query( 'insert', array( $table->get_table_name(), $insertion_col_n_values, $format_for_insertion ) );
2362
-		if( $result === false ) {
2361
+		$result = $this->_do_wpdb_query('insert', array($table->get_table_name(), $insertion_col_n_values, $format_for_insertion));
2362
+		if ($result === false) {
2363 2363
 			return false;
2364 2364
 		}
2365 2365
 		//ok, now what do we return for the ID of the newly-inserted thing?
2366
-		if($this->has_primary_key_field()){
2367
-			if($this->get_primary_key_field()->is_auto_increment()){
2366
+		if ($this->has_primary_key_field()) {
2367
+			if ($this->get_primary_key_field()->is_auto_increment()) {
2368 2368
 				return $wpdb->insert_id;
2369
-			}else{
2369
+			} else {
2370 2370
 				//it's not an auto-increment primary key, so
2371 2371
 				//it must have been supplied
2372 2372
 				return $fields_n_values[$this->get_primary_key_field()->get_name()];
2373 2373
 			}
2374
-		}else{
2374
+		} else {
2375 2375
 			//we can't return a  primary key because there is none. instead return
2376 2376
 			//a unique string indicating this model
2377 2377
 			return $this->get_index_primary_key_string($fields_n_values);
@@ -2386,15 +2386,15 @@  discard block
 block discarded – undo
2386 2386
 	 * @param array $fields_n_values
2387 2387
 	 * @return mixed string|int|float depending on what the table column will be expecting
2388 2388
 	 */
2389
-	protected function _prepare_value_or_use_default( $field_obj, $fields_n_values ){
2389
+	protected function _prepare_value_or_use_default($field_obj, $fields_n_values) {
2390 2390
 		//if this field doesn't allow nullable, don't allow it
2391
-		if( ! $field_obj->is_nullable() && (
2392
-				! isset( $fields_n_values[ $field_obj->get_name() ] ) ||
2393
-				$fields_n_values[ $field_obj->get_name() ] === NULL ) ){
2394
-			$fields_n_values[ $field_obj->get_name() ] = $field_obj->get_default_value();
2391
+		if ( ! $field_obj->is_nullable() && (
2392
+				! isset($fields_n_values[$field_obj->get_name()]) ||
2393
+				$fields_n_values[$field_obj->get_name()] === NULL )) {
2394
+			$fields_n_values[$field_obj->get_name()] = $field_obj->get_default_value();
2395 2395
 		}
2396
-		$unprepared_value = isset( $fields_n_values[ $field_obj->get_name() ] ) ? $fields_n_values[ $field_obj->get_name() ] : NULL;
2397
-		return $this->_prepare_value_for_use_in_db( $unprepared_value, $field_obj);
2396
+		$unprepared_value = isset($fields_n_values[$field_obj->get_name()]) ? $fields_n_values[$field_obj->get_name()] : NULL;
2397
+		return $this->_prepare_value_for_use_in_db($unprepared_value, $field_obj);
2398 2398
 	}
2399 2399
 
2400 2400
 
@@ -2406,9 +2406,9 @@  discard block
 block discarded – undo
2406 2406
 	 * @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
2407 2407
 	 * @return mixed a value ready for use in the database for insertions, updating, or in a where clause
2408 2408
 	 */
2409
-	private function _prepare_value_for_use_in_db($value, $field){
2410
-		if($field && $field instanceof EE_Model_Field_Base){
2411
-			switch( $this->_values_already_prepared_by_model_object ){
2409
+	private function _prepare_value_for_use_in_db($value, $field) {
2410
+		if ($field && $field instanceof EE_Model_Field_Base) {
2411
+			switch ($this->_values_already_prepared_by_model_object) {
2412 2412
 				/** @noinspection PhpMissingBreakStatementInspection */
2413 2413
 				case self::not_prepared_by_model_object:
2414 2414
 					$value = $field->prepare_for_set($value);
@@ -2419,7 +2419,7 @@  discard block
 block discarded – undo
2419 2419
 					//leave the value alone
2420 2420
 			}
2421 2421
 			return $value;
2422
-		}else{
2422
+		} else {
2423 2423
 			return $value;
2424 2424
 		}
2425 2425
 	}
@@ -2429,13 +2429,13 @@  discard block
 block discarded – undo
2429 2429
 	 * @return EE_Primary_Table
2430 2430
 	 * @throws EE_Error
2431 2431
 	 */
2432
-	protected function _get_main_table(){
2433
-		foreach($this->_tables as $table){
2434
-			if($table instanceof EE_Primary_Table){
2432
+	protected function _get_main_table() {
2433
+		foreach ($this->_tables as $table) {
2434
+			if ($table instanceof EE_Primary_Table) {
2435 2435
 				return $table;
2436 2436
 			}
2437 2437
 		}
2438
-		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)));
2438
+		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)));
2439 2439
 	}
2440 2440
 
2441 2441
 	/**
@@ -2454,7 +2454,7 @@  discard block
 block discarded – undo
2454 2454
 	 */
2455 2455
 	public function second_table() {
2456 2456
 		// grab second table from tables array
2457
-		$second_table = end( $this->_tables );
2457
+		$second_table = end($this->_tables);
2458 2458
 		return $second_table instanceof EE_Secondary_Table ? $second_table->get_table_name() : NULL;
2459 2459
 	}
2460 2460
 
@@ -2467,8 +2467,8 @@  discard block
 block discarded – undo
2467 2467
 	 * @param string $table_alias
2468 2468
 	 * @return EE_Primary_Table | EE_Secondary_Table
2469 2469
 	 */
2470
-	public function get_table_obj_by_alias( $table_alias = '' ) {
2471
-		return isset( $this->_tables[ $table_alias ] ) ? $this->_tables[ $table_alias ] : NULL;
2470
+	public function get_table_obj_by_alias($table_alias = '') {
2471
+		return isset($this->_tables[$table_alias]) ? $this->_tables[$table_alias] : NULL;
2472 2472
 	}
2473 2473
 
2474 2474
 
@@ -2477,10 +2477,10 @@  discard block
 block discarded – undo
2477 2477
 	 * Gets all the tables of type EE_Other_Table from EEM_CPT_Basel_Model::_tables
2478 2478
 	 * @return EE_Secondary_Table[]
2479 2479
 	 */
2480
-	protected function _get_other_tables(){
2481
-		$other_tables =array();
2482
-		foreach($this->_tables as $table_alias => $table){
2483
-			if($table instanceof EE_Secondary_Table){
2480
+	protected function _get_other_tables() {
2481
+		$other_tables = array();
2482
+		foreach ($this->_tables as $table_alias => $table) {
2483
+			if ($table instanceof EE_Secondary_Table) {
2484 2484
 				$other_tables[$table_alias] = $table;
2485 2485
 			}
2486 2486
 		}
@@ -2492,7 +2492,7 @@  discard block
 block discarded – undo
2492 2492
 	 * @param string $table_alias, array key in EEM_Base::_tables
2493 2493
 	 * @return EE_Model_Field_Base[]
2494 2494
 	 */
2495
-	function _get_fields_for_table($table_alias){
2495
+	function _get_fields_for_table($table_alias) {
2496 2496
 		return $this->_fields[$table_alias];
2497 2497
 	}
2498 2498
 
@@ -2504,29 +2504,29 @@  discard block
 block discarded – undo
2504 2504
 	 * @param array $query_params like EEM_Base::get_all's $query_parameters['where']
2505 2505
 	 * @return EE_Model_Query_Info_Carrier
2506 2506
 	 */
2507
-	function _extract_related_models_from_query($query_params){
2507
+	function _extract_related_models_from_query($query_params) {
2508 2508
 		$query_info_carrier = new EE_Model_Query_Info_Carrier();
2509
-		if(array_key_exists(0,$query_params)){
2510
-			$this->_extract_related_models_from_sub_params_array_keys($query_params[0], $query_info_carrier,0);
2511
-		}
2512
-		if(array_key_exists('group_by', $query_params)){
2513
-			if(is_array($query_params['group_by'])){
2514
-				$this->_extract_related_models_from_sub_params_array_values($query_params['group_by'],$query_info_carrier,'group_by');
2515
-			}elseif( ! empty ( $query_params['group_by'] )){
2516
-				$this->_extract_related_model_info_from_query_param( $query_params['group_by'],$query_info_carrier,'group_by');
2509
+		if (array_key_exists(0, $query_params)) {
2510
+			$this->_extract_related_models_from_sub_params_array_keys($query_params[0], $query_info_carrier, 0);
2511
+		}
2512
+		if (array_key_exists('group_by', $query_params)) {
2513
+			if (is_array($query_params['group_by'])) {
2514
+				$this->_extract_related_models_from_sub_params_array_values($query_params['group_by'], $query_info_carrier, 'group_by');
2515
+			}elseif ( ! empty ($query_params['group_by'])) {
2516
+				$this->_extract_related_model_info_from_query_param($query_params['group_by'], $query_info_carrier, 'group_by');
2517 2517
 			}
2518 2518
 		}
2519
-		if(array_key_exists('having',$query_params)){
2520
-			$this->_extract_related_models_from_sub_params_array_keys($query_params[0], $query_info_carrier,'having');
2519
+		if (array_key_exists('having', $query_params)) {
2520
+			$this->_extract_related_models_from_sub_params_array_keys($query_params[0], $query_info_carrier, 'having');
2521 2521
 		}
2522
-		if(array_key_exists('order_by', $query_params)){
2523
-			if ( is_array( $query_params['order_by'] ) )
2524
-				$this->_extract_related_models_from_sub_params_array_keys($query_params['order_by'],$query_info_carrier,'order_by');
2525
-			elseif( ! empty( $query_params['order_by'] ))
2526
-				$this->_extract_related_model_info_from_query_param( $query_params['order_by'], $query_info_carrier,'order_by');
2522
+		if (array_key_exists('order_by', $query_params)) {
2523
+			if (is_array($query_params['order_by']))
2524
+				$this->_extract_related_models_from_sub_params_array_keys($query_params['order_by'], $query_info_carrier, 'order_by');
2525
+			elseif ( ! empty($query_params['order_by']))
2526
+				$this->_extract_related_model_info_from_query_param($query_params['order_by'], $query_info_carrier, 'order_by');
2527 2527
 		}
2528
-		if(array_key_exists('force_join', $query_params)){
2529
-			$this->_extract_related_models_from_sub_params_array_values($query_params['force_join'],$query_info_carrier,'force_join');
2528
+		if (array_key_exists('force_join', $query_params)) {
2529
+			$this->_extract_related_models_from_sub_params_array_values($query_params['force_join'], $query_info_carrier, 'force_join');
2530 2530
 		}
2531 2531
 		return $query_info_carrier;
2532 2532
 	}
@@ -2539,34 +2539,34 @@  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_keys($sub_query_params, EE_Model_Query_Info_Carrier $model_query_info_carrier,$query_param_type){
2543
-		if (!empty($sub_query_params)){
2542
+	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) {
2543
+		if ( ! empty($sub_query_params)) {
2544 2544
 			$sub_query_params = (array) $sub_query_params;
2545
-			foreach($sub_query_params as $param => $possibly_array_of_params){
2545
+			foreach ($sub_query_params as $param => $possibly_array_of_params) {
2546 2546
 				//$param could be simply 'EVT_ID', or it could be 'Registrations.REG_ID', or even 'Registrations.Transactions.Payments.PAY_amount'
2547
-				$this->_extract_related_model_info_from_query_param( $param, $model_query_info_carrier,$query_param_type);
2547
+				$this->_extract_related_model_info_from_query_param($param, $model_query_info_carrier, $query_param_type);
2548 2548
 
2549 2549
 				//if $possibly_array_of_params is an array, try recursing into it, searching for keys which
2550 2550
 				//indicate needed joins. Eg, array('NOT'=>array('Registration.TXN_ID'=>23)). In this case, we tried
2551 2551
 				//extracting models out of the 'NOT', which obviously wasn't successful, and then we recurse into the value
2552 2552
 				//of array('Registration.TXN_ID'=>23)
2553 2553
 				$query_param_sans_stars = $this->_remove_stars_and_anything_after_from_condition_query_param_key($param);
2554
-				if(in_array($query_param_sans_stars, $this->_logic_query_param_keys,true)){
2555
-					if (! is_array($possibly_array_of_params)){
2554
+				if (in_array($query_param_sans_stars, $this->_logic_query_param_keys, true)) {
2555
+					if ( ! is_array($possibly_array_of_params)) {
2556 2556
 						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"),
2557
-							$param,$possibly_array_of_params));
2558
-					}else{
2559
-						$this->_extract_related_models_from_sub_params_array_keys($possibly_array_of_params, $model_query_info_carrier,$query_param_type);
2557
+							$param, $possibly_array_of_params));
2558
+					} else {
2559
+						$this->_extract_related_models_from_sub_params_array_keys($possibly_array_of_params, $model_query_info_carrier, $query_param_type);
2560 2560
 					}
2561
-				}elseif($query_param_type === 0 //ie WHERE
2561
+				}elseif ($query_param_type === 0 //ie WHERE
2562 2562
 						&& is_array($possibly_array_of_params)
2563 2563
 						&& isset($possibly_array_of_params[2])
2564
-						&& $possibly_array_of_params[2] == true){
2564
+						&& $possibly_array_of_params[2] == true) {
2565 2565
 					//then $possible_array_of_params looks something like array('<','DTT_sold',true)
2566 2566
 					//indicating that $possible_array_of_params[1] is actually a field name,
2567 2567
 					//from which we should extract query parameters!
2568
-					if(! isset($possibly_array_of_params[0]) || ! isset($possibly_array_of_params[1])){
2569
-						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)));
2568
+					if ( ! isset($possibly_array_of_params[0]) || ! isset($possibly_array_of_params[1])) {
2569
+						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)));
2570 2570
 					}
2571 2571
 					$this->_extract_related_model_info_from_query_param($possibly_array_of_params[1], $model_query_info_carrier, $query_param_type);
2572 2572
 				}
@@ -2585,14 +2585,14 @@  discard block
 block discarded – undo
2585 2585
 	 * @throws EE_Error
2586 2586
 	 * @return \EE_Model_Query_Info_Carrier
2587 2587
 	 */
2588
-	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){
2589
-		if (!empty($sub_query_params)){
2590
-			if(!is_array($sub_query_params)){
2591
-				throw new EE_Error(sprintf(__("Query parameter %s should be an array, but it isn't.", "event_espresso"),$sub_query_params));
2588
+	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) {
2589
+		if ( ! empty($sub_query_params)) {
2590
+			if ( ! is_array($sub_query_params)) {
2591
+				throw new EE_Error(sprintf(__("Query parameter %s should be an array, but it isn't.", "event_espresso"), $sub_query_params));
2592 2592
 			}
2593
-			foreach($sub_query_params as $param){
2593
+			foreach ($sub_query_params as $param) {
2594 2594
 				//$param could be simply 'EVT_ID', or it could be 'Registrations.REG_ID', or even 'Registrations.Transactions.Payments.PAY_amount'
2595
-				$this->_extract_related_model_info_from_query_param( $param, $model_query_info_carrier, $query_param_type);
2595
+				$this->_extract_related_model_info_from_query_param($param, $model_query_info_carrier, $query_param_type);
2596 2596
 			}
2597 2597
 		}
2598 2598
 		return $model_query_info_carrier;
@@ -2611,81 +2611,81 @@  discard block
 block discarded – undo
2611 2611
 	 * @throws EE_Error
2612 2612
 	 * @return EE_Model_Query_Info_Carrier
2613 2613
 	 */
2614
-	function _create_model_query_info_carrier($query_params){
2615
-		if( ! is_array( $query_params ) ){
2616
-			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' );
2614
+	function _create_model_query_info_carrier($query_params) {
2615
+		if ( ! is_array($query_params)) {
2616
+			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');
2617 2617
 			$query_params = array();
2618 2618
 		}
2619
-		if( isset( $query_params[0] ) ) {
2619
+		if (isset($query_params[0])) {
2620 2620
 			$where_query_params = $query_params[0];
2621
-		}else{
2621
+		} else {
2622 2622
 			$where_query_params = array();
2623 2623
 		}
2624 2624
 		//first check if we should alter the query to account for caps or not
2625 2625
 		//because the caps might require us to do extra joins
2626
-		if( isset( $query_params[ 'caps' ] ) && $query_params[ 'caps' ] != 'none' ) {
2627
-			$query_params[0] = $where_query_params = array_replace_recursive( $where_query_params, $this->caps_where_conditions( $query_params[ 'caps' ] ) );
2626
+		if (isset($query_params['caps']) && $query_params['caps'] != 'none') {
2627
+			$query_params[0] = $where_query_params = array_replace_recursive($where_query_params, $this->caps_where_conditions($query_params['caps']));
2628 2628
 		}
2629 2629
 		$query_object = $this->_extract_related_models_from_query($query_params);
2630 2630
 
2631 2631
 		//verify where_query_params has NO numeric indexes.... that's simply not how you use it!
2632
-		foreach($where_query_params as $key => $value){
2633
-			if(is_int($key)){
2634
-				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)));
2632
+		foreach ($where_query_params as $key => $value) {
2633
+			if (is_int($key)) {
2634
+				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)));
2635 2635
 			}
2636 2636
 		}
2637
-		if( array_key_exists( 'default_where_conditions',$query_params) && ! empty( $query_params['default_where_conditions'] )){
2637
+		if (array_key_exists('default_where_conditions', $query_params) && ! empty($query_params['default_where_conditions'])) {
2638 2638
 			$use_default_where_conditions = $query_params['default_where_conditions'];
2639
-		}else{
2639
+		} else {
2640 2640
 			$use_default_where_conditions = 'all';
2641 2641
 		}
2642
-		$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 );
2643
-		$query_object->set_where_sql( $this->_construct_where_clause($where_query_params));
2642
+		$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);
2643
+		$query_object->set_where_sql($this->_construct_where_clause($where_query_params));
2644 2644
 
2645 2645
 
2646 2646
 		//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:
2647 2647
 		//array( 'on_join_limit' => array('Primary_Table_Alias', array(1,10) ) )
2648
-		if ( array_key_exists('on_join_limit', $query_params ) && ! empty( $query_params['on_join_limit'] )) {
2649
-			$query_object->set_main_model_join_sql( $this->_construct_limit_join_select( $query_params['on_join_limit'][0], $query_params['on_join_limit'][1] ) );
2648
+		if (array_key_exists('on_join_limit', $query_params) && ! empty($query_params['on_join_limit'])) {
2649
+			$query_object->set_main_model_join_sql($this->_construct_limit_join_select($query_params['on_join_limit'][0], $query_params['on_join_limit'][1]));
2650 2650
 		}
2651 2651
 
2652 2652
 
2653 2653
 		//set limit
2654
-		if(array_key_exists('limit',$query_params)){
2655
-			if(is_array($query_params['limit'])){
2656
-				if( ! isset($query_params['limit'][0]) || ! isset($query_params['limit'][1])){
2657
-					$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']));
2654
+		if (array_key_exists('limit', $query_params)) {
2655
+			if (is_array($query_params['limit'])) {
2656
+				if ( ! isset($query_params['limit'][0]) || ! isset($query_params['limit'][1])) {
2657
+					$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']));
2658 2658
 					throw new EE_Error($e."|".$e);
2659 2659
 				}
2660 2660
 				//they passed us an array for the limit. Assume it's like array(50,25), meaning offset by 50, and get 25
2661 2661
 				$query_object->set_limit_sql(" LIMIT ".$query_params['limit'][0].",".$query_params['limit'][1]);
2662
-			}elseif( ! empty ( $query_params['limit'] )){
2662
+			}elseif ( ! empty ($query_params['limit'])) {
2663 2663
 				$query_object->set_limit_sql((" LIMIT ".$query_params['limit']));
2664 2664
 			}
2665 2665
 		}
2666 2666
 		//set order by
2667
-		if(array_key_exists('order_by',$query_params)){
2668
-			if(is_array($query_params['order_by'])){
2667
+		if (array_key_exists('order_by', $query_params)) {
2668
+			if (is_array($query_params['order_by'])) {
2669 2669
 				//if they're using 'order_by' as an array, they can't use 'order' (because 'order_by' must
2670 2670
 				//specify whether to ascend or descend on each field. Eg 'order_by'=>array('EVT_ID'=>'ASC'). So
2671 2671
 				//including 'order' wouldn't make any sense if 'order_by' has already specified which way to order!
2672
-				if(array_key_exists('order', $query_params)){
2672
+				if (array_key_exists('order', $query_params)) {
2673 2673
 					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"),
2674
-							get_class($this),implode(", ",array_keys($query_params['order_by'])),implode(", ",$query_params['order_by']),$query_params['order']));
2674
+							get_class($this), implode(", ", array_keys($query_params['order_by'])), implode(", ", $query_params['order_by']), $query_params['order']));
2675 2675
 				}
2676
-				 $this->_extract_related_models_from_sub_params_array_keys($query_params['order_by'],$query_object,'order_by');
2676
+				 $this->_extract_related_models_from_sub_params_array_keys($query_params['order_by'], $query_object, 'order_by');
2677 2677
 				//assume it's an array of fields to order by
2678 2678
 				$order_array = array();
2679
-				foreach($query_params['order_by'] as $field_name_to_order_by => $order){
2679
+				foreach ($query_params['order_by'] as $field_name_to_order_by => $order) {
2680 2680
 					$order = $this->_extract_order($order);
2681 2681
 					$order_array[] = $this->_deduce_column_name_from_query_param($field_name_to_order_by).SP.$order;
2682 2682
 				}
2683
-				$query_object->set_order_by_sql(" ORDER BY ".implode(",",$order_array));
2684
-			}elseif( ! empty ( $query_params['order_by'] )){
2685
-				$this->_extract_related_model_info_from_query_param($query_params['order_by'],$query_object,'order',$query_params['order_by']);
2686
-				if(isset($query_params['order'])){
2683
+				$query_object->set_order_by_sql(" ORDER BY ".implode(",", $order_array));
2684
+			}elseif ( ! empty ($query_params['order_by'])) {
2685
+				$this->_extract_related_model_info_from_query_param($query_params['order_by'], $query_object, 'order', $query_params['order_by']);
2686
+				if (isset($query_params['order'])) {
2687 2687
 					$order = $this->_extract_order($query_params['order']);
2688
-				}else{
2688
+				} else {
2689 2689
 					$order = 'DESC';
2690 2690
 				}
2691 2691
 				$query_object->set_order_by_sql(" ORDER BY ".$this->_deduce_column_name_from_query_param($query_params['order_by']).SP.$order);
@@ -2693,46 +2693,46 @@  discard block
 block discarded – undo
2693 2693
 		}
2694 2694
 
2695 2695
 		//if 'order_by' wasn't set, maybe they are just using 'order' on its own?
2696
-		if( ! array_key_exists('order_by',$query_params) && array_key_exists('order',$query_params) && ! empty( $query_params['order'] )){
2696
+		if ( ! array_key_exists('order_by', $query_params) && array_key_exists('order', $query_params) && ! empty($query_params['order'])) {
2697 2697
 			$pk_field = $this->get_primary_key_field();
2698 2698
 			$order = $this->_extract_order($query_params['order']);
2699 2699
 			$query_object->set_order_by_sql(" ORDER BY ".$pk_field->get_qualified_column().SP.$order);
2700 2700
 		}
2701 2701
 
2702 2702
 		//set group by
2703
-		if(array_key_exists('group_by',$query_params)){
2704
-			if(is_array($query_params['group_by'])){
2703
+		if (array_key_exists('group_by', $query_params)) {
2704
+			if (is_array($query_params['group_by'])) {
2705 2705
 				//it's an array, so assume we'll be grouping by a bunch of stuff
2706 2706
 				$group_by_array = array();
2707
-				foreach($query_params['group_by'] as $field_name_to_group_by){
2707
+				foreach ($query_params['group_by'] as $field_name_to_group_by) {
2708 2708
 					$group_by_array[] = $this->_deduce_column_name_from_query_param($field_name_to_group_by);
2709 2709
 				}
2710
-				$query_object->set_group_by_sql(" GROUP BY ".implode(", ",$group_by_array));
2711
-			}elseif( ! empty ( $query_params['group_by'] )){
2710
+				$query_object->set_group_by_sql(" GROUP BY ".implode(", ", $group_by_array));
2711
+			}elseif ( ! empty ($query_params['group_by'])) {
2712 2712
 				$query_object->set_group_by_sql(" GROUP BY ".$this->_deduce_column_name_from_query_param($query_params['group_by']));
2713 2713
 			}
2714 2714
 		}
2715 2715
 		//set having
2716
-		if(array_key_exists('having',$query_params) && $query_params['having']){
2717
-			$query_object->set_having_sql( $this->_construct_having_clause($query_params['having']));
2716
+		if (array_key_exists('having', $query_params) && $query_params['having']) {
2717
+			$query_object->set_having_sql($this->_construct_having_clause($query_params['having']));
2718 2718
 		}
2719 2719
 
2720 2720
 		//now, just verify they didn't pass anything wack
2721
-		foreach($query_params as $query_key => $query_value){
2722
-			if( ! in_array($query_key,$this->_allowed_query_params,true)){
2721
+		foreach ($query_params as $query_key => $query_value) {
2722
+			if ( ! in_array($query_key, $this->_allowed_query_params, true)) {
2723 2723
 				throw new EE_Error(
2724 2724
 					sprintf(
2725
-						__("You passed %s as a query parameter to %s, which is illegal! The allowed query parameters are %s",'event_espresso'),
2725
+						__("You passed %s as a query parameter to %s, which is illegal! The allowed query parameters are %s", 'event_espresso'),
2726 2726
 						$query_key,
2727 2727
 						get_class($this),
2728 2728
 //						print_r( $this->_allowed_query_params, TRUE )
2729
-						implode( ',', $this->_allowed_query_params )
2729
+						implode(',', $this->_allowed_query_params)
2730 2730
 					)
2731 2731
 				);
2732 2732
 			}
2733 2733
 		}
2734 2734
 		$main_model_join_sql = $query_object->get_main_model_join_sql();
2735
-		if ( empty( $main_model_join_sql ) )
2735
+		if (empty($main_model_join_sql))
2736 2736
 			$query_object->set_main_model_join_sql($this->_construct_internal_join());
2737 2737
 		return $query_object;
2738 2738
 	}
@@ -2743,17 +2743,17 @@  discard block
 block discarded – undo
2743 2743
 	 * @param string $context one of EEM_Base::valid_cap_contexts()
2744 2744
 	 * @return array like EEM_Base::get_all() 's $query_params[0]
2745 2745
 	 */
2746
-	public function caps_where_conditions( $context = self::caps_read ) {
2747
-		EEM_Base::verify_is_valid_cap_context( $context );
2746
+	public function caps_where_conditions($context = self::caps_read) {
2747
+		EEM_Base::verify_is_valid_cap_context($context);
2748 2748
 		$cap_where_conditions = array();
2749
-		$cap_restrictions = $this->caps_missing( $context );
2749
+		$cap_restrictions = $this->caps_missing($context);
2750 2750
 		/**
2751 2751
 		 * @var $cap_restrictions EE_Default_Where_Conditions[]
2752 2752
 		 */
2753
-		foreach( $cap_restrictions as $cap => $restriction_if_no_cap ) {
2754
-				$cap_where_conditions = array_replace_recursive( $cap_where_conditions, $restriction_if_no_cap->get_default_where_conditions() );
2753
+		foreach ($cap_restrictions as $cap => $restriction_if_no_cap) {
2754
+				$cap_where_conditions = array_replace_recursive($cap_where_conditions, $restriction_if_no_cap->get_default_where_conditions());
2755 2755
 		}
2756
-		return apply_filters( 'FHEE__EEM_Base__caps_where_conditions__return', $cap_where_conditions, $this, $context, $cap_restrictions );
2756
+		return apply_filters('FHEE__EEM_Base__caps_where_conditions__return', $cap_where_conditions, $this, $context, $cap_restrictions);
2757 2757
 	}
2758 2758
 
2759 2759
 	/**
@@ -2763,11 +2763,11 @@  discard block
 block discarded – undo
2763 2763
 	 * @return string either ASC, asc, DESC or desc
2764 2764
 	 * @throws EE_Error
2765 2765
 	 */
2766
-	private function _extract_order($should_be_order_string){
2767
-		if(in_array($should_be_order_string, $this->_allowed_order_values)){
2766
+	private function _extract_order($should_be_order_string) {
2767
+		if (in_array($should_be_order_string, $this->_allowed_order_values)) {
2768 2768
 			return $should_be_order_string;
2769
-		}else{
2770
-			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));
2769
+		} else {
2770
+			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));
2771 2771
 		}
2772 2772
 	}
2773 2773
 
@@ -2785,7 +2785,7 @@  discard block
 block discarded – undo
2785 2785
 	 * @throws EE_Error
2786 2786
 	 * @return array like $query_params[0], see EEM_Base::get_all for documentation
2787 2787
 	 */
2788
-	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()){
2788
+	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()) {
2789 2789
 		$allowed_used_default_where_conditions_values = array(
2790 2790
 				'all',
2791 2791
 				'this_model_only',
@@ -2793,19 +2793,19 @@  discard block
 block discarded – undo
2793 2793
 				'minimum',
2794 2794
 				'none'
2795 2795
 			);
2796
-		if( ! in_array($use_default_where_conditions,$allowed_used_default_where_conditions_values)){
2797
-			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)));
2796
+		if ( ! in_array($use_default_where_conditions, $allowed_used_default_where_conditions_values)) {
2797
+			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)));
2798 2798
 		}
2799
-		if( in_array($use_default_where_conditions, array('all','this_model_only')) ){
2799
+		if (in_array($use_default_where_conditions, array('all', 'this_model_only'))) {
2800 2800
 			$universal_query_params = $this->_get_default_where_conditions();
2801
-		}elseif( in_array( $use_default_where_conditions, array( 'minimum' ) ) ) {
2801
+		}elseif (in_array($use_default_where_conditions, array('minimum'))) {
2802 2802
 			$universal_query_params = $this->_get_minimum_where_conditions();
2803
-		}else{
2803
+		} else {
2804 2804
 			$universal_query_params = array();
2805 2805
 		}
2806 2806
 
2807
-		if(in_array($use_default_where_conditions,array('all','other_models_only'))){
2808
-			foreach($query_info_carrier->get_model_names_included() as $model_relation_path => $model_name){
2807
+		if (in_array($use_default_where_conditions, array('all', 'other_models_only'))) {
2808
+			foreach ($query_info_carrier->get_model_names_included() as $model_relation_path => $model_name) {
2809 2809
 				$related_model = $this->get_related_model_obj($model_name);
2810 2810
 				$related_model_universal_where_params = $related_model->_get_default_where_conditions($model_relation_path);
2811 2811
 
@@ -2832,22 +2832,22 @@  discard block
 block discarded – undo
2832 2832
 	 * @param string $model_relation_path like 'Transaction.Payment.'
2833 2833
 	 * @return array like EEM_Base::get_all's $query_params[0]
2834 2834
 	 */
2835
-	private function _override_defaults_or_make_null_friendly($default_where_conditions,$provided_where_conditions,$model,$model_relation_path){
2835
+	private function _override_defaults_or_make_null_friendly($default_where_conditions, $provided_where_conditions, $model, $model_relation_path) {
2836 2836
 		$null_friendly_where_conditions = array();
2837 2837
 		$none_overridden = true;
2838 2838
 		$or_condition_key_for_defaults = 'OR*'.get_class($model);
2839 2839
 
2840
-		foreach($default_where_conditions as $key => $val){
2841
-			if( isset($provided_where_conditions[$key])){
2840
+		foreach ($default_where_conditions as $key => $val) {
2841
+			if (isset($provided_where_conditions[$key])) {
2842 2842
 				$none_overridden = false;
2843
-			}else{
2843
+			} else {
2844 2844
 				$null_friendly_where_conditions[$or_condition_key_for_defaults]['AND'][$key] = $val;
2845 2845
 			}
2846 2846
 		}
2847
-		if( $none_overridden && $default_where_conditions){
2848
-			if($model->has_primary_key_field()){
2847
+		if ($none_overridden && $default_where_conditions) {
2848
+			if ($model->has_primary_key_field()) {
2849 2849
 				$null_friendly_where_conditions[$or_condition_key_for_defaults][$model_relation_path.".".$model->primary_key_name()] = array('IS NULL');
2850
-			}else{
2850
+			} else {
2851 2851
 				//@todo NO PK, use other defaults
2852 2852
 			}
2853 2853
 		}
@@ -2862,8 +2862,8 @@  discard block
 block discarded – undo
2862 2862
 	 * @param string $model_relation_path eg, path from Event to Payment is "Registration.Transaction.Payment."
2863 2863
 	 * @return array like EEM_Base::get_all's $query_params[0] (where conditions)
2864 2864
 	 */
2865
-	private function _get_default_where_conditions($model_relation_path = null){
2866
-		if ( $this->_ignore_where_strategy )
2865
+	private function _get_default_where_conditions($model_relation_path = null) {
2866
+		if ($this->_ignore_where_strategy)
2867 2867
 			return array();
2868 2868
 
2869 2869
 		return $this->_default_where_conditions_strategy->get_default_where_conditions($model_relation_path);
@@ -2877,8 +2877,8 @@  discard block
 block discarded – undo
2877 2877
 	 * @param string $model_relation_path eg, path from Event to Payment is "Registration.Transaction.Payment."
2878 2878
 	 * @return array like EEM_Base::get_all's $query_params[0] (where conditions)
2879 2879
 	 */
2880
-	protected function _get_minimum_where_conditions($model_relation_path = null){
2881
-		if ( $this->_ignore_where_strategy )
2880
+	protected function _get_minimum_where_conditions($model_relation_path = null) {
2881
+		if ($this->_ignore_where_strategy)
2882 2882
 			return array();
2883 2883
 
2884 2884
 		return $this->_minimum_where_conditions_strategy->get_default_where_conditions($model_relation_path);
@@ -2889,13 +2889,13 @@  discard block
 block discarded – undo
2889 2889
 	 * @param EE_Model_Query_Info_Carrier $model_query_info
2890 2890
 	 * @return string
2891 2891
 	 */
2892
-	private function _construct_default_select_sql(EE_Model_Query_Info_Carrier $model_query_info){
2892
+	private function _construct_default_select_sql(EE_Model_Query_Info_Carrier $model_query_info) {
2893 2893
 		$selects = $this->_get_columns_to_select_for_this_model();
2894
-		foreach($model_query_info->get_model_names_included() as $model_relation_chain => $name_of_other_model_included){
2894
+		foreach ($model_query_info->get_model_names_included() as $model_relation_chain => $name_of_other_model_included) {
2895 2895
 			$other_model_included = $this->get_related_model_obj($name_of_other_model_included);
2896 2896
 			$selects = array_merge($selects, $other_model_included->_get_columns_to_select_for_this_model($model_relation_chain));
2897 2897
 		}
2898
-		return implode(", ",$selects);
2898
+		return implode(", ", $selects);
2899 2899
 	}
2900 2900
 
2901 2901
 	/**
@@ -2904,19 +2904,19 @@  discard block
 block discarded – undo
2904 2904
 	 * @param string $model_relation_chain like 'Question.Question_Group.Event'
2905 2905
 	 * @return array numerically indexed, values are columns to select and rename, eg "Event.ID AS 'Event.ID'"
2906 2906
 	 */
2907
-	public function _get_columns_to_select_for_this_model($model_relation_chain = ''){
2907
+	public function _get_columns_to_select_for_this_model($model_relation_chain = '') {
2908 2908
 		$fields = $this->field_settings();
2909 2909
 		$selects = array();
2910 2910
 		$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());
2911
-		foreach($fields as $field_obj){
2912
-			$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()."'";
2911
+		foreach ($fields as $field_obj) {
2912
+			$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()."'";
2913 2913
 		}
2914 2914
 		//make sure we are also getting the PKs of each table
2915 2915
 		$tables = $this->get_tables();
2916
-		if(count($tables) > 1){
2917
-			foreach($tables as $table_obj){
2918
-				$qualified_pk_column = $table_alias_with_model_relation_chain_prefix . $table_obj->get_fully_qualified_pk_column();
2919
-				if( ! in_array($qualified_pk_column,$selects)){
2916
+		if (count($tables) > 1) {
2917
+			foreach ($tables as $table_obj) {
2918
+				$qualified_pk_column = $table_alias_with_model_relation_chain_prefix.$table_obj->get_fully_qualified_pk_column();
2919
+				if ( ! in_array($qualified_pk_column, $selects)) {
2920 2920
 					$selects[] = "$qualified_pk_column AS '$qualified_pk_column'";
2921 2921
 				}
2922 2922
 			}
@@ -2940,66 +2940,66 @@  discard block
 block discarded – undo
2940 2940
 	 * @throws EE_Error
2941 2941
 	 * @return void only modifies the EEM_Related_Model_Info_Carrier passed into it
2942 2942
 	 */
2943
-	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 ){
2944
-		if($original_query_param == NULL){
2943
+	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) {
2944
+		if ($original_query_param == NULL) {
2945 2945
 			$original_query_param = $query_param;
2946 2946
 		}
2947 2947
 		$query_param = $this->_remove_stars_and_anything_after_from_condition_query_param_key($query_param);
2948 2948
 		/** @var $allow_logic_query_params bool whether or not to allow logic_query_params like 'NOT','OR', or 'AND' */
2949
-		$allow_logic_query_params = in_array($query_param_type,array('where','having'));
2950
-		$allow_fields = in_array($query_param_type,array('where','having','order_by','group_by','order'));
2949
+		$allow_logic_query_params = in_array($query_param_type, array('where', 'having'));
2950
+		$allow_fields = in_array($query_param_type, array('where', 'having', 'order_by', 'group_by', 'order'));
2951 2951
 		//check to see if we have a field on this model
2952 2952
 		$this_model_fields = $this->field_settings(true);
2953
-		if(array_key_exists($query_param,$this_model_fields)){
2954
-			if($allow_fields){
2953
+		if (array_key_exists($query_param, $this_model_fields)) {
2954
+			if ($allow_fields) {
2955 2955
 				return;
2956
-			}else{
2956
+			} else {
2957 2957
 				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"),
2958
-						$query_param,get_class($this),$query_param_type,$original_query_param));
2958
+						$query_param, get_class($this), $query_param_type, $original_query_param));
2959 2959
 			}
2960 2960
 		}
2961 2961
 		//check if this is a special logic query param
2962
-		elseif(in_array($query_param, $this->_logic_query_param_keys, TRUE)){
2963
-			if($allow_logic_query_params){
2962
+		elseif (in_array($query_param, $this->_logic_query_param_keys, TRUE)) {
2963
+			if ($allow_logic_query_params) {
2964 2964
 				return;
2965
-			}else{
2965
+			} else {
2966 2966
 				throw new EE_Error(
2967 2967
 					sprintf(
2968
-						__( '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' ),
2969
-						implode( '", "', $this->_logic_query_param_keys ),
2970
-						$query_param ,
2971
-						get_class( $this ),
2968
+						__('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'),
2969
+						implode('", "', $this->_logic_query_param_keys),
2970
+						$query_param,
2971
+						get_class($this),
2972 2972
 						'<br />',
2973
-						"\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
2973
+						"\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
2974 2974
 					)
2975 2975
 				);
2976 2976
 			}
2977 2977
 		}
2978 2978
 
2979 2979
 		//check if it's a custom selection
2980
-		elseif(array_key_exists($query_param,$this->_custom_selections)){
2980
+		elseif (array_key_exists($query_param, $this->_custom_selections)) {
2981 2981
 			return;
2982 2982
 		}
2983 2983
 
2984 2984
 		//check if has a model name at the beginning
2985 2985
 		//and
2986 2986
 		//check if it's a field on a related model
2987
-		foreach($this->_model_relations as $valid_related_model_name=>$relation_obj){
2988
-			if(strpos($query_param, $valid_related_model_name.".") === 0){
2989
-				$this->_add_join_to_model($valid_related_model_name, $passed_in_query_info,$original_query_param);
2987
+		foreach ($this->_model_relations as $valid_related_model_name=>$relation_obj) {
2988
+			if (strpos($query_param, $valid_related_model_name.".") === 0) {
2989
+				$this->_add_join_to_model($valid_related_model_name, $passed_in_query_info, $original_query_param);
2990 2990
 				$query_param = substr($query_param, strlen($valid_related_model_name."."));
2991
-				if($query_param == ''){
2991
+				if ($query_param == '') {
2992 2992
 					//nothing left to $query_param
2993 2993
 					//we should actually end in a field name, not a model like this!
2994 2994
 					throw new EE_Error(sprintf(__("Query param '%s' (of type %s on model %s) shouldn't end on a period (.) ", "event_espresso"),
2995
-					$query_param,$query_param_type,get_class($this),$valid_related_model_name));
2996
-				}else{
2995
+					$query_param, $query_param_type, get_class($this), $valid_related_model_name));
2996
+				} else {
2997 2997
 					$related_model_obj = $this->get_related_model_obj($valid_related_model_name);
2998 2998
 					$related_model_obj->_extract_related_model_info_from_query_param($query_param, $passed_in_query_info, $query_param_type, $original_query_param);
2999 2999
 					return;
3000 3000
 				}
3001
-			}elseif($query_param == $valid_related_model_name){
3002
-				$this->_add_join_to_model($valid_related_model_name, $passed_in_query_info,$original_query_param);
3001
+			}elseif ($query_param == $valid_related_model_name) {
3002
+				$this->_add_join_to_model($valid_related_model_name, $passed_in_query_info, $original_query_param);
3003 3003
 				return;
3004 3004
 			}
3005 3005
 		}
@@ -3009,7 +3009,7 @@  discard block
 block discarded – undo
3009 3009
 		//and we previously confirmed it wasn't a logic query param or field on the current model
3010 3010
 		//it's wack, that's what it is
3011 3011
 		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"),
3012
-				$query_param,get_class($this),$query_param_type,$original_query_param));
3012
+				$query_param, get_class($this), $query_param_type, $original_query_param));
3013 3013
 
3014 3014
 	}
3015 3015
 
@@ -3026,26 +3026,26 @@  discard block
 block discarded – undo
3026 3026
 	 * 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)
3027 3027
 	 * @return void
3028 3028
 	 */
3029
-	private function _add_join_to_model($model_name, EE_Model_Query_Info_Carrier $passed_in_query_info,$original_query_param){
3029
+	private function _add_join_to_model($model_name, EE_Model_Query_Info_Carrier $passed_in_query_info, $original_query_param) {
3030 3030
 		$relation_obj = $this->related_settings_for($model_name);
3031 3031
 
3032 3032
 		$model_relation_chain = EE_Model_Parser::extract_model_relation_chain($model_name, $original_query_param);
3033 3033
 		//check if the relation is HABTM, because then we're essentially doing two joins
3034 3034
 		//If so, join first to the JOIN table, and add its data types, and then continue as normal
3035
-		if($relation_obj instanceof EE_HABTM_Relation){
3035
+		if ($relation_obj instanceof EE_HABTM_Relation) {
3036 3036
 			$join_model_obj = $relation_obj->get_join_model();
3037 3037
 			//replace the model specified with the join model for this relation chain, whi
3038 3038
 			$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);
3039 3039
 			$new_query_info = new EE_Model_Query_Info_Carrier(
3040 3040
 					array($relation_chain_to_join_model => $join_model_obj->get_this_model_name()),
3041 3041
 					$relation_obj->get_join_to_intermediate_model_statement($relation_chain_to_join_model));
3042
-			$passed_in_query_info->merge( $new_query_info  );
3042
+			$passed_in_query_info->merge($new_query_info);
3043 3043
 		}
3044 3044
 		//now just join to the other table pointed to by the relation object, and add its data types
3045 3045
 		$new_query_info = new EE_Model_Query_Info_Carrier(
3046 3046
 				array($model_relation_chain=>$model_name),
3047 3047
 				$relation_obj->get_join_statement($model_relation_chain));
3048
-		$passed_in_query_info->merge( $new_query_info  );
3048
+		$passed_in_query_info->merge($new_query_info);
3049 3049
 	}
3050 3050
 
3051 3051
 
@@ -3054,11 +3054,11 @@  discard block
 block discarded – undo
3054 3054
 	 * @param array $where_params like EEM_Base::get_all
3055 3055
 	 * @return string of SQL
3056 3056
 	 */
3057
-	private function _construct_where_clause($where_params){
3057
+	private function _construct_where_clause($where_params) {
3058 3058
 		$SQL = $this->_construct_condition_clause_recursive($where_params, ' AND ');
3059
-		if($SQL){
3060
-			return " WHERE ". $SQL;
3061
-		}else{
3059
+		if ($SQL) {
3060
+			return " WHERE ".$SQL;
3061
+		} else {
3062 3062
 			return '';
3063 3063
 		}
3064 3064
 	}
@@ -3069,11 +3069,11 @@  discard block
 block discarded – undo
3069 3069
 	 * @param array $having_params
3070 3070
 	 * @return string
3071 3071
 	 */
3072
-	private function _construct_having_clause($having_params){
3072
+	private function _construct_having_clause($having_params) {
3073 3073
 		$SQL = $this->_construct_condition_clause_recursive($having_params, ' AND ');
3074
-		if($SQL){
3075
-			return " HAVING ". $SQL;
3076
-		}else{
3074
+		if ($SQL) {
3075
+			return " HAVING ".$SQL;
3076
+		} else {
3077 3077
 			return '';
3078 3078
 		}
3079 3079
 
@@ -3087,17 +3087,17 @@  discard block
 block discarded – undo
3087 3087
 	 * @return EE_Model_Field_Base
3088 3088
 	 * @throws EE_Error
3089 3089
 	 */
3090
-	protected function _get_field_on_model($field_name,$model_name){
3090
+	protected function _get_field_on_model($field_name, $model_name) {
3091 3091
 		$model_class = 'EEM_'.$model_name;
3092 3092
 		$model_filepath = $model_class.".model.php";
3093
-		EE_Registry::instance()->load_helper( 'File' );
3094
-		if ( is_readable($model_filepath)){
3093
+		EE_Registry::instance()->load_helper('File');
3094
+		if (is_readable($model_filepath)) {
3095 3095
 			require_once($model_filepath);
3096
-			$model_instance=call_user_func($model_name."::instance");
3096
+			$model_instance = call_user_func($model_name."::instance");
3097 3097
 			/* @var $model_instance EEM_Base */
3098 3098
 			return $model_instance->field_settings_for($field_name);
3099
-		}else{
3100
-			throw new EE_Error(sprintf(__('No model named %s exists, with classname %s and filepath %s','event_espresso'),$model_name,$model_class,$model_filepath));
3099
+		} else {
3100
+			throw new EE_Error(sprintf(__('No model named %s exists, with classname %s and filepath %s', 'event_espresso'), $model_name, $model_class, $model_filepath));
3101 3101
 		}
3102 3102
 	}
3103 3103
 
@@ -3110,43 +3110,43 @@  discard block
 block discarded – undo
3110 3110
 	 * @throws EE_Error
3111 3111
 	 * @return string of SQL
3112 3112
 	 */
3113
-	private function _construct_condition_clause_recursive($where_params, $glue = ' AND'){
3114
-		$where_clauses=array();
3115
-		foreach($where_params as $query_param => $op_and_value_or_sub_condition){
3116
-			$query_param = $this->_remove_stars_and_anything_after_from_condition_query_param_key($query_param);//str_replace("*",'',$query_param);
3117
-			if(in_array($query_param,$this->_logic_query_param_keys)){
3118
-				switch($query_param){
3113
+	private function _construct_condition_clause_recursive($where_params, $glue = ' AND') {
3114
+		$where_clauses = array();
3115
+		foreach ($where_params as $query_param => $op_and_value_or_sub_condition) {
3116
+			$query_param = $this->_remove_stars_and_anything_after_from_condition_query_param_key($query_param); //str_replace("*",'',$query_param);
3117
+			if (in_array($query_param, $this->_logic_query_param_keys)) {
3118
+				switch ($query_param) {
3119 3119
 					case 'not':
3120 3120
 					case 'NOT':
3121
-						$where_clauses[] = "! (". $this->_construct_condition_clause_recursive($op_and_value_or_sub_condition, $glue).")";
3121
+						$where_clauses[] = "! (".$this->_construct_condition_clause_recursive($op_and_value_or_sub_condition, $glue).")";
3122 3122
 						break;
3123 3123
 					case 'and':
3124 3124
 					case 'AND':
3125
-						$where_clauses[] = " (". $this->_construct_condition_clause_recursive($op_and_value_or_sub_condition, ' AND ') .")";
3125
+						$where_clauses[] = " (".$this->_construct_condition_clause_recursive($op_and_value_or_sub_condition, ' AND ').")";
3126 3126
 						break;
3127 3127
 					case 'or':
3128 3128
 					case 'OR':
3129
-						$where_clauses[] = " (". $this->_construct_condition_clause_recursive($op_and_value_or_sub_condition, ' OR ') .")";
3129
+						$where_clauses[] = " (".$this->_construct_condition_clause_recursive($op_and_value_or_sub_condition, ' OR ').")";
3130 3130
 						break;
3131 3131
 				}
3132
-			}else{
3132
+			} else {
3133 3133
 				$field_obj = $this->_deduce_field_from_query_param($query_param);
3134 3134
 
3135 3135
 				//if it's not a normal field, maybe it's a custom selection?
3136
-				if( ! $field_obj){
3137
-					if(isset( $this->_custom_selections[$query_param][1])){
3136
+				if ( ! $field_obj) {
3137
+					if (isset($this->_custom_selections[$query_param][1])) {
3138 3138
 						$field_obj = $this->_custom_selections[$query_param][1];
3139
-					}else{
3140
-						throw new EE_Error(sprintf(__("%s is neither a valid model field name, nor a custom selection", "event_espresso"),$query_param));
3139
+					} else {
3140
+						throw new EE_Error(sprintf(__("%s is neither a valid model field name, nor a custom selection", "event_espresso"), $query_param));
3141 3141
 					}
3142 3142
 				}
3143 3143
 				$op_and_value_sql = $this->_construct_op_and_value($op_and_value_or_sub_condition, $field_obj);
3144
-				$where_clauses[]=$this->_deduce_column_name_from_query_param($query_param).SP.$op_and_value_sql;
3144
+				$where_clauses[] = $this->_deduce_column_name_from_query_param($query_param).SP.$op_and_value_sql;
3145 3145
 			}
3146 3146
 		}
3147
-		if($where_clauses){
3148
-			$SQL = implode($glue,$where_clauses);
3149
-		}else{
3147
+		if ($where_clauses) {
3148
+			$SQL = implode($glue, $where_clauses);
3149
+		} else {
3150 3150
 			$SQL = '';
3151 3151
 		}
3152 3152
 		return $SQL;
@@ -3160,18 +3160,18 @@  discard block
 block discarded – undo
3160 3160
 	 * @throws EE_Error
3161 3161
 	 * @return string table alias and column name for SQL, eg "Transaction.TXN_ID"
3162 3162
 	 */
3163
-	private function _deduce_column_name_from_query_param($query_param){
3163
+	private function _deduce_column_name_from_query_param($query_param) {
3164 3164
 		$field = $this->_deduce_field_from_query_param($query_param);
3165 3165
 
3166
-		if( $field ){
3167
-			$table_alias_prefix = EE_Model_Parser::extract_table_alias_model_relation_chain_from_query_param( $field->get_model_name(), $query_param );
3168
-			return $table_alias_prefix . $field->get_qualified_column();
3169
-		}elseif(array_key_exists($query_param,$this->_custom_selections)){
3166
+		if ($field) {
3167
+			$table_alias_prefix = EE_Model_Parser::extract_table_alias_model_relation_chain_from_query_param($field->get_model_name(), $query_param);
3168
+			return $table_alias_prefix.$field->get_qualified_column();
3169
+		}elseif (array_key_exists($query_param, $this->_custom_selections)) {
3170 3170
 			//maybe it's custom selection item?
3171 3171
 			//if so, just use it as the "column name"
3172 3172
 			return $query_param;
3173
-		}else{
3174
-			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)));
3173
+		} else {
3174
+			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)));
3175 3175
 		}
3176 3176
 	}
3177 3177
 
@@ -3183,11 +3183,11 @@  discard block
 block discarded – undo
3183 3183
 	 * @param string $condition_query_param_key
3184 3184
 	 * @return string
3185 3185
 	 */
3186
-	private function _remove_stars_and_anything_after_from_condition_query_param_key($condition_query_param_key){
3186
+	private function _remove_stars_and_anything_after_from_condition_query_param_key($condition_query_param_key) {
3187 3187
 		$pos_of_star = strpos($condition_query_param_key, '*');
3188
-		if($pos_of_star === FALSE){
3188
+		if ($pos_of_star === FALSE) {
3189 3189
 			return $condition_query_param_key;
3190
-		}else{
3190
+		} else {
3191 3191
 			$condition_query_param_sans_star = substr($condition_query_param_key, 0, $pos_of_star);
3192 3192
 			return $condition_query_param_sans_star;
3193 3193
 		}
@@ -3202,54 +3202,54 @@  discard block
 block discarded – undo
3202 3202
 	 * @throws EE_Error
3203 3203
 	 * @return string
3204 3204
 	 */
3205
-	private function _construct_op_and_value($op_and_value, $field_obj){
3206
-		if(is_array( $op_and_value )){
3205
+	private function _construct_op_and_value($op_and_value, $field_obj) {
3206
+		if (is_array($op_and_value)) {
3207 3207
 			$operator = isset($op_and_value[0]) ? $this->_prepare_operator_for_sql($op_and_value[0]) : null;
3208
-			if( ! $operator){
3208
+			if ( ! $operator) {
3209 3209
 				$php_array_like_string = array();
3210
-				foreach($op_and_value as $key => $value){
3210
+				foreach ($op_and_value as $key => $value) {
3211 3211
 					$php_array_like_string[] = "$key=>$value";
3212 3212
 				}
3213
-				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)));
3213
+				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)));
3214 3214
 			}
3215 3215
 			$value = isset($op_and_value[1]) ? $op_and_value[1] : null;
3216
-		}else{
3216
+		} else {
3217 3217
 			$operator = '=';
3218 3218
 			$value = $op_and_value;
3219 3219
 		}
3220 3220
 
3221 3221
 		//check to see if the value is actually another field
3222
-		if(is_array($op_and_value) && isset($op_and_value[2]) && $op_and_value[2] == true){
3222
+		if (is_array($op_and_value) && isset($op_and_value[2]) && $op_and_value[2] == true) {
3223 3223
 			return $operator.SP.$this->_deduce_column_name_from_query_param($value);
3224
-		}elseif(in_array($operator, $this->_in_style_operators) && is_array($value)){
3224
+		}elseif (in_array($operator, $this->_in_style_operators) && is_array($value)) {
3225 3225
 			//in this case, the value should be an array, or at least a comma-separated list
3226 3226
 			//it will need to handle a little differently
3227 3227
 			$cleaned_value = $this->_construct_in_value($value, $field_obj);
3228 3228
 			//note: $cleaned_value has already been run through $wpdb->prepare()
3229 3229
 			return $operator.SP.$cleaned_value;
3230
-		} elseif( in_array( $operator, $this->_between_style_operators ) && is_array( $value ) ) {
3230
+		} elseif (in_array($operator, $this->_between_style_operators) && is_array($value)) {
3231 3231
 			//the value should be an array with count of two.
3232
-			if ( count($value) !== 2 )
3233
-				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" ) );
3234
-			$cleaned_value = $this->_construct_between_value( $value, $field_obj );
3232
+			if (count($value) !== 2)
3233
+				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"));
3234
+			$cleaned_value = $this->_construct_between_value($value, $field_obj);
3235 3235
 			return $operator.SP.$cleaned_value;
3236
-		} elseif( in_array( $operator, $this->_null_style_operators ) ) {
3237
-			if($value != NULL){
3238
-				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));
3236
+		} elseif (in_array($operator, $this->_null_style_operators)) {
3237
+			if ($value != NULL) {
3238
+				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));
3239 3239
 			}
3240 3240
 			return $operator;
3241
-		}elseif( $operator == 'LIKE' && ! is_array($value)){
3241
+		}elseif ($operator == 'LIKE' && ! is_array($value)) {
3242 3242
 			//if the operator is 'LIKE', we want to allow percent signs (%) and not
3243 3243
 			//remove other junk. So just treat it as a string.
3244 3244
 			return $operator.SP.$this->_wpdb_prepare_using_field($value, '%s');
3245
-		}elseif( ! in_array($operator, $this->_in_style_operators) && ! is_array($value)){
3246
-			return $operator.SP.$this->_wpdb_prepare_using_field($value,$field_obj);
3247
-		}elseif(in_array($operator, $this->_in_style_operators) && ! is_array($value)){
3248
-			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));
3249
-		}elseif( ! in_array($operator, $this->_in_style_operators) && is_array($value)){
3250
-			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));
3251
-		}else{
3252
-			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)));
3245
+		}elseif ( ! in_array($operator, $this->_in_style_operators) && ! is_array($value)) {
3246
+			return $operator.SP.$this->_wpdb_prepare_using_field($value, $field_obj);
3247
+		}elseif (in_array($operator, $this->_in_style_operators) && ! is_array($value)) {
3248
+			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));
3249
+		}elseif ( ! in_array($operator, $this->_in_style_operators) && is_array($value)) {
3250
+			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));
3251
+		} else {
3252
+			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)));
3253 3253
 		}
3254 3254
 	}
3255 3255
 
@@ -3261,12 +3261,12 @@  discard block
 block discarded – undo
3261 3261
 	 * @param EE_Model_Field_Base|string $field_obj if string, it should be the datatype to be used when querying, eg '%s'
3262 3262
 	 * @return string
3263 3263
 	 */
3264
-	function _construct_between_value( $values, $field_obj ) {
3264
+	function _construct_between_value($values, $field_obj) {
3265 3265
 		$cleaned_values = array();
3266
-		foreach ( $values as $value ) {
3267
-			$cleaned_values[] = $this->_wpdb_prepare_using_field($value,$field_obj);
3266
+		foreach ($values as $value) {
3267
+			$cleaned_values[] = $this->_wpdb_prepare_using_field($value, $field_obj);
3268 3268
 		}
3269
-		return  $cleaned_values[0] . " AND " . $cleaned_values[1];
3269
+		return  $cleaned_values[0]." AND ".$cleaned_values[1];
3270 3270
 	}
3271 3271
 
3272 3272
 
@@ -3282,26 +3282,26 @@  discard block
 block discarded – undo
3282 3282
 	 * @param EE_Model_Field_Base|string $field_obj if string, it should be a wpdb data type like '%s', or '%d'
3283 3283
 	 * @return string of SQL to follow an 'IN' or 'NOT IN' operator
3284 3284
 	 */
3285
-	function _construct_in_value($values,  $field_obj){
3285
+	function _construct_in_value($values, $field_obj) {
3286 3286
 		//check if the value is a CSV list
3287
-		if(is_string($values)){
3287
+		if (is_string($values)) {
3288 3288
 			//in which case, turn it into an array
3289
-			$values = explode(",",$values);
3289
+			$values = explode(",", $values);
3290 3290
 		}
3291 3291
 		$cleaned_values = array();
3292
-		foreach($values as $value){
3293
-			$cleaned_values[] = $this->_wpdb_prepare_using_field($value,$field_obj);
3292
+		foreach ($values as $value) {
3293
+			$cleaned_values[] = $this->_wpdb_prepare_using_field($value, $field_obj);
3294 3294
 		}
3295 3295
 		//we would just LOVE to leave $cleaned_values as an empty array, and return the value as "()",
3296 3296
 		//but unfortunately that's invalid SQL. So instead we return a string which we KNOW will evaluate to be the empty set
3297 3297
 		//which is effectively equivalent to returning "()". We don't return "(0)" because that only works for auto-incrementing columns
3298
-		if(empty($cleaned_values)){
3298
+		if (empty($cleaned_values)) {
3299 3299
 			$all_fields = $this->field_settings();
3300 3300
 			$a_field = array_shift($all_fields);
3301 3301
 			$main_table = $this->_get_main_table();
3302 3302
 			$cleaned_values[] = "SELECT ".$a_field->get_table_column()." FROM ".$main_table->get_table_name()." WHERE FALSE";
3303 3303
 		}
3304
-		return "(".implode(",",$cleaned_values).")";
3304
+		return "(".implode(",", $cleaned_values).")";
3305 3305
 	}
3306 3306
 
3307 3307
 
@@ -3313,16 +3313,16 @@  discard block
 block discarded – undo
3313 3313
 	 * @throws EE_Error
3314 3314
 	 * @return false|null|string
3315 3315
 	 */
3316
-	private function _wpdb_prepare_using_field($value,$field_obj){
3316
+	private function _wpdb_prepare_using_field($value, $field_obj) {
3317 3317
 		/** @type WPDB $wpdb */
3318 3318
 		global $wpdb;
3319
-		if($field_obj instanceof EE_Model_Field_Base){
3320
-			return $wpdb->prepare($field_obj->get_wpdb_data_type(),$this->_prepare_value_for_use_in_db($value, $field_obj));
3321
-		}else{//$field_obj should really just be a data type
3322
-			if( ! in_array($field_obj,$this->_valid_wpdb_data_types)){
3323
-				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)));
3319
+		if ($field_obj instanceof EE_Model_Field_Base) {
3320
+			return $wpdb->prepare($field_obj->get_wpdb_data_type(), $this->_prepare_value_for_use_in_db($value, $field_obj));
3321
+		} else {//$field_obj should really just be a data type
3322
+			if ( ! in_array($field_obj, $this->_valid_wpdb_data_types)) {
3323
+				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)));
3324 3324
 			}
3325
-			return $wpdb->prepare($field_obj,$value);
3325
+			return $wpdb->prepare($field_obj, $value);
3326 3326
 		}
3327 3327
 	}
3328 3328
 
@@ -3334,27 +3334,27 @@  discard block
 block discarded – undo
3334 3334
 	 * @throws EE_Error
3335 3335
 	 * @return EE_Model_Field_Base
3336 3336
 	 */
3337
-	protected function _deduce_field_from_query_param($query_param_name){
3337
+	protected function _deduce_field_from_query_param($query_param_name) {
3338 3338
 		//ok, now proceed with deducing which part is the model's name, and which is the field's name
3339 3339
 		//which will help us find the database table and column
3340 3340
 
3341
-		$query_param_parts = explode(".",$query_param_name);
3342
-		if(empty($query_param_parts)){
3343
-			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));
3341
+		$query_param_parts = explode(".", $query_param_name);
3342
+		if (empty($query_param_parts)) {
3343
+			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));
3344 3344
 		}
3345 3345
 		$number_of_parts = count($query_param_parts);
3346
-		$last_query_param_part = $query_param_parts[ count($query_param_parts) - 1 ];
3347
-		if($number_of_parts == 1){
3346
+		$last_query_param_part = $query_param_parts[count($query_param_parts) - 1];
3347
+		if ($number_of_parts == 1) {
3348 3348
 			$field_name = $last_query_param_part;
3349 3349
 			$model_obj = $this;
3350
-		}else{// $number_of_parts >= 2
3350
+		} else {// $number_of_parts >= 2
3351 3351
 			//the last part is the column name, and there are only 2parts. therefore...
3352 3352
 			$field_name = $last_query_param_part;
3353
-			$model_obj = $this->get_related_model_obj( $query_param_parts[ $number_of_parts - 2 ]);
3353
+			$model_obj = $this->get_related_model_obj($query_param_parts[$number_of_parts - 2]);
3354 3354
 		}
3355
-		try{
3355
+		try {
3356 3356
 			return $model_obj->field_settings_for($field_name);
3357
-		}catch(EE_Error $e){
3357
+		} catch (EE_Error $e) {
3358 3358
 			return null;
3359 3359
 		}
3360 3360
 	}
@@ -3368,13 +3368,13 @@  discard block
 block discarded – undo
3368 3368
 	 * @throws EE_Error
3369 3369
 	 * @return string
3370 3370
 	 */
3371
-	function _get_qualified_column_for_field($field_name){
3371
+	function _get_qualified_column_for_field($field_name) {
3372 3372
 		$all_fields = $this->field_settings();
3373 3373
 		$field = isset($all_fields[$field_name]) ? $all_fields[$field_name] : FALSE;
3374
-		if($field){
3374
+		if ($field) {
3375 3375
 			return $field->get_qualified_column();
3376
-		}else{
3377
-			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)));
3376
+		} else {
3377
+			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)));
3378 3378
 		}
3379 3379
 	}
3380 3380
 
@@ -3388,14 +3388,14 @@  discard block
 block discarded – undo
3388 3388
 	 * @param  mixed|string $limit The limit for this select
3389 3389
 	 * @return string 				The final select join element for the query.
3390 3390
 	 */
3391
-	function _construct_limit_join_select( $table_alias, $limit ) {
3391
+	function _construct_limit_join_select($table_alias, $limit) {
3392 3392
 		$SQL = '';
3393 3393
 
3394
-		foreach ( $this->_tables as $table_obj ) {
3395
-			if ( $table_obj instanceof EE_Primary_Table ) {
3396
-				$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;
3397
-			} elseif ( $table_obj instanceof EE_Secondary_Table ) {
3398
-				$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;
3394
+		foreach ($this->_tables as $table_obj) {
3395
+			if ($table_obj instanceof EE_Primary_Table) {
3396
+				$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;
3397
+			} elseif ($table_obj instanceof EE_Secondary_Table) {
3398
+				$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;
3399 3399
 			}
3400 3400
 		}
3401 3401
 		return $SQL;
@@ -3408,7 +3408,7 @@  discard block
 block discarded – undo
3408 3408
 	 * Eg "wp_post AS Event" or "wp_post AS Event INNER JOIN wp_postmeta Event_Meta ON Event.ID = Event_Meta.post_id"
3409 3409
 	 * @return string SQL
3410 3410
 	 */
3411
-	function _construct_internal_join(){
3411
+	function _construct_internal_join() {
3412 3412
 		$SQL = $this->_get_main_table()->get_table_sql();
3413 3413
 		$SQL .= $this->_construct_internal_join_to_table_with_alias($this->_get_main_table()->get_table_alias());
3414 3414
 		return $SQL;
@@ -3429,17 +3429,17 @@  discard block
 block discarded – undo
3429 3429
 	 * @param string $alias_prefixed table alias to join to (this table should already be in the FROM SQL clause)
3430 3430
 	 * @return string
3431 3431
 	 */
3432
-	function _construct_internal_join_to_table_with_alias($alias_prefixed){
3432
+	function _construct_internal_join_to_table_with_alias($alias_prefixed) {
3433 3433
 		$SQL = '';
3434 3434
 		$alias_sans_prefix = EE_Model_Parser::remove_table_alias_model_relation_chain_prefix($alias_prefixed);
3435
-		foreach($this->_tables as $table_obj){
3436
-			if($table_obj instanceof EE_Secondary_Table){//table is secondary table
3437
-				if($alias_sans_prefix == $table_obj->get_table_alias()){
3435
+		foreach ($this->_tables as $table_obj) {
3436
+			if ($table_obj instanceof EE_Secondary_Table) {//table is secondary table
3437
+				if ($alias_sans_prefix == $table_obj->get_table_alias()) {
3438 3438
 					//so we're joining to this table, meaning the table is already in
3439 3439
 					//the FROM statement, BUT the primary table isn't. So we want
3440 3440
 					//to add the inverse join sql
3441 3441
 					$SQL .= $table_obj->get_inverse_join_sql($alias_prefixed);
3442
-				}else{
3442
+				} else {
3443 3443
 					//just add a regular JOIN to this table from the primary table
3444 3444
 					$SQL .= $table_obj->get_join_sql($alias_prefixed);
3445 3445
 				}
@@ -3453,9 +3453,9 @@  discard block
 block discarded – undo
3453 3453
 	 * 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)
3454 3454
 	 * @return array
3455 3455
 	 */
3456
-	function _get_data_types(){
3456
+	function _get_data_types() {
3457 3457
 		$data_types = array();
3458
-		foreach(array_values($this->field_settings()) as $field_obj){
3458
+		foreach (array_values($this->field_settings()) as $field_obj) {
3459 3459
 			//$data_types[$field_obj->get_table_column()] = $field_obj->get_wpdb_data_type();
3460 3460
 			/** @var $field_obj EE_Model_Field_Base */
3461 3461
 			$data_types[$field_obj->get_qualified_column()] = $field_obj->get_wpdb_data_type();
@@ -3471,11 +3471,11 @@  discard block
 block discarded – undo
3471 3471
 	 * @throws EE_Error
3472 3472
 	 * @return EEM_Base
3473 3473
 	 */
3474
-	function get_related_model_obj($model_name){
3474
+	function get_related_model_obj($model_name) {
3475 3475
 
3476 3476
 		$model_classname = "EEM_".$model_name;
3477
-		if(!class_exists($model_classname)){
3478
-			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));
3477
+		if ( ! class_exists($model_classname)) {
3478
+			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));
3479 3479
 		}
3480 3480
 		$model_obj = call_user_func($model_classname."::instance");
3481 3481
 		return $model_obj;
@@ -3486,7 +3486,7 @@  discard block
 block discarded – undo
3486 3486
 	 * Returns the array of EE_ModelRelations for this model.
3487 3487
 	 * @return EE_Model_Relation_Base[]
3488 3488
 	 */
3489
-	public function relation_settings(){
3489
+	public function relation_settings() {
3490 3490
 		return $this->_model_relations;
3491 3491
 	}
3492 3492
 
@@ -3496,10 +3496,10 @@  discard block
 block discarded – undo
3496 3496
 	 * (Eg, without an event, datetimes have little purpose.)
3497 3497
 	 * @return EE_Belongs_To_Relation[]
3498 3498
 	 */
3499
-	public function belongs_to_relations(){
3499
+	public function belongs_to_relations() {
3500 3500
 		$belongs_to_relations = array();
3501
-		foreach($this->relation_settings() as $model_name => $relation_obj){
3502
-			if($relation_obj instanceof EE_Belongs_To_Relation){
3501
+		foreach ($this->relation_settings() as $model_name => $relation_obj) {
3502
+			if ($relation_obj instanceof EE_Belongs_To_Relation) {
3503 3503
 				$belongs_to_relations[$model_name] = $relation_obj;
3504 3504
 			}
3505 3505
 		}
@@ -3514,15 +3514,15 @@  discard block
 block discarded – undo
3514 3514
 	 * @throws EE_Error
3515 3515
 	 * @return EE_Model_Relation_Base
3516 3516
 	 */
3517
-	public function related_settings_for($relation_name){
3518
-		$relatedModels=$this->relation_settings();
3519
-		if(!array_key_exists($relation_name,$relatedModels)){
3517
+	public function related_settings_for($relation_name) {
3518
+		$relatedModels = $this->relation_settings();
3519
+		if ( ! array_key_exists($relation_name, $relatedModels)) {
3520 3520
 			throw new EE_Error(
3521 3521
 				sprintf(
3522
-					__('Cannot get %s related to %s. There is no model relation of that type. There is, however, %s...','event_espresso'),
3522
+					__('Cannot get %s related to %s. There is no model relation of that type. There is, however, %s...', 'event_espresso'),
3523 3523
 					$relation_name,
3524 3524
 					$this->_get_class_name(),
3525
-					implode( ', ', array_keys( $relatedModels ))
3525
+					implode(', ', array_keys($relatedModels))
3526 3526
 				)
3527 3527
 			);
3528 3528
 		}
@@ -3537,10 +3537,10 @@  discard block
 block discarded – undo
3537 3537
 	 * @throws EE_Error
3538 3538
 	 * @return EE_Model_Field_Base
3539 3539
 	 */
3540
-	public function field_settings_for($fieldName){
3541
-		$fieldSettings=$this->field_settings(true);
3542
-		if( ! array_key_exists($fieldName,$fieldSettings)){
3543
-			throw new EE_Error(sprintf(__("There is no field/column '%s' on '%s'",'event_espresso'),$fieldName,get_class($this)));
3540
+	public function field_settings_for($fieldName) {
3541
+		$fieldSettings = $this->field_settings(true);
3542
+		if ( ! array_key_exists($fieldName, $fieldSettings)) {
3543
+			throw new EE_Error(sprintf(__("There is no field/column '%s' on '%s'", 'event_espresso'), $fieldName, get_class($this)));
3544 3544
 		}
3545 3545
 		return $fieldSettings[$fieldName];
3546 3546
 	}
@@ -3550,11 +3550,11 @@  discard block
 block discarded – undo
3550 3550
 	 * @param string $fieldName a key in the model's _field_settings array
3551 3551
 	 * @return boolean
3552 3552
 	 */
3553
-	public function has_field($fieldName){
3553
+	public function has_field($fieldName) {
3554 3554
 		$fieldSettings = $this->field_settings(true);
3555
-		if( isset($fieldSettings[$fieldName])){
3555
+		if (isset($fieldSettings[$fieldName])) {
3556 3556
 			return true;
3557
-		}else{
3557
+		} else {
3558 3558
 			return false;
3559 3559
 		}
3560 3560
 	}
@@ -3564,11 +3564,11 @@  discard block
 block discarded – undo
3564 3564
 	 * @param string $relation_name possibly one of the keys in the relation_settings array
3565 3565
 	 * @return boolean
3566 3566
 	 */
3567
-	public function has_relation($relation_name){
3567
+	public function has_relation($relation_name) {
3568 3568
 		$relations = $this->relation_settings();
3569
-		if(isset($relations[$relation_name])){
3569
+		if (isset($relations[$relation_name])) {
3570 3570
 			return true;
3571
-		}else{
3571
+		} else {
3572 3572
 			return false;
3573 3573
 		}
3574 3574
 	}
@@ -3580,7 +3580,7 @@  discard block
 block discarded – undo
3580 3580
 	 * @param $field_obj
3581 3581
 	 * @return EE_Model_Field_Base
3582 3582
 	 */
3583
-	public function is_primary_key_field( $field_obj ){
3583
+	public function is_primary_key_field($field_obj) {
3584 3584
 		return $field_obj instanceof EE_Primary_Key_Field_Base ? TRUE : FALSE;
3585 3585
 	}
3586 3586
 
@@ -3592,16 +3592,16 @@  discard block
 block discarded – undo
3592 3592
 	 * @return EE_Model_Field_Base
3593 3593
 	 * @throws EE_Error
3594 3594
 	 */
3595
-	public function get_primary_key_field(){
3596
-		if( $this->_primary_key_field === NULL ){
3597
-			foreach( $this->field_settings( TRUE ) as $field_obj ){
3598
-				if( $this->is_primary_key_field( $field_obj )){
3595
+	public function get_primary_key_field() {
3596
+		if ($this->_primary_key_field === NULL) {
3597
+			foreach ($this->field_settings(TRUE) as $field_obj) {
3598
+				if ($this->is_primary_key_field($field_obj)) {
3599 3599
 					$this->_primary_key_field = $field_obj;
3600 3600
 					break;
3601 3601
 				}
3602 3602
 			}
3603
-			if( ! $this->_primary_key_field instanceof EE_Primary_Key_Field_Base ){
3604
-				throw new EE_Error(sprintf(__("There is no Primary Key defined on model %s",'event_espresso'),get_class($this)));
3603
+			if ( ! $this->_primary_key_field instanceof EE_Primary_Key_Field_Base) {
3604
+				throw new EE_Error(sprintf(__("There is no Primary Key defined on model %s", 'event_espresso'), get_class($this)));
3605 3605
 			}
3606 3606
 		}
3607 3607
 		return $this->_primary_key_field;
@@ -3614,12 +3614,12 @@  discard block
 block discarded – undo
3614 3614
 	 * Internally does some caching.
3615 3615
 	 * @return boolean
3616 3616
 	 */
3617
-	public function has_primary_key_field(){
3618
-		if($this->_has_primary_key_field === null){
3619
-			try{
3617
+	public function has_primary_key_field() {
3618
+		if ($this->_has_primary_key_field === null) {
3619
+			try {
3620 3620
 				$this->get_primary_key_field();
3621 3621
 				$this->_has_primary_key_field = true;
3622
-			}catch(EE_Error $e){
3622
+			} catch (EE_Error $e) {
3623 3623
 				$this->_has_primary_key_field = false;
3624 3624
 			}
3625 3625
 		}
@@ -3633,9 +3633,9 @@  discard block
 block discarded – undo
3633 3633
 	 * @param string $field_class_name class name of field that you want to find. Eg, EE_Datetime_Field, EE_Foreign_Key_Field, etc
3634 3634
 	 * @return EE_Model_Field_Base or null if none is found
3635 3635
 	 */
3636
-	public function get_a_field_of_type($field_class_name){
3637
-		foreach($this->field_settings() as $field){
3638
-			if( $field instanceof $field_class_name ){
3636
+	public function get_a_field_of_type($field_class_name) {
3637
+		foreach ($this->field_settings() as $field) {
3638
+			if ($field instanceof $field_class_name) {
3639 3639
 				return $field;
3640 3640
 			}
3641 3641
 		}
@@ -3649,21 +3649,21 @@  discard block
 block discarded – undo
3649 3649
 	 * @return EE_Foreign_Key_Field_Base
3650 3650
 	 * @throws EE_Error
3651 3651
 	 */
3652
-	public function get_foreign_key_to($model_name){
3653
-		if( ! isset( $this->_cache_foreign_key_to_fields[ $model_name ] ) ){
3654
-			foreach($this->field_settings() as $field){
3652
+	public function get_foreign_key_to($model_name) {
3653
+		if ( ! isset($this->_cache_foreign_key_to_fields[$model_name])) {
3654
+			foreach ($this->field_settings() as $field) {
3655 3655
 //				if(is_subclass_of($field, 'EE_Foreign_Key_Field_Base')){
3656
-				if( $field instanceof EE_Foreign_Key_Field_Base ){
3657
-					if (in_array($model_name,$field->get_model_names_pointed_to() ) ) {
3658
-						$this->_cache_foreign_key_to_fields[ $model_name ] = $field;
3656
+				if ($field instanceof EE_Foreign_Key_Field_Base) {
3657
+					if (in_array($model_name, $field->get_model_names_pointed_to())) {
3658
+						$this->_cache_foreign_key_to_fields[$model_name] = $field;
3659 3659
 					}
3660 3660
 				}
3661 3661
 			}
3662
-			if( ! isset( $this->_cache_foreign_key_to_fields[ $model_name ] ) ){
3663
-				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)));
3662
+			if ( ! isset($this->_cache_foreign_key_to_fields[$model_name])) {
3663
+				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)));
3664 3664
 			}
3665 3665
 		}
3666
-		return $this->_cache_foreign_key_to_fields[ $model_name ];
3666
+		return $this->_cache_foreign_key_to_fields[$model_name];
3667 3667
 	}
3668 3668
 
3669 3669
 
@@ -3674,7 +3674,7 @@  discard block
 block discarded – undo
3674 3674
 	 * a table alias with a model chain prefix, like 'Venue__Event_Venue___Event_Meta'. Either one works
3675 3675
 	 * @return EE_Table_Base
3676 3676
 	 */
3677
-	function get_table_for_alias($table_alias){
3677
+	function get_table_for_alias($table_alias) {
3678 3678
 		$table_alias_sans_model_relation_chain_prefix = EE_Model_Parser::remove_table_alias_model_relation_chain_prefix($table_alias);
3679 3679
 		return $this->_tables[$table_alias_sans_model_relation_chain_prefix]->get_table_name();
3680 3680
 	}
@@ -3687,25 +3687,25 @@  discard block
 block discarded – undo
3687 3687
 	 * @param bool $include_db_only_fields flag indicating whether or not to include the db-only fields
3688 3688
 	 * @return EE_Model_Field_Base[] where the keys are the field's name
3689 3689
 	 */
3690
-	public function field_settings($include_db_only_fields = false){
3691
-		if( $include_db_only_fields ){
3692
-			if( $this->_cached_fields === NULL ){
3690
+	public function field_settings($include_db_only_fields = false) {
3691
+		if ($include_db_only_fields) {
3692
+			if ($this->_cached_fields === NULL) {
3693 3693
 				$this->_cached_fields = array();
3694
-				foreach($this->_fields as $fields_corresponding_to_table){
3695
-					foreach($fields_corresponding_to_table as $field_name => $field_obj){
3696
-						$this->_cached_fields[$field_name]=$field_obj;
3694
+				foreach ($this->_fields as $fields_corresponding_to_table) {
3695
+					foreach ($fields_corresponding_to_table as $field_name => $field_obj) {
3696
+						$this->_cached_fields[$field_name] = $field_obj;
3697 3697
 					}
3698 3698
 				}
3699 3699
 			}
3700 3700
 			return $this->_cached_fields;
3701
-		}else{
3702
-			if( $this->_cached_fields_non_db_only === NULL ){
3701
+		} else {
3702
+			if ($this->_cached_fields_non_db_only === NULL) {
3703 3703
 				$this->_cached_fields_non_db_only = array();
3704
-				foreach($this->_fields as $fields_corresponding_to_table){
3705
-					foreach($fields_corresponding_to_table as $field_name => $field_obj){
3704
+				foreach ($this->_fields as $fields_corresponding_to_table) {
3705
+					foreach ($fields_corresponding_to_table as $field_name => $field_obj) {
3706 3706
 						/** @var $field_obj EE_Model_Field_Base */
3707
-						if( ! $field_obj->is_db_only_field() ){
3708
-							$this->_cached_fields_non_db_only[$field_name]=$field_obj;
3707
+						if ( ! $field_obj->is_db_only_field()) {
3708
+							$this->_cached_fields_non_db_only[$field_name] = $field_obj;
3709 3709
 						}
3710 3710
 					}
3711 3711
 				}
@@ -3724,67 +3724,67 @@  discard block
 block discarded – undo
3724 3724
 	 * @return \EE_Base_Class[] array keys are primary keys (if there is a primary key on the model. if not, numerically indexed)
3725 3725
 	 * @throws \EE_Error
3726 3726
 	 */
3727
-	protected function _create_objects( $rows = array() ) {
3728
-		$array_of_objects=array();
3729
-		if(empty($rows)){
3727
+	protected function _create_objects($rows = array()) {
3728
+		$array_of_objects = array();
3729
+		if (empty($rows)) {
3730 3730
 			return array();
3731 3731
 		}
3732 3732
 		$count_if_model_has_no_primary_key = 0;
3733 3733
 		$has_primary_key = $this->has_primary_key_field();
3734
-		if( $has_primary_key ) {
3734
+		if ($has_primary_key) {
3735 3735
 			$primary_key_field = $this->get_primary_key_field();
3736 3736
 		} else {
3737 3737
 			$primary_key_field = null;
3738 3738
 		}
3739
-		foreach ( $rows as $row ) {
3740
-			if(empty($row)){
3739
+		foreach ($rows as $row) {
3740
+			if (empty($row)) {
3741 3741
 				//wp did its weird thing where it returns an array like array(0=>null), which is totally not helpful...
3742 3742
 				return array();
3743 3743
 			}
3744 3744
 			//check if we've already set this object in the results array,
3745 3745
 			//in which case there's no need to process it further (again)
3746
-			if( $has_primary_key ) {
3746
+			if ($has_primary_key) {
3747 3747
 				$table_pk_value = $this->_get_column_value_with_table_alias_or_not(
3748 3748
 					$row,
3749 3749
 					$primary_key_field->get_qualified_column(),
3750 3750
 					$primary_key_field->get_table_column()
3751 3751
 				);
3752
-				if( $table_pk_value &&
3753
-					isset( $array_of_objects[ $table_pk_value ] ) ) {
3752
+				if ($table_pk_value &&
3753
+					isset($array_of_objects[$table_pk_value])) {
3754 3754
 					continue;
3755 3755
 				}
3756 3756
 			}
3757
-			$classInstance=$this->instantiate_class_from_array_or_object($row);
3758
-			if( ! $classInstance ) {
3757
+			$classInstance = $this->instantiate_class_from_array_or_object($row);
3758
+			if ( ! $classInstance) {
3759 3759
 				throw new EE_Error(
3760 3760
 					sprintf(
3761
-						__( 'Could not create instance of class %s from row %s', 'event_espresso' ),
3761
+						__('Could not create instance of class %s from row %s', 'event_espresso'),
3762 3762
 						$this->get_this_model_name(),
3763
-						http_build_query( $row )
3763
+						http_build_query($row)
3764 3764
 					)
3765 3765
 				);
3766 3766
 			}
3767 3767
 			//set the timezone on the instantiated objects
3768
-			$classInstance->set_timezone( $this->_timezone );
3768
+			$classInstance->set_timezone($this->_timezone);
3769 3769
 			//make sure if there is any timezone setting present that we set the timezone for the object
3770 3770
 			$key = $has_primary_key ? $classInstance->ID() : $count_if_model_has_no_primary_key++;
3771
-			$array_of_objects[ $key ] = $classInstance;
3771
+			$array_of_objects[$key] = $classInstance;
3772 3772
 			//also, for all the relations of type BelongsTo, see if we can cache
3773 3773
 			//those related models
3774 3774
 			//(we could do this for other relations too, but if there are conditions
3775 3775
 			//that filtered out some fo the results, then we'd be caching an incomplete set
3776 3776
 			//so it requires a little more thought than just caching them immediately...)
3777
-			foreach($this->_model_relations as $modelName => $relation_obj){
3778
-				if( $relation_obj instanceof EE_Belongs_To_Relation){
3777
+			foreach ($this->_model_relations as $modelName => $relation_obj) {
3778
+				if ($relation_obj instanceof EE_Belongs_To_Relation) {
3779 3779
 					//check if this model's INFO is present. If so, cache it on the model
3780 3780
 					$other_model = $relation_obj->get_other_model();
3781 3781
 
3782 3782
 					$other_model_obj_maybe = $other_model->instantiate_class_from_array_or_object($row);
3783 3783
 
3784 3784
 					//if we managed to make a model object from the results, cache it on the main model object
3785
-					if( $other_model_obj_maybe ){
3785
+					if ($other_model_obj_maybe) {
3786 3786
 						//set timezone on these other model objects if they are present
3787
-						$other_model_obj_maybe->set_timezone( $this->_timezone );
3787
+						$other_model_obj_maybe->set_timezone($this->_timezone);
3788 3788
 						$classInstance->cache($modelName, $other_model_obj_maybe);
3789 3789
 					}
3790 3790
 				}
@@ -3805,12 +3805,12 @@  discard block
 block discarded – undo
3805 3805
 
3806 3806
 		$this_model_fields_and_values = array();
3807 3807
 		//setup the row using default values;
3808
-		foreach ( $this->field_settings() as $field_name => $field_obj ) {
3808
+		foreach ($this->field_settings() as $field_name => $field_obj) {
3809 3809
 			$this_model_fields_and_values[$field_name] = $field_obj->get_default_value();
3810 3810
 		}
3811 3811
 
3812 3812
 		$className = $this->_get_class_name();
3813
-		$classInstance = EE_Registry::instance()->load_class( $className, array( $this_model_fields_and_values ), FALSE, FALSE );
3813
+		$classInstance = EE_Registry::instance()->load_class($className, array($this_model_fields_and_values), FALSE, FALSE);
3814 3814
 
3815 3815
 		return $classInstance;
3816 3816
 	}
@@ -3823,45 +3823,45 @@  discard block
 block discarded – undo
3823 3823
 	 * or an stdClass where each property is the name of a column,
3824 3824
 	 * @return EE_Base_Class
3825 3825
 	 */
3826
-	public function instantiate_class_from_array_or_object($cols_n_values){
3827
-		if( ! is_array( $cols_n_values ) && is_object( $cols_n_values )) {
3828
-			$cols_n_values = get_object_vars( $cols_n_values );
3826
+	public function instantiate_class_from_array_or_object($cols_n_values) {
3827
+		if ( ! is_array($cols_n_values) && is_object($cols_n_values)) {
3828
+			$cols_n_values = get_object_vars($cols_n_values);
3829 3829
 		}
3830 3830
 		$primary_key = NULL;
3831 3831
 		//make sure the array only has keys that are fields/columns on this model
3832
-		$this_model_fields_n_values = $this->_deduce_fields_n_values_from_cols_n_values( $cols_n_values );
3833
-		if( $this->has_primary_key_field() && isset( $this_model_fields_n_values[ $this->primary_key_name() ] ) ){
3834
-			$primary_key = $this_model_fields_n_values[ $this->primary_key_name() ];
3832
+		$this_model_fields_n_values = $this->_deduce_fields_n_values_from_cols_n_values($cols_n_values);
3833
+		if ($this->has_primary_key_field() && isset($this_model_fields_n_values[$this->primary_key_name()])) {
3834
+			$primary_key = $this_model_fields_n_values[$this->primary_key_name()];
3835 3835
 		}
3836
-		$className=$this->_get_class_name();
3836
+		$className = $this->_get_class_name();
3837 3837
 
3838 3838
 		//check we actually found results that we can use to build our model object
3839 3839
 		//if not, return null
3840
-		if( $this->has_primary_key_field()){
3841
-			if(empty( $this_model_fields_n_values[$this->primary_key_name()] )){
3840
+		if ($this->has_primary_key_field()) {
3841
+			if (empty($this_model_fields_n_values[$this->primary_key_name()])) {
3842 3842
 				return NULL;
3843 3843
 			}
3844
-		}else if($this->unique_indexes()){
3844
+		} else if ($this->unique_indexes()) {
3845 3845
 			$first_column = reset($this_model_fields_n_values);
3846
-			if(empty($first_column)){
3846
+			if (empty($first_column)) {
3847 3847
 				return NULL;
3848 3848
 			}
3849 3849
 		}
3850 3850
 
3851 3851
 		// if there is no primary key or the object doesn't already exist in the entity map, then create a new instance
3852
-		if ( $primary_key){
3853
-			$classInstance = $this->get_from_entity_map( $primary_key );
3854
-			if( ! $classInstance) {
3855
-				$classInstance = EE_Registry::instance()->load_class( $className, array( $this_model_fields_n_values, $this->_timezone ), TRUE, FALSE );
3852
+		if ($primary_key) {
3853
+			$classInstance = $this->get_from_entity_map($primary_key);
3854
+			if ( ! $classInstance) {
3855
+				$classInstance = EE_Registry::instance()->load_class($className, array($this_model_fields_n_values, $this->_timezone), TRUE, FALSE);
3856 3856
 				// add this new object to the entity map
3857
-				$classInstance = $this->add_to_entity_map( $classInstance );
3857
+				$classInstance = $this->add_to_entity_map($classInstance);
3858 3858
 			}
3859
-		}else{
3860
-			$classInstance = EE_Registry::instance()->load_class( $className, array( $this_model_fields_n_values, $this->_timezone ), TRUE, FALSE );
3859
+		} else {
3860
+			$classInstance = EE_Registry::instance()->load_class($className, array($this_model_fields_n_values, $this->_timezone), TRUE, FALSE);
3861 3861
 		}
3862 3862
 
3863 3863
 			//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.
3864
-		$this->set_timezone( $classInstance->get_timezone() );
3864
+		$this->set_timezone($classInstance->get_timezone());
3865 3865
 		return $classInstance;
3866 3866
 	}
3867 3867
 	/**
@@ -3869,8 +3869,8 @@  discard block
 block discarded – undo
3869 3869
 	 * @param int|string $id the ID of the model object
3870 3870
 	 * @return EE_Base_Class
3871 3871
 	 */
3872
-	public function get_from_entity_map( $id ){
3873
-		return isset( $this->_entity_map[ $id ] ) ? $this->_entity_map[ $id ] : NULL;
3872
+	public function get_from_entity_map($id) {
3873
+		return isset($this->_entity_map[$id]) ? $this->_entity_map[$id] : NULL;
3874 3874
 	}
3875 3875
 
3876 3876
 
@@ -3889,21 +3889,21 @@  discard block
 block discarded – undo
3889 3889
 	 * @throws EE_Error
3890 3890
 	 * @return \EE_Base_Class
3891 3891
 	 */
3892
-	public function add_to_entity_map( EE_Base_Class $object) {
3892
+	public function add_to_entity_map(EE_Base_Class $object) {
3893 3893
 		$className = $this->_get_class_name();
3894
-		if( ! $object instanceof $className ){
3895
-			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 ) );
3894
+		if ( ! $object instanceof $className) {
3895
+			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));
3896 3896
 		}
3897 3897
 		/** @var $object EE_Base_Class */
3898
-		if ( ! $object->ID() ){
3899
-			throw new EE_Error(sprintf(__("You tried storing a model object with NO ID in the %s entity mapper.", "event_espresso"),get_class($this)));
3898
+		if ( ! $object->ID()) {
3899
+			throw new EE_Error(sprintf(__("You tried storing a model object with NO ID in the %s entity mapper.", "event_espresso"), get_class($this)));
3900 3900
 		}
3901 3901
 		// double check it's not already there
3902
-		$classInstance = $this->get_from_entity_map( $object->ID() );
3903
-		if ( $classInstance ) {
3902
+		$classInstance = $this->get_from_entity_map($object->ID());
3903
+		if ($classInstance) {
3904 3904
 			return $classInstance;
3905 3905
 		} else {
3906
-			$this->_entity_map[ $object->ID() ] = $object;
3906
+			$this->_entity_map[$object->ID()] = $object;
3907 3907
 			return $object;
3908 3908
 		}
3909 3909
 	}
@@ -3916,8 +3916,8 @@  discard block
 block discarded – undo
3916 3916
 	 * @param array $cols_n_values
3917 3917
 	 * @return array
3918 3918
 	 */
3919
-	public function deduce_fields_n_values_from_cols_n_values( $cols_n_values ) {
3920
-		return $this->_deduce_fields_n_values_from_cols_n_values( $cols_n_values );
3919
+	public function deduce_fields_n_values_from_cols_n_values($cols_n_values) {
3920
+		return $this->_deduce_fields_n_values_from_cols_n_values($cols_n_values);
3921 3921
 	}
3922 3922
 
3923 3923
 
@@ -3930,40 +3930,40 @@  discard block
 block discarded – undo
3930 3930
 	 * @param string $cols_n_values
3931 3931
 	 * @return array
3932 3932
 	 */
3933
-	protected function _deduce_fields_n_values_from_cols_n_values( $cols_n_values ){
3933
+	protected function _deduce_fields_n_values_from_cols_n_values($cols_n_values) {
3934 3934
 		$this_model_fields_n_values = array();
3935
-		foreach( $this->get_tables() as $table_alias => $table_obj ) {
3936
-			$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() );
3935
+		foreach ($this->get_tables() as $table_alias => $table_obj) {
3936
+			$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());
3937 3937
 			//there is a primary key on this table and its not set. Use defaults for all its columns
3938
-			if( $table_obj->get_pk_column() && $table_pk_value === NULL ){
3939
-				foreach( $this->_get_fields_for_table( $table_alias ) as $field_name => $field_obj ) {
3940
-					if( ! $field_obj->is_db_only_field() ){
3938
+			if ($table_obj->get_pk_column() && $table_pk_value === NULL) {
3939
+				foreach ($this->_get_fields_for_table($table_alias) as $field_name => $field_obj) {
3940
+					if ( ! $field_obj->is_db_only_field()) {
3941 3941
 						//prepare field as if its coming from db
3942
-						$prepared_value = $field_obj->prepare_for_set( $field_obj->get_default_value() );
3943
-						$this_model_fields_n_values[$field_name] = $field_obj->prepare_for_use_in_db( $prepared_value );
3942
+						$prepared_value = $field_obj->prepare_for_set($field_obj->get_default_value());
3943
+						$this_model_fields_n_values[$field_name] = $field_obj->prepare_for_use_in_db($prepared_value);
3944 3944
 					}
3945 3945
 				}
3946
-			}else{
3946
+			} else {
3947 3947
 				//the table's rows existed. Use their values
3948
-				foreach( $this->_get_fields_for_table( $table_alias ) as $field_name => $field_obj ) {
3949
-					if( ! $field_obj->is_db_only_field() )
3950
-					$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() );
3948
+				foreach ($this->_get_fields_for_table($table_alias) as $field_name => $field_obj) {
3949
+					if ( ! $field_obj->is_db_only_field())
3950
+					$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());
3951 3951
 				}
3952 3952
 			}
3953 3953
 		}
3954 3954
 		return $this_model_fields_n_values;
3955 3955
 	}
3956 3956
 
3957
-	protected function _get_column_value_with_table_alias_or_not( $cols_n_values, $qualified_column, $regular_column ){
3957
+	protected function _get_column_value_with_table_alias_or_not($cols_n_values, $qualified_column, $regular_column) {
3958 3958
 		//ask the field what it think it's table_name.column_name should be, and call it the "qualified column"
3959 3959
 		//does the field on the model relate to this column retrieved from the db?
3960 3960
 		//or is it a db-only field? (not relating to the model)
3961
-		if( isset( $cols_n_values[ $qualified_column ] ) ){
3962
-			$value = $cols_n_values[ $qualified_column ];
3961
+		if (isset($cols_n_values[$qualified_column])) {
3962
+			$value = $cols_n_values[$qualified_column];
3963 3963
 
3964
-		}elseif( isset( $cols_n_values[ $regular_column ] ) ){
3965
-			$value = $cols_n_values[ $regular_column ];
3966
-		}else{
3964
+		}elseif (isset($cols_n_values[$regular_column])) {
3965
+			$value = $cols_n_values[$regular_column];
3966
+		} else {
3967 3967
 			$value = NULL;
3968 3968
 		}
3969 3969
 
@@ -3981,24 +3981,24 @@  discard block
 block discarded – undo
3981 3981
 	 * @param int|string $id
3982 3982
 	 * @return EE_Base_Class
3983 3983
 	 */
3984
-	public function refresh_entity_map_from_db( $id ){
3985
-		$obj_in_map = $this->get_from_entity_map( $id );
3986
-		if( $obj_in_map ){
3987
-			$wpdb_results = $this->_get_all_wpdb_results( array( array ( $this->get_primary_key_field()->get_name() => $id ), 'limit' => 1 ) );
3988
-			if( $wpdb_results && is_array( $wpdb_results ) ){
3989
-				$one_row = reset( $wpdb_results );
3990
-				foreach( $this->_deduce_fields_n_values_from_cols_n_values($one_row ) as $field_name => $db_value ) {
3991
-					$obj_in_map->set_from_db( $field_name, $db_value );
3984
+	public function refresh_entity_map_from_db($id) {
3985
+		$obj_in_map = $this->get_from_entity_map($id);
3986
+		if ($obj_in_map) {
3987
+			$wpdb_results = $this->_get_all_wpdb_results(array(array($this->get_primary_key_field()->get_name() => $id), 'limit' => 1));
3988
+			if ($wpdb_results && is_array($wpdb_results)) {
3989
+				$one_row = reset($wpdb_results);
3990
+				foreach ($this->_deduce_fields_n_values_from_cols_n_values($one_row) as $field_name => $db_value) {
3991
+					$obj_in_map->set_from_db($field_name, $db_value);
3992 3992
 				}
3993 3993
 				//clear the cache of related model objects
3994
-				foreach ( $this->relation_settings() as $relation_name => $relation_obj ){
3995
-					$obj_in_map->clear_cache($relation_name, NULL, TRUE );
3994
+				foreach ($this->relation_settings() as $relation_name => $relation_obj) {
3995
+					$obj_in_map->clear_cache($relation_name, NULL, TRUE);
3996 3996
 				}
3997 3997
 			}
3998
-			$this->_entity_map[ $id ] = $obj_in_map;
3998
+			$this->_entity_map[$id] = $obj_in_map;
3999 3999
 			return $obj_in_map;
4000
-		}else{
4001
-			return $this->get_one_by_ID( $id );
4000
+		} else {
4001
+			return $this->get_one_by_ID($id);
4002 4002
 		}
4003 4003
 	}
4004 4004
 
@@ -4016,24 +4016,24 @@  discard block
 block discarded – undo
4016 4016
 	 * @param EE_Base_Class $replacing_model_obj
4017 4017
 	 * @return \EE_Base_Class
4018 4018
 	 */
4019
-	public function refresh_entity_map_with( $id, $replacing_model_obj ) {
4020
-		$obj_in_map = $this->get_from_entity_map( $id );
4021
-		if( $obj_in_map ){
4022
-			if( $replacing_model_obj instanceof EE_Base_Class ){
4023
-				foreach( $replacing_model_obj->model_field_array() as $field_name => $value ) {
4024
-					$obj_in_map->set( $field_name, $value );
4019
+	public function refresh_entity_map_with($id, $replacing_model_obj) {
4020
+		$obj_in_map = $this->get_from_entity_map($id);
4021
+		if ($obj_in_map) {
4022
+			if ($replacing_model_obj instanceof EE_Base_Class) {
4023
+				foreach ($replacing_model_obj->model_field_array() as $field_name => $value) {
4024
+					$obj_in_map->set($field_name, $value);
4025 4025
 				}
4026 4026
 				//make the model object in the entity map's cache match the $replacing_model_obj
4027
-				foreach ( $this->relation_settings() as $relation_name => $relation_obj ){
4028
-					$obj_in_map->clear_cache($relation_name, NULL, TRUE );
4029
-					foreach( $replacing_model_obj->get_all_from_cache( $relation_name ) as $cache_id => $cached_obj ) {
4030
-						$obj_in_map->cache( $relation_name, $cached_obj, $cache_id );
4027
+				foreach ($this->relation_settings() as $relation_name => $relation_obj) {
4028
+					$obj_in_map->clear_cache($relation_name, NULL, TRUE);
4029
+					foreach ($replacing_model_obj->get_all_from_cache($relation_name) as $cache_id => $cached_obj) {
4030
+						$obj_in_map->cache($relation_name, $cached_obj, $cache_id);
4031 4031
 					}
4032 4032
 				}
4033 4033
 			}
4034 4034
 			return $obj_in_map;
4035
-		}else{
4036
-			$this->add_to_entity_map( $replacing_model_obj );
4035
+		} else {
4036
+			$this->add_to_entity_map($replacing_model_obj);
4037 4037
 			return $replacing_model_obj;
4038 4038
 		}
4039 4039
 	}
@@ -4046,7 +4046,7 @@  discard block
 block discarded – undo
4046 4046
 	 * require_once($this->_getClassName().".class.php");
4047 4047
 	 * @return string
4048 4048
 	 */
4049
-	private function _get_class_name(){
4049
+	private function _get_class_name() {
4050 4050
 		return "EE_".$this->get_this_model_name();
4051 4051
 	}
4052 4052
 
@@ -4059,10 +4059,10 @@  discard block
 block discarded – undo
4059 4059
 	 * @param int $quantity
4060 4060
 	 * @return string
4061 4061
 	 */
4062
-	public function item_name($quantity = 1){
4063
-		if($quantity == 1){
4062
+	public function item_name($quantity = 1) {
4063
+		if ($quantity == 1) {
4064 4064
 			return $this->singular_item;
4065
-		}else{
4065
+		} else {
4066 4066
 			return $this->plural_item;
4067 4067
 		}
4068 4068
 	}
@@ -4091,13 +4091,13 @@  discard block
 block discarded – undo
4091 4091
 	 * @throws EE_Error
4092 4092
 	 * @return mixed whatever the plugin which calls add_filter decides
4093 4093
 	 */
4094
-	public function __call($methodName,$args){
4095
-		$className=get_class($this);
4096
-		$tagName="FHEE__{$className}__{$methodName}";
4097
-		if(!has_filter($tagName)){
4094
+	public function __call($methodName, $args) {
4095
+		$className = get_class($this);
4096
+		$tagName = "FHEE__{$className}__{$methodName}";
4097
+		if ( ! has_filter($tagName)) {
4098 4098
 			throw new EE_Error(
4099 4099
 				sprintf(
4100
-					__( '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' ),
4100
+					__('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'),
4101 4101
 					$methodName,
4102 4102
 					$className,
4103 4103
 					$tagName,
@@ -4106,7 +4106,7 @@  discard block
 block discarded – undo
4106 4106
 			);
4107 4107
 		}
4108 4108
 
4109
-		return apply_filters($tagName,null,$this,$args);
4109
+		return apply_filters($tagName, null, $this, $args);
4110 4110
 	}
4111 4111
 
4112 4112
 
@@ -4119,22 +4119,22 @@  discard block
 block discarded – undo
4119 4119
 	 * @throws EE_Error
4120 4120
 	 * @return EE_Base_Class
4121 4121
 	 */
4122
-	public function ensure_is_obj( $base_class_obj_or_id, $ensure_is_in_db = FALSE ){
4122
+	public function ensure_is_obj($base_class_obj_or_id, $ensure_is_in_db = FALSE) {
4123 4123
 		$className = $this->_get_class_name();
4124 4124
 		$primary_key_field = $this->get_primary_key_field();
4125
-		if( $base_class_obj_or_id instanceof $className ){
4125
+		if ($base_class_obj_or_id instanceof $className) {
4126 4126
 			$model_object = $base_class_obj_or_id;
4127
-		}elseif( $primary_key_field instanceof EE_Primary_Key_Int_Field && (
4128
-				is_int( $base_class_obj_or_id ) ||
4129
-				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)
4127
+		}elseif ($primary_key_field instanceof EE_Primary_Key_Int_Field && (
4128
+				is_int($base_class_obj_or_id) ||
4129
+				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)
4130 4130
 			$model_object = $this->get_one_by_ID($base_class_obj_or_id);
4131
-		}elseif( $primary_key_field instanceof EE_Primary_Key_String_Field && is_string($base_class_obj_or_id) ){
4131
+		}elseif ($primary_key_field instanceof EE_Primary_Key_String_Field && is_string($base_class_obj_or_id)) {
4132 4132
 			//assume its a string representation of the object
4133 4133
 			$model_object = $this->get_one_by_ID($base_class_obj_or_id);
4134
-		}else{
4135
-			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)));
4134
+		} else {
4135
+			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)));
4136 4136
 		}
4137
-		if( $model_object->ID() == NULL && $ensure_is_in_db){
4137
+		if ($model_object->ID() == NULL && $ensure_is_in_db) {
4138 4138
 			$model_object->save();
4139 4139
 		}
4140 4140
 		return $model_object;
@@ -4150,19 +4150,19 @@  discard block
 block discarded – undo
4150 4150
 	 * @return int|string depending on the type of this model object's ID
4151 4151
 	 * @throws EE_Error
4152 4152
 	 */
4153
-	public function ensure_is_ID($base_class_obj_or_id){
4153
+	public function ensure_is_ID($base_class_obj_or_id) {
4154 4154
 		$className = $this->_get_class_name();
4155
-		if( $base_class_obj_or_id instanceof $className ){
4155
+		if ($base_class_obj_or_id instanceof $className) {
4156 4156
 			/** @var $base_class_obj_or_id EE_Base_Class */
4157 4157
 			$id = $base_class_obj_or_id->ID();
4158
-		}elseif(is_int($base_class_obj_or_id)){
4158
+		}elseif (is_int($base_class_obj_or_id)) {
4159 4159
 			//assume it's an ID
4160 4160
 			$id = $base_class_obj_or_id;
4161
-		}elseif(is_string($base_class_obj_or_id)){
4161
+		}elseif (is_string($base_class_obj_or_id)) {
4162 4162
 			//assume its a string representation of the object
4163 4163
 			$id = $base_class_obj_or_id;
4164
-		}else{
4165
-			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)));
4164
+		} else {
4165
+			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)));
4166 4166
 		}
4167 4167
 		return $id;
4168 4168
 	}
@@ -4185,14 +4185,14 @@  discard block
 block discarded – undo
4185 4185
 	 * @param int $values_already_prepared like one of the constants on EEM_Base
4186 4186
 	 * @return void
4187 4187
 	 */
4188
-	public function assume_values_already_prepared_by_model_object($values_already_prepared = self::not_prepared_by_model_object){
4188
+	public function assume_values_already_prepared_by_model_object($values_already_prepared = self::not_prepared_by_model_object) {
4189 4189
 		$this->_values_already_prepared_by_model_object = $values_already_prepared;
4190 4190
 	}
4191 4191
 	/**
4192 4192
 	 * Read comments for assume_values_already_prepared_by_model_object()
4193 4193
 	 * @return int
4194 4194
 	 */
4195
-	public function get_assumption_concerning_values_already_prepared_by_model_object(){
4195
+	public function get_assumption_concerning_values_already_prepared_by_model_object() {
4196 4196
 		return $this->_values_already_prepared_by_model_object;
4197 4197
 	}
4198 4198
 
@@ -4200,17 +4200,17 @@  discard block
 block discarded – undo
4200 4200
 	 * Gets all the indexes on this model
4201 4201
 	 * @return EE_Index[]
4202 4202
 	 */
4203
-	public function indexes(){
4203
+	public function indexes() {
4204 4204
 		return $this->_indexes;
4205 4205
 	}
4206 4206
 	/**
4207 4207
 	 * Gets all the Unique Indexes on this model
4208 4208
 	 * @return EE_Unique_Index[]
4209 4209
 	 */
4210
-	public function unique_indexes(){
4210
+	public function unique_indexes() {
4211 4211
 		$unique_indexes = array();
4212
-		foreach($this->_indexes as $name => $index){
4213
-			if($index instanceof EE_Unique_Index){
4212
+		foreach ($this->_indexes as $name => $index) {
4213
+			if ($index instanceof EE_Unique_Index) {
4214 4214
 				$unique_indexes [$name] = $index;
4215 4215
 			}
4216 4216
 		}
@@ -4223,13 +4223,13 @@  discard block
 block discarded – undo
4223 4223
 	 * on a primary index
4224 4224
 	 * @return EE_Model_Field_Base[] indexed by the field's name
4225 4225
 	 */
4226
-	public function get_combined_primary_key_fields(){
4227
-		foreach($this->indexes() as $index){
4228
-			if($index instanceof EE_Primary_Key_Index){
4226
+	public function get_combined_primary_key_fields() {
4227
+		foreach ($this->indexes() as $index) {
4228
+			if ($index instanceof EE_Primary_Key_Index) {
4229 4229
 				return $index->fields();
4230 4230
 			}
4231 4231
 		}
4232
-		return array( $this->primary_key_name() => $this->get_primary_key_field());
4232
+		return array($this->primary_key_name() => $this->get_primary_key_field());
4233 4233
 	}
4234 4234
 	
4235 4235
 
@@ -4239,7 +4239,7 @@  discard block
 block discarded – undo
4239 4239
 	 * @param array $cols_n_values keys are field names, values are their values
4240 4240
 	 * @return string
4241 4241
 	 */
4242
-	public function get_index_primary_key_string($cols_n_values){
4242
+	public function get_index_primary_key_string($cols_n_values) {
4243 4243
 		$cols_n_values_for_primary_key_index = array_intersect_key($cols_n_values, $this->get_combined_primary_key_fields());
4244 4244
 		return http_build_query($cols_n_values_for_primary_key_index);
4245 4245
 	}
@@ -4251,13 +4251,13 @@  discard block
 block discarded – undo
4251 4251
 	 * @param string $index_primary_key_string
4252 4252
 	 * @return null|array
4253 4253
 	 */
4254
-	function parse_index_primary_key_string( $index_primary_key_string) {
4254
+	function parse_index_primary_key_string($index_primary_key_string) {
4255 4255
 		$key_fields = $this->get_combined_primary_key_fields();
4256 4256
 		//check all of them are in the $id
4257 4257
 		$key_vals_in_combined_pk = array();
4258
-		parse_str( $index_primary_key_string, $key_vals_in_combined_pk );
4259
-		foreach( $key_fields as $key_field_name => $field_obj ) {
4260
-			if( ! isset( $key_vals_in_combined_pk[ $key_field_name ] ) ){
4258
+		parse_str($index_primary_key_string, $key_vals_in_combined_pk);
4259
+		foreach ($key_fields as $key_field_name => $field_obj) {
4260
+			if ( ! isset($key_vals_in_combined_pk[$key_field_name])) {
4261 4261
 				return NULL;
4262 4262
 			}
4263 4263
 		}
@@ -4270,10 +4270,10 @@  discard block
 block discarded – undo
4270 4270
 	 * @param array $key_vals
4271 4271
 	 * @return boolean
4272 4272
 	 */
4273
-	function has_all_combined_primary_key_fields( $key_vals ) {
4274
-		$keys_it_should_have = array_keys( $this->get_combined_primary_key_fields() );
4275
-		foreach( $keys_it_should_have as $key ){
4276
-			if( ! isset( $key_vals[ $key ] ) ){
4273
+	function has_all_combined_primary_key_fields($key_vals) {
4274
+		$keys_it_should_have = array_keys($this->get_combined_primary_key_fields());
4275
+		foreach ($keys_it_should_have as $key) {
4276
+			if ( ! isset($key_vals[$key])) {
4277 4277
 				return false;
4278 4278
 			}
4279 4279
 		}
@@ -4289,23 +4289,23 @@  discard block
 block discarded – undo
4289 4289
 	 * @throws EE_Error
4290 4290
 	 * @return \EE_Base_Class[] Array keys are object IDs (if there is a primary key on the model. if not, numerically indexed)
4291 4291
 	 */
4292
-	public function get_all_copies($model_object_or_attributes_array, $query_params = array()){
4292
+	public function get_all_copies($model_object_or_attributes_array, $query_params = array()) {
4293 4293
 
4294
-		if($model_object_or_attributes_array instanceof EE_Base_Class){
4294
+		if ($model_object_or_attributes_array instanceof EE_Base_Class) {
4295 4295
 			$attributes_array = $model_object_or_attributes_array->model_field_array();
4296
-		}elseif(is_array($model_object_or_attributes_array)){
4296
+		}elseif (is_array($model_object_or_attributes_array)) {
4297 4297
 			$attributes_array = $model_object_or_attributes_array;
4298
-		}else{
4299
-			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));
4298
+		} else {
4299
+			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));
4300 4300
 		}
4301 4301
 		//even copies obviously won't have the same ID, so remove the primary key
4302 4302
 		//from the WHERE conditions for finding copies (if there is a primary key, of course)
4303
-		if($this->has_primary_key_field() && isset($attributes_array[$this->primary_key_name()])){
4303
+		if ($this->has_primary_key_field() && isset($attributes_array[$this->primary_key_name()])) {
4304 4304
 			unset($attributes_array[$this->primary_key_name()]);
4305 4305
 		}
4306
-		if(isset($query_params[0])){
4307
-			$query_params[0] = array_merge($attributes_array,$query_params);
4308
-		}else{
4306
+		if (isset($query_params[0])) {
4307
+			$query_params[0] = array_merge($attributes_array, $query_params);
4308
+		} else {
4309 4309
 			$query_params[0] = $attributes_array;
4310 4310
 		}
4311 4311
 		return $this->get_all($query_params);
@@ -4319,16 +4319,16 @@  discard block
 block discarded – undo
4319 4319
 	 * @param array $query_params
4320 4320
 	 * @return EE_Base_Class
4321 4321
 	 */
4322
-	function get_one_copy($model_object_or_attributes_array,$query_params = array()){
4323
-		if( ! is_array( $query_params ) ){
4324
-			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' );
4322
+	function get_one_copy($model_object_or_attributes_array, $query_params = array()) {
4323
+		if ( ! is_array($query_params)) {
4324
+			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');
4325 4325
 			$query_params = array();
4326 4326
 		}
4327 4327
 		$query_params['limit'] = 1;
4328
-		$copies = $this->get_all_copies($model_object_or_attributes_array,$query_params);
4329
-		if(is_array($copies)){
4328
+		$copies = $this->get_all_copies($model_object_or_attributes_array, $query_params);
4329
+		if (is_array($copies)) {
4330 4330
 			return array_shift($copies);
4331
-		}else{
4331
+		} else {
4332 4332
 			return null;
4333 4333
 		}
4334 4334
 	}
@@ -4342,10 +4342,10 @@  discard block
 block discarded – undo
4342 4342
 	 * @param int|string $id the value of the primary key to update
4343 4343
 	 * @return int number of rows updated
4344 4344
 	 */
4345
-	public function update_by_ID($fields_n_values,$id){
4345
+	public function update_by_ID($fields_n_values, $id) {
4346 4346
 		$query_params = array(0=>array($this->get_primary_key_field()->get_name() => $id),
4347 4347
 			'default_where_conditions'=>'other_models_only',);
4348
-		return $this->update($fields_n_values,$query_params);
4348
+		return $this->update($fields_n_values, $query_params);
4349 4349
 	}
4350 4350
 
4351 4351
 
@@ -4356,12 +4356,12 @@  discard block
 block discarded – undo
4356 4356
 	 * @return string an operator which can be used in SQL
4357 4357
 	 * @throws EE_Error
4358 4358
 	 */
4359
-	private function _prepare_operator_for_sql($operator_supplied){
4359
+	private function _prepare_operator_for_sql($operator_supplied) {
4360 4360
 		$sql_operator = isset($this->_valid_operators[$operator_supplied]) ? $this->_valid_operators[$operator_supplied] : null;
4361
-		if($sql_operator){
4361
+		if ($sql_operator) {
4362 4362
 			return $sql_operator;
4363
-		}else{
4364
-			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))));
4363
+		} else {
4364
+			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))));
4365 4365
 		}
4366 4366
 	}
4367 4367
 
@@ -4371,10 +4371,10 @@  discard block
 block discarded – undo
4371 4371
 	 * @param array $query_params like get_all's
4372 4372
 	 * @return string[]
4373 4373
 	 */
4374
-	public function get_all_names($query_params = array()){
4374
+	public function get_all_names($query_params = array()) {
4375 4375
 		$objs = $this->get_all($query_params);
4376 4376
 		$names = array();
4377
-		foreach($objs as $obj){
4377
+		foreach ($objs as $obj) {
4378 4378
 			$names[$obj->ID()] = $obj->name();
4379 4379
 		}
4380 4380
 		return $names;
@@ -4389,22 +4389,22 @@  discard block
 block discarded – undo
4389 4389
 	 * @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
4390 4390
 	 * @return array
4391 4391
 	 */
4392
-	public function get_IDs( $model_objects, $filter_out_empty_ids = false) {
4393
-		if( ! $this->has_primary_key_field() ) {
4394
-			if( WP_DEBUG ) {
4395
-				EE_Error::add_error( __( 'Trying to get IDs from a model than has no primary key', 'event_espresso' ), __FILE__, __FUNCTION__, __LINE__ );
4392
+	public function get_IDs($model_objects, $filter_out_empty_ids = false) {
4393
+		if ( ! $this->has_primary_key_field()) {
4394
+			if (WP_DEBUG) {
4395
+				EE_Error::add_error(__('Trying to get IDs from a model than has no primary key', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__);
4396 4396
 				return array();
4397 4397
 			}
4398 4398
 		}
4399 4399
 		$IDs = array();
4400
-		foreach( $model_objects as $model_object ) {
4400
+		foreach ($model_objects as $model_object) {
4401 4401
 			$id = $model_object->ID();
4402
-			if( ! $id ) {
4403
-				if( $filter_out_empty_ids ) {
4402
+			if ( ! $id) {
4403
+				if ($filter_out_empty_ids) {
4404 4404
 					continue;
4405 4405
 				}
4406
-				if( WP_DEBUG ) {
4407
-					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__ );
4406
+				if (WP_DEBUG) {
4407
+					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__);
4408 4408
 				}
4409 4409
 			}
4410 4410
 			$IDs[] = $id;
@@ -4417,8 +4417,8 @@  discard block
 block discarded – undo
4417 4417
 	 * are no capabilities that relate to this model returns false
4418 4418
 	 * @return string|false
4419 4419
 	 */
4420
-	public function cap_slug(){
4421
-		return apply_filters( 'FHEE__EEM_Base__cap_slug', $this->_caps_slug, $this);
4420
+	public function cap_slug() {
4421
+		return apply_filters('FHEE__EEM_Base__cap_slug', $this->_caps_slug, $this);
4422 4422
 	}
4423 4423
 
4424 4424
 	/**
@@ -4430,27 +4430,27 @@  discard block
 block discarded – undo
4430 4430
 	 * @param string $context
4431 4431
 	 * @return EE_Default_Where_Conditions[] indexed by associated capability
4432 4432
 	 */
4433
-	public function cap_restrictions( $context = EEM_Base::caps_read ) {
4434
-		EEM_Base::verify_is_valid_cap_context( $context );
4433
+	public function cap_restrictions($context = EEM_Base::caps_read) {
4434
+		EEM_Base::verify_is_valid_cap_context($context);
4435 4435
 		//check if we ought to run the restriction generator first
4436
-		if( isset( $this->_cap_restriction_generators[ $context ] ) &&
4437
-				$this->_cap_restriction_generators[ $context ] instanceof EE_Restriction_Generator_Base &&
4438
-				! $this->_cap_restriction_generators[ $context ]->has_generated_cap_restrictions() ) {
4439
-			$this->_cap_restrictions[ $context ] = array_merge( $this->_cap_restrictions[ $context ],  $this->_cap_restriction_generators[ $context ]->generate_restrictions() );
4436
+		if (isset($this->_cap_restriction_generators[$context]) &&
4437
+				$this->_cap_restriction_generators[$context] instanceof EE_Restriction_Generator_Base &&
4438
+				! $this->_cap_restriction_generators[$context]->has_generated_cap_restrictions()) {
4439
+			$this->_cap_restrictions[$context] = array_merge($this->_cap_restrictions[$context], $this->_cap_restriction_generators[$context]->generate_restrictions());
4440 4440
 		}
4441 4441
 		//and make sure we've finalized the construction of each restriction
4442
-		foreach( $this->_cap_restrictions[ $context ] as $where_conditions_obj ) {
4443
-			$where_conditions_obj->_finalize_construct( $this );
4442
+		foreach ($this->_cap_restrictions[$context] as $where_conditions_obj) {
4443
+			$where_conditions_obj->_finalize_construct($this);
4444 4444
 		}
4445 4445
 
4446
-		return $this->_cap_restrictions[ $context ];
4446
+		return $this->_cap_restrictions[$context];
4447 4447
 	}
4448 4448
 
4449 4449
 	/**
4450 4450
 	 * Indicating whether or not this model thinks its a wp core model
4451 4451
 	 * @return boolean
4452 4452
 	 */
4453
-	public function is_wp_core_model(){
4453
+	public function is_wp_core_model() {
4454 4454
 		return $this->_wp_core_model;
4455 4455
 	}
4456 4456
 
@@ -4460,12 +4460,12 @@  discard block
 block discarded – undo
4460 4460
 	 * @param string $context one of EEM_Base::caps_ constants
4461 4461
 	 * @return EE_Default_Where_Conditions[] indexed by capability name
4462 4462
 	 */
4463
-	public function caps_missing( $context = EEM_Base::caps_read ) {
4463
+	public function caps_missing($context = EEM_Base::caps_read) {
4464 4464
 		$missing_caps = array();
4465
-		$cap_restrictions = $this->cap_restrictions( $context );
4466
-		foreach( $cap_restrictions as $cap => $restriction_if_no_cap ) {
4467
-			if( ! EE_Capabilities::instance()->current_user_can( $cap, $this->get_this_model_name() . '_model_applying_caps') ) {
4468
-				$missing_caps[ $cap ] = $restriction_if_no_cap;
4465
+		$cap_restrictions = $this->cap_restrictions($context);
4466
+		foreach ($cap_restrictions as $cap => $restriction_if_no_cap) {
4467
+			if ( ! EE_Capabilities::instance()->current_user_can($cap, $this->get_this_model_name().'_model_applying_caps')) {
4468
+				$missing_caps[$cap] = $restriction_if_no_cap;
4469 4469
 			}
4470 4470
 		}
4471 4471
 		return $missing_caps;
@@ -4477,7 +4477,7 @@  discard block
 block discarded – undo
4477 4477
 	 * one of 'read', 'edit', or 'delete'
4478 4478
 	 */
4479 4479
 	public function cap_contexts_to_cap_action_map() {
4480
-		return apply_filters( 'FHEE__EEM_Base__cap_contexts_to_cap_action_map', $this->_cap_contexts_to_cap_action_map, $this );
4480
+		return apply_filters('FHEE__EEM_Base__cap_contexts_to_cap_action_map', $this->_cap_contexts_to_cap_action_map, $this);
4481 4481
 	}
4482 4482
 
4483 4483
 
@@ -4488,19 +4488,19 @@  discard block
 block discarded – undo
4488 4488
 	 * @return string one of EEM_Base::cap_contexts_to_cap_action_map() values
4489 4489
 	 * @throws \EE_Error
4490 4490
 	 */
4491
-	public function cap_action_for_context( $context ) {
4491
+	public function cap_action_for_context($context) {
4492 4492
 		$mapping = $this->cap_contexts_to_cap_action_map();
4493
-		if( isset( $mapping[ $context ] ) ) {
4494
-			return $mapping[ $context ];
4493
+		if (isset($mapping[$context])) {
4494
+			return $mapping[$context];
4495 4495
 		}
4496
-		if( $action = apply_filters( 'FHEE__EEM_Base__cap_action_for_context', null, $this, $mapping, $context ) ) {
4496
+		if ($action = apply_filters('FHEE__EEM_Base__cap_action_for_context', null, $this, $mapping, $context)) {
4497 4497
 			return $action;
4498 4498
 		}
4499 4499
 		throw new EE_Error(
4500 4500
 			sprintf(
4501
-				__( 'Cannot find capability restrictions for context "%1$s", allowed values are:%2$s', 'event_espresso' ),
4501
+				__('Cannot find capability restrictions for context "%1$s", allowed values are:%2$s', 'event_espresso'),
4502 4502
 				$context,
4503
-				implode(',', array_keys( $this->cap_contexts_to_cap_action_map() ) )
4503
+				implode(',', array_keys($this->cap_contexts_to_cap_action_map()))
4504 4504
 			)
4505 4505
 		);
4506 4506
 
@@ -4511,7 +4511,7 @@  discard block
 block discarded – undo
4511 4511
 	 * @return array
4512 4512
 	 */
4513 4513
 	static public function valid_cap_contexts() {
4514
-		return apply_filters( 'FHEE__EEM_Base__valid_cap_contexts', array(
4514
+		return apply_filters('FHEE__EEM_Base__valid_cap_contexts', array(
4515 4515
 			self::caps_read,
4516 4516
 			self::caps_read_admin,
4517 4517
 			self::caps_edit,
@@ -4527,17 +4527,17 @@  discard block
 block discarded – undo
4527 4527
 	 * @return bool
4528 4528
 	 * @throws \EE_Error
4529 4529
 	 */
4530
-	static public function verify_is_valid_cap_context( $context ) {
4530
+	static public function verify_is_valid_cap_context($context) {
4531 4531
 		$valid_cap_contexts = EEM_Base::valid_cap_contexts();
4532
-		if( in_array( $context, $valid_cap_contexts ) ) {
4532
+		if (in_array($context, $valid_cap_contexts)) {
4533 4533
 			return true;
4534
-		}else{
4534
+		} else {
4535 4535
 			throw new EE_Error(
4536 4536
 				sprintf(
4537
-					__( 'Context "%1$s" passed into model "%2$s" is not a valid context. They are: %3$s', 'event_espresso' ),
4537
+					__('Context "%1$s" passed into model "%2$s" is not a valid context. They are: %3$s', 'event_espresso'),
4538 4538
 					$context,
4539
-					'EEM_Base' ,
4540
-					implode(',', $valid_cap_contexts )
4539
+					'EEM_Base',
4540
+					implode(',', $valid_cap_contexts)
4541 4541
 				)
4542 4542
 			);
4543 4543
 		}
Please login to merge, or discard this patch.