Completed
Branch BUG-7537 (42ca46)
by
unknown
1233:48 queued 1213:30
created
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/helpers/EEH_File.helper.php 1 patch
Spacing   +179 added lines, -179 removed lines patch added patch discarded remove patch
@@ -12,8 +12,8 @@  discard block
 block discarded – undo
12 12
  * @ version		 	4.0
13 13
  *
14 14
  */
15
-require_once( EE_HELPERS . 'EEH_Base.helper.php' );
16
-require_once( EE_INTERFACES . 'EEI_Interfaces.php' );
15
+require_once(EE_HELPERS.'EEH_Base.helper.php');
16
+require_once(EE_INTERFACES.'EEI_Interfaces.php');
17 17
 /**
18 18
  *
19 19
  * Class EEH_File
@@ -42,30 +42,30 @@  discard block
 block discarded – undo
42 42
 	 * @throws EE_Error
43 43
 	 * @return WP_Filesystem_Base
44 44
 	 */
45
-	private static function _get_wp_filesystem( $filepath = null) {
46
-		if( apply_filters( 
45
+	private static function _get_wp_filesystem($filepath = null) {
46
+		if (apply_filters( 
47 47
 				'FHEE__EEH_File___get_wp_filesystem__allow_using_filesystem_direct', 
48
-				$filepath && EEH_File::is_in_uploads_folder( $filepath ), 
49
-				$filepath ) ) {
50
-			if( ! EEH_File::$_wp_filesystem_direct instanceof WP_Filesystem_Direct ) {
51
-				require_once(ABSPATH . 'wp-admin/includes/class-wp-filesystem-base.php');
48
+				$filepath && EEH_File::is_in_uploads_folder($filepath), 
49
+				$filepath )) {
50
+			if ( ! EEH_File::$_wp_filesystem_direct instanceof WP_Filesystem_Direct) {
51
+				require_once(ABSPATH.'wp-admin/includes/class-wp-filesystem-base.php');
52 52
 				$method = 'direct';
53
-				$wp_filesystem_direct_file = apply_filters( 'filesystem_method_file', ABSPATH . 'wp-admin/includes/class-wp-filesystem-' . $method . '.php', $method );
53
+				$wp_filesystem_direct_file = apply_filters('filesystem_method_file', ABSPATH.'wp-admin/includes/class-wp-filesystem-'.$method.'.php', $method);
54 54
 				//check constants defined, just like in wp-admin/includes/file.php's WP_Filesystem()
55
-				if ( ! defined('FS_CHMOD_DIR') ) {
56
-					define('FS_CHMOD_DIR', ( fileperms( ABSPATH ) & 0777 | 0755 ) );
55
+				if ( ! defined('FS_CHMOD_DIR')) {
56
+					define('FS_CHMOD_DIR', (fileperms(ABSPATH) & 0777 | 0755));
57 57
 				}
58
-				if ( ! defined('FS_CHMOD_FILE') ) {
59
-					define('FS_CHMOD_FILE', ( fileperms( ABSPATH . 'index.php' ) & 0777 | 0644 ) );
58
+				if ( ! defined('FS_CHMOD_FILE')) {
59
+					define('FS_CHMOD_FILE', (fileperms(ABSPATH.'index.php') & 0777 | 0644));
60 60
 				}
61
-				require_once( $wp_filesystem_direct_file );
62
-				EEH_File::$_wp_filesystem_direct = new WP_Filesystem_Direct( array() );
61
+				require_once($wp_filesystem_direct_file);
62
+				EEH_File::$_wp_filesystem_direct = new WP_Filesystem_Direct(array());
63 63
 			}
64 64
 			return EEH_File::$_wp_filesystem_direct;
65 65
 		}
66 66
 		global $wp_filesystem;
67 67
 		// no filesystem setup ???
68
-		if ( ! $wp_filesystem instanceof WP_Filesystem_Base ) {
68
+		if ( ! $wp_filesystem instanceof WP_Filesystem_Base) {
69 69
 			// if some eager beaver's just trying to get in there too early...
70 70
 			// let them do it, because we are one of those eager beavers! :P
71 71
 			/**
@@ -78,34 +78,34 @@  discard block
 block discarded – undo
78 78
 			 * and there may be troubles if the WP files are owned by a different user
79 79
 			 * than the server user. But both of these issues should exist in 4.4 and earlier too
80 80
 			 */
81
-			if ( FALSE && ! did_action( 'wp_loaded' )) {
81
+			if (FALSE && ! did_action('wp_loaded')) {
82 82
 				$msg = __('An attempt to access and/or write to a file on the server could not be completed due to a lack of sufficient credentials.', 'event_espresso');
83
-				if ( WP_DEBUG ) {
84
-					$msg .= '<br />' .  __('The WP Filesystem can not be accessed until after the "wp_loaded" hook has run, so it\'s best not to attempt access until the "admin_init" hookpoint.', 'event_espresso');
83
+				if (WP_DEBUG) {
84
+					$msg .= '<br />'.__('The WP Filesystem can not be accessed until after the "wp_loaded" hook has run, so it\'s best not to attempt access until the "admin_init" hookpoint.', 'event_espresso');
85 85
 				}
86
-				throw new EE_Error( $msg );
86
+				throw new EE_Error($msg);
87 87
 			} else {
88 88
 				// should be loaded if we are past the wp_loaded hook...
89
-				if ( ! function_exists( 'WP_Filesystem' )) {
90
-					require_once( ABSPATH . 'wp-admin/includes/file.php' );
91
-					require_once( ABSPATH . 'wp-admin/includes/template.php' );
89
+				if ( ! function_exists('WP_Filesystem')) {
90
+					require_once(ABSPATH.'wp-admin/includes/file.php');
91
+					require_once(ABSPATH.'wp-admin/includes/template.php');
92 92
 				}
93 93
 				// turn on output buffering so that we can capture the credentials form
94 94
 				ob_start();
95
-				$credentials = request_filesystem_credentials( '' );
95
+				$credentials = request_filesystem_credentials('');
96 96
 				// store credentials form for the time being
97 97
 				EEH_File::$_credentials_form = ob_get_clean();
98 98
 				// basically check for direct or previously configured access
99
-				if ( ! WP_Filesystem( $credentials ) ) {
99
+				if ( ! WP_Filesystem($credentials)) {
100 100
 					// if credentials do NOT exist
101
-					if ( $credentials === FALSE ) {
102
-						add_action( 'admin_notices', array( 'EEH_File', 'display_request_filesystem_credentials_form' ), 999 );
103
-						throw new EE_Error( __('An attempt to access and/or write to a file on the server could not be completed due to a lack of sufficient credentials.', 'event_espresso'));
104
-					} elseif( is_wp_error( $wp_filesystem->errors ) && $wp_filesystem->errors->get_error_code() ) {
105
-						add_action( 'admin_notices', array( 'EEH_File', 'display_request_filesystem_credentials_form' ), 999 );
101
+					if ($credentials === FALSE) {
102
+						add_action('admin_notices', array('EEH_File', 'display_request_filesystem_credentials_form'), 999);
103
+						throw new EE_Error(__('An attempt to access and/or write to a file on the server could not be completed due to a lack of sufficient credentials.', 'event_espresso'));
104
+					} elseif (is_wp_error($wp_filesystem->errors) && $wp_filesystem->errors->get_error_code()) {
105
+						add_action('admin_notices', array('EEH_File', 'display_request_filesystem_credentials_form'), 999);
106 106
 						throw new EE_Error(
107 107
 								sprintf(
108
-										__( 'WP Filesystem Error: $1%s', 'event_espresso' ),
108
+										__('WP Filesystem Error: $1%s', 'event_espresso'),
109 109
 										$wp_filesystem->errors->get_error_message() ) );
110 110
 					}
111 111
 				}
@@ -118,8 +118,8 @@  discard block
 block discarded – undo
118 118
 	 * display_request_filesystem_credentials_form
119 119
 	 */
120 120
 	public static function display_request_filesystem_credentials_form() {
121
-		if ( ! empty( EEH_File::$_credentials_form )) {
122
-			echo '<div class="updated espresso-notices-attention"><p>' . EEH_File::$_credentials_form . '</p></div>';
121
+		if ( ! empty(EEH_File::$_credentials_form)) {
122
+			echo '<div class="updated espresso-notices-attention"><p>'.EEH_File::$_credentials_form.'</p></div>';
123 123
 		}
124 124
 	}
125 125
 
@@ -137,29 +137,29 @@  discard block
 block discarded – undo
137 137
 	 * @throws EE_Error
138 138
 	 * @return bool
139 139
 	 */
140
-	public static function verify_filepath_and_permissions( $full_file_path = '', $file_name = '', $file_ext = '', $type_of_file = '' ) {
140
+	public static function verify_filepath_and_permissions($full_file_path = '', $file_name = '', $file_ext = '', $type_of_file = '') {
141 141
 		// load WP_Filesystem and set file permissions
142
-		$wp_filesystem = EEH_File::_get_wp_filesystem( $full_file_path );
143
-		$full_file_path = EEH_File::standardise_directory_separators( $full_file_path );
144
-		if ( ! $wp_filesystem->is_readable( EEH_File::convert_local_filepath_to_remote_filepath( $full_file_path ) )) {
145
-			$file_name = ! empty( $type_of_file ) ? $file_name . ' ' . $type_of_file : $file_name;
146
-			$file_name .= ! empty( $file_ext ) ? ' file' : ' folder';
142
+		$wp_filesystem = EEH_File::_get_wp_filesystem($full_file_path);
143
+		$full_file_path = EEH_File::standardise_directory_separators($full_file_path);
144
+		if ( ! $wp_filesystem->is_readable(EEH_File::convert_local_filepath_to_remote_filepath($full_file_path))) {
145
+			$file_name = ! empty($type_of_file) ? $file_name.' '.$type_of_file : $file_name;
146
+			$file_name .= ! empty($file_ext) ? ' file' : ' folder';
147 147
 			$msg = sprintf(
148
-				__( 'The requested %1$s could not be found or is not readable, possibly due to an incorrect filepath, or incorrect file permissions.%2$s', 'event_espresso' ),
148
+				__('The requested %1$s could not be found or is not readable, possibly due to an incorrect filepath, or incorrect file permissions.%2$s', 'event_espresso'),
149 149
 				$file_name,
150 150
 				'<br />'
151 151
 			);
152
-			if ( EEH_File::exists( $full_file_path )) {
153
-				$msg .= EEH_File::_permissions_error_for_unreadable_filepath( $full_file_path, $type_of_file );
152
+			if (EEH_File::exists($full_file_path)) {
153
+				$msg .= EEH_File::_permissions_error_for_unreadable_filepath($full_file_path, $type_of_file);
154 154
 			} else {
155 155
 				// no file permissions means the file was not found
156 156
 				$msg .= sprintf(
157
-					__( 'Please ensure the following path is correct: "%s".', 'event_espresso' ),
157
+					__('Please ensure the following path is correct: "%s".', 'event_espresso'),
158 158
 					$full_file_path
159 159
 				);
160 160
 			}
161
-			if ( defined( 'WP_DEBUG' ) && WP_DEBUG ) {
162
-				throw new EE_Error( $msg . '||' . $msg );
161
+			if (defined('WP_DEBUG') && WP_DEBUG) {
162
+				throw new EE_Error($msg.'||'.$msg);
163 163
 			}
164 164
 			return FALSE;
165 165
 		}
@@ -176,24 +176,24 @@  discard block
 block discarded – undo
176 176
 	 * @param string $type_of_file - general type of file (ie: "module"), this is only used to improve error messages
177 177
 	 * @return string
178 178
 	 */
179
-	private static function _permissions_error_for_unreadable_filepath( $full_file_path = '', $type_of_file = '' ){
179
+	private static function _permissions_error_for_unreadable_filepath($full_file_path = '', $type_of_file = '') {
180 180
 		// load WP_Filesystem and set file permissions
181
-		$wp_filesystem = EEH_File::_get_wp_filesystem( $full_file_path );
181
+		$wp_filesystem = EEH_File::_get_wp_filesystem($full_file_path);
182 182
 		// check file permissions
183
-		$perms = $wp_filesystem->getchmod( EEH_File::convert_local_filepath_to_remote_filepath( $full_file_path ) );
184
-		if ( $perms ) {
183
+		$perms = $wp_filesystem->getchmod(EEH_File::convert_local_filepath_to_remote_filepath($full_file_path));
184
+		if ($perms) {
185 185
 			// file permissions exist, but way be set incorrectly
186
-			$type_of_file = ! empty( $type_of_file ) ? $type_of_file . ' ' : '';
187
-			$type_of_file .= ! empty( $type_of_file ) ? 'file' : 'folder';
186
+			$type_of_file = ! empty($type_of_file) ? $type_of_file.' ' : '';
187
+			$type_of_file .= ! empty($type_of_file) ? 'file' : 'folder';
188 188
 			return sprintf(
189
-				__( 'File permissions for the requested %1$s are currently set at "%2$s". The recommended permissions are 644 for files and 755 for folders.', 'event_espresso' ),
189
+				__('File permissions for the requested %1$s are currently set at "%2$s". The recommended permissions are 644 for files and 755 for folders.', 'event_espresso'),
190 190
 				$type_of_file,
191 191
 				$perms
192 192
 			);
193 193
 		} else {
194 194
 			// file exists but file permissions could not be read ?!?!
195 195
 			return sprintf(
196
-				__( 'Please ensure that the server and/or PHP configuration allows the current process to access the following file: "%s".', 'event_espresso' ),
196
+				__('Please ensure that the server and/or PHP configuration allows the current process to access the following file: "%s".', 'event_espresso'),
197 197
 				$full_file_path
198 198
 			);
199 199
 		}
@@ -211,35 +211,35 @@  discard block
 block discarded – undo
211 211
 	 * can't write to it
212 212
 	 * @return bool false if folder isn't writable; true if it exists and is writeable,
213 213
 	 */
214
-	public static function ensure_folder_exists_and_is_writable( $folder = '' ){
215
-		if ( empty( $folder )) {
214
+	public static function ensure_folder_exists_and_is_writable($folder = '') {
215
+		if (empty($folder)) {
216 216
 			return false;
217 217
 		}
218 218
 		// remove ending DS
219
-		$folder = EEH_File::standardise_directory_separators( rtrim( $folder, '/\\' ));
220
-		$parent_folder = EEH_File::get_parent_folder( $folder );
219
+		$folder = EEH_File::standardise_directory_separators(rtrim($folder, '/\\'));
220
+		$parent_folder = EEH_File::get_parent_folder($folder);
221 221
 		// add DS to folder
222
-		$folder = EEH_File::end_with_directory_separator( $folder );
223
-		$wp_filesystem = EEH_File::_get_wp_filesystem( $folder );
224
-		if ( ! $wp_filesystem->is_dir( EEH_File::convert_local_filepath_to_remote_filepath( $folder ) ) ) {
222
+		$folder = EEH_File::end_with_directory_separator($folder);
223
+		$wp_filesystem = EEH_File::_get_wp_filesystem($folder);
224
+		if ( ! $wp_filesystem->is_dir(EEH_File::convert_local_filepath_to_remote_filepath($folder))) {
225 225
 			//ok so it doesn't exist. Does its parent? Can we write to it?
226
-			if(	! EEH_File::ensure_folder_exists_and_is_writable( $parent_folder ) ) {
226
+			if ( ! EEH_File::ensure_folder_exists_and_is_writable($parent_folder)) {
227 227
 				return false;
228 228
 			}
229
-			if ( ! EEH_File::verify_is_writable( $parent_folder, 'folder' )) {
229
+			if ( ! EEH_File::verify_is_writable($parent_folder, 'folder')) {
230 230
 				return false;
231 231
 			} else {
232
-				if ( ! $wp_filesystem->mkdir( EEH_File::convert_local_filepath_to_remote_filepath(  $folder ) ) ) {
233
-					if ( defined( 'WP_DEBUG' ) && WP_DEBUG ) {
234
-						$msg = sprintf( __( '"%s" could not be created.', 'event_espresso' ), $folder );
235
-						$msg .= EEH_File::_permissions_error_for_unreadable_filepath( $folder );
236
-						throw new EE_Error( $msg );
232
+				if ( ! $wp_filesystem->mkdir(EEH_File::convert_local_filepath_to_remote_filepath($folder))) {
233
+					if (defined('WP_DEBUG') && WP_DEBUG) {
234
+						$msg = sprintf(__('"%s" could not be created.', 'event_espresso'), $folder);
235
+						$msg .= EEH_File::_permissions_error_for_unreadable_filepath($folder);
236
+						throw new EE_Error($msg);
237 237
 					}
238 238
 					return false;
239 239
 				}
240
-				EEH_File::add_index_file( $folder );
240
+				EEH_File::add_index_file($folder);
241 241
 			}
242
-		} elseif ( ! EEH_File::verify_is_writable( $folder, 'folder' )) {
242
+		} elseif ( ! EEH_File::verify_is_writable($folder, 'folder')) {
243 243
 			return false;
244 244
 		}
245 245
 		return true;
@@ -254,15 +254,15 @@  discard block
 block discarded – undo
254 254
 	 * @throws EE_Error
255 255
 	 * @return bool
256 256
 	 */
257
-	public static function verify_is_writable( $full_path = '', $file_or_folder = 'folder' ){
257
+	public static function verify_is_writable($full_path = '', $file_or_folder = 'folder') {
258 258
 		// load WP_Filesystem and set file permissions
259
-		$wp_filesystem = EEH_File::_get_wp_filesystem( $full_path );
260
-		$full_path = EEH_File::standardise_directory_separators( $full_path );
261
-		if ( ! $wp_filesystem->is_writable( EEH_File::convert_local_filepath_to_remote_filepath( $full_path ) ) ) {
262
-			if ( defined( 'WP_DEBUG' ) && WP_DEBUG ) {
263
-				$msg = sprintf( __( 'The "%1$s" %2$s is not writable.', 'event_espresso' ), $full_path, $file_or_folder );
264
-				$msg .= EEH_File::_permissions_error_for_unreadable_filepath( $full_path );
265
-				throw new EE_Error( $msg );
259
+		$wp_filesystem = EEH_File::_get_wp_filesystem($full_path);
260
+		$full_path = EEH_File::standardise_directory_separators($full_path);
261
+		if ( ! $wp_filesystem->is_writable(EEH_File::convert_local_filepath_to_remote_filepath($full_path))) {
262
+			if (defined('WP_DEBUG') && WP_DEBUG) {
263
+				$msg = sprintf(__('The "%1$s" %2$s is not writable.', 'event_espresso'), $full_path, $file_or_folder);
264
+				$msg .= EEH_File::_permissions_error_for_unreadable_filepath($full_path);
265
+				throw new EE_Error($msg);
266 266
 			}
267 267
 			return FALSE;
268 268
 		}
@@ -279,25 +279,25 @@  discard block
 block discarded – undo
279 279
 	 * @throws EE_Error
280 280
 	 * @return bool
281 281
 	 */
282
-	public static function ensure_file_exists_and_is_writable( $full_file_path = '' ) {
282
+	public static function ensure_file_exists_and_is_writable($full_file_path = '') {
283 283
 		// load WP_Filesystem and set file permissions
284
-		$wp_filesystem = EEH_File::_get_wp_filesystem( $full_file_path );
285
-		$full_file_path = EEH_File::standardise_directory_separators( $full_file_path );
286
-		$parent_folder = EEH_File::get_parent_folder( $full_file_path );
287
-		if ( ! EEH_File::exists( $full_file_path )) {
288
-			if( ! EEH_File::ensure_folder_exists_and_is_writable( $parent_folder ) ) {
284
+		$wp_filesystem = EEH_File::_get_wp_filesystem($full_file_path);
285
+		$full_file_path = EEH_File::standardise_directory_separators($full_file_path);
286
+		$parent_folder = EEH_File::get_parent_folder($full_file_path);
287
+		if ( ! EEH_File::exists($full_file_path)) {
288
+			if ( ! EEH_File::ensure_folder_exists_and_is_writable($parent_folder)) {
289 289
 				return false;
290 290
 			}
291
-			if ( ! $wp_filesystem->touch( EEH_File::convert_local_filepath_to_remote_filepath( $full_file_path ) ) ) {
292
-				if ( defined( 'WP_DEBUG' ) && WP_DEBUG ) {
293
-					$msg = sprintf( __( 'The "%s" file could not be created.', 'event_espresso' ), $full_file_path );
294
-					$msg .= EEH_File::_permissions_error_for_unreadable_filepath( $full_file_path );
295
-					throw new EE_Error( $msg );
291
+			if ( ! $wp_filesystem->touch(EEH_File::convert_local_filepath_to_remote_filepath($full_file_path))) {
292
+				if (defined('WP_DEBUG') && WP_DEBUG) {
293
+					$msg = sprintf(__('The "%s" file could not be created.', 'event_espresso'), $full_file_path);
294
+					$msg .= EEH_File::_permissions_error_for_unreadable_filepath($full_file_path);
295
+					throw new EE_Error($msg);
296 296
 				}
297 297
 				return false;
298 298
 			}
299 299
 		}
300
-		if ( ! EEH_File::verify_is_writable( $full_file_path, 'file' )) {
300
+		if ( ! EEH_File::verify_is_writable($full_file_path, 'file')) {
301 301
 			return false;
302 302
 		}
303 303
 		return true;
@@ -309,15 +309,15 @@  discard block
 block discarded – undo
309 309
 	 * @param string $file_or_folder_path
310 310
 	 * @return string parent folder, ENDING with a directory separator
311 311
 	 */
312
-	public static function get_parent_folder( $file_or_folder_path ) {
312
+	public static function get_parent_folder($file_or_folder_path) {
313 313
 		//find the last DS, ignoring a DS on the very end
314 314
 		//eg if given "/var/something/somewhere/", we want to get "somewhere"'s
315 315
 		//parent folder, "/var/something/"
316
-		$ds = strrpos( $file_or_folder_path, DS, -2 );
317
-		return substr( $file_or_folder_path, 0, $ds + 1 );
316
+		$ds = strrpos($file_or_folder_path, DS, -2);
317
+		return substr($file_or_folder_path, 0, $ds + 1);
318 318
 	}
319 319
 	
320
-	public static function ensure_folder_exists_recursively( $folder ) {
320
+	public static function ensure_folder_exists_recursively($folder) {
321 321
 		
322 322
 	}
323 323
 
@@ -328,12 +328,12 @@  discard block
 block discarded – undo
328 328
 	 * @param string $full_file_path
329 329
 	 * @return string
330 330
 	 */
331
-	public static function get_file_contents( $full_file_path = '' ){
332
-		$full_file_path = EEH_File::standardise_directory_separators( $full_file_path );
333
-		if ( EEH_File::verify_filepath_and_permissions( $full_file_path, EEH_File::get_filename_from_filepath( $full_file_path ) , EEH_File::get_file_extension( $full_file_path ))) {
331
+	public static function get_file_contents($full_file_path = '') {
332
+		$full_file_path = EEH_File::standardise_directory_separators($full_file_path);
333
+		if (EEH_File::verify_filepath_and_permissions($full_file_path, EEH_File::get_filename_from_filepath($full_file_path), EEH_File::get_file_extension($full_file_path))) {
334 334
 			// load WP_Filesystem and set file permissions
335
-			$wp_filesystem = EEH_File::_get_wp_filesystem( $full_file_path );
336
-			return $wp_filesystem->get_contents(EEH_File::convert_local_filepath_to_remote_filepath( $full_file_path ) );
335
+			$wp_filesystem = EEH_File::_get_wp_filesystem($full_file_path);
336
+			return $wp_filesystem->get_contents(EEH_File::convert_local_filepath_to_remote_filepath($full_file_path));
337 337
 		}
338 338
 		return '';
339 339
 	}
@@ -348,26 +348,26 @@  discard block
 block discarded – undo
348 348
 	 * @throws EE_Error
349 349
 	 * @return bool
350 350
 	 */
351
-	public static function write_to_file( $full_file_path = '', $file_contents = '', $file_type = '' ){
352
-		$full_file_path = EEH_File::standardise_directory_separators( $full_file_path );
353
-		$file_type = ! empty( $file_type ) ? rtrim( $file_type, ' ' ) . ' ' : '';
354
-		$folder = EEH_File::remove_filename_from_filepath( $full_file_path );
355
-		if ( ! EEH_File::verify_is_writable( $folder, 'folder' )) {
356
-			if ( defined( 'WP_DEBUG' ) && WP_DEBUG ) {
357
-				$msg = sprintf( __( 'The %1$sfile located at "%2$s" is not writable.', 'event_espresso' ), $file_type, $full_file_path );
358
-				$msg .= EEH_File::_permissions_error_for_unreadable_filepath( $full_file_path );
359
-				throw new EE_Error( $msg );
351
+	public static function write_to_file($full_file_path = '', $file_contents = '', $file_type = '') {
352
+		$full_file_path = EEH_File::standardise_directory_separators($full_file_path);
353
+		$file_type = ! empty($file_type) ? rtrim($file_type, ' ').' ' : '';
354
+		$folder = EEH_File::remove_filename_from_filepath($full_file_path);
355
+		if ( ! EEH_File::verify_is_writable($folder, 'folder')) {
356
+			if (defined('WP_DEBUG') && WP_DEBUG) {
357
+				$msg = sprintf(__('The %1$sfile located at "%2$s" is not writable.', 'event_espresso'), $file_type, $full_file_path);
358
+				$msg .= EEH_File::_permissions_error_for_unreadable_filepath($full_file_path);
359
+				throw new EE_Error($msg);
360 360
 			}
361 361
 			return FALSE;
362 362
 		}
363 363
 		// load WP_Filesystem and set file permissions
364
-		$wp_filesystem = EEH_File::_get_wp_filesystem( $full_file_path );
364
+		$wp_filesystem = EEH_File::_get_wp_filesystem($full_file_path);
365 365
 		// write the file
366
-		if ( ! $wp_filesystem->put_contents(EEH_File::convert_local_filepath_to_remote_filepath( $full_file_path ), $file_contents )) {
367
-			if ( defined( 'WP_DEBUG' ) && WP_DEBUG ) {
368
-				$msg = sprintf( __( 'The %1$sfile located at "%2$s" could not be written to.', 'event_espresso' ), $file_type, $full_file_path );
369
-				$msg .= EEH_File::_permissions_error_for_unreadable_filepath( $full_file_path, 'f' );
370
-				throw new EE_Error( $msg );
366
+		if ( ! $wp_filesystem->put_contents(EEH_File::convert_local_filepath_to_remote_filepath($full_file_path), $file_contents)) {
367
+			if (defined('WP_DEBUG') && WP_DEBUG) {
368
+				$msg = sprintf(__('The %1$sfile located at "%2$s" could not be written to.', 'event_espresso'), $file_type, $full_file_path);
369
+				$msg .= EEH_File::_permissions_error_for_unreadable_filepath($full_file_path, 'f');
370
+				throw new EE_Error($msg);
371 371
 			}
372 372
 			return FALSE;
373 373
 		}
@@ -382,9 +382,9 @@  discard block
 block discarded – undo
382 382
 	 * @param boolean|string $type 'd' for directory, 'f' for file
383 383
 	 * @return boolean
384 384
 	 */
385
-	public static function delete( $filepath, $recursive = false, $type = false ) {
385
+	public static function delete($filepath, $recursive = false, $type = false) {
386 386
 		$wp_filesystem = EEH_File::_get_wp_filesystem();
387
-		return $wp_filesystem->delete( $filepath, $recursive, $type ) ? TRUE : FALSE;
387
+		return $wp_filesystem->delete($filepath, $recursive, $type) ? TRUE : FALSE;
388 388
 	}
389 389
 
390 390
 
@@ -396,9 +396,9 @@  discard block
 block discarded – undo
396 396
 	 * @param string $full_file_path
397 397
 	 * @return bool
398 398
 	 */
399
-	public static function exists( $full_file_path = '' ) {
400
-		$wp_filesystem = EEH_File::_get_wp_filesystem( $full_file_path );
401
-		return $wp_filesystem->exists( EEH_File::convert_local_filepath_to_remote_filepath( $full_file_path ) ) ? TRUE : FALSE;
399
+	public static function exists($full_file_path = '') {
400
+		$wp_filesystem = EEH_File::_get_wp_filesystem($full_file_path);
401
+		return $wp_filesystem->exists(EEH_File::convert_local_filepath_to_remote_filepath($full_file_path)) ? TRUE : FALSE;
402 402
 	}
403 403
 
404 404
 
@@ -410,9 +410,9 @@  discard block
 block discarded – undo
410 410
 	 * @param string $full_file_path
411 411
 	 * @return bool
412 412
 	 */
413
-	public static function is_readable( $full_file_path = '' ) {
414
-		$wp_filesystem = EEH_File::_get_wp_filesystem( $full_file_path );
415
-		if( $wp_filesystem->is_readable( EEH_File::convert_local_filepath_to_remote_filepath(  $full_file_path ) ) ) {
413
+	public static function is_readable($full_file_path = '') {
414
+		$wp_filesystem = EEH_File::_get_wp_filesystem($full_file_path);
415
+		if ($wp_filesystem->is_readable(EEH_File::convert_local_filepath_to_remote_filepath($full_file_path))) {
416 416
 			return true;
417 417
 		} else {
418 418
 			return false;
@@ -428,8 +428,8 @@  discard block
 block discarded – undo
428 428
 	 * @param string $full_file_path
429 429
 	 * @return string
430 430
 	 */
431
-	public static function remove_filename_from_filepath( $full_file_path = '' ) {
432
-		return pathinfo( $full_file_path, PATHINFO_DIRNAME );
431
+	public static function remove_filename_from_filepath($full_file_path = '') {
432
+		return pathinfo($full_file_path, PATHINFO_DIRNAME);
433 433
 	}
434 434
 
435 435
 
@@ -439,8 +439,8 @@  discard block
 block discarded – undo
439 439
 	 * @param string $full_file_path
440 440
 	 * @return string
441 441
 	 */
442
-	public static function get_filename_from_filepath( $full_file_path = '' ) {
443
-		return pathinfo( $full_file_path, PATHINFO_BASENAME );
442
+	public static function get_filename_from_filepath($full_file_path = '') {
443
+		return pathinfo($full_file_path, PATHINFO_BASENAME);
444 444
 	}
445 445
 
446 446
 
@@ -450,8 +450,8 @@  discard block
 block discarded – undo
450 450
 	 * @param string $full_file_path
451 451
 	 * @return string
452 452
 	 */
453
-	public static function get_file_extension( $full_file_path = '' ) {
454
-		return pathinfo( $full_file_path, PATHINFO_EXTENSION );
453
+	public static function get_file_extension($full_file_path = '') {
454
+		return pathinfo($full_file_path, PATHINFO_EXTENSION);
455 455
 	}
456 456
 
457 457
 
@@ -461,10 +461,10 @@  discard block
 block discarded – undo
461 461
 	 * @param string $folder
462 462
 	 * @return bool
463 463
 	 */
464
-	public static function add_htaccess_deny_from_all( $folder = '' ) {
465
-		$folder = EEH_File::standardise_and_end_with_directory_separator( $folder );
466
-		if ( ! EEH_File::exists( $folder . '.htaccess' ) ) {
467
-			if ( ! EEH_File::write_to_file( $folder . '.htaccess', 'deny from all', '.htaccess' )) {
464
+	public static function add_htaccess_deny_from_all($folder = '') {
465
+		$folder = EEH_File::standardise_and_end_with_directory_separator($folder);
466
+		if ( ! EEH_File::exists($folder.'.htaccess')) {
467
+			if ( ! EEH_File::write_to_file($folder.'.htaccess', 'deny from all', '.htaccess')) {
468 468
 				return FALSE;
469 469
 			}
470 470
 		}
@@ -477,10 +477,10 @@  discard block
 block discarded – undo
477 477
 	 * @param string $folder
478 478
 	 * @return boolean
479 479
 	 */
480
-	public static function add_index_file( $folder ) {
481
-		$folder = EEH_File::standardise_and_end_with_directory_separator( $folder );
482
-		if ( ! EEH_File::exists( $folder . 'index.php' ) ) {
483
-			if ( ! EEH_File::write_to_file( $folder . 'index.php', 'You are not permitted to read from this folder', '.php' )) {
480
+	public static function add_index_file($folder) {
481
+		$folder = EEH_File::standardise_and_end_with_directory_separator($folder);
482
+		if ( ! EEH_File::exists($folder.'index.php')) {
483
+			if ( ! EEH_File::write_to_file($folder.'index.php', 'You are not permitted to read from this folder', '.php')) {
484 484
 				return false;
485 485
 			}
486 486
 		}
@@ -495,11 +495,11 @@  discard block
 block discarded – undo
495 495
 	 * @param string $file_path
496 496
 	 * @return string
497 497
 	 */
498
-	public static function get_classname_from_filepath_with_standard_filename( $file_path ){
498
+	public static function get_classname_from_filepath_with_standard_filename($file_path) {
499 499
 		//extract file from path
500
-		$filename = basename( $file_path );
500
+		$filename = basename($file_path);
501 501
 		//now remove the first period and everything after
502
-		$pos_of_first_period = strpos( $filename,'.' );
502
+		$pos_of_first_period = strpos($filename, '.');
503 503
 		return substr($filename, 0, $pos_of_first_period);
504 504
 	}
505 505
 
@@ -511,8 +511,8 @@  discard block
 block discarded – undo
511 511
 	 * @param string $file_path
512 512
 	 * @return string
513 513
 	 */
514
-	public static function standardise_directory_separators( $file_path ){
515
-		return str_replace( array( '\\', '/' ), DS, $file_path );
514
+	public static function standardise_directory_separators($file_path) {
515
+		return str_replace(array('\\', '/'), DS, $file_path);
516 516
 	}
517 517
 
518 518
 
@@ -523,8 +523,8 @@  discard block
 block discarded – undo
523 523
 	 * @param string $file_path
524 524
 	 * @return string
525 525
 	 */
526
-	public static function end_with_directory_separator( $file_path ){
527
-		return rtrim( $file_path, '/\\' ) . DS;
526
+	public static function end_with_directory_separator($file_path) {
527
+		return rtrim($file_path, '/\\').DS;
528 528
 	}
529 529
 
530 530
 
@@ -534,8 +534,8 @@  discard block
 block discarded – undo
534 534
 	 * @param $file_path
535 535
 	 * @return string
536 536
 	 */
537
-	public static function standardise_and_end_with_directory_separator( $file_path ){
538
-		return self::end_with_directory_separator( self::standardise_directory_separators( $file_path ));
537
+	public static function standardise_and_end_with_directory_separator($file_path) {
538
+		return self::end_with_directory_separator(self::standardise_directory_separators($file_path));
539 539
 	}
540 540
 
541 541
 
@@ -552,21 +552,21 @@  discard block
 block discarded – undo
552 552
 	 *		if $index_numerically == FALSE (Default) keys are what the class names SHOULD be;
553 553
 	 *		 and values are their filepaths
554 554
 	 */
555
-	public static function get_contents_of_folders( $folder_paths = array(), $index_numerically = FALSE ){
555
+	public static function get_contents_of_folders($folder_paths = array(), $index_numerically = FALSE) {
556 556
 		$class_to_folder_path = array();
557
-		foreach( $folder_paths as $folder_path ){
558
-			$folder_path = self::standardise_and_end_with_directory_separator( $folder_path );
557
+		foreach ($folder_paths as $folder_path) {
558
+			$folder_path = self::standardise_and_end_with_directory_separator($folder_path);
559 559
 			// load WP_Filesystem and set file permissions
560
-			$files_in_folder = glob( $folder_path . '*' );
560
+			$files_in_folder = glob($folder_path.'*');
561 561
 			$class_to_folder_path = array();
562
-			if ( $files_in_folder ) {
563
-				foreach( $files_in_folder as $file_path ){
562
+			if ($files_in_folder) {
563
+				foreach ($files_in_folder as $file_path) {
564 564
 					//only add files, not folders
565
-					if ( ! is_dir( $file_path )) {
566
-						if ( $index_numerically ) {
565
+					if ( ! is_dir($file_path)) {
566
+						if ($index_numerically) {
567 567
 							$class_to_folder_path[] = $file_path;
568 568
 						} else {
569
-							$classname = self::get_classname_from_filepath_with_standard_filename( $file_path );
569
+							$classname = self::get_classname_from_filepath_with_standard_filename($file_path);
570 570
 							$class_to_folder_path[$classname] = $file_path;
571 571
 						}
572 572
 					}
@@ -586,39 +586,39 @@  discard block
 block discarded – undo
586 586
 	 * @return boolean success
587 587
 	 * @throws EE_Error
588 588
 	 */
589
-	public static function copy( $source_file, $destination_file, $overwrite = FALSE ){
590
-		$full_source_path = EEH_File::standardise_directory_separators( $source_file );
591
-		if( ! EEH_File::exists( $full_source_path ) ){
592
-			if ( defined( 'WP_DEBUG' ) && WP_DEBUG ) {
593
-				$msg = sprintf( __( 'The file located at "%2$s" is not readable or doesn\'t exist.', 'event_espresso' ), $full_source_path );
594
-				$msg .= EEH_File::_permissions_error_for_unreadable_filepath( $full_source_path );
595
-				throw new EE_Error( $msg );
589
+	public static function copy($source_file, $destination_file, $overwrite = FALSE) {
590
+		$full_source_path = EEH_File::standardise_directory_separators($source_file);
591
+		if ( ! EEH_File::exists($full_source_path)) {
592
+			if (defined('WP_DEBUG') && WP_DEBUG) {
593
+				$msg = sprintf(__('The file located at "%2$s" is not readable or doesn\'t exist.', 'event_espresso'), $full_source_path);
594
+				$msg .= EEH_File::_permissions_error_for_unreadable_filepath($full_source_path);
595
+				throw new EE_Error($msg);
596 596
 			}
597 597
 			return FALSE;
598 598
 		}
599 599
 
600
-		$full_dest_path = EEH_File::standardise_directory_separators( $destination_file );
601
-		$folder = EEH_File::remove_filename_from_filepath( $full_dest_path );
602
-		if ( ! EEH_File::verify_is_writable( $folder, 'folder' )) {
603
-			if ( defined( 'WP_DEBUG' ) && WP_DEBUG ) {
604
-				$msg = sprintf( __( 'The file located at "%2$s" is not writable.', 'event_espresso' ), $full_dest_path );
605
-				$msg .= EEH_File::_permissions_error_for_unreadable_filepath( $full_dest_path );
606
-				throw new EE_Error( $msg );
600
+		$full_dest_path = EEH_File::standardise_directory_separators($destination_file);
601
+		$folder = EEH_File::remove_filename_from_filepath($full_dest_path);
602
+		if ( ! EEH_File::verify_is_writable($folder, 'folder')) {
603
+			if (defined('WP_DEBUG') && WP_DEBUG) {
604
+				$msg = sprintf(__('The file located at "%2$s" is not writable.', 'event_espresso'), $full_dest_path);
605
+				$msg .= EEH_File::_permissions_error_for_unreadable_filepath($full_dest_path);
606
+				throw new EE_Error($msg);
607 607
 			}
608 608
 			return FALSE;
609 609
 		}
610 610
 
611 611
 		// load WP_Filesystem and set file permissions
612
-		$wp_filesystem = EEH_File::_get_wp_filesystem( $destination_file );
612
+		$wp_filesystem = EEH_File::_get_wp_filesystem($destination_file);
613 613
 		// write the file
614 614
 		if ( ! $wp_filesystem->copy( 
615
-						EEH_File::convert_local_filepath_to_remote_filepath( $full_source_path ), 
616
-						EEH_File::convert_local_filepath_to_remote_filepath( $full_dest_path ), 
615
+						EEH_File::convert_local_filepath_to_remote_filepath($full_source_path), 
616
+						EEH_File::convert_local_filepath_to_remote_filepath($full_dest_path), 
617 617
 						$overwrite )) {
618
-			if ( defined( 'WP_DEBUG' ) && WP_DEBUG ) {
619
-				$msg = sprintf( __( 'Attempted writing to file %1$s, but could not, probably because of permissions issues', 'event_espresso' ), $full_source_path );
620
-				$msg .= EEH_File::_permissions_error_for_unreadable_filepath( $full_source_path, 'f' );
621
-				throw new EE_Error( $msg );
618
+			if (defined('WP_DEBUG') && WP_DEBUG) {
619
+				$msg = sprintf(__('Attempted writing to file %1$s, but could not, probably because of permissions issues', 'event_espresso'), $full_source_path);
620
+				$msg .= EEH_File::_permissions_error_for_unreadable_filepath($full_source_path, 'f');
621
+				throw new EE_Error($msg);
622 622
 			}
623 623
 			return FALSE;
624 624
 		}
@@ -630,9 +630,9 @@  discard block
 block discarded – undo
630 630
 	 * @param string $filepath
631 631
 	 * @return boolean
632 632
 	 */
633
-	public static function is_in_uploads_folder( $filepath ) {
633
+	public static function is_in_uploads_folder($filepath) {
634 634
 		$uploads = wp_upload_dir();
635
-		return strpos( $filepath, $uploads[ 'basedir' ] ) === 0 ? true : false;
635
+		return strpos($filepath, $uploads['basedir']) === 0 ? true : false;
636 636
 	}
637 637
 	
638 638
 	/**
@@ -646,9 +646,9 @@  discard block
 block discarded – undo
646 646
 	 * @return string the remote filepath (eg the filepath the filesystem method, eg 
647 647
 	 * ftp or ssh, will use to access the folder
648 648
 	 */
649
-	public static function convert_local_filepath_to_remote_filepath( $local_filepath ) {
650
-		$wp_filesystem = EEH_File::_get_wp_filesystem( $local_filepath );
651
-		return str_replace( WP_CONTENT_DIR . DS, $wp_filesystem->wp_content_dir(), $local_filepath );
649
+	public static function convert_local_filepath_to_remote_filepath($local_filepath) {
650
+		$wp_filesystem = EEH_File::_get_wp_filesystem($local_filepath);
651
+		return str_replace(WP_CONTENT_DIR.DS, $wp_filesystem->wp_content_dir(), $local_filepath);
652 652
 	}
653 653
 }
654 654
 // End of file EEH_File.helper.php
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.
core/db_models/EEM_Extra_Join.model.php 1 patch
Spacing   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -21,26 +21,26 @@
 block discarded – undo
21 21
  * @since		 	   $VID:$
22 22
  *
23 23
  */
24
-if (!defined('EVENT_ESPRESSO_VERSION')) {
24
+if ( ! defined('EVENT_ESPRESSO_VERSION')) {
25 25
 	exit('No direct script access allowed');
26 26
 }
27 27
 
28
-class EEM_Extra_Join extends EEM_Base{
28
+class EEM_Extra_Join extends EEM_Base {
29 29
 	// private instance of the Extra Join object
30 30
 	protected static $_instance = NULL;
31 31
 	
32 32
 	public function __construct($timezone = NULL) {
33
-		$models_this_can_join = array_keys( EE_Registry::instance()->non_abstract_db_models );
33
+		$models_this_can_join = array_keys(EE_Registry::instance()->non_abstract_db_models);
34 34
 		$this->_tables = array(
35
-			'Extra_Join' => new EE_Primary_Table( 'esp_extra_join', 'EXJ_ID' ),
35
+			'Extra_Join' => new EE_Primary_Table('esp_extra_join', 'EXJ_ID'),
36 36
 		);
37 37
 		$this->_fields = array(
38 38
 			'Extra_Join' => array(
39
-				'EXJ_ID' => new EE_Primary_Key_Int_Field( 'EXJ_ID', __( 'Extra Join ID', 'event_espresso' ) ),
40
-				'EXJ_first_model_ID' => new EE_Foreign_Key_String_Field( 'EXJ_first_model_ID', __( 'First Model ID', 'event_espresso' ), true, 0, $models_this_can_join ),
41
-				'EXJ_first_model_name' => new EE_Any_Foreign_Model_Name_Field( 'EXJ_first_model_name', __( 'First Model Name', 'event_espresso'), true, '', $models_this_can_join ),
42
-				'EXJ_second_model_ID' => new EE_Foreign_Key_String_Field( 'EXJ_second_model_ID', __( 'Second Model ID', 'event_espresso' ), true, 0, $models_this_can_join ),
43
-				'EXJ_second_model_name' => new EE_Any_Foreign_Model_Name_Field( 'EXJ_second_model_name', __( 'Second Model Name', 'event_espresso'), true, '', $models_this_can_join ),
39
+				'EXJ_ID' => new EE_Primary_Key_Int_Field('EXJ_ID', __('Extra Join ID', 'event_espresso')),
40
+				'EXJ_first_model_ID' => new EE_Foreign_Key_String_Field('EXJ_first_model_ID', __('First Model ID', 'event_espresso'), true, 0, $models_this_can_join),
41
+				'EXJ_first_model_name' => new EE_Any_Foreign_Model_Name_Field('EXJ_first_model_name', __('First Model Name', 'event_espresso'), true, '', $models_this_can_join),
42
+				'EXJ_second_model_ID' => new EE_Foreign_Key_String_Field('EXJ_second_model_ID', __('Second Model ID', 'event_espresso'), true, 0, $models_this_can_join),
43
+				'EXJ_second_model_name' => new EE_Any_Foreign_Model_Name_Field('EXJ_second_model_name', __('Second Model Name', 'event_espresso'), true, '', $models_this_can_join),
44 44
 				
45 45
 			)
46 46
 		);
Please login to merge, or discard this patch.
core/db_models/EEM_Base.model.php 2 patches
Doc Comments   +15 added lines, -15 removed lines patch added patch discarded remove patch
@@ -741,7 +741,7 @@  discard block
 block discarded – undo
741 741
 	 * Returns the name of the field's name that points to the WP_User table
742 742
 	 *  on this model (or follows the _model_chain_to_wp_user and uses that model's
743 743
 	 * foreign key to the WP_User table)
744
-	 * @return string|boolean string on success, boolean false when there is no
744
+	 * @return string|false string on success, boolean false when there is no
745 745
 	 * foreign key to the WP_User table
746 746
 	 */
747 747
 	function wp_user_field_name() {
@@ -837,6 +837,7 @@  discard block
 block discarded – undo
837 837
 	 * If you would like to use these custom selections in WHERE, GROUP_BY, or HAVING clauses, you must instead provide an array.
838 838
 	 * Array keys are the aliases used to refer to this selection, and values are to be numerically-indexed arrays, where 0 is the selection
839 839
 	 * and 1 is the data type. Eg, array('count'=>array('COUNT(REG_ID)','%d'))
840
+	 * @param string $columns_to_select
840 841
 	 * @return stdClass[] like results of $wpdb->get_results($sql,OBJECT), (ie, output type is OBJECT)
841 842
 	 */
842 843
 	public function  get_all_wpdb_results($query_params = array(), $output = ARRAY_A, $columns_to_select = null){
@@ -1139,7 +1140,7 @@  discard block
 block discarded – undo
1139 1140
 	 * @param bool   $pretty          Whether to return the pretty formats (true) or not (false).
1140 1141
 	 * @throws EE_Error   If the given field_name is not of the EE_Datetime_Field type.
1141 1142
 	 *
1142
-	 * @return array formats in an array with the date format first, and the time format last.
1143
+	 * @return string[] formats in an array with the date format first, and the time format last.
1143 1144
 	 */
1144 1145
 	public function get_formats_for( $field_name, $pretty = false ) {
1145 1146
 		$field_settings = $this->field_settings_for( $field_name );
@@ -1174,7 +1175,7 @@  discard block
 block discarded – undo
1174 1175
 	 *
1175 1176
 	 * @throws EE_Error   	If the given field_name is not of the EE_Datetime_Field type.
1176 1177
 	 *
1177
-	 * @return int|string  If the given field_name is not of the EE_Datetime_Field type, then an EE_Error
1178
+	 * @return string|null  If the given field_name is not of the EE_Datetime_Field type, then an EE_Error
1178 1179
 	 *                    	     exception is triggered.
1179 1180
 	 */
1180 1181
 	public function current_time_for_query( $field_name, $timestamp = false, $what = 'both' ) {
@@ -1474,7 +1475,7 @@  discard block
 block discarded – undo
1474 1475
 	 * Deletes a single row from the DB given the model object's primary key value. (eg, EE_Attendee->ID()'s value).
1475 1476
 	 * Wrapper for EEM_Base::delete()
1476 1477
 	 * @param mixed $id
1477
-	 * @return boolean whether the row got deleted or not
1478
+	 * @return integer whether the row got deleted or not
1478 1479
 	 */
1479 1480
 	public function delete_by_ID( $id ){
1480 1481
 		return $this->delete( array(
@@ -1834,7 +1835,7 @@  discard block
 block discarded – undo
1834 1835
 	/**
1835 1836
 	 * Verifies the EE addons' database is up-to-date and records that we've done it on
1836 1837
 	 * EEM_Base::$_db_verification_level
1837
-	 * @param $wpdb_method
1838
+	 * @param string $wpdb_method
1838 1839
 	 * @param $arguments_to_provide
1839 1840
 	 * @return string
1840 1841
 	 */
@@ -1902,7 +1903,6 @@  discard block
 block discarded – undo
1902 1903
 	 * 'hasAndBelongsToMany' relationships: checks that there isn't already an entry in the join table, and adds one.
1903 1904
 	 * If one of the model Objects has not yet been saved to the database, it is saved before adding the entry in the join table
1904 1905
 	 *
1905
-	 * @param EE_Base_Class/int $thisModelObject
1906 1906
 	 * @param EE_Base_Class/int $id_or_obj EE_base_Class or ID of other Model Object
1907 1907
 	 * @param string $relationName, key in EEM_Base::_relations
1908 1908
 	 * an attendee to a group, you also want to specify which role they will have in that group. So you would use this parameter to specify array('role-column-name'=>'role-id')
@@ -1924,8 +1924,8 @@  discard block
 block discarded – undo
1924 1924
 	 *
1925 1925
 	 * 'hasAndBelongsToMany' relationships:removes any existing entry in the join table between the two models.
1926 1926
 	 *
1927
-	 * @param EE_Base_Class/int $id_or_obj
1928
-	 * @param EE_Base_Class/int $other_model_id_or_obj EE_Base_Class or ID of other Model Object
1927
+	 * @param EE_CPT_Base $id_or_obj
1928
+	 * @param EE_Term_Taxonomy $other_model_id_or_obj EE_Base_Class or ID of other Model Object
1929 1929
 	 * @param string $relationName key in EEM_Base::_relations
1930 1930
 	 * @return boolean of success
1931 1931
 	 * @param array   $where_query This allows you to enter further query params for the relation to for relation to methods that allow you to further specify extra columns to join by (such as HABTM).  Keep in mind that the only acceptable query_params is strict "col" => "value" pairs because these will be inserted in any new rows created as well.
@@ -2001,7 +2001,7 @@  discard block
 block discarded – undo
2001 2001
 	/**
2002 2002
 	 * Instead of getting the related model objects, simply counts them. Ignores default_where_conditions by default,
2003 2003
 	 * unless otherwise specified in the $query_params
2004
-	 * @param int/EE_Base_Class $id_or_obj
2004
+	 * @param EE_Event $id_or_obj
2005 2005
 	 * @param string $model_name like 'Event', or 'Registration'
2006 2006
 	 * @param array $query_params like EEM_Base::get_all's
2007 2007
 	 * @param string $field_to_count name of field to count by. By default, uses primary key
@@ -2390,7 +2390,7 @@  discard block
 block discarded – undo
2390 2390
 	/**
2391 2391
 	 * Finds all the fields that correspond to the given table
2392 2392
 	 * @param string $table_alias, array key in EEM_Base::_tables
2393
-	 * @return EE_Model_Field_Base[]
2393
+	 * @return EE_Model_Field_Base
2394 2394
 	 */
2395 2395
 	function _get_fields_for_table($table_alias){
2396 2396
 		return $this->_fields[$table_alias];
@@ -3454,8 +3454,8 @@  discard block
 block discarded – undo
3454 3454
 	/**
3455 3455
 	 * gets the field object of type 'primary_key' from the fieldsSettings attribute.
3456 3456
 	 * Eg, on EE_Answer that would be ANS_ID field object
3457
-	 * @param $field_obj
3458
-	 * @return EE_Model_Field_Base
3457
+	 * @param EE_Model_Field_Base $field_obj
3458
+	 * @return boolean
3459 3459
 	 */
3460 3460
 	public function is_primary_key_field( $field_obj ){
3461 3461
 		return $field_obj instanceof EE_Primary_Key_Field_Base ? TRUE : FALSE;
@@ -3549,7 +3549,7 @@  discard block
 block discarded – undo
3549 3549
 	 * Gets the actual table for the table alias
3550 3550
 	 * @param string $table_alias eg Event, Event_Meta, Registration, Transaction, but maybe
3551 3551
 	 * a table alias with a model chain prefix, like 'Venue__Event_Venue___Event_Meta'. Either one works
3552
-	 * @return EE_Table_Base
3552
+	 * @return string
3553 3553
 	 */
3554 3554
 	function get_table_for_alias($table_alias){
3555 3555
 		$table_alias_sans_model_relation_chain_prefix = EE_Model_Parser::remove_table_alias_model_relation_chain_prefix($table_alias);
@@ -3676,7 +3676,7 @@  discard block
 block discarded – undo
3676 3676
 	 * The purpose of this method is to allow us to create a model object that is not in the db that holds default values.
3677 3677
 	 * 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!).
3678 3678
 	 *
3679
-	 * @return EE_Base_Class single EE_Base_Class object with default values for the properties.
3679
+	 * @return boolean single EE_Base_Class object with default values for the properties.
3680 3680
 	 */
3681 3681
 	public function create_default_object() {
3682 3682
 
@@ -4066,7 +4066,7 @@  discard block
 block discarded – undo
4066 4066
 	}
4067 4067
 	/**
4068 4068
 	 * Read comments for assume_values_already_prepared_by_model_object()
4069
-	 * @return int
4069
+	 * @return boolean
4070 4070
 	 */
4071 4071
 	public function get_assumption_concerning_values_already_prepared_by_model_object(){
4072 4072
 		return $this->_values_already_prepared_by_model_object;
Please login to merge, or discard this patch.
Spacing   +954 added lines, -954 removed lines patch added patch discarded remove patch
@@ -23,7 +23,7 @@  discard block
 block discarded – undo
23 23
  * @since 				EE4
24 24
  *
25 25
  */
26
-abstract class EEM_Base extends EE_Base{
26
+abstract class EEM_Base extends EE_Base {
27 27
 
28 28
 	//admin posty
29 29
 	//basic -> grants access to mine -> if they don't have it, select none
@@ -228,7 +228,7 @@  discard block
 block discarded – undo
228 228
 	 * Flag indicating whether this model has a primary key or not
229 229
 	 * @var boolean
230 230
 	 */
231
-	protected $_has_primary_key_field=null;
231
+	protected $_has_primary_key_field = null;
232 232
 
233 233
 	/**
234 234
 	 * Whether or not this model is based off a table in WP core only (CPTs should set
@@ -290,19 +290,19 @@  discard block
 block discarded – undo
290 290
 	 * operators that work like 'BETWEEN'.  Typically used for datetime calculations, i.e. "BETWEEN '12-1-2011' AND '12-31-2012'"
291 291
 	 * @var array
292 292
 	 */
293
-	protected $_between_style_operators = array( 'BETWEEN' );
293
+	protected $_between_style_operators = array('BETWEEN');
294 294
 
295 295
 	/**
296 296
 	 * operators that are used for handling NUll and !NULL queries.  Typically used for when checking if a row exists on a join table.
297 297
 	 * @var array
298 298
 	 */
299
-	protected $_null_style_operators = array( 'IS NOT NULL', 'IS NULL');
299
+	protected $_null_style_operators = array('IS NOT NULL', 'IS NULL');
300 300
 
301 301
 	/**
302 302
 	 * Allowed values for $query_params['order'] for ordering in queries
303 303
 	 * @var array
304 304
 	 */
305
-	protected $_allowed_order_values = array('asc','desc','ASC','DESC');
305
+	protected $_allowed_order_values = array('asc', 'desc', 'ASC', 'DESC');
306 306
 
307 307
 	/**
308 308
 	 * When these are keys in a WHERE or HAVING clause, they are handled much differently
@@ -316,13 +316,13 @@  discard block
 block discarded – undo
316 316
 	 * 'where', but 'where' clauses are so common that we thought we'd omit it
317 317
 	 * @var array
318 318
 	 */
319
-	private $_allowed_query_params = array(0, 'limit','order_by','group_by','having','force_join','order','on_join_limit','default_where_conditions', 'caps');
319
+	private $_allowed_query_params = array(0, 'limit', 'order_by', 'group_by', 'having', 'force_join', 'order', 'on_join_limit', 'default_where_conditions', 'caps');
320 320
 
321 321
 	/**
322 322
 	 * All the data types that can be used in $wpdb->prepare statements.
323 323
 	 * @var array
324 324
 	 */
325
-	private $_valid_wpdb_data_types = array('%d','%s','%f');
325
+	private $_valid_wpdb_data_types = array('%d', '%s', '%f');
326 326
 
327 327
 	/**
328 328
 	 * 	EE_Registry Object
@@ -355,17 +355,17 @@  discard block
 block discarded – undo
355 355
 	/**
356 356
 	 * constant used to show EEM_Base has not yet verified the db on this http request
357 357
 	 */
358
-	const db_verified_none 		= 0;
358
+	const db_verified_none = 0;
359 359
 	/**
360 360
 	 * constant used to show EEM_Base has verified the EE core db on this http request,
361 361
 	 * but not the addons' dbs
362 362
 	 */
363
-	const db_verified_core 		= 1;
363
+	const db_verified_core = 1;
364 364
 	/**
365 365
 	 * constant used to show EEM_Base has verified the addons' dbs (and implicitly
366 366
 	 * the EE core db too)
367 367
 	 */
368
-	const db_verified_addons 	= 2;
368
+	const db_verified_addons = 2;
369 369
 
370 370
 	/**
371 371
 	 * indicates whether an EEM_Base child has already re-verified the DB
@@ -402,13 +402,13 @@  discard block
 block discarded – undo
402 402
 	 * @param null $timezone
403 403
 	 * @throws \EE_Error
404 404
 	 */
405
-	protected function __construct( $timezone = NULL ){
405
+	protected function __construct($timezone = NULL) {
406 406
 		// check that the model has not been loaded too soon
407
-		if ( ! did_action( 'AHEE__EE_System__load_espresso_addons' )) {
408
-			throw new EE_Error (
407
+		if ( ! did_action('AHEE__EE_System__load_espresso_addons')) {
408
+			throw new EE_Error(
409 409
 				sprintf(
410
-					__( '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' ),
411
-					get_class( $this )
410
+					__('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'),
411
+					get_class($this)
412 412
 				)
413 413
 			);
414 414
 		}
@@ -418,11 +418,11 @@  discard block
 block discarded – undo
418 418
 		 * just use EE_Register_Model_Extension
419 419
 		 * @var EE_Table_Base[] $_tables
420 420
 		 */
421
-		$this->_tables = apply_filters( 'FHEE__'.get_class($this).'__construct__tables', $this->_tables );
422
-		foreach($this->_tables as $table_alias => $table_obj){
421
+		$this->_tables = apply_filters('FHEE__'.get_class($this).'__construct__tables', $this->_tables);
422
+		foreach ($this->_tables as $table_alias => $table_obj) {
423 423
 			/** @var $table_obj EE_Table_Base */
424 424
 			$table_obj->_construct_finalize_with_alias($table_alias);
425
-			if( $table_obj instanceof EE_Secondary_Table ){
425
+			if ($table_obj instanceof EE_Secondary_Table) {
426 426
 				/** @var $table_obj EE_Secondary_Table */
427 427
 				$table_obj->_construct_finalize_set_table_to_join_with($this->_get_main_table());
428 428
 			}
@@ -432,48 +432,48 @@  discard block
 block discarded – undo
432 432
 		 * EE_Register_Model_Extension
433 433
 		 * @param EE_Model_Field_Base[] $_fields
434 434
 		 */
435
-		$this->_fields = apply_filters('FHEE__'.get_class($this).'__construct__fields',$this->_fields);
436
-		foreach($this->_fields as $table_alias => $fields_for_table){
437
-			if ( ! array_key_exists( $table_alias, $this->_tables )){
438
-				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)));
435
+		$this->_fields = apply_filters('FHEE__'.get_class($this).'__construct__fields', $this->_fields);
436
+		foreach ($this->_fields as $table_alias => $fields_for_table) {
437
+			if ( ! array_key_exists($table_alias, $this->_tables)) {
438
+				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)));
439 439
 			}
440
-			foreach($fields_for_table as $field_name => $field_obj){
440
+			foreach ($fields_for_table as $field_name => $field_obj) {
441 441
 				/** @var $field_obj EE_Model_Field_Base | EE_Primary_Key_Field_Base */
442 442
 				//primary key field base has a slightly different _construct_finalize
443 443
 				/** @var $field_obj EE_Model_Field_Base */
444
-				$field_obj->_construct_finalize( $table_alias, $field_name, $this->get_this_model_name() );
444
+				$field_obj->_construct_finalize($table_alias, $field_name, $this->get_this_model_name());
445 445
 			}
446 446
 		}
447 447
 
448 448
 		// everything is related to Extra_Meta
449
-		if( get_class($this) != 'EEM_Extra_Meta'){
449
+		if (get_class($this) != 'EEM_Extra_Meta') {
450 450
 			//make extra meta related to everything, but don't block deleting things just
451 451
 			//because they have related extra meta info. For now just orphan those extra meta
452 452
 			//in the future we should automatically delete them
453
-			$this->_model_relations['Extra_Meta'] = new EE_Has_Many_Any_Relation( FALSE );
453
+			$this->_model_relations['Extra_Meta'] = new EE_Has_Many_Any_Relation(FALSE);
454 454
 		}
455 455
 		//and change logs
456
-		if( get_class( $this) !=  'EEM_Change_Log' ) {
457
-			$this->_model_relations[ 'Change_Log' ] = new EE_Has_Many_Any_Relation( FALSE );
456
+		if (get_class($this) != 'EEM_Change_Log') {
457
+			$this->_model_relations['Change_Log'] = new EE_Has_Many_Any_Relation(FALSE);
458 458
 		}
459 459
 		/**
460 460
 		 * Filters the list of relations on a model. It is best to NOT use this directly and instead just use
461 461
 		 * EE_Register_Model_Extension
462 462
 		 * @param EE_Model_Relation_Base[] $_model_relations
463 463
 		 */
464
-		$this->_model_relations = apply_filters('FHEE__'.get_class($this).'__construct__model_relations',$this->_model_relations);
465
-		foreach($this->_model_relations as $model_name => $relation_obj){
464
+		$this->_model_relations = apply_filters('FHEE__'.get_class($this).'__construct__model_relations', $this->_model_relations);
465
+		foreach ($this->_model_relations as $model_name => $relation_obj) {
466 466
 			/** @var $relation_obj EE_Model_Relation_Base */
467 467
 			$relation_obj->_construct_finalize_set_models($this->get_this_model_name(), $model_name);
468 468
 		}
469
-		foreach($this->_indexes as $index_name => $index_obj){
469
+		foreach ($this->_indexes as $index_name => $index_obj) {
470 470
 			/** @var $index_obj EE_Index */
471 471
 			$index_obj->_construct_finalize($index_name, $this->get_this_model_name());
472 472
 		}
473 473
 
474 474
 		$this->set_timezone($timezone);
475 475
 		//finalize default where condition strategy, or set default
476
-		if( ! $this->_default_where_conditions_strategy){
476
+		if ( ! $this->_default_where_conditions_strategy) {
477 477
 			//nothing was set during child constructor, so set default
478 478
 			$this->_default_where_conditions_strategy = new EE_Default_Where_Conditions();
479 479
 		}
@@ -481,15 +481,15 @@  discard block
 block discarded – undo
481 481
 
482 482
 		//if the cap slug hasn't been set, and we haven't set it to false on purpose
483 483
 		//to indicate to NOT set it, set it to the logical default
484
-		if( $this->_caps_slug === null ) {
485
-			EE_Registry::instance()->load_helper( 'Inflector' );
486
-			$this->_caps_slug = EEH_Inflector::pluralize_and_lower( $this->get_this_model_name() );
484
+		if ($this->_caps_slug === null) {
485
+			EE_Registry::instance()->load_helper('Inflector');
486
+			$this->_caps_slug = EEH_Inflector::pluralize_and_lower($this->get_this_model_name());
487 487
 		}
488 488
 		//initialize the standard cap restriction generators if none were specified by the child constructor
489
-		if( $this->_cap_restriction_generators !== false ){
490
-			foreach( $this->cap_contexts_to_cap_action_map() as $cap_context => $action ){
491
-				if( ! isset( $this->_cap_restriction_generators[ $cap_context ] ) ) {
492
-					$this->_cap_restriction_generators[ $cap_context ] = apply_filters(
489
+		if ($this->_cap_restriction_generators !== false) {
490
+			foreach ($this->cap_contexts_to_cap_action_map() as $cap_context => $action) {
491
+				if ( ! isset($this->_cap_restriction_generators[$cap_context])) {
492
+					$this->_cap_restriction_generators[$cap_context] = apply_filters(
493 493
 						'FHEE__EEM_Base___construct__standard_cap_restriction_generator',
494 494
 						new EE_Restriction_Generator_Protected(),
495 495
 						$cap_context,
@@ -499,23 +499,23 @@  discard block
 block discarded – undo
499 499
 			}
500 500
 		}
501 501
 		//if there are cap restriction generators, use them to make the default cap restrictions
502
-		if( $this->_cap_restriction_generators !== false ){
503
-			foreach( $this->_cap_restriction_generators as $context => $generator_object ) {
504
-				if( ! $generator_object ){
502
+		if ($this->_cap_restriction_generators !== false) {
503
+			foreach ($this->_cap_restriction_generators as $context => $generator_object) {
504
+				if ( ! $generator_object) {
505 505
 					continue;
506 506
 				}
507
-				if( ! $generator_object instanceof EE_Restriction_Generator_Base ){
507
+				if ( ! $generator_object instanceof EE_Restriction_Generator_Base) {
508 508
 					throw new EE_Error(
509 509
 						sprintf(
510
-							__( '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' ),
510
+							__('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'),
511 511
 							$context,
512 512
 							$this->get_this_model_name()
513 513
 						)
514 514
 					);
515 515
 				}
516
-				$action = $this->cap_action_for_context( $context );
517
-				if( ! $generator_object->construction_finalized() ){
518
-					$generator_object->_construct_finalize( $this, $action );
516
+				$action = $this->cap_action_for_context($context);
517
+				if ( ! $generator_object->construction_finalized()) {
518
+					$generator_object->_construct_finalize($this, $action);
519 519
 				}
520 520
 
521 521
 			}
@@ -529,11 +529,11 @@  discard block
 block discarded – undo
529 529
 	 * @param string $context one of EEM_Base::valid_cap_contexts()
530 530
 	 * @return EE_Default_Where_Conditions[]
531 531
 	 */
532
-	protected function _generate_cap_restrictions( $context ){
533
-		if( isset( $this->_cap_restriction_generators[ $context ] ) &&
534
-				$this->_cap_restriction_generators[ $context ] instanceof EE_Restriction_Generator_Base ) {
535
-			return $this->_cap_restriction_generators[ $context ]->generate_restrictions();
536
-		}else{
532
+	protected function _generate_cap_restrictions($context) {
533
+		if (isset($this->_cap_restriction_generators[$context]) &&
534
+				$this->_cap_restriction_generators[$context] instanceof EE_Restriction_Generator_Base) {
535
+			return $this->_cap_restriction_generators[$context]->generate_restrictions();
536
+		} else {
537 537
 			return array();
538 538
 		}
539 539
 }
@@ -546,16 +546,16 @@  discard block
 block discarded – undo
546 546
 	 *		@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)
547 547
 	 *		@return static (as in the concrete child class)
548 548
 	 */
549
-	public static function instance( $timezone = NULL ){
549
+	public static function instance($timezone = NULL) {
550 550
 
551 551
 		// check if instance of Espresso_model already exists
552 552
 		if ( ! static::$_instance instanceof static) {
553 553
 			// instantiate Espresso_model
554
-			static::$_instance = new static( $timezone );
554
+			static::$_instance = new static($timezone);
555 555
 		}
556 556
 
557 557
 		//we might have a timezone set, let set_timezone decide what to do with it
558
-		static::$_instance->set_timezone( $timezone );
558
+		static::$_instance->set_timezone($timezone);
559 559
 
560 560
 		// Espresso_model object
561 561
 		return static::$_instance;
@@ -568,11 +568,11 @@  discard block
 block discarded – undo
568 568
 	 * @param null | string $timezone
569 569
 	 * @return static
570 570
 	 */
571
-	public static function reset(  $timezone = NULL ){
572
-		if ( ! is_null( static::$_instance ) ) {
571
+	public static function reset($timezone = NULL) {
572
+		if ( ! is_null(static::$_instance)) {
573 573
 			static::$_instance = null;
574 574
 
575
-			return self::instance( $timezone );
575
+			return self::instance($timezone);
576 576
 		}
577 577
 		return null;
578 578
 	}
@@ -583,15 +583,15 @@  discard block
 block discarded – undo
583 583
 	 * @param  boolean $translated return localized strings or JUST the array.
584 584
 	 * @return array
585 585
 	 */
586
-	 public function status_array( $translated = FALSE ) {
587
-	 	if ( !array_key_exists('Status', $this->_model_relations ) )
586
+	 public function status_array($translated = FALSE) {
587
+	 	if ( ! array_key_exists('Status', $this->_model_relations))
588 588
 	 		return array();
589 589
 	 	$model_name = $this->get_this_model_name();
590
-	 	$status_type = str_replace(' ', '_', strtolower( str_replace('_', ' ', $model_name) ) );
591
-	 	$stati = EEM_Status::instance()->get_all(array(array('STS_type' => $status_type) ) );
590
+	 	$status_type = str_replace(' ', '_', strtolower(str_replace('_', ' ', $model_name)));
591
+	 	$stati = EEM_Status::instance()->get_all(array(array('STS_type' => $status_type)));
592 592
 	 	$status_array = array();
593
-	 	foreach ( $stati as $status ) {
594
-            $status_array[ $status->ID() ] = $status->get('STS_code');
593
+	 	foreach ($stati as $status) {
594
+            $status_array[$status->ID()] = $status->get('STS_code');
595 595
         }
596 596
         return $translated ? EEM_Status::instance()->localized_status($status_array, FALSE, 'sentence') : $status_array;
597 597
     }
@@ -774,7 +774,7 @@  discard block
 block discarded – undo
774 774
 	 *			'order_by'=>array('ANS_value'=>'ASC')
775 775
 	 *		));
776 776
 	 */
777
-	function get_all($query_params = array()){
777
+	function get_all($query_params = array()) {
778 778
 		return $this->_create_objects($this->_get_all_wpdb_results($query_params, ARRAY_A, NULL));
779 779
 	}
780 780
 
@@ -784,10 +784,10 @@  discard block
 block discarded – undo
784 784
 	 * @param array $query_params @see EEM_Base::get_all()
785 785
 	 * @return array like EEM_Base::get_all
786 786
 	 */
787
-	function alter_query_params_to_only_include_mine( $query_params = array() ) {
787
+	function alter_query_params_to_only_include_mine($query_params = array()) {
788 788
 		$wp_user_field_name = $this->wp_user_field_name();
789
-		if( $wp_user_field_name ){
790
-			$query_params[0][ $wp_user_field_name ] = get_current_user_id();
789
+		if ($wp_user_field_name) {
790
+			$query_params[0][$wp_user_field_name] = get_current_user_id();
791 791
 		}
792 792
 		return $query_params;
793 793
 	}
@@ -800,19 +800,19 @@  discard block
 block discarded – undo
800 800
 	 * foreign key to the WP_User table
801 801
 	 */
802 802
 	function wp_user_field_name() {
803
-		try{
804
-			if( ! empty( $this->_model_chain_to_wp_user ) ) {
805
-				$models_to_follow_to_wp_users = explode( '.', $this->_model_chain_to_wp_user );
806
-				$last_model_name = end( $models_to_follow_to_wp_users );
807
-				$model_with_fk_to_wp_users = EE_Registry::instance()->load_model( $last_model_name );
808
-				$model_chain_to_wp_user = $this->_model_chain_to_wp_user . '.';
809
-			}else{
803
+		try {
804
+			if ( ! empty($this->_model_chain_to_wp_user)) {
805
+				$models_to_follow_to_wp_users = explode('.', $this->_model_chain_to_wp_user);
806
+				$last_model_name = end($models_to_follow_to_wp_users);
807
+				$model_with_fk_to_wp_users = EE_Registry::instance()->load_model($last_model_name);
808
+				$model_chain_to_wp_user = $this->_model_chain_to_wp_user.'.';
809
+			} else {
810 810
 				$model_with_fk_to_wp_users = $this;
811 811
 				$model_chain_to_wp_user = '';
812 812
 			}
813
-			$wp_user_field = $model_with_fk_to_wp_users->get_foreign_key_to( 'WP_User' );
814
-			return $model_chain_to_wp_user . $wp_user_field->get_name();
815
-		}catch( EE_Error $e ) {
813
+			$wp_user_field = $model_with_fk_to_wp_users->get_foreign_key_to('WP_User');
814
+			return $model_chain_to_wp_user.$wp_user_field->get_name();
815
+		} catch (EE_Error $e) {
816 816
 			return false;
817 817
 		}
818 818
 	}
@@ -826,7 +826,7 @@  discard block
 block discarded – undo
826 826
 	 * (or transiently-related model)
827 827
 	 * @return string
828 828
 	 */
829
-	public function model_chain_to_wp_user(){
829
+	public function model_chain_to_wp_user() {
830 830
 		return $this->_model_chain_to_wp_user;
831 831
 	}
832 832
 
@@ -838,13 +838,13 @@  discard block
 block discarded – undo
838 838
 	 * @return boolean
839 839
 	 */
840 840
 	public function is_owned() {
841
-		if( $this->model_chain_to_wp_user() ){
841
+		if ($this->model_chain_to_wp_user()) {
842 842
 			return true;
843
-		}else{
844
-			try{
845
-				$this->get_foreign_key_to( 'WP_User' );
843
+		} else {
844
+			try {
845
+				$this->get_foreign_key_to('WP_User');
846 846
 				return true;
847
-			}catch( EE_Error $e ){
847
+			} catch (EE_Error $e) {
848 848
 				return false;
849 849
 			}
850 850
 		}
@@ -863,21 +863,21 @@  discard block
 block discarded – undo
863 863
 	 * and 1 is the data type. Eg, array('count'=>array('COUNT(REG_ID)','%d'))
864 864
 	 * @return array | stdClass[] like results of $wpdb->get_results($sql,OBJECT), (ie, output type is OBJECT)
865 865
 	 */
866
-	protected function  _get_all_wpdb_results($query_params = array(), $output = ARRAY_A, $columns_to_select = null){
866
+	protected function  _get_all_wpdb_results($query_params = array(), $output = ARRAY_A, $columns_to_select = null) {
867 867
 		//remember the custom selections, if any
868
-		if(is_array($columns_to_select)){
868
+		if (is_array($columns_to_select)) {
869 869
 			$this->_custom_selections = $columns_to_select;
870
-		}elseif(is_string($columns_to_select)){
870
+		}elseif (is_string($columns_to_select)) {
871 871
 			$this->_custom_selections = array($this->_custom_selections);
872
-		}else{
872
+		} else {
873 873
 			$this->_custom_selections = array();
874 874
 		}
875 875
 
876 876
 		$model_query_info = $this->_create_model_query_info_carrier($query_params);
877 877
 		$select_expressions = $columns_to_select ? $this->_construct_select_from_input($columns_to_select) : $this->_construct_default_select_sql($model_query_info);
878
-		$SQL ="SELECT $select_expressions ".$this->_construct_2nd_half_of_select_query($model_query_info);
878
+		$SQL = "SELECT $select_expressions ".$this->_construct_2nd_half_of_select_query($model_query_info);
879 879
 //		echo "sql:$SQL";
880
-		$results =  $this->_do_wpdb_query( 'get_results', array($SQL, $output ) );// $wpdb->get_results($SQL, $output);
880
+		$results = $this->_do_wpdb_query('get_results', array($SQL, $output)); // $wpdb->get_results($SQL, $output);
881 881
 		return $results;
882 882
 	}
883 883
 
@@ -895,7 +895,7 @@  discard block
 block discarded – undo
895 895
 	 * and 1 is the data type. Eg, array('count'=>array('COUNT(REG_ID)','%d'))
896 896
 	 * @return array|stdClass[] like results of $wpdb->get_results($sql,OBJECT), (ie, output type is OBJECT)
897 897
 	 */
898
-	public function  get_all_wpdb_results($query_params = array(), $output = ARRAY_A, $columns_to_select = null){
898
+	public function  get_all_wpdb_results($query_params = array(), $output = ARRAY_A, $columns_to_select = null) {
899 899
 		return $this->_get_all_wpdb_results($query_params, $output, $columns_to_select);
900 900
 	}
901 901
 
@@ -907,12 +907,12 @@  discard block
 block discarded – undo
907 907
 	 * @throws EE_Error
908 908
 	 * @return string
909 909
 	 */
910
-	private function _construct_select_from_input($columns_to_select){
911
-		if(is_array($columns_to_select)){
910
+	private function _construct_select_from_input($columns_to_select) {
911
+		if (is_array($columns_to_select)) {
912 912
 			$select_sql_array = array();
913 913
 
914
-			foreach($columns_to_select as $alias => $selection_and_datatype){
915
-				if( ! is_array($selection_and_datatype) || ! isset($selection_and_datatype[1])){
914
+			foreach ($columns_to_select as $alias => $selection_and_datatype) {
915
+				if ( ! is_array($selection_and_datatype) || ! isset($selection_and_datatype[1])) {
916 916
 					throw new EE_Error(
917 917
 						sprintf(
918 918
 							__(
@@ -924,24 +924,24 @@  discard block
 block discarded – undo
924 924
 						)
925 925
 					);
926 926
 				}
927
-				if( ! in_array( $selection_and_datatype[1],$this->_valid_wpdb_data_types)){
927
+				if ( ! in_array($selection_and_datatype[1], $this->_valid_wpdb_data_types)) {
928 928
 					throw new EE_Error(
929 929
 						sprintf(
930 930
 							__(
931 931
 								"Datatype %s (for selection '%s' and alias '%s') is not a valid wpdb datatype (eg %%s)",
932 932
 								"event_espresso"
933 933
 							),
934
-							$selection_and_datatype[ 1 ],
935
-							$selection_and_datatype[ 0 ],
934
+							$selection_and_datatype[1],
935
+							$selection_and_datatype[0],
936 936
 							$alias,
937
-							implode( ",", $this->_valid_wpdb_data_types )
937
+							implode(",", $this->_valid_wpdb_data_types)
938 938
 						)
939 939
 					);
940 940
 				}
941 941
 				$select_sql_array[] = "{$selection_and_datatype[0]} AS $alias";
942 942
 			}
943
-			$columns_to_select_string = implode(", ",$select_sql_array);
944
-		}else{
943
+			$columns_to_select_string = implode(", ", $select_sql_array);
944
+		} else {
945 945
 			$columns_to_select_string = $columns_to_select;
946 946
 		}
947 947
 		return $columns_to_select_string;
@@ -954,7 +954,7 @@  discard block
 block discarded – undo
954 954
 	 * Convenient wrapper for getting the primary key field's name. Eg, on Registration, this would be 'REG_ID'
955 955
 	 * @return string
956 956
 	 */
957
-	function primary_key_name(){
957
+	function primary_key_name() {
958 958
 		return $this->get_primary_key_field()->get_name();
959 959
 	}
960 960
 
@@ -966,15 +966,15 @@  discard block
 block discarded – undo
966 966
 	 * @param mixed $id int or string, depending on the type of the model's primary key
967 967
 	 * @return EE_Base_Class
968 968
 	 */
969
-	function get_one_by_ID($id){
970
-		if( $this->get_from_entity_map( $id ) ){
971
-			return $this->get_from_entity_map( $id );
972
-		}elseif( $this->has_primary_key_field ( ) ) {
969
+	function get_one_by_ID($id) {
970
+		if ($this->get_from_entity_map($id)) {
971
+			return $this->get_from_entity_map($id);
972
+		}elseif ($this->has_primary_key_field( )) {
973 973
 			$primary_key_name = $this->get_primary_key_field()->get_name();
974 974
 			return $this->get_one(array(array($primary_key_name => $id)));
975
-		}else{
975
+		} else {
976 976
 			//no primary key, so the $id must be from the get_index_primary_key_string()
977
-			return $this->get_one( array( $this->parse_index_primary_key_string( $id ) ) );
977
+			return $this->get_one(array($this->parse_index_primary_key_string($id)));
978 978
 		}
979 979
 	}
980 980
 
@@ -985,16 +985,16 @@  discard block
 block discarded – undo
985 985
 	 * @param array $query_params like EEM_Base's $query_params variable.
986 986
 	 * @return EE_Base_Class | NULL
987 987
 	 */
988
-	function get_one($query_params = array()){
989
-		if( ! is_array( $query_params ) ){
990
-			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' );
988
+	function get_one($query_params = array()) {
989
+		if ( ! is_array($query_params)) {
990
+			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');
991 991
 			$query_params = array();
992 992
 		}
993 993
 		$query_params['limit'] = 1;
994 994
 		$items = $this->get_all($query_params);
995
-		if(empty($items)){
995
+		if (empty($items)) {
996 996
 			return null;
997
-		}else{
997
+		} else {
998 998
 			return array_shift($items);
999 999
 		}
1000 1000
 	}
@@ -1018,8 +1018,8 @@  discard block
 block discarded – undo
1018 1018
 	 *
1019 1019
 	 * @return EE_Base_Class[]|array
1020 1020
 	 */
1021
-	public function next_x( $current_field_value, $field_to_order_by = null, $limit = 1, $query_params = array(), $columns_to_select = null ) {
1022
-		return $this->_get_consecutive( $current_field_value, '>', $field_to_order_by, $limit, $query_params, $columns_to_select );
1021
+	public function next_x($current_field_value, $field_to_order_by = null, $limit = 1, $query_params = array(), $columns_to_select = null) {
1022
+		return $this->_get_consecutive($current_field_value, '>', $field_to_order_by, $limit, $query_params, $columns_to_select);
1023 1023
 	}
1024 1024
 
1025 1025
 
@@ -1042,8 +1042,8 @@  discard block
 block discarded – undo
1042 1042
 	 *
1043 1043
 	 * @return EE_Base_Class[]|array
1044 1044
 	 */
1045
-	public function previous_x( $current_field_value, $field_to_order_by = null, $limit = 1, $query_params = array(), $columns_to_select = null ) {
1046
-		return $this->_get_consecutive( $current_field_value, '<', $field_to_order_by, $limit, $query_params, $columns_to_select );
1045
+	public function previous_x($current_field_value, $field_to_order_by = null, $limit = 1, $query_params = array(), $columns_to_select = null) {
1046
+		return $this->_get_consecutive($current_field_value, '<', $field_to_order_by, $limit, $query_params, $columns_to_select);
1047 1047
 	}
1048 1048
 
1049 1049
 
@@ -1065,9 +1065,9 @@  discard block
 block discarded – undo
1065 1065
 	 *
1066 1066
 	 * @return EE_Base_Class|null|array()
1067 1067
 	 */
1068
-	public function next( $current_field_value, $field_to_order_by = null, $query_params = array(), $columns_to_select = null ) {
1069
-		$results = $this->_get_consecutive( $current_field_value, '>', $field_to_order_by, 1, $query_params, $columns_to_select );
1070
-		return empty( $results ) ? null : reset( $results );
1068
+	public function next($current_field_value, $field_to_order_by = null, $query_params = array(), $columns_to_select = null) {
1069
+		$results = $this->_get_consecutive($current_field_value, '>', $field_to_order_by, 1, $query_params, $columns_to_select);
1070
+		return empty($results) ? null : reset($results);
1071 1071
 	}
1072 1072
 
1073 1073
 
@@ -1089,9 +1089,9 @@  discard block
 block discarded – undo
1089 1089
 	 *
1090 1090
 	 * @return EE_Base_Class|null|array()
1091 1091
 	 */
1092
-	public function previous( $current_field_value, $field_to_order_by = null, $query_params = array(), $columns_to_select = null ) {
1093
-		$results = $this->_get_consecutive( $current_field_value, '<', $field_to_order_by, 1, $query_params, $columns_to_select );
1094
-		return empty( $results ) ? null : reset( $results );
1092
+	public function previous($current_field_value, $field_to_order_by = null, $query_params = array(), $columns_to_select = null) {
1093
+		$results = $this->_get_consecutive($current_field_value, '<', $field_to_order_by, 1, $query_params, $columns_to_select);
1094
+		return empty($results) ? null : reset($results);
1095 1095
 	}
1096 1096
 
1097 1097
 
@@ -1117,40 +1117,40 @@  discard block
 block discarded – undo
1117 1117
 	 * @return EE_Base_Class[]|array
1118 1118
 	 * @throws EE_Error
1119 1119
 	 */
1120
-	protected function _get_consecutive( $current_field_value, $operand = '>', $field_to_order_by = null, $limit = 1, $query_params = array(), $columns_to_select = null ) {
1120
+	protected function _get_consecutive($current_field_value, $operand = '>', $field_to_order_by = null, $limit = 1, $query_params = array(), $columns_to_select = null) {
1121 1121
 		//if $field_to_order_by is empty then let's assume we're ordering by the primary key.
1122
-		if ( empty( $field_to_order_by ) ) {
1123
-			if ( $this->has_primary_key_field() ) {
1122
+		if (empty($field_to_order_by)) {
1123
+			if ($this->has_primary_key_field()) {
1124 1124
 				$field_to_order_by = $this->get_primary_key_field()->get_name();
1125 1125
 			} else {
1126 1126
 
1127
-				if ( WP_DEBUG ) {
1128
-					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' ) );
1127
+				if (WP_DEBUG) {
1128
+					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'));
1129 1129
 				}
1130
-				EE_Error::add_error( __('There was an error with the query.', 'event_espresso') );
1130
+				EE_Error::add_error(__('There was an error with the query.', 'event_espresso'));
1131 1131
 				return array();
1132 1132
 			}
1133 1133
 		}
1134 1134
 
1135
-		if( ! is_array( $query_params ) ){
1136
-			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' );
1135
+		if ( ! is_array($query_params)) {
1136
+			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');
1137 1137
 			$query_params = array();
1138 1138
 		}
1139 1139
 
1140 1140
 		//let's add the where query param for consecutive look up.
1141
-		$query_params[0][ $field_to_order_by ] = array( $operand, $current_field_value );
1141
+		$query_params[0][$field_to_order_by] = array($operand, $current_field_value);
1142 1142
 		$query_params['limit'] = $limit;
1143 1143
 
1144 1144
 		//set direction
1145
-		$incoming_orderby = isset( $query_params['order_by'] ) ? $query_params['order_by'] : array();
1146
-		$query_params['order_by'] = $operand == '>' ? array( $field_to_order_by => 'ASC' ) + $incoming_orderby : array( $field_to_order_by => 'DESC') + $incoming_orderby;
1145
+		$incoming_orderby = isset($query_params['order_by']) ? $query_params['order_by'] : array();
1146
+		$query_params['order_by'] = $operand == '>' ? array($field_to_order_by => 'ASC') + $incoming_orderby : array($field_to_order_by => 'DESC') + $incoming_orderby;
1147 1147
 
1148 1148
 		//if $columns_to_select is empty then that means we're returning EE_Base_Class objects
1149
-		if ( empty( $columns_to_select ) ) {
1150
-			return $this->get_all( $query_params );
1149
+		if (empty($columns_to_select)) {
1150
+			return $this->get_all($query_params);
1151 1151
 		} else {
1152 1152
 			//getting just the fields
1153
-			return $this->_get_all_wpdb_results( $query_params, ARRAY_A, $columns_to_select );
1153
+			return $this->_get_all_wpdb_results($query_params, ARRAY_A, $columns_to_select);
1154 1154
 		}
1155 1155
 	}
1156 1156
 
@@ -1161,18 +1161,18 @@  discard block
 block discarded – undo
1161 1161
 	 * This sets the _timezone property after model object has been instantiated.
1162 1162
 	 * @param null | string $timezone valid PHP DateTimeZone timezone string
1163 1163
 	 */
1164
-	public function set_timezone( $timezone ) {
1165
-		if ( $timezone !== null ) {
1164
+	public function set_timezone($timezone) {
1165
+		if ($timezone !== null) {
1166 1166
 			$this->_timezone = $timezone;
1167 1167
 		}
1168 1168
 		//note we need to loop through relations and set the timezone on those objects as well.
1169
-		foreach ( $this->_model_relations as $relation ) {
1170
-			$relation->set_timezone( $timezone );
1169
+		foreach ($this->_model_relations as $relation) {
1170
+			$relation->set_timezone($timezone);
1171 1171
 		}
1172 1172
 		//and finally we do the same for any datetime fields
1173
-		foreach ( $this->_fields as $field ) {
1174
-			if ( $field instanceof EE_Datetime_Field ) {
1175
-				$field->set_timezone( $timezone );
1173
+		foreach ($this->_fields as $field) {
1174
+			if ($field instanceof EE_Datetime_Field) {
1175
+				$field->set_timezone($timezone);
1176 1176
 			}
1177 1177
 		}
1178 1178
 	}
@@ -1187,9 +1187,9 @@  discard block
 block discarded – undo
1187 1187
 	 */
1188 1188
 	public function get_timezone() {
1189 1189
 		//first validate if timezone is set.  If not, then let's set it be whatever is set on the model fields.
1190
-		if ( empty( $this->_timezone ) ) {
1191
-			foreach( $this->_fields as $field ) {
1192
-				if ( $field instanceof EE_Datetime_Field ) {
1190
+		if (empty($this->_timezone)) {
1191
+			foreach ($this->_fields as $field) {
1192
+				if ($field instanceof EE_Datetime_Field) {
1193 1193
 					$this->set_timezone($field->get_timezone());
1194 1194
 					break;
1195 1195
 				}
@@ -1197,9 +1197,9 @@  discard block
 block discarded – undo
1197 1197
 		}
1198 1198
 
1199 1199
 		//if timezone STILL empty then return the default timezone for the site.
1200
-		if ( empty( $this->_timezone ) ) {
1201
-			EE_Registry::instance()->load_helper( 'DTT_Helper' );
1202
-			$this->set_timezone( EEH_DTT_Helper::get_timezone() );
1200
+		if (empty($this->_timezone)) {
1201
+			EE_Registry::instance()->load_helper('DTT_Helper');
1202
+			$this->set_timezone(EEH_DTT_Helper::get_timezone());
1203 1203
 		}
1204 1204
 		return $this->_timezone;
1205 1205
 	}
@@ -1217,19 +1217,19 @@  discard block
 block discarded – undo
1217 1217
 	 *
1218 1218
 	 * @return array formats in an array with the date format first, and the time format last.
1219 1219
 	 */
1220
-	public function get_formats_for( $field_name, $pretty = false ) {
1221
-		$field_settings = $this->field_settings_for( $field_name );
1220
+	public function get_formats_for($field_name, $pretty = false) {
1221
+		$field_settings = $this->field_settings_for($field_name);
1222 1222
 
1223 1223
 		//if not a valid EE_Datetime_Field then throw error
1224
-		if ( ! $field_settings instanceof EE_Datetime_Field ) {
1225
-			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 ) );
1224
+		if ( ! $field_settings instanceof EE_Datetime_Field) {
1225
+			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));
1226 1226
 		}
1227 1227
 
1228 1228
 		//while we are here, let's make sure the timezone internally in EEM_Base matches what is stored on
1229 1229
 		//the field.
1230 1230
 		$this->_timezone = $field_settings->get_timezone();
1231 1231
 
1232
-		return array( $field_settings->get_date_format( $pretty ), $field_settings->get_time_format( $pretty ) );
1232
+		return array($field_settings->get_date_format($pretty), $field_settings->get_time_format($pretty));
1233 1233
 	}
1234 1234
 
1235 1235
 
@@ -1253,25 +1253,25 @@  discard block
 block discarded – undo
1253 1253
 	 * @return int|string  If the given field_name is not of the EE_Datetime_Field type, then an EE_Error
1254 1254
 	 *                    	     exception is triggered.
1255 1255
 	 */
1256
-	public function current_time_for_query( $field_name, $timestamp = false, $what = 'both' ) {
1257
-		$formats = $this->get_formats_for( $field_name );
1256
+	public function current_time_for_query($field_name, $timestamp = false, $what = 'both') {
1257
+		$formats = $this->get_formats_for($field_name);
1258 1258
 
1259
-		$DateTime = new DateTime( "now", new DateTimeZone( $this->_timezone ) );
1259
+		$DateTime = new DateTime("now", new DateTimeZone($this->_timezone));
1260 1260
 
1261
-		if ( $timestamp ) {
1262
-			return $DateTime->format( 'U' );
1261
+		if ($timestamp) {
1262
+			return $DateTime->format('U');
1263 1263
 		}
1264 1264
 
1265 1265
 		//not returning timestamp, so return formatted string in timezone.
1266
-		switch( $what ) {
1266
+		switch ($what) {
1267 1267
 			case 'time' :
1268
-				return $DateTime->format( $formats[1] );
1268
+				return $DateTime->format($formats[1]);
1269 1269
 				break;
1270 1270
 			case 'date' :
1271
-				return $DateTime->format( $formats[0] );
1271
+				return $DateTime->format($formats[0]);
1272 1272
 				break;
1273 1273
 			default :
1274
-				return $DateTime->format( implode( ' ', $formats ) );
1274
+				return $DateTime->format(implode(' ', $formats));
1275 1275
 				break;
1276 1276
 		}
1277 1277
 	}
@@ -1295,20 +1295,20 @@  discard block
 block discarded – undo
1295 1295
 	 *                           		'U', this is ignored.
1296 1296
 	 * @return DateTime
1297 1297
 	 */
1298
-	public function convert_datetime_for_query( $field_name, $timestring, $incoming_format, $timezone = '' ) {
1298
+	public function convert_datetime_for_query($field_name, $timestring, $incoming_format, $timezone = '') {
1299 1299
 
1300 1300
 		//just using this to ensure the timezone is set correctly internally
1301
-		$this->get_formats_for( $field_name );
1301
+		$this->get_formats_for($field_name);
1302 1302
 
1303 1303
 		//load EEH_DTT_Helper
1304
-		EE_Registry::instance()->load_helper( 'DTT_Helper' );
1305
-		$set_timezone = empty( $timezone ) ? EEH_DTT_Helper::get_timezone() : $timezone;
1304
+		EE_Registry::instance()->load_helper('DTT_Helper');
1305
+		$set_timezone = empty($timezone) ? EEH_DTT_Helper::get_timezone() : $timezone;
1306 1306
 
1307
-		$incomingDateTime = date_create_from_format( $incoming_format, $timestring, new DateTimeZone( $set_timezone ) );
1308
-		if( $incomingDateTime ) {
1309
-			return $incomingDateTime->setTimeZone( new DateTimeZone( $this->_timezone ) );
1307
+		$incomingDateTime = date_create_from_format($incoming_format, $timestring, new DateTimeZone($set_timezone));
1308
+		if ($incomingDateTime) {
1309
+			return $incomingDateTime->setTimeZone(new DateTimeZone($this->_timezone));
1310 1310
 		} else {
1311
-			return new DateTime( null, new DateTimeZone( $set_timezone ) );
1311
+			return new DateTime(null, new DateTimeZone($set_timezone));
1312 1312
 		}
1313 1313
 	}
1314 1314
 
@@ -1319,7 +1319,7 @@  discard block
 block discarded – undo
1319 1319
 	 * Gets all the tables comprising this model. Array keys are the table aliases, and values are EE_Table objects
1320 1320
 	 * @return EE_Table_Base[]
1321 1321
 	 */
1322
-	function get_tables(){
1322
+	function get_tables() {
1323 1323
 		return $this->_tables;
1324 1324
 	}
1325 1325
 
@@ -1353,9 +1353,9 @@  discard block
 block discarded – undo
1353 1353
 	 * be aware that model objects being used could get out-of-sync with the database
1354 1354
 	 * @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)
1355 1355
 	 */
1356
-	function update($fields_n_values, $query_params, $keep_model_objs_in_sync = TRUE){
1357
-		if( ! is_array( $query_params ) ){
1358
-			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' );
1356
+	function update($fields_n_values, $query_params, $keep_model_objs_in_sync = TRUE) {
1357
+		if ( ! is_array($query_params)) {
1358
+			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');
1359 1359
 			$query_params = array();
1360 1360
 		}
1361 1361
 		/**
@@ -1365,7 +1365,7 @@  discard block
 block discarded – undo
1365 1365
 		 * @param array $fields_n_values the updated fields and their new values
1366 1366
 		 * @param array $query_params @see EEM_Base::get_all()
1367 1367
 		 */
1368
-		do_action( 'AHEE__EEM_Base__update__begin',$this, $fields_n_values, $query_params );
1368
+		do_action('AHEE__EEM_Base__update__begin', $this, $fields_n_values, $query_params);
1369 1369
 		/**
1370 1370
 		 * Filters the fields about to be updated given the query parameters. You can provide the
1371 1371
 		 * $query_params to $this->get_all() to find exactly which records will be updated
@@ -1373,10 +1373,10 @@  discard block
 block discarded – undo
1373 1373
 		 * @param EEM_Base $model the model being queried
1374 1374
 		 * @param array $query_params see EEM_Base::get_all()
1375 1375
 		 */
1376
-		$fields_n_values = apply_filters( 'FHEE__EEM_Base__update__fields_n_values', $fields_n_values, $this, $query_params );
1376
+		$fields_n_values = apply_filters('FHEE__EEM_Base__update__fields_n_values', $fields_n_values, $this, $query_params);
1377 1377
 		//need to verify that, for any entry we want to update, there are entries in each secondary table.
1378 1378
 		//to do that, for each table, verify that it's PK isn't null.
1379
-		$tables= $this->get_tables();
1379
+		$tables = $this->get_tables();
1380 1380
 
1381 1381
 		//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
1382 1382
 		//NOTE: we should make this code more efficient by NOT querying twice
@@ -1386,29 +1386,29 @@  discard block
 block discarded – undo
1386 1386
 			//we want to make sure the default_where strategy is ignored
1387 1387
 			$this->_ignore_where_strategy = TRUE;
1388 1388
 			$wpdb_select_results = $this->_get_all_wpdb_results($query_params);
1389
-			foreach( $wpdb_select_results as $wpdb_result ){
1389
+			foreach ($wpdb_select_results as $wpdb_result) {
1390 1390
 				// type cast stdClass as array
1391
-				$wpdb_result = (array)$wpdb_result;
1391
+				$wpdb_result = (array) $wpdb_result;
1392 1392
 				//get the model object's PK, as we'll want this if we need to insert a row into secondary tables
1393
-				if( $this->has_primary_key_field() ){
1394
-					$main_table_pk_value = $wpdb_result[ $this->get_primary_key_field()->get_qualified_column() ];
1395
-				}else{
1393
+				if ($this->has_primary_key_field()) {
1394
+					$main_table_pk_value = $wpdb_result[$this->get_primary_key_field()->get_qualified_column()];
1395
+				} else {
1396 1396
 					//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)
1397 1397
 					$main_table_pk_value = null;
1398 1398
 				}
1399 1399
 				//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
1400 1400
 				//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
1401
-				if(count($tables) > 1){
1401
+				if (count($tables) > 1) {
1402 1402
 					//foreach matching row in the DB, ensure that each table's PK isn't null. If so, there must not be an entry
1403 1403
 					//in that table, and so we'll want to insert one
1404
-					foreach($tables as $table_obj){
1404
+					foreach ($tables as $table_obj) {
1405 1405
 						$this_table_pk_column = $table_obj->get_fully_qualified_pk_column();
1406 1406
 						//if there is no private key for this table on the results, it means there's no entry
1407 1407
 						//in this table, right? so insert a row in the current table, using any fields available
1408
-						if( ! ( array_key_exists( $this_table_pk_column, $wpdb_result) && $wpdb_result[ $this_table_pk_column ] )){
1408
+						if ( ! (array_key_exists($this_table_pk_column, $wpdb_result) && $wpdb_result[$this_table_pk_column])) {
1409 1409
 							$success = $this->_insert_into_specific_table($table_obj, $fields_n_values, $main_table_pk_value);
1410 1410
 							//if we died here, report the error
1411
-							if( ! $success ) {
1411
+							if ( ! $success) {
1412 1412
 								return false;
1413 1413
 							}
1414 1414
 						}
@@ -1428,44 +1428,44 @@  discard block
 block discarded – undo
1428 1428
 		//if this wasn't called from a model object (to update itself)
1429 1429
 		//then we want to make sure we keep all the existing
1430 1430
 		//model objects in sync with the db
1431
-		if( $keep_model_objs_in_sync && ! $this->_values_already_prepared_by_model_object ){
1432
-			if( $this->has_primary_key_field() ){
1433
-				$model_objs_affected_ids = $this->get_col( $query_params );
1434
-			}else{
1431
+		if ($keep_model_objs_in_sync && ! $this->_values_already_prepared_by_model_object) {
1432
+			if ($this->has_primary_key_field()) {
1433
+				$model_objs_affected_ids = $this->get_col($query_params);
1434
+			} else {
1435 1435
 				//we need to select a bunch of columns and then combine them into the the "index primary key string"s
1436
-				$models_affected_key_columns = $this->_get_all_wpdb_results($query_params, ARRAY_A );
1436
+				$models_affected_key_columns = $this->_get_all_wpdb_results($query_params, ARRAY_A);
1437 1437
 				$model_objs_affected_ids = array();
1438
-				foreach( $models_affected_key_columns as $row ){
1439
-					$combined_index_key = $this->get_index_primary_key_string( $row );
1440
-					$model_objs_affected_ids[ $combined_index_key ] = $combined_index_key;
1438
+				foreach ($models_affected_key_columns as $row) {
1439
+					$combined_index_key = $this->get_index_primary_key_string($row);
1440
+					$model_objs_affected_ids[$combined_index_key] = $combined_index_key;
1441 1441
 				}
1442 1442
 
1443 1443
 			}
1444 1444
 
1445
-			if( ! $model_objs_affected_ids ){
1445
+			if ( ! $model_objs_affected_ids) {
1446 1446
 				//wait wait wait- if nothing was affected let's stop here
1447 1447
 				return 0;
1448 1448
 			}
1449
-			foreach( $model_objs_affected_ids as $id ){
1450
-				$model_obj_in_entity_map = $this->get_from_entity_map( $id );
1451
-				if( $model_obj_in_entity_map ){
1452
-					foreach( $fields_n_values as $field => $new_value ){
1453
-						$model_obj_in_entity_map->set( $field, $new_value );
1449
+			foreach ($model_objs_affected_ids as $id) {
1450
+				$model_obj_in_entity_map = $this->get_from_entity_map($id);
1451
+				if ($model_obj_in_entity_map) {
1452
+					foreach ($fields_n_values as $field => $new_value) {
1453
+						$model_obj_in_entity_map->set($field, $new_value);
1454 1454
 					}
1455 1455
 				}
1456 1456
 			}
1457 1457
 			//if there is a primary key on this model, we can now do a slight optimization
1458
-			if( $this->has_primary_key_field() ){
1458
+			if ($this->has_primary_key_field()) {
1459 1459
 				//we already know what we want to update. So let's make the query simpler so it's a little more efficient
1460 1460
 				$query_params = array(
1461
-					array( $this->primary_key_name() => array( 'IN', $model_objs_affected_ids ) ),
1462
-					'limit' => count( $model_objs_affected_ids ), 'default_where_conditions' => 'none' );
1461
+					array($this->primary_key_name() => array('IN', $model_objs_affected_ids)),
1462
+					'limit' => count($model_objs_affected_ids), 'default_where_conditions' => 'none' );
1463 1463
 			}
1464 1464
 		}
1465 1465
 
1466
-		$model_query_info = $this->_create_model_query_info_carrier( $query_params );
1467
-		$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.
1468
-		$rows_affected = $this->_do_wpdb_query('query', array( $SQL ) );
1466
+		$model_query_info = $this->_create_model_query_info_carrier($query_params);
1467
+		$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.
1468
+		$rows_affected = $this->_do_wpdb_query('query', array($SQL));
1469 1469
 		/**
1470 1470
 		 * Action called after a model update call has been made.
1471 1471
 		 *
@@ -1474,8 +1474,8 @@  discard block
 block discarded – undo
1474 1474
 		 * @param array $query_params @see EEM_Base::get_all()
1475 1475
 		 * @param int $rows_affected
1476 1476
 		 */
1477
-		do_action( 'AHEE__EEM_Base__update__end',$this, $fields_n_values, $query_params, $rows_affected );
1478
-		return $rows_affected;//how many supposedly got updated
1477
+		do_action('AHEE__EEM_Base__update__end', $this, $fields_n_values, $query_params, $rows_affected);
1478
+		return $rows_affected; //how many supposedly got updated
1479 1479
 	}
1480 1480
 
1481 1481
 	/**
@@ -1487,22 +1487,22 @@  discard block
 block discarded – undo
1487 1487
 	 * @param string $field_to_select
1488 1488
 	 * @return array just like $wpdb->get_col()
1489 1489
 	 */
1490
-	public function get_col( $query_params  = array(), $field_to_select = NULL ){
1490
+	public function get_col($query_params = array(), $field_to_select = NULL) {
1491 1491
 
1492
-		if( $field_to_select ){
1493
-			$field = $this->field_settings_for( $field_to_select );
1494
-		}elseif( $this->has_primary_key_field ( ) ){
1492
+		if ($field_to_select) {
1493
+			$field = $this->field_settings_for($field_to_select);
1494
+		}elseif ($this->has_primary_key_field( )) {
1495 1495
 			$field = $this->get_primary_key_field();
1496
-		}else{
1496
+		} else {
1497 1497
 			//no primary key, just grab the first column
1498
-			$field = reset( $this->field_settings());
1498
+			$field = reset($this->field_settings());
1499 1499
 		}
1500 1500
 
1501 1501
 
1502 1502
 		$model_query_info = $this->_create_model_query_info_carrier($query_params);
1503 1503
 		$select_expressions = $field->get_qualified_column();
1504
-		$SQL ="SELECT $select_expressions ".$this->_construct_2nd_half_of_select_query($model_query_info);
1505
-		$results =  $this->_do_wpdb_query('get_col', array( $SQL ) );
1504
+		$SQL = "SELECT $select_expressions ".$this->_construct_2nd_half_of_select_query($model_query_info);
1505
+		$results = $this->_do_wpdb_query('get_col', array($SQL));
1506 1506
 		return $results;
1507 1507
 	}
1508 1508
 
@@ -1512,12 +1512,12 @@  discard block
 block discarded – undo
1512 1512
 	 * @param string $field_to_select @see EEM_Base::get_col()
1513 1513
 	 * @return string
1514 1514
 	 */
1515
-	public function get_var( $query_params = array(), $field_to_select = NULL ) {
1516
-		$query_params[ 'limit' ] = 1;
1517
-		$col = $this->get_col( $query_params, $field_to_select );
1518
-		if( ! empty( $col ) ) {
1519
-			return reset( $col );
1520
-		}else{
1515
+	public function get_var($query_params = array(), $field_to_select = NULL) {
1516
+		$query_params['limit'] = 1;
1517
+		$col = $this->get_col($query_params, $field_to_select);
1518
+		if ( ! empty($col)) {
1519
+			return reset($col);
1520
+		} else {
1521 1521
 			return NULL;
1522 1522
 		}
1523 1523
 	}
@@ -1531,19 +1531,19 @@  discard block
 block discarded – undo
1531 1531
 	 * @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
1532 1532
 	 * @return string of SQL
1533 1533
 	 */
1534
-	function _construct_update_sql($fields_n_values){
1534
+	function _construct_update_sql($fields_n_values) {
1535 1535
 		/** @type WPDB $wpdb */
1536 1536
 		global $wpdb;
1537 1537
 		$cols_n_values = array();
1538
-		foreach($fields_n_values as $field_name => $value){
1538
+		foreach ($fields_n_values as $field_name => $value) {
1539 1539
 			$field_obj = $this->field_settings_for($field_name);
1540 1540
 			//if the value is NULL, we want to assign the value to that.
1541 1541
 			//wpdb->prepare doesn't really handle that properly
1542
-			$prepared_value = $this->_prepare_value_or_use_default( $field_obj, $fields_n_values );
1543
-			$value_sql = $prepared_value===NULL ? 'NULL' : $wpdb->prepare( $field_obj->get_wpdb_data_type(), $prepared_value );
1542
+			$prepared_value = $this->_prepare_value_or_use_default($field_obj, $fields_n_values);
1543
+			$value_sql = $prepared_value === NULL ? 'NULL' : $wpdb->prepare($field_obj->get_wpdb_data_type(), $prepared_value);
1544 1544
 			$cols_n_values[] = $field_obj->get_qualified_column()."=".$value_sql;
1545 1545
 		}
1546
-		return implode(",",$cols_n_values);
1546
+		return implode(",", $cols_n_values);
1547 1547
 
1548 1548
 	}
1549 1549
 
@@ -1558,11 +1558,11 @@  discard block
 block discarded – undo
1558 1558
 	 * which may depend on it. Its generally advisable to always leave this as TRUE, otherwise you could easily corrupt your DB
1559 1559
 	 * @return boolean whether the row got deleted or not
1560 1560
 	 */
1561
-	public function delete_by_ID( $id, $allow_blocking = true ){
1562
-		return $this->delete( array(
1563
-			array( $this->get_primary_key_field()->get_name() => $id ),
1561
+	public function delete_by_ID($id, $allow_blocking = true) {
1562
+		return $this->delete(array(
1563
+			array($this->get_primary_key_field()->get_name() => $id),
1564 1564
 			'limit' 	=> 1
1565
-		), $allow_blocking );
1565
+		), $allow_blocking);
1566 1566
 	}
1567 1567
 
1568 1568
 
@@ -1577,7 +1577,7 @@  discard block
 block discarded – undo
1577 1577
 	 * which may depend on it. Its generally advisable to always leave this as TRUE, otherwise you could easily corrupt your DB
1578 1578
 	 * @return int how many rows got deleted
1579 1579
 	 */
1580
-	function delete($query_params,$allow_blocking = true){
1580
+	function delete($query_params, $allow_blocking = true) {
1581 1581
 		/**
1582 1582
 		 * Action called just before performing a real deletion query. You can use the
1583 1583
 		 * model and its $query_params to find exactly which items will be deleted
@@ -1586,34 +1586,34 @@  discard block
 block discarded – undo
1586 1586
 		 * @param boolean $allow_blocking whether or not to allow related model objects
1587 1587
 		 * to block (prevent) this deletion
1588 1588
 		 */
1589
-		do_action( 'AHEE__EEM_Base__delete__begin', $this, $query_params, $allow_blocking );
1589
+		do_action('AHEE__EEM_Base__delete__begin', $this, $query_params, $allow_blocking);
1590 1590
 		//some MySQL databases may be running safe mode, which may restrict
1591 1591
 		//deletion if there is no KEY column used in the WHERE statement of a deletion.
1592 1592
 		//to get around this, we first do a SELECT, get all the IDs, and then run another query
1593 1593
 		//to delete them
1594 1594
 		$items_for_deletion = $this->_get_all_wpdb_results($query_params);
1595
-		$deletion_where = $this->_setup_ids_for_delete( $items_for_deletion, $allow_blocking);
1596
-		if($deletion_where){
1595
+		$deletion_where = $this->_setup_ids_for_delete($items_for_deletion, $allow_blocking);
1596
+		if ($deletion_where) {
1597 1597
 			//echo "objects for deletion:";var_dump($objects_for_deletion);
1598 1598
 			$model_query_info = $this->_create_model_query_info_carrier($query_params);
1599 1599
 			$table_aliases = array();
1600
-			foreach(array_keys($this->_tables) as $table_alias){
1600
+			foreach (array_keys($this->_tables) as $table_alias) {
1601 1601
 				$table_aliases[] = $table_alias;
1602 1602
 			}
1603
-			$SQL = "DELETE ".implode(", ",$table_aliases)." FROM ".$model_query_info->get_full_join_sql()." WHERE ".$deletion_where;
1603
+			$SQL = "DELETE ".implode(", ", $table_aliases)." FROM ".$model_query_info->get_full_join_sql()." WHERE ".$deletion_where;
1604 1604
 
1605 1605
 			//		/echo "delete sql:$SQL";
1606
-			$rows_deleted = $this->_do_wpdb_query( 'query', array( $SQL ) );
1607
-		}else{
1606
+			$rows_deleted = $this->_do_wpdb_query('query', array($SQL));
1607
+		} else {
1608 1608
 			$rows_deleted = 0;
1609 1609
 		}
1610 1610
 
1611 1611
 		//and lastly make sure those items are removed from the entity map; if they could be put into it at all
1612
-		if( $this->has_primary_key_field() ){
1613
-			foreach($items_for_deletion as $item_for_deletion_row ){
1614
-				$pk_value = $item_for_deletion_row[ $this->get_primary_key_field()->get_qualified_column() ];
1615
-				if( isset( $this->_entity_map[ $pk_value ] ) ){
1616
-					unset( $this->_entity_map[ $pk_value ] );
1612
+		if ($this->has_primary_key_field()) {
1613
+			foreach ($items_for_deletion as $item_for_deletion_row) {
1614
+				$pk_value = $item_for_deletion_row[$this->get_primary_key_field()->get_qualified_column()];
1615
+				if (isset($this->_entity_map[$pk_value])) {
1616
+					unset($this->_entity_map[$pk_value]);
1617 1617
 				}
1618 1618
 			}
1619 1619
 		}
@@ -1625,8 +1625,8 @@  discard block
 block discarded – undo
1625 1625
 		 * @param array $query_params @see EEM_Base::get_all()
1626 1626
 		 * @param int $rows_deleted
1627 1627
 		 */
1628
-		do_action( 'AHEE__EEM_Base__delete__end', $this, $query_params, $rows_deleted );
1629
-		return $rows_deleted;//how many supposedly got deleted
1628
+		do_action('AHEE__EEM_Base__delete__end', $this, $query_params, $rows_deleted);
1629
+		return $rows_deleted; //how many supposedly got deleted
1630 1630
 	}
1631 1631
 
1632 1632
 
@@ -1642,28 +1642,28 @@  discard block
 block discarded – undo
1642 1642
 	 * blocking its deletion before removing the relation between A and B
1643 1643
 	 * @return boolean
1644 1644
 	 */
1645
-	public function delete_is_blocked_by_related_models($this_model_obj_or_id, $ignore_this_model_obj = null){
1645
+	public function delete_is_blocked_by_related_models($this_model_obj_or_id, $ignore_this_model_obj = null) {
1646 1646
 		//first, if $ignore_this_model_obj was supplied, get its model
1647
-		if($ignore_this_model_obj && $ignore_this_model_obj instanceof EE_Base_Class){
1647
+		if ($ignore_this_model_obj && $ignore_this_model_obj instanceof EE_Base_Class) {
1648 1648
 			$ignored_model = $ignore_this_model_obj->get_model();
1649
-		}else{
1649
+		} else {
1650 1650
 			$ignored_model = null;
1651 1651
 		}
1652 1652
 		//now check all the relations of $this_model_obj_or_id and see if there
1653 1653
 		//are any related model objects blocking it?
1654 1654
 		$is_blocked = false;
1655
-		foreach($this->_model_relations as $relation_name => $relation_obj){
1656
-			if( $relation_obj->block_delete_if_related_models_exist()){
1655
+		foreach ($this->_model_relations as $relation_name => $relation_obj) {
1656
+			if ($relation_obj->block_delete_if_related_models_exist()) {
1657 1657
 				//if $ignore_this_model_obj was supplied, then for the query
1658 1658
 				//on that model needs to be told to ignore $ignore_this_model_obj
1659
-				if($ignored_model && $relation_name == $ignored_model->get_this_model_name()){
1660
-					$related_model_objects = $relation_obj->get_all_related($this_model_obj_or_id,array(
1661
-					array($ignored_model->get_primary_key_field()->get_name() => array('!=',$ignore_this_model_obj->ID()))));
1662
-				}else{
1659
+				if ($ignored_model && $relation_name == $ignored_model->get_this_model_name()) {
1660
+					$related_model_objects = $relation_obj->get_all_related($this_model_obj_or_id, array(
1661
+					array($ignored_model->get_primary_key_field()->get_name() => array('!=', $ignore_this_model_obj->ID()))));
1662
+				} else {
1663 1663
 					$related_model_objects = $relation_obj->get_all_related($this_model_obj_or_id);
1664 1664
 				}
1665 1665
 
1666
-				if($related_model_objects){
1666
+				if ($related_model_objects) {
1667 1667
 					EE_Error::add_error($relation_obj->get_deletion_error_message(), __FILE__, __FUNCTION__, __LINE__);
1668 1668
 					$is_blocked = true;
1669 1669
 				}
@@ -1683,65 +1683,65 @@  discard block
 block discarded – undo
1683 1683
 	 * @throws EE_Error
1684 1684
 	 * @return string    everything that comes after the WHERE statement.
1685 1685
 	 */
1686
-	protected function _setup_ids_for_delete( $objects_for_deletion, $allow_blocking = true) {
1687
-		if($this->has_primary_key_field()){
1686
+	protected function _setup_ids_for_delete($objects_for_deletion, $allow_blocking = true) {
1687
+		if ($this->has_primary_key_field()) {
1688 1688
 			$primary_table = $this->_get_main_table();
1689 1689
 			$other_tables = $this->_get_other_tables();
1690 1690
 			$deletes = $query = array();
1691
-			foreach ( $objects_for_deletion as $delete_object ) {
1691
+			foreach ($objects_for_deletion as $delete_object) {
1692 1692
 				//before we mark this object for deletion,
1693 1693
 				//make sure there's no related objects blocking its deletion (if we're checking)
1694
-				if( $allow_blocking && $this->delete_is_blocked_by_related_models($delete_object[$primary_table->get_fully_qualified_pk_column()]) ){
1694
+				if ($allow_blocking && $this->delete_is_blocked_by_related_models($delete_object[$primary_table->get_fully_qualified_pk_column()])) {
1695 1695
 					continue;
1696 1696
 				}
1697 1697
 
1698 1698
 				//primary table deletes
1699
-				if ( isset( $delete_object[$primary_table->get_fully_qualified_pk_column()] ) )
1699
+				if (isset($delete_object[$primary_table->get_fully_qualified_pk_column()]))
1700 1700
 					$deletes[$primary_table->get_fully_qualified_pk_column()][] = $delete_object[$primary_table->get_fully_qualified_pk_column()];
1701 1701
 
1702 1702
 				//other tables
1703
-				if ( !empty( $other_tables ) ) {
1704
-					foreach ( $other_tables as $ot ) {
1703
+				if ( ! empty($other_tables)) {
1704
+					foreach ($other_tables as $ot) {
1705 1705
 
1706 1706
 						//first check if we've got the foreign key column here.
1707
-						if ( isset( $delete_object[$ot->get_fully_qualified_fk_column()] ) )
1707
+						if (isset($delete_object[$ot->get_fully_qualified_fk_column()]))
1708 1708
 							$deletes[$ot->get_fully_qualified_pk_column()][] = $delete_object[$ot->get_fully_qualified_fk_column()];
1709 1709
 
1710 1710
 						//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
1711
-						if ( isset( $delete_object[$ot->get_fully_qualified_pk_column()] ) )
1711
+						if (isset($delete_object[$ot->get_fully_qualified_pk_column()]))
1712 1712
 							$deletes[$ot->get_fully_qualified_pk_column()][] = $delete_object[$ot->get_fully_qualified_pk_column()];
1713 1713
 
1714 1714
 						//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!
1715
-						if ( isset( $delete_object[$ot->get_fully_qualified_pk_on_fk_table()]) )
1715
+						if (isset($delete_object[$ot->get_fully_qualified_pk_on_fk_table()]))
1716 1716
 							$deletes[$ot->get_fully_qualified_pk_column()][] = $delete_object[$ot->get_fully_qualified_pk_column()];
1717 1717
 					}
1718 1718
 				}
1719 1719
 			}
1720 1720
 
1721 1721
 			//we should have deletes now, so let's just go through and setup the where statement
1722
-			foreach ( $deletes as $column => $values ) {
1722
+			foreach ($deletes as $column => $values) {
1723 1723
 				//make sure we have unique $values;
1724 1724
 				$values = array_unique($values);
1725
-				$query[] = $column . ' IN(' . implode(",",$values) . ')';
1725
+				$query[] = $column.' IN('.implode(",", $values).')';
1726 1726
 			}
1727 1727
 
1728
-			return !empty($query) ? implode(' AND ', $query ) : '';
1729
-		}elseif(count($this->get_combined_primary_key_fields()) > 1){
1728
+			return ! empty($query) ? implode(' AND ', $query) : '';
1729
+		}elseif (count($this->get_combined_primary_key_fields()) > 1) {
1730 1730
 			$ways_to_identify_a_row = array();
1731 1731
 			$fields = $this->get_combined_primary_key_fields();
1732 1732
 			//note: because there' sno primary key, that means nothing else  can be pointing to this model, right?
1733
-			foreach($objects_for_deletion as  $delete_object){
1733
+			foreach ($objects_for_deletion as  $delete_object) {
1734 1734
 				$values_for_each_cpk_for_a_row = array();
1735
-				foreach($fields as $cpk_field){
1735
+				foreach ($fields as $cpk_field) {
1736 1736
 					$values_for_each_cpk_for_a_row[] = $cpk_field->get_qualified_column()."=".$delete_object[$cpk_field->get_qualified_column()];
1737 1737
 				}
1738
-				$ways_to_identify_a_row[] = "(".implode(" AND ",$values_for_each_cpk_for_a_row).")";
1738
+				$ways_to_identify_a_row[] = "(".implode(" AND ", $values_for_each_cpk_for_a_row).")";
1739 1739
 			}
1740
-			return implode(" OR ",$ways_to_identify_a_row);
1741
-		}else{
1740
+			return implode(" OR ", $ways_to_identify_a_row);
1741
+		} else {
1742 1742
 			//so there's no primary key and no combined key...
1743 1743
 			//sorry, can't help you
1744
-			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)));
1744
+			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)));
1745 1745
 		}
1746 1746
 	}
1747 1747
 
@@ -1755,21 +1755,21 @@  discard block
 block discarded – undo
1755 1755
 	 * @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;
1756 1756
 	 * @return int
1757 1757
 	 */
1758
-	function count($query_params =array(),$field_to_count = NULL, $distinct = FALSE){
1758
+	function count($query_params = array(), $field_to_count = NULL, $distinct = FALSE) {
1759 1759
 		$model_query_info = $this->_create_model_query_info_carrier($query_params);
1760
-		if($field_to_count){
1760
+		if ($field_to_count) {
1761 1761
 			$field_obj = $this->field_settings_for($field_to_count);
1762 1762
 			$column_to_count = $field_obj->get_qualified_column();
1763
-		}elseif($this->has_primary_key_field ()){
1763
+		}elseif ($this->has_primary_key_field()) {
1764 1764
 			$pk_field_obj = $this->get_primary_key_field();
1765 1765
 			$column_to_count = $pk_field_obj->get_qualified_column();
1766
-		}else{//there's no primary key
1766
+		} else {//there's no primary key
1767 1767
 			$column_to_count = '*';
1768 1768
 		}
1769 1769
 
1770
-		$column_to_count = $distinct ? "DISTINCT (" . $column_to_count . " )" : $column_to_count;
1771
-		$SQL ="SELECT COUNT(".$column_to_count.")" . $this->_construct_2nd_half_of_select_query($model_query_info);
1772
-		return (int)$this->_do_wpdb_query( 'get_var', array( $SQL) );
1770
+		$column_to_count = $distinct ? "DISTINCT (".$column_to_count." )" : $column_to_count;
1771
+		$SQL = "SELECT COUNT(".$column_to_count.")".$this->_construct_2nd_half_of_select_query($model_query_info);
1772
+		return (int) $this->_do_wpdb_query('get_var', array($SQL));
1773 1773
 	}
1774 1774
 
1775 1775
 	/**
@@ -1779,23 +1779,23 @@  discard block
 block discarded – undo
1779 1779
 	 * @param string $field_to_sum name of field (array key in $_fields array)
1780 1780
 	 * @return float
1781 1781
 	 */
1782
-	function sum($query_params, $field_to_sum = NULL){
1782
+	function sum($query_params, $field_to_sum = NULL) {
1783 1783
 		$model_query_info = $this->_create_model_query_info_carrier($query_params);
1784 1784
 
1785
-		if($field_to_sum){
1785
+		if ($field_to_sum) {
1786 1786
 			$field_obj = $this->field_settings_for($field_to_sum);
1787 1787
 
1788
-		}else{
1788
+		} else {
1789 1789
 			$field_obj = $this->get_primary_key_field();
1790 1790
 		}
1791 1791
 		$column_to_count = $field_obj->get_qualified_column();
1792 1792
 
1793
-		$SQL ="SELECT SUM(".$column_to_count.")" . $this->_construct_2nd_half_of_select_query($model_query_info);
1794
-		$return_value = $this->_do_wpdb_query('get_var',array( $SQL ) );
1795
-		if($field_obj->get_wpdb_data_type() == '%d' || $field_obj->get_wpdb_data_type() == '%s' ){
1796
-			return (float)$return_value;
1797
-		}else{//must be %f
1798
-			return (float)$return_value;
1793
+		$SQL = "SELECT SUM(".$column_to_count.")".$this->_construct_2nd_half_of_select_query($model_query_info);
1794
+		$return_value = $this->_do_wpdb_query('get_var', array($SQL));
1795
+		if ($field_obj->get_wpdb_data_type() == '%d' || $field_obj->get_wpdb_data_type() == '%s') {
1796
+			return (float) $return_value;
1797
+		} else {//must be %f
1798
+			return (float) $return_value;
1799 1799
 		}
1800 1800
 	}
1801 1801
 
@@ -1810,33 +1810,33 @@  discard block
 block discarded – undo
1810 1810
 	 * @global wpdb $wpdb
1811 1811
 	 * @return mixed
1812 1812
 	 */
1813
-	protected function _do_wpdb_query( $wpdb_method, $arguments_to_provide ){
1813
+	protected function _do_wpdb_query($wpdb_method, $arguments_to_provide) {
1814 1814
 		//if we're in maintenance mode level 2, DON'T run any queries
1815 1815
 		//because level 2 indicates the database needs updating and
1816 1816
 		//is probably out of sync with the code
1817
-		if( ! EE_Maintenance_Mode::instance()->models_can_query()){
1817
+		if ( ! EE_Maintenance_Mode::instance()->models_can_query()) {
1818 1818
 			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")));
1819 1819
 		}
1820 1820
 		/** @type WPDB $wpdb */
1821 1821
 		global $wpdb;
1822
-		if( ! method_exists( $wpdb, $wpdb_method ) ){
1823
-			throw new EE_Error( sprintf( __( 'There is no method named "%s" on Wordpress\' $wpdb object','event_espresso' ), $wpdb_method ) );
1822
+		if ( ! method_exists($wpdb, $wpdb_method)) {
1823
+			throw new EE_Error(sprintf(__('There is no method named "%s" on Wordpress\' $wpdb object', 'event_espresso'), $wpdb_method));
1824 1824
 		}
1825
-		if( WP_DEBUG ){
1825
+		if (WP_DEBUG) {
1826 1826
 			$old_show_errors_value = $wpdb->show_errors;
1827
-			$wpdb->show_errors( FALSE );
1828
-		}
1829
-		$result = $this->_process_wpdb_query( $wpdb_method, $arguments_to_provide );
1830
-		$this->show_db_query_if_previously_requested( $wpdb->last_query );
1831
-		if( WP_DEBUG ){
1832
-			$wpdb->show_errors( $old_show_errors_value );
1833
-			if( ! empty( $wpdb->last_error ) ){
1834
-				throw new EE_Error( sprintf( __( 'WPDB Error: "%s"', 'event_espresso' ), $wpdb->last_error ) );
1835
-			}elseif( $result === false ){
1836
-				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 ) ) );
1827
+			$wpdb->show_errors(FALSE);
1828
+		}
1829
+		$result = $this->_process_wpdb_query($wpdb_method, $arguments_to_provide);
1830
+		$this->show_db_query_if_previously_requested($wpdb->last_query);
1831
+		if (WP_DEBUG) {
1832
+			$wpdb->show_errors($old_show_errors_value);
1833
+			if ( ! empty($wpdb->last_error)) {
1834
+				throw new EE_Error(sprintf(__('WPDB Error: "%s"', 'event_espresso'), $wpdb->last_error));
1835
+			}elseif ($result === false) {
1836
+				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 1837
 			}
1838
-		}elseif( $result === false ) {
1839
-			EE_Error::add_error( sprintf( __( 'A database error has occurred. Turn on WP_DEBUG for more information.', 'event_espresso' )), __FILE__, __FUNCTION__, __LINE__);
1838
+		}elseif ($result === false) {
1839
+			EE_Error::add_error(sprintf(__('A database error has occurred. Turn on WP_DEBUG for more information.', 'event_espresso')), __FILE__, __FUNCTION__, __LINE__);
1840 1840
 		}
1841 1841
 		return $result;
1842 1842
 	}
@@ -1852,23 +1852,23 @@  discard block
 block discarded – undo
1852 1852
 	 * @param array $arguments_to_provide
1853 1853
 	 * @return mixed
1854 1854
 	 */
1855
-	private function _process_wpdb_query( $wpdb_method, $arguments_to_provide ) {
1855
+	private function _process_wpdb_query($wpdb_method, $arguments_to_provide) {
1856 1856
 		/** @type WPDB $wpdb */
1857 1857
 		global $wpdb;
1858 1858
 		$wpdb->last_error = null;
1859
-		$result = call_user_func_array( array( $wpdb, $wpdb_method ), $arguments_to_provide );
1859
+		$result = call_user_func_array(array($wpdb, $wpdb_method), $arguments_to_provide);
1860 1860
 		// was there an error running the query?
1861
-		if ( ( $result === false || ! empty( $wpdb->last_error ) ) ) {
1862
-			switch ( EEM_Base::$_db_verification_level ) {
1861
+		if (($result === false || ! empty($wpdb->last_error))) {
1862
+			switch (EEM_Base::$_db_verification_level) {
1863 1863
 
1864 1864
 				case EEM_Base::db_verified_none :
1865 1865
 					// let's double-check core's DB
1866
-					$error_message = $this->_verify_core_db( $wpdb_method, $arguments_to_provide );
1866
+					$error_message = $this->_verify_core_db($wpdb_method, $arguments_to_provide);
1867 1867
 					break;
1868 1868
 
1869 1869
 				case EEM_Base::db_verified_core :
1870 1870
 					// STILL NO LOVE?? verify all the addons too. Maybe they need to be fixed
1871
-					$error_message = $this->_verify_addons_db( $wpdb_method, $arguments_to_provide );
1871
+					$error_message = $this->_verify_addons_db($wpdb_method, $arguments_to_provide);
1872 1872
 					break;
1873 1873
 
1874 1874
 				case EEM_Base::db_verified_addons :
@@ -1876,11 +1876,11 @@  discard block
 block discarded – undo
1876 1876
 					return $result;
1877 1877
 					break;
1878 1878
 			}
1879
-			if ( ! empty( $error_message ) ) {
1880
-				EE_Log::instance()->log( __FILE__, __FUNCTION__, $error_message, 'error' );
1881
-				trigger_error( $error_message );
1879
+			if ( ! empty($error_message)) {
1880
+				EE_Log::instance()->log(__FILE__, __FUNCTION__, $error_message, 'error');
1881
+				trigger_error($error_message);
1882 1882
 			}
1883
-			return $this->_process_wpdb_query( $wpdb_method, $arguments_to_provide );
1883
+			return $this->_process_wpdb_query($wpdb_method, $arguments_to_provide);
1884 1884
 
1885 1885
 		}
1886 1886
 
@@ -1896,18 +1896,18 @@  discard block
 block discarded – undo
1896 1896
 	 * @param array $arguments_to_provide
1897 1897
 	 * @return string
1898 1898
 	 */
1899
-	private function _verify_core_db( $wpdb_method, $arguments_to_provide ){
1899
+	private function _verify_core_db($wpdb_method, $arguments_to_provide) {
1900 1900
 		/** @type WPDB $wpdb */
1901 1901
 		global $wpdb;
1902 1902
 		//ok remember that we've already attempted fixing the core db, in case the problem persists
1903 1903
 		EEM_Base::$_db_verification_level = EEM_Base::db_verified_core;
1904 1904
 		$error_message = sprintf(
1905
-			__( 'WPDB Error "%1$s" while running wpdb method "%2$s" with arguments %3$s. Automatically attempting to fix EE Core DB', 'event_espresso' ),
1905
+			__('WPDB Error "%1$s" while running wpdb method "%2$s" with arguments %3$s. Automatically attempting to fix EE Core DB', 'event_espresso'),
1906 1906
 			$wpdb->last_error,
1907 1907
 			$wpdb_method,
1908
-			json_encode( $arguments_to_provide )
1908
+			json_encode($arguments_to_provide)
1909 1909
 		);
1910
-		EE_System::instance()->initialize_db_if_no_migrations_required( false, true );
1910
+		EE_System::instance()->initialize_db_if_no_migrations_required(false, true);
1911 1911
 		return $error_message;
1912 1912
 	}
1913 1913
 
@@ -1920,16 +1920,16 @@  discard block
 block discarded – undo
1920 1920
 	 * @param $arguments_to_provide
1921 1921
 	 * @return string
1922 1922
 	 */
1923
-	private function _verify_addons_db( $wpdb_method, $arguments_to_provide ) {
1923
+	private function _verify_addons_db($wpdb_method, $arguments_to_provide) {
1924 1924
 		/** @type WPDB $wpdb */
1925 1925
 		global $wpdb;
1926 1926
 		//ok remember that we've already attempted fixing the addons dbs, in case the problem persists
1927 1927
 		EEM_Base::$_db_verification_level = EEM_Base::db_verified_addons;
1928 1928
 		$error_message = sprintf(
1929
-			__( 'WPDB AGAIN: Error "%1$s" while running the same method and arguments as before. Automatically attempting to fix EE Addons DB', 'event_espresso' ),
1929
+			__('WPDB AGAIN: Error "%1$s" while running the same method and arguments as before. Automatically attempting to fix EE Addons DB', 'event_espresso'),
1930 1930
 			$wpdb->last_error,
1931 1931
 			$wpdb_method,
1932
-			json_encode( $arguments_to_provide )
1932
+			json_encode($arguments_to_provide)
1933 1933
 		);
1934 1934
 		EE_System::instance()->initialize_addons();
1935 1935
 		return $error_message;
@@ -1944,7 +1944,7 @@  discard block
 block discarded – undo
1944 1944
 	 * @param EE_Model_Query_Info_Carrier $model_query_info
1945 1945
 	 * @return string
1946 1946
 	 */
1947
-	private function _construct_2nd_half_of_select_query(EE_Model_Query_Info_Carrier $model_query_info){
1947
+	private function _construct_2nd_half_of_select_query(EE_Model_Query_Info_Carrier $model_query_info) {
1948 1948
 		return " FROM ".$model_query_info->get_full_join_sql().
1949 1949
 				$model_query_info->get_where_sql().
1950 1950
 				$model_query_info->get_group_by_sql().
@@ -1957,7 +1957,7 @@  discard block
 block discarded – undo
1957 1957
 	 * Set to easily debug the next X queries ran from this model.
1958 1958
 	 * @param int $count
1959 1959
 	 */
1960
-	function show_next_x_db_queries($count = 1){
1960
+	function show_next_x_db_queries($count = 1) {
1961 1961
 		$this->_show_next_x_db_queries = $count;
1962 1962
 	}
1963 1963
 
@@ -1966,8 +1966,8 @@  discard block
 block discarded – undo
1966 1966
 	/**
1967 1967
 	 * @param $sql_query
1968 1968
 	 */
1969
-	function show_db_query_if_previously_requested($sql_query){
1970
-		if($this->_show_next_x_db_queries > 0){
1969
+	function show_db_query_if_previously_requested($sql_query) {
1970
+		if ($this->_show_next_x_db_queries > 0) {
1971 1971
 			echo $sql_query;
1972 1972
 			$this->_show_next_x_db_queries--;
1973 1973
 		}
@@ -1991,9 +1991,9 @@  discard block
 block discarded – undo
1991 1991
 	 * @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.
1992 1992
 	 * @return EE_Base_Class which was added as a relation. Object referred to by $other_model_id_or_obj
1993 1993
 	 */
1994
-	public function add_relationship_to($id_or_obj,$other_model_id_or_obj, $relationName, $extra_join_model_fields_n_values = array()){
1994
+	public function add_relationship_to($id_or_obj, $other_model_id_or_obj, $relationName, $extra_join_model_fields_n_values = array()) {
1995 1995
 		$relation_obj = $this->related_settings_for($relationName);
1996
-		return $relation_obj->add_relation_to( $id_or_obj, $other_model_id_or_obj, $extra_join_model_fields_n_values);
1996
+		return $relation_obj->add_relation_to($id_or_obj, $other_model_id_or_obj, $extra_join_model_fields_n_values);
1997 1997
 	}
1998 1998
 
1999 1999
 	/**
@@ -2012,9 +2012,9 @@  discard block
 block discarded – undo
2012 2012
 	 * @return boolean of success
2013 2013
 	 * @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.
2014 2014
 	 */
2015
-	public function remove_relationship_to($id_or_obj,  $other_model_id_or_obj, $relationName, $where_query= array() ){
2015
+	public function remove_relationship_to($id_or_obj, $other_model_id_or_obj, $relationName, $where_query = array()) {
2016 2016
 		$relation_obj = $this->related_settings_for($relationName);
2017
-		return $relation_obj->remove_relation_to($id_or_obj, $other_model_id_or_obj, $where_query );
2017
+		return $relation_obj->remove_relation_to($id_or_obj, $other_model_id_or_obj, $where_query);
2018 2018
 	}
2019 2019
 
2020 2020
 
@@ -2027,9 +2027,9 @@  discard block
 block discarded – undo
2027 2027
 	 * @param EE_Base_Class[] objects to which relations were removed
2028 2028
 	 * @return \EE_Base_Class[]
2029 2029
 	 */
2030
-	public function remove_relations($id_or_obj,$relationName,$where_query_params = array()){
2030
+	public function remove_relations($id_or_obj, $relationName, $where_query_params = array()) {
2031 2031
 		$relation_obj = $this->related_settings_for($relationName);
2032
-		return $relation_obj->remove_relations($id_or_obj, $where_query_params );
2032
+		return $relation_obj->remove_relations($id_or_obj, $where_query_params);
2033 2033
 	}
2034 2034
 
2035 2035
 
@@ -2042,10 +2042,10 @@  discard block
 block discarded – undo
2042 2042
 	 * @param array $query_params like EEM_Base::get_all
2043 2043
 	 * @return EE_Base_Class[]
2044 2044
 	 */
2045
-	function get_all_related($id_or_obj, $model_name, $query_params = null){
2045
+	function get_all_related($id_or_obj, $model_name, $query_params = null) {
2046 2046
 		$model_obj = $this->ensure_is_obj($id_or_obj);
2047 2047
 		$relation_settings = $this->related_settings_for($model_name);
2048
-		return $relation_settings->get_all_related($model_obj,$query_params);
2048
+		return $relation_settings->get_all_related($model_obj, $query_params);
2049 2049
 	}
2050 2050
 
2051 2051
 	/**
@@ -2058,10 +2058,10 @@  discard block
 block discarded – undo
2058 2058
 	 * @param array $query_params
2059 2059
 	 * @return int how many deleted
2060 2060
 	 */
2061
-	public function delete_related($id_or_obj,$model_name, $query_params = array()){
2061
+	public function delete_related($id_or_obj, $model_name, $query_params = array()) {
2062 2062
 		$model_obj = $this->ensure_is_obj($id_or_obj);
2063 2063
 		$relation_settings = $this->related_settings_for($model_name);
2064
-		return $relation_settings->delete_all_related($model_obj,$query_params);
2064
+		return $relation_settings->delete_all_related($model_obj, $query_params);
2065 2065
 	}
2066 2066
 
2067 2067
 	/**
@@ -2074,10 +2074,10 @@  discard block
 block discarded – undo
2074 2074
 	 * @param array $query_params
2075 2075
 	 * @return int how many deleted
2076 2076
 	 */
2077
-	public function delete_related_permanently($id_or_obj,$model_name, $query_params = array()){
2077
+	public function delete_related_permanently($id_or_obj, $model_name, $query_params = array()) {
2078 2078
 		$model_obj = $this->ensure_is_obj($id_or_obj);
2079 2079
 		$relation_settings = $this->related_settings_for($model_name);
2080
-		return $relation_settings->delete_related_permanently($model_obj,$query_params);
2080
+		return $relation_settings->delete_related_permanently($model_obj, $query_params);
2081 2081
 	}
2082 2082
 
2083 2083
 	/**
@@ -2090,17 +2090,17 @@  discard block
 block discarded – undo
2090 2090
 	 * @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;
2091 2091
 	 * @return int
2092 2092
 	 */
2093
-	function count_related($id_or_obj,$model_name,$query_params = array(),$field_to_count = null, $distinct = FALSE){
2093
+	function count_related($id_or_obj, $model_name, $query_params = array(), $field_to_count = null, $distinct = FALSE) {
2094 2094
 		$related_model = $this->get_related_model_obj($model_name);
2095 2095
 		//we're just going to use the query params on the related model's normal get_all query,
2096 2096
 		//except add a condition to say to match the current mod
2097
-		if( ! isset($query_params['default_where_conditions'])){
2098
-			$query_params['default_where_conditions']='none';
2097
+		if ( ! isset($query_params['default_where_conditions'])) {
2098
+			$query_params['default_where_conditions'] = 'none';
2099 2099
 		}
2100 2100
 		$this_model_name = $this->get_this_model_name();
2101 2101
 		$this_pk_field_name = $this->get_primary_key_field()->get_name();
2102
-		$query_params[0][$this_model_name.".".$this_pk_field_name]=$id_or_obj;
2103
-		return $related_model->count($query_params,$field_to_count,$distinct);
2102
+		$query_params[0][$this_model_name.".".$this_pk_field_name] = $id_or_obj;
2103
+		return $related_model->count($query_params, $field_to_count, $distinct);
2104 2104
 	}
2105 2105
 
2106 2106
 
@@ -2114,21 +2114,21 @@  discard block
 block discarded – undo
2114 2114
 	 * @param string $field_to_sum name of field to count by. By default, uses primary key
2115 2115
 	 * @return float
2116 2116
 	 */
2117
-	function sum_related($id_or_obj,$model_name,$query_params,$field_to_sum = null){
2117
+	function sum_related($id_or_obj, $model_name, $query_params, $field_to_sum = null) {
2118 2118
 		$related_model = $this->get_related_model_obj($model_name);
2119
-		if( ! is_array( $query_params ) ){
2120
-			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' );
2119
+		if ( ! is_array($query_params)) {
2120
+			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');
2121 2121
 			$query_params = array();
2122 2122
 		}
2123 2123
 		//we're just going to use the query params on the related model's normal get_all query,
2124 2124
 		//except add a condition to say to match the current mod
2125
-		if( ! isset($query_params['default_where_conditions'])){
2126
-			$query_params['default_where_conditions']='none';
2125
+		if ( ! isset($query_params['default_where_conditions'])) {
2126
+			$query_params['default_where_conditions'] = 'none';
2127 2127
 		}
2128 2128
 		$this_model_name = $this->get_this_model_name();
2129 2129
 		$this_pk_field_name = $this->get_primary_key_field()->get_name();
2130
-		$query_params[0][$this_model_name.".".$this_pk_field_name]=$id_or_obj;
2131
-		return $related_model->sum($query_params,$field_to_sum);
2130
+		$query_params[0][$this_model_name.".".$this_pk_field_name] = $id_or_obj;
2131
+		return $related_model->sum($query_params, $field_to_sum);
2132 2132
 	}
2133 2133
 
2134 2134
 
@@ -2140,12 +2140,12 @@  discard block
 block discarded – undo
2140 2140
 	 * @param array $query_params like EEM_Base::get_all's
2141 2141
 	 * @return EE_Base_Class
2142 2142
 	 */
2143
-	public function get_first_related( EE_Base_Class $id_or_obj, $other_model_name, $query_params ){
2144
-		$query_params['limit']=1;
2145
-		$results = $this->get_all_related($id_or_obj,$other_model_name,$query_params);
2146
-		if( $results ){
2143
+	public function get_first_related(EE_Base_Class $id_or_obj, $other_model_name, $query_params) {
2144
+		$query_params['limit'] = 1;
2145
+		$results = $this->get_all_related($id_or_obj, $other_model_name, $query_params);
2146
+		if ($results) {
2147 2147
 			return array_shift($results);
2148
-		}else{
2148
+		} else {
2149 2149
 			return null;
2150 2150
 		}
2151 2151
 
@@ -2155,8 +2155,8 @@  discard block
 block discarded – undo
2155 2155
 	 * Gets the model's name as it's expected in queries. For example, if this is EEM_Event model, that would be Event
2156 2156
 	 * @return string
2157 2157
 	 */
2158
-	function get_this_model_name(){
2159
-		return str_replace("EEM_","",get_class($this));
2158
+	function get_this_model_name() {
2159
+		return str_replace("EEM_", "", get_class($this));
2160 2160
 	}
2161 2161
 
2162 2162
 	/**
@@ -2164,14 +2164,14 @@  discard block
 block discarded – undo
2164 2164
 	 * @return EE_Any_Foreign_Model_Name_Field
2165 2165
 	 * @throws EE_Error
2166 2166
 	 */
2167
-	public function get_field_containing_related_model_name(){
2168
-		foreach($this->field_settings(true) as $field){
2169
-			if($field instanceof EE_Any_Foreign_Model_Name_Field){
2167
+	public function get_field_containing_related_model_name() {
2168
+		foreach ($this->field_settings(true) as $field) {
2169
+			if ($field instanceof EE_Any_Foreign_Model_Name_Field) {
2170 2170
 				$field_with_model_name = $field;
2171 2171
 			}
2172 2172
 		}
2173
-		if( !isset($field_with_model_name) || !$field_with_model_name ){
2174
-			throw new EE_Error(sprintf(__("There is no EE_Any_Foreign_Model_Name field on model %s", "event_espresso"), $this->get_this_model_name() ));
2173
+		if ( ! isset($field_with_model_name) || ! $field_with_model_name) {
2174
+			throw new EE_Error(sprintf(__("There is no EE_Any_Foreign_Model_Name field on model %s", "event_espresso"), $this->get_this_model_name()));
2175 2175
 		}
2176 2176
 		return $field_with_model_name;
2177 2177
 	}
@@ -2192,19 +2192,19 @@  discard block
 block discarded – undo
2192 2192
 	 * @return int new primary key on main table that got inserted
2193 2193
 	 * @throws EE_Error
2194 2194
 	 */
2195
-	function insert($field_n_values){
2195
+	function insert($field_n_values) {
2196 2196
 		/**
2197 2197
 		 * Filters the fields and their values before inserting an item using the models
2198 2198
 		 * @param array $fields_n_values keys are the fields and values are their new values
2199 2199
 		 * @param EEM_Base $model the model used
2200 2200
 		 */
2201
-		$field_n_values = apply_filters( 'FHEE__EEM_Base__insert__fields_n_values', $field_n_values, $this );
2202
-		if($this->_satisfies_unique_indexes($field_n_values)){
2201
+		$field_n_values = apply_filters('FHEE__EEM_Base__insert__fields_n_values', $field_n_values, $this);
2202
+		if ($this->_satisfies_unique_indexes($field_n_values)) {
2203 2203
 			$main_table = $this->_get_main_table();
2204 2204
 			$new_id = $this->_insert_into_specific_table($main_table, $field_n_values, false);
2205
-			if( $new_id !== false ) {
2206
-				foreach($this->_get_other_tables() as $other_table){
2207
-					$this->_insert_into_specific_table($other_table, $field_n_values,$new_id);
2205
+			if ($new_id !== false) {
2206
+				foreach ($this->_get_other_tables() as $other_table) {
2207
+					$this->_insert_into_specific_table($other_table, $field_n_values, $new_id);
2208 2208
 				}
2209 2209
 			}
2210 2210
 			/**
@@ -2214,9 +2214,9 @@  discard block
 block discarded – undo
2214 2214
 			 * @param array $fields_n_values fields and their values
2215 2215
 			 * @param int|string the ID of the newly-inserted model object
2216 2216
 			 */
2217
-			do_action( 'AHEE__EEM_Base__insert__end', $this, $field_n_values, $new_id );
2217
+			do_action('AHEE__EEM_Base__insert__end', $this, $field_n_values, $new_id);
2218 2218
 			return $new_id;
2219
-		}else{
2219
+		} else {
2220 2220
 			return FALSE;
2221 2221
 		}
2222 2222
 	}
@@ -2229,11 +2229,11 @@  discard block
 block discarded – undo
2229 2229
 	 * @param string $action
2230 2230
 	 * @return boolean
2231 2231
 	 */
2232
-	protected function _satisfies_unique_indexes($field_n_values,$action = 'insert'){
2233
-		foreach($this->unique_indexes() as $index_name => $index){
2232
+	protected function _satisfies_unique_indexes($field_n_values, $action = 'insert') {
2233
+		foreach ($this->unique_indexes() as $index_name => $index) {
2234 2234
 			$uniqueness_where_params = array_intersect_key($field_n_values, $index->fields());
2235
-			if($this->exists(array($uniqueness_where_params))){
2236
-				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__ );
2235
+			if ($this->exists(array($uniqueness_where_params))) {
2236
+				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__);
2237 2237
 				return false;
2238 2238
 			}
2239 2239
 		}
@@ -2254,28 +2254,28 @@  discard block
 block discarded – undo
2254 2254
 	 * @throws EE_Error
2255 2255
 	 * @return EE_Base_Class
2256 2256
 	 */
2257
-	public function get_one_conflicting($obj_or_fields_array, $include_primary_key = true ){
2258
-		if($obj_or_fields_array instanceof EE_Base_Class){
2257
+	public function get_one_conflicting($obj_or_fields_array, $include_primary_key = true) {
2258
+		if ($obj_or_fields_array instanceof EE_Base_Class) {
2259 2259
 			$fields_n_values = $obj_or_fields_array->model_field_array();
2260
-		}elseif( is_array($obj_or_fields_array)){
2260
+		}elseif (is_array($obj_or_fields_array)) {
2261 2261
 			$fields_n_values = $obj_or_fields_array;
2262
-		}else{
2263
-			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));
2262
+		} else {
2263
+			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));
2264 2264
 		}
2265
-		$query_params = array( 'default_where_conditions' => 'minimum' );
2266
-		if( $this->has_primary_key_field() &&
2267
-				( $include_primary_key || $this->get_primary_key_field() instanceof EE_Primary_Key_String_Field) &&
2268
-				isset($fields_n_values[$this->primary_key_name()])){
2265
+		$query_params = array('default_where_conditions' => 'minimum');
2266
+		if ($this->has_primary_key_field() &&
2267
+				($include_primary_key || $this->get_primary_key_field() instanceof EE_Primary_Key_String_Field) &&
2268
+				isset($fields_n_values[$this->primary_key_name()])) {
2269 2269
 			$query_params[0]['OR'][$this->primary_key_name()] = $fields_n_values[$this->primary_key_name()];
2270 2270
 		}
2271
-		foreach($this->unique_indexes() as $unique_index_name=>$unique_index){
2271
+		foreach ($this->unique_indexes() as $unique_index_name=>$unique_index) {
2272 2272
 			$uniqueness_where_params = array_intersect_key($fields_n_values, $unique_index->fields());
2273 2273
 			$query_params[0]['OR']['AND*'.$unique_index_name] = $uniqueness_where_params;
2274 2274
 		}
2275 2275
 		//if there is nothing to base this search on, then we shouldn't find anything
2276
-		if( ! isset( $query_params[0] ) || ( isset( $query_params[0] ) && empty( $query_params[0] ) ) ) {
2276
+		if ( ! isset($query_params[0]) || (isset($query_params[0]) && empty($query_params[0]))) {
2277 2277
 			return array();
2278
-		}else{
2278
+		} else {
2279 2279
 			return $this->get_one($query_params);
2280 2280
 		}
2281 2281
 	}
@@ -2285,7 +2285,7 @@  discard block
 block discarded – undo
2285 2285
 	 * @param array $query_params
2286 2286
 	 * @return boolean
2287 2287
 	 */
2288
-	function exists($query_params){
2288
+	function exists($query_params) {
2289 2289
 		$query_params['limit'] = 1;
2290 2290
 		return $this->count($query_params) > 0;
2291 2291
 	}
@@ -2295,7 +2295,7 @@  discard block
 block discarded – undo
2295 2295
 	 * @param int|string $id
2296 2296
 	 * @return boolean
2297 2297
 	 */
2298
-	function exists_by_ID($id){
2298
+	function exists_by_ID($id) {
2299 2299
 		return $this->exists(array('default_where_conditions'=>'none', array($this->primary_key_name() => $id)));
2300 2300
 	}
2301 2301
 
@@ -2315,45 +2315,45 @@  discard block
 block discarded – undo
2315 2315
 	 * @global WPDB $wpdb only used to get the $wpdb->insert_id after performing an insert
2316 2316
 	 * @return int ID of new row inserted, or FALSE on failure
2317 2317
 	 */
2318
-	protected function _insert_into_specific_table(EE_Table_Base $table, $fields_n_values, $new_id = 0 ){
2318
+	protected function _insert_into_specific_table(EE_Table_Base $table, $fields_n_values, $new_id = 0) {
2319 2319
 		global $wpdb;
2320 2320
 		$insertion_col_n_values = array();
2321 2321
 		$format_for_insertion = array();
2322 2322
 		$fields_on_table = $this->_get_fields_for_table($table->get_table_alias());
2323
-		foreach($fields_on_table as $field_name => $field_obj){
2323
+		foreach ($fields_on_table as $field_name => $field_obj) {
2324 2324
 			//check if its an auto-incrementing column, in which case we should just leave it to do its autoincrement thing
2325
-			if($field_obj->is_auto_increment()){
2325
+			if ($field_obj->is_auto_increment()) {
2326 2326
 				continue;
2327 2327
 			}
2328 2328
 			$prepared_value = $this->_prepare_value_or_use_default($field_obj, $fields_n_values);
2329 2329
 			//if the value we want to assign it to is NULL, just don't mention it for the insertion
2330
-			if( $prepared_value !== NULL ){
2331
-				$insertion_col_n_values[ $field_obj->get_table_column() ] = $prepared_value;
2330
+			if ($prepared_value !== NULL) {
2331
+				$insertion_col_n_values[$field_obj->get_table_column()] = $prepared_value;
2332 2332
 				$format_for_insertion[] = $field_obj->get_wpdb_data_type();
2333 2333
 			}
2334 2334
 		}
2335 2335
 
2336
-		if($table instanceof EE_Secondary_Table && $new_id){
2336
+		if ($table instanceof EE_Secondary_Table && $new_id) {
2337 2337
 			//its not the main table, so we should have already saved the main table's PK which we just inserted
2338 2338
 			//so add the fk to the main table as a column
2339 2339
 			$insertion_col_n_values[$table->get_fk_on_table()] = $new_id;
2340
-			$format_for_insertion[]='%d';//yes right now we're only allowing these foreign keys to be INTs
2340
+			$format_for_insertion[] = '%d'; //yes right now we're only allowing these foreign keys to be INTs
2341 2341
 		}
2342 2342
 		//insert the new entry
2343
-		$result = $this->_do_wpdb_query( 'insert', array( $table->get_table_name(), $insertion_col_n_values, $format_for_insertion ) );
2344
-		if( $result === false ) {
2343
+		$result = $this->_do_wpdb_query('insert', array($table->get_table_name(), $insertion_col_n_values, $format_for_insertion));
2344
+		if ($result === false) {
2345 2345
 			return false;
2346 2346
 		}
2347 2347
 		//ok, now what do we return for the ID of the newly-inserted thing?
2348
-		if($this->has_primary_key_field()){
2349
-			if($this->get_primary_key_field()->is_auto_increment()){
2348
+		if ($this->has_primary_key_field()) {
2349
+			if ($this->get_primary_key_field()->is_auto_increment()) {
2350 2350
 				return $wpdb->insert_id;
2351
-			}else{
2351
+			} else {
2352 2352
 				//it's not an auto-increment primary key, so
2353 2353
 				//it must have been supplied
2354 2354
 				return $fields_n_values[$this->get_primary_key_field()->get_name()];
2355 2355
 			}
2356
-		}else{
2356
+		} else {
2357 2357
 			//we can't return a  primary key because there is none. instead return
2358 2358
 			//a unique string indicating this model
2359 2359
 			return $this->get_index_primary_key_string($fields_n_values);
@@ -2368,15 +2368,15 @@  discard block
 block discarded – undo
2368 2368
 	 * @param array $fields_n_values
2369 2369
 	 * @return mixed string|int|float depending on what the table column will be expecting
2370 2370
 	 */
2371
-	protected function _prepare_value_or_use_default( $field_obj, $fields_n_values ){
2371
+	protected function _prepare_value_or_use_default($field_obj, $fields_n_values) {
2372 2372
 		//if this field doesn't allow nullable, don't allow it
2373
-		if( ! $field_obj->is_nullable() && (
2374
-				! isset( $fields_n_values[ $field_obj->get_name() ] ) ||
2375
-				$fields_n_values[ $field_obj->get_name() ] === NULL ) ){
2376
-			$fields_n_values[ $field_obj->get_name() ] = $field_obj->get_default_value();
2373
+		if ( ! $field_obj->is_nullable() && (
2374
+				! isset($fields_n_values[$field_obj->get_name()]) ||
2375
+				$fields_n_values[$field_obj->get_name()] === NULL )) {
2376
+			$fields_n_values[$field_obj->get_name()] = $field_obj->get_default_value();
2377 2377
 		}
2378
-		$unprepared_value = isset( $fields_n_values[ $field_obj->get_name() ] ) ? $fields_n_values[ $field_obj->get_name() ] : NULL;
2379
-		return $this->_prepare_value_for_use_in_db( $unprepared_value, $field_obj);
2378
+		$unprepared_value = isset($fields_n_values[$field_obj->get_name()]) ? $fields_n_values[$field_obj->get_name()] : NULL;
2379
+		return $this->_prepare_value_for_use_in_db($unprepared_value, $field_obj);
2380 2380
 	}
2381 2381
 
2382 2382
 
@@ -2388,9 +2388,9 @@  discard block
 block discarded – undo
2388 2388
 	 * @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
2389 2389
 	 * @return mixed a value ready for use in the database for insertions, updating, or in a where clause
2390 2390
 	 */
2391
-	private function _prepare_value_for_use_in_db($value, $field){
2392
-		if($field && $field instanceof EE_Model_Field_Base){
2393
-			switch( $this->_values_already_prepared_by_model_object ){
2391
+	private function _prepare_value_for_use_in_db($value, $field) {
2392
+		if ($field && $field instanceof EE_Model_Field_Base) {
2393
+			switch ($this->_values_already_prepared_by_model_object) {
2394 2394
 				/** @noinspection PhpMissingBreakStatementInspection */
2395 2395
 				case self::not_prepared_by_model_object:
2396 2396
 					$value = $field->prepare_for_set($value);
@@ -2401,7 +2401,7 @@  discard block
 block discarded – undo
2401 2401
 					//leave the value alone
2402 2402
 			}
2403 2403
 			return $value;
2404
-		}else{
2404
+		} else {
2405 2405
 			return $value;
2406 2406
 		}
2407 2407
 	}
@@ -2411,13 +2411,13 @@  discard block
 block discarded – undo
2411 2411
 	 * @return EE_Primary_Table
2412 2412
 	 * @throws EE_Error
2413 2413
 	 */
2414
-	protected function _get_main_table(){
2415
-		foreach($this->_tables as $table){
2416
-			if($table instanceof EE_Primary_Table){
2414
+	protected function _get_main_table() {
2415
+		foreach ($this->_tables as $table) {
2416
+			if ($table instanceof EE_Primary_Table) {
2417 2417
 				return $table;
2418 2418
 			}
2419 2419
 		}
2420
-		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)));
2420
+		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)));
2421 2421
 	}
2422 2422
 
2423 2423
 	/**
@@ -2436,7 +2436,7 @@  discard block
 block discarded – undo
2436 2436
 	 */
2437 2437
 	public function second_table() {
2438 2438
 		// grab second table from tables array
2439
-		$second_table = end( $this->_tables );
2439
+		$second_table = end($this->_tables);
2440 2440
 		return $second_table instanceof EE_Secondary_Table ? $second_table->get_table_name() : NULL;
2441 2441
 	}
2442 2442
 
@@ -2449,8 +2449,8 @@  discard block
 block discarded – undo
2449 2449
 	 * @param string $table_alias
2450 2450
 	 * @return EE_Primary_Table | EE_Secondary_Table
2451 2451
 	 */
2452
-	public function get_table_obj_by_alias( $table_alias = '' ) {
2453
-		return isset( $this->_tables[ $table_alias ] ) ? $this->_tables[ $table_alias ] : NULL;
2452
+	public function get_table_obj_by_alias($table_alias = '') {
2453
+		return isset($this->_tables[$table_alias]) ? $this->_tables[$table_alias] : NULL;
2454 2454
 	}
2455 2455
 
2456 2456
 
@@ -2459,10 +2459,10 @@  discard block
 block discarded – undo
2459 2459
 	 * Gets all the tables of type EE_Other_Table from EEM_CPT_Basel_Model::_tables
2460 2460
 	 * @return EE_Secondary_Table[]
2461 2461
 	 */
2462
-	protected function _get_other_tables(){
2463
-		$other_tables =array();
2464
-		foreach($this->_tables as $table_alias => $table){
2465
-			if($table instanceof EE_Secondary_Table){
2462
+	protected function _get_other_tables() {
2463
+		$other_tables = array();
2464
+		foreach ($this->_tables as $table_alias => $table) {
2465
+			if ($table instanceof EE_Secondary_Table) {
2466 2466
 				$other_tables[$table_alias] = $table;
2467 2467
 			}
2468 2468
 		}
@@ -2474,7 +2474,7 @@  discard block
 block discarded – undo
2474 2474
 	 * @param string $table_alias, array key in EEM_Base::_tables
2475 2475
 	 * @return EE_Model_Field_Base[]
2476 2476
 	 */
2477
-	function _get_fields_for_table($table_alias){
2477
+	function _get_fields_for_table($table_alias) {
2478 2478
 		return $this->_fields[$table_alias];
2479 2479
 	}
2480 2480
 
@@ -2486,29 +2486,29 @@  discard block
 block discarded – undo
2486 2486
 	 * @param array $query_params like EEM_Base::get_all's $query_parameters['where']
2487 2487
 	 * @return EE_Model_Query_Info_Carrier
2488 2488
 	 */
2489
-	function _extract_related_models_from_query($query_params){
2489
+	function _extract_related_models_from_query($query_params) {
2490 2490
 		$query_info_carrier = new EE_Model_Query_Info_Carrier();
2491
-		if(array_key_exists(0,$query_params)){
2492
-			$this->_extract_related_models_from_sub_params_array_keys($query_params[0], $query_info_carrier,0);
2493
-		}
2494
-		if(array_key_exists('group_by', $query_params)){
2495
-			if(is_array($query_params['group_by'])){
2496
-				$this->_extract_related_models_from_sub_params_array_values($query_params['group_by'],$query_info_carrier,'group_by');
2497
-			}elseif( ! empty ( $query_params['group_by'] )){
2498
-				$this->_extract_related_model_info_from_query_param( $query_params['group_by'],$query_info_carrier,'group_by');
2491
+		if (array_key_exists(0, $query_params)) {
2492
+			$this->_extract_related_models_from_sub_params_array_keys($query_params[0], $query_info_carrier, 0);
2493
+		}
2494
+		if (array_key_exists('group_by', $query_params)) {
2495
+			if (is_array($query_params['group_by'])) {
2496
+				$this->_extract_related_models_from_sub_params_array_values($query_params['group_by'], $query_info_carrier, 'group_by');
2497
+			}elseif ( ! empty ($query_params['group_by'])) {
2498
+				$this->_extract_related_model_info_from_query_param($query_params['group_by'], $query_info_carrier, 'group_by');
2499 2499
 			}
2500 2500
 		}
2501
-		if(array_key_exists('having',$query_params)){
2502
-			$this->_extract_related_models_from_sub_params_array_keys($query_params[0], $query_info_carrier,'having');
2501
+		if (array_key_exists('having', $query_params)) {
2502
+			$this->_extract_related_models_from_sub_params_array_keys($query_params[0], $query_info_carrier, 'having');
2503 2503
 		}
2504
-		if(array_key_exists('order_by', $query_params)){
2505
-			if ( is_array( $query_params['order_by'] ) )
2506
-				$this->_extract_related_models_from_sub_params_array_keys($query_params['order_by'],$query_info_carrier,'order_by');
2507
-			elseif( ! empty( $query_params['order_by'] ))
2508
-				$this->_extract_related_model_info_from_query_param( $query_params['order_by'], $query_info_carrier,'order_by');
2504
+		if (array_key_exists('order_by', $query_params)) {
2505
+			if (is_array($query_params['order_by']))
2506
+				$this->_extract_related_models_from_sub_params_array_keys($query_params['order_by'], $query_info_carrier, 'order_by');
2507
+			elseif ( ! empty($query_params['order_by']))
2508
+				$this->_extract_related_model_info_from_query_param($query_params['order_by'], $query_info_carrier, 'order_by');
2509 2509
 		}
2510
-		if(array_key_exists('force_join', $query_params)){
2511
-			$this->_extract_related_models_from_sub_params_array_values($query_params['force_join'],$query_info_carrier,'force_join');
2510
+		if (array_key_exists('force_join', $query_params)) {
2511
+			$this->_extract_related_models_from_sub_params_array_values($query_params['force_join'], $query_info_carrier, 'force_join');
2512 2512
 		}
2513 2513
 		return $query_info_carrier;
2514 2514
 	}
@@ -2521,34 +2521,34 @@  discard block
 block discarded – undo
2521 2521
 	 * @throws EE_Error
2522 2522
 	 * @return \EE_Model_Query_Info_Carrier
2523 2523
 	 */
2524
-	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){
2525
-		if (!empty($sub_query_params)){
2524
+	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) {
2525
+		if ( ! empty($sub_query_params)) {
2526 2526
 			$sub_query_params = (array) $sub_query_params;
2527
-			foreach($sub_query_params as $param => $possibly_array_of_params){
2527
+			foreach ($sub_query_params as $param => $possibly_array_of_params) {
2528 2528
 				//$param could be simply 'EVT_ID', or it could be 'Registrations.REG_ID', or even 'Registrations.Transactions.Payments.PAY_amount'
2529
-				$this->_extract_related_model_info_from_query_param( $param, $model_query_info_carrier,$query_param_type);
2529
+				$this->_extract_related_model_info_from_query_param($param, $model_query_info_carrier, $query_param_type);
2530 2530
 
2531 2531
 				//if $possibly_array_of_params is an array, try recursing into it, searching for keys which
2532 2532
 				//indicate needed joins. Eg, array('NOT'=>array('Registration.TXN_ID'=>23)). In this case, we tried
2533 2533
 				//extracting models out of the 'NOT', which obviously wasn't successful, and then we recurse into the value
2534 2534
 				//of array('Registration.TXN_ID'=>23)
2535 2535
 				$query_param_sans_stars = $this->_remove_stars_and_anything_after_from_condition_query_param_key($param);
2536
-				if(in_array($query_param_sans_stars, $this->_logic_query_param_keys,true)){
2537
-					if (! is_array($possibly_array_of_params)){
2536
+				if (in_array($query_param_sans_stars, $this->_logic_query_param_keys, true)) {
2537
+					if ( ! is_array($possibly_array_of_params)) {
2538 2538
 						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"),
2539
-							$param,$possibly_array_of_params));
2540
-					}else{
2541
-						$this->_extract_related_models_from_sub_params_array_keys($possibly_array_of_params, $model_query_info_carrier,$query_param_type);
2539
+							$param, $possibly_array_of_params));
2540
+					} else {
2541
+						$this->_extract_related_models_from_sub_params_array_keys($possibly_array_of_params, $model_query_info_carrier, $query_param_type);
2542 2542
 					}
2543
-				}elseif($query_param_type === 0 //ie WHERE
2543
+				}elseif ($query_param_type === 0 //ie WHERE
2544 2544
 						&& is_array($possibly_array_of_params)
2545 2545
 						&& isset($possibly_array_of_params[2])
2546
-						&& $possibly_array_of_params[2] == true){
2546
+						&& $possibly_array_of_params[2] == true) {
2547 2547
 					//then $possible_array_of_params looks something like array('<','DTT_sold',true)
2548 2548
 					//indicating that $possible_array_of_params[1] is actually a field name,
2549 2549
 					//from which we should extract query parameters!
2550
-					if(! isset($possibly_array_of_params[0]) || ! isset($possibly_array_of_params[1])){
2551
-						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)));
2550
+					if ( ! isset($possibly_array_of_params[0]) || ! isset($possibly_array_of_params[1])) {
2551
+						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)));
2552 2552
 					}
2553 2553
 					$this->_extract_related_model_info_from_query_param($possibly_array_of_params[1], $model_query_info_carrier, $query_param_type);
2554 2554
 				}
@@ -2567,14 +2567,14 @@  discard block
 block discarded – undo
2567 2567
 	 * @throws EE_Error
2568 2568
 	 * @return \EE_Model_Query_Info_Carrier
2569 2569
 	 */
2570
-	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){
2571
-		if (!empty($sub_query_params)){
2572
-			if(!is_array($sub_query_params)){
2573
-				throw new EE_Error(sprintf(__("Query parameter %s should be an array, but it isn't.", "event_espresso"),$sub_query_params));
2570
+	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) {
2571
+		if ( ! empty($sub_query_params)) {
2572
+			if ( ! is_array($sub_query_params)) {
2573
+				throw new EE_Error(sprintf(__("Query parameter %s should be an array, but it isn't.", "event_espresso"), $sub_query_params));
2574 2574
 			}
2575
-			foreach($sub_query_params as $param){
2575
+			foreach ($sub_query_params as $param) {
2576 2576
 				//$param could be simply 'EVT_ID', or it could be 'Registrations.REG_ID', or even 'Registrations.Transactions.Payments.PAY_amount'
2577
-				$this->_extract_related_model_info_from_query_param( $param, $model_query_info_carrier, $query_param_type);
2577
+				$this->_extract_related_model_info_from_query_param($param, $model_query_info_carrier, $query_param_type);
2578 2578
 			}
2579 2579
 		}
2580 2580
 		return $model_query_info_carrier;
@@ -2593,81 +2593,81 @@  discard block
 block discarded – undo
2593 2593
 	 * @throws EE_Error
2594 2594
 	 * @return EE_Model_Query_Info_Carrier
2595 2595
 	 */
2596
-	function _create_model_query_info_carrier($query_params){
2597
-		if( ! is_array( $query_params ) ){
2598
-			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' );
2596
+	function _create_model_query_info_carrier($query_params) {
2597
+		if ( ! is_array($query_params)) {
2598
+			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');
2599 2599
 			$query_params = array();
2600 2600
 		}
2601
-		if( isset( $query_params[0] ) ) {
2601
+		if (isset($query_params[0])) {
2602 2602
 			$where_query_params = $query_params[0];
2603
-		}else{
2603
+		} else {
2604 2604
 			$where_query_params = array();
2605 2605
 		}
2606 2606
 		//first check if we should alter the query to account for caps or not
2607 2607
 		//because the caps might require us to do extra joins
2608
-		if( isset( $query_params[ 'caps' ] ) && $query_params[ 'caps' ] != 'none' ) {
2609
-			$query_params[0] = $where_query_params = array_replace_recursive( $where_query_params, $this->caps_where_conditions( $query_params[ 'caps' ] ) );
2608
+		if (isset($query_params['caps']) && $query_params['caps'] != 'none') {
2609
+			$query_params[0] = $where_query_params = array_replace_recursive($where_query_params, $this->caps_where_conditions($query_params['caps']));
2610 2610
 		}
2611 2611
 		$query_object = $this->_extract_related_models_from_query($query_params);
2612 2612
 
2613 2613
 		//verify where_query_params has NO numeric indexes.... that's simply not how you use it!
2614
-		foreach($where_query_params as $key => $value){
2615
-			if(is_int($key)){
2616
-				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)));
2614
+		foreach ($where_query_params as $key => $value) {
2615
+			if (is_int($key)) {
2616
+				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)));
2617 2617
 			}
2618 2618
 		}
2619
-		if( array_key_exists( 'default_where_conditions',$query_params) && ! empty( $query_params['default_where_conditions'] )){
2619
+		if (array_key_exists('default_where_conditions', $query_params) && ! empty($query_params['default_where_conditions'])) {
2620 2620
 			$use_default_where_conditions = $query_params['default_where_conditions'];
2621
-		}else{
2621
+		} else {
2622 2622
 			$use_default_where_conditions = 'all';
2623 2623
 		}
2624
-		$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 );
2625
-		$query_object->set_where_sql( $this->_construct_where_clause($where_query_params));
2624
+		$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);
2625
+		$query_object->set_where_sql($this->_construct_where_clause($where_query_params));
2626 2626
 
2627 2627
 
2628 2628
 		//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:
2629 2629
 		//array( 'on_join_limit' => array('Primary_Table_Alias', array(1,10) ) )
2630
-		if ( array_key_exists('on_join_limit', $query_params ) && ! empty( $query_params['on_join_limit'] )) {
2631
-			$query_object->set_main_model_join_sql( $this->_construct_limit_join_select( $query_params['on_join_limit'][0], $query_params['on_join_limit'][1] ) );
2630
+		if (array_key_exists('on_join_limit', $query_params) && ! empty($query_params['on_join_limit'])) {
2631
+			$query_object->set_main_model_join_sql($this->_construct_limit_join_select($query_params['on_join_limit'][0], $query_params['on_join_limit'][1]));
2632 2632
 		}
2633 2633
 
2634 2634
 
2635 2635
 		//set limit
2636
-		if(array_key_exists('limit',$query_params)){
2637
-			if(is_array($query_params['limit'])){
2638
-				if( ! isset($query_params['limit'][0]) || ! isset($query_params['limit'][1])){
2639
-					$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']));
2636
+		if (array_key_exists('limit', $query_params)) {
2637
+			if (is_array($query_params['limit'])) {
2638
+				if ( ! isset($query_params['limit'][0]) || ! isset($query_params['limit'][1])) {
2639
+					$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']));
2640 2640
 					throw new EE_Error($e."|".$e);
2641 2641
 				}
2642 2642
 				//they passed us an array for the limit. Assume it's like array(50,25), meaning offset by 50, and get 25
2643 2643
 				$query_object->set_limit_sql(" LIMIT ".$query_params['limit'][0].",".$query_params['limit'][1]);
2644
-			}elseif( ! empty ( $query_params['limit'] )){
2644
+			}elseif ( ! empty ($query_params['limit'])) {
2645 2645
 				$query_object->set_limit_sql((" LIMIT ".$query_params['limit']));
2646 2646
 			}
2647 2647
 		}
2648 2648
 		//set order by
2649
-		if(array_key_exists('order_by',$query_params)){
2650
-			if(is_array($query_params['order_by'])){
2649
+		if (array_key_exists('order_by', $query_params)) {
2650
+			if (is_array($query_params['order_by'])) {
2651 2651
 				//if they're using 'order_by' as an array, they can't use 'order' (because 'order_by' must
2652 2652
 				//specify whether to ascend or descend on each field. Eg 'order_by'=>array('EVT_ID'=>'ASC'). So
2653 2653
 				//including 'order' wouldn't make any sense if 'order_by' has already specified which way to order!
2654
-				if(array_key_exists('order', $query_params)){
2654
+				if (array_key_exists('order', $query_params)) {
2655 2655
 					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"),
2656
-							get_class($this),implode(", ",array_keys($query_params['order_by'])),implode(", ",$query_params['order_by']),$query_params['order']));
2656
+							get_class($this), implode(", ", array_keys($query_params['order_by'])), implode(", ", $query_params['order_by']), $query_params['order']));
2657 2657
 				}
2658
-				 $this->_extract_related_models_from_sub_params_array_keys($query_params['order_by'],$query_object,'order_by');
2658
+				 $this->_extract_related_models_from_sub_params_array_keys($query_params['order_by'], $query_object, 'order_by');
2659 2659
 				//assume it's an array of fields to order by
2660 2660
 				$order_array = array();
2661
-				foreach($query_params['order_by'] as $field_name_to_order_by => $order){
2661
+				foreach ($query_params['order_by'] as $field_name_to_order_by => $order) {
2662 2662
 					$order = $this->_extract_order($order);
2663 2663
 					$order_array[] = $this->_deduce_column_name_from_query_param($field_name_to_order_by).SP.$order;
2664 2664
 				}
2665
-				$query_object->set_order_by_sql(" ORDER BY ".implode(",",$order_array));
2666
-			}elseif( ! empty ( $query_params['order_by'] )){
2667
-				$this->_extract_related_model_info_from_query_param($query_params['order_by'],$query_object,'order',$query_params['order_by']);
2668
-				if(isset($query_params['order'])){
2665
+				$query_object->set_order_by_sql(" ORDER BY ".implode(",", $order_array));
2666
+			}elseif ( ! empty ($query_params['order_by'])) {
2667
+				$this->_extract_related_model_info_from_query_param($query_params['order_by'], $query_object, 'order', $query_params['order_by']);
2668
+				if (isset($query_params['order'])) {
2669 2669
 					$order = $this->_extract_order($query_params['order']);
2670
-				}else{
2670
+				} else {
2671 2671
 					$order = 'DESC';
2672 2672
 				}
2673 2673
 				$query_object->set_order_by_sql(" ORDER BY ".$this->_deduce_column_name_from_query_param($query_params['order_by']).SP.$order);
@@ -2675,46 +2675,46 @@  discard block
 block discarded – undo
2675 2675
 		}
2676 2676
 
2677 2677
 		//if 'order_by' wasn't set, maybe they are just using 'order' on its own?
2678
-		if( ! array_key_exists('order_by',$query_params) && array_key_exists('order',$query_params) && ! empty( $query_params['order'] )){
2678
+		if ( ! array_key_exists('order_by', $query_params) && array_key_exists('order', $query_params) && ! empty($query_params['order'])) {
2679 2679
 			$pk_field = $this->get_primary_key_field();
2680 2680
 			$order = $this->_extract_order($query_params['order']);
2681 2681
 			$query_object->set_order_by_sql(" ORDER BY ".$pk_field->get_qualified_column().SP.$order);
2682 2682
 		}
2683 2683
 
2684 2684
 		//set group by
2685
-		if(array_key_exists('group_by',$query_params)){
2686
-			if(is_array($query_params['group_by'])){
2685
+		if (array_key_exists('group_by', $query_params)) {
2686
+			if (is_array($query_params['group_by'])) {
2687 2687
 				//it's an array, so assume we'll be grouping by a bunch of stuff
2688 2688
 				$group_by_array = array();
2689
-				foreach($query_params['group_by'] as $field_name_to_group_by){
2689
+				foreach ($query_params['group_by'] as $field_name_to_group_by) {
2690 2690
 					$group_by_array[] = $this->_deduce_column_name_from_query_param($field_name_to_group_by);
2691 2691
 				}
2692
-				$query_object->set_group_by_sql(" GROUP BY ".implode(", ",$group_by_array));
2693
-			}elseif( ! empty ( $query_params['group_by'] )){
2692
+				$query_object->set_group_by_sql(" GROUP BY ".implode(", ", $group_by_array));
2693
+			}elseif ( ! empty ($query_params['group_by'])) {
2694 2694
 				$query_object->set_group_by_sql(" GROUP BY ".$this->_deduce_column_name_from_query_param($query_params['group_by']));
2695 2695
 			}
2696 2696
 		}
2697 2697
 		//set having
2698
-		if(array_key_exists('having',$query_params) && $query_params['having']){
2699
-			$query_object->set_having_sql( $this->_construct_having_clause($query_params['having']));
2698
+		if (array_key_exists('having', $query_params) && $query_params['having']) {
2699
+			$query_object->set_having_sql($this->_construct_having_clause($query_params['having']));
2700 2700
 		}
2701 2701
 
2702 2702
 		//now, just verify they didn't pass anything wack
2703
-		foreach($query_params as $query_key => $query_value){
2704
-			if( ! in_array($query_key,$this->_allowed_query_params,true)){
2703
+		foreach ($query_params as $query_key => $query_value) {
2704
+			if ( ! in_array($query_key, $this->_allowed_query_params, true)) {
2705 2705
 				throw new EE_Error(
2706 2706
 					sprintf(
2707
-						__("You passed %s as a query parameter to %s, which is illegal! The allowed query parameters are %s",'event_espresso'),
2707
+						__("You passed %s as a query parameter to %s, which is illegal! The allowed query parameters are %s", 'event_espresso'),
2708 2708
 						$query_key,
2709 2709
 						get_class($this),
2710 2710
 //						print_r( $this->_allowed_query_params, TRUE )
2711
-						implode( ',', $this->_allowed_query_params )
2711
+						implode(',', $this->_allowed_query_params)
2712 2712
 					)
2713 2713
 				);
2714 2714
 			}
2715 2715
 		}
2716 2716
 		$main_model_join_sql = $query_object->get_main_model_join_sql();
2717
-		if ( empty( $main_model_join_sql ) )
2717
+		if (empty($main_model_join_sql))
2718 2718
 			$query_object->set_main_model_join_sql($this->_construct_internal_join());
2719 2719
 		return $query_object;
2720 2720
 	}
@@ -2725,17 +2725,17 @@  discard block
 block discarded – undo
2725 2725
 	 * @param string $context one of EEM_Base::valid_cap_contexts()
2726 2726
 	 * @return array like EEM_Base::get_all() 's $query_params[0]
2727 2727
 	 */
2728
-	public function caps_where_conditions( $context = self::caps_read ) {
2729
-		EEM_Base::verify_is_valid_cap_context( $context );
2728
+	public function caps_where_conditions($context = self::caps_read) {
2729
+		EEM_Base::verify_is_valid_cap_context($context);
2730 2730
 		$cap_where_conditions = array();
2731
-		$cap_restrictions = $this->caps_missing( $context );
2731
+		$cap_restrictions = $this->caps_missing($context);
2732 2732
 		/**
2733 2733
 		 * @var $cap_restrictions EE_Default_Where_Conditions[]
2734 2734
 		 */
2735
-		foreach( $cap_restrictions as $cap => $restriction_if_no_cap ) {
2736
-				$cap_where_conditions = array_replace_recursive( $cap_where_conditions, $restriction_if_no_cap->get_default_where_conditions() );
2735
+		foreach ($cap_restrictions as $cap => $restriction_if_no_cap) {
2736
+				$cap_where_conditions = array_replace_recursive($cap_where_conditions, $restriction_if_no_cap->get_default_where_conditions());
2737 2737
 		}
2738
-		return apply_filters( 'FHEE__EEM_Base__caps_where_conditions__return', $cap_where_conditions, $this, $context, $cap_restrictions );
2738
+		return apply_filters('FHEE__EEM_Base__caps_where_conditions__return', $cap_where_conditions, $this, $context, $cap_restrictions);
2739 2739
 	}
2740 2740
 
2741 2741
 	/**
@@ -2745,11 +2745,11 @@  discard block
 block discarded – undo
2745 2745
 	 * @return string either ASC, asc, DESC or desc
2746 2746
 	 * @throws EE_Error
2747 2747
 	 */
2748
-	private function _extract_order($should_be_order_string){
2749
-		if(in_array($should_be_order_string, $this->_allowed_order_values)){
2748
+	private function _extract_order($should_be_order_string) {
2749
+		if (in_array($should_be_order_string, $this->_allowed_order_values)) {
2750 2750
 			return $should_be_order_string;
2751
-		}else{
2752
-			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));
2751
+		} else {
2752
+			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));
2753 2753
 		}
2754 2754
 	}
2755 2755
 
@@ -2767,25 +2767,25 @@  discard block
 block discarded – undo
2767 2767
 	 * @throws EE_Error
2768 2768
 	 * @return array like $query_params[0], see EEM_Base::get_all for documentation
2769 2769
 	 */
2770
-	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()){
2771
-		$allowed_used_default_where_conditions_values = array('all', 'minimum', 'this_model_only', 'other_models_only','none');
2772
-		if( ! in_array($use_default_where_conditions,$allowed_used_default_where_conditions_values)){
2773
-			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)));
2770
+	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()) {
2771
+		$allowed_used_default_where_conditions_values = array('all', 'minimum', 'this_model_only', 'other_models_only', 'none');
2772
+		if ( ! in_array($use_default_where_conditions, $allowed_used_default_where_conditions_values)) {
2773
+			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)));
2774 2774
 		}
2775
-		if( in_array($use_default_where_conditions, array('all','this_model_only')) ){
2775
+		if (in_array($use_default_where_conditions, array('all', 'this_model_only'))) {
2776 2776
 			$universal_query_params = $this->_get_default_where_conditions();
2777
-		}elseif( $use_default_where_conditions == 'minimum' ) {
2777
+		}elseif ($use_default_where_conditions == 'minimum') {
2778 2778
 			$universal_query_params = $this->_get_minimum_where_conditions();
2779
-		}else{
2779
+		} else {
2780 2780
 			$universal_query_params = array();
2781 2781
 		}
2782 2782
 
2783
-		if(in_array($use_default_where_conditions,array('all', 'minimum',  'other_models_only'))){
2784
-			foreach($query_info_carrier->get_model_names_included() as $model_relation_path => $model_name){
2783
+		if (in_array($use_default_where_conditions, array('all', 'minimum', 'other_models_only'))) {
2784
+			foreach ($query_info_carrier->get_model_names_included() as $model_relation_path => $model_name) {
2785 2785
 				$related_model = $this->get_related_model_obj($model_name);
2786
-				if( $use_default_where_conditions == 'minimum' ) {
2786
+				if ($use_default_where_conditions == 'minimum') {
2787 2787
 					$related_model_universal_where_params = $related_model->_get_minimum_where_conditions($model_relation_path);
2788
-				}else{
2788
+				} else {
2789 2789
 					$related_model_universal_where_params = $related_model->_get_default_where_conditions($model_relation_path);
2790 2790
 				}
2791 2791
 
@@ -2812,22 +2812,22 @@  discard block
 block discarded – undo
2812 2812
 	 * @param string $model_relation_path like 'Transaction.Payment.'
2813 2813
 	 * @return array like EEM_Base::get_all's $query_params[0]
2814 2814
 	 */
2815
-	private function _override_defaults_or_make_null_friendly($default_where_conditions,$provided_where_conditions,$model,$model_relation_path){
2815
+	private function _override_defaults_or_make_null_friendly($default_where_conditions, $provided_where_conditions, $model, $model_relation_path) {
2816 2816
 		$null_friendly_where_conditions = array();
2817 2817
 		$none_overridden = true;
2818 2818
 		$or_condition_key_for_defaults = 'OR*'.get_class($model);
2819 2819
 
2820
-		foreach($default_where_conditions as $key => $val){
2821
-			if( isset($provided_where_conditions[$key])){
2820
+		foreach ($default_where_conditions as $key => $val) {
2821
+			if (isset($provided_where_conditions[$key])) {
2822 2822
 				$none_overridden = false;
2823
-			}else{
2823
+			} else {
2824 2824
 				$null_friendly_where_conditions[$or_condition_key_for_defaults]['AND'][$key] = $val;
2825 2825
 			}
2826 2826
 		}
2827
-		if( $none_overridden && $default_where_conditions){
2828
-			if($model->has_primary_key_field()){
2827
+		if ($none_overridden && $default_where_conditions) {
2828
+			if ($model->has_primary_key_field()) {
2829 2829
 				$null_friendly_where_conditions[$or_condition_key_for_defaults][$model_relation_path.".".$model->primary_key_name()] = array('IS NULL');
2830
-			}else{
2830
+			} else {
2831 2831
 				//@todo NO PK, use other defaults
2832 2832
 			}
2833 2833
 		}
@@ -2842,8 +2842,8 @@  discard block
 block discarded – undo
2842 2842
 	 * @param string $model_relation_path eg, path from Event to Payment is "Registration.Transaction.Payment."
2843 2843
 	 * @return array like EEM_Base::get_all's $query_params[0] (where conditions)
2844 2844
 	 */
2845
-	protected function _get_default_where_conditions($model_relation_path = null){
2846
-		if ( $this->_ignore_where_strategy )
2845
+	protected function _get_default_where_conditions($model_relation_path = null) {
2846
+		if ($this->_ignore_where_strategy)
2847 2847
 			return array();
2848 2848
 
2849 2849
 		return $this->_default_where_conditions_strategy->get_default_where_conditions($model_relation_path);
@@ -2857,8 +2857,8 @@  discard block
 block discarded – undo
2857 2857
 	 * @param string $model_relation_path eg, path from Event to Payment is "Registration.Transaction.Payment."
2858 2858
 	 * @return array like EEM_Base::get_all's $query_params[0] (where conditions)
2859 2859
 	 */
2860
-	private function _get_minimum_where_conditions($model_relation_path = null){
2861
-		if ( $this->_ignore_where_strategy )
2860
+	private function _get_minimum_where_conditions($model_relation_path = null) {
2861
+		if ($this->_ignore_where_strategy)
2862 2862
 			return array();
2863 2863
 
2864 2864
 		return $this->_default_where_conditions_strategy->get_minimum_where_conditions($model_relation_path);
@@ -2869,13 +2869,13 @@  discard block
 block discarded – undo
2869 2869
 	 * @param EE_Model_Query_Info_Carrier $model_query_info
2870 2870
 	 * @return string
2871 2871
 	 */
2872
-	private function _construct_default_select_sql(EE_Model_Query_Info_Carrier $model_query_info){
2872
+	private function _construct_default_select_sql(EE_Model_Query_Info_Carrier $model_query_info) {
2873 2873
 		$selects = $this->_get_columns_to_select_for_this_model();
2874
-		foreach($model_query_info->get_model_names_included() as $model_relation_chain => $name_of_other_model_included){
2874
+		foreach ($model_query_info->get_model_names_included() as $model_relation_chain => $name_of_other_model_included) {
2875 2875
 			$other_model_included = $this->get_related_model_obj($name_of_other_model_included);
2876 2876
 			$selects = array_merge($selects, $other_model_included->_get_columns_to_select_for_this_model($model_relation_chain));
2877 2877
 		}
2878
-		return implode(", ",$selects);
2878
+		return implode(", ", $selects);
2879 2879
 	}
2880 2880
 
2881 2881
 	/**
@@ -2884,19 +2884,19 @@  discard block
 block discarded – undo
2884 2884
 	 * @param string $model_relation_chain like 'Question.Question_Group.Event'
2885 2885
 	 * @return array numerically indexed, values are columns to select and rename, eg "Event.ID AS 'Event.ID'"
2886 2886
 	 */
2887
-	public function _get_columns_to_select_for_this_model($model_relation_chain = ''){
2887
+	public function _get_columns_to_select_for_this_model($model_relation_chain = '') {
2888 2888
 		$fields = $this->field_settings();
2889 2889
 		$selects = array();
2890 2890
 		$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());
2891
-		foreach($fields as $field_obj){
2892
-			$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()."'";
2891
+		foreach ($fields as $field_obj) {
2892
+			$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()."'";
2893 2893
 		}
2894 2894
 		//make sure we are also getting the PKs of each table
2895 2895
 		$tables = $this->get_tables();
2896
-		if(count($tables) > 1){
2897
-			foreach($tables as $table_obj){
2898
-				$qualified_pk_column = $table_alias_with_model_relation_chain_prefix . $table_obj->get_fully_qualified_pk_column();
2899
-				if( ! in_array($qualified_pk_column,$selects)){
2896
+		if (count($tables) > 1) {
2897
+			foreach ($tables as $table_obj) {
2898
+				$qualified_pk_column = $table_alias_with_model_relation_chain_prefix.$table_obj->get_fully_qualified_pk_column();
2899
+				if ( ! in_array($qualified_pk_column, $selects)) {
2900 2900
 					$selects[] = "$qualified_pk_column AS '$qualified_pk_column'";
2901 2901
 				}
2902 2902
 			}
@@ -2920,66 +2920,66 @@  discard block
 block discarded – undo
2920 2920
 	 * @throws EE_Error
2921 2921
 	 * @return void only modifies the EEM_Related_Model_Info_Carrier passed into it
2922 2922
 	 */
2923
-	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 ){
2924
-		if($original_query_param == NULL){
2923
+	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) {
2924
+		if ($original_query_param == NULL) {
2925 2925
 			$original_query_param = $query_param;
2926 2926
 		}
2927 2927
 		$query_param = $this->_remove_stars_and_anything_after_from_condition_query_param_key($query_param);
2928 2928
 		/** @var $allow_logic_query_params bool whether or not to allow logic_query_params like 'NOT','OR', or 'AND' */
2929
-		$allow_logic_query_params = in_array($query_param_type,array('where','having'));
2930
-		$allow_fields = in_array($query_param_type,array('where','having','order_by','group_by','order'));
2929
+		$allow_logic_query_params = in_array($query_param_type, array('where', 'having'));
2930
+		$allow_fields = in_array($query_param_type, array('where', 'having', 'order_by', 'group_by', 'order'));
2931 2931
 		//check to see if we have a field on this model
2932 2932
 		$this_model_fields = $this->field_settings(true);
2933
-		if(array_key_exists($query_param,$this_model_fields)){
2934
-			if($allow_fields){
2933
+		if (array_key_exists($query_param, $this_model_fields)) {
2934
+			if ($allow_fields) {
2935 2935
 				return;
2936
-			}else{
2936
+			} else {
2937 2937
 				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"),
2938
-						$query_param,get_class($this),$query_param_type,$original_query_param));
2938
+						$query_param, get_class($this), $query_param_type, $original_query_param));
2939 2939
 			}
2940 2940
 		}
2941 2941
 		//check if this is a special logic query param
2942
-		elseif(in_array($query_param, $this->_logic_query_param_keys, TRUE)){
2943
-			if($allow_logic_query_params){
2942
+		elseif (in_array($query_param, $this->_logic_query_param_keys, TRUE)) {
2943
+			if ($allow_logic_query_params) {
2944 2944
 				return;
2945
-			}else{
2945
+			} else {
2946 2946
 				throw new EE_Error(
2947 2947
 					sprintf(
2948
-						__( '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' ),
2949
-						implode( '", "', $this->_logic_query_param_keys ),
2950
-						$query_param ,
2951
-						get_class( $this ),
2948
+						__('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'),
2949
+						implode('", "', $this->_logic_query_param_keys),
2950
+						$query_param,
2951
+						get_class($this),
2952 2952
 						'<br />',
2953
-						"\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
2953
+						"\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
2954 2954
 					)
2955 2955
 				);
2956 2956
 			}
2957 2957
 		}
2958 2958
 
2959 2959
 		//check if it's a custom selection
2960
-		elseif(array_key_exists($query_param,$this->_custom_selections)){
2960
+		elseif (array_key_exists($query_param, $this->_custom_selections)) {
2961 2961
 			return;
2962 2962
 		}
2963 2963
 
2964 2964
 		//check if has a model name at the beginning
2965 2965
 		//and
2966 2966
 		//check if it's a field on a related model
2967
-		foreach($this->_model_relations as $valid_related_model_name=>$relation_obj){
2968
-			if(strpos($query_param, $valid_related_model_name.".") === 0){
2969
-				$this->_add_join_to_model($valid_related_model_name, $passed_in_query_info,$original_query_param);
2967
+		foreach ($this->_model_relations as $valid_related_model_name=>$relation_obj) {
2968
+			if (strpos($query_param, $valid_related_model_name.".") === 0) {
2969
+				$this->_add_join_to_model($valid_related_model_name, $passed_in_query_info, $original_query_param);
2970 2970
 				$query_param = substr($query_param, strlen($valid_related_model_name."."));
2971
-				if($query_param == ''){
2971
+				if ($query_param == '') {
2972 2972
 					//nothing left to $query_param
2973 2973
 					//we should actually end in a field name, not a model like this!
2974 2974
 					throw new EE_Error(sprintf(__("Query param '%s' (of type %s on model %s) shouldn't end on a period (.) ", "event_espresso"),
2975
-					$query_param,$query_param_type,get_class($this),$valid_related_model_name));
2976
-				}else{
2975
+					$query_param, $query_param_type, get_class($this), $valid_related_model_name));
2976
+				} else {
2977 2977
 					$related_model_obj = $this->get_related_model_obj($valid_related_model_name);
2978 2978
 					$related_model_obj->_extract_related_model_info_from_query_param($query_param, $passed_in_query_info, $query_param_type, $original_query_param);
2979 2979
 					return;
2980 2980
 				}
2981
-			}elseif($query_param == $valid_related_model_name){
2982
-				$this->_add_join_to_model($valid_related_model_name, $passed_in_query_info,$original_query_param);
2981
+			}elseif ($query_param == $valid_related_model_name) {
2982
+				$this->_add_join_to_model($valid_related_model_name, $passed_in_query_info, $original_query_param);
2983 2983
 				return;
2984 2984
 			}
2985 2985
 		}
@@ -2989,7 +2989,7 @@  discard block
 block discarded – undo
2989 2989
 		//and we previously confirmed it wasn't a logic query param or field on the current model
2990 2990
 		//it's wack, that's what it is
2991 2991
 		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"),
2992
-				$query_param,get_class($this),$query_param_type,$original_query_param));
2992
+				$query_param, get_class($this), $query_param_type, $original_query_param));
2993 2993
 
2994 2994
 	}
2995 2995
 
@@ -3006,26 +3006,26 @@  discard block
 block discarded – undo
3006 3006
 	 * 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)
3007 3007
 	 * @return void
3008 3008
 	 */
3009
-	private function _add_join_to_model($model_name, EE_Model_Query_Info_Carrier $passed_in_query_info,$original_query_param){
3009
+	private function _add_join_to_model($model_name, EE_Model_Query_Info_Carrier $passed_in_query_info, $original_query_param) {
3010 3010
 		$relation_obj = $this->related_settings_for($model_name);
3011 3011
 
3012 3012
 		$model_relation_chain = EE_Model_Parser::extract_model_relation_chain($model_name, $original_query_param);
3013 3013
 		//check if the relation is HABTM, because then we're essentially doing two joins
3014 3014
 		//If so, join first to the JOIN table, and add its data types, and then continue as normal
3015
-		if($relation_obj instanceof EE_HABTM_Relation){
3015
+		if ($relation_obj instanceof EE_HABTM_Relation) {
3016 3016
 			$join_model_obj = $relation_obj->get_join_model();
3017 3017
 			//replace the model specified with the join model for this relation chain, whi
3018 3018
 			$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);
3019 3019
 			$new_query_info = new EE_Model_Query_Info_Carrier(
3020 3020
 					array($relation_chain_to_join_model => $join_model_obj->get_this_model_name()),
3021 3021
 					$relation_obj->get_join_to_intermediate_model_statement($relation_chain_to_join_model));
3022
-			$passed_in_query_info->merge( $new_query_info  );
3022
+			$passed_in_query_info->merge($new_query_info);
3023 3023
 		}
3024 3024
 		//now just join to the other table pointed to by the relation object, and add its data types
3025 3025
 		$new_query_info = new EE_Model_Query_Info_Carrier(
3026 3026
 				array($model_relation_chain=>$model_name),
3027 3027
 				$relation_obj->get_join_statement($model_relation_chain));
3028
-		$passed_in_query_info->merge( $new_query_info  );
3028
+		$passed_in_query_info->merge($new_query_info);
3029 3029
 	}
3030 3030
 
3031 3031
 
@@ -3034,11 +3034,11 @@  discard block
 block discarded – undo
3034 3034
 	 * @param array $where_params like EEM_Base::get_all
3035 3035
 	 * @return string of SQL
3036 3036
 	 */
3037
-	private function _construct_where_clause($where_params){
3037
+	private function _construct_where_clause($where_params) {
3038 3038
 		$SQL = $this->_construct_condition_clause_recursive($where_params, ' AND ');
3039
-		if($SQL){
3040
-			return " WHERE ". $SQL;
3041
-		}else{
3039
+		if ($SQL) {
3040
+			return " WHERE ".$SQL;
3041
+		} else {
3042 3042
 			return '';
3043 3043
 		}
3044 3044
 	}
@@ -3049,11 +3049,11 @@  discard block
 block discarded – undo
3049 3049
 	 * @param array $having_params
3050 3050
 	 * @return string
3051 3051
 	 */
3052
-	private function _construct_having_clause($having_params){
3052
+	private function _construct_having_clause($having_params) {
3053 3053
 		$SQL = $this->_construct_condition_clause_recursive($having_params, ' AND ');
3054
-		if($SQL){
3055
-			return " HAVING ". $SQL;
3056
-		}else{
3054
+		if ($SQL) {
3055
+			return " HAVING ".$SQL;
3056
+		} else {
3057 3057
 			return '';
3058 3058
 		}
3059 3059
 
@@ -3067,17 +3067,17 @@  discard block
 block discarded – undo
3067 3067
 	 * @return EE_Model_Field_Base
3068 3068
 	 * @throws EE_Error
3069 3069
 	 */
3070
-	protected function _get_field_on_model($field_name,$model_name){
3070
+	protected function _get_field_on_model($field_name, $model_name) {
3071 3071
 		$model_class = 'EEM_'.$model_name;
3072 3072
 		$model_filepath = $model_class.".model.php";
3073
-		EE_Registry::instance()->load_helper( 'File' );
3074
-		if ( is_readable($model_filepath)){
3073
+		EE_Registry::instance()->load_helper('File');
3074
+		if (is_readable($model_filepath)) {
3075 3075
 			require_once($model_filepath);
3076
-			$model_instance=call_user_func($model_name."::instance");
3076
+			$model_instance = call_user_func($model_name."::instance");
3077 3077
 			/* @var $model_instance EEM_Base */
3078 3078
 			return $model_instance->field_settings_for($field_name);
3079
-		}else{
3080
-			throw new EE_Error(sprintf(__('No model named %s exists, with classname %s and filepath %s','event_espresso'),$model_name,$model_class,$model_filepath));
3079
+		} else {
3080
+			throw new EE_Error(sprintf(__('No model named %s exists, with classname %s and filepath %s', 'event_espresso'), $model_name, $model_class, $model_filepath));
3081 3081
 		}
3082 3082
 	}
3083 3083
 
@@ -3090,43 +3090,43 @@  discard block
 block discarded – undo
3090 3090
 	 * @throws EE_Error
3091 3091
 	 * @return string of SQL
3092 3092
 	 */
3093
-	private function _construct_condition_clause_recursive($where_params, $glue = ' AND'){
3094
-		$where_clauses=array();
3095
-		foreach($where_params as $query_param => $op_and_value_or_sub_condition){
3096
-			$query_param = $this->_remove_stars_and_anything_after_from_condition_query_param_key($query_param);//str_replace("*",'',$query_param);
3097
-			if(in_array($query_param,$this->_logic_query_param_keys)){
3098
-				switch($query_param){
3093
+	private function _construct_condition_clause_recursive($where_params, $glue = ' AND') {
3094
+		$where_clauses = array();
3095
+		foreach ($where_params as $query_param => $op_and_value_or_sub_condition) {
3096
+			$query_param = $this->_remove_stars_and_anything_after_from_condition_query_param_key($query_param); //str_replace("*",'',$query_param);
3097
+			if (in_array($query_param, $this->_logic_query_param_keys)) {
3098
+				switch ($query_param) {
3099 3099
 					case 'not':
3100 3100
 					case 'NOT':
3101
-						$where_clauses[] = "! (". $this->_construct_condition_clause_recursive($op_and_value_or_sub_condition, $glue).")";
3101
+						$where_clauses[] = "! (".$this->_construct_condition_clause_recursive($op_and_value_or_sub_condition, $glue).")";
3102 3102
 						break;
3103 3103
 					case 'and':
3104 3104
 					case 'AND':
3105
-						$where_clauses[] = " (". $this->_construct_condition_clause_recursive($op_and_value_or_sub_condition, ' AND ') .")";
3105
+						$where_clauses[] = " (".$this->_construct_condition_clause_recursive($op_and_value_or_sub_condition, ' AND ').")";
3106 3106
 						break;
3107 3107
 					case 'or':
3108 3108
 					case 'OR':
3109
-						$where_clauses[] = " (". $this->_construct_condition_clause_recursive($op_and_value_or_sub_condition, ' OR ') .")";
3109
+						$where_clauses[] = " (".$this->_construct_condition_clause_recursive($op_and_value_or_sub_condition, ' OR ').")";
3110 3110
 						break;
3111 3111
 				}
3112
-			}else{
3112
+			} else {
3113 3113
 				$field_obj = $this->_deduce_field_from_query_param($query_param);
3114 3114
 
3115 3115
 				//if it's not a normal field, maybe it's a custom selection?
3116
-				if( ! $field_obj){
3117
-					if(isset( $this->_custom_selections[$query_param][1])){
3116
+				if ( ! $field_obj) {
3117
+					if (isset($this->_custom_selections[$query_param][1])) {
3118 3118
 						$field_obj = $this->_custom_selections[$query_param][1];
3119
-					}else{
3120
-						throw new EE_Error(sprintf(__("%s is neither a valid model field name, nor a custom selection", "event_espresso"),$query_param));
3119
+					} else {
3120
+						throw new EE_Error(sprintf(__("%s is neither a valid model field name, nor a custom selection", "event_espresso"), $query_param));
3121 3121
 					}
3122 3122
 				}
3123 3123
 				$op_and_value_sql = $this->_construct_op_and_value($op_and_value_or_sub_condition, $field_obj);
3124
-				$where_clauses[]=$this->_deduce_column_name_from_query_param($query_param).SP.$op_and_value_sql;
3124
+				$where_clauses[] = $this->_deduce_column_name_from_query_param($query_param).SP.$op_and_value_sql;
3125 3125
 			}
3126 3126
 		}
3127
-		if($where_clauses){
3128
-			$SQL = implode($glue,$where_clauses);
3129
-		}else{
3127
+		if ($where_clauses) {
3128
+			$SQL = implode($glue, $where_clauses);
3129
+		} else {
3130 3130
 			$SQL = '';
3131 3131
 		}
3132 3132
 		return $SQL;
@@ -3140,18 +3140,18 @@  discard block
 block discarded – undo
3140 3140
 	 * @throws EE_Error
3141 3141
 	 * @return string table alias and column name for SQL, eg "Transaction.TXN_ID"
3142 3142
 	 */
3143
-	private function _deduce_column_name_from_query_param($query_param){
3143
+	private function _deduce_column_name_from_query_param($query_param) {
3144 3144
 		$field = $this->_deduce_field_from_query_param($query_param);
3145 3145
 
3146
-		if( $field ){
3147
-			$table_alias_prefix = EE_Model_Parser::extract_table_alias_model_relation_chain_from_query_param( $field->get_model_name(), $query_param );
3148
-			return $table_alias_prefix . $field->get_qualified_column();
3149
-		}elseif(array_key_exists($query_param,$this->_custom_selections)){
3146
+		if ($field) {
3147
+			$table_alias_prefix = EE_Model_Parser::extract_table_alias_model_relation_chain_from_query_param($field->get_model_name(), $query_param);
3148
+			return $table_alias_prefix.$field->get_qualified_column();
3149
+		}elseif (array_key_exists($query_param, $this->_custom_selections)) {
3150 3150
 			//maybe it's custom selection item?
3151 3151
 			//if so, just use it as the "column name"
3152 3152
 			return $query_param;
3153
-		}else{
3154
-			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)));
3153
+		} else {
3154
+			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)));
3155 3155
 		}
3156 3156
 	}
3157 3157
 
@@ -3163,11 +3163,11 @@  discard block
 block discarded – undo
3163 3163
 	 * @param string $condition_query_param_key
3164 3164
 	 * @return string
3165 3165
 	 */
3166
-	private function _remove_stars_and_anything_after_from_condition_query_param_key($condition_query_param_key){
3166
+	private function _remove_stars_and_anything_after_from_condition_query_param_key($condition_query_param_key) {
3167 3167
 		$pos_of_star = strpos($condition_query_param_key, '*');
3168
-		if($pos_of_star === FALSE){
3168
+		if ($pos_of_star === FALSE) {
3169 3169
 			return $condition_query_param_key;
3170
-		}else{
3170
+		} else {
3171 3171
 			$condition_query_param_sans_star = substr($condition_query_param_key, 0, $pos_of_star);
3172 3172
 			return $condition_query_param_sans_star;
3173 3173
 		}
@@ -3182,54 +3182,54 @@  discard block
 block discarded – undo
3182 3182
 	 * @throws EE_Error
3183 3183
 	 * @return string
3184 3184
 	 */
3185
-	private function _construct_op_and_value($op_and_value, $field_obj){
3186
-		if(is_array( $op_and_value )){
3185
+	private function _construct_op_and_value($op_and_value, $field_obj) {
3186
+		if (is_array($op_and_value)) {
3187 3187
 			$operator = isset($op_and_value[0]) ? $this->_prepare_operator_for_sql($op_and_value[0]) : null;
3188
-			if( ! $operator){
3188
+			if ( ! $operator) {
3189 3189
 				$php_array_like_string = array();
3190
-				foreach($op_and_value as $key => $value){
3190
+				foreach ($op_and_value as $key => $value) {
3191 3191
 					$php_array_like_string[] = "$key=>$value";
3192 3192
 				}
3193
-				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)));
3193
+				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)));
3194 3194
 			}
3195 3195
 			$value = isset($op_and_value[1]) ? $op_and_value[1] : null;
3196
-		}else{
3196
+		} else {
3197 3197
 			$operator = '=';
3198 3198
 			$value = $op_and_value;
3199 3199
 		}
3200 3200
 
3201 3201
 		//check to see if the value is actually another field
3202
-		if(is_array($op_and_value) && isset($op_and_value[2]) && $op_and_value[2] == true){
3202
+		if (is_array($op_and_value) && isset($op_and_value[2]) && $op_and_value[2] == true) {
3203 3203
 			return $operator.SP.$this->_deduce_column_name_from_query_param($value);
3204
-		}elseif(in_array($operator, $this->_in_style_operators) && is_array($value)){
3204
+		}elseif (in_array($operator, $this->_in_style_operators) && is_array($value)) {
3205 3205
 			//in this case, the value should be an array, or at least a comma-separated list
3206 3206
 			//it will need to handle a little differently
3207 3207
 			$cleaned_value = $this->_construct_in_value($value, $field_obj);
3208 3208
 			//note: $cleaned_value has already been run through $wpdb->prepare()
3209 3209
 			return $operator.SP.$cleaned_value;
3210
-		} elseif( in_array( $operator, $this->_between_style_operators ) && is_array( $value ) ) {
3210
+		} elseif (in_array($operator, $this->_between_style_operators) && is_array($value)) {
3211 3211
 			//the value should be an array with count of two.
3212
-			if ( count($value) !== 2 )
3213
-				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" ) );
3214
-			$cleaned_value = $this->_construct_between_value( $value, $field_obj );
3212
+			if (count($value) !== 2)
3213
+				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"));
3214
+			$cleaned_value = $this->_construct_between_value($value, $field_obj);
3215 3215
 			return $operator.SP.$cleaned_value;
3216
-		} elseif( in_array( $operator, $this->_null_style_operators ) ) {
3217
-			if($value != NULL){
3218
-				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));
3216
+		} elseif (in_array($operator, $this->_null_style_operators)) {
3217
+			if ($value != NULL) {
3218
+				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));
3219 3219
 			}
3220 3220
 			return $operator;
3221
-		}elseif( $operator == 'LIKE' && ! is_array($value)){
3221
+		}elseif ($operator == 'LIKE' && ! is_array($value)) {
3222 3222
 			//if the operator is 'LIKE', we want to allow percent signs (%) and not
3223 3223
 			//remove other junk. So just treat it as a string.
3224 3224
 			return $operator.SP.$this->_wpdb_prepare_using_field($value, '%s');
3225
-		}elseif( ! in_array($operator, $this->_in_style_operators) && ! is_array($value)){
3226
-			return $operator.SP.$this->_wpdb_prepare_using_field($value,$field_obj);
3227
-		}elseif(in_array($operator, $this->_in_style_operators) && ! is_array($value)){
3228
-			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));
3229
-		}elseif( ! in_array($operator, $this->_in_style_operators) && is_array($value)){
3230
-			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));
3231
-		}else{
3232
-			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)));
3225
+		}elseif ( ! in_array($operator, $this->_in_style_operators) && ! is_array($value)) {
3226
+			return $operator.SP.$this->_wpdb_prepare_using_field($value, $field_obj);
3227
+		}elseif (in_array($operator, $this->_in_style_operators) && ! is_array($value)) {
3228
+			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));
3229
+		}elseif ( ! in_array($operator, $this->_in_style_operators) && is_array($value)) {
3230
+			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));
3231
+		} else {
3232
+			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)));
3233 3233
 		}
3234 3234
 	}
3235 3235
 
@@ -3241,12 +3241,12 @@  discard block
 block discarded – undo
3241 3241
 	 * @param EE_Model_Field_Base|string $field_obj if string, it should be the datatype to be used when querying, eg '%s'
3242 3242
 	 * @return string
3243 3243
 	 */
3244
-	function _construct_between_value( $values, $field_obj ) {
3244
+	function _construct_between_value($values, $field_obj) {
3245 3245
 		$cleaned_values = array();
3246
-		foreach ( $values as $value ) {
3247
-			$cleaned_values[] = $this->_wpdb_prepare_using_field($value,$field_obj);
3246
+		foreach ($values as $value) {
3247
+			$cleaned_values[] = $this->_wpdb_prepare_using_field($value, $field_obj);
3248 3248
 		}
3249
-		return  $cleaned_values[0] . " AND " . $cleaned_values[1];
3249
+		return  $cleaned_values[0]." AND ".$cleaned_values[1];
3250 3250
 	}
3251 3251
 
3252 3252
 
@@ -3262,26 +3262,26 @@  discard block
 block discarded – undo
3262 3262
 	 * @param EE_Model_Field_Base|string $field_obj if string, it should be a wpdb data type like '%s', or '%d'
3263 3263
 	 * @return string of SQL to follow an 'IN' or 'NOT IN' operator
3264 3264
 	 */
3265
-	function _construct_in_value($values,  $field_obj){
3265
+	function _construct_in_value($values, $field_obj) {
3266 3266
 		//check if the value is a CSV list
3267
-		if(is_string($values)){
3267
+		if (is_string($values)) {
3268 3268
 			//in which case, turn it into an array
3269
-			$values = explode(",",$values);
3269
+			$values = explode(",", $values);
3270 3270
 		}
3271 3271
 		$cleaned_values = array();
3272
-		foreach($values as $value){
3273
-			$cleaned_values[] = $this->_wpdb_prepare_using_field($value,$field_obj);
3272
+		foreach ($values as $value) {
3273
+			$cleaned_values[] = $this->_wpdb_prepare_using_field($value, $field_obj);
3274 3274
 		}
3275 3275
 		//we would just LOVE to leave $cleaned_values as an empty array, and return the value as "()",
3276 3276
 		//but unfortunately that's invalid SQL. So instead we return a string which we KNOW will evaluate to be the empty set
3277 3277
 		//which is effectively equivalent to returning "()". We don't return "(0)" because that only works for auto-incrementing columns
3278
-		if(empty($cleaned_values)){
3278
+		if (empty($cleaned_values)) {
3279 3279
 			$all_fields = $this->field_settings();
3280 3280
 			$a_field = array_shift($all_fields);
3281 3281
 			$main_table = $this->_get_main_table();
3282 3282
 			$cleaned_values[] = "SELECT ".$a_field->get_table_column()." FROM ".$main_table->get_table_name()." WHERE FALSE";
3283 3283
 		}
3284
-		return "(".implode(",",$cleaned_values).")";
3284
+		return "(".implode(",", $cleaned_values).")";
3285 3285
 	}
3286 3286
 
3287 3287
 
@@ -3293,16 +3293,16 @@  discard block
 block discarded – undo
3293 3293
 	 * @throws EE_Error
3294 3294
 	 * @return false|null|string
3295 3295
 	 */
3296
-	private function _wpdb_prepare_using_field($value,$field_obj){
3296
+	private function _wpdb_prepare_using_field($value, $field_obj) {
3297 3297
 		/** @type WPDB $wpdb */
3298 3298
 		global $wpdb;
3299
-		if($field_obj instanceof EE_Model_Field_Base){
3300
-			return $wpdb->prepare($field_obj->get_wpdb_data_type(),$this->_prepare_value_for_use_in_db($value, $field_obj));
3301
-		}else{//$field_obj should really just be a data type
3302
-			if( ! in_array($field_obj,$this->_valid_wpdb_data_types)){
3303
-				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)));
3299
+		if ($field_obj instanceof EE_Model_Field_Base) {
3300
+			return $wpdb->prepare($field_obj->get_wpdb_data_type(), $this->_prepare_value_for_use_in_db($value, $field_obj));
3301
+		} else {//$field_obj should really just be a data type
3302
+			if ( ! in_array($field_obj, $this->_valid_wpdb_data_types)) {
3303
+				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)));
3304 3304
 			}
3305
-			return $wpdb->prepare($field_obj,$value);
3305
+			return $wpdb->prepare($field_obj, $value);
3306 3306
 		}
3307 3307
 	}
3308 3308
 
@@ -3314,27 +3314,27 @@  discard block
 block discarded – undo
3314 3314
 	 * @throws EE_Error
3315 3315
 	 * @return EE_Model_Field_Base
3316 3316
 	 */
3317
-	protected function _deduce_field_from_query_param($query_param_name){
3317
+	protected function _deduce_field_from_query_param($query_param_name) {
3318 3318
 		//ok, now proceed with deducing which part is the model's name, and which is the field's name
3319 3319
 		//which will help us find the database table and column
3320 3320
 
3321
-		$query_param_parts = explode(".",$query_param_name);
3322
-		if(empty($query_param_parts)){
3323
-			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));
3321
+		$query_param_parts = explode(".", $query_param_name);
3322
+		if (empty($query_param_parts)) {
3323
+			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));
3324 3324
 		}
3325 3325
 		$number_of_parts = count($query_param_parts);
3326
-		$last_query_param_part = $query_param_parts[ count($query_param_parts) - 1 ];
3327
-		if($number_of_parts == 1){
3326
+		$last_query_param_part = $query_param_parts[count($query_param_parts) - 1];
3327
+		if ($number_of_parts == 1) {
3328 3328
 			$field_name = $last_query_param_part;
3329 3329
 			$model_obj = $this;
3330
-		}else{// $number_of_parts >= 2
3330
+		} else {// $number_of_parts >= 2
3331 3331
 			//the last part is the column name, and there are only 2parts. therefore...
3332 3332
 			$field_name = $last_query_param_part;
3333
-			$model_obj = $this->get_related_model_obj( $query_param_parts[ $number_of_parts - 2 ]);
3333
+			$model_obj = $this->get_related_model_obj($query_param_parts[$number_of_parts - 2]);
3334 3334
 		}
3335
-		try{
3335
+		try {
3336 3336
 			return $model_obj->field_settings_for($field_name);
3337
-		}catch(EE_Error $e){
3337
+		} catch (EE_Error $e) {
3338 3338
 			return null;
3339 3339
 		}
3340 3340
 	}
@@ -3348,13 +3348,13 @@  discard block
 block discarded – undo
3348 3348
 	 * @throws EE_Error
3349 3349
 	 * @return string
3350 3350
 	 */
3351
-	function _get_qualified_column_for_field($field_name){
3351
+	function _get_qualified_column_for_field($field_name) {
3352 3352
 		$all_fields = $this->field_settings();
3353 3353
 		$field = isset($all_fields[$field_name]) ? $all_fields[$field_name] : FALSE;
3354
-		if($field){
3354
+		if ($field) {
3355 3355
 			return $field->get_qualified_column();
3356
-		}else{
3357
-			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)));
3356
+		} else {
3357
+			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)));
3358 3358
 		}
3359 3359
 	}
3360 3360
 
@@ -3368,14 +3368,14 @@  discard block
 block discarded – undo
3368 3368
 	 * @param  mixed|string $limit The limit for this select
3369 3369
 	 * @return string 				The final select join element for the query.
3370 3370
 	 */
3371
-	function _construct_limit_join_select( $table_alias, $limit ) {
3371
+	function _construct_limit_join_select($table_alias, $limit) {
3372 3372
 		$SQL = '';
3373 3373
 
3374
-		foreach ( $this->_tables as $table_obj ) {
3375
-			if ( $table_obj instanceof EE_Primary_Table ) {
3376
-				$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;
3377
-			} elseif ( $table_obj instanceof EE_Secondary_Table ) {
3378
-				$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;
3374
+		foreach ($this->_tables as $table_obj) {
3375
+			if ($table_obj instanceof EE_Primary_Table) {
3376
+				$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;
3377
+			} elseif ($table_obj instanceof EE_Secondary_Table) {
3378
+				$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;
3379 3379
 			}
3380 3380
 		}
3381 3381
 		return $SQL;
@@ -3388,7 +3388,7 @@  discard block
 block discarded – undo
3388 3388
 	 * Eg "wp_post AS Event" or "wp_post AS Event INNER JOIN wp_postmeta Event_Meta ON Event.ID = Event_Meta.post_id"
3389 3389
 	 * @return string SQL
3390 3390
 	 */
3391
-	function _construct_internal_join(){
3391
+	function _construct_internal_join() {
3392 3392
 		$SQL = $this->_get_main_table()->get_table_sql();
3393 3393
 		$SQL .= $this->_construct_internal_join_to_table_with_alias($this->_get_main_table()->get_table_alias());
3394 3394
 		return $SQL;
@@ -3409,17 +3409,17 @@  discard block
 block discarded – undo
3409 3409
 	 * @param string $alias_prefixed table alias to join to (this table should already be in the FROM SQL clause)
3410 3410
 	 * @return string
3411 3411
 	 */
3412
-	function _construct_internal_join_to_table_with_alias($alias_prefixed){
3412
+	function _construct_internal_join_to_table_with_alias($alias_prefixed) {
3413 3413
 		$SQL = '';
3414 3414
 		$alias_sans_prefix = EE_Model_Parser::remove_table_alias_model_relation_chain_prefix($alias_prefixed);
3415
-		foreach($this->_tables as $table_obj){
3416
-			if($table_obj instanceof EE_Secondary_Table){//table is secondary table
3417
-				if($alias_sans_prefix == $table_obj->get_table_alias()){
3415
+		foreach ($this->_tables as $table_obj) {
3416
+			if ($table_obj instanceof EE_Secondary_Table) {//table is secondary table
3417
+				if ($alias_sans_prefix == $table_obj->get_table_alias()) {
3418 3418
 					//so we're joining to this table, meaning the table is already in
3419 3419
 					//the FROM statement, BUT the primary table isn't. So we want
3420 3420
 					//to add the inverse join sql
3421 3421
 					$SQL .= $table_obj->get_inverse_join_sql($alias_prefixed);
3422
-				}else{
3422
+				} else {
3423 3423
 					//just add a regular JOIN to this table from the primary table
3424 3424
 					$SQL .= $table_obj->get_join_sql($alias_prefixed);
3425 3425
 				}
@@ -3433,9 +3433,9 @@  discard block
 block discarded – undo
3433 3433
 	 * 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)
3434 3434
 	 * @return array
3435 3435
 	 */
3436
-	function _get_data_types(){
3436
+	function _get_data_types() {
3437 3437
 		$data_types = array();
3438
-		foreach(array_values($this->field_settings()) as $field_obj){
3438
+		foreach (array_values($this->field_settings()) as $field_obj) {
3439 3439
 			//$data_types[$field_obj->get_table_column()] = $field_obj->get_wpdb_data_type();
3440 3440
 			/** @var $field_obj EE_Model_Field_Base */
3441 3441
 			$data_types[$field_obj->get_qualified_column()] = $field_obj->get_wpdb_data_type();
@@ -3451,11 +3451,11 @@  discard block
 block discarded – undo
3451 3451
 	 * @throws EE_Error
3452 3452
 	 * @return EEM_Base
3453 3453
 	 */
3454
-	function get_related_model_obj($model_name){
3454
+	function get_related_model_obj($model_name) {
3455 3455
 
3456 3456
 		$model_classname = "EEM_".$model_name;
3457
-		if(!class_exists($model_classname)){
3458
-			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));
3457
+		if ( ! class_exists($model_classname)) {
3458
+			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));
3459 3459
 		}
3460 3460
 		$model_obj = call_user_func($model_classname."::instance");
3461 3461
 		return $model_obj;
@@ -3466,7 +3466,7 @@  discard block
 block discarded – undo
3466 3466
 	 * Returns the array of EE_ModelRelations for this model.
3467 3467
 	 * @return EE_Model_Relation_Base[]
3468 3468
 	 */
3469
-	public function relation_settings(){
3469
+	public function relation_settings() {
3470 3470
 		return $this->_model_relations;
3471 3471
 	}
3472 3472
 
@@ -3476,10 +3476,10 @@  discard block
 block discarded – undo
3476 3476
 	 * (Eg, without an event, datetimes have little purpose.)
3477 3477
 	 * @return EE_Belongs_To_Relation[]
3478 3478
 	 */
3479
-	public function belongs_to_relations(){
3479
+	public function belongs_to_relations() {
3480 3480
 		$belongs_to_relations = array();
3481
-		foreach($this->relation_settings() as $model_name => $relation_obj){
3482
-			if($relation_obj instanceof EE_Belongs_To_Relation){
3481
+		foreach ($this->relation_settings() as $model_name => $relation_obj) {
3482
+			if ($relation_obj instanceof EE_Belongs_To_Relation) {
3483 3483
 				$belongs_to_relations[$model_name] = $relation_obj;
3484 3484
 			}
3485 3485
 		}
@@ -3494,15 +3494,15 @@  discard block
 block discarded – undo
3494 3494
 	 * @throws EE_Error
3495 3495
 	 * @return EE_Model_Relation_Base
3496 3496
 	 */
3497
-	public function related_settings_for($relation_name){
3498
-		$relatedModels=$this->relation_settings();
3499
-		if(!array_key_exists($relation_name,$relatedModels)){
3497
+	public function related_settings_for($relation_name) {
3498
+		$relatedModels = $this->relation_settings();
3499
+		if ( ! array_key_exists($relation_name, $relatedModels)) {
3500 3500
 			throw new EE_Error(
3501 3501
 				sprintf(
3502
-					__('Cannot get %s related to %s. There is no model relation of that type. There is, however, %s...','event_espresso'),
3502
+					__('Cannot get %s related to %s. There is no model relation of that type. There is, however, %s...', 'event_espresso'),
3503 3503
 					$relation_name,
3504 3504
 					$this->_get_class_name(),
3505
-					implode( ', ', array_keys( $relatedModels ))
3505
+					implode(', ', array_keys($relatedModels))
3506 3506
 				)
3507 3507
 			);
3508 3508
 		}
@@ -3517,10 +3517,10 @@  discard block
 block discarded – undo
3517 3517
 	 * @throws EE_Error
3518 3518
 	 * @return EE_Model_Field_Base
3519 3519
 	 */
3520
-	public function field_settings_for($fieldName){
3521
-		$fieldSettings=$this->field_settings(true);
3522
-		if( ! array_key_exists($fieldName,$fieldSettings)){
3523
-			throw new EE_Error(sprintf(__("There is no field/column '%s' on '%s'",'event_espresso'),$fieldName,get_class($this)));
3520
+	public function field_settings_for($fieldName) {
3521
+		$fieldSettings = $this->field_settings(true);
3522
+		if ( ! array_key_exists($fieldName, $fieldSettings)) {
3523
+			throw new EE_Error(sprintf(__("There is no field/column '%s' on '%s'", 'event_espresso'), $fieldName, get_class($this)));
3524 3524
 		}
3525 3525
 		return $fieldSettings[$fieldName];
3526 3526
 	}
@@ -3530,11 +3530,11 @@  discard block
 block discarded – undo
3530 3530
 	 * @param string $fieldName a key in the model's _field_settings array
3531 3531
 	 * @return boolean
3532 3532
 	 */
3533
-	public function has_field($fieldName){
3533
+	public function has_field($fieldName) {
3534 3534
 		$fieldSettings = $this->field_settings(true);
3535
-		if( isset($fieldSettings[$fieldName])){
3535
+		if (isset($fieldSettings[$fieldName])) {
3536 3536
 			return true;
3537
-		}else{
3537
+		} else {
3538 3538
 			return false;
3539 3539
 		}
3540 3540
 	}
@@ -3544,11 +3544,11 @@  discard block
 block discarded – undo
3544 3544
 	 * @param string $relation_name possibly one of the keys in the relation_settings array
3545 3545
 	 * @return boolean
3546 3546
 	 */
3547
-	public function has_relation($relation_name){
3547
+	public function has_relation($relation_name) {
3548 3548
 		$relations = $this->relation_settings();
3549
-		if(isset($relations[$relation_name])){
3549
+		if (isset($relations[$relation_name])) {
3550 3550
 			return true;
3551
-		}else{
3551
+		} else {
3552 3552
 			return false;
3553 3553
 		}
3554 3554
 	}
@@ -3560,7 +3560,7 @@  discard block
 block discarded – undo
3560 3560
 	 * @param $field_obj
3561 3561
 	 * @return EE_Model_Field_Base
3562 3562
 	 */
3563
-	public function is_primary_key_field( $field_obj ){
3563
+	public function is_primary_key_field($field_obj) {
3564 3564
 		return $field_obj instanceof EE_Primary_Key_Field_Base ? TRUE : FALSE;
3565 3565
 	}
3566 3566
 
@@ -3572,16 +3572,16 @@  discard block
 block discarded – undo
3572 3572
 	 * @return EE_Model_Field_Base
3573 3573
 	 * @throws EE_Error
3574 3574
 	 */
3575
-	public function get_primary_key_field(){
3576
-		if( $this->_primary_key_field === NULL ){
3577
-			foreach( $this->field_settings( TRUE ) as $field_obj ){
3578
-				if( $this->is_primary_key_field( $field_obj )){
3575
+	public function get_primary_key_field() {
3576
+		if ($this->_primary_key_field === NULL) {
3577
+			foreach ($this->field_settings(TRUE) as $field_obj) {
3578
+				if ($this->is_primary_key_field($field_obj)) {
3579 3579
 					$this->_primary_key_field = $field_obj;
3580 3580
 					break;
3581 3581
 				}
3582 3582
 			}
3583
-			if( ! $this->_primary_key_field instanceof EE_Primary_Key_Field_Base ){
3584
-				throw new EE_Error(sprintf(__("There is no Primary Key defined on model %s",'event_espresso'),get_class($this)));
3583
+			if ( ! $this->_primary_key_field instanceof EE_Primary_Key_Field_Base) {
3584
+				throw new EE_Error(sprintf(__("There is no Primary Key defined on model %s", 'event_espresso'), get_class($this)));
3585 3585
 			}
3586 3586
 		}
3587 3587
 		return $this->_primary_key_field;
@@ -3594,12 +3594,12 @@  discard block
 block discarded – undo
3594 3594
 	 * Internally does some caching.
3595 3595
 	 * @return boolean
3596 3596
 	 */
3597
-	public function has_primary_key_field(){
3598
-		if($this->_has_primary_key_field === null){
3599
-			try{
3597
+	public function has_primary_key_field() {
3598
+		if ($this->_has_primary_key_field === null) {
3599
+			try {
3600 3600
 				$this->get_primary_key_field();
3601 3601
 				$this->_has_primary_key_field = true;
3602
-			}catch(EE_Error $e){
3602
+			} catch (EE_Error $e) {
3603 3603
 				$this->_has_primary_key_field = false;
3604 3604
 			}
3605 3605
 		}
@@ -3613,9 +3613,9 @@  discard block
 block discarded – undo
3613 3613
 	 * @param string $field_class_name class name of field that you want to find. Eg, EE_Datetime_Field, EE_Foreign_Key_Field, etc
3614 3614
 	 * @return EE_Model_Field_Base or null if none is found
3615 3615
 	 */
3616
-	public function get_a_field_of_type($field_class_name){
3617
-		foreach($this->field_settings() as $field){
3618
-			if( $field instanceof $field_class_name ){
3616
+	public function get_a_field_of_type($field_class_name) {
3617
+		foreach ($this->field_settings() as $field) {
3618
+			if ($field instanceof $field_class_name) {
3619 3619
 				return $field;
3620 3620
 			}
3621 3621
 		}
@@ -3629,21 +3629,21 @@  discard block
 block discarded – undo
3629 3629
 	 * @return EE_Foreign_Key_Field_Base
3630 3630
 	 * @throws EE_Error
3631 3631
 	 */
3632
-	public function get_foreign_key_to($model_name){
3633
-		if( ! isset( $this->_cache_foreign_key_to_fields[ $model_name ] ) ){
3634
-			foreach($this->field_settings() as $field){
3632
+	public function get_foreign_key_to($model_name) {
3633
+		if ( ! isset($this->_cache_foreign_key_to_fields[$model_name])) {
3634
+			foreach ($this->field_settings() as $field) {
3635 3635
 //				if(is_subclass_of($field, 'EE_Foreign_Key_Field_Base')){
3636
-				if( $field instanceof EE_Foreign_Key_Field_Base ){
3637
-					if (in_array($model_name,$field->get_model_names_pointed_to() ) ) {
3638
-						$this->_cache_foreign_key_to_fields[ $model_name ] = $field;
3636
+				if ($field instanceof EE_Foreign_Key_Field_Base) {
3637
+					if (in_array($model_name, $field->get_model_names_pointed_to())) {
3638
+						$this->_cache_foreign_key_to_fields[$model_name] = $field;
3639 3639
 					}
3640 3640
 				}
3641 3641
 			}
3642
-			if( ! isset( $this->_cache_foreign_key_to_fields[ $model_name ] ) ){
3643
-				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)));
3642
+			if ( ! isset($this->_cache_foreign_key_to_fields[$model_name])) {
3643
+				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)));
3644 3644
 			}
3645 3645
 		}
3646
-		return $this->_cache_foreign_key_to_fields[ $model_name ];
3646
+		return $this->_cache_foreign_key_to_fields[$model_name];
3647 3647
 	}
3648 3648
 
3649 3649
 
@@ -3654,7 +3654,7 @@  discard block
 block discarded – undo
3654 3654
 	 * a table alias with a model chain prefix, like 'Venue__Event_Venue___Event_Meta'. Either one works
3655 3655
 	 * @return EE_Table_Base
3656 3656
 	 */
3657
-	function get_table_for_alias($table_alias){
3657
+	function get_table_for_alias($table_alias) {
3658 3658
 		$table_alias_sans_model_relation_chain_prefix = EE_Model_Parser::remove_table_alias_model_relation_chain_prefix($table_alias);
3659 3659
 		return $this->_tables[$table_alias_sans_model_relation_chain_prefix]->get_table_name();
3660 3660
 	}
@@ -3667,25 +3667,25 @@  discard block
 block discarded – undo
3667 3667
 	 * @param bool $include_db_only_fields flag indicating whether or not to include the db-only fields
3668 3668
 	 * @return EE_Model_Field_Base[] where the keys are the field's name
3669 3669
 	 */
3670
-	public function field_settings($include_db_only_fields = false){
3671
-		if( $include_db_only_fields ){
3672
-			if( $this->_cached_fields === NULL ){
3670
+	public function field_settings($include_db_only_fields = false) {
3671
+		if ($include_db_only_fields) {
3672
+			if ($this->_cached_fields === NULL) {
3673 3673
 				$this->_cached_fields = array();
3674
-				foreach($this->_fields as $fields_corresponding_to_table){
3675
-					foreach($fields_corresponding_to_table as $field_name => $field_obj){
3676
-						$this->_cached_fields[$field_name]=$field_obj;
3674
+				foreach ($this->_fields as $fields_corresponding_to_table) {
3675
+					foreach ($fields_corresponding_to_table as $field_name => $field_obj) {
3676
+						$this->_cached_fields[$field_name] = $field_obj;
3677 3677
 					}
3678 3678
 				}
3679 3679
 			}
3680 3680
 			return $this->_cached_fields;
3681
-		}else{
3682
-			if( $this->_cached_fields_non_db_only === NULL ){
3681
+		} else {
3682
+			if ($this->_cached_fields_non_db_only === NULL) {
3683 3683
 				$this->_cached_fields_non_db_only = array();
3684
-				foreach($this->_fields as $fields_corresponding_to_table){
3685
-					foreach($fields_corresponding_to_table as $field_name => $field_obj){
3684
+				foreach ($this->_fields as $fields_corresponding_to_table) {
3685
+					foreach ($fields_corresponding_to_table as $field_name => $field_obj) {
3686 3686
 						/** @var $field_obj EE_Model_Field_Base */
3687
-						if( ! $field_obj->is_db_only_field() ){
3688
-							$this->_cached_fields_non_db_only[$field_name]=$field_obj;
3687
+						if ( ! $field_obj->is_db_only_field()) {
3688
+							$this->_cached_fields_non_db_only[$field_name] = $field_obj;
3689 3689
 						}
3690 3690
 					}
3691 3691
 				}
@@ -3704,67 +3704,67 @@  discard block
 block discarded – undo
3704 3704
 	 * @return \EE_Base_Class[] array keys are primary keys (if there is a primary key on the model. if not, numerically indexed)
3705 3705
 	 * @throws \EE_Error
3706 3706
 	 */
3707
-	protected function _create_objects( $rows = array() ) {
3708
-		$array_of_objects=array();
3709
-		if(empty($rows)){
3707
+	protected function _create_objects($rows = array()) {
3708
+		$array_of_objects = array();
3709
+		if (empty($rows)) {
3710 3710
 			return array();
3711 3711
 		}
3712 3712
 		$count_if_model_has_no_primary_key = 0;
3713 3713
 		$has_primary_key = $this->has_primary_key_field();
3714
-		if( $has_primary_key ) {
3714
+		if ($has_primary_key) {
3715 3715
 			$primary_key_field = $this->get_primary_key_field();
3716 3716
 		} else {
3717 3717
 			$primary_key_field = null;
3718 3718
 		}
3719
-		foreach ( $rows as $row ) {
3720
-			if(empty($row)){
3719
+		foreach ($rows as $row) {
3720
+			if (empty($row)) {
3721 3721
 				//wp did its weird thing where it returns an array like array(0=>null), which is totally not helpful...
3722 3722
 				return array();
3723 3723
 			}
3724 3724
 			//check if we've already set this object in the results array,
3725 3725
 			//in which case there's no need to process it further (again)
3726
-			if( $has_primary_key ) {
3726
+			if ($has_primary_key) {
3727 3727
 				$table_pk_value = $this->_get_column_value_with_table_alias_or_not(
3728 3728
 					$row,
3729 3729
 					$primary_key_field->get_qualified_column(),
3730 3730
 					$primary_key_field->get_table_column()
3731 3731
 				);
3732
-				if( $table_pk_value &&
3733
-					isset( $array_of_objects[ $table_pk_value ] ) ) {
3732
+				if ($table_pk_value &&
3733
+					isset($array_of_objects[$table_pk_value])) {
3734 3734
 					continue;
3735 3735
 				}
3736 3736
 			}
3737
-			$classInstance=$this->instantiate_class_from_array_or_object($row);
3738
-			if( ! $classInstance ) {
3737
+			$classInstance = $this->instantiate_class_from_array_or_object($row);
3738
+			if ( ! $classInstance) {
3739 3739
 				throw new EE_Error(
3740 3740
 					sprintf(
3741
-						__( 'Could not create instance of class %s from row %s', 'event_espresso' ),
3741
+						__('Could not create instance of class %s from row %s', 'event_espresso'),
3742 3742
 						$this->get_this_model_name(),
3743
-						http_build_query( $row )
3743
+						http_build_query($row)
3744 3744
 					)
3745 3745
 				);
3746 3746
 			}
3747 3747
 			//set the timezone on the instantiated objects
3748
-			$classInstance->set_timezone( $this->_timezone );
3748
+			$classInstance->set_timezone($this->_timezone);
3749 3749
 			//make sure if there is any timezone setting present that we set the timezone for the object
3750 3750
 			$key = $has_primary_key ? $classInstance->ID() : $count_if_model_has_no_primary_key++;
3751
-			$array_of_objects[ $key ] = $classInstance;
3751
+			$array_of_objects[$key] = $classInstance;
3752 3752
 			//also, for all the relations of type BelongsTo, see if we can cache
3753 3753
 			//those related models
3754 3754
 			//(we could do this for other relations too, but if there are conditions
3755 3755
 			//that filtered out some fo the results, then we'd be caching an incomplete set
3756 3756
 			//so it requires a little more thought than just caching them immediately...)
3757
-			foreach($this->_model_relations as $modelName => $relation_obj){
3758
-				if( $relation_obj instanceof EE_Belongs_To_Relation){
3757
+			foreach ($this->_model_relations as $modelName => $relation_obj) {
3758
+				if ($relation_obj instanceof EE_Belongs_To_Relation) {
3759 3759
 					//check if this model's INFO is present. If so, cache it on the model
3760 3760
 					$other_model = $relation_obj->get_other_model();
3761 3761
 
3762 3762
 					$other_model_obj_maybe = $other_model->instantiate_class_from_array_or_object($row);
3763 3763
 
3764 3764
 					//if we managed to make a model object from the results, cache it on the main model object
3765
-					if( $other_model_obj_maybe ){
3765
+					if ($other_model_obj_maybe) {
3766 3766
 						//set timezone on these other model objects if they are present
3767
-						$other_model_obj_maybe->set_timezone( $this->_timezone );
3767
+						$other_model_obj_maybe->set_timezone($this->_timezone);
3768 3768
 						$classInstance->cache($modelName, $other_model_obj_maybe);
3769 3769
 					}
3770 3770
 				}
@@ -3785,12 +3785,12 @@  discard block
 block discarded – undo
3785 3785
 
3786 3786
 		$this_model_fields_and_values = array();
3787 3787
 		//setup the row using default values;
3788
-		foreach ( $this->field_settings() as $field_name => $field_obj ) {
3788
+		foreach ($this->field_settings() as $field_name => $field_obj) {
3789 3789
 			$this_model_fields_and_values[$field_name] = $field_obj->get_default_value();
3790 3790
 		}
3791 3791
 
3792 3792
 		$className = $this->_get_class_name();
3793
-		$classInstance = EE_Registry::instance()->load_class( $className, array( $this_model_fields_and_values ), FALSE, FALSE );
3793
+		$classInstance = EE_Registry::instance()->load_class($className, array($this_model_fields_and_values), FALSE, FALSE);
3794 3794
 
3795 3795
 		return $classInstance;
3796 3796
 	}
@@ -3803,45 +3803,45 @@  discard block
 block discarded – undo
3803 3803
 	 * or an stdClass where each property is the name of a column,
3804 3804
 	 * @return EE_Base_Class
3805 3805
 	 */
3806
-	public function instantiate_class_from_array_or_object($cols_n_values){
3807
-		if( ! is_array( $cols_n_values ) && is_object( $cols_n_values )) {
3808
-			$cols_n_values = get_object_vars( $cols_n_values );
3806
+	public function instantiate_class_from_array_or_object($cols_n_values) {
3807
+		if ( ! is_array($cols_n_values) && is_object($cols_n_values)) {
3808
+			$cols_n_values = get_object_vars($cols_n_values);
3809 3809
 		}
3810 3810
 		$primary_key = NULL;
3811 3811
 		//make sure the array only has keys that are fields/columns on this model
3812
-		$this_model_fields_n_values = $this->_deduce_fields_n_values_from_cols_n_values( $cols_n_values );
3813
-		if( $this->has_primary_key_field() && isset( $this_model_fields_n_values[ $this->primary_key_name() ] ) ){
3814
-			$primary_key = $this_model_fields_n_values[ $this->primary_key_name() ];
3812
+		$this_model_fields_n_values = $this->_deduce_fields_n_values_from_cols_n_values($cols_n_values);
3813
+		if ($this->has_primary_key_field() && isset($this_model_fields_n_values[$this->primary_key_name()])) {
3814
+			$primary_key = $this_model_fields_n_values[$this->primary_key_name()];
3815 3815
 		}
3816
-		$className=$this->_get_class_name();
3816
+		$className = $this->_get_class_name();
3817 3817
 
3818 3818
 		//check we actually found results that we can use to build our model object
3819 3819
 		//if not, return null
3820
-		if( $this->has_primary_key_field()){
3821
-			if(empty( $this_model_fields_n_values[$this->primary_key_name()] )){
3820
+		if ($this->has_primary_key_field()) {
3821
+			if (empty($this_model_fields_n_values[$this->primary_key_name()])) {
3822 3822
 				return NULL;
3823 3823
 			}
3824
-		}else if($this->unique_indexes()){
3824
+		} else if ($this->unique_indexes()) {
3825 3825
 			$first_column = reset($this_model_fields_n_values);
3826
-			if(empty($first_column)){
3826
+			if (empty($first_column)) {
3827 3827
 				return NULL;
3828 3828
 			}
3829 3829
 		}
3830 3830
 
3831 3831
 		// if there is no primary key or the object doesn't already exist in the entity map, then create a new instance
3832
-		if ( $primary_key){
3833
-			$classInstance = $this->get_from_entity_map( $primary_key );
3834
-			if( ! $classInstance) {
3835
-				$classInstance = EE_Registry::instance()->load_class( $className, array( $this_model_fields_n_values, $this->_timezone ), TRUE, FALSE );
3832
+		if ($primary_key) {
3833
+			$classInstance = $this->get_from_entity_map($primary_key);
3834
+			if ( ! $classInstance) {
3835
+				$classInstance = EE_Registry::instance()->load_class($className, array($this_model_fields_n_values, $this->_timezone), TRUE, FALSE);
3836 3836
 				// add this new object to the entity map
3837
-				$classInstance = $this->add_to_entity_map( $classInstance );
3837
+				$classInstance = $this->add_to_entity_map($classInstance);
3838 3838
 			}
3839
-		}else{
3840
-			$classInstance = EE_Registry::instance()->load_class( $className, array( $this_model_fields_n_values, $this->_timezone ), TRUE, FALSE );
3839
+		} else {
3840
+			$classInstance = EE_Registry::instance()->load_class($className, array($this_model_fields_n_values, $this->_timezone), TRUE, FALSE);
3841 3841
 		}
3842 3842
 
3843 3843
 			//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.
3844
-		$this->set_timezone( $classInstance->get_timezone() );
3844
+		$this->set_timezone($classInstance->get_timezone());
3845 3845
 		return $classInstance;
3846 3846
 	}
3847 3847
 	/**
@@ -3849,8 +3849,8 @@  discard block
 block discarded – undo
3849 3849
 	 * @param int|string $id the ID of the model object
3850 3850
 	 * @return EE_Base_Class
3851 3851
 	 */
3852
-	public function get_from_entity_map( $id ){
3853
-		return isset( $this->_entity_map[ $id ] ) ? $this->_entity_map[ $id ] : NULL;
3852
+	public function get_from_entity_map($id) {
3853
+		return isset($this->_entity_map[$id]) ? $this->_entity_map[$id] : NULL;
3854 3854
 	}
3855 3855
 
3856 3856
 
@@ -3869,21 +3869,21 @@  discard block
 block discarded – undo
3869 3869
 	 * @throws EE_Error
3870 3870
 	 * @return \EE_Base_Class
3871 3871
 	 */
3872
-	public function add_to_entity_map( EE_Base_Class $object) {
3872
+	public function add_to_entity_map(EE_Base_Class $object) {
3873 3873
 		$className = $this->_get_class_name();
3874
-		if( ! $object instanceof $className ){
3875
-			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 ) );
3874
+		if ( ! $object instanceof $className) {
3875
+			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));
3876 3876
 		}
3877 3877
 		/** @var $object EE_Base_Class */
3878
-		if ( ! $object->ID() ){
3879
-			throw new EE_Error(sprintf(__("You tried storing a model object with NO ID in the %s entity mapper.", "event_espresso"),get_class($this)));
3878
+		if ( ! $object->ID()) {
3879
+			throw new EE_Error(sprintf(__("You tried storing a model object with NO ID in the %s entity mapper.", "event_espresso"), get_class($this)));
3880 3880
 		}
3881 3881
 		// double check it's not already there
3882
-		$classInstance = $this->get_from_entity_map( $object->ID() );
3883
-		if ( $classInstance ) {
3882
+		$classInstance = $this->get_from_entity_map($object->ID());
3883
+		if ($classInstance) {
3884 3884
 			return $classInstance;
3885 3885
 		} else {
3886
-			$this->_entity_map[ $object->ID() ] = $object;
3886
+			$this->_entity_map[$object->ID()] = $object;
3887 3887
 			return $object;
3888 3888
 		}
3889 3889
 	}
@@ -3896,8 +3896,8 @@  discard block
 block discarded – undo
3896 3896
 	 * @param array $cols_n_values
3897 3897
 	 * @return array
3898 3898
 	 */
3899
-	public function deduce_fields_n_values_from_cols_n_values( $cols_n_values ) {
3900
-		return $this->_deduce_fields_n_values_from_cols_n_values( $cols_n_values );
3899
+	public function deduce_fields_n_values_from_cols_n_values($cols_n_values) {
3900
+		return $this->_deduce_fields_n_values_from_cols_n_values($cols_n_values);
3901 3901
 	}
3902 3902
 
3903 3903
 
@@ -3910,40 +3910,40 @@  discard block
 block discarded – undo
3910 3910
 	 * @param string $cols_n_values
3911 3911
 	 * @return array
3912 3912
 	 */
3913
-	protected function _deduce_fields_n_values_from_cols_n_values( $cols_n_values ){
3913
+	protected function _deduce_fields_n_values_from_cols_n_values($cols_n_values) {
3914 3914
 		$this_model_fields_n_values = array();
3915
-		foreach( $this->get_tables() as $table_alias => $table_obj ) {
3916
-			$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() );
3915
+		foreach ($this->get_tables() as $table_alias => $table_obj) {
3916
+			$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());
3917 3917
 			//there is a primary key on this table and its not set. Use defaults for all its columns
3918
-			if( $table_obj->get_pk_column() && $table_pk_value === NULL ){
3919
-				foreach( $this->_get_fields_for_table( $table_alias ) as $field_name => $field_obj ) {
3920
-					if( ! $field_obj->is_db_only_field() ){
3918
+			if ($table_obj->get_pk_column() && $table_pk_value === NULL) {
3919
+				foreach ($this->_get_fields_for_table($table_alias) as $field_name => $field_obj) {
3920
+					if ( ! $field_obj->is_db_only_field()) {
3921 3921
 						//prepare field as if its coming from db
3922
-						$prepared_value = $field_obj->prepare_for_set( $field_obj->get_default_value() );
3923
-						$this_model_fields_n_values[$field_name] = $field_obj->prepare_for_use_in_db( $prepared_value );
3922
+						$prepared_value = $field_obj->prepare_for_set($field_obj->get_default_value());
3923
+						$this_model_fields_n_values[$field_name] = $field_obj->prepare_for_use_in_db($prepared_value);
3924 3924
 					}
3925 3925
 				}
3926
-			}else{
3926
+			} else {
3927 3927
 				//the table's rows existed. Use their values
3928
-				foreach( $this->_get_fields_for_table( $table_alias ) as $field_name => $field_obj ) {
3929
-					if( ! $field_obj->is_db_only_field() )
3930
-					$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() );
3928
+				foreach ($this->_get_fields_for_table($table_alias) as $field_name => $field_obj) {
3929
+					if ( ! $field_obj->is_db_only_field())
3930
+					$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());
3931 3931
 				}
3932 3932
 			}
3933 3933
 		}
3934 3934
 		return $this_model_fields_n_values;
3935 3935
 	}
3936 3936
 
3937
-	protected function _get_column_value_with_table_alias_or_not( $cols_n_values, $qualified_column, $regular_column ){
3937
+	protected function _get_column_value_with_table_alias_or_not($cols_n_values, $qualified_column, $regular_column) {
3938 3938
 		//ask the field what it think it's table_name.column_name should be, and call it the "qualified column"
3939 3939
 		//does the field on the model relate to this column retrieved from the db?
3940 3940
 		//or is it a db-only field? (not relating to the model)
3941
-		if( isset( $cols_n_values[ $qualified_column ] ) ){
3942
-			$value = $cols_n_values[ $qualified_column ];
3941
+		if (isset($cols_n_values[$qualified_column])) {
3942
+			$value = $cols_n_values[$qualified_column];
3943 3943
 
3944
-		}elseif( isset( $cols_n_values[ $regular_column ] ) ){
3945
-			$value = $cols_n_values[ $regular_column ];
3946
-		}else{
3944
+		}elseif (isset($cols_n_values[$regular_column])) {
3945
+			$value = $cols_n_values[$regular_column];
3946
+		} else {
3947 3947
 			$value = NULL;
3948 3948
 		}
3949 3949
 
@@ -3961,23 +3961,23 @@  discard block
 block discarded – undo
3961 3961
 	 * @param int|string $id
3962 3962
 	 * @return EE_Base_Class
3963 3963
 	 */
3964
-	public function refresh_entity_map_from_db( $id ){
3965
-		$obj_in_map = $this->get_from_entity_map( $id );
3966
-		if( $obj_in_map ){
3967
-			$wpdb_results = $this->_get_all_wpdb_results( array( array ( $this->get_primary_key_field()->get_name() => $id ), 'limit' => 1 ) );
3968
-			if( $wpdb_results && is_array( $wpdb_results ) ){
3969
-				$one_row = reset( $wpdb_results );
3970
-				foreach( $this->_deduce_fields_n_values_from_cols_n_values($one_row ) as $field_name => $db_value ) {
3971
-					$obj_in_map->set_from_db( $field_name, $db_value );
3964
+	public function refresh_entity_map_from_db($id) {
3965
+		$obj_in_map = $this->get_from_entity_map($id);
3966
+		if ($obj_in_map) {
3967
+			$wpdb_results = $this->_get_all_wpdb_results(array(array($this->get_primary_key_field()->get_name() => $id), 'limit' => 1));
3968
+			if ($wpdb_results && is_array($wpdb_results)) {
3969
+				$one_row = reset($wpdb_results);
3970
+				foreach ($this->_deduce_fields_n_values_from_cols_n_values($one_row) as $field_name => $db_value) {
3971
+					$obj_in_map->set_from_db($field_name, $db_value);
3972 3972
 				}
3973 3973
 				//clear the cache of related model objects
3974
-				foreach ( $this->relation_settings() as $relation_name => $relation_obj ){
3975
-					$obj_in_map->clear_cache($relation_name, NULL, TRUE );
3974
+				foreach ($this->relation_settings() as $relation_name => $relation_obj) {
3975
+					$obj_in_map->clear_cache($relation_name, NULL, TRUE);
3976 3976
 				}
3977 3977
 			}
3978 3978
 			return $obj_in_map;
3979
-		}else{
3980
-			return $this->get_one_by_ID( $id );
3979
+		} else {
3980
+			return $this->get_one_by_ID($id);
3981 3981
 		}
3982 3982
 	}
3983 3983
 
@@ -3995,24 +3995,24 @@  discard block
 block discarded – undo
3995 3995
 	 * @param EE_Base_Class $replacing_model_obj
3996 3996
 	 * @return \EE_Base_Class
3997 3997
 	 */
3998
-	public function refresh_entity_map_with( $id, $replacing_model_obj ) {
3999
-		$obj_in_map = $this->get_from_entity_map( $id );
4000
-		if( $obj_in_map ){
4001
-			if( $replacing_model_obj instanceof EE_Base_Class ){
4002
-				foreach( $replacing_model_obj->model_field_array() as $field_name => $value ) {
4003
-					$obj_in_map->set( $field_name, $value );
3998
+	public function refresh_entity_map_with($id, $replacing_model_obj) {
3999
+		$obj_in_map = $this->get_from_entity_map($id);
4000
+		if ($obj_in_map) {
4001
+			if ($replacing_model_obj instanceof EE_Base_Class) {
4002
+				foreach ($replacing_model_obj->model_field_array() as $field_name => $value) {
4003
+					$obj_in_map->set($field_name, $value);
4004 4004
 				}
4005 4005
 				//make the model object in the entity map's cache match the $replacing_model_obj
4006
-				foreach ( $this->relation_settings() as $relation_name => $relation_obj ){
4007
-					$obj_in_map->clear_cache($relation_name, NULL, TRUE );
4008
-					foreach( $replacing_model_obj->get_all_from_cache( $relation_name ) as $cache_id => $cached_obj ) {
4009
-						$obj_in_map->cache( $relation_name, $cached_obj, $cache_id );
4006
+				foreach ($this->relation_settings() as $relation_name => $relation_obj) {
4007
+					$obj_in_map->clear_cache($relation_name, NULL, TRUE);
4008
+					foreach ($replacing_model_obj->get_all_from_cache($relation_name) as $cache_id => $cached_obj) {
4009
+						$obj_in_map->cache($relation_name, $cached_obj, $cache_id);
4010 4010
 					}
4011 4011
 				}
4012 4012
 			}
4013 4013
 			return $obj_in_map;
4014
-		}else{
4015
-			$this->add_to_entity_map( $replacing_model_obj );
4014
+		} else {
4015
+			$this->add_to_entity_map($replacing_model_obj);
4016 4016
 			return $replacing_model_obj;
4017 4017
 		}
4018 4018
 	}
@@ -4025,7 +4025,7 @@  discard block
 block discarded – undo
4025 4025
 	 * require_once($this->_getClassName().".class.php");
4026 4026
 	 * @return string
4027 4027
 	 */
4028
-	private function _get_class_name(){
4028
+	private function _get_class_name() {
4029 4029
 		return "EE_".$this->get_this_model_name();
4030 4030
 	}
4031 4031
 
@@ -4038,10 +4038,10 @@  discard block
 block discarded – undo
4038 4038
 	 * @param int $quantity
4039 4039
 	 * @return string
4040 4040
 	 */
4041
-	public function item_name($quantity = 1){
4042
-		if($quantity == 1){
4041
+	public function item_name($quantity = 1) {
4042
+		if ($quantity == 1) {
4043 4043
 			return $this->singular_item;
4044
-		}else{
4044
+		} else {
4045 4045
 			return $this->plural_item;
4046 4046
 		}
4047 4047
 	}
@@ -4070,13 +4070,13 @@  discard block
 block discarded – undo
4070 4070
 	 * @throws EE_Error
4071 4071
 	 * @return mixed whatever the plugin which calls add_filter decides
4072 4072
 	 */
4073
-	public function __call($methodName,$args){
4074
-		$className=get_class($this);
4075
-		$tagName="FHEE__{$className}__{$methodName}";
4076
-		if(!has_filter($tagName)){
4073
+	public function __call($methodName, $args) {
4074
+		$className = get_class($this);
4075
+		$tagName = "FHEE__{$className}__{$methodName}";
4076
+		if ( ! has_filter($tagName)) {
4077 4077
 			throw new EE_Error(
4078 4078
 				sprintf(
4079
-					__( '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' ),
4079
+					__('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'),
4080 4080
 					$methodName,
4081 4081
 					$className,
4082 4082
 					$tagName,
@@ -4085,7 +4085,7 @@  discard block
 block discarded – undo
4085 4085
 			);
4086 4086
 		}
4087 4087
 
4088
-		return apply_filters($tagName,null,$this,$args);
4088
+		return apply_filters($tagName, null, $this, $args);
4089 4089
 	}
4090 4090
 
4091 4091
 
@@ -4098,22 +4098,22 @@  discard block
 block discarded – undo
4098 4098
 	 * @throws EE_Error
4099 4099
 	 * @return EE_Base_Class
4100 4100
 	 */
4101
-	public function ensure_is_obj( $base_class_obj_or_id, $ensure_is_in_db = FALSE ){
4101
+	public function ensure_is_obj($base_class_obj_or_id, $ensure_is_in_db = FALSE) {
4102 4102
 		$className = $this->_get_class_name();
4103 4103
 		$primary_key_field = $this->get_primary_key_field();
4104
-		if( $base_class_obj_or_id instanceof $className ){
4104
+		if ($base_class_obj_or_id instanceof $className) {
4105 4105
 			$model_object = $base_class_obj_or_id;
4106
-		}elseif( $primary_key_field instanceof EE_Primary_Key_Int_Field && (
4107
-				is_int( $base_class_obj_or_id ) ||
4108
-				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)
4106
+		}elseif ($primary_key_field instanceof EE_Primary_Key_Int_Field && (
4107
+				is_int($base_class_obj_or_id) ||
4108
+				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)
4109 4109
 			$model_object = $this->get_one_by_ID($base_class_obj_or_id);
4110
-		}elseif( $primary_key_field instanceof EE_Primary_Key_String_Field && is_string($base_class_obj_or_id) ){
4110
+		}elseif ($primary_key_field instanceof EE_Primary_Key_String_Field && is_string($base_class_obj_or_id)) {
4111 4111
 			//assume its a string representation of the object
4112 4112
 			$model_object = $this->get_one_by_ID($base_class_obj_or_id);
4113
-		}else{
4114
-			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)));
4113
+		} else {
4114
+			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)));
4115 4115
 		}
4116
-		if( $model_object->ID() == NULL && $ensure_is_in_db){
4116
+		if ($model_object->ID() == NULL && $ensure_is_in_db) {
4117 4117
 			$model_object->save();
4118 4118
 		}
4119 4119
 		return $model_object;
@@ -4129,19 +4129,19 @@  discard block
 block discarded – undo
4129 4129
 	 * @return int|string depending on the type of this model object's ID
4130 4130
 	 * @throws EE_Error
4131 4131
 	 */
4132
-	public function ensure_is_ID($base_class_obj_or_id){
4132
+	public function ensure_is_ID($base_class_obj_or_id) {
4133 4133
 		$className = $this->_get_class_name();
4134
-		if( $base_class_obj_or_id instanceof $className ){
4134
+		if ($base_class_obj_or_id instanceof $className) {
4135 4135
 			/** @var $base_class_obj_or_id EE_Base_Class */
4136 4136
 			$id = $base_class_obj_or_id->ID();
4137
-		}elseif(is_int($base_class_obj_or_id)){
4137
+		}elseif (is_int($base_class_obj_or_id)) {
4138 4138
 			//assume it's an ID
4139 4139
 			$id = $base_class_obj_or_id;
4140
-		}elseif(is_string($base_class_obj_or_id)){
4140
+		}elseif (is_string($base_class_obj_or_id)) {
4141 4141
 			//assume its a string representation of the object
4142 4142
 			$id = $base_class_obj_or_id;
4143
-		}else{
4144
-			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)));
4143
+		} else {
4144
+			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)));
4145 4145
 		}
4146 4146
 		return $id;
4147 4147
 	}
@@ -4164,14 +4164,14 @@  discard block
 block discarded – undo
4164 4164
 	 * @param int $values_already_prepared like one of the constants on EEM_Base
4165 4165
 	 * @return void
4166 4166
 	 */
4167
-	public function assume_values_already_prepared_by_model_object($values_already_prepared = self::not_prepared_by_model_object){
4167
+	public function assume_values_already_prepared_by_model_object($values_already_prepared = self::not_prepared_by_model_object) {
4168 4168
 		$this->_values_already_prepared_by_model_object = $values_already_prepared;
4169 4169
 	}
4170 4170
 	/**
4171 4171
 	 * Read comments for assume_values_already_prepared_by_model_object()
4172 4172
 	 * @return int
4173 4173
 	 */
4174
-	public function get_assumption_concerning_values_already_prepared_by_model_object(){
4174
+	public function get_assumption_concerning_values_already_prepared_by_model_object() {
4175 4175
 		return $this->_values_already_prepared_by_model_object;
4176 4176
 	}
4177 4177
 
@@ -4179,17 +4179,17 @@  discard block
 block discarded – undo
4179 4179
 	 * Gets all the indexes on this model
4180 4180
 	 * @return EE_Index[]
4181 4181
 	 */
4182
-	public function indexes(){
4182
+	public function indexes() {
4183 4183
 		return $this->_indexes;
4184 4184
 	}
4185 4185
 	/**
4186 4186
 	 * Gets all the Unique Indexes on this model
4187 4187
 	 * @return EE_Unique_Index[]
4188 4188
 	 */
4189
-	public function unique_indexes(){
4189
+	public function unique_indexes() {
4190 4190
 		$unique_indexes = array();
4191
-		foreach($this->_indexes as $name => $index){
4192
-			if($index instanceof EE_Unique_Index){
4191
+		foreach ($this->_indexes as $name => $index) {
4192
+			if ($index instanceof EE_Unique_Index) {
4193 4193
 				$unique_indexes [$name] = $index;
4194 4194
 			}
4195 4195
 		}
@@ -4202,9 +4202,9 @@  discard block
 block discarded – undo
4202 4202
 	 * on a primary index
4203 4203
 	 * @return EE_Model_Field_Base[]
4204 4204
 	 */
4205
-	public function get_combined_primary_key_fields(){
4206
-		foreach($this->indexes() as $index){
4207
-			if($index instanceof EE_Primary_Key_Index){
4205
+	public function get_combined_primary_key_fields() {
4206
+		foreach ($this->indexes() as $index) {
4207
+			if ($index instanceof EE_Primary_Key_Index) {
4208 4208
 				return $index->fields();
4209 4209
 			}
4210 4210
 		}
@@ -4217,7 +4217,7 @@  discard block
 block discarded – undo
4217 4217
 	 * @param array $cols_n_values keys are field names, values are their values
4218 4218
 	 * @return string
4219 4219
 	 */
4220
-	public function get_index_primary_key_string($cols_n_values){
4220
+	public function get_index_primary_key_string($cols_n_values) {
4221 4221
 		$cols_n_values_for_primary_key_index = array_intersect_key($cols_n_values, $this->get_combined_primary_key_fields());
4222 4222
 		return http_build_query($cols_n_values_for_primary_key_index);
4223 4223
 	}
@@ -4229,13 +4229,13 @@  discard block
 block discarded – undo
4229 4229
 	 * @param string $index_primary_key_string
4230 4230
 	 * @return null|array
4231 4231
 	 */
4232
-	function parse_index_primary_key_string( $index_primary_key_string) {
4232
+	function parse_index_primary_key_string($index_primary_key_string) {
4233 4233
 		$key_fields = $this->get_combined_primary_key_fields();
4234 4234
 		//check all of them are in the $id
4235 4235
 		$key_vals_in_combined_pk = array();
4236
-		parse_str( $index_primary_key_string, $key_vals_in_combined_pk );
4237
-		foreach( $key_fields as $key_field_name => $field_obj ) {
4238
-			if( ! isset( $key_vals_in_combined_pk[ $key_field_name ] ) ){
4236
+		parse_str($index_primary_key_string, $key_vals_in_combined_pk);
4237
+		foreach ($key_fields as $key_field_name => $field_obj) {
4238
+			if ( ! isset($key_vals_in_combined_pk[$key_field_name])) {
4239 4239
 				return NULL;
4240 4240
 			}
4241 4241
 		}
@@ -4248,10 +4248,10 @@  discard block
 block discarded – undo
4248 4248
 	 * @param array $key_vals
4249 4249
 	 * @return boolean
4250 4250
 	 */
4251
-	function has_all_combined_primary_key_fields( $key_vals ) {
4252
-		$keys_it_should_have = array_keys( $this->get_combined_primary_key_fields() );
4253
-		foreach( $keys_it_should_have as $key ){
4254
-			if( ! isset( $key_vals[ $key ] ) ){
4251
+	function has_all_combined_primary_key_fields($key_vals) {
4252
+		$keys_it_should_have = array_keys($this->get_combined_primary_key_fields());
4253
+		foreach ($keys_it_should_have as $key) {
4254
+			if ( ! isset($key_vals[$key])) {
4255 4255
 				return false;
4256 4256
 			}
4257 4257
 		}
@@ -4267,23 +4267,23 @@  discard block
 block discarded – undo
4267 4267
 	 * @throws EE_Error
4268 4268
 	 * @return \EE_Base_Class[] Array keys are object IDs (if there is a primary key on the model. if not, numerically indexed)
4269 4269
 	 */
4270
-	public function get_all_copies($model_object_or_attributes_array, $query_params = array()){
4270
+	public function get_all_copies($model_object_or_attributes_array, $query_params = array()) {
4271 4271
 
4272
-		if($model_object_or_attributes_array instanceof EE_Base_Class){
4272
+		if ($model_object_or_attributes_array instanceof EE_Base_Class) {
4273 4273
 			$attributes_array = $model_object_or_attributes_array->model_field_array();
4274
-		}elseif(is_array($model_object_or_attributes_array)){
4274
+		}elseif (is_array($model_object_or_attributes_array)) {
4275 4275
 			$attributes_array = $model_object_or_attributes_array;
4276
-		}else{
4277
-			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));
4276
+		} else {
4277
+			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));
4278 4278
 		}
4279 4279
 		//even copies obviously won't have the same ID, so remove the primary key
4280 4280
 		//from the WHERE conditions for finding copies (if there is a primary key, of course)
4281
-		if($this->has_primary_key_field() && isset($attributes_array[$this->primary_key_name()])){
4281
+		if ($this->has_primary_key_field() && isset($attributes_array[$this->primary_key_name()])) {
4282 4282
 			unset($attributes_array[$this->primary_key_name()]);
4283 4283
 		}
4284
-		if(isset($query_params[0])){
4285
-			$query_params[0] = array_merge($attributes_array,$query_params);
4286
-		}else{
4284
+		if (isset($query_params[0])) {
4285
+			$query_params[0] = array_merge($attributes_array, $query_params);
4286
+		} else {
4287 4287
 			$query_params[0] = $attributes_array;
4288 4288
 		}
4289 4289
 		return $this->get_all($query_params);
@@ -4297,16 +4297,16 @@  discard block
 block discarded – undo
4297 4297
 	 * @param array $query_params
4298 4298
 	 * @return EE_Base_Class
4299 4299
 	 */
4300
-	function get_one_copy($model_object_or_attributes_array,$query_params = array()){
4301
-		if( ! is_array( $query_params ) ){
4302
-			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' );
4300
+	function get_one_copy($model_object_or_attributes_array, $query_params = array()) {
4301
+		if ( ! is_array($query_params)) {
4302
+			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');
4303 4303
 			$query_params = array();
4304 4304
 		}
4305 4305
 		$query_params['limit'] = 1;
4306
-		$copies = $this->get_all_copies($model_object_or_attributes_array,$query_params);
4307
-		if(is_array($copies)){
4306
+		$copies = $this->get_all_copies($model_object_or_attributes_array, $query_params);
4307
+		if (is_array($copies)) {
4308 4308
 			return array_shift($copies);
4309
-		}else{
4309
+		} else {
4310 4310
 			return null;
4311 4311
 		}
4312 4312
 	}
@@ -4320,10 +4320,10 @@  discard block
 block discarded – undo
4320 4320
 	 * @param int|string $id the value of the primary key to update
4321 4321
 	 * @return int number of rows updated
4322 4322
 	 */
4323
-	public function update_by_ID($fields_n_values,$id){
4323
+	public function update_by_ID($fields_n_values, $id) {
4324 4324
 		$query_params = array(0=>array($this->get_primary_key_field()->get_name() => $id),
4325 4325
 			'default_where_conditions'=>'other_models_only',);
4326
-		return $this->update($fields_n_values,$query_params);
4326
+		return $this->update($fields_n_values, $query_params);
4327 4327
 	}
4328 4328
 
4329 4329
 
@@ -4334,12 +4334,12 @@  discard block
 block discarded – undo
4334 4334
 	 * @return string an operator which can be used in SQL
4335 4335
 	 * @throws EE_Error
4336 4336
 	 */
4337
-	private function _prepare_operator_for_sql($operator_supplied){
4337
+	private function _prepare_operator_for_sql($operator_supplied) {
4338 4338
 		$sql_operator = isset($this->_valid_operators[$operator_supplied]) ? $this->_valid_operators[$operator_supplied] : null;
4339
-		if($sql_operator){
4339
+		if ($sql_operator) {
4340 4340
 			return $sql_operator;
4341
-		}else{
4342
-			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))));
4341
+		} else {
4342
+			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))));
4343 4343
 		}
4344 4344
 	}
4345 4345
 
@@ -4349,10 +4349,10 @@  discard block
 block discarded – undo
4349 4349
 	 * @param array $query_params like get_all's
4350 4350
 	 * @return string[]
4351 4351
 	 */
4352
-	public function get_all_names($query_params = array()){
4352
+	public function get_all_names($query_params = array()) {
4353 4353
 		$objs = $this->get_all($query_params);
4354 4354
 		$names = array();
4355
-		foreach($objs as $obj){
4355
+		foreach ($objs as $obj) {
4356 4356
 			$names[$obj->ID()] = $obj->name();
4357 4357
 		}
4358 4358
 		return $names;
@@ -4367,22 +4367,22 @@  discard block
 block discarded – undo
4367 4367
 	 * @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
4368 4368
 	 * @return array
4369 4369
 	 */
4370
-	public function get_IDs( $model_objects, $filter_out_empty_ids = false) {
4371
-		if( ! $this->has_primary_key_field() ) {
4372
-			if( WP_DEBUG ) {
4373
-				EE_Error::add_error( __( 'Trying to get IDs from a model than has no primary key', 'event_espresso' ), __FILE__, __FUNCTION__, __LINE__ );
4370
+	public function get_IDs($model_objects, $filter_out_empty_ids = false) {
4371
+		if ( ! $this->has_primary_key_field()) {
4372
+			if (WP_DEBUG) {
4373
+				EE_Error::add_error(__('Trying to get IDs from a model than has no primary key', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__);
4374 4374
 				return array();
4375 4375
 			}
4376 4376
 		}
4377 4377
 		$IDs = array();
4378
-		foreach( $model_objects as $model_object ) {
4378
+		foreach ($model_objects as $model_object) {
4379 4379
 			$id = $model_object->ID();
4380
-			if( ! $id ) {
4381
-				if( $filter_out_empty_ids ) {
4380
+			if ( ! $id) {
4381
+				if ($filter_out_empty_ids) {
4382 4382
 					continue;
4383 4383
 				}
4384
-				if( WP_DEBUG ) {
4385
-					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__ );
4384
+				if (WP_DEBUG) {
4385
+					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__);
4386 4386
 				}
4387 4387
 			}
4388 4388
 			$IDs[] = $id;
@@ -4395,8 +4395,8 @@  discard block
 block discarded – undo
4395 4395
 	 * are no capabilities that relate to this model returns false
4396 4396
 	 * @return string|false
4397 4397
 	 */
4398
-	public function cap_slug(){
4399
-		return apply_filters( 'FHEE__EEM_Base__cap_slug', $this->_caps_slug, $this);
4398
+	public function cap_slug() {
4399
+		return apply_filters('FHEE__EEM_Base__cap_slug', $this->_caps_slug, $this);
4400 4400
 	}
4401 4401
 
4402 4402
 	/**
@@ -4408,27 +4408,27 @@  discard block
 block discarded – undo
4408 4408
 	 * @param string $context
4409 4409
 	 * @return EE_Default_Where_Conditions[] indexed by associated capability
4410 4410
 	 */
4411
-	public function cap_restrictions( $context = EEM_Base::caps_read ) {
4412
-		EEM_Base::verify_is_valid_cap_context( $context );
4411
+	public function cap_restrictions($context = EEM_Base::caps_read) {
4412
+		EEM_Base::verify_is_valid_cap_context($context);
4413 4413
 		//check if we ought to run the restriction generator first
4414
-		if( isset( $this->_cap_restriction_generators[ $context ] ) &&
4415
-				$this->_cap_restriction_generators[ $context ] instanceof EE_Restriction_Generator_Base &&
4416
-				! $this->_cap_restriction_generators[ $context ]->has_generated_cap_restrictions() ) {
4417
-			$this->_cap_restrictions[ $context ] = array_merge( $this->_cap_restrictions[ $context ],  $this->_cap_restriction_generators[ $context ]->generate_restrictions() );
4414
+		if (isset($this->_cap_restriction_generators[$context]) &&
4415
+				$this->_cap_restriction_generators[$context] instanceof EE_Restriction_Generator_Base &&
4416
+				! $this->_cap_restriction_generators[$context]->has_generated_cap_restrictions()) {
4417
+			$this->_cap_restrictions[$context] = array_merge($this->_cap_restrictions[$context], $this->_cap_restriction_generators[$context]->generate_restrictions());
4418 4418
 		}
4419 4419
 		//and make sure we've finalized the construction of each restriction
4420
-		foreach( $this->_cap_restrictions[ $context ] as $where_conditions_obj ) {
4421
-			$where_conditions_obj->_finalize_construct( $this );
4420
+		foreach ($this->_cap_restrictions[$context] as $where_conditions_obj) {
4421
+			$where_conditions_obj->_finalize_construct($this);
4422 4422
 		}
4423 4423
 
4424
-		return $this->_cap_restrictions[ $context ];
4424
+		return $this->_cap_restrictions[$context];
4425 4425
 	}
4426 4426
 
4427 4427
 	/**
4428 4428
 	 * Indicating whether or not this model thinks its a wp core model
4429 4429
 	 * @return boolean
4430 4430
 	 */
4431
-	public function is_wp_core_model(){
4431
+	public function is_wp_core_model() {
4432 4432
 		return $this->_wp_core_model;
4433 4433
 	}
4434 4434
 
@@ -4438,12 +4438,12 @@  discard block
 block discarded – undo
4438 4438
 	 * @param string $context one of EEM_Base::caps_ constants
4439 4439
 	 * @return EE_Default_Where_Conditions[] indexed by capability name
4440 4440
 	 */
4441
-	public function caps_missing( $context = EEM_Base::caps_read ) {
4441
+	public function caps_missing($context = EEM_Base::caps_read) {
4442 4442
 		$missing_caps = array();
4443
-		$cap_restrictions = $this->cap_restrictions( $context );
4444
-		foreach( $cap_restrictions as $cap => $restriction_if_no_cap ) {
4445
-			if( ! EE_Capabilities::instance()->current_user_can( $cap, $this->get_this_model_name() . '_model_applying_caps') ) {
4446
-				$missing_caps[ $cap ] = $restriction_if_no_cap;
4443
+		$cap_restrictions = $this->cap_restrictions($context);
4444
+		foreach ($cap_restrictions as $cap => $restriction_if_no_cap) {
4445
+			if ( ! EE_Capabilities::instance()->current_user_can($cap, $this->get_this_model_name().'_model_applying_caps')) {
4446
+				$missing_caps[$cap] = $restriction_if_no_cap;
4447 4447
 			}
4448 4448
 		}
4449 4449
 		return $missing_caps;
@@ -4455,7 +4455,7 @@  discard block
 block discarded – undo
4455 4455
 	 * one of 'read', 'edit', or 'delete'
4456 4456
 	 */
4457 4457
 	public function cap_contexts_to_cap_action_map() {
4458
-		return apply_filters( 'FHEE__EEM_Base__cap_contexts_to_cap_action_map', $this->_cap_contexts_to_cap_action_map, $this );
4458
+		return apply_filters('FHEE__EEM_Base__cap_contexts_to_cap_action_map', $this->_cap_contexts_to_cap_action_map, $this);
4459 4459
 	}
4460 4460
 
4461 4461
 
@@ -4466,19 +4466,19 @@  discard block
 block discarded – undo
4466 4466
 	 * @return string one of EEM_Base::cap_contexts_to_cap_action_map() values
4467 4467
 	 * @throws \EE_Error
4468 4468
 	 */
4469
-	public function cap_action_for_context( $context ) {
4469
+	public function cap_action_for_context($context) {
4470 4470
 		$mapping = $this->cap_contexts_to_cap_action_map();
4471
-		if( isset( $mapping[ $context ] ) ) {
4472
-			return $mapping[ $context ];
4471
+		if (isset($mapping[$context])) {
4472
+			return $mapping[$context];
4473 4473
 		}
4474
-		if( $action = apply_filters( 'FHEE__EEM_Base__cap_action_for_context', null, $this, $mapping, $context ) ) {
4474
+		if ($action = apply_filters('FHEE__EEM_Base__cap_action_for_context', null, $this, $mapping, $context)) {
4475 4475
 			return $action;
4476 4476
 		}
4477 4477
 		throw new EE_Error(
4478 4478
 			sprintf(
4479
-				__( 'Cannot find capability restrictions for context "%1$s", allowed values are:%2$s', 'event_espresso' ),
4479
+				__('Cannot find capability restrictions for context "%1$s", allowed values are:%2$s', 'event_espresso'),
4480 4480
 				$context,
4481
-				implode(',', array_keys( $this->cap_contexts_to_cap_action_map() ) )
4481
+				implode(',', array_keys($this->cap_contexts_to_cap_action_map()))
4482 4482
 			)
4483 4483
 		);
4484 4484
 
@@ -4489,7 +4489,7 @@  discard block
 block discarded – undo
4489 4489
 	 * @return array
4490 4490
 	 */
4491 4491
 	static public function valid_cap_contexts() {
4492
-		return apply_filters( 'FHEE__EEM_Base__valid_cap_contexts', array(
4492
+		return apply_filters('FHEE__EEM_Base__valid_cap_contexts', array(
4493 4493
 			self::caps_read,
4494 4494
 			self::caps_read_admin,
4495 4495
 			self::caps_edit,
@@ -4505,17 +4505,17 @@  discard block
 block discarded – undo
4505 4505
 	 * @return bool
4506 4506
 	 * @throws \EE_Error
4507 4507
 	 */
4508
-	static public function verify_is_valid_cap_context( $context ) {
4508
+	static public function verify_is_valid_cap_context($context) {
4509 4509
 		$valid_cap_contexts = EEM_Base::valid_cap_contexts();
4510
-		if( in_array( $context, $valid_cap_contexts ) ) {
4510
+		if (in_array($context, $valid_cap_contexts)) {
4511 4511
 			return true;
4512
-		}else{
4512
+		} else {
4513 4513
 			throw new EE_Error(
4514 4514
 				sprintf(
4515
-					__( 'Context "%1$s" passed into model "%2$s" is not a valid context. They are: %3$s', 'event_espresso' ),
4515
+					__('Context "%1$s" passed into model "%2$s" is not a valid context. They are: %3$s', 'event_espresso'),
4516 4516
 					$context,
4517
-					'EEM_Base' ,
4518
-					implode(',', $valid_cap_contexts )
4517
+					'EEM_Base',
4518
+					implode(',', $valid_cap_contexts)
4519 4519
 				)
4520 4520
 			);
4521 4521
 		}
Please login to merge, or discard this patch.
registration_form/templates/questions_main_meta_box.template.php 1 patch
Spacing   +54 added lines, -54 removed lines patch added patch discarded remove patch
@@ -21,7 +21,7 @@  discard block
 block discarded – undo
21 21
 		<tbody>
22 22
 			<tr>
23 23
 				<th>
24
-					<label for="QST_display_text"><?php echo $fields['QST_display_text']->get_nicename();?></label> <?php echo EEH_Template::get_help_tab_link('question_text_info');?>
24
+					<label for="QST_display_text"><?php echo $fields['QST_display_text']->get_nicename(); ?></label> <?php echo EEH_Template::get_help_tab_link('question_text_info'); ?>
25 25
 				</th>
26 26
 				<td>
27 27
 					<input type="text" class="regular-text" id="QST_display_text" name="QST_display_text" value="<?php $question->f('QST_display_text')?>"/>
@@ -31,23 +31,23 @@  discard block
 block discarded – undo
31 31
 
32 32
 			<tr>
33 33
 				<th>
34
-					<label for="QST_admin_label"><?php echo $fields['QST_admin_label']->get_nicename();?></label> <?php echo EEH_Template::get_help_tab_link('question_label_info');?>
34
+					<label for="QST_admin_label"><?php echo $fields['QST_admin_label']->get_nicename(); ?></label> <?php echo EEH_Template::get_help_tab_link('question_label_info'); ?>
35 35
 				</th>
36 36
 				<td>
37 37
 					<?php
38
-						$disabled = ! empty( $QST_system ) ? ' disabled="disabled"' : '';
39
-						$id =  ! empty( $QST_system ) ? '_disabled' : '';
38
+						$disabled = ! empty($QST_system) ? ' disabled="disabled"' : '';
39
+						$id = ! empty($QST_system) ? '_disabled' : '';
40 40
 					?>
41 41
 					<input type="text" class="regular-text" id="QST_admin_label<?php echo $id?>" name="QST_admin_label<?php echo $id?>" value="<?php $question->f('QST_admin_label')?>"<?php echo $disabled?>/>
42 42
 					<input class="QST_order" type="hidden" id="QST_order<?php echo $id; ?>" name = "QST_order<?php echo $id; ?>" value="<?php echo $question->get('QST_order'); ?>" />
43
-					<?php if ( ! empty( $QST_system )) { ?>
43
+					<?php if ( ! empty($QST_system)) { ?>
44 44
 						<input type="hidden"  id="QST_admin_label" name="QST_admin_label" value="<?php echo $question->admin_label()?>"/>
45 45
 					<?php } ?>
46 46
 					<br/>
47 47
 					<p class="description">
48
-					<?php if ( ! empty( $QST_system )) { ?>
48
+					<?php if ( ! empty($QST_system)) { ?>
49 49
 					<span class="description" style="color:#D54E21;">
50
-						<?php _e('System question! This field cannot be changed.','event_espresso')?>
50
+						<?php _e('System question! This field cannot be changed.', 'event_espresso')?>
51 51
 					</span>
52 52
 					<?php } ?>
53 53
 
@@ -57,21 +57,21 @@  discard block
 block discarded – undo
57 57
 
58 58
 			<tr>
59 59
 				<th>
60
-					<label for="QST_admin_only"><?php echo $fields['QST_admin_only']->get_nicename();?></label> <?php echo EEH_Template::get_help_tab_link('question_admin_only_info');?>
60
+					<label for="QST_admin_only"><?php echo $fields['QST_admin_only']->get_nicename(); ?></label> <?php echo EEH_Template::get_help_tab_link('question_admin_only_info'); ?>
61 61
 				</th>
62 62
 				<td>
63 63
 					<?php
64
-						$disabled = ! empty( $QST_system ) ? ' disabled="disabled"' : '';
65
-						$id =  ! empty( $QST_system ) ? '_disabled' : '';
64
+						$disabled = ! empty($QST_system) ? ' disabled="disabled"' : '';
65
+						$id = ! empty($QST_system) ? '_disabled' : '';
66 66
 						$admin_only = $question->get('QST_admin_only');
67
-						$checked = !empty( $admin_only ) ? ' checked="checked"' : '';
67
+						$checked = ! empty($admin_only) ? ' checked="checked"' : '';
68 68
 					?>
69 69
 					<input class="QST_admin_only" type="checkbox" id="QST_admin_only<?php echo $id; ?>" name = "QST_admin_only<?php echo $id; ?>" value="1"<?php echo $disabled; echo $checked; ?>/>
70 70
 					<br/>
71 71
 					<p class="description">
72
-					<?php if ( ! empty( $QST_system )) { ?>
72
+					<?php if ( ! empty($QST_system)) { ?>
73 73
 					<span class="description" style="color:#D54E21;">
74
-						<?php _e('System question! This field cannot be changed.','event_espresso')?>
74
+						<?php _e('System question! This field cannot be changed.', 'event_espresso')?>
75 75
 					</span>
76 76
 					<?php } ?>
77 77
 
@@ -81,21 +81,21 @@  discard block
 block discarded – undo
81 81
 
82 82
 			<tr>
83 83
 				<th>
84
-					<label for="QST_type"><?php echo $fields['QST_type']->get_nicename();?></label> <?php echo EEH_Template::get_help_tab_link('question_type_info');?>
84
+					<label for="QST_type"><?php echo $fields['QST_type']->get_nicename(); ?></label> <?php echo EEH_Template::get_help_tab_link('question_type_info'); ?>
85 85
 				</th>
86 86
 				<td>
87 87
 					<?php
88
-						$disabled = ! empty( $QST_system ) ? ' disabled="disabled"' : '';
89
-						$id =  ! empty( $QST_system ) ? '_disabled' : '';
90
-						echo EEH_Form_Fields::select_input( 'QST_type' . $id, $question_types, $question->type(), 'id="QST_type' . $id . '"' . $disabled );
91
-						if( ! empty( $QST_system ) ) { ?>
88
+						$disabled = ! empty($QST_system) ? ' disabled="disabled"' : '';
89
+						$id = ! empty($QST_system) ? '_disabled' : '';
90
+						echo EEH_Form_Fields::select_input('QST_type'.$id, $question_types, $question->type(), 'id="QST_type'.$id.'"'.$disabled);
91
+						if ( ! empty($QST_system)) { ?>
92 92
 							<input type="hidden"  id="QST_type" name="QST_type" value="<?php echo $question->type()?>"/>
93 93
 						<?php
94
-							$explanatory_text = __('System question! This field cannot be changed.','event_espresso');
95
-						}else{
96
-							$explanatory_text = __('Because there are currently answers for this question in the database, your options to change the question type have been limited to similar question-types.','event_espresso');
94
+							$explanatory_text = __('System question! This field cannot be changed.', 'event_espresso');
95
+						} else {
96
+							$explanatory_text = __('Because there are currently answers for this question in the database, your options to change the question type have been limited to similar question-types.', 'event_espresso');
97 97
 						}
98
-						if ( ! empty( $QST_system ) || $has_answers ) { ?>
98
+						if ( ! empty($QST_system) || $has_answers) { ?>
99 99
 							<p><span class="description" style="color:#D54E21;">
100 100
 								<?php echo $explanatory_text; ?>
101 101
 							</span></p>
@@ -108,22 +108,22 @@  discard block
 block discarded – undo
108 108
 			<tr id="text_input_question_options">
109 109
 				<th>
110 110
 					<label>
111
-						<?php _e( 'Maximum Allowed Response Size', 'event_espresso' );?>
111
+						<?php _e('Maximum Allowed Response Size', 'event_espresso'); ?>
112 112
 					</label>
113 113
 				</th>
114 114
 				<td>
115
-					<input id="QST_max" name="QST_max" type="number" <?php echo $max_max == EE_INF ? '' : "max='$max_max'";?> value="<?php $question->f( 'QST_max' );?>" min="1">
115
+					<input id="QST_max" name="QST_max" type="number" <?php echo $max_max == EE_INF ? '' : "max='$max_max'"; ?> value="<?php $question->f('QST_max'); ?>" min="1">
116 116
 					<p>
117 117
 						<span class="description">
118
-							<?php _e( 'Maximum number of characters allowed when answering this question', 'event_espresso' );?>
118
+							<?php _e('Maximum number of characters allowed when answering this question', 'event_espresso'); ?>
119 119
 						</span>
120 120
 					</p>
121
-					<?php if ( $QST_system ) { ?>
121
+					<?php if ($QST_system) { ?>
122 122
 					<p>
123 123
 						<span class="description" style="color:#D54E21;">
124 124
 							<?php printf(
125
-									__( 'System question! The maximum number of characters that can be used for this question is %1$s', 'event_espresso' ),
126
-									$max_max );?>
125
+									__('System question! The maximum number of characters that can be used for this question is %1$s', 'event_espresso'),
126
+									$max_max ); ?>
127 127
 						</span>
128 128
 					</p>
129 129
 					<?php } ?>
@@ -132,7 +132,7 @@  discard block
 block discarded – undo
132 132
 			<tr id="question_options">
133 133
 				<th>
134 134
 					<label>
135
-						<?php _e('Answer Options','event_espresso')?>
135
+						<?php _e('Answer Options', 'event_espresso')?>
136 136
 					</label>
137 137
 				</th>
138 138
 				<td>
@@ -141,10 +141,10 @@  discard block
 block discarded – undo
141 141
 						<thead>
142 142
 							<tr>
143 143
 								<th class="option-value-header">
144
-									<?php _e('Value','event_espresso')?>
144
+									<?php _e('Value', 'event_espresso')?>
145 145
 								</th>
146 146
 								<th class="option-desc-header">
147
-									<?php _e('Description (optional, only shown on registration form)','event_espresso')?>
147
+									<?php _e('Description (optional, only shown on registration form)', 'event_espresso')?>
148 148
 								</th>
149 149
 								<th>
150 150
 								</th>
@@ -167,17 +167,17 @@  discard block
 block discarded – undo
167 167
 							</tr>
168 168
 
169 169
 							<?php
170
-							$count=0;
170
+							$count = 0;
171 171
 							$question_options = $question->options();
172
-							if ( ! empty( $question_options )) {
173
-								foreach( $question_options as $option_id => $option ) {
174
-									$disabled =  $has_answers || $option->get('QSO_system') ? ' disabled="disabled"'  : '';
172
+							if ( ! empty($question_options)) {
173
+								foreach ($question_options as $option_id => $option) {
174
+									$disabled = $has_answers || $option->get('QSO_system') ? ' disabled="disabled"' : '';
175 175
 							?>
176 176
 								<tr class="question-option ee-options-sortable">
177 177
 									<td class="option-value-cell">
178 178
 										<input type="hidden" class="QSO_order" name="question_options[<?php echo $count; ?>][QSO_order]" value="<?php echo $count; ?>">
179 179
 										<input type="text" class="option-value regular-text" name="question_options[<?php echo $count?>][QSO_value]" value="<?php  $option->f('QSO_value')?>"<?php echo $disabled; ?>>
180
-										<?php if ( $has_answers ) : ?>
180
+										<?php if ($has_answers) : ?>
181 181
 											<input type="hidden" name="question_options[<?php echo $count; ?>][QSO_value]" value="<?php echo $option->f('QSO_value'); ?>" >
182 182
 										<?php endif; ?>
183 183
 									</td>
@@ -185,7 +185,7 @@  discard block
 block discarded – undo
185 185
 										<input type="text" class="option-desc regular-text" name="question_options[<?php echo $count?>][QSO_desc]" value="<?php $option->f('QSO_desc')?>">
186 186
 									</td>
187 187
 									<td>
188
-										<?php if ( ! $option->system() ) { ?>
188
+										<?php if ( ! $option->system()) { ?>
189 189
 											<span class="dashicons clickable dashicons-post-trash ee-icon-size-18 remove-option remove-item"></span>
190 190
 										<?php } ?>
191 191
 										<span class="dashicons dashicons-image-flip-vertical sortable-drag-handle ee-icon-size-18"></span>
@@ -224,13 +224,13 @@  discard block
 block discarded – undo
224 224
 					</table>
225 225
 
226 226
 					<a id="new-question-option" class="button" style="margin:0 0 1em 3px;">
227
-						<?php _e('Add Another Answer Option','event_espresso')?>
227
+						<?php _e('Add Another Answer Option', 'event_espresso')?>
228 228
 					</a><br/>
229 229
 
230 230
 					<p class="description">
231
-						<?php _e('Answer Options are the choices that you give people to select from for RADIO_BTN, CHECKBOX or DROPDOWN questions. The Value is a simple key that will be saved to the database and the description is optional. Note that values CANNOT contain any HTML, but descriptions can.','event_espresso')?>
231
+						<?php _e('Answer Options are the choices that you give people to select from for RADIO_BTN, CHECKBOX or DROPDOWN questions. The Value is a simple key that will be saved to the database and the description is optional. Note that values CANNOT contain any HTML, but descriptions can.', 'event_espresso')?>
232 232
 					</p>
233
-					<?php if ( $has_answers ) : ?>
233
+					<?php if ($has_answers) : ?>
234 234
 					<p class="description" style="color:#D54E21;">
235 235
 							<?php _e('Answer values that are uneditable are this way because there are registrations in the database that have answers for this question.  If you need to correct a mistake, or edit an existing option value, then trash the existing one and create a new option with the changes.  This will ensure that the existing registrations that chose the original answer will preserve that answer.', 'event_espresso'); ?>
236 236
 					</p>
@@ -241,32 +241,32 @@  discard block
 block discarded – undo
241 241
 
242 242
 			<tr>
243 243
 				<th>
244
-					<label for="QST_required"><?php echo $fields['QST_required']->get_nicename();?></label> <?php echo EEH_Template::get_help_tab_link('required_question_info');?>
244
+					<label for="QST_required"><?php echo $fields['QST_required']->get_nicename(); ?></label> <?php echo EEH_Template::get_help_tab_link('required_question_info'); ?>
245 245
 				</th>
246 246
 				<td>
247 247
 					<?php
248
-					$system_required = array( 'fname', 'email' );
249
-					$disabled = in_array( $QST_system, $system_required ) ? ' disabled="disabled"' : '';
248
+					$system_required = array('fname', 'email');
249
+					$disabled = in_array($QST_system, $system_required) ? ' disabled="disabled"' : '';
250 250
 					$required_on = $question->get('QST_admin_only');
251 251
 					$show_required_msg = $required_on ? '' : ' display:none;';
252
-					$disabled = $required_on || ! empty( $disabled ) ? ' disabled="disabled"' : '';
253
-					$id =  ! empty( $disabled ) && in_array( $QST_system, $system_required) ? '_disabled' : '';
254
-					$requiredOptions=array(
255
-						array('text'=>'Optional','id'=>0),
256
-						array('text'=>'Required','id'=>1)
252
+					$disabled = $required_on || ! empty($disabled) ? ' disabled="disabled"' : '';
253
+					$id = ! empty($disabled) && in_array($QST_system, $system_required) ? '_disabled' : '';
254
+					$requiredOptions = array(
255
+						array('text'=>'Optional', 'id'=>0),
256
+						array('text'=>'Required', 'id'=>1)
257 257
 					);
258
-					echo EEH_Form_Fields::select_input('QST_required' . $id, $requiredOptions, $question->required(), 'id="QST_required' . $id . '"' . $disabled );
258
+					echo EEH_Form_Fields::select_input('QST_required'.$id, $requiredOptions, $question->required(), 'id="QST_required'.$id.'"'.$disabled);
259 259
 					?>
260 260
 						<p><span id="required_toggled_on" class="description" style="color:#D54E21;<?php echo $show_required_msg; ?>">
261
-						<?php _e('Required is set to optional, and this field is disabled, because the question is Admin-Only.','event_espresso')?>
261
+						<?php _e('Required is set to optional, and this field is disabled, because the question is Admin-Only.', 'event_espresso')?>
262 262
 						</span></p>
263 263
 						<p><span id="required_toggled_off" class="description" style="color:#D54E21; display: none;">
264
-							<?php _e('Required option field is no longer disabled because the question is not Admin-Only','event_espresso')?>
264
+							<?php _e('Required option field is no longer disabled because the question is not Admin-Only', 'event_espresso')?>
265 265
 						</span></p>
266
-					<?php if ( ! empty( $disabled ) && in_array( $QST_system, $system_required ) ) { ?>
266
+					<?php if ( ! empty($disabled) && in_array($QST_system, $system_required)) { ?>
267 267
 						<input type="hidden"  id="QST_required" name="QST_required" value="1"/>
268 268
 						<p><span class="description" style="color:#D54E21;">
269
-						<?php _e('System question! This field cannot be changed.','event_espresso')?>
269
+						<?php _e('System question! This field cannot be changed.', 'event_espresso')?>
270 270
 					</span></p>
271 271
 					<?php } ?>
272 272
 
@@ -275,7 +275,7 @@  discard block
 block discarded – undo
275 275
 
276 276
 			<tr>
277 277
 				<th>
278
-					<label for="QST_required_text"><?php _e('Required Text', 'event_espresso'); ?></label> <?php echo EEH_Template::get_help_tab_link('required_text_info');?>
278
+					<label for="QST_required_text"><?php _e('Required Text', 'event_espresso'); ?></label> <?php echo EEH_Template::get_help_tab_link('required_text_info'); ?>
279 279
 				</th>
280 280
 				<td>
281 281
 					<input type="text" class="regular-text" id="QST_required_text" name="QST_required_text" value="<?php  $question->f('QST_required_text')?>"/>
Please login to merge, or discard this patch.
core/helpers/EEH_Activation.helper.php 1 patch
Spacing   +367 added lines, -367 removed lines patch added patch discarded remove patch
@@ -57,9 +57,9 @@  discard block
 block discarded – undo
57 57
 	 * @param $table_name
58 58
 	 * @return string
59 59
 	 */
60
-	public static function ensure_table_name_has_prefix( $table_name ) {
60
+	public static function ensure_table_name_has_prefix($table_name) {
61 61
 		global $wpdb;
62
-		return strpos( $table_name, $wpdb->prefix ) === 0 ? $table_name : $wpdb->prefix . $table_name;
62
+		return strpos($table_name, $wpdb->prefix) === 0 ? $table_name : $wpdb->prefix.$table_name;
63 63
 	}
64 64
 
65 65
 
@@ -85,7 +85,7 @@  discard block
 block discarded – undo
85 85
 	 * be called on plugin activation and reactivation
86 86
 	 * @return boolean success, whether the database and folders are setup properly
87 87
 	 */
88
-	public static function initialize_db_and_folders(){
88
+	public static function initialize_db_and_folders() {
89 89
 		$good_filesystem = EEH_Activation::create_upload_directories();
90 90
 		$good_db = EEH_Activation::create_database_tables();
91 91
 		return $good_filesystem && $good_db;
@@ -99,9 +99,9 @@  discard block
 block discarded – undo
99 99
 	 * upon activation of a new plugin, reactivation, and at the end
100 100
 	 * of running migration scripts
101 101
 	 */
102
-	public static function initialize_db_content(){
102
+	public static function initialize_db_content() {
103 103
 		//let's avoid doing all this logic repeatedly, especially when addons are requesting it
104
-		if( EEH_Activation::$_initialized_db_content_already_in_this_request ) {
104
+		if (EEH_Activation::$_initialized_db_content_already_in_this_request) {
105 105
 			return;
106 106
 		}
107 107
 		EEH_Activation::$_initialized_db_content_already_in_this_request = true;
@@ -118,7 +118,7 @@  discard block
 block discarded – undo
118 118
 		EEH_Activation::remove_cron_tasks();
119 119
 		EEH_Activation::create_cron_tasks();
120 120
 		//also, check for CAF default db content
121
-		do_action( 'AHEE__EEH_Activation__initialize_db_content' );
121
+		do_action('AHEE__EEH_Activation__initialize_db_content');
122 122
 		//also: EEM_Gateways::load_all_gateways() outputs a lot of success messages
123 123
 		//which users really won't care about on initial activation
124 124
 		EE_Error::overwrite_success();
@@ -137,7 +137,7 @@  discard block
 block discarded – undo
137 137
 	 * @return array
138 138
 	 * @throws \EE_Error
139 139
 	 */
140
-	public static function get_cron_tasks( $which_to_include ) {
140
+	public static function get_cron_tasks($which_to_include) {
141 141
 		$cron_tasks = apply_filters(
142 142
 			'FHEE__EEH_Activation__get_cron_tasks',
143 143
 			array(
@@ -146,17 +146,17 @@  discard block
 block discarded – undo
146 146
 				'AHEE__EE_Cron_Tasks__update_transaction_with_payment' => EEH_Activation::cron_task_no_longer_in_use, //there may have been a bug which prevented from these cron tasks from getting unscheduled, so we might want to remove these for a few updates
147 147
 			)
148 148
 		);
149
-		if( $which_to_include === 'all' ) {
149
+		if ($which_to_include === 'all') {
150 150
 			//leave as-is
151
-		}elseif( $which_to_include === 'old' ) {
152
-			$cron_tasks = array_filter( $cron_tasks, function ( $value ) {
151
+		}elseif ($which_to_include === 'old') {
152
+			$cron_tasks = array_filter($cron_tasks, function($value) {
153 153
 				return $value === EEH_Activation::cron_task_no_longer_in_use;
154 154
 			});
155
-		}elseif( $which_to_include === 'current' ) {
156
-			$cron_tasks = array_filter( $cron_tasks );
157
-		}elseif( WP_DEBUG ) {
158
-			throw new EE_Error( sprintf( __( 'Invalidate argument of "%1$s" passed to EEH_Activation::get_cron_tasks. Valid values are "all", "old" and "current".', 'event_espresso' ), $which_to_include ) );
159
-		}else{
155
+		}elseif ($which_to_include === 'current') {
156
+			$cron_tasks = array_filter($cron_tasks);
157
+		}elseif (WP_DEBUG) {
158
+			throw new EE_Error(sprintf(__('Invalidate argument of "%1$s" passed to EEH_Activation::get_cron_tasks. Valid values are "all", "old" and "current".', 'event_espresso'), $which_to_include));
159
+		} else {
160 160
 			//leave as-is
161 161
 		}
162 162
 		return $cron_tasks;
@@ -167,9 +167,9 @@  discard block
 block discarded – undo
167 167
 	 */
168 168
 	public static function create_cron_tasks() {
169 169
 
170
-		foreach( EEH_Activation::get_cron_tasks( 'current' ) as $hook_name => $frequency ) {
171
-			if( ! wp_next_scheduled( $hook_name ) ) {
172
-				wp_schedule_event( time(), $frequency, $hook_name );
170
+		foreach (EEH_Activation::get_cron_tasks('current') as $hook_name => $frequency) {
171
+			if ( ! wp_next_scheduled($hook_name)) {
172
+				wp_schedule_event(time(), $frequency, $hook_name);
173 173
 			}
174 174
 		}
175 175
 
@@ -179,10 +179,10 @@  discard block
 block discarded – undo
179 179
 	 * Remove the currently-existing and now-removed cron tasks.
180 180
 	 * @param boolean $remove_all whether to only remove the old ones, or remove absolutely ALL the EE ones
181 181
 	 */
182
-	public static function remove_cron_tasks( $remove_all = true ) {
182
+	public static function remove_cron_tasks($remove_all = true) {
183 183
 		$cron_tasks_to_remove = $remove_all ? 'all' : 'old';
184 184
 		$crons = _get_cron_array();
185
-		$crons = is_array( $crons ) ? $crons : array();
185
+		$crons = is_array($crons) ? $crons : array();
186 186
 		/* reminder that $crons looks like: top-level keys are timestamps,
187 187
 		 * and their values are arrays.
188 188
 		 * The 2nd level arrays have keys with each of the cron task hooknames to run at that time
@@ -200,14 +200,14 @@  discard block
 block discarded – undo
200 200
 		 *					...
201 201
 		 *      ...
202 202
 		 */
203
-		foreach( EEH_Activation::get_cron_tasks( $cron_tasks_to_remove ) as $hook_name => $frequency ) {
204
-			foreach( $crons as $timestamp => $hooks_to_fire_at_time ) {
205
-				if ( array_key_exists( $hook_name, $hooks_to_fire_at_time ) )  {
206
-					unset( $crons[ $timestamp ][ $hook_name ] );
203
+		foreach (EEH_Activation::get_cron_tasks($cron_tasks_to_remove) as $hook_name => $frequency) {
204
+			foreach ($crons as $timestamp => $hooks_to_fire_at_time) {
205
+				if (array_key_exists($hook_name, $hooks_to_fire_at_time)) {
206
+					unset($crons[$timestamp][$hook_name]);
207 207
 				}
208 208
 			}
209 209
 		}
210
-		_set_cron_array( $crons );
210
+		_set_cron_array($crons);
211 211
 	}
212 212
 
213 213
 
@@ -222,7 +222,7 @@  discard block
 block discarded – undo
222 222
 	 */
223 223
 	public static function CPT_initialization() {
224 224
 		// register Custom Post Types
225
-		EE_Registry::instance()->load_core( 'Register_CPTs' );
225
+		EE_Registry::instance()->load_core('Register_CPTs');
226 226
 		flush_rewrite_rules();
227 227
 	}
228 228
 
@@ -240,8 +240,8 @@  discard block
 block discarded – undo
240 240
 	 * 	@return void
241 241
 	 */
242 242
 	public static function reset_and_update_config() {
243
-		do_action( 'AHEE__EE_Config___load_core_config__start', array( 'EEH_Activation', 'load_calendar_config' ) );
244
-		add_filter( 'FHEE__EE_Config___load_core_config__config_settings', array( 'EEH_Activation', 'migrate_old_config_data' ), 10, 3 );
243
+		do_action('AHEE__EE_Config___load_core_config__start', array('EEH_Activation', 'load_calendar_config'));
244
+		add_filter('FHEE__EE_Config___load_core_config__config_settings', array('EEH_Activation', 'migrate_old_config_data'), 10, 3);
245 245
 		//EE_Config::reset();
246 246
 	}
247 247
 
@@ -254,23 +254,23 @@  discard block
 block discarded – undo
254 254
 	 */
255 255
 	public static function load_calendar_config() {
256 256
 		// grab array of all plugin folders and loop thru it
257
-		$plugins = glob( WP_PLUGIN_DIR . DS . '*', GLOB_ONLYDIR );
258
-		if ( empty( $plugins ) ) {
257
+		$plugins = glob(WP_PLUGIN_DIR.DS.'*', GLOB_ONLYDIR);
258
+		if (empty($plugins)) {
259 259
 			return;
260 260
 		}
261
-		foreach ( $plugins as $plugin_path ) {
261
+		foreach ($plugins as $plugin_path) {
262 262
 			// grab plugin folder name from path
263
-			$plugin = basename( $plugin_path );
263
+			$plugin = basename($plugin_path);
264 264
 			// drill down to Espresso plugins
265
-			if ( strpos( $plugin, 'espresso' ) !== FALSE || strpos( $plugin, 'Espresso' ) !== FALSE || strpos( $plugin, 'ee4' ) !== FALSE || strpos( $plugin, 'EE4' ) !== FALSE ) {
265
+			if (strpos($plugin, 'espresso') !== FALSE || strpos($plugin, 'Espresso') !== FALSE || strpos($plugin, 'ee4') !== FALSE || strpos($plugin, 'EE4') !== FALSE) {
266 266
 				// then to calendar related plugins
267
-				if ( strpos( $plugin, 'calendar' ) !== FALSE ) {
267
+				if (strpos($plugin, 'calendar') !== FALSE) {
268 268
 					// this is what we are looking for
269
-					$calendar_config = $plugin_path . DS . 'EE_Calendar_Config.php';
269
+					$calendar_config = $plugin_path.DS.'EE_Calendar_Config.php';
270 270
 					// does it exist in this folder ?
271
-					if ( is_readable( $calendar_config )) {
271
+					if (is_readable($calendar_config)) {
272 272
 						// YEAH! let's load it
273
-						require_once( $calendar_config );
273
+						require_once($calendar_config);
274 274
 					}
275 275
 				}
276 276
 			}
@@ -287,21 +287,21 @@  discard block
 block discarded – undo
287 287
 	 * @param \EE_Config $EE_Config
288 288
 	 * @return \stdClass
289 289
 	 */
290
-	public static function migrate_old_config_data( $settings = array(), $config = '', EE_Config $EE_Config ) {
291
-		$convert_from_array = array( 'addons' );
290
+	public static function migrate_old_config_data($settings = array(), $config = '', EE_Config $EE_Config) {
291
+		$convert_from_array = array('addons');
292 292
 		// in case old settings were saved as an array
293
-		if ( is_array( $settings ) && in_array( $config, $convert_from_array )) {
293
+		if (is_array($settings) && in_array($config, $convert_from_array)) {
294 294
 			// convert existing settings to an object
295 295
 			$config_array = $settings;
296 296
 			$settings = new stdClass();
297
-			foreach ( $config_array as $key => $value ){
298
-				if ( $key == 'calendar' && class_exists( 'EE_Calendar_Config' )) {
299
-					$EE_Config->set_config( 'addons', 'EE_Calendar', 'EE_Calendar_Config', $value );
297
+			foreach ($config_array as $key => $value) {
298
+				if ($key == 'calendar' && class_exists('EE_Calendar_Config')) {
299
+					$EE_Config->set_config('addons', 'EE_Calendar', 'EE_Calendar_Config', $value);
300 300
 				} else {
301 301
 					$settings->$key = $value;
302 302
 				}
303 303
 			}
304
-			add_filter( 'FHEE__EE_Config___load_core_config__update_espresso_config', '__return_true' );
304
+			add_filter('FHEE__EE_Config___load_core_config__update_espresso_config', '__return_true');
305 305
 		}
306 306
 		return $settings;
307 307
 	}
@@ -317,8 +317,8 @@  discard block
 block discarded – undo
317 317
 	 */
318 318
 	public static function deactivate_event_espresso() {
319 319
 		// check permissions
320
-		if ( current_user_can( 'activate_plugins' )) {
321
-			deactivate_plugins( EE_PLUGIN_BASENAME, TRUE );
320
+		if (current_user_can('activate_plugins')) {
321
+			deactivate_plugins(EE_PLUGIN_BASENAME, TRUE);
322 322
 		}
323 323
 	}
324 324
 
@@ -340,79 +340,79 @@  discard block
 block discarded – undo
340 340
 		$critical_pages = array(
341 341
 			array(
342 342
 				'id' =>'reg_page_id',
343
-				'name' => __( 'Registration Checkout', 'event_espresso' ),
343
+				'name' => __('Registration Checkout', 'event_espresso'),
344 344
 				'post' => NULL,
345 345
 				'code' => 'ESPRESSO_CHECKOUT'
346 346
 			),
347 347
 			array(
348 348
 				'id' => 'txn_page_id',
349
-				'name' => __( 'Transactions', 'event_espresso' ),
349
+				'name' => __('Transactions', 'event_espresso'),
350 350
 				'post' => NULL,
351 351
 				'code' => 'ESPRESSO_TXN_PAGE'
352 352
 			),
353 353
 			array(
354 354
 				'id' => 'thank_you_page_id',
355
-				'name' => __( 'Thank You', 'event_espresso' ),
355
+				'name' => __('Thank You', 'event_espresso'),
356 356
 				'post' => NULL,
357 357
 				'code' => 'ESPRESSO_THANK_YOU'
358 358
 			),
359 359
 			array(
360 360
 				'id' => 'cancel_page_id',
361
-				'name' => __( 'Registration Cancelled', 'event_espresso' ),
361
+				'name' => __('Registration Cancelled', 'event_espresso'),
362 362
 				'post' => NULL,
363 363
 				'code' => 'ESPRESSO_CANCELLED'
364 364
 			),
365 365
 		);
366 366
 
367
-		foreach ( $critical_pages as $critical_page ) {
367
+		foreach ($critical_pages as $critical_page) {
368 368
 			// is critical page ID set in config ?
369
-			if ( EE_Registry::instance()->CFG->core->$critical_page['id'] !== FALSE ) {
369
+			if (EE_Registry::instance()->CFG->core->$critical_page['id'] !== FALSE) {
370 370
 				// attempt to find post by ID
371
-				$critical_page['post'] = get_post( EE_Registry::instance()->CFG->core->$critical_page['id'] );
371
+				$critical_page['post'] = get_post(EE_Registry::instance()->CFG->core->$critical_page['id']);
372 372
 			}
373 373
 			// no dice?
374
-			if ( $critical_page['post'] == NULL ) {
374
+			if ($critical_page['post'] == NULL) {
375 375
 				// attempt to find post by title
376
-				$critical_page['post'] = self::get_page_by_ee_shortcode( $critical_page['code'] );
376
+				$critical_page['post'] = self::get_page_by_ee_shortcode($critical_page['code']);
377 377
 				// still nothing?
378
-				if ( $critical_page['post'] == NULL ) {
379
-					$critical_page = EEH_Activation::create_critical_page( $critical_page );
378
+				if ($critical_page['post'] == NULL) {
379
+					$critical_page = EEH_Activation::create_critical_page($critical_page);
380 380
 					// REALLY? Still nothing ??!?!?
381
-					if ( $critical_page['post'] == NULL ) {
382
-						$msg = __( 'The Event Espresso critical page configuration settings could not be updated.', 'event_espresso' );
383
-						EE_Error::add_error( $msg, __FILE__, __FUNCTION__, __LINE__ );
381
+					if ($critical_page['post'] == NULL) {
382
+						$msg = __('The Event Espresso critical page configuration settings could not be updated.', 'event_espresso');
383
+						EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
384 384
 						break;
385 385
 					}
386 386
 				}
387 387
 			}
388 388
 			// track post_shortcodes
389
-			if ( $critical_page['post'] ) {
390
-				EEH_Activation::_track_critical_page_post_shortcodes( $critical_page );
389
+			if ($critical_page['post']) {
390
+				EEH_Activation::_track_critical_page_post_shortcodes($critical_page);
391 391
 			}
392 392
 			// check that Post ID matches critical page ID in config
393
-			if ( isset( $critical_page['post']->ID ) && $critical_page['post']->ID != EE_Registry::instance()->CFG->core->$critical_page['id'] ) {
393
+			if (isset($critical_page['post']->ID) && $critical_page['post']->ID != EE_Registry::instance()->CFG->core->$critical_page['id']) {
394 394
 				//update Config with post ID
395 395
 				EE_Registry::instance()->CFG->core->$critical_page['id'] = $critical_page['post']->ID;
396
-				if ( ! EE_Config::instance()->update_espresso_config( FALSE, FALSE ) ) {
397
-					$msg = __( 'The Event Espresso critical page configuration settings could not be updated.', 'event_espresso' );
398
-					EE_Error::add_error( $msg, __FILE__, __FUNCTION__, __LINE__ );
396
+				if ( ! EE_Config::instance()->update_espresso_config(FALSE, FALSE)) {
397
+					$msg = __('The Event Espresso critical page configuration settings could not be updated.', 'event_espresso');
398
+					EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
399 399
 				}
400 400
 			}
401 401
 
402
-			$critical_page_problem =  ! isset( $critical_page['post']->post_status ) || $critical_page['post']->post_status != 'publish' || strpos( $critical_page['post']->post_content, $critical_page['code'] ) === FALSE ? TRUE : $critical_page_problem;
402
+			$critical_page_problem = ! isset($critical_page['post']->post_status) || $critical_page['post']->post_status != 'publish' || strpos($critical_page['post']->post_content, $critical_page['code']) === FALSE ? TRUE : $critical_page_problem;
403 403
 
404 404
 		}
405 405
 
406
-		if ( $critical_page_problem ) {
406
+		if ($critical_page_problem) {
407 407
 			$msg = sprintf(
408
-				__('A potential issue has been detected with one or more of your Event Espresso pages. Go to %s to view your Event Espresso pages.', 'event_espresso' ),
409
-				'<a href="' . admin_url('admin.php?page=espresso_general_settings&action=critical_pages') . '">' . __('Event Espresso Critical Pages Settings', 'event_espresso') . '</a>'
408
+				__('A potential issue has been detected with one or more of your Event Espresso pages. Go to %s to view your Event Espresso pages.', 'event_espresso'),
409
+				'<a href="'.admin_url('admin.php?page=espresso_general_settings&action=critical_pages').'">'.__('Event Espresso Critical Pages Settings', 'event_espresso').'</a>'
410 410
 			);
411
-			EE_Error::add_persistent_admin_notice( 'critical_page_problem', $msg );
411
+			EE_Error::add_persistent_admin_notice('critical_page_problem', $msg);
412 412
 		}
413 413
 
414
-		if ( EE_Error::has_notices() ) {
415
-			EE_Error::get_notices( FALSE, TRUE, TRUE );
414
+		if (EE_Error::has_notices()) {
415
+			EE_Error::get_notices(FALSE, TRUE, TRUE);
416 416
 		}
417 417
 
418 418
 	}
@@ -425,13 +425,13 @@  discard block
 block discarded – undo
425 425
 	 * parameter to the shortcode
426 426
 	 * @return WP_Post or NULl
427 427
 	 */
428
-	public static function get_page_by_ee_shortcode($ee_shortcode){
428
+	public static function get_page_by_ee_shortcode($ee_shortcode) {
429 429
 		global $wpdb;
430 430
 		$shortcode_and_opening_bracket = '['.$ee_shortcode;
431 431
 		$post_id = $wpdb->get_var("SELECT ID FROM {$wpdb->posts} WHERE post_content LIKE '%$shortcode_and_opening_bracket%' LIMIT 1");
432
-		if($post_id){
432
+		if ($post_id) {
433 433
 			return get_post($post_id);
434
-		}else{
434
+		} else {
435 435
 			return NULL;
436 436
 		}
437 437
 
@@ -448,32 +448,32 @@  discard block
 block discarded – undo
448 448
 	 * @param array $critical_page
449 449
 	 * @return array
450 450
 	 */
451
-	public static function create_critical_page( $critical_page ) {
451
+	public static function create_critical_page($critical_page) {
452 452
 
453 453
 		$post_args = array(
454 454
 			'post_title' => $critical_page['name'],
455 455
 			'post_status' => 'publish',
456 456
 			'post_type' => 'page',
457 457
 			'comment_status' => 'closed',
458
-			'post_content' => '[' . $critical_page['code'] . ']'
458
+			'post_content' => '['.$critical_page['code'].']'
459 459
 		);
460 460
 
461
-		$post_id = wp_insert_post( $post_args );
462
-		if ( ! $post_id ) {
461
+		$post_id = wp_insert_post($post_args);
462
+		if ( ! $post_id) {
463 463
 			$msg = sprintf(
464
-				__( 'The Event Espresso  critical page entitled "%s" could not be created.', 'event_espresso' ),
464
+				__('The Event Espresso  critical page entitled "%s" could not be created.', 'event_espresso'),
465 465
 				$critical_page['name']
466 466
 			);
467
-			EE_Error::add_error( $msg, __FILE__, __FUNCTION__, __LINE__ );
467
+			EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
468 468
 			return $critical_page;
469 469
 		}
470 470
 		// get newly created post's details
471
-		if ( ! $critical_page['post'] = get_post( $post_id )) {
471
+		if ( ! $critical_page['post'] = get_post($post_id)) {
472 472
 			$msg = sprintf(
473
-				__( 'The Event Espresso critical page entitled "%s" could not be retrieved.', 'event_espresso' ),
473
+				__('The Event Espresso critical page entitled "%s" could not be retrieved.', 'event_espresso'),
474 474
 				$critical_page['name']
475 475
 			);
476
-			EE_Error::add_error( $msg, __FILE__, __FUNCTION__, __LINE__ );
476
+			EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
477 477
 		}
478 478
 
479 479
 		return $critical_page;
@@ -492,34 +492,34 @@  discard block
 block discarded – undo
492 492
 	 * @param array $critical_page
493 493
 	 * @return void
494 494
 	 */
495
-	private static function _track_critical_page_post_shortcodes( $critical_page = array() ) {
495
+	private static function _track_critical_page_post_shortcodes($critical_page = array()) {
496 496
 		// check the goods
497
-		if ( ! $critical_page['post'] instanceof WP_Post ) {
497
+		if ( ! $critical_page['post'] instanceof WP_Post) {
498 498
 			$msg = sprintf(
499
-				__( 'The Event Espresso critical page shortcode for the page %s can not be tracked because it is not a WP_Post object.', 'event_espresso' ),
499
+				__('The Event Espresso critical page shortcode for the page %s can not be tracked because it is not a WP_Post object.', 'event_espresso'),
500 500
 				$critical_page['name']
501 501
 			);
502
-			EE_Error::add_error( $msg, __FILE__, __FUNCTION__, __LINE__ );
502
+			EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
503 503
 			return;
504 504
 		}
505 505
 		// map shortcode to post
506
-		EE_Registry::instance()->CFG->core->post_shortcodes[ $critical_page['post']->post_name ][ $critical_page['code'] ] = $critical_page['post']->ID;
506
+		EE_Registry::instance()->CFG->core->post_shortcodes[$critical_page['post']->post_name][$critical_page['code']] = $critical_page['post']->ID;
507 507
 		// and make sure it's NOT added to the WP "Posts Page"
508 508
 		// name of the WP Posts Page
509 509
 		$posts_page = EE_Registry::instance()->CFG->get_page_for_posts();
510
-		if ( isset( EE_Registry::instance()->CFG->core->post_shortcodes[ $posts_page ] )) {
511
-			unset( EE_Registry::instance()->CFG->core->post_shortcodes[ $posts_page ][ $critical_page['code'] ] );
510
+		if (isset(EE_Registry::instance()->CFG->core->post_shortcodes[$posts_page])) {
511
+			unset(EE_Registry::instance()->CFG->core->post_shortcodes[$posts_page][$critical_page['code']]);
512 512
 		}
513
-		if ( $posts_page != 'posts' && isset( EE_Registry::instance()->CFG->core->post_shortcodes['posts'] )) {
514
-			unset( EE_Registry::instance()->CFG->core->post_shortcodes['posts'][ $critical_page['code'] ] );
513
+		if ($posts_page != 'posts' && isset(EE_Registry::instance()->CFG->core->post_shortcodes['posts'])) {
514
+			unset(EE_Registry::instance()->CFG->core->post_shortcodes['posts'][$critical_page['code']]);
515 515
 		}
516 516
 		// update post_shortcode CFG
517
-		if ( ! EE_Config::instance()->update_espresso_config( FALSE, FALSE )) {
517
+		if ( ! EE_Config::instance()->update_espresso_config(FALSE, FALSE)) {
518 518
 			$msg = sprintf(
519
-				__( 'The Event Espresso critical page shortcode for the %s page could not be configured properly.', 'event_espresso' ),
519
+				__('The Event Espresso critical page shortcode for the %s page could not be configured properly.', 'event_espresso'),
520 520
 				$critical_page['name']
521 521
 			);
522
-			EE_Error::add_error( $msg, __FILE__, __FUNCTION__, __LINE__ );
522
+			EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
523 523
 		}
524 524
 	}
525 525
 
@@ -537,24 +537,24 @@  discard block
 block discarded – undo
537 537
 	public static function get_default_creator_id() {
538 538
 		global $wpdb;
539 539
 
540
-		if ( ! empty( self::$_default_creator_id ) ) {
540
+		if ( ! empty(self::$_default_creator_id)) {
541 541
 			return self::$_default_creator_id;
542 542
 		}/**/
543 543
 
544
-		$role_to_check = apply_filters( 'FHEE__EEH_Activation__get_default_creator_id__role_to_check', 'administrator' );
544
+		$role_to_check = apply_filters('FHEE__EEH_Activation__get_default_creator_id__role_to_check', 'administrator');
545 545
 
546 546
 		//let's allow pre_filtering for early exits by alternative methods for getting id.  We check for truthy result and if so then exit early.
547
-		$pre_filtered_id = apply_filters( 'FHEE__EEH_Activation__get_default_creator_id__pre_filtered_id', false, $role_to_check );
548
-		if ( $pre_filtered_id !== false ) {
547
+		$pre_filtered_id = apply_filters('FHEE__EEH_Activation__get_default_creator_id__pre_filtered_id', false, $role_to_check);
548
+		if ($pre_filtered_id !== false) {
549 549
 			return (int) $pre_filtered_id;
550 550
 		}
551 551
 
552
-		$capabilities_key = EEH_Activation::ensure_table_name_has_prefix( 'capabilities' );
553
-		$query = $wpdb->prepare( "SELECT user_id FROM $wpdb->usermeta WHERE meta_key = '$capabilities_key' AND meta_value LIKE %s ORDER BY user_id ASC LIMIT 0,1", '%' . $role_to_check . '%' );
554
-		$user_id = $wpdb->get_var( $query );
555
-		 $user_id = apply_filters( 'FHEE__EEH_Activation_Helper__get_default_creator_id__user_id', $user_id );
556
-		 if ( $user_id && intval( $user_id ) ) {
557
-		 	self::$_default_creator_id =  intval( $user_id );
552
+		$capabilities_key = EEH_Activation::ensure_table_name_has_prefix('capabilities');
553
+		$query = $wpdb->prepare("SELECT user_id FROM $wpdb->usermeta WHERE meta_key = '$capabilities_key' AND meta_value LIKE %s ORDER BY user_id ASC LIMIT 0,1", '%'.$role_to_check.'%');
554
+		$user_id = $wpdb->get_var($query);
555
+		 $user_id = apply_filters('FHEE__EEH_Activation_Helper__get_default_creator_id__user_id', $user_id);
556
+		 if ($user_id && intval($user_id)) {
557
+		 	self::$_default_creator_id = intval($user_id);
558 558
 		 	return self::$_default_creator_id;
559 559
 		 } else {
560 560
 		 	return NULL;
@@ -581,29 +581,29 @@  discard block
 block discarded – undo
581 581
 	 * 	@return void
582 582
 	 * @throws EE_Error if there are database errors
583 583
 	 */
584
-	public static function create_table( $table_name, $sql, $engine = 'ENGINE=MyISAM ', $drop_pre_existing_table = false ) {
585
-		if( apply_filters( 'FHEE__EEH_Activation__create_table__short_circuit', FALSE, $table_name, $sql ) ){
584
+	public static function create_table($table_name, $sql, $engine = 'ENGINE=MyISAM ', $drop_pre_existing_table = false) {
585
+		if (apply_filters('FHEE__EEH_Activation__create_table__short_circuit', FALSE, $table_name, $sql)) {
586 586
 			return;
587 587
 		}
588
-		do_action( 'AHEE_log', __FILE__, __FUNCTION__, '' );
589
-		if ( ! function_exists( 'dbDelta' )) {
590
-			require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
588
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
589
+		if ( ! function_exists('dbDelta')) {
590
+			require_once(ABSPATH.'wp-admin/includes/upgrade.php');
591 591
 		}
592 592
 		/** @var WPDB $wpdb */
593 593
 		global $wpdb;
594
-		$wp_table_name = EEH_Activation::ensure_table_name_has_prefix( $table_name );
594
+		$wp_table_name = EEH_Activation::ensure_table_name_has_prefix($table_name);
595 595
 		// do we need to first delete an existing version of this table ?
596
-		if ( $drop_pre_existing_table && EEH_Activation::table_exists( $wp_table_name ) ){
596
+		if ($drop_pre_existing_table && EEH_Activation::table_exists($wp_table_name)) {
597 597
 			// ok, delete the table... but ONLY if it's empty
598
-			$deleted_safely = EEH_Activation::delete_db_table_if_empty( $wp_table_name );
598
+			$deleted_safely = EEH_Activation::delete_db_table_if_empty($wp_table_name);
599 599
 			// table is NOT empty, are you SURE you want to delete this table ???
600
-			if ( ! $deleted_safely && defined( 'EE_DROP_BAD_TABLES' ) && EE_DROP_BAD_TABLES ){
601
-				EEH_Activation::delete_unused_db_table( $wp_table_name );
602
-			} else if ( ! $deleted_safely ) {
600
+			if ( ! $deleted_safely && defined('EE_DROP_BAD_TABLES') && EE_DROP_BAD_TABLES) {
601
+				EEH_Activation::delete_unused_db_table($wp_table_name);
602
+			} else if ( ! $deleted_safely) {
603 603
 				// so we should be more cautious rather than just dropping tables so easily
604 604
 				EE_Error::add_persistent_admin_notice(
605
-						'bad_table_' . $wp_table_name . '_detected',
606
-						sprintf( __( 'Database table %1$s exists when it shouldn\'t, and may contain erroneous data. If you have previously restored your database from a backup that didn\'t remove the old tables, then we recommend adding %2$s to your %3$s file then restore to that backup again. This will clear out the invalid data from %1$s. Afterwards you should undo that change from your %3$s file. %4$sIf you cannot edit %3$s, you should remove the data from %1$s manually then restore to the backup again.', 'event_espresso' ),
605
+						'bad_table_'.$wp_table_name.'_detected',
606
+						sprintf(__('Database table %1$s exists when it shouldn\'t, and may contain erroneous data. If you have previously restored your database from a backup that didn\'t remove the old tables, then we recommend adding %2$s to your %3$s file then restore to that backup again. This will clear out the invalid data from %1$s. Afterwards you should undo that change from your %3$s file. %4$sIf you cannot edit %3$s, you should remove the data from %1$s manually then restore to the backup again.', 'event_espresso'),
607 607
 								$wp_table_name,
608 608
 								"<pre>define( 'EE_DROP_BAD_TABLES', TRUE );</pre>",
609 609
 								'<b>wp-config.php</b>',
@@ -612,25 +612,25 @@  discard block
 block discarded – undo
612 612
 			}
613 613
 		}
614 614
 		// does $sql contain valid column information? ( LPT: https://regex101.com/ is great for working out regex patterns )
615
-		if ( preg_match( '((((.*?))(,\s))+)', $sql, $valid_column_data ) ) {
615
+		if (preg_match('((((.*?))(,\s))+)', $sql, $valid_column_data)) {
616 616
 			$SQL = "CREATE TABLE $wp_table_name ( $sql ) $engine DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci;";
617 617
 			//get $wpdb to echo errors, but buffer them. This way at least WE know an error
618 618
 			//happened. And then we can choose to tell the end user
619
-			$old_show_errors_policy = $wpdb->show_errors( TRUE );
620
-			$old_error_suppression_policy = $wpdb->suppress_errors( FALSE );
619
+			$old_show_errors_policy = $wpdb->show_errors(TRUE);
620
+			$old_error_suppression_policy = $wpdb->suppress_errors(FALSE);
621 621
 			ob_start();
622
-			dbDelta( $SQL );
622
+			dbDelta($SQL);
623 623
 			$output = ob_get_contents();
624 624
 			ob_end_clean();
625
-			$wpdb->show_errors( $old_show_errors_policy );
626
-			$wpdb->suppress_errors( $old_error_suppression_policy );
627
-			if( ! empty( $output ) ){
628
-				throw new EE_Error( $output	);
625
+			$wpdb->show_errors($old_show_errors_policy);
626
+			$wpdb->suppress_errors($old_error_suppression_policy);
627
+			if ( ! empty($output)) {
628
+				throw new EE_Error($output);
629 629
 			}
630 630
 		} else {
631 631
 			throw new EE_Error(
632 632
 				sprintf(
633
-					__( 'The following table creation SQL does not contain valid information about the table columns: %1$s %2$s', 'event_espresso' ),
633
+					__('The following table creation SQL does not contain valid information about the table columns: %1$s %2$s', 'event_espresso'),
634 634
 					'<br />',
635 635
 					$sql
636 636
 				)
@@ -652,15 +652,15 @@  discard block
 block discarded – undo
652 652
 	 * @param string $column_info if your SQL were 'ALTER TABLE table_name ADD price VARCHAR(10)', this would be 'VARCHAR(10)'
653 653
 	 * @return bool|int
654 654
 	 */
655
-	public static function add_column_if_it_doesnt_exist($table_name,$column_name,$column_info='INT UNSIGNED NOT NULL'){
656
-		if( apply_filters( 'FHEE__EEH_Activation__add_column_if_it_doesnt_exist__short_circuit', FALSE ) ){
655
+	public static function add_column_if_it_doesnt_exist($table_name, $column_name, $column_info = 'INT UNSIGNED NOT NULL') {
656
+		if (apply_filters('FHEE__EEH_Activation__add_column_if_it_doesnt_exist__short_circuit', FALSE)) {
657 657
 			return FALSE;
658 658
 		}
659 659
 		global $wpdb;
660
-		$full_table_name= EEH_Activation::ensure_table_name_has_prefix( $table_name );
660
+		$full_table_name = EEH_Activation::ensure_table_name_has_prefix($table_name);
661 661
 		$fields = self::get_fields_on_table($table_name);
662
-		if (!in_array($column_name, $fields)){
663
-			$alter_query="ALTER TABLE $full_table_name ADD $column_name $column_info";
662
+		if ( ! in_array($column_name, $fields)) {
663
+			$alter_query = "ALTER TABLE $full_table_name ADD $column_name $column_info";
664 664
 			//echo "alter query:$alter_query";
665 665
 			return $wpdb->query($alter_query);
666 666
 		}
@@ -679,15 +679,15 @@  discard block
 block discarded – undo
679 679
 	 * 	@param string $table_name, without prefixed $wpdb->prefix
680 680
 	 * 	@return array of database column names
681 681
 	 */
682
-	public static function get_fields_on_table( $table_name = NULL ) {
682
+	public static function get_fields_on_table($table_name = NULL) {
683 683
 		global $wpdb;
684
-		$table_name= EEH_Activation::ensure_table_name_has_prefix( $table_name );
685
-		if ( ! empty( $table_name )) {
684
+		$table_name = EEH_Activation::ensure_table_name_has_prefix($table_name);
685
+		if ( ! empty($table_name)) {
686 686
 			$columns = $wpdb->get_results("SHOW COLUMNS FROM $table_name ");
687 687
 			if ($columns !== FALSE) {
688 688
 				$field_array = array();
689
-				foreach($columns as $column ){
690
-					$field_array[] = $column->Field;;
689
+				foreach ($columns as $column) {
690
+					$field_array[] = $column->Field; ;
691 691
 				}
692 692
 				return $field_array;
693 693
 			}
@@ -705,12 +705,12 @@  discard block
 block discarded – undo
705 705
 	 * @param string $table_name
706 706
 	 * @return bool
707 707
 	 */
708
-	public static function db_table_is_empty( $table_name ) {
708
+	public static function db_table_is_empty($table_name) {
709 709
 		global $wpdb;
710
-		$table_name = EEH_Activation::ensure_table_name_has_prefix( $table_name );
711
-		if ( EEH_Activation::table_exists( $table_name ) ) {
712
-			$count = $wpdb->get_var( "SELECT COUNT(*) FROM $table_name" );
713
-			return absint( $count ) === 0 ? true : false;
710
+		$table_name = EEH_Activation::ensure_table_name_has_prefix($table_name);
711
+		if (EEH_Activation::table_exists($table_name)) {
712
+			$count = $wpdb->get_var("SELECT COUNT(*) FROM $table_name");
713
+			return absint($count) === 0 ? true : false;
714 714
 		}
715 715
 		return false;
716 716
 	}
@@ -725,9 +725,9 @@  discard block
 block discarded – undo
725 725
 	 * @param string $table_name
726 726
 	 * @return bool | int
727 727
 	 */
728
-	public static function delete_db_table_if_empty( $table_name ) {
729
-		if ( EEH_Activation::db_table_is_empty( $table_name ) ) {
730
-			return EEH_Activation::delete_unused_db_table( $table_name );
728
+	public static function delete_db_table_if_empty($table_name) {
729
+		if (EEH_Activation::db_table_is_empty($table_name)) {
730
+			return EEH_Activation::delete_unused_db_table($table_name);
731 731
 		}
732 732
 		return false;
733 733
 	}
@@ -742,11 +742,11 @@  discard block
 block discarded – undo
742 742
 	 * @param string $table_name
743 743
 	 * @return bool | int
744 744
 	 */
745
-	public static function delete_unused_db_table( $table_name ) {
745
+	public static function delete_unused_db_table($table_name) {
746 746
 		global $wpdb;
747
-		if ( EEH_Activation::table_exists( $table_name ) ) {
748
-			$table_name = EEH_Activation::ensure_table_name_has_prefix( $table_name );
749
-			return $wpdb->query( "DROP TABLE IF EXISTS $table_name" );
747
+		if (EEH_Activation::table_exists($table_name)) {
748
+			$table_name = EEH_Activation::ensure_table_name_has_prefix($table_name);
749
+			return $wpdb->query("DROP TABLE IF EXISTS $table_name");
750 750
 		}
751 751
 		return false;
752 752
 	}
@@ -762,18 +762,18 @@  discard block
 block discarded – undo
762 762
 	 * @param string $index_name
763 763
 	 * @return bool | int
764 764
 	 */
765
-	public static function drop_index( $table_name, $index_name ) {
766
-		if( apply_filters( 'FHEE__EEH_Activation__drop_index__short_circuit', FALSE ) ){
765
+	public static function drop_index($table_name, $index_name) {
766
+		if (apply_filters('FHEE__EEH_Activation__drop_index__short_circuit', FALSE)) {
767 767
 			return FALSE;
768 768
 		}
769 769
 		global $wpdb;
770
-		$table_name = EEH_Activation::ensure_table_name_has_prefix( $table_name );
770
+		$table_name = EEH_Activation::ensure_table_name_has_prefix($table_name);
771 771
 		$index_exists_query = "SHOW INDEX FROM $table_name WHERE Key_name = '$index_name'";
772 772
 		if (
773
-			$wpdb->get_var( "SHOW TABLES LIKE '$table_name'" ) == $table_name
774
-			&& $wpdb->get_var( $index_exists_query ) == $table_name //using get_var with the $index_exists_query returns the table's name
773
+			$wpdb->get_var("SHOW TABLES LIKE '$table_name'") == $table_name
774
+			&& $wpdb->get_var($index_exists_query) == $table_name //using get_var with the $index_exists_query returns the table's name
775 775
 		) {
776
-			return $wpdb->query( "ALTER TABLE $table_name DROP INDEX $index_name" );
776
+			return $wpdb->query("ALTER TABLE $table_name DROP INDEX $index_name");
777 777
 		}
778 778
 		return TRUE;
779 779
 	}
@@ -789,27 +789,27 @@  discard block
 block discarded – undo
789 789
 	 * @return boolean success (whether database is setup properly or not)
790 790
 	 */
791 791
 	public static function create_database_tables() {
792
-		EE_Registry::instance()->load_core( 'Data_Migration_Manager' );
792
+		EE_Registry::instance()->load_core('Data_Migration_Manager');
793 793
 		//find the migration script that sets the database to be compatible with the code
794 794
 		$dms_name = EE_Data_Migration_Manager::instance()->get_most_up_to_date_dms();
795
-		if( $dms_name ){
796
-			$current_data_migration_script = EE_Registry::instance()->load_dms( $dms_name );
797
-			$current_data_migration_script->set_migrating( false );
795
+		if ($dms_name) {
796
+			$current_data_migration_script = EE_Registry::instance()->load_dms($dms_name);
797
+			$current_data_migration_script->set_migrating(false);
798 798
 			$current_data_migration_script->schema_changes_before_migration();
799 799
 			$current_data_migration_script->schema_changes_after_migration();
800
-			if( $current_data_migration_script->get_errors() ){
801
-				if( WP_DEBUG ){
802
-					foreach( $current_data_migration_script->get_errors() as $error ){
803
-						EE_Error::add_error($error, __FILE__, __FUNCTION__, __LINE__ );
800
+			if ($current_data_migration_script->get_errors()) {
801
+				if (WP_DEBUG) {
802
+					foreach ($current_data_migration_script->get_errors() as $error) {
803
+						EE_Error::add_error($error, __FILE__, __FUNCTION__, __LINE__);
804 804
 					}
805
-				}else{
806
-					EE_Error::add_error( __( 'There were errors creating the Event Espresso database tables and Event Espresso has been deactivated. To view the errors, please enable WP_DEBUG in your wp-config.php file.', 'event_espresso' ) );
805
+				} else {
806
+					EE_Error::add_error(__('There were errors creating the Event Espresso database tables and Event Espresso has been deactivated. To view the errors, please enable WP_DEBUG in your wp-config.php file.', 'event_espresso'));
807 807
 				}
808 808
 				return false;
809 809
 			}
810 810
 			EE_Data_Migration_Manager::instance()->update_current_database_state_to();
811
-		}else{
812
-			EE_Error::add_error( __( 'Could not determine most up-to-date data migration script from which to pull database schema structure. So database is probably not setup properly', 'event_espresso' ), __FILE__, __FUNCTION__, __LINE__);
811
+		} else {
812
+			EE_Error::add_error(__('Could not determine most up-to-date data migration script from which to pull database schema structure. So database is probably not setup properly', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__);
813 813
 			return false;
814 814
 		}
815 815
 		return true;
@@ -829,27 +829,27 @@  discard block
 block discarded – undo
829 829
 	public static function initialize_system_questions() {
830 830
 		// QUESTION GROUPS
831 831
 		global $wpdb;
832
-		$table_name = EEH_Activation::ensure_table_name_has_prefix( 'esp_question_group' );
832
+		$table_name = EEH_Activation::ensure_table_name_has_prefix('esp_question_group');
833 833
 		$SQL = "SELECT QSG_system FROM $table_name WHERE QSG_system != 0";
834 834
 		// what we have
835
-		$question_groups = $wpdb->get_col( $SQL );
835
+		$question_groups = $wpdb->get_col($SQL);
836 836
 		// check the response
837
-		$question_groups = is_array( $question_groups ) ? $question_groups : array();
837
+		$question_groups = is_array($question_groups) ? $question_groups : array();
838 838
 		// what we should have
839
-		$QSG_systems = array( 1, 2 );
839
+		$QSG_systems = array(1, 2);
840 840
 		// loop thru what we should have and compare to what we have
841
-		foreach ( $QSG_systems as $QSG_system ) {
841
+		foreach ($QSG_systems as $QSG_system) {
842 842
 			// reset values array
843 843
 			$QSG_values = array();
844 844
 			// if we don't have what we should have (but use $QST_system as as string because that's what we got from the db)
845
-			if ( ! in_array( "$QSG_system", $question_groups )) {
845
+			if ( ! in_array("$QSG_system", $question_groups)) {
846 846
 				// add it
847
-				switch ( $QSG_system ) {
847
+				switch ($QSG_system) {
848 848
 
849 849
 					case 1:
850 850
 							$QSG_values = array(
851
-									'QSG_name' => __( 'Personal Information', 'event_espresso' ),
852
-									'QSG_identifier' => 'personal-information-' . time(),
851
+									'QSG_name' => __('Personal Information', 'event_espresso'),
852
+									'QSG_identifier' => 'personal-information-'.time(),
853 853
 									'QSG_desc' => '',
854 854
 									'QSG_order' => 1,
855 855
 									'QSG_show_group_name' => 1,
@@ -861,8 +861,8 @@  discard block
 block discarded – undo
861 861
 
862 862
 					case 2:
863 863
 							$QSG_values = array(
864
-									'QSG_name' => __( 'Address Information','event_espresso' ),
865
-									'QSG_identifier' => 'address-information-' . time(),
864
+									'QSG_name' => __('Address Information', 'event_espresso'),
865
+									'QSG_identifier' => 'address-information-'.time(),
866 866
 									'QSG_desc' => '',
867 867
 									'QSG_order' => 2,
868 868
 									'QSG_show_group_name' => 1,
@@ -874,14 +874,14 @@  discard block
 block discarded – undo
874 874
 
875 875
 				}
876 876
 				// make sure we have some values before inserting them
877
-				if ( ! empty( $QSG_values )) {
877
+				if ( ! empty($QSG_values)) {
878 878
 					// insert system question
879 879
 					$wpdb->insert(
880 880
 						$table_name,
881 881
 						$QSG_values,
882
-						array('%s', '%s', '%s', '%d', '%d', '%d', '%d', '%d' )
882
+						array('%s', '%s', '%s', '%d', '%d', '%d', '%d', '%d')
883 883
 					);
884
-					$QSG_IDs[ $QSG_system ] = $wpdb->insert_id;
884
+					$QSG_IDs[$QSG_system] = $wpdb->insert_id;
885 885
 				}
886 886
 			}
887 887
 		}
@@ -890,10 +890,10 @@  discard block
 block discarded – undo
890 890
 
891 891
 		// QUESTIONS
892 892
 		global $wpdb;
893
-		$table_name = EEH_Activation::ensure_table_name_has_prefix( 'esp_question' );
893
+		$table_name = EEH_Activation::ensure_table_name_has_prefix('esp_question');
894 894
 		$SQL = "SELECT QST_system FROM $table_name WHERE QST_system != ''";
895 895
 		// what we have
896
-		$questions = $wpdb->get_col( $SQL );
896
+		$questions = $wpdb->get_col($SQL);
897 897
 		// what we should have
898 898
 		$QST_systems = array(
899 899
 			'fname',
@@ -910,25 +910,25 @@  discard block
 block discarded – undo
910 910
 		$order_for_group_1 = 1;
911 911
 		$order_for_group_2 = 1;
912 912
 		// loop thru what we should have and compare to what we have
913
-		foreach ( $QST_systems as $QST_system ) {
913
+		foreach ($QST_systems as $QST_system) {
914 914
 			// reset values array
915 915
 			$QST_values = array();
916 916
 			// if we don't have what we should have
917
-			if ( ! in_array( $QST_system, $questions )) {
917
+			if ( ! in_array($QST_system, $questions)) {
918 918
 				// add it
919
-				switch ( $QST_system ) {
919
+				switch ($QST_system) {
920 920
 
921 921
 					case 'fname':
922 922
 							$QST_values = array(
923
-									'QST_display_text' => __( 'First Name', 'event_espresso' ),
924
-									'QST_admin_label' => __( 'First Name - System Question', 'event_espresso' ),
923
+									'QST_display_text' => __('First Name', 'event_espresso'),
924
+									'QST_admin_label' => __('First Name - System Question', 'event_espresso'),
925 925
 									'QST_system' => 'fname',
926 926
 									'QST_type' => 'TEXT',
927 927
 									'QST_required' => 1,
928
-									'QST_required_text' => __( 'This field is required', 'event_espresso' ),
928
+									'QST_required_text' => __('This field is required', 'event_espresso'),
929 929
 									'QST_order' => 1,
930 930
 									'QST_admin_only' => 0,
931
-									'QST_max' => EEM_Question::instance()->absolute_max_for_system_question( $QST_system ),
931
+									'QST_max' => EEM_Question::instance()->absolute_max_for_system_question($QST_system),
932 932
 									'QST_wp_user' => self::get_default_creator_id(),
933 933
 									'QST_deleted' => 0
934 934
 								);
@@ -936,15 +936,15 @@  discard block
 block discarded – undo
936 936
 
937 937
 					case 'lname':
938 938
 							$QST_values = array(
939
-									'QST_display_text' => __( 'Last Name', 'event_espresso' ),
940
-									'QST_admin_label' => __( 'Last Name - System Question', 'event_espresso' ),
939
+									'QST_display_text' => __('Last Name', 'event_espresso'),
940
+									'QST_admin_label' => __('Last Name - System Question', 'event_espresso'),
941 941
 									'QST_system' => 'lname',
942 942
 									'QST_type' => 'TEXT',
943 943
 									'QST_required' => 1,
944
-									'QST_required_text' => __( 'This field is required', 'event_espresso' ),
944
+									'QST_required_text' => __('This field is required', 'event_espresso'),
945 945
 									'QST_order' => 2,
946 946
 									'QST_admin_only' => 0,
947
-									'QST_max' => EEM_Question::instance()->absolute_max_for_system_question( $QST_system ),
947
+									'QST_max' => EEM_Question::instance()->absolute_max_for_system_question($QST_system),
948 948
 									'QST_wp_user' => self::get_default_creator_id(),
949 949
 									'QST_deleted' => 0
950 950
 								);
@@ -952,15 +952,15 @@  discard block
 block discarded – undo
952 952
 
953 953
 					case 'email':
954 954
 							$QST_values = array(
955
-									'QST_display_text' => __( 'Email Address', 'event_espresso' ),
956
-									'QST_admin_label' => __( 'Email Address - System Question', 'event_espresso' ),
955
+									'QST_display_text' => __('Email Address', 'event_espresso'),
956
+									'QST_admin_label' => __('Email Address - System Question', 'event_espresso'),
957 957
 									'QST_system' => 'email',
958 958
 									'QST_type' => 'TEXT',
959 959
 									'QST_required' => 1,
960
-									'QST_required_text' => __( 'This field is required', 'event_espresso' ),
960
+									'QST_required_text' => __('This field is required', 'event_espresso'),
961 961
 									'QST_order' => 3,
962 962
 									'QST_admin_only' => 0,
963
-									'QST_max' => EEM_Question::instance()->absolute_max_for_system_question( $QST_system ),
963
+									'QST_max' => EEM_Question::instance()->absolute_max_for_system_question($QST_system),
964 964
 									'QST_wp_user' => self::get_default_creator_id(),
965 965
 									'QST_deleted' => 0
966 966
 								);
@@ -968,15 +968,15 @@  discard block
 block discarded – undo
968 968
 
969 969
 					case 'address':
970 970
 							$QST_values = array(
971
-									'QST_display_text' => __( 'Address', 'event_espresso' ),
972
-									'QST_admin_label' => __( 'Address - System Question', 'event_espresso' ),
971
+									'QST_display_text' => __('Address', 'event_espresso'),
972
+									'QST_admin_label' => __('Address - System Question', 'event_espresso'),
973 973
 									'QST_system' => 'address',
974 974
 									'QST_type' => 'TEXT',
975 975
 									'QST_required' => 0,
976
-									'QST_required_text' => __( 'This field is required', 'event_espresso' ),
976
+									'QST_required_text' => __('This field is required', 'event_espresso'),
977 977
 									'QST_order' => 4,
978 978
 									'QST_admin_only' => 0,
979
-									'QST_max' => EEM_Question::instance()->absolute_max_for_system_question( $QST_system ),
979
+									'QST_max' => EEM_Question::instance()->absolute_max_for_system_question($QST_system),
980 980
 									'QST_wp_user' => self::get_default_creator_id(),
981 981
 									'QST_deleted' => 0
982 982
 								);
@@ -984,15 +984,15 @@  discard block
 block discarded – undo
984 984
 
985 985
 					case 'address2':
986 986
 							$QST_values = array(
987
-									'QST_display_text' => __( 'Address2', 'event_espresso' ),
988
-									'QST_admin_label' => __( 'Address2 - System Question', 'event_espresso' ),
987
+									'QST_display_text' => __('Address2', 'event_espresso'),
988
+									'QST_admin_label' => __('Address2 - System Question', 'event_espresso'),
989 989
 									'QST_system' => 'address2',
990 990
 									'QST_type' => 'TEXT',
991 991
 									'QST_required' => 0,
992
-									'QST_required_text' => __( 'This field is required', 'event_espresso' ),
992
+									'QST_required_text' => __('This field is required', 'event_espresso'),
993 993
 									'QST_order' => 5,
994 994
 									'QST_admin_only' => 0,
995
-									'QST_max' => EEM_Question::instance()->absolute_max_for_system_question( $QST_system ),
995
+									'QST_max' => EEM_Question::instance()->absolute_max_for_system_question($QST_system),
996 996
 									'QST_wp_user' => self::get_default_creator_id(),
997 997
 									'QST_deleted' => 0
998 998
 								);
@@ -1000,15 +1000,15 @@  discard block
 block discarded – undo
1000 1000
 
1001 1001
 					case 'city':
1002 1002
 							$QST_values = array(
1003
-									'QST_display_text' => __( 'City', 'event_espresso' ),
1004
-									'QST_admin_label' => __( 'City - System Question', 'event_espresso' ),
1003
+									'QST_display_text' => __('City', 'event_espresso'),
1004
+									'QST_admin_label' => __('City - System Question', 'event_espresso'),
1005 1005
 									'QST_system' => 'city',
1006 1006
 									'QST_type' => 'TEXT',
1007 1007
 									'QST_required' => 0,
1008
-									'QST_required_text' => __( 'This field is required', 'event_espresso' ),
1008
+									'QST_required_text' => __('This field is required', 'event_espresso'),
1009 1009
 									'QST_order' => 6,
1010 1010
 									'QST_admin_only' => 0,
1011
-									'QST_max' => EEM_Question::instance()->absolute_max_for_system_question( $QST_system ),
1011
+									'QST_max' => EEM_Question::instance()->absolute_max_for_system_question($QST_system),
1012 1012
 									'QST_wp_user' => self::get_default_creator_id(),
1013 1013
 									'QST_deleted' => 0
1014 1014
 								);
@@ -1016,12 +1016,12 @@  discard block
 block discarded – undo
1016 1016
 
1017 1017
 					case 'state':
1018 1018
 							$QST_values = array(
1019
-									'QST_display_text' => __( 'State/Province', 'event_espresso' ),
1020
-									'QST_admin_label' => __( 'State/Province - System Question', 'event_espresso' ),
1019
+									'QST_display_text' => __('State/Province', 'event_espresso'),
1020
+									'QST_admin_label' => __('State/Province - System Question', 'event_espresso'),
1021 1021
 									'QST_system' => 'state',
1022 1022
 									'QST_type' => 'STATE',
1023 1023
 									'QST_required' => 0,
1024
-									'QST_required_text' => __( 'This field is required', 'event_espresso' ),
1024
+									'QST_required_text' => __('This field is required', 'event_espresso'),
1025 1025
 									'QST_order' => 7,
1026 1026
 									'QST_admin_only' => 0,
1027 1027
 									'QST_wp_user' => self::get_default_creator_id(),
@@ -1031,12 +1031,12 @@  discard block
 block discarded – undo
1031 1031
 
1032 1032
 					case 'country' :
1033 1033
 							$QST_values = array(
1034
-									'QST_display_text' => __( 'Country', 'event_espresso' ),
1035
-									'QST_admin_label' => __( 'Country - System Question', 'event_espresso' ),
1034
+									'QST_display_text' => __('Country', 'event_espresso'),
1035
+									'QST_admin_label' => __('Country - System Question', 'event_espresso'),
1036 1036
 									'QST_system' => 'country',
1037 1037
 									'QST_type' => 'COUNTRY',
1038 1038
 									'QST_required' => 0,
1039
-									'QST_required_text' => __( 'This field is required', 'event_espresso' ),
1039
+									'QST_required_text' => __('This field is required', 'event_espresso'),
1040 1040
 									'QST_order' => 8,
1041 1041
 									'QST_admin_only' => 0,
1042 1042
 									'QST_wp_user' => self::get_default_creator_id(),
@@ -1046,15 +1046,15 @@  discard block
 block discarded – undo
1046 1046
 
1047 1047
 					case 'zip':
1048 1048
 							$QST_values = array(
1049
-									'QST_display_text' => __( 'Zip/Postal Code', 'event_espresso' ),
1050
-									'QST_admin_label' => __( 'Zip/Postal Code - System Question', 'event_espresso' ),
1049
+									'QST_display_text' => __('Zip/Postal Code', 'event_espresso'),
1050
+									'QST_admin_label' => __('Zip/Postal Code - System Question', 'event_espresso'),
1051 1051
 									'QST_system' => 'zip',
1052 1052
 									'QST_type' => 'TEXT',
1053 1053
 									'QST_required' => 0,
1054
-									'QST_required_text' => __( 'This field is required', 'event_espresso' ),
1054
+									'QST_required_text' => __('This field is required', 'event_espresso'),
1055 1055
 									'QST_order' => 9,
1056 1056
 									'QST_admin_only' => 0,
1057
-									'QST_max' => EEM_Question::instance()->absolute_max_for_system_question( $QST_system ),
1057
+									'QST_max' => EEM_Question::instance()->absolute_max_for_system_question($QST_system),
1058 1058
 									'QST_wp_user' => self::get_default_creator_id(),
1059 1059
 									'QST_deleted' => 0
1060 1060
 								);
@@ -1062,49 +1062,49 @@  discard block
 block discarded – undo
1062 1062
 
1063 1063
 					case 'phone':
1064 1064
 							$QST_values = array(
1065
-									'QST_display_text' => __( 'Phone Number', 'event_espresso' ),
1066
-									'QST_admin_label' => __( 'Phone Number - System Question', 'event_espresso' ),
1065
+									'QST_display_text' => __('Phone Number', 'event_espresso'),
1066
+									'QST_admin_label' => __('Phone Number - System Question', 'event_espresso'),
1067 1067
 									'QST_system' => 'phone',
1068 1068
 									'QST_type' => 'TEXT',
1069 1069
 									'QST_required' => 0,
1070
-									'QST_required_text' => __( 'This field is required', 'event_espresso' ),
1070
+									'QST_required_text' => __('This field is required', 'event_espresso'),
1071 1071
 									'QST_order' => 10,
1072 1072
 									'QST_admin_only' => 0,
1073
-									'QST_max' => EEM_Question::instance()->absolute_max_for_system_question( $QST_system ),
1073
+									'QST_max' => EEM_Question::instance()->absolute_max_for_system_question($QST_system),
1074 1074
 									'QST_wp_user' => self::get_default_creator_id(),
1075 1075
 									'QST_deleted' => 0
1076 1076
 								);
1077 1077
 						break;
1078 1078
 
1079 1079
 				}
1080
-				if ( ! empty( $QST_values )) {
1080
+				if ( ! empty($QST_values)) {
1081 1081
 					// insert system question
1082 1082
 					$wpdb->insert(
1083 1083
 						$table_name,
1084 1084
 						$QST_values,
1085
-						array( '%s', '%s', '%s', '%s', '%d', '%s', '%d', '%d', '%d', '%d' )
1085
+						array('%s', '%s', '%s', '%s', '%d', '%s', '%d', '%d', '%d', '%d')
1086 1086
 					);
1087 1087
 					$QST_ID = $wpdb->insert_id;
1088 1088
 
1089 1089
 					// QUESTION GROUP QUESTIONS
1090
-					if(  in_array( $QST_system, array( 'fname', 'lname', 'email' ) ) ) {
1090
+					if (in_array($QST_system, array('fname', 'lname', 'email'))) {
1091 1091
 						$system_question_we_want = EEM_Question_Group::system_personal;
1092 1092
 					} else {
1093 1093
 						$system_question_we_want = EEM_Question_Group::system_address;
1094 1094
 					}
1095
-					if( isset( $QSG_IDs[ $system_question_we_want ] ) ) {
1096
-						$QSG_ID = $QSG_IDs[ $system_question_we_want ];
1095
+					if (isset($QSG_IDs[$system_question_we_want])) {
1096
+						$QSG_ID = $QSG_IDs[$system_question_we_want];
1097 1097
 					} else {
1098
-						$id_col = EEM_Question_Group::instance()->get_col( array( array( 'QSG_system' => $system_question_we_want ) ) );
1099
-						if( is_array( $id_col ) ) {
1100
-							$QSG_ID = reset( $id_col );
1098
+						$id_col = EEM_Question_Group::instance()->get_col(array(array('QSG_system' => $system_question_we_want)));
1099
+						if (is_array($id_col)) {
1100
+							$QSG_ID = reset($id_col);
1101 1101
 						} else {
1102 1102
 							//ok so we didn't find it in the db either?? that's weird because we should have inserted it at the start of this method
1103 1103
                                                         EE_Log::instance()->log( 
1104 1104
                                                                 __FILE__, 
1105 1105
                                                                 __FUNCTION__, 
1106 1106
                                                                 sprintf( 
1107
-                                                                        __( 'Could not associate question %1$s to a question group because no system question group existed', 'event_espresso'), 
1107
+                                                                        __('Could not associate question %1$s to a question group because no system question group existed', 'event_espresso'), 
1108 1108
                                                                         $QST_ID ), 
1109 1109
                                                                 'error' );
1110 1110
                                                         continue;
@@ -1113,9 +1113,9 @@  discard block
 block discarded – undo
1113 1113
                                         
1114 1114
 					// add system questions to groups
1115 1115
 					$wpdb->insert(
1116
-						EEH_Activation::ensure_table_name_has_prefix( 'esp_question_group_question' ),
1117
-						array( 'QSG_ID' => $QSG_ID , 'QST_ID' => $QST_ID, 'QGQ_order'=>($QSG_ID==1)? $order_for_group_1++ : $order_for_group_2++ ),
1118
-						array( '%d', '%d','%d' )
1116
+						EEH_Activation::ensure_table_name_has_prefix('esp_question_group_question'),
1117
+						array('QSG_ID' => $QSG_ID, 'QST_ID' => $QST_ID, 'QGQ_order'=>($QSG_ID == 1) ? $order_for_group_1++ : $order_for_group_2++),
1118
+						array('%d', '%d', '%d')
1119 1119
 					);
1120 1120
 				}
1121 1121
 			}
@@ -1127,11 +1127,11 @@  discard block
 block discarded – undo
1127 1127
 	 * Makes sure the default payment method (Invoice) is active.
1128 1128
 	 * This used to be done automatically as part of constructing the old gateways config
1129 1129
 	 */
1130
-	public static function insert_default_payment_methods(){
1131
-		if( ! EEM_Payment_Method::instance()->count_active( EEM_Payment_Method::scope_cart ) ){
1132
-			EE_Registry::instance()->load_lib( 'Payment_Method_Manager' );
1133
-			EE_Payment_Method_Manager::instance()->activate_a_payment_method_of_type( 'Invoice' );
1134
-		}else{
1130
+	public static function insert_default_payment_methods() {
1131
+		if ( ! EEM_Payment_Method::instance()->count_active(EEM_Payment_Method::scope_cart)) {
1132
+			EE_Registry::instance()->load_lib('Payment_Method_Manager');
1133
+			EE_Payment_Method_Manager::instance()->activate_a_payment_method_of_type('Invoice');
1134
+		} else {
1135 1135
 			EEM_Payment_Method::instance()->verify_button_urls();
1136 1136
 		}
1137 1137
 	}
@@ -1147,7 +1147,7 @@  discard block
 block discarded – undo
1147 1147
 
1148 1148
 		global $wpdb;
1149 1149
 
1150
-		if ( EEH_Activation::table_exists( EEM_Status::instance()->table() ) ) {
1150
+		if (EEH_Activation::table_exists(EEM_Status::instance()->table())) {
1151 1151
 
1152 1152
 			$table_name = EEM_Status::instance()->table();
1153 1153
 
@@ -1213,38 +1213,38 @@  discard block
 block discarded – undo
1213 1213
 	 * 	@return boolean success of verifying upload directories exist
1214 1214
 	 */
1215 1215
 	public static function create_upload_directories() {
1216
-		EE_Registry::instance()->load_helper( 'File' );
1216
+		EE_Registry::instance()->load_helper('File');
1217 1217
 		// Create the required folders
1218 1218
 		$folders = array(
1219 1219
 				EVENT_ESPRESSO_TEMPLATE_DIR,
1220 1220
 				EVENT_ESPRESSO_GATEWAY_DIR,
1221
-				EVENT_ESPRESSO_UPLOAD_DIR . 'logs/',
1222
-				EVENT_ESPRESSO_UPLOAD_DIR . 'css/',
1223
-				EVENT_ESPRESSO_UPLOAD_DIR . 'tickets/'
1221
+				EVENT_ESPRESSO_UPLOAD_DIR.'logs/',
1222
+				EVENT_ESPRESSO_UPLOAD_DIR.'css/',
1223
+				EVENT_ESPRESSO_UPLOAD_DIR.'tickets/'
1224 1224
 		);
1225
-		foreach ( $folders as $folder ) {
1225
+		foreach ($folders as $folder) {
1226 1226
 			try {
1227
-				EEH_File::ensure_folder_exists_and_is_writable( $folder );
1228
-				@ chmod( $folder, 0755 );
1229
-			} catch( EE_Error $e ){
1227
+				EEH_File::ensure_folder_exists_and_is_writable($folder);
1228
+				@ chmod($folder, 0755);
1229
+			} catch (EE_Error $e) {
1230 1230
 				EE_Error::add_error(
1231 1231
 					sprintf(
1232
-						__(  'Could not create the folder at "%1$s" because: %2$s', 'event_espresso' ),
1232
+						__('Could not create the folder at "%1$s" because: %2$s', 'event_espresso'),
1233 1233
 						$folder,
1234
-						'<br />' . $e->getMessage()
1234
+						'<br />'.$e->getMessage()
1235 1235
 					),
1236 1236
 					__FILE__, __FUNCTION__, __LINE__
1237 1237
 				);
1238 1238
 				//indicate we'll need to fix this later
1239
-				update_option( EEH_Activation::upload_directories_incomplete_option_name, true );
1239
+				update_option(EEH_Activation::upload_directories_incomplete_option_name, true);
1240 1240
 				return FALSE;
1241 1241
 			}
1242 1242
 		}
1243 1243
 		//just add the .htaccess file to the logs directory to begin with. Even if logging
1244 1244
 		//is disabled, there might be activation errors recorded in there
1245
-		EEH_File::add_htaccess_deny_from_all( EVENT_ESPRESSO_UPLOAD_DIR . 'logs/' );
1245
+		EEH_File::add_htaccess_deny_from_all(EVENT_ESPRESSO_UPLOAD_DIR.'logs/');
1246 1246
 		//remember EE's folders are all good
1247
-		delete_option( EEH_Activation::upload_directories_incomplete_option_name );
1247
+		delete_option(EEH_Activation::upload_directories_incomplete_option_name);
1248 1248
 		return TRUE;
1249 1249
 	}
1250 1250
 	
@@ -1257,7 +1257,7 @@  discard block
 block discarded – undo
1257 1257
 	 * @return boolean
1258 1258
 	 */
1259 1259
 	public static function upload_directories_incomplete() {
1260
-		return get_option( EEH_Activation::upload_directories_incomplete_option_name, false );
1260
+		return get_option(EEH_Activation::upload_directories_incomplete_option_name, false);
1261 1261
 	}
1262 1262
 
1263 1263
 
@@ -1276,16 +1276,16 @@  discard block
 block discarded – undo
1276 1276
 		$installed_messengers = $default_messengers = array();
1277 1277
 
1278 1278
 		//include our helper
1279
-		EE_Registry::instance()->load_helper( 'MSG_Template' );
1279
+		EE_Registry::instance()->load_helper('MSG_Template');
1280 1280
 
1281 1281
 		//get all installed messenger objects
1282 1282
 		$installed = EEH_MSG_Template::get_installed_message_objects();
1283 1283
 
1284 1284
 		//let's setup the $installed messengers in an array AND the messengers that are set to be activated on install.
1285
-		foreach ( $installed['messengers'] as $msgr ) {
1286
-			if ( $msgr instanceof EE_messenger ) {
1285
+		foreach ($installed['messengers'] as $msgr) {
1286
+			if ($msgr instanceof EE_messenger) {
1287 1287
 				$installed_messengers[$msgr->name] = $msgr;
1288
-				if ( $msgr->activate_on_install ) {
1288
+				if ($msgr->activate_on_install) {
1289 1289
 					$default_messengers[] = $msgr->name;
1290 1290
 				}
1291 1291
 			}
@@ -1295,36 +1295,36 @@  discard block
 block discarded – undo
1295 1295
 		$active_messengers = EEH_MSG_Template::get_active_messengers_in_db();
1296 1296
 
1297 1297
 		//things that have already been activated before
1298
-		$has_activated = get_option( 'ee_has_activated_messenger' );
1298
+		$has_activated = get_option('ee_has_activated_messenger');
1299 1299
 
1300 1300
 		//do an initial loop to determine if we need to continue
1301 1301
 		$def_ms = array();
1302
-		foreach ( $default_messengers as $msgr ) {
1303
-			if ( isset($active_messengers[$msgr] ) || isset( $has_activated[$msgr] ) ) continue;
1302
+		foreach ($default_messengers as $msgr) {
1303
+			if (isset($active_messengers[$msgr]) || isset($has_activated[$msgr])) continue;
1304 1304
 			$def_ms[] = $msgr;
1305 1305
 		}
1306 1306
 
1307 1307
 		//setup the $installed_mts in an array
1308
-		foreach ( $installed['message_types'] as $imt ) {
1309
-			if ( $imt instanceof EE_message_type ) {
1308
+		foreach ($installed['message_types'] as $imt) {
1309
+			if ($imt instanceof EE_message_type) {
1310 1310
 				$installed_mts[$imt->name] = $imt;
1311 1311
 			}
1312 1312
 		}
1313 1313
 
1314 1314
 		//loop through default array for default messengers (if present)
1315
-		if ( ! empty( $def_ms ) ) {
1316
-			foreach ( $def_ms as $messenger ) {
1315
+		if ( ! empty($def_ms)) {
1316
+			foreach ($def_ms as $messenger) {
1317 1317
 				//all is good so let's setup the default stuff. We need to use the given messenger object (if exists) to get the default message type for the messenger.
1318
-				if ( ! isset( $installed_messengers[$messenger] )) {
1318
+				if ( ! isset($installed_messengers[$messenger])) {
1319 1319
 					continue;
1320 1320
 				}
1321 1321
 				/** @var EE_messenger[] $installed_messengers  */
1322 1322
 				$default_mts = $installed_messengers[$messenger]->get_default_message_types();
1323 1323
 				$active_messengers[$messenger]['obj'] = $installed_messengers[$messenger];
1324
-				foreach ( $default_mts as $index => $mt ) {
1324
+				foreach ($default_mts as $index => $mt) {
1325 1325
 					//is there an installed_mt matching the default string?  If not then nothing to do here.
1326
-					if ( ! isset( $installed_mts[$mt] ) ) {
1327
-						unset( $default_mts[$index] );
1326
+					if ( ! isset($installed_mts[$mt])) {
1327
+						unset($default_mts[$index]);
1328 1328
 						continue;
1329 1329
 					}
1330 1330
 
@@ -1333,41 +1333,41 @@  discard block
 block discarded – undo
1333 1333
 					/** @var EE_message_type[] $installed_mts */
1334 1334
 					$settings_fields = $installed_mts[$mt]->get_admin_settings_fields();
1335 1335
 					$settings = array();
1336
-					if ( is_array( $settings_fields ) ) {
1337
-						foreach ( $settings_fields as $field => $values ) {
1338
-							if ( isset( $values['default'] ) ) {
1336
+					if (is_array($settings_fields)) {
1337
+						foreach ($settings_fields as $field => $values) {
1338
+							if (isset($values['default'])) {
1339 1339
 								$settings[$field] = $values['default'];
1340 1340
 							}
1341 1341
 						}
1342 1342
 					}
1343 1343
 
1344
-					$active_messengers[$messenger]['settings'][$messenger . '-message_types'][$mt]['settings'] = $settings;
1344
+					$active_messengers[$messenger]['settings'][$messenger.'-message_types'][$mt]['settings'] = $settings;
1345 1345
 					$has_activated[$messenger][] = $mt;
1346 1346
 				}
1347 1347
 
1348 1348
 				//setup any initial settings for the messenger
1349 1349
 				$msgr_settings = $installed_messengers[$messenger]->get_admin_settings_fields();
1350 1350
 
1351
-				if ( !empty( $msgr_settings ) ) {
1352
-					foreach ( $msgr_settings as $field => $value ) {
1351
+				if ( ! empty($msgr_settings)) {
1352
+					foreach ($msgr_settings as $field => $value) {
1353 1353
 						$active_messengers[$messenger]['settings'][$field] = $value;
1354 1354
 					}
1355 1355
 				}
1356 1356
 
1357 1357
 				//now let's save the settings for this messenger! Must do now because the validator checks the db for active messengers to validate.
1358
-				EEH_MSG_Template::update_active_messengers_in_db( $active_messengers );
1358
+				EEH_MSG_Template::update_active_messengers_in_db($active_messengers);
1359 1359
 
1360 1360
 				//let's generate all the templates but only if the messenger has default_mts (otherwise its just activated).
1361
-				if ( !empty( $default_mts ) ) {
1362
-					$success = EEH_MSG_Template::generate_new_templates( $messenger, $default_mts, '', TRUE );
1361
+				if ( ! empty($default_mts)) {
1362
+					$success = EEH_MSG_Template::generate_new_templates($messenger, $default_mts, '', TRUE);
1363 1363
 				}
1364 1364
 			}
1365 1365
 		} //end check for empty( $def_ms )
1366 1366
 
1367 1367
 		//still need to see if there are any message types to activate for active messengers
1368
-		foreach ( $active_messengers as $messenger => $settings ) {
1368
+		foreach ($active_messengers as $messenger => $settings) {
1369 1369
 			$msg_obj = $settings['obj'];
1370
-			if ( ! $msg_obj instanceof EE_messenger ) {
1370
+			if ( ! $msg_obj instanceof EE_messenger) {
1371 1371
 				continue;
1372 1372
 			}
1373 1373
 
@@ -1375,45 +1375,45 @@  discard block
 block discarded – undo
1375 1375
 			$new_default_mts = array();
1376 1376
 
1377 1377
 			//loop through each default mt reported by the messenger and make sure its set in its active db entry.
1378
-			foreach( $all_default_mts as $index => $mt ) {
1378
+			foreach ($all_default_mts as $index => $mt) {
1379 1379
 				//already active? already has generated templates? || has already been activated before (we dont' want to reactivate things users intentionally deactivated).
1380
-				if ( ( isset( $has_activated[$messenger] ) && in_array($mt, $has_activated[$messenger]) ) || isset( $active_messengers[$messenger]['settings'][$messenger . '-message_types'][$mt] ) ||  EEH_MSG_Template::already_generated( $messenger, $mt, 0, FALSE ) ) {
1380
+				if ((isset($has_activated[$messenger]) && in_array($mt, $has_activated[$messenger])) || isset($active_messengers[$messenger]['settings'][$messenger.'-message_types'][$mt]) || EEH_MSG_Template::already_generated($messenger, $mt, 0, FALSE)) {
1381 1381
 					continue;
1382 1382
 				}
1383 1383
 
1384 1384
 				//is there an installed_mt matching the default string?  If not then nothing to do here.
1385
-				if ( ! isset( $installed_mts[$mt] ) ) {
1386
-					unset( $all_default_mts[$mt] );
1385
+				if ( ! isset($installed_mts[$mt])) {
1386
+					unset($all_default_mts[$mt]);
1387 1387
 					continue;
1388 1388
 				}
1389 1389
 
1390 1390
 				$settings_fields = $installed_mts[$mt]->get_admin_settings_fields();
1391 1391
 				$settings = array();
1392
-				if ( is_array( $settings_fields ) ) {
1393
-					foreach ( $settings_fields as $field => $values ) {
1394
-						if ( isset( $values['default'] ) ) {
1392
+				if (is_array($settings_fields)) {
1393
+					foreach ($settings_fields as $field => $values) {
1394
+						if (isset($values['default'])) {
1395 1395
 							$settings[$field] = $values['default'];
1396 1396
 						}
1397 1397
 					}
1398 1398
 				}
1399 1399
 
1400
-				$active_messengers[$messenger]['settings'][$messenger . '-message_types'][$mt]['settings'] = $settings;
1400
+				$active_messengers[$messenger]['settings'][$messenger.'-message_types'][$mt]['settings'] = $settings;
1401 1401
 				$new_default_mts[] = $mt;
1402 1402
 				$has_activated[$messenger][] = $mt;
1403 1403
 			}
1404 1404
 
1405 1405
 
1406
-			if ( ! empty( $new_default_mts ) ) {
1407
-				$success = EEH_MSG_Template::generate_new_templates( $messenger, $new_default_mts, '', TRUE );
1406
+			if ( ! empty($new_default_mts)) {
1407
+				$success = EEH_MSG_Template::generate_new_templates($messenger, $new_default_mts, '', TRUE);
1408 1408
 			}
1409 1409
 
1410 1410
 		}
1411 1411
 
1412 1412
 		//now let's save the settings for this messenger!
1413
-		EEH_MSG_Template::update_active_messengers_in_db( $active_messengers );
1413
+		EEH_MSG_Template::update_active_messengers_in_db($active_messengers);
1414 1414
 
1415 1415
 		//update $has_activated record
1416
-		update_option( 'ee_has_activated_messenger', $has_activated );
1416
+		update_option('ee_has_activated_messenger', $has_activated);
1417 1417
 
1418 1418
 		//that's it!
1419 1419
 		return $success;
@@ -1433,47 +1433,47 @@  discard block
 block discarded – undo
1433 1433
 	 */
1434 1434
 	public static function validate_messages_system() {
1435 1435
 		//include our helper
1436
-		EE_Registry::instance()->load_helper( 'MSG_Template' );
1436
+		EE_Registry::instance()->load_helper('MSG_Template');
1437 1437
 
1438 1438
 		//get active and installed  messengers/message types.
1439 1439
 		$active_messengers = EEH_MSG_Template::get_active_messengers_in_db();
1440 1440
 		$installed = EEH_MSG_Template::get_installed_message_objects();
1441 1441
 		$installed_messengers = $installed_mts = array();
1442 1442
 		//set up the arrays so they can be handled easier.
1443
-		foreach( $installed['messengers'] as $im ) {
1444
-			if ( $im instanceof EE_messenger ) {
1443
+		foreach ($installed['messengers'] as $im) {
1444
+			if ($im instanceof EE_messenger) {
1445 1445
 				$installed_messengers[$im->name] = $im;
1446 1446
 			}
1447 1447
 		}
1448
-		foreach( $installed['message_types'] as $imt ) {
1449
-			if ( $imt instanceof EE_message_type ) {
1448
+		foreach ($installed['message_types'] as $imt) {
1449
+			if ($imt instanceof EE_message_type) {
1450 1450
 				$installed_mts[$imt->name] = $imt;
1451 1451
 			}
1452 1452
 		}
1453 1453
 
1454 1454
 		//now let's loop through the active array and validate
1455
-		foreach( $active_messengers as $messenger => $active_details ) {
1455
+		foreach ($active_messengers as $messenger => $active_details) {
1456 1456
 			//first let's see if this messenger is installed.
1457
-			if ( ! isset( $installed_messengers[$messenger] ) ) {
1457
+			if ( ! isset($installed_messengers[$messenger])) {
1458 1458
 				//not set so let's just remove from actives and make sure templates are inactive.
1459
-				unset( $active_messengers[$messenger] );
1460
-				EEH_MSG_Template::update_to_inactive( $messenger );
1459
+				unset($active_messengers[$messenger]);
1460
+				EEH_MSG_Template::update_to_inactive($messenger);
1461 1461
 				continue;
1462 1462
 			}
1463 1463
 
1464 1464
 			//messenger is active, so let's just make sure that any active message types not installed are deactivated.
1465
-			$mts = ! empty( $active_details['settings'][$messenger . '-message_types'] ) ? $active_details['settings'][$messenger . '-message_types'] : array();
1466
-			foreach ( $mts as $mt_name => $mt ) {
1467
-				if ( ! isset( $installed_mts[$mt_name] )  ) {
1468
-					unset( $active_messengers[$messenger]['settings'][$messenger . '-message_types'][$mt_name] );
1469
-					EEH_MSG_Template::update_to_inactive( $messenger, $mt_name );
1465
+			$mts = ! empty($active_details['settings'][$messenger.'-message_types']) ? $active_details['settings'][$messenger.'-message_types'] : array();
1466
+			foreach ($mts as $mt_name => $mt) {
1467
+				if ( ! isset($installed_mts[$mt_name])) {
1468
+					unset($active_messengers[$messenger]['settings'][$messenger.'-message_types'][$mt_name]);
1469
+					EEH_MSG_Template::update_to_inactive($messenger, $mt_name);
1470 1470
 				}
1471 1471
 			}
1472 1472
 		}
1473 1473
 
1474 1474
 		//all done! let's update the active_messengers.
1475
-		EEH_MSG_Template::update_active_messengers_in_db( $active_messengers );
1476
-		do_action( 'AHEE__EEH_Activation__validate_messages_system' );
1475
+		EEH_MSG_Template::update_active_messengers_in_db($active_messengers);
1476
+		do_action('AHEE__EEH_Activation__validate_messages_system');
1477 1477
 		return;
1478 1478
 	}
1479 1479
 
@@ -1487,12 +1487,12 @@  discard block
 block discarded – undo
1487 1487
 	 * 	@static
1488 1488
 	 * 	@return void
1489 1489
 	 */
1490
-	public static function create_no_ticket_prices_array(){
1490
+	public static function create_no_ticket_prices_array() {
1491 1491
 		// this creates an array for tracking events that have no active ticket prices created
1492 1492
 		// this allows us to warn admins of the situation so that it can be corrected
1493
-		$espresso_no_ticket_prices = get_option( 'ee_no_ticket_prices', FALSE );
1494
-		if ( ! $espresso_no_ticket_prices ) {
1495
-			add_option( 'ee_no_ticket_prices', array(), '', FALSE );
1493
+		$espresso_no_ticket_prices = get_option('ee_no_ticket_prices', FALSE);
1494
+		if ( ! $espresso_no_ticket_prices) {
1495
+			add_option('ee_no_ticket_prices', array(), '', FALSE);
1496 1496
 		}
1497 1497
 	}
1498 1498
 
@@ -1514,24 +1514,24 @@  discard block
 block discarded – undo
1514 1514
 	 * Finds all our EE4 custom post types, and deletes them and their associated data (like post meta or term relations)/
1515 1515
 	 * @global wpdb $wpdb
1516 1516
 	 */
1517
-	public static function delete_all_espresso_cpt_data(){
1517
+	public static function delete_all_espresso_cpt_data() {
1518 1518
 		global $wpdb;
1519 1519
 		//get all the CPT post_types
1520 1520
 		$ee_post_types = array();
1521
-		foreach(EE_Registry::instance()->non_abstract_db_models as $model_name){
1522
-			if ( method_exists( $model_name, 'instance' )) {
1523
-				$model_obj = call_user_func( array( $model_name, 'instance' ));
1524
-				if ( $model_obj instanceof EEM_CPT_Base ) {
1525
-					$ee_post_types[] = $wpdb->prepare("%s",$model_obj->post_type());
1521
+		foreach (EE_Registry::instance()->non_abstract_db_models as $model_name) {
1522
+			if (method_exists($model_name, 'instance')) {
1523
+				$model_obj = call_user_func(array($model_name, 'instance'));
1524
+				if ($model_obj instanceof EEM_CPT_Base) {
1525
+					$ee_post_types[] = $wpdb->prepare("%s", $model_obj->post_type());
1526 1526
 				}
1527 1527
 			}
1528 1528
 		}
1529 1529
 		//get all our CPTs
1530
-		$query = "SELECT ID FROM {$wpdb->posts} WHERE post_type IN (".implode(",",$ee_post_types).")";
1530
+		$query = "SELECT ID FROM {$wpdb->posts} WHERE post_type IN (".implode(",", $ee_post_types).")";
1531 1531
 		$cpt_ids = $wpdb->get_col($query);
1532 1532
 		//delete each post meta and term relations too
1533
-		foreach($cpt_ids as $post_id){
1534
-			wp_delete_post($post_id,true);
1533
+		foreach ($cpt_ids as $post_id) {
1534
+			wp_delete_post($post_id, true);
1535 1535
 		}
1536 1536
 	}
1537 1537
 
@@ -1545,18 +1545,18 @@  discard block
 block discarded – undo
1545 1545
 	 * @param bool $remove_all
1546 1546
 	 * @return void
1547 1547
 	 */
1548
-	public static function delete_all_espresso_tables_and_data( $remove_all = true ) {
1548
+	public static function delete_all_espresso_tables_and_data($remove_all = true) {
1549 1549
 		global $wpdb;
1550 1550
 		$undeleted_tables = array();
1551 1551
 
1552 1552
 		// load registry
1553
-		foreach( EE_Registry::instance()->non_abstract_db_models as $model_name ){
1554
-			if ( method_exists( $model_name, 'instance' )) {
1555
-				$model_obj = call_user_func( array( $model_name, 'instance' ));
1556
-				if ( $model_obj instanceof EEM_Base ) {
1557
-					foreach ( $model_obj->get_tables() as $table ) {
1558
-						if ( strpos( $table->get_table_name(), 'esp_' )) {
1559
-							switch ( EEH_Activation::delete_unused_db_table( $table->get_table_name() )) {
1553
+		foreach (EE_Registry::instance()->non_abstract_db_models as $model_name) {
1554
+			if (method_exists($model_name, 'instance')) {
1555
+				$model_obj = call_user_func(array($model_name, 'instance'));
1556
+				if ($model_obj instanceof EEM_Base) {
1557
+					foreach ($model_obj->get_tables() as $table) {
1558
+						if (strpos($table->get_table_name(), 'esp_')) {
1559
+							switch (EEH_Activation::delete_unused_db_table($table->get_table_name())) {
1560 1560
 								case false :
1561 1561
 									$undeleted_tables[] = $table->get_table_name();
1562 1562
 								break;
@@ -1581,8 +1581,8 @@  discard block
 block discarded – undo
1581 1581
 			'esp_promotion_rule',
1582 1582
 			'esp_rule'
1583 1583
 		);
1584
-		foreach( $tables_without_models as $table ){
1585
-			EEH_Activation::delete_db_table_if_empty( $table );
1584
+		foreach ($tables_without_models as $table) {
1585
+			EEH_Activation::delete_db_table_if_empty($table);
1586 1586
 		}
1587 1587
 
1588 1588
 
@@ -1619,58 +1619,58 @@  discard block
 block discarded – undo
1619 1619
 			'ee_pers_admin_notices' => true,
1620 1620
 			'ee_upload_directories_incomplete' => true,
1621 1621
 		);
1622
-		if( is_main_site() ) {
1623
-			$wp_options_to_delete[ 'ee_network_config' ] = true;
1622
+		if (is_main_site()) {
1623
+			$wp_options_to_delete['ee_network_config'] = true;
1624 1624
 		}
1625 1625
 
1626 1626
 		$undeleted_options = array();
1627
-		foreach ( $wp_options_to_delete as $option_name => $no_wildcard ) {
1627
+		foreach ($wp_options_to_delete as $option_name => $no_wildcard) {
1628 1628
 
1629
-			if( $no_wildcard ){
1630
-				if( ! delete_option( $option_name ) ){
1629
+			if ($no_wildcard) {
1630
+				if ( ! delete_option($option_name)) {
1631 1631
 					$undeleted_options[] = $option_name;
1632 1632
 				}
1633
-			}else{
1634
-				$option_names_to_delete_from_wildcard = $wpdb->get_col( "SELECT option_name FROM $wpdb->options WHERE option_name LIKE '%$option_name%'" );
1635
-				foreach($option_names_to_delete_from_wildcard as $option_name_from_wildcard ){
1636
-					if( ! delete_option( $option_name_from_wildcard ) ){
1633
+			} else {
1634
+				$option_names_to_delete_from_wildcard = $wpdb->get_col("SELECT option_name FROM $wpdb->options WHERE option_name LIKE '%$option_name%'");
1635
+				foreach ($option_names_to_delete_from_wildcard as $option_name_from_wildcard) {
1636
+					if ( ! delete_option($option_name_from_wildcard)) {
1637 1637
 						$undeleted_options[] = $option_name_from_wildcard;
1638 1638
 					}
1639 1639
 				}
1640 1640
 			}
1641 1641
 		}
1642 1642
                 //also, let's make sure the "ee_config_option_names" wp option stays out by removing the action that adds it
1643
-                remove_action( 'shutdown', array( EE_Config::instance(), 'shutdown' ), 10 );
1643
+                remove_action('shutdown', array(EE_Config::instance(), 'shutdown'), 10);
1644 1644
 
1645
-		if ( $remove_all && $espresso_db_update = get_option( 'espresso_db_update' )) {
1645
+		if ($remove_all && $espresso_db_update = get_option('espresso_db_update')) {
1646 1646
 			$db_update_sans_ee4 = array();
1647
-			foreach($espresso_db_update as $version => $times_activated){
1648
-				if( $version[0] =='3'){//if its NON EE4
1647
+			foreach ($espresso_db_update as $version => $times_activated) {
1648
+				if ($version[0] == '3') {//if its NON EE4
1649 1649
 					$db_update_sans_ee4[$version] = $times_activated;
1650 1650
 				}
1651 1651
 			}
1652
-			update_option( 'espresso_db_update', $db_update_sans_ee4 );
1652
+			update_option('espresso_db_update', $db_update_sans_ee4);
1653 1653
 		}
1654 1654
 
1655 1655
 		$errors = '';
1656
-		if ( ! empty( $undeleted_tables )) {
1656
+		if ( ! empty($undeleted_tables)) {
1657 1657
 			$errors .= sprintf(
1658
-				__( 'The following tables could not be deleted: %s%s', 'event_espresso' ),
1658
+				__('The following tables could not be deleted: %s%s', 'event_espresso'),
1659 1659
 				'<br/>',
1660
-				implode( ',<br/>', $undeleted_tables )
1660
+				implode(',<br/>', $undeleted_tables)
1661 1661
 			);
1662 1662
 		}
1663
-		if ( ! empty( $undeleted_options )) {
1664
-			$errors .= ! empty( $undeleted_tables ) ? '<br/>' : '';
1663
+		if ( ! empty($undeleted_options)) {
1664
+			$errors .= ! empty($undeleted_tables) ? '<br/>' : '';
1665 1665
 			$errors .= sprintf(
1666
-				__( 'The following wp-options could not be deleted: %s%s', 'event_espresso' ),
1666
+				__('The following wp-options could not be deleted: %s%s', 'event_espresso'),
1667 1667
 				'<br/>',
1668
-				implode( ',<br/>', $undeleted_options )
1668
+				implode(',<br/>', $undeleted_options)
1669 1669
 			);
1670 1670
 
1671 1671
 		}
1672
-		if ( $errors != '' ) {
1673
-			EE_Error::add_attention( $errors, __FILE__, __FUNCTION__, __LINE__ );
1672
+		if ($errors != '') {
1673
+			EE_Error::add_attention($errors, __FILE__, __FUNCTION__, __LINE__);
1674 1674
 		}
1675 1675
 	}
1676 1676
 
@@ -1680,23 +1680,23 @@  discard block
 block discarded – undo
1680 1680
 	 * @param string $table_name with or without $wpdb->prefix
1681 1681
 	 * @return boolean
1682 1682
 	 */
1683
-	public static function table_exists( $table_name ){
1683
+	public static function table_exists($table_name) {
1684 1684
 		global $wpdb, $EZSQL_ERROR;
1685
-		$table_name = EEH_Activation::ensure_table_name_has_prefix( $table_name );
1685
+		$table_name = EEH_Activation::ensure_table_name_has_prefix($table_name);
1686 1686
 		//ignore if this causes an sql error
1687 1687
 		$old_error = $wpdb->last_error;
1688 1688
 		$old_suppress_errors = $wpdb->suppress_errors();
1689
-		$old_show_errors_value = $wpdb->show_errors( FALSE );
1689
+		$old_show_errors_value = $wpdb->show_errors(FALSE);
1690 1690
 		$ezsql_error_cache = $EZSQL_ERROR;
1691
-		$wpdb->get_results( "SELECT * from $table_name LIMIT 1");
1692
-		$wpdb->show_errors( $old_show_errors_value );
1693
-		$wpdb->suppress_errors( $old_suppress_errors );
1691
+		$wpdb->get_results("SELECT * from $table_name LIMIT 1");
1692
+		$wpdb->show_errors($old_show_errors_value);
1693
+		$wpdb->suppress_errors($old_suppress_errors);
1694 1694
 		$new_error = $wpdb->last_error;
1695 1695
 		$wpdb->last_error = $old_error;
1696 1696
 		$EZSQL_ERROR = $ezsql_error_cache;
1697
-		if( empty( $new_error ) ){
1697
+		if (empty($new_error)) {
1698 1698
 			return TRUE;
1699
-		}else{
1699
+		} else {
1700 1700
 			return FALSE;
1701 1701
 		}
1702 1702
 	}
@@ -1704,7 +1704,7 @@  discard block
 block discarded – undo
1704 1704
 	/**
1705 1705
 	 * Resets the cache on EEH_Activation
1706 1706
 	 */
1707
-	public static function reset(){
1707
+	public static function reset() {
1708 1708
 		self::$_default_creator_id = NULL;
1709 1709
 		self::$_initialized_db_content_already_in_this_request = false;
1710 1710
 	}
Please login to merge, or discard this patch.