Completed
Branch 4.8-master (798cec)
by
unknown
17:06 queued 12s
created
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.
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.
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -257,7 +257,7 @@
 block discarded – undo
257 257
 	* 		@param	int	$TXN_ID
258 258
 	* 		@param    int		$ATT_ID
259 259
 	* 		@param    int		$att_nmbr 	in case the ATT_ID is the same for multiple registrations (same details used) then the attendee number is required
260
-	*		@return 		mixed		array on success, FALSE on fail
260
+	*		@return 		EE_Base_Class|null		array on success, FALSE on fail
261 261
 	*/
262 262
 	public function get_registration_for_transaction_attendee( $TXN_ID = 0, $ATT_ID = 0, $att_nmbr = 0 ) {
263 263
 		return $this->get_one(array(
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.
Doc Comments   +16 added lines, -16 removed lines patch added patch discarded remove patch
@@ -761,7 +761,7 @@  discard block
 block discarded – undo
761 761
 	 * Returns the name of the field's name that points to the WP_User table
762 762
 	 *  on this model (or follows the _model_chain_to_wp_user and uses that model's
763 763
 	 * foreign key to the WP_User table)
764
-	 * @return string|boolean string on success, boolean false when there is no
764
+	 * @return string|false string on success, boolean false when there is no
765 765
 	 * foreign key to the WP_User table
766 766
 	 */
767 767
 	function wp_user_field_name() {
@@ -858,6 +858,7 @@  discard block
 block discarded – undo
858 858
 	 * If you would like to use these custom selections in WHERE, GROUP_BY, or HAVING clauses, you must instead provide an array.
859 859
 	 * Array keys are the aliases used to refer to this selection, and values are to be numerically-indexed arrays, where 0 is the selection
860 860
 	 * and 1 is the data type. Eg, array('count'=>array('COUNT(REG_ID)','%d'))
861
+	 * @param string $columns_to_select
861 862
 	 * @return array|stdClass[] like results of $wpdb->get_results($sql,OBJECT), (ie, output type is OBJECT)
862 863
 	 */
863 864
 	public function  get_all_wpdb_results($query_params = array(), $output = ARRAY_A, $columns_to_select = null){
@@ -1200,7 +1201,7 @@  discard block
 block discarded – undo
1200 1201
 	 * @param bool   $pretty          Whether to return the pretty formats (true) or not (false).
1201 1202
 	 * @throws EE_Error   If the given field_name is not of the EE_Datetime_Field type.
1202 1203
 	 *
1203
-	 * @return array formats in an array with the date format first, and the time format last.
1204
+	 * @return string[] formats in an array with the date format first, and the time format last.
1204 1205
 	 */
1205 1206
 	public function get_formats_for( $field_name, $pretty = false ) {
1206 1207
 		$field_settings = $this->field_settings_for( $field_name );
@@ -1235,7 +1236,7 @@  discard block
 block discarded – undo
1235 1236
 	 *
1236 1237
 	 * @throws EE_Error   	If the given field_name is not of the EE_Datetime_Field type.
1237 1238
 	 *
1238
-	 * @return int|string  If the given field_name is not of the EE_Datetime_Field type, then an EE_Error
1239
+	 * @return string|null  If the given field_name is not of the EE_Datetime_Field type, then an EE_Error
1239 1240
 	 *                    	     exception is triggered.
1240 1241
 	 */
1241 1242
 	public function current_time_for_query( $field_name, $timestamp = false, $what = 'both' ) {
@@ -1535,7 +1536,7 @@  discard block
 block discarded – undo
1535 1536
 	 * not just have a flag field on it switched
1536 1537
 	 * Wrapper for EEM_Base::delete_permanently()
1537 1538
 	 * @param mixed $id
1538
-	 * @return boolean whether the row got deleted or not
1539
+	 * @return integer whether the row got deleted or not
1539 1540
 	 */
1540 1541
 	public function delete_permanently_by_ID( $id ) {
1541 1542
 		return $this->delete_permanently( 
@@ -1552,7 +1553,7 @@  discard block
 block discarded – undo
1552 1553
 	 * Deletes a single row from the DB given the model object's primary key value. (eg, EE_Attendee->ID()'s value).
1553 1554
 	 * Wrapper for EEM_Base::delete()
1554 1555
 	 * @param mixed $id
1555
-	 * @return boolean whether the row got deleted or not
1556
+	 * @return integer whether the row got deleted or not
1556 1557
 	 */
1557 1558
 	public function delete_by_ID( $id ){
1558 1559
 		return $this->delete( 
@@ -1926,7 +1927,7 @@  discard block
 block discarded – undo
1926 1927
 	/**
1927 1928
 	 * Verifies the EE addons' database is up-to-date and records that we've done it on
1928 1929
 	 * EEM_Base::$_db_verification_level
1929
-	 * @param $wpdb_method
1930
+	 * @param string $wpdb_method
1930 1931
 	 * @param $arguments_to_provide
1931 1932
 	 * @return string
1932 1933
 	 */
@@ -1994,7 +1995,6 @@  discard block
 block discarded – undo
1994 1995
 	 * 'hasAndBelongsToMany' relationships: checks that there isn't already an entry in the join table, and adds one.
1995 1996
 	 * 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
1996 1997
 	 *
1997
-	 * @param EE_Base_Class/int $thisModelObject
1998 1998
 	 * @param EE_Base_Class/int $id_or_obj EE_base_Class or ID of other Model Object
1999 1999
 	 * @param string $relationName, key in EEM_Base::_relations
2000 2000
 	 * 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')
@@ -2016,8 +2016,8 @@  discard block
 block discarded – undo
2016 2016
 	 *
2017 2017
 	 * 'hasAndBelongsToMany' relationships:removes any existing entry in the join table between the two models.
2018 2018
 	 *
2019
-	 * @param EE_Base_Class/int $id_or_obj
2020
-	 * @param EE_Base_Class/int $other_model_id_or_obj EE_Base_Class or ID of other Model Object
2019
+	 * @param EE_CPT_Base $id_or_obj
2020
+	 * @param EE_Term_Taxonomy $other_model_id_or_obj EE_Base_Class or ID of other Model Object
2021 2021
 	 * @param string $relationName key in EEM_Base::_relations
2022 2022
 	 * @return boolean of success
2023 2023
 	 * @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.
@@ -2093,7 +2093,7 @@  discard block
 block discarded – undo
2093 2093
 	/**
2094 2094
 	 * Instead of getting the related model objects, simply counts them. Ignores default_where_conditions by default,
2095 2095
 	 * unless otherwise specified in the $query_params
2096
-	 * @param int/EE_Base_Class $id_or_obj
2096
+	 * @param EE_Event $id_or_obj
2097 2097
 	 * @param string $model_name like 'Event', or 'Registration'
2098 2098
 	 * @param array $query_params like EEM_Base::get_all's
2099 2099
 	 * @param string $field_to_count name of field to count by. By default, uses primary key
@@ -2482,7 +2482,7 @@  discard block
 block discarded – undo
2482 2482
 	/**
2483 2483
 	 * Finds all the fields that correspond to the given table
2484 2484
 	 * @param string $table_alias, array key in EEM_Base::_tables
2485
-	 * @return EE_Model_Field_Base[]
2485
+	 * @return EE_Model_Field_Base
2486 2486
 	 */
2487 2487
 	function _get_fields_for_table($table_alias){
2488 2488
 		return $this->_fields[$table_alias];
@@ -3569,8 +3569,8 @@  discard block
 block discarded – undo
3569 3569
 	/**
3570 3570
 	 * gets the field object of type 'primary_key' from the fieldsSettings attribute.
3571 3571
 	 * Eg, on EE_Answer that would be ANS_ID field object
3572
-	 * @param $field_obj
3573
-	 * @return EE_Model_Field_Base
3572
+	 * @param EE_Model_Field_Base $field_obj
3573
+	 * @return boolean
3574 3574
 	 */
3575 3575
 	public function is_primary_key_field( $field_obj ){
3576 3576
 		return $field_obj instanceof EE_Primary_Key_Field_Base ? TRUE : FALSE;
@@ -3664,7 +3664,7 @@  discard block
 block discarded – undo
3664 3664
 	 * Gets the actual table for the table alias
3665 3665
 	 * @param string $table_alias eg Event, Event_Meta, Registration, Transaction, but maybe
3666 3666
 	 * a table alias with a model chain prefix, like 'Venue__Event_Venue___Event_Meta'. Either one works
3667
-	 * @return EE_Table_Base
3667
+	 * @return string
3668 3668
 	 */
3669 3669
 	function get_table_for_alias($table_alias){
3670 3670
 		$table_alias_sans_model_relation_chain_prefix = EE_Model_Parser::remove_table_alias_model_relation_chain_prefix($table_alias);
@@ -3791,7 +3791,7 @@  discard block
 block discarded – undo
3791 3791
 	 * The purpose of this method is to allow us to create a model object that is not in the db that holds default values.
3792 3792
 	 * 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!).
3793 3793
 	 *
3794
-	 * @return EE_Base_Class single EE_Base_Class object with default values for the properties.
3794
+	 * @return boolean single EE_Base_Class object with default values for the properties.
3795 3795
 	 */
3796 3796
 	public function create_default_object() {
3797 3797
 
@@ -4182,7 +4182,7 @@  discard block
 block discarded – undo
4182 4182
 	}
4183 4183
 	/**
4184 4184
 	 * Read comments for assume_values_already_prepared_by_model_object()
4185
-	 * @return int
4185
+	 * @return boolean
4186 4186
 	 */
4187 4187
 	public function get_assumption_concerning_values_already_prepared_by_model_object(){
4188 4188
 		return $this->_values_already_prepared_by_model_object;
Please login to merge, or discard this patch.
Braces   +132 added lines, -121 removed lines patch added patch discarded remove patch
@@ -540,7 +540,7 @@  discard block
 block discarded – undo
540 540
 		if( isset( $this->_cap_restriction_generators[ $context ] ) &&
541 541
 				$this->_cap_restriction_generators[ $context ] instanceof EE_Restriction_Generator_Base ) {
542 542
 			return $this->_cap_restriction_generators[ $context ]->generate_restrictions();
543
-		}else{
543
+		} else{
544 544
 			return array();
545 545
 		}
546 546
 }
@@ -591,8 +591,9 @@  discard block
 block discarded – undo
591 591
 	 * @return array
592 592
 	 */
593 593
 	 public function status_array( $translated = FALSE ) {
594
-	 	if ( !array_key_exists('Status', $this->_model_relations ) )
595
-	 		return array();
594
+	 	if ( !array_key_exists('Status', $this->_model_relations ) ) {
595
+	 		 		return array();
596
+	 	}
596 597
 	 	$model_name = $this->get_this_model_name();
597 598
 	 	$status_type = str_replace(' ', '_', strtolower( str_replace('_', ' ', $model_name) ) );
598 599
 	 	$stati = EEM_Status::instance()->get_all(array(array('STS_type' => $status_type) ) );
@@ -771,13 +772,13 @@  discard block
 block discarded – undo
771 772
 				$last_model_name = end( $models_to_follow_to_wp_users );
772 773
 				$model_with_fk_to_wp_users = EE_Registry::instance()->load_model( $last_model_name );
773 774
 				$model_chain_to_wp_user = $this->_model_chain_to_wp_user . '.';
774
-			}else{
775
+			} else{
775 776
 				$model_with_fk_to_wp_users = $this;
776 777
 				$model_chain_to_wp_user = '';
777 778
 			}
778 779
 			$wp_user_field = $model_with_fk_to_wp_users->get_foreign_key_to( 'WP_User' );
779 780
 			return $model_chain_to_wp_user . $wp_user_field->get_name();
780
-		}catch( EE_Error $e ) {
781
+		} catch( EE_Error $e ) {
781 782
 			return false;
782 783
 		}
783 784
 	}
@@ -805,11 +806,11 @@  discard block
 block discarded – undo
805 806
 	public function is_owned() {
806 807
 		if( $this->model_chain_to_wp_user() ){
807 808
 			return true;
808
-		}else{
809
+		} else{
809 810
 			try{
810 811
 				$this->get_foreign_key_to( 'WP_User' );
811 812
 				return true;
812
-			}catch( EE_Error $e ){
813
+			} catch( EE_Error $e ){
813 814
 				return false;
814 815
 			}
815 816
 		}
@@ -832,9 +833,9 @@  discard block
 block discarded – undo
832 833
 		//remember the custom selections, if any
833 834
 		if(is_array($columns_to_select)){
834 835
 			$this->_custom_selections = $columns_to_select;
835
-		}elseif(is_string($columns_to_select)){
836
+		} elseif(is_string($columns_to_select)){
836 837
 			$this->_custom_selections = array($this->_custom_selections);
837
-		}else{
838
+		} else{
838 839
 			$this->_custom_selections = array();
839 840
 		}
840 841
 
@@ -906,7 +907,7 @@  discard block
 block discarded – undo
906 907
 				$select_sql_array[] = "{$selection_and_datatype[0]} AS $alias";
907 908
 			}
908 909
 			$columns_to_select_string = implode(", ",$select_sql_array);
909
-		}else{
910
+		} else{
910 911
 			$columns_to_select_string = $columns_to_select;
911 912
 		}
912 913
 		return $columns_to_select_string;
@@ -956,7 +957,7 @@  discard block
 block discarded – undo
956 957
 		}
957 958
 		if( $this->has_primary_key_field ( ) ) {
958 959
 			$query_params[ 0 ][ $this->primary_key_name() ] = $id ;
959
-		}else{
960
+		} else{
960 961
 			//no primary key, so the $id must be from the get_index_primary_key_string()
961 962
 			$query_params[0] = array_replace_recursive( $query_params[ 0 ], $this->parse_index_primary_key_string( $id ) );
962 963
 		}
@@ -979,7 +980,7 @@  discard block
 block discarded – undo
979 980
 		$items = $this->get_all($query_params);
980 981
 		if(empty($items)){
981 982
 			return null;
982
-		}else{
983
+		} else{
983 984
 			return array_shift($items);
984 985
 		}
985 986
 	}
@@ -1374,7 +1375,7 @@  discard block
 block discarded – undo
1374 1375
 				//get the model object's PK, as we'll want this if we need to insert a row into secondary tables
1375 1376
 				if( $this->has_primary_key_field() ){
1376 1377
 					$main_table_pk_value = $wpdb_result[ $this->get_primary_key_field()->get_qualified_column() ];
1377
-				}else{
1378
+				} else{
1378 1379
 					//if there's no primary key, we basically can't support having a 2nd table on the model (we could but it would be lots of work)
1379 1380
 					$main_table_pk_value = null;
1380 1381
 				}
@@ -1413,7 +1414,7 @@  discard block
 block discarded – undo
1413 1414
 		if( $keep_model_objs_in_sync && ! $this->_values_already_prepared_by_model_object ){
1414 1415
 			if( $this->has_primary_key_field() ){
1415 1416
 				$model_objs_affected_ids = $this->get_col( $query_params );
1416
-			}else{
1417
+			} else{
1417 1418
 				//we need to select a bunch of columns and then combine them into the the "index primary key string"s
1418 1419
 				$models_affected_key_columns = $this->_get_all_wpdb_results($query_params, ARRAY_A );
1419 1420
 				$model_objs_affected_ids = array();
@@ -1473,9 +1474,9 @@  discard block
 block discarded – undo
1473 1474
 
1474 1475
 		if( $field_to_select ){
1475 1476
 			$field = $this->field_settings_for( $field_to_select );
1476
-		}elseif( $this->has_primary_key_field ( ) ){
1477
+		} elseif( $this->has_primary_key_field ( ) ){
1477 1478
 			$field = $this->get_primary_key_field();
1478
-		}else{
1479
+		} else{
1479 1480
 			//no primary key, just grab the first column
1480 1481
 			$field = reset( $this->field_settings());
1481 1482
 		}
@@ -1499,7 +1500,7 @@  discard block
 block discarded – undo
1499 1500
 		$col = $this->get_col( $query_params, $field_to_select );
1500 1501
 		if( ! empty( $col ) ) {
1501 1502
 			return reset( $col );
1502
-		}else{
1503
+		} else{
1503 1504
 			return NULL;
1504 1505
 		}
1505 1506
 	}
@@ -1614,7 +1615,7 @@  discard block
 block discarded – undo
1614 1615
 
1615 1616
 			//		/echo "delete sql:$SQL";
1616 1617
 			$rows_deleted = $this->_do_wpdb_query( 'query', array( $SQL ) );
1617
-		}else{
1618
+		} else{
1618 1619
 			$rows_deleted = 0;
1619 1620
 		}
1620 1621
 
@@ -1656,7 +1657,7 @@  discard block
 block discarded – undo
1656 1657
 		//first, if $ignore_this_model_obj was supplied, get its model
1657 1658
 		if($ignore_this_model_obj && $ignore_this_model_obj instanceof EE_Base_Class){
1658 1659
 			$ignored_model = $ignore_this_model_obj->get_model();
1659
-		}else{
1660
+		} else{
1660 1661
 			$ignored_model = null;
1661 1662
 		}
1662 1663
 		//now check all the relations of $this_model_obj_or_id and see if there
@@ -1669,7 +1670,7 @@  discard block
 block discarded – undo
1669 1670
 				if($ignored_model && $relation_name == $ignored_model->get_this_model_name()){
1670 1671
 					$related_model_objects = $relation_obj->get_all_related($this_model_obj_or_id,array(
1671 1672
 					array($ignored_model->get_primary_key_field()->get_name() => array('!=',$ignore_this_model_obj->ID()))));
1672
-				}else{
1673
+				} else{
1673 1674
 					$related_model_objects = $relation_obj->get_all_related($this_model_obj_or_id);
1674 1675
 				}
1675 1676
 
@@ -1706,24 +1707,28 @@  discard block
 block discarded – undo
1706 1707
 				}
1707 1708
 
1708 1709
 				//primary table deletes
1709
-				if ( isset( $delete_object[$primary_table->get_fully_qualified_pk_column()] ) )
1710
-					$deletes[$primary_table->get_fully_qualified_pk_column()][] = $delete_object[$primary_table->get_fully_qualified_pk_column()];
1710
+				if ( isset( $delete_object[$primary_table->get_fully_qualified_pk_column()] ) ) {
1711
+									$deletes[$primary_table->get_fully_qualified_pk_column()][] = $delete_object[$primary_table->get_fully_qualified_pk_column()];
1712
+				}
1711 1713
 
1712 1714
 				//other tables
1713 1715
 				if ( !empty( $other_tables ) ) {
1714 1716
 					foreach ( $other_tables as $ot ) {
1715 1717
 
1716 1718
 						//first check if we've got the foreign key column here.
1717
-						if ( isset( $delete_object[$ot->get_fully_qualified_fk_column()] ) )
1718
-							$deletes[$ot->get_fully_qualified_pk_column()][] = $delete_object[$ot->get_fully_qualified_fk_column()];
1719
+						if ( isset( $delete_object[$ot->get_fully_qualified_fk_column()] ) ) {
1720
+													$deletes[$ot->get_fully_qualified_pk_column()][] = $delete_object[$ot->get_fully_qualified_fk_column()];
1721
+						}
1719 1722
 
1720 1723
 						//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
1721
-						if ( isset( $delete_object[$ot->get_fully_qualified_pk_column()] ) )
1722
-							$deletes[$ot->get_fully_qualified_pk_column()][] = $delete_object[$ot->get_fully_qualified_pk_column()];
1724
+						if ( isset( $delete_object[$ot->get_fully_qualified_pk_column()] ) ) {
1725
+													$deletes[$ot->get_fully_qualified_pk_column()][] = $delete_object[$ot->get_fully_qualified_pk_column()];
1726
+						}
1723 1727
 
1724 1728
 						//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!
1725
-						if ( isset( $delete_object[$ot->get_fully_qualified_pk_on_fk_table()]) )
1726
-							$deletes[$ot->get_fully_qualified_pk_column()][] = $delete_object[$ot->get_fully_qualified_pk_column()];
1729
+						if ( isset( $delete_object[$ot->get_fully_qualified_pk_on_fk_table()]) ) {
1730
+													$deletes[$ot->get_fully_qualified_pk_column()][] = $delete_object[$ot->get_fully_qualified_pk_column()];
1731
+						}
1727 1732
 					}
1728 1733
 				}
1729 1734
 			}
@@ -1736,7 +1741,7 @@  discard block
 block discarded – undo
1736 1741
 			}
1737 1742
 
1738 1743
 			return !empty($query) ? implode(' AND ', $query ) : '';
1739
-		}elseif(count($this->get_combined_primary_key_fields()) > 1){
1744
+		} elseif(count($this->get_combined_primary_key_fields()) > 1){
1740 1745
 			$ways_to_identify_a_row = array();
1741 1746
 			$fields = $this->get_combined_primary_key_fields();
1742 1747
 			//note: because there' sno primary key, that means nothing else  can be pointing to this model, right?
@@ -1748,7 +1753,7 @@  discard block
 block discarded – undo
1748 1753
 				$ways_to_identify_a_row[] = "(".implode(" AND ",$values_for_each_cpk_for_a_row).")";
1749 1754
 			}
1750 1755
 			return implode(" OR ",$ways_to_identify_a_row);
1751
-		}else{
1756
+		} else{
1752 1757
 			//so there's no primary key and no combined key...
1753 1758
 			//sorry, can't help you
1754 1759
 			throw new EE_Error(sprintf(__("Cannot delete objects of type %s because there is no primary key NOR combined key", "event_espresso"),get_class($this)));
@@ -1770,10 +1775,10 @@  discard block
 block discarded – undo
1770 1775
 		if($field_to_count){
1771 1776
 			$field_obj = $this->field_settings_for($field_to_count);
1772 1777
 			$column_to_count = $field_obj->get_qualified_column();
1773
-		}elseif($this->has_primary_key_field ()){
1778
+		} elseif($this->has_primary_key_field ()){
1774 1779
 			$pk_field_obj = $this->get_primary_key_field();
1775 1780
 			$column_to_count = $pk_field_obj->get_qualified_column();
1776
-		}else{//there's no primary key
1781
+		} else{//there's no primary key
1777 1782
 			$column_to_count = '*';
1778 1783
 		}
1779 1784
 
@@ -1795,7 +1800,7 @@  discard block
 block discarded – undo
1795 1800
 		if($field_to_sum){
1796 1801
 			$field_obj = $this->field_settings_for($field_to_sum);
1797 1802
 
1798
-		}else{
1803
+		} else{
1799 1804
 			$field_obj = $this->get_primary_key_field();
1800 1805
 		}
1801 1806
 		$column_to_count = $field_obj->get_qualified_column();
@@ -1804,7 +1809,7 @@  discard block
 block discarded – undo
1804 1809
 		$return_value = $this->_do_wpdb_query('get_var',array( $SQL ) );
1805 1810
 		if($field_obj->get_wpdb_data_type() == '%d' || $field_obj->get_wpdb_data_type() == '%s' ){
1806 1811
 			return (float)$return_value;
1807
-		}else{//must be %f
1812
+		} else{//must be %f
1808 1813
 			return (float)$return_value;
1809 1814
 		}
1810 1815
 	}
@@ -1842,10 +1847,10 @@  discard block
 block discarded – undo
1842 1847
 			$wpdb->show_errors( $old_show_errors_value );
1843 1848
 			if( ! empty( $wpdb->last_error ) ){
1844 1849
 				throw new EE_Error( sprintf( __( 'WPDB Error: "%s"', 'event_espresso' ), $wpdb->last_error ) );
1845
-			}elseif( $result === false ){
1850
+			} elseif( $result === false ){
1846 1851
 				throw new EE_Error( sprintf( __( 'WPDB Error occurred, but no error message was logged by wpdb! The wpdb method called was "%1$s" and the arguments were "%2$s"', 'event_espresso' ), $wpdb_method, var_export( $arguments_to_provide, true ) ) );
1847 1852
 			}
1848
-		}elseif( $result === false ) {
1853
+		} elseif( $result === false ) {
1849 1854
 			EE_Error::add_error( sprintf( __( 'A database error has occurred. Turn on WP_DEBUG for more information.', 'event_espresso' )), __FILE__, __FUNCTION__, __LINE__);
1850 1855
 		}
1851 1856
 		return $result;
@@ -2155,7 +2160,7 @@  discard block
 block discarded – undo
2155 2160
 		$results = $this->get_all_related($id_or_obj,$other_model_name,$query_params);
2156 2161
 		if( $results ){
2157 2162
 			return array_shift($results);
2158
-		}else{
2163
+		} else{
2159 2164
 			return null;
2160 2165
 		}
2161 2166
 
@@ -2226,7 +2231,7 @@  discard block
 block discarded – undo
2226 2231
 			 */
2227 2232
 			do_action( 'AHEE__EEM_Base__insert__end', $this, $field_n_values, $new_id );
2228 2233
 			return $new_id;
2229
-		}else{
2234
+		} else{
2230 2235
 			return FALSE;
2231 2236
 		}
2232 2237
 	}
@@ -2267,9 +2272,9 @@  discard block
 block discarded – undo
2267 2272
 	public function get_one_conflicting($obj_or_fields_array, $include_primary_key = true ){
2268 2273
 		if($obj_or_fields_array instanceof EE_Base_Class){
2269 2274
 			$fields_n_values = $obj_or_fields_array->model_field_array();
2270
-		}elseif( is_array($obj_or_fields_array)){
2275
+		} elseif( is_array($obj_or_fields_array)){
2271 2276
 			$fields_n_values = $obj_or_fields_array;
2272
-		}else{
2277
+		} else{
2273 2278
 			throw new EE_Error(sprintf(__("%s get_all_conflicting should be called with a model object or an array of field names and values, you provided %d", "event_espresso"),get_class($this),$obj_or_fields_array));
2274 2279
 		}
2275 2280
 		$query_params = array();
@@ -2285,7 +2290,7 @@  discard block
 block discarded – undo
2285 2290
 		//if there is nothing to base this search on, then we shouldn't find anything
2286 2291
 		if( empty( $query_params ) ){
2287 2292
 			return array();
2288
-		}else{
2293
+		} else{
2289 2294
 			return $this->get_one($query_params);
2290 2295
 		}
2291 2296
 	}
@@ -2358,12 +2363,12 @@  discard block
 block discarded – undo
2358 2363
 		if($this->has_primary_key_field()){
2359 2364
 			if($this->get_primary_key_field()->is_auto_increment()){
2360 2365
 				return $wpdb->insert_id;
2361
-			}else{
2366
+			} else{
2362 2367
 				//it's not an auto-increment primary key, so
2363 2368
 				//it must have been supplied
2364 2369
 				return $fields_n_values[$this->get_primary_key_field()->get_name()];
2365 2370
 			}
2366
-		}else{
2371
+		} else{
2367 2372
 			//we can't return a  primary key because there is none. instead return
2368 2373
 			//a unique string indicating this model
2369 2374
 			return $this->get_index_primary_key_string($fields_n_values);
@@ -2411,7 +2416,7 @@  discard block
 block discarded – undo
2411 2416
 					//leave the value alone
2412 2417
 			}
2413 2418
 			return $value;
2414
-		}else{
2419
+		} else{
2415 2420
 			return $value;
2416 2421
 		}
2417 2422
 	}
@@ -2504,7 +2509,7 @@  discard block
 block discarded – undo
2504 2509
 		if(array_key_exists('group_by', $query_params)){
2505 2510
 			if(is_array($query_params['group_by'])){
2506 2511
 				$this->_extract_related_models_from_sub_params_array_values($query_params['group_by'],$query_info_carrier,'group_by');
2507
-			}elseif( ! empty ( $query_params['group_by'] )){
2512
+			} elseif( ! empty ( $query_params['group_by'] )){
2508 2513
 				$this->_extract_related_model_info_from_query_param( $query_params['group_by'],$query_info_carrier,'group_by');
2509 2514
 			}
2510 2515
 		}
@@ -2512,10 +2517,11 @@  discard block
 block discarded – undo
2512 2517
 			$this->_extract_related_models_from_sub_params_array_keys($query_params[0], $query_info_carrier,'having');
2513 2518
 		}
2514 2519
 		if(array_key_exists('order_by', $query_params)){
2515
-			if ( is_array( $query_params['order_by'] ) )
2516
-				$this->_extract_related_models_from_sub_params_array_keys($query_params['order_by'],$query_info_carrier,'order_by');
2517
-			elseif( ! empty( $query_params['order_by'] ))
2518
-				$this->_extract_related_model_info_from_query_param( $query_params['order_by'], $query_info_carrier,'order_by');
2520
+			if ( is_array( $query_params['order_by'] ) ) {
2521
+							$this->_extract_related_models_from_sub_params_array_keys($query_params['order_by'],$query_info_carrier,'order_by');
2522
+			} elseif( ! empty( $query_params['order_by'] )) {
2523
+							$this->_extract_related_model_info_from_query_param( $query_params['order_by'], $query_info_carrier,'order_by');
2524
+			}
2519 2525
 		}
2520 2526
 		if(array_key_exists('force_join', $query_params)){
2521 2527
 			$this->_extract_related_models_from_sub_params_array_values($query_params['force_join'],$query_info_carrier,'force_join');
@@ -2547,10 +2553,10 @@  discard block
 block discarded – undo
2547 2553
 					if (! is_array($possibly_array_of_params)){
2548 2554
 						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"),
2549 2555
 							$param,$possibly_array_of_params));
2550
-					}else{
2556
+					} else{
2551 2557
 						$this->_extract_related_models_from_sub_params_array_keys($possibly_array_of_params, $model_query_info_carrier,$query_param_type);
2552 2558
 					}
2553
-				}elseif($query_param_type === 0 //ie WHERE
2559
+				} elseif($query_param_type === 0 //ie WHERE
2554 2560
 						&& is_array($possibly_array_of_params)
2555 2561
 						&& isset($possibly_array_of_params[2])
2556 2562
 						&& $possibly_array_of_params[2] == true){
@@ -2610,7 +2616,7 @@  discard block
 block discarded – undo
2610 2616
 		}
2611 2617
 		if( isset( $query_params[0] ) ) {
2612 2618
 			$where_query_params = $query_params[0];
2613
-		}else{
2619
+		} else{
2614 2620
 			$where_query_params = array();
2615 2621
 		}
2616 2622
 		//first check if we should alter the query to account for caps or not
@@ -2628,7 +2634,7 @@  discard block
 block discarded – undo
2628 2634
 		}
2629 2635
 		if( array_key_exists( 'default_where_conditions',$query_params) && ! empty( $query_params['default_where_conditions'] )){
2630 2636
 			$use_default_where_conditions = $query_params['default_where_conditions'];
2631
-		}else{
2637
+		} else{
2632 2638
 			$use_default_where_conditions = 'all';
2633 2639
 		}
2634 2640
 		$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 );
@@ -2651,7 +2657,7 @@  discard block
 block discarded – undo
2651 2657
 				}
2652 2658
 				//they passed us an array for the limit. Assume it's like array(50,25), meaning offset by 50, and get 25
2653 2659
 				$query_object->set_limit_sql(" LIMIT ".$query_params['limit'][0].",".$query_params['limit'][1]);
2654
-			}elseif( ! empty ( $query_params['limit'] )){
2660
+			} elseif( ! empty ( $query_params['limit'] )){
2655 2661
 				$query_object->set_limit_sql((" LIMIT ".$query_params['limit']));
2656 2662
 			}
2657 2663
 		}
@@ -2673,11 +2679,11 @@  discard block
 block discarded – undo
2673 2679
 					$order_array[] = $this->_deduce_column_name_from_query_param($field_name_to_order_by).SP.$order;
2674 2680
 				}
2675 2681
 				$query_object->set_order_by_sql(" ORDER BY ".implode(",",$order_array));
2676
-			}elseif( ! empty ( $query_params['order_by'] )){
2682
+			} elseif( ! empty ( $query_params['order_by'] )){
2677 2683
 				$this->_extract_related_model_info_from_query_param($query_params['order_by'],$query_object,'order',$query_params['order_by']);
2678 2684
 				if(isset($query_params['order'])){
2679 2685
 					$order = $this->_extract_order($query_params['order']);
2680
-				}else{
2686
+				} else{
2681 2687
 					$order = 'DESC';
2682 2688
 				}
2683 2689
 				$query_object->set_order_by_sql(" ORDER BY ".$this->_deduce_column_name_from_query_param($query_params['order_by']).SP.$order);
@@ -2700,7 +2706,7 @@  discard block
 block discarded – undo
2700 2706
 					$group_by_array[] = $this->_deduce_column_name_from_query_param($field_name_to_group_by);
2701 2707
 				}
2702 2708
 				$query_object->set_group_by_sql(" GROUP BY ".implode(", ",$group_by_array));
2703
-			}elseif( ! empty ( $query_params['group_by'] )){
2709
+			} elseif( ! empty ( $query_params['group_by'] )){
2704 2710
 				$query_object->set_group_by_sql(" GROUP BY ".$this->_deduce_column_name_from_query_param($query_params['group_by']));
2705 2711
 			}
2706 2712
 		}
@@ -2724,8 +2730,9 @@  discard block
 block discarded – undo
2724 2730
 			}
2725 2731
 		}
2726 2732
 		$main_model_join_sql = $query_object->get_main_model_join_sql();
2727
-		if ( empty( $main_model_join_sql ) )
2728
-			$query_object->set_main_model_join_sql($this->_construct_internal_join());
2733
+		if ( empty( $main_model_join_sql ) ) {
2734
+					$query_object->set_main_model_join_sql($this->_construct_internal_join());
2735
+		}
2729 2736
 		return $query_object;
2730 2737
 	}
2731 2738
 
@@ -2758,7 +2765,7 @@  discard block
 block discarded – undo
2758 2765
 	private function _extract_order($should_be_order_string){
2759 2766
 		if(in_array($should_be_order_string, $this->_allowed_order_values)){
2760 2767
 			return $should_be_order_string;
2761
-		}else{
2768
+		} else{
2762 2769
 			throw new EE_Error(sprintf(__("While performing a query on '%s', tried to use '%s' as an order parameter. ", "event_espresso"),get_class($this),$should_be_order_string));
2763 2770
 		}
2764 2771
 	}
@@ -2790,9 +2797,9 @@  discard block
 block discarded – undo
2790 2797
 		}
2791 2798
 		if( in_array($use_default_where_conditions, array('all','this_model_only')) ){
2792 2799
 			$universal_query_params = $this->_get_default_where_conditions();
2793
-		}elseif( in_array( $use_default_where_conditions, array( 'minimum' ) ) ) {
2800
+		} elseif( in_array( $use_default_where_conditions, array( 'minimum' ) ) ) {
2794 2801
 			$universal_query_params = $this->_get_minimum_where_conditions();
2795
-		}else{
2802
+		} else{
2796 2803
 			$universal_query_params = array();
2797 2804
 		}
2798 2805
 
@@ -2832,14 +2839,14 @@  discard block
 block discarded – undo
2832 2839
 		foreach($default_where_conditions as $key => $val){
2833 2840
 			if( isset($provided_where_conditions[$key])){
2834 2841
 				$none_overridden = false;
2835
-			}else{
2842
+			} else{
2836 2843
 				$null_friendly_where_conditions[$or_condition_key_for_defaults]['AND'][$key] = $val;
2837 2844
 			}
2838 2845
 		}
2839 2846
 		if( $none_overridden && $default_where_conditions){
2840 2847
 			if($model->has_primary_key_field()){
2841 2848
 				$null_friendly_where_conditions[$or_condition_key_for_defaults][$model_relation_path.".".$model->primary_key_name()] = array('IS NULL');
2842
-			}else{
2849
+			} else{
2843 2850
 				//@todo NO PK, use other defaults
2844 2851
 			}
2845 2852
 		}
@@ -2855,8 +2862,9 @@  discard block
 block discarded – undo
2855 2862
 	 * @return array like EEM_Base::get_all's $query_params[0] (where conditions)
2856 2863
 	 */
2857 2864
 	private function _get_default_where_conditions($model_relation_path = null){
2858
-		if ( $this->_ignore_where_strategy )
2859
-			return array();
2865
+		if ( $this->_ignore_where_strategy ) {
2866
+					return array();
2867
+		}
2860 2868
 
2861 2869
 		return $this->_default_where_conditions_strategy->get_default_where_conditions($model_relation_path);
2862 2870
 	}
@@ -2870,8 +2878,9 @@  discard block
 block discarded – undo
2870 2878
 	 * @return array like EEM_Base::get_all's $query_params[0] (where conditions)
2871 2879
 	 */
2872 2880
 	protected function _get_minimum_where_conditions($model_relation_path = null){
2873
-		if ( $this->_ignore_where_strategy )
2874
-			return array();
2881
+		if ( $this->_ignore_where_strategy ) {
2882
+					return array();
2883
+		}
2875 2884
 
2876 2885
 		return $this->_minimum_where_conditions_strategy->get_default_where_conditions($model_relation_path);
2877 2886
 	}
@@ -2945,7 +2954,7 @@  discard block
 block discarded – undo
2945 2954
 		if(array_key_exists($query_param,$this_model_fields)){
2946 2955
 			if($allow_fields){
2947 2956
 				return;
2948
-			}else{
2957
+			} else{
2949 2958
 				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"),
2950 2959
 						$query_param,get_class($this),$query_param_type,$original_query_param));
2951 2960
 			}
@@ -2954,7 +2963,7 @@  discard block
 block discarded – undo
2954 2963
 		elseif(in_array($query_param, $this->_logic_query_param_keys, TRUE)){
2955 2964
 			if($allow_logic_query_params){
2956 2965
 				return;
2957
-			}else{
2966
+			} else{
2958 2967
 				throw new EE_Error(
2959 2968
 					sprintf(
2960 2969
 						__( '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' ),
@@ -2985,12 +2994,12 @@  discard block
 block discarded – undo
2985 2994
 					//we should actually end in a field name, not a model like this!
2986 2995
 					throw new EE_Error(sprintf(__("Query param '%s' (of type %s on model %s) shouldn't end on a period (.) ", "event_espresso"),
2987 2996
 					$query_param,$query_param_type,get_class($this),$valid_related_model_name));
2988
-				}else{
2997
+				} else{
2989 2998
 					$related_model_obj = $this->get_related_model_obj($valid_related_model_name);
2990 2999
 					$related_model_obj->_extract_related_model_info_from_query_param($query_param, $passed_in_query_info, $query_param_type, $original_query_param);
2991 3000
 					return;
2992 3001
 				}
2993
-			}elseif($query_param == $valid_related_model_name){
3002
+			} elseif($query_param == $valid_related_model_name){
2994 3003
 				$this->_add_join_to_model($valid_related_model_name, $passed_in_query_info,$original_query_param);
2995 3004
 				return;
2996 3005
 			}
@@ -3050,7 +3059,7 @@  discard block
 block discarded – undo
3050 3059
 		$SQL = $this->_construct_condition_clause_recursive($where_params, ' AND ');
3051 3060
 		if($SQL){
3052 3061
 			return " WHERE ". $SQL;
3053
-		}else{
3062
+		} else{
3054 3063
 			return '';
3055 3064
 		}
3056 3065
 	}
@@ -3065,7 +3074,7 @@  discard block
 block discarded – undo
3065 3074
 		$SQL = $this->_construct_condition_clause_recursive($having_params, ' AND ');
3066 3075
 		if($SQL){
3067 3076
 			return " HAVING ". $SQL;
3068
-		}else{
3077
+		} else{
3069 3078
 			return '';
3070 3079
 		}
3071 3080
 
@@ -3088,7 +3097,7 @@  discard block
 block discarded – undo
3088 3097
 			$model_instance=call_user_func($model_name."::instance");
3089 3098
 			/* @var $model_instance EEM_Base */
3090 3099
 			return $model_instance->field_settings_for($field_name);
3091
-		}else{
3100
+		} else{
3092 3101
 			throw new EE_Error(sprintf(__('No model named %s exists, with classname %s and filepath %s','event_espresso'),$model_name,$model_class,$model_filepath));
3093 3102
 		}
3094 3103
 	}
@@ -3121,14 +3130,14 @@  discard block
 block discarded – undo
3121 3130
 						$where_clauses[] = " (". $this->_construct_condition_clause_recursive($op_and_value_or_sub_condition, ' OR ') .")";
3122 3131
 						break;
3123 3132
 				}
3124
-			}else{
3133
+			} else{
3125 3134
 				$field_obj = $this->_deduce_field_from_query_param($query_param);
3126 3135
 
3127 3136
 				//if it's not a normal field, maybe it's a custom selection?
3128 3137
 				if( ! $field_obj){
3129 3138
 					if(isset( $this->_custom_selections[$query_param][1])){
3130 3139
 						$field_obj = $this->_custom_selections[$query_param][1];
3131
-					}else{
3140
+					} else{
3132 3141
 						throw new EE_Error(sprintf(__("%s is neither a valid model field name, nor a custom selection", "event_espresso"),$query_param));
3133 3142
 					}
3134 3143
 				}
@@ -3138,7 +3147,7 @@  discard block
 block discarded – undo
3138 3147
 		}
3139 3148
 		if($where_clauses){
3140 3149
 			$SQL = implode($glue,$where_clauses);
3141
-		}else{
3150
+		} else{
3142 3151
 			$SQL = '';
3143 3152
 		}
3144 3153
 		return $SQL;
@@ -3158,11 +3167,11 @@  discard block
 block discarded – undo
3158 3167
 		if( $field ){
3159 3168
 			$table_alias_prefix = EE_Model_Parser::extract_table_alias_model_relation_chain_from_query_param( $field->get_model_name(), $query_param );
3160 3169
 			return $table_alias_prefix . $field->get_qualified_column();
3161
-		}elseif(array_key_exists($query_param,$this->_custom_selections)){
3170
+		} elseif(array_key_exists($query_param,$this->_custom_selections)){
3162 3171
 			//maybe it's custom selection item?
3163 3172
 			//if so, just use it as the "column name"
3164 3173
 			return $query_param;
3165
-		}else{
3174
+		} else{
3166 3175
 			throw new EE_Error(sprintf(__("%s is not a valid field on this model, nor a custom selection (%s)", "event_espresso"),$query_param,implode(",",$this->_custom_selections)));
3167 3176
 		}
3168 3177
 	}
@@ -3179,7 +3188,7 @@  discard block
 block discarded – undo
3179 3188
 		$pos_of_star = strpos($condition_query_param_key, '*');
3180 3189
 		if($pos_of_star === FALSE){
3181 3190
 			return $condition_query_param_key;
3182
-		}else{
3191
+		} else{
3183 3192
 			$condition_query_param_sans_star = substr($condition_query_param_key, 0, $pos_of_star);
3184 3193
 			return $condition_query_param_sans_star;
3185 3194
 		}
@@ -3205,7 +3214,7 @@  discard block
 block discarded – undo
3205 3214
 				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)));
3206 3215
 			}
3207 3216
 			$value = isset($op_and_value[1]) ? $op_and_value[1] : null;
3208
-		}else{
3217
+		} else{
3209 3218
 			$operator = '=';
3210 3219
 			$value = $op_and_value;
3211 3220
 		}
@@ -3213,7 +3222,7 @@  discard block
 block discarded – undo
3213 3222
 		//check to see if the value is actually another field
3214 3223
 		if(is_array($op_and_value) && isset($op_and_value[2]) && $op_and_value[2] == true){
3215 3224
 			return $operator.SP.$this->_deduce_column_name_from_query_param($value);
3216
-		}elseif(in_array($operator, $this->_in_style_operators) && is_array($value)){
3225
+		} elseif(in_array($operator, $this->_in_style_operators) && is_array($value)){
3217 3226
 			//in this case, the value should be an array, or at least a comma-separated list
3218 3227
 			//it will need to handle a little differently
3219 3228
 			$cleaned_value = $this->_construct_in_value($value, $field_obj);
@@ -3221,8 +3230,9 @@  discard block
 block discarded – undo
3221 3230
 			return $operator.SP.$cleaned_value;
3222 3231
 		} elseif( in_array( $operator, $this->_between_style_operators ) && is_array( $value ) ) {
3223 3232
 			//the value should be an array with count of two.
3224
-			if ( count($value) !== 2 )
3225
-				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" ) );
3233
+			if ( count($value) !== 2 ) {
3234
+							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" ) );
3235
+			}
3226 3236
 			$cleaned_value = $this->_construct_between_value( $value, $field_obj );
3227 3237
 			return $operator.SP.$cleaned_value;
3228 3238
 		} elseif( in_array( $operator, $this->_null_style_operators ) ) {
@@ -3230,17 +3240,17 @@  discard block
 block discarded – undo
3230 3240
 				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));
3231 3241
 			}
3232 3242
 			return $operator;
3233
-		}elseif( $operator == 'LIKE' && ! is_array($value)){
3243
+		} elseif( $operator == 'LIKE' && ! is_array($value)){
3234 3244
 			//if the operator is 'LIKE', we want to allow percent signs (%) and not
3235 3245
 			//remove other junk. So just treat it as a string.
3236 3246
 			return $operator.SP.$this->_wpdb_prepare_using_field($value, '%s');
3237
-		}elseif( ! in_array($operator, $this->_in_style_operators) && ! is_array($value)){
3247
+		} elseif( ! in_array($operator, $this->_in_style_operators) && ! is_array($value)){
3238 3248
 			return $operator.SP.$this->_wpdb_prepare_using_field($value,$field_obj);
3239
-		}elseif(in_array($operator, $this->_in_style_operators) && ! is_array($value)){
3249
+		} elseif(in_array($operator, $this->_in_style_operators) && ! is_array($value)){
3240 3250
 			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));
3241
-		}elseif( ! in_array($operator, $this->_in_style_operators) && is_array($value)){
3251
+		} elseif( ! in_array($operator, $this->_in_style_operators) && is_array($value)){
3242 3252
 			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));
3243
-		}else{
3253
+		} else{
3244 3254
 			throw new EE_Error(sprintf(__("It appears you've provided some totally invalid query parameters. Operator and value were:'%s', which isn't right at all", "event_espresso"),  http_build_query($op_and_value)));
3245 3255
 		}
3246 3256
 	}
@@ -3310,7 +3320,7 @@  discard block
 block discarded – undo
3310 3320
 		global $wpdb;
3311 3321
 		if($field_obj instanceof EE_Model_Field_Base){
3312 3322
 			return $wpdb->prepare($field_obj->get_wpdb_data_type(),$this->_prepare_value_for_use_in_db($value, $field_obj));
3313
-		}else{//$field_obj should really just be a data type
3323
+		} else{//$field_obj should really just be a data type
3314 3324
 			if( ! in_array($field_obj,$this->_valid_wpdb_data_types)){
3315 3325
 				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)));
3316 3326
 			}
@@ -3339,14 +3349,14 @@  discard block
 block discarded – undo
3339 3349
 		if($number_of_parts == 1){
3340 3350
 			$field_name = $last_query_param_part;
3341 3351
 			$model_obj = $this;
3342
-		}else{// $number_of_parts >= 2
3352
+		} else{// $number_of_parts >= 2
3343 3353
 			//the last part is the column name, and there are only 2parts. therefore...
3344 3354
 			$field_name = $last_query_param_part;
3345 3355
 			$model_obj = $this->get_related_model_obj( $query_param_parts[ $number_of_parts - 2 ]);
3346 3356
 		}
3347 3357
 		try{
3348 3358
 			return $model_obj->field_settings_for($field_name);
3349
-		}catch(EE_Error $e){
3359
+		} catch(EE_Error $e){
3350 3360
 			return null;
3351 3361
 		}
3352 3362
 	}
@@ -3365,7 +3375,7 @@  discard block
 block discarded – undo
3365 3375
 		$field = isset($all_fields[$field_name]) ? $all_fields[$field_name] : FALSE;
3366 3376
 		if($field){
3367 3377
 			return $field->get_qualified_column();
3368
-		}else{
3378
+		} else{
3369 3379
 			throw new EE_Error(sprintf(__("There is no field titled %s on model %s. Either the query trying to use it is bad, or you need to add it to the list of fields on the model.",'event_espresso'),$field_name,get_class($this)));
3370 3380
 		}
3371 3381
 	}
@@ -3431,7 +3441,7 @@  discard block
 block discarded – undo
3431 3441
 					//the FROM statement, BUT the primary table isn't. So we want
3432 3442
 					//to add the inverse join sql
3433 3443
 					$SQL .= $table_obj->get_inverse_join_sql($alias_prefixed);
3434
-				}else{
3444
+				} else{
3435 3445
 					//just add a regular JOIN to this table from the primary table
3436 3446
 					$SQL .= $table_obj->get_join_sql($alias_prefixed);
3437 3447
 				}
@@ -3546,7 +3556,7 @@  discard block
 block discarded – undo
3546 3556
 		$fieldSettings = $this->field_settings(true);
3547 3557
 		if( isset($fieldSettings[$fieldName])){
3548 3558
 			return true;
3549
-		}else{
3559
+		} else{
3550 3560
 			return false;
3551 3561
 		}
3552 3562
 	}
@@ -3560,7 +3570,7 @@  discard block
 block discarded – undo
3560 3570
 		$relations = $this->relation_settings();
3561 3571
 		if(isset($relations[$relation_name])){
3562 3572
 			return true;
3563
-		}else{
3573
+		} else{
3564 3574
 			return false;
3565 3575
 		}
3566 3576
 	}
@@ -3611,7 +3621,7 @@  discard block
 block discarded – undo
3611 3621
 			try{
3612 3622
 				$this->get_primary_key_field();
3613 3623
 				$this->_has_primary_key_field = true;
3614
-			}catch(EE_Error $e){
3624
+			} catch(EE_Error $e){
3615 3625
 				$this->_has_primary_key_field = false;
3616 3626
 			}
3617 3627
 		}
@@ -3690,7 +3700,7 @@  discard block
 block discarded – undo
3690 3700
 				}
3691 3701
 			}
3692 3702
 			return $this->_cached_fields;
3693
-		}else{
3703
+		} else{
3694 3704
 			if( $this->_cached_fields_non_db_only === NULL ){
3695 3705
 				$this->_cached_fields_non_db_only = array();
3696 3706
 				foreach($this->_fields as $fields_corresponding_to_table){
@@ -3833,7 +3843,7 @@  discard block
 block discarded – undo
3833 3843
 			if(empty( $this_model_fields_n_values[$this->primary_key_name()] )){
3834 3844
 				return NULL;
3835 3845
 			}
3836
-		}else if($this->unique_indexes()){
3846
+		} else if($this->unique_indexes()){
3837 3847
 			$first_column = reset($this_model_fields_n_values);
3838 3848
 			if(empty($first_column)){
3839 3849
 				return NULL;
@@ -3848,7 +3858,7 @@  discard block
 block discarded – undo
3848 3858
 				// add this new object to the entity map
3849 3859
 				$classInstance = $this->add_to_entity_map( $classInstance );
3850 3860
 			}
3851
-		}else{
3861
+		} else{
3852 3862
 			$classInstance = EE_Registry::instance()->load_class( $className, array( $this_model_fields_n_values, $this->_timezone ), TRUE, FALSE );
3853 3863
 		}
3854 3864
 
@@ -3935,11 +3945,12 @@  discard block
 block discarded – undo
3935 3945
 						$this_model_fields_n_values[$field_name] = $field_obj->prepare_for_use_in_db( $prepared_value );
3936 3946
 					}
3937 3947
 				}
3938
-			}else{
3948
+			} else{
3939 3949
 				//the table's rows existed. Use their values
3940 3950
 				foreach( $this->_get_fields_for_table( $table_alias ) as $field_name => $field_obj ) {
3941
-					if( ! $field_obj->is_db_only_field() )
3942
-					$this_model_fields_n_values[$field_name] = $this->_get_column_value_with_table_alias_or_not($cols_n_values, $field_obj->get_qualified_column(), $field_obj->get_table_column() );
3951
+					if( ! $field_obj->is_db_only_field() ) {
3952
+										$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() );
3953
+					}
3943 3954
 				}
3944 3955
 			}
3945 3956
 		}
@@ -3953,9 +3964,9 @@  discard block
 block discarded – undo
3953 3964
 		if( isset( $cols_n_values[ $qualified_column ] ) ){
3954 3965
 			$value = $cols_n_values[ $qualified_column ];
3955 3966
 
3956
-		}elseif( isset( $cols_n_values[ $regular_column ] ) ){
3967
+		} elseif( isset( $cols_n_values[ $regular_column ] ) ){
3957 3968
 			$value = $cols_n_values[ $regular_column ];
3958
-		}else{
3969
+		} else{
3959 3970
 			$value = NULL;
3960 3971
 		}
3961 3972
 
@@ -3989,7 +4000,7 @@  discard block
 block discarded – undo
3989 4000
 			}
3990 4001
 			$this->_entity_map[ $id ] = $obj_in_map;
3991 4002
 			return $obj_in_map;
3992
-		}else{
4003
+		} else{
3993 4004
 			return $this->get_one_by_ID( $id );
3994 4005
 		}
3995 4006
 	}
@@ -4024,7 +4035,7 @@  discard block
 block discarded – undo
4024 4035
 				}
4025 4036
 			}
4026 4037
 			return $obj_in_map;
4027
-		}else{
4038
+		} else{
4028 4039
 			$this->add_to_entity_map( $replacing_model_obj );
4029 4040
 			return $replacing_model_obj;
4030 4041
 		}
@@ -4054,7 +4065,7 @@  discard block
 block discarded – undo
4054 4065
 	public function item_name($quantity = 1){
4055 4066
 		if($quantity == 1){
4056 4067
 			return $this->singular_item;
4057
-		}else{
4068
+		} else{
4058 4069
 			return $this->plural_item;
4059 4070
 		}
4060 4071
 	}
@@ -4116,14 +4127,14 @@  discard block
 block discarded – undo
4116 4127
 		$primary_key_field = $this->get_primary_key_field();
4117 4128
 		if( $base_class_obj_or_id instanceof $className ){
4118 4129
 			$model_object = $base_class_obj_or_id;
4119
-		}elseif( $primary_key_field instanceof EE_Primary_Key_Int_Field && (
4130
+		} elseif( $primary_key_field instanceof EE_Primary_Key_Int_Field && (
4120 4131
 				is_int( $base_class_obj_or_id ) ||
4121 4132
 				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)
4122 4133
 			$model_object = $this->get_one_by_ID($base_class_obj_or_id);
4123
-		}elseif( $primary_key_field instanceof EE_Primary_Key_String_Field && is_string($base_class_obj_or_id) ){
4134
+		} elseif( $primary_key_field instanceof EE_Primary_Key_String_Field && is_string($base_class_obj_or_id) ){
4124 4135
 			//assume its a string representation of the object
4125 4136
 			$model_object = $this->get_one_by_ID($base_class_obj_or_id);
4126
-		}else{
4137
+		} else{
4127 4138
 			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)));
4128 4139
 		}
4129 4140
 		if( $model_object->ID() == NULL && $ensure_is_in_db){
@@ -4147,13 +4158,13 @@  discard block
 block discarded – undo
4147 4158
 		if( $base_class_obj_or_id instanceof $className ){
4148 4159
 			/** @var $base_class_obj_or_id EE_Base_Class */
4149 4160
 			$id = $base_class_obj_or_id->ID();
4150
-		}elseif(is_int($base_class_obj_or_id)){
4161
+		} elseif(is_int($base_class_obj_or_id)){
4151 4162
 			//assume it's an ID
4152 4163
 			$id = $base_class_obj_or_id;
4153
-		}elseif(is_string($base_class_obj_or_id)){
4164
+		} elseif(is_string($base_class_obj_or_id)){
4154 4165
 			//assume its a string representation of the object
4155 4166
 			$id = $base_class_obj_or_id;
4156
-		}else{
4167
+		} else{
4157 4168
 			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)));
4158 4169
 		}
4159 4170
 		return $id;
@@ -4284,9 +4295,9 @@  discard block
 block discarded – undo
4284 4295
 
4285 4296
 		if($model_object_or_attributes_array instanceof EE_Base_Class){
4286 4297
 			$attributes_array = $model_object_or_attributes_array->model_field_array();
4287
-		}elseif(is_array($model_object_or_attributes_array)){
4298
+		} elseif(is_array($model_object_or_attributes_array)){
4288 4299
 			$attributes_array = $model_object_or_attributes_array;
4289
-		}else{
4300
+		} else{
4290 4301
 			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));
4291 4302
 		}
4292 4303
 		//even copies obviously won't have the same ID, so remove the primary key
@@ -4296,7 +4307,7 @@  discard block
 block discarded – undo
4296 4307
 		}
4297 4308
 		if(isset($query_params[0])){
4298 4309
 			$query_params[0] = array_merge($attributes_array,$query_params);
4299
-		}else{
4310
+		} else{
4300 4311
 			$query_params[0] = $attributes_array;
4301 4312
 		}
4302 4313
 		return $this->get_all($query_params);
@@ -4319,7 +4330,7 @@  discard block
 block discarded – undo
4319 4330
 		$copies = $this->get_all_copies($model_object_or_attributes_array,$query_params);
4320 4331
 		if(is_array($copies)){
4321 4332
 			return array_shift($copies);
4322
-		}else{
4333
+		} else{
4323 4334
 			return null;
4324 4335
 		}
4325 4336
 	}
@@ -4351,7 +4362,7 @@  discard block
 block discarded – undo
4351 4362
 		$sql_operator = isset($this->_valid_operators[$operator_supplied]) ? $this->_valid_operators[$operator_supplied] : null;
4352 4363
 		if($sql_operator){
4353 4364
 			return $sql_operator;
4354
-		}else{
4365
+		} else{
4355 4366
 			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))));
4356 4367
 		}
4357 4368
 	}
@@ -4522,7 +4533,7 @@  discard block
 block discarded – undo
4522 4533
 		$valid_cap_contexts = EEM_Base::valid_cap_contexts();
4523 4534
 		if( in_array( $context, $valid_cap_contexts ) ) {
4524 4535
 			return true;
4525
-		}else{
4536
+		} else{
4526 4537
 			throw new EE_Error(
4527 4538
 				sprintf(
4528 4539
 					__( '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.
Spacing   +959 added lines, -959 removed lines patch added patch discarded remove patch
@@ -23,7 +23,7 @@  discard block
 block discarded – undo
23 23
  * @since 				EE4
24 24
  *
25 25
  */
26
-abstract class EEM_Base extends EE_Base{
26
+abstract class EEM_Base extends EE_Base {
27 27
 
28 28
 	//admin posty
29 29
 	//basic -> grants access to mine -> if they don't have it, select none
@@ -235,7 +235,7 @@  discard block
 block discarded – undo
235 235
 	 * Flag indicating whether this model has a primary key or not
236 236
 	 * @var boolean
237 237
 	 */
238
-	protected $_has_primary_key_field=null;
238
+	protected $_has_primary_key_field = null;
239 239
 
240 240
 	/**
241 241
 	 * Whether or not this model is based off a table in WP core only (CPTs should set
@@ -297,19 +297,19 @@  discard block
 block discarded – undo
297 297
 	 * operators that work like 'BETWEEN'.  Typically used for datetime calculations, i.e. "BETWEEN '12-1-2011' AND '12-31-2012'"
298 298
 	 * @var array
299 299
 	 */
300
-	protected $_between_style_operators = array( 'BETWEEN' );
300
+	protected $_between_style_operators = array('BETWEEN');
301 301
 
302 302
 	/**
303 303
 	 * operators that are used for handling NUll and !NULL queries.  Typically used for when checking if a row exists on a join table.
304 304
 	 * @var array
305 305
 	 */
306
-	protected $_null_style_operators = array( 'IS NOT NULL', 'IS NULL');
306
+	protected $_null_style_operators = array('IS NOT NULL', 'IS NULL');
307 307
 
308 308
 	/**
309 309
 	 * Allowed values for $query_params['order'] for ordering in queries
310 310
 	 * @var array
311 311
 	 */
312
-	protected $_allowed_order_values = array('asc','desc','ASC','DESC');
312
+	protected $_allowed_order_values = array('asc', 'desc', 'ASC', 'DESC');
313 313
 
314 314
 	/**
315 315
 	 * When these are keys in a WHERE or HAVING clause, they are handled much differently
@@ -323,13 +323,13 @@  discard block
 block discarded – undo
323 323
 	 * 'where', but 'where' clauses are so common that we thought we'd omit it
324 324
 	 * @var array
325 325
 	 */
326
-	private $_allowed_query_params = array(0, 'limit','order_by','group_by','having','force_join','order','on_join_limit','default_where_conditions', 'caps');
326
+	private $_allowed_query_params = array(0, 'limit', 'order_by', 'group_by', 'having', 'force_join', 'order', 'on_join_limit', 'default_where_conditions', 'caps');
327 327
 
328 328
 	/**
329 329
 	 * All the data types that can be used in $wpdb->prepare statements.
330 330
 	 * @var array
331 331
 	 */
332
-	private $_valid_wpdb_data_types = array('%d','%s','%f');
332
+	private $_valid_wpdb_data_types = array('%d', '%s', '%f');
333 333
 
334 334
 	/**
335 335
 	 * 	EE_Registry Object
@@ -362,17 +362,17 @@  discard block
 block discarded – undo
362 362
 	/**
363 363
 	 * constant used to show EEM_Base has not yet verified the db on this http request
364 364
 	 */
365
-	const db_verified_none 		= 0;
365
+	const db_verified_none = 0;
366 366
 	/**
367 367
 	 * constant used to show EEM_Base has verified the EE core db on this http request,
368 368
 	 * but not the addons' dbs
369 369
 	 */
370
-	const db_verified_core 		= 1;
370
+	const db_verified_core = 1;
371 371
 	/**
372 372
 	 * constant used to show EEM_Base has verified the addons' dbs (and implicitly
373 373
 	 * the EE core db too)
374 374
 	 */
375
-	const db_verified_addons 	= 2;
375
+	const db_verified_addons = 2;
376 376
 
377 377
 	/**
378 378
 	 * indicates whether an EEM_Base child has already re-verified the DB
@@ -403,13 +403,13 @@  discard block
 block discarded – undo
403 403
 	 * @param null $timezone
404 404
 	 * @throws \EE_Error
405 405
 	 */
406
-	protected function __construct( $timezone = NULL ){
406
+	protected function __construct($timezone = NULL) {
407 407
 		// check that the model has not been loaded too soon
408
-		if ( ! did_action( 'AHEE__EE_System__load_espresso_addons' )) {
409
-			throw new EE_Error (
408
+		if ( ! did_action('AHEE__EE_System__load_espresso_addons')) {
409
+			throw new EE_Error(
410 410
 				sprintf(
411
-					__( 'The %1$s model can not be loaded before the "AHEE__EE_System__load_espresso_addons" hook has been called. This gives other addons a chance to extend this model.', 'event_espresso' ),
412
-					get_class( $this )
411
+					__('The %1$s model can not be loaded before the "AHEE__EE_System__load_espresso_addons" hook has been called. This gives other addons a chance to extend this model.', 'event_espresso'),
412
+					get_class($this)
413 413
 				)
414 414
 			);
415 415
 		}
@@ -419,11 +419,11 @@  discard block
 block discarded – undo
419 419
 		 * just use EE_Register_Model_Extension
420 420
 		 * @var EE_Table_Base[] $_tables
421 421
 		 */
422
-		$this->_tables = apply_filters( 'FHEE__'.get_class($this).'__construct__tables', $this->_tables );
423
-		foreach($this->_tables as $table_alias => $table_obj){
422
+		$this->_tables = apply_filters('FHEE__'.get_class($this).'__construct__tables', $this->_tables);
423
+		foreach ($this->_tables as $table_alias => $table_obj) {
424 424
 			/** @var $table_obj EE_Table_Base */
425 425
 			$table_obj->_construct_finalize_with_alias($table_alias);
426
-			if( $table_obj instanceof EE_Secondary_Table ){
426
+			if ($table_obj instanceof EE_Secondary_Table) {
427 427
 				/** @var $table_obj EE_Secondary_Table */
428 428
 				$table_obj->_construct_finalize_set_table_to_join_with($this->_get_main_table());
429 429
 			}
@@ -433,54 +433,54 @@  discard block
 block discarded – undo
433 433
 		 * EE_Register_Model_Extension
434 434
 		 * @param EE_Model_Field_Base[] $_fields
435 435
 		 */
436
-		$this->_fields = apply_filters('FHEE__'.get_class($this).'__construct__fields',$this->_fields);
436
+		$this->_fields = apply_filters('FHEE__'.get_class($this).'__construct__fields', $this->_fields);
437 437
 		$this->_invalidate_field_caches();
438
-		foreach($this->_fields as $table_alias => $fields_for_table){
439
-			if ( ! array_key_exists( $table_alias, $this->_tables )){
440
-				throw new EE_Error(sprintf(__("Table alias %s does not exist in EEM_Base child's _tables array. Only tables defined are %s",'event_espresso'),$table_alias,implode(",",$this->_fields)));
438
+		foreach ($this->_fields as $table_alias => $fields_for_table) {
439
+			if ( ! array_key_exists($table_alias, $this->_tables)) {
440
+				throw new EE_Error(sprintf(__("Table alias %s does not exist in EEM_Base child's _tables array. Only tables defined are %s", 'event_espresso'), $table_alias, implode(",", $this->_fields)));
441 441
 			}
442
-			foreach($fields_for_table as $field_name => $field_obj){
442
+			foreach ($fields_for_table as $field_name => $field_obj) {
443 443
 				/** @var $field_obj EE_Model_Field_Base | EE_Primary_Key_Field_Base */
444 444
 				//primary key field base has a slightly different _construct_finalize
445 445
 				/** @var $field_obj EE_Model_Field_Base */
446
-				$field_obj->_construct_finalize( $table_alias, $field_name, $this->get_this_model_name() );
446
+				$field_obj->_construct_finalize($table_alias, $field_name, $this->get_this_model_name());
447 447
 			}
448 448
 		}
449 449
 
450 450
 		// everything is related to Extra_Meta
451
-		if( get_class($this) != 'EEM_Extra_Meta'){
451
+		if (get_class($this) != 'EEM_Extra_Meta') {
452 452
 			//make extra meta related to everything, but don't block deleting things just
453 453
 			//because they have related extra meta info. For now just orphan those extra meta
454 454
 			//in the future we should automatically delete them
455
-			$this->_model_relations['Extra_Meta'] = new EE_Has_Many_Any_Relation( FALSE );
455
+			$this->_model_relations['Extra_Meta'] = new EE_Has_Many_Any_Relation(FALSE);
456 456
 		}
457 457
 		//and change logs
458
-		if( get_class( $this) !=  'EEM_Change_Log' ) {
459
-			$this->_model_relations[ 'Change_Log' ] = new EE_Has_Many_Any_Relation( FALSE );
458
+		if (get_class($this) != 'EEM_Change_Log') {
459
+			$this->_model_relations['Change_Log'] = new EE_Has_Many_Any_Relation(FALSE);
460 460
 		}
461 461
 		/**
462 462
 		 * Filters the list of relations on a model. It is best to NOT use this directly and instead just use
463 463
 		 * EE_Register_Model_Extension
464 464
 		 * @param EE_Model_Relation_Base[] $_model_relations
465 465
 		 */
466
-		$this->_model_relations = apply_filters('FHEE__'.get_class($this).'__construct__model_relations',$this->_model_relations);
467
-		foreach($this->_model_relations as $model_name => $relation_obj){
466
+		$this->_model_relations = apply_filters('FHEE__'.get_class($this).'__construct__model_relations', $this->_model_relations);
467
+		foreach ($this->_model_relations as $model_name => $relation_obj) {
468 468
 			/** @var $relation_obj EE_Model_Relation_Base */
469 469
 			$relation_obj->_construct_finalize_set_models($this->get_this_model_name(), $model_name);
470 470
 		}
471
-		foreach($this->_indexes as $index_name => $index_obj){
471
+		foreach ($this->_indexes as $index_name => $index_obj) {
472 472
 			/** @var $index_obj EE_Index */
473 473
 			$index_obj->_construct_finalize($index_name, $this->get_this_model_name());
474 474
 		}
475 475
 
476 476
 		$this->set_timezone($timezone);
477 477
 		//finalize default where condition strategy, or set default
478
-		if( ! $this->_default_where_conditions_strategy){
478
+		if ( ! $this->_default_where_conditions_strategy) {
479 479
 			//nothing was set during child constructor, so set default
480 480
 			$this->_default_where_conditions_strategy = new EE_Default_Where_Conditions();
481 481
 		}
482 482
 		$this->_default_where_conditions_strategy->_finalize_construct($this);
483
-		if( ! $this->_minimum_where_conditions_strategy){
483
+		if ( ! $this->_minimum_where_conditions_strategy) {
484 484
 			//nothing was set during child constructor, so set default
485 485
 			$this->_minimum_where_conditions_strategy = new EE_Default_Where_Conditions();
486 486
 		}
@@ -488,15 +488,15 @@  discard block
 block discarded – undo
488 488
 
489 489
 		//if the cap slug hasn't been set, and we haven't set it to false on purpose
490 490
 		//to indicate to NOT set it, set it to the logical default
491
-		if( $this->_caps_slug === null ) {
492
-			EE_Registry::instance()->load_helper( 'Inflector' );
493
-			$this->_caps_slug = EEH_Inflector::pluralize_and_lower( $this->get_this_model_name() );
491
+		if ($this->_caps_slug === null) {
492
+			EE_Registry::instance()->load_helper('Inflector');
493
+			$this->_caps_slug = EEH_Inflector::pluralize_and_lower($this->get_this_model_name());
494 494
 		}
495 495
 		//initialize the standard cap restriction generators if none were specified by the child constructor
496
-		if( $this->_cap_restriction_generators !== false ){
497
-			foreach( $this->cap_contexts_to_cap_action_map() as $cap_context => $action ){
498
-				if( ! isset( $this->_cap_restriction_generators[ $cap_context ] ) ) {
499
-					$this->_cap_restriction_generators[ $cap_context ] = apply_filters(
496
+		if ($this->_cap_restriction_generators !== false) {
497
+			foreach ($this->cap_contexts_to_cap_action_map() as $cap_context => $action) {
498
+				if ( ! isset($this->_cap_restriction_generators[$cap_context])) {
499
+					$this->_cap_restriction_generators[$cap_context] = apply_filters(
500 500
 						'FHEE__EEM_Base___construct__standard_cap_restriction_generator',
501 501
 						new EE_Restriction_Generator_Protected(),
502 502
 						$cap_context,
@@ -506,23 +506,23 @@  discard block
 block discarded – undo
506 506
 			}
507 507
 		}
508 508
 		//if there are cap restriction generators, use them to make the default cap restrictions
509
-		if( $this->_cap_restriction_generators !== false ){
510
-			foreach( $this->_cap_restriction_generators as $context => $generator_object ) {
511
-				if( ! $generator_object ){
509
+		if ($this->_cap_restriction_generators !== false) {
510
+			foreach ($this->_cap_restriction_generators as $context => $generator_object) {
511
+				if ( ! $generator_object) {
512 512
 					continue;
513 513
 				}
514
-				if( ! $generator_object instanceof EE_Restriction_Generator_Base ){
514
+				if ( ! $generator_object instanceof EE_Restriction_Generator_Base) {
515 515
 					throw new EE_Error(
516 516
 						sprintf(
517
-							__( 'Index "%1$s" in the model %2$s\'s _cap_restriction_generators is not a child of EE_Restriction_Generator_Base. It should be that or NULL.', 'event_espresso' ),
517
+							__('Index "%1$s" in the model %2$s\'s _cap_restriction_generators is not a child of EE_Restriction_Generator_Base. It should be that or NULL.', 'event_espresso'),
518 518
 							$context,
519 519
 							$this->get_this_model_name()
520 520
 						)
521 521
 					);
522 522
 				}
523
-				$action = $this->cap_action_for_context( $context );
524
-				if( ! $generator_object->construction_finalized() ){
525
-					$generator_object->_construct_finalize( $this, $action );
523
+				$action = $this->cap_action_for_context($context);
524
+				if ( ! $generator_object->construction_finalized()) {
525
+					$generator_object->_construct_finalize($this, $action);
526 526
 				}
527 527
 
528 528
 			}
@@ -536,11 +536,11 @@  discard block
 block discarded – undo
536 536
 	 * @param string $context one of EEM_Base::valid_cap_contexts()
537 537
 	 * @return EE_Default_Where_Conditions[]
538 538
 	 */
539
-	protected function _generate_cap_restrictions( $context ){
540
-		if( isset( $this->_cap_restriction_generators[ $context ] ) &&
541
-				$this->_cap_restriction_generators[ $context ] instanceof EE_Restriction_Generator_Base ) {
542
-			return $this->_cap_restriction_generators[ $context ]->generate_restrictions();
543
-		}else{
539
+	protected function _generate_cap_restrictions($context) {
540
+		if (isset($this->_cap_restriction_generators[$context]) &&
541
+				$this->_cap_restriction_generators[$context] instanceof EE_Restriction_Generator_Base) {
542
+			return $this->_cap_restriction_generators[$context]->generate_restrictions();
543
+		} else {
544 544
 			return array();
545 545
 		}
546 546
 }
@@ -553,16 +553,16 @@  discard block
 block discarded – undo
553 553
 	 *		@param string $timezone string representing the timezone we want to set for returned Date Time Strings (and any incoming timezone data that gets saved).  Note this just sends the timezone info to the date time model field objects.  Default is NULL (and will be assumed using the set timezone in the 'timezone_string' wp option)
554 554
 	 *		@return static (as in the concrete child class)
555 555
 	 */
556
-	public static function instance( $timezone = NULL ){
556
+	public static function instance($timezone = NULL) {
557 557
 
558 558
 		// check if instance of Espresso_model already exists
559 559
 		if ( ! static::$_instance instanceof static) {
560 560
 			// instantiate Espresso_model
561
-			static::$_instance = new static( $timezone );
561
+			static::$_instance = new static($timezone);
562 562
 		}
563 563
 
564 564
 		//we might have a timezone set, let set_timezone decide what to do with it
565
-		static::$_instance->set_timezone( $timezone );
565
+		static::$_instance->set_timezone($timezone);
566 566
 
567 567
 		// Espresso_model object
568 568
 		return static::$_instance;
@@ -575,11 +575,11 @@  discard block
 block discarded – undo
575 575
 	 * @param null | string $timezone
576 576
 	 * @return static
577 577
 	 */
578
-	public static function reset(  $timezone = NULL ){
579
-		if ( ! is_null( static::$_instance ) ) {
578
+	public static function reset($timezone = NULL) {
579
+		if ( ! is_null(static::$_instance)) {
580 580
 			static::$_instance = null;
581 581
 
582
-			return self::instance( $timezone );
582
+			return self::instance($timezone);
583 583
 		}
584 584
 		return null;
585 585
 	}
@@ -590,15 +590,15 @@  discard block
 block discarded – undo
590 590
 	 * @param  boolean $translated return localized strings or JUST the array.
591 591
 	 * @return array
592 592
 	 */
593
-	 public function status_array( $translated = FALSE ) {
594
-	 	if ( !array_key_exists('Status', $this->_model_relations ) )
593
+	 public function status_array($translated = FALSE) {
594
+	 	if ( ! array_key_exists('Status', $this->_model_relations))
595 595
 	 		return array();
596 596
 	 	$model_name = $this->get_this_model_name();
597
-	 	$status_type = str_replace(' ', '_', strtolower( str_replace('_', ' ', $model_name) ) );
598
-	 	$stati = EEM_Status::instance()->get_all(array(array('STS_type' => $status_type) ) );
597
+	 	$status_type = str_replace(' ', '_', strtolower(str_replace('_', ' ', $model_name)));
598
+	 	$stati = EEM_Status::instance()->get_all(array(array('STS_type' => $status_type)));
599 599
 	 	$status_array = array();
600
-	 	foreach ( $stati as $status ) {
601
-            $status_array[ $status->ID() ] = $status->get('STS_code');
600
+	 	foreach ($stati as $status) {
601
+            $status_array[$status->ID()] = $status->get('STS_code');
602 602
         }
603 603
         return $translated ? EEM_Status::instance()->localized_status($status_array, FALSE, 'sentence') : $status_array;
604 604
     }
@@ -740,10 +740,10 @@  discard block
 block discarded – undo
740 740
 	 *			'order_by'=>array('ANS_value'=>'ASC')
741 741
 	 *		));
742 742
 	 */
743
-	function get_all($query_params = array()){
744
-		if( isset( $query_params[ 'limit' ] )
745
-			&& ! isset( $query_params[ 'group_by' ] ) ) {
746
-			$query_params[ 'group_by' ] = array_keys( $this->get_combined_primary_key_fields() );
743
+	function get_all($query_params = array()) {
744
+		if (isset($query_params['limit'])
745
+			&& ! isset($query_params['group_by'])) {
746
+			$query_params['group_by'] = array_keys($this->get_combined_primary_key_fields());
747 747
 		}
748 748
 		return $this->_create_objects($this->_get_all_wpdb_results($query_params, ARRAY_A, NULL));
749 749
 	}
@@ -754,10 +754,10 @@  discard block
 block discarded – undo
754 754
 	 * @param array $query_params @see EEM_Base::get_all()
755 755
 	 * @return array like EEM_Base::get_all
756 756
 	 */
757
-	function alter_query_params_to_only_include_mine( $query_params = array() ) {
757
+	function alter_query_params_to_only_include_mine($query_params = array()) {
758 758
 		$wp_user_field_name = $this->wp_user_field_name();
759
-		if( $wp_user_field_name ){
760
-			$query_params[0][ $wp_user_field_name ] = get_current_user_id();
759
+		if ($wp_user_field_name) {
760
+			$query_params[0][$wp_user_field_name] = get_current_user_id();
761 761
 		}
762 762
 		return $query_params;
763 763
 	}
@@ -770,19 +770,19 @@  discard block
 block discarded – undo
770 770
 	 * foreign key to the WP_User table
771 771
 	 */
772 772
 	function wp_user_field_name() {
773
-		try{
774
-			if( ! empty( $this->_model_chain_to_wp_user ) ) {
775
-				$models_to_follow_to_wp_users = explode( '.', $this->_model_chain_to_wp_user );
776
-				$last_model_name = end( $models_to_follow_to_wp_users );
777
-				$model_with_fk_to_wp_users = EE_Registry::instance()->load_model( $last_model_name );
778
-				$model_chain_to_wp_user = $this->_model_chain_to_wp_user . '.';
779
-			}else{
773
+		try {
774
+			if ( ! empty($this->_model_chain_to_wp_user)) {
775
+				$models_to_follow_to_wp_users = explode('.', $this->_model_chain_to_wp_user);
776
+				$last_model_name = end($models_to_follow_to_wp_users);
777
+				$model_with_fk_to_wp_users = EE_Registry::instance()->load_model($last_model_name);
778
+				$model_chain_to_wp_user = $this->_model_chain_to_wp_user.'.';
779
+			} else {
780 780
 				$model_with_fk_to_wp_users = $this;
781 781
 				$model_chain_to_wp_user = '';
782 782
 			}
783
-			$wp_user_field = $model_with_fk_to_wp_users->get_foreign_key_to( 'WP_User' );
784
-			return $model_chain_to_wp_user . $wp_user_field->get_name();
785
-		}catch( EE_Error $e ) {
783
+			$wp_user_field = $model_with_fk_to_wp_users->get_foreign_key_to('WP_User');
784
+			return $model_chain_to_wp_user.$wp_user_field->get_name();
785
+		} catch (EE_Error $e) {
786 786
 			return false;
787 787
 		}
788 788
 	}
@@ -796,7 +796,7 @@  discard block
 block discarded – undo
796 796
 	 * (or transiently-related model)
797 797
 	 * @return string
798 798
 	 */
799
-	public function model_chain_to_wp_user(){
799
+	public function model_chain_to_wp_user() {
800 800
 		return $this->_model_chain_to_wp_user;
801 801
 	}
802 802
 
@@ -808,13 +808,13 @@  discard block
 block discarded – undo
808 808
 	 * @return boolean
809 809
 	 */
810 810
 	public function is_owned() {
811
-		if( $this->model_chain_to_wp_user() ){
811
+		if ($this->model_chain_to_wp_user()) {
812 812
 			return true;
813
-		}else{
814
-			try{
815
-				$this->get_foreign_key_to( 'WP_User' );
813
+		} else {
814
+			try {
815
+				$this->get_foreign_key_to('WP_User');
816 816
 				return true;
817
-			}catch( EE_Error $e ){
817
+			} catch (EE_Error $e) {
818 818
 				return false;
819 819
 			}
820 820
 		}
@@ -833,21 +833,21 @@  discard block
 block discarded – undo
833 833
 	 * and 1 is the data type. Eg, array('count'=>array('COUNT(REG_ID)','%d'))
834 834
 	 * @return array | stdClass[] like results of $wpdb->get_results($sql,OBJECT), (ie, output type is OBJECT)
835 835
 	 */
836
-	protected function  _get_all_wpdb_results($query_params = array(), $output = ARRAY_A, $columns_to_select = null){
836
+	protected function  _get_all_wpdb_results($query_params = array(), $output = ARRAY_A, $columns_to_select = null) {
837 837
 		//remember the custom selections, if any
838
-		if(is_array($columns_to_select)){
838
+		if (is_array($columns_to_select)) {
839 839
 			$this->_custom_selections = $columns_to_select;
840
-		}elseif(is_string($columns_to_select)){
840
+		}elseif (is_string($columns_to_select)) {
841 841
 			$this->_custom_selections = array($this->_custom_selections);
842
-		}else{
842
+		} else {
843 843
 			$this->_custom_selections = array();
844 844
 		}
845 845
 
846 846
 		$model_query_info = $this->_create_model_query_info_carrier($query_params);
847 847
 		$select_expressions = $columns_to_select ? $this->_construct_select_from_input($columns_to_select) : $this->_construct_default_select_sql($model_query_info);
848
-		$SQL ="SELECT $select_expressions ".$this->_construct_2nd_half_of_select_query($model_query_info);
848
+		$SQL = "SELECT $select_expressions ".$this->_construct_2nd_half_of_select_query($model_query_info);
849 849
 //		echo "sql:$SQL";
850
-		$results =  $this->_do_wpdb_query( 'get_results', array($SQL, $output ) );// $wpdb->get_results($SQL, $output);
850
+		$results = $this->_do_wpdb_query('get_results', array($SQL, $output)); // $wpdb->get_results($SQL, $output);
851 851
 		return $results;
852 852
 	}
853 853
 
@@ -865,7 +865,7 @@  discard block
 block discarded – undo
865 865
 	 * and 1 is the data type. Eg, array('count'=>array('COUNT(REG_ID)','%d'))
866 866
 	 * @return array|stdClass[] like results of $wpdb->get_results($sql,OBJECT), (ie, output type is OBJECT)
867 867
 	 */
868
-	public function  get_all_wpdb_results($query_params = array(), $output = ARRAY_A, $columns_to_select = null){
868
+	public function  get_all_wpdb_results($query_params = array(), $output = ARRAY_A, $columns_to_select = null) {
869 869
 		return $this->_get_all_wpdb_results($query_params, $output, $columns_to_select);
870 870
 	}
871 871
 
@@ -877,12 +877,12 @@  discard block
 block discarded – undo
877 877
 	 * @throws EE_Error
878 878
 	 * @return string
879 879
 	 */
880
-	private function _construct_select_from_input($columns_to_select){
881
-		if(is_array($columns_to_select)){
880
+	private function _construct_select_from_input($columns_to_select) {
881
+		if (is_array($columns_to_select)) {
882 882
 			$select_sql_array = array();
883 883
 
884
-			foreach($columns_to_select as $alias => $selection_and_datatype){
885
-				if( ! is_array($selection_and_datatype) || ! isset($selection_and_datatype[1])){
884
+			foreach ($columns_to_select as $alias => $selection_and_datatype) {
885
+				if ( ! is_array($selection_and_datatype) || ! isset($selection_and_datatype[1])) {
886 886
 					throw new EE_Error(
887 887
 						sprintf(
888 888
 							__(
@@ -894,24 +894,24 @@  discard block
 block discarded – undo
894 894
 						)
895 895
 					);
896 896
 				}
897
-				if( ! in_array( $selection_and_datatype[1],$this->_valid_wpdb_data_types)){
897
+				if ( ! in_array($selection_and_datatype[1], $this->_valid_wpdb_data_types)) {
898 898
 					throw new EE_Error(
899 899
 						sprintf(
900 900
 							__(
901 901
 								"Datatype %s (for selection '%s' and alias '%s') is not a valid wpdb datatype (eg %%s)",
902 902
 								"event_espresso"
903 903
 							),
904
-							$selection_and_datatype[ 1 ],
905
-							$selection_and_datatype[ 0 ],
904
+							$selection_and_datatype[1],
905
+							$selection_and_datatype[0],
906 906
 							$alias,
907
-							implode( ",", $this->_valid_wpdb_data_types )
907
+							implode(",", $this->_valid_wpdb_data_types)
908 908
 						)
909 909
 					);
910 910
 				}
911 911
 				$select_sql_array[] = "{$selection_and_datatype[0]} AS $alias";
912 912
 			}
913
-			$columns_to_select_string = implode(", ",$select_sql_array);
914
-		}else{
913
+			$columns_to_select_string = implode(", ", $select_sql_array);
914
+		} else {
915 915
 			$columns_to_select_string = $columns_to_select;
916 916
 		}
917 917
 		return $columns_to_select_string;
@@ -924,7 +924,7 @@  discard block
 block discarded – undo
924 924
 	 * Convenient wrapper for getting the primary key field's name. Eg, on Registration, this would be 'REG_ID'
925 925
 	 * @return string
926 926
 	 */
927
-	function primary_key_name(){
927
+	function primary_key_name() {
928 928
 		return $this->get_primary_key_field()->get_name();
929 929
 	}
930 930
 
@@ -936,14 +936,14 @@  discard block
 block discarded – undo
936 936
 	 * @param mixed $id int or string, depending on the type of the model's primary key
937 937
 	 * @return EE_Base_Class
938 938
 	 */
939
-	function get_one_by_ID($id){
940
-		if( $this->get_from_entity_map( $id ) ){
941
-			return $this->get_from_entity_map( $id );
939
+	function get_one_by_ID($id) {
940
+		if ($this->get_from_entity_map($id)) {
941
+			return $this->get_from_entity_map($id);
942 942
 		}
943 943
 		return $this->get_one(
944 944
 			$this->alter_query_params_to_restrict_by_ID(
945 945
 				$id,
946
-				array( 'default_where_conditions' => 'minimum' )
946
+				array('default_where_conditions' => 'minimum')
947 947
 			)
948 948
 		);
949 949
 	}
@@ -955,15 +955,15 @@  discard block
 block discarded – undo
955 955
 	 * @param array $query_params
956 956
 	 * @return array of normal query params, @see EEM_Base::get_all
957 957
 	 */
958
-	public function alter_query_params_to_restrict_by_ID( $id, $query_params = array() ) {
959
-		if( ! isset( $query_params[ 0 ] ) ) {
960
-			$query_params[ 0 ] = array();
958
+	public function alter_query_params_to_restrict_by_ID($id, $query_params = array()) {
959
+		if ( ! isset($query_params[0])) {
960
+			$query_params[0] = array();
961 961
 		}
962
-		if( $this->has_primary_key_field ( ) ) {
963
-			$query_params[ 0 ][ $this->primary_key_name() ] = $id ;
964
-		}else{
962
+		if ($this->has_primary_key_field( )) {
963
+			$query_params[0][$this->primary_key_name()] = $id;
964
+		} else {
965 965
 			//no primary key, so the $id must be from the get_index_primary_key_string()
966
-			$query_params[0] = array_replace_recursive( $query_params[ 0 ], $this->parse_index_primary_key_string( $id ) );
966
+			$query_params[0] = array_replace_recursive($query_params[0], $this->parse_index_primary_key_string($id));
967 967
 		}
968 968
 		return $query_params;
969 969
 	}
@@ -975,16 +975,16 @@  discard block
 block discarded – undo
975 975
 	 * @param array $query_params like EEM_Base's $query_params variable.
976 976
 	 * @return EE_Base_Class | NULL
977 977
 	 */
978
-	function get_one($query_params = array()){
979
-		if( ! is_array( $query_params ) ){
980
-			EE_Error::doing_it_wrong('EEM_Base::get_one', sprintf( __( '$query_params should be an array, you passed a variable of type %s', 'event_espresso' ), gettype( $query_params ) ), '4.6.0' );
978
+	function get_one($query_params = array()) {
979
+		if ( ! is_array($query_params)) {
980
+			EE_Error::doing_it_wrong('EEM_Base::get_one', sprintf(__('$query_params should be an array, you passed a variable of type %s', 'event_espresso'), gettype($query_params)), '4.6.0');
981 981
 			$query_params = array();
982 982
 		}
983 983
 		$query_params['limit'] = 1;
984 984
 		$items = $this->get_all($query_params);
985
-		if(empty($items)){
985
+		if (empty($items)) {
986 986
 			return null;
987
-		}else{
987
+		} else {
988 988
 			return array_shift($items);
989 989
 		}
990 990
 	}
@@ -1008,8 +1008,8 @@  discard block
 block discarded – undo
1008 1008
 	 *
1009 1009
 	 * @return EE_Base_Class[]|array
1010 1010
 	 */
1011
-	public function next_x( $current_field_value, $field_to_order_by = null, $limit = 1, $query_params = array(), $columns_to_select = null ) {
1012
-		return $this->_get_consecutive( $current_field_value, '>', $field_to_order_by, $limit, $query_params, $columns_to_select );
1011
+	public function next_x($current_field_value, $field_to_order_by = null, $limit = 1, $query_params = array(), $columns_to_select = null) {
1012
+		return $this->_get_consecutive($current_field_value, '>', $field_to_order_by, $limit, $query_params, $columns_to_select);
1013 1013
 	}
1014 1014
 
1015 1015
 
@@ -1032,8 +1032,8 @@  discard block
 block discarded – undo
1032 1032
 	 *
1033 1033
 	 * @return EE_Base_Class[]|array
1034 1034
 	 */
1035
-	public function previous_x( $current_field_value, $field_to_order_by = null, $limit = 1, $query_params = array(), $columns_to_select = null ) {
1036
-		return $this->_get_consecutive( $current_field_value, '<', $field_to_order_by, $limit, $query_params, $columns_to_select );
1035
+	public function previous_x($current_field_value, $field_to_order_by = null, $limit = 1, $query_params = array(), $columns_to_select = null) {
1036
+		return $this->_get_consecutive($current_field_value, '<', $field_to_order_by, $limit, $query_params, $columns_to_select);
1037 1037
 	}
1038 1038
 
1039 1039
 
@@ -1055,9 +1055,9 @@  discard block
 block discarded – undo
1055 1055
 	 *
1056 1056
 	 * @return EE_Base_Class|null|array()
1057 1057
 	 */
1058
-	public function next( $current_field_value, $field_to_order_by = null, $query_params = array(), $columns_to_select = null ) {
1059
-		$results = $this->_get_consecutive( $current_field_value, '>', $field_to_order_by, 1, $query_params, $columns_to_select );
1060
-		return empty( $results ) ? null : reset( $results );
1058
+	public function next($current_field_value, $field_to_order_by = null, $query_params = array(), $columns_to_select = null) {
1059
+		$results = $this->_get_consecutive($current_field_value, '>', $field_to_order_by, 1, $query_params, $columns_to_select);
1060
+		return empty($results) ? null : reset($results);
1061 1061
 	}
1062 1062
 
1063 1063
 
@@ -1079,9 +1079,9 @@  discard block
 block discarded – undo
1079 1079
 	 *
1080 1080
 	 * @return EE_Base_Class|null|array()
1081 1081
 	 */
1082
-	public function previous( $current_field_value, $field_to_order_by = null, $query_params = array(), $columns_to_select = null ) {
1083
-		$results = $this->_get_consecutive( $current_field_value, '<', $field_to_order_by, 1, $query_params, $columns_to_select );
1084
-		return empty( $results ) ? null : reset( $results );
1082
+	public function previous($current_field_value, $field_to_order_by = null, $query_params = array(), $columns_to_select = null) {
1083
+		$results = $this->_get_consecutive($current_field_value, '<', $field_to_order_by, 1, $query_params, $columns_to_select);
1084
+		return empty($results) ? null : reset($results);
1085 1085
 	}
1086 1086
 
1087 1087
 
@@ -1107,40 +1107,40 @@  discard block
 block discarded – undo
1107 1107
 	 * @return EE_Base_Class[]|array
1108 1108
 	 * @throws EE_Error
1109 1109
 	 */
1110
-	protected function _get_consecutive( $current_field_value, $operand = '>', $field_to_order_by = null, $limit = 1, $query_params = array(), $columns_to_select = null ) {
1110
+	protected function _get_consecutive($current_field_value, $operand = '>', $field_to_order_by = null, $limit = 1, $query_params = array(), $columns_to_select = null) {
1111 1111
 		//if $field_to_order_by is empty then let's assume we're ordering by the primary key.
1112
-		if ( empty( $field_to_order_by ) ) {
1113
-			if ( $this->has_primary_key_field() ) {
1112
+		if (empty($field_to_order_by)) {
1113
+			if ($this->has_primary_key_field()) {
1114 1114
 				$field_to_order_by = $this->get_primary_key_field()->get_name();
1115 1115
 			} else {
1116 1116
 
1117
-				if ( WP_DEBUG ) {
1118
-					throw new EE_Error( __( 'EEM_Base::_get_consecutive() has been called with no $field_to_order_by argument and there is no primary key on the field.  Please provide the field you would like to use as the base for retrieving the next item(s).', 'event_espresso' ) );
1117
+				if (WP_DEBUG) {
1118
+					throw new EE_Error(__('EEM_Base::_get_consecutive() has been called with no $field_to_order_by argument and there is no primary key on the field.  Please provide the field you would like to use as the base for retrieving the next item(s).', 'event_espresso'));
1119 1119
 				}
1120
-				EE_Error::add_error( __('There was an error with the query.', 'event_espresso') );
1120
+				EE_Error::add_error(__('There was an error with the query.', 'event_espresso'));
1121 1121
 				return array();
1122 1122
 			}
1123 1123
 		}
1124 1124
 
1125
-		if( ! is_array( $query_params ) ){
1126
-			EE_Error::doing_it_wrong('EEM_Base::_get_consecutive', sprintf( __( '$query_params should be an array, you passed a variable of type %s', 'event_espresso' ), gettype( $query_params ) ), '4.6.0' );
1125
+		if ( ! is_array($query_params)) {
1126
+			EE_Error::doing_it_wrong('EEM_Base::_get_consecutive', sprintf(__('$query_params should be an array, you passed a variable of type %s', 'event_espresso'), gettype($query_params)), '4.6.0');
1127 1127
 			$query_params = array();
1128 1128
 		}
1129 1129
 
1130 1130
 		//let's add the where query param for consecutive look up.
1131
-		$query_params[0][ $field_to_order_by ] = array( $operand, $current_field_value );
1131
+		$query_params[0][$field_to_order_by] = array($operand, $current_field_value);
1132 1132
 		$query_params['limit'] = $limit;
1133 1133
 
1134 1134
 		//set direction
1135
-		$incoming_orderby = isset( $query_params['order_by'] ) ? $query_params['order_by'] : array();
1136
-		$query_params['order_by'] = $operand == '>' ? array( $field_to_order_by => 'ASC' ) + $incoming_orderby : array( $field_to_order_by => 'DESC') + $incoming_orderby;
1135
+		$incoming_orderby = isset($query_params['order_by']) ? $query_params['order_by'] : array();
1136
+		$query_params['order_by'] = $operand == '>' ? array($field_to_order_by => 'ASC') + $incoming_orderby : array($field_to_order_by => 'DESC') + $incoming_orderby;
1137 1137
 
1138 1138
 		//if $columns_to_select is empty then that means we're returning EE_Base_Class objects
1139
-		if ( empty( $columns_to_select ) ) {
1140
-			return $this->get_all( $query_params );
1139
+		if (empty($columns_to_select)) {
1140
+			return $this->get_all($query_params);
1141 1141
 		} else {
1142 1142
 			//getting just the fields
1143
-			return $this->_get_all_wpdb_results( $query_params, ARRAY_A, $columns_to_select );
1143
+			return $this->_get_all_wpdb_results($query_params, ARRAY_A, $columns_to_select);
1144 1144
 		}
1145 1145
 	}
1146 1146
 
@@ -1151,18 +1151,18 @@  discard block
 block discarded – undo
1151 1151
 	 * This sets the _timezone property after model object has been instantiated.
1152 1152
 	 * @param null | string $timezone valid PHP DateTimeZone timezone string
1153 1153
 	 */
1154
-	public function set_timezone( $timezone ) {
1155
-		if ( $timezone !== null ) {
1154
+	public function set_timezone($timezone) {
1155
+		if ($timezone !== null) {
1156 1156
 			$this->_timezone = $timezone;
1157 1157
 		}
1158 1158
 		//note we need to loop through relations and set the timezone on those objects as well.
1159
-		foreach ( $this->_model_relations as $relation ) {
1160
-			$relation->set_timezone( $timezone );
1159
+		foreach ($this->_model_relations as $relation) {
1160
+			$relation->set_timezone($timezone);
1161 1161
 		}
1162 1162
 		//and finally we do the same for any datetime fields
1163
-		foreach ( $this->_fields as $field ) {
1164
-			if ( $field instanceof EE_Datetime_Field ) {
1165
-				$field->set_timezone( $timezone );
1163
+		foreach ($this->_fields as $field) {
1164
+			if ($field instanceof EE_Datetime_Field) {
1165
+				$field->set_timezone($timezone);
1166 1166
 			}
1167 1167
 		}
1168 1168
 	}
@@ -1177,9 +1177,9 @@  discard block
 block discarded – undo
1177 1177
 	 */
1178 1178
 	public function get_timezone() {
1179 1179
 		//first validate if timezone is set.  If not, then let's set it be whatever is set on the model fields.
1180
-		if ( empty( $this->_timezone ) ) {
1181
-			foreach( $this->_fields as $field ) {
1182
-				if ( $field instanceof EE_Datetime_Field ) {
1180
+		if (empty($this->_timezone)) {
1181
+			foreach ($this->_fields as $field) {
1182
+				if ($field instanceof EE_Datetime_Field) {
1183 1183
 					$this->set_timezone($field->get_timezone());
1184 1184
 					break;
1185 1185
 				}
@@ -1187,9 +1187,9 @@  discard block
 block discarded – undo
1187 1187
 		}
1188 1188
 
1189 1189
 		//if timezone STILL empty then return the default timezone for the site.
1190
-		if ( empty( $this->_timezone ) ) {
1191
-			EE_Registry::instance()->load_helper( 'DTT_Helper' );
1192
-			$this->set_timezone( EEH_DTT_Helper::get_timezone() );
1190
+		if (empty($this->_timezone)) {
1191
+			EE_Registry::instance()->load_helper('DTT_Helper');
1192
+			$this->set_timezone(EEH_DTT_Helper::get_timezone());
1193 1193
 		}
1194 1194
 		return $this->_timezone;
1195 1195
 	}
@@ -1207,19 +1207,19 @@  discard block
 block discarded – undo
1207 1207
 	 *
1208 1208
 	 * @return array formats in an array with the date format first, and the time format last.
1209 1209
 	 */
1210
-	public function get_formats_for( $field_name, $pretty = false ) {
1211
-		$field_settings = $this->field_settings_for( $field_name );
1210
+	public function get_formats_for($field_name, $pretty = false) {
1211
+		$field_settings = $this->field_settings_for($field_name);
1212 1212
 
1213 1213
 		//if not a valid EE_Datetime_Field then throw error
1214
-		if ( ! $field_settings instanceof EE_Datetime_Field ) {
1215
-			throw new EE_Error( sprintf( __('The field sent into EEM_Base::get_formats_for (%s) is not registered as a EE_Datetime_Field. Please check the spelling and make sure you are submitting the right field name to retrieve date_formats for.', 'event_espresso' ), $field_name ) );
1214
+		if ( ! $field_settings instanceof EE_Datetime_Field) {
1215
+			throw new EE_Error(sprintf(__('The field sent into EEM_Base::get_formats_for (%s) is not registered as a EE_Datetime_Field. Please check the spelling and make sure you are submitting the right field name to retrieve date_formats for.', 'event_espresso'), $field_name));
1216 1216
 		}
1217 1217
 
1218 1218
 		//while we are here, let's make sure the timezone internally in EEM_Base matches what is stored on
1219 1219
 		//the field.
1220 1220
 		$this->_timezone = $field_settings->get_timezone();
1221 1221
 
1222
-		return array( $field_settings->get_date_format( $pretty ), $field_settings->get_time_format( $pretty ) );
1222
+		return array($field_settings->get_date_format($pretty), $field_settings->get_time_format($pretty));
1223 1223
 	}
1224 1224
 
1225 1225
 
@@ -1243,25 +1243,25 @@  discard block
 block discarded – undo
1243 1243
 	 * @return int|string  If the given field_name is not of the EE_Datetime_Field type, then an EE_Error
1244 1244
 	 *                    	     exception is triggered.
1245 1245
 	 */
1246
-	public function current_time_for_query( $field_name, $timestamp = false, $what = 'both' ) {
1247
-		$formats = $this->get_formats_for( $field_name );
1246
+	public function current_time_for_query($field_name, $timestamp = false, $what = 'both') {
1247
+		$formats = $this->get_formats_for($field_name);
1248 1248
 
1249
-		$DateTime = new DateTime( "now", new DateTimeZone( $this->_timezone ) );
1249
+		$DateTime = new DateTime("now", new DateTimeZone($this->_timezone));
1250 1250
 
1251
-		if ( $timestamp ) {
1252
-			return $DateTime->format( 'U' );
1251
+		if ($timestamp) {
1252
+			return $DateTime->format('U');
1253 1253
 		}
1254 1254
 
1255 1255
 		//not returning timestamp, so return formatted string in timezone.
1256
-		switch( $what ) {
1256
+		switch ($what) {
1257 1257
 			case 'time' :
1258
-				return $DateTime->format( $formats[1] );
1258
+				return $DateTime->format($formats[1]);
1259 1259
 				break;
1260 1260
 			case 'date' :
1261
-				return $DateTime->format( $formats[0] );
1261
+				return $DateTime->format($formats[0]);
1262 1262
 				break;
1263 1263
 			default :
1264
-				return $DateTime->format( implode( ' ', $formats ) );
1264
+				return $DateTime->format(implode(' ', $formats));
1265 1265
 				break;
1266 1266
 		}
1267 1267
 	}
@@ -1285,18 +1285,18 @@  discard block
 block discarded – undo
1285 1285
 	 *                           		'U', this is ignored.
1286 1286
 	 * @return DateTime
1287 1287
 	 */
1288
-	public function convert_datetime_for_query( $field_name, $timestring, $incoming_format, $timezone = '' ) {
1288
+	public function convert_datetime_for_query($field_name, $timestring, $incoming_format, $timezone = '') {
1289 1289
 
1290 1290
 		//just using this to ensure the timezone is set correctly internally
1291
-		$this->get_formats_for( $field_name );
1291
+		$this->get_formats_for($field_name);
1292 1292
 
1293 1293
 		//load EEH_DTT_Helper
1294
-		EE_Registry::instance()->load_helper( 'DTT_Helper' );
1295
-		$set_timezone = empty( $timezone ) ? EEH_DTT_Helper::get_timezone() : $timezone;
1294
+		EE_Registry::instance()->load_helper('DTT_Helper');
1295
+		$set_timezone = empty($timezone) ? EEH_DTT_Helper::get_timezone() : $timezone;
1296 1296
 
1297
-		$incomingDateTime = date_create_from_format( $incoming_format, $timestring, new DateTimeZone( $set_timezone ) );
1297
+		$incomingDateTime = date_create_from_format($incoming_format, $timestring, new DateTimeZone($set_timezone));
1298 1298
 
1299
-		return $incomingDateTime->setTimeZone( new DateTimeZone( $this->_timezone ) );
1299
+		return $incomingDateTime->setTimeZone(new DateTimeZone($this->_timezone));
1300 1300
 	}
1301 1301
 
1302 1302
 
@@ -1306,7 +1306,7 @@  discard block
 block discarded – undo
1306 1306
 	 * Gets all the tables comprising this model. Array keys are the table aliases, and values are EE_Table objects
1307 1307
 	 * @return EE_Table_Base[]
1308 1308
 	 */
1309
-	function get_tables(){
1309
+	function get_tables() {
1310 1310
 		return $this->_tables;
1311 1311
 	}
1312 1312
 
@@ -1340,9 +1340,9 @@  discard block
 block discarded – undo
1340 1340
 	 * be aware that model objects being used could get out-of-sync with the database
1341 1341
 	 * @return int how many rows got updated or FALSE if something went wrong with the query (wp returns FALSE or num rows affected which *could* include 0 which DOES NOT mean the query was bad)
1342 1342
 	 */
1343
-	function update($fields_n_values, $query_params, $keep_model_objs_in_sync = TRUE){
1344
-		if( ! is_array( $query_params ) ){
1345
-			EE_Error::doing_it_wrong('EEM_Base::update', sprintf( __( '$query_params should be an array, you passed a variable of type %s', 'event_espresso' ), gettype( $query_params ) ), '4.6.0' );
1343
+	function update($fields_n_values, $query_params, $keep_model_objs_in_sync = TRUE) {
1344
+		if ( ! is_array($query_params)) {
1345
+			EE_Error::doing_it_wrong('EEM_Base::update', sprintf(__('$query_params should be an array, you passed a variable of type %s', 'event_espresso'), gettype($query_params)), '4.6.0');
1346 1346
 			$query_params = array();
1347 1347
 		}
1348 1348
 		/**
@@ -1352,7 +1352,7 @@  discard block
 block discarded – undo
1352 1352
 		 * @param array $fields_n_values the updated fields and their new values
1353 1353
 		 * @param array $query_params @see EEM_Base::get_all()
1354 1354
 		 */
1355
-		do_action( 'AHEE__EEM_Base__update__begin',$this, $fields_n_values, $query_params );
1355
+		do_action('AHEE__EEM_Base__update__begin', $this, $fields_n_values, $query_params);
1356 1356
 		/**
1357 1357
 		 * Filters the fields about to be updated given the query parameters. You can provide the
1358 1358
 		 * $query_params to $this->get_all() to find exactly which records will be updated
@@ -1360,10 +1360,10 @@  discard block
 block discarded – undo
1360 1360
 		 * @param EEM_Base $model the model being queried
1361 1361
 		 * @param array $query_params see EEM_Base::get_all()
1362 1362
 		 */
1363
-		$fields_n_values = apply_filters( 'FHEE__EEM_Base__update__fields_n_values', $fields_n_values, $this, $query_params );
1363
+		$fields_n_values = apply_filters('FHEE__EEM_Base__update__fields_n_values', $fields_n_values, $this, $query_params);
1364 1364
 		//need to verify that, for any entry we want to update, there are entries in each secondary table.
1365 1365
 		//to do that, for each table, verify that it's PK isn't null.
1366
-		$tables= $this->get_tables();
1366
+		$tables = $this->get_tables();
1367 1367
 
1368 1368
 		//and if the other tables don't have a row for each table-to-be-updated, we'll insert one with whatever values available in the current update query
1369 1369
 		//NOTE: we should make this code more efficient by NOT querying twice
@@ -1373,29 +1373,29 @@  discard block
 block discarded – undo
1373 1373
 			//we want to make sure the default_where strategy is ignored
1374 1374
 			$this->_ignore_where_strategy = TRUE;
1375 1375
 			$wpdb_select_results = $this->_get_all_wpdb_results($query_params);
1376
-			foreach( $wpdb_select_results as $wpdb_result ){
1376
+			foreach ($wpdb_select_results as $wpdb_result) {
1377 1377
 				// type cast stdClass as array
1378
-				$wpdb_result = (array)$wpdb_result;
1378
+				$wpdb_result = (array) $wpdb_result;
1379 1379
 				//get the model object's PK, as we'll want this if we need to insert a row into secondary tables
1380
-				if( $this->has_primary_key_field() ){
1381
-					$main_table_pk_value = $wpdb_result[ $this->get_primary_key_field()->get_qualified_column() ];
1382
-				}else{
1380
+				if ($this->has_primary_key_field()) {
1381
+					$main_table_pk_value = $wpdb_result[$this->get_primary_key_field()->get_qualified_column()];
1382
+				} else {
1383 1383
 					//if there's no primary key, we basically can't support having a 2nd table on the model (we could but it would be lots of work)
1384 1384
 					$main_table_pk_value = null;
1385 1385
 				}
1386 1386
 				//if there are more than 1 tables, we'll want to verify that each table for this model has an entry in the other tables
1387 1387
 				//and if the other tables don't have a row for each table-to-be-updated, we'll insert one with whatever values available in the current update query
1388
-				if(count($tables) > 1){
1388
+				if (count($tables) > 1) {
1389 1389
 					//foreach matching row in the DB, ensure that each table's PK isn't null. If so, there must not be an entry
1390 1390
 					//in that table, and so we'll want to insert one
1391
-					foreach($tables as $table_obj){
1391
+					foreach ($tables as $table_obj) {
1392 1392
 						$this_table_pk_column = $table_obj->get_fully_qualified_pk_column();
1393 1393
 						//if there is no private key for this table on the results, it means there's no entry
1394 1394
 						//in this table, right? so insert a row in the current table, using any fields available
1395
-						if( ! ( array_key_exists( $this_table_pk_column, $wpdb_result) && $wpdb_result[ $this_table_pk_column ] )){
1395
+						if ( ! (array_key_exists($this_table_pk_column, $wpdb_result) && $wpdb_result[$this_table_pk_column])) {
1396 1396
 							$success = $this->_insert_into_specific_table($table_obj, $fields_n_values, $main_table_pk_value);
1397 1397
 							//if we died here, report the error
1398
-							if( ! $success ) {
1398
+							if ( ! $success) {
1399 1399
 								return false;
1400 1400
 							}
1401 1401
 						}
@@ -1415,44 +1415,44 @@  discard block
 block discarded – undo
1415 1415
 		//if this wasn't called from a model object (to update itself)
1416 1416
 		//then we want to make sure we keep all the existing
1417 1417
 		//model objects in sync with the db
1418
-		if( $keep_model_objs_in_sync && ! $this->_values_already_prepared_by_model_object ){
1419
-			if( $this->has_primary_key_field() ){
1420
-				$model_objs_affected_ids = $this->get_col( $query_params );
1421
-			}else{
1418
+		if ($keep_model_objs_in_sync && ! $this->_values_already_prepared_by_model_object) {
1419
+			if ($this->has_primary_key_field()) {
1420
+				$model_objs_affected_ids = $this->get_col($query_params);
1421
+			} else {
1422 1422
 				//we need to select a bunch of columns and then combine them into the the "index primary key string"s
1423
-				$models_affected_key_columns = $this->_get_all_wpdb_results($query_params, ARRAY_A );
1423
+				$models_affected_key_columns = $this->_get_all_wpdb_results($query_params, ARRAY_A);
1424 1424
 				$model_objs_affected_ids = array();
1425
-				foreach( $models_affected_key_columns as $row ){
1426
-					$combined_index_key = $this->get_index_primary_key_string( $row );
1427
-					$model_objs_affected_ids[ $combined_index_key ] = $combined_index_key;
1425
+				foreach ($models_affected_key_columns as $row) {
1426
+					$combined_index_key = $this->get_index_primary_key_string($row);
1427
+					$model_objs_affected_ids[$combined_index_key] = $combined_index_key;
1428 1428
 				}
1429 1429
 
1430 1430
 			}
1431 1431
 
1432
-			if( ! $model_objs_affected_ids ){
1432
+			if ( ! $model_objs_affected_ids) {
1433 1433
 				//wait wait wait- if nothing was affected let's stop here
1434 1434
 				return 0;
1435 1435
 			}
1436
-			foreach( $model_objs_affected_ids as $id ){
1437
-				$model_obj_in_entity_map = $this->get_from_entity_map( $id );
1438
-				if( $model_obj_in_entity_map ){
1439
-					foreach( $fields_n_values as $field => $new_value ){
1440
-						$model_obj_in_entity_map->set( $field, $new_value );
1436
+			foreach ($model_objs_affected_ids as $id) {
1437
+				$model_obj_in_entity_map = $this->get_from_entity_map($id);
1438
+				if ($model_obj_in_entity_map) {
1439
+					foreach ($fields_n_values as $field => $new_value) {
1440
+						$model_obj_in_entity_map->set($field, $new_value);
1441 1441
 					}
1442 1442
 				}
1443 1443
 			}
1444 1444
 			//if there is a primary key on this model, we can now do a slight optimization
1445
-			if( $this->has_primary_key_field() ){
1445
+			if ($this->has_primary_key_field()) {
1446 1446
 				//we already know what we want to update. So let's make the query simpler so it's a little more efficient
1447 1447
 				$query_params = array(
1448
-					array( $this->primary_key_name() => array( 'IN', $model_objs_affected_ids ) ),
1449
-					'limit' => count( $model_objs_affected_ids ), 'default_where_conditions' => 'none' );
1448
+					array($this->primary_key_name() => array('IN', $model_objs_affected_ids)),
1449
+					'limit' => count($model_objs_affected_ids), 'default_where_conditions' => 'none' );
1450 1450
 			}
1451 1451
 		}
1452 1452
 
1453
-		$model_query_info = $this->_create_model_query_info_carrier( $query_params );
1454
-		$SQL = "UPDATE ".$model_query_info->get_full_join_sql()." SET ".$this->_construct_update_sql($fields_n_values).$model_query_info->get_where_sql();//note: doesn't use _construct_2nd_half_of_select_query() because doesn't accept LIMIT, ORDER BY, etc.
1455
-		$rows_affected = $this->_do_wpdb_query('query', array( $SQL ) );
1453
+		$model_query_info = $this->_create_model_query_info_carrier($query_params);
1454
+		$SQL = "UPDATE ".$model_query_info->get_full_join_sql()." SET ".$this->_construct_update_sql($fields_n_values).$model_query_info->get_where_sql(); //note: doesn't use _construct_2nd_half_of_select_query() because doesn't accept LIMIT, ORDER BY, etc.
1455
+		$rows_affected = $this->_do_wpdb_query('query', array($SQL));
1456 1456
 		/**
1457 1457
 		 * Action called after a model update call has been made.
1458 1458
 		 *
@@ -1461,8 +1461,8 @@  discard block
 block discarded – undo
1461 1461
 		 * @param array $query_params @see EEM_Base::get_all()
1462 1462
 		 * @param int $rows_affected
1463 1463
 		 */
1464
-		do_action( 'AHEE__EEM_Base__update__end',$this, $fields_n_values, $query_params, $rows_affected );
1465
-		return $rows_affected;//how many supposedly got updated
1464
+		do_action('AHEE__EEM_Base__update__end', $this, $fields_n_values, $query_params, $rows_affected);
1465
+		return $rows_affected; //how many supposedly got updated
1466 1466
 	}
1467 1467
 
1468 1468
 	/**
@@ -1474,22 +1474,22 @@  discard block
 block discarded – undo
1474 1474
 	 * @param string $field_to_select
1475 1475
 	 * @return array just like $wpdb->get_col()
1476 1476
 	 */
1477
-	public function get_col( $query_params  = array(), $field_to_select = NULL ){
1477
+	public function get_col($query_params = array(), $field_to_select = NULL) {
1478 1478
 
1479
-		if( $field_to_select ){
1480
-			$field = $this->field_settings_for( $field_to_select );
1481
-		}elseif( $this->has_primary_key_field ( ) ){
1479
+		if ($field_to_select) {
1480
+			$field = $this->field_settings_for($field_to_select);
1481
+		}elseif ($this->has_primary_key_field( )) {
1482 1482
 			$field = $this->get_primary_key_field();
1483
-		}else{
1483
+		} else {
1484 1484
 			//no primary key, just grab the first column
1485
-			$field = reset( $this->field_settings());
1485
+			$field = reset($this->field_settings());
1486 1486
 		}
1487 1487
 
1488 1488
 
1489 1489
 		$model_query_info = $this->_create_model_query_info_carrier($query_params);
1490 1490
 		$select_expressions = $field->get_qualified_column();
1491
-		$SQL ="SELECT $select_expressions ".$this->_construct_2nd_half_of_select_query($model_query_info);
1492
-		$results =  $this->_do_wpdb_query('get_col', array( $SQL ) );
1491
+		$SQL = "SELECT $select_expressions ".$this->_construct_2nd_half_of_select_query($model_query_info);
1492
+		$results = $this->_do_wpdb_query('get_col', array($SQL));
1493 1493
 		return $results;
1494 1494
 	}
1495 1495
 
@@ -1499,12 +1499,12 @@  discard block
 block discarded – undo
1499 1499
 	 * @param string $field_to_select @see EEM_Base::get_col()
1500 1500
 	 * @return string
1501 1501
 	 */
1502
-	public function get_var( $query_params = array(), $field_to_select = NULL ) {
1503
-		$query_params[ 'limit' ] = 1;
1504
-		$col = $this->get_col( $query_params, $field_to_select );
1505
-		if( ! empty( $col ) ) {
1506
-			return reset( $col );
1507
-		}else{
1502
+	public function get_var($query_params = array(), $field_to_select = NULL) {
1503
+		$query_params['limit'] = 1;
1504
+		$col = $this->get_col($query_params, $field_to_select);
1505
+		if ( ! empty($col)) {
1506
+			return reset($col);
1507
+		} else {
1508 1508
 			return NULL;
1509 1509
 		}
1510 1510
 	}
@@ -1518,19 +1518,19 @@  discard block
 block discarded – undo
1518 1518
 	 * @param array $fields_n_values array keys are field names on this model, and values are what those fields should be updated to in the DB
1519 1519
 	 * @return string of SQL
1520 1520
 	 */
1521
-	function _construct_update_sql($fields_n_values){
1521
+	function _construct_update_sql($fields_n_values) {
1522 1522
 		/** @type WPDB $wpdb */
1523 1523
 		global $wpdb;
1524 1524
 		$cols_n_values = array();
1525
-		foreach($fields_n_values as $field_name => $value){
1525
+		foreach ($fields_n_values as $field_name => $value) {
1526 1526
 			$field_obj = $this->field_settings_for($field_name);
1527 1527
 			//if the value is NULL, we want to assign the value to that.
1528 1528
 			//wpdb->prepare doesn't really handle that properly
1529
-			$prepared_value = $this->_prepare_value_or_use_default( $field_obj, $fields_n_values );
1530
-			$value_sql = $prepared_value===NULL ? 'NULL' : $wpdb->prepare( $field_obj->get_wpdb_data_type(), $prepared_value );
1529
+			$prepared_value = $this->_prepare_value_or_use_default($field_obj, $fields_n_values);
1530
+			$value_sql = $prepared_value === NULL ? 'NULL' : $wpdb->prepare($field_obj->get_wpdb_data_type(), $prepared_value);
1531 1531
 			$cols_n_values[] = $field_obj->get_qualified_column()."=".$value_sql;
1532 1532
 		}
1533
-		return implode(",",$cols_n_values);
1533
+		return implode(",", $cols_n_values);
1534 1534
 
1535 1535
 	}
1536 1536
 
@@ -1542,10 +1542,10 @@  discard block
 block discarded – undo
1542 1542
 	 * @param mixed $id
1543 1543
 	 * @return boolean whether the row got deleted or not
1544 1544
 	 */
1545
-	public function delete_permanently_by_ID( $id ) {
1545
+	public function delete_permanently_by_ID($id) {
1546 1546
 		return $this->delete_permanently(
1547 1547
 			array(
1548
-				array( $this->get_primary_key_field()->get_name() => $id ),
1548
+				array($this->get_primary_key_field()->get_name() => $id),
1549 1549
 				'limit' 	=> 1
1550 1550
 			)
1551 1551
 		);
@@ -1559,10 +1559,10 @@  discard block
 block discarded – undo
1559 1559
 	 * @param mixed $id
1560 1560
 	 * @return boolean whether the row got deleted or not
1561 1561
 	 */
1562
-	public function delete_by_ID( $id ){
1562
+	public function delete_by_ID($id) {
1563 1563
 		return $this->delete(
1564 1564
 			array(
1565
-				array( $this->get_primary_key_field()->get_name() => $id ),
1565
+				array($this->get_primary_key_field()->get_name() => $id),
1566 1566
 				'limit' 	=> 1
1567 1567
 			)
1568 1568
 		);
@@ -1576,7 +1576,7 @@  discard block
 block discarded – undo
1576 1576
 	 * @param boolean $allow_blocking
1577 1577
 	 * @return @see EEM_Base::delete_permanently
1578 1578
 	 */
1579
-	function delete($query_params,$allow_blocking = true){
1579
+	function delete($query_params, $allow_blocking = true) {
1580 1580
 		return $this->delete_permanently($query_params, $allow_blocking);
1581 1581
 	}
1582 1582
 
@@ -1592,7 +1592,7 @@  discard block
 block discarded – undo
1592 1592
 	 * which may depend on it. Its generally advisable to always leave this as TRUE, otherwise you could easily corrupt your DB
1593 1593
 	 * @return int how many rows got deleted
1594 1594
 	 */
1595
-	function delete_permanently($query_params,$allow_blocking = true){
1595
+	function delete_permanently($query_params, $allow_blocking = true) {
1596 1596
 		/**
1597 1597
 		 * Action called just before performing a real deletion query. You can use the
1598 1598
 		 * model and its $query_params to find exactly which items will be deleted
@@ -1601,34 +1601,34 @@  discard block
 block discarded – undo
1601 1601
 		 * @param boolean $allow_blocking whether or not to allow related model objects
1602 1602
 		 * to block (prevent) this deletion
1603 1603
 		 */
1604
-		do_action( 'AHEE__EEM_Base__delete__begin', $this, $query_params, $allow_blocking );
1604
+		do_action('AHEE__EEM_Base__delete__begin', $this, $query_params, $allow_blocking);
1605 1605
 		//some MySQL databases may be running safe mode, which may restrict
1606 1606
 		//deletion if there is no KEY column used in the WHERE statement of a deletion.
1607 1607
 		//to get around this, we first do a SELECT, get all the IDs, and then run another query
1608 1608
 		//to delete them
1609 1609
 		$items_for_deletion = $this->_get_all_wpdb_results($query_params);
1610
-		$deletion_where = $this->_setup_ids_for_delete( $items_for_deletion, $allow_blocking);
1611
-		if($deletion_where){
1610
+		$deletion_where = $this->_setup_ids_for_delete($items_for_deletion, $allow_blocking);
1611
+		if ($deletion_where) {
1612 1612
 			//echo "objects for deletion:";var_dump($objects_for_deletion);
1613 1613
 			$model_query_info = $this->_create_model_query_info_carrier($query_params);
1614 1614
 			$table_aliases = array();
1615
-			foreach(array_keys($this->_tables) as $table_alias){
1615
+			foreach (array_keys($this->_tables) as $table_alias) {
1616 1616
 				$table_aliases[] = $table_alias;
1617 1617
 			}
1618
-			$SQL = "DELETE ".implode(", ",$table_aliases)." FROM ".$model_query_info->get_full_join_sql()." WHERE ".$deletion_where;
1618
+			$SQL = "DELETE ".implode(", ", $table_aliases)." FROM ".$model_query_info->get_full_join_sql()." WHERE ".$deletion_where;
1619 1619
 
1620 1620
 			//		/echo "delete sql:$SQL";
1621
-			$rows_deleted = $this->_do_wpdb_query( 'query', array( $SQL ) );
1622
-		}else{
1621
+			$rows_deleted = $this->_do_wpdb_query('query', array($SQL));
1622
+		} else {
1623 1623
 			$rows_deleted = 0;
1624 1624
 		}
1625 1625
 
1626 1626
 		//and lastly make sure those items are removed from the entity map; if they could be put into it at all
1627
-		if( $this->has_primary_key_field() ){
1628
-			foreach($items_for_deletion as $item_for_deletion_row ){
1629
-				$pk_value = $item_for_deletion_row[ $this->get_primary_key_field()->get_qualified_column() ];
1630
-				if( isset( $this->_entity_map[ $pk_value ] ) ){
1631
-					unset( $this->_entity_map[ $pk_value ] );
1627
+		if ($this->has_primary_key_field()) {
1628
+			foreach ($items_for_deletion as $item_for_deletion_row) {
1629
+				$pk_value = $item_for_deletion_row[$this->get_primary_key_field()->get_qualified_column()];
1630
+				if (isset($this->_entity_map[$pk_value])) {
1631
+					unset($this->_entity_map[$pk_value]);
1632 1632
 				}
1633 1633
 			}
1634 1634
 		}
@@ -1640,8 +1640,8 @@  discard block
 block discarded – undo
1640 1640
 		 * @param array $query_params @see EEM_Base::get_all()
1641 1641
 		 * @param int $rows_deleted
1642 1642
 		 */
1643
-		do_action( 'AHEE__EEM_Base__delete__end', $this, $query_params, $rows_deleted );
1644
-		return $rows_deleted;//how many supposedly got deleted
1643
+		do_action('AHEE__EEM_Base__delete__end', $this, $query_params, $rows_deleted);
1644
+		return $rows_deleted; //how many supposedly got deleted
1645 1645
 	}
1646 1646
 
1647 1647
 
@@ -1657,28 +1657,28 @@  discard block
 block discarded – undo
1657 1657
 	 * blocking its deletion before removing the relation between A and B
1658 1658
 	 * @return boolean
1659 1659
 	 */
1660
-	public function delete_is_blocked_by_related_models($this_model_obj_or_id, $ignore_this_model_obj = null){
1660
+	public function delete_is_blocked_by_related_models($this_model_obj_or_id, $ignore_this_model_obj = null) {
1661 1661
 		//first, if $ignore_this_model_obj was supplied, get its model
1662
-		if($ignore_this_model_obj && $ignore_this_model_obj instanceof EE_Base_Class){
1662
+		if ($ignore_this_model_obj && $ignore_this_model_obj instanceof EE_Base_Class) {
1663 1663
 			$ignored_model = $ignore_this_model_obj->get_model();
1664
-		}else{
1664
+		} else {
1665 1665
 			$ignored_model = null;
1666 1666
 		}
1667 1667
 		//now check all the relations of $this_model_obj_or_id and see if there
1668 1668
 		//are any related model objects blocking it?
1669 1669
 		$is_blocked = false;
1670
-		foreach($this->_model_relations as $relation_name => $relation_obj){
1671
-			if( $relation_obj->block_delete_if_related_models_exist()){
1670
+		foreach ($this->_model_relations as $relation_name => $relation_obj) {
1671
+			if ($relation_obj->block_delete_if_related_models_exist()) {
1672 1672
 				//if $ignore_this_model_obj was supplied, then for the query
1673 1673
 				//on that model needs to be told to ignore $ignore_this_model_obj
1674
-				if($ignored_model && $relation_name == $ignored_model->get_this_model_name()){
1675
-					$related_model_objects = $relation_obj->get_all_related($this_model_obj_or_id,array(
1676
-					array($ignored_model->get_primary_key_field()->get_name() => array('!=',$ignore_this_model_obj->ID()))));
1677
-				}else{
1674
+				if ($ignored_model && $relation_name == $ignored_model->get_this_model_name()) {
1675
+					$related_model_objects = $relation_obj->get_all_related($this_model_obj_or_id, array(
1676
+					array($ignored_model->get_primary_key_field()->get_name() => array('!=', $ignore_this_model_obj->ID()))));
1677
+				} else {
1678 1678
 					$related_model_objects = $relation_obj->get_all_related($this_model_obj_or_id);
1679 1679
 				}
1680 1680
 
1681
-				if($related_model_objects){
1681
+				if ($related_model_objects) {
1682 1682
 					EE_Error::add_error($relation_obj->get_deletion_error_message(), __FILE__, __FUNCTION__, __LINE__);
1683 1683
 					$is_blocked = true;
1684 1684
 				}
@@ -1698,65 +1698,65 @@  discard block
 block discarded – undo
1698 1698
 	 * @throws EE_Error
1699 1699
 	 * @return string    everything that comes after the WHERE statement.
1700 1700
 	 */
1701
-	protected function _setup_ids_for_delete( $objects_for_deletion, $allow_blocking = true) {
1702
-		if($this->has_primary_key_field()){
1701
+	protected function _setup_ids_for_delete($objects_for_deletion, $allow_blocking = true) {
1702
+		if ($this->has_primary_key_field()) {
1703 1703
 			$primary_table = $this->_get_main_table();
1704 1704
 			$other_tables = $this->_get_other_tables();
1705 1705
 			$deletes = $query = array();
1706
-			foreach ( $objects_for_deletion as $delete_object ) {
1706
+			foreach ($objects_for_deletion as $delete_object) {
1707 1707
 				//before we mark this object for deletion,
1708 1708
 				//make sure there's no related objects blocking its deletion (if we're checking)
1709
-				if( $allow_blocking && $this->delete_is_blocked_by_related_models($delete_object[$primary_table->get_fully_qualified_pk_column()]) ){
1709
+				if ($allow_blocking && $this->delete_is_blocked_by_related_models($delete_object[$primary_table->get_fully_qualified_pk_column()])) {
1710 1710
 					continue;
1711 1711
 				}
1712 1712
 
1713 1713
 				//primary table deletes
1714
-				if ( isset( $delete_object[$primary_table->get_fully_qualified_pk_column()] ) )
1714
+				if (isset($delete_object[$primary_table->get_fully_qualified_pk_column()]))
1715 1715
 					$deletes[$primary_table->get_fully_qualified_pk_column()][] = $delete_object[$primary_table->get_fully_qualified_pk_column()];
1716 1716
 
1717 1717
 				//other tables
1718
-				if ( !empty( $other_tables ) ) {
1719
-					foreach ( $other_tables as $ot ) {
1718
+				if ( ! empty($other_tables)) {
1719
+					foreach ($other_tables as $ot) {
1720 1720
 
1721 1721
 						//first check if we've got the foreign key column here.
1722
-						if ( isset( $delete_object[$ot->get_fully_qualified_fk_column()] ) )
1722
+						if (isset($delete_object[$ot->get_fully_qualified_fk_column()]))
1723 1723
 							$deletes[$ot->get_fully_qualified_pk_column()][] = $delete_object[$ot->get_fully_qualified_fk_column()];
1724 1724
 
1725 1725
 						//wait! it's entirely possible that we'll have a the primary key for this table in here if it's a foreign key for one of the other secondary tables
1726
-						if ( isset( $delete_object[$ot->get_fully_qualified_pk_column()] ) )
1726
+						if (isset($delete_object[$ot->get_fully_qualified_pk_column()]))
1727 1727
 							$deletes[$ot->get_fully_qualified_pk_column()][] = $delete_object[$ot->get_fully_qualified_pk_column()];
1728 1728
 
1729 1729
 						//finally, it is possible that the fk for this table is found in the fully qualified pk column for the fk table, so let's see if that's there!
1730
-						if ( isset( $delete_object[$ot->get_fully_qualified_pk_on_fk_table()]) )
1730
+						if (isset($delete_object[$ot->get_fully_qualified_pk_on_fk_table()]))
1731 1731
 							$deletes[$ot->get_fully_qualified_pk_column()][] = $delete_object[$ot->get_fully_qualified_pk_column()];
1732 1732
 					}
1733 1733
 				}
1734 1734
 			}
1735 1735
 
1736 1736
 			//we should have deletes now, so let's just go through and setup the where statement
1737
-			foreach ( $deletes as $column => $values ) {
1737
+			foreach ($deletes as $column => $values) {
1738 1738
 				//make sure we have unique $values;
1739 1739
 				$values = array_unique($values);
1740
-				$query[] = $column . ' IN(' . implode(",",$values) . ')';
1740
+				$query[] = $column.' IN('.implode(",", $values).')';
1741 1741
 			}
1742 1742
 
1743
-			return !empty($query) ? implode(' AND ', $query ) : '';
1744
-		}elseif(count($this->get_combined_primary_key_fields()) > 1){
1743
+			return ! empty($query) ? implode(' AND ', $query) : '';
1744
+		}elseif (count($this->get_combined_primary_key_fields()) > 1) {
1745 1745
 			$ways_to_identify_a_row = array();
1746 1746
 			$fields = $this->get_combined_primary_key_fields();
1747 1747
 			//note: because there' sno primary key, that means nothing else  can be pointing to this model, right?
1748
-			foreach($objects_for_deletion as  $delete_object){
1748
+			foreach ($objects_for_deletion as  $delete_object) {
1749 1749
 				$values_for_each_cpk_for_a_row = array();
1750
-				foreach($fields as $cpk_field){
1750
+				foreach ($fields as $cpk_field) {
1751 1751
 					$values_for_each_cpk_for_a_row[] = $cpk_field->get_qualified_column()."=".$delete_object[$cpk_field->get_qualified_column()];
1752 1752
 				}
1753
-				$ways_to_identify_a_row[] = "(".implode(" AND ",$values_for_each_cpk_for_a_row).")";
1753
+				$ways_to_identify_a_row[] = "(".implode(" AND ", $values_for_each_cpk_for_a_row).")";
1754 1754
 			}
1755
-			return implode(" OR ",$ways_to_identify_a_row);
1756
-		}else{
1755
+			return implode(" OR ", $ways_to_identify_a_row);
1756
+		} else {
1757 1757
 			//so there's no primary key and no combined key...
1758 1758
 			//sorry, can't help you
1759
-			throw new EE_Error(sprintf(__("Cannot delete objects of type %s because there is no primary key NOR combined key", "event_espresso"),get_class($this)));
1759
+			throw new EE_Error(sprintf(__("Cannot delete objects of type %s because there is no primary key NOR combined key", "event_espresso"), get_class($this)));
1760 1760
 		}
1761 1761
 	}
1762 1762
 
@@ -1770,21 +1770,21 @@  discard block
 block discarded – undo
1770 1770
 	 * @param bool 	 $distinct if we want to only count the distinct values for the column then you can trigger that by the setting $distinct to TRUE;
1771 1771
 	 * @return int
1772 1772
 	 */
1773
-	function count($query_params =array(),$field_to_count = NULL, $distinct = FALSE){
1773
+	function count($query_params = array(), $field_to_count = NULL, $distinct = FALSE) {
1774 1774
 		$model_query_info = $this->_create_model_query_info_carrier($query_params);
1775
-		if($field_to_count){
1775
+		if ($field_to_count) {
1776 1776
 			$field_obj = $this->field_settings_for($field_to_count);
1777 1777
 			$column_to_count = $field_obj->get_qualified_column();
1778
-		}elseif($this->has_primary_key_field ()){
1778
+		}elseif ($this->has_primary_key_field()) {
1779 1779
 			$pk_field_obj = $this->get_primary_key_field();
1780 1780
 			$column_to_count = $pk_field_obj->get_qualified_column();
1781
-		}else{//there's no primary key
1781
+		} else {//there's no primary key
1782 1782
 			$column_to_count = '*';
1783 1783
 		}
1784 1784
 
1785
-		$column_to_count = $distinct ? "DISTINCT (" . $column_to_count . " )" : $column_to_count;
1786
-		$SQL ="SELECT COUNT(".$column_to_count.")" . $this->_construct_2nd_half_of_select_query($model_query_info);
1787
-		return (int)$this->_do_wpdb_query( 'get_var', array( $SQL) );
1785
+		$column_to_count = $distinct ? "DISTINCT (".$column_to_count." )" : $column_to_count;
1786
+		$SQL = "SELECT COUNT(".$column_to_count.")".$this->_construct_2nd_half_of_select_query($model_query_info);
1787
+		return (int) $this->_do_wpdb_query('get_var', array($SQL));
1788 1788
 	}
1789 1789
 
1790 1790
 	/**
@@ -1794,23 +1794,23 @@  discard block
 block discarded – undo
1794 1794
 	 * @param string $field_to_sum name of field (array key in $_fields array)
1795 1795
 	 * @return float
1796 1796
 	 */
1797
-	function sum($query_params, $field_to_sum = NULL){
1797
+	function sum($query_params, $field_to_sum = NULL) {
1798 1798
 		$model_query_info = $this->_create_model_query_info_carrier($query_params);
1799 1799
 
1800
-		if($field_to_sum){
1800
+		if ($field_to_sum) {
1801 1801
 			$field_obj = $this->field_settings_for($field_to_sum);
1802 1802
 
1803
-		}else{
1803
+		} else {
1804 1804
 			$field_obj = $this->get_primary_key_field();
1805 1805
 		}
1806 1806
 		$column_to_count = $field_obj->get_qualified_column();
1807 1807
 
1808
-		$SQL ="SELECT SUM(".$column_to_count.")" . $this->_construct_2nd_half_of_select_query($model_query_info);
1809
-		$return_value = $this->_do_wpdb_query('get_var',array( $SQL ) );
1810
-		if($field_obj->get_wpdb_data_type() == '%d' || $field_obj->get_wpdb_data_type() == '%s' ){
1811
-			return (float)$return_value;
1812
-		}else{//must be %f
1813
-			return (float)$return_value;
1808
+		$SQL = "SELECT SUM(".$column_to_count.")".$this->_construct_2nd_half_of_select_query($model_query_info);
1809
+		$return_value = $this->_do_wpdb_query('get_var', array($SQL));
1810
+		if ($field_obj->get_wpdb_data_type() == '%d' || $field_obj->get_wpdb_data_type() == '%s') {
1811
+			return (float) $return_value;
1812
+		} else {//must be %f
1813
+			return (float) $return_value;
1814 1814
 		}
1815 1815
 	}
1816 1816
 
@@ -1825,33 +1825,33 @@  discard block
 block discarded – undo
1825 1825
 	 * @global wpdb $wpdb
1826 1826
 	 * @return mixed
1827 1827
 	 */
1828
-	protected function _do_wpdb_query( $wpdb_method, $arguments_to_provide ){
1828
+	protected function _do_wpdb_query($wpdb_method, $arguments_to_provide) {
1829 1829
 		//if we're in maintenance mode level 2, DON'T run any queries
1830 1830
 		//because level 2 indicates the database needs updating and
1831 1831
 		//is probably out of sync with the code
1832
-		if( ! EE_Maintenance_Mode::instance()->models_can_query()){
1832
+		if ( ! EE_Maintenance_Mode::instance()->models_can_query()) {
1833 1833
 			throw new EE_Error(sprintf(__("Event Espresso Level 2 Maintenance mode is active. That means EE can not run ANY database queries until the necessary migration scripts have run which will take EE out of maintenance mode level 2. Please inform support of this error.", "event_espresso")));
1834 1834
 		}
1835 1835
 		/** @type WPDB $wpdb */
1836 1836
 		global $wpdb;
1837
-		if( ! method_exists( $wpdb, $wpdb_method ) ){
1838
-			throw new EE_Error( sprintf( __( 'There is no method named "%s" on Wordpress\' $wpdb object','event_espresso' ), $wpdb_method ) );
1837
+		if ( ! method_exists($wpdb, $wpdb_method)) {
1838
+			throw new EE_Error(sprintf(__('There is no method named "%s" on Wordpress\' $wpdb object', 'event_espresso'), $wpdb_method));
1839 1839
 		}
1840
-		if( WP_DEBUG ){
1840
+		if (WP_DEBUG) {
1841 1841
 			$old_show_errors_value = $wpdb->show_errors;
1842
-			$wpdb->show_errors( FALSE );
1843
-		}
1844
-		$result = $this->_process_wpdb_query( $wpdb_method, $arguments_to_provide );
1845
-		$this->show_db_query_if_previously_requested( $wpdb->last_query );
1846
-		if( WP_DEBUG ){
1847
-			$wpdb->show_errors( $old_show_errors_value );
1848
-			if( ! empty( $wpdb->last_error ) ){
1849
-				throw new EE_Error( sprintf( __( 'WPDB Error: "%s"', 'event_espresso' ), $wpdb->last_error ) );
1850
-			}elseif( $result === false ){
1851
-				throw new EE_Error( sprintf( __( 'WPDB Error occurred, but no error message was logged by wpdb! The wpdb method called was "%1$s" and the arguments were "%2$s"', 'event_espresso' ), $wpdb_method, var_export( $arguments_to_provide, true ) ) );
1842
+			$wpdb->show_errors(FALSE);
1843
+		}
1844
+		$result = $this->_process_wpdb_query($wpdb_method, $arguments_to_provide);
1845
+		$this->show_db_query_if_previously_requested($wpdb->last_query);
1846
+		if (WP_DEBUG) {
1847
+			$wpdb->show_errors($old_show_errors_value);
1848
+			if ( ! empty($wpdb->last_error)) {
1849
+				throw new EE_Error(sprintf(__('WPDB Error: "%s"', 'event_espresso'), $wpdb->last_error));
1850
+			}elseif ($result === false) {
1851
+				throw new EE_Error(sprintf(__('WPDB Error occurred, but no error message was logged by wpdb! The wpdb method called was "%1$s" and the arguments were "%2$s"', 'event_espresso'), $wpdb_method, var_export($arguments_to_provide, true)));
1852 1852
 			}
1853
-		}elseif( $result === false ) {
1854
-			EE_Error::add_error( sprintf( __( 'A database error has occurred. Turn on WP_DEBUG for more information.', 'event_espresso' )), __FILE__, __FUNCTION__, __LINE__);
1853
+		}elseif ($result === false) {
1854
+			EE_Error::add_error(sprintf(__('A database error has occurred. Turn on WP_DEBUG for more information.', 'event_espresso')), __FILE__, __FUNCTION__, __LINE__);
1855 1855
 		}
1856 1856
 		return $result;
1857 1857
 	}
@@ -1867,26 +1867,26 @@  discard block
 block discarded – undo
1867 1867
 	 * @param array $arguments_to_provide
1868 1868
 	 * @return mixed
1869 1869
 	 */
1870
-	private function _process_wpdb_query( $wpdb_method, $arguments_to_provide ) {
1870
+	private function _process_wpdb_query($wpdb_method, $arguments_to_provide) {
1871 1871
 		/** @type WPDB $wpdb */
1872 1872
 		global $wpdb;
1873 1873
 		$wpdb->last_error = null;
1874
-		$result = call_user_func_array( array( $wpdb, $wpdb_method ), $arguments_to_provide );
1874
+		$result = call_user_func_array(array($wpdb, $wpdb_method), $arguments_to_provide);
1875 1875
 		// was there an error running the query? but we don't care on new activations
1876 1876
 		// (we're going to setup the DB anyway on new activations)
1877
-		if ( ( $result === false || ! empty( $wpdb->last_error ) )
1877
+		if (($result === false || ! empty($wpdb->last_error))
1878 1878
 			&& EE_System::instance()->detect_req_type() != EE_System::req_type_new_activation
1879 1879
 		) {
1880
-			switch ( EEM_Base::$_db_verification_level ) {
1880
+			switch (EEM_Base::$_db_verification_level) {
1881 1881
 
1882 1882
 				case EEM_Base::db_verified_none :
1883 1883
 					// let's double-check core's DB
1884
-					$error_message = $this->_verify_core_db( $wpdb_method, $arguments_to_provide );
1884
+					$error_message = $this->_verify_core_db($wpdb_method, $arguments_to_provide);
1885 1885
 					break;
1886 1886
 
1887 1887
 				case EEM_Base::db_verified_core :
1888 1888
 					// STILL NO LOVE?? verify all the addons too. Maybe they need to be fixed
1889
-					$error_message = $this->_verify_addons_db( $wpdb_method, $arguments_to_provide );
1889
+					$error_message = $this->_verify_addons_db($wpdb_method, $arguments_to_provide);
1890 1890
 					break;
1891 1891
 
1892 1892
 				case EEM_Base::db_verified_addons :
@@ -1894,11 +1894,11 @@  discard block
 block discarded – undo
1894 1894
 					return $result;
1895 1895
 					break;
1896 1896
 			}
1897
-			if ( ! empty( $error_message ) ) {
1898
-				EE_Log::instance()->log( __FILE__, __FUNCTION__, $error_message, 'error' );
1899
-				trigger_error( $error_message );
1897
+			if ( ! empty($error_message)) {
1898
+				EE_Log::instance()->log(__FILE__, __FUNCTION__, $error_message, 'error');
1899
+				trigger_error($error_message);
1900 1900
 			}
1901
-			return $this->_process_wpdb_query( $wpdb_method, $arguments_to_provide );
1901
+			return $this->_process_wpdb_query($wpdb_method, $arguments_to_provide);
1902 1902
 
1903 1903
 		}
1904 1904
 
@@ -1914,18 +1914,18 @@  discard block
 block discarded – undo
1914 1914
 	 * @param array $arguments_to_provide
1915 1915
 	 * @return string
1916 1916
 	 */
1917
-	private function _verify_core_db( $wpdb_method, $arguments_to_provide ){
1917
+	private function _verify_core_db($wpdb_method, $arguments_to_provide) {
1918 1918
 		/** @type WPDB $wpdb */
1919 1919
 		global $wpdb;
1920 1920
 		//ok remember that we've already attempted fixing the core db, in case the problem persists
1921 1921
 		EEM_Base::$_db_verification_level = EEM_Base::db_verified_core;
1922 1922
 		$error_message = sprintf(
1923
-			__( 'WPDB Error "%1$s" while running wpdb method "%2$s" with arguments %3$s. Automatically attempting to fix EE Core DB', 'event_espresso' ),
1923
+			__('WPDB Error "%1$s" while running wpdb method "%2$s" with arguments %3$s. Automatically attempting to fix EE Core DB', 'event_espresso'),
1924 1924
 			$wpdb->last_error,
1925 1925
 			$wpdb_method,
1926
-			json_encode( $arguments_to_provide )
1926
+			json_encode($arguments_to_provide)
1927 1927
 		);
1928
-		EE_System::instance()->initialize_db_if_no_migrations_required( false, true );
1928
+		EE_System::instance()->initialize_db_if_no_migrations_required(false, true);
1929 1929
 		return $error_message;
1930 1930
 	}
1931 1931
 
@@ -1938,16 +1938,16 @@  discard block
 block discarded – undo
1938 1938
 	 * @param $arguments_to_provide
1939 1939
 	 * @return string
1940 1940
 	 */
1941
-	private function _verify_addons_db( $wpdb_method, $arguments_to_provide ) {
1941
+	private function _verify_addons_db($wpdb_method, $arguments_to_provide) {
1942 1942
 		/** @type WPDB $wpdb */
1943 1943
 		global $wpdb;
1944 1944
 		//ok remember that we've already attempted fixing the addons dbs, in case the problem persists
1945 1945
 		EEM_Base::$_db_verification_level = EEM_Base::db_verified_addons;
1946 1946
 		$error_message = sprintf(
1947
-			__( 'WPDB AGAIN: Error "%1$s" while running the same method and arguments as before. Automatically attempting to fix EE Addons DB', 'event_espresso' ),
1947
+			__('WPDB AGAIN: Error "%1$s" while running the same method and arguments as before. Automatically attempting to fix EE Addons DB', 'event_espresso'),
1948 1948
 			$wpdb->last_error,
1949 1949
 			$wpdb_method,
1950
-			json_encode( $arguments_to_provide )
1950
+			json_encode($arguments_to_provide)
1951 1951
 		);
1952 1952
 		EE_System::instance()->initialize_addons();
1953 1953
 		return $error_message;
@@ -1962,7 +1962,7 @@  discard block
 block discarded – undo
1962 1962
 	 * @param EE_Model_Query_Info_Carrier $model_query_info
1963 1963
 	 * @return string
1964 1964
 	 */
1965
-	private function _construct_2nd_half_of_select_query(EE_Model_Query_Info_Carrier $model_query_info){
1965
+	private function _construct_2nd_half_of_select_query(EE_Model_Query_Info_Carrier $model_query_info) {
1966 1966
 		return " FROM ".$model_query_info->get_full_join_sql().
1967 1967
 				$model_query_info->get_where_sql().
1968 1968
 				$model_query_info->get_group_by_sql().
@@ -1975,7 +1975,7 @@  discard block
 block discarded – undo
1975 1975
 	 * Set to easily debug the next X queries ran from this model.
1976 1976
 	 * @param int $count
1977 1977
 	 */
1978
-	function show_next_x_db_queries($count = 1){
1978
+	function show_next_x_db_queries($count = 1) {
1979 1979
 		$this->_show_next_x_db_queries = $count;
1980 1980
 	}
1981 1981
 
@@ -1984,8 +1984,8 @@  discard block
 block discarded – undo
1984 1984
 	/**
1985 1985
 	 * @param $sql_query
1986 1986
 	 */
1987
-	function show_db_query_if_previously_requested($sql_query){
1988
-		if($this->_show_next_x_db_queries > 0){
1987
+	function show_db_query_if_previously_requested($sql_query) {
1988
+		if ($this->_show_next_x_db_queries > 0) {
1989 1989
 			echo $sql_query;
1990 1990
 			$this->_show_next_x_db_queries--;
1991 1991
 		}
@@ -2009,9 +2009,9 @@  discard block
 block discarded – undo
2009 2009
 	 * @param array   $extra_join_model_fields_n_values This allows you to enter further query params for the relation to for relation to methods that allow you to further specify extra columns to join by (such as HABTM).  Keep in mind that the only acceptable query_params is strict "col" => "value" pairs because these will be inserted in any new rows created as well.
2010 2010
 	 * @return EE_Base_Class which was added as a relation. Object referred to by $other_model_id_or_obj
2011 2011
 	 */
2012
-	public function add_relationship_to($id_or_obj,$other_model_id_or_obj, $relationName, $extra_join_model_fields_n_values = array()){
2012
+	public function add_relationship_to($id_or_obj, $other_model_id_or_obj, $relationName, $extra_join_model_fields_n_values = array()) {
2013 2013
 		$relation_obj = $this->related_settings_for($relationName);
2014
-		return $relation_obj->add_relation_to( $id_or_obj, $other_model_id_or_obj, $extra_join_model_fields_n_values);
2014
+		return $relation_obj->add_relation_to($id_or_obj, $other_model_id_or_obj, $extra_join_model_fields_n_values);
2015 2015
 	}
2016 2016
 
2017 2017
 	/**
@@ -2030,9 +2030,9 @@  discard block
 block discarded – undo
2030 2030
 	 * @return boolean of success
2031 2031
 	 * @param array   $where_query This allows you to enter further query params for the relation to for relation to methods that allow you to further specify extra columns to join by (such as HABTM).  Keep in mind that the only acceptable query_params is strict "col" => "value" pairs because these will be inserted in any new rows created as well.
2032 2032
 	 */
2033
-	public function remove_relationship_to($id_or_obj,  $other_model_id_or_obj, $relationName, $where_query= array() ){
2033
+	public function remove_relationship_to($id_or_obj, $other_model_id_or_obj, $relationName, $where_query = array()) {
2034 2034
 		$relation_obj = $this->related_settings_for($relationName);
2035
-		return $relation_obj->remove_relation_to($id_or_obj, $other_model_id_or_obj, $where_query );
2035
+		return $relation_obj->remove_relation_to($id_or_obj, $other_model_id_or_obj, $where_query);
2036 2036
 	}
2037 2037
 
2038 2038
 
@@ -2045,9 +2045,9 @@  discard block
 block discarded – undo
2045 2045
 	 * @param EE_Base_Class[] objects to which relations were removed
2046 2046
 	 * @return \EE_Base_Class[]
2047 2047
 	 */
2048
-	public function remove_relations($id_or_obj,$relationName,$where_query_params = array()){
2048
+	public function remove_relations($id_or_obj, $relationName, $where_query_params = array()) {
2049 2049
 		$relation_obj = $this->related_settings_for($relationName);
2050
-		return $relation_obj->remove_relations($id_or_obj, $where_query_params );
2050
+		return $relation_obj->remove_relations($id_or_obj, $where_query_params);
2051 2051
 	}
2052 2052
 
2053 2053
 
@@ -2060,10 +2060,10 @@  discard block
 block discarded – undo
2060 2060
 	 * @param array $query_params like EEM_Base::get_all
2061 2061
 	 * @return EE_Base_Class[]
2062 2062
 	 */
2063
-	function get_all_related($id_or_obj, $model_name, $query_params = null){
2063
+	function get_all_related($id_or_obj, $model_name, $query_params = null) {
2064 2064
 		$model_obj = $this->ensure_is_obj($id_or_obj);
2065 2065
 		$relation_settings = $this->related_settings_for($model_name);
2066
-		return $relation_settings->get_all_related($model_obj,$query_params);
2066
+		return $relation_settings->get_all_related($model_obj, $query_params);
2067 2067
 	}
2068 2068
 
2069 2069
 	/**
@@ -2076,10 +2076,10 @@  discard block
 block discarded – undo
2076 2076
 	 * @param array $query_params
2077 2077
 	 * @return int how many deleted
2078 2078
 	 */
2079
-	public function delete_related($id_or_obj,$model_name, $query_params = array()){
2079
+	public function delete_related($id_or_obj, $model_name, $query_params = array()) {
2080 2080
 		$model_obj = $this->ensure_is_obj($id_or_obj);
2081 2081
 		$relation_settings = $this->related_settings_for($model_name);
2082
-		return $relation_settings->delete_all_related($model_obj,$query_params);
2082
+		return $relation_settings->delete_all_related($model_obj, $query_params);
2083 2083
 	}
2084 2084
 
2085 2085
 	/**
@@ -2092,10 +2092,10 @@  discard block
 block discarded – undo
2092 2092
 	 * @param array $query_params
2093 2093
 	 * @return int how many deleted
2094 2094
 	 */
2095
-	public function delete_related_permanently($id_or_obj,$model_name, $query_params = array()){
2095
+	public function delete_related_permanently($id_or_obj, $model_name, $query_params = array()) {
2096 2096
 		$model_obj = $this->ensure_is_obj($id_or_obj);
2097 2097
 		$relation_settings = $this->related_settings_for($model_name);
2098
-		return $relation_settings->delete_related_permanently($model_obj,$query_params);
2098
+		return $relation_settings->delete_related_permanently($model_obj, $query_params);
2099 2099
 	}
2100 2100
 
2101 2101
 	/**
@@ -2108,17 +2108,17 @@  discard block
 block discarded – undo
2108 2108
 	 * @param bool 	 $distinct if we want to only count the distinct values for the column then you can trigger that by the setting $distinct to TRUE;
2109 2109
 	 * @return int
2110 2110
 	 */
2111
-	function count_related($id_or_obj,$model_name,$query_params = array(),$field_to_count = null, $distinct = FALSE){
2111
+	function count_related($id_or_obj, $model_name, $query_params = array(), $field_to_count = null, $distinct = FALSE) {
2112 2112
 		$related_model = $this->get_related_model_obj($model_name);
2113 2113
 		//we're just going to use the query params on the related model's normal get_all query,
2114 2114
 		//except add a condition to say to match the current mod
2115
-		if( ! isset($query_params['default_where_conditions'])){
2116
-			$query_params['default_where_conditions']='none';
2115
+		if ( ! isset($query_params['default_where_conditions'])) {
2116
+			$query_params['default_where_conditions'] = 'none';
2117 2117
 		}
2118 2118
 		$this_model_name = $this->get_this_model_name();
2119 2119
 		$this_pk_field_name = $this->get_primary_key_field()->get_name();
2120
-		$query_params[0][$this_model_name.".".$this_pk_field_name]=$id_or_obj;
2121
-		return $related_model->count($query_params,$field_to_count,$distinct);
2120
+		$query_params[0][$this_model_name.".".$this_pk_field_name] = $id_or_obj;
2121
+		return $related_model->count($query_params, $field_to_count, $distinct);
2122 2122
 	}
2123 2123
 
2124 2124
 
@@ -2132,21 +2132,21 @@  discard block
 block discarded – undo
2132 2132
 	 * @param string $field_to_sum name of field to count by. By default, uses primary key
2133 2133
 	 * @return float
2134 2134
 	 */
2135
-	function sum_related($id_or_obj,$model_name,$query_params,$field_to_sum = null){
2135
+	function sum_related($id_or_obj, $model_name, $query_params, $field_to_sum = null) {
2136 2136
 		$related_model = $this->get_related_model_obj($model_name);
2137
-		if( ! is_array( $query_params ) ){
2138
-			EE_Error::doing_it_wrong('EEM_Base::sum_related', sprintf( __( '$query_params should be an array, you passed a variable of type %s', 'event_espresso' ), gettype( $query_params ) ), '4.6.0' );
2137
+		if ( ! is_array($query_params)) {
2138
+			EE_Error::doing_it_wrong('EEM_Base::sum_related', sprintf(__('$query_params should be an array, you passed a variable of type %s', 'event_espresso'), gettype($query_params)), '4.6.0');
2139 2139
 			$query_params = array();
2140 2140
 		}
2141 2141
 		//we're just going to use the query params on the related model's normal get_all query,
2142 2142
 		//except add a condition to say to match the current mod
2143
-		if( ! isset($query_params['default_where_conditions'])){
2144
-			$query_params['default_where_conditions']='none';
2143
+		if ( ! isset($query_params['default_where_conditions'])) {
2144
+			$query_params['default_where_conditions'] = 'none';
2145 2145
 		}
2146 2146
 		$this_model_name = $this->get_this_model_name();
2147 2147
 		$this_pk_field_name = $this->get_primary_key_field()->get_name();
2148
-		$query_params[0][$this_model_name.".".$this_pk_field_name]=$id_or_obj;
2149
-		return $related_model->sum($query_params,$field_to_sum);
2148
+		$query_params[0][$this_model_name.".".$this_pk_field_name] = $id_or_obj;
2149
+		return $related_model->sum($query_params, $field_to_sum);
2150 2150
 	}
2151 2151
 
2152 2152
 
@@ -2158,12 +2158,12 @@  discard block
 block discarded – undo
2158 2158
 	 * @param array $query_params like EEM_Base::get_all's
2159 2159
 	 * @return EE_Base_Class
2160 2160
 	 */
2161
-	public function get_first_related( EE_Base_Class $id_or_obj, $other_model_name, $query_params ){
2162
-		$query_params['limit']=1;
2163
-		$results = $this->get_all_related($id_or_obj,$other_model_name,$query_params);
2164
-		if( $results ){
2161
+	public function get_first_related(EE_Base_Class $id_or_obj, $other_model_name, $query_params) {
2162
+		$query_params['limit'] = 1;
2163
+		$results = $this->get_all_related($id_or_obj, $other_model_name, $query_params);
2164
+		if ($results) {
2165 2165
 			return array_shift($results);
2166
-		}else{
2166
+		} else {
2167 2167
 			return null;
2168 2168
 		}
2169 2169
 
@@ -2173,8 +2173,8 @@  discard block
 block discarded – undo
2173 2173
 	 * Gets the model's name as it's expected in queries. For example, if this is EEM_Event model, that would be Event
2174 2174
 	 * @return string
2175 2175
 	 */
2176
-	function get_this_model_name(){
2177
-		return str_replace("EEM_","",get_class($this));
2176
+	function get_this_model_name() {
2177
+		return str_replace("EEM_", "", get_class($this));
2178 2178
 	}
2179 2179
 
2180 2180
 	/**
@@ -2182,14 +2182,14 @@  discard block
 block discarded – undo
2182 2182
 	 * @return EE_Any_Foreign_Model_Name_Field
2183 2183
 	 * @throws EE_Error
2184 2184
 	 */
2185
-	public function get_field_containing_related_model_name(){
2186
-		foreach($this->field_settings(true) as $field){
2187
-			if($field instanceof EE_Any_Foreign_Model_Name_Field){
2185
+	public function get_field_containing_related_model_name() {
2186
+		foreach ($this->field_settings(true) as $field) {
2187
+			if ($field instanceof EE_Any_Foreign_Model_Name_Field) {
2188 2188
 				$field_with_model_name = $field;
2189 2189
 			}
2190 2190
 		}
2191
-		if( !isset($field_with_model_name) || !$field_with_model_name ){
2192
-			throw new EE_Error(sprintf(__("There is no EE_Any_Foreign_Model_Name field on model %s", "event_espresso"), $this->get_this_model_name() ));
2191
+		if ( ! isset($field_with_model_name) || ! $field_with_model_name) {
2192
+			throw new EE_Error(sprintf(__("There is no EE_Any_Foreign_Model_Name field on model %s", "event_espresso"), $this->get_this_model_name()));
2193 2193
 		}
2194 2194
 		return $field_with_model_name;
2195 2195
 	}
@@ -2210,19 +2210,19 @@  discard block
 block discarded – undo
2210 2210
 	 * @return int new primary key on main table that got inserted
2211 2211
 	 * @throws EE_Error
2212 2212
 	 */
2213
-	function insert($field_n_values){
2213
+	function insert($field_n_values) {
2214 2214
 		/**
2215 2215
 		 * Filters the fields and their values before inserting an item using the models
2216 2216
 		 * @param array $fields_n_values keys are the fields and values are their new values
2217 2217
 		 * @param EEM_Base $model the model used
2218 2218
 		 */
2219
-		$field_n_values = apply_filters( 'FHEE__EEM_Base__insert__fields_n_values', $field_n_values, $this );
2220
-		if($this->_satisfies_unique_indexes($field_n_values)){
2219
+		$field_n_values = apply_filters('FHEE__EEM_Base__insert__fields_n_values', $field_n_values, $this);
2220
+		if ($this->_satisfies_unique_indexes($field_n_values)) {
2221 2221
 			$main_table = $this->_get_main_table();
2222 2222
 			$new_id = $this->_insert_into_specific_table($main_table, $field_n_values, false);
2223
-			if( $new_id !== false ) {
2224
-				foreach($this->_get_other_tables() as $other_table){
2225
-					$this->_insert_into_specific_table($other_table, $field_n_values,$new_id);
2223
+			if ($new_id !== false) {
2224
+				foreach ($this->_get_other_tables() as $other_table) {
2225
+					$this->_insert_into_specific_table($other_table, $field_n_values, $new_id);
2226 2226
 				}
2227 2227
 			}
2228 2228
 			/**
@@ -2232,9 +2232,9 @@  discard block
 block discarded – undo
2232 2232
 			 * @param array $fields_n_values fields and their values
2233 2233
 			 * @param int|string the ID of the newly-inserted model object
2234 2234
 			 */
2235
-			do_action( 'AHEE__EEM_Base__insert__end', $this, $field_n_values, $new_id );
2235
+			do_action('AHEE__EEM_Base__insert__end', $this, $field_n_values, $new_id);
2236 2236
 			return $new_id;
2237
-		}else{
2237
+		} else {
2238 2238
 			return FALSE;
2239 2239
 		}
2240 2240
 	}
@@ -2247,11 +2247,11 @@  discard block
 block discarded – undo
2247 2247
 	 * @param string $action
2248 2248
 	 * @return boolean
2249 2249
 	 */
2250
-	protected function _satisfies_unique_indexes($field_n_values,$action = 'insert'){
2251
-		foreach($this->unique_indexes() as $index_name => $index){
2250
+	protected function _satisfies_unique_indexes($field_n_values, $action = 'insert') {
2251
+		foreach ($this->unique_indexes() as $index_name => $index) {
2252 2252
 			$uniqueness_where_params = array_intersect_key($field_n_values, $index->fields());
2253
-			if($this->exists(array($uniqueness_where_params))){
2254
-				EE_Error::add_error(sprintf(__("Could not %s %s. %s uniqueness index failed. Fields %s must form a unique set, but an entry already exists with values %s.", "event_espresso"),$action,$this->_get_class_name(),$index_name,implode(",",$index->field_names()),http_build_query($uniqueness_where_params)), __FILE__, __FUNCTION__, __LINE__ );
2253
+			if ($this->exists(array($uniqueness_where_params))) {
2254
+				EE_Error::add_error(sprintf(__("Could not %s %s. %s uniqueness index failed. Fields %s must form a unique set, but an entry already exists with values %s.", "event_espresso"), $action, $this->_get_class_name(), $index_name, implode(",", $index->field_names()), http_build_query($uniqueness_where_params)), __FILE__, __FUNCTION__, __LINE__);
2255 2255
 				return false;
2256 2256
 			}
2257 2257
 		}
@@ -2272,28 +2272,28 @@  discard block
 block discarded – undo
2272 2272
 	 * @throws EE_Error
2273 2273
 	 * @return EE_Base_Class
2274 2274
 	 */
2275
-	public function get_one_conflicting($obj_or_fields_array, $include_primary_key = true ){
2276
-		if($obj_or_fields_array instanceof EE_Base_Class){
2275
+	public function get_one_conflicting($obj_or_fields_array, $include_primary_key = true) {
2276
+		if ($obj_or_fields_array instanceof EE_Base_Class) {
2277 2277
 			$fields_n_values = $obj_or_fields_array->model_field_array();
2278
-		}elseif( is_array($obj_or_fields_array)){
2278
+		}elseif (is_array($obj_or_fields_array)) {
2279 2279
 			$fields_n_values = $obj_or_fields_array;
2280
-		}else{
2281
-			throw new EE_Error(sprintf(__("%s get_all_conflicting should be called with a model object or an array of field names and values, you provided %d", "event_espresso"),get_class($this),$obj_or_fields_array));
2280
+		} else {
2281
+			throw new EE_Error(sprintf(__("%s get_all_conflicting should be called with a model object or an array of field names and values, you provided %d", "event_espresso"), get_class($this), $obj_or_fields_array));
2282 2282
 		}
2283 2283
 		$query_params = array();
2284
-		if( $this->has_primary_key_field() &&
2285
-				( $include_primary_key || $this->get_primary_key_field() instanceof EE_Primary_Key_String_Field) &&
2286
-				isset($fields_n_values[$this->primary_key_name()])){
2284
+		if ($this->has_primary_key_field() &&
2285
+				($include_primary_key || $this->get_primary_key_field() instanceof EE_Primary_Key_String_Field) &&
2286
+				isset($fields_n_values[$this->primary_key_name()])) {
2287 2287
 			$query_params[0]['OR'][$this->primary_key_name()] = $fields_n_values[$this->primary_key_name()];
2288 2288
 		}
2289
-		foreach($this->unique_indexes() as $unique_index_name=>$unique_index){
2289
+		foreach ($this->unique_indexes() as $unique_index_name=>$unique_index) {
2290 2290
 			$uniqueness_where_params = array_intersect_key($fields_n_values, $unique_index->fields());
2291 2291
 			$query_params[0]['OR']['AND*'.$unique_index_name] = $uniqueness_where_params;
2292 2292
 		}
2293 2293
 		//if there is nothing to base this search on, then we shouldn't find anything
2294
-		if( empty( $query_params ) ){
2294
+		if (empty($query_params)) {
2295 2295
 			return array();
2296
-		}else{
2296
+		} else {
2297 2297
 			return $this->get_one($query_params);
2298 2298
 		}
2299 2299
 	}
@@ -2303,7 +2303,7 @@  discard block
 block discarded – undo
2303 2303
 	 * @param array $query_params
2304 2304
 	 * @return boolean
2305 2305
 	 */
2306
-	function exists($query_params){
2306
+	function exists($query_params) {
2307 2307
 		$query_params['limit'] = 1;
2308 2308
 		return $this->count($query_params) > 0;
2309 2309
 	}
@@ -2313,7 +2313,7 @@  discard block
 block discarded – undo
2313 2313
 	 * @param int|string $id
2314 2314
 	 * @return boolean
2315 2315
 	 */
2316
-	function exists_by_ID($id){
2316
+	function exists_by_ID($id) {
2317 2317
 		return $this->exists(array('default_where_conditions'=>'none', array($this->primary_key_name() => $id)));
2318 2318
 	}
2319 2319
 
@@ -2333,45 +2333,45 @@  discard block
 block discarded – undo
2333 2333
 	 * @global WPDB $wpdb only used to get the $wpdb->insert_id after performing an insert
2334 2334
 	 * @return int ID of new row inserted, or FALSE on failure
2335 2335
 	 */
2336
-	protected function _insert_into_specific_table(EE_Table_Base $table, $fields_n_values, $new_id = 0 ){
2336
+	protected function _insert_into_specific_table(EE_Table_Base $table, $fields_n_values, $new_id = 0) {
2337 2337
 		global $wpdb;
2338 2338
 		$insertion_col_n_values = array();
2339 2339
 		$format_for_insertion = array();
2340 2340
 		$fields_on_table = $this->_get_fields_for_table($table->get_table_alias());
2341
-		foreach($fields_on_table as $field_name => $field_obj){
2341
+		foreach ($fields_on_table as $field_name => $field_obj) {
2342 2342
 			//check if its an auto-incrementing column, in which case we should just leave it to do its autoincrement thing
2343
-			if($field_obj->is_auto_increment()){
2343
+			if ($field_obj->is_auto_increment()) {
2344 2344
 				continue;
2345 2345
 			}
2346 2346
 			$prepared_value = $this->_prepare_value_or_use_default($field_obj, $fields_n_values);
2347 2347
 			//if the value we want to assign it to is NULL, just don't mention it for the insertion
2348
-			if( $prepared_value !== NULL ){
2349
-				$insertion_col_n_values[ $field_obj->get_table_column() ] = $prepared_value;
2348
+			if ($prepared_value !== NULL) {
2349
+				$insertion_col_n_values[$field_obj->get_table_column()] = $prepared_value;
2350 2350
 				$format_for_insertion[] = $field_obj->get_wpdb_data_type();
2351 2351
 			}
2352 2352
 		}
2353 2353
 
2354
-		if($table instanceof EE_Secondary_Table && $new_id){
2354
+		if ($table instanceof EE_Secondary_Table && $new_id) {
2355 2355
 			//its not the main table, so we should have already saved the main table's PK which we just inserted
2356 2356
 			//so add the fk to the main table as a column
2357 2357
 			$insertion_col_n_values[$table->get_fk_on_table()] = $new_id;
2358
-			$format_for_insertion[]='%d';//yes right now we're only allowing these foreign keys to be INTs
2358
+			$format_for_insertion[] = '%d'; //yes right now we're only allowing these foreign keys to be INTs
2359 2359
 		}
2360 2360
 		//insert the new entry
2361
-		$result = $this->_do_wpdb_query( 'insert', array( $table->get_table_name(), $insertion_col_n_values, $format_for_insertion ) );
2362
-		if( $result === false ) {
2361
+		$result = $this->_do_wpdb_query('insert', array($table->get_table_name(), $insertion_col_n_values, $format_for_insertion));
2362
+		if ($result === false) {
2363 2363
 			return false;
2364 2364
 		}
2365 2365
 		//ok, now what do we return for the ID of the newly-inserted thing?
2366
-		if($this->has_primary_key_field()){
2367
-			if($this->get_primary_key_field()->is_auto_increment()){
2366
+		if ($this->has_primary_key_field()) {
2367
+			if ($this->get_primary_key_field()->is_auto_increment()) {
2368 2368
 				return $wpdb->insert_id;
2369
-			}else{
2369
+			} else {
2370 2370
 				//it's not an auto-increment primary key, so
2371 2371
 				//it must have been supplied
2372 2372
 				return $fields_n_values[$this->get_primary_key_field()->get_name()];
2373 2373
 			}
2374
-		}else{
2374
+		} else {
2375 2375
 			//we can't return a  primary key because there is none. instead return
2376 2376
 			//a unique string indicating this model
2377 2377
 			return $this->get_index_primary_key_string($fields_n_values);
@@ -2386,15 +2386,15 @@  discard block
 block discarded – undo
2386 2386
 	 * @param array $fields_n_values
2387 2387
 	 * @return mixed string|int|float depending on what the table column will be expecting
2388 2388
 	 */
2389
-	protected function _prepare_value_or_use_default( $field_obj, $fields_n_values ){
2389
+	protected function _prepare_value_or_use_default($field_obj, $fields_n_values) {
2390 2390
 		//if this field doesn't allow nullable, don't allow it
2391
-		if( ! $field_obj->is_nullable() && (
2392
-				! isset( $fields_n_values[ $field_obj->get_name() ] ) ||
2393
-				$fields_n_values[ $field_obj->get_name() ] === NULL ) ){
2394
-			$fields_n_values[ $field_obj->get_name() ] = $field_obj->get_default_value();
2391
+		if ( ! $field_obj->is_nullable() && (
2392
+				! isset($fields_n_values[$field_obj->get_name()]) ||
2393
+				$fields_n_values[$field_obj->get_name()] === NULL )) {
2394
+			$fields_n_values[$field_obj->get_name()] = $field_obj->get_default_value();
2395 2395
 		}
2396
-		$unprepared_value = isset( $fields_n_values[ $field_obj->get_name() ] ) ? $fields_n_values[ $field_obj->get_name() ] : NULL;
2397
-		return $this->_prepare_value_for_use_in_db( $unprepared_value, $field_obj);
2396
+		$unprepared_value = isset($fields_n_values[$field_obj->get_name()]) ? $fields_n_values[$field_obj->get_name()] : NULL;
2397
+		return $this->_prepare_value_for_use_in_db($unprepared_value, $field_obj);
2398 2398
 	}
2399 2399
 
2400 2400
 
@@ -2406,9 +2406,9 @@  discard block
 block discarded – undo
2406 2406
 	 * @param EE_Model_Field_Base $field field which will be doing the preparing of the value. If null, we assume $value is a custom selection
2407 2407
 	 * @return mixed a value ready for use in the database for insertions, updating, or in a where clause
2408 2408
 	 */
2409
-	private function _prepare_value_for_use_in_db($value, $field){
2410
-		if($field && $field instanceof EE_Model_Field_Base){
2411
-			switch( $this->_values_already_prepared_by_model_object ){
2409
+	private function _prepare_value_for_use_in_db($value, $field) {
2410
+		if ($field && $field instanceof EE_Model_Field_Base) {
2411
+			switch ($this->_values_already_prepared_by_model_object) {
2412 2412
 				/** @noinspection PhpMissingBreakStatementInspection */
2413 2413
 				case self::not_prepared_by_model_object:
2414 2414
 					$value = $field->prepare_for_set($value);
@@ -2419,7 +2419,7 @@  discard block
 block discarded – undo
2419 2419
 					//leave the value alone
2420 2420
 			}
2421 2421
 			return $value;
2422
-		}else{
2422
+		} else {
2423 2423
 			return $value;
2424 2424
 		}
2425 2425
 	}
@@ -2429,13 +2429,13 @@  discard block
 block discarded – undo
2429 2429
 	 * @return EE_Primary_Table
2430 2430
 	 * @throws EE_Error
2431 2431
 	 */
2432
-	protected function _get_main_table(){
2433
-		foreach($this->_tables as $table){
2434
-			if($table instanceof EE_Primary_Table){
2432
+	protected function _get_main_table() {
2433
+		foreach ($this->_tables as $table) {
2434
+			if ($table instanceof EE_Primary_Table) {
2435 2435
 				return $table;
2436 2436
 			}
2437 2437
 		}
2438
-		throw new EE_Error(sprintf(__('There are no main tables on %s. They should be added to _tables array in the constructor','event_espresso'),get_class($this)));
2438
+		throw new EE_Error(sprintf(__('There are no main tables on %s. They should be added to _tables array in the constructor', 'event_espresso'), get_class($this)));
2439 2439
 	}
2440 2440
 
2441 2441
 	/**
@@ -2454,7 +2454,7 @@  discard block
 block discarded – undo
2454 2454
 	 */
2455 2455
 	public function second_table() {
2456 2456
 		// grab second table from tables array
2457
-		$second_table = end( $this->_tables );
2457
+		$second_table = end($this->_tables);
2458 2458
 		return $second_table instanceof EE_Secondary_Table ? $second_table->get_table_name() : NULL;
2459 2459
 	}
2460 2460
 
@@ -2467,8 +2467,8 @@  discard block
 block discarded – undo
2467 2467
 	 * @param string $table_alias
2468 2468
 	 * @return EE_Primary_Table | EE_Secondary_Table
2469 2469
 	 */
2470
-	public function get_table_obj_by_alias( $table_alias = '' ) {
2471
-		return isset( $this->_tables[ $table_alias ] ) ? $this->_tables[ $table_alias ] : NULL;
2470
+	public function get_table_obj_by_alias($table_alias = '') {
2471
+		return isset($this->_tables[$table_alias]) ? $this->_tables[$table_alias] : NULL;
2472 2472
 	}
2473 2473
 
2474 2474
 
@@ -2477,10 +2477,10 @@  discard block
 block discarded – undo
2477 2477
 	 * Gets all the tables of type EE_Other_Table from EEM_CPT_Basel_Model::_tables
2478 2478
 	 * @return EE_Secondary_Table[]
2479 2479
 	 */
2480
-	protected function _get_other_tables(){
2481
-		$other_tables =array();
2482
-		foreach($this->_tables as $table_alias => $table){
2483
-			if($table instanceof EE_Secondary_Table){
2480
+	protected function _get_other_tables() {
2481
+		$other_tables = array();
2482
+		foreach ($this->_tables as $table_alias => $table) {
2483
+			if ($table instanceof EE_Secondary_Table) {
2484 2484
 				$other_tables[$table_alias] = $table;
2485 2485
 			}
2486 2486
 		}
@@ -2492,7 +2492,7 @@  discard block
 block discarded – undo
2492 2492
 	 * @param string $table_alias, array key in EEM_Base::_tables
2493 2493
 	 * @return EE_Model_Field_Base[]
2494 2494
 	 */
2495
-	function _get_fields_for_table($table_alias){
2495
+	function _get_fields_for_table($table_alias) {
2496 2496
 		return $this->_fields[$table_alias];
2497 2497
 	}
2498 2498
 
@@ -2504,29 +2504,29 @@  discard block
 block discarded – undo
2504 2504
 	 * @param array $query_params like EEM_Base::get_all's $query_parameters['where']
2505 2505
 	 * @return EE_Model_Query_Info_Carrier
2506 2506
 	 */
2507
-	function _extract_related_models_from_query($query_params){
2507
+	function _extract_related_models_from_query($query_params) {
2508 2508
 		$query_info_carrier = new EE_Model_Query_Info_Carrier();
2509
-		if(array_key_exists(0,$query_params)){
2510
-			$this->_extract_related_models_from_sub_params_array_keys($query_params[0], $query_info_carrier,0);
2511
-		}
2512
-		if(array_key_exists('group_by', $query_params)){
2513
-			if(is_array($query_params['group_by'])){
2514
-				$this->_extract_related_models_from_sub_params_array_values($query_params['group_by'],$query_info_carrier,'group_by');
2515
-			}elseif( ! empty ( $query_params['group_by'] )){
2516
-				$this->_extract_related_model_info_from_query_param( $query_params['group_by'],$query_info_carrier,'group_by');
2509
+		if (array_key_exists(0, $query_params)) {
2510
+			$this->_extract_related_models_from_sub_params_array_keys($query_params[0], $query_info_carrier, 0);
2511
+		}
2512
+		if (array_key_exists('group_by', $query_params)) {
2513
+			if (is_array($query_params['group_by'])) {
2514
+				$this->_extract_related_models_from_sub_params_array_values($query_params['group_by'], $query_info_carrier, 'group_by');
2515
+			}elseif ( ! empty ($query_params['group_by'])) {
2516
+				$this->_extract_related_model_info_from_query_param($query_params['group_by'], $query_info_carrier, 'group_by');
2517 2517
 			}
2518 2518
 		}
2519
-		if(array_key_exists('having',$query_params)){
2520
-			$this->_extract_related_models_from_sub_params_array_keys($query_params[0], $query_info_carrier,'having');
2519
+		if (array_key_exists('having', $query_params)) {
2520
+			$this->_extract_related_models_from_sub_params_array_keys($query_params[0], $query_info_carrier, 'having');
2521 2521
 		}
2522
-		if(array_key_exists('order_by', $query_params)){
2523
-			if ( is_array( $query_params['order_by'] ) )
2524
-				$this->_extract_related_models_from_sub_params_array_keys($query_params['order_by'],$query_info_carrier,'order_by');
2525
-			elseif( ! empty( $query_params['order_by'] ))
2526
-				$this->_extract_related_model_info_from_query_param( $query_params['order_by'], $query_info_carrier,'order_by');
2522
+		if (array_key_exists('order_by', $query_params)) {
2523
+			if (is_array($query_params['order_by']))
2524
+				$this->_extract_related_models_from_sub_params_array_keys($query_params['order_by'], $query_info_carrier, 'order_by');
2525
+			elseif ( ! empty($query_params['order_by']))
2526
+				$this->_extract_related_model_info_from_query_param($query_params['order_by'], $query_info_carrier, 'order_by');
2527 2527
 		}
2528
-		if(array_key_exists('force_join', $query_params)){
2529
-			$this->_extract_related_models_from_sub_params_array_values($query_params['force_join'],$query_info_carrier,'force_join');
2528
+		if (array_key_exists('force_join', $query_params)) {
2529
+			$this->_extract_related_models_from_sub_params_array_values($query_params['force_join'], $query_info_carrier, 'force_join');
2530 2530
 		}
2531 2531
 		return $query_info_carrier;
2532 2532
 	}
@@ -2539,34 +2539,34 @@  discard block
 block discarded – undo
2539 2539
 	 * @throws EE_Error
2540 2540
 	 * @return \EE_Model_Query_Info_Carrier
2541 2541
 	 */
2542
-	private function _extract_related_models_from_sub_params_array_keys($sub_query_params, EE_Model_Query_Info_Carrier $model_query_info_carrier,$query_param_type){
2543
-		if (!empty($sub_query_params)){
2542
+	private function _extract_related_models_from_sub_params_array_keys($sub_query_params, EE_Model_Query_Info_Carrier $model_query_info_carrier, $query_param_type) {
2543
+		if ( ! empty($sub_query_params)) {
2544 2544
 			$sub_query_params = (array) $sub_query_params;
2545
-			foreach($sub_query_params as $param => $possibly_array_of_params){
2545
+			foreach ($sub_query_params as $param => $possibly_array_of_params) {
2546 2546
 				//$param could be simply 'EVT_ID', or it could be 'Registrations.REG_ID', or even 'Registrations.Transactions.Payments.PAY_amount'
2547
-				$this->_extract_related_model_info_from_query_param( $param, $model_query_info_carrier,$query_param_type);
2547
+				$this->_extract_related_model_info_from_query_param($param, $model_query_info_carrier, $query_param_type);
2548 2548
 
2549 2549
 				//if $possibly_array_of_params is an array, try recursing into it, searching for keys which
2550 2550
 				//indicate needed joins. Eg, array('NOT'=>array('Registration.TXN_ID'=>23)). In this case, we tried
2551 2551
 				//extracting models out of the 'NOT', which obviously wasn't successful, and then we recurse into the value
2552 2552
 				//of array('Registration.TXN_ID'=>23)
2553 2553
 				$query_param_sans_stars = $this->_remove_stars_and_anything_after_from_condition_query_param_key($param);
2554
-				if(in_array($query_param_sans_stars, $this->_logic_query_param_keys,true)){
2555
-					if (! is_array($possibly_array_of_params)){
2554
+				if (in_array($query_param_sans_stars, $this->_logic_query_param_keys, true)) {
2555
+					if ( ! is_array($possibly_array_of_params)) {
2556 2556
 						throw new EE_Error(sprintf(__("You used a special where query param %s, but the value isn't an array of where query params, it's just %s'. It should be an array, eg array('EVT_ID'=>23,'OR'=>array('Venue.VNU_ID'=>32,'Venue.VNU_name'=>'monkey_land'))", "event_espresso"),
2557
-							$param,$possibly_array_of_params));
2558
-					}else{
2559
-						$this->_extract_related_models_from_sub_params_array_keys($possibly_array_of_params, $model_query_info_carrier,$query_param_type);
2557
+							$param, $possibly_array_of_params));
2558
+					} else {
2559
+						$this->_extract_related_models_from_sub_params_array_keys($possibly_array_of_params, $model_query_info_carrier, $query_param_type);
2560 2560
 					}
2561
-				}elseif($query_param_type === 0 //ie WHERE
2561
+				}elseif ($query_param_type === 0 //ie WHERE
2562 2562
 						&& is_array($possibly_array_of_params)
2563 2563
 						&& isset($possibly_array_of_params[2])
2564
-						&& $possibly_array_of_params[2] == true){
2564
+						&& $possibly_array_of_params[2] == true) {
2565 2565
 					//then $possible_array_of_params looks something like array('<','DTT_sold',true)
2566 2566
 					//indicating that $possible_array_of_params[1] is actually a field name,
2567 2567
 					//from which we should extract query parameters!
2568
-					if(! isset($possibly_array_of_params[0]) || ! isset($possibly_array_of_params[1])){
2569
-						throw new EE_Error(sprintf(__("Improperly formed query parameter %s. It should be numerically indexed like array('<','DTT_sold',true); but you provided %s", "event_espresso"),$query_param_type,implode(",",$possibly_array_of_params)));
2568
+					if ( ! isset($possibly_array_of_params[0]) || ! isset($possibly_array_of_params[1])) {
2569
+						throw new EE_Error(sprintf(__("Improperly formed query parameter %s. It should be numerically indexed like array('<','DTT_sold',true); but you provided %s", "event_espresso"), $query_param_type, implode(",", $possibly_array_of_params)));
2570 2570
 					}
2571 2571
 					$this->_extract_related_model_info_from_query_param($possibly_array_of_params[1], $model_query_info_carrier, $query_param_type);
2572 2572
 				}
@@ -2585,14 +2585,14 @@  discard block
 block discarded – undo
2585 2585
 	 * @throws EE_Error
2586 2586
 	 * @return \EE_Model_Query_Info_Carrier
2587 2587
 	 */
2588
-	private function _extract_related_models_from_sub_params_array_values($sub_query_params, EE_Model_Query_Info_Carrier $model_query_info_carrier,$query_param_type){
2589
-		if (!empty($sub_query_params)){
2590
-			if(!is_array($sub_query_params)){
2591
-				throw new EE_Error(sprintf(__("Query parameter %s should be an array, but it isn't.", "event_espresso"),$sub_query_params));
2588
+	private function _extract_related_models_from_sub_params_array_values($sub_query_params, EE_Model_Query_Info_Carrier $model_query_info_carrier, $query_param_type) {
2589
+		if ( ! empty($sub_query_params)) {
2590
+			if ( ! is_array($sub_query_params)) {
2591
+				throw new EE_Error(sprintf(__("Query parameter %s should be an array, but it isn't.", "event_espresso"), $sub_query_params));
2592 2592
 			}
2593
-			foreach($sub_query_params as $param){
2593
+			foreach ($sub_query_params as $param) {
2594 2594
 				//$param could be simply 'EVT_ID', or it could be 'Registrations.REG_ID', or even 'Registrations.Transactions.Payments.PAY_amount'
2595
-				$this->_extract_related_model_info_from_query_param( $param, $model_query_info_carrier, $query_param_type);
2595
+				$this->_extract_related_model_info_from_query_param($param, $model_query_info_carrier, $query_param_type);
2596 2596
 			}
2597 2597
 		}
2598 2598
 		return $model_query_info_carrier;
@@ -2611,81 +2611,81 @@  discard block
 block discarded – undo
2611 2611
 	 * @throws EE_Error
2612 2612
 	 * @return EE_Model_Query_Info_Carrier
2613 2613
 	 */
2614
-	function _create_model_query_info_carrier($query_params){
2615
-		if( ! is_array( $query_params ) ){
2616
-			EE_Error::doing_it_wrong('EEM_Base::_create_model_query_info_carrier', sprintf( __( '$query_params should be an array, you passed a variable of type %s', 'event_espresso' ), gettype( $query_params ) ), '4.6.0' );
2614
+	function _create_model_query_info_carrier($query_params) {
2615
+		if ( ! is_array($query_params)) {
2616
+			EE_Error::doing_it_wrong('EEM_Base::_create_model_query_info_carrier', sprintf(__('$query_params should be an array, you passed a variable of type %s', 'event_espresso'), gettype($query_params)), '4.6.0');
2617 2617
 			$query_params = array();
2618 2618
 		}
2619
-		if( isset( $query_params[0] ) ) {
2619
+		if (isset($query_params[0])) {
2620 2620
 			$where_query_params = $query_params[0];
2621
-		}else{
2621
+		} else {
2622 2622
 			$where_query_params = array();
2623 2623
 		}
2624 2624
 		//first check if we should alter the query to account for caps or not
2625 2625
 		//because the caps might require us to do extra joins
2626
-		if( isset( $query_params[ 'caps' ] ) && $query_params[ 'caps' ] != 'none' ) {
2627
-			$query_params[0] = $where_query_params = array_replace_recursive( $where_query_params, $this->caps_where_conditions( $query_params[ 'caps' ] ) );
2626
+		if (isset($query_params['caps']) && $query_params['caps'] != 'none') {
2627
+			$query_params[0] = $where_query_params = array_replace_recursive($where_query_params, $this->caps_where_conditions($query_params['caps']));
2628 2628
 		}
2629 2629
 		$query_object = $this->_extract_related_models_from_query($query_params);
2630 2630
 
2631 2631
 		//verify where_query_params has NO numeric indexes.... that's simply not how you use it!
2632
-		foreach($where_query_params as $key => $value){
2633
-			if(is_int($key)){
2634
-				throw new EE_Error(sprintf(__("WHERE query params must NOT be numerically-indexed. You provided the array key '%s' for value '%s' while querying model %s. All the query params provided were '%s' Please read documentation on EEM_Base::get_all.", "event_espresso"),$key, var_export( $value, true ), var_export( $query_params, true ), get_class($this)));
2632
+		foreach ($where_query_params as $key => $value) {
2633
+			if (is_int($key)) {
2634
+				throw new EE_Error(sprintf(__("WHERE query params must NOT be numerically-indexed. You provided the array key '%s' for value '%s' while querying model %s. All the query params provided were '%s' Please read documentation on EEM_Base::get_all.", "event_espresso"), $key, var_export($value, true), var_export($query_params, true), get_class($this)));
2635 2635
 			}
2636 2636
 		}
2637
-		if( array_key_exists( 'default_where_conditions',$query_params) && ! empty( $query_params['default_where_conditions'] )){
2637
+		if (array_key_exists('default_where_conditions', $query_params) && ! empty($query_params['default_where_conditions'])) {
2638 2638
 			$use_default_where_conditions = $query_params['default_where_conditions'];
2639
-		}else{
2639
+		} else {
2640 2640
 			$use_default_where_conditions = 'all';
2641 2641
 		}
2642
-		$where_query_params = array_merge($this->_get_default_where_conditions_for_models_in_query($query_object,$use_default_where_conditions,$where_query_params), $where_query_params );
2643
-		$query_object->set_where_sql( $this->_construct_where_clause($where_query_params));
2642
+		$where_query_params = array_merge($this->_get_default_where_conditions_for_models_in_query($query_object, $use_default_where_conditions, $where_query_params), $where_query_params);
2643
+		$query_object->set_where_sql($this->_construct_where_clause($where_query_params));
2644 2644
 
2645 2645
 
2646 2646
 		//if this is a "on_join_limit" then we are limiting on on a specific table in a multi_table join.  So we need to setup a subquery and use that for the main join.  Note for now this only works on the primary table for the model.  So for instance, you could set the limit array like this:
2647 2647
 		//array( 'on_join_limit' => array('Primary_Table_Alias', array(1,10) ) )
2648
-		if ( array_key_exists('on_join_limit', $query_params ) && ! empty( $query_params['on_join_limit'] )) {
2649
-			$query_object->set_main_model_join_sql( $this->_construct_limit_join_select( $query_params['on_join_limit'][0], $query_params['on_join_limit'][1] ) );
2648
+		if (array_key_exists('on_join_limit', $query_params) && ! empty($query_params['on_join_limit'])) {
2649
+			$query_object->set_main_model_join_sql($this->_construct_limit_join_select($query_params['on_join_limit'][0], $query_params['on_join_limit'][1]));
2650 2650
 		}
2651 2651
 
2652 2652
 
2653 2653
 		//set limit
2654
-		if(array_key_exists('limit',$query_params)){
2655
-			if(is_array($query_params['limit'])){
2656
-				if( ! isset($query_params['limit'][0]) || ! isset($query_params['limit'][1])){
2657
-					$e = sprintf(__("Invalid DB query. You passed '%s' for the LIMIT, but only the following are valid: an integer, string representing an integer, a string like 'int,int', or an array like array(int,int)", "event_espresso"),  http_build_query($query_params['limit']));
2654
+		if (array_key_exists('limit', $query_params)) {
2655
+			if (is_array($query_params['limit'])) {
2656
+				if ( ! isset($query_params['limit'][0]) || ! isset($query_params['limit'][1])) {
2657
+					$e = sprintf(__("Invalid DB query. You passed '%s' for the LIMIT, but only the following are valid: an integer, string representing an integer, a string like 'int,int', or an array like array(int,int)", "event_espresso"), http_build_query($query_params['limit']));
2658 2658
 					throw new EE_Error($e."|".$e);
2659 2659
 				}
2660 2660
 				//they passed us an array for the limit. Assume it's like array(50,25), meaning offset by 50, and get 25
2661 2661
 				$query_object->set_limit_sql(" LIMIT ".$query_params['limit'][0].",".$query_params['limit'][1]);
2662
-			}elseif( ! empty ( $query_params['limit'] )){
2662
+			}elseif ( ! empty ($query_params['limit'])) {
2663 2663
 				$query_object->set_limit_sql((" LIMIT ".$query_params['limit']));
2664 2664
 			}
2665 2665
 		}
2666 2666
 		//set order by
2667
-		if(array_key_exists('order_by',$query_params)){
2668
-			if(is_array($query_params['order_by'])){
2667
+		if (array_key_exists('order_by', $query_params)) {
2668
+			if (is_array($query_params['order_by'])) {
2669 2669
 				//if they're using 'order_by' as an array, they can't use 'order' (because 'order_by' must
2670 2670
 				//specify whether to ascend or descend on each field. Eg 'order_by'=>array('EVT_ID'=>'ASC'). So
2671 2671
 				//including 'order' wouldn't make any sense if 'order_by' has already specified which way to order!
2672
-				if(array_key_exists('order', $query_params)){
2672
+				if (array_key_exists('order', $query_params)) {
2673 2673
 					throw new EE_Error(sprintf(__("In querying %s, we are using query parameter 'order_by' as an array (keys:%s,values:%s), and so we can't use query parameter 'order' (value %s). You should just use the 'order_by' parameter ", "event_espresso"),
2674
-							get_class($this),implode(", ",array_keys($query_params['order_by'])),implode(", ",$query_params['order_by']),$query_params['order']));
2674
+							get_class($this), implode(", ", array_keys($query_params['order_by'])), implode(", ", $query_params['order_by']), $query_params['order']));
2675 2675
 				}
2676
-				 $this->_extract_related_models_from_sub_params_array_keys($query_params['order_by'],$query_object,'order_by');
2676
+				 $this->_extract_related_models_from_sub_params_array_keys($query_params['order_by'], $query_object, 'order_by');
2677 2677
 				//assume it's an array of fields to order by
2678 2678
 				$order_array = array();
2679
-				foreach($query_params['order_by'] as $field_name_to_order_by => $order){
2679
+				foreach ($query_params['order_by'] as $field_name_to_order_by => $order) {
2680 2680
 					$order = $this->_extract_order($order);
2681 2681
 					$order_array[] = $this->_deduce_column_name_from_query_param($field_name_to_order_by).SP.$order;
2682 2682
 				}
2683
-				$query_object->set_order_by_sql(" ORDER BY ".implode(",",$order_array));
2684
-			}elseif( ! empty ( $query_params['order_by'] )){
2685
-				$this->_extract_related_model_info_from_query_param($query_params['order_by'],$query_object,'order',$query_params['order_by']);
2686
-				if(isset($query_params['order'])){
2683
+				$query_object->set_order_by_sql(" ORDER BY ".implode(",", $order_array));
2684
+			}elseif ( ! empty ($query_params['order_by'])) {
2685
+				$this->_extract_related_model_info_from_query_param($query_params['order_by'], $query_object, 'order', $query_params['order_by']);
2686
+				if (isset($query_params['order'])) {
2687 2687
 					$order = $this->_extract_order($query_params['order']);
2688
-				}else{
2688
+				} else {
2689 2689
 					$order = 'DESC';
2690 2690
 				}
2691 2691
 				$query_object->set_order_by_sql(" ORDER BY ".$this->_deduce_column_name_from_query_param($query_params['order_by']).SP.$order);
@@ -2693,46 +2693,46 @@  discard block
 block discarded – undo
2693 2693
 		}
2694 2694
 
2695 2695
 		//if 'order_by' wasn't set, maybe they are just using 'order' on its own?
2696
-		if( ! array_key_exists('order_by',$query_params) && array_key_exists('order',$query_params) && ! empty( $query_params['order'] )){
2696
+		if ( ! array_key_exists('order_by', $query_params) && array_key_exists('order', $query_params) && ! empty($query_params['order'])) {
2697 2697
 			$pk_field = $this->get_primary_key_field();
2698 2698
 			$order = $this->_extract_order($query_params['order']);
2699 2699
 			$query_object->set_order_by_sql(" ORDER BY ".$pk_field->get_qualified_column().SP.$order);
2700 2700
 		}
2701 2701
 
2702 2702
 		//set group by
2703
-		if(array_key_exists('group_by',$query_params)){
2704
-			if(is_array($query_params['group_by'])){
2703
+		if (array_key_exists('group_by', $query_params)) {
2704
+			if (is_array($query_params['group_by'])) {
2705 2705
 				//it's an array, so assume we'll be grouping by a bunch of stuff
2706 2706
 				$group_by_array = array();
2707
-				foreach($query_params['group_by'] as $field_name_to_group_by){
2707
+				foreach ($query_params['group_by'] as $field_name_to_group_by) {
2708 2708
 					$group_by_array[] = $this->_deduce_column_name_from_query_param($field_name_to_group_by);
2709 2709
 				}
2710
-				$query_object->set_group_by_sql(" GROUP BY ".implode(", ",$group_by_array));
2711
-			}elseif( ! empty ( $query_params['group_by'] )){
2710
+				$query_object->set_group_by_sql(" GROUP BY ".implode(", ", $group_by_array));
2711
+			}elseif ( ! empty ($query_params['group_by'])) {
2712 2712
 				$query_object->set_group_by_sql(" GROUP BY ".$this->_deduce_column_name_from_query_param($query_params['group_by']));
2713 2713
 			}
2714 2714
 		}
2715 2715
 		//set having
2716
-		if(array_key_exists('having',$query_params) && $query_params['having']){
2717
-			$query_object->set_having_sql( $this->_construct_having_clause($query_params['having']));
2716
+		if (array_key_exists('having', $query_params) && $query_params['having']) {
2717
+			$query_object->set_having_sql($this->_construct_having_clause($query_params['having']));
2718 2718
 		}
2719 2719
 
2720 2720
 		//now, just verify they didn't pass anything wack
2721
-		foreach($query_params as $query_key => $query_value){
2722
-			if( ! in_array($query_key,$this->_allowed_query_params,true)){
2721
+		foreach ($query_params as $query_key => $query_value) {
2722
+			if ( ! in_array($query_key, $this->_allowed_query_params, true)) {
2723 2723
 				throw new EE_Error(
2724 2724
 					sprintf(
2725
-						__("You passed %s as a query parameter to %s, which is illegal! The allowed query parameters are %s",'event_espresso'),
2725
+						__("You passed %s as a query parameter to %s, which is illegal! The allowed query parameters are %s", 'event_espresso'),
2726 2726
 						$query_key,
2727 2727
 						get_class($this),
2728 2728
 //						print_r( $this->_allowed_query_params, TRUE )
2729
-						implode( ',', $this->_allowed_query_params )
2729
+						implode(',', $this->_allowed_query_params)
2730 2730
 					)
2731 2731
 				);
2732 2732
 			}
2733 2733
 		}
2734 2734
 		$main_model_join_sql = $query_object->get_main_model_join_sql();
2735
-		if ( empty( $main_model_join_sql ) )
2735
+		if (empty($main_model_join_sql))
2736 2736
 			$query_object->set_main_model_join_sql($this->_construct_internal_join());
2737 2737
 		return $query_object;
2738 2738
 	}
@@ -2743,17 +2743,17 @@  discard block
 block discarded – undo
2743 2743
 	 * @param string $context one of EEM_Base::valid_cap_contexts()
2744 2744
 	 * @return array like EEM_Base::get_all() 's $query_params[0]
2745 2745
 	 */
2746
-	public function caps_where_conditions( $context = self::caps_read ) {
2747
-		EEM_Base::verify_is_valid_cap_context( $context );
2746
+	public function caps_where_conditions($context = self::caps_read) {
2747
+		EEM_Base::verify_is_valid_cap_context($context);
2748 2748
 		$cap_where_conditions = array();
2749
-		$cap_restrictions = $this->caps_missing( $context );
2749
+		$cap_restrictions = $this->caps_missing($context);
2750 2750
 		/**
2751 2751
 		 * @var $cap_restrictions EE_Default_Where_Conditions[]
2752 2752
 		 */
2753
-		foreach( $cap_restrictions as $cap => $restriction_if_no_cap ) {
2754
-				$cap_where_conditions = array_replace_recursive( $cap_where_conditions, $restriction_if_no_cap->get_default_where_conditions() );
2753
+		foreach ($cap_restrictions as $cap => $restriction_if_no_cap) {
2754
+				$cap_where_conditions = array_replace_recursive($cap_where_conditions, $restriction_if_no_cap->get_default_where_conditions());
2755 2755
 		}
2756
-		return apply_filters( 'FHEE__EEM_Base__caps_where_conditions__return', $cap_where_conditions, $this, $context, $cap_restrictions );
2756
+		return apply_filters('FHEE__EEM_Base__caps_where_conditions__return', $cap_where_conditions, $this, $context, $cap_restrictions);
2757 2757
 	}
2758 2758
 
2759 2759
 	/**
@@ -2763,11 +2763,11 @@  discard block
 block discarded – undo
2763 2763
 	 * @return string either ASC, asc, DESC or desc
2764 2764
 	 * @throws EE_Error
2765 2765
 	 */
2766
-	private function _extract_order($should_be_order_string){
2767
-		if(in_array($should_be_order_string, $this->_allowed_order_values)){
2766
+	private function _extract_order($should_be_order_string) {
2767
+		if (in_array($should_be_order_string, $this->_allowed_order_values)) {
2768 2768
 			return $should_be_order_string;
2769
-		}else{
2770
-			throw new EE_Error(sprintf(__("While performing a query on '%s', tried to use '%s' as an order parameter. ", "event_espresso"),get_class($this),$should_be_order_string));
2769
+		} else {
2770
+			throw new EE_Error(sprintf(__("While performing a query on '%s', tried to use '%s' as an order parameter. ", "event_espresso"), get_class($this), $should_be_order_string));
2771 2771
 		}
2772 2772
 	}
2773 2773
 
@@ -2785,7 +2785,7 @@  discard block
 block discarded – undo
2785 2785
 	 * @throws EE_Error
2786 2786
 	 * @return array like $query_params[0], see EEM_Base::get_all for documentation
2787 2787
 	 */
2788
-	private function _get_default_where_conditions_for_models_in_query(EE_Model_Query_Info_Carrier $query_info_carrier,$use_default_where_conditions = 'all',$where_query_params = array()){
2788
+	private function _get_default_where_conditions_for_models_in_query(EE_Model_Query_Info_Carrier $query_info_carrier, $use_default_where_conditions = 'all', $where_query_params = array()) {
2789 2789
 		$allowed_used_default_where_conditions_values = array(
2790 2790
 				'all',
2791 2791
 				'this_model_only',
@@ -2793,19 +2793,19 @@  discard block
 block discarded – undo
2793 2793
 				'minimum',
2794 2794
 				'none'
2795 2795
 			);
2796
-		if( ! in_array($use_default_where_conditions,$allowed_used_default_where_conditions_values)){
2797
-			throw new EE_Error(sprintf(__("You passed an invalid value to the query parameter 'default_where_conditions' of '%s'. Allowed values are %s", "event_espresso"),$use_default_where_conditions,implode(", ",$allowed_used_default_where_conditions_values)));
2796
+		if ( ! in_array($use_default_where_conditions, $allowed_used_default_where_conditions_values)) {
2797
+			throw new EE_Error(sprintf(__("You passed an invalid value to the query parameter 'default_where_conditions' of '%s'. Allowed values are %s", "event_espresso"), $use_default_where_conditions, implode(", ", $allowed_used_default_where_conditions_values)));
2798 2798
 		}
2799
-		if( in_array($use_default_where_conditions, array('all','this_model_only')) ){
2799
+		if (in_array($use_default_where_conditions, array('all', 'this_model_only'))) {
2800 2800
 			$universal_query_params = $this->_get_default_where_conditions();
2801
-		}elseif( in_array( $use_default_where_conditions, array( 'minimum' ) ) ) {
2801
+		}elseif (in_array($use_default_where_conditions, array('minimum'))) {
2802 2802
 			$universal_query_params = $this->_get_minimum_where_conditions();
2803
-		}else{
2803
+		} else {
2804 2804
 			$universal_query_params = array();
2805 2805
 		}
2806 2806
 
2807
-		if(in_array($use_default_where_conditions,array('all','other_models_only'))){
2808
-			foreach($query_info_carrier->get_model_names_included() as $model_relation_path => $model_name){
2807
+		if (in_array($use_default_where_conditions, array('all', 'other_models_only'))) {
2808
+			foreach ($query_info_carrier->get_model_names_included() as $model_relation_path => $model_name) {
2809 2809
 				$related_model = $this->get_related_model_obj($model_name);
2810 2810
 				$related_model_universal_where_params = $related_model->_get_default_where_conditions($model_relation_path);
2811 2811
 
@@ -2832,22 +2832,22 @@  discard block
 block discarded – undo
2832 2832
 	 * @param string $model_relation_path like 'Transaction.Payment.'
2833 2833
 	 * @return array like EEM_Base::get_all's $query_params[0]
2834 2834
 	 */
2835
-	private function _override_defaults_or_make_null_friendly($default_where_conditions,$provided_where_conditions,$model,$model_relation_path){
2835
+	private function _override_defaults_or_make_null_friendly($default_where_conditions, $provided_where_conditions, $model, $model_relation_path) {
2836 2836
 		$null_friendly_where_conditions = array();
2837 2837
 		$none_overridden = true;
2838 2838
 		$or_condition_key_for_defaults = 'OR*'.get_class($model);
2839 2839
 
2840
-		foreach($default_where_conditions as $key => $val){
2841
-			if( isset($provided_where_conditions[$key])){
2840
+		foreach ($default_where_conditions as $key => $val) {
2841
+			if (isset($provided_where_conditions[$key])) {
2842 2842
 				$none_overridden = false;
2843
-			}else{
2843
+			} else {
2844 2844
 				$null_friendly_where_conditions[$or_condition_key_for_defaults]['AND'][$key] = $val;
2845 2845
 			}
2846 2846
 		}
2847
-		if( $none_overridden && $default_where_conditions){
2848
-			if($model->has_primary_key_field()){
2847
+		if ($none_overridden && $default_where_conditions) {
2848
+			if ($model->has_primary_key_field()) {
2849 2849
 				$null_friendly_where_conditions[$or_condition_key_for_defaults][$model_relation_path.".".$model->primary_key_name()] = array('IS NULL');
2850
-			}else{
2850
+			} else {
2851 2851
 				//@todo NO PK, use other defaults
2852 2852
 			}
2853 2853
 		}
@@ -2862,8 +2862,8 @@  discard block
 block discarded – undo
2862 2862
 	 * @param string $model_relation_path eg, path from Event to Payment is "Registration.Transaction.Payment."
2863 2863
 	 * @return array like EEM_Base::get_all's $query_params[0] (where conditions)
2864 2864
 	 */
2865
-	private function _get_default_where_conditions($model_relation_path = null){
2866
-		if ( $this->_ignore_where_strategy )
2865
+	private function _get_default_where_conditions($model_relation_path = null) {
2866
+		if ($this->_ignore_where_strategy)
2867 2867
 			return array();
2868 2868
 
2869 2869
 		return $this->_default_where_conditions_strategy->get_default_where_conditions($model_relation_path);
@@ -2877,8 +2877,8 @@  discard block
 block discarded – undo
2877 2877
 	 * @param string $model_relation_path eg, path from Event to Payment is "Registration.Transaction.Payment."
2878 2878
 	 * @return array like EEM_Base::get_all's $query_params[0] (where conditions)
2879 2879
 	 */
2880
-	protected function _get_minimum_where_conditions($model_relation_path = null){
2881
-		if ( $this->_ignore_where_strategy )
2880
+	protected function _get_minimum_where_conditions($model_relation_path = null) {
2881
+		if ($this->_ignore_where_strategy)
2882 2882
 			return array();
2883 2883
 
2884 2884
 		return $this->_minimum_where_conditions_strategy->get_default_where_conditions($model_relation_path);
@@ -2889,13 +2889,13 @@  discard block
 block discarded – undo
2889 2889
 	 * @param EE_Model_Query_Info_Carrier $model_query_info
2890 2890
 	 * @return string
2891 2891
 	 */
2892
-	private function _construct_default_select_sql(EE_Model_Query_Info_Carrier $model_query_info){
2892
+	private function _construct_default_select_sql(EE_Model_Query_Info_Carrier $model_query_info) {
2893 2893
 		$selects = $this->_get_columns_to_select_for_this_model();
2894
-		foreach($model_query_info->get_model_names_included() as $model_relation_chain => $name_of_other_model_included){
2894
+		foreach ($model_query_info->get_model_names_included() as $model_relation_chain => $name_of_other_model_included) {
2895 2895
 			$other_model_included = $this->get_related_model_obj($name_of_other_model_included);
2896 2896
 			$selects = array_merge($selects, $other_model_included->_get_columns_to_select_for_this_model($model_relation_chain));
2897 2897
 		}
2898
-		return implode(", ",$selects);
2898
+		return implode(", ", $selects);
2899 2899
 	}
2900 2900
 
2901 2901
 	/**
@@ -2904,19 +2904,19 @@  discard block
 block discarded – undo
2904 2904
 	 * @param string $model_relation_chain like 'Question.Question_Group.Event'
2905 2905
 	 * @return array numerically indexed, values are columns to select and rename, eg "Event.ID AS 'Event.ID'"
2906 2906
 	 */
2907
-	public function _get_columns_to_select_for_this_model($model_relation_chain = ''){
2907
+	public function _get_columns_to_select_for_this_model($model_relation_chain = '') {
2908 2908
 		$fields = $this->field_settings();
2909 2909
 		$selects = array();
2910 2910
 		$table_alias_with_model_relation_chain_prefix = EE_Model_Parser::extract_table_alias_model_relation_chain_prefix($model_relation_chain, $this->get_this_model_name());
2911
-		foreach($fields as $field_obj){
2912
-			$selects[] = $table_alias_with_model_relation_chain_prefix . $field_obj->get_table_alias().".".$field_obj->get_table_column()." AS '".$table_alias_with_model_relation_chain_prefix.$field_obj->get_table_alias().".".$field_obj->get_table_column()."'";
2911
+		foreach ($fields as $field_obj) {
2912
+			$selects[] = $table_alias_with_model_relation_chain_prefix.$field_obj->get_table_alias().".".$field_obj->get_table_column()." AS '".$table_alias_with_model_relation_chain_prefix.$field_obj->get_table_alias().".".$field_obj->get_table_column()."'";
2913 2913
 		}
2914 2914
 		//make sure we are also getting the PKs of each table
2915 2915
 		$tables = $this->get_tables();
2916
-		if(count($tables) > 1){
2917
-			foreach($tables as $table_obj){
2918
-				$qualified_pk_column = $table_alias_with_model_relation_chain_prefix . $table_obj->get_fully_qualified_pk_column();
2919
-				if( ! in_array($qualified_pk_column,$selects)){
2916
+		if (count($tables) > 1) {
2917
+			foreach ($tables as $table_obj) {
2918
+				$qualified_pk_column = $table_alias_with_model_relation_chain_prefix.$table_obj->get_fully_qualified_pk_column();
2919
+				if ( ! in_array($qualified_pk_column, $selects)) {
2920 2920
 					$selects[] = "$qualified_pk_column AS '$qualified_pk_column'";
2921 2921
 				}
2922 2922
 			}
@@ -2940,66 +2940,66 @@  discard block
 block discarded – undo
2940 2940
 	 * @throws EE_Error
2941 2941
 	 * @return void only modifies the EEM_Related_Model_Info_Carrier passed into it
2942 2942
 	 */
2943
-	private function _extract_related_model_info_from_query_param( $query_param, EE_Model_Query_Info_Carrier $passed_in_query_info, $query_param_type, $original_query_param = NULL ){
2944
-		if($original_query_param == NULL){
2943
+	private function _extract_related_model_info_from_query_param($query_param, EE_Model_Query_Info_Carrier $passed_in_query_info, $query_param_type, $original_query_param = NULL) {
2944
+		if ($original_query_param == NULL) {
2945 2945
 			$original_query_param = $query_param;
2946 2946
 		}
2947 2947
 		$query_param = $this->_remove_stars_and_anything_after_from_condition_query_param_key($query_param);
2948 2948
 		/** @var $allow_logic_query_params bool whether or not to allow logic_query_params like 'NOT','OR', or 'AND' */
2949
-		$allow_logic_query_params = in_array($query_param_type,array('where','having'));
2950
-		$allow_fields = in_array($query_param_type,array('where','having','order_by','group_by','order'));
2949
+		$allow_logic_query_params = in_array($query_param_type, array('where', 'having'));
2950
+		$allow_fields = in_array($query_param_type, array('where', 'having', 'order_by', 'group_by', 'order'));
2951 2951
 		//check to see if we have a field on this model
2952 2952
 		$this_model_fields = $this->field_settings(true);
2953
-		if(array_key_exists($query_param,$this_model_fields)){
2954
-			if($allow_fields){
2953
+		if (array_key_exists($query_param, $this_model_fields)) {
2954
+			if ($allow_fields) {
2955 2955
 				return;
2956
-			}else{
2956
+			} else {
2957 2957
 				throw new EE_Error(sprintf(__("Using a field name (%s) on model %s is not allowed on this query param type '%s'. Original query param was %s", "event_espresso"),
2958
-						$query_param,get_class($this),$query_param_type,$original_query_param));
2958
+						$query_param, get_class($this), $query_param_type, $original_query_param));
2959 2959
 			}
2960 2960
 		}
2961 2961
 		//check if this is a special logic query param
2962
-		elseif(in_array($query_param, $this->_logic_query_param_keys, TRUE)){
2963
-			if($allow_logic_query_params){
2962
+		elseif (in_array($query_param, $this->_logic_query_param_keys, TRUE)) {
2963
+			if ($allow_logic_query_params) {
2964 2964
 				return;
2965
-			}else{
2965
+			} else {
2966 2966
 				throw new EE_Error(
2967 2967
 					sprintf(
2968
-						__( 'Logic query params ("%1$s") are being used incorrectly with the following query param ("%2$s") on model %3$s. %4$sAdditional Info:%4$s%5$s', 'event_espresso' ),
2969
-						implode( '", "', $this->_logic_query_param_keys ),
2970
-						$query_param ,
2971
-						get_class( $this ),
2968
+						__('Logic query params ("%1$s") are being used incorrectly with the following query param ("%2$s") on model %3$s. %4$sAdditional Info:%4$s%5$s', 'event_espresso'),
2969
+						implode('", "', $this->_logic_query_param_keys),
2970
+						$query_param,
2971
+						get_class($this),
2972 2972
 						'<br />',
2973
-						"\t" . ' $passed_in_query_info = <pre>' . print_r( $passed_in_query_info, TRUE ) . '</pre>' . "\n\t" . ' $query_param_type = ' . $query_param_type . "\n\t" . ' $original_query_param = ' . $original_query_param
2973
+						"\t".' $passed_in_query_info = <pre>'.print_r($passed_in_query_info, TRUE).'</pre>'."\n\t".' $query_param_type = '.$query_param_type."\n\t".' $original_query_param = '.$original_query_param
2974 2974
 					)
2975 2975
 				);
2976 2976
 			}
2977 2977
 		}
2978 2978
 
2979 2979
 		//check if it's a custom selection
2980
-		elseif(array_key_exists($query_param,$this->_custom_selections)){
2980
+		elseif (array_key_exists($query_param, $this->_custom_selections)) {
2981 2981
 			return;
2982 2982
 		}
2983 2983
 
2984 2984
 		//check if has a model name at the beginning
2985 2985
 		//and
2986 2986
 		//check if it's a field on a related model
2987
-		foreach($this->_model_relations as $valid_related_model_name=>$relation_obj){
2988
-			if(strpos($query_param, $valid_related_model_name.".") === 0){
2989
-				$this->_add_join_to_model($valid_related_model_name, $passed_in_query_info,$original_query_param);
2987
+		foreach ($this->_model_relations as $valid_related_model_name=>$relation_obj) {
2988
+			if (strpos($query_param, $valid_related_model_name.".") === 0) {
2989
+				$this->_add_join_to_model($valid_related_model_name, $passed_in_query_info, $original_query_param);
2990 2990
 				$query_param = substr($query_param, strlen($valid_related_model_name."."));
2991
-				if($query_param == ''){
2991
+				if ($query_param == '') {
2992 2992
 					//nothing left to $query_param
2993 2993
 					//we should actually end in a field name, not a model like this!
2994 2994
 					throw new EE_Error(sprintf(__("Query param '%s' (of type %s on model %s) shouldn't end on a period (.) ", "event_espresso"),
2995
-					$query_param,$query_param_type,get_class($this),$valid_related_model_name));
2996
-				}else{
2995
+					$query_param, $query_param_type, get_class($this), $valid_related_model_name));
2996
+				} else {
2997 2997
 					$related_model_obj = $this->get_related_model_obj($valid_related_model_name);
2998 2998
 					$related_model_obj->_extract_related_model_info_from_query_param($query_param, $passed_in_query_info, $query_param_type, $original_query_param);
2999 2999
 					return;
3000 3000
 				}
3001
-			}elseif($query_param == $valid_related_model_name){
3002
-				$this->_add_join_to_model($valid_related_model_name, $passed_in_query_info,$original_query_param);
3001
+			}elseif ($query_param == $valid_related_model_name) {
3002
+				$this->_add_join_to_model($valid_related_model_name, $passed_in_query_info, $original_query_param);
3003 3003
 				return;
3004 3004
 			}
3005 3005
 		}
@@ -3009,7 +3009,7 @@  discard block
 block discarded – undo
3009 3009
 		//and we previously confirmed it wasn't a logic query param or field on the current model
3010 3010
 		//it's wack, that's what it is
3011 3011
 		throw new EE_Error(sprintf(__("There is no model named '%s' related to %s. Query param type is %s and original query param is %s", "event_espresso"),
3012
-				$query_param,get_class($this),$query_param_type,$original_query_param));
3012
+				$query_param, get_class($this), $query_param_type, $original_query_param));
3013 3013
 
3014 3014
 	}
3015 3015
 
@@ -3026,26 +3026,26 @@  discard block
 block discarded – undo
3026 3026
 	 * what models to prepend onto its default query params or in case it wants to rename tables (in case there are multiple joins to the same table)
3027 3027
 	 * @return void
3028 3028
 	 */
3029
-	private function _add_join_to_model($model_name, EE_Model_Query_Info_Carrier $passed_in_query_info,$original_query_param){
3029
+	private function _add_join_to_model($model_name, EE_Model_Query_Info_Carrier $passed_in_query_info, $original_query_param) {
3030 3030
 		$relation_obj = $this->related_settings_for($model_name);
3031 3031
 
3032 3032
 		$model_relation_chain = EE_Model_Parser::extract_model_relation_chain($model_name, $original_query_param);
3033 3033
 		//check if the relation is HABTM, because then we're essentially doing two joins
3034 3034
 		//If so, join first to the JOIN table, and add its data types, and then continue as normal
3035
-		if($relation_obj instanceof EE_HABTM_Relation){
3035
+		if ($relation_obj instanceof EE_HABTM_Relation) {
3036 3036
 			$join_model_obj = $relation_obj->get_join_model();
3037 3037
 			//replace the model specified with the join model for this relation chain, whi
3038 3038
 			$relation_chain_to_join_model = EE_Model_Parser::replace_model_name_with_join_model_name_in_model_relation_chain($model_name, $join_model_obj->get_this_model_name(), $model_relation_chain);
3039 3039
 			$new_query_info = new EE_Model_Query_Info_Carrier(
3040 3040
 					array($relation_chain_to_join_model => $join_model_obj->get_this_model_name()),
3041 3041
 					$relation_obj->get_join_to_intermediate_model_statement($relation_chain_to_join_model));
3042
-			$passed_in_query_info->merge( $new_query_info  );
3042
+			$passed_in_query_info->merge($new_query_info);
3043 3043
 		}
3044 3044
 		//now just join to the other table pointed to by the relation object, and add its data types
3045 3045
 		$new_query_info = new EE_Model_Query_Info_Carrier(
3046 3046
 				array($model_relation_chain=>$model_name),
3047 3047
 				$relation_obj->get_join_statement($model_relation_chain));
3048
-		$passed_in_query_info->merge( $new_query_info  );
3048
+		$passed_in_query_info->merge($new_query_info);
3049 3049
 	}
3050 3050
 
3051 3051
 
@@ -3054,11 +3054,11 @@  discard block
 block discarded – undo
3054 3054
 	 * @param array $where_params like EEM_Base::get_all
3055 3055
 	 * @return string of SQL
3056 3056
 	 */
3057
-	private function _construct_where_clause($where_params){
3057
+	private function _construct_where_clause($where_params) {
3058 3058
 		$SQL = $this->_construct_condition_clause_recursive($where_params, ' AND ');
3059
-		if($SQL){
3060
-			return " WHERE ". $SQL;
3061
-		}else{
3059
+		if ($SQL) {
3060
+			return " WHERE ".$SQL;
3061
+		} else {
3062 3062
 			return '';
3063 3063
 		}
3064 3064
 	}
@@ -3069,11 +3069,11 @@  discard block
 block discarded – undo
3069 3069
 	 * @param array $having_params
3070 3070
 	 * @return string
3071 3071
 	 */
3072
-	private function _construct_having_clause($having_params){
3072
+	private function _construct_having_clause($having_params) {
3073 3073
 		$SQL = $this->_construct_condition_clause_recursive($having_params, ' AND ');
3074
-		if($SQL){
3075
-			return " HAVING ". $SQL;
3076
-		}else{
3074
+		if ($SQL) {
3075
+			return " HAVING ".$SQL;
3076
+		} else {
3077 3077
 			return '';
3078 3078
 		}
3079 3079
 
@@ -3087,17 +3087,17 @@  discard block
 block discarded – undo
3087 3087
 	 * @return EE_Model_Field_Base
3088 3088
 	 * @throws EE_Error
3089 3089
 	 */
3090
-	protected function _get_field_on_model($field_name,$model_name){
3090
+	protected function _get_field_on_model($field_name, $model_name) {
3091 3091
 		$model_class = 'EEM_'.$model_name;
3092 3092
 		$model_filepath = $model_class.".model.php";
3093
-		EE_Registry::instance()->load_helper( 'File' );
3094
-		if ( is_readable($model_filepath)){
3093
+		EE_Registry::instance()->load_helper('File');
3094
+		if (is_readable($model_filepath)) {
3095 3095
 			require_once($model_filepath);
3096
-			$model_instance=call_user_func($model_name."::instance");
3096
+			$model_instance = call_user_func($model_name."::instance");
3097 3097
 			/* @var $model_instance EEM_Base */
3098 3098
 			return $model_instance->field_settings_for($field_name);
3099
-		}else{
3100
-			throw new EE_Error(sprintf(__('No model named %s exists, with classname %s and filepath %s','event_espresso'),$model_name,$model_class,$model_filepath));
3099
+		} else {
3100
+			throw new EE_Error(sprintf(__('No model named %s exists, with classname %s and filepath %s', 'event_espresso'), $model_name, $model_class, $model_filepath));
3101 3101
 		}
3102 3102
 	}
3103 3103
 
@@ -3110,43 +3110,43 @@  discard block
 block discarded – undo
3110 3110
 	 * @throws EE_Error
3111 3111
 	 * @return string of SQL
3112 3112
 	 */
3113
-	private function _construct_condition_clause_recursive($where_params, $glue = ' AND'){
3114
-		$where_clauses=array();
3115
-		foreach($where_params as $query_param => $op_and_value_or_sub_condition){
3116
-			$query_param = $this->_remove_stars_and_anything_after_from_condition_query_param_key($query_param);//str_replace("*",'',$query_param);
3117
-			if(in_array($query_param,$this->_logic_query_param_keys)){
3118
-				switch($query_param){
3113
+	private function _construct_condition_clause_recursive($where_params, $glue = ' AND') {
3114
+		$where_clauses = array();
3115
+		foreach ($where_params as $query_param => $op_and_value_or_sub_condition) {
3116
+			$query_param = $this->_remove_stars_and_anything_after_from_condition_query_param_key($query_param); //str_replace("*",'',$query_param);
3117
+			if (in_array($query_param, $this->_logic_query_param_keys)) {
3118
+				switch ($query_param) {
3119 3119
 					case 'not':
3120 3120
 					case 'NOT':
3121
-						$where_clauses[] = "! (". $this->_construct_condition_clause_recursive($op_and_value_or_sub_condition, $glue).")";
3121
+						$where_clauses[] = "! (".$this->_construct_condition_clause_recursive($op_and_value_or_sub_condition, $glue).")";
3122 3122
 						break;
3123 3123
 					case 'and':
3124 3124
 					case 'AND':
3125
-						$where_clauses[] = " (". $this->_construct_condition_clause_recursive($op_and_value_or_sub_condition, ' AND ') .")";
3125
+						$where_clauses[] = " (".$this->_construct_condition_clause_recursive($op_and_value_or_sub_condition, ' AND ').")";
3126 3126
 						break;
3127 3127
 					case 'or':
3128 3128
 					case 'OR':
3129
-						$where_clauses[] = " (". $this->_construct_condition_clause_recursive($op_and_value_or_sub_condition, ' OR ') .")";
3129
+						$where_clauses[] = " (".$this->_construct_condition_clause_recursive($op_and_value_or_sub_condition, ' OR ').")";
3130 3130
 						break;
3131 3131
 				}
3132
-			}else{
3132
+			} else {
3133 3133
 				$field_obj = $this->_deduce_field_from_query_param($query_param);
3134 3134
 
3135 3135
 				//if it's not a normal field, maybe it's a custom selection?
3136
-				if( ! $field_obj){
3137
-					if(isset( $this->_custom_selections[$query_param][1])){
3136
+				if ( ! $field_obj) {
3137
+					if (isset($this->_custom_selections[$query_param][1])) {
3138 3138
 						$field_obj = $this->_custom_selections[$query_param][1];
3139
-					}else{
3140
-						throw new EE_Error(sprintf(__("%s is neither a valid model field name, nor a custom selection", "event_espresso"),$query_param));
3139
+					} else {
3140
+						throw new EE_Error(sprintf(__("%s is neither a valid model field name, nor a custom selection", "event_espresso"), $query_param));
3141 3141
 					}
3142 3142
 				}
3143 3143
 				$op_and_value_sql = $this->_construct_op_and_value($op_and_value_or_sub_condition, $field_obj);
3144
-				$where_clauses[]=$this->_deduce_column_name_from_query_param($query_param).SP.$op_and_value_sql;
3144
+				$where_clauses[] = $this->_deduce_column_name_from_query_param($query_param).SP.$op_and_value_sql;
3145 3145
 			}
3146 3146
 		}
3147
-		if($where_clauses){
3148
-			$SQL = implode($glue,$where_clauses);
3149
-		}else{
3147
+		if ($where_clauses) {
3148
+			$SQL = implode($glue, $where_clauses);
3149
+		} else {
3150 3150
 			$SQL = '';
3151 3151
 		}
3152 3152
 		return $SQL;
@@ -3160,18 +3160,18 @@  discard block
 block discarded – undo
3160 3160
 	 * @throws EE_Error
3161 3161
 	 * @return string table alias and column name for SQL, eg "Transaction.TXN_ID"
3162 3162
 	 */
3163
-	private function _deduce_column_name_from_query_param($query_param){
3163
+	private function _deduce_column_name_from_query_param($query_param) {
3164 3164
 		$field = $this->_deduce_field_from_query_param($query_param);
3165 3165
 
3166
-		if( $field ){
3167
-			$table_alias_prefix = EE_Model_Parser::extract_table_alias_model_relation_chain_from_query_param( $field->get_model_name(), $query_param );
3168
-			return $table_alias_prefix . $field->get_qualified_column();
3169
-		}elseif(array_key_exists($query_param,$this->_custom_selections)){
3166
+		if ($field) {
3167
+			$table_alias_prefix = EE_Model_Parser::extract_table_alias_model_relation_chain_from_query_param($field->get_model_name(), $query_param);
3168
+			return $table_alias_prefix.$field->get_qualified_column();
3169
+		}elseif (array_key_exists($query_param, $this->_custom_selections)) {
3170 3170
 			//maybe it's custom selection item?
3171 3171
 			//if so, just use it as the "column name"
3172 3172
 			return $query_param;
3173
-		}else{
3174
-			throw new EE_Error(sprintf(__("%s is not a valid field on this model, nor a custom selection (%s)", "event_espresso"),$query_param,implode(",",$this->_custom_selections)));
3173
+		} else {
3174
+			throw new EE_Error(sprintf(__("%s is not a valid field on this model, nor a custom selection (%s)", "event_espresso"), $query_param, implode(",", $this->_custom_selections)));
3175 3175
 		}
3176 3176
 	}
3177 3177
 
@@ -3183,11 +3183,11 @@  discard block
 block discarded – undo
3183 3183
 	 * @param string $condition_query_param_key
3184 3184
 	 * @return string
3185 3185
 	 */
3186
-	private function _remove_stars_and_anything_after_from_condition_query_param_key($condition_query_param_key){
3186
+	private function _remove_stars_and_anything_after_from_condition_query_param_key($condition_query_param_key) {
3187 3187
 		$pos_of_star = strpos($condition_query_param_key, '*');
3188
-		if($pos_of_star === FALSE){
3188
+		if ($pos_of_star === FALSE) {
3189 3189
 			return $condition_query_param_key;
3190
-		}else{
3190
+		} else {
3191 3191
 			$condition_query_param_sans_star = substr($condition_query_param_key, 0, $pos_of_star);
3192 3192
 			return $condition_query_param_sans_star;
3193 3193
 		}
@@ -3202,54 +3202,54 @@  discard block
 block discarded – undo
3202 3202
 	 * @throws EE_Error
3203 3203
 	 * @return string
3204 3204
 	 */
3205
-	private function _construct_op_and_value($op_and_value, $field_obj){
3206
-		if(is_array( $op_and_value )){
3205
+	private function _construct_op_and_value($op_and_value, $field_obj) {
3206
+		if (is_array($op_and_value)) {
3207 3207
 			$operator = isset($op_and_value[0]) ? $this->_prepare_operator_for_sql($op_and_value[0]) : null;
3208
-			if( ! $operator){
3208
+			if ( ! $operator) {
3209 3209
 				$php_array_like_string = array();
3210
-				foreach($op_and_value as $key => $value){
3210
+				foreach ($op_and_value as $key => $value) {
3211 3211
 					$php_array_like_string[] = "$key=>$value";
3212 3212
 				}
3213
-				throw new EE_Error(sprintf(__("You setup a query parameter like you were going to specify an operator, but didn't. You provided '(%s)', but the operator should be at array key index 0 (eg array('>',32))", "event_espresso"), implode(",",$php_array_like_string)));
3213
+				throw new EE_Error(sprintf(__("You setup a query parameter like you were going to specify an operator, but didn't. You provided '(%s)', but the operator should be at array key index 0 (eg array('>',32))", "event_espresso"), implode(",", $php_array_like_string)));
3214 3214
 			}
3215 3215
 			$value = isset($op_and_value[1]) ? $op_and_value[1] : null;
3216
-		}else{
3216
+		} else {
3217 3217
 			$operator = '=';
3218 3218
 			$value = $op_and_value;
3219 3219
 		}
3220 3220
 
3221 3221
 		//check to see if the value is actually another field
3222
-		if(is_array($op_and_value) && isset($op_and_value[2]) && $op_and_value[2] == true){
3222
+		if (is_array($op_and_value) && isset($op_and_value[2]) && $op_and_value[2] == true) {
3223 3223
 			return $operator.SP.$this->_deduce_column_name_from_query_param($value);
3224
-		}elseif(in_array($operator, $this->_in_style_operators) && is_array($value)){
3224
+		}elseif (in_array($operator, $this->_in_style_operators) && is_array($value)) {
3225 3225
 			//in this case, the value should be an array, or at least a comma-separated list
3226 3226
 			//it will need to handle a little differently
3227 3227
 			$cleaned_value = $this->_construct_in_value($value, $field_obj);
3228 3228
 			//note: $cleaned_value has already been run through $wpdb->prepare()
3229 3229
 			return $operator.SP.$cleaned_value;
3230
-		} elseif( in_array( $operator, $this->_between_style_operators ) && is_array( $value ) ) {
3230
+		} elseif (in_array($operator, $this->_between_style_operators) && is_array($value)) {
3231 3231
 			//the value should be an array with count of two.
3232
-			if ( count($value) !== 2 )
3233
-				throw new EE_Error( sprintf( __("The '%s' operator must be used with an array of values and there must be exactly TWO values in that array.", 'event_espresso'), "BETWEEN" ) );
3234
-			$cleaned_value = $this->_construct_between_value( $value, $field_obj );
3232
+			if (count($value) !== 2)
3233
+				throw new EE_Error(sprintf(__("The '%s' operator must be used with an array of values and there must be exactly TWO values in that array.", 'event_espresso'), "BETWEEN"));
3234
+			$cleaned_value = $this->_construct_between_value($value, $field_obj);
3235 3235
 			return $operator.SP.$cleaned_value;
3236
-		} elseif( in_array( $operator, $this->_null_style_operators ) ) {
3237
-			if($value != NULL){
3238
-				throw new EE_Error(sprintf(__("You attempted to give a value  (%s) while using a NULL-style operator (%s). That isn't valid", "event_espresso"),$value,$operator));
3236
+		} elseif (in_array($operator, $this->_null_style_operators)) {
3237
+			if ($value != NULL) {
3238
+				throw new EE_Error(sprintf(__("You attempted to give a value  (%s) while using a NULL-style operator (%s). That isn't valid", "event_espresso"), $value, $operator));
3239 3239
 			}
3240 3240
 			return $operator;
3241
-		}elseif( $operator == 'LIKE' && ! is_array($value)){
3241
+		}elseif ($operator == 'LIKE' && ! is_array($value)) {
3242 3242
 			//if the operator is 'LIKE', we want to allow percent signs (%) and not
3243 3243
 			//remove other junk. So just treat it as a string.
3244 3244
 			return $operator.SP.$this->_wpdb_prepare_using_field($value, '%s');
3245
-		}elseif( ! in_array($operator, $this->_in_style_operators) && ! is_array($value)){
3246
-			return $operator.SP.$this->_wpdb_prepare_using_field($value,$field_obj);
3247
-		}elseif(in_array($operator, $this->_in_style_operators) && ! is_array($value)){
3248
-			throw new EE_Error(sprintf(__("Operator '%s' must be used with an array of values, eg 'Registration.REG_ID' => array('%s',array(1,2,3))",'event_espresso'),$operator, $operator));
3249
-		}elseif( ! in_array($operator, $this->_in_style_operators) && is_array($value)){
3250
-			throw new EE_Error(sprintf(__("Operator '%s' must be used with a single value, not an array. Eg 'Registration.REG_ID => array('%s',23))",'event_espresso'),$operator,$operator));
3251
-		}else{
3252
-			throw new EE_Error(sprintf(__("It appears you've provided some totally invalid query parameters. Operator and value were:'%s', which isn't right at all", "event_espresso"),  http_build_query($op_and_value)));
3245
+		}elseif ( ! in_array($operator, $this->_in_style_operators) && ! is_array($value)) {
3246
+			return $operator.SP.$this->_wpdb_prepare_using_field($value, $field_obj);
3247
+		}elseif (in_array($operator, $this->_in_style_operators) && ! is_array($value)) {
3248
+			throw new EE_Error(sprintf(__("Operator '%s' must be used with an array of values, eg 'Registration.REG_ID' => array('%s',array(1,2,3))", 'event_espresso'), $operator, $operator));
3249
+		}elseif ( ! in_array($operator, $this->_in_style_operators) && is_array($value)) {
3250
+			throw new EE_Error(sprintf(__("Operator '%s' must be used with a single value, not an array. Eg 'Registration.REG_ID => array('%s',23))", 'event_espresso'), $operator, $operator));
3251
+		} else {
3252
+			throw new EE_Error(sprintf(__("It appears you've provided some totally invalid query parameters. Operator and value were:'%s', which isn't right at all", "event_espresso"), http_build_query($op_and_value)));
3253 3253
 		}
3254 3254
 	}
3255 3255
 
@@ -3261,12 +3261,12 @@  discard block
 block discarded – undo
3261 3261
 	 * @param EE_Model_Field_Base|string $field_obj if string, it should be the datatype to be used when querying, eg '%s'
3262 3262
 	 * @return string
3263 3263
 	 */
3264
-	function _construct_between_value( $values, $field_obj ) {
3264
+	function _construct_between_value($values, $field_obj) {
3265 3265
 		$cleaned_values = array();
3266
-		foreach ( $values as $value ) {
3267
-			$cleaned_values[] = $this->_wpdb_prepare_using_field($value,$field_obj);
3266
+		foreach ($values as $value) {
3267
+			$cleaned_values[] = $this->_wpdb_prepare_using_field($value, $field_obj);
3268 3268
 		}
3269
-		return  $cleaned_values[0] . " AND " . $cleaned_values[1];
3269
+		return  $cleaned_values[0]." AND ".$cleaned_values[1];
3270 3270
 	}
3271 3271
 
3272 3272
 
@@ -3282,26 +3282,26 @@  discard block
 block discarded – undo
3282 3282
 	 * @param EE_Model_Field_Base|string $field_obj if string, it should be a wpdb data type like '%s', or '%d'
3283 3283
 	 * @return string of SQL to follow an 'IN' or 'NOT IN' operator
3284 3284
 	 */
3285
-	function _construct_in_value($values,  $field_obj){
3285
+	function _construct_in_value($values, $field_obj) {
3286 3286
 		//check if the value is a CSV list
3287
-		if(is_string($values)){
3287
+		if (is_string($values)) {
3288 3288
 			//in which case, turn it into an array
3289
-			$values = explode(",",$values);
3289
+			$values = explode(",", $values);
3290 3290
 		}
3291 3291
 		$cleaned_values = array();
3292
-		foreach($values as $value){
3293
-			$cleaned_values[] = $this->_wpdb_prepare_using_field($value,$field_obj);
3292
+		foreach ($values as $value) {
3293
+			$cleaned_values[] = $this->_wpdb_prepare_using_field($value, $field_obj);
3294 3294
 		}
3295 3295
 		//we would just LOVE to leave $cleaned_values as an empty array, and return the value as "()",
3296 3296
 		//but unfortunately that's invalid SQL. So instead we return a string which we KNOW will evaluate to be the empty set
3297 3297
 		//which is effectively equivalent to returning "()". We don't return "(0)" because that only works for auto-incrementing columns
3298
-		if(empty($cleaned_values)){
3298
+		if (empty($cleaned_values)) {
3299 3299
 			$all_fields = $this->field_settings();
3300 3300
 			$a_field = array_shift($all_fields);
3301 3301
 			$main_table = $this->_get_main_table();
3302 3302
 			$cleaned_values[] = "SELECT ".$a_field->get_table_column()." FROM ".$main_table->get_table_name()." WHERE FALSE";
3303 3303
 		}
3304
-		return "(".implode(",",$cleaned_values).")";
3304
+		return "(".implode(",", $cleaned_values).")";
3305 3305
 	}
3306 3306
 
3307 3307
 
@@ -3313,16 +3313,16 @@  discard block
 block discarded – undo
3313 3313
 	 * @throws EE_Error
3314 3314
 	 * @return false|null|string
3315 3315
 	 */
3316
-	private function _wpdb_prepare_using_field($value,$field_obj){
3316
+	private function _wpdb_prepare_using_field($value, $field_obj) {
3317 3317
 		/** @type WPDB $wpdb */
3318 3318
 		global $wpdb;
3319
-		if($field_obj instanceof EE_Model_Field_Base){
3320
-			return $wpdb->prepare($field_obj->get_wpdb_data_type(),$this->_prepare_value_for_use_in_db($value, $field_obj));
3321
-		}else{//$field_obj should really just be a data type
3322
-			if( ! in_array($field_obj,$this->_valid_wpdb_data_types)){
3323
-				throw new EE_Error(sprintf(__("%s is not a valid wpdb datatype. Valid ones are %s", "event_espresso"),$field_obj,implode(",",$this->_valid_wpdb_data_types)));
3319
+		if ($field_obj instanceof EE_Model_Field_Base) {
3320
+			return $wpdb->prepare($field_obj->get_wpdb_data_type(), $this->_prepare_value_for_use_in_db($value, $field_obj));
3321
+		} else {//$field_obj should really just be a data type
3322
+			if ( ! in_array($field_obj, $this->_valid_wpdb_data_types)) {
3323
+				throw new EE_Error(sprintf(__("%s is not a valid wpdb datatype. Valid ones are %s", "event_espresso"), $field_obj, implode(",", $this->_valid_wpdb_data_types)));
3324 3324
 			}
3325
-			return $wpdb->prepare($field_obj,$value);
3325
+			return $wpdb->prepare($field_obj, $value);
3326 3326
 		}
3327 3327
 	}
3328 3328
 
@@ -3334,27 +3334,27 @@  discard block
 block discarded – undo
3334 3334
 	 * @throws EE_Error
3335 3335
 	 * @return EE_Model_Field_Base
3336 3336
 	 */
3337
-	protected function _deduce_field_from_query_param($query_param_name){
3337
+	protected function _deduce_field_from_query_param($query_param_name) {
3338 3338
 		//ok, now proceed with deducing which part is the model's name, and which is the field's name
3339 3339
 		//which will help us find the database table and column
3340 3340
 
3341
-		$query_param_parts = explode(".",$query_param_name);
3342
-		if(empty($query_param_parts)){
3343
-			throw new EE_Error(sprintf(__("_extract_column_name is empty when trying to extract column and table name from %s",'event_espresso'),$query_param_name));
3341
+		$query_param_parts = explode(".", $query_param_name);
3342
+		if (empty($query_param_parts)) {
3343
+			throw new EE_Error(sprintf(__("_extract_column_name is empty when trying to extract column and table name from %s", 'event_espresso'), $query_param_name));
3344 3344
 		}
3345 3345
 		$number_of_parts = count($query_param_parts);
3346
-		$last_query_param_part = $query_param_parts[ count($query_param_parts) - 1 ];
3347
-		if($number_of_parts == 1){
3346
+		$last_query_param_part = $query_param_parts[count($query_param_parts) - 1];
3347
+		if ($number_of_parts == 1) {
3348 3348
 			$field_name = $last_query_param_part;
3349 3349
 			$model_obj = $this;
3350
-		}else{// $number_of_parts >= 2
3350
+		} else {// $number_of_parts >= 2
3351 3351
 			//the last part is the column name, and there are only 2parts. therefore...
3352 3352
 			$field_name = $last_query_param_part;
3353
-			$model_obj = $this->get_related_model_obj( $query_param_parts[ $number_of_parts - 2 ]);
3353
+			$model_obj = $this->get_related_model_obj($query_param_parts[$number_of_parts - 2]);
3354 3354
 		}
3355
-		try{
3355
+		try {
3356 3356
 			return $model_obj->field_settings_for($field_name);
3357
-		}catch(EE_Error $e){
3357
+		} catch (EE_Error $e) {
3358 3358
 			return null;
3359 3359
 		}
3360 3360
 	}
@@ -3368,13 +3368,13 @@  discard block
 block discarded – undo
3368 3368
 	 * @throws EE_Error
3369 3369
 	 * @return string
3370 3370
 	 */
3371
-	function _get_qualified_column_for_field($field_name){
3371
+	function _get_qualified_column_for_field($field_name) {
3372 3372
 		$all_fields = $this->field_settings();
3373 3373
 		$field = isset($all_fields[$field_name]) ? $all_fields[$field_name] : FALSE;
3374
-		if($field){
3374
+		if ($field) {
3375 3375
 			return $field->get_qualified_column();
3376
-		}else{
3377
-			throw new EE_Error(sprintf(__("There is no field titled %s on model %s. Either the query trying to use it is bad, or you need to add it to the list of fields on the model.",'event_espresso'),$field_name,get_class($this)));
3376
+		} else {
3377
+			throw new EE_Error(sprintf(__("There is no field titled %s on model %s. Either the query trying to use it is bad, or you need to add it to the list of fields on the model.", 'event_espresso'), $field_name, get_class($this)));
3378 3378
 		}
3379 3379
 	}
3380 3380
 
@@ -3388,14 +3388,14 @@  discard block
 block discarded – undo
3388 3388
 	 * @param  mixed|string $limit The limit for this select
3389 3389
 	 * @return string 				The final select join element for the query.
3390 3390
 	 */
3391
-	function _construct_limit_join_select( $table_alias, $limit ) {
3391
+	function _construct_limit_join_select($table_alias, $limit) {
3392 3392
 		$SQL = '';
3393 3393
 
3394
-		foreach ( $this->_tables as $table_obj ) {
3395
-			if ( $table_obj instanceof EE_Primary_Table ) {
3396
-				$SQL .= $table_alias == $table_obj->get_table_alias() ? $table_obj->get_select_join_limit( $limit ) : SP.$table_obj->get_table_name()." AS ".$table_obj->get_table_alias().SP;
3397
-			} elseif ( $table_obj instanceof EE_Secondary_Table ) {
3398
-				$SQL .= $table_alias == $table_obj->get_table_alias() ? $table_obj->get_select_join_limit_join($limit) : SP . $table_obj->get_join_sql( $table_alias ).SP;
3394
+		foreach ($this->_tables as $table_obj) {
3395
+			if ($table_obj instanceof EE_Primary_Table) {
3396
+				$SQL .= $table_alias == $table_obj->get_table_alias() ? $table_obj->get_select_join_limit($limit) : SP.$table_obj->get_table_name()." AS ".$table_obj->get_table_alias().SP;
3397
+			} elseif ($table_obj instanceof EE_Secondary_Table) {
3398
+				$SQL .= $table_alias == $table_obj->get_table_alias() ? $table_obj->get_select_join_limit_join($limit) : SP.$table_obj->get_join_sql($table_alias).SP;
3399 3399
 			}
3400 3400
 		}
3401 3401
 		return $SQL;
@@ -3408,7 +3408,7 @@  discard block
 block discarded – undo
3408 3408
 	 * Eg "wp_post AS Event" or "wp_post AS Event INNER JOIN wp_postmeta Event_Meta ON Event.ID = Event_Meta.post_id"
3409 3409
 	 * @return string SQL
3410 3410
 	 */
3411
-	function _construct_internal_join(){
3411
+	function _construct_internal_join() {
3412 3412
 		$SQL = $this->_get_main_table()->get_table_sql();
3413 3413
 		$SQL .= $this->_construct_internal_join_to_table_with_alias($this->_get_main_table()->get_table_alias());
3414 3414
 		return $SQL;
@@ -3429,17 +3429,17 @@  discard block
 block discarded – undo
3429 3429
 	 * @param string $alias_prefixed table alias to join to (this table should already be in the FROM SQL clause)
3430 3430
 	 * @return string
3431 3431
 	 */
3432
-	function _construct_internal_join_to_table_with_alias($alias_prefixed){
3432
+	function _construct_internal_join_to_table_with_alias($alias_prefixed) {
3433 3433
 		$SQL = '';
3434 3434
 		$alias_sans_prefix = EE_Model_Parser::remove_table_alias_model_relation_chain_prefix($alias_prefixed);
3435
-		foreach($this->_tables as $table_obj){
3436
-			if($table_obj instanceof EE_Secondary_Table){//table is secondary table
3437
-				if($alias_sans_prefix == $table_obj->get_table_alias()){
3435
+		foreach ($this->_tables as $table_obj) {
3436
+			if ($table_obj instanceof EE_Secondary_Table) {//table is secondary table
3437
+				if ($alias_sans_prefix == $table_obj->get_table_alias()) {
3438 3438
 					//so we're joining to this table, meaning the table is already in
3439 3439
 					//the FROM statement, BUT the primary table isn't. So we want
3440 3440
 					//to add the inverse join sql
3441 3441
 					$SQL .= $table_obj->get_inverse_join_sql($alias_prefixed);
3442
-				}else{
3442
+				} else {
3443 3443
 					//just add a regular JOIN to this table from the primary table
3444 3444
 					$SQL .= $table_obj->get_join_sql($alias_prefixed);
3445 3445
 				}
@@ -3453,9 +3453,9 @@  discard block
 block discarded – undo
3453 3453
 	 * This should be a growing array of keys being table-columns (eg 'EVT_ID' and 'Event.EVT_ID'), and values being their data type (eg, '%s', '%d', etc)
3454 3454
 	 * @return array
3455 3455
 	 */
3456
-	function _get_data_types(){
3456
+	function _get_data_types() {
3457 3457
 		$data_types = array();
3458
-		foreach(array_values($this->field_settings()) as $field_obj){
3458
+		foreach (array_values($this->field_settings()) as $field_obj) {
3459 3459
 			//$data_types[$field_obj->get_table_column()] = $field_obj->get_wpdb_data_type();
3460 3460
 			/** @var $field_obj EE_Model_Field_Base */
3461 3461
 			$data_types[$field_obj->get_qualified_column()] = $field_obj->get_wpdb_data_type();
@@ -3471,11 +3471,11 @@  discard block
 block discarded – undo
3471 3471
 	 * @throws EE_Error
3472 3472
 	 * @return EEM_Base
3473 3473
 	 */
3474
-	function get_related_model_obj($model_name){
3474
+	function get_related_model_obj($model_name) {
3475 3475
 
3476 3476
 		$model_classname = "EEM_".$model_name;
3477
-		if(!class_exists($model_classname)){
3478
-			throw new EE_Error(sprintf(__("You specified a related model named %s in your query. No such model exists, if it did, it would have the classname %s",'event_espresso'),$model_name,$model_classname));
3477
+		if ( ! class_exists($model_classname)) {
3478
+			throw new EE_Error(sprintf(__("You specified a related model named %s in your query. No such model exists, if it did, it would have the classname %s", 'event_espresso'), $model_name, $model_classname));
3479 3479
 		}
3480 3480
 		$model_obj = call_user_func($model_classname."::instance");
3481 3481
 		return $model_obj;
@@ -3486,7 +3486,7 @@  discard block
 block discarded – undo
3486 3486
 	 * Returns the array of EE_ModelRelations for this model.
3487 3487
 	 * @return EE_Model_Relation_Base[]
3488 3488
 	 */
3489
-	public function relation_settings(){
3489
+	public function relation_settings() {
3490 3490
 		return $this->_model_relations;
3491 3491
 	}
3492 3492
 
@@ -3496,10 +3496,10 @@  discard block
 block discarded – undo
3496 3496
 	 * (Eg, without an event, datetimes have little purpose.)
3497 3497
 	 * @return EE_Belongs_To_Relation[]
3498 3498
 	 */
3499
-	public function belongs_to_relations(){
3499
+	public function belongs_to_relations() {
3500 3500
 		$belongs_to_relations = array();
3501
-		foreach($this->relation_settings() as $model_name => $relation_obj){
3502
-			if($relation_obj instanceof EE_Belongs_To_Relation){
3501
+		foreach ($this->relation_settings() as $model_name => $relation_obj) {
3502
+			if ($relation_obj instanceof EE_Belongs_To_Relation) {
3503 3503
 				$belongs_to_relations[$model_name] = $relation_obj;
3504 3504
 			}
3505 3505
 		}
@@ -3514,15 +3514,15 @@  discard block
 block discarded – undo
3514 3514
 	 * @throws EE_Error
3515 3515
 	 * @return EE_Model_Relation_Base
3516 3516
 	 */
3517
-	public function related_settings_for($relation_name){
3518
-		$relatedModels=$this->relation_settings();
3519
-		if(!array_key_exists($relation_name,$relatedModels)){
3517
+	public function related_settings_for($relation_name) {
3518
+		$relatedModels = $this->relation_settings();
3519
+		if ( ! array_key_exists($relation_name, $relatedModels)) {
3520 3520
 			throw new EE_Error(
3521 3521
 				sprintf(
3522
-					__('Cannot get %s related to %s. There is no model relation of that type. There is, however, %s...','event_espresso'),
3522
+					__('Cannot get %s related to %s. There is no model relation of that type. There is, however, %s...', 'event_espresso'),
3523 3523
 					$relation_name,
3524 3524
 					$this->_get_class_name(),
3525
-					implode( ', ', array_keys( $relatedModels ))
3525
+					implode(', ', array_keys($relatedModels))
3526 3526
 				)
3527 3527
 			);
3528 3528
 		}
@@ -3537,10 +3537,10 @@  discard block
 block discarded – undo
3537 3537
 	 * @throws EE_Error
3538 3538
 	 * @return EE_Model_Field_Base
3539 3539
 	 */
3540
-	public function field_settings_for($fieldName){
3541
-		$fieldSettings=$this->field_settings(true);
3542
-		if( ! array_key_exists($fieldName,$fieldSettings)){
3543
-			throw new EE_Error(sprintf(__("There is no field/column '%s' on '%s'",'event_espresso'),$fieldName,get_class($this)));
3540
+	public function field_settings_for($fieldName) {
3541
+		$fieldSettings = $this->field_settings(true);
3542
+		if ( ! array_key_exists($fieldName, $fieldSettings)) {
3543
+			throw new EE_Error(sprintf(__("There is no field/column '%s' on '%s'", 'event_espresso'), $fieldName, get_class($this)));
3544 3544
 		}
3545 3545
 		return $fieldSettings[$fieldName];
3546 3546
 	}
@@ -3550,11 +3550,11 @@  discard block
 block discarded – undo
3550 3550
 	 * @param string $fieldName a key in the model's _field_settings array
3551 3551
 	 * @return boolean
3552 3552
 	 */
3553
-	public function has_field($fieldName){
3553
+	public function has_field($fieldName) {
3554 3554
 		$fieldSettings = $this->field_settings(true);
3555
-		if( isset($fieldSettings[$fieldName])){
3555
+		if (isset($fieldSettings[$fieldName])) {
3556 3556
 			return true;
3557
-		}else{
3557
+		} else {
3558 3558
 			return false;
3559 3559
 		}
3560 3560
 	}
@@ -3564,11 +3564,11 @@  discard block
 block discarded – undo
3564 3564
 	 * @param string $relation_name possibly one of the keys in the relation_settings array
3565 3565
 	 * @return boolean
3566 3566
 	 */
3567
-	public function has_relation($relation_name){
3567
+	public function has_relation($relation_name) {
3568 3568
 		$relations = $this->relation_settings();
3569
-		if(isset($relations[$relation_name])){
3569
+		if (isset($relations[$relation_name])) {
3570 3570
 			return true;
3571
-		}else{
3571
+		} else {
3572 3572
 			return false;
3573 3573
 		}
3574 3574
 	}
@@ -3580,7 +3580,7 @@  discard block
 block discarded – undo
3580 3580
 	 * @param $field_obj
3581 3581
 	 * @return EE_Model_Field_Base
3582 3582
 	 */
3583
-	public function is_primary_key_field( $field_obj ){
3583
+	public function is_primary_key_field($field_obj) {
3584 3584
 		return $field_obj instanceof EE_Primary_Key_Field_Base ? TRUE : FALSE;
3585 3585
 	}
3586 3586
 
@@ -3592,16 +3592,16 @@  discard block
 block discarded – undo
3592 3592
 	 * @return EE_Model_Field_Base
3593 3593
 	 * @throws EE_Error
3594 3594
 	 */
3595
-	public function get_primary_key_field(){
3596
-		if( $this->_primary_key_field === NULL ){
3597
-			foreach( $this->field_settings( TRUE ) as $field_obj ){
3598
-				if( $this->is_primary_key_field( $field_obj )){
3595
+	public function get_primary_key_field() {
3596
+		if ($this->_primary_key_field === NULL) {
3597
+			foreach ($this->field_settings(TRUE) as $field_obj) {
3598
+				if ($this->is_primary_key_field($field_obj)) {
3599 3599
 					$this->_primary_key_field = $field_obj;
3600 3600
 					break;
3601 3601
 				}
3602 3602
 			}
3603
-			if( ! $this->_primary_key_field instanceof EE_Primary_Key_Field_Base ){
3604
-				throw new EE_Error(sprintf(__("There is no Primary Key defined on model %s",'event_espresso'),get_class($this)));
3603
+			if ( ! $this->_primary_key_field instanceof EE_Primary_Key_Field_Base) {
3604
+				throw new EE_Error(sprintf(__("There is no Primary Key defined on model %s", 'event_espresso'), get_class($this)));
3605 3605
 			}
3606 3606
 		}
3607 3607
 		return $this->_primary_key_field;
@@ -3614,12 +3614,12 @@  discard block
 block discarded – undo
3614 3614
 	 * Internally does some caching.
3615 3615
 	 * @return boolean
3616 3616
 	 */
3617
-	public function has_primary_key_field(){
3618
-		if($this->_has_primary_key_field === null){
3619
-			try{
3617
+	public function has_primary_key_field() {
3618
+		if ($this->_has_primary_key_field === null) {
3619
+			try {
3620 3620
 				$this->get_primary_key_field();
3621 3621
 				$this->_has_primary_key_field = true;
3622
-			}catch(EE_Error $e){
3622
+			} catch (EE_Error $e) {
3623 3623
 				$this->_has_primary_key_field = false;
3624 3624
 			}
3625 3625
 		}
@@ -3633,9 +3633,9 @@  discard block
 block discarded – undo
3633 3633
 	 * @param string $field_class_name class name of field that you want to find. Eg, EE_Datetime_Field, EE_Foreign_Key_Field, etc
3634 3634
 	 * @return EE_Model_Field_Base or null if none is found
3635 3635
 	 */
3636
-	public function get_a_field_of_type($field_class_name){
3637
-		foreach($this->field_settings() as $field){
3638
-			if( $field instanceof $field_class_name ){
3636
+	public function get_a_field_of_type($field_class_name) {
3637
+		foreach ($this->field_settings() as $field) {
3638
+			if ($field instanceof $field_class_name) {
3639 3639
 				return $field;
3640 3640
 			}
3641 3641
 		}
@@ -3649,21 +3649,21 @@  discard block
 block discarded – undo
3649 3649
 	 * @return EE_Foreign_Key_Field_Base
3650 3650
 	 * @throws EE_Error
3651 3651
 	 */
3652
-	public function get_foreign_key_to($model_name){
3653
-		if( ! isset( $this->_cache_foreign_key_to_fields[ $model_name ] ) ){
3654
-			foreach($this->field_settings() as $field){
3652
+	public function get_foreign_key_to($model_name) {
3653
+		if ( ! isset($this->_cache_foreign_key_to_fields[$model_name])) {
3654
+			foreach ($this->field_settings() as $field) {
3655 3655
 //				if(is_subclass_of($field, 'EE_Foreign_Key_Field_Base')){
3656
-				if( $field instanceof EE_Foreign_Key_Field_Base ){
3657
-					if (in_array($model_name,$field->get_model_names_pointed_to() ) ) {
3658
-						$this->_cache_foreign_key_to_fields[ $model_name ] = $field;
3656
+				if ($field instanceof EE_Foreign_Key_Field_Base) {
3657
+					if (in_array($model_name, $field->get_model_names_pointed_to())) {
3658
+						$this->_cache_foreign_key_to_fields[$model_name] = $field;
3659 3659
 					}
3660 3660
 				}
3661 3661
 			}
3662
-			if( ! isset( $this->_cache_foreign_key_to_fields[ $model_name ] ) ){
3663
-				throw new EE_Error(sprintf(__("There is no foreign key field pointing to model %s on model %s",'event_espresso'),$model_name,get_class($this)));
3662
+			if ( ! isset($this->_cache_foreign_key_to_fields[$model_name])) {
3663
+				throw new EE_Error(sprintf(__("There is no foreign key field pointing to model %s on model %s", 'event_espresso'), $model_name, get_class($this)));
3664 3664
 			}
3665 3665
 		}
3666
-		return $this->_cache_foreign_key_to_fields[ $model_name ];
3666
+		return $this->_cache_foreign_key_to_fields[$model_name];
3667 3667
 	}
3668 3668
 
3669 3669
 
@@ -3674,7 +3674,7 @@  discard block
 block discarded – undo
3674 3674
 	 * a table alias with a model chain prefix, like 'Venue__Event_Venue___Event_Meta'. Either one works
3675 3675
 	 * @return EE_Table_Base
3676 3676
 	 */
3677
-	function get_table_for_alias($table_alias){
3677
+	function get_table_for_alias($table_alias) {
3678 3678
 		$table_alias_sans_model_relation_chain_prefix = EE_Model_Parser::remove_table_alias_model_relation_chain_prefix($table_alias);
3679 3679
 		return $this->_tables[$table_alias_sans_model_relation_chain_prefix]->get_table_name();
3680 3680
 	}
@@ -3687,25 +3687,25 @@  discard block
 block discarded – undo
3687 3687
 	 * @param bool $include_db_only_fields flag indicating whether or not to include the db-only fields
3688 3688
 	 * @return EE_Model_Field_Base[] where the keys are the field's name
3689 3689
 	 */
3690
-	public function field_settings($include_db_only_fields = false){
3691
-		if( $include_db_only_fields ){
3692
-			if( $this->_cached_fields === NULL ){
3690
+	public function field_settings($include_db_only_fields = false) {
3691
+		if ($include_db_only_fields) {
3692
+			if ($this->_cached_fields === NULL) {
3693 3693
 				$this->_cached_fields = array();
3694
-				foreach($this->_fields as $fields_corresponding_to_table){
3695
-					foreach($fields_corresponding_to_table as $field_name => $field_obj){
3696
-						$this->_cached_fields[$field_name]=$field_obj;
3694
+				foreach ($this->_fields as $fields_corresponding_to_table) {
3695
+					foreach ($fields_corresponding_to_table as $field_name => $field_obj) {
3696
+						$this->_cached_fields[$field_name] = $field_obj;
3697 3697
 					}
3698 3698
 				}
3699 3699
 			}
3700 3700
 			return $this->_cached_fields;
3701
-		}else{
3702
-			if( $this->_cached_fields_non_db_only === NULL ){
3701
+		} else {
3702
+			if ($this->_cached_fields_non_db_only === NULL) {
3703 3703
 				$this->_cached_fields_non_db_only = array();
3704
-				foreach($this->_fields as $fields_corresponding_to_table){
3705
-					foreach($fields_corresponding_to_table as $field_name => $field_obj){
3704
+				foreach ($this->_fields as $fields_corresponding_to_table) {
3705
+					foreach ($fields_corresponding_to_table as $field_name => $field_obj) {
3706 3706
 						/** @var $field_obj EE_Model_Field_Base */
3707
-						if( ! $field_obj->is_db_only_field() ){
3708
-							$this->_cached_fields_non_db_only[$field_name]=$field_obj;
3707
+						if ( ! $field_obj->is_db_only_field()) {
3708
+							$this->_cached_fields_non_db_only[$field_name] = $field_obj;
3709 3709
 						}
3710 3710
 					}
3711 3711
 				}
@@ -3724,67 +3724,67 @@  discard block
 block discarded – undo
3724 3724
 	 * @return \EE_Base_Class[] array keys are primary keys (if there is a primary key on the model. if not, numerically indexed)
3725 3725
 	 * @throws \EE_Error
3726 3726
 	 */
3727
-	protected function _create_objects( $rows = array() ) {
3728
-		$array_of_objects=array();
3729
-		if(empty($rows)){
3727
+	protected function _create_objects($rows = array()) {
3728
+		$array_of_objects = array();
3729
+		if (empty($rows)) {
3730 3730
 			return array();
3731 3731
 		}
3732 3732
 		$count_if_model_has_no_primary_key = 0;
3733 3733
 		$has_primary_key = $this->has_primary_key_field();
3734
-		if( $has_primary_key ) {
3734
+		if ($has_primary_key) {
3735 3735
 			$primary_key_field = $this->get_primary_key_field();
3736 3736
 		} else {
3737 3737
 			$primary_key_field = null;
3738 3738
 		}
3739
-		foreach ( $rows as $row ) {
3740
-			if(empty($row)){
3739
+		foreach ($rows as $row) {
3740
+			if (empty($row)) {
3741 3741
 				//wp did its weird thing where it returns an array like array(0=>null), which is totally not helpful...
3742 3742
 				return array();
3743 3743
 			}
3744 3744
 			//check if we've already set this object in the results array,
3745 3745
 			//in which case there's no need to process it further (again)
3746
-			if( $has_primary_key ) {
3746
+			if ($has_primary_key) {
3747 3747
 				$table_pk_value = $this->_get_column_value_with_table_alias_or_not(
3748 3748
 					$row,
3749 3749
 					$primary_key_field->get_qualified_column(),
3750 3750
 					$primary_key_field->get_table_column()
3751 3751
 				);
3752
-				if( $table_pk_value &&
3753
-					isset( $array_of_objects[ $table_pk_value ] ) ) {
3752
+				if ($table_pk_value &&
3753
+					isset($array_of_objects[$table_pk_value])) {
3754 3754
 					continue;
3755 3755
 				}
3756 3756
 			}
3757
-			$classInstance=$this->instantiate_class_from_array_or_object($row);
3758
-			if( ! $classInstance ) {
3757
+			$classInstance = $this->instantiate_class_from_array_or_object($row);
3758
+			if ( ! $classInstance) {
3759 3759
 				throw new EE_Error(
3760 3760
 					sprintf(
3761
-						__( 'Could not create instance of class %s from row %s', 'event_espresso' ),
3761
+						__('Could not create instance of class %s from row %s', 'event_espresso'),
3762 3762
 						$this->get_this_model_name(),
3763
-						http_build_query( $row )
3763
+						http_build_query($row)
3764 3764
 					)
3765 3765
 				);
3766 3766
 			}
3767 3767
 			//set the timezone on the instantiated objects
3768
-			$classInstance->set_timezone( $this->_timezone );
3768
+			$classInstance->set_timezone($this->_timezone);
3769 3769
 			//make sure if there is any timezone setting present that we set the timezone for the object
3770 3770
 			$key = $has_primary_key ? $classInstance->ID() : $count_if_model_has_no_primary_key++;
3771
-			$array_of_objects[ $key ] = $classInstance;
3771
+			$array_of_objects[$key] = $classInstance;
3772 3772
 			//also, for all the relations of type BelongsTo, see if we can cache
3773 3773
 			//those related models
3774 3774
 			//(we could do this for other relations too, but if there are conditions
3775 3775
 			//that filtered out some fo the results, then we'd be caching an incomplete set
3776 3776
 			//so it requires a little more thought than just caching them immediately...)
3777
-			foreach($this->_model_relations as $modelName => $relation_obj){
3778
-				if( $relation_obj instanceof EE_Belongs_To_Relation){
3777
+			foreach ($this->_model_relations as $modelName => $relation_obj) {
3778
+				if ($relation_obj instanceof EE_Belongs_To_Relation) {
3779 3779
 					//check if this model's INFO is present. If so, cache it on the model
3780 3780
 					$other_model = $relation_obj->get_other_model();
3781 3781
 
3782 3782
 					$other_model_obj_maybe = $other_model->instantiate_class_from_array_or_object($row);
3783 3783
 
3784 3784
 					//if we managed to make a model object from the results, cache it on the main model object
3785
-					if( $other_model_obj_maybe ){
3785
+					if ($other_model_obj_maybe) {
3786 3786
 						//set timezone on these other model objects if they are present
3787
-						$other_model_obj_maybe->set_timezone( $this->_timezone );
3787
+						$other_model_obj_maybe->set_timezone($this->_timezone);
3788 3788
 						$classInstance->cache($modelName, $other_model_obj_maybe);
3789 3789
 					}
3790 3790
 				}
@@ -3805,12 +3805,12 @@  discard block
 block discarded – undo
3805 3805
 
3806 3806
 		$this_model_fields_and_values = array();
3807 3807
 		//setup the row using default values;
3808
-		foreach ( $this->field_settings() as $field_name => $field_obj ) {
3808
+		foreach ($this->field_settings() as $field_name => $field_obj) {
3809 3809
 			$this_model_fields_and_values[$field_name] = $field_obj->get_default_value();
3810 3810
 		}
3811 3811
 
3812 3812
 		$className = $this->_get_class_name();
3813
-		$classInstance = EE_Registry::instance()->load_class( $className, array( $this_model_fields_and_values ), FALSE, FALSE );
3813
+		$classInstance = EE_Registry::instance()->load_class($className, array($this_model_fields_and_values), FALSE, FALSE);
3814 3814
 
3815 3815
 		return $classInstance;
3816 3816
 	}
@@ -3823,45 +3823,45 @@  discard block
 block discarded – undo
3823 3823
 	 * or an stdClass where each property is the name of a column,
3824 3824
 	 * @return EE_Base_Class
3825 3825
 	 */
3826
-	public function instantiate_class_from_array_or_object($cols_n_values){
3827
-		if( ! is_array( $cols_n_values ) && is_object( $cols_n_values )) {
3828
-			$cols_n_values = get_object_vars( $cols_n_values );
3826
+	public function instantiate_class_from_array_or_object($cols_n_values) {
3827
+		if ( ! is_array($cols_n_values) && is_object($cols_n_values)) {
3828
+			$cols_n_values = get_object_vars($cols_n_values);
3829 3829
 		}
3830 3830
 		$primary_key = NULL;
3831 3831
 		//make sure the array only has keys that are fields/columns on this model
3832
-		$this_model_fields_n_values = $this->_deduce_fields_n_values_from_cols_n_values( $cols_n_values );
3833
-		if( $this->has_primary_key_field() && isset( $this_model_fields_n_values[ $this->primary_key_name() ] ) ){
3834
-			$primary_key = $this_model_fields_n_values[ $this->primary_key_name() ];
3832
+		$this_model_fields_n_values = $this->_deduce_fields_n_values_from_cols_n_values($cols_n_values);
3833
+		if ($this->has_primary_key_field() && isset($this_model_fields_n_values[$this->primary_key_name()])) {
3834
+			$primary_key = $this_model_fields_n_values[$this->primary_key_name()];
3835 3835
 		}
3836
-		$className=$this->_get_class_name();
3836
+		$className = $this->_get_class_name();
3837 3837
 
3838 3838
 		//check we actually found results that we can use to build our model object
3839 3839
 		//if not, return null
3840
-		if( $this->has_primary_key_field()){
3841
-			if(empty( $this_model_fields_n_values[$this->primary_key_name()] )){
3840
+		if ($this->has_primary_key_field()) {
3841
+			if (empty($this_model_fields_n_values[$this->primary_key_name()])) {
3842 3842
 				return NULL;
3843 3843
 			}
3844
-		}else if($this->unique_indexes()){
3844
+		} else if ($this->unique_indexes()) {
3845 3845
 			$first_column = reset($this_model_fields_n_values);
3846
-			if(empty($first_column)){
3846
+			if (empty($first_column)) {
3847 3847
 				return NULL;
3848 3848
 			}
3849 3849
 		}
3850 3850
 
3851 3851
 		// if there is no primary key or the object doesn't already exist in the entity map, then create a new instance
3852
-		if ( $primary_key){
3853
-			$classInstance = $this->get_from_entity_map( $primary_key );
3854
-			if( ! $classInstance) {
3855
-				$classInstance = EE_Registry::instance()->load_class( $className, array( $this_model_fields_n_values, $this->_timezone ), TRUE, FALSE );
3852
+		if ($primary_key) {
3853
+			$classInstance = $this->get_from_entity_map($primary_key);
3854
+			if ( ! $classInstance) {
3855
+				$classInstance = EE_Registry::instance()->load_class($className, array($this_model_fields_n_values, $this->_timezone), TRUE, FALSE);
3856 3856
 				// add this new object to the entity map
3857
-				$classInstance = $this->add_to_entity_map( $classInstance );
3857
+				$classInstance = $this->add_to_entity_map($classInstance);
3858 3858
 			}
3859
-		}else{
3860
-			$classInstance = EE_Registry::instance()->load_class( $className, array( $this_model_fields_n_values, $this->_timezone ), TRUE, FALSE );
3859
+		} else {
3860
+			$classInstance = EE_Registry::instance()->load_class($className, array($this_model_fields_n_values, $this->_timezone), TRUE, FALSE);
3861 3861
 		}
3862 3862
 
3863 3863
 			//it is entirely possible that the instantiated class object has a set timezone_string db field and has set it's internal _timezone property accordingly (see new_instance_from_db in model objects particularly EE_Event for example).  In this case, we want to make sure the model object doesn't have its timezone string overwritten by any timezone property currently set here on the model so, we intentionally override the model _timezone property with the model_object timezone property.
3864
-		$this->set_timezone( $classInstance->get_timezone() );
3864
+		$this->set_timezone($classInstance->get_timezone());
3865 3865
 		return $classInstance;
3866 3866
 	}
3867 3867
 	/**
@@ -3869,8 +3869,8 @@  discard block
 block discarded – undo
3869 3869
 	 * @param int|string $id the ID of the model object
3870 3870
 	 * @return EE_Base_Class
3871 3871
 	 */
3872
-	public function get_from_entity_map( $id ){
3873
-		return isset( $this->_entity_map[ $id ] ) ? $this->_entity_map[ $id ] : NULL;
3872
+	public function get_from_entity_map($id) {
3873
+		return isset($this->_entity_map[$id]) ? $this->_entity_map[$id] : NULL;
3874 3874
 	}
3875 3875
 
3876 3876
 
@@ -3889,21 +3889,21 @@  discard block
 block discarded – undo
3889 3889
 	 * @throws EE_Error
3890 3890
 	 * @return \EE_Base_Class
3891 3891
 	 */
3892
-	public function add_to_entity_map( EE_Base_Class $object) {
3892
+	public function add_to_entity_map(EE_Base_Class $object) {
3893 3893
 		$className = $this->_get_class_name();
3894
-		if( ! $object instanceof $className ){
3895
-			throw new EE_Error(sprintf(__("You tried adding a %s to a mapping of %ss", "event_espresso"),is_object( $object ) ? get_class( $object ) : $object, $className ) );
3894
+		if ( ! $object instanceof $className) {
3895
+			throw new EE_Error(sprintf(__("You tried adding a %s to a mapping of %ss", "event_espresso"), is_object($object) ? get_class($object) : $object, $className));
3896 3896
 		}
3897 3897
 		/** @var $object EE_Base_Class */
3898
-		if ( ! $object->ID() ){
3899
-			throw new EE_Error(sprintf(__("You tried storing a model object with NO ID in the %s entity mapper.", "event_espresso"),get_class($this)));
3898
+		if ( ! $object->ID()) {
3899
+			throw new EE_Error(sprintf(__("You tried storing a model object with NO ID in the %s entity mapper.", "event_espresso"), get_class($this)));
3900 3900
 		}
3901 3901
 		// double check it's not already there
3902
-		$classInstance = $this->get_from_entity_map( $object->ID() );
3903
-		if ( $classInstance ) {
3902
+		$classInstance = $this->get_from_entity_map($object->ID());
3903
+		if ($classInstance) {
3904 3904
 			return $classInstance;
3905 3905
 		} else {
3906
-			$this->_entity_map[ $object->ID() ] = $object;
3906
+			$this->_entity_map[$object->ID()] = $object;
3907 3907
 			return $object;
3908 3908
 		}
3909 3909
 	}
@@ -3916,8 +3916,8 @@  discard block
 block discarded – undo
3916 3916
 	 * @param array $cols_n_values
3917 3917
 	 * @return array
3918 3918
 	 */
3919
-	public function deduce_fields_n_values_from_cols_n_values( $cols_n_values ) {
3920
-		return $this->_deduce_fields_n_values_from_cols_n_values( $cols_n_values );
3919
+	public function deduce_fields_n_values_from_cols_n_values($cols_n_values) {
3920
+		return $this->_deduce_fields_n_values_from_cols_n_values($cols_n_values);
3921 3921
 	}
3922 3922
 
3923 3923
 
@@ -3930,40 +3930,40 @@  discard block
 block discarded – undo
3930 3930
 	 * @param string $cols_n_values
3931 3931
 	 * @return array
3932 3932
 	 */
3933
-	protected function _deduce_fields_n_values_from_cols_n_values( $cols_n_values ){
3933
+	protected function _deduce_fields_n_values_from_cols_n_values($cols_n_values) {
3934 3934
 		$this_model_fields_n_values = array();
3935
-		foreach( $this->get_tables() as $table_alias => $table_obj ) {
3936
-			$table_pk_value = $this->_get_column_value_with_table_alias_or_not($cols_n_values, $table_obj->get_fully_qualified_pk_column(), $table_obj->get_pk_column() );
3935
+		foreach ($this->get_tables() as $table_alias => $table_obj) {
3936
+			$table_pk_value = $this->_get_column_value_with_table_alias_or_not($cols_n_values, $table_obj->get_fully_qualified_pk_column(), $table_obj->get_pk_column());
3937 3937
 			//there is a primary key on this table and its not set. Use defaults for all its columns
3938
-			if( $table_obj->get_pk_column() && $table_pk_value === NULL ){
3939
-				foreach( $this->_get_fields_for_table( $table_alias ) as $field_name => $field_obj ) {
3940
-					if( ! $field_obj->is_db_only_field() ){
3938
+			if ($table_obj->get_pk_column() && $table_pk_value === NULL) {
3939
+				foreach ($this->_get_fields_for_table($table_alias) as $field_name => $field_obj) {
3940
+					if ( ! $field_obj->is_db_only_field()) {
3941 3941
 						//prepare field as if its coming from db
3942
-						$prepared_value = $field_obj->prepare_for_set( $field_obj->get_default_value() );
3943
-						$this_model_fields_n_values[$field_name] = $field_obj->prepare_for_use_in_db( $prepared_value );
3942
+						$prepared_value = $field_obj->prepare_for_set($field_obj->get_default_value());
3943
+						$this_model_fields_n_values[$field_name] = $field_obj->prepare_for_use_in_db($prepared_value);
3944 3944
 					}
3945 3945
 				}
3946
-			}else{
3946
+			} else {
3947 3947
 				//the table's rows existed. Use their values
3948
-				foreach( $this->_get_fields_for_table( $table_alias ) as $field_name => $field_obj ) {
3949
-					if( ! $field_obj->is_db_only_field() )
3950
-					$this_model_fields_n_values[$field_name] = $this->_get_column_value_with_table_alias_or_not($cols_n_values, $field_obj->get_qualified_column(), $field_obj->get_table_column() );
3948
+				foreach ($this->_get_fields_for_table($table_alias) as $field_name => $field_obj) {
3949
+					if ( ! $field_obj->is_db_only_field())
3950
+					$this_model_fields_n_values[$field_name] = $this->_get_column_value_with_table_alias_or_not($cols_n_values, $field_obj->get_qualified_column(), $field_obj->get_table_column());
3951 3951
 				}
3952 3952
 			}
3953 3953
 		}
3954 3954
 		return $this_model_fields_n_values;
3955 3955
 	}
3956 3956
 
3957
-	protected function _get_column_value_with_table_alias_or_not( $cols_n_values, $qualified_column, $regular_column ){
3957
+	protected function _get_column_value_with_table_alias_or_not($cols_n_values, $qualified_column, $regular_column) {
3958 3958
 		//ask the field what it think it's table_name.column_name should be, and call it the "qualified column"
3959 3959
 		//does the field on the model relate to this column retrieved from the db?
3960 3960
 		//or is it a db-only field? (not relating to the model)
3961
-		if( isset( $cols_n_values[ $qualified_column ] ) ){
3962
-			$value = $cols_n_values[ $qualified_column ];
3961
+		if (isset($cols_n_values[$qualified_column])) {
3962
+			$value = $cols_n_values[$qualified_column];
3963 3963
 
3964
-		}elseif( isset( $cols_n_values[ $regular_column ] ) ){
3965
-			$value = $cols_n_values[ $regular_column ];
3966
-		}else{
3964
+		}elseif (isset($cols_n_values[$regular_column])) {
3965
+			$value = $cols_n_values[$regular_column];
3966
+		} else {
3967 3967
 			$value = NULL;
3968 3968
 		}
3969 3969
 
@@ -3981,23 +3981,23 @@  discard block
 block discarded – undo
3981 3981
 	 * @param int|string $id
3982 3982
 	 * @return EE_Base_Class
3983 3983
 	 */
3984
-	public function refresh_entity_map_from_db( $id ){
3985
-		$obj_in_map = $this->get_from_entity_map( $id );
3986
-		if( $obj_in_map ){
3987
-			$wpdb_results = $this->_get_all_wpdb_results( array( array ( $this->get_primary_key_field()->get_name() => $id ), 'limit' => 1 ) );
3988
-			if( $wpdb_results && is_array( $wpdb_results ) ){
3989
-				$one_row = reset( $wpdb_results );
3990
-				foreach( $this->_deduce_fields_n_values_from_cols_n_values($one_row ) as $field_name => $db_value ) {
3991
-					$obj_in_map->set_from_db( $field_name, $db_value );
3984
+	public function refresh_entity_map_from_db($id) {
3985
+		$obj_in_map = $this->get_from_entity_map($id);
3986
+		if ($obj_in_map) {
3987
+			$wpdb_results = $this->_get_all_wpdb_results(array(array($this->get_primary_key_field()->get_name() => $id), 'limit' => 1));
3988
+			if ($wpdb_results && is_array($wpdb_results)) {
3989
+				$one_row = reset($wpdb_results);
3990
+				foreach ($this->_deduce_fields_n_values_from_cols_n_values($one_row) as $field_name => $db_value) {
3991
+					$obj_in_map->set_from_db($field_name, $db_value);
3992 3992
 				}
3993 3993
 				//clear the cache of related model objects
3994
-				foreach ( $this->relation_settings() as $relation_name => $relation_obj ){
3995
-					$obj_in_map->clear_cache($relation_name, NULL, TRUE );
3994
+				foreach ($this->relation_settings() as $relation_name => $relation_obj) {
3995
+					$obj_in_map->clear_cache($relation_name, NULL, TRUE);
3996 3996
 				}
3997 3997
 			}
3998 3998
 			return $obj_in_map;
3999
-		}else{
4000
-			return $this->get_one_by_ID( $id );
3999
+		} else {
4000
+			return $this->get_one_by_ID($id);
4001 4001
 		}
4002 4002
 	}
4003 4003
 
@@ -4015,24 +4015,24 @@  discard block
 block discarded – undo
4015 4015
 	 * @param EE_Base_Class $replacing_model_obj
4016 4016
 	 * @return \EE_Base_Class
4017 4017
 	 */
4018
-	public function refresh_entity_map_with( $id, $replacing_model_obj ) {
4019
-		$obj_in_map = $this->get_from_entity_map( $id );
4020
-		if( $obj_in_map ){
4021
-			if( $replacing_model_obj instanceof EE_Base_Class ){
4022
-				foreach( $replacing_model_obj->model_field_array() as $field_name => $value ) {
4023
-					$obj_in_map->set( $field_name, $value );
4018
+	public function refresh_entity_map_with($id, $replacing_model_obj) {
4019
+		$obj_in_map = $this->get_from_entity_map($id);
4020
+		if ($obj_in_map) {
4021
+			if ($replacing_model_obj instanceof EE_Base_Class) {
4022
+				foreach ($replacing_model_obj->model_field_array() as $field_name => $value) {
4023
+					$obj_in_map->set($field_name, $value);
4024 4024
 				}
4025 4025
 				//make the model object in the entity map's cache match the $replacing_model_obj
4026
-				foreach ( $this->relation_settings() as $relation_name => $relation_obj ){
4027
-					$obj_in_map->clear_cache($relation_name, NULL, TRUE );
4028
-					foreach( $replacing_model_obj->get_all_from_cache( $relation_name ) as $cache_id => $cached_obj ) {
4029
-						$obj_in_map->cache( $relation_name, $cached_obj, $cache_id );
4026
+				foreach ($this->relation_settings() as $relation_name => $relation_obj) {
4027
+					$obj_in_map->clear_cache($relation_name, NULL, TRUE);
4028
+					foreach ($replacing_model_obj->get_all_from_cache($relation_name) as $cache_id => $cached_obj) {
4029
+						$obj_in_map->cache($relation_name, $cached_obj, $cache_id);
4030 4030
 					}
4031 4031
 				}
4032 4032
 			}
4033 4033
 			return $obj_in_map;
4034
-		}else{
4035
-			$this->add_to_entity_map( $replacing_model_obj );
4034
+		} else {
4035
+			$this->add_to_entity_map($replacing_model_obj);
4036 4036
 			return $replacing_model_obj;
4037 4037
 		}
4038 4038
 	}
@@ -4045,7 +4045,7 @@  discard block
 block discarded – undo
4045 4045
 	 * require_once($this->_getClassName().".class.php");
4046 4046
 	 * @return string
4047 4047
 	 */
4048
-	private function _get_class_name(){
4048
+	private function _get_class_name() {
4049 4049
 		return "EE_".$this->get_this_model_name();
4050 4050
 	}
4051 4051
 
@@ -4058,10 +4058,10 @@  discard block
 block discarded – undo
4058 4058
 	 * @param int $quantity
4059 4059
 	 * @return string
4060 4060
 	 */
4061
-	public function item_name($quantity = 1){
4062
-		if($quantity == 1){
4061
+	public function item_name($quantity = 1) {
4062
+		if ($quantity == 1) {
4063 4063
 			return $this->singular_item;
4064
-		}else{
4064
+		} else {
4065 4065
 			return $this->plural_item;
4066 4066
 		}
4067 4067
 	}
@@ -4090,13 +4090,13 @@  discard block
 block discarded – undo
4090 4090
 	 * @throws EE_Error
4091 4091
 	 * @return mixed whatever the plugin which calls add_filter decides
4092 4092
 	 */
4093
-	public function __call($methodName,$args){
4094
-		$className=get_class($this);
4095
-		$tagName="FHEE__{$className}__{$methodName}";
4096
-		if(!has_filter($tagName)){
4093
+	public function __call($methodName, $args) {
4094
+		$className = get_class($this);
4095
+		$tagName = "FHEE__{$className}__{$methodName}";
4096
+		if ( ! has_filter($tagName)) {
4097 4097
 			throw new EE_Error(
4098 4098
 				sprintf(
4099
-					__( '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' ),
4099
+					__('Method %1$s on model %2$s does not exist! You can create one with the following code in functions.php or in a plugin: %4$s function my_callback(%4$s \$previousReturnValue, EEM_Base \$object\ $argsArray=NULL ){%4$s     /*function body*/%4$s      return \$whatever;%4$s }%4$s add_filter( \'%3$s\', \'my_callback\', 10, 3 );', 'event_espresso'),
4100 4100
 					$methodName,
4101 4101
 					$className,
4102 4102
 					$tagName,
@@ -4105,7 +4105,7 @@  discard block
 block discarded – undo
4105 4105
 			);
4106 4106
 		}
4107 4107
 
4108
-		return apply_filters($tagName,null,$this,$args);
4108
+		return apply_filters($tagName, null, $this, $args);
4109 4109
 	}
4110 4110
 
4111 4111
 
@@ -4118,22 +4118,22 @@  discard block
 block discarded – undo
4118 4118
 	 * @throws EE_Error
4119 4119
 	 * @return EE_Base_Class
4120 4120
 	 */
4121
-	public function ensure_is_obj( $base_class_obj_or_id, $ensure_is_in_db = FALSE ){
4121
+	public function ensure_is_obj($base_class_obj_or_id, $ensure_is_in_db = FALSE) {
4122 4122
 		$className = $this->_get_class_name();
4123 4123
 		$primary_key_field = $this->get_primary_key_field();
4124
-		if( $base_class_obj_or_id instanceof $className ){
4124
+		if ($base_class_obj_or_id instanceof $className) {
4125 4125
 			$model_object = $base_class_obj_or_id;
4126
-		}elseif( $primary_key_field instanceof EE_Primary_Key_Int_Field && (
4127
-				is_int( $base_class_obj_or_id ) ||
4128
-				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)
4126
+		}elseif ($primary_key_field instanceof EE_Primary_Key_Int_Field && (
4127
+				is_int($base_class_obj_or_id) ||
4128
+				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)
4129 4129
 			$model_object = $this->get_one_by_ID($base_class_obj_or_id);
4130
-		}elseif( $primary_key_field instanceof EE_Primary_Key_String_Field && is_string($base_class_obj_or_id) ){
4130
+		}elseif ($primary_key_field instanceof EE_Primary_Key_String_Field && is_string($base_class_obj_or_id)) {
4131 4131
 			//assume its a string representation of the object
4132 4132
 			$model_object = $this->get_one_by_ID($base_class_obj_or_id);
4133
-		}else{
4134
-			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)));
4133
+		} else {
4134
+			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)));
4135 4135
 		}
4136
-		if( $model_object->ID() == NULL && $ensure_is_in_db){
4136
+		if ($model_object->ID() == NULL && $ensure_is_in_db) {
4137 4137
 			$model_object->save();
4138 4138
 		}
4139 4139
 		return $model_object;
@@ -4149,19 +4149,19 @@  discard block
 block discarded – undo
4149 4149
 	 * @return int|string depending on the type of this model object's ID
4150 4150
 	 * @throws EE_Error
4151 4151
 	 */
4152
-	public function ensure_is_ID($base_class_obj_or_id){
4152
+	public function ensure_is_ID($base_class_obj_or_id) {
4153 4153
 		$className = $this->_get_class_name();
4154
-		if( $base_class_obj_or_id instanceof $className ){
4154
+		if ($base_class_obj_or_id instanceof $className) {
4155 4155
 			/** @var $base_class_obj_or_id EE_Base_Class */
4156 4156
 			$id = $base_class_obj_or_id->ID();
4157
-		}elseif(is_int($base_class_obj_or_id)){
4157
+		}elseif (is_int($base_class_obj_or_id)) {
4158 4158
 			//assume it's an ID
4159 4159
 			$id = $base_class_obj_or_id;
4160
-		}elseif(is_string($base_class_obj_or_id)){
4160
+		}elseif (is_string($base_class_obj_or_id)) {
4161 4161
 			//assume its a string representation of the object
4162 4162
 			$id = $base_class_obj_or_id;
4163
-		}else{
4164
-			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)));
4163
+		} else {
4164
+			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)));
4165 4165
 		}
4166 4166
 		return $id;
4167 4167
 	}
@@ -4184,14 +4184,14 @@  discard block
 block discarded – undo
4184 4184
 	 * @param int $values_already_prepared like one of the constants on EEM_Base
4185 4185
 	 * @return void
4186 4186
 	 */
4187
-	public function assume_values_already_prepared_by_model_object($values_already_prepared = self::not_prepared_by_model_object){
4187
+	public function assume_values_already_prepared_by_model_object($values_already_prepared = self::not_prepared_by_model_object) {
4188 4188
 		$this->_values_already_prepared_by_model_object = $values_already_prepared;
4189 4189
 	}
4190 4190
 	/**
4191 4191
 	 * Read comments for assume_values_already_prepared_by_model_object()
4192 4192
 	 * @return int
4193 4193
 	 */
4194
-	public function get_assumption_concerning_values_already_prepared_by_model_object(){
4194
+	public function get_assumption_concerning_values_already_prepared_by_model_object() {
4195 4195
 		return $this->_values_already_prepared_by_model_object;
4196 4196
 	}
4197 4197
 
@@ -4199,17 +4199,17 @@  discard block
 block discarded – undo
4199 4199
 	 * Gets all the indexes on this model
4200 4200
 	 * @return EE_Index[]
4201 4201
 	 */
4202
-	public function indexes(){
4202
+	public function indexes() {
4203 4203
 		return $this->_indexes;
4204 4204
 	}
4205 4205
 	/**
4206 4206
 	 * Gets all the Unique Indexes on this model
4207 4207
 	 * @return EE_Unique_Index[]
4208 4208
 	 */
4209
-	public function unique_indexes(){
4209
+	public function unique_indexes() {
4210 4210
 		$unique_indexes = array();
4211
-		foreach($this->_indexes as $name => $index){
4212
-			if($index instanceof EE_Unique_Index){
4211
+		foreach ($this->_indexes as $name => $index) {
4212
+			if ($index instanceof EE_Unique_Index) {
4213 4213
 				$unique_indexes [$name] = $index;
4214 4214
 			}
4215 4215
 		}
@@ -4222,13 +4222,13 @@  discard block
 block discarded – undo
4222 4222
 	 * on a primary index
4223 4223
 	 * @return EE_Model_Field_Base[]
4224 4224
 	 */
4225
-	public function get_combined_primary_key_fields(){
4226
-		foreach($this->indexes() as $index){
4227
-			if($index instanceof EE_Primary_Key_Index){
4225
+	public function get_combined_primary_key_fields() {
4226
+		foreach ($this->indexes() as $index) {
4227
+			if ($index instanceof EE_Primary_Key_Index) {
4228 4228
 				return $index->fields();
4229 4229
 			}
4230 4230
 		}
4231
-		return array( $this->primary_key_name() => $this->get_primary_key_field());
4231
+		return array($this->primary_key_name() => $this->get_primary_key_field());
4232 4232
 	}
4233 4233
 	
4234 4234
 
@@ -4238,7 +4238,7 @@  discard block
 block discarded – undo
4238 4238
 	 * @param array $cols_n_values keys are field names, values are their values
4239 4239
 	 * @return string
4240 4240
 	 */
4241
-	public function get_index_primary_key_string($cols_n_values){
4241
+	public function get_index_primary_key_string($cols_n_values) {
4242 4242
 		$cols_n_values_for_primary_key_index = array_intersect_key($cols_n_values, $this->get_combined_primary_key_fields());
4243 4243
 		return http_build_query($cols_n_values_for_primary_key_index);
4244 4244
 	}
@@ -4250,13 +4250,13 @@  discard block
 block discarded – undo
4250 4250
 	 * @param string $index_primary_key_string
4251 4251
 	 * @return null|array
4252 4252
 	 */
4253
-	function parse_index_primary_key_string( $index_primary_key_string) {
4253
+	function parse_index_primary_key_string($index_primary_key_string) {
4254 4254
 		$key_fields = $this->get_combined_primary_key_fields();
4255 4255
 		//check all of them are in the $id
4256 4256
 		$key_vals_in_combined_pk = array();
4257
-		parse_str( $index_primary_key_string, $key_vals_in_combined_pk );
4258
-		foreach( $key_fields as $key_field_name => $field_obj ) {
4259
-			if( ! isset( $key_vals_in_combined_pk[ $key_field_name ] ) ){
4257
+		parse_str($index_primary_key_string, $key_vals_in_combined_pk);
4258
+		foreach ($key_fields as $key_field_name => $field_obj) {
4259
+			if ( ! isset($key_vals_in_combined_pk[$key_field_name])) {
4260 4260
 				return NULL;
4261 4261
 			}
4262 4262
 		}
@@ -4269,10 +4269,10 @@  discard block
 block discarded – undo
4269 4269
 	 * @param array $key_vals
4270 4270
 	 * @return boolean
4271 4271
 	 */
4272
-	function has_all_combined_primary_key_fields( $key_vals ) {
4273
-		$keys_it_should_have = array_keys( $this->get_combined_primary_key_fields() );
4274
-		foreach( $keys_it_should_have as $key ){
4275
-			if( ! isset( $key_vals[ $key ] ) ){
4272
+	function has_all_combined_primary_key_fields($key_vals) {
4273
+		$keys_it_should_have = array_keys($this->get_combined_primary_key_fields());
4274
+		foreach ($keys_it_should_have as $key) {
4275
+			if ( ! isset($key_vals[$key])) {
4276 4276
 				return false;
4277 4277
 			}
4278 4278
 		}
@@ -4288,23 +4288,23 @@  discard block
 block discarded – undo
4288 4288
 	 * @throws EE_Error
4289 4289
 	 * @return \EE_Base_Class[] Array keys are object IDs (if there is a primary key on the model. if not, numerically indexed)
4290 4290
 	 */
4291
-	public function get_all_copies($model_object_or_attributes_array, $query_params = array()){
4291
+	public function get_all_copies($model_object_or_attributes_array, $query_params = array()) {
4292 4292
 
4293
-		if($model_object_or_attributes_array instanceof EE_Base_Class){
4293
+		if ($model_object_or_attributes_array instanceof EE_Base_Class) {
4294 4294
 			$attributes_array = $model_object_or_attributes_array->model_field_array();
4295
-		}elseif(is_array($model_object_or_attributes_array)){
4295
+		}elseif (is_array($model_object_or_attributes_array)) {
4296 4296
 			$attributes_array = $model_object_or_attributes_array;
4297
-		}else{
4298
-			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));
4297
+		} else {
4298
+			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));
4299 4299
 		}
4300 4300
 		//even copies obviously won't have the same ID, so remove the primary key
4301 4301
 		//from the WHERE conditions for finding copies (if there is a primary key, of course)
4302
-		if($this->has_primary_key_field() && isset($attributes_array[$this->primary_key_name()])){
4302
+		if ($this->has_primary_key_field() && isset($attributes_array[$this->primary_key_name()])) {
4303 4303
 			unset($attributes_array[$this->primary_key_name()]);
4304 4304
 		}
4305
-		if(isset($query_params[0])){
4306
-			$query_params[0] = array_merge($attributes_array,$query_params);
4307
-		}else{
4305
+		if (isset($query_params[0])) {
4306
+			$query_params[0] = array_merge($attributes_array, $query_params);
4307
+		} else {
4308 4308
 			$query_params[0] = $attributes_array;
4309 4309
 		}
4310 4310
 		return $this->get_all($query_params);
@@ -4318,16 +4318,16 @@  discard block
 block discarded – undo
4318 4318
 	 * @param array $query_params
4319 4319
 	 * @return EE_Base_Class
4320 4320
 	 */
4321
-	function get_one_copy($model_object_or_attributes_array,$query_params = array()){
4322
-		if( ! is_array( $query_params ) ){
4323
-			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' );
4321
+	function get_one_copy($model_object_or_attributes_array, $query_params = array()) {
4322
+		if ( ! is_array($query_params)) {
4323
+			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');
4324 4324
 			$query_params = array();
4325 4325
 		}
4326 4326
 		$query_params['limit'] = 1;
4327
-		$copies = $this->get_all_copies($model_object_or_attributes_array,$query_params);
4328
-		if(is_array($copies)){
4327
+		$copies = $this->get_all_copies($model_object_or_attributes_array, $query_params);
4328
+		if (is_array($copies)) {
4329 4329
 			return array_shift($copies);
4330
-		}else{
4330
+		} else {
4331 4331
 			return null;
4332 4332
 		}
4333 4333
 	}
@@ -4341,10 +4341,10 @@  discard block
 block discarded – undo
4341 4341
 	 * @param int|string $id the value of the primary key to update
4342 4342
 	 * @return int number of rows updated
4343 4343
 	 */
4344
-	public function update_by_ID($fields_n_values,$id){
4344
+	public function update_by_ID($fields_n_values, $id) {
4345 4345
 		$query_params = array(0=>array($this->get_primary_key_field()->get_name() => $id),
4346 4346
 			'default_where_conditions'=>'other_models_only',);
4347
-		return $this->update($fields_n_values,$query_params);
4347
+		return $this->update($fields_n_values, $query_params);
4348 4348
 	}
4349 4349
 
4350 4350
 
@@ -4355,12 +4355,12 @@  discard block
 block discarded – undo
4355 4355
 	 * @return string an operator which can be used in SQL
4356 4356
 	 * @throws EE_Error
4357 4357
 	 */
4358
-	private function _prepare_operator_for_sql($operator_supplied){
4358
+	private function _prepare_operator_for_sql($operator_supplied) {
4359 4359
 		$sql_operator = isset($this->_valid_operators[$operator_supplied]) ? $this->_valid_operators[$operator_supplied] : null;
4360
-		if($sql_operator){
4360
+		if ($sql_operator) {
4361 4361
 			return $sql_operator;
4362
-		}else{
4363
-			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))));
4362
+		} else {
4363
+			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))));
4364 4364
 		}
4365 4365
 	}
4366 4366
 
@@ -4370,10 +4370,10 @@  discard block
 block discarded – undo
4370 4370
 	 * @param array $query_params like get_all's
4371 4371
 	 * @return string[]
4372 4372
 	 */
4373
-	public function get_all_names($query_params = array()){
4373
+	public function get_all_names($query_params = array()) {
4374 4374
 		$objs = $this->get_all($query_params);
4375 4375
 		$names = array();
4376
-		foreach($objs as $obj){
4376
+		foreach ($objs as $obj) {
4377 4377
 			$names[$obj->ID()] = $obj->name();
4378 4378
 		}
4379 4379
 		return $names;
@@ -4388,22 +4388,22 @@  discard block
 block discarded – undo
4388 4388
 	 * @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
4389 4389
 	 * @return array
4390 4390
 	 */
4391
-	public function get_IDs( $model_objects, $filter_out_empty_ids = false) {
4392
-		if( ! $this->has_primary_key_field() ) {
4393
-			if( WP_DEBUG ) {
4394
-				EE_Error::add_error( __( 'Trying to get IDs from a model than has no primary key', 'event_espresso' ), __FILE__, __FUNCTION__, __LINE__ );
4391
+	public function get_IDs($model_objects, $filter_out_empty_ids = false) {
4392
+		if ( ! $this->has_primary_key_field()) {
4393
+			if (WP_DEBUG) {
4394
+				EE_Error::add_error(__('Trying to get IDs from a model than has no primary key', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__);
4395 4395
 				return array();
4396 4396
 			}
4397 4397
 		}
4398 4398
 		$IDs = array();
4399
-		foreach( $model_objects as $model_object ) {
4399
+		foreach ($model_objects as $model_object) {
4400 4400
 			$id = $model_object->ID();
4401
-			if( ! $id ) {
4402
-				if( $filter_out_empty_ids ) {
4401
+			if ( ! $id) {
4402
+				if ($filter_out_empty_ids) {
4403 4403
 					continue;
4404 4404
 				}
4405
-				if( WP_DEBUG ) {
4406
-					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__ );
4405
+				if (WP_DEBUG) {
4406
+					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__);
4407 4407
 				}
4408 4408
 			}
4409 4409
 			$IDs[] = $id;
@@ -4416,8 +4416,8 @@  discard block
 block discarded – undo
4416 4416
 	 * are no capabilities that relate to this model returns false
4417 4417
 	 * @return string|false
4418 4418
 	 */
4419
-	public function cap_slug(){
4420
-		return apply_filters( 'FHEE__EEM_Base__cap_slug', $this->_caps_slug, $this);
4419
+	public function cap_slug() {
4420
+		return apply_filters('FHEE__EEM_Base__cap_slug', $this->_caps_slug, $this);
4421 4421
 	}
4422 4422
 
4423 4423
 	/**
@@ -4429,27 +4429,27 @@  discard block
 block discarded – undo
4429 4429
 	 * @param string $context
4430 4430
 	 * @return EE_Default_Where_Conditions[] indexed by associated capability
4431 4431
 	 */
4432
-	public function cap_restrictions( $context = EEM_Base::caps_read ) {
4433
-		EEM_Base::verify_is_valid_cap_context( $context );
4432
+	public function cap_restrictions($context = EEM_Base::caps_read) {
4433
+		EEM_Base::verify_is_valid_cap_context($context);
4434 4434
 		//check if we ought to run the restriction generator first
4435
-		if( isset( $this->_cap_restriction_generators[ $context ] ) &&
4436
-				$this->_cap_restriction_generators[ $context ] instanceof EE_Restriction_Generator_Base &&
4437
-				! $this->_cap_restriction_generators[ $context ]->has_generated_cap_restrictions() ) {
4438
-			$this->_cap_restrictions[ $context ] = array_merge( $this->_cap_restrictions[ $context ],  $this->_cap_restriction_generators[ $context ]->generate_restrictions() );
4435
+		if (isset($this->_cap_restriction_generators[$context]) &&
4436
+				$this->_cap_restriction_generators[$context] instanceof EE_Restriction_Generator_Base &&
4437
+				! $this->_cap_restriction_generators[$context]->has_generated_cap_restrictions()) {
4438
+			$this->_cap_restrictions[$context] = array_merge($this->_cap_restrictions[$context], $this->_cap_restriction_generators[$context]->generate_restrictions());
4439 4439
 		}
4440 4440
 		//and make sure we've finalized the construction of each restriction
4441
-		foreach( $this->_cap_restrictions[ $context ] as $where_conditions_obj ) {
4442
-			$where_conditions_obj->_finalize_construct( $this );
4441
+		foreach ($this->_cap_restrictions[$context] as $where_conditions_obj) {
4442
+			$where_conditions_obj->_finalize_construct($this);
4443 4443
 		}
4444 4444
 
4445
-		return $this->_cap_restrictions[ $context ];
4445
+		return $this->_cap_restrictions[$context];
4446 4446
 	}
4447 4447
 
4448 4448
 	/**
4449 4449
 	 * Indicating whether or not this model thinks its a wp core model
4450 4450
 	 * @return boolean
4451 4451
 	 */
4452
-	public function is_wp_core_model(){
4452
+	public function is_wp_core_model() {
4453 4453
 		return $this->_wp_core_model;
4454 4454
 	}
4455 4455
 
@@ -4459,12 +4459,12 @@  discard block
 block discarded – undo
4459 4459
 	 * @param string $context one of EEM_Base::caps_ constants
4460 4460
 	 * @return EE_Default_Where_Conditions[] indexed by capability name
4461 4461
 	 */
4462
-	public function caps_missing( $context = EEM_Base::caps_read ) {
4462
+	public function caps_missing($context = EEM_Base::caps_read) {
4463 4463
 		$missing_caps = array();
4464
-		$cap_restrictions = $this->cap_restrictions( $context );
4465
-		foreach( $cap_restrictions as $cap => $restriction_if_no_cap ) {
4466
-			if( ! EE_Capabilities::instance()->current_user_can( $cap, $this->get_this_model_name() . '_model_applying_caps') ) {
4467
-				$missing_caps[ $cap ] = $restriction_if_no_cap;
4464
+		$cap_restrictions = $this->cap_restrictions($context);
4465
+		foreach ($cap_restrictions as $cap => $restriction_if_no_cap) {
4466
+			if ( ! EE_Capabilities::instance()->current_user_can($cap, $this->get_this_model_name().'_model_applying_caps')) {
4467
+				$missing_caps[$cap] = $restriction_if_no_cap;
4468 4468
 			}
4469 4469
 		}
4470 4470
 		return $missing_caps;
@@ -4476,7 +4476,7 @@  discard block
 block discarded – undo
4476 4476
 	 * one of 'read', 'edit', or 'delete'
4477 4477
 	 */
4478 4478
 	public function cap_contexts_to_cap_action_map() {
4479
-		return apply_filters( 'FHEE__EEM_Base__cap_contexts_to_cap_action_map', $this->_cap_contexts_to_cap_action_map, $this );
4479
+		return apply_filters('FHEE__EEM_Base__cap_contexts_to_cap_action_map', $this->_cap_contexts_to_cap_action_map, $this);
4480 4480
 	}
4481 4481
 
4482 4482
 
@@ -4487,19 +4487,19 @@  discard block
 block discarded – undo
4487 4487
 	 * @return string one of EEM_Base::cap_contexts_to_cap_action_map() values
4488 4488
 	 * @throws \EE_Error
4489 4489
 	 */
4490
-	public function cap_action_for_context( $context ) {
4490
+	public function cap_action_for_context($context) {
4491 4491
 		$mapping = $this->cap_contexts_to_cap_action_map();
4492
-		if( isset( $mapping[ $context ] ) ) {
4493
-			return $mapping[ $context ];
4492
+		if (isset($mapping[$context])) {
4493
+			return $mapping[$context];
4494 4494
 		}
4495
-		if( $action = apply_filters( 'FHEE__EEM_Base__cap_action_for_context', null, $this, $mapping, $context ) ) {
4495
+		if ($action = apply_filters('FHEE__EEM_Base__cap_action_for_context', null, $this, $mapping, $context)) {
4496 4496
 			return $action;
4497 4497
 		}
4498 4498
 		throw new EE_Error(
4499 4499
 			sprintf(
4500
-				__( 'Cannot find capability restrictions for context "%1$s", allowed values are:%2$s', 'event_espresso' ),
4500
+				__('Cannot find capability restrictions for context "%1$s", allowed values are:%2$s', 'event_espresso'),
4501 4501
 				$context,
4502
-				implode(',', array_keys( $this->cap_contexts_to_cap_action_map() ) )
4502
+				implode(',', array_keys($this->cap_contexts_to_cap_action_map()))
4503 4503
 			)
4504 4504
 		);
4505 4505
 
@@ -4510,7 +4510,7 @@  discard block
 block discarded – undo
4510 4510
 	 * @return array
4511 4511
 	 */
4512 4512
 	static public function valid_cap_contexts() {
4513
-		return apply_filters( 'FHEE__EEM_Base__valid_cap_contexts', array(
4513
+		return apply_filters('FHEE__EEM_Base__valid_cap_contexts', array(
4514 4514
 			self::caps_read,
4515 4515
 			self::caps_read_admin,
4516 4516
 			self::caps_edit,
@@ -4526,17 +4526,17 @@  discard block
 block discarded – undo
4526 4526
 	 * @return bool
4527 4527
 	 * @throws \EE_Error
4528 4528
 	 */
4529
-	static public function verify_is_valid_cap_context( $context ) {
4529
+	static public function verify_is_valid_cap_context($context) {
4530 4530
 		$valid_cap_contexts = EEM_Base::valid_cap_contexts();
4531
-		if( in_array( $context, $valid_cap_contexts ) ) {
4531
+		if (in_array($context, $valid_cap_contexts)) {
4532 4532
 			return true;
4533
-		}else{
4533
+		} else {
4534 4534
 			throw new EE_Error(
4535 4535
 				sprintf(
4536
-					__( 'Context "%1$s" passed into model "%2$s" is not a valid context. They are: %3$s', 'event_espresso' ),
4536
+					__('Context "%1$s" passed into model "%2$s" is not a valid context. They are: %3$s', 'event_espresso'),
4537 4537
 					$context,
4538
-					'EEM_Base' ,
4539
-					implode(',', $valid_cap_contexts )
4538
+					'EEM_Base',
4539
+					implode(',', $valid_cap_contexts)
4540 4540
 				)
4541 4541
 			);
4542 4542
 		}
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   +88 added lines, -88 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_publish - the wp post status for published cpts
@@ -69,55 +69,55 @@  discard block
 block discarded – undo
69 69
 	 * @param string $timezone
70 70
 	 * @throws \EE_Error
71 71
 	 */
72
-	protected function __construct( $timezone = NULL ){
72
+	protected function __construct($timezone = NULL) {
73 73
 
74 74
 		//adds a relationship to Term_Taxonomy for all these models. For this to work
75 75
 		//Term_Relationship must have a relation to each model subclassing EE_CPT_Base explicitly
76 76
 		//eg, in EEM_Term_Relationship, inside the _model_relations array, there must be an entry
77 77
 		//with key equalling the subclassing model's model name (eg 'Event' or 'Venue'), and the value
78 78
 		//must also be new EE_HABTM_Relation('Term_Relationship');
79
-		$this->_model_relations['Term_Taxonomy'] =new EE_HABTM_Relation('Term_Relationship');
79
+		$this->_model_relations['Term_Taxonomy'] = new EE_HABTM_Relation('Term_Relationship');
80 80
 		$primary_table_name = NULL;
81 81
 		//add  the common _status field to all CPT primary tables.
82
-		foreach ( $this->_tables as $alias => $table_obj ) {
83
-			if ( $table_obj instanceof EE_Primary_Table ) {
82
+		foreach ($this->_tables as $alias => $table_obj) {
83
+			if ($table_obj instanceof EE_Primary_Table) {
84 84
 				$primary_table_name = $alias;
85 85
 			}
86 86
 		}
87 87
 		//set default wp post statuses if child has not already set.
88
-		if ( ! isset( $this->_fields[$primary_table_name]['status'] )) {
88
+		if ( ! isset($this->_fields[$primary_table_name]['status'])) {
89 89
 			$this->_fields[$primary_table_name]['status'] = new EE_WP_Post_Status_Field('post_status', __("Event Status", "event_espresso"), false, 'draft');
90 90
 		}
91
-		if( ! isset( $this->_fields[$primary_table_name]['to_ping'])){
92
-			$this->_fields[$primary_table_name]['to_ping'] = new EE_DB_Only_Text_Field('to_ping', __( 'To Ping', 'event_espresso' ), FALSE, '');
91
+		if ( ! isset($this->_fields[$primary_table_name]['to_ping'])) {
92
+			$this->_fields[$primary_table_name]['to_ping'] = new EE_DB_Only_Text_Field('to_ping', __('To Ping', 'event_espresso'), FALSE, '');
93 93
 		}
94
-		if( ! isset( $this->_fields[$primary_table_name]['pinged'])){
95
-			$this->_fields[$primary_table_name]['pinged'] = new EE_DB_Only_Text_Field('pinged', __( 'Pinged', 'event_espresso' ), FALSE, '');
94
+		if ( ! isset($this->_fields[$primary_table_name]['pinged'])) {
95
+			$this->_fields[$primary_table_name]['pinged'] = new EE_DB_Only_Text_Field('pinged', __('Pinged', 'event_espresso'), FALSE, '');
96 96
 		}
97 97
 
98
-		if( ! isset( $this->_fields[$primary_table_name]['comment_status'])){
99
-			$this->_fields[$primary_table_name]['comment_status'] = new EE_Plain_Text_Field('comment_status', __('Comment Status', 'event_espresso' ), FALSE, 'open');
98
+		if ( ! isset($this->_fields[$primary_table_name]['comment_status'])) {
99
+			$this->_fields[$primary_table_name]['comment_status'] = new EE_Plain_Text_Field('comment_status', __('Comment Status', 'event_espresso'), FALSE, 'open');
100 100
 		}
101 101
 
102
-		if( ! isset( $this->_fields[$primary_table_name]['ping_status'])){
102
+		if ( ! isset($this->_fields[$primary_table_name]['ping_status'])) {
103 103
 			$this->_fields[$primary_table_name]['ping_status'] = new EE_Plain_Text_Field('ping_status', __('Ping Status', 'event_espresso'), FALSE, 'open');
104 104
 		}
105 105
 
106
-		if( ! isset( $this->_fields[$primary_table_name]['post_content_filtered'])){
107
-			$this->_fields[$primary_table_name]['post_content_filtered'] = new EE_DB_Only_Text_Field('post_content_filtered', __( 'Post Content Filtered', 'event_espresso' ), FALSE, '');
106
+		if ( ! isset($this->_fields[$primary_table_name]['post_content_filtered'])) {
107
+			$this->_fields[$primary_table_name]['post_content_filtered'] = new EE_DB_Only_Text_Field('post_content_filtered', __('Post Content Filtered', 'event_espresso'), FALSE, '');
108 108
 		}
109
-		if( ! isset( $this->_model_relations[ 'Post_Meta' ] ) ) {
109
+		if ( ! isset($this->_model_relations['Post_Meta'])) {
110 110
 			//don't block deletes though because we want to maintain the current behaviour
111
-			$this->_model_relations[ 'Post_Meta' ] = new EE_Has_Many_Relation( false );
111
+			$this->_model_relations['Post_Meta'] = new EE_Has_Many_Relation(false);
112 112
 		}
113
-		if( ! $this->_minimum_where_conditions_strategy instanceof EE_Default_Where_Conditions ){
113
+		if ( ! $this->_minimum_where_conditions_strategy instanceof EE_Default_Where_Conditions) {
114 114
 			//nothing was set during child constructor, so set default
115
-			$this->_minimum_where_conditions_strategy = new EE_CPT_Minimum_Where_Conditions( $this->post_type() );
115
+			$this->_minimum_where_conditions_strategy = new EE_CPT_Minimum_Where_Conditions($this->post_type());
116 116
 		}
117
-		if( ! $this->_default_where_conditions_strategy instanceof EE_Default_Where_Conditions ) {
117
+		if ( ! $this->_default_where_conditions_strategy instanceof EE_Default_Where_Conditions) {
118 118
 			//nothing was set during child constructor, so set default
119 119
 			//it's ok for child classes to specify this, but generally this is more DRY
120
-			$this->_default_where_conditions_strategy = new EE_CPT_Where_Conditions( $this->post_type() );
120
+			$this->_default_where_conditions_strategy = new EE_CPT_Where_Conditions($this->post_type());
121 121
 		}
122 122
 		parent::__construct($timezone);
123 123
 
@@ -130,7 +130,7 @@  discard block
 block discarded – undo
130 130
 	 */
131 131
 	public function public_event_stati() {
132 132
 		// @see wp-includes/post.php
133
-		return get_post_stati( array( 'public' => TRUE ));
133
+		return get_post_stati(array('public' => TRUE));
134 134
 	}
135 135
 
136 136
 
@@ -141,7 +141,7 @@  discard block
 block discarded – undo
141 141
 	 * @return string
142 142
 	 * @throws EE_Error
143 143
 	 */
144
-	public function deleted_field_name(){
144
+	public function deleted_field_name() {
145 145
 		throw new EE_Error(sprintf(__("EEM_CPT_Base should nto call deleted_field_name! It should instead use post_status_field_name", "event_espresso")));
146 146
 	}
147 147
 
@@ -152,12 +152,12 @@  discard block
 block discarded – undo
152 152
 	 * @return string
153 153
 	 * @throws EE_Error
154 154
 	 */
155
-	public function post_status_field_name(){
155
+	public function post_status_field_name() {
156 156
 		$field = $this->get_a_field_of_type('EE_WP_Post_Status_Field');
157
-		if($field){
157
+		if ($field) {
158 158
 			return $field->get_name();
159
-		}else{
160
-			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)));
159
+		} else {
160
+			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)));
161 161
 		}
162 162
 	}
163 163
 
@@ -168,9 +168,9 @@  discard block
 block discarded – undo
168 168
 	 * @param array $query_params like EEM_Base::get_all's $query_params
169 169
 	 * @return array like EEM_Base::get_all's $query_params
170 170
 	 */
171
-	protected function _alter_query_params_so_only_trashed_items_included($query_params){
172
-		$post_status_field_name=$this->post_status_field_name();
173
-		$query_params[0][$post_status_field_name]=self::post_status_trashed;
171
+	protected function _alter_query_params_so_only_trashed_items_included($query_params) {
172
+		$post_status_field_name = $this->post_status_field_name();
173
+		$query_params[0][$post_status_field_name] = self::post_status_trashed;
174 174
 		return $query_params;
175 175
 	}
176 176
 
@@ -181,8 +181,8 @@  discard block
 block discarded – undo
181 181
 	 * @param array $query_params
182 182
 	 * @return array
183 183
 	 */
184
-	protected function _alter_query_params_so_deleted_and_undeleted_items_included($query_params){
185
-		$query_params[ 'default_where_conditions' ] = 'minimum';
184
+	protected function _alter_query_params_so_deleted_and_undeleted_items_included($query_params) {
185
+		$query_params['default_where_conditions'] = 'minimum';
186 186
 		return $query_params;
187 187
 	}
188 188
 
@@ -194,11 +194,11 @@  discard block
 block discarded – undo
194 194
 	 * @param array $query_params like EEM_Base::get_all
195 195
 	 * @return boolean success
196 196
 	 */
197
-	function delete_or_restore($delete=true,$query_params = array()){
198
-		$post_status_field_name=$this->post_status_field_name();
197
+	function delete_or_restore($delete = true, $query_params = array()) {
198
+		$post_status_field_name = $this->post_status_field_name();
199 199
 		$query_params = $this->_alter_query_params_so_deleted_and_undeleted_items_included($query_params);
200 200
 		$new_status = $delete ? self::post_status_trashed : 'draft';
201
-		if ( $this->update (array($post_status_field_name=>$new_status), $query_params )) {
201
+		if ($this->update(array($post_status_field_name=>$new_status), $query_params)) {
202 202
 			return TRUE;
203 203
 		} else {
204 204
 			return FALSE;
@@ -215,7 +215,7 @@  discard block
 block discarded – undo
215 215
 	 */
216 216
 	public function meta_table() {
217 217
 		$meta_table = $this->_get_other_tables();
218
-		$meta_table = reset( $meta_table );
218
+		$meta_table = reset($meta_table);
219 219
 		return $meta_table instanceof EE_Secondary_Table ? $meta_table->get_table_name() : NULL;
220 220
 	}
221 221
 
@@ -227,16 +227,16 @@  discard block
 block discarded – undo
227 227
 	 * @param  bool $all triggers whether we include DB_Only fields or JUST non DB_Only fields.  Defaults to false (no db only fields)
228 228
 	 * @return array
229 229
 	 */
230
-	public function get_meta_table_fields( $all = FALSE ) {
230
+	public function get_meta_table_fields($all = FALSE) {
231 231
 		$all_fields = $fields_to_return = array();
232
-		foreach ( $this->_tables as $alias => $table_obj ) {
233
-			if ( $table_obj instanceof EE_Secondary_Table )
234
-				$all_fields = array_merge( $this->_get_fields_for_table($alias), $all_fields );
232
+		foreach ($this->_tables as $alias => $table_obj) {
233
+			if ($table_obj instanceof EE_Secondary_Table)
234
+				$all_fields = array_merge($this->_get_fields_for_table($alias), $all_fields);
235 235
 		}
236 236
 
237
-		if ( !$all ) {
238
-			foreach ( $all_fields as $name => $obj ) {
239
-				if ( $obj instanceof EE_DB_Only_Field_Base )
237
+		if ( ! $all) {
238
+			foreach ($all_fields as $name => $obj) {
239
+				if ($obj instanceof EE_DB_Only_Field_Base)
240 240
 					continue;
241 241
 				$fields_to_return[] = $name;
242 242
 			}
@@ -259,13 +259,13 @@  discard block
 block discarded – undo
259 259
 	 * @param int $parent_term_taxonomy_id
260 260
 	 * @return EE_Term_Taxonomy
261 261
 	 */
262
-	function add_event_category(EE_CPT_Base $cpt_model_object, $category_name, $category_description ='',$parent_term_taxonomy_id = null){
262
+	function add_event_category(EE_CPT_Base $cpt_model_object, $category_name, $category_description = '', $parent_term_taxonomy_id = null) {
263 263
 		//create term
264
-		require_once( EE_MODELS . 'EEM_Term.model.php');
264
+		require_once(EE_MODELS.'EEM_Term.model.php');
265 265
 		//first, check for a term by the same name or slug
266 266
 		$category_slug = sanitize_title($category_name);
267
-		$term = EEM_Term::instance()->get_one(array(array('OR'=>array('name'=>$category_name,'slug'=>$category_slug))));
268
-		if( ! $term ){
267
+		$term = EEM_Term::instance()->get_one(array(array('OR'=>array('name'=>$category_name, 'slug'=>$category_slug))));
268
+		if ( ! $term) {
269 269
 			$term = EE_Term::new_instance(array(
270 270
 				'name'=>$category_name,
271 271
 				'slug'=>$category_slug
@@ -273,10 +273,10 @@  discard block
 block discarded – undo
273 273
 			$term->save();
274 274
 		}
275 275
 		//make sure there's a term-taxonomy entry too
276
-		require_once( EE_MODELS . 'EEM_Term_Taxonomy.model.php');
277
-		$term_taxonomy = EEM_Term_Taxonomy::instance()->get_one(array(array('term_id'=>$term->ID(),'taxonomy'=>EE_Event_Category_Taxonomy)));
276
+		require_once(EE_MODELS.'EEM_Term_Taxonomy.model.php');
277
+		$term_taxonomy = EEM_Term_Taxonomy::instance()->get_one(array(array('term_id'=>$term->ID(), 'taxonomy'=>EE_Event_Category_Taxonomy)));
278 278
 		/** @var $term_taxonomy EE_Term_Taxonomy */
279
-		if( ! $term_taxonomy ){
279
+		if ( ! $term_taxonomy) {
280 280
 			$term_taxonomy = EE_Term_Taxonomy::new_instance(array(
281 281
 				'term_id'=>$term->ID(),
282 282
 				'taxonomy'=>EE_Event_Category_Taxonomy,
@@ -285,7 +285,7 @@  discard block
 block discarded – undo
285 285
 				'parent'=>$parent_term_taxonomy_id
286 286
 			));
287 287
 			$term_taxonomy->save();
288
-		}else{
288
+		} else {
289 289
 			$term_taxonomy->set_count($term_taxonomy->count() + 1);
290 290
 			$term_taxonomy->save();
291 291
 		}
@@ -300,11 +300,11 @@  discard block
 block discarded – undo
300 300
 	 * @param string $category_name name of the event category (term)
301 301
 	 * @return bool
302 302
 	 */
303
-	function remove_event_category(EE_CPT_Base $cpt_model_object_event, $category_name){
303
+	function remove_event_category(EE_CPT_Base $cpt_model_object_event, $category_name) {
304 304
 		//find the term_taxonomy by that name
305
-		$term_taxonomy = $this->get_first_related($cpt_model_object_event, 'Term_Taxonomy', array(array('Term.name'=>$category_name,'taxonomy'=>EE_Event_Category_Taxonomy)));
305
+		$term_taxonomy = $this->get_first_related($cpt_model_object_event, 'Term_Taxonomy', array(array('Term.name'=>$category_name, 'taxonomy'=>EE_Event_Category_Taxonomy)));
306 306
 		/** @var $term_taxonomy EE_Term_Taxonomy */
307
-		if( $term_taxonomy ){
307
+		if ($term_taxonomy) {
308 308
 			$term_taxonomy->set_count($term_taxonomy->count() - 1);
309 309
 			$term_taxonomy->save();
310 310
 		}
@@ -324,8 +324,8 @@  discard block
 block discarded – undo
324 324
 	 * @param string|array $attr Optional. Query string or array of attributes.
325 325
 	 * @return string HTML image element
326 326
 	 */
327
-	public function get_feature_image( $id, $size = 'thumbnail', $attr = '' ) {
328
-		return get_the_post_thumbnail( $id, $size, $attr );
327
+	public function get_feature_image($id, $size = 'thumbnail', $attr = '') {
328
+		return get_the_post_thumbnail($id, $size, $attr);
329 329
 	}
330 330
 
331 331
 
@@ -338,10 +338,10 @@  discard block
 block discarded – undo
338 338
 	 * @global array $wp_post_statuses set in wp core for storing all the post stati
339 339
 	 * @return array
340 340
 	 */
341
-	public function get_post_statuses(){
341
+	public function get_post_statuses() {
342 342
 		global $wp_post_statuses;
343 343
 		$statuses = array();
344
-		foreach($wp_post_statuses as $post_status => $args_object){
344
+		foreach ($wp_post_statuses as $post_status => $args_object) {
345 345
 			$statuses[$post_status] = $args_object->label;
346 346
 		}
347 347
 		return $statuses;
@@ -356,9 +356,9 @@  discard block
 block discarded – undo
356 356
 	public function get_status_array() {
357 357
 		$statuses = $this->get_post_statuses();
358 358
 		//first the global filter
359
-		$statuses = apply_filters( 'FHEE_EEM_CPT_Base__get_status_array', $statuses );
359
+		$statuses = apply_filters('FHEE_EEM_CPT_Base__get_status_array', $statuses);
360 360
 		//now the class specific filter
361
-		$statuses = apply_filters( 'FHEE_EEM_' . get_class($this) . '__get_status_array', $statuses );
361
+		$statuses = apply_filters('FHEE_EEM_'.get_class($this).'__get_status_array', $statuses);
362 362
 		return $statuses;
363 363
 	}
364 364
 
@@ -370,7 +370,7 @@  discard block
 block discarded – undo
370 370
 	 */
371 371
 	public function get_custom_post_statuses() {
372 372
 		$new_stati = array();
373
-		foreach ( $this->_custom_stati as $status => $props ) {
373
+		foreach ($this->_custom_stati as $status => $props) {
374 374
 			$new_stati[$status] = $props['label'];
375 375
 		}
376 376
 		return $new_stati;
@@ -386,24 +386,24 @@  discard block
 block discarded – undo
386 386
 	 * @param WP_Post|array $post
387 387
 	 * @return EE_CPT_Base
388 388
 	 */
389
-	public function instantiate_class_from_post_object_orig($post){
390
-		$post = (array)$post;
389
+	public function instantiate_class_from_post_object_orig($post) {
390
+		$post = (array) $post;
391 391
 		$has_all_necessary_fields_for_table = true;
392 392
 		//check if the post has fields on the meta table already
393
-		foreach($this->_get_other_tables() as $table_obj){
393
+		foreach ($this->_get_other_tables() as $table_obj) {
394 394
 			$fields_for_that_table = $this->_get_fields_for_table($table_obj->get_table_alias());
395
-			foreach($fields_for_that_table as $field_obj){
396
-				if( ! isset($post[$field_obj->get_table_column()])
397
-					&& ! isset($post[$field_obj->get_qualified_column()])){
395
+			foreach ($fields_for_that_table as $field_obj) {
396
+				if ( ! isset($post[$field_obj->get_table_column()])
397
+					&& ! isset($post[$field_obj->get_qualified_column()])) {
398 398
 					$has_all_necessary_fields_for_table = false;
399 399
 				}
400 400
 			}
401 401
 		}
402 402
 		//if we don't have all the fields we need, then just fetch the proper model from the DB
403
-		if( ! $has_all_necessary_fields_for_table){
403
+		if ( ! $has_all_necessary_fields_for_table) {
404 404
 
405 405
 			return $this->get_one_by_ID($post['ID']);
406
-		}else{
406
+		} else {
407 407
 			return $this->instantiate_class_from_array_or_object($post);
408 408
 		}
409 409
 	}
@@ -414,30 +414,30 @@  discard block
 block discarded – undo
414 414
 	 * @param null $post
415 415
 	 * @return EE_Base_Class|EE_Soft_Delete_Base_Class
416 416
 	 */
417
-	public function instantiate_class_from_post_object( $post = NULL ){
418
-		if ( empty( $post )) {
417
+	public function instantiate_class_from_post_object($post = NULL) {
418
+		if (empty($post)) {
419 419
 			global $post;
420 420
 		}
421
-		$post = (array)$post;
421
+		$post = (array) $post;
422 422
 		$tables_needing_to_be_queried = array();
423 423
 		//check if the post has fields on the meta table already
424
-		foreach($this->get_tables() as $table_obj){
424
+		foreach ($this->get_tables() as $table_obj) {
425 425
 			$fields_for_that_table = $this->_get_fields_for_table($table_obj->get_table_alias());
426
-			foreach($fields_for_that_table as $field_obj){
427
-				if( ! isset($post[$field_obj->get_table_column()])
428
-					&& ! isset($post[$field_obj->get_qualified_column()])){
426
+			foreach ($fields_for_that_table as $field_obj) {
427
+				if ( ! isset($post[$field_obj->get_table_column()])
428
+					&& ! isset($post[$field_obj->get_qualified_column()])) {
429 429
 					$tables_needing_to_be_queried[$table_obj->get_table_alias()] = $table_obj;
430 430
 				}
431 431
 			}
432 432
 		}
433 433
 		//if we don't have all the fields we need, then just fetch the proper model from the DB
434
-		if( $tables_needing_to_be_queried){
435
-			if(count($tables_needing_to_be_queried) == 1 && reset($tables_needing_to_be_queried) instanceof EE_Secondary_Table){
434
+		if ($tables_needing_to_be_queried) {
435
+			if (count($tables_needing_to_be_queried) == 1 && reset($tables_needing_to_be_queried) instanceof EE_Secondary_Table) {
436 436
 				//so we're only missing data from a secondary table. Well that's not too hard to query for
437 437
 				$table_to_query = reset($tables_needing_to_be_queried);
438
-				$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 ));
439
-				if ( ! empty( $missing_data )) {
440
-					$post = array_merge( $post, $missing_data );
438
+				$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));
439
+				if ( ! empty($missing_data)) {
440
+					$post = array_merge($post, $missing_data);
441 441
 				}
442 442
 			} else {
443 443
 				return $this->get_one_by_ID($post['ID']);
@@ -454,15 +454,15 @@  discard block
 block discarded – undo
454 454
 	 * @throws EE_Error
455 455
 	 * @return string
456 456
 	 */
457
-	public function post_type(){
457
+	public function post_type() {
458 458
 		$post_type_field = NULL;
459
-		foreach($this->field_settings(true) as $field_obj){
460
-			if($field_obj instanceof EE_WP_Post_Type_Field){
461
-				$post_type_field = $field_obj;break;
459
+		foreach ($this->field_settings(true) as $field_obj) {
460
+			if ($field_obj instanceof EE_WP_Post_Type_Field) {
461
+				$post_type_field = $field_obj; break;
462 462
 			}
463 463
 		}
464
-		if($post_type_field == NULL){
465
-			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)));
464
+		if ($post_type_field == NULL) {
465
+			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)));
466 466
 		}
467 467
 		return $post_type_field->get_default_value();
468 468
 	}
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.
core/db_models/EEM_Datetime.model.php 4 patches
Braces   +11 added lines, -5 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
  * Event Espresso
4 6
  *
@@ -191,7 +193,7 @@  discard block
 block discarded – undo
191 193
 		$results =  $this->get_datetimes_for_event_ordered_by_start_time($EVT_ID, $include_expired, $include_deleted, 1);
192 194
 		if($results){
193 195
 			return array_shift($results);
194
-		}else{
196
+		} else{
195 197
 			return NULL;
196 198
 		}
197 199
 	}
@@ -318,7 +320,7 @@  discard block
 block discarded – undo
318 320
 		$results = $this->get_datetimes_for_event_ordered_by_importance($EVT_ID, 1);
319 321
 		if($results){
320 322
 			return array_shift($results);
321
-		}else{
323
+		} else{
322 324
 			return null;
323 325
 		}
324 326
 	}
@@ -351,7 +353,9 @@  discard block
 block discarded – undo
351 353
 					break;
352 354
 
353 355
 			case 'expired' :
354
-				if ( isset( $where_params['Event.status'] ) ) unset( $where_params['Event.status'] );
356
+				if ( isset( $where_params['Event.status'] ) ) {
357
+					unset( $where_params['Event.status'] );
358
+				}
355 359
 				//get events to exclude
356 360
 				$exclude_query[0] = array_merge( $where_params, array( 'DTT_EVT_end' => array( '>', $this->current_time_for_query( 'DTT_EVT_end' ) ) ) );
357 361
 				//first get all events that have datetimes where its not expired.
@@ -378,7 +382,9 @@  discard block
 block discarded – undo
378 382
 				break;
379 383
 
380 384
 			case 'inactive' :
381
-				if ( isset( $where_params['Event.status'] ) ) unset( $where_params['Event.status'] );
385
+				if ( isset( $where_params['Event.status'] ) ) {
386
+					unset( $where_params['Event.status'] );
387
+				}
382 388
 				if ( isset( $where_params['OR'] ) ) {
383 389
 					$where_params['AND']['OR'] = $where_params['OR'];
384 390
 				}
Please login to merge, or discard this patch.
Indentation   +19 added lines, -19 removed lines patch added patch discarded remove patch
@@ -75,11 +75,11 @@  discard block
 block discarded – undo
75 75
 
76 76
 
77 77
 	/**
78
-	*		create new blank datetime
79
-	*
80
-	* 		@access		public
81
-	*		@return 		EE_Datetime[]		array on success, FALSE on fail
82
-	*/
78
+	 *		create new blank datetime
79
+	 *
80
+	 * 		@access		public
81
+	 *		@return 		EE_Datetime[]		array on success, FALSE on fail
82
+	 */
83 83
 	public function create_new_blank_datetime() {
84 84
 		$blank_datetime = EE_Datetime::new_instance(
85 85
 			array(
@@ -100,12 +100,12 @@  discard block
 block discarded – undo
100 100
 
101 101
 
102 102
 	/**
103
-	*		get event start date from db
104
-	*
105
-	* 		@access		public
106
-	* 		@param		int 			$EVT_ID
107
-	*		@return 		EE_Datetime[]		array on success, FALSE on fail
108
-	*/
103
+	 *		get event start date from db
104
+	 *
105
+	 * 		@access		public
106
+	 * 		@param		int 			$EVT_ID
107
+	 *		@return 		EE_Datetime[]		array on success, FALSE on fail
108
+	 */
109 109
 	public function get_all_event_dates( $EVT_ID = 0 ) {
110 110
 		if ( ! $EVT_ID ) { // on add_new_event event_id gets set to 0
111 111
 			return $this->create_new_blank_datetime();
@@ -250,14 +250,14 @@  discard block
 block discarded – undo
250 250
 	}
251 251
 
252 252
 		/**
253
-	 * Gets ALL the datetimes for an ticket (including trashed ones, for now), ordered
254
-	 * only by start date
255
-	 * @param int $TKT_ID
256
-	 * @param boolean $include_expired
257
-	 * @param boolean $include_deleted
258
-	 * @param int $limit
259
-	 * @return EE_Datetime[]
260
-	 */
253
+		 * Gets ALL the datetimes for an ticket (including trashed ones, for now), ordered
254
+		 * only by start date
255
+		 * @param int $TKT_ID
256
+		 * @param boolean $include_expired
257
+		 * @param boolean $include_deleted
258
+		 * @param int $limit
259
+		 * @return EE_Datetime[]
260
+		 */
261 261
 	public function get_datetimes_for_ticket_ordered_by_start_time($TKT_ID, $include_expired = true, $include_deleted= true, $limit = NULL){
262 262
 		//sanitize TKT_ID
263 263
 		$TKT_ID =  intval( $TKT_ID );
Please login to merge, or discard this patch.
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -443,7 +443,7 @@
 block discarded – undo
443 443
 	/**
444 444
 	 * This returns an array of counts of datetimes in the database for each Datetime status that can be queried.
445 445
 	 *
446
-	 * @param  array $stati_to_include        If included you can restrict the statuses we return counts for by including the stati
446
+	 * @param  string[] $stati_to_include        If included you can restrict the statuses we return counts for by including the stati
447 447
 	 *                               you want counts for as values in the array.  An empty array returns counts for all valid
448 448
 	 *                               stati.
449 449
 	 * @param  array  $query_params  If included can be used to refine the conditions for returning the count (i.e. only for
Please login to merge, or discard this patch.
Spacing   +139 added lines, -139 removed lines patch added patch discarded remove patch
@@ -21,8 +21,8 @@  discard block
 block discarded – undo
21 21
  *
22 22
  * ------------------------------------------------------------------------
23 23
  */
24
-require_once ( EE_MODELS . 'EEM_Soft_Delete_Base.model.php' );
25
-require_once ( EE_CLASSES . 'EE_Datetime.class.php' );
24
+require_once (EE_MODELS.'EEM_Soft_Delete_Base.model.php');
25
+require_once (EE_CLASSES.'EE_Datetime.class.php');
26 26
 
27 27
 class EEM_Datetime extends EEM_Soft_Delete_Base {
28 28
 
@@ -35,27 +35,27 @@  discard block
 block discarded – undo
35 35
 	 *		@access private
36 36
 	 *		@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)
37 37
 	 */
38
-	protected function __construct( $timezone ) {
39
-		$this->singular_item = __('Datetime','event_espresso');
40
-		$this->plural_item = __('Datetimes','event_espresso');
38
+	protected function __construct($timezone) {
39
+		$this->singular_item = __('Datetime', 'event_espresso');
40
+		$this->plural_item = __('Datetimes', 'event_espresso');
41 41
 
42 42
 		$this->_tables = array(
43 43
 			'Datetime'=> new EE_Primary_Table('esp_datetime', 'DTT_ID')
44 44
 		);
45 45
 		$this->_fields = array(
46 46
 			'Datetime'=>array(
47
-				'DTT_ID'=> new EE_Primary_Key_Int_Field('DTT_ID', __('Datetime ID','event_espresso')),
48
-				'EVT_ID'=>new EE_Foreign_Key_Int_Field('EVT_ID', __('Event ID','event_espresso'), false, 0, 'Event'),
47
+				'DTT_ID'=> new EE_Primary_Key_Int_Field('DTT_ID', __('Datetime ID', 'event_espresso')),
48
+				'EVT_ID'=>new EE_Foreign_Key_Int_Field('EVT_ID', __('Event ID', 'event_espresso'), false, 0, 'Event'),
49 49
 				'DTT_name' => new EE_Plain_Text_Field('DTT_name', __('Datetime Name', 'event_espresso'), false, ''),
50 50
 				'DTT_description' => new EE_Full_HTML_Field('DTT_description', __('Description for Datetime', 'event_espresso'), false, ''),
51
-				'DTT_EVT_start'=>new EE_Datetime_Field('DTT_EVT_start', __('Start time/date of Event','event_espresso'), false, time(), $timezone ),
52
-				'DTT_EVT_end'=>new EE_Datetime_Field('DTT_EVT_end', __('End time/date of Event','event_espresso'), false, time(), $timezone ),
53
-				'DTT_reg_limit'=>new EE_Infinite_Integer_Field('DTT_reg_limit', __('Registration Limit for this time','event_espresso'), true, EE_INF),
54
-				'DTT_sold'=>new EE_Integer_Field('DTT_sold', __('How many sales for this Datetime that have occurred', 'event_espresso'), true, 0 ),
55
-				'DTT_is_primary'=>new EE_Boolean_Field('DTT_is_primary', __("Flag indicating datetime is primary one for event", "event_espresso"), false,false),
51
+				'DTT_EVT_start'=>new EE_Datetime_Field('DTT_EVT_start', __('Start time/date of Event', 'event_espresso'), false, time(), $timezone),
52
+				'DTT_EVT_end'=>new EE_Datetime_Field('DTT_EVT_end', __('End time/date of Event', 'event_espresso'), false, time(), $timezone),
53
+				'DTT_reg_limit'=>new EE_Infinite_Integer_Field('DTT_reg_limit', __('Registration Limit for this time', 'event_espresso'), true, EE_INF),
54
+				'DTT_sold'=>new EE_Integer_Field('DTT_sold', __('How many sales for this Datetime that have occurred', 'event_espresso'), true, 0),
55
+				'DTT_is_primary'=>new EE_Boolean_Field('DTT_is_primary', __("Flag indicating datetime is primary one for event", "event_espresso"), false, false),
56 56
 				'DTT_order' => new EE_Integer_Field('DTT_order', __('The order in which the Datetime is displayed', 'event_espresso'), false, 0),
57
-				'DTT_parent' => new EE_Integer_Field('DTT_parent', __('Indicates what DTT_ID is the parent of this DTT_ID'), true, 0 ),
58
-				'DTT_deleted' => new EE_Trashed_Flag_Field('DTT_deleted', __('Flag indicating datetime is archived', 'event_espresso'), false, false ),
57
+				'DTT_parent' => new EE_Integer_Field('DTT_parent', __('Indicates what DTT_ID is the parent of this DTT_ID'), true, 0),
58
+				'DTT_deleted' => new EE_Trashed_Flag_Field('DTT_deleted', __('Flag indicating datetime is archived', 'event_espresso'), false, false),
59 59
 			));
60 60
 		$this->_model_relations = array(
61 61
 			'Ticket'=>new EE_HABTM_Relation('Datetime_Ticket'),
@@ -64,11 +64,11 @@  discard block
 block discarded – undo
64 64
 		);
65 65
 		$this->_model_chain_to_wp_user = 'Event';
66 66
 		//this model is generally available for reading
67
-		$this->_cap_restriction_generators[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Event_Related_Public( 'Event' );
68
-		$this->_cap_restriction_generators[ EEM_Base::caps_read_admin ] = new EE_Restriction_Generator_Event_Related_Protected( 'Event' );
69
-		$this->_cap_restriction_generators[ EEM_Base::caps_edit ] = new EE_Restriction_Generator_Event_Related_Protected( 'Event' );
70
-		$this->_cap_restriction_generators[ EEM_Base::caps_delete ] = new EE_Restriction_Generator_Event_Related_Protected( 'Event', EEM_Base::caps_edit );
71
-		parent::__construct( $timezone );
67
+		$this->_cap_restriction_generators[EEM_Base::caps_read] = new EE_Restriction_Generator_Event_Related_Public('Event');
68
+		$this->_cap_restriction_generators[EEM_Base::caps_read_admin] = new EE_Restriction_Generator_Event_Related_Protected('Event');
69
+		$this->_cap_restriction_generators[EEM_Base::caps_edit] = new EE_Restriction_Generator_Event_Related_Protected('Event');
70
+		$this->_cap_restriction_generators[EEM_Base::caps_delete] = new EE_Restriction_Generator_Event_Related_Protected('Event', EEM_Base::caps_edit);
71
+		parent::__construct($timezone);
72 72
 	}
73 73
 
74 74
 
@@ -83,16 +83,16 @@  discard block
 block discarded – undo
83 83
 	public function create_new_blank_datetime() {
84 84
 		$blank_datetime = EE_Datetime::new_instance(
85 85
 			array(
86
-				'DTT_EVT_start' => $this->current_time_for_query( 'DTT_EVT_start', true ) + (60 * 60 * 24 * 30),
87
-				'DTT_EVT_end' => $this->current_time_for_query( 'DTT_EVT_end', true ) + (60 * 60 * 24 * 30),
86
+				'DTT_EVT_start' => $this->current_time_for_query('DTT_EVT_start', true) + (60 * 60 * 24 * 30),
87
+				'DTT_EVT_end' => $this->current_time_for_query('DTT_EVT_end', true) + (60 * 60 * 24 * 30),
88 88
 				'DTT_order' => 1,
89 89
 				'DTT_reg_limit' => EE_INF
90 90
 			),
91 91
 			$this->_timezone
92 92
 		);
93
-		$blank_datetime->set_start_time( $this->convert_datetime_for_query( 'DTT_EVT_start', '8am', 'ga', $this->_timezone ) );
94
-		$blank_datetime->set_end_time( $this->convert_datetime_for_query( 'DTT_EVT_end', '5pm', 'ga', $this->_timezone ) );
95
-		return array( $blank_datetime );
93
+		$blank_datetime->set_start_time($this->convert_datetime_for_query('DTT_EVT_start', '8am', 'ga', $this->_timezone));
94
+		$blank_datetime->set_end_time($this->convert_datetime_for_query('DTT_EVT_end', '5pm', 'ga', $this->_timezone));
95
+		return array($blank_datetime);
96 96
 	}
97 97
 
98 98
 
@@ -106,13 +106,13 @@  discard block
 block discarded – undo
106 106
 	* 		@param		int 			$EVT_ID
107 107
 	*		@return 		EE_Datetime[]		array on success, FALSE on fail
108 108
 	*/
109
-	public function get_all_event_dates( $EVT_ID = 0 ) {
110
-		if ( ! $EVT_ID ) { // on add_new_event event_id gets set to 0
109
+	public function get_all_event_dates($EVT_ID = 0) {
110
+		if ( ! $EVT_ID) { // on add_new_event event_id gets set to 0
111 111
 			return $this->create_new_blank_datetime();
112 112
 		}
113
-		$results =  $this->get_datetimes_for_event_ordered_by_DTT_order($EVT_ID);
113
+		$results = $this->get_datetimes_for_event_ordered_by_DTT_order($EVT_ID);
114 114
 
115
-		if ( empty( $results ) ) {
115
+		if (empty($results)) {
116 116
 			return $this->create_new_blank_datetime();
117 117
 		}
118 118
 
@@ -133,26 +133,26 @@  discard block
 block discarded – undo
133 133
 	 *                        	the given number
134 134
 	 * @return EE_Datetime[]
135 135
 	 */
136
-	public function get_datetimes_for_event_ordered_by_DTT_order( $EVT_ID, $include_expired = TRUE, $include_deleted= TRUE, $limit = NULL  ) {
136
+	public function get_datetimes_for_event_ordered_by_DTT_order($EVT_ID, $include_expired = TRUE, $include_deleted = TRUE, $limit = NULL) {
137 137
 
138 138
 		//sanitize EVT_ID
139
-		$EVT_ID = intval( $EVT_ID );
139
+		$EVT_ID = intval($EVT_ID);
140 140
 
141 141
 		$old_assumption = $this->get_assumption_concerning_values_already_prepared_by_model_object();
142
-		$this->assume_values_already_prepared_by_model_object( EEM_Base::prepared_for_use_in_db );
143
-		$where_params = array( 'Event.EVT_ID' => $EVT_ID );
142
+		$this->assume_values_already_prepared_by_model_object(EEM_Base::prepared_for_use_in_db);
143
+		$where_params = array('Event.EVT_ID' => $EVT_ID);
144 144
 
145
-		$query_params = ! empty( $limit ) ? array( $where_params, 'limit' => $limit, 'order_by' => array( 'DTT_order' => 'ASC' ), 'default_where_conditions' => 'none' ) : array( $where_params, 'order_by' => array( 'DTT_order' => 'ASC' ), 'default_where_conditions' => 'none' );
145
+		$query_params = ! empty($limit) ? array($where_params, 'limit' => $limit, 'order_by' => array('DTT_order' => 'ASC'), 'default_where_conditions' => 'none') : array($where_params, 'order_by' => array('DTT_order' => 'ASC'), 'default_where_conditions' => 'none');
146 146
 
147
-		if( ! $include_expired){
148
-			$query_params[0]['DTT_EVT_end'] = array( '>=', current_time( 'mysql', TRUE ) );
147
+		if ( ! $include_expired) {
148
+			$query_params[0]['DTT_EVT_end'] = array('>=', current_time('mysql', TRUE));
149 149
 		}
150
-		if( $include_deleted){
151
-			$query_params[0]['DTT_deleted'] = array( 'IN', array( TRUE, FALSE ));
150
+		if ($include_deleted) {
151
+			$query_params[0]['DTT_deleted'] = array('IN', array(TRUE, FALSE));
152 152
 		}
153 153
 
154
-		$result = $this->get_all( $query_params );
155
-		$this->assume_values_already_prepared_by_model_object( $old_assumption );
154
+		$result = $this->get_all($query_params);
155
+		$this->assume_values_already_prepared_by_model_object($old_assumption);
156 156
 		return $result;
157 157
 	}
158 158
 
@@ -167,8 +167,8 @@  discard block
 block discarded – undo
167 167
 	 * @param int $limit
168 168
 	 * @return EE_Datetime[]
169 169
 	 */
170
-	public function get_datetimes_for_event_ordered_by_importance( $EVT_ID = 0, $limit = NULL){
171
-		return $this->get_all( array(array('Event.EVT_ID'=>$EVT_ID),
170
+	public function get_datetimes_for_event_ordered_by_importance($EVT_ID = 0, $limit = NULL) {
171
+		return $this->get_all(array(array('Event.EVT_ID'=>$EVT_ID),
172 172
 			'limit'=>$limit,
173 173
 			'order_by'=>array('DTT_EVT_start'=>'ASC'),
174 174
 			'default_where_conditions' => 'none'));
@@ -183,11 +183,11 @@  discard block
 block discarded – undo
183 183
 	 * @param boolean $include_deleted
184 184
 	 * @return EE_Datetime
185 185
 	 */
186
-	public function get_oldest_datetime_for_event($EVT_ID, $include_expired = false,$include_deleted = false){
187
-		$results =  $this->get_datetimes_for_event_ordered_by_start_time($EVT_ID, $include_expired, $include_deleted, 1);
188
-		if($results){
186
+	public function get_oldest_datetime_for_event($EVT_ID, $include_expired = false, $include_deleted = false) {
187
+		$results = $this->get_datetimes_for_event_ordered_by_start_time($EVT_ID, $include_expired, $include_deleted, 1);
188
+		if ($results) {
189 189
 			return array_shift($results);
190
-		}else{
190
+		} else {
191 191
 			return NULL;
192 192
 		}
193 193
 	}
@@ -201,16 +201,16 @@  discard block
 block discarded – undo
201 201
 	 * @param bool $try_to_exclude_deleted
202 202
 	 * @return \EE_Datetime
203 203
 	 */
204
-	public function get_primary_datetime_for_event($EVT_ID,$try_to_exclude_expired = true, $try_to_exclude_deleted = true){
205
-		if($try_to_exclude_expired){
206
-			$non_expired = $this->get_oldest_datetime_for_event($EVT_ID, false,false);
207
-			if($non_expired){
204
+	public function get_primary_datetime_for_event($EVT_ID, $try_to_exclude_expired = true, $try_to_exclude_deleted = true) {
205
+		if ($try_to_exclude_expired) {
206
+			$non_expired = $this->get_oldest_datetime_for_event($EVT_ID, false, false);
207
+			if ($non_expired) {
208 208
 				return $non_expired;
209 209
 			}
210 210
 		}
211
-		if($try_to_exclude_deleted){
211
+		if ($try_to_exclude_deleted) {
212 212
 			$expired_even = $this->get_oldest_datetime_for_event($EVT_ID, true);
213
-			if($expired_even){
213
+			if ($expired_even) {
214 214
 				return $expired_even;
215 215
 			}
216 216
 		}
@@ -229,23 +229,23 @@  discard block
 block discarded – undo
229 229
 	 * @param int $limit
230 230
 	 * @return EE_Datetime[]
231 231
 	 */
232
-	public function get_datetimes_for_event_ordered_by_start_time($EVT_ID, $include_expired = true, $include_deleted= true, $limit = NULL ){
232
+	public function get_datetimes_for_event_ordered_by_start_time($EVT_ID, $include_expired = true, $include_deleted = true, $limit = NULL) {
233 233
 		//sanitize EVT_ID
234
-		$EVT_ID = intval( $EVT_ID );
234
+		$EVT_ID = intval($EVT_ID);
235 235
 		$old_assumption = $this->get_assumption_concerning_values_already_prepared_by_model_object();
236
-		$this->assume_values_already_prepared_by_model_object( EEM_Base::prepared_for_use_in_db );
237
-		$query_params =array(array('Event.EVT_ID'=>$EVT_ID),'order_by'=>array('DTT_EVT_start'=>'asc'));
238
-		if( ! $include_expired){
239
-			$query_params[0]['DTT_EVT_end'] = array('>=',current_time('mysql', TRUE));
236
+		$this->assume_values_already_prepared_by_model_object(EEM_Base::prepared_for_use_in_db);
237
+		$query_params = array(array('Event.EVT_ID'=>$EVT_ID), 'order_by'=>array('DTT_EVT_start'=>'asc'));
238
+		if ( ! $include_expired) {
239
+			$query_params[0]['DTT_EVT_end'] = array('>=', current_time('mysql', TRUE));
240 240
 		}
241
-		if( $include_deleted){
242
-			$query_params[0]['DTT_deleted'] = array('IN',array(true,false));
241
+		if ($include_deleted) {
242
+			$query_params[0]['DTT_deleted'] = array('IN', array(true, false));
243 243
 		}
244
-		if($limit){
244
+		if ($limit) {
245 245
 			$query_params['limit'] = $limit;
246 246
 		}
247
-		$result = $this->get_all( $query_params );
248
-		$this->assume_values_already_prepared_by_model_object( $old_assumption );
247
+		$result = $this->get_all($query_params);
248
+		$this->assume_values_already_prepared_by_model_object($old_assumption);
249 249
 		return $result;
250 250
 	}
251 251
 
@@ -258,23 +258,23 @@  discard block
 block discarded – undo
258 258
 	 * @param int $limit
259 259
 	 * @return EE_Datetime[]
260 260
 	 */
261
-	public function get_datetimes_for_ticket_ordered_by_start_time($TKT_ID, $include_expired = true, $include_deleted= true, $limit = NULL){
261
+	public function get_datetimes_for_ticket_ordered_by_start_time($TKT_ID, $include_expired = true, $include_deleted = true, $limit = NULL) {
262 262
 		//sanitize TKT_ID
263
-		$TKT_ID =  intval( $TKT_ID );
263
+		$TKT_ID = intval($TKT_ID);
264 264
 		$old_assumption = $this->get_assumption_concerning_values_already_prepared_by_model_object();
265
-		$this->assume_values_already_prepared_by_model_object( EEM_Base::prepared_for_use_in_db );
266
-		$query_params =array(array('Ticket.TKT_ID'=>$TKT_ID),'order_by'=>array('DTT_EVT_start'=>'asc'));
267
-		if( ! $include_expired){
268
-			$query_params[0]['DTT_EVT_end'] = array('>=',current_time('mysql', TRUE));
265
+		$this->assume_values_already_prepared_by_model_object(EEM_Base::prepared_for_use_in_db);
266
+		$query_params = array(array('Ticket.TKT_ID'=>$TKT_ID), 'order_by'=>array('DTT_EVT_start'=>'asc'));
267
+		if ( ! $include_expired) {
268
+			$query_params[0]['DTT_EVT_end'] = array('>=', current_time('mysql', TRUE));
269 269
 		}
270
-		if( $include_deleted){
271
-			$query_params[0]['DTT_deleted'] = array('IN',array(true,false));
270
+		if ($include_deleted) {
271
+			$query_params[0]['DTT_deleted'] = array('IN', array(true, false));
272 272
 		}
273
-		if($limit){
273
+		if ($limit) {
274 274
 			$query_params['limit'] = $limit;
275 275
 		}
276
-		$result = $this->get_all( $query_params );
277
-		$this->assume_values_already_prepared_by_model_object( $old_assumption );
276
+		$result = $this->get_all($query_params);
277
+		$this->assume_values_already_prepared_by_model_object($old_assumption);
278 278
 		return $result;
279 279
 	}
280 280
 
@@ -290,24 +290,24 @@  discard block
 block discarded – undo
290 290
 	 *                                  that number
291 291
 	 * @return EE_Datetime[]
292 292
 	 */
293
-	public function get_datetimes_for_ticket_ordered_by_DTT_order( $TKT_ID, $include_expired = true, $include_deleted = true, $limit = NULL ) {
293
+	public function get_datetimes_for_ticket_ordered_by_DTT_order($TKT_ID, $include_expired = true, $include_deleted = true, $limit = NULL) {
294 294
 		//sanitize id.
295
-		$TKT_ID =  intval( $TKT_ID );
295
+		$TKT_ID = intval($TKT_ID);
296 296
 		$old_assumption = $this->get_assumption_concerning_values_already_prepared_by_model_object();
297
-		$this->assume_values_already_prepared_by_model_object( EEM_Base::prepared_for_use_in_db );
298
-		$where_params = array( 'Ticket.TKT_ID' => $TKT_ID );
299
-		$query_params = array( $where_params, 'order_by' => array( 'DTT_order' => 'ASC' ) );
300
-		if( ! $include_expired){
301
-			$query_params[0]['DTT_EVT_end'] = array('>=',current_time('mysql', TRUE));
297
+		$this->assume_values_already_prepared_by_model_object(EEM_Base::prepared_for_use_in_db);
298
+		$where_params = array('Ticket.TKT_ID' => $TKT_ID);
299
+		$query_params = array($where_params, 'order_by' => array('DTT_order' => 'ASC'));
300
+		if ( ! $include_expired) {
301
+			$query_params[0]['DTT_EVT_end'] = array('>=', current_time('mysql', TRUE));
302 302
 		}
303
-		if( $include_deleted){
304
-			$query_params[0]['DTT_deleted'] = array('IN',array(true,false));
303
+		if ($include_deleted) {
304
+			$query_params[0]['DTT_deleted'] = array('IN', array(true, false));
305 305
 		}
306
-		if($limit){
306
+		if ($limit) {
307 307
 			$query_params['limit'] = $limit;
308 308
 		}
309
-		$result = $this->get_all( $query_params );
310
-		$this->assume_values_already_prepared_by_model_object( $old_assumption );
309
+		$result = $this->get_all($query_params);
310
+		$this->assume_values_already_prepared_by_model_object($old_assumption);
311 311
 		return $result;
312 312
 	}
313 313
 
@@ -318,11 +318,11 @@  discard block
 block discarded – undo
318 318
 	 * @param int $EVT_ID
319 319
 	 * @return EE_Datetime
320 320
 	 */
321
-	public function get_most_important_datetime_for_event($EVT_ID){
321
+	public function get_most_important_datetime_for_event($EVT_ID) {
322 322
 		$results = $this->get_datetimes_for_event_ordered_by_importance($EVT_ID, 1);
323
-		if($results){
323
+		if ($results) {
324 324
 			return array_shift($results);
325
-		}else{
325
+		} else {
326 326
 			return null;
327 327
 		}
328 328
 	}
@@ -341,78 +341,78 @@  discard block
 block discarded – undo
341 341
 	 * 			- inactive = Events that are either not published.
342 342
 	 * @return wpdb results array
343 343
 	 */
344
-	public function get_dtt_months_and_years( $where_params, $evt_active_status = '' ) {
345
-		$current_time_for_DTT_EVT_start = $this->current_time_for_query( 'DTT_EVT_start' );
346
-		$current_time_for_DTT_EVT_end = $this->current_time_for_query( 'DTT_EVT_end' );
344
+	public function get_dtt_months_and_years($where_params, $evt_active_status = '') {
345
+		$current_time_for_DTT_EVT_start = $this->current_time_for_query('DTT_EVT_start');
346
+		$current_time_for_DTT_EVT_end = $this->current_time_for_query('DTT_EVT_end');
347 347
 
348
-		switch ( $evt_active_status ) {
348
+		switch ($evt_active_status) {
349 349
 			case 'upcoming' :
350 350
 					$where_params['Event.status'] = 'publish';
351 351
 					//if there are already query_params matching DTT_EVT_start then we need to modify that to add them.
352
-					if ( isset( $where_params['DTT_EVT_start'] ) ) {
352
+					if (isset($where_params['DTT_EVT_start'])) {
353 353
 						$where_params['DTT_EVT_start*****'] = $where_params['DTT_EVT_start'];
354 354
 					}
355
-					$where_params['DTT_EVT_start'] = array('>', $current_time_for_DTT_EVT_start );
355
+					$where_params['DTT_EVT_start'] = array('>', $current_time_for_DTT_EVT_start);
356 356
 					break;
357 357
 
358 358
 			case 'expired' :
359
-				if ( isset( $where_params['Event.status'] ) ) unset( $where_params['Event.status'] );
359
+				if (isset($where_params['Event.status'])) unset($where_params['Event.status']);
360 360
 				//get events to exclude
361
-				$exclude_query[0] = array_merge( $where_params, array( 'DTT_EVT_end' => array( '>', $current_time_for_DTT_EVT_end ) ) );
361
+				$exclude_query[0] = array_merge($where_params, array('DTT_EVT_end' => array('>', $current_time_for_DTT_EVT_end)));
362 362
 				//first get all events that have datetimes where its not expired.
363
-				$event_ids = $this->_get_all_wpdb_results( $exclude_query, OBJECT_K, 'Datetime.EVT_ID' );
364
-				$event_ids = array_keys( $event_ids );
363
+				$event_ids = $this->_get_all_wpdb_results($exclude_query, OBJECT_K, 'Datetime.EVT_ID');
364
+				$event_ids = array_keys($event_ids);
365 365
 
366
-				if ( isset( $where_params['DTT_EVT_end'] ) ) {
366
+				if (isset($where_params['DTT_EVT_end'])) {
367 367
 					$where_params['DTT_EVT_end****'] = $where_params['DTT_EVT_end'];
368 368
 				}
369
-				$where_params['DTT_EVT_end'] = array( '<', $current_time_for_DTT_EVT_end );
370
-				$where_params['Event.EVT_ID'] = array( 'NOT IN', $event_ids );
369
+				$where_params['DTT_EVT_end'] = array('<', $current_time_for_DTT_EVT_end);
370
+				$where_params['Event.EVT_ID'] = array('NOT IN', $event_ids);
371 371
 				break;
372 372
 
373 373
 			case 'active' :
374 374
 				$where_params['Event.status'] = 'publish';
375
-				if ( isset( $where_params['DTT_EVT_start'] ) ) {
375
+				if (isset($where_params['DTT_EVT_start'])) {
376 376
 					$where_params['Datetime.DTT_EVT_start******'] = $where_params['DTT_EVT_start'];
377 377
 				}
378
-				if ( isset( $where_params['Datetime.DTT_EVT_end'] ) ) {
378
+				if (isset($where_params['Datetime.DTT_EVT_end'])) {
379 379
 					$where_params['Datetime.DTT_EVT_end*****'] = $where_params['DTT_EVT_end'];
380 380
 				}
381
-				$where_params['DTT_EVT_start'] = array('<',  $current_time_for_DTT_EVT_start );
382
-				$where_params['DTT_EVT_end'] = array('>', $current_time_for_DTT_EVT_end );
381
+				$where_params['DTT_EVT_start'] = array('<', $current_time_for_DTT_EVT_start);
382
+				$where_params['DTT_EVT_end'] = array('>', $current_time_for_DTT_EVT_end);
383 383
 				break;
384 384
 
385 385
 			case 'inactive' :
386
-				if ( isset( $where_params['Event.status'] ) ) unset( $where_params['Event.status'] );
387
-				if ( isset( $where_params['OR'] ) ) {
386
+				if (isset($where_params['Event.status'])) unset($where_params['Event.status']);
387
+				if (isset($where_params['OR'])) {
388 388
 					$where_params['AND']['OR'] = $where_params['OR'];
389 389
 				}
390
-				if ( isset( $where_params['DTT_EVT_end'] ) ) {
390
+				if (isset($where_params['DTT_EVT_end'])) {
391 391
 					$where_params['AND']['DTT_EVT_end****'] = $where_params['DTT_EVT_end'];
392
-					unset( $where_params['DTT_EVT_end'] );
392
+					unset($where_params['DTT_EVT_end']);
393 393
 				}
394 394
 
395
-				if ( isset( $where_params['DTT_EVT_start'] ) ) {
395
+				if (isset($where_params['DTT_EVT_start'])) {
396 396
 					$where_params['AND']['DTT_EVT_start'] = $where_params['DTT_EVT_start'];
397
-					unset( $where_params['DTT_EVT_start'] );
397
+					unset($where_params['DTT_EVT_start']);
398 398
 				}
399
-				$where_params['AND']['Event.status'] = array( '!=', 'publish' );
399
+				$where_params['AND']['Event.status'] = array('!=', 'publish');
400 400
 				break;
401 401
 		}
402 402
 
403 403
 		$query_params[0] = $where_params;
404 404
 		$query_params['group_by'] = array('dtt_year', 'dtt_month');
405
-		$query_params['order_by'] = array( 'DTT_EVT_start' => 'DESC' );
405
+		$query_params['order_by'] = array('DTT_EVT_start' => 'DESC');
406 406
 
407
-		EE_Registry::instance()->load_helper( 'DTT_Helper' );
408
-		$query_interval = EEH_DTT_Helper::get_sql_query_interval_for_offset( $this->get_timezone(), 'DTT_EVT_start' );
407
+		EE_Registry::instance()->load_helper('DTT_Helper');
408
+		$query_interval = EEH_DTT_Helper::get_sql_query_interval_for_offset($this->get_timezone(), 'DTT_EVT_start');
409 409
 
410 410
 		$columns_to_select = array(
411
-			'dtt_year' => array('YEAR(' . $query_interval . ')', '%s'),
412
-			'dtt_month' => array('MONTHNAME(' . $query_interval . ')', '%s'),
413
-			'dtt_month_num' => array('MONTH(' . $query_interval .')', '%s')
411
+			'dtt_year' => array('YEAR('.$query_interval.')', '%s'),
412
+			'dtt_month' => array('MONTHNAME('.$query_interval.')', '%s'),
413
+			'dtt_month_num' => array('MONTH('.$query_interval.')', '%s')
414 414
 			);
415
-		return $this->_get_all_wpdb_results( $query_params, OBJECT, $columns_to_select );
415
+		return $this->_get_all_wpdb_results($query_params, OBJECT, $columns_to_select);
416 416
 	}
417 417
 
418 418
 	/**
@@ -420,8 +420,8 @@  discard block
 block discarded – undo
420 420
 	 * for the tickets for each datetime)
421 421
 	 * @param EE_Datetime[] $datetimes
422 422
 	 */
423
-	public function update_sold($datetimes){
424
-		foreach($datetimes as $datetime){
423
+	public function update_sold($datetimes) {
424
+		foreach ($datetimes as $datetime) {
425 425
 			$datetime->update_sold();
426 426
 		}
427 427
 	}
@@ -436,10 +436,10 @@  discard block
 block discarded – undo
436 436
 	 * @param array $query_params
437 437
 	 * @return int of tickets available. If sold out, return less than 1. If infinite, returns EE_INF,  IF there are NO tickets attached to datetime then FALSE is returned.
438 438
 	 */
439
-	public function sum_tickets_currently_available_at_datetime( $DTT_ID, $query_params = array() ) {
440
-		$datetime = $this->get_one_by_ID( $DTT_ID );
441
-		if ( $datetime instanceof EE_Datetime ) {
442
-			return $datetime->tickets_remaining( $query_params );
439
+	public function sum_tickets_currently_available_at_datetime($DTT_ID, $query_params = array()) {
440
+		$datetime = $this->get_one_by_ID($DTT_ID);
441
+		if ($datetime instanceof EE_Datetime) {
442
+			return $datetime->tickets_remaining($query_params);
443 443
 		}
444 444
 		return 0;
445 445
 	}
@@ -461,36 +461,36 @@  discard block
 block discarded – undo
461 461
 	 *                EE_Datetime::upcoming
462 462
 	 *                EE_Datetime::expired
463 463
 	 */
464
-	public function get_datetime_counts_by_status( $stati_to_include = array(), $query_params = array() ) {
464
+	public function get_datetime_counts_by_status($stati_to_include = array(), $query_params = array()) {
465 465
 		//only accept where conditions for this query.
466
-		$_where = isset( $query_params[0] ) ? $query_params[0] : array();
466
+		$_where = isset($query_params[0]) ? $query_params[0] : array();
467 467
 		$status_query_args = array(
468 468
 				EE_Datetime::active => array_merge(
469 469
 						$_where,
470
-						array( 'DTT_EVT_start' => array( '<', time() ), 'DTT_EVT_end' => array( '>', time() ) )
470
+						array('DTT_EVT_start' => array('<', time()), 'DTT_EVT_end' => array('>', time()))
471 471
 				),
472 472
 				EE_Datetime::upcoming => array_merge(
473 473
 						$_where,
474
-						array( 'DTT_EVT_start' => array( '>', time() ) )
474
+						array('DTT_EVT_start' => array('>', time()))
475 475
 				),
476 476
 				EE_Datetime::expired => array_merge(
477 477
 						$_where,
478
-						array( 'DTT_EVT_end' => array('<', time() ) )
478
+						array('DTT_EVT_end' => array('<', time()))
479 479
 				)
480 480
 		);
481 481
 
482
-		if ( ! empty( $stati_to_include ) ) {
483
-			foreach( array_keys( $status_query_args ) as $status ) {
484
-				if ( ! in_array( $status, $stati_to_include ) ) {
485
-					unset( $status_query_args[$status] );
482
+		if ( ! empty($stati_to_include)) {
483
+			foreach (array_keys($status_query_args) as $status) {
484
+				if ( ! in_array($status, $stati_to_include)) {
485
+					unset($status_query_args[$status]);
486 486
 				}
487 487
 			}
488 488
 		}
489 489
 
490 490
 		//loop through and query counts for each stati.
491 491
 		$status_query_results = array();
492
-		foreach( $status_query_args as $status => $status_where_conditions ) {
493
-			$status_query_results[ $status ] = EEM_Datetime::count( array( $status_where_conditions ), 'DTT_ID', true );
492
+		foreach ($status_query_args as $status => $status_where_conditions) {
493
+			$status_query_results[$status] = EEM_Datetime::count(array($status_where_conditions), 'DTT_ID', true);
494 494
 		}
495 495
 
496 496
 		return $status_query_results;
@@ -504,9 +504,9 @@  discard block
 block discarded – undo
504 504
 	 * @param array $query_params
505 505
 	 * @return int
506 506
 	 */
507
-	public function get_datetime_count_for_status( $status = EE_Datetime::active, $query_params = array() ) {
508
-		$count = $this->get_datetime_counts_by_status( array( $status ), $query_params );
509
-		return ! empty( $count[$status] ) ? $count[$status] : 0;
507
+	public function get_datetime_count_for_status($status = EE_Datetime::active, $query_params = array()) {
508
+		$count = $this->get_datetime_counts_by_status(array($status), $query_params);
509
+		return ! empty($count[$status]) ? $count[$status] : 0;
510 510
 	}
511 511
 
512 512
 
Please login to merge, or discard this patch.
core/db_models/EEM_Datetime_Ticket.model.php 2 patches
Spacing   +13 added lines, -13 removed lines patch added patch discarded remove patch
@@ -21,8 +21,8 @@  discard block
 block discarded – undo
21 21
  *
22 22
  * ------------------------------------------------------------------------
23 23
  */
24
-require_once ( EE_MODELS . 'EEM_Base.model.php' );
25
-require_once ( EE_CLASSES . 'EE_Datetime_Ticket.class.php' );
24
+require_once (EE_MODELS.'EEM_Base.model.php');
25
+require_once (EE_CLASSES.'EE_Datetime_Ticket.class.php');
26 26
 
27 27
 class EEM_Datetime_Ticket extends EEM_Base {
28 28
 
@@ -37,28 +37,28 @@  discard block
 block discarded – undo
37 37
 	 *		@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)
38 38
 	 *		@return void
39 39
 	 */
40
-	protected function __construct( $timezone ) {
41
-		$this->singular_item = __('Datetime Ticket','event_espresso');
42
-		$this->plural_item = __('Datetime Tickets','event_espresso');
40
+	protected function __construct($timezone) {
41
+		$this->singular_item = __('Datetime Ticket', 'event_espresso');
42
+		$this->plural_item = __('Datetime Tickets', 'event_espresso');
43 43
 
44 44
 		$this->_tables = array(
45 45
 			'Datetime_Ticket'=> new EE_Primary_Table('esp_datetime_ticket', 'DTK_ID')
46 46
 		);
47 47
 		$this->_fields = array(
48 48
 			'Datetime_Ticket'=>array(
49
-				'DTK_ID'=>new EE_Primary_Key_Int_Field('DTK_ID', __('Datetime Ticket ID','event_espresso')),
50
-				'DTT_ID'=>new EE_Foreign_Key_Int_Field('DTT_ID', __('The ID to the Datetime','event_espresso'), false, 0, 'Datetime' ),
51
-				'TKT_ID'=>new EE_Foreign_Key_Int_Field('TKT_ID', __('The ID to the Ticket','event_espresso'), false, 0, 'Ticket' )
49
+				'DTK_ID'=>new EE_Primary_Key_Int_Field('DTK_ID', __('Datetime Ticket ID', 'event_espresso')),
50
+				'DTT_ID'=>new EE_Foreign_Key_Int_Field('DTT_ID', __('The ID to the Datetime', 'event_espresso'), false, 0, 'Datetime'),
51
+				'TKT_ID'=>new EE_Foreign_Key_Int_Field('TKT_ID', __('The ID to the Ticket', 'event_espresso'), false, 0, 'Ticket')
52 52
 			));
53 53
 		$this->_model_relations = array(
54 54
 			'Ticket'=>new EE_Belongs_To_Relation(),
55 55
 			'Datetime'=>new EE_Belongs_To_Relation()
56 56
 		);
57 57
 		//this model is generally available for reading
58
-		$this->_cap_restriction_generators[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Event_Related_Public( 'Datetime.Event' );
59
-		$this->_cap_restriction_generators[ EEM_Base::caps_read_admin ] = new EE_Restriction_Generator_Event_Related_Protected( 'Datetime.Event' );
60
-		$this->_cap_restriction_generators[ EEM_Base::caps_edit ] = new EE_Restriction_Generator_Event_Related_Protected( 'Datetime.Event' );
61
-		$this->_cap_restriction_generators[ EEM_Base::caps_delete ] = new EE_Restriction_Generator_Event_Related_Protected( 'Datetime.Event', EEM_Base::caps_edit );
62
-		parent::__construct( $timezone );
58
+		$this->_cap_restriction_generators[EEM_Base::caps_read] = new EE_Restriction_Generator_Event_Related_Public('Datetime.Event');
59
+		$this->_cap_restriction_generators[EEM_Base::caps_read_admin] = new EE_Restriction_Generator_Event_Related_Protected('Datetime.Event');
60
+		$this->_cap_restriction_generators[EEM_Base::caps_edit] = new EE_Restriction_Generator_Event_Related_Protected('Datetime.Event');
61
+		$this->_cap_restriction_generators[EEM_Base::caps_delete] = new EE_Restriction_Generator_Event_Related_Protected('Datetime.Event', EEM_Base::caps_edit);
62
+		parent::__construct($timezone);
63 63
 	}
64 64
 } //end EEM_Datetime_Ticket class
65 65
\ No newline at end of file
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.