Completed
Branch BUG-8698-ticket-sellouts (d652f0)
by
unknown
814:28 queued 786:25
created
core/db_models/EEM_Event.model.php 1 patch
Indentation   +43 added lines, -43 removed lines patch added patch discarded remove patch
@@ -179,11 +179,11 @@  discard block
 block discarded – undo
179 179
 
180 180
 
181 181
 	/**
182
-	*		get_question_groups
183
-	*
184
-	* 		@access		public
185
-	*		@return 		array
186
-	*/
182
+	 *		get_question_groups
183
+	 *
184
+	 * 		@access		public
185
+	 *		@return 		array
186
+	 */
187 187
 	public function get_all_question_groups() {
188 188
 		return EE_Registry::instance()->load_model( 'Question_Group' )->get_all( array(
189 189
 			array( 'QSG_deleted' => FALSE ),
@@ -197,12 +197,12 @@  discard block
 block discarded – undo
197 197
 
198 198
 
199 199
 	/**
200
-	*		get_question_groups
201
-	*
202
-	* 		@access		public
203
-	* 		@param		int $EVT_ID
204
-	*		@return 		array
205
-	*/
200
+	 *		get_question_groups
201
+	 *
202
+	 * 		@access		public
203
+	 * 		@param		int $EVT_ID
204
+	 *		@return 		array
205
+	 */
206 206
 	public function get_all_event_question_groups( $EVT_ID = 0 ) {
207 207
 		if ( ! isset( $EVT_ID) || ! absint( $EVT_ID )) {
208 208
 			EE_Error::add_error( __( 'An error occurred. No Event Question Groups could be retrieved because an Event ID was not received.', 'event_espresso' ), __FILE__, __FUNCTION__, __LINE__ );
@@ -218,13 +218,13 @@  discard block
 block discarded – undo
218 218
 
219 219
 
220 220
 	/**
221
-	*		get_question_groups
222
-	*
223
-	* 		@access		public
224
-	* 		@param		int $EVT_ID
225
-	* 		@param		boolean	$for_primary_attendee
226
-	*		@return 		array
227
-	*/
221
+	 *		get_question_groups
222
+	 *
223
+	 * 		@access		public
224
+	 * 		@param		int $EVT_ID
225
+	 * 		@param		boolean	$for_primary_attendee
226
+	 *		@return 		array
227
+	 */
228 228
 	public function get_event_question_groups( $EVT_ID = 0, $for_primary_attendee = TRUE ) {
229 229
 		if ( ! isset( $EVT_ID) || ! absint( $EVT_ID )) {
230 230
 			EE_Error::add_error( __( 'An error occurred. No Event Question Groups could be retrieved because an Event ID was not received.', 'event_espresso' ), __FILE__, __FUNCTION__, __LINE__ );
@@ -241,13 +241,13 @@  discard block
 block discarded – undo
241 241
 
242 242
 
243 243
 	/**
244
-	*		get_question_groups
245
-	*
246
-	* 		@access		public
247
-	* 		@param		int $EVT_ID
248
-	* 		@param		EE_Registration 	$registration
249
-	*		@return 		array
250
-	*/
244
+	 *		get_question_groups
245
+	 *
246
+	 * 		@access		public
247
+	 * 		@param		int $EVT_ID
248
+	 * 		@param		EE_Registration 	$registration
249
+	 *		@return 		array
250
+	 */
251 251
 	public function get_question_groups_for_event( $EVT_ID = 0, EE_Registration $registration ) {
252 252
 
253 253
 		if ( ! isset( $EVT_ID) || ! absint( $EVT_ID )) {
@@ -275,12 +275,12 @@  discard block
 block discarded – undo
275 275
 
276 276
 
277 277
 	/**
278
-	*		get_question_target_db_column
279
-	*
280
-	* 		@access		public
281
-	* 		@param		string		$QSG_IDs  csv list of $QSG IDs
282
-	*		@return 		array
283
-	*/
278
+	 *		get_question_target_db_column
279
+	 *
280
+	 * 		@access		public
281
+	 * 		@param		string		$QSG_IDs  csv list of $QSG IDs
282
+	 *		@return 		array
283
+	 */
284 284
 	public function get_questions_in_groups( $QSG_IDs = '' ) {
285 285
 
286 286
 		if ( empty( $QSG_IDs )) {
@@ -306,12 +306,12 @@  discard block
 block discarded – undo
306 306
 
307 307
 
308 308
 	/**
309
-	*		get_options_for_question
310
-	*
311
-	* 		@access		public
312
-	* 		@param		string		$QST_IDs  csv list of $QST IDs
313
-	*		@return 		array
314
-	*/
309
+	 *		get_options_for_question
310
+	 *
311
+	 * 		@access		public
312
+	 * 		@param		string		$QST_IDs  csv list of $QST IDs
313
+	 *		@return 		array
314
+	 */
315 315
 	public function get_options_for_question( $QST_IDs ) {
316 316
 
317 317
 		if ( empty( $QST_IDs )) {
@@ -396,12 +396,12 @@  discard block
 block discarded – undo
396 396
 
397 397
 
398 398
 	/**
399
-	*		_get_question_target_db_column
400
-	*
401
-	* 		@access		private
402
-	* 		@param		$QST
403
-	*		@return 		string		string
404
-	*/
399
+	 *		_get_question_target_db_column
400
+	 *
401
+	 * 		@access		private
402
+	 * 		@param		$QST
403
+	 *		@return 		string		string
404
+	 */
405 405
 	private function _generate_question_input_name( $QST ) {
406 406
 
407 407
 		if ( $QST->QST_system ) {
Please login to merge, or discard this patch.
core/db_models/EEM_Base.model.php 4 patches
Indentation   +27 added lines, -27 removed lines patch added patch discarded remove patch
@@ -1,28 +1,28 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 /**
3
- *
4
- * Class EEM_Base
5
- *
6
- * Multi-table model. Especially handles joins when querying.
7
- * An important note about values dealt with in models and model objects:
8
- * values used by models exist in basically 3 different domains, which the EE_Model_Fields help convert between:
9
- * 1. Client-code values (eg, controller code may refer to a date as "March 21, 2013")
10
- * 2. Model object values (eg, after the model object has called set() on the value and saves it onto the model object, it may become a unix timestamp, eg 12312412412)
11
- * 3. Database values (eg, we may later decide to store dates as mysql dates, in which case they'd be stored as '2013-03-21 00:00:00')
12
- * Sometimes these values are the same, but often they are not. When your client code is using a model's functions, you need to be aware
13
- * which domain your data exists in. If it is client-code values (ie, it hasn't had a EE_Model_Field call prepare_for_set on it) then use the
14
- * model functions as normal. However, if you are calling the model functions with values from the model object domain (ie, the code your writing is
15
- * probably within a model object, and all the values you're dealing with have had an EE_Model_Field call prepare_for_set on them), then you'll want
16
- * to set $values_already_prepared_by_model_object to FALSE within the argument-list of the functions you call (in order to avoid re-processing those values).
17
- * If your values are already in the database values domain, you'll either way to convert them into the model object domain by creating model objects
18
- * from those raw db values (ie,using EEM_Base::_create_objects), or just use $wpdb directly.
19
- *
20
- * @package 			Event Espresso
21
- * @subpackage 	core
22
- * @author 				Michael Nelson
23
- * @since 				EE4
24
- *
25
- */
3
+	 *
4
+	 * Class EEM_Base
5
+	 *
6
+	 * Multi-table model. Especially handles joins when querying.
7
+	 * An important note about values dealt with in models and model objects:
8
+	 * values used by models exist in basically 3 different domains, which the EE_Model_Fields help convert between:
9
+	 * 1. Client-code values (eg, controller code may refer to a date as "March 21, 2013")
10
+	 * 2. Model object values (eg, after the model object has called set() on the value and saves it onto the model object, it may become a unix timestamp, eg 12312412412)
11
+	 * 3. Database values (eg, we may later decide to store dates as mysql dates, in which case they'd be stored as '2013-03-21 00:00:00')
12
+	 * Sometimes these values are the same, but often they are not. When your client code is using a model's functions, you need to be aware
13
+	 * which domain your data exists in. If it is client-code values (ie, it hasn't had a EE_Model_Field call prepare_for_set on it) then use the
14
+	 * model functions as normal. However, if you are calling the model functions with values from the model object domain (ie, the code your writing is
15
+	 * probably within a model object, and all the values you're dealing with have had an EE_Model_Field call prepare_for_set on them), then you'll want
16
+	 * to set $values_already_prepared_by_model_object to FALSE within the argument-list of the functions you call (in order to avoid re-processing those values).
17
+	 * If your values are already in the database values domain, you'll either way to convert them into the model object domain by creating model objects
18
+	 * from those raw db values (ie,using EEM_Base::_create_objects), or just use $wpdb directly.
19
+	 *
20
+	 * @package 			Event Espresso
21
+	 * @subpackage 	core
22
+	 * @author 				Michael Nelson
23
+	 * @since 				EE4
24
+	 *
25
+	 */
26 26
 abstract class EEM_Base extends EE_Base{
27 27
 
28 28
 	//admin posty
@@ -578,10 +578,10 @@  discard block
 block discarded – undo
578 578
 	 	$stati = EEM_Status::instance()->get_all(array(array('STS_type' => $status_type) ) );
579 579
 	 	$status_array = array();
580 580
 	 	foreach ( $stati as $status ) {
581
-            $status_array[ $status->ID() ] = $status->get('STS_code');
582
-        }
583
-        return $translated ? EEM_Status::instance()->localized_status($status_array, FALSE, 'sentence') : $status_array;
584
-    }
581
+			$status_array[ $status->ID() ] = $status->get('STS_code');
582
+		}
583
+		return $translated ? EEM_Status::instance()->localized_status($status_array, FALSE, 'sentence') : $status_array;
584
+	}
585 585
 
586 586
 
587 587
 
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.
Spacing   +956 added lines, -956 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
     }
@@ -739,7 +739,7 @@  discard block
 block discarded – undo
739 739
 	 *			'order_by'=>array('ANS_value'=>'ASC')
740 740
 	 *		));
741 741
 	 */
742
-	function get_all($query_params = array()){
742
+	function get_all($query_params = array()) {
743 743
 		return $this->_create_objects($this->_get_all_wpdb_results($query_params, ARRAY_A, NULL));
744 744
 	}
745 745
 
@@ -749,10 +749,10 @@  discard block
 block discarded – undo
749 749
 	 * @param array $query_params @see EEM_Base::get_all()
750 750
 	 * @return array like EEM_Base::get_all
751 751
 	 */
752
-	function alter_query_params_to_only_include_mine( $query_params = array() ) {
752
+	function alter_query_params_to_only_include_mine($query_params = array()) {
753 753
 		$wp_user_field_name = $this->wp_user_field_name();
754
-		if( $wp_user_field_name ){
755
-			$query_params[0][ $wp_user_field_name ] = get_current_user_id();
754
+		if ($wp_user_field_name) {
755
+			$query_params[0][$wp_user_field_name] = get_current_user_id();
756 756
 		}
757 757
 		return $query_params;
758 758
 	}
@@ -765,19 +765,19 @@  discard block
 block discarded – undo
765 765
 	 * foreign key to the WP_User table
766 766
 	 */
767 767
 	function wp_user_field_name() {
768
-		try{
769
-			if( ! empty( $this->_model_chain_to_wp_user ) ) {
770
-				$models_to_follow_to_wp_users = explode( '.', $this->_model_chain_to_wp_user );
771
-				$last_model_name = end( $models_to_follow_to_wp_users );
772
-				$model_with_fk_to_wp_users = EE_Registry::instance()->load_model( $last_model_name );
773
-				$model_chain_to_wp_user = $this->_model_chain_to_wp_user . '.';
774
-			}else{
768
+		try {
769
+			if ( ! empty($this->_model_chain_to_wp_user)) {
770
+				$models_to_follow_to_wp_users = explode('.', $this->_model_chain_to_wp_user);
771
+				$last_model_name = end($models_to_follow_to_wp_users);
772
+				$model_with_fk_to_wp_users = EE_Registry::instance()->load_model($last_model_name);
773
+				$model_chain_to_wp_user = $this->_model_chain_to_wp_user.'.';
774
+			} else {
775 775
 				$model_with_fk_to_wp_users = $this;
776 776
 				$model_chain_to_wp_user = '';
777 777
 			}
778
-			$wp_user_field = $model_with_fk_to_wp_users->get_foreign_key_to( 'WP_User' );
779
-			return $model_chain_to_wp_user . $wp_user_field->get_name();
780
-		}catch( EE_Error $e ) {
778
+			$wp_user_field = $model_with_fk_to_wp_users->get_foreign_key_to('WP_User');
779
+			return $model_chain_to_wp_user.$wp_user_field->get_name();
780
+		} catch (EE_Error $e) {
781 781
 			return false;
782 782
 		}
783 783
 	}
@@ -791,7 +791,7 @@  discard block
 block discarded – undo
791 791
 	 * (or transiently-related model)
792 792
 	 * @return string
793 793
 	 */
794
-	public function model_chain_to_wp_user(){
794
+	public function model_chain_to_wp_user() {
795 795
 		return $this->_model_chain_to_wp_user;
796 796
 	}
797 797
 
@@ -803,13 +803,13 @@  discard block
 block discarded – undo
803 803
 	 * @return boolean
804 804
 	 */
805 805
 	public function is_owned() {
806
-		if( $this->model_chain_to_wp_user() ){
806
+		if ($this->model_chain_to_wp_user()) {
807 807
 			return true;
808
-		}else{
809
-			try{
810
-				$this->get_foreign_key_to( 'WP_User' );
808
+		} else {
809
+			try {
810
+				$this->get_foreign_key_to('WP_User');
811 811
 				return true;
812
-			}catch( EE_Error $e ){
812
+			} catch (EE_Error $e) {
813 813
 				return false;
814 814
 			}
815 815
 		}
@@ -828,21 +828,21 @@  discard block
 block discarded – undo
828 828
 	 * and 1 is the data type. Eg, array('count'=>array('COUNT(REG_ID)','%d'))
829 829
 	 * @return array | stdClass[] like results of $wpdb->get_results($sql,OBJECT), (ie, output type is OBJECT)
830 830
 	 */
831
-	protected function  _get_all_wpdb_results($query_params = array(), $output = ARRAY_A, $columns_to_select = null){
831
+	protected function  _get_all_wpdb_results($query_params = array(), $output = ARRAY_A, $columns_to_select = null) {
832 832
 		//remember the custom selections, if any
833
-		if(is_array($columns_to_select)){
833
+		if (is_array($columns_to_select)) {
834 834
 			$this->_custom_selections = $columns_to_select;
835
-		}elseif(is_string($columns_to_select)){
835
+		}elseif (is_string($columns_to_select)) {
836 836
 			$this->_custom_selections = array($this->_custom_selections);
837
-		}else{
837
+		} else {
838 838
 			$this->_custom_selections = array();
839 839
 		}
840 840
 
841 841
 		$model_query_info = $this->_create_model_query_info_carrier($query_params);
842 842
 		$select_expressions = $columns_to_select ? $this->_construct_select_from_input($columns_to_select) : $this->_construct_default_select_sql($model_query_info);
843
-		$SQL ="SELECT $select_expressions ".$this->_construct_2nd_half_of_select_query($model_query_info);
843
+		$SQL = "SELECT $select_expressions ".$this->_construct_2nd_half_of_select_query($model_query_info);
844 844
 //		echo "sql:$SQL";
845
-		$results =  $this->_do_wpdb_query( 'get_results', array($SQL, $output ) );// $wpdb->get_results($SQL, $output);
845
+		$results = $this->_do_wpdb_query('get_results', array($SQL, $output)); // $wpdb->get_results($SQL, $output);
846 846
 		return $results;
847 847
 	}
848 848
 
@@ -860,7 +860,7 @@  discard block
 block discarded – undo
860 860
 	 * and 1 is the data type. Eg, array('count'=>array('COUNT(REG_ID)','%d'))
861 861
 	 * @return array|stdClass[] like results of $wpdb->get_results($sql,OBJECT), (ie, output type is OBJECT)
862 862
 	 */
863
-	public function  get_all_wpdb_results($query_params = array(), $output = ARRAY_A, $columns_to_select = null){
863
+	public function  get_all_wpdb_results($query_params = array(), $output = ARRAY_A, $columns_to_select = null) {
864 864
 		return $this->_get_all_wpdb_results($query_params, $output, $columns_to_select);
865 865
 	}
866 866
 
@@ -872,12 +872,12 @@  discard block
 block discarded – undo
872 872
 	 * @throws EE_Error
873 873
 	 * @return string
874 874
 	 */
875
-	private function _construct_select_from_input($columns_to_select){
876
-		if(is_array($columns_to_select)){
875
+	private function _construct_select_from_input($columns_to_select) {
876
+		if (is_array($columns_to_select)) {
877 877
 			$select_sql_array = array();
878 878
 
879
-			foreach($columns_to_select as $alias => $selection_and_datatype){
880
-				if( ! is_array($selection_and_datatype) || ! isset($selection_and_datatype[1])){
879
+			foreach ($columns_to_select as $alias => $selection_and_datatype) {
880
+				if ( ! is_array($selection_and_datatype) || ! isset($selection_and_datatype[1])) {
881 881
 					throw new EE_Error(
882 882
 						sprintf(
883 883
 							__(
@@ -889,24 +889,24 @@  discard block
 block discarded – undo
889 889
 						)
890 890
 					);
891 891
 				}
892
-				if( ! in_array( $selection_and_datatype[1],$this->_valid_wpdb_data_types)){
892
+				if ( ! in_array($selection_and_datatype[1], $this->_valid_wpdb_data_types)) {
893 893
 					throw new EE_Error(
894 894
 						sprintf(
895 895
 							__(
896 896
 								"Datatype %s (for selection '%s' and alias '%s') is not a valid wpdb datatype (eg %%s)",
897 897
 								"event_espresso"
898 898
 							),
899
-							$selection_and_datatype[ 1 ],
900
-							$selection_and_datatype[ 0 ],
899
+							$selection_and_datatype[1],
900
+							$selection_and_datatype[0],
901 901
 							$alias,
902
-							implode( ",", $this->_valid_wpdb_data_types )
902
+							implode(",", $this->_valid_wpdb_data_types)
903 903
 						)
904 904
 					);
905 905
 				}
906 906
 				$select_sql_array[] = "{$selection_and_datatype[0]} AS $alias";
907 907
 			}
908
-			$columns_to_select_string = implode(", ",$select_sql_array);
909
-		}else{
908
+			$columns_to_select_string = implode(", ", $select_sql_array);
909
+		} else {
910 910
 			$columns_to_select_string = $columns_to_select;
911 911
 		}
912 912
 		return $columns_to_select_string;
@@ -919,7 +919,7 @@  discard block
 block discarded – undo
919 919
 	 * Convenient wrapper for getting the primary key field's name. Eg, on Registration, this would be 'REG_ID'
920 920
 	 * @return string
921 921
 	 */
922
-	function primary_key_name(){
922
+	function primary_key_name() {
923 923
 		return $this->get_primary_key_field()->get_name();
924 924
 	}
925 925
 
@@ -931,14 +931,14 @@  discard block
 block discarded – undo
931 931
 	 * @param mixed $id int or string, depending on the type of the model's primary key
932 932
 	 * @return EE_Base_Class
933 933
 	 */
934
-	function get_one_by_ID($id){
935
-		if( $this->get_from_entity_map( $id ) ){
936
-			return $this->get_from_entity_map( $id );
934
+	function get_one_by_ID($id) {
935
+		if ($this->get_from_entity_map($id)) {
936
+			return $this->get_from_entity_map($id);
937 937
 		}
938 938
 		return $this->get_one( 
939 939
 			$this->alter_query_params_to_restrict_by_ID( 
940 940
 				$id,
941
-				array( 'default_where_conditions' => 'minimum' )
941
+				array('default_where_conditions' => 'minimum')
942 942
 			) 
943 943
 		);
944 944
 	}
@@ -950,15 +950,15 @@  discard block
 block discarded – undo
950 950
 	 * @param array $query_params
951 951
 	 * @return array of normal query params, @see EEM_Base::get_all
952 952
 	 */
953
-	public function alter_query_params_to_restrict_by_ID( $id, $query_params = array() ) {
954
-		if( ! isset( $query_params[ 0 ] ) ) {
955
-			$query_params[ 0 ] = array();
953
+	public function alter_query_params_to_restrict_by_ID($id, $query_params = array()) {
954
+		if ( ! isset($query_params[0])) {
955
+			$query_params[0] = array();
956 956
 		}
957
-		if( $this->has_primary_key_field ( ) ) {
958
-			$query_params[ 0 ][ $this->primary_key_name() ] = $id ;
959
-		}else{
957
+		if ($this->has_primary_key_field( )) {
958
+			$query_params[0][$this->primary_key_name()] = $id;
959
+		} else {
960 960
 			//no primary key, so the $id must be from the get_index_primary_key_string()
961
-			$query_params[0] = array_replace_recursive( $query_params[ 0 ], $this->parse_index_primary_key_string( $id ) );
961
+			$query_params[0] = array_replace_recursive($query_params[0], $this->parse_index_primary_key_string($id));
962 962
 		}
963 963
 		return $query_params;
964 964
 	}
@@ -970,16 +970,16 @@  discard block
 block discarded – undo
970 970
 	 * @param array $query_params like EEM_Base's $query_params variable.
971 971
 	 * @return EE_Base_Class | NULL
972 972
 	 */
973
-	function get_one($query_params = array()){
974
-		if( ! is_array( $query_params ) ){
975
-			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' );
973
+	function get_one($query_params = array()) {
974
+		if ( ! is_array($query_params)) {
975
+			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');
976 976
 			$query_params = array();
977 977
 		}
978 978
 		$query_params['limit'] = 1;
979 979
 		$items = $this->get_all($query_params);
980
-		if(empty($items)){
980
+		if (empty($items)) {
981 981
 			return null;
982
-		}else{
982
+		} else {
983 983
 			return array_shift($items);
984 984
 		}
985 985
 	}
@@ -1003,8 +1003,8 @@  discard block
 block discarded – undo
1003 1003
 	 *
1004 1004
 	 * @return EE_Base_Class[]|array
1005 1005
 	 */
1006
-	public function next_x( $current_field_value, $field_to_order_by = null, $limit = 1, $query_params = array(), $columns_to_select = null ) {
1007
-		return $this->_get_consecutive( $current_field_value, '>', $field_to_order_by, $limit, $query_params, $columns_to_select );
1006
+	public function next_x($current_field_value, $field_to_order_by = null, $limit = 1, $query_params = array(), $columns_to_select = null) {
1007
+		return $this->_get_consecutive($current_field_value, '>', $field_to_order_by, $limit, $query_params, $columns_to_select);
1008 1008
 	}
1009 1009
 
1010 1010
 
@@ -1027,8 +1027,8 @@  discard block
 block discarded – undo
1027 1027
 	 *
1028 1028
 	 * @return EE_Base_Class[]|array
1029 1029
 	 */
1030
-	public function previous_x( $current_field_value, $field_to_order_by = null, $limit = 1, $query_params = array(), $columns_to_select = null ) {
1031
-		return $this->_get_consecutive( $current_field_value, '<', $field_to_order_by, $limit, $query_params, $columns_to_select );
1030
+	public function previous_x($current_field_value, $field_to_order_by = null, $limit = 1, $query_params = array(), $columns_to_select = null) {
1031
+		return $this->_get_consecutive($current_field_value, '<', $field_to_order_by, $limit, $query_params, $columns_to_select);
1032 1032
 	}
1033 1033
 
1034 1034
 
@@ -1050,9 +1050,9 @@  discard block
 block discarded – undo
1050 1050
 	 *
1051 1051
 	 * @return EE_Base_Class|null|array()
1052 1052
 	 */
1053
-	public function next( $current_field_value, $field_to_order_by = null, $query_params = array(), $columns_to_select = null ) {
1054
-		$results = $this->_get_consecutive( $current_field_value, '>', $field_to_order_by, 1, $query_params, $columns_to_select );
1055
-		return empty( $results ) ? null : reset( $results );
1053
+	public function next($current_field_value, $field_to_order_by = null, $query_params = array(), $columns_to_select = null) {
1054
+		$results = $this->_get_consecutive($current_field_value, '>', $field_to_order_by, 1, $query_params, $columns_to_select);
1055
+		return empty($results) ? null : reset($results);
1056 1056
 	}
1057 1057
 
1058 1058
 
@@ -1074,9 +1074,9 @@  discard block
 block discarded – undo
1074 1074
 	 *
1075 1075
 	 * @return EE_Base_Class|null|array()
1076 1076
 	 */
1077
-	public function previous( $current_field_value, $field_to_order_by = null, $query_params = array(), $columns_to_select = null ) {
1078
-		$results = $this->_get_consecutive( $current_field_value, '<', $field_to_order_by, 1, $query_params, $columns_to_select );
1079
-		return empty( $results ) ? null : reset( $results );
1077
+	public function previous($current_field_value, $field_to_order_by = null, $query_params = array(), $columns_to_select = null) {
1078
+		$results = $this->_get_consecutive($current_field_value, '<', $field_to_order_by, 1, $query_params, $columns_to_select);
1079
+		return empty($results) ? null : reset($results);
1080 1080
 	}
1081 1081
 
1082 1082
 
@@ -1102,40 +1102,40 @@  discard block
 block discarded – undo
1102 1102
 	 * @return EE_Base_Class[]|array
1103 1103
 	 * @throws EE_Error
1104 1104
 	 */
1105
-	protected function _get_consecutive( $current_field_value, $operand = '>', $field_to_order_by = null, $limit = 1, $query_params = array(), $columns_to_select = null ) {
1105
+	protected function _get_consecutive($current_field_value, $operand = '>', $field_to_order_by = null, $limit = 1, $query_params = array(), $columns_to_select = null) {
1106 1106
 		//if $field_to_order_by is empty then let's assume we're ordering by the primary key.
1107
-		if ( empty( $field_to_order_by ) ) {
1108
-			if ( $this->has_primary_key_field() ) {
1107
+		if (empty($field_to_order_by)) {
1108
+			if ($this->has_primary_key_field()) {
1109 1109
 				$field_to_order_by = $this->get_primary_key_field()->get_name();
1110 1110
 			} else {
1111 1111
 
1112
-				if ( WP_DEBUG ) {
1113
-					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' ) );
1112
+				if (WP_DEBUG) {
1113
+					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'));
1114 1114
 				}
1115
-				EE_Error::add_error( __('There was an error with the query.', 'event_espresso') );
1115
+				EE_Error::add_error(__('There was an error with the query.', 'event_espresso'));
1116 1116
 				return array();
1117 1117
 			}
1118 1118
 		}
1119 1119
 
1120
-		if( ! is_array( $query_params ) ){
1121
-			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' );
1120
+		if ( ! is_array($query_params)) {
1121
+			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');
1122 1122
 			$query_params = array();
1123 1123
 		}
1124 1124
 
1125 1125
 		//let's add the where query param for consecutive look up.
1126
-		$query_params[0][ $field_to_order_by ] = array( $operand, $current_field_value );
1126
+		$query_params[0][$field_to_order_by] = array($operand, $current_field_value);
1127 1127
 		$query_params['limit'] = $limit;
1128 1128
 
1129 1129
 		//set direction
1130
-		$incoming_orderby = isset( $query_params['order_by'] ) ? $query_params['order_by'] : array();
1131
-		$query_params['order_by'] = $operand == '>' ? array( $field_to_order_by => 'ASC' ) + $incoming_orderby : array( $field_to_order_by => 'DESC') + $incoming_orderby;
1130
+		$incoming_orderby = isset($query_params['order_by']) ? $query_params['order_by'] : array();
1131
+		$query_params['order_by'] = $operand == '>' ? array($field_to_order_by => 'ASC') + $incoming_orderby : array($field_to_order_by => 'DESC') + $incoming_orderby;
1132 1132
 
1133 1133
 		//if $columns_to_select is empty then that means we're returning EE_Base_Class objects
1134
-		if ( empty( $columns_to_select ) ) {
1135
-			return $this->get_all( $query_params );
1134
+		if (empty($columns_to_select)) {
1135
+			return $this->get_all($query_params);
1136 1136
 		} else {
1137 1137
 			//getting just the fields
1138
-			return $this->_get_all_wpdb_results( $query_params, ARRAY_A, $columns_to_select );
1138
+			return $this->_get_all_wpdb_results($query_params, ARRAY_A, $columns_to_select);
1139 1139
 		}
1140 1140
 	}
1141 1141
 
@@ -1146,18 +1146,18 @@  discard block
 block discarded – undo
1146 1146
 	 * This sets the _timezone property after model object has been instantiated.
1147 1147
 	 * @param null | string $timezone valid PHP DateTimeZone timezone string
1148 1148
 	 */
1149
-	public function set_timezone( $timezone ) {
1150
-		if ( $timezone !== null ) {
1149
+	public function set_timezone($timezone) {
1150
+		if ($timezone !== null) {
1151 1151
 			$this->_timezone = $timezone;
1152 1152
 		}
1153 1153
 		//note we need to loop through relations and set the timezone on those objects as well.
1154
-		foreach ( $this->_model_relations as $relation ) {
1155
-			$relation->set_timezone( $timezone );
1154
+		foreach ($this->_model_relations as $relation) {
1155
+			$relation->set_timezone($timezone);
1156 1156
 		}
1157 1157
 		//and finally we do the same for any datetime fields
1158
-		foreach ( $this->_fields as $field ) {
1159
-			if ( $field instanceof EE_Datetime_Field ) {
1160
-				$field->set_timezone( $timezone );
1158
+		foreach ($this->_fields as $field) {
1159
+			if ($field instanceof EE_Datetime_Field) {
1160
+				$field->set_timezone($timezone);
1161 1161
 			}
1162 1162
 		}
1163 1163
 	}
@@ -1172,9 +1172,9 @@  discard block
 block discarded – undo
1172 1172
 	 */
1173 1173
 	public function get_timezone() {
1174 1174
 		//first validate if timezone is set.  If not, then let's set it be whatever is set on the model fields.
1175
-		if ( empty( $this->_timezone ) ) {
1176
-			foreach( $this->_fields as $field ) {
1177
-				if ( $field instanceof EE_Datetime_Field ) {
1175
+		if (empty($this->_timezone)) {
1176
+			foreach ($this->_fields as $field) {
1177
+				if ($field instanceof EE_Datetime_Field) {
1178 1178
 					$this->set_timezone($field->get_timezone());
1179 1179
 					break;
1180 1180
 				}
@@ -1182,9 +1182,9 @@  discard block
 block discarded – undo
1182 1182
 		}
1183 1183
 
1184 1184
 		//if timezone STILL empty then return the default timezone for the site.
1185
-		if ( empty( $this->_timezone ) ) {
1186
-			EE_Registry::instance()->load_helper( 'DTT_Helper' );
1187
-			$this->set_timezone( EEH_DTT_Helper::get_timezone() );
1185
+		if (empty($this->_timezone)) {
1186
+			EE_Registry::instance()->load_helper('DTT_Helper');
1187
+			$this->set_timezone(EEH_DTT_Helper::get_timezone());
1188 1188
 		}
1189 1189
 		return $this->_timezone;
1190 1190
 	}
@@ -1202,19 +1202,19 @@  discard block
 block discarded – undo
1202 1202
 	 *
1203 1203
 	 * @return array formats in an array with the date format first, and the time format last.
1204 1204
 	 */
1205
-	public function get_formats_for( $field_name, $pretty = false ) {
1206
-		$field_settings = $this->field_settings_for( $field_name );
1205
+	public function get_formats_for($field_name, $pretty = false) {
1206
+		$field_settings = $this->field_settings_for($field_name);
1207 1207
 
1208 1208
 		//if not a valid EE_Datetime_Field then throw error
1209
-		if ( ! $field_settings instanceof EE_Datetime_Field ) {
1210
-			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 ) );
1209
+		if ( ! $field_settings instanceof EE_Datetime_Field) {
1210
+			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));
1211 1211
 		}
1212 1212
 
1213 1213
 		//while we are here, let's make sure the timezone internally in EEM_Base matches what is stored on
1214 1214
 		//the field.
1215 1215
 		$this->_timezone = $field_settings->get_timezone();
1216 1216
 
1217
-		return array( $field_settings->get_date_format( $pretty ), $field_settings->get_time_format( $pretty ) );
1217
+		return array($field_settings->get_date_format($pretty), $field_settings->get_time_format($pretty));
1218 1218
 	}
1219 1219
 
1220 1220
 
@@ -1238,25 +1238,25 @@  discard block
 block discarded – undo
1238 1238
 	 * @return int|string  If the given field_name is not of the EE_Datetime_Field type, then an EE_Error
1239 1239
 	 *                    	     exception is triggered.
1240 1240
 	 */
1241
-	public function current_time_for_query( $field_name, $timestamp = false, $what = 'both' ) {
1242
-		$formats = $this->get_formats_for( $field_name );
1241
+	public function current_time_for_query($field_name, $timestamp = false, $what = 'both') {
1242
+		$formats = $this->get_formats_for($field_name);
1243 1243
 
1244
-		$DateTime = new DateTime( "now", new DateTimeZone( $this->_timezone ) );
1244
+		$DateTime = new DateTime("now", new DateTimeZone($this->_timezone));
1245 1245
 
1246
-		if ( $timestamp ) {
1247
-			return $DateTime->format( 'U' );
1246
+		if ($timestamp) {
1247
+			return $DateTime->format('U');
1248 1248
 		}
1249 1249
 
1250 1250
 		//not returning timestamp, so return formatted string in timezone.
1251
-		switch( $what ) {
1251
+		switch ($what) {
1252 1252
 			case 'time' :
1253
-				return $DateTime->format( $formats[1] );
1253
+				return $DateTime->format($formats[1]);
1254 1254
 				break;
1255 1255
 			case 'date' :
1256
-				return $DateTime->format( $formats[0] );
1256
+				return $DateTime->format($formats[0]);
1257 1257
 				break;
1258 1258
 			default :
1259
-				return $DateTime->format( implode( ' ', $formats ) );
1259
+				return $DateTime->format(implode(' ', $formats));
1260 1260
 				break;
1261 1261
 		}
1262 1262
 	}
@@ -1280,18 +1280,18 @@  discard block
 block discarded – undo
1280 1280
 	 *                           		'U', this is ignored.
1281 1281
 	 * @return DateTime
1282 1282
 	 */
1283
-	public function convert_datetime_for_query( $field_name, $timestring, $incoming_format, $timezone = '' ) {
1283
+	public function convert_datetime_for_query($field_name, $timestring, $incoming_format, $timezone = '') {
1284 1284
 
1285 1285
 		//just using this to ensure the timezone is set correctly internally
1286
-		$this->get_formats_for( $field_name );
1286
+		$this->get_formats_for($field_name);
1287 1287
 
1288 1288
 		//load EEH_DTT_Helper
1289
-		EE_Registry::instance()->load_helper( 'DTT_Helper' );
1290
-		$set_timezone = empty( $timezone ) ? EEH_DTT_Helper::get_timezone() : $timezone;
1289
+		EE_Registry::instance()->load_helper('DTT_Helper');
1290
+		$set_timezone = empty($timezone) ? EEH_DTT_Helper::get_timezone() : $timezone;
1291 1291
 
1292
-		$incomingDateTime = date_create_from_format( $incoming_format, $timestring, new DateTimeZone( $set_timezone ) );
1292
+		$incomingDateTime = date_create_from_format($incoming_format, $timestring, new DateTimeZone($set_timezone));
1293 1293
 
1294
-		return $incomingDateTime->setTimeZone( new DateTimeZone( $this->_timezone ) );
1294
+		return $incomingDateTime->setTimeZone(new DateTimeZone($this->_timezone));
1295 1295
 	}
1296 1296
 
1297 1297
 
@@ -1301,7 +1301,7 @@  discard block
 block discarded – undo
1301 1301
 	 * Gets all the tables comprising this model. Array keys are the table aliases, and values are EE_Table objects
1302 1302
 	 * @return EE_Table_Base[]
1303 1303
 	 */
1304
-	function get_tables(){
1304
+	function get_tables() {
1305 1305
 		return $this->_tables;
1306 1306
 	}
1307 1307
 
@@ -1335,9 +1335,9 @@  discard block
 block discarded – undo
1335 1335
 	 * be aware that model objects being used could get out-of-sync with the database
1336 1336
 	 * @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)
1337 1337
 	 */
1338
-	function update($fields_n_values, $query_params, $keep_model_objs_in_sync = TRUE){
1339
-		if( ! is_array( $query_params ) ){
1340
-			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' );
1338
+	function update($fields_n_values, $query_params, $keep_model_objs_in_sync = TRUE) {
1339
+		if ( ! is_array($query_params)) {
1340
+			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');
1341 1341
 			$query_params = array();
1342 1342
 		}
1343 1343
 		/**
@@ -1347,7 +1347,7 @@  discard block
 block discarded – undo
1347 1347
 		 * @param array $fields_n_values the updated fields and their new values
1348 1348
 		 * @param array $query_params @see EEM_Base::get_all()
1349 1349
 		 */
1350
-		do_action( 'AHEE__EEM_Base__update__begin',$this, $fields_n_values, $query_params );
1350
+		do_action('AHEE__EEM_Base__update__begin', $this, $fields_n_values, $query_params);
1351 1351
 		/**
1352 1352
 		 * Filters the fields about to be updated given the query parameters. You can provide the
1353 1353
 		 * $query_params to $this->get_all() to find exactly which records will be updated
@@ -1355,10 +1355,10 @@  discard block
 block discarded – undo
1355 1355
 		 * @param EEM_Base $model the model being queried
1356 1356
 		 * @param array $query_params see EEM_Base::get_all()
1357 1357
 		 */
1358
-		$fields_n_values = apply_filters( 'FHEE__EEM_Base__update__fields_n_values', $fields_n_values, $this, $query_params );
1358
+		$fields_n_values = apply_filters('FHEE__EEM_Base__update__fields_n_values', $fields_n_values, $this, $query_params);
1359 1359
 		//need to verify that, for any entry we want to update, there are entries in each secondary table.
1360 1360
 		//to do that, for each table, verify that it's PK isn't null.
1361
-		$tables= $this->get_tables();
1361
+		$tables = $this->get_tables();
1362 1362
 
1363 1363
 		//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
1364 1364
 		//NOTE: we should make this code more efficient by NOT querying twice
@@ -1368,29 +1368,29 @@  discard block
 block discarded – undo
1368 1368
 			//we want to make sure the default_where strategy is ignored
1369 1369
 			$this->_ignore_where_strategy = TRUE;
1370 1370
 			$wpdb_select_results = $this->_get_all_wpdb_results($query_params);
1371
-			foreach( $wpdb_select_results as $wpdb_result ){
1371
+			foreach ($wpdb_select_results as $wpdb_result) {
1372 1372
 				// type cast stdClass as array
1373
-				$wpdb_result = (array)$wpdb_result;
1373
+				$wpdb_result = (array) $wpdb_result;
1374 1374
 				//get the model object's PK, as we'll want this if we need to insert a row into secondary tables
1375
-				if( $this->has_primary_key_field() ){
1376
-					$main_table_pk_value = $wpdb_result[ $this->get_primary_key_field()->get_qualified_column() ];
1377
-				}else{
1375
+				if ($this->has_primary_key_field()) {
1376
+					$main_table_pk_value = $wpdb_result[$this->get_primary_key_field()->get_qualified_column()];
1377
+				} else {
1378 1378
 					//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 1379
 					$main_table_pk_value = null;
1380 1380
 				}
1381 1381
 				//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
1382 1382
 				//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
1383
-				if(count($tables) > 1){
1383
+				if (count($tables) > 1) {
1384 1384
 					//foreach matching row in the DB, ensure that each table's PK isn't null. If so, there must not be an entry
1385 1385
 					//in that table, and so we'll want to insert one
1386
-					foreach($tables as $table_obj){
1386
+					foreach ($tables as $table_obj) {
1387 1387
 						$this_table_pk_column = $table_obj->get_fully_qualified_pk_column();
1388 1388
 						//if there is no private key for this table on the results, it means there's no entry
1389 1389
 						//in this table, right? so insert a row in the current table, using any fields available
1390
-						if( ! ( array_key_exists( $this_table_pk_column, $wpdb_result) && $wpdb_result[ $this_table_pk_column ] )){
1390
+						if ( ! (array_key_exists($this_table_pk_column, $wpdb_result) && $wpdb_result[$this_table_pk_column])) {
1391 1391
 							$success = $this->_insert_into_specific_table($table_obj, $fields_n_values, $main_table_pk_value);
1392 1392
 							//if we died here, report the error
1393
-							if( ! $success ) {
1393
+							if ( ! $success) {
1394 1394
 								return false;
1395 1395
 							}
1396 1396
 						}
@@ -1410,44 +1410,44 @@  discard block
 block discarded – undo
1410 1410
 		//if this wasn't called from a model object (to update itself)
1411 1411
 		//then we want to make sure we keep all the existing
1412 1412
 		//model objects in sync with the db
1413
-		if( $keep_model_objs_in_sync && ! $this->_values_already_prepared_by_model_object ){
1414
-			if( $this->has_primary_key_field() ){
1415
-				$model_objs_affected_ids = $this->get_col( $query_params );
1416
-			}else{
1413
+		if ($keep_model_objs_in_sync && ! $this->_values_already_prepared_by_model_object) {
1414
+			if ($this->has_primary_key_field()) {
1415
+				$model_objs_affected_ids = $this->get_col($query_params);
1416
+			} else {
1417 1417
 				//we need to select a bunch of columns and then combine them into the the "index primary key string"s
1418
-				$models_affected_key_columns = $this->_get_all_wpdb_results($query_params, ARRAY_A );
1418
+				$models_affected_key_columns = $this->_get_all_wpdb_results($query_params, ARRAY_A);
1419 1419
 				$model_objs_affected_ids = array();
1420
-				foreach( $models_affected_key_columns as $row ){
1421
-					$combined_index_key = $this->get_index_primary_key_string( $row );
1422
-					$model_objs_affected_ids[ $combined_index_key ] = $combined_index_key;
1420
+				foreach ($models_affected_key_columns as $row) {
1421
+					$combined_index_key = $this->get_index_primary_key_string($row);
1422
+					$model_objs_affected_ids[$combined_index_key] = $combined_index_key;
1423 1423
 				}
1424 1424
 
1425 1425
 			}
1426 1426
 
1427
-			if( ! $model_objs_affected_ids ){
1427
+			if ( ! $model_objs_affected_ids) {
1428 1428
 				//wait wait wait- if nothing was affected let's stop here
1429 1429
 				return 0;
1430 1430
 			}
1431
-			foreach( $model_objs_affected_ids as $id ){
1432
-				$model_obj_in_entity_map = $this->get_from_entity_map( $id );
1433
-				if( $model_obj_in_entity_map ){
1434
-					foreach( $fields_n_values as $field => $new_value ){
1435
-						$model_obj_in_entity_map->set( $field, $new_value );
1431
+			foreach ($model_objs_affected_ids as $id) {
1432
+				$model_obj_in_entity_map = $this->get_from_entity_map($id);
1433
+				if ($model_obj_in_entity_map) {
1434
+					foreach ($fields_n_values as $field => $new_value) {
1435
+						$model_obj_in_entity_map->set($field, $new_value);
1436 1436
 					}
1437 1437
 				}
1438 1438
 			}
1439 1439
 			//if there is a primary key on this model, we can now do a slight optimization
1440
-			if( $this->has_primary_key_field() ){
1440
+			if ($this->has_primary_key_field()) {
1441 1441
 				//we already know what we want to update. So let's make the query simpler so it's a little more efficient
1442 1442
 				$query_params = array(
1443
-					array( $this->primary_key_name() => array( 'IN', $model_objs_affected_ids ) ),
1444
-					'limit' => count( $model_objs_affected_ids ), 'default_where_conditions' => 'none' );
1443
+					array($this->primary_key_name() => array('IN', $model_objs_affected_ids)),
1444
+					'limit' => count($model_objs_affected_ids), 'default_where_conditions' => 'none' );
1445 1445
 			}
1446 1446
 		}
1447 1447
 
1448
-		$model_query_info = $this->_create_model_query_info_carrier( $query_params );
1449
-		$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.
1450
-		$rows_affected = $this->_do_wpdb_query('query', array( $SQL ) );
1448
+		$model_query_info = $this->_create_model_query_info_carrier($query_params);
1449
+		$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.
1450
+		$rows_affected = $this->_do_wpdb_query('query', array($SQL));
1451 1451
 		/**
1452 1452
 		 * Action called after a model update call has been made.
1453 1453
 		 *
@@ -1456,8 +1456,8 @@  discard block
 block discarded – undo
1456 1456
 		 * @param array $query_params @see EEM_Base::get_all()
1457 1457
 		 * @param int $rows_affected
1458 1458
 		 */
1459
-		do_action( 'AHEE__EEM_Base__update__end',$this, $fields_n_values, $query_params, $rows_affected );
1460
-		return $rows_affected;//how many supposedly got updated
1459
+		do_action('AHEE__EEM_Base__update__end', $this, $fields_n_values, $query_params, $rows_affected);
1460
+		return $rows_affected; //how many supposedly got updated
1461 1461
 	}
1462 1462
 
1463 1463
 	/**
@@ -1469,22 +1469,22 @@  discard block
 block discarded – undo
1469 1469
 	 * @param string $field_to_select
1470 1470
 	 * @return array just like $wpdb->get_col()
1471 1471
 	 */
1472
-	public function get_col( $query_params  = array(), $field_to_select = NULL ){
1472
+	public function get_col($query_params = array(), $field_to_select = NULL) {
1473 1473
 
1474
-		if( $field_to_select ){
1475
-			$field = $this->field_settings_for( $field_to_select );
1476
-		}elseif( $this->has_primary_key_field ( ) ){
1474
+		if ($field_to_select) {
1475
+			$field = $this->field_settings_for($field_to_select);
1476
+		}elseif ($this->has_primary_key_field( )) {
1477 1477
 			$field = $this->get_primary_key_field();
1478
-		}else{
1478
+		} else {
1479 1479
 			//no primary key, just grab the first column
1480
-			$field = reset( $this->field_settings());
1480
+			$field = reset($this->field_settings());
1481 1481
 		}
1482 1482
 
1483 1483
 
1484 1484
 		$model_query_info = $this->_create_model_query_info_carrier($query_params);
1485 1485
 		$select_expressions = $field->get_qualified_column();
1486
-		$SQL ="SELECT $select_expressions ".$this->_construct_2nd_half_of_select_query($model_query_info);
1487
-		$results =  $this->_do_wpdb_query('get_col', array( $SQL ) );
1486
+		$SQL = "SELECT $select_expressions ".$this->_construct_2nd_half_of_select_query($model_query_info);
1487
+		$results = $this->_do_wpdb_query('get_col', array($SQL));
1488 1488
 		return $results;
1489 1489
 	}
1490 1490
 
@@ -1494,12 +1494,12 @@  discard block
 block discarded – undo
1494 1494
 	 * @param string $field_to_select @see EEM_Base::get_col()
1495 1495
 	 * @return string
1496 1496
 	 */
1497
-	public function get_var( $query_params = array(), $field_to_select = NULL ) {
1498
-		$query_params[ 'limit' ] = 1;
1499
-		$col = $this->get_col( $query_params, $field_to_select );
1500
-		if( ! empty( $col ) ) {
1501
-			return reset( $col );
1502
-		}else{
1497
+	public function get_var($query_params = array(), $field_to_select = NULL) {
1498
+		$query_params['limit'] = 1;
1499
+		$col = $this->get_col($query_params, $field_to_select);
1500
+		if ( ! empty($col)) {
1501
+			return reset($col);
1502
+		} else {
1503 1503
 			return NULL;
1504 1504
 		}
1505 1505
 	}
@@ -1513,19 +1513,19 @@  discard block
 block discarded – undo
1513 1513
 	 * @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
1514 1514
 	 * @return string of SQL
1515 1515
 	 */
1516
-	function _construct_update_sql($fields_n_values){
1516
+	function _construct_update_sql($fields_n_values) {
1517 1517
 		/** @type WPDB $wpdb */
1518 1518
 		global $wpdb;
1519 1519
 		$cols_n_values = array();
1520
-		foreach($fields_n_values as $field_name => $value){
1520
+		foreach ($fields_n_values as $field_name => $value) {
1521 1521
 			$field_obj = $this->field_settings_for($field_name);
1522 1522
 			//if the value is NULL, we want to assign the value to that.
1523 1523
 			//wpdb->prepare doesn't really handle that properly
1524
-			$prepared_value = $this->_prepare_value_or_use_default( $field_obj, $fields_n_values );
1525
-			$value_sql = $prepared_value===NULL ? 'NULL' : $wpdb->prepare( $field_obj->get_wpdb_data_type(), $prepared_value );
1524
+			$prepared_value = $this->_prepare_value_or_use_default($field_obj, $fields_n_values);
1525
+			$value_sql = $prepared_value === NULL ? 'NULL' : $wpdb->prepare($field_obj->get_wpdb_data_type(), $prepared_value);
1526 1526
 			$cols_n_values[] = $field_obj->get_qualified_column()."=".$value_sql;
1527 1527
 		}
1528
-		return implode(",",$cols_n_values);
1528
+		return implode(",", $cols_n_values);
1529 1529
 
1530 1530
 	}
1531 1531
 	
@@ -1537,10 +1537,10 @@  discard block
 block discarded – undo
1537 1537
 	 * @param mixed $id
1538 1538
 	 * @return boolean whether the row got deleted or not
1539 1539
 	 */
1540
-	public function delete_permanently_by_ID( $id ) {
1540
+	public function delete_permanently_by_ID($id) {
1541 1541
 		return $this->delete_permanently( 
1542 1542
 			array(
1543
-				array( $this->get_primary_key_field()->get_name() => $id ),
1543
+				array($this->get_primary_key_field()->get_name() => $id),
1544 1544
 				'limit' 	=> 1
1545 1545
 			) 
1546 1546
 		);
@@ -1554,10 +1554,10 @@  discard block
 block discarded – undo
1554 1554
 	 * @param mixed $id
1555 1555
 	 * @return boolean whether the row got deleted or not
1556 1556
 	 */
1557
-	public function delete_by_ID( $id ){
1557
+	public function delete_by_ID($id) {
1558 1558
 		return $this->delete( 
1559 1559
 			array(
1560
-				array( $this->get_primary_key_field()->get_name() => $id ),
1560
+				array($this->get_primary_key_field()->get_name() => $id),
1561 1561
 				'limit' 	=> 1
1562 1562
 			) 
1563 1563
 		);
@@ -1571,7 +1571,7 @@  discard block
 block discarded – undo
1571 1571
 	 * @param boolean $allow_blocking
1572 1572
 	 * @return @see EEM_Base::delete_permanently
1573 1573
 	 */
1574
-	function delete($query_params,$allow_blocking = true){
1574
+	function delete($query_params, $allow_blocking = true) {
1575 1575
 		return $this->delete_permanently($query_params, $allow_blocking);
1576 1576
 	}
1577 1577
 
@@ -1587,7 +1587,7 @@  discard block
 block discarded – undo
1587 1587
 	 * which may depend on it. Its generally advisable to always leave this as TRUE, otherwise you could easily corrupt your DB
1588 1588
 	 * @return int how many rows got deleted
1589 1589
 	 */
1590
-	function delete_permanently($query_params,$allow_blocking = true){
1590
+	function delete_permanently($query_params, $allow_blocking = true) {
1591 1591
 		/**
1592 1592
 		 * Action called just before performing a real deletion query. You can use the
1593 1593
 		 * model and its $query_params to find exactly which items will be deleted
@@ -1596,34 +1596,34 @@  discard block
 block discarded – undo
1596 1596
 		 * @param boolean $allow_blocking whether or not to allow related model objects
1597 1597
 		 * to block (prevent) this deletion
1598 1598
 		 */
1599
-		do_action( 'AHEE__EEM_Base__delete__begin', $this, $query_params, $allow_blocking );
1599
+		do_action('AHEE__EEM_Base__delete__begin', $this, $query_params, $allow_blocking);
1600 1600
 		//some MySQL databases may be running safe mode, which may restrict
1601 1601
 		//deletion if there is no KEY column used in the WHERE statement of a deletion.
1602 1602
 		//to get around this, we first do a SELECT, get all the IDs, and then run another query
1603 1603
 		//to delete them
1604 1604
 		$items_for_deletion = $this->_get_all_wpdb_results($query_params);
1605
-		$deletion_where = $this->_setup_ids_for_delete( $items_for_deletion, $allow_blocking);
1606
-		if($deletion_where){
1605
+		$deletion_where = $this->_setup_ids_for_delete($items_for_deletion, $allow_blocking);
1606
+		if ($deletion_where) {
1607 1607
 			//echo "objects for deletion:";var_dump($objects_for_deletion);
1608 1608
 			$model_query_info = $this->_create_model_query_info_carrier($query_params);
1609 1609
 			$table_aliases = array();
1610
-			foreach(array_keys($this->_tables) as $table_alias){
1610
+			foreach (array_keys($this->_tables) as $table_alias) {
1611 1611
 				$table_aliases[] = $table_alias;
1612 1612
 			}
1613
-			$SQL = "DELETE ".implode(", ",$table_aliases)." FROM ".$model_query_info->get_full_join_sql()." WHERE ".$deletion_where;
1613
+			$SQL = "DELETE ".implode(", ", $table_aliases)." FROM ".$model_query_info->get_full_join_sql()." WHERE ".$deletion_where;
1614 1614
 
1615 1615
 			//		/echo "delete sql:$SQL";
1616
-			$rows_deleted = $this->_do_wpdb_query( 'query', array( $SQL ) );
1617
-		}else{
1616
+			$rows_deleted = $this->_do_wpdb_query('query', array($SQL));
1617
+		} else {
1618 1618
 			$rows_deleted = 0;
1619 1619
 		}
1620 1620
 
1621 1621
 		//and lastly make sure those items are removed from the entity map; if they could be put into it at all
1622
-		if( $this->has_primary_key_field() ){
1623
-			foreach($items_for_deletion as $item_for_deletion_row ){
1624
-				$pk_value = $item_for_deletion_row[ $this->get_primary_key_field()->get_qualified_column() ];
1625
-				if( isset( $this->_entity_map[ $pk_value ] ) ){
1626
-					unset( $this->_entity_map[ $pk_value ] );
1622
+		if ($this->has_primary_key_field()) {
1623
+			foreach ($items_for_deletion as $item_for_deletion_row) {
1624
+				$pk_value = $item_for_deletion_row[$this->get_primary_key_field()->get_qualified_column()];
1625
+				if (isset($this->_entity_map[$pk_value])) {
1626
+					unset($this->_entity_map[$pk_value]);
1627 1627
 				}
1628 1628
 			}
1629 1629
 		}
@@ -1635,8 +1635,8 @@  discard block
 block discarded – undo
1635 1635
 		 * @param array $query_params @see EEM_Base::get_all()
1636 1636
 		 * @param int $rows_deleted
1637 1637
 		 */
1638
-		do_action( 'AHEE__EEM_Base__delete__end', $this, $query_params, $rows_deleted );
1639
-		return $rows_deleted;//how many supposedly got deleted
1638
+		do_action('AHEE__EEM_Base__delete__end', $this, $query_params, $rows_deleted);
1639
+		return $rows_deleted; //how many supposedly got deleted
1640 1640
 	}
1641 1641
 
1642 1642
 
@@ -1652,28 +1652,28 @@  discard block
 block discarded – undo
1652 1652
 	 * blocking its deletion before removing the relation between A and B
1653 1653
 	 * @return boolean
1654 1654
 	 */
1655
-	public function delete_is_blocked_by_related_models($this_model_obj_or_id, $ignore_this_model_obj = null){
1655
+	public function delete_is_blocked_by_related_models($this_model_obj_or_id, $ignore_this_model_obj = null) {
1656 1656
 		//first, if $ignore_this_model_obj was supplied, get its model
1657
-		if($ignore_this_model_obj && $ignore_this_model_obj instanceof EE_Base_Class){
1657
+		if ($ignore_this_model_obj && $ignore_this_model_obj instanceof EE_Base_Class) {
1658 1658
 			$ignored_model = $ignore_this_model_obj->get_model();
1659
-		}else{
1659
+		} else {
1660 1660
 			$ignored_model = null;
1661 1661
 		}
1662 1662
 		//now check all the relations of $this_model_obj_or_id and see if there
1663 1663
 		//are any related model objects blocking it?
1664 1664
 		$is_blocked = false;
1665
-		foreach($this->_model_relations as $relation_name => $relation_obj){
1666
-			if( $relation_obj->block_delete_if_related_models_exist()){
1665
+		foreach ($this->_model_relations as $relation_name => $relation_obj) {
1666
+			if ($relation_obj->block_delete_if_related_models_exist()) {
1667 1667
 				//if $ignore_this_model_obj was supplied, then for the query
1668 1668
 				//on that model needs to be told to ignore $ignore_this_model_obj
1669
-				if($ignored_model && $relation_name == $ignored_model->get_this_model_name()){
1670
-					$related_model_objects = $relation_obj->get_all_related($this_model_obj_or_id,array(
1671
-					array($ignored_model->get_primary_key_field()->get_name() => array('!=',$ignore_this_model_obj->ID()))));
1672
-				}else{
1669
+				if ($ignored_model && $relation_name == $ignored_model->get_this_model_name()) {
1670
+					$related_model_objects = $relation_obj->get_all_related($this_model_obj_or_id, array(
1671
+					array($ignored_model->get_primary_key_field()->get_name() => array('!=', $ignore_this_model_obj->ID()))));
1672
+				} else {
1673 1673
 					$related_model_objects = $relation_obj->get_all_related($this_model_obj_or_id);
1674 1674
 				}
1675 1675
 
1676
-				if($related_model_objects){
1676
+				if ($related_model_objects) {
1677 1677
 					EE_Error::add_error($relation_obj->get_deletion_error_message(), __FILE__, __FUNCTION__, __LINE__);
1678 1678
 					$is_blocked = true;
1679 1679
 				}
@@ -1693,65 +1693,65 @@  discard block
 block discarded – undo
1693 1693
 	 * @throws EE_Error
1694 1694
 	 * @return string    everything that comes after the WHERE statement.
1695 1695
 	 */
1696
-	protected function _setup_ids_for_delete( $objects_for_deletion, $allow_blocking = true) {
1697
-		if($this->has_primary_key_field()){
1696
+	protected function _setup_ids_for_delete($objects_for_deletion, $allow_blocking = true) {
1697
+		if ($this->has_primary_key_field()) {
1698 1698
 			$primary_table = $this->_get_main_table();
1699 1699
 			$other_tables = $this->_get_other_tables();
1700 1700
 			$deletes = $query = array();
1701
-			foreach ( $objects_for_deletion as $delete_object ) {
1701
+			foreach ($objects_for_deletion as $delete_object) {
1702 1702
 				//before we mark this object for deletion,
1703 1703
 				//make sure there's no related objects blocking its deletion (if we're checking)
1704
-				if( $allow_blocking && $this->delete_is_blocked_by_related_models($delete_object[$primary_table->get_fully_qualified_pk_column()]) ){
1704
+				if ($allow_blocking && $this->delete_is_blocked_by_related_models($delete_object[$primary_table->get_fully_qualified_pk_column()])) {
1705 1705
 					continue;
1706 1706
 				}
1707 1707
 
1708 1708
 				//primary table deletes
1709
-				if ( isset( $delete_object[$primary_table->get_fully_qualified_pk_column()] ) )
1709
+				if (isset($delete_object[$primary_table->get_fully_qualified_pk_column()]))
1710 1710
 					$deletes[$primary_table->get_fully_qualified_pk_column()][] = $delete_object[$primary_table->get_fully_qualified_pk_column()];
1711 1711
 
1712 1712
 				//other tables
1713
-				if ( !empty( $other_tables ) ) {
1714
-					foreach ( $other_tables as $ot ) {
1713
+				if ( ! empty($other_tables)) {
1714
+					foreach ($other_tables as $ot) {
1715 1715
 
1716 1716
 						//first check if we've got the foreign key column here.
1717
-						if ( isset( $delete_object[$ot->get_fully_qualified_fk_column()] ) )
1717
+						if (isset($delete_object[$ot->get_fully_qualified_fk_column()]))
1718 1718
 							$deletes[$ot->get_fully_qualified_pk_column()][] = $delete_object[$ot->get_fully_qualified_fk_column()];
1719 1719
 
1720 1720
 						//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()] ) )
1721
+						if (isset($delete_object[$ot->get_fully_qualified_pk_column()]))
1722 1722
 							$deletes[$ot->get_fully_qualified_pk_column()][] = $delete_object[$ot->get_fully_qualified_pk_column()];
1723 1723
 
1724 1724
 						//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()]) )
1725
+						if (isset($delete_object[$ot->get_fully_qualified_pk_on_fk_table()]))
1726 1726
 							$deletes[$ot->get_fully_qualified_pk_column()][] = $delete_object[$ot->get_fully_qualified_pk_column()];
1727 1727
 					}
1728 1728
 				}
1729 1729
 			}
1730 1730
 
1731 1731
 			//we should have deletes now, so let's just go through and setup the where statement
1732
-			foreach ( $deletes as $column => $values ) {
1732
+			foreach ($deletes as $column => $values) {
1733 1733
 				//make sure we have unique $values;
1734 1734
 				$values = array_unique($values);
1735
-				$query[] = $column . ' IN(' . implode(",",$values) . ')';
1735
+				$query[] = $column.' IN('.implode(",", $values).')';
1736 1736
 			}
1737 1737
 
1738
-			return !empty($query) ? implode(' AND ', $query ) : '';
1739
-		}elseif(count($this->get_combined_primary_key_fields()) > 1){
1738
+			return ! empty($query) ? implode(' AND ', $query) : '';
1739
+		}elseif (count($this->get_combined_primary_key_fields()) > 1) {
1740 1740
 			$ways_to_identify_a_row = array();
1741 1741
 			$fields = $this->get_combined_primary_key_fields();
1742 1742
 			//note: because there' sno primary key, that means nothing else  can be pointing to this model, right?
1743
-			foreach($objects_for_deletion as  $delete_object){
1743
+			foreach ($objects_for_deletion as  $delete_object) {
1744 1744
 				$values_for_each_cpk_for_a_row = array();
1745
-				foreach($fields as $cpk_field){
1745
+				foreach ($fields as $cpk_field) {
1746 1746
 					$values_for_each_cpk_for_a_row[] = $cpk_field->get_qualified_column()."=".$delete_object[$cpk_field->get_qualified_column()];
1747 1747
 				}
1748
-				$ways_to_identify_a_row[] = "(".implode(" AND ",$values_for_each_cpk_for_a_row).")";
1748
+				$ways_to_identify_a_row[] = "(".implode(" AND ", $values_for_each_cpk_for_a_row).")";
1749 1749
 			}
1750
-			return implode(" OR ",$ways_to_identify_a_row);
1751
-		}else{
1750
+			return implode(" OR ", $ways_to_identify_a_row);
1751
+		} else {
1752 1752
 			//so there's no primary key and no combined key...
1753 1753
 			//sorry, can't help you
1754
-			throw new EE_Error(sprintf(__("Cannot delete objects of type %s because there is no primary key NOR combined key", "event_espresso"),get_class($this)));
1754
+			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)));
1755 1755
 		}
1756 1756
 	}
1757 1757
 
@@ -1765,21 +1765,21 @@  discard block
 block discarded – undo
1765 1765
 	 * @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;
1766 1766
 	 * @return int
1767 1767
 	 */
1768
-	function count($query_params =array(),$field_to_count = NULL, $distinct = FALSE){
1768
+	function count($query_params = array(), $field_to_count = NULL, $distinct = FALSE) {
1769 1769
 		$model_query_info = $this->_create_model_query_info_carrier($query_params);
1770
-		if($field_to_count){
1770
+		if ($field_to_count) {
1771 1771
 			$field_obj = $this->field_settings_for($field_to_count);
1772 1772
 			$column_to_count = $field_obj->get_qualified_column();
1773
-		}elseif($this->has_primary_key_field ()){
1773
+		}elseif ($this->has_primary_key_field()) {
1774 1774
 			$pk_field_obj = $this->get_primary_key_field();
1775 1775
 			$column_to_count = $pk_field_obj->get_qualified_column();
1776
-		}else{//there's no primary key
1776
+		} else {//there's no primary key
1777 1777
 			$column_to_count = '*';
1778 1778
 		}
1779 1779
 
1780
-		$column_to_count = $distinct ? "DISTINCT (" . $column_to_count . " )" : $column_to_count;
1781
-		$SQL ="SELECT COUNT(".$column_to_count.")" . $this->_construct_2nd_half_of_select_query($model_query_info);
1782
-		return (int)$this->_do_wpdb_query( 'get_var', array( $SQL) );
1780
+		$column_to_count = $distinct ? "DISTINCT (".$column_to_count." )" : $column_to_count;
1781
+		$SQL = "SELECT COUNT(".$column_to_count.")".$this->_construct_2nd_half_of_select_query($model_query_info);
1782
+		return (int) $this->_do_wpdb_query('get_var', array($SQL));
1783 1783
 	}
1784 1784
 
1785 1785
 	/**
@@ -1789,23 +1789,23 @@  discard block
 block discarded – undo
1789 1789
 	 * @param string $field_to_sum name of field (array key in $_fields array)
1790 1790
 	 * @return float
1791 1791
 	 */
1792
-	function sum($query_params, $field_to_sum = NULL){
1792
+	function sum($query_params, $field_to_sum = NULL) {
1793 1793
 		$model_query_info = $this->_create_model_query_info_carrier($query_params);
1794 1794
 
1795
-		if($field_to_sum){
1795
+		if ($field_to_sum) {
1796 1796
 			$field_obj = $this->field_settings_for($field_to_sum);
1797 1797
 
1798
-		}else{
1798
+		} else {
1799 1799
 			$field_obj = $this->get_primary_key_field();
1800 1800
 		}
1801 1801
 		$column_to_count = $field_obj->get_qualified_column();
1802 1802
 
1803
-		$SQL ="SELECT SUM(".$column_to_count.")" . $this->_construct_2nd_half_of_select_query($model_query_info);
1804
-		$return_value = $this->_do_wpdb_query('get_var',array( $SQL ) );
1805
-		if($field_obj->get_wpdb_data_type() == '%d' || $field_obj->get_wpdb_data_type() == '%s' ){
1806
-			return (float)$return_value;
1807
-		}else{//must be %f
1808
-			return (float)$return_value;
1803
+		$SQL = "SELECT SUM(".$column_to_count.")".$this->_construct_2nd_half_of_select_query($model_query_info);
1804
+		$return_value = $this->_do_wpdb_query('get_var', array($SQL));
1805
+		if ($field_obj->get_wpdb_data_type() == '%d' || $field_obj->get_wpdb_data_type() == '%s') {
1806
+			return (float) $return_value;
1807
+		} else {//must be %f
1808
+			return (float) $return_value;
1809 1809
 		}
1810 1810
 	}
1811 1811
 
@@ -1820,33 +1820,33 @@  discard block
 block discarded – undo
1820 1820
 	 * @global wpdb $wpdb
1821 1821
 	 * @return mixed
1822 1822
 	 */
1823
-	protected function _do_wpdb_query( $wpdb_method, $arguments_to_provide ){
1823
+	protected function _do_wpdb_query($wpdb_method, $arguments_to_provide) {
1824 1824
 		//if we're in maintenance mode level 2, DON'T run any queries
1825 1825
 		//because level 2 indicates the database needs updating and
1826 1826
 		//is probably out of sync with the code
1827
-		if( ! EE_Maintenance_Mode::instance()->models_can_query()){
1827
+		if ( ! EE_Maintenance_Mode::instance()->models_can_query()) {
1828 1828
 			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")));
1829 1829
 		}
1830 1830
 		/** @type WPDB $wpdb */
1831 1831
 		global $wpdb;
1832
-		if( ! method_exists( $wpdb, $wpdb_method ) ){
1833
-			throw new EE_Error( sprintf( __( 'There is no method named "%s" on Wordpress\' $wpdb object','event_espresso' ), $wpdb_method ) );
1832
+		if ( ! method_exists($wpdb, $wpdb_method)) {
1833
+			throw new EE_Error(sprintf(__('There is no method named "%s" on Wordpress\' $wpdb object', 'event_espresso'), $wpdb_method));
1834 1834
 		}
1835
-		if( WP_DEBUG ){
1835
+		if (WP_DEBUG) {
1836 1836
 			$old_show_errors_value = $wpdb->show_errors;
1837
-			$wpdb->show_errors( FALSE );
1838
-		}
1839
-		$result = $this->_process_wpdb_query( $wpdb_method, $arguments_to_provide );
1840
-		$this->show_db_query_if_previously_requested( $wpdb->last_query );
1841
-		if( WP_DEBUG ){
1842
-			$wpdb->show_errors( $old_show_errors_value );
1843
-			if( ! empty( $wpdb->last_error ) ){
1844
-				throw new EE_Error( sprintf( __( 'WPDB Error: "%s"', 'event_espresso' ), $wpdb->last_error ) );
1845
-			}elseif( $result === false ){
1846
-				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 ) ) );
1837
+			$wpdb->show_errors(FALSE);
1838
+		}
1839
+		$result = $this->_process_wpdb_query($wpdb_method, $arguments_to_provide);
1840
+		$this->show_db_query_if_previously_requested($wpdb->last_query);
1841
+		if (WP_DEBUG) {
1842
+			$wpdb->show_errors($old_show_errors_value);
1843
+			if ( ! empty($wpdb->last_error)) {
1844
+				throw new EE_Error(sprintf(__('WPDB Error: "%s"', 'event_espresso'), $wpdb->last_error));
1845
+			}elseif ($result === false) {
1846
+				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 1847
 			}
1848
-		}elseif( $result === false ) {
1849
-			EE_Error::add_error( sprintf( __( 'A database error has occurred. Turn on WP_DEBUG for more information.', 'event_espresso' )), __FILE__, __FUNCTION__, __LINE__);
1848
+		}elseif ($result === false) {
1849
+			EE_Error::add_error(sprintf(__('A database error has occurred. Turn on WP_DEBUG for more information.', 'event_espresso')), __FILE__, __FUNCTION__, __LINE__);
1850 1850
 		}
1851 1851
 		return $result;
1852 1852
 	}
@@ -1862,23 +1862,23 @@  discard block
 block discarded – undo
1862 1862
 	 * @param array $arguments_to_provide
1863 1863
 	 * @return mixed
1864 1864
 	 */
1865
-	private function _process_wpdb_query( $wpdb_method, $arguments_to_provide ) {
1865
+	private function _process_wpdb_query($wpdb_method, $arguments_to_provide) {
1866 1866
 		/** @type WPDB $wpdb */
1867 1867
 		global $wpdb;
1868 1868
 		$wpdb->last_error = null;
1869
-		$result = call_user_func_array( array( $wpdb, $wpdb_method ), $arguments_to_provide );
1869
+		$result = call_user_func_array(array($wpdb, $wpdb_method), $arguments_to_provide);
1870 1870
 		// was there an error running the query?
1871
-		if ( ( $result === false || ! empty( $wpdb->last_error ) ) ) {
1872
-			switch ( EEM_Base::$_db_verification_level ) {
1871
+		if (($result === false || ! empty($wpdb->last_error))) {
1872
+			switch (EEM_Base::$_db_verification_level) {
1873 1873
 
1874 1874
 				case EEM_Base::db_verified_none :
1875 1875
 					// let's double-check core's DB
1876
-					$error_message = $this->_verify_core_db( $wpdb_method, $arguments_to_provide );
1876
+					$error_message = $this->_verify_core_db($wpdb_method, $arguments_to_provide);
1877 1877
 					break;
1878 1878
 
1879 1879
 				case EEM_Base::db_verified_core :
1880 1880
 					// STILL NO LOVE?? verify all the addons too. Maybe they need to be fixed
1881
-					$error_message = $this->_verify_addons_db( $wpdb_method, $arguments_to_provide );
1881
+					$error_message = $this->_verify_addons_db($wpdb_method, $arguments_to_provide);
1882 1882
 					break;
1883 1883
 
1884 1884
 				case EEM_Base::db_verified_addons :
@@ -1886,11 +1886,11 @@  discard block
 block discarded – undo
1886 1886
 					return $result;
1887 1887
 					break;
1888 1888
 			}
1889
-			if ( ! empty( $error_message ) ) {
1890
-				EE_Log::instance()->log( __FILE__, __FUNCTION__, $error_message, 'error' );
1891
-				trigger_error( $error_message );
1889
+			if ( ! empty($error_message)) {
1890
+				EE_Log::instance()->log(__FILE__, __FUNCTION__, $error_message, 'error');
1891
+				trigger_error($error_message);
1892 1892
 			}
1893
-			return $this->_process_wpdb_query( $wpdb_method, $arguments_to_provide );
1893
+			return $this->_process_wpdb_query($wpdb_method, $arguments_to_provide);
1894 1894
 
1895 1895
 		}
1896 1896
 
@@ -1906,18 +1906,18 @@  discard block
 block discarded – undo
1906 1906
 	 * @param array $arguments_to_provide
1907 1907
 	 * @return string
1908 1908
 	 */
1909
-	private function _verify_core_db( $wpdb_method, $arguments_to_provide ){
1909
+	private function _verify_core_db($wpdb_method, $arguments_to_provide) {
1910 1910
 		/** @type WPDB $wpdb */
1911 1911
 		global $wpdb;
1912 1912
 		//ok remember that we've already attempted fixing the core db, in case the problem persists
1913 1913
 		EEM_Base::$_db_verification_level = EEM_Base::db_verified_core;
1914 1914
 		$error_message = sprintf(
1915
-			__( 'WPDB Error "%1$s" while running wpdb method "%2$s" with arguments %3$s. Automatically attempting to fix EE Core DB', 'event_espresso' ),
1915
+			__('WPDB Error "%1$s" while running wpdb method "%2$s" with arguments %3$s. Automatically attempting to fix EE Core DB', 'event_espresso'),
1916 1916
 			$wpdb->last_error,
1917 1917
 			$wpdb_method,
1918
-			json_encode( $arguments_to_provide )
1918
+			json_encode($arguments_to_provide)
1919 1919
 		);
1920
-		EE_System::instance()->initialize_db_if_no_migrations_required( false, true );
1920
+		EE_System::instance()->initialize_db_if_no_migrations_required(false, true);
1921 1921
 		return $error_message;
1922 1922
 	}
1923 1923
 
@@ -1930,16 +1930,16 @@  discard block
 block discarded – undo
1930 1930
 	 * @param $arguments_to_provide
1931 1931
 	 * @return string
1932 1932
 	 */
1933
-	private function _verify_addons_db( $wpdb_method, $arguments_to_provide ) {
1933
+	private function _verify_addons_db($wpdb_method, $arguments_to_provide) {
1934 1934
 		/** @type WPDB $wpdb */
1935 1935
 		global $wpdb;
1936 1936
 		//ok remember that we've already attempted fixing the addons dbs, in case the problem persists
1937 1937
 		EEM_Base::$_db_verification_level = EEM_Base::db_verified_addons;
1938 1938
 		$error_message = sprintf(
1939
-			__( 'WPDB AGAIN: Error "%1$s" while running the same method and arguments as before. Automatically attempting to fix EE Addons DB', 'event_espresso' ),
1939
+			__('WPDB AGAIN: Error "%1$s" while running the same method and arguments as before. Automatically attempting to fix EE Addons DB', 'event_espresso'),
1940 1940
 			$wpdb->last_error,
1941 1941
 			$wpdb_method,
1942
-			json_encode( $arguments_to_provide )
1942
+			json_encode($arguments_to_provide)
1943 1943
 		);
1944 1944
 		EE_System::instance()->initialize_addons();
1945 1945
 		return $error_message;
@@ -1954,7 +1954,7 @@  discard block
 block discarded – undo
1954 1954
 	 * @param EE_Model_Query_Info_Carrier $model_query_info
1955 1955
 	 * @return string
1956 1956
 	 */
1957
-	private function _construct_2nd_half_of_select_query(EE_Model_Query_Info_Carrier $model_query_info){
1957
+	private function _construct_2nd_half_of_select_query(EE_Model_Query_Info_Carrier $model_query_info) {
1958 1958
 		return " FROM ".$model_query_info->get_full_join_sql().
1959 1959
 				$model_query_info->get_where_sql().
1960 1960
 				$model_query_info->get_group_by_sql().
@@ -1967,7 +1967,7 @@  discard block
 block discarded – undo
1967 1967
 	 * Set to easily debug the next X queries ran from this model.
1968 1968
 	 * @param int $count
1969 1969
 	 */
1970
-	function show_next_x_db_queries($count = 1){
1970
+	function show_next_x_db_queries($count = 1) {
1971 1971
 		$this->_show_next_x_db_queries = $count;
1972 1972
 	}
1973 1973
 
@@ -1976,8 +1976,8 @@  discard block
 block discarded – undo
1976 1976
 	/**
1977 1977
 	 * @param $sql_query
1978 1978
 	 */
1979
-	function show_db_query_if_previously_requested($sql_query){
1980
-		if($this->_show_next_x_db_queries > 0){
1979
+	function show_db_query_if_previously_requested($sql_query) {
1980
+		if ($this->_show_next_x_db_queries > 0) {
1981 1981
 			echo $sql_query;
1982 1982
 			$this->_show_next_x_db_queries--;
1983 1983
 		}
@@ -2001,9 +2001,9 @@  discard block
 block discarded – undo
2001 2001
 	 * @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.
2002 2002
 	 * @return EE_Base_Class which was added as a relation. Object referred to by $other_model_id_or_obj
2003 2003
 	 */
2004
-	public function add_relationship_to($id_or_obj,$other_model_id_or_obj, $relationName, $extra_join_model_fields_n_values = array()){
2004
+	public function add_relationship_to($id_or_obj, $other_model_id_or_obj, $relationName, $extra_join_model_fields_n_values = array()) {
2005 2005
 		$relation_obj = $this->related_settings_for($relationName);
2006
-		return $relation_obj->add_relation_to( $id_or_obj, $other_model_id_or_obj, $extra_join_model_fields_n_values);
2006
+		return $relation_obj->add_relation_to($id_or_obj, $other_model_id_or_obj, $extra_join_model_fields_n_values);
2007 2007
 	}
2008 2008
 
2009 2009
 	/**
@@ -2022,9 +2022,9 @@  discard block
 block discarded – undo
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.
2024 2024
 	 */
2025
-	public function remove_relationship_to($id_or_obj,  $other_model_id_or_obj, $relationName, $where_query= array() ){
2025
+	public function remove_relationship_to($id_or_obj, $other_model_id_or_obj, $relationName, $where_query = array()) {
2026 2026
 		$relation_obj = $this->related_settings_for($relationName);
2027
-		return $relation_obj->remove_relation_to($id_or_obj, $other_model_id_or_obj, $where_query );
2027
+		return $relation_obj->remove_relation_to($id_or_obj, $other_model_id_or_obj, $where_query);
2028 2028
 	}
2029 2029
 
2030 2030
 
@@ -2037,9 +2037,9 @@  discard block
 block discarded – undo
2037 2037
 	 * @param EE_Base_Class[] objects to which relations were removed
2038 2038
 	 * @return \EE_Base_Class[]
2039 2039
 	 */
2040
-	public function remove_relations($id_or_obj,$relationName,$where_query_params = array()){
2040
+	public function remove_relations($id_or_obj, $relationName, $where_query_params = array()) {
2041 2041
 		$relation_obj = $this->related_settings_for($relationName);
2042
-		return $relation_obj->remove_relations($id_or_obj, $where_query_params );
2042
+		return $relation_obj->remove_relations($id_or_obj, $where_query_params);
2043 2043
 	}
2044 2044
 
2045 2045
 
@@ -2052,10 +2052,10 @@  discard block
 block discarded – undo
2052 2052
 	 * @param array $query_params like EEM_Base::get_all
2053 2053
 	 * @return EE_Base_Class[]
2054 2054
 	 */
2055
-	function get_all_related($id_or_obj, $model_name, $query_params = null){
2055
+	function get_all_related($id_or_obj, $model_name, $query_params = null) {
2056 2056
 		$model_obj = $this->ensure_is_obj($id_or_obj);
2057 2057
 		$relation_settings = $this->related_settings_for($model_name);
2058
-		return $relation_settings->get_all_related($model_obj,$query_params);
2058
+		return $relation_settings->get_all_related($model_obj, $query_params);
2059 2059
 	}
2060 2060
 
2061 2061
 	/**
@@ -2068,10 +2068,10 @@  discard block
 block discarded – undo
2068 2068
 	 * @param array $query_params
2069 2069
 	 * @return int how many deleted
2070 2070
 	 */
2071
-	public function delete_related($id_or_obj,$model_name, $query_params = array()){
2071
+	public function delete_related($id_or_obj, $model_name, $query_params = array()) {
2072 2072
 		$model_obj = $this->ensure_is_obj($id_or_obj);
2073 2073
 		$relation_settings = $this->related_settings_for($model_name);
2074
-		return $relation_settings->delete_all_related($model_obj,$query_params);
2074
+		return $relation_settings->delete_all_related($model_obj, $query_params);
2075 2075
 	}
2076 2076
 
2077 2077
 	/**
@@ -2084,10 +2084,10 @@  discard block
 block discarded – undo
2084 2084
 	 * @param array $query_params
2085 2085
 	 * @return int how many deleted
2086 2086
 	 */
2087
-	public function delete_related_permanently($id_or_obj,$model_name, $query_params = array()){
2087
+	public function delete_related_permanently($id_or_obj, $model_name, $query_params = array()) {
2088 2088
 		$model_obj = $this->ensure_is_obj($id_or_obj);
2089 2089
 		$relation_settings = $this->related_settings_for($model_name);
2090
-		return $relation_settings->delete_related_permanently($model_obj,$query_params);
2090
+		return $relation_settings->delete_related_permanently($model_obj, $query_params);
2091 2091
 	}
2092 2092
 
2093 2093
 	/**
@@ -2100,17 +2100,17 @@  discard block
 block discarded – undo
2100 2100
 	 * @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;
2101 2101
 	 * @return int
2102 2102
 	 */
2103
-	function count_related($id_or_obj,$model_name,$query_params = array(),$field_to_count = null, $distinct = FALSE){
2103
+	function count_related($id_or_obj, $model_name, $query_params = array(), $field_to_count = null, $distinct = FALSE) {
2104 2104
 		$related_model = $this->get_related_model_obj($model_name);
2105 2105
 		//we're just going to use the query params on the related model's normal get_all query,
2106 2106
 		//except add a condition to say to match the current mod
2107
-		if( ! isset($query_params['default_where_conditions'])){
2108
-			$query_params['default_where_conditions']='none';
2107
+		if ( ! isset($query_params['default_where_conditions'])) {
2108
+			$query_params['default_where_conditions'] = 'none';
2109 2109
 		}
2110 2110
 		$this_model_name = $this->get_this_model_name();
2111 2111
 		$this_pk_field_name = $this->get_primary_key_field()->get_name();
2112
-		$query_params[0][$this_model_name.".".$this_pk_field_name]=$id_or_obj;
2113
-		return $related_model->count($query_params,$field_to_count,$distinct);
2112
+		$query_params[0][$this_model_name.".".$this_pk_field_name] = $id_or_obj;
2113
+		return $related_model->count($query_params, $field_to_count, $distinct);
2114 2114
 	}
2115 2115
 
2116 2116
 
@@ -2124,21 +2124,21 @@  discard block
 block discarded – undo
2124 2124
 	 * @param string $field_to_sum name of field to count by. By default, uses primary key
2125 2125
 	 * @return float
2126 2126
 	 */
2127
-	function sum_related($id_or_obj,$model_name,$query_params,$field_to_sum = null){
2127
+	function sum_related($id_or_obj, $model_name, $query_params, $field_to_sum = null) {
2128 2128
 		$related_model = $this->get_related_model_obj($model_name);
2129
-		if( ! is_array( $query_params ) ){
2130
-			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' );
2129
+		if ( ! is_array($query_params)) {
2130
+			EE_Error::doing_it_wrong('EEM_Base::sum_related', sprintf(__('$query_params should be an array, you passed a variable of type %s', 'event_espresso'), gettype($query_params)), '4.6.0');
2131 2131
 			$query_params = array();
2132 2132
 		}
2133 2133
 		//we're just going to use the query params on the related model's normal get_all query,
2134 2134
 		//except add a condition to say to match the current mod
2135
-		if( ! isset($query_params['default_where_conditions'])){
2136
-			$query_params['default_where_conditions']='none';
2135
+		if ( ! isset($query_params['default_where_conditions'])) {
2136
+			$query_params['default_where_conditions'] = 'none';
2137 2137
 		}
2138 2138
 		$this_model_name = $this->get_this_model_name();
2139 2139
 		$this_pk_field_name = $this->get_primary_key_field()->get_name();
2140
-		$query_params[0][$this_model_name.".".$this_pk_field_name]=$id_or_obj;
2141
-		return $related_model->sum($query_params,$field_to_sum);
2140
+		$query_params[0][$this_model_name.".".$this_pk_field_name] = $id_or_obj;
2141
+		return $related_model->sum($query_params, $field_to_sum);
2142 2142
 	}
2143 2143
 
2144 2144
 
@@ -2150,12 +2150,12 @@  discard block
 block discarded – undo
2150 2150
 	 * @param array $query_params like EEM_Base::get_all's
2151 2151
 	 * @return EE_Base_Class
2152 2152
 	 */
2153
-	public function get_first_related( EE_Base_Class $id_or_obj, $other_model_name, $query_params ){
2154
-		$query_params['limit']=1;
2155
-		$results = $this->get_all_related($id_or_obj,$other_model_name,$query_params);
2156
-		if( $results ){
2153
+	public function get_first_related(EE_Base_Class $id_or_obj, $other_model_name, $query_params) {
2154
+		$query_params['limit'] = 1;
2155
+		$results = $this->get_all_related($id_or_obj, $other_model_name, $query_params);
2156
+		if ($results) {
2157 2157
 			return array_shift($results);
2158
-		}else{
2158
+		} else {
2159 2159
 			return null;
2160 2160
 		}
2161 2161
 
@@ -2165,8 +2165,8 @@  discard block
 block discarded – undo
2165 2165
 	 * Gets the model's name as it's expected in queries. For example, if this is EEM_Event model, that would be Event
2166 2166
 	 * @return string
2167 2167
 	 */
2168
-	function get_this_model_name(){
2169
-		return str_replace("EEM_","",get_class($this));
2168
+	function get_this_model_name() {
2169
+		return str_replace("EEM_", "", get_class($this));
2170 2170
 	}
2171 2171
 
2172 2172
 	/**
@@ -2174,14 +2174,14 @@  discard block
 block discarded – undo
2174 2174
 	 * @return EE_Any_Foreign_Model_Name_Field
2175 2175
 	 * @throws EE_Error
2176 2176
 	 */
2177
-	public function get_field_containing_related_model_name(){
2178
-		foreach($this->field_settings(true) as $field){
2179
-			if($field instanceof EE_Any_Foreign_Model_Name_Field){
2177
+	public function get_field_containing_related_model_name() {
2178
+		foreach ($this->field_settings(true) as $field) {
2179
+			if ($field instanceof EE_Any_Foreign_Model_Name_Field) {
2180 2180
 				$field_with_model_name = $field;
2181 2181
 			}
2182 2182
 		}
2183
-		if( !isset($field_with_model_name) || !$field_with_model_name ){
2184
-			throw new EE_Error(sprintf(__("There is no EE_Any_Foreign_Model_Name field on model %s", "event_espresso"), $this->get_this_model_name() ));
2183
+		if ( ! isset($field_with_model_name) || ! $field_with_model_name) {
2184
+			throw new EE_Error(sprintf(__("There is no EE_Any_Foreign_Model_Name field on model %s", "event_espresso"), $this->get_this_model_name()));
2185 2185
 		}
2186 2186
 		return $field_with_model_name;
2187 2187
 	}
@@ -2202,19 +2202,19 @@  discard block
 block discarded – undo
2202 2202
 	 * @return int new primary key on main table that got inserted
2203 2203
 	 * @throws EE_Error
2204 2204
 	 */
2205
-	function insert($field_n_values){
2205
+	function insert($field_n_values) {
2206 2206
 		/**
2207 2207
 		 * Filters the fields and their values before inserting an item using the models
2208 2208
 		 * @param array $fields_n_values keys are the fields and values are their new values
2209 2209
 		 * @param EEM_Base $model the model used
2210 2210
 		 */
2211
-		$field_n_values = apply_filters( 'FHEE__EEM_Base__insert__fields_n_values', $field_n_values, $this );
2212
-		if($this->_satisfies_unique_indexes($field_n_values)){
2211
+		$field_n_values = apply_filters('FHEE__EEM_Base__insert__fields_n_values', $field_n_values, $this);
2212
+		if ($this->_satisfies_unique_indexes($field_n_values)) {
2213 2213
 			$main_table = $this->_get_main_table();
2214 2214
 			$new_id = $this->_insert_into_specific_table($main_table, $field_n_values, false);
2215
-			if( $new_id !== false ) {
2216
-				foreach($this->_get_other_tables() as $other_table){
2217
-					$this->_insert_into_specific_table($other_table, $field_n_values,$new_id);
2215
+			if ($new_id !== false) {
2216
+				foreach ($this->_get_other_tables() as $other_table) {
2217
+					$this->_insert_into_specific_table($other_table, $field_n_values, $new_id);
2218 2218
 				}
2219 2219
 			}
2220 2220
 			/**
@@ -2224,9 +2224,9 @@  discard block
 block discarded – undo
2224 2224
 			 * @param array $fields_n_values fields and their values
2225 2225
 			 * @param int|string the ID of the newly-inserted model object
2226 2226
 			 */
2227
-			do_action( 'AHEE__EEM_Base__insert__end', $this, $field_n_values, $new_id );
2227
+			do_action('AHEE__EEM_Base__insert__end', $this, $field_n_values, $new_id);
2228 2228
 			return $new_id;
2229
-		}else{
2229
+		} else {
2230 2230
 			return FALSE;
2231 2231
 		}
2232 2232
 	}
@@ -2239,11 +2239,11 @@  discard block
 block discarded – undo
2239 2239
 	 * @param string $action
2240 2240
 	 * @return boolean
2241 2241
 	 */
2242
-	protected function _satisfies_unique_indexes($field_n_values,$action = 'insert'){
2243
-		foreach($this->unique_indexes() as $index_name => $index){
2242
+	protected function _satisfies_unique_indexes($field_n_values, $action = 'insert') {
2243
+		foreach ($this->unique_indexes() as $index_name => $index) {
2244 2244
 			$uniqueness_where_params = array_intersect_key($field_n_values, $index->fields());
2245
-			if($this->exists(array($uniqueness_where_params))){
2246
-				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__ );
2245
+			if ($this->exists(array($uniqueness_where_params))) {
2246
+				EE_Error::add_error(sprintf(__("Could not %s %s. %s uniqueness index failed. Fields %s must form a unique set, but an entry already exists with values %s.", "event_espresso"), $action, $this->_get_class_name(), $index_name, implode(",", $index->field_names()), http_build_query($uniqueness_where_params)), __FILE__, __FUNCTION__, __LINE__);
2247 2247
 				return false;
2248 2248
 			}
2249 2249
 		}
@@ -2264,28 +2264,28 @@  discard block
 block discarded – undo
2264 2264
 	 * @throws EE_Error
2265 2265
 	 * @return EE_Base_Class
2266 2266
 	 */
2267
-	public function get_one_conflicting($obj_or_fields_array, $include_primary_key = true ){
2268
-		if($obj_or_fields_array instanceof EE_Base_Class){
2267
+	public function get_one_conflicting($obj_or_fields_array, $include_primary_key = true) {
2268
+		if ($obj_or_fields_array instanceof EE_Base_Class) {
2269 2269
 			$fields_n_values = $obj_or_fields_array->model_field_array();
2270
-		}elseif( is_array($obj_or_fields_array)){
2270
+		}elseif (is_array($obj_or_fields_array)) {
2271 2271
 			$fields_n_values = $obj_or_fields_array;
2272
-		}else{
2273
-			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));
2272
+		} else {
2273
+			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 2274
 		}
2275 2275
 		$query_params = array();
2276
-		if( $this->has_primary_key_field() &&
2277
-				( $include_primary_key || $this->get_primary_key_field() instanceof EE_Primary_Key_String_Field) &&
2278
-				isset($fields_n_values[$this->primary_key_name()])){
2276
+		if ($this->has_primary_key_field() &&
2277
+				($include_primary_key || $this->get_primary_key_field() instanceof EE_Primary_Key_String_Field) &&
2278
+				isset($fields_n_values[$this->primary_key_name()])) {
2279 2279
 			$query_params[0]['OR'][$this->primary_key_name()] = $fields_n_values[$this->primary_key_name()];
2280 2280
 		}
2281
-		foreach($this->unique_indexes() as $unique_index_name=>$unique_index){
2281
+		foreach ($this->unique_indexes() as $unique_index_name=>$unique_index) {
2282 2282
 			$uniqueness_where_params = array_intersect_key($fields_n_values, $unique_index->fields());
2283 2283
 			$query_params[0]['OR']['AND*'.$unique_index_name] = $uniqueness_where_params;
2284 2284
 		}
2285 2285
 		//if there is nothing to base this search on, then we shouldn't find anything
2286
-		if( empty( $query_params ) ){
2286
+		if (empty($query_params)) {
2287 2287
 			return array();
2288
-		}else{
2288
+		} else {
2289 2289
 			return $this->get_one($query_params);
2290 2290
 		}
2291 2291
 	}
@@ -2295,7 +2295,7 @@  discard block
 block discarded – undo
2295 2295
 	 * @param array $query_params
2296 2296
 	 * @return boolean
2297 2297
 	 */
2298
-	function exists($query_params){
2298
+	function exists($query_params) {
2299 2299
 		$query_params['limit'] = 1;
2300 2300
 		return $this->count($query_params) > 0;
2301 2301
 	}
@@ -2305,7 +2305,7 @@  discard block
 block discarded – undo
2305 2305
 	 * @param int|string $id
2306 2306
 	 * @return boolean
2307 2307
 	 */
2308
-	function exists_by_ID($id){
2308
+	function exists_by_ID($id) {
2309 2309
 		return $this->exists(array('default_where_conditions'=>'none', array($this->primary_key_name() => $id)));
2310 2310
 	}
2311 2311
 
@@ -2325,45 +2325,45 @@  discard block
 block discarded – undo
2325 2325
 	 * @global WPDB $wpdb only used to get the $wpdb->insert_id after performing an insert
2326 2326
 	 * @return int ID of new row inserted, or FALSE on failure
2327 2327
 	 */
2328
-	protected function _insert_into_specific_table(EE_Table_Base $table, $fields_n_values, $new_id = 0 ){
2328
+	protected function _insert_into_specific_table(EE_Table_Base $table, $fields_n_values, $new_id = 0) {
2329 2329
 		global $wpdb;
2330 2330
 		$insertion_col_n_values = array();
2331 2331
 		$format_for_insertion = array();
2332 2332
 		$fields_on_table = $this->_get_fields_for_table($table->get_table_alias());
2333
-		foreach($fields_on_table as $field_name => $field_obj){
2333
+		foreach ($fields_on_table as $field_name => $field_obj) {
2334 2334
 			//check if its an auto-incrementing column, in which case we should just leave it to do its autoincrement thing
2335
-			if($field_obj->is_auto_increment()){
2335
+			if ($field_obj->is_auto_increment()) {
2336 2336
 				continue;
2337 2337
 			}
2338 2338
 			$prepared_value = $this->_prepare_value_or_use_default($field_obj, $fields_n_values);
2339 2339
 			//if the value we want to assign it to is NULL, just don't mention it for the insertion
2340
-			if( $prepared_value !== NULL ){
2341
-				$insertion_col_n_values[ $field_obj->get_table_column() ] = $prepared_value;
2340
+			if ($prepared_value !== NULL) {
2341
+				$insertion_col_n_values[$field_obj->get_table_column()] = $prepared_value;
2342 2342
 				$format_for_insertion[] = $field_obj->get_wpdb_data_type();
2343 2343
 			}
2344 2344
 		}
2345 2345
 
2346
-		if($table instanceof EE_Secondary_Table && $new_id){
2346
+		if ($table instanceof EE_Secondary_Table && $new_id) {
2347 2347
 			//its not the main table, so we should have already saved the main table's PK which we just inserted
2348 2348
 			//so add the fk to the main table as a column
2349 2349
 			$insertion_col_n_values[$table->get_fk_on_table()] = $new_id;
2350
-			$format_for_insertion[]='%d';//yes right now we're only allowing these foreign keys to be INTs
2350
+			$format_for_insertion[] = '%d'; //yes right now we're only allowing these foreign keys to be INTs
2351 2351
 		}
2352 2352
 		//insert the new entry
2353
-		$result = $this->_do_wpdb_query( 'insert', array( $table->get_table_name(), $insertion_col_n_values, $format_for_insertion ) );
2354
-		if( $result === false ) {
2353
+		$result = $this->_do_wpdb_query('insert', array($table->get_table_name(), $insertion_col_n_values, $format_for_insertion));
2354
+		if ($result === false) {
2355 2355
 			return false;
2356 2356
 		}
2357 2357
 		//ok, now what do we return for the ID of the newly-inserted thing?
2358
-		if($this->has_primary_key_field()){
2359
-			if($this->get_primary_key_field()->is_auto_increment()){
2358
+		if ($this->has_primary_key_field()) {
2359
+			if ($this->get_primary_key_field()->is_auto_increment()) {
2360 2360
 				return $wpdb->insert_id;
2361
-			}else{
2361
+			} else {
2362 2362
 				//it's not an auto-increment primary key, so
2363 2363
 				//it must have been supplied
2364 2364
 				return $fields_n_values[$this->get_primary_key_field()->get_name()];
2365 2365
 			}
2366
-		}else{
2366
+		} else {
2367 2367
 			//we can't return a  primary key because there is none. instead return
2368 2368
 			//a unique string indicating this model
2369 2369
 			return $this->get_index_primary_key_string($fields_n_values);
@@ -2378,15 +2378,15 @@  discard block
 block discarded – undo
2378 2378
 	 * @param array $fields_n_values
2379 2379
 	 * @return mixed string|int|float depending on what the table column will be expecting
2380 2380
 	 */
2381
-	protected function _prepare_value_or_use_default( $field_obj, $fields_n_values ){
2381
+	protected function _prepare_value_or_use_default($field_obj, $fields_n_values) {
2382 2382
 		//if this field doesn't allow nullable, don't allow it
2383
-		if( ! $field_obj->is_nullable() && (
2384
-				! isset( $fields_n_values[ $field_obj->get_name() ] ) ||
2385
-				$fields_n_values[ $field_obj->get_name() ] === NULL ) ){
2386
-			$fields_n_values[ $field_obj->get_name() ] = $field_obj->get_default_value();
2383
+		if ( ! $field_obj->is_nullable() && (
2384
+				! isset($fields_n_values[$field_obj->get_name()]) ||
2385
+				$fields_n_values[$field_obj->get_name()] === NULL )) {
2386
+			$fields_n_values[$field_obj->get_name()] = $field_obj->get_default_value();
2387 2387
 		}
2388
-		$unprepared_value = isset( $fields_n_values[ $field_obj->get_name() ] ) ? $fields_n_values[ $field_obj->get_name() ] : NULL;
2389
-		return $this->_prepare_value_for_use_in_db( $unprepared_value, $field_obj);
2388
+		$unprepared_value = isset($fields_n_values[$field_obj->get_name()]) ? $fields_n_values[$field_obj->get_name()] : NULL;
2389
+		return $this->_prepare_value_for_use_in_db($unprepared_value, $field_obj);
2390 2390
 	}
2391 2391
 
2392 2392
 
@@ -2398,9 +2398,9 @@  discard block
 block discarded – undo
2398 2398
 	 * @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
2399 2399
 	 * @return mixed a value ready for use in the database for insertions, updating, or in a where clause
2400 2400
 	 */
2401
-	private function _prepare_value_for_use_in_db($value, $field){
2402
-		if($field && $field instanceof EE_Model_Field_Base){
2403
-			switch( $this->_values_already_prepared_by_model_object ){
2401
+	private function _prepare_value_for_use_in_db($value, $field) {
2402
+		if ($field && $field instanceof EE_Model_Field_Base) {
2403
+			switch ($this->_values_already_prepared_by_model_object) {
2404 2404
 				/** @noinspection PhpMissingBreakStatementInspection */
2405 2405
 				case self::not_prepared_by_model_object:
2406 2406
 					$value = $field->prepare_for_set($value);
@@ -2411,7 +2411,7 @@  discard block
 block discarded – undo
2411 2411
 					//leave the value alone
2412 2412
 			}
2413 2413
 			return $value;
2414
-		}else{
2414
+		} else {
2415 2415
 			return $value;
2416 2416
 		}
2417 2417
 	}
@@ -2421,13 +2421,13 @@  discard block
 block discarded – undo
2421 2421
 	 * @return EE_Primary_Table
2422 2422
 	 * @throws EE_Error
2423 2423
 	 */
2424
-	protected function _get_main_table(){
2425
-		foreach($this->_tables as $table){
2426
-			if($table instanceof EE_Primary_Table){
2424
+	protected function _get_main_table() {
2425
+		foreach ($this->_tables as $table) {
2426
+			if ($table instanceof EE_Primary_Table) {
2427 2427
 				return $table;
2428 2428
 			}
2429 2429
 		}
2430
-		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)));
2430
+		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)));
2431 2431
 	}
2432 2432
 
2433 2433
 	/**
@@ -2446,7 +2446,7 @@  discard block
 block discarded – undo
2446 2446
 	 */
2447 2447
 	public function second_table() {
2448 2448
 		// grab second table from tables array
2449
-		$second_table = end( $this->_tables );
2449
+		$second_table = end($this->_tables);
2450 2450
 		return $second_table instanceof EE_Secondary_Table ? $second_table->get_table_name() : NULL;
2451 2451
 	}
2452 2452
 
@@ -2459,8 +2459,8 @@  discard block
 block discarded – undo
2459 2459
 	 * @param string $table_alias
2460 2460
 	 * @return EE_Primary_Table | EE_Secondary_Table
2461 2461
 	 */
2462
-	public function get_table_obj_by_alias( $table_alias = '' ) {
2463
-		return isset( $this->_tables[ $table_alias ] ) ? $this->_tables[ $table_alias ] : NULL;
2462
+	public function get_table_obj_by_alias($table_alias = '') {
2463
+		return isset($this->_tables[$table_alias]) ? $this->_tables[$table_alias] : NULL;
2464 2464
 	}
2465 2465
 
2466 2466
 
@@ -2469,10 +2469,10 @@  discard block
 block discarded – undo
2469 2469
 	 * Gets all the tables of type EE_Other_Table from EEM_CPT_Basel_Model::_tables
2470 2470
 	 * @return EE_Secondary_Table[]
2471 2471
 	 */
2472
-	protected function _get_other_tables(){
2473
-		$other_tables =array();
2474
-		foreach($this->_tables as $table_alias => $table){
2475
-			if($table instanceof EE_Secondary_Table){
2472
+	protected function _get_other_tables() {
2473
+		$other_tables = array();
2474
+		foreach ($this->_tables as $table_alias => $table) {
2475
+			if ($table instanceof EE_Secondary_Table) {
2476 2476
 				$other_tables[$table_alias] = $table;
2477 2477
 			}
2478 2478
 		}
@@ -2484,7 +2484,7 @@  discard block
 block discarded – undo
2484 2484
 	 * @param string $table_alias, array key in EEM_Base::_tables
2485 2485
 	 * @return EE_Model_Field_Base[]
2486 2486
 	 */
2487
-	function _get_fields_for_table($table_alias){
2487
+	function _get_fields_for_table($table_alias) {
2488 2488
 		return $this->_fields[$table_alias];
2489 2489
 	}
2490 2490
 
@@ -2496,29 +2496,29 @@  discard block
 block discarded – undo
2496 2496
 	 * @param array $query_params like EEM_Base::get_all's $query_parameters['where']
2497 2497
 	 * @return EE_Model_Query_Info_Carrier
2498 2498
 	 */
2499
-	function _extract_related_models_from_query($query_params){
2499
+	function _extract_related_models_from_query($query_params) {
2500 2500
 		$query_info_carrier = new EE_Model_Query_Info_Carrier();
2501
-		if(array_key_exists(0,$query_params)){
2502
-			$this->_extract_related_models_from_sub_params_array_keys($query_params[0], $query_info_carrier,0);
2503
-		}
2504
-		if(array_key_exists('group_by', $query_params)){
2505
-			if(is_array($query_params['group_by'])){
2506
-				$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'] )){
2508
-				$this->_extract_related_model_info_from_query_param( $query_params['group_by'],$query_info_carrier,'group_by');
2501
+		if (array_key_exists(0, $query_params)) {
2502
+			$this->_extract_related_models_from_sub_params_array_keys($query_params[0], $query_info_carrier, 0);
2503
+		}
2504
+		if (array_key_exists('group_by', $query_params)) {
2505
+			if (is_array($query_params['group_by'])) {
2506
+				$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'])) {
2508
+				$this->_extract_related_model_info_from_query_param($query_params['group_by'], $query_info_carrier, 'group_by');
2509 2509
 			}
2510 2510
 		}
2511
-		if(array_key_exists('having',$query_params)){
2512
-			$this->_extract_related_models_from_sub_params_array_keys($query_params[0], $query_info_carrier,'having');
2511
+		if (array_key_exists('having', $query_params)) {
2512
+			$this->_extract_related_models_from_sub_params_array_keys($query_params[0], $query_info_carrier, 'having');
2513 2513
 		}
2514
-		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');
2514
+		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');
2519 2519
 		}
2520
-		if(array_key_exists('force_join', $query_params)){
2521
-			$this->_extract_related_models_from_sub_params_array_values($query_params['force_join'],$query_info_carrier,'force_join');
2520
+		if (array_key_exists('force_join', $query_params)) {
2521
+			$this->_extract_related_models_from_sub_params_array_values($query_params['force_join'], $query_info_carrier, 'force_join');
2522 2522
 		}
2523 2523
 		return $query_info_carrier;
2524 2524
 	}
@@ -2531,34 +2531,34 @@  discard block
 block discarded – undo
2531 2531
 	 * @throws EE_Error
2532 2532
 	 * @return \EE_Model_Query_Info_Carrier
2533 2533
 	 */
2534
-	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){
2535
-		if (!empty($sub_query_params)){
2534
+	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) {
2535
+		if ( ! empty($sub_query_params)) {
2536 2536
 			$sub_query_params = (array) $sub_query_params;
2537
-			foreach($sub_query_params as $param => $possibly_array_of_params){
2537
+			foreach ($sub_query_params as $param => $possibly_array_of_params) {
2538 2538
 				//$param could be simply 'EVT_ID', or it could be 'Registrations.REG_ID', or even 'Registrations.Transactions.Payments.PAY_amount'
2539
-				$this->_extract_related_model_info_from_query_param( $param, $model_query_info_carrier,$query_param_type);
2539
+				$this->_extract_related_model_info_from_query_param($param, $model_query_info_carrier, $query_param_type);
2540 2540
 
2541 2541
 				//if $possibly_array_of_params is an array, try recursing into it, searching for keys which
2542 2542
 				//indicate needed joins. Eg, array('NOT'=>array('Registration.TXN_ID'=>23)). In this case, we tried
2543 2543
 				//extracting models out of the 'NOT', which obviously wasn't successful, and then we recurse into the value
2544 2544
 				//of array('Registration.TXN_ID'=>23)
2545 2545
 				$query_param_sans_stars = $this->_remove_stars_and_anything_after_from_condition_query_param_key($param);
2546
-				if(in_array($query_param_sans_stars, $this->_logic_query_param_keys,true)){
2547
-					if (! is_array($possibly_array_of_params)){
2546
+				if (in_array($query_param_sans_stars, $this->_logic_query_param_keys, true)) {
2547
+					if ( ! is_array($possibly_array_of_params)) {
2548 2548
 						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
-							$param,$possibly_array_of_params));
2550
-					}else{
2551
-						$this->_extract_related_models_from_sub_params_array_keys($possibly_array_of_params, $model_query_info_carrier,$query_param_type);
2549
+							$param, $possibly_array_of_params));
2550
+					} else {
2551
+						$this->_extract_related_models_from_sub_params_array_keys($possibly_array_of_params, $model_query_info_carrier, $query_param_type);
2552 2552
 					}
2553
-				}elseif($query_param_type === 0 //ie WHERE
2553
+				}elseif ($query_param_type === 0 //ie WHERE
2554 2554
 						&& is_array($possibly_array_of_params)
2555 2555
 						&& isset($possibly_array_of_params[2])
2556
-						&& $possibly_array_of_params[2] == true){
2556
+						&& $possibly_array_of_params[2] == true) {
2557 2557
 					//then $possible_array_of_params looks something like array('<','DTT_sold',true)
2558 2558
 					//indicating that $possible_array_of_params[1] is actually a field name,
2559 2559
 					//from which we should extract query parameters!
2560
-					if(! isset($possibly_array_of_params[0]) || ! isset($possibly_array_of_params[1])){
2561
-						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)));
2560
+					if ( ! isset($possibly_array_of_params[0]) || ! isset($possibly_array_of_params[1])) {
2561
+						throw new EE_Error(sprintf(__("Improperly formed query parameter %s. It should be numerically indexed like array('<','DTT_sold',true); but you provided %s", "event_espresso"), $query_param_type, implode(",", $possibly_array_of_params)));
2562 2562
 					}
2563 2563
 					$this->_extract_related_model_info_from_query_param($possibly_array_of_params[1], $model_query_info_carrier, $query_param_type);
2564 2564
 				}
@@ -2577,14 +2577,14 @@  discard block
 block discarded – undo
2577 2577
 	 * @throws EE_Error
2578 2578
 	 * @return \EE_Model_Query_Info_Carrier
2579 2579
 	 */
2580
-	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){
2581
-		if (!empty($sub_query_params)){
2582
-			if(!is_array($sub_query_params)){
2583
-				throw new EE_Error(sprintf(__("Query parameter %s should be an array, but it isn't.", "event_espresso"),$sub_query_params));
2580
+	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) {
2581
+		if ( ! empty($sub_query_params)) {
2582
+			if ( ! is_array($sub_query_params)) {
2583
+				throw new EE_Error(sprintf(__("Query parameter %s should be an array, but it isn't.", "event_espresso"), $sub_query_params));
2584 2584
 			}
2585
-			foreach($sub_query_params as $param){
2585
+			foreach ($sub_query_params as $param) {
2586 2586
 				//$param could be simply 'EVT_ID', or it could be 'Registrations.REG_ID', or even 'Registrations.Transactions.Payments.PAY_amount'
2587
-				$this->_extract_related_model_info_from_query_param( $param, $model_query_info_carrier, $query_param_type);
2587
+				$this->_extract_related_model_info_from_query_param($param, $model_query_info_carrier, $query_param_type);
2588 2588
 			}
2589 2589
 		}
2590 2590
 		return $model_query_info_carrier;
@@ -2603,81 +2603,81 @@  discard block
 block discarded – undo
2603 2603
 	 * @throws EE_Error
2604 2604
 	 * @return EE_Model_Query_Info_Carrier
2605 2605
 	 */
2606
-	function _create_model_query_info_carrier($query_params){
2607
-		if( ! is_array( $query_params ) ){
2608
-			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' );
2606
+	function _create_model_query_info_carrier($query_params) {
2607
+		if ( ! is_array($query_params)) {
2608
+			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');
2609 2609
 			$query_params = array();
2610 2610
 		}
2611
-		if( isset( $query_params[0] ) ) {
2611
+		if (isset($query_params[0])) {
2612 2612
 			$where_query_params = $query_params[0];
2613
-		}else{
2613
+		} else {
2614 2614
 			$where_query_params = array();
2615 2615
 		}
2616 2616
 		//first check if we should alter the query to account for caps or not
2617 2617
 		//because the caps might require us to do extra joins
2618
-		if( isset( $query_params[ 'caps' ] ) && $query_params[ 'caps' ] != 'none' ) {
2619
-			$query_params[0] = $where_query_params = array_replace_recursive( $where_query_params, $this->caps_where_conditions( $query_params[ 'caps' ] ) );
2618
+		if (isset($query_params['caps']) && $query_params['caps'] != 'none') {
2619
+			$query_params[0] = $where_query_params = array_replace_recursive($where_query_params, $this->caps_where_conditions($query_params['caps']));
2620 2620
 		}
2621 2621
 		$query_object = $this->_extract_related_models_from_query($query_params);
2622 2622
 
2623 2623
 		//verify where_query_params has NO numeric indexes.... that's simply not how you use it!
2624
-		foreach($where_query_params as $key => $value){
2625
-			if(is_int($key)){
2626
-				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)));
2624
+		foreach ($where_query_params as $key => $value) {
2625
+			if (is_int($key)) {
2626
+				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)));
2627 2627
 			}
2628 2628
 		}
2629
-		if( array_key_exists( 'default_where_conditions',$query_params) && ! empty( $query_params['default_where_conditions'] )){
2629
+		if (array_key_exists('default_where_conditions', $query_params) && ! empty($query_params['default_where_conditions'])) {
2630 2630
 			$use_default_where_conditions = $query_params['default_where_conditions'];
2631
-		}else{
2631
+		} else {
2632 2632
 			$use_default_where_conditions = 'all';
2633 2633
 		}
2634
-		$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 );
2635
-		$query_object->set_where_sql( $this->_construct_where_clause($where_query_params));
2634
+		$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);
2635
+		$query_object->set_where_sql($this->_construct_where_clause($where_query_params));
2636 2636
 
2637 2637
 
2638 2638
 		//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:
2639 2639
 		//array( 'on_join_limit' => array('Primary_Table_Alias', array(1,10) ) )
2640
-		if ( array_key_exists('on_join_limit', $query_params ) && ! empty( $query_params['on_join_limit'] )) {
2641
-			$query_object->set_main_model_join_sql( $this->_construct_limit_join_select( $query_params['on_join_limit'][0], $query_params['on_join_limit'][1] ) );
2640
+		if (array_key_exists('on_join_limit', $query_params) && ! empty($query_params['on_join_limit'])) {
2641
+			$query_object->set_main_model_join_sql($this->_construct_limit_join_select($query_params['on_join_limit'][0], $query_params['on_join_limit'][1]));
2642 2642
 		}
2643 2643
 
2644 2644
 
2645 2645
 		//set limit
2646
-		if(array_key_exists('limit',$query_params)){
2647
-			if(is_array($query_params['limit'])){
2648
-				if( ! isset($query_params['limit'][0]) || ! isset($query_params['limit'][1])){
2649
-					$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']));
2646
+		if (array_key_exists('limit', $query_params)) {
2647
+			if (is_array($query_params['limit'])) {
2648
+				if ( ! isset($query_params['limit'][0]) || ! isset($query_params['limit'][1])) {
2649
+					$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']));
2650 2650
 					throw new EE_Error($e."|".$e);
2651 2651
 				}
2652 2652
 				//they passed us an array for the limit. Assume it's like array(50,25), meaning offset by 50, and get 25
2653 2653
 				$query_object->set_limit_sql(" LIMIT ".$query_params['limit'][0].",".$query_params['limit'][1]);
2654
-			}elseif( ! empty ( $query_params['limit'] )){
2654
+			}elseif ( ! empty ($query_params['limit'])) {
2655 2655
 				$query_object->set_limit_sql((" LIMIT ".$query_params['limit']));
2656 2656
 			}
2657 2657
 		}
2658 2658
 		//set order by
2659
-		if(array_key_exists('order_by',$query_params)){
2660
-			if(is_array($query_params['order_by'])){
2659
+		if (array_key_exists('order_by', $query_params)) {
2660
+			if (is_array($query_params['order_by'])) {
2661 2661
 				//if they're using 'order_by' as an array, they can't use 'order' (because 'order_by' must
2662 2662
 				//specify whether to ascend or descend on each field. Eg 'order_by'=>array('EVT_ID'=>'ASC'). So
2663 2663
 				//including 'order' wouldn't make any sense if 'order_by' has already specified which way to order!
2664
-				if(array_key_exists('order', $query_params)){
2664
+				if (array_key_exists('order', $query_params)) {
2665 2665
 					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"),
2666
-							get_class($this),implode(", ",array_keys($query_params['order_by'])),implode(", ",$query_params['order_by']),$query_params['order']));
2666
+							get_class($this), implode(", ", array_keys($query_params['order_by'])), implode(", ", $query_params['order_by']), $query_params['order']));
2667 2667
 				}
2668
-				 $this->_extract_related_models_from_sub_params_array_keys($query_params['order_by'],$query_object,'order_by');
2668
+				 $this->_extract_related_models_from_sub_params_array_keys($query_params['order_by'], $query_object, 'order_by');
2669 2669
 				//assume it's an array of fields to order by
2670 2670
 				$order_array = array();
2671
-				foreach($query_params['order_by'] as $field_name_to_order_by => $order){
2671
+				foreach ($query_params['order_by'] as $field_name_to_order_by => $order) {
2672 2672
 					$order = $this->_extract_order($order);
2673 2673
 					$order_array[] = $this->_deduce_column_name_from_query_param($field_name_to_order_by).SP.$order;
2674 2674
 				}
2675
-				$query_object->set_order_by_sql(" ORDER BY ".implode(",",$order_array));
2676
-			}elseif( ! empty ( $query_params['order_by'] )){
2677
-				$this->_extract_related_model_info_from_query_param($query_params['order_by'],$query_object,'order',$query_params['order_by']);
2678
-				if(isset($query_params['order'])){
2675
+				$query_object->set_order_by_sql(" ORDER BY ".implode(",", $order_array));
2676
+			}elseif ( ! empty ($query_params['order_by'])) {
2677
+				$this->_extract_related_model_info_from_query_param($query_params['order_by'], $query_object, 'order', $query_params['order_by']);
2678
+				if (isset($query_params['order'])) {
2679 2679
 					$order = $this->_extract_order($query_params['order']);
2680
-				}else{
2680
+				} else {
2681 2681
 					$order = 'DESC';
2682 2682
 				}
2683 2683
 				$query_object->set_order_by_sql(" ORDER BY ".$this->_deduce_column_name_from_query_param($query_params['order_by']).SP.$order);
@@ -2685,46 +2685,46 @@  discard block
 block discarded – undo
2685 2685
 		}
2686 2686
 
2687 2687
 		//if 'order_by' wasn't set, maybe they are just using 'order' on its own?
2688
-		if( ! array_key_exists('order_by',$query_params) && array_key_exists('order',$query_params) && ! empty( $query_params['order'] )){
2688
+		if ( ! array_key_exists('order_by', $query_params) && array_key_exists('order', $query_params) && ! empty($query_params['order'])) {
2689 2689
 			$pk_field = $this->get_primary_key_field();
2690 2690
 			$order = $this->_extract_order($query_params['order']);
2691 2691
 			$query_object->set_order_by_sql(" ORDER BY ".$pk_field->get_qualified_column().SP.$order);
2692 2692
 		}
2693 2693
 
2694 2694
 		//set group by
2695
-		if(array_key_exists('group_by',$query_params)){
2696
-			if(is_array($query_params['group_by'])){
2695
+		if (array_key_exists('group_by', $query_params)) {
2696
+			if (is_array($query_params['group_by'])) {
2697 2697
 				//it's an array, so assume we'll be grouping by a bunch of stuff
2698 2698
 				$group_by_array = array();
2699
-				foreach($query_params['group_by'] as $field_name_to_group_by){
2699
+				foreach ($query_params['group_by'] as $field_name_to_group_by) {
2700 2700
 					$group_by_array[] = $this->_deduce_column_name_from_query_param($field_name_to_group_by);
2701 2701
 				}
2702
-				$query_object->set_group_by_sql(" GROUP BY ".implode(", ",$group_by_array));
2703
-			}elseif( ! empty ( $query_params['group_by'] )){
2702
+				$query_object->set_group_by_sql(" GROUP BY ".implode(", ", $group_by_array));
2703
+			}elseif ( ! empty ($query_params['group_by'])) {
2704 2704
 				$query_object->set_group_by_sql(" GROUP BY ".$this->_deduce_column_name_from_query_param($query_params['group_by']));
2705 2705
 			}
2706 2706
 		}
2707 2707
 		//set having
2708
-		if(array_key_exists('having',$query_params) && $query_params['having']){
2709
-			$query_object->set_having_sql( $this->_construct_having_clause($query_params['having']));
2708
+		if (array_key_exists('having', $query_params) && $query_params['having']) {
2709
+			$query_object->set_having_sql($this->_construct_having_clause($query_params['having']));
2710 2710
 		}
2711 2711
 
2712 2712
 		//now, just verify they didn't pass anything wack
2713
-		foreach($query_params as $query_key => $query_value){
2714
-			if( ! in_array($query_key,$this->_allowed_query_params,true)){
2713
+		foreach ($query_params as $query_key => $query_value) {
2714
+			if ( ! in_array($query_key, $this->_allowed_query_params, true)) {
2715 2715
 				throw new EE_Error(
2716 2716
 					sprintf(
2717
-						__("You passed %s as a query parameter to %s, which is illegal! The allowed query parameters are %s",'event_espresso'),
2717
+						__("You passed %s as a query parameter to %s, which is illegal! The allowed query parameters are %s", 'event_espresso'),
2718 2718
 						$query_key,
2719 2719
 						get_class($this),
2720 2720
 //						print_r( $this->_allowed_query_params, TRUE )
2721
-						implode( ',', $this->_allowed_query_params )
2721
+						implode(',', $this->_allowed_query_params)
2722 2722
 					)
2723 2723
 				);
2724 2724
 			}
2725 2725
 		}
2726 2726
 		$main_model_join_sql = $query_object->get_main_model_join_sql();
2727
-		if ( empty( $main_model_join_sql ) )
2727
+		if (empty($main_model_join_sql))
2728 2728
 			$query_object->set_main_model_join_sql($this->_construct_internal_join());
2729 2729
 		return $query_object;
2730 2730
 	}
@@ -2735,17 +2735,17 @@  discard block
 block discarded – undo
2735 2735
 	 * @param string $context one of EEM_Base::valid_cap_contexts()
2736 2736
 	 * @return array like EEM_Base::get_all() 's $query_params[0]
2737 2737
 	 */
2738
-	public function caps_where_conditions( $context = self::caps_read ) {
2739
-		EEM_Base::verify_is_valid_cap_context( $context );
2738
+	public function caps_where_conditions($context = self::caps_read) {
2739
+		EEM_Base::verify_is_valid_cap_context($context);
2740 2740
 		$cap_where_conditions = array();
2741
-		$cap_restrictions = $this->caps_missing( $context );
2741
+		$cap_restrictions = $this->caps_missing($context);
2742 2742
 		/**
2743 2743
 		 * @var $cap_restrictions EE_Default_Where_Conditions[]
2744 2744
 		 */
2745
-		foreach( $cap_restrictions as $cap => $restriction_if_no_cap ) {
2746
-				$cap_where_conditions = array_replace_recursive( $cap_where_conditions, $restriction_if_no_cap->get_default_where_conditions() );
2745
+		foreach ($cap_restrictions as $cap => $restriction_if_no_cap) {
2746
+				$cap_where_conditions = array_replace_recursive($cap_where_conditions, $restriction_if_no_cap->get_default_where_conditions());
2747 2747
 		}
2748
-		return apply_filters( 'FHEE__EEM_Base__caps_where_conditions__return', $cap_where_conditions, $this, $context, $cap_restrictions );
2748
+		return apply_filters('FHEE__EEM_Base__caps_where_conditions__return', $cap_where_conditions, $this, $context, $cap_restrictions);
2749 2749
 	}
2750 2750
 
2751 2751
 	/**
@@ -2755,11 +2755,11 @@  discard block
 block discarded – undo
2755 2755
 	 * @return string either ASC, asc, DESC or desc
2756 2756
 	 * @throws EE_Error
2757 2757
 	 */
2758
-	private function _extract_order($should_be_order_string){
2759
-		if(in_array($should_be_order_string, $this->_allowed_order_values)){
2758
+	private function _extract_order($should_be_order_string) {
2759
+		if (in_array($should_be_order_string, $this->_allowed_order_values)) {
2760 2760
 			return $should_be_order_string;
2761
-		}else{
2762
-			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));
2761
+		} else {
2762
+			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 2763
 		}
2764 2764
 	}
2765 2765
 
@@ -2777,7 +2777,7 @@  discard block
 block discarded – undo
2777 2777
 	 * @throws EE_Error
2778 2778
 	 * @return array like $query_params[0], see EEM_Base::get_all for documentation
2779 2779
 	 */
2780
-	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()){
2780
+	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()) {
2781 2781
 		$allowed_used_default_where_conditions_values = array(
2782 2782
 				'all',
2783 2783
 				'this_model_only', 
@@ -2785,19 +2785,19 @@  discard block
 block discarded – undo
2785 2785
 				'minimum',
2786 2786
 				'none'
2787 2787
 			);
2788
-		if( ! in_array($use_default_where_conditions,$allowed_used_default_where_conditions_values)){
2789
-			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)));
2788
+		if ( ! in_array($use_default_where_conditions, $allowed_used_default_where_conditions_values)) {
2789
+			throw new EE_Error(sprintf(__("You passed an invalid value to the query parameter 'default_where_conditions' of '%s'. Allowed values are %s", "event_espresso"), $use_default_where_conditions, implode(", ", $allowed_used_default_where_conditions_values)));
2790 2790
 		}
2791
-		if( in_array($use_default_where_conditions, array('all','this_model_only')) ){
2791
+		if (in_array($use_default_where_conditions, array('all', 'this_model_only'))) {
2792 2792
 			$universal_query_params = $this->_get_default_where_conditions();
2793
-		}elseif( in_array( $use_default_where_conditions, array( 'minimum' ) ) ) {
2793
+		}elseif (in_array($use_default_where_conditions, array('minimum'))) {
2794 2794
 			$universal_query_params = $this->_get_minimum_where_conditions();
2795
-		}else{
2795
+		} else {
2796 2796
 			$universal_query_params = array();
2797 2797
 		}
2798 2798
 
2799
-		if(in_array($use_default_where_conditions,array('all','other_models_only'))){
2800
-			foreach($query_info_carrier->get_model_names_included() as $model_relation_path => $model_name){
2799
+		if (in_array($use_default_where_conditions, array('all', 'other_models_only'))) {
2800
+			foreach ($query_info_carrier->get_model_names_included() as $model_relation_path => $model_name) {
2801 2801
 				$related_model = $this->get_related_model_obj($model_name);
2802 2802
 				$related_model_universal_where_params = $related_model->_get_default_where_conditions($model_relation_path);
2803 2803
 
@@ -2824,22 +2824,22 @@  discard block
 block discarded – undo
2824 2824
 	 * @param string $model_relation_path like 'Transaction.Payment.'
2825 2825
 	 * @return array like EEM_Base::get_all's $query_params[0]
2826 2826
 	 */
2827
-	private function _override_defaults_or_make_null_friendly($default_where_conditions,$provided_where_conditions,$model,$model_relation_path){
2827
+	private function _override_defaults_or_make_null_friendly($default_where_conditions, $provided_where_conditions, $model, $model_relation_path) {
2828 2828
 		$null_friendly_where_conditions = array();
2829 2829
 		$none_overridden = true;
2830 2830
 		$or_condition_key_for_defaults = 'OR*'.get_class($model);
2831 2831
 
2832
-		foreach($default_where_conditions as $key => $val){
2833
-			if( isset($provided_where_conditions[$key])){
2832
+		foreach ($default_where_conditions as $key => $val) {
2833
+			if (isset($provided_where_conditions[$key])) {
2834 2834
 				$none_overridden = false;
2835
-			}else{
2835
+			} else {
2836 2836
 				$null_friendly_where_conditions[$or_condition_key_for_defaults]['AND'][$key] = $val;
2837 2837
 			}
2838 2838
 		}
2839
-		if( $none_overridden && $default_where_conditions){
2840
-			if($model->has_primary_key_field()){
2839
+		if ($none_overridden && $default_where_conditions) {
2840
+			if ($model->has_primary_key_field()) {
2841 2841
 				$null_friendly_where_conditions[$or_condition_key_for_defaults][$model_relation_path.".".$model->primary_key_name()] = array('IS NULL');
2842
-			}else{
2842
+			} else {
2843 2843
 				//@todo NO PK, use other defaults
2844 2844
 			}
2845 2845
 		}
@@ -2854,8 +2854,8 @@  discard block
 block discarded – undo
2854 2854
 	 * @param string $model_relation_path eg, path from Event to Payment is "Registration.Transaction.Payment."
2855 2855
 	 * @return array like EEM_Base::get_all's $query_params[0] (where conditions)
2856 2856
 	 */
2857
-	private function _get_default_where_conditions($model_relation_path = null){
2858
-		if ( $this->_ignore_where_strategy )
2857
+	private function _get_default_where_conditions($model_relation_path = null) {
2858
+		if ($this->_ignore_where_strategy)
2859 2859
 			return array();
2860 2860
 
2861 2861
 		return $this->_default_where_conditions_strategy->get_default_where_conditions($model_relation_path);
@@ -2869,8 +2869,8 @@  discard block
 block discarded – undo
2869 2869
 	 * @param string $model_relation_path eg, path from Event to Payment is "Registration.Transaction.Payment."
2870 2870
 	 * @return array like EEM_Base::get_all's $query_params[0] (where conditions)
2871 2871
 	 */
2872
-	protected function _get_minimum_where_conditions($model_relation_path = null){
2873
-		if ( $this->_ignore_where_strategy )
2872
+	protected function _get_minimum_where_conditions($model_relation_path = null) {
2873
+		if ($this->_ignore_where_strategy)
2874 2874
 			return array();
2875 2875
 
2876 2876
 		return $this->_minimum_where_conditions_strategy->get_default_where_conditions($model_relation_path);
@@ -2881,13 +2881,13 @@  discard block
 block discarded – undo
2881 2881
 	 * @param EE_Model_Query_Info_Carrier $model_query_info
2882 2882
 	 * @return string
2883 2883
 	 */
2884
-	private function _construct_default_select_sql(EE_Model_Query_Info_Carrier $model_query_info){
2884
+	private function _construct_default_select_sql(EE_Model_Query_Info_Carrier $model_query_info) {
2885 2885
 		$selects = $this->_get_columns_to_select_for_this_model();
2886
-		foreach($model_query_info->get_model_names_included() as $model_relation_chain => $name_of_other_model_included){
2886
+		foreach ($model_query_info->get_model_names_included() as $model_relation_chain => $name_of_other_model_included) {
2887 2887
 			$other_model_included = $this->get_related_model_obj($name_of_other_model_included);
2888 2888
 			$selects = array_merge($selects, $other_model_included->_get_columns_to_select_for_this_model($model_relation_chain));
2889 2889
 		}
2890
-		return implode(", ",$selects);
2890
+		return implode(", ", $selects);
2891 2891
 	}
2892 2892
 
2893 2893
 	/**
@@ -2896,19 +2896,19 @@  discard block
 block discarded – undo
2896 2896
 	 * @param string $model_relation_chain like 'Question.Question_Group.Event'
2897 2897
 	 * @return array numerically indexed, values are columns to select and rename, eg "Event.ID AS 'Event.ID'"
2898 2898
 	 */
2899
-	public function _get_columns_to_select_for_this_model($model_relation_chain = ''){
2899
+	public function _get_columns_to_select_for_this_model($model_relation_chain = '') {
2900 2900
 		$fields = $this->field_settings();
2901 2901
 		$selects = array();
2902 2902
 		$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());
2903
-		foreach($fields as $field_obj){
2904
-			$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()."'";
2903
+		foreach ($fields as $field_obj) {
2904
+			$selects[] = $table_alias_with_model_relation_chain_prefix.$field_obj->get_table_alias().".".$field_obj->get_table_column()." AS '".$table_alias_with_model_relation_chain_prefix.$field_obj->get_table_alias().".".$field_obj->get_table_column()."'";
2905 2905
 		}
2906 2906
 		//make sure we are also getting the PKs of each table
2907 2907
 		$tables = $this->get_tables();
2908
-		if(count($tables) > 1){
2909
-			foreach($tables as $table_obj){
2910
-				$qualified_pk_column = $table_alias_with_model_relation_chain_prefix . $table_obj->get_fully_qualified_pk_column();
2911
-				if( ! in_array($qualified_pk_column,$selects)){
2908
+		if (count($tables) > 1) {
2909
+			foreach ($tables as $table_obj) {
2910
+				$qualified_pk_column = $table_alias_with_model_relation_chain_prefix.$table_obj->get_fully_qualified_pk_column();
2911
+				if ( ! in_array($qualified_pk_column, $selects)) {
2912 2912
 					$selects[] = "$qualified_pk_column AS '$qualified_pk_column'";
2913 2913
 				}
2914 2914
 			}
@@ -2932,66 +2932,66 @@  discard block
 block discarded – undo
2932 2932
 	 * @throws EE_Error
2933 2933
 	 * @return void only modifies the EEM_Related_Model_Info_Carrier passed into it
2934 2934
 	 */
2935
-	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 ){
2936
-		if($original_query_param == NULL){
2935
+	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) {
2936
+		if ($original_query_param == NULL) {
2937 2937
 			$original_query_param = $query_param;
2938 2938
 		}
2939 2939
 		$query_param = $this->_remove_stars_and_anything_after_from_condition_query_param_key($query_param);
2940 2940
 		/** @var $allow_logic_query_params bool whether or not to allow logic_query_params like 'NOT','OR', or 'AND' */
2941
-		$allow_logic_query_params = in_array($query_param_type,array('where','having'));
2942
-		$allow_fields = in_array($query_param_type,array('where','having','order_by','group_by','order'));
2941
+		$allow_logic_query_params = in_array($query_param_type, array('where', 'having'));
2942
+		$allow_fields = in_array($query_param_type, array('where', 'having', 'order_by', 'group_by', 'order'));
2943 2943
 		//check to see if we have a field on this model
2944 2944
 		$this_model_fields = $this->field_settings(true);
2945
-		if(array_key_exists($query_param,$this_model_fields)){
2946
-			if($allow_fields){
2945
+		if (array_key_exists($query_param, $this_model_fields)) {
2946
+			if ($allow_fields) {
2947 2947
 				return;
2948
-			}else{
2948
+			} else {
2949 2949
 				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
-						$query_param,get_class($this),$query_param_type,$original_query_param));
2950
+						$query_param, get_class($this), $query_param_type, $original_query_param));
2951 2951
 			}
2952 2952
 		}
2953 2953
 		//check if this is a special logic query param
2954
-		elseif(in_array($query_param, $this->_logic_query_param_keys, TRUE)){
2955
-			if($allow_logic_query_params){
2954
+		elseif (in_array($query_param, $this->_logic_query_param_keys, TRUE)) {
2955
+			if ($allow_logic_query_params) {
2956 2956
 				return;
2957
-			}else{
2957
+			} else {
2958 2958
 				throw new EE_Error(
2959 2959
 					sprintf(
2960
-						__( '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' ),
2961
-						implode( '", "', $this->_logic_query_param_keys ),
2962
-						$query_param ,
2963
-						get_class( $this ),
2960
+						__('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'),
2961
+						implode('", "', $this->_logic_query_param_keys),
2962
+						$query_param,
2963
+						get_class($this),
2964 2964
 						'<br />',
2965
-						"\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
2965
+						"\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
2966 2966
 					)
2967 2967
 				);
2968 2968
 			}
2969 2969
 		}
2970 2970
 
2971 2971
 		//check if it's a custom selection
2972
-		elseif(array_key_exists($query_param,$this->_custom_selections)){
2972
+		elseif (array_key_exists($query_param, $this->_custom_selections)) {
2973 2973
 			return;
2974 2974
 		}
2975 2975
 
2976 2976
 		//check if has a model name at the beginning
2977 2977
 		//and
2978 2978
 		//check if it's a field on a related model
2979
-		foreach($this->_model_relations as $valid_related_model_name=>$relation_obj){
2980
-			if(strpos($query_param, $valid_related_model_name.".") === 0){
2981
-				$this->_add_join_to_model($valid_related_model_name, $passed_in_query_info,$original_query_param);
2979
+		foreach ($this->_model_relations as $valid_related_model_name=>$relation_obj) {
2980
+			if (strpos($query_param, $valid_related_model_name.".") === 0) {
2981
+				$this->_add_join_to_model($valid_related_model_name, $passed_in_query_info, $original_query_param);
2982 2982
 				$query_param = substr($query_param, strlen($valid_related_model_name."."));
2983
-				if($query_param == ''){
2983
+				if ($query_param == '') {
2984 2984
 					//nothing left to $query_param
2985 2985
 					//we should actually end in a field name, not a model like this!
2986 2986
 					throw new EE_Error(sprintf(__("Query param '%s' (of type %s on model %s) shouldn't end on a period (.) ", "event_espresso"),
2987
-					$query_param,$query_param_type,get_class($this),$valid_related_model_name));
2988
-				}else{
2987
+					$query_param, $query_param_type, get_class($this), $valid_related_model_name));
2988
+				} else {
2989 2989
 					$related_model_obj = $this->get_related_model_obj($valid_related_model_name);
2990 2990
 					$related_model_obj->_extract_related_model_info_from_query_param($query_param, $passed_in_query_info, $query_param_type, $original_query_param);
2991 2991
 					return;
2992 2992
 				}
2993
-			}elseif($query_param == $valid_related_model_name){
2994
-				$this->_add_join_to_model($valid_related_model_name, $passed_in_query_info,$original_query_param);
2993
+			}elseif ($query_param == $valid_related_model_name) {
2994
+				$this->_add_join_to_model($valid_related_model_name, $passed_in_query_info, $original_query_param);
2995 2995
 				return;
2996 2996
 			}
2997 2997
 		}
@@ -3001,7 +3001,7 @@  discard block
 block discarded – undo
3001 3001
 		//and we previously confirmed it wasn't a logic query param or field on the current model
3002 3002
 		//it's wack, that's what it is
3003 3003
 		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"),
3004
-				$query_param,get_class($this),$query_param_type,$original_query_param));
3004
+				$query_param, get_class($this), $query_param_type, $original_query_param));
3005 3005
 
3006 3006
 	}
3007 3007
 
@@ -3018,26 +3018,26 @@  discard block
 block discarded – undo
3018 3018
 	 * 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)
3019 3019
 	 * @return void
3020 3020
 	 */
3021
-	private function _add_join_to_model($model_name, EE_Model_Query_Info_Carrier $passed_in_query_info,$original_query_param){
3021
+	private function _add_join_to_model($model_name, EE_Model_Query_Info_Carrier $passed_in_query_info, $original_query_param) {
3022 3022
 		$relation_obj = $this->related_settings_for($model_name);
3023 3023
 
3024 3024
 		$model_relation_chain = EE_Model_Parser::extract_model_relation_chain($model_name, $original_query_param);
3025 3025
 		//check if the relation is HABTM, because then we're essentially doing two joins
3026 3026
 		//If so, join first to the JOIN table, and add its data types, and then continue as normal
3027
-		if($relation_obj instanceof EE_HABTM_Relation){
3027
+		if ($relation_obj instanceof EE_HABTM_Relation) {
3028 3028
 			$join_model_obj = $relation_obj->get_join_model();
3029 3029
 			//replace the model specified with the join model for this relation chain, whi
3030 3030
 			$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);
3031 3031
 			$new_query_info = new EE_Model_Query_Info_Carrier(
3032 3032
 					array($relation_chain_to_join_model => $join_model_obj->get_this_model_name()),
3033 3033
 					$relation_obj->get_join_to_intermediate_model_statement($relation_chain_to_join_model));
3034
-			$passed_in_query_info->merge( $new_query_info  );
3034
+			$passed_in_query_info->merge($new_query_info);
3035 3035
 		}
3036 3036
 		//now just join to the other table pointed to by the relation object, and add its data types
3037 3037
 		$new_query_info = new EE_Model_Query_Info_Carrier(
3038 3038
 				array($model_relation_chain=>$model_name),
3039 3039
 				$relation_obj->get_join_statement($model_relation_chain));
3040
-		$passed_in_query_info->merge( $new_query_info  );
3040
+		$passed_in_query_info->merge($new_query_info);
3041 3041
 	}
3042 3042
 
3043 3043
 
@@ -3046,11 +3046,11 @@  discard block
 block discarded – undo
3046 3046
 	 * @param array $where_params like EEM_Base::get_all
3047 3047
 	 * @return string of SQL
3048 3048
 	 */
3049
-	private function _construct_where_clause($where_params){
3049
+	private function _construct_where_clause($where_params) {
3050 3050
 		$SQL = $this->_construct_condition_clause_recursive($where_params, ' AND ');
3051
-		if($SQL){
3052
-			return " WHERE ". $SQL;
3053
-		}else{
3051
+		if ($SQL) {
3052
+			return " WHERE ".$SQL;
3053
+		} else {
3054 3054
 			return '';
3055 3055
 		}
3056 3056
 	}
@@ -3061,11 +3061,11 @@  discard block
 block discarded – undo
3061 3061
 	 * @param array $having_params
3062 3062
 	 * @return string
3063 3063
 	 */
3064
-	private function _construct_having_clause($having_params){
3064
+	private function _construct_having_clause($having_params) {
3065 3065
 		$SQL = $this->_construct_condition_clause_recursive($having_params, ' AND ');
3066
-		if($SQL){
3067
-			return " HAVING ". $SQL;
3068
-		}else{
3066
+		if ($SQL) {
3067
+			return " HAVING ".$SQL;
3068
+		} else {
3069 3069
 			return '';
3070 3070
 		}
3071 3071
 
@@ -3079,17 +3079,17 @@  discard block
 block discarded – undo
3079 3079
 	 * @return EE_Model_Field_Base
3080 3080
 	 * @throws EE_Error
3081 3081
 	 */
3082
-	protected function _get_field_on_model($field_name,$model_name){
3082
+	protected function _get_field_on_model($field_name, $model_name) {
3083 3083
 		$model_class = 'EEM_'.$model_name;
3084 3084
 		$model_filepath = $model_class.".model.php";
3085
-		EE_Registry::instance()->load_helper( 'File' );
3086
-		if ( is_readable($model_filepath)){
3085
+		EE_Registry::instance()->load_helper('File');
3086
+		if (is_readable($model_filepath)) {
3087 3087
 			require_once($model_filepath);
3088
-			$model_instance=call_user_func($model_name."::instance");
3088
+			$model_instance = call_user_func($model_name."::instance");
3089 3089
 			/* @var $model_instance EEM_Base */
3090 3090
 			return $model_instance->field_settings_for($field_name);
3091
-		}else{
3092
-			throw new EE_Error(sprintf(__('No model named %s exists, with classname %s and filepath %s','event_espresso'),$model_name,$model_class,$model_filepath));
3091
+		} else {
3092
+			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 3093
 		}
3094 3094
 	}
3095 3095
 
@@ -3102,43 +3102,43 @@  discard block
 block discarded – undo
3102 3102
 	 * @throws EE_Error
3103 3103
 	 * @return string of SQL
3104 3104
 	 */
3105
-	private function _construct_condition_clause_recursive($where_params, $glue = ' AND'){
3106
-		$where_clauses=array();
3107
-		foreach($where_params as $query_param => $op_and_value_or_sub_condition){
3108
-			$query_param = $this->_remove_stars_and_anything_after_from_condition_query_param_key($query_param);//str_replace("*",'',$query_param);
3109
-			if(in_array($query_param,$this->_logic_query_param_keys)){
3110
-				switch($query_param){
3105
+	private function _construct_condition_clause_recursive($where_params, $glue = ' AND') {
3106
+		$where_clauses = array();
3107
+		foreach ($where_params as $query_param => $op_and_value_or_sub_condition) {
3108
+			$query_param = $this->_remove_stars_and_anything_after_from_condition_query_param_key($query_param); //str_replace("*",'',$query_param);
3109
+			if (in_array($query_param, $this->_logic_query_param_keys)) {
3110
+				switch ($query_param) {
3111 3111
 					case 'not':
3112 3112
 					case 'NOT':
3113
-						$where_clauses[] = "! (". $this->_construct_condition_clause_recursive($op_and_value_or_sub_condition, $glue).")";
3113
+						$where_clauses[] = "! (".$this->_construct_condition_clause_recursive($op_and_value_or_sub_condition, $glue).")";
3114 3114
 						break;
3115 3115
 					case 'and':
3116 3116
 					case 'AND':
3117
-						$where_clauses[] = " (". $this->_construct_condition_clause_recursive($op_and_value_or_sub_condition, ' AND ') .")";
3117
+						$where_clauses[] = " (".$this->_construct_condition_clause_recursive($op_and_value_or_sub_condition, ' AND ').")";
3118 3118
 						break;
3119 3119
 					case 'or':
3120 3120
 					case 'OR':
3121
-						$where_clauses[] = " (". $this->_construct_condition_clause_recursive($op_and_value_or_sub_condition, ' OR ') .")";
3121
+						$where_clauses[] = " (".$this->_construct_condition_clause_recursive($op_and_value_or_sub_condition, ' OR ').")";
3122 3122
 						break;
3123 3123
 				}
3124
-			}else{
3124
+			} else {
3125 3125
 				$field_obj = $this->_deduce_field_from_query_param($query_param);
3126 3126
 
3127 3127
 				//if it's not a normal field, maybe it's a custom selection?
3128
-				if( ! $field_obj){
3129
-					if(isset( $this->_custom_selections[$query_param][1])){
3128
+				if ( ! $field_obj) {
3129
+					if (isset($this->_custom_selections[$query_param][1])) {
3130 3130
 						$field_obj = $this->_custom_selections[$query_param][1];
3131
-					}else{
3132
-						throw new EE_Error(sprintf(__("%s is neither a valid model field name, nor a custom selection", "event_espresso"),$query_param));
3131
+					} else {
3132
+						throw new EE_Error(sprintf(__("%s is neither a valid model field name, nor a custom selection", "event_espresso"), $query_param));
3133 3133
 					}
3134 3134
 				}
3135 3135
 				$op_and_value_sql = $this->_construct_op_and_value($op_and_value_or_sub_condition, $field_obj);
3136
-				$where_clauses[]=$this->_deduce_column_name_from_query_param($query_param).SP.$op_and_value_sql;
3136
+				$where_clauses[] = $this->_deduce_column_name_from_query_param($query_param).SP.$op_and_value_sql;
3137 3137
 			}
3138 3138
 		}
3139
-		if($where_clauses){
3140
-			$SQL = implode($glue,$where_clauses);
3141
-		}else{
3139
+		if ($where_clauses) {
3140
+			$SQL = implode($glue, $where_clauses);
3141
+		} else {
3142 3142
 			$SQL = '';
3143 3143
 		}
3144 3144
 		return $SQL;
@@ -3152,18 +3152,18 @@  discard block
 block discarded – undo
3152 3152
 	 * @throws EE_Error
3153 3153
 	 * @return string table alias and column name for SQL, eg "Transaction.TXN_ID"
3154 3154
 	 */
3155
-	private function _deduce_column_name_from_query_param($query_param){
3155
+	private function _deduce_column_name_from_query_param($query_param) {
3156 3156
 		$field = $this->_deduce_field_from_query_param($query_param);
3157 3157
 
3158
-		if( $field ){
3159
-			$table_alias_prefix = EE_Model_Parser::extract_table_alias_model_relation_chain_from_query_param( $field->get_model_name(), $query_param );
3160
-			return $table_alias_prefix . $field->get_qualified_column();
3161
-		}elseif(array_key_exists($query_param,$this->_custom_selections)){
3158
+		if ($field) {
3159
+			$table_alias_prefix = EE_Model_Parser::extract_table_alias_model_relation_chain_from_query_param($field->get_model_name(), $query_param);
3160
+			return $table_alias_prefix.$field->get_qualified_column();
3161
+		}elseif (array_key_exists($query_param, $this->_custom_selections)) {
3162 3162
 			//maybe it's custom selection item?
3163 3163
 			//if so, just use it as the "column name"
3164 3164
 			return $query_param;
3165
-		}else{
3166
-			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)));
3165
+		} else {
3166
+			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 3167
 		}
3168 3168
 	}
3169 3169
 
@@ -3175,11 +3175,11 @@  discard block
 block discarded – undo
3175 3175
 	 * @param string $condition_query_param_key
3176 3176
 	 * @return string
3177 3177
 	 */
3178
-	private function _remove_stars_and_anything_after_from_condition_query_param_key($condition_query_param_key){
3178
+	private function _remove_stars_and_anything_after_from_condition_query_param_key($condition_query_param_key) {
3179 3179
 		$pos_of_star = strpos($condition_query_param_key, '*');
3180
-		if($pos_of_star === FALSE){
3180
+		if ($pos_of_star === FALSE) {
3181 3181
 			return $condition_query_param_key;
3182
-		}else{
3182
+		} else {
3183 3183
 			$condition_query_param_sans_star = substr($condition_query_param_key, 0, $pos_of_star);
3184 3184
 			return $condition_query_param_sans_star;
3185 3185
 		}
@@ -3194,54 +3194,54 @@  discard block
 block discarded – undo
3194 3194
 	 * @throws EE_Error
3195 3195
 	 * @return string
3196 3196
 	 */
3197
-	private function _construct_op_and_value($op_and_value, $field_obj){
3198
-		if(is_array( $op_and_value )){
3197
+	private function _construct_op_and_value($op_and_value, $field_obj) {
3198
+		if (is_array($op_and_value)) {
3199 3199
 			$operator = isset($op_and_value[0]) ? $this->_prepare_operator_for_sql($op_and_value[0]) : null;
3200
-			if( ! $operator){
3200
+			if ( ! $operator) {
3201 3201
 				$php_array_like_string = array();
3202
-				foreach($op_and_value as $key => $value){
3202
+				foreach ($op_and_value as $key => $value) {
3203 3203
 					$php_array_like_string[] = "$key=>$value";
3204 3204
 				}
3205
-				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)));
3205
+				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 3206
 			}
3207 3207
 			$value = isset($op_and_value[1]) ? $op_and_value[1] : null;
3208
-		}else{
3208
+		} else {
3209 3209
 			$operator = '=';
3210 3210
 			$value = $op_and_value;
3211 3211
 		}
3212 3212
 
3213 3213
 		//check to see if the value is actually another field
3214
-		if(is_array($op_and_value) && isset($op_and_value[2]) && $op_and_value[2] == true){
3214
+		if (is_array($op_and_value) && isset($op_and_value[2]) && $op_and_value[2] == true) {
3215 3215
 			return $operator.SP.$this->_deduce_column_name_from_query_param($value);
3216
-		}elseif(in_array($operator, $this->_in_style_operators) && is_array($value)){
3216
+		}elseif (in_array($operator, $this->_in_style_operators) && is_array($value)) {
3217 3217
 			//in this case, the value should be an array, or at least a comma-separated list
3218 3218
 			//it will need to handle a little differently
3219 3219
 			$cleaned_value = $this->_construct_in_value($value, $field_obj);
3220 3220
 			//note: $cleaned_value has already been run through $wpdb->prepare()
3221 3221
 			return $operator.SP.$cleaned_value;
3222
-		} elseif( in_array( $operator, $this->_between_style_operators ) && is_array( $value ) ) {
3222
+		} elseif (in_array($operator, $this->_between_style_operators) && is_array($value)) {
3223 3223
 			//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" ) );
3226
-			$cleaned_value = $this->_construct_between_value( $value, $field_obj );
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"));
3226
+			$cleaned_value = $this->_construct_between_value($value, $field_obj);
3227 3227
 			return $operator.SP.$cleaned_value;
3228
-		} elseif( in_array( $operator, $this->_null_style_operators ) ) {
3229
-			if($value != NULL){
3230
-				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));
3228
+		} elseif (in_array($operator, $this->_null_style_operators)) {
3229
+			if ($value != NULL) {
3230
+				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 3231
 			}
3232 3232
 			return $operator;
3233
-		}elseif( $operator == 'LIKE' && ! is_array($value)){
3233
+		}elseif ($operator == 'LIKE' && ! is_array($value)) {
3234 3234
 			//if the operator is 'LIKE', we want to allow percent signs (%) and not
3235 3235
 			//remove other junk. So just treat it as a string.
3236 3236
 			return $operator.SP.$this->_wpdb_prepare_using_field($value, '%s');
3237
-		}elseif( ! in_array($operator, $this->_in_style_operators) && ! is_array($value)){
3238
-			return $operator.SP.$this->_wpdb_prepare_using_field($value,$field_obj);
3239
-		}elseif(in_array($operator, $this->_in_style_operators) && ! is_array($value)){
3240
-			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)){
3242
-			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{
3244
-			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)));
3237
+		}elseif ( ! in_array($operator, $this->_in_style_operators) && ! is_array($value)) {
3238
+			return $operator.SP.$this->_wpdb_prepare_using_field($value, $field_obj);
3239
+		}elseif (in_array($operator, $this->_in_style_operators) && ! is_array($value)) {
3240
+			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)) {
3242
+			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 {
3244
+			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 3245
 		}
3246 3246
 	}
3247 3247
 
@@ -3253,12 +3253,12 @@  discard block
 block discarded – undo
3253 3253
 	 * @param EE_Model_Field_Base|string $field_obj if string, it should be the datatype to be used when querying, eg '%s'
3254 3254
 	 * @return string
3255 3255
 	 */
3256
-	function _construct_between_value( $values, $field_obj ) {
3256
+	function _construct_between_value($values, $field_obj) {
3257 3257
 		$cleaned_values = array();
3258
-		foreach ( $values as $value ) {
3259
-			$cleaned_values[] = $this->_wpdb_prepare_using_field($value,$field_obj);
3258
+		foreach ($values as $value) {
3259
+			$cleaned_values[] = $this->_wpdb_prepare_using_field($value, $field_obj);
3260 3260
 		}
3261
-		return  $cleaned_values[0] . " AND " . $cleaned_values[1];
3261
+		return  $cleaned_values[0]." AND ".$cleaned_values[1];
3262 3262
 	}
3263 3263
 
3264 3264
 
@@ -3274,26 +3274,26 @@  discard block
 block discarded – undo
3274 3274
 	 * @param EE_Model_Field_Base|string $field_obj if string, it should be a wpdb data type like '%s', or '%d'
3275 3275
 	 * @return string of SQL to follow an 'IN' or 'NOT IN' operator
3276 3276
 	 */
3277
-	function _construct_in_value($values,  $field_obj){
3277
+	function _construct_in_value($values, $field_obj) {
3278 3278
 		//check if the value is a CSV list
3279
-		if(is_string($values)){
3279
+		if (is_string($values)) {
3280 3280
 			//in which case, turn it into an array
3281
-			$values = explode(",",$values);
3281
+			$values = explode(",", $values);
3282 3282
 		}
3283 3283
 		$cleaned_values = array();
3284
-		foreach($values as $value){
3285
-			$cleaned_values[] = $this->_wpdb_prepare_using_field($value,$field_obj);
3284
+		foreach ($values as $value) {
3285
+			$cleaned_values[] = $this->_wpdb_prepare_using_field($value, $field_obj);
3286 3286
 		}
3287 3287
 		//we would just LOVE to leave $cleaned_values as an empty array, and return the value as "()",
3288 3288
 		//but unfortunately that's invalid SQL. So instead we return a string which we KNOW will evaluate to be the empty set
3289 3289
 		//which is effectively equivalent to returning "()". We don't return "(0)" because that only works for auto-incrementing columns
3290
-		if(empty($cleaned_values)){
3290
+		if (empty($cleaned_values)) {
3291 3291
 			$all_fields = $this->field_settings();
3292 3292
 			$a_field = array_shift($all_fields);
3293 3293
 			$main_table = $this->_get_main_table();
3294 3294
 			$cleaned_values[] = "SELECT ".$a_field->get_table_column()." FROM ".$main_table->get_table_name()." WHERE FALSE";
3295 3295
 		}
3296
-		return "(".implode(",",$cleaned_values).")";
3296
+		return "(".implode(",", $cleaned_values).")";
3297 3297
 	}
3298 3298
 
3299 3299
 
@@ -3305,16 +3305,16 @@  discard block
 block discarded – undo
3305 3305
 	 * @throws EE_Error
3306 3306
 	 * @return false|null|string
3307 3307
 	 */
3308
-	private function _wpdb_prepare_using_field($value,$field_obj){
3308
+	private function _wpdb_prepare_using_field($value, $field_obj) {
3309 3309
 		/** @type WPDB $wpdb */
3310 3310
 		global $wpdb;
3311
-		if($field_obj instanceof EE_Model_Field_Base){
3312
-			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
3314
-			if( ! in_array($field_obj,$this->_valid_wpdb_data_types)){
3315
-				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)));
3311
+		if ($field_obj instanceof EE_Model_Field_Base) {
3312
+			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
3314
+			if ( ! in_array($field_obj, $this->_valid_wpdb_data_types)) {
3315
+				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 3316
 			}
3317
-			return $wpdb->prepare($field_obj,$value);
3317
+			return $wpdb->prepare($field_obj, $value);
3318 3318
 		}
3319 3319
 	}
3320 3320
 
@@ -3326,27 +3326,27 @@  discard block
 block discarded – undo
3326 3326
 	 * @throws EE_Error
3327 3327
 	 * @return EE_Model_Field_Base
3328 3328
 	 */
3329
-	protected function _deduce_field_from_query_param($query_param_name){
3329
+	protected function _deduce_field_from_query_param($query_param_name) {
3330 3330
 		//ok, now proceed with deducing which part is the model's name, and which is the field's name
3331 3331
 		//which will help us find the database table and column
3332 3332
 
3333
-		$query_param_parts = explode(".",$query_param_name);
3334
-		if(empty($query_param_parts)){
3335
-			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));
3333
+		$query_param_parts = explode(".", $query_param_name);
3334
+		if (empty($query_param_parts)) {
3335
+			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));
3336 3336
 		}
3337 3337
 		$number_of_parts = count($query_param_parts);
3338
-		$last_query_param_part = $query_param_parts[ count($query_param_parts) - 1 ];
3339
-		if($number_of_parts == 1){
3338
+		$last_query_param_part = $query_param_parts[count($query_param_parts) - 1];
3339
+		if ($number_of_parts == 1) {
3340 3340
 			$field_name = $last_query_param_part;
3341 3341
 			$model_obj = $this;
3342
-		}else{// $number_of_parts >= 2
3342
+		} else {// $number_of_parts >= 2
3343 3343
 			//the last part is the column name, and there are only 2parts. therefore...
3344 3344
 			$field_name = $last_query_param_part;
3345
-			$model_obj = $this->get_related_model_obj( $query_param_parts[ $number_of_parts - 2 ]);
3345
+			$model_obj = $this->get_related_model_obj($query_param_parts[$number_of_parts - 2]);
3346 3346
 		}
3347
-		try{
3347
+		try {
3348 3348
 			return $model_obj->field_settings_for($field_name);
3349
-		}catch(EE_Error $e){
3349
+		} catch (EE_Error $e) {
3350 3350
 			return null;
3351 3351
 		}
3352 3352
 	}
@@ -3360,13 +3360,13 @@  discard block
 block discarded – undo
3360 3360
 	 * @throws EE_Error
3361 3361
 	 * @return string
3362 3362
 	 */
3363
-	function _get_qualified_column_for_field($field_name){
3363
+	function _get_qualified_column_for_field($field_name) {
3364 3364
 		$all_fields = $this->field_settings();
3365 3365
 		$field = isset($all_fields[$field_name]) ? $all_fields[$field_name] : FALSE;
3366
-		if($field){
3366
+		if ($field) {
3367 3367
 			return $field->get_qualified_column();
3368
-		}else{
3369
-			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)));
3368
+		} else {
3369
+			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 3370
 		}
3371 3371
 	}
3372 3372
 
@@ -3380,14 +3380,14 @@  discard block
 block discarded – undo
3380 3380
 	 * @param  mixed|string $limit The limit for this select
3381 3381
 	 * @return string 				The final select join element for the query.
3382 3382
 	 */
3383
-	function _construct_limit_join_select( $table_alias, $limit ) {
3383
+	function _construct_limit_join_select($table_alias, $limit) {
3384 3384
 		$SQL = '';
3385 3385
 
3386
-		foreach ( $this->_tables as $table_obj ) {
3387
-			if ( $table_obj instanceof EE_Primary_Table ) {
3388
-				$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;
3389
-			} elseif ( $table_obj instanceof EE_Secondary_Table ) {
3390
-				$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;
3386
+		foreach ($this->_tables as $table_obj) {
3387
+			if ($table_obj instanceof EE_Primary_Table) {
3388
+				$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;
3389
+			} elseif ($table_obj instanceof EE_Secondary_Table) {
3390
+				$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;
3391 3391
 			}
3392 3392
 		}
3393 3393
 		return $SQL;
@@ -3400,7 +3400,7 @@  discard block
 block discarded – undo
3400 3400
 	 * Eg "wp_post AS Event" or "wp_post AS Event INNER JOIN wp_postmeta Event_Meta ON Event.ID = Event_Meta.post_id"
3401 3401
 	 * @return string SQL
3402 3402
 	 */
3403
-	function _construct_internal_join(){
3403
+	function _construct_internal_join() {
3404 3404
 		$SQL = $this->_get_main_table()->get_table_sql();
3405 3405
 		$SQL .= $this->_construct_internal_join_to_table_with_alias($this->_get_main_table()->get_table_alias());
3406 3406
 		return $SQL;
@@ -3421,17 +3421,17 @@  discard block
 block discarded – undo
3421 3421
 	 * @param string $alias_prefixed table alias to join to (this table should already be in the FROM SQL clause)
3422 3422
 	 * @return string
3423 3423
 	 */
3424
-	function _construct_internal_join_to_table_with_alias($alias_prefixed){
3424
+	function _construct_internal_join_to_table_with_alias($alias_prefixed) {
3425 3425
 		$SQL = '';
3426 3426
 		$alias_sans_prefix = EE_Model_Parser::remove_table_alias_model_relation_chain_prefix($alias_prefixed);
3427
-		foreach($this->_tables as $table_obj){
3428
-			if($table_obj instanceof EE_Secondary_Table){//table is secondary table
3429
-				if($alias_sans_prefix == $table_obj->get_table_alias()){
3427
+		foreach ($this->_tables as $table_obj) {
3428
+			if ($table_obj instanceof EE_Secondary_Table) {//table is secondary table
3429
+				if ($alias_sans_prefix == $table_obj->get_table_alias()) {
3430 3430
 					//so we're joining to this table, meaning the table is already in
3431 3431
 					//the FROM statement, BUT the primary table isn't. So we want
3432 3432
 					//to add the inverse join sql
3433 3433
 					$SQL .= $table_obj->get_inverse_join_sql($alias_prefixed);
3434
-				}else{
3434
+				} else {
3435 3435
 					//just add a regular JOIN to this table from the primary table
3436 3436
 					$SQL .= $table_obj->get_join_sql($alias_prefixed);
3437 3437
 				}
@@ -3445,9 +3445,9 @@  discard block
 block discarded – undo
3445 3445
 	 * 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)
3446 3446
 	 * @return array
3447 3447
 	 */
3448
-	function _get_data_types(){
3448
+	function _get_data_types() {
3449 3449
 		$data_types = array();
3450
-		foreach(array_values($this->field_settings()) as $field_obj){
3450
+		foreach (array_values($this->field_settings()) as $field_obj) {
3451 3451
 			//$data_types[$field_obj->get_table_column()] = $field_obj->get_wpdb_data_type();
3452 3452
 			/** @var $field_obj EE_Model_Field_Base */
3453 3453
 			$data_types[$field_obj->get_qualified_column()] = $field_obj->get_wpdb_data_type();
@@ -3463,11 +3463,11 @@  discard block
 block discarded – undo
3463 3463
 	 * @throws EE_Error
3464 3464
 	 * @return EEM_Base
3465 3465
 	 */
3466
-	function get_related_model_obj($model_name){
3466
+	function get_related_model_obj($model_name) {
3467 3467
 
3468 3468
 		$model_classname = "EEM_".$model_name;
3469
-		if(!class_exists($model_classname)){
3470
-			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));
3469
+		if ( ! class_exists($model_classname)) {
3470
+			throw new EE_Error(sprintf(__("You specified a related model named %s in your query. No such model exists, if it did, it would have the classname %s", 'event_espresso'), $model_name, $model_classname));
3471 3471
 		}
3472 3472
 		$model_obj = call_user_func($model_classname."::instance");
3473 3473
 		return $model_obj;
@@ -3478,7 +3478,7 @@  discard block
 block discarded – undo
3478 3478
 	 * Returns the array of EE_ModelRelations for this model.
3479 3479
 	 * @return EE_Model_Relation_Base[]
3480 3480
 	 */
3481
-	public function relation_settings(){
3481
+	public function relation_settings() {
3482 3482
 		return $this->_model_relations;
3483 3483
 	}
3484 3484
 
@@ -3488,10 +3488,10 @@  discard block
 block discarded – undo
3488 3488
 	 * (Eg, without an event, datetimes have little purpose.)
3489 3489
 	 * @return EE_Belongs_To_Relation[]
3490 3490
 	 */
3491
-	public function belongs_to_relations(){
3491
+	public function belongs_to_relations() {
3492 3492
 		$belongs_to_relations = array();
3493
-		foreach($this->relation_settings() as $model_name => $relation_obj){
3494
-			if($relation_obj instanceof EE_Belongs_To_Relation){
3493
+		foreach ($this->relation_settings() as $model_name => $relation_obj) {
3494
+			if ($relation_obj instanceof EE_Belongs_To_Relation) {
3495 3495
 				$belongs_to_relations[$model_name] = $relation_obj;
3496 3496
 			}
3497 3497
 		}
@@ -3506,15 +3506,15 @@  discard block
 block discarded – undo
3506 3506
 	 * @throws EE_Error
3507 3507
 	 * @return EE_Model_Relation_Base
3508 3508
 	 */
3509
-	public function related_settings_for($relation_name){
3510
-		$relatedModels=$this->relation_settings();
3511
-		if(!array_key_exists($relation_name,$relatedModels)){
3509
+	public function related_settings_for($relation_name) {
3510
+		$relatedModels = $this->relation_settings();
3511
+		if ( ! array_key_exists($relation_name, $relatedModels)) {
3512 3512
 			throw new EE_Error(
3513 3513
 				sprintf(
3514
-					__('Cannot get %s related to %s. There is no model relation of that type. There is, however, %s...','event_espresso'),
3514
+					__('Cannot get %s related to %s. There is no model relation of that type. There is, however, %s...', 'event_espresso'),
3515 3515
 					$relation_name,
3516 3516
 					$this->_get_class_name(),
3517
-					implode( ', ', array_keys( $relatedModels ))
3517
+					implode(', ', array_keys($relatedModels))
3518 3518
 				)
3519 3519
 			);
3520 3520
 		}
@@ -3529,10 +3529,10 @@  discard block
 block discarded – undo
3529 3529
 	 * @throws EE_Error
3530 3530
 	 * @return EE_Model_Field_Base
3531 3531
 	 */
3532
-	public function field_settings_for($fieldName){
3533
-		$fieldSettings=$this->field_settings(true);
3534
-		if( ! array_key_exists($fieldName,$fieldSettings)){
3535
-			throw new EE_Error(sprintf(__("There is no field/column '%s' on '%s'",'event_espresso'),$fieldName,get_class($this)));
3532
+	public function field_settings_for($fieldName) {
3533
+		$fieldSettings = $this->field_settings(true);
3534
+		if ( ! array_key_exists($fieldName, $fieldSettings)) {
3535
+			throw new EE_Error(sprintf(__("There is no field/column '%s' on '%s'", 'event_espresso'), $fieldName, get_class($this)));
3536 3536
 		}
3537 3537
 		return $fieldSettings[$fieldName];
3538 3538
 	}
@@ -3542,11 +3542,11 @@  discard block
 block discarded – undo
3542 3542
 	 * @param string $fieldName a key in the model's _field_settings array
3543 3543
 	 * @return boolean
3544 3544
 	 */
3545
-	public function has_field($fieldName){
3545
+	public function has_field($fieldName) {
3546 3546
 		$fieldSettings = $this->field_settings(true);
3547
-		if( isset($fieldSettings[$fieldName])){
3547
+		if (isset($fieldSettings[$fieldName])) {
3548 3548
 			return true;
3549
-		}else{
3549
+		} else {
3550 3550
 			return false;
3551 3551
 		}
3552 3552
 	}
@@ -3556,11 +3556,11 @@  discard block
 block discarded – undo
3556 3556
 	 * @param string $relation_name possibly one of the keys in the relation_settings array
3557 3557
 	 * @return boolean
3558 3558
 	 */
3559
-	public function has_relation($relation_name){
3559
+	public function has_relation($relation_name) {
3560 3560
 		$relations = $this->relation_settings();
3561
-		if(isset($relations[$relation_name])){
3561
+		if (isset($relations[$relation_name])) {
3562 3562
 			return true;
3563
-		}else{
3563
+		} else {
3564 3564
 			return false;
3565 3565
 		}
3566 3566
 	}
@@ -3572,7 +3572,7 @@  discard block
 block discarded – undo
3572 3572
 	 * @param $field_obj
3573 3573
 	 * @return EE_Model_Field_Base
3574 3574
 	 */
3575
-	public function is_primary_key_field( $field_obj ){
3575
+	public function is_primary_key_field($field_obj) {
3576 3576
 		return $field_obj instanceof EE_Primary_Key_Field_Base ? TRUE : FALSE;
3577 3577
 	}
3578 3578
 
@@ -3584,16 +3584,16 @@  discard block
 block discarded – undo
3584 3584
 	 * @return EE_Model_Field_Base
3585 3585
 	 * @throws EE_Error
3586 3586
 	 */
3587
-	public function get_primary_key_field(){
3588
-		if( $this->_primary_key_field === NULL ){
3589
-			foreach( $this->field_settings( TRUE ) as $field_obj ){
3590
-				if( $this->is_primary_key_field( $field_obj )){
3587
+	public function get_primary_key_field() {
3588
+		if ($this->_primary_key_field === NULL) {
3589
+			foreach ($this->field_settings(TRUE) as $field_obj) {
3590
+				if ($this->is_primary_key_field($field_obj)) {
3591 3591
 					$this->_primary_key_field = $field_obj;
3592 3592
 					break;
3593 3593
 				}
3594 3594
 			}
3595
-			if( ! $this->_primary_key_field instanceof EE_Primary_Key_Field_Base ){
3596
-				throw new EE_Error(sprintf(__("There is no Primary Key defined on model %s",'event_espresso'),get_class($this)));
3595
+			if ( ! $this->_primary_key_field instanceof EE_Primary_Key_Field_Base) {
3596
+				throw new EE_Error(sprintf(__("There is no Primary Key defined on model %s", 'event_espresso'), get_class($this)));
3597 3597
 			}
3598 3598
 		}
3599 3599
 		return $this->_primary_key_field;
@@ -3606,12 +3606,12 @@  discard block
 block discarded – undo
3606 3606
 	 * Internally does some caching.
3607 3607
 	 * @return boolean
3608 3608
 	 */
3609
-	public function has_primary_key_field(){
3610
-		if($this->_has_primary_key_field === null){
3611
-			try{
3609
+	public function has_primary_key_field() {
3610
+		if ($this->_has_primary_key_field === null) {
3611
+			try {
3612 3612
 				$this->get_primary_key_field();
3613 3613
 				$this->_has_primary_key_field = true;
3614
-			}catch(EE_Error $e){
3614
+			} catch (EE_Error $e) {
3615 3615
 				$this->_has_primary_key_field = false;
3616 3616
 			}
3617 3617
 		}
@@ -3625,9 +3625,9 @@  discard block
 block discarded – undo
3625 3625
 	 * @param string $field_class_name class name of field that you want to find. Eg, EE_Datetime_Field, EE_Foreign_Key_Field, etc
3626 3626
 	 * @return EE_Model_Field_Base or null if none is found
3627 3627
 	 */
3628
-	public function get_a_field_of_type($field_class_name){
3629
-		foreach($this->field_settings() as $field){
3630
-			if( $field instanceof $field_class_name ){
3628
+	public function get_a_field_of_type($field_class_name) {
3629
+		foreach ($this->field_settings() as $field) {
3630
+			if ($field instanceof $field_class_name) {
3631 3631
 				return $field;
3632 3632
 			}
3633 3633
 		}
@@ -3641,21 +3641,21 @@  discard block
 block discarded – undo
3641 3641
 	 * @return EE_Foreign_Key_Field_Base
3642 3642
 	 * @throws EE_Error
3643 3643
 	 */
3644
-	public function get_foreign_key_to($model_name){
3645
-		if( ! isset( $this->_cache_foreign_key_to_fields[ $model_name ] ) ){
3646
-			foreach($this->field_settings() as $field){
3644
+	public function get_foreign_key_to($model_name) {
3645
+		if ( ! isset($this->_cache_foreign_key_to_fields[$model_name])) {
3646
+			foreach ($this->field_settings() as $field) {
3647 3647
 //				if(is_subclass_of($field, 'EE_Foreign_Key_Field_Base')){
3648
-				if( $field instanceof EE_Foreign_Key_Field_Base ){
3649
-					if (in_array($model_name,$field->get_model_names_pointed_to() ) ) {
3650
-						$this->_cache_foreign_key_to_fields[ $model_name ] = $field;
3648
+				if ($field instanceof EE_Foreign_Key_Field_Base) {
3649
+					if (in_array($model_name, $field->get_model_names_pointed_to())) {
3650
+						$this->_cache_foreign_key_to_fields[$model_name] = $field;
3651 3651
 					}
3652 3652
 				}
3653 3653
 			}
3654
-			if( ! isset( $this->_cache_foreign_key_to_fields[ $model_name ] ) ){
3655
-				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)));
3654
+			if ( ! isset($this->_cache_foreign_key_to_fields[$model_name])) {
3655
+				throw new EE_Error(sprintf(__("There is no foreign key field pointing to model %s on model %s", 'event_espresso'), $model_name, get_class($this)));
3656 3656
 			}
3657 3657
 		}
3658
-		return $this->_cache_foreign_key_to_fields[ $model_name ];
3658
+		return $this->_cache_foreign_key_to_fields[$model_name];
3659 3659
 	}
3660 3660
 
3661 3661
 
@@ -3666,7 +3666,7 @@  discard block
 block discarded – undo
3666 3666
 	 * a table alias with a model chain prefix, like 'Venue__Event_Venue___Event_Meta'. Either one works
3667 3667
 	 * @return EE_Table_Base
3668 3668
 	 */
3669
-	function get_table_for_alias($table_alias){
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);
3671 3671
 		return $this->_tables[$table_alias_sans_model_relation_chain_prefix]->get_table_name();
3672 3672
 	}
@@ -3679,25 +3679,25 @@  discard block
 block discarded – undo
3679 3679
 	 * @param bool $include_db_only_fields flag indicating whether or not to include the db-only fields
3680 3680
 	 * @return EE_Model_Field_Base[] where the keys are the field's name
3681 3681
 	 */
3682
-	public function field_settings($include_db_only_fields = false){
3683
-		if( $include_db_only_fields ){
3684
-			if( $this->_cached_fields === NULL ){
3682
+	public function field_settings($include_db_only_fields = false) {
3683
+		if ($include_db_only_fields) {
3684
+			if ($this->_cached_fields === NULL) {
3685 3685
 				$this->_cached_fields = array();
3686
-				foreach($this->_fields as $fields_corresponding_to_table){
3687
-					foreach($fields_corresponding_to_table as $field_name => $field_obj){
3688
-						$this->_cached_fields[$field_name]=$field_obj;
3686
+				foreach ($this->_fields as $fields_corresponding_to_table) {
3687
+					foreach ($fields_corresponding_to_table as $field_name => $field_obj) {
3688
+						$this->_cached_fields[$field_name] = $field_obj;
3689 3689
 					}
3690 3690
 				}
3691 3691
 			}
3692 3692
 			return $this->_cached_fields;
3693
-		}else{
3694
-			if( $this->_cached_fields_non_db_only === NULL ){
3693
+		} else {
3694
+			if ($this->_cached_fields_non_db_only === NULL) {
3695 3695
 				$this->_cached_fields_non_db_only = array();
3696
-				foreach($this->_fields as $fields_corresponding_to_table){
3697
-					foreach($fields_corresponding_to_table as $field_name => $field_obj){
3696
+				foreach ($this->_fields as $fields_corresponding_to_table) {
3697
+					foreach ($fields_corresponding_to_table as $field_name => $field_obj) {
3698 3698
 						/** @var $field_obj EE_Model_Field_Base */
3699
-						if( ! $field_obj->is_db_only_field() ){
3700
-							$this->_cached_fields_non_db_only[$field_name]=$field_obj;
3699
+						if ( ! $field_obj->is_db_only_field()) {
3700
+							$this->_cached_fields_non_db_only[$field_name] = $field_obj;
3701 3701
 						}
3702 3702
 					}
3703 3703
 				}
@@ -3716,67 +3716,67 @@  discard block
 block discarded – undo
3716 3716
 	 * @return \EE_Base_Class[] array keys are primary keys (if there is a primary key on the model. if not, numerically indexed)
3717 3717
 	 * @throws \EE_Error
3718 3718
 	 */
3719
-	protected function _create_objects( $rows = array() ) {
3720
-		$array_of_objects=array();
3721
-		if(empty($rows)){
3719
+	protected function _create_objects($rows = array()) {
3720
+		$array_of_objects = array();
3721
+		if (empty($rows)) {
3722 3722
 			return array();
3723 3723
 		}
3724 3724
 		$count_if_model_has_no_primary_key = 0;
3725 3725
 		$has_primary_key = $this->has_primary_key_field();
3726
-		if( $has_primary_key ) {
3726
+		if ($has_primary_key) {
3727 3727
 			$primary_key_field = $this->get_primary_key_field();
3728 3728
 		} else {
3729 3729
 			$primary_key_field = null;
3730 3730
 		}
3731
-		foreach ( $rows as $row ) {
3732
-			if(empty($row)){
3731
+		foreach ($rows as $row) {
3732
+			if (empty($row)) {
3733 3733
 				//wp did its weird thing where it returns an array like array(0=>null), which is totally not helpful...
3734 3734
 				return array();
3735 3735
 			}
3736 3736
 			//check if we've already set this object in the results array,
3737 3737
 			//in which case there's no need to process it further (again)
3738
-			if( $has_primary_key ) {
3738
+			if ($has_primary_key) {
3739 3739
 				$table_pk_value = $this->_get_column_value_with_table_alias_or_not(
3740 3740
 					$row,
3741 3741
 					$primary_key_field->get_qualified_column(),
3742 3742
 					$primary_key_field->get_table_column()
3743 3743
 				);
3744
-				if( $table_pk_value &&
3745
-					isset( $array_of_objects[ $table_pk_value ] ) ) {
3744
+				if ($table_pk_value &&
3745
+					isset($array_of_objects[$table_pk_value])) {
3746 3746
 					continue;
3747 3747
 				}
3748 3748
 			}
3749
-			$classInstance=$this->instantiate_class_from_array_or_object($row);
3750
-			if( ! $classInstance ) {
3749
+			$classInstance = $this->instantiate_class_from_array_or_object($row);
3750
+			if ( ! $classInstance) {
3751 3751
 				throw new EE_Error(
3752 3752
 					sprintf(
3753
-						__( 'Could not create instance of class %s from row %s', 'event_espresso' ),
3753
+						__('Could not create instance of class %s from row %s', 'event_espresso'),
3754 3754
 						$this->get_this_model_name(),
3755
-						http_build_query( $row )
3755
+						http_build_query($row)
3756 3756
 					)
3757 3757
 				);
3758 3758
 			}
3759 3759
 			//set the timezone on the instantiated objects
3760
-			$classInstance->set_timezone( $this->_timezone );
3760
+			$classInstance->set_timezone($this->_timezone);
3761 3761
 			//make sure if there is any timezone setting present that we set the timezone for the object
3762 3762
 			$key = $has_primary_key ? $classInstance->ID() : $count_if_model_has_no_primary_key++;
3763
-			$array_of_objects[ $key ] = $classInstance;
3763
+			$array_of_objects[$key] = $classInstance;
3764 3764
 			//also, for all the relations of type BelongsTo, see if we can cache
3765 3765
 			//those related models
3766 3766
 			//(we could do this for other relations too, but if there are conditions
3767 3767
 			//that filtered out some fo the results, then we'd be caching an incomplete set
3768 3768
 			//so it requires a little more thought than just caching them immediately...)
3769
-			foreach($this->_model_relations as $modelName => $relation_obj){
3770
-				if( $relation_obj instanceof EE_Belongs_To_Relation){
3769
+			foreach ($this->_model_relations as $modelName => $relation_obj) {
3770
+				if ($relation_obj instanceof EE_Belongs_To_Relation) {
3771 3771
 					//check if this model's INFO is present. If so, cache it on the model
3772 3772
 					$other_model = $relation_obj->get_other_model();
3773 3773
 
3774 3774
 					$other_model_obj_maybe = $other_model->instantiate_class_from_array_or_object($row);
3775 3775
 
3776 3776
 					//if we managed to make a model object from the results, cache it on the main model object
3777
-					if( $other_model_obj_maybe ){
3777
+					if ($other_model_obj_maybe) {
3778 3778
 						//set timezone on these other model objects if they are present
3779
-						$other_model_obj_maybe->set_timezone( $this->_timezone );
3779
+						$other_model_obj_maybe->set_timezone($this->_timezone);
3780 3780
 						$classInstance->cache($modelName, $other_model_obj_maybe);
3781 3781
 					}
3782 3782
 				}
@@ -3797,12 +3797,12 @@  discard block
 block discarded – undo
3797 3797
 
3798 3798
 		$this_model_fields_and_values = array();
3799 3799
 		//setup the row using default values;
3800
-		foreach ( $this->field_settings() as $field_name => $field_obj ) {
3800
+		foreach ($this->field_settings() as $field_name => $field_obj) {
3801 3801
 			$this_model_fields_and_values[$field_name] = $field_obj->get_default_value();
3802 3802
 		}
3803 3803
 
3804 3804
 		$className = $this->_get_class_name();
3805
-		$classInstance = EE_Registry::instance()->load_class( $className, array( $this_model_fields_and_values ), FALSE, FALSE );
3805
+		$classInstance = EE_Registry::instance()->load_class($className, array($this_model_fields_and_values), FALSE, FALSE);
3806 3806
 
3807 3807
 		return $classInstance;
3808 3808
 	}
@@ -3815,45 +3815,45 @@  discard block
 block discarded – undo
3815 3815
 	 * or an stdClass where each property is the name of a column,
3816 3816
 	 * @return EE_Base_Class
3817 3817
 	 */
3818
-	public function instantiate_class_from_array_or_object($cols_n_values){
3819
-		if( ! is_array( $cols_n_values ) && is_object( $cols_n_values )) {
3820
-			$cols_n_values = get_object_vars( $cols_n_values );
3818
+	public function instantiate_class_from_array_or_object($cols_n_values) {
3819
+		if ( ! is_array($cols_n_values) && is_object($cols_n_values)) {
3820
+			$cols_n_values = get_object_vars($cols_n_values);
3821 3821
 		}
3822 3822
 		$primary_key = NULL;
3823 3823
 		//make sure the array only has keys that are fields/columns on this model
3824
-		$this_model_fields_n_values = $this->_deduce_fields_n_values_from_cols_n_values( $cols_n_values );
3825
-		if( $this->has_primary_key_field() && isset( $this_model_fields_n_values[ $this->primary_key_name() ] ) ){
3826
-			$primary_key = $this_model_fields_n_values[ $this->primary_key_name() ];
3824
+		$this_model_fields_n_values = $this->_deduce_fields_n_values_from_cols_n_values($cols_n_values);
3825
+		if ($this->has_primary_key_field() && isset($this_model_fields_n_values[$this->primary_key_name()])) {
3826
+			$primary_key = $this_model_fields_n_values[$this->primary_key_name()];
3827 3827
 		}
3828
-		$className=$this->_get_class_name();
3828
+		$className = $this->_get_class_name();
3829 3829
 
3830 3830
 		//check we actually found results that we can use to build our model object
3831 3831
 		//if not, return null
3832
-		if( $this->has_primary_key_field()){
3833
-			if(empty( $this_model_fields_n_values[$this->primary_key_name()] )){
3832
+		if ($this->has_primary_key_field()) {
3833
+			if (empty($this_model_fields_n_values[$this->primary_key_name()])) {
3834 3834
 				return NULL;
3835 3835
 			}
3836
-		}else if($this->unique_indexes()){
3836
+		} else if ($this->unique_indexes()) {
3837 3837
 			$first_column = reset($this_model_fields_n_values);
3838
-			if(empty($first_column)){
3838
+			if (empty($first_column)) {
3839 3839
 				return NULL;
3840 3840
 			}
3841 3841
 		}
3842 3842
 
3843 3843
 		// if there is no primary key or the object doesn't already exist in the entity map, then create a new instance
3844
-		if ( $primary_key){
3845
-			$classInstance = $this->get_from_entity_map( $primary_key );
3846
-			if( ! $classInstance) {
3847
-				$classInstance = EE_Registry::instance()->load_class( $className, array( $this_model_fields_n_values, $this->_timezone ), TRUE, FALSE );
3844
+		if ($primary_key) {
3845
+			$classInstance = $this->get_from_entity_map($primary_key);
3846
+			if ( ! $classInstance) {
3847
+				$classInstance = EE_Registry::instance()->load_class($className, array($this_model_fields_n_values, $this->_timezone), TRUE, FALSE);
3848 3848
 				// add this new object to the entity map
3849
-				$classInstance = $this->add_to_entity_map( $classInstance );
3849
+				$classInstance = $this->add_to_entity_map($classInstance);
3850 3850
 			}
3851
-		}else{
3852
-			$classInstance = EE_Registry::instance()->load_class( $className, array( $this_model_fields_n_values, $this->_timezone ), TRUE, FALSE );
3851
+		} else {
3852
+			$classInstance = EE_Registry::instance()->load_class($className, array($this_model_fields_n_values, $this->_timezone), TRUE, FALSE);
3853 3853
 		}
3854 3854
 
3855 3855
 			//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.
3856
-		$this->set_timezone( $classInstance->get_timezone() );
3856
+		$this->set_timezone($classInstance->get_timezone());
3857 3857
 		return $classInstance;
3858 3858
 	}
3859 3859
 	/**
@@ -3861,8 +3861,8 @@  discard block
 block discarded – undo
3861 3861
 	 * @param int|string $id the ID of the model object
3862 3862
 	 * @return EE_Base_Class
3863 3863
 	 */
3864
-	public function get_from_entity_map( $id ){
3865
-		return isset( $this->_entity_map[ $id ] ) ? $this->_entity_map[ $id ] : NULL;
3864
+	public function get_from_entity_map($id) {
3865
+		return isset($this->_entity_map[$id]) ? $this->_entity_map[$id] : NULL;
3866 3866
 	}
3867 3867
 
3868 3868
 
@@ -3881,21 +3881,21 @@  discard block
 block discarded – undo
3881 3881
 	 * @throws EE_Error
3882 3882
 	 * @return \EE_Base_Class
3883 3883
 	 */
3884
-	public function add_to_entity_map( EE_Base_Class $object) {
3884
+	public function add_to_entity_map(EE_Base_Class $object) {
3885 3885
 		$className = $this->_get_class_name();
3886
-		if( ! $object instanceof $className ){
3887
-			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 ) );
3886
+		if ( ! $object instanceof $className) {
3887
+			throw new EE_Error(sprintf(__("You tried adding a %s to a mapping of %ss", "event_espresso"), is_object($object) ? get_class($object) : $object, $className));
3888 3888
 		}
3889 3889
 		/** @var $object EE_Base_Class */
3890
-		if ( ! $object->ID() ){
3891
-			throw new EE_Error(sprintf(__("You tried storing a model object with NO ID in the %s entity mapper.", "event_espresso"),get_class($this)));
3890
+		if ( ! $object->ID()) {
3891
+			throw new EE_Error(sprintf(__("You tried storing a model object with NO ID in the %s entity mapper.", "event_espresso"), get_class($this)));
3892 3892
 		}
3893 3893
 		// double check it's not already there
3894
-		$classInstance = $this->get_from_entity_map( $object->ID() );
3895
-		if ( $classInstance ) {
3894
+		$classInstance = $this->get_from_entity_map($object->ID());
3895
+		if ($classInstance) {
3896 3896
 			return $classInstance;
3897 3897
 		} else {
3898
-			$this->_entity_map[ $object->ID() ] = $object;
3898
+			$this->_entity_map[$object->ID()] = $object;
3899 3899
 			return $object;
3900 3900
 		}
3901 3901
 	}
@@ -3908,8 +3908,8 @@  discard block
 block discarded – undo
3908 3908
 	 * @param array $cols_n_values
3909 3909
 	 * @return array
3910 3910
 	 */
3911
-	public function deduce_fields_n_values_from_cols_n_values( $cols_n_values ) {
3912
-		return $this->_deduce_fields_n_values_from_cols_n_values( $cols_n_values );
3911
+	public function deduce_fields_n_values_from_cols_n_values($cols_n_values) {
3912
+		return $this->_deduce_fields_n_values_from_cols_n_values($cols_n_values);
3913 3913
 	}
3914 3914
 
3915 3915
 
@@ -3922,40 +3922,40 @@  discard block
 block discarded – undo
3922 3922
 	 * @param string $cols_n_values
3923 3923
 	 * @return array
3924 3924
 	 */
3925
-	protected function _deduce_fields_n_values_from_cols_n_values( $cols_n_values ){
3925
+	protected function _deduce_fields_n_values_from_cols_n_values($cols_n_values) {
3926 3926
 		$this_model_fields_n_values = array();
3927
-		foreach( $this->get_tables() as $table_alias => $table_obj ) {
3928
-			$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() );
3927
+		foreach ($this->get_tables() as $table_alias => $table_obj) {
3928
+			$table_pk_value = $this->_get_column_value_with_table_alias_or_not($cols_n_values, $table_obj->get_fully_qualified_pk_column(), $table_obj->get_pk_column());
3929 3929
 			//there is a primary key on this table and its not set. Use defaults for all its columns
3930
-			if( $table_obj->get_pk_column() && $table_pk_value === NULL ){
3931
-				foreach( $this->_get_fields_for_table( $table_alias ) as $field_name => $field_obj ) {
3932
-					if( ! $field_obj->is_db_only_field() ){
3930
+			if ($table_obj->get_pk_column() && $table_pk_value === NULL) {
3931
+				foreach ($this->_get_fields_for_table($table_alias) as $field_name => $field_obj) {
3932
+					if ( ! $field_obj->is_db_only_field()) {
3933 3933
 						//prepare field as if its coming from db
3934
-						$prepared_value = $field_obj->prepare_for_set( $field_obj->get_default_value() );
3935
-						$this_model_fields_n_values[$field_name] = $field_obj->prepare_for_use_in_db( $prepared_value );
3934
+						$prepared_value = $field_obj->prepare_for_set($field_obj->get_default_value());
3935
+						$this_model_fields_n_values[$field_name] = $field_obj->prepare_for_use_in_db($prepared_value);
3936 3936
 					}
3937 3937
 				}
3938
-			}else{
3938
+			} else {
3939 3939
 				//the table's rows existed. Use their values
3940
-				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() );
3940
+				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());
3943 3943
 				}
3944 3944
 			}
3945 3945
 		}
3946 3946
 		return $this_model_fields_n_values;
3947 3947
 	}
3948 3948
 
3949
-	protected function _get_column_value_with_table_alias_or_not( $cols_n_values, $qualified_column, $regular_column ){
3949
+	protected function _get_column_value_with_table_alias_or_not($cols_n_values, $qualified_column, $regular_column) {
3950 3950
 		//ask the field what it think it's table_name.column_name should be, and call it the "qualified column"
3951 3951
 		//does the field on the model relate to this column retrieved from the db?
3952 3952
 		//or is it a db-only field? (not relating to the model)
3953
-		if( isset( $cols_n_values[ $qualified_column ] ) ){
3954
-			$value = $cols_n_values[ $qualified_column ];
3953
+		if (isset($cols_n_values[$qualified_column])) {
3954
+			$value = $cols_n_values[$qualified_column];
3955 3955
 
3956
-		}elseif( isset( $cols_n_values[ $regular_column ] ) ){
3957
-			$value = $cols_n_values[ $regular_column ];
3958
-		}else{
3956
+		}elseif (isset($cols_n_values[$regular_column])) {
3957
+			$value = $cols_n_values[$regular_column];
3958
+		} else {
3959 3959
 			$value = NULL;
3960 3960
 		}
3961 3961
 
@@ -3973,24 +3973,24 @@  discard block
 block discarded – undo
3973 3973
 	 * @param int|string $id
3974 3974
 	 * @return EE_Base_Class
3975 3975
 	 */
3976
-	public function refresh_entity_map_from_db( $id ){
3977
-		$obj_in_map = $this->get_from_entity_map( $id );
3978
-		if( $obj_in_map ){
3979
-			$wpdb_results = $this->_get_all_wpdb_results( array( array ( $this->get_primary_key_field()->get_name() => $id ), 'limit' => 1 ) );
3980
-			if( $wpdb_results && is_array( $wpdb_results ) ){
3981
-				$one_row = reset( $wpdb_results );
3982
-				foreach( $this->_deduce_fields_n_values_from_cols_n_values($one_row ) as $field_name => $db_value ) {
3983
-					$obj_in_map->set_from_db( $field_name, $db_value );
3976
+	public function refresh_entity_map_from_db($id) {
3977
+		$obj_in_map = $this->get_from_entity_map($id);
3978
+		if ($obj_in_map) {
3979
+			$wpdb_results = $this->_get_all_wpdb_results(array(array($this->get_primary_key_field()->get_name() => $id), 'limit' => 1));
3980
+			if ($wpdb_results && is_array($wpdb_results)) {
3981
+				$one_row = reset($wpdb_results);
3982
+				foreach ($this->_deduce_fields_n_values_from_cols_n_values($one_row) as $field_name => $db_value) {
3983
+					$obj_in_map->set_from_db($field_name, $db_value);
3984 3984
 				}
3985 3985
 				//clear the cache of related model objects
3986
-				foreach ( $this->relation_settings() as $relation_name => $relation_obj ){
3987
-					$obj_in_map->clear_cache($relation_name, NULL, TRUE );
3986
+				foreach ($this->relation_settings() as $relation_name => $relation_obj) {
3987
+					$obj_in_map->clear_cache($relation_name, NULL, TRUE);
3988 3988
 				}
3989 3989
 			}
3990
-			$this->_entity_map[ $id ] = $obj_in_map;
3990
+			$this->_entity_map[$id] = $obj_in_map;
3991 3991
 			return $obj_in_map;
3992
-		}else{
3993
-			return $this->get_one_by_ID( $id );
3992
+		} else {
3993
+			return $this->get_one_by_ID($id);
3994 3994
 		}
3995 3995
 	}
3996 3996
 
@@ -4008,24 +4008,24 @@  discard block
 block discarded – undo
4008 4008
 	 * @param EE_Base_Class $replacing_model_obj
4009 4009
 	 * @return \EE_Base_Class
4010 4010
 	 */
4011
-	public function refresh_entity_map_with( $id, $replacing_model_obj ) {
4012
-		$obj_in_map = $this->get_from_entity_map( $id );
4013
-		if( $obj_in_map ){
4014
-			if( $replacing_model_obj instanceof EE_Base_Class ){
4015
-				foreach( $replacing_model_obj->model_field_array() as $field_name => $value ) {
4016
-					$obj_in_map->set( $field_name, $value );
4011
+	public function refresh_entity_map_with($id, $replacing_model_obj) {
4012
+		$obj_in_map = $this->get_from_entity_map($id);
4013
+		if ($obj_in_map) {
4014
+			if ($replacing_model_obj instanceof EE_Base_Class) {
4015
+				foreach ($replacing_model_obj->model_field_array() as $field_name => $value) {
4016
+					$obj_in_map->set($field_name, $value);
4017 4017
 				}
4018 4018
 				//make the model object in the entity map's cache match the $replacing_model_obj
4019
-				foreach ( $this->relation_settings() as $relation_name => $relation_obj ){
4020
-					$obj_in_map->clear_cache($relation_name, NULL, TRUE );
4021
-					foreach( $replacing_model_obj->get_all_from_cache( $relation_name ) as $cache_id => $cached_obj ) {
4022
-						$obj_in_map->cache( $relation_name, $cached_obj, $cache_id );
4019
+				foreach ($this->relation_settings() as $relation_name => $relation_obj) {
4020
+					$obj_in_map->clear_cache($relation_name, NULL, TRUE);
4021
+					foreach ($replacing_model_obj->get_all_from_cache($relation_name) as $cache_id => $cached_obj) {
4022
+						$obj_in_map->cache($relation_name, $cached_obj, $cache_id);
4023 4023
 					}
4024 4024
 				}
4025 4025
 			}
4026 4026
 			return $obj_in_map;
4027
-		}else{
4028
-			$this->add_to_entity_map( $replacing_model_obj );
4027
+		} else {
4028
+			$this->add_to_entity_map($replacing_model_obj);
4029 4029
 			return $replacing_model_obj;
4030 4030
 		}
4031 4031
 	}
@@ -4038,7 +4038,7 @@  discard block
 block discarded – undo
4038 4038
 	 * require_once($this->_getClassName().".class.php");
4039 4039
 	 * @return string
4040 4040
 	 */
4041
-	private function _get_class_name(){
4041
+	private function _get_class_name() {
4042 4042
 		return "EE_".$this->get_this_model_name();
4043 4043
 	}
4044 4044
 
@@ -4051,10 +4051,10 @@  discard block
 block discarded – undo
4051 4051
 	 * @param int $quantity
4052 4052
 	 * @return string
4053 4053
 	 */
4054
-	public function item_name($quantity = 1){
4055
-		if($quantity == 1){
4054
+	public function item_name($quantity = 1) {
4055
+		if ($quantity == 1) {
4056 4056
 			return $this->singular_item;
4057
-		}else{
4057
+		} else {
4058 4058
 			return $this->plural_item;
4059 4059
 		}
4060 4060
 	}
@@ -4083,13 +4083,13 @@  discard block
 block discarded – undo
4083 4083
 	 * @throws EE_Error
4084 4084
 	 * @return mixed whatever the plugin which calls add_filter decides
4085 4085
 	 */
4086
-	public function __call($methodName,$args){
4087
-		$className=get_class($this);
4088
-		$tagName="FHEE__{$className}__{$methodName}";
4089
-		if(!has_filter($tagName)){
4086
+	public function __call($methodName, $args) {
4087
+		$className = get_class($this);
4088
+		$tagName = "FHEE__{$className}__{$methodName}";
4089
+		if ( ! has_filter($tagName)) {
4090 4090
 			throw new EE_Error(
4091 4091
 				sprintf(
4092
-					__( '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' ),
4092
+					__('Method %1$s on model %2$s does not exist! You can create one with the following code in functions.php or in a plugin: %4$s function my_callback(%4$s \$previousReturnValue, EEM_Base \$object\ $argsArray=NULL ){%4$s     /*function body*/%4$s      return \$whatever;%4$s }%4$s add_filter( \'%3$s\', \'my_callback\', 10, 3 );', 'event_espresso'),
4093 4093
 					$methodName,
4094 4094
 					$className,
4095 4095
 					$tagName,
@@ -4098,7 +4098,7 @@  discard block
 block discarded – undo
4098 4098
 			);
4099 4099
 		}
4100 4100
 
4101
-		return apply_filters($tagName,null,$this,$args);
4101
+		return apply_filters($tagName, null, $this, $args);
4102 4102
 	}
4103 4103
 
4104 4104
 
@@ -4111,22 +4111,22 @@  discard block
 block discarded – undo
4111 4111
 	 * @throws EE_Error
4112 4112
 	 * @return EE_Base_Class
4113 4113
 	 */
4114
-	public function ensure_is_obj( $base_class_obj_or_id, $ensure_is_in_db = FALSE ){
4114
+	public function ensure_is_obj($base_class_obj_or_id, $ensure_is_in_db = FALSE) {
4115 4115
 		$className = $this->_get_class_name();
4116 4116
 		$primary_key_field = $this->get_primary_key_field();
4117
-		if( $base_class_obj_or_id instanceof $className ){
4117
+		if ($base_class_obj_or_id instanceof $className) {
4118 4118
 			$model_object = $base_class_obj_or_id;
4119
-		}elseif( $primary_key_field instanceof EE_Primary_Key_Int_Field && (
4120
-				is_int( $base_class_obj_or_id ) ||
4121
-				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)
4119
+		}elseif ($primary_key_field instanceof EE_Primary_Key_Int_Field && (
4120
+				is_int($base_class_obj_or_id) ||
4121
+				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 4122
 			$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) ){
4123
+		}elseif ($primary_key_field instanceof EE_Primary_Key_String_Field && is_string($base_class_obj_or_id)) {
4124 4124
 			//assume its a string representation of the object
4125 4125
 			$model_object = $this->get_one_by_ID($base_class_obj_or_id);
4126
-		}else{
4127
-			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)));
4126
+		} else {
4127
+			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 4128
 		}
4129
-		if( $model_object->ID() == NULL && $ensure_is_in_db){
4129
+		if ($model_object->ID() == NULL && $ensure_is_in_db) {
4130 4130
 			$model_object->save();
4131 4131
 		}
4132 4132
 		return $model_object;
@@ -4142,19 +4142,19 @@  discard block
 block discarded – undo
4142 4142
 	 * @return int|string depending on the type of this model object's ID
4143 4143
 	 * @throws EE_Error
4144 4144
 	 */
4145
-	public function ensure_is_ID($base_class_obj_or_id){
4145
+	public function ensure_is_ID($base_class_obj_or_id) {
4146 4146
 		$className = $this->_get_class_name();
4147
-		if( $base_class_obj_or_id instanceof $className ){
4147
+		if ($base_class_obj_or_id instanceof $className) {
4148 4148
 			/** @var $base_class_obj_or_id EE_Base_Class */
4149 4149
 			$id = $base_class_obj_or_id->ID();
4150
-		}elseif(is_int($base_class_obj_or_id)){
4150
+		}elseif (is_int($base_class_obj_or_id)) {
4151 4151
 			//assume it's an ID
4152 4152
 			$id = $base_class_obj_or_id;
4153
-		}elseif(is_string($base_class_obj_or_id)){
4153
+		}elseif (is_string($base_class_obj_or_id)) {
4154 4154
 			//assume its a string representation of the object
4155 4155
 			$id = $base_class_obj_or_id;
4156
-		}else{
4157
-			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)));
4156
+		} else {
4157
+			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 4158
 		}
4159 4159
 		return $id;
4160 4160
 	}
@@ -4177,14 +4177,14 @@  discard block
 block discarded – undo
4177 4177
 	 * @param int $values_already_prepared like one of the constants on EEM_Base
4178 4178
 	 * @return void
4179 4179
 	 */
4180
-	public function assume_values_already_prepared_by_model_object($values_already_prepared = self::not_prepared_by_model_object){
4180
+	public function assume_values_already_prepared_by_model_object($values_already_prepared = self::not_prepared_by_model_object) {
4181 4181
 		$this->_values_already_prepared_by_model_object = $values_already_prepared;
4182 4182
 	}
4183 4183
 	/**
4184 4184
 	 * Read comments for assume_values_already_prepared_by_model_object()
4185 4185
 	 * @return int
4186 4186
 	 */
4187
-	public function get_assumption_concerning_values_already_prepared_by_model_object(){
4187
+	public function get_assumption_concerning_values_already_prepared_by_model_object() {
4188 4188
 		return $this->_values_already_prepared_by_model_object;
4189 4189
 	}
4190 4190
 
@@ -4192,17 +4192,17 @@  discard block
 block discarded – undo
4192 4192
 	 * Gets all the indexes on this model
4193 4193
 	 * @return EE_Index[]
4194 4194
 	 */
4195
-	public function indexes(){
4195
+	public function indexes() {
4196 4196
 		return $this->_indexes;
4197 4197
 	}
4198 4198
 	/**
4199 4199
 	 * Gets all the Unique Indexes on this model
4200 4200
 	 * @return EE_Unique_Index[]
4201 4201
 	 */
4202
-	public function unique_indexes(){
4202
+	public function unique_indexes() {
4203 4203
 		$unique_indexes = array();
4204
-		foreach($this->_indexes as $name => $index){
4205
-			if($index instanceof EE_Unique_Index){
4204
+		foreach ($this->_indexes as $name => $index) {
4205
+			if ($index instanceof EE_Unique_Index) {
4206 4206
 				$unique_indexes [$name] = $index;
4207 4207
 			}
4208 4208
 		}
@@ -4215,9 +4215,9 @@  discard block
 block discarded – undo
4215 4215
 	 * on a primary index
4216 4216
 	 * @return EE_Model_Field_Base[]
4217 4217
 	 */
4218
-	public function get_combined_primary_key_fields(){
4219
-		foreach($this->indexes() as $index){
4220
-			if($index instanceof EE_Primary_Key_Index){
4218
+	public function get_combined_primary_key_fields() {
4219
+		foreach ($this->indexes() as $index) {
4220
+			if ($index instanceof EE_Primary_Key_Index) {
4221 4221
 				return $index->fields();
4222 4222
 			}
4223 4223
 		}
@@ -4230,7 +4230,7 @@  discard block
 block discarded – undo
4230 4230
 	 * @param array $cols_n_values keys are field names, values are their values
4231 4231
 	 * @return string
4232 4232
 	 */
4233
-	public function get_index_primary_key_string($cols_n_values){
4233
+	public function get_index_primary_key_string($cols_n_values) {
4234 4234
 		$cols_n_values_for_primary_key_index = array_intersect_key($cols_n_values, $this->get_combined_primary_key_fields());
4235 4235
 		return http_build_query($cols_n_values_for_primary_key_index);
4236 4236
 	}
@@ -4242,13 +4242,13 @@  discard block
 block discarded – undo
4242 4242
 	 * @param string $index_primary_key_string
4243 4243
 	 * @return null|array
4244 4244
 	 */
4245
-	function parse_index_primary_key_string( $index_primary_key_string) {
4245
+	function parse_index_primary_key_string($index_primary_key_string) {
4246 4246
 		$key_fields = $this->get_combined_primary_key_fields();
4247 4247
 		//check all of them are in the $id
4248 4248
 		$key_vals_in_combined_pk = array();
4249
-		parse_str( $index_primary_key_string, $key_vals_in_combined_pk );
4250
-		foreach( $key_fields as $key_field_name => $field_obj ) {
4251
-			if( ! isset( $key_vals_in_combined_pk[ $key_field_name ] ) ){
4249
+		parse_str($index_primary_key_string, $key_vals_in_combined_pk);
4250
+		foreach ($key_fields as $key_field_name => $field_obj) {
4251
+			if ( ! isset($key_vals_in_combined_pk[$key_field_name])) {
4252 4252
 				return NULL;
4253 4253
 			}
4254 4254
 		}
@@ -4261,10 +4261,10 @@  discard block
 block discarded – undo
4261 4261
 	 * @param array $key_vals
4262 4262
 	 * @return boolean
4263 4263
 	 */
4264
-	function has_all_combined_primary_key_fields( $key_vals ) {
4265
-		$keys_it_should_have = array_keys( $this->get_combined_primary_key_fields() );
4266
-		foreach( $keys_it_should_have as $key ){
4267
-			if( ! isset( $key_vals[ $key ] ) ){
4264
+	function has_all_combined_primary_key_fields($key_vals) {
4265
+		$keys_it_should_have = array_keys($this->get_combined_primary_key_fields());
4266
+		foreach ($keys_it_should_have as $key) {
4267
+			if ( ! isset($key_vals[$key])) {
4268 4268
 				return false;
4269 4269
 			}
4270 4270
 		}
@@ -4280,23 +4280,23 @@  discard block
 block discarded – undo
4280 4280
 	 * @throws EE_Error
4281 4281
 	 * @return \EE_Base_Class[] Array keys are object IDs (if there is a primary key on the model. if not, numerically indexed)
4282 4282
 	 */
4283
-	public function get_all_copies($model_object_or_attributes_array, $query_params = array()){
4283
+	public function get_all_copies($model_object_or_attributes_array, $query_params = array()) {
4284 4284
 
4285
-		if($model_object_or_attributes_array instanceof EE_Base_Class){
4285
+		if ($model_object_or_attributes_array instanceof EE_Base_Class) {
4286 4286
 			$attributes_array = $model_object_or_attributes_array->model_field_array();
4287
-		}elseif(is_array($model_object_or_attributes_array)){
4287
+		}elseif (is_array($model_object_or_attributes_array)) {
4288 4288
 			$attributes_array = $model_object_or_attributes_array;
4289
-		}else{
4290
-			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));
4289
+		} else {
4290
+			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 4291
 		}
4292 4292
 		//even copies obviously won't have the same ID, so remove the primary key
4293 4293
 		//from the WHERE conditions for finding copies (if there is a primary key, of course)
4294
-		if($this->has_primary_key_field() && isset($attributes_array[$this->primary_key_name()])){
4294
+		if ($this->has_primary_key_field() && isset($attributes_array[$this->primary_key_name()])) {
4295 4295
 			unset($attributes_array[$this->primary_key_name()]);
4296 4296
 		}
4297
-		if(isset($query_params[0])){
4298
-			$query_params[0] = array_merge($attributes_array,$query_params);
4299
-		}else{
4297
+		if (isset($query_params[0])) {
4298
+			$query_params[0] = array_merge($attributes_array, $query_params);
4299
+		} else {
4300 4300
 			$query_params[0] = $attributes_array;
4301 4301
 		}
4302 4302
 		return $this->get_all($query_params);
@@ -4310,16 +4310,16 @@  discard block
 block discarded – undo
4310 4310
 	 * @param array $query_params
4311 4311
 	 * @return EE_Base_Class
4312 4312
 	 */
4313
-	function get_one_copy($model_object_or_attributes_array,$query_params = array()){
4314
-		if( ! is_array( $query_params ) ){
4315
-			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' );
4313
+	function get_one_copy($model_object_or_attributes_array, $query_params = array()) {
4314
+		if ( ! is_array($query_params)) {
4315
+			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');
4316 4316
 			$query_params = array();
4317 4317
 		}
4318 4318
 		$query_params['limit'] = 1;
4319
-		$copies = $this->get_all_copies($model_object_or_attributes_array,$query_params);
4320
-		if(is_array($copies)){
4319
+		$copies = $this->get_all_copies($model_object_or_attributes_array, $query_params);
4320
+		if (is_array($copies)) {
4321 4321
 			return array_shift($copies);
4322
-		}else{
4322
+		} else {
4323 4323
 			return null;
4324 4324
 		}
4325 4325
 	}
@@ -4333,10 +4333,10 @@  discard block
 block discarded – undo
4333 4333
 	 * @param int|string $id the value of the primary key to update
4334 4334
 	 * @return int number of rows updated
4335 4335
 	 */
4336
-	public function update_by_ID($fields_n_values,$id){
4336
+	public function update_by_ID($fields_n_values, $id) {
4337 4337
 		$query_params = array(0=>array($this->get_primary_key_field()->get_name() => $id),
4338 4338
 			'default_where_conditions'=>'other_models_only',);
4339
-		return $this->update($fields_n_values,$query_params);
4339
+		return $this->update($fields_n_values, $query_params);
4340 4340
 	}
4341 4341
 
4342 4342
 
@@ -4347,12 +4347,12 @@  discard block
 block discarded – undo
4347 4347
 	 * @return string an operator which can be used in SQL
4348 4348
 	 * @throws EE_Error
4349 4349
 	 */
4350
-	private function _prepare_operator_for_sql($operator_supplied){
4350
+	private function _prepare_operator_for_sql($operator_supplied) {
4351 4351
 		$sql_operator = isset($this->_valid_operators[$operator_supplied]) ? $this->_valid_operators[$operator_supplied] : null;
4352
-		if($sql_operator){
4352
+		if ($sql_operator) {
4353 4353
 			return $sql_operator;
4354
-		}else{
4355
-			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))));
4354
+		} else {
4355
+			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 4356
 		}
4357 4357
 	}
4358 4358
 
@@ -4362,10 +4362,10 @@  discard block
 block discarded – undo
4362 4362
 	 * @param array $query_params like get_all's
4363 4363
 	 * @return string[]
4364 4364
 	 */
4365
-	public function get_all_names($query_params = array()){
4365
+	public function get_all_names($query_params = array()) {
4366 4366
 		$objs = $this->get_all($query_params);
4367 4367
 		$names = array();
4368
-		foreach($objs as $obj){
4368
+		foreach ($objs as $obj) {
4369 4369
 			$names[$obj->ID()] = $obj->name();
4370 4370
 		}
4371 4371
 		return $names;
@@ -4380,22 +4380,22 @@  discard block
 block discarded – undo
4380 4380
 	 * @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
4381 4381
 	 * @return array
4382 4382
 	 */
4383
-	public function get_IDs( $model_objects, $filter_out_empty_ids = false) {
4384
-		if( ! $this->has_primary_key_field() ) {
4385
-			if( WP_DEBUG ) {
4386
-				EE_Error::add_error( __( 'Trying to get IDs from a model than has no primary key', 'event_espresso' ), __FILE__, __FUNCTION__, __LINE__ );
4383
+	public function get_IDs($model_objects, $filter_out_empty_ids = false) {
4384
+		if ( ! $this->has_primary_key_field()) {
4385
+			if (WP_DEBUG) {
4386
+				EE_Error::add_error(__('Trying to get IDs from a model than has no primary key', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__);
4387 4387
 				return array();
4388 4388
 			}
4389 4389
 		}
4390 4390
 		$IDs = array();
4391
-		foreach( $model_objects as $model_object ) {
4391
+		foreach ($model_objects as $model_object) {
4392 4392
 			$id = $model_object->ID();
4393
-			if( ! $id ) {
4394
-				if( $filter_out_empty_ids ) {
4393
+			if ( ! $id) {
4394
+				if ($filter_out_empty_ids) {
4395 4395
 					continue;
4396 4396
 				}
4397
-				if( WP_DEBUG ) {
4398
-					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__ );
4397
+				if (WP_DEBUG) {
4398
+					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__);
4399 4399
 				}
4400 4400
 			}
4401 4401
 			$IDs[] = $id;
@@ -4408,8 +4408,8 @@  discard block
 block discarded – undo
4408 4408
 	 * are no capabilities that relate to this model returns false
4409 4409
 	 * @return string|false
4410 4410
 	 */
4411
-	public function cap_slug(){
4412
-		return apply_filters( 'FHEE__EEM_Base__cap_slug', $this->_caps_slug, $this);
4411
+	public function cap_slug() {
4412
+		return apply_filters('FHEE__EEM_Base__cap_slug', $this->_caps_slug, $this);
4413 4413
 	}
4414 4414
 
4415 4415
 	/**
@@ -4421,27 +4421,27 @@  discard block
 block discarded – undo
4421 4421
 	 * @param string $context
4422 4422
 	 * @return EE_Default_Where_Conditions[] indexed by associated capability
4423 4423
 	 */
4424
-	public function cap_restrictions( $context = EEM_Base::caps_read ) {
4425
-		EEM_Base::verify_is_valid_cap_context( $context );
4424
+	public function cap_restrictions($context = EEM_Base::caps_read) {
4425
+		EEM_Base::verify_is_valid_cap_context($context);
4426 4426
 		//check if we ought to run the restriction generator first
4427
-		if( isset( $this->_cap_restriction_generators[ $context ] ) &&
4428
-				$this->_cap_restriction_generators[ $context ] instanceof EE_Restriction_Generator_Base &&
4429
-				! $this->_cap_restriction_generators[ $context ]->has_generated_cap_restrictions() ) {
4430
-			$this->_cap_restrictions[ $context ] = array_merge( $this->_cap_restrictions[ $context ],  $this->_cap_restriction_generators[ $context ]->generate_restrictions() );
4427
+		if (isset($this->_cap_restriction_generators[$context]) &&
4428
+				$this->_cap_restriction_generators[$context] instanceof EE_Restriction_Generator_Base &&
4429
+				! $this->_cap_restriction_generators[$context]->has_generated_cap_restrictions()) {
4430
+			$this->_cap_restrictions[$context] = array_merge($this->_cap_restrictions[$context], $this->_cap_restriction_generators[$context]->generate_restrictions());
4431 4431
 		}
4432 4432
 		//and make sure we've finalized the construction of each restriction
4433
-		foreach( $this->_cap_restrictions[ $context ] as $where_conditions_obj ) {
4434
-			$where_conditions_obj->_finalize_construct( $this );
4433
+		foreach ($this->_cap_restrictions[$context] as $where_conditions_obj) {
4434
+			$where_conditions_obj->_finalize_construct($this);
4435 4435
 		}
4436 4436
 
4437
-		return $this->_cap_restrictions[ $context ];
4437
+		return $this->_cap_restrictions[$context];
4438 4438
 	}
4439 4439
 
4440 4440
 	/**
4441 4441
 	 * Indicating whether or not this model thinks its a wp core model
4442 4442
 	 * @return boolean
4443 4443
 	 */
4444
-	public function is_wp_core_model(){
4444
+	public function is_wp_core_model() {
4445 4445
 		return $this->_wp_core_model;
4446 4446
 	}
4447 4447
 
@@ -4451,12 +4451,12 @@  discard block
 block discarded – undo
4451 4451
 	 * @param string $context one of EEM_Base::caps_ constants
4452 4452
 	 * @return EE_Default_Where_Conditions[] indexed by capability name
4453 4453
 	 */
4454
-	public function caps_missing( $context = EEM_Base::caps_read ) {
4454
+	public function caps_missing($context = EEM_Base::caps_read) {
4455 4455
 		$missing_caps = array();
4456
-		$cap_restrictions = $this->cap_restrictions( $context );
4457
-		foreach( $cap_restrictions as $cap => $restriction_if_no_cap ) {
4458
-			if( ! EE_Capabilities::instance()->current_user_can( $cap, $this->get_this_model_name() . '_model_applying_caps') ) {
4459
-				$missing_caps[ $cap ] = $restriction_if_no_cap;
4456
+		$cap_restrictions = $this->cap_restrictions($context);
4457
+		foreach ($cap_restrictions as $cap => $restriction_if_no_cap) {
4458
+			if ( ! EE_Capabilities::instance()->current_user_can($cap, $this->get_this_model_name().'_model_applying_caps')) {
4459
+				$missing_caps[$cap] = $restriction_if_no_cap;
4460 4460
 			}
4461 4461
 		}
4462 4462
 		return $missing_caps;
@@ -4468,7 +4468,7 @@  discard block
 block discarded – undo
4468 4468
 	 * one of 'read', 'edit', or 'delete'
4469 4469
 	 */
4470 4470
 	public function cap_contexts_to_cap_action_map() {
4471
-		return apply_filters( 'FHEE__EEM_Base__cap_contexts_to_cap_action_map', $this->_cap_contexts_to_cap_action_map, $this );
4471
+		return apply_filters('FHEE__EEM_Base__cap_contexts_to_cap_action_map', $this->_cap_contexts_to_cap_action_map, $this);
4472 4472
 	}
4473 4473
 
4474 4474
 
@@ -4479,19 +4479,19 @@  discard block
 block discarded – undo
4479 4479
 	 * @return string one of EEM_Base::cap_contexts_to_cap_action_map() values
4480 4480
 	 * @throws \EE_Error
4481 4481
 	 */
4482
-	public function cap_action_for_context( $context ) {
4482
+	public function cap_action_for_context($context) {
4483 4483
 		$mapping = $this->cap_contexts_to_cap_action_map();
4484
-		if( isset( $mapping[ $context ] ) ) {
4485
-			return $mapping[ $context ];
4484
+		if (isset($mapping[$context])) {
4485
+			return $mapping[$context];
4486 4486
 		}
4487
-		if( $action = apply_filters( 'FHEE__EEM_Base__cap_action_for_context', null, $this, $mapping, $context ) ) {
4487
+		if ($action = apply_filters('FHEE__EEM_Base__cap_action_for_context', null, $this, $mapping, $context)) {
4488 4488
 			return $action;
4489 4489
 		}
4490 4490
 		throw new EE_Error(
4491 4491
 			sprintf(
4492
-				__( 'Cannot find capability restrictions for context "%1$s", allowed values are:%2$s', 'event_espresso' ),
4492
+				__('Cannot find capability restrictions for context "%1$s", allowed values are:%2$s', 'event_espresso'),
4493 4493
 				$context,
4494
-				implode(',', array_keys( $this->cap_contexts_to_cap_action_map() ) )
4494
+				implode(',', array_keys($this->cap_contexts_to_cap_action_map()))
4495 4495
 			)
4496 4496
 		);
4497 4497
 
@@ -4502,7 +4502,7 @@  discard block
 block discarded – undo
4502 4502
 	 * @return array
4503 4503
 	 */
4504 4504
 	static public function valid_cap_contexts() {
4505
-		return apply_filters( 'FHEE__EEM_Base__valid_cap_contexts', array(
4505
+		return apply_filters('FHEE__EEM_Base__valid_cap_contexts', array(
4506 4506
 			self::caps_read,
4507 4507
 			self::caps_read_admin,
4508 4508
 			self::caps_edit,
@@ -4518,17 +4518,17 @@  discard block
 block discarded – undo
4518 4518
 	 * @return bool
4519 4519
 	 * @throws \EE_Error
4520 4520
 	 */
4521
-	static public function verify_is_valid_cap_context( $context ) {
4521
+	static public function verify_is_valid_cap_context($context) {
4522 4522
 		$valid_cap_contexts = EEM_Base::valid_cap_contexts();
4523
-		if( in_array( $context, $valid_cap_contexts ) ) {
4523
+		if (in_array($context, $valid_cap_contexts)) {
4524 4524
 			return true;
4525
-		}else{
4525
+		} else {
4526 4526
 			throw new EE_Error(
4527 4527
 				sprintf(
4528
-					__( 'Context "%1$s" passed into model "%2$s" is not a valid context. They are: %3$s', 'event_espresso' ),
4528
+					__('Context "%1$s" passed into model "%2$s" is not a valid context. They are: %3$s', 'event_espresso'),
4529 4529
 					$context,
4530
-					'EEM_Base' ,
4531
-					implode(',', $valid_cap_contexts )
4530
+					'EEM_Base',
4531
+					implode(',', $valid_cap_contexts)
4532 4532
 				)
4533 4533
 			);
4534 4534
 		}
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.
core/db_models/EEM_Registration.model.php 3 patches
Indentation   +28 added lines, -28 removed lines patch added patch discarded remove patch
@@ -2,15 +2,15 @@  discard block
 block discarded – undo
2 2
 require_once ( EE_MODELS . 'EEM_Soft_Delete_Base.model.php' );
3 3
 require_once ( EE_CLASSES . 'EE_Registration.class.php' );
4 4
 /**
5
- *
6
- * Registration Model
7
- *
8
- * @package			Event Espresso
9
- * @subpackage		includes/models/
10
- * @author				Mike Nelson, Brent Christensen
11
- *
12
- * ------------------------------------------------------------------------
13
- */
5
+	 *
6
+	 * Registration Model
7
+	 *
8
+	 * @package			Event Espresso
9
+	 * @subpackage		includes/models/
10
+	 * @author				Mike Nelson, Brent Christensen
11
+	 *
12
+	 * ------------------------------------------------------------------------
13
+	 */
14 14
 class EEM_Registration extends EEM_Soft_Delete_Base {
15 15
 
16 16
   	// private instance of the Registration object
@@ -220,11 +220,11 @@  discard block
 block discarded – undo
220 220
 
221 221
 
222 222
 	/**
223
-	*		retrieve ALL registrations for a particular Attendee from db
224
-	* 		@access		public
225
-	* 		@param		int		$ATT_ID
226
-	*		@return 	EE_Registration[]
227
-	*/
223
+	 *		retrieve ALL registrations for a particular Attendee from db
224
+	 * 		@access		public
225
+	 * 		@param		int		$ATT_ID
226
+	 *		@return 	EE_Registration[]
227
+	 */
228 228
 	public function get_all_registrations_for_attendee( $ATT_ID = 0 ) {
229 229
 		if ( ! $ATT_ID ) {
230 230
 			return FALSE;
@@ -251,14 +251,14 @@  discard block
 block discarded – undo
251 251
 
252 252
 
253 253
 	/**
254
-	*		retrieve registration for a specific transaction attendee from db
255
-	*
256
-	* 		@access		public
257
-	* 		@param	int	$TXN_ID
258
-	* 		@param    int		$ATT_ID
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
261
-	*/
254
+	 *		retrieve registration for a specific transaction attendee from db
255
+	 *
256
+	 * 		@access		public
257
+	 * 		@param	int	$TXN_ID
258
+	 * 		@param    int		$ATT_ID
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
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(
264 264
 			array(
@@ -271,12 +271,12 @@  discard block
 block discarded – undo
271 271
 
272 272
 
273 273
 	/**
274
-	*		get the number of registrations per day  for the Registration Admin page Reports Tab.
274
+	 *		get the number of registrations per day  for the Registration Admin page Reports Tab.
275 275
 	 *		(doesn't utilize models because it's a fairly specialized query)
276
-	* 		@access		public
276
+	 * 		@access		public
277 277
 	 *		@param $period string which can be passed to php's strtotime function (eg "-1 month")
278 278
 	 *		@return stdClass[] with properties regDate and total
279
-	*/
279
+	 */
280 280
 	public function get_registrations_per_day_report( $period = '-1 month' ) {
281 281
 
282 282
 		$sql_date = $this->convert_datetime_for_query( 'REG_date', date("Y-m-d H:i:s", strtotime($period) ), 'Y-m-d H:i:s', 'UTC' );
@@ -305,11 +305,11 @@  discard block
 block discarded – undo
305 305
 
306 306
 
307 307
 	/**
308
-	*		get the number of registrations per event  for the Registration Admin page Reports Tab
309
-	* 		@access		public
308
+	 *		get the number of registrations per event  for the Registration Admin page Reports Tab
309
+	 * 		@access		public
310 310
 	 * @param $period string which can be passed to php's strtotime function (eg "-1 month")
311 311
 	 *		@return stdClass[] each with properties event_name, reg_limit, and total
312
-	*/
312
+	 */
313 313
 	public function get_registrations_per_event_report( $period = '-1 month' ) {
314 314
 
315 315
 		$date_sql = $this->convert_datetime_for_query( 'REG_date', date( "Y-m-d H:i:s", strtotime( $period )), 'Y-m-d H:i:s', 'UTC' );
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.
Spacing   +66 added lines, -66 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@  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_Soft_Delete_Base.model.php' );
3
-require_once ( EE_CLASSES . 'EE_Registration.class.php' );
2
+require_once (EE_MODELS.'EEM_Soft_Delete_Base.model.php');
3
+require_once (EE_CLASSES.'EE_Registration.class.php');
4 4
 /**
5 5
  *
6 6
  * Registration Model
@@ -92,31 +92,31 @@  discard block
 block discarded – undo
92 92
 	 *    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)
93 93
 	 * @return \EEM_Registration
94 94
 	 */
95
-	protected function __construct( $timezone ) {
96
-		$this->singular_item = __('Registration','event_espresso');
97
-		$this->plural_item = __('Registrations','event_espresso');
95
+	protected function __construct($timezone) {
96
+		$this->singular_item = __('Registration', 'event_espresso');
97
+		$this->plural_item = __('Registrations', 'event_espresso');
98 98
 
99 99
 		$this->_tables = array(
100
-			'Registration'=>new EE_Primary_Table('esp_registration','REG_ID')
100
+			'Registration'=>new EE_Primary_Table('esp_registration', 'REG_ID')
101 101
 		);
102 102
 		$this->_fields = array(
103 103
 			'Registration'=>array(
104
-				'REG_ID'=>new EE_Primary_Key_Int_Field('REG_ID', __('Registration ID','event_espresso')),
105
-				'EVT_ID'=>new EE_Foreign_Key_Int_Field('EVT_ID', __('Event ID','event_espresso'), false, 0, 'Event'),
106
-				'ATT_ID'=>new EE_Foreign_Key_Int_Field('ATT_ID', __('Attendee ID','event_espresso'), false, 0, 'Attendee'),
107
-				'TXN_ID'=>new EE_Foreign_Key_Int_Field('TXN_ID', __('Transaction ID','event_espresso'), false, 0, 'Transaction'),
108
-				'TKT_ID'=>new EE_Foreign_Key_Int_Field('TKT_ID', __('Ticket ID','event_espresso'), false, 0, 'Ticket'),
109
-				'STS_ID'=>new EE_Foreign_Key_String_Field('STS_ID', __('Status ID','event_espresso'), false, EEM_Registration::status_id_incomplete, 'Status'),
110
-				'REG_date'=>new EE_Datetime_Field('REG_date', __('Time registration occurred','event_espresso'), false, time(), $timezone ),
111
-				'REG_final_price'=>new EE_Money_Field('REG_final_price', __('Registration\'s share of the transaction total','event_espresso'), false, 0),
112
-				'REG_paid'=>new EE_Money_Field('REG_paid', __('Amount paid to date towards registration','event_espresso'), false, 0),
113
-				'REG_session'=>new EE_Plain_Text_Field('REG_session', __('Session ID of registration','event_espresso'), false, ''),
114
-				'REG_code'=>new EE_Plain_Text_Field('REG_code', __('Unique Code for this registration','event_espresso'), false, ''),
115
-				'REG_url_link'=>new EE_Plain_Text_Field('REG_url_link', __('String to be used in URL for identifying registration','event_espresso'), false, ''),
116
-				'REG_count'=>new EE_Integer_Field('REG_count', __('Count of this registration in the group registration ','event_espresso'), true, 1),
117
-				'REG_group_size'=>new EE_Integer_Field('REG_group_size', __('Number of registrations on this group','event_espresso'), false, 1),
118
-				'REG_att_is_going'=>new EE_Boolean_Field('REG_att_is_going', __('Flag indicating the registrant plans on attending','event_espresso'), false, false),
119
-				'REG_deleted' => new EE_Trashed_Flag_Field('REG_deleted', __('Flag indicating if registration has been archived or not.', 'event_espresso'), false, false )
104
+				'REG_ID'=>new EE_Primary_Key_Int_Field('REG_ID', __('Registration ID', 'event_espresso')),
105
+				'EVT_ID'=>new EE_Foreign_Key_Int_Field('EVT_ID', __('Event ID', 'event_espresso'), false, 0, 'Event'),
106
+				'ATT_ID'=>new EE_Foreign_Key_Int_Field('ATT_ID', __('Attendee ID', 'event_espresso'), false, 0, 'Attendee'),
107
+				'TXN_ID'=>new EE_Foreign_Key_Int_Field('TXN_ID', __('Transaction ID', 'event_espresso'), false, 0, 'Transaction'),
108
+				'TKT_ID'=>new EE_Foreign_Key_Int_Field('TKT_ID', __('Ticket ID', 'event_espresso'), false, 0, 'Ticket'),
109
+				'STS_ID'=>new EE_Foreign_Key_String_Field('STS_ID', __('Status ID', 'event_espresso'), false, EEM_Registration::status_id_incomplete, 'Status'),
110
+				'REG_date'=>new EE_Datetime_Field('REG_date', __('Time registration occurred', 'event_espresso'), false, time(), $timezone),
111
+				'REG_final_price'=>new EE_Money_Field('REG_final_price', __('Registration\'s share of the transaction total', 'event_espresso'), false, 0),
112
+				'REG_paid'=>new EE_Money_Field('REG_paid', __('Amount paid to date towards registration', 'event_espresso'), false, 0),
113
+				'REG_session'=>new EE_Plain_Text_Field('REG_session', __('Session ID of registration', 'event_espresso'), false, ''),
114
+				'REG_code'=>new EE_Plain_Text_Field('REG_code', __('Unique Code for this registration', 'event_espresso'), false, ''),
115
+				'REG_url_link'=>new EE_Plain_Text_Field('REG_url_link', __('String to be used in URL for identifying registration', 'event_espresso'), false, ''),
116
+				'REG_count'=>new EE_Integer_Field('REG_count', __('Count of this registration in the group registration ', 'event_espresso'), true, 1),
117
+				'REG_group_size'=>new EE_Integer_Field('REG_group_size', __('Number of registrations on this group', 'event_espresso'), false, 1),
118
+				'REG_att_is_going'=>new EE_Boolean_Field('REG_att_is_going', __('Flag indicating the registrant plans on attending', 'event_espresso'), false, false),
119
+				'REG_deleted' => new EE_Trashed_Flag_Field('REG_deleted', __('Flag indicating if registration has been archived or not.', 'event_espresso'), false, false)
120 120
 			)
121 121
 		);
122 122
 		$this->_model_relations = array(
@@ -128,11 +128,11 @@  discard block
 block discarded – undo
128 128
 			'Answer'=>new EE_Has_Many_Relation(),
129 129
 			'Checkin'=>new EE_Has_Many_Relation(),
130 130
 			'Registration_Payment' => new EE_Has_Many_Relation(),
131
-			'Payment'=>new EE_HABTM_Relation( 'Registration_Payment' ),
131
+			'Payment'=>new EE_HABTM_Relation('Registration_Payment'),
132 132
 		);
133 133
 		$this->_model_chain_to_wp_user = 'Event';
134 134
 
135
-		parent::__construct( $timezone );
135
+		parent::__construct($timezone);
136 136
 	}
137 137
 
138 138
 
@@ -165,9 +165,9 @@  discard block
 block discarded – undo
165 165
 	 *		@param bool  $translated If true will return the values as singular localized strings
166 166
 	 *		@return array
167 167
 	 */
168
-	public static function reg_status_array( $exclude = array(), $translated = FALSE ) {
169
-		EEM_Registration::instance()->_get_registration_status_array( $exclude );
170
-		return $translated ? EEM_Status::instance()->localized_status( self::$_reg_status, FALSE, 'sentence') : self::$_reg_status;
168
+	public static function reg_status_array($exclude = array(), $translated = FALSE) {
169
+		EEM_Registration::instance()->_get_registration_status_array($exclude);
170
+		return $translated ? EEM_Status::instance()->localized_status(self::$_reg_status, FALSE, 'sentence') : self::$_reg_status;
171 171
 	}
172 172
 
173 173
 
@@ -178,19 +178,19 @@  discard block
 block discarded – undo
178 178
 	 * @param array $exclude
179 179
 	 * @return array
180 180
 	 */
181
-	private function _get_registration_status_array( $exclude = array() ) {
181
+	private function _get_registration_status_array($exclude = array()) {
182 182
 		//in the very rare circumstance that we are deleting a model's table's data
183 183
 		//and the table hasn't actually been created, this could have an error
184 184
 		/** @type WPDB $wpdb */
185 185
 		global $wpdb;
186
-		EE_Registry::instance()->load_helper( 'Activation' );
187
-		if( EEH_Activation::table_exists( $wpdb->prefix . 'esp_status' ) ){
188
-			$SQL = 'SELECT STS_ID, STS_code FROM '. $wpdb->prefix . 'esp_status WHERE STS_type = "registration"';
189
-			$results = $wpdb->get_results( $SQL );
186
+		EE_Registry::instance()->load_helper('Activation');
187
+		if (EEH_Activation::table_exists($wpdb->prefix.'esp_status')) {
188
+			$SQL = 'SELECT STS_ID, STS_code FROM '.$wpdb->prefix.'esp_status WHERE STS_type = "registration"';
189
+			$results = $wpdb->get_results($SQL);
190 190
 			self::$_reg_status = array();
191
-			foreach ( $results as $status ) {
192
-				if ( ! in_array( $status->STS_ID, $exclude )) {
193
-					self::$_reg_status[ $status->STS_ID ] = $status->STS_code;
191
+			foreach ($results as $status) {
192
+				if ( ! in_array($status->STS_ID, $exclude)) {
193
+					self::$_reg_status[$status->STS_ID] = $status->STS_code;
194 194
 				}
195 195
 			}
196 196
 		}
@@ -205,15 +205,15 @@  discard block
 block discarded – undo
205 205
 	 * @param  array  $where_params Array of query_params as described in the comments for EEM_Base::get_all()
206 206
 	 * @return wpdb results array
207 207
 	 */
208
-	public function get_reg_months_and_years( $where_params ) {
208
+	public function get_reg_months_and_years($where_params) {
209 209
 		$query_params[0] = $where_params;
210 210
 		$query_params['group_by'] = array('reg_year', 'reg_month');
211
-		$query_params['order_by'] = array( 'REG_date' => 'DESC' );
211
+		$query_params['order_by'] = array('REG_date' => 'DESC');
212 212
 		$columns_to_select = array(
213 213
 			'reg_year' => array('YEAR(REG_date)', '%s'),
214 214
 			'reg_month' => array('MONTHNAME(REG_date)', '%s')
215 215
 			);
216
-		return $this->_get_all_wpdb_results( $query_params, OBJECT, $columns_to_select );
216
+		return $this->_get_all_wpdb_results($query_params, OBJECT, $columns_to_select);
217 217
 	}
218 218
 
219 219
 
@@ -225,11 +225,11 @@  discard block
 block discarded – undo
225 225
 	* 		@param		int		$ATT_ID
226 226
 	*		@return 	EE_Registration[]
227 227
 	*/
228
-	public function get_all_registrations_for_attendee( $ATT_ID = 0 ) {
229
-		if ( ! $ATT_ID ) {
228
+	public function get_all_registrations_for_attendee($ATT_ID = 0) {
229
+		if ( ! $ATT_ID) {
230 230
 			return FALSE;
231 231
 		}
232
-		return $this->get_all( array( array( 'ATT_ID' => $ATT_ID )));
232
+		return $this->get_all(array(array('ATT_ID' => $ATT_ID)));
233 233
 	}
234 234
 
235 235
 
@@ -240,8 +240,8 @@  discard block
 block discarded – undo
240 240
 	 * @param string $REG_url_link
241 241
 	 * @return EE_Registration
242 242
 	 */
243
-	public function get_registration_for_reg_url_link($REG_url_link){
244
-		if(!$REG_url_link){
243
+	public function get_registration_for_reg_url_link($REG_url_link) {
244
+		if ( ! $REG_url_link) {
245 245
 			return false;
246 246
 		}
247 247
 		return $this->get_one(array(array('REG_url_link'=>$REG_url_link)));
@@ -259,13 +259,13 @@  discard block
 block discarded – undo
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 260
 	*		@return 		mixed		array on success, FALSE on fail
261 261
 	*/
262
-	public function get_registration_for_transaction_attendee( $TXN_ID = 0, $ATT_ID = 0, $att_nmbr = 0 ) {
262
+	public function get_registration_for_transaction_attendee($TXN_ID = 0, $ATT_ID = 0, $att_nmbr = 0) {
263 263
 		return $this->get_one(array(
264 264
 			array(
265 265
 				'TXN_ID'=>$TXN_ID,
266 266
 				'ATT_ID'=>$ATT_ID
267 267
 			),
268
-			'limit'=>array( min( ( $att_nmbr-1 ), 0 ), 1 )
268
+			'limit'=>array(min(($att_nmbr - 1), 0), 1)
269 269
 		));
270 270
 	}
271 271
 
@@ -277,12 +277,12 @@  discard block
 block discarded – undo
277 277
 	 *		@param $period string which can be passed to php's strtotime function (eg "-1 month")
278 278
 	 *		@return stdClass[] with properties regDate and total
279 279
 	*/
280
-	public function get_registrations_per_day_report( $period = '-1 month' ) {
280
+	public function get_registrations_per_day_report($period = '-1 month') {
281 281
 
282
-		$sql_date = $this->convert_datetime_for_query( 'REG_date', date("Y-m-d H:i:s", strtotime($period) ), 'Y-m-d H:i:s', 'UTC' );
283
-		$where = array( 'REG_date' => array( '>=', $sql_date ), 'STS_ID' => array( '!=', EEM_Registration::status_id_incomplete ) );
282
+		$sql_date = $this->convert_datetime_for_query('REG_date', date("Y-m-d H:i:s", strtotime($period)), 'Y-m-d H:i:s', 'UTC');
283
+		$where = array('REG_date' => array('>=', $sql_date), 'STS_ID' => array('!=', EEM_Registration::status_id_incomplete));
284 284
 
285
-		if ( ! EE_Registry::instance()->CAP->current_user_can( 'ee_read_others_registrations', 'reg_per_day_report' ) ) {
285
+		if ( ! EE_Registry::instance()->CAP->current_user_can('ee_read_others_registrations', 'reg_per_day_report')) {
286 286
 			$where['Event.EVT_wp_user'] = get_current_user_id();
287 287
 		}
288 288
 
@@ -294,8 +294,8 @@  discard block
 block discarded – undo
294 294
 				),
295 295
 				OBJECT,
296 296
 				array(
297
-					'regDate'=>array('DATE(Registration.REG_date)','%s'),
298
-					'total'=>array('count(REG_ID)','%d')
297
+					'regDate'=>array('DATE(Registration.REG_date)', '%s'),
298
+					'total'=>array('count(REG_ID)', '%d')
299 299
 				));
300 300
 		return $results;
301 301
 	}
@@ -310,23 +310,23 @@  discard block
 block discarded – undo
310 310
 	 * @param $period string which can be passed to php's strtotime function (eg "-1 month")
311 311
 	 *		@return stdClass[] each with properties event_name, reg_limit, and total
312 312
 	*/
313
-	public function get_registrations_per_event_report( $period = '-1 month' ) {
313
+	public function get_registrations_per_event_report($period = '-1 month') {
314 314
 
315
-		$date_sql = $this->convert_datetime_for_query( 'REG_date', date( "Y-m-d H:i:s", strtotime( $period )), 'Y-m-d H:i:s', 'UTC' );
316
-		$where = array( 'REG_date' => array( '>=', $date_sql ), 'STS_ID' => array( '!=', EEM_Registration::status_id_incomplete ) );
315
+		$date_sql = $this->convert_datetime_for_query('REG_date', date("Y-m-d H:i:s", strtotime($period)), 'Y-m-d H:i:s', 'UTC');
316
+		$where = array('REG_date' => array('>=', $date_sql), 'STS_ID' => array('!=', EEM_Registration::status_id_incomplete));
317 317
 
318
-		if ( ! EE_Registry::instance()->CAP->current_user_can( 'ee_read_others_registrations', 'reg_per_event_report' ) ) {
318
+		if ( ! EE_Registry::instance()->CAP->current_user_can('ee_read_others_registrations', 'reg_per_event_report')) {
319 319
 			$where['Event.EVT_wp_user'] = get_current_user_id();
320 320
 		}
321 321
 		$results = $this->_get_all_wpdb_results(array(
322 322
 			$where,
323 323
 			'group_by'=>'Event.EVT_name',
324 324
 			'order_by'=>'Event.EVT_name',
325
-			'limit'=>array(0,24)),
325
+			'limit'=>array(0, 24)),
326 326
 			OBJECT,
327 327
 			array(
328
-				'event_name'=>array('Event_CPT.post_title','%s'),
329
-				'total'=>array('COUNT(REG_ID)','%s')
328
+				'event_name'=>array('Event_CPT.post_title', '%s'),
329
+				'total'=>array('COUNT(REG_ID)', '%s')
330 330
 			)
331 331
 		);
332 332
 
@@ -340,11 +340,11 @@  discard block
 block discarded – undo
340 340
 	 * @param int $TXN_ID
341 341
 	 * @return EE_Registration
342 342
 	 */
343
-	public function get_primary_registration_for_transaction_ID( $TXN_ID = 0){
344
-		if( ! $TXN_ID ){
343
+	public function get_primary_registration_for_transaction_ID($TXN_ID = 0) {
344
+		if ( ! $TXN_ID) {
345 345
 			return false;
346 346
 		}
347
-		return $this->get_one(array(array('TXN_ID'=>$TXN_ID,'REG_count'=>  EEM_Registration::PRIMARY_REGISTRANT_COUNT)));
347
+		return $this->get_one(array(array('TXN_ID'=>$TXN_ID, 'REG_count'=>  EEM_Registration::PRIMARY_REGISTRANT_COUNT)));
348 348
 	}
349 349
 
350 350
 
@@ -356,11 +356,11 @@  discard block
 block discarded – undo
356 356
 	 *		@param boolean $for_incomplete_payments
357 357
 	 *		@return int
358 358
 	 */
359
-	public function get_event_registration_count ( $EVT_ID, $for_incomplete_payments = FALSE ) {
359
+	public function get_event_registration_count($EVT_ID, $for_incomplete_payments = FALSE) {
360 360
 		// we only count approved registrations towards registration limits
361
-		$query_params = array( array( 'EVT_ID' => $EVT_ID, 'STS_ID' => self::status_id_approved ) );
362
-		if( $for_incomplete_payments ){
363
-			$query_params[0]['Transaction.STS_ID']=array('!=',  EEM_Transaction::complete_status_code);
361
+		$query_params = array(array('EVT_ID' => $EVT_ID, 'STS_ID' => self::status_id_approved));
362
+		if ($for_incomplete_payments) {
363
+			$query_params[0]['Transaction.STS_ID'] = array('!=', EEM_Transaction::complete_status_code);
364 364
 		}
365 365
 
366 366
 		return $this->count($query_params);
@@ -376,7 +376,7 @@  discard block
 block discarded – undo
376 376
 		/** @type WPDB $wpdb */
377 377
 		global $wpdb;
378 378
 		return $wpdb->query(
379
-				'DELETE r FROM ' . $this->table() . ' r LEFT JOIN ' . EEM_Transaction::instance()->table() . ' t ON r.TXN_ID = t.TXN_ID WHERE t.TXN_ID IS NULL' );
379
+				'DELETE r FROM '.$this->table().' r LEFT JOIN '.EEM_Transaction::instance()->table().' t ON r.TXN_ID = t.TXN_ID WHERE t.TXN_ID IS NULL' );
380 380
 	}
381 381
 
382 382
 
Please login to merge, or discard this patch.
core/helpers/EEH_Line_Item.helper.php 2 patches
Indentation   +31 added lines, -31 removed lines patch added patch discarded remove patch
@@ -468,15 +468,15 @@  discard block
 block discarded – undo
468 468
 	}
469 469
 
470 470
 	/**
471
-	  * Given the grand total line item and a ticket, finds the event sub-total
472
-	  * line item the ticket's purchase should be added onto
473
-	  *
474
-	  * @access public
475
-	  * @param EE_Line_Item $grand_total the grand total line item
476
-	  * @param EE_Ticket $ticket
477
-	  * @throws \EE_Error
478
-	  * @return EE_Line_Item
479
-	  */
471
+	 * Given the grand total line item and a ticket, finds the event sub-total
472
+	 * line item the ticket's purchase should be added onto
473
+	 *
474
+	 * @access public
475
+	 * @param EE_Line_Item $grand_total the grand total line item
476
+	 * @param EE_Ticket $ticket
477
+	 * @throws \EE_Error
478
+	 * @return EE_Line_Item
479
+	 */
480 480
 	public static function get_event_line_item_for_ticket( EE_Line_Item $grand_total, EE_Ticket $ticket ) {
481 481
 		$first_datetime = $ticket->first_datetime();
482 482
 		if( ! $first_datetime instanceof EE_Datetime ){
@@ -685,21 +685,21 @@  discard block
 block discarded – undo
685 685
 	 * @return EE_Line_Item the new tax line item created
686 686
 	 */
687 687
 	public static function set_total_tax_to( EE_Line_Item $total_line_item, $amount, $name = NULL, $description = NULL, $code = NULL, $add_to_existing_line_item = false ){
688
-            $tax_subtotal = self::get_taxes_subtotal( $total_line_item );
689
-            $taxable_total = $total_line_item->taxable_total();
690
-
691
-            if( $add_to_existing_line_item ) {
692
-                $new_tax = $tax_subtotal->get_child_line_item( $code );
693
-                EEM_Line_Item::instance()->delete( array( array( 'LIN_code' => array( '!=', $code ), 'LIN_parent' => $tax_subtotal->ID() ) ) );
694
-            } else {
695
-                $new_tax = null;
696
-                $tax_subtotal->delete_children_line_items();
697
-            }
698
-            if( $new_tax ) {
699
-                $new_tax->set_total( $new_tax->total() + $amount );
700
-                $new_tax->set_percent( $taxable_total ? ( $new_tax->total() ) / $taxable_total * 100 : 0 );
701
-            } else {
702
-                //no existing tax item. Create it
688
+			$tax_subtotal = self::get_taxes_subtotal( $total_line_item );
689
+			$taxable_total = $total_line_item->taxable_total();
690
+
691
+			if( $add_to_existing_line_item ) {
692
+				$new_tax = $tax_subtotal->get_child_line_item( $code );
693
+				EEM_Line_Item::instance()->delete( array( array( 'LIN_code' => array( '!=', $code ), 'LIN_parent' => $tax_subtotal->ID() ) ) );
694
+			} else {
695
+				$new_tax = null;
696
+				$tax_subtotal->delete_children_line_items();
697
+			}
698
+			if( $new_tax ) {
699
+				$new_tax->set_total( $new_tax->total() + $amount );
700
+				$new_tax->set_percent( $taxable_total ? ( $new_tax->total() ) / $taxable_total * 100 : 0 );
701
+			} else {
702
+				//no existing tax item. Create it
703 703
 				$new_tax = EE_Line_Item::new_instance( array(
704 704
 					'TXN_ID'      => $total_line_item->TXN_ID(),
705 705
 					'LIN_name'    => $name ? $name : __( 'Tax', 'event_espresso' ),
@@ -712,16 +712,16 @@  discard block
 block discarded – undo
712 712
 				) );
713 713
 			}
714 714
 
715
-            $new_tax = apply_filters(
715
+			$new_tax = apply_filters(
716 716
 				'FHEE__EEH_Line_Item__set_total_tax_to__new_tax_subtotal',
717 717
 				$new_tax,
718 718
 				$total_line_item
719
-            );
720
-            $new_tax->save();
721
-            $tax_subtotal->set_total( $new_tax->total() );
722
-            $tax_subtotal->save();
723
-            $total_line_item->recalculate_total_including_taxes();
724
-            return $new_tax;
719
+			);
720
+			$new_tax->save();
721
+			$tax_subtotal->set_total( $new_tax->total() );
722
+			$tax_subtotal->save();
723
+			$total_line_item->recalculate_total_including_taxes();
724
+			return $new_tax;
725 725
 	}
726 726
 
727 727
 
Please login to merge, or discard this patch.
Spacing   +294 added lines, -294 removed lines patch added patch discarded remove patch
@@ -1,4 +1,4 @@  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')) { exit('No direct script access allowed'); }
2 2
 /**
3 3
  *
4 4
  * EEH_Line_Item
@@ -40,8 +40,8 @@  discard block
 block discarded – undo
40 40
 	 * @param boolean $code if set to a value, ensures there is only one line item with that code
41 41
 	 * @return boolean success
42 42
 	 */
43
-	public static function add_unrelated_item( EE_Line_Item $parent_line_item, $name, $unit_price, $description = '', $quantity = 1, $taxable = FALSE, $code = NULL  ){
44
-		$items_subtotal = self::get_pre_tax_subtotal( $parent_line_item );
43
+	public static function add_unrelated_item(EE_Line_Item $parent_line_item, $name, $unit_price, $description = '', $quantity = 1, $taxable = FALSE, $code = NULL) {
44
+		$items_subtotal = self::get_pre_tax_subtotal($parent_line_item);
45 45
 		$line_item = EE_Line_Item::new_instance(array(
46 46
 			'LIN_name' => $name,
47 47
 			'LIN_desc' => $description,
@@ -49,8 +49,8 @@  discard block
 block discarded – undo
49 49
 			'LIN_quantity' => $quantity,
50 50
 			'LIN_percent' => null,
51 51
 			'LIN_is_taxable' => $taxable,
52
-			'LIN_order' => $items_subtotal instanceof EE_Line_Item ? count( $items_subtotal->children() ) : 0,
53
-			'LIN_total' => floatval( $unit_price ) * intval( $quantity ),
52
+			'LIN_order' => $items_subtotal instanceof EE_Line_Item ? count($items_subtotal->children()) : 0,
53
+			'LIN_total' => floatval($unit_price) * intval($quantity),
54 54
 			'LIN_type'=>  EEM_Line_Item::type_line_item,
55 55
 			'LIN_code' => $code,
56 56
 		));
@@ -59,7 +59,7 @@  discard block
 block discarded – undo
59 59
 			$line_item,
60 60
 			$parent_line_item
61 61
 		);
62
-		return self::add_item( $parent_line_item, $line_item );
62
+		return self::add_item($parent_line_item, $line_item);
63 63
 	}
64 64
 
65 65
 
@@ -80,7 +80,7 @@  discard block
 block discarded – undo
80 80
 	 * @param boolean      $taxable
81 81
 	 * @return boolean success
82 82
 	 */
83
-	public static function add_percentage_based_item( EE_Line_Item $parent_line_item, $name, $percentage_amount, $description = '', $taxable = FALSE ){
83
+	public static function add_percentage_based_item(EE_Line_Item $parent_line_item, $name, $percentage_amount, $description = '', $taxable = FALSE) {
84 84
 		$line_item = EE_Line_Item::new_instance(array(
85 85
 			'LIN_name' => $name,
86 86
 			'LIN_desc' => $description,
@@ -88,7 +88,7 @@  discard block
 block discarded – undo
88 88
 			'LIN_percent' => $percentage_amount,
89 89
 			'LIN_quantity' => NULL,
90 90
 			'LIN_is_taxable' => $taxable,
91
-			'LIN_total' => floatval( $percentage_amount * ( $parent_line_item->total() / 100 )),
91
+			'LIN_total' => floatval($percentage_amount * ($parent_line_item->total() / 100)),
92 92
 			'LIN_type'=>  EEM_Line_Item::type_line_item,
93 93
 			'LIN_parent' => $parent_line_item->ID()
94 94
 		));
@@ -96,7 +96,7 @@  discard block
 block discarded – undo
96 96
 			'FHEE__EEH_Line_Item__add_percentage_based_item__line_item',
97 97
 			$line_item
98 98
 		);
99
-		return self::add_item( $parent_line_item, $line_item );
99
+		return self::add_item($parent_line_item, $line_item);
100 100
 	}
101 101
 
102 102
 
@@ -117,15 +117,15 @@  discard block
 block discarded – undo
117 117
 	 * @return \EE_Line_Item
118 118
 	 * @throws \EE_Error
119 119
 	 */
120
-	public static function add_ticket_purchase( EE_Line_Item $total_line_item, EE_Ticket $ticket, $qty = 1 ){
121
-		if ( ! $total_line_item instanceof EE_Line_Item || ! $total_line_item->is_total() ) {
122
-			throw new EE_Error( sprintf( __( 'A valid line item total is required in order to add tickets. A line item of type "%s" was passed.', 'event_espresso' ), $ticket->ID(), $total_line_item->ID() ) );
120
+	public static function add_ticket_purchase(EE_Line_Item $total_line_item, EE_Ticket $ticket, $qty = 1) {
121
+		if ( ! $total_line_item instanceof EE_Line_Item || ! $total_line_item->is_total()) {
122
+			throw new EE_Error(sprintf(__('A valid line item total is required in order to add tickets. A line item of type "%s" was passed.', 'event_espresso'), $ticket->ID(), $total_line_item->ID()));
123 123
 		}
124 124
 		// either increment the qty for an existing ticket
125
-		$line_item = self::increment_ticket_qty_if_already_in_cart( $total_line_item, $ticket, $qty );
125
+		$line_item = self::increment_ticket_qty_if_already_in_cart($total_line_item, $ticket, $qty);
126 126
 		// or add a new one
127
-		if ( ! $line_item instanceof EE_Line_Item ) {
128
-			$line_item = self::create_ticket_line_item( $total_line_item, $ticket, $qty );
127
+		if ( ! $line_item instanceof EE_Line_Item) {
128
+			$line_item = self::create_ticket_line_item($total_line_item, $ticket, $qty);
129 129
 		}
130 130
 		$total_line_item->recalculate_total_including_taxes();
131 131
 		return $line_item;
@@ -141,19 +141,19 @@  discard block
 block discarded – undo
141 141
 	 * @return \EE_Line_Item
142 142
 	 * @throws \EE_Error
143 143
 	 */
144
-	public static function increment_ticket_qty_if_already_in_cart( EE_Line_Item $total_line_item, EE_Ticket $ticket, $qty = 1 ) {
144
+	public static function increment_ticket_qty_if_already_in_cart(EE_Line_Item $total_line_item, EE_Ticket $ticket, $qty = 1) {
145 145
 		$line_item = null;
146
-		if ( $total_line_item instanceof EE_Line_Item && $total_line_item->is_total() ) {
147
-			$ticket_line_items = EEH_Line_Item::get_ticket_line_items( $total_line_item );
148
-			foreach ( (array)$ticket_line_items as $ticket_line_item ) {
149
-				if ( $ticket_line_item instanceof EE_Line_Item && $ticket_line_item->OBJ_ID() == $ticket->ID() ) {
146
+		if ($total_line_item instanceof EE_Line_Item && $total_line_item->is_total()) {
147
+			$ticket_line_items = EEH_Line_Item::get_ticket_line_items($total_line_item);
148
+			foreach ((array) $ticket_line_items as $ticket_line_item) {
149
+				if ($ticket_line_item instanceof EE_Line_Item && $ticket_line_item->OBJ_ID() == $ticket->ID()) {
150 150
 					$line_item = $ticket_line_item;
151 151
 					break;
152 152
 				}
153 153
 			}
154 154
 		}
155
-		if ( $line_item instanceof EE_Line_Item ) {
156
-			EEH_Line_Item::increment_quantity( $line_item, $qty );
155
+		if ($line_item instanceof EE_Line_Item) {
156
+			EEH_Line_Item::increment_quantity($line_item, $qty);
157 157
 			return $line_item;
158 158
 		}
159 159
 		return null;
@@ -166,15 +166,15 @@  discard block
 block discarded – undo
166 166
 	 * @param int $qty
167 167
 	 * @return void
168 168
 	 */
169
-	public static function increment_quantity( EE_Line_Item $line_item, $qty = 1 ) {
170
-		if( ! $line_item->is_percent() ) {
169
+	public static function increment_quantity(EE_Line_Item $line_item, $qty = 1) {
170
+		if ( ! $line_item->is_percent()) {
171 171
 			$qty += $line_item->quantity();
172
-			$line_item->set_quantity( $qty );
173
-			$line_item->set_total( $line_item->unit_price() * $qty );
172
+			$line_item->set_quantity($qty);
173
+			$line_item->set_total($line_item->unit_price() * $qty);
174 174
 		}
175
-		foreach( $line_item->children() as $child ) {
176
-			if( $child->is_sub_line_item() ) {
177
-				EEH_Line_Item::update_quantity( $child, $line_item->quantity() );
175
+		foreach ($line_item->children() as $child) {
176
+			if ($child->is_sub_line_item()) {
177
+				EEH_Line_Item::update_quantity($child, $line_item->quantity());
178 178
 			}
179 179
 		}
180 180
 	}
@@ -185,14 +185,14 @@  discard block
 block discarded – undo
185 185
 	 * @param EE_Line_Item $line_item
186 186
 	 * @param int $new_quantity
187 187
 	 */
188
-	public static function update_quantity( EE_Line_Item $line_item, $new_quantity ) {
189
-		if( ! $line_item->is_percent() ) {
190
-			$line_item->set_quantity( $new_quantity );
191
-			$line_item->set_total( $line_item->unit_price() * $new_quantity );
188
+	public static function update_quantity(EE_Line_Item $line_item, $new_quantity) {
189
+		if ( ! $line_item->is_percent()) {
190
+			$line_item->set_quantity($new_quantity);
191
+			$line_item->set_total($line_item->unit_price() * $new_quantity);
192 192
 		}
193
-		foreach( $line_item->children() as $child ) {
194
-			if( $child->is_sub_line_item() ) {
195
-				EEH_Line_Item::update_quantity( $child, $new_quantity );
193
+		foreach ($line_item->children() as $child) {
194
+			if ($child->is_sub_line_item()) {
195
+				EEH_Line_Item::update_quantity($child, $new_quantity);
196 196
 			}
197 197
 		}
198 198
 	}
@@ -207,45 +207,45 @@  discard block
 block discarded – undo
207 207
 	 * @return \EE_Line_Item
208 208
 	 * @throws \EE_Error
209 209
 	 */
210
-	public static function create_ticket_line_item( EE_Line_Item $total_line_item, EE_Ticket $ticket, $qty = 1 ) {
210
+	public static function create_ticket_line_item(EE_Line_Item $total_line_item, EE_Ticket $ticket, $qty = 1) {
211 211
 		$datetimes = $ticket->datetimes();
212
-		$first_datetime = reset( $datetimes );
213
-		if( $first_datetime instanceof EE_Datetime &&
214
-				$first_datetime->event() instanceof EE_Event ) {
212
+		$first_datetime = reset($datetimes);
213
+		if ($first_datetime instanceof EE_Datetime &&
214
+				$first_datetime->event() instanceof EE_Event) {
215 215
 			$first_datetime_name = $first_datetime->event()->name();
216 216
 		} else {
217
-			$first_datetime_name = __( 'Event', 'event_espresso' );
217
+			$first_datetime_name = __('Event', 'event_espresso');
218 218
 		}
219
-		$event = sprintf( _x( '(For %1$s)', '(For Event Name)', 'event_espresso' ), $first_datetime_name );
219
+		$event = sprintf(_x('(For %1$s)', '(For Event Name)', 'event_espresso'), $first_datetime_name);
220 220
 		// get event subtotal line
221
-		$events_sub_total = self::get_event_line_item_for_ticket( $total_line_item, $ticket );
222
-		if ( ! $events_sub_total instanceof EE_Line_Item ) {
223
-			throw new EE_Error( sprintf( __( 'There is no events sub-total for ticket %s on total line item %d', 'event_espresso' ), $ticket->ID(), $total_line_item->ID() ) );
221
+		$events_sub_total = self::get_event_line_item_for_ticket($total_line_item, $ticket);
222
+		if ( ! $events_sub_total instanceof EE_Line_Item) {
223
+			throw new EE_Error(sprintf(__('There is no events sub-total for ticket %s on total line item %d', 'event_espresso'), $ticket->ID(), $total_line_item->ID()));
224 224
 		}
225 225
 		// add $ticket to cart
226
-		$line_item = EE_Line_Item::new_instance( array(
226
+		$line_item = EE_Line_Item::new_instance(array(
227 227
 			'LIN_name'       	=> $ticket->name(),
228
-			'LIN_desc'       		=> $ticket->description() != '' ? $ticket->description() . ' ' . $event : $event,
228
+			'LIN_desc'       		=> $ticket->description() != '' ? $ticket->description().' '.$event : $event,
229 229
 			'LIN_unit_price' 	=> $ticket->price(),
230 230
 			'LIN_quantity'   	=> $qty,
231 231
 			'LIN_is_taxable' 	=> $ticket->taxable(),
232
-			'LIN_order'      	=> count( $events_sub_total->children() ),
232
+			'LIN_order'      	=> count($events_sub_total->children()),
233 233
 			'LIN_total'      		=> $ticket->price() * $qty,
234 234
 			'LIN_type'       		=> EEM_Line_Item::type_line_item,
235 235
 			'OBJ_ID'         		=> $ticket->ID(),
236 236
 			'OBJ_type'       	=> 'Ticket'
237
-		) );
237
+		));
238 238
 		$line_item = apply_filters(
239 239
 			'FHEE__EEH_Line_Item__create_ticket_line_item__line_item',
240 240
 			$line_item
241 241
 		);
242
-		$events_sub_total->add_child_line_item( $line_item );
242
+		$events_sub_total->add_child_line_item($line_item);
243 243
 		//now add the sub-line items
244 244
 		$running_total_for_ticket = 0;
245
-		foreach ( $ticket->prices( array( 'order_by' => array( 'PRC_order' => 'ASC' ) ) ) as $price ) {
245
+		foreach ($ticket->prices(array('order_by' => array('PRC_order' => 'ASC'))) as $price) {
246 246
 			$sign = $price->is_discount() ? -1 : 1;
247 247
 			$price_total = $price->is_percent() ? $running_total_for_ticket * $price->amount() / 100 : $price->amount() * $qty;
248
-			$sub_line_item = EE_Line_Item::new_instance( array(
248
+			$sub_line_item = EE_Line_Item::new_instance(array(
249 249
 				'LIN_name'       	=> $price->name(),
250 250
 				'LIN_desc'       		=> $price->desc(),
251 251
 				'LIN_quantity'   	=> $price->is_percent() ? null : $qty,
@@ -255,18 +255,18 @@  discard block
 block discarded – undo
255 255
 				'LIN_type'       		=> EEM_Line_Item::type_sub_line_item,
256 256
 				'OBJ_ID'         		=> $price->ID(),
257 257
 				'OBJ_type'       	=> 'Price'
258
-			) );
258
+			));
259 259
 			$sub_line_item = apply_filters(
260 260
 				'FHEE__EEH_Line_Item__create_ticket_line_item__sub_line_item',
261 261
 				$sub_line_item
262 262
 			);
263
-			if ( $price->is_percent() ) {
264
-				$sub_line_item->set_percent( $sign * $price->amount() );
263
+			if ($price->is_percent()) {
264
+				$sub_line_item->set_percent($sign * $price->amount());
265 265
 			} else {
266
-				$sub_line_item->set_unit_price( $sign * $price->amount() );
266
+				$sub_line_item->set_unit_price($sign * $price->amount());
267 267
 			}
268 268
 			$running_total_for_ticket += $price_total;
269
-			$line_item->add_child_line_item( $sub_line_item );
269
+			$line_item->add_child_line_item($sub_line_item);
270 270
 		}
271 271
 		return $line_item;
272 272
 	}
@@ -284,11 +284,11 @@  discard block
 block discarded – undo
284 284
 	 * @param EE_Line_Item $item to be added
285 285
 	 * @return boolean
286 286
 	 */
287
-	public static function add_item( EE_Line_Item $total_line_item, EE_Line_Item $item ){
288
-		$pre_tax_subtotal = self::get_pre_tax_subtotal( $total_line_item );
289
-		if ( $pre_tax_subtotal instanceof EE_Line_Item ){
287
+	public static function add_item(EE_Line_Item $total_line_item, EE_Line_Item $item) {
288
+		$pre_tax_subtotal = self::get_pre_tax_subtotal($total_line_item);
289
+		if ($pre_tax_subtotal instanceof EE_Line_Item) {
290 290
 			$success = $pre_tax_subtotal->add_child_line_item($item);
291
-		}else{
291
+		} else {
292 292
 			return FALSE;
293 293
 		}
294 294
 		$total_line_item->recalculate_total_including_taxes();
@@ -302,9 +302,9 @@  discard block
 block discarded – undo
302 302
 	 * @param EE_Line_Item $total_line_item of type EEM_Line_Item::type_total
303 303
 	 *	@return \EE_Line_Item
304 304
 	 */
305
-	public static function get_pre_tax_subtotal( EE_Line_Item $total_line_item ){
306
-		$pre_tax_subtotal = $total_line_item->get_child_line_item( 'pre-tax-subtotal' );
307
-		return $pre_tax_subtotal instanceof EE_Line_Item ? $pre_tax_subtotal : self::create_pre_tax_subtotal( $total_line_item );
305
+	public static function get_pre_tax_subtotal(EE_Line_Item $total_line_item) {
306
+		$pre_tax_subtotal = $total_line_item->get_child_line_item('pre-tax-subtotal');
307
+		return $pre_tax_subtotal instanceof EE_Line_Item ? $pre_tax_subtotal : self::create_pre_tax_subtotal($total_line_item);
308 308
 	}
309 309
 
310 310
 
@@ -314,9 +314,9 @@  discard block
 block discarded – undo
314 314
 	 * @param EE_Line_Item $total_line_item of type EEM_Line_Item::type_total
315 315
 	 * @return \EE_Line_Item
316 316
 	 */
317
-	public static function get_taxes_subtotal( EE_Line_Item $total_line_item ){
318
-		$taxes = $total_line_item->get_child_line_item( 'taxes' );
319
-		return $taxes ? $taxes : self::create_taxes_subtotal( $total_line_item );
317
+	public static function get_taxes_subtotal(EE_Line_Item $total_line_item) {
318
+		$taxes = $total_line_item->get_child_line_item('taxes');
319
+		return $taxes ? $taxes : self::create_taxes_subtotal($total_line_item);
320 320
 	}
321 321
 
322 322
 
@@ -327,12 +327,12 @@  discard block
 block discarded – undo
327 327
 	 * @param EE_Transaction $transaction
328 328
 	 * @return void
329 329
 	 */
330
-	public static function set_TXN_ID( EE_Line_Item $line_item, $transaction = NULL ){
331
-		if( $transaction ){
330
+	public static function set_TXN_ID(EE_Line_Item $line_item, $transaction = NULL) {
331
+		if ($transaction) {
332 332
 			/** @type EEM_Transaction $EEM_Transaction */
333
-			$EEM_Transaction = EE_Registry::instance()->load_model( 'Transaction' );
334
-			$transaction = $EEM_Transaction->ensure_is_ID( $transaction );
335
-			$line_item->set_TXN_ID( $transaction );
333
+			$EEM_Transaction = EE_Registry::instance()->load_model('Transaction');
334
+			$transaction = $EEM_Transaction->ensure_is_ID($transaction);
335
+			$line_item->set_TXN_ID($transaction);
336 336
 		}
337 337
 	}
338 338
 
@@ -345,8 +345,8 @@  discard block
 block discarded – undo
345 345
 	 * @param EE_Transaction $transaction
346 346
 	 * @return \EE_Line_Item of type total
347 347
 	 */
348
-	public static function create_total_line_item( $transaction = NULL ){
349
-		$total_line_item = EE_Line_Item::new_instance( array(
348
+	public static function create_total_line_item($transaction = NULL) {
349
+		$total_line_item = EE_Line_Item::new_instance(array(
350 350
 			'LIN_code'	=> 'total',
351 351
 			'LIN_name'	=> __('Grand Total', 'event_espresso'),
352 352
 			'LIN_type'	=> EEM_Line_Item::type_total,
@@ -356,9 +356,9 @@  discard block
 block discarded – undo
356 356
 			'FHEE__EEH_Line_Item__create_total_line_item__total_line_item',
357 357
 			$total_line_item
358 358
 		);
359
-		self::set_TXN_ID( $total_line_item, $transaction );
360
-		self::create_pre_tax_subtotal( $total_line_item, $transaction );
361
-		self::create_taxes_subtotal( $total_line_item, $transaction );
359
+		self::set_TXN_ID($total_line_item, $transaction);
360
+		self::create_pre_tax_subtotal($total_line_item, $transaction);
361
+		self::create_taxes_subtotal($total_line_item, $transaction);
362 362
 		return $total_line_item;
363 363
 	}
364 364
 
@@ -370,19 +370,19 @@  discard block
 block discarded – undo
370 370
 	 * @param EE_Transaction $transaction
371 371
 	 * @return EE_Line_Item
372 372
 	 */
373
-	protected static function create_pre_tax_subtotal( EE_Line_Item $total_line_item, $transaction = NULL ){
374
-		$pre_tax_line_item = EE_Line_Item::new_instance( array(
373
+	protected static function create_pre_tax_subtotal(EE_Line_Item $total_line_item, $transaction = NULL) {
374
+		$pre_tax_line_item = EE_Line_Item::new_instance(array(
375 375
 			'LIN_code' 	=> 'pre-tax-subtotal',
376
-			'LIN_name' 	=> __( 'Pre-Tax Subtotal', 'event_espresso' ),
376
+			'LIN_name' 	=> __('Pre-Tax Subtotal', 'event_espresso'),
377 377
 			'LIN_type' 	=> EEM_Line_Item::type_sub_total
378
-		) );
378
+		));
379 379
 		$pre_tax_line_item = apply_filters(
380 380
 			'FHEE__EEH_Line_Item__create_pre_tax_subtotal__pre_tax_line_item',
381 381
 			$pre_tax_line_item
382 382
 		);
383
-		self::set_TXN_ID( $pre_tax_line_item, $transaction );
384
-		$total_line_item->add_child_line_item( $pre_tax_line_item );
385
-		self::create_event_subtotal( $pre_tax_line_item, $transaction );
383
+		self::set_TXN_ID($pre_tax_line_item, $transaction);
384
+		$total_line_item->add_child_line_item($pre_tax_line_item);
385
+		self::create_event_subtotal($pre_tax_line_item, $transaction);
386 386
 		return $pre_tax_line_item;
387 387
 	}
388 388
 
@@ -395,21 +395,21 @@  discard block
 block discarded – undo
395 395
 	 * @param EE_Transaction $transaction
396 396
 	 * @return EE_Line_Item
397 397
 	 */
398
-	protected static function create_taxes_subtotal( EE_Line_Item $total_line_item, $transaction = NULL ){
398
+	protected static function create_taxes_subtotal(EE_Line_Item $total_line_item, $transaction = NULL) {
399 399
 		$tax_line_item = EE_Line_Item::new_instance(array(
400 400
 			'LIN_code'	=> 'taxes',
401 401
 			'LIN_name' 	=> __('Taxes', 'event_espresso'),
402 402
 			'LIN_type'	=> EEM_Line_Item::type_tax_sub_total,
403
-			'LIN_order' => 1000,//this should always come last
403
+			'LIN_order' => 1000, //this should always come last
404 404
 		));
405 405
 		$tax_line_item = apply_filters(
406 406
 			'FHEE__EEH_Line_Item__create_taxes_subtotal__tax_line_item',
407 407
 			$tax_line_item
408 408
 		);
409
-		self::set_TXN_ID( $tax_line_item, $transaction );
410
-		$total_line_item->add_child_line_item( $tax_line_item );
409
+		self::set_TXN_ID($tax_line_item, $transaction);
410
+		$total_line_item->add_child_line_item($tax_line_item);
411 411
 		//and lastly, add the actual taxes
412
-		self::apply_taxes( $total_line_item );
412
+		self::apply_taxes($total_line_item);
413 413
 		return $tax_line_item;
414 414
 	}
415 415
 
@@ -422,11 +422,11 @@  discard block
 block discarded – undo
422 422
 	 * @param EE_Event $event
423 423
 	 * @return EE_Line_Item
424 424
 	 */
425
-	public static function create_event_subtotal( EE_Line_Item $pre_tax_line_item, $transaction = NULL, $event = NULL ){
425
+	public static function create_event_subtotal(EE_Line_Item $pre_tax_line_item, $transaction = NULL, $event = NULL) {
426 426
 		$event_line_item = EE_Line_Item::new_instance(array(
427
-			'LIN_code'	=> self::get_event_code( $event ),
428
-			'LIN_name' 	=> self::get_event_name( $event ),
429
-			'LIN_desc' 	=> self::get_event_desc( $event ),
427
+			'LIN_code'	=> self::get_event_code($event),
428
+			'LIN_name' 	=> self::get_event_name($event),
429
+			'LIN_desc' 	=> self::get_event_desc($event),
430 430
 			'LIN_type'	=> EEM_Line_Item::type_sub_total,
431 431
 			'OBJ_type' 	=> 'Event',
432 432
 			'OBJ_ID' 		=>  $event instanceof EE_Event ? $event->ID() : 0
@@ -435,8 +435,8 @@  discard block
 block discarded – undo
435 435
 			'FHEE__EEH_Line_Item__create_event_subtotal__event_line_item',
436 436
 			$event_line_item
437 437
 		);
438
-		self::set_TXN_ID( $event_line_item, $transaction );
439
-		$pre_tax_line_item->add_child_line_item( $event_line_item );
438
+		self::set_TXN_ID($event_line_item, $transaction);
439
+		$pre_tax_line_item->add_child_line_item($event_line_item);
440 440
 		return $event_line_item;
441 441
 	}
442 442
 
@@ -445,8 +445,8 @@  discard block
 block discarded – undo
445 445
 	 * @param EE_Event $event
446 446
 	 * @return string
447 447
 	 */
448
-	public static function get_event_code( $event ) {
449
-		return 'event-' . ( $event instanceof EE_Event ? $event->ID() : '0' );
448
+	public static function get_event_code($event) {
449
+		return 'event-'.($event instanceof EE_Event ? $event->ID() : '0');
450 450
 	}
451 451
 
452 452
 	/**
@@ -454,8 +454,8 @@  discard block
 block discarded – undo
454 454
 	 * @param EE_Event $event
455 455
 	 * @return string
456 456
 	 */
457
-	public static function get_event_name( $event ) {
458
-		return $event instanceof EE_Event ? $event->name() : __( 'Event', 'event_espresso' );
457
+	public static function get_event_name($event) {
458
+		return $event instanceof EE_Event ? $event->name() : __('Event', 'event_espresso');
459 459
 	}
460 460
 
461 461
 	/**
@@ -463,7 +463,7 @@  discard block
 block discarded – undo
463 463
 	 * @param EE_Event $event
464 464
 	 * @return string
465 465
 	 */
466
-	public static function get_event_desc( $event ) {
466
+	public static function get_event_desc($event) {
467 467
 		return $event instanceof EE_Event ? $event->short_description() : '';
468 468
 	}
469 469
 
@@ -477,16 +477,16 @@  discard block
 block discarded – undo
477 477
 	  * @throws \EE_Error
478 478
 	  * @return EE_Line_Item
479 479
 	  */
480
-	public static function get_event_line_item_for_ticket( EE_Line_Item $grand_total, EE_Ticket $ticket ) {
480
+	public static function get_event_line_item_for_ticket(EE_Line_Item $grand_total, EE_Ticket $ticket) {
481 481
 		$first_datetime = $ticket->first_datetime();
482
-		if( ! $first_datetime instanceof EE_Datetime ){
483
-			throw new EE_Error( sprintf( __( 'The supplied ticket (ID %d) has no datetimes', 'event_espresso' ), $ticket->ID() ) );
482
+		if ( ! $first_datetime instanceof EE_Datetime) {
483
+			throw new EE_Error(sprintf(__('The supplied ticket (ID %d) has no datetimes', 'event_espresso'), $ticket->ID()));
484 484
 		}
485 485
 		$event = $first_datetime->event();
486
-		if ( ! $event instanceof EE_Event ) {
487
-			throw new EE_Error( sprintf( __( 'The supplied ticket (ID %d) has no event data associated with it.','event_espresso' ), $ticket->ID() ) );
486
+		if ( ! $event instanceof EE_Event) {
487
+			throw new EE_Error(sprintf(__('The supplied ticket (ID %d) has no event data associated with it.', 'event_espresso'), $ticket->ID()));
488 488
 		}
489
-		return EEH_Line_Item::get_event_line_item( $grand_total, $event );
489
+		return EEH_Line_Item::get_event_line_item($grand_total, $event);
490 490
 	}
491 491
 
492 492
 	/**
@@ -495,31 +495,31 @@  discard block
 block discarded – undo
495 495
 	 * @param EE_Event $event
496 496
 	 * @return EE_Line_Item for the event subtotal which is a child of $grand_total
497 497
 	 */
498
-	public static function get_event_line_item( EE_Line_Item $grand_total, $event ) {
498
+	public static function get_event_line_item(EE_Line_Item $grand_total, $event) {
499 499
 		/** @type EE_Event $event */
500
-		$event = EEM_Event::instance()->ensure_is_obj( $event, true );
500
+		$event = EEM_Event::instance()->ensure_is_obj($event, true);
501 501
 		$event_line_item = NULL;
502 502
 		$found = false;
503
-		foreach ( EEH_Line_Item::get_event_subtotals( $grand_total ) as $event_line_item ) {
503
+		foreach (EEH_Line_Item::get_event_subtotals($grand_total) as $event_line_item) {
504 504
 			// default event subtotal, we should only ever find this the first time this method is called
505
-			if ( ! $event_line_item->OBJ_ID() ) {
505
+			if ( ! $event_line_item->OBJ_ID()) {
506 506
 				// let's use this! but first... set the event details
507
-				EEH_Line_Item::set_event_subtotal_details( $event_line_item, $event );
507
+				EEH_Line_Item::set_event_subtotal_details($event_line_item, $event);
508 508
 				$found = true;
509 509
 				break;
510
-			} else if ( $event_line_item->OBJ_ID() === $event->ID() ) {
510
+			} else if ($event_line_item->OBJ_ID() === $event->ID()) {
511 511
 				// found existing line item for this event in the cart, so break out of loop and use this one
512 512
 				$found = true;
513 513
 				break;
514 514
 			}
515 515
 		}
516
-		if ( ! $found ) {
516
+		if ( ! $found) {
517 517
 			//there is no event sub-total yet, so add it
518
-			$pre_tax_subtotal = EEH_Line_Item::get_pre_tax_subtotal( $grand_total );
518
+			$pre_tax_subtotal = EEH_Line_Item::get_pre_tax_subtotal($grand_total);
519 519
 			// create a new "event" subtotal below that
520
-			$event_line_item = EEH_Line_Item::create_event_subtotal( $pre_tax_subtotal, null, $event );
520
+			$event_line_item = EEH_Line_Item::create_event_subtotal($pre_tax_subtotal, null, $event);
521 521
 			// and set the event details
522
-			EEH_Line_Item::set_event_subtotal_details( $event_line_item, $event );
522
+			EEH_Line_Item::set_event_subtotal_details($event_line_item, $event);
523 523
 		}
524 524
 		return $event_line_item;
525 525
 	}
@@ -533,14 +533,14 @@  discard block
 block discarded – undo
533 533
 	 * @param EE_Transaction $transaction
534 534
 	 * @return EE_Line_Item
535 535
 	 */
536
-	public static function set_event_subtotal_details( EE_Line_Item $event_line_item, EE_Event $event, $transaction = NULL ){
537
-		if ( $event instanceof EE_Event ) {
538
-			$event_line_item->set_code( self::get_event_code( $event ) );
539
-			$event_line_item->set_name( self::get_event_name( $event ) );
540
-			$event_line_item->set_desc( self::get_event_desc( $event ) );
541
-			$event_line_item->set_OBJ_ID( $event->ID() );
536
+	public static function set_event_subtotal_details(EE_Line_Item $event_line_item, EE_Event $event, $transaction = NULL) {
537
+		if ($event instanceof EE_Event) {
538
+			$event_line_item->set_code(self::get_event_code($event));
539
+			$event_line_item->set_name(self::get_event_name($event));
540
+			$event_line_item->set_desc(self::get_event_desc($event));
541
+			$event_line_item->set_OBJ_ID($event->ID());
542 542
 		}
543
-		self::set_TXN_ID( $event_line_item, $transaction );
543
+		self::set_TXN_ID($event_line_item, $transaction);
544 544
 	}
545 545
 
546 546
 
@@ -551,19 +551,19 @@  discard block
 block discarded – undo
551 551
 	 * any old taxes are removed
552 552
 	 * @param EE_Line_Item $total_line_item of type EEM_Line_Item::type_total
553 553
 	 */
554
-	public static function apply_taxes( EE_Line_Item $total_line_item ){
554
+	public static function apply_taxes(EE_Line_Item $total_line_item) {
555 555
 		/** @type EEM_Price $EEM_Price */
556
-		$EEM_Price = EE_Registry::instance()->load_model( 'Price' );
556
+		$EEM_Price = EE_Registry::instance()->load_model('Price');
557 557
 		// get array of taxes via Price Model
558 558
 		$ordered_taxes = $EEM_Price->get_all_prices_that_are_taxes();
559
-		ksort( $ordered_taxes );
560
-		$taxes_line_item = self::get_taxes_subtotal( $total_line_item );
559
+		ksort($ordered_taxes);
560
+		$taxes_line_item = self::get_taxes_subtotal($total_line_item);
561 561
 		//just to be safe, remove its old tax line items
562 562
 		$taxes_line_item->delete_children_line_items();
563 563
 		//loop thru taxes
564
-		foreach ( $ordered_taxes as $order => $taxes ) {
565
-			foreach ( $taxes as $tax ) {
566
-				if ( $tax instanceof EE_Price ) {
564
+		foreach ($ordered_taxes as $order => $taxes) {
565
+			foreach ($taxes as $tax) {
566
+				if ($tax instanceof EE_Price) {
567 567
 					$tax_line_item = EE_Line_Item::new_instance(
568 568
 						array(
569 569
 							'LIN_name'       => $tax->name(),
@@ -581,7 +581,7 @@  discard block
 block discarded – undo
581 581
 						'FHEE__EEH_Line_Item__apply_taxes__tax_line_item',
582 582
 						$tax_line_item
583 583
 					);
584
-					$taxes_line_item->add_child_line_item( $tax_line_item );
584
+					$taxes_line_item->add_child_line_item($tax_line_item);
585 585
 				}
586 586
 			}
587 587
 		}
@@ -596,10 +596,10 @@  discard block
 block discarded – undo
596 596
 	 * @param EE_Line_Item $total_line_item of type EEM_Line_Item::type_total
597 597
 	 * @return float
598 598
 	 */
599
-	public static function ensure_taxes_applied( $total_line_item ){
600
-		$taxes_subtotal = self::get_taxes_subtotal( $total_line_item );
601
-		if( ! $taxes_subtotal->children()){
602
-			self::apply_taxes( $total_line_item );
599
+	public static function ensure_taxes_applied($total_line_item) {
600
+		$taxes_subtotal = self::get_taxes_subtotal($total_line_item);
601
+		if ( ! $taxes_subtotal->children()) {
602
+			self::apply_taxes($total_line_item);
603 603
 		}
604 604
 		return $taxes_subtotal->total();
605 605
 	}
@@ -612,16 +612,16 @@  discard block
 block discarded – undo
612 612
 	 * @param EE_Line_Item $parent_line_item
613 613
 	 * @return bool
614 614
 	 */
615
-	public static function delete_all_child_items( EE_Line_Item $parent_line_item ) {
615
+	public static function delete_all_child_items(EE_Line_Item $parent_line_item) {
616 616
 		$deleted = 0;
617
-		foreach ( $parent_line_item->children() as $child_line_item ) {
618
-			if ( $child_line_item instanceof EE_Line_Item ) {
619
-				$deleted += EEH_Line_Item::delete_all_child_items( $child_line_item );
620
-				if ( $child_line_item->ID() ) {
617
+		foreach ($parent_line_item->children() as $child_line_item) {
618
+			if ($child_line_item instanceof EE_Line_Item) {
619
+				$deleted += EEH_Line_Item::delete_all_child_items($child_line_item);
620
+				if ($child_line_item->ID()) {
621 621
 					$child_line_item->delete();
622
-					unset( $child_line_item );
622
+					unset($child_line_item);
623 623
 				} else {
624
-					$parent_line_item->delete_child_line_item( $child_line_item->code() );
624
+					$parent_line_item->delete_child_line_item($child_line_item->code());
625 625
 				}
626 626
 				$deleted++;
627 627
 			}
@@ -643,25 +643,25 @@  discard block
 block discarded – undo
643 643
 	 * @param array|bool|string $line_item_codes
644 644
 	 * @return int number of items successfully removed
645 645
 	 */
646
-	public static function delete_items( EE_Line_Item $total_line_item, $line_item_codes = FALSE ) {
646
+	public static function delete_items(EE_Line_Item $total_line_item, $line_item_codes = FALSE) {
647 647
 
648
-		if( $total_line_item->type() != EEM_Line_Item::type_total ){
649
-			EE_Error::doing_it_wrong('EEH_Line_Item::delete_items', __( 'This static method should only be called with a TOTAL line item, otherwise we won\'t recalculate the totals correctly', 'event_espresso' ), '4.6.18' );
648
+		if ($total_line_item->type() != EEM_Line_Item::type_total) {
649
+			EE_Error::doing_it_wrong('EEH_Line_Item::delete_items', __('This static method should only be called with a TOTAL line item, otherwise we won\'t recalculate the totals correctly', 'event_espresso'), '4.6.18');
650 650
 		}
651
-		do_action( 'AHEE_log', __FILE__, __FUNCTION__, '' );
651
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
652 652
 
653 653
 		// check if only a single line_item_id was passed
654
-		if ( ! empty( $line_item_codes ) && ! is_array( $line_item_codes )) {
654
+		if ( ! empty($line_item_codes) && ! is_array($line_item_codes)) {
655 655
 			// place single line_item_id in an array to appear as multiple line_item_ids
656
-			$line_item_codes = array ( $line_item_codes );
656
+			$line_item_codes = array($line_item_codes);
657 657
 		}
658 658
 		$removals = 0;
659 659
 		// cycle thru line_item_ids
660
-		foreach ( $line_item_codes as $line_item_id ) {
660
+		foreach ($line_item_codes as $line_item_id) {
661 661
 			$removals += $total_line_item->delete_child_line_item($line_item_id);
662 662
 		}
663 663
 
664
-		if ( $removals > 0 ) {
664
+		if ($removals > 0) {
665 665
 			$total_line_item->recalculate_taxes_and_tax_total();
666 666
 			return $removals;
667 667
 		} else {
@@ -684,32 +684,32 @@  discard block
 block discarded – undo
684 684
 	 *                                           $amount will be added onto it; otherwise will simply set the taxes to match $amount
685 685
 	 * @return EE_Line_Item the new tax line item created
686 686
 	 */
687
-	public static function set_total_tax_to( EE_Line_Item $total_line_item, $amount, $name = NULL, $description = NULL, $code = NULL, $add_to_existing_line_item = false ){
688
-            $tax_subtotal = self::get_taxes_subtotal( $total_line_item );
687
+	public static function set_total_tax_to(EE_Line_Item $total_line_item, $amount, $name = NULL, $description = NULL, $code = NULL, $add_to_existing_line_item = false) {
688
+            $tax_subtotal = self::get_taxes_subtotal($total_line_item);
689 689
             $taxable_total = $total_line_item->taxable_total();
690 690
 
691
-            if( $add_to_existing_line_item ) {
692
-                $new_tax = $tax_subtotal->get_child_line_item( $code );
693
-                EEM_Line_Item::instance()->delete( array( array( 'LIN_code' => array( '!=', $code ), 'LIN_parent' => $tax_subtotal->ID() ) ) );
691
+            if ($add_to_existing_line_item) {
692
+                $new_tax = $tax_subtotal->get_child_line_item($code);
693
+                EEM_Line_Item::instance()->delete(array(array('LIN_code' => array('!=', $code), 'LIN_parent' => $tax_subtotal->ID())));
694 694
             } else {
695 695
                 $new_tax = null;
696 696
                 $tax_subtotal->delete_children_line_items();
697 697
             }
698
-            if( $new_tax ) {
699
-                $new_tax->set_total( $new_tax->total() + $amount );
700
-                $new_tax->set_percent( $taxable_total ? ( $new_tax->total() ) / $taxable_total * 100 : 0 );
698
+            if ($new_tax) {
699
+                $new_tax->set_total($new_tax->total() + $amount);
700
+                $new_tax->set_percent($taxable_total ? ($new_tax->total()) / $taxable_total * 100 : 0);
701 701
             } else {
702 702
                 //no existing tax item. Create it
703
-				$new_tax = EE_Line_Item::new_instance( array(
703
+				$new_tax = EE_Line_Item::new_instance(array(
704 704
 					'TXN_ID'      => $total_line_item->TXN_ID(),
705
-					'LIN_name'    => $name ? $name : __( 'Tax', 'event_espresso' ),
705
+					'LIN_name'    => $name ? $name : __('Tax', 'event_espresso'),
706 706
 					'LIN_desc'    => $description ? $description : '',
707
-					'LIN_percent' => $taxable_total ? ( $amount / $taxable_total * 100 ) : 0,
707
+					'LIN_percent' => $taxable_total ? ($amount / $taxable_total * 100) : 0,
708 708
 					'LIN_total'   => $amount,
709 709
 					'LIN_parent'  => $tax_subtotal->ID(),
710 710
 					'LIN_type'    => EEM_Line_Item::type_tax,
711 711
 					'LIN_code'    => $code
712
-				) );
712
+				));
713 713
 			}
714 714
 
715 715
             $new_tax = apply_filters(
@@ -718,7 +718,7 @@  discard block
 block discarded – undo
718 718
 				$total_line_item
719 719
             );
720 720
             $new_tax->save();
721
-            $tax_subtotal->set_total( $new_tax->total() );
721
+            $tax_subtotal->set_total($new_tax->total());
722 722
             $tax_subtotal->save();
723 723
             $total_line_item->recalculate_total_including_taxes();
724 724
             return $new_tax;
@@ -734,17 +734,17 @@  discard block
 block discarded – undo
734 734
 	 *  it will be whitelisted (ie, except from becoming taxable)
735 735
 	 * @param boolean $taxable
736 736
 	 */
737
-	public static function set_line_items_taxable( EE_Line_Item $line_item, $taxable = true, $code_substring_for_whitelist = null ) {
738
-		if( $code_substring_for_whitelist !== null ) {
739
-			$whitelisted = strpos( $line_item->code(), $code_substring_for_whitelist ) !== false ? true : false;
737
+	public static function set_line_items_taxable(EE_Line_Item $line_item, $taxable = true, $code_substring_for_whitelist = null) {
738
+		if ($code_substring_for_whitelist !== null) {
739
+			$whitelisted = strpos($line_item->code(), $code_substring_for_whitelist) !== false ? true : false;
740 740
 		} else {
741 741
 			$whitelisted = false;
742 742
 		}
743
-		if( $line_item->is_line_item() && ! $whitelisted ) {
744
-			$line_item->set_is_taxable( $taxable );
743
+		if ($line_item->is_line_item() && ! $whitelisted) {
744
+			$line_item->set_is_taxable($taxable);
745 745
 		}
746
-		foreach( $line_item->children() as $child_line_item ) {
747
-			EEH_Line_Item::set_line_items_taxable( $child_line_item, $taxable, $code_substring_for_whitelist );
746
+		foreach ($line_item->children() as $child_line_item) {
747
+			EEH_Line_Item::set_line_items_taxable($child_line_item, $taxable, $code_substring_for_whitelist);
748 748
 		}
749 749
 	}
750 750
 
@@ -757,8 +757,8 @@  discard block
 block discarded – undo
757 757
 	 * @param \EE_Line_Item $parent_line_item - the line item to find descendants of
758 758
 	 * @return EE_Line_Item[]
759 759
 	 */
760
-	public static function get_event_subtotals( EE_Line_Item $parent_line_item ) {
761
-		return self::get_subtotals_of_object_type( $parent_line_item, 'Event' );
760
+	public static function get_event_subtotals(EE_Line_Item $parent_line_item) {
761
+		return self::get_subtotals_of_object_type($parent_line_item, 'Event');
762 762
 	}
763 763
 
764 764
 
@@ -771,8 +771,8 @@  discard block
 block discarded – undo
771 771
 	 * @param string $obj_type
772 772
 	 * @return EE_Line_Item[]
773 773
 	 */
774
-	public static function get_subtotals_of_object_type( EE_Line_Item $parent_line_item, $obj_type = '' ) {
775
-		return self::_get_descendants_by_type_and_object_type( $parent_line_item, EEM_Line_Item::type_sub_total, $obj_type );
774
+	public static function get_subtotals_of_object_type(EE_Line_Item $parent_line_item, $obj_type = '') {
775
+		return self::_get_descendants_by_type_and_object_type($parent_line_item, EEM_Line_Item::type_sub_total, $obj_type);
776 776
 	}
777 777
 
778 778
 
@@ -784,8 +784,8 @@  discard block
 block discarded – undo
784 784
 	 * @param \EE_Line_Item $parent_line_item - the line item to find descendants of
785 785
 	 * @return EE_Line_Item[]
786 786
 	 */
787
-	public static function get_ticket_line_items( EE_Line_Item $parent_line_item ) {
788
-		return self::get_line_items_of_object_type( $parent_line_item, 'Ticket' );
787
+	public static function get_ticket_line_items(EE_Line_Item $parent_line_item) {
788
+		return self::get_line_items_of_object_type($parent_line_item, 'Ticket');
789 789
 	}
790 790
 
791 791
 
@@ -798,8 +798,8 @@  discard block
 block discarded – undo
798 798
 	 * @param string $obj_type
799 799
 	 * @return EE_Line_Item[]
800 800
 	 */
801
-	public static function get_line_items_of_object_type( EE_Line_Item $parent_line_item, $obj_type = '' ) {
802
-		return self::_get_descendants_by_type_and_object_type( $parent_line_item, EEM_Line_Item::type_line_item, $obj_type );
801
+	public static function get_line_items_of_object_type(EE_Line_Item $parent_line_item, $obj_type = '') {
802
+		return self::_get_descendants_by_type_and_object_type($parent_line_item, EEM_Line_Item::type_line_item, $obj_type);
803 803
 	}
804 804
 
805 805
 
@@ -810,8 +810,8 @@  discard block
 block discarded – undo
810 810
 	 * @param \EE_Line_Item $parent_line_item - the line item to find descendants of
811 811
 	 * @return EE_Line_Item[]
812 812
 	 */
813
-	public static function get_tax_descendants( EE_Line_Item $parent_line_item ) {
814
-		return EEH_Line_Item::get_descendants_of_type( $parent_line_item, EEM_Line_Item::type_tax );
813
+	public static function get_tax_descendants(EE_Line_Item $parent_line_item) {
814
+		return EEH_Line_Item::get_descendants_of_type($parent_line_item, EEM_Line_Item::type_tax);
815 815
 	}
816 816
 
817 817
 
@@ -822,8 +822,8 @@  discard block
 block discarded – undo
822 822
 	 * @param \EE_Line_Item $parent_line_item - the line item to find descendants of
823 823
 	 * @return EE_Line_Item[]
824 824
 	 */
825
-	public static function get_line_item_descendants( EE_Line_Item $parent_line_item ) {
826
-		return EEH_Line_Item::get_descendants_of_type( $parent_line_item, EEM_Line_Item::type_line_item );
825
+	public static function get_line_item_descendants(EE_Line_Item $parent_line_item) {
826
+		return EEH_Line_Item::get_descendants_of_type($parent_line_item, EEM_Line_Item::type_line_item);
827 827
 	}
828 828
 
829 829
 
@@ -836,8 +836,8 @@  discard block
 block discarded – undo
836 836
 	 * @param string $line_item_type one of the EEM_Line_Item constants
837 837
 	 * @return EE_Line_Item[]
838 838
 	 */
839
-	public static function get_descendants_of_type( EE_Line_Item $parent_line_item, $line_item_type ) {
840
-		return self::_get_descendants_by_type_and_object_type( $parent_line_item, $line_item_type, NULL );
839
+	public static function get_descendants_of_type(EE_Line_Item $parent_line_item, $line_item_type) {
840
+		return self::_get_descendants_by_type_and_object_type($parent_line_item, $line_item_type, NULL);
841 841
 	}
842 842
 
843 843
 
@@ -850,15 +850,15 @@  discard block
 block discarded – undo
850 850
 	 * @param string | NULL $obj_type object model class name (minus prefix) or NULL to ignore object type when searching
851 851
 	 * @return EE_Line_Item[]
852 852
 	 */
853
-	protected static function _get_descendants_by_type_and_object_type( EE_Line_Item $parent_line_item, $line_item_type, $obj_type = NULL ) {
853
+	protected static function _get_descendants_by_type_and_object_type(EE_Line_Item $parent_line_item, $line_item_type, $obj_type = NULL) {
854 854
 		$objects = array();
855
-		foreach ( $parent_line_item->children() as $child_line_item ) {
856
-			if ( $child_line_item instanceof EE_Line_Item ) {
857
-				if ( $child_line_item->type() == $line_item_type && ( $child_line_item->OBJ_type() == $obj_type || $obj_type === NULL )) {
855
+		foreach ($parent_line_item->children() as $child_line_item) {
856
+			if ($child_line_item instanceof EE_Line_Item) {
857
+				if ($child_line_item->type() == $line_item_type && ($child_line_item->OBJ_type() == $obj_type || $obj_type === NULL)) {
858 858
 					$objects[] = $child_line_item;
859 859
 				} else {
860 860
 					//go-through-all-its children looking for more matches
861
-					$objects = array_merge( $objects, self::_get_descendants_by_type_and_object_type( $child_line_item, $line_item_type, $obj_type ));
861
+					$objects = array_merge($objects, self::_get_descendants_by_type_and_object_type($child_line_item, $line_item_type, $obj_type));
862 862
 				}
863 863
 			}
864 864
 		}
@@ -876,9 +876,9 @@  discard block
 block discarded – undo
876 876
 	 * @param array $OBJ_IDs array of OBJ_IDs
877 877
 	 * @return EE_Line_Item[]
878 878
 	 */
879
-	public static function get_line_items_by_object_type_and_IDs( EE_Line_Item $parent_line_item, $OBJ_type = '', $OBJ_IDs = array() ) {
880
-		$OBJ_IDs = is_array( $OBJ_IDs ) ? $OBJ_IDs : array( $OBJ_IDs );
881
-		return self::_get_descendants_by_object_type_and_object_ID( $parent_line_item, $OBJ_type, $OBJ_IDs );
879
+	public static function get_line_items_by_object_type_and_IDs(EE_Line_Item $parent_line_item, $OBJ_type = '', $OBJ_IDs = array()) {
880
+		$OBJ_IDs = is_array($OBJ_IDs) ? $OBJ_IDs : array($OBJ_IDs);
881
+		return self::_get_descendants_by_object_type_and_object_ID($parent_line_item, $OBJ_type, $OBJ_IDs);
882 882
 	}
883 883
 
884 884
 
@@ -891,15 +891,15 @@  discard block
 block discarded – undo
891 891
 	 * @param array $OBJ_IDs array of OBJ_IDs
892 892
 	 * @return EE_Line_Item[]
893 893
 	 */
894
-	protected static function _get_descendants_by_object_type_and_object_ID( EE_Line_Item $parent_line_item, $OBJ_type, $OBJ_IDs ) {
894
+	protected static function _get_descendants_by_object_type_and_object_ID(EE_Line_Item $parent_line_item, $OBJ_type, $OBJ_IDs) {
895 895
 		$objects = array();
896
-		foreach ( $parent_line_item->children() as $child_line_item ) {
897
-			if ( $child_line_item instanceof EE_Line_Item ) {
898
-				if ( $child_line_item->OBJ_type() == $OBJ_type && in_array( $child_line_item->OBJ_ID(), $OBJ_IDs )) {
896
+		foreach ($parent_line_item->children() as $child_line_item) {
897
+			if ($child_line_item instanceof EE_Line_Item) {
898
+				if ($child_line_item->OBJ_type() == $OBJ_type && in_array($child_line_item->OBJ_ID(), $OBJ_IDs)) {
899 899
 					$objects[] = $child_line_item;
900 900
 				} else {
901 901
 					//go-through-all-its children looking for more matches
902
-					$objects = array_merge( $objects, self::_get_descendants_by_object_type_and_object_ID( $child_line_item, $OBJ_type, $OBJ_IDs ));
902
+					$objects = array_merge($objects, self::_get_descendants_by_object_type_and_object_ID($child_line_item, $OBJ_type, $OBJ_IDs));
903 903
 				}
904 904
 			}
905 905
 		}
@@ -917,8 +917,8 @@  discard block
 block discarded – undo
917 917
 	 * @param string $type like one of the EEM_Line_Item::type_*
918 918
 	 * @return EE_Line_Item
919 919
 	 */
920
-	public static function get_nearest_descendant_of_type( EE_Line_Item $parent_line_item, $type ) {
921
-		return self::_get_nearest_descendant( $parent_line_item, 'LIN_type' , $type );
920
+	public static function get_nearest_descendant_of_type(EE_Line_Item $parent_line_item, $type) {
921
+		return self::_get_nearest_descendant($parent_line_item, 'LIN_type', $type);
922 922
 	}
923 923
 
924 924
 
@@ -931,8 +931,8 @@  discard block
 block discarded – undo
931 931
 	 * @param string $code any value used for LIN_code
932 932
 	 * @return EE_Line_Item
933 933
 	 */
934
-	public static function get_nearest_descendant_having_code( EE_Line_Item $parent_line_item, $code ) {
935
-		return self::_get_nearest_descendant( $parent_line_item, 'LIN_code' , $code );
934
+	public static function get_nearest_descendant_having_code(EE_Line_Item $parent_line_item, $code) {
935
+		return self::_get_nearest_descendant($parent_line_item, 'LIN_code', $code);
936 936
 	}
937 937
 
938 938
 
@@ -945,15 +945,15 @@  discard block
 block discarded – undo
945 945
 	 * @param string $value any value stored in $search_field
946 946
 	 * @return EE_Line_Item
947 947
 	 */
948
-	protected static function _get_nearest_descendant( EE_Line_Item $parent_line_item, $search_field, $value ) {
949
-		foreach( $parent_line_item->children() as $child ){
950
-			if ( $child->get( $search_field ) == $value ){
948
+	protected static function _get_nearest_descendant(EE_Line_Item $parent_line_item, $search_field, $value) {
949
+		foreach ($parent_line_item->children() as $child) {
950
+			if ($child->get($search_field) == $value) {
951 951
 				return $child;
952 952
 			}
953 953
 		}
954
-		foreach( $parent_line_item->children() as $child ){
955
-			$descendant_found = self::_get_nearest_descendant( $child, $search_field, $value );
956
-			if ( $descendant_found ){
954
+		foreach ($parent_line_item->children() as $child) {
955
+			$descendant_found = self::_get_nearest_descendant($child, $search_field, $value);
956
+			if ($descendant_found) {
957 957
 				return $descendant_found;
958 958
 			}
959 959
 		}
@@ -969,22 +969,22 @@  discard block
 block discarded – undo
969 969
 	 * @param int $indentation
970 970
 	 * @return void
971 971
 	 */
972
-	public static function visualize( EE_Line_Item $line_item, $indentation = 0 ){
972
+	public static function visualize(EE_Line_Item $line_item, $indentation = 0) {
973 973
 		echo "\n<br />";
974
-		for( $i = 0; $i < $indentation; $i++ ){
974
+		for ($i = 0; $i < $indentation; $i++) {
975 975
 			echo " - ";
976 976
 		}
977
-		if( $line_item->is_percent() ) {
978
-			$breakdown = $line_item->percent() . '%';
977
+		if ($line_item->is_percent()) {
978
+			$breakdown = $line_item->percent().'%';
979 979
 		} else {
980
-			$breakdown = '$' . $line_item->unit_price() . "x" . $line_item->quantity();
980
+			$breakdown = '$'.$line_item->unit_price()."x".$line_item->quantity();
981 981
 		}
982
-		echo $line_item->name() . "( " . $line_item->ID() . " ) : " . $line_item->type() . " $" . $line_item->total() . "(" . $breakdown . ")";
983
-		if( $line_item->is_taxable() ){
982
+		echo $line_item->name()."( ".$line_item->ID()." ) : ".$line_item->type()." $".$line_item->total()."(".$breakdown.")";
983
+		if ($line_item->is_taxable()) {
984 984
 			echo "  * taxable";
985 985
 		}
986
-		if( $line_item->children() ){
987
-			foreach($line_item->children() as $child){
986
+		if ($line_item->children()) {
987
+			foreach ($line_item->children() as $child) {
988 988
 				self::visualize($child, $indentation + 1);
989 989
 			}
990 990
 		}
@@ -1025,88 +1025,88 @@  discard block
 block discarded – undo
1025 1025
 	 *                                          is theirs, which can be done with
1026 1026
 	 *                                          `EEM_Line_Item::instance()->get_line_item_for_registration( $registration );`
1027 1027
 	 */
1028
-	public static function calculate_reg_final_prices_per_line_item( EE_Line_Item $line_item, $billable_ticket_quantities = array() ) {
1028
+	public static function calculate_reg_final_prices_per_line_item(EE_Line_Item $line_item, $billable_ticket_quantities = array()) {
1029 1029
 		//init running grand total if not already
1030
-		if ( ! isset( $running_totals[ 'total' ] ) ) {
1031
-			$running_totals[ 'total' ] = 0;
1030
+		if ( ! isset($running_totals['total'])) {
1031
+			$running_totals['total'] = 0;
1032 1032
 		}
1033
-		if( ! isset( $running_totals[ 'taxable' ] ) ) {
1034
-			$running_totals[ 'taxable' ] = array( 'total' => 0 );
1033
+		if ( ! isset($running_totals['taxable'])) {
1034
+			$running_totals['taxable'] = array('total' => 0);
1035 1035
 		}
1036
-		foreach ( $line_item->children() as $child_line_item ) {
1037
-			switch ( $child_line_item->type() ) {
1036
+		foreach ($line_item->children() as $child_line_item) {
1037
+			switch ($child_line_item->type()) {
1038 1038
 
1039 1039
 				case EEM_Line_Item::type_sub_total :
1040
-					$running_totals_from_subtotal = EEH_Line_Item::calculate_reg_final_prices_per_line_item( $child_line_item, $billable_ticket_quantities );
1040
+					$running_totals_from_subtotal = EEH_Line_Item::calculate_reg_final_prices_per_line_item($child_line_item, $billable_ticket_quantities);
1041 1041
 					//combine arrays but preserve numeric keys
1042
-					$running_totals = array_replace_recursive( $running_totals_from_subtotal, $running_totals );
1043
-					$running_totals[ 'total' ] += $running_totals_from_subtotal[ 'total' ];
1044
-					$running_totals[ 'taxable'][ 'total' ] += $running_totals_from_subtotal[ 'taxable' ][ 'total' ];
1042
+					$running_totals = array_replace_recursive($running_totals_from_subtotal, $running_totals);
1043
+					$running_totals['total'] += $running_totals_from_subtotal['total'];
1044
+					$running_totals['taxable']['total'] += $running_totals_from_subtotal['taxable']['total'];
1045 1045
 					break;
1046 1046
 
1047 1047
 				case EEM_Line_Item::type_tax_sub_total :
1048 1048
 
1049 1049
 					//find how much the taxes percentage is
1050
-					if ( $child_line_item->percent() != 0 ) {
1050
+					if ($child_line_item->percent() != 0) {
1051 1051
 						$tax_percent_decimal = $child_line_item->percent() / 100;
1052 1052
 					} else {
1053 1053
 						$tax_percent_decimal = EE_Taxes::get_total_taxes_percentage() / 100;
1054 1054
 					}
1055 1055
 					//and apply to all the taxable totals, and add to the pretax totals
1056
-					foreach ( $running_totals as $line_item_id => $this_running_total ) {
1056
+					foreach ($running_totals as $line_item_id => $this_running_total) {
1057 1057
 						//"total" and "taxable" array key is an exception
1058
-						if ( $line_item_id === 'taxable' ) {
1058
+						if ($line_item_id === 'taxable') {
1059 1059
 							continue;
1060 1060
 						}
1061
-						$taxable_total = $running_totals[ 'taxable' ][ $line_item_id ];
1062
-						$running_totals[ $line_item_id ] += ( $taxable_total * $tax_percent_decimal );
1061
+						$taxable_total = $running_totals['taxable'][$line_item_id];
1062
+						$running_totals[$line_item_id] += ($taxable_total * $tax_percent_decimal);
1063 1063
 					}
1064 1064
 					break;
1065 1065
 
1066 1066
 				case EEM_Line_Item::type_line_item :
1067 1067
 
1068 1068
 					// ticket line items or ????
1069
-					if ( $child_line_item->OBJ_type() === 'Ticket' ) {
1069
+					if ($child_line_item->OBJ_type() === 'Ticket') {
1070 1070
 						// kk it's a ticket
1071
-						if ( isset( $running_totals[ $child_line_item->ID() ] ) ) {
1071
+						if (isset($running_totals[$child_line_item->ID()])) {
1072 1072
 							//huh? that shouldn't happen.
1073
-							$running_totals[ 'total' ] += $child_line_item->total();
1073
+							$running_totals['total'] += $child_line_item->total();
1074 1074
 						} else {
1075 1075
 							//its not in our running totals yet. great.
1076
-							if ( $child_line_item->is_taxable() ) {
1076
+							if ($child_line_item->is_taxable()) {
1077 1077
 								$taxable_amount = $child_line_item->unit_price();
1078 1078
 							} else {
1079 1079
 								$taxable_amount = 0;
1080 1080
 							}
1081 1081
 							// are we only calculating totals for some tickets?
1082
-							if ( isset( $billable_ticket_quantities[ $child_line_item->OBJ_ID() ] ) ) {
1083
-								$quantity = $billable_ticket_quantities[ $child_line_item->OBJ_ID() ];
1084
-								$running_totals[ $child_line_item->ID() ] = $quantity ? $child_line_item->unit_price() : 0;
1085
-								$running_totals[ 'taxable' ][ $child_line_item->ID() ] = $quantity ? $taxable_amount : 0;
1082
+							if (isset($billable_ticket_quantities[$child_line_item->OBJ_ID()])) {
1083
+								$quantity = $billable_ticket_quantities[$child_line_item->OBJ_ID()];
1084
+								$running_totals[$child_line_item->ID()] = $quantity ? $child_line_item->unit_price() : 0;
1085
+								$running_totals['taxable'][$child_line_item->ID()] = $quantity ? $taxable_amount : 0;
1086 1086
 							} else {
1087 1087
 								$quantity = $child_line_item->quantity();
1088
-								$running_totals[ $child_line_item->ID() ] = $child_line_item->unit_price();
1089
-								$running_totals[ 'taxable' ][ $child_line_item->ID() ] = $taxable_amount;
1088
+								$running_totals[$child_line_item->ID()] = $child_line_item->unit_price();
1089
+								$running_totals['taxable'][$child_line_item->ID()] = $taxable_amount;
1090 1090
 							}
1091
-							$running_totals[ 'taxable' ][ 'total' ] += $taxable_amount * $quantity;
1092
-							$running_totals[ 'total' ] += $child_line_item->unit_price() * $quantity;
1091
+							$running_totals['taxable']['total'] += $taxable_amount * $quantity;
1092
+							$running_totals['total'] += $child_line_item->unit_price() * $quantity;
1093 1093
 						}
1094 1094
 					} else {
1095 1095
 						// it's some other type of item added to the cart
1096 1096
 						// it should affect the running totals
1097 1097
 						// basically we want to convert it into a PERCENT modifier. Because
1098 1098
 						// more clearly affect all registration's final price equally
1099
-						$line_items_percent_of_running_total = $running_totals[ 'total' ] > 0 ? ( $child_line_item->total() / $running_totals[ 'total' ] ) + 1 : 1;
1100
-						foreach ( $running_totals as $line_item_id => $this_running_total ) {
1099
+						$line_items_percent_of_running_total = $running_totals['total'] > 0 ? ($child_line_item->total() / $running_totals['total']) + 1 : 1;
1100
+						foreach ($running_totals as $line_item_id => $this_running_total) {
1101 1101
 							//the "taxable" array key is an exception
1102
-							if ( $line_item_id === 'taxable' ) {
1102
+							if ($line_item_id === 'taxable') {
1103 1103
 								continue;
1104 1104
 							}
1105 1105
 							// update the running totals
1106 1106
 							// yes this actually even works for the running grand total!
1107
-							$running_totals[ $line_item_id ] = $line_items_percent_of_running_total * $this_running_total;
1108
-							if ( $child_line_item->is_taxable() ) {
1109
-								$running_totals[ 'taxable' ][ $line_item_id ] = $line_items_percent_of_running_total * $running_totals[ 'taxable' ][ $line_item_id ];
1107
+							$running_totals[$line_item_id] = $line_items_percent_of_running_total * $this_running_total;
1108
+							if ($child_line_item->is_taxable()) {
1109
+								$running_totals['taxable'][$line_item_id] = $line_items_percent_of_running_total * $running_totals['taxable'][$line_item_id];
1110 1110
 							}
1111 1111
 						}
1112 1112
 					}
@@ -1125,15 +1125,15 @@  discard block
 block discarded – undo
1125 1125
 	 * @param EE_Registration[] $registrations
1126 1126
 	 * @return \EE_Line_Item
1127 1127
 	 */
1128
-	public static function billable_line_item_tree( EE_Line_Item $line_item, $registrations ) {
1129
-		$copy_li = EEH_Line_Item::billable_line_item( $line_item, $registrations );
1130
-		foreach ( $line_item->children() as $child_li ) {
1131
-			$copy_li->add_child_line_item( EEH_Line_Item::billable_line_item_tree( $child_li, $registrations ) );
1128
+	public static function billable_line_item_tree(EE_Line_Item $line_item, $registrations) {
1129
+		$copy_li = EEH_Line_Item::billable_line_item($line_item, $registrations);
1130
+		foreach ($line_item->children() as $child_li) {
1131
+			$copy_li->add_child_line_item(EEH_Line_Item::billable_line_item_tree($child_li, $registrations));
1132 1132
 		}
1133 1133
 		//if this is the grand total line item, make sure the totals all add up
1134 1134
 		//(we could have duplicated this logic AS we copied the line items, but
1135 1135
 		//it seems DRYer this way)
1136
-		if ( $copy_li->type() === EEM_Line_Item::type_total ) {
1136
+		if ($copy_li->type() === EEM_Line_Item::type_total) {
1137 1137
 			$copy_li->recalculate_total_including_taxes();
1138 1138
 		}
1139 1139
 		return $copy_li;
@@ -1148,26 +1148,26 @@  discard block
 block discarded – undo
1148 1148
 	 * @return EE_Line_Item
1149 1149
 	 * @param EE_Registration[] $registrations
1150 1150
 	 */
1151
-	public static function billable_line_item( EE_Line_Item $line_item, $registrations ) {
1151
+	public static function billable_line_item(EE_Line_Item $line_item, $registrations) {
1152 1152
 		$new_li_fields = $line_item->model_field_array();
1153
-		if ( $line_item->type() === EEM_Line_Item::type_line_item &&
1153
+		if ($line_item->type() === EEM_Line_Item::type_line_item &&
1154 1154
 			$line_item->OBJ_type() === 'Ticket'
1155 1155
 		) {
1156 1156
 			$count = 0;
1157
-			foreach ( $registrations as $registration ) {
1158
-				if ( $line_item->OBJ_ID() === $registration->ticket_ID() &&
1159
-					in_array( $registration->status_ID(), EEM_Registration::reg_statuses_that_allow_payment() )
1157
+			foreach ($registrations as $registration) {
1158
+				if ($line_item->OBJ_ID() === $registration->ticket_ID() &&
1159
+					in_array($registration->status_ID(), EEM_Registration::reg_statuses_that_allow_payment())
1160 1160
 				) {
1161 1161
 					$count++;
1162 1162
 				}
1163 1163
 			}
1164
-			$new_li_fields[ 'LIN_quantity' ] = $count;
1164
+			$new_li_fields['LIN_quantity'] = $count;
1165 1165
 		}
1166 1166
 		//don't set the total. We'll leave that up to the code that calculates it
1167
-		unset( $new_li_fields[ 'LIN_ID' ] );
1168
-		unset( $new_li_fields[ 'LIN_parent' ] );
1169
-		unset( $new_li_fields[ 'LIN_total' ] );
1170
-		return EE_Line_Item::new_instance( $new_li_fields );
1167
+		unset($new_li_fields['LIN_ID']);
1168
+		unset($new_li_fields['LIN_parent']);
1169
+		unset($new_li_fields['LIN_total']);
1170
+		return EE_Line_Item::new_instance($new_li_fields);
1171 1171
 	}
1172 1172
 
1173 1173
 
@@ -1179,19 +1179,19 @@  discard block
 block discarded – undo
1179 1179
 	 * @param EE_Line_Item $line_item |null
1180 1180
 	 * @return \EE_Line_Item|null
1181 1181
 	 */
1182
-	public static function non_empty_line_items( EE_Line_Item $line_item ) {
1183
-		$copied_li = EEH_Line_Item::non_empty_line_item( $line_item );
1184
-		if ( $copied_li === null ) {
1182
+	public static function non_empty_line_items(EE_Line_Item $line_item) {
1183
+		$copied_li = EEH_Line_Item::non_empty_line_item($line_item);
1184
+		if ($copied_li === null) {
1185 1185
 			return null;
1186 1186
 		}
1187 1187
 		//if this is an event subtotal, we want to only include it if it
1188 1188
 		//has a non-zero total and at least one ticket line item child
1189 1189
 		$ticket_children = 0;
1190
-		foreach ( $line_item->children() as $child_li ) {
1191
-			$child_li_copy = EEH_Line_Item::non_empty_line_items( $child_li );
1192
-			if ( $child_li_copy !== null ) {
1193
-				$copied_li->add_child_line_item( $child_li_copy );
1194
-				if ( $child_li_copy->type() === EEM_Line_Item::type_line_item &&
1190
+		foreach ($line_item->children() as $child_li) {
1191
+			$child_li_copy = EEH_Line_Item::non_empty_line_items($child_li);
1192
+			if ($child_li_copy !== null) {
1193
+				$copied_li->add_child_line_item($child_li_copy);
1194
+				if ($child_li_copy->type() === EEM_Line_Item::type_line_item &&
1195 1195
 					$child_li_copy->OBJ_type() === 'Ticket'
1196 1196
 				) {
1197 1197
 					$ticket_children++;
@@ -1200,7 +1200,7 @@  discard block
 block discarded – undo
1200 1200
 		}
1201 1201
 		//if this is an event subtotal with NO ticket children
1202 1202
 		//we basically want to ignore it
1203
-		if ( $line_item->type() === EEM_Line_Item::type_sub_total &&
1203
+		if ($line_item->type() === EEM_Line_Item::type_sub_total &&
1204 1204
 			$line_item->OBJ_type() === 'Event' &&
1205 1205
 			$ticket_children === 0 &&
1206 1206
 			$line_item->total() === 0
@@ -1218,8 +1218,8 @@  discard block
 block discarded – undo
1218 1218
 	 * @param EE_Line_Item      $line_item
1219 1219
 	 * @return EE_Line_Item
1220 1220
 	 */
1221
-	public static function non_empty_line_item( EE_Line_Item $line_item ) {
1222
-		if ( $line_item->type() === EEM_Line_Item::type_line_item &&
1221
+	public static function non_empty_line_item(EE_Line_Item $line_item) {
1222
+		if ($line_item->type() === EEM_Line_Item::type_line_item &&
1223 1223
 			$line_item->OBJ_type() === 'Ticket' &&
1224 1224
 			$line_item->quantity() == 0
1225 1225
 		) {
@@ -1227,9 +1227,9 @@  discard block
 block discarded – undo
1227 1227
 		}
1228 1228
 		$new_li_fields = $line_item->model_field_array();
1229 1229
 		//don't set the total. We'll leave that up to the code that calculates it
1230
-		unset( $new_li_fields[ 'LIN_ID' ] );
1231
-		unset( $new_li_fields[ 'LIN_parent' ] );
1232
-		return EE_Line_Item::new_instance( $new_li_fields );
1230
+		unset($new_li_fields['LIN_ID']);
1231
+		unset($new_li_fields['LIN_parent']);
1232
+		return EE_Line_Item::new_instance($new_li_fields);
1233 1233
 	}
1234 1234
 
1235 1235
 
@@ -1243,9 +1243,9 @@  discard block
 block discarded – undo
1243 1243
 	 * @param EE_Line_Item $total_line_item
1244 1244
 	 *	@return \EE_Line_Item
1245 1245
 	 */
1246
-	public static function get_items_subtotal( EE_Line_Item $total_line_item ){
1247
-		EE_Error::doing_it_wrong( 'EEH_Line_Item::get_items_subtotal()', __('Method replaced with EEH_Line_Item::get_pre_tax_subtotal()', 'event_espresso'), '4.6.0' );
1248
-		return self::get_pre_tax_subtotal( $total_line_item );
1246
+	public static function get_items_subtotal(EE_Line_Item $total_line_item) {
1247
+		EE_Error::doing_it_wrong('EEH_Line_Item::get_items_subtotal()', __('Method replaced with EEH_Line_Item::get_pre_tax_subtotal()', 'event_espresso'), '4.6.0');
1248
+		return self::get_pre_tax_subtotal($total_line_item);
1249 1249
 	}
1250 1250
 
1251 1251
 
@@ -1255,9 +1255,9 @@  discard block
 block discarded – undo
1255 1255
 	 * @param EE_Transaction $transaction
1256 1256
 	 *	@return \EE_Line_Item
1257 1257
 	 */
1258
-	public static function create_default_total_line_item( $transaction = NULL) {
1259
-		EE_Error::doing_it_wrong( 'EEH_Line_Item::create_default_total_line_item()', __('Method replaced with EEH_Line_Item::create_total_line_item()', 'event_espresso'), '4.6.0' );
1260
-		return self::create_total_line_item( $transaction );
1258
+	public static function create_default_total_line_item($transaction = NULL) {
1259
+		EE_Error::doing_it_wrong('EEH_Line_Item::create_default_total_line_item()', __('Method replaced with EEH_Line_Item::create_total_line_item()', 'event_espresso'), '4.6.0');
1260
+		return self::create_total_line_item($transaction);
1261 1261
 	}
1262 1262
 
1263 1263
 
@@ -1268,9 +1268,9 @@  discard block
 block discarded – undo
1268 1268
 	 * @param EE_Transaction $transaction
1269 1269
 	 *	@return \EE_Line_Item
1270 1270
 	 */
1271
-	public static function create_default_tickets_subtotal( EE_Line_Item $total_line_item, $transaction = NULL) {
1272
-		EE_Error::doing_it_wrong( 'EEH_Line_Item::create_default_tickets_subtotal()', __('Method replaced with EEH_Line_Item::create_pre_tax_subtotal()', 'event_espresso'), '4.6.0' );
1273
-		return self::create_pre_tax_subtotal( $total_line_item, $transaction );
1271
+	public static function create_default_tickets_subtotal(EE_Line_Item $total_line_item, $transaction = NULL) {
1272
+		EE_Error::doing_it_wrong('EEH_Line_Item::create_default_tickets_subtotal()', __('Method replaced with EEH_Line_Item::create_pre_tax_subtotal()', 'event_espresso'), '4.6.0');
1273
+		return self::create_pre_tax_subtotal($total_line_item, $transaction);
1274 1274
 	}
1275 1275
 
1276 1276
 
@@ -1281,9 +1281,9 @@  discard block
 block discarded – undo
1281 1281
 	 * @param EE_Transaction $transaction
1282 1282
 	 *	@return \EE_Line_Item
1283 1283
 	 */
1284
-	public static function create_default_taxes_subtotal( EE_Line_Item $total_line_item, $transaction = NULL) {
1285
-		EE_Error::doing_it_wrong( 'EEH_Line_Item::create_default_taxes_subtotal()', __('Method replaced with EEH_Line_Item::create_taxes_subtotal()', 'event_espresso'), '4.6.0' );
1286
-		return self::create_taxes_subtotal( $total_line_item, $transaction );
1284
+	public static function create_default_taxes_subtotal(EE_Line_Item $total_line_item, $transaction = NULL) {
1285
+		EE_Error::doing_it_wrong('EEH_Line_Item::create_default_taxes_subtotal()', __('Method replaced with EEH_Line_Item::create_taxes_subtotal()', 'event_espresso'), '4.6.0');
1286
+		return self::create_taxes_subtotal($total_line_item, $transaction);
1287 1287
 	}
1288 1288
 
1289 1289
 
@@ -1294,9 +1294,9 @@  discard block
 block discarded – undo
1294 1294
 	 * @param EE_Transaction $transaction
1295 1295
 	 *	@return \EE_Line_Item
1296 1296
 	 */
1297
-	public static function create_default_event_subtotal( EE_Line_Item $total_line_item, $transaction = NULL) {
1298
-		EE_Error::doing_it_wrong( 'EEH_Line_Item::create_default_event_subtotal()', __('Method replaced with EEH_Line_Item::create_event_subtotal()', 'event_espresso'), '4.6.0' );
1299
-		return self::create_event_subtotal( $total_line_item, $transaction );
1297
+	public static function create_default_event_subtotal(EE_Line_Item $total_line_item, $transaction = NULL) {
1298
+		EE_Error::doing_it_wrong('EEH_Line_Item::create_default_event_subtotal()', __('Method replaced with EEH_Line_Item::create_event_subtotal()', 'event_espresso'), '4.6.0');
1299
+		return self::create_event_subtotal($total_line_item, $transaction);
1300 1300
 	}
1301 1301
 
1302 1302
 
Please login to merge, or discard this patch.
core/db_classes/EE_Question.class.php 2 patches
Doc Comments   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -184,7 +184,7 @@  discard block
 block discarded – undo
184 184
 	/**
185 185
 	 * returns the text for displaying the question to users
186 186
 	 * @access public
187
-	 * @return string
187
+	 * @return boolean
188 188
 	 */
189 189
 	public function display_text() {
190 190
 		return $this->get( 'QST_display_text' );
@@ -195,7 +195,7 @@  discard block
 block discarded – undo
195 195
 	/**
196 196
 	 * returns the text for the administrative label
197 197
 	 * @access public
198
-	 * @return string
198
+	 * @return boolean
199 199
 	 */
200 200
 	public function admin_label() {
201 201
 		return $this->get( 'QST_admin_label' );
@@ -206,7 +206,7 @@  discard block
 block discarded – undo
206 206
 	/**
207 207
 	 * returns the attendee column name for this question
208 208
 	 * @access public
209
-	 * @return string
209
+	 * @return boolean
210 210
 	 */
211 211
 	public function system_ID() {
212 212
 		return $this->get( 'QST_system' );
@@ -229,7 +229,7 @@  discard block
 block discarded – undo
229 229
 	 * returns the text which should be displayed when a user
230 230
 	 * doesn't answer this question in a form
231 231
 	 * @access public
232
-	 * @return string
232
+	 * @return boolean
233 233
 	 */
234 234
 	public function required_text() {
235 235
 		return $this->get( 'QST_required_text' );
@@ -240,7 +240,7 @@  discard block
 block discarded – undo
240 240
 	/**
241 241
 	 * returns the type of this question
242 242
 	 * @access public
243
-	 * @return string
243
+	 * @return boolean
244 244
 	 */
245 245
 	public function type() {
246 246
 		return $this->get( 'QST_type' );
@@ -252,7 +252,7 @@  discard block
 block discarded – undo
252 252
 	 * returns an integer showing where this question should
253 253
 	 * be placed in a sequence of questions
254 254
 	 * @access public
255
-	 * @return int
255
+	 * @return boolean
256 256
 	 */
257 257
 	public function order() {
258 258
 		return $this->get( 'QST_order' );
@@ -275,7 +275,7 @@  discard block
 block discarded – undo
275 275
 	/**
276 276
 	 * returns the id the wordpress user who created this question
277 277
 	 * @access public
278
-	 * @return int
278
+	 * @return boolean
279 279
 	 */
280 280
 	public function wp_user() {
281 281
 		return $this->get( 'QST_wp_user' );
@@ -369,7 +369,7 @@  discard block
 block discarded – undo
369 369
 	 * Adds an option for this question. Note: if the option were previously associated with a different
370 370
 	 * Question, that relationship will be overwritten.
371 371
 	 * @param EE_Question_Option $option
372
-	 * @return boolean success
372
+	 * @return EE_Base_Class success
373 373
 	 */
374 374
 	public function add_option( EE_Question_Option $option ) {
375 375
 		return $this->_add_relation_to( $option, 'Question_Option' );
@@ -392,7 +392,7 @@  discard block
 block discarded – undo
392 392
 	/**
393 393
 	 * Marks the option as deleted.
394 394
 	 * @param EE_Question_Option $option
395
-	 * @return boolean success
395
+	 * @return EE_Base_Class success
396 396
 	 */
397 397
 	public function remove_option( EE_Question_Option $option ) {
398 398
 		return $this->_remove_relation_to( $option, 'Question_Option' );
@@ -461,7 +461,7 @@  discard block
 block discarded – undo
461 461
 	
462 462
 	/**
463 463
 	 * Returns the question's maximum allowed response size
464
-	 * @return int|float
464
+	 * @return boolean
465 465
 	 */
466 466
 	public function max() {
467 467
 		return $this->get( 'QST_max' );
Please login to merge, or discard this patch.
Spacing   +74 added lines, -74 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1
-<?php if ( !defined( 'EVENT_ESPRESSO_VERSION' ) ) {
2
-	exit( 'No direct script access allowed' );
1
+<?php if ( ! defined('EVENT_ESPRESSO_VERSION')) {
2
+	exit('No direct script access allowed');
3 3
 }
4 4
 /**
5 5
  * Event Espresso
@@ -37,9 +37,9 @@  discard block
 block discarded – undo
37 37
 	 *                             		    date_format and the second value is the time format
38 38
 	 * @return EE_Question
39 39
 	 */
40
-	public static function new_instance( $props_n_values = array(), $timezone = null, $date_formats = array() ) {
41
-		$has_object = parent::_check_for_object( $props_n_values, __CLASS__ );
42
-		return $has_object ? $has_object : new self( $props_n_values, false, $timezone, $date_formats );
40
+	public static function new_instance($props_n_values = array(), $timezone = null, $date_formats = array()) {
41
+		$has_object = parent::_check_for_object($props_n_values, __CLASS__);
42
+		return $has_object ? $has_object : new self($props_n_values, false, $timezone, $date_formats);
43 43
 	}
44 44
 
45 45
 
@@ -50,8 +50,8 @@  discard block
 block discarded – undo
50 50
 	 *                          		the website will be used.
51 51
 	 * @return EE_Question
52 52
 	 */
53
-	public static function new_instance_from_db( $props_n_values = array(), $timezone = null ) {
54
-		return new self( $props_n_values, TRUE, $timezone );
53
+	public static function new_instance_from_db($props_n_values = array(), $timezone = null) {
54
+		return new self($props_n_values, TRUE, $timezone);
55 55
 	}
56 56
 
57 57
 
@@ -62,8 +62,8 @@  discard block
 block discarded – undo
62 62
 	 * @access        public
63 63
 	 * @param string $QST_display_text
64 64
 	 */
65
-	public function set_display_text( $QST_display_text = '' ) {
66
-		$this->set( 'QST_display_text', $QST_display_text );
65
+	public function set_display_text($QST_display_text = '') {
66
+		$this->set('QST_display_text', $QST_display_text);
67 67
 	}
68 68
 
69 69
 
@@ -74,8 +74,8 @@  discard block
 block discarded – undo
74 74
 	 * @access        public
75 75
 	 * @param        string $QST_admin_label
76 76
 	 */
77
-	public function set_admin_label( $QST_admin_label = '' ) {
78
-		$this->set( 'QST_admin_label', $QST_admin_label );
77
+	public function set_admin_label($QST_admin_label = '') {
78
+		$this->set('QST_admin_label', $QST_admin_label);
79 79
 	}
80 80
 
81 81
 
@@ -86,8 +86,8 @@  discard block
 block discarded – undo
86 86
 	 * @access        public
87 87
 	 * @param        mixed $QST_system
88 88
 	 */
89
-	public function set_system_ID( $QST_system = '' ) {
90
-		$this->set( 'QST_system', $QST_system );
89
+	public function set_system_ID($QST_system = '') {
90
+		$this->set('QST_system', $QST_system);
91 91
 	}
92 92
 
93 93
 
@@ -98,8 +98,8 @@  discard block
 block discarded – undo
98 98
 	 * @access        public
99 99
 	 * @param        string $QST_type
100 100
 	 */
101
-	public function set_question_type( $QST_type = '' ) {
102
-		$this->set( 'QST_type', $QST_type );
101
+	public function set_question_type($QST_type = '') {
102
+		$this->set('QST_type', $QST_type);
103 103
 	}
104 104
 
105 105
 
@@ -110,8 +110,8 @@  discard block
 block discarded – undo
110 110
 	 * @access        public
111 111
 	 * @param        bool $QST_required
112 112
 	 */
113
-	public function set_required( $QST_required = FALSE ) {
114
-		$this->set( 'QST_required', $QST_required );
113
+	public function set_required($QST_required = FALSE) {
114
+		$this->set('QST_required', $QST_required);
115 115
 	}
116 116
 
117 117
 
@@ -122,8 +122,8 @@  discard block
 block discarded – undo
122 122
 	 * @access        public
123 123
 	 * @param        string $QST_required_text
124 124
 	 */
125
-	public function set_required_text( $QST_required_text = '' ) {
126
-		$this->set( 'QST_required_text', $QST_required_text );
125
+	public function set_required_text($QST_required_text = '') {
126
+		$this->set('QST_required_text', $QST_required_text);
127 127
 	}
128 128
 
129 129
 
@@ -134,8 +134,8 @@  discard block
 block discarded – undo
134 134
 	 * @access        public
135 135
 	 * @param        int $QST_order
136 136
 	 */
137
-	public function set_order( $QST_order = 0 ) {
138
-		$this->set( 'QST_order', $QST_order );
137
+	public function set_order($QST_order = 0) {
138
+		$this->set('QST_order', $QST_order);
139 139
 	}
140 140
 
141 141
 
@@ -146,8 +146,8 @@  discard block
 block discarded – undo
146 146
 	 * @access        public
147 147
 	 * @param        bool $QST_admin_only
148 148
 	 */
149
-	public function set_admin_only( $QST_admin_only = FALSE ) {
150
-		$this->set( 'QST_admin_only', $QST_admin_only );
149
+	public function set_admin_only($QST_admin_only = FALSE) {
150
+		$this->set('QST_admin_only', $QST_admin_only);
151 151
 	}
152 152
 
153 153
 
@@ -158,8 +158,8 @@  discard block
 block discarded – undo
158 158
 	 * @access        public
159 159
 	 * @param        int $QST_wp_user
160 160
 	 */
161
-	public function set_wp_user( $QST_wp_user = 1 ) {
162
-		$this->set( 'QST_wp_user', $QST_wp_user );
161
+	public function set_wp_user($QST_wp_user = 1) {
162
+		$this->set('QST_wp_user', $QST_wp_user);
163 163
 	}
164 164
 
165 165
 
@@ -175,8 +175,8 @@  discard block
 block discarded – undo
175 175
 	 * @access        public
176 176
 	 * @param 	bool $QST_deleted
177 177
 	 */
178
-	public function set_deleted( $QST_deleted = FALSE ) {
179
-		$this->set( 'QST_deleted', $QST_deleted );
178
+	public function set_deleted($QST_deleted = FALSE) {
179
+		$this->set('QST_deleted', $QST_deleted);
180 180
 	}
181 181
 
182 182
 
@@ -187,7 +187,7 @@  discard block
 block discarded – undo
187 187
 	 * @return string
188 188
 	 */
189 189
 	public function display_text() {
190
-		return $this->get( 'QST_display_text' );
190
+		return $this->get('QST_display_text');
191 191
 	}
192 192
 
193 193
 
@@ -198,7 +198,7 @@  discard block
 block discarded – undo
198 198
 	 * @return string
199 199
 	 */
200 200
 	public function admin_label() {
201
-		return $this->get( 'QST_admin_label' );
201
+		return $this->get('QST_admin_label');
202 202
 	}
203 203
 
204 204
 
@@ -209,7 +209,7 @@  discard block
 block discarded – undo
209 209
 	 * @return string
210 210
 	 */
211 211
 	public function system_ID() {
212
-		return $this->get( 'QST_system' );
212
+		return $this->get('QST_system');
213 213
 	}
214 214
 
215 215
 
@@ -220,7 +220,7 @@  discard block
 block discarded – undo
220 220
 	 * @return boolean
221 221
 	 */
222 222
 	public function required() {
223
-		return $this->get( 'QST_required' );
223
+		return $this->get('QST_required');
224 224
 	}
225 225
 
226 226
 
@@ -232,7 +232,7 @@  discard block
 block discarded – undo
232 232
 	 * @return string
233 233
 	 */
234 234
 	public function required_text() {
235
-		return $this->get( 'QST_required_text' );
235
+		return $this->get('QST_required_text');
236 236
 	}
237 237
 
238 238
 
@@ -243,7 +243,7 @@  discard block
 block discarded – undo
243 243
 	 * @return string
244 244
 	 */
245 245
 	public function type() {
246
-		return $this->get( 'QST_type' );
246
+		return $this->get('QST_type');
247 247
 	}
248 248
 
249 249
 
@@ -255,7 +255,7 @@  discard block
 block discarded – undo
255 255
 	 * @return int
256 256
 	 */
257 257
 	public function order() {
258
-		return $this->get( 'QST_order' );
258
+		return $this->get('QST_order');
259 259
 	}
260 260
 
261 261
 
@@ -267,7 +267,7 @@  discard block
 block discarded – undo
267 267
 	 * @return boolean
268 268
 	 */
269 269
 	public function admin_only() {
270
-		return $this->get( 'QST_admin_only' );
270
+		return $this->get('QST_admin_only');
271 271
 	}
272 272
 
273 273
 
@@ -278,7 +278,7 @@  discard block
 block discarded – undo
278 278
 	 * @return int
279 279
 	 */
280 280
 	public function wp_user() {
281
-		return $this->get( 'QST_wp_user' );
281
+		return $this->get('QST_wp_user');
282 282
 	}
283 283
 
284 284
 
@@ -289,7 +289,7 @@  discard block
 block discarded – undo
289 289
 	 * @return boolean
290 290
 	 */
291 291
 	public function deleted() {
292
-		return $this->get( 'QST_deleted' );
292
+		return $this->get('QST_deleted');
293 293
 	}
294 294
 
295 295
 
@@ -299,7 +299,7 @@  discard block
 block discarded – undo
299 299
 	 * @return EE_Answer[]
300 300
 	 */
301 301
 	public function answers() {
302
-		return $this->get_many_related( 'Answer' );
302
+		return $this->get_many_related('Answer');
303 303
 	}
304 304
 
305 305
 
@@ -309,7 +309,7 @@  discard block
 block discarded – undo
309 309
 	 * @return boolean true = has answers, false = no answers.
310 310
 	 */
311 311
 	public function has_answers() {
312
-		return $this->count_related( 'Answer' ) > 0 ? TRUE : FALSE;
312
+		return $this->count_related('Answer') > 0 ? TRUE : FALSE;
313 313
 	}
314 314
 
315 315
 
@@ -319,7 +319,7 @@  discard block
 block discarded – undo
319 319
 	 * @return EE_Question_Group[]
320 320
 	 */
321 321
 	public function question_groups() {
322
-		return $this->get_many_related( 'Question_Group' );
322
+		return $this->get_many_related('Question_Group');
323 323
 	}
324 324
 
325 325
 
@@ -333,24 +333,24 @@  discard block
 block discarded – undo
333 333
 	 *                                                       whether it was trashed or not.
334 334
 	 * @return EE_Question_Option[]
335 335
 	 */
336
-	public function options( $notDeletedOptionsOnly = TRUE, $selected_value_to_always_include = NULL ) {
337
-		if ( ! $this->ID() ) {
336
+	public function options($notDeletedOptionsOnly = TRUE, $selected_value_to_always_include = NULL) {
337
+		if ( ! $this->ID()) {
338 338
 			return array();
339 339
 		}
340 340
 		$query_params = array();
341
-		if ( $selected_value_to_always_include ) {
342
-			if ( is_array( $selected_value_to_always_include ) ) {
343
-				$query_params[ 0 ][ 'OR*options-query' ][ 'QSO_value' ] = array( 'IN', $selected_value_to_always_include );
341
+		if ($selected_value_to_always_include) {
342
+			if (is_array($selected_value_to_always_include)) {
343
+				$query_params[0]['OR*options-query']['QSO_value'] = array('IN', $selected_value_to_always_include);
344 344
 			} else {
345
-				$query_params[ 0 ][ 'OR*options-query' ][ 'QSO_value' ] = $selected_value_to_always_include;
345
+				$query_params[0]['OR*options-query']['QSO_value'] = $selected_value_to_always_include;
346 346
 			}
347 347
 		}
348
-		if ( $notDeletedOptionsOnly ) {
349
-			$query_params[ 0 ][ 'OR*options-query' ][ 'QSO_deleted' ] = FALSE;
348
+		if ($notDeletedOptionsOnly) {
349
+			$query_params[0]['OR*options-query']['QSO_deleted'] = FALSE;
350 350
 		}
351 351
 		//order by QSO_order
352
-		$query_params[ 'order_by' ] = array( 'QSO_order' => 'ASC' );
353
-		return $this->get_many_related( 'Question_Option', $query_params );
352
+		$query_params['order_by'] = array('QSO_order' => 'ASC');
353
+		return $this->get_many_related('Question_Option', $query_params);
354 354
 	}
355 355
 
356 356
 
@@ -360,7 +360,7 @@  discard block
 block discarded – undo
360 360
 	 * @return \EE_Question_Option[]
361 361
 	 */
362 362
 	public function temp_options() {
363
-		return $this->_model_relations[ 'Question_Option' ];
363
+		return $this->_model_relations['Question_Option'];
364 364
 	}
365 365
 
366 366
 
@@ -371,8 +371,8 @@  discard block
 block discarded – undo
371 371
 	 * @param EE_Question_Option $option
372 372
 	 * @return boolean success
373 373
 	 */
374
-	public function add_option( EE_Question_Option $option ) {
375
-		return $this->_add_relation_to( $option, 'Question_Option' );
374
+	public function add_option(EE_Question_Option $option) {
375
+		return $this->_add_relation_to($option, 'Question_Option');
376 376
 	}
377 377
 
378 378
 
@@ -382,8 +382,8 @@  discard block
 block discarded – undo
382 382
 	 * @param EE_Question_Option $option
383 383
 	 * @return boolean success
384 384
 	 */
385
-	public function add_temp_option( EE_Question_Option $option ) {
386
-		$this->_model_relations[ 'Question_Option' ][ ] = $option;
385
+	public function add_temp_option(EE_Question_Option $option) {
386
+		$this->_model_relations['Question_Option'][] = $option;
387 387
 		return TRUE;
388 388
 	}
389 389
 
@@ -394,8 +394,8 @@  discard block
 block discarded – undo
394 394
 	 * @param EE_Question_Option $option
395 395
 	 * @return boolean success
396 396
 	 */
397
-	public function remove_option( EE_Question_Option $option ) {
398
-		return $this->_remove_relation_to( $option, 'Question_Option' );
397
+	public function remove_option(EE_Question_Option $option) {
398
+		return $this->_remove_relation_to($option, 'Question_Option');
399 399
 	}
400 400
 
401 401
 
@@ -404,8 +404,8 @@  discard block
 block discarded – undo
404 404
 	 * @return bool
405 405
 	 */
406 406
 	public function is_system_question() {
407
-		$system_ID = $this->get( 'QST_system' );
408
-		return ! empty( $system_ID ) ? TRUE : FALSE;
407
+		$system_ID = $this->get('QST_system');
408
+		return ! empty($system_ID) ? TRUE : FALSE;
409 409
 	}
410 410
 
411 411
 
@@ -418,8 +418,8 @@  discard block
 block discarded – undo
418 418
 	 */
419 419
 	public function set_order_to_latest() {
420 420
 		$latest_order = $this->get_model()->get_latest_question_order();
421
-		$latest_order ++;
422
-		$this->set( 'QST_order', $latest_order );
421
+		$latest_order++;
422
+		$this->set('QST_order', $latest_order);
423 423
 	}
424 424
 
425 425
 
@@ -438,20 +438,20 @@  discard block
 block discarded – undo
438 438
 	 * Duplicates this question and its question options
439 439
 	 * @return \EE_Question
440 440
 	 */
441
-	public function duplicate( $options = array() ) {
441
+	public function duplicate($options = array()) {
442 442
 		$new_question = clone $this;
443
-		$new_question->set( 'QST_ID', null );
444
-		$new_question->set_display_text( sprintf( __( '%s **Duplicate**', 'event_espresso' ), $this->display_text() ) );
445
-		$new_question->set_admin_label( sprintf( __( '%s **Duplicate**', 'event_espresso' ), $this->admin_label() ) );
446
-		$new_question->set_system_ID( null );
447
-		$new_question->set_wp_user( get_current_user_id() );
443
+		$new_question->set('QST_ID', null);
444
+		$new_question->set_display_text(sprintf(__('%s **Duplicate**', 'event_espresso'), $this->display_text()));
445
+		$new_question->set_admin_label(sprintf(__('%s **Duplicate**', 'event_espresso'), $this->admin_label()));
446
+		$new_question->set_system_ID(null);
447
+		$new_question->set_wp_user(get_current_user_id());
448 448
                 //if we're duplicating a trashed question, assume we don't want the new one to be trashed
449
-                $new_question->set_deleted( false );
449
+                $new_question->set_deleted(false);
450 450
 		$success = $new_question->save();
451
-		if( $success ) {
451
+		if ($success) {
452 452
 			//we don't totally want to duplicate the question options, because we want them to be for the NEW question
453
-			foreach( $this->options() as $question_option ) {
454
-				$question_option->duplicate( array( 'QST_ID' => $new_question->ID() ) );
453
+			foreach ($this->options() as $question_option) {
454
+				$question_option->duplicate(array('QST_ID' => $new_question->ID()));
455 455
 			}
456 456
 			return $new_question;
457 457
 		} else {
@@ -464,7 +464,7 @@  discard block
 block discarded – undo
464 464
 	 * @return int|float
465 465
 	 */
466 466
 	public function max() {
467
-		return $this->get( 'QST_max' );
467
+		return $this->get('QST_max');
468 468
 	}
469 469
 	
470 470
 	/**
@@ -472,8 +472,8 @@  discard block
 block discarded – undo
472 472
 	 * @param int|float $new_max
473 473
 	 * @return int|float
474 474
 	 */
475
-	public function set_max( $new_max ) {
476
-		return $this->set( 'QST_max', $new_max );
475
+	public function set_max($new_max) {
476
+		return $this->set('QST_max', $new_max);
477 477
 	}
478 478
 
479 479
 
Please login to merge, or discard this patch.
strategies/validation/EE_Max_Length_Validation_Strategy.strategy.php 1 patch
Spacing   +12 added lines, -12 removed lines patch added patch discarded remove patch
@@ -8,36 +8,36 @@
 block discarded – undo
8 8
  * @subpackage	Expression package is undefined on line 19, column 19 in Templates/Scripting/PHPClass.php.
9 9
  * @author				Mike Nelson
10 10
  */
11
-class EE_Max_Length_Validation_Strategy extends EE_Validation_Strategy_Base{
11
+class EE_Max_Length_Validation_Strategy extends EE_Validation_Strategy_Base {
12 12
 
13 13
 	protected $_max_length;
14 14
 
15
-	public function __construct( $validation_error_message = NULL, $max_length = EE_INF ) {
15
+	public function __construct($validation_error_message = NULL, $max_length = EE_INF) {
16 16
 		$this->_max_length = $max_length;
17
-		if( $validation_error_message === null ) {
18
-			$validation_error_message = sprintf( __( 'Input is too long. Maximum number of characters is %1$s', 'event_espresso' ), $max_length );
17
+		if ($validation_error_message === null) {
18
+			$validation_error_message = sprintf(__('Input is too long. Maximum number of characters is %1$s', 'event_espresso'), $max_length);
19 19
 		}
20
-		parent::__construct( $validation_error_message );
20
+		parent::__construct($validation_error_message);
21 21
 	}
22 22
 
23 23
 	/**
24 24
 	 * @param $normalized_value
25 25
 	 */
26 26
 	public function validate($normalized_value) {
27
-		if( $this->_max_length !== EE_INF &&
27
+		if ($this->_max_length !== EE_INF &&
28 28
 				$normalized_value &&
29
-				is_string( $normalized_value ) &&
30
-				 strlen( $normalized_value ) > $this->_max_length){
31
-			throw new EE_Validation_Error( $this->get_validation_error_message(), 'maxlength' );
29
+				is_string($normalized_value) &&
30
+				 strlen($normalized_value) > $this->_max_length) {
31
+			throw new EE_Validation_Error($this->get_validation_error_message(), 'maxlength');
32 32
 		}
33 33
 	}
34 34
 
35 35
 	/**
36 36
 	 * @return array
37 37
 	 */
38
-	function get_jquery_validation_rule_array(){
39
-		if( $this->_max_length !== EE_INF ) {
40
-			return array( 'maxlength'=> $this->_max_length, 'messages' => array( 'maxlength' => $this->get_validation_error_message() ) );
38
+	function get_jquery_validation_rule_array() {
39
+		if ($this->_max_length !== EE_INF) {
40
+			return array('maxlength'=> $this->_max_length, 'messages' => array('maxlength' => $this->get_validation_error_message()));
41 41
 		} else {
42 42
 			return array();
43 43
 		}
Please login to merge, or discard this patch.
core/libraries/batch/JobHandlerBaseClasses/JobHandlerFile.php 2 patches
Indentation   +12 added lines, -12 removed lines patch added patch discarded remove patch
@@ -1,17 +1,17 @@
 block discarded – undo
1 1
 <?php
2 2
 /**
3
- *
4
- * Class JobHandlerFile
5
- *
6
- * Base class for common implementations of JobHandlerInterface, but ones
7
- * which write to a temporary file
8
- *
9
- * @package         Event Espresso
10
- * @subpackage    batch
11
- * @author				Mike Nelson
12
- * @since		 	   4.8.26
13
- *
14
- */
3
+	 *
4
+	 * Class JobHandlerFile
5
+	 *
6
+	 * Base class for common implementations of JobHandlerInterface, but ones
7
+	 * which write to a temporary file
8
+	 *
9
+	 * @package         Event Espresso
10
+	 * @subpackage    batch
11
+	 * @author				Mike Nelson
12
+	 * @since		 	   4.8.26
13
+	 *
14
+	 */
15 15
 namespace EventEspressoBatchRequest\JobHandlerBaseClasses;
16 16
 
17 17
 use EventEspressoBatchRequest\Helpers\BatchRequestException;
Please login to merge, or discard this patch.
Spacing   +23 added lines, -23 removed lines patch added patch discarded remove patch
@@ -16,8 +16,8 @@  discard block
 block discarded – undo
16 16
 
17 17
 use EventEspressoBatchRequest\Helpers\BatchRequestException;
18 18
 
19
-if ( ! defined( 'EVENT_ESPRESSO_VERSION' ) ) {
20
-	exit( 'No direct script access allowed' );
19
+if ( ! defined('EVENT_ESPRESSO_VERSION')) {
20
+	exit('No direct script access allowed');
21 21
 }
22 22
 
23 23
 
@@ -39,8 +39,8 @@  discard block
 block discarded – undo
39 39
 	 *
40 40
 	 * @param \EEHI_File|null $file_helper
41 41
 	 */
42
-	public function __construct( \EEHI_File $file_helper = null ) {
43
-		if( ! $file_helper ) {
42
+	public function __construct(\EEHI_File $file_helper = null) {
43
+		if ( ! $file_helper) {
44 44
 			$this->_file_helper = new \EEH_File();
45 45
 		}
46 46
 	}
@@ -56,39 +56,39 @@  discard block
 block discarded – undo
56 56
 	 * @return string
57 57
 	 * @throws \EventEspressoBatchRequest\Helpers\BatchRequestException
58 58
 	 */
59
-	public function create_file_from_job_with_name( $job_id, $filename, $filetype = 'application/ms-excel' ) {
59
+	public function create_file_from_job_with_name($job_id, $filename, $filetype = 'application/ms-excel') {
60 60
 		$filepath = '';
61
-		try{
61
+		try {
62 62
 			$success = $this->_file_helper->ensure_folder_exists_and_is_writable(
63
-				EVENT_ESPRESSO_UPLOAD_DIR . JobHandlerFile::temp_folder_name
63
+				EVENT_ESPRESSO_UPLOAD_DIR.JobHandlerFile::temp_folder_name
64 64
 			);
65
-			if ( $success ) {
65
+			if ($success) {
66 66
 				$success = $this->_file_helper->ensure_folder_exists_and_is_writable(
67
-					EVENT_ESPRESSO_UPLOAD_DIR . JobHandlerFile::temp_folder_name . DS . $job_id
67
+					EVENT_ESPRESSO_UPLOAD_DIR.JobHandlerFile::temp_folder_name.DS.$job_id
68 68
 				);
69 69
 			}
70
-			if( $success ) {
71
-				$filepath = EVENT_ESPRESSO_UPLOAD_DIR . JobHandlerFile::temp_folder_name . DS . $job_id . DS. $filename;
72
-				$success = $this->_file_helper->ensure_file_exists_and_is_writable( $filepath );
70
+			if ($success) {
71
+				$filepath = EVENT_ESPRESSO_UPLOAD_DIR.JobHandlerFile::temp_folder_name.DS.$job_id.DS.$filename;
72
+				$success = $this->_file_helper->ensure_file_exists_and_is_writable($filepath);
73 73
 			}
74 74
 			//let's add the .htaccess file so safari will open the file properly
75
-			if( $success ) {
76
-				$extension = \EEH_File::get_file_extension( $filepath );
75
+			if ($success) {
76
+				$extension = \EEH_File::get_file_extension($filepath);
77 77
 				\EEH_File::write_to_file(
78
-					EVENT_ESPRESSO_UPLOAD_DIR . JobHandlerFile::temp_folder_name . DS . $job_id . DS . '.htaccess',
79
-					'AddType ' . $filetype . ' ' . $extension,
78
+					EVENT_ESPRESSO_UPLOAD_DIR.JobHandlerFile::temp_folder_name.DS.$job_id.DS.'.htaccess',
79
+					'AddType '.$filetype.' '.$extension,
80 80
 					'.htaccess'
81 81
 				);
82 82
 			}
83 83
 			//those methods normally fail with an exception, but if not, let's do it
84
-			if( ! $success ) {
85
-				throw new \EE_Error( 'could_not_create_temp_file',
86
-				__( 'An unknown error occurred', 'event_espresso' ));
84
+			if ( ! $success) {
85
+				throw new \EE_Error('could_not_create_temp_file',
86
+				__('An unknown error occurred', 'event_espresso'));
87 87
 			}
88
-		} catch( \EE_Error $e ) {
88
+		} catch (\EE_Error $e) {
89 89
 			throw new BatchRequestException(
90 90
 				sprintf(
91
-					__( 'Could not create temporary file for job %1$s, because: %2$s ', 'event_espresso' ),
91
+					__('Could not create temporary file for job %1$s, because: %2$s ', 'event_espresso'),
92 92
 					$job_id,
93 93
 					$e->getMessage()
94 94
 				),
@@ -104,8 +104,8 @@  discard block
 block discarded – undo
104 104
 	 * @param string $filepath
105 105
 	 * @return string url to file
106 106
 	 */
107
-	public function get_url_to_file( $filepath ) {
108
-		return str_replace( EVENT_ESPRESSO_UPLOAD_DIR, EVENT_ESPRESSO_UPLOAD_URL, $filepath );
107
+	public function get_url_to_file($filepath) {
108
+		return str_replace(EVENT_ESPRESSO_UPLOAD_DIR, EVENT_ESPRESSO_UPLOAD_URL, $filepath);
109 109
 	}
110 110
 }
111 111
 
Please login to merge, or discard this patch.
libraries/form_sections/payment_methods/EE_Payment_Method_Form.form.php 1 patch
Spacing   +32 added lines, -32 removed lines patch added patch discarded remove patch
@@ -4,7 +4,7 @@  discard block
 block discarded – undo
4 4
  * Specialized form for payment methods, allowing for easy setting and retrieving of meta fields.
5 5
  * Uses EEM_Payment_Method as the model
6 6
  */
7
-class EE_Payment_Method_Form extends EE_Model_Form_Section{
7
+class EE_Payment_Method_Form extends EE_Model_Form_Section {
8 8
 
9 9
 	/**
10 10
 	 * All the subsection inputs that correspond ot extra meta rows
@@ -39,37 +39,37 @@  discard block
 block discarded – undo
39 39
 	 *	@see EE_Model_Form_Section::__construct() for more
40 40
 	 * }
41 41
 	 */
42
-	public function __construct($options_array = array()){
42
+	public function __construct($options_array = array()) {
43 43
 		$this->_model = EEM_Payment_Method::instance();
44 44
 		$this->_options_array = $options_array;
45
-		if(isset($options_array['payment_method_type'])){
45
+		if (isset($options_array['payment_method_type'])) {
46 46
 			$this->_payment_method_type = $options_array['payment_method_type'];
47 47
 		}
48 48
 		$options_array = $this->_options_array;
49
-		if(isset($options_array['extra_meta_inputs'])){
50
-			$this->_extra_meta_inputs = array_merge($this->_extra_meta_inputs,$options_array['extra_meta_inputs']);
49
+		if (isset($options_array['extra_meta_inputs'])) {
50
+			$this->_extra_meta_inputs = array_merge($this->_extra_meta_inputs, $options_array['extra_meta_inputs']);
51 51
 		}
52
-		if($this->_extra_meta_inputs){
53
-			$this->_subsections = array_merge($this->_subsections,$this->_extra_meta_inputs);
52
+		if ($this->_extra_meta_inputs) {
53
+			$this->_subsections = array_merge($this->_subsections, $this->_extra_meta_inputs);
54 54
 		}
55 55
 		$this->_subsections['PMD_button_url'] = new EE_Admin_File_Uploader_Input(
56
-			array( 'html_label_text'=>  __( 'Button URL', 'event_espresso' ))
56
+			array('html_label_text'=>  __('Button URL', 'event_espresso'))
57 57
 		);
58 58
 		$this->_subsections['PMD_scope'] = new EE_Checkbox_Multi_Input(
59 59
 			EEM_Payment_Method::instance()->scopes(),
60
-			array( 'html_label_text' => $this->_model->field_settings_for('PMD_scope')->get_nicename() . EEH_Template::get_help_tab_link( 'payment_methods_overview' ))
60
+			array('html_label_text' => $this->_model->field_settings_for('PMD_scope')->get_nicename().EEH_Template::get_help_tab_link('payment_methods_overview'))
61 61
 		);
62 62
 		//setup the currency options
63 63
 		$this->_subsections['Currency'] = new EE_Select_Multi_Model_Input(
64
-			EEM_Currency::instance()->get_all_currencies_usable_by( $this->_payment_method_type ),
64
+			EEM_Currency::instance()->get_all_currencies_usable_by($this->_payment_method_type),
65 65
 			array(
66
-				'html_label_text'=>  __( 'Currencies Supported', 'event_espresso' ),
66
+				'html_label_text'=>  __('Currencies Supported', 'event_espresso'),
67 67
 				'required'=>TRUE
68 68
 			)
69 69
 		);
70
-		$this->_subsections['PMD_order'] = new EE_Text_Input( array(
71
-			'html_label_text' => __( 'Order', 'event_espresso' ),
72
-			'html_help_text' => __( 'Lowest numbers will be shown first', 'event_espresso' ),
70
+		$this->_subsections['PMD_order'] = new EE_Text_Input(array(
71
+			'html_label_text' => __('Order', 'event_espresso'),
72
+			'html_help_text' => __('Lowest numbers will be shown first', 'event_espresso'),
73 73
 			'normalization_strategy' => new EE_Int_Normalization(),
74 74
 			'validation_strategies' => array(
75 75
 				new EE_Int_Validation_Strategy()
@@ -88,15 +88,15 @@  discard block
 block discarded – undo
88 88
 	 * @param string 	$name
89 89
 	 * @throws EE_Error
90 90
 	 */
91
-	public function _construct_finalize( $parent_form_section, $name ) {
92
-		if( ! $this->_payment_method_type instanceof EE_PMT_Base ){
93
-			throw new EE_Error( sprintf( __( 'Payment Method forms must have set their payment method type BEFORE calling _construct_finalize', 'event_espresso' )));
91
+	public function _construct_finalize($parent_form_section, $name) {
92
+		if ( ! $this->_payment_method_type instanceof EE_PMT_Base) {
93
+			throw new EE_Error(sprintf(__('Payment Method forms must have set their payment method type BEFORE calling _construct_finalize', 'event_espresso')));
94 94
 		}
95 95
 		//set the name of this form based on the payment method type
96
-		if( ! $this->_name && ! $name ){
97
-			$name = str_replace(" ","_",ucwords(str_replace("_"," ",($this->_payment_method_type->system_name()))))."_Settings_Form";
96
+		if ( ! $this->_name && ! $name) {
97
+			$name = str_replace(" ", "_", ucwords(str_replace("_", " ", ($this->_payment_method_type->system_name()))))."_Settings_Form";
98 98
 		}
99
-		parent::_construct_finalize( $parent_form_section, $name );
99
+		parent::_construct_finalize($parent_form_section, $name);
100 100
 	}
101 101
 
102 102
 
@@ -105,8 +105,8 @@  discard block
 block discarded – undo
105 105
 	 * @param $payment_method_type
106 106
 	 * @throws EE_Error
107 107
 	 */
108
-	public function set_payment_method_type( $payment_method_type ){
109
-		if( ! $payment_method_type instanceof EE_PMT_Base){
108
+	public function set_payment_method_type($payment_method_type) {
109
+		if ( ! $payment_method_type instanceof EE_PMT_Base) {
110 110
 			throw new EE_Error(sprintf(__("Payment Method forms MUST set a payment method type by using _set_payment_method_type", "event_espresso")));
111 111
 		}
112 112
 		$this->_payment_method_type = $payment_method_type;
@@ -118,10 +118,10 @@  discard block
 block discarded – undo
118 118
 	 * extends the model form section's save method to also save the extra meta field values
119 119
 	 * @return int ID of the payment method inserted, or true on update
120 120
 	 */
121
-	public function save(){
121
+	public function save() {
122 122
 		$parent_save_val = parent::save();
123
-		if( $this->_model_object && $this->_model_object->ID()){
124
-			foreach($this->_extra_meta_inputs as $input_name => $input){
123
+		if ($this->_model_object && $this->_model_object->ID()) {
124
+			foreach ($this->_extra_meta_inputs as $input_name => $input) {
125 125
 				$this->_model_object->update_extra_meta($input_name, $input->normalized_value());
126 126
 			}
127 127
 		}
@@ -138,8 +138,8 @@  discard block
 block discarded – undo
138 138
 		$model_obj = $this->_model->ensure_is_obj($model_obj);
139 139
 		parent::populate_model_obj($model_obj);
140 140
 		$extra_meta = $model_obj->all_extra_meta_array();
141
-		foreach($this->_extra_meta_inputs as $input_name => $extra_meta_input){
142
-			if(isset($extra_meta[$input_name])){
141
+		foreach ($this->_extra_meta_inputs as $input_name => $extra_meta_input) {
142
+			if (isset($extra_meta[$input_name])) {
143 143
 				$extra_meta_input->set_default($extra_meta[$input_name]);
144 144
 			}
145 145
 		}
@@ -151,10 +151,10 @@  discard block
 block discarded – undo
151 151
 	 * gets the default name of this form section if none is specified
152 152
 	 * @return string
153 153
 	 */
154
-	protected function _set_default_name_if_empty(){
155
-		if( ! $this->_name ){
156
-			$default_name = str_replace("EEM_", "", get_class($this->_model)) . "_Model_Form";
157
-			$this->_name =  $default_name;
154
+	protected function _set_default_name_if_empty() {
155
+		if ( ! $this->_name) {
156
+			$default_name = str_replace("EEM_", "", get_class($this->_model))."_Model_Form";
157
+			$this->_name = $default_name;
158 158
 		}
159 159
 	}
160 160
 
@@ -164,7 +164,7 @@  discard block
 block discarded – undo
164 164
 	 * Gets all the extra meta inputs in this form
165 165
 	 * @return EE_Form_Input_Base[]
166 166
 	 */
167
-	public function extra_meta_inputs(){
167
+	public function extra_meta_inputs() {
168 168
 		return $this->_extra_meta_inputs;
169 169
 	}
170 170
 }
Please login to merge, or discard this patch.
admin_pages/registration_form/Registration_Form_Admin_Page.core.php 2 patches
Braces   +9 added lines, -13 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
@@ -330,14 +331,9 @@  discard block
 block discarded – undo
330 331
 			else if ( $fieldName == 'QST_admin_label' && ( isset( $this->_req_data['QST_admin_label'] ) && empty( $this->_req_data['QST_admin_label'] )  )) {
331 332
 				$QST_text = isset( $this->_req_data['QST_display_text'] ) ? $this->_req_data['QST_display_text'] : '' ;
332 333
 				$set_column_values[$fieldName] = sanitize_title(wp_trim_words($QST_text,10));
333
-			}
334
-
335
-
336
-			else if ( $fieldName == 'QST_admin_only' && ( !isset( $this->_req_data['QST_admin_only'] ) ) ) {
334
+			} else if ( $fieldName == 'QST_admin_only' && ( !isset( $this->_req_data['QST_admin_only'] ) ) ) {
337 335
 				$set_column_values[$fieldName] = 0;
338
-			}
339
-
340
-			else if ( $fieldName == 'QST_max' ) {
336
+			} else if ( $fieldName == 'QST_max' ) {
341 337
 				$qst_system = EEM_Question::instance()->get_var(
342 338
 					array(
343 339
 						array(
@@ -390,7 +386,7 @@  discard block
 block discarded – undo
390 386
 			$question=$this->_question_model->get_one_by_ID($ID);
391 387
 			$additional_hidden_fields=array('QST_ID'=>array('type'=>'hidden','value'=>$ID));
392 388
 			$this->_set_add_edit_form_tags('update_question', $additional_hidden_fields);
393
-		}else{
389
+		} else{
394 390
 			$question= EE_Question::new_instance();
395 391
 			$question->set_order_to_latest();
396 392
 			$this->_set_add_edit_form_tags('insert_question');
@@ -421,7 +417,7 @@  discard block
 block discarded – undo
421 417
 			$ID=$this->_question_model->insert($set_column_values);
422 418
 			$success = $ID ? true : false;
423 419
 			$action_desc = 'added';
424
-		}else{
420
+		} else{
425 421
 			$ID=absint($this->_req_data['QST_ID']);
426 422
 			$pk=$this->_question_model->primary_key_name();
427 423
 			$wheres=array($pk=>$ID);
@@ -442,7 +438,7 @@  discard block
 block discarded – undo
442 438
 					$option_req_index=$this->_get_option_req_data_index($option_ID);
443 439
 					if($option_req_index!==FALSE){
444 440
 						$option->save($this->_req_data['question_options'][$option_req_index]);
445
-					}else{
441
+					} else{
446 442
 						//not found, remove it
447 443
 						$option->delete();
448 444
 					}
@@ -519,7 +515,7 @@  discard block
 block discarded – undo
519 515
 						'QSG_name'=>array('LIKE',"%$search_string%"),
520 516
 						'QSG_desc'=>array('LIKE',"%$search_string%"))
521 517
 					);
522
-			}else{
518
+			} else{
523 519
 				$query_params[0]=array(
524 520
 					'QST_display_text'=>array('LIKE',"%$search_string%")
525 521
 					);
@@ -575,7 +571,7 @@  discard block
 block discarded – undo
575 571
 		if ($count){
576 572
 			$where = isset( $query_params[0] ) ? array( $query_params[0] ) : array();
577 573
 			$results = $QST->count($where);
578
-		}else{
574
+		} else{
579 575
 			$results = $QST->get_all($query_params);
580 576
 		}
581 577
 		return $results;
Please login to merge, or discard this patch.
Spacing   +145 added lines, -145 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  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
 /**
@@ -58,12 +58,12 @@  discard block
 block discarded – undo
58 58
 
59 59
 
60 60
 
61
-	public function __construct( $routing = TRUE ) {
62
-		require_once( EE_MODELS . 'EEM_Question.model.php' );
63
-		require_once( EE_MODELS . 'EEM_Question_Group.model.php' );
64
-		$this->_question_model=  EEM_Question::instance();
65
-		$this->_question_group_model=EEM_Question_Group::instance();
66
-		parent::__construct( $routing );
61
+	public function __construct($routing = TRUE) {
62
+		require_once(EE_MODELS.'EEM_Question.model.php');
63
+		require_once(EE_MODELS.'EEM_Question_Group.model.php');
64
+		$this->_question_model = EEM_Question::instance();
65
+		$this->_question_group_model = EEM_Question_Group::instance();
66
+		parent::__construct($routing);
67 67
 	}
68 68
 
69 69
 
@@ -97,7 +97,7 @@  discard block
 block discarded – undo
97 97
 
98 98
 
99 99
 	protected function _set_page_routes() {
100
-		$qst_id = ! empty( $this->_req_data['QST_ID'] ) ? $this->_req_data['QST_ID'] : 0;
100
+		$qst_id = ! empty($this->_req_data['QST_ID']) ? $this->_req_data['QST_ID'] : 0;
101 101
 		$this->_page_routes = array(
102 102
 			'default' => array(
103 103
 				'func' => '_questions_overview_list_table',
@@ -118,7 +118,7 @@  discard block
 block discarded – undo
118 118
 
119 119
 			'update_question' => array(
120 120
 				'func' => '_insert_or_update_question',
121
-				'args' => array('new_question' => FALSE ),
121
+				'args' => array('new_question' => FALSE),
122 122
 				'capability' => 'ee_edit_question',
123 123
 				'obj_id' => $qst_id,
124 124
 				'noheader' => TRUE,
@@ -153,7 +153,7 @@  discard block
 block discarded – undo
153 153
 						'filename' => 'registration_form_questions_overview_views_bulk_actions_search'
154 154
 						)
155 155
 					),
156
-				'help_tour' => array( 'Registration_Form_Questions_Overview_Help_Tour'),
156
+				'help_tour' => array('Registration_Form_Questions_Overview_Help_Tour'),
157 157
 				'require_nonce' => FALSE,
158 158
 				'qtips' => array(
159 159
 					'EE_Registration_Form_Tips'
@@ -172,7 +172,7 @@  discard block
 block discarded – undo
172 172
 						'filename' => 'registration_form_question_groups'
173 173
 						),
174 174
 					),
175
-				'help_tour' => array( 'Registration_Form_Question_Groups_Help_Tour'),
175
+				'help_tour' => array('Registration_Form_Question_Groups_Help_Tour'),
176 176
 				'require_nonce' => FALSE
177 177
 				),
178 178
 
@@ -181,16 +181,16 @@  discard block
 block discarded – undo
181 181
 					'label' => __('Edit Question', 'event_espresso'),
182 182
 					'order' => 15,
183 183
 					'persistent' => FALSE,
184
-					'url' => isset($this->_req_data['question_id']) ? add_query_arg(array('question_id' => $this->_req_data['question_id'] ), $this->_current_page_view_url )  : $this->_admin_base_url
184
+					'url' => isset($this->_req_data['question_id']) ? add_query_arg(array('question_id' => $this->_req_data['question_id']), $this->_current_page_view_url) : $this->_admin_base_url
185 185
 					),
186
-				'metaboxes' => array_merge( $this->_default_espresso_metaboxes, array('_publish_post_box' ) ),
186
+				'metaboxes' => array_merge($this->_default_espresso_metaboxes, array('_publish_post_box')),
187 187
 				'help_tabs' => array(
188 188
 					'registration_form_edit_question_group_help_tab' => array(
189 189
 						'title' => __('Edit Question', 'event_espresso'),
190 190
 						'filename' => 'registration_form_edit_question'
191 191
 						),
192 192
 					),
193
-                'help_tour' => array( 'Registration_Form_Edit_Question_Help_Tour'),
193
+                'help_tour' => array('Registration_Form_Edit_Question_Help_Tour'),
194 194
 				'require_nonce' => FALSE
195 195
 				),
196 196
 			);
@@ -218,7 +218,7 @@  discard block
 block discarded – undo
218 218
 	//none of the below group are currently used for Event Categories
219 219
 	protected function _add_feature_pointers() {}
220 220
 	public function load_scripts_styles() {
221
-		wp_register_style( 'espresso_registration', REGISTRATION_FORM_ASSETS_URL . 'espresso_registration_form_admin.css', array(), EVENT_ESPRESSO_VERSION );
221
+		wp_register_style('espresso_registration', REGISTRATION_FORM_ASSETS_URL.'espresso_registration_form_admin.css', array(), EVENT_ESPRESSO_VERSION);
222 222
 		wp_enqueue_style('espresso_registration');
223 223
 	}
224 224
 	public function admin_init() {}
@@ -234,20 +234,20 @@  discard block
 block discarded – undo
234 234
 
235 235
 	public function load_scripts_styles_add_question() {
236 236
 		$this->load_scripts_styles_forms();
237
-		wp_register_script( 'espresso_registration_form_single', REGISTRATION_FORM_ASSETS_URL . 'espresso_registration_form_admin.js', array('jquery-ui-sortable'), EVENT_ESPRESSO_VERSION, TRUE );
238
-		wp_enqueue_script( 'espresso_registration_form_single' );
237
+		wp_register_script('espresso_registration_form_single', REGISTRATION_FORM_ASSETS_URL.'espresso_registration_form_admin.js', array('jquery-ui-sortable'), EVENT_ESPRESSO_VERSION, TRUE);
238
+		wp_enqueue_script('espresso_registration_form_single');
239 239
 	}
240 240
 	public function load_scripts_styles_edit_question() {
241 241
 		$this->load_scripts_styles_forms();
242
-		wp_register_script( 'espresso_registration_form_single', REGISTRATION_FORM_ASSETS_URL . 'espresso_registration_form_admin.js', array('jquery-ui-sortable'), EVENT_ESPRESSO_VERSION, TRUE );
243
-		wp_enqueue_script( 'espresso_registration_form_single' );
242
+		wp_register_script('espresso_registration_form_single', REGISTRATION_FORM_ASSETS_URL.'espresso_registration_form_admin.js', array('jquery-ui-sortable'), EVENT_ESPRESSO_VERSION, TRUE);
243
+		wp_enqueue_script('espresso_registration_form_single');
244 244
 	}
245 245
 
246 246
 
247 247
 
248 248
 
249 249
 	public function recaptcha_info_help_tab() {
250
-		$template = REGISTRATION_FORM_TEMPLATE_PATH . 'recaptcha_info_help_tab.template.php';
250
+		$template = REGISTRATION_FORM_TEMPLATE_PATH.'recaptcha_info_help_tab.template.php';
251 251
 		EEH_Template::display_template($template, array());
252 252
 	}
253 253
 
@@ -279,7 +279,7 @@  discard block
 block discarded – undo
279 279
 				)
280 280
 		);
281 281
 
282
-		if ( EE_Registry::instance()->CAP->current_user_can( 'ee_delete_questions', 'espresso_registration_form_trash_questions' ) ) {
282
+		if (EE_Registry::instance()->CAP->current_user_can('ee_delete_questions', 'espresso_registration_form_trash_questions')) {
283 283
 			$this->_views['trash'] = array(
284 284
 				'slug' => 'trash',
285 285
 				'label' => __('Trash', 'event_espresso'),
@@ -297,9 +297,9 @@  discard block
 block discarded – undo
297 297
 	 */
298 298
 	protected function _questions_groups_preview() {
299 299
 		$this->_admin_page_title = __('Question Groups (Preview)', 'event_espresso');
300
-		$this->_template_args['preview_img'] = '<img src="' . REGISTRATION_FORM_ASSETS_URL . 'caf_reg_form_preview.jpg" alt="' . esc_attr__( 'Preview Question Groups Overview List Table screenshot', 'event_espresso' ) . '" />';
301
-		$this->_template_args['preview_text'] = '<strong>'.__( 'Question Groups is a feature that is only available in the Caffeinated version of Event Espresso.  With the Question Groups feature you are able to: create new question groups, edit existing question groups, and also create and edit new questions and add them to question groups.', 'event_espresso' ).'</strong>';
302
-		$this->display_admin_caf_preview_page( 'question_groups_tab' );
300
+		$this->_template_args['preview_img'] = '<img src="'.REGISTRATION_FORM_ASSETS_URL.'caf_reg_form_preview.jpg" alt="'.esc_attr__('Preview Question Groups Overview List Table screenshot', 'event_espresso').'" />';
301
+		$this->_template_args['preview_text'] = '<strong>'.__('Question Groups is a feature that is only available in the Caffeinated version of Event Espresso.  With the Question Groups feature you are able to: create new question groups, edit existing question groups, and also create and edit new questions and add them to question groups.', 'event_espresso').'</strong>';
302
+		$this->display_admin_caf_preview_page('question_groups_tab');
303 303
 	}
304 304
 
305 305
 
@@ -310,58 +310,58 @@  discard block
 block discarded – undo
310 310
 	 * @param \EEM_Base $model
311 311
 	 * @return array where each key is the name of a model's field/db column, and each value is its value.
312 312
 	 */
313
-	protected function _set_column_values_for(EEM_Base $model){
314
-		do_action( 'AHEE_log', __FILE__, __FUNCTION__, '' );
315
-		$set_column_values=array();
313
+	protected function _set_column_values_for(EEM_Base $model) {
314
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
315
+		$set_column_values = array();
316 316
 
317 317
 		//some initial checks for proper values.
318 318
 		//if QST_admin_only, then no matter what QST_required is we disable.
319
-		if ( !empty( $this->_req_data['QST_admin_only'] ) ) {
319
+		if ( ! empty($this->_req_data['QST_admin_only'])) {
320 320
 			$this->_req_data['QST_required'] = 0;
321 321
 		}
322
-		foreach($model->field_settings() as $fieldName=>$settings){
322
+		foreach ($model->field_settings() as $fieldName=>$settings) {
323 323
 			// basically if QSG_identifier is empty or not set
324
-			if ( $fieldName == 'QSG_identifier' && ( isset( $this->_req_data['QSG_identifier'] ) && empty( $this->_req_data['QSG_identifier'] ) )) {
325
-				$QSG_name = isset( $this->_req_data['QSG_name'] ) ? $this->_req_data['QSG_name'] : '' ;
326
-				$set_column_values[$fieldName] = sanitize_title($QSG_name ) . '-' . uniqid();
324
+			if ($fieldName == 'QSG_identifier' && (isset($this->_req_data['QSG_identifier']) && empty($this->_req_data['QSG_identifier']))) {
325
+				$QSG_name = isset($this->_req_data['QSG_name']) ? $this->_req_data['QSG_name'] : '';
326
+				$set_column_values[$fieldName] = sanitize_title($QSG_name).'-'.uniqid();
327 327
 //				dd($set_column_values);
328 328
 			}
329 329
 			//if the admin label is blank, use a slug version of the question text
330
-			else if ( $fieldName == 'QST_admin_label' && ( isset( $this->_req_data['QST_admin_label'] ) && empty( $this->_req_data['QST_admin_label'] )  )) {
331
-				$QST_text = isset( $this->_req_data['QST_display_text'] ) ? $this->_req_data['QST_display_text'] : '' ;
332
-				$set_column_values[$fieldName] = sanitize_title(wp_trim_words($QST_text,10));
330
+			else if ($fieldName == 'QST_admin_label' && (isset($this->_req_data['QST_admin_label']) && empty($this->_req_data['QST_admin_label']))) {
331
+				$QST_text = isset($this->_req_data['QST_display_text']) ? $this->_req_data['QST_display_text'] : '';
332
+				$set_column_values[$fieldName] = sanitize_title(wp_trim_words($QST_text, 10));
333 333
 			}
334 334
 
335 335
 
336
-			else if ( $fieldName == 'QST_admin_only' && ( !isset( $this->_req_data['QST_admin_only'] ) ) ) {
336
+			else if ($fieldName == 'QST_admin_only' && ( ! isset($this->_req_data['QST_admin_only']))) {
337 337
 				$set_column_values[$fieldName] = 0;
338 338
 			}
339 339
 
340
-			else if ( $fieldName == 'QST_max' ) {
340
+			else if ($fieldName == 'QST_max') {
341 341
 				$qst_system = EEM_Question::instance()->get_var(
342 342
 					array(
343 343
 						array(
344
-							'QST_ID' => isset( $this->_req_data[ 'QST_ID' ] ) ? $this->_req_data[ 'QST_ID' ] : 0
344
+							'QST_ID' => isset($this->_req_data['QST_ID']) ? $this->_req_data['QST_ID'] : 0
345 345
 						)
346 346
 					),
347 347
 					'QST_system' );
348
-				$max_max = EEM_Question::instance()->absolute_max_for_system_question( $qst_system );
349
-				if( empty( $this->_req_data[ 'QST_max' ] ) ||
350
-					 $this->_req_data[ 'QST_max' ] > $max_max ) {
351
-					$set_column_values[ $fieldName ] = $max_max;
348
+				$max_max = EEM_Question::instance()->absolute_max_for_system_question($qst_system);
349
+				if (empty($this->_req_data['QST_max']) ||
350
+					 $this->_req_data['QST_max'] > $max_max) {
351
+					$set_column_values[$fieldName] = $max_max;
352 352
 				}
353 353
 			}
354 354
 
355 355
 
356 356
 			//only add a property to the array if it's not null (otherwise the model should just use the default value)
357
-			if(
358
-				! isset( $set_column_values[ $fieldName ] ) &&
359
-				isset($this->_req_data[$fieldName] ) ){
360
-				$set_column_values[$fieldName]=$this->_req_data[$fieldName];
357
+			if (
358
+				! isset($set_column_values[$fieldName]) &&
359
+				isset($this->_req_data[$fieldName]) ) {
360
+				$set_column_values[$fieldName] = $this->_req_data[$fieldName];
361 361
 			}
362 362
 
363 363
 		}
364
-		return $set_column_values;//validation fo this data to be performed by the model before insertion.
364
+		return $set_column_values; //validation fo this data to be performed by the model before insertion.
365 365
 	}
366 366
 
367 367
 
@@ -379,30 +379,30 @@  discard block
 block discarded – undo
379 379
 	/**
380 380
 	 * @param string $action
381 381
 	 */
382
-	protected function _edit_question( $action= 'add' ) {
383
-		do_action( 'AHEE_log', __FILE__, __FUNCTION__, '' );
384
-		$ID=isset( $this->_req_data['QST_ID'] ) && ! empty( $this->_req_data['QST_ID'] ) ? absint( $this->_req_data['QST_ID'] ) : FALSE;
382
+	protected function _edit_question($action = 'add') {
383
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
384
+		$ID = isset($this->_req_data['QST_ID']) && ! empty($this->_req_data['QST_ID']) ? absint($this->_req_data['QST_ID']) : FALSE;
385 385
 
386
-		$this->_admin_page_title = ucwords( str_replace( '_', ' ', $this->_req_action ));
386
+		$this->_admin_page_title = ucwords(str_replace('_', ' ', $this->_req_action));
387 387
 		// add PRC_ID to title if editing
388
-		$this->_admin_page_title = $ID ? $this->_admin_page_title . ' # ' . $ID : $this->_admin_page_title;
389
-		if($ID){
390
-			$question=$this->_question_model->get_one_by_ID($ID);
391
-			$additional_hidden_fields=array('QST_ID'=>array('type'=>'hidden','value'=>$ID));
388
+		$this->_admin_page_title = $ID ? $this->_admin_page_title.' # '.$ID : $this->_admin_page_title;
389
+		if ($ID) {
390
+			$question = $this->_question_model->get_one_by_ID($ID);
391
+			$additional_hidden_fields = array('QST_ID'=>array('type'=>'hidden', 'value'=>$ID));
392 392
 			$this->_set_add_edit_form_tags('update_question', $additional_hidden_fields);
393
-		}else{
394
-			$question= EE_Question::new_instance();
393
+		} else {
394
+			$question = EE_Question::new_instance();
395 395
 			$question->set_order_to_latest();
396 396
 			$this->_set_add_edit_form_tags('insert_question');
397 397
 		}
398
-		$question_types = $question->has_answers() ?  $this->_question_model->question_types_in_same_category( $question->type() ) : $this->_question_model->allowed_question_types();
399
-		$this->_template_args['QST_ID']=$ID;
400
-		$this->_template_args['question']=$question;
401
-		$this->_template_args['question_types']= $question_types;
402
-		$this->_template_args['max_max'] = EEM_Question::instance()->absolute_max_for_system_question( $question->system_ID() );
398
+		$question_types = $question->has_answers() ? $this->_question_model->question_types_in_same_category($question->type()) : $this->_question_model->allowed_question_types();
399
+		$this->_template_args['QST_ID'] = $ID;
400
+		$this->_template_args['question'] = $question;
401
+		$this->_template_args['question_types'] = $question_types;
402
+		$this->_template_args['max_max'] = EEM_Question::instance()->absolute_max_for_system_question($question->system_ID());
403 403
 
404
-		$this->_set_publish_post_box_vars( 'id', $ID );
405
-		$this->_template_args['admin_page_content'] = EEH_Template::display_template( REGISTRATION_FORM_TEMPLATE_PATH . 'questions_main_meta_box.template.php', $this->_template_args, TRUE );
404
+		$this->_set_publish_post_box_vars('id', $ID);
405
+		$this->_template_args['admin_page_content'] = EEH_Template::display_template(REGISTRATION_FORM_TEMPLATE_PATH.'questions_main_meta_box.template.php', $this->_template_args, TRUE);
406 406
 
407 407
 		// the details template wrapper
408 408
 		$this->display_admin_page_with_sidebar();
@@ -414,58 +414,58 @@  discard block
 block discarded – undo
414 414
 	 * @param bool|true $new_question
415 415
 	 * @throws \EE_Error
416 416
 	 */
417
-	protected function _insert_or_update_question( $new_question = TRUE) {
418
-		do_action( 'AHEE_log', __FILE__, __FUNCTION__, '' );
419
-		$set_column_values=$this->_set_column_values_for($this->_question_model);
420
-		if($new_question){
421
-			$ID=$this->_question_model->insert($set_column_values);
417
+	protected function _insert_or_update_question($new_question = TRUE) {
418
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
419
+		$set_column_values = $this->_set_column_values_for($this->_question_model);
420
+		if ($new_question) {
421
+			$ID = $this->_question_model->insert($set_column_values);
422 422
 			$success = $ID ? true : false;
423 423
 			$action_desc = 'added';
424
-		}else{
425
-			$ID=absint($this->_req_data['QST_ID']);
426
-			$pk=$this->_question_model->primary_key_name();
427
-			$wheres=array($pk=>$ID);
424
+		} else {
425
+			$ID = absint($this->_req_data['QST_ID']);
426
+			$pk = $this->_question_model->primary_key_name();
427
+			$wheres = array($pk=>$ID);
428 428
 			unset($set_column_values[$pk]);
429
-			$success= $this->_question_model->update($set_column_values,array($wheres));
430
-			$action_desc='updated';
429
+			$success = $this->_question_model->update($set_column_values, array($wheres));
430
+			$action_desc = 'updated';
431 431
 		}
432 432
 
433
-		if ($ID){
433
+		if ($ID) {
434 434
 			//save the related options
435 435
 			//trash removed options, save old ones
436 436
 			//get list of all options
437 437
 			/** @type EE_Question $question */
438
-			$question=$this->_question_model->get_one_by_ID($ID);
439
-			$options=$question->options();
440
-			if(! empty($options)){
441
-				foreach($options as $option_ID=>$option){
442
-					$option_req_index=$this->_get_option_req_data_index($option_ID);
443
-					if($option_req_index!==FALSE){
438
+			$question = $this->_question_model->get_one_by_ID($ID);
439
+			$options = $question->options();
440
+			if ( ! empty($options)) {
441
+				foreach ($options as $option_ID=>$option) {
442
+					$option_req_index = $this->_get_option_req_data_index($option_ID);
443
+					if ($option_req_index !== FALSE) {
444 444
 						$option->save($this->_req_data['question_options'][$option_req_index]);
445
-					}else{
445
+					} else {
446 446
 						//not found, remove it
447 447
 						$option->delete();
448 448
 					}
449 449
 				}
450 450
 			}
451 451
 			//save new related options
452
-			foreach($this->_req_data['question_options'] as $index=>$option_req_data){
453
-				if( empty($option_req_data['QSO_ID'] ) && (  ( isset( $option_req_data['QSO_value'] ) && $option_req_data['QSO_value'] !== '' ) || ! empty( $option_req_data['QSO_desc'] ) ) ) {//no ID! save it!
454
-					if( ! isset( $option_req_data['QSO_value'] ) || $option_req_data['QSO_value'] === ''  ){
455
-						$option_req_data['QSO_value']=$option_req_data['QSO_desc'];
452
+			foreach ($this->_req_data['question_options'] as $index=>$option_req_data) {
453
+				if (empty($option_req_data['QSO_ID']) && ((isset($option_req_data['QSO_value']) && $option_req_data['QSO_value'] !== '') || ! empty($option_req_data['QSO_desc']))) {//no ID! save it!
454
+					if ( ! isset($option_req_data['QSO_value']) || $option_req_data['QSO_value'] === '') {
455
+						$option_req_data['QSO_value'] = $option_req_data['QSO_desc'];
456 456
 					}
457
-					$new_option=EE_Question_Option::new_instance( array( 'QSO_value' => $option_req_data['QSO_value'], 'QSO_desc' => $option_req_data['QSO_desc'], 'QSO_order' => $option_req_data['QSO_order'], 'QST_ID' => $question->ID()));
457
+					$new_option = EE_Question_Option::new_instance(array('QSO_value' => $option_req_data['QSO_value'], 'QSO_desc' => $option_req_data['QSO_desc'], 'QSO_order' => $option_req_data['QSO_order'], 'QST_ID' => $question->ID()));
458 458
 					$new_option->save();
459 459
 				}
460 460
 			}
461 461
 		}
462
-		$query_args = array( 'action' => 'edit_question', 'QST_ID' => $ID );
463
-		if ( $success !== FALSE ) {
464
-			$msg = $new_question ? sprintf( __('The %s has been created', 'event_espresso'), $this->_question_model->item_name() ) : sprintf( __('The %s has been updated', 'event_espresso' ), $this->_question_model->item_name() );
465
-			EE_Error::add_success( $msg );
462
+		$query_args = array('action' => 'edit_question', 'QST_ID' => $ID);
463
+		if ($success !== FALSE) {
464
+			$msg = $new_question ? sprintf(__('The %s has been created', 'event_espresso'), $this->_question_model->item_name()) : sprintf(__('The %s has been updated', 'event_espresso'), $this->_question_model->item_name());
465
+			EE_Error::add_success($msg);
466 466
 		}
467 467
 
468
-		$this->_redirect_after_action( FALSE, '', $action_desc, $query_args, TRUE);
468
+		$this->_redirect_after_action(FALSE, '', $action_desc, $query_args, TRUE);
469 469
 	}
470 470
 
471 471
 
@@ -478,10 +478,10 @@  discard block
 block discarded – undo
478 478
 	 * @param int $ID of the question option to find
479 479
 	 * @return int index in question_options array if successful, FALSE if unsuccessful
480 480
 	 */
481
-	protected function _get_option_req_data_index($ID){
482
-		$req_data_for_question_options=$this->_req_data['question_options'];
483
-		foreach($req_data_for_question_options as $num=>$option_data){
484
-			if(array_key_exists('QSO_ID',$option_data) && intval($option_data['QSO_ID'])==$ID){
481
+	protected function _get_option_req_data_index($ID) {
482
+		$req_data_for_question_options = $this->_req_data['question_options'];
483
+		foreach ($req_data_for_question_options as $num=>$option_data) {
484
+			if (array_key_exists('QSO_ID', $option_data) && intval($option_data['QSO_ID']) == $ID) {
485 485
 				return $num;
486 486
 			}
487 487
 		}
@@ -503,25 +503,25 @@  discard block
 block discarded – undo
503 503
 	 * @param int      $current_page
504 504
 	 * @return array lik EEM_Base::get_all's $query_params parameter
505 505
 	 */
506
-	protected function get_query_params($model, $per_page=10,$current_page=10){
506
+	protected function get_query_params($model, $per_page = 10, $current_page = 10) {
507 507
 		$query_params = array();
508
-		$offset=($current_page-1)*$per_page;
509
-		$query_params['limit']=array($offset,$per_page);
510
-		$order = ( isset( $this->_req_data['order'] ) && ! empty( $this->_req_data['order'] )) ? $this->_req_data['order'] : 'ASC';
508
+		$offset = ($current_page - 1) * $per_page;
509
+		$query_params['limit'] = array($offset, $per_page);
510
+		$order = (isset($this->_req_data['order']) && ! empty($this->_req_data['order'])) ? $this->_req_data['order'] : 'ASC';
511 511
 		$orderby_field = $model instanceof EEM_Question ? 'QST_ID' : 'QSG_order';
512 512
 		$field_to_order_by = empty($this->_req_data['orderby']) ? $orderby_field : $this->_req_data['orderby'];
513
-		$query_params['order_by']=array( $field_to_order_by => $order );
514
-		$search_string = array_key_exists('s',$this->_req_data) ? $this->_req_data['s'] : null;
515
-		if(! empty($search_string)){
516
-			if($model instanceof EEM_Question_Group){
517
-				$query_params[0]=array(
513
+		$query_params['order_by'] = array($field_to_order_by => $order);
514
+		$search_string = array_key_exists('s', $this->_req_data) ? $this->_req_data['s'] : null;
515
+		if ( ! empty($search_string)) {
516
+			if ($model instanceof EEM_Question_Group) {
517
+				$query_params[0] = array(
518 518
 					'OR'=>array(
519
-						'QSG_name'=>array('LIKE',"%$search_string%"),
520
-						'QSG_desc'=>array('LIKE',"%$search_string%"))
519
+						'QSG_name'=>array('LIKE', "%$search_string%"),
520
+						'QSG_desc'=>array('LIKE', "%$search_string%"))
521 521
 					);
522
-			}else{
523
-				$query_params[0]=array(
524
-					'QST_display_text'=>array('LIKE',"%$search_string%")
522
+			} else {
523
+				$query_params[0] = array(
524
+					'QST_display_text'=>array('LIKE', "%$search_string%")
525 525
 					);
526 526
 			}
527 527
 		}
@@ -569,13 +569,13 @@  discard block
 block discarded – undo
569 569
 	 * @param bool|false $count
570 570
 	 * @return \EE_Soft_Delete_Base_Class[]|int
571 571
 	 */
572
-	public function get_questions( $per_page=10, $current_page = 1, $count = FALSE ) {
572
+	public function get_questions($per_page = 10, $current_page = 1, $count = FALSE) {
573 573
 		$QST = EEM_Question::instance();
574 574
 		$query_params = $this->get_query_params($QST, $per_page, $current_page);
575
-		if ($count){
576
-			$where = isset( $query_params[0] ) ? array( $query_params[0] ) : array();
575
+		if ($count) {
576
+			$where = isset($query_params[0]) ? array($query_params[0]) : array();
577 577
 			$results = $QST->count($where);
578
-		}else{
578
+		} else {
579 579
 			$results = $QST->get_all($query_params);
580 580
 		}
581 581
 		return $results;
@@ -590,10 +590,10 @@  discard block
 block discarded – undo
590 590
 	 * @param bool|false $count
591 591
 	 * @return \EE_Soft_Delete_Base_Class[]|int
592 592
 	 */
593
-	public function get_trashed_questions( $per_page, $current_page = 1, $count = FALSE ) {
594
-		$query_params =$this->get_query_params( EEM_Question::instance(), $per_page, $current_page);
595
-		$where        = isset( $query_params[0] ) ? array($query_params[0]) : array();
596
-		$questions    =$count ? EEM_Question::instance()->count_deleted($where) : EEM_Question::instance()->get_all_deleted($query_params);
593
+	public function get_trashed_questions($per_page, $current_page = 1, $count = FALSE) {
594
+		$query_params = $this->get_query_params(EEM_Question::instance(), $per_page, $current_page);
595
+		$where        = isset($query_params[0]) ? array($query_params[0]) : array();
596
+		$questions    = $count ? EEM_Question::instance()->count_deleted($where) : EEM_Question::instance()->get_all_deleted($query_params);
597 597
 		return $questions;
598 598
 	}
599 599
 
@@ -605,11 +605,11 @@  discard block
 block discarded – undo
605 605
 	 * @param bool|false $count
606 606
 	 * @return \EE_Soft_Delete_Base_Class[]
607 607
 	 */
608
-	public function get_question_groups( $per_page, $current_page = 1, $count = FALSE ) {
608
+	public function get_question_groups($per_page, $current_page = 1, $count = FALSE) {
609 609
 		/** @type EEM_Question_Group $questionGroupModel */
610
-		$questionGroupModel=EEM_Question_Group::instance();
611
-		$query_params=$this->get_query_params( $questionGroupModel, $per_page, $current_page );
612
-		$questionGroups=$questionGroupModel->get_all($query_params);//note: this a subclass of EEM_Soft_Delete_Base, so this is actually only getting non-trashed items
610
+		$questionGroupModel = EEM_Question_Group::instance();
611
+		$query_params = $this->get_query_params($questionGroupModel, $per_page, $current_page);
612
+		$questionGroups = $questionGroupModel->get_all($query_params); //note: this a subclass of EEM_Soft_Delete_Base, so this is actually only getting non-trashed items
613 613
 		return $questionGroups;
614 614
 	}
615 615
 
@@ -626,36 +626,36 @@  discard block
 block discarded – undo
626 626
 
627 627
 		$this->_template_args['values'] = $this->_yes_no_values;
628 628
 
629
-		$this->_template_args['use_captcha'] = isset( EE_Registry::instance()->CFG->registration->use_captcha ) ? EE_Registry::instance()->CFG->registration->use_captcha : FALSE;
630
-		$this->_template_args['show_captcha_settings'] = $this->_template_args['use_captcha'] ? 'style="display:table-row;"': '';
629
+		$this->_template_args['use_captcha'] = isset(EE_Registry::instance()->CFG->registration->use_captcha) ? EE_Registry::instance()->CFG->registration->use_captcha : FALSE;
630
+		$this->_template_args['show_captcha_settings'] = $this->_template_args['use_captcha'] ? 'style="display:table-row;"' : '';
631 631
 
632
-		$this->_template_args['recaptcha_publickey'] = isset( EE_Registry::instance()->CFG->registration->recaptcha_publickey ) ? stripslashes( EE_Registry::instance()->CFG->registration->recaptcha_publickey ) : '';
633
-		$this->_template_args['recaptcha_privatekey'] = isset( EE_Registry::instance()->CFG->registration->recaptcha_privatekey ) ? stripslashes( EE_Registry::instance()->CFG->registration->recaptcha_privatekey ) : '';
634
-		$this->_template_args['recaptcha_width'] = isset( EE_Registry::instance()->CFG->registration->recaptcha_width ) ? absint( EE_Registry::instance()->CFG->registration->recaptcha_width ) : 500;
632
+		$this->_template_args['recaptcha_publickey'] = isset(EE_Registry::instance()->CFG->registration->recaptcha_publickey) ? stripslashes(EE_Registry::instance()->CFG->registration->recaptcha_publickey) : '';
633
+		$this->_template_args['recaptcha_privatekey'] = isset(EE_Registry::instance()->CFG->registration->recaptcha_privatekey) ? stripslashes(EE_Registry::instance()->CFG->registration->recaptcha_privatekey) : '';
634
+		$this->_template_args['recaptcha_width'] = isset(EE_Registry::instance()->CFG->registration->recaptcha_width) ? absint(EE_Registry::instance()->CFG->registration->recaptcha_width) : 500;
635 635
 
636 636
 		$this->_template_args['recaptcha_theme_options'] = array(
637
-				array('id'  => 'red','text'=> __('Red', 'event_espresso')),
638
-				array('id'  => 'white','text'=> __('White', 'event_espresso')),
639
-				array('id'  => 'blackglass','text'=> __('Blackglass', 'event_espresso')),
640
-				array('id'  => 'clean','text'=> __('Clean', 'event_espresso'))
637
+				array('id'  => 'red', 'text'=> __('Red', 'event_espresso')),
638
+				array('id'  => 'white', 'text'=> __('White', 'event_espresso')),
639
+				array('id'  => 'blackglass', 'text'=> __('Blackglass', 'event_espresso')),
640
+				array('id'  => 'clean', 'text'=> __('Clean', 'event_espresso'))
641 641
 			);
642
-		$this->_template_args['recaptcha_theme'] = isset( EE_Registry::instance()->CFG->registration->recaptcha_theme ) ? EE_Registry::instance()->CFG->registration->get_pretty( 'recaptcha_theme' ) : 'clean';
642
+		$this->_template_args['recaptcha_theme'] = isset(EE_Registry::instance()->CFG->registration->recaptcha_theme) ? EE_Registry::instance()->CFG->registration->get_pretty('recaptcha_theme') : 'clean';
643 643
 
644 644
 		$this->_template_args['recaptcha_language_options'] = array(
645
-				array('id'  => 'en','text'=> __('English', 'event_espresso')),
646
-				array('id'  => 'es','text'=> __('Spanish', 'event_espresso')),
647
-				array('id'  => 'nl','text'=> __('Dutch', 'event_espresso')),
648
-				array('id'  => 'fr','text'=> __('French', 'event_espresso')),
649
-				array('id'  => 'de','text'=> __('German', 'event_espresso')),
650
-				array('id'  => 'pt','text'=> __('Portuguese', 'event_espresso')),
651
-				array('id'  => 'ru','text'=> __('Russian', 'event_espresso')),
652
-				array('id'  => 'tr','text'=> __('Turkish', 'event_espresso'))
645
+				array('id'  => 'en', 'text'=> __('English', 'event_espresso')),
646
+				array('id'  => 'es', 'text'=> __('Spanish', 'event_espresso')),
647
+				array('id'  => 'nl', 'text'=> __('Dutch', 'event_espresso')),
648
+				array('id'  => 'fr', 'text'=> __('French', 'event_espresso')),
649
+				array('id'  => 'de', 'text'=> __('German', 'event_espresso')),
650
+				array('id'  => 'pt', 'text'=> __('Portuguese', 'event_espresso')),
651
+				array('id'  => 'ru', 'text'=> __('Russian', 'event_espresso')),
652
+				array('id'  => 'tr', 'text'=> __('Turkish', 'event_espresso'))
653 653
 			);
654
-		$this->_template_args['recaptcha_language'] = isset( EE_Registry::instance()->CFG->registration->recaptcha_language ) ? EE_Registry::instance()->CFG->registration->recaptcha_language : 'en';
654
+		$this->_template_args['recaptcha_language'] = isset(EE_Registry::instance()->CFG->registration->recaptcha_language) ? EE_Registry::instance()->CFG->registration->recaptcha_language : 'en';
655 655
 
656
-		$this->_set_add_edit_form_tags( 'update_reg_form_settings' );
657
-		$this->_set_publish_post_box_vars( NULL, FALSE, FALSE, NULL, FALSE );
658
-		$this->_template_args['admin_page_content'] = EEH_Template::display_template( REGISTRATION_FORM_TEMPLATE_PATH . 'reg_form_settings.template.php', $this->_template_args, TRUE );
656
+		$this->_set_add_edit_form_tags('update_reg_form_settings');
657
+		$this->_set_publish_post_box_vars(NULL, FALSE, FALSE, NULL, FALSE);
658
+		$this->_template_args['admin_page_content'] = EEH_Template::display_template(REGISTRATION_FORM_TEMPLATE_PATH.'reg_form_settings.template.php', $this->_template_args, TRUE);
659 659
 		$this->display_admin_page_with_sidebar();
660 660
 	}
661 661
 
Please login to merge, or discard this patch.