Completed
Branch BUG-5580-mike-implementation (468206)
by
unknown
08:00 queued 1434:13
created
core/db_classes/EE_Ticket_Template.class.php 1 patch
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1
-<?php if ( ! defined( 'EVENT_ESPRESSO_VERSION' ) ) {
2
-	exit( 'No direct script access allowed' );
1
+<?php if ( ! defined('EVENT_ESPRESSO_VERSION')) {
2
+	exit('No direct script access allowed');
3 3
 }
4 4
 /**
5 5
  * Event Espresso
@@ -35,9 +35,9 @@  discard block
 block discarded – undo
35 35
 	 * @param string $timezone
36 36
 	 * @return EE_Ticket_Template|mixed
37 37
 	 */
38
-	public static function new_instance( $props_n_values = array(), $timezone = '' ) {
39
-		$has_object = parent::_check_for_object( $props_n_values, __CLASS__, $timezone );
40
-		return $has_object ? $has_object : new self( $props_n_values, FALSE, $timezone );
38
+	public static function new_instance($props_n_values = array(), $timezone = '') {
39
+		$has_object = parent::_check_for_object($props_n_values, __CLASS__, $timezone);
40
+		return $has_object ? $has_object : new self($props_n_values, FALSE, $timezone);
41 41
 	}
42 42
 
43 43
 
@@ -47,8 +47,8 @@  discard block
 block discarded – undo
47 47
 	 * @param string $timezone
48 48
 	 * @return EE_Ticket_Template
49 49
 	 */
50
-	public static function new_instance_from_db( $props_n_values = array(), $timezone = '' ) {
51
-		return new self( $props_n_values, TRUE, $timezone );
50
+	public static function new_instance_from_db($props_n_values = array(), $timezone = '') {
51
+		return new self($props_n_values, TRUE, $timezone);
52 52
 	}
53 53
 
54 54
 
Please login to merge, or discard this patch.
core/db_classes/EE_WP_User.class.php 1 patch
Spacing   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1
-<?php if ( !defined( 'EVENT_ESPRESSO_VERSION' ) ) {
2
-	exit( 'No direct script access allowed' );
1
+<?php if ( ! defined('EVENT_ESPRESSO_VERSION')) {
2
+	exit('No direct script access allowed');
3 3
 }
4 4
 /**
5 5
  * EE_WP_User class
@@ -22,9 +22,9 @@  discard block
 block discarded – undo
22 22
 	 * @param array $props_n_values
23 23
 	 * @return EE_WP_User|mixed
24 24
 	 */
25
-	public static function new_instance( $props_n_values = array() ) {
26
-		$has_object = parent::_check_for_object( $props_n_values, __CLASS__ );
27
-		return $has_object ? $has_object : new self( $props_n_values );
25
+	public static function new_instance($props_n_values = array()) {
26
+		$has_object = parent::_check_for_object($props_n_values, __CLASS__);
27
+		return $has_object ? $has_object : new self($props_n_values);
28 28
 	}
29 29
 
30 30
 
@@ -33,8 +33,8 @@  discard block
 block discarded – undo
33 33
 	 * @param array $props_n_values
34 34
 	 * @return EE_WP_User
35 35
 	 */
36
-	public static function new_instance_from_db( $props_n_values = array() ) {
37
-		return new self( $props_n_values, TRUE );
36
+	public static function new_instance_from_db($props_n_values = array()) {
37
+		return new self($props_n_values, TRUE);
38 38
 	}
39 39
 
40 40
 	/**
@@ -42,8 +42,8 @@  discard block
 block discarded – undo
42 42
 	 * @return WP_User
43 43
 	 */
44 44
 	public function wp_user_obj() {
45
-		if( ! $this->_wp_user_obj ) {
46
-			$this->_wp_user_obj = get_user_by('ID', $this->ID() );
45
+		if ( ! $this->_wp_user_obj) {
46
+			$this->_wp_user_obj = get_user_by('ID', $this->ID());
47 47
 		}
48 48
 		return $this->_wp_user_obj;
49 49
 	}
Please login to merge, or discard this patch.
core/db_models/EEM_Attendee.model.php 4 patches
Indentation   +26 added lines, -26 removed lines patch added patch discarded remove patch
@@ -105,13 +105,13 @@  discard block
 block discarded – undo
105 105
 
106 106
 
107 107
 	/**
108
-	*		retrieve  a single attendee from db via their ID
109
-	*
110
-	* 		@access		public
111
-	* 		@param		$ATT_ID
112
-	*		@return 		mixed		array on success, FALSE on fail
108
+	 *		retrieve  a single attendee from db via their ID
109
+	 *
110
+	 * 		@access		public
111
+	 * 		@param		$ATT_ID
112
+	 *		@return 		mixed		array on success, FALSE on fail
113 113
 	 * 		@deprecated
114
-	*/
114
+	 */
115 115
 	public function get_attendee_by_ID( $ATT_ID = FALSE ) {
116 116
 		// retrieve a particular EE_Attendee
117 117
 		return $this->get_one_by_ID( $ATT_ID );
@@ -121,12 +121,12 @@  discard block
 block discarded – undo
121 121
 
122 122
 
123 123
 	/**
124
-	*		retrieve  a single attendee from db via their ID
125
-	*
126
-	* 		@access		public
127
-	* 		@param		array $where_cols_n_values
128
-	*		@return 		mixed		array on success, FALSE on fail
129
-	*/
124
+	 *		retrieve  a single attendee from db via their ID
125
+	 *
126
+	 * 		@access		public
127
+	 * 		@param		array $where_cols_n_values
128
+	 *		@return 		mixed		array on success, FALSE on fail
129
+	 */
130 130
 	public function get_attendee( $where_cols_n_values = array() ) {
131 131
 
132 132
 		if ( empty( $where_cols_n_values )) {
@@ -174,20 +174,20 @@  discard block
 block discarded – undo
174 174
 
175 175
 
176 176
 	/**
177
-             * Takes an incoming array of EE_Registration ids and sends back a list of corresponding non duplicate
178
-             * EE_Attendee objects.
179
-             *
180
-             * @since    4.3.0
181
-             * @param  array $ids array of EE_Registration ids
182
-             * @return  EE_Attendee[]
183
-             */
184
-            public function get_array_of_contacts_from_reg_ids( $ids ) {
185
-                $ids = (array) $ids;
186
-                $_where = array(
187
-                    'Registration.REG_ID' => array( 'in', $ids )
188
-                    );
189
-                return $this->get_all( array( $_where ) );
190
-            }
177
+	 * Takes an incoming array of EE_Registration ids and sends back a list of corresponding non duplicate
178
+	 * EE_Attendee objects.
179
+	 *
180
+	 * @since    4.3.0
181
+	 * @param  array $ids array of EE_Registration ids
182
+	 * @return  EE_Attendee[]
183
+	 */
184
+			public function get_array_of_contacts_from_reg_ids( $ids ) {
185
+				$ids = (array) $ids;
186
+				$_where = array(
187
+					'Registration.REG_ID' => array( 'in', $ids )
188
+					);
189
+				return $this->get_all( array( $_where ) );
190
+			}
191 191
 
192 192
 
193 193
 }
Please login to merge, or discard this patch.
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -256,7 +256,7 @@
 block discarded – undo
256 256
 	* 		@param	int	$TXN_ID
257 257
 	* 		@param    int		$ATT_ID
258 258
 	* 		@param    int		$att_nmbr 	in case the ATT_ID is the same for multiple registrations (same details used) then the attendee number is required
259
-	*		@return 		mixed		array on success, FALSE on fail
259
+	*		@return 		EE_Soft_Delete_Base_Class|null		array on success, FALSE on fail
260 260
 	*/
261 261
 	public function get_registration_for_transaction_attendee( $TXN_ID = 0, $ATT_ID = 0, $att_nmbr = 0 ) {
262 262
 		return $this->get_one(array(
Please login to merge, or discard this patch.
Braces   +3 added lines, -1 removed lines patch added patch discarded remove patch
@@ -1,4 +1,6 @@
 block discarded – undo
1
-<?php if ( ! defined('EVENT_ESPRESSO_VERSION')) exit('No direct script access allowed');
1
+<?php if ( ! defined('EVENT_ESPRESSO_VERSION')) {
2
+	exit('No direct script access allowed');
3
+}
2 4
 /**
3 5
  * Event Espresso
4 6
  *
Please login to merge, or discard this patch.
Spacing   +52 added lines, -52 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1 1
 <?php if ( ! defined('EVENT_ESPRESSO_VERSION')) exit('No direct script access allowed');
2
-require_once ( EE_MODELS . 'EEM_Base.model.php' );
2
+require_once (EE_MODELS.'EEM_Base.model.php');
3 3
 
4 4
 /**
5 5
  *
@@ -21,60 +21,60 @@  discard block
 block discarded – undo
21 21
 	 * Please instead use the EEM_Attendee::system_question_* constants
22 22
 	 * @deprecated
23 23
 	 */
24
-	const fname_question_id=1;
24
+	const fname_question_id = 1;
25 25
 
26 26
 	/**
27 27
 	 * @deprecated
28 28
 	 */
29
-	const lname_question_id=2;
29
+	const lname_question_id = 2;
30 30
 
31 31
 
32 32
 	/**
33 33
 	 * @deprecated
34 34
 	 */
35
-	const email_question_id=3;
35
+	const email_question_id = 3;
36 36
 
37 37
 
38 38
 	/**
39 39
 	 * @deprecated
40 40
 	 */
41
-	const address_question_id=4;
41
+	const address_question_id = 4;
42 42
 
43 43
 
44 44
 	/**
45 45
 	 * @deprecated
46 46
 	 */
47
-	const address2_question_id=5;
47
+	const address2_question_id = 5;
48 48
 
49 49
 
50 50
 	/**
51 51
 	 * @deprecated
52 52
 	 */
53
-	const city_question_id=6;
53
+	const city_question_id = 6;
54 54
 
55 55
 
56 56
 	/**
57 57
 	 * @deprecated
58 58
 	 */
59
-	const state_question_id=7;
59
+	const state_question_id = 7;
60 60
 
61 61
 
62 62
 	/**
63 63
 	 * @deprecated
64 64
 	 */
65
-	const country_question_id=8;
65
+	const country_question_id = 8;
66 66
 
67 67
 
68 68
 	/**
69 69
 	 * @deprecated
70 70
 	 */
71
-	const zip_question_id=9;
71
+	const zip_question_id = 9;
72 72
 
73 73
 
74 74
 	/**
75 75
 	 * @deprecated
76 76
 	 */
77
-	const phone_question_id=10;
77
+	const phone_question_id = 10;
78 78
 
79 79
 	/**
80 80
 	 * When looking for questions that correspond to attendee fields,
@@ -119,9 +119,9 @@  discard block
 block discarded – undo
119 119
 	 * @access protected
120 120
 	 * @param null $timezone
121 121
 	 */
122
-	protected function __construct( $timezone = NULL ) {
123
-		$this->singular_item = __('Attendee','event_espresso');
124
-		$this->plural_item = __('Attendees','event_espresso');
122
+	protected function __construct($timezone = NULL) {
123
+		$this->singular_item = __('Attendee', 'event_espresso');
124
+		$this->plural_item = __('Attendees', 'event_espresso');
125 125
 		$this->_tables = array(
126 126
 			'Attendee_CPT'=> new EE_Primary_Table('posts', 'ID'),
127 127
 			'Attendee_Meta'=>new EE_Secondary_Table('esp_attendee_meta', 'ATTM_ID', 'ATT_ID')
@@ -135,36 +135,36 @@  discard block
 block discarded – undo
135 135
 				'ATT_created'=>new EE_Datetime_Field('post_date', __("Time Attendee Created", "event_espresso"), false, time()),
136 136
 				'ATT_short_bio'=>new EE_Simple_HTML_Field('post_excerpt', __("Attendee Short Biography", "event_espresso"), true, __("No Biography Provided", "event_espresso")),
137 137
 				'ATT_modified'=>new EE_Datetime_Field('post_modified', __("Time Attendee Last Modified", "event_espresso"), FALSE, time()),
138
-				'ATT_author'=>new EE_WP_User_Field('post_author', __("Creator ID of the first Event attended", "event_espresso"), false ),
138
+				'ATT_author'=>new EE_WP_User_Field('post_author', __("Creator ID of the first Event attended", "event_espresso"), false),
139 139
 				'ATT_parent'=>new EE_DB_Only_Int_Field('post_parent', __("Parent Attendee (unused)", "event_espresso"), false, 0),
140
-				'post_type'=>new EE_WP_Post_Type_Field('espresso_attendees'),// EE_DB_Only_Text_Field('post_type', __("Post Type of Attendee", "event_espresso"), false,'espresso_attendees'),
140
+				'post_type'=>new EE_WP_Post_Type_Field('espresso_attendees'), // EE_DB_Only_Text_Field('post_type', __("Post Type of Attendee", "event_espresso"), false,'espresso_attendees'),
141 141
 				'status' => new EE_WP_Post_Status_Field('post_status', __('Attendee Status', 'event_espresso'), false, 'publish')
142 142
 			),
143 143
 			'Attendee_Meta'=>array(
144
-				'ATTM_ID'=> new EE_DB_Only_Int_Field('ATTM_ID', __('Attendee Meta Row ID','event_espresso'), false),
144
+				'ATTM_ID'=> new EE_DB_Only_Int_Field('ATTM_ID', __('Attendee Meta Row ID', 'event_espresso'), false),
145 145
 				'ATT_ID_fk'=>new EE_DB_Only_Int_Field('ATT_ID', __("Foreign Key to Attendee in Post Table", "event_espresso"), false),
146
-				'ATT_fname'=>new EE_Plain_Text_Field('ATT_fname', __('First Name','event_espresso'), true, ''),
147
-				'ATT_lname'=>new EE_Plain_Text_Field('ATT_lname', __('Last Name','event_espresso'), true, ''),
148
-				'ATT_address'=>new EE_Plain_Text_Field('ATT_address', __('Address Part 1','event_espresso'), true, ''),
149
-				'ATT_address2'=>new EE_Plain_Text_Field('ATT_address2', __('Address Part 2','event_espresso'), true, ''),
150
-				'ATT_city'=>new EE_Plain_Text_Field('ATT_city', __('City','event_espresso'), true, ''),
151
-				'STA_ID'=>new EE_Foreign_Key_Int_Field('STA_ID', __('State','event_espresso'), true,0,'State'),
152
-				'CNT_ISO'=>new EE_Foreign_Key_String_Field('CNT_ISO', __('Country','event_espresso'), true,'','Country'),
153
-				'ATT_zip'=>new EE_Plain_Text_Field('ATT_zip', __('ZIP/Postal Code','event_espresso'), true, ''),
154
-				'ATT_email'=>new EE_Email_Field('ATT_email', __('Email Address','event_espresso'), true, ''),
155
-				'ATT_phone'=>new EE_Plain_Text_Field('ATT_phone', __('Phone','event_espresso'), true, '')
146
+				'ATT_fname'=>new EE_Plain_Text_Field('ATT_fname', __('First Name', 'event_espresso'), true, ''),
147
+				'ATT_lname'=>new EE_Plain_Text_Field('ATT_lname', __('Last Name', 'event_espresso'), true, ''),
148
+				'ATT_address'=>new EE_Plain_Text_Field('ATT_address', __('Address Part 1', 'event_espresso'), true, ''),
149
+				'ATT_address2'=>new EE_Plain_Text_Field('ATT_address2', __('Address Part 2', 'event_espresso'), true, ''),
150
+				'ATT_city'=>new EE_Plain_Text_Field('ATT_city', __('City', 'event_espresso'), true, ''),
151
+				'STA_ID'=>new EE_Foreign_Key_Int_Field('STA_ID', __('State', 'event_espresso'), true, 0, 'State'),
152
+				'CNT_ISO'=>new EE_Foreign_Key_String_Field('CNT_ISO', __('Country', 'event_espresso'), true, '', 'Country'),
153
+				'ATT_zip'=>new EE_Plain_Text_Field('ATT_zip', __('ZIP/Postal Code', 'event_espresso'), true, ''),
154
+				'ATT_email'=>new EE_Email_Field('ATT_email', __('Email Address', 'event_espresso'), true, ''),
155
+				'ATT_phone'=>new EE_Plain_Text_Field('ATT_phone', __('Phone', 'event_espresso'), true, '')
156 156
 			));
157 157
 		$this->_model_relations = array(
158 158
 			'Registration'=>new EE_Has_Many_Relation(),
159 159
 			'State'=>new EE_Belongs_To_Relation(),
160 160
 			'Country'=>new EE_Belongs_To_Relation(),
161
-			'Event'=>new EE_HABTM_Relation('Registration', FALSE ),
161
+			'Event'=>new EE_HABTM_Relation('Registration', FALSE),
162 162
 			'WP_User' => new EE_Belongs_To_Relation(),
163 163
 		);
164 164
 		require_once('strategies/EE_CPT_Where_Conditions.strategy.php');
165 165
 		$this->_default_where_conditions_strategy = new EE_CPT_Where_Conditions('espresso_attendees', 'ATTM_ID');
166 166
 		$this->_caps_slug = 'contacts';
167
-		parent::__construct( $timezone );
167
+		parent::__construct($timezone);
168 168
 
169 169
 	}
170 170
 
@@ -174,8 +174,8 @@  discard block
 block discarded – undo
174 174
 	 * @param string $system_question_string
175 175
 	 * @return string|null if not found
176 176
 	 */
177
-	public function get_attendee_field_for_system_question( $system_question_string ) {
178
-		return isset( $this->_system_question_to_attendee_field_name[ $system_question_string ] ) ? $this->_system_question_to_attendee_field_name[ $system_question_string ] : null;
177
+	public function get_attendee_field_for_system_question($system_question_string) {
178
+		return isset($this->_system_question_to_attendee_field_name[$system_question_string]) ? $this->_system_question_to_attendee_field_name[$system_question_string] : null;
179 179
 	}
180 180
 
181 181
 
@@ -186,8 +186,8 @@  discard block
 block discarded – undo
186 186
 	 * @param EE_Transaction/int $transaction_id_or_obj EE_Transaction or its ID
187 187
 	 * @return EE_Attendee[]
188 188
 	 */
189
-	public function get_attendees_for_transaction( $transaction_id_or_obj ){
190
-		return $this->get_all( array( array(
189
+	public function get_attendees_for_transaction($transaction_id_or_obj) {
190
+		return $this->get_all(array(array(
191 191
 			  'Registration.Transaction.TXN_ID' => $transaction_id_or_obj instanceof EE_Transaction ? $transaction_id_or_obj->ID() : $transaction_id_or_obj
192 192
 		  )));
193 193
 	}
@@ -202,9 +202,9 @@  discard block
 block discarded – undo
202 202
 	*		@return 		mixed		array on success, FALSE on fail
203 203
 	 * 		@deprecated
204 204
 	*/
205
-	public function get_attendee_by_ID( $ATT_ID = FALSE ) {
205
+	public function get_attendee_by_ID($ATT_ID = FALSE) {
206 206
 		// retrieve a particular EE_Attendee
207
-		return $this->get_one_by_ID( $ATT_ID );
207
+		return $this->get_one_by_ID($ATT_ID);
208 208
 	}
209 209
 
210 210
 
@@ -217,14 +217,14 @@  discard block
 block discarded – undo
217 217
 	* 		@param		array $where_cols_n_values
218 218
 	*		@return 		mixed		array on success, FALSE on fail
219 219
 	*/
220
-	public function get_attendee( $where_cols_n_values = array() ) {
220
+	public function get_attendee($where_cols_n_values = array()) {
221 221
 
222
-		if ( empty( $where_cols_n_values )) {
222
+		if (empty($where_cols_n_values)) {
223 223
 			return FALSE;
224 224
 		}
225
-		$attendee = $this->get_all( array($where_cols_n_values ));
226
-		if ( ! empty( $attendee )) {
227
-			return array_shift( $attendee );
225
+		$attendee = $this->get_all(array($where_cols_n_values));
226
+		if ( ! empty($attendee)) {
227
+			return array_shift($attendee);
228 228
 		} else {
229 229
 			return FALSE;
230 230
 		}
@@ -240,20 +240,20 @@  discard block
 block discarded – undo
240 240
 	 * @param array $where_cols_n_values
241 241
 	 * @return bool|mixed
242 242
 	 */
243
-	public function find_existing_attendee( $where_cols_n_values = NULL ) {
243
+	public function find_existing_attendee($where_cols_n_values = NULL) {
244 244
 		// search by combo of first and last names plus the email address
245
-		$attendee_data_keys = array( 'ATT_fname' => $this->_ATT_fname, 'ATT_lname' => $this->_ATT_lname, 'ATT_email' => $this->_ATT_email );
245
+		$attendee_data_keys = array('ATT_fname' => $this->_ATT_fname, 'ATT_lname' => $this->_ATT_lname, 'ATT_email' => $this->_ATT_email);
246 246
 		// no search params means attendee object already exists.
247
-		$where_cols_n_values = is_array( $where_cols_n_values ) && ! empty( $where_cols_n_values ) ? $where_cols_n_values : $attendee_data_keys;
247
+		$where_cols_n_values = is_array($where_cols_n_values) && ! empty($where_cols_n_values) ? $where_cols_n_values : $attendee_data_keys;
248 248
 		$valid_data = TRUE;
249 249
 		// check for required values
250
-		$valid_data = isset( $where_cols_n_values['ATT_fname'] ) && ! empty( $where_cols_n_values['ATT_fname'] ) ? $valid_data : FALSE;
251
-		$valid_data = isset( $where_cols_n_values['ATT_lname'] ) && ! empty( $where_cols_n_values['ATT_lname'] ) ? $valid_data : FALSE;
252
-		$valid_data = isset( $where_cols_n_values['ATT_email'] ) && ! empty( $where_cols_n_values['ATT_email'] ) ? $valid_data : FALSE;
250
+		$valid_data = isset($where_cols_n_values['ATT_fname']) && ! empty($where_cols_n_values['ATT_fname']) ? $valid_data : FALSE;
251
+		$valid_data = isset($where_cols_n_values['ATT_lname']) && ! empty($where_cols_n_values['ATT_lname']) ? $valid_data : FALSE;
252
+		$valid_data = isset($where_cols_n_values['ATT_email']) && ! empty($where_cols_n_values['ATT_email']) ? $valid_data : FALSE;
253 253
 
254
-		if ( $valid_data ) {
255
-			$attendee = $this->get_attendee( $where_cols_n_values );
256
-			if ( $attendee instanceof EE_Attendee ) {
254
+		if ($valid_data) {
255
+			$attendee = $this->get_attendee($where_cols_n_values);
256
+			if ($attendee instanceof EE_Attendee) {
257 257
 				return $attendee;
258 258
 			}
259 259
 		}
@@ -271,12 +271,12 @@  discard block
 block discarded – undo
271 271
              * @param  array $ids array of EE_Registration ids
272 272
              * @return  EE_Attendee[]
273 273
              */
274
-            public function get_array_of_contacts_from_reg_ids( $ids ) {
274
+            public function get_array_of_contacts_from_reg_ids($ids) {
275 275
                 $ids = (array) $ids;
276 276
                 $_where = array(
277
-                    'Registration.REG_ID' => array( 'in', $ids )
277
+                    'Registration.REG_ID' => array('in', $ids)
278 278
                     );
279
-                return $this->get_all( array( $_where ) );
279
+                return $this->get_all(array($_where));
280 280
             }
281 281
 
282 282
 
Please login to merge, or discard this patch.
core/db_models/EEM_Base.model.php 4 patches
Indentation   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -555,10 +555,10 @@
 block discarded – undo
555 555
 	 	$stati = EEM_Status::instance()->get_all(array(array('STS_type' => $status_type) ) );
556 556
 	 	$status_array = array();
557 557
 	 	foreach ( $stati as $status ) {
558
-            $status_array[ $status->ID() ] = $status->get('STS_code');
559
-        }
560
-        return $translated ? EEM_Status::instance()->localized_status($status_array, FALSE, 'sentence') : $status_array;
561
-    }
558
+			$status_array[ $status->ID() ] = $status->get('STS_code');
559
+		}
560
+		return $translated ? EEM_Status::instance()->localized_status($status_array, FALSE, 'sentence') : $status_array;
561
+	}
562 562
 
563 563
 
564 564
 
Please login to merge, or discard this patch.
Braces   +129 added lines, -119 removed lines patch added patch discarded remove patch
@@ -497,7 +497,7 @@  discard block
 block discarded – undo
497 497
 		if( isset( $this->_cap_restriction_generators[ $context ] ) &&
498 498
 				$this->_cap_restriction_generators[ $context ] instanceof EE_Restriction_Generator_Base ) {
499 499
 			return $this->_cap_restriction_generators[ $context ]->generate_restrictions();
500
-		}else{
500
+		} else{
501 501
 			return array();
502 502
 		}
503 503
 }
@@ -548,8 +548,9 @@  discard block
 block discarded – undo
548 548
 	 * @return array
549 549
 	 */
550 550
 	 public function status_array( $translated = FALSE ) {
551
-	 	if ( !array_key_exists('Status', $this->_model_relations ) )
552
-	 		return array();
551
+	 	if ( !array_key_exists('Status', $this->_model_relations ) ) {
552
+	 		 		return array();
553
+	 	}
553 554
 	 	$model_name = $this->get_this_model_name();
554 555
 	 	$status_type = str_replace(' ', '_', strtolower( str_replace('_', ' ', $model_name) ) );
555 556
 	 	$stati = EEM_Status::instance()->get_all(array(array('STS_type' => $status_type) ) );
@@ -728,13 +729,13 @@  discard block
 block discarded – undo
728 729
 				$last_model_name = end( $models_to_follow_to_wp_users );
729 730
 				$model_with_fk_to_wp_users = EE_Registry::instance()->load_model( $last_model_name );
730 731
 				$model_chain_to_wp_user = $this->_model_chain_to_wp_user . '.';
731
-			}else{
732
+			} else{
732 733
 				$model_with_fk_to_wp_users = $this;
733 734
 				$model_chain_to_wp_user = '';
734 735
 			}
735 736
 			$wp_user_field = $model_with_fk_to_wp_users->get_foreign_key_to( 'WP_User' );
736 737
 			return $model_chain_to_wp_user . $wp_user_field->get_name();
737
-		}catch( EE_Error $e ) {
738
+		} catch( EE_Error $e ) {
738 739
 			return false;
739 740
 		}
740 741
 	}
@@ -762,11 +763,11 @@  discard block
 block discarded – undo
762 763
 	public function is_owned() {
763 764
 		if( $this->model_chain_to_wp_user() ){
764 765
 			return true;
765
-		}else{
766
+		} else{
766 767
 			try{
767 768
 				$this->get_foreign_key_to( 'WP_User' );
768 769
 				return true;
769
-			}catch( EE_Error $e ){
770
+			} catch( EE_Error $e ){
770 771
 				return false;
771 772
 			}
772 773
 		}
@@ -789,9 +790,9 @@  discard block
 block discarded – undo
789 790
 		//remember the custom selections, if any
790 791
 		if(is_array($columns_to_select)){
791 792
 			$this->_custom_selections = $columns_to_select;
792
-		}elseif(is_string($columns_to_select)){
793
+		} elseif(is_string($columns_to_select)){
793 794
 			$this->_custom_selections = array($this->_custom_selections);
794
-		}else{
795
+		} else{
795 796
 			$this->_custom_selections = array();
796 797
 		}
797 798
 
@@ -842,7 +843,7 @@  discard block
 block discarded – undo
842 843
 				$select_sql_array[] = "{$selection_and_datatype[0]} AS $alias";
843 844
 			}
844 845
 			$columns_to_select_string = implode(", ",$select_sql_array);
845
-		}else{
846
+		} else{
846 847
 			$columns_to_select_string = $columns_to_select;
847 848
 		}
848 849
 		return $columns_to_select_string;
@@ -870,10 +871,10 @@  discard block
 block discarded – undo
870 871
 	function get_one_by_ID($id){
871 872
 		if( $this->get_from_entity_map( $id ) ){
872 873
 			return $this->get_from_entity_map( $id );
873
-		}elseif( $this->has_primary_key_field ( ) ) {
874
+		} elseif( $this->has_primary_key_field ( ) ) {
874 875
 			$primary_key_name = $this->get_primary_key_field()->get_name();
875 876
 			return $this->get_one(array(array($primary_key_name => $id)));
876
-		}else{
877
+		} else{
877 878
 			//no primary key, so the $id must be from the get_index_primary_key_string()
878 879
 			return $this->get_one( array( $this->parse_index_primary_key_string( $id ) ) );
879 880
 		}
@@ -895,7 +896,7 @@  discard block
 block discarded – undo
895 896
 		$items = $this->get_all($query_params);
896 897
 		if(empty($items)){
897 898
 			return null;
898
-		}else{
899
+		} else{
899 900
 			return array_shift($items);
900 901
 		}
901 902
 	}
@@ -1290,7 +1291,7 @@  discard block
 block discarded – undo
1290 1291
 				//get the model object's PK, as we'll want this if we need to insert a row into secondary tables
1291 1292
 				if( $this->has_primary_key_field() ){
1292 1293
 					$main_table_pk_value = $wpdb_result[ $this->get_primary_key_field()->get_qualified_column() ];
1293
-				}else{
1294
+				} else{
1294 1295
 					//if there's no primary key, we basically can't support having a 2nd table on the model (we could but it woudl be lots of work)
1295 1296
 					$main_table_pk_value = null;
1296 1297
 				}
@@ -1329,7 +1330,7 @@  discard block
 block discarded – undo
1329 1330
 		if( $keep_model_objs_in_sync && ! $this->_values_already_prepared_by_model_object ){
1330 1331
 			if( $this->has_primary_key_field() ){
1331 1332
 				$model_objs_affected_ids = $this->get_col( $query_params );
1332
-			}else{
1333
+			} else{
1333 1334
 				//we need to select a bunch of columns and then combine them into the the "index primary key string"s
1334 1335
 				$models_affected_key_columns = $this->_get_all_wpdb_results($query_params, ARRAY_A );
1335 1336
 				$model_objs_affected_ids = array();
@@ -1389,9 +1390,9 @@  discard block
 block discarded – undo
1389 1390
 
1390 1391
 		if( $field_to_select ){
1391 1392
 			$field = $this->field_settings_for( $field_to_select );
1392
-		}elseif( $this->has_primary_key_field ( ) ){
1393
+		} elseif( $this->has_primary_key_field ( ) ){
1393 1394
 			$field = $this->get_primary_key_field();
1394
-		}else{
1395
+		} else{
1395 1396
 			//no primary key, just grab the first column
1396 1397
 			$field = reset( $this->field_settings());
1397 1398
 		}
@@ -1415,7 +1416,7 @@  discard block
 block discarded – undo
1415 1416
 		$col = $this->get_col( $query_params, $field_to_select );
1416 1417
 		if( ! empty( $col ) ) {
1417 1418
 			return reset( $col );
1418
-		}else{
1419
+		} else{
1419 1420
 			return NULL;
1420 1421
 		}
1421 1422
 	}
@@ -1499,7 +1500,7 @@  discard block
 block discarded – undo
1499 1500
 
1500 1501
 			//		/echo "delete sql:$SQL";
1501 1502
 			$rows_deleted = $this->_do_wpdb_query( 'query', array( $SQL ) );
1502
-		}else{
1503
+		} else{
1503 1504
 			$rows_deleted = 0;
1504 1505
 		}
1505 1506
 
@@ -1541,7 +1542,7 @@  discard block
 block discarded – undo
1541 1542
 		//first, if $ignore_this_model_obj was supplied, get its model
1542 1543
 		if($ignore_this_model_obj && $ignore_this_model_obj instanceof EE_Base_Class){
1543 1544
 			$ignored_model = $ignore_this_model_obj->get_model();
1544
-		}else{
1545
+		} else{
1545 1546
 			$ignored_model = null;
1546 1547
 		}
1547 1548
 		//now check all the relations of $this_model_obj_or_id and see if there
@@ -1554,7 +1555,7 @@  discard block
 block discarded – undo
1554 1555
 				if($ignored_model && $relation_name == $ignored_model->get_this_model_name()){
1555 1556
 					$related_model_objects = $relation_obj->get_all_related($this_model_obj_or_id,array(
1556 1557
 					array($ignored_model->get_primary_key_field()->get_name() => array('!=',$ignore_this_model_obj->ID()))));
1557
-				}else{
1558
+				} else{
1558 1559
 					$related_model_objects = $relation_obj->get_all_related($this_model_obj_or_id);
1559 1560
 				}
1560 1561
 
@@ -1591,24 +1592,28 @@  discard block
 block discarded – undo
1591 1592
 				}
1592 1593
 
1593 1594
 				//primary table deletes
1594
-				if ( isset( $delete_object[$primary_table->get_fully_qualified_pk_column()] ) )
1595
-					$deletes[$primary_table->get_fully_qualified_pk_column()][] = $delete_object[$primary_table->get_fully_qualified_pk_column()];
1595
+				if ( isset( $delete_object[$primary_table->get_fully_qualified_pk_column()] ) ) {
1596
+									$deletes[$primary_table->get_fully_qualified_pk_column()][] = $delete_object[$primary_table->get_fully_qualified_pk_column()];
1597
+				}
1596 1598
 
1597 1599
 				//other tables
1598 1600
 				if ( !empty( $other_tables ) ) {
1599 1601
 					foreach ( $other_tables as $ot ) {
1600 1602
 
1601 1603
 						//first check if we've got the foreign key column here.
1602
-						if ( isset( $delete_object[$ot->get_fully_qualified_fk_column()] ) )
1603
-							$deletes[$ot->get_fully_qualified_pk_column()][] = $delete_object[$ot->get_fully_qualified_fk_column()];
1604
+						if ( isset( $delete_object[$ot->get_fully_qualified_fk_column()] ) ) {
1605
+													$deletes[$ot->get_fully_qualified_pk_column()][] = $delete_object[$ot->get_fully_qualified_fk_column()];
1606
+						}
1604 1607
 
1605 1608
 						//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
1606
-						if ( isset( $delete_object[$ot->get_fully_qualified_pk_column()] ) )
1607
-							$deletes[$ot->get_fully_qualified_pk_column()][] = $delete_object[$ot->get_fully_qualified_pk_column()];
1609
+						if ( isset( $delete_object[$ot->get_fully_qualified_pk_column()] ) ) {
1610
+													$deletes[$ot->get_fully_qualified_pk_column()][] = $delete_object[$ot->get_fully_qualified_pk_column()];
1611
+						}
1608 1612
 
1609 1613
 						//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!
1610
-						if ( isset( $delete_object[$ot->get_fully_qualified_pk_on_fk_table()]) )
1611
-							$deletes[$ot->get_fully_qualified_pk_column()][] = $delete_object[$ot->get_fully_qualified_pk_column()];
1614
+						if ( isset( $delete_object[$ot->get_fully_qualified_pk_on_fk_table()]) ) {
1615
+													$deletes[$ot->get_fully_qualified_pk_column()][] = $delete_object[$ot->get_fully_qualified_pk_column()];
1616
+						}
1612 1617
 					}
1613 1618
 				}
1614 1619
 			}
@@ -1621,7 +1626,7 @@  discard block
 block discarded – undo
1621 1626
 			}
1622 1627
 
1623 1628
 			return !empty($query) ? implode(' AND ', $query ) : '';
1624
-		}elseif(count($this->get_combined_primary_key_fields()) > 1){
1629
+		} elseif(count($this->get_combined_primary_key_fields()) > 1){
1625 1630
 			$ways_to_identify_a_row = array();
1626 1631
 			$fields = $this->get_combined_primary_key_fields();
1627 1632
 			//note: because there' sno primary key, that means nothing else  can be pointing to this model, right?
@@ -1633,7 +1638,7 @@  discard block
 block discarded – undo
1633 1638
 				$ways_to_identify_a_row[] = "(".implode(" AND ",$values_for_each_cpk_for_a_row).")";
1634 1639
 			}
1635 1640
 			return implode(" OR ",$ways_to_identify_a_row);
1636
-		}else{
1641
+		} else{
1637 1642
 			//so there's no primary key and no combined key...
1638 1643
 			//sorry, can't help you
1639 1644
 			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)));
@@ -1655,10 +1660,10 @@  discard block
 block discarded – undo
1655 1660
 		if($field_to_count){
1656 1661
 			$field_obj = $this->field_settings_for($field_to_count);
1657 1662
 			$column_to_count = $field_obj->get_qualified_column();
1658
-		}elseif($this->has_primary_key_field ()){
1663
+		} elseif($this->has_primary_key_field ()){
1659 1664
 			$pk_field_obj = $this->get_primary_key_field();
1660 1665
 			$column_to_count = $pk_field_obj->get_qualified_column();
1661
-		}else{//there's no primary key
1666
+		} else{//there's no primary key
1662 1667
 			$column_to_count = '*';
1663 1668
 		}
1664 1669
 
@@ -1680,7 +1685,7 @@  discard block
 block discarded – undo
1680 1685
 		if($field_to_sum){
1681 1686
 			$field_obj = $this->field_settings_for($field_to_sum);
1682 1687
 
1683
-		}else{
1688
+		} else{
1684 1689
 			$field_obj = $this->get_primary_key_field();
1685 1690
 		}
1686 1691
 		$column_to_count = $field_obj->get_qualified_column();
@@ -1689,7 +1694,7 @@  discard block
 block discarded – undo
1689 1694
 		$return_value = $this->_do_wpdb_query('get_var',array( $SQL ) );
1690 1695
 		if($field_obj->get_wpdb_data_type() == '%d' || $field_obj->get_wpdb_data_type() == '%s' ){
1691 1696
 			return (float)$return_value;
1692
-		}else{//must be %f
1697
+		} else{//must be %f
1693 1698
 			return (float)$return_value;
1694 1699
 		}
1695 1700
 	}
@@ -1729,10 +1734,10 @@  discard block
 block discarded – undo
1729 1734
 			$wpdb->show_errors( $old_show_errors_value );
1730 1735
 			if( ! empty( $wpdb->last_error ) ){
1731 1736
 				throw new EE_Error( sprintf( __( 'WPDB Error: "%s"', 'event_espresso' ), $wpdb->last_error ) );
1732
-			}elseif( $result === false ){
1737
+			} elseif( $result === false ){
1733 1738
 				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 ) ) );
1734 1739
 			}
1735
-		}elseif( $result === false ) {
1740
+		} elseif( $result === false ) {
1736 1741
 			EE_Error::add_error( sprintf( __( 'A database error has occurred. Turn on WP_DEBUG for more information.', 'event_espresso' )), __FILE__, __FUNCTION__, __LINE__);
1737 1742
 		}
1738 1743
 		return $result;
@@ -1946,7 +1951,7 @@  discard block
 block discarded – undo
1946 1951
 		$results = $this->get_all_related($id_or_obj,$other_model_name,$query_params);
1947 1952
 		if( $results ){
1948 1953
 			return array_shift($results);
1949
-		}else{
1954
+		} else{
1950 1955
 			return null;
1951 1956
 		}
1952 1957
 
@@ -2017,7 +2022,7 @@  discard block
 block discarded – undo
2017 2022
 			 */
2018 2023
 			do_action( 'AHEE__EEM_Base__insert__end', $this, $field_n_values, $new_id );
2019 2024
 			return $new_id;
2020
-		}else{
2025
+		} else{
2021 2026
 			return FALSE;
2022 2027
 		}
2023 2028
 	}
@@ -2058,9 +2063,9 @@  discard block
 block discarded – undo
2058 2063
 	public function get_one_conflicting($obj_or_fields_array, $include_primary_key = true ){
2059 2064
 		if($obj_or_fields_array instanceof EE_Base_Class){
2060 2065
 			$fields_n_values = $obj_or_fields_array->model_field_array();
2061
-		}elseif( is_array($obj_or_fields_array)){
2066
+		} elseif( is_array($obj_or_fields_array)){
2062 2067
 			$fields_n_values = $obj_or_fields_array;
2063
-		}else{
2068
+		} else{
2064 2069
 			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));
2065 2070
 		}
2066 2071
 		$query_params = array();
@@ -2076,7 +2081,7 @@  discard block
 block discarded – undo
2076 2081
 		//if there is nothing to base this search on, then we shouldn't find anything
2077 2082
 		if( empty( $query_params ) ){
2078 2083
 			return array();
2079
-		}else{
2084
+		} else{
2080 2085
 			return $this->get_one($query_params);
2081 2086
 		}
2082 2087
 	}
@@ -2149,12 +2154,12 @@  discard block
 block discarded – undo
2149 2154
 		if($this->has_primary_key_field()){
2150 2155
 			if($this->get_primary_key_field()->is_auto_increment()){
2151 2156
 				return $wpdb->insert_id;
2152
-			}else{
2157
+			} else{
2153 2158
 				//it's not an auto-increment primary key, so
2154 2159
 				//it must have been supplied
2155 2160
 				return $fields_n_values[$this->get_primary_key_field()->get_name()];
2156 2161
 			}
2157
-		}else{
2162
+		} else{
2158 2163
 			//we can't return a  primary key because there is none. instead return
2159 2164
 			//a unique string indicating this model
2160 2165
 			return $this->get_index_primary_key_string($fields_n_values);
@@ -2202,7 +2207,7 @@  discard block
 block discarded – undo
2202 2207
 					//leave the value alone
2203 2208
 			}
2204 2209
 			return $value;
2205
-		}else{
2210
+		} else{
2206 2211
 			return $value;
2207 2212
 		}
2208 2213
 	}
@@ -2295,7 +2300,7 @@  discard block
 block discarded – undo
2295 2300
 		if(array_key_exists('group_by', $query_params)){
2296 2301
 			if(is_array($query_params['group_by'])){
2297 2302
 				$this->_extract_related_models_from_sub_params_array_values($query_params['group_by'],$query_info_carrier,'group_by');
2298
-			}elseif( ! empty ( $query_params['group_by'] )){
2303
+			} elseif( ! empty ( $query_params['group_by'] )){
2299 2304
 				$this->_extract_related_model_info_from_query_param( $query_params['group_by'],$query_info_carrier,'group_by');
2300 2305
 			}
2301 2306
 		}
@@ -2303,10 +2308,11 @@  discard block
 block discarded – undo
2303 2308
 			$this->_extract_related_models_from_sub_params_array_keys($query_params[0], $query_info_carrier,'having');
2304 2309
 		}
2305 2310
 		if(array_key_exists('order_by', $query_params)){
2306
-			if ( is_array( $query_params['order_by'] ) )
2307
-				$this->_extract_related_models_from_sub_params_array_keys($query_params['order_by'],$query_info_carrier,'order_by');
2308
-			elseif( ! empty( $query_params['order_by'] ))
2309
-				$this->_extract_related_model_info_from_query_param( $query_params['order_by'], $query_info_carrier,'order_by');
2311
+			if ( is_array( $query_params['order_by'] ) ) {
2312
+							$this->_extract_related_models_from_sub_params_array_keys($query_params['order_by'],$query_info_carrier,'order_by');
2313
+			} elseif( ! empty( $query_params['order_by'] )) {
2314
+							$this->_extract_related_model_info_from_query_param( $query_params['order_by'], $query_info_carrier,'order_by');
2315
+			}
2310 2316
 		}
2311 2317
 		if(array_key_exists('force_join', $query_params)){
2312 2318
 			$this->_extract_related_models_from_sub_params_array_values($query_params['force_join'],$query_info_carrier,'force_join');
@@ -2338,10 +2344,10 @@  discard block
 block discarded – undo
2338 2344
 					if (! is_array($possibly_array_of_params)){
2339 2345
 						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"),
2340 2346
 							$param,$possibly_array_of_params));
2341
-					}else{
2347
+					} else{
2342 2348
 						$this->_extract_related_models_from_sub_params_array_keys($possibly_array_of_params, $model_query_info_carrier,$query_param_type);
2343 2349
 					}
2344
-				}elseif($query_param_type === 0 //ie WHERE
2350
+				} elseif($query_param_type === 0 //ie WHERE
2345 2351
 						&& is_array($possibly_array_of_params)
2346 2352
 						&& isset($possibly_array_of_params[2])
2347 2353
 						&& $possibly_array_of_params[2] == true){
@@ -2401,7 +2407,7 @@  discard block
 block discarded – undo
2401 2407
 		}
2402 2408
 		if( isset( $query_params[0] ) ) {
2403 2409
 			$where_query_params = $query_params[0];
2404
-		}else{
2410
+		} else{
2405 2411
 			$where_query_params = array();
2406 2412
 		}
2407 2413
 		//first check if we should alter the query to account for caps or not
@@ -2419,7 +2425,7 @@  discard block
 block discarded – undo
2419 2425
 		}
2420 2426
 		if( array_key_exists( 'default_where_conditions',$query_params) && ! empty( $query_params['default_where_conditions'] )){
2421 2427
 			$use_default_where_conditions = $query_params['default_where_conditions'];
2422
-		}else{
2428
+		} else{
2423 2429
 			$use_default_where_conditions = 'all';
2424 2430
 		}
2425 2431
 		$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 );
@@ -2442,7 +2448,7 @@  discard block
 block discarded – undo
2442 2448
 				}
2443 2449
 				//they passed us an array for the limit. Assume it's like array(50,25), meaning offset by 50, and get 25
2444 2450
 				$query_object->set_limit_sql(" LIMIT ".$query_params['limit'][0].",".$query_params['limit'][1]);
2445
-			}elseif( ! empty ( $query_params['limit'] )){
2451
+			} elseif( ! empty ( $query_params['limit'] )){
2446 2452
 				$query_object->set_limit_sql((" LIMIT ".$query_params['limit']));
2447 2453
 			}
2448 2454
 		}
@@ -2464,11 +2470,11 @@  discard block
 block discarded – undo
2464 2470
 					$order_array[] = $this->_deduce_column_name_from_query_param($field_name_to_order_by).SP.$order;
2465 2471
 				}
2466 2472
 				$query_object->set_order_by_sql(" ORDER BY ".implode(",",$order_array));
2467
-			}elseif( ! empty ( $query_params['order_by'] )){
2473
+			} elseif( ! empty ( $query_params['order_by'] )){
2468 2474
 				$this->_extract_related_model_info_from_query_param($query_params['order_by'],$query_object,'order',$query_params['order_by']);
2469 2475
 				if(isset($query_params['order'])){
2470 2476
 					$order = $this->_extract_order($query_params['order']);
2471
-				}else{
2477
+				} else{
2472 2478
 					$order = 'DESC';
2473 2479
 				}
2474 2480
 				$query_object->set_order_by_sql(" ORDER BY ".$this->_deduce_column_name_from_query_param($query_params['order_by']).SP.$order);
@@ -2491,7 +2497,7 @@  discard block
 block discarded – undo
2491 2497
 					$group_by_array[] = $this->_deduce_column_name_from_query_param($field_name_to_group_by);
2492 2498
 				}
2493 2499
 				$query_object->set_group_by_sql(" GROUP BY ".implode(", ",$group_by_array));
2494
-			}elseif( ! empty ( $query_params['group_by'] )){
2500
+			} elseif( ! empty ( $query_params['group_by'] )){
2495 2501
 				$query_object->set_group_by_sql(" GROUP BY ".$this->_deduce_column_name_from_query_param($query_params['group_by']));
2496 2502
 			}
2497 2503
 		}
@@ -2515,8 +2521,9 @@  discard block
 block discarded – undo
2515 2521
 			}
2516 2522
 		}
2517 2523
 		$main_model_join_sql = $query_object->get_main_model_join_sql();
2518
-		if ( empty( $main_model_join_sql ) )
2519
-			$query_object->set_main_model_join_sql($this->_construct_internal_join());
2524
+		if ( empty( $main_model_join_sql ) ) {
2525
+					$query_object->set_main_model_join_sql($this->_construct_internal_join());
2526
+		}
2520 2527
 		return $query_object;
2521 2528
 	}
2522 2529
 
@@ -2549,7 +2556,7 @@  discard block
 block discarded – undo
2549 2556
 	private function _extract_order($should_be_order_string){
2550 2557
 		if(in_array($should_be_order_string, $this->_allowed_order_values)){
2551 2558
 			return $should_be_order_string;
2552
-		}else{
2559
+		} else{
2553 2560
 			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));
2554 2561
 		}
2555 2562
 	}
@@ -2575,7 +2582,7 @@  discard block
 block discarded – undo
2575 2582
 		}
2576 2583
 		if( in_array($use_default_where_conditions, array('all','this_model_only')) ){
2577 2584
 			$universal_query_params = $this->_get_default_where_conditions();
2578
-		}else{
2585
+		} else{
2579 2586
 			$universal_query_params = array();
2580 2587
 		}
2581 2588
 
@@ -2615,14 +2622,14 @@  discard block
 block discarded – undo
2615 2622
 		foreach($default_where_conditions as $key => $val){
2616 2623
 			if( isset($provided_where_conditions[$key])){
2617 2624
 				$none_overridden = false;
2618
-			}else{
2625
+			} else{
2619 2626
 				$null_friendly_where_conditions[$or_condition_key_for_defaults]['AND'][$key] = $val;
2620 2627
 			}
2621 2628
 		}
2622 2629
 		if( $none_overridden && $default_where_conditions){
2623 2630
 			if($model->has_primary_key_field()){
2624 2631
 				$null_friendly_where_conditions[$or_condition_key_for_defaults][$model_relation_path.".".$model->primary_key_name()] = array('IS NULL');
2625
-			}else{
2632
+			} else{
2626 2633
 				//@todo NO PK, use other defaults
2627 2634
 			}
2628 2635
 		}
@@ -2638,8 +2645,9 @@  discard block
 block discarded – undo
2638 2645
 	 * @return array like EEM_Base::get_all's $query_params[0] (where conditions)
2639 2646
 	 */
2640 2647
 	private function _get_default_where_conditions($model_relation_path = null){
2641
-		if ( $this->_ignore_where_strategy )
2642
-			return array();
2648
+		if ( $this->_ignore_where_strategy ) {
2649
+					return array();
2650
+		}
2643 2651
 
2644 2652
 		return $this->_default_where_conditions_strategy->get_default_where_conditions($model_relation_path);
2645 2653
 	}
@@ -2713,7 +2721,7 @@  discard block
 block discarded – undo
2713 2721
 		if(array_key_exists($query_param,$this_model_fields)){
2714 2722
 			if($allow_fields){
2715 2723
 				return;
2716
-			}else{
2724
+			} else{
2717 2725
 				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"),
2718 2726
 						$query_param,get_class($this),$query_param_type,$original_query_param));
2719 2727
 			}
@@ -2722,7 +2730,7 @@  discard block
 block discarded – undo
2722 2730
 		elseif(in_array($query_param, $this->_logic_query_param_keys, TRUE)){
2723 2731
 			if($allow_logic_query_params){
2724 2732
 				return;
2725
-			}else{
2733
+			} else{
2726 2734
 				throw new EE_Error(
2727 2735
 					sprintf(
2728 2736
 						__( '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' ),
@@ -2753,12 +2761,12 @@  discard block
 block discarded – undo
2753 2761
 					//we should actually end in a field name, not a model like this!
2754 2762
 					throw new EE_Error(sprintf(__("Query param '%s' (of type %s on model %s) shouldn't end on a period (.) ", "event_espresso"),
2755 2763
 					$query_param,$query_param_type,get_class($this),$valid_related_model_name));
2756
-				}else{
2764
+				} else{
2757 2765
 					$related_model_obj = $this->get_related_model_obj($valid_related_model_name);
2758 2766
 					$related_model_obj->_extract_related_model_info_from_query_param($query_param, $passed_in_query_info, $query_param_type, $original_query_param);
2759 2767
 					return;
2760 2768
 				}
2761
-			}elseif($query_param == $valid_related_model_name){
2769
+			} elseif($query_param == $valid_related_model_name){
2762 2770
 				$this->_add_join_to_model($valid_related_model_name, $passed_in_query_info,$original_query_param);
2763 2771
 				return;
2764 2772
 			}
@@ -2818,7 +2826,7 @@  discard block
 block discarded – undo
2818 2826
 		$SQL = $this->_construct_condition_clause_recursive($where_params, ' AND ');
2819 2827
 		if($SQL){
2820 2828
 			return " WHERE ". $SQL;
2821
-		}else{
2829
+		} else{
2822 2830
 			return '';
2823 2831
 		}
2824 2832
 	}
@@ -2833,7 +2841,7 @@  discard block
 block discarded – undo
2833 2841
 		$SQL = $this->_construct_condition_clause_recursive($having_params, ' AND ');
2834 2842
 		if($SQL){
2835 2843
 			return " HAVING ". $SQL;
2836
-		}else{
2844
+		} else{
2837 2845
 			return '';
2838 2846
 		}
2839 2847
 
@@ -2856,7 +2864,7 @@  discard block
 block discarded – undo
2856 2864
 			$model_instance=call_user_func($model_name."::instance");
2857 2865
 			/* @var $model_instance EEM_Base */
2858 2866
 			return $model_instance->field_settings_for($field_name);
2859
-		}else{
2867
+		} else{
2860 2868
 			throw new EE_Error(sprintf(__('No model named %s exists, with classname %s and filepath %s','event_espresso'),$model_name,$model_class,$model_filepath));
2861 2869
 		}
2862 2870
 	}
@@ -2889,14 +2897,14 @@  discard block
 block discarded – undo
2889 2897
 						$where_clauses[] = " (". $this->_construct_condition_clause_recursive($op_and_value_or_sub_condition, ' OR ') .")";
2890 2898
 						break;
2891 2899
 				}
2892
-			}else{
2900
+			} else{
2893 2901
 				$field_obj = $this->_deduce_field_from_query_param($query_param);
2894 2902
 
2895 2903
 				//if it's not a normal field, maybe it's a custom selection?
2896 2904
 				if( ! $field_obj){
2897 2905
 					if(isset( $this->_custom_selections[$query_param][1])){
2898 2906
 						$field_obj = $this->_custom_selections[$query_param][1];
2899
-					}else{
2907
+					} else{
2900 2908
 						throw new EE_Error(sprintf(__("%s is neither a valid model field name, nor a custom selection", "event_espresso"),$query_param));
2901 2909
 					}
2902 2910
 				}
@@ -2906,7 +2914,7 @@  discard block
 block discarded – undo
2906 2914
 		}
2907 2915
 		if($where_clauses){
2908 2916
 			$SQL = implode($glue,$where_clauses);
2909
-		}else{
2917
+		} else{
2910 2918
 			$SQL = '';
2911 2919
 		}
2912 2920
 		return $SQL;
@@ -2926,11 +2934,11 @@  discard block
 block discarded – undo
2926 2934
 		if( $field ){
2927 2935
 			$table_alias_prefix = EE_Model_Parser::extract_table_alias_model_relation_chain_from_query_param( $field->get_model_name(), $query_param );
2928 2936
 			return $table_alias_prefix . $field->get_qualified_column();
2929
-		}elseif(array_key_exists($query_param,$this->_custom_selections)){
2937
+		} elseif(array_key_exists($query_param,$this->_custom_selections)){
2930 2938
 			//maybe it's custom selection item?
2931 2939
 			//if so, just use it as the "column name"
2932 2940
 			return $query_param;
2933
-		}else{
2941
+		} else{
2934 2942
 			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)));
2935 2943
 		}
2936 2944
 	}
@@ -2947,7 +2955,7 @@  discard block
 block discarded – undo
2947 2955
 		$pos_of_star = strpos($condition_query_param_key, '*');
2948 2956
 		if($pos_of_star === FALSE){
2949 2957
 			return $condition_query_param_key;
2950
-		}else{
2958
+		} else{
2951 2959
 			$condition_query_param_sans_star = substr($condition_query_param_key, 0, $pos_of_star);
2952 2960
 			return $condition_query_param_sans_star;
2953 2961
 		}
@@ -2973,7 +2981,7 @@  discard block
 block discarded – undo
2973 2981
 				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)));
2974 2982
 			}
2975 2983
 			$value = isset($op_and_value[1]) ? $op_and_value[1] : null;
2976
-		}else{
2984
+		} else{
2977 2985
 			$operator = '=';
2978 2986
 			$value = $op_and_value;
2979 2987
 		}
@@ -2981,7 +2989,7 @@  discard block
 block discarded – undo
2981 2989
 		//check to see if the value is actually another field
2982 2990
 		if(is_array($op_and_value) && isset($op_and_value[2]) && $op_and_value[2] == true){
2983 2991
 			return $operator.SP.$this->_deduce_column_name_from_query_param($value);
2984
-		}elseif(in_array($operator, $this->_in_style_operators) && is_array($value)){
2992
+		} elseif(in_array($operator, $this->_in_style_operators) && is_array($value)){
2985 2993
 			//in this case, the value should be an array, or at least a comma-separated list
2986 2994
 			//it will need to handle a little differently
2987 2995
 			$cleaned_value = $this->_construct_in_value($value, $field_obj);
@@ -2989,8 +2997,9 @@  discard block
 block discarded – undo
2989 2997
 			return $operator.SP.$cleaned_value;
2990 2998
 		} elseif( in_array( $operator, $this->_between_style_operators ) && is_array( $value ) ) {
2991 2999
 			//the value should be an array with count of two.
2992
-			if ( count($value) !== 2 )
2993
-				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" ) );
3000
+			if ( count($value) !== 2 ) {
3001
+							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" ) );
3002
+			}
2994 3003
 			$cleaned_value = $this->_construct_between_value( $value, $field_obj );
2995 3004
 			return $operator.SP.$cleaned_value;
2996 3005
 		} elseif( in_array( $operator, $this->_null_style_operators ) ) {
@@ -2998,17 +3007,17 @@  discard block
 block discarded – undo
2998 3007
 				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));
2999 3008
 			}
3000 3009
 			return $operator;
3001
-		}elseif( $operator == 'LIKE' && ! is_array($value)){
3010
+		} elseif( $operator == 'LIKE' && ! is_array($value)){
3002 3011
 			//if the operator is 'LIKE', we want to allow percent signs (%) and not
3003 3012
 			//remove other junk. So just treat it as a string.
3004 3013
 			return $operator.SP.$this->_wpdb_prepare_using_field($value, '%s');
3005
-		}elseif( ! in_array($operator, $this->_in_style_operators) && ! is_array($value)){
3014
+		} elseif( ! in_array($operator, $this->_in_style_operators) && ! is_array($value)){
3006 3015
 			return $operator.SP.$this->_wpdb_prepare_using_field($value,$field_obj);
3007
-		}elseif(in_array($operator, $this->_in_style_operators) && ! is_array($value)){
3016
+		} elseif(in_array($operator, $this->_in_style_operators) && ! is_array($value)){
3008 3017
 			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));
3009
-		}elseif( ! in_array($operator, $this->_in_style_operators) && is_array($value)){
3018
+		} elseif( ! in_array($operator, $this->_in_style_operators) && is_array($value)){
3010 3019
 			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));
3011
-		}else{
3020
+		} else{
3012 3021
 			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)));
3013 3022
 		}
3014 3023
 	}
@@ -3078,7 +3087,7 @@  discard block
 block discarded – undo
3078 3087
 		global $wpdb;
3079 3088
 		if($field_obj instanceof EE_Model_Field_Base){
3080 3089
 			return $wpdb->prepare($field_obj->get_wpdb_data_type(),$this->_prepare_value_for_use_in_db($value, $field_obj));
3081
-		}else{//$field_obj should really just be a data type
3090
+		} else{//$field_obj should really just be a data type
3082 3091
 			if( ! in_array($field_obj,$this->_valid_wpdb_data_types)){
3083 3092
 				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)));
3084 3093
 			}
@@ -3107,14 +3116,14 @@  discard block
 block discarded – undo
3107 3116
 		if($number_of_parts == 1){
3108 3117
 			$field_name = $last_query_param_part;
3109 3118
 			$model_obj = $this;
3110
-		}else{// $number_of_parts >= 2
3119
+		} else{// $number_of_parts >= 2
3111 3120
 			//the last part is the column name, and there are only 2parts. therefore...
3112 3121
 			$field_name = $last_query_param_part;
3113 3122
 			$model_obj = $this->get_related_model_obj( $query_param_parts[ $number_of_parts - 2 ]);
3114 3123
 		}
3115 3124
 		try{
3116 3125
 			return $model_obj->field_settings_for($field_name);
3117
-		}catch(EE_Error $e){
3126
+		} catch(EE_Error $e){
3118 3127
 			return null;
3119 3128
 		}
3120 3129
 	}
@@ -3133,7 +3142,7 @@  discard block
 block discarded – undo
3133 3142
 		$field = isset($all_fields[$field_name]) ? $all_fields[$field_name] : FALSE;
3134 3143
 		if($field){
3135 3144
 			return $field->get_qualified_column();
3136
-		}else{
3145
+		} else{
3137 3146
 			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)));
3138 3147
 		}
3139 3148
 	}
@@ -3199,7 +3208,7 @@  discard block
 block discarded – undo
3199 3208
 					//the FROM statement, BUT the primary table isn't. So we want
3200 3209
 					//to add the inverse join sql
3201 3210
 					$SQL .= $table_obj->get_inverse_join_sql($alias_prefixed);
3202
-				}else{
3211
+				} else{
3203 3212
 					//just add a regular JOIN to this table from the primary table
3204 3213
 					$SQL .= $table_obj->get_join_sql($alias_prefixed);
3205 3214
 				}
@@ -3314,7 +3323,7 @@  discard block
 block discarded – undo
3314 3323
 		$fieldSettings = $this->field_settings(true);
3315 3324
 		if( isset($fieldSettings[$fieldName])){
3316 3325
 			return true;
3317
-		}else{
3326
+		} else{
3318 3327
 			return false;
3319 3328
 		}
3320 3329
 	}
@@ -3328,7 +3337,7 @@  discard block
 block discarded – undo
3328 3337
 		$relations = $this->relation_settings();
3329 3338
 		if(isset($relations[$relation_name])){
3330 3339
 			return true;
3331
-		}else{
3340
+		} else{
3332 3341
 			return false;
3333 3342
 		}
3334 3343
 	}
@@ -3379,7 +3388,7 @@  discard block
 block discarded – undo
3379 3388
 			try{
3380 3389
 				$this->get_primary_key_field();
3381 3390
 				$this->_has_primary_key_field = true;
3382
-			}catch(EE_Error $e){
3391
+			} catch(EE_Error $e){
3383 3392
 				$this->_has_primary_key_field = false;
3384 3393
 			}
3385 3394
 		}
@@ -3458,7 +3467,7 @@  discard block
 block discarded – undo
3458 3467
 				}
3459 3468
 			}
3460 3469
 			return $this->_cached_fields;
3461
-		}else{
3470
+		} else{
3462 3471
 			if( $this->_cached_fields_non_db_only === NULL ){
3463 3472
 				$this->_cached_fields_non_db_only = array();
3464 3473
 				foreach($this->_fields as $fields_corresponding_to_table){
@@ -3574,7 +3583,7 @@  discard block
 block discarded – undo
3574 3583
 			if(empty( $this_model_fields_n_values[$this->primary_key_name()] )){
3575 3584
 				return NULL;
3576 3585
 			}
3577
-		}else if($this->unique_indexes()){
3586
+		} else if($this->unique_indexes()){
3578 3587
 			$first_column = reset($this_model_fields_n_values);
3579 3588
 			if(empty($first_column)){
3580 3589
 				return NULL;
@@ -3589,7 +3598,7 @@  discard block
 block discarded – undo
3589 3598
 				// add this new object to the entity map
3590 3599
 				$classInstance = $this->add_to_entity_map( $classInstance );
3591 3600
 			}
3592
-		}else{
3601
+		} else{
3593 3602
 			$classInstance = EE_Registry::instance()->load_class( $className, array( $this_model_fields_n_values, $this->_timezone ), TRUE, FALSE );
3594 3603
 		}
3595 3604
 
@@ -3676,11 +3685,12 @@  discard block
 block discarded – undo
3676 3685
 						$this_model_fields_n_values[$field_name] = $field_obj->prepare_for_use_in_db( $prepared_value );
3677 3686
 					}
3678 3687
 				}
3679
-			}else{
3688
+			} else{
3680 3689
 				//the table's rows existed. Use their values
3681 3690
 				foreach( $this->_get_fields_for_table( $table_alias ) as $field_name => $field_obj ) {
3682
-					if( ! $field_obj->is_db_only_field() )
3683
-					$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() );
3691
+					if( ! $field_obj->is_db_only_field() ) {
3692
+										$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() );
3693
+					}
3684 3694
 				}
3685 3695
 			}
3686 3696
 		}
@@ -3694,9 +3704,9 @@  discard block
 block discarded – undo
3694 3704
 		if( isset( $cols_n_values[ $qualified_column ] ) ){
3695 3705
 			$value = $cols_n_values[ $qualified_column ];
3696 3706
 
3697
-		}elseif( isset( $cols_n_values[ $regular_column ] ) ){
3707
+		} elseif( isset( $cols_n_values[ $regular_column ] ) ){
3698 3708
 			$value = $cols_n_values[ $regular_column ];
3699
-		}else{
3709
+		} else{
3700 3710
 			$value = NULL;
3701 3711
 		}
3702 3712
 
@@ -3729,7 +3739,7 @@  discard block
 block discarded – undo
3729 3739
 				}
3730 3740
 			}
3731 3741
 			return $obj_in_map;
3732
-		}else{
3742
+		} else{
3733 3743
 			return $this->get_one_by_ID( $id );
3734 3744
 		}
3735 3745
 	}
@@ -3764,7 +3774,7 @@  discard block
 block discarded – undo
3764 3774
 				}
3765 3775
 			}
3766 3776
 			return $obj_in_map;
3767
-		}else{
3777
+		} else{
3768 3778
 			$this->add_to_entity_map( $replacing_model_obj );
3769 3779
 			return $replacing_model_obj;
3770 3780
 		}
@@ -3794,7 +3804,7 @@  discard block
 block discarded – undo
3794 3804
 	public function item_name($quantity = 1){
3795 3805
 		if($quantity == 1){
3796 3806
 			return $this->singular_item;
3797
-		}else{
3807
+		} else{
3798 3808
 			return $this->plural_item;
3799 3809
 		}
3800 3810
 	}
@@ -3856,14 +3866,14 @@  discard block
 block discarded – undo
3856 3866
 		$primary_key_field = $this->get_primary_key_field();
3857 3867
 		if( $base_class_obj_or_id instanceof $className ){
3858 3868
 			$model_object = $base_class_obj_or_id;
3859
-		}elseif( $primary_key_field instanceof EE_Primary_Key_Int_Field && (
3869
+		} elseif( $primary_key_field instanceof EE_Primary_Key_Int_Field && (
3860 3870
 				is_int( $base_class_obj_or_id ) ||
3861 3871
 				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)
3862 3872
 			$model_object = $this->get_one_by_ID($base_class_obj_or_id);
3863
-		}elseif( $primary_key_field instanceof EE_Primary_Key_String_Field && is_string($base_class_obj_or_id) ){
3873
+		} elseif( $primary_key_field instanceof EE_Primary_Key_String_Field && is_string($base_class_obj_or_id) ){
3864 3874
 			//assume its a string representation of the object
3865 3875
 			$model_object = $this->get_one_by_ID($base_class_obj_or_id);
3866
-		}else{
3876
+		} else{
3867 3877
 			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)));
3868 3878
 		}
3869 3879
 		if( $model_object->ID() == NULL && $ensure_is_in_db){
@@ -3887,13 +3897,13 @@  discard block
 block discarded – undo
3887 3897
 		if( $base_class_obj_or_id instanceof $className ){
3888 3898
 			/** @var $base_class_obj_or_id EE_Base_Class */
3889 3899
 			$id = $base_class_obj_or_id->ID();
3890
-		}elseif(is_int($base_class_obj_or_id)){
3900
+		} elseif(is_int($base_class_obj_or_id)){
3891 3901
 			//assume it's an ID
3892 3902
 			$id = $base_class_obj_or_id;
3893
-		}elseif(is_string($base_class_obj_or_id)){
3903
+		} elseif(is_string($base_class_obj_or_id)){
3894 3904
 			//assume its a string representation of the object
3895 3905
 			$id = $base_class_obj_or_id;
3896
-		}else{
3906
+		} else{
3897 3907
 			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)));
3898 3908
 		}
3899 3909
 		return $id;
@@ -4024,9 +4034,9 @@  discard block
 block discarded – undo
4024 4034
 
4025 4035
 		if($model_object_or_attributes_array instanceof EE_Base_Class){
4026 4036
 			$attributes_array = $model_object_or_attributes_array->model_field_array();
4027
-		}elseif(is_array($model_object_or_attributes_array)){
4037
+		} elseif(is_array($model_object_or_attributes_array)){
4028 4038
 			$attributes_array = $model_object_or_attributes_array;
4029
-		}else{
4039
+		} else{
4030 4040
 			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));
4031 4041
 		}
4032 4042
 		//even copies obviously won't have the same ID, so remove the primary key
@@ -4036,7 +4046,7 @@  discard block
 block discarded – undo
4036 4046
 		}
4037 4047
 		if(isset($query_params[0])){
4038 4048
 			$query_params[0] = array_merge($attributes_array,$query_params);
4039
-		}else{
4049
+		} else{
4040 4050
 			$query_params[0] = $attributes_array;
4041 4051
 		}
4042 4052
 		return $this->get_all($query_params);
@@ -4059,7 +4069,7 @@  discard block
 block discarded – undo
4059 4069
 		$copies = $this->get_all_copies($model_object_or_attributes_array,$query_params);
4060 4070
 		if(is_array($copies)){
4061 4071
 			return array_shift($copies);
4062
-		}else{
4072
+		} else{
4063 4073
 			return null;
4064 4074
 		}
4065 4075
 	}
@@ -4091,7 +4101,7 @@  discard block
 block discarded – undo
4091 4101
 		$sql_operator = isset($this->_valid_operators[$operator_supplied]) ? $this->_valid_operators[$operator_supplied] : null;
4092 4102
 		if($sql_operator){
4093 4103
 			return $sql_operator;
4094
-		}else{
4104
+		} else{
4095 4105
 			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))));
4096 4106
 		}
4097 4107
 	}
@@ -4262,7 +4272,7 @@  discard block
 block discarded – undo
4262 4272
 		$valid_cap_contexts = EEM_Base::valid_cap_contexts();
4263 4273
 		if( in_array( $context, $valid_cap_contexts ) ) {
4264 4274
 			return true;
4265
-		}else{
4275
+		} else{
4266 4276
 			throw new EE_Error(
4267 4277
 				sprintf(
4268 4278
 					__( 'Context "%1$s" passed into model "%2$s" is not a valid context. They are: %3$s', 'event_espresso' ),
Please login to merge, or discard this patch.
Doc Comments   +18 added lines, -15 removed lines patch added patch discarded remove patch
@@ -741,7 +741,7 @@  discard block
 block discarded – undo
741 741
 	 * Returns the name of the field's name that points to the WP_User table
742 742
 	 *  on this model (or follows the _model_chain_to_wp_user and uses that model's
743 743
 	 * foreign key to the WP_User table)
744
-	 * @return string|boolean string on success, boolean false when there is no
744
+	 * @return string|false string on success, boolean false when there is no
745 745
 	 * foreign key to the WP_User table
746 746
 	 */
747 747
 	function wp_user_field_name() {
@@ -837,6 +837,7 @@  discard block
 block discarded – undo
837 837
 	 * If you would like to use these custom selections in WHERE, GROUP_BY, or HAVING clauses, you must instead provide an array.
838 838
 	 * Array keys are the aliases used to refer to this selection, and values are to be numerically-indexed arrays, where 0 is the selection
839 839
 	 * and 1 is the data type. Eg, array('count'=>array('COUNT(REG_ID)','%d'))
840
+	 * @param string $columns_to_select
840 841
 	 * @return stdClass[] like results of $wpdb->get_results($sql,OBJECT), (ie, output type is OBJECT)
841 842
 	 */
842 843
 	public function  get_all_wpdb_results($query_params = array(), $output = ARRAY_A, $columns_to_select = null){
@@ -1139,7 +1140,7 @@  discard block
 block discarded – undo
1139 1140
 	 * @param bool   $pretty          Whether to return the pretty formats (true) or not (false).
1140 1141
 	 * @throws EE_Error   If the given field_name is not of the EE_Datetime_Field type.
1141 1142
 	 *
1142
-	 * @return array formats in an array with the date format first, and the time format last.
1143
+	 * @return string[] formats in an array with the date format first, and the time format last.
1143 1144
 	 */
1144 1145
 	public function get_formats_for( $field_name, $pretty = false ) {
1145 1146
 		$field_settings = $this->field_settings_for( $field_name );
@@ -1174,7 +1175,7 @@  discard block
 block discarded – undo
1174 1175
 	 *
1175 1176
 	 * @throws EE_Error   	If the given field_name is not of the EE_Datetime_Field type.
1176 1177
 	 *
1177
-	 * @return int|string  If the given field_name is not of the EE_Datetime_Field type, then an EE_Error
1178
+	 * @return string|null  If the given field_name is not of the EE_Datetime_Field type, then an EE_Error
1178 1179
 	 *                    	     exception is triggered.
1179 1180
 	 */
1180 1181
 	public function current_time_for_query( $field_name, $timestamp = false, $what = 'both' ) {
@@ -1474,7 +1475,7 @@  discard block
 block discarded – undo
1474 1475
 	 * Deletes a single row from the DB given the model object's primary key value. (eg, EE_Attendee->ID()'s value).
1475 1476
 	 * Wrapper for EEM_Base::delete()
1476 1477
 	 * @param mixed $id
1477
-	 * @return boolean whether the row got deleted or not
1478
+	 * @return integer whether the row got deleted or not
1478 1479
 	 */
1479 1480
 	public function delete_by_ID( $id ){
1480 1481
 		return $this->delete( array(
@@ -1834,7 +1835,7 @@  discard block
 block discarded – undo
1834 1835
 	/**
1835 1836
 	 * Verifies the EE addons' database is up-to-date and records that we've done it on
1836 1837
 	 * EEM_Base::$_db_verification_level
1837
-	 * @param $wpdb_method
1838
+	 * @param string $wpdb_method
1838 1839
 	 * @param $arguments_to_provide
1839 1840
 	 * @return string
1840 1841
 	 */
@@ -1902,7 +1903,6 @@  discard block
 block discarded – undo
1902 1903
 	 * 'hasAndBelongsToMany' relationships: checks that there isn't already an entry in the join table, and adds one.
1903 1904
 	 * If one of the model Objects has not yet been saved to the database, it is saved before adding the entry in the join table
1904 1905
 	 *
1905
-	 * @param EE_Base_Class/int $thisModelObject
1906 1906
 	 * @param EE_Base_Class/int $id_or_obj EE_base_Class or ID of other Model Object
1907 1907
 	 * @param string $relationName, key in EEM_Base::_relations
1908 1908
 	 * an attendee to a group, you also want to specify which role they will have in that group. So you would use this parameter to specify array('role-column-name'=>'role-id')
@@ -1924,8 +1924,8 @@  discard block
 block discarded – undo
1924 1924
 	 *
1925 1925
 	 * 'hasAndBelongsToMany' relationships:removes any existing entry in the join table between the two models.
1926 1926
 	 *
1927
-	 * @param EE_Base_Class/int $id_or_obj
1928
-	 * @param EE_Base_Class/int $other_model_id_or_obj EE_Base_Class or ID of other Model Object
1927
+	 * @param EE_CPT_Base $id_or_obj
1928
+	 * @param EE_Term_Taxonomy $other_model_id_or_obj EE_Base_Class or ID of other Model Object
1929 1929
 	 * @param string $relationName key in EEM_Base::_relations
1930 1930
 	 * @return boolean of success
1931 1931
 	 * @param array   $where_query This allows you to enter further query params for the relation to for relation to methods that allow you to further specify extra columns to join by (such as HABTM).  Keep in mind that the only acceptable query_params is strict "col" => "value" pairs because these will be inserted in any new rows created as well.
@@ -2001,7 +2001,7 @@  discard block
 block discarded – undo
2001 2001
 	/**
2002 2002
 	 * Instead of getting the related model objects, simply counts them. Ignores default_where_conditions by default,
2003 2003
 	 * unless otherwise specified in the $query_params
2004
-	 * @param int/EE_Base_Class $id_or_obj
2004
+	 * @param EE_Event $id_or_obj
2005 2005
 	 * @param string $model_name like 'Event', or 'Registration'
2006 2006
 	 * @param array $query_params like EEM_Base::get_all's
2007 2007
 	 * @param string $field_to_count name of field to count by. By default, uses primary key
@@ -2390,7 +2390,7 @@  discard block
 block discarded – undo
2390 2390
 	/**
2391 2391
 	 * Finds all the fields that correspond to the given table
2392 2392
 	 * @param string $table_alias, array key in EEM_Base::_tables
2393
-	 * @return EE_Model_Field_Base[]
2393
+	 * @return EE_Model_Field_Base
2394 2394
 	 */
2395 2395
 	function _get_fields_for_table($table_alias){
2396 2396
 		return $this->_fields[$table_alias];
@@ -3454,8 +3454,8 @@  discard block
 block discarded – undo
3454 3454
 	/**
3455 3455
 	 * gets the field object of type 'primary_key' from the fieldsSettings attribute.
3456 3456
 	 * Eg, on EE_Answer that would be ANS_ID field object
3457
-	 * @param $field_obj
3458
-	 * @return EE_Model_Field_Base
3457
+	 * @param EE_Model_Field_Base $field_obj
3458
+	 * @return boolean
3459 3459
 	 */
3460 3460
 	public function is_primary_key_field( $field_obj ){
3461 3461
 		return $field_obj instanceof EE_Primary_Key_Field_Base ? TRUE : FALSE;
@@ -3549,7 +3549,7 @@  discard block
 block discarded – undo
3549 3549
 	 * Gets the actual table for the table alias
3550 3550
 	 * @param string $table_alias eg Event, Event_Meta, Registration, Transaction, but maybe
3551 3551
 	 * a table alias with a model chain prefix, like 'Venue__Event_Venue___Event_Meta'. Either one works
3552
-	 * @return EE_Table_Base
3552
+	 * @return string
3553 3553
 	 */
3554 3554
 	function get_table_for_alias($table_alias){
3555 3555
 		$table_alias_sans_model_relation_chain_prefix = EE_Model_Parser::remove_table_alias_model_relation_chain_prefix($table_alias);
@@ -3649,7 +3649,7 @@  discard block
 block discarded – undo
3649 3649
 	 * The purpose of this method is to allow us to create a model object that is not in the db that holds default values.
3650 3650
 	 * A typical example of where this is used is when creating a new item and the initial load of a form.  We dont' necessarily want to test for if the object is present but just assume it is BUT load the defaults from the object (as set in the model_field!).
3651 3651
 	 *
3652
-	 * @return EE_Base_Class single EE_Base_Class object with default values for the properties.
3652
+	 * @return boolean single EE_Base_Class object with default values for the properties.
3653 3653
 	 */
3654 3654
 	public function create_default_object() {
3655 3655
 
@@ -3804,6 +3804,9 @@  discard block
 block discarded – undo
3804 3804
 		return $this_model_fields_n_values;
3805 3805
 	}
3806 3806
 
3807
+	/**
3808
+	 * @param string $cols_n_values
3809
+	 */
3807 3810
 	protected function _get_column_value_with_table_alias_or_not( $cols_n_values, $qualified_column, $regular_column ){
3808 3811
 		//ask the field what it think it's table_name.column_name should be, and call it the "qualified column"
3809 3812
 		//does the field on the model relate to this column retrieved from the db?
@@ -4039,7 +4042,7 @@  discard block
 block discarded – undo
4039 4042
 	}
4040 4043
 	/**
4041 4044
 	 * Read comments for assume_values_already_prepared_by_model_object()
4042
-	 * @return int
4045
+	 * @return boolean
4043 4046
 	 */
4044 4047
 	public function get_assumption_concerning_values_already_prepared_by_model_object(){
4045 4048
 		return $this->_values_already_prepared_by_model_object;
Please login to merge, or discard this patch.
Spacing   +939 added lines, -939 removed lines patch added patch discarded remove patch
@@ -23,7 +23,7 @@  discard block
 block discarded – undo
23 23
  * @since 				EE4
24 24
  *
25 25
  */
26
-abstract class EEM_Base extends EE_Base{
26
+abstract class EEM_Base extends EE_Base {
27 27
 
28 28
 	//admin posty
29 29
 	//basic -> grants access to mine -> if they don't have it, select none
@@ -228,7 +228,7 @@  discard block
 block discarded – undo
228 228
 	 * Flag indicating whether this model has a primary key or not
229 229
 	 * @var boolean
230 230
 	 */
231
-	protected $_has_primary_key_field=null;
231
+	protected $_has_primary_key_field = null;
232 232
 
233 233
 	/**
234 234
 	 * Whether or not this model is based off a table in WP core only (CPTs should set
@@ -283,19 +283,19 @@  discard block
 block discarded – undo
283 283
 	 * operators that work like 'BETWEEN'.  Typically used for datetime calculations, i.e. "BETWEEN '12-1-2011' AND '12-31-2012'"
284 284
 	 * @var array
285 285
 	 */
286
-	protected $_between_style_operators = array( 'BETWEEN' );
286
+	protected $_between_style_operators = array('BETWEEN');
287 287
 
288 288
 	/**
289 289
 	 * operators that are used for handling NUll and !NULL queries.  Typically used for when checking if a row exists on a join table.
290 290
 	 * @var array
291 291
 	 */
292
-	protected $_null_style_operators = array( 'IS NOT NULL', 'IS NULL');
292
+	protected $_null_style_operators = array('IS NOT NULL', 'IS NULL');
293 293
 
294 294
 	/**
295 295
 	 * Allowed values for $query_params['order'] for ordering in queries
296 296
 	 * @var array
297 297
 	 */
298
-	protected $_allowed_order_values = array('asc','desc','ASC','DESC');
298
+	protected $_allowed_order_values = array('asc', 'desc', 'ASC', 'DESC');
299 299
 
300 300
 	/**
301 301
 	 * When these are keys in a WHERE or HAVING clause, they are handled much differently
@@ -309,13 +309,13 @@  discard block
 block discarded – undo
309 309
 	 * 'where', but 'where' clauses are so common that we thought we'd omit it
310 310
 	 * @var array
311 311
 	 */
312
-	private $_allowed_query_params = array(0, 'limit','order_by','group_by','having','force_join','order','on_join_limit','default_where_conditions', 'caps');
312
+	private $_allowed_query_params = array(0, 'limit', 'order_by', 'group_by', 'having', 'force_join', 'order', 'on_join_limit', 'default_where_conditions', 'caps');
313 313
 
314 314
 	/**
315 315
 	 * All the data types that can be used in $wpdb->prepare statements.
316 316
 	 * @var array
317 317
 	 */
318
-	private $_valid_wpdb_data_types = array('%d','%s','%f');
318
+	private $_valid_wpdb_data_types = array('%d', '%s', '%f');
319 319
 
320 320
 	/**
321 321
 	 * 	EE_Registry Object
@@ -348,17 +348,17 @@  discard block
 block discarded – undo
348 348
 	/**
349 349
 	 * constant used to show EEM_Base has not yet verified the db on this http request
350 350
 	 */
351
-	const db_verified_none 		= 0;
351
+	const db_verified_none = 0;
352 352
 	/**
353 353
 	 * constant used to show EEM_Base has verified the EE core db on this http request,
354 354
 	 * but not the addons' dbs
355 355
 	 */
356
-	const db_verified_core 		= 1;
356
+	const db_verified_core = 1;
357 357
 	/**
358 358
 	 * constant used to show EEM_Base has verified the addons' dbs (and implicitly
359 359
 	 * the EE core db too)
360 360
 	 */
361
-	const db_verified_addons 	= 2;
361
+	const db_verified_addons = 2;
362 362
 
363 363
 	/**
364 364
 	 * indicates whether an EEM_Base child has already re-verified the DB
@@ -389,13 +389,13 @@  discard block
 block discarded – undo
389 389
 	 * @param null $timezone
390 390
 	 * @throws \EE_Error
391 391
 	 */
392
-	protected function __construct( $timezone = NULL ){
392
+	protected function __construct($timezone = NULL) {
393 393
 		// check that the model has not been loaded too soon
394
-		if ( ! did_action( 'AHEE__EE_System__load_espresso_addons' )) {
395
-			throw new EE_Error (
394
+		if ( ! did_action('AHEE__EE_System__load_espresso_addons')) {
395
+			throw new EE_Error(
396 396
 				sprintf(
397
-					__( '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' ),
398
-					get_class( $this )
397
+					__('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'),
398
+					get_class($this)
399 399
 				)
400 400
 			);
401 401
 		}
@@ -405,11 +405,11 @@  discard block
 block discarded – undo
405 405
 		 * just use EE_Register_Model_Extension
406 406
 		 * @var EE_Table_Base[] $_tables
407 407
 		 */
408
-		$this->_tables = apply_filters( 'FHEE__'.get_class($this).'__construct__tables', $this->_tables );
409
-		foreach($this->_tables as $table_alias => $table_obj){
408
+		$this->_tables = apply_filters('FHEE__'.get_class($this).'__construct__tables', $this->_tables);
409
+		foreach ($this->_tables as $table_alias => $table_obj) {
410 410
 			/** @var $table_obj EE_Table_Base */
411 411
 			$table_obj->_construct_finalize_with_alias($table_alias);
412
-			if( $table_obj instanceof EE_Secondary_Table ){
412
+			if ($table_obj instanceof EE_Secondary_Table) {
413 413
 				/** @var $table_obj EE_Secondary_Table */
414 414
 				$table_obj->_construct_finalize_set_table_to_join_with($this->_get_main_table());
415 415
 			}
@@ -419,48 +419,48 @@  discard block
 block discarded – undo
419 419
 		 * EE_Register_Model_Extension
420 420
 		 * @param EE_Model_Field_Base[] $_fields
421 421
 		 */
422
-		$this->_fields = apply_filters('FHEE__'.get_class($this).'__construct__fields',$this->_fields);
423
-		foreach($this->_fields as $table_alias => $fields_for_table){
424
-			if ( ! array_key_exists( $table_alias, $this->_tables )){
425
-				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)));
422
+		$this->_fields = apply_filters('FHEE__'.get_class($this).'__construct__fields', $this->_fields);
423
+		foreach ($this->_fields as $table_alias => $fields_for_table) {
424
+			if ( ! array_key_exists($table_alias, $this->_tables)) {
425
+				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)));
426 426
 			}
427
-			foreach($fields_for_table as $field_name => $field_obj){
427
+			foreach ($fields_for_table as $field_name => $field_obj) {
428 428
 				/** @var $field_obj EE_Model_Field_Base | EE_Primary_Key_Field_Base */
429 429
 				//primary key field base has a slightly different _construct_finalize
430 430
 				/** @var $field_obj EE_Model_Field_Base */
431
-				$field_obj->_construct_finalize( $table_alias, $field_name, $this->get_this_model_name() );
431
+				$field_obj->_construct_finalize($table_alias, $field_name, $this->get_this_model_name());
432 432
 			}
433 433
 		}
434 434
 
435 435
 		// everything is related to Extra_Meta
436
-		if( get_class($this) != 'EEM_Extra_Meta'){
436
+		if (get_class($this) != 'EEM_Extra_Meta') {
437 437
 			//make extra meta related to everything, but don't block deleting things just
438 438
 			//because they have related extra meta info. For now just orphan those extra meta
439 439
 			//in the future we should automatically delete them
440
-			$this->_model_relations['Extra_Meta'] = new EE_Has_Many_Any_Relation( FALSE );
440
+			$this->_model_relations['Extra_Meta'] = new EE_Has_Many_Any_Relation(FALSE);
441 441
 		}
442 442
 		//and change logs
443
-		if( get_class( $this) !=  'EEM_Change_Log' ) {
444
-			$this->_model_relations[ 'Change_Log' ] = new EE_Has_Many_Any_Relation( FALSE );
443
+		if (get_class($this) != 'EEM_Change_Log') {
444
+			$this->_model_relations['Change_Log'] = new EE_Has_Many_Any_Relation(FALSE);
445 445
 		}
446 446
 		/**
447 447
 		 * Filters the list of relations on a model. It is best to NOT use this directly and instead just use
448 448
 		 * EE_Register_Model_Extension
449 449
 		 * @param EE_Model_Relation_Base[] $_model_relations
450 450
 		 */
451
-		$this->_model_relations = apply_filters('FHEE__'.get_class($this).'__construct__model_relations',$this->_model_relations);
452
-		foreach($this->_model_relations as $model_name => $relation_obj){
451
+		$this->_model_relations = apply_filters('FHEE__'.get_class($this).'__construct__model_relations', $this->_model_relations);
452
+		foreach ($this->_model_relations as $model_name => $relation_obj) {
453 453
 			/** @var $relation_obj EE_Model_Relation_Base */
454 454
 			$relation_obj->_construct_finalize_set_models($this->get_this_model_name(), $model_name);
455 455
 		}
456
-		foreach($this->_indexes as $index_name => $index_obj){
456
+		foreach ($this->_indexes as $index_name => $index_obj) {
457 457
 			/** @var $index_obj EE_Index */
458 458
 			$index_obj->_construct_finalize($index_name, $this->get_this_model_name());
459 459
 		}
460 460
 
461 461
 		$this->set_timezone($timezone);
462 462
 		//finalize default where condition strategy, or set default
463
-		if( ! $this->_default_where_conditions_strategy){
463
+		if ( ! $this->_default_where_conditions_strategy) {
464 464
 			//nothing was set during child constructor, so set default
465 465
 			$this->_default_where_conditions_strategy = new EE_Default_Where_Conditions();
466 466
 		}
@@ -468,15 +468,15 @@  discard block
 block discarded – undo
468 468
 
469 469
 		//if the cap slug hasn't been set, and we haven't set it to false on purpose
470 470
 		//to indicate to NOT set it, set it to the logical default
471
-		if( $this->_caps_slug === null ) {
472
-			EE_Registry::instance()->load_helper( 'Inflector' );
473
-			$this->_caps_slug = EEH_Inflector::pluralize_and_lower( $this->get_this_model_name() );
471
+		if ($this->_caps_slug === null) {
472
+			EE_Registry::instance()->load_helper('Inflector');
473
+			$this->_caps_slug = EEH_Inflector::pluralize_and_lower($this->get_this_model_name());
474 474
 		}
475 475
 		//initialize the standard cap restriction generators if none were specified by the child constructor
476
-		if( $this->_cap_restriction_generators !== false ){
477
-			foreach( $this->cap_contexts_to_cap_action_map() as $cap_context => $action ){
478
-				if( ! isset( $this->_cap_restriction_generators[ $cap_context ] ) ) {
479
-					$this->_cap_restriction_generators[ $cap_context ] = apply_filters(
476
+		if ($this->_cap_restriction_generators !== false) {
477
+			foreach ($this->cap_contexts_to_cap_action_map() as $cap_context => $action) {
478
+				if ( ! isset($this->_cap_restriction_generators[$cap_context])) {
479
+					$this->_cap_restriction_generators[$cap_context] = apply_filters(
480 480
 						'FHEE__EEM_Base___construct__standard_cap_restriction_generator',
481 481
 						new EE_Restriction_Generator_Protected(),
482 482
 						$cap_context,
@@ -486,23 +486,23 @@  discard block
 block discarded – undo
486 486
 			}
487 487
 		}
488 488
 		//if there are cap restriction generators, use them to make the default cap restrictions
489
-		if( $this->_cap_restriction_generators !== false ){
490
-			foreach( $this->_cap_restriction_generators as $context => $generator_object ) {
491
-				if( ! $generator_object ){
489
+		if ($this->_cap_restriction_generators !== false) {
490
+			foreach ($this->_cap_restriction_generators as $context => $generator_object) {
491
+				if ( ! $generator_object) {
492 492
 					continue;
493 493
 				}
494
-				if( ! $generator_object instanceof EE_Restriction_Generator_Base ){
494
+				if ( ! $generator_object instanceof EE_Restriction_Generator_Base) {
495 495
 					throw new EE_Error(
496 496
 						sprintf(
497
-							__( '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' ),
497
+							__('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'),
498 498
 							$context,
499 499
 							$this->get_this_model_name()
500 500
 						)
501 501
 					);
502 502
 				}
503
-				$action = $this->cap_action_for_context( $context );
504
-				if( ! $generator_object->construction_finalized() ){
505
-					$generator_object->_construct_finalize( $this, $action );
503
+				$action = $this->cap_action_for_context($context);
504
+				if ( ! $generator_object->construction_finalized()) {
505
+					$generator_object->_construct_finalize($this, $action);
506 506
 				}
507 507
 
508 508
 			}
@@ -516,11 +516,11 @@  discard block
 block discarded – undo
516 516
 	 * @param string $context one of EEM_Base::valid_cap_contexts()
517 517
 	 * @return EE_Default_Where_Conditions[]
518 518
 	 */
519
-	protected function _generate_cap_restrictions( $context ){
520
-		if( isset( $this->_cap_restriction_generators[ $context ] ) &&
521
-				$this->_cap_restriction_generators[ $context ] instanceof EE_Restriction_Generator_Base ) {
522
-			return $this->_cap_restriction_generators[ $context ]->generate_restrictions();
523
-		}else{
519
+	protected function _generate_cap_restrictions($context) {
520
+		if (isset($this->_cap_restriction_generators[$context]) &&
521
+				$this->_cap_restriction_generators[$context] instanceof EE_Restriction_Generator_Base) {
522
+			return $this->_cap_restriction_generators[$context]->generate_restrictions();
523
+		} else {
524 524
 			return array();
525 525
 		}
526 526
 }
@@ -533,16 +533,16 @@  discard block
 block discarded – undo
533 533
 	 *		@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)
534 534
 	 *		@return static (as in the concrete child class)
535 535
 	 */
536
-	public static function instance( $timezone = NULL ){
536
+	public static function instance($timezone = NULL) {
537 537
 
538 538
 		// check if instance of Espresso_model already exists
539 539
 		if ( ! static::$_instance instanceof static) {
540 540
 			// instantiate Espresso_model
541
-			static::$_instance = new static( $timezone );
541
+			static::$_instance = new static($timezone);
542 542
 		}
543 543
 
544 544
 		//we might have a timezone set, let set_timezone decide what to do with it
545
-		static::$_instance->set_timezone( $timezone );
545
+		static::$_instance->set_timezone($timezone);
546 546
 
547 547
 		// Espresso_model object
548 548
 		return static::$_instance;
@@ -555,11 +555,11 @@  discard block
 block discarded – undo
555 555
 	 * @param null | string $timezone
556 556
 	 * @return static
557 557
 	 */
558
-	public static function reset(  $timezone = NULL ){
559
-		if ( ! is_null( static::$_instance ) ) {
558
+	public static function reset($timezone = NULL) {
559
+		if ( ! is_null(static::$_instance)) {
560 560
 			static::$_instance = null;
561 561
 
562
-			return self::instance( $timezone );
562
+			return self::instance($timezone);
563 563
 		}
564 564
 		return null;
565 565
 	}
@@ -570,15 +570,15 @@  discard block
 block discarded – undo
570 570
 	 * @param  boolean $translated return localized strings or JUST the array.
571 571
 	 * @return array
572 572
 	 */
573
-	 public function status_array( $translated = FALSE ) {
574
-	 	if ( !array_key_exists('Status', $this->_model_relations ) )
573
+	 public function status_array($translated = FALSE) {
574
+	 	if ( ! array_key_exists('Status', $this->_model_relations))
575 575
 	 		return array();
576 576
 	 	$model_name = $this->get_this_model_name();
577
-	 	$status_type = str_replace(' ', '_', strtolower( str_replace('_', ' ', $model_name) ) );
578
-	 	$stati = EEM_Status::instance()->get_all(array(array('STS_type' => $status_type) ) );
577
+	 	$status_type = str_replace(' ', '_', strtolower(str_replace('_', ' ', $model_name)));
578
+	 	$stati = EEM_Status::instance()->get_all(array(array('STS_type' => $status_type)));
579 579
 	 	$status_array = array();
580
-	 	foreach ( $stati as $status ) {
581
-            $status_array[ $status->ID() ] = $status->get('STS_code');
580
+	 	foreach ($stati as $status) {
581
+            $status_array[$status->ID()] = $status->get('STS_code');
582 582
         }
583 583
         return $translated ? EEM_Status::instance()->localized_status($status_array, FALSE, 'sentence') : $status_array;
584 584
     }
@@ -719,7 +719,7 @@  discard block
 block discarded – undo
719 719
 	 *			'order_by'=>array('ANS_value'=>'ASC')
720 720
 	 *		));
721 721
 	 */
722
-	function get_all($query_params = array()){
722
+	function get_all($query_params = array()) {
723 723
 		return $this->_create_objects($this->_get_all_wpdb_results($query_params, ARRAY_A, NULL));
724 724
 	}
725 725
 
@@ -729,10 +729,10 @@  discard block
 block discarded – undo
729 729
 	 * @param array $query_params @see EEM_Base::get_all()
730 730
 	 * @return array like EEM_Base::get_all
731 731
 	 */
732
-	function alter_query_params_to_only_include_mine( $query_params = array() ) {
732
+	function alter_query_params_to_only_include_mine($query_params = array()) {
733 733
 		$wp_user_field_name = $this->wp_user_field_name();
734
-		if( $wp_user_field_name ){
735
-			$query_params[0][ $wp_user_field_name ] = get_current_user_id();
734
+		if ($wp_user_field_name) {
735
+			$query_params[0][$wp_user_field_name] = get_current_user_id();
736 736
 		}
737 737
 		return $query_params;
738 738
 	}
@@ -745,19 +745,19 @@  discard block
 block discarded – undo
745 745
 	 * foreign key to the WP_User table
746 746
 	 */
747 747
 	function wp_user_field_name() {
748
-		try{
749
-			if( ! empty( $this->_model_chain_to_wp_user ) ) {
750
-				$models_to_follow_to_wp_users = explode( '.', $this->_model_chain_to_wp_user );
751
-				$last_model_name = end( $models_to_follow_to_wp_users );
752
-				$model_with_fk_to_wp_users = EE_Registry::instance()->load_model( $last_model_name );
753
-				$model_chain_to_wp_user = $this->_model_chain_to_wp_user . '.';
754
-			}else{
748
+		try {
749
+			if ( ! empty($this->_model_chain_to_wp_user)) {
750
+				$models_to_follow_to_wp_users = explode('.', $this->_model_chain_to_wp_user);
751
+				$last_model_name = end($models_to_follow_to_wp_users);
752
+				$model_with_fk_to_wp_users = EE_Registry::instance()->load_model($last_model_name);
753
+				$model_chain_to_wp_user = $this->_model_chain_to_wp_user.'.';
754
+			} else {
755 755
 				$model_with_fk_to_wp_users = $this;
756 756
 				$model_chain_to_wp_user = '';
757 757
 			}
758
-			$wp_user_field = $model_with_fk_to_wp_users->get_foreign_key_to( 'WP_User' );
759
-			return $model_chain_to_wp_user . $wp_user_field->get_name();
760
-		}catch( EE_Error $e ) {
758
+			$wp_user_field = $model_with_fk_to_wp_users->get_foreign_key_to('WP_User');
759
+			return $model_chain_to_wp_user.$wp_user_field->get_name();
760
+		} catch (EE_Error $e) {
761 761
 			return false;
762 762
 		}
763 763
 	}
@@ -771,7 +771,7 @@  discard block
 block discarded – undo
771 771
 	 * (or transietly-related model)
772 772
 	 * @return string
773 773
 	 */
774
-	public function model_chain_to_wp_user(){
774
+	public function model_chain_to_wp_user() {
775 775
 		return $this->_model_chain_to_wp_user;
776 776
 	}
777 777
 
@@ -783,13 +783,13 @@  discard block
 block discarded – undo
783 783
 	 * @return boolean
784 784
 	 */
785 785
 	public function is_owned() {
786
-		if( $this->model_chain_to_wp_user() ){
786
+		if ($this->model_chain_to_wp_user()) {
787 787
 			return true;
788
-		}else{
789
-			try{
790
-				$this->get_foreign_key_to( 'WP_User' );
788
+		} else {
789
+			try {
790
+				$this->get_foreign_key_to('WP_User');
791 791
 				return true;
792
-			}catch( EE_Error $e ){
792
+			} catch (EE_Error $e) {
793 793
 				return false;
794 794
 			}
795 795
 		}
@@ -808,21 +808,21 @@  discard block
 block discarded – undo
808 808
 	 * and 1 is the data type. Eg, array('count'=>array('COUNT(REG_ID)','%d'))
809 809
 	 * @return array|stdClass[] like results of $wpdb->get_results($sql,OBJECT), (ie, output type is OBJECT)
810 810
 	 */
811
-	protected function  _get_all_wpdb_results($query_params = array(), $output = ARRAY_A, $columns_to_select = null){
811
+	protected function  _get_all_wpdb_results($query_params = array(), $output = ARRAY_A, $columns_to_select = null) {
812 812
 		//remember the custom selections, if any
813
-		if(is_array($columns_to_select)){
813
+		if (is_array($columns_to_select)) {
814 814
 			$this->_custom_selections = $columns_to_select;
815
-		}elseif(is_string($columns_to_select)){
815
+		}elseif (is_string($columns_to_select)) {
816 816
 			$this->_custom_selections = array($this->_custom_selections);
817
-		}else{
817
+		} else {
818 818
 			$this->_custom_selections = array();
819 819
 		}
820 820
 
821 821
 		$model_query_info = $this->_create_model_query_info_carrier($query_params);
822 822
 		$select_expressions = $columns_to_select ? $this->_construct_select_from_input($columns_to_select) : $this->_construct_default_select_sql($model_query_info);
823
-		$SQL ="SELECT $select_expressions ".$this->_construct_2nd_half_of_select_query($model_query_info);
823
+		$SQL = "SELECT $select_expressions ".$this->_construct_2nd_half_of_select_query($model_query_info);
824 824
 //		echo "sql:$SQL";
825
-		$results =  $this->_do_wpdb_query( 'get_results', array($SQL, $output ) );// $wpdb->get_results($SQL, $output);
825
+		$results = $this->_do_wpdb_query('get_results', array($SQL, $output)); // $wpdb->get_results($SQL, $output);
826 826
 		return $results;
827 827
 	}
828 828
 
@@ -839,7 +839,7 @@  discard block
 block discarded – undo
839 839
 	 * and 1 is the data type. Eg, array('count'=>array('COUNT(REG_ID)','%d'))
840 840
 	 * @return stdClass[] like results of $wpdb->get_results($sql,OBJECT), (ie, output type is OBJECT)
841 841
 	 */
842
-	public function  get_all_wpdb_results($query_params = array(), $output = ARRAY_A, $columns_to_select = null){
842
+	public function  get_all_wpdb_results($query_params = array(), $output = ARRAY_A, $columns_to_select = null) {
843 843
 		return $this->_get_all_wpdb_results($query_params, $output, $columns_to_select);
844 844
 	}
845 845
 
@@ -851,21 +851,21 @@  discard block
 block discarded – undo
851 851
 	 * @throws EE_Error
852 852
 	 * @return string
853 853
 	 */
854
-	private function _construct_select_from_input($columns_to_select){
855
-		if(is_array($columns_to_select)){
854
+	private function _construct_select_from_input($columns_to_select) {
855
+		if (is_array($columns_to_select)) {
856 856
 			$select_sql_array = array();
857 857
 
858
-			foreach($columns_to_select as $alias => $selection_and_datatype){
859
-				if( ! is_array($selection_and_datatype) || ! isset($selection_and_datatype[1])){
860
-					throw new EE_Error(sprintf(__("Custom selection %s (alias %s) needs to be an array like array('COUNT(REG_ID)','%%d')", "event_espresso"),$selection_and_datatype,$alias));
858
+			foreach ($columns_to_select as $alias => $selection_and_datatype) {
859
+				if ( ! is_array($selection_and_datatype) || ! isset($selection_and_datatype[1])) {
860
+					throw new EE_Error(sprintf(__("Custom selection %s (alias %s) needs to be an array like array('COUNT(REG_ID)','%%d')", "event_espresso"), $selection_and_datatype, $alias));
861 861
 				}
862
-				if( ! in_array( $selection_and_datatype[1],$this->_valid_wpdb_data_types)){
863
-					throw new EE_Error(sprintf(__("Datatype %s (for selection '%s' and alias '%s') is not a valid wpdb datatype (eg %%s)", "event_espresso"),$selection_and_datatype[1],$selection_and_datatype[0],$alias,implode(",",$this->_valid_wpdb_data_types)));
862
+				if ( ! in_array($selection_and_datatype[1], $this->_valid_wpdb_data_types)) {
863
+					throw new EE_Error(sprintf(__("Datatype %s (for selection '%s' and alias '%s') is not a valid wpdb datatype (eg %%s)", "event_espresso"), $selection_and_datatype[1], $selection_and_datatype[0], $alias, implode(",", $this->_valid_wpdb_data_types)));
864 864
 				}
865 865
 				$select_sql_array[] = "{$selection_and_datatype[0]} AS $alias";
866 866
 			}
867
-			$columns_to_select_string = implode(", ",$select_sql_array);
868
-		}else{
867
+			$columns_to_select_string = implode(", ", $select_sql_array);
868
+		} else {
869 869
 			$columns_to_select_string = $columns_to_select;
870 870
 		}
871 871
 		return $columns_to_select_string;
@@ -878,7 +878,7 @@  discard block
 block discarded – undo
878 878
 	 * Convenient wrapper for getting the primary key field's name. Eg, on Registration, this would be 'REG_ID'
879 879
 	 * @return string
880 880
 	 */
881
-	function primary_key_name(){
881
+	function primary_key_name() {
882 882
 		return $this->get_primary_key_field()->get_name();
883 883
 	}
884 884
 
@@ -890,15 +890,15 @@  discard block
 block discarded – undo
890 890
 	 * @param mixed $id int or string, depending on the type of the model's primary key
891 891
 	 * @return EE_Base_Class
892 892
 	 */
893
-	function get_one_by_ID($id){
894
-		if( $this->get_from_entity_map( $id ) ){
895
-			return $this->get_from_entity_map( $id );
896
-		}elseif( $this->has_primary_key_field ( ) ) {
893
+	function get_one_by_ID($id) {
894
+		if ($this->get_from_entity_map($id)) {
895
+			return $this->get_from_entity_map($id);
896
+		}elseif ($this->has_primary_key_field( )) {
897 897
 			$primary_key_name = $this->get_primary_key_field()->get_name();
898 898
 			return $this->get_one(array(array($primary_key_name => $id)));
899
-		}else{
899
+		} else {
900 900
 			//no primary key, so the $id must be from the get_index_primary_key_string()
901
-			return $this->get_one( array( $this->parse_index_primary_key_string( $id ) ) );
901
+			return $this->get_one(array($this->parse_index_primary_key_string($id)));
902 902
 		}
903 903
 	}
904 904
 
@@ -909,16 +909,16 @@  discard block
 block discarded – undo
909 909
 	 * @param array $query_params like EEM_Base's $query_params variable.
910 910
 	 * @return EE_Base_Class | NULL
911 911
 	 */
912
-	function get_one($query_params = array()){
913
-		if( ! is_array( $query_params ) ){
914
-			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' );
912
+	function get_one($query_params = array()) {
913
+		if ( ! is_array($query_params)) {
914
+			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');
915 915
 			$query_params = array();
916 916
 		}
917 917
 		$query_params['limit'] = 1;
918 918
 		$items = $this->get_all($query_params);
919
-		if(empty($items)){
919
+		if (empty($items)) {
920 920
 			return null;
921
-		}else{
921
+		} else {
922 922
 			return array_shift($items);
923 923
 		}
924 924
 	}
@@ -942,8 +942,8 @@  discard block
 block discarded – undo
942 942
 	 *
943 943
 	 * @return EE_Base_Class[]|array
944 944
 	 */
945
-	public function next_x( $current_field_value, $field_to_order_by = null, $limit = 1, $query_params = array(), $columns_to_select = null ) {
946
-		return $this->_get_consecutive( $current_field_value, '>', $field_to_order_by, $limit, $query_params, $columns_to_select );
945
+	public function next_x($current_field_value, $field_to_order_by = null, $limit = 1, $query_params = array(), $columns_to_select = null) {
946
+		return $this->_get_consecutive($current_field_value, '>', $field_to_order_by, $limit, $query_params, $columns_to_select);
947 947
 	}
948 948
 
949 949
 
@@ -966,8 +966,8 @@  discard block
 block discarded – undo
966 966
 	 *
967 967
 	 * @return EE_Base_Class[]|array
968 968
 	 */
969
-	public function previous_x( $current_field_value, $field_to_order_by = null, $limit = 1, $query_params = array(), $columns_to_select = null ) {
970
-		return $this->_get_consecutive( $current_field_value, '<', $field_to_order_by, $limit, $query_params, $columns_to_select );
969
+	public function previous_x($current_field_value, $field_to_order_by = null, $limit = 1, $query_params = array(), $columns_to_select = null) {
970
+		return $this->_get_consecutive($current_field_value, '<', $field_to_order_by, $limit, $query_params, $columns_to_select);
971 971
 	}
972 972
 
973 973
 
@@ -989,9 +989,9 @@  discard block
 block discarded – undo
989 989
 	 *
990 990
 	 * @return EE_Base_Class|null|array()
991 991
 	 */
992
-	public function next( $current_field_value, $field_to_order_by = null, $query_params = array(), $columns_to_select = null ) {
993
-		$results = $this->_get_consecutive( $current_field_value, '>', $field_to_order_by, 1, $query_params, $columns_to_select );
994
-		return empty( $results ) ? null : reset( $results );
992
+	public function next($current_field_value, $field_to_order_by = null, $query_params = array(), $columns_to_select = null) {
993
+		$results = $this->_get_consecutive($current_field_value, '>', $field_to_order_by, 1, $query_params, $columns_to_select);
994
+		return empty($results) ? null : reset($results);
995 995
 	}
996 996
 
997 997
 
@@ -1013,9 +1013,9 @@  discard block
 block discarded – undo
1013 1013
 	 *
1014 1014
 	 * @return EE_Base_Class|null|array()
1015 1015
 	 */
1016
-	public function previous( $current_field_value, $field_to_order_by = null, $query_params = array(), $columns_to_select = null ) {
1017
-		$results = $this->_get_consecutive( $current_field_value, '<', $field_to_order_by, 1, $query_params, $columns_to_select );
1018
-		return empty( $results ) ? null : reset( $results );
1016
+	public function previous($current_field_value, $field_to_order_by = null, $query_params = array(), $columns_to_select = null) {
1017
+		$results = $this->_get_consecutive($current_field_value, '<', $field_to_order_by, 1, $query_params, $columns_to_select);
1018
+		return empty($results) ? null : reset($results);
1019 1019
 	}
1020 1020
 
1021 1021
 
@@ -1041,40 +1041,40 @@  discard block
 block discarded – undo
1041 1041
 	 * @return EE_Base_Class[]|array
1042 1042
 	 * @throws EE_Error
1043 1043
 	 */
1044
-	protected function _get_consecutive( $current_field_value, $operand = '>', $field_to_order_by = null, $limit = 1, $query_params = array(), $columns_to_select = null ) {
1044
+	protected function _get_consecutive($current_field_value, $operand = '>', $field_to_order_by = null, $limit = 1, $query_params = array(), $columns_to_select = null) {
1045 1045
 		//if $field_to_order_by is empty then let's assume we're ordering by the primary key.
1046
-		if ( empty( $field_to_order_by ) ) {
1047
-			if ( $this->has_primary_key_field() ) {
1046
+		if (empty($field_to_order_by)) {
1047
+			if ($this->has_primary_key_field()) {
1048 1048
 				$field_to_order_by = $this->get_primary_key_field()->get_name();
1049 1049
 			} else {
1050 1050
 
1051
-				if ( WP_DEBUG ) {
1052
-					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' ) );
1051
+				if (WP_DEBUG) {
1052
+					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'));
1053 1053
 				}
1054
-				EE_Error::add_error( __('There was an error with the query.', 'event_espresso') );
1054
+				EE_Error::add_error(__('There was an error with the query.', 'event_espresso'));
1055 1055
 				return array();
1056 1056
 			}
1057 1057
 		}
1058 1058
 
1059
-		if( ! is_array( $query_params ) ){
1060
-			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' );
1059
+		if ( ! is_array($query_params)) {
1060
+			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');
1061 1061
 			$query_params = array();
1062 1062
 		}
1063 1063
 
1064 1064
 		//let's add the where query param for consecutive look up.
1065
-		$query_params[0][ $field_to_order_by ] = array( $operand, $current_field_value );
1065
+		$query_params[0][$field_to_order_by] = array($operand, $current_field_value);
1066 1066
 		$query_params['limit'] = $limit;
1067 1067
 
1068 1068
 		//set direction
1069
-		$incoming_orderby = isset( $query_params['order_by'] ) ? $query_params['order_by'] : array();
1070
-		$query_params['order_by'] = $operand == '>' ? array( $field_to_order_by => 'ASC' ) + $incoming_orderby : array( $field_to_order_by => 'DESC') + $incoming_orderby;
1069
+		$incoming_orderby = isset($query_params['order_by']) ? $query_params['order_by'] : array();
1070
+		$query_params['order_by'] = $operand == '>' ? array($field_to_order_by => 'ASC') + $incoming_orderby : array($field_to_order_by => 'DESC') + $incoming_orderby;
1071 1071
 
1072 1072
 		//if $columns_to_select is empty then that means we're returning EE_Base_Class objects
1073
-		if ( empty( $columns_to_select ) ) {
1074
-			return $this->get_all( $query_params );
1073
+		if (empty($columns_to_select)) {
1074
+			return $this->get_all($query_params);
1075 1075
 		} else {
1076 1076
 			//getting just the fields
1077
-			return $this->_get_all_wpdb_results( $query_params, ARRAY_A, $columns_to_select );
1077
+			return $this->_get_all_wpdb_results($query_params, ARRAY_A, $columns_to_select);
1078 1078
 		}
1079 1079
 	}
1080 1080
 
@@ -1085,18 +1085,18 @@  discard block
 block discarded – undo
1085 1085
 	 * This sets the _timezone property after model object has been instantiated.
1086 1086
 	 * @param null | string $timezone valid PHP DateTimeZone timezone string
1087 1087
 	 */
1088
-	public function set_timezone( $timezone ) {
1089
-		if ( $timezone !== null ) {
1088
+	public function set_timezone($timezone) {
1089
+		if ($timezone !== null) {
1090 1090
 			$this->_timezone = $timezone;
1091 1091
 		}
1092 1092
 		//note we need to loop through relations and set the timezone on those objects as well.
1093
-		foreach ( $this->_model_relations as $relation ) {
1094
-			$relation->set_timezone( $timezone );
1093
+		foreach ($this->_model_relations as $relation) {
1094
+			$relation->set_timezone($timezone);
1095 1095
 		}
1096 1096
 		//and finally we do the same for any datetime fields
1097
-		foreach ( $this->_fields as $field ) {
1098
-			if ( $field instanceof EE_Datetime_Field ) {
1099
-				$field->set_timezone( $timezone );
1097
+		foreach ($this->_fields as $field) {
1098
+			if ($field instanceof EE_Datetime_Field) {
1099
+				$field->set_timezone($timezone);
1100 1100
 			}
1101 1101
 		}
1102 1102
 	}
@@ -1111,9 +1111,9 @@  discard block
 block discarded – undo
1111 1111
 	 */
1112 1112
 	public function get_timezone() {
1113 1113
 		//first validate if timezone is set.  If not, then let's set it be whatever is set on the model fields.
1114
-		if ( empty( $this->_timezone ) ) {
1115
-			foreach( $this->_fields as $field ) {
1116
-				if ( $field instanceof EE_Datetime_Field ) {
1114
+		if (empty($this->_timezone)) {
1115
+			foreach ($this->_fields as $field) {
1116
+				if ($field instanceof EE_Datetime_Field) {
1117 1117
 					$this->set_timezone($field->get_timezone());
1118 1118
 					break;
1119 1119
 				}
@@ -1121,9 +1121,9 @@  discard block
 block discarded – undo
1121 1121
 		}
1122 1122
 
1123 1123
 		//if timezone STILL empty then return the default timezone for the site.
1124
-		if ( empty( $this->_timezone ) ) {
1125
-			EE_Registry::instance()->load_helper( 'DTT_Helper' );
1126
-			$this->set_timezone( EEH_DTT_Helper::get_timezone() );
1124
+		if (empty($this->_timezone)) {
1125
+			EE_Registry::instance()->load_helper('DTT_Helper');
1126
+			$this->set_timezone(EEH_DTT_Helper::get_timezone());
1127 1127
 		}
1128 1128
 		return $this->_timezone;
1129 1129
 	}
@@ -1141,19 +1141,19 @@  discard block
 block discarded – undo
1141 1141
 	 *
1142 1142
 	 * @return array formats in an array with the date format first, and the time format last.
1143 1143
 	 */
1144
-	public function get_formats_for( $field_name, $pretty = false ) {
1145
-		$field_settings = $this->field_settings_for( $field_name );
1144
+	public function get_formats_for($field_name, $pretty = false) {
1145
+		$field_settings = $this->field_settings_for($field_name);
1146 1146
 
1147 1147
 		//if not a valid EE_Datetime_Field then throw error
1148
-		if ( ! $field_settings instanceof EE_Datetime_Field ) {
1149
-			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 ) );
1148
+		if ( ! $field_settings instanceof EE_Datetime_Field) {
1149
+			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));
1150 1150
 		}
1151 1151
 
1152 1152
 		//while we are here, let's make sure the timezone internally in EEM_Base matches what is stored on
1153 1153
 		//the field.
1154 1154
 		$this->_timezone = $field_settings->get_timezone();
1155 1155
 
1156
-		return array( $field_settings->get_date_format( $pretty ), $field_settings->get_time_format( $pretty ) );
1156
+		return array($field_settings->get_date_format($pretty), $field_settings->get_time_format($pretty));
1157 1157
 	}
1158 1158
 
1159 1159
 
@@ -1177,25 +1177,25 @@  discard block
 block discarded – undo
1177 1177
 	 * @return int|string  If the given field_name is not of the EE_Datetime_Field type, then an EE_Error
1178 1178
 	 *                    	     exception is triggered.
1179 1179
 	 */
1180
-	public function current_time_for_query( $field_name, $timestamp = false, $what = 'both' ) {
1181
-		$formats = $this->get_formats_for( $field_name );
1180
+	public function current_time_for_query($field_name, $timestamp = false, $what = 'both') {
1181
+		$formats = $this->get_formats_for($field_name);
1182 1182
 
1183
-		$DateTime = new DateTime( "now", new DateTimeZone( $this->_timezone ) );
1183
+		$DateTime = new DateTime("now", new DateTimeZone($this->_timezone));
1184 1184
 
1185
-		if ( $timestamp ) {
1186
-			return $DateTime->format( 'U' );
1185
+		if ($timestamp) {
1186
+			return $DateTime->format('U');
1187 1187
 		}
1188 1188
 
1189 1189
 		//not returning timestamp, so return formatted string in timezone.
1190
-		switch( $what ) {
1190
+		switch ($what) {
1191 1191
 			case 'time' :
1192
-				return $DateTime->format( $formats[1] );
1192
+				return $DateTime->format($formats[1]);
1193 1193
 				break;
1194 1194
 			case 'date' :
1195
-				return $DateTime->format( $formats[0] );
1195
+				return $DateTime->format($formats[0]);
1196 1196
 				break;
1197 1197
 			default :
1198
-				return $DateTime->format( implode( ' ', $formats ) );
1198
+				return $DateTime->format(implode(' ', $formats));
1199 1199
 				break;
1200 1200
 		}
1201 1201
 	}
@@ -1219,18 +1219,18 @@  discard block
 block discarded – undo
1219 1219
 	 *                           		'U', this is ignored.
1220 1220
 	 * @return DateTime
1221 1221
 	 */
1222
-	public function convert_datetime_for_query( $field_name, $timestring, $incoming_format, $timezone = '' ) {
1222
+	public function convert_datetime_for_query($field_name, $timestring, $incoming_format, $timezone = '') {
1223 1223
 
1224 1224
 		//just using this to ensure the timezone is set correctly internally
1225
-		$this->get_formats_for( $field_name );
1225
+		$this->get_formats_for($field_name);
1226 1226
 
1227 1227
 		//load EEH_DTT_Helper
1228
-		EE_Registry::instance()->load_helper( 'DTT_Helper' );
1229
-		$set_timezone = empty( $timezone ) ? EEH_DTT_Helper::get_timezone() : $timezone;
1228
+		EE_Registry::instance()->load_helper('DTT_Helper');
1229
+		$set_timezone = empty($timezone) ? EEH_DTT_Helper::get_timezone() : $timezone;
1230 1230
 
1231
-		$incomingDateTime = date_create_from_format( $incoming_format, $timestring, new DateTimeZone( $set_timezone ) );
1231
+		$incomingDateTime = date_create_from_format($incoming_format, $timestring, new DateTimeZone($set_timezone));
1232 1232
 
1233
-		return $incomingDateTime->setTimeZone( new DateTimeZone( $this->_timezone ) );
1233
+		return $incomingDateTime->setTimeZone(new DateTimeZone($this->_timezone));
1234 1234
 	}
1235 1235
 
1236 1236
 
@@ -1240,7 +1240,7 @@  discard block
 block discarded – undo
1240 1240
 	 * Gets all the tables comprising this model. Array keys are the table aliases, and values are EE_Table objects
1241 1241
 	 * @return EE_Table_Base[]
1242 1242
 	 */
1243
-	function get_tables(){
1243
+	function get_tables() {
1244 1244
 		return $this->_tables;
1245 1245
 	}
1246 1246
 
@@ -1274,9 +1274,9 @@  discard block
 block discarded – undo
1274 1274
 	 * be aware that model objects being used could get out-of-sync with the database
1275 1275
 	 * @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)
1276 1276
 	 */
1277
-	function update($fields_n_values, $query_params, $keep_model_objs_in_sync = TRUE){
1278
-		if( ! is_array( $query_params ) ){
1279
-			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' );
1277
+	function update($fields_n_values, $query_params, $keep_model_objs_in_sync = TRUE) {
1278
+		if ( ! is_array($query_params)) {
1279
+			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');
1280 1280
 			$query_params = array();
1281 1281
 		}
1282 1282
 		/**
@@ -1286,7 +1286,7 @@  discard block
 block discarded – undo
1286 1286
 		 * @param array $fields_n_values the updated fields and their new values
1287 1287
 		 * @param array $query_params @see EEM_Base::get_all()
1288 1288
 		 */
1289
-		do_action( 'AHEE__EEM_Base__update__begin',$this, $fields_n_values, $query_params );
1289
+		do_action('AHEE__EEM_Base__update__begin', $this, $fields_n_values, $query_params);
1290 1290
 		/**
1291 1291
 		 * Filters the fields about to be updated given the query parameters. You can provide the
1292 1292
 		 * $query_params to $this->get_all() to find exactly which records will be updated
@@ -1294,10 +1294,10 @@  discard block
 block discarded – undo
1294 1294
 		 * @param EEM_Base $model the model being queried
1295 1295
 		 * @param array $query_params see EEM_Base::get_all()
1296 1296
 		 */
1297
-		$fields_n_values = apply_filters( 'FHEE__EEM_Base__update__fields_n_values', $fields_n_values, $this, $query_params );
1297
+		$fields_n_values = apply_filters('FHEE__EEM_Base__update__fields_n_values', $fields_n_values, $this, $query_params);
1298 1298
 		//need to verify that, for any entry we want to update, there are entries in each secondary table.
1299 1299
 		//to do that, for each table, verify that it's PK isn't null.
1300
-		$tables= $this->get_tables();
1300
+		$tables = $this->get_tables();
1301 1301
 
1302 1302
 		//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
1303 1303
 		//NOTE: we should make this code more efficient by NOT querying twice
@@ -1307,29 +1307,29 @@  discard block
 block discarded – undo
1307 1307
 			//we want to make sure the default_where strategy is ignored
1308 1308
 			$this->_ignore_where_strategy = TRUE;
1309 1309
 			$wpdb_select_results = $this->_get_all_wpdb_results($query_params);
1310
-			foreach( $wpdb_select_results as $wpdb_result ){
1310
+			foreach ($wpdb_select_results as $wpdb_result) {
1311 1311
 				// type cast stdClass as array
1312
-				$wpdb_result = (array)$wpdb_result;
1312
+				$wpdb_result = (array) $wpdb_result;
1313 1313
 				//get the model object's PK, as we'll want this if we need to insert a row into secondary tables
1314
-				if( $this->has_primary_key_field() ){
1315
-					$main_table_pk_value = $wpdb_result[ $this->get_primary_key_field()->get_qualified_column() ];
1316
-				}else{
1314
+				if ($this->has_primary_key_field()) {
1315
+					$main_table_pk_value = $wpdb_result[$this->get_primary_key_field()->get_qualified_column()];
1316
+				} else {
1317 1317
 					//if there's no primary key, we basically can't support having a 2nd table on the model (we could but it woudl be lots of work)
1318 1318
 					$main_table_pk_value = null;
1319 1319
 				}
1320 1320
 				//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
1321 1321
 				//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
1322
-				if(count($tables) > 1){
1322
+				if (count($tables) > 1) {
1323 1323
 					//foreach matching row in the DB, ensure that each table's PK isn't null. If so, there must not be an entry
1324 1324
 					//in that table, and so we'll want to insert one
1325
-					foreach($tables as $table_obj){
1325
+					foreach ($tables as $table_obj) {
1326 1326
 						$this_table_pk_column = $table_obj->get_fully_qualified_pk_column();
1327 1327
 						//if there is no private key for this table on the results, it means there's no entry
1328 1328
 						//in this table, right? so insert a row in the current table, using any fields available
1329
-						if( ! ( array_key_exists( $this_table_pk_column, $wpdb_result) && $wpdb_result[ $this_table_pk_column ] )){
1329
+						if ( ! (array_key_exists($this_table_pk_column, $wpdb_result) && $wpdb_result[$this_table_pk_column])) {
1330 1330
 							$success = $this->_insert_into_specific_table($table_obj, $fields_n_values, $main_table_pk_value);
1331 1331
 							//if we died here, report the error
1332
-							if( ! $success ) {
1332
+							if ( ! $success) {
1333 1333
 								return false;
1334 1334
 							}
1335 1335
 						}
@@ -1349,44 +1349,44 @@  discard block
 block discarded – undo
1349 1349
 		//if this wasn't called from a model object (to update itself)
1350 1350
 		//then we want to make sure we keep all the existing
1351 1351
 		//model objects in sync with the db
1352
-		if( $keep_model_objs_in_sync && ! $this->_values_already_prepared_by_model_object ){
1353
-			if( $this->has_primary_key_field() ){
1354
-				$model_objs_affected_ids = $this->get_col( $query_params );
1355
-			}else{
1352
+		if ($keep_model_objs_in_sync && ! $this->_values_already_prepared_by_model_object) {
1353
+			if ($this->has_primary_key_field()) {
1354
+				$model_objs_affected_ids = $this->get_col($query_params);
1355
+			} else {
1356 1356
 				//we need to select a bunch of columns and then combine them into the the "index primary key string"s
1357
-				$models_affected_key_columns = $this->_get_all_wpdb_results($query_params, ARRAY_A );
1357
+				$models_affected_key_columns = $this->_get_all_wpdb_results($query_params, ARRAY_A);
1358 1358
 				$model_objs_affected_ids = array();
1359
-				foreach( $models_affected_key_columns as $row ){
1360
-					$combined_index_key = $this->get_index_primary_key_string( $row );
1361
-					$model_objs_affected_ids[ $combined_index_key ] = $combined_index_key;
1359
+				foreach ($models_affected_key_columns as $row) {
1360
+					$combined_index_key = $this->get_index_primary_key_string($row);
1361
+					$model_objs_affected_ids[$combined_index_key] = $combined_index_key;
1362 1362
 				}
1363 1363
 
1364 1364
 			}
1365 1365
 
1366
-			if( ! $model_objs_affected_ids ){
1366
+			if ( ! $model_objs_affected_ids) {
1367 1367
 				//wait wait wait- if nothing was affected let's stop here
1368 1368
 				return 0;
1369 1369
 			}
1370
-			foreach( $model_objs_affected_ids as $id ){
1371
-				$model_obj_in_entity_map = $this->get_from_entity_map( $id );
1372
-				if( $model_obj_in_entity_map ){
1373
-					foreach( $fields_n_values as $field => $new_value ){
1374
-						$model_obj_in_entity_map->set( $field, $new_value );
1370
+			foreach ($model_objs_affected_ids as $id) {
1371
+				$model_obj_in_entity_map = $this->get_from_entity_map($id);
1372
+				if ($model_obj_in_entity_map) {
1373
+					foreach ($fields_n_values as $field => $new_value) {
1374
+						$model_obj_in_entity_map->set($field, $new_value);
1375 1375
 					}
1376 1376
 				}
1377 1377
 			}
1378 1378
 			//if there is a primary key on this model, we can now do a slight optimization
1379
-			if( $this->has_primary_key_field() ){
1379
+			if ($this->has_primary_key_field()) {
1380 1380
 				//we already know what we want to update. So let's make the query simpler so it's a little more efficient
1381 1381
 				$query_params = array(
1382
-					array( $this->primary_key_name() => array( 'IN', $model_objs_affected_ids ) ),
1383
-					'limit' => count( $model_objs_affected_ids ), 'default_where_conditions' => 'none' );
1382
+					array($this->primary_key_name() => array('IN', $model_objs_affected_ids)),
1383
+					'limit' => count($model_objs_affected_ids), 'default_where_conditions' => 'none' );
1384 1384
 			}
1385 1385
 		}
1386 1386
 
1387
-		$model_query_info = $this->_create_model_query_info_carrier( $query_params );
1388
-		$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.
1389
-		$rows_affected = $this->_do_wpdb_query('query', array( $SQL ) );
1387
+		$model_query_info = $this->_create_model_query_info_carrier($query_params);
1388
+		$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.
1389
+		$rows_affected = $this->_do_wpdb_query('query', array($SQL));
1390 1390
 		/**
1391 1391
 		 * Action called after a model update call has been made.
1392 1392
 		 *
@@ -1395,8 +1395,8 @@  discard block
 block discarded – undo
1395 1395
 		 * @param array $query_params @see EEM_Base::get_all()
1396 1396
 		 * @param int $rows_affected
1397 1397
 		 */
1398
-		do_action( 'AHEE__EEM_Base__update__end',$this, $fields_n_values, $query_params, $rows_affected );
1399
-		return $rows_affected;//how many supposedly got updated
1398
+		do_action('AHEE__EEM_Base__update__end', $this, $fields_n_values, $query_params, $rows_affected);
1399
+		return $rows_affected; //how many supposedly got updated
1400 1400
 	}
1401 1401
 
1402 1402
 	/**
@@ -1408,22 +1408,22 @@  discard block
 block discarded – undo
1408 1408
 	 * @param string $field_to_select
1409 1409
 	 * @return array just like $wpdb->get_col()
1410 1410
 	 */
1411
-	public function get_col( $query_params  = array(), $field_to_select = NULL ){
1411
+	public function get_col($query_params = array(), $field_to_select = NULL) {
1412 1412
 
1413
-		if( $field_to_select ){
1414
-			$field = $this->field_settings_for( $field_to_select );
1415
-		}elseif( $this->has_primary_key_field ( ) ){
1413
+		if ($field_to_select) {
1414
+			$field = $this->field_settings_for($field_to_select);
1415
+		}elseif ($this->has_primary_key_field( )) {
1416 1416
 			$field = $this->get_primary_key_field();
1417
-		}else{
1417
+		} else {
1418 1418
 			//no primary key, just grab the first column
1419
-			$field = reset( $this->field_settings());
1419
+			$field = reset($this->field_settings());
1420 1420
 		}
1421 1421
 
1422 1422
 
1423 1423
 		$model_query_info = $this->_create_model_query_info_carrier($query_params);
1424 1424
 		$select_expressions = $field->get_qualified_column();
1425
-		$SQL ="SELECT $select_expressions ".$this->_construct_2nd_half_of_select_query($model_query_info);
1426
-		$results =  $this->_do_wpdb_query('get_col', array( $SQL ) );
1425
+		$SQL = "SELECT $select_expressions ".$this->_construct_2nd_half_of_select_query($model_query_info);
1426
+		$results = $this->_do_wpdb_query('get_col', array($SQL));
1427 1427
 		return $results;
1428 1428
 	}
1429 1429
 
@@ -1433,12 +1433,12 @@  discard block
 block discarded – undo
1433 1433
 	 * @param string $field_to_select @see EEM_Base::get_col()
1434 1434
 	 * @return string
1435 1435
 	 */
1436
-	public function get_var( $query_params = array(), $field_to_select = NULL ) {
1437
-		$query_params[ 'limit' ] = 1;
1438
-		$col = $this->get_col( $query_params, $field_to_select );
1439
-		if( ! empty( $col ) ) {
1440
-			return reset( $col );
1441
-		}else{
1436
+	public function get_var($query_params = array(), $field_to_select = NULL) {
1437
+		$query_params['limit'] = 1;
1438
+		$col = $this->get_col($query_params, $field_to_select);
1439
+		if ( ! empty($col)) {
1440
+			return reset($col);
1441
+		} else {
1442 1442
 			return NULL;
1443 1443
 		}
1444 1444
 	}
@@ -1452,19 +1452,19 @@  discard block
 block discarded – undo
1452 1452
 	 * @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
1453 1453
 	 * @return string of SQL
1454 1454
 	 */
1455
-	function _construct_update_sql($fields_n_values){
1455
+	function _construct_update_sql($fields_n_values) {
1456 1456
 		/** @type WPDB $wpdb */
1457 1457
 		global $wpdb;
1458 1458
 		$cols_n_values = array();
1459
-		foreach($fields_n_values as $field_name => $value){
1459
+		foreach ($fields_n_values as $field_name => $value) {
1460 1460
 			$field_obj = $this->field_settings_for($field_name);
1461 1461
 			//if the value is NULL, we want to assign the value to that.
1462 1462
 			//wpdb->prepare doesn't really handle that properly
1463
-			$prepared_value = $this->_prepare_value_or_use_default( $field_obj, $fields_n_values );
1464
-			$value_sql = $prepared_value===NULL ? 'NULL' : $wpdb->prepare( $field_obj->get_wpdb_data_type(), $prepared_value );
1463
+			$prepared_value = $this->_prepare_value_or_use_default($field_obj, $fields_n_values);
1464
+			$value_sql = $prepared_value === NULL ? 'NULL' : $wpdb->prepare($field_obj->get_wpdb_data_type(), $prepared_value);
1465 1465
 			$cols_n_values[] = $field_obj->get_qualified_column()."=".$value_sql;
1466 1466
 		}
1467
-		return implode(",",$cols_n_values);
1467
+		return implode(",", $cols_n_values);
1468 1468
 
1469 1469
 	}
1470 1470
 
@@ -1476,11 +1476,11 @@  discard block
 block discarded – undo
1476 1476
 	 * @param mixed $id
1477 1477
 	 * @return boolean whether the row got deleted or not
1478 1478
 	 */
1479
-	public function delete_by_ID( $id ){
1480
-		return $this->delete( array(
1481
-			array( $this->get_primary_key_field()->get_name() => $id ),
1479
+	public function delete_by_ID($id) {
1480
+		return $this->delete(array(
1481
+			array($this->get_primary_key_field()->get_name() => $id),
1482 1482
 			'limit' 	=> 1
1483
-		) );
1483
+		));
1484 1484
 	}
1485 1485
 
1486 1486
 
@@ -1495,7 +1495,7 @@  discard block
 block discarded – undo
1495 1495
 	 * which may depend on it. Its generally advisable to always leave this as TRUE, otherwise you could easily corrupt your DB
1496 1496
 	 * @return int how many rows got deleted
1497 1497
 	 */
1498
-	function delete($query_params,$allow_blocking = true){
1498
+	function delete($query_params, $allow_blocking = true) {
1499 1499
 		/**
1500 1500
 		 * Action called just before performing a real deletion query. You can use the
1501 1501
 		 * model and its $query_params to find exactly which items will be deleted
@@ -1504,34 +1504,34 @@  discard block
 block discarded – undo
1504 1504
 		 * @param boolean $allow_blocking whether or not to allow related model objects
1505 1505
 		 * to block (prevent) this deletion
1506 1506
 		 */
1507
-		do_action( 'AHEE__EEM_Base__delete__begin', $this, $query_params, $allow_blocking );
1507
+		do_action('AHEE__EEM_Base__delete__begin', $this, $query_params, $allow_blocking);
1508 1508
 		//some MySQL databases may be running safe mode, which may restrict
1509 1509
 		//deletion if there is no KEY column used in the WHERE statement of a deletion.
1510 1510
 		//to get around this, we first do a SELECT, get all the IDs, and then run another query
1511 1511
 		//to delete them
1512 1512
 		$items_for_deletion = $this->_get_all_wpdb_results($query_params);
1513
-		$deletion_where = $this->_setup_ids_for_delete( $items_for_deletion, $allow_blocking);
1514
-		if($deletion_where){
1513
+		$deletion_where = $this->_setup_ids_for_delete($items_for_deletion, $allow_blocking);
1514
+		if ($deletion_where) {
1515 1515
 			//echo "objects for deletion:";var_dump($objects_for_deletion);
1516 1516
 			$model_query_info = $this->_create_model_query_info_carrier($query_params);
1517 1517
 			$table_aliases = array();
1518
-			foreach(array_keys($this->_tables) as $table_alias){
1518
+			foreach (array_keys($this->_tables) as $table_alias) {
1519 1519
 				$table_aliases[] = $table_alias;
1520 1520
 			}
1521
-			$SQL = "DELETE ".implode(", ",$table_aliases)." FROM ".$model_query_info->get_full_join_sql()." WHERE ".$deletion_where;
1521
+			$SQL = "DELETE ".implode(", ", $table_aliases)." FROM ".$model_query_info->get_full_join_sql()." WHERE ".$deletion_where;
1522 1522
 
1523 1523
 			//		/echo "delete sql:$SQL";
1524
-			$rows_deleted = $this->_do_wpdb_query( 'query', array( $SQL ) );
1525
-		}else{
1524
+			$rows_deleted = $this->_do_wpdb_query('query', array($SQL));
1525
+		} else {
1526 1526
 			$rows_deleted = 0;
1527 1527
 		}
1528 1528
 
1529 1529
 		//and lastly make sure those items are removed from the entity map; if they could be put into it at all
1530
-		if( $this->has_primary_key_field() ){
1531
-			foreach($items_for_deletion as $item_for_deletion_row ){
1532
-				$pk_value = $item_for_deletion_row[ $this->get_primary_key_field()->get_qualified_column() ];
1533
-				if( isset( $this->_entity_map[ $pk_value ] ) ){
1534
-					unset( $this->_entity_map[ $pk_value ] );
1530
+		if ($this->has_primary_key_field()) {
1531
+			foreach ($items_for_deletion as $item_for_deletion_row) {
1532
+				$pk_value = $item_for_deletion_row[$this->get_primary_key_field()->get_qualified_column()];
1533
+				if (isset($this->_entity_map[$pk_value])) {
1534
+					unset($this->_entity_map[$pk_value]);
1535 1535
 				}
1536 1536
 			}
1537 1537
 		}
@@ -1543,8 +1543,8 @@  discard block
 block discarded – undo
1543 1543
 		 * @param array $query_params @see EEM_Base::get_all()
1544 1544
 		 * @param int $rows_deleted
1545 1545
 		 */
1546
-		do_action( 'AHEE__EEM_Base__delete__end', $this, $query_params, $rows_deleted );
1547
-		return $rows_deleted;//how many supposedly got deleted
1546
+		do_action('AHEE__EEM_Base__delete__end', $this, $query_params, $rows_deleted);
1547
+		return $rows_deleted; //how many supposedly got deleted
1548 1548
 	}
1549 1549
 
1550 1550
 
@@ -1560,28 +1560,28 @@  discard block
 block discarded – undo
1560 1560
 	 * blocking its deletion before removing the relation between A and B
1561 1561
 	 * @return boolean
1562 1562
 	 */
1563
-	public function delete_is_blocked_by_related_models($this_model_obj_or_id, $ignore_this_model_obj = null){
1563
+	public function delete_is_blocked_by_related_models($this_model_obj_or_id, $ignore_this_model_obj = null) {
1564 1564
 		//first, if $ignore_this_model_obj was supplied, get its model
1565
-		if($ignore_this_model_obj && $ignore_this_model_obj instanceof EE_Base_Class){
1565
+		if ($ignore_this_model_obj && $ignore_this_model_obj instanceof EE_Base_Class) {
1566 1566
 			$ignored_model = $ignore_this_model_obj->get_model();
1567
-		}else{
1567
+		} else {
1568 1568
 			$ignored_model = null;
1569 1569
 		}
1570 1570
 		//now check all the relations of $this_model_obj_or_id and see if there
1571 1571
 		//are any related model objects blocking it?
1572 1572
 		$is_blocked = false;
1573
-		foreach($this->_model_relations as $relation_name => $relation_obj){
1574
-			if( $relation_obj->block_delete_if_related_models_exist()){
1573
+		foreach ($this->_model_relations as $relation_name => $relation_obj) {
1574
+			if ($relation_obj->block_delete_if_related_models_exist()) {
1575 1575
 				//if $ignore_this_model_obj was supplied, then for the query
1576 1576
 				//on that model needs to be told to ignore $ignore_this_model_obj
1577
-				if($ignored_model && $relation_name == $ignored_model->get_this_model_name()){
1578
-					$related_model_objects = $relation_obj->get_all_related($this_model_obj_or_id,array(
1579
-					array($ignored_model->get_primary_key_field()->get_name() => array('!=',$ignore_this_model_obj->ID()))));
1580
-				}else{
1577
+				if ($ignored_model && $relation_name == $ignored_model->get_this_model_name()) {
1578
+					$related_model_objects = $relation_obj->get_all_related($this_model_obj_or_id, array(
1579
+					array($ignored_model->get_primary_key_field()->get_name() => array('!=', $ignore_this_model_obj->ID()))));
1580
+				} else {
1581 1581
 					$related_model_objects = $relation_obj->get_all_related($this_model_obj_or_id);
1582 1582
 				}
1583 1583
 
1584
-				if($related_model_objects){
1584
+				if ($related_model_objects) {
1585 1585
 					EE_Error::add_error($relation_obj->get_deletion_error_message(), __FILE__, __FUNCTION__, __LINE__);
1586 1586
 					$is_blocked = true;
1587 1587
 				}
@@ -1601,65 +1601,65 @@  discard block
 block discarded – undo
1601 1601
 	 * @throws EE_Error
1602 1602
 	 * @return string    everything that comes after the WHERE statement.
1603 1603
 	 */
1604
-	protected function _setup_ids_for_delete( $objects_for_deletion, $allow_blocking = true) {
1605
-		if($this->has_primary_key_field()){
1604
+	protected function _setup_ids_for_delete($objects_for_deletion, $allow_blocking = true) {
1605
+		if ($this->has_primary_key_field()) {
1606 1606
 			$primary_table = $this->_get_main_table();
1607 1607
 			$other_tables = $this->_get_other_tables();
1608 1608
 			$deletes = $query = array();
1609
-			foreach ( $objects_for_deletion as $delete_object ) {
1609
+			foreach ($objects_for_deletion as $delete_object) {
1610 1610
 				//before we mark this object for deletion,
1611 1611
 				//make sure there's no related objects blocking its deletion (if we're checking)
1612
-				if( $allow_blocking && $this->delete_is_blocked_by_related_models($delete_object[$primary_table->get_fully_qualified_pk_column()]) ){
1612
+				if ($allow_blocking && $this->delete_is_blocked_by_related_models($delete_object[$primary_table->get_fully_qualified_pk_column()])) {
1613 1613
 					continue;
1614 1614
 				}
1615 1615
 
1616 1616
 				//primary table deletes
1617
-				if ( isset( $delete_object[$primary_table->get_fully_qualified_pk_column()] ) )
1617
+				if (isset($delete_object[$primary_table->get_fully_qualified_pk_column()]))
1618 1618
 					$deletes[$primary_table->get_fully_qualified_pk_column()][] = $delete_object[$primary_table->get_fully_qualified_pk_column()];
1619 1619
 
1620 1620
 				//other tables
1621
-				if ( !empty( $other_tables ) ) {
1622
-					foreach ( $other_tables as $ot ) {
1621
+				if ( ! empty($other_tables)) {
1622
+					foreach ($other_tables as $ot) {
1623 1623
 
1624 1624
 						//first check if we've got the foreign key column here.
1625
-						if ( isset( $delete_object[$ot->get_fully_qualified_fk_column()] ) )
1625
+						if (isset($delete_object[$ot->get_fully_qualified_fk_column()]))
1626 1626
 							$deletes[$ot->get_fully_qualified_pk_column()][] = $delete_object[$ot->get_fully_qualified_fk_column()];
1627 1627
 
1628 1628
 						//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
1629
-						if ( isset( $delete_object[$ot->get_fully_qualified_pk_column()] ) )
1629
+						if (isset($delete_object[$ot->get_fully_qualified_pk_column()]))
1630 1630
 							$deletes[$ot->get_fully_qualified_pk_column()][] = $delete_object[$ot->get_fully_qualified_pk_column()];
1631 1631
 
1632 1632
 						//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!
1633
-						if ( isset( $delete_object[$ot->get_fully_qualified_pk_on_fk_table()]) )
1633
+						if (isset($delete_object[$ot->get_fully_qualified_pk_on_fk_table()]))
1634 1634
 							$deletes[$ot->get_fully_qualified_pk_column()][] = $delete_object[$ot->get_fully_qualified_pk_column()];
1635 1635
 					}
1636 1636
 				}
1637 1637
 			}
1638 1638
 
1639 1639
 			//we should have deletes now, so let's just go through and setup the where statement
1640
-			foreach ( $deletes as $column => $values ) {
1640
+			foreach ($deletes as $column => $values) {
1641 1641
 				//make sure we have unique $values;
1642 1642
 				$values = array_unique($values);
1643
-				$query[] = $column . ' IN(' . implode(",",$values) . ')';
1643
+				$query[] = $column.' IN('.implode(",", $values).')';
1644 1644
 			}
1645 1645
 
1646
-			return !empty($query) ? implode(' AND ', $query ) : '';
1647
-		}elseif(count($this->get_combined_primary_key_fields()) > 1){
1646
+			return ! empty($query) ? implode(' AND ', $query) : '';
1647
+		}elseif (count($this->get_combined_primary_key_fields()) > 1) {
1648 1648
 			$ways_to_identify_a_row = array();
1649 1649
 			$fields = $this->get_combined_primary_key_fields();
1650 1650
 			//note: because there' sno primary key, that means nothing else  can be pointing to this model, right?
1651
-			foreach($objects_for_deletion as  $delete_object){
1651
+			foreach ($objects_for_deletion as  $delete_object) {
1652 1652
 				$values_for_each_cpk_for_a_row = array();
1653
-				foreach($fields as $cpk_field){
1653
+				foreach ($fields as $cpk_field) {
1654 1654
 					$values_for_each_cpk_for_a_row[] = $cpk_field->get_qualified_column()."=".$delete_object[$cpk_field->get_qualified_column()];
1655 1655
 				}
1656
-				$ways_to_identify_a_row[] = "(".implode(" AND ",$values_for_each_cpk_for_a_row).")";
1656
+				$ways_to_identify_a_row[] = "(".implode(" AND ", $values_for_each_cpk_for_a_row).")";
1657 1657
 			}
1658
-			return implode(" OR ",$ways_to_identify_a_row);
1659
-		}else{
1658
+			return implode(" OR ", $ways_to_identify_a_row);
1659
+		} else {
1660 1660
 			//so there's no primary key and no combined key...
1661 1661
 			//sorry, can't help you
1662
-			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)));
1662
+			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)));
1663 1663
 		}
1664 1664
 	}
1665 1665
 
@@ -1673,21 +1673,21 @@  discard block
 block discarded – undo
1673 1673
 	 * @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;
1674 1674
 	 * @return int
1675 1675
 	 */
1676
-	function count($query_params =array(),$field_to_count = NULL, $distinct = FALSE){
1676
+	function count($query_params = array(), $field_to_count = NULL, $distinct = FALSE) {
1677 1677
 		$model_query_info = $this->_create_model_query_info_carrier($query_params);
1678
-		if($field_to_count){
1678
+		if ($field_to_count) {
1679 1679
 			$field_obj = $this->field_settings_for($field_to_count);
1680 1680
 			$column_to_count = $field_obj->get_qualified_column();
1681
-		}elseif($this->has_primary_key_field ()){
1681
+		}elseif ($this->has_primary_key_field()) {
1682 1682
 			$pk_field_obj = $this->get_primary_key_field();
1683 1683
 			$column_to_count = $pk_field_obj->get_qualified_column();
1684
-		}else{//there's no primary key
1684
+		} else {//there's no primary key
1685 1685
 			$column_to_count = '*';
1686 1686
 		}
1687 1687
 
1688
-		$column_to_count = $distinct ? "DISTINCT (" . $column_to_count . " )" : $column_to_count;
1689
-		$SQL ="SELECT COUNT(".$column_to_count.")" . $this->_construct_2nd_half_of_select_query($model_query_info);
1690
-		return (int)$this->_do_wpdb_query( 'get_var', array( $SQL) );
1688
+		$column_to_count = $distinct ? "DISTINCT (".$column_to_count." )" : $column_to_count;
1689
+		$SQL = "SELECT COUNT(".$column_to_count.")".$this->_construct_2nd_half_of_select_query($model_query_info);
1690
+		return (int) $this->_do_wpdb_query('get_var', array($SQL));
1691 1691
 	}
1692 1692
 
1693 1693
 	/**
@@ -1697,23 +1697,23 @@  discard block
 block discarded – undo
1697 1697
 	 * @param string $field_to_sum name of field (array key in $_fields array)
1698 1698
 	 * @return float
1699 1699
 	 */
1700
-	function sum($query_params, $field_to_sum = NULL){
1700
+	function sum($query_params, $field_to_sum = NULL) {
1701 1701
 		$model_query_info = $this->_create_model_query_info_carrier($query_params);
1702 1702
 
1703
-		if($field_to_sum){
1703
+		if ($field_to_sum) {
1704 1704
 			$field_obj = $this->field_settings_for($field_to_sum);
1705 1705
 
1706
-		}else{
1706
+		} else {
1707 1707
 			$field_obj = $this->get_primary_key_field();
1708 1708
 		}
1709 1709
 		$column_to_count = $field_obj->get_qualified_column();
1710 1710
 
1711
-		$SQL ="SELECT SUM(".$column_to_count.")" . $this->_construct_2nd_half_of_select_query($model_query_info);
1712
-		$return_value = $this->_do_wpdb_query('get_var',array( $SQL ) );
1713
-		if($field_obj->get_wpdb_data_type() == '%d' || $field_obj->get_wpdb_data_type() == '%s' ){
1714
-			return (float)$return_value;
1715
-		}else{//must be %f
1716
-			return (float)$return_value;
1711
+		$SQL = "SELECT SUM(".$column_to_count.")".$this->_construct_2nd_half_of_select_query($model_query_info);
1712
+		$return_value = $this->_do_wpdb_query('get_var', array($SQL));
1713
+		if ($field_obj->get_wpdb_data_type() == '%d' || $field_obj->get_wpdb_data_type() == '%s') {
1714
+			return (float) $return_value;
1715
+		} else {//must be %f
1716
+			return (float) $return_value;
1717 1717
 		}
1718 1718
 	}
1719 1719
 
@@ -1728,33 +1728,33 @@  discard block
 block discarded – undo
1728 1728
 	 * @global wpdb $wpdb
1729 1729
 	 * @return mixed
1730 1730
 	 */
1731
-	protected function _do_wpdb_query( $wpdb_method, $arguments_to_provide ){
1731
+	protected function _do_wpdb_query($wpdb_method, $arguments_to_provide) {
1732 1732
 		//if we're in maintenance mode level 2, DON'T run any queries
1733 1733
 		//because level 2 indicates the database needs updating and
1734 1734
 		//is probably out of sync with the code
1735
-		if( ! EE_Maintenance_Mode::instance()->models_can_query()){
1735
+		if ( ! EE_Maintenance_Mode::instance()->models_can_query()) {
1736 1736
 			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")));
1737 1737
 		}
1738 1738
 		/** @type WPDB $wpdb */
1739 1739
 		global $wpdb;
1740
-		if( ! method_exists( $wpdb, $wpdb_method ) ){
1741
-			throw new EE_Error( sprintf( __( 'There is no method named "%s" on Wordpress\' $wpdb object','event_espresso' ), $wpdb_method ) );
1740
+		if ( ! method_exists($wpdb, $wpdb_method)) {
1741
+			throw new EE_Error(sprintf(__('There is no method named "%s" on Wordpress\' $wpdb object', 'event_espresso'), $wpdb_method));
1742 1742
 		}
1743
-		if( WP_DEBUG ){
1743
+		if (WP_DEBUG) {
1744 1744
 			$old_show_errors_value = $wpdb->show_errors;
1745
-			$wpdb->show_errors( FALSE );
1746
-		}
1747
-		$result = $this->_process_wpdb_query( $wpdb_method, $arguments_to_provide );
1748
-		$this->show_db_query_if_previously_requested( $wpdb->last_query );
1749
-		if( WP_DEBUG ){
1750
-			$wpdb->show_errors( $old_show_errors_value );
1751
-			if( ! empty( $wpdb->last_error ) ){
1752
-				throw new EE_Error( sprintf( __( 'WPDB Error: "%s"', 'event_espresso' ), $wpdb->last_error ) );
1753
-			}elseif( $result === false ){
1754
-				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 ) ) );
1745
+			$wpdb->show_errors(FALSE);
1746
+		}
1747
+		$result = $this->_process_wpdb_query($wpdb_method, $arguments_to_provide);
1748
+		$this->show_db_query_if_previously_requested($wpdb->last_query);
1749
+		if (WP_DEBUG) {
1750
+			$wpdb->show_errors($old_show_errors_value);
1751
+			if ( ! empty($wpdb->last_error)) {
1752
+				throw new EE_Error(sprintf(__('WPDB Error: "%s"', 'event_espresso'), $wpdb->last_error));
1753
+			}elseif ($result === false) {
1754
+				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)));
1755 1755
 			}
1756
-		}elseif( $result === false ) {
1757
-			EE_Error::add_error( sprintf( __( 'A database error has occurred. Turn on WP_DEBUG for more information.', 'event_espresso' )), __FILE__, __FUNCTION__, __LINE__);
1756
+		}elseif ($result === false) {
1757
+			EE_Error::add_error(sprintf(__('A database error has occurred. Turn on WP_DEBUG for more information.', 'event_espresso')), __FILE__, __FUNCTION__, __LINE__);
1758 1758
 		}
1759 1759
 		return $result;
1760 1760
 	}
@@ -1770,23 +1770,23 @@  discard block
 block discarded – undo
1770 1770
 	 * @param array $arguments_to_provide
1771 1771
 	 * @return mixed
1772 1772
 	 */
1773
-	private function _process_wpdb_query( $wpdb_method, $arguments_to_provide ) {
1773
+	private function _process_wpdb_query($wpdb_method, $arguments_to_provide) {
1774 1774
 		/** @type WPDB $wpdb */
1775 1775
 		global $wpdb;
1776 1776
 		$wpdb->last_error = null;
1777
-		$result = call_user_func_array( array( $wpdb, $wpdb_method ), $arguments_to_provide );
1777
+		$result = call_user_func_array(array($wpdb, $wpdb_method), $arguments_to_provide);
1778 1778
 		// was there an error running the query?
1779
-		if ( ( $result === false || ! empty( $wpdb->last_error ) ) ) {
1780
-			switch ( EEM_Base::$_db_verification_level ) {
1779
+		if (($result === false || ! empty($wpdb->last_error))) {
1780
+			switch (EEM_Base::$_db_verification_level) {
1781 1781
 
1782 1782
 				case EEM_Base::db_verified_none :
1783 1783
 					// let's double-check core's DB
1784
-					$error_message = $this->_verify_core_db( $wpdb_method, $arguments_to_provide );
1784
+					$error_message = $this->_verify_core_db($wpdb_method, $arguments_to_provide);
1785 1785
 					break;
1786 1786
 
1787 1787
 				case EEM_Base::db_verified_core :
1788 1788
 					// STILL NO LOVE?? verify all the addons too. Maybe they need to be fixed
1789
-					$error_message = $this->_verify_addons_db( $wpdb_method, $arguments_to_provide );
1789
+					$error_message = $this->_verify_addons_db($wpdb_method, $arguments_to_provide);
1790 1790
 					break;
1791 1791
 
1792 1792
 				case EEM_Base::db_verified_addons :
@@ -1794,11 +1794,11 @@  discard block
 block discarded – undo
1794 1794
 					return $result;
1795 1795
 					break;
1796 1796
 			}
1797
-			if ( ! empty( $error_message ) ) {
1798
-				EE_Log::instance()->log( __FILE__, __FUNCTION__, $error_message, 'error' );
1799
-				trigger_error( $error_message );
1797
+			if ( ! empty($error_message)) {
1798
+				EE_Log::instance()->log(__FILE__, __FUNCTION__, $error_message, 'error');
1799
+				trigger_error($error_message);
1800 1800
 			}
1801
-			return $this->_process_wpdb_query( $wpdb_method, $arguments_to_provide );
1801
+			return $this->_process_wpdb_query($wpdb_method, $arguments_to_provide);
1802 1802
 
1803 1803
 		}
1804 1804
 
@@ -1814,18 +1814,18 @@  discard block
 block discarded – undo
1814 1814
 	 * @param array $arguments_to_provide
1815 1815
 	 * @return string
1816 1816
 	 */
1817
-	private function _verify_core_db( $wpdb_method, $arguments_to_provide ){
1817
+	private function _verify_core_db($wpdb_method, $arguments_to_provide) {
1818 1818
 		/** @type WPDB $wpdb */
1819 1819
 		global $wpdb;
1820 1820
 		//ok remember that we've already attempted fixing the core db, in case the problem persists
1821 1821
 		EEM_Base::$_db_verification_level = EEM_Base::db_verified_core;
1822 1822
 		$error_message = sprintf(
1823
-			__( 'WPDB Error "%1$s" while running wpdb method "%2$s" with arguments %3$s. Automatically attempting to fix EE Core DB', 'event_espresso' ),
1823
+			__('WPDB Error "%1$s" while running wpdb method "%2$s" with arguments %3$s. Automatically attempting to fix EE Core DB', 'event_espresso'),
1824 1824
 			$wpdb->last_error,
1825 1825
 			$wpdb_method,
1826
-			json_encode( $arguments_to_provide )
1826
+			json_encode($arguments_to_provide)
1827 1827
 		);
1828
-		EE_System::instance()->initialize_db_if_no_migrations_required( false, true );
1828
+		EE_System::instance()->initialize_db_if_no_migrations_required(false, true);
1829 1829
 		return $error_message;
1830 1830
 	}
1831 1831
 
@@ -1838,16 +1838,16 @@  discard block
 block discarded – undo
1838 1838
 	 * @param $arguments_to_provide
1839 1839
 	 * @return string
1840 1840
 	 */
1841
-	private function _verify_addons_db( $wpdb_method, $arguments_to_provide ) {
1841
+	private function _verify_addons_db($wpdb_method, $arguments_to_provide) {
1842 1842
 		/** @type WPDB $wpdb */
1843 1843
 		global $wpdb;
1844 1844
 		//ok remember that we've already attempted fixing the addons dbs, in case the problem persists
1845 1845
 		EEM_Base::$_db_verification_level = EEM_Base::db_verified_addons;
1846 1846
 		$error_message = sprintf(
1847
-			__( 'WPDB AGAIN: Error "%1$s" while running the same method and arguments as before. Automatically attempting to fix EE Addons DB', 'event_espresso' ),
1847
+			__('WPDB AGAIN: Error "%1$s" while running the same method and arguments as before. Automatically attempting to fix EE Addons DB', 'event_espresso'),
1848 1848
 			$wpdb->last_error,
1849 1849
 			$wpdb_method,
1850
-			json_encode( $arguments_to_provide )
1850
+			json_encode($arguments_to_provide)
1851 1851
 		);
1852 1852
 		EE_System::instance()->initialize_addons();
1853 1853
 		return $error_message;
@@ -1862,7 +1862,7 @@  discard block
 block discarded – undo
1862 1862
 	 * @param EE_Model_Query_Info_Carrier $model_query_info
1863 1863
 	 * @return string
1864 1864
 	 */
1865
-	private function _construct_2nd_half_of_select_query(EE_Model_Query_Info_Carrier $model_query_info){
1865
+	private function _construct_2nd_half_of_select_query(EE_Model_Query_Info_Carrier $model_query_info) {
1866 1866
 		return " FROM ".$model_query_info->get_full_join_sql().
1867 1867
 				$model_query_info->get_where_sql().
1868 1868
 				$model_query_info->get_group_by_sql().
@@ -1875,7 +1875,7 @@  discard block
 block discarded – undo
1875 1875
 	 * Set to easily debug the next X queries ran from this model.
1876 1876
 	 * @param int $count
1877 1877
 	 */
1878
-	function show_next_x_db_queries($count = 1){
1878
+	function show_next_x_db_queries($count = 1) {
1879 1879
 		$this->_show_next_x_db_queries = $count;
1880 1880
 	}
1881 1881
 
@@ -1884,8 +1884,8 @@  discard block
 block discarded – undo
1884 1884
 	/**
1885 1885
 	 * @param $sql_query
1886 1886
 	 */
1887
-	function show_db_query_if_previously_requested($sql_query){
1888
-		if($this->_show_next_x_db_queries > 0){
1887
+	function show_db_query_if_previously_requested($sql_query) {
1888
+		if ($this->_show_next_x_db_queries > 0) {
1889 1889
 			echo $sql_query;
1890 1890
 			$this->_show_next_x_db_queries--;
1891 1891
 		}
@@ -1909,7 +1909,7 @@  discard block
 block discarded – undo
1909 1909
 	 * @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.
1910 1910
 	 * @return EE_Base_Class which was added as a relation. Object referred to by $other_model_id_or_obj
1911 1911
 	 */
1912
-	public function add_relationship_to($id_or_obj,$other_model_id_or_obj, $relationName, $extra_join_model_fields_n_values = array()){
1912
+	public function add_relationship_to($id_or_obj, $other_model_id_or_obj, $relationName, $extra_join_model_fields_n_values = array()) {
1913 1913
 		$relation_obj = $this->related_settings_for($relationName);
1914 1914
 		return $relation_obj->add_relation_to($id_or_obj, $other_model_id_or_obj, $extra_join_model_fields_n_values);
1915 1915
 	}
@@ -1930,9 +1930,9 @@  discard block
 block discarded – undo
1930 1930
 	 * @return boolean of success
1931 1931
 	 * @param array   $where_query This allows you to enter further query params for the relation to for relation to methods that allow you to further specify extra columns to join by (such as HABTM).  Keep in mind that the only acceptable query_params is strict "col" => "value" pairs because these will be inserted in any new rows created as well.
1932 1932
 	 */
1933
-	public function remove_relationship_to($id_or_obj,  $other_model_id_or_obj, $relationName, $where_query= array() ){
1933
+	public function remove_relationship_to($id_or_obj, $other_model_id_or_obj, $relationName, $where_query = array()) {
1934 1934
 		$relation_obj = $this->related_settings_for($relationName);
1935
-		return $relation_obj->remove_relation_to($id_or_obj, $other_model_id_or_obj, $where_query );
1935
+		return $relation_obj->remove_relation_to($id_or_obj, $other_model_id_or_obj, $where_query);
1936 1936
 	}
1937 1937
 
1938 1938
 
@@ -1945,9 +1945,9 @@  discard block
 block discarded – undo
1945 1945
 	 * @param EE_Base_Class[] objects to which relations were removed
1946 1946
 	 * @return \EE_Base_Class[]
1947 1947
 	 */
1948
-	public function remove_relations($id_or_obj,$relationName,$where_query_params = array()){
1948
+	public function remove_relations($id_or_obj, $relationName, $where_query_params = array()) {
1949 1949
 		$relation_obj = $this->related_settings_for($relationName);
1950
-		return $relation_obj->remove_relations($id_or_obj, $where_query_params );
1950
+		return $relation_obj->remove_relations($id_or_obj, $where_query_params);
1951 1951
 	}
1952 1952
 
1953 1953
 
@@ -1960,10 +1960,10 @@  discard block
 block discarded – undo
1960 1960
 	 * @param array $query_params like EEM_Base::get_all
1961 1961
 	 * @return EE_Base_Class[]
1962 1962
 	 */
1963
-	function get_all_related($id_or_obj, $model_name, $query_params = null){
1963
+	function get_all_related($id_or_obj, $model_name, $query_params = null) {
1964 1964
 		$model_obj = $this->ensure_is_obj($id_or_obj);
1965 1965
 		$relation_settings = $this->related_settings_for($model_name);
1966
-		return $relation_settings->get_all_related($model_obj,$query_params);
1966
+		return $relation_settings->get_all_related($model_obj, $query_params);
1967 1967
 	}
1968 1968
 
1969 1969
 	/**
@@ -1976,10 +1976,10 @@  discard block
 block discarded – undo
1976 1976
 	 * @param array $query_params
1977 1977
 	 * @return int how many deleted
1978 1978
 	 */
1979
-	public function delete_related($id_or_obj,$model_name, $query_params = array()){
1979
+	public function delete_related($id_or_obj, $model_name, $query_params = array()) {
1980 1980
 		$model_obj = $this->ensure_is_obj($id_or_obj);
1981 1981
 		$relation_settings = $this->related_settings_for($model_name);
1982
-		return $relation_settings->delete_all_related($model_obj,$query_params);
1982
+		return $relation_settings->delete_all_related($model_obj, $query_params);
1983 1983
 	}
1984 1984
 
1985 1985
 	/**
@@ -1992,10 +1992,10 @@  discard block
 block discarded – undo
1992 1992
 	 * @param array $query_params
1993 1993
 	 * @return int how many deleted
1994 1994
 	 */
1995
-	public function delete_related_permanently($id_or_obj,$model_name, $query_params = array()){
1995
+	public function delete_related_permanently($id_or_obj, $model_name, $query_params = array()) {
1996 1996
 		$model_obj = $this->ensure_is_obj($id_or_obj);
1997 1997
 		$relation_settings = $this->related_settings_for($model_name);
1998
-		return $relation_settings->delete_related_permanently($model_obj,$query_params);
1998
+		return $relation_settings->delete_related_permanently($model_obj, $query_params);
1999 1999
 	}
2000 2000
 
2001 2001
 	/**
@@ -2008,17 +2008,17 @@  discard block
 block discarded – undo
2008 2008
 	 * @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;
2009 2009
 	 * @return int
2010 2010
 	 */
2011
-	function count_related($id_or_obj,$model_name,$query_params = array(),$field_to_count = null, $distinct = FALSE){
2011
+	function count_related($id_or_obj, $model_name, $query_params = array(), $field_to_count = null, $distinct = FALSE) {
2012 2012
 		$related_model = $this->get_related_model_obj($model_name);
2013 2013
 		//we're just going to use the query params on the related model's normal get_all query,
2014 2014
 		//except add a condition to say to match the current mod
2015
-		if( ! isset($query_params['default_where_conditions'])){
2016
-			$query_params['default_where_conditions']='none';
2015
+		if ( ! isset($query_params['default_where_conditions'])) {
2016
+			$query_params['default_where_conditions'] = 'none';
2017 2017
 		}
2018 2018
 		$this_model_name = $this->get_this_model_name();
2019 2019
 		$this_pk_field_name = $this->get_primary_key_field()->get_name();
2020
-		$query_params[0][$this_model_name.".".$this_pk_field_name]=$id_or_obj;
2021
-		return $related_model->count($query_params,$field_to_count,$distinct);
2020
+		$query_params[0][$this_model_name.".".$this_pk_field_name] = $id_or_obj;
2021
+		return $related_model->count($query_params, $field_to_count, $distinct);
2022 2022
 	}
2023 2023
 
2024 2024
 
@@ -2032,21 +2032,21 @@  discard block
 block discarded – undo
2032 2032
 	 * @param string $field_to_sum name of field to count by. By default, uses primary key
2033 2033
 	 * @return float
2034 2034
 	 */
2035
-	function sum_related($id_or_obj,$model_name,$query_params,$field_to_sum = null){
2035
+	function sum_related($id_or_obj, $model_name, $query_params, $field_to_sum = null) {
2036 2036
 		$related_model = $this->get_related_model_obj($model_name);
2037
-		if( ! is_array( $query_params ) ){
2038
-			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' );
2037
+		if ( ! is_array($query_params)) {
2038
+			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');
2039 2039
 			$query_params = array();
2040 2040
 		}
2041 2041
 		//we're just going to use the query params on the related model's normal get_all query,
2042 2042
 		//except add a condition to say to match the current mod
2043
-		if( ! isset($query_params['default_where_conditions'])){
2044
-			$query_params['default_where_conditions']='none';
2043
+		if ( ! isset($query_params['default_where_conditions'])) {
2044
+			$query_params['default_where_conditions'] = 'none';
2045 2045
 		}
2046 2046
 		$this_model_name = $this->get_this_model_name();
2047 2047
 		$this_pk_field_name = $this->get_primary_key_field()->get_name();
2048
-		$query_params[0][$this_model_name.".".$this_pk_field_name]=$id_or_obj;
2049
-		return $related_model->sum($query_params,$field_to_sum);
2048
+		$query_params[0][$this_model_name.".".$this_pk_field_name] = $id_or_obj;
2049
+		return $related_model->sum($query_params, $field_to_sum);
2050 2050
 	}
2051 2051
 
2052 2052
 
@@ -2058,12 +2058,12 @@  discard block
 block discarded – undo
2058 2058
 	 * @param array $query_params like EEM_Base::get_all's
2059 2059
 	 * @return EE_Base_Class
2060 2060
 	 */
2061
-	public function get_first_related( EE_Base_Class $id_or_obj, $other_model_name, $query_params ){
2062
-		$query_params['limit']=1;
2063
-		$results = $this->get_all_related($id_or_obj,$other_model_name,$query_params);
2064
-		if( $results ){
2061
+	public function get_first_related(EE_Base_Class $id_or_obj, $other_model_name, $query_params) {
2062
+		$query_params['limit'] = 1;
2063
+		$results = $this->get_all_related($id_or_obj, $other_model_name, $query_params);
2064
+		if ($results) {
2065 2065
 			return array_shift($results);
2066
-		}else{
2066
+		} else {
2067 2067
 			return null;
2068 2068
 		}
2069 2069
 
@@ -2073,8 +2073,8 @@  discard block
 block discarded – undo
2073 2073
 	 * Gets the model's name as it's expected in queries. For example, if this is EEM_Event model, that would be Event
2074 2074
 	 * @return string
2075 2075
 	 */
2076
-	function get_this_model_name(){
2077
-		return str_replace("EEM_","",get_class($this));
2076
+	function get_this_model_name() {
2077
+		return str_replace("EEM_", "", get_class($this));
2078 2078
 	}
2079 2079
 
2080 2080
 	/**
@@ -2082,14 +2082,14 @@  discard block
 block discarded – undo
2082 2082
 	 * @return EE_Any_Foreign_Model_Name_Field
2083 2083
 	 * @throws EE_Error
2084 2084
 	 */
2085
-	public function get_field_containing_related_model_name(){
2086
-		foreach($this->field_settings(true) as $field){
2087
-			if($field instanceof EE_Any_Foreign_Model_Name_Field){
2085
+	public function get_field_containing_related_model_name() {
2086
+		foreach ($this->field_settings(true) as $field) {
2087
+			if ($field instanceof EE_Any_Foreign_Model_Name_Field) {
2088 2088
 				$field_with_model_name = $field;
2089 2089
 			}
2090 2090
 		}
2091
-		if( !isset($field_with_model_name) || !$field_with_model_name ){
2092
-			throw new EE_Error(sprintf(__("There is no EE_Any_Foreign_Model_Name field on model %s", "event_espresso"), $this->get_this_model_name() ));
2091
+		if ( ! isset($field_with_model_name) || ! $field_with_model_name) {
2092
+			throw new EE_Error(sprintf(__("There is no EE_Any_Foreign_Model_Name field on model %s", "event_espresso"), $this->get_this_model_name()));
2093 2093
 		}
2094 2094
 		return $field_with_model_name;
2095 2095
 	}
@@ -2110,19 +2110,19 @@  discard block
 block discarded – undo
2110 2110
 	 * @return int new primary key on main table that got inserted
2111 2111
 	 * @throws EE_Error
2112 2112
 	 */
2113
-	function insert($field_n_values){
2113
+	function insert($field_n_values) {
2114 2114
 		/**
2115 2115
 		 * Filters the fields and their values before inserting an item using the models
2116 2116
 		 * @param array $fields_n_values keys are the fields and values are their new values
2117 2117
 		 * @param EEM_Base $model the model used
2118 2118
 		 */
2119
-		$field_n_values = apply_filters( 'FHEE__EEM_Base__insert__fields_n_values', $field_n_values, $this );
2120
-		if($this->_satisfies_unique_indexes($field_n_values)){
2119
+		$field_n_values = apply_filters('FHEE__EEM_Base__insert__fields_n_values', $field_n_values, $this);
2120
+		if ($this->_satisfies_unique_indexes($field_n_values)) {
2121 2121
 			$main_table = $this->_get_main_table();
2122 2122
 			$new_id = $this->_insert_into_specific_table($main_table, $field_n_values, false);
2123
-			if( $new_id !== false ) {
2124
-				foreach($this->_get_other_tables() as $other_table){
2125
-					$this->_insert_into_specific_table($other_table, $field_n_values,$new_id);
2123
+			if ($new_id !== false) {
2124
+				foreach ($this->_get_other_tables() as $other_table) {
2125
+					$this->_insert_into_specific_table($other_table, $field_n_values, $new_id);
2126 2126
 				}
2127 2127
 			}
2128 2128
 			/**
@@ -2132,9 +2132,9 @@  discard block
 block discarded – undo
2132 2132
 			 * @param array $fields_n_values fields and their values
2133 2133
 			 * @param int|string the ID of the newly-inserted model object
2134 2134
 			 */
2135
-			do_action( 'AHEE__EEM_Base__insert__end', $this, $field_n_values, $new_id );
2135
+			do_action('AHEE__EEM_Base__insert__end', $this, $field_n_values, $new_id);
2136 2136
 			return $new_id;
2137
-		}else{
2137
+		} else {
2138 2138
 			return FALSE;
2139 2139
 		}
2140 2140
 	}
@@ -2147,11 +2147,11 @@  discard block
 block discarded – undo
2147 2147
 	 * @param string $action
2148 2148
 	 * @return boolean
2149 2149
 	 */
2150
-	protected function _satisfies_unique_indexes($field_n_values,$action = 'insert'){
2151
-		foreach($this->unique_indexes() as $index_name => $index){
2150
+	protected function _satisfies_unique_indexes($field_n_values, $action = 'insert') {
2151
+		foreach ($this->unique_indexes() as $index_name => $index) {
2152 2152
 			$uniqueness_where_params = array_intersect_key($field_n_values, $index->fields());
2153
-			if($this->exists(array($uniqueness_where_params))){
2154
-				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__ );
2153
+			if ($this->exists(array($uniqueness_where_params))) {
2154
+				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__);
2155 2155
 				return false;
2156 2156
 			}
2157 2157
 		}
@@ -2172,28 +2172,28 @@  discard block
 block discarded – undo
2172 2172
 	 * @throws EE_Error
2173 2173
 	 * @return EE_Base_Class
2174 2174
 	 */
2175
-	public function get_one_conflicting($obj_or_fields_array, $include_primary_key = true ){
2176
-		if($obj_or_fields_array instanceof EE_Base_Class){
2175
+	public function get_one_conflicting($obj_or_fields_array, $include_primary_key = true) {
2176
+		if ($obj_or_fields_array instanceof EE_Base_Class) {
2177 2177
 			$fields_n_values = $obj_or_fields_array->model_field_array();
2178
-		}elseif( is_array($obj_or_fields_array)){
2178
+		}elseif (is_array($obj_or_fields_array)) {
2179 2179
 			$fields_n_values = $obj_or_fields_array;
2180
-		}else{
2181
-			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));
2180
+		} else {
2181
+			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));
2182 2182
 		}
2183 2183
 		$query_params = array();
2184
-		if( $this->has_primary_key_field() &&
2185
-				( $include_primary_key || $this->get_primary_key_field() instanceof EE_Primary_Key_String_Field) &&
2186
-				isset($fields_n_values[$this->primary_key_name()])){
2184
+		if ($this->has_primary_key_field() &&
2185
+				($include_primary_key || $this->get_primary_key_field() instanceof EE_Primary_Key_String_Field) &&
2186
+				isset($fields_n_values[$this->primary_key_name()])) {
2187 2187
 			$query_params[0]['OR'][$this->primary_key_name()] = $fields_n_values[$this->primary_key_name()];
2188 2188
 		}
2189
-		foreach($this->unique_indexes() as $unique_index_name=>$unique_index){
2189
+		foreach ($this->unique_indexes() as $unique_index_name=>$unique_index) {
2190 2190
 			$uniqueness_where_params = array_intersect_key($fields_n_values, $unique_index->fields());
2191 2191
 			$query_params[0]['OR']['AND*'.$unique_index_name] = $uniqueness_where_params;
2192 2192
 		}
2193 2193
 		//if there is nothing to base this search on, then we shouldn't find anything
2194
-		if( empty( $query_params ) ){
2194
+		if (empty($query_params)) {
2195 2195
 			return array();
2196
-		}else{
2196
+		} else {
2197 2197
 			return $this->get_one($query_params);
2198 2198
 		}
2199 2199
 	}
@@ -2203,7 +2203,7 @@  discard block
 block discarded – undo
2203 2203
 	 * @param array $query_params
2204 2204
 	 * @return boolean
2205 2205
 	 */
2206
-	function exists($query_params){
2206
+	function exists($query_params) {
2207 2207
 		$query_params['limit'] = 1;
2208 2208
 		return $this->count($query_params) > 0;
2209 2209
 	}
@@ -2213,7 +2213,7 @@  discard block
 block discarded – undo
2213 2213
 	 * @param int|string $id
2214 2214
 	 * @return boolean
2215 2215
 	 */
2216
-	function exists_by_ID($id){
2216
+	function exists_by_ID($id) {
2217 2217
 		return $this->exists(array('default_where_conditions'=>'none', array($this->primary_key_name() => $id)));
2218 2218
 	}
2219 2219
 
@@ -2233,45 +2233,45 @@  discard block
 block discarded – undo
2233 2233
 	 * @global WPDB $wpdb only used to get the $wpdb->insert_id after performing an insert
2234 2234
 	 * @return int ID of new row inserted, or FALSE on failure
2235 2235
 	 */
2236
-	protected function _insert_into_specific_table(EE_Table_Base $table, $fields_n_values, $new_id = 0 ){
2236
+	protected function _insert_into_specific_table(EE_Table_Base $table, $fields_n_values, $new_id = 0) {
2237 2237
 		global $wpdb;
2238 2238
 		$insertion_col_n_values = array();
2239 2239
 		$format_for_insertion = array();
2240 2240
 		$fields_on_table = $this->_get_fields_for_table($table->get_table_alias());
2241
-		foreach($fields_on_table as $field_name => $field_obj){
2241
+		foreach ($fields_on_table as $field_name => $field_obj) {
2242 2242
 			//check if its an auto-incrementing column, in which case we should just leave it to do its autoincrement thing
2243
-			if($field_obj->is_auto_increment()){
2243
+			if ($field_obj->is_auto_increment()) {
2244 2244
 				continue;
2245 2245
 			}
2246 2246
 			$prepared_value = $this->_prepare_value_or_use_default($field_obj, $fields_n_values);
2247 2247
 			//if the value we want to assign it to is NULL, just don't mention it for the insertion
2248
-			if( $prepared_value !== NULL ){
2249
-				$insertion_col_n_values[ $field_obj->get_table_column() ] = $prepared_value;
2248
+			if ($prepared_value !== NULL) {
2249
+				$insertion_col_n_values[$field_obj->get_table_column()] = $prepared_value;
2250 2250
 				$format_for_insertion[] = $field_obj->get_wpdb_data_type();
2251 2251
 			}
2252 2252
 		}
2253 2253
 
2254
-		if($table instanceof EE_Secondary_Table && $new_id){
2254
+		if ($table instanceof EE_Secondary_Table && $new_id) {
2255 2255
 			//its not the main table, so we should have already saved the main table's PK which we just inserted
2256 2256
 			//so add the fk to the main table as a column
2257 2257
 			$insertion_col_n_values[$table->get_fk_on_table()] = $new_id;
2258
-			$format_for_insertion[]='%d';//yes right now we're only allowing these foreign keys to be INTs
2258
+			$format_for_insertion[] = '%d'; //yes right now we're only allowing these foreign keys to be INTs
2259 2259
 		}
2260 2260
 		//insert the new entry
2261
-		$result = $this->_do_wpdb_query( 'insert', array( $table->get_table_name(), $insertion_col_n_values, $format_for_insertion ) );
2262
-		if( $result === false ) {
2261
+		$result = $this->_do_wpdb_query('insert', array($table->get_table_name(), $insertion_col_n_values, $format_for_insertion));
2262
+		if ($result === false) {
2263 2263
 			return false;
2264 2264
 		}
2265 2265
 		//ok, now what do we return for the ID of the newly-inserted thing?
2266
-		if($this->has_primary_key_field()){
2267
-			if($this->get_primary_key_field()->is_auto_increment()){
2266
+		if ($this->has_primary_key_field()) {
2267
+			if ($this->get_primary_key_field()->is_auto_increment()) {
2268 2268
 				return $wpdb->insert_id;
2269
-			}else{
2269
+			} else {
2270 2270
 				//it's not an auto-increment primary key, so
2271 2271
 				//it must have been supplied
2272 2272
 				return $fields_n_values[$this->get_primary_key_field()->get_name()];
2273 2273
 			}
2274
-		}else{
2274
+		} else {
2275 2275
 			//we can't return a  primary key because there is none. instead return
2276 2276
 			//a unique string indicating this model
2277 2277
 			return $this->get_index_primary_key_string($fields_n_values);
@@ -2286,15 +2286,15 @@  discard block
 block discarded – undo
2286 2286
 	 * @param array $fields_n_values
2287 2287
 	 * @return mixed string|int|float depending on what the table column will be expecting
2288 2288
 	 */
2289
-	protected function _prepare_value_or_use_default( $field_obj, $fields_n_values ){
2289
+	protected function _prepare_value_or_use_default($field_obj, $fields_n_values) {
2290 2290
 		//if this field doesn't allow nullable, don't allow it
2291
-		if( ! $field_obj->is_nullable() && (
2292
-				! isset( $fields_n_values[ $field_obj->get_name() ] ) ||
2293
-				$fields_n_values[ $field_obj->get_name() ] === NULL ) ){
2294
-			$fields_n_values[ $field_obj->get_name() ] = $field_obj->get_default_value();
2291
+		if ( ! $field_obj->is_nullable() && (
2292
+				! isset($fields_n_values[$field_obj->get_name()]) ||
2293
+				$fields_n_values[$field_obj->get_name()] === NULL )) {
2294
+			$fields_n_values[$field_obj->get_name()] = $field_obj->get_default_value();
2295 2295
 		}
2296
-		$unprepared_value = isset( $fields_n_values[ $field_obj->get_name() ] ) ? $fields_n_values[ $field_obj->get_name() ] : NULL;
2297
-		return $this->_prepare_value_for_use_in_db( $unprepared_value, $field_obj);
2296
+		$unprepared_value = isset($fields_n_values[$field_obj->get_name()]) ? $fields_n_values[$field_obj->get_name()] : NULL;
2297
+		return $this->_prepare_value_for_use_in_db($unprepared_value, $field_obj);
2298 2298
 	}
2299 2299
 
2300 2300
 
@@ -2306,9 +2306,9 @@  discard block
 block discarded – undo
2306 2306
 	 * @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
2307 2307
 	 * @return mixed a value ready for use in the database for insertions, updating, or in a where clause
2308 2308
 	 */
2309
-	private function _prepare_value_for_use_in_db($value, $field){
2310
-		if($field && $field instanceof EE_Model_Field_Base){
2311
-			switch( $this->_values_already_prepared_by_model_object ){
2309
+	private function _prepare_value_for_use_in_db($value, $field) {
2310
+		if ($field && $field instanceof EE_Model_Field_Base) {
2311
+			switch ($this->_values_already_prepared_by_model_object) {
2312 2312
 				/** @noinspection PhpMissingBreakStatementInspection */
2313 2313
 				case self::not_prepared_by_model_object:
2314 2314
 					$value = $field->prepare_for_set($value);
@@ -2319,7 +2319,7 @@  discard block
 block discarded – undo
2319 2319
 					//leave the value alone
2320 2320
 			}
2321 2321
 			return $value;
2322
-		}else{
2322
+		} else {
2323 2323
 			return $value;
2324 2324
 		}
2325 2325
 	}
@@ -2329,13 +2329,13 @@  discard block
 block discarded – undo
2329 2329
 	 * @return EE_Primary_Table
2330 2330
 	 * @throws EE_Error
2331 2331
 	 */
2332
-	protected function _get_main_table(){
2333
-		foreach($this->_tables as $table){
2334
-			if($table instanceof EE_Primary_Table){
2332
+	protected function _get_main_table() {
2333
+		foreach ($this->_tables as $table) {
2334
+			if ($table instanceof EE_Primary_Table) {
2335 2335
 				return $table;
2336 2336
 			}
2337 2337
 		}
2338
-		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)));
2338
+		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)));
2339 2339
 	}
2340 2340
 
2341 2341
 	/**
@@ -2354,7 +2354,7 @@  discard block
 block discarded – undo
2354 2354
 	 */
2355 2355
 	public function second_table() {
2356 2356
 		// grab second table from tables array
2357
-		$second_table = end( $this->_tables );
2357
+		$second_table = end($this->_tables);
2358 2358
 		return $second_table instanceof EE_Secondary_Table ? $second_table->get_table_name() : NULL;
2359 2359
 	}
2360 2360
 
@@ -2367,8 +2367,8 @@  discard block
 block discarded – undo
2367 2367
 	 * @param string $table_alias
2368 2368
 	 * @return EE_Primary_Table | EE_Secondary_Table
2369 2369
 	 */
2370
-	public function get_table_obj_by_alias( $table_alias = '' ) {
2371
-		return isset( $this->_tables[ $table_alias ] ) ? $this->_tables[ $table_alias ] : NULL;
2370
+	public function get_table_obj_by_alias($table_alias = '') {
2371
+		return isset($this->_tables[$table_alias]) ? $this->_tables[$table_alias] : NULL;
2372 2372
 	}
2373 2373
 
2374 2374
 
@@ -2377,10 +2377,10 @@  discard block
 block discarded – undo
2377 2377
 	 * Gets all the tables of type EE_Other_Table from EEM_CPT_Basel_Model::_tables
2378 2378
 	 * @return EE_Secondary_Table[]
2379 2379
 	 */
2380
-	protected function _get_other_tables(){
2381
-		$other_tables =array();
2382
-		foreach($this->_tables as $table_alias => $table){
2383
-			if($table instanceof EE_Secondary_Table){
2380
+	protected function _get_other_tables() {
2381
+		$other_tables = array();
2382
+		foreach ($this->_tables as $table_alias => $table) {
2383
+			if ($table instanceof EE_Secondary_Table) {
2384 2384
 				$other_tables[$table_alias] = $table;
2385 2385
 			}
2386 2386
 		}
@@ -2392,7 +2392,7 @@  discard block
 block discarded – undo
2392 2392
 	 * @param string $table_alias, array key in EEM_Base::_tables
2393 2393
 	 * @return EE_Model_Field_Base[]
2394 2394
 	 */
2395
-	function _get_fields_for_table($table_alias){
2395
+	function _get_fields_for_table($table_alias) {
2396 2396
 		return $this->_fields[$table_alias];
2397 2397
 	}
2398 2398
 
@@ -2404,29 +2404,29 @@  discard block
 block discarded – undo
2404 2404
 	 * @param array $query_params like EEM_Base::get_all's $query_parameters['where']
2405 2405
 	 * @return EE_Model_Query_Info_Carrier
2406 2406
 	 */
2407
-	function _extract_related_models_from_query($query_params){
2407
+	function _extract_related_models_from_query($query_params) {
2408 2408
 		$query_info_carrier = new EE_Model_Query_Info_Carrier();
2409
-		if(array_key_exists(0,$query_params)){
2410
-			$this->_extract_related_models_from_sub_params_array_keys($query_params[0], $query_info_carrier,0);
2411
-		}
2412
-		if(array_key_exists('group_by', $query_params)){
2413
-			if(is_array($query_params['group_by'])){
2414
-				$this->_extract_related_models_from_sub_params_array_values($query_params['group_by'],$query_info_carrier,'group_by');
2415
-			}elseif( ! empty ( $query_params['group_by'] )){
2416
-				$this->_extract_related_model_info_from_query_param( $query_params['group_by'],$query_info_carrier,'group_by');
2409
+		if (array_key_exists(0, $query_params)) {
2410
+			$this->_extract_related_models_from_sub_params_array_keys($query_params[0], $query_info_carrier, 0);
2411
+		}
2412
+		if (array_key_exists('group_by', $query_params)) {
2413
+			if (is_array($query_params['group_by'])) {
2414
+				$this->_extract_related_models_from_sub_params_array_values($query_params['group_by'], $query_info_carrier, 'group_by');
2415
+			}elseif ( ! empty ($query_params['group_by'])) {
2416
+				$this->_extract_related_model_info_from_query_param($query_params['group_by'], $query_info_carrier, 'group_by');
2417 2417
 			}
2418 2418
 		}
2419
-		if(array_key_exists('having',$query_params)){
2420
-			$this->_extract_related_models_from_sub_params_array_keys($query_params[0], $query_info_carrier,'having');
2419
+		if (array_key_exists('having', $query_params)) {
2420
+			$this->_extract_related_models_from_sub_params_array_keys($query_params[0], $query_info_carrier, 'having');
2421 2421
 		}
2422
-		if(array_key_exists('order_by', $query_params)){
2423
-			if ( is_array( $query_params['order_by'] ) )
2424
-				$this->_extract_related_models_from_sub_params_array_keys($query_params['order_by'],$query_info_carrier,'order_by');
2425
-			elseif( ! empty( $query_params['order_by'] ))
2426
-				$this->_extract_related_model_info_from_query_param( $query_params['order_by'], $query_info_carrier,'order_by');
2422
+		if (array_key_exists('order_by', $query_params)) {
2423
+			if (is_array($query_params['order_by']))
2424
+				$this->_extract_related_models_from_sub_params_array_keys($query_params['order_by'], $query_info_carrier, 'order_by');
2425
+			elseif ( ! empty($query_params['order_by']))
2426
+				$this->_extract_related_model_info_from_query_param($query_params['order_by'], $query_info_carrier, 'order_by');
2427 2427
 		}
2428
-		if(array_key_exists('force_join', $query_params)){
2429
-			$this->_extract_related_models_from_sub_params_array_values($query_params['force_join'],$query_info_carrier,'force_join');
2428
+		if (array_key_exists('force_join', $query_params)) {
2429
+			$this->_extract_related_models_from_sub_params_array_values($query_params['force_join'], $query_info_carrier, 'force_join');
2430 2430
 		}
2431 2431
 		return $query_info_carrier;
2432 2432
 	}
@@ -2439,34 +2439,34 @@  discard block
 block discarded – undo
2439 2439
 	 * @throws EE_Error
2440 2440
 	 * @return \EE_Model_Query_Info_Carrier
2441 2441
 	 */
2442
-	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){
2443
-		if (!empty($sub_query_params)){
2442
+	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) {
2443
+		if ( ! empty($sub_query_params)) {
2444 2444
 			$sub_query_params = (array) $sub_query_params;
2445
-			foreach($sub_query_params as $param => $possibly_array_of_params){
2445
+			foreach ($sub_query_params as $param => $possibly_array_of_params) {
2446 2446
 				//$param could be simply 'EVT_ID', or it could be 'Registrations.REG_ID', or even 'Registrations.Transactions.Payments.PAY_amount'
2447
-				$this->_extract_related_model_info_from_query_param( $param, $model_query_info_carrier,$query_param_type);
2447
+				$this->_extract_related_model_info_from_query_param($param, $model_query_info_carrier, $query_param_type);
2448 2448
 
2449 2449
 				//if $possibly_array_of_params is an array, try recursing into it, searching for keys which
2450 2450
 				//indicate needed joins. Eg, array('NOT'=>array('Registration.TXN_ID'=>23)). In this case, we tried
2451 2451
 				//extracting models out of the 'NOT', which obviously wasn't successful, and then we recurse into the value
2452 2452
 				//of array('Registration.TXN_ID'=>23)
2453 2453
 				$query_param_sans_stars = $this->_remove_stars_and_anything_after_from_condition_query_param_key($param);
2454
-				if(in_array($query_param_sans_stars, $this->_logic_query_param_keys,true)){
2455
-					if (! is_array($possibly_array_of_params)){
2454
+				if (in_array($query_param_sans_stars, $this->_logic_query_param_keys, true)) {
2455
+					if ( ! is_array($possibly_array_of_params)) {
2456 2456
 						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"),
2457
-							$param,$possibly_array_of_params));
2458
-					}else{
2459
-						$this->_extract_related_models_from_sub_params_array_keys($possibly_array_of_params, $model_query_info_carrier,$query_param_type);
2457
+							$param, $possibly_array_of_params));
2458
+					} else {
2459
+						$this->_extract_related_models_from_sub_params_array_keys($possibly_array_of_params, $model_query_info_carrier, $query_param_type);
2460 2460
 					}
2461
-				}elseif($query_param_type === 0 //ie WHERE
2461
+				}elseif ($query_param_type === 0 //ie WHERE
2462 2462
 						&& is_array($possibly_array_of_params)
2463 2463
 						&& isset($possibly_array_of_params[2])
2464
-						&& $possibly_array_of_params[2] == true){
2464
+						&& $possibly_array_of_params[2] == true) {
2465 2465
 					//then $possible_array_of_params looks something like array('<','DTT_sold',true)
2466 2466
 					//indicating that $possible_array_of_params[1] is actually a field name,
2467 2467
 					//from which we should extract query parameters!
2468
-					if(! isset($possibly_array_of_params[0]) || ! isset($possibly_array_of_params[1])){
2469
-						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)));
2468
+					if ( ! isset($possibly_array_of_params[0]) || ! isset($possibly_array_of_params[1])) {
2469
+						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)));
2470 2470
 					}
2471 2471
 					$this->_extract_related_model_info_from_query_param($possibly_array_of_params[1], $model_query_info_carrier, $query_param_type);
2472 2472
 				}
@@ -2485,14 +2485,14 @@  discard block
 block discarded – undo
2485 2485
 	 * @throws EE_Error
2486 2486
 	 * @return \EE_Model_Query_Info_Carrier
2487 2487
 	 */
2488
-	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){
2489
-		if (!empty($sub_query_params)){
2490
-			if(!is_array($sub_query_params)){
2491
-				throw new EE_Error(sprintf(__("Query parameter %s should be an array, but it isn't.", "event_espresso"),$sub_query_params));
2488
+	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) {
2489
+		if ( ! empty($sub_query_params)) {
2490
+			if ( ! is_array($sub_query_params)) {
2491
+				throw new EE_Error(sprintf(__("Query parameter %s should be an array, but it isn't.", "event_espresso"), $sub_query_params));
2492 2492
 			}
2493
-			foreach($sub_query_params as $param){
2493
+			foreach ($sub_query_params as $param) {
2494 2494
 				//$param could be simply 'EVT_ID', or it could be 'Registrations.REG_ID', or even 'Registrations.Transactions.Payments.PAY_amount'
2495
-				$this->_extract_related_model_info_from_query_param( $param, $model_query_info_carrier, $query_param_type);
2495
+				$this->_extract_related_model_info_from_query_param($param, $model_query_info_carrier, $query_param_type);
2496 2496
 			}
2497 2497
 		}
2498 2498
 		return $model_query_info_carrier;
@@ -2511,81 +2511,81 @@  discard block
 block discarded – undo
2511 2511
 	 * @throws EE_Error
2512 2512
 	 * @return EE_Model_Query_Info_Carrier
2513 2513
 	 */
2514
-	function _create_model_query_info_carrier($query_params){
2515
-		if( ! is_array( $query_params ) ){
2516
-			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' );
2514
+	function _create_model_query_info_carrier($query_params) {
2515
+		if ( ! is_array($query_params)) {
2516
+			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');
2517 2517
 			$query_params = array();
2518 2518
 		}
2519
-		if( isset( $query_params[0] ) ) {
2519
+		if (isset($query_params[0])) {
2520 2520
 			$where_query_params = $query_params[0];
2521
-		}else{
2521
+		} else {
2522 2522
 			$where_query_params = array();
2523 2523
 		}
2524 2524
 		//first check if we should alter the query to account for caps or not
2525 2525
 		//because the caps might require us to do extra joins
2526
-		if( isset( $query_params[ 'caps' ] ) && $query_params[ 'caps' ] != 'none' ) {
2527
-			$query_params[0] = $where_query_params = array_replace_recursive( $where_query_params, $this->caps_where_conditions( $query_params[ 'caps' ] ) );
2526
+		if (isset($query_params['caps']) && $query_params['caps'] != 'none') {
2527
+			$query_params[0] = $where_query_params = array_replace_recursive($where_query_params, $this->caps_where_conditions($query_params['caps']));
2528 2528
 		}
2529 2529
 		$query_object = $this->_extract_related_models_from_query($query_params);
2530 2530
 
2531 2531
 		//verify where_query_params has NO numeric indexes.... that's simply not how you use it!
2532
-		foreach($where_query_params as $key => $value){
2533
-			if(is_int($key)){
2534
-				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)));
2532
+		foreach ($where_query_params as $key => $value) {
2533
+			if (is_int($key)) {
2534
+				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)));
2535 2535
 			}
2536 2536
 		}
2537
-		if( array_key_exists( 'default_where_conditions',$query_params) && ! empty( $query_params['default_where_conditions'] )){
2537
+		if (array_key_exists('default_where_conditions', $query_params) && ! empty($query_params['default_where_conditions'])) {
2538 2538
 			$use_default_where_conditions = $query_params['default_where_conditions'];
2539
-		}else{
2539
+		} else {
2540 2540
 			$use_default_where_conditions = 'all';
2541 2541
 		}
2542
-		$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 );
2543
-		$query_object->set_where_sql( $this->_construct_where_clause($where_query_params));
2542
+		$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);
2543
+		$query_object->set_where_sql($this->_construct_where_clause($where_query_params));
2544 2544
 
2545 2545
 
2546 2546
 		//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:
2547 2547
 		//array( 'on_join_limit' => array('Primary_Table_Alias', array(1,10) ) )
2548
-		if ( array_key_exists('on_join_limit', $query_params ) && ! empty( $query_params['on_join_limit'] )) {
2549
-			$query_object->set_main_model_join_sql( $this->_construct_limit_join_select( $query_params['on_join_limit'][0], $query_params['on_join_limit'][1] ) );
2548
+		if (array_key_exists('on_join_limit', $query_params) && ! empty($query_params['on_join_limit'])) {
2549
+			$query_object->set_main_model_join_sql($this->_construct_limit_join_select($query_params['on_join_limit'][0], $query_params['on_join_limit'][1]));
2550 2550
 		}
2551 2551
 
2552 2552
 
2553 2553
 		//set limit
2554
-		if(array_key_exists('limit',$query_params)){
2555
-			if(is_array($query_params['limit'])){
2556
-				if( ! isset($query_params['limit'][0]) || ! isset($query_params['limit'][1])){
2557
-					$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']));
2554
+		if (array_key_exists('limit', $query_params)) {
2555
+			if (is_array($query_params['limit'])) {
2556
+				if ( ! isset($query_params['limit'][0]) || ! isset($query_params['limit'][1])) {
2557
+					$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']));
2558 2558
 					throw new EE_Error($e."|".$e);
2559 2559
 				}
2560 2560
 				//they passed us an array for the limit. Assume it's like array(50,25), meaning offset by 50, and get 25
2561 2561
 				$query_object->set_limit_sql(" LIMIT ".$query_params['limit'][0].",".$query_params['limit'][1]);
2562
-			}elseif( ! empty ( $query_params['limit'] )){
2562
+			}elseif ( ! empty ($query_params['limit'])) {
2563 2563
 				$query_object->set_limit_sql((" LIMIT ".$query_params['limit']));
2564 2564
 			}
2565 2565
 		}
2566 2566
 		//set order by
2567
-		if(array_key_exists('order_by',$query_params)){
2568
-			if(is_array($query_params['order_by'])){
2567
+		if (array_key_exists('order_by', $query_params)) {
2568
+			if (is_array($query_params['order_by'])) {
2569 2569
 				//if they're using 'order_by' as an array, they can't use 'order' (because 'order_by' must
2570 2570
 				//specify whether to ascend or descend on each field. Eg 'order_by'=>array('EVT_ID'=>'ASC'). So
2571 2571
 				//including 'order' wouldn't make any sense if 'order_by' has already specified which way to order!
2572
-				if(array_key_exists('order', $query_params)){
2572
+				if (array_key_exists('order', $query_params)) {
2573 2573
 					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"),
2574
-							get_class($this),implode(", ",array_keys($query_params['order_by'])),implode(", ",$query_params['order_by']),$query_params['order']));
2574
+							get_class($this), implode(", ", array_keys($query_params['order_by'])), implode(", ", $query_params['order_by']), $query_params['order']));
2575 2575
 				}
2576
-				 $this->_extract_related_models_from_sub_params_array_keys($query_params['order_by'],$query_object,'order_by');
2576
+				 $this->_extract_related_models_from_sub_params_array_keys($query_params['order_by'], $query_object, 'order_by');
2577 2577
 				//assume it's an array of fields to order by
2578 2578
 				$order_array = array();
2579
-				foreach($query_params['order_by'] as $field_name_to_order_by => $order){
2579
+				foreach ($query_params['order_by'] as $field_name_to_order_by => $order) {
2580 2580
 					$order = $this->_extract_order($order);
2581 2581
 					$order_array[] = $this->_deduce_column_name_from_query_param($field_name_to_order_by).SP.$order;
2582 2582
 				}
2583
-				$query_object->set_order_by_sql(" ORDER BY ".implode(",",$order_array));
2584
-			}elseif( ! empty ( $query_params['order_by'] )){
2585
-				$this->_extract_related_model_info_from_query_param($query_params['order_by'],$query_object,'order',$query_params['order_by']);
2586
-				if(isset($query_params['order'])){
2583
+				$query_object->set_order_by_sql(" ORDER BY ".implode(",", $order_array));
2584
+			}elseif ( ! empty ($query_params['order_by'])) {
2585
+				$this->_extract_related_model_info_from_query_param($query_params['order_by'], $query_object, 'order', $query_params['order_by']);
2586
+				if (isset($query_params['order'])) {
2587 2587
 					$order = $this->_extract_order($query_params['order']);
2588
-				}else{
2588
+				} else {
2589 2589
 					$order = 'DESC';
2590 2590
 				}
2591 2591
 				$query_object->set_order_by_sql(" ORDER BY ".$this->_deduce_column_name_from_query_param($query_params['order_by']).SP.$order);
@@ -2593,46 +2593,46 @@  discard block
 block discarded – undo
2593 2593
 		}
2594 2594
 
2595 2595
 		//if 'order_by' wasn't set, maybe they are just using 'order' on its own?
2596
-		if( ! array_key_exists('order_by',$query_params) && array_key_exists('order',$query_params) && ! empty( $query_params['order'] )){
2596
+		if ( ! array_key_exists('order_by', $query_params) && array_key_exists('order', $query_params) && ! empty($query_params['order'])) {
2597 2597
 			$pk_field = $this->get_primary_key_field();
2598 2598
 			$order = $this->_extract_order($query_params['order']);
2599 2599
 			$query_object->set_order_by_sql(" ORDER BY ".$pk_field->get_qualified_column().SP.$order);
2600 2600
 		}
2601 2601
 
2602 2602
 		//set group by
2603
-		if(array_key_exists('group_by',$query_params)){
2604
-			if(is_array($query_params['group_by'])){
2603
+		if (array_key_exists('group_by', $query_params)) {
2604
+			if (is_array($query_params['group_by'])) {
2605 2605
 				//it's an array, so assume we'll be grouping by a bunch of stuff
2606 2606
 				$group_by_array = array();
2607
-				foreach($query_params['group_by'] as $field_name_to_group_by){
2607
+				foreach ($query_params['group_by'] as $field_name_to_group_by) {
2608 2608
 					$group_by_array[] = $this->_deduce_column_name_from_query_param($field_name_to_group_by);
2609 2609
 				}
2610
-				$query_object->set_group_by_sql(" GROUP BY ".implode(", ",$group_by_array));
2611
-			}elseif( ! empty ( $query_params['group_by'] )){
2610
+				$query_object->set_group_by_sql(" GROUP BY ".implode(", ", $group_by_array));
2611
+			}elseif ( ! empty ($query_params['group_by'])) {
2612 2612
 				$query_object->set_group_by_sql(" GROUP BY ".$this->_deduce_column_name_from_query_param($query_params['group_by']));
2613 2613
 			}
2614 2614
 		}
2615 2615
 		//set having
2616
-		if(array_key_exists('having',$query_params) && $query_params['having']){
2617
-			$query_object->set_having_sql( $this->_construct_having_clause($query_params['having']));
2616
+		if (array_key_exists('having', $query_params) && $query_params['having']) {
2617
+			$query_object->set_having_sql($this->_construct_having_clause($query_params['having']));
2618 2618
 		}
2619 2619
 
2620 2620
 		//now, just verify they didn't pass anything wack
2621
-		foreach($query_params as $query_key => $query_value){
2622
-			if( ! in_array($query_key,$this->_allowed_query_params,true)){
2621
+		foreach ($query_params as $query_key => $query_value) {
2622
+			if ( ! in_array($query_key, $this->_allowed_query_params, true)) {
2623 2623
 				throw new EE_Error(
2624 2624
 					sprintf(
2625
-						__("You passed %s as a query parameter to %s, which is illegal! The allowed query parameters are %s",'event_espresso'),
2625
+						__("You passed %s as a query parameter to %s, which is illegal! The allowed query parameters are %s", 'event_espresso'),
2626 2626
 						$query_key,
2627 2627
 						get_class($this),
2628 2628
 //						print_r( $this->_allowed_query_params, TRUE )
2629
-						implode( ',', $this->_allowed_query_params )
2629
+						implode(',', $this->_allowed_query_params)
2630 2630
 					)
2631 2631
 				);
2632 2632
 			}
2633 2633
 		}
2634 2634
 		$main_model_join_sql = $query_object->get_main_model_join_sql();
2635
-		if ( empty( $main_model_join_sql ) )
2635
+		if (empty($main_model_join_sql))
2636 2636
 			$query_object->set_main_model_join_sql($this->_construct_internal_join());
2637 2637
 		return $query_object;
2638 2638
 	}
@@ -2643,17 +2643,17 @@  discard block
 block discarded – undo
2643 2643
 	 * @param string $context one of EEM_Base::valid_cap_contexts()
2644 2644
 	 * @return array like EEM_Base::get_all() 's $query_params[0]
2645 2645
 	 */
2646
-	public function caps_where_conditions( $context = self::caps_read ) {
2647
-		EEM_Base::verify_is_valid_cap_context( $context );
2646
+	public function caps_where_conditions($context = self::caps_read) {
2647
+		EEM_Base::verify_is_valid_cap_context($context);
2648 2648
 		$cap_where_conditions = array();
2649
-		$cap_restrictions = $this->caps_missing( $context );
2649
+		$cap_restrictions = $this->caps_missing($context);
2650 2650
 		/**
2651 2651
 		 * @var $cap_restrictions EE_Default_Where_Conditions[]
2652 2652
 		 */
2653
-		foreach( $cap_restrictions as $cap => $restriction_if_no_cap ) {
2654
-				$cap_where_conditions = array_replace_recursive( $cap_where_conditions, $restriction_if_no_cap->get_default_where_conditions() );
2653
+		foreach ($cap_restrictions as $cap => $restriction_if_no_cap) {
2654
+				$cap_where_conditions = array_replace_recursive($cap_where_conditions, $restriction_if_no_cap->get_default_where_conditions());
2655 2655
 		}
2656
-		return apply_filters( 'FHEE__EEM_Base__caps_where_conditions__return', $cap_where_conditions, $this, $context, $cap_restrictions );
2656
+		return apply_filters('FHEE__EEM_Base__caps_where_conditions__return', $cap_where_conditions, $this, $context, $cap_restrictions);
2657 2657
 	}
2658 2658
 
2659 2659
 	/**
@@ -2663,11 +2663,11 @@  discard block
 block discarded – undo
2663 2663
 	 * @return string either ASC, asc, DESC or desc
2664 2664
 	 * @throws EE_Error
2665 2665
 	 */
2666
-	private function _extract_order($should_be_order_string){
2667
-		if(in_array($should_be_order_string, $this->_allowed_order_values)){
2666
+	private function _extract_order($should_be_order_string) {
2667
+		if (in_array($should_be_order_string, $this->_allowed_order_values)) {
2668 2668
 			return $should_be_order_string;
2669
-		}else{
2670
-			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));
2669
+		} else {
2670
+			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));
2671 2671
 		}
2672 2672
 	}
2673 2673
 
@@ -2685,19 +2685,19 @@  discard block
 block discarded – undo
2685 2685
 	 * @throws EE_Error
2686 2686
 	 * @return array like $query_params[0], see EEM_Base::get_all for documentation
2687 2687
 	 */
2688
-	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()){
2689
-		$allowed_used_default_where_conditions_values = array('all','this_model_only', 'other_models_only','none');
2690
-		if( ! in_array($use_default_where_conditions,$allowed_used_default_where_conditions_values)){
2691
-			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)));
2688
+	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()) {
2689
+		$allowed_used_default_where_conditions_values = array('all', 'this_model_only', 'other_models_only', 'none');
2690
+		if ( ! in_array($use_default_where_conditions, $allowed_used_default_where_conditions_values)) {
2691
+			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)));
2692 2692
 		}
2693
-		if( in_array($use_default_where_conditions, array('all','this_model_only')) ){
2693
+		if (in_array($use_default_where_conditions, array('all', 'this_model_only'))) {
2694 2694
 			$universal_query_params = $this->_get_default_where_conditions();
2695
-		}else{
2695
+		} else {
2696 2696
 			$universal_query_params = array();
2697 2697
 		}
2698 2698
 
2699
-		if(in_array($use_default_where_conditions,array('all','other_models_only'))){
2700
-			foreach($query_info_carrier->get_model_names_included() as $model_relation_path => $model_name){
2699
+		if (in_array($use_default_where_conditions, array('all', 'other_models_only'))) {
2700
+			foreach ($query_info_carrier->get_model_names_included() as $model_relation_path => $model_name) {
2701 2701
 				$related_model = $this->get_related_model_obj($model_name);
2702 2702
 				$related_model_universal_where_params = $related_model->_get_default_where_conditions($model_relation_path);
2703 2703
 
@@ -2724,22 +2724,22 @@  discard block
 block discarded – undo
2724 2724
 	 * @param string $model_relation_path like 'Transaction.Payment.'
2725 2725
 	 * @return array like EEM_Base::get_all's $query_params[0]
2726 2726
 	 */
2727
-	private function _override_defaults_or_make_null_friendly($default_where_conditions,$provided_where_conditions,$model,$model_relation_path){
2727
+	private function _override_defaults_or_make_null_friendly($default_where_conditions, $provided_where_conditions, $model, $model_relation_path) {
2728 2728
 		$null_friendly_where_conditions = array();
2729 2729
 		$none_overridden = true;
2730 2730
 		$or_condition_key_for_defaults = 'OR*'.get_class($model);
2731 2731
 
2732
-		foreach($default_where_conditions as $key => $val){
2733
-			if( isset($provided_where_conditions[$key])){
2732
+		foreach ($default_where_conditions as $key => $val) {
2733
+			if (isset($provided_where_conditions[$key])) {
2734 2734
 				$none_overridden = false;
2735
-			}else{
2735
+			} else {
2736 2736
 				$null_friendly_where_conditions[$or_condition_key_for_defaults]['AND'][$key] = $val;
2737 2737
 			}
2738 2738
 		}
2739
-		if( $none_overridden && $default_where_conditions){
2740
-			if($model->has_primary_key_field()){
2739
+		if ($none_overridden && $default_where_conditions) {
2740
+			if ($model->has_primary_key_field()) {
2741 2741
 				$null_friendly_where_conditions[$or_condition_key_for_defaults][$model_relation_path.".".$model->primary_key_name()] = array('IS NULL');
2742
-			}else{
2742
+			} else {
2743 2743
 				//@todo NO PK, use other defaults
2744 2744
 			}
2745 2745
 		}
@@ -2754,8 +2754,8 @@  discard block
 block discarded – undo
2754 2754
 	 * @param string $model_relation_path eg, path from Event to Payment is "Registration.Transaction.Payment."
2755 2755
 	 * @return array like EEM_Base::get_all's $query_params[0] (where conditions)
2756 2756
 	 */
2757
-	private function _get_default_where_conditions($model_relation_path = null){
2758
-		if ( $this->_ignore_where_strategy )
2757
+	private function _get_default_where_conditions($model_relation_path = null) {
2758
+		if ($this->_ignore_where_strategy)
2759 2759
 			return array();
2760 2760
 
2761 2761
 		return $this->_default_where_conditions_strategy->get_default_where_conditions($model_relation_path);
@@ -2766,13 +2766,13 @@  discard block
 block discarded – undo
2766 2766
 	 * @param EE_Model_Query_Info_Carrier $model_query_info
2767 2767
 	 * @return string
2768 2768
 	 */
2769
-	private function _construct_default_select_sql(EE_Model_Query_Info_Carrier $model_query_info){
2769
+	private function _construct_default_select_sql(EE_Model_Query_Info_Carrier $model_query_info) {
2770 2770
 		$selects = $this->_get_columns_to_select_for_this_model();
2771
-		foreach($model_query_info->get_model_names_included() as $model_relation_chain => $name_of_other_model_included){
2771
+		foreach ($model_query_info->get_model_names_included() as $model_relation_chain => $name_of_other_model_included) {
2772 2772
 			$other_model_included = $this->get_related_model_obj($name_of_other_model_included);
2773 2773
 			$selects = array_merge($selects, $other_model_included->_get_columns_to_select_for_this_model($model_relation_chain));
2774 2774
 		}
2775
-		return implode(", ",$selects);
2775
+		return implode(", ", $selects);
2776 2776
 	}
2777 2777
 
2778 2778
 	/**
@@ -2781,19 +2781,19 @@  discard block
 block discarded – undo
2781 2781
 	 * @param string $model_relation_chain like 'Question.Question_Group.Event'
2782 2782
 	 * @return array numerically indexed, values are columns to select and rename, eg "Event.ID AS 'Event.ID'"
2783 2783
 	 */
2784
-	public function _get_columns_to_select_for_this_model($model_relation_chain = ''){
2784
+	public function _get_columns_to_select_for_this_model($model_relation_chain = '') {
2785 2785
 		$fields = $this->field_settings();
2786 2786
 		$selects = array();
2787 2787
 		$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());
2788
-		foreach($fields as $field_obj){
2789
-			$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()."'";
2788
+		foreach ($fields as $field_obj) {
2789
+			$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()."'";
2790 2790
 		}
2791 2791
 		//make sure we are also getting the PKs of each table
2792 2792
 		$tables = $this->get_tables();
2793
-		if(count($tables) > 1){
2794
-			foreach($tables as $table_obj){
2795
-				$qualified_pk_column = $table_alias_with_model_relation_chain_prefix . $table_obj->get_fully_qualified_pk_column();
2796
-				if( ! in_array($qualified_pk_column,$selects)){
2793
+		if (count($tables) > 1) {
2794
+			foreach ($tables as $table_obj) {
2795
+				$qualified_pk_column = $table_alias_with_model_relation_chain_prefix.$table_obj->get_fully_qualified_pk_column();
2796
+				if ( ! in_array($qualified_pk_column, $selects)) {
2797 2797
 					$selects[] = "$qualified_pk_column AS '$qualified_pk_column'";
2798 2798
 				}
2799 2799
 			}
@@ -2817,66 +2817,66 @@  discard block
 block discarded – undo
2817 2817
 	 * @throws EE_Error
2818 2818
 	 * @return void only modifies the EEM_Related_Model_Info_Carrier passed into it
2819 2819
 	 */
2820
-	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 ){
2821
-		if($original_query_param == NULL){
2820
+	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) {
2821
+		if ($original_query_param == NULL) {
2822 2822
 			$original_query_param = $query_param;
2823 2823
 		}
2824 2824
 		$query_param = $this->_remove_stars_and_anything_after_from_condition_query_param_key($query_param);
2825 2825
 		/** @var $allow_logic_query_params bool whether or not to allow logic_query_params like 'NOT','OR', or 'AND' */
2826
-		$allow_logic_query_params = in_array($query_param_type,array('where','having'));
2827
-		$allow_fields = in_array($query_param_type,array('where','having','order_by','group_by','order'));
2826
+		$allow_logic_query_params = in_array($query_param_type, array('where', 'having'));
2827
+		$allow_fields = in_array($query_param_type, array('where', 'having', 'order_by', 'group_by', 'order'));
2828 2828
 		//check to see if we have a field on this model
2829 2829
 		$this_model_fields = $this->field_settings(true);
2830
-		if(array_key_exists($query_param,$this_model_fields)){
2831
-			if($allow_fields){
2830
+		if (array_key_exists($query_param, $this_model_fields)) {
2831
+			if ($allow_fields) {
2832 2832
 				return;
2833
-			}else{
2833
+			} else {
2834 2834
 				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"),
2835
-						$query_param,get_class($this),$query_param_type,$original_query_param));
2835
+						$query_param, get_class($this), $query_param_type, $original_query_param));
2836 2836
 			}
2837 2837
 		}
2838 2838
 		//check if this is a special logic query param
2839
-		elseif(in_array($query_param, $this->_logic_query_param_keys, TRUE)){
2840
-			if($allow_logic_query_params){
2839
+		elseif (in_array($query_param, $this->_logic_query_param_keys, TRUE)) {
2840
+			if ($allow_logic_query_params) {
2841 2841
 				return;
2842
-			}else{
2842
+			} else {
2843 2843
 				throw new EE_Error(
2844 2844
 					sprintf(
2845
-						__( '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' ),
2846
-						implode( '", "', $this->_logic_query_param_keys ),
2847
-						$query_param ,
2848
-						get_class( $this ),
2845
+						__('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'),
2846
+						implode('", "', $this->_logic_query_param_keys),
2847
+						$query_param,
2848
+						get_class($this),
2849 2849
 						'<br />',
2850
-						"\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
2850
+						"\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
2851 2851
 					)
2852 2852
 				);
2853 2853
 			}
2854 2854
 		}
2855 2855
 
2856 2856
 		//check if it's a custom selection
2857
-		elseif(array_key_exists($query_param,$this->_custom_selections)){
2857
+		elseif (array_key_exists($query_param, $this->_custom_selections)) {
2858 2858
 			return;
2859 2859
 		}
2860 2860
 
2861 2861
 		//check if has a model name at the beginning
2862 2862
 		//and
2863 2863
 		//check if it's a field on a related model
2864
-		foreach($this->_model_relations as $valid_related_model_name=>$relation_obj){
2865
-			if(strpos($query_param, $valid_related_model_name.".") === 0){
2866
-				$this->_add_join_to_model($valid_related_model_name, $passed_in_query_info,$original_query_param);
2864
+		foreach ($this->_model_relations as $valid_related_model_name=>$relation_obj) {
2865
+			if (strpos($query_param, $valid_related_model_name.".") === 0) {
2866
+				$this->_add_join_to_model($valid_related_model_name, $passed_in_query_info, $original_query_param);
2867 2867
 				$query_param = substr($query_param, strlen($valid_related_model_name."."));
2868
-				if($query_param == ''){
2868
+				if ($query_param == '') {
2869 2869
 					//nothing left to $query_param
2870 2870
 					//we should actually end in a field name, not a model like this!
2871 2871
 					throw new EE_Error(sprintf(__("Query param '%s' (of type %s on model %s) shouldn't end on a period (.) ", "event_espresso"),
2872
-					$query_param,$query_param_type,get_class($this),$valid_related_model_name));
2873
-				}else{
2872
+					$query_param, $query_param_type, get_class($this), $valid_related_model_name));
2873
+				} else {
2874 2874
 					$related_model_obj = $this->get_related_model_obj($valid_related_model_name);
2875 2875
 					$related_model_obj->_extract_related_model_info_from_query_param($query_param, $passed_in_query_info, $query_param_type, $original_query_param);
2876 2876
 					return;
2877 2877
 				}
2878
-			}elseif($query_param == $valid_related_model_name){
2879
-				$this->_add_join_to_model($valid_related_model_name, $passed_in_query_info,$original_query_param);
2878
+			}elseif ($query_param == $valid_related_model_name) {
2879
+				$this->_add_join_to_model($valid_related_model_name, $passed_in_query_info, $original_query_param);
2880 2880
 				return;
2881 2881
 			}
2882 2882
 		}
@@ -2886,7 +2886,7 @@  discard block
 block discarded – undo
2886 2886
 		//and we previously confirmed it wasn't a logic query param or field on the current model
2887 2887
 		//it's wack, that's what it is
2888 2888
 		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"),
2889
-				$query_param,get_class($this),$query_param_type,$original_query_param));
2889
+				$query_param, get_class($this), $query_param_type, $original_query_param));
2890 2890
 
2891 2891
 	}
2892 2892
 
@@ -2903,26 +2903,26 @@  discard block
 block discarded – undo
2903 2903
 	 * 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)
2904 2904
 	 * @return void
2905 2905
 	 */
2906
-	private function _add_join_to_model($model_name, EE_Model_Query_Info_Carrier $passed_in_query_info,$original_query_param){
2906
+	private function _add_join_to_model($model_name, EE_Model_Query_Info_Carrier $passed_in_query_info, $original_query_param) {
2907 2907
 		$relation_obj = $this->related_settings_for($model_name);
2908 2908
 
2909 2909
 		$model_relation_chain = EE_Model_Parser::extract_model_relation_chain($model_name, $original_query_param);
2910 2910
 		//check if the relation is HABTM, because then we're essentially doing two joins
2911 2911
 		//If so, join first to the JOIN table, and add its data types, and then continue as normal
2912
-		if($relation_obj instanceof EE_HABTM_Relation){
2912
+		if ($relation_obj instanceof EE_HABTM_Relation) {
2913 2913
 			$join_model_obj = $relation_obj->get_join_model();
2914 2914
 			//replace the model specified with the join model for this relation chain, whi
2915 2915
 			$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);
2916 2916
 			$new_query_info = new EE_Model_Query_Info_Carrier(
2917 2917
 					array($relation_chain_to_join_model => $join_model_obj->get_this_model_name()),
2918 2918
 					$relation_obj->get_join_to_intermediate_model_statement($relation_chain_to_join_model));
2919
-			$passed_in_query_info->merge( $new_query_info  );
2919
+			$passed_in_query_info->merge($new_query_info);
2920 2920
 		}
2921 2921
 		//now just join to the other table pointed to by the relation object, and add its data types
2922 2922
 		$new_query_info = new EE_Model_Query_Info_Carrier(
2923 2923
 				array($model_relation_chain=>$model_name),
2924 2924
 				$relation_obj->get_join_statement($model_relation_chain));
2925
-		$passed_in_query_info->merge( $new_query_info  );
2925
+		$passed_in_query_info->merge($new_query_info);
2926 2926
 	}
2927 2927
 
2928 2928
 
@@ -2931,11 +2931,11 @@  discard block
 block discarded – undo
2931 2931
 	 * @param array $where_params like EEM_Base::get_all
2932 2932
 	 * @return string of SQL
2933 2933
 	 */
2934
-	private function _construct_where_clause($where_params){
2934
+	private function _construct_where_clause($where_params) {
2935 2935
 		$SQL = $this->_construct_condition_clause_recursive($where_params, ' AND ');
2936
-		if($SQL){
2937
-			return " WHERE ". $SQL;
2938
-		}else{
2936
+		if ($SQL) {
2937
+			return " WHERE ".$SQL;
2938
+		} else {
2939 2939
 			return '';
2940 2940
 		}
2941 2941
 	}
@@ -2946,11 +2946,11 @@  discard block
 block discarded – undo
2946 2946
 	 * @param array $having_params
2947 2947
 	 * @return string
2948 2948
 	 */
2949
-	private function _construct_having_clause($having_params){
2949
+	private function _construct_having_clause($having_params) {
2950 2950
 		$SQL = $this->_construct_condition_clause_recursive($having_params, ' AND ');
2951
-		if($SQL){
2952
-			return " HAVING ". $SQL;
2953
-		}else{
2951
+		if ($SQL) {
2952
+			return " HAVING ".$SQL;
2953
+		} else {
2954 2954
 			return '';
2955 2955
 		}
2956 2956
 
@@ -2964,17 +2964,17 @@  discard block
 block discarded – undo
2964 2964
 	 * @return EE_Model_Field_Base
2965 2965
 	 * @throws EE_Error
2966 2966
 	 */
2967
-	protected function _get_field_on_model($field_name,$model_name){
2967
+	protected function _get_field_on_model($field_name, $model_name) {
2968 2968
 		$model_class = 'EEM_'.$model_name;
2969 2969
 		$model_filepath = $model_class.".model.php";
2970
-		EE_Registry::instance()->load_helper( 'File' );
2971
-		if ( is_readable($model_filepath)){
2970
+		EE_Registry::instance()->load_helper('File');
2971
+		if (is_readable($model_filepath)) {
2972 2972
 			require_once($model_filepath);
2973
-			$model_instance=call_user_func($model_name."::instance");
2973
+			$model_instance = call_user_func($model_name."::instance");
2974 2974
 			/* @var $model_instance EEM_Base */
2975 2975
 			return $model_instance->field_settings_for($field_name);
2976
-		}else{
2977
-			throw new EE_Error(sprintf(__('No model named %s exists, with classname %s and filepath %s','event_espresso'),$model_name,$model_class,$model_filepath));
2976
+		} else {
2977
+			throw new EE_Error(sprintf(__('No model named %s exists, with classname %s and filepath %s', 'event_espresso'), $model_name, $model_class, $model_filepath));
2978 2978
 		}
2979 2979
 	}
2980 2980
 
@@ -2987,43 +2987,43 @@  discard block
 block discarded – undo
2987 2987
 	 * @throws EE_Error
2988 2988
 	 * @return string of SQL
2989 2989
 	 */
2990
-	private function _construct_condition_clause_recursive($where_params, $glue = ' AND'){
2991
-		$where_clauses=array();
2992
-		foreach($where_params as $query_param => $op_and_value_or_sub_condition){
2993
-			$query_param = $this->_remove_stars_and_anything_after_from_condition_query_param_key($query_param);//str_replace("*",'',$query_param);
2994
-			if(in_array($query_param,$this->_logic_query_param_keys)){
2995
-				switch($query_param){
2990
+	private function _construct_condition_clause_recursive($where_params, $glue = ' AND') {
2991
+		$where_clauses = array();
2992
+		foreach ($where_params as $query_param => $op_and_value_or_sub_condition) {
2993
+			$query_param = $this->_remove_stars_and_anything_after_from_condition_query_param_key($query_param); //str_replace("*",'',$query_param);
2994
+			if (in_array($query_param, $this->_logic_query_param_keys)) {
2995
+				switch ($query_param) {
2996 2996
 					case 'not':
2997 2997
 					case 'NOT':
2998
-						$where_clauses[] = "! (". $this->_construct_condition_clause_recursive($op_and_value_or_sub_condition, $glue).")";
2998
+						$where_clauses[] = "! (".$this->_construct_condition_clause_recursive($op_and_value_or_sub_condition, $glue).")";
2999 2999
 						break;
3000 3000
 					case 'and':
3001 3001
 					case 'AND':
3002
-						$where_clauses[] = " (". $this->_construct_condition_clause_recursive($op_and_value_or_sub_condition, ' AND ') .")";
3002
+						$where_clauses[] = " (".$this->_construct_condition_clause_recursive($op_and_value_or_sub_condition, ' AND ').")";
3003 3003
 						break;
3004 3004
 					case 'or':
3005 3005
 					case 'OR':
3006
-						$where_clauses[] = " (". $this->_construct_condition_clause_recursive($op_and_value_or_sub_condition, ' OR ') .")";
3006
+						$where_clauses[] = " (".$this->_construct_condition_clause_recursive($op_and_value_or_sub_condition, ' OR ').")";
3007 3007
 						break;
3008 3008
 				}
3009
-			}else{
3009
+			} else {
3010 3010
 				$field_obj = $this->_deduce_field_from_query_param($query_param);
3011 3011
 
3012 3012
 				//if it's not a normal field, maybe it's a custom selection?
3013
-				if( ! $field_obj){
3014
-					if(isset( $this->_custom_selections[$query_param][1])){
3013
+				if ( ! $field_obj) {
3014
+					if (isset($this->_custom_selections[$query_param][1])) {
3015 3015
 						$field_obj = $this->_custom_selections[$query_param][1];
3016
-					}else{
3017
-						throw new EE_Error(sprintf(__("%s is neither a valid model field name, nor a custom selection", "event_espresso"),$query_param));
3016
+					} else {
3017
+						throw new EE_Error(sprintf(__("%s is neither a valid model field name, nor a custom selection", "event_espresso"), $query_param));
3018 3018
 					}
3019 3019
 				}
3020 3020
 				$op_and_value_sql = $this->_construct_op_and_value($op_and_value_or_sub_condition, $field_obj);
3021
-				$where_clauses[]=$this->_deduce_column_name_from_query_param($query_param).SP.$op_and_value_sql;
3021
+				$where_clauses[] = $this->_deduce_column_name_from_query_param($query_param).SP.$op_and_value_sql;
3022 3022
 			}
3023 3023
 		}
3024
-		if($where_clauses){
3025
-			$SQL = implode($glue,$where_clauses);
3026
-		}else{
3024
+		if ($where_clauses) {
3025
+			$SQL = implode($glue, $where_clauses);
3026
+		} else {
3027 3027
 			$SQL = '';
3028 3028
 		}
3029 3029
 		return $SQL;
@@ -3037,18 +3037,18 @@  discard block
 block discarded – undo
3037 3037
 	 * @throws EE_Error
3038 3038
 	 * @return string table alias and column name for SQL, eg "Transaction.TXN_ID"
3039 3039
 	 */
3040
-	private function _deduce_column_name_from_query_param($query_param){
3040
+	private function _deduce_column_name_from_query_param($query_param) {
3041 3041
 		$field = $this->_deduce_field_from_query_param($query_param);
3042 3042
 
3043
-		if( $field ){
3044
-			$table_alias_prefix = EE_Model_Parser::extract_table_alias_model_relation_chain_from_query_param( $field->get_model_name(), $query_param );
3045
-			return $table_alias_prefix . $field->get_qualified_column();
3046
-		}elseif(array_key_exists($query_param,$this->_custom_selections)){
3043
+		if ($field) {
3044
+			$table_alias_prefix = EE_Model_Parser::extract_table_alias_model_relation_chain_from_query_param($field->get_model_name(), $query_param);
3045
+			return $table_alias_prefix.$field->get_qualified_column();
3046
+		}elseif (array_key_exists($query_param, $this->_custom_selections)) {
3047 3047
 			//maybe it's custom selection item?
3048 3048
 			//if so, just use it as the "column name"
3049 3049
 			return $query_param;
3050
-		}else{
3051
-			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)));
3050
+		} else {
3051
+			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)));
3052 3052
 		}
3053 3053
 	}
3054 3054
 
@@ -3060,11 +3060,11 @@  discard block
 block discarded – undo
3060 3060
 	 * @param string $condition_query_param_key
3061 3061
 	 * @return string
3062 3062
 	 */
3063
-	private function _remove_stars_and_anything_after_from_condition_query_param_key($condition_query_param_key){
3063
+	private function _remove_stars_and_anything_after_from_condition_query_param_key($condition_query_param_key) {
3064 3064
 		$pos_of_star = strpos($condition_query_param_key, '*');
3065
-		if($pos_of_star === FALSE){
3065
+		if ($pos_of_star === FALSE) {
3066 3066
 			return $condition_query_param_key;
3067
-		}else{
3067
+		} else {
3068 3068
 			$condition_query_param_sans_star = substr($condition_query_param_key, 0, $pos_of_star);
3069 3069
 			return $condition_query_param_sans_star;
3070 3070
 		}
@@ -3079,54 +3079,54 @@  discard block
 block discarded – undo
3079 3079
 	 * @throws EE_Error
3080 3080
 	 * @return string
3081 3081
 	 */
3082
-	private function _construct_op_and_value($op_and_value, $field_obj){
3083
-		if(is_array( $op_and_value )){
3082
+	private function _construct_op_and_value($op_and_value, $field_obj) {
3083
+		if (is_array($op_and_value)) {
3084 3084
 			$operator = isset($op_and_value[0]) ? $this->_prepare_operator_for_sql($op_and_value[0]) : null;
3085
-			if( ! $operator){
3085
+			if ( ! $operator) {
3086 3086
 				$php_array_like_string = array();
3087
-				foreach($op_and_value as $key => $value){
3087
+				foreach ($op_and_value as $key => $value) {
3088 3088
 					$php_array_like_string[] = "$key=>$value";
3089 3089
 				}
3090
-				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)));
3090
+				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)));
3091 3091
 			}
3092 3092
 			$value = isset($op_and_value[1]) ? $op_and_value[1] : null;
3093
-		}else{
3093
+		} else {
3094 3094
 			$operator = '=';
3095 3095
 			$value = $op_and_value;
3096 3096
 		}
3097 3097
 
3098 3098
 		//check to see if the value is actually another field
3099
-		if(is_array($op_and_value) && isset($op_and_value[2]) && $op_and_value[2] == true){
3099
+		if (is_array($op_and_value) && isset($op_and_value[2]) && $op_and_value[2] == true) {
3100 3100
 			return $operator.SP.$this->_deduce_column_name_from_query_param($value);
3101
-		}elseif(in_array($operator, $this->_in_style_operators) && is_array($value)){
3101
+		}elseif (in_array($operator, $this->_in_style_operators) && is_array($value)) {
3102 3102
 			//in this case, the value should be an array, or at least a comma-separated list
3103 3103
 			//it will need to handle a little differently
3104 3104
 			$cleaned_value = $this->_construct_in_value($value, $field_obj);
3105 3105
 			//note: $cleaned_value has already been run through $wpdb->prepare()
3106 3106
 			return $operator.SP.$cleaned_value;
3107
-		} elseif( in_array( $operator, $this->_between_style_operators ) && is_array( $value ) ) {
3107
+		} elseif (in_array($operator, $this->_between_style_operators) && is_array($value)) {
3108 3108
 			//the value should be an array with count of two.
3109
-			if ( count($value) !== 2 )
3110
-				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" ) );
3111
-			$cleaned_value = $this->_construct_between_value( $value, $field_obj );
3109
+			if (count($value) !== 2)
3110
+				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"));
3111
+			$cleaned_value = $this->_construct_between_value($value, $field_obj);
3112 3112
 			return $operator.SP.$cleaned_value;
3113
-		} elseif( in_array( $operator, $this->_null_style_operators ) ) {
3114
-			if($value != NULL){
3115
-				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));
3113
+		} elseif (in_array($operator, $this->_null_style_operators)) {
3114
+			if ($value != NULL) {
3115
+				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));
3116 3116
 			}
3117 3117
 			return $operator;
3118
-		}elseif( $operator == 'LIKE' && ! is_array($value)){
3118
+		}elseif ($operator == 'LIKE' && ! is_array($value)) {
3119 3119
 			//if the operator is 'LIKE', we want to allow percent signs (%) and not
3120 3120
 			//remove other junk. So just treat it as a string.
3121 3121
 			return $operator.SP.$this->_wpdb_prepare_using_field($value, '%s');
3122
-		}elseif( ! in_array($operator, $this->_in_style_operators) && ! is_array($value)){
3123
-			return $operator.SP.$this->_wpdb_prepare_using_field($value,$field_obj);
3124
-		}elseif(in_array($operator, $this->_in_style_operators) && ! is_array($value)){
3125
-			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));
3126
-		}elseif( ! in_array($operator, $this->_in_style_operators) && is_array($value)){
3127
-			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));
3128
-		}else{
3129
-			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)));
3122
+		}elseif ( ! in_array($operator, $this->_in_style_operators) && ! is_array($value)) {
3123
+			return $operator.SP.$this->_wpdb_prepare_using_field($value, $field_obj);
3124
+		}elseif (in_array($operator, $this->_in_style_operators) && ! is_array($value)) {
3125
+			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));
3126
+		}elseif ( ! in_array($operator, $this->_in_style_operators) && is_array($value)) {
3127
+			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));
3128
+		} else {
3129
+			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)));
3130 3130
 		}
3131 3131
 	}
3132 3132
 
@@ -3138,12 +3138,12 @@  discard block
 block discarded – undo
3138 3138
 	 * @param EE_Model_Field_Base|string $field_obj if string, it should be the datatype to be used when querying, eg '%s'
3139 3139
 	 * @return string
3140 3140
 	 */
3141
-	function _construct_between_value( $values, $field_obj ) {
3141
+	function _construct_between_value($values, $field_obj) {
3142 3142
 		$cleaned_values = array();
3143
-		foreach ( $values as $value ) {
3144
-			$cleaned_values[] = $this->_wpdb_prepare_using_field($value,$field_obj);
3143
+		foreach ($values as $value) {
3144
+			$cleaned_values[] = $this->_wpdb_prepare_using_field($value, $field_obj);
3145 3145
 		}
3146
-		return  $cleaned_values[0] . " AND " . $cleaned_values[1];
3146
+		return  $cleaned_values[0]." AND ".$cleaned_values[1];
3147 3147
 	}
3148 3148
 
3149 3149
 
@@ -3159,26 +3159,26 @@  discard block
 block discarded – undo
3159 3159
 	 * @param EE_Model_Field_Base|string $field_obj if string, it should be a wpdb data type like '%s', or '%d'
3160 3160
 	 * @return string of SQL to follow an 'IN' or 'NOT IN' operator
3161 3161
 	 */
3162
-	function _construct_in_value($values,  $field_obj){
3162
+	function _construct_in_value($values, $field_obj) {
3163 3163
 		//check if the value is a CSV list
3164
-		if(is_string($values)){
3164
+		if (is_string($values)) {
3165 3165
 			//in which case, turn it into an array
3166
-			$values = explode(",",$values);
3166
+			$values = explode(",", $values);
3167 3167
 		}
3168 3168
 		$cleaned_values = array();
3169
-		foreach($values as $value){
3170
-			$cleaned_values[] = $this->_wpdb_prepare_using_field($value,$field_obj);
3169
+		foreach ($values as $value) {
3170
+			$cleaned_values[] = $this->_wpdb_prepare_using_field($value, $field_obj);
3171 3171
 		}
3172 3172
 		//we would just LOVE to leave $cleaned_values as an empty array, and return the value as "()",
3173 3173
 		//but unfortunately that's invalid SQL. So instead we return a string which we KNOW will evaluate to be the empty set
3174 3174
 		//which is effectively equivalent to returning "()". We don't return "(0)" because that only works for auto-incrementing columns
3175
-		if(empty($cleaned_values)){
3175
+		if (empty($cleaned_values)) {
3176 3176
 			$all_fields = $this->field_settings();
3177 3177
 			$a_field = array_shift($all_fields);
3178 3178
 			$main_table = $this->_get_main_table();
3179 3179
 			$cleaned_values[] = "SELECT ".$a_field->get_table_column()." FROM ".$main_table->get_table_name()." WHERE FALSE";
3180 3180
 		}
3181
-		return "(".implode(",",$cleaned_values).")";
3181
+		return "(".implode(",", $cleaned_values).")";
3182 3182
 	}
3183 3183
 
3184 3184
 
@@ -3190,16 +3190,16 @@  discard block
 block discarded – undo
3190 3190
 	 * @throws EE_Error
3191 3191
 	 * @return false|null|string
3192 3192
 	 */
3193
-	private function _wpdb_prepare_using_field($value,$field_obj){
3193
+	private function _wpdb_prepare_using_field($value, $field_obj) {
3194 3194
 		/** @type WPDB $wpdb */
3195 3195
 		global $wpdb;
3196
-		if($field_obj instanceof EE_Model_Field_Base){
3197
-			return $wpdb->prepare($field_obj->get_wpdb_data_type(),$this->_prepare_value_for_use_in_db($value, $field_obj));
3198
-		}else{//$field_obj should really just be a data type
3199
-			if( ! in_array($field_obj,$this->_valid_wpdb_data_types)){
3200
-				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)));
3196
+		if ($field_obj instanceof EE_Model_Field_Base) {
3197
+			return $wpdb->prepare($field_obj->get_wpdb_data_type(), $this->_prepare_value_for_use_in_db($value, $field_obj));
3198
+		} else {//$field_obj should really just be a data type
3199
+			if ( ! in_array($field_obj, $this->_valid_wpdb_data_types)) {
3200
+				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)));
3201 3201
 			}
3202
-			return $wpdb->prepare($field_obj,$value);
3202
+			return $wpdb->prepare($field_obj, $value);
3203 3203
 		}
3204 3204
 	}
3205 3205
 
@@ -3211,27 +3211,27 @@  discard block
 block discarded – undo
3211 3211
 	 * @throws EE_Error
3212 3212
 	 * @return EE_Model_Field_Base
3213 3213
 	 */
3214
-	protected function _deduce_field_from_query_param($query_param_name){
3214
+	protected function _deduce_field_from_query_param($query_param_name) {
3215 3215
 		//ok, now proceed with deducing which part is the model's name, and which is the field's name
3216 3216
 		//which will help us find the database table and column
3217 3217
 
3218
-		$query_param_parts = explode(".",$query_param_name);
3219
-		if(empty($query_param_parts)){
3220
-			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));
3218
+		$query_param_parts = explode(".", $query_param_name);
3219
+		if (empty($query_param_parts)) {
3220
+			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));
3221 3221
 		}
3222 3222
 		$number_of_parts = count($query_param_parts);
3223
-		$last_query_param_part = $query_param_parts[ count($query_param_parts) - 1 ];
3224
-		if($number_of_parts == 1){
3223
+		$last_query_param_part = $query_param_parts[count($query_param_parts) - 1];
3224
+		if ($number_of_parts == 1) {
3225 3225
 			$field_name = $last_query_param_part;
3226 3226
 			$model_obj = $this;
3227
-		}else{// $number_of_parts >= 2
3227
+		} else {// $number_of_parts >= 2
3228 3228
 			//the last part is the column name, and there are only 2parts. therefore...
3229 3229
 			$field_name = $last_query_param_part;
3230
-			$model_obj = $this->get_related_model_obj( $query_param_parts[ $number_of_parts - 2 ]);
3230
+			$model_obj = $this->get_related_model_obj($query_param_parts[$number_of_parts - 2]);
3231 3231
 		}
3232
-		try{
3232
+		try {
3233 3233
 			return $model_obj->field_settings_for($field_name);
3234
-		}catch(EE_Error $e){
3234
+		} catch (EE_Error $e) {
3235 3235
 			return null;
3236 3236
 		}
3237 3237
 	}
@@ -3245,13 +3245,13 @@  discard block
 block discarded – undo
3245 3245
 	 * @throws EE_Error
3246 3246
 	 * @return string
3247 3247
 	 */
3248
-	function _get_qualified_column_for_field($field_name){
3248
+	function _get_qualified_column_for_field($field_name) {
3249 3249
 		$all_fields = $this->field_settings();
3250 3250
 		$field = isset($all_fields[$field_name]) ? $all_fields[$field_name] : FALSE;
3251
-		if($field){
3251
+		if ($field) {
3252 3252
 			return $field->get_qualified_column();
3253
-		}else{
3254
-			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)));
3253
+		} else {
3254
+			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)));
3255 3255
 		}
3256 3256
 	}
3257 3257
 
@@ -3265,14 +3265,14 @@  discard block
 block discarded – undo
3265 3265
 	 * @param  mixed|string $limit The limit for this select
3266 3266
 	 * @return string 				The final select join element for the query.
3267 3267
 	 */
3268
-	function _construct_limit_join_select( $table_alias, $limit ) {
3268
+	function _construct_limit_join_select($table_alias, $limit) {
3269 3269
 		$SQL = '';
3270 3270
 
3271
-		foreach ( $this->_tables as $table_obj ) {
3272
-			if ( $table_obj instanceof EE_Primary_Table ) {
3273
-				$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;
3274
-			} elseif ( $table_obj instanceof EE_Secondary_Table ) {
3275
-				$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;
3271
+		foreach ($this->_tables as $table_obj) {
3272
+			if ($table_obj instanceof EE_Primary_Table) {
3273
+				$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;
3274
+			} elseif ($table_obj instanceof EE_Secondary_Table) {
3275
+				$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;
3276 3276
 			}
3277 3277
 		}
3278 3278
 		return $SQL;
@@ -3285,7 +3285,7 @@  discard block
 block discarded – undo
3285 3285
 	 * Eg "wp_post AS Event" or "wp_post AS Event INNER JOIN wp_postmeta Event_Meta ON Event.ID = Event_Meta.post_id"
3286 3286
 	 * @return string SQL
3287 3287
 	 */
3288
-	function _construct_internal_join(){
3288
+	function _construct_internal_join() {
3289 3289
 		$SQL = $this->_get_main_table()->get_table_sql();
3290 3290
 		$SQL .= $this->_construct_internal_join_to_table_with_alias($this->_get_main_table()->get_table_alias());
3291 3291
 		return $SQL;
@@ -3306,17 +3306,17 @@  discard block
 block discarded – undo
3306 3306
 	 * @param string $alias_prefixed table alias to join to (this table should already be in the FROM SQL clause)
3307 3307
 	 * @return string
3308 3308
 	 */
3309
-	function _construct_internal_join_to_table_with_alias($alias_prefixed){
3309
+	function _construct_internal_join_to_table_with_alias($alias_prefixed) {
3310 3310
 		$SQL = '';
3311 3311
 		$alias_sans_prefix = EE_Model_Parser::remove_table_alias_model_relation_chain_prefix($alias_prefixed);
3312
-		foreach($this->_tables as $table_obj){
3313
-			if($table_obj instanceof EE_Secondary_Table){//table is secondary table
3314
-				if($alias_sans_prefix == $table_obj->get_table_alias()){
3312
+		foreach ($this->_tables as $table_obj) {
3313
+			if ($table_obj instanceof EE_Secondary_Table) {//table is secondary table
3314
+				if ($alias_sans_prefix == $table_obj->get_table_alias()) {
3315 3315
 					//so we're joining to this table, meaning the table is already in
3316 3316
 					//the FROM statement, BUT the primary table isn't. So we want
3317 3317
 					//to add the inverse join sql
3318 3318
 					$SQL .= $table_obj->get_inverse_join_sql($alias_prefixed);
3319
-				}else{
3319
+				} else {
3320 3320
 					//just add a regular JOIN to this table from the primary table
3321 3321
 					$SQL .= $table_obj->get_join_sql($alias_prefixed);
3322 3322
 				}
@@ -3330,9 +3330,9 @@  discard block
 block discarded – undo
3330 3330
 	 * 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)
3331 3331
 	 * @return array
3332 3332
 	 */
3333
-	function _get_data_types(){
3333
+	function _get_data_types() {
3334 3334
 		$data_types = array();
3335
-		foreach(array_values($this->field_settings()) as $field_obj){
3335
+		foreach (array_values($this->field_settings()) as $field_obj) {
3336 3336
 			//$data_types[$field_obj->get_table_column()] = $field_obj->get_wpdb_data_type();
3337 3337
 			/** @var $field_obj EE_Model_Field_Base */
3338 3338
 			$data_types[$field_obj->get_qualified_column()] = $field_obj->get_wpdb_data_type();
@@ -3348,11 +3348,11 @@  discard block
 block discarded – undo
3348 3348
 	 * @throws EE_Error
3349 3349
 	 * @return EEM_Base
3350 3350
 	 */
3351
-	function get_related_model_obj($model_name){
3351
+	function get_related_model_obj($model_name) {
3352 3352
 
3353 3353
 		$model_classname = "EEM_".$model_name;
3354
-		if(!class_exists($model_classname)){
3355
-			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));
3354
+		if ( ! class_exists($model_classname)) {
3355
+			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));
3356 3356
 		}
3357 3357
 		$model_obj = call_user_func($model_classname."::instance");
3358 3358
 		return $model_obj;
@@ -3363,7 +3363,7 @@  discard block
 block discarded – undo
3363 3363
 	 * Returns the array of EE_ModelRelations for this model.
3364 3364
 	 * @return EE_Model_Relation_Base[]
3365 3365
 	 */
3366
-	public function relation_settings(){
3366
+	public function relation_settings() {
3367 3367
 		return $this->_model_relations;
3368 3368
 	}
3369 3369
 
@@ -3373,10 +3373,10 @@  discard block
 block discarded – undo
3373 3373
 	 * (Eg, without an event, datetimes have little purpose.)
3374 3374
 	 * @return EE_Belongs_To_Relation[]
3375 3375
 	 */
3376
-	public function belongs_to_relations(){
3376
+	public function belongs_to_relations() {
3377 3377
 		$belongs_to_relations = array();
3378
-		foreach($this->relation_settings() as $model_name => $relation_obj){
3379
-			if($relation_obj instanceof EE_Belongs_To_Relation){
3378
+		foreach ($this->relation_settings() as $model_name => $relation_obj) {
3379
+			if ($relation_obj instanceof EE_Belongs_To_Relation) {
3380 3380
 				$belongs_to_relations[$model_name] = $relation_obj;
3381 3381
 			}
3382 3382
 		}
@@ -3391,15 +3391,15 @@  discard block
 block discarded – undo
3391 3391
 	 * @throws EE_Error
3392 3392
 	 * @return EE_Model_Relation_Base
3393 3393
 	 */
3394
-	public function related_settings_for($relation_name){
3395
-		$relatedModels=$this->relation_settings();
3396
-		if(!array_key_exists($relation_name,$relatedModels)){
3394
+	public function related_settings_for($relation_name) {
3395
+		$relatedModels = $this->relation_settings();
3396
+		if ( ! array_key_exists($relation_name, $relatedModels)) {
3397 3397
 			throw new EE_Error(
3398 3398
 				sprintf(
3399
-					__('Cannot get %s related to %s. There is no model relation of that type. There is, however, %s...','event_espresso'),
3399
+					__('Cannot get %s related to %s. There is no model relation of that type. There is, however, %s...', 'event_espresso'),
3400 3400
 					$relation_name,
3401 3401
 					$this->_get_class_name(),
3402
-					implode( ', ', array_keys( $relatedModels ))
3402
+					implode(', ', array_keys($relatedModels))
3403 3403
 				)
3404 3404
 			);
3405 3405
 		}
@@ -3414,10 +3414,10 @@  discard block
 block discarded – undo
3414 3414
 	 * @throws EE_Error
3415 3415
 	 * @return EE_Model_Field_Base
3416 3416
 	 */
3417
-	public function field_settings_for($fieldName){
3418
-		$fieldSettings=$this->field_settings(true);
3419
-		if( ! array_key_exists($fieldName,$fieldSettings)){
3420
-			throw new EE_Error(sprintf(__("There is no field/column '%s' on '%s'",'event_espresso'),$fieldName,get_class($this)));
3417
+	public function field_settings_for($fieldName) {
3418
+		$fieldSettings = $this->field_settings(true);
3419
+		if ( ! array_key_exists($fieldName, $fieldSettings)) {
3420
+			throw new EE_Error(sprintf(__("There is no field/column '%s' on '%s'", 'event_espresso'), $fieldName, get_class($this)));
3421 3421
 		}
3422 3422
 		return $fieldSettings[$fieldName];
3423 3423
 	}
@@ -3427,11 +3427,11 @@  discard block
 block discarded – undo
3427 3427
 	 * @param string $fieldName a key in the model's _field_settings array
3428 3428
 	 * @return boolean
3429 3429
 	 */
3430
-	public function has_field($fieldName){
3430
+	public function has_field($fieldName) {
3431 3431
 		$fieldSettings = $this->field_settings(true);
3432
-		if( isset($fieldSettings[$fieldName])){
3432
+		if (isset($fieldSettings[$fieldName])) {
3433 3433
 			return true;
3434
-		}else{
3434
+		} else {
3435 3435
 			return false;
3436 3436
 		}
3437 3437
 	}
@@ -3441,11 +3441,11 @@  discard block
 block discarded – undo
3441 3441
 	 * @param string $relation_name possibly one of the keys in the relation_settings array
3442 3442
 	 * @return boolean
3443 3443
 	 */
3444
-	public function has_relation($relation_name){
3444
+	public function has_relation($relation_name) {
3445 3445
 		$relations = $this->relation_settings();
3446
-		if(isset($relations[$relation_name])){
3446
+		if (isset($relations[$relation_name])) {
3447 3447
 			return true;
3448
-		}else{
3448
+		} else {
3449 3449
 			return false;
3450 3450
 		}
3451 3451
 	}
@@ -3457,7 +3457,7 @@  discard block
 block discarded – undo
3457 3457
 	 * @param $field_obj
3458 3458
 	 * @return EE_Model_Field_Base
3459 3459
 	 */
3460
-	public function is_primary_key_field( $field_obj ){
3460
+	public function is_primary_key_field($field_obj) {
3461 3461
 		return $field_obj instanceof EE_Primary_Key_Field_Base ? TRUE : FALSE;
3462 3462
 	}
3463 3463
 
@@ -3469,16 +3469,16 @@  discard block
 block discarded – undo
3469 3469
 	 * @return EE_Model_Field_Base
3470 3470
 	 * @throws EE_Error
3471 3471
 	 */
3472
-	public function get_primary_key_field(){
3473
-		if( $this->_primary_key_field === NULL ){
3474
-			foreach( $this->field_settings( TRUE ) as $field_obj ){
3475
-				if( $this->is_primary_key_field( $field_obj )){
3472
+	public function get_primary_key_field() {
3473
+		if ($this->_primary_key_field === NULL) {
3474
+			foreach ($this->field_settings(TRUE) as $field_obj) {
3475
+				if ($this->is_primary_key_field($field_obj)) {
3476 3476
 					$this->_primary_key_field = $field_obj;
3477 3477
 					break;
3478 3478
 				}
3479 3479
 			}
3480
-			if( ! $this->_primary_key_field instanceof EE_Primary_Key_Field_Base ){
3481
-				throw new EE_Error(sprintf(__("There is no Primary Key defined on model %s",'event_espresso'),get_class($this)));
3480
+			if ( ! $this->_primary_key_field instanceof EE_Primary_Key_Field_Base) {
3481
+				throw new EE_Error(sprintf(__("There is no Primary Key defined on model %s", 'event_espresso'), get_class($this)));
3482 3482
 			}
3483 3483
 		}
3484 3484
 		return $this->_primary_key_field;
@@ -3491,12 +3491,12 @@  discard block
 block discarded – undo
3491 3491
 	 * Internally does some caching.
3492 3492
 	 * @return boolean
3493 3493
 	 */
3494
-	public function has_primary_key_field(){
3495
-		if($this->_has_primary_key_field === null){
3496
-			try{
3494
+	public function has_primary_key_field() {
3495
+		if ($this->_has_primary_key_field === null) {
3496
+			try {
3497 3497
 				$this->get_primary_key_field();
3498 3498
 				$this->_has_primary_key_field = true;
3499
-			}catch(EE_Error $e){
3499
+			} catch (EE_Error $e) {
3500 3500
 				$this->_has_primary_key_field = false;
3501 3501
 			}
3502 3502
 		}
@@ -3510,9 +3510,9 @@  discard block
 block discarded – undo
3510 3510
 	 * @param string $field_class_name class name of field that you want to find. Eg, EE_Datetime_Field, EE_Foreign_Key_Field, etc
3511 3511
 	 * @return EE_Model_Field_Base or null if none is found
3512 3512
 	 */
3513
-	public function get_a_field_of_type($field_class_name){
3514
-		foreach($this->field_settings() as $field){
3515
-			if( $field instanceof $field_class_name ){
3513
+	public function get_a_field_of_type($field_class_name) {
3514
+		foreach ($this->field_settings() as $field) {
3515
+			if ($field instanceof $field_class_name) {
3516 3516
 				return $field;
3517 3517
 			}
3518 3518
 		}
@@ -3526,21 +3526,21 @@  discard block
 block discarded – undo
3526 3526
 	 * @return EE_Foreign_Key_Field_Base
3527 3527
 	 * @throws EE_Error
3528 3528
 	 */
3529
-	public function get_foreign_key_to($model_name){
3530
-		if( ! isset( $this->_cache_foreign_key_to_fields[ $model_name ] ) ){
3531
-			foreach($this->field_settings() as $field){
3529
+	public function get_foreign_key_to($model_name) {
3530
+		if ( ! isset($this->_cache_foreign_key_to_fields[$model_name])) {
3531
+			foreach ($this->field_settings() as $field) {
3532 3532
 //				if(is_subclass_of($field, 'EE_Foreign_Key_Field_Base')){
3533
-				if( $field instanceof EE_Foreign_Key_Field_Base ){
3534
-					if (in_array($model_name,$field->get_model_names_pointed_to() ) ) {
3535
-						$this->_cache_foreign_key_to_fields[ $model_name ] = $field;
3533
+				if ($field instanceof EE_Foreign_Key_Field_Base) {
3534
+					if (in_array($model_name, $field->get_model_names_pointed_to())) {
3535
+						$this->_cache_foreign_key_to_fields[$model_name] = $field;
3536 3536
 					}
3537 3537
 				}
3538 3538
 			}
3539
-			if( ! isset( $this->_cache_foreign_key_to_fields[ $model_name ] ) ){
3540
-				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)));
3539
+			if ( ! isset($this->_cache_foreign_key_to_fields[$model_name])) {
3540
+				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)));
3541 3541
 			}
3542 3542
 		}
3543
-		return $this->_cache_foreign_key_to_fields[ $model_name ];
3543
+		return $this->_cache_foreign_key_to_fields[$model_name];
3544 3544
 	}
3545 3545
 
3546 3546
 
@@ -3551,7 +3551,7 @@  discard block
 block discarded – undo
3551 3551
 	 * a table alias with a model chain prefix, like 'Venue__Event_Venue___Event_Meta'. Either one works
3552 3552
 	 * @return EE_Table_Base
3553 3553
 	 */
3554
-	function get_table_for_alias($table_alias){
3554
+	function get_table_for_alias($table_alias) {
3555 3555
 		$table_alias_sans_model_relation_chain_prefix = EE_Model_Parser::remove_table_alias_model_relation_chain_prefix($table_alias);
3556 3556
 		return $this->_tables[$table_alias_sans_model_relation_chain_prefix]->get_table_name();
3557 3557
 	}
@@ -3564,25 +3564,25 @@  discard block
 block discarded – undo
3564 3564
 	 * @param bool $include_db_only_fields flag indicating whether or not to include the db-only fields
3565 3565
 	 * @return EE_Model_Field_Base[] where the keys are the field's name
3566 3566
 	 */
3567
-	public function field_settings($include_db_only_fields = false){
3568
-		if( $include_db_only_fields ){
3569
-			if( $this->_cached_fields === NULL ){
3567
+	public function field_settings($include_db_only_fields = false) {
3568
+		if ($include_db_only_fields) {
3569
+			if ($this->_cached_fields === NULL) {
3570 3570
 				$this->_cached_fields = array();
3571
-				foreach($this->_fields as $fields_corresponding_to_table){
3572
-					foreach($fields_corresponding_to_table as $field_name => $field_obj){
3573
-						$this->_cached_fields[$field_name]=$field_obj;
3571
+				foreach ($this->_fields as $fields_corresponding_to_table) {
3572
+					foreach ($fields_corresponding_to_table as $field_name => $field_obj) {
3573
+						$this->_cached_fields[$field_name] = $field_obj;
3574 3574
 					}
3575 3575
 				}
3576 3576
 			}
3577 3577
 			return $this->_cached_fields;
3578
-		}else{
3579
-			if( $this->_cached_fields_non_db_only === NULL ){
3578
+		} else {
3579
+			if ($this->_cached_fields_non_db_only === NULL) {
3580 3580
 				$this->_cached_fields_non_db_only = array();
3581
-				foreach($this->_fields as $fields_corresponding_to_table){
3582
-					foreach($fields_corresponding_to_table as $field_name => $field_obj){
3581
+				foreach ($this->_fields as $fields_corresponding_to_table) {
3582
+					foreach ($fields_corresponding_to_table as $field_name => $field_obj) {
3583 3583
 						/** @var $field_obj EE_Model_Field_Base */
3584
-						if( ! $field_obj->is_db_only_field() ){
3585
-							$this->_cached_fields_non_db_only[$field_name]=$field_obj;
3584
+						if ( ! $field_obj->is_db_only_field()) {
3585
+							$this->_cached_fields_non_db_only[$field_name] = $field_obj;
3586 3586
 						}
3587 3587
 					}
3588 3588
 				}
@@ -3601,40 +3601,40 @@  discard block
 block discarded – undo
3601 3601
 	 * @return \EE_Base_Class[] array keys are primary keys (if there is a primary key on the model. if not, numerically indexed)
3602 3602
 	 * @throws \EE_Error
3603 3603
 	 */
3604
-	protected function _create_objects( $rows = array() ) {
3605
-		$array_of_objects=array();
3606
-		if(empty($rows)){
3604
+	protected function _create_objects($rows = array()) {
3605
+		$array_of_objects = array();
3606
+		if (empty($rows)) {
3607 3607
 			return array();
3608 3608
 		}
3609 3609
 		$count_if_model_has_no_primary_key = 0;
3610
-		foreach ( $rows as $row ) {
3611
-			if(empty($row)){//wp did its weird thing where it returns an array like array(0=>null), which is totally not helpful...
3610
+		foreach ($rows as $row) {
3611
+			if (empty($row)) {//wp did its weird thing where it returns an array like array(0=>null), which is totally not helpful...
3612 3612
 				return array();
3613 3613
 			}
3614
-			$classInstance=$this->instantiate_class_from_array_or_object($row);
3615
-			if( ! $classInstance ) {
3616
-				throw new EE_Error( sprintf( __( 'Could not create instance of class %s from row %s', 'event_espresso' ), $this->get_this_model_name(), http_build_query( $row ) ) );
3614
+			$classInstance = $this->instantiate_class_from_array_or_object($row);
3615
+			if ( ! $classInstance) {
3616
+				throw new EE_Error(sprintf(__('Could not create instance of class %s from row %s', 'event_espresso'), $this->get_this_model_name(), http_build_query($row)));
3617 3617
 			}
3618 3618
 			//set the timezone on the instantiated objects
3619
-			$classInstance->set_timezone( $this->_timezone );
3619
+			$classInstance->set_timezone($this->_timezone);
3620 3620
 			//make sure if there is any timezone setting present that we set the timezone for the object
3621
-			$array_of_objects[$this->has_primary_key_field() ? $classInstance->ID() : $count_if_model_has_no_primary_key++]=$classInstance;
3621
+			$array_of_objects[$this->has_primary_key_field() ? $classInstance->ID() : $count_if_model_has_no_primary_key++] = $classInstance;
3622 3622
 			//also, for all the relations of type BelongsTo, see if we can cache
3623 3623
 			//those related models
3624 3624
 			//(we could do this for other relations too, but if there are conditions
3625 3625
 			//that filtered out some fo the results, then we'd be caching an incomplete set
3626 3626
 			//so it requires a little more thought than just caching them immediately...)
3627
-			foreach($this->_model_relations as $modelName => $relation_obj){
3628
-				if( $relation_obj instanceof EE_Belongs_To_Relation){
3627
+			foreach ($this->_model_relations as $modelName => $relation_obj) {
3628
+				if ($relation_obj instanceof EE_Belongs_To_Relation) {
3629 3629
 					//check if this model's INFO is present. If so, cache it on the model
3630 3630
 					$other_model = $relation_obj->get_other_model();
3631 3631
 
3632 3632
 					$other_model_obj_maybe = $other_model->instantiate_class_from_array_or_object($row);
3633 3633
 
3634 3634
 					//if we managed to make a model object from the results, cache it on the main model object
3635
-					if( $other_model_obj_maybe ){
3635
+					if ($other_model_obj_maybe) {
3636 3636
 						//set timezone on these other model objects if they are present
3637
-						$other_model_obj_maybe->set_timezone( $this->_timezone );
3637
+						$other_model_obj_maybe->set_timezone($this->_timezone);
3638 3638
 						$classInstance->cache($modelName, $other_model_obj_maybe);
3639 3639
 					}
3640 3640
 				}
@@ -3655,12 +3655,12 @@  discard block
 block discarded – undo
3655 3655
 
3656 3656
 		$this_model_fields_and_values = array();
3657 3657
 		//setup the row using default values;
3658
-		foreach ( $this->field_settings() as $field_name => $field_obj ) {
3658
+		foreach ($this->field_settings() as $field_name => $field_obj) {
3659 3659
 			$this_model_fields_and_values[$field_name] = $field_obj->get_default_value();
3660 3660
 		}
3661 3661
 
3662 3662
 		$className = $this->_get_class_name();
3663
-		$classInstance = EE_Registry::instance()->load_class( $className, array( $this_model_fields_and_values ), FALSE, FALSE );
3663
+		$classInstance = EE_Registry::instance()->load_class($className, array($this_model_fields_and_values), FALSE, FALSE);
3664 3664
 
3665 3665
 		return $classInstance;
3666 3666
 	}
@@ -3673,45 +3673,45 @@  discard block
 block discarded – undo
3673 3673
 	 * or an stdClass where each property is the name of a column,
3674 3674
 	 * @return EE_Base_Class
3675 3675
 	 */
3676
-	public function instantiate_class_from_array_or_object($cols_n_values){
3677
-		if( ! is_array( $cols_n_values ) && is_object( $cols_n_values )) {
3678
-			$cols_n_values = get_object_vars( $cols_n_values );
3676
+	public function instantiate_class_from_array_or_object($cols_n_values) {
3677
+		if ( ! is_array($cols_n_values) && is_object($cols_n_values)) {
3678
+			$cols_n_values = get_object_vars($cols_n_values);
3679 3679
 		}
3680 3680
 		$primary_key = NULL;
3681 3681
 		//make sure the array only has keys that are fields/columns on this model
3682
-		$this_model_fields_n_values = $this->_deduce_fields_n_values_from_cols_n_values( $cols_n_values );
3683
-		if( $this->has_primary_key_field() && isset( $this_model_fields_n_values[ $this->primary_key_name() ] ) ){
3684
-			$primary_key = $this_model_fields_n_values[ $this->primary_key_name() ];
3682
+		$this_model_fields_n_values = $this->_deduce_fields_n_values_from_cols_n_values($cols_n_values);
3683
+		if ($this->has_primary_key_field() && isset($this_model_fields_n_values[$this->primary_key_name()])) {
3684
+			$primary_key = $this_model_fields_n_values[$this->primary_key_name()];
3685 3685
 		}
3686
-		$className=$this->_get_class_name();
3686
+		$className = $this->_get_class_name();
3687 3687
 
3688 3688
 		//check we actually found results that we can use to build our model object
3689 3689
 		//if not, return null
3690
-		if( $this->has_primary_key_field()){
3691
-			if(empty( $this_model_fields_n_values[$this->primary_key_name()] )){
3690
+		if ($this->has_primary_key_field()) {
3691
+			if (empty($this_model_fields_n_values[$this->primary_key_name()])) {
3692 3692
 				return NULL;
3693 3693
 			}
3694
-		}else if($this->unique_indexes()){
3694
+		} else if ($this->unique_indexes()) {
3695 3695
 			$first_column = reset($this_model_fields_n_values);
3696
-			if(empty($first_column)){
3696
+			if (empty($first_column)) {
3697 3697
 				return NULL;
3698 3698
 			}
3699 3699
 		}
3700 3700
 
3701 3701
 		// if there is no primary key or the object doesn't already exist in the entity map, then create a new instance
3702
-		if ( $primary_key){
3703
-			$classInstance = $this->get_from_entity_map( $primary_key );
3704
-			if( ! $classInstance) {
3705
-				$classInstance = EE_Registry::instance()->load_class( $className, array( $this_model_fields_n_values, $this->_timezone ), TRUE, FALSE );
3702
+		if ($primary_key) {
3703
+			$classInstance = $this->get_from_entity_map($primary_key);
3704
+			if ( ! $classInstance) {
3705
+				$classInstance = EE_Registry::instance()->load_class($className, array($this_model_fields_n_values, $this->_timezone), TRUE, FALSE);
3706 3706
 				// add this new object to the entity map
3707
-				$classInstance = $this->add_to_entity_map( $classInstance );
3707
+				$classInstance = $this->add_to_entity_map($classInstance);
3708 3708
 			}
3709
-		}else{
3710
-			$classInstance = EE_Registry::instance()->load_class( $className, array( $this_model_fields_n_values, $this->_timezone ), TRUE, FALSE );
3709
+		} else {
3710
+			$classInstance = EE_Registry::instance()->load_class($className, array($this_model_fields_n_values, $this->_timezone), TRUE, FALSE);
3711 3711
 		}
3712 3712
 
3713 3713
 			//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.
3714
-		$this->set_timezone( $classInstance->get_timezone() );
3714
+		$this->set_timezone($classInstance->get_timezone());
3715 3715
 		return $classInstance;
3716 3716
 	}
3717 3717
 	/**
@@ -3719,8 +3719,8 @@  discard block
 block discarded – undo
3719 3719
 	 * @param int|string $id the ID of the model object
3720 3720
 	 * @return EE_Base_Class
3721 3721
 	 */
3722
-	public function get_from_entity_map( $id ){
3723
-		return isset( $this->_entity_map[ $id ] ) ? $this->_entity_map[ $id ] : NULL;
3722
+	public function get_from_entity_map($id) {
3723
+		return isset($this->_entity_map[$id]) ? $this->_entity_map[$id] : NULL;
3724 3724
 	}
3725 3725
 
3726 3726
 
@@ -3739,21 +3739,21 @@  discard block
 block discarded – undo
3739 3739
 	 * @throws EE_Error
3740 3740
 	 * @return \EE_Base_Class
3741 3741
 	 */
3742
-	public function add_to_entity_map( EE_Base_Class $object) {
3742
+	public function add_to_entity_map(EE_Base_Class $object) {
3743 3743
 		$className = $this->_get_class_name();
3744
-		if( ! $object instanceof $className ){
3745
-			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 ) );
3744
+		if ( ! $object instanceof $className) {
3745
+			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));
3746 3746
 		}
3747 3747
 		/** @var $object EE_Base_Class */
3748
-		if ( ! $object->ID() ){
3749
-			throw new EE_Error(sprintf(__("You tried storing a model object with NO ID in the %s entity mapper.", "event_espresso"),get_class($this)));
3748
+		if ( ! $object->ID()) {
3749
+			throw new EE_Error(sprintf(__("You tried storing a model object with NO ID in the %s entity mapper.", "event_espresso"), get_class($this)));
3750 3750
 		}
3751 3751
 		// double check it's not already there
3752
-		$classInstance = $this->get_from_entity_map( $object->ID() );
3753
-		if ( $classInstance ) {
3752
+		$classInstance = $this->get_from_entity_map($object->ID());
3753
+		if ($classInstance) {
3754 3754
 			return $classInstance;
3755 3755
 		} else {
3756
-			$this->_entity_map[ $object->ID() ] = $object;
3756
+			$this->_entity_map[$object->ID()] = $object;
3757 3757
 			return $object;
3758 3758
 		}
3759 3759
 	}
@@ -3766,8 +3766,8 @@  discard block
 block discarded – undo
3766 3766
 	 * @param array $cols_n_values
3767 3767
 	 * @return array
3768 3768
 	 */
3769
-	public function deduce_fields_n_values_from_cols_n_values( $cols_n_values ) {
3770
-		return $this->_deduce_fields_n_values_from_cols_n_values( $cols_n_values );
3769
+	public function deduce_fields_n_values_from_cols_n_values($cols_n_values) {
3770
+		return $this->_deduce_fields_n_values_from_cols_n_values($cols_n_values);
3771 3771
 	}
3772 3772
 
3773 3773
 
@@ -3780,40 +3780,40 @@  discard block
 block discarded – undo
3780 3780
 	 * @param string $cols_n_values
3781 3781
 	 * @return array
3782 3782
 	 */
3783
-	protected function _deduce_fields_n_values_from_cols_n_values( $cols_n_values ){
3783
+	protected function _deduce_fields_n_values_from_cols_n_values($cols_n_values) {
3784 3784
 		$this_model_fields_n_values = array();
3785
-		foreach( $this->get_tables() as $table_alias => $table_obj ) {
3786
-			$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() );
3785
+		foreach ($this->get_tables() as $table_alias => $table_obj) {
3786
+			$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());
3787 3787
 			//there is a primary key on this table and its not set. Use defaults for all its columns
3788
-			if( $table_obj->get_pk_column() && $table_pk_value === NULL ){
3789
-				foreach( $this->_get_fields_for_table( $table_alias ) as $field_name => $field_obj ) {
3790
-					if( ! $field_obj->is_db_only_field() ){
3788
+			if ($table_obj->get_pk_column() && $table_pk_value === NULL) {
3789
+				foreach ($this->_get_fields_for_table($table_alias) as $field_name => $field_obj) {
3790
+					if ( ! $field_obj->is_db_only_field()) {
3791 3791
 						//prepare field as if its coming from db
3792
-						$prepared_value = $field_obj->prepare_for_set( $field_obj->get_default_value() );
3793
-						$this_model_fields_n_values[$field_name] = $field_obj->prepare_for_use_in_db( $prepared_value );
3792
+						$prepared_value = $field_obj->prepare_for_set($field_obj->get_default_value());
3793
+						$this_model_fields_n_values[$field_name] = $field_obj->prepare_for_use_in_db($prepared_value);
3794 3794
 					}
3795 3795
 				}
3796
-			}else{
3796
+			} else {
3797 3797
 				//the table's rows existed. Use their values
3798
-				foreach( $this->_get_fields_for_table( $table_alias ) as $field_name => $field_obj ) {
3799
-					if( ! $field_obj->is_db_only_field() )
3800
-					$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() );
3798
+				foreach ($this->_get_fields_for_table($table_alias) as $field_name => $field_obj) {
3799
+					if ( ! $field_obj->is_db_only_field())
3800
+					$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());
3801 3801
 				}
3802 3802
 			}
3803 3803
 		}
3804 3804
 		return $this_model_fields_n_values;
3805 3805
 	}
3806 3806
 
3807
-	protected function _get_column_value_with_table_alias_or_not( $cols_n_values, $qualified_column, $regular_column ){
3807
+	protected function _get_column_value_with_table_alias_or_not($cols_n_values, $qualified_column, $regular_column) {
3808 3808
 		//ask the field what it think it's table_name.column_name should be, and call it the "qualified column"
3809 3809
 		//does the field on the model relate to this column retrieved from the db?
3810 3810
 		//or is it a db-only field? (not relating to the model)
3811
-		if( isset( $cols_n_values[ $qualified_column ] ) ){
3812
-			$value = $cols_n_values[ $qualified_column ];
3811
+		if (isset($cols_n_values[$qualified_column])) {
3812
+			$value = $cols_n_values[$qualified_column];
3813 3813
 
3814
-		}elseif( isset( $cols_n_values[ $regular_column ] ) ){
3815
-			$value = $cols_n_values[ $regular_column ];
3816
-		}else{
3814
+		}elseif (isset($cols_n_values[$regular_column])) {
3815
+			$value = $cols_n_values[$regular_column];
3816
+		} else {
3817 3817
 			$value = NULL;
3818 3818
 		}
3819 3819
 
@@ -3831,23 +3831,23 @@  discard block
 block discarded – undo
3831 3831
 	 * @param int|string $id
3832 3832
 	 * @return EE_Base_Class
3833 3833
 	 */
3834
-	public function refresh_entity_map_from_db( $id ){
3835
-		$obj_in_map = $this->get_from_entity_map( $id );
3836
-		if( $obj_in_map ){
3837
-			$wpdb_results = $this->_get_all_wpdb_results( array( array ( $this->get_primary_key_field()->get_name() => $id ), 'limit' => 1 ) );
3838
-			if( $wpdb_results && is_array( $wpdb_results ) ){
3839
-				$one_row = reset( $wpdb_results );
3840
-				foreach( $this->_deduce_fields_n_values_from_cols_n_values($one_row ) as $field_name => $db_value ) {
3841
-					$obj_in_map->set_from_db( $field_name, $db_value );
3834
+	public function refresh_entity_map_from_db($id) {
3835
+		$obj_in_map = $this->get_from_entity_map($id);
3836
+		if ($obj_in_map) {
3837
+			$wpdb_results = $this->_get_all_wpdb_results(array(array($this->get_primary_key_field()->get_name() => $id), 'limit' => 1));
3838
+			if ($wpdb_results && is_array($wpdb_results)) {
3839
+				$one_row = reset($wpdb_results);
3840
+				foreach ($this->_deduce_fields_n_values_from_cols_n_values($one_row) as $field_name => $db_value) {
3841
+					$obj_in_map->set_from_db($field_name, $db_value);
3842 3842
 				}
3843 3843
 				//clear the cache of related model objects
3844
-				foreach ( $this->relation_settings() as $relation_name => $relation_obj ){
3845
-					$obj_in_map->clear_cache($relation_name, NULL, TRUE );
3844
+				foreach ($this->relation_settings() as $relation_name => $relation_obj) {
3845
+					$obj_in_map->clear_cache($relation_name, NULL, TRUE);
3846 3846
 				}
3847 3847
 			}
3848 3848
 			return $obj_in_map;
3849
-		}else{
3850
-			return $this->get_one_by_ID( $id );
3849
+		} else {
3850
+			return $this->get_one_by_ID($id);
3851 3851
 		}
3852 3852
 	}
3853 3853
 
@@ -3865,24 +3865,24 @@  discard block
 block discarded – undo
3865 3865
 	 * @param EE_Base_Class $replacing_model_obj
3866 3866
 	 * @return \EE_Base_Class
3867 3867
 	 */
3868
-	public function refresh_entity_map_with( $id, $replacing_model_obj ) {
3869
-		$obj_in_map = $this->get_from_entity_map( $id );
3870
-		if( $obj_in_map ){
3871
-			if( $replacing_model_obj instanceof EE_Base_Class ){
3872
-				foreach( $replacing_model_obj->model_field_array() as $field_name => $value ) {
3873
-					$obj_in_map->set( $field_name, $value );
3868
+	public function refresh_entity_map_with($id, $replacing_model_obj) {
3869
+		$obj_in_map = $this->get_from_entity_map($id);
3870
+		if ($obj_in_map) {
3871
+			if ($replacing_model_obj instanceof EE_Base_Class) {
3872
+				foreach ($replacing_model_obj->model_field_array() as $field_name => $value) {
3873
+					$obj_in_map->set($field_name, $value);
3874 3874
 				}
3875 3875
 				//make the model object in the entity map's cache match the $replacing_model_obj
3876
-				foreach ( $this->relation_settings() as $relation_name => $relation_obj ){
3877
-					$obj_in_map->clear_cache($relation_name, NULL, TRUE );
3878
-					foreach( $replacing_model_obj->get_all_from_cache( $relation_name ) as $cache_id => $cached_obj ) {
3879
-						$obj_in_map->cache( $relation_name, $cached_obj, $cache_id );
3876
+				foreach ($this->relation_settings() as $relation_name => $relation_obj) {
3877
+					$obj_in_map->clear_cache($relation_name, NULL, TRUE);
3878
+					foreach ($replacing_model_obj->get_all_from_cache($relation_name) as $cache_id => $cached_obj) {
3879
+						$obj_in_map->cache($relation_name, $cached_obj, $cache_id);
3880 3880
 					}
3881 3881
 				}
3882 3882
 			}
3883 3883
 			return $obj_in_map;
3884
-		}else{
3885
-			$this->add_to_entity_map( $replacing_model_obj );
3884
+		} else {
3885
+			$this->add_to_entity_map($replacing_model_obj);
3886 3886
 			return $replacing_model_obj;
3887 3887
 		}
3888 3888
 	}
@@ -3895,7 +3895,7 @@  discard block
 block discarded – undo
3895 3895
 	 * require_once($this->_getClassName().".class.php");
3896 3896
 	 * @return string
3897 3897
 	 */
3898
-	private function _get_class_name(){
3898
+	private function _get_class_name() {
3899 3899
 		return "EE_".$this->get_this_model_name();
3900 3900
 	}
3901 3901
 
@@ -3908,10 +3908,10 @@  discard block
 block discarded – undo
3908 3908
 	 * @param int $quantity
3909 3909
 	 * @return string
3910 3910
 	 */
3911
-	public function item_name($quantity = 1){
3912
-		if($quantity == 1){
3911
+	public function item_name($quantity = 1) {
3912
+		if ($quantity == 1) {
3913 3913
 			return $this->singular_item;
3914
-		}else{
3914
+		} else {
3915 3915
 			return $this->plural_item;
3916 3916
 		}
3917 3917
 	}
@@ -3940,13 +3940,13 @@  discard block
 block discarded – undo
3940 3940
 	 * @throws EE_Error
3941 3941
 	 * @return mixed whatever the plugin which calls add_filter decides
3942 3942
 	 */
3943
-	public function __call($methodName,$args){
3944
-		$className=get_class($this);
3945
-		$tagName="FHEE__{$className}__{$methodName}";
3946
-		if(!has_filter($tagName)){
3943
+	public function __call($methodName, $args) {
3944
+		$className = get_class($this);
3945
+		$tagName = "FHEE__{$className}__{$methodName}";
3946
+		if ( ! has_filter($tagName)) {
3947 3947
 			throw new EE_Error(
3948 3948
 				sprintf(
3949
-					__( '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' ),
3949
+					__('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'),
3950 3950
 					$methodName,
3951 3951
 					$className,
3952 3952
 					$tagName,
@@ -3955,7 +3955,7 @@  discard block
 block discarded – undo
3955 3955
 			);
3956 3956
 		}
3957 3957
 
3958
-		return apply_filters($tagName,null,$this,$args);
3958
+		return apply_filters($tagName, null, $this, $args);
3959 3959
 	}
3960 3960
 
3961 3961
 
@@ -3968,22 +3968,22 @@  discard block
 block discarded – undo
3968 3968
 	 * @throws EE_Error
3969 3969
 	 * @return EE_Base_Class
3970 3970
 	 */
3971
-	public function ensure_is_obj( $base_class_obj_or_id, $ensure_is_in_db = FALSE ){
3971
+	public function ensure_is_obj($base_class_obj_or_id, $ensure_is_in_db = FALSE) {
3972 3972
 		$className = $this->_get_class_name();
3973 3973
 		$primary_key_field = $this->get_primary_key_field();
3974
-		if( $base_class_obj_or_id instanceof $className ){
3974
+		if ($base_class_obj_or_id instanceof $className) {
3975 3975
 			$model_object = $base_class_obj_or_id;
3976
-		}elseif( $primary_key_field instanceof EE_Primary_Key_Int_Field && (
3977
-				is_int( $base_class_obj_or_id ) ||
3978
-				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)
3976
+		}elseif ($primary_key_field instanceof EE_Primary_Key_Int_Field && (
3977
+				is_int($base_class_obj_or_id) ||
3978
+				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)
3979 3979
 			$model_object = $this->get_one_by_ID($base_class_obj_or_id);
3980
-		}elseif( $primary_key_field instanceof EE_Primary_Key_String_Field && is_string($base_class_obj_or_id) ){
3980
+		}elseif ($primary_key_field instanceof EE_Primary_Key_String_Field && is_string($base_class_obj_or_id)) {
3981 3981
 			//assume its a string representation of the object
3982 3982
 			$model_object = $this->get_one_by_ID($base_class_obj_or_id);
3983
-		}else{
3984
-			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)));
3983
+		} else {
3984
+			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)));
3985 3985
 		}
3986
-		if( $model_object->ID() == NULL && $ensure_is_in_db){
3986
+		if ($model_object->ID() == NULL && $ensure_is_in_db) {
3987 3987
 			$model_object->save();
3988 3988
 		}
3989 3989
 		return $model_object;
@@ -3999,19 +3999,19 @@  discard block
 block discarded – undo
3999 3999
 	 * @return int|string depending on the type of this model object's ID
4000 4000
 	 * @throws EE_Error
4001 4001
 	 */
4002
-	public function ensure_is_ID($base_class_obj_or_id){
4002
+	public function ensure_is_ID($base_class_obj_or_id) {
4003 4003
 		$className = $this->_get_class_name();
4004
-		if( $base_class_obj_or_id instanceof $className ){
4004
+		if ($base_class_obj_or_id instanceof $className) {
4005 4005
 			/** @var $base_class_obj_or_id EE_Base_Class */
4006 4006
 			$id = $base_class_obj_or_id->ID();
4007
-		}elseif(is_int($base_class_obj_or_id)){
4007
+		}elseif (is_int($base_class_obj_or_id)) {
4008 4008
 			//assume it's an ID
4009 4009
 			$id = $base_class_obj_or_id;
4010
-		}elseif(is_string($base_class_obj_or_id)){
4010
+		}elseif (is_string($base_class_obj_or_id)) {
4011 4011
 			//assume its a string representation of the object
4012 4012
 			$id = $base_class_obj_or_id;
4013
-		}else{
4014
-			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)));
4013
+		} else {
4014
+			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)));
4015 4015
 		}
4016 4016
 		return $id;
4017 4017
 	}
@@ -4034,14 +4034,14 @@  discard block
 block discarded – undo
4034 4034
 	 * @param int $values_already_prepared like one of the constants on EEM_Base
4035 4035
 	 * @return void
4036 4036
 	 */
4037
-	public function assume_values_already_prepared_by_model_object($values_already_prepared = self::not_prepared_by_model_object){
4037
+	public function assume_values_already_prepared_by_model_object($values_already_prepared = self::not_prepared_by_model_object) {
4038 4038
 		$this->_values_already_prepared_by_model_object = $values_already_prepared;
4039 4039
 	}
4040 4040
 	/**
4041 4041
 	 * Read comments for assume_values_already_prepared_by_model_object()
4042 4042
 	 * @return int
4043 4043
 	 */
4044
-	public function get_assumption_concerning_values_already_prepared_by_model_object(){
4044
+	public function get_assumption_concerning_values_already_prepared_by_model_object() {
4045 4045
 		return $this->_values_already_prepared_by_model_object;
4046 4046
 	}
4047 4047
 
@@ -4049,17 +4049,17 @@  discard block
 block discarded – undo
4049 4049
 	 * Gets all the indexes on this model
4050 4050
 	 * @return EE_Index[]
4051 4051
 	 */
4052
-	public function indexes(){
4052
+	public function indexes() {
4053 4053
 		return $this->_indexes;
4054 4054
 	}
4055 4055
 	/**
4056 4056
 	 * Gets all the Unique Indexes on this model
4057 4057
 	 * @return EE_Unique_Index[]
4058 4058
 	 */
4059
-	public function unique_indexes(){
4059
+	public function unique_indexes() {
4060 4060
 		$unique_indexes = array();
4061
-		foreach($this->_indexes as $name => $index){
4062
-			if($index instanceof EE_Unique_Index){
4061
+		foreach ($this->_indexes as $name => $index) {
4062
+			if ($index instanceof EE_Unique_Index) {
4063 4063
 				$unique_indexes [$name] = $index;
4064 4064
 			}
4065 4065
 		}
@@ -4072,9 +4072,9 @@  discard block
 block discarded – undo
4072 4072
 	 * on a primary index
4073 4073
 	 * @return EE_Model_Field_Base[]
4074 4074
 	 */
4075
-	public function get_combined_primary_key_fields(){
4076
-		foreach($this->indexes() as $index){
4077
-			if($index instanceof EE_Primary_Key_Index){
4075
+	public function get_combined_primary_key_fields() {
4076
+		foreach ($this->indexes() as $index) {
4077
+			if ($index instanceof EE_Primary_Key_Index) {
4078 4078
 				return $index->fields();
4079 4079
 			}
4080 4080
 		}
@@ -4087,7 +4087,7 @@  discard block
 block discarded – undo
4087 4087
 	 * @param array $cols_n_values keys are field names, values are their values
4088 4088
 	 * @return string
4089 4089
 	 */
4090
-	public function get_index_primary_key_string($cols_n_values){
4090
+	public function get_index_primary_key_string($cols_n_values) {
4091 4091
 		$cols_n_values_for_primary_key_index = array_intersect_key($cols_n_values, $this->get_combined_primary_key_fields());
4092 4092
 		return http_build_query($cols_n_values_for_primary_key_index);
4093 4093
 	}
@@ -4099,13 +4099,13 @@  discard block
 block discarded – undo
4099 4099
 	 * @param string $index_primary_key_string
4100 4100
 	 * @return null|array
4101 4101
 	 */
4102
-	function parse_index_primary_key_string( $index_primary_key_string) {
4102
+	function parse_index_primary_key_string($index_primary_key_string) {
4103 4103
 		$key_fields = $this->get_combined_primary_key_fields();
4104 4104
 		//check all of them are in the $id
4105 4105
 		$key_vals_in_combined_pk = array();
4106
-		parse_str( $index_primary_key_string, $key_vals_in_combined_pk );
4107
-		foreach( $key_fields as $key_field_name => $field_obj ) {
4108
-			if( ! isset( $key_vals_in_combined_pk[ $key_field_name ] ) ){
4106
+		parse_str($index_primary_key_string, $key_vals_in_combined_pk);
4107
+		foreach ($key_fields as $key_field_name => $field_obj) {
4108
+			if ( ! isset($key_vals_in_combined_pk[$key_field_name])) {
4109 4109
 				return NULL;
4110 4110
 			}
4111 4111
 		}
@@ -4118,10 +4118,10 @@  discard block
 block discarded – undo
4118 4118
 	 * @param array $key_vals
4119 4119
 	 * @return boolean
4120 4120
 	 */
4121
-	function has_all_combined_primary_key_fields( $key_vals ) {
4122
-		$keys_it_should_have = array_keys( $this->get_combined_primary_key_fields() );
4123
-		foreach( $keys_it_should_have as $key ){
4124
-			if( ! isset( $key_vals[ $key ] ) ){
4121
+	function has_all_combined_primary_key_fields($key_vals) {
4122
+		$keys_it_should_have = array_keys($this->get_combined_primary_key_fields());
4123
+		foreach ($keys_it_should_have as $key) {
4124
+			if ( ! isset($key_vals[$key])) {
4125 4125
 				return false;
4126 4126
 			}
4127 4127
 		}
@@ -4137,23 +4137,23 @@  discard block
 block discarded – undo
4137 4137
 	 * @throws EE_Error
4138 4138
 	 * @return \EE_Base_Class[] Array keys are object IDs (if there is a primary key on the model. if not, numerically indexed)
4139 4139
 	 */
4140
-	public function get_all_copies($model_object_or_attributes_array, $query_params = array()){
4140
+	public function get_all_copies($model_object_or_attributes_array, $query_params = array()) {
4141 4141
 
4142
-		if($model_object_or_attributes_array instanceof EE_Base_Class){
4142
+		if ($model_object_or_attributes_array instanceof EE_Base_Class) {
4143 4143
 			$attributes_array = $model_object_or_attributes_array->model_field_array();
4144
-		}elseif(is_array($model_object_or_attributes_array)){
4144
+		}elseif (is_array($model_object_or_attributes_array)) {
4145 4145
 			$attributes_array = $model_object_or_attributes_array;
4146
-		}else{
4147
-			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));
4146
+		} else {
4147
+			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));
4148 4148
 		}
4149 4149
 		//even copies obviously won't have the same ID, so remove the primary key
4150 4150
 		//from the WHERE conditions for finding copies (if there is a primary key, of course)
4151
-		if($this->has_primary_key_field() && isset($attributes_array[$this->primary_key_name()])){
4151
+		if ($this->has_primary_key_field() && isset($attributes_array[$this->primary_key_name()])) {
4152 4152
 			unset($attributes_array[$this->primary_key_name()]);
4153 4153
 		}
4154
-		if(isset($query_params[0])){
4155
-			$query_params[0] = array_merge($attributes_array,$query_params);
4156
-		}else{
4154
+		if (isset($query_params[0])) {
4155
+			$query_params[0] = array_merge($attributes_array, $query_params);
4156
+		} else {
4157 4157
 			$query_params[0] = $attributes_array;
4158 4158
 		}
4159 4159
 		return $this->get_all($query_params);
@@ -4167,16 +4167,16 @@  discard block
 block discarded – undo
4167 4167
 	 * @param array $query_params
4168 4168
 	 * @return EE_Base_Class
4169 4169
 	 */
4170
-	function get_one_copy($model_object_or_attributes_array,$query_params = array()){
4171
-		if( ! is_array( $query_params ) ){
4172
-			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' );
4170
+	function get_one_copy($model_object_or_attributes_array, $query_params = array()) {
4171
+		if ( ! is_array($query_params)) {
4172
+			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');
4173 4173
 			$query_params = array();
4174 4174
 		}
4175 4175
 		$query_params['limit'] = 1;
4176
-		$copies = $this->get_all_copies($model_object_or_attributes_array,$query_params);
4177
-		if(is_array($copies)){
4176
+		$copies = $this->get_all_copies($model_object_or_attributes_array, $query_params);
4177
+		if (is_array($copies)) {
4178 4178
 			return array_shift($copies);
4179
-		}else{
4179
+		} else {
4180 4180
 			return null;
4181 4181
 		}
4182 4182
 	}
@@ -4190,10 +4190,10 @@  discard block
 block discarded – undo
4190 4190
 	 * @param int|string $id the value of the primary key to update
4191 4191
 	 * @return int number of rows updated
4192 4192
 	 */
4193
-	public function update_by_ID($fields_n_values,$id){
4193
+	public function update_by_ID($fields_n_values, $id) {
4194 4194
 		$query_params = array(0=>array($this->get_primary_key_field()->get_name() => $id),
4195 4195
 			'default_where_conditions'=>'other_models_only',);
4196
-		return $this->update($fields_n_values,$query_params);
4196
+		return $this->update($fields_n_values, $query_params);
4197 4197
 	}
4198 4198
 
4199 4199
 
@@ -4204,12 +4204,12 @@  discard block
 block discarded – undo
4204 4204
 	 * @return string an operator which can be used in SQL
4205 4205
 	 * @throws EE_Error
4206 4206
 	 */
4207
-	private function _prepare_operator_for_sql($operator_supplied){
4207
+	private function _prepare_operator_for_sql($operator_supplied) {
4208 4208
 		$sql_operator = isset($this->_valid_operators[$operator_supplied]) ? $this->_valid_operators[$operator_supplied] : null;
4209
-		if($sql_operator){
4209
+		if ($sql_operator) {
4210 4210
 			return $sql_operator;
4211
-		}else{
4212
-			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))));
4211
+		} else {
4212
+			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))));
4213 4213
 		}
4214 4214
 	}
4215 4215
 
@@ -4219,10 +4219,10 @@  discard block
 block discarded – undo
4219 4219
 	 * @param array $query_params like get_all's
4220 4220
 	 * @return string[]
4221 4221
 	 */
4222
-	public function get_all_names($query_params = array()){
4222
+	public function get_all_names($query_params = array()) {
4223 4223
 		$objs = $this->get_all($query_params);
4224 4224
 		$names = array();
4225
-		foreach($objs as $obj){
4225
+		foreach ($objs as $obj) {
4226 4226
 			$names[$obj->ID()] = $obj->name();
4227 4227
 		}
4228 4228
 		return $names;
@@ -4237,22 +4237,22 @@  discard block
 block discarded – undo
4237 4237
 	 * @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
4238 4238
 	 * @return array
4239 4239
 	 */
4240
-	public function get_IDs( $model_objects, $filter_out_empty_ids = false) {
4241
-		if( ! $this->has_primary_key_field() ) {
4242
-			if( WP_DEBUG ) {
4243
-				EE_Error::add_error( __( 'Trying to get IDs from a model than has no primary key', 'event_espresso' ), __FILE__, __FUNCTION__, __LINE__ );
4240
+	public function get_IDs($model_objects, $filter_out_empty_ids = false) {
4241
+		if ( ! $this->has_primary_key_field()) {
4242
+			if (WP_DEBUG) {
4243
+				EE_Error::add_error(__('Trying to get IDs from a model than has no primary key', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__);
4244 4244
 				return array();
4245 4245
 			}
4246 4246
 		}
4247 4247
 		$IDs = array();
4248
-		foreach( $model_objects as $model_object ) {
4248
+		foreach ($model_objects as $model_object) {
4249 4249
 			$id = $model_object->ID();
4250
-			if( ! $id ) {
4251
-				if( $filter_out_empty_ids ) {
4250
+			if ( ! $id) {
4251
+				if ($filter_out_empty_ids) {
4252 4252
 					continue;
4253 4253
 				}
4254
-				if( WP_DEBUG ) {
4255
-					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__ );
4254
+				if (WP_DEBUG) {
4255
+					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__);
4256 4256
 				}
4257 4257
 			}
4258 4258
 			$IDs[] = $id;
@@ -4265,8 +4265,8 @@  discard block
 block discarded – undo
4265 4265
 	 * are no capabilities that relate to this model returns false
4266 4266
 	 * @return string|false
4267 4267
 	 */
4268
-	public function cap_slug(){
4269
-		return apply_filters( 'FHEE__EEM_Base__cap_slug', $this->_caps_slug, $this);
4268
+	public function cap_slug() {
4269
+		return apply_filters('FHEE__EEM_Base__cap_slug', $this->_caps_slug, $this);
4270 4270
 	}
4271 4271
 
4272 4272
 	/**
@@ -4278,27 +4278,27 @@  discard block
 block discarded – undo
4278 4278
 	 * @param string $context
4279 4279
 	 * @return EE_Default_Where_Conditions[] indexed by associated capability
4280 4280
 	 */
4281
-	public function cap_restrictions( $context = EEM_Base::caps_read ) {
4282
-		EEM_Base::verify_is_valid_cap_context( $context );
4281
+	public function cap_restrictions($context = EEM_Base::caps_read) {
4282
+		EEM_Base::verify_is_valid_cap_context($context);
4283 4283
 		//check if we ought to run the restriction generator first
4284
-		if( isset( $this->_cap_restriction_generators[ $context ] ) &&
4285
-				$this->_cap_restriction_generators[ $context ] instanceof EE_Restriction_Generator_Base &&
4286
-				! $this->_cap_restriction_generators[ $context ]->has_generated_cap_restrictions() ) {
4287
-			$this->_cap_restrictions[ $context ] = array_merge( $this->_cap_restrictions[ $context ],  $this->_cap_restriction_generators[ $context ]->generate_restrictions() );
4284
+		if (isset($this->_cap_restriction_generators[$context]) &&
4285
+				$this->_cap_restriction_generators[$context] instanceof EE_Restriction_Generator_Base &&
4286
+				! $this->_cap_restriction_generators[$context]->has_generated_cap_restrictions()) {
4287
+			$this->_cap_restrictions[$context] = array_merge($this->_cap_restrictions[$context], $this->_cap_restriction_generators[$context]->generate_restrictions());
4288 4288
 		}
4289 4289
 		//and make sure we've finalized the construction of each restriction
4290
-		foreach( $this->_cap_restrictions[ $context ] as $where_conditions_obj ) {
4291
-			$where_conditions_obj->_finalize_construct( $this );
4290
+		foreach ($this->_cap_restrictions[$context] as $where_conditions_obj) {
4291
+			$where_conditions_obj->_finalize_construct($this);
4292 4292
 		}
4293 4293
 
4294
-		return $this->_cap_restrictions[ $context ];
4294
+		return $this->_cap_restrictions[$context];
4295 4295
 	}
4296 4296
 
4297 4297
 	/**
4298 4298
 	 * Indicating whether or not this model thinks its a wp core model
4299 4299
 	 * @return boolean
4300 4300
 	 */
4301
-	public function is_wp_core_model(){
4301
+	public function is_wp_core_model() {
4302 4302
 		return $this->_wp_core_model;
4303 4303
 	}
4304 4304
 
@@ -4308,12 +4308,12 @@  discard block
 block discarded – undo
4308 4308
 	 * @param string $context one of EEM_Base::caps_ constants
4309 4309
 	 * @return EE_Default_Where_Conditions[] indexed by capability name
4310 4310
 	 */
4311
-	public function caps_missing( $context = EEM_Base::caps_read ) {
4311
+	public function caps_missing($context = EEM_Base::caps_read) {
4312 4312
 		$missing_caps = array();
4313
-		$cap_restrictions = $this->cap_restrictions( $context );
4314
-		foreach( $cap_restrictions as $cap => $restriction_if_no_cap ) {
4315
-			if( ! EE_Capabilities::instance()->current_user_can( $cap, $this->get_this_model_name() . '_model_applying_caps') ) {
4316
-				$missing_caps[ $cap ] = $restriction_if_no_cap;
4313
+		$cap_restrictions = $this->cap_restrictions($context);
4314
+		foreach ($cap_restrictions as $cap => $restriction_if_no_cap) {
4315
+			if ( ! EE_Capabilities::instance()->current_user_can($cap, $this->get_this_model_name().'_model_applying_caps')) {
4316
+				$missing_caps[$cap] = $restriction_if_no_cap;
4317 4317
 			}
4318 4318
 		}
4319 4319
 		return $missing_caps;
@@ -4325,7 +4325,7 @@  discard block
 block discarded – undo
4325 4325
 	 * one of 'read', 'edit', or 'delete'
4326 4326
 	 */
4327 4327
 	public function cap_contexts_to_cap_action_map() {
4328
-		return apply_filters( 'FHEE__EEM_Base__cap_contexts_to_cap_action_map', $this->_cap_contexts_to_cap_action_map, $this );
4328
+		return apply_filters('FHEE__EEM_Base__cap_contexts_to_cap_action_map', $this->_cap_contexts_to_cap_action_map, $this);
4329 4329
 	}
4330 4330
 
4331 4331
 
@@ -4336,19 +4336,19 @@  discard block
 block discarded – undo
4336 4336
 	 * @return string one of EEM_Base::cap_contexts_to_cap_action_map() values
4337 4337
 	 * @throws \EE_Error
4338 4338
 	 */
4339
-	public function cap_action_for_context( $context ) {
4339
+	public function cap_action_for_context($context) {
4340 4340
 		$mapping = $this->cap_contexts_to_cap_action_map();
4341
-		if( isset( $mapping[ $context ] ) ) {
4342
-			return $mapping[ $context ];
4341
+		if (isset($mapping[$context])) {
4342
+			return $mapping[$context];
4343 4343
 		}
4344
-		if( $action = apply_filters( 'FHEE__EEM_Base__cap_action_for_context', null, $this, $mapping, $context ) ) {
4344
+		if ($action = apply_filters('FHEE__EEM_Base__cap_action_for_context', null, $this, $mapping, $context)) {
4345 4345
 			return $action;
4346 4346
 		}
4347 4347
 		throw new EE_Error(
4348 4348
 			sprintf(
4349
-				__( 'Cannot find capability restrictions for context "%1$s", allowed values are:%2$s', 'event_espresso' ),
4349
+				__('Cannot find capability restrictions for context "%1$s", allowed values are:%2$s', 'event_espresso'),
4350 4350
 				$context,
4351
-				implode(',', array_keys( $this->cap_contexts_to_cap_action_map() ) )
4351
+				implode(',', array_keys($this->cap_contexts_to_cap_action_map()))
4352 4352
 			)
4353 4353
 		);
4354 4354
 
@@ -4359,7 +4359,7 @@  discard block
 block discarded – undo
4359 4359
 	 * @return array
4360 4360
 	 */
4361 4361
 	static public function valid_cap_contexts() {
4362
-		return apply_filters( 'FHEE__EEM_Base__valid_cap_contexts', array(
4362
+		return apply_filters('FHEE__EEM_Base__valid_cap_contexts', array(
4363 4363
 			self::caps_read,
4364 4364
 			self::caps_read_admin,
4365 4365
 			self::caps_edit,
@@ -4375,17 +4375,17 @@  discard block
 block discarded – undo
4375 4375
 	 * @return bool
4376 4376
 	 * @throws \EE_Error
4377 4377
 	 */
4378
-	static public function verify_is_valid_cap_context( $context ) {
4378
+	static public function verify_is_valid_cap_context($context) {
4379 4379
 		$valid_cap_contexts = EEM_Base::valid_cap_contexts();
4380
-		if( in_array( $context, $valid_cap_contexts ) ) {
4380
+		if (in_array($context, $valid_cap_contexts)) {
4381 4381
 			return true;
4382
-		}else{
4382
+		} else {
4383 4383
 			throw new EE_Error(
4384 4384
 				sprintf(
4385
-					__( 'Context "%1$s" passed into model "%2$s" is not a valid context. They are: %3$s', 'event_espresso' ),
4385
+					__('Context "%1$s" passed into model "%2$s" is not a valid context. They are: %3$s', 'event_espresso'),
4386 4386
 					$context,
4387
-					'EEM_Base' ,
4388
-					implode(',', $valid_cap_contexts )
4387
+					'EEM_Base',
4388
+					implode(',', $valid_cap_contexts)
4389 4389
 				)
4390 4390
 			);
4391 4391
 		}
Please login to merge, or discard this patch.
core/db_models/EEM_CPT_Base.model.php 2 patches
Braces   +9 added lines, -7 removed lines patch added patch discarded remove patch
@@ -118,7 +118,7 @@  discard block
 block discarded – undo
118 118
 		$field = $this->get_a_field_of_type('EE_WP_Post_Status_Field');
119 119
 		if($field){
120 120
 			return $field->get_name();
121
-		}else{
121
+		} else{
122 122
 			throw new EE_Error(sprintf(__('We are trying to find the post status flag field on %s, but none was found. Are you sure there is a field of type EE_Trashed_Flag_Field in %s constructor?','event_espresso'),get_class($this),get_class($this)));
123 123
 		}
124 124
 	}
@@ -193,14 +193,16 @@  discard block
 block discarded – undo
193 193
 	public function get_meta_table_fields( $all = FALSE ) {
194 194
 		$all_fields = $fields_to_return = array();
195 195
 		foreach ( $this->_tables as $alias => $table_obj ) {
196
-			if ( $table_obj instanceof EE_Secondary_Table )
197
-				$all_fields = array_merge( $this->_get_fields_for_table($alias), $all_fields );
196
+			if ( $table_obj instanceof EE_Secondary_Table ) {
197
+							$all_fields = array_merge( $this->_get_fields_for_table($alias), $all_fields );
198
+			}
198 199
 		}
199 200
 
200 201
 		if ( !$all ) {
201 202
 			foreach ( $all_fields as $name => $obj ) {
202
-				if ( $obj instanceof EE_DB_Only_Field_Base )
203
-					continue;
203
+				if ( $obj instanceof EE_DB_Only_Field_Base ) {
204
+									continue;
205
+				}
204 206
 				$fields_to_return[] = $name;
205 207
 			}
206 208
 		} else {
@@ -248,7 +250,7 @@  discard block
 block discarded – undo
248 250
 				'parent'=>$parent_term_taxonomy_id
249 251
 			));
250 252
 			$term_taxonomy->save();
251
-		}else{
253
+		} else{
252 254
 			$term_taxonomy->set_count($term_taxonomy->count() + 1);
253 255
 			$term_taxonomy->save();
254 256
 		}
@@ -366,7 +368,7 @@  discard block
 block discarded – undo
366 368
 		if( ! $has_all_necessary_fields_for_table){
367 369
 
368 370
 			return $this->get_one_by_ID($post['ID']);
369
-		}else{
371
+		} else{
370 372
 			return $this->instantiate_class_from_array_or_object($post);
371 373
 		}
372 374
 	}
Please login to merge, or discard this patch.
Spacing   +85 added lines, -85 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1 1
 <?php
2
-define('EE_Event_Category_Taxonomy','espresso_event_category');
2
+define('EE_Event_Category_Taxonomy', 'espresso_event_category');
3 3
 /**
4 4
  *
5 5
  * EEM_CPT_Base
@@ -16,7 +16,7 @@  discard block
 block discarded – undo
16 16
  * @author 				Mike Nelson
17 17
  *
18 18
  */
19
-abstract class EEM_CPT_Base extends EEM_Soft_Delete_Base{
19
+abstract class EEM_CPT_Base extends EEM_Soft_Delete_Base {
20 20
 
21 21
 	/**
22 22
 	 * @var string post_status_trashed - the wp post status for trashed cpts
@@ -44,46 +44,46 @@  discard block
 block discarded – undo
44 44
 	 * @param string $timezone
45 45
 	 * @throws \EE_Error
46 46
 	 */
47
-	protected function __construct( $timezone = NULL ){
47
+	protected function __construct($timezone = NULL) {
48 48
 
49 49
 		//adds a relationship to Term_Taxonomy for all these models. For this to work
50 50
 		//Term_Relationship must have a relation to each model subclassing EE_CPT_Base explicitly
51 51
 		//eg, in EEM_Term_Relationship, inside the _model_relations array, there must be an entry
52 52
 		//with key equalling the subclassing model's model name (eg 'Event' or 'Venue'), and the value
53 53
 		//must also be new EE_HABTM_Relation('Term_Relationship');
54
-		$this->_model_relations['Term_Taxonomy'] =new EE_HABTM_Relation('Term_Relationship');
54
+		$this->_model_relations['Term_Taxonomy'] = new EE_HABTM_Relation('Term_Relationship');
55 55
 		$primary_table_name = NULL;
56 56
 		//add  the common _status field to all CPT primary tables.
57
-		foreach ( $this->_tables as $alias => $table_obj ) {
58
-			if ( $table_obj instanceof EE_Primary_Table ) {
57
+		foreach ($this->_tables as $alias => $table_obj) {
58
+			if ($table_obj instanceof EE_Primary_Table) {
59 59
 				$primary_table_name = $alias;
60 60
 			}
61 61
 		}
62 62
 		//set default wp post statuses if child has not already set.
63
-		if ( ! isset( $this->_fields[$primary_table_name]['status'] )) {
63
+		if ( ! isset($this->_fields[$primary_table_name]['status'])) {
64 64
 			$this->_fields[$primary_table_name]['status'] = new EE_WP_Post_Status_Field('post_status', __("Event Status", "event_espresso"), false, 'draft');
65 65
 		}
66
-		if( ! isset( $this->_fields[$primary_table_name]['to_ping'])){
67
-			$this->_fields[$primary_table_name]['to_ping'] = new EE_DB_Only_Text_Field('to_ping', __( 'To Ping', 'event_espresso' ), FALSE, '');
66
+		if ( ! isset($this->_fields[$primary_table_name]['to_ping'])) {
67
+			$this->_fields[$primary_table_name]['to_ping'] = new EE_DB_Only_Text_Field('to_ping', __('To Ping', 'event_espresso'), FALSE, '');
68 68
 		}
69
-		if( ! isset( $this->_fields[$primary_table_name]['pinged'])){
70
-			$this->_fields[$primary_table_name]['pinged'] = new EE_DB_Only_Text_Field('pinged', __( 'Pinged', 'event_espresso' ), FALSE, '');
69
+		if ( ! isset($this->_fields[$primary_table_name]['pinged'])) {
70
+			$this->_fields[$primary_table_name]['pinged'] = new EE_DB_Only_Text_Field('pinged', __('Pinged', 'event_espresso'), FALSE, '');
71 71
 		}
72 72
 
73
-		if( ! isset( $this->_fields[$primary_table_name]['comment_status'])){
74
-			$this->_fields[$primary_table_name]['comment_status'] = new EE_Plain_Text_Field('comment_status', __('Comment Status', 'event_espresso' ), FALSE, 'open');
73
+		if ( ! isset($this->_fields[$primary_table_name]['comment_status'])) {
74
+			$this->_fields[$primary_table_name]['comment_status'] = new EE_Plain_Text_Field('comment_status', __('Comment Status', 'event_espresso'), FALSE, 'open');
75 75
 		}
76 76
 
77
-		if( ! isset( $this->_fields[$primary_table_name]['ping_status'])){
77
+		if ( ! isset($this->_fields[$primary_table_name]['ping_status'])) {
78 78
 			$this->_fields[$primary_table_name]['ping_status'] = new EE_Plain_Text_Field('ping_status', __('Ping Status', 'event_espresso'), FALSE, 'open');
79 79
 		}
80 80
 
81
-		if( ! isset( $this->_fields[$primary_table_name]['post_content_filtered'])){
82
-			$this->_fields[$primary_table_name]['post_content_filtered'] = new EE_DB_Only_Text_Field('post_content_filtered', __( 'Post Content Filtered', 'event_espresso' ), FALSE, '');
81
+		if ( ! isset($this->_fields[$primary_table_name]['post_content_filtered'])) {
82
+			$this->_fields[$primary_table_name]['post_content_filtered'] = new EE_DB_Only_Text_Field('post_content_filtered', __('Post Content Filtered', 'event_espresso'), FALSE, '');
83 83
 		}
84
-		if( ! isset( $this->_model_relations[ 'Post_Meta' ] ) ) {
84
+		if ( ! isset($this->_model_relations['Post_Meta'])) {
85 85
 			//don't block deletes though because we want to maintain the current behaviour
86
-			$this->_model_relations[ 'Post_Meta' ] = new EE_Has_Many_Relation( false );
86
+			$this->_model_relations['Post_Meta'] = new EE_Has_Many_Relation(false);
87 87
 		}
88 88
 		parent::__construct($timezone);
89 89
 
@@ -96,7 +96,7 @@  discard block
 block discarded – undo
96 96
 	 */
97 97
 	public function public_event_stati() {
98 98
 		// @see wp-includes/post.php
99
-		return get_post_stati( array( 'public' => TRUE ));
99
+		return get_post_stati(array('public' => TRUE));
100 100
 	}
101 101
 
102 102
 
@@ -107,7 +107,7 @@  discard block
 block discarded – undo
107 107
 	 * @return string
108 108
 	 * @throws EE_Error
109 109
 	 */
110
-	public function deleted_field_name(){
110
+	public function deleted_field_name() {
111 111
 		throw new EE_Error(sprintf(__("EEM_CPT_Base should nto call deleted_field_name! It should instead use post_status_field_name", "event_espresso")));
112 112
 	}
113 113
 
@@ -118,12 +118,12 @@  discard block
 block discarded – undo
118 118
 	 * @return string
119 119
 	 * @throws EE_Error
120 120
 	 */
121
-	public function post_status_field_name(){
121
+	public function post_status_field_name() {
122 122
 		$field = $this->get_a_field_of_type('EE_WP_Post_Status_Field');
123
-		if($field){
123
+		if ($field) {
124 124
 			return $field->get_name();
125
-		}else{
126
-			throw new EE_Error(sprintf(__('We are trying to find the post status flag field on %s, but none was found. Are you sure there is a field of type EE_Trashed_Flag_Field in %s constructor?','event_espresso'),get_class($this),get_class($this)));
125
+		} else {
126
+			throw new EE_Error(sprintf(__('We are trying to find the post status flag field on %s, but none was found. Are you sure there is a field of type EE_Trashed_Flag_Field in %s constructor?', 'event_espresso'), get_class($this), get_class($this)));
127 127
 		}
128 128
 	}
129 129
 
@@ -134,9 +134,9 @@  discard block
 block discarded – undo
134 134
 	 * @param array $query_params like EEM_Base::get_all's $query_params
135 135
 	 * @return array like EEM_Base::get_all's $query_params
136 136
 	 */
137
-	protected function _alter_query_params_so_only_trashed_items_included($query_params){
138
-		$post_status_field_name=$this->post_status_field_name();
139
-		$query_params[0][$post_status_field_name]=self::post_status_trashed;
137
+	protected function _alter_query_params_so_only_trashed_items_included($query_params) {
138
+		$post_status_field_name = $this->post_status_field_name();
139
+		$query_params[0][$post_status_field_name] = self::post_status_trashed;
140 140
 		return $query_params;
141 141
 	}
142 142
 
@@ -147,9 +147,9 @@  discard block
 block discarded – undo
147 147
 	 * @param array $query_params
148 148
 	 * @return array
149 149
 	 */
150
-	protected function _alter_query_params_so_deleted_and_undeleted_items_included($query_params){
151
-		$post_status_field_name=$this->post_status_field_name();
152
-		$query_params[0][$post_status_field_name]=array('IN',array_keys($this->get_status_array()));
150
+	protected function _alter_query_params_so_deleted_and_undeleted_items_included($query_params) {
151
+		$post_status_field_name = $this->post_status_field_name();
152
+		$query_params[0][$post_status_field_name] = array('IN', array_keys($this->get_status_array()));
153 153
 		return $query_params;
154 154
 	}
155 155
 
@@ -161,11 +161,11 @@  discard block
 block discarded – undo
161 161
 	 * @param array $query_params like EEM_Base::get_all
162 162
 	 * @return boolean success
163 163
 	 */
164
-	function delete_or_restore($delete=true,$query_params = array()){
165
-		$post_status_field_name=$this->post_status_field_name();
164
+	function delete_or_restore($delete = true, $query_params = array()) {
165
+		$post_status_field_name = $this->post_status_field_name();
166 166
 		$query_params = $this->_alter_query_params_so_deleted_and_undeleted_items_included($query_params);
167 167
 		$new_status = $delete ? self::post_status_trashed : 'draft';
168
-		if ( $this->update (array($post_status_field_name=>$new_status), $query_params )) {
168
+		if ($this->update(array($post_status_field_name=>$new_status), $query_params)) {
169 169
 			return TRUE;
170 170
 		} else {
171 171
 			return FALSE;
@@ -182,7 +182,7 @@  discard block
 block discarded – undo
182 182
 	 */
183 183
 	public function meta_table() {
184 184
 		$meta_table = $this->_get_other_tables();
185
-		$meta_table = reset( $meta_table );
185
+		$meta_table = reset($meta_table);
186 186
 		return $meta_table instanceof EE_Secondary_Table ? $meta_table->get_table_name() : NULL;
187 187
 	}
188 188
 
@@ -194,16 +194,16 @@  discard block
 block discarded – undo
194 194
 	 * @param  bool $all triggers whether we include DB_Only fields or JUST non DB_Only fields.  Defaults to false (no db only fields)
195 195
 	 * @return array
196 196
 	 */
197
-	public function get_meta_table_fields( $all = FALSE ) {
197
+	public function get_meta_table_fields($all = FALSE) {
198 198
 		$all_fields = $fields_to_return = array();
199
-		foreach ( $this->_tables as $alias => $table_obj ) {
200
-			if ( $table_obj instanceof EE_Secondary_Table )
201
-				$all_fields = array_merge( $this->_get_fields_for_table($alias), $all_fields );
199
+		foreach ($this->_tables as $alias => $table_obj) {
200
+			if ($table_obj instanceof EE_Secondary_Table)
201
+				$all_fields = array_merge($this->_get_fields_for_table($alias), $all_fields);
202 202
 		}
203 203
 
204
-		if ( !$all ) {
205
-			foreach ( $all_fields as $name => $obj ) {
206
-				if ( $obj instanceof EE_DB_Only_Field_Base )
204
+		if ( ! $all) {
205
+			foreach ($all_fields as $name => $obj) {
206
+				if ($obj instanceof EE_DB_Only_Field_Base)
207 207
 					continue;
208 208
 				$fields_to_return[] = $name;
209 209
 			}
@@ -226,13 +226,13 @@  discard block
 block discarded – undo
226 226
 	 * @param int $parent_term_taxonomy_id
227 227
 	 * @return EE_Term_Taxonomy
228 228
 	 */
229
-	function add_event_category(EE_CPT_Base $cpt_model_object, $category_name, $category_description ='',$parent_term_taxonomy_id = null){
229
+	function add_event_category(EE_CPT_Base $cpt_model_object, $category_name, $category_description = '', $parent_term_taxonomy_id = null) {
230 230
 		//create term
231
-		require_once( EE_MODELS . 'EEM_Term.model.php');
231
+		require_once(EE_MODELS.'EEM_Term.model.php');
232 232
 		//first, check for a term by the same name or slug
233 233
 		$category_slug = sanitize_title($category_name);
234
-		$term = EEM_Term::instance()->get_one(array(array('OR'=>array('name'=>$category_name,'slug'=>$category_slug))));
235
-		if( ! $term ){
234
+		$term = EEM_Term::instance()->get_one(array(array('OR'=>array('name'=>$category_name, 'slug'=>$category_slug))));
235
+		if ( ! $term) {
236 236
 			$term = EE_Term::new_instance(array(
237 237
 				'name'=>$category_name,
238 238
 				'slug'=>$category_slug
@@ -240,10 +240,10 @@  discard block
 block discarded – undo
240 240
 			$term->save();
241 241
 		}
242 242
 		//make sure there's a term-taxonomy entry too
243
-		require_once( EE_MODELS . 'EEM_Term_Taxonomy.model.php');
244
-		$term_taxonomy = EEM_Term_Taxonomy::instance()->get_one(array(array('term_id'=>$term->ID(),'taxonomy'=>EE_Event_Category_Taxonomy)));
243
+		require_once(EE_MODELS.'EEM_Term_Taxonomy.model.php');
244
+		$term_taxonomy = EEM_Term_Taxonomy::instance()->get_one(array(array('term_id'=>$term->ID(), 'taxonomy'=>EE_Event_Category_Taxonomy)));
245 245
 		/** @var $term_taxonomy EE_Term_Taxonomy */
246
-		if( ! $term_taxonomy ){
246
+		if ( ! $term_taxonomy) {
247 247
 			$term_taxonomy = EE_Term_Taxonomy::new_instance(array(
248 248
 				'term_id'=>$term->ID(),
249 249
 				'taxonomy'=>EE_Event_Category_Taxonomy,
@@ -252,7 +252,7 @@  discard block
 block discarded – undo
252 252
 				'parent'=>$parent_term_taxonomy_id
253 253
 			));
254 254
 			$term_taxonomy->save();
255
-		}else{
255
+		} else {
256 256
 			$term_taxonomy->set_count($term_taxonomy->count() + 1);
257 257
 			$term_taxonomy->save();
258 258
 		}
@@ -267,11 +267,11 @@  discard block
 block discarded – undo
267 267
 	 * @param string $category_name name of the event category (term)
268 268
 	 * @return bool
269 269
 	 */
270
-	function remove_event_category(EE_CPT_Base $cpt_model_object_event, $category_name){
270
+	function remove_event_category(EE_CPT_Base $cpt_model_object_event, $category_name) {
271 271
 		//find the term_taxonomy by that name
272
-		$term_taxonomy = $this->get_first_related($cpt_model_object_event, 'Term_Taxonomy', array(array('Term.name'=>$category_name,'taxonomy'=>EE_Event_Category_Taxonomy)));
272
+		$term_taxonomy = $this->get_first_related($cpt_model_object_event, 'Term_Taxonomy', array(array('Term.name'=>$category_name, 'taxonomy'=>EE_Event_Category_Taxonomy)));
273 273
 		/** @var $term_taxonomy EE_Term_Taxonomy */
274
-		if( $term_taxonomy ){
274
+		if ($term_taxonomy) {
275 275
 			$term_taxonomy->set_count($term_taxonomy->count() - 1);
276 276
 			$term_taxonomy->save();
277 277
 		}
@@ -291,8 +291,8 @@  discard block
 block discarded – undo
291 291
 	 * @param string|array $attr Optional. Query string or array of attributes.
292 292
 	 * @return string HTML image element
293 293
 	 */
294
-	public function get_feature_image( $id, $size = 'thumbnail', $attr = '' ) {
295
-		return get_the_post_thumbnail( $id, $size, $attr );
294
+	public function get_feature_image($id, $size = 'thumbnail', $attr = '') {
295
+		return get_the_post_thumbnail($id, $size, $attr);
296 296
 	}
297 297
 
298 298
 
@@ -305,10 +305,10 @@  discard block
 block discarded – undo
305 305
 	 * @global array $wp_post_statuses set in wp core for storing all the post stati
306 306
 	 * @return array
307 307
 	 */
308
-	public function get_post_statuses(){
308
+	public function get_post_statuses() {
309 309
 		global $wp_post_statuses;
310 310
 		$statuses = array();
311
-		foreach($wp_post_statuses as $post_status => $args_object){
311
+		foreach ($wp_post_statuses as $post_status => $args_object) {
312 312
 			$statuses[$post_status] = $args_object->label;
313 313
 		}
314 314
 		return $statuses;
@@ -323,9 +323,9 @@  discard block
 block discarded – undo
323 323
 	public function get_status_array() {
324 324
 		$statuses = $this->get_post_statuses();
325 325
 		//first the global filter
326
-		$statuses = apply_filters( 'FHEE_EEM_CPT_Base__get_status_array', $statuses );
326
+		$statuses = apply_filters('FHEE_EEM_CPT_Base__get_status_array', $statuses);
327 327
 		//now the class specific filter
328
-		$statuses = apply_filters( 'FHEE_EEM_' . get_class($this) . '__get_status_array', $statuses );
328
+		$statuses = apply_filters('FHEE_EEM_'.get_class($this).'__get_status_array', $statuses);
329 329
 		return $statuses;
330 330
 	}
331 331
 
@@ -337,7 +337,7 @@  discard block
 block discarded – undo
337 337
 	 */
338 338
 	public function get_custom_post_statuses() {
339 339
 		$new_stati = array();
340
-		foreach ( $this->_custom_stati as $status => $props ) {
340
+		foreach ($this->_custom_stati as $status => $props) {
341 341
 			$new_stati[$status] = $props['label'];
342 342
 		}
343 343
 		return $new_stati;
@@ -353,24 +353,24 @@  discard block
 block discarded – undo
353 353
 	 * @param WP_Post|array $post
354 354
 	 * @return EE_CPT_Base
355 355
 	 */
356
-	public function instantiate_class_from_post_object_orig($post){
357
-		$post = (array)$post;
356
+	public function instantiate_class_from_post_object_orig($post) {
357
+		$post = (array) $post;
358 358
 		$has_all_necessary_fields_for_table = true;
359 359
 		//check if the post has fields on the meta table already
360
-		foreach($this->_get_other_tables() as $table_obj){
360
+		foreach ($this->_get_other_tables() as $table_obj) {
361 361
 			$fields_for_that_table = $this->_get_fields_for_table($table_obj->get_table_alias());
362
-			foreach($fields_for_that_table as $field_obj){
363
-				if( ! isset($post[$field_obj->get_table_column()])
364
-					&& ! isset($post[$field_obj->get_qualified_column()])){
362
+			foreach ($fields_for_that_table as $field_obj) {
363
+				if ( ! isset($post[$field_obj->get_table_column()])
364
+					&& ! isset($post[$field_obj->get_qualified_column()])) {
365 365
 					$has_all_necessary_fields_for_table = false;
366 366
 				}
367 367
 			}
368 368
 		}
369 369
 		//if we don't have all the fields we need, then just fetch the proper model from the DB
370
-		if( ! $has_all_necessary_fields_for_table){
370
+		if ( ! $has_all_necessary_fields_for_table) {
371 371
 
372 372
 			return $this->get_one_by_ID($post['ID']);
373
-		}else{
373
+		} else {
374 374
 			return $this->instantiate_class_from_array_or_object($post);
375 375
 		}
376 376
 	}
@@ -381,30 +381,30 @@  discard block
 block discarded – undo
381 381
 	 * @param null $post
382 382
 	 * @return EE_Base_Class|EE_Soft_Delete_Base_Class
383 383
 	 */
384
-	public function instantiate_class_from_post_object( $post = NULL ){
385
-		if ( empty( $post )) {
384
+	public function instantiate_class_from_post_object($post = NULL) {
385
+		if (empty($post)) {
386 386
 			global $post;
387 387
 		}
388
-		$post = (array)$post;
388
+		$post = (array) $post;
389 389
 		$tables_needing_to_be_queried = array();
390 390
 		//check if the post has fields on the meta table already
391
-		foreach($this->get_tables() as $table_obj){
391
+		foreach ($this->get_tables() as $table_obj) {
392 392
 			$fields_for_that_table = $this->_get_fields_for_table($table_obj->get_table_alias());
393
-			foreach($fields_for_that_table as $field_obj){
394
-				if( ! isset($post[$field_obj->get_table_column()])
395
-					&& ! isset($post[$field_obj->get_qualified_column()])){
393
+			foreach ($fields_for_that_table as $field_obj) {
394
+				if ( ! isset($post[$field_obj->get_table_column()])
395
+					&& ! isset($post[$field_obj->get_qualified_column()])) {
396 396
 					$tables_needing_to_be_queried[$table_obj->get_table_alias()] = $table_obj;
397 397
 				}
398 398
 			}
399 399
 		}
400 400
 		//if we don't have all the fields we need, then just fetch the proper model from the DB
401
-		if( $tables_needing_to_be_queried){
402
-			if(count($tables_needing_to_be_queried) == 1 && reset($tables_needing_to_be_queried) instanceof EE_Secondary_Table){
401
+		if ($tables_needing_to_be_queried) {
402
+			if (count($tables_needing_to_be_queried) == 1 && reset($tables_needing_to_be_queried) instanceof EE_Secondary_Table) {
403 403
 				//so we're only missing data from a secondary table. Well that's not too hard to query for
404 404
 				$table_to_query = reset($tables_needing_to_be_queried);
405
-				$missing_data = $this->_do_wpdb_query( 'get_row', array( 'SELECT * FROM ' . $table_to_query->get_table_name() . ' WHERE ' . $table_to_query->get_fk_on_table() . ' = ' . $post['ID'], ARRAY_A ));
406
-				if ( ! empty( $missing_data )) {
407
-					$post = array_merge( $post, $missing_data );
405
+				$missing_data = $this->_do_wpdb_query('get_row', array('SELECT * FROM '.$table_to_query->get_table_name().' WHERE '.$table_to_query->get_fk_on_table().' = '.$post['ID'], ARRAY_A));
406
+				if ( ! empty($missing_data)) {
407
+					$post = array_merge($post, $missing_data);
408 408
 				}
409 409
 			} else {
410 410
 				return $this->get_one_by_ID($post['ID']);
@@ -421,15 +421,15 @@  discard block
 block discarded – undo
421 421
 	 * @throws EE_Error
422 422
 	 * @return string
423 423
 	 */
424
-	public function post_type(){
424
+	public function post_type() {
425 425
 		$post_type_field = NULL;
426
-		foreach($this->field_settings(true) as $field_obj){
427
-			if($field_obj instanceof EE_WP_Post_Type_Field){
428
-				$post_type_field = $field_obj;break;
426
+		foreach ($this->field_settings(true) as $field_obj) {
427
+			if ($field_obj instanceof EE_WP_Post_Type_Field) {
428
+				$post_type_field = $field_obj; break;
429 429
 			}
430 430
 		}
431
-		if($post_type_field == NULL){
432
-			throw new EE_Error(sprintf(__("CPT Model %s should have a field of type EE_WP_Post_Type, but doesnt", "event_espresso"),get_class($this)));
431
+		if ($post_type_field == NULL) {
432
+			throw new EE_Error(sprintf(__("CPT Model %s should have a field of type EE_WP_Post_Type, but doesnt", "event_espresso"), get_class($this)));
433 433
 		}
434 434
 		return $post_type_field->get_default_value();
435 435
 	}
Please login to merge, or discard this patch.
core/db_models/EEM_Checkin.model.php 2 patches
Spacing   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -23,8 +23,8 @@  discard block
 block discarded – undo
23 23
  *
24 24
  * ------------------------------------------------------------------------
25 25
  */
26
-require_once ( EE_MODELS . 'EEM_Base.model.php' );
27
-require_once ( EE_CLASSES . 'EE_Checkin.class.php' );
26
+require_once (EE_MODELS.'EEM_Base.model.php');
27
+require_once (EE_CLASSES.'EE_Checkin.class.php');
28 28
 
29 29
 class EEM_Checkin extends EEM_Base {
30 30
 
@@ -40,12 +40,12 @@  discard block
 block discarded – undo
40 40
 	 * 		@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)
41 41
 	 * 		@return void
42 42
 	 */
43
-	protected function __construct( $timezone = NULL ) {
44
-		$this->singular_item = __('Check-In','event_espresso');
45
-		$this->plural_item = __('Check-Ins','event_espresso');
43
+	protected function __construct($timezone = NULL) {
44
+		$this->singular_item = __('Check-In', 'event_espresso');
45
+		$this->plural_item = __('Check-Ins', 'event_espresso');
46 46
 
47 47
 		$this->_tables = array(
48
-			'Checkin'=>new EE_Primary_Table('esp_checkin','CHK_ID')
48
+			'Checkin'=>new EE_Primary_Table('esp_checkin', 'CHK_ID')
49 49
 		);
50 50
 		$this->_fields = array(
51 51
 			'Checkin'=> array(
@@ -53,7 +53,7 @@  discard block
 block discarded – undo
53 53
 				'REG_ID'=>new EE_Foreign_Key_Int_Field('REG_ID', 'Registration Id', false, 0, 'Registration'),
54 54
 				'DTT_ID'=>new EE_Foreign_Key_Int_Field('DTT_ID', 'Datetime Id', false, 0, 'Datetime'),
55 55
 				'CHK_in'=>new EE_Boolean_Field('CHK_in', 'Whether a person has checked in or checked out', false, true),
56
-				'CHK_timestamp'=>new EE_Datetime_Field('CHK_timestamp', __('When the row was modified','event_espresso'), false, time(), $timezone )
56
+				'CHK_timestamp'=>new EE_Datetime_Field('CHK_timestamp', __('When the row was modified', 'event_espresso'), false, time(), $timezone)
57 57
 			)
58 58
 		);
59 59
 		$this->_model_relations = array(
@@ -61,7 +61,7 @@  discard block
 block discarded – undo
61 61
 			'Datetime'=>new EE_Belongs_To_Relation()
62 62
 		);
63 63
 		$this->_model_chain_to_wp_user = 'Registration.Event';
64
-		parent::__construct( $timezone );
64
+		parent::__construct($timezone);
65 65
 
66 66
 	}
67 67
 
Please login to merge, or discard this patch.
Braces   +3 added lines, -1 removed lines patch added patch discarded remove patch
@@ -1,4 +1,6 @@
 block discarded – undo
1
-<?php if ( ! defined('EVENT_ESPRESSO_VERSION')) exit('No direct script access allowed');
1
+<?php if ( ! defined('EVENT_ESPRESSO_VERSION')) {
2
+	exit('No direct script access allowed');
3
+}
2 4
 /**
3 5
  * Event Espresso
4 6
  *
Please login to merge, or discard this patch.
core/db_models/EEM_Country.model.php 3 patches
Indentation   +11 added lines, -11 removed lines patch added patch discarded remove patch
@@ -83,11 +83,11 @@  discard block
 block discarded – undo
83 83
 
84 84
 
85 85
 	/**
86
-	*		_get_countries
87
-	*
88
-	* 		@access		public
89
-	*		@return 		array
90
-	*/
86
+	 *		_get_countries
87
+	 *
88
+	 * 		@access		public
89
+	 *		@return 		array
90
+	 */
91 91
 	public function get_all_countries() {
92 92
 		if ( ! self::$_all_countries ) {
93 93
 			self::$_all_countries = $this->get_all( array( 'order_by'=>array('CNT_name'=>'ASC'), 'limit'=> array( 0,99999 )));
@@ -96,12 +96,12 @@  discard block
 block discarded – undo
96 96
 	}
97 97
 
98 98
 	/**
99
-	*		_get_countries
100
-	*		Gets and caches the list of active countries. If you know the list of active countries
101
-	*		has changed during this request, first use EEM_Country::reset() to flush the cache
102
-	* 		@access		public
103
-	*		@return 		array
104
-	*/
99
+	 *		_get_countries
100
+	 *		Gets and caches the list of active countries. If you know the list of active countries
101
+	 *		has changed during this request, first use EEM_Country::reset() to flush the cache
102
+	 * 		@access		public
103
+	 *		@return 		array
104
+	 */
105 105
 	public function get_all_active_countries() {
106 106
 		if ( ! self::$_active_countries ) {
107 107
 			self::$_active_countries =  $this->get_all( array( array( 'CNT_active' => TRUE ), 'order_by'=>array('CNT_name'=>'ASC'), 'limit'=>array( 0, 99999 )));
Please login to merge, or discard this patch.
Spacing   +34 added lines, -34 removed lines patch added patch discarded remove patch
@@ -36,15 +36,15 @@  discard block
 block discarded – undo
36 36
 	 * Resets the country
37 37
 	 * @return EEM_Country
38 38
 	 */
39
-	public static function reset( $timezone = NULL ){
39
+	public static function reset($timezone = NULL) {
40 40
 		self::$_active_countries = NULL;
41 41
 		self::$_all_countries = NULL;
42
-		return parent::reset( $timezone );
42
+		return parent::reset($timezone);
43 43
 	}
44 44
 
45
-	protected function __construct( $timezone = NULL ){
46
-		$this->singular_item = __('Country','event_espresso');
47
-		$this->plural_item = __('Countries','event_espresso');
45
+	protected function __construct($timezone = NULL) {
46
+		$this->singular_item = __('Country', 'event_espresso');
47
+		$this->plural_item = __('Countries', 'event_espresso');
48 48
 
49 49
 
50 50
 		$this->_tables = array(
@@ -52,21 +52,21 @@  discard block
 block discarded – undo
52 52
 		);
53 53
 		$this->_fields = array(
54 54
 			'Country'=>array(
55
-				'CNT_active' => new EE_Boolean_Field('CNT_active', __('Country Appears in Dropdown Select Lists','event_espresso'), false, true),
56
-				'CNT_ISO'=> new EE_Primary_Key_String_Field('CNT_ISO', __('Country ISO Code','event_espresso')),
57
-				'CNT_ISO3'=>new EE_All_Caps_Text_Field('CNT_ISO3', __('Country ISO3 Code','event_espresso'), false,''),
58
-				'RGN_ID'=>new EE_Integer_Field('RGN_ID', __('Region ID','event_espresso'), false,0),//should be a foreign key, but no region table exists yet
59
-				'CNT_name'=>new EE_Plain_Text_Field('CNT_name', __('Country Name','event_espresso'), false,''),
60
-				'CNT_cur_code'=>new EE_All_Caps_Text_Field('CNT_cur_code', __('Country Currency Code','event_espresso'), false),
61
-				'CNT_cur_single' => new EE_Plain_Text_Field('CNT_cur_single', __('Currency Name Singular','event_espresso'), false),
62
-				'CNT_cur_plural' => new EE_Plain_Text_Field('CNT_cur_plural', __('Currency Name Plural','event_espresso'), false),
63
-				'CNT_cur_sign' => new EE_Plain_Text_Field('CNT_cur_sign', __('Currency Sign','event_espresso'), false),
64
-				'CNT_cur_sign_b4' => new EE_Boolean_Field('CNT_cur_sign_b4', __('Currency Sign Before Number','event_espresso'), false, true),
65
-				'CNT_cur_dec_plc' => new EE_Integer_Field('CNT_cur_dec_plc', __('Currency Decimal Places','event_espresso'), false, 2),
66
-				'CNT_cur_dec_mrk' => new EE_Plain_Text_Field('CNT_cur_dec_mrk', __('Currency Decimal Mark','event_espresso'), false, '.'),
67
-				'CNT_cur_thsnds' => new EE_Plain_Text_Field('CNT_cur_thsnds', __('Currency Thousands Seperator','event_espresso'), false, ','),
68
-				'CNT_tel_code' => new EE_Plain_Text_Field('CNT_tel_code', __('Country Telephone Code','event_espresso'), false, ''),
69
-				'CNT_is_EU' => new EE_Boolean_Field('CNT_is_EU', __('Country is Member of EU','event_espresso'), false, false)
55
+				'CNT_active' => new EE_Boolean_Field('CNT_active', __('Country Appears in Dropdown Select Lists', 'event_espresso'), false, true),
56
+				'CNT_ISO'=> new EE_Primary_Key_String_Field('CNT_ISO', __('Country ISO Code', 'event_espresso')),
57
+				'CNT_ISO3'=>new EE_All_Caps_Text_Field('CNT_ISO3', __('Country ISO3 Code', 'event_espresso'), false, ''),
58
+				'RGN_ID'=>new EE_Integer_Field('RGN_ID', __('Region ID', 'event_espresso'), false, 0), //should be a foreign key, but no region table exists yet
59
+				'CNT_name'=>new EE_Plain_Text_Field('CNT_name', __('Country Name', 'event_espresso'), false, ''),
60
+				'CNT_cur_code'=>new EE_All_Caps_Text_Field('CNT_cur_code', __('Country Currency Code', 'event_espresso'), false),
61
+				'CNT_cur_single' => new EE_Plain_Text_Field('CNT_cur_single', __('Currency Name Singular', 'event_espresso'), false),
62
+				'CNT_cur_plural' => new EE_Plain_Text_Field('CNT_cur_plural', __('Currency Name Plural', 'event_espresso'), false),
63
+				'CNT_cur_sign' => new EE_Plain_Text_Field('CNT_cur_sign', __('Currency Sign', 'event_espresso'), false),
64
+				'CNT_cur_sign_b4' => new EE_Boolean_Field('CNT_cur_sign_b4', __('Currency Sign Before Number', 'event_espresso'), false, true),
65
+				'CNT_cur_dec_plc' => new EE_Integer_Field('CNT_cur_dec_plc', __('Currency Decimal Places', 'event_espresso'), false, 2),
66
+				'CNT_cur_dec_mrk' => new EE_Plain_Text_Field('CNT_cur_dec_mrk', __('Currency Decimal Mark', 'event_espresso'), false, '.'),
67
+				'CNT_cur_thsnds' => new EE_Plain_Text_Field('CNT_cur_thsnds', __('Currency Thousands Seperator', 'event_espresso'), false, ','),
68
+				'CNT_tel_code' => new EE_Plain_Text_Field('CNT_tel_code', __('Country Telephone Code', 'event_espresso'), false, ''),
69
+				'CNT_is_EU' => new EE_Boolean_Field('CNT_is_EU', __('Country is Member of EU', 'event_espresso'), false, false)
70 70
 			));
71 71
 		$this->_model_relations = array(
72 72
 			'Attendee'=>new EE_Has_Many_Relation(),
@@ -74,9 +74,9 @@  discard block
 block discarded – undo
74 74
 			'Venue'=>new EE_Has_Many_Relation(),
75 75
 		);
76 76
 		//only anyone to view, but only those with the default role can do anything
77
-		$this->_cap_restriction_generators[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Public();
77
+		$this->_cap_restriction_generators[EEM_Base::caps_read] = new EE_Restriction_Generator_Public();
78 78
 
79
-		parent::__construct( $timezone );
79
+		parent::__construct($timezone);
80 80
 	}
81 81
 
82 82
 
@@ -89,8 +89,8 @@  discard block
 block discarded – undo
89 89
 	*		@return 		array
90 90
 	*/
91 91
 	public function get_all_countries() {
92
-		if ( ! self::$_all_countries ) {
93
-			self::$_all_countries = $this->get_all( array( 'order_by'=>array('CNT_name'=>'ASC'), 'limit'=> array( 0,99999 )));
92
+		if ( ! self::$_all_countries) {
93
+			self::$_all_countries = $this->get_all(array('order_by'=>array('CNT_name'=>'ASC'), 'limit'=> array(0, 99999)));
94 94
 		}
95 95
 		return self::$_all_countries;
96 96
 	}
@@ -103,8 +103,8 @@  discard block
 block discarded – undo
103 103
 	*		@return 		array
104 104
 	*/
105 105
 	public function get_all_active_countries() {
106
-		if ( ! self::$_active_countries ) {
107
-			self::$_active_countries =  $this->get_all( array( array( 'CNT_active' => TRUE ), 'order_by'=>array('CNT_name'=>'ASC'), 'limit'=>array( 0, 99999 )));
106
+		if ( ! self::$_active_countries) {
107
+			self::$_active_countries = $this->get_all(array(array('CNT_active' => TRUE), 'order_by'=>array('CNT_name'=>'ASC'), 'limit'=>array(0, 99999)));
108 108
 		}
109 109
 		return self::$_active_countries;
110 110
 	}
@@ -114,15 +114,15 @@  discard block
 block discarded – undo
114 114
 	 * @param string $country_ISO
115 115
 	 * @return string
116 116
 	 */
117
-	public function get_country_name_by_ISO( $country_ISO ){
118
-		if( isset( self::$_all_countries[ $country_ISO ] ) &&
119
-				self::$_all_countries[ $country_ISO ] instanceof EE_Country ){
120
-			return self::$_all_countries[ $country_ISO ]->name();
117
+	public function get_country_name_by_ISO($country_ISO) {
118
+		if (isset(self::$_all_countries[$country_ISO]) &&
119
+				self::$_all_countries[$country_ISO] instanceof EE_Country) {
120
+			return self::$_all_countries[$country_ISO]->name();
121 121
 		}
122
-		$names = $this->get_col( array( array( 'CNT_ISO' => $country_ISO ), 'limit' => 1), 'CNT_name' );
123
-		if( is_array( $names ) && ! empty( $names ) ){
124
-			return reset( $names );
125
-		}else{
122
+		$names = $this->get_col(array(array('CNT_ISO' => $country_ISO), 'limit' => 1), 'CNT_name');
123
+		if (is_array($names) && ! empty($names)) {
124
+			return reset($names);
125
+		} else {
126 126
 			return '';
127 127
 		}
128 128
 	}
Please login to merge, or discard this patch.
Braces   +4 added lines, -2 removed lines patch added patch discarded remove patch
@@ -1,4 +1,6 @@  discard block
 block discarded – undo
1
-<?php if ( ! defined('EVENT_ESPRESSO_VERSION')) exit('No direct script access allowed');
1
+<?php if ( ! defined('EVENT_ESPRESSO_VERSION')) {
2
+	exit('No direct script access allowed');
3
+}
2 4
 /**
3 5
  * EEH_URL helper
4 6
  * Helper class for URL-related PHP functions
@@ -62,7 +64,7 @@  discard block
 block discarded – undo
62 64
 				isset($results['response']['code']) &&
63 65
 				$results['response']['code'] == '200'){
64 66
 			return true;
65
-		}else{
67
+		} else{
66 68
 			return false;
67 69
 		}
68 70
 	}
Please login to merge, or discard this patch.
core/db_models/EEM_Currency.model.php 2 patches
Spacing   +23 added lines, -23 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,32 +25,32 @@  discard block
 block discarded – undo
25 25
  *
26 26
  * ------------------------------------------------------------------------
27 27
  */
28
-class EEM_Currency extends EEM_Base{
28
+class EEM_Currency extends EEM_Base {
29 29
 		// private instance of the Attendee object
30 30
 	protected static $_instance = NULL;
31 31
 
32
-	protected function __construct( $timezone = NULL ) {
33
-		$this->singular_item = __('Currency','event_espresso');
34
-		$this->plural_item = __('Currencies','event_espresso');
32
+	protected function __construct($timezone = NULL) {
33
+		$this->singular_item = __('Currency', 'event_espresso');
34
+		$this->plural_item = __('Currencies', 'event_espresso');
35 35
 		$this->_tables = array(
36 36
 			'Currency'=> new EE_Primary_Table('esp_currency', 'CUR_code')
37 37
 		);
38 38
 		$this->_fields = array(
39 39
 			'Currency'=>array(
40
-				'CUR_code'=> new EE_Primary_Key_String_Field('CUR_code', __('Currency COde','event_espresso')),
41
-				'CUR_single' => new EE_Plain_Text_Field('CUR_single', __('Currency Name Singular','event_espresso'), false),
42
-				'CUR_plural' => new EE_Plain_Text_Field('CUR_plural', __('Currency Name Plural','event_espresso'), false),
43
-				'CUR_sign' => new EE_Plain_Text_Field('CUR_sign', __('Currency Sign','event_espresso'), false),
44
-				'CUR_dec_plc' => new EE_Integer_Field('CUR_dec_plc', __('Currency Decimal Places','event_espresso'), false, 2),
45
-				'CUR_active'=>new EE_Boolean_Field('CUR_active', __("Active?", 'event_espresso'), false,true),
40
+				'CUR_code'=> new EE_Primary_Key_String_Field('CUR_code', __('Currency COde', 'event_espresso')),
41
+				'CUR_single' => new EE_Plain_Text_Field('CUR_single', __('Currency Name Singular', 'event_espresso'), false),
42
+				'CUR_plural' => new EE_Plain_Text_Field('CUR_plural', __('Currency Name Plural', 'event_espresso'), false),
43
+				'CUR_sign' => new EE_Plain_Text_Field('CUR_sign', __('Currency Sign', 'event_espresso'), false),
44
+				'CUR_dec_plc' => new EE_Integer_Field('CUR_dec_plc', __('Currency Decimal Places', 'event_espresso'), false, 2),
45
+				'CUR_active'=>new EE_Boolean_Field('CUR_active', __("Active?", 'event_espresso'), false, true),
46 46
 			));
47 47
 		$this->_model_relations = array(
48 48
 			'Payment_Method'=>new EE_HABTM_Relation('Currency_Payment_Method'),
49 49
 		);
50 50
 		//this model is generally available for reading
51
-		$this->_cap_restriction_generators[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Public();
51
+		$this->_cap_restriction_generators[EEM_Base::caps_read] = new EE_Restriction_Generator_Public();
52 52
 
53
-		parent::__construct( $timezone );
53
+		parent::__construct($timezone);
54 54
 	}
55 55
 
56 56
 	/**
@@ -59,10 +59,10 @@  discard block
 block discarded – undo
59 59
 	 * @param array $query_params see EEM_Base::get_all
60 60
 	 * @return EE_Currency[]
61 61
 	 */
62
-	public function get_all_active($query_params = array()){
62
+	public function get_all_active($query_params = array()) {
63 63
 		$query_params[0]['CUR_active'] = true;
64
-		if( ! isset($query_params['order_by'])){
65
-			$query_params['order_by'] = array('CUR_code'=>'ASC','CUR_single'=>'ASC');
64
+		if ( ! isset($query_params['order_by'])) {
65
+			$query_params['order_by'] = array('CUR_code'=>'ASC', 'CUR_single'=>'ASC');
66 66
 		}
67 67
 		return $this->get_all($query_params);
68 68
 	}
@@ -71,17 +71,17 @@  discard block
 block discarded – undo
71 71
 	 * @param EE_PMT_Base $payment_method_type
72 72
 	 * @return EE_Currency[]
73 73
 	 */
74
-	public function get_all_currencies_usable_by($payment_method_type){
75
-		if($payment_method_type instanceof EE_PMT_Base &&
76
-				$payment_method_type->get_gateway()){
74
+	public function get_all_currencies_usable_by($payment_method_type) {
75
+		if ($payment_method_type instanceof EE_PMT_Base &&
76
+				$payment_method_type->get_gateway()) {
77 77
 			$currencies_supported = $payment_method_type->get_gateway()->currencies_supported();
78
-		}else{
78
+		} else {
79 79
 			$currencies_supported = EE_Gateway::all_currencies_supported;
80 80
 		}
81
-		if($currencies_supported == EE_Gateway::all_currencies_supported || empty( $currencies_supported ) ) {
81
+		if ($currencies_supported == EE_Gateway::all_currencies_supported || empty($currencies_supported)) {
82 82
 			$currencies = $this->get_all_active();
83
-		}else{
84
-			$currencies = $this->get_all_active(array(array('CUR_code'=>array('IN',$currencies_supported))));
83
+		} else {
84
+			$currencies = $this->get_all_active(array(array('CUR_code'=>array('IN', $currencies_supported))));
85 85
 		}
86 86
 		return $currencies;
87 87
 	}
Please login to merge, or discard this patch.
Braces   +4 added lines, -3 removed lines patch added patch discarded remove patch
@@ -1,6 +1,7 @@  discard block
 block discarded – undo
1 1
 <?php
2
-if (!defined('EVENT_ESPRESSO_VERSION'))
2
+if (!defined('EVENT_ESPRESSO_VERSION')) {
3 3
 	exit('No direct script access allowed');
4
+}
4 5
 
5 6
 /**
6 7
  * Event Espresso
@@ -84,7 +85,7 @@  discard block
 block discarded – undo
84 85
 	public function is_valid() {
85 86
 		if(count($this->_validation_errors)){
86 87
 			return false;
87
-		}else{
88
+		} else{
88 89
 			return true;
89 90
 		}
90 91
 	}
@@ -113,7 +114,7 @@  discard block
 block discarded – undo
113 114
 		if($message_or_object instanceof EE_Validation_Error){
114 115
 			$validation_error= $message_or_object;
115 116
 			$validation_error->set_form_section($this);
116
-		}else{
117
+		} else{
117 118
 			$validation_error = new EE_Validation_Error($message_or_object, $error_code, $this, $previous_exception);
118 119
 		}
119 120
 		$this->_validation_errors[] = $validation_error;
Please login to merge, or discard this patch.
core/db_models/EEM_Currency_Payment_Method.model.php 2 patches
Spacing   +11 added lines, -11 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,22 +25,22 @@  discard block
 block discarded – undo
25 25
  *
26 26
  * ------------------------------------------------------------------------
27 27
  */
28
-class EEM_Currency_Payment_Method extends EEM_Base{
28
+class EEM_Currency_Payment_Method extends EEM_Base {
29 29
 	// private instance of the Attendee object
30 30
 	protected static $_instance = NULL;
31 31
 
32 32
 
33
-	protected function __construct( $timezone = NULL ) {
34
-		$this->singular_item = __('Currency Usable by Payment Method','event_espresso');
35
-		$this->plural_item = __('Currencies Usable by Payment Methods','event_espresso');
33
+	protected function __construct($timezone = NULL) {
34
+		$this->singular_item = __('Currency Usable by Payment Method', 'event_espresso');
35
+		$this->plural_item = __('Currencies Usable by Payment Methods', 'event_espresso');
36 36
 		$this->_tables = array(
37
-			'Currency_Payment_Method'=>new EE_Primary_Table('esp_currency_payment_method','CPM_ID')
37
+			'Currency_Payment_Method'=>new EE_Primary_Table('esp_currency_payment_method', 'CPM_ID')
38 38
 		);
39 39
 		$this->_fields = array(
40 40
 			'Currency_Payment_Method'=>array(
41
-				'CPM_ID'=>new EE_Primary_Key_Int_Field('CPM_ID', __('Currency to Payment Method LInk ID','event_espresso')),
42
-				'CUR_code'=>new EE_Foreign_Key_String_Field('CUR_code', __('Currency Code','event_espresso'), false, 0, 'Currency'),
43
-				'PMD_ID'=>new EE_Foreign_Key_Int_Field('PMD_ID', __('Paymetn Method ID','event_espresso'), false, 0, 'Payment_Method')
41
+				'CPM_ID'=>new EE_Primary_Key_Int_Field('CPM_ID', __('Currency to Payment Method LInk ID', 'event_espresso')),
42
+				'CUR_code'=>new EE_Foreign_Key_String_Field('CUR_code', __('Currency Code', 'event_espresso'), false, 0, 'Currency'),
43
+				'PMD_ID'=>new EE_Foreign_Key_Int_Field('PMD_ID', __('Paymetn Method ID', 'event_espresso'), false, 0, 'Payment_Method')
44 44
 			)
45 45
 		);
46 46
 		$this->_model_relations = array(
@@ -48,9 +48,9 @@  discard block
 block discarded – undo
48 48
 			'Payment_Method'=>new EE_Belongs_To_Relation()
49 49
 		);
50 50
 		//this model is generally available for reading
51
-		$this->_cap_restriction_generators[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Public();
51
+		$this->_cap_restriction_generators[EEM_Base::caps_read] = new EE_Restriction_Generator_Public();
52 52
 		$this->_caps_slug = 'payment_methods';
53
-		parent::__construct( $timezone );
53
+		parent::__construct($timezone);
54 54
 	}
55 55
 }
56 56
 
Please login to merge, or discard this patch.
Braces   +2 added lines, -1 removed lines patch added patch discarded remove patch
@@ -1,7 +1,8 @@
 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 7
  * Event Espresso
7 8
  *
Please login to merge, or discard this patch.