Completed
Branch BUG-10015-set-curl-ssl-version (7bdf86)
by
unknown
30:31 queued 13:32
created
core/db_classes/EE_Line_Item.class.php 1 patch
Spacing   +215 added lines, -215 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
@@ -50,9 +50,9 @@  discard block
 block discarded – undo
50 50
 	 *                             		    date_format and the second value is the time format
51 51
 	 * @return EE_Line_Item
52 52
 	 */
53
-	public static function new_instance( $props_n_values = array(), $timezone = null, $date_formats = array() ) {
54
-		$has_object = parent::_check_for_object( $props_n_values, __CLASS__, $timezone, $date_formats );
55
-		return $has_object ? $has_object : new self( $props_n_values, false, $timezone, $date_formats );
53
+	public static function new_instance($props_n_values = array(), $timezone = null, $date_formats = array()) {
54
+		$has_object = parent::_check_for_object($props_n_values, __CLASS__, $timezone, $date_formats);
55
+		return $has_object ? $has_object : new self($props_n_values, false, $timezone, $date_formats);
56 56
 	}
57 57
 
58 58
 
@@ -63,8 +63,8 @@  discard block
 block discarded – undo
63 63
 	 *                          		the website will be used.
64 64
 	 * @return EE_Line_Item
65 65
 	 */
66
-	public static function new_instance_from_db( $props_n_values = array(), $timezone = null ) {
67
-		return new self( $props_n_values, TRUE, $timezone );
66
+	public static function new_instance_from_db($props_n_values = array(), $timezone = null) {
67
+		return new self($props_n_values, TRUE, $timezone);
68 68
 	}
69 69
 
70 70
 
@@ -75,10 +75,10 @@  discard block
 block discarded – undo
75 75
 	 * @param bool   $bydb
76 76
 	 * @param string $timezone
77 77
 	 */
78
-	protected function __construct( $fieldValues = array(), $bydb = FALSE, $timezone = '' ) {
79
-		parent::__construct( $fieldValues, $bydb, $timezone );
80
-		if ( ! $this->get( 'LIN_code' ) ) {
81
-			$this->set_code( $this->generate_code() );
78
+	protected function __construct($fieldValues = array(), $bydb = FALSE, $timezone = '') {
79
+		parent::__construct($fieldValues, $bydb, $timezone);
80
+		if ( ! $this->get('LIN_code')) {
81
+			$this->set_code($this->generate_code());
82 82
 		}
83 83
 	}
84 84
 
@@ -89,7 +89,7 @@  discard block
 block discarded – undo
89 89
 	 * @return int
90 90
 	 */
91 91
 	public function ID() {
92
-		return $this->get( 'LIN_ID' );
92
+		return $this->get('LIN_ID');
93 93
 	}
94 94
 
95 95
 
@@ -99,7 +99,7 @@  discard block
 block discarded – undo
99 99
 	 * @return int
100 100
 	 */
101 101
 	public function TXN_ID() {
102
-		return $this->get( 'TXN_ID' );
102
+		return $this->get('TXN_ID');
103 103
 	}
104 104
 
105 105
 
@@ -109,8 +109,8 @@  discard block
 block discarded – undo
109 109
 	 * @param int $TXN_ID
110 110
 	 * @return boolean
111 111
 	 */
112
-	public function set_TXN_ID( $TXN_ID ) {
113
-		$this->set( 'TXN_ID', $TXN_ID );
112
+	public function set_TXN_ID($TXN_ID) {
113
+		$this->set('TXN_ID', $TXN_ID);
114 114
 	}
115 115
 
116 116
 
@@ -120,9 +120,9 @@  discard block
 block discarded – undo
120 120
 	 * @return string
121 121
 	 */
122 122
 	public function name() {
123
-		$name =  $this->get( 'LIN_name' );
124
-		if( ! $name ){
125
-			$name = ucwords( str_replace( '-', ' ', $this->type() ) );
123
+		$name = $this->get('LIN_name');
124
+		if ( ! $name) {
125
+			$name = ucwords(str_replace('-', ' ', $this->type()));
126 126
 		}
127 127
 		return $name;
128 128
 	}
@@ -134,8 +134,8 @@  discard block
 block discarded – undo
134 134
 	 * @param string $name
135 135
 	 * @return boolean
136 136
 	 */
137
-	public function set_name( $name ) {
138
-		$this->set( 'LIN_name', $name );
137
+	public function set_name($name) {
138
+		$this->set('LIN_name', $name);
139 139
 	}
140 140
 
141 141
 
@@ -145,7 +145,7 @@  discard block
 block discarded – undo
145 145
 	 * @return string
146 146
 	 */
147 147
 	public function desc() {
148
-		return $this->get( 'LIN_desc' );
148
+		return $this->get('LIN_desc');
149 149
 	}
150 150
 
151 151
 
@@ -155,8 +155,8 @@  discard block
 block discarded – undo
155 155
 	 * @param string $desc
156 156
 	 * @return boolean
157 157
 	 */
158
-	public function set_desc( $desc ) {
159
-		$this->set( 'LIN_desc', $desc );
158
+	public function set_desc($desc) {
159
+		$this->set('LIN_desc', $desc);
160 160
 	}
161 161
 
162 162
 
@@ -166,7 +166,7 @@  discard block
 block discarded – undo
166 166
 	 * @return int
167 167
 	 */
168 168
 	public function quantity() {
169
-		return $this->get( 'LIN_quantity' );
169
+		return $this->get('LIN_quantity');
170 170
 	}
171 171
 
172 172
 
@@ -176,8 +176,8 @@  discard block
 block discarded – undo
176 176
 	 * @param int $quantity
177 177
 	 * @return boolean
178 178
 	 */
179
-	function set_quantity( $quantity ) {
180
-		$this->set( 'LIN_quantity', max( $quantity, 0 ) );
179
+	function set_quantity($quantity) {
180
+		$this->set('LIN_quantity', max($quantity, 0));
181 181
 	}
182 182
 
183 183
 
@@ -187,7 +187,7 @@  discard block
 block discarded – undo
187 187
 	 * @return string
188 188
 	 */
189 189
 	public function OBJ_ID() {
190
-		return $this->get( 'OBJ_ID' );
190
+		return $this->get('OBJ_ID');
191 191
 	}
192 192
 
193 193
 
@@ -197,8 +197,8 @@  discard block
 block discarded – undo
197 197
 	 * @param string $item_id
198 198
 	 * @return boolean
199 199
 	 */
200
-	public function set_OBJ_ID( $item_id ) {
201
-		$this->set( 'OBJ_ID', $item_id );
200
+	public function set_OBJ_ID($item_id) {
201
+		$this->set('OBJ_ID', $item_id);
202 202
 	}
203 203
 
204 204
 
@@ -208,7 +208,7 @@  discard block
 block discarded – undo
208 208
 	 * @return string
209 209
 	 */
210 210
 	public function OBJ_type() {
211
-		return $this->get( 'OBJ_type' );
211
+		return $this->get('OBJ_type');
212 212
 	}
213 213
 
214 214
 
@@ -246,8 +246,8 @@  discard block
 block discarded – undo
246 246
 	 * @param string $OBJ_type
247 247
 	 * @return boolean
248 248
 	 */
249
-	public function set_OBJ_type( $OBJ_type ) {
250
-		$this->set( 'OBJ_type', $OBJ_type );
249
+	public function set_OBJ_type($OBJ_type) {
250
+		$this->set('OBJ_type', $OBJ_type);
251 251
 	}
252 252
 
253 253
 
@@ -257,7 +257,7 @@  discard block
 block discarded – undo
257 257
 	 * @return float
258 258
 	 */
259 259
 	public function unit_price() {
260
-		return $this->get( 'LIN_unit_price' );
260
+		return $this->get('LIN_unit_price');
261 261
 	}
262 262
 
263 263
 
@@ -267,8 +267,8 @@  discard block
 block discarded – undo
267 267
 	 * @param float $unit_price
268 268
 	 * @return boolean
269 269
 	 */
270
-	public function set_unit_price( $unit_price ) {
271
-		$this->set( 'LIN_unit_price', $unit_price );
270
+	public function set_unit_price($unit_price) {
271
+		$this->set('LIN_unit_price', $unit_price);
272 272
 	}
273 273
 
274 274
 
@@ -279,19 +279,19 @@  discard block
 block discarded – undo
279 279
 	 * @return boolean
280 280
 	 */
281 281
 	public function is_percent() {
282
-		if( $this->is_tax_sub_total() ) {
282
+		if ($this->is_tax_sub_total()) {
283 283
 			//tax subtotals HAVE a percent on them, that percentage only applies
284 284
 			//to taxable items, so its' an exception. Treat it like a flat line item
285 285
 			return false;
286 286
 		}
287
-		$unit_price = abs( $this->get( 'LIN_unit_price' ) );
288
-		$percent = abs( $this->get( 'LIN_percent' ) );
289
-		if ( $unit_price < .001 && $percent ) {
287
+		$unit_price = abs($this->get('LIN_unit_price'));
288
+		$percent = abs($this->get('LIN_percent'));
289
+		if ($unit_price < .001 && $percent) {
290 290
 			return TRUE;
291
-		} elseif ( $unit_price >= .001 && !$percent ) {
291
+		} elseif ($unit_price >= .001 && ! $percent) {
292 292
 			return FALSE;
293
-		} elseif ( $unit_price >= .001 && $percent ) {
294
-			throw new EE_Error( sprintf( __( "A Line Item can not have a unit price of (%s) AND a percent (%s)!", "event_espresso" ), $unit_price, $percent ) );
293
+		} elseif ($unit_price >= .001 && $percent) {
294
+			throw new EE_Error(sprintf(__("A Line Item can not have a unit price of (%s) AND a percent (%s)!", "event_espresso"), $unit_price, $percent));
295 295
 		} else {
296 296
 			// if they're both 0, assume its not a percent item
297 297
 			return FALSE;
@@ -305,7 +305,7 @@  discard block
 block discarded – undo
305 305
 	 * @return float
306 306
 	 */
307 307
 	public function percent() {
308
-		return $this->get( 'LIN_percent' );
308
+		return $this->get('LIN_percent');
309 309
 	}
310 310
 
311 311
 
@@ -315,8 +315,8 @@  discard block
 block discarded – undo
315 315
 	 * @param float $percent
316 316
 	 * @return boolean
317 317
 	 */
318
-	public function set_percent( $percent ) {
319
-		$this->set( 'LIN_percent', $percent );
318
+	public function set_percent($percent) {
319
+		$this->set('LIN_percent', $percent);
320 320
 	}
321 321
 
322 322
 
@@ -326,7 +326,7 @@  discard block
 block discarded – undo
326 326
 	 * @return float
327 327
 	 */
328 328
 	public function total() {
329
-		return $this->get( 'LIN_total' );
329
+		return $this->get('LIN_total');
330 330
 	}
331 331
 
332 332
 
@@ -336,8 +336,8 @@  discard block
 block discarded – undo
336 336
 	 * @param float $total
337 337
 	 * @return boolean
338 338
 	 */
339
-	public function set_total( $total ) {
340
-		$this->set( 'LIN_total', $total );
339
+	public function set_total($total) {
340
+		$this->set('LIN_total', $total);
341 341
 	}
342 342
 
343 343
 
@@ -347,7 +347,7 @@  discard block
 block discarded – undo
347 347
 	 * @return int
348 348
 	 */
349 349
 	public function order() {
350
-		return $this->get( 'LIN_order' );
350
+		return $this->get('LIN_order');
351 351
 	}
352 352
 
353 353
 
@@ -356,8 +356,8 @@  discard block
 block discarded – undo
356 356
 	 * Sets order
357 357
 	 * @param int $order
358 358
 	 */
359
-	public function set_order( $order ) {
360
-		$this->set( 'LIN_order', $order );
359
+	public function set_order($order) {
360
+		$this->set('LIN_order', $order);
361 361
 	}
362 362
 
363 363
 
@@ -367,7 +367,7 @@  discard block
 block discarded – undo
367 367
 	 * @return int
368 368
 	 */
369 369
 	public function parent_ID() {
370
-		return $this->get( 'LIN_parent' );
370
+		return $this->get('LIN_parent');
371 371
 	}
372 372
 
373 373
 
@@ -377,8 +377,8 @@  discard block
 block discarded – undo
377 377
 	 * @param int $parent
378 378
 	 * @return boolean
379 379
 	 */
380
-	public function set_parent_ID( $parent ) {
381
-		$this->set( 'LIN_parent', $parent );
380
+	public function set_parent_ID($parent) {
381
+		$this->set('LIN_parent', $parent);
382 382
 	}
383 383
 
384 384
 
@@ -388,7 +388,7 @@  discard block
 block discarded – undo
388 388
 	 * @return string
389 389
 	 */
390 390
 	public function type() {
391
-		return $this->get( 'LIN_type' );
391
+		return $this->get('LIN_type');
392 392
 	}
393 393
 
394 394
 
@@ -398,8 +398,8 @@  discard block
 block discarded – undo
398 398
 	 * @param string $type
399 399
 	 * @return boolean
400 400
 	 */
401
-	public function set_type( $type ) {
402
-		$this->set( 'LIN_type', $type );
401
+	public function set_type($type) {
402
+		$this->set('LIN_type', $type);
403 403
 	}
404 404
 
405 405
 
@@ -412,8 +412,8 @@  discard block
 block discarded – undo
412 412
 	 * @return EE_Line_Item
413 413
 	 */
414 414
 	public function parent() {
415
-		if( $this->ID() ) {
416
-			return $this->get_model()->get_one_by_ID( $this->parent_ID() );
415
+		if ($this->ID()) {
416
+			return $this->get_model()->get_one_by_ID($this->parent_ID());
417 417
 		} else {
418 418
 			return $this->_parent;
419 419
 		}
@@ -426,13 +426,13 @@  discard block
 block discarded – undo
426 426
 	 * @return EE_Line_Item[]
427 427
 	 */
428 428
 	public function children() {
429
-		if ( $this->ID() ) {
429
+		if ($this->ID()) {
430 430
 			return $this->get_model()->get_all(
431 431
 					array(
432
-						array( 'LIN_parent' => $this->ID() ),
433
-						'order_by' => array( 'LIN_order' => 'ASC' ) ) );
432
+						array('LIN_parent' => $this->ID()),
433
+						'order_by' => array('LIN_order' => 'ASC') ) );
434 434
 		} else {
435
-			if ( ! is_array( $this->_children ) ) {
435
+			if ( ! is_array($this->_children)) {
436 436
 				$this->_children = array();
437 437
 			}
438 438
 			return $this->_children;
@@ -446,7 +446,7 @@  discard block
 block discarded – undo
446 446
 	 * @return string
447 447
 	 */
448 448
 	public function code() {
449
-		return $this->get( 'LIN_code' );
449
+		return $this->get('LIN_code');
450 450
 	}
451 451
 
452 452
 
@@ -456,8 +456,8 @@  discard block
 block discarded – undo
456 456
 	 * @param string $code
457 457
 	 * @return boolean
458 458
 	 */
459
-	public function set_code( $code ) {
460
-		$this->set( 'LIN_code', $code );
459
+	public function set_code($code) {
460
+		$this->set('LIN_code', $code);
461 461
 	}
462 462
 
463 463
 
@@ -467,7 +467,7 @@  discard block
 block discarded – undo
467 467
 	 * @return boolean
468 468
 	 */
469 469
 	public function is_taxable() {
470
-		return $this->get( 'LIN_is_taxable' );
470
+		return $this->get('LIN_is_taxable');
471 471
 	}
472 472
 
473 473
 
@@ -477,8 +477,8 @@  discard block
 block discarded – undo
477 477
 	 * @param boolean $is_taxable
478 478
 	 * @return boolean
479 479
 	 */
480
-	public function set_is_taxable( $is_taxable ) {
481
-		$this->set( 'LIN_is_taxable', $is_taxable );
480
+	public function set_is_taxable($is_taxable) {
481
+		$this->set('LIN_is_taxable', $is_taxable);
482 482
 	}
483 483
 
484 484
 
@@ -493,7 +493,7 @@  discard block
 block discarded – undo
493 493
 	 */
494 494
 	public function get_object() {
495 495
 		$model_name_of_related_obj = $this->OBJ_type();
496
-		return $this->get_model()->has_relation(  $model_name_of_related_obj ) ? $this->get_first_related( $model_name_of_related_obj ) : NULL;
496
+		return $this->get_model()->has_relation($model_name_of_related_obj) ? $this->get_first_related($model_name_of_related_obj) : NULL;
497 497
 	}
498 498
 
499 499
 
@@ -504,11 +504,11 @@  discard block
 block discarded – undo
504 504
 	 * @param array $query_params
505 505
 	 * @return EE_Ticket
506 506
 	 */
507
-	public function ticket( $query_params = array() ) {
507
+	public function ticket($query_params = array()) {
508 508
 		//we're going to assume that when this method is called we always want to receive the attached ticket EVEN if that ticket is archived.  This can be overridden via the incoming $query_params argument
509
-		$remove_defaults = array( 'default_where_conditions' => 'none' );
510
-		$query_params = array_merge( $remove_defaults, $query_params );
511
-		return $this->get_first_related( 'Ticket', $query_params );
509
+		$remove_defaults = array('default_where_conditions' => 'none');
510
+		$query_params = array_merge($remove_defaults, $query_params);
511
+		return $this->get_first_related('Ticket', $query_params);
512 512
 	}
513 513
 
514 514
 
@@ -518,11 +518,11 @@  discard block
 block discarded – undo
518 518
 	 * @return EE_Datetime | NULL
519 519
 	 */
520 520
 	public function get_ticket_datetime() {
521
-		if ( $this->OBJ_type() === 'Ticket' ) {
521
+		if ($this->OBJ_type() === 'Ticket') {
522 522
 			$ticket = $this->ticket();
523
-			if ( $ticket instanceof EE_Ticket ) {
523
+			if ($ticket instanceof EE_Ticket) {
524 524
 				$datetime = $ticket->first_datetime();
525
-				if ( $datetime instanceof EE_Datetime ) {
525
+				if ($datetime instanceof EE_Datetime) {
526 526
 					return $datetime;
527 527
 				}
528 528
 			}
@@ -538,9 +538,9 @@  discard block
 block discarded – undo
538 538
 	 * @return string
539 539
 	 */
540 540
 	public function ticket_event_name() {
541
-		$event_name = __( "Unknown", "event_espresso" );
541
+		$event_name = __("Unknown", "event_espresso");
542 542
 		$event = $this->ticket_event();
543
-		if ( $event instanceof EE_Event ) {
543
+		if ($event instanceof EE_Event) {
544 544
 			$event_name = $event->name();
545 545
 		}
546 546
 		return $event_name;
@@ -554,9 +554,9 @@  discard block
 block discarded – undo
554 554
 	public function ticket_event() {
555 555
 		$event = null;
556 556
 		$ticket = $this->ticket();
557
-		if ( $ticket instanceof EE_Ticket ) {
557
+		if ($ticket instanceof EE_Ticket) {
558 558
 			$datetime = $ticket->first_datetime();
559
-			if ( $datetime instanceof EE_Datetime ) {
559
+			if ($datetime instanceof EE_Datetime) {
560 560
 				$event = $datetime->event();
561 561
 			}
562 562
 		}
@@ -571,11 +571,11 @@  discard block
 block discarded – undo
571 571
 	 * @param string $time_format
572 572
 	 * @return string
573 573
 	 */
574
-	public function ticket_datetime_start( $date_format = '', $time_format = '' ) {
575
-		$first_datetime_string = __( "Unknown", "event_espresso" );
574
+	public function ticket_datetime_start($date_format = '', $time_format = '') {
575
+		$first_datetime_string = __("Unknown", "event_espresso");
576 576
 		$datetime = $this->get_ticket_datetime();
577
-		if ( $datetime ) {
578
-			$first_datetime_string = $datetime->start_date_and_time( $date_format, $time_format );
577
+		if ($datetime) {
578
+			$first_datetime_string = $datetime->start_date_and_time($date_format, $time_format);
579 579
 		}
580 580
 		return $first_datetime_string;
581 581
 	}
@@ -590,26 +590,26 @@  discard block
 block discarded – undo
590 590
 	 * @return bool success
591 591
 	 * @throws \EE_Error
592 592
 	 */
593
-	public function add_child_line_item( EEI_Line_Item $line_item, $set_order = true ) {
593
+	public function add_child_line_item(EEI_Line_Item $line_item, $set_order = true) {
594 594
 		// should we calculate the LIN_order for this line item ?
595
-		if ( $set_order || $line_item->order() === null ) {
596
-			$line_item->set_order( count( $this->children() ) );
595
+		if ($set_order || $line_item->order() === null) {
596
+			$line_item->set_order(count($this->children()));
597 597
 		}
598
-		if ( $this->ID() ) {
598
+		if ($this->ID()) {
599 599
 			//check for any duplicate line items (with the same code), if so, this replaces it
600
-			$line_item_with_same_code = $this->get_child_line_item(  $line_item->code() );
601
-			if( $line_item_with_same_code instanceof EE_Line_Item && $line_item_with_same_code !== $line_item ) {
602
-				$this->delete_child_line_item( $line_item_with_same_code->code() );
600
+			$line_item_with_same_code = $this->get_child_line_item($line_item->code());
601
+			if ($line_item_with_same_code instanceof EE_Line_Item && $line_item_with_same_code !== $line_item) {
602
+				$this->delete_child_line_item($line_item_with_same_code->code());
603 603
 			}
604
-			$line_item->set_parent_ID( $this->ID() );
605
-			if( $this->TXN_ID() ){
606
-				$line_item->set_TXN_ID( $this->TXN_ID() );
604
+			$line_item->set_parent_ID($this->ID());
605
+			if ($this->TXN_ID()) {
606
+				$line_item->set_TXN_ID($this->TXN_ID());
607 607
 			}
608 608
 			return $line_item->save();
609 609
 		} else {
610
-			$this->_children[ $line_item->code() ] = $line_item;
611
-			if( $line_item->parent() != $this ) {
612
-				$line_item->set_parent( $this );
610
+			$this->_children[$line_item->code()] = $line_item;
611
+			if ($line_item->parent() != $this) {
612
+				$line_item->set_parent($this);
613 613
 			}
614 614
 			return TRUE;
615 615
 		}
@@ -623,16 +623,16 @@  discard block
 block discarded – undo
623 623
 	 * @param EE_Line_Item $line_item
624 624
 	 *
625 625
 	 */
626
-	public function set_parent( $line_item ) {
627
-		if ( $this->ID() ) {
628
-			if( ! $line_item->ID() ) {
626
+	public function set_parent($line_item) {
627
+		if ($this->ID()) {
628
+			if ( ! $line_item->ID()) {
629 629
 				$line_item->save();
630 630
 			}
631
-			$this->set_parent_ID( $line_item->ID() );
631
+			$this->set_parent_ID($line_item->ID());
632 632
 			$this->save();
633 633
 		} else {
634 634
 			$this->_parent = $line_item;
635
-			$this->set_parent_ID( $line_item->ID() );
635
+			$this->set_parent_ID($line_item->ID());
636 636
 		}
637 637
 	}
638 638
 
@@ -645,11 +645,11 @@  discard block
 block discarded – undo
645 645
 	 * @param string $code
646 646
 	 * @return EE_Line_Item
647 647
 	 */
648
-	public function get_child_line_item( $code ) {
649
-		if ( $this->ID() ) {
650
-			return $this->get_model()->get_one( array( array( 'LIN_parent' => $this->ID(), 'LIN_code' => $code ) ) );
648
+	public function get_child_line_item($code) {
649
+		if ($this->ID()) {
650
+			return $this->get_model()->get_one(array(array('LIN_parent' => $this->ID(), 'LIN_code' => $code)));
651 651
 		} else {
652
-			return isset( $this->_children[ $code ] ) ? $this->_children[ $code ] : null;
652
+			return isset($this->_children[$code]) ? $this->_children[$code] : null;
653 653
 		}
654 654
 	}
655 655
 
@@ -660,10 +660,10 @@  discard block
 block discarded – undo
660 660
 	 * @return int
661 661
 	 */
662 662
 	public function delete_children_line_items() {
663
-		if ( $this->ID() ) {
664
-			return $this->get_model()->delete( array( array( 'LIN_parent' => $this->ID() ) ) );
663
+		if ($this->ID()) {
664
+			return $this->get_model()->delete(array(array('LIN_parent' => $this->ID())));
665 665
 		} else {
666
-			$count = count( $this->_children );
666
+			$count = count($this->_children);
667 667
 			$this->_children = array();
668 668
 			return $count;
669 669
 		}
@@ -680,25 +680,25 @@  discard block
 block discarded – undo
680 680
 	 * @param bool $stop_search_once_found
681 681
 	 * @return int count of items deleted (or simply removed from the line item's cache, if not has not been saved to the DB yet)
682 682
 	 */
683
-	public function delete_child_line_item( $code, $stop_search_once_found = true ) {
684
-		if ( $this->ID() ) {
683
+	public function delete_child_line_item($code, $stop_search_once_found = true) {
684
+		if ($this->ID()) {
685 685
 			$items_deleted = 0;
686
-			if( $this->code() == $code ) {
687
-				$items_deleted += EEH_Line_Item::delete_all_child_items( $this );
686
+			if ($this->code() == $code) {
687
+				$items_deleted += EEH_Line_Item::delete_all_child_items($this);
688 688
 				$items_deleted += (int) $this->delete();
689
-				if( $stop_search_once_found ){
689
+				if ($stop_search_once_found) {
690 690
 					return $items_deleted;
691 691
 				}
692 692
 			}
693
-			foreach( $this->children() as $child_line_item ) {
694
-				$items_deleted += $child_line_item->delete_child_line_item( $code, $stop_search_once_found );
693
+			foreach ($this->children() as $child_line_item) {
694
+				$items_deleted += $child_line_item->delete_child_line_item($code, $stop_search_once_found);
695 695
 			}
696 696
 			return $items_deleted;
697 697
 		} else {
698
-			if( isset( $this->_children[ $code ] ) ) {
699
-				unset( $this->_children[ $code ] );
698
+			if (isset($this->_children[$code])) {
699
+				unset($this->_children[$code]);
700 700
 				return 1;
701
-			}else{
701
+			} else {
702 702
 				return 0;
703 703
 			}
704 704
 		}
@@ -711,9 +711,9 @@  discard block
 block discarded – undo
711 711
 	 * @return boolean
712 712
 	 */
713 713
 	public function delete_if_childless_subtotal() {
714
-		if( $this->ID() &&
714
+		if ($this->ID() &&
715 715
 				$this->type() == EEM_Line_Item::type_sub_total &&
716
-				! $this->children() ) {
716
+				! $this->children()) {
717 717
 			return $this->delete();
718 718
 		} else {
719 719
 			return false;
@@ -728,7 +728,7 @@  discard block
 block discarded – undo
728 728
 	 */
729 729
 	public function generate_code() {
730 730
 		// each line item in the cart requires a unique identifier
731
-		return md5( $this->get( 'OBJ_type' ) . $this->get( 'OBJ_ID' ) . microtime() );
731
+		return md5($this->get('OBJ_type').$this->get('OBJ_ID').microtime());
732 732
 	}
733 733
 
734 734
 
@@ -811,7 +811,7 @@  discard block
 block discarded – undo
811 811
 	 * @return string like '2, 004.00', formatted according to the localized currency
812 812
 	 */
813 813
 	public function unit_price_no_code() {
814
-		return $this->get_pretty( 'LIN_unit_price', 'no_currency_code' );
814
+		return $this->get_pretty('LIN_unit_price', 'no_currency_code');
815 815
 	}
816 816
 
817 817
 
@@ -821,7 +821,7 @@  discard block
 block discarded – undo
821 821
 	 * @return string like '2, 004.00', formatted according to the localized currency
822 822
 	 */
823 823
 	public function total_no_code() {
824
-		return $this->get_pretty( 'LIN_total', 'no_currency_code' );
824
+		return $this->get_pretty('LIN_total', 'no_currency_code');
825 825
 	}
826 826
 
827 827
 
@@ -841,17 +841,17 @@  discard block
 block discarded – undo
841 841
 		$tax_total = $this->recalculate_taxes_and_tax_total();
842 842
 		$total = $pre_tax_total + $tax_total;
843 843
 		// no negative totals plz
844
-		$total = max( $total, 0 );
845
-		$this->set_total( $total );
844
+		$total = max($total, 0);
845
+		$this->set_total($total);
846 846
 		//only update the related transaction's total
847 847
 		//if we intend to save this line item and its a grand total
848
-		if(
848
+		if (
849 849
 			$this->allow_persist() &&
850 850
 			$this->type() === EEM_Line_Item::type_total &&
851 851
 			$this->transaction() instanceof EE_Transaction
852
-		){
853
-			$this->transaction()->set_total( $total );
854
-			if ( $this->transaction()->ID() ) {
852
+		) {
853
+			$this->transaction()->set_total($total);
854
+			if ($this->transaction()->ID()) {
855 855
 				$this->transaction()->save();
856 856
 			}
857 857
 		}
@@ -871,46 +871,46 @@  discard block
 block discarded – undo
871 871
 		$total = 0;
872 872
 		$my_children = $this->children();
873 873
 		// completely ignore tax totals, tax sub-totals, and cancelled line items, when calculating the pre-tax-total
874
-		if ( $this->is_tax_sub_total() || $this->is_tax() || $this->is_cancelled() ) {
874
+		if ($this->is_tax_sub_total() || $this->is_tax() || $this->is_cancelled()) {
875 875
 			return 0;
876 876
 		} elseif (
877
-			empty( $my_children )
878
-			&& ( $this->is_sub_line_item() || $this->is_line_item() )
877
+			empty($my_children)
878
+			&& ($this->is_sub_line_item() || $this->is_line_item())
879 879
 		) {
880 880
 			$total = $this->unit_price() * $this->quantity();
881
-		} elseif( $this->is_sub_total() || $this->is_total() ) {
882
-			$total = $this->_recalculate_pretax_total_for_subtotal( $total, $my_children );
883
-		} elseif ( ! empty( $my_children ) && $this->is_line_item() ) {
884
-			$total = $this->_recalculate_pretax_total_for_line_item( $total, $my_children );
881
+		} elseif ($this->is_sub_total() || $this->is_total()) {
882
+			$total = $this->_recalculate_pretax_total_for_subtotal($total, $my_children);
883
+		} elseif ( ! empty($my_children) && $this->is_line_item()) {
884
+			$total = $this->_recalculate_pretax_total_for_line_item($total, $my_children);
885 885
 		}
886 886
 		//ensure all non-line items and non-sub-line-items have a quantity of 1
887
-		if(
887
+		if (
888 888
 			! $this->is_line_item() &&
889 889
 			! $this->is_sub_line_item() &&
890 890
 			! $this->is_cancellation()
891 891
 		) {
892
-			$this->set_quantity( 1 );
893
-			if( ! $this->is_percent() ) {
894
-				$this->set_unit_price( $this->total() );
892
+			$this->set_quantity(1);
893
+			if ( ! $this->is_percent()) {
894
+				$this->set_unit_price($this->total());
895 895
 			}
896 896
 		}
897 897
 
898 898
 		//we don't want to bother saving grand totals, because that needs to factor in taxes anyways
899 899
 		//so it ought to be
900
-		if( ! $this->is_total() ) {
901
-			$this->set_total( $total );
900
+		if ( ! $this->is_total()) {
901
+			$this->set_total($total);
902 902
 			//if not a percent line item, make sure we keep the unit price in sync
903
-			if(
904
-				! empty( $my_children )
903
+			if (
904
+				! empty($my_children)
905 905
 				&& $this->is_line_item()
906 906
 				&& ! $this->is_percent()
907 907
 			) {
908
-				if( $this->quantity() === 0 ){
908
+				if ($this->quantity() === 0) {
909 909
 					$new_unit_price = 0;
910 910
 				} else {
911 911
 					$new_unit_price = $this->total() / $this->quantity();
912 912
 				}
913
-				$this->set_unit_price( $new_unit_price );
913
+				$this->set_unit_price($new_unit_price);
914 914
 			}
915 915
 			$this->maybe_save();
916 916
 		}
@@ -930,39 +930,39 @@  discard block
 block discarded – undo
930 930
 	 * @return float
931 931
 	 * @throws \EE_Error
932 932
 	 */
933
-	protected function _recalculate_pretax_total_for_subtotal( $calculated_total_so_far, $my_children = null ) {
934
-		if( $my_children === null ) {
933
+	protected function _recalculate_pretax_total_for_subtotal($calculated_total_so_far, $my_children = null) {
934
+		if ($my_children === null) {
935 935
 			$my_children = $this->children();
936 936
 		}
937 937
 		//get the total of all its children
938
-		foreach ( $my_children as $child_line_item ) {
939
-			if ( $child_line_item instanceof EE_Line_Item && ! $child_line_item->is_cancellation() ) {
938
+		foreach ($my_children as $child_line_item) {
939
+			if ($child_line_item instanceof EE_Line_Item && ! $child_line_item->is_cancellation()) {
940 940
 				// percentage line items are based on total so far
941
-				if ( $child_line_item->is_percent() ) {
941
+				if ($child_line_item->is_percent()) {
942 942
 					//round as we go so that the line items add up ok
943 943
 					$percent_total = round(
944 944
 						$calculated_total_so_far * $child_line_item->percent() / 100,
945 945
 						EE_Registry::instance()->CFG->currency->dec_plc
946 946
 					);
947
-					$child_line_item->set_total( $percent_total );
947
+					$child_line_item->set_total($percent_total);
948 948
 					//so far all percent line items should have a quantity of 1
949 949
 					//(ie, no double percent discounts. Although that might be requested someday)
950
-					$child_line_item->set_quantity( 1 );
950
+					$child_line_item->set_quantity(1);
951 951
 					$child_line_item->maybe_save();
952 952
 					$calculated_total_so_far += $percent_total;
953 953
 				} else {
954 954
 					//verify flat sub-line-item quantities match their parent
955
-					if( $child_line_item->is_sub_line_item() ) {
956
-						$child_line_item->set_quantity( $this->quantity() );
955
+					if ($child_line_item->is_sub_line_item()) {
956
+						$child_line_item->set_quantity($this->quantity());
957 957
 					}
958 958
 					$calculated_total_so_far += $child_line_item->recalculate_pre_tax_total();
959 959
 				}
960 960
 			}
961 961
 		}
962 962
 
963
-		if( $this->is_sub_total() ){
963
+		if ($this->is_sub_total()) {
964 964
 			// no negative totals plz
965
-			$calculated_total_so_far = max( $calculated_total_so_far, 0 );
965
+			$calculated_total_so_far = max($calculated_total_so_far, 0);
966 966
 		}
967 967
 		return $calculated_total_so_far;
968 968
 	}
@@ -980,8 +980,8 @@  discard block
 block discarded – undo
980 980
 	 * @return float
981 981
 	 * @throws \EE_Error
982 982
 	 */
983
-	protected function _recalculate_pretax_total_for_line_item( $calculated_total_so_far, $my_children = null ) {
984
-		if( $my_children === null ) {
983
+	protected function _recalculate_pretax_total_for_line_item($calculated_total_so_far, $my_children = null) {
984
+		if ($my_children === null) {
985 985
 			$my_children = $this->children();
986 986
 		}
987 987
 		//we need to keep track of the running total for a single item,
@@ -989,10 +989,10 @@  discard block
 block discarded – undo
989 989
 		$unit_price_for_total = 0;
990 990
 		$quantity_for_total = 1;
991 991
 		//get the total of all its children
992
-		foreach ( $my_children as $child_line_item ) {
993
-			if ( $child_line_item instanceof EE_Line_Item &&
992
+		foreach ($my_children as $child_line_item) {
993
+			if ($child_line_item instanceof EE_Line_Item &&
994 994
 					! $child_line_item->is_cancellation()) {
995
-				if ( $child_line_item->is_percent() ) {
995
+				if ($child_line_item->is_percent()) {
996 996
 					//it should be the unit-price-so-far multiplied by teh percent multiplied by the quantity
997 997
 					//not total multiplied by percent, because that ignores rounding along-the-way
998 998
 					$percent_unit_price = round(
@@ -1000,17 +1000,17 @@  discard block
 block discarded – undo
1000 1000
 						EE_Registry::instance()->CFG->currency->dec_plc
1001 1001
 					);
1002 1002
 					$percent_total = $percent_unit_price * $quantity_for_total;
1003
-					$child_line_item->set_total( $percent_total );
1003
+					$child_line_item->set_total($percent_total);
1004 1004
 					//so far all percent line items should have a quantity of 1
1005 1005
 					//(ie, no double percent discounts. Although that might be requested someday)
1006
-					$child_line_item->set_quantity( 1 );
1006
+					$child_line_item->set_quantity(1);
1007 1007
 					$child_line_item->maybe_save();
1008 1008
 					$calculated_total_so_far += $percent_total;
1009 1009
 					$unit_price_for_total += $percent_unit_price;
1010 1010
 				} else {
1011 1011
 					//verify flat sub-line-item quantities match their parent
1012
-					if( $child_line_item->is_sub_line_item() ) {
1013
-						$child_line_item->set_quantity( $this->quantity() );
1012
+					if ($child_line_item->is_sub_line_item()) {
1013
+						$child_line_item->set_quantity($this->quantity());
1014 1014
 					}
1015 1015
 					$quantity_for_total = $child_line_item->quantity();
1016 1016
 					$calculated_total_so_far += $child_line_item->recalculate_pre_tax_total();
@@ -1034,10 +1034,10 @@  discard block
 block discarded – undo
1034 1034
 		//calculate the pretax total
1035 1035
 		$taxable_total = $this->taxable_total();
1036 1036
 		$tax_total = 0;
1037
-		foreach ( $taxes as $tax ) {
1037
+		foreach ($taxes as $tax) {
1038 1038
 			$total_on_this_tax = $taxable_total * $tax->percent() / 100;
1039 1039
 			//remember the total on this line item
1040
-			$tax->set_total( $total_on_this_tax );
1040
+			$tax->set_total($total_on_this_tax);
1041 1041
 			$tax_total += $tax->total();
1042 1042
 		}
1043 1043
 		$this->_recalculate_tax_sub_total();
@@ -1051,21 +1051,21 @@  discard block
 block discarded – undo
1051 1051
 	 * @return void
1052 1052
 	 */
1053 1053
 	private function _recalculate_tax_sub_total() {
1054
-		if ( $this->is_tax_sub_total() ) {
1054
+		if ($this->is_tax_sub_total()) {
1055 1055
 			$total = 0;
1056 1056
 			$total_percent = 0;
1057 1057
 			//simply loop through all its children (which should be taxes) and sum their total
1058
-			foreach ( $this->children() as $child_tax ) {
1059
-				if ( $child_tax instanceof EE_Line_Item ) {
1058
+			foreach ($this->children() as $child_tax) {
1059
+				if ($child_tax instanceof EE_Line_Item) {
1060 1060
 					$total += $child_tax->total();
1061 1061
 					$total_percent += $child_tax->percent();
1062 1062
 				}
1063 1063
 			}
1064
-			$this->set_total( $total );
1065
-			$this->set_percent( $total_percent );
1066
-		} elseif ( $this->is_total() ) {
1067
-			foreach ( $this->children() as $maybe_tax_subtotal ) {
1068
-				if ( $maybe_tax_subtotal instanceof EE_Line_Item ) {
1064
+			$this->set_total($total);
1065
+			$this->set_percent($total_percent);
1066
+		} elseif ($this->is_total()) {
1067
+			foreach ($this->children() as $maybe_tax_subtotal) {
1068
+				if ($maybe_tax_subtotal instanceof EE_Line_Item) {
1069 1069
 					$maybe_tax_subtotal->_recalculate_tax_sub_total();
1070 1070
 				}
1071 1071
 			}
@@ -1081,8 +1081,8 @@  discard block
 block discarded – undo
1081 1081
 	public function get_total_tax() {
1082 1082
 		$this->_recalculate_tax_sub_total();
1083 1083
 		$total = 0;
1084
-		foreach ( $this->tax_descendants() as $tax_line_item ) {
1085
-			if ( $tax_line_item instanceof EE_Line_Item ) {
1084
+		foreach ($this->tax_descendants() as $tax_line_item) {
1085
+			if ($tax_line_item instanceof EE_Line_Item) {
1086 1086
 				$total += $tax_line_item->total();
1087 1087
 			}
1088 1088
 		}
@@ -1096,15 +1096,15 @@  discard block
 block discarded – undo
1096 1096
 	 */
1097 1097
 	public function get_items_total() {
1098 1098
 		//by default, let's make sure we're consistent with the existing line item
1099
-		if( $this->is_total() ) {
1100
-			$pretax_subtotal_li = EEH_Line_Item::get_pre_tax_subtotal( $this );
1101
-			if( $pretax_subtotal_li instanceof EE_Line_Item ) {
1099
+		if ($this->is_total()) {
1100
+			$pretax_subtotal_li = EEH_Line_Item::get_pre_tax_subtotal($this);
1101
+			if ($pretax_subtotal_li instanceof EE_Line_Item) {
1102 1102
 				return $pretax_subtotal_li->total();
1103 1103
 			}
1104 1104
 		}
1105 1105
 		$total = 0;
1106
-		foreach ( $this->get_items() as $item ) {
1107
-			if ( $item instanceof EE_Line_Item ) {
1106
+		foreach ($this->get_items() as $item) {
1107
+			if ($item instanceof EE_Line_Item) {
1108 1108
 				$total += $item->total();
1109 1109
 			}
1110 1110
 		}
@@ -1119,7 +1119,7 @@  discard block
 block discarded – undo
1119 1119
 	 * @return EE_Line_Item[]
1120 1120
 	 */
1121 1121
 	public function tax_descendants() {
1122
-		return EEH_Line_Item::get_tax_descendants( $this );
1122
+		return EEH_Line_Item::get_tax_descendants($this);
1123 1123
 	}
1124 1124
 
1125 1125
 
@@ -1129,7 +1129,7 @@  discard block
 block discarded – undo
1129 1129
 	 * @return EE_Line_Item[]
1130 1130
 	 */
1131 1131
 	public function get_items() {
1132
-		return EEH_Line_Item::get_line_item_descendants( $this );
1132
+		return EEH_Line_Item::get_line_item_descendants($this);
1133 1133
 	}
1134 1134
 
1135 1135
 
@@ -1145,22 +1145,22 @@  discard block
 block discarded – undo
1145 1145
 	 */
1146 1146
 	public function taxable_total() {
1147 1147
 		$total = 0;
1148
-		if ( $this->children() ) {
1149
-			foreach ( $this->children() as $child_line_item ) {
1150
-				if ( $child_line_item->type() === EEM_Line_Item::type_line_item && $child_line_item->is_taxable()) {
1148
+		if ($this->children()) {
1149
+			foreach ($this->children() as $child_line_item) {
1150
+				if ($child_line_item->type() === EEM_Line_Item::type_line_item && $child_line_item->is_taxable()) {
1151 1151
 					//if it's a percent item, only take into account the percent
1152 1152
 					//that's taxable too (the taxable total so far)
1153
-					if( $child_line_item->is_percent() ) {
1154
-						$total = $total + ( $total * $child_line_item->percent() / 100 );
1155
-					}else{
1153
+					if ($child_line_item->is_percent()) {
1154
+						$total = $total + ($total * $child_line_item->percent() / 100);
1155
+					} else {
1156 1156
 						$total += $child_line_item->total();
1157 1157
 					}
1158
-				}elseif( $child_line_item->type() === EEM_Line_Item::type_sub_total ){
1158
+				}elseif ($child_line_item->type() === EEM_Line_Item::type_sub_total) {
1159 1159
 					$total += $child_line_item->taxable_total();
1160 1160
 				}
1161 1161
 			}
1162 1162
 		}
1163
-		return max( $total, 0 );
1163
+		return max($total, 0);
1164 1164
 	}
1165 1165
 
1166 1166
 
@@ -1170,7 +1170,7 @@  discard block
 block discarded – undo
1170 1170
 	 * @return EE_Transaction
1171 1171
 	 */
1172 1172
 	public function transaction() {
1173
-		return $this->get_first_related( 'Transaction' );
1173
+		return $this->get_first_related('Transaction');
1174 1174
 	}
1175 1175
 
1176 1176
 
@@ -1183,18 +1183,18 @@  discard block
 block discarded – undo
1183 1183
 	 * @param int $txn_id if none is provided, assumes $this->TXN_ID()
1184 1184
 	 * @return int count of items saved
1185 1185
 	 */
1186
-	public function save_this_and_descendants_to_txn( $txn_id = NULL ) {
1186
+	public function save_this_and_descendants_to_txn($txn_id = NULL) {
1187 1187
 		$count = 0;
1188
-		if ( ! $txn_id ) {
1188
+		if ( ! $txn_id) {
1189 1189
 			$txn_id = $this->TXN_ID();
1190 1190
 		}
1191
-		$this->set_TXN_ID( $txn_id );
1191
+		$this->set_TXN_ID($txn_id);
1192 1192
 		$children = $this->children();
1193 1193
 		$count += $this->save() ? 1 : 0;
1194
-		foreach ( $children as $child_line_item ) {
1195
-			if ( $child_line_item instanceof EE_Line_Item ) {
1196
-				$child_line_item->set_parent_ID( $this->ID() );
1197
-				$count += $child_line_item->save_this_and_descendants_to_txn( $txn_id );
1194
+		foreach ($children as $child_line_item) {
1195
+			if ($child_line_item instanceof EE_Line_Item) {
1196
+				$child_line_item->set_parent_ID($this->ID());
1197
+				$count += $child_line_item->save_this_and_descendants_to_txn($txn_id);
1198 1198
 			}
1199 1199
 		}
1200 1200
 		return $count;
@@ -1211,9 +1211,9 @@  discard block
 block discarded – undo
1211 1211
 		$count = 0;
1212 1212
 		$children = $this->children();
1213 1213
 		$count += $this->save() ? 1 : 0;
1214
-		foreach ( $children as $child_line_item ) {
1215
-			if ( $child_line_item instanceof EE_Line_Item ) {
1216
-				$child_line_item->set_parent_ID( $this->ID() );
1214
+		foreach ($children as $child_line_item) {
1215
+			if ($child_line_item instanceof EE_Line_Item) {
1216
+				$child_line_item->set_parent_ID($this->ID());
1217 1217
 				$count += $child_line_item->save_this_and_descendants();
1218 1218
 			}
1219 1219
 		}
@@ -1227,8 +1227,8 @@  discard block
 block discarded – undo
1227 1227
 	 * @return EE_Line_Item[]
1228 1228
 	 */
1229 1229
 	function get_cancellations() {
1230
-		EE_Registry::instance()->load_helper( 'Line_Item' );
1231
-		return EEH_Line_Item::get_descendants_of_type( $this, EEM_Line_Item::type_cancellation );
1230
+		EE_Registry::instance()->load_helper('Line_Item');
1231
+		return EEH_Line_Item::get_descendants_of_type($this, EEM_Line_Item::type_cancellation);
1232 1232
 	}
1233 1233
 
1234 1234
 
@@ -1238,9 +1238,9 @@  discard block
 block discarded – undo
1238 1238
 	 * @param string $type one of the constants on EEM_Line_Item
1239 1239
 	 * @return EE_Line_Item[]
1240 1240
 	 */
1241
-	protected function _get_descendants_of_type( $type ) {
1242
-		EE_Error::doing_it_wrong( 'EE_Line_Item::_get_descendants_of_type()', __('Method replaced with EEH_Line_Item::get_descendants_of_type()', 'event_espresso'), '4.6.0' );
1243
-		return EEH_Line_Item::get_descendants_of_type( $this, $type );
1241
+	protected function _get_descendants_of_type($type) {
1242
+		EE_Error::doing_it_wrong('EE_Line_Item::_get_descendants_of_type()', __('Method replaced with EEH_Line_Item::get_descendants_of_type()', 'event_espresso'), '4.6.0');
1243
+		return EEH_Line_Item::get_descendants_of_type($this, $type);
1244 1244
 	}
1245 1245
 
1246 1246
 
@@ -1250,9 +1250,9 @@  discard block
 block discarded – undo
1250 1250
 	 * @param string $type like one of the EEM_Line_Item::type_*
1251 1251
 	 * @return EE_Line_Item
1252 1252
 	 */
1253
-	public function get_nearest_descendant_of_type( $type ) {
1254
-		EE_Error::doing_it_wrong( 'EE_Line_Item::get_nearest_descendant_of_type()', __('Method replaced with EEH_Line_Item::get_nearest_descendant_of_type()', 'event_espresso'), '4.6.0' );
1255
-		return EEH_Line_Item::get_nearest_descendant_of_type( $this, $type );
1253
+	public function get_nearest_descendant_of_type($type) {
1254
+		EE_Error::doing_it_wrong('EE_Line_Item::get_nearest_descendant_of_type()', __('Method replaced with EEH_Line_Item::get_nearest_descendant_of_type()', 'event_espresso'), '4.6.0');
1255
+		return EEH_Line_Item::get_nearest_descendant_of_type($this, $type);
1256 1256
 	}
1257 1257
 
1258 1258
 
@@ -1263,7 +1263,7 @@  discard block
 block discarded – undo
1263 1263
 	 * @return int count of items saved
1264 1264
 	 */
1265 1265
 	public function maybe_save() {
1266
-		if ( $this->ID() ) {
1266
+		if ($this->ID()) {
1267 1267
 			return $this->save();
1268 1268
 		}
1269 1269
 		return false;
Please login to merge, or discard this patch.
core/db_models/EEM_Base.model.php 3 patches
Doc Comments   +16 added lines, -13 removed lines patch added patch discarded remove patch
@@ -802,7 +802,7 @@  discard block
 block discarded – undo
802 802
 	 * Returns the name of the field's name that points to the WP_User table
803 803
 	 *  on this model (or follows the _model_chain_to_wp_user and uses that model's
804 804
 	 * foreign key to the WP_User table)
805
-	 * @return string|boolean string on success, boolean false when there is no
805
+	 * @return string|false string on success, boolean false when there is no
806 806
 	 * foreign key to the WP_User table
807 807
 	 */
808 808
 	public function wp_user_field_name() {
@@ -897,6 +897,7 @@  discard block
 block discarded – undo
897 897
 	 * If you would like to use these custom selections in WHERE, GROUP_BY, or HAVING clauses, you must instead provide an array.
898 898
 	 * Array keys are the aliases used to refer to this selection, and values are to be numerically-indexed arrays, where 0 is the selection
899 899
 	 * and 1 is the data type. Eg, array('count'=>array('COUNT(REG_ID)','%d'))
900
+	 * @param string $columns_to_select
900 901
 	 * @return array|stdClass[] like results of $wpdb->get_results($sql,OBJECT), (ie, output type is OBJECT)
901 902
 	 * @throws \EE_Error
902 903
 	 */
@@ -1242,7 +1243,7 @@  discard block
 block discarded – undo
1242 1243
 	 * @param bool   $pretty          Whether to return the pretty formats (true) or not (false).
1243 1244
 	 * @throws EE_Error   If the given field_name is not of the EE_Datetime_Field type.
1244 1245
 	 *
1245
-	 * @return array formats in an array with the date format first, and the time format last.
1246
+	 * @return string[] formats in an array with the date format first, and the time format last.
1246 1247
 	 */
1247 1248
 	public function get_formats_for( $field_name, $pretty = false ) {
1248 1249
 		$field_settings = $this->field_settings_for( $field_name );
@@ -1277,7 +1278,7 @@  discard block
 block discarded – undo
1277 1278
 	 *
1278 1279
 	 * @throws EE_Error   	If the given field_name is not of the EE_Datetime_Field type.
1279 1280
 	 *
1280
-	 * @return int|string  If the given field_name is not of the EE_Datetime_Field type, then an EE_Error
1281
+	 * @return string|null  If the given field_name is not of the EE_Datetime_Field type, then an EE_Error
1281 1282
 	 *                    	     exception is triggered.
1282 1283
 	 */
1283 1284
 	public function current_time_for_query( $field_name, $timestamp = false, $what = 'both' ) {
@@ -1588,7 +1589,7 @@  discard block
 block discarded – undo
1588 1589
 	 * Wrapper for EEM_Base::delete_permanently()
1589 1590
 	 *
1590 1591
 	 * @param mixed $id
1591
-	 * @return boolean whether the row got deleted or not
1592
+	 * @return integer whether the row got deleted or not
1592 1593
 	 * @throws \EE_Error
1593 1594
 	 */
1594 1595
 	public function delete_permanently_by_ID( $id ) {
@@ -1607,7 +1608,7 @@  discard block
 block discarded – undo
1607 1608
 	 * Wrapper for EEM_Base::delete()
1608 1609
 	 *
1609 1610
 	 * @param mixed $id
1610
-	 * @return boolean whether the row got deleted or not
1611
+	 * @return integer whether the row got deleted or not
1611 1612
 	 * @throws \EE_Error
1612 1613
 	 */
1613 1614
 	public function delete_by_ID( $id ){
@@ -2017,7 +2018,7 @@  discard block
 block discarded – undo
2017 2018
 	/**
2018 2019
 	 * Verifies the EE addons' database is up-to-date and records that we've done it on
2019 2020
 	 * EEM_Base::$_db_verification_level
2020
-	 * @param $wpdb_method
2021
+	 * @param string $wpdb_method
2021 2022
 	 * @param $arguments_to_provide
2022 2023
 	 * @return string
2023 2024
 	 */
@@ -2112,6 +2113,7 @@  discard block
 block discarded – undo
2112 2113
 	 * @return boolean of success
2113 2114
 	 * @throws \EE_Error
2114 2115
 	 * @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.
2116
+	 * @param EE_Base_Class $id_or_obj
2115 2117
 	 */
2116 2118
 	public function remove_relationship_to($id_or_obj,  $other_model_id_or_obj, $relationName, $where_query= array() ){
2117 2119
 		$relation_obj = $this->related_settings_for($relationName);
@@ -2121,7 +2123,7 @@  discard block
 block discarded – undo
2121 2123
 
2122 2124
 
2123 2125
 	/**
2124
-	 * @param mixed           $id_or_obj
2126
+	 * @param EE_Base_Class           $id_or_obj
2125 2127
 	 * @param string          $relationName
2126 2128
 	 * @param array           $where_query_params
2127 2129
 	 * @param EE_Base_Class[] objects to which relations were removed
@@ -2160,7 +2162,7 @@  discard block
 block discarded – undo
2160 2162
 	 * However, if the model objects can't be deleted because of blocking related model objects, then
2161 2163
 	 * they aren't deleted. (Unless the thing that would have been deleted can be soft-deleted, that still happens).
2162 2164
 	 *
2163
-	 * @param EE_Base_Class|int|string $id_or_obj
2165
+	 * @param EE_Base_Class $id_or_obj
2164 2166
 	 * @param string                   $model_name
2165 2167
 	 * @param array                    $query_params
2166 2168
 	 * @return int how many deleted
@@ -2180,7 +2182,7 @@  discard block
 block discarded – undo
2180 2182
 	 * the model objects can't be hard deleted because of blocking related model objects,
2181 2183
 	 * just does a soft-delete on them instead.
2182 2184
 	 *
2183
-	 * @param EE_Base_Class|int|string $id_or_obj
2185
+	 * @param EE_Base_Class $id_or_obj
2184 2186
 	 * @param string                   $model_name
2185 2187
 	 * @param array                    $query_params
2186 2188
 	 * @return int how many deleted
@@ -2229,6 +2231,7 @@  discard block
 block discarded – undo
2229 2231
 	 * @param string $model_name   like 'Event', or 'Registration'
2230 2232
 	 * @param array  $query_params like EEM_Base::get_all's
2231 2233
 	 * @param string $field_to_sum name of field to count by. By default, uses primary key
2234
+	 * @param EE_Base_Class $id_or_obj
2232 2235
 	 * @return float
2233 2236
 	 * @throws \EE_Error
2234 2237
 	 */
@@ -2638,7 +2641,7 @@  discard block
 block discarded – undo
2638 2641
 	/**
2639 2642
 	 * Finds all the fields that correspond to the given table
2640 2643
 	 * @param string $table_alias, array key in EEM_Base::_tables
2641
-	 * @return EE_Model_Field_Base[]
2644
+	 * @return EE_Model_Field_Base
2642 2645
 	 */
2643 2646
 	public function _get_fields_for_table($table_alias){
2644 2647
 		return $this->_fields[$table_alias];
@@ -3901,7 +3904,7 @@  discard block
 block discarded – undo
3901 3904
 	/**
3902 3905
 	 * gets the field object of type 'primary_key' from the fieldsSettings attribute.
3903 3906
 	 * Eg, on EE_Answer that would be ANS_ID field object
3904
-	 * @param $field_obj
3907
+	 * @param EE_Model_Field_Base $field_obj
3905 3908
 	 * @return boolean
3906 3909
 	 */
3907 3910
 	public function is_primary_key_field( $field_obj ){
@@ -3997,7 +4000,7 @@  discard block
 block discarded – undo
3997 4000
 	 * Gets the actual table for the table alias
3998 4001
 	 * @param string $table_alias eg Event, Event_Meta, Registration, Transaction, but maybe
3999 4002
 	 * a table alias with a model chain prefix, like 'Venue__Event_Venue___Event_Meta'. Either one works
4000
-	 * @return EE_Table_Base
4003
+	 * @return string
4001 4004
 	 */
4002 4005
 	public function get_table_for_alias($table_alias){
4003 4006
 		$table_alias_sans_model_relation_chain_prefix = EE_Model_Parser::remove_table_alias_model_relation_chain_prefix($table_alias);
@@ -4543,7 +4546,7 @@  discard block
 block discarded – undo
4543 4546
 	}
4544 4547
 	/**
4545 4548
 	 * Read comments for assume_values_already_prepared_by_model_object()
4546
-	 * @return int
4549
+	 * @return boolean
4547 4550
 	 */
4548 4551
 	public function get_assumption_concerning_values_already_prepared_by_model_object(){
4549 4552
 		return $this->_values_already_prepared_by_model_object;
Please login to merge, or discard this patch.
Indentation   +16 added lines, -17 removed lines patch added patch discarded remove patch
@@ -653,11 +653,11 @@  discard block
 block discarded – undo
653 653
 	 * Gets all the EE_Base_Class objects which match the $query_params, by querying the DB.
654 654
 	 *
655 655
 	 * @param array $query_params {
656
-     *	@var array $0 (where) array {
656
+	 *	@var array $0 (where) array {
657 657
 	 *		eg: array('QST_display_text'=>'Are you bob?','QST_admin_text'=>'Determine if user is bob')
658
-			* becomes
658
+	 * becomes
659 659
 	 *		SQL >> "...WHERE QST_display_text = 'Are you bob?' AND QST_admin_text = 'Determine if user is bob'...")
660
-     *		To add WHERE conditions based on related models (and even models-related-to-related-models) prepend the model's name
660
+	 *		To add WHERE conditions based on related models (and even models-related-to-related-models) prepend the model's name
661 661
 	 *		onto the field name. Eg, EEM_Event::instance()->get_all(array(array('Venue.VNU_ID'=>12)));
662 662
 	 *		becomes
663 663
 	 *		SQL >> "SELECT * FROM wp_posts AS Event_CPT
@@ -677,7 +677,7 @@  discard block
 block discarded – undo
677 677
 	 *		SQL >> "...WHERE QST_display_text LIKE '%bob%' AND QST_ID < 34 AND QST_wp_user IN (1,2,7,23)...".
678 678
 	 *        Valid operators so far: =, !=, <, <=, >, >=, LIKE, NOT LIKE, IN (followed by numeric-indexed array),
679 679
 	 *          NOT IN (dido), BETWEEN (followed by an array with exactly 2 date strings), IS NULL, and IS NOT NULL
680
-     *		Values can be a string, int, or float. They can also be arrays IFF the operator is IN.
680
+	 *		Values can be a string, int, or float. They can also be arrays IFF the operator is IN.
681 681
 	 *        Also, values can actually be field names. To indicate the value is a field,
682 682
 	 *          simply provide a third array item (true) to the operator-value array like so:
683 683
 	 *		eg: array( 'DTT_reg_limit' => array('>', 'DTT_sold', TRUE) )
@@ -686,7 +686,7 @@  discard block
 block discarded – undo
686 686
 	 *		Note: you can also use related model field names like you would any other field name.
687 687
 	 *		eg: array('Datetime.DTT_reg_limit'=>array('=','Datetime.DTT_sold',TRUE)
688 688
 	 *		could be used if you were querying EEM_Tickets (because Datetime is directly related to tickets)
689
-     *		Also, by default all the where conditions are AND'd together.
689
+	 *		Also, by default all the where conditions are AND'd together.
690 690
 	 *		To override this, add an array key 'OR' (or 'AND') and the array to be OR'd together
691 691
 	 *		eg: array('OR'=>array('TXN_ID' => 23 , 'TXN_timestamp__>' => 345678912))
692 692
 	 *		becomes
@@ -701,17 +701,17 @@  discard block
 block discarded – undo
701 701
 	 *		eg array('OR'=>array('NOT'=>array('TXN_total' => 50, 'TXN_paid'=>23)),AND=>array('TXN_ID'=>1,'STS_ID'=>'TIN')
702 702
 	 *		becomes
703 703
 	 *		SQL >> "...where ! (TXN_total =50 OR TXN_paid =23) AND TXN_ID=1 AND STS_ID='TIN'"
704
-     *		They can be nested indefinitely.
704
+	 *		They can be nested indefinitely.
705 705
 	 *		eg: array('OR'=>array('TXN_total' => 23, 'NOT'=> array( 'TXN_timestamp'=> 345678912, 'AND'=>array('TXN_paid' => 53, 'STS_ID' => 'TIN'))))
706 706
 	 *		becomes
707 707
 	 *		SQL >> "...WHERE TXN_total = 23 OR ! (TXN_timestamp = 345678912 OR (TXN_paid = 53 AND STS_ID = 'TIN'))..."
708
-     *		GOTCHA:
708
+	 *		GOTCHA:
709 709
 	 *		because this is an array, array keys must be unique, making it impossible to place two or more where conditions applying to the same field.
710 710
 	 *		eg: array('PAY_timestamp'=>array('>',$start_date),'PAY_timestamp'=>array('<',$end_date),'PAY_timestamp'=>array('!=',$special_date)),
711 711
 	 *		as PHP enforces that the array keys must be unique, thus removing the first two array entries with key 'PAY_timestamp'.
712 712
 	 *		becomes
713 713
 	 *		SQL >> "PAY_timestamp !=  4234232", ignoring the first two PAY_timestamp conditions).
714
-     *		To overcome this, you can add a '*' character to the end of the field's name, followed by anything.
714
+	 *		To overcome this, you can add a '*' character to the end of the field's name, followed by anything.
715 715
 	 *		These will be removed when generating the SQL string, but allow for the array keys to be unique.
716 716
 	 *		eg: you could rewrite the previous query as:
717 717
 	 *		array('PAY_timestamp'=>array('>',$start_date),'PAY_timestamp*1st'=>array('<',$end_date),'PAY_timestamp*2nd'=>array('!=',$special_date))
@@ -744,7 +744,7 @@  discard block
 block discarded – undo
744 744
 	 *		You will probably only want to do this in hopes of increasing efficiency, as related models which belongs to the current model
745 745
 	 *		(ie, the current model has a foreign key to them, like how Registration belongs to Attendee) can be cached in order
746 746
 	 *		to avoid future queries
747
-     *	@var string $default_where_conditions can be set to 'none', 'this_model_only', 'other_models_only', or 'all'. set this to 'none' to disable all default where conditions. Eg, usually soft-deleted objects are filtered-out
747
+	 *	@var string $default_where_conditions can be set to 'none', 'this_model_only', 'other_models_only', or 'all'. set this to 'none' to disable all default where conditions. Eg, usually soft-deleted objects are filtered-out
748 748
 	 *		if you want to include them, set this query param to 'none'. If you want to ONLY disable THIS model's default where conditions
749 749
 	 *		set it to 'other_models_only'. If you only want this model's default where conditions added to the query, use 'this_model_only'.
750 750
 	 *		If you want to use all default where conditions (default), set to 'all'.
@@ -1014,7 +1014,6 @@  discard block
 block discarded – undo
1014 1014
 	/**
1015 1015
 	 * Gets a single item for this model from the DB, given the $query_params. Only returns a single class, not an array. If no item is found,
1016 1016
 	 * null is returned.
1017
-
1018 1017
 	 *
1019 1018
 *@param array $query_params like EEM_Base's $query_params variable.
1020 1019
 	 * @return EE_Base_Class|EE_Soft_Delete_Base_Class|NULL
@@ -1117,7 +1116,7 @@  discard block
 block discarded – undo
1117 1116
 	 *                                      can indicate just the columns you
1118 1117
 	 *                                      want and a single array indexed by
1119 1118
 	 *                                      the columns will be returned.
1120
- * @return EE_Base_Class|null|array()
1119
+	 * @return EE_Base_Class|null|array()
1121 1120
 	 * @throws EE_Error
1122 1121
 	 */
1123 1122
 	public function previous( $current_field_value, $field_to_order_by = null, $query_params = array(), $columns_to_select = null ) {
@@ -1765,7 +1764,7 @@  discard block
 block discarded – undo
1765 1764
 				//make sure there's no related objects blocking its deletion (if we're checking)
1766 1765
 				if (
1767 1766
 					$allow_blocking
1768
-				    && $this->delete_is_blocked_by_related_models(
1767
+					&& $this->delete_is_blocked_by_related_models(
1769 1768
 						$delete_object[ $primary_table->get_fully_qualified_pk_column() ]
1770 1769
 					)
1771 1770
 				) {
@@ -1813,8 +1812,8 @@  discard block
 block discarded – undo
1813 1812
 				foreach($fields as $cpk_field){
1814 1813
 					if ( $cpk_field instanceof EE_Model_Field_Base ){
1815 1814
 						$values_for_each_cpk_for_a_row[] = $cpk_field->get_qualified_column()
1816
-						                                   . "="
1817
-						                                   . $delete_object[ $cpk_field->get_qualified_column() ];
1815
+														   . "="
1816
+														   . $delete_object[ $cpk_field->get_qualified_column() ];
1818 1817
 					}
1819 1818
 				}
1820 1819
 				$ways_to_identify_a_row[] = "(".implode(" AND ",$values_for_each_cpk_for_a_row).")";
@@ -2930,8 +2929,8 @@  discard block
 block discarded – undo
2930 2929
 		}
2931 2930
 		//if 'order_by' wasn't set, maybe they are just using 'order' on its own?
2932 2931
 		if ( ! array_key_exists( 'order_by', $query_params )
2933
-		     && array_key_exists( 'order', $query_params )
2934
-		     && ! empty( $query_params['order'] )
2932
+			 && array_key_exists( 'order', $query_params )
2933
+			 && ! empty( $query_params['order'] )
2935 2934
 		) {
2936 2935
 			$pk_field = $this->get_primary_key_field();
2937 2936
 			$order = $this->_extract_order( $query_params['order'] );
@@ -4469,7 +4468,7 @@  discard block
 block discarded – undo
4469 4468
 				$model_object = $this->get_one_by_ID( $base_class_obj_or_id );
4470 4469
 			} else if (
4471 4470
 				$primary_key_field instanceof EE_Primary_Key_String_Field
4472
-			    && is_string( $base_class_obj_or_id )
4471
+				&& is_string( $base_class_obj_or_id )
4473 4472
 			) {
4474 4473
 				// assume its a string representation of the object
4475 4474
 				$model_object = $this->get_one_by_ID( $base_class_obj_or_id );
Please login to merge, or discard this patch.
Spacing   +975 added lines, -975 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
@@ -243,7 +243,7 @@  discard block
 block discarded – undo
243 243
 	 * Flag indicating whether this model has a primary key or not
244 244
 	 * @var boolean
245 245
 	 */
246
-	protected $_has_primary_key_field=null;
246
+	protected $_has_primary_key_field = null;
247 247
 
248 248
 	/**
249 249
 	 * Whether or not this model is based off a table in WP core only (CPTs should set
@@ -305,19 +305,19 @@  discard block
 block discarded – undo
305 305
 	 * operators that work like 'BETWEEN'.  Typically used for datetime calculations, i.e. "BETWEEN '12-1-2011' AND '12-31-2012'"
306 306
 	 * @var array
307 307
 	 */
308
-	protected $_between_style_operators = array( 'BETWEEN' );
308
+	protected $_between_style_operators = array('BETWEEN');
309 309
 
310 310
 	/**
311 311
 	 * operators that are used for handling NUll and !NULL queries.  Typically used for when checking if a row exists on a join table.
312 312
 	 * @var array
313 313
 	 */
314
-	protected $_null_style_operators = array( 'IS NOT NULL', 'IS NULL');
314
+	protected $_null_style_operators = array('IS NOT NULL', 'IS NULL');
315 315
 
316 316
 	/**
317 317
 	 * Allowed values for $query_params['order'] for ordering in queries
318 318
 	 * @var array
319 319
 	 */
320
-	protected $_allowed_order_values = array('asc','desc','ASC','DESC');
320
+	protected $_allowed_order_values = array('asc', 'desc', 'ASC', 'DESC');
321 321
 
322 322
 	/**
323 323
 	 * When these are keys in a WHERE or HAVING clause, they are handled much differently
@@ -331,13 +331,13 @@  discard block
 block discarded – undo
331 331
 	 * 'where', but 'where' clauses are so common that we thought we'd omit it
332 332
 	 * @var array
333 333
 	 */
334
-	private $_allowed_query_params = array(0, 'limit','order_by','group_by','having','force_join','order','on_join_limit','default_where_conditions', 'caps');
334
+	private $_allowed_query_params = array(0, 'limit', 'order_by', 'group_by', 'having', 'force_join', 'order', 'on_join_limit', 'default_where_conditions', 'caps');
335 335
 
336 336
 	/**
337 337
 	 * All the data types that can be used in $wpdb->prepare statements.
338 338
 	 * @var array
339 339
 	 */
340
-	private $_valid_wpdb_data_types = array('%d','%s','%f');
340
+	private $_valid_wpdb_data_types = array('%d', '%s', '%f');
341 341
 
342 342
 	/**
343 343
 	 * 	EE_Registry Object
@@ -370,17 +370,17 @@  discard block
 block discarded – undo
370 370
 	/**
371 371
 	 * constant used to show EEM_Base has not yet verified the db on this http request
372 372
 	 */
373
-	const db_verified_none 		= 0;
373
+	const db_verified_none = 0;
374 374
 	/**
375 375
 	 * constant used to show EEM_Base has verified the EE core db on this http request,
376 376
 	 * but not the addons' dbs
377 377
 	 */
378
-	const db_verified_core 		= 1;
378
+	const db_verified_core = 1;
379 379
 	/**
380 380
 	 * constant used to show EEM_Base has verified the addons' dbs (and implicitly
381 381
 	 * the EE core db too)
382 382
 	 */
383
-	const db_verified_addons 	= 2;
383
+	const db_verified_addons = 2;
384 384
 
385 385
 	/**
386 386
 	 * indicates whether an EEM_Base child has already re-verified the DB
@@ -411,13 +411,13 @@  discard block
 block discarded – undo
411 411
 	 * @param null $timezone
412 412
 	 * @throws \EE_Error
413 413
 	 */
414
-	protected function __construct( $timezone = NULL ){
414
+	protected function __construct($timezone = NULL) {
415 415
 		// check that the model has not been loaded too soon
416
-		if ( ! did_action( 'AHEE__EE_System__load_espresso_addons' )) {
417
-			throw new EE_Error (
416
+		if ( ! did_action('AHEE__EE_System__load_espresso_addons')) {
417
+			throw new EE_Error(
418 418
 				sprintf(
419
-					__( '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' ),
420
-					get_class( $this )
419
+					__('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'),
420
+					get_class($this)
421 421
 				)
422 422
 			);
423 423
 		}
@@ -425,7 +425,7 @@  discard block
 block discarded – undo
425 425
 		/**
426 426
 		 * Set blogid for models to current blog. However we ONLY do this if $_model_query_blog_id is not already set.
427 427
 		 */
428
-		if ( empty( EEM_Base::$_model_query_blog_id ) ) {
428
+		if (empty(EEM_Base::$_model_query_blog_id)) {
429 429
 			EEM_Base::set_model_query_blog_id();
430 430
 		}
431 431
 
@@ -434,11 +434,11 @@  discard block
 block discarded – undo
434 434
 		 * just use EE_Register_Model_Extension
435 435
 		 * @var EE_Table_Base[] $_tables
436 436
 		 */
437
-		$this->_tables = apply_filters( 'FHEE__'.get_class($this).'__construct__tables', $this->_tables );
438
-		foreach($this->_tables as $table_alias => $table_obj){
437
+		$this->_tables = apply_filters('FHEE__'.get_class($this).'__construct__tables', $this->_tables);
438
+		foreach ($this->_tables as $table_alias => $table_obj) {
439 439
 			/** @var $table_obj EE_Table_Base */
440 440
 			$table_obj->_construct_finalize_with_alias($table_alias);
441
-			if( $table_obj instanceof EE_Secondary_Table ){
441
+			if ($table_obj instanceof EE_Secondary_Table) {
442 442
 				/** @var $table_obj EE_Secondary_Table */
443 443
 				$table_obj->_construct_finalize_set_table_to_join_with($this->_get_main_table());
444 444
 			}
@@ -448,54 +448,54 @@  discard block
 block discarded – undo
448 448
 		 * EE_Register_Model_Extension
449 449
 		 * @param EE_Model_Field_Base[] $_fields
450 450
 		 */
451
-		$this->_fields = apply_filters('FHEE__'.get_class($this).'__construct__fields',$this->_fields);
451
+		$this->_fields = apply_filters('FHEE__'.get_class($this).'__construct__fields', $this->_fields);
452 452
 		$this->_invalidate_field_caches();
453
-		foreach($this->_fields as $table_alias => $fields_for_table){
454
-			if ( ! array_key_exists( $table_alias, $this->_tables )){
455
-				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)));
453
+		foreach ($this->_fields as $table_alias => $fields_for_table) {
454
+			if ( ! array_key_exists($table_alias, $this->_tables)) {
455
+				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)));
456 456
 			}
457
-			foreach($fields_for_table as $field_name => $field_obj){
457
+			foreach ($fields_for_table as $field_name => $field_obj) {
458 458
 				/** @var $field_obj EE_Model_Field_Base | EE_Primary_Key_Field_Base */
459 459
 				//primary key field base has a slightly different _construct_finalize
460 460
 				/** @var $field_obj EE_Model_Field_Base */
461
-				$field_obj->_construct_finalize( $table_alias, $field_name, $this->get_this_model_name() );
461
+				$field_obj->_construct_finalize($table_alias, $field_name, $this->get_this_model_name());
462 462
 			}
463 463
 		}
464 464
 
465 465
 		// everything is related to Extra_Meta
466
-		if( get_class($this) !== 'EEM_Extra_Meta'){
466
+		if (get_class($this) !== 'EEM_Extra_Meta') {
467 467
 			//make extra meta related to everything, but don't block deleting things just
468 468
 			//because they have related extra meta info. For now just orphan those extra meta
469 469
 			//in the future we should automatically delete them
470
-			$this->_model_relations['Extra_Meta'] = new EE_Has_Many_Any_Relation( FALSE );
470
+			$this->_model_relations['Extra_Meta'] = new EE_Has_Many_Any_Relation(FALSE);
471 471
 		}
472 472
 		//and change logs
473
-		if( get_class( $this) !==  'EEM_Change_Log' ) {
474
-			$this->_model_relations[ 'Change_Log' ] = new EE_Has_Many_Any_Relation( FALSE );
473
+		if (get_class($this) !== 'EEM_Change_Log') {
474
+			$this->_model_relations['Change_Log'] = new EE_Has_Many_Any_Relation(FALSE);
475 475
 		}
476 476
 		/**
477 477
 		 * Filters the list of relations on a model. It is best to NOT use this directly and instead just use
478 478
 		 * EE_Register_Model_Extension
479 479
 		 * @param EE_Model_Relation_Base[] $_model_relations
480 480
 		 */
481
-		$this->_model_relations = apply_filters('FHEE__'.get_class($this).'__construct__model_relations',$this->_model_relations);
482
-		foreach($this->_model_relations as $model_name => $relation_obj){
481
+		$this->_model_relations = apply_filters('FHEE__'.get_class($this).'__construct__model_relations', $this->_model_relations);
482
+		foreach ($this->_model_relations as $model_name => $relation_obj) {
483 483
 			/** @var $relation_obj EE_Model_Relation_Base */
484 484
 			$relation_obj->_construct_finalize_set_models($this->get_this_model_name(), $model_name);
485 485
 		}
486
-		foreach($this->_indexes as $index_name => $index_obj){
486
+		foreach ($this->_indexes as $index_name => $index_obj) {
487 487
 			/** @var $index_obj EE_Index */
488 488
 			$index_obj->_construct_finalize($index_name, $this->get_this_model_name());
489 489
 		}
490 490
 
491 491
 		$this->set_timezone($timezone);
492 492
 		//finalize default where condition strategy, or set default
493
-		if( ! $this->_default_where_conditions_strategy){
493
+		if ( ! $this->_default_where_conditions_strategy) {
494 494
 			//nothing was set during child constructor, so set default
495 495
 			$this->_default_where_conditions_strategy = new EE_Default_Where_Conditions();
496 496
 		}
497 497
 		$this->_default_where_conditions_strategy->_finalize_construct($this);
498
-		if( ! $this->_minimum_where_conditions_strategy){
498
+		if ( ! $this->_minimum_where_conditions_strategy) {
499 499
 			//nothing was set during child constructor, so set default
500 500
 			$this->_minimum_where_conditions_strategy = new EE_Default_Where_Conditions();
501 501
 		}
@@ -503,14 +503,14 @@  discard block
 block discarded – undo
503 503
 
504 504
 		//if the cap slug hasn't been set, and we haven't set it to false on purpose
505 505
 		//to indicate to NOT set it, set it to the logical default
506
-		if( $this->_caps_slug === null ) {
507
-			$this->_caps_slug = EEH_Inflector::pluralize_and_lower( $this->get_this_model_name() );
506
+		if ($this->_caps_slug === null) {
507
+			$this->_caps_slug = EEH_Inflector::pluralize_and_lower($this->get_this_model_name());
508 508
 		}
509 509
 		//initialize the standard cap restriction generators if none were specified by the child constructor
510
-		if( $this->_cap_restriction_generators !== false ){
511
-			foreach( $this->cap_contexts_to_cap_action_map() as $cap_context => $action ){
512
-				if( ! isset( $this->_cap_restriction_generators[ $cap_context ] ) ) {
513
-					$this->_cap_restriction_generators[ $cap_context ] = apply_filters(
510
+		if ($this->_cap_restriction_generators !== false) {
511
+			foreach ($this->cap_contexts_to_cap_action_map() as $cap_context => $action) {
512
+				if ( ! isset($this->_cap_restriction_generators[$cap_context])) {
513
+					$this->_cap_restriction_generators[$cap_context] = apply_filters(
514 514
 						'FHEE__EEM_Base___construct__standard_cap_restriction_generator',
515 515
 						new EE_Restriction_Generator_Protected(),
516 516
 						$cap_context,
@@ -520,23 +520,23 @@  discard block
 block discarded – undo
520 520
 			}
521 521
 		}
522 522
 		//if there are cap restriction generators, use them to make the default cap restrictions
523
-		if( $this->_cap_restriction_generators !== false ){
524
-			foreach( $this->_cap_restriction_generators as $context => $generator_object ) {
525
-				if( ! $generator_object ){
523
+		if ($this->_cap_restriction_generators !== false) {
524
+			foreach ($this->_cap_restriction_generators as $context => $generator_object) {
525
+				if ( ! $generator_object) {
526 526
 					continue;
527 527
 				}
528
-				if( ! $generator_object instanceof EE_Restriction_Generator_Base ){
528
+				if ( ! $generator_object instanceof EE_Restriction_Generator_Base) {
529 529
 					throw new EE_Error(
530 530
 						sprintf(
531
-							__( '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' ),
531
+							__('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'),
532 532
 							$context,
533 533
 							$this->get_this_model_name()
534 534
 						)
535 535
 					);
536 536
 				}
537
-				$action = $this->cap_action_for_context( $context );
538
-				if( ! $generator_object->construction_finalized() ){
539
-					$generator_object->_construct_finalize( $this, $action );
537
+				$action = $this->cap_action_for_context($context);
538
+				if ( ! $generator_object->construction_finalized()) {
539
+					$generator_object->_construct_finalize($this, $action);
540 540
 				}
541 541
 
542 542
 			}
@@ -550,11 +550,11 @@  discard block
 block discarded – undo
550 550
 	 * @param string $context one of EEM_Base::valid_cap_contexts()
551 551
 	 * @return EE_Default_Where_Conditions[]
552 552
 	 */
553
-	protected function _generate_cap_restrictions( $context ){
554
-		if( isset( $this->_cap_restriction_generators[ $context ] ) &&
555
-				$this->_cap_restriction_generators[ $context ] instanceof EE_Restriction_Generator_Base ) {
556
-			return $this->_cap_restriction_generators[ $context ]->generate_restrictions();
557
-		}else{
553
+	protected function _generate_cap_restrictions($context) {
554
+		if (isset($this->_cap_restriction_generators[$context]) &&
555
+				$this->_cap_restriction_generators[$context] instanceof EE_Restriction_Generator_Base) {
556
+			return $this->_cap_restriction_generators[$context]->generate_restrictions();
557
+		} else {
558 558
 			return array();
559 559
 		}
560 560
 	}
@@ -566,7 +566,7 @@  discard block
 block discarded – undo
566 566
 	 * @param int $blog_id  If provided then will set the blog_id for the models to this id.  If not provided then the
567 567
 	 *                      value for get_current_blog_id() will be used.
568 568
 	 */
569
-	public static function set_model_query_blog_id( $blog_id = 0 ) {
569
+	public static function set_model_query_blog_id($blog_id = 0) {
570 570
 		EEM_Base::$_model_query_blog_id = $blog_id > 0 ? (int) $blog_id : get_current_blog_id();
571 571
 	}
572 572
 
@@ -591,16 +591,16 @@  discard block
 block discarded – undo
591 591
 	 *		@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)
592 592
 	 *		@return static (as in the concrete child class)
593 593
 	 */
594
-	public static function instance( $timezone = NULL ){
594
+	public static function instance($timezone = NULL) {
595 595
 
596 596
 		// check if instance of Espresso_model already exists
597 597
 		if ( ! static::$_instance instanceof static) {
598 598
 			// instantiate Espresso_model
599
-			static::$_instance = new static( $timezone );
599
+			static::$_instance = new static($timezone);
600 600
 		}
601 601
 
602 602
 		//we might have a timezone set, let set_timezone decide what to do with it
603
-		static::$_instance->set_timezone( $timezone );
603
+		static::$_instance->set_timezone($timezone);
604 604
 
605 605
 		// Espresso_model object
606 606
 		return static::$_instance;
@@ -613,11 +613,11 @@  discard block
 block discarded – undo
613 613
 	 * @param null | string $timezone
614 614
 	 * @return static
615 615
 	 */
616
-	public static function reset(  $timezone = NULL ){
617
-		if ( ! is_null( static::$_instance ) ) {
616
+	public static function reset($timezone = NULL) {
617
+		if ( ! is_null(static::$_instance)) {
618 618
 			static::$_instance = null;
619 619
 
620
-			return self::instance( $timezone );
620
+			return self::instance($timezone);
621 621
 		}
622 622
 		return null;
623 623
 	}
@@ -631,19 +631,19 @@  discard block
 block discarded – undo
631 631
 	 * @return array
632 632
 	 * @throws \EE_Error
633 633
 	 */
634
-	 public function status_array( $translated = FALSE ) {
635
-		 if ( ! array_key_exists( 'Status', $this->_model_relations ) ) {
634
+	 public function status_array($translated = FALSE) {
635
+		 if ( ! array_key_exists('Status', $this->_model_relations)) {
636 636
 			 return array();
637 637
 		 }
638 638
 		 $model_name = $this->get_this_model_name();
639
-		 $status_type = str_replace( ' ', '_', strtolower( str_replace( '_', ' ', $model_name ) ) );
640
-		 $stati = EEM_Status::instance()->get_all( array( array( 'STS_type' => $status_type ) ) );
639
+		 $status_type = str_replace(' ', '_', strtolower(str_replace('_', ' ', $model_name)));
640
+		 $stati = EEM_Status::instance()->get_all(array(array('STS_type' => $status_type)));
641 641
 		 $status_array = array();
642
-		 foreach ( $stati as $status ) {
643
-			 $status_array[ $status->ID() ] = $status->get( 'STS_code' );
642
+		 foreach ($stati as $status) {
643
+			 $status_array[$status->ID()] = $status->get('STS_code');
644 644
 		 }
645 645
 		 return $translated
646
-			 ? EEM_Status::instance()->localized_status( $status_array, false, 'sentence' )
646
+			 ? EEM_Status::instance()->localized_status($status_array, false, 'sentence')
647 647
 			 : $status_array;
648 648
 	 }
649 649
 
@@ -776,10 +776,10 @@  discard block
 block discarded – undo
776 776
 	 *		));
777 777
 	 * @throws \EE_Error
778 778
 	 */
779
-	public function get_all($query_params = array()){
780
-		if( isset( $query_params[ 'limit' ] )
781
-			&& ! isset( $query_params[ 'group_by' ] ) ) {
782
-			$query_params[ 'group_by' ] = array_keys( $this->get_combined_primary_key_fields() );
779
+	public function get_all($query_params = array()) {
780
+		if (isset($query_params['limit'])
781
+			&& ! isset($query_params['group_by'])) {
782
+			$query_params['group_by'] = array_keys($this->get_combined_primary_key_fields());
783 783
 		}
784 784
 		return $this->_create_objects($this->_get_all_wpdb_results($query_params, ARRAY_A, NULL));
785 785
 	}
@@ -790,10 +790,10 @@  discard block
 block discarded – undo
790 790
 	 * @param array $query_params @see EEM_Base::get_all()
791 791
 	 * @return array like EEM_Base::get_all
792 792
 	 */
793
-	public function alter_query_params_to_only_include_mine( $query_params = array() ) {
793
+	public function alter_query_params_to_only_include_mine($query_params = array()) {
794 794
 		$wp_user_field_name = $this->wp_user_field_name();
795
-		if( $wp_user_field_name ){
796
-			$query_params[0][ $wp_user_field_name ] = get_current_user_id();
795
+		if ($wp_user_field_name) {
796
+			$query_params[0][$wp_user_field_name] = get_current_user_id();
797 797
 		}
798 798
 		return $query_params;
799 799
 	}
@@ -806,19 +806,19 @@  discard block
 block discarded – undo
806 806
 	 * foreign key to the WP_User table
807 807
 	 */
808 808
 	public function wp_user_field_name() {
809
-		try{
810
-			if( ! empty( $this->_model_chain_to_wp_user ) ) {
811
-				$models_to_follow_to_wp_users = explode( '.', $this->_model_chain_to_wp_user );
812
-				$last_model_name = end( $models_to_follow_to_wp_users );
813
-				$model_with_fk_to_wp_users = EE_Registry::instance()->load_model( $last_model_name );
814
-				$model_chain_to_wp_user = $this->_model_chain_to_wp_user . '.';
815
-			}else{
809
+		try {
810
+			if ( ! empty($this->_model_chain_to_wp_user)) {
811
+				$models_to_follow_to_wp_users = explode('.', $this->_model_chain_to_wp_user);
812
+				$last_model_name = end($models_to_follow_to_wp_users);
813
+				$model_with_fk_to_wp_users = EE_Registry::instance()->load_model($last_model_name);
814
+				$model_chain_to_wp_user = $this->_model_chain_to_wp_user.'.';
815
+			} else {
816 816
 				$model_with_fk_to_wp_users = $this;
817 817
 				$model_chain_to_wp_user = '';
818 818
 			}
819
-			$wp_user_field = $model_with_fk_to_wp_users->get_foreign_key_to( 'WP_User' );
820
-			return $model_chain_to_wp_user . $wp_user_field->get_name();
821
-		}catch( EE_Error $e ) {
819
+			$wp_user_field = $model_with_fk_to_wp_users->get_foreign_key_to('WP_User');
820
+			return $model_chain_to_wp_user.$wp_user_field->get_name();
821
+		} catch (EE_Error $e) {
822 822
 			return false;
823 823
 		}
824 824
 	}
@@ -832,7 +832,7 @@  discard block
 block discarded – undo
832 832
 	 * (or transiently-related model)
833 833
 	 * @return string
834 834
 	 */
835
-	public function model_chain_to_wp_user(){
835
+	public function model_chain_to_wp_user() {
836 836
 		return $this->_model_chain_to_wp_user;
837 837
 	}
838 838
 
@@ -844,13 +844,13 @@  discard block
 block discarded – undo
844 844
 	 * @return boolean
845 845
 	 */
846 846
 	public function is_owned() {
847
-		if( $this->model_chain_to_wp_user() ){
847
+		if ($this->model_chain_to_wp_user()) {
848 848
 			return true;
849
-		}else{
850
-			try{
851
-				$this->get_foreign_key_to( 'WP_User' );
849
+		} else {
850
+			try {
851
+				$this->get_foreign_key_to('WP_User');
852 852
 				return true;
853
-			}catch( EE_Error $e ){
853
+			} catch (EE_Error $e) {
854 854
 				return false;
855 855
 			}
856 856
 		}
@@ -872,17 +872,17 @@  discard block
 block discarded – undo
872 872
 	 * @return array | stdClass[] like results of $wpdb->get_results($sql,OBJECT), (ie, output type is OBJECT)
873 873
 	 * @throws \EE_Error
874 874
 	 */
875
-	protected function  _get_all_wpdb_results($query_params = array(), $output = ARRAY_A, $columns_to_select = null){
875
+	protected function  _get_all_wpdb_results($query_params = array(), $output = ARRAY_A, $columns_to_select = null) {
876 876
 		// remember the custom selections, if any, and type cast as array
877 877
 		// (unless $columns_to_select is an object, then just set as an empty array)
878 878
 		// Note: (array) 'some string' === array( 'some string' )
879
-		$this->_custom_selections = ! is_object( $columns_to_select ) ? (array) $columns_to_select : array();
880
-		$model_query_info = $this->_create_model_query_info_carrier( $query_params );
879
+		$this->_custom_selections = ! is_object($columns_to_select) ? (array) $columns_to_select : array();
880
+		$model_query_info = $this->_create_model_query_info_carrier($query_params);
881 881
 		$select_expressions = $columns_to_select !== null
882
-			? $this->_construct_select_from_input( $columns_to_select )
883
-			: $this->_construct_default_select_sql( $model_query_info );
884
-		$SQL = "SELECT $select_expressions " . $this->_construct_2nd_half_of_select_query( $model_query_info );
885
-		return $this->_do_wpdb_query( 'get_results', array( $SQL, $output ) );
882
+			? $this->_construct_select_from_input($columns_to_select)
883
+			: $this->_construct_default_select_sql($model_query_info);
884
+		$SQL = "SELECT $select_expressions ".$this->_construct_2nd_half_of_select_query($model_query_info);
885
+		return $this->_do_wpdb_query('get_results', array($SQL, $output));
886 886
 	}
887 887
 
888 888
 	/**
@@ -900,7 +900,7 @@  discard block
 block discarded – undo
900 900
 	 * @return array|stdClass[] like results of $wpdb->get_results($sql,OBJECT), (ie, output type is OBJECT)
901 901
 	 * @throws \EE_Error
902 902
 	 */
903
-	public function  get_all_wpdb_results($query_params = array(), $output = ARRAY_A, $columns_to_select = null){
903
+	public function  get_all_wpdb_results($query_params = array(), $output = ARRAY_A, $columns_to_select = null) {
904 904
 		return $this->_get_all_wpdb_results($query_params, $output, $columns_to_select);
905 905
 	}
906 906
 
@@ -912,12 +912,12 @@  discard block
 block discarded – undo
912 912
 	 * @throws EE_Error
913 913
 	 * @return string
914 914
 	 */
915
-	private function _construct_select_from_input($columns_to_select){
916
-		if(is_array($columns_to_select)){
915
+	private function _construct_select_from_input($columns_to_select) {
916
+		if (is_array($columns_to_select)) {
917 917
 			$select_sql_array = array();
918 918
 
919
-			foreach($columns_to_select as $alias => $selection_and_datatype){
920
-				if( ! is_array($selection_and_datatype) || ! isset($selection_and_datatype[1])){
919
+			foreach ($columns_to_select as $alias => $selection_and_datatype) {
920
+				if ( ! is_array($selection_and_datatype) || ! isset($selection_and_datatype[1])) {
921 921
 					throw new EE_Error(
922 922
 						sprintf(
923 923
 							__(
@@ -929,24 +929,24 @@  discard block
 block discarded – undo
929 929
 						)
930 930
 					);
931 931
 				}
932
-				if( ! in_array( $selection_and_datatype[1],$this->_valid_wpdb_data_types)){
932
+				if ( ! in_array($selection_and_datatype[1], $this->_valid_wpdb_data_types)) {
933 933
 					throw new EE_Error(
934 934
 						sprintf(
935 935
 							__(
936 936
 								"Datatype %s (for selection '%s' and alias '%s') is not a valid wpdb datatype (eg %%s)",
937 937
 								"event_espresso"
938 938
 							),
939
-							$selection_and_datatype[ 1 ],
940
-							$selection_and_datatype[ 0 ],
939
+							$selection_and_datatype[1],
940
+							$selection_and_datatype[0],
941 941
 							$alias,
942
-							implode( ",", $this->_valid_wpdb_data_types )
942
+							implode(",", $this->_valid_wpdb_data_types)
943 943
 						)
944 944
 					);
945 945
 				}
946 946
 				$select_sql_array[] = "{$selection_and_datatype[0]} AS $alias";
947 947
 			}
948
-			$columns_to_select_string = implode(", ",$select_sql_array);
949
-		}else{
948
+			$columns_to_select_string = implode(", ", $select_sql_array);
949
+		} else {
950 950
 			$columns_to_select_string = $columns_to_select;
951 951
 		}
952 952
 		return $columns_to_select_string;
@@ -961,7 +961,7 @@  discard block
 block discarded – undo
961 961
 	 * @return string
962 962
 	 * @throws \EE_Error
963 963
 	 */
964
-	public function primary_key_name(){
964
+	public function primary_key_name() {
965 965
 		return $this->get_primary_key_field()->get_name();
966 966
 	}
967 967
 
@@ -973,14 +973,14 @@  discard block
 block discarded – undo
973 973
 	 * @param mixed $id int or string, depending on the type of the model's primary key
974 974
 	 * @return EE_Base_Class
975 975
 	 */
976
-	public function get_one_by_ID($id){
977
-		if( $this->get_from_entity_map( $id ) ){
978
-			return $this->get_from_entity_map( $id );
976
+	public function get_one_by_ID($id) {
977
+		if ($this->get_from_entity_map($id)) {
978
+			return $this->get_from_entity_map($id);
979 979
 		}
980 980
 		return $this->get_one(
981 981
 			$this->alter_query_params_to_restrict_by_ID(
982 982
 				$id,
983
-				array( 'default_where_conditions' => 'minimum' )
983
+				array('default_where_conditions' => 'minimum')
984 984
 			)
985 985
 		);
986 986
 	}
@@ -996,15 +996,15 @@  discard block
 block discarded – undo
996 996
 	 * @return array of normal query params, @see EEM_Base::get_all
997 997
 	 * @throws \EE_Error
998 998
 	 */
999
-	public function alter_query_params_to_restrict_by_ID( $id, $query_params = array() ) {
1000
-		if( ! isset( $query_params[ 0 ] ) ) {
1001
-			$query_params[ 0 ] = array();
999
+	public function alter_query_params_to_restrict_by_ID($id, $query_params = array()) {
1000
+		if ( ! isset($query_params[0])) {
1001
+			$query_params[0] = array();
1002 1002
 		}
1003
-		if( $this->has_primary_key_field ( ) ) {
1004
-			$query_params[ 0 ][ $this->primary_key_name() ] = $id ;
1005
-		}else{
1003
+		if ($this->has_primary_key_field( )) {
1004
+			$query_params[0][$this->primary_key_name()] = $id;
1005
+		} else {
1006 1006
 			//no primary key, so the $id must be from the get_index_primary_key_string()
1007
-			$query_params[0] = array_replace_recursive( $query_params[ 0 ], $this->parse_index_primary_key_string( $id ) );
1007
+			$query_params[0] = array_replace_recursive($query_params[0], $this->parse_index_primary_key_string($id));
1008 1008
 		}
1009 1009
 		return $query_params;
1010 1010
 	}
@@ -1020,16 +1020,16 @@  discard block
 block discarded – undo
1020 1020
 	 * @return EE_Base_Class|EE_Soft_Delete_Base_Class|NULL
1021 1021
 	 * @throws \EE_Error
1022 1022
 	 */
1023
-	public function get_one($query_params = array()){
1024
-		if( ! is_array( $query_params ) ){
1025
-			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' );
1023
+	public function get_one($query_params = array()) {
1024
+		if ( ! is_array($query_params)) {
1025
+			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');
1026 1026
 			$query_params = array();
1027 1027
 		}
1028 1028
 		$query_params['limit'] = 1;
1029 1029
 		$items = $this->get_all($query_params);
1030
-		if(empty($items)){
1030
+		if (empty($items)) {
1031 1031
 			return null;
1032
-		}else{
1032
+		} else {
1033 1033
 			return array_shift($items);
1034 1034
 		}
1035 1035
 	}
@@ -1052,8 +1052,8 @@  discard block
 block discarded – undo
1052 1052
 	 * @return EE_Base_Class[]|array
1053 1053
 	 * @throws \EE_Error
1054 1054
 	 */
1055
-	public function next_x( $current_field_value, $field_to_order_by = null, $limit = 1, $query_params = array(), $columns_to_select = null ) {
1056
-		return $this->_get_consecutive( $current_field_value, '>', $field_to_order_by, $limit, $query_params, $columns_to_select );
1055
+	public function next_x($current_field_value, $field_to_order_by = null, $limit = 1, $query_params = array(), $columns_to_select = null) {
1056
+		return $this->_get_consecutive($current_field_value, '>', $field_to_order_by, $limit, $query_params, $columns_to_select);
1057 1057
 	}
1058 1058
 
1059 1059
 
@@ -1074,8 +1074,8 @@  discard block
 block discarded – undo
1074 1074
 	 * @return EE_Base_Class[]|array
1075 1075
 	 * @throws \EE_Error
1076 1076
 	 */
1077
-	public function previous_x( $current_field_value, $field_to_order_by = null, $limit = 1, $query_params = array(), $columns_to_select = null ) {
1078
-		return $this->_get_consecutive( $current_field_value, '<', $field_to_order_by, $limit, $query_params, $columns_to_select );
1077
+	public function previous_x($current_field_value, $field_to_order_by = null, $limit = 1, $query_params = array(), $columns_to_select = null) {
1078
+		return $this->_get_consecutive($current_field_value, '<', $field_to_order_by, $limit, $query_params, $columns_to_select);
1079 1079
 	}
1080 1080
 
1081 1081
 
@@ -1096,9 +1096,9 @@  discard block
 block discarded – undo
1096 1096
 	 * @return EE_Base_Class|null|array()
1097 1097
 	 * @throws \EE_Error
1098 1098
 	 */
1099
-	public function next( $current_field_value, $field_to_order_by = null, $query_params = array(), $columns_to_select = null ) {
1100
-		$results = $this->_get_consecutive( $current_field_value, '>', $field_to_order_by, 1, $query_params, $columns_to_select );
1101
-		return empty( $results ) ? null : reset( $results );
1099
+	public function next($current_field_value, $field_to_order_by = null, $query_params = array(), $columns_to_select = null) {
1100
+		$results = $this->_get_consecutive($current_field_value, '>', $field_to_order_by, 1, $query_params, $columns_to_select);
1101
+		return empty($results) ? null : reset($results);
1102 1102
 	}
1103 1103
 
1104 1104
 
@@ -1120,9 +1120,9 @@  discard block
 block discarded – undo
1120 1120
  * @return EE_Base_Class|null|array()
1121 1121
 	 * @throws EE_Error
1122 1122
 	 */
1123
-	public function previous( $current_field_value, $field_to_order_by = null, $query_params = array(), $columns_to_select = null ) {
1124
-		$results = $this->_get_consecutive( $current_field_value, '<', $field_to_order_by, 1, $query_params, $columns_to_select );
1125
-		return empty( $results ) ? null : reset( $results );
1123
+	public function previous($current_field_value, $field_to_order_by = null, $query_params = array(), $columns_to_select = null) {
1124
+		$results = $this->_get_consecutive($current_field_value, '<', $field_to_order_by, 1, $query_params, $columns_to_select);
1125
+		return empty($results) ? null : reset($results);
1126 1126
 	}
1127 1127
 
1128 1128
 
@@ -1143,42 +1143,42 @@  discard block
 block discarded – undo
1143 1143
 	 * @return EE_Base_Class[]|array
1144 1144
 	 * @throws EE_Error
1145 1145
 	 */
1146
-	protected function _get_consecutive( $current_field_value, $operand = '>', $field_to_order_by = null, $limit = 1, $query_params = array(), $columns_to_select = null ) {
1146
+	protected function _get_consecutive($current_field_value, $operand = '>', $field_to_order_by = null, $limit = 1, $query_params = array(), $columns_to_select = null) {
1147 1147
 		//if $field_to_order_by is empty then let's assume we're ordering by the primary key.
1148
-		if ( empty( $field_to_order_by ) ) {
1149
-			if ( $this->has_primary_key_field() ) {
1148
+		if (empty($field_to_order_by)) {
1149
+			if ($this->has_primary_key_field()) {
1150 1150
 				$field_to_order_by = $this->get_primary_key_field()->get_name();
1151 1151
 			} else {
1152 1152
 
1153
-				if ( WP_DEBUG ) {
1154
-					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' ) );
1153
+				if (WP_DEBUG) {
1154
+					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'));
1155 1155
 				}
1156
-				EE_Error::add_error( __('There was an error with the query.', 'event_espresso') );
1156
+				EE_Error::add_error(__('There was an error with the query.', 'event_espresso'));
1157 1157
 				return array();
1158 1158
 			}
1159 1159
 		}
1160 1160
 
1161
-		if( ! is_array( $query_params ) ){
1162
-			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' );
1161
+		if ( ! is_array($query_params)) {
1162
+			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');
1163 1163
 			$query_params = array();
1164 1164
 		}
1165 1165
 
1166 1166
 		//let's add the where query param for consecutive look up.
1167
-		$query_params[0][ $field_to_order_by ] = array( $operand, $current_field_value );
1167
+		$query_params[0][$field_to_order_by] = array($operand, $current_field_value);
1168 1168
 		$query_params['limit'] = $limit;
1169 1169
 
1170 1170
 		//set direction
1171
-		$incoming_orderby = isset( $query_params['order_by'] ) ? (array)$query_params['order_by'] : array();
1171
+		$incoming_orderby = isset($query_params['order_by']) ? (array) $query_params['order_by'] : array();
1172 1172
 		$query_params['order_by'] = $operand === '>'
1173
-			? array( $field_to_order_by => 'ASC' ) + $incoming_orderby
1174
-			: array( $field_to_order_by => 'DESC') + $incoming_orderby;
1173
+			? array($field_to_order_by => 'ASC') + $incoming_orderby
1174
+			: array($field_to_order_by => 'DESC') + $incoming_orderby;
1175 1175
 
1176 1176
 		//if $columns_to_select is empty then that means we're returning EE_Base_Class objects
1177
-		if ( empty( $columns_to_select ) ) {
1178
-			return $this->get_all( $query_params );
1177
+		if (empty($columns_to_select)) {
1178
+			return $this->get_all($query_params);
1179 1179
 		} else {
1180 1180
 			//getting just the fields
1181
-			return $this->_get_all_wpdb_results( $query_params, ARRAY_A, $columns_to_select );
1181
+			return $this->_get_all_wpdb_results($query_params, ARRAY_A, $columns_to_select);
1182 1182
 		}
1183 1183
 	}
1184 1184
 
@@ -1189,18 +1189,18 @@  discard block
 block discarded – undo
1189 1189
 	 * This sets the _timezone property after model object has been instantiated.
1190 1190
 	 * @param null | string $timezone valid PHP DateTimeZone timezone string
1191 1191
 	 */
1192
-	public function set_timezone( $timezone ) {
1193
-		if ( $timezone !== null ) {
1192
+	public function set_timezone($timezone) {
1193
+		if ($timezone !== null) {
1194 1194
 			$this->_timezone = $timezone;
1195 1195
 		}
1196 1196
 		//note we need to loop through relations and set the timezone on those objects as well.
1197
-		foreach ( $this->_model_relations as $relation ) {
1198
-			$relation->set_timezone( $timezone );
1197
+		foreach ($this->_model_relations as $relation) {
1198
+			$relation->set_timezone($timezone);
1199 1199
 		}
1200 1200
 		//and finally we do the same for any datetime fields
1201
-		foreach ( $this->_fields as $field ) {
1202
-			if ( $field instanceof EE_Datetime_Field ) {
1203
-				$field->set_timezone( $timezone );
1201
+		foreach ($this->_fields as $field) {
1202
+			if ($field instanceof EE_Datetime_Field) {
1203
+				$field->set_timezone($timezone);
1204 1204
 			}
1205 1205
 		}
1206 1206
 	}
@@ -1215,9 +1215,9 @@  discard block
 block discarded – undo
1215 1215
 	 */
1216 1216
 	public function get_timezone() {
1217 1217
 		//first validate if timezone is set.  If not, then let's set it be whatever is set on the model fields.
1218
-		if ( empty( $this->_timezone ) ) {
1219
-			foreach( $this->_fields as $field ) {
1220
-				if ( $field instanceof EE_Datetime_Field ) {
1218
+		if (empty($this->_timezone)) {
1219
+			foreach ($this->_fields as $field) {
1220
+				if ($field instanceof EE_Datetime_Field) {
1221 1221
 					$this->set_timezone($field->get_timezone());
1222 1222
 					break;
1223 1223
 				}
@@ -1225,8 +1225,8 @@  discard block
 block discarded – undo
1225 1225
 		}
1226 1226
 
1227 1227
 		//if timezone STILL empty then return the default timezone for the site.
1228
-		if ( empty( $this->_timezone ) ) {
1229
-			$this->set_timezone( EEH_DTT_Helper::get_timezone() );
1228
+		if (empty($this->_timezone)) {
1229
+			$this->set_timezone(EEH_DTT_Helper::get_timezone());
1230 1230
 		}
1231 1231
 		return $this->_timezone;
1232 1232
 	}
@@ -1244,19 +1244,19 @@  discard block
 block discarded – undo
1244 1244
 	 *
1245 1245
 	 * @return array formats in an array with the date format first, and the time format last.
1246 1246
 	 */
1247
-	public function get_formats_for( $field_name, $pretty = false ) {
1248
-		$field_settings = $this->field_settings_for( $field_name );
1247
+	public function get_formats_for($field_name, $pretty = false) {
1248
+		$field_settings = $this->field_settings_for($field_name);
1249 1249
 
1250 1250
 		//if not a valid EE_Datetime_Field then throw error
1251
-		if ( ! $field_settings instanceof EE_Datetime_Field ) {
1252
-			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 ) );
1251
+		if ( ! $field_settings instanceof EE_Datetime_Field) {
1252
+			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));
1253 1253
 		}
1254 1254
 
1255 1255
 		//while we are here, let's make sure the timezone internally in EEM_Base matches what is stored on
1256 1256
 		//the field.
1257 1257
 		$this->_timezone = $field_settings->get_timezone();
1258 1258
 
1259
-		return array( $field_settings->get_date_format( $pretty ), $field_settings->get_time_format( $pretty ) );
1259
+		return array($field_settings->get_date_format($pretty), $field_settings->get_time_format($pretty));
1260 1260
 	}
1261 1261
 
1262 1262
 
@@ -1280,25 +1280,25 @@  discard block
 block discarded – undo
1280 1280
 	 * @return int|string  If the given field_name is not of the EE_Datetime_Field type, then an EE_Error
1281 1281
 	 *                    	     exception is triggered.
1282 1282
 	 */
1283
-	public function current_time_for_query( $field_name, $timestamp = false, $what = 'both' ) {
1284
-		$formats = $this->get_formats_for( $field_name );
1283
+	public function current_time_for_query($field_name, $timestamp = false, $what = 'both') {
1284
+		$formats = $this->get_formats_for($field_name);
1285 1285
 
1286
-		$DateTime = new DateTime( "now", new DateTimeZone( $this->_timezone ) );
1286
+		$DateTime = new DateTime("now", new DateTimeZone($this->_timezone));
1287 1287
 
1288
-		if ( $timestamp ) {
1289
-			return $DateTime->format( 'U' );
1288
+		if ($timestamp) {
1289
+			return $DateTime->format('U');
1290 1290
 		}
1291 1291
 
1292 1292
 		//not returning timestamp, so return formatted string in timezone.
1293
-		switch( $what ) {
1293
+		switch ($what) {
1294 1294
 			case 'time' :
1295
-				return $DateTime->format( $formats[1] );
1295
+				return $DateTime->format($formats[1]);
1296 1296
 				break;
1297 1297
 			case 'date' :
1298
-				return $DateTime->format( $formats[0] );
1298
+				return $DateTime->format($formats[0]);
1299 1299
 				break;
1300 1300
 			default :
1301
-				return $DateTime->format( implode( ' ', $formats ) );
1301
+				return $DateTime->format(implode(' ', $formats));
1302 1302
 				break;
1303 1303
 		}
1304 1304
 	}
@@ -1320,17 +1320,17 @@  discard block
 block discarded – undo
1320 1320
 	 * @return DateTime
1321 1321
 	 * @throws \EE_Error
1322 1322
 	 */
1323
-	public function convert_datetime_for_query( $field_name, $timestring, $incoming_format, $timezone = '' ) {
1323
+	public function convert_datetime_for_query($field_name, $timestring, $incoming_format, $timezone = '') {
1324 1324
 
1325 1325
 		//just using this to ensure the timezone is set correctly internally
1326
-		$this->get_formats_for( $field_name );
1326
+		$this->get_formats_for($field_name);
1327 1327
 
1328 1328
 		//load EEH_DTT_Helper
1329
-		$set_timezone = empty( $timezone ) ? EEH_DTT_Helper::get_timezone() : $timezone;
1329
+		$set_timezone = empty($timezone) ? EEH_DTT_Helper::get_timezone() : $timezone;
1330 1330
 
1331
-		$incomingDateTime = date_create_from_format( $incoming_format, $timestring, new DateTimeZone( $set_timezone ) );
1331
+		$incomingDateTime = date_create_from_format($incoming_format, $timestring, new DateTimeZone($set_timezone));
1332 1332
 
1333
-		return $incomingDateTime->setTimezone( new DateTimeZone( $this->_timezone ) );
1333
+		return $incomingDateTime->setTimezone(new DateTimeZone($this->_timezone));
1334 1334
 	}
1335 1335
 
1336 1336
 
@@ -1340,7 +1340,7 @@  discard block
 block discarded – undo
1340 1340
 	 * Gets all the tables comprising this model. Array keys are the table aliases, and values are EE_Table objects
1341 1341
 	 * @return EE_Table_Base[]
1342 1342
 	 */
1343
-	public function get_tables(){
1343
+	public function get_tables() {
1344 1344
 		return $this->_tables;
1345 1345
 	}
1346 1346
 
@@ -1376,9 +1376,9 @@  discard block
 block discarded – undo
1376 1376
 	 * @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)
1377 1377
 	 * @throws \EE_Error
1378 1378
 	 */
1379
-	public function update($fields_n_values, $query_params, $keep_model_objs_in_sync = TRUE){
1380
-		if( ! is_array( $query_params ) ){
1381
-			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' );
1379
+	public function update($fields_n_values, $query_params, $keep_model_objs_in_sync = TRUE) {
1380
+		if ( ! is_array($query_params)) {
1381
+			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');
1382 1382
 			$query_params = array();
1383 1383
 		}
1384 1384
 		/**
@@ -1388,7 +1388,7 @@  discard block
 block discarded – undo
1388 1388
 		 * @param array $fields_n_values the updated fields and their new values
1389 1389
 		 * @param array $query_params @see EEM_Base::get_all()
1390 1390
 		 */
1391
-		do_action( 'AHEE__EEM_Base__update__begin',$this, $fields_n_values, $query_params );
1391
+		do_action('AHEE__EEM_Base__update__begin', $this, $fields_n_values, $query_params);
1392 1392
 		/**
1393 1393
 		 * Filters the fields about to be updated given the query parameters. You can provide the
1394 1394
 		 * $query_params to $this->get_all() to find exactly which records will be updated
@@ -1396,10 +1396,10 @@  discard block
 block discarded – undo
1396 1396
 		 * @param EEM_Base $model the model being queried
1397 1397
 		 * @param array $query_params see EEM_Base::get_all()
1398 1398
 		 */
1399
-		$fields_n_values = (array)apply_filters( 'FHEE__EEM_Base__update__fields_n_values', $fields_n_values, $this, $query_params );
1399
+		$fields_n_values = (array) apply_filters('FHEE__EEM_Base__update__fields_n_values', $fields_n_values, $this, $query_params);
1400 1400
 		//need to verify that, for any entry we want to update, there are entries in each secondary table.
1401 1401
 		//to do that, for each table, verify that it's PK isn't null.
1402
-		$tables= $this->get_tables();
1402
+		$tables = $this->get_tables();
1403 1403
 
1404 1404
 		//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
1405 1405
 		//NOTE: we should make this code more efficient by NOT querying twice
@@ -1409,29 +1409,29 @@  discard block
 block discarded – undo
1409 1409
 			//we want to make sure the default_where strategy is ignored
1410 1410
 			$this->_ignore_where_strategy = TRUE;
1411 1411
 			$wpdb_select_results = $this->_get_all_wpdb_results($query_params);
1412
-			foreach( $wpdb_select_results as $wpdb_result ){
1412
+			foreach ($wpdb_select_results as $wpdb_result) {
1413 1413
 				// type cast stdClass as array
1414
-				$wpdb_result = (array)$wpdb_result;
1414
+				$wpdb_result = (array) $wpdb_result;
1415 1415
 				//get the model object's PK, as we'll want this if we need to insert a row into secondary tables
1416
-				if( $this->has_primary_key_field() ){
1417
-					$main_table_pk_value = $wpdb_result[ $this->get_primary_key_field()->get_qualified_column() ];
1418
-				}else{
1416
+				if ($this->has_primary_key_field()) {
1417
+					$main_table_pk_value = $wpdb_result[$this->get_primary_key_field()->get_qualified_column()];
1418
+				} else {
1419 1419
 					//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)
1420 1420
 					$main_table_pk_value = null;
1421 1421
 				}
1422 1422
 				//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
1423 1423
 				//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
1424
-				if(count($tables) > 1){
1424
+				if (count($tables) > 1) {
1425 1425
 					//foreach matching row in the DB, ensure that each table's PK isn't null. If so, there must not be an entry
1426 1426
 					//in that table, and so we'll want to insert one
1427
-					foreach($tables as $table_obj){
1427
+					foreach ($tables as $table_obj) {
1428 1428
 						$this_table_pk_column = $table_obj->get_fully_qualified_pk_column();
1429 1429
 						//if there is no private key for this table on the results, it means there's no entry
1430 1430
 						//in this table, right? so insert a row in the current table, using any fields available
1431
-						if( ! ( array_key_exists( $this_table_pk_column, $wpdb_result) && $wpdb_result[ $this_table_pk_column ] )){
1431
+						if ( ! (array_key_exists($this_table_pk_column, $wpdb_result) && $wpdb_result[$this_table_pk_column])) {
1432 1432
 							$success = $this->_insert_into_specific_table($table_obj, $fields_n_values, $main_table_pk_value);
1433 1433
 							//if we died here, report the error
1434
-							if( ! $success ) {
1434
+							if ( ! $success) {
1435 1435
 								return false;
1436 1436
 							}
1437 1437
 						}
@@ -1451,44 +1451,44 @@  discard block
 block discarded – undo
1451 1451
 		//if this wasn't called from a model object (to update itself)
1452 1452
 		//then we want to make sure we keep all the existing
1453 1453
 		//model objects in sync with the db
1454
-		if( $keep_model_objs_in_sync && ! $this->_values_already_prepared_by_model_object ){
1455
-			if( $this->has_primary_key_field() ){
1456
-				$model_objs_affected_ids = $this->get_col( $query_params );
1457
-			}else{
1454
+		if ($keep_model_objs_in_sync && ! $this->_values_already_prepared_by_model_object) {
1455
+			if ($this->has_primary_key_field()) {
1456
+				$model_objs_affected_ids = $this->get_col($query_params);
1457
+			} else {
1458 1458
 				//we need to select a bunch of columns and then combine them into the the "index primary key string"s
1459
-				$models_affected_key_columns = $this->_get_all_wpdb_results($query_params, ARRAY_A );
1459
+				$models_affected_key_columns = $this->_get_all_wpdb_results($query_params, ARRAY_A);
1460 1460
 				$model_objs_affected_ids = array();
1461
-				foreach( $models_affected_key_columns as $row ){
1462
-					$combined_index_key = $this->get_index_primary_key_string( $row );
1463
-					$model_objs_affected_ids[ $combined_index_key ] = $combined_index_key;
1461
+				foreach ($models_affected_key_columns as $row) {
1462
+					$combined_index_key = $this->get_index_primary_key_string($row);
1463
+					$model_objs_affected_ids[$combined_index_key] = $combined_index_key;
1464 1464
 				}
1465 1465
 
1466 1466
 			}
1467 1467
 
1468
-			if( ! $model_objs_affected_ids ){
1468
+			if ( ! $model_objs_affected_ids) {
1469 1469
 				//wait wait wait- if nothing was affected let's stop here
1470 1470
 				return 0;
1471 1471
 			}
1472
-			foreach( $model_objs_affected_ids as $id ){
1473
-				$model_obj_in_entity_map = $this->get_from_entity_map( $id );
1474
-				if( $model_obj_in_entity_map ){
1475
-					foreach( $fields_n_values as $field => $new_value ){
1476
-						$model_obj_in_entity_map->set( $field, $new_value );
1472
+			foreach ($model_objs_affected_ids as $id) {
1473
+				$model_obj_in_entity_map = $this->get_from_entity_map($id);
1474
+				if ($model_obj_in_entity_map) {
1475
+					foreach ($fields_n_values as $field => $new_value) {
1476
+						$model_obj_in_entity_map->set($field, $new_value);
1477 1477
 					}
1478 1478
 				}
1479 1479
 			}
1480 1480
 			//if there is a primary key on this model, we can now do a slight optimization
1481
-			if( $this->has_primary_key_field() ){
1481
+			if ($this->has_primary_key_field()) {
1482 1482
 				//we already know what we want to update. So let's make the query simpler so it's a little more efficient
1483 1483
 				$query_params = array(
1484
-					array( $this->primary_key_name() => array( 'IN', $model_objs_affected_ids ) ),
1485
-					'limit' => count( $model_objs_affected_ids ), 'default_where_conditions' => 'none' );
1484
+					array($this->primary_key_name() => array('IN', $model_objs_affected_ids)),
1485
+					'limit' => count($model_objs_affected_ids), 'default_where_conditions' => 'none' );
1486 1486
 			}
1487 1487
 		}
1488 1488
 
1489
-		$model_query_info = $this->_create_model_query_info_carrier( $query_params );
1490
-		$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.
1491
-		$rows_affected = $this->_do_wpdb_query('query', array( $SQL ) );
1489
+		$model_query_info = $this->_create_model_query_info_carrier($query_params);
1490
+		$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.
1491
+		$rows_affected = $this->_do_wpdb_query('query', array($SQL));
1492 1492
 		/**
1493 1493
 		 * Action called after a model update call has been made.
1494 1494
 		 *
@@ -1497,8 +1497,8 @@  discard block
 block discarded – undo
1497 1497
 		 * @param array $query_params @see EEM_Base::get_all()
1498 1498
 		 * @param int $rows_affected
1499 1499
 		 */
1500
-		do_action( 'AHEE__EEM_Base__update__end',$this, $fields_n_values, $query_params, $rows_affected );
1501
-		return $rows_affected;//how many supposedly got updated
1500
+		do_action('AHEE__EEM_Base__update__end', $this, $fields_n_values, $query_params, $rows_affected);
1501
+		return $rows_affected; //how many supposedly got updated
1502 1502
 	}
1503 1503
 
1504 1504
 
@@ -1514,22 +1514,22 @@  discard block
 block discarded – undo
1514 1514
 	 * @return array just like $wpdb->get_col()
1515 1515
 	 * @throws \EE_Error
1516 1516
 	 */
1517
-	public function get_col( $query_params  = array(), $field_to_select = NULL ){
1517
+	public function get_col($query_params = array(), $field_to_select = NULL) {
1518 1518
 
1519
-		if( $field_to_select ){
1520
-			$field = $this->field_settings_for( $field_to_select );
1521
-		}elseif( $this->has_primary_key_field ( ) ){
1519
+		if ($field_to_select) {
1520
+			$field = $this->field_settings_for($field_to_select);
1521
+		}elseif ($this->has_primary_key_field( )) {
1522 1522
 			$field = $this->get_primary_key_field();
1523
-		}else{
1523
+		} else {
1524 1524
 			//no primary key, just grab the first column
1525
-			$field = reset( $this->field_settings());
1525
+			$field = reset($this->field_settings());
1526 1526
 		}
1527 1527
 
1528 1528
 
1529 1529
 		$model_query_info = $this->_create_model_query_info_carrier($query_params);
1530 1530
 		$select_expressions = $field->get_qualified_column();
1531
-		$SQL ="SELECT $select_expressions ".$this->_construct_2nd_half_of_select_query($model_query_info);
1532
-		return $this->_do_wpdb_query('get_col', array( $SQL ) );
1531
+		$SQL = "SELECT $select_expressions ".$this->_construct_2nd_half_of_select_query($model_query_info);
1532
+		return $this->_do_wpdb_query('get_col', array($SQL));
1533 1533
 	}
1534 1534
 
1535 1535
 
@@ -1542,12 +1542,12 @@  discard block
 block discarded – undo
1542 1542
 	 * @return string
1543 1543
 	 * @throws \EE_Error
1544 1544
 	 */
1545
-	public function get_var( $query_params = array(), $field_to_select = NULL ) {
1546
-		$query_params[ 'limit' ] = 1;
1547
-		$col = $this->get_col( $query_params, $field_to_select );
1548
-		if( ! empty( $col ) ) {
1549
-			return reset( $col );
1550
-		}else{
1545
+	public function get_var($query_params = array(), $field_to_select = NULL) {
1546
+		$query_params['limit'] = 1;
1547
+		$col = $this->get_col($query_params, $field_to_select);
1548
+		if ( ! empty($col)) {
1549
+			return reset($col);
1550
+		} else {
1551 1551
 			return NULL;
1552 1552
 		}
1553 1553
 	}
@@ -1563,19 +1563,19 @@  discard block
 block discarded – undo
1563 1563
 	 * @return string of SQL
1564 1564
 	 * @throws \EE_Error
1565 1565
 	 */
1566
-	public function _construct_update_sql($fields_n_values){
1566
+	public function _construct_update_sql($fields_n_values) {
1567 1567
 		/** @type WPDB $wpdb */
1568 1568
 		global $wpdb;
1569 1569
 		$cols_n_values = array();
1570
-		foreach($fields_n_values as $field_name => $value){
1570
+		foreach ($fields_n_values as $field_name => $value) {
1571 1571
 			$field_obj = $this->field_settings_for($field_name);
1572 1572
 			//if the value is NULL, we want to assign the value to that.
1573 1573
 			//wpdb->prepare doesn't really handle that properly
1574
-			$prepared_value = $this->_prepare_value_or_use_default( $field_obj, $fields_n_values );
1575
-			$value_sql = $prepared_value===NULL ? 'NULL' : $wpdb->prepare( $field_obj->get_wpdb_data_type(), $prepared_value );
1574
+			$prepared_value = $this->_prepare_value_or_use_default($field_obj, $fields_n_values);
1575
+			$value_sql = $prepared_value === NULL ? 'NULL' : $wpdb->prepare($field_obj->get_wpdb_data_type(), $prepared_value);
1576 1576
 			$cols_n_values[] = $field_obj->get_qualified_column()."=".$value_sql;
1577 1577
 		}
1578
-		return implode(",",$cols_n_values);
1578
+		return implode(",", $cols_n_values);
1579 1579
 
1580 1580
 	}
1581 1581
 
@@ -1591,10 +1591,10 @@  discard block
 block discarded – undo
1591 1591
 	 * @return boolean whether the row got deleted or not
1592 1592
 	 * @throws \EE_Error
1593 1593
 	 */
1594
-	public function delete_permanently_by_ID( $id ) {
1594
+	public function delete_permanently_by_ID($id) {
1595 1595
 		return $this->delete_permanently(
1596 1596
 			array(
1597
-				array( $this->get_primary_key_field()->get_name() => $id ),
1597
+				array($this->get_primary_key_field()->get_name() => $id),
1598 1598
 				'limit' 	=> 1
1599 1599
 			)
1600 1600
 		);
@@ -1610,10 +1610,10 @@  discard block
 block discarded – undo
1610 1610
 	 * @return boolean whether the row got deleted or not
1611 1611
 	 * @throws \EE_Error
1612 1612
 	 */
1613
-	public function delete_by_ID( $id ){
1613
+	public function delete_by_ID($id) {
1614 1614
 		return $this->delete(
1615 1615
 			array(
1616
-				array( $this->get_primary_key_field()->get_name() => $id ),
1616
+				array($this->get_primary_key_field()->get_name() => $id),
1617 1617
 				'limit' 	=> 1
1618 1618
 			)
1619 1619
 		);
@@ -1632,7 +1632,7 @@  discard block
 block discarded – undo
1632 1632
 	 * @return int how many rows got deleted
1633 1633
 	 * @throws \EE_Error
1634 1634
 	 */
1635
-	public function delete($query_params,$allow_blocking = true){
1635
+	public function delete($query_params, $allow_blocking = true) {
1636 1636
 		return $this->delete_permanently($query_params, $allow_blocking);
1637 1637
 	}
1638 1638
 
@@ -1650,7 +1650,7 @@  discard block
 block discarded – undo
1650 1650
 	 * @return int how many rows got deleted
1651 1651
 	 * @throws \EE_Error
1652 1652
 	 */
1653
-	public function delete_permanently($query_params,$allow_blocking = true){
1653
+	public function delete_permanently($query_params, $allow_blocking = true) {
1654 1654
 		/**
1655 1655
 		 * Action called just before performing a real deletion query. You can use the
1656 1656
 		 * model and its $query_params to find exactly which items will be deleted
@@ -1659,31 +1659,31 @@  discard block
 block discarded – undo
1659 1659
 		 * @param boolean $allow_blocking whether or not to allow related model objects
1660 1660
 		 * to block (prevent) this deletion
1661 1661
 		 */
1662
-		do_action( 'AHEE__EEM_Base__delete__begin', $this, $query_params, $allow_blocking );
1662
+		do_action('AHEE__EEM_Base__delete__begin', $this, $query_params, $allow_blocking);
1663 1663
 		//some MySQL databases may be running safe mode, which may restrict
1664 1664
 		//deletion if there is no KEY column used in the WHERE statement of a deletion.
1665 1665
 		//to get around this, we first do a SELECT, get all the IDs, and then run another query
1666 1666
 		//to delete them
1667 1667
 		$items_for_deletion = $this->_get_all_wpdb_results($query_params);
1668
-		$deletion_where = $this->_setup_ids_for_delete( $items_for_deletion, $allow_blocking);
1669
-		if($deletion_where){
1668
+		$deletion_where = $this->_setup_ids_for_delete($items_for_deletion, $allow_blocking);
1669
+		if ($deletion_where) {
1670 1670
 			//echo "objects for deletion:";var_dump($objects_for_deletion);
1671 1671
 			$model_query_info = $this->_create_model_query_info_carrier($query_params);
1672
-			$table_aliases = array_keys( $this->_tables );
1673
-			$SQL = "DELETE ".implode(", ",$table_aliases)." FROM ".$model_query_info->get_full_join_sql()." WHERE ".$deletion_where;
1672
+			$table_aliases = array_keys($this->_tables);
1673
+			$SQL = "DELETE ".implode(", ", $table_aliases)." FROM ".$model_query_info->get_full_join_sql()." WHERE ".$deletion_where;
1674 1674
 
1675 1675
 			//		/echo "delete sql:$SQL";
1676
-			$rows_deleted = $this->_do_wpdb_query( 'query', array( $SQL ) );
1677
-		}else{
1676
+			$rows_deleted = $this->_do_wpdb_query('query', array($SQL));
1677
+		} else {
1678 1678
 			$rows_deleted = 0;
1679 1679
 		}
1680 1680
 
1681 1681
 		//and lastly make sure those items are removed from the entity map; if they could be put into it at all
1682
-		if( $this->has_primary_key_field() ){
1683
-			foreach($items_for_deletion as $item_for_deletion_row ){
1684
-				$pk_value = $item_for_deletion_row[ $this->get_primary_key_field()->get_qualified_column() ];
1685
-				if( isset( $this->_entity_map[ EEM_Base::$_model_query_blog_id ][ $pk_value ] ) ){
1686
-					unset( $this->_entity_map[ EEM_Base::$_model_query_blog_id ][ $pk_value ] );
1682
+		if ($this->has_primary_key_field()) {
1683
+			foreach ($items_for_deletion as $item_for_deletion_row) {
1684
+				$pk_value = $item_for_deletion_row[$this->get_primary_key_field()->get_qualified_column()];
1685
+				if (isset($this->_entity_map[EEM_Base::$_model_query_blog_id][$pk_value])) {
1686
+					unset($this->_entity_map[EEM_Base::$_model_query_blog_id][$pk_value]);
1687 1687
 				}
1688 1688
 			}
1689 1689
 		}
@@ -1695,8 +1695,8 @@  discard block
 block discarded – undo
1695 1695
 		 * @param array $query_params @see EEM_Base::get_all()
1696 1696
 		 * @param int $rows_deleted
1697 1697
 		 */
1698
-		do_action( 'AHEE__EEM_Base__delete__end', $this, $query_params, $rows_deleted );
1699
-		return $rows_deleted;//how many supposedly got deleted
1698
+		do_action('AHEE__EEM_Base__delete__end', $this, $query_params, $rows_deleted);
1699
+		return $rows_deleted; //how many supposedly got deleted
1700 1700
 	}
1701 1701
 
1702 1702
 
@@ -1714,28 +1714,28 @@  discard block
 block discarded – undo
1714 1714
 	 * @return boolean
1715 1715
 	 * @throws \EE_Error
1716 1716
 	 */
1717
-	public function delete_is_blocked_by_related_models($this_model_obj_or_id, $ignore_this_model_obj = null){
1717
+	public function delete_is_blocked_by_related_models($this_model_obj_or_id, $ignore_this_model_obj = null) {
1718 1718
 		//first, if $ignore_this_model_obj was supplied, get its model
1719
-		if($ignore_this_model_obj && $ignore_this_model_obj instanceof EE_Base_Class){
1719
+		if ($ignore_this_model_obj && $ignore_this_model_obj instanceof EE_Base_Class) {
1720 1720
 			$ignored_model = $ignore_this_model_obj->get_model();
1721
-		}else{
1721
+		} else {
1722 1722
 			$ignored_model = null;
1723 1723
 		}
1724 1724
 		//now check all the relations of $this_model_obj_or_id and see if there
1725 1725
 		//are any related model objects blocking it?
1726 1726
 		$is_blocked = false;
1727
-		foreach($this->_model_relations as $relation_name => $relation_obj){
1728
-			if( $relation_obj->block_delete_if_related_models_exist()){
1727
+		foreach ($this->_model_relations as $relation_name => $relation_obj) {
1728
+			if ($relation_obj->block_delete_if_related_models_exist()) {
1729 1729
 				//if $ignore_this_model_obj was supplied, then for the query
1730 1730
 				//on that model needs to be told to ignore $ignore_this_model_obj
1731
-				if($ignored_model && $relation_name === $ignored_model->get_this_model_name()){
1732
-					$related_model_objects = $relation_obj->get_all_related($this_model_obj_or_id,array(
1733
-					array($ignored_model->get_primary_key_field()->get_name() => array('!=',$ignore_this_model_obj->ID()))));
1734
-				}else{
1731
+				if ($ignored_model && $relation_name === $ignored_model->get_this_model_name()) {
1732
+					$related_model_objects = $relation_obj->get_all_related($this_model_obj_or_id, array(
1733
+					array($ignored_model->get_primary_key_field()->get_name() => array('!=', $ignore_this_model_obj->ID()))));
1734
+				} else {
1735 1735
 					$related_model_objects = $relation_obj->get_all_related($this_model_obj_or_id);
1736 1736
 				}
1737 1737
 
1738
-				if($related_model_objects){
1738
+				if ($related_model_objects) {
1739 1739
 					EE_Error::add_error($relation_obj->get_deletion_error_message(), __FILE__, __FUNCTION__, __LINE__);
1740 1740
 					$is_blocked = true;
1741 1741
 				}
@@ -1755,75 +1755,75 @@  discard block
 block discarded – undo
1755 1755
 	 * @throws EE_Error
1756 1756
 	 * @return string    everything that comes after the WHERE statement.
1757 1757
 	 */
1758
-	protected function _setup_ids_for_delete( $objects_for_deletion, $allow_blocking = true) {
1759
-		if($this->has_primary_key_field()){
1758
+	protected function _setup_ids_for_delete($objects_for_deletion, $allow_blocking = true) {
1759
+		if ($this->has_primary_key_field()) {
1760 1760
 			$primary_table = $this->_get_main_table();
1761 1761
 			$other_tables = $this->_get_other_tables();
1762 1762
 			$deletes = $query = array();
1763
-			foreach ( $objects_for_deletion as $delete_object ) {
1763
+			foreach ($objects_for_deletion as $delete_object) {
1764 1764
 				//before we mark this object for deletion,
1765 1765
 				//make sure there's no related objects blocking its deletion (if we're checking)
1766 1766
 				if (
1767 1767
 					$allow_blocking
1768 1768
 				    && $this->delete_is_blocked_by_related_models(
1769
-						$delete_object[ $primary_table->get_fully_qualified_pk_column() ]
1769
+						$delete_object[$primary_table->get_fully_qualified_pk_column()]
1770 1770
 					)
1771 1771
 				) {
1772 1772
 					continue;
1773 1773
 				}
1774 1774
 				//primary table deletes
1775
-				if ( isset( $delete_object[ $primary_table->get_fully_qualified_pk_column() ] ) ) {
1776
-					$deletes[ $primary_table->get_fully_qualified_pk_column() ][] = $delete_object[ $primary_table->get_fully_qualified_pk_column() ];
1775
+				if (isset($delete_object[$primary_table->get_fully_qualified_pk_column()])) {
1776
+					$deletes[$primary_table->get_fully_qualified_pk_column()][] = $delete_object[$primary_table->get_fully_qualified_pk_column()];
1777 1777
 				}
1778 1778
 				//other tables
1779
-				if ( ! empty( $other_tables ) ) {
1780
-					foreach ( $other_tables as $ot ) {
1779
+				if ( ! empty($other_tables)) {
1780
+					foreach ($other_tables as $ot) {
1781 1781
 						//first check if we've got the foreign key column here.
1782
-						if ( isset( $delete_object[ $ot->get_fully_qualified_fk_column() ] ) ) {
1783
-							$deletes[ $ot->get_fully_qualified_pk_column() ][] = $delete_object[ $ot->get_fully_qualified_fk_column() ];
1782
+						if (isset($delete_object[$ot->get_fully_qualified_fk_column()])) {
1783
+							$deletes[$ot->get_fully_qualified_pk_column()][] = $delete_object[$ot->get_fully_qualified_fk_column()];
1784 1784
 						}
1785 1785
 						// wait! it's entirely possible that we'll have a the primary key
1786 1786
 						// for this table in here, if it's a foreign key for one of the other secondary tables
1787
-						if ( isset( $delete_object[ $ot->get_fully_qualified_pk_column() ] ) ) {
1788
-							$deletes[ $ot->get_fully_qualified_pk_column() ][] = $delete_object[ $ot->get_fully_qualified_pk_column() ];
1787
+						if (isset($delete_object[$ot->get_fully_qualified_pk_column()])) {
1788
+							$deletes[$ot->get_fully_qualified_pk_column()][] = $delete_object[$ot->get_fully_qualified_pk_column()];
1789 1789
 						}
1790 1790
 						// finally, it is possible that the fk for this table is found
1791 1791
 						// in the fully qualified pk column for the fk table, so let's see if that's there!
1792
-						if ( isset( $delete_object[ $ot->get_fully_qualified_pk_on_fk_table() ] ) ) {
1793
-							$deletes[ $ot->get_fully_qualified_pk_column() ][] = $delete_object[ $ot->get_fully_qualified_pk_column() ];
1792
+						if (isset($delete_object[$ot->get_fully_qualified_pk_on_fk_table()])) {
1793
+							$deletes[$ot->get_fully_qualified_pk_column()][] = $delete_object[$ot->get_fully_qualified_pk_column()];
1794 1794
 						}
1795 1795
 					}
1796 1796
 				}
1797 1797
 			}
1798 1798
 
1799 1799
 			//we should have deletes now, so let's just go through and setup the where statement
1800
-			foreach ( $deletes as $column => $values ) {
1800
+			foreach ($deletes as $column => $values) {
1801 1801
 				//make sure we have unique $values;
1802 1802
 				$values = array_unique($values);
1803
-				$query[] = $column . ' IN(' . implode(",",$values) . ')';
1803
+				$query[] = $column.' IN('.implode(",", $values).')';
1804 1804
 			}
1805 1805
 
1806
-			return !empty($query) ? implode(' AND ', $query ) : '';
1807
-		}elseif(count($this->get_combined_primary_key_fields()) > 1){
1806
+			return ! empty($query) ? implode(' AND ', $query) : '';
1807
+		}elseif (count($this->get_combined_primary_key_fields()) > 1) {
1808 1808
 			$ways_to_identify_a_row = array();
1809 1809
 			$fields = $this->get_combined_primary_key_fields();
1810 1810
 			//note: because there' sno primary key, that means nothing else  can be pointing to this model, right?
1811
-			foreach($objects_for_deletion as  $delete_object){
1811
+			foreach ($objects_for_deletion as  $delete_object) {
1812 1812
 				$values_for_each_cpk_for_a_row = array();
1813
-				foreach($fields as $cpk_field){
1814
-					if ( $cpk_field instanceof EE_Model_Field_Base ){
1813
+				foreach ($fields as $cpk_field) {
1814
+					if ($cpk_field instanceof EE_Model_Field_Base) {
1815 1815
 						$values_for_each_cpk_for_a_row[] = $cpk_field->get_qualified_column()
1816 1816
 						                                   . "="
1817
-						                                   . $delete_object[ $cpk_field->get_qualified_column() ];
1817
+						                                   . $delete_object[$cpk_field->get_qualified_column()];
1818 1818
 					}
1819 1819
 				}
1820
-				$ways_to_identify_a_row[] = "(".implode(" AND ",$values_for_each_cpk_for_a_row).")";
1820
+				$ways_to_identify_a_row[] = "(".implode(" AND ", $values_for_each_cpk_for_a_row).")";
1821 1821
 			}
1822
-			return implode(" OR ",$ways_to_identify_a_row);
1823
-		}else{
1822
+			return implode(" OR ", $ways_to_identify_a_row);
1823
+		} else {
1824 1824
 			//so there's no primary key and no combined key...
1825 1825
 			//sorry, can't help you
1826
-			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)));
1826
+			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)));
1827 1827
 		}
1828 1828
 	}
1829 1829
 
@@ -1839,21 +1839,21 @@  discard block
 block discarded – undo
1839 1839
 	 * @return int
1840 1840
 	 * @throws \EE_Error
1841 1841
 	 */
1842
-	public function count($query_params =array(),$field_to_count = NULL, $distinct = FALSE){
1842
+	public function count($query_params = array(), $field_to_count = NULL, $distinct = FALSE) {
1843 1843
 		$model_query_info = $this->_create_model_query_info_carrier($query_params);
1844
-		if($field_to_count){
1844
+		if ($field_to_count) {
1845 1845
 			$field_obj = $this->field_settings_for($field_to_count);
1846 1846
 			$column_to_count = $field_obj->get_qualified_column();
1847
-		}elseif($this->has_primary_key_field ()){
1847
+		}elseif ($this->has_primary_key_field()) {
1848 1848
 			$pk_field_obj = $this->get_primary_key_field();
1849 1849
 			$column_to_count = $pk_field_obj->get_qualified_column();
1850
-		}else{//there's no primary key
1850
+		} else {//there's no primary key
1851 1851
 			$column_to_count = '*';
1852 1852
 		}
1853 1853
 
1854
-		$column_to_count = $distinct ? "DISTINCT (" . $column_to_count . " )" : $column_to_count;
1855
-		$SQL ="SELECT COUNT(".$column_to_count.")" . $this->_construct_2nd_half_of_select_query($model_query_info);
1856
-		return (int)$this->_do_wpdb_query( 'get_var', array( $SQL) );
1854
+		$column_to_count = $distinct ? "DISTINCT (".$column_to_count." )" : $column_to_count;
1855
+		$SQL = "SELECT COUNT(".$column_to_count.")".$this->_construct_2nd_half_of_select_query($model_query_info);
1856
+		return (int) $this->_do_wpdb_query('get_var', array($SQL));
1857 1857
 	}
1858 1858
 
1859 1859
 
@@ -1866,24 +1866,24 @@  discard block
 block discarded – undo
1866 1866
 	 * @return float
1867 1867
 	 * @throws \EE_Error
1868 1868
 	 */
1869
-	public function sum($query_params, $field_to_sum = NULL){
1869
+	public function sum($query_params, $field_to_sum = NULL) {
1870 1870
 		$model_query_info = $this->_create_model_query_info_carrier($query_params);
1871 1871
 
1872
-		if($field_to_sum){
1872
+		if ($field_to_sum) {
1873 1873
 			$field_obj = $this->field_settings_for($field_to_sum);
1874 1874
 
1875
-		}else{
1875
+		} else {
1876 1876
 			$field_obj = $this->get_primary_key_field();
1877 1877
 		}
1878 1878
 		$column_to_count = $field_obj->get_qualified_column();
1879 1879
 
1880
-		$SQL ="SELECT SUM(".$column_to_count.")" . $this->_construct_2nd_half_of_select_query($model_query_info);
1881
-		$return_value = $this->_do_wpdb_query('get_var',array( $SQL ) );
1880
+		$SQL = "SELECT SUM(".$column_to_count.")".$this->_construct_2nd_half_of_select_query($model_query_info);
1881
+		$return_value = $this->_do_wpdb_query('get_var', array($SQL));
1882 1882
 		$data_type = $field_obj->get_wpdb_data_type();
1883
-		if( $data_type === '%d' || $data_type === '%s' ){
1884
-			return (float)$return_value;
1885
-		}else{//must be %f
1886
-			return (float)$return_value;
1883
+		if ($data_type === '%d' || $data_type === '%s') {
1884
+			return (float) $return_value;
1885
+		} else {//must be %f
1886
+			return (float) $return_value;
1887 1887
 		}
1888 1888
 	}
1889 1889
 
@@ -1898,37 +1898,37 @@  discard block
 block discarded – undo
1898 1898
 	 * @global wpdb $wpdb
1899 1899
 	 * @return mixed
1900 1900
 	 */
1901
-	protected function _do_wpdb_query( $wpdb_method, $arguments_to_provide ){
1901
+	protected function _do_wpdb_query($wpdb_method, $arguments_to_provide) {
1902 1902
 		//if we're in maintenance mode level 2, DON'T run any queries
1903 1903
 		//because level 2 indicates the database needs updating and
1904 1904
 		//is probably out of sync with the code
1905
-		if( ! EE_Maintenance_Mode::instance()->models_can_query()){
1905
+		if ( ! EE_Maintenance_Mode::instance()->models_can_query()) {
1906 1906
 			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")));
1907 1907
 		}
1908 1908
 		/** @type WPDB $wpdb */
1909 1909
 		global $wpdb;
1910
-		if( ! method_exists( $wpdb, $wpdb_method ) ){
1911
-			throw new EE_Error( sprintf( __( 'There is no method named "%s" on Wordpress\' $wpdb object','event_espresso' ), $wpdb_method ) );
1910
+		if ( ! method_exists($wpdb, $wpdb_method)) {
1911
+			throw new EE_Error(sprintf(__('There is no method named "%s" on Wordpress\' $wpdb object', 'event_espresso'), $wpdb_method));
1912 1912
 		}
1913
-		if( WP_DEBUG ){
1913
+		if (WP_DEBUG) {
1914 1914
 			$old_show_errors_value = $wpdb->show_errors;
1915
-			$wpdb->show_errors( FALSE );
1916
-		}
1917
-		$result = $this->_process_wpdb_query( $wpdb_method, $arguments_to_provide );
1918
-		$this->show_db_query_if_previously_requested( $wpdb->last_query );
1919
-		if( WP_DEBUG ){
1920
-			$wpdb->show_errors( $old_show_errors_value );
1921
-			if( ! empty( $wpdb->last_error ) ){
1922
-				throw new EE_Error( sprintf( __( 'WPDB Error: "%s"', 'event_espresso' ), $wpdb->last_error ) );
1923
-			}elseif( $result === false ){
1924
-				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 ) ) );
1915
+			$wpdb->show_errors(FALSE);
1916
+		}
1917
+		$result = $this->_process_wpdb_query($wpdb_method, $arguments_to_provide);
1918
+		$this->show_db_query_if_previously_requested($wpdb->last_query);
1919
+		if (WP_DEBUG) {
1920
+			$wpdb->show_errors($old_show_errors_value);
1921
+			if ( ! empty($wpdb->last_error)) {
1922
+				throw new EE_Error(sprintf(__('WPDB Error: "%s"', 'event_espresso'), $wpdb->last_error));
1923
+			}elseif ($result === false) {
1924
+				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)));
1925 1925
 			}
1926
-		}elseif( $result === false ) {
1926
+		}elseif ($result === false) {
1927 1927
 			EE_Error::add_error(
1928 1928
 				sprintf(
1929
-					__( 'A database error has occurred. Turn on WP_DEBUG for more information.||A database error occurred doing wpdb method "%1$s", with arguments "%2$s". The error was "%3$s"', 'event_espresso' ),
1929
+					__('A database error has occurred. Turn on WP_DEBUG for more information.||A database error occurred doing wpdb method "%1$s", with arguments "%2$s". The error was "%3$s"', 'event_espresso'),
1930 1930
 					$wpdb_method,
1931
-					var_export( $arguments_to_provide, true ),
1931
+					var_export($arguments_to_provide, true),
1932 1932
 					$wpdb->last_error
1933 1933
 				),
1934 1934
 				__FILE__,
@@ -1950,26 +1950,26 @@  discard block
 block discarded – undo
1950 1950
 	 * @param array $arguments_to_provide
1951 1951
 	 * @return mixed
1952 1952
 	 */
1953
-	private function _process_wpdb_query( $wpdb_method, $arguments_to_provide ) {
1953
+	private function _process_wpdb_query($wpdb_method, $arguments_to_provide) {
1954 1954
 		/** @type WPDB $wpdb */
1955 1955
 		global $wpdb;
1956 1956
 		$wpdb->last_error = null;
1957
-		$result = call_user_func_array( array( $wpdb, $wpdb_method ), $arguments_to_provide );
1957
+		$result = call_user_func_array(array($wpdb, $wpdb_method), $arguments_to_provide);
1958 1958
 		// was there an error running the query? but we don't care on new activations
1959 1959
 		// (we're going to setup the DB anyway on new activations)
1960
-		if ( ( $result === false || ! empty( $wpdb->last_error ) )
1960
+		if (($result === false || ! empty($wpdb->last_error))
1961 1961
 			&& EE_System::instance()->detect_req_type() !== EE_System::req_type_new_activation
1962 1962
 		) {
1963
-			switch ( EEM_Base::$_db_verification_level ) {
1963
+			switch (EEM_Base::$_db_verification_level) {
1964 1964
 
1965 1965
 				case EEM_Base::db_verified_none :
1966 1966
 					// let's double-check core's DB
1967
-					$error_message = $this->_verify_core_db( $wpdb_method, $arguments_to_provide );
1967
+					$error_message = $this->_verify_core_db($wpdb_method, $arguments_to_provide);
1968 1968
 					break;
1969 1969
 
1970 1970
 				case EEM_Base::db_verified_core :
1971 1971
 					// STILL NO LOVE?? verify all the addons too. Maybe they need to be fixed
1972
-					$error_message = $this->_verify_addons_db( $wpdb_method, $arguments_to_provide );
1972
+					$error_message = $this->_verify_addons_db($wpdb_method, $arguments_to_provide);
1973 1973
 					break;
1974 1974
 
1975 1975
 				case EEM_Base::db_verified_addons :
@@ -1977,11 +1977,11 @@  discard block
 block discarded – undo
1977 1977
 					return $result;
1978 1978
 					break;
1979 1979
 			}
1980
-			if ( ! empty( $error_message ) ) {
1981
-				EE_Log::instance()->log( __FILE__, __FUNCTION__, $error_message, 'error' );
1982
-				trigger_error( $error_message );
1980
+			if ( ! empty($error_message)) {
1981
+				EE_Log::instance()->log(__FILE__, __FUNCTION__, $error_message, 'error');
1982
+				trigger_error($error_message);
1983 1983
 			}
1984
-			return $this->_process_wpdb_query( $wpdb_method, $arguments_to_provide );
1984
+			return $this->_process_wpdb_query($wpdb_method, $arguments_to_provide);
1985 1985
 
1986 1986
 		}
1987 1987
 
@@ -1997,18 +1997,18 @@  discard block
 block discarded – undo
1997 1997
 	 * @param array $arguments_to_provide
1998 1998
 	 * @return string
1999 1999
 	 */
2000
-	private function _verify_core_db( $wpdb_method, $arguments_to_provide ){
2000
+	private function _verify_core_db($wpdb_method, $arguments_to_provide) {
2001 2001
 		/** @type WPDB $wpdb */
2002 2002
 		global $wpdb;
2003 2003
 		//ok remember that we've already attempted fixing the core db, in case the problem persists
2004 2004
 		EEM_Base::$_db_verification_level = EEM_Base::db_verified_core;
2005 2005
 		$error_message = sprintf(
2006
-			__( 'WPDB Error "%1$s" while running wpdb method "%2$s" with arguments %3$s. Automatically attempting to fix EE Core DB', 'event_espresso' ),
2006
+			__('WPDB Error "%1$s" while running wpdb method "%2$s" with arguments %3$s. Automatically attempting to fix EE Core DB', 'event_espresso'),
2007 2007
 			$wpdb->last_error,
2008 2008
 			$wpdb_method,
2009
-			json_encode( $arguments_to_provide )
2009
+			json_encode($arguments_to_provide)
2010 2010
 		);
2011
-		EE_System::instance()->initialize_db_if_no_migrations_required( false, true );
2011
+		EE_System::instance()->initialize_db_if_no_migrations_required(false, true);
2012 2012
 		return $error_message;
2013 2013
 	}
2014 2014
 
@@ -2021,16 +2021,16 @@  discard block
 block discarded – undo
2021 2021
 	 * @param $arguments_to_provide
2022 2022
 	 * @return string
2023 2023
 	 */
2024
-	private function _verify_addons_db( $wpdb_method, $arguments_to_provide ) {
2024
+	private function _verify_addons_db($wpdb_method, $arguments_to_provide) {
2025 2025
 		/** @type WPDB $wpdb */
2026 2026
 		global $wpdb;
2027 2027
 		//ok remember that we've already attempted fixing the addons dbs, in case the problem persists
2028 2028
 		EEM_Base::$_db_verification_level = EEM_Base::db_verified_addons;
2029 2029
 		$error_message = sprintf(
2030
-			__( 'WPDB AGAIN: Error "%1$s" while running the same method and arguments as before. Automatically attempting to fix EE Addons DB', 'event_espresso' ),
2030
+			__('WPDB AGAIN: Error "%1$s" while running the same method and arguments as before. Automatically attempting to fix EE Addons DB', 'event_espresso'),
2031 2031
 			$wpdb->last_error,
2032 2032
 			$wpdb_method,
2033
-			json_encode( $arguments_to_provide )
2033
+			json_encode($arguments_to_provide)
2034 2034
 		);
2035 2035
 		EE_System::instance()->initialize_addons();
2036 2036
 		return $error_message;
@@ -2045,7 +2045,7 @@  discard block
 block discarded – undo
2045 2045
 	 * @param EE_Model_Query_Info_Carrier $model_query_info
2046 2046
 	 * @return string
2047 2047
 	 */
2048
-	private function _construct_2nd_half_of_select_query(EE_Model_Query_Info_Carrier $model_query_info){
2048
+	private function _construct_2nd_half_of_select_query(EE_Model_Query_Info_Carrier $model_query_info) {
2049 2049
 		return " FROM ".$model_query_info->get_full_join_sql().
2050 2050
 				$model_query_info->get_where_sql().
2051 2051
 				$model_query_info->get_group_by_sql().
@@ -2058,7 +2058,7 @@  discard block
 block discarded – undo
2058 2058
 	 * Set to easily debug the next X queries ran from this model.
2059 2059
 	 * @param int $count
2060 2060
 	 */
2061
-	public function show_next_x_db_queries($count = 1){
2061
+	public function show_next_x_db_queries($count = 1) {
2062 2062
 		$this->_show_next_x_db_queries = $count;
2063 2063
 	}
2064 2064
 
@@ -2067,8 +2067,8 @@  discard block
 block discarded – undo
2067 2067
 	/**
2068 2068
 	 * @param $sql_query
2069 2069
 	 */
2070
-	public function show_db_query_if_previously_requested($sql_query){
2071
-		if($this->_show_next_x_db_queries > 0){
2070
+	public function show_db_query_if_previously_requested($sql_query) {
2071
+		if ($this->_show_next_x_db_queries > 0) {
2072 2072
 			echo $sql_query;
2073 2073
 			$this->_show_next_x_db_queries--;
2074 2074
 		}
@@ -2092,9 +2092,9 @@  discard block
 block discarded – undo
2092 2092
 	 * @return EE_Base_Class which was added as a relation. Object referred to by $other_model_id_or_obj
2093 2093
 	 * @throws \EE_Error
2094 2094
 	 */
2095
-	public function add_relationship_to($id_or_obj,$other_model_id_or_obj, $relationName, $extra_join_model_fields_n_values = array()){
2095
+	public function add_relationship_to($id_or_obj, $other_model_id_or_obj, $relationName, $extra_join_model_fields_n_values = array()) {
2096 2096
 		$relation_obj = $this->related_settings_for($relationName);
2097
-		return $relation_obj->add_relation_to( $id_or_obj, $other_model_id_or_obj, $extra_join_model_fields_n_values);
2097
+		return $relation_obj->add_relation_to($id_or_obj, $other_model_id_or_obj, $extra_join_model_fields_n_values);
2098 2098
 	}
2099 2099
 
2100 2100
 
@@ -2113,9 +2113,9 @@  discard block
 block discarded – undo
2113 2113
 	 * @throws \EE_Error
2114 2114
 	 * @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.
2115 2115
 	 */
2116
-	public function remove_relationship_to($id_or_obj,  $other_model_id_or_obj, $relationName, $where_query= array() ){
2116
+	public function remove_relationship_to($id_or_obj, $other_model_id_or_obj, $relationName, $where_query = array()) {
2117 2117
 		$relation_obj = $this->related_settings_for($relationName);
2118
-		return $relation_obj->remove_relation_to($id_or_obj, $other_model_id_or_obj, $where_query );
2118
+		return $relation_obj->remove_relation_to($id_or_obj, $other_model_id_or_obj, $where_query);
2119 2119
 	}
2120 2120
 
2121 2121
 
@@ -2128,9 +2128,9 @@  discard block
 block discarded – undo
2128 2128
 	 * @return \EE_Base_Class[]
2129 2129
 	 * @throws \EE_Error
2130 2130
 	 */
2131
-	public function remove_relations($id_or_obj,$relationName,$where_query_params = array()){
2131
+	public function remove_relations($id_or_obj, $relationName, $where_query_params = array()) {
2132 2132
 		$relation_obj = $this->related_settings_for($relationName);
2133
-		return $relation_obj->remove_relations($id_or_obj, $where_query_params );
2133
+		return $relation_obj->remove_relations($id_or_obj, $where_query_params);
2134 2134
 	}
2135 2135
 
2136 2136
 
@@ -2146,10 +2146,10 @@  discard block
 block discarded – undo
2146 2146
 	 * @return EE_Base_Class[]
2147 2147
 	 * @throws \EE_Error
2148 2148
 	 */
2149
-	public function get_all_related($id_or_obj, $model_name, $query_params = null){
2149
+	public function get_all_related($id_or_obj, $model_name, $query_params = null) {
2150 2150
 		$model_obj = $this->ensure_is_obj($id_or_obj);
2151 2151
 		$relation_settings = $this->related_settings_for($model_name);
2152
-		return $relation_settings->get_all_related($model_obj,$query_params);
2152
+		return $relation_settings->get_all_related($model_obj, $query_params);
2153 2153
 	}
2154 2154
 
2155 2155
 
@@ -2166,10 +2166,10 @@  discard block
 block discarded – undo
2166 2166
 	 * @return int how many deleted
2167 2167
 	 * @throws \EE_Error
2168 2168
 	 */
2169
-	public function delete_related($id_or_obj,$model_name, $query_params = array()){
2169
+	public function delete_related($id_or_obj, $model_name, $query_params = array()) {
2170 2170
 		$model_obj = $this->ensure_is_obj($id_or_obj);
2171 2171
 		$relation_settings = $this->related_settings_for($model_name);
2172
-		return $relation_settings->delete_all_related($model_obj,$query_params);
2172
+		return $relation_settings->delete_all_related($model_obj, $query_params);
2173 2173
 	}
2174 2174
 
2175 2175
 
@@ -2186,10 +2186,10 @@  discard block
 block discarded – undo
2186 2186
 	 * @return int how many deleted
2187 2187
 	 * @throws \EE_Error
2188 2188
 	 */
2189
-	public function delete_related_permanently($id_or_obj,$model_name, $query_params = array()){
2189
+	public function delete_related_permanently($id_or_obj, $model_name, $query_params = array()) {
2190 2190
 		$model_obj = $this->ensure_is_obj($id_or_obj);
2191 2191
 		$relation_settings = $this->related_settings_for($model_name);
2192
-		return $relation_settings->delete_related_permanently($model_obj,$query_params);
2192
+		return $relation_settings->delete_related_permanently($model_obj, $query_params);
2193 2193
 	}
2194 2194
 
2195 2195
 
@@ -2206,17 +2206,17 @@  discard block
 block discarded – undo
2206 2206
 	 * @return int
2207 2207
 	 * @throws \EE_Error
2208 2208
 	 */
2209
-	public function count_related($id_or_obj,$model_name,$query_params = array(),$field_to_count = null, $distinct = FALSE){
2209
+	public function count_related($id_or_obj, $model_name, $query_params = array(), $field_to_count = null, $distinct = FALSE) {
2210 2210
 		$related_model = $this->get_related_model_obj($model_name);
2211 2211
 		//we're just going to use the query params on the related model's normal get_all query,
2212 2212
 		//except add a condition to say to match the current mod
2213
-		if( ! isset($query_params['default_where_conditions'])){
2214
-			$query_params['default_where_conditions']='none';
2213
+		if ( ! isset($query_params['default_where_conditions'])) {
2214
+			$query_params['default_where_conditions'] = 'none';
2215 2215
 		}
2216 2216
 		$this_model_name = $this->get_this_model_name();
2217 2217
 		$this_pk_field_name = $this->get_primary_key_field()->get_name();
2218
-		$query_params[0][$this_model_name.".".$this_pk_field_name]=$id_or_obj;
2219
-		return $related_model->count($query_params,$field_to_count,$distinct);
2218
+		$query_params[0][$this_model_name.".".$this_pk_field_name] = $id_or_obj;
2219
+		return $related_model->count($query_params, $field_to_count, $distinct);
2220 2220
 	}
2221 2221
 
2222 2222
 
@@ -2232,21 +2232,21 @@  discard block
 block discarded – undo
2232 2232
 	 * @return float
2233 2233
 	 * @throws \EE_Error
2234 2234
 	 */
2235
-	public function sum_related($id_or_obj,$model_name,$query_params,$field_to_sum = null){
2235
+	public function sum_related($id_or_obj, $model_name, $query_params, $field_to_sum = null) {
2236 2236
 		$related_model = $this->get_related_model_obj($model_name);
2237
-		if( ! is_array( $query_params ) ){
2238
-			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' );
2237
+		if ( ! is_array($query_params)) {
2238
+			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');
2239 2239
 			$query_params = array();
2240 2240
 		}
2241 2241
 		//we're just going to use the query params on the related model's normal get_all query,
2242 2242
 		//except add a condition to say to match the current mod
2243
-		if( ! isset($query_params['default_where_conditions'])){
2244
-			$query_params['default_where_conditions']='none';
2243
+		if ( ! isset($query_params['default_where_conditions'])) {
2244
+			$query_params['default_where_conditions'] = 'none';
2245 2245
 		}
2246 2246
 		$this_model_name = $this->get_this_model_name();
2247 2247
 		$this_pk_field_name = $this->get_primary_key_field()->get_name();
2248
-		$query_params[0][$this_model_name.".".$this_pk_field_name]=$id_or_obj;
2249
-		return $related_model->sum($query_params,$field_to_sum);
2248
+		$query_params[0][$this_model_name.".".$this_pk_field_name] = $id_or_obj;
2249
+		return $related_model->sum($query_params, $field_to_sum);
2250 2250
 	}
2251 2251
 
2252 2252
 
@@ -2260,12 +2260,12 @@  discard block
 block discarded – undo
2260 2260
 	 * @return EE_Base_Class
2261 2261
 	 * @throws \EE_Error
2262 2262
 	 */
2263
-	public function get_first_related( EE_Base_Class $id_or_obj, $other_model_name, $query_params ){
2264
-		$query_params['limit']=1;
2265
-		$results = $this->get_all_related($id_or_obj,$other_model_name,$query_params);
2266
-		if( $results ){
2263
+	public function get_first_related(EE_Base_Class $id_or_obj, $other_model_name, $query_params) {
2264
+		$query_params['limit'] = 1;
2265
+		$results = $this->get_all_related($id_or_obj, $other_model_name, $query_params);
2266
+		if ($results) {
2267 2267
 			return array_shift($results);
2268
-		}else{
2268
+		} else {
2269 2269
 			return null;
2270 2270
 		}
2271 2271
 
@@ -2275,8 +2275,8 @@  discard block
 block discarded – undo
2275 2275
 	 * Gets the model's name as it's expected in queries. For example, if this is EEM_Event model, that would be Event
2276 2276
 	 * @return string
2277 2277
 	 */
2278
-	public function get_this_model_name(){
2279
-		return str_replace("EEM_","",get_class($this));
2278
+	public function get_this_model_name() {
2279
+		return str_replace("EEM_", "", get_class($this));
2280 2280
 	}
2281 2281
 
2282 2282
 	/**
@@ -2284,14 +2284,14 @@  discard block
 block discarded – undo
2284 2284
 	 * @return EE_Any_Foreign_Model_Name_Field
2285 2285
 	 * @throws EE_Error
2286 2286
 	 */
2287
-	public function get_field_containing_related_model_name(){
2288
-		foreach($this->field_settings(true) as $field){
2289
-			if($field instanceof EE_Any_Foreign_Model_Name_Field){
2287
+	public function get_field_containing_related_model_name() {
2288
+		foreach ($this->field_settings(true) as $field) {
2289
+			if ($field instanceof EE_Any_Foreign_Model_Name_Field) {
2290 2290
 				$field_with_model_name = $field;
2291 2291
 			}
2292 2292
 		}
2293
-		if( !isset($field_with_model_name) || !$field_with_model_name ){
2294
-			throw new EE_Error(sprintf(__("There is no EE_Any_Foreign_Model_Name field on model %s", "event_espresso"), $this->get_this_model_name() ));
2293
+		if ( ! isset($field_with_model_name) || ! $field_with_model_name) {
2294
+			throw new EE_Error(sprintf(__("There is no EE_Any_Foreign_Model_Name field on model %s", "event_espresso"), $this->get_this_model_name()));
2295 2295
 		}
2296 2296
 		return $field_with_model_name;
2297 2297
 	}
@@ -2312,19 +2312,19 @@  discard block
 block discarded – undo
2312 2312
 	 * @return int new primary key on main table that got inserted
2313 2313
 	 * @throws EE_Error
2314 2314
 	 */
2315
-	public function insert($field_n_values){
2315
+	public function insert($field_n_values) {
2316 2316
 		/**
2317 2317
 		 * Filters the fields and their values before inserting an item using the models
2318 2318
 		 * @param array $fields_n_values keys are the fields and values are their new values
2319 2319
 		 * @param EEM_Base $model the model used
2320 2320
 		 */
2321
-		$field_n_values = (array)apply_filters( 'FHEE__EEM_Base__insert__fields_n_values', $field_n_values, $this );
2322
-		if($this->_satisfies_unique_indexes($field_n_values)){
2321
+		$field_n_values = (array) apply_filters('FHEE__EEM_Base__insert__fields_n_values', $field_n_values, $this);
2322
+		if ($this->_satisfies_unique_indexes($field_n_values)) {
2323 2323
 			$main_table = $this->_get_main_table();
2324 2324
 			$new_id = $this->_insert_into_specific_table($main_table, $field_n_values, false);
2325
-			if( $new_id !== false ) {
2326
-				foreach($this->_get_other_tables() as $other_table){
2327
-					$this->_insert_into_specific_table($other_table, $field_n_values,$new_id);
2325
+			if ($new_id !== false) {
2326
+				foreach ($this->_get_other_tables() as $other_table) {
2327
+					$this->_insert_into_specific_table($other_table, $field_n_values, $new_id);
2328 2328
 				}
2329 2329
 			}
2330 2330
 			/**
@@ -2334,9 +2334,9 @@  discard block
 block discarded – undo
2334 2334
 			 * @param array $fields_n_values fields and their values
2335 2335
 			 * @param int|string the ID of the newly-inserted model object
2336 2336
 			 */
2337
-			do_action( 'AHEE__EEM_Base__insert__end', $this, $field_n_values, $new_id );
2337
+			do_action('AHEE__EEM_Base__insert__end', $this, $field_n_values, $new_id);
2338 2338
 			return $new_id;
2339
-		}else{
2339
+		} else {
2340 2340
 			return FALSE;
2341 2341
 		}
2342 2342
 	}
@@ -2351,10 +2351,10 @@  discard block
 block discarded – undo
2351 2351
 	 * @return boolean
2352 2352
 	 * @throws \EE_Error
2353 2353
 	 */
2354
-	protected function _satisfies_unique_indexes($field_n_values,$action = 'insert'){
2355
-		foreach($this->unique_indexes() as $index_name => $index){
2354
+	protected function _satisfies_unique_indexes($field_n_values, $action = 'insert') {
2355
+		foreach ($this->unique_indexes() as $index_name => $index) {
2356 2356
 			$uniqueness_where_params = array_intersect_key($field_n_values, $index->fields());
2357
-			if($this->exists(array($uniqueness_where_params))){
2357
+			if ($this->exists(array($uniqueness_where_params))) {
2358 2358
 				EE_Error::add_error(
2359 2359
 					sprintf(
2360 2360
 						__(
@@ -2364,8 +2364,8 @@  discard block
 block discarded – undo
2364 2364
 						$action,
2365 2365
 						$this->_get_class_name(),
2366 2366
 						$index_name,
2367
-						implode( ",", $index->field_names() ),
2368
-						http_build_query( $uniqueness_where_params )
2367
+						implode(",", $index->field_names()),
2368
+						http_build_query($uniqueness_where_params)
2369 2369
 					),
2370 2370
 					__FILE__,
2371 2371
 					__FUNCTION__,
@@ -2395,37 +2395,37 @@  discard block
 block discarded – undo
2395 2395
 	 * @throws EE_Error
2396 2396
 	 * @return EE_Base_Class|array
2397 2397
 	 */
2398
-	public function get_one_conflicting($obj_or_fields_array, $include_primary_key = true ){
2399
-		if($obj_or_fields_array instanceof EE_Base_Class){
2398
+	public function get_one_conflicting($obj_or_fields_array, $include_primary_key = true) {
2399
+		if ($obj_or_fields_array instanceof EE_Base_Class) {
2400 2400
 			$fields_n_values = $obj_or_fields_array->model_field_array();
2401
-		}elseif( is_array($obj_or_fields_array)){
2401
+		}elseif (is_array($obj_or_fields_array)) {
2402 2402
 			$fields_n_values = $obj_or_fields_array;
2403
-		}else{
2403
+		} else {
2404 2404
 			throw new EE_Error(
2405 2405
 				sprintf(
2406 2406
 					__(
2407 2407
 						"%s get_all_conflicting should be called with a model object or an array of field names and values, you provided %d",
2408 2408
 						"event_espresso"
2409 2409
 					),
2410
-					get_class( $this ),
2410
+					get_class($this),
2411 2411
 					$obj_or_fields_array
2412 2412
 				)
2413 2413
 			);
2414 2414
 		}
2415 2415
 		$query_params = array();
2416
-		if( $this->has_primary_key_field() &&
2417
-				( $include_primary_key || $this->get_primary_key_field() instanceof EE_Primary_Key_String_Field) &&
2418
-				isset($fields_n_values[$this->primary_key_name()])){
2416
+		if ($this->has_primary_key_field() &&
2417
+				($include_primary_key || $this->get_primary_key_field() instanceof EE_Primary_Key_String_Field) &&
2418
+				isset($fields_n_values[$this->primary_key_name()])) {
2419 2419
 			$query_params[0]['OR'][$this->primary_key_name()] = $fields_n_values[$this->primary_key_name()];
2420 2420
 		}
2421
-		foreach($this->unique_indexes() as $unique_index_name=>$unique_index){
2421
+		foreach ($this->unique_indexes() as $unique_index_name=>$unique_index) {
2422 2422
 			$uniqueness_where_params = array_intersect_key($fields_n_values, $unique_index->fields());
2423 2423
 			$query_params[0]['OR']['AND*'.$unique_index_name] = $uniqueness_where_params;
2424 2424
 		}
2425 2425
 		//if there is nothing to base this search on, then we shouldn't find anything
2426
-		if( empty( $query_params ) ){
2426
+		if (empty($query_params)) {
2427 2427
 			return array();
2428
-		}else{
2428
+		} else {
2429 2429
 			return $this->get_one($query_params);
2430 2430
 		}
2431 2431
 	}
@@ -2439,7 +2439,7 @@  discard block
 block discarded – undo
2439 2439
 	 * @return boolean
2440 2440
 	 * @throws \EE_Error
2441 2441
 	 */
2442
-	public function exists($query_params){
2442
+	public function exists($query_params) {
2443 2443
 		$query_params['limit'] = 1;
2444 2444
 		return $this->count($query_params) > 0;
2445 2445
 	}
@@ -2453,7 +2453,7 @@  discard block
 block discarded – undo
2453 2453
 	 * @return boolean
2454 2454
 	 * @throws \EE_Error
2455 2455
 	 */
2456
-	public function exists_by_ID($id){
2456
+	public function exists_by_ID($id) {
2457 2457
 		return $this->exists(array('default_where_conditions'=>'none', array($this->primary_key_name() => $id)));
2458 2458
 	}
2459 2459
 
@@ -2473,45 +2473,45 @@  discard block
 block discarded – undo
2473 2473
 	 * @global WPDB $wpdb only used to get the $wpdb->insert_id after performing an insert
2474 2474
 	 * @return int ID of new row inserted, or FALSE on failure
2475 2475
 	 */
2476
-	protected function _insert_into_specific_table(EE_Table_Base $table, $fields_n_values, $new_id = 0 ){
2476
+	protected function _insert_into_specific_table(EE_Table_Base $table, $fields_n_values, $new_id = 0) {
2477 2477
 		global $wpdb;
2478 2478
 		$insertion_col_n_values = array();
2479 2479
 		$format_for_insertion = array();
2480 2480
 		$fields_on_table = $this->_get_fields_for_table($table->get_table_alias());
2481
-		foreach($fields_on_table as $field_name => $field_obj){
2481
+		foreach ($fields_on_table as $field_name => $field_obj) {
2482 2482
 			//check if its an auto-incrementing column, in which case we should just leave it to do its autoincrement thing
2483
-			if($field_obj->is_auto_increment()){
2483
+			if ($field_obj->is_auto_increment()) {
2484 2484
 				continue;
2485 2485
 			}
2486 2486
 			$prepared_value = $this->_prepare_value_or_use_default($field_obj, $fields_n_values);
2487 2487
 			//if the value we want to assign it to is NULL, just don't mention it for the insertion
2488
-			if( $prepared_value !== NULL ){
2489
-				$insertion_col_n_values[ $field_obj->get_table_column() ] = $prepared_value;
2488
+			if ($prepared_value !== NULL) {
2489
+				$insertion_col_n_values[$field_obj->get_table_column()] = $prepared_value;
2490 2490
 				$format_for_insertion[] = $field_obj->get_wpdb_data_type();
2491 2491
 			}
2492 2492
 		}
2493 2493
 
2494
-		if($table instanceof EE_Secondary_Table && $new_id){
2494
+		if ($table instanceof EE_Secondary_Table && $new_id) {
2495 2495
 			//its not the main table, so we should have already saved the main table's PK which we just inserted
2496 2496
 			//so add the fk to the main table as a column
2497 2497
 			$insertion_col_n_values[$table->get_fk_on_table()] = $new_id;
2498
-			$format_for_insertion[]='%d';//yes right now we're only allowing these foreign keys to be INTs
2498
+			$format_for_insertion[] = '%d'; //yes right now we're only allowing these foreign keys to be INTs
2499 2499
 		}
2500 2500
 		//insert the new entry
2501
-		$result = $this->_do_wpdb_query( 'insert', array( $table->get_table_name(), $insertion_col_n_values, $format_for_insertion ) );
2502
-		if( $result === false ) {
2501
+		$result = $this->_do_wpdb_query('insert', array($table->get_table_name(), $insertion_col_n_values, $format_for_insertion));
2502
+		if ($result === false) {
2503 2503
 			return false;
2504 2504
 		}
2505 2505
 		//ok, now what do we return for the ID of the newly-inserted thing?
2506
-		if($this->has_primary_key_field()){
2507
-			if($this->get_primary_key_field()->is_auto_increment()){
2506
+		if ($this->has_primary_key_field()) {
2507
+			if ($this->get_primary_key_field()->is_auto_increment()) {
2508 2508
 				return $wpdb->insert_id;
2509
-			}else{
2509
+			} else {
2510 2510
 				//it's not an auto-increment primary key, so
2511 2511
 				//it must have been supplied
2512 2512
 				return $fields_n_values[$this->get_primary_key_field()->get_name()];
2513 2513
 			}
2514
-		}else{
2514
+		} else {
2515 2515
 			//we can't return a  primary key because there is none. instead return
2516 2516
 			//a unique string indicating this model
2517 2517
 			return $this->get_index_primary_key_string($fields_n_values);
@@ -2530,15 +2530,15 @@  discard block
 block discarded – undo
2530 2530
 	 * @return mixed string|int|float depending on what the table column will be expecting
2531 2531
 	 * @throws \EE_Error
2532 2532
 	 */
2533
-	protected function _prepare_value_or_use_default( $field_obj, $fields_n_values ){
2533
+	protected function _prepare_value_or_use_default($field_obj, $fields_n_values) {
2534 2534
 		//if this field doesn't allow nullable, don't allow it
2535
-		if( ! $field_obj->is_nullable() && (
2536
-				! isset( $fields_n_values[ $field_obj->get_name() ] ) ||
2537
-				$fields_n_values[ $field_obj->get_name() ] === NULL ) ){
2538
-			$fields_n_values[ $field_obj->get_name() ] = $field_obj->get_default_value();
2535
+		if ( ! $field_obj->is_nullable() && (
2536
+				! isset($fields_n_values[$field_obj->get_name()]) ||
2537
+				$fields_n_values[$field_obj->get_name()] === NULL )) {
2538
+			$fields_n_values[$field_obj->get_name()] = $field_obj->get_default_value();
2539 2539
 		}
2540
-		$unprepared_value = isset( $fields_n_values[ $field_obj->get_name() ] ) ? $fields_n_values[ $field_obj->get_name() ] : NULL;
2541
-		return $this->_prepare_value_for_use_in_db( $unprepared_value, $field_obj);
2540
+		$unprepared_value = isset($fields_n_values[$field_obj->get_name()]) ? $fields_n_values[$field_obj->get_name()] : NULL;
2541
+		return $this->_prepare_value_for_use_in_db($unprepared_value, $field_obj);
2542 2542
 	}
2543 2543
 
2544 2544
 
@@ -2550,9 +2550,9 @@  discard block
 block discarded – undo
2550 2550
 	 * @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
2551 2551
 	 * @return mixed a value ready for use in the database for insertions, updating, or in a where clause
2552 2552
 	 */
2553
-	private function _prepare_value_for_use_in_db($value, $field){
2554
-		if($field && $field instanceof EE_Model_Field_Base){
2555
-			switch( $this->_values_already_prepared_by_model_object ){
2553
+	private function _prepare_value_for_use_in_db($value, $field) {
2554
+		if ($field && $field instanceof EE_Model_Field_Base) {
2555
+			switch ($this->_values_already_prepared_by_model_object) {
2556 2556
 				/** @noinspection PhpMissingBreakStatementInspection */
2557 2557
 				case self::not_prepared_by_model_object:
2558 2558
 					$value = $field->prepare_for_set($value);
@@ -2563,7 +2563,7 @@  discard block
 block discarded – undo
2563 2563
 					//leave the value alone
2564 2564
 			}
2565 2565
 			return $value;
2566
-		}else{
2566
+		} else {
2567 2567
 			return $value;
2568 2568
 		}
2569 2569
 	}
@@ -2573,13 +2573,13 @@  discard block
 block discarded – undo
2573 2573
 	 * @return EE_Primary_Table
2574 2574
 	 * @throws EE_Error
2575 2575
 	 */
2576
-	protected function _get_main_table(){
2577
-		foreach($this->_tables as $table){
2578
-			if($table instanceof EE_Primary_Table){
2576
+	protected function _get_main_table() {
2577
+		foreach ($this->_tables as $table) {
2578
+			if ($table instanceof EE_Primary_Table) {
2579 2579
 				return $table;
2580 2580
 			}
2581 2581
 		}
2582
-		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)));
2582
+		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)));
2583 2583
 	}
2584 2584
 
2585 2585
 
@@ -2602,7 +2602,7 @@  discard block
 block discarded – undo
2602 2602
 	 */
2603 2603
 	public function second_table() {
2604 2604
 		// grab second table from tables array
2605
-		$second_table = end( $this->_tables );
2605
+		$second_table = end($this->_tables);
2606 2606
 		return $second_table instanceof EE_Secondary_Table ? $second_table->get_table_name() : NULL;
2607 2607
 	}
2608 2608
 
@@ -2615,8 +2615,8 @@  discard block
 block discarded – undo
2615 2615
 	 * @param string $table_alias
2616 2616
 	 * @return EE_Primary_Table | EE_Secondary_Table
2617 2617
 	 */
2618
-	public function get_table_obj_by_alias( $table_alias = '' ) {
2619
-		return isset( $this->_tables[ $table_alias ] ) ? $this->_tables[ $table_alias ] : NULL;
2618
+	public function get_table_obj_by_alias($table_alias = '') {
2619
+		return isset($this->_tables[$table_alias]) ? $this->_tables[$table_alias] : NULL;
2620 2620
 	}
2621 2621
 
2622 2622
 
@@ -2625,10 +2625,10 @@  discard block
 block discarded – undo
2625 2625
 	 * Gets all the tables of type EE_Other_Table from EEM_CPT_Basel_Model::_tables
2626 2626
 	 * @return EE_Secondary_Table[]
2627 2627
 	 */
2628
-	protected function _get_other_tables(){
2629
-		$other_tables =array();
2630
-		foreach($this->_tables as $table_alias => $table){
2631
-			if($table instanceof EE_Secondary_Table){
2628
+	protected function _get_other_tables() {
2629
+		$other_tables = array();
2630
+		foreach ($this->_tables as $table_alias => $table) {
2631
+			if ($table instanceof EE_Secondary_Table) {
2632 2632
 				$other_tables[$table_alias] = $table;
2633 2633
 			}
2634 2634
 		}
@@ -2640,7 +2640,7 @@  discard block
 block discarded – undo
2640 2640
 	 * @param string $table_alias, array key in EEM_Base::_tables
2641 2641
 	 * @return EE_Model_Field_Base[]
2642 2642
 	 */
2643
-	public function _get_fields_for_table($table_alias){
2643
+	public function _get_fields_for_table($table_alias) {
2644 2644
 		return $this->_fields[$table_alias];
2645 2645
 	}
2646 2646
 
@@ -2656,19 +2656,19 @@  discard block
 block discarded – undo
2656 2656
 	 * @return EE_Model_Query_Info_Carrier
2657 2657
 	 * @throws \EE_Error
2658 2658
 	 */
2659
-	public function _extract_related_models_from_query($query_params){
2659
+	public function _extract_related_models_from_query($query_params) {
2660 2660
 		$query_info_carrier = new EE_Model_Query_Info_Carrier();
2661
-		if ( array_key_exists( 0, $query_params ) ) {
2662
-			$this->_extract_related_models_from_sub_params_array_keys( $query_params[0], $query_info_carrier, 0 );
2661
+		if (array_key_exists(0, $query_params)) {
2662
+			$this->_extract_related_models_from_sub_params_array_keys($query_params[0], $query_info_carrier, 0);
2663 2663
 		}
2664
-		if ( array_key_exists( 'group_by', $query_params ) ) {
2665
-			if ( is_array( $query_params['group_by'] ) ) {
2664
+		if (array_key_exists('group_by', $query_params)) {
2665
+			if (is_array($query_params['group_by'])) {
2666 2666
 				$this->_extract_related_models_from_sub_params_array_values(
2667 2667
 					$query_params['group_by'],
2668 2668
 					$query_info_carrier,
2669 2669
 					'group_by'
2670 2670
 				);
2671
-			} elseif ( ! empty ( $query_params['group_by'] ) ) {
2671
+			} elseif ( ! empty ($query_params['group_by'])) {
2672 2672
 				$this->_extract_related_model_info_from_query_param(
2673 2673
 					$query_params['group_by'],
2674 2674
 					$query_info_carrier,
@@ -2676,21 +2676,21 @@  discard block
 block discarded – undo
2676 2676
 				);
2677 2677
 			}
2678 2678
 		}
2679
-		if ( array_key_exists( 'having', $query_params ) ) {
2679
+		if (array_key_exists('having', $query_params)) {
2680 2680
 			$this->_extract_related_models_from_sub_params_array_keys(
2681 2681
 				$query_params[0],
2682 2682
 				$query_info_carrier,
2683 2683
 				'having'
2684 2684
 			);
2685 2685
 		}
2686
-		if ( array_key_exists( 'order_by', $query_params ) ) {
2687
-			if ( is_array( $query_params['order_by'] ) ) {
2686
+		if (array_key_exists('order_by', $query_params)) {
2687
+			if (is_array($query_params['order_by'])) {
2688 2688
 				$this->_extract_related_models_from_sub_params_array_keys(
2689 2689
 					$query_params['order_by'],
2690 2690
 					$query_info_carrier,
2691 2691
 					'order_by'
2692 2692
 				);
2693
-			} elseif ( ! empty( $query_params['order_by'] ) ) {
2693
+			} elseif ( ! empty($query_params['order_by'])) {
2694 2694
 				$this->_extract_related_model_info_from_query_param(
2695 2695
 					$query_params['order_by'],
2696 2696
 					$query_info_carrier,
@@ -2698,7 +2698,7 @@  discard block
 block discarded – undo
2698 2698
 				);
2699 2699
 			}
2700 2700
 		}
2701
-		if ( array_key_exists( 'force_join', $query_params ) ) {
2701
+		if (array_key_exists('force_join', $query_params)) {
2702 2702
 			$this->_extract_related_models_from_sub_params_array_values(
2703 2703
 				$query_params['force_join'],
2704 2704
 				$query_info_carrier,
@@ -2716,34 +2716,34 @@  discard block
 block discarded – undo
2716 2716
 	 * @throws EE_Error
2717 2717
 	 * @return \EE_Model_Query_Info_Carrier
2718 2718
 	 */
2719
-	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){
2720
-		if (!empty($sub_query_params)){
2719
+	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) {
2720
+		if ( ! empty($sub_query_params)) {
2721 2721
 			$sub_query_params = (array) $sub_query_params;
2722
-			foreach($sub_query_params as $param => $possibly_array_of_params){
2722
+			foreach ($sub_query_params as $param => $possibly_array_of_params) {
2723 2723
 				//$param could be simply 'EVT_ID', or it could be 'Registrations.REG_ID', or even 'Registrations.Transactions.Payments.PAY_amount'
2724
-				$this->_extract_related_model_info_from_query_param( $param, $model_query_info_carrier,$query_param_type);
2724
+				$this->_extract_related_model_info_from_query_param($param, $model_query_info_carrier, $query_param_type);
2725 2725
 
2726 2726
 				//if $possibly_array_of_params is an array, try recursing into it, searching for keys which
2727 2727
 				//indicate needed joins. Eg, array('NOT'=>array('Registration.TXN_ID'=>23)). In this case, we tried
2728 2728
 				//extracting models out of the 'NOT', which obviously wasn't successful, and then we recurse into the value
2729 2729
 				//of array('Registration.TXN_ID'=>23)
2730 2730
 				$query_param_sans_stars = $this->_remove_stars_and_anything_after_from_condition_query_param_key($param);
2731
-				if(in_array($query_param_sans_stars, $this->_logic_query_param_keys,true)){
2732
-					if (! is_array($possibly_array_of_params)){
2731
+				if (in_array($query_param_sans_stars, $this->_logic_query_param_keys, true)) {
2732
+					if ( ! is_array($possibly_array_of_params)) {
2733 2733
 						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"),
2734
-							$param,$possibly_array_of_params));
2735
-					}else{
2736
-						$this->_extract_related_models_from_sub_params_array_keys($possibly_array_of_params, $model_query_info_carrier,$query_param_type);
2734
+							$param, $possibly_array_of_params));
2735
+					} else {
2736
+						$this->_extract_related_models_from_sub_params_array_keys($possibly_array_of_params, $model_query_info_carrier, $query_param_type);
2737 2737
 					}
2738
-				}elseif($query_param_type === 0 //ie WHERE
2738
+				}elseif ($query_param_type === 0 //ie WHERE
2739 2739
 						&& is_array($possibly_array_of_params)
2740 2740
 						&& isset($possibly_array_of_params[2])
2741
-						&& $possibly_array_of_params[2] == true){
2741
+						&& $possibly_array_of_params[2] == true) {
2742 2742
 					//then $possible_array_of_params looks something like array('<','DTT_sold',true)
2743 2743
 					//indicating that $possible_array_of_params[1] is actually a field name,
2744 2744
 					//from which we should extract query parameters!
2745
-					if( ! isset($possibly_array_of_params[0], $possibly_array_of_params[1] ) ) {
2746
-						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)));
2745
+					if ( ! isset($possibly_array_of_params[0], $possibly_array_of_params[1])) {
2746
+						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)));
2747 2747
 					}
2748 2748
 					$this->_extract_related_model_info_from_query_param($possibly_array_of_params[1], $model_query_info_carrier, $query_param_type);
2749 2749
 				}
@@ -2762,14 +2762,14 @@  discard block
 block discarded – undo
2762 2762
 	 * @throws EE_Error
2763 2763
 	 * @return \EE_Model_Query_Info_Carrier
2764 2764
 	 */
2765
-	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){
2766
-		if (!empty($sub_query_params)){
2767
-			if(!is_array($sub_query_params)){
2768
-				throw new EE_Error(sprintf(__("Query parameter %s should be an array, but it isn't.", "event_espresso"),$sub_query_params));
2765
+	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) {
2766
+		if ( ! empty($sub_query_params)) {
2767
+			if ( ! is_array($sub_query_params)) {
2768
+				throw new EE_Error(sprintf(__("Query parameter %s should be an array, but it isn't.", "event_espresso"), $sub_query_params));
2769 2769
 			}
2770
-			foreach($sub_query_params as $param){
2770
+			foreach ($sub_query_params as $param) {
2771 2771
 				//$param could be simply 'EVT_ID', or it could be 'Registrations.REG_ID', or even 'Registrations.Transactions.Payments.PAY_amount'
2772
-				$this->_extract_related_model_info_from_query_param( $param, $model_query_info_carrier, $query_param_type);
2772
+				$this->_extract_related_model_info_from_query_param($param, $model_query_info_carrier, $query_param_type);
2773 2773
 			}
2774 2774
 		}
2775 2775
 		return $model_query_info_carrier;
@@ -2788,8 +2788,8 @@  discard block
 block discarded – undo
2788 2788
 	 * @throws EE_Error
2789 2789
 	 * @return EE_Model_Query_Info_Carrier
2790 2790
 	 */
2791
-	public function _create_model_query_info_carrier($query_params){
2792
-		if ( ! is_array( $query_params ) ) {
2791
+	public function _create_model_query_info_carrier($query_params) {
2792
+		if ( ! is_array($query_params)) {
2793 2793
 			EE_Error::doing_it_wrong(
2794 2794
 				'EEM_Base::_create_model_query_info_carrier',
2795 2795
 				sprintf(
@@ -2797,16 +2797,16 @@  discard block
 block discarded – undo
2797 2797
 						'$query_params should be an array, you passed a variable of type %s',
2798 2798
 						'event_espresso'
2799 2799
 					),
2800
-					gettype( $query_params )
2800
+					gettype($query_params)
2801 2801
 				),
2802 2802
 				'4.6.0'
2803 2803
 			);
2804 2804
 			$query_params = array();
2805 2805
 		}
2806
-		$where_query_params = isset( $query_params[0] ) ? $query_params[0] : array();
2806
+		$where_query_params = isset($query_params[0]) ? $query_params[0] : array();
2807 2807
 		//first check if we should alter the query to account for caps or not
2808 2808
 		//because the caps might require us to do extra joins
2809
-		if ( isset( $query_params['caps'] ) && $query_params['caps'] !== 'none' ) {
2809
+		if (isset($query_params['caps']) && $query_params['caps'] !== 'none') {
2810 2810
 			$query_params[0] = $where_query_params = array_replace_recursive(
2811 2811
 				$where_query_params,
2812 2812
 				$this->caps_where_conditions(
@@ -2814,10 +2814,10 @@  discard block
 block discarded – undo
2814 2814
 				)
2815 2815
 			);
2816 2816
 		}
2817
-		$query_object = $this->_extract_related_models_from_query( $query_params );
2817
+		$query_object = $this->_extract_related_models_from_query($query_params);
2818 2818
 		//verify where_query_params has NO numeric indexes.... that's simply not how you use it!
2819
-		foreach ( $where_query_params as $key => $value ) {
2820
-			if ( is_int( $key ) ) {
2819
+		foreach ($where_query_params as $key => $value) {
2820
+			if (is_int($key)) {
2821 2821
 				throw new EE_Error(
2822 2822
 					sprintf(
2823 2823
 						__(
@@ -2825,16 +2825,16 @@  discard block
 block discarded – undo
2825 2825
 							"event_espresso"
2826 2826
 						),
2827 2827
 						$key,
2828
-						var_export( $value, true ),
2829
-						var_export( $query_params, true ),
2830
-						get_class( $this )
2828
+						var_export($value, true),
2829
+						var_export($query_params, true),
2830
+						get_class($this)
2831 2831
 					)
2832 2832
 				);
2833 2833
 			}
2834 2834
 		}
2835 2835
 		if (
2836
-			array_key_exists( 'default_where_conditions', $query_params )
2837
-			&& ! empty( $query_params['default_where_conditions'] )
2836
+			array_key_exists('default_where_conditions', $query_params)
2837
+			&& ! empty($query_params['default_where_conditions'])
2838 2838
 		) {
2839 2839
 			$use_default_where_conditions = $query_params['default_where_conditions'];
2840 2840
 		} else {
@@ -2848,13 +2848,13 @@  discard block
 block discarded – undo
2848 2848
 			),
2849 2849
 			$where_query_params
2850 2850
 		);
2851
-		$query_object->set_where_sql( $this->_construct_where_clause( $where_query_params ) );
2851
+		$query_object->set_where_sql($this->_construct_where_clause($where_query_params));
2852 2852
 		// if this is a "on_join_limit" then we are limiting on on a specific table in a multi_table join.
2853 2853
 		// So we need to setup a subquery and use that for the main join.
2854 2854
 		// Note for now this only works on the primary table for the model.
2855 2855
 		// So for instance, you could set the limit array like this:
2856 2856
 		// array( 'on_join_limit' => array('Primary_Table_Alias', array(1,10) ) )
2857
-		if ( array_key_exists( 'on_join_limit', $query_params ) && ! empty( $query_params['on_join_limit'] ) ) {
2857
+		if (array_key_exists('on_join_limit', $query_params) && ! empty($query_params['on_join_limit'])) {
2858 2858
 			$query_object->set_main_model_join_sql(
2859 2859
 				$this->_construct_limit_join_select(
2860 2860
 					$query_params['on_join_limit'][0],
@@ -2863,40 +2863,40 @@  discard block
 block discarded – undo
2863 2863
 			);
2864 2864
 		}
2865 2865
 		//set limit
2866
-		if ( array_key_exists( 'limit', $query_params ) ) {
2867
-			if ( is_array( $query_params['limit'] ) ) {
2868
-				if ( ! isset( $query_params['limit'][0], $query_params['limit'][1] ) ) {
2866
+		if (array_key_exists('limit', $query_params)) {
2867
+			if (is_array($query_params['limit'])) {
2868
+				if ( ! isset($query_params['limit'][0], $query_params['limit'][1])) {
2869 2869
 					$e = sprintf(
2870 2870
 						__(
2871 2871
 							"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)",
2872 2872
 							"event_espresso"
2873 2873
 						),
2874
-						http_build_query( $query_params['limit'] )
2874
+						http_build_query($query_params['limit'])
2875 2875
 					);
2876
-					throw new EE_Error( $e . "|" . $e );
2876
+					throw new EE_Error($e."|".$e);
2877 2877
 				}
2878 2878
 				//they passed us an array for the limit. Assume it's like array(50,25), meaning offset by 50, and get 25
2879
-				$query_object->set_limit_sql( " LIMIT " . $query_params['limit'][0] . "," . $query_params['limit'][1] );
2880
-			} elseif ( ! empty ( $query_params['limit'] ) ) {
2881
-				$query_object->set_limit_sql( " LIMIT " . $query_params['limit'] );
2879
+				$query_object->set_limit_sql(" LIMIT ".$query_params['limit'][0].",".$query_params['limit'][1]);
2880
+			} elseif ( ! empty ($query_params['limit'])) {
2881
+				$query_object->set_limit_sql(" LIMIT ".$query_params['limit']);
2882 2882
 			}
2883 2883
 		}
2884 2884
 		//set order by
2885
-		if ( array_key_exists( 'order_by', $query_params ) ) {
2886
-			if ( is_array( $query_params['order_by'] ) ) {
2885
+		if (array_key_exists('order_by', $query_params)) {
2886
+			if (is_array($query_params['order_by'])) {
2887 2887
 				//if they're using 'order_by' as an array, they can't use 'order' (because 'order_by' must
2888 2888
 				//specify whether to ascend or descend on each field. Eg 'order_by'=>array('EVT_ID'=>'ASC'). So
2889 2889
 				//including 'order' wouldn't make any sense if 'order_by' has already specified which way to order!
2890
-				if ( array_key_exists( 'order', $query_params ) ) {
2890
+				if (array_key_exists('order', $query_params)) {
2891 2891
 					throw new EE_Error(
2892 2892
 						sprintf(
2893 2893
 							__(
2894 2894
 								"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 ",
2895 2895
 								"event_espresso"
2896 2896
 							),
2897
-							get_class( $this ),
2898
-							implode( ", ", array_keys( $query_params['order_by'] ) ),
2899
-							implode( ", ", $query_params['order_by'] ),
2897
+							get_class($this),
2898
+							implode(", ", array_keys($query_params['order_by'])),
2899
+							implode(", ", $query_params['order_by']),
2900 2900
 							$query_params['order']
2901 2901
 						)
2902 2902
 					);
@@ -2908,57 +2908,57 @@  discard block
 block discarded – undo
2908 2908
 				);
2909 2909
 				//assume it's an array of fields to order by
2910 2910
 				$order_array = array();
2911
-				foreach ( $query_params['order_by'] as $field_name_to_order_by => $order ) {
2912
-					$order = $this->_extract_order( $order );
2913
-					$order_array[] = $this->_deduce_column_name_from_query_param( $field_name_to_order_by ) . SP . $order;
2911
+				foreach ($query_params['order_by'] as $field_name_to_order_by => $order) {
2912
+					$order = $this->_extract_order($order);
2913
+					$order_array[] = $this->_deduce_column_name_from_query_param($field_name_to_order_by).SP.$order;
2914 2914
 				}
2915
-				$query_object->set_order_by_sql( " ORDER BY " . implode( ",", $order_array ) );
2916
-			} elseif ( ! empty ( $query_params['order_by'] ) ) {
2915
+				$query_object->set_order_by_sql(" ORDER BY ".implode(",", $order_array));
2916
+			} elseif ( ! empty ($query_params['order_by'])) {
2917 2917
 				$this->_extract_related_model_info_from_query_param(
2918 2918
 					$query_params['order_by'],
2919 2919
 					$query_object,
2920 2920
 					'order',
2921 2921
 					$query_params['order_by']
2922 2922
 				);
2923
-				$order = isset( $query_params['order'] )
2924
-					? $this->_extract_order( $query_params['order'] )
2923
+				$order = isset($query_params['order'])
2924
+					? $this->_extract_order($query_params['order'])
2925 2925
 					: 'DESC';
2926 2926
 				$query_object->set_order_by_sql(
2927
-					" ORDER BY " . $this->_deduce_column_name_from_query_param( $query_params['order_by'] ) . SP . $order
2927
+					" ORDER BY ".$this->_deduce_column_name_from_query_param($query_params['order_by']).SP.$order
2928 2928
 				);
2929 2929
 			}
2930 2930
 		}
2931 2931
 		//if 'order_by' wasn't set, maybe they are just using 'order' on its own?
2932
-		if ( ! array_key_exists( 'order_by', $query_params )
2933
-		     && array_key_exists( 'order', $query_params )
2934
-		     && ! empty( $query_params['order'] )
2932
+		if ( ! array_key_exists('order_by', $query_params)
2933
+		     && array_key_exists('order', $query_params)
2934
+		     && ! empty($query_params['order'])
2935 2935
 		) {
2936 2936
 			$pk_field = $this->get_primary_key_field();
2937
-			$order = $this->_extract_order( $query_params['order'] );
2938
-			$query_object->set_order_by_sql( " ORDER BY " . $pk_field->get_qualified_column() . SP . $order );
2937
+			$order = $this->_extract_order($query_params['order']);
2938
+			$query_object->set_order_by_sql(" ORDER BY ".$pk_field->get_qualified_column().SP.$order);
2939 2939
 		}
2940 2940
 		//set group by
2941
-		if ( array_key_exists( 'group_by', $query_params ) ) {
2942
-			if ( is_array( $query_params['group_by'] ) ) {
2941
+		if (array_key_exists('group_by', $query_params)) {
2942
+			if (is_array($query_params['group_by'])) {
2943 2943
 				//it's an array, so assume we'll be grouping by a bunch of stuff
2944 2944
 				$group_by_array = array();
2945
-				foreach ( $query_params['group_by'] as $field_name_to_group_by ) {
2946
-					$group_by_array[] = $this->_deduce_column_name_from_query_param( $field_name_to_group_by );
2945
+				foreach ($query_params['group_by'] as $field_name_to_group_by) {
2946
+					$group_by_array[] = $this->_deduce_column_name_from_query_param($field_name_to_group_by);
2947 2947
 				}
2948
-				$query_object->set_group_by_sql( " GROUP BY " . implode( ", ", $group_by_array ) );
2949
-			} elseif ( ! empty ( $query_params['group_by'] ) ) {
2948
+				$query_object->set_group_by_sql(" GROUP BY ".implode(", ", $group_by_array));
2949
+			} elseif ( ! empty ($query_params['group_by'])) {
2950 2950
 				$query_object->set_group_by_sql(
2951
-					" GROUP BY " . $this->_deduce_column_name_from_query_param( $query_params['group_by'] )
2951
+					" GROUP BY ".$this->_deduce_column_name_from_query_param($query_params['group_by'])
2952 2952
 				);
2953 2953
 			}
2954 2954
 		}
2955 2955
 		//set having
2956
-		if ( array_key_exists( 'having', $query_params ) && $query_params['having'] ) {
2957
-			$query_object->set_having_sql( $this->_construct_having_clause( $query_params['having'] ) );
2956
+		if (array_key_exists('having', $query_params) && $query_params['having']) {
2957
+			$query_object->set_having_sql($this->_construct_having_clause($query_params['having']));
2958 2958
 		}
2959 2959
 		//now, just verify they didn't pass anything wack
2960
-		foreach ( $query_params as $query_key => $query_value ) {
2961
-			if ( ! in_array( $query_key, $this->_allowed_query_params, true ) ) {
2960
+		foreach ($query_params as $query_key => $query_value) {
2961
+			if ( ! in_array($query_key, $this->_allowed_query_params, true)) {
2962 2962
 				throw new EE_Error(
2963 2963
 					sprintf(
2964 2964
 						__(
@@ -2966,16 +2966,16 @@  discard block
 block discarded – undo
2966 2966
 							'event_espresso'
2967 2967
 						),
2968 2968
 						$query_key,
2969
-						get_class( $this ),
2969
+						get_class($this),
2970 2970
 //						print_r( $this->_allowed_query_params, TRUE )
2971
-						implode( ',', $this->_allowed_query_params )
2971
+						implode(',', $this->_allowed_query_params)
2972 2972
 					)
2973 2973
 				);
2974 2974
 			}
2975 2975
 		}
2976 2976
 		$main_model_join_sql = $query_object->get_main_model_join_sql();
2977
-		if ( empty( $main_model_join_sql ) ) {
2978
-			$query_object->set_main_model_join_sql( $this->_construct_internal_join() );
2977
+		if (empty($main_model_join_sql)) {
2978
+			$query_object->set_main_model_join_sql($this->_construct_internal_join());
2979 2979
 		}
2980 2980
 		return $query_object;
2981 2981
 	}
@@ -2990,17 +2990,17 @@  discard block
 block discarded – undo
2990 2990
 	 * @return array like EEM_Base::get_all() 's $query_params[0]
2991 2991
 	 * @throws \EE_Error
2992 2992
 	 */
2993
-	public function caps_where_conditions( $context = self::caps_read ) {
2994
-		EEM_Base::verify_is_valid_cap_context( $context );
2993
+	public function caps_where_conditions($context = self::caps_read) {
2994
+		EEM_Base::verify_is_valid_cap_context($context);
2995 2995
 		$cap_where_conditions = array();
2996
-		$cap_restrictions = $this->caps_missing( $context );
2996
+		$cap_restrictions = $this->caps_missing($context);
2997 2997
 		/**
2998 2998
 		 * @var $cap_restrictions EE_Default_Where_Conditions[]
2999 2999
 		 */
3000
-		foreach( $cap_restrictions as $cap => $restriction_if_no_cap ) {
3001
-				$cap_where_conditions = array_replace_recursive( $cap_where_conditions, $restriction_if_no_cap->get_default_where_conditions() );
3000
+		foreach ($cap_restrictions as $cap => $restriction_if_no_cap) {
3001
+				$cap_where_conditions = array_replace_recursive($cap_where_conditions, $restriction_if_no_cap->get_default_where_conditions());
3002 3002
 		}
3003
-		return apply_filters( 'FHEE__EEM_Base__caps_where_conditions__return', $cap_where_conditions, $this, $context, $cap_restrictions );
3003
+		return apply_filters('FHEE__EEM_Base__caps_where_conditions__return', $cap_where_conditions, $this, $context, $cap_restrictions);
3004 3004
 	}
3005 3005
 
3006 3006
 	/**
@@ -3010,11 +3010,11 @@  discard block
 block discarded – undo
3010 3010
 	 * @return string either ASC, asc, DESC or desc
3011 3011
 	 * @throws EE_Error
3012 3012
 	 */
3013
-	private function _extract_order($should_be_order_string){
3014
-		if(in_array($should_be_order_string, $this->_allowed_order_values)){
3013
+	private function _extract_order($should_be_order_string) {
3014
+		if (in_array($should_be_order_string, $this->_allowed_order_values)) {
3015 3015
 			return $should_be_order_string;
3016
-		}else{
3017
-			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));
3016
+		} else {
3017
+			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));
3018 3018
 		}
3019 3019
 	}
3020 3020
 
@@ -3032,7 +3032,7 @@  discard block
 block discarded – undo
3032 3032
 	 * @throws EE_Error
3033 3033
 	 * @return array like $query_params[0], see EEM_Base::get_all for documentation
3034 3034
 	 */
3035
-	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()){
3035
+	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()) {
3036 3036
 		$allowed_used_default_where_conditions_values = array(
3037 3037
 				'all',
3038 3038
 				'this_model_only',
@@ -3040,17 +3040,17 @@  discard block
 block discarded – undo
3040 3040
 				'minimum',
3041 3041
 				'none'
3042 3042
 			);
3043
-		if( ! in_array($use_default_where_conditions,$allowed_used_default_where_conditions_values)){
3044
-			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)));
3043
+		if ( ! in_array($use_default_where_conditions, $allowed_used_default_where_conditions_values)) {
3044
+			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)));
3045 3045
 		}
3046 3046
 		$universal_query_params = array();
3047
-		if( $use_default_where_conditions === 'all' || $use_default_where_conditions === 'this_model_only' ){
3047
+		if ($use_default_where_conditions === 'all' || $use_default_where_conditions === 'this_model_only') {
3048 3048
 			$universal_query_params = $this->_get_default_where_conditions();
3049
-		} else if( $use_default_where_conditions === 'minimum' ) {
3049
+		} else if ($use_default_where_conditions === 'minimum') {
3050 3050
 			$universal_query_params = $this->_get_minimum_where_conditions();
3051 3051
 		}
3052
-		if(in_array($use_default_where_conditions,array('all','other_models_only'))){
3053
-			foreach($query_info_carrier->get_model_names_included() as $model_relation_path => $model_name){
3052
+		if (in_array($use_default_where_conditions, array('all', 'other_models_only'))) {
3053
+			foreach ($query_info_carrier->get_model_names_included() as $model_relation_path => $model_name) {
3054 3054
 				$related_model = $this->get_related_model_obj($model_name);
3055 3055
 				$related_model_universal_where_params = $related_model->_get_default_where_conditions($model_relation_path);
3056 3056
 				$overrides = $this->_override_defaults_or_make_null_friendly(
@@ -3083,20 +3083,20 @@  discard block
 block discarded – undo
3083 3083
 	 * @return array like EEM_Base::get_all's $query_params[0]
3084 3084
 	 * @throws \EE_Error
3085 3085
 	 */
3086
-	private function _override_defaults_or_make_null_friendly($default_where_conditions,$provided_where_conditions,$model,$model_relation_path){
3086
+	private function _override_defaults_or_make_null_friendly($default_where_conditions, $provided_where_conditions, $model, $model_relation_path) {
3087 3087
 		$null_friendly_where_conditions = array();
3088 3088
 		$none_overridden = true;
3089 3089
 		$or_condition_key_for_defaults = 'OR*'.get_class($model);
3090 3090
 
3091
-		foreach($default_where_conditions as $key => $val){
3092
-			if( isset($provided_where_conditions[$key])){
3091
+		foreach ($default_where_conditions as $key => $val) {
3092
+			if (isset($provided_where_conditions[$key])) {
3093 3093
 				$none_overridden = false;
3094
-			}else{
3094
+			} else {
3095 3095
 				$null_friendly_where_conditions[$or_condition_key_for_defaults]['AND'][$key] = $val;
3096 3096
 			}
3097 3097
 		}
3098
-		if( $none_overridden && $default_where_conditions){
3099
-			if($model->has_primary_key_field()){
3098
+		if ($none_overridden && $default_where_conditions) {
3099
+			if ($model->has_primary_key_field()) {
3100 3100
 				$null_friendly_where_conditions[$or_condition_key_for_defaults][$model_relation_path.".".$model->primary_key_name()] = array('IS NULL');
3101 3101
 			}/*else{
3102 3102
 				//@todo NO PK, use other defaults
@@ -3113,8 +3113,8 @@  discard block
 block discarded – undo
3113 3113
 	 * @param string $model_relation_path eg, path from Event to Payment is "Registration.Transaction.Payment."
3114 3114
 	 * @return array like EEM_Base::get_all's $query_params[0] (where conditions)
3115 3115
 	 */
3116
-	private function _get_default_where_conditions($model_relation_path = null){
3117
-		if ( $this->_ignore_where_strategy ){
3116
+	private function _get_default_where_conditions($model_relation_path = null) {
3117
+		if ($this->_ignore_where_strategy) {
3118 3118
 			return array();
3119 3119
 		}
3120 3120
 		return $this->_default_where_conditions_strategy->get_default_where_conditions($model_relation_path);
@@ -3128,8 +3128,8 @@  discard block
 block discarded – undo
3128 3128
 	 * @param string $model_relation_path eg, path from Event to Payment is "Registration.Transaction.Payment."
3129 3129
 	 * @return array like EEM_Base::get_all's $query_params[0] (where conditions)
3130 3130
 	 */
3131
-	protected function _get_minimum_where_conditions($model_relation_path = null){
3132
-		if ( $this->_ignore_where_strategy ){
3131
+	protected function _get_minimum_where_conditions($model_relation_path = null) {
3132
+		if ($this->_ignore_where_strategy) {
3133 3133
 			return array();
3134 3134
 		}
3135 3135
 		return $this->_minimum_where_conditions_strategy->get_default_where_conditions($model_relation_path);
@@ -3145,16 +3145,16 @@  discard block
 block discarded – undo
3145 3145
 	 * @return string
3146 3146
 	 * @throws \EE_Error
3147 3147
 	 */
3148
-	private function _construct_default_select_sql(EE_Model_Query_Info_Carrier $model_query_info){
3148
+	private function _construct_default_select_sql(EE_Model_Query_Info_Carrier $model_query_info) {
3149 3149
 		$selects = $this->_get_columns_to_select_for_this_model();
3150
-		foreach($model_query_info->get_model_names_included() as $model_relation_chain => $name_of_other_model_included){
3150
+		foreach ($model_query_info->get_model_names_included() as $model_relation_chain => $name_of_other_model_included) {
3151 3151
 			$other_model_included = $this->get_related_model_obj($name_of_other_model_included);
3152
-			$other_model_selects = $other_model_included->_get_columns_to_select_for_this_model( $model_relation_chain );
3153
-			foreach ( $other_model_selects as $key => $value ) {
3152
+			$other_model_selects = $other_model_included->_get_columns_to_select_for_this_model($model_relation_chain);
3153
+			foreach ($other_model_selects as $key => $value) {
3154 3154
 				$selects[] = $value;
3155 3155
 			}
3156 3156
 		}
3157
-		return implode(", ",$selects);
3157
+		return implode(", ", $selects);
3158 3158
 	}
3159 3159
 
3160 3160
 	/**
@@ -3163,19 +3163,19 @@  discard block
 block discarded – undo
3163 3163
 	 * @param string $model_relation_chain like 'Question.Question_Group.Event'
3164 3164
 	 * @return array numerically indexed, values are columns to select and rename, eg "Event.ID AS 'Event.ID'"
3165 3165
 	 */
3166
-	public function _get_columns_to_select_for_this_model($model_relation_chain = ''){
3166
+	public function _get_columns_to_select_for_this_model($model_relation_chain = '') {
3167 3167
 		$fields = $this->field_settings();
3168 3168
 		$selects = array();
3169 3169
 		$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());
3170
-		foreach($fields as $field_obj){
3171
-			$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()."'";
3170
+		foreach ($fields as $field_obj) {
3171
+			$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()."'";
3172 3172
 		}
3173 3173
 		//make sure we are also getting the PKs of each table
3174 3174
 		$tables = $this->get_tables();
3175
-		if(count($tables) > 1){
3176
-			foreach($tables as $table_obj){
3177
-				$qualified_pk_column = $table_alias_with_model_relation_chain_prefix . $table_obj->get_fully_qualified_pk_column();
3178
-				if( ! in_array($qualified_pk_column,$selects)){
3175
+		if (count($tables) > 1) {
3176
+			foreach ($tables as $table_obj) {
3177
+				$qualified_pk_column = $table_alias_with_model_relation_chain_prefix.$table_obj->get_fully_qualified_pk_column();
3178
+				if ( ! in_array($qualified_pk_column, $selects)) {
3179 3179
 					$selects[] = "$qualified_pk_column AS '$qualified_pk_column'";
3180 3180
 				}
3181 3181
 			}
@@ -3205,65 +3205,65 @@  discard block
 block discarded – undo
3205 3205
 		$query_param_type,
3206 3206
 		$original_query_param = null
3207 3207
 	) {
3208
-		if( $original_query_param === null ){
3208
+		if ($original_query_param === null) {
3209 3209
 			$original_query_param = $query_param;
3210 3210
 		}
3211 3211
 		$query_param = $this->_remove_stars_and_anything_after_from_condition_query_param_key($query_param);
3212 3212
 		/** @var $allow_logic_query_params bool whether or not to allow logic_query_params like 'NOT','OR', or 'AND' */
3213
-		$allow_logic_query_params = in_array($query_param_type,array('where','having'));
3214
-		$allow_fields = in_array($query_param_type,array('where','having','order_by','group_by','order'));
3213
+		$allow_logic_query_params = in_array($query_param_type, array('where', 'having'));
3214
+		$allow_fields = in_array($query_param_type, array('where', 'having', 'order_by', 'group_by', 'order'));
3215 3215
 		//check to see if we have a field on this model
3216 3216
 		$this_model_fields = $this->field_settings(true);
3217
-		if(array_key_exists($query_param,$this_model_fields)){
3218
-			if($allow_fields){
3217
+		if (array_key_exists($query_param, $this_model_fields)) {
3218
+			if ($allow_fields) {
3219 3219
 				return;
3220
-			}else{
3220
+			} else {
3221 3221
 				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"),
3222
-						$query_param,get_class($this),$query_param_type,$original_query_param));
3222
+						$query_param, get_class($this), $query_param_type, $original_query_param));
3223 3223
 			}
3224 3224
 		}
3225 3225
 		//check if this is a special logic query param
3226
-		elseif(in_array($query_param, $this->_logic_query_param_keys, TRUE)){
3227
-			if($allow_logic_query_params){
3226
+		elseif (in_array($query_param, $this->_logic_query_param_keys, TRUE)) {
3227
+			if ($allow_logic_query_params) {
3228 3228
 				return;
3229
-			}else{
3229
+			} else {
3230 3230
 				throw new EE_Error(
3231 3231
 					sprintf(
3232
-						__( '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' ),
3233
-						implode( '", "', $this->_logic_query_param_keys ),
3234
-						$query_param ,
3235
-						get_class( $this ),
3232
+						__('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'),
3233
+						implode('", "', $this->_logic_query_param_keys),
3234
+						$query_param,
3235
+						get_class($this),
3236 3236
 						'<br />',
3237
-						"\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
3237
+						"\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
3238 3238
 					)
3239 3239
 				);
3240 3240
 			}
3241 3241
 		}
3242 3242
 
3243 3243
 		//check if it's a custom selection
3244
-		elseif(array_key_exists($query_param,$this->_custom_selections)){
3244
+		elseif (array_key_exists($query_param, $this->_custom_selections)) {
3245 3245
 			return;
3246 3246
 		}
3247 3247
 
3248 3248
 		//check if has a model name at the beginning
3249 3249
 		//and
3250 3250
 		//check if it's a field on a related model
3251
-		foreach($this->_model_relations as $valid_related_model_name=>$relation_obj){
3252
-			if(strpos($query_param, $valid_related_model_name.".") === 0){
3253
-				$this->_add_join_to_model($valid_related_model_name, $passed_in_query_info,$original_query_param);
3251
+		foreach ($this->_model_relations as $valid_related_model_name=>$relation_obj) {
3252
+			if (strpos($query_param, $valid_related_model_name.".") === 0) {
3253
+				$this->_add_join_to_model($valid_related_model_name, $passed_in_query_info, $original_query_param);
3254 3254
 				$query_param = substr($query_param, strlen($valid_related_model_name."."));
3255
-				if($query_param === ''){
3255
+				if ($query_param === '') {
3256 3256
 					//nothing left to $query_param
3257 3257
 					//we should actually end in a field name, not a model like this!
3258 3258
 					throw new EE_Error(sprintf(__("Query param '%s' (of type %s on model %s) shouldn't end on a period (.) ", "event_espresso"),
3259
-					$query_param,$query_param_type,get_class($this),$valid_related_model_name));
3260
-				}else{
3259
+					$query_param, $query_param_type, get_class($this), $valid_related_model_name));
3260
+				} else {
3261 3261
 					$related_model_obj = $this->get_related_model_obj($valid_related_model_name);
3262 3262
 					$related_model_obj->_extract_related_model_info_from_query_param($query_param, $passed_in_query_info, $query_param_type, $original_query_param);
3263 3263
 					return;
3264 3264
 				}
3265
-			}elseif($query_param === $valid_related_model_name){
3266
-				$this->_add_join_to_model($valid_related_model_name, $passed_in_query_info,$original_query_param);
3265
+			}elseif ($query_param === $valid_related_model_name) {
3266
+				$this->_add_join_to_model($valid_related_model_name, $passed_in_query_info, $original_query_param);
3267 3267
 				return;
3268 3268
 			}
3269 3269
 		}
@@ -3273,7 +3273,7 @@  discard block
 block discarded – undo
3273 3273
 		//and we previously confirmed it wasn't a logic query param or field on the current model
3274 3274
 		//it's wack, that's what it is
3275 3275
 		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"),
3276
-				$query_param,get_class($this),$query_param_type,$original_query_param));
3276
+				$query_param, get_class($this), $query_param_type, $original_query_param));
3277 3277
 
3278 3278
 	}
3279 3279
 
@@ -3292,26 +3292,26 @@  discard block
 block discarded – undo
3292 3292
 	 * @return void
3293 3293
 	 * @throws \EE_Error
3294 3294
 	 */
3295
-	private function _add_join_to_model($model_name, EE_Model_Query_Info_Carrier $passed_in_query_info,$original_query_param){
3295
+	private function _add_join_to_model($model_name, EE_Model_Query_Info_Carrier $passed_in_query_info, $original_query_param) {
3296 3296
 		$relation_obj = $this->related_settings_for($model_name);
3297 3297
 
3298 3298
 		$model_relation_chain = EE_Model_Parser::extract_model_relation_chain($model_name, $original_query_param);
3299 3299
 		//check if the relation is HABTM, because then we're essentially doing two joins
3300 3300
 		//If so, join first to the JOIN table, and add its data types, and then continue as normal
3301
-		if($relation_obj instanceof EE_HABTM_Relation){
3301
+		if ($relation_obj instanceof EE_HABTM_Relation) {
3302 3302
 			$join_model_obj = $relation_obj->get_join_model();
3303 3303
 			//replace the model specified with the join model for this relation chain, whi
3304 3304
 			$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);
3305 3305
 			$new_query_info = new EE_Model_Query_Info_Carrier(
3306 3306
 					array($relation_chain_to_join_model => $join_model_obj->get_this_model_name()),
3307 3307
 					$relation_obj->get_join_to_intermediate_model_statement($relation_chain_to_join_model));
3308
-			$passed_in_query_info->merge( $new_query_info  );
3308
+			$passed_in_query_info->merge($new_query_info);
3309 3309
 		}
3310 3310
 		//now just join to the other table pointed to by the relation object, and add its data types
3311 3311
 		$new_query_info = new EE_Model_Query_Info_Carrier(
3312 3312
 				array($model_relation_chain=>$model_name),
3313 3313
 				$relation_obj->get_join_statement($model_relation_chain));
3314
-		$passed_in_query_info->merge( $new_query_info  );
3314
+		$passed_in_query_info->merge($new_query_info);
3315 3315
 	}
3316 3316
 
3317 3317
 
@@ -3323,11 +3323,11 @@  discard block
 block discarded – undo
3323 3323
 	 * @return string of SQL
3324 3324
 	 * @throws \EE_Error
3325 3325
 	 */
3326
-	private function _construct_where_clause($where_params){
3326
+	private function _construct_where_clause($where_params) {
3327 3327
 		$SQL = $this->_construct_condition_clause_recursive($where_params, ' AND ');
3328
-		if($SQL){
3329
-			return " WHERE ". $SQL;
3330
-		}else{
3328
+		if ($SQL) {
3329
+			return " WHERE ".$SQL;
3330
+		} else {
3331 3331
 			return '';
3332 3332
 		}
3333 3333
 	}
@@ -3342,11 +3342,11 @@  discard block
 block discarded – undo
3342 3342
 	 * @return string
3343 3343
 	 * @throws \EE_Error
3344 3344
 	 */
3345
-	private function _construct_having_clause($having_params){
3345
+	private function _construct_having_clause($having_params) {
3346 3346
 		$SQL = $this->_construct_condition_clause_recursive($having_params, ' AND ');
3347
-		if($SQL){
3348
-			return " HAVING ". $SQL;
3349
-		}else{
3347
+		if ($SQL) {
3348
+			return " HAVING ".$SQL;
3349
+		} else {
3350 3350
 			return '';
3351 3351
 		}
3352 3352
 
@@ -3360,16 +3360,16 @@  discard block
 block discarded – undo
3360 3360
 	 * @return EE_Model_Field_Base
3361 3361
 	 * @throws EE_Error
3362 3362
 	 */
3363
-	protected function _get_field_on_model($field_name,$model_name){
3363
+	protected function _get_field_on_model($field_name, $model_name) {
3364 3364
 		$model_class = 'EEM_'.$model_name;
3365 3365
 		$model_filepath = $model_class.".model.php";
3366
-		if ( is_readable($model_filepath)){
3366
+		if (is_readable($model_filepath)) {
3367 3367
 			require_once($model_filepath);
3368
-			$model_instance=call_user_func($model_name."::instance");
3368
+			$model_instance = call_user_func($model_name."::instance");
3369 3369
 			/* @var $model_instance EEM_Base */
3370 3370
 			return $model_instance->field_settings_for($field_name);
3371
-		}else{
3372
-			throw new EE_Error(sprintf(__('No model named %s exists, with classname %s and filepath %s','event_espresso'),$model_name,$model_class,$model_filepath));
3371
+		} else {
3372
+			throw new EE_Error(sprintf(__('No model named %s exists, with classname %s and filepath %s', 'event_espresso'), $model_name, $model_class, $model_filepath));
3373 3373
 		}
3374 3374
 	}
3375 3375
 
@@ -3382,41 +3382,41 @@  discard block
 block discarded – undo
3382 3382
 	 * @throws EE_Error
3383 3383
 	 * @return string of SQL
3384 3384
 	 */
3385
-	private function _construct_condition_clause_recursive($where_params, $glue = ' AND'){
3386
-		$where_clauses=array();
3387
-		foreach($where_params as $query_param => $op_and_value_or_sub_condition){
3388
-			$query_param = $this->_remove_stars_and_anything_after_from_condition_query_param_key($query_param);//str_replace("*",'',$query_param);
3389
-			if(in_array($query_param,$this->_logic_query_param_keys)){
3390
-				switch($query_param){
3385
+	private function _construct_condition_clause_recursive($where_params, $glue = ' AND') {
3386
+		$where_clauses = array();
3387
+		foreach ($where_params as $query_param => $op_and_value_or_sub_condition) {
3388
+			$query_param = $this->_remove_stars_and_anything_after_from_condition_query_param_key($query_param); //str_replace("*",'',$query_param);
3389
+			if (in_array($query_param, $this->_logic_query_param_keys)) {
3390
+				switch ($query_param) {
3391 3391
 					case 'not':
3392 3392
 					case 'NOT':
3393
-						$where_clauses[] = "! (". $this->_construct_condition_clause_recursive($op_and_value_or_sub_condition, $glue).")";
3393
+						$where_clauses[] = "! (".$this->_construct_condition_clause_recursive($op_and_value_or_sub_condition, $glue).")";
3394 3394
 						break;
3395 3395
 					case 'and':
3396 3396
 					case 'AND':
3397
-						$where_clauses[] = " (". $this->_construct_condition_clause_recursive($op_and_value_or_sub_condition, ' AND ') .")";
3397
+						$where_clauses[] = " (".$this->_construct_condition_clause_recursive($op_and_value_or_sub_condition, ' AND ').")";
3398 3398
 						break;
3399 3399
 					case 'or':
3400 3400
 					case 'OR':
3401
-						$where_clauses[] = " (". $this->_construct_condition_clause_recursive($op_and_value_or_sub_condition, ' OR ') .")";
3401
+						$where_clauses[] = " (".$this->_construct_condition_clause_recursive($op_and_value_or_sub_condition, ' OR ').")";
3402 3402
 						break;
3403 3403
 				}
3404
-			}else{
3404
+			} else {
3405 3405
 				$field_obj = $this->_deduce_field_from_query_param($query_param);
3406 3406
 
3407 3407
 				//if it's not a normal field, maybe it's a custom selection?
3408
-				if( ! $field_obj){
3409
-					if(isset( $this->_custom_selections[$query_param][1])){
3408
+				if ( ! $field_obj) {
3409
+					if (isset($this->_custom_selections[$query_param][1])) {
3410 3410
 						$field_obj = $this->_custom_selections[$query_param][1];
3411
-					}else{
3412
-						throw new EE_Error(sprintf(__("%s is neither a valid model field name, nor a custom selection", "event_espresso"),$query_param));
3411
+					} else {
3412
+						throw new EE_Error(sprintf(__("%s is neither a valid model field name, nor a custom selection", "event_espresso"), $query_param));
3413 3413
 					}
3414 3414
 				}
3415 3415
 				$op_and_value_sql = $this->_construct_op_and_value($op_and_value_or_sub_condition, $field_obj);
3416
-				$where_clauses[]=$this->_deduce_column_name_from_query_param($query_param).SP.$op_and_value_sql;
3416
+				$where_clauses[] = $this->_deduce_column_name_from_query_param($query_param).SP.$op_and_value_sql;
3417 3417
 			}
3418 3418
 		}
3419
-		return $where_clauses ? implode( $glue, $where_clauses ) : '';
3419
+		return $where_clauses ? implode($glue, $where_clauses) : '';
3420 3420
 	}
3421 3421
 
3422 3422
 
@@ -3427,18 +3427,18 @@  discard block
 block discarded – undo
3427 3427
 	 * @throws EE_Error
3428 3428
 	 * @return string table alias and column name for SQL, eg "Transaction.TXN_ID"
3429 3429
 	 */
3430
-	private function _deduce_column_name_from_query_param($query_param){
3430
+	private function _deduce_column_name_from_query_param($query_param) {
3431 3431
 		$field = $this->_deduce_field_from_query_param($query_param);
3432 3432
 
3433
-		if( $field ){
3434
-			$table_alias_prefix = EE_Model_Parser::extract_table_alias_model_relation_chain_from_query_param( $field->get_model_name(), $query_param );
3435
-			return $table_alias_prefix . $field->get_qualified_column();
3436
-		}elseif(array_key_exists($query_param,$this->_custom_selections)){
3433
+		if ($field) {
3434
+			$table_alias_prefix = EE_Model_Parser::extract_table_alias_model_relation_chain_from_query_param($field->get_model_name(), $query_param);
3435
+			return $table_alias_prefix.$field->get_qualified_column();
3436
+		}elseif (array_key_exists($query_param, $this->_custom_selections)) {
3437 3437
 			//maybe it's custom selection item?
3438 3438
 			//if so, just use it as the "column name"
3439 3439
 			return $query_param;
3440
-		}else{
3441
-			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)));
3440
+		} else {
3441
+			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)));
3442 3442
 		}
3443 3443
 	}
3444 3444
 
@@ -3450,11 +3450,11 @@  discard block
 block discarded – undo
3450 3450
 	 * @param string $condition_query_param_key
3451 3451
 	 * @return string
3452 3452
 	 */
3453
-	private function _remove_stars_and_anything_after_from_condition_query_param_key($condition_query_param_key){
3453
+	private function _remove_stars_and_anything_after_from_condition_query_param_key($condition_query_param_key) {
3454 3454
 		$pos_of_star = strpos($condition_query_param_key, '*');
3455
-		if($pos_of_star === FALSE){
3455
+		if ($pos_of_star === FALSE) {
3456 3456
 			return $condition_query_param_key;
3457
-		}else{
3457
+		} else {
3458 3458
 			$condition_query_param_sans_star = substr($condition_query_param_key, 0, $pos_of_star);
3459 3459
 			return $condition_query_param_sans_star;
3460 3460
 		}
@@ -3469,12 +3469,12 @@  discard block
 block discarded – undo
3469 3469
 	 * @throws EE_Error
3470 3470
 	 * @return string
3471 3471
 	 */
3472
-	private function _construct_op_and_value($op_and_value, $field_obj){
3473
-		if ( is_array( $op_and_value ) ) {
3474
-			$operator = isset( $op_and_value[0] ) ? $this->_prepare_operator_for_sql( $op_and_value[0] ) : null;
3475
-			if ( ! $operator ) {
3472
+	private function _construct_op_and_value($op_and_value, $field_obj) {
3473
+		if (is_array($op_and_value)) {
3474
+			$operator = isset($op_and_value[0]) ? $this->_prepare_operator_for_sql($op_and_value[0]) : null;
3475
+			if ( ! $operator) {
3476 3476
 				$php_array_like_string = array();
3477
-				foreach ( $op_and_value as $key => $value ) {
3477
+				foreach ($op_and_value as $key => $value) {
3478 3478
 					$php_array_like_string[] = "$key=>$value";
3479 3479
 				}
3480 3480
 				throw new EE_Error(
@@ -3483,27 +3483,27 @@  discard block
 block discarded – undo
3483 3483
 							"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))",
3484 3484
 							"event_espresso"
3485 3485
 						),
3486
-						implode( ",", $php_array_like_string )
3486
+						implode(",", $php_array_like_string)
3487 3487
 					)
3488 3488
 				);
3489 3489
 			}
3490
-			$value = isset( $op_and_value[1] ) ? $op_and_value[1] : null;
3490
+			$value = isset($op_and_value[1]) ? $op_and_value[1] : null;
3491 3491
 		} else {
3492 3492
 			$operator = '=';
3493 3493
 			$value = $op_and_value;
3494 3494
 		}
3495 3495
 		//check to see if the value is actually another field
3496
-		if ( is_array( $op_and_value ) && isset( $op_and_value[2] ) && $op_and_value[2] == true ) {
3497
-			return $operator . SP . $this->_deduce_column_name_from_query_param( $value );
3498
-		} elseif ( in_array( $operator, $this->_in_style_operators ) && is_array( $value ) ) {
3496
+		if (is_array($op_and_value) && isset($op_and_value[2]) && $op_and_value[2] == true) {
3497
+			return $operator.SP.$this->_deduce_column_name_from_query_param($value);
3498
+		} elseif (in_array($operator, $this->_in_style_operators) && is_array($value)) {
3499 3499
 			//in this case, the value should be an array, or at least a comma-separated list
3500 3500
 			//it will need to handle a little differently
3501
-			$cleaned_value = $this->_construct_in_value( $value, $field_obj );
3501
+			$cleaned_value = $this->_construct_in_value($value, $field_obj);
3502 3502
 			//note: $cleaned_value has already been run through $wpdb->prepare()
3503
-			return $operator . SP . $cleaned_value;
3504
-		} elseif ( in_array( $operator, $this->_between_style_operators ) && is_array( $value ) ) {
3503
+			return $operator.SP.$cleaned_value;
3504
+		} elseif (in_array($operator, $this->_between_style_operators) && is_array($value)) {
3505 3505
 			//the value should be an array with count of two.
3506
-			if ( count( $value ) !== 2 ) {
3506
+			if (count($value) !== 2) {
3507 3507
 				throw new EE_Error(
3508 3508
 					sprintf(
3509 3509
 						__(
@@ -3514,10 +3514,10 @@  discard block
 block discarded – undo
3514 3514
 					)
3515 3515
 				);
3516 3516
 			}
3517
-			$cleaned_value = $this->_construct_between_value( $value, $field_obj );
3518
-			return $operator . SP . $cleaned_value;
3519
-		} elseif ( in_array( $operator, $this->_null_style_operators ) ) {
3520
-			if ( $value !== null ) {
3517
+			$cleaned_value = $this->_construct_between_value($value, $field_obj);
3518
+			return $operator.SP.$cleaned_value;
3519
+		} elseif (in_array($operator, $this->_null_style_operators)) {
3520
+			if ($value !== null) {
3521 3521
 				throw new EE_Error(
3522 3522
 					sprintf(
3523 3523
 						__(
@@ -3530,13 +3530,13 @@  discard block
 block discarded – undo
3530 3530
 				);
3531 3531
 			}
3532 3532
 			return $operator;
3533
-		} elseif ( $operator === 'LIKE' && ! is_array( $value ) ) {
3533
+		} elseif ($operator === 'LIKE' && ! is_array($value)) {
3534 3534
 			//if the operator is 'LIKE', we want to allow percent signs (%) and not
3535 3535
 			//remove other junk. So just treat it as a string.
3536
-			return $operator . SP . $this->_wpdb_prepare_using_field( $value, '%s' );
3537
-		} elseif ( ! in_array( $operator, $this->_in_style_operators ) && ! is_array( $value ) ) {
3538
-			return $operator . SP . $this->_wpdb_prepare_using_field( $value, $field_obj );
3539
-		} elseif ( in_array( $operator, $this->_in_style_operators ) && ! is_array( $value ) ) {
3536
+			return $operator.SP.$this->_wpdb_prepare_using_field($value, '%s');
3537
+		} elseif ( ! in_array($operator, $this->_in_style_operators) && ! is_array($value)) {
3538
+			return $operator.SP.$this->_wpdb_prepare_using_field($value, $field_obj);
3539
+		} elseif (in_array($operator, $this->_in_style_operators) && ! is_array($value)) {
3540 3540
 			throw new EE_Error(
3541 3541
 				sprintf(
3542 3542
 					__(
@@ -3547,7 +3547,7 @@  discard block
 block discarded – undo
3547 3547
 					$operator
3548 3548
 				)
3549 3549
 			);
3550
-		} elseif ( ! in_array( $operator, $this->_in_style_operators ) && is_array( $value ) ) {
3550
+		} elseif ( ! in_array($operator, $this->_in_style_operators) && is_array($value)) {
3551 3551
 			throw new EE_Error(
3552 3552
 				sprintf(
3553 3553
 					__(
@@ -3565,7 +3565,7 @@  discard block
 block discarded – undo
3565 3565
 						"It appears you've provided some totally invalid query parameters. Operator and value were:'%s', which isn't right at all",
3566 3566
 						"event_espresso"
3567 3567
 					),
3568
-					http_build_query( $op_and_value )
3568
+					http_build_query($op_and_value)
3569 3569
 				)
3570 3570
 			);
3571 3571
 		}
@@ -3581,12 +3581,12 @@  discard block
 block discarded – undo
3581 3581
 	 * @return string
3582 3582
 	 * @throws \EE_Error
3583 3583
 	 */
3584
-	public function _construct_between_value( $values, $field_obj ) {
3584
+	public function _construct_between_value($values, $field_obj) {
3585 3585
 		$cleaned_values = array();
3586
-		foreach ( $values as $value ) {
3587
-			$cleaned_values[] = $this->_wpdb_prepare_using_field($value,$field_obj);
3586
+		foreach ($values as $value) {
3587
+			$cleaned_values[] = $this->_wpdb_prepare_using_field($value, $field_obj);
3588 3588
 		}
3589
-		return  $cleaned_values[0] . " AND " . $cleaned_values[1];
3589
+		return  $cleaned_values[0]." AND ".$cleaned_values[1];
3590 3590
 	}
3591 3591
 
3592 3592
 
@@ -3603,26 +3603,26 @@  discard block
 block discarded – undo
3603 3603
 	 * @return string of SQL to follow an 'IN' or 'NOT IN' operator
3604 3604
 	 * @throws \EE_Error
3605 3605
 	 */
3606
-	public function _construct_in_value($values,  $field_obj){
3606
+	public function _construct_in_value($values, $field_obj) {
3607 3607
 		//check if the value is a CSV list
3608
-		if(is_string($values)){
3608
+		if (is_string($values)) {
3609 3609
 			//in which case, turn it into an array
3610
-			$values = explode(",",$values);
3610
+			$values = explode(",", $values);
3611 3611
 		}
3612 3612
 		$cleaned_values = array();
3613
-		foreach($values as $value){
3614
-			$cleaned_values[] = $this->_wpdb_prepare_using_field($value,$field_obj);
3613
+		foreach ($values as $value) {
3614
+			$cleaned_values[] = $this->_wpdb_prepare_using_field($value, $field_obj);
3615 3615
 		}
3616 3616
 		//we would just LOVE to leave $cleaned_values as an empty array, and return the value as "()",
3617 3617
 		//but unfortunately that's invalid SQL. So instead we return a string which we KNOW will evaluate to be the empty set
3618 3618
 		//which is effectively equivalent to returning "()". We don't return "(0)" because that only works for auto-incrementing columns
3619
-		if(empty($cleaned_values)){
3619
+		if (empty($cleaned_values)) {
3620 3620
 			$all_fields = $this->field_settings();
3621 3621
 			$a_field = array_shift($all_fields);
3622 3622
 			$main_table = $this->_get_main_table();
3623 3623
 			$cleaned_values[] = "SELECT ".$a_field->get_table_column()." FROM ".$main_table->get_table_name()." WHERE FALSE";
3624 3624
 		}
3625
-		return "(".implode(",",$cleaned_values).")";
3625
+		return "(".implode(",", $cleaned_values).")";
3626 3626
 	}
3627 3627
 
3628 3628
 
@@ -3634,16 +3634,16 @@  discard block
 block discarded – undo
3634 3634
 	 * @throws EE_Error
3635 3635
 	 * @return false|null|string
3636 3636
 	 */
3637
-	private function _wpdb_prepare_using_field($value,$field_obj){
3637
+	private function _wpdb_prepare_using_field($value, $field_obj) {
3638 3638
 		/** @type WPDB $wpdb */
3639 3639
 		global $wpdb;
3640
-		if($field_obj instanceof EE_Model_Field_Base){
3641
-			return $wpdb->prepare($field_obj->get_wpdb_data_type(),$this->_prepare_value_for_use_in_db($value, $field_obj));
3642
-		}else{//$field_obj should really just be a data type
3643
-			if( ! in_array($field_obj,$this->_valid_wpdb_data_types)){
3644
-				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)));
3640
+		if ($field_obj instanceof EE_Model_Field_Base) {
3641
+			return $wpdb->prepare($field_obj->get_wpdb_data_type(), $this->_prepare_value_for_use_in_db($value, $field_obj));
3642
+		} else {//$field_obj should really just be a data type
3643
+			if ( ! in_array($field_obj, $this->_valid_wpdb_data_types)) {
3644
+				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)));
3645 3645
 			}
3646
-			return $wpdb->prepare($field_obj,$value);
3646
+			return $wpdb->prepare($field_obj, $value);
3647 3647
 		}
3648 3648
 	}
3649 3649
 
@@ -3655,27 +3655,27 @@  discard block
 block discarded – undo
3655 3655
 	 * @throws EE_Error
3656 3656
 	 * @return EE_Model_Field_Base
3657 3657
 	 */
3658
-	protected function _deduce_field_from_query_param($query_param_name){
3658
+	protected function _deduce_field_from_query_param($query_param_name) {
3659 3659
 		//ok, now proceed with deducing which part is the model's name, and which is the field's name
3660 3660
 		//which will help us find the database table and column
3661 3661
 
3662
-		$query_param_parts = explode(".",$query_param_name);
3663
-		if(empty($query_param_parts)){
3664
-			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));
3662
+		$query_param_parts = explode(".", $query_param_name);
3663
+		if (empty($query_param_parts)) {
3664
+			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));
3665 3665
 		}
3666 3666
 		$number_of_parts = count($query_param_parts);
3667
-		$last_query_param_part = $query_param_parts[ count($query_param_parts) - 1 ];
3668
-		if($number_of_parts === 1){
3667
+		$last_query_param_part = $query_param_parts[count($query_param_parts) - 1];
3668
+		if ($number_of_parts === 1) {
3669 3669
 			$field_name = $last_query_param_part;
3670 3670
 			$model_obj = $this;
3671
-		}else{// $number_of_parts >= 2
3671
+		} else {// $number_of_parts >= 2
3672 3672
 			//the last part is the column name, and there are only 2parts. therefore...
3673 3673
 			$field_name = $last_query_param_part;
3674
-			$model_obj = $this->get_related_model_obj( $query_param_parts[ $number_of_parts - 2 ]);
3674
+			$model_obj = $this->get_related_model_obj($query_param_parts[$number_of_parts - 2]);
3675 3675
 		}
3676
-		try{
3676
+		try {
3677 3677
 			return $model_obj->field_settings_for($field_name);
3678
-		}catch(EE_Error $e){
3678
+		} catch (EE_Error $e) {
3679 3679
 			return null;
3680 3680
 		}
3681 3681
 	}
@@ -3689,13 +3689,13 @@  discard block
 block discarded – undo
3689 3689
 	 * @throws EE_Error
3690 3690
 	 * @return string
3691 3691
 	 */
3692
-	public function _get_qualified_column_for_field($field_name){
3692
+	public function _get_qualified_column_for_field($field_name) {
3693 3693
 		$all_fields = $this->field_settings();
3694 3694
 		$field = isset($all_fields[$field_name]) ? $all_fields[$field_name] : FALSE;
3695
-		if($field){
3695
+		if ($field) {
3696 3696
 			return $field->get_qualified_column();
3697
-		}else{
3698
-			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)));
3697
+		} else {
3698
+			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)));
3699 3699
 		}
3700 3700
 	}
3701 3701
 
@@ -3709,17 +3709,17 @@  discard block
 block discarded – undo
3709 3709
 	 * @param  mixed|string $limit The limit for this select
3710 3710
 	 * @return string                The final select join element for the query.
3711 3711
 	 */
3712
-	public function _construct_limit_join_select( $table_alias, $limit ) {
3712
+	public function _construct_limit_join_select($table_alias, $limit) {
3713 3713
 		$SQL = '';
3714
-		foreach ( $this->_tables as $table_obj ) {
3715
-			if ( $table_obj instanceof EE_Primary_Table ) {
3714
+		foreach ($this->_tables as $table_obj) {
3715
+			if ($table_obj instanceof EE_Primary_Table) {
3716 3716
 				$SQL .= $table_alias === $table_obj->get_table_alias()
3717
-					? $table_obj->get_select_join_limit( $limit )
3718
-					: SP . $table_obj->get_table_name() . " AS " . $table_obj->get_table_alias() . SP;
3719
-			} elseif ( $table_obj instanceof EE_Secondary_Table ) {
3717
+					? $table_obj->get_select_join_limit($limit)
3718
+					: SP.$table_obj->get_table_name()." AS ".$table_obj->get_table_alias().SP;
3719
+			} elseif ($table_obj instanceof EE_Secondary_Table) {
3720 3720
 				$SQL .= $table_alias === $table_obj->get_table_alias()
3721
-					? $table_obj->get_select_join_limit_join( $limit )
3722
-					: SP . $table_obj->get_join_sql( $table_alias ) . SP;
3721
+					? $table_obj->get_select_join_limit_join($limit)
3722
+					: SP.$table_obj->get_join_sql($table_alias).SP;
3723 3723
 			}
3724 3724
 		}
3725 3725
 		return $SQL;
@@ -3734,7 +3734,7 @@  discard block
 block discarded – undo
3734 3734
 	 * @return string SQL
3735 3735
 	 * @throws \EE_Error
3736 3736
 	 */
3737
-	public function _construct_internal_join(){
3737
+	public function _construct_internal_join() {
3738 3738
 		$SQL = $this->_get_main_table()->get_table_sql();
3739 3739
 		$SQL .= $this->_construct_internal_join_to_table_with_alias($this->_get_main_table()->get_table_alias());
3740 3740
 		return $SQL;
@@ -3755,17 +3755,17 @@  discard block
 block discarded – undo
3755 3755
 	 * @param string $alias_prefixed table alias to join to (this table should already be in the FROM SQL clause)
3756 3756
 	 * @return string
3757 3757
 	 */
3758
-	public function _construct_internal_join_to_table_with_alias($alias_prefixed){
3758
+	public function _construct_internal_join_to_table_with_alias($alias_prefixed) {
3759 3759
 		$SQL = '';
3760 3760
 		$alias_sans_prefix = EE_Model_Parser::remove_table_alias_model_relation_chain_prefix($alias_prefixed);
3761
-		foreach($this->_tables as $table_obj){
3762
-			if($table_obj instanceof EE_Secondary_Table){//table is secondary table
3763
-				if($alias_sans_prefix === $table_obj->get_table_alias()){
3761
+		foreach ($this->_tables as $table_obj) {
3762
+			if ($table_obj instanceof EE_Secondary_Table) {//table is secondary table
3763
+				if ($alias_sans_prefix === $table_obj->get_table_alias()) {
3764 3764
 					//so we're joining to this table, meaning the table is already in
3765 3765
 					//the FROM statement, BUT the primary table isn't. So we want
3766 3766
 					//to add the inverse join sql
3767 3767
 					$SQL .= $table_obj->get_inverse_join_sql($alias_prefixed);
3768
-				}else{
3768
+				} else {
3769 3769
 					//just add a regular JOIN to this table from the primary table
3770 3770
 					$SQL .= $table_obj->get_join_sql($alias_prefixed);
3771 3771
 				}
@@ -3779,9 +3779,9 @@  discard block
 block discarded – undo
3779 3779
 	 * 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)
3780 3780
 	 * @return array
3781 3781
 	 */
3782
-	public function _get_data_types(){
3782
+	public function _get_data_types() {
3783 3783
 		$data_types = array();
3784
-		foreach( $this->field_settings() as $field_obj){
3784
+		foreach ($this->field_settings() as $field_obj) {
3785 3785
 			//$data_types[$field_obj->get_table_column()] = $field_obj->get_wpdb_data_type();
3786 3786
 			/** @var $field_obj EE_Model_Field_Base */
3787 3787
 			$data_types[$field_obj->get_qualified_column()] = $field_obj->get_wpdb_data_type();
@@ -3797,10 +3797,10 @@  discard block
 block discarded – undo
3797 3797
 	 * @throws EE_Error
3798 3798
 	 * @return EEM_Base
3799 3799
 	 */
3800
-	public function get_related_model_obj($model_name){
3800
+	public function get_related_model_obj($model_name) {
3801 3801
 		$model_classname = "EEM_".$model_name;
3802
-		if(!class_exists($model_classname)){
3803
-			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));
3802
+		if ( ! class_exists($model_classname)) {
3803
+			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));
3804 3804
 		}
3805 3805
 		return call_user_func($model_classname."::instance");
3806 3806
 	}
@@ -3810,7 +3810,7 @@  discard block
 block discarded – undo
3810 3810
 	 * Returns the array of EE_ModelRelations for this model.
3811 3811
 	 * @return EE_Model_Relation_Base[]
3812 3812
 	 */
3813
-	public function relation_settings(){
3813
+	public function relation_settings() {
3814 3814
 		return $this->_model_relations;
3815 3815
 	}
3816 3816
 
@@ -3820,10 +3820,10 @@  discard block
 block discarded – undo
3820 3820
 	 * (Eg, without an event, datetimes have little purpose.)
3821 3821
 	 * @return EE_Belongs_To_Relation[]
3822 3822
 	 */
3823
-	public function belongs_to_relations(){
3823
+	public function belongs_to_relations() {
3824 3824
 		$belongs_to_relations = array();
3825
-		foreach($this->relation_settings() as $model_name => $relation_obj){
3826
-			if($relation_obj instanceof EE_Belongs_To_Relation){
3825
+		foreach ($this->relation_settings() as $model_name => $relation_obj) {
3826
+			if ($relation_obj instanceof EE_Belongs_To_Relation) {
3827 3827
 				$belongs_to_relations[$model_name] = $relation_obj;
3828 3828
 			}
3829 3829
 		}
@@ -3838,15 +3838,15 @@  discard block
 block discarded – undo
3838 3838
 	 * @throws EE_Error
3839 3839
 	 * @return EE_Model_Relation_Base
3840 3840
 	 */
3841
-	public function related_settings_for($relation_name){
3842
-		$relatedModels=$this->relation_settings();
3843
-		if(!array_key_exists($relation_name,$relatedModels)){
3841
+	public function related_settings_for($relation_name) {
3842
+		$relatedModels = $this->relation_settings();
3843
+		if ( ! array_key_exists($relation_name, $relatedModels)) {
3844 3844
 			throw new EE_Error(
3845 3845
 				sprintf(
3846
-					__('Cannot get %s related to %s. There is no model relation of that type. There is, however, %s...','event_espresso'),
3846
+					__('Cannot get %s related to %s. There is no model relation of that type. There is, however, %s...', 'event_espresso'),
3847 3847
 					$relation_name,
3848 3848
 					$this->_get_class_name(),
3849
-					implode( ', ', array_keys( $relatedModels ))
3849
+					implode(', ', array_keys($relatedModels))
3850 3850
 				)
3851 3851
 			);
3852 3852
 		}
@@ -3861,10 +3861,10 @@  discard block
 block discarded – undo
3861 3861
 	 * @throws EE_Error
3862 3862
 	 * @return EE_Model_Field_Base
3863 3863
 	 */
3864
-	public function field_settings_for($fieldName){
3865
-		$fieldSettings=$this->field_settings(true);
3866
-		if( ! array_key_exists($fieldName,$fieldSettings)){
3867
-			throw new EE_Error(sprintf(__("There is no field/column '%s' on '%s'",'event_espresso'),$fieldName,get_class($this)));
3864
+	public function field_settings_for($fieldName) {
3865
+		$fieldSettings = $this->field_settings(true);
3866
+		if ( ! array_key_exists($fieldName, $fieldSettings)) {
3867
+			throw new EE_Error(sprintf(__("There is no field/column '%s' on '%s'", 'event_espresso'), $fieldName, get_class($this)));
3868 3868
 		}
3869 3869
 		return $fieldSettings[$fieldName];
3870 3870
 	}
@@ -3874,11 +3874,11 @@  discard block
 block discarded – undo
3874 3874
 	 * @param string $fieldName a key in the model's _field_settings array
3875 3875
 	 * @return boolean
3876 3876
 	 */
3877
-	public function has_field($fieldName){
3877
+	public function has_field($fieldName) {
3878 3878
 		$fieldSettings = $this->field_settings(true);
3879
-		if( isset($fieldSettings[$fieldName])){
3879
+		if (isset($fieldSettings[$fieldName])) {
3880 3880
 			return true;
3881
-		}else{
3881
+		} else {
3882 3882
 			return false;
3883 3883
 		}
3884 3884
 	}
@@ -3888,11 +3888,11 @@  discard block
 block discarded – undo
3888 3888
 	 * @param string $relation_name possibly one of the keys in the relation_settings array
3889 3889
 	 * @return boolean
3890 3890
 	 */
3891
-	public function has_relation($relation_name){
3891
+	public function has_relation($relation_name) {
3892 3892
 		$relations = $this->relation_settings();
3893
-		if(isset($relations[$relation_name])){
3893
+		if (isset($relations[$relation_name])) {
3894 3894
 			return true;
3895
-		}else{
3895
+		} else {
3896 3896
 			return false;
3897 3897
 		}
3898 3898
 	}
@@ -3904,7 +3904,7 @@  discard block
 block discarded – undo
3904 3904
 	 * @param $field_obj
3905 3905
 	 * @return boolean
3906 3906
 	 */
3907
-	public function is_primary_key_field( $field_obj ){
3907
+	public function is_primary_key_field($field_obj) {
3908 3908
 		return $field_obj instanceof EE_Primary_Key_Field_Base ? TRUE : FALSE;
3909 3909
 	}
3910 3910
 
@@ -3916,16 +3916,16 @@  discard block
 block discarded – undo
3916 3916
 	 * @return EE_Model_Field_Base
3917 3917
 	 * @throws EE_Error
3918 3918
 	 */
3919
-	public function get_primary_key_field(){
3920
-		if( $this->_primary_key_field === NULL ){
3921
-			foreach( $this->field_settings( TRUE ) as $field_obj ){
3922
-				if( $this->is_primary_key_field( $field_obj )){
3919
+	public function get_primary_key_field() {
3920
+		if ($this->_primary_key_field === NULL) {
3921
+			foreach ($this->field_settings(TRUE) as $field_obj) {
3922
+				if ($this->is_primary_key_field($field_obj)) {
3923 3923
 					$this->_primary_key_field = $field_obj;
3924 3924
 					break;
3925 3925
 				}
3926 3926
 			}
3927
-			if( ! $this->_primary_key_field instanceof EE_Primary_Key_Field_Base ){
3928
-				throw new EE_Error(sprintf(__("There is no Primary Key defined on model %s",'event_espresso'),get_class($this)));
3927
+			if ( ! $this->_primary_key_field instanceof EE_Primary_Key_Field_Base) {
3928
+				throw new EE_Error(sprintf(__("There is no Primary Key defined on model %s", 'event_espresso'), get_class($this)));
3929 3929
 			}
3930 3930
 		}
3931 3931
 		return $this->_primary_key_field;
@@ -3938,12 +3938,12 @@  discard block
 block discarded – undo
3938 3938
 	 * Internally does some caching.
3939 3939
 	 * @return boolean
3940 3940
 	 */
3941
-	public function has_primary_key_field(){
3942
-		if($this->_has_primary_key_field === null){
3943
-			try{
3941
+	public function has_primary_key_field() {
3942
+		if ($this->_has_primary_key_field === null) {
3943
+			try {
3944 3944
 				$this->get_primary_key_field();
3945 3945
 				$this->_has_primary_key_field = true;
3946
-			}catch(EE_Error $e){
3946
+			} catch (EE_Error $e) {
3947 3947
 				$this->_has_primary_key_field = false;
3948 3948
 			}
3949 3949
 		}
@@ -3957,9 +3957,9 @@  discard block
 block discarded – undo
3957 3957
 	 * @param string $field_class_name class name of field that you want to find. Eg, EE_Datetime_Field, EE_Foreign_Key_Field, etc
3958 3958
 	 * @return EE_Model_Field_Base or null if none is found
3959 3959
 	 */
3960
-	public function get_a_field_of_type($field_class_name){
3961
-		foreach($this->field_settings() as $field){
3962
-			if( $field instanceof $field_class_name ){
3960
+	public function get_a_field_of_type($field_class_name) {
3961
+		foreach ($this->field_settings() as $field) {
3962
+			if ($field instanceof $field_class_name) {
3963 3963
 				return $field;
3964 3964
 			}
3965 3965
 		}
@@ -3973,22 +3973,22 @@  discard block
 block discarded – undo
3973 3973
 	 * @return EE_Foreign_Key_Field_Base
3974 3974
 	 * @throws EE_Error
3975 3975
 	 */
3976
-	public function get_foreign_key_to($model_name){
3977
-		if( ! isset( $this->_cache_foreign_key_to_fields[ $model_name ] ) ){
3978
-			foreach($this->field_settings() as $field){
3979
-				if(
3976
+	public function get_foreign_key_to($model_name) {
3977
+		if ( ! isset($this->_cache_foreign_key_to_fields[$model_name])) {
3978
+			foreach ($this->field_settings() as $field) {
3979
+				if (
3980 3980
 					$field instanceof EE_Foreign_Key_Field_Base
3981
-					&& in_array($model_name,$field->get_model_names_pointed_to() )
3981
+					&& in_array($model_name, $field->get_model_names_pointed_to())
3982 3982
 				) {
3983
-					$this->_cache_foreign_key_to_fields[ $model_name ] = $field;
3983
+					$this->_cache_foreign_key_to_fields[$model_name] = $field;
3984 3984
 					break;
3985 3985
 				}
3986 3986
 			}
3987
-			if( ! isset( $this->_cache_foreign_key_to_fields[ $model_name ] ) ){
3988
-				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)));
3987
+			if ( ! isset($this->_cache_foreign_key_to_fields[$model_name])) {
3988
+				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)));
3989 3989
 			}
3990 3990
 		}
3991
-		return $this->_cache_foreign_key_to_fields[ $model_name ];
3991
+		return $this->_cache_foreign_key_to_fields[$model_name];
3992 3992
 	}
3993 3993
 
3994 3994
 
@@ -3999,7 +3999,7 @@  discard block
 block discarded – undo
3999 3999
 	 * a table alias with a model chain prefix, like 'Venue__Event_Venue___Event_Meta'. Either one works
4000 4000
 	 * @return EE_Table_Base
4001 4001
 	 */
4002
-	public function get_table_for_alias($table_alias){
4002
+	public function get_table_for_alias($table_alias) {
4003 4003
 		$table_alias_sans_model_relation_chain_prefix = EE_Model_Parser::remove_table_alias_model_relation_chain_prefix($table_alias);
4004 4004
 		return $this->_tables[$table_alias_sans_model_relation_chain_prefix]->get_table_name();
4005 4005
 	}
@@ -4012,25 +4012,25 @@  discard block
 block discarded – undo
4012 4012
 	 * @param bool $include_db_only_fields flag indicating whether or not to include the db-only fields
4013 4013
 	 * @return EE_Model_Field_Base[] where the keys are the field's name
4014 4014
 	 */
4015
-	public function field_settings($include_db_only_fields = false){
4016
-		if( $include_db_only_fields ){
4017
-			if( $this->_cached_fields === NULL ){
4015
+	public function field_settings($include_db_only_fields = false) {
4016
+		if ($include_db_only_fields) {
4017
+			if ($this->_cached_fields === NULL) {
4018 4018
 				$this->_cached_fields = array();
4019
-				foreach($this->_fields as $fields_corresponding_to_table){
4020
-					foreach($fields_corresponding_to_table as $field_name => $field_obj){
4021
-						$this->_cached_fields[$field_name]=$field_obj;
4019
+				foreach ($this->_fields as $fields_corresponding_to_table) {
4020
+					foreach ($fields_corresponding_to_table as $field_name => $field_obj) {
4021
+						$this->_cached_fields[$field_name] = $field_obj;
4022 4022
 					}
4023 4023
 				}
4024 4024
 			}
4025 4025
 			return $this->_cached_fields;
4026
-		}else{
4027
-			if( $this->_cached_fields_non_db_only === NULL ){
4026
+		} else {
4027
+			if ($this->_cached_fields_non_db_only === NULL) {
4028 4028
 				$this->_cached_fields_non_db_only = array();
4029
-				foreach($this->_fields as $fields_corresponding_to_table){
4030
-					foreach($fields_corresponding_to_table as $field_name => $field_obj){
4029
+				foreach ($this->_fields as $fields_corresponding_to_table) {
4030
+					foreach ($fields_corresponding_to_table as $field_name => $field_obj) {
4031 4031
 						/** @var $field_obj EE_Model_Field_Base */
4032
-						if( ! $field_obj->is_db_only_field() ){
4033
-							$this->_cached_fields_non_db_only[$field_name]=$field_obj;
4032
+						if ( ! $field_obj->is_db_only_field()) {
4033
+							$this->_cached_fields_non_db_only[$field_name] = $field_obj;
4034 4034
 						}
4035 4035
 					}
4036 4036
 				}
@@ -4049,60 +4049,60 @@  discard block
 block discarded – undo
4049 4049
 	 * @return \EE_Base_Class[] array keys are primary keys (if there is a primary key on the model. if not, numerically indexed)
4050 4050
 	 * @throws \EE_Error
4051 4051
 	 */
4052
-	protected function _create_objects( $rows = array() ) {
4053
-		$array_of_objects=array();
4054
-		if(empty($rows)){
4052
+	protected function _create_objects($rows = array()) {
4053
+		$array_of_objects = array();
4054
+		if (empty($rows)) {
4055 4055
 			return array();
4056 4056
 		}
4057 4057
 		$count_if_model_has_no_primary_key = 0;
4058 4058
 		$has_primary_key = $this->has_primary_key_field();
4059 4059
 		$primary_key_field = $has_primary_key ? $this->get_primary_key_field() : null;
4060
-		foreach ( (array)$rows as $row ) {
4061
-			if(empty($row)){
4060
+		foreach ((array) $rows as $row) {
4061
+			if (empty($row)) {
4062 4062
 				//wp did its weird thing where it returns an array like array(0=>null), which is totally not helpful...
4063 4063
 				return array();
4064 4064
 			}
4065 4065
 			//check if we've already set this object in the results array,
4066 4066
 			//in which case there's no need to process it further (again)
4067
-			if( $has_primary_key ) {
4067
+			if ($has_primary_key) {
4068 4068
 				$table_pk_value = $this->_get_column_value_with_table_alias_or_not(
4069 4069
 					$row,
4070 4070
 					$primary_key_field->get_qualified_column(),
4071 4071
 					$primary_key_field->get_table_column()
4072 4072
 				);
4073
-				if( $table_pk_value && isset( $array_of_objects[ $table_pk_value ] ) ) {
4073
+				if ($table_pk_value && isset($array_of_objects[$table_pk_value])) {
4074 4074
 					continue;
4075 4075
 				}
4076 4076
 			}
4077 4077
 			$classInstance = $this->instantiate_class_from_array_or_object($row);
4078
-			if( ! $classInstance ) {
4078
+			if ( ! $classInstance) {
4079 4079
 				throw new EE_Error(
4080 4080
 					sprintf(
4081
-						__( 'Could not create instance of class %s from row %s', 'event_espresso' ),
4081
+						__('Could not create instance of class %s from row %s', 'event_espresso'),
4082 4082
 						$this->get_this_model_name(),
4083
-						http_build_query( $row )
4083
+						http_build_query($row)
4084 4084
 					)
4085 4085
 				);
4086 4086
 			}
4087 4087
 			//set the timezone on the instantiated objects
4088
-			$classInstance->set_timezone( $this->_timezone );
4088
+			$classInstance->set_timezone($this->_timezone);
4089 4089
 			//make sure if there is any timezone setting present that we set the timezone for the object
4090 4090
 			$key = $has_primary_key ? $classInstance->ID() : $count_if_model_has_no_primary_key++;
4091
-			$array_of_objects[ $key ] = $classInstance;
4091
+			$array_of_objects[$key] = $classInstance;
4092 4092
 			//also, for all the relations of type BelongsTo, see if we can cache
4093 4093
 			//those related models
4094 4094
 			//(we could do this for other relations too, but if there are conditions
4095 4095
 			//that filtered out some fo the results, then we'd be caching an incomplete set
4096 4096
 			//so it requires a little more thought than just caching them immediately...)
4097
-			foreach($this->_model_relations as $modelName => $relation_obj){
4098
-				if( $relation_obj instanceof EE_Belongs_To_Relation){
4097
+			foreach ($this->_model_relations as $modelName => $relation_obj) {
4098
+				if ($relation_obj instanceof EE_Belongs_To_Relation) {
4099 4099
 					//check if this model's INFO is present. If so, cache it on the model
4100 4100
 					$other_model = $relation_obj->get_other_model();
4101 4101
 					$other_model_obj_maybe = $other_model->instantiate_class_from_array_or_object($row);
4102 4102
 					//if we managed to make a model object from the results, cache it on the main model object
4103
-					if( $other_model_obj_maybe ){
4103
+					if ($other_model_obj_maybe) {
4104 4104
 						//set timezone on these other model objects if they are present
4105
-						$other_model_obj_maybe->set_timezone( $this->_timezone );
4105
+						$other_model_obj_maybe->set_timezone($this->_timezone);
4106 4106
 						$classInstance->cache($modelName, $other_model_obj_maybe);
4107 4107
 					}
4108 4108
 				}
@@ -4123,12 +4123,12 @@  discard block
 block discarded – undo
4123 4123
 
4124 4124
 		$this_model_fields_and_values = array();
4125 4125
 		//setup the row using default values;
4126
-		foreach ( $this->field_settings() as $field_name => $field_obj ) {
4126
+		foreach ($this->field_settings() as $field_name => $field_obj) {
4127 4127
 			$this_model_fields_and_values[$field_name] = $field_obj->get_default_value();
4128 4128
 		}
4129 4129
 
4130 4130
 		$className = $this->_get_class_name();
4131
-		$classInstance = EE_Registry::instance()->load_class( $className, array( $this_model_fields_and_values ), FALSE, FALSE );
4131
+		$classInstance = EE_Registry::instance()->load_class($className, array($this_model_fields_and_values), FALSE, FALSE);
4132 4132
 
4133 4133
 		return $classInstance;
4134 4134
 	}
@@ -4141,45 +4141,45 @@  discard block
 block discarded – undo
4141 4141
 	 * @return EE_Base_Class
4142 4142
 	 * @throws \EE_Error
4143 4143
 	 */
4144
-	public function instantiate_class_from_array_or_object($cols_n_values){
4145
-		if( ! is_array( $cols_n_values ) && is_object( $cols_n_values )) {
4146
-			$cols_n_values = get_object_vars( $cols_n_values );
4144
+	public function instantiate_class_from_array_or_object($cols_n_values) {
4145
+		if ( ! is_array($cols_n_values) && is_object($cols_n_values)) {
4146
+			$cols_n_values = get_object_vars($cols_n_values);
4147 4147
 		}
4148 4148
 		$primary_key = NULL;
4149 4149
 		//make sure the array only has keys that are fields/columns on this model
4150
-		$this_model_fields_n_values = $this->_deduce_fields_n_values_from_cols_n_values( $cols_n_values );
4151
-		if( $this->has_primary_key_field() && isset( $this_model_fields_n_values[ $this->primary_key_name() ] ) ){
4152
-			$primary_key = $this_model_fields_n_values[ $this->primary_key_name() ];
4150
+		$this_model_fields_n_values = $this->_deduce_fields_n_values_from_cols_n_values($cols_n_values);
4151
+		if ($this->has_primary_key_field() && isset($this_model_fields_n_values[$this->primary_key_name()])) {
4152
+			$primary_key = $this_model_fields_n_values[$this->primary_key_name()];
4153 4153
 		}
4154
-		$className=$this->_get_class_name();
4154
+		$className = $this->_get_class_name();
4155 4155
 
4156 4156
 		//check we actually found results that we can use to build our model object
4157 4157
 		//if not, return null
4158
-		if( $this->has_primary_key_field()){
4159
-			if(empty( $this_model_fields_n_values[$this->primary_key_name()] )){
4158
+		if ($this->has_primary_key_field()) {
4159
+			if (empty($this_model_fields_n_values[$this->primary_key_name()])) {
4160 4160
 				return NULL;
4161 4161
 			}
4162
-		}else if($this->unique_indexes()){
4162
+		} else if ($this->unique_indexes()) {
4163 4163
 			$first_column = reset($this_model_fields_n_values);
4164
-			if(empty($first_column)){
4164
+			if (empty($first_column)) {
4165 4165
 				return NULL;
4166 4166
 			}
4167 4167
 		}
4168 4168
 
4169 4169
 		// if there is no primary key or the object doesn't already exist in the entity map, then create a new instance
4170
-		if ( $primary_key){
4171
-			$classInstance = $this->get_from_entity_map( $primary_key );
4172
-			if( ! $classInstance) {
4173
-				$classInstance = EE_Registry::instance()->load_class( $className, array( $this_model_fields_n_values, $this->_timezone ), TRUE, FALSE );
4170
+		if ($primary_key) {
4171
+			$classInstance = $this->get_from_entity_map($primary_key);
4172
+			if ( ! $classInstance) {
4173
+				$classInstance = EE_Registry::instance()->load_class($className, array($this_model_fields_n_values, $this->_timezone), TRUE, FALSE);
4174 4174
 				// add this new object to the entity map
4175
-				$classInstance = $this->add_to_entity_map( $classInstance );
4175
+				$classInstance = $this->add_to_entity_map($classInstance);
4176 4176
 			}
4177
-		}else{
4178
-			$classInstance = EE_Registry::instance()->load_class( $className, array( $this_model_fields_n_values, $this->_timezone ), TRUE, FALSE );
4177
+		} else {
4178
+			$classInstance = EE_Registry::instance()->load_class($className, array($this_model_fields_n_values, $this->_timezone), TRUE, FALSE);
4179 4179
 		}
4180 4180
 
4181 4181
 			//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.
4182
-		$this->set_timezone( $classInstance->get_timezone() );
4182
+		$this->set_timezone($classInstance->get_timezone());
4183 4183
 		return $classInstance;
4184 4184
 	}
4185 4185
 	/**
@@ -4187,8 +4187,8 @@  discard block
 block discarded – undo
4187 4187
 	 * @param int|string $id the ID of the model object
4188 4188
 	 * @return EE_Base_Class
4189 4189
 	 */
4190
-	public function get_from_entity_map( $id ){
4191
-		return isset( $this->_entity_map[ EEM_Base::$_model_query_blog_id ][ $id ] ) ? $this->_entity_map[ EEM_Base::$_model_query_blog_id ][ $id ] : NULL;
4190
+	public function get_from_entity_map($id) {
4191
+		return isset($this->_entity_map[EEM_Base::$_model_query_blog_id][$id]) ? $this->_entity_map[EEM_Base::$_model_query_blog_id][$id] : NULL;
4192 4192
 	}
4193 4193
 
4194 4194
 
@@ -4210,21 +4210,21 @@  discard block
 block discarded – undo
4210 4210
 	 * @throws EE_Error
4211 4211
 	 * @return \EE_Base_Class
4212 4212
 	 */
4213
-	public function add_to_entity_map( EE_Base_Class $object) {
4213
+	public function add_to_entity_map(EE_Base_Class $object) {
4214 4214
 		$className = $this->_get_class_name();
4215
-		if( ! $object instanceof $className ){
4216
-			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 ) );
4215
+		if ( ! $object instanceof $className) {
4216
+			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));
4217 4217
 		}
4218 4218
 		/** @var $object EE_Base_Class */
4219
-		if ( ! $object->ID() ){
4220
-			throw new EE_Error(sprintf(__("You tried storing a model object with NO ID in the %s entity mapper.", "event_espresso"),get_class($this)));
4219
+		if ( ! $object->ID()) {
4220
+			throw new EE_Error(sprintf(__("You tried storing a model object with NO ID in the %s entity mapper.", "event_espresso"), get_class($this)));
4221 4221
 		}
4222 4222
 		// double check it's not already there
4223
-		$classInstance = $this->get_from_entity_map( $object->ID() );
4224
-		if ( $classInstance ) {
4223
+		$classInstance = $this->get_from_entity_map($object->ID());
4224
+		if ($classInstance) {
4225 4225
 			return $classInstance;
4226 4226
 		} else {
4227
-			$this->_entity_map[ EEM_Base::$_model_query_blog_id ][ $object->ID() ] = $object;
4227
+			$this->_entity_map[EEM_Base::$_model_query_blog_id][$object->ID()] = $object;
4228 4228
 			return $object;
4229 4229
 		}
4230 4230
 	}
@@ -4238,13 +4238,13 @@  discard block
 block discarded – undo
4238 4238
 	 * @param int|string $id the ID of the model object
4239 4239
 	 * @return boolean
4240 4240
 	 */
4241
-	public function clear_entity_map( $id = null ) {
4242
-		if ( empty( $id ) ) {
4243
-			$this->_entity_map[ EEM_Base::$_model_query_blog_id ] = array();
4241
+	public function clear_entity_map($id = null) {
4242
+		if (empty($id)) {
4243
+			$this->_entity_map[EEM_Base::$_model_query_blog_id] = array();
4244 4244
 			return true;
4245 4245
 		}
4246
-		if ( isset( $this->_entity_map[ EEM_Base::$_model_query_blog_id ][ $id ] ) ) {
4247
-			unset( $this->_entity_map[ EEM_Base::$_model_query_blog_id ][ $id ] );
4246
+		if (isset($this->_entity_map[EEM_Base::$_model_query_blog_id][$id])) {
4247
+			unset($this->_entity_map[EEM_Base::$_model_query_blog_id][$id]);
4248 4248
 			return true;
4249 4249
 		}
4250 4250
 		return false;
@@ -4260,8 +4260,8 @@  discard block
 block discarded – undo
4260 4260
 	 * @param array $cols_n_values
4261 4261
 	 * @return array
4262 4262
 	 */
4263
-	public function deduce_fields_n_values_from_cols_n_values( $cols_n_values ) {
4264
-		return $this->_deduce_fields_n_values_from_cols_n_values( $cols_n_values );
4263
+	public function deduce_fields_n_values_from_cols_n_values($cols_n_values) {
4264
+		return $this->_deduce_fields_n_values_from_cols_n_values($cols_n_values);
4265 4265
 	}
4266 4266
 
4267 4267
 
@@ -4274,23 +4274,23 @@  discard block
 block discarded – undo
4274 4274
 	 * @param string $cols_n_values
4275 4275
 	 * @return array
4276 4276
 	 */
4277
-	protected function _deduce_fields_n_values_from_cols_n_values( $cols_n_values ){
4277
+	protected function _deduce_fields_n_values_from_cols_n_values($cols_n_values) {
4278 4278
 		$this_model_fields_n_values = array();
4279
-		foreach( $this->get_tables() as $table_alias => $table_obj ) {
4280
-			$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() );
4279
+		foreach ($this->get_tables() as $table_alias => $table_obj) {
4280
+			$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());
4281 4281
 			//there is a primary key on this table and its not set. Use defaults for all its columns
4282
-			if( $table_pk_value === null && $table_obj->get_pk_column() ){
4283
-				foreach( $this->_get_fields_for_table( $table_alias ) as $field_name => $field_obj ) {
4284
-					if( ! $field_obj->is_db_only_field() ){
4282
+			if ($table_pk_value === null && $table_obj->get_pk_column()) {
4283
+				foreach ($this->_get_fields_for_table($table_alias) as $field_name => $field_obj) {
4284
+					if ( ! $field_obj->is_db_only_field()) {
4285 4285
 						//prepare field as if its coming from db
4286
-						$prepared_value = $field_obj->prepare_for_set( $field_obj->get_default_value() );
4287
-						$this_model_fields_n_values[$field_name] = $field_obj->prepare_for_use_in_db( $prepared_value );
4286
+						$prepared_value = $field_obj->prepare_for_set($field_obj->get_default_value());
4287
+						$this_model_fields_n_values[$field_name] = $field_obj->prepare_for_use_in_db($prepared_value);
4288 4288
 					}
4289 4289
 				}
4290
-			}else{
4290
+			} else {
4291 4291
 				//the table's rows existed. Use their values
4292
-				foreach( $this->_get_fields_for_table( $table_alias ) as $field_name => $field_obj ) {
4293
-					if( ! $field_obj->is_db_only_field() ){
4292
+				foreach ($this->_get_fields_for_table($table_alias) as $field_name => $field_obj) {
4293
+					if ( ! $field_obj->is_db_only_field()) {
4294 4294
 						$this_model_fields_n_values[$field_name] = $this->_get_column_value_with_table_alias_or_not(
4295 4295
 							$cols_n_values, $field_obj->get_qualified_column(),
4296 4296
 							$field_obj->get_table_column()
@@ -4310,15 +4310,15 @@  discard block
 block discarded – undo
4310 4310
 	 * @param $regular_column
4311 4311
 	 * @return null
4312 4312
 	 */
4313
-	protected function _get_column_value_with_table_alias_or_not( $cols_n_values, $qualified_column, $regular_column ){
4313
+	protected function _get_column_value_with_table_alias_or_not($cols_n_values, $qualified_column, $regular_column) {
4314 4314
 		$value = null;
4315 4315
 		//ask the field what it think it's table_name.column_name should be, and call it the "qualified column"
4316 4316
 		//does the field on the model relate to this column retrieved from the db?
4317 4317
 		//or is it a db-only field? (not relating to the model)
4318
-		if( isset( $cols_n_values[ $qualified_column ] ) ){
4319
-			$value = $cols_n_values[ $qualified_column ];
4320
-		}elseif( isset( $cols_n_values[ $regular_column ] ) ){
4321
-			$value = $cols_n_values[ $regular_column ];
4318
+		if (isset($cols_n_values[$qualified_column])) {
4319
+			$value = $cols_n_values[$qualified_column];
4320
+		}elseif (isset($cols_n_values[$regular_column])) {
4321
+			$value = $cols_n_values[$regular_column];
4322 4322
 		}
4323 4323
 		return $value;
4324 4324
 	}
@@ -4334,25 +4334,25 @@  discard block
 block discarded – undo
4334 4334
 	 * @return EE_Base_Class
4335 4335
 	 * @throws \EE_Error
4336 4336
 	 */
4337
-	public function refresh_entity_map_from_db( $id ){
4338
-		$obj_in_map = $this->get_from_entity_map( $id );
4339
-		if( $obj_in_map ){
4337
+	public function refresh_entity_map_from_db($id) {
4338
+		$obj_in_map = $this->get_from_entity_map($id);
4339
+		if ($obj_in_map) {
4340 4340
 			$wpdb_results = $this->_get_all_wpdb_results(
4341
-				array( array( $this->get_primary_key_field()->get_name() => $id ), 'limit' => 1 )
4341
+				array(array($this->get_primary_key_field()->get_name() => $id), 'limit' => 1)
4342 4342
 			);
4343
-			if( $wpdb_results && is_array( $wpdb_results ) ){
4344
-				$one_row = reset( $wpdb_results );
4345
-				foreach( $this->_deduce_fields_n_values_from_cols_n_values($one_row ) as $field_name => $db_value ) {
4346
-					$obj_in_map->set_from_db( $field_name, $db_value );
4343
+			if ($wpdb_results && is_array($wpdb_results)) {
4344
+				$one_row = reset($wpdb_results);
4345
+				foreach ($this->_deduce_fields_n_values_from_cols_n_values($one_row) as $field_name => $db_value) {
4346
+					$obj_in_map->set_from_db($field_name, $db_value);
4347 4347
 				}
4348 4348
 				//clear the cache of related model objects
4349
-				foreach ( $this->relation_settings() as $relation_name => $relation_obj ){
4350
-					$obj_in_map->clear_cache($relation_name, NULL, TRUE );
4349
+				foreach ($this->relation_settings() as $relation_name => $relation_obj) {
4350
+					$obj_in_map->clear_cache($relation_name, NULL, TRUE);
4351 4351
 				}
4352 4352
 			}
4353 4353
 			return $obj_in_map;
4354
-		}else{
4355
-			return $this->get_one_by_ID( $id );
4354
+		} else {
4355
+			return $this->get_one_by_ID($id);
4356 4356
 		}
4357 4357
 	}
4358 4358
 
@@ -4370,24 +4370,24 @@  discard block
 block discarded – undo
4370 4370
 	 * @return \EE_Base_Class
4371 4371
 	 * @throws \EE_Error
4372 4372
 	 */
4373
-	public function refresh_entity_map_with( $id, $replacing_model_obj ) {
4374
-		$obj_in_map = $this->get_from_entity_map( $id );
4375
-		if( $obj_in_map ){
4376
-			if( $replacing_model_obj instanceof EE_Base_Class ){
4377
-				foreach( $replacing_model_obj->model_field_array() as $field_name => $value ) {
4378
-					$obj_in_map->set( $field_name, $value );
4373
+	public function refresh_entity_map_with($id, $replacing_model_obj) {
4374
+		$obj_in_map = $this->get_from_entity_map($id);
4375
+		if ($obj_in_map) {
4376
+			if ($replacing_model_obj instanceof EE_Base_Class) {
4377
+				foreach ($replacing_model_obj->model_field_array() as $field_name => $value) {
4378
+					$obj_in_map->set($field_name, $value);
4379 4379
 				}
4380 4380
 				//make the model object in the entity map's cache match the $replacing_model_obj
4381
-				foreach ( $this->relation_settings() as $relation_name => $relation_obj ){
4382
-					$obj_in_map->clear_cache($relation_name, NULL, TRUE );
4383
-					foreach( $replacing_model_obj->get_all_from_cache( $relation_name ) as $cache_id => $cached_obj ) {
4384
-						$obj_in_map->cache( $relation_name, $cached_obj, $cache_id );
4381
+				foreach ($this->relation_settings() as $relation_name => $relation_obj) {
4382
+					$obj_in_map->clear_cache($relation_name, NULL, TRUE);
4383
+					foreach ($replacing_model_obj->get_all_from_cache($relation_name) as $cache_id => $cached_obj) {
4384
+						$obj_in_map->cache($relation_name, $cached_obj, $cache_id);
4385 4385
 					}
4386 4386
 				}
4387 4387
 			}
4388 4388
 			return $obj_in_map;
4389
-		}else{
4390
-			$this->add_to_entity_map( $replacing_model_obj );
4389
+		} else {
4390
+			$this->add_to_entity_map($replacing_model_obj);
4391 4391
 			return $replacing_model_obj;
4392 4392
 		}
4393 4393
 	}
@@ -4400,7 +4400,7 @@  discard block
 block discarded – undo
4400 4400
 	 * require_once($this->_getClassName().".class.php");
4401 4401
 	 * @return string
4402 4402
 	 */
4403
-	private function _get_class_name(){
4403
+	private function _get_class_name() {
4404 4404
 		return "EE_".$this->get_this_model_name();
4405 4405
 	}
4406 4406
 
@@ -4413,8 +4413,8 @@  discard block
 block discarded – undo
4413 4413
 	 * @param int $quantity
4414 4414
 	 * @return string
4415 4415
 	 */
4416
-	public function item_name($quantity = 1){
4417
-		return (int)$quantity === 1 ? $this->singular_item : $this->plural_item;
4416
+	public function item_name($quantity = 1) {
4417
+		return (int) $quantity === 1 ? $this->singular_item : $this->plural_item;
4418 4418
 	}
4419 4419
 
4420 4420
 
@@ -4441,13 +4441,13 @@  discard block
 block discarded – undo
4441 4441
 	 * @throws EE_Error
4442 4442
 	 * @return mixed whatever the plugin which calls add_filter decides
4443 4443
 	 */
4444
-	public function __call($methodName,$args){
4445
-		$className=get_class($this);
4446
-		$tagName="FHEE__{$className}__{$methodName}";
4447
-		if(!has_filter($tagName)){
4444
+	public function __call($methodName, $args) {
4445
+		$className = get_class($this);
4446
+		$tagName = "FHEE__{$className}__{$methodName}";
4447
+		if ( ! has_filter($tagName)) {
4448 4448
 			throw new EE_Error(
4449 4449
 				sprintf(
4450
-					__( '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' ),
4450
+					__('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'),
4451 4451
 					$methodName,
4452 4452
 					$className,
4453 4453
 					$tagName,
@@ -4456,7 +4456,7 @@  discard block
 block discarded – undo
4456 4456
 			);
4457 4457
 		}
4458 4458
 
4459
-		return apply_filters($tagName,null,$this,$args);
4459
+		return apply_filters($tagName, null, $this, $args);
4460 4460
 	}
4461 4461
 
4462 4462
 
@@ -4474,28 +4474,28 @@  discard block
 block discarded – undo
4474 4474
 	 * @throws EE_Error
4475 4475
 	 * @return EE_Base_Class
4476 4476
 	 */
4477
-	public function ensure_is_obj( $base_class_obj_or_id, $ensure_is_in_db = FALSE ){
4477
+	public function ensure_is_obj($base_class_obj_or_id, $ensure_is_in_db = FALSE) {
4478 4478
 		$className = $this->_get_class_name();
4479
-		if ( $base_class_obj_or_id instanceof $className ) {
4479
+		if ($base_class_obj_or_id instanceof $className) {
4480 4480
 			$model_object = $base_class_obj_or_id;
4481 4481
 		} else {
4482 4482
 			$primary_key_field = $this->get_primary_key_field();
4483 4483
 			if (
4484 4484
 				$primary_key_field instanceof EE_Primary_Key_Int_Field
4485 4485
 				&& (
4486
-					is_int( $base_class_obj_or_id )
4487
-					|| is_string( $base_class_obj_or_id )
4486
+					is_int($base_class_obj_or_id)
4487
+					|| is_string($base_class_obj_or_id)
4488 4488
 				)
4489 4489
 			) {
4490 4490
 				// assume it's an ID.
4491 4491
 				// either a proper integer or a string representing an integer (eg "101" instead of 101)
4492
-				$model_object = $this->get_one_by_ID( $base_class_obj_or_id );
4492
+				$model_object = $this->get_one_by_ID($base_class_obj_or_id);
4493 4493
 			} else if (
4494 4494
 				$primary_key_field instanceof EE_Primary_Key_String_Field
4495
-			    && is_string( $base_class_obj_or_id )
4495
+			    && is_string($base_class_obj_or_id)
4496 4496
 			) {
4497 4497
 				// assume its a string representation of the object
4498
-				$model_object = $this->get_one_by_ID( $base_class_obj_or_id );
4498
+				$model_object = $this->get_one_by_ID($base_class_obj_or_id);
4499 4499
 			} else {
4500 4500
 				throw new EE_Error(
4501 4501
 					sprintf(
@@ -4505,12 +4505,12 @@  discard block
 block discarded – undo
4505 4505
 						),
4506 4506
 						$base_class_obj_or_id,
4507 4507
 						$this->_get_class_name(),
4508
-						print_r( $base_class_obj_or_id, true )
4508
+						print_r($base_class_obj_or_id, true)
4509 4509
 					)
4510 4510
 				);
4511 4511
 			}
4512 4512
 		}
4513
-		if ( $ensure_is_in_db && $model_object->ID() !== null ) {
4513
+		if ($ensure_is_in_db && $model_object->ID() !== null) {
4514 4514
 			$model_object->save();
4515 4515
 		}
4516 4516
 		return $model_object;
@@ -4526,19 +4526,19 @@  discard block
 block discarded – undo
4526 4526
 	 * @return int|string depending on the type of this model object's ID
4527 4527
 	 * @throws EE_Error
4528 4528
 	 */
4529
-	public function ensure_is_ID($base_class_obj_or_id){
4529
+	public function ensure_is_ID($base_class_obj_or_id) {
4530 4530
 		$className = $this->_get_class_name();
4531
-		if( $base_class_obj_or_id instanceof $className ){
4531
+		if ($base_class_obj_or_id instanceof $className) {
4532 4532
 			/** @var $base_class_obj_or_id EE_Base_Class */
4533 4533
 			$id = $base_class_obj_or_id->ID();
4534
-		}elseif(is_int($base_class_obj_or_id)){
4534
+		}elseif (is_int($base_class_obj_or_id)) {
4535 4535
 			//assume it's an ID
4536 4536
 			$id = $base_class_obj_or_id;
4537
-		}elseif(is_string($base_class_obj_or_id)){
4537
+		}elseif (is_string($base_class_obj_or_id)) {
4538 4538
 			//assume its a string representation of the object
4539 4539
 			$id = $base_class_obj_or_id;
4540
-		}else{
4541
-			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)));
4540
+		} else {
4541
+			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)));
4542 4542
 		}
4543 4543
 		return $id;
4544 4544
 	}
@@ -4561,14 +4561,14 @@  discard block
 block discarded – undo
4561 4561
 	 * @param int $values_already_prepared like one of the constants on EEM_Base
4562 4562
 	 * @return void
4563 4563
 	 */
4564
-	public function assume_values_already_prepared_by_model_object($values_already_prepared = self::not_prepared_by_model_object){
4564
+	public function assume_values_already_prepared_by_model_object($values_already_prepared = self::not_prepared_by_model_object) {
4565 4565
 		$this->_values_already_prepared_by_model_object = $values_already_prepared;
4566 4566
 	}
4567 4567
 	/**
4568 4568
 	 * Read comments for assume_values_already_prepared_by_model_object()
4569 4569
 	 * @return int
4570 4570
 	 */
4571
-	public function get_assumption_concerning_values_already_prepared_by_model_object(){
4571
+	public function get_assumption_concerning_values_already_prepared_by_model_object() {
4572 4572
 		return $this->_values_already_prepared_by_model_object;
4573 4573
 	}
4574 4574
 
@@ -4576,17 +4576,17 @@  discard block
 block discarded – undo
4576 4576
 	 * Gets all the indexes on this model
4577 4577
 	 * @return EE_Index[]
4578 4578
 	 */
4579
-	public function indexes(){
4579
+	public function indexes() {
4580 4580
 		return $this->_indexes;
4581 4581
 	}
4582 4582
 	/**
4583 4583
 	 * Gets all the Unique Indexes on this model
4584 4584
 	 * @return EE_Unique_Index[]
4585 4585
 	 */
4586
-	public function unique_indexes(){
4586
+	public function unique_indexes() {
4587 4587
 		$unique_indexes = array();
4588
-		foreach($this->_indexes as $name => $index){
4589
-			if($index instanceof EE_Unique_Index){
4588
+		foreach ($this->_indexes as $name => $index) {
4589
+			if ($index instanceof EE_Unique_Index) {
4590 4590
 				$unique_indexes [$name] = $index;
4591 4591
 			}
4592 4592
 		}
@@ -4604,13 +4604,13 @@  discard block
 block discarded – undo
4604 4604
 	 * @return EE_Model_Field_Base[] indexed by the field's name
4605 4605
 	 * @throws \EE_Error
4606 4606
 	 */
4607
-	public function get_combined_primary_key_fields(){
4608
-		foreach($this->indexes() as $index){
4609
-			if($index instanceof EE_Primary_Key_Index){
4607
+	public function get_combined_primary_key_fields() {
4608
+		foreach ($this->indexes() as $index) {
4609
+			if ($index instanceof EE_Primary_Key_Index) {
4610 4610
 				return $index->fields();
4611 4611
 			}
4612 4612
 		}
4613
-		return array( $this->primary_key_name() => $this->get_primary_key_field());
4613
+		return array($this->primary_key_name() => $this->get_primary_key_field());
4614 4614
 	}
4615 4615
 
4616 4616
 
@@ -4624,7 +4624,7 @@  discard block
 block discarded – undo
4624 4624
 	 * @return string
4625 4625
 	 * @throws \EE_Error
4626 4626
 	 */
4627
-	public function get_index_primary_key_string($cols_n_values){
4627
+	public function get_index_primary_key_string($cols_n_values) {
4628 4628
 		$cols_n_values_for_primary_key_index = array_intersect_key($cols_n_values, $this->get_combined_primary_key_fields());
4629 4629
 		return http_build_query($cols_n_values_for_primary_key_index);
4630 4630
 	}
@@ -4639,13 +4639,13 @@  discard block
 block discarded – undo
4639 4639
 	 * @return null|array
4640 4640
 	 * @throws \EE_Error
4641 4641
 	 */
4642
-	public function parse_index_primary_key_string( $index_primary_key_string) {
4642
+	public function parse_index_primary_key_string($index_primary_key_string) {
4643 4643
 		$key_fields = $this->get_combined_primary_key_fields();
4644 4644
 		//check all of them are in the $id
4645 4645
 		$key_vals_in_combined_pk = array();
4646
-		parse_str( $index_primary_key_string, $key_vals_in_combined_pk );
4647
-		foreach( $key_fields as $key_field_name => $field_obj ) {
4648
-			if( ! isset( $key_vals_in_combined_pk[ $key_field_name ] ) ){
4646
+		parse_str($index_primary_key_string, $key_vals_in_combined_pk);
4647
+		foreach ($key_fields as $key_field_name => $field_obj) {
4648
+			if ( ! isset($key_vals_in_combined_pk[$key_field_name])) {
4649 4649
 				return NULL;
4650 4650
 			}
4651 4651
 		}
@@ -4662,10 +4662,10 @@  discard block
 block discarded – undo
4662 4662
 	 * @return boolean
4663 4663
 	 * @throws \EE_Error
4664 4664
 	 */
4665
-	public function has_all_combined_primary_key_fields( $key_vals ) {
4666
-		$keys_it_should_have = array_keys( $this->get_combined_primary_key_fields() );
4667
-		foreach( $keys_it_should_have as $key ){
4668
-			if( ! isset( $key_vals[ $key ] ) ){
4665
+	public function has_all_combined_primary_key_fields($key_vals) {
4666
+		$keys_it_should_have = array_keys($this->get_combined_primary_key_fields());
4667
+		foreach ($keys_it_should_have as $key) {
4668
+			if ( ! isset($key_vals[$key])) {
4669 4669
 				return false;
4670 4670
 			}
4671 4671
 		}
@@ -4681,23 +4681,23 @@  discard block
 block discarded – undo
4681 4681
 	 * @throws EE_Error
4682 4682
 	 * @return \EE_Base_Class[] Array keys are object IDs (if there is a primary key on the model. if not, numerically indexed)
4683 4683
 	 */
4684
-	public function get_all_copies($model_object_or_attributes_array, $query_params = array()){
4684
+	public function get_all_copies($model_object_or_attributes_array, $query_params = array()) {
4685 4685
 
4686
-		if($model_object_or_attributes_array instanceof EE_Base_Class){
4686
+		if ($model_object_or_attributes_array instanceof EE_Base_Class) {
4687 4687
 			$attributes_array = $model_object_or_attributes_array->model_field_array();
4688
-		}elseif(is_array($model_object_or_attributes_array)){
4688
+		}elseif (is_array($model_object_or_attributes_array)) {
4689 4689
 			$attributes_array = $model_object_or_attributes_array;
4690
-		}else{
4691
-			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));
4690
+		} else {
4691
+			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));
4692 4692
 		}
4693 4693
 		//even copies obviously won't have the same ID, so remove the primary key
4694 4694
 		//from the WHERE conditions for finding copies (if there is a primary key, of course)
4695
-		if($this->has_primary_key_field() && isset($attributes_array[$this->primary_key_name()])){
4695
+		if ($this->has_primary_key_field() && isset($attributes_array[$this->primary_key_name()])) {
4696 4696
 			unset($attributes_array[$this->primary_key_name()]);
4697 4697
 		}
4698
-		if(isset($query_params[0])){
4699
-			$query_params[0] = array_merge($attributes_array,$query_params);
4700
-		}else{
4698
+		if (isset($query_params[0])) {
4699
+			$query_params[0] = array_merge($attributes_array, $query_params);
4700
+		} else {
4701 4701
 			$query_params[0] = $attributes_array;
4702 4702
 		}
4703 4703
 		return $this->get_all($query_params);
@@ -4713,16 +4713,16 @@  discard block
 block discarded – undo
4713 4713
 	 * @return EE_Base_Class
4714 4714
 	 * @throws \EE_Error
4715 4715
 	 */
4716
-	public function get_one_copy($model_object_or_attributes_array,$query_params = array()){
4717
-		if( ! is_array( $query_params ) ){
4718
-			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' );
4716
+	public function get_one_copy($model_object_or_attributes_array, $query_params = array()) {
4717
+		if ( ! is_array($query_params)) {
4718
+			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');
4719 4719
 			$query_params = array();
4720 4720
 		}
4721 4721
 		$query_params['limit'] = 1;
4722
-		$copies = $this->get_all_copies($model_object_or_attributes_array,$query_params);
4723
-		if(is_array($copies)){
4722
+		$copies = $this->get_all_copies($model_object_or_attributes_array, $query_params);
4723
+		if (is_array($copies)) {
4724 4724
 			return array_shift($copies);
4725
-		}else{
4725
+		} else {
4726 4726
 			return null;
4727 4727
 		}
4728 4728
 	}
@@ -4738,10 +4738,10 @@  discard block
 block discarded – undo
4738 4738
 	 * @return int number of rows updated
4739 4739
 	 * @throws \EE_Error
4740 4740
 	 */
4741
-	public function update_by_ID($fields_n_values,$id){
4741
+	public function update_by_ID($fields_n_values, $id) {
4742 4742
 		$query_params = array(0=>array($this->get_primary_key_field()->get_name() => $id),
4743 4743
 			'default_where_conditions'=>'other_models_only',);
4744
-		return $this->update($fields_n_values,$query_params);
4744
+		return $this->update($fields_n_values, $query_params);
4745 4745
 	}
4746 4746
 
4747 4747
 
@@ -4752,12 +4752,12 @@  discard block
 block discarded – undo
4752 4752
 	 * @return string an operator which can be used in SQL
4753 4753
 	 * @throws EE_Error
4754 4754
 	 */
4755
-	private function _prepare_operator_for_sql($operator_supplied){
4755
+	private function _prepare_operator_for_sql($operator_supplied) {
4756 4756
 		$sql_operator = isset($this->_valid_operators[$operator_supplied]) ? $this->_valid_operators[$operator_supplied] : null;
4757
-		if($sql_operator){
4757
+		if ($sql_operator) {
4758 4758
 			return $sql_operator;
4759
-		}else{
4760
-			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))));
4759
+		} else {
4760
+			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))));
4761 4761
 		}
4762 4762
 	}
4763 4763
 
@@ -4771,10 +4771,10 @@  discard block
 block discarded – undo
4771 4771
 	 * @return string[]
4772 4772
 	 * @throws \EE_Error
4773 4773
 	 */
4774
-	public function get_all_names($query_params = array()){
4774
+	public function get_all_names($query_params = array()) {
4775 4775
 		$objs = $this->get_all($query_params);
4776 4776
 		$names = array();
4777
-		foreach($objs as $obj){
4777
+		foreach ($objs as $obj) {
4778 4778
 			$names[$obj->ID()] = $obj->name();
4779 4779
 		}
4780 4780
 		return $names;
@@ -4793,11 +4793,11 @@  discard block
 block discarded – undo
4793 4793
 	 * @return array
4794 4794
 	 * @throws \EE_Error
4795 4795
 	 */
4796
-	public function get_IDs( $model_objects, $filter_out_empty_ids = false) {
4797
-		if( ! $this->has_primary_key_field() ) {
4798
-			if( WP_DEBUG ) {
4796
+	public function get_IDs($model_objects, $filter_out_empty_ids = false) {
4797
+		if ( ! $this->has_primary_key_field()) {
4798
+			if (WP_DEBUG) {
4799 4799
 				EE_Error::add_error(
4800
-					__( 'Trying to get IDs from a model than has no primary key', 'event_espresso' ),
4800
+					__('Trying to get IDs from a model than has no primary key', 'event_espresso'),
4801 4801
 					__FILE__,
4802 4802
 					__FUNCTION__,
4803 4803
 					__LINE__
@@ -4805,13 +4805,13 @@  discard block
 block discarded – undo
4805 4805
 			}
4806 4806
 		}
4807 4807
 		$IDs = array();
4808
-		foreach( $model_objects as $model_object ) {
4808
+		foreach ($model_objects as $model_object) {
4809 4809
 			$id = $model_object->ID();
4810
-			if( ! $id ) {
4811
-				if( $filter_out_empty_ids ) {
4810
+			if ( ! $id) {
4811
+				if ($filter_out_empty_ids) {
4812 4812
 					continue;
4813 4813
 				}
4814
-				if ( WP_DEBUG ) {
4814
+				if (WP_DEBUG) {
4815 4815
 					EE_Error::add_error(
4816 4816
 						__(
4817 4817
 							'Called %1$s on a model object that has no ID and so probably hasn\'t been saved to the database',
@@ -4833,8 +4833,8 @@  discard block
 block discarded – undo
4833 4833
 	 * are no capabilities that relate to this model returns false
4834 4834
 	 * @return string|false
4835 4835
 	 */
4836
-	public function cap_slug(){
4837
-		return apply_filters( 'FHEE__EEM_Base__cap_slug', $this->_caps_slug, $this);
4836
+	public function cap_slug() {
4837
+		return apply_filters('FHEE__EEM_Base__cap_slug', $this->_caps_slug, $this);
4838 4838
 	}
4839 4839
 
4840 4840
 
@@ -4849,34 +4849,34 @@  discard block
 block discarded – undo
4849 4849
 	 * @return EE_Default_Where_Conditions[] indexed by associated capability
4850 4850
 	 * @throws \EE_Error
4851 4851
 	 */
4852
-	public function cap_restrictions( $context = EEM_Base::caps_read ) {
4853
-		EEM_Base::verify_is_valid_cap_context( $context );
4852
+	public function cap_restrictions($context = EEM_Base::caps_read) {
4853
+		EEM_Base::verify_is_valid_cap_context($context);
4854 4854
 		//check if we ought to run the restriction generator first
4855
-		if(
4856
-			isset( $this->_cap_restriction_generators[ $context ] )
4857
-			&& $this->_cap_restriction_generators[ $context ] instanceof EE_Restriction_Generator_Base
4858
-			&& ! $this->_cap_restriction_generators[ $context ]->has_generated_cap_restrictions()
4855
+		if (
4856
+			isset($this->_cap_restriction_generators[$context])
4857
+			&& $this->_cap_restriction_generators[$context] instanceof EE_Restriction_Generator_Base
4858
+			&& ! $this->_cap_restriction_generators[$context]->has_generated_cap_restrictions()
4859 4859
 		) {
4860
-			$this->_cap_restrictions[ $context ] = array_merge(
4861
-				$this->_cap_restrictions[ $context ],
4862
-				$this->_cap_restriction_generators[ $context ]->generate_restrictions()
4860
+			$this->_cap_restrictions[$context] = array_merge(
4861
+				$this->_cap_restrictions[$context],
4862
+				$this->_cap_restriction_generators[$context]->generate_restrictions()
4863 4863
 			);
4864 4864
 		}
4865 4865
 		//and make sure we've finalized the construction of each restriction
4866
-		foreach( $this->_cap_restrictions[ $context ] as $where_conditions_obj ) {
4867
-			if ( $where_conditions_obj instanceof EE_Default_Where_Conditions ) {
4868
-				$where_conditions_obj->_finalize_construct( $this );
4866
+		foreach ($this->_cap_restrictions[$context] as $where_conditions_obj) {
4867
+			if ($where_conditions_obj instanceof EE_Default_Where_Conditions) {
4868
+				$where_conditions_obj->_finalize_construct($this);
4869 4869
 			}
4870 4870
 		}
4871 4871
 
4872
-		return $this->_cap_restrictions[ $context ];
4872
+		return $this->_cap_restrictions[$context];
4873 4873
 	}
4874 4874
 
4875 4875
 	/**
4876 4876
 	 * Indicating whether or not this model thinks its a wp core model
4877 4877
 	 * @return boolean
4878 4878
 	 */
4879
-	public function is_wp_core_model(){
4879
+	public function is_wp_core_model() {
4880 4880
 		return $this->_wp_core_model;
4881 4881
 	}
4882 4882
 
@@ -4890,12 +4890,12 @@  discard block
 block discarded – undo
4890 4890
 	 * @return EE_Default_Where_Conditions[] indexed by capability name
4891 4891
 	 * @throws \EE_Error
4892 4892
 	 */
4893
-	public function caps_missing( $context = EEM_Base::caps_read ) {
4893
+	public function caps_missing($context = EEM_Base::caps_read) {
4894 4894
 		$missing_caps = array();
4895
-		$cap_restrictions = $this->cap_restrictions( $context );
4896
-		foreach( $cap_restrictions as $cap => $restriction_if_no_cap ) {
4897
-			if( ! EE_Capabilities::instance()->current_user_can( $cap, $this->get_this_model_name() . '_model_applying_caps') ) {
4898
-				$missing_caps[ $cap ] = $restriction_if_no_cap;
4895
+		$cap_restrictions = $this->cap_restrictions($context);
4896
+		foreach ($cap_restrictions as $cap => $restriction_if_no_cap) {
4897
+			if ( ! EE_Capabilities::instance()->current_user_can($cap, $this->get_this_model_name().'_model_applying_caps')) {
4898
+				$missing_caps[$cap] = $restriction_if_no_cap;
4899 4899
 			}
4900 4900
 		}
4901 4901
 		return $missing_caps;
@@ -4907,7 +4907,7 @@  discard block
 block discarded – undo
4907 4907
 	 * one of 'read', 'edit', or 'delete'
4908 4908
 	 */
4909 4909
 	public function cap_contexts_to_cap_action_map() {
4910
-		return apply_filters( 'FHEE__EEM_Base__cap_contexts_to_cap_action_map', $this->_cap_contexts_to_cap_action_map, $this );
4910
+		return apply_filters('FHEE__EEM_Base__cap_contexts_to_cap_action_map', $this->_cap_contexts_to_cap_action_map, $this);
4911 4911
 	}
4912 4912
 
4913 4913
 
@@ -4918,19 +4918,19 @@  discard block
 block discarded – undo
4918 4918
 	 * @return string one of EEM_Base::cap_contexts_to_cap_action_map() values
4919 4919
 	 * @throws \EE_Error
4920 4920
 	 */
4921
-	public function cap_action_for_context( $context ) {
4921
+	public function cap_action_for_context($context) {
4922 4922
 		$mapping = $this->cap_contexts_to_cap_action_map();
4923
-		if( isset( $mapping[ $context ] ) ) {
4924
-			return $mapping[ $context ];
4923
+		if (isset($mapping[$context])) {
4924
+			return $mapping[$context];
4925 4925
 		}
4926
-		if( $action = apply_filters( 'FHEE__EEM_Base__cap_action_for_context', null, $this, $mapping, $context ) ) {
4926
+		if ($action = apply_filters('FHEE__EEM_Base__cap_action_for_context', null, $this, $mapping, $context)) {
4927 4927
 			return $action;
4928 4928
 		}
4929 4929
 		throw new EE_Error(
4930 4930
 			sprintf(
4931
-				__( 'Cannot find capability restrictions for context "%1$s", allowed values are:%2$s', 'event_espresso' ),
4931
+				__('Cannot find capability restrictions for context "%1$s", allowed values are:%2$s', 'event_espresso'),
4932 4932
 				$context,
4933
-				implode(',', array_keys( $this->cap_contexts_to_cap_action_map() ) )
4933
+				implode(',', array_keys($this->cap_contexts_to_cap_action_map()))
4934 4934
 			)
4935 4935
 		);
4936 4936
 
@@ -4941,7 +4941,7 @@  discard block
 block discarded – undo
4941 4941
 	 * @return array
4942 4942
 	 */
4943 4943
 	static public function valid_cap_contexts() {
4944
-		return apply_filters( 'FHEE__EEM_Base__valid_cap_contexts', array(
4944
+		return apply_filters('FHEE__EEM_Base__valid_cap_contexts', array(
4945 4945
 			self::caps_read,
4946 4946
 			self::caps_read_admin,
4947 4947
 			self::caps_edit,
@@ -4957,17 +4957,17 @@  discard block
 block discarded – undo
4957 4957
 	 * @return bool
4958 4958
 	 * @throws \EE_Error
4959 4959
 	 */
4960
-	static public function verify_is_valid_cap_context( $context ) {
4960
+	static public function verify_is_valid_cap_context($context) {
4961 4961
 		$valid_cap_contexts = EEM_Base::valid_cap_contexts();
4962
-		if( in_array( $context, $valid_cap_contexts ) ) {
4962
+		if (in_array($context, $valid_cap_contexts)) {
4963 4963
 			return true;
4964
-		}else{
4964
+		} else {
4965 4965
 			throw new EE_Error(
4966 4966
 				sprintf(
4967
-					__( 'Context "%1$s" passed into model "%2$s" is not a valid context. They are: %3$s', 'event_espresso' ),
4967
+					__('Context "%1$s" passed into model "%2$s" is not a valid context. They are: %3$s', 'event_espresso'),
4968 4968
 					$context,
4969
-					'EEM_Base' ,
4970
-					implode(',', $valid_cap_contexts )
4969
+					'EEM_Base',
4970
+					implode(',', $valid_cap_contexts)
4971 4971
 				)
4972 4972
 			);
4973 4973
 		}
Please login to merge, or discard this patch.
core/db_models/EEM_Registration.model.php 2 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -328,7 +328,7 @@
 block discarded – undo
328 328
 	* 		@param	int	$TXN_ID
329 329
 	* 		@param    int		$ATT_ID
330 330
 	* 		@param    int		$att_nmbr 	in case the ATT_ID is the same for multiple registrations (same details used) then the attendee number is required
331
-	*		@return 		mixed		array on success, FALSE on fail
331
+	*		@return 		null|EE_Base_Class		array on success, FALSE on fail
332 332
 	*/
333 333
 	public function get_registration_for_transaction_attendee( $TXN_ID = 0, $ATT_ID = 0, $att_nmbr = 0 ) {
334 334
 		return $this->get_one(array(
Please login to merge, or discard this patch.
Spacing   +108 added lines, -108 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@  discard block
 block discarded – undo
1 1
 <?php if ( ! defined('EVENT_ESPRESSO_VERSION')) exit('No direct script access allowed');
2
-require_once ( EE_MODELS . 'EEM_Soft_Delete_Base.model.php' );
3
-require_once ( EE_CLASSES . 'EE_Registration.class.php' );
2
+require_once (EE_MODELS.'EEM_Soft_Delete_Base.model.php');
3
+require_once (EE_CLASSES.'EE_Registration.class.php');
4 4
 /**
5 5
  *
6 6
  * Registration Model
@@ -101,31 +101,31 @@  discard block
 block discarded – undo
101 101
 	 *    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)
102 102
 	 * @return \EEM_Registration
103 103
 	 */
104
-	protected function __construct( $timezone = null ) {
105
-		$this->singular_item = __('Registration','event_espresso');
106
-		$this->plural_item = __('Registrations','event_espresso');
104
+	protected function __construct($timezone = null) {
105
+		$this->singular_item = __('Registration', 'event_espresso');
106
+		$this->plural_item = __('Registrations', 'event_espresso');
107 107
 
108 108
 		$this->_tables = array(
109
-			'Registration'=>new EE_Primary_Table('esp_registration','REG_ID')
109
+			'Registration'=>new EE_Primary_Table('esp_registration', 'REG_ID')
110 110
 		);
111 111
 		$this->_fields = array(
112 112
 			'Registration'=>array(
113
-				'REG_ID'=>new EE_Primary_Key_Int_Field('REG_ID', __('Registration ID','event_espresso')),
114
-				'EVT_ID'=>new EE_Foreign_Key_Int_Field('EVT_ID', __('Event ID','event_espresso'), false, 0, 'Event'),
115
-				'ATT_ID'=>new EE_Foreign_Key_Int_Field('ATT_ID', __('Attendee ID','event_espresso'), false, 0, 'Attendee'),
116
-				'TXN_ID'=>new EE_Foreign_Key_Int_Field('TXN_ID', __('Transaction ID','event_espresso'), false, 0, 'Transaction'),
117
-				'TKT_ID'=>new EE_Foreign_Key_Int_Field('TKT_ID', __('Ticket ID','event_espresso'), false, 0, 'Ticket'),
118
-				'STS_ID'=>new EE_Foreign_Key_String_Field('STS_ID', __('Status ID','event_espresso'), false, EEM_Registration::status_id_incomplete, 'Status'),
119
-				'REG_date'=>new EE_Datetime_Field('REG_date', __('Time registration occurred','event_espresso'), false, EE_Datetime_Field::now, $timezone ),
120
-				'REG_final_price'=>new EE_Money_Field('REG_final_price', __('Registration\'s share of the transaction total','event_espresso'), false, 0),
121
-				'REG_paid'=>new EE_Money_Field('REG_paid', __('Amount paid to date towards registration','event_espresso'), false, 0),
122
-				'REG_session'=>new EE_Plain_Text_Field('REG_session', __('Session ID of registration','event_espresso'), false, ''),
123
-				'REG_code'=>new EE_Plain_Text_Field('REG_code', __('Unique Code for this registration','event_espresso'), false, ''),
124
-				'REG_url_link'=>new EE_Plain_Text_Field('REG_url_link', __('String to be used in URL for identifying registration','event_espresso'), false, ''),
125
-				'REG_count'=>new EE_Integer_Field('REG_count', __('Count of this registration in the group registration ','event_espresso'), true, 1),
126
-				'REG_group_size'=>new EE_Integer_Field('REG_group_size', __('Number of registrations on this group','event_espresso'), false, 1),
127
-				'REG_att_is_going'=>new EE_Boolean_Field('REG_att_is_going', __('Flag indicating the registrant plans on attending','event_espresso'), false, false),
128
-				'REG_deleted' => new EE_Trashed_Flag_Field('REG_deleted', __('Flag indicating if registration has been archived or not.', 'event_espresso'), false, false )
113
+				'REG_ID'=>new EE_Primary_Key_Int_Field('REG_ID', __('Registration ID', 'event_espresso')),
114
+				'EVT_ID'=>new EE_Foreign_Key_Int_Field('EVT_ID', __('Event ID', 'event_espresso'), false, 0, 'Event'),
115
+				'ATT_ID'=>new EE_Foreign_Key_Int_Field('ATT_ID', __('Attendee ID', 'event_espresso'), false, 0, 'Attendee'),
116
+				'TXN_ID'=>new EE_Foreign_Key_Int_Field('TXN_ID', __('Transaction ID', 'event_espresso'), false, 0, 'Transaction'),
117
+				'TKT_ID'=>new EE_Foreign_Key_Int_Field('TKT_ID', __('Ticket ID', 'event_espresso'), false, 0, 'Ticket'),
118
+				'STS_ID'=>new EE_Foreign_Key_String_Field('STS_ID', __('Status ID', 'event_espresso'), false, EEM_Registration::status_id_incomplete, 'Status'),
119
+				'REG_date'=>new EE_Datetime_Field('REG_date', __('Time registration occurred', 'event_espresso'), false, EE_Datetime_Field::now, $timezone),
120
+				'REG_final_price'=>new EE_Money_Field('REG_final_price', __('Registration\'s share of the transaction total', 'event_espresso'), false, 0),
121
+				'REG_paid'=>new EE_Money_Field('REG_paid', __('Amount paid to date towards registration', 'event_espresso'), false, 0),
122
+				'REG_session'=>new EE_Plain_Text_Field('REG_session', __('Session ID of registration', 'event_espresso'), false, ''),
123
+				'REG_code'=>new EE_Plain_Text_Field('REG_code', __('Unique Code for this registration', 'event_espresso'), false, ''),
124
+				'REG_url_link'=>new EE_Plain_Text_Field('REG_url_link', __('String to be used in URL for identifying registration', 'event_espresso'), false, ''),
125
+				'REG_count'=>new EE_Integer_Field('REG_count', __('Count of this registration in the group registration ', 'event_espresso'), true, 1),
126
+				'REG_group_size'=>new EE_Integer_Field('REG_group_size', __('Number of registrations on this group', 'event_espresso'), false, 1),
127
+				'REG_att_is_going'=>new EE_Boolean_Field('REG_att_is_going', __('Flag indicating the registrant plans on attending', 'event_espresso'), false, false),
128
+				'REG_deleted' => new EE_Trashed_Flag_Field('REG_deleted', __('Flag indicating if registration has been archived or not.', 'event_espresso'), false, false)
129 129
 			)
130 130
 		);
131 131
 		$this->_model_relations = array(
@@ -137,12 +137,12 @@  discard block
 block discarded – undo
137 137
 			'Answer'=>new EE_Has_Many_Relation(),
138 138
 			'Checkin'=>new EE_Has_Many_Relation(),
139 139
 			'Registration_Payment' => new EE_Has_Many_Relation(),
140
-			'Payment'=>new EE_HABTM_Relation( 'Registration_Payment' ),
141
-			'Message' => new EE_Has_Many_Any_Relation( false ) //allow deletes even if there are messages in the queue related
140
+			'Payment'=>new EE_HABTM_Relation('Registration_Payment'),
141
+			'Message' => new EE_Has_Many_Any_Relation(false) //allow deletes even if there are messages in the queue related
142 142
 		);
143 143
 		$this->_model_chain_to_wp_user = 'Event';
144 144
 
145
-		parent::__construct( $timezone );
145
+		parent::__construct($timezone);
146 146
 	}
147 147
 
148 148
 
@@ -217,9 +217,9 @@  discard block
 block discarded – undo
217 217
 	 *		@param bool  $translated If true will return the values as singular localized strings
218 218
 	 *		@return array
219 219
 	 */
220
-	public static function reg_status_array( $exclude = array(), $translated = FALSE ) {
221
-		EEM_Registration::instance()->_get_registration_status_array( $exclude );
222
-		return $translated ? EEM_Status::instance()->localized_status( self::$_reg_status, FALSE, 'sentence') : self::$_reg_status;
220
+	public static function reg_status_array($exclude = array(), $translated = FALSE) {
221
+		EEM_Registration::instance()->_get_registration_status_array($exclude);
222
+		return $translated ? EEM_Status::instance()->localized_status(self::$_reg_status, FALSE, 'sentence') : self::$_reg_status;
223 223
 	}
224 224
 
225 225
 
@@ -230,18 +230,18 @@  discard block
 block discarded – undo
230 230
 	 * @param array $exclude
231 231
 	 * @return array
232 232
 	 */
233
-	private function _get_registration_status_array( $exclude = array() ) {
233
+	private function _get_registration_status_array($exclude = array()) {
234 234
 		//in the very rare circumstance that we are deleting a model's table's data
235 235
 		//and the table hasn't actually been created, this could have an error
236 236
 		/** @type WPDB $wpdb */
237 237
 		global $wpdb;
238
-		if( EEH_Activation::table_exists( $wpdb->prefix . 'esp_status' ) ){
239
-			$SQL = 'SELECT STS_ID, STS_code FROM '. $wpdb->prefix . 'esp_status WHERE STS_type = "registration"';
240
-			$results = $wpdb->get_results( $SQL );
238
+		if (EEH_Activation::table_exists($wpdb->prefix.'esp_status')) {
239
+			$SQL = 'SELECT STS_ID, STS_code FROM '.$wpdb->prefix.'esp_status WHERE STS_type = "registration"';
240
+			$results = $wpdb->get_results($SQL);
241 241
 			self::$_reg_status = array();
242
-			foreach ( $results as $status ) {
243
-				if ( ! in_array( $status->STS_ID, $exclude )) {
244
-					self::$_reg_status[ $status->STS_ID ] = $status->STS_code;
242
+			foreach ($results as $status) {
243
+				if ( ! in_array($status->STS_ID, $exclude)) {
244
+					self::$_reg_status[$status->STS_ID] = $status->STS_code;
245 245
 				}
246 246
 			}
247 247
 		}
@@ -256,15 +256,15 @@  discard block
 block discarded – undo
256 256
 	 * @param  array  $where_params Array of query_params as described in the comments for EEM_Base::get_all()
257 257
 	 * @return wpdb results array
258 258
 	 */
259
-	public function get_reg_months_and_years( $where_params ) {
259
+	public function get_reg_months_and_years($where_params) {
260 260
 		$query_params[0] = $where_params;
261 261
 		$query_params['group_by'] = array('reg_year', 'reg_month');
262
-		$query_params['order_by'] = array( 'REG_date' => 'DESC' );
262
+		$query_params['order_by'] = array('REG_date' => 'DESC');
263 263
 		$columns_to_select = array(
264 264
 			'reg_year' => array('YEAR(REG_date)', '%s'),
265 265
 			'reg_month' => array('MONTHNAME(REG_date)', '%s')
266 266
 			);
267
-		return $this->_get_all_wpdb_results( $query_params, OBJECT, $columns_to_select );
267
+		return $this->_get_all_wpdb_results($query_params, OBJECT, $columns_to_select);
268 268
 	}
269 269
 
270 270
 
@@ -276,11 +276,11 @@  discard block
 block discarded – undo
276 276
 	* 		@param		int		$ATT_ID
277 277
 	*		@return 	EE_Registration[]
278 278
 	*/
279
-	public function get_all_registrations_for_attendee( $ATT_ID = 0 ) {
280
-		if ( ! $ATT_ID ) {
279
+	public function get_all_registrations_for_attendee($ATT_ID = 0) {
280
+		if ( ! $ATT_ID) {
281 281
 			return FALSE;
282 282
 		}
283
-		return $this->get_all( array( array( 'ATT_ID' => $ATT_ID )));
283
+		return $this->get_all(array(array('ATT_ID' => $ATT_ID)));
284 284
 	}
285 285
 
286 286
 
@@ -291,8 +291,8 @@  discard block
 block discarded – undo
291 291
 	 * @param string $REG_url_link
292 292
 	 * @return EE_Registration
293 293
 	 */
294
-	public function get_registration_for_reg_url_link($REG_url_link){
295
-		if(!$REG_url_link){
294
+	public function get_registration_for_reg_url_link($REG_url_link) {
295
+		if ( ! $REG_url_link) {
296 296
 			return false;
297 297
 		}
298 298
 		return $this->get_one(array(array('REG_url_link'=>$REG_url_link)));
@@ -310,13 +310,13 @@  discard block
 block discarded – undo
310 310
 	* 		@param    int		$att_nmbr 	in case the ATT_ID is the same for multiple registrations (same details used) then the attendee number is required
311 311
 	*		@return 		mixed		array on success, FALSE on fail
312 312
 	*/
313
-	public function get_registration_for_transaction_attendee( $TXN_ID = 0, $ATT_ID = 0, $att_nmbr = 0 ) {
313
+	public function get_registration_for_transaction_attendee($TXN_ID = 0, $ATT_ID = 0, $att_nmbr = 0) {
314 314
 		return $this->get_one(array(
315 315
 			array(
316 316
 				'TXN_ID'=>$TXN_ID,
317 317
 				'ATT_ID'=>$ATT_ID
318 318
 			),
319
-			'limit'=>array( min( ( $att_nmbr-1 ), 0 ), 1 )
319
+			'limit'=>array(min(($att_nmbr - 1), 0), 1)
320 320
 		));
321 321
 	}
322 322
 
@@ -328,16 +328,16 @@  discard block
 block discarded – undo
328 328
 	 *		@param $period string which can be passed to php's strtotime function (eg "-1 month")
329 329
 	 *		@return stdClass[] with properties regDate and total
330 330
 	*/
331
-	public function get_registrations_per_day_report( $period = '-1 month' ) {
331
+	public function get_registrations_per_day_report($period = '-1 month') {
332 332
 
333
-		$sql_date = $this->convert_datetime_for_query( 'REG_date', date("Y-m-d H:i:s", strtotime($period) ), 'Y-m-d H:i:s', 'UTC' );
334
-		$where = array( 'REG_date' => array( '>=', $sql_date ), 'STS_ID' => array( '!=', EEM_Registration::status_id_incomplete ) );
333
+		$sql_date = $this->convert_datetime_for_query('REG_date', date("Y-m-d H:i:s", strtotime($period)), 'Y-m-d H:i:s', 'UTC');
334
+		$where = array('REG_date' => array('>=', $sql_date), 'STS_ID' => array('!=', EEM_Registration::status_id_incomplete));
335 335
 
336
-		if ( ! EE_Registry::instance()->CAP->current_user_can( 'ee_read_others_registrations', 'reg_per_day_report' ) ) {
336
+		if ( ! EE_Registry::instance()->CAP->current_user_can('ee_read_others_registrations', 'reg_per_day_report')) {
337 337
 			$where['Event.EVT_wp_user'] = get_current_user_id();
338 338
 		}
339 339
 
340
-		$query_interval = EEH_DTT_Helper::get_sql_query_interval_for_offset( $this->get_timezone(), 'REG_date' );
340
+		$query_interval = EEH_DTT_Helper::get_sql_query_interval_for_offset($this->get_timezone(), 'REG_date');
341 341
 
342 342
 		$results = $this->_get_all_wpdb_results(
343 343
 				array(
@@ -347,8 +347,8 @@  discard block
 block discarded – undo
347 347
 				),
348 348
 				OBJECT,
349 349
 				array(
350
-					'regDate'=>array( 'DATE(' . $query_interval . ')','%s'),
351
-					'total'=>array('count(REG_ID)','%d')
350
+					'regDate'=>array('DATE('.$query_interval.')', '%s'),
351
+					'total'=>array('count(REG_ID)', '%d')
352 352
 				));
353 353
 		return $results;
354 354
 	}
@@ -363,22 +363,22 @@  discard block
 block discarded – undo
363 363
 	 * @return stdClass[] with properties Registration_REG_date and a column for each registration status as the STS_ID
364 364
 	 *                    (i.e. RAP)
365 365
 	 */
366
-	public function get_registrations_per_day_and_per_status_report( $period = '-1 month' ) {
366
+	public function get_registrations_per_day_and_per_status_report($period = '-1 month') {
367 367
 		global $wpdb;
368
-		$registration_table = $wpdb->prefix . 'esp_registration';
368
+		$registration_table = $wpdb->prefix.'esp_registration';
369 369
 		$event_table = $wpdb->posts;
370
-		$sql_date = date("Y-m-d H:i:s", strtotime($period) );
370
+		$sql_date = date("Y-m-d H:i:s", strtotime($period));
371 371
 
372 372
 		//prepare the query interval for displaying offset
373
-		$query_interval = EEH_DTT_Helper::get_sql_query_interval_for_offset( $this->get_timezone(), 'dates.REG_date' );
373
+		$query_interval = EEH_DTT_Helper::get_sql_query_interval_for_offset($this->get_timezone(), 'dates.REG_date');
374 374
 
375 375
 		//inner date query
376 376
 		$inner_date_query = "SELECT DISTINCT REG_date from $registration_table ";
377 377
 		$inner_where = " WHERE";
378 378
 		//exclude events not authored by user if permissions in effect
379
-		if ( ! EE_Registry::instance()->CAP->current_user_can( 'ee_read_others_registrations', 'reg_per_event_report' ) ) {
379
+		if ( ! EE_Registry::instance()->CAP->current_user_can('ee_read_others_registrations', 'reg_per_event_report')) {
380 380
 			$inner_date_query .= "LEFT JOIN $event_table ON ID = EVT_ID";
381
-			$inner_where .= " post_author = " . get_current_user_id() . " AND";
381
+			$inner_where .= " post_author = ".get_current_user_id()." AND";
382 382
 		}
383 383
 		$inner_where .= " REG_date >= '$sql_date'";
384 384
 		$inner_date_query .= $inner_where;
@@ -390,8 +390,8 @@  discard block
 block discarded – undo
390 390
 		$select_parts = array();
391 391
 
392 392
 		//loop through registration stati to do parts for each status.
393
-		foreach ( EEM_Registration::reg_status_array() as $STS_ID => $STS_code ) {
394
-			if ( $STS_ID === EEM_Registration::status_id_incomplete ) {
393
+		foreach (EEM_Registration::reg_status_array() as $STS_ID => $STS_code) {
394
+			if ($STS_ID === EEM_Registration::status_id_incomplete) {
395 395
 				continue;
396 396
 			}
397 397
 			$select_parts[] = "COUNT($STS_code.REG_ID) as $STS_ID";
@@ -399,14 +399,14 @@  discard block
 block discarded – undo
399 399
 		}
400 400
 
401 401
 		//setup the selects
402
-		$select .= implode(', ', $select_parts );
402
+		$select .= implode(', ', $select_parts);
403 403
 		$select .= " FROM ($inner_date_query) AS dates LEFT JOIN ";
404 404
 
405 405
 		//setup the joins
406
-		$join .= implode( " LEFT JOIN ", $join_parts );
406
+		$join .= implode(" LEFT JOIN ", $join_parts);
407 407
 
408 408
 		//now let's put it all together
409
-		$query = $select . $join . ' GROUP BY Registration_REG_date';
409
+		$query = $select.$join.' GROUP BY Registration_REG_date';
410 410
 
411 411
 		//and execute it
412 412
 		$results = $wpdb->get_results(
@@ -427,23 +427,23 @@  discard block
 block discarded – undo
427 427
 	 * @param $period string which can be passed to php's strtotime function (eg "-1 month")
428 428
 	 *		@return stdClass[] each with properties event_name, reg_limit, and total
429 429
 	*/
430
-	public function get_registrations_per_event_report( $period = '-1 month' ) {
430
+	public function get_registrations_per_event_report($period = '-1 month') {
431 431
 
432
-		$date_sql = $this->convert_datetime_for_query( 'REG_date', date( "Y-m-d H:i:s", strtotime( $period )), 'Y-m-d H:i:s', 'UTC' );
433
-		$where = array( 'REG_date' => array( '>=', $date_sql ), 'STS_ID' => array( '!=', EEM_Registration::status_id_incomplete ) );
432
+		$date_sql = $this->convert_datetime_for_query('REG_date', date("Y-m-d H:i:s", strtotime($period)), 'Y-m-d H:i:s', 'UTC');
433
+		$where = array('REG_date' => array('>=', $date_sql), 'STS_ID' => array('!=', EEM_Registration::status_id_incomplete));
434 434
 
435
-		if ( ! EE_Registry::instance()->CAP->current_user_can( 'ee_read_others_registrations', 'reg_per_event_report' ) ) {
435
+		if ( ! EE_Registry::instance()->CAP->current_user_can('ee_read_others_registrations', 'reg_per_event_report')) {
436 436
 			$where['Event.EVT_wp_user'] = get_current_user_id();
437 437
 		}
438 438
 		$results = $this->_get_all_wpdb_results(array(
439 439
 			$where,
440 440
 			'group_by'=>'Event.EVT_name',
441 441
 			'order_by'=>'Event.EVT_name',
442
-			'limit'=>array(0,24)),
442
+			'limit'=>array(0, 24)),
443 443
 			OBJECT,
444 444
 			array(
445
-				'event_name'=>array('Event_CPT.post_title','%s'),
446
-				'total'=>array('COUNT(REG_ID)','%s')
445
+				'event_name'=>array('Event_CPT.post_title', '%s'),
446
+				'total'=>array('COUNT(REG_ID)', '%s')
447 447
 			)
448 448
 		);
449 449
 
@@ -461,19 +461,19 @@  discard block
 block discarded – undo
461 461
 	 * @return stdClass[] with properties `Registration_Event` and a column for each registration status as the STS_ID
462 462
 	 *                    (i.e. RAP)
463 463
 	 */
464
-	public function get_registrations_per_event_and_per_status_report( $period = '-1 month' ) {
464
+	public function get_registrations_per_event_and_per_status_report($period = '-1 month') {
465 465
 		global $wpdb;
466
-		$registration_table = $wpdb->prefix . 'esp_registration';
466
+		$registration_table = $wpdb->prefix.'esp_registration';
467 467
 		$event_table = $wpdb->posts;
468
-		$sql_date = date("Y-m-d H:i:s", strtotime($period) );
468
+		$sql_date = date("Y-m-d H:i:s", strtotime($period));
469 469
 
470 470
 		//inner date query
471 471
 		$inner_date_query = "SELECT DISTINCT EVT_ID, REG_date from $registration_table ";
472 472
 		$inner_where = " WHERE";
473 473
 		//exclude events not authored by user if permissions in effect
474
-		if ( ! EE_Registry::instance()->CAP->current_user_can( 'ee_read_others_registrations', 'reg_per_event_report' ) ) {
474
+		if ( ! EE_Registry::instance()->CAP->current_user_can('ee_read_others_registrations', 'reg_per_event_report')) {
475 475
 			$inner_date_query .= "LEFT JOIN $event_table ON ID = EVT_ID";
476
-			$inner_where .= " post_author = " . get_current_user_id() . " AND";
476
+			$inner_where .= " post_author = ".get_current_user_id()." AND";
477 477
 		}
478 478
 		$inner_where .= " REG_date >= '$sql_date'";
479 479
 		$inner_date_query .= $inner_where;
@@ -485,8 +485,8 @@  discard block
 block discarded – undo
485 485
 		$select_parts = array();
486 486
 
487 487
 		//loop through registration stati to do parts for each status.
488
-		foreach ( EEM_Registration::reg_status_array() as $STS_ID => $STS_code ) {
489
-			if ( $STS_ID === EEM_Registration::status_id_incomplete ) {
488
+		foreach (EEM_Registration::reg_status_array() as $STS_ID => $STS_code) {
489
+			if ($STS_ID === EEM_Registration::status_id_incomplete) {
490 490
 				continue;
491 491
 			}
492 492
 			$select_parts[] = "COUNT($STS_code.REG_ID) as $STS_ID";
@@ -494,14 +494,14 @@  discard block
 block discarded – undo
494 494
 		}
495 495
 
496 496
 		//setup the selects
497
-		$select .= implode( ', ', $select_parts );
497
+		$select .= implode(', ', $select_parts);
498 498
 		$select .= " FROM ($inner_date_query) AS dates LEFT JOIN $event_table as Event ON Event.ID = dates.EVT_ID LEFT JOIN ";
499 499
 
500 500
 		//setup remaining joins
501
-		$join .= implode( " LEFT JOIN ", $join_parts );
501
+		$join .= implode(" LEFT JOIN ", $join_parts);
502 502
 
503 503
 		//now put it all together
504
-		$query = $select . $join . ' GROUP BY Registration_Event';
504
+		$query = $select.$join.' GROUP BY Registration_Event';
505 505
 
506 506
 		//and execute
507 507
 		$results = $wpdb->get_results(
@@ -517,11 +517,11 @@  discard block
 block discarded – undo
517 517
 	 * @param int $TXN_ID
518 518
 	 * @return EE_Registration
519 519
 	 */
520
-	public function get_primary_registration_for_transaction_ID( $TXN_ID = 0){
521
-		if( ! $TXN_ID ){
520
+	public function get_primary_registration_for_transaction_ID($TXN_ID = 0) {
521
+		if ( ! $TXN_ID) {
522 522
 			return false;
523 523
 		}
524
-		return $this->get_one(array(array('TXN_ID'=>$TXN_ID,'REG_count'=>  EEM_Registration::PRIMARY_REGISTRANT_COUNT)));
524
+		return $this->get_one(array(array('TXN_ID'=>$TXN_ID, 'REG_count'=>  EEM_Registration::PRIMARY_REGISTRANT_COUNT)));
525 525
 	}
526 526
 
527 527
 
@@ -533,11 +533,11 @@  discard block
 block discarded – undo
533 533
 	 *		@param boolean $for_incomplete_payments
534 534
 	 *		@return int
535 535
 	 */
536
-	public function get_event_registration_count ( $EVT_ID, $for_incomplete_payments = FALSE ) {
536
+	public function get_event_registration_count($EVT_ID, $for_incomplete_payments = FALSE) {
537 537
 		// we only count approved registrations towards registration limits
538
-		$query_params = array( array( 'EVT_ID' => $EVT_ID, 'STS_ID' => self::status_id_approved ) );
539
-		if( $for_incomplete_payments ){
540
-			$query_params[0]['Transaction.STS_ID']=array('!=',  EEM_Transaction::complete_status_code);
538
+		$query_params = array(array('EVT_ID' => $EVT_ID, 'STS_ID' => self::status_id_approved));
539
+		if ($for_incomplete_payments) {
540
+			$query_params[0]['Transaction.STS_ID'] = array('!=', EEM_Transaction::complete_status_code);
541 541
 		}
542 542
 
543 543
 		return $this->count($query_params);
@@ -553,7 +553,7 @@  discard block
 block discarded – undo
553 553
 		/** @type WPDB $wpdb */
554 554
 		global $wpdb;
555 555
 		return $wpdb->query(
556
-				'DELETE r FROM ' . $this->table() . ' r LEFT JOIN ' . EEM_Transaction::instance()->table() . ' t ON r.TXN_ID = t.TXN_ID WHERE t.TXN_ID IS NULL' );
556
+				'DELETE r FROM '.$this->table().' r LEFT JOIN '.EEM_Transaction::instance()->table().' t ON r.TXN_ID = t.TXN_ID WHERE t.TXN_ID IS NULL' );
557 557
 	}
558 558
 
559 559
 	/**
@@ -563,17 +563,17 @@  discard block
 block discarded – undo
563 563
 	 * @param boolean $checked_in whether to count registrations checked IN or OUT
564 564
 	 * @return int
565 565
 	 */
566
-	public function count_registrations_checked_into_datetime( $DTT_ID, $checked_in = true) {
566
+	public function count_registrations_checked_into_datetime($DTT_ID, $checked_in = true) {
567 567
 		global $wpdb;
568 568
 		//subquery to get latest checkin
569 569
 		$query = $wpdb->prepare(
570 570
 			'SELECT '
571 571
 				. 'COUNT( DISTINCT checkins.REG_ID ) '
572
-			. 'FROM ' . EEM_Checkin::instance()->table() . ' AS checkins INNER JOIN'
572
+			. 'FROM '.EEM_Checkin::instance()->table().' AS checkins INNER JOIN'
573 573
 				. '( SELECT '
574 574
 					. 'max( CHK_timestamp ) AS latest_checkin, '
575 575
 					. 'REG_ID AS REG_ID '
576
-				. 'FROM ' . EEM_Checkin::instance()->table() . ' '
576
+				. 'FROM '.EEM_Checkin::instance()->table().' '
577 577
 				. 'WHERE DTT_ID=%d '
578 578
 				. 'GROUP BY REG_ID'
579 579
 			. ') AS most_recent_checkin_per_reg '
@@ -584,7 +584,7 @@  discard block
 block discarded – undo
584 584
 			$DTT_ID,
585 585
 			$checked_in
586 586
 		);
587
-		return (int)$wpdb->get_var( $query );
587
+		return (int) $wpdb->get_var($query);
588 588
 	}
589 589
 
590 590
 	/**
@@ -594,18 +594,18 @@  discard block
 block discarded – undo
594 594
 	 * @param boolean $checked_in whether to count registrations checked IN or OUT
595 595
 	 * @return int
596 596
 	 */
597
-	public function count_registrations_checked_into_event( $EVT_ID, $checked_in = true ) {
597
+	public function count_registrations_checked_into_event($EVT_ID, $checked_in = true) {
598 598
 		global $wpdb;
599 599
 		//subquery to get latest checkin
600 600
 		$query = $wpdb->prepare(
601 601
 			'SELECT '
602 602
 				. 'COUNT( DISTINCT checkins.REG_ID ) '
603
-			. 'FROM ' . EEM_Checkin::instance()->table() . ' AS checkins INNER JOIN'
603
+			. 'FROM '.EEM_Checkin::instance()->table().' AS checkins INNER JOIN'
604 604
 				. '( SELECT '
605 605
 					. 'max( CHK_timestamp ) AS latest_checkin, '
606 606
 					. 'REG_ID AS REG_ID '
607
-				. 'FROM ' . EEM_Checkin::instance()->table() . ' AS c '
608
-				. 'INNER JOIN ' . EEM_Datetime::instance()->table() . ' AS d '
607
+				. 'FROM '.EEM_Checkin::instance()->table().' AS c '
608
+				. 'INNER JOIN '.EEM_Datetime::instance()->table().' AS d '
609 609
 				. 'ON c.DTT_ID=d.DTT_ID '
610 610
 				. 'WHERE d.EVT_ID=%d '
611 611
 				. 'GROUP BY REG_ID'
@@ -617,7 +617,7 @@  discard block
 block discarded – undo
617 617
 			$EVT_ID,
618 618
 			$checked_in
619 619
 		);
620
-		return (int)$wpdb->get_var( $query );
620
+		return (int) $wpdb->get_var($query);
621 621
 	}
622 622
 
623 623
 
@@ -632,15 +632,15 @@  discard block
 block discarded – undo
632 632
 	 * @param array $attendee_ids
633 633
 	 * @return EE_Registration[]
634 634
 	 */
635
-	public function get_latest_registration_for_each_of_given_contacts( $attendee_ids = array() ) {
635
+	public function get_latest_registration_for_each_of_given_contacts($attendee_ids = array()) {
636 636
 		//first do a native wp_query to get the latest REG_ID's matching these attendees.
637 637
 		global $wpdb;
638
-		$registration_table = $wpdb->prefix . 'esp_registration';
638
+		$registration_table = $wpdb->prefix.'esp_registration';
639 639
 		$attendee_table = $wpdb->posts;
640
-		$attendee_ids = is_array( $attendee_ids )
641
-			? array_map( 'absint', $attendee_ids )
642
-			: array( (int) $attendee_ids );
643
-		$attendee_ids = implode( ',', $attendee_ids );
640
+		$attendee_ids = is_array($attendee_ids)
641
+			? array_map('absint', $attendee_ids)
642
+			: array((int) $attendee_ids);
643
+		$attendee_ids = implode(',', $attendee_ids);
644 644
 
645 645
 
646 646
 		//first we do a query to get the registration ids
@@ -665,24 +665,24 @@  discard block
 block discarded – undo
665 665
 			ARRAY_A
666 666
 		);
667 667
 
668
-		if ( empty( $registration_ids ) ) {
668
+		if (empty($registration_ids)) {
669 669
 			return array();
670 670
 		}
671 671
 
672 672
 		$ids_for_model_query = array();
673 673
 		//let's flatten the ids so they can be used in the model query.
674
-		foreach ( $registration_ids as $registration_id ) {
675
-			if ( isset( $registration_id['registration_id'] ) ) {
674
+		foreach ($registration_ids as $registration_id) {
675
+			if (isset($registration_id['registration_id'])) {
676 676
 				$ids_for_model_query[] = $registration_id['registration_id'];
677 677
 			}
678 678
 		}
679 679
 
680 680
 		//construct query
681 681
 		$_where = array(
682
-			'REG_ID' => array( 'IN', $ids_for_model_query )
682
+			'REG_ID' => array('IN', $ids_for_model_query)
683 683
 		);
684 684
 
685
-		return $this->get_all( array( $_where ) );
685
+		return $this->get_all(array($_where));
686 686
 	}
687 687
 
688 688
 
Please login to merge, or discard this patch.
core/db_models/EEM_Soft_Delete_Base.model.php 2 patches
Doc Comments   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -146,7 +146,7 @@  discard block
 block discarded – undo
146 146
 	 * Sum all the deleted items.
147 147
 	 * @param array $query_params like EEM_Base::get_all
148 148
 	 * @param string $field_to_sum
149
-	 * @return int
149
+	 * @return double
150 150
 	 */
151 151
 	public function sum_deleted($query_params = null, $field_to_sum = null){
152 152
 		$query_params = $this->_alter_query_params_so_only_trashed_items_included($query_params);
@@ -195,7 +195,7 @@  discard block
 block discarded – undo
195 195
 	 * @param boolean $allow_blocking if TRUE, matched objects will only be deleted if there is no related model info
196 196
 	 * that blocks it (ie, there' sno other data that depends on this data); if false, deletes regardless of other objects
197 197
 	 * which may depend on it. Its generally advisable to always leave this as TRUE, otherwise you could easily corrupt your DB
198
-	 * @return boolean success
198
+	 * @return integer success
199 199
 	 */
200 200
 	public function delete_permanently($query_params = array(), $allow_blocking = true){
201 201
 		$query_params = $this->_alter_query_params_so_deleted_and_undeleted_items_included($query_params);
Please login to merge, or discard this patch.
Spacing   +37 added lines, -37 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1 1
 <?php if ( ! defined('EVENT_ESPRESSO_VERSION')) exit('No direct script access allowed');
2
-require_once( EE_MODELS . 'EEM_Base.model.php');
2
+require_once(EE_MODELS.'EEM_Base.model.php');
3 3
 /**
4 4
  * EEM_Soft_Delete_Base
5 5
  *
@@ -25,13 +25,13 @@  discard block
 block discarded – undo
25 25
  * @subpackage		includes/models/
26 26
  * @author				Michael Nelson
27 27
  */
28
-abstract class EEM_Soft_Delete_Base extends EEM_Base{
28
+abstract class EEM_Soft_Delete_Base extends EEM_Base {
29 29
 
30 30
 	/**
31 31
 	 * @param null $timezone
32 32
 	 */
33 33
 	protected function __construct($timezone = NULL) {
34
-		if( ! $this->_default_where_conditions_strategy instanceof EE_Default_Where_Conditions ){
34
+		if ( ! $this->_default_where_conditions_strategy instanceof EE_Default_Where_Conditions) {
35 35
 			$this->_default_where_conditions_strategy = new EE_Soft_Delete_Where_Conditions();
36 36
 		}
37 37
 		parent::__construct($timezone);
@@ -42,12 +42,12 @@  discard block
 block discarded – undo
42 42
 	 * @return string
43 43
 	 * @throws EE_Error
44 44
 	 */
45
-	public function deleted_field_name(){
45
+	public function deleted_field_name() {
46 46
 		$field = $this->get_a_field_of_type('EE_Trashed_Flag_Field');
47
-		if($field){
47
+		if ($field) {
48 48
 			return $field->get_name();
49
-		}else{
50
-			throw new EE_Error(sprintf(__('We are trying to find the deleted flag field on %s, but none was found. Are you sure there is a field of type EE_Trashed_Flag_Field in %s constructor?','event_espresso'),get_class($this),get_class($this)));
49
+		} else {
50
+			throw new EE_Error(sprintf(__('We are trying to find the deleted flag field on %s, but none was found. Are you sure there is a field of type EE_Trashed_Flag_Field in %s constructor?', 'event_espresso'), get_class($this), get_class($this)));
51 51
 		}
52 52
 	}
53 53
 
@@ -57,7 +57,7 @@  discard block
 block discarded – undo
57 57
 	 * @param array $query_params like EEM_Base::get_all's $query_params
58 58
 	 * @return EE_Soft_Delete_Base_Class
59 59
 	 */
60
-	public function get_one_deleted($query_params = array()){
60
+	public function get_one_deleted($query_params = array()) {
61 61
 		$query_params = $this->_alter_query_params_so_only_trashed_items_included($query_params);
62 62
 		return parent::get_one($query_params);
63 63
 	}
@@ -67,7 +67,7 @@  discard block
 block discarded – undo
67 67
 	 * @param array $query_params like EEM_base::get_all's $query_params
68 68
 	 * @return EE_Soft_Delete_Base_Class
69 69
 	 */
70
-	public function get_one_deleted_or_undeleted($query_params = array()){
70
+	public function get_one_deleted_or_undeleted($query_params = array()) {
71 71
 		$query_params = $this->_alter_query_params_so_deleted_and_undeleted_items_included($query_params);
72 72
 		return parent::get_one($query_params);
73 73
 	}
@@ -77,11 +77,11 @@  discard block
 block discarded – undo
77 77
 	 * @param int|string $id
78 78
 	 * @return EE_Soft_Delete_Base_Class
79 79
 	 */
80
-	public function get_one_by_ID_but_ignore_deleted($id){
80
+	public function get_one_by_ID_but_ignore_deleted($id) {
81 81
 		return $this->get_one(
82 82
 			$this->alter_query_params_to_restrict_by_ID(
83 83
 				$id,
84
-				array( 'default_where_conditions' => 'default' )
84
+				array('default_where_conditions' => 'default')
85 85
 			)
86 86
 		);
87 87
 	}
@@ -93,7 +93,7 @@  discard block
 block discarded – undo
93 93
 	 * @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;
94 94
 	 * @return int
95 95
 	 */
96
-	public function count_deleted($query_params = null, $field_to_count = null, $distinct = FALSE){
96
+	public function count_deleted($query_params = null, $field_to_count = null, $distinct = FALSE) {
97 97
 		$query_params = $this->_alter_query_params_so_only_trashed_items_included($query_params);
98 98
 		return parent::count($query_params, $field_to_count, $distinct);
99 99
 	}
@@ -103,9 +103,9 @@  discard block
 block discarded – undo
103 103
 	 * @param array $query_params like EEM_Base::get_all's $query_params
104 104
 	 * @return array like EEM_Base::get_all's $query_params
105 105
 	 */
106
-	protected function _alter_query_params_so_only_trashed_items_included($query_params){
107
-		$deletedFlagFieldName=$this->deleted_field_name();
108
-		$query_params[0][$deletedFlagFieldName]=true;
106
+	protected function _alter_query_params_so_only_trashed_items_included($query_params) {
107
+		$deletedFlagFieldName = $this->deleted_field_name();
108
+		$query_params[0][$deletedFlagFieldName] = true;
109 109
 		return $query_params;
110 110
 	}
111 111
 
@@ -114,7 +114,7 @@  discard block
 block discarded – undo
114 114
 	 * @param array $query_params
115 115
 	 * @return array
116 116
 	 */
117
-	public function alter_query_params_so_deleted_and_undeleted_items_included( $query_params = array() ){
117
+	public function alter_query_params_so_deleted_and_undeleted_items_included($query_params = array()) {
118 118
 		return $this->_alter_query_params_so_deleted_and_undeleted_items_included($query_params);
119 119
 	}
120 120
 
@@ -123,8 +123,8 @@  discard block
 block discarded – undo
123 123
 	 * @param array $query_params
124 124
 	 * @return array
125 125
 	 */
126
-	protected function _alter_query_params_so_deleted_and_undeleted_items_included($query_params){
127
-		if( ! isset( $query_params[ 'default_where_conditions' ] ) ) {
126
+	protected function _alter_query_params_so_deleted_and_undeleted_items_included($query_params) {
127
+		if ( ! isset($query_params['default_where_conditions'])) {
128 128
 			$query_params['default_where_conditions'] = 'minimum';
129 129
 		}
130 130
 		return $query_params;
@@ -137,9 +137,9 @@  discard block
 block discarded – undo
137 137
 	 * @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;
138 138
 	 * @return int
139 139
 	 */
140
-	public function count_deleted_and_undeleted($query_params = null, $field_to_count = null, $distinct = FALSE){
140
+	public function count_deleted_and_undeleted($query_params = null, $field_to_count = null, $distinct = FALSE) {
141 141
 		$query_params = $this->_alter_query_params_so_deleted_and_undeleted_items_included($query_params);
142
-		return parent::count($query_params,$field_to_count, $distinct);
142
+		return parent::count($query_params, $field_to_count, $distinct);
143 143
 	}
144 144
 
145 145
 	/**
@@ -148,7 +148,7 @@  discard block
 block discarded – undo
148 148
 	 * @param string $field_to_sum
149 149
 	 * @return int
150 150
 	 */
151
-	public function sum_deleted($query_params = null, $field_to_sum = null){
151
+	public function sum_deleted($query_params = null, $field_to_sum = null) {
152 152
 		$query_params = $this->_alter_query_params_so_only_trashed_items_included($query_params);
153 153
 		return parent::sum($query_params, $field_to_sum);
154 154
 	}
@@ -159,7 +159,7 @@  discard block
 block discarded – undo
159 159
 	 * @param string $field_to_sum
160 160
 	 * @return int
161 161
 	 */
162
-	public function sum_deleted_and_undeleted($query_params = null, $field_to_sum = null){
162
+	public function sum_deleted_and_undeleted($query_params = null, $field_to_sum = null) {
163 163
 		$query_params = $this->_alter_query_params_so_deleted_and_undeleted_items_included($query_params);
164 164
 		parent::sum($query_params, $field_to_sum);
165 165
 	}
@@ -169,7 +169,7 @@  discard block
 block discarded – undo
169 169
 	 * @param array $query_params like EEM_Base::get_all
170 170
 	 * @return EE_Soft_Delete_Base_Class[]
171 171
 	 */
172
-	public function get_all_deleted_and_undeleted($query_params = array()){
172
+	public function get_all_deleted_and_undeleted($query_params = array()) {
173 173
 		$query_params = $this->_alter_query_params_so_deleted_and_undeleted_items_included($query_params);
174 174
 		return parent::get_all($query_params);
175 175
 	}
@@ -179,7 +179,7 @@  discard block
 block discarded – undo
179 179
 	 * @param array $query_params like EEM_Base::get_all
180 180
 	 * @return EE_Soft_Delete_Base_Class[]
181 181
 	 */
182
-	public function get_all_deleted($query_params = array()){
182
+	public function get_all_deleted($query_params = array()) {
183 183
 		$query_params = $this->_alter_query_params_so_only_trashed_items_included($query_params);
184 184
 		return parent::get_all($query_params);
185 185
 	}
@@ -197,7 +197,7 @@  discard block
 block discarded – undo
197 197
 	 * which may depend on it. Its generally advisable to always leave this as TRUE, otherwise you could easily corrupt your DB
198 198
 	 * @return boolean success
199 199
 	 */
200
-	public function delete_permanently($query_params = array(), $allow_blocking = true){
200
+	public function delete_permanently($query_params = array(), $allow_blocking = true) {
201 201
 		$query_params = $this->_alter_query_params_so_deleted_and_undeleted_items_included($query_params);
202 202
 		return parent::delete_permanently($query_params, $allow_blocking);
203 203
 	}
@@ -208,8 +208,8 @@  discard block
 block discarded – undo
208 208
 	 * @param mixed $ID int if primary key is an int, string otherwise
209 209
 	 * @return boolean success
210 210
 	 */
211
-	public function restore_by_ID($ID=FALSE){
212
-		return $this->delete_or_restore_by_ID(false,$ID);
211
+	public function restore_by_ID($ID = FALSE) {
212
+		return $this->delete_or_restore_by_ID(false, $ID);
213 213
 	}
214 214
 	/**
215 215
 	 * For deleting or restoring a particular item. Note that this model is a SOFT-DELETABLE model! However,
@@ -218,14 +218,14 @@  discard block
 block discarded – undo
218 218
 	 * @param mixed $ID int if primary key is an int, string otherwise
219 219
 	 * @return boolean
220 220
 	 */
221
-	public function delete_or_restore_by_ID($delete=true,$ID=FALSE){
222
-		if ( ! $ID ) {
221
+	public function delete_or_restore_by_ID($delete = true, $ID = FALSE) {
222
+		if ( ! $ID) {
223 223
 			return FALSE;
224 224
 		}
225 225
 		if (
226 226
 			$this->delete_or_restore(
227 227
 				$delete,
228
-				$this->alter_query_params_to_restrict_by_ID( $ID )
228
+				$this->alter_query_params_to_restrict_by_ID($ID)
229 229
 			)
230 230
 		) {
231 231
 			return TRUE;
@@ -245,7 +245,7 @@  discard block
 block discarded – undo
245 245
 	 * @param bool  $block_deletes
246 246
 	 * @return boolean
247 247
 	 */
248
-	public function delete($query_params = array(), $block_deletes = false){
248
+	public function delete($query_params = array(), $block_deletes = false) {
249 249
 		//no matter what, we WON'T block soft deletes.
250 250
 		return $this->delete_or_restore(true, $query_params);
251 251
 	}
@@ -256,7 +256,7 @@  discard block
 block discarded – undo
256 256
 	 * @param array $query_params like EEM_Base::get_all
257 257
 	 * @return boolean
258 258
 	 */
259
-	public function restore($query_params = array()){
259
+	public function restore($query_params = array()) {
260 260
 		return $this->delete_or_restore(false, $query_params);
261 261
 	}
262 262
 	/**
@@ -265,10 +265,10 @@  discard block
 block discarded – undo
265 265
 	 * @param array $query_params like EEM_Base::get_all
266 266
 	 * @return boolean
267 267
 	 */
268
-	function delete_or_restore($delete=true,$query_params = array()){
269
-		$deletedFlagFieldName=$this->deleted_field_name();
268
+	function delete_or_restore($delete = true, $query_params = array()) {
269
+		$deletedFlagFieldName = $this->deleted_field_name();
270 270
 		$query_params = $this->_alter_query_params_so_deleted_and_undeleted_items_included($query_params);
271
-		if ( $this->update (array($deletedFlagFieldName=>$delete), $query_params )) {
271
+		if ($this->update(array($deletedFlagFieldName=>$delete), $query_params)) {
272 272
 			return TRUE;
273 273
 		} else {
274 274
 			return FALSE;
@@ -286,8 +286,8 @@  discard block
 block discarded – undo
286 286
 	 * be aware that model objects being used could get out-of-sync with the database
287 287
 	 * @return int number of items updated
288 288
 	 */
289
-	public function update_deleted_and_undeleted($fields_n_values, $query_params, $keep_model_objs_in_sync = TRUE ){
289
+	public function update_deleted_and_undeleted($fields_n_values, $query_params, $keep_model_objs_in_sync = TRUE) {
290 290
 		$query_params = $this->_alter_query_params_so_deleted_and_undeleted_items_included($query_params);
291
-		return $this->update($fields_n_values, $query_params, $keep_model_objs_in_sync );
291
+		return $this->update($fields_n_values, $query_params, $keep_model_objs_in_sync);
292 292
 	}
293 293
 }
Please login to merge, or discard this patch.
core/helpers/EEH_Line_Item.helper.php 1 patch
Spacing   +342 added lines, -342 removed lines patch added patch discarded remove patch
@@ -1,4 +1,4 @@  discard block
 block discarded – undo
1
-<?php if (!defined('EVENT_ESPRESSO_VERSION')) { exit('No direct script access allowed'); }
1
+<?php if ( ! defined('EVENT_ESPRESSO_VERSION')) { exit('No direct script access allowed'); }
2 2
 /**
3 3
  *
4 4
  * EEH_Line_Item
@@ -45,8 +45,8 @@  discard block
 block discarded – undo
45 45
 	 * @return boolean success
46 46
 	 * @throws \EE_Error
47 47
 	 */
48
-	public static function add_unrelated_item( EE_Line_Item $parent_line_item, $name, $unit_price, $description = '', $quantity = 1, $taxable = FALSE, $code = NULL  ){
49
-		$items_subtotal = self::get_pre_tax_subtotal( $parent_line_item );
48
+	public static function add_unrelated_item(EE_Line_Item $parent_line_item, $name, $unit_price, $description = '', $quantity = 1, $taxable = FALSE, $code = NULL) {
49
+		$items_subtotal = self::get_pre_tax_subtotal($parent_line_item);
50 50
 		$line_item = EE_Line_Item::new_instance(array(
51 51
 			'LIN_name' => $name,
52 52
 			'LIN_desc' => $description,
@@ -54,7 +54,7 @@  discard block
 block discarded – undo
54 54
 			'LIN_quantity' => $quantity,
55 55
 			'LIN_percent' => null,
56 56
 			'LIN_is_taxable' => $taxable,
57
-			'LIN_order' => $items_subtotal instanceof EE_Line_Item ? count( $items_subtotal->children() ) : 0,
57
+			'LIN_order' => $items_subtotal instanceof EE_Line_Item ? count($items_subtotal->children()) : 0,
58 58
 			'LIN_total' => (float) $unit_price * (int) $quantity,
59 59
 			'LIN_type'=>  EEM_Line_Item::type_line_item,
60 60
 			'LIN_code' => $code,
@@ -64,7 +64,7 @@  discard block
 block discarded – undo
64 64
 			$line_item,
65 65
 			$parent_line_item
66 66
 		);
67
-		return self::add_item( $parent_line_item, $line_item );
67
+		return self::add_item($parent_line_item, $line_item);
68 68
 	}
69 69
 
70 70
 
@@ -86,7 +86,7 @@  discard block
 block discarded – undo
86 86
 	 * @return boolean success
87 87
 	 * @throws \EE_Error
88 88
 	 */
89
-	public static function add_percentage_based_item( EE_Line_Item $parent_line_item, $name, $percentage_amount, $description = '', $taxable = FALSE ){
89
+	public static function add_percentage_based_item(EE_Line_Item $parent_line_item, $name, $percentage_amount, $description = '', $taxable = FALSE) {
90 90
 		$line_item = EE_Line_Item::new_instance(array(
91 91
 			'LIN_name' => $name,
92 92
 			'LIN_desc' => $description,
@@ -94,7 +94,7 @@  discard block
 block discarded – undo
94 94
 			'LIN_percent' => $percentage_amount,
95 95
 			'LIN_quantity' => NULL,
96 96
 			'LIN_is_taxable' => $taxable,
97
-			'LIN_total' => (float) ( $percentage_amount * ( $parent_line_item->total() / 100 ) ),
97
+			'LIN_total' => (float) ($percentage_amount * ($parent_line_item->total() / 100)),
98 98
 			'LIN_type'=>  EEM_Line_Item::type_line_item,
99 99
 			'LIN_parent' => $parent_line_item->ID()
100 100
 		));
@@ -102,7 +102,7 @@  discard block
 block discarded – undo
102 102
 			'FHEE__EEH_Line_Item__add_percentage_based_item__line_item',
103 103
 			$line_item
104 104
 		);
105
-		return self::add_item( $parent_line_item, $line_item );
105
+		return self::add_item($parent_line_item, $line_item);
106 106
 	}
107 107
 
108 108
 
@@ -123,15 +123,15 @@  discard block
 block discarded – undo
123 123
 	 * @return \EE_Line_Item
124 124
 	 * @throws \EE_Error
125 125
 	 */
126
-	public static function add_ticket_purchase( EE_Line_Item $total_line_item, EE_Ticket $ticket, $qty = 1 ){
127
-		if ( ! $total_line_item instanceof EE_Line_Item || ! $total_line_item->is_total() ) {
128
-			throw new EE_Error( sprintf( __( 'A valid line item total is required in order to add tickets. A line item of type "%s" was passed.', 'event_espresso' ), $ticket->ID(), $total_line_item->ID() ) );
126
+	public static function add_ticket_purchase(EE_Line_Item $total_line_item, EE_Ticket $ticket, $qty = 1) {
127
+		if ( ! $total_line_item instanceof EE_Line_Item || ! $total_line_item->is_total()) {
128
+			throw new EE_Error(sprintf(__('A valid line item total is required in order to add tickets. A line item of type "%s" was passed.', 'event_espresso'), $ticket->ID(), $total_line_item->ID()));
129 129
 		}
130 130
 		// either increment the qty for an existing ticket
131
-		$line_item = self::increment_ticket_qty_if_already_in_cart( $total_line_item, $ticket, $qty );
131
+		$line_item = self::increment_ticket_qty_if_already_in_cart($total_line_item, $ticket, $qty);
132 132
 		// or add a new one
133
-		if ( ! $line_item instanceof EE_Line_Item ) {
134
-			$line_item = self::create_ticket_line_item( $total_line_item, $ticket, $qty );
133
+		if ( ! $line_item instanceof EE_Line_Item) {
134
+			$line_item = self::create_ticket_line_item($total_line_item, $ticket, $qty);
135 135
 		}
136 136
 		$total_line_item->recalculate_total_including_taxes();
137 137
 		return $line_item;
@@ -147,11 +147,11 @@  discard block
 block discarded – undo
147 147
 	 * @return \EE_Line_Item
148 148
 	 * @throws \EE_Error
149 149
 	 */
150
-	public static function increment_ticket_qty_if_already_in_cart( EE_Line_Item $total_line_item, EE_Ticket $ticket, $qty = 1 ) {
150
+	public static function increment_ticket_qty_if_already_in_cart(EE_Line_Item $total_line_item, EE_Ticket $ticket, $qty = 1) {
151 151
 		$line_item = null;
152
-		if ( $total_line_item instanceof EE_Line_Item && $total_line_item->is_total() ) {
153
-			$ticket_line_items = EEH_Line_Item::get_ticket_line_items( $total_line_item );
154
-			foreach ( (array)$ticket_line_items as $ticket_line_item ) {
152
+		if ($total_line_item instanceof EE_Line_Item && $total_line_item->is_total()) {
153
+			$ticket_line_items = EEH_Line_Item::get_ticket_line_items($total_line_item);
154
+			foreach ((array) $ticket_line_items as $ticket_line_item) {
155 155
 				if (
156 156
 					$ticket_line_item instanceof EE_Line_Item
157 157
 					&& (int) $ticket_line_item->OBJ_ID() === (int) $ticket->ID()
@@ -161,8 +161,8 @@  discard block
 block discarded – undo
161 161
 				}
162 162
 			}
163 163
 		}
164
-		if ( $line_item instanceof EE_Line_Item ) {
165
-			EEH_Line_Item::increment_quantity( $line_item, $qty );
164
+		if ($line_item instanceof EE_Line_Item) {
165
+			EEH_Line_Item::increment_quantity($line_item, $qty);
166 166
 			return $line_item;
167 167
 		}
168 168
 		return null;
@@ -179,16 +179,16 @@  discard block
 block discarded – undo
179 179
 	 * @return void
180 180
 	 * @throws \EE_Error
181 181
 	 */
182
-	public static function increment_quantity( EE_Line_Item $line_item, $qty = 1 ) {
183
-		if( ! $line_item->is_percent() ) {
182
+	public static function increment_quantity(EE_Line_Item $line_item, $qty = 1) {
183
+		if ( ! $line_item->is_percent()) {
184 184
 			$qty += $line_item->quantity();
185
-			$line_item->set_quantity( $qty );
186
-			$line_item->set_total( $line_item->unit_price() * $qty );
185
+			$line_item->set_quantity($qty);
186
+			$line_item->set_total($line_item->unit_price() * $qty);
187 187
 			$line_item->save();
188 188
 		}
189
-		foreach( $line_item->children() as $child ) {
190
-			if( $child->is_sub_line_item() ) {
191
-				EEH_Line_Item::update_quantity( $child, $qty );
189
+		foreach ($line_item->children() as $child) {
190
+			if ($child->is_sub_line_item()) {
191
+				EEH_Line_Item::update_quantity($child, $qty);
192 192
 			}
193 193
 		}
194 194
 	}
@@ -204,17 +204,17 @@  discard block
 block discarded – undo
204 204
 	 * @return void
205 205
 	 * @throws \EE_Error
206 206
 	 */
207
-	public static function decrement_quantity( EE_Line_Item $line_item, $qty = 1 ) {
208
-		if( ! $line_item->is_percent() ) {
207
+	public static function decrement_quantity(EE_Line_Item $line_item, $qty = 1) {
208
+		if ( ! $line_item->is_percent()) {
209 209
 			$qty = $line_item->quantity() - $qty;
210
-			$qty = max( $qty, 0 );
211
-			$line_item->set_quantity( $qty );
212
-			$line_item->set_total( $line_item->unit_price() * $qty );
210
+			$qty = max($qty, 0);
211
+			$line_item->set_quantity($qty);
212
+			$line_item->set_total($line_item->unit_price() * $qty);
213 213
 			$line_item->save();
214 214
 		}
215
-		foreach( $line_item->children() as $child ) {
216
-			if( $child->is_sub_line_item() ) {
217
-				EEH_Line_Item::update_quantity( $child, $qty );
215
+		foreach ($line_item->children() as $child) {
216
+			if ($child->is_sub_line_item()) {
217
+				EEH_Line_Item::update_quantity($child, $qty);
218 218
 			}
219 219
 		}
220 220
 	}
@@ -229,15 +229,15 @@  discard block
 block discarded – undo
229 229
 	 * @param int          $new_quantity
230 230
 	 * @throws \EE_Error
231 231
 	 */
232
-	public static function update_quantity( EE_Line_Item $line_item, $new_quantity ) {
233
-		if( ! $line_item->is_percent() ) {
234
-			$line_item->set_quantity( $new_quantity );
235
-			$line_item->set_total( $line_item->unit_price() * $new_quantity );
232
+	public static function update_quantity(EE_Line_Item $line_item, $new_quantity) {
233
+		if ( ! $line_item->is_percent()) {
234
+			$line_item->set_quantity($new_quantity);
235
+			$line_item->set_total($line_item->unit_price() * $new_quantity);
236 236
 			$line_item->save();
237 237
 		}
238
-		foreach( $line_item->children() as $child ) {
239
-			if( $child->is_sub_line_item() ) {
240
-				EEH_Line_Item::update_quantity( $child, $new_quantity );
238
+		foreach ($line_item->children() as $child) {
239
+			if ($child->is_sub_line_item()) {
240
+				EEH_Line_Item::update_quantity($child, $new_quantity);
241 241
 			}
242 242
 		}
243 243
 	}
@@ -252,43 +252,43 @@  discard block
 block discarded – undo
252 252
 	 * @return \EE_Line_Item
253 253
 	 * @throws \EE_Error
254 254
 	 */
255
-	public static function create_ticket_line_item( EE_Line_Item $total_line_item, EE_Ticket $ticket, $qty = 1 ) {
255
+	public static function create_ticket_line_item(EE_Line_Item $total_line_item, EE_Ticket $ticket, $qty = 1) {
256 256
 		$datetimes = $ticket->datetimes();
257
-		$first_datetime = reset( $datetimes );
258
-		if( $first_datetime instanceof EE_Datetime && $first_datetime->event() instanceof EE_Event ) {
257
+		$first_datetime = reset($datetimes);
258
+		if ($first_datetime instanceof EE_Datetime && $first_datetime->event() instanceof EE_Event) {
259 259
 			$first_datetime_name = $first_datetime->event()->name();
260 260
 		} else {
261
-			$first_datetime_name = __( 'Event', 'event_espresso' );
261
+			$first_datetime_name = __('Event', 'event_espresso');
262 262
 		}
263
-		$event = sprintf( _x( '(For %1$s)', '(For Event Name)', 'event_espresso' ), $first_datetime_name );
263
+		$event = sprintf(_x('(For %1$s)', '(For Event Name)', 'event_espresso'), $first_datetime_name);
264 264
 		// get event subtotal line
265
-		$events_sub_total = self::get_event_line_item_for_ticket( $total_line_item, $ticket );
265
+		$events_sub_total = self::get_event_line_item_for_ticket($total_line_item, $ticket);
266 266
 		// add $ticket to cart
267
-		$line_item = EE_Line_Item::new_instance( array(
267
+		$line_item = EE_Line_Item::new_instance(array(
268 268
 			'LIN_name'       	=> $ticket->name(),
269
-			'LIN_desc'       		=> $ticket->description() !== '' ? $ticket->description() . ' ' . $event : $event,
269
+			'LIN_desc'       		=> $ticket->description() !== '' ? $ticket->description().' '.$event : $event,
270 270
 			'LIN_unit_price' 	=> $ticket->price(),
271 271
 			'LIN_quantity'   	=> $qty,
272 272
 			'LIN_is_taxable' 	=> $ticket->taxable(),
273
-			'LIN_order'      	=> count( $events_sub_total->children() ),
273
+			'LIN_order'      	=> count($events_sub_total->children()),
274 274
 			'LIN_total'      		=> $ticket->price() * $qty,
275 275
 			'LIN_type'       		=> EEM_Line_Item::type_line_item,
276 276
 			'OBJ_ID'         		=> $ticket->ID(),
277 277
 			'OBJ_type'       	=> 'Ticket'
278
-		) );
278
+		));
279 279
 		$line_item = apply_filters(
280 280
 			'FHEE__EEH_Line_Item__create_ticket_line_item__line_item',
281 281
 			$line_item
282 282
 		);
283
-		$events_sub_total->add_child_line_item( $line_item );
283
+		$events_sub_total->add_child_line_item($line_item);
284 284
 		//now add the sub-line items
285 285
 		$running_total_for_ticket = 0;
286
-		foreach ( $ticket->prices( array( 'order_by' => array( 'PRC_order' => 'ASC' ) ) ) as $price ) {
286
+		foreach ($ticket->prices(array('order_by' => array('PRC_order' => 'ASC'))) as $price) {
287 287
 			$sign = $price->is_discount() ? -1 : 1;
288 288
 			$price_total = $price->is_percent()
289 289
 				? $running_total_for_ticket * $price->amount() / 100
290 290
 				: $price->amount() * $qty;
291
-			$sub_line_item = EE_Line_Item::new_instance( array(
291
+			$sub_line_item = EE_Line_Item::new_instance(array(
292 292
 				'LIN_name'       	=> $price->name(),
293 293
 				'LIN_desc'       		=> $price->desc(),
294 294
 				'LIN_quantity'   	=> $price->is_percent() ? null : $qty,
@@ -298,18 +298,18 @@  discard block
 block discarded – undo
298 298
 				'LIN_type'       		=> EEM_Line_Item::type_sub_line_item,
299 299
 				'OBJ_ID'         		=> $price->ID(),
300 300
 				'OBJ_type'       	=> 'Price'
301
-			) );
301
+			));
302 302
 			$sub_line_item = apply_filters(
303 303
 				'FHEE__EEH_Line_Item__create_ticket_line_item__sub_line_item',
304 304
 				$sub_line_item
305 305
 			);
306
-			if ( $price->is_percent() ) {
307
-				$sub_line_item->set_percent( $sign * $price->amount() );
306
+			if ($price->is_percent()) {
307
+				$sub_line_item->set_percent($sign * $price->amount());
308 308
 			} else {
309
-				$sub_line_item->set_unit_price( $sign * $price->amount() );
309
+				$sub_line_item->set_unit_price($sign * $price->amount());
310 310
 			}
311 311
 			$running_total_for_ticket += $price_total;
312
-			$line_item->add_child_line_item( $sub_line_item );
312
+			$line_item->add_child_line_item($sub_line_item);
313 313
 		}
314 314
 		return $line_item;
315 315
 	}
@@ -329,11 +329,11 @@  discard block
 block discarded – undo
329 329
 	 * @return boolean
330 330
 	 * @throws \EE_Error
331 331
 	 */
332
-	public static function add_item( EE_Line_Item $total_line_item, EE_Line_Item $item ){
333
-		$pre_tax_subtotal = self::get_pre_tax_subtotal( $total_line_item );
334
-		if ( $pre_tax_subtotal instanceof EE_Line_Item ){
332
+	public static function add_item(EE_Line_Item $total_line_item, EE_Line_Item $item) {
333
+		$pre_tax_subtotal = self::get_pre_tax_subtotal($total_line_item);
334
+		if ($pre_tax_subtotal instanceof EE_Line_Item) {
335 335
 			$success = $pre_tax_subtotal->add_child_line_item($item);
336
-		}else{
336
+		} else {
337 337
 			return FALSE;
338 338
 		}
339 339
 		$total_line_item->recalculate_total_including_taxes();
@@ -352,34 +352,34 @@  discard block
 block discarded – undo
352 352
 	 * @return bool success
353 353
 	 * @throws \EE_Error
354 354
 	 */
355
-	public static function cancel_ticket_line_item( EE_Line_Item $ticket_line_item, $qty = 1 ) {
355
+	public static function cancel_ticket_line_item(EE_Line_Item $ticket_line_item, $qty = 1) {
356 356
 		// validate incoming line_item
357
-		if ( $ticket_line_item->OBJ_type() !== 'Ticket' ) {
357
+		if ($ticket_line_item->OBJ_type() !== 'Ticket') {
358 358
 			throw new EE_Error(
359 359
 				sprintf(
360
-					__( 'The supplied line item must have an Object Type of "Ticket", not %1$s.', 'event_espresso' ),
360
+					__('The supplied line item must have an Object Type of "Ticket", not %1$s.', 'event_espresso'),
361 361
 					$ticket_line_item->type()
362 362
 				)
363 363
 			);
364 364
 		}
365
-		if ( $ticket_line_item->quantity() < $qty ) {
365
+		if ($ticket_line_item->quantity() < $qty) {
366 366
 			throw new EE_Error(
367 367
 				sprintf(
368
-					__( 'Can not cancel %1$d ticket(s) because the supplied line item has a quantity of %2$d.', 'event_espresso' ),
368
+					__('Can not cancel %1$d ticket(s) because the supplied line item has a quantity of %2$d.', 'event_espresso'),
369 369
 					$qty,
370 370
 					$ticket_line_item->quantity()
371 371
 				)
372 372
 			);
373 373
 		}
374 374
 		// decrement ticket quantity; don't rely on auto-fixing when recalculating totals to do this
375
-		$ticket_line_item->set_quantity( $ticket_line_item->quantity() - $qty );
376
-		foreach( $ticket_line_item->children() as $child_line_item ) {
377
-			if(
375
+		$ticket_line_item->set_quantity($ticket_line_item->quantity() - $qty);
376
+		foreach ($ticket_line_item->children() as $child_line_item) {
377
+			if (
378 378
 				$child_line_item->is_sub_line_item()
379 379
 				&& ! $child_line_item->is_percent()
380 380
 				&& ! $child_line_item->is_cancellation()
381 381
 			) {
382
-				$child_line_item->set_quantity( $child_line_item->quantity() - $qty );
382
+				$child_line_item->set_quantity($child_line_item->quantity() - $qty);
383 383
 			}
384 384
 		}
385 385
 		// get cancellation sub line item
@@ -387,31 +387,31 @@  discard block
 block discarded – undo
387 387
 			$ticket_line_item,
388 388
 			EEM_Line_Item::type_cancellation
389 389
 		);
390
-		$cancellation_line_item = reset( $cancellation_line_item );
390
+		$cancellation_line_item = reset($cancellation_line_item);
391 391
 		// verify that this ticket was indeed previously cancelled
392
-		if ( $cancellation_line_item instanceof EE_Line_Item ) {
392
+		if ($cancellation_line_item instanceof EE_Line_Item) {
393 393
 			// increment cancelled quantity
394
-			$cancellation_line_item->set_quantity( $cancellation_line_item->quantity() + $qty );
394
+			$cancellation_line_item->set_quantity($cancellation_line_item->quantity() + $qty);
395 395
 		} else {
396 396
 			// create cancellation sub line item
397
-			$cancellation_line_item = EE_Line_Item::new_instance( array(
398
-				'LIN_name'       => __( 'Cancellation', 'event_espresso' ),
397
+			$cancellation_line_item = EE_Line_Item::new_instance(array(
398
+				'LIN_name'       => __('Cancellation', 'event_espresso'),
399 399
 				'LIN_desc'       => sprintf(
400
-					_x( 'Cancelled %1$s : %2$s', 'Cancelled Ticket Name : 2015-01-01 11:11', 'event_espresso' ),
400
+					_x('Cancelled %1$s : %2$s', 'Cancelled Ticket Name : 2015-01-01 11:11', 'event_espresso'),
401 401
 					$ticket_line_item->name(),
402
-					current_time( get_option( 'date_format' ) . ' ' . get_option( 'time_format' ) )
402
+					current_time(get_option('date_format').' '.get_option('time_format'))
403 403
 				),
404 404
 				'LIN_unit_price' => 0, // $ticket_line_item->unit_price()
405 405
 				'LIN_quantity'   => $qty,
406 406
 				'LIN_is_taxable' => $ticket_line_item->is_taxable(),
407
-				'LIN_order'      => count( $ticket_line_item->children() ),
407
+				'LIN_order'      => count($ticket_line_item->children()),
408 408
 				'LIN_total'      => 0, // $ticket_line_item->unit_price()
409 409
 				'LIN_type'       => EEM_Line_Item::type_cancellation,
410
-			) );
411
-			$ticket_line_item->add_child_line_item( $cancellation_line_item );
410
+			));
411
+			$ticket_line_item->add_child_line_item($cancellation_line_item);
412 412
 		}
413
-		if ( $ticket_line_item->save_this_and_descendants() > 0 ) {
414
-			EEH_Line_Item::get_grand_total_and_recalculate_everything( $ticket_line_item );
413
+		if ($ticket_line_item->save_this_and_descendants() > 0) {
414
+			EEH_Line_Item::get_grand_total_and_recalculate_everything($ticket_line_item);
415 415
 			return true;
416 416
 		}
417 417
 		return false;
@@ -429,12 +429,12 @@  discard block
 block discarded – undo
429 429
 	 * @return bool success
430 430
 	 * @throws \EE_Error
431 431
 	 */
432
-	public static function reinstate_canceled_ticket_line_item( EE_Line_Item $ticket_line_item, $qty = 1 ) {
432
+	public static function reinstate_canceled_ticket_line_item(EE_Line_Item $ticket_line_item, $qty = 1) {
433 433
 		// validate incoming line_item
434
-		if ( $ticket_line_item->OBJ_type() !== 'Ticket' ) {
434
+		if ($ticket_line_item->OBJ_type() !== 'Ticket') {
435 435
 			throw new EE_Error(
436 436
 				sprintf(
437
-					__( 'The supplied line item must have an Object Type of "Ticket", not %1$s.', 'event_espresso' ),
437
+					__('The supplied line item must have an Object Type of "Ticket", not %1$s.', 'event_espresso'),
438 438
 					$ticket_line_item->type()
439 439
 				)
440 440
 			);
@@ -444,37 +444,37 @@  discard block
 block discarded – undo
444 444
 			$ticket_line_item,
445 445
 			EEM_Line_Item::type_cancellation
446 446
 		);
447
-		$cancellation_line_item = reset( $cancellation_line_item );
447
+		$cancellation_line_item = reset($cancellation_line_item);
448 448
 		// verify that this ticket was indeed previously cancelled
449
-		if ( ! $cancellation_line_item instanceof EE_Line_Item ) {
449
+		if ( ! $cancellation_line_item instanceof EE_Line_Item) {
450 450
 			return false;
451 451
 		}
452
-		if ( $cancellation_line_item->quantity() > $qty ) {
452
+		if ($cancellation_line_item->quantity() > $qty) {
453 453
 			// decrement cancelled quantity
454
-			$cancellation_line_item->set_quantity( $cancellation_line_item->quantity() - $qty );
455
-		} else if ( $cancellation_line_item->quantity() == $qty ) {
454
+			$cancellation_line_item->set_quantity($cancellation_line_item->quantity() - $qty);
455
+		} else if ($cancellation_line_item->quantity() == $qty) {
456 456
 			// decrement cancelled quantity in case anyone still has the object kicking around
457
-			$cancellation_line_item->set_quantity( $cancellation_line_item->quantity() - $qty );
457
+			$cancellation_line_item->set_quantity($cancellation_line_item->quantity() - $qty);
458 458
 			// delete because quantity will end up as 0
459 459
 			$cancellation_line_item->delete();
460 460
 			// and attempt to destroy the object,
461 461
 			// even though PHP won't actually destroy it until it needs the memory
462
-			unset( $cancellation_line_item );
462
+			unset($cancellation_line_item);
463 463
 		} else {
464 464
 			// what ?!?! negative quantity ?!?!
465 465
 			throw new EE_Error(
466 466
 				sprintf(
467
-					__( 'Can not reinstate %1$d cancelled ticket(s) because the cancelled ticket quantity is only %2$d.',
468
-						'event_espresso' ),
467
+					__('Can not reinstate %1$d cancelled ticket(s) because the cancelled ticket quantity is only %2$d.',
468
+						'event_espresso'),
469 469
 					$qty,
470 470
 					$cancellation_line_item->quantity()
471 471
 				)
472 472
 			);
473 473
 		}
474 474
 		// increment ticket quantity
475
-		$ticket_line_item->set_quantity( $ticket_line_item->quantity() + $qty );
476
-		if ( $ticket_line_item->save_this_and_descendants() > 0 ) {
477
-			EEH_Line_Item::get_grand_total_and_recalculate_everything( $ticket_line_item );
475
+		$ticket_line_item->set_quantity($ticket_line_item->quantity() + $qty);
476
+		if ($ticket_line_item->save_this_and_descendants() > 0) {
477
+			EEH_Line_Item::get_grand_total_and_recalculate_everything($ticket_line_item);
478 478
 			return true;
479 479
 		}
480 480
 		return false;
@@ -489,8 +489,8 @@  discard block
 block discarded – undo
489 489
 	 * @param EE_Line_Item $line_item
490 490
 	 * @return \EE_Line_Item
491 491
 	 */
492
-	public static function get_grand_total_and_recalculate_everything( EE_Line_Item $line_item ){
493
-		$grand_total_line_item = EEH_Line_Item::find_transaction_grand_total_for_line_item( $line_item );
492
+	public static function get_grand_total_and_recalculate_everything(EE_Line_Item $line_item) {
493
+		$grand_total_line_item = EEH_Line_Item::find_transaction_grand_total_for_line_item($line_item);
494 494
 		return $grand_total_line_item->recalculate_total_including_taxes();
495 495
 	}
496 496
 
@@ -503,11 +503,11 @@  discard block
 block discarded – undo
503 503
 	 * @return \EE_Line_Item
504 504
 	 * @throws \EE_Error
505 505
 	 */
506
-	public static function get_pre_tax_subtotal( EE_Line_Item $total_line_item ){
507
-		$pre_tax_subtotal = $total_line_item->get_child_line_item( 'pre-tax-subtotal' );
506
+	public static function get_pre_tax_subtotal(EE_Line_Item $total_line_item) {
507
+		$pre_tax_subtotal = $total_line_item->get_child_line_item('pre-tax-subtotal');
508 508
 		return $pre_tax_subtotal instanceof EE_Line_Item
509 509
 			? $pre_tax_subtotal
510
-			: self::create_pre_tax_subtotal( $total_line_item );
510
+			: self::create_pre_tax_subtotal($total_line_item);
511 511
 	}
512 512
 
513 513
 
@@ -519,9 +519,9 @@  discard block
 block discarded – undo
519 519
 	 * @return \EE_Line_Item
520 520
 	 * @throws \EE_Error
521 521
 	 */
522
-	public static function get_taxes_subtotal( EE_Line_Item $total_line_item ){
523
-		$taxes = $total_line_item->get_child_line_item( 'taxes' );
524
-		return $taxes ? $taxes : self::create_taxes_subtotal( $total_line_item );
522
+	public static function get_taxes_subtotal(EE_Line_Item $total_line_item) {
523
+		$taxes = $total_line_item->get_child_line_item('taxes');
524
+		return $taxes ? $taxes : self::create_taxes_subtotal($total_line_item);
525 525
 	}
526 526
 
527 527
 
@@ -534,12 +534,12 @@  discard block
 block discarded – undo
534 534
 	 * @return void
535 535
 	 * @throws \EE_Error
536 536
 	 */
537
-	public static function set_TXN_ID( EE_Line_Item $line_item, $transaction = NULL ){
538
-		if( $transaction ){
537
+	public static function set_TXN_ID(EE_Line_Item $line_item, $transaction = NULL) {
538
+		if ($transaction) {
539 539
 			/** @type EEM_Transaction $EEM_Transaction */
540
-			$EEM_Transaction = EE_Registry::instance()->load_model( 'Transaction' );
541
-			$TXN_ID = $EEM_Transaction->ensure_is_ID( $transaction );
542
-			$line_item->set_TXN_ID( $TXN_ID );
540
+			$EEM_Transaction = EE_Registry::instance()->load_model('Transaction');
541
+			$TXN_ID = $EEM_Transaction->ensure_is_ID($transaction);
542
+			$line_item->set_TXN_ID($TXN_ID);
543 543
 		}
544 544
 	}
545 545
 
@@ -554,8 +554,8 @@  discard block
 block discarded – undo
554 554
 	 * @return \EE_Line_Item of type total
555 555
 	 * @throws \EE_Error
556 556
 	 */
557
-	public static function create_total_line_item( $transaction = NULL ){
558
-		$total_line_item = EE_Line_Item::new_instance( array(
557
+	public static function create_total_line_item($transaction = NULL) {
558
+		$total_line_item = EE_Line_Item::new_instance(array(
559 559
 			'LIN_code'	=> 'total',
560 560
 			'LIN_name'	=> __('Grand Total', 'event_espresso'),
561 561
 			'LIN_type'	=> EEM_Line_Item::type_total,
@@ -565,9 +565,9 @@  discard block
 block discarded – undo
565 565
 			'FHEE__EEH_Line_Item__create_total_line_item__total_line_item',
566 566
 			$total_line_item
567 567
 		);
568
-		self::set_TXN_ID( $total_line_item, $transaction );
569
-		self::create_pre_tax_subtotal( $total_line_item, $transaction );
570
-		self::create_taxes_subtotal( $total_line_item, $transaction );
568
+		self::set_TXN_ID($total_line_item, $transaction);
569
+		self::create_pre_tax_subtotal($total_line_item, $transaction);
570
+		self::create_taxes_subtotal($total_line_item, $transaction);
571 571
 		return $total_line_item;
572 572
 	}
573 573
 
@@ -581,19 +581,19 @@  discard block
 block discarded – undo
581 581
 	 * @return EE_Line_Item
582 582
 	 * @throws \EE_Error
583 583
 	 */
584
-	protected static function create_pre_tax_subtotal( EE_Line_Item $total_line_item, $transaction = NULL ){
585
-		$pre_tax_line_item = EE_Line_Item::new_instance( array(
584
+	protected static function create_pre_tax_subtotal(EE_Line_Item $total_line_item, $transaction = NULL) {
585
+		$pre_tax_line_item = EE_Line_Item::new_instance(array(
586 586
 			'LIN_code' 	=> 'pre-tax-subtotal',
587
-			'LIN_name' 	=> __( 'Pre-Tax Subtotal', 'event_espresso' ),
587
+			'LIN_name' 	=> __('Pre-Tax Subtotal', 'event_espresso'),
588 588
 			'LIN_type' 	=> EEM_Line_Item::type_sub_total
589
-		) );
589
+		));
590 590
 		$pre_tax_line_item = apply_filters(
591 591
 			'FHEE__EEH_Line_Item__create_pre_tax_subtotal__pre_tax_line_item',
592 592
 			$pre_tax_line_item
593 593
 		);
594
-		self::set_TXN_ID( $pre_tax_line_item, $transaction );
595
-		$total_line_item->add_child_line_item( $pre_tax_line_item );
596
-		self::create_event_subtotal( $pre_tax_line_item, $transaction );
594
+		self::set_TXN_ID($pre_tax_line_item, $transaction);
595
+		$total_line_item->add_child_line_item($pre_tax_line_item);
596
+		self::create_event_subtotal($pre_tax_line_item, $transaction);
597 597
 		return $pre_tax_line_item;
598 598
 	}
599 599
 
@@ -608,21 +608,21 @@  discard block
 block discarded – undo
608 608
 	 * @return EE_Line_Item
609 609
 	 * @throws \EE_Error
610 610
 	 */
611
-	protected static function create_taxes_subtotal( EE_Line_Item $total_line_item, $transaction = NULL ){
611
+	protected static function create_taxes_subtotal(EE_Line_Item $total_line_item, $transaction = NULL) {
612 612
 		$tax_line_item = EE_Line_Item::new_instance(array(
613 613
 			'LIN_code'	=> 'taxes',
614 614
 			'LIN_name' 	=> __('Taxes', 'event_espresso'),
615 615
 			'LIN_type'	=> EEM_Line_Item::type_tax_sub_total,
616
-			'LIN_order' => 1000,//this should always come last
616
+			'LIN_order' => 1000, //this should always come last
617 617
 		));
618 618
 		$tax_line_item = apply_filters(
619 619
 			'FHEE__EEH_Line_Item__create_taxes_subtotal__tax_line_item',
620 620
 			$tax_line_item
621 621
 		);
622
-		self::set_TXN_ID( $tax_line_item, $transaction );
623
-		$total_line_item->add_child_line_item( $tax_line_item );
622
+		self::set_TXN_ID($tax_line_item, $transaction);
623
+		$total_line_item->add_child_line_item($tax_line_item);
624 624
 		//and lastly, add the actual taxes
625
-		self::apply_taxes( $total_line_item );
625
+		self::apply_taxes($total_line_item);
626 626
 		return $tax_line_item;
627 627
 	}
628 628
 
@@ -637,11 +637,11 @@  discard block
 block discarded – undo
637 637
 	 * @return EE_Line_Item
638 638
 	 * @throws \EE_Error
639 639
 	 */
640
-	public static function create_event_subtotal( EE_Line_Item $pre_tax_line_item, $transaction = NULL, $event = NULL ){
640
+	public static function create_event_subtotal(EE_Line_Item $pre_tax_line_item, $transaction = NULL, $event = NULL) {
641 641
 		$event_line_item = EE_Line_Item::new_instance(array(
642
-			'LIN_code'	=> self::get_event_code( $event ),
643
-			'LIN_name' 	=> self::get_event_name( $event ),
644
-			'LIN_desc' 	=> self::get_event_desc( $event ),
642
+			'LIN_code'	=> self::get_event_code($event),
643
+			'LIN_name' 	=> self::get_event_name($event),
644
+			'LIN_desc' 	=> self::get_event_desc($event),
645 645
 			'LIN_type'	=> EEM_Line_Item::type_sub_total,
646 646
 			'OBJ_type' 	=> 'Event',
647 647
 			'OBJ_ID' 		=>  $event instanceof EE_Event ? $event->ID() : 0
@@ -650,8 +650,8 @@  discard block
 block discarded – undo
650 650
 			'FHEE__EEH_Line_Item__create_event_subtotal__event_line_item',
651 651
 			$event_line_item
652 652
 		);
653
-		self::set_TXN_ID( $event_line_item, $transaction );
654
-		$pre_tax_line_item->add_child_line_item( $event_line_item );
653
+		self::set_TXN_ID($event_line_item, $transaction);
654
+		$pre_tax_line_item->add_child_line_item($event_line_item);
655 655
 		return $event_line_item;
656 656
 	}
657 657
 
@@ -664,8 +664,8 @@  discard block
 block discarded – undo
664 664
 	 * @return string
665 665
 	 * @throws \EE_Error
666 666
 	 */
667
-	public static function get_event_code( $event ) {
668
-		return 'event-' . ( $event instanceof EE_Event ? $event->ID() : '0' );
667
+	public static function get_event_code($event) {
668
+		return 'event-'.($event instanceof EE_Event ? $event->ID() : '0');
669 669
 	}
670 670
 
671 671
 	/**
@@ -673,8 +673,8 @@  discard block
 block discarded – undo
673 673
 	 * @param EE_Event $event
674 674
 	 * @return string
675 675
 	 */
676
-	public static function get_event_name( $event ) {
677
-		return $event instanceof EE_Event ? $event->name() : __( 'Event', 'event_espresso' );
676
+	public static function get_event_name($event) {
677
+		return $event instanceof EE_Event ? $event->name() : __('Event', 'event_espresso');
678 678
 	}
679 679
 
680 680
 	/**
@@ -682,7 +682,7 @@  discard block
 block discarded – undo
682 682
 	 * @param EE_Event $event
683 683
 	 * @return string
684 684
 	 */
685
-	public static function get_event_desc( $event ) {
685
+	public static function get_event_desc($event) {
686 686
 		return $event instanceof EE_Event ? $event->short_description() : '';
687 687
 	}
688 688
 
@@ -696,27 +696,27 @@  discard block
 block discarded – undo
696 696
 	  * @throws \EE_Error
697 697
 	  * @return EE_Line_Item
698 698
 	  */
699
-	public static function get_event_line_item_for_ticket( EE_Line_Item $grand_total, EE_Ticket $ticket ) {
699
+	public static function get_event_line_item_for_ticket(EE_Line_Item $grand_total, EE_Ticket $ticket) {
700 700
 		$first_datetime = $ticket->first_datetime();
701
-		if ( ! $first_datetime instanceof EE_Datetime ) {
701
+		if ( ! $first_datetime instanceof EE_Datetime) {
702 702
 			throw new EE_Error(
703
-				sprintf( __( 'The supplied ticket (ID %d) has no datetimes', 'event_espresso' ), $ticket->ID() )
703
+				sprintf(__('The supplied ticket (ID %d) has no datetimes', 'event_espresso'), $ticket->ID())
704 704
 			);
705 705
 		}
706 706
 		$event = $first_datetime->event();
707
-		if ( ! $event instanceof EE_Event ) {
707
+		if ( ! $event instanceof EE_Event) {
708 708
 			throw new EE_Error(
709 709
 				sprintf(
710
-					__( 'The supplied ticket (ID %d) has no event data associated with it.', 'event_espresso' ),
710
+					__('The supplied ticket (ID %d) has no event data associated with it.', 'event_espresso'),
711 711
 					$ticket->ID()
712 712
 				)
713 713
 			);
714 714
 		}
715
-		$events_sub_total = EEH_Line_Item::get_event_line_item( $grand_total, $event );
716
-		if ( ! $events_sub_total instanceof EE_Line_Item ) {
715
+		$events_sub_total = EEH_Line_Item::get_event_line_item($grand_total, $event);
716
+		if ( ! $events_sub_total instanceof EE_Line_Item) {
717 717
 			throw new EE_Error(
718 718
 				sprintf(
719
-					__( 'There is no events sub-total for ticket %s on total line item %d', 'event_espresso' ),
719
+					__('There is no events sub-total for ticket %s on total line item %d', 'event_espresso'),
720 720
 					$ticket->ID(),
721 721
 					$grand_total->ID()
722 722
 				)
@@ -735,31 +735,31 @@  discard block
 block discarded – undo
735 735
 	 * @return EE_Line_Item for the event subtotal which is a child of $grand_total
736 736
 	 * @throws \EE_Error
737 737
 	 */
738
-	public static function get_event_line_item( EE_Line_Item $grand_total, $event ) {
738
+	public static function get_event_line_item(EE_Line_Item $grand_total, $event) {
739 739
 		/** @type EE_Event $event */
740
-		$event = EEM_Event::instance()->ensure_is_obj( $event, true );
740
+		$event = EEM_Event::instance()->ensure_is_obj($event, true);
741 741
 		$event_line_item = NULL;
742 742
 		$found = false;
743
-		foreach ( EEH_Line_Item::get_event_subtotals( $grand_total ) as $event_line_item ) {
743
+		foreach (EEH_Line_Item::get_event_subtotals($grand_total) as $event_line_item) {
744 744
 			// default event subtotal, we should only ever find this the first time this method is called
745
-			if ( ! $event_line_item->OBJ_ID() ) {
745
+			if ( ! $event_line_item->OBJ_ID()) {
746 746
 				// let's use this! but first... set the event details
747
-				EEH_Line_Item::set_event_subtotal_details( $event_line_item, $event );
747
+				EEH_Line_Item::set_event_subtotal_details($event_line_item, $event);
748 748
 				$found = true;
749 749
 				break;
750
-			} else if ( $event_line_item->OBJ_ID() === $event->ID() ) {
750
+			} else if ($event_line_item->OBJ_ID() === $event->ID()) {
751 751
 				// found existing line item for this event in the cart, so break out of loop and use this one
752 752
 				$found = true;
753 753
 				break;
754 754
 			}
755 755
 		}
756
-		if ( ! $found ) {
756
+		if ( ! $found) {
757 757
 			//there is no event sub-total yet, so add it
758
-			$pre_tax_subtotal = EEH_Line_Item::get_pre_tax_subtotal( $grand_total );
758
+			$pre_tax_subtotal = EEH_Line_Item::get_pre_tax_subtotal($grand_total);
759 759
 			// create a new "event" subtotal below that
760
-			$event_line_item = EEH_Line_Item::create_event_subtotal( $pre_tax_subtotal, null, $event );
760
+			$event_line_item = EEH_Line_Item::create_event_subtotal($pre_tax_subtotal, null, $event);
761 761
 			// and set the event details
762
-			EEH_Line_Item::set_event_subtotal_details( $event_line_item, $event );
762
+			EEH_Line_Item::set_event_subtotal_details($event_line_item, $event);
763 763
 		}
764 764
 		return $event_line_item;
765 765
 	}
@@ -780,13 +780,13 @@  discard block
 block discarded – undo
780 780
 		EE_Event $event,
781 781
 		$transaction = null
782 782
 	) {
783
-		if ( $event instanceof EE_Event ) {
784
-			$event_line_item->set_code( self::get_event_code( $event ) );
785
-			$event_line_item->set_name( self::get_event_name( $event ) );
786
-			$event_line_item->set_desc( self::get_event_desc( $event ) );
787
-			$event_line_item->set_OBJ_ID( $event->ID() );
783
+		if ($event instanceof EE_Event) {
784
+			$event_line_item->set_code(self::get_event_code($event));
785
+			$event_line_item->set_name(self::get_event_name($event));
786
+			$event_line_item->set_desc(self::get_event_desc($event));
787
+			$event_line_item->set_OBJ_ID($event->ID());
788 788
 		}
789
-		self::set_TXN_ID( $event_line_item, $transaction );
789
+		self::set_TXN_ID($event_line_item, $transaction);
790 790
 	}
791 791
 
792 792
 
@@ -799,19 +799,19 @@  discard block
 block discarded – undo
799 799
 	 * @param EE_Line_Item $total_line_item of type EEM_Line_Item::type_total
800 800
 	 * @throws \EE_Error
801 801
 	 */
802
-	public static function apply_taxes( EE_Line_Item $total_line_item ){
802
+	public static function apply_taxes(EE_Line_Item $total_line_item) {
803 803
 		/** @type EEM_Price $EEM_Price */
804
-		$EEM_Price = EE_Registry::instance()->load_model( 'Price' );
804
+		$EEM_Price = EE_Registry::instance()->load_model('Price');
805 805
 		// get array of taxes via Price Model
806 806
 		$ordered_taxes = $EEM_Price->get_all_prices_that_are_taxes();
807
-		ksort( $ordered_taxes );
808
-		$taxes_line_item = self::get_taxes_subtotal( $total_line_item );
807
+		ksort($ordered_taxes);
808
+		$taxes_line_item = self::get_taxes_subtotal($total_line_item);
809 809
 		//just to be safe, remove its old tax line items
810 810
 		$taxes_line_item->delete_children_line_items();
811 811
 		//loop thru taxes
812
-		foreach ( $ordered_taxes as $order => $taxes ) {
813
-			foreach ( $taxes as $tax ) {
814
-				if ( $tax instanceof EE_Price ) {
812
+		foreach ($ordered_taxes as $order => $taxes) {
813
+			foreach ($taxes as $tax) {
814
+				if ($tax instanceof EE_Price) {
815 815
 					$tax_line_item = EE_Line_Item::new_instance(
816 816
 						array(
817 817
 							'LIN_name'       => $tax->name(),
@@ -829,7 +829,7 @@  discard block
 block discarded – undo
829 829
 						'FHEE__EEH_Line_Item__apply_taxes__tax_line_item',
830 830
 						$tax_line_item
831 831
 					);
832
-					$taxes_line_item->add_child_line_item( $tax_line_item );
832
+					$taxes_line_item->add_child_line_item($tax_line_item);
833 833
 				}
834 834
 			}
835 835
 		}
@@ -846,10 +846,10 @@  discard block
 block discarded – undo
846 846
 	 * @return float
847 847
 	 * @throws \EE_Error
848 848
 	 */
849
-	public static function ensure_taxes_applied( $total_line_item ){
850
-		$taxes_subtotal = self::get_taxes_subtotal( $total_line_item );
851
-		if( ! $taxes_subtotal->children()){
852
-			self::apply_taxes( $total_line_item );
849
+	public static function ensure_taxes_applied($total_line_item) {
850
+		$taxes_subtotal = self::get_taxes_subtotal($total_line_item);
851
+		if ( ! $taxes_subtotal->children()) {
852
+			self::apply_taxes($total_line_item);
853 853
 		}
854 854
 		return $taxes_subtotal->total();
855 855
 	}
@@ -863,16 +863,16 @@  discard block
 block discarded – undo
863 863
 	 * @return bool
864 864
 	 * @throws \EE_Error
865 865
 	 */
866
-	public static function delete_all_child_items( EE_Line_Item $parent_line_item ) {
866
+	public static function delete_all_child_items(EE_Line_Item $parent_line_item) {
867 867
 		$deleted = 0;
868
-		foreach ( $parent_line_item->children() as $child_line_item ) {
869
-			if ( $child_line_item instanceof EE_Line_Item ) {
870
-				$deleted += EEH_Line_Item::delete_all_child_items( $child_line_item );
871
-				if ( $child_line_item->ID() ) {
868
+		foreach ($parent_line_item->children() as $child_line_item) {
869
+			if ($child_line_item instanceof EE_Line_Item) {
870
+				$deleted += EEH_Line_Item::delete_all_child_items($child_line_item);
871
+				if ($child_line_item->ID()) {
872 872
 					$child_line_item->delete();
873
-					unset( $child_line_item );
873
+					unset($child_line_item);
874 874
 				} else {
875
-					$parent_line_item->delete_child_line_item( $child_line_item->code() );
875
+					$parent_line_item->delete_child_line_item($child_line_item->code());
876 876
 				}
877 877
 				$deleted++;
878 878
 			}
@@ -894,9 +894,9 @@  discard block
 block discarded – undo
894 894
 	 * @param array|bool|string $line_item_codes
895 895
 	 * @return int number of items successfully removed
896 896
 	 */
897
-	public static function delete_items( EE_Line_Item $total_line_item, $line_item_codes = FALSE ) {
897
+	public static function delete_items(EE_Line_Item $total_line_item, $line_item_codes = FALSE) {
898 898
 
899
-		if( $total_line_item->type() !== EEM_Line_Item::type_total ){
899
+		if ($total_line_item->type() !== EEM_Line_Item::type_total) {
900 900
 			EE_Error::doing_it_wrong(
901 901
 				'EEH_Line_Item::delete_items',
902 902
 				__(
@@ -906,20 +906,20 @@  discard block
 block discarded – undo
906 906
 				'4.6.18'
907 907
 			);
908 908
 		}
909
-		do_action( 'AHEE_log', __FILE__, __FUNCTION__, '' );
909
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
910 910
 
911 911
 		// check if only a single line_item_id was passed
912
-		if ( ! empty( $line_item_codes ) && ! is_array( $line_item_codes )) {
912
+		if ( ! empty($line_item_codes) && ! is_array($line_item_codes)) {
913 913
 			// place single line_item_id in an array to appear as multiple line_item_ids
914
-			$line_item_codes = array ( $line_item_codes );
914
+			$line_item_codes = array($line_item_codes);
915 915
 		}
916 916
 		$removals = 0;
917 917
 		// cycle thru line_item_ids
918
-		foreach ( $line_item_codes as $line_item_id ) {
918
+		foreach ($line_item_codes as $line_item_id) {
919 919
 			$removals += $total_line_item->delete_child_line_item($line_item_id);
920 920
 		}
921 921
 
922
-		if ( $removals > 0 ) {
922
+		if ($removals > 0) {
923 923
 			$total_line_item->recalculate_taxes_and_tax_total();
924 924
 			return $removals;
925 925
 		} else {
@@ -952,33 +952,33 @@  discard block
 block discarded – undo
952 952
 		$code = null,
953 953
 		$add_to_existing_line_item = false
954 954
 	) {
955
-		$tax_subtotal = self::get_taxes_subtotal( $total_line_item );
955
+		$tax_subtotal = self::get_taxes_subtotal($total_line_item);
956 956
             $taxable_total = $total_line_item->taxable_total();
957 957
 
958
-            if( $add_to_existing_line_item ) {
959
-                $new_tax = $tax_subtotal->get_child_line_item( $code );
958
+            if ($add_to_existing_line_item) {
959
+                $new_tax = $tax_subtotal->get_child_line_item($code);
960 960
 	            EEM_Line_Item::instance()->delete(
961
-		            array( array( 'LIN_code' => array( '!=', $code ), 'LIN_parent' => $tax_subtotal->ID() ) )
961
+		            array(array('LIN_code' => array('!=', $code), 'LIN_parent' => $tax_subtotal->ID()))
962 962
 	            );
963 963
             } else {
964 964
                 $new_tax = null;
965 965
                 $tax_subtotal->delete_children_line_items();
966 966
             }
967
-            if( $new_tax ) {
968
-                $new_tax->set_total( $new_tax->total() + $amount );
969
-                $new_tax->set_percent( $taxable_total ? $new_tax->total() / $taxable_total * 100 : 0 );
967
+            if ($new_tax) {
968
+                $new_tax->set_total($new_tax->total() + $amount);
969
+                $new_tax->set_percent($taxable_total ? $new_tax->total() / $taxable_total * 100 : 0);
970 970
             } else {
971 971
                 //no existing tax item. Create it
972
-				$new_tax = EE_Line_Item::new_instance( array(
972
+				$new_tax = EE_Line_Item::new_instance(array(
973 973
 					'TXN_ID'      => $total_line_item->TXN_ID(),
974
-					'LIN_name'    => $name ? $name : __( 'Tax', 'event_espresso' ),
974
+					'LIN_name'    => $name ? $name : __('Tax', 'event_espresso'),
975 975
 					'LIN_desc'    => $description ? $description : '',
976
-					'LIN_percent' => $taxable_total ? ( $amount / $taxable_total * 100 ) : 0,
976
+					'LIN_percent' => $taxable_total ? ($amount / $taxable_total * 100) : 0,
977 977
 					'LIN_total'   => $amount,
978 978
 					'LIN_parent'  => $tax_subtotal->ID(),
979 979
 					'LIN_type'    => EEM_Line_Item::type_tax,
980 980
 					'LIN_code'    => $code
981
-				) );
981
+				));
982 982
 			}
983 983
 
984 984
             $new_tax = apply_filters(
@@ -987,7 +987,7 @@  discard block
 block discarded – undo
987 987
 				$total_line_item
988 988
             );
989 989
             $new_tax->save();
990
-            $tax_subtotal->set_total( $new_tax->total() );
990
+            $tax_subtotal->set_total($new_tax->total());
991 991
             $tax_subtotal->save();
992 992
             $total_line_item->recalculate_total_including_taxes();
993 993
             return $new_tax;
@@ -1009,14 +1009,14 @@  discard block
 block discarded – undo
1009 1009
 		$code_substring_for_whitelist = null
1010 1010
 	) {
1011 1011
 		$whitelisted = false;
1012
-		if( $code_substring_for_whitelist !== null ) {
1013
-			$whitelisted = strpos( $line_item->code(), $code_substring_for_whitelist ) !== false ? true : false;
1012
+		if ($code_substring_for_whitelist !== null) {
1013
+			$whitelisted = strpos($line_item->code(), $code_substring_for_whitelist) !== false ? true : false;
1014 1014
 		}
1015
-		if( ! $whitelisted && $line_item->is_line_item() ) {
1016
-			$line_item->set_is_taxable( $taxable );
1015
+		if ( ! $whitelisted && $line_item->is_line_item()) {
1016
+			$line_item->set_is_taxable($taxable);
1017 1017
 		}
1018
-		foreach( $line_item->children() as $child_line_item ) {
1019
-			EEH_Line_Item::set_line_items_taxable( $child_line_item, $taxable, $code_substring_for_whitelist );
1018
+		foreach ($line_item->children() as $child_line_item) {
1019
+			EEH_Line_Item::set_line_items_taxable($child_line_item, $taxable, $code_substring_for_whitelist);
1020 1020
 		}
1021 1021
 	}
1022 1022
 
@@ -1029,8 +1029,8 @@  discard block
 block discarded – undo
1029 1029
 	 * @param \EE_Line_Item $parent_line_item - the line item to find descendants of
1030 1030
 	 * @return EE_Line_Item[]
1031 1031
 	 */
1032
-	public static function get_event_subtotals( EE_Line_Item $parent_line_item ) {
1033
-		return self::get_subtotals_of_object_type( $parent_line_item, 'Event' );
1032
+	public static function get_event_subtotals(EE_Line_Item $parent_line_item) {
1033
+		return self::get_subtotals_of_object_type($parent_line_item, 'Event');
1034 1034
 	}
1035 1035
 
1036 1036
 
@@ -1043,7 +1043,7 @@  discard block
 block discarded – undo
1043 1043
 	 * @param string $obj_type
1044 1044
 	 * @return EE_Line_Item[]
1045 1045
 	 */
1046
-	public static function get_subtotals_of_object_type( EE_Line_Item $parent_line_item, $obj_type = '' ) {
1046
+	public static function get_subtotals_of_object_type(EE_Line_Item $parent_line_item, $obj_type = '') {
1047 1047
 		return self::_get_descendants_by_type_and_object_type(
1048 1048
 			$parent_line_item,
1049 1049
 			EEM_Line_Item::type_sub_total,
@@ -1060,8 +1060,8 @@  discard block
 block discarded – undo
1060 1060
 	 * @param \EE_Line_Item $parent_line_item - the line item to find descendants of
1061 1061
 	 * @return EE_Line_Item[]
1062 1062
 	 */
1063
-	public static function get_ticket_line_items( EE_Line_Item $parent_line_item ) {
1064
-		return self::get_line_items_of_object_type( $parent_line_item, 'Ticket' );
1063
+	public static function get_ticket_line_items(EE_Line_Item $parent_line_item) {
1064
+		return self::get_line_items_of_object_type($parent_line_item, 'Ticket');
1065 1065
 	}
1066 1066
 
1067 1067
 
@@ -1074,8 +1074,8 @@  discard block
 block discarded – undo
1074 1074
 	 * @param string $obj_type
1075 1075
 	 * @return EE_Line_Item[]
1076 1076
 	 */
1077
-	public static function get_line_items_of_object_type( EE_Line_Item $parent_line_item, $obj_type = '' ) {
1078
-		return self::_get_descendants_by_type_and_object_type( $parent_line_item, EEM_Line_Item::type_line_item, $obj_type );
1077
+	public static function get_line_items_of_object_type(EE_Line_Item $parent_line_item, $obj_type = '') {
1078
+		return self::_get_descendants_by_type_and_object_type($parent_line_item, EEM_Line_Item::type_line_item, $obj_type);
1079 1079
 	}
1080 1080
 
1081 1081
 
@@ -1086,8 +1086,8 @@  discard block
 block discarded – undo
1086 1086
 	 * @param \EE_Line_Item $parent_line_item - the line item to find descendants of
1087 1087
 	 * @return EE_Line_Item[]
1088 1088
 	 */
1089
-	public static function get_tax_descendants( EE_Line_Item $parent_line_item ) {
1090
-		return EEH_Line_Item::get_descendants_of_type( $parent_line_item, EEM_Line_Item::type_tax );
1089
+	public static function get_tax_descendants(EE_Line_Item $parent_line_item) {
1090
+		return EEH_Line_Item::get_descendants_of_type($parent_line_item, EEM_Line_Item::type_tax);
1091 1091
 	}
1092 1092
 
1093 1093
 
@@ -1098,8 +1098,8 @@  discard block
 block discarded – undo
1098 1098
 	 * @param \EE_Line_Item $parent_line_item - the line item to find descendants of
1099 1099
 	 * @return EE_Line_Item[]
1100 1100
 	 */
1101
-	public static function get_line_item_descendants( EE_Line_Item $parent_line_item ) {
1102
-		return EEH_Line_Item::get_descendants_of_type( $parent_line_item, EEM_Line_Item::type_line_item );
1101
+	public static function get_line_item_descendants(EE_Line_Item $parent_line_item) {
1102
+		return EEH_Line_Item::get_descendants_of_type($parent_line_item, EEM_Line_Item::type_line_item);
1103 1103
 	}
1104 1104
 
1105 1105
 
@@ -1112,8 +1112,8 @@  discard block
 block discarded – undo
1112 1112
 	 * @param string $line_item_type one of the EEM_Line_Item constants
1113 1113
 	 * @return EE_Line_Item[]
1114 1114
 	 */
1115
-	public static function get_descendants_of_type( EE_Line_Item $parent_line_item, $line_item_type ) {
1116
-		return self::_get_descendants_by_type_and_object_type( $parent_line_item, $line_item_type, NULL );
1115
+	public static function get_descendants_of_type(EE_Line_Item $parent_line_item, $line_item_type) {
1116
+		return self::_get_descendants_by_type_and_object_type($parent_line_item, $line_item_type, NULL);
1117 1117
 	}
1118 1118
 
1119 1119
 
@@ -1132,8 +1132,8 @@  discard block
 block discarded – undo
1132 1132
 		$obj_type = null
1133 1133
 	) {
1134 1134
 		$objects = array();
1135
-		foreach ( $parent_line_item->children() as $child_line_item ) {
1136
-			if ( $child_line_item instanceof EE_Line_Item ) {
1135
+		foreach ($parent_line_item->children() as $child_line_item) {
1136
+			if ($child_line_item instanceof EE_Line_Item) {
1137 1137
 				if (
1138 1138
 					$child_line_item->type() === $line_item_type
1139 1139
 				    && (
@@ -1173,7 +1173,7 @@  discard block
 block discarded – undo
1173 1173
 		$OBJ_type = '',
1174 1174
 		$OBJ_IDs = array()
1175 1175
 	) {
1176
-		return self::_get_descendants_by_object_type_and_object_ID( $parent_line_item, $OBJ_type, $OBJ_IDs );
1176
+		return self::_get_descendants_by_object_type_and_object_ID($parent_line_item, $OBJ_type, $OBJ_IDs);
1177 1177
 	}
1178 1178
 
1179 1179
 
@@ -1192,12 +1192,12 @@  discard block
 block discarded – undo
1192 1192
 		$OBJ_IDs
1193 1193
 	) {
1194 1194
 		$objects = array();
1195
-		foreach ( $parent_line_item->children() as $child_line_item ) {
1196
-			if ( $child_line_item instanceof EE_Line_Item ) {
1195
+		foreach ($parent_line_item->children() as $child_line_item) {
1196
+			if ($child_line_item instanceof EE_Line_Item) {
1197 1197
 				if (
1198
-					is_array( $OBJ_IDs )
1198
+					is_array($OBJ_IDs)
1199 1199
 					&& $child_line_item->OBJ_type() === $OBJ_type
1200
-					&& in_array( $child_line_item->OBJ_ID(), $OBJ_IDs )
1200
+					&& in_array($child_line_item->OBJ_ID(), $OBJ_IDs)
1201 1201
 				) {
1202 1202
 					$objects[] = $child_line_item;
1203 1203
 				} else {
@@ -1227,8 +1227,8 @@  discard block
 block discarded – undo
1227 1227
 	 * @param string $type like one of the EEM_Line_Item::type_*
1228 1228
 	 * @return EE_Line_Item
1229 1229
 	 */
1230
-	public static function get_nearest_descendant_of_type( EE_Line_Item $parent_line_item, $type ) {
1231
-		return self::_get_nearest_descendant( $parent_line_item, 'LIN_type' , $type );
1230
+	public static function get_nearest_descendant_of_type(EE_Line_Item $parent_line_item, $type) {
1231
+		return self::_get_nearest_descendant($parent_line_item, 'LIN_type', $type);
1232 1232
 	}
1233 1233
 
1234 1234
 
@@ -1242,8 +1242,8 @@  discard block
 block discarded – undo
1242 1242
 	 * @param string $code any value used for LIN_code
1243 1243
 	 * @return EE_Line_Item
1244 1244
 	 */
1245
-	public static function get_nearest_descendant_having_code( EE_Line_Item $parent_line_item, $code ) {
1246
-		return self::_get_nearest_descendant( $parent_line_item, 'LIN_code' , $code );
1245
+	public static function get_nearest_descendant_having_code(EE_Line_Item $parent_line_item, $code) {
1246
+		return self::_get_nearest_descendant($parent_line_item, 'LIN_code', $code);
1247 1247
 	}
1248 1248
 
1249 1249
 
@@ -1257,15 +1257,15 @@  discard block
 block discarded – undo
1257 1257
 	 * @param string $value any value stored in $search_field
1258 1258
 	 * @return EE_Line_Item
1259 1259
 	 */
1260
-	protected static function _get_nearest_descendant( EE_Line_Item $parent_line_item, $search_field, $value ) {
1261
-		foreach( $parent_line_item->children() as $child ){
1262
-			if ( $child->get( $search_field ) == $value ){
1260
+	protected static function _get_nearest_descendant(EE_Line_Item $parent_line_item, $search_field, $value) {
1261
+		foreach ($parent_line_item->children() as $child) {
1262
+			if ($child->get($search_field) == $value) {
1263 1263
 				return $child;
1264 1264
 			}
1265 1265
 		}
1266
-		foreach( $parent_line_item->children() as $child ){
1267
-			$descendant_found = self::_get_nearest_descendant( $child, $search_field, $value );
1268
-			if ( $descendant_found ){
1266
+		foreach ($parent_line_item->children() as $child) {
1267
+			$descendant_found = self::_get_nearest_descendant($child, $search_field, $value);
1268
+			if ($descendant_found) {
1269 1269
 				return $descendant_found;
1270 1270
 			}
1271 1271
 		}
@@ -1282,24 +1282,24 @@  discard block
 block discarded – undo
1282 1282
 	 * @return \EE_Line_Item
1283 1283
 	 * @throws \EE_Error
1284 1284
 	 */
1285
-	public static function find_transaction_grand_total_for_line_item( EE_Line_Item $line_item ){
1286
-		if ( $line_item->TXN_ID() ) {
1287
-			$total_line_item = $line_item->transaction()->total_line_item( false );
1288
-			if ( $total_line_item instanceof EE_Line_Item ) {
1285
+	public static function find_transaction_grand_total_for_line_item(EE_Line_Item $line_item) {
1286
+		if ($line_item->TXN_ID()) {
1287
+			$total_line_item = $line_item->transaction()->total_line_item(false);
1288
+			if ($total_line_item instanceof EE_Line_Item) {
1289 1289
 				return $total_line_item;
1290 1290
 			}
1291 1291
 		} else {
1292 1292
 			$line_item_parent = $line_item->parent();
1293
-			if ( $line_item_parent instanceof EE_Line_Item ) {
1294
-				if ( $line_item_parent->is_total() ) {
1293
+			if ($line_item_parent instanceof EE_Line_Item) {
1294
+				if ($line_item_parent->is_total()) {
1295 1295
 					return $line_item_parent;
1296 1296
 				}
1297
-				return EEH_Line_Item::find_transaction_grand_total_for_line_item( $line_item_parent );
1297
+				return EEH_Line_Item::find_transaction_grand_total_for_line_item($line_item_parent);
1298 1298
 			}
1299 1299
 		}
1300 1300
 		throw new EE_Error(
1301 1301
 			sprintf(
1302
-				__( 'A valid grand total for line item %1$d was not found.', 'event_espresso' ),
1302
+				__('A valid grand total for line item %1$d was not found.', 'event_espresso'),
1303 1303
 				$line_item->ID()
1304 1304
 			)
1305 1305
 		);
@@ -1316,31 +1316,31 @@  discard block
 block discarded – undo
1316 1316
 	 * @return void
1317 1317
 	 * @throws \EE_Error
1318 1318
 	 */
1319
-	public static function visualize( EE_Line_Item $line_item, $indentation = 0 ){
1319
+	public static function visualize(EE_Line_Item $line_item, $indentation = 0) {
1320 1320
 		echo defined('EE_TESTS_DIR') ? "\n" : '<br />';
1321
-		if ( ! $indentation ) {
1322
-			echo defined( 'EE_TESTS_DIR' ) ? "\n" : '<br />';
1321
+		if ( ! $indentation) {
1322
+			echo defined('EE_TESTS_DIR') ? "\n" : '<br />';
1323 1323
 		}
1324
-		for( $i = 0; $i < $indentation; $i++ ){
1324
+		for ($i = 0; $i < $indentation; $i++) {
1325 1325
 			echo ". ";
1326 1326
 		}
1327 1327
 		$breakdown = '';
1328
-		if ( $line_item->is_line_item()){
1329
-			if ( $line_item->is_percent() ) {
1328
+		if ($line_item->is_line_item()) {
1329
+			if ($line_item->is_percent()) {
1330 1330
 				$breakdown = "{$line_item->percent()}%";
1331 1331
 			} else {
1332
-				$breakdown = '$' . "{$line_item->unit_price()} x {$line_item->quantity()}";
1332
+				$breakdown = '$'."{$line_item->unit_price()} x {$line_item->quantity()}";
1333 1333
 			}
1334 1334
 		}
1335
-		echo $line_item->name() . " ( ID:{$line_item->ID()} ) : {$line_item->type()} " . '$' . "{$line_item->total()}";
1336
-		if ( $breakdown ) {
1335
+		echo $line_item->name()." ( ID:{$line_item->ID()} ) : {$line_item->type()} ".'$'."{$line_item->total()}";
1336
+		if ($breakdown) {
1337 1337
 			echo " ( {$breakdown} )";
1338 1338
 		}
1339
-		if( $line_item->is_taxable() ){
1339
+		if ($line_item->is_taxable()) {
1340 1340
 			echo "  * taxable";
1341 1341
 		}
1342
-		if( $line_item->children() ){
1343
-			foreach($line_item->children() as $child){
1342
+		if ($line_item->children()) {
1343
+			foreach ($line_item->children() as $child) {
1344 1344
 				self::visualize($child, $indentation + 1);
1345 1345
 			}
1346 1346
 		}
@@ -1381,97 +1381,97 @@  discard block
 block discarded – undo
1381 1381
 	 *                                          is theirs, which can be done with
1382 1382
 	 *                                          `EEM_Line_Item::instance()->get_line_item_for_registration( $registration );`
1383 1383
 	 */
1384
-	public static function calculate_reg_final_prices_per_line_item( EE_Line_Item $line_item, $billable_ticket_quantities = array() ) {
1384
+	public static function calculate_reg_final_prices_per_line_item(EE_Line_Item $line_item, $billable_ticket_quantities = array()) {
1385 1385
 		//init running grand total if not already
1386
-		if ( ! isset( $running_totals[ 'total' ] ) ) {
1387
-			$running_totals[ 'total' ] = 0;
1386
+		if ( ! isset($running_totals['total'])) {
1387
+			$running_totals['total'] = 0;
1388 1388
 		}
1389
-		if( ! isset( $running_totals[ 'taxable' ] ) ) {
1390
-			$running_totals[ 'taxable' ] = array( 'total' => 0 );
1389
+		if ( ! isset($running_totals['taxable'])) {
1390
+			$running_totals['taxable'] = array('total' => 0);
1391 1391
 		}
1392
-		foreach ( $line_item->children() as $child_line_item ) {
1393
-			switch ( $child_line_item->type() ) {
1392
+		foreach ($line_item->children() as $child_line_item) {
1393
+			switch ($child_line_item->type()) {
1394 1394
 
1395 1395
 				case EEM_Line_Item::type_sub_total :
1396
-					$running_totals_from_subtotal = EEH_Line_Item::calculate_reg_final_prices_per_line_item( $child_line_item, $billable_ticket_quantities );
1396
+					$running_totals_from_subtotal = EEH_Line_Item::calculate_reg_final_prices_per_line_item($child_line_item, $billable_ticket_quantities);
1397 1397
 					//combine arrays but preserve numeric keys
1398
-					$running_totals = array_replace_recursive( $running_totals_from_subtotal, $running_totals );
1399
-					$running_totals[ 'total' ] += $running_totals_from_subtotal[ 'total' ];
1400
-					$running_totals[ 'taxable'][ 'total' ] += $running_totals_from_subtotal[ 'taxable' ][ 'total' ];
1398
+					$running_totals = array_replace_recursive($running_totals_from_subtotal, $running_totals);
1399
+					$running_totals['total'] += $running_totals_from_subtotal['total'];
1400
+					$running_totals['taxable']['total'] += $running_totals_from_subtotal['taxable']['total'];
1401 1401
 					break;
1402 1402
 
1403 1403
 				case EEM_Line_Item::type_tax_sub_total :
1404 1404
 
1405 1405
 					//find how much the taxes percentage is
1406
-					if ( $child_line_item->percent() !== 0 ) {
1406
+					if ($child_line_item->percent() !== 0) {
1407 1407
 						$tax_percent_decimal = $child_line_item->percent() / 100;
1408 1408
 					} else {
1409 1409
 						$tax_percent_decimal = EE_Taxes::get_total_taxes_percentage() / 100;
1410 1410
 					}
1411 1411
 					//and apply to all the taxable totals, and add to the pretax totals
1412
-					foreach ( $running_totals as $line_item_id => $this_running_total ) {
1412
+					foreach ($running_totals as $line_item_id => $this_running_total) {
1413 1413
 						//"total" and "taxable" array key is an exception
1414
-						if ( $line_item_id === 'taxable' ) {
1414
+						if ($line_item_id === 'taxable') {
1415 1415
 							continue;
1416 1416
 						}
1417
-						$taxable_total = $running_totals[ 'taxable' ][ $line_item_id ];
1418
-						$running_totals[ $line_item_id ] += ( $taxable_total * $tax_percent_decimal );
1417
+						$taxable_total = $running_totals['taxable'][$line_item_id];
1418
+						$running_totals[$line_item_id] += ($taxable_total * $tax_percent_decimal);
1419 1419
 					}
1420 1420
 					break;
1421 1421
 
1422 1422
 				case EEM_Line_Item::type_line_item :
1423 1423
 
1424 1424
 					// ticket line items or ????
1425
-					if ( $child_line_item->OBJ_type() === 'Ticket' ) {
1425
+					if ($child_line_item->OBJ_type() === 'Ticket') {
1426 1426
 						// kk it's a ticket
1427
-						if ( isset( $running_totals[ $child_line_item->ID() ] ) ) {
1427
+						if (isset($running_totals[$child_line_item->ID()])) {
1428 1428
 							//huh? that shouldn't happen.
1429
-							$running_totals[ 'total' ] += $child_line_item->total();
1429
+							$running_totals['total'] += $child_line_item->total();
1430 1430
 						} else {
1431 1431
 							//its not in our running totals yet. great.
1432
-							if ( $child_line_item->is_taxable() ) {
1432
+							if ($child_line_item->is_taxable()) {
1433 1433
 								$taxable_amount = $child_line_item->unit_price();
1434 1434
 							} else {
1435 1435
 								$taxable_amount = 0;
1436 1436
 							}
1437 1437
 							// are we only calculating totals for some tickets?
1438
-							if ( isset( $billable_ticket_quantities[ $child_line_item->OBJ_ID() ] ) ) {
1439
-								$quantity = $billable_ticket_quantities[ $child_line_item->OBJ_ID() ];
1440
-								$running_totals[ $child_line_item->ID() ] = $quantity
1438
+							if (isset($billable_ticket_quantities[$child_line_item->OBJ_ID()])) {
1439
+								$quantity = $billable_ticket_quantities[$child_line_item->OBJ_ID()];
1440
+								$running_totals[$child_line_item->ID()] = $quantity
1441 1441
 									? $child_line_item->unit_price()
1442 1442
 									: 0;
1443
-								$running_totals[ 'taxable' ][ $child_line_item->ID() ] = $quantity
1443
+								$running_totals['taxable'][$child_line_item->ID()] = $quantity
1444 1444
 									? $taxable_amount
1445 1445
 									: 0;
1446 1446
 							} else {
1447 1447
 								$quantity = $child_line_item->quantity();
1448
-								$running_totals[ $child_line_item->ID() ] = $child_line_item->unit_price();
1449
-								$running_totals[ 'taxable' ][ $child_line_item->ID() ] = $taxable_amount;
1448
+								$running_totals[$child_line_item->ID()] = $child_line_item->unit_price();
1449
+								$running_totals['taxable'][$child_line_item->ID()] = $taxable_amount;
1450 1450
 							}
1451
-							$running_totals[ 'taxable' ][ 'total' ] += $taxable_amount * $quantity;
1452
-							$running_totals[ 'total' ] += $child_line_item->unit_price() * $quantity;
1451
+							$running_totals['taxable']['total'] += $taxable_amount * $quantity;
1452
+							$running_totals['total'] += $child_line_item->unit_price() * $quantity;
1453 1453
 						}
1454 1454
 					} else {
1455 1455
 						// it's some other type of item added to the cart
1456 1456
 						// it should affect the running totals
1457 1457
 						// basically we want to convert it into a PERCENT modifier. Because
1458 1458
 						// more clearly affect all registration's final price equally
1459
-						$line_items_percent_of_running_total = $running_totals[ 'total' ] > 0
1460
-							? ( $child_line_item->total() / $running_totals[ 'total' ] ) + 1
1459
+						$line_items_percent_of_running_total = $running_totals['total'] > 0
1460
+							? ($child_line_item->total() / $running_totals['total']) + 1
1461 1461
 							: 1;
1462
-						foreach ( $running_totals as $line_item_id => $this_running_total ) {
1462
+						foreach ($running_totals as $line_item_id => $this_running_total) {
1463 1463
 							//the "taxable" array key is an exception
1464
-							if ( $line_item_id === 'taxable' ) {
1464
+							if ($line_item_id === 'taxable') {
1465 1465
 								continue;
1466 1466
 							}
1467 1467
 							// update the running totals
1468 1468
 							// yes this actually even works for the running grand total!
1469
-							$running_totals[ $line_item_id ] =
1469
+							$running_totals[$line_item_id] =
1470 1470
 								$line_items_percent_of_running_total * $this_running_total;
1471 1471
 
1472
-							if ( $child_line_item->is_taxable() ) {
1473
-								$running_totals[ 'taxable' ][ $line_item_id ] =
1474
-									$line_items_percent_of_running_total * $running_totals[ 'taxable' ][ $line_item_id ];
1472
+							if ($child_line_item->is_taxable()) {
1473
+								$running_totals['taxable'][$line_item_id] =
1474
+									$line_items_percent_of_running_total * $running_totals['taxable'][$line_item_id];
1475 1475
 							}
1476 1476
 						}
1477 1477
 					}
@@ -1489,16 +1489,16 @@  discard block
 block discarded – undo
1489 1489
 	 * @return float | null
1490 1490
 	 * @throws \OutOfRangeException
1491 1491
 	 */
1492
-	public static function calculate_final_price_for_ticket_line_item( \EE_Line_Item $total_line_item, \EE_Line_Item $ticket_line_item ) {
1492
+	public static function calculate_final_price_for_ticket_line_item(\EE_Line_Item $total_line_item, \EE_Line_Item $ticket_line_item) {
1493 1493
 		static $final_prices_per_ticket_line_item = array();
1494
-		if ( empty( $final_prices_per_ticket_line_item ) ) {
1494
+		if (empty($final_prices_per_ticket_line_item)) {
1495 1495
 			$final_prices_per_ticket_line_item = \EEH_Line_Item::calculate_reg_final_prices_per_line_item(
1496 1496
 				$total_line_item
1497 1497
 			);
1498 1498
 		}
1499 1499
 		//ok now find this new registration's final price
1500
-		if ( isset( $final_prices_per_ticket_line_item[ $ticket_line_item->ID() ] ) ) {
1501
-			return $final_prices_per_ticket_line_item[ $ticket_line_item->ID() ];
1500
+		if (isset($final_prices_per_ticket_line_item[$ticket_line_item->ID()])) {
1501
+			return $final_prices_per_ticket_line_item[$ticket_line_item->ID()];
1502 1502
 		}
1503 1503
 		$message = sprintf(
1504 1504
 			__(
@@ -1507,10 +1507,10 @@  discard block
 block discarded – undo
1507 1507
 			),
1508 1508
 			$ticket_line_item->ID()
1509 1509
 		);
1510
-		if ( WP_DEBUG ) {
1511
-			throw new \OutOfRangeException( $message );
1510
+		if (WP_DEBUG) {
1511
+			throw new \OutOfRangeException($message);
1512 1512
 		} else {
1513
-			EE_Log::instance()->log( __CLASS__, __FUNCTION__, $message );
1513
+			EE_Log::instance()->log(__CLASS__, __FUNCTION__, $message);
1514 1514
 		}
1515 1515
 		return null;
1516 1516
 	}
@@ -1526,15 +1526,15 @@  discard block
 block discarded – undo
1526 1526
 	 * @return \EE_Line_Item
1527 1527
 	 * @throws \EE_Error
1528 1528
 	 */
1529
-	public static function billable_line_item_tree( EE_Line_Item $line_item, $registrations ) {
1530
-		$copy_li = EEH_Line_Item::billable_line_item( $line_item, $registrations );
1531
-		foreach ( $line_item->children() as $child_li ) {
1532
-			$copy_li->add_child_line_item( EEH_Line_Item::billable_line_item_tree( $child_li, $registrations ) );
1529
+	public static function billable_line_item_tree(EE_Line_Item $line_item, $registrations) {
1530
+		$copy_li = EEH_Line_Item::billable_line_item($line_item, $registrations);
1531
+		foreach ($line_item->children() as $child_li) {
1532
+			$copy_li->add_child_line_item(EEH_Line_Item::billable_line_item_tree($child_li, $registrations));
1533 1533
 		}
1534 1534
 		//if this is the grand total line item, make sure the totals all add up
1535 1535
 		//(we could have duplicated this logic AS we copied the line items, but
1536 1536
 		//it seems DRYer this way)
1537
-		if ( $copy_li->type() === EEM_Line_Item::type_total ) {
1537
+		if ($copy_li->type() === EEM_Line_Item::type_total) {
1538 1538
 			$copy_li->recalculate_total_including_taxes();
1539 1539
 		}
1540 1540
 		return $copy_li;
@@ -1551,24 +1551,24 @@  discard block
 block discarded – undo
1551 1551
 	 * @throws \EE_Error
1552 1552
 	 * @param EE_Registration[] $registrations
1553 1553
 	 */
1554
-	public static function billable_line_item( EE_Line_Item $line_item, $registrations ) {
1554
+	public static function billable_line_item(EE_Line_Item $line_item, $registrations) {
1555 1555
 		$new_li_fields = $line_item->model_field_array();
1556
-		if ( $line_item->type() === EEM_Line_Item::type_line_item &&
1556
+		if ($line_item->type() === EEM_Line_Item::type_line_item &&
1557 1557
 			$line_item->OBJ_type() === 'Ticket'
1558 1558
 		) {
1559 1559
 			$count = 0;
1560
-			foreach ( $registrations as $registration ) {
1561
-				if ( $line_item->OBJ_ID() === $registration->ticket_ID() &&
1562
-					in_array( $registration->status_ID(), EEM_Registration::reg_statuses_that_allow_payment() )
1560
+			foreach ($registrations as $registration) {
1561
+				if ($line_item->OBJ_ID() === $registration->ticket_ID() &&
1562
+					in_array($registration->status_ID(), EEM_Registration::reg_statuses_that_allow_payment())
1563 1563
 				) {
1564 1564
 					$count++;
1565 1565
 				}
1566 1566
 			}
1567
-			$new_li_fields[ 'LIN_quantity' ] = $count;
1567
+			$new_li_fields['LIN_quantity'] = $count;
1568 1568
 		}
1569 1569
 		//don't set the total. We'll leave that up to the code that calculates it
1570
-		unset( $new_li_fields[ 'LIN_ID' ], $new_li_fields[ 'LIN_parent' ], $new_li_fields[ 'LIN_total' ] );
1571
-		return EE_Line_Item::new_instance( $new_li_fields );
1570
+		unset($new_li_fields['LIN_ID'], $new_li_fields['LIN_parent'], $new_li_fields['LIN_total']);
1571
+		return EE_Line_Item::new_instance($new_li_fields);
1572 1572
 	}
1573 1573
 
1574 1574
 
@@ -1581,19 +1581,19 @@  discard block
 block discarded – undo
1581 1581
 	 * @return \EE_Line_Item|null
1582 1582
 	 * @throws \EE_Error
1583 1583
 	 */
1584
-	public static function non_empty_line_items( EE_Line_Item $line_item ) {
1585
-		$copied_li = EEH_Line_Item::non_empty_line_item( $line_item );
1586
-		if ( $copied_li === null ) {
1584
+	public static function non_empty_line_items(EE_Line_Item $line_item) {
1585
+		$copied_li = EEH_Line_Item::non_empty_line_item($line_item);
1586
+		if ($copied_li === null) {
1587 1587
 			return null;
1588 1588
 		}
1589 1589
 		//if this is an event subtotal, we want to only include it if it
1590 1590
 		//has a non-zero total and at least one ticket line item child
1591 1591
 		$ticket_children = 0;
1592
-		foreach ( $line_item->children() as $child_li ) {
1593
-			$child_li_copy = EEH_Line_Item::non_empty_line_items( $child_li );
1594
-			if ( $child_li_copy !== null ) {
1595
-				$copied_li->add_child_line_item( $child_li_copy );
1596
-				if ( $child_li_copy->type() === EEM_Line_Item::type_line_item &&
1592
+		foreach ($line_item->children() as $child_li) {
1593
+			$child_li_copy = EEH_Line_Item::non_empty_line_items($child_li);
1594
+			if ($child_li_copy !== null) {
1595
+				$copied_li->add_child_line_item($child_li_copy);
1596
+				if ($child_li_copy->type() === EEM_Line_Item::type_line_item &&
1597 1597
 					$child_li_copy->OBJ_type() === 'Ticket'
1598 1598
 				) {
1599 1599
 					$ticket_children++;
@@ -1623,8 +1623,8 @@  discard block
 block discarded – undo
1623 1623
 	 * @return EE_Line_Item
1624 1624
 	 * @throws \EE_Error
1625 1625
 	 */
1626
-	public static function non_empty_line_item( EE_Line_Item $line_item ) {
1627
-		if ( $line_item->type() === EEM_Line_Item::type_line_item &&
1626
+	public static function non_empty_line_item(EE_Line_Item $line_item) {
1627
+		if ($line_item->type() === EEM_Line_Item::type_line_item &&
1628 1628
 			$line_item->OBJ_type() === 'Ticket' &&
1629 1629
 			$line_item->quantity() === 0
1630 1630
 		) {
@@ -1632,8 +1632,8 @@  discard block
 block discarded – undo
1632 1632
 		}
1633 1633
 		$new_li_fields = $line_item->model_field_array();
1634 1634
 		//don't set the total. We'll leave that up to the code that calculates it
1635
-		unset( $new_li_fields[ 'LIN_ID' ], $new_li_fields[ 'LIN_parent' ] );
1636
-		return EE_Line_Item::new_instance( $new_li_fields );
1635
+		unset($new_li_fields['LIN_ID'], $new_li_fields['LIN_parent']);
1636
+		return EE_Line_Item::new_instance($new_li_fields);
1637 1637
 	}
1638 1638
 
1639 1639
 
@@ -1645,9 +1645,9 @@  discard block
 block discarded – undo
1645 1645
 	 * @return \EE_Line_Item
1646 1646
 	 * @throws \EE_Error
1647 1647
 	 */
1648
-	public static function get_items_subtotal( EE_Line_Item $total_line_item ){
1649
-		EE_Error::doing_it_wrong( 'EEH_Line_Item::get_items_subtotal()', __('Method replaced with EEH_Line_Item::get_pre_tax_subtotal()', 'event_espresso'), '4.6.0' );
1650
-		return self::get_pre_tax_subtotal( $total_line_item );
1648
+	public static function get_items_subtotal(EE_Line_Item $total_line_item) {
1649
+		EE_Error::doing_it_wrong('EEH_Line_Item::get_items_subtotal()', __('Method replaced with EEH_Line_Item::get_pre_tax_subtotal()', 'event_espresso'), '4.6.0');
1650
+		return self::get_pre_tax_subtotal($total_line_item);
1651 1651
 	}
1652 1652
 
1653 1653
 
@@ -1658,9 +1658,9 @@  discard block
 block discarded – undo
1658 1658
 	 * @return \EE_Line_Item
1659 1659
 	 * @throws \EE_Error
1660 1660
 	 */
1661
-	public static function create_default_total_line_item( $transaction = NULL) {
1662
-		EE_Error::doing_it_wrong( 'EEH_Line_Item::create_default_total_line_item()', __('Method replaced with EEH_Line_Item::create_total_line_item()', 'event_espresso'), '4.6.0' );
1663
-		return self::create_total_line_item( $transaction );
1661
+	public static function create_default_total_line_item($transaction = NULL) {
1662
+		EE_Error::doing_it_wrong('EEH_Line_Item::create_default_total_line_item()', __('Method replaced with EEH_Line_Item::create_total_line_item()', 'event_espresso'), '4.6.0');
1663
+		return self::create_total_line_item($transaction);
1664 1664
 	}
1665 1665
 
1666 1666
 
@@ -1672,9 +1672,9 @@  discard block
 block discarded – undo
1672 1672
 	 * @return \EE_Line_Item
1673 1673
 	 * @throws \EE_Error
1674 1674
 	 */
1675
-	public static function create_default_tickets_subtotal( EE_Line_Item $total_line_item, $transaction = NULL) {
1676
-		EE_Error::doing_it_wrong( 'EEH_Line_Item::create_default_tickets_subtotal()', __('Method replaced with EEH_Line_Item::create_pre_tax_subtotal()', 'event_espresso'), '4.6.0' );
1677
-		return self::create_pre_tax_subtotal( $total_line_item, $transaction );
1675
+	public static function create_default_tickets_subtotal(EE_Line_Item $total_line_item, $transaction = NULL) {
1676
+		EE_Error::doing_it_wrong('EEH_Line_Item::create_default_tickets_subtotal()', __('Method replaced with EEH_Line_Item::create_pre_tax_subtotal()', 'event_espresso'), '4.6.0');
1677
+		return self::create_pre_tax_subtotal($total_line_item, $transaction);
1678 1678
 	}
1679 1679
 
1680 1680
 
@@ -1686,9 +1686,9 @@  discard block
 block discarded – undo
1686 1686
 	 * @return \EE_Line_Item
1687 1687
 	 * @throws \EE_Error
1688 1688
 	 */
1689
-	public static function create_default_taxes_subtotal( EE_Line_Item $total_line_item, $transaction = NULL) {
1690
-		EE_Error::doing_it_wrong( 'EEH_Line_Item::create_default_taxes_subtotal()', __('Method replaced with EEH_Line_Item::create_taxes_subtotal()', 'event_espresso'), '4.6.0' );
1691
-		return self::create_taxes_subtotal( $total_line_item, $transaction );
1689
+	public static function create_default_taxes_subtotal(EE_Line_Item $total_line_item, $transaction = NULL) {
1690
+		EE_Error::doing_it_wrong('EEH_Line_Item::create_default_taxes_subtotal()', __('Method replaced with EEH_Line_Item::create_taxes_subtotal()', 'event_espresso'), '4.6.0');
1691
+		return self::create_taxes_subtotal($total_line_item, $transaction);
1692 1692
 	}
1693 1693
 
1694 1694
 
@@ -1700,9 +1700,9 @@  discard block
 block discarded – undo
1700 1700
 	 * @return \EE_Line_Item
1701 1701
 	 * @throws \EE_Error
1702 1702
 	 */
1703
-	public static function create_default_event_subtotal( EE_Line_Item $total_line_item, $transaction = NULL) {
1704
-		EE_Error::doing_it_wrong( 'EEH_Line_Item::create_default_event_subtotal()', __('Method replaced with EEH_Line_Item::create_event_subtotal()', 'event_espresso'), '4.6.0' );
1705
-		return self::create_event_subtotal( $total_line_item, $transaction );
1703
+	public static function create_default_event_subtotal(EE_Line_Item $total_line_item, $transaction = NULL) {
1704
+		EE_Error::doing_it_wrong('EEH_Line_Item::create_default_event_subtotal()', __('Method replaced with EEH_Line_Item::create_event_subtotal()', 'event_espresso'), '4.6.0');
1705
+		return self::create_event_subtotal($total_line_item, $transaction);
1706 1706
 	}
1707 1707
 
1708 1708
 
Please login to merge, or discard this patch.
core/helpers/EEH_File.helper.php 1 patch
Spacing   +178 added lines, -178 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
@@ -52,30 +52,30 @@  discard block
 block discarded – undo
52 52
 	 * @throws EE_Error if filesystem credentials are required
53 53
 	 * @return WP_Filesystem_Base
54 54
 	 */
55
-	private static function _get_wp_filesystem( $filepath = null) {
56
-		if( apply_filters(
55
+	private static function _get_wp_filesystem($filepath = null) {
56
+		if (apply_filters(
57 57
 				'FHEE__EEH_File___get_wp_filesystem__allow_using_filesystem_direct',
58
-				$filepath && EEH_File::is_in_uploads_folder( $filepath ),
59
-				$filepath ) ) {
60
-			if( ! EEH_File::$_wp_filesystem_direct instanceof WP_Filesystem_Direct ) {
61
-				require_once(ABSPATH . 'wp-admin/includes/class-wp-filesystem-base.php');
58
+				$filepath && EEH_File::is_in_uploads_folder($filepath),
59
+				$filepath )) {
60
+			if ( ! EEH_File::$_wp_filesystem_direct instanceof WP_Filesystem_Direct) {
61
+				require_once(ABSPATH.'wp-admin/includes/class-wp-filesystem-base.php');
62 62
 				$method = 'direct';
63
-				$wp_filesystem_direct_file = apply_filters( 'filesystem_method_file', ABSPATH . 'wp-admin/includes/class-wp-filesystem-' . $method . '.php', $method );
63
+				$wp_filesystem_direct_file = apply_filters('filesystem_method_file', ABSPATH.'wp-admin/includes/class-wp-filesystem-'.$method.'.php', $method);
64 64
 				//check constants defined, just like in wp-admin/includes/file.php's WP_Filesystem()
65
-				if ( ! defined('FS_CHMOD_DIR') ) {
66
-					define('FS_CHMOD_DIR', ( fileperms( ABSPATH ) & 0777 | 0755 ) );
65
+				if ( ! defined('FS_CHMOD_DIR')) {
66
+					define('FS_CHMOD_DIR', (fileperms(ABSPATH) & 0777 | 0755));
67 67
 				}
68
-				if ( ! defined('FS_CHMOD_FILE') ) {
69
-					define('FS_CHMOD_FILE', ( fileperms( ABSPATH . 'index.php' ) & 0777 | 0644 ) );
68
+				if ( ! defined('FS_CHMOD_FILE')) {
69
+					define('FS_CHMOD_FILE', (fileperms(ABSPATH.'index.php') & 0777 | 0644));
70 70
 				}
71
-				require_once( $wp_filesystem_direct_file );
72
-				EEH_File::$_wp_filesystem_direct = new WP_Filesystem_Direct( array() );
71
+				require_once($wp_filesystem_direct_file);
72
+				EEH_File::$_wp_filesystem_direct = new WP_Filesystem_Direct(array());
73 73
 			}
74 74
 			return EEH_File::$_wp_filesystem_direct;
75 75
 		}
76 76
 		global $wp_filesystem;
77 77
 		// no filesystem setup ???
78
-		if ( ! $wp_filesystem instanceof WP_Filesystem_Base ) {
78
+		if ( ! $wp_filesystem instanceof WP_Filesystem_Base) {
79 79
 			// if some eager beaver's just trying to get in there too early...
80 80
 			// let them do it, because we are one of those eager beavers! :P
81 81
 			/**
@@ -88,34 +88,34 @@  discard block
 block discarded – undo
88 88
 			 * and there may be troubles if the WP files are owned by a different user
89 89
 			 * than the server user. But both of these issues should exist in 4.4 and earlier too
90 90
 			 */
91
-			if ( FALSE && ! did_action( 'wp_loaded' )) {
91
+			if (FALSE && ! did_action('wp_loaded')) {
92 92
 				$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');
93
-				if ( WP_DEBUG ) {
94
-					$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');
93
+				if (WP_DEBUG) {
94
+					$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');
95 95
 				}
96
-				throw new EE_Error( $msg );
96
+				throw new EE_Error($msg);
97 97
 			} else {
98 98
 				// should be loaded if we are past the wp_loaded hook...
99
-				if ( ! function_exists( 'WP_Filesystem' )) {
100
-					require_once( ABSPATH . 'wp-admin/includes/file.php' );
101
-					require_once( ABSPATH . 'wp-admin/includes/template.php' );
99
+				if ( ! function_exists('WP_Filesystem')) {
100
+					require_once(ABSPATH.'wp-admin/includes/file.php');
101
+					require_once(ABSPATH.'wp-admin/includes/template.php');
102 102
 				}
103 103
 				// turn on output buffering so that we can capture the credentials form
104 104
 				ob_start();
105
-				$credentials = request_filesystem_credentials( '' );
105
+				$credentials = request_filesystem_credentials('');
106 106
 				// store credentials form for the time being
107 107
 				EEH_File::$_credentials_form = ob_get_clean();
108 108
 				// basically check for direct or previously configured access
109
-				if ( ! WP_Filesystem( $credentials ) ) {
109
+				if ( ! WP_Filesystem($credentials)) {
110 110
 					// if credentials do NOT exist
111
-					if ( $credentials === FALSE ) {
112
-						add_action( 'admin_notices', array( 'EEH_File', 'display_request_filesystem_credentials_form' ), 999 );
113
-						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'));
114
-					} elseif( is_wp_error( $wp_filesystem->errors ) && $wp_filesystem->errors->get_error_code() ) {
115
-						add_action( 'admin_notices', array( 'EEH_File', 'display_request_filesystem_credentials_form' ), 999 );
111
+					if ($credentials === FALSE) {
112
+						add_action('admin_notices', array('EEH_File', 'display_request_filesystem_credentials_form'), 999);
113
+						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'));
114
+					} elseif (is_wp_error($wp_filesystem->errors) && $wp_filesystem->errors->get_error_code()) {
115
+						add_action('admin_notices', array('EEH_File', 'display_request_filesystem_credentials_form'), 999);
116 116
 						throw new EE_Error(
117 117
 								sprintf(
118
-										__( 'WP Filesystem Error: $1%s', 'event_espresso' ),
118
+										__('WP Filesystem Error: $1%s', 'event_espresso'),
119 119
 										$wp_filesystem->errors->get_error_message() ) );
120 120
 					}
121 121
 				}
@@ -128,8 +128,8 @@  discard block
 block discarded – undo
128 128
 	 * display_request_filesystem_credentials_form
129 129
 	 */
130 130
 	public static function display_request_filesystem_credentials_form() {
131
-		if ( ! empty( EEH_File::$_credentials_form )) {
132
-			echo '<div class="updated espresso-notices-attention"><p>' . EEH_File::$_credentials_form . '</p></div>';
131
+		if ( ! empty(EEH_File::$_credentials_form)) {
132
+			echo '<div class="updated espresso-notices-attention"><p>'.EEH_File::$_credentials_form.'</p></div>';
133 133
 		}
134 134
 	}
135 135
 
@@ -147,29 +147,29 @@  discard block
 block discarded – undo
147 147
 	 * @throws EE_Error if filesystem credentials are required
148 148
 	 * @return bool
149 149
 	 */
150
-	public static function verify_filepath_and_permissions( $full_file_path = '', $file_name = '', $file_ext = '', $type_of_file = '' ) {
150
+	public static function verify_filepath_and_permissions($full_file_path = '', $file_name = '', $file_ext = '', $type_of_file = '') {
151 151
 		// load WP_Filesystem and set file permissions
152
-		$wp_filesystem = EEH_File::_get_wp_filesystem( $full_file_path );
153
-		$full_file_path = EEH_File::standardise_directory_separators( $full_file_path );
154
-		if ( ! $wp_filesystem->is_readable( EEH_File::convert_local_filepath_to_remote_filepath( $full_file_path ) )) {
155
-			$file_name = ! empty( $type_of_file ) ? $file_name . ' ' . $type_of_file : $file_name;
156
-			$file_name .= ! empty( $file_ext ) ? ' file' : ' folder';
152
+		$wp_filesystem = EEH_File::_get_wp_filesystem($full_file_path);
153
+		$full_file_path = EEH_File::standardise_directory_separators($full_file_path);
154
+		if ( ! $wp_filesystem->is_readable(EEH_File::convert_local_filepath_to_remote_filepath($full_file_path))) {
155
+			$file_name = ! empty($type_of_file) ? $file_name.' '.$type_of_file : $file_name;
156
+			$file_name .= ! empty($file_ext) ? ' file' : ' folder';
157 157
 			$msg = sprintf(
158
-				__( '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' ),
158
+				__('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'),
159 159
 				$file_name,
160 160
 				'<br />'
161 161
 			);
162
-			if ( EEH_File::exists( $full_file_path )) {
163
-				$msg .= EEH_File::_permissions_error_for_unreadable_filepath( $full_file_path, $type_of_file );
162
+			if (EEH_File::exists($full_file_path)) {
163
+				$msg .= EEH_File::_permissions_error_for_unreadable_filepath($full_file_path, $type_of_file);
164 164
 			} else {
165 165
 				// no file permissions means the file was not found
166 166
 				$msg .= sprintf(
167
-					__( 'Please ensure the following path is correct: "%s".', 'event_espresso' ),
167
+					__('Please ensure the following path is correct: "%s".', 'event_espresso'),
168 168
 					$full_file_path
169 169
 				);
170 170
 			}
171
-			if ( defined( 'WP_DEBUG' ) && WP_DEBUG ) {
172
-				throw new EE_Error( $msg . '||' . $msg );
171
+			if (defined('WP_DEBUG') && WP_DEBUG) {
172
+				throw new EE_Error($msg.'||'.$msg);
173 173
 			}
174 174
 			return FALSE;
175 175
 		}
@@ -187,24 +187,24 @@  discard block
 block discarded – undo
187 187
 	 * @throws EE_Error if filesystem credentials are required
188 188
 	 * @return string
189 189
 	 */
190
-	private static function _permissions_error_for_unreadable_filepath( $full_file_path = '', $type_of_file = '' ){
190
+	private static function _permissions_error_for_unreadable_filepath($full_file_path = '', $type_of_file = '') {
191 191
 		// load WP_Filesystem and set file permissions
192
-		$wp_filesystem = EEH_File::_get_wp_filesystem( $full_file_path );
192
+		$wp_filesystem = EEH_File::_get_wp_filesystem($full_file_path);
193 193
 		// check file permissions
194
-		$perms = $wp_filesystem->getchmod( EEH_File::convert_local_filepath_to_remote_filepath( $full_file_path ) );
195
-		if ( $perms ) {
194
+		$perms = $wp_filesystem->getchmod(EEH_File::convert_local_filepath_to_remote_filepath($full_file_path));
195
+		if ($perms) {
196 196
 			// file permissions exist, but way be set incorrectly
197
-			$type_of_file = ! empty( $type_of_file ) ? $type_of_file . ' ' : '';
198
-			$type_of_file .= ! empty( $type_of_file ) ? 'file' : 'folder';
197
+			$type_of_file = ! empty($type_of_file) ? $type_of_file.' ' : '';
198
+			$type_of_file .= ! empty($type_of_file) ? 'file' : 'folder';
199 199
 			return sprintf(
200
-				__( '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' ),
200
+				__('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'),
201 201
 				$type_of_file,
202 202
 				$perms
203 203
 			);
204 204
 		} else {
205 205
 			// file exists but file permissions could not be read ?!?!
206 206
 			return sprintf(
207
-				__( 'Please ensure that the server and/or PHP configuration allows the current process to access the following file: "%s".', 'event_espresso' ),
207
+				__('Please ensure that the server and/or PHP configuration allows the current process to access the following file: "%s".', 'event_espresso'),
208 208
 				$full_file_path
209 209
 			);
210 210
 		}
@@ -222,35 +222,35 @@  discard block
 block discarded – undo
222 222
 	 * can't write to it
223 223
 	 * @return bool false if folder isn't writable; true if it exists and is writeable,
224 224
 	 */
225
-	public static function ensure_folder_exists_and_is_writable( $folder = '' ){
226
-		if ( empty( $folder )) {
225
+	public static function ensure_folder_exists_and_is_writable($folder = '') {
226
+		if (empty($folder)) {
227 227
 			return false;
228 228
 		}
229 229
 		// remove ending DS
230
-		$folder = EEH_File::standardise_directory_separators( rtrim( $folder, '/\\' ));
231
-		$parent_folder = EEH_File::get_parent_folder( $folder );
230
+		$folder = EEH_File::standardise_directory_separators(rtrim($folder, '/\\'));
231
+		$parent_folder = EEH_File::get_parent_folder($folder);
232 232
 		// add DS to folder
233
-		$folder = EEH_File::end_with_directory_separator( $folder );
234
-		$wp_filesystem = EEH_File::_get_wp_filesystem( $folder );
235
-		if ( ! $wp_filesystem->is_dir( EEH_File::convert_local_filepath_to_remote_filepath( $folder ) ) ) {
233
+		$folder = EEH_File::end_with_directory_separator($folder);
234
+		$wp_filesystem = EEH_File::_get_wp_filesystem($folder);
235
+		if ( ! $wp_filesystem->is_dir(EEH_File::convert_local_filepath_to_remote_filepath($folder))) {
236 236
 			//ok so it doesn't exist. Does its parent? Can we write to it?
237
-			if(	! EEH_File::ensure_folder_exists_and_is_writable( $parent_folder ) ) {
237
+			if ( ! EEH_File::ensure_folder_exists_and_is_writable($parent_folder)) {
238 238
 				return false;
239 239
 			}
240
-			if ( ! EEH_File::verify_is_writable( $parent_folder, 'folder' )) {
240
+			if ( ! EEH_File::verify_is_writable($parent_folder, 'folder')) {
241 241
 				return false;
242 242
 			} else {
243
-				if ( ! $wp_filesystem->mkdir( EEH_File::convert_local_filepath_to_remote_filepath(  $folder ) ) ) {
244
-					if ( defined( 'WP_DEBUG' ) && WP_DEBUG ) {
245
-						$msg = sprintf( __( '"%s" could not be created.', 'event_espresso' ), $folder );
246
-						$msg .= EEH_File::_permissions_error_for_unreadable_filepath( $folder );
247
-						throw new EE_Error( $msg );
243
+				if ( ! $wp_filesystem->mkdir(EEH_File::convert_local_filepath_to_remote_filepath($folder))) {
244
+					if (defined('WP_DEBUG') && WP_DEBUG) {
245
+						$msg = sprintf(__('"%s" could not be created.', 'event_espresso'), $folder);
246
+						$msg .= EEH_File::_permissions_error_for_unreadable_filepath($folder);
247
+						throw new EE_Error($msg);
248 248
 					}
249 249
 					return false;
250 250
 				}
251
-				EEH_File::add_index_file( $folder );
251
+				EEH_File::add_index_file($folder);
252 252
 			}
253
-		} elseif ( ! EEH_File::verify_is_writable( $folder, 'folder' )) {
253
+		} elseif ( ! EEH_File::verify_is_writable($folder, 'folder')) {
254 254
 			return false;
255 255
 		}
256 256
 		return true;
@@ -265,15 +265,15 @@  discard block
 block discarded – undo
265 265
 	 * @throws EE_Error if filesystem credentials are required
266 266
 	 * @return bool
267 267
 	 */
268
-	public static function verify_is_writable( $full_path = '', $file_or_folder = 'folder' ){
268
+	public static function verify_is_writable($full_path = '', $file_or_folder = 'folder') {
269 269
 		// load WP_Filesystem and set file permissions
270
-		$wp_filesystem = EEH_File::_get_wp_filesystem( $full_path );
271
-		$full_path = EEH_File::standardise_directory_separators( $full_path );
272
-		if ( ! $wp_filesystem->is_writable( EEH_File::convert_local_filepath_to_remote_filepath( $full_path ) ) ) {
273
-			if ( defined( 'WP_DEBUG' ) && WP_DEBUG ) {
274
-				$msg = sprintf( __( 'The "%1$s" %2$s is not writable.', 'event_espresso' ), $full_path, $file_or_folder );
275
-				$msg .= EEH_File::_permissions_error_for_unreadable_filepath( $full_path );
276
-				throw new EE_Error( $msg );
270
+		$wp_filesystem = EEH_File::_get_wp_filesystem($full_path);
271
+		$full_path = EEH_File::standardise_directory_separators($full_path);
272
+		if ( ! $wp_filesystem->is_writable(EEH_File::convert_local_filepath_to_remote_filepath($full_path))) {
273
+			if (defined('WP_DEBUG') && WP_DEBUG) {
274
+				$msg = sprintf(__('The "%1$s" %2$s is not writable.', 'event_espresso'), $full_path, $file_or_folder);
275
+				$msg .= EEH_File::_permissions_error_for_unreadable_filepath($full_path);
276
+				throw new EE_Error($msg);
277 277
 			}
278 278
 			return FALSE;
279 279
 		}
@@ -290,25 +290,25 @@  discard block
 block discarded – undo
290 290
 	 * @throws EE_Error if filesystem credentials are required
291 291
 	 * @return bool
292 292
 	 */
293
-	public static function ensure_file_exists_and_is_writable( $full_file_path = '' ) {
293
+	public static function ensure_file_exists_and_is_writable($full_file_path = '') {
294 294
 		// load WP_Filesystem and set file permissions
295
-		$wp_filesystem = EEH_File::_get_wp_filesystem( $full_file_path );
296
-		$full_file_path = EEH_File::standardise_directory_separators( $full_file_path );
297
-		$parent_folder = EEH_File::get_parent_folder( $full_file_path );
298
-		if ( ! EEH_File::exists( $full_file_path )) {
299
-			if( ! EEH_File::ensure_folder_exists_and_is_writable( $parent_folder ) ) {
295
+		$wp_filesystem = EEH_File::_get_wp_filesystem($full_file_path);
296
+		$full_file_path = EEH_File::standardise_directory_separators($full_file_path);
297
+		$parent_folder = EEH_File::get_parent_folder($full_file_path);
298
+		if ( ! EEH_File::exists($full_file_path)) {
299
+			if ( ! EEH_File::ensure_folder_exists_and_is_writable($parent_folder)) {
300 300
 				return false;
301 301
 			}
302
-			if ( ! $wp_filesystem->touch( EEH_File::convert_local_filepath_to_remote_filepath( $full_file_path ) ) ) {
303
-				if ( defined( 'WP_DEBUG' ) && WP_DEBUG ) {
304
-					$msg = sprintf( __( 'The "%s" file could not be created.', 'event_espresso' ), $full_file_path );
305
-					$msg .= EEH_File::_permissions_error_for_unreadable_filepath( $full_file_path );
306
-					throw new EE_Error( $msg );
302
+			if ( ! $wp_filesystem->touch(EEH_File::convert_local_filepath_to_remote_filepath($full_file_path))) {
303
+				if (defined('WP_DEBUG') && WP_DEBUG) {
304
+					$msg = sprintf(__('The "%s" file could not be created.', 'event_espresso'), $full_file_path);
305
+					$msg .= EEH_File::_permissions_error_for_unreadable_filepath($full_file_path);
306
+					throw new EE_Error($msg);
307 307
 				}
308 308
 				return false;
309 309
 			}
310 310
 		}
311
-		if ( ! EEH_File::verify_is_writable( $full_file_path, 'file' )) {
311
+		if ( ! EEH_File::verify_is_writable($full_file_path, 'file')) {
312 312
 			return false;
313 313
 		}
314 314
 		return true;
@@ -320,12 +320,12 @@  discard block
 block discarded – undo
320 320
 	 * @param string $file_or_folder_path
321 321
 	 * @return string parent folder, ENDING with a directory separator
322 322
 	 */
323
-	public static function get_parent_folder( $file_or_folder_path ) {
323
+	public static function get_parent_folder($file_or_folder_path) {
324 324
 		//find the last DS, ignoring a DS on the very end
325 325
 		//eg if given "/var/something/somewhere/", we want to get "somewhere"'s
326 326
 		//parent folder, "/var/something/"
327
-		$ds = strlen($file_or_folder_path) > 1 ? strrpos( $file_or_folder_path, DS, -2 ) : $file_or_folder_path;
328
-		return substr( $file_or_folder_path, 0, $ds + 1 );
327
+		$ds = strlen($file_or_folder_path) > 1 ? strrpos($file_or_folder_path, DS, -2) : $file_or_folder_path;
328
+		return substr($file_or_folder_path, 0, $ds + 1);
329 329
 	}
330 330
 
331 331
 	// public static function ensure_folder_exists_recursively( $folder ) {
@@ -340,12 +340,12 @@  discard block
 block discarded – undo
340 340
 	 * @throws EE_Error if filesystem credentials are required
341 341
 	 * @return string
342 342
 	 */
343
-	public static function get_file_contents( $full_file_path = '' ){
344
-		$full_file_path = EEH_File::standardise_directory_separators( $full_file_path );
345
-		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 ))) {
343
+	public static function get_file_contents($full_file_path = '') {
344
+		$full_file_path = EEH_File::standardise_directory_separators($full_file_path);
345
+		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))) {
346 346
 			// load WP_Filesystem and set file permissions
347
-			$wp_filesystem = EEH_File::_get_wp_filesystem( $full_file_path );
348
-			return $wp_filesystem->get_contents(EEH_File::convert_local_filepath_to_remote_filepath( $full_file_path ) );
347
+			$wp_filesystem = EEH_File::_get_wp_filesystem($full_file_path);
348
+			return $wp_filesystem->get_contents(EEH_File::convert_local_filepath_to_remote_filepath($full_file_path));
349 349
 		}
350 350
 		return '';
351 351
 	}
@@ -360,26 +360,26 @@  discard block
 block discarded – undo
360 360
 	 * @throws EE_Error if filesystem credentials are required
361 361
 	 * @return bool
362 362
 	 */
363
-	public static function write_to_file( $full_file_path = '', $file_contents = '', $file_type = '' ){
364
-		$full_file_path = EEH_File::standardise_directory_separators( $full_file_path );
365
-		$file_type = ! empty( $file_type ) ? rtrim( $file_type, ' ' ) . ' ' : '';
366
-		$folder = EEH_File::remove_filename_from_filepath( $full_file_path );
367
-		if ( ! EEH_File::verify_is_writable( $folder, 'folder' )) {
368
-			if ( defined( 'WP_DEBUG' ) && WP_DEBUG ) {
369
-				$msg = sprintf( __( 'The %1$sfile located at "%2$s" is not writable.', 'event_espresso' ), $file_type, $full_file_path );
370
-				$msg .= EEH_File::_permissions_error_for_unreadable_filepath( $full_file_path );
371
-				throw new EE_Error( $msg );
363
+	public static function write_to_file($full_file_path = '', $file_contents = '', $file_type = '') {
364
+		$full_file_path = EEH_File::standardise_directory_separators($full_file_path);
365
+		$file_type = ! empty($file_type) ? rtrim($file_type, ' ').' ' : '';
366
+		$folder = EEH_File::remove_filename_from_filepath($full_file_path);
367
+		if ( ! EEH_File::verify_is_writable($folder, 'folder')) {
368
+			if (defined('WP_DEBUG') && WP_DEBUG) {
369
+				$msg = sprintf(__('The %1$sfile located at "%2$s" is not writable.', 'event_espresso'), $file_type, $full_file_path);
370
+				$msg .= EEH_File::_permissions_error_for_unreadable_filepath($full_file_path);
371
+				throw new EE_Error($msg);
372 372
 			}
373 373
 			return FALSE;
374 374
 		}
375 375
 		// load WP_Filesystem and set file permissions
376
-		$wp_filesystem = EEH_File::_get_wp_filesystem( $full_file_path );
376
+		$wp_filesystem = EEH_File::_get_wp_filesystem($full_file_path);
377 377
 		// write the file
378
-		if ( ! $wp_filesystem->put_contents(EEH_File::convert_local_filepath_to_remote_filepath( $full_file_path ), $file_contents )) {
379
-			if ( defined( 'WP_DEBUG' ) && WP_DEBUG ) {
380
-				$msg = sprintf( __( 'The %1$sfile located at "%2$s" could not be written to.', 'event_espresso' ), $file_type, $full_file_path );
381
-				$msg .= EEH_File::_permissions_error_for_unreadable_filepath( $full_file_path, 'f' );
382
-				throw new EE_Error( $msg );
378
+		if ( ! $wp_filesystem->put_contents(EEH_File::convert_local_filepath_to_remote_filepath($full_file_path), $file_contents)) {
379
+			if (defined('WP_DEBUG') && WP_DEBUG) {
380
+				$msg = sprintf(__('The %1$sfile located at "%2$s" could not be written to.', 'event_espresso'), $file_type, $full_file_path);
381
+				$msg .= EEH_File::_permissions_error_for_unreadable_filepath($full_file_path, 'f');
382
+				throw new EE_Error($msg);
383 383
 			}
384 384
 			return FALSE;
385 385
 		}
@@ -395,9 +395,9 @@  discard block
 block discarded – undo
395 395
 	 * @throws EE_Error if filesystem credentials are required
396 396
 	 * @return boolean
397 397
 	 */
398
-	public static function delete( $filepath, $recursive = false, $type = false ) {
398
+	public static function delete($filepath, $recursive = false, $type = false) {
399 399
 		$wp_filesystem = EEH_File::_get_wp_filesystem();
400
-		return $wp_filesystem->delete( $filepath, $recursive, $type ) ? TRUE : FALSE;
400
+		return $wp_filesystem->delete($filepath, $recursive, $type) ? TRUE : FALSE;
401 401
 	}
402 402
 
403 403
 
@@ -409,9 +409,9 @@  discard block
 block discarded – undo
409 409
 	 * @throws EE_Error if filesystem credentials are required
410 410
 	 * @return bool
411 411
 	 */
412
-	public static function exists( $full_file_path = '' ) {
413
-		$wp_filesystem = EEH_File::_get_wp_filesystem( $full_file_path );
414
-		return $wp_filesystem->exists( EEH_File::convert_local_filepath_to_remote_filepath( $full_file_path ) ) ? TRUE : FALSE;
412
+	public static function exists($full_file_path = '') {
413
+		$wp_filesystem = EEH_File::_get_wp_filesystem($full_file_path);
414
+		return $wp_filesystem->exists(EEH_File::convert_local_filepath_to_remote_filepath($full_file_path)) ? TRUE : FALSE;
415 415
 	}
416 416
 
417 417
 
@@ -424,9 +424,9 @@  discard block
 block discarded – undo
424 424
 	 * @throws EE_Error if filesystem credentials are required
425 425
 	 * @return bool
426 426
 	 */
427
-	public static function is_readable( $full_file_path = '' ) {
428
-		$wp_filesystem = EEH_File::_get_wp_filesystem( $full_file_path );
429
-		if( $wp_filesystem->is_readable( EEH_File::convert_local_filepath_to_remote_filepath(  $full_file_path ) ) ) {
427
+	public static function is_readable($full_file_path = '') {
428
+		$wp_filesystem = EEH_File::_get_wp_filesystem($full_file_path);
429
+		if ($wp_filesystem->is_readable(EEH_File::convert_local_filepath_to_remote_filepath($full_file_path))) {
430 430
 			return true;
431 431
 		} else {
432 432
 			return false;
@@ -442,8 +442,8 @@  discard block
 block discarded – undo
442 442
 	 * @param string $full_file_path
443 443
 	 * @return string
444 444
 	 */
445
-	public static function remove_filename_from_filepath( $full_file_path = '' ) {
446
-		return pathinfo( $full_file_path, PATHINFO_DIRNAME );
445
+	public static function remove_filename_from_filepath($full_file_path = '') {
446
+		return pathinfo($full_file_path, PATHINFO_DIRNAME);
447 447
 	}
448 448
 
449 449
 
@@ -453,8 +453,8 @@  discard block
 block discarded – undo
453 453
 	 * @param string $full_file_path
454 454
 	 * @return string
455 455
 	 */
456
-	public static function get_filename_from_filepath( $full_file_path = '' ) {
457
-		return pathinfo( $full_file_path, PATHINFO_BASENAME );
456
+	public static function get_filename_from_filepath($full_file_path = '') {
457
+		return pathinfo($full_file_path, PATHINFO_BASENAME);
458 458
 	}
459 459
 
460 460
 
@@ -464,8 +464,8 @@  discard block
 block discarded – undo
464 464
 	 * @param string $full_file_path
465 465
 	 * @return string
466 466
 	 */
467
-	public static function get_file_extension( $full_file_path = '' ) {
468
-		return pathinfo( $full_file_path, PATHINFO_EXTENSION );
467
+	public static function get_file_extension($full_file_path = '') {
468
+		return pathinfo($full_file_path, PATHINFO_EXTENSION);
469 469
 	}
470 470
 
471 471
 
@@ -476,10 +476,10 @@  discard block
 block discarded – undo
476 476
 	 * @throws EE_Error if filesystem credentials are required
477 477
 	 * @return bool
478 478
 	 */
479
-	public static function add_htaccess_deny_from_all( $folder = '' ) {
480
-		$folder = EEH_File::standardise_and_end_with_directory_separator( $folder );
481
-		if ( ! EEH_File::exists( $folder . '.htaccess' ) ) {
482
-			if ( ! EEH_File::write_to_file( $folder . '.htaccess', 'deny from all', '.htaccess' )) {
479
+	public static function add_htaccess_deny_from_all($folder = '') {
480
+		$folder = EEH_File::standardise_and_end_with_directory_separator($folder);
481
+		if ( ! EEH_File::exists($folder.'.htaccess')) {
482
+			if ( ! EEH_File::write_to_file($folder.'.htaccess', 'deny from all', '.htaccess')) {
483 483
 				return FALSE;
484 484
 			}
485 485
 		}
@@ -493,10 +493,10 @@  discard block
 block discarded – undo
493 493
 	 * @throws EE_Error if filesystem credentials are required
494 494
 	 * @return boolean
495 495
 	 */
496
-	public static function add_index_file( $folder ) {
497
-		$folder = EEH_File::standardise_and_end_with_directory_separator( $folder );
498
-		if ( ! EEH_File::exists( $folder . 'index.php' ) ) {
499
-			if ( ! EEH_File::write_to_file( $folder . 'index.php', 'You are not permitted to read from this folder', '.php' )) {
496
+	public static function add_index_file($folder) {
497
+		$folder = EEH_File::standardise_and_end_with_directory_separator($folder);
498
+		if ( ! EEH_File::exists($folder.'index.php')) {
499
+			if ( ! EEH_File::write_to_file($folder.'index.php', 'You are not permitted to read from this folder', '.php')) {
500 500
 				return false;
501 501
 			}
502 502
 		}
@@ -511,11 +511,11 @@  discard block
 block discarded – undo
511 511
 	 * @param string $file_path
512 512
 	 * @return string
513 513
 	 */
514
-	public static function get_classname_from_filepath_with_standard_filename( $file_path ){
514
+	public static function get_classname_from_filepath_with_standard_filename($file_path) {
515 515
 		//extract file from path
516
-		$filename = basename( $file_path );
516
+		$filename = basename($file_path);
517 517
 		//now remove the first period and everything after
518
-		$pos_of_first_period = strpos( $filename,'.' );
518
+		$pos_of_first_period = strpos($filename, '.');
519 519
 		return substr($filename, 0, $pos_of_first_period);
520 520
 	}
521 521
 
@@ -527,8 +527,8 @@  discard block
 block discarded – undo
527 527
 	 * @param string $file_path
528 528
 	 * @return string
529 529
 	 */
530
-	public static function standardise_directory_separators( $file_path ){
531
-		return str_replace( array( '\\', '/' ), DS, $file_path );
530
+	public static function standardise_directory_separators($file_path) {
531
+		return str_replace(array('\\', '/'), DS, $file_path);
532 532
 	}
533 533
 
534 534
 
@@ -539,8 +539,8 @@  discard block
 block discarded – undo
539 539
 	 * @param string $file_path
540 540
 	 * @return string
541 541
 	 */
542
-	public static function end_with_directory_separator( $file_path ){
543
-		return rtrim( $file_path, '/\\' ) . DS;
542
+	public static function end_with_directory_separator($file_path) {
543
+		return rtrim($file_path, '/\\').DS;
544 544
 	}
545 545
 
546 546
 
@@ -550,8 +550,8 @@  discard block
 block discarded – undo
550 550
 	 * @param $file_path
551 551
 	 * @return string
552 552
 	 */
553
-	public static function standardise_and_end_with_directory_separator( $file_path ){
554
-		return self::end_with_directory_separator( self::standardise_directory_separators( $file_path ));
553
+	public static function standardise_and_end_with_directory_separator($file_path) {
554
+		return self::end_with_directory_separator(self::standardise_directory_separators($file_path));
555 555
 	}
556 556
 
557 557
 
@@ -568,21 +568,21 @@  discard block
 block discarded – undo
568 568
 	 *		if $index_numerically == FALSE (Default) keys are what the class names SHOULD be;
569 569
 	 *		 and values are their filepaths
570 570
 	 */
571
-	public static function get_contents_of_folders( $folder_paths = array(), $index_numerically = FALSE ){
571
+	public static function get_contents_of_folders($folder_paths = array(), $index_numerically = FALSE) {
572 572
 		$class_to_folder_path = array();
573
-		foreach( $folder_paths as $folder_path ){
574
-			$folder_path = self::standardise_and_end_with_directory_separator( $folder_path );
573
+		foreach ($folder_paths as $folder_path) {
574
+			$folder_path = self::standardise_and_end_with_directory_separator($folder_path);
575 575
 			// load WP_Filesystem and set file permissions
576
-			$files_in_folder = glob( $folder_path . '*' );
576
+			$files_in_folder = glob($folder_path.'*');
577 577
 			$class_to_folder_path = array();
578
-			if ( $files_in_folder ) {
579
-				foreach( $files_in_folder as $file_path ){
578
+			if ($files_in_folder) {
579
+				foreach ($files_in_folder as $file_path) {
580 580
 					//only add files, not folders
581
-					if ( ! is_dir( $file_path )) {
582
-						if ( $index_numerically ) {
581
+					if ( ! is_dir($file_path)) {
582
+						if ($index_numerically) {
583 583
 							$class_to_folder_path[] = $file_path;
584 584
 						} else {
585
-							$classname = self::get_classname_from_filepath_with_standard_filename( $file_path );
585
+							$classname = self::get_classname_from_filepath_with_standard_filename($file_path);
586 586
 							$class_to_folder_path[$classname] = $file_path;
587 587
 						}
588 588
 					}
@@ -602,39 +602,39 @@  discard block
 block discarded – undo
602 602
 	 * @throws EE_Error if filesystem credentials are required
603 603
 	 * @return boolean success
604 604
 	 */
605
-	public static function copy( $source_file, $destination_file, $overwrite = FALSE ){
606
-		$full_source_path = EEH_File::standardise_directory_separators( $source_file );
607
-		if( ! EEH_File::exists( $full_source_path ) ){
608
-			if ( defined( 'WP_DEBUG' ) && WP_DEBUG ) {
609
-				$msg = sprintf( __( 'The file located at "%2$s" is not readable or doesn\'t exist.', 'event_espresso' ), $full_source_path );
610
-				$msg .= EEH_File::_permissions_error_for_unreadable_filepath( $full_source_path );
611
-				throw new EE_Error( $msg );
605
+	public static function copy($source_file, $destination_file, $overwrite = FALSE) {
606
+		$full_source_path = EEH_File::standardise_directory_separators($source_file);
607
+		if ( ! EEH_File::exists($full_source_path)) {
608
+			if (defined('WP_DEBUG') && WP_DEBUG) {
609
+				$msg = sprintf(__('The file located at "%2$s" is not readable or doesn\'t exist.', 'event_espresso'), $full_source_path);
610
+				$msg .= EEH_File::_permissions_error_for_unreadable_filepath($full_source_path);
611
+				throw new EE_Error($msg);
612 612
 			}
613 613
 			return FALSE;
614 614
 		}
615 615
 
616
-		$full_dest_path = EEH_File::standardise_directory_separators( $destination_file );
617
-		$folder = EEH_File::remove_filename_from_filepath( $full_dest_path );
618
-		if ( ! EEH_File::verify_is_writable( $folder, 'folder' )) {
619
-			if ( defined( 'WP_DEBUG' ) && WP_DEBUG ) {
620
-				$msg = sprintf( __( 'The file located at "%2$s" is not writable.', 'event_espresso' ), $full_dest_path );
621
-				$msg .= EEH_File::_permissions_error_for_unreadable_filepath( $full_dest_path );
622
-				throw new EE_Error( $msg );
616
+		$full_dest_path = EEH_File::standardise_directory_separators($destination_file);
617
+		$folder = EEH_File::remove_filename_from_filepath($full_dest_path);
618
+		if ( ! EEH_File::verify_is_writable($folder, 'folder')) {
619
+			if (defined('WP_DEBUG') && WP_DEBUG) {
620
+				$msg = sprintf(__('The file located at "%2$s" is not writable.', 'event_espresso'), $full_dest_path);
621
+				$msg .= EEH_File::_permissions_error_for_unreadable_filepath($full_dest_path);
622
+				throw new EE_Error($msg);
623 623
 			}
624 624
 			return FALSE;
625 625
 		}
626 626
 
627 627
 		// load WP_Filesystem and set file permissions
628
-		$wp_filesystem = EEH_File::_get_wp_filesystem( $destination_file );
628
+		$wp_filesystem = EEH_File::_get_wp_filesystem($destination_file);
629 629
 		// write the file
630 630
 		if ( ! $wp_filesystem->copy(
631
-						EEH_File::convert_local_filepath_to_remote_filepath( $full_source_path ),
632
-						EEH_File::convert_local_filepath_to_remote_filepath( $full_dest_path ),
631
+						EEH_File::convert_local_filepath_to_remote_filepath($full_source_path),
632
+						EEH_File::convert_local_filepath_to_remote_filepath($full_dest_path),
633 633
 						$overwrite )) {
634
-			if ( defined( 'WP_DEBUG' ) && WP_DEBUG ) {
635
-				$msg = sprintf( __( 'Attempted writing to file %1$s, but could not, probably because of permissions issues', 'event_espresso' ), $full_source_path );
636
-				$msg .= EEH_File::_permissions_error_for_unreadable_filepath( $full_source_path, 'f' );
637
-				throw new EE_Error( $msg );
634
+			if (defined('WP_DEBUG') && WP_DEBUG) {
635
+				$msg = sprintf(__('Attempted writing to file %1$s, but could not, probably because of permissions issues', 'event_espresso'), $full_source_path);
636
+				$msg .= EEH_File::_permissions_error_for_unreadable_filepath($full_source_path, 'f');
637
+				throw new EE_Error($msg);
638 638
 			}
639 639
 			return FALSE;
640 640
 		}
@@ -646,9 +646,9 @@  discard block
 block discarded – undo
646 646
 	 * @param string $filepath
647 647
 	 * @return boolean
648 648
 	 */
649
-	public static function is_in_uploads_folder( $filepath ) {
649
+	public static function is_in_uploads_folder($filepath) {
650 650
 		$uploads = wp_upload_dir();
651
-		return strpos( $filepath, $uploads[ 'basedir' ] ) === 0 ? true : false;
651
+		return strpos($filepath, $uploads['basedir']) === 0 ? true : false;
652 652
 	}
653 653
 
654 654
 	/**
@@ -663,9 +663,9 @@  discard block
 block discarded – undo
663 663
 	 * @return string the remote filepath (eg the filepath the filesystem method, eg
664 664
 	 * ftp or ssh, will use to access the folder
665 665
 	 */
666
-	public static function convert_local_filepath_to_remote_filepath( $local_filepath ) {
667
-		$wp_filesystem = EEH_File::_get_wp_filesystem( $local_filepath );
668
-		return str_replace( WP_CONTENT_DIR . DS, $wp_filesystem->wp_content_dir(), $local_filepath );
666
+	public static function convert_local_filepath_to_remote_filepath($local_filepath) {
667
+		$wp_filesystem = EEH_File::_get_wp_filesystem($local_filepath);
668
+		return str_replace(WP_CONTENT_DIR.DS, $wp_filesystem->wp_content_dir(), $local_filepath);
669 669
 	}
670 670
 }
671 671
 // End of file EEH_File.helper.php
Please login to merge, or discard this patch.
core/EE_Registry.core.php 1 patch
Spacing   +209 added lines, -209 removed lines patch added patch discarded remove patch
@@ -184,10 +184,10 @@  discard block
 block discarded – undo
184 184
 	 * @param  \EE_Dependency_Map $dependency_map
185 185
 	 * @return \EE_Registry instance
186 186
 	 */
187
-	public static function instance( \EE_Dependency_Map $dependency_map = null ) {
187
+	public static function instance(\EE_Dependency_Map $dependency_map = null) {
188 188
 		// check if class object is instantiated
189
-		if ( ! self::$_instance instanceof EE_Registry ) {
190
-			self::$_instance = new EE_Registry( $dependency_map );
189
+		if ( ! self::$_instance instanceof EE_Registry) {
190
+			self::$_instance = new EE_Registry($dependency_map);
191 191
 		}
192 192
 		return self::$_instance;
193 193
 	}
@@ -202,9 +202,9 @@  discard block
 block discarded – undo
202 202
 	 * @param  \EE_Dependency_Map $dependency_map
203 203
 	 * @return \EE_Registry
204 204
 	 */
205
-	protected function __construct( \EE_Dependency_Map $dependency_map ) {
205
+	protected function __construct(\EE_Dependency_Map $dependency_map) {
206 206
 		$this->_dependency_map = $dependency_map;
207
-		add_action( 'EE_Load_Espresso_Core__handle_request__initialize_core_loading', array( $this, 'initialize' ) );
207
+		add_action('EE_Load_Espresso_Core__handle_request__initialize_core_loading', array($this, 'initialize'));
208 208
 	}
209 209
 
210 210
 
@@ -232,19 +232,19 @@  discard block
 block discarded – undo
232 232
 		$this->modules = new stdClass();
233 233
 		$this->shortcodes = new stdClass();
234 234
 		$this->widgets = new stdClass();
235
-		$this->load_core( 'Base', array(), true );
235
+		$this->load_core('Base', array(), true);
236 236
 		// add our request and response objects to the cache
237
-		$request_loader = $this->_dependency_map->class_loader( 'EE_Request' );
237
+		$request_loader = $this->_dependency_map->class_loader('EE_Request');
238 238
 		$this->_set_cached_class(
239 239
 			$request_loader(),
240 240
 			'EE_Request'
241 241
 		);
242
-		$response_loader = $this->_dependency_map->class_loader( 'EE_Response' );
242
+		$response_loader = $this->_dependency_map->class_loader('EE_Response');
243 243
 		$this->_set_cached_class(
244 244
 			$response_loader(),
245 245
 			'EE_Response'
246 246
 		);
247
-		add_action( 'AHEE__EE_System__set_hooks_for_core', array( $this, 'init' ) );
247
+		add_action('AHEE__EE_System__set_hooks_for_core', array($this, 'init'));
248 248
 	}
249 249
 
250 250
 
@@ -257,10 +257,10 @@  discard block
 block discarded – undo
257 257
 	 */
258 258
 	public function init() {
259 259
 		// Get current page protocol
260
-		$protocol = isset( $_SERVER[ 'HTTPS' ] ) ? 'https://' : 'http://';
260
+		$protocol = isset($_SERVER['HTTPS']) ? 'https://' : 'http://';
261 261
 		// Output admin-ajax.php URL with same protocol as current page
262
-		self::$i18n_js_strings[ 'ajax_url' ] = admin_url( 'admin-ajax.php', $protocol );
263
-		self::$i18n_js_strings[ 'wp_debug' ] = defined( 'WP_DEBUG' ) ? WP_DEBUG : false;
262
+		self::$i18n_js_strings['ajax_url'] = admin_url('admin-ajax.php', $protocol);
263
+		self::$i18n_js_strings['wp_debug'] = defined('WP_DEBUG') ? WP_DEBUG : false;
264 264
 	}
265 265
 
266 266
 
@@ -271,14 +271,14 @@  discard block
 block discarded – undo
271 271
 	 * @return string
272 272
 	 */
273 273
 	public static function localize_i18n_js_strings() {
274
-		$i18n_js_strings = (array)EE_Registry::$i18n_js_strings;
275
-		foreach ( $i18n_js_strings as $key => $value ) {
276
-			if ( is_scalar( $value ) ) {
277
-				$i18n_js_strings[ $key ] = html_entity_decode( (string)$value, ENT_QUOTES, 'UTF-8' );
274
+		$i18n_js_strings = (array) EE_Registry::$i18n_js_strings;
275
+		foreach ($i18n_js_strings as $key => $value) {
276
+			if (is_scalar($value)) {
277
+				$i18n_js_strings[$key] = html_entity_decode((string) $value, ENT_QUOTES, 'UTF-8');
278 278
 			}
279 279
 		}
280 280
 
281
-		return "/* <![CDATA[ */ var eei18n = " . wp_json_encode( $i18n_js_strings ) . '; /* ]]> */';
281
+		return "/* <![CDATA[ */ var eei18n = ".wp_json_encode($i18n_js_strings).'; /* ]]> */';
282 282
 	}
283 283
 
284 284
 
@@ -286,15 +286,15 @@  discard block
 block discarded – undo
286 286
 	/**
287 287
 	 * @param mixed string | EED_Module $module
288 288
 	 */
289
-	public function add_module( $module ) {
290
-		if ( $module instanceof EED_Module ) {
291
-			$module_class = get_class( $module );
289
+	public function add_module($module) {
290
+		if ($module instanceof EED_Module) {
291
+			$module_class = get_class($module);
292 292
 			$this->modules->{$module_class} = $module;
293 293
 		} else {
294
-			if ( ! class_exists( 'EE_Module_Request_Router' ) ) {
295
-				$this->load_core( 'Module_Request_Router' );
294
+			if ( ! class_exists('EE_Module_Request_Router')) {
295
+				$this->load_core('Module_Request_Router');
296 296
 			}
297
-			$this->modules->{$module} = EE_Module_Request_Router::module_factory( $module );
297
+			$this->modules->{$module} = EE_Module_Request_Router::module_factory($module);
298 298
 		}
299 299
 	}
300 300
 
@@ -304,8 +304,8 @@  discard block
 block discarded – undo
304 304
 	 * @param string $module_name
305 305
 	 * @return mixed EED_Module | NULL
306 306
 	 */
307
-	public function get_module( $module_name = '' ) {
308
-		return isset( $this->modules->{$module_name} ) ? $this->modules->{$module_name} : null;
307
+	public function get_module($module_name = '') {
308
+		return isset($this->modules->{$module_name} ) ? $this->modules->{$module_name} : null;
309 309
 	}
310 310
 
311 311
 
@@ -319,20 +319,20 @@  discard block
 block discarded – undo
319 319
 	 * @param bool $load_only
320 320
 	 * @return mixed
321 321
 	 */
322
-	public function load_core( $class_name, $arguments = array(), $load_only = false ) {
322
+	public function load_core($class_name, $arguments = array(), $load_only = false) {
323 323
 		$core_paths = apply_filters(
324 324
 			'FHEE__EE_Registry__load_core__core_paths',
325 325
 			array(
326 326
 				EE_CORE,
327 327
 				EE_ADMIN,
328 328
 				EE_CPTS,
329
-				EE_CORE . 'data_migration_scripts' . DS,
330
-				EE_CORE . 'request_stack' . DS,
331
-				EE_CORE . 'middleware' . DS,
329
+				EE_CORE.'data_migration_scripts'.DS,
330
+				EE_CORE.'request_stack'.DS,
331
+				EE_CORE.'middleware'.DS,
332 332
 			)
333 333
 		);
334 334
 		// retrieve instantiated class
335
-		return $this->_load( $core_paths, 'EE_', $class_name, 'core', $arguments, false, true, $load_only );
335
+		return $this->_load($core_paths, 'EE_', $class_name, 'core', $arguments, false, true, $load_only);
336 336
 	}
337 337
 
338 338
 
@@ -346,15 +346,15 @@  discard block
 block discarded – undo
346 346
 	 * @param bool $load_only
347 347
 	 * @return mixed
348 348
 	 */
349
-	public function load_service( $class_name, $arguments = array(), $load_only = false ) {
349
+	public function load_service($class_name, $arguments = array(), $load_only = false) {
350 350
 		$service_paths = apply_filters(
351 351
 			'FHEE__EE_Registry__load_service__service_paths',
352 352
 			array(
353
-				EE_CORE . 'services' . DS,
353
+				EE_CORE.'services'.DS,
354 354
 			)
355 355
 		);
356 356
 		// retrieve instantiated class
357
-		return $this->_load( $service_paths, 'EE_', $class_name, 'class', $arguments, false, true, $load_only );
357
+		return $this->_load($service_paths, 'EE_', $class_name, 'class', $arguments, false, true, $load_only);
358 358
 	}
359 359
 
360 360
 
@@ -367,9 +367,9 @@  discard block
 block discarded – undo
367 367
 	 * @param mixed $arguments
368 368
 	 * @return EE_Data_Migration_Script_Base|mixed
369 369
 	 */
370
-	public function load_dms( $class_name, $arguments = array() ) {
370
+	public function load_dms($class_name, $arguments = array()) {
371 371
 		// retrieve instantiated class
372
-		return $this->_load( EE_Data_Migration_Manager::instance()->get_data_migration_script_folders(), 'EE_DMS_', $class_name, 'dms', $arguments, false, false, false );
372
+		return $this->_load(EE_Data_Migration_Manager::instance()->get_data_migration_script_folders(), 'EE_DMS_', $class_name, 'dms', $arguments, false, false, false);
373 373
 	}
374 374
 
375 375
 
@@ -384,14 +384,14 @@  discard block
 block discarded – undo
384 384
 	 * @param bool $load_only whether or not to just load the file and NOT instantiate, or load AND instantiate (default)
385 385
 	 * @return EE_Base_Class | bool
386 386
 	 */
387
-	public function load_class( $class_name, $arguments = array(), $from_db = false, $cache = true, $load_only = false ) {
388
-		$paths = apply_filters( 'FHEE__EE_Registry__load_class__paths', array(
387
+	public function load_class($class_name, $arguments = array(), $from_db = false, $cache = true, $load_only = false) {
388
+		$paths = apply_filters('FHEE__EE_Registry__load_class__paths', array(
389 389
 			EE_CORE,
390 390
 			EE_CLASSES,
391 391
 			EE_BUSINESS
392
-		) );
392
+		));
393 393
 		// retrieve instantiated class
394
-		return $this->_load( $paths, 'EE_', $class_name, 'class', $arguments, $from_db, $cache, $load_only );
394
+		return $this->_load($paths, 'EE_', $class_name, 'class', $arguments, $from_db, $cache, $load_only);
395 395
 	}
396 396
 
397 397
 
@@ -404,11 +404,11 @@  discard block
 block discarded – undo
404 404
 	 * @param bool $load_only
405 405
 	 * @return EEH_Base | bool
406 406
 	 */
407
-	public function load_helper( $class_name, $arguments = array(), $load_only = true ) {
407
+	public function load_helper($class_name, $arguments = array(), $load_only = true) {
408 408
 		// todo: add doing_it_wrong() in a few versions after all addons have had calls to this method removed
409
-		$helper_paths = apply_filters( 'FHEE__EE_Registry__load_helper__helper_paths', array( EE_HELPERS ) );
409
+		$helper_paths = apply_filters('FHEE__EE_Registry__load_helper__helper_paths', array(EE_HELPERS));
410 410
 		// retrieve instantiated class
411
-		return $this->_load( $helper_paths, 'EEH_', $class_name, 'helper', $arguments, false, true, $load_only );
411
+		return $this->_load($helper_paths, 'EEH_', $class_name, 'helper', $arguments, false, true, $load_only);
412 412
 	}
413 413
 
414 414
 
@@ -423,16 +423,16 @@  discard block
 block discarded – undo
423 423
 	 * @param bool $cache  whether to cache the object or not.
424 424
 	 * @return mixed
425 425
 	 */
426
-	public function load_lib( $class_name, $arguments = array(), $load_only = false, $cache = true ) {
426
+	public function load_lib($class_name, $arguments = array(), $load_only = false, $cache = true) {
427 427
 		$paths = array(
428 428
 			EE_LIBRARIES,
429
-			EE_LIBRARIES . 'messages' . DS,
430
-			EE_LIBRARIES . 'shortcodes' . DS,
431
-			EE_LIBRARIES . 'qtips' . DS,
432
-			EE_LIBRARIES . 'payment_methods' . DS,
429
+			EE_LIBRARIES.'messages'.DS,
430
+			EE_LIBRARIES.'shortcodes'.DS,
431
+			EE_LIBRARIES.'qtips'.DS,
432
+			EE_LIBRARIES.'payment_methods'.DS,
433 433
 		);
434 434
 		// retrieve instantiated class
435
-		return $this->_load( $paths, 'EE_', $class_name, 'lib', $arguments, false, $cache, $load_only );
435
+		return $this->_load($paths, 'EE_', $class_name, 'lib', $arguments, false, $cache, $load_only);
436 436
 	}
437 437
 
438 438
 
@@ -445,13 +445,13 @@  discard block
 block discarded – undo
445 445
 	 * @param bool $load_only
446 446
 	 * @return EEM_Base | bool
447 447
 	 */
448
-	public function load_model( $class_name, $arguments = array(), $load_only = false ) {
449
-		$paths = apply_filters( 'FHEE__EE_Registry__load_model__paths', array(
448
+	public function load_model($class_name, $arguments = array(), $load_only = false) {
449
+		$paths = apply_filters('FHEE__EE_Registry__load_model__paths', array(
450 450
 			EE_MODELS,
451 451
 			EE_CORE
452
-		) );
452
+		));
453 453
 		// retrieve instantiated class
454
-		return $this->_load( $paths, 'EEM_', $class_name, 'model', $arguments, false, true, $load_only );
454
+		return $this->_load($paths, 'EEM_', $class_name, 'model', $arguments, false, true, $load_only);
455 455
 	}
456 456
 
457 457
 
@@ -464,15 +464,15 @@  discard block
 block discarded – undo
464 464
 	 * @param bool $load_only
465 465
 	 * @return mixed | bool
466 466
 	 */
467
-	public function load_model_class( $class_name, $arguments = array(), $load_only = true ) {
467
+	public function load_model_class($class_name, $arguments = array(), $load_only = true) {
468 468
 		$paths = array(
469
-			EE_MODELS . 'fields' . DS,
470
-			EE_MODELS . 'helpers' . DS,
471
-			EE_MODELS . 'relations' . DS,
472
-			EE_MODELS . 'strategies' . DS
469
+			EE_MODELS.'fields'.DS,
470
+			EE_MODELS.'helpers'.DS,
471
+			EE_MODELS.'relations'.DS,
472
+			EE_MODELS.'strategies'.DS
473 473
 		);
474 474
 		// retrieve instantiated class
475
-		return $this->_load( $paths, 'EE_', $class_name, '', $arguments, false, true, $load_only );
475
+		return $this->_load($paths, 'EE_', $class_name, '', $arguments, false, true, $load_only);
476 476
 	}
477 477
 
478 478
 
@@ -482,8 +482,8 @@  discard block
 block discarded – undo
482 482
 	 * @param string $model_name like Event, Attendee, Question_Group_Question, etc.
483 483
 	 * @return boolean
484 484
 	 */
485
-	public function is_model_name( $model_name ) {
486
-		return isset( $this->models[ $model_name ] ) ? true : false;
485
+	public function is_model_name($model_name) {
486
+		return isset($this->models[$model_name]) ? true : false;
487 487
 	}
488 488
 
489 489
 
@@ -498,9 +498,9 @@  discard block
 block discarded – undo
498 498
 	 * @param bool $load_only
499 499
 	 * @return mixed
500 500
 	 */
501
-	public function load_file( $path_to_file, $file_name, $type = '', $arguments = array(), $load_only = true ) {
501
+	public function load_file($path_to_file, $file_name, $type = '', $arguments = array(), $load_only = true) {
502 502
 		// retrieve instantiated class
503
-		return $this->_load( $path_to_file, '', $file_name, $type, $arguments, false, true, $load_only );
503
+		return $this->_load($path_to_file, '', $file_name, $type, $arguments, false, true, $load_only);
504 504
 	}
505 505
 
506 506
 
@@ -515,9 +515,9 @@  discard block
 block discarded – undo
515 515
 	 * @param bool $load_only
516 516
 	 * @return EE_Addon
517 517
 	 */
518
-	public function load_addon( $path_to_file, $class_name, $type = 'class', $arguments = array(), $load_only = false ) {
518
+	public function load_addon($path_to_file, $class_name, $type = 'class', $arguments = array(), $load_only = false) {
519 519
 		// retrieve instantiated class
520
-		return $this->_load( $path_to_file, 'addon', $class_name, $type, $arguments, false, true, $load_only );
520
+		return $this->_load($path_to_file, 'addon', $class_name, $type, $arguments, false, true, $load_only);
521 521
 	}
522 522
 
523 523
 
@@ -548,35 +548,35 @@  discard block
 block discarded – undo
548 548
 		$load_only = false,
549 549
 		$addon = false
550 550
 	) {
551
-		$class_name = $this->_dependency_map->get_alias( $class_name );
552
-		if ( ! class_exists( $class_name ) ) {
551
+		$class_name = $this->_dependency_map->get_alias($class_name);
552
+		if ( ! class_exists($class_name)) {
553 553
 			// maybe the class is registered with a preceding \
554
-			$class_name = strpos( $class_name, '\\' ) !== 0 ? '\\' . $class_name : $class_name;
554
+			$class_name = strpos($class_name, '\\') !== 0 ? '\\'.$class_name : $class_name;
555 555
 			// still doesn't exist ?
556
-			if ( ! class_exists( $class_name ) ) {
556
+			if ( ! class_exists($class_name)) {
557 557
 				return null;
558 558
 			}
559 559
 		}
560 560
 		// if we're only loading the class and it already exists, then let's just return true immediately
561
-		if ( $load_only ) {
561
+		if ($load_only) {
562 562
 			return true;
563 563
 		}
564 564
 		$addon = $addon ? 'addon' : '';
565 565
 		// $this->_cache_on is toggled during the recursive loading that can occur with dependency injection
566 566
 		// $cache is controlled by individual calls to separate Registry loader methods like load_class()
567 567
 		// $load_only is also controlled by individual calls to separate Registry loader methods like load_file()
568
-		if ( $this->_cache_on && $cache && ! $load_only ) {
568
+		if ($this->_cache_on && $cache && ! $load_only) {
569 569
 			// return object if it's already cached
570
-			$cached_class = $this->_get_cached_class( $class_name, $addon );
571
-			if ( $cached_class !== null ) {
570
+			$cached_class = $this->_get_cached_class($class_name, $addon);
571
+			if ($cached_class !== null) {
572 572
 				return $cached_class;
573 573
 			}
574 574
 		}
575 575
 		// instantiate the requested object
576
-		$class_obj = $this->_create_object( $class_name, $arguments, $addon, $from_db );
577
-		if ( $this->_cache_on && $cache ) {
576
+		$class_obj = $this->_create_object($class_name, $arguments, $addon, $from_db);
577
+		if ($this->_cache_on && $cache) {
578 578
 			// save it for later... kinda like gum  { : $
579
-			$this->_set_cached_class( $class_obj, $class_name, $addon, $from_db );
579
+			$this->_set_cached_class($class_obj, $class_name, $addon, $from_db);
580 580
 		}
581 581
 		$this->_cache_on = true;
582 582
 		return $class_obj;
@@ -611,47 +611,47 @@  discard block
 block discarded – undo
611 611
 		$load_only = false
612 612
 	) {
613 613
 		// strip php file extension
614
-		$class_name = str_replace( '.php', '', trim( $class_name ) );
614
+		$class_name = str_replace('.php', '', trim($class_name));
615 615
 		// does the class have a prefix ?
616
-		if ( ! empty( $class_prefix ) && $class_prefix != 'addon' ) {
616
+		if ( ! empty($class_prefix) && $class_prefix != 'addon') {
617 617
 			// make sure $class_prefix is uppercase
618
-			$class_prefix = strtoupper( trim( $class_prefix ) );
618
+			$class_prefix = strtoupper(trim($class_prefix));
619 619
 			// add class prefix ONCE!!!
620
-			$class_name = $class_prefix . str_replace( $class_prefix, '', $class_name );
620
+			$class_name = $class_prefix.str_replace($class_prefix, '', $class_name);
621 621
 		}
622
-		$class_name = $this->_dependency_map->get_alias( $class_name );
623
-		$class_exists = class_exists( $class_name );
622
+		$class_name = $this->_dependency_map->get_alias($class_name);
623
+		$class_exists = class_exists($class_name);
624 624
 		// if we're only loading the class and it already exists, then let's just return true immediately
625
-		if ( $load_only && $class_exists ) {
625
+		if ($load_only && $class_exists) {
626 626
 			return true;
627 627
 		}
628 628
 		// $this->_cache_on is toggled during the recursive loading that can occur with dependency injection
629 629
 		// $cache is controlled by individual calls to separate Registry loader methods like load_class()
630 630
 		// $load_only is also controlled by individual calls to separate Registry loader methods like load_file()
631
-		if ( $this->_cache_on && $cache && ! $load_only ) {
631
+		if ($this->_cache_on && $cache && ! $load_only) {
632 632
 			// return object if it's already cached
633
-			$cached_class = $this->_get_cached_class( $class_name, $class_prefix );
634
-			if ( $cached_class !== null ) {
633
+			$cached_class = $this->_get_cached_class($class_name, $class_prefix);
634
+			if ($cached_class !== null) {
635 635
 				return $cached_class;
636 636
 			}
637 637
 		}
638 638
 		// if the class doesn't already exist.. then we need to try and find the file and load it
639
-		if ( ! $class_exists ) {
639
+		if ( ! $class_exists) {
640 640
 			// get full path to file
641
-			$path = $this->_resolve_path( $class_name, $type, $file_paths );
641
+			$path = $this->_resolve_path($class_name, $type, $file_paths);
642 642
 			// load the file
643
-			$loaded = $this->_require_file( $path, $class_name, $type, $file_paths );
643
+			$loaded = $this->_require_file($path, $class_name, $type, $file_paths);
644 644
 			// if loading failed, or we are only loading a file but NOT instantiating an object
645
-			if ( ! $loaded || $load_only ) {
645
+			if ( ! $loaded || $load_only) {
646 646
 				// return boolean if only loading, or null if an object was expected
647 647
 				return $load_only ? $loaded : null;
648 648
 			}
649 649
 		}
650 650
 		// instantiate the requested object
651
-		$class_obj = $this->_create_object( $class_name, $arguments, $type, $from_db );
652
-		if ( $this->_cache_on && $cache ) {
651
+		$class_obj = $this->_create_object($class_name, $arguments, $type, $from_db);
652
+		if ($this->_cache_on && $cache) {
653 653
 			// save it for later... kinda like gum  { : $
654
-			$this->_set_cached_class( $class_obj, $class_name, $class_prefix, $from_db );
654
+			$this->_set_cached_class($class_obj, $class_name, $class_prefix, $from_db);
655 655
 		}
656 656
 		$this->_cache_on = true;
657 657
 		return $class_obj;
@@ -674,21 +674,21 @@  discard block
 block discarded – undo
674 674
 	 * @param string $class_prefix
675 675
 	 * @return mixed
676 676
 	 */
677
-	protected function _get_cached_class( $class_name, $class_prefix = '' ) {
678
-		if ( isset( $this->_class_abbreviations[ $class_name ] ) ) {
679
-			$class_abbreviation = $this->_class_abbreviations[ $class_name ];
677
+	protected function _get_cached_class($class_name, $class_prefix = '') {
678
+		if (isset($this->_class_abbreviations[$class_name])) {
679
+			$class_abbreviation = $this->_class_abbreviations[$class_name];
680 680
 		} else {
681 681
 			// have to specify something, but not anything that will conflict
682 682
 			$class_abbreviation = 'FANCY_BATMAN_PANTS';
683 683
 		}
684 684
 		// check if class has already been loaded, and return it if it has been
685
-		if ( isset( $this->{$class_abbreviation} ) && ! is_null( $this->{$class_abbreviation} ) ) {
685
+		if (isset($this->{$class_abbreviation} ) && ! is_null($this->{$class_abbreviation} )) {
686 686
 			return $this->{$class_abbreviation};
687
-		} else if ( isset ( $this->{$class_name} ) ) {
687
+		} else if (isset ($this->{$class_name} )) {
688 688
 			return $this->{$class_name};
689
-		} else if ( isset ( $this->LIB->{$class_name} ) ) {
689
+		} else if (isset ($this->LIB->{$class_name} )) {
690 690
 			return $this->LIB->{$class_name};
691
-		} else if ( $class_prefix == 'addon' && isset ( $this->addons->{$class_name} ) ) {
691
+		} else if ($class_prefix == 'addon' && isset ($this->addons->{$class_name} )) {
692 692
 			return $this->addons->{$class_name};
693 693
 		}
694 694
 		return null;
@@ -709,20 +709,20 @@  discard block
 block discarded – undo
709 709
 	 * @param array $file_paths
710 710
 	 * @return string | bool
711 711
 	 */
712
-	protected function _resolve_path( $class_name, $type = '', $file_paths = array() ) {
712
+	protected function _resolve_path($class_name, $type = '', $file_paths = array()) {
713 713
 		// make sure $file_paths is an array
714
-		$file_paths = is_array( $file_paths ) ? $file_paths : array( $file_paths );
714
+		$file_paths = is_array($file_paths) ? $file_paths : array($file_paths);
715 715
 		// cycle thru paths
716
-		foreach ( $file_paths as $key => $file_path ) {
716
+		foreach ($file_paths as $key => $file_path) {
717 717
 			// convert all separators to proper DS, if no filepath, then use EE_CLASSES
718
-			$file_path = $file_path ? str_replace( array( '/', '\\' ), DS, $file_path ) : EE_CLASSES;
718
+			$file_path = $file_path ? str_replace(array('/', '\\'), DS, $file_path) : EE_CLASSES;
719 719
 			// prep file type
720
-			$type = ! empty( $type ) ? trim( $type, '.' ) . '.' : '';
720
+			$type = ! empty($type) ? trim($type, '.').'.' : '';
721 721
 			// build full file path
722
-			$file_paths[ $key ] = rtrim( $file_path, DS ) . DS . $class_name . '.' . $type . 'php';
722
+			$file_paths[$key] = rtrim($file_path, DS).DS.$class_name.'.'.$type.'php';
723 723
 			//does the file exist and can be read ?
724
-			if ( is_readable( $file_paths[ $key ] ) ) {
725
-				return $file_paths[ $key ];
724
+			if (is_readable($file_paths[$key])) {
725
+				return $file_paths[$key];
726 726
 			}
727 727
 		}
728 728
 		return false;
@@ -744,29 +744,29 @@  discard block
 block discarded – undo
744 744
 	 * @return boolean
745 745
 	 * @throws \EE_Error
746 746
 	 */
747
-	protected function _require_file( $path, $class_name, $type = '', $file_paths = array() ) {
747
+	protected function _require_file($path, $class_name, $type = '', $file_paths = array()) {
748 748
 		// don't give up! you gotta...
749 749
 		try {
750 750
 			//does the file exist and can it be read ?
751
-			if ( ! $path ) {
751
+			if ( ! $path) {
752 752
 				// so sorry, can't find the file
753
-				throw new EE_Error (
753
+				throw new EE_Error(
754 754
 					sprintf(
755
-						__( 'The %1$s file %2$s could not be located or is not readable due to file permissions. Please ensure that the following filepath(s) are correct: %3$s', 'event_espresso' ),
756
-						trim( $type, '.' ),
755
+						__('The %1$s file %2$s could not be located or is not readable due to file permissions. Please ensure that the following filepath(s) are correct: %3$s', 'event_espresso'),
756
+						trim($type, '.'),
757 757
 						$class_name,
758
-						'<br />' . implode( ',<br />', $file_paths )
758
+						'<br />'.implode(',<br />', $file_paths)
759 759
 					)
760 760
 				);
761 761
 			}
762 762
 			// get the file
763
-			require_once( $path );
763
+			require_once($path);
764 764
 			// if the class isn't already declared somewhere
765
-			if ( class_exists( $class_name, false ) === false ) {
765
+			if (class_exists($class_name, false) === false) {
766 766
 				// so sorry, not a class
767 767
 				throw new EE_Error(
768 768
 					sprintf(
769
-						__( 'The %s file %s does not appear to contain the %s Class.', 'event_espresso' ),
769
+						__('The %s file %s does not appear to contain the %s Class.', 'event_espresso'),
770 770
 						$type,
771 771
 						$path,
772 772
 						$class_name
@@ -774,7 +774,7 @@  discard block
 block discarded – undo
774 774
 				);
775 775
 			}
776 776
 
777
-		} catch ( EE_Error $e ) {
777
+		} catch (EE_Error $e) {
778 778
 			$e->get_error();
779 779
 			return false;
780 780
 		}
@@ -806,61 +806,61 @@  discard block
 block discarded – undo
806 806
 	 * @return null | object
807 807
 	 * @throws \EE_Error
808 808
 	 */
809
-	protected function _create_object( $class_name, $arguments = array(), $type = '', $from_db = false ) {
809
+	protected function _create_object($class_name, $arguments = array(), $type = '', $from_db = false) {
810 810
 		$class_obj = null;
811 811
 		$instantiation_mode = '0) none';
812 812
 		// don't give up! you gotta...
813 813
 		try {
814 814
 			// create reflection
815
-			$reflector = $this->get_ReflectionClass( $class_name );
815
+			$reflector = $this->get_ReflectionClass($class_name);
816 816
 			// make sure arguments are an array
817
-			$arguments = is_array( $arguments ) ? $arguments : array( $arguments );
817
+			$arguments = is_array($arguments) ? $arguments : array($arguments);
818 818
 			// and if arguments array is numerically and sequentially indexed, then we want it to remain as is,
819 819
 			// else wrap it in an additional array so that it doesn't get split into multiple parameters
820
-			$arguments = $this->_array_is_numerically_and_sequentially_indexed( $arguments )
820
+			$arguments = $this->_array_is_numerically_and_sequentially_indexed($arguments)
821 821
 				? $arguments
822
-				: array( $arguments );
822
+				: array($arguments);
823 823
 			// attempt to inject dependencies ?
824
-			if ( $this->_dependency_map->has( $class_name ) ) {
825
-				$arguments = $this->_resolve_dependencies( $reflector, $class_name, $arguments );
824
+			if ($this->_dependency_map->has($class_name)) {
825
+				$arguments = $this->_resolve_dependencies($reflector, $class_name, $arguments);
826 826
 			}
827 827
 			// instantiate the class if possible
828
-			if ( $reflector->isAbstract() ) {
828
+			if ($reflector->isAbstract()) {
829 829
 				// nothing to instantiate, loading file was enough
830 830
 				// does not throw an exception so $instantiation_mode is unused
831 831
 				// $instantiation_mode = "1) no constructor abstract class";
832 832
 				$class_obj = true;
833
-			} else if ( $reflector->getConstructor() === null && $reflector->isInstantiable() && empty( $arguments ) ) {
833
+			} else if ($reflector->getConstructor() === null && $reflector->isInstantiable() && empty($arguments)) {
834 834
 				// no constructor = static methods only... nothing to instantiate, loading file was enough
835 835
 				$instantiation_mode = "2) no constructor but instantiable";
836 836
 				$class_obj = $reflector->newInstance();
837
-			} else if ( $from_db && method_exists( $class_name, 'new_instance_from_db' ) ) {
837
+			} else if ($from_db && method_exists($class_name, 'new_instance_from_db')) {
838 838
 				$instantiation_mode = "3) new_instance_from_db()";
839
-				$class_obj = call_user_func_array( array( $class_name, 'new_instance_from_db' ), $arguments );
840
-			} else if ( method_exists( $class_name, 'new_instance' ) ) {
839
+				$class_obj = call_user_func_array(array($class_name, 'new_instance_from_db'), $arguments);
840
+			} else if (method_exists($class_name, 'new_instance')) {
841 841
 				$instantiation_mode = "4) new_instance()";
842
-				$class_obj = call_user_func_array( array( $class_name, 'new_instance' ), $arguments );
843
-			} else if ( method_exists( $class_name, 'instance' ) ) {
842
+				$class_obj = call_user_func_array(array($class_name, 'new_instance'), $arguments);
843
+			} else if (method_exists($class_name, 'instance')) {
844 844
 				$instantiation_mode = "5) instance()";
845
-				$class_obj = call_user_func_array( array( $class_name, 'instance' ), $arguments );
846
-			} else if ( $reflector->isInstantiable() ) {
845
+				$class_obj = call_user_func_array(array($class_name, 'instance'), $arguments);
846
+			} else if ($reflector->isInstantiable()) {
847 847
 				$instantiation_mode = "6) constructor";
848
-				$class_obj = $reflector->newInstanceArgs( $arguments );
848
+				$class_obj = $reflector->newInstanceArgs($arguments);
849 849
 			} else {
850 850
 				// heh ? something's not right !
851 851
 				throw new EE_Error(
852 852
 					sprintf(
853
-						__( 'The %s file %s could not be instantiated.', 'event_espresso' ),
853
+						__('The %s file %s could not be instantiated.', 'event_espresso'),
854 854
 						$type,
855 855
 						$class_name
856 856
 					)
857 857
 				);
858 858
 			}
859
-		} catch ( Exception $e ) {
860
-			if ( ! $e instanceof EE_Error ) {
859
+		} catch (Exception $e) {
860
+			if ( ! $e instanceof EE_Error) {
861 861
 				$e = new EE_Error(
862 862
 					sprintf(
863
-						__( 'The following error occurred while attempting to instantiate "%1$s": %2$s %3$s %2$s instantiation mode : %4$s', 'event_espresso' ),
863
+						__('The following error occurred while attempting to instantiate "%1$s": %2$s %3$s %2$s instantiation mode : %4$s', 'event_espresso'),
864 864
 						$class_name,
865 865
 						'<br />',
866 866
 						$e->getMessage(),
@@ -880,8 +880,8 @@  discard block
 block discarded – undo
880 880
 	 * @param array $array
881 881
 	 * @return bool
882 882
 	 */
883
-	protected function _array_is_numerically_and_sequentially_indexed( array $array ) {
884
-		return ! empty( $array ) ? array_keys( $array ) === range( 0, count( $array ) - 1 ) : true;
883
+	protected function _array_is_numerically_and_sequentially_indexed(array $array) {
884
+		return ! empty($array) ? array_keys($array) === range(0, count($array) - 1) : true;
885 885
 	}
886 886
 
887 887
 
@@ -896,14 +896,14 @@  discard block
 block discarded – undo
896 896
 	 * @param string $class_name
897 897
 	 * @return ReflectionClass
898 898
 	 */
899
-	public function get_ReflectionClass( $class_name ) {
899
+	public function get_ReflectionClass($class_name) {
900 900
 		if (
901
-			! isset( $this->_reflectors[ $class_name ] )
902
-			|| ! $this->_reflectors[ $class_name ] instanceof ReflectionClass
901
+			! isset($this->_reflectors[$class_name])
902
+			|| ! $this->_reflectors[$class_name] instanceof ReflectionClass
903 903
 		) {
904
-			$this->_reflectors[ $class_name ] = new ReflectionClass( $class_name );
904
+			$this->_reflectors[$class_name] = new ReflectionClass($class_name);
905 905
 		}
906
-		return $this->_reflectors[ $class_name ];
906
+		return $this->_reflectors[$class_name];
907 907
 	}
908 908
 
909 909
 
@@ -928,50 +928,50 @@  discard block
 block discarded – undo
928 928
 	 * @return array
929 929
 	 * @throws \ReflectionException
930 930
 	 */
931
-	protected function _resolve_dependencies( ReflectionClass $reflector, $class_name, $arguments = array() ) {
931
+	protected function _resolve_dependencies(ReflectionClass $reflector, $class_name, $arguments = array()) {
932 932
 		// let's examine the constructor
933 933
 		$constructor = $reflector->getConstructor();
934 934
 		// whu? huh? nothing?
935
-		if ( ! $constructor ) {
935
+		if ( ! $constructor) {
936 936
 			return $arguments;
937 937
 		}
938 938
 		// get constructor parameters
939 939
 		$params = $constructor->getParameters();
940 940
 		// and the keys for the incoming arguments array so that we can compare existing arguments with what is expected
941
-		$argument_keys = array_keys( $arguments );
941
+		$argument_keys = array_keys($arguments);
942 942
 		// now loop thru all of the constructors expected parameters
943
-		foreach ( $params as $index => $param ) {
943
+		foreach ($params as $index => $param) {
944 944
 			// is this a dependency for a specific class ?
945 945
 			$param_class = $param->getClass() ? $param->getClass()->name : null;
946 946
 			if (
947 947
 				// param is not even a class
948
-				empty( $param_class )
948
+				empty($param_class)
949 949
 				// and something already exists in the incoming arguments for this param
950
-				&& isset( $argument_keys[ $index ], $arguments[ $argument_keys[ $index ] ] )
950
+				&& isset($argument_keys[$index], $arguments[$argument_keys[$index]])
951 951
 			) {
952 952
 				// so let's skip this argument and move on to the next
953 953
 				continue;
954 954
 			} else if (
955 955
 				// parameter is type hinted as a class, exists as an incoming argument, AND it's the correct class
956
-				! empty( $param_class )
957
-				&& isset( $argument_keys[ $index ], $arguments[ $argument_keys[ $index ] ] )
958
-				&& $arguments[ $argument_keys[ $index ] ] instanceof $param_class
956
+				! empty($param_class)
957
+				&& isset($argument_keys[$index], $arguments[$argument_keys[$index]])
958
+				&& $arguments[$argument_keys[$index]] instanceof $param_class
959 959
 			) {
960 960
 				// skip this argument and move on to the next
961 961
 				continue;
962 962
 			} else if (
963 963
 				// parameter is type hinted as a class, and should be injected
964
-				! empty( $param_class )
965
-				&& $this->_dependency_map->has_dependency_for_class( $class_name, $param_class )
964
+				! empty($param_class)
965
+				&& $this->_dependency_map->has_dependency_for_class($class_name, $param_class)
966 966
 			) {
967
-				$arguments = $this->_resolve_dependency( $class_name, $param_class, $arguments, $index );
967
+				$arguments = $this->_resolve_dependency($class_name, $param_class, $arguments, $index);
968 968
 			} else {
969 969
 				try {
970
-					$arguments[ $index ] = $param->getDefaultValue();
971
-				} catch ( ReflectionException $e ) {
970
+					$arguments[$index] = $param->getDefaultValue();
971
+				} catch (ReflectionException $e) {
972 972
 					throw new ReflectionException(
973 973
 						sprintf(
974
-							__( '%1$s for parameter "$%2$s"', 'event_espresso' ),
974
+							__('%1$s for parameter "$%2$s"', 'event_espresso'),
975 975
 							$e->getMessage(),
976 976
 							$param->getName()
977 977
 						)
@@ -993,30 +993,30 @@  discard block
 block discarded – undo
993 993
 	 * @param mixed $index
994 994
 	 * @return array
995 995
 	 */
996
-	protected function _resolve_dependency( $class_name, $param_class , $arguments, $index ) {
996
+	protected function _resolve_dependency($class_name, $param_class, $arguments, $index) {
997 997
 		$dependency = null;
998 998
 		// should dependency be loaded from cache ?
999
-		$cache_on = $this->_dependency_map->loading_strategy_for_class_dependency( $class_name, $param_class )
999
+		$cache_on = $this->_dependency_map->loading_strategy_for_class_dependency($class_name, $param_class)
1000 1000
 		            !== EE_Dependency_Map::load_new_object
1001 1001
 			? true
1002 1002
 			: false;
1003 1003
 		// we might have a dependency...
1004 1004
 		// let's MAYBE try and find it in our cache if that's what's been requested
1005
-		$cached_class = $cache_on ? $this->_get_cached_class( $param_class ) : null;
1005
+		$cached_class = $cache_on ? $this->_get_cached_class($param_class) : null;
1006 1006
 		// and grab it if it exists
1007
-		if ( $cached_class instanceof $param_class ) {
1007
+		if ($cached_class instanceof $param_class) {
1008 1008
 			$dependency = $cached_class;
1009
-		} else if ( $param_class != $class_name ) {
1009
+		} else if ($param_class != $class_name) {
1010 1010
 			// obtain the loader method from the dependency map
1011
-			$loader = $this->_dependency_map->class_loader( $param_class );
1011
+			$loader = $this->_dependency_map->class_loader($param_class);
1012 1012
 			// is loader a custom closure ?
1013
-			if ( $loader instanceof Closure ) {
1013
+			if ($loader instanceof Closure) {
1014 1014
 				$dependency = $loader();
1015 1015
 			} else {
1016 1016
 				// set the cache on property for the recursive loading call
1017 1017
 				$this->_cache_on = $cache_on;
1018 1018
 				// if not, then let's try and load it via the registry
1019
-				if ( method_exists( $this, $loader ) ) {
1019
+				if (method_exists($this, $loader)) {
1020 1020
 					$dependency = $this->{$loader}($param_class);
1021 1021
 				} else {
1022 1022
 					$dependency = $this->create($param_class, array(), $cache_on);
@@ -1024,12 +1024,12 @@  discard block
 block discarded – undo
1024 1024
 			}
1025 1025
 		}
1026 1026
 		// did we successfully find the correct dependency ?
1027
-		if ( $dependency instanceof $param_class ) {
1027
+		if ($dependency instanceof $param_class) {
1028 1028
 			// then let's inject it into the incoming array of arguments at the correct location
1029
-			if ( isset( $argument_keys[ $index ] ) ) {
1030
-				$arguments[ $argument_keys[ $index ] ] = $dependency;
1029
+			if (isset($argument_keys[$index])) {
1030
+				$arguments[$argument_keys[$index]] = $dependency;
1031 1031
 			} else {
1032
-				$arguments[ $index ] = $dependency;
1032
+				$arguments[$index] = $dependency;
1033 1033
 			}
1034 1034
 		}
1035 1035
 		return $arguments;
@@ -1054,19 +1054,19 @@  discard block
 block discarded – undo
1054 1054
 	 * @param bool $from_db
1055 1055
 	 * @return void
1056 1056
 	 */
1057
-	protected function _set_cached_class( $class_obj, $class_name, $class_prefix = '', $from_db = false ) {
1058
-		if ( empty( $class_obj ) ) {
1057
+	protected function _set_cached_class($class_obj, $class_name, $class_prefix = '', $from_db = false) {
1058
+		if (empty($class_obj)) {
1059 1059
 			return;
1060 1060
 		}
1061 1061
 		// return newly instantiated class
1062
-		if ( isset( $this->_class_abbreviations[ $class_name ] ) ) {
1063
-			$class_abbreviation = $this->_class_abbreviations[ $class_name ];
1062
+		if (isset($this->_class_abbreviations[$class_name])) {
1063
+			$class_abbreviation = $this->_class_abbreviations[$class_name];
1064 1064
 			$this->{$class_abbreviation} = $class_obj;
1065
-		} else if ( property_exists( $this, $class_name ) ) {
1065
+		} else if (property_exists($this, $class_name)) {
1066 1066
 			$this->{$class_name} = $class_obj;
1067
-		} else if ( $class_prefix == 'addon' ) {
1067
+		} else if ($class_prefix == 'addon') {
1068 1068
 			$this->addons->{$class_name} = $class_obj;
1069
-		} else if ( ! $from_db ) {
1069
+		} else if ( ! $from_db) {
1070 1070
 			$this->LIB->{$class_name} = $class_obj;
1071 1071
 		}
1072 1072
 	}
@@ -1083,12 +1083,12 @@  discard block
 block discarded – undo
1083 1083
 	 * @param array  $arguments
1084 1084
 	 * @return object
1085 1085
 	 */
1086
-	public static function factory( $classname, $arguments = array() ) {
1087
-		$loader = self::instance()->_dependency_map->class_loader( $classname );
1088
-		if ( $loader instanceof Closure ) {
1089
-			return $loader( $arguments );
1090
-		} else if ( method_exists( EE_Registry::instance(), $loader ) ) {
1091
-			return EE_Registry::instance()->{$loader}( $classname, $arguments );
1086
+	public static function factory($classname, $arguments = array()) {
1087
+		$loader = self::instance()->_dependency_map->class_loader($classname);
1088
+		if ($loader instanceof Closure) {
1089
+			return $loader($arguments);
1090
+		} else if (method_exists(EE_Registry::instance(), $loader)) {
1091
+			return EE_Registry::instance()->{$loader}($classname, $arguments);
1092 1092
 		}
1093 1093
 		return null;
1094 1094
 	}
@@ -1101,9 +1101,9 @@  discard block
 block discarded – undo
1101 1101
 	 * @param string $name
1102 1102
 	 * @return EE_Addon
1103 1103
 	 */
1104
-	public function get_addon_by_name( $name ) {
1105
-		foreach ( $this->addons as $addon ) {
1106
-			if ( $addon->name() == $name ) {
1104
+	public function get_addon_by_name($name) {
1105
+		foreach ($this->addons as $addon) {
1106
+			if ($addon->name() == $name) {
1107 1107
 				return $addon;
1108 1108
 			}
1109 1109
 		}
@@ -1119,8 +1119,8 @@  discard block
 block discarded – undo
1119 1119
 	 */
1120 1120
 	public function get_addons_by_name() {
1121 1121
 		$addons = array();
1122
-		foreach ( $this->addons as $addon ) {
1123
-			$addons[ $addon->name() ] = $addon;
1122
+		foreach ($this->addons as $addon) {
1123
+			$addons[$addon->name()] = $addon;
1124 1124
 		}
1125 1125
 		return $addons;
1126 1126
 	}
@@ -1135,16 +1135,16 @@  discard block
 block discarded – undo
1135 1135
 	 * @return \EEM_Base
1136 1136
 	 * @throws \EE_Error
1137 1137
 	 */
1138
-	public function reset_model( $model_name ) {
1139
-		$model_class_name = strpos( $model_name, 'EEM_' ) !== 0 ? "EEM_{$model_name}" : $model_name;
1140
-		if( ! isset( $this->LIB->{$model_class_name} ) || ! $this->LIB->{$model_class_name} instanceof EEM_Base ) {
1138
+	public function reset_model($model_name) {
1139
+		$model_class_name = strpos($model_name, 'EEM_') !== 0 ? "EEM_{$model_name}" : $model_name;
1140
+		if ( ! isset($this->LIB->{$model_class_name} ) || ! $this->LIB->{$model_class_name} instanceof EEM_Base) {
1141 1141
 			return null;
1142 1142
 		}
1143 1143
 		//get that model reset it and make sure we nuke the old reference to it
1144
-		if ( $this->LIB->{$model_class_name} instanceof $model_class_name && is_callable( array( $model_class_name, 'reset' ))) {
1144
+		if ($this->LIB->{$model_class_name} instanceof $model_class_name && is_callable(array($model_class_name, 'reset'))) {
1145 1145
 			$this->LIB->{$model_class_name} = $this->LIB->{$model_class_name}->reset();
1146 1146
 		} else {
1147
-			throw new EE_Error( sprintf( __( 'Model %s does not have a method "reset"', 'event_espresso' ), $model_name ) );
1147
+			throw new EE_Error(sprintf(__('Model %s does not have a method "reset"', 'event_espresso'), $model_name));
1148 1148
 		}
1149 1149
 		return $this->LIB->{$model_class_name};
1150 1150
 	}
@@ -1181,13 +1181,13 @@  discard block
 block discarded – undo
1181 1181
 	 *
1182 1182
 	 * @return EE_Registry
1183 1183
 	 */
1184
-	public static function reset( $hard = false, $reinstantiate = true, $reset_models = true ) {
1184
+	public static function reset($hard = false, $reinstantiate = true, $reset_models = true) {
1185 1185
 		$instance = self::instance();
1186 1186
 		EEH_Activation::reset();
1187 1187
 
1188 1188
 		//properties that get reset
1189 1189
 		$instance->_cache_on = true;
1190
-		$instance->CFG = EE_Config::reset( $hard, $reinstantiate );
1190
+		$instance->CFG = EE_Config::reset($hard, $reinstantiate);
1191 1191
 		$instance->CART = null;
1192 1192
 		$instance->MRM = null;
1193 1193
 		$instance->LIB = new stdClass();
@@ -1195,9 +1195,9 @@  discard block
 block discarded – undo
1195 1195
 		//messages reset
1196 1196
 		EED_Messages::reset();
1197 1197
 
1198
-		if ( $reset_models ) {
1199
-			foreach ( array_keys( $instance->non_abstract_db_models ) as $model_name ) {
1200
-				$instance->reset_model( $model_name );
1198
+		if ($reset_models) {
1199
+			foreach (array_keys($instance->non_abstract_db_models) as $model_name) {
1200
+				$instance->reset_model($model_name);
1201 1201
 			}
1202 1202
 		}
1203 1203
 
@@ -1219,7 +1219,7 @@  discard block
 block discarded – undo
1219 1219
 	 * @param $a
1220 1220
 	 * @param $b
1221 1221
 	 */
1222
-	final function __call( $a, $b ) {
1222
+	final function __call($a, $b) {
1223 1223
 	}
1224 1224
 
1225 1225
 
@@ -1227,7 +1227,7 @@  discard block
 block discarded – undo
1227 1227
 	/**
1228 1228
 	 * @param $a
1229 1229
 	 */
1230
-	final function __get( $a ) {
1230
+	final function __get($a) {
1231 1231
 	}
1232 1232
 
1233 1233
 
@@ -1236,7 +1236,7 @@  discard block
 block discarded – undo
1236 1236
 	 * @param $a
1237 1237
 	 * @param $b
1238 1238
 	 */
1239
-	final function __set( $a, $b ) {
1239
+	final function __set($a, $b) {
1240 1240
 	}
1241 1241
 
1242 1242
 
@@ -1244,7 +1244,7 @@  discard block
 block discarded – undo
1244 1244
 	/**
1245 1245
 	 * @param $a
1246 1246
 	 */
1247
-	final function __isset( $a ) {
1247
+	final function __isset($a) {
1248 1248
 	}
1249 1249
 
1250 1250
 
@@ -1252,7 +1252,7 @@  discard block
 block discarded – undo
1252 1252
 	/**
1253 1253
 	 * @param $a
1254 1254
 	 */
1255
-	final function __unset( $a ) {
1255
+	final function __unset($a) {
1256 1256
 	}
1257 1257
 
1258 1258
 
@@ -1299,7 +1299,7 @@  discard block
 block discarded – undo
1299 1299
 	 * @param $a
1300 1300
 	 * @param $b
1301 1301
 	 */
1302
-	final static function __callStatic( $a, $b ) {
1302
+	final static function __callStatic($a, $b) {
1303 1303
 	}
1304 1304
 
1305 1305
 	/**
@@ -1308,9 +1308,9 @@  discard block
 block discarded – undo
1308 1308
 	 */
1309 1309
 	public function cpt_models() {
1310 1310
 		$cpt_models = array();
1311
-		foreach( $this->non_abstract_db_models as $short_name => $classname ) {
1312
-			if( is_subclass_of(  $classname, 'EEM_CPT_Base' ) ) {
1313
-				$cpt_models[ $short_name ] = $classname;
1311
+		foreach ($this->non_abstract_db_models as $short_name => $classname) {
1312
+			if (is_subclass_of($classname, 'EEM_CPT_Base')) {
1313
+				$cpt_models[$short_name] = $classname;
1314 1314
 			}
1315 1315
 		}
1316 1316
 		return $cpt_models;
Please login to merge, or discard this patch.
core/db_models/EEM_Event.model.php 1 patch
Spacing   +161 added lines, -161 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1 1
 <?php if ( ! defined('EVENT_ESPRESSO_VERSION')) exit('No direct script access allowed');
2
-require_once( EE_MODELS . 'EEM_CPT_Base.model.php');
2
+require_once(EE_MODELS.'EEM_CPT_Base.model.php');
3 3
 /**
4 4
  *
5 5
  * EEM_Event Model
@@ -11,7 +11,7 @@  discard block
 block discarded – undo
11 11
  * @author				Michael Nelson, Brent Christensen
12 12
  *
13 13
  */
14
-class EEM_Event  extends EEM_CPT_Base{
14
+class EEM_Event  extends EEM_CPT_Base {
15 15
 
16 16
 	/**
17 17
 	 * constant used by status(), indicating that no more tickets can be purchased for any of the datetimes for the event
@@ -51,15 +51,15 @@  discard block
 block discarded – undo
51 51
 	 * @param string $timezone
52 52
 	 * @return EEM_Event
53 53
 	 */
54
-	public static function instance( $timezone = NULL ){
54
+	public static function instance($timezone = NULL) {
55 55
 
56 56
 		// check if instance of EEM_Event already exists
57
-		if ( ! self::$_instance instanceof EEM_Event ) {
57
+		if ( ! self::$_instance instanceof EEM_Event) {
58 58
 			// instantiate Espresso_model
59
-			self::$_instance = new self( $timezone );
59
+			self::$_instance = new self($timezone);
60 60
 		}
61 61
 		//we might have a timezone set, let set_timezone decide what to do with it
62
-		self::$_instance->set_timezone( $timezone );
62
+		self::$_instance->set_timezone($timezone);
63 63
 		// EEM_Event object
64 64
 		return self::$_instance;
65 65
 	}
@@ -70,12 +70,12 @@  discard block
 block discarded – undo
70 70
 	 * @param string $timezone
71 71
 	 * @return EEM_Event
72 72
 	 */
73
-	protected function __construct($timezone = null){
73
+	protected function __construct($timezone = null) {
74 74
 
75
-		EE_Registry::instance()->load_model( 'Registration' );
75
+		EE_Registry::instance()->load_model('Registration');
76 76
 
77
-		$this->singular_item = __('Event','event_espresso');
78
-		$this->plural_item = __('Events','event_espresso');
77
+		$this->singular_item = __('Event', 'event_espresso');
78
+		$this->plural_item = __('Events', 'event_espresso');
79 79
 
80 80
 		// to remove Cancelled events from the frontend, copy the following filter to your functions.php file
81 81
 		// add_filter( 'AFEE__EEM_Event__construct___custom_stati__cancelled__Public', '__return_false' );
@@ -89,57 +89,57 @@  discard block
 block discarded – undo
89 89
 			array(
90 90
 				EEM_Event::cancelled => array(
91 91
 					'label' => __('Cancelled', 'event_espresso'),
92
-					'public' => apply_filters( 'AFEE__EEM_Event__construct___custom_stati__cancelled__Public', TRUE )
92
+					'public' => apply_filters('AFEE__EEM_Event__construct___custom_stati__cancelled__Public', TRUE)
93 93
 				),
94 94
 				EEM_Event::postponed => array(
95 95
 					'label' => __('Postponed', 'event_espresso'),
96
-					'public' => apply_filters( 'AFEE__EEM_Event__construct___custom_stati__postponed__Public', TRUE )
96
+					'public' => apply_filters('AFEE__EEM_Event__construct___custom_stati__postponed__Public', TRUE)
97 97
 				),
98 98
 				EEM_Event::sold_out => array(
99 99
 					'label' => __('Sold Out', 'event_espresso'),
100
-					'public' => apply_filters( 'AFEE__EEM_Event__construct___custom_stati__sold_out__Public', TRUE )
100
+					'public' => apply_filters('AFEE__EEM_Event__construct___custom_stati__sold_out__Public', TRUE)
101 101
 				)
102 102
 			)
103 103
 		);
104 104
 
105
-		self::$_default_reg_status = empty( self::$_default_reg_status ) ? EEM_Registration::status_id_pending_payment : self::$_default_reg_status;
105
+		self::$_default_reg_status = empty(self::$_default_reg_status) ? EEM_Registration::status_id_pending_payment : self::$_default_reg_status;
106 106
 
107 107
 		$this->_tables = array(
108
-			'Event_CPT'=>new EE_Primary_Table( 'posts','ID' ),
109
-			'Event_Meta'=> new EE_Secondary_Table( 'esp_event_meta', 'EVTM_ID', 'EVT_ID' )
108
+			'Event_CPT'=>new EE_Primary_Table('posts', 'ID'),
109
+			'Event_Meta'=> new EE_Secondary_Table('esp_event_meta', 'EVTM_ID', 'EVT_ID')
110 110
 		);
111 111
 
112 112
 		$this->_fields = array(
113 113
 			'Event_CPT'=>array(
114
-				'EVT_ID'=>new EE_Primary_Key_Int_Field( 'ID', __( 'Post ID for Event','event_espresso' )),
115
-				'EVT_name'=>new EE_Plain_Text_Field( 'post_title', __( 'Event Name','event_espresso' ), FALSE, '' ),
116
-				'EVT_desc'=>new EE_Post_Content_Field( 'post_content', __( 'Event Description', 'event_espresso' ), FALSE, '' ),
117
-				'EVT_slug'=>new EE_Slug_Field( 'post_name', __( 'Event Slug', 'event_espresso' ), FALSE, '' ),
118
-				'EVT_created'=>new EE_Datetime_Field( 'post_date', __( 'Date/Time Event Created', 'event_espresso' ), FALSE, EE_Datetime_Field::now ),
119
-				'EVT_short_desc'=>new EE_Simple_HTML_Field( 'post_excerpt', __( 'Event Short Description', 'event_espresso' ), FALSE,'' ),
120
-				'EVT_modified'=>new EE_Datetime_Field( 'post_modified', __( 'Date/Time Event Modified', 'event_espresso' ), FALSE, EE_Datetime_Field::now ),
121
-				'EVT_wp_user'=>new EE_WP_User_Field( 'post_author', __( 'Event Creator ID', 'event_espresso'), FALSE),
122
-				'parent'=>new EE_Integer_Field( 'post_parent', __( 'Event Parent ID', 'event_espresso' ), FALSE, 0 ),
123
-				'EVT_order'=>new EE_Integer_Field( 'menu_order', __( 'Event Menu Order', 'event_espresso' ), FALSE, 1 ),
124
-				'post_type'=>new EE_WP_Post_Type_Field('espresso_events'),// EE_Plain_Text_Field( 'post_type', __( 'Event Post Type', 'event_espresso' ), FALSE, 'espresso_events' ),
125
-				'status' => new EE_WP_Post_Status_Field( 'post_status', __( 'Event Status', 'event_espresso' ), FALSE, 'draft', $this->_custom_stati )
114
+				'EVT_ID'=>new EE_Primary_Key_Int_Field('ID', __('Post ID for Event', 'event_espresso')),
115
+				'EVT_name'=>new EE_Plain_Text_Field('post_title', __('Event Name', 'event_espresso'), FALSE, ''),
116
+				'EVT_desc'=>new EE_Post_Content_Field('post_content', __('Event Description', 'event_espresso'), FALSE, ''),
117
+				'EVT_slug'=>new EE_Slug_Field('post_name', __('Event Slug', 'event_espresso'), FALSE, ''),
118
+				'EVT_created'=>new EE_Datetime_Field('post_date', __('Date/Time Event Created', 'event_espresso'), FALSE, EE_Datetime_Field::now),
119
+				'EVT_short_desc'=>new EE_Simple_HTML_Field('post_excerpt', __('Event Short Description', 'event_espresso'), FALSE, ''),
120
+				'EVT_modified'=>new EE_Datetime_Field('post_modified', __('Date/Time Event Modified', 'event_espresso'), FALSE, EE_Datetime_Field::now),
121
+				'EVT_wp_user'=>new EE_WP_User_Field('post_author', __('Event Creator ID', 'event_espresso'), FALSE),
122
+				'parent'=>new EE_Integer_Field('post_parent', __('Event Parent ID', 'event_espresso'), FALSE, 0),
123
+				'EVT_order'=>new EE_Integer_Field('menu_order', __('Event Menu Order', 'event_espresso'), FALSE, 1),
124
+				'post_type'=>new EE_WP_Post_Type_Field('espresso_events'), // EE_Plain_Text_Field( 'post_type', __( 'Event Post Type', 'event_espresso' ), FALSE, 'espresso_events' ),
125
+				'status' => new EE_WP_Post_Status_Field('post_status', __('Event Status', 'event_espresso'), FALSE, 'draft', $this->_custom_stati)
126 126
 			),
127 127
 			'Event_Meta'=>array(
128
-				'EVTM_ID'=> new EE_DB_Only_Float_Field( 'EVTM_ID', __( 'Event Meta Row ID','event_espresso' ), FALSE ),
129
-				'EVT_ID_fk'=>new EE_DB_Only_Int_Field( 'EVT_ID', __( 'Foreign key to Event ID from Event Meta table', 'event_espresso' ), FALSE ),
130
-				'EVT_display_desc'=>new EE_Boolean_Field( 'EVT_display_desc', __( 'Display Description Flag', 'event_espresso' ), FALSE, 1 ),
131
-				'EVT_display_ticket_selector'=>new EE_Boolean_Field( 'EVT_display_ticket_selector', __( 'Display Ticket Selector Flag', 'event_espresso' ), FALSE, 1 ),
132
-				'EVT_visible_on'=>new EE_Datetime_Field( 'EVT_visible_on', __( 'Event Visible Date', 'event_espresso' ), TRUE, EE_Datetime_Field::now ),
133
-				'EVT_additional_limit'=>new EE_Integer_Field( 'EVT_additional_limit', __( 'Limit of Additional Registrations on Same Transaction', 'event_espresso' ), TRUE, 10 ),
128
+				'EVTM_ID'=> new EE_DB_Only_Float_Field('EVTM_ID', __('Event Meta Row ID', 'event_espresso'), FALSE),
129
+				'EVT_ID_fk'=>new EE_DB_Only_Int_Field('EVT_ID', __('Foreign key to Event ID from Event Meta table', 'event_espresso'), FALSE),
130
+				'EVT_display_desc'=>new EE_Boolean_Field('EVT_display_desc', __('Display Description Flag', 'event_espresso'), FALSE, 1),
131
+				'EVT_display_ticket_selector'=>new EE_Boolean_Field('EVT_display_ticket_selector', __('Display Ticket Selector Flag', 'event_espresso'), FALSE, 1),
132
+				'EVT_visible_on'=>new EE_Datetime_Field('EVT_visible_on', __('Event Visible Date', 'event_espresso'), TRUE, EE_Datetime_Field::now),
133
+				'EVT_additional_limit'=>new EE_Integer_Field('EVT_additional_limit', __('Limit of Additional Registrations on Same Transaction', 'event_espresso'), TRUE, 10),
134 134
 				'EVT_default_registration_status'=>new EE_Enum_Text_Field(
135
-					'EVT_default_registration_status', __( 'Default Registration Status on this Event', 'event_espresso' ), FALSE, EEM_Event::$_default_reg_status, EEM_Registration::reg_status_array()
135
+					'EVT_default_registration_status', __('Default Registration Status on this Event', 'event_espresso'), FALSE, EEM_Event::$_default_reg_status, EEM_Registration::reg_status_array()
136 136
 				),
137
-				'EVT_member_only'=>new EE_Boolean_Field( 'EVT_member_only', __( 'Member-Only Event Flag', 'event_espresso' ), FALSE, FALSE ),
138
-				'EVT_phone'=> new EE_Plain_Text_Field('EVT_phone', __( 'Event Phone Number', 'event_espresso' ), FALSE ),
139
-				'EVT_allow_overflow'=>new EE_Boolean_Field(  'EVT_allow_overflow', __( 'Allow Overflow on Event', 'event_espresso' ), FALSE, FALSE ),
140
-				'EVT_timezone_string'=>new EE_Plain_Text_Field( 'EVT_timezone_string', __( 'Timezone (name) for Event times', 'event_espresso' ), FALSE ),
141
-				'EVT_external_URL'=>new EE_Plain_Text_Field( 'EVT_external_URL', __( 'URL of Event Page if hosted elsewhere', 'event_espresso' ), TRUE ),
142
-				'EVT_donations'=>new EE_Boolean_Field( 'EVT_donations', __( 'Accept Donations?', 'event_espresso' ), FALSE, FALSE )
137
+				'EVT_member_only'=>new EE_Boolean_Field('EVT_member_only', __('Member-Only Event Flag', 'event_espresso'), FALSE, FALSE),
138
+				'EVT_phone'=> new EE_Plain_Text_Field('EVT_phone', __('Event Phone Number', 'event_espresso'), FALSE),
139
+				'EVT_allow_overflow'=>new EE_Boolean_Field('EVT_allow_overflow', __('Allow Overflow on Event', 'event_espresso'), FALSE, FALSE),
140
+				'EVT_timezone_string'=>new EE_Plain_Text_Field('EVT_timezone_string', __('Timezone (name) for Event times', 'event_espresso'), FALSE),
141
+				'EVT_external_URL'=>new EE_Plain_Text_Field('EVT_external_URL', __('URL of Event Page if hosted elsewhere', 'event_espresso'), TRUE),
142
+				'EVT_donations'=>new EE_Boolean_Field('EVT_donations', __('Accept Donations?', 'event_espresso'), FALSE, FALSE)
143 143
 
144 144
 			));
145 145
 
@@ -154,8 +154,8 @@  discard block
 block discarded – undo
154 154
 			'WP_User' => new EE_Belongs_To_Relation(),
155 155
 		);
156 156
 		//this model is generally available for reading
157
-		$this->_cap_restriction_generators[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Public();
158
-		parent::__construct( $timezone );
157
+		$this->_cap_restriction_generators[EEM_Base::caps_read] = new EE_Restriction_Generator_Public();
158
+		parent::__construct($timezone);
159 159
 	}
160 160
 
161 161
 
@@ -163,14 +163,14 @@  discard block
 block discarded – undo
163 163
 	/**
164 164
 	 * @param string $default_reg_status
165 165
 	 */
166
-	public static function set_default_reg_status( $default_reg_status ) {
166
+	public static function set_default_reg_status($default_reg_status) {
167 167
 		self::$_default_reg_status = $default_reg_status;
168 168
 		//if EEM_Event has already been instantiated, then we need to reset the `EVT_default_reg_status` field to use the new default.
169
-		if ( self::$_instance instanceof EEM_Event ) {
169
+		if (self::$_instance instanceof EEM_Event) {
170 170
 			self::$_instance->_fields['Event_Meta']['EVT_default_registration_status'] = new EE_Enum_Text_Field(
171
-				'EVT_default_registration_status', __( 'Default Registration Status on this Event', 'event_espresso' ), false, $default_reg_status, EEM_Registration::reg_status_array()
171
+				'EVT_default_registration_status', __('Default Registration Status on this Event', 'event_espresso'), false, $default_reg_status, EEM_Registration::reg_status_array()
172 172
 			);
173
-			self::$_instance->_fields['Event_Meta']['EVT_default_registration_status']->_construct_finalize( 'Event_Meta', 'EVT_default_registration_status', 'EEM_Event' );
173
+			self::$_instance->_fields['Event_Meta']['EVT_default_registration_status']->_construct_finalize('Event_Meta', 'EVT_default_registration_status', 'EEM_Event');
174 174
 		}
175 175
 	}
176 176
 
@@ -183,9 +183,9 @@  discard block
 block discarded – undo
183 183
 	*		@return 		array
184 184
 	*/
185 185
 	public function get_all_question_groups() {
186
-		return EE_Registry::instance()->load_model( 'Question_Group' )->get_all( array(
187
-			array( 'QSG_deleted' => FALSE ),
188
-			'order_by' => array( 'QSG_order' => 'ASC' )
186
+		return EE_Registry::instance()->load_model('Question_Group')->get_all(array(
187
+			array('QSG_deleted' => FALSE),
188
+			'order_by' => array('QSG_order' => 'ASC')
189 189
 		));
190 190
 	}
191 191
 
@@ -201,13 +201,13 @@  discard block
 block discarded – undo
201 201
 	* 		@param		int $EVT_ID
202 202
 	*		@return 		array
203 203
 	*/
204
-	public function get_all_event_question_groups( $EVT_ID = 0 ) {
205
-		if ( ! isset( $EVT_ID) || ! absint( $EVT_ID )) {
206
-			EE_Error::add_error( __( 'An error occurred. No Event Question Groups could be retrieved because an Event ID was not received.', 'event_espresso' ), __FILE__, __FUNCTION__, __LINE__ );
204
+	public function get_all_event_question_groups($EVT_ID = 0) {
205
+		if ( ! isset($EVT_ID) || ! absint($EVT_ID)) {
206
+			EE_Error::add_error(__('An error occurred. No Event Question Groups could be retrieved because an Event ID was not received.', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__);
207 207
 			return FALSE;
208 208
 		}
209
-		return EE_Registry::instance()->load_model( 'Event_Question_Group' )->get_all( array(
210
-			array( 'EVT_ID' => $EVT_ID )
209
+		return EE_Registry::instance()->load_model('Event_Question_Group')->get_all(array(
210
+			array('EVT_ID' => $EVT_ID)
211 211
 		));
212 212
 	}
213 213
 
@@ -223,13 +223,13 @@  discard block
 block discarded – undo
223 223
 	* 		@param		boolean	$for_primary_attendee
224 224
 	*		@return 		array
225 225
 	*/
226
-	public function get_event_question_groups( $EVT_ID = 0, $for_primary_attendee = TRUE ) {
227
-		if ( ! isset( $EVT_ID) || ! absint( $EVT_ID )) {
228
-			EE_Error::add_error( __( 'An error occurred. No Event Question Groups could be retrieved because an Event ID was not received.', 'event_espresso' ), __FILE__, __FUNCTION__, __LINE__ );
226
+	public function get_event_question_groups($EVT_ID = 0, $for_primary_attendee = TRUE) {
227
+		if ( ! isset($EVT_ID) || ! absint($EVT_ID)) {
228
+			EE_Error::add_error(__('An error occurred. No Event Question Groups could be retrieved because an Event ID was not received.', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__);
229 229
 			return FALSE;
230 230
 		}
231
-		return EE_Registry::instance()->load_model( 'Event_Question_Group' )->get_all( array(
232
-			array( 'EVT_ID' => $EVT_ID, 'EQG_primary' => $for_primary_attendee )
231
+		return EE_Registry::instance()->load_model('Event_Question_Group')->get_all(array(
232
+			array('EVT_ID' => $EVT_ID, 'EQG_primary' => $for_primary_attendee)
233 233
 		));
234 234
 	}
235 235
 
@@ -246,10 +246,10 @@  discard block
 block discarded – undo
246 246
 	* 		@param		EE_Registration 	$registration
247 247
 	*		@return 		array
248 248
 	*/
249
-	public function get_question_groups_for_event( $EVT_ID = 0, EE_Registration $registration ) {
249
+	public function get_question_groups_for_event($EVT_ID = 0, EE_Registration $registration) {
250 250
 
251
-		if ( ! isset( $EVT_ID) || ! absint( $EVT_ID )) {
252
-			EE_Error::add_error( __( 'An error occurred. No Question Groups could be retrieved because an Event ID was not received.', 'event_espresso' ), __FILE__, __FUNCTION__, __LINE__ );
251
+		if ( ! isset($EVT_ID) || ! absint($EVT_ID)) {
252
+			EE_Error::add_error(__('An error occurred. No Question Groups could be retrieved because an Event ID was not received.', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__);
253 253
 			return FALSE;
254 254
 		}
255 255
 
@@ -259,7 +259,7 @@  discard block
 block discarded – undo
259 259
 			'QSG_deleted' => FALSE
260 260
 		);
261 261
 
262
-		return EE_Registry::instance()->load_model( 'Question_Group' )->get_all( array(
262
+		return EE_Registry::instance()->load_model('Question_Group')->get_all(array(
263 263
 			$where_params,
264 264
 			'order_by' => array('QSG_order' => 'ASC')
265 265
 		));
@@ -279,16 +279,16 @@  discard block
 block discarded – undo
279 279
 	* 		@param		string		$QSG_IDs  csv list of $QSG IDs
280 280
 	*		@return 		array
281 281
 	*/
282
-	public function get_questions_in_groups( $QSG_IDs = '' ) {
282
+	public function get_questions_in_groups($QSG_IDs = '') {
283 283
 
284
-		if ( empty( $QSG_IDs )) {
285
-			EE_Error::add_error( __( 'An error occurred. No Question Group IDs were received.', 'event_espresso' ), __FILE__, __FUNCTION__, __LINE__ );
284
+		if (empty($QSG_IDs)) {
285
+			EE_Error::add_error(__('An error occurred. No Question Group IDs were received.', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__);
286 286
 			return FALSE;
287 287
 		}
288 288
 
289
-		return EE_Registry::instance()->load_model( 'Question' )->get_all( array(
289
+		return EE_Registry::instance()->load_model('Question')->get_all(array(
290 290
 			array(
291
-				'Question_Group.QSG_ID' => array( 'IN', $QSG_IDs ),
291
+				'Question_Group.QSG_ID' => array('IN', $QSG_IDs),
292 292
 				'QST_deleted' => FALSE,
293 293
 				'QST_admin_only' => is_admin()
294 294
 			),
@@ -310,16 +310,16 @@  discard block
 block discarded – undo
310 310
 	* 		@param		string		$QST_IDs  csv list of $QST IDs
311 311
 	*		@return 		array
312 312
 	*/
313
-	public function get_options_for_question( $QST_IDs ) {
313
+	public function get_options_for_question($QST_IDs) {
314 314
 
315
-		if ( empty( $QST_IDs )) {
316
-			EE_Error::add_error( __( 'An error occurred. No Question IDs were received.', 'event_espresso' ), __FILE__, __FUNCTION__, __LINE__ );
315
+		if (empty($QST_IDs)) {
316
+			EE_Error::add_error(__('An error occurred. No Question IDs were received.', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__);
317 317
 			return FALSE;
318 318
 		}
319 319
 
320
-		return EE_Registry::instance()->load_model( 'Question_Option' )->get_all( array(
320
+		return EE_Registry::instance()->load_model('Question_Option')->get_all(array(
321 321
 			array(
322
-				'Question.QST_ID' => array( 'IN', $QST_IDs ),
322
+				'Question.QST_ID' => array('IN', $QST_IDs),
323 323
 				'QSO_deleted' => FALSE
324 324
 			),
325 325
 			'order_by' => 'QSO_ID'
@@ -339,46 +339,46 @@  discard block
 block discarded – undo
339 339
 	 * @throws EE_Error
340 340
 	 * @return 	array
341 341
 	 */
342
-	public function assemble_array_of_groups_questions_and_options( EE_Registration $registration, $EVT_ID = 0 ) {
342
+	public function assemble_array_of_groups_questions_and_options(EE_Registration $registration, $EVT_ID = 0) {
343 343
 
344
-		if ( empty( $EVT_ID ) ) {
345
-			throw new EE_Error( __( 'An error occurred. No EVT_ID is included.  Needed to know which question groups to retrieve.', 'event_espresso' ) );
344
+		if (empty($EVT_ID)) {
345
+			throw new EE_Error(__('An error occurred. No EVT_ID is included.  Needed to know which question groups to retrieve.', 'event_espresso'));
346 346
 		}
347 347
 
348 348
 		$questions = array();
349 349
 
350 350
 		// get all question groups for event
351
-		$qgs = $this->get_question_groups_for_event( $EVT_ID, $registration );
352
-		if ( !empty( $qgs ) ) {
353
-			foreach ( $qgs as $qg ) {
351
+		$qgs = $this->get_question_groups_for_event($EVT_ID, $registration);
352
+		if ( ! empty($qgs)) {
353
+			foreach ($qgs as $qg) {
354 354
 			 	$qsts = $qg->questions();
355
-			 	$questions[ $qg->ID() ] = $qg->model_field_array();
356
-			 	$questions[ $qg->ID() ]['QSG_questions'] = array();
357
-			 	foreach ( $qsts as $qst ) {
358
-			 		if ( $qst->is_system_question() )
355
+			 	$questions[$qg->ID()] = $qg->model_field_array();
356
+			 	$questions[$qg->ID()]['QSG_questions'] = array();
357
+			 	foreach ($qsts as $qst) {
358
+			 		if ($qst->is_system_question())
359 359
 			 			continue;
360
-			 		$answer = EEM_Answer::instance()->get_one( array( array( 'QST_ID' => $qst->ID(), 'REG_ID' => $registration->ID() ) ) );
360
+			 		$answer = EEM_Answer::instance()->get_one(array(array('QST_ID' => $qst->ID(), 'REG_ID' => $registration->ID())));
361 361
 			 		$answer = $answer instanceof EE_Answer ? $answer : EEM_Answer::instance()->create_default_object();
362 362
 			 		$qst_name = $qstn_id = $qst->ID();
363 363
 			 		$ans_id = $answer->ID();
364
-			 		$qst_name = !empty( $ans_id ) ?  '[' . $qst_name . '][' . $ans_id . ']' : '[' . $qst_name . ']';
364
+			 		$qst_name = ! empty($ans_id) ? '['.$qst_name.']['.$ans_id.']' : '['.$qst_name.']';
365 365
 			 		$input_name = '';
366
-			 		$input_id = sanitize_key( $qst->display_text() );
366
+			 		$input_id = sanitize_key($qst->display_text());
367 367
 			 		$input_class = '';
368 368
 			 		$questions[$qg->ID()]['QSG_questions'][$qst->ID()] = $qst->model_field_array();
369
-		 			$questions[ $qg->ID() ]['QSG_questions'][ $qst->ID() ]['QST_input_name'] = 'qstn' . $input_name . $qst_name;
370
-					$questions[ $qg->ID() ]['QSG_questions'][ $qst->ID() ]['QST_input_id'] = $input_id . '-' . $qstn_id;
371
-					$questions[ $qg->ID() ]['QSG_questions'][ $qst->ID() ]['QST_input_class'] = $input_class;
372
-					$questions[ $qg->ID() ]['QSG_questions'][ $qst->ID() ]['QST_options'] = array();
373
-					$questions[ $qg->ID() ]['QSG_questions'][ $qst->ID() ]['qst_obj'] = $qst;
374
-					$questions[ $qg->ID() ]['QSG_questions'][ $qst->ID() ]['ans_obj'] = $answer;
369
+		 			$questions[$qg->ID()]['QSG_questions'][$qst->ID()]['QST_input_name'] = 'qstn'.$input_name.$qst_name;
370
+					$questions[$qg->ID()]['QSG_questions'][$qst->ID()]['QST_input_id'] = $input_id.'-'.$qstn_id;
371
+					$questions[$qg->ID()]['QSG_questions'][$qst->ID()]['QST_input_class'] = $input_class;
372
+					$questions[$qg->ID()]['QSG_questions'][$qst->ID()]['QST_options'] = array();
373
+					$questions[$qg->ID()]['QSG_questions'][$qst->ID()]['qst_obj'] = $qst;
374
+					$questions[$qg->ID()]['QSG_questions'][$qst->ID()]['ans_obj'] = $answer;
375 375
 					//leave responses as-is, don't convert stuff into html entities please!
376
-					$questions[ $qg->ID() ][ 'QSG_questions'][ $qst->ID() ][ 'htmlentities' ] = false;
377
-					if ( $qst->type() == 'RADIO_BTN' || $qst->type() == 'CHECKBOX' || $qst->type() == 'DROPDOWN' ) {
378
-						$QSOs = $qst->options(TRUE,$answer->value());
379
-						if ( is_array( $QSOs ) ) {
380
-							foreach ( $QSOs as $QSO_ID => $QSO ) {
381
-								$questions[ $qg->ID() ]['QSG_questions'][ $qst->ID() ]['QST_options'][ $QSO_ID ] = $QSO->model_field_array();
376
+					$questions[$qg->ID()]['QSG_questions'][$qst->ID()]['htmlentities'] = false;
377
+					if ($qst->type() == 'RADIO_BTN' || $qst->type() == 'CHECKBOX' || $qst->type() == 'DROPDOWN') {
378
+						$QSOs = $qst->options(TRUE, $answer->value());
379
+						if (is_array($QSOs)) {
380
+							foreach ($QSOs as $QSO_ID => $QSO) {
381
+								$questions[$qg->ID()]['QSG_questions'][$qst->ID()]['QST_options'][$QSO_ID] = $QSO->model_field_array();
382 382
 							}
383 383
 						}
384 384
 					}
@@ -402,9 +402,9 @@  discard block
 block discarded – undo
402 402
 	* 		@param		$QST
403 403
 	*		@return 		string		string
404 404
 	*/
405
-	private function _generate_question_input_name( $QST ) {
405
+	private function _generate_question_input_name($QST) {
406 406
 
407
-		if ( $QST->QST_system ) {
407
+		if ($QST->QST_system) {
408 408
 			$qst_name = $QST->QST_system;
409 409
 /*			switch( $QST->QST_system ) {
410 410
 
@@ -471,36 +471,36 @@  discard block
 block discarded – undo
471 471
 	 * @param bool    $count whether to return the count or not (default FALSE)
472 472
 	 * @return array 	EE_Event objects
473 473
 	 */
474
-	public function get_active_events( $query_params, $count = FALSE ) {
475
-		if ( array_key_exists( 0, $query_params ) ) {
474
+	public function get_active_events($query_params, $count = FALSE) {
475
+		if (array_key_exists(0, $query_params)) {
476 476
 			$where_params = $query_params[0];
477
-			unset( $query_params[0] );
477
+			unset($query_params[0]);
478 478
 		} else {
479 479
 			$where_params = array();
480 480
 		}
481 481
 
482 482
 		//if we have count make sure we don't include group by
483
-		if ( $count && isset( $query_params['group_by'] ) ) {
484
-			unset( $query_params['group_by'] );
483
+		if ($count && isset($query_params['group_by'])) {
484
+			unset($query_params['group_by']);
485 485
 		}
486 486
 
487 487
 		//let's add specific query_params for active_events - keep in mind this will override any sent status in the query AND any date queries.
488 488
 		$where_params['status'] = 'publish';
489 489
 		//if already have where params for DTT_EVT_start or DTT_EVT_end then append these conditions
490
-		if ( isset( $where_params['Datetime.DTT_EVT_start'] ) ) {
491
-			$where_params['Datetime.DTT_EVT_start******'] = array('<',  EEM_Datetime::instance()->current_time_for_query( 'DTT_EVT_start' ) );
490
+		if (isset($where_params['Datetime.DTT_EVT_start'])) {
491
+			$where_params['Datetime.DTT_EVT_start******'] = array('<', EEM_Datetime::instance()->current_time_for_query('DTT_EVT_start'));
492 492
 		} else {
493
-			$where_params['Datetime.DTT_EVT_start'] = array('<',  EEM_Datetime::instance()->current_time_for_query( 'DTT_EVT_start' ) );
493
+			$where_params['Datetime.DTT_EVT_start'] = array('<', EEM_Datetime::instance()->current_time_for_query('DTT_EVT_start'));
494 494
 		}
495 495
 
496
-		if ( isset( $where_params['Datetime.DTT_EVT_end'] ) ) {
497
-			$where_params['Datetime.DTT_EVT_end*****'] = array('>', EEM_Datetime::instance()->current_time_for_query( 'DTT_EVT_end' ) );
496
+		if (isset($where_params['Datetime.DTT_EVT_end'])) {
497
+			$where_params['Datetime.DTT_EVT_end*****'] = array('>', EEM_Datetime::instance()->current_time_for_query('DTT_EVT_end'));
498 498
 		} else {
499
-			$where_params['Datetime.DTT_EVT_end'] = array('>', EEM_Datetime::instance()->current_time_for_query( 'DTT_EVT_end' ) );
499
+			$where_params['Datetime.DTT_EVT_end'] = array('>', EEM_Datetime::instance()->current_time_for_query('DTT_EVT_end'));
500 500
 		}
501 501
 		$query_params[0] = $where_params;
502 502
 		// don't use $query_params with count() because we don't want to include additional query clauses like "GROUP BY"
503
-		return $count ? $this->count( array( $where_params ), 'EVT_ID', true ) : $this->get_all( $query_params );
503
+		return $count ? $this->count(array($where_params), 'EVT_ID', true) : $this->get_all($query_params);
504 504
 	}
505 505
 
506 506
 
@@ -515,30 +515,30 @@  discard block
 block discarded – undo
515 515
 	 * @param bool    $count whether to return the count or not (default FALSE)
516 516
 	 * @return array               EE_Event objects
517 517
 	 */
518
-	public function get_upcoming_events( $query_params, $count = FALSE ) {
519
-		if ( array_key_exists( 0, $query_params ) ) {
518
+	public function get_upcoming_events($query_params, $count = FALSE) {
519
+		if (array_key_exists(0, $query_params)) {
520 520
 			$where_params = $query_params[0];
521
-			unset( $query_params[0] );
521
+			unset($query_params[0]);
522 522
 		} else {
523 523
 			$where_params = array();
524 524
 		}
525 525
 
526 526
 		//if we have count make sure we don't include group by
527
-		if ( $count && isset( $query_params['group_by'] ) ) {
528
-			unset( $query_params['group_by'] );
527
+		if ($count && isset($query_params['group_by'])) {
528
+			unset($query_params['group_by']);
529 529
 		}
530 530
 
531 531
 		//let's add specific query_params for active_events - keep in mind this will override any sent status in the query AND any date queries.
532 532
 		$where_params['status'] = 'publish';
533 533
 		//if there are already query_params matching DTT_EVT_start then we need to modify that to add them.
534
-		if ( isset( $where_params['Datetime.DTT_EVT_start'] ) ) {
535
-			$where_params['Datetime.DTT_EVT_start*****'] = array('>', EEM_Datetime::instance()->current_time_for_query( 'DTT_EVT_start' ) );
534
+		if (isset($where_params['Datetime.DTT_EVT_start'])) {
535
+			$where_params['Datetime.DTT_EVT_start*****'] = array('>', EEM_Datetime::instance()->current_time_for_query('DTT_EVT_start'));
536 536
 		} else {
537
-			$where_params['Datetime.DTT_EVT_start'] = array('>', EEM_Datetime::instance()->current_time_for_query( 'DTT_EVT_start' ) );
537
+			$where_params['Datetime.DTT_EVT_start'] = array('>', EEM_Datetime::instance()->current_time_for_query('DTT_EVT_start'));
538 538
 		}
539 539
 		$query_params[0] = $where_params;
540 540
 		// don't use $query_params with count() because we don't want to include additional query clauses like "GROUP BY"
541
-		return $count ? $this->count( array( $where_params ), 'EVT_ID', true ) : $this->get_all( $query_params );
541
+		return $count ? $this->count(array($where_params), 'EVT_ID', true) : $this->get_all($query_params);
542 542
 	}
543 543
 
544 544
 
@@ -550,54 +550,54 @@  discard block
 block discarded – undo
550 550
 	 * @param bool    $count whether to return the count or not (default FALSE)
551 551
 	 * @return array 	EE_Event objects
552 552
 	 */
553
-	public function get_expired_events( $query_params, $count = FALSE ) {
553
+	public function get_expired_events($query_params, $count = FALSE) {
554 554
 
555
-		$where_params = isset( $query_params[0] ) ? $query_params[0] : array();
555
+		$where_params = isset($query_params[0]) ? $query_params[0] : array();
556 556
 
557 557
 		//if we have count make sure we don't include group by
558
-		if ( $count && isset( $query_params['group_by'] ) ) {
559
-			unset( $query_params['group_by'] );
558
+		if ($count && isset($query_params['group_by'])) {
559
+			unset($query_params['group_by']);
560 560
 		}
561 561
 
562 562
 		//let's add specific query_params for active_events - keep in mind this will override any sent status in the query AND any date queries.
563
-		if ( isset( $where_params['status'] ) ) {
564
-			unset( $where_params['status'] );
563
+		if (isset($where_params['status'])) {
564
+			unset($where_params['status']);
565 565
 		}
566 566
 		$exclude_query = $query_params;
567
-		if ( isset( $exclude_query[0] ) ) {
568
-			unset( $exclude_query[0] );
567
+		if (isset($exclude_query[0])) {
568
+			unset($exclude_query[0]);
569 569
 		}
570
-		$exclude_query[0] = array( 'Datetime.DTT_EVT_end' => array( '>', EEM_Datetime::instance()->current_time_for_query( 'DTT_EVT_end' ) ) );
570
+		$exclude_query[0] = array('Datetime.DTT_EVT_end' => array('>', EEM_Datetime::instance()->current_time_for_query('DTT_EVT_end')));
571 571
 		//first get all events that have datetimes where its not expired.
572
-		$event_ids = $this->_get_all_wpdb_results( $exclude_query, OBJECT_K, 'Event_CPT.ID' );
573
-		$event_ids = array_keys( $event_ids );
572
+		$event_ids = $this->_get_all_wpdb_results($exclude_query, OBJECT_K, 'Event_CPT.ID');
573
+		$event_ids = array_keys($event_ids);
574 574
 
575 575
 		//if we have any additional query_params, let's add them to the 'AND' condition
576 576
 		$and_condition = array(
577
-			'Datetime.DTT_EVT_end' => array( '<', EEM_Datetime::instance()->current_time_for_query( 'DTT_EVT_end' ) ),
578
-			'EVT_ID' =>  array( 'NOT IN', $event_ids )
577
+			'Datetime.DTT_EVT_end' => array('<', EEM_Datetime::instance()->current_time_for_query('DTT_EVT_end')),
578
+			'EVT_ID' =>  array('NOT IN', $event_ids)
579 579
 			);
580 580
 
581
-		if ( isset( $where_params['OR'] ) ) {
581
+		if (isset($where_params['OR'])) {
582 582
 			$and_condition['OR'] = $where_params['OR'];
583
-			unset( $where_params['OR'] );
583
+			unset($where_params['OR']);
584 584
 		}
585 585
 
586
-		if ( isset( $where_params['Datetime.DTT_EVT_end'] ) ) {
586
+		if (isset($where_params['Datetime.DTT_EVT_end'])) {
587 587
 			$and_condition['Datetime.DTT_EVT_end****'] = $where_params['Datetime.DTT_EVT_end'];
588
-			unset( $where_params['Datetime.DTT_EVT_end'] );
588
+			unset($where_params['Datetime.DTT_EVT_end']);
589 589
 		}
590 590
 
591
-		if ( isset( $where_params['Datetime.DTT_EVT_start'] ) ) {
591
+		if (isset($where_params['Datetime.DTT_EVT_start'])) {
592 592
 			$and_condition['Datetime.DTT_EVT_start'] = $where_params['Datetime.DTT_EVT_start'];
593
-			unset( $where_params['Datetime.DTT_EVT_start'] );
593
+			unset($where_params['Datetime.DTT_EVT_start']);
594 594
 		}
595 595
 
596 596
 		//merge remaining $where params with the and conditions.
597
-		$where_params['AND'] = array_merge( $and_condition, $where_params );
597
+		$where_params['AND'] = array_merge($and_condition, $where_params);
598 598
 		$query_params[0] = $where_params;
599 599
 		// don't use $query_params with count() because we don't want to include additional query clauses like "GROUP BY"
600
-		return $count ? $this->count( array( $where_params ), 'EVT_ID', true ) : $this->get_all( $query_params );
600
+		return $count ? $this->count(array($where_params), 'EVT_ID', true) : $this->get_all($query_params);
601 601
 	}
602 602
 
603 603
 
@@ -608,40 +608,40 @@  discard block
 block discarded – undo
608 608
 	 * @param  boolean $count        whether to return the count or not (default FALSE)
609 609
 	 * @return EE_Event[]            array of EE_Event objects
610 610
 	 */
611
-	public function get_inactive_events( $query_params, $count = FALSE ) {
612
-		$where_params = isset( $query_params[0] ) ? $query_params[0] : array();
611
+	public function get_inactive_events($query_params, $count = FALSE) {
612
+		$where_params = isset($query_params[0]) ? $query_params[0] : array();
613 613
 
614 614
 		//let's add in specific query_params for inactive events.
615
-		if ( isset( $where_params['status'] ) ) {
616
-			unset( $where_params['status'] );
615
+		if (isset($where_params['status'])) {
616
+			unset($where_params['status']);
617 617
 		}
618 618
 
619 619
 		//if we have count make sure we don't include group by
620
-		if ( $count && isset( $query_params['group_by'] ) ) {
621
-			unset( $query_params['group_by'] );
620
+		if ($count && isset($query_params['group_by'])) {
621
+			unset($query_params['group_by']);
622 622
 		}
623 623
 
624 624
 		//if we have any additional query_params, let's add them to the 'AND' condition
625
-		$where_params['AND']['status'] = array( '!=', 'publish' );
625
+		$where_params['AND']['status'] = array('!=', 'publish');
626 626
 
627
-		if ( isset( $where_params['OR'] ) ) {
627
+		if (isset($where_params['OR'])) {
628 628
 			$where_params['AND']['OR'] = $where_params['OR'];
629
-			unset( $where_params['OR'] );
629
+			unset($where_params['OR']);
630 630
 		}
631 631
 
632
-		if ( isset( $where_params['Datetime.DTT_EVT_end'] ) ) {
632
+		if (isset($where_params['Datetime.DTT_EVT_end'])) {
633 633
 			$where_params['AND']['Datetime.DTT_EVT_end****'] = $where_params['Datetime.DTT_EVT_end'];
634
-			unset( $where_params['Datetime.DTT_EVT_end'] );
634
+			unset($where_params['Datetime.DTT_EVT_end']);
635 635
 		}
636 636
 
637
-		if ( isset( $where_params['Datetime.DTT_EVT_start'] ) ) {
637
+		if (isset($where_params['Datetime.DTT_EVT_start'])) {
638 638
 			$where_params['AND']['Datetime.DTT_EVT_start'] = $where_params['Datetime.DTT_EVT_start'];
639
-			unset( $where_params['Datetime.DTT_EVT_start'] );
639
+			unset($where_params['Datetime.DTT_EVT_start']);
640 640
 		}
641 641
 
642 642
 		$query_params[0] = $where_params;
643 643
 		// don't use $query_params with count() because we don't want to include additional query clauses like "GROUP BY"
644
-		return $count ? $this->count( array( $where_params ), 'EVT_ID', true ) : $this->get_all( $query_params );
644
+		return $count ? $this->count(array($where_params), 'EVT_ID', true) : $this->get_all($query_params);
645 645
 	}
646 646
 
647 647
 
@@ -649,13 +649,13 @@  discard block
 block discarded – undo
649 649
 	 * This is just injecting into the parent add_relationship_to so we do special handling on price relationships because we don't want to override any existing global default prices but instead insert NEW prices that get attached to the event.
650 650
 	 * See parent for param descriptions
651 651
 	 */
652
-	public function add_relationship_to($id_or_obj,$other_model_id_or_obj, $relationName, $where_query = array()){
652
+	public function add_relationship_to($id_or_obj, $other_model_id_or_obj, $relationName, $where_query = array()) {
653 653
 
654
-		if ( $relationName == 'Price' ) {
654
+		if ($relationName == 'Price') {
655 655
 			//let's get the PRC object for the given ID to make sure that we aren't dealing with a default
656 656
 			$prc_chk = $this->get_related_model_obj($relationName)->ensure_is_obj($other_model_id_or_obj);
657 657
 			//if EVT_ID = 0, then this is a default
658
-			if ( $prc_chk->get('EVT_ID') == 0 ) {
658
+			if ($prc_chk->get('EVT_ID') == 0) {
659 659
 				//let's set the prc_id as 0 so we force an insert on the add_relation_to carried out by relation
660 660
 				$prc_chk->set('PRC_ID', 0);
661 661
 			}
@@ -665,7 +665,7 @@  discard block
 block discarded – undo
665 665
 		}
666 666
 
667 667
 		//otherwise carry on as normal
668
-		return parent::add_relationship_to($id_or_obj,$other_model_id_or_obj, $relationName, $where_query);
668
+		return parent::add_relationship_to($id_or_obj, $other_model_id_or_obj, $relationName, $where_query);
669 669
 	}
670 670
 
671 671
 
Please login to merge, or discard this patch.
core/db_models/EEM_Transaction.model.php 1 patch
Spacing   +55 added lines, -55 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1
-<?php if ( ! defined('EVENT_ESPRESSO_VERSION')) {exit('No direct script access allowed');}
2
-require_once ( EE_MODELS . 'EEM_Base.model.php' );
1
+<?php if ( ! defined('EVENT_ESPRESSO_VERSION')) {exit('No direct script access allowed'); }
2
+require_once (EE_MODELS.'EEM_Base.model.php');
3 3
 /**
4 4
  *
5 5
  * Transaction Model
@@ -67,36 +67,36 @@  discard block
 block discarded – undo
67 67
 	 * @return EEM_Transaction
68 68
 	 * @throws \EE_Error
69 69
 	 */
70
-	protected function __construct( $timezone ) {
71
-		$this->singular_item = __('Transaction','event_espresso');
72
-		$this->plural_item = __('Transactions','event_espresso');
70
+	protected function __construct($timezone) {
71
+		$this->singular_item = __('Transaction', 'event_espresso');
72
+		$this->plural_item = __('Transactions', 'event_espresso');
73 73
 
74 74
 		$this->_tables = array(
75
-			'TransactionTable'=>new EE_Primary_Table('esp_transaction','TXN_ID')
75
+			'TransactionTable'=>new EE_Primary_Table('esp_transaction', 'TXN_ID')
76 76
 		);
77 77
 		$this->_fields = array(
78 78
 			'TransactionTable'=>array(
79
-				'TXN_ID'=>new EE_Primary_Key_Int_Field('TXN_ID', __('Transaction ID','event_espresso')),
80
-				'TXN_timestamp'=>new EE_Datetime_Field('TXN_timestamp', __('date when transaction was created','event_espresso'), false, EE_Datetime_Field::now, $timezone ),
81
-				'TXN_total'=>new EE_Money_Field('TXN_total', __('Total value of Transaction','event_espresso'), false, 0),
82
-				'TXN_paid'=>new EE_Money_Field('TXN_paid', __('Amount paid towards transaction to date','event_espresso'), false, 0),
83
-				'STS_ID'=>new EE_Foreign_Key_String_Field('STS_ID', __('Status ID','event_espresso'), false, EEM_Transaction::failed_status_code, 'Status'),
84
-				'TXN_session_data'=>new EE_Serialized_Text_Field('TXN_session_data', __('Serialized session data','event_espresso'), true, ''),
85
-				'TXN_hash_salt'=>new EE_Plain_Text_Field('TXN_hash_salt', __('Transaction Hash Salt','event_espresso'), true, ''),
79
+				'TXN_ID'=>new EE_Primary_Key_Int_Field('TXN_ID', __('Transaction ID', 'event_espresso')),
80
+				'TXN_timestamp'=>new EE_Datetime_Field('TXN_timestamp', __('date when transaction was created', 'event_espresso'), false, EE_Datetime_Field::now, $timezone),
81
+				'TXN_total'=>new EE_Money_Field('TXN_total', __('Total value of Transaction', 'event_espresso'), false, 0),
82
+				'TXN_paid'=>new EE_Money_Field('TXN_paid', __('Amount paid towards transaction to date', 'event_espresso'), false, 0),
83
+				'STS_ID'=>new EE_Foreign_Key_String_Field('STS_ID', __('Status ID', 'event_espresso'), false, EEM_Transaction::failed_status_code, 'Status'),
84
+				'TXN_session_data'=>new EE_Serialized_Text_Field('TXN_session_data', __('Serialized session data', 'event_espresso'), true, ''),
85
+				'TXN_hash_salt'=>new EE_Plain_Text_Field('TXN_hash_salt', __('Transaction Hash Salt', 'event_espresso'), true, ''),
86 86
 				'PMD_ID'=>new EE_Foreign_Key_Int_Field('PMD_ID', __("Last Used Payment Method", 'event_espresso'), true, NULL, 'Payment_Method'),
87
-				'TXN_reg_steps' => new EE_Serialized_Text_Field( 'TXN_reg_steps', __( 'Registration Steps', 'event_espresso' ), FALSE, array() ),
87
+				'TXN_reg_steps' => new EE_Serialized_Text_Field('TXN_reg_steps', __('Registration Steps', 'event_espresso'), FALSE, array()),
88 88
 			)
89 89
 		);
90 90
 		$this->_model_relations = array(
91 91
 			'Registration'=>new EE_Has_Many_Relation(),
92 92
 			'Payment'=>new EE_Has_Many_Relation(),
93 93
 			'Status'=>new EE_Belongs_To_Relation(),
94
-			'Line_Item'=>new EE_Has_Many_Relation(false),//you can delete a transaction without needing to delete its line items
94
+			'Line_Item'=>new EE_Has_Many_Relation(false), //you can delete a transaction without needing to delete its line items
95 95
 			'Payment_Method'=>new EE_Belongs_To_Relation(),
96 96
 			'Message' => new EE_Has_Many_Relation()
97 97
 		);
98 98
 		$this->_model_chain_to_wp_user = 'Registration.Event';
99
-		parent::__construct( $timezone );
99
+		parent::__construct($timezone);
100 100
 
101 101
 	}
102 102
 
@@ -107,22 +107,22 @@  discard block
 block discarded – undo
107 107
 	 * @param string $period
108 108
 	 * @return \stdClass[]
109 109
 	 */
110
-	public function get_revenue_per_day_report( $period = '-1 month' ) {
111
-		$sql_date = $this->convert_datetime_for_query( 'TXN_timestamp', date( 'Y-m-d H:i:s', strtotime( $period ) ), 'Y-m-d H:i:s', 'UTC' );
110
+	public function get_revenue_per_day_report($period = '-1 month') {
111
+		$sql_date = $this->convert_datetime_for_query('TXN_timestamp', date('Y-m-d H:i:s', strtotime($period)), 'Y-m-d H:i:s', 'UTC');
112 112
 
113
-		$query_interval = EEH_DTT_Helper::get_sql_query_interval_for_offset( $this->get_timezone(), 'TXN_timestamp' );
113
+		$query_interval = EEH_DTT_Helper::get_sql_query_interval_for_offset($this->get_timezone(), 'TXN_timestamp');
114 114
 		return $this->_get_all_wpdb_results(
115 115
 			array(
116 116
 				array(
117
-					'TXN_timestamp' => array( '>=', $sql_date )
117
+					'TXN_timestamp' => array('>=', $sql_date)
118 118
 				),
119 119
 				'group_by' => 'txnDate',
120
-				'order_by' => array( 'TXN_timestamp' => 'ASC' )
120
+				'order_by' => array('TXN_timestamp' => 'ASC')
121 121
 			),
122 122
 			OBJECT,
123 123
 			array(
124
-				'txnDate' => array( 'DATE(' . $query_interval . ')', '%s' ),
125
-				'revenue' => array( 'SUM(TransactionTable.TXN_paid)', '%d' )
124
+				'txnDate' => array('DATE('.$query_interval.')', '%s'),
125
+				'revenue' => array('SUM(TransactionTable.TXN_paid)', '%d')
126 126
 			)
127 127
 		);
128 128
 	}
@@ -137,18 +137,18 @@  discard block
 block discarded – undo
137 137
 	 * @throws \EE_Error
138 138
 	 * @return mixed
139 139
 	 */
140
-	public function get_revenue_per_event_report( $period = '-1 month' ) {
140
+	public function get_revenue_per_event_report($period = '-1 month') {
141 141
 		global $wpdb;
142
-		$transaction_table = $wpdb->prefix . 'esp_transaction';
143
-		$registration_table = $wpdb->prefix . 'esp_registration';
142
+		$transaction_table = $wpdb->prefix.'esp_transaction';
143
+		$registration_table = $wpdb->prefix.'esp_registration';
144 144
 		$event_table = $wpdb->posts;
145
-		$payment_table = $wpdb->prefix . 'esp_payment';
146
-		$sql_date = date( 'Y-m-d H:i:s', strtotime( $period ) );
145
+		$payment_table = $wpdb->prefix.'esp_payment';
146
+		$sql_date = date('Y-m-d H:i:s', strtotime($period));
147 147
 		$approved_payment_status = EEM_Payment::status_id_approved;
148 148
 		$extra_event_on_join = '';
149 149
 		//exclude events not authored by user if permissions in effect
150
-		if ( ! EE_Registry::instance()->CAP->current_user_can( 'ee_read_others_registrations', 'reg_per_event_report' ) ) {
151
-			$extra_event_on_join = ' AND Event.post_author = ' . get_current_user_id();
150
+		if ( ! EE_Registry::instance()->CAP->current_user_can('ee_read_others_registrations', 'reg_per_event_report')) {
151
+			$extra_event_on_join = ' AND Event.post_author = '.get_current_user_id();
152 152
 		}
153 153
 
154 154
 		return $wpdb->get_results(
@@ -188,10 +188,10 @@  discard block
 block discarded – undo
188 188
 	 * @param string $reg_url_link
189 189
 	 * @return EE_Transaction
190 190
 	 */
191
-	public function get_transaction_from_reg_url_link( $reg_url_link = '' ){
192
-		return $this->get_one( array(
191
+	public function get_transaction_from_reg_url_link($reg_url_link = '') {
192
+		return $this->get_one(array(
193 193
 			array(
194
-				'Registration.REG_url_link' => ! empty( $reg_url_link ) ? $reg_url_link : EE_Registry::instance()->REQ->get( 'e_reg_url_link', '' )
194
+				'Registration.REG_url_link' => ! empty($reg_url_link) ? $reg_url_link : EE_Registry::instance()->REQ->get('e_reg_url_link', '')
195 195
 			)
196 196
 		));
197 197
 	}
@@ -208,16 +208,16 @@  discard block
 block discarded – undo
208 208
 	 * @return boolean
209 209
 	 * @throws \EE_Error
210 210
 	 */
211
-	public function update_based_on_payments( $transaction_obj_or_id, $save_txn = TRUE ){
211
+	public function update_based_on_payments($transaction_obj_or_id, $save_txn = TRUE) {
212 212
 		EE_Error::doing_it_wrong(
213
-			__CLASS__ . '::' . __FUNCTION__,
214
-			sprintf( __( 'This method is deprecated. Please use "%s" instead', 'event_espresso' ), 'EE_Transaction_Processor::update_transaction_and_registrations_after_checkout_or_payment()' ),
213
+			__CLASS__.'::'.__FUNCTION__,
214
+			sprintf(__('This method is deprecated. Please use "%s" instead', 'event_espresso'), 'EE_Transaction_Processor::update_transaction_and_registrations_after_checkout_or_payment()'),
215 215
 			'4.6.0'
216 216
 		);
217 217
 		/** @type EE_Transaction_Processor $transaction_processor */
218
-		$transaction_processor = EE_Registry::instance()->load_class( 'Transaction_Processor' );
218
+		$transaction_processor = EE_Registry::instance()->load_class('Transaction_Processor');
219 219
 		return $transaction_processor->update_transaction_and_registrations_after_checkout_or_payment(
220
-			$this->ensure_is_obj( $transaction_obj_or_id )
220
+			$this->ensure_is_obj($transaction_obj_or_id)
221 221
 		);
222 222
 	}
223 223
 
@@ -249,7 +249,7 @@  discard block
 block discarded – undo
249 249
 			array(
250 250
 				0 => array(
251 251
 					'STS_ID' => EEM_Transaction::failed_status_code,
252
-					'TXN_timestamp' => array( '<', time() - $time_to_leave_alone )
252
+					'TXN_timestamp' => array('<', time() - $time_to_leave_alone)
253 253
 				)
254 254
 			),
255 255
 			$time_to_leave_alone
@@ -262,29 +262,29 @@  discard block
 block discarded – undo
262 262
 		 */
263 263
 		$txn_ids = apply_filters(
264 264
 			'FHEE__EEM_Transaction__delete_junk_transactions__transaction_ids_to_delete',
265
-			EEM_Transaction::instance()->get_col( $ids_query, 'TXN_ID' ),
265
+			EEM_Transaction::instance()->get_col($ids_query, 'TXN_ID'),
266 266
 			$time_to_leave_alone
267 267
 		);
268 268
 		//now that we have the ids to delete
269
-		if ( ! empty( $txn_ids ) && is_array( $txn_ids ) ) {
269
+		if ( ! empty($txn_ids) && is_array($txn_ids)) {
270 270
 			// first, make sure these TXN's are removed the "ee_locked_transactions" array
271
-			EEM_Transaction::unset_locked_transactions( $txn_ids );
271
+			EEM_Transaction::unset_locked_transactions($txn_ids);
272 272
 			// let's get deletin'...
273 273
 			// Why no wpdb->prepare?  Because the data is trusted.
274 274
 			// We got the ids from the original query to get them FROM
275 275
 			// the db (which is sanitized) so no need to prepare them again.
276
-			$query   = '
276
+			$query = '
277 277
 				DELETE
278
-				FROM ' . $this->table() . '
278
+				FROM ' . $this->table().'
279 279
 				WHERE
280
-					TXN_ID IN ( ' . implode( ",", $txn_ids ) . ')';
281
-			$deleted = $wpdb->query( $query );
280
+					TXN_ID IN ( ' . implode(",", $txn_ids).')';
281
+			$deleted = $wpdb->query($query);
282 282
 		}
283
-		if ( $deleted ) {
283
+		if ($deleted) {
284 284
 			/**
285 285
 			 * Allows code to do something after the transactions have been deleted.
286 286
 			 */
287
-			do_action( 'AHEE__EEM_Transaction__delete_junk_transactions__successful_deletion', $txn_ids );
287
+			do_action('AHEE__EEM_Transaction__delete_junk_transactions__successful_deletion', $txn_ids);
288 288
 		}
289 289
 		return $deleted;
290 290
 	}
@@ -295,17 +295,17 @@  discard block
 block discarded – undo
295 295
 	 * @param array $transaction_IDs
296 296
 	 * @return bool
297 297
 	 */
298
-	public static function unset_locked_transactions( array $transaction_IDs ) {
299
-		$locked_transactions = get_option( 'ee_locked_transactions', array() );
298
+	public static function unset_locked_transactions(array $transaction_IDs) {
299
+		$locked_transactions = get_option('ee_locked_transactions', array());
300 300
 		$update = false;
301
-		foreach ( $transaction_IDs as $TXN_ID ) {
302
-			if ( isset( $locked_transactions[ $TXN_ID ] ) ) {
303
-				unset( $locked_transactions[ $TXN_ID ] );
301
+		foreach ($transaction_IDs as $TXN_ID) {
302
+			if (isset($locked_transactions[$TXN_ID])) {
303
+				unset($locked_transactions[$TXN_ID]);
304 304
 				$update = true;
305 305
 			}
306 306
 		}
307
-		if ( $update ) {
308
-			update_option( 'ee_locked_transactions', $locked_transactions );
307
+		if ($update) {
308
+			update_option('ee_locked_transactions', $locked_transactions);
309 309
 		}
310 310
 		return $update;
311 311
 	}
Please login to merge, or discard this patch.