Completed
Branch FET-8347-separate-logging (f2247f)
by
unknown
39:36 queued 30:33
created
core/db_classes/EE_Taxes.class.php 2 patches
Braces   +3 added lines, -2 removed lines patch added patch discarded remove patch
@@ -36,8 +36,9 @@
 block discarded – undo
36 36
 		$tax = 0;
37 37
 		$total_tax = 0;
38 38
 		//This first checks to see if the given ticket is taxable.
39
-		if ( ! $ticket->get( 'TKT_taxable' ) )
40
-			return $tax;
39
+		if ( ! $ticket->get( 'TKT_taxable' ) ) {
40
+					return $tax;
41
+		}
41 42
 		//get subtotal (notice we're only retrieving a subtotal if there isn't one given)
42 43
 		$subtotal = self::get_subtotal_for_admin( $ticket );
43 44
 		//get taxes
Please login to merge, or discard this patch.
Spacing   +18 added lines, -18 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
  * Taxes class
@@ -32,20 +32,20 @@  discard block
 block discarded – undo
32 32
 	 * @param  EE_Ticket $ticket incoming EE_Ticket
33 33
 	 * @return float             total taxes to apply to ticket.
34 34
 	 */
35
-	public static function get_total_taxes_for_admin( EE_Ticket $ticket ) {
35
+	public static function get_total_taxes_for_admin(EE_Ticket $ticket) {
36 36
 		$tax = 0;
37 37
 		$total_tax = 0;
38 38
 		//This first checks to see if the given ticket is taxable.
39
-		if ( ! $ticket->get( 'TKT_taxable' ) )
39
+		if ( ! $ticket->get('TKT_taxable'))
40 40
 			return $tax;
41 41
 		//get subtotal (notice we're only retrieving a subtotal if there isn't one given)
42
-		$subtotal = self::get_subtotal_for_admin( $ticket );
42
+		$subtotal = self::get_subtotal_for_admin($ticket);
43 43
 		//get taxes
44 44
 		$taxes = self::get_taxes_for_admin();
45 45
 		//apply taxes to subtotal
46
-		foreach ( $taxes as $tax ) {
46
+		foreach ($taxes as $tax) {
47 47
 			//assuming taxes are not cumulative
48
-			$total_tax += $subtotal * $tax->get( 'PRC_amount' ) / 100;
48
+			$total_tax += $subtotal * $tax->get('PRC_amount') / 100;
49 49
 		}
50 50
 		return $total_tax;
51 51
 	}
@@ -56,9 +56,9 @@  discard block
 block discarded – undo
56 56
 	 * @param EE_Ticket $ticket
57 57
 	 * @return float
58 58
 	 */
59
-	public static function get_subtotal_for_admin( EE_Ticket $ticket ) {
59
+	public static function get_subtotal_for_admin(EE_Ticket $ticket) {
60 60
 		$TKT_ID = $ticket->ID();
61
-		return isset( self::$_subtotal[ $TKT_ID ] ) ? self::$_subtotal[ $TKT_ID ] : self::_get_subtotal_for_admin( $ticket );
61
+		return isset(self::$_subtotal[$TKT_ID]) ? self::$_subtotal[$TKT_ID] : self::_get_subtotal_for_admin($ticket);
62 62
 	}
63 63
 
64 64
 
@@ -68,26 +68,26 @@  discard block
 block discarded – undo
68 68
 	 * @param  EE_Ticket $ticket
69 69
 	 * @return float     subtotal calculated from all EE_Price[] on Ticket.
70 70
 	 */
71
-	private static function _get_subtotal_for_admin( EE_Ticket $ticket ) {
71
+	private static function _get_subtotal_for_admin(EE_Ticket $ticket) {
72 72
 		$subtotal = 0;
73 73
 		//get all prices
74
-		$prices = $ticket->get_many_related( 'Price', array( 'default_where_conditions' => 'none', 'order_by' => array( 'PRC_order' => 'ASC' ) ) );
74
+		$prices = $ticket->get_many_related('Price', array('default_where_conditions' => 'none', 'order_by' => array('PRC_order' => 'ASC')));
75 75
 		//let's loop through them (base price is always the first item)
76
-		foreach ( $prices as $price ) {
77
-			if ( $price instanceof EE_Price ) {
78
-				switch ( $price->type_obj()->base_type() ) {
76
+		foreach ($prices as $price) {
77
+			if ($price instanceof EE_Price) {
78
+				switch ($price->type_obj()->base_type()) {
79 79
 					case 1: // base price
80 80
 					case 3: // surcharges
81
-						$subtotal += $price->is_percent() ? $subtotal * $price->get( 'PRC_amount' ) / 100 : $price->get( 'PRC_amount' );
81
+						$subtotal += $price->is_percent() ? $subtotal * $price->get('PRC_amount') / 100 : $price->get('PRC_amount');
82 82
 						break;
83 83
 					case 2: // discounts
84
-						$subtotal -= $price->is_percent() ? $subtotal * $price->get( 'PRC_amount' ) / 100 : $price->get( 'PRC_amount' );
84
+						$subtotal -= $price->is_percent() ? $subtotal * $price->get('PRC_amount') / 100 : $price->get('PRC_amount');
85 85
 						break;
86 86
 				}
87 87
 			}
88 88
 		}
89 89
 		$TKT_ID = $ticket->ID();
90
-		self::$_subtotal = array( $TKT_ID => $subtotal );
90
+		self::$_subtotal = array($TKT_ID => $subtotal);
91 91
 		return $subtotal;
92 92
 	}
93 93
 
@@ -98,7 +98,7 @@  discard block
 block discarded – undo
98 98
 	 * @return EE_Price[] EE_Price objects that have PRT_ID == 4
99 99
 	 */
100 100
 	public static function get_taxes_for_admin() {
101
-		self::$_default_taxes = ! empty( self::$_default_taxes ) ? self::$_default_taxes : EE_Registry::instance()->load_model( 'Price' )->get_all( array( array( 'Price_Type.PBT_ID' => 4 ) ) );
101
+		self::$_default_taxes = ! empty(self::$_default_taxes) ? self::$_default_taxes : EE_Registry::instance()->load_model('Price')->get_all(array(array('Price_Type.PBT_ID' => 4)));
102 102
 		return self::$_default_taxes;
103 103
 	}
104 104
 
Please login to merge, or discard this patch.
core/db_classes/EE_Term_Relationship.class.php 1 patch
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1
-<?php if ( !defined( 'EVENT_ESPRESSO_VERSION' ) ) {
2
-	exit( 'No direct script access allowed' );
1
+<?php if ( ! defined('EVENT_ESPRESSO_VERSION')) {
2
+	exit('No direct script access allowed');
3 3
 }
4 4
 /**
5 5
  * Event Espresso
@@ -30,9 +30,9 @@  discard block
 block discarded – undo
30 30
 	 * @param array $props_n_values
31 31
 	 * @return EE_Term_Relationship
32 32
 	 */
33
-	public static function new_instance( $props_n_values = array() ) {
34
-		$has_object = parent::_check_for_object( $props_n_values, __CLASS__ );
35
-		return $has_object ? $has_object : new self( $props_n_values );
33
+	public static function new_instance($props_n_values = array()) {
34
+		$has_object = parent::_check_for_object($props_n_values, __CLASS__);
35
+		return $has_object ? $has_object : new self($props_n_values);
36 36
 	}
37 37
 
38 38
 
@@ -41,8 +41,8 @@  discard block
 block discarded – undo
41 41
 	 * @param array $props_n_values
42 42
 	 * @return EE_Term_Relationship
43 43
 	 */
44
-	public static function new_instance_from_db( $props_n_values = array() ) {
45
-		return new self( $props_n_values, TRUE );
44
+	public static function new_instance_from_db($props_n_values = array()) {
45
+		return new self($props_n_values, TRUE);
46 46
 	}
47 47
 
48 48
 
Please login to merge, or discard this patch.
core/db_classes/EE_Ticket_Price.class.php 1 patch
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1
-<?php if ( ! defined( 'EVENT_ESPRESSO_VERSION' ) ) {
2
-	exit( 'No direct script access allowed' );
1
+<?php if ( ! defined('EVENT_ESPRESSO_VERSION')) {
2
+	exit('No direct script access allowed');
3 3
 }
4 4
 /**
5 5
  * Event Espresso
@@ -35,9 +35,9 @@  discard block
 block discarded – undo
35 35
 	 * @param string $timezone
36 36
 	 * @return EE_Ticket_Price|mixed
37 37
 	 */
38
-	public static function new_instance( $props_n_values = array(), $timezone = '' ) {
39
-		$has_object = parent::_check_for_object( $props_n_values, __CLASS__, $timezone );
40
-		return $has_object ? $has_object : new self( $props_n_values, FALSE, $timezone );
38
+	public static function new_instance($props_n_values = array(), $timezone = '') {
39
+		$has_object = parent::_check_for_object($props_n_values, __CLASS__, $timezone);
40
+		return $has_object ? $has_object : new self($props_n_values, FALSE, $timezone);
41 41
 	}
42 42
 
43 43
 
@@ -47,8 +47,8 @@  discard block
 block discarded – undo
47 47
 	 * @param string $timezone
48 48
 	 * @return EE_Ticket_Price
49 49
 	 */
50
-	public static function new_instance_from_db( $props_n_values = array(), $timezone = '' ) {
51
-		return new self( $props_n_values, TRUE, $timezone );
50
+	public static function new_instance_from_db($props_n_values = array(), $timezone = '') {
51
+		return new self($props_n_values, TRUE, $timezone);
52 52
 	}
53 53
 
54 54
 
Please login to merge, or discard this patch.
core/db_classes/EE_Ticket_Template.class.php 1 patch
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1
-<?php if ( ! defined( 'EVENT_ESPRESSO_VERSION' ) ) {
2
-	exit( 'No direct script access allowed' );
1
+<?php if ( ! defined('EVENT_ESPRESSO_VERSION')) {
2
+	exit('No direct script access allowed');
3 3
 }
4 4
 /**
5 5
  * Event Espresso
@@ -35,9 +35,9 @@  discard block
 block discarded – undo
35 35
 	 * @param string $timezone
36 36
 	 * @return EE_Ticket_Template|mixed
37 37
 	 */
38
-	public static function new_instance( $props_n_values = array(), $timezone = '' ) {
39
-		$has_object = parent::_check_for_object( $props_n_values, __CLASS__, $timezone );
40
-		return $has_object ? $has_object : new self( $props_n_values, FALSE, $timezone );
38
+	public static function new_instance($props_n_values = array(), $timezone = '') {
39
+		$has_object = parent::_check_for_object($props_n_values, __CLASS__, $timezone);
40
+		return $has_object ? $has_object : new self($props_n_values, FALSE, $timezone);
41 41
 	}
42 42
 
43 43
 
@@ -47,8 +47,8 @@  discard block
 block discarded – undo
47 47
 	 * @param string $timezone
48 48
 	 * @return EE_Ticket_Template
49 49
 	 */
50
-	public static function new_instance_from_db( $props_n_values = array(), $timezone = '' ) {
51
-		return new self( $props_n_values, TRUE, $timezone );
50
+	public static function new_instance_from_db($props_n_values = array(), $timezone = '') {
51
+		return new self($props_n_values, TRUE, $timezone);
52 52
 	}
53 53
 
54 54
 
Please login to merge, or discard this patch.
core/db_classes/EE_Transaction.class.php 3 patches
Braces   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -742,11 +742,11 @@
 block discarded – undo
742 742
 		$pm = $this->get_first_related('Payment_Method');
743 743
 		if( $pm instanceof EE_Payment_Method ){
744 744
 			return $pm;
745
-		}else{
745
+		} else{
746 746
 			$last_payment = $this->last_payment();
747 747
 			if( $last_payment instanceof EE_Payment && $last_payment->payment_method() ){
748 748
 				return $last_payment->payment_method();
749
-			}else{
749
+			} else{
750 750
 				return NULL;
751 751
 			}
752 752
 		}
Please login to merge, or discard this patch.
Doc Comments   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -209,7 +209,7 @@  discard block
 block discarded – undo
209 209
 	/**
210 210
 	 *        get Transaction Total
211 211
 	 * @access        public
212
-	 * @return float
212
+	 * @return boolean
213 213
 	 */
214 214
 	public function total() {
215 215
 		return $this->get( 'TXN_total' );
@@ -220,7 +220,7 @@  discard block
 block discarded – undo
220 220
 	/**
221 221
 	 *        get Total Amount Paid to Date
222 222
 	 * @access        public
223
-	 * @return float
223
+	 * @return boolean
224 224
 	 */
225 225
 	public function paid() {
226 226
 		return $this->get( 'TXN_paid' );
@@ -322,7 +322,7 @@  discard block
 block discarded – undo
322 322
 	/**
323 323
 	 * Gets all the attendees for this transaction (handy for use with EE_Attendee's get_registrations_for_event function
324 324
 	 * for getting attendees and how many registrations they each have for an event)
325
-	 * @return mixed EE_Attendee[] by default, int if $output is set to 'COUNT'
325
+	 * @return EE_Base_Class[] EE_Attendee[] by default, int if $output is set to 'COUNT'
326 326
 	 */
327 327
 	public function attendees() {
328 328
 		return $this->get_many_related( 'Attendee', array( array( 'Registration.Transaction.TXN_ID' => $this->ID() ) ) );
@@ -567,7 +567,7 @@  discard block
 block discarded – undo
567 567
 	/**
568 568
 	 * Gets all the extra meta info on this payment
569 569
 	 * @param array $query_params like EEM_Base::get_all
570
-	 * @return EE_Extra_Meta
570
+	 * @return EE_Base_Class[]
571 571
 	 */
572 572
 	public function extra_meta( $query_params = array() ) {
573 573
 		return $this->get_many_related( 'Extra_Meta', $query_params );
@@ -714,7 +714,7 @@  discard block
 block discarded – undo
714 714
 
715 715
 	/**
716 716
 	 * Gets PMD_ID
717
-	 * @return int
717
+	 * @return boolean
718 718
 	 */
719 719
 	function payment_method_ID() {
720 720
 		return $this->get('PMD_ID');
@@ -725,7 +725,7 @@  discard block
 block discarded – undo
725 725
 	/**
726 726
 	 * Sets PMD_ID
727 727
 	 * @param int $PMD_ID
728
-	 * @return boolean
728
+	 * @return boolean|null
729 729
 	 */
730 730
 	function set_payment_method_ID($PMD_ID) {
731 731
 		$this->set('PMD_ID', $PMD_ID);
Please login to merge, or discard this patch.
Spacing   +112 added lines, -112 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
@@ -26,7 +26,7 @@  discard block
 block discarded – undo
26 26
  * @subpackage 	includes/classes/EE_Transaction.class.php
27 27
  * @author 				Brent Christensen
28 28
  */
29
-class EE_Transaction extends EE_Base_Class implements EEI_Transaction{
29
+class EE_Transaction extends EE_Base_Class implements EEI_Transaction {
30 30
 
31 31
 
32 32
 	/**
@@ -35,9 +35,9 @@  discard block
 block discarded – undo
35 35
 	 * @param string $timezone
36 36
 	 * @return EE_Transaction
37 37
 	 */
38
-	public static function new_instance( $props_n_values = array(), $timezone = '' ) {
39
-		$has_object = parent::_check_for_object( $props_n_values, __CLASS__ );
40
-		return $has_object ? $has_object : new self( $props_n_values, FALSE, $timezone );
38
+	public static function new_instance($props_n_values = array(), $timezone = '') {
39
+		$has_object = parent::_check_for_object($props_n_values, __CLASS__);
40
+		return $has_object ? $has_object : new self($props_n_values, FALSE, $timezone);
41 41
 	}
42 42
 
43 43
 
@@ -48,8 +48,8 @@  discard block
 block discarded – undo
48 48
 	 * @param string $timezone
49 49
 	 * @return EE_Transaction
50 50
 	 */
51
-	public static function new_instance_from_db( $props_n_values = array(), $timezone = '' ) {
52
-		return new self( $props_n_values, TRUE, $timezone );
51
+	public static function new_instance_from_db($props_n_values = array(), $timezone = '') {
52
+		return new self($props_n_values, TRUE, $timezone);
53 53
 	}
54 54
 
55 55
 
@@ -64,9 +64,9 @@  discard block
 block discarded – undo
64 64
 	 * @return 	void
65 65
 	 */
66 66
 	public function lock() {
67
-		$locked_transactions = get_option( 'ee_locked_transactions', array() );
68
-		$locked_transactions[ $this->ID() ] = true;
69
-		update_option( 'ee_locked_transactions', $locked_transactions );
67
+		$locked_transactions = get_option('ee_locked_transactions', array());
68
+		$locked_transactions[$this->ID()] = true;
69
+		update_option('ee_locked_transactions', $locked_transactions);
70 70
 	}
71 71
 
72 72
 
@@ -80,9 +80,9 @@  discard block
 block discarded – undo
80 80
 	 * @return 	void
81 81
 	 */
82 82
 	public function unlock() {
83
-		$locked_transactions = get_option( 'ee_locked_transactions', array() );
84
-		unset( $locked_transactions[ $this->ID() ] );
85
-		update_option( 'ee_locked_transactions', $locked_transactions );
83
+		$locked_transactions = get_option('ee_locked_transactions', array());
84
+		unset($locked_transactions[$this->ID()]);
85
+		update_option('ee_locked_transactions', $locked_transactions);
86 86
 	}
87 87
 
88 88
 	/**
@@ -99,8 +99,8 @@  discard block
 block discarded – undo
99 99
 	 * @return boolean
100 100
 	 */
101 101
 	public function is_locked() {
102
-		$locked_transactions = get_option( 'ee_locked_transactions', array() );
103
-		return isset( $locked_transactions[ $this->ID() ] ) ? true : false;
102
+		$locked_transactions = get_option('ee_locked_transactions', array());
103
+		return isset($locked_transactions[$this->ID()]) ? true : false;
104 104
 	}
105 105
 
106 106
 
@@ -111,8 +111,8 @@  discard block
 block discarded – undo
111 111
 	 * @access        public
112 112
 	 * @param        float $total total value of transaction
113 113
 	 */
114
-	public function set_total( $total = 0.00 ) {
115
-		$this->set( 'TXN_total', $total );
114
+	public function set_total($total = 0.00) {
115
+		$this->set('TXN_total', $total);
116 116
 	}
117 117
 
118 118
 
@@ -123,8 +123,8 @@  discard block
 block discarded – undo
123 123
 	 * @access        public
124 124
 	 * @param        float $total_paid total amount paid to date (sum of all payments)
125 125
 	 */
126
-	public function set_paid( $total_paid = 0.00 ) {
127
-		$this->set( 'TXN_paid', $total_paid );
126
+	public function set_paid($total_paid = 0.00) {
127
+		$this->set('TXN_paid', $total_paid);
128 128
 	}
129 129
 
130 130
 
@@ -135,8 +135,8 @@  discard block
 block discarded – undo
135 135
 	 * @access        public
136 136
 	 * @param        string $status whether the transaction is open, declined, accepted, or any number of custom values that can be set
137 137
 	 */
138
-	public function set_status( $status = '' ) {
139
-		$this->set( 'STS_ID', $status );
138
+	public function set_status($status = '') {
139
+		$this->set('STS_ID', $status);
140 140
 	}
141 141
 
142 142
 
@@ -147,8 +147,8 @@  discard block
 block discarded – undo
147 147
 	 * @access        public
148 148
 	 * @param        string $hash_salt required for some payment gateways
149 149
 	 */
150
-	public function set_hash_salt( $hash_salt = '' ) {
151
-		$this->set( 'TXN_hash_salt', $hash_salt );
150
+	public function set_hash_salt($hash_salt = '') {
151
+		$this->set('TXN_hash_salt', $hash_salt);
152 152
 	}
153 153
 
154 154
 
@@ -157,8 +157,8 @@  discard block
 block discarded – undo
157 157
 	 * Sets TXN_reg_steps array
158 158
 	 * @param array $txn_reg_steps
159 159
 	 */
160
-	function set_reg_steps( $txn_reg_steps ) {
161
-		$this->set( 'TXN_reg_steps', $txn_reg_steps );
160
+	function set_reg_steps($txn_reg_steps) {
161
+		$this->set('TXN_reg_steps', $txn_reg_steps);
162 162
 	}
163 163
 
164 164
 
@@ -168,8 +168,8 @@  discard block
 block discarded – undo
168 168
 	 * @return array
169 169
 	 */
170 170
 	function reg_steps() {
171
-		$TXN_reg_steps = $this->get( 'TXN_reg_steps' );
172
-		return is_array( $TXN_reg_steps ) ? $TXN_reg_steps : array();
171
+		$TXN_reg_steps = $this->get('TXN_reg_steps');
172
+		return is_array($TXN_reg_steps) ? $TXN_reg_steps : array();
173 173
 	}
174 174
 
175 175
 
@@ -179,7 +179,7 @@  discard block
 block discarded – undo
179 179
 	 * @return string of transaction's total cost, with currency symbol and decimal
180 180
 	 */
181 181
 	public function pretty_total() {
182
-		return $this->get_pretty( 'TXN_total' );
182
+		return $this->get_pretty('TXN_total');
183 183
 	}
184 184
 
185 185
 
@@ -189,7 +189,7 @@  discard block
 block discarded – undo
189 189
 	 * @return string
190 190
 	 */
191 191
 	public function pretty_paid() {
192
-		return $this->get_pretty( 'TXN_paid' );
192
+		return $this->get_pretty('TXN_paid');
193 193
 	}
194 194
 
195 195
 
@@ -201,7 +201,7 @@  discard block
 block discarded – undo
201 201
 	 * @return float amount remaining
202 202
 	 */
203 203
 	public function remaining() {
204
-		return (float)( $this->total() - $this->paid() );
204
+		return (float) ($this->total() - $this->paid());
205 205
 	}
206 206
 
207 207
 
@@ -212,7 +212,7 @@  discard block
 block discarded – undo
212 212
 	 * @return float
213 213
 	 */
214 214
 	public function total() {
215
-		return $this->get( 'TXN_total' );
215
+		return $this->get('TXN_total');
216 216
 	}
217 217
 
218 218
 
@@ -223,7 +223,7 @@  discard block
 block discarded – undo
223 223
 	 * @return float
224 224
 	 */
225 225
 	public function paid() {
226
-		return $this->get( 'TXN_paid' );
226
+		return $this->get('TXN_paid');
227 227
 	}
228 228
 
229 229
 
@@ -233,8 +233,8 @@  discard block
 block discarded – undo
233 233
 	 * @access        public
234 234
 	 */
235 235
 	public function get_cart_session() {
236
-		$session_data = $this->get( 'TXN_session_data' );
237
-		return isset( $session_data[ 'cart' ] ) && $session_data[ 'cart' ] instanceof EE_Cart ? $session_data[ 'cart' ] : NULL;
236
+		$session_data = $this->get('TXN_session_data');
237
+		return isset($session_data['cart']) && $session_data['cart'] instanceof EE_Cart ? $session_data['cart'] : NULL;
238 238
 	}
239 239
 
240 240
 
@@ -244,9 +244,9 @@  discard block
 block discarded – undo
244 244
 	 * @access        public
245 245
 	 */
246 246
 	public function session_data() {
247
-		$session_data = $this->get( 'TXN_session_data' );
248
-		if ( empty( $session_data ) ) {
249
-			$session_data = array( 'id' => NULL, 'user_id' => NULL, 'ip_address' => NULL, 'user_agent' => NULL, 'init_access' => NULL, 'last_access' => NULL, 'pages_visited' => array() );
247
+		$session_data = $this->get('TXN_session_data');
248
+		if (empty($session_data)) {
249
+			$session_data = array('id' => NULL, 'user_id' => NULL, 'ip_address' => NULL, 'user_agent' => NULL, 'init_access' => NULL, 'last_access' => NULL, 'pages_visited' => array());
250 250
 		}
251 251
 		return $session_data;
252 252
 	}
@@ -259,11 +259,11 @@  discard block
 block discarded – undo
259 259
 	 * @access        public
260 260
 	 * @param        EE_Session|array $session_data
261 261
 	 */
262
-	public function set_txn_session_data( $session_data ) {
263
-		if ( $session_data instanceof EE_Session ) {
264
-			$this->set( 'TXN_session_data', $session_data->get_session_data( NULL, TRUE ));
262
+	public function set_txn_session_data($session_data) {
263
+		if ($session_data instanceof EE_Session) {
264
+			$this->set('TXN_session_data', $session_data->get_session_data(NULL, TRUE));
265 265
 		} else {
266
-			$this->set( 'TXN_session_data', $session_data );
266
+			$this->set('TXN_session_data', $session_data);
267 267
 		}
268 268
 	}
269 269
 
@@ -274,7 +274,7 @@  discard block
 block discarded – undo
274 274
 	 * @access        public
275 275
 	 */
276 276
 	public function hash_salt_() {
277
-		return $this->get( 'TXN_hash_salt' );
277
+		return $this->get('TXN_hash_salt');
278 278
 	}
279 279
 
280 280
 
@@ -293,13 +293,13 @@  discard block
 block discarded – undo
293 293
 	 * @param 	boolean 	$gmt - whether to return a unix timestamp with UTC offset applied (default) or no UTC offset applied
294 294
 	 * @return 	string | int
295 295
 	 */
296
-	public function datetime( $format = FALSE, $gmt = FALSE ) {
297
-		if ( $format ) {
298
-			return $this->get_pretty( 'TXN_timestamp' );
299
-		} else if ( $gmt ) {
300
-			return $this->get_raw( 'TXN_timestamp' );
296
+	public function datetime($format = FALSE, $gmt = FALSE) {
297
+		if ($format) {
298
+			return $this->get_pretty('TXN_timestamp');
299
+		} else if ($gmt) {
300
+			return $this->get_raw('TXN_timestamp');
301 301
 		} else {
302
-			return $this->get( 'TXN_timestamp' );
302
+			return $this->get('TXN_timestamp');
303 303
 		}
304 304
 	}
305 305
 
@@ -311,10 +311,10 @@  discard block
 block discarded – undo
311 311
 	 * @param        boolean $get_cached   TRUE to retrieve cached registrations or FALSE to pull from the db
312 312
 	 * @return EE_Registration[]
313 313
 	 */
314
-	public function registrations( $query_params = array(), $get_cached = FALSE ) {
315
-		$query_params = ( empty( $query_params ) || ! is_array( $query_params ) ) ? array( 'order_by' => array( 'Event.EVT_name' => 'ASC', 'Attendee.ATT_lname' => 'ASC', 'Attendee.ATT_fname' => 'ASC' ) ) : $query_params;
314
+	public function registrations($query_params = array(), $get_cached = FALSE) {
315
+		$query_params = (empty($query_params) || ! is_array($query_params)) ? array('order_by' => array('Event.EVT_name' => 'ASC', 'Attendee.ATT_lname' => 'ASC', 'Attendee.ATT_fname' => 'ASC')) : $query_params;
316 316
 		$query_params = $get_cached ? array() : $query_params;
317
-		return $this->get_many_related( 'Registration', $query_params );
317
+		return $this->get_many_related('Registration', $query_params);
318 318
 	}
319 319
 
320 320
 
@@ -325,7 +325,7 @@  discard block
 block discarded – undo
325 325
 	 * @return mixed EE_Attendee[] by default, int if $output is set to 'COUNT'
326 326
 	 */
327 327
 	public function attendees() {
328
-		return $this->get_many_related( 'Attendee', array( array( 'Registration.Transaction.TXN_ID' => $this->ID() ) ) );
328
+		return $this->get_many_related('Attendee', array(array('Registration.Transaction.TXN_ID' => $this->ID())));
329 329
 	}
330 330
 
331 331
 
@@ -335,8 +335,8 @@  discard block
 block discarded – undo
335 335
 	 * @param array $query_params like EEM_Base::get_all
336 336
 	 * @return EE_Payment[]
337 337
 	 */
338
-	public function payments( $query_params = array() ) {
339
-		return $this->get_many_related( 'Payment', $query_params );
338
+	public function payments($query_params = array()) {
339
+		return $this->get_many_related('Payment', $query_params);
340 340
 	}
341 341
 
342 342
 
@@ -346,8 +346,8 @@  discard block
 block discarded – undo
346 346
 	 * @return EE_Payment[]
347 347
 	 */
348 348
 	public function approved_payments() {
349
-		EE_Registry::instance()->load_model( 'Payment' );
350
-		return $this->get_many_related( 'Payment', array( array( 'STS_ID' => EEM_Payment::status_id_approved ), 'order_by' => array( 'PAY_timestamp' => 'DESC' ) ) );
349
+		EE_Registry::instance()->load_model('Payment');
350
+		return $this->get_many_related('Payment', array(array('STS_ID' => EEM_Payment::status_id_approved), 'order_by' => array('PAY_timestamp' => 'DESC')));
351 351
 	}
352 352
 
353 353
 
@@ -357,8 +357,8 @@  discard block
 block discarded – undo
357 357
 	 * @param bool $show_icons
358 358
 	 * @return string
359 359
 	 */
360
-	public function e_pretty_status( $show_icons = FALSE ) {
361
-		echo $this->pretty_status( $show_icons );
360
+	public function e_pretty_status($show_icons = FALSE) {
361
+		echo $this->pretty_status($show_icons);
362 362
 	}
363 363
 
364 364
 
@@ -368,10 +368,10 @@  discard block
 block discarded – undo
368 368
 	 * @param bool $show_icons
369 369
 	 * @return string
370 370
 	 */
371
-	public function pretty_status( $show_icons = FALSE ) {
372
-		$status = EEM_Status::instance()->localized_status( array( $this->status_ID() => __( 'unknown', 'event_espresso' ) ), FALSE, 'sentence' );
371
+	public function pretty_status($show_icons = FALSE) {
372
+		$status = EEM_Status::instance()->localized_status(array($this->status_ID() => __('unknown', 'event_espresso')), FALSE, 'sentence');
373 373
 		$icon = '';
374
-		switch ( $this->status_ID() ) {
374
+		switch ($this->status_ID()) {
375 375
 			case EEM_Transaction::complete_status_code:
376 376
 				$icon = $show_icons ? '<span class="dashicons dashicons-yes ee-icon-size-24 green-text"></span>' : '';
377 377
 				break;
@@ -388,7 +388,7 @@  discard block
 block discarded – undo
388 388
 				$icon = $show_icons ? '<span class="dashicons dashicons-plus ee-icon-size-16 orange-text"></span>' : '';
389 389
 				break;
390 390
 		}
391
-		return $icon . $status[ $this->status_ID() ];
391
+		return $icon.$status[$this->status_ID()];
392 392
 	}
393 393
 
394 394
 
@@ -398,7 +398,7 @@  discard block
 block discarded – undo
398 398
 	 * @access        public
399 399
 	 */
400 400
 	public function status_ID() {
401
-		return $this->get( 'STS_ID' );
401
+		return $this->get('STS_ID');
402 402
 	}
403 403
 
404 404
 
@@ -408,7 +408,7 @@  discard block
 block discarded – undo
408 408
 	 * @return boolean
409 409
 	 */
410 410
 	public function is_free() {
411
-		return (float)$this->get( 'TXN_total' ) == 0 ? TRUE : FALSE;
411
+		return (float) $this->get('TXN_total') == 0 ? TRUE : FALSE;
412 412
 	}
413 413
 
414 414
 
@@ -476,12 +476,12 @@  discard block
 block discarded – undo
476 476
 	 * @access public
477 477
 	 * @return string
478 478
 	 */
479
-	public function invoice_url( $type = 'html' ) {
479
+	public function invoice_url($type = 'html') {
480 480
 		$REG = $this->primary_registration();
481
-		if ( ! $REG instanceof EE_Registration ) {
481
+		if ( ! $REG instanceof EE_Registration) {
482 482
 			return '';
483 483
 		}
484
-		return $REG->invoice_url( $type );
484
+		return $REG->invoice_url($type);
485 485
 	}
486 486
 
487 487
 
@@ -491,7 +491,7 @@  discard block
 block discarded – undo
491 491
 	 * @return EE_Registration
492 492
 	 */
493 493
 	public function primary_registration() {
494
-		return $this->get_first_related( 'Registration', array( array( 'REG_count' => EEM_Registration::PRIMARY_REGISTRANT_COUNT ) ) );
494
+		return $this->get_first_related('Registration', array(array('REG_count' => EEM_Registration::PRIMARY_REGISTRANT_COUNT)));
495 495
 	}
496 496
 
497 497
 
@@ -501,12 +501,12 @@  discard block
 block discarded – undo
501 501
 	 * @param string $type 'pdf' or 'html' (default is 'html')
502 502
 	 * @return string
503 503
 	 */
504
-	public function receipt_url( $type = 'html' ) {
504
+	public function receipt_url($type = 'html') {
505 505
 		$REG = $this->primary_registration();
506
-		if ( ! $REG instanceof EE_Registration ) {
506
+		if ( ! $REG instanceof EE_Registration) {
507 507
 			return '';
508 508
 		}
509
-		return $REG->receipt_url( $type );
509
+		return $REG->receipt_url($type);
510 510
 	}
511 511
 
512 512
 
@@ -531,15 +531,15 @@  discard block
 block discarded – undo
531 531
 	 * @deprecated
532 532
 	 * @return boolean
533 533
 	 */
534
-	public function update_based_on_payments(){
534
+	public function update_based_on_payments() {
535 535
 		EE_Error::doing_it_wrong(
536
-			__CLASS__ . '::' . __FUNCTION__,
537
-			sprintf( __( 'This method is deprecated. Please use "%s" instead', 'event_espresso' ), 'EE_Transaction_Processor::update_transaction_and_registrations_after_checkout_or_payment()' ),
536
+			__CLASS__.'::'.__FUNCTION__,
537
+			sprintf(__('This method is deprecated. Please use "%s" instead', 'event_espresso'), 'EE_Transaction_Processor::update_transaction_and_registrations_after_checkout_or_payment()'),
538 538
 			'4.6.0'
539 539
 		);
540 540
 		/** @type EE_Transaction_Processor $transaction_processor */
541
-		$transaction_processor = EE_Registry::instance()->load_class( 'Transaction_Processor' );
542
-		return  $transaction_processor->update_transaction_and_registrations_after_checkout_or_payment( $this );
541
+		$transaction_processor = EE_Registry::instance()->load_class('Transaction_Processor');
542
+		return  $transaction_processor->update_transaction_and_registrations_after_checkout_or_payment($this);
543 543
 	}
544 544
 
545 545
 
@@ -548,7 +548,7 @@  discard block
 block discarded – undo
548 548
 	 * @return string
549 549
 	 */
550 550
 	public function gateway_response_on_transaction() {
551
-		$payment = $this->get_first_related( 'Payment' );
551
+		$payment = $this->get_first_related('Payment');
552 552
 		return $payment instanceof EE_Payment ? $payment->gateway_response() : '';
553 553
 	}
554 554
 
@@ -559,7 +559,7 @@  discard block
 block discarded – undo
559 559
 	 * @return EE_Status
560 560
 	 */
561 561
 	public function status_obj() {
562
-		return $this->get_first_related( 'Status' );
562
+		return $this->get_first_related('Status');
563 563
 	}
564 564
 
565 565
 
@@ -569,8 +569,8 @@  discard block
 block discarded – undo
569 569
 	 * @param array $query_params like EEM_Base::get_all
570 570
 	 * @return EE_Extra_Meta
571 571
 	 */
572
-	public function extra_meta( $query_params = array() ) {
573
-		return $this->get_many_related( 'Extra_Meta', $query_params );
572
+	public function extra_meta($query_params = array()) {
573
+		return $this->get_many_related('Extra_Meta', $query_params);
574 574
 	}
575 575
 
576 576
 
@@ -580,8 +580,8 @@  discard block
 block discarded – undo
580 580
 	 * @param EE_Registration $registration
581 581
 	 * @return EE_Base_Class the relation was added to
582 582
 	 */
583
-	public function add_registration( EE_Registration $registration ) {
584
-		return $this->_add_relation_to( $registration, 'Registration' );
583
+	public function add_registration(EE_Registration $registration) {
584
+		return $this->_add_relation_to($registration, 'Registration');
585 585
 	}
586 586
 
587 587
 
@@ -592,8 +592,8 @@  discard block
 block discarded – undo
592 592
 	 * @param int $registration_or_id
593 593
 	 * @return EE_Base_Class that was removed from being related
594 594
 	 */
595
-	public function remove_registration_with_id( $registration_or_id ) {
596
-		return $this->_remove_relation_to( $registration_or_id, 'Registration' );
595
+	public function remove_registration_with_id($registration_or_id) {
596
+		return $this->_remove_relation_to($registration_or_id, 'Registration');
597 597
 	}
598 598
 
599 599
 
@@ -603,7 +603,7 @@  discard block
 block discarded – undo
603 603
 	 * @return EE_Line_Item[]
604 604
 	 */
605 605
 	public function items_purchased() {
606
-		return $this->line_items( array( array( 'LIN_type' => EEM_Line_Item::type_line_item ) ) );
606
+		return $this->line_items(array(array('LIN_type' => EEM_Line_Item::type_line_item)));
607 607
 	}
608 608
 
609 609
 
@@ -613,8 +613,8 @@  discard block
 block discarded – undo
613 613
 	 * @param EE_Line_Item $line_item
614 614
 	 * @return EE_Base_Class the relation was added to
615 615
 	 */
616
-	public function add_line_item( EE_Line_Item $line_item ) {
617
-		return $this->_add_relation_to( $line_item, 'Line_Item' );
616
+	public function add_line_item(EE_Line_Item $line_item) {
617
+		return $this->_add_relation_to($line_item, 'Line_Item');
618 618
 	}
619 619
 
620 620
 
@@ -624,8 +624,8 @@  discard block
 block discarded – undo
624 624
 	 * @param array $query_params
625 625
 	 * @return EE_Line_Item[]
626 626
 	 */
627
-	public function line_items( $query_params = array() ) {
628
-		return $this->get_many_related( 'Line_Item', $query_params );
627
+	public function line_items($query_params = array()) {
628
+		return $this->get_many_related('Line_Item', $query_params);
629 629
 	}
630 630
 
631 631
 
@@ -635,7 +635,7 @@  discard block
 block discarded – undo
635 635
 	 * @return EE_Line_Item[]
636 636
 	 */
637 637
 	public function tax_items() {
638
-		return $this->line_items( array( array( 'LIN_type' => EEM_Line_Item::type_tax ) ) );
638
+		return $this->line_items(array(array('LIN_type' => EEM_Line_Item::type_tax)));
639 639
 	}
640 640
 
641 641
 
@@ -646,9 +646,9 @@  discard block
 block discarded – undo
646 646
 	 * @return EE_Line_Item
647 647
 	 */
648 648
 	public function total_line_item() {
649
-		$item =  $this->get_first_related( 'Line_Item', array( array( 'LIN_type' => EEM_Line_Item::type_total ) ) );
650
-		if( ! $item ){
651
-			EE_Registry::instance()->load_helper( 'Line_Item' );
649
+		$item = $this->get_first_related('Line_Item', array(array('LIN_type' => EEM_Line_Item::type_total)));
650
+		if ( ! $item) {
651
+			EE_Registry::instance()->load_helper('Line_Item');
652 652
 			$item = EEH_Line_Item::create_default_total_line_item();
653 653
 		}
654 654
 		return $item;
@@ -663,7 +663,7 @@  discard block
 block discarded – undo
663 663
 	 */
664 664
 	public function tax_total() {
665 665
 		$tax_line_item = $this->tax_total_line_item();
666
-		if ( $tax_line_item ) {
666
+		if ($tax_line_item) {
667 667
 			return $tax_line_item->total();
668 668
 		} else {
669 669
 			return 0;
@@ -677,9 +677,9 @@  discard block
 block discarded – undo
677 677
 	 * @return EE_Line_Item
678 678
 	 */
679 679
 	public function tax_total_line_item() {
680
-		$item =  $this->get_first_related( 'Line_Item', array( array( 'LIN_type' => EEM_Line_Item::type_tax_sub_total ) ) );
681
-		if( ! $item ){
682
-			EE_Registry::instance()->load_helper( 'Line_Item' );
680
+		$item = $this->get_first_related('Line_Item', array(array('LIN_type' => EEM_Line_Item::type_tax_sub_total)));
681
+		if ( ! $item) {
682
+			EE_Registry::instance()->load_helper('Line_Item');
683 683
 			$item = EEH_Line_Item::create_default_total_line_item();
684 684
 		}
685 685
 		return $item;
@@ -691,20 +691,20 @@  discard block
 block discarded – undo
691 691
 	 *  Gets the array of billing info for the gateway and for this transaction's primary registration's attendee.
692 692
 	 * @return EE_Form_Section_Proper
693 693
 	 */
694
-	public function billing_info(){
694
+	public function billing_info() {
695 695
 		$payment_method = $this->payment_method();
696
-		if ( !$payment_method){
696
+		if ( ! $payment_method) {
697 697
 			EE_Error::add_error(__("Could not find billing info for transaction because no gateway has been used for it yet", "event_espresso"), __FILE__, __FUNCTION__, __LINE__);
698 698
 			return false;
699 699
 		}
700 700
 		$primary_reg = $this->primary_registration();
701
-		if ( ! $primary_reg ) {
702
-			EE_Error::add_error( __( "Cannot get billing info for gateway %s on transaction because no primary registration exists", "event_espresso" ), __FILE__, __FUNCTION__, __LINE__ );
701
+		if ( ! $primary_reg) {
702
+			EE_Error::add_error(__("Cannot get billing info for gateway %s on transaction because no primary registration exists", "event_espresso"), __FILE__, __FUNCTION__, __LINE__);
703 703
 			return FALSE;
704 704
 		}
705 705
 		$attendee = $primary_reg->attendee();
706
-		if ( ! $attendee ) {
707
-			EE_Error::add_error( __( "Cannot get billing info for gateway %s on transaction because the primary registration has no attendee exists", "event_espresso" ), __FILE__, __FUNCTION__, __LINE__ );
706
+		if ( ! $attendee) {
707
+			EE_Error::add_error(__("Cannot get billing info for gateway %s on transaction because the primary registration has no attendee exists", "event_espresso"), __FILE__, __FUNCTION__, __LINE__);
708 708
 			return FALSE;
709 709
 		}
710 710
 		return $attendee->billing_info_for_payment_method($payment_method);
@@ -739,15 +739,15 @@  discard block
 block discarded – undo
739 739
 	 * offline ones, dont' create payments)
740 740
 	 * @return EE_Payment_Method
741 741
 	 */
742
-	function payment_method(){
742
+	function payment_method() {
743 743
 		$pm = $this->get_first_related('Payment_Method');
744
-		if( $pm instanceof EE_Payment_Method ){
744
+		if ($pm instanceof EE_Payment_Method) {
745 745
 			return $pm;
746
-		}else{
746
+		} else {
747 747
 			$last_payment = $this->last_payment();
748
-			if( $last_payment instanceof EE_Payment && $last_payment->payment_method() ){
748
+			if ($last_payment instanceof EE_Payment && $last_payment->payment_method()) {
749 749
 				return $last_payment->payment_method();
750
-			}else{
750
+			} else {
751 751
 				return NULL;
752 752
 			}
753 753
 		}
@@ -758,15 +758,15 @@  discard block
 block discarded – undo
758 758
 	 * @return EE_Payment
759 759
 	 */
760 760
 	public function last_payment() {
761
-		return $this->get_first_related( 'Payment', array( 'order_by' => array( 'PAY_ID' => 'desc' ) ) );
761
+		return $this->get_first_related('Payment', array('order_by' => array('PAY_ID' => 'desc')));
762 762
 	}
763 763
 
764 764
 	/**
765 765
 	 * Gets all the line items which are unrelated to tickets on this transaction
766 766
 	 * @return EE_Line_Item[]
767 767
 	 */
768
-	public function non_ticket_line_items(){
769
-		return EEM_Line_Item::instance()->get_all_non_ticket_line_items_for_transaction( $this->ID() );
768
+	public function non_ticket_line_items() {
769
+		return EEM_Line_Item::instance()->get_all_non_ticket_line_items_for_transaction($this->ID());
770 770
 	}
771 771
 
772 772
 
Please login to merge, or discard this patch.
core/db_classes/EE_WP_User.class.php 1 patch
Spacing   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1
-<?php if ( !defined( 'EVENT_ESPRESSO_VERSION' ) ) {
2
-	exit( 'No direct script access allowed' );
1
+<?php if ( ! defined('EVENT_ESPRESSO_VERSION')) {
2
+	exit('No direct script access allowed');
3 3
 }
4 4
 /**
5 5
  * EE_WP_User class
@@ -22,9 +22,9 @@  discard block
 block discarded – undo
22 22
 	 * @param array $props_n_values
23 23
 	 * @return EE_WP_User|mixed
24 24
 	 */
25
-	public static function new_instance( $props_n_values = array() ) {
26
-		$has_object = parent::_check_for_object( $props_n_values, __CLASS__ );
27
-		return $has_object ? $has_object : new self( $props_n_values );
25
+	public static function new_instance($props_n_values = array()) {
26
+		$has_object = parent::_check_for_object($props_n_values, __CLASS__);
27
+		return $has_object ? $has_object : new self($props_n_values);
28 28
 	}
29 29
 
30 30
 
@@ -33,8 +33,8 @@  discard block
 block discarded – undo
33 33
 	 * @param array $props_n_values
34 34
 	 * @return EE_WP_User
35 35
 	 */
36
-	public static function new_instance_from_db( $props_n_values = array() ) {
37
-		return new self( $props_n_values, TRUE );
36
+	public static function new_instance_from_db($props_n_values = array()) {
37
+		return new self($props_n_values, TRUE);
38 38
 	}
39 39
 
40 40
 	/**
@@ -42,8 +42,8 @@  discard block
 block discarded – undo
42 42
 	 * @return WP_User
43 43
 	 */
44 44
 	public function wp_user_obj() {
45
-		if( ! $this->_wp_user_obj ) {
46
-			$this->_wp_user_obj = get_user_by('ID', $this->ID() );
45
+		if ( ! $this->_wp_user_obj) {
46
+			$this->_wp_user_obj = get_user_by('ID', $this->ID());
47 47
 		}
48 48
 		return $this->_wp_user_obj;
49 49
 	}
Please login to merge, or discard this patch.
core/db_models/EEM_Answer.model.php 2 patches
Braces   +7 added lines, -5 removed lines patch added patch discarded remove patch
@@ -1,4 +1,6 @@  discard block
 block discarded – undo
1
-<?php if ( ! defined('EVENT_ESPRESSO_VERSION')) exit('No direct script access allowed');
1
+<?php if ( ! defined('EVENT_ESPRESSO_VERSION')) {
2
+	exit('No direct script access allowed');
3
+}
2 4
 /**
3 5
  * Event Espresso
4 6
  *
@@ -89,7 +91,7 @@  discard block
 block discarded – undo
89 91
 			if( $answer_obj instanceof EE_Answer ){
90 92
 				if($pretty_answer){
91 93
 					$value = $answer_obj->pretty_value();
92
-				}else{
94
+				} else{
93 95
 					$value = $answer_obj->value();
94 96
 				}
95 97
 			}
@@ -129,13 +131,13 @@  discard block
 block discarded – undo
129 131
 				if($field_name == 'STA_ID'){
130 132
 					$state = $registration->attendee()->state_obj();
131 133
 					$value = $state instanceof EE_State ? $state->name() : sprintf(__('Unknown State (%s)', 'event_espresso'),$registration->attendee()->state_ID());
132
-				}else if($field_name == 'CNT_ISO'){
134
+				} else if($field_name == 'CNT_ISO'){
133 135
 					$country = $registration->attendee()->country_obj();
134 136
 					$value = $country instanceof EE_Country ? $country->name() : sprintf(__('Unknown Country (%s)', "event_espresso"),$registration->attendee()->country_ID());
135
-				}else{
137
+				} else{
136 138
 					$value = $registration->attendee()->get_pretty($field_name);
137 139
 				}
138
-			}else{
140
+			} else{
139 141
 				$value = $registration->attendee()->get($field_name);
140 142
 			}
141 143
 		}
Please login to merge, or discard this patch.
Spacing   +29 added lines, -29 removed lines patch added patch discarded remove patch
@@ -50,18 +50,18 @@  discard block
 block discarded – undo
50 50
 	/**
51 51
 	 * 	constructor
52 52
 	 */
53
-	protected function __construct( $timezone = NULL ){
54
-		$this->singular_item = __('Answer','event_espresso');
55
-		$this->plural_item = __('Answers','event_espresso');
53
+	protected function __construct($timezone = NULL) {
54
+		$this->singular_item = __('Answer', 'event_espresso');
55
+		$this->plural_item = __('Answers', 'event_espresso');
56 56
 		$this->_tables = array(
57 57
 			'Answer'=> new EE_Primary_Table('esp_answer', 'ANS_ID')
58 58
 		);
59 59
 		$this->_fields = array(
60 60
 			'Answer'=>array(
61
-				'ANS_ID'=> new EE_Primary_Key_Int_Field('ANS_ID', __('Answer ID','event_espresso')),
62
-				'REG_ID'=>new EE_Foreign_Key_Int_Field('REG_ID', __('Registration ID','event_espresso'), false, 0, 'Registration'),
63
-				'QST_ID'=>new EE_Foreign_Key_Int_Field('QST_ID', __('Question ID','event_espresso'), false, 0, 'Question'),
64
-				'ANS_value'=>new EE_Maybe_Serialized_Text_Field('ANS_value', __('Answer Value','event_espresso'), false, '')
61
+				'ANS_ID'=> new EE_Primary_Key_Int_Field('ANS_ID', __('Answer ID', 'event_espresso')),
62
+				'REG_ID'=>new EE_Foreign_Key_Int_Field('REG_ID', __('Registration ID', 'event_espresso'), false, 0, 'Registration'),
63
+				'QST_ID'=>new EE_Foreign_Key_Int_Field('QST_ID', __('Question ID', 'event_espresso'), false, 0, 'Question'),
64
+				'ANS_value'=>new EE_Maybe_Serialized_Text_Field('ANS_value', __('Answer Value', 'event_espresso'), false, '')
65 65
 			));
66 66
 		$this->_model_relations = array(
67 67
 			'Registration'=>new EE_Belongs_To_Relation(),
@@ -69,7 +69,7 @@  discard block
 block discarded – undo
69 69
 		);
70 70
 		$this->_model_chain_to_wp_user = 'Registration.Event';
71 71
 		$this->_caps_slug = 'registrations';
72
-		parent::__construct( $timezone );
72
+		parent::__construct($timezone);
73 73
 	}
74 74
 
75 75
 
@@ -82,19 +82,19 @@  discard block
 block discarded – undo
82 82
 	 * @param boolean $pretty_answer whether to call 'pretty_value' or just 'value'
83 83
 	 * @return string
84 84
 	 */
85
-	public function get_answer_value_to_question( EE_Registration $registration, $question_id = NULL,$pretty_answer = FALSE ){
86
-		$value = $this->get_attendee_property_answer_value( $registration, $question_id, $pretty_answer );
87
-		if (  $value === NULL ){
88
-			$answer_obj = $this->get_registration_question_answer_object( $registration, $question_id, $pretty_answer );
89
-			if( $answer_obj instanceof EE_Answer ){
90
-				if($pretty_answer){
85
+	public function get_answer_value_to_question(EE_Registration $registration, $question_id = NULL, $pretty_answer = FALSE) {
86
+		$value = $this->get_attendee_property_answer_value($registration, $question_id, $pretty_answer);
87
+		if ($value === NULL) {
88
+			$answer_obj = $this->get_registration_question_answer_object($registration, $question_id, $pretty_answer);
89
+			if ($answer_obj instanceof EE_Answer) {
90
+				if ($pretty_answer) {
91 91
 					$value = $answer_obj->pretty_value();
92
-				}else{
92
+				} else {
93 93
 					$value = $answer_obj->value();
94 94
 				}
95 95
 			}
96 96
 		}
97
-		return apply_filters( 'FHEE__EEM_Answer__get_answer_value_to_question__answer_value', $value, $registration, $question_id );
97
+		return apply_filters('FHEE__EEM_Answer__get_answer_value_to_question__answer_value', $value, $registration, $question_id);
98 98
 	}
99 99
 
100 100
 
@@ -105,9 +105,9 @@  discard block
 block discarded – undo
105 105
 	 * @param int $question_id
106 106
 	 * @return EE_Answer
107 107
 	 */
108
-	public function get_registration_question_answer_object( EE_Registration $registration, $question_id = NULL){
109
-		$answer_obj = $this->get_one( array( array( 'QST_ID'=>$question_id, 'REG_ID'=>$registration->ID() )));
110
-		return apply_filters( 'FHEE__EEM_Answer__get_registration_question_answer_object__answer_obj', $answer_obj, $registration, $question_id );
108
+	public function get_registration_question_answer_object(EE_Registration $registration, $question_id = NULL) {
109
+		$answer_obj = $this->get_one(array(array('QST_ID'=>$question_id, 'REG_ID'=>$registration->ID())));
110
+		return apply_filters('FHEE__EEM_Answer__get_registration_question_answer_object__answer_obj', $answer_obj, $registration, $question_id);
111 111
 	}
112 112
 
113 113
 
@@ -119,27 +119,27 @@  discard block
 block discarded – undo
119 119
 	 * @param boolean $pretty_answer
120 120
 	 * @return string
121 121
 	 */
122
-	public function get_attendee_property_answer_value( EE_Registration $registration, $question_id = NULL, $pretty_answer = FALSE ){
122
+	public function get_attendee_property_answer_value(EE_Registration $registration, $question_id = NULL, $pretty_answer = FALSE) {
123 123
 		$field_name = NULL;
124 124
 		$value = NULL;
125 125
 		//only bother checking if the registration has an attendee
126
-		if( $registration->attendee() instanceof EE_Attendee && isset($this->_question_id_to_att_field_map[$question_id])){
126
+		if ($registration->attendee() instanceof EE_Attendee && isset($this->_question_id_to_att_field_map[$question_id])) {
127 127
 			$field_name = $this->_question_id_to_att_field_map[$question_id];
128
-			if($pretty_answer){
129
-				if($field_name == 'STA_ID'){
128
+			if ($pretty_answer) {
129
+				if ($field_name == 'STA_ID') {
130 130
 					$state = $registration->attendee()->state_obj();
131
-					$value = $state instanceof EE_State ? $state->name() : sprintf(__('Unknown State (%s)', 'event_espresso'),$registration->attendee()->state_ID());
132
-				}else if($field_name == 'CNT_ISO'){
131
+					$value = $state instanceof EE_State ? $state->name() : sprintf(__('Unknown State (%s)', 'event_espresso'), $registration->attendee()->state_ID());
132
+				} else if ($field_name == 'CNT_ISO') {
133 133
 					$country = $registration->attendee()->country_obj();
134
-					$value = $country instanceof EE_Country ? $country->name() : sprintf(__('Unknown Country (%s)', "event_espresso"),$registration->attendee()->country_ID());
135
-				}else{
134
+					$value = $country instanceof EE_Country ? $country->name() : sprintf(__('Unknown Country (%s)', "event_espresso"), $registration->attendee()->country_ID());
135
+				} else {
136 136
 					$value = $registration->attendee()->get_pretty($field_name);
137 137
 				}
138
-			}else{
138
+			} else {
139 139
 				$value = $registration->attendee()->get($field_name);
140 140
 			}
141 141
 		}
142
-		return apply_filters( 'FHEE__EEM_Answer__get_attendee_question_answer_value__answer_value', $value, $registration, $question_id );
142
+		return apply_filters('FHEE__EEM_Answer__get_attendee_question_answer_value__answer_value', $value, $registration, $question_id);
143 143
 	}
144 144
 
145 145
 
Please login to merge, or discard this patch.
core/db_models/EEM_Base.model.php 4 patches
Indentation   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -555,10 +555,10 @@
 block discarded – undo
555 555
 	 	$stati = EEM_Status::instance()->get_all(array(array('STS_type' => $status_type) ) );
556 556
 	 	$status_array = array();
557 557
 	 	foreach ( $stati as $status ) {
558
-            $status_array[ $status->ID() ] = $status->get('STS_code');
559
-        }
560
-        return $translated ? EEM_Status::instance()->localized_status($status_array, FALSE, 'sentence') : $status_array;
561
-    }
558
+			$status_array[ $status->ID() ] = $status->get('STS_code');
559
+		}
560
+		return $translated ? EEM_Status::instance()->localized_status($status_array, FALSE, 'sentence') : $status_array;
561
+	}
562 562
 
563 563
 
564 564
 
Please login to merge, or discard this patch.
Spacing   +885 added lines, -885 removed lines patch added patch discarded remove patch
@@ -23,7 +23,7 @@  discard block
 block discarded – undo
23 23
  * @since 				EE4
24 24
  *
25 25
  */
26
-abstract class EEM_Base extends EE_Base{
26
+abstract class EEM_Base extends EE_Base {
27 27
 
28 28
 		//admin posty
29 29
 	//basic -> grants access to mine -> if they don't have it, select none
@@ -228,7 +228,7 @@  discard block
 block discarded – undo
228 228
 	 * Flag indicating whether this model has a primary key or not
229 229
 	 * @var boolean
230 230
 	 */
231
-	protected $_has_primary_key_field=null;
231
+	protected $_has_primary_key_field = null;
232 232
 
233 233
 	/**
234 234
 	 * Whether or not this model is based off a table in WP core only (CPTs should set
@@ -283,19 +283,19 @@  discard block
 block discarded – undo
283 283
 	 * operators that work like 'BETWEEN'.  Typically used for datetime calculations, i.e. "BETWEEN '12-1-2011' AND '12-31-2012'"
284 284
 	 * @var array
285 285
 	 */
286
-	protected $_between_style_operators = array( 'BETWEEN' );
286
+	protected $_between_style_operators = array('BETWEEN');
287 287
 
288 288
 	/**
289 289
 	 * operators that are used for handling NUll and !NULL queries.  Typically used for when checking if a row exists on a join table.
290 290
 	 * @var array
291 291
 	 */
292
-	protected $_null_style_operators = array( 'IS NOT NULL', 'IS NULL');
292
+	protected $_null_style_operators = array('IS NOT NULL', 'IS NULL');
293 293
 
294 294
 	/**
295 295
 	 * Allowed values for $query_params['order'] for ordering in queries
296 296
 	 * @var array
297 297
 	 */
298
-	protected $_allowed_order_values = array('asc','desc','ASC','DESC');
298
+	protected $_allowed_order_values = array('asc', 'desc', 'ASC', 'DESC');
299 299
 
300 300
 	/**
301 301
 	 * When these are keys in a WHERE or HAVING clause, they are handled much differently
@@ -309,13 +309,13 @@  discard block
 block discarded – undo
309 309
 	 * 'where', but 'where' clauses are so common that we thought we'd omit it
310 310
 	 * @var array
311 311
 	 */
312
-	private $_allowed_query_params = array(0, 'limit','order_by','group_by','having','force_join','order','on_join_limit','default_where_conditions', 'caps');
312
+	private $_allowed_query_params = array(0, 'limit', 'order_by', 'group_by', 'having', 'force_join', 'order', 'on_join_limit', 'default_where_conditions', 'caps');
313 313
 
314 314
 	/**
315 315
 	 * All the data types that can be used in $wpdb->prepare statements.
316 316
 	 * @var array
317 317
 	 */
318
-	private $_valid_wpdb_data_types = array('%d','%s','%f');
318
+	private $_valid_wpdb_data_types = array('%d', '%s', '%f');
319 319
 
320 320
 	/**
321 321
 	 * 	EE_Registry Object
@@ -373,13 +373,13 @@  discard block
 block discarded – undo
373 373
 	 * @param null $timezone
374 374
 	 * @throws \EE_Error
375 375
 	 */
376
-	protected function __construct( $timezone = NULL ){
376
+	protected function __construct($timezone = NULL) {
377 377
 		// check that the model has not been loaded too soon
378
-		if ( ! did_action( 'AHEE__EE_System__load_espresso_addons' )) {
379
-			throw new EE_Error (
378
+		if ( ! did_action('AHEE__EE_System__load_espresso_addons')) {
379
+			throw new EE_Error(
380 380
 				sprintf(
381
-					__( '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' ),
382
-					get_class( $this )
381
+					__('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'),
382
+					get_class($this)
383 383
 				)
384 384
 			);
385 385
 		}
@@ -389,11 +389,11 @@  discard block
 block discarded – undo
389 389
 		 * just use EE_Register_Model_Extension
390 390
 		 * @var EE_Table_Base[] $_tables
391 391
 		 */
392
-		$this->_tables = apply_filters( 'FHEE__'.get_class($this).'__construct__tables', $this->_tables );
393
-		foreach($this->_tables as $table_alias => $table_obj){
392
+		$this->_tables = apply_filters('FHEE__'.get_class($this).'__construct__tables', $this->_tables);
393
+		foreach ($this->_tables as $table_alias => $table_obj) {
394 394
 			/** @var $table_obj EE_Table_Base */
395 395
 			$table_obj->_construct_finalize_with_alias($table_alias);
396
-			if( $table_obj instanceof EE_Secondary_Table ){
396
+			if ($table_obj instanceof EE_Secondary_Table) {
397 397
 				/** @var $table_obj EE_Secondary_Table */
398 398
 				$table_obj->_construct_finalize_set_table_to_join_with($this->_get_main_table());
399 399
 			}
@@ -403,48 +403,48 @@  discard block
 block discarded – undo
403 403
 		 * EE_Register_Model_Extension
404 404
 		 * @param EE_Model_Field_Base[] $_fields
405 405
 		 */
406
-		$this->_fields = apply_filters('FHEE__'.get_class($this).'__construct__fields',$this->_fields);
407
-		foreach($this->_fields as $table_alias => $fields_for_table){
408
-			if ( ! array_key_exists( $table_alias, $this->_tables )){
409
-				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)));
406
+		$this->_fields = apply_filters('FHEE__'.get_class($this).'__construct__fields', $this->_fields);
407
+		foreach ($this->_fields as $table_alias => $fields_for_table) {
408
+			if ( ! array_key_exists($table_alias, $this->_tables)) {
409
+				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)));
410 410
 			}
411
-			foreach($fields_for_table as $field_name => $field_obj){
411
+			foreach ($fields_for_table as $field_name => $field_obj) {
412 412
 				/** @var $field_obj EE_Model_Field_Base | EE_Primary_Key_Field_Base */
413 413
 				//primary key field base has a slightly different _construct_finalize
414 414
 				/** @var $field_obj EE_Model_Field_Base */
415
-				$field_obj->_construct_finalize( $table_alias, $field_name, $this->get_this_model_name() );
415
+				$field_obj->_construct_finalize($table_alias, $field_name, $this->get_this_model_name());
416 416
 			}
417 417
 		}
418 418
 
419 419
 		// everything is related to Extra_Meta
420
-		if( get_class($this) != 'EEM_Extra_Meta'){
420
+		if (get_class($this) != 'EEM_Extra_Meta') {
421 421
 			//make extra meta related to everything, but don't block deleting things just
422 422
 			//because they have related extra meta info. For now just orphan those extra meta
423 423
 			//in the future we should automatically delete them
424
-			$this->_model_relations['Extra_Meta'] = new EE_Has_Many_Any_Relation( FALSE );
424
+			$this->_model_relations['Extra_Meta'] = new EE_Has_Many_Any_Relation(FALSE);
425 425
 		}
426 426
 		//and change logs
427
-		if( get_class( $this) !=  'EEM_Change_Log' ) {
428
-			$this->_model_relations[ 'Change_Log' ] = new EE_Has_Many_Any_Relation( FALSE );
427
+		if (get_class($this) != 'EEM_Change_Log') {
428
+			$this->_model_relations['Change_Log'] = new EE_Has_Many_Any_Relation(FALSE);
429 429
 		}
430 430
 		/**
431 431
 		 * Filters the list of relations on a model. It is best to NOT use this directly and instead just use
432 432
 		 * EE_Register_Model_Extension
433 433
 		 * @param EE_Model_Relation_Base[] $_model_relations
434 434
 		 */
435
-		$this->_model_relations = apply_filters('FHEE__'.get_class($this).'__construct__model_relations',$this->_model_relations);
436
-		foreach($this->_model_relations as $model_name => $relation_obj){
435
+		$this->_model_relations = apply_filters('FHEE__'.get_class($this).'__construct__model_relations', $this->_model_relations);
436
+		foreach ($this->_model_relations as $model_name => $relation_obj) {
437 437
 			/** @var $relation_obj EE_Model_Relation_Base */
438 438
 			$relation_obj->_construct_finalize_set_models($this->get_this_model_name(), $model_name);
439 439
 		}
440
-		foreach($this->_indexes as $index_name => $index_obj){
440
+		foreach ($this->_indexes as $index_name => $index_obj) {
441 441
 			/** @var $index_obj EE_Index */
442 442
 			$index_obj->_construct_finalize($index_name, $this->get_this_model_name());
443 443
 		}
444 444
 
445 445
 		$this->set_timezone($timezone);
446 446
 		//finalize default where condition strategy, or set default
447
-		if( ! $this->_default_where_conditions_strategy){
447
+		if ( ! $this->_default_where_conditions_strategy) {
448 448
 			//nothing was set during child constructor, so set default
449 449
 			$this->_default_where_conditions_strategy = new EE_Default_Where_Conditions();
450 450
 		}
@@ -452,15 +452,15 @@  discard block
 block discarded – undo
452 452
 
453 453
 		//if the cap slug hasn't been set, and we haven't set it to false on purpose
454 454
 		//to indicate to NOT set it, set it to the logical default
455
-		if( $this->_caps_slug === null ) {
456
-			EE_Registry::instance()->load_helper( 'Inflector' );
457
-			$this->_caps_slug = EEH_Inflector::pluralize_and_lower( $this->get_this_model_name() );
455
+		if ($this->_caps_slug === null) {
456
+			EE_Registry::instance()->load_helper('Inflector');
457
+			$this->_caps_slug = EEH_Inflector::pluralize_and_lower($this->get_this_model_name());
458 458
 		}
459 459
 		//initialize the standard cap restriction generators if none were specified by the child constructor
460
-		if( $this->_cap_restriction_generators !== false ){
461
-			foreach( $this->cap_contexts_to_cap_action_map() as $cap_context => $action ){
462
-				if( ! isset( $this->_cap_restriction_generators[ $cap_context ] ) ) {
463
-					$this->_cap_restriction_generators[ $cap_context ] = apply_filters(
460
+		if ($this->_cap_restriction_generators !== false) {
461
+			foreach ($this->cap_contexts_to_cap_action_map() as $cap_context => $action) {
462
+				if ( ! isset($this->_cap_restriction_generators[$cap_context])) {
463
+					$this->_cap_restriction_generators[$cap_context] = apply_filters(
464 464
 						'FHEE__EEM_Base___construct__standard_cap_restriction_generator',
465 465
 						new EE_Restriction_Generator_Protected(),
466 466
 						$cap_context,
@@ -470,23 +470,23 @@  discard block
 block discarded – undo
470 470
 			}
471 471
 		}
472 472
 		//if there are cap restriction generators, use them to make the default cap restrictions
473
-		if( $this->_cap_restriction_generators !== false ){
474
-			foreach( $this->_cap_restriction_generators as $context => $generator_object ) {
475
-				if( ! $generator_object ){
473
+		if ($this->_cap_restriction_generators !== false) {
474
+			foreach ($this->_cap_restriction_generators as $context => $generator_object) {
475
+				if ( ! $generator_object) {
476 476
 					continue;
477 477
 				}
478
-				if( ! $generator_object instanceof EE_Restriction_Generator_Base ){
478
+				if ( ! $generator_object instanceof EE_Restriction_Generator_Base) {
479 479
 					throw new EE_Error(
480 480
 						sprintf(
481
-							__( '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' ),
481
+							__('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'),
482 482
 							$context,
483 483
 							$this->get_this_model_name()
484 484
 						)
485 485
 					);
486 486
 				}
487
-				$action = $this->cap_action_for_context( $context );
488
-				if( ! $generator_object->construction_finalized() ){
489
-					$generator_object->_construct_finalize( $this, $action );
487
+				$action = $this->cap_action_for_context($context);
488
+				if ( ! $generator_object->construction_finalized()) {
489
+					$generator_object->_construct_finalize($this, $action);
490 490
 				}
491 491
 
492 492
 			}
@@ -500,11 +500,11 @@  discard block
 block discarded – undo
500 500
 	 * @param string $context one of EEM_Base::valid_cap_contexts()
501 501
 	 * @return EE_Default_Where_Conditions[]
502 502
 	 */
503
-	protected function _generate_cap_restrictions( $context ){
504
-		if( isset( $this->_cap_restriction_generators[ $context ] ) &&
505
-				$this->_cap_restriction_generators[ $context ] instanceof EE_Restriction_Generator_Base ) {
506
-			return $this->_cap_restriction_generators[ $context ]->generate_restrictions();
507
-		}else{
503
+	protected function _generate_cap_restrictions($context) {
504
+		if (isset($this->_cap_restriction_generators[$context]) &&
505
+				$this->_cap_restriction_generators[$context] instanceof EE_Restriction_Generator_Base) {
506
+			return $this->_cap_restriction_generators[$context]->generate_restrictions();
507
+		} else {
508 508
 			return array();
509 509
 		}
510 510
 }
@@ -516,20 +516,20 @@  discard block
 block discarded – undo
516 516
 	 * This sets the _timezone property after model object has been instantiated.
517 517
 	 * @param string $timezone valid PHP DateTimeZone timezone string
518 518
 	 */
519
-	public function set_timezone( $timezone ) {
520
-		if($timezone !== NULL){
519
+	public function set_timezone($timezone) {
520
+		if ($timezone !== NULL) {
521 521
 			$this->_timezone = $timezone;
522 522
 		}
523 523
 
524 524
 		//note we need to loop through relations and set the timezone on those objects as well.
525
-		foreach ( $this->_model_relations as $relation ) {
525
+		foreach ($this->_model_relations as $relation) {
526 526
 			$relation->set_timezone($timezone);
527 527
 		}
528 528
 
529 529
 		//and finally we do the same for any datetime fields
530
-		foreach ( $this->_fields as $field ) {
531
-			if ( $field instanceof EE_Datetime_Field ) {
532
-				$field->set_timezone( $timezone );
530
+		foreach ($this->_fields as $field) {
531
+			if ($field instanceof EE_Datetime_Field) {
532
+				$field->set_timezone($timezone);
533 533
 			}
534 534
 		}
535 535
 	}
@@ -541,16 +541,16 @@  discard block
 block discarded – undo
541 541
 	 *		@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)
542 542
 	 *		@return static (as in the concrete child class)
543 543
 	 */
544
-	public static function instance( $timezone = NULL ){
544
+	public static function instance($timezone = NULL) {
545 545
 
546 546
 		// check if instance of Espresso_model already exists
547 547
 		if ( ! static::$_instance instanceof static) {
548 548
 			// instantiate Espresso_model
549
-			static::$_instance = new static( $timezone );
549
+			static::$_instance = new static($timezone);
550 550
 		}
551 551
 
552 552
 		//we might have a timezone set, let set_timezone decide what to do with it
553
-		static::$_instance->set_timezone( $timezone );
553
+		static::$_instance->set_timezone($timezone);
554 554
 
555 555
 		// Espresso_model object
556 556
 		return static::$_instance;
@@ -562,9 +562,9 @@  discard block
 block discarded – undo
562 562
 	 * resets the model and returns it
563 563
 	 * @return static
564 564
 	 */
565
-	public static function reset(  $timezone = NULL ){
565
+	public static function reset($timezone = NULL) {
566 566
 		static::$_instance = NULL;
567
-		return self::instance( $timezone );
567
+		return self::instance($timezone);
568 568
 	}
569 569
 
570 570
 	/**
@@ -573,15 +573,15 @@  discard block
 block discarded – undo
573 573
 	 * @param  boolean $translated return localized strings or JUST the array.
574 574
 	 * @return array
575 575
 	 */
576
-	 public function status_array( $translated = FALSE ) {
577
-	 	if ( !array_key_exists('Status', $this->_model_relations ) )
576
+	 public function status_array($translated = FALSE) {
577
+	 	if ( ! array_key_exists('Status', $this->_model_relations))
578 578
 	 		return array();
579 579
 	 	$model_name = $this->get_this_model_name();
580
-	 	$status_type = str_replace(' ', '_', strtolower( str_replace('_', ' ', $model_name) ) );
581
-	 	$stati = EEM_Status::instance()->get_all(array(array('STS_type' => $status_type) ) );
580
+	 	$status_type = str_replace(' ', '_', strtolower(str_replace('_', ' ', $model_name)));
581
+	 	$stati = EEM_Status::instance()->get_all(array(array('STS_type' => $status_type)));
582 582
 	 	$status_array = array();
583
-	 	foreach ( $stati as $status ) {
584
-            $status_array[ $status->ID() ] = $status->get('STS_code');
583
+	 	foreach ($stati as $status) {
584
+            $status_array[$status->ID()] = $status->get('STS_code');
585 585
         }
586 586
         return $translated ? EEM_Status::instance()->localized_status($status_array, FALSE, 'sentence') : $status_array;
587 587
     }
@@ -722,7 +722,7 @@  discard block
 block discarded – undo
722 722
 	 *			'order_by'=>array('ANS_value'=>'ASC')
723 723
 	 *		));
724 724
 	 */
725
-	function get_all($query_params = array()){
725
+	function get_all($query_params = array()) {
726 726
 		return $this->_create_objects($this->_get_all_wpdb_results($query_params, ARRAY_A, NULL));
727 727
 	}
728 728
 
@@ -732,10 +732,10 @@  discard block
 block discarded – undo
732 732
 	 * @param array $query_parms @see EEM_Base::get_all()
733 733
 	 * @return array like EEM_Base::get_all
734 734
 	 */
735
-	function alter_query_params_to_only_include_mine( $query_parms = array() ) {
735
+	function alter_query_params_to_only_include_mine($query_parms = array()) {
736 736
 		$wp_user_field_name = $this->wp_user_field_name();
737
-		if( $wp_user_field_name ){
738
-			$query_parms[0][ $wp_user_field_name ] = get_current_user_id();
737
+		if ($wp_user_field_name) {
738
+			$query_parms[0][$wp_user_field_name] = get_current_user_id();
739 739
 		}
740 740
 		return $query_parms;
741 741
 	}
@@ -748,19 +748,19 @@  discard block
 block discarded – undo
748 748
 	 * foreign key to the WP_User table
749 749
 	 */
750 750
 	function wp_user_field_name() {
751
-		try{
752
-			if( ! empty( $this->_model_chain_to_wp_user ) ) {
753
-				$models_to_follow_to_wp_users = explode( '.', $this->_model_chain_to_wp_user );
754
-				$last_model_name = end( $models_to_follow_to_wp_users );
755
-				$model_with_fk_to_wp_users = EE_Registry::instance()->load_model( $last_model_name );
756
-				$model_chain_to_wp_user = $this->_model_chain_to_wp_user . '.';
757
-			}else{
751
+		try {
752
+			if ( ! empty($this->_model_chain_to_wp_user)) {
753
+				$models_to_follow_to_wp_users = explode('.', $this->_model_chain_to_wp_user);
754
+				$last_model_name = end($models_to_follow_to_wp_users);
755
+				$model_with_fk_to_wp_users = EE_Registry::instance()->load_model($last_model_name);
756
+				$model_chain_to_wp_user = $this->_model_chain_to_wp_user.'.';
757
+			} else {
758 758
 				$model_with_fk_to_wp_users = $this;
759 759
 				$model_chain_to_wp_user = '';
760 760
 			}
761
-			$wp_user_field = $model_with_fk_to_wp_users->get_foreign_key_to( 'WP_User' );
762
-			return $model_chain_to_wp_user . $wp_user_field->get_name();
763
-		}catch( EE_Error $e ) {
761
+			$wp_user_field = $model_with_fk_to_wp_users->get_foreign_key_to('WP_User');
762
+			return $model_chain_to_wp_user.$wp_user_field->get_name();
763
+		} catch (EE_Error $e) {
764 764
 			return false;
765 765
 		}
766 766
 	}
@@ -774,7 +774,7 @@  discard block
 block discarded – undo
774 774
 	 * (or transietly-related model)
775 775
 	 * @return string
776 776
 	 */
777
-	public function model_chain_to_wp_user(){
777
+	public function model_chain_to_wp_user() {
778 778
 		return $this->_model_chain_to_wp_user;
779 779
 	}
780 780
 
@@ -786,13 +786,13 @@  discard block
 block discarded – undo
786 786
 	 * @return boolean
787 787
 	 */
788 788
 	public function is_owned() {
789
-		if( $this->model_chain_to_wp_user() ){
789
+		if ($this->model_chain_to_wp_user()) {
790 790
 			return true;
791
-		}else{
792
-			try{
793
-				$this->get_foreign_key_to( 'WP_User' );
791
+		} else {
792
+			try {
793
+				$this->get_foreign_key_to('WP_User');
794 794
 				return true;
795
-			}catch( EE_Error $e ){
795
+			} catch (EE_Error $e) {
796 796
 				return false;
797 797
 			}
798 798
 		}
@@ -811,21 +811,21 @@  discard block
 block discarded – undo
811 811
 	 * and 1 is the data type. Eg, array('count'=>array('COUNT(REG_ID)','%d'))
812 812
 	 * @return stdClass[] like results of $wpdb->get_results($sql,OBJECT), (ie, output type is OBJECT)
813 813
 	 */
814
-	protected function  _get_all_wpdb_results($query_params = array(), $output = ARRAY_A, $columns_to_select = null){
814
+	protected function  _get_all_wpdb_results($query_params = array(), $output = ARRAY_A, $columns_to_select = null) {
815 815
 		//remember the custom selections, if any
816
-		if(is_array($columns_to_select)){
816
+		if (is_array($columns_to_select)) {
817 817
 			$this->_custom_selections = $columns_to_select;
818
-		}elseif(is_string($columns_to_select)){
818
+		}elseif (is_string($columns_to_select)) {
819 819
 			$this->_custom_selections = array($this->_custom_selections);
820
-		}else{
820
+		} else {
821 821
 			$this->_custom_selections = array();
822 822
 		}
823 823
 
824 824
 		$model_query_info = $this->_create_model_query_info_carrier($query_params);
825 825
 		$select_expressions = $columns_to_select ? $this->_construct_select_from_input($columns_to_select) : $this->_construct_default_select_sql($model_query_info);
826
-		$SQL ="SELECT $select_expressions ".$this->_construct_2nd_half_of_select_query($model_query_info);
826
+		$SQL = "SELECT $select_expressions ".$this->_construct_2nd_half_of_select_query($model_query_info);
827 827
 //		echo "sql:$SQL";
828
-		$results =  $this->_do_wpdb_query( 'get_results', array($SQL, $output ) );// $wpdb->get_results($SQL, $output);
828
+		$results = $this->_do_wpdb_query('get_results', array($SQL, $output)); // $wpdb->get_results($SQL, $output);
829 829
 		return $results;
830 830
 	}
831 831
 
@@ -842,7 +842,7 @@  discard block
 block discarded – undo
842 842
 	 * and 1 is the data type. Eg, array('count'=>array('COUNT(REG_ID)','%d'))
843 843
 	 * @return stdClass[] like results of $wpdb->get_results($sql,OBJECT), (ie, output type is OBJECT)
844 844
 	 */
845
-	public function  get_all_wpdb_results($query_params = array(), $output = ARRAY_A, $columns_to_select = null){
845
+	public function  get_all_wpdb_results($query_params = array(), $output = ARRAY_A, $columns_to_select = null) {
846 846
 		return $this->_get_all_wpdb_results($query_params, $output, $columns_to_select);
847 847
 	}
848 848
 
@@ -854,21 +854,21 @@  discard block
 block discarded – undo
854 854
 	 * @throws EE_Error
855 855
 	 * @return string
856 856
 	 */
857
-	private function _construct_select_from_input($columns_to_select){
858
-		if(is_array($columns_to_select)){
857
+	private function _construct_select_from_input($columns_to_select) {
858
+		if (is_array($columns_to_select)) {
859 859
 			$select_sql_array = array();
860 860
 
861
-			foreach($columns_to_select as $alias => $selection_and_datatype){
862
-				if( ! is_array($selection_and_datatype) || ! isset($selection_and_datatype[1])){
863
-					throw new EE_Error(sprintf(__("Custom selection %s (alias %s) needs to be an array like array('COUNT(REG_ID)','%%d')", "event_espresso"),$selection_and_datatype,$alias));
861
+			foreach ($columns_to_select as $alias => $selection_and_datatype) {
862
+				if ( ! is_array($selection_and_datatype) || ! isset($selection_and_datatype[1])) {
863
+					throw new EE_Error(sprintf(__("Custom selection %s (alias %s) needs to be an array like array('COUNT(REG_ID)','%%d')", "event_espresso"), $selection_and_datatype, $alias));
864 864
 				}
865
-				if( ! in_array( $selection_and_datatype[1],$this->_valid_wpdb_data_types)){
866
-					throw new EE_Error(sprintf(__("Datatype %s (for selection '%s' and alias '%s') is not a valid wpdb datatype (eg %%s)", "event_espresso"),$selection_and_datatype[1],$selection_and_datatype[0],$alias,implode(",",$this->_valid_wpdb_data_types)));
865
+				if ( ! in_array($selection_and_datatype[1], $this->_valid_wpdb_data_types)) {
866
+					throw new EE_Error(sprintf(__("Datatype %s (for selection '%s' and alias '%s') is not a valid wpdb datatype (eg %%s)", "event_espresso"), $selection_and_datatype[1], $selection_and_datatype[0], $alias, implode(",", $this->_valid_wpdb_data_types)));
867 867
 				}
868 868
 				$select_sql_array[] = "{$selection_and_datatype[0]} AS $alias";
869 869
 			}
870
-			$columns_to_select_string = implode(", ",$select_sql_array);
871
-		}else{
870
+			$columns_to_select_string = implode(", ", $select_sql_array);
871
+		} else {
872 872
 			$columns_to_select_string = $columns_to_select;
873 873
 		}
874 874
 		return $columns_to_select_string;
@@ -881,7 +881,7 @@  discard block
 block discarded – undo
881 881
 	 * Convenient wrapper for getting the primary key field's name. Eg, on Registration, this would be 'REG_ID'
882 882
 	 * @return string
883 883
 	 */
884
-	function primary_key_name(){
884
+	function primary_key_name() {
885 885
 		return $this->get_primary_key_field()->get_name();
886 886
 	}
887 887
 
@@ -893,15 +893,15 @@  discard block
 block discarded – undo
893 893
 	 * @param mixed $id int or string, depending on the type of the model's primary key
894 894
 	 * @return EE_Base_Class
895 895
 	 */
896
-	function get_one_by_ID($id){
897
-		if( $this->get_from_entity_map( $id ) ){
898
-			return $this->get_from_entity_map( $id );
899
-		}elseif( $this->has_primary_key_field ( ) ) {
896
+	function get_one_by_ID($id) {
897
+		if ($this->get_from_entity_map($id)) {
898
+			return $this->get_from_entity_map($id);
899
+		}elseif ($this->has_primary_key_field( )) {
900 900
 			$primary_key_name = $this->get_primary_key_field()->get_name();
901 901
 			return $this->get_one(array(array($primary_key_name => $id)));
902
-		}else{
902
+		} else {
903 903
 			//no primary key, so the $id must be from the get_index_primary_key_string()
904
-			return $this->get_one( array( $this->parse_index_primary_key_string( $id ) ) );
904
+			return $this->get_one(array($this->parse_index_primary_key_string($id)));
905 905
 		}
906 906
 	}
907 907
 
@@ -912,16 +912,16 @@  discard block
 block discarded – undo
912 912
 	 * @param array $query_params like EEM_Base's $query_params variable.
913 913
 	 * @return EE_Base_Class | NULL
914 914
 	 */
915
-	function get_one($query_params = array()){
916
-		if( ! is_array( $query_params ) ){
917
-			EE_Error::doing_it_wrong('EEM_Base::get_one', sprintf( __( '$query_params should be an array, you passed a variable of type %s', 'event_espresso' ), gettype( $query_params ) ), '4.6.0' );
915
+	function get_one($query_params = array()) {
916
+		if ( ! is_array($query_params)) {
917
+			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');
918 918
 			$query_params = array();
919 919
 		}
920 920
 		$query_params['limit'] = 1;
921 921
 		$items = $this->get_all($query_params);
922
-		if(empty($items)){
922
+		if (empty($items)) {
923 923
 			return null;
924
-		}else{
924
+		} else {
925 925
 			return array_shift($items);
926 926
 		}
927 927
 	}
@@ -945,8 +945,8 @@  discard block
 block discarded – undo
945 945
 	 *
946 946
 	 * @return EE_Base_Class[]|array
947 947
 	 */
948
-	public function next_x( $current_field_value, $field_to_order_by = null, $limit = 1, $query_params = array(), $columns_to_select = null ) {
949
-		return $this->_get_consecutive( $current_field_value, '>', $field_to_order_by, $limit, $query_params, $columns_to_select );
948
+	public function next_x($current_field_value, $field_to_order_by = null, $limit = 1, $query_params = array(), $columns_to_select = null) {
949
+		return $this->_get_consecutive($current_field_value, '>', $field_to_order_by, $limit, $query_params, $columns_to_select);
950 950
 	}
951 951
 
952 952
 
@@ -969,8 +969,8 @@  discard block
 block discarded – undo
969 969
 	 *
970 970
 	 * @return EE_Base_Class[]|array
971 971
 	 */
972
-	public function previous_x( $current_field_value, $field_to_order_by = null, $limit = 1, $query_params = array(), $columns_to_select = null ) {
973
-		return $this->_get_consecutive( $current_field_value, '<', $field_to_order_by, $limit, $query_params, $columns_to_select );
972
+	public function previous_x($current_field_value, $field_to_order_by = null, $limit = 1, $query_params = array(), $columns_to_select = null) {
973
+		return $this->_get_consecutive($current_field_value, '<', $field_to_order_by, $limit, $query_params, $columns_to_select);
974 974
 	}
975 975
 
976 976
 
@@ -992,9 +992,9 @@  discard block
 block discarded – undo
992 992
 	 *
993 993
 	 * @return EE_Base_Class|null|array()
994 994
 	 */
995
-	public function next( $current_field_value, $field_to_order_by = null, $query_params = array(), $columns_to_select = null ) {
996
-		$results = $this->_get_consecutive( $current_field_value, '>', $field_to_order_by, 1, $query_params, $columns_to_select );
997
-		return empty( $results ) ? null : reset( $results );
995
+	public function next($current_field_value, $field_to_order_by = null, $query_params = array(), $columns_to_select = null) {
996
+		$results = $this->_get_consecutive($current_field_value, '>', $field_to_order_by, 1, $query_params, $columns_to_select);
997
+		return empty($results) ? null : reset($results);
998 998
 	}
999 999
 
1000 1000
 
@@ -1016,9 +1016,9 @@  discard block
 block discarded – undo
1016 1016
 	 *
1017 1017
 	 * @return EE_Base_Class|null|array()
1018 1018
 	 */
1019
-	public function previous( $current_field_value, $field_to_order_by = null, $query_params = array(), $columns_to_select = null ) {
1020
-		$results = $this->_get_consecutive( $current_field_value, '<', $field_to_order_by, 1, $query_params, $columns_to_select );
1021
-		return empty( $results ) ? null : reset( $results );
1019
+	public function previous($current_field_value, $field_to_order_by = null, $query_params = array(), $columns_to_select = null) {
1020
+		$results = $this->_get_consecutive($current_field_value, '<', $field_to_order_by, 1, $query_params, $columns_to_select);
1021
+		return empty($results) ? null : reset($results);
1022 1022
 	}
1023 1023
 
1024 1024
 
@@ -1044,40 +1044,40 @@  discard block
 block discarded – undo
1044 1044
 	 * @return EE_Base_Class[]|array
1045 1045
 	 * @throws EE_Error
1046 1046
 	 */
1047
-	protected function _get_consecutive( $current_field_value, $operand = '>', $field_to_order_by = null, $limit = 1, $query_params = array(), $columns_to_select = null ) {
1047
+	protected function _get_consecutive($current_field_value, $operand = '>', $field_to_order_by = null, $limit = 1, $query_params = array(), $columns_to_select = null) {
1048 1048
 		//if $field_to_order_by is empty then let's assume we're ordering by the primary key.
1049
-		if ( empty( $field_to_order_by ) ) {
1050
-			if ( $this->has_primary_key_field() ) {
1049
+		if (empty($field_to_order_by)) {
1050
+			if ($this->has_primary_key_field()) {
1051 1051
 				$field_to_order_by = $this->get_primary_key_field()->get_name();
1052 1052
 			} else {
1053 1053
 
1054
-				if ( WP_DEBUG ) {
1055
-					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' ) );
1054
+				if (WP_DEBUG) {
1055
+					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'));
1056 1056
 				}
1057
-				EE_Error::add_error( __('There was an error with the query.', 'event_espresso') );
1057
+				EE_Error::add_error(__('There was an error with the query.', 'event_espresso'));
1058 1058
 				return array();
1059 1059
 			}
1060 1060
 		}
1061 1061
 
1062
-		if( ! is_array( $query_params ) ){
1063
-			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' );
1062
+		if ( ! is_array($query_params)) {
1063
+			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');
1064 1064
 			$query_params = array();
1065 1065
 		}
1066 1066
 
1067 1067
 		//let's add the where query param for consecutive look up.
1068
-		$query_params[0][ $field_to_order_by ] = array( $operand, $current_field_value );
1068
+		$query_params[0][$field_to_order_by] = array($operand, $current_field_value);
1069 1069
 		$query_params['limit'] = $limit;
1070 1070
 
1071 1071
 		//set direction
1072
-		$incoming_orderby = isset( $query_params['order_by'] ) ? $query_params['order_by'] : array();
1073
-		$query_params['order_by'] = $operand == '>' ? array( $field_to_order_by => 'ASC' ) + $incoming_orderby : array( $field_to_order_by => 'DESC') + $incoming_orderby;
1072
+		$incoming_orderby = isset($query_params['order_by']) ? $query_params['order_by'] : array();
1073
+		$query_params['order_by'] = $operand == '>' ? array($field_to_order_by => 'ASC') + $incoming_orderby : array($field_to_order_by => 'DESC') + $incoming_orderby;
1074 1074
 
1075 1075
 		//if $columns_to_select is empty then that means we're returning EE_Base_Class objects
1076
-		if ( empty( $columns_to_select ) ) {
1077
-			return $this->get_all( $query_params );
1076
+		if (empty($columns_to_select)) {
1077
+			return $this->get_all($query_params);
1078 1078
 		} else {
1079 1079
 			//getting just the fields
1080
-			return $this->_get_all_wpdb_results( $query_params, ARRAY_A, $columns_to_select );
1080
+			return $this->_get_all_wpdb_results($query_params, ARRAY_A, $columns_to_select);
1081 1081
 		}
1082 1082
 	}
1083 1083
 
@@ -1100,7 +1100,7 @@  discard block
 block discarded – undo
1100 1100
 	 * Gets all the tables comprising this model. Array keys are the table aliases, and values are EE_Table objects
1101 1101
 	 * @return EE_Table_Base[]
1102 1102
 	 */
1103
-	function get_tables(){
1103
+	function get_tables() {
1104 1104
 		return $this->_tables;
1105 1105
 	}
1106 1106
 
@@ -1134,9 +1134,9 @@  discard block
 block discarded – undo
1134 1134
 	 * be aware that model objects being used could get out-of-sync with the database
1135 1135
 	 * @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)
1136 1136
 	 */
1137
-	function update($fields_n_values, $query_params, $keep_model_objs_in_sync = TRUE){
1138
-		if( ! is_array( $query_params ) ){
1139
-			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' );
1137
+	function update($fields_n_values, $query_params, $keep_model_objs_in_sync = TRUE) {
1138
+		if ( ! is_array($query_params)) {
1139
+			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');
1140 1140
 			$query_params = array();
1141 1141
 		}
1142 1142
 		/**
@@ -1146,7 +1146,7 @@  discard block
 block discarded – undo
1146 1146
 		 * @param array $fields_n_values the updated fields and their new values
1147 1147
 		 * @param array $query_params @see EEM_Base::get_all()
1148 1148
 		 */
1149
-		do_action( 'AHEE__EEM_Base__update__begin',$this, $fields_n_values, $query_params );
1149
+		do_action('AHEE__EEM_Base__update__begin', $this, $fields_n_values, $query_params);
1150 1150
 		/**
1151 1151
 		 * Filters the fields about to be updated given the query parameters. You can provide the
1152 1152
 		 * $query_params to $this->get_all() to find exactly which records will be updated
@@ -1154,10 +1154,10 @@  discard block
 block discarded – undo
1154 1154
 		 * @param EEM_Base $model the model being queried
1155 1155
 		 * @param array $query_params see EEM_Base::get_all()
1156 1156
 		 */
1157
-		$fields_n_values = apply_filters( 'FHEE__EEM_Base__update__fields_n_values', $fields_n_values, $this, $query_params );
1157
+		$fields_n_values = apply_filters('FHEE__EEM_Base__update__fields_n_values', $fields_n_values, $this, $query_params);
1158 1158
 		//need to verify that, for any entry we want to update, there are entries in each secondary table.
1159 1159
 		//to do that, for each table, verify that it's PK isn't null.
1160
-		$tables= $this->get_tables();
1160
+		$tables = $this->get_tables();
1161 1161
 
1162 1162
 		//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
1163 1163
 		//NOTE: we should make this code more efficient by NOT querying twice
@@ -1167,29 +1167,29 @@  discard block
 block discarded – undo
1167 1167
 			//we want to make sure the default_where strategy is ignored
1168 1168
 			$this->_ignore_where_strategy = TRUE;
1169 1169
 			$wpdb_select_results = $this->_get_all_wpdb_results($query_params);
1170
-			foreach( $wpdb_select_results as $wpdb_result ){
1170
+			foreach ($wpdb_select_results as $wpdb_result) {
1171 1171
 				// type cast stdClass as array
1172
-				$wpdb_result = (array)$wpdb_result;
1172
+				$wpdb_result = (array) $wpdb_result;
1173 1173
 				//get the model object's PK, as we'll want this if we need to insert a row into secondary tables
1174
-				if( $this->has_primary_key_field() ){
1175
-					$main_table_pk_value = $wpdb_result[ $this->get_primary_key_field()->get_qualified_column() ];
1176
-				}else{
1174
+				if ($this->has_primary_key_field()) {
1175
+					$main_table_pk_value = $wpdb_result[$this->get_primary_key_field()->get_qualified_column()];
1176
+				} else {
1177 1177
 					//if there's no primary key, we basically can't support having a 2nd table on the model (we could but it woudl be lots of work)
1178 1178
 					$main_table_pk_value = null;
1179 1179
 				}
1180 1180
 				//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
1181 1181
 				//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
1182
-				if(count($tables) > 1){
1182
+				if (count($tables) > 1) {
1183 1183
 					//foreach matching row in the DB, ensure that each table's PK isn't null. If so, there must not be an entry
1184 1184
 					//in that table, and so we'll want to insert one
1185
-					foreach($tables as $table_obj){
1185
+					foreach ($tables as $table_obj) {
1186 1186
 						$this_table_pk_column = $table_obj->get_fully_qualified_pk_column();
1187 1187
 						//if there is no private key for this table on the results, it means there's no entry
1188 1188
 						//in this table, right? so insert a row in the current table, using any fields available
1189
-						if( ! ( array_key_exists( $this_table_pk_column, $wpdb_result) && $wpdb_result[ $this_table_pk_column ] )){
1189
+						if ( ! (array_key_exists($this_table_pk_column, $wpdb_result) && $wpdb_result[$this_table_pk_column])) {
1190 1190
 							$success = $this->_insert_into_specific_table($table_obj, $fields_n_values, $main_table_pk_value);
1191 1191
 							//if we died here, report the error
1192
-							if( ! $success ) {
1192
+							if ( ! $success) {
1193 1193
 								return false;
1194 1194
 							}
1195 1195
 						}
@@ -1209,44 +1209,44 @@  discard block
 block discarded – undo
1209 1209
 		//if this wasn't called from a model object (to update itself)
1210 1210
 		//then we want to make sure we keep all the existing
1211 1211
 		//model objects in sync with the db
1212
-		if( $keep_model_objs_in_sync && ! $this->_values_already_prepared_by_model_object ){
1213
-			if( $this->has_primary_key_field() ){
1214
-				$model_objs_affected_ids = $this->get_col( $query_params );
1215
-			}else{
1212
+		if ($keep_model_objs_in_sync && ! $this->_values_already_prepared_by_model_object) {
1213
+			if ($this->has_primary_key_field()) {
1214
+				$model_objs_affected_ids = $this->get_col($query_params);
1215
+			} else {
1216 1216
 				//we need to select a bunch of columns and then combine them into the the "index primary key string"s
1217
-				$models_affected_key_columns = $this->_get_all_wpdb_results($query_params, ARRAY_A );
1217
+				$models_affected_key_columns = $this->_get_all_wpdb_results($query_params, ARRAY_A);
1218 1218
 				$model_objs_affected_ids = array();
1219
-				foreach( $models_affected_key_columns as $row ){
1220
-					$combined_index_key = $this->get_index_primary_key_string( $row );
1221
-					$model_objs_affected_ids[ $combined_index_key ] = $combined_index_key;
1219
+				foreach ($models_affected_key_columns as $row) {
1220
+					$combined_index_key = $this->get_index_primary_key_string($row);
1221
+					$model_objs_affected_ids[$combined_index_key] = $combined_index_key;
1222 1222
 				}
1223 1223
 
1224 1224
 			}
1225 1225
 
1226
-			if( ! $model_objs_affected_ids ){
1226
+			if ( ! $model_objs_affected_ids) {
1227 1227
 				//wait wait wait- if nothing was affected let's stop here
1228 1228
 				return 0;
1229 1229
 			}
1230
-			foreach( $model_objs_affected_ids as $id ){
1231
-				$model_obj_in_entity_map = $this->get_from_entity_map( $id );
1232
-				if( $model_obj_in_entity_map ){
1233
-					foreach( $fields_n_values as $field => $new_value ){
1234
-						$model_obj_in_entity_map->set( $field, $new_value );
1230
+			foreach ($model_objs_affected_ids as $id) {
1231
+				$model_obj_in_entity_map = $this->get_from_entity_map($id);
1232
+				if ($model_obj_in_entity_map) {
1233
+					foreach ($fields_n_values as $field => $new_value) {
1234
+						$model_obj_in_entity_map->set($field, $new_value);
1235 1235
 					}
1236 1236
 				}
1237 1237
 			}
1238 1238
 			//if there is a primary key on this model, we can now do a slight optimization
1239
-			if( $this->has_primary_key_field() ){
1239
+			if ($this->has_primary_key_field()) {
1240 1240
 				//we already know what we want to update. So let's make the query simpler so it's a little more efficient
1241 1241
 				$query_params = array(
1242
-					array( $this->primary_key_name() => array( 'IN', $model_objs_affected_ids ) ),
1243
-					'limit' => count( $model_objs_affected_ids ), 'default_where_conditions' => 'none' );
1242
+					array($this->primary_key_name() => array('IN', $model_objs_affected_ids)),
1243
+					'limit' => count($model_objs_affected_ids), 'default_where_conditions' => 'none' );
1244 1244
 			}
1245 1245
 		}
1246 1246
 
1247
-		$model_query_info = $this->_create_model_query_info_carrier( $query_params );
1248
-		$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.
1249
-		$rows_affected = $this->_do_wpdb_query('query', array( $SQL ) );
1247
+		$model_query_info = $this->_create_model_query_info_carrier($query_params);
1248
+		$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.
1249
+		$rows_affected = $this->_do_wpdb_query('query', array($SQL));
1250 1250
 		/**
1251 1251
 		 * Action called after a model update call has been made.
1252 1252
 		 *
@@ -1255,8 +1255,8 @@  discard block
 block discarded – undo
1255 1255
 		 * @param array $query_params @see EEM_Base::get_all()
1256 1256
 		 * @param int $rows_affected
1257 1257
 		 */
1258
-		do_action( 'AHEE__EEM_Base__update__end',$this, $fields_n_values, $query_params, $rows_affected );
1259
-		return $rows_affected;//how many supposedly got updated
1258
+		do_action('AHEE__EEM_Base__update__end', $this, $fields_n_values, $query_params, $rows_affected);
1259
+		return $rows_affected; //how many supposedly got updated
1260 1260
 	}
1261 1261
 
1262 1262
 	/**
@@ -1268,22 +1268,22 @@  discard block
 block discarded – undo
1268 1268
 	 * @param string $field_to_select
1269 1269
 	 * @return array just like $wpdb->get_col()
1270 1270
 	 */
1271
-	public function get_col( $query_params  = array(), $field_to_select = NULL ){
1271
+	public function get_col($query_params = array(), $field_to_select = NULL) {
1272 1272
 
1273
-		if( $field_to_select ){
1274
-			$field = $this->field_settings_for( $field_to_select );
1275
-		}elseif( $this->has_primary_key_field ( ) ){
1273
+		if ($field_to_select) {
1274
+			$field = $this->field_settings_for($field_to_select);
1275
+		}elseif ($this->has_primary_key_field( )) {
1276 1276
 			$field = $this->get_primary_key_field();
1277
-		}else{
1277
+		} else {
1278 1278
 			//no primary key, just grab the first column
1279
-			$field = reset( $this->field_settings());
1279
+			$field = reset($this->field_settings());
1280 1280
 		}
1281 1281
 
1282 1282
 
1283 1283
 		$model_query_info = $this->_create_model_query_info_carrier($query_params);
1284 1284
 		$select_expressions = $field->get_qualified_column();
1285
-		$SQL ="SELECT $select_expressions ".$this->_construct_2nd_half_of_select_query($model_query_info);
1286
-		$results =  $this->_do_wpdb_query('get_col', array( $SQL ) );
1285
+		$SQL = "SELECT $select_expressions ".$this->_construct_2nd_half_of_select_query($model_query_info);
1286
+		$results = $this->_do_wpdb_query('get_col', array($SQL));
1287 1287
 		return $results;
1288 1288
 	}
1289 1289
 
@@ -1293,12 +1293,12 @@  discard block
 block discarded – undo
1293 1293
 	 * @param string $field_to_select @see EEM_Base::get_col()
1294 1294
 	 * @return string
1295 1295
 	 */
1296
-	public function get_var( $query_params = array(), $field_to_select = NULL ) {
1297
-		$query_params[ 'limit' ] = 1;
1298
-		$col = $this->get_col( $query_params, $field_to_select );
1299
-		if( ! empty( $col ) ) {
1300
-			return reset( $col );
1301
-		}else{
1296
+	public function get_var($query_params = array(), $field_to_select = NULL) {
1297
+		$query_params['limit'] = 1;
1298
+		$col = $this->get_col($query_params, $field_to_select);
1299
+		if ( ! empty($col)) {
1300
+			return reset($col);
1301
+		} else {
1302 1302
 			return NULL;
1303 1303
 		}
1304 1304
 	}
@@ -1312,18 +1312,18 @@  discard block
 block discarded – undo
1312 1312
 	 * @param array $fields_n_values array keys are field names on this model, and values are what those fields should be updated to in the DB
1313 1313
 	 * @return string of SQL
1314 1314
 	 */
1315
-	function _construct_update_sql($fields_n_values){
1315
+	function _construct_update_sql($fields_n_values) {
1316 1316
 		global $wpdb;
1317 1317
 		$cols_n_values = array();
1318
-		foreach($fields_n_values as $field_name => $value){
1318
+		foreach ($fields_n_values as $field_name => $value) {
1319 1319
 			$field_obj = $this->field_settings_for($field_name);
1320 1320
 			//if the value is NULL, we want to assign the value to that.
1321 1321
 			//wpdb->prepare doesn't really handle that properly
1322
-			$prepared_value = $this->_prepare_value_or_use_default( $field_obj, $fields_n_values );
1323
-			$value_sql = $prepared_value===NULL ? 'NULL' : $wpdb->prepare( $field_obj->get_wpdb_data_type(), $prepared_value );
1322
+			$prepared_value = $this->_prepare_value_or_use_default($field_obj, $fields_n_values);
1323
+			$value_sql = $prepared_value === NULL ? 'NULL' : $wpdb->prepare($field_obj->get_wpdb_data_type(), $prepared_value);
1324 1324
 			$cols_n_values[] = $field_obj->get_qualified_column()."=".$value_sql;
1325 1325
 		}
1326
-		return implode(",",$cols_n_values);
1326
+		return implode(",", $cols_n_values);
1327 1327
 
1328 1328
 	}
1329 1329
 
@@ -1335,11 +1335,11 @@  discard block
 block discarded – undo
1335 1335
 	 * @param mixed $id
1336 1336
 	 * @return boolean whether the row got deleted or not
1337 1337
 	 */
1338
-	public function delete_by_ID( $id ){
1339
-		return $this->delete( array(
1340
-			array( $this->get_primary_key_field()->get_name() => $id ),
1338
+	public function delete_by_ID($id) {
1339
+		return $this->delete(array(
1340
+			array($this->get_primary_key_field()->get_name() => $id),
1341 1341
 			'limit' 	=> 1
1342
-		) );
1342
+		));
1343 1343
 	}
1344 1344
 
1345 1345
 
@@ -1354,7 +1354,7 @@  discard block
 block discarded – undo
1354 1354
 	 * which may depend on it. Its generally advisable to always leave this as TRUE, otherwise you could easily corrupt your DB
1355 1355
 	 * @return int how many rows got deleted
1356 1356
 	 */
1357
-	function delete($query_params,$allow_blocking = true){
1357
+	function delete($query_params, $allow_blocking = true) {
1358 1358
 		/**
1359 1359
 		 * Action called just before performing a real deletion query. You can use the
1360 1360
 		 * model and its $query_params to find exactly which items will be deleted
@@ -1363,34 +1363,34 @@  discard block
 block discarded – undo
1363 1363
 		 * @param boolean $allow_blocking whether or not to allow related model objects
1364 1364
 		 * to block (prevent) this deletion
1365 1365
 		 */
1366
-		do_action( 'AHEE__EEM_Base__delete__begin', $this, $query_params, $allow_blocking );
1366
+		do_action('AHEE__EEM_Base__delete__begin', $this, $query_params, $allow_blocking);
1367 1367
 		//some MySQL databases may be running safe mode, which may restrict
1368 1368
 		//deletion if there is no KEY column used in the WHERE statement of a deletion.
1369 1369
 		//to get around this, we first do a SELECT, get all the IDs, and then run another query
1370 1370
 		//to delete them
1371 1371
 		$items_for_deletion = $this->_get_all_wpdb_results($query_params);
1372
-		$deletion_where = $this->_setup_ids_for_delete( $items_for_deletion, $allow_blocking);
1373
-		if($deletion_where){
1372
+		$deletion_where = $this->_setup_ids_for_delete($items_for_deletion, $allow_blocking);
1373
+		if ($deletion_where) {
1374 1374
 			//echo "objects for deletion:";var_dump($objects_for_deletion);
1375 1375
 			$model_query_info = $this->_create_model_query_info_carrier($query_params);
1376 1376
 			$table_aliases = array();
1377
-			foreach(array_keys($this->_tables) as $table_alias){
1377
+			foreach (array_keys($this->_tables) as $table_alias) {
1378 1378
 				$table_aliases[] = $table_alias;
1379 1379
 			}
1380
-			$SQL = "DELETE ".implode(", ",$table_aliases)." FROM ".$model_query_info->get_full_join_sql()." WHERE ".$deletion_where;
1380
+			$SQL = "DELETE ".implode(", ", $table_aliases)." FROM ".$model_query_info->get_full_join_sql()." WHERE ".$deletion_where;
1381 1381
 
1382 1382
 			//		/echo "delete sql:$SQL";
1383
-			$rows_deleted = $this->_do_wpdb_query( 'query', array( $SQL ) );
1384
-		}else{
1383
+			$rows_deleted = $this->_do_wpdb_query('query', array($SQL));
1384
+		} else {
1385 1385
 			$rows_deleted = 0;
1386 1386
 		}
1387 1387
 
1388 1388
 		//and lastly make sure those items are removed from the entity map; if they could be put into it at all
1389
-		if( $this->has_primary_key_field() ){
1390
-			foreach($items_for_deletion as $item_for_deletion_row ){
1391
-				$pk_value = $item_for_deletion_row[ $this->get_primary_key_field()->get_qualified_column() ];
1392
-				if( isset( $this->_entity_map[ $pk_value ] ) ){
1393
-					unset( $this->_entity_map[ $pk_value ] );
1389
+		if ($this->has_primary_key_field()) {
1390
+			foreach ($items_for_deletion as $item_for_deletion_row) {
1391
+				$pk_value = $item_for_deletion_row[$this->get_primary_key_field()->get_qualified_column()];
1392
+				if (isset($this->_entity_map[$pk_value])) {
1393
+					unset($this->_entity_map[$pk_value]);
1394 1394
 				}
1395 1395
 			}
1396 1396
 		}
@@ -1402,8 +1402,8 @@  discard block
 block discarded – undo
1402 1402
 		 * @param array $query_params @see EEM_Base::get_all()
1403 1403
 		 * @param int $rows_deleted
1404 1404
 		 */
1405
-		do_action( 'AHEE__EEM_Base__delete__end', $this, $query_params, $rows_deleted );
1406
-		return $rows_deleted;//how many supposedly got deleted
1405
+		do_action('AHEE__EEM_Base__delete__end', $this, $query_params, $rows_deleted);
1406
+		return $rows_deleted; //how many supposedly got deleted
1407 1407
 	}
1408 1408
 
1409 1409
 
@@ -1419,28 +1419,28 @@  discard block
 block discarded – undo
1419 1419
 	 * blocking its deletion before removing the relation between A and B
1420 1420
 	 * @return boolean
1421 1421
 	 */
1422
-	public function delete_is_blocked_by_related_models($this_model_obj_or_id, $ignore_this_model_obj = null){
1422
+	public function delete_is_blocked_by_related_models($this_model_obj_or_id, $ignore_this_model_obj = null) {
1423 1423
 		//first, if $ignore_this_model_obj was supplied, get its model
1424
-		if($ignore_this_model_obj && $ignore_this_model_obj instanceof EE_Base_Class){
1424
+		if ($ignore_this_model_obj && $ignore_this_model_obj instanceof EE_Base_Class) {
1425 1425
 			$ignored_model = $ignore_this_model_obj->get_model();
1426
-		}else{
1426
+		} else {
1427 1427
 			$ignored_model = null;
1428 1428
 		}
1429 1429
 		//now check all the relations of $this_model_obj_or_id and see if there
1430 1430
 		//are any related model objects blocking it?
1431 1431
 		$is_blocked = false;
1432
-		foreach($this->_model_relations as $relation_name => $relation_obj){
1433
-			if( $relation_obj->block_delete_if_related_models_exist()){
1432
+		foreach ($this->_model_relations as $relation_name => $relation_obj) {
1433
+			if ($relation_obj->block_delete_if_related_models_exist()) {
1434 1434
 				//if $ignore_this_model_obj was supplied, then for the query
1435 1435
 				//on that model needs to be told to ignore $ignore_this_model_obj
1436
-				if($ignored_model && $relation_name == $ignored_model->get_this_model_name()){
1437
-					$related_model_objects = $relation_obj->get_all_related($this_model_obj_or_id,array(
1438
-					array($ignored_model->get_primary_key_field()->get_name() => array('!=',$ignore_this_model_obj->ID()))));
1439
-				}else{
1436
+				if ($ignored_model && $relation_name == $ignored_model->get_this_model_name()) {
1437
+					$related_model_objects = $relation_obj->get_all_related($this_model_obj_or_id, array(
1438
+					array($ignored_model->get_primary_key_field()->get_name() => array('!=', $ignore_this_model_obj->ID()))));
1439
+				} else {
1440 1440
 					$related_model_objects = $relation_obj->get_all_related($this_model_obj_or_id);
1441 1441
 				}
1442 1442
 
1443
-				if($related_model_objects){
1443
+				if ($related_model_objects) {
1444 1444
 					EE_Error::add_error($relation_obj->get_deletion_error_message(), __FILE__, __FUNCTION__, __LINE__);
1445 1445
 					$is_blocked = true;
1446 1446
 				}
@@ -1460,65 +1460,65 @@  discard block
 block discarded – undo
1460 1460
 	 * @throws EE_Error
1461 1461
 	 * @return string    everything that comes after the WHERE statement.
1462 1462
 	 */
1463
-	protected function _setup_ids_for_delete( $objects_for_deletion, $allow_blocking = true) {
1464
-		if($this->has_primary_key_field()){
1463
+	protected function _setup_ids_for_delete($objects_for_deletion, $allow_blocking = true) {
1464
+		if ($this->has_primary_key_field()) {
1465 1465
 			$primary_table = $this->_get_main_table();
1466 1466
 			$other_tables = $this->_get_other_tables();
1467 1467
 			$deletes = $query = array();
1468
-			foreach ( $objects_for_deletion as $delete_object ) {
1468
+			foreach ($objects_for_deletion as $delete_object) {
1469 1469
 				//before we mark this object for deletion,
1470 1470
 				//make sure there's no related objects blocking its deletion (if we're checking)
1471
-				if( $allow_blocking && $this->delete_is_blocked_by_related_models($delete_object[$primary_table->get_fully_qualified_pk_column()]) ){
1471
+				if ($allow_blocking && $this->delete_is_blocked_by_related_models($delete_object[$primary_table->get_fully_qualified_pk_column()])) {
1472 1472
 					continue;
1473 1473
 				}
1474 1474
 
1475 1475
 				//primary table deletes
1476
-				if ( isset( $delete_object[$primary_table->get_fully_qualified_pk_column()] ) )
1476
+				if (isset($delete_object[$primary_table->get_fully_qualified_pk_column()]))
1477 1477
 					$deletes[$primary_table->get_fully_qualified_pk_column()][] = $delete_object[$primary_table->get_fully_qualified_pk_column()];
1478 1478
 
1479 1479
 				//other tables
1480
-				if ( !empty( $other_tables ) ) {
1481
-					foreach ( $other_tables as $ot ) {
1480
+				if ( ! empty($other_tables)) {
1481
+					foreach ($other_tables as $ot) {
1482 1482
 
1483 1483
 						//first check if we've got the foreign key column here.
1484
-						if ( isset( $delete_object[$ot->get_fully_qualified_fk_column()] ) )
1484
+						if (isset($delete_object[$ot->get_fully_qualified_fk_column()]))
1485 1485
 							$deletes[$ot->get_fully_qualified_pk_column()][] = $delete_object[$ot->get_fully_qualified_fk_column()];
1486 1486
 
1487 1487
 						//wait! it's entirely possible that we'll have a the primary key for this table in here if it's a foreign key for one of the other secondary tables
1488
-						if ( isset( $delete_object[$ot->get_fully_qualified_pk_column()] ) )
1488
+						if (isset($delete_object[$ot->get_fully_qualified_pk_column()]))
1489 1489
 							$deletes[$ot->get_fully_qualified_pk_column()][] = $delete_object[$ot->get_fully_qualified_pk_column()];
1490 1490
 
1491 1491
 						//finally, it is possible that the fk for this table is found in the fully qualified pk column for the fk table, so let's see if that's there!
1492
-						if ( isset( $delete_object[$ot->get_fully_qualified_pk_on_fk_table()]) )
1492
+						if (isset($delete_object[$ot->get_fully_qualified_pk_on_fk_table()]))
1493 1493
 							$deletes[$ot->get_fully_qualified_pk_column()][] = $delete_object[$ot->get_fully_qualified_pk_column()];
1494 1494
 					}
1495 1495
 				}
1496 1496
 			}
1497 1497
 
1498 1498
 			//we should have deletes now, so let's just go through and setup the where statement
1499
-			foreach ( $deletes as $column => $values ) {
1499
+			foreach ($deletes as $column => $values) {
1500 1500
 				//make sure we have unique $values;
1501 1501
 				$values = array_unique($values);
1502
-				$query[] = $column . ' IN(' . implode(",",$values) . ')';
1502
+				$query[] = $column.' IN('.implode(",", $values).')';
1503 1503
 			}
1504 1504
 
1505
-			return !empty($query) ? implode(' AND ', $query ) : '';
1506
-		}elseif(count($this->get_combined_primary_key_fields()) > 1){
1505
+			return ! empty($query) ? implode(' AND ', $query) : '';
1506
+		}elseif (count($this->get_combined_primary_key_fields()) > 1) {
1507 1507
 			$ways_to_identify_a_row = array();
1508 1508
 			$fields = $this->get_combined_primary_key_fields();
1509 1509
 			//note: because there' sno primary key, that means nothing else  can be pointing to this model, right?
1510
-			foreach($objects_for_deletion as  $delete_object){
1510
+			foreach ($objects_for_deletion as  $delete_object) {
1511 1511
 				$values_for_each_cpk_for_a_row = array();
1512
-				foreach($fields as $cpk_field){
1512
+				foreach ($fields as $cpk_field) {
1513 1513
 					$values_for_each_cpk_for_a_row[] = $cpk_field->get_qualified_column()."=".$delete_object[$cpk_field->get_qualified_column()];
1514 1514
 				}
1515
-				$ways_to_identify_a_row[] = "(".implode(" AND ",$values_for_each_cpk_for_a_row).")";
1515
+				$ways_to_identify_a_row[] = "(".implode(" AND ", $values_for_each_cpk_for_a_row).")";
1516 1516
 			}
1517
-			return implode(" OR ",$ways_to_identify_a_row);
1518
-		}else{
1517
+			return implode(" OR ", $ways_to_identify_a_row);
1518
+		} else {
1519 1519
 			//so there's no primary key and no combined key...
1520 1520
 			//sorry, can't help you
1521
-			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)));
1521
+			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)));
1522 1522
 		}
1523 1523
 	}
1524 1524
 
@@ -1532,21 +1532,21 @@  discard block
 block discarded – undo
1532 1532
 	 * @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;
1533 1533
 	 * @return int
1534 1534
 	 */
1535
-	function count($query_params =array(),$field_to_count = NULL, $distinct = FALSE){
1535
+	function count($query_params = array(), $field_to_count = NULL, $distinct = FALSE) {
1536 1536
 		$model_query_info = $this->_create_model_query_info_carrier($query_params);
1537
-		if($field_to_count){
1537
+		if ($field_to_count) {
1538 1538
 			$field_obj = $this->field_settings_for($field_to_count);
1539 1539
 			$column_to_count = $field_obj->get_qualified_column();
1540
-		}elseif($this->has_primary_key_field ()){
1540
+		}elseif ($this->has_primary_key_field()) {
1541 1541
 			$pk_field_obj = $this->get_primary_key_field();
1542 1542
 			$column_to_count = $pk_field_obj->get_qualified_column();
1543
-		}else{//there's no primary key
1543
+		} else {//there's no primary key
1544 1544
 			$column_to_count = '*';
1545 1545
 		}
1546 1546
 
1547
-		$column_to_count = $distinct ? "DISTINCT (" . $column_to_count . " )" : $column_to_count;
1548
-		$SQL ="SELECT COUNT(".$column_to_count.")" . $this->_construct_2nd_half_of_select_query($model_query_info);
1549
-		return (int)$this->_do_wpdb_query( 'get_var', array( $SQL) );
1547
+		$column_to_count = $distinct ? "DISTINCT (".$column_to_count." )" : $column_to_count;
1548
+		$SQL = "SELECT COUNT(".$column_to_count.")".$this->_construct_2nd_half_of_select_query($model_query_info);
1549
+		return (int) $this->_do_wpdb_query('get_var', array($SQL));
1550 1550
 	}
1551 1551
 
1552 1552
 	/**
@@ -1556,23 +1556,23 @@  discard block
 block discarded – undo
1556 1556
 	 * @param string $field_to_sum name of field (array key in $_fields array)
1557 1557
 	 * @return int
1558 1558
 	 */
1559
-	function sum($query_params, $field_to_sum = NULL){
1559
+	function sum($query_params, $field_to_sum = NULL) {
1560 1560
 		$model_query_info = $this->_create_model_query_info_carrier($query_params);
1561 1561
 
1562
-		if($field_to_sum){
1562
+		if ($field_to_sum) {
1563 1563
 			$field_obj = $this->field_settings_for($field_to_sum);
1564 1564
 
1565
-		}else{
1565
+		} else {
1566 1566
 			$field_obj = $this->get_primary_key_field();
1567 1567
 		}
1568 1568
 		$column_to_count = $field_obj->get_qualified_column();
1569 1569
 
1570
-		$SQL ="SELECT SUM(".$column_to_count.")" . $this->_construct_2nd_half_of_select_query($model_query_info);
1571
-		$return_value = $this->_do_wpdb_query('get_var',array( $SQL ) );
1572
-		if($field_obj->get_wpdb_data_type() == '%d' || $field_obj->get_wpdb_data_type() == '%s' ){
1573
-			return (int)$return_value;
1574
-		}else{//must be %f
1575
-			return (float)$return_value;
1570
+		$SQL = "SELECT SUM(".$column_to_count.")".$this->_construct_2nd_half_of_select_query($model_query_info);
1571
+		$return_value = $this->_do_wpdb_query('get_var', array($SQL));
1572
+		if ($field_obj->get_wpdb_data_type() == '%d' || $field_obj->get_wpdb_data_type() == '%s') {
1573
+			return (int) $return_value;
1574
+		} else {//must be %f
1575
+			return (float) $return_value;
1576 1576
 		}
1577 1577
 	}
1578 1578
 
@@ -1587,34 +1587,34 @@  discard block
 block discarded – undo
1587 1587
 	 * @global wpdb $wpdb
1588 1588
 	 * @return mixed
1589 1589
 	 */
1590
-	protected function _do_wpdb_query( $wpdb_method, $arguments_to_provide ){
1590
+	protected function _do_wpdb_query($wpdb_method, $arguments_to_provide) {
1591 1591
 		//if we're in maintenance mode level 2, DON'T run any queries
1592 1592
 		//because level 2 indicates the database needs updating and
1593 1593
 		//is probably out of sync with the code
1594
-		if( ! EE_Maintenance_Mode::instance()->models_can_query()){
1594
+		if ( ! EE_Maintenance_Mode::instance()->models_can_query()) {
1595 1595
 			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")));
1596 1596
 		}
1597 1597
 		global $wpdb;
1598
-		if( ! method_exists( $wpdb, $wpdb_method ) ){
1599
-			throw new EE_Error( sprintf( __( 'There is no method named "%s" on Wordpress\' $wpdb object','event_espresso' ), $wpdb_method ) );
1598
+		if ( ! method_exists($wpdb, $wpdb_method)) {
1599
+			throw new EE_Error(sprintf(__('There is no method named "%s" on Wordpress\' $wpdb object', 'event_espresso'), $wpdb_method));
1600 1600
 		}
1601
-		if( WP_DEBUG ){
1601
+		if (WP_DEBUG) {
1602 1602
 			$wpdb->last_error = NULL;
1603 1603
 			$old_show_errors_value = $wpdb->show_errors;
1604
-			$wpdb->show_errors( FALSE );
1604
+			$wpdb->show_errors(FALSE);
1605 1605
 		}
1606 1606
 
1607
-		$result = call_user_func_array( array( $wpdb, $wpdb_method ) , $arguments_to_provide );
1608
-		$this->show_db_query_if_previously_requested( $wpdb->last_query );
1609
-		if( WP_DEBUG ){
1610
-			$wpdb->show_errors( $old_show_errors_value );
1611
-			if( ! empty( $wpdb->last_error ) ){
1612
-				throw new EE_Error( sprintf( __( 'WPDB Error: "%s"', 'event_espresso' ), $wpdb->last_error ) );
1613
-			}elseif( $result === false ){
1614
-				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 ) ) );
1607
+		$result = call_user_func_array(array($wpdb, $wpdb_method), $arguments_to_provide);
1608
+		$this->show_db_query_if_previously_requested($wpdb->last_query);
1609
+		if (WP_DEBUG) {
1610
+			$wpdb->show_errors($old_show_errors_value);
1611
+			if ( ! empty($wpdb->last_error)) {
1612
+				throw new EE_Error(sprintf(__('WPDB Error: "%s"', 'event_espresso'), $wpdb->last_error));
1613
+			}elseif ($result === false) {
1614
+				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)));
1615 1615
 			}
1616
-		}elseif( $result === false ) {
1617
-			EE_Error::add_error( sprintf( __( 'A database error has occurred. Turn on WP_DEBUG for more information.', 'event_espresso' )), __FILE__, __FUNCTION__, __LINE__);
1616
+		}elseif ($result === false) {
1617
+			EE_Error::add_error(sprintf(__('A database error has occurred. Turn on WP_DEBUG for more information.', 'event_espresso')), __FILE__, __FUNCTION__, __LINE__);
1618 1618
 		}
1619 1619
 		return $result;
1620 1620
 	}
@@ -1626,7 +1626,7 @@  discard block
 block discarded – undo
1626 1626
 	 * @param EE_Model_Query_Info_Carrier $model_query_info
1627 1627
 	 * @return string
1628 1628
 	 */
1629
-	private function _construct_2nd_half_of_select_query(EE_Model_Query_Info_Carrier $model_query_info){
1629
+	private function _construct_2nd_half_of_select_query(EE_Model_Query_Info_Carrier $model_query_info) {
1630 1630
 		return " FROM ".$model_query_info->get_full_join_sql().
1631 1631
 				$model_query_info->get_where_sql().
1632 1632
 				$model_query_info->get_group_by_sql().
@@ -1639,7 +1639,7 @@  discard block
 block discarded – undo
1639 1639
 	 * Set to easily debug the next X queries ran from this model.
1640 1640
 	 * @param int $count
1641 1641
 	 */
1642
-	function show_next_x_db_queries($count = 1){
1642
+	function show_next_x_db_queries($count = 1) {
1643 1643
 		$this->_show_next_x_db_queries = $count;
1644 1644
 	}
1645 1645
 
@@ -1648,8 +1648,8 @@  discard block
 block discarded – undo
1648 1648
 	/**
1649 1649
 	 * @param $sql_query
1650 1650
 	 */
1651
-	function show_db_query_if_previously_requested($sql_query){
1652
-		if($this->_show_next_x_db_queries > 0){
1651
+	function show_db_query_if_previously_requested($sql_query) {
1652
+		if ($this->_show_next_x_db_queries > 0) {
1653 1653
 			echo $sql_query;
1654 1654
 			$this->_show_next_x_db_queries--;
1655 1655
 		}
@@ -1673,7 +1673,7 @@  discard block
 block discarded – undo
1673 1673
 	 * @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.
1674 1674
 	 * @return EE_Base_Class which was added as a relation. Object referred to by $other_model_id_or_obj
1675 1675
 	 */
1676
-	public function add_relationship_to($id_or_obj,$other_model_id_or_obj, $relationName, $where_query = array()){
1676
+	public function add_relationship_to($id_or_obj, $other_model_id_or_obj, $relationName, $where_query = array()) {
1677 1677
 		$relation_obj = $this->related_settings_for($relationName);
1678 1678
 		return $relation_obj->add_relation_to($id_or_obj, $other_model_id_or_obj, $where_query);
1679 1679
 	}
@@ -1694,9 +1694,9 @@  discard block
 block discarded – undo
1694 1694
 	 * @return boolean of success
1695 1695
 	 * @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.
1696 1696
 	 */
1697
-	public function remove_relationship_to($id_or_obj,  $other_model_id_or_obj, $relationName, $where_query= array() ){
1697
+	public function remove_relationship_to($id_or_obj, $other_model_id_or_obj, $relationName, $where_query = array()) {
1698 1698
 		$relation_obj = $this->related_settings_for($relationName);
1699
-		return $relation_obj->remove_relation_to($id_or_obj, $other_model_id_or_obj, $where_query );
1699
+		return $relation_obj->remove_relation_to($id_or_obj, $other_model_id_or_obj, $where_query);
1700 1700
 	}
1701 1701
 
1702 1702
 
@@ -1709,9 +1709,9 @@  discard block
 block discarded – undo
1709 1709
 	 * @param EE_Base_Class[] objects to which relations were removed
1710 1710
 	 * @return \EE_Base_Class[]
1711 1711
 	 */
1712
-	public function remove_relations($id_or_obj,$relationName,$where_query_params = array()){
1712
+	public function remove_relations($id_or_obj, $relationName, $where_query_params = array()) {
1713 1713
 		$relation_obj = $this->related_settings_for($relationName);
1714
-		return $relation_obj->remove_relations($id_or_obj, $where_query_params );
1714
+		return $relation_obj->remove_relations($id_or_obj, $where_query_params);
1715 1715
 	}
1716 1716
 
1717 1717
 
@@ -1724,10 +1724,10 @@  discard block
 block discarded – undo
1724 1724
 	 * @param array $query_params like EEM_Base::get_all
1725 1725
 	 * @return EE_Base_Class[]
1726 1726
 	 */
1727
-	function get_all_related($id_or_obj, $model_name, $query_params = null){
1727
+	function get_all_related($id_or_obj, $model_name, $query_params = null) {
1728 1728
 		$model_obj = $this->ensure_is_obj($id_or_obj);
1729 1729
 		$relation_settings = $this->related_settings_for($model_name);
1730
-		return $relation_settings->get_all_related($model_obj,$query_params);
1730
+		return $relation_settings->get_all_related($model_obj, $query_params);
1731 1731
 	}
1732 1732
 
1733 1733
 	/**
@@ -1740,10 +1740,10 @@  discard block
 block discarded – undo
1740 1740
 	 * @param array $query_params
1741 1741
 	 * @return int how many deleted
1742 1742
 	 */
1743
-	public function delete_related($id_or_obj,$model_name, $query_params = array()){
1743
+	public function delete_related($id_or_obj, $model_name, $query_params = array()) {
1744 1744
 		$model_obj = $this->ensure_is_obj($id_or_obj);
1745 1745
 		$relation_settings = $this->related_settings_for($model_name);
1746
-		return $relation_settings->delete_all_related($model_obj,$query_params);
1746
+		return $relation_settings->delete_all_related($model_obj, $query_params);
1747 1747
 	}
1748 1748
 
1749 1749
 	/**
@@ -1756,10 +1756,10 @@  discard block
 block discarded – undo
1756 1756
 	 * @param array $query_params
1757 1757
 	 * @return int how many deleted
1758 1758
 	 */
1759
-	public function delete_related_permanently($id_or_obj,$model_name, $query_params = array()){
1759
+	public function delete_related_permanently($id_or_obj, $model_name, $query_params = array()) {
1760 1760
 		$model_obj = $this->ensure_is_obj($id_or_obj);
1761 1761
 		$relation_settings = $this->related_settings_for($model_name);
1762
-		return $relation_settings->delete_related_permanently($model_obj,$query_params);
1762
+		return $relation_settings->delete_related_permanently($model_obj, $query_params);
1763 1763
 	}
1764 1764
 
1765 1765
 	/**
@@ -1772,17 +1772,17 @@  discard block
 block discarded – undo
1772 1772
 	 * @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;
1773 1773
 	 * @return int
1774 1774
 	 */
1775
-	function count_related($id_or_obj,$model_name,$query_params = array(),$field_to_count = null, $distinct = FALSE){
1775
+	function count_related($id_or_obj, $model_name, $query_params = array(), $field_to_count = null, $distinct = FALSE) {
1776 1776
 		$related_model = $this->get_related_model_obj($model_name);
1777 1777
 		//we're just going to use the query params on the related model's normal get_all query,
1778 1778
 		//except add a condition to say to match the current mod
1779
-		if( ! isset($query_params['default_where_conditions'])){
1780
-			$query_params['default_where_conditions']='none';
1779
+		if ( ! isset($query_params['default_where_conditions'])) {
1780
+			$query_params['default_where_conditions'] = 'none';
1781 1781
 		}
1782 1782
 		$this_model_name = $this->get_this_model_name();
1783 1783
 		$this_pk_field_name = $this->get_primary_key_field()->get_name();
1784
-		$query_params[0][$this_model_name.".".$this_pk_field_name]=$id_or_obj;
1785
-		return $related_model->count($query_params,$field_to_count,$distinct);
1784
+		$query_params[0][$this_model_name.".".$this_pk_field_name] = $id_or_obj;
1785
+		return $related_model->count($query_params, $field_to_count, $distinct);
1786 1786
 	}
1787 1787
 
1788 1788
 
@@ -1796,21 +1796,21 @@  discard block
 block discarded – undo
1796 1796
 	 * @param string $field_to_sum name of field to count by. By default, uses primary key
1797 1797
 	 * @return int
1798 1798
 	 */
1799
-	function sum_related($id_or_obj,$model_name,$query_params,$field_to_sum = null){
1799
+	function sum_related($id_or_obj, $model_name, $query_params, $field_to_sum = null) {
1800 1800
 		$related_model = $this->get_related_model_obj($model_name);
1801
-		if( ! is_array( $query_params ) ){
1802
-			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' );
1801
+		if ( ! is_array($query_params)) {
1802
+			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');
1803 1803
 			$query_params = array();
1804 1804
 		}
1805 1805
 		//we're just going to use the query params on the related model's normal get_all query,
1806 1806
 		//except add a condition to say to match the current mod
1807
-		if( ! isset($query_params['default_where_conditions'])){
1808
-			$query_params['default_where_conditions']='none';
1807
+		if ( ! isset($query_params['default_where_conditions'])) {
1808
+			$query_params['default_where_conditions'] = 'none';
1809 1809
 		}
1810 1810
 		$this_model_name = $this->get_this_model_name();
1811 1811
 		$this_pk_field_name = $this->get_primary_key_field()->get_name();
1812
-		$query_params[0][$this_model_name.".".$this_pk_field_name]=$id_or_obj;
1813
-		return $related_model->sum($query_params,$field_to_sum);
1812
+		$query_params[0][$this_model_name.".".$this_pk_field_name] = $id_or_obj;
1813
+		return $related_model->sum($query_params, $field_to_sum);
1814 1814
 	}
1815 1815
 
1816 1816
 
@@ -1822,12 +1822,12 @@  discard block
 block discarded – undo
1822 1822
 	 * @param array $query_params like EEM_Base::get_all's
1823 1823
 	 * @return EE_Base_Class
1824 1824
 	 */
1825
-	public function get_first_related( EE_Base_Class $id_or_obj, $other_model_name, $query_params ){
1826
-		$query_params['limit']=1;
1827
-		$results = $this->get_all_related($id_or_obj,$other_model_name,$query_params);
1828
-		if( $results ){
1825
+	public function get_first_related(EE_Base_Class $id_or_obj, $other_model_name, $query_params) {
1826
+		$query_params['limit'] = 1;
1827
+		$results = $this->get_all_related($id_or_obj, $other_model_name, $query_params);
1828
+		if ($results) {
1829 1829
 			return array_shift($results);
1830
-		}else{
1830
+		} else {
1831 1831
 			return null;
1832 1832
 		}
1833 1833
 
@@ -1837,8 +1837,8 @@  discard block
 block discarded – undo
1837 1837
 	 * Gets the model's name as it's expected in queries. For example, if this is EEM_Event model, that would be Event
1838 1838
 	 * @return string
1839 1839
 	 */
1840
-	function get_this_model_name(){
1841
-		return str_replace("EEM_","",get_class($this));
1840
+	function get_this_model_name() {
1841
+		return str_replace("EEM_", "", get_class($this));
1842 1842
 	}
1843 1843
 
1844 1844
 	/**
@@ -1846,14 +1846,14 @@  discard block
 block discarded – undo
1846 1846
 	 * @return EE_Any_Foreign_Model_Name_Field
1847 1847
 	 * @throws EE_Error
1848 1848
 	 */
1849
-	public function get_field_containing_related_model_name(){
1850
-		foreach($this->field_settings(true) as $field){
1851
-			if($field instanceof EE_Any_Foreign_Model_Name_Field){
1849
+	public function get_field_containing_related_model_name() {
1850
+		foreach ($this->field_settings(true) as $field) {
1851
+			if ($field instanceof EE_Any_Foreign_Model_Name_Field) {
1852 1852
 				$field_with_model_name = $field;
1853 1853
 			}
1854 1854
 		}
1855
-		if( !isset($field_with_model_name) || !$field_with_model_name ){
1856
-			throw new EE_Error(sprintf(__("There is no EE_Any_Foreign_Model_Name field on model %s", "event_espresso"), $this->get_this_model_name() ));
1855
+		if ( ! isset($field_with_model_name) || ! $field_with_model_name) {
1856
+			throw new EE_Error(sprintf(__("There is no EE_Any_Foreign_Model_Name field on model %s", "event_espresso"), $this->get_this_model_name()));
1857 1857
 		}
1858 1858
 		return $field_with_model_name;
1859 1859
 	}
@@ -1874,19 +1874,19 @@  discard block
 block discarded – undo
1874 1874
 	 * @return int new primary key on main table that got inserted
1875 1875
 	 * @throws EE_Error
1876 1876
 	 */
1877
-	function insert($field_n_values){
1877
+	function insert($field_n_values) {
1878 1878
 		/**
1879 1879
 		 * Filters the fields and their values before inserting an item using the models
1880 1880
 		 * @param array $fields_n_values keys are the fields and values are their new values
1881 1881
 		 * @param EEM_Base $model the model used
1882 1882
 		 */
1883
-		$field_n_values = apply_filters( 'FHEE__EEM_Base__insert__fields_n_values', $field_n_values, $this );
1884
-		if($this->_satisfies_unique_indexes($field_n_values)){
1883
+		$field_n_values = apply_filters('FHEE__EEM_Base__insert__fields_n_values', $field_n_values, $this);
1884
+		if ($this->_satisfies_unique_indexes($field_n_values)) {
1885 1885
 			$main_table = $this->_get_main_table();
1886 1886
 			$new_id = $this->_insert_into_specific_table($main_table, $field_n_values, false);
1887
-			if( $new_id !== false ) {
1888
-				foreach($this->_get_other_tables() as $other_table){
1889
-					$this->_insert_into_specific_table($other_table, $field_n_values,$new_id);
1887
+			if ($new_id !== false) {
1888
+				foreach ($this->_get_other_tables() as $other_table) {
1889
+					$this->_insert_into_specific_table($other_table, $field_n_values, $new_id);
1890 1890
 				}
1891 1891
 			}
1892 1892
 			/**
@@ -1896,9 +1896,9 @@  discard block
 block discarded – undo
1896 1896
 			 * @param array $fields_n_values fields and their values
1897 1897
 			 * @param int|string the ID of the newly-inserted model object
1898 1898
 			 */
1899
-			do_action( 'AHEE__EEM_Base__insert__end', $this, $field_n_values, $new_id );
1899
+			do_action('AHEE__EEM_Base__insert__end', $this, $field_n_values, $new_id);
1900 1900
 			return $new_id;
1901
-		}else{
1901
+		} else {
1902 1902
 			return FALSE;
1903 1903
 		}
1904 1904
 	}
@@ -1911,11 +1911,11 @@  discard block
 block discarded – undo
1911 1911
 	 * @param string $action
1912 1912
 	 * @return boolean
1913 1913
 	 */
1914
-	protected function _satisfies_unique_indexes($field_n_values,$action = 'insert'){
1915
-		foreach($this->unique_indexes() as $index_name => $index){
1914
+	protected function _satisfies_unique_indexes($field_n_values, $action = 'insert') {
1915
+		foreach ($this->unique_indexes() as $index_name => $index) {
1916 1916
 			$uniqueness_where_params = array_intersect_key($field_n_values, $index->fields());
1917
-			if($this->exists(array($uniqueness_where_params))){
1918
-				EE_Error::add_error(sprintf(__("Could not %s %s. %s uniqueness index failed. Fields %s must form a unique set, but an entry already exists with values %s.", "event_espresso"),$action,$this->_get_class_name(),$index_name,implode(",",$index->field_names()),http_build_query($uniqueness_where_params)), __FILE__, __FUNCTION__, __LINE__ );
1917
+			if ($this->exists(array($uniqueness_where_params))) {
1918
+				EE_Error::add_error(sprintf(__("Could not %s %s. %s uniqueness index failed. Fields %s must form a unique set, but an entry already exists with values %s.", "event_espresso"), $action, $this->_get_class_name(), $index_name, implode(",", $index->field_names()), http_build_query($uniqueness_where_params)), __FILE__, __FUNCTION__, __LINE__);
1919 1919
 				return false;
1920 1920
 			}
1921 1921
 		}
@@ -1936,28 +1936,28 @@  discard block
 block discarded – undo
1936 1936
 	 * @throws EE_Error
1937 1937
 	 * @return EE_Base_Class
1938 1938
 	 */
1939
-	public function get_one_conflicting($obj_or_fields_array, $include_primary_key = true ){
1940
-		if($obj_or_fields_array instanceof EE_Base_Class){
1939
+	public function get_one_conflicting($obj_or_fields_array, $include_primary_key = true) {
1940
+		if ($obj_or_fields_array instanceof EE_Base_Class) {
1941 1941
 			$fields_n_values = $obj_or_fields_array->model_field_array();
1942
-		}elseif( is_array($obj_or_fields_array)){
1942
+		}elseif (is_array($obj_or_fields_array)) {
1943 1943
 			$fields_n_values = $obj_or_fields_array;
1944
-		}else{
1945
-			throw new EE_Error(sprintf(__("%s get_all_conflicting should be called with a model object or an array of field names and values, you provided %d", "event_espresso"),get_class($this),$obj_or_fields_array));
1944
+		} else {
1945
+			throw new EE_Error(sprintf(__("%s get_all_conflicting should be called with a model object or an array of field names and values, you provided %d", "event_espresso"), get_class($this), $obj_or_fields_array));
1946 1946
 		}
1947 1947
 		$query_params = array();
1948
-		if( $this->has_primary_key_field() &&
1949
-				( $include_primary_key || $this->get_primary_key_field() instanceof EE_Primary_Key_String_Field) &&
1950
-				isset($fields_n_values[$this->primary_key_name()])){
1948
+		if ($this->has_primary_key_field() &&
1949
+				($include_primary_key || $this->get_primary_key_field() instanceof EE_Primary_Key_String_Field) &&
1950
+				isset($fields_n_values[$this->primary_key_name()])) {
1951 1951
 			$query_params[0]['OR'][$this->primary_key_name()] = $fields_n_values[$this->primary_key_name()];
1952 1952
 		}
1953
-		foreach($this->unique_indexes() as $unique_index_name=>$unique_index){
1953
+		foreach ($this->unique_indexes() as $unique_index_name=>$unique_index) {
1954 1954
 			$uniqueness_where_params = array_intersect_key($fields_n_values, $unique_index->fields());
1955 1955
 			$query_params[0]['OR']['AND*'.$unique_index_name] = $uniqueness_where_params;
1956 1956
 		}
1957 1957
 		//if there is nothing to base this search on, then we shouldn't find anything
1958
-		if( empty( $query_params ) ){
1958
+		if (empty($query_params)) {
1959 1959
 			return array();
1960
-		}else{
1960
+		} else {
1961 1961
 			return $this->get_one($query_params);
1962 1962
 		}
1963 1963
 	}
@@ -1967,7 +1967,7 @@  discard block
 block discarded – undo
1967 1967
 	 * @param array $query_params
1968 1968
 	 * @return boolean
1969 1969
 	 */
1970
-	function exists($query_params){
1970
+	function exists($query_params) {
1971 1971
 		$query_params['limit'] = 1;
1972 1972
 		return $this->count($query_params) > 0;
1973 1973
 	}
@@ -1977,7 +1977,7 @@  discard block
 block discarded – undo
1977 1977
 	 * @param int|string $id
1978 1978
 	 * @return boolean
1979 1979
 	 */
1980
-	function exists_by_ID($id){
1980
+	function exists_by_ID($id) {
1981 1981
 		return $this->exists(array('default_where_conditions'=>'none', array($this->primary_key_name() => $id)));
1982 1982
 	}
1983 1983
 
@@ -1997,45 +1997,45 @@  discard block
 block discarded – undo
1997 1997
 	 * @global WPDB $wpdb only used to get the $wpdb->insert_id after performing an insert
1998 1998
 	 * @return int ID of new row inserted, or FALSE on failure
1999 1999
 	 */
2000
-	protected function _insert_into_specific_table(EE_Table_Base $table, $fields_n_values, $new_id = 0 ){
2000
+	protected function _insert_into_specific_table(EE_Table_Base $table, $fields_n_values, $new_id = 0) {
2001 2001
 		global $wpdb;
2002 2002
 		$insertion_col_n_values = array();
2003 2003
 		$format_for_insertion = array();
2004 2004
 		$fields_on_table = $this->_get_fields_for_table($table->get_table_alias());
2005
-		foreach($fields_on_table as $field_name => $field_obj){
2005
+		foreach ($fields_on_table as $field_name => $field_obj) {
2006 2006
 			//check if its an auto-incrementing column, in which case we should just leave it to do its autoincrement thing
2007
-			if($field_obj->is_auto_increment()){
2007
+			if ($field_obj->is_auto_increment()) {
2008 2008
 				continue;
2009 2009
 			}
2010 2010
 			$prepared_value = $this->_prepare_value_or_use_default($field_obj, $fields_n_values);
2011 2011
 			//if the value we want to assign it to is NULL, just don't mention it for the insertion
2012
-			if( $prepared_value !== NULL ){
2013
-				$insertion_col_n_values[ $field_obj->get_table_column() ] = $prepared_value;
2012
+			if ($prepared_value !== NULL) {
2013
+				$insertion_col_n_values[$field_obj->get_table_column()] = $prepared_value;
2014 2014
 				$format_for_insertion[] = $field_obj->get_wpdb_data_type();
2015 2015
 			}
2016 2016
 		}
2017 2017
 
2018
-		if($table instanceof EE_Secondary_Table && $new_id){
2018
+		if ($table instanceof EE_Secondary_Table && $new_id) {
2019 2019
 			//its not the main table, so we should have already saved the main table's PK which we just inserted
2020 2020
 			//so add the fk to the main table as a column
2021 2021
 			$insertion_col_n_values[$table->get_fk_on_table()] = $new_id;
2022
-			$format_for_insertion[]='%d';//yes right now we're only allowing these foreign keys to be INTs
2022
+			$format_for_insertion[] = '%d'; //yes right now we're only allowing these foreign keys to be INTs
2023 2023
 		}
2024 2024
 		//insert the new entry
2025
-		$result = $this->_do_wpdb_query( 'insert', array( $table->get_table_name(), $insertion_col_n_values, $format_for_insertion ) );
2026
-		if( $result === false ) {
2025
+		$result = $this->_do_wpdb_query('insert', array($table->get_table_name(), $insertion_col_n_values, $format_for_insertion));
2026
+		if ($result === false) {
2027 2027
 			return false;
2028 2028
 		}
2029 2029
 		//ok, now what do we return for the ID of the newly-inserted thing?
2030
-		if($this->has_primary_key_field()){
2031
-			if($this->get_primary_key_field()->is_auto_increment()){
2030
+		if ($this->has_primary_key_field()) {
2031
+			if ($this->get_primary_key_field()->is_auto_increment()) {
2032 2032
 				return $wpdb->insert_id;
2033
-			}else{
2033
+			} else {
2034 2034
 				//it's not an auto-increment primary key, so
2035 2035
 				//it must have been supplied
2036 2036
 				return $fields_n_values[$this->get_primary_key_field()->get_name()];
2037 2037
 			}
2038
-		}else{
2038
+		} else {
2039 2039
 			//we can't return a  primary key because there is none. instead return
2040 2040
 			//a unique string indicating this model
2041 2041
 			return $this->get_index_primary_key_string($fields_n_values);
@@ -2050,15 +2050,15 @@  discard block
 block discarded – undo
2050 2050
 	 * @param array $fields_n_values
2051 2051
 	 * @return mixed string|int|float depending on what the table column will be expecting
2052 2052
 	 */
2053
-	protected function _prepare_value_or_use_default( $field_obj, $fields_n_values ){
2053
+	protected function _prepare_value_or_use_default($field_obj, $fields_n_values) {
2054 2054
 		//if this field doesn't allow nullable, don't allow it
2055
-		if( ! $field_obj->is_nullable() && (
2056
-				! isset( $fields_n_values[ $field_obj->get_name() ] ) ||
2057
-				$fields_n_values[ $field_obj->get_name() ] === NULL ) ){
2058
-			$fields_n_values[ $field_obj->get_name() ] = $field_obj->get_default_value();
2055
+		if ( ! $field_obj->is_nullable() && (
2056
+				! isset($fields_n_values[$field_obj->get_name()]) ||
2057
+				$fields_n_values[$field_obj->get_name()] === NULL )) {
2058
+			$fields_n_values[$field_obj->get_name()] = $field_obj->get_default_value();
2059 2059
 		}
2060
-		$unprepared_value = isset( $fields_n_values[ $field_obj->get_name() ] ) ? $fields_n_values[ $field_obj->get_name() ] : NULL;
2061
-		return $this->_prepare_value_for_use_in_db( $unprepared_value, $field_obj);
2060
+		$unprepared_value = isset($fields_n_values[$field_obj->get_name()]) ? $fields_n_values[$field_obj->get_name()] : NULL;
2061
+		return $this->_prepare_value_for_use_in_db($unprepared_value, $field_obj);
2062 2062
 	}
2063 2063
 
2064 2064
 
@@ -2070,9 +2070,9 @@  discard block
 block discarded – undo
2070 2070
 	 * @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
2071 2071
 	 * @return mixed a value ready for use in the database for insertions, updating, or in a where clause
2072 2072
 	 */
2073
-	private function _prepare_value_for_use_in_db($value, $field){
2074
-		if($field && $field instanceof EE_Model_Field_Base){
2075
-			switch( $this->_values_already_prepared_by_model_object ){
2073
+	private function _prepare_value_for_use_in_db($value, $field) {
2074
+		if ($field && $field instanceof EE_Model_Field_Base) {
2075
+			switch ($this->_values_already_prepared_by_model_object) {
2076 2076
 				case self::not_prepared_by_model_object:
2077 2077
 					$value = $field->prepare_for_set($value);
2078 2078
 					//purposefully left out "return"
@@ -2082,7 +2082,7 @@  discard block
 block discarded – undo
2082 2082
 					//leave the value alone
2083 2083
 			}
2084 2084
 			return $value;
2085
-		}else{
2085
+		} else {
2086 2086
 			return $value;
2087 2087
 		}
2088 2088
 	}
@@ -2092,13 +2092,13 @@  discard block
 block discarded – undo
2092 2092
 	 * @return EE_Primary_Table
2093 2093
 	 * @throws EE_Error
2094 2094
 	 */
2095
-	protected function _get_main_table(){
2096
-		foreach($this->_tables as $table){
2097
-			if($table instanceof EE_Primary_Table){
2095
+	protected function _get_main_table() {
2096
+		foreach ($this->_tables as $table) {
2097
+			if ($table instanceof EE_Primary_Table) {
2098 2098
 				return $table;
2099 2099
 			}
2100 2100
 		}
2101
-		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)));
2101
+		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)));
2102 2102
 	}
2103 2103
 
2104 2104
 	/**
@@ -2117,7 +2117,7 @@  discard block
 block discarded – undo
2117 2117
 	 */
2118 2118
 	public function second_table() {
2119 2119
 		// grab second table from tables array
2120
-		$second_table = end( $this->_tables );
2120
+		$second_table = end($this->_tables);
2121 2121
 		return $second_table instanceof EE_Secondary_Table ? $second_table->get_table_name() : NULL;
2122 2122
 	}
2123 2123
 
@@ -2130,8 +2130,8 @@  discard block
 block discarded – undo
2130 2130
 	 * @param string $table_alias
2131 2131
 	 * @return EE_Primary_Table | EE_Secondary_Table
2132 2132
 	 */
2133
-	public function get_table_obj_by_alias( $table_alias = '' ) {
2134
-		return isset( $this->_tables[ $table_alias ] ) ? $this->_tables[ $table_alias ] : NULL;
2133
+	public function get_table_obj_by_alias($table_alias = '') {
2134
+		return isset($this->_tables[$table_alias]) ? $this->_tables[$table_alias] : NULL;
2135 2135
 	}
2136 2136
 
2137 2137
 
@@ -2140,10 +2140,10 @@  discard block
 block discarded – undo
2140 2140
 	 * Gets all the tables of type EE_Other_Table from EEM_CPT_Basel_Model::_tables
2141 2141
 	 * @return EE_Secondary_Table[]
2142 2142
 	 */
2143
-	protected function _get_other_tables(){
2144
-		$other_tables =array();
2145
-		foreach($this->_tables as $table_alias => $table){
2146
-			if($table instanceof EE_Secondary_Table){
2143
+	protected function _get_other_tables() {
2144
+		$other_tables = array();
2145
+		foreach ($this->_tables as $table_alias => $table) {
2146
+			if ($table instanceof EE_Secondary_Table) {
2147 2147
 				$other_tables[$table_alias] = $table;
2148 2148
 			}
2149 2149
 		}
@@ -2155,7 +2155,7 @@  discard block
 block discarded – undo
2155 2155
 	 * @param string $table_alias, array key in EEM_Base::_tables
2156 2156
 	 * @return EE_Model_Field_Base[]
2157 2157
 	 */
2158
-	function _get_fields_for_table($table_alias){
2158
+	function _get_fields_for_table($table_alias) {
2159 2159
 		return $this->_fields[$table_alias];
2160 2160
 	}
2161 2161
 
@@ -2167,29 +2167,29 @@  discard block
 block discarded – undo
2167 2167
 	 * @param array $query_params like EEM_Base::get_all's $query_parameters['where']
2168 2168
 	 * @return EE_Model_Query_Info_Carrier
2169 2169
 	 */
2170
-	function _extract_related_models_from_query($query_params){
2170
+	function _extract_related_models_from_query($query_params) {
2171 2171
 		$query_info_carrier = new EE_Model_Query_Info_Carrier();
2172
-		if(array_key_exists(0,$query_params)){
2173
-			$this->_extract_related_models_from_sub_params_array_keys($query_params[0], $query_info_carrier,0);
2174
-		}
2175
-		if(array_key_exists('group_by', $query_params)){
2176
-			if(is_array($query_params['group_by'])){
2177
-				$this->_extract_related_models_from_sub_params_array_values($query_params['group_by'],$query_info_carrier,'group_by');
2178
-			}elseif( ! empty ( $query_params['group_by'] )){
2179
-				$this->_extract_related_model_info_from_query_param( $query_params['group_by'],$query_info_carrier,'group_by');
2172
+		if (array_key_exists(0, $query_params)) {
2173
+			$this->_extract_related_models_from_sub_params_array_keys($query_params[0], $query_info_carrier, 0);
2174
+		}
2175
+		if (array_key_exists('group_by', $query_params)) {
2176
+			if (is_array($query_params['group_by'])) {
2177
+				$this->_extract_related_models_from_sub_params_array_values($query_params['group_by'], $query_info_carrier, 'group_by');
2178
+			}elseif ( ! empty ($query_params['group_by'])) {
2179
+				$this->_extract_related_model_info_from_query_param($query_params['group_by'], $query_info_carrier, 'group_by');
2180 2180
 			}
2181 2181
 		}
2182
-		if(array_key_exists('having',$query_params)){
2183
-			$this->_extract_related_models_from_sub_params_array_keys($query_params[0], $query_info_carrier,'having');
2182
+		if (array_key_exists('having', $query_params)) {
2183
+			$this->_extract_related_models_from_sub_params_array_keys($query_params[0], $query_info_carrier, 'having');
2184 2184
 		}
2185
-		if(array_key_exists('order_by', $query_params)){
2186
-			if ( is_array( $query_params['order_by'] ) )
2187
-				$this->_extract_related_models_from_sub_params_array_keys($query_params['order_by'],$query_info_carrier,'order_by');
2188
-			elseif( ! empty( $query_params['order_by'] ))
2189
-				$this->_extract_related_model_info_from_query_param( $query_params['order_by'], $query_info_carrier,'order_by');
2185
+		if (array_key_exists('order_by', $query_params)) {
2186
+			if (is_array($query_params['order_by']))
2187
+				$this->_extract_related_models_from_sub_params_array_keys($query_params['order_by'], $query_info_carrier, 'order_by');
2188
+			elseif ( ! empty($query_params['order_by']))
2189
+				$this->_extract_related_model_info_from_query_param($query_params['order_by'], $query_info_carrier, 'order_by');
2190 2190
 		}
2191
-		if(array_key_exists('force_join', $query_params)){
2192
-			$this->_extract_related_models_from_sub_params_array_values($query_params['force_join'],$query_info_carrier,'force_join');
2191
+		if (array_key_exists('force_join', $query_params)) {
2192
+			$this->_extract_related_models_from_sub_params_array_values($query_params['force_join'], $query_info_carrier, 'force_join');
2193 2193
 		}
2194 2194
 		return $query_info_carrier;
2195 2195
 	}
@@ -2202,34 +2202,34 @@  discard block
 block discarded – undo
2202 2202
 	 * @throws EE_Error
2203 2203
 	 * @return \EE_Model_Query_Info_Carrier
2204 2204
 	 */
2205
-	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){
2206
-		if (!empty($sub_query_params)){
2205
+	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) {
2206
+		if ( ! empty($sub_query_params)) {
2207 2207
 			$sub_query_params = (array) $sub_query_params;
2208
-			foreach($sub_query_params as $param => $possibly_array_of_params){
2208
+			foreach ($sub_query_params as $param => $possibly_array_of_params) {
2209 2209
 				//$param could be simply 'EVT_ID', or it could be 'Registrations.REG_ID', or even 'Registrations.Transactions.Payments.PAY_amount'
2210
-				$this->_extract_related_model_info_from_query_param( $param, $model_query_info_carrier,$query_param_type);
2210
+				$this->_extract_related_model_info_from_query_param($param, $model_query_info_carrier, $query_param_type);
2211 2211
 
2212 2212
 				//if $possibly_array_of_params is an array, try recursing into it, searching for keys which
2213 2213
 				//indicate needed joins. Eg, array('NOT'=>array('Registration.TXN_ID'=>23)). In this case, we tried
2214 2214
 				//extracting models out of the 'NOT', which obviously wasn't successful, and then we recurse into the value
2215 2215
 				//of array('Registration.TXN_ID'=>23)
2216 2216
 				$query_param_sans_stars = $this->_remove_stars_and_anything_after_from_condition_query_param_key($param);
2217
-				if(in_array($query_param_sans_stars, $this->_logic_query_param_keys,true)){
2218
-					if (! is_array($possibly_array_of_params)){
2217
+				if (in_array($query_param_sans_stars, $this->_logic_query_param_keys, true)) {
2218
+					if ( ! is_array($possibly_array_of_params)) {
2219 2219
 						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"),
2220
-							$param,$possibly_array_of_params));
2221
-					}else{
2222
-						$this->_extract_related_models_from_sub_params_array_keys($possibly_array_of_params, $model_query_info_carrier,$query_param_type);
2220
+							$param, $possibly_array_of_params));
2221
+					} else {
2222
+						$this->_extract_related_models_from_sub_params_array_keys($possibly_array_of_params, $model_query_info_carrier, $query_param_type);
2223 2223
 					}
2224
-				}elseif($query_param_type === 0 //ie WHERE
2224
+				}elseif ($query_param_type === 0 //ie WHERE
2225 2225
 						&& is_array($possibly_array_of_params)
2226 2226
 						&& isset($possibly_array_of_params[2])
2227
-						&& $possibly_array_of_params[2] == true){
2227
+						&& $possibly_array_of_params[2] == true) {
2228 2228
 					//then $possible_array_of_params looks something like array('<','DTT_sold',true)
2229 2229
 					//indicating that $possible_array_of_params[1] is actually a field name,
2230 2230
 					//from which we should extract query parameters!
2231
-					if(! isset($possibly_array_of_params[0]) || ! isset($possibly_array_of_params[1])){
2232
-						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)));
2231
+					if ( ! isset($possibly_array_of_params[0]) || ! isset($possibly_array_of_params[1])) {
2232
+						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)));
2233 2233
 					}
2234 2234
 					$this->_extract_related_model_info_from_query_param($possibly_array_of_params[1], $model_query_info_carrier, $query_param_type);
2235 2235
 				}
@@ -2248,14 +2248,14 @@  discard block
 block discarded – undo
2248 2248
 	 * @throws EE_Error
2249 2249
 	 * @return \EE_Model_Query_Info_Carrier
2250 2250
 	 */
2251
-	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){
2252
-		if (!empty($sub_query_params)){
2253
-			if(!is_array($sub_query_params)){
2254
-				throw new EE_Error(sprintf(__("Query parameter %s should be an array, but it isn't.", "event_espresso"),$sub_query_params));
2251
+	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) {
2252
+		if ( ! empty($sub_query_params)) {
2253
+			if ( ! is_array($sub_query_params)) {
2254
+				throw new EE_Error(sprintf(__("Query parameter %s should be an array, but it isn't.", "event_espresso"), $sub_query_params));
2255 2255
 			}
2256
-			foreach($sub_query_params as $param){
2256
+			foreach ($sub_query_params as $param) {
2257 2257
 				//$param could be simply 'EVT_ID', or it could be 'Registrations.REG_ID', or even 'Registrations.Transactions.Payments.PAY_amount'
2258
-				$this->_extract_related_model_info_from_query_param( $param, $model_query_info_carrier, $query_param_type);
2258
+				$this->_extract_related_model_info_from_query_param($param, $model_query_info_carrier, $query_param_type);
2259 2259
 			}
2260 2260
 		}
2261 2261
 		return $model_query_info_carrier;
@@ -2274,81 +2274,81 @@  discard block
 block discarded – undo
2274 2274
 	 * @throws EE_Error
2275 2275
 	 * @return EE_Model_Query_Info_Carrier
2276 2276
 	 */
2277
-	function _create_model_query_info_carrier($query_params){
2278
-		if( isset( $query_params[0] ) ) {
2277
+	function _create_model_query_info_carrier($query_params) {
2278
+		if (isset($query_params[0])) {
2279 2279
 			$where_query_params = $query_params[0];
2280
-		}else{
2280
+		} else {
2281 2281
 			$where_query_params = array();
2282 2282
 		}
2283 2283
 		//first check if we should alter the query to account for caps or not
2284 2284
 		//because the caps might require us to do extra joins
2285
-		if( isset( $query_params[ 'caps' ] ) && $query_params[ 'caps' ] != 'none' ) {
2286
-			$query_params[0] = $where_query_params = array_replace_recursive( $where_query_params, $this->caps_where_conditions( $query_params[ 'caps' ] ) );
2285
+		if (isset($query_params['caps']) && $query_params['caps'] != 'none') {
2286
+			$query_params[0] = $where_query_params = array_replace_recursive($where_query_params, $this->caps_where_conditions($query_params['caps']));
2287 2287
 		}
2288
-		if( ! is_array( $query_params ) ){
2289
-			EE_Error::doing_it_wrong('EEM_Base::_create_model_query_info_carrier', sprintf( __( '$query_params should be an array, you passed a variable of type %s', 'event_espresso' ), gettype( $query_params ) ), '4.6.0' );
2288
+		if ( ! is_array($query_params)) {
2289
+			EE_Error::doing_it_wrong('EEM_Base::_create_model_query_info_carrier', sprintf(__('$query_params should be an array, you passed a variable of type %s', 'event_espresso'), gettype($query_params)), '4.6.0');
2290 2290
 			$query_params = array();
2291 2291
 		}
2292 2292
 		$query_object = $this->_extract_related_models_from_query($query_params);
2293 2293
 
2294 2294
 		//verify where_query_params has NO numeric indexes.... that's simply not how you use it!
2295
-		foreach($where_query_params as $key => $value){
2296
-			if(is_int($key)){
2297
-				throw new EE_Error(sprintf(__("WHERE query params must NOT be numerically-indexed. You provided the array key '%s' for value '%s' while querying model %s. All the query params provided were '%s' Please read documentation on EEM_Base::get_all.", "event_espresso"),$key, var_export( $value, true ), var_export( $query_params, true ), get_class($this)));
2295
+		foreach ($where_query_params as $key => $value) {
2296
+			if (is_int($key)) {
2297
+				throw new EE_Error(sprintf(__("WHERE query params must NOT be numerically-indexed. You provided the array key '%s' for value '%s' while querying model %s. All the query params provided were '%s' Please read documentation on EEM_Base::get_all.", "event_espresso"), $key, var_export($value, true), var_export($query_params, true), get_class($this)));
2298 2298
 			}
2299 2299
 		}
2300
-		if( array_key_exists( 'default_where_conditions',$query_params) && ! empty( $query_params['default_where_conditions'] )){
2300
+		if (array_key_exists('default_where_conditions', $query_params) && ! empty($query_params['default_where_conditions'])) {
2301 2301
 			$use_default_where_conditions = $query_params['default_where_conditions'];
2302
-		}else{
2302
+		} else {
2303 2303
 			$use_default_where_conditions = 'all';
2304 2304
 		}
2305
-		$where_query_params = array_merge($this->_get_default_where_conditions_for_models_in_query($query_object,$use_default_where_conditions,$where_query_params), $where_query_params );
2306
-		$query_object->set_where_sql( $this->_construct_where_clause($where_query_params));
2305
+		$where_query_params = array_merge($this->_get_default_where_conditions_for_models_in_query($query_object, $use_default_where_conditions, $where_query_params), $where_query_params);
2306
+		$query_object->set_where_sql($this->_construct_where_clause($where_query_params));
2307 2307
 
2308 2308
 
2309 2309
 		//if this is a "on_join_limit" then we are limiting on on a specific table in a multi_table join.  So we need to setup a subquery and use that for the main join.  Note for now this only works on the primary table for the model.  So for instance, you could set the limit array like this:
2310 2310
 		//array( 'on_join_limit' => array('Primary_Table_Alias', array(1,10) ) )
2311
-		if ( array_key_exists('on_join_limit', $query_params ) && ! empty( $query_params['on_join_limit'] )) {
2312
-			$query_object->set_main_model_join_sql( $this->_construct_limit_join_select( $query_params['on_join_limit'][0], $query_params['on_join_limit'][1] ) );
2311
+		if (array_key_exists('on_join_limit', $query_params) && ! empty($query_params['on_join_limit'])) {
2312
+			$query_object->set_main_model_join_sql($this->_construct_limit_join_select($query_params['on_join_limit'][0], $query_params['on_join_limit'][1]));
2313 2313
 		}
2314 2314
 
2315 2315
 
2316 2316
 		//set limit
2317
-		if(array_key_exists('limit',$query_params)){
2318
-			if(is_array($query_params['limit'])){
2319
-				if( ! isset($query_params['limit'][0]) || ! isset($query_params['limit'][1])){
2320
-					$e = sprintf(__("Invalid DB query. You passed '%s' for the LIMIT, but only the following are valid: an integer, string representing an integer, a string like 'int,int', or an array like array(int,int)", "event_espresso"),  http_build_query($query_params['limit']));
2317
+		if (array_key_exists('limit', $query_params)) {
2318
+			if (is_array($query_params['limit'])) {
2319
+				if ( ! isset($query_params['limit'][0]) || ! isset($query_params['limit'][1])) {
2320
+					$e = sprintf(__("Invalid DB query. You passed '%s' for the LIMIT, but only the following are valid: an integer, string representing an integer, a string like 'int,int', or an array like array(int,int)", "event_espresso"), http_build_query($query_params['limit']));
2321 2321
 					throw new EE_Error($e."|".$e);
2322 2322
 				}
2323 2323
 				//they passed us an array for the limit. Assume it's like array(50,25), meaning offset by 50, and get 25
2324 2324
 				$query_object->set_limit_sql(" LIMIT ".$query_params['limit'][0].",".$query_params['limit'][1]);
2325
-			}elseif( ! empty ( $query_params['limit'] )){
2325
+			}elseif ( ! empty ($query_params['limit'])) {
2326 2326
 				$query_object->set_limit_sql((" LIMIT ".$query_params['limit']));
2327 2327
 			}
2328 2328
 		}
2329 2329
 		//set order by
2330
-		if(array_key_exists('order_by',$query_params)){
2331
-			if(is_array($query_params['order_by'])){
2330
+		if (array_key_exists('order_by', $query_params)) {
2331
+			if (is_array($query_params['order_by'])) {
2332 2332
 				//if they're using 'order_by' as an array, they can't use 'order' (because 'order_by' must
2333 2333
 				//specify whether to ascend or descend on each field. Eg 'order_by'=>array('EVT_ID'=>'ASC'). So
2334 2334
 				//including 'order' wouldn't make any sense if 'order_by' has already specified which way to order!
2335
-				if(array_key_exists('order', $query_params)){
2335
+				if (array_key_exists('order', $query_params)) {
2336 2336
 					throw new EE_Error(sprintf(__("In querying %s, we are using query parameter 'order_by' as an array (keys:%s,values:%s), and so we can't use query parameter 'order' (value %s). You should just use the 'order_by' parameter ", "event_espresso"),
2337
-							get_class($this),implode(", ",array_keys($query_params['order_by'])),implode(", ",$query_params['order_by']),$query_params['order']));
2337
+							get_class($this), implode(", ", array_keys($query_params['order_by'])), implode(", ", $query_params['order_by']), $query_params['order']));
2338 2338
 				}
2339
-				 $this->_extract_related_models_from_sub_params_array_keys($query_params['order_by'],$query_object,'order_by');
2339
+				 $this->_extract_related_models_from_sub_params_array_keys($query_params['order_by'], $query_object, 'order_by');
2340 2340
 				//assume it's an array of fields to order by
2341 2341
 				$order_array = array();
2342
-				foreach($query_params['order_by'] as $field_name_to_order_by => $order){
2342
+				foreach ($query_params['order_by'] as $field_name_to_order_by => $order) {
2343 2343
 					$order = $this->_extract_order($order);
2344 2344
 					$order_array[] = $this->_deduce_column_name_from_query_param($field_name_to_order_by).SP.$order;
2345 2345
 				}
2346
-				$query_object->set_order_by_sql(" ORDER BY ".implode(",",$order_array));
2347
-			}elseif( ! empty ( $query_params['order_by'] )){
2348
-				$this->_extract_related_model_info_from_query_param($query_params['order_by'],$query_object,'order',$query_params['order_by']);
2349
-				if(isset($query_params['order'])){
2346
+				$query_object->set_order_by_sql(" ORDER BY ".implode(",", $order_array));
2347
+			}elseif ( ! empty ($query_params['order_by'])) {
2348
+				$this->_extract_related_model_info_from_query_param($query_params['order_by'], $query_object, 'order', $query_params['order_by']);
2349
+				if (isset($query_params['order'])) {
2350 2350
 					$order = $this->_extract_order($query_params['order']);
2351
-				}else{
2351
+				} else {
2352 2352
 					$order = 'DESC';
2353 2353
 				}
2354 2354
 				$query_object->set_order_by_sql(" ORDER BY ".$this->_deduce_column_name_from_query_param($query_params['order_by']).SP.$order);
@@ -2356,46 +2356,46 @@  discard block
 block discarded – undo
2356 2356
 		}
2357 2357
 
2358 2358
 		//if 'order_by' wasn't set, maybe they are just using 'order' on its own?
2359
-		if( ! array_key_exists('order_by',$query_params) && array_key_exists('order',$query_params) && ! empty( $query_params['order'] )){
2359
+		if ( ! array_key_exists('order_by', $query_params) && array_key_exists('order', $query_params) && ! empty($query_params['order'])) {
2360 2360
 			$pk_field = $this->get_primary_key_field();
2361 2361
 			$order = $this->_extract_order($query_params['order']);
2362 2362
 			$query_object->set_order_by_sql(" ORDER BY ".$pk_field->get_qualified_column().SP.$order);
2363 2363
 		}
2364 2364
 
2365 2365
 		//set group by
2366
-		if(array_key_exists('group_by',$query_params)){
2367
-			if(is_array($query_params['group_by'])){
2366
+		if (array_key_exists('group_by', $query_params)) {
2367
+			if (is_array($query_params['group_by'])) {
2368 2368
 				//it's an array, so assume we'll be grouping by a bunch of stuff
2369 2369
 				$group_by_array = array();
2370
-				foreach($query_params['group_by'] as $field_name_to_group_by){
2370
+				foreach ($query_params['group_by'] as $field_name_to_group_by) {
2371 2371
 					$group_by_array[] = $this->_deduce_column_name_from_query_param($field_name_to_group_by);
2372 2372
 				}
2373
-				$query_object->set_group_by_sql(" GROUP BY ".implode(", ",$group_by_array));
2374
-			}elseif( ! empty ( $query_params['group_by'] )){
2373
+				$query_object->set_group_by_sql(" GROUP BY ".implode(", ", $group_by_array));
2374
+			}elseif ( ! empty ($query_params['group_by'])) {
2375 2375
 				$query_object->set_group_by_sql(" GROUP BY ".$this->_deduce_column_name_from_query_param($query_params['group_by']));
2376 2376
 			}
2377 2377
 		}
2378 2378
 		//set having
2379
-		if(array_key_exists('having',$query_params) && $query_params['having']){
2380
-			$query_object->set_having_sql( $this->_construct_having_clause($query_params['having']));
2379
+		if (array_key_exists('having', $query_params) && $query_params['having']) {
2380
+			$query_object->set_having_sql($this->_construct_having_clause($query_params['having']));
2381 2381
 		}
2382 2382
 
2383 2383
 		//now, just verify they didn't pass anything wack
2384
-		foreach($query_params as $query_key => $query_value){
2385
-			if( ! in_array($query_key,$this->_allowed_query_params,true)){
2384
+		foreach ($query_params as $query_key => $query_value) {
2385
+			if ( ! in_array($query_key, $this->_allowed_query_params, true)) {
2386 2386
 				throw new EE_Error(
2387 2387
 					sprintf(
2388
-						__("You passed %s as a query parameter to %s, which is illegal! The allowed query parameters are %s",'event_espresso'),
2388
+						__("You passed %s as a query parameter to %s, which is illegal! The allowed query parameters are %s", 'event_espresso'),
2389 2389
 						$query_key,
2390 2390
 						get_class($this),
2391 2391
 //						print_r( $this->_allowed_query_params, TRUE )
2392
-						implode( ',', $this->_allowed_query_params )
2392
+						implode(',', $this->_allowed_query_params)
2393 2393
 					)
2394 2394
 				);
2395 2395
 			}
2396 2396
 		}
2397 2397
 		$main_model_join_sql = $query_object->get_main_model_join_sql();
2398
-		if ( empty( $main_model_join_sql ) )
2398
+		if (empty($main_model_join_sql))
2399 2399
 			$query_object->set_main_model_join_sql($this->_construct_internal_join());
2400 2400
 		return $query_object;
2401 2401
 	}
@@ -2406,17 +2406,17 @@  discard block
 block discarded – undo
2406 2406
 	 * @param string $context one of EEM_Base::valid_cap_contexts()
2407 2407
 	 * @return array like EEM_Base::get_all() 's $query_params[0]
2408 2408
 	 */
2409
-	public function caps_where_conditions( $context = self::caps_read ) {
2410
-		EEM_Base::verify_is_valid_cap_context( $context );
2409
+	public function caps_where_conditions($context = self::caps_read) {
2410
+		EEM_Base::verify_is_valid_cap_context($context);
2411 2411
 		$cap_where_conditions = array();
2412
-		$cap_restrictions = $this->caps_missing( $context );
2412
+		$cap_restrictions = $this->caps_missing($context);
2413 2413
 		/**
2414 2414
 		 * @var $cap_restrictions EE_Default_Where_Conditions[]
2415 2415
 		 */
2416
-		foreach( $cap_restrictions as $cap => $restriction_if_no_cap ) {
2417
-				$cap_where_conditions = array_replace_recursive( $cap_where_conditions, $restriction_if_no_cap->get_default_where_conditions() );
2416
+		foreach ($cap_restrictions as $cap => $restriction_if_no_cap) {
2417
+				$cap_where_conditions = array_replace_recursive($cap_where_conditions, $restriction_if_no_cap->get_default_where_conditions());
2418 2418
 		}
2419
-		return apply_filters( 'FHEE__EEM_Base__caps_where_conditions__return', $cap_where_conditions, $this, $context, $cap_restrictions );
2419
+		return apply_filters('FHEE__EEM_Base__caps_where_conditions__return', $cap_where_conditions, $this, $context, $cap_restrictions);
2420 2420
 	}
2421 2421
 
2422 2422
 	/**
@@ -2426,11 +2426,11 @@  discard block
 block discarded – undo
2426 2426
 	 * @return string either ASC, asc, DESC or desc
2427 2427
 	 * @throws EE_Error
2428 2428
 	 */
2429
-	private function _extract_order($should_be_order_string){
2430
-		if(in_array($should_be_order_string, $this->_allowed_order_values)){
2429
+	private function _extract_order($should_be_order_string) {
2430
+		if (in_array($should_be_order_string, $this->_allowed_order_values)) {
2431 2431
 			return $should_be_order_string;
2432
-		}else{
2433
-			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));
2432
+		} else {
2433
+			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));
2434 2434
 		}
2435 2435
 	}
2436 2436
 
@@ -2448,19 +2448,19 @@  discard block
 block discarded – undo
2448 2448
 	 * @throws EE_Error
2449 2449
 	 * @return array like $query_params[0], see EEM_Base::get_all for documentation
2450 2450
 	 */
2451
-	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()){
2452
-		$allowed_used_default_where_conditions_values = array('all','this_model_only', 'other_models_only','none');
2453
-		if( ! in_array($use_default_where_conditions,$allowed_used_default_where_conditions_values)){
2454
-			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)));
2451
+	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()) {
2452
+		$allowed_used_default_where_conditions_values = array('all', 'this_model_only', 'other_models_only', 'none');
2453
+		if ( ! in_array($use_default_where_conditions, $allowed_used_default_where_conditions_values)) {
2454
+			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)));
2455 2455
 		}
2456
-		if( in_array($use_default_where_conditions, array('all','this_model_only')) ){
2456
+		if (in_array($use_default_where_conditions, array('all', 'this_model_only'))) {
2457 2457
 			$universal_query_params = $this->_get_default_where_conditions();
2458
-		}else{
2458
+		} else {
2459 2459
 			$universal_query_params = array();
2460 2460
 		}
2461 2461
 
2462
-		if(in_array($use_default_where_conditions,array('all','other_models_only'))){
2463
-			foreach($query_info_carrier->get_model_names_included() as $model_relation_path => $model_name){
2462
+		if (in_array($use_default_where_conditions, array('all', 'other_models_only'))) {
2463
+			foreach ($query_info_carrier->get_model_names_included() as $model_relation_path => $model_name) {
2464 2464
 				$related_model = $this->get_related_model_obj($model_name);
2465 2465
 				$related_model_universal_where_params = $related_model->_get_default_where_conditions($model_relation_path);
2466 2466
 
@@ -2487,22 +2487,22 @@  discard block
 block discarded – undo
2487 2487
 	 * @param string $model_relation_path like 'Transaction.Payment.'
2488 2488
 	 * @return array like EEM_Base::get_all's $query_params[0]
2489 2489
 	 */
2490
-	private function _override_defaults_or_make_null_friendly($default_where_conditions,$provided_where_conditions,$model,$model_relation_path){
2490
+	private function _override_defaults_or_make_null_friendly($default_where_conditions, $provided_where_conditions, $model, $model_relation_path) {
2491 2491
 		$null_friendly_where_conditions = array();
2492 2492
 		$none_overridden = true;
2493 2493
 		$or_condition_key_for_defaults = 'OR*'.get_class($model);
2494 2494
 
2495
-		foreach($default_where_conditions as $key => $val){
2496
-			if( isset($provided_where_conditions[$key])){
2495
+		foreach ($default_where_conditions as $key => $val) {
2496
+			if (isset($provided_where_conditions[$key])) {
2497 2497
 				$none_overridden = false;
2498
-			}else{
2498
+			} else {
2499 2499
 				$null_friendly_where_conditions[$or_condition_key_for_defaults]['AND'][$key] = $val;
2500 2500
 			}
2501 2501
 		}
2502
-		if( $none_overridden && $default_where_conditions){
2503
-			if($model->has_primary_key_field()){
2502
+		if ($none_overridden && $default_where_conditions) {
2503
+			if ($model->has_primary_key_field()) {
2504 2504
 				$null_friendly_where_conditions[$or_condition_key_for_defaults][$model_relation_path.".".$model->primary_key_name()] = array('IS NULL');
2505
-			}else{
2505
+			} else {
2506 2506
 				//@todo NO PK, use other defaults
2507 2507
 			}
2508 2508
 		}
@@ -2517,8 +2517,8 @@  discard block
 block discarded – undo
2517 2517
 	 * @param string $model_relation_path eg, path from Event to Payment is "Registration.Transaction.Payment."
2518 2518
 	 * @return array like EEM_Base::get_all's $query_params[0] (where conditions)
2519 2519
 	 */
2520
-	private function _get_default_where_conditions($model_relation_path = null){
2521
-		if ( $this->_ignore_where_strategy )
2520
+	private function _get_default_where_conditions($model_relation_path = null) {
2521
+		if ($this->_ignore_where_strategy)
2522 2522
 			return array();
2523 2523
 
2524 2524
 		return $this->_default_where_conditions_strategy->get_default_where_conditions($model_relation_path);
@@ -2529,13 +2529,13 @@  discard block
 block discarded – undo
2529 2529
 	 * @param EE_Model_Query_Info_Carrier $model_query_info
2530 2530
 	 * @return string
2531 2531
 	 */
2532
-	private function _construct_default_select_sql(EE_Model_Query_Info_Carrier $model_query_info){
2532
+	private function _construct_default_select_sql(EE_Model_Query_Info_Carrier $model_query_info) {
2533 2533
 		$selects = $this->_get_columns_to_select_for_this_model();
2534
-		foreach($model_query_info->get_model_names_included() as $model_relation_chain => $name_of_other_model_included){
2534
+		foreach ($model_query_info->get_model_names_included() as $model_relation_chain => $name_of_other_model_included) {
2535 2535
 			$other_model_included = $this->get_related_model_obj($name_of_other_model_included);
2536 2536
 			$selects = array_merge($selects, $other_model_included->_get_columns_to_select_for_this_model($model_relation_chain));
2537 2537
 		}
2538
-		return implode(", ",$selects);
2538
+		return implode(", ", $selects);
2539 2539
 	}
2540 2540
 
2541 2541
 	/**
@@ -2544,19 +2544,19 @@  discard block
 block discarded – undo
2544 2544
 	 * @param string $model_relation_chain like 'Question.Question_Group.Event'
2545 2545
 	 * @return array numerically indexed, values are columns to select and rename, eg "Event.ID AS 'Event.ID'"
2546 2546
 	 */
2547
-	public function _get_columns_to_select_for_this_model($model_relation_chain = ''){
2547
+	public function _get_columns_to_select_for_this_model($model_relation_chain = '') {
2548 2548
 		$fields = $this->field_settings();
2549 2549
 		$selects = array();
2550 2550
 		$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());
2551
-		foreach($fields as $field_obj){
2552
-			$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()."'";
2551
+		foreach ($fields as $field_obj) {
2552
+			$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()."'";
2553 2553
 		}
2554 2554
 		//make sure we are also getting the PKs of each table
2555 2555
 		$tables = $this->get_tables();
2556
-		if(count($tables) > 1){
2557
-			foreach($tables as $table_obj){
2558
-				$qualified_pk_column = $table_alias_with_model_relation_chain_prefix . $table_obj->get_fully_qualified_pk_column();
2559
-				if( ! in_array($qualified_pk_column,$selects)){
2556
+		if (count($tables) > 1) {
2557
+			foreach ($tables as $table_obj) {
2558
+				$qualified_pk_column = $table_alias_with_model_relation_chain_prefix.$table_obj->get_fully_qualified_pk_column();
2559
+				if ( ! in_array($qualified_pk_column, $selects)) {
2560 2560
 					$selects[] = "$qualified_pk_column AS '$qualified_pk_column'";
2561 2561
 				}
2562 2562
 			}
@@ -2580,65 +2580,65 @@  discard block
 block discarded – undo
2580 2580
 	 * @throws EE_Error
2581 2581
 	 * @return void only modifies the EEM_Related_Model_Info_Carrier passed into it
2582 2582
 	 */
2583
-	private function _extract_related_model_info_from_query_param( $query_param, EE_Model_Query_Info_Carrier $passed_in_query_info, $query_param_type, $original_query_param = NULL ){
2584
-		if($original_query_param == NULL){
2583
+	private function _extract_related_model_info_from_query_param($query_param, EE_Model_Query_Info_Carrier $passed_in_query_info, $query_param_type, $original_query_param = NULL) {
2584
+		if ($original_query_param == NULL) {
2585 2585
 			$original_query_param = $query_param;
2586 2586
 		}
2587 2587
 		$query_param = $this->_remove_stars_and_anything_after_from_condition_query_param_key($query_param);
2588 2588
 		/** @var $allow_logic_query_params bool whether or not to allow logic_query_params like 'NOT','OR', or 'AND' */
2589
-		$allow_logic_query_params = in_array($query_param_type,array('where','having'));
2590
-		$allow_fields = in_array($query_param_type,array('where','having','order_by','group_by','order'));
2589
+		$allow_logic_query_params = in_array($query_param_type, array('where', 'having'));
2590
+		$allow_fields = in_array($query_param_type, array('where', 'having', 'order_by', 'group_by', 'order'));
2591 2591
 		//check to see if we have a field on this model
2592 2592
 		$this_model_fields = $this->field_settings(true);
2593
-		if(array_key_exists($query_param,$this_model_fields)){
2594
-			if($allow_fields){
2593
+		if (array_key_exists($query_param, $this_model_fields)) {
2594
+			if ($allow_fields) {
2595 2595
 				return;
2596
-			}else{
2596
+			} else {
2597 2597
 				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"),
2598
-						$query_param,get_class($this),$query_param_type,$original_query_param));
2598
+						$query_param, get_class($this), $query_param_type, $original_query_param));
2599 2599
 			}
2600 2600
 		}
2601 2601
 		//check if this is a special logic query param
2602
-		elseif(in_array($query_param, $this->_logic_query_param_keys, TRUE)){
2603
-			if($allow_logic_query_params){
2602
+		elseif (in_array($query_param, $this->_logic_query_param_keys, TRUE)) {
2603
+			if ($allow_logic_query_params) {
2604 2604
 				return;
2605
-			}else{
2605
+			} else {
2606 2606
 				throw new EE_Error(
2607 2607
 					sprintf(
2608
-						__( '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' ),
2609
-						implode( '", "', $this->_logic_query_param_keys ),
2610
-						$query_param ,
2611
-						get_class( $this ),
2608
+						__('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'),
2609
+						implode('", "', $this->_logic_query_param_keys),
2610
+						$query_param,
2611
+						get_class($this),
2612 2612
 						'<br />',
2613
-						"\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
2613
+						"\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
2614 2614
 					)
2615 2615
 				);
2616 2616
 			}
2617 2617
 		}
2618 2618
 		//check if it's a custom selection
2619
-		elseif(array_key_exists($query_param,$this->_custom_selections)){
2619
+		elseif (array_key_exists($query_param, $this->_custom_selections)) {
2620 2620
 			return;
2621 2621
 		}
2622 2622
 
2623 2623
 		//check if has a model name at the beginning
2624 2624
 		//and
2625 2625
 		//check if it's a field on a related model
2626
-		foreach($this->_model_relations as $valid_related_model_name=>$relation_obj){
2627
-			if(strpos($query_param, $valid_related_model_name.".") === 0){
2628
-				$this->_add_join_to_model($valid_related_model_name, $passed_in_query_info,$original_query_param);
2626
+		foreach ($this->_model_relations as $valid_related_model_name=>$relation_obj) {
2627
+			if (strpos($query_param, $valid_related_model_name.".") === 0) {
2628
+				$this->_add_join_to_model($valid_related_model_name, $passed_in_query_info, $original_query_param);
2629 2629
 				$query_param = substr($query_param, strlen($valid_related_model_name."."));
2630
-				if($query_param == ''){
2630
+				if ($query_param == '') {
2631 2631
 					//nothing left to $query_param
2632 2632
 					//we should actually end in a field name, not a model like this!
2633 2633
 					throw new EE_Error(sprintf(__("Query param '%s' (of type %s on model %s) shouldn't end on a period (.) ", "event_espresso"),
2634
-					$query_param,$query_param_type,get_class($this),$valid_related_model_name));
2635
-				}else{
2634
+					$query_param, $query_param_type, get_class($this), $valid_related_model_name));
2635
+				} else {
2636 2636
 					$related_model_obj = $this->get_related_model_obj($valid_related_model_name);
2637 2637
 					$related_model_obj->_extract_related_model_info_from_query_param($query_param, $passed_in_query_info, $query_param_type, $original_query_param);
2638 2638
 					return;
2639 2639
 				}
2640
-			}elseif($query_param == $valid_related_model_name){
2641
-				$this->_add_join_to_model($valid_related_model_name, $passed_in_query_info,$original_query_param);
2640
+			}elseif ($query_param == $valid_related_model_name) {
2641
+				$this->_add_join_to_model($valid_related_model_name, $passed_in_query_info, $original_query_param);
2642 2642
 				return;
2643 2643
 			}
2644 2644
 		}
@@ -2648,7 +2648,7 @@  discard block
 block discarded – undo
2648 2648
 		//and we previously confirmed it wasn't a logic query param or field on the current model
2649 2649
 		//it's wack, that's what it is
2650 2650
 		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"),
2651
-				$query_param,get_class($this),$query_param_type,$original_query_param));
2651
+				$query_param, get_class($this), $query_param_type, $original_query_param));
2652 2652
 
2653 2653
 	}
2654 2654
 
@@ -2665,26 +2665,26 @@  discard block
 block discarded – undo
2665 2665
 	 * what models to prepend onto its default query params or in case it wants to rename tables (in case there are multiple joins to the same table)
2666 2666
 	 * @return void
2667 2667
 	 */
2668
-	private function _add_join_to_model($model_name, EE_Model_Query_Info_Carrier $passed_in_query_info,$original_query_param){
2668
+	private function _add_join_to_model($model_name, EE_Model_Query_Info_Carrier $passed_in_query_info, $original_query_param) {
2669 2669
 		$relation_obj = $this->related_settings_for($model_name);
2670 2670
 
2671 2671
 		$model_relation_chain = EE_Model_Parser::extract_model_relation_chain($model_name, $original_query_param);
2672 2672
 		//check if the relation is HABTM, because then we're essentially doing two joins
2673 2673
 		//If so, join first to the JOIN table, and add its data types, and then continue as normal
2674
-		if($relation_obj instanceof EE_HABTM_Relation){
2674
+		if ($relation_obj instanceof EE_HABTM_Relation) {
2675 2675
 			$join_model_obj = $relation_obj->get_join_model();
2676 2676
 			//replace the model specified with the join model for this relation chain, whi
2677 2677
 			$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);
2678 2678
 			$new_query_info = new EE_Model_Query_Info_Carrier(
2679 2679
 					array($relation_chain_to_join_model => $join_model_obj->get_this_model_name()),
2680 2680
 					$relation_obj->get_join_to_intermediate_model_statement($relation_chain_to_join_model));
2681
-			$passed_in_query_info->merge( $new_query_info  );
2681
+			$passed_in_query_info->merge($new_query_info);
2682 2682
 		}
2683 2683
 		//now just join to the other table pointed to by the relation object, and add its data types
2684 2684
 		$new_query_info = new EE_Model_Query_Info_Carrier(
2685 2685
 				array($model_relation_chain=>$model_name),
2686 2686
 				$relation_obj->get_join_statement($model_relation_chain));
2687
-		$passed_in_query_info->merge( $new_query_info  );
2687
+		$passed_in_query_info->merge($new_query_info);
2688 2688
 	}
2689 2689
 
2690 2690
 
@@ -2693,11 +2693,11 @@  discard block
 block discarded – undo
2693 2693
 	 * @param array $where_params like EEM_Base::get_all
2694 2694
 	 * @return string of SQL
2695 2695
 	 */
2696
-	private function _construct_where_clause($where_params){
2696
+	private function _construct_where_clause($where_params) {
2697 2697
 		$SQL = $this->_construct_condition_clause_recursive($where_params, ' AND ');
2698
-		if($SQL){
2699
-			return " WHERE ". $SQL;
2700
-		}else{
2698
+		if ($SQL) {
2699
+			return " WHERE ".$SQL;
2700
+		} else {
2701 2701
 			return '';
2702 2702
 		}
2703 2703
 	}
@@ -2708,11 +2708,11 @@  discard block
 block discarded – undo
2708 2708
 	 * @param array $having_params
2709 2709
 	 * @return string
2710 2710
 	 */
2711
-	private function _construct_having_clause($having_params){
2711
+	private function _construct_having_clause($having_params) {
2712 2712
 		$SQL = $this->_construct_condition_clause_recursive($having_params, ' AND ');
2713
-		if($SQL){
2714
-			return " HAVING ". $SQL;
2715
-		}else{
2713
+		if ($SQL) {
2714
+			return " HAVING ".$SQL;
2715
+		} else {
2716 2716
 			return '';
2717 2717
 		}
2718 2718
 
@@ -2726,17 +2726,17 @@  discard block
 block discarded – undo
2726 2726
 	 * @return EE_Model_Field_Base
2727 2727
 	 * @throws EE_Error
2728 2728
 	 */
2729
-	protected function _get_field_on_model($field_name,$model_name){
2729
+	protected function _get_field_on_model($field_name, $model_name) {
2730 2730
 		$model_class = 'EEM_'.$model_name;
2731 2731
 		$model_filepath = $model_class.".model.php";
2732
-		EE_Registry::instance()->load_helper( 'File' );
2733
-		if ( is_readable($model_filepath)){
2732
+		EE_Registry::instance()->load_helper('File');
2733
+		if (is_readable($model_filepath)) {
2734 2734
 			require_once($model_filepath);
2735
-			$model_instance=call_user_func($model_name."::instance");
2735
+			$model_instance = call_user_func($model_name."::instance");
2736 2736
 			/* @var $model_instance EEM_Base */
2737 2737
 			return $model_instance->field_settings_for($field_name);
2738
-		}else{
2739
-			throw new EE_Error(sprintf(__('No model named %s exists, with classname %s and filepath %s','event_espresso'),$model_name,$model_class,$model_filepath));
2738
+		} else {
2739
+			throw new EE_Error(sprintf(__('No model named %s exists, with classname %s and filepath %s', 'event_espresso'), $model_name, $model_class, $model_filepath));
2740 2740
 		}
2741 2741
 	}
2742 2742
 
@@ -2749,43 +2749,43 @@  discard block
 block discarded – undo
2749 2749
 	 * @throws EE_Error
2750 2750
 	 * @return string of SQL
2751 2751
 	 */
2752
-	private function _construct_condition_clause_recursive($where_params, $glue = ' AND'){
2753
-		$where_clauses=array();
2754
-		foreach($where_params as $query_param => $op_and_value_or_sub_condition){
2755
-			$query_param = $this->_remove_stars_and_anything_after_from_condition_query_param_key($query_param);//str_replace("*",'',$query_param);
2756
-			if(in_array($query_param,$this->_logic_query_param_keys)){
2757
-				switch($query_param){
2752
+	private function _construct_condition_clause_recursive($where_params, $glue = ' AND') {
2753
+		$where_clauses = array();
2754
+		foreach ($where_params as $query_param => $op_and_value_or_sub_condition) {
2755
+			$query_param = $this->_remove_stars_and_anything_after_from_condition_query_param_key($query_param); //str_replace("*",'',$query_param);
2756
+			if (in_array($query_param, $this->_logic_query_param_keys)) {
2757
+				switch ($query_param) {
2758 2758
 					case 'not':
2759 2759
 					case 'NOT':
2760
-						$where_clauses[] = "! (". $this->_construct_condition_clause_recursive($op_and_value_or_sub_condition, $glue).")";
2760
+						$where_clauses[] = "! (".$this->_construct_condition_clause_recursive($op_and_value_or_sub_condition, $glue).")";
2761 2761
 						break;
2762 2762
 					case 'and':
2763 2763
 					case 'AND':
2764
-						$where_clauses[] = " (". $this->_construct_condition_clause_recursive($op_and_value_or_sub_condition, ' AND ') .")";
2764
+						$where_clauses[] = " (".$this->_construct_condition_clause_recursive($op_and_value_or_sub_condition, ' AND ').")";
2765 2765
 						break;
2766 2766
 					case 'or':
2767 2767
 					case 'OR':
2768
-						$where_clauses[] = " (". $this->_construct_condition_clause_recursive($op_and_value_or_sub_condition, ' OR ') .")";
2768
+						$where_clauses[] = " (".$this->_construct_condition_clause_recursive($op_and_value_or_sub_condition, ' OR ').")";
2769 2769
 						break;
2770 2770
 				}
2771
-			}else{
2771
+			} else {
2772 2772
 				$field_obj = $this->_deduce_field_from_query_param($query_param);
2773 2773
 
2774 2774
 				//if it's not a normal field, maybe it's a custom selection?
2775
-				if( ! $field_obj){
2776
-					if(isset( $this->_custom_selections[$query_param][1])){
2775
+				if ( ! $field_obj) {
2776
+					if (isset($this->_custom_selections[$query_param][1])) {
2777 2777
 						$field_obj = $this->_custom_selections[$query_param][1];
2778
-					}else{
2779
-						throw new EE_Error(sprintf(__("%s is neither a valid model field name, nor a custom selection", "event_espresso"),$query_param));
2778
+					} else {
2779
+						throw new EE_Error(sprintf(__("%s is neither a valid model field name, nor a custom selection", "event_espresso"), $query_param));
2780 2780
 					}
2781 2781
 				}
2782 2782
 				$op_and_value_sql = $this->_construct_op_and_value($op_and_value_or_sub_condition, $field_obj);
2783
-				$where_clauses[]=$this->_deduce_column_name_from_query_param($query_param).SP.$op_and_value_sql;
2783
+				$where_clauses[] = $this->_deduce_column_name_from_query_param($query_param).SP.$op_and_value_sql;
2784 2784
 			}
2785 2785
 		}
2786
-		if($where_clauses){
2787
-			$SQL = implode($glue,$where_clauses);
2788
-		}else{
2786
+		if ($where_clauses) {
2787
+			$SQL = implode($glue, $where_clauses);
2788
+		} else {
2789 2789
 			$SQL = '';
2790 2790
 		}
2791 2791
 		return $SQL;
@@ -2799,18 +2799,18 @@  discard block
 block discarded – undo
2799 2799
 	 * @throws EE_Error
2800 2800
 	 * @return string table alias and column name for SQL, eg "Transaction.TXN_ID"
2801 2801
 	 */
2802
-	private function _deduce_column_name_from_query_param($query_param){
2802
+	private function _deduce_column_name_from_query_param($query_param) {
2803 2803
 		$field = $this->_deduce_field_from_query_param($query_param);
2804 2804
 
2805
-		if( $field ){
2806
-			$table_alias_prefix = EE_Model_Parser::extract_table_alias_model_relation_chain_from_query_param( $field->get_model_name(), $query_param );
2807
-			return $table_alias_prefix . $field->get_qualified_column();
2808
-		}elseif(array_key_exists($query_param,$this->_custom_selections)){
2805
+		if ($field) {
2806
+			$table_alias_prefix = EE_Model_Parser::extract_table_alias_model_relation_chain_from_query_param($field->get_model_name(), $query_param);
2807
+			return $table_alias_prefix.$field->get_qualified_column();
2808
+		}elseif (array_key_exists($query_param, $this->_custom_selections)) {
2809 2809
 			//maybe it's custom selection item?
2810 2810
 			//if so, just use it as the "column name"
2811 2811
 			return $query_param;
2812
-		}else{
2813
-			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)));
2812
+		} else {
2813
+			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)));
2814 2814
 		}
2815 2815
 	}
2816 2816
 
@@ -2822,11 +2822,11 @@  discard block
 block discarded – undo
2822 2822
 	 * @param string $condition_query_param_key
2823 2823
 	 * @return string
2824 2824
 	 */
2825
-	private function _remove_stars_and_anything_after_from_condition_query_param_key($condition_query_param_key){
2825
+	private function _remove_stars_and_anything_after_from_condition_query_param_key($condition_query_param_key) {
2826 2826
 		$pos_of_star = strpos($condition_query_param_key, '*');
2827
-		if($pos_of_star === FALSE){
2827
+		if ($pos_of_star === FALSE) {
2828 2828
 			return $condition_query_param_key;
2829
-		}else{
2829
+		} else {
2830 2830
 			$condition_query_param_sans_star = substr($condition_query_param_key, 0, $pos_of_star);
2831 2831
 			return $condition_query_param_sans_star;
2832 2832
 		}
@@ -2841,54 +2841,54 @@  discard block
 block discarded – undo
2841 2841
 	 * @throws EE_Error
2842 2842
 	 * @return string
2843 2843
 	 */
2844
-	private function _construct_op_and_value($op_and_value, $field_obj){
2845
-		if(is_array( $op_and_value )){
2844
+	private function _construct_op_and_value($op_and_value, $field_obj) {
2845
+		if (is_array($op_and_value)) {
2846 2846
 			$operator = isset($op_and_value[0]) ? $this->_prepare_operator_for_sql($op_and_value[0]) : null;
2847
-			if( ! $operator){
2847
+			if ( ! $operator) {
2848 2848
 				$php_array_like_string = array();
2849
-				foreach($op_and_value as $key => $value){
2849
+				foreach ($op_and_value as $key => $value) {
2850 2850
 					$php_array_like_string[] = "$key=>$value";
2851 2851
 				}
2852
-				throw new EE_Error(sprintf(__("You setup a query parameter like you were going to specify an operator, but didn't. You provided '(%s)', but the operator should be at array key index 0 (eg array('>',32))", "event_espresso"), implode(",",$php_array_like_string)));
2852
+				throw new EE_Error(sprintf(__("You setup a query parameter like you were going to specify an operator, but didn't. You provided '(%s)', but the operator should be at array key index 0 (eg array('>',32))", "event_espresso"), implode(",", $php_array_like_string)));
2853 2853
 			}
2854 2854
 			$value = isset($op_and_value[1]) ? $op_and_value[1] : null;
2855
-		}else{
2855
+		} else {
2856 2856
 			$operator = '=';
2857 2857
 			$value = $op_and_value;
2858 2858
 		}
2859 2859
 
2860 2860
 		//check to see if the value is actually another field
2861
-		if(is_array($op_and_value) && isset($op_and_value[2]) && $op_and_value[2] == true){
2861
+		if (is_array($op_and_value) && isset($op_and_value[2]) && $op_and_value[2] == true) {
2862 2862
 			return $operator.SP.$this->_deduce_column_name_from_query_param($value);
2863
-		}elseif(in_array($operator, $this->_in_style_operators) && is_array($value)){
2863
+		}elseif (in_array($operator, $this->_in_style_operators) && is_array($value)) {
2864 2864
 			//in this case, the value should be an array, or at least a comma-separated list
2865 2865
 			//it will need to handle a little differently
2866 2866
 			$cleaned_value = $this->_construct_in_value($value, $field_obj);
2867 2867
 			//note: $cleaned_value has already been run through $wpdb->prepare()
2868 2868
 			return $operator.SP.$cleaned_value;
2869
-		} elseif( in_array( $operator, $this->_between_style_operators ) && is_array( $value ) ) {
2869
+		} elseif (in_array($operator, $this->_between_style_operators) && is_array($value)) {
2870 2870
 			//the value should be an array with count of two.
2871
-			if ( count($value) !== 2 )
2872
-				throw new EE_Error( sprintf( __("The '%s' operator must be used with an array of values and there must be exactly TWO values in that array.", 'event_espresso'), "BETWEEN" ) );
2873
-			$cleaned_value = $this->_construct_between_value( $value, $field_obj );
2871
+			if (count($value) !== 2)
2872
+				throw new EE_Error(sprintf(__("The '%s' operator must be used with an array of values and there must be exactly TWO values in that array.", 'event_espresso'), "BETWEEN"));
2873
+			$cleaned_value = $this->_construct_between_value($value, $field_obj);
2874 2874
 			return $operator.SP.$cleaned_value;
2875
-		} elseif( in_array( $operator, $this->_null_style_operators ) ) {
2876
-			if($value != NULL){
2877
-				throw new EE_Error(sprintf(__("You attempted to give a value  (%s) while using a NULL-style operator (%s). That isn't valid", "event_espresso"),$value,$operator));
2875
+		} elseif (in_array($operator, $this->_null_style_operators)) {
2876
+			if ($value != NULL) {
2877
+				throw new EE_Error(sprintf(__("You attempted to give a value  (%s) while using a NULL-style operator (%s). That isn't valid", "event_espresso"), $value, $operator));
2878 2878
 			}
2879 2879
 			return $operator;
2880
-		}elseif( $operator == 'LIKE' && ! is_array($value)){
2880
+		}elseif ($operator == 'LIKE' && ! is_array($value)) {
2881 2881
 			//if the operator is 'LIKE', we want to allow percent signs (%) and not
2882 2882
 			//remove other junk. So just treat it as a string.
2883 2883
 			return $operator.SP.$this->_wpdb_prepare_using_field($value, '%s');
2884
-		}elseif( ! in_array($operator, $this->_in_style_operators) && ! is_array($value)){
2885
-			return $operator.SP.$this->_wpdb_prepare_using_field($value,$field_obj);
2886
-		}elseif(in_array($operator, $this->_in_style_operators) && ! is_array($value)){
2887
-			throw new EE_Error(sprintf(__("Operator '%s' must be used with an array of values, eg 'Registration.REG_ID' => array('%s',array(1,2,3))",'event_espresso'),$operator, $operator));
2888
-		}elseif( ! in_array($operator, $this->_in_style_operators) && is_array($value)){
2889
-			throw new EE_Error(sprintf(__("Operator '%s' must be used with a single value, not an array. Eg 'Registration.REG_ID => array('%s',23))",'event_espresso'),$operator,$operator));
2890
-		}else{
2891
-			throw new EE_Error(sprintf(__("It appears you've provided some totally invalid query parameters. Operator and value were:'%s', which isn't right at all", "event_espresso"),  http_build_query($op_and_value)));
2884
+		}elseif ( ! in_array($operator, $this->_in_style_operators) && ! is_array($value)) {
2885
+			return $operator.SP.$this->_wpdb_prepare_using_field($value, $field_obj);
2886
+		}elseif (in_array($operator, $this->_in_style_operators) && ! is_array($value)) {
2887
+			throw new EE_Error(sprintf(__("Operator '%s' must be used with an array of values, eg 'Registration.REG_ID' => array('%s',array(1,2,3))", 'event_espresso'), $operator, $operator));
2888
+		}elseif ( ! in_array($operator, $this->_in_style_operators) && is_array($value)) {
2889
+			throw new EE_Error(sprintf(__("Operator '%s' must be used with a single value, not an array. Eg 'Registration.REG_ID => array('%s',23))", 'event_espresso'), $operator, $operator));
2890
+		} else {
2891
+			throw new EE_Error(sprintf(__("It appears you've provided some totally invalid query parameters. Operator and value were:'%s', which isn't right at all", "event_espresso"), http_build_query($op_and_value)));
2892 2892
 		}
2893 2893
 	}
2894 2894
 
@@ -2900,12 +2900,12 @@  discard block
 block discarded – undo
2900 2900
 	 * @param EE_Model_Field_Base|string $field_obj if string, it should be the datatype to be used when querying, eg '%s'
2901 2901
 	 * @return string
2902 2902
 	 */
2903
-	function _construct_between_value( $values, $field_obj ) {
2903
+	function _construct_between_value($values, $field_obj) {
2904 2904
 		$cleaned_values = array();
2905
-		foreach ( $values as $value ) {
2906
-			$cleaned_values[] = $this->_wpdb_prepare_using_field($value,$field_obj);
2905
+		foreach ($values as $value) {
2906
+			$cleaned_values[] = $this->_wpdb_prepare_using_field($value, $field_obj);
2907 2907
 		}
2908
-		return  $cleaned_values[0] . " AND " . $cleaned_values[1];
2908
+		return  $cleaned_values[0]." AND ".$cleaned_values[1];
2909 2909
 	}
2910 2910
 
2911 2911
 
@@ -2921,26 +2921,26 @@  discard block
 block discarded – undo
2921 2921
 	 * @param EE_Model_Field_Base|string $field_obj if string, it should be a wpdb data type like '%s', or '%d'
2922 2922
 	 * @return string of SQL to follow an 'IN' or 'NOT IN' operator
2923 2923
 	 */
2924
-	function _construct_in_value($values,  $field_obj){
2924
+	function _construct_in_value($values, $field_obj) {
2925 2925
 		//check if the value is a CSV list
2926
-		if(is_string($values)){
2926
+		if (is_string($values)) {
2927 2927
 			//in which case, turn it into an array
2928
-			$values = explode(",",$values);
2928
+			$values = explode(",", $values);
2929 2929
 		}
2930 2930
 		$cleaned_values = array();
2931
-		foreach($values as $value){
2932
-			$cleaned_values[] = $this->_wpdb_prepare_using_field($value,$field_obj);
2931
+		foreach ($values as $value) {
2932
+			$cleaned_values[] = $this->_wpdb_prepare_using_field($value, $field_obj);
2933 2933
 		}
2934 2934
 		//we would just LOVE to leave $cleaned_values as an empty array, and return the value as "()",
2935 2935
 		//but unfortunately that's invalid SQL. So instead we return a string which we KNOW will evaluate to be the empty set
2936 2936
 		//which is effectively equivalent to returning "()". We don't return "(0)" because that only works for auto-incrementing columns
2937
-		if(empty($cleaned_values)){
2937
+		if (empty($cleaned_values)) {
2938 2938
 			$all_fields = $this->field_settings();
2939 2939
 			$a_field = array_shift($all_fields);
2940 2940
 			$main_table = $this->_get_main_table();
2941 2941
 			$cleaned_values[] = "SELECT ".$a_field->get_table_column()." FROM ".$main_table->get_table_name()." WHERE FALSE";
2942 2942
 		}
2943
-		return "(".implode(",",$cleaned_values).")";
2943
+		return "(".implode(",", $cleaned_values).")";
2944 2944
 	}
2945 2945
 
2946 2946
 
@@ -2952,15 +2952,15 @@  discard block
 block discarded – undo
2952 2952
 	 * @throws EE_Error
2953 2953
 	 * @return false|null|string
2954 2954
 	 */
2955
-	private function _wpdb_prepare_using_field($value,$field_obj){
2955
+	private function _wpdb_prepare_using_field($value, $field_obj) {
2956 2956
 		global $wpdb;
2957
-		if($field_obj instanceof EE_Model_Field_Base){
2958
-			return $wpdb->prepare($field_obj->get_wpdb_data_type(),$this->_prepare_value_for_use_in_db($value, $field_obj));
2959
-		}else{//$field_obj should really just be a data type
2960
-			if( ! in_array($field_obj,$this->_valid_wpdb_data_types)){
2961
-				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)));
2957
+		if ($field_obj instanceof EE_Model_Field_Base) {
2958
+			return $wpdb->prepare($field_obj->get_wpdb_data_type(), $this->_prepare_value_for_use_in_db($value, $field_obj));
2959
+		} else {//$field_obj should really just be a data type
2960
+			if ( ! in_array($field_obj, $this->_valid_wpdb_data_types)) {
2961
+				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)));
2962 2962
 			}
2963
-			return $wpdb->prepare($field_obj,$value);
2963
+			return $wpdb->prepare($field_obj, $value);
2964 2964
 		}
2965 2965
 	}
2966 2966
 
@@ -2972,27 +2972,27 @@  discard block
 block discarded – undo
2972 2972
 	 * @throws EE_Error
2973 2973
 	 * @return EE_Model_Field_Base
2974 2974
 	 */
2975
-	protected function _deduce_field_from_query_param($query_param_name){
2975
+	protected function _deduce_field_from_query_param($query_param_name) {
2976 2976
 		//ok, now proceed with deducing which part is the model's name, and which is the field's name
2977 2977
 		//which will help us find the database table and column
2978 2978
 
2979
-		$query_param_parts = explode(".",$query_param_name);
2980
-		if(empty($query_param_parts)){
2981
-			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));
2979
+		$query_param_parts = explode(".", $query_param_name);
2980
+		if (empty($query_param_parts)) {
2981
+			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));
2982 2982
 		}
2983 2983
 		$number_of_parts = count($query_param_parts);
2984
-		$last_query_param_part = $query_param_parts[ count($query_param_parts) - 1 ];
2985
-		if($number_of_parts == 1){
2984
+		$last_query_param_part = $query_param_parts[count($query_param_parts) - 1];
2985
+		if ($number_of_parts == 1) {
2986 2986
 			$field_name = $last_query_param_part;
2987 2987
 			$model_obj = $this;
2988
-		}else{// $number_of_parts >= 2
2988
+		} else {// $number_of_parts >= 2
2989 2989
 			//the last part is the column name, and there are only 2parts. therefore...
2990 2990
 			$field_name = $last_query_param_part;
2991
-			$model_obj = $this->get_related_model_obj( $query_param_parts[ $number_of_parts - 2 ]);
2991
+			$model_obj = $this->get_related_model_obj($query_param_parts[$number_of_parts - 2]);
2992 2992
 		}
2993
-		try{
2993
+		try {
2994 2994
 			return $model_obj->field_settings_for($field_name);
2995
-		}catch(EE_Error $e){
2995
+		} catch (EE_Error $e) {
2996 2996
 			return null;
2997 2997
 		}
2998 2998
 	}
@@ -3006,13 +3006,13 @@  discard block
 block discarded – undo
3006 3006
 	 * @throws EE_Error
3007 3007
 	 * @return string
3008 3008
 	 */
3009
-	function _get_qualified_column_for_field($field_name){
3009
+	function _get_qualified_column_for_field($field_name) {
3010 3010
 		$all_fields = $this->field_settings();
3011 3011
 		$field = isset($all_fields[$field_name]) ? $all_fields[$field_name] : FALSE;
3012
-		if($field){
3012
+		if ($field) {
3013 3013
 			return $field->get_qualified_column();
3014
-		}else{
3015
-			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)));
3014
+		} else {
3015
+			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)));
3016 3016
 		}
3017 3017
 	}
3018 3018
 
@@ -3026,14 +3026,14 @@  discard block
 block discarded – undo
3026 3026
 	 * @param  mixed|string $limit The limit for this select
3027 3027
 	 * @return string 				The final select join element for the query.
3028 3028
 	 */
3029
-	function _construct_limit_join_select( $table_alias, $limit ) {
3029
+	function _construct_limit_join_select($table_alias, $limit) {
3030 3030
 		$SQL = '';
3031 3031
 
3032
-		foreach ( $this->_tables as $table_obj ) {
3033
-			if ( $table_obj instanceof EE_Primary_Table ) {
3034
-				$SQL .= $table_alias == $table_obj->get_table_alias() ? $table_obj->get_select_join_limit( $limit ) : SP.$table_obj->get_table_name()." AS ".$table_obj->get_table_alias().SP;
3035
-			} elseif ( $table_obj instanceof EE_Secondary_Table ) {
3036
-				$SQL .= $table_alias == $table_obj->get_table_alias() ? $table_obj->get_select_join_limit_join($limit) : SP . $table_obj->get_join_sql( $table_alias ).SP;
3032
+		foreach ($this->_tables as $table_obj) {
3033
+			if ($table_obj instanceof EE_Primary_Table) {
3034
+				$SQL .= $table_alias == $table_obj->get_table_alias() ? $table_obj->get_select_join_limit($limit) : SP.$table_obj->get_table_name()." AS ".$table_obj->get_table_alias().SP;
3035
+			} elseif ($table_obj instanceof EE_Secondary_Table) {
3036
+				$SQL .= $table_alias == $table_obj->get_table_alias() ? $table_obj->get_select_join_limit_join($limit) : SP.$table_obj->get_join_sql($table_alias).SP;
3037 3037
 			}
3038 3038
 		}
3039 3039
 		return $SQL;
@@ -3046,7 +3046,7 @@  discard block
 block discarded – undo
3046 3046
 	 * Eg "wp_post AS Event" or "wp_post AS Event INNER JOIN wp_postmeta Event_Meta ON Event.ID = Event_Meta.post_id"
3047 3047
 	 * @return string SQL
3048 3048
 	 */
3049
-	function _construct_internal_join(){
3049
+	function _construct_internal_join() {
3050 3050
 		$SQL = $this->_get_main_table()->get_table_sql();
3051 3051
 		$SQL .= $this->_construct_internal_join_to_table_with_alias($this->_get_main_table()->get_table_alias());
3052 3052
 		return $SQL;
@@ -3067,17 +3067,17 @@  discard block
 block discarded – undo
3067 3067
 	 * @param string $alias_prefixed table alias to join to (this table should already be in the FROM SQL clause)
3068 3068
 	 * @return string
3069 3069
 	 */
3070
-	function _construct_internal_join_to_table_with_alias($alias_prefixed){
3070
+	function _construct_internal_join_to_table_with_alias($alias_prefixed) {
3071 3071
 		$SQL = '';
3072 3072
 		$alias_sans_prefix = EE_Model_Parser::remove_table_alias_model_relation_chain_prefix($alias_prefixed);
3073
-		foreach($this->_tables as $table_obj){
3074
-			if($table_obj instanceof EE_Secondary_Table){//table is secondary table
3075
-				if($alias_sans_prefix == $table_obj->get_table_alias()){
3073
+		foreach ($this->_tables as $table_obj) {
3074
+			if ($table_obj instanceof EE_Secondary_Table) {//table is secondary table
3075
+				if ($alias_sans_prefix == $table_obj->get_table_alias()) {
3076 3076
 					//so we're joining to this table, meaning the table is already in
3077 3077
 					//the FROM statement, BUT the primary table isn't. So we want
3078 3078
 					//to add the inverse join sql
3079 3079
 					$SQL .= $table_obj->get_inverse_join_sql($alias_prefixed);
3080
-				}else{
3080
+				} else {
3081 3081
 					//just add a regular JOIN to this table from the primary table
3082 3082
 					$SQL .= $table_obj->get_join_sql($alias_prefixed);
3083 3083
 				}
@@ -3091,9 +3091,9 @@  discard block
 block discarded – undo
3091 3091
 	 * 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)
3092 3092
 	 * @return array
3093 3093
 	 */
3094
-	function _get_data_types(){
3094
+	function _get_data_types() {
3095 3095
 		$data_types = array();
3096
-		foreach(array_values($this->field_settings()) as $field_obj){
3096
+		foreach (array_values($this->field_settings()) as $field_obj) {
3097 3097
 			//$data_types[$field_obj->get_table_column()] = $field_obj->get_wpdb_data_type();
3098 3098
 			/** @var $field_obj EE_Model_Field_Base */
3099 3099
 			$data_types[$field_obj->get_qualified_column()] = $field_obj->get_wpdb_data_type();
@@ -3109,11 +3109,11 @@  discard block
 block discarded – undo
3109 3109
 	 * @throws EE_Error
3110 3110
 	 * @return EEM_Base
3111 3111
 	 */
3112
-	function get_related_model_obj($model_name){
3112
+	function get_related_model_obj($model_name) {
3113 3113
 
3114 3114
 		$model_classname = "EEM_".$model_name;
3115
-		if(!class_exists($model_classname)){
3116
-			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));
3115
+		if ( ! class_exists($model_classname)) {
3116
+			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));
3117 3117
 		}
3118 3118
 		$model_obj = call_user_func($model_classname."::instance");
3119 3119
 		return $model_obj;
@@ -3124,7 +3124,7 @@  discard block
 block discarded – undo
3124 3124
 	 * Returns the array of EE_ModelRelations for this model.
3125 3125
 	 * @return EE_Model_Relation_Base[]
3126 3126
 	 */
3127
-	public function relation_settings(){
3127
+	public function relation_settings() {
3128 3128
 		return $this->_model_relations;
3129 3129
 	}
3130 3130
 
@@ -3134,10 +3134,10 @@  discard block
 block discarded – undo
3134 3134
 	 * (Eg, without an event, datetimes have little purpose.)
3135 3135
 	 * @return EE_Belongs_To_Relation[]
3136 3136
 	 */
3137
-	public function belongs_to_relations(){
3137
+	public function belongs_to_relations() {
3138 3138
 		$belongs_to_relations = array();
3139
-		foreach($this->relation_settings() as $model_name => $relation_obj){
3140
-			if($relation_obj instanceof EE_Belongs_To_Relation){
3139
+		foreach ($this->relation_settings() as $model_name => $relation_obj) {
3140
+			if ($relation_obj instanceof EE_Belongs_To_Relation) {
3141 3141
 				$belongs_to_relations[$model_name] = $relation_obj;
3142 3142
 			}
3143 3143
 		}
@@ -3152,15 +3152,15 @@  discard block
 block discarded – undo
3152 3152
 	 * @throws EE_Error
3153 3153
 	 * @return EE_Model_Relation_Base
3154 3154
 	 */
3155
-	public function related_settings_for($relation_name){
3156
-		$relatedModels=$this->relation_settings();
3157
-		if(!array_key_exists($relation_name,$relatedModels)){
3155
+	public function related_settings_for($relation_name) {
3156
+		$relatedModels = $this->relation_settings();
3157
+		if ( ! array_key_exists($relation_name, $relatedModels)) {
3158 3158
 			throw new EE_Error(
3159 3159
 				sprintf(
3160
-					__('Cannot get %s related to %s. There is no model relation of that type. There is, however, %s...','event_espresso'),
3160
+					__('Cannot get %s related to %s. There is no model relation of that type. There is, however, %s...', 'event_espresso'),
3161 3161
 					$relation_name,
3162 3162
 					$this->_get_class_name(),
3163
-					implode( ', ', array_keys( $relatedModels ))
3163
+					implode(', ', array_keys($relatedModels))
3164 3164
 				)
3165 3165
 			);
3166 3166
 		}
@@ -3175,10 +3175,10 @@  discard block
 block discarded – undo
3175 3175
 	 * @throws EE_Error
3176 3176
 	 * @return EE_Model_Field_Base
3177 3177
 	 */
3178
-	public function field_settings_for($fieldName){
3179
-		$fieldSettings=$this->field_settings(true);
3180
-		if( ! array_key_exists($fieldName,$fieldSettings)){
3181
-			throw new EE_Error(sprintf(__("There is no field/column '%s' on '%s'",'event_espresso'),$fieldName,get_class($this)));
3178
+	public function field_settings_for($fieldName) {
3179
+		$fieldSettings = $this->field_settings(true);
3180
+		if ( ! array_key_exists($fieldName, $fieldSettings)) {
3181
+			throw new EE_Error(sprintf(__("There is no field/column '%s' on '%s'", 'event_espresso'), $fieldName, get_class($this)));
3182 3182
 		}
3183 3183
 		return $fieldSettings[$fieldName];
3184 3184
 	}
@@ -3188,11 +3188,11 @@  discard block
 block discarded – undo
3188 3188
 	 * @param string $fieldName a key in the model's _field_settings array
3189 3189
 	 * @return boolean
3190 3190
 	 */
3191
-	public function has_field($fieldName){
3191
+	public function has_field($fieldName) {
3192 3192
 		$fieldSettings = $this->field_settings(true);
3193
-		if( isset($fieldSettings[$fieldName])){
3193
+		if (isset($fieldSettings[$fieldName])) {
3194 3194
 			return true;
3195
-		}else{
3195
+		} else {
3196 3196
 			return false;
3197 3197
 		}
3198 3198
 	}
@@ -3202,11 +3202,11 @@  discard block
 block discarded – undo
3202 3202
 	 * @param string $relation_name possibly one of the keys in the relation_settings array
3203 3203
 	 * @return boolean
3204 3204
 	 */
3205
-	public function has_relation($relation_name){
3205
+	public function has_relation($relation_name) {
3206 3206
 		$relations = $this->relation_settings();
3207
-		if(isset($relations[$relation_name])){
3207
+		if (isset($relations[$relation_name])) {
3208 3208
 			return true;
3209
-		}else{
3209
+		} else {
3210 3210
 			return false;
3211 3211
 		}
3212 3212
 	}
@@ -3218,7 +3218,7 @@  discard block
 block discarded – undo
3218 3218
 	 * @param $field_obj
3219 3219
 	 * @return EE_Model_Field_Base
3220 3220
 	 */
3221
-	public function is_primary_key_field( $field_obj ){
3221
+	public function is_primary_key_field($field_obj) {
3222 3222
 		return $field_obj instanceof EE_Primary_Key_Field_Base ? TRUE : FALSE;
3223 3223
 	}
3224 3224
 
@@ -3230,16 +3230,16 @@  discard block
 block discarded – undo
3230 3230
 	 * @return EE_Model_Field_Base
3231 3231
 	 * @throws EE_Error
3232 3232
 	 */
3233
-	public function get_primary_key_field(){
3234
-		if( $this->_primary_key_field === NULL ){
3235
-			foreach( $this->field_settings( TRUE ) as $field_obj ){
3236
-				if( $this->is_primary_key_field( $field_obj )){
3233
+	public function get_primary_key_field() {
3234
+		if ($this->_primary_key_field === NULL) {
3235
+			foreach ($this->field_settings(TRUE) as $field_obj) {
3236
+				if ($this->is_primary_key_field($field_obj)) {
3237 3237
 					$this->_primary_key_field = $field_obj;
3238 3238
 					break;
3239 3239
 				}
3240 3240
 			}
3241
-			if( ! $this->_primary_key_field instanceof EE_Primary_Key_Field_Base ){
3242
-				throw new EE_Error(sprintf(__("There is no Primary Key defined on model %s",'event_espresso'),get_class($this)));
3241
+			if ( ! $this->_primary_key_field instanceof EE_Primary_Key_Field_Base) {
3242
+				throw new EE_Error(sprintf(__("There is no Primary Key defined on model %s", 'event_espresso'), get_class($this)));
3243 3243
 			}
3244 3244
 		}
3245 3245
 		return $this->_primary_key_field;
@@ -3252,12 +3252,12 @@  discard block
 block discarded – undo
3252 3252
 	 * Internally does some caching.
3253 3253
 	 * @return boolean
3254 3254
 	 */
3255
-	public function has_primary_key_field(){
3256
-		if($this->_has_primary_key_field === null){
3257
-			try{
3255
+	public function has_primary_key_field() {
3256
+		if ($this->_has_primary_key_field === null) {
3257
+			try {
3258 3258
 				$this->get_primary_key_field();
3259 3259
 				$this->_has_primary_key_field = true;
3260
-			}catch(EE_Error $e){
3260
+			} catch (EE_Error $e) {
3261 3261
 				$this->_has_primary_key_field = false;
3262 3262
 			}
3263 3263
 		}
@@ -3271,9 +3271,9 @@  discard block
 block discarded – undo
3271 3271
 	 * @param string $field_class_name class name of field that you want to find. Eg, EE_Datetime_Field, EE_Foreign_Key_Field, etc
3272 3272
 	 * @return EE_Model_Field_Base or null if none is found
3273 3273
 	 */
3274
-	public function get_a_field_of_type($field_class_name){
3275
-		foreach($this->field_settings() as $field){
3276
-			if( $field instanceof $field_class_name ){
3274
+	public function get_a_field_of_type($field_class_name) {
3275
+		foreach ($this->field_settings() as $field) {
3276
+			if ($field instanceof $field_class_name) {
3277 3277
 				return $field;
3278 3278
 			}
3279 3279
 		}
@@ -3287,21 +3287,21 @@  discard block
 block discarded – undo
3287 3287
 	 * @return EE_Foreign_Key_Field_Base
3288 3288
 	 * @throws EE_Error
3289 3289
 	 */
3290
-	public function get_foreign_key_to($model_name){
3291
-		if( ! isset( $this->_cache_foreign_key_to_fields[ $model_name ] ) ){
3292
-			foreach($this->field_settings() as $field){
3290
+	public function get_foreign_key_to($model_name) {
3291
+		if ( ! isset($this->_cache_foreign_key_to_fields[$model_name])) {
3292
+			foreach ($this->field_settings() as $field) {
3293 3293
 //				if(is_subclass_of($field, 'EE_Foreign_Key_Field_Base')){
3294
-				if( $field instanceof EE_Foreign_Key_Field_Base ){
3295
-					if (in_array($model_name,$field->get_model_names_pointed_to() ) ) {
3296
-						$this->_cache_foreign_key_to_fields[ $model_name ] = $field;
3294
+				if ($field instanceof EE_Foreign_Key_Field_Base) {
3295
+					if (in_array($model_name, $field->get_model_names_pointed_to())) {
3296
+						$this->_cache_foreign_key_to_fields[$model_name] = $field;
3297 3297
 					}
3298 3298
 				}
3299 3299
 			}
3300
-			if( ! isset( $this->_cache_foreign_key_to_fields[ $model_name ] ) ){
3301
-				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)));
3300
+			if ( ! isset($this->_cache_foreign_key_to_fields[$model_name])) {
3301
+				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)));
3302 3302
 			}
3303 3303
 		}
3304
-		return $this->_cache_foreign_key_to_fields[ $model_name ];
3304
+		return $this->_cache_foreign_key_to_fields[$model_name];
3305 3305
 	}
3306 3306
 
3307 3307
 
@@ -3312,7 +3312,7 @@  discard block
 block discarded – undo
3312 3312
 	 * a table alias with a model chain prefix, like 'Venue__Event_Venue___Event_Meta'. Either one works
3313 3313
 	 * @return EE_Table_Base
3314 3314
 	 */
3315
-	function get_table_for_alias($table_alias){
3315
+	function get_table_for_alias($table_alias) {
3316 3316
 		$table_alias_sans_model_relation_chain_prefix = EE_Model_Parser::remove_table_alias_model_relation_chain_prefix($table_alias);
3317 3317
 		return $this->_tables[$table_alias_sans_model_relation_chain_prefix]->get_table_name();
3318 3318
 	}
@@ -3325,25 +3325,25 @@  discard block
 block discarded – undo
3325 3325
 	 * @param bool $include_db_only_fields flag indicating whether or not to include the db-only fields
3326 3326
 	 * @return EE_Model_Field_Base[] where the keys are the field's name
3327 3327
 	 */
3328
-	public function field_settings($include_db_only_fields = false){
3329
-		if( $include_db_only_fields ){
3330
-			if( $this->_cached_fields === NULL ){
3328
+	public function field_settings($include_db_only_fields = false) {
3329
+		if ($include_db_only_fields) {
3330
+			if ($this->_cached_fields === NULL) {
3331 3331
 				$this->_cached_fields = array();
3332
-				foreach($this->_fields as $fields_corresponding_to_table){
3333
-					foreach($fields_corresponding_to_table as $field_name => $field_obj){
3334
-						$this->_cached_fields[$field_name]=$field_obj;
3332
+				foreach ($this->_fields as $fields_corresponding_to_table) {
3333
+					foreach ($fields_corresponding_to_table as $field_name => $field_obj) {
3334
+						$this->_cached_fields[$field_name] = $field_obj;
3335 3335
 					}
3336 3336
 				}
3337 3337
 			}
3338 3338
 			return $this->_cached_fields;
3339
-		}else{
3340
-			if( $this->_cached_fields_non_db_only === NULL ){
3339
+		} else {
3340
+			if ($this->_cached_fields_non_db_only === NULL) {
3341 3341
 				$this->_cached_fields_non_db_only = array();
3342
-				foreach($this->_fields as $fields_corresponding_to_table){
3343
-					foreach($fields_corresponding_to_table as $field_name => $field_obj){
3342
+				foreach ($this->_fields as $fields_corresponding_to_table) {
3343
+					foreach ($fields_corresponding_to_table as $field_name => $field_obj) {
3344 3344
 						/** @var $field_obj EE_Model_Field_Base */
3345
-						if( ! $field_obj->is_db_only_field() ){
3346
-							$this->_cached_fields_non_db_only[$field_name]=$field_obj;
3345
+						if ( ! $field_obj->is_db_only_field()) {
3346
+							$this->_cached_fields_non_db_only[$field_name] = $field_obj;
3347 3347
 						}
3348 3348
 					}
3349 3349
 				}
@@ -3362,40 +3362,40 @@  discard block
 block discarded – undo
3362 3362
 	 * @return \EE_Base_Class[] array keys are primary keys (if there is a primary key on the model. if not, numerically indexed)
3363 3363
 	 * @throws \EE_Error
3364 3364
 	 */
3365
-	protected function _create_objects( $rows = array() ) {
3366
-		$array_of_objects=array();
3367
-		if(empty($rows)){
3365
+	protected function _create_objects($rows = array()) {
3366
+		$array_of_objects = array();
3367
+		if (empty($rows)) {
3368 3368
 			return array();
3369 3369
 		}
3370 3370
 		$count_if_model_has_no_primary_key = 0;
3371
-		foreach ( $rows as $row ) {
3372
-			if(empty($row)){//wp did its weird thing where it returns an array like array(0=>null), which is totally not helpful...
3371
+		foreach ($rows as $row) {
3372
+			if (empty($row)) {//wp did its weird thing where it returns an array like array(0=>null), which is totally not helpful...
3373 3373
 				return array();
3374 3374
 			}
3375
-			$classInstance=$this->instantiate_class_from_array_or_object($row);
3376
-			if( ! $classInstance ) {
3377
-				throw new EE_Error( sprintf( __( 'Could not create instance of class %s from row %s', 'event_espresso' ), $this->get_this_model_name(), http_build_query( $row ) ) );
3375
+			$classInstance = $this->instantiate_class_from_array_or_object($row);
3376
+			if ( ! $classInstance) {
3377
+				throw new EE_Error(sprintf(__('Could not create instance of class %s from row %s', 'event_espresso'), $this->get_this_model_name(), http_build_query($row)));
3378 3378
 			}
3379 3379
 			//set the timezone on the instantiated objects
3380
-			$classInstance->set_timezone( $this->_timezone );
3380
+			$classInstance->set_timezone($this->_timezone);
3381 3381
 			//make sure if there is any timezone setting present that we set the timezone for the object
3382
-			$array_of_objects[$this->has_primary_key_field() ? $classInstance->ID() : $count_if_model_has_no_primary_key++]=$classInstance;
3382
+			$array_of_objects[$this->has_primary_key_field() ? $classInstance->ID() : $count_if_model_has_no_primary_key++] = $classInstance;
3383 3383
 			//also, for all the relations of type BelongsTo, see if we can cache
3384 3384
 			//those related models
3385 3385
 			//(we could do this for other relations too, but if there are conditions
3386 3386
 			//that filtered out some fo the results, then we'd be caching an incomplete set
3387 3387
 			//so it requires a little more thought than just caching them immediately...)
3388
-			foreach($this->_model_relations as $modelName => $relation_obj){
3389
-				if( $relation_obj instanceof EE_Belongs_To_Relation){
3388
+			foreach ($this->_model_relations as $modelName => $relation_obj) {
3389
+				if ($relation_obj instanceof EE_Belongs_To_Relation) {
3390 3390
 					//check if this model's INFO is present. If so, cache it on the model
3391 3391
 					$other_model = $relation_obj->get_other_model();
3392 3392
 
3393 3393
 					$other_model_obj_maybe = $other_model->instantiate_class_from_array_or_object($row);
3394 3394
 
3395 3395
 					//if we managed to make a model object from the results, cache it on the main model object
3396
-					if( $other_model_obj_maybe ){
3396
+					if ($other_model_obj_maybe) {
3397 3397
 						//set timezone on these other model objects if they are present
3398
-						$other_model_obj_maybe->set_timezone( $this->_timezone );
3398
+						$other_model_obj_maybe->set_timezone($this->_timezone);
3399 3399
 						$classInstance->cache($modelName, $other_model_obj_maybe);
3400 3400
 					}
3401 3401
 				}
@@ -3416,12 +3416,12 @@  discard block
 block discarded – undo
3416 3416
 
3417 3417
 		$this_model_fields_and_values = array();
3418 3418
 		//setup the row using default values;
3419
-		foreach ( $this->field_settings() as $field_name => $field_obj ) {
3419
+		foreach ($this->field_settings() as $field_name => $field_obj) {
3420 3420
 			$this_model_fields_and_values[$field_name] = $field_obj->get_default_value();
3421 3421
 		}
3422 3422
 
3423 3423
 		$className = $this->_get_class_name();
3424
-		$classInstance = EE_Registry::instance()->load_class( $className, array( $this_model_fields_and_values ), FALSE, FALSE );
3424
+		$classInstance = EE_Registry::instance()->load_class($className, array($this_model_fields_and_values), FALSE, FALSE);
3425 3425
 
3426 3426
 		return $classInstance;
3427 3427
 	}
@@ -3432,13 +3432,13 @@  discard block
 block discarded – undo
3432 3432
 	 * _get_cached_acceptable_table_columns
3433 3433
 	 * @return EE_Model_Field_Base[]|null
3434 3434
 	 */
3435
-	private function _get_cached_acceptable_table_columns(){
3436
-		if( $this->_model_fields_sorted_by_db_col === NULL ){
3437
-			foreach( $this->field_settings() as $field_obj ){
3438
-				if( ! $field_obj->is_db_only_field() ){
3439
-					$this->_model_fields_sorted_by_db_col[ $field_obj->get_qualified_column() ] = $field_obj;
3435
+	private function _get_cached_acceptable_table_columns() {
3436
+		if ($this->_model_fields_sorted_by_db_col === NULL) {
3437
+			foreach ($this->field_settings() as $field_obj) {
3438
+				if ( ! $field_obj->is_db_only_field()) {
3439
+					$this->_model_fields_sorted_by_db_col[$field_obj->get_qualified_column()] = $field_obj;
3440 3440
 //					$this->_model_fields_sorted_by_db_col[ $field->get_table_column() ] = $field_obj;
3441
-					$this->_model_fields_sorted_by_db_col[ $field_obj->get_table_column() ] = $field_obj;
3441
+					$this->_model_fields_sorted_by_db_col[$field_obj->get_table_column()] = $field_obj;
3442 3442
 				}
3443 3443
 			}
3444 3444
 		}
@@ -3451,45 +3451,45 @@  discard block
 block discarded – undo
3451 3451
 	 * or an stdClass where each property is the name of a column,
3452 3452
 	 * @return EE_Base_Class
3453 3453
 	 */
3454
-	public function instantiate_class_from_array_or_object($cols_n_values){
3455
-		if( ! is_array( $cols_n_values ) && is_object( $cols_n_values )) {
3456
-			$cols_n_values = get_object_vars( $cols_n_values );
3454
+	public function instantiate_class_from_array_or_object($cols_n_values) {
3455
+		if ( ! is_array($cols_n_values) && is_object($cols_n_values)) {
3456
+			$cols_n_values = get_object_vars($cols_n_values);
3457 3457
 		}
3458 3458
 		$primary_key = NULL;
3459 3459
 		//make sure the array only has keys that are fields/columns on this model
3460
-		$this_model_fields_n_values = $this->_deduce_fields_n_values_from_cols_n_values( $cols_n_values );
3461
-		if( $this->has_primary_key_field() && isset( $this_model_fields_n_values[ $this->primary_key_name() ] ) ){
3462
-			$primary_key = $this_model_fields_n_values[ $this->primary_key_name() ];
3460
+		$this_model_fields_n_values = $this->_deduce_fields_n_values_from_cols_n_values($cols_n_values);
3461
+		if ($this->has_primary_key_field() && isset($this_model_fields_n_values[$this->primary_key_name()])) {
3462
+			$primary_key = $this_model_fields_n_values[$this->primary_key_name()];
3463 3463
 		}
3464
-		$className=$this->_get_class_name();
3464
+		$className = $this->_get_class_name();
3465 3465
 
3466 3466
 		//check we actually found results that we can use to build our model object
3467 3467
 		//if not, return null
3468
-		if( $this->has_primary_key_field()){
3469
-			if(empty( $this_model_fields_n_values[$this->primary_key_name()] )){
3468
+		if ($this->has_primary_key_field()) {
3469
+			if (empty($this_model_fields_n_values[$this->primary_key_name()])) {
3470 3470
 				return NULL;
3471 3471
 			}
3472
-		}else if($this->unique_indexes()){
3472
+		} else if ($this->unique_indexes()) {
3473 3473
 			$first_column = reset($this_model_fields_n_values);
3474
-			if(empty($first_column)){
3474
+			if (empty($first_column)) {
3475 3475
 				return NULL;
3476 3476
 			}
3477 3477
 		}
3478 3478
 
3479 3479
 		// if there is no primary key or the object doesn't already exist in the entity map, then create a new instance
3480
-		if ( $primary_key){
3481
-			$classInstance = $this->get_from_entity_map( $primary_key );
3482
-			if( ! $classInstance) {
3483
-				$classInstance = EE_Registry::instance()->load_class( $className, array( $this_model_fields_n_values, $this->_timezone ), TRUE, FALSE );
3480
+		if ($primary_key) {
3481
+			$classInstance = $this->get_from_entity_map($primary_key);
3482
+			if ( ! $classInstance) {
3483
+				$classInstance = EE_Registry::instance()->load_class($className, array($this_model_fields_n_values, $this->_timezone), TRUE, FALSE);
3484 3484
 				// add this new object to the entity map
3485
-				$classInstance = $this->add_to_entity_map( $classInstance );
3485
+				$classInstance = $this->add_to_entity_map($classInstance);
3486 3486
 			}
3487
-		}else{
3488
-			$classInstance = EE_Registry::instance()->load_class( $className, array( $this_model_fields_n_values, $this->_timezone ), TRUE, FALSE );
3487
+		} else {
3488
+			$classInstance = EE_Registry::instance()->load_class($className, array($this_model_fields_n_values, $this->_timezone), TRUE, FALSE);
3489 3489
 		}
3490 3490
 
3491 3491
 			//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.
3492
-		$this->set_timezone( $classInstance->get_timezone() );
3492
+		$this->set_timezone($classInstance->get_timezone());
3493 3493
 		return $classInstance;
3494 3494
 	}
3495 3495
 	/**
@@ -3497,8 +3497,8 @@  discard block
 block discarded – undo
3497 3497
 	 * @param int|string $id the ID of the model object
3498 3498
 	 * @return EE_Base_Class
3499 3499
 	 */
3500
-	public function get_from_entity_map( $id ){
3501
-		return isset( $this->_entity_map[ $id ] ) ? $this->_entity_map[ $id ] : NULL;
3500
+	public function get_from_entity_map($id) {
3501
+		return isset($this->_entity_map[$id]) ? $this->_entity_map[$id] : NULL;
3502 3502
 	}
3503 3503
 
3504 3504
 
@@ -3517,21 +3517,21 @@  discard block
 block discarded – undo
3517 3517
 	 * @throws EE_Error
3518 3518
 	 * @return \EE_Base_Class
3519 3519
 	 */
3520
-	public function add_to_entity_map( EE_Base_Class $object) {
3520
+	public function add_to_entity_map(EE_Base_Class $object) {
3521 3521
 		$className = $this->_get_class_name();
3522
-		if( ! $object instanceof $className ){
3523
-			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 ) );
3522
+		if ( ! $object instanceof $className) {
3523
+			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));
3524 3524
 		}
3525 3525
 		/** @var $object EE_Base_Class */
3526
-		if ( ! $object->ID() ){
3527
-			throw new EE_Error(sprintf(__("You tried storing a model object with NO ID in the %s entity mapper.", "event_espresso"),get_class($this)));
3526
+		if ( ! $object->ID()) {
3527
+			throw new EE_Error(sprintf(__("You tried storing a model object with NO ID in the %s entity mapper.", "event_espresso"), get_class($this)));
3528 3528
 		}
3529 3529
 		// double check it's not already there
3530
-		$classInstance = $this->get_from_entity_map( $object->ID() );
3531
-		if ( $classInstance ) {
3530
+		$classInstance = $this->get_from_entity_map($object->ID());
3531
+		if ($classInstance) {
3532 3532
 			return $classInstance;
3533 3533
 		} else {
3534
-			$this->_entity_map[ $object->ID() ] = $object;
3534
+			$this->_entity_map[$object->ID()] = $object;
3535 3535
 			return $object;
3536 3536
 		}
3537 3537
 	}
@@ -3544,8 +3544,8 @@  discard block
 block discarded – undo
3544 3544
 	 * @param array $cols_n_values
3545 3545
 	 * @return array
3546 3546
 	 */
3547
-	public function deduce_fields_n_values_from_cols_n_values( $cols_n_values ) {
3548
-		return $this->_deduce_fields_n_values_from_cols_n_values( $cols_n_values );
3547
+	public function deduce_fields_n_values_from_cols_n_values($cols_n_values) {
3548
+		return $this->_deduce_fields_n_values_from_cols_n_values($cols_n_values);
3549 3549
 	}
3550 3550
 
3551 3551
 
@@ -3558,38 +3558,38 @@  discard block
 block discarded – undo
3558 3558
 	 * @param string $cols_n_values
3559 3559
 	 * @return array
3560 3560
 	 */
3561
-	protected function _deduce_fields_n_values_from_cols_n_values( $cols_n_values ){
3561
+	protected function _deduce_fields_n_values_from_cols_n_values($cols_n_values) {
3562 3562
 		$this_model_fields_n_values = array();
3563
-		foreach( $this->get_tables() as $table_alias => $table_obj ) {
3564
-			$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() );
3563
+		foreach ($this->get_tables() as $table_alias => $table_obj) {
3564
+			$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());
3565 3565
 			//there is a primary key on this table and its not set. Use defaults for all its columns
3566
-			if( $table_obj->get_pk_column() && $table_pk_value === NULL ){
3567
-				foreach( $this->_get_fields_for_table( $table_alias ) as $field_name => $field_obj ) {
3568
-					if( ! $field_obj->is_db_only_field() ){
3566
+			if ($table_obj->get_pk_column() && $table_pk_value === NULL) {
3567
+				foreach ($this->_get_fields_for_table($table_alias) as $field_name => $field_obj) {
3568
+					if ( ! $field_obj->is_db_only_field()) {
3569 3569
 						$this_model_fields_n_values[$field_name] = $field_obj->get_default_value();
3570 3570
 					}
3571 3571
 				}
3572
-			}else{
3572
+			} else {
3573 3573
 				//the table's rows existed. Use their values
3574
-				foreach( $this->_get_fields_for_table( $table_alias ) as $field_name => $field_obj ) {
3575
-					if( ! $field_obj->is_db_only_field() )
3576
-					$this_model_fields_n_values[$field_name] = $this->_get_column_value_with_table_alias_or_not($cols_n_values, $field_obj->get_qualified_column(), $field_obj->get_table_column() );
3574
+				foreach ($this->_get_fields_for_table($table_alias) as $field_name => $field_obj) {
3575
+					if ( ! $field_obj->is_db_only_field())
3576
+					$this_model_fields_n_values[$field_name] = $this->_get_column_value_with_table_alias_or_not($cols_n_values, $field_obj->get_qualified_column(), $field_obj->get_table_column());
3577 3577
 				}
3578 3578
 			}
3579 3579
 		}
3580 3580
 		return $this_model_fields_n_values;
3581 3581
 	}
3582 3582
 
3583
-	protected function _get_column_value_with_table_alias_or_not( $cols_n_values, $qualified_column, $regular_column ){
3583
+	protected function _get_column_value_with_table_alias_or_not($cols_n_values, $qualified_column, $regular_column) {
3584 3584
 		//ask the field what it think it's table_name.column_name should be, and call it the "qualified column"
3585 3585
 		//does the field on the model relate to this column retrieved from the db?
3586 3586
 		//or is it a db-only field? (not relating to the model)
3587
-		if( isset( $cols_n_values[ $qualified_column ] ) ){
3588
-			$value = $cols_n_values[ $qualified_column ];
3587
+		if (isset($cols_n_values[$qualified_column])) {
3588
+			$value = $cols_n_values[$qualified_column];
3589 3589
 
3590
-		}elseif( isset( $cols_n_values[ $regular_column ] ) ){
3591
-			$value = $cols_n_values[ $regular_column ];
3592
-		}else{
3590
+		}elseif (isset($cols_n_values[$regular_column])) {
3591
+			$value = $cols_n_values[$regular_column];
3592
+		} else {
3593 3593
 			$value = NULL;
3594 3594
 		}
3595 3595
 
@@ -3607,23 +3607,23 @@  discard block
 block discarded – undo
3607 3607
 	 * @param int|string $id
3608 3608
 	 * @return EE_Base_Class
3609 3609
 	 */
3610
-	public function refresh_entity_map_from_db( $id ){
3611
-		$obj_in_map = $this->get_from_entity_map( $id );
3612
-		if( $obj_in_map ){
3613
-			$wpdb_results = $this->_get_all_wpdb_results( array( array ( $this->get_primary_key_field()->get_name() => $id ), 'limit' => 1 ) );
3614
-			if( $wpdb_results && is_array( $wpdb_results ) ){
3615
-				$one_row = reset( $wpdb_results );
3616
-				foreach( $this->_deduce_fields_n_values_from_cols_n_values($one_row ) as $field_name => $db_value ) {
3617
-					$obj_in_map->set_from_db( $field_name, $db_value );
3610
+	public function refresh_entity_map_from_db($id) {
3611
+		$obj_in_map = $this->get_from_entity_map($id);
3612
+		if ($obj_in_map) {
3613
+			$wpdb_results = $this->_get_all_wpdb_results(array(array($this->get_primary_key_field()->get_name() => $id), 'limit' => 1));
3614
+			if ($wpdb_results && is_array($wpdb_results)) {
3615
+				$one_row = reset($wpdb_results);
3616
+				foreach ($this->_deduce_fields_n_values_from_cols_n_values($one_row) as $field_name => $db_value) {
3617
+					$obj_in_map->set_from_db($field_name, $db_value);
3618 3618
 				}
3619 3619
 				//clear the cache of related model objects
3620
-				foreach ( $this->relation_settings() as $relation_name => $relation_obj ){
3621
-					$obj_in_map->clear_cache($relation_name, NULL, TRUE );
3620
+				foreach ($this->relation_settings() as $relation_name => $relation_obj) {
3621
+					$obj_in_map->clear_cache($relation_name, NULL, TRUE);
3622 3622
 				}
3623 3623
 			}
3624 3624
 			return $obj_in_map;
3625
-		}else{
3626
-			return $this->get_one_by_ID( $id );
3625
+		} else {
3626
+			return $this->get_one_by_ID($id);
3627 3627
 		}
3628 3628
 	}
3629 3629
 
@@ -3641,24 +3641,24 @@  discard block
 block discarded – undo
3641 3641
 	 * @param EE_Base_Class $replacing_model_obj
3642 3642
 	 * @return \EE_Base_Class
3643 3643
 	 */
3644
-	public function refresh_entity_map_with( $id, $replacing_model_obj ) {
3645
-		$obj_in_map = $this->get_from_entity_map( $id );
3646
-		if( $obj_in_map ){
3647
-			if( $replacing_model_obj instanceof EE_Base_Class ){
3648
-				foreach( $replacing_model_obj->model_field_array() as $field_name => $value ) {
3649
-					$obj_in_map->set( $field_name, $value );
3644
+	public function refresh_entity_map_with($id, $replacing_model_obj) {
3645
+		$obj_in_map = $this->get_from_entity_map($id);
3646
+		if ($obj_in_map) {
3647
+			if ($replacing_model_obj instanceof EE_Base_Class) {
3648
+				foreach ($replacing_model_obj->model_field_array() as $field_name => $value) {
3649
+					$obj_in_map->set($field_name, $value);
3650 3650
 				}
3651 3651
 				//make the model object in the entity map's cache match the $replacing_model_obj
3652
-				foreach ( $this->relation_settings() as $relation_name => $relation_obj ){
3653
-					$obj_in_map->clear_cache($relation_name, NULL, TRUE );
3654
-					foreach( $replacing_model_obj->get_all_from_cache( $relation_name ) as $cache_id => $cached_obj ) {
3655
-						$obj_in_map->cache( $relation_name, $cached_obj, $cache_id );
3652
+				foreach ($this->relation_settings() as $relation_name => $relation_obj) {
3653
+					$obj_in_map->clear_cache($relation_name, NULL, TRUE);
3654
+					foreach ($replacing_model_obj->get_all_from_cache($relation_name) as $cache_id => $cached_obj) {
3655
+						$obj_in_map->cache($relation_name, $cached_obj, $cache_id);
3656 3656
 					}
3657 3657
 				}
3658 3658
 			}
3659 3659
 			return $obj_in_map;
3660
-		}else{
3661
-			$this->add_to_entity_map( $replacing_model_obj );
3660
+		} else {
3661
+			$this->add_to_entity_map($replacing_model_obj);
3662 3662
 			return $replacing_model_obj;
3663 3663
 		}
3664 3664
 	}
@@ -3671,7 +3671,7 @@  discard block
 block discarded – undo
3671 3671
 	 * require_once($this->_getClassName().".class.php");
3672 3672
 	 * @return string
3673 3673
 	 */
3674
-	private function _get_class_name(){
3674
+	private function _get_class_name() {
3675 3675
 		return "EE_".$this->get_this_model_name();
3676 3676
 	}
3677 3677
 
@@ -3684,10 +3684,10 @@  discard block
 block discarded – undo
3684 3684
 	 * @param int $quantity
3685 3685
 	 * @return string
3686 3686
 	 */
3687
-	public function item_name($quantity = 1){
3688
-		if($quantity == 1){
3687
+	public function item_name($quantity = 1) {
3688
+		if ($quantity == 1) {
3689 3689
 			return $this->singular_item;
3690
-		}else{
3690
+		} else {
3691 3691
 			return $this->plural_item;
3692 3692
 		}
3693 3693
 	}
@@ -3716,13 +3716,13 @@  discard block
 block discarded – undo
3716 3716
 	 * @throws EE_Error
3717 3717
 	 * @return mixed whatever the plugin which calls add_filter decides
3718 3718
 	 */
3719
-	public function __call($methodName,$args){
3720
-		$className=get_class($this);
3721
-		$tagName="FHEE__{$className}__{$methodName}";
3722
-		if(!has_filter($tagName)){
3719
+	public function __call($methodName, $args) {
3720
+		$className = get_class($this);
3721
+		$tagName = "FHEE__{$className}__{$methodName}";
3722
+		if ( ! has_filter($tagName)) {
3723 3723
 			throw new EE_Error(
3724 3724
 				sprintf(
3725
-					__( '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' ),
3725
+					__('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'),
3726 3726
 					$methodName,
3727 3727
 					$className,
3728 3728
 					$tagName,
@@ -3731,7 +3731,7 @@  discard block
 block discarded – undo
3731 3731
 			);
3732 3732
 		}
3733 3733
 
3734
-		return apply_filters($tagName,null,$this,$args);
3734
+		return apply_filters($tagName, null, $this, $args);
3735 3735
 	}
3736 3736
 
3737 3737
 
@@ -3744,22 +3744,22 @@  discard block
 block discarded – undo
3744 3744
 	 * @throws EE_Error
3745 3745
 	 * @return EE_Base_Class
3746 3746
 	 */
3747
-	public function ensure_is_obj( $base_class_obj_or_id, $ensure_is_in_db = FALSE ){
3747
+	public function ensure_is_obj($base_class_obj_or_id, $ensure_is_in_db = FALSE) {
3748 3748
 		$className = $this->_get_class_name();
3749 3749
 		$primary_key_field = $this->get_primary_key_field();
3750
-		if( $base_class_obj_or_id instanceof $className ){
3750
+		if ($base_class_obj_or_id instanceof $className) {
3751 3751
 			$model_object = $base_class_obj_or_id;
3752
-		}elseif( $primary_key_field instanceof EE_Primary_Key_Int_Field && (
3753
-				is_int( $base_class_obj_or_id ) ||
3754
-				is_string( $base_class_obj_or_id ) )){//assume it's an ID. either a proper integer or a string representing an integer (eg "101" instead of 101)
3752
+		}elseif ($primary_key_field instanceof EE_Primary_Key_Int_Field && (
3753
+				is_int($base_class_obj_or_id) ||
3754
+				is_string($base_class_obj_or_id) )) {//assume it's an ID. either a proper integer or a string representing an integer (eg "101" instead of 101)
3755 3755
 			$model_object = $this->get_one_by_ID($base_class_obj_or_id);
3756
-		}elseif( $primary_key_field instanceof EE_Primary_Key_String_Field && is_string($base_class_obj_or_id) ){
3756
+		}elseif ($primary_key_field instanceof EE_Primary_Key_String_Field && is_string($base_class_obj_or_id)) {
3757 3757
 			//assume its a string representation of the object
3758 3758
 			$model_object = $this->get_one_by_ID($base_class_obj_or_id);
3759
-		}else{
3760
-			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)));
3759
+		} else {
3760
+			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)));
3761 3761
 		}
3762
-		if( $model_object->ID() == NULL && $ensure_is_in_db){
3762
+		if ($model_object->ID() == NULL && $ensure_is_in_db) {
3763 3763
 			$model_object->save();
3764 3764
 		}
3765 3765
 		return $model_object;
@@ -3775,19 +3775,19 @@  discard block
 block discarded – undo
3775 3775
 	 * @return int|string depending on the type of this model object's ID
3776 3776
 	 * @throws EE_Error
3777 3777
 	 */
3778
-	public function ensure_is_ID($base_class_obj_or_id){
3778
+	public function ensure_is_ID($base_class_obj_or_id) {
3779 3779
 		$className = $this->_get_class_name();
3780
-		if( $base_class_obj_or_id instanceof $className ){
3780
+		if ($base_class_obj_or_id instanceof $className) {
3781 3781
 			/** @var $base_class_obj_or_id EE_Base_Class */
3782 3782
 			$id = $base_class_obj_or_id->ID();
3783
-		}elseif(is_int($base_class_obj_or_id)){
3783
+		}elseif (is_int($base_class_obj_or_id)) {
3784 3784
 			//assume it's an ID
3785 3785
 			$id = $base_class_obj_or_id;
3786
-		}elseif(is_string($base_class_obj_or_id)){
3786
+		}elseif (is_string($base_class_obj_or_id)) {
3787 3787
 			//assume its a string representation of the object
3788 3788
 			$id = $base_class_obj_or_id;
3789
-		}else{
3790
-			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)));
3789
+		} else {
3790
+			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)));
3791 3791
 		}
3792 3792
 		return $id;
3793 3793
 	}
@@ -3810,14 +3810,14 @@  discard block
 block discarded – undo
3810 3810
 	 * @param int $values_already_prepared like one of the constants on EEM_Base
3811 3811
 	 * @return void
3812 3812
 	 */
3813
-	public function assume_values_already_prepared_by_model_object($values_already_prepared = self::not_prepared_by_model_object){
3813
+	public function assume_values_already_prepared_by_model_object($values_already_prepared = self::not_prepared_by_model_object) {
3814 3814
 		$this->_values_already_prepared_by_model_object = $values_already_prepared;
3815 3815
 	}
3816 3816
 	/**
3817 3817
 	 * Read comments for assume_values_already_prepared_by_model_object()
3818 3818
 	 * @return int
3819 3819
 	 */
3820
-	public function get_assumption_concerning_values_already_prepared_by_model_object(){
3820
+	public function get_assumption_concerning_values_already_prepared_by_model_object() {
3821 3821
 		return $this->_values_already_prepared_by_model_object;
3822 3822
 	}
3823 3823
 
@@ -3825,17 +3825,17 @@  discard block
 block discarded – undo
3825 3825
 	 * Gets all the indexes on this model
3826 3826
 	 * @return EE_Index[]
3827 3827
 	 */
3828
-	public function indexes(){
3828
+	public function indexes() {
3829 3829
 		return $this->_indexes;
3830 3830
 	}
3831 3831
 	/**
3832 3832
 	 * Gets all the Unique Indexes on this model
3833 3833
 	 * @return EE_Unique_Index[]
3834 3834
 	 */
3835
-	public function unique_indexes(){
3835
+	public function unique_indexes() {
3836 3836
 		$unique_indexes = array();
3837
-		foreach($this->_indexes as $name => $index){
3838
-			if($index instanceof EE_Unique_Index){
3837
+		foreach ($this->_indexes as $name => $index) {
3838
+			if ($index instanceof EE_Unique_Index) {
3839 3839
 				$unique_indexes [$name] = $index;
3840 3840
 			}
3841 3841
 		}
@@ -3848,9 +3848,9 @@  discard block
 block discarded – undo
3848 3848
 	 * on a primary index
3849 3849
 	 * @return EE_Model_Field_Base[]
3850 3850
 	 */
3851
-	public function get_combined_primary_key_fields(){
3852
-		foreach($this->indexes() as $index){
3853
-			if($index instanceof EE_Primary_Key_Index){
3851
+	public function get_combined_primary_key_fields() {
3852
+		foreach ($this->indexes() as $index) {
3853
+			if ($index instanceof EE_Primary_Key_Index) {
3854 3854
 				return $index->fields();
3855 3855
 			}
3856 3856
 		}
@@ -3863,7 +3863,7 @@  discard block
 block discarded – undo
3863 3863
 	 * @param array $cols_n_values keys are field names, values are their values
3864 3864
 	 * @return string
3865 3865
 	 */
3866
-	public function get_index_primary_key_string($cols_n_values){
3866
+	public function get_index_primary_key_string($cols_n_values) {
3867 3867
 		$cols_n_values_for_primary_key_index = array_intersect_key($cols_n_values, $this->get_combined_primary_key_fields());
3868 3868
 		return http_build_query($cols_n_values_for_primary_key_index);
3869 3869
 	}
@@ -3875,13 +3875,13 @@  discard block
 block discarded – undo
3875 3875
 	 * @param string $index_primary_key_string
3876 3876
 	 * @return null|array
3877 3877
 	 */
3878
-	function parse_index_primary_key_string( $index_primary_key_string) {
3878
+	function parse_index_primary_key_string($index_primary_key_string) {
3879 3879
 		$key_fields = $this->get_combined_primary_key_fields();
3880 3880
 		//check all of them are in the $id
3881 3881
 		$key_vals_in_combined_pk = array();
3882
-		parse_str( $index_primary_key_string, $key_vals_in_combined_pk );
3883
-		foreach( $key_fields as $key_field_name => $field_obj ) {
3884
-			if( ! isset( $key_vals_in_combined_pk[ $key_field_name ] ) ){
3882
+		parse_str($index_primary_key_string, $key_vals_in_combined_pk);
3883
+		foreach ($key_fields as $key_field_name => $field_obj) {
3884
+			if ( ! isset($key_vals_in_combined_pk[$key_field_name])) {
3885 3885
 				return NULL;
3886 3886
 			}
3887 3887
 		}
@@ -3894,10 +3894,10 @@  discard block
 block discarded – undo
3894 3894
 	 * @param array $key_vals
3895 3895
 	 * @return boolean
3896 3896
 	 */
3897
-	function has_all_combined_primary_key_fields( $key_vals ) {
3898
-		$keys_it_should_have = array_keys( $this->get_combined_primary_key_fields() );
3899
-		foreach( $keys_it_should_have as $key ){
3900
-			if( ! isset( $key_vals[ $key ] ) ){
3897
+	function has_all_combined_primary_key_fields($key_vals) {
3898
+		$keys_it_should_have = array_keys($this->get_combined_primary_key_fields());
3899
+		foreach ($keys_it_should_have as $key) {
3900
+			if ( ! isset($key_vals[$key])) {
3901 3901
 				return false;
3902 3902
 			}
3903 3903
 		}
@@ -3913,23 +3913,23 @@  discard block
 block discarded – undo
3913 3913
 	 * @throws EE_Error
3914 3914
 	 * @return \EE_Base_Class[]
3915 3915
 	 */
3916
-	public function get_all_copies($model_object_or_attributes_array, $query_params = array()){
3916
+	public function get_all_copies($model_object_or_attributes_array, $query_params = array()) {
3917 3917
 
3918
-		if($model_object_or_attributes_array instanceof EE_Base_Class){
3918
+		if ($model_object_or_attributes_array instanceof EE_Base_Class) {
3919 3919
 			$attributes_array = $model_object_or_attributes_array->model_field_array();
3920
-		}elseif(is_array($model_object_or_attributes_array)){
3920
+		}elseif (is_array($model_object_or_attributes_array)) {
3921 3921
 			$attributes_array = $model_object_or_attributes_array;
3922
-		}else{
3923
-			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));
3922
+		} else {
3923
+			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));
3924 3924
 		}
3925 3925
 		//even copies obviously won't have the same ID, so remove the primary key
3926 3926
 		//from the WHERE conditions for finding copies (if there is a primary key, of course)
3927
-		if($this->has_primary_key_field() && isset($attributes_array[$this->primary_key_name()])){
3927
+		if ($this->has_primary_key_field() && isset($attributes_array[$this->primary_key_name()])) {
3928 3928
 			unset($attributes_array[$this->primary_key_name()]);
3929 3929
 		}
3930
-		if(isset($query_params[0])){
3931
-			$query_params[0] = array_merge($attributes_array,$query_params);
3932
-		}else{
3930
+		if (isset($query_params[0])) {
3931
+			$query_params[0] = array_merge($attributes_array, $query_params);
3932
+		} else {
3933 3933
 			$query_params[0] = $attributes_array;
3934 3934
 		}
3935 3935
 		return $this->get_all($query_params);
@@ -3943,16 +3943,16 @@  discard block
 block discarded – undo
3943 3943
 	 * @param array $query_params
3944 3944
 	 * @return EE_Base_Class
3945 3945
 	 */
3946
-	function get_one_copy($model_object_or_attributes_array,$query_params = array()){
3947
-		if( ! is_array( $query_params ) ){
3948
-			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' );
3946
+	function get_one_copy($model_object_or_attributes_array, $query_params = array()) {
3947
+		if ( ! is_array($query_params)) {
3948
+			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');
3949 3949
 			$query_params = array();
3950 3950
 		}
3951 3951
 		$query_params['limit'] = 1;
3952
-		$copies = $this->get_all_copies($model_object_or_attributes_array,$query_params);
3953
-		if(is_array($copies)){
3952
+		$copies = $this->get_all_copies($model_object_or_attributes_array, $query_params);
3953
+		if (is_array($copies)) {
3954 3954
 			return array_shift($copies);
3955
-		}else{
3955
+		} else {
3956 3956
 			return null;
3957 3957
 		}
3958 3958
 	}
@@ -3966,10 +3966,10 @@  discard block
 block discarded – undo
3966 3966
 	 * @param int|string $id the value of the primary key to update
3967 3967
 	 * @return int number of rows updated
3968 3968
 	 */
3969
-	public function update_by_ID($fields_n_values,$id){
3969
+	public function update_by_ID($fields_n_values, $id) {
3970 3970
 		$query_params = array(0=>array($this->get_primary_key_field()->get_name() => $id),
3971 3971
 			'default_where_conditions'=>'other_models_only',);
3972
-		return $this->update($fields_n_values,$query_params);
3972
+		return $this->update($fields_n_values, $query_params);
3973 3973
 	}
3974 3974
 
3975 3975
 
@@ -3980,12 +3980,12 @@  discard block
 block discarded – undo
3980 3980
 	 * @return string an operator which can be used in SQL
3981 3981
 	 * @throws EE_Error
3982 3982
 	 */
3983
-	private function _prepare_operator_for_sql($operator_supplied){
3983
+	private function _prepare_operator_for_sql($operator_supplied) {
3984 3984
 		$sql_operator = isset($this->_valid_operators[$operator_supplied]) ? $this->_valid_operators[$operator_supplied] : null;
3985
-		if($sql_operator){
3985
+		if ($sql_operator) {
3986 3986
 			return $sql_operator;
3987
-		}else{
3988
-			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))));
3987
+		} else {
3988
+			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))));
3989 3989
 		}
3990 3990
 	}
3991 3991
 
@@ -3995,10 +3995,10 @@  discard block
 block discarded – undo
3995 3995
 	 * @param array $query_params like get_all's
3996 3996
 	 * @return string[]
3997 3997
 	 */
3998
-	public function get_all_names($query_params = array()){
3998
+	public function get_all_names($query_params = array()) {
3999 3999
 		$objs = $this->get_all($query_params);
4000 4000
 		$names = array();
4001
-		foreach($objs as $obj){
4001
+		foreach ($objs as $obj) {
4002 4002
 			$names[$obj->ID()] = $obj->name();
4003 4003
 		}
4004 4004
 		return $names;
@@ -4009,8 +4009,8 @@  discard block
 block discarded – undo
4009 4009
 	 * are no capabilities that relate to this model returns false
4010 4010
 	 * @return string|false
4011 4011
 	 */
4012
-	public function cap_slug(){
4013
-		return apply_filters( 'FHEE__EEM_Base__cap_slug', $this->_caps_slug, $this);
4012
+	public function cap_slug() {
4013
+		return apply_filters('FHEE__EEM_Base__cap_slug', $this->_caps_slug, $this);
4014 4014
 	}
4015 4015
 
4016 4016
 	/**
@@ -4022,27 +4022,27 @@  discard block
 block discarded – undo
4022 4022
 	 * @param string $context
4023 4023
 	 * @return EE_Default_Where_Conditions[] indexed by associated capability
4024 4024
 	 */
4025
-	public function cap_restrictions( $context = EEM_Base::caps_read ) {
4026
-		EEM_Base::verify_is_valid_cap_context( $context );
4025
+	public function cap_restrictions($context = EEM_Base::caps_read) {
4026
+		EEM_Base::verify_is_valid_cap_context($context);
4027 4027
 		//check if we ought to run the restriction generator first
4028
-		if( isset( $this->_cap_restriction_generators[ $context ] ) &&
4029
-				$this->_cap_restriction_generators[ $context ] instanceof EE_Restriction_Generator_Base &&
4030
-				! $this->_cap_restriction_generators[ $context ]->has_generated_cap_restrictions() ) {
4031
-			$this->_cap_restrictions[ $context ] = array_merge( $this->_cap_restrictions[ $context ],  $this->_cap_restriction_generators[ $context ]->generate_restrictions() );
4028
+		if (isset($this->_cap_restriction_generators[$context]) &&
4029
+				$this->_cap_restriction_generators[$context] instanceof EE_Restriction_Generator_Base &&
4030
+				! $this->_cap_restriction_generators[$context]->has_generated_cap_restrictions()) {
4031
+			$this->_cap_restrictions[$context] = array_merge($this->_cap_restrictions[$context], $this->_cap_restriction_generators[$context]->generate_restrictions());
4032 4032
 		}
4033 4033
 		//and make sure we've finalized the construction of each restriction
4034
-		foreach( $this->_cap_restrictions[ $context ] as $where_conditions_obj ) {
4035
-			$where_conditions_obj->_finalize_construct( $this );
4034
+		foreach ($this->_cap_restrictions[$context] as $where_conditions_obj) {
4035
+			$where_conditions_obj->_finalize_construct($this);
4036 4036
 		}
4037 4037
 
4038
-		return $this->_cap_restrictions[ $context ];
4038
+		return $this->_cap_restrictions[$context];
4039 4039
 	}
4040 4040
 
4041 4041
 	/**
4042 4042
 	 * Indicating whether or not this model thinks its a wp core model
4043 4043
 	 * @return boolean
4044 4044
 	 */
4045
-	public function is_wp_core_model(){
4045
+	public function is_wp_core_model() {
4046 4046
 		return $this->_wp_core_model;
4047 4047
 	}
4048 4048
 
@@ -4052,12 +4052,12 @@  discard block
 block discarded – undo
4052 4052
 	 * @param string $context one of EEM_Base::caps_ constants
4053 4053
 	 * @return EE_Default_Where_Conditions[] indexed by capability name
4054 4054
 	 */
4055
-	public function caps_missing( $context = EEM_Base::caps_read ) {
4055
+	public function caps_missing($context = EEM_Base::caps_read) {
4056 4056
 		$missing_caps = array();
4057
-		$cap_restrictions = $this->cap_restrictions( $context );
4058
-		foreach( $cap_restrictions as $cap => $restriction_if_no_cap ) {
4059
-			if( ! EE_Capabilities::instance()->current_user_can( $cap, $this->get_this_model_name() . '_model_applying_caps') ) {
4060
-				$missing_caps[ $cap ] = $restriction_if_no_cap;
4057
+		$cap_restrictions = $this->cap_restrictions($context);
4058
+		foreach ($cap_restrictions as $cap => $restriction_if_no_cap) {
4059
+			if ( ! EE_Capabilities::instance()->current_user_can($cap, $this->get_this_model_name().'_model_applying_caps')) {
4060
+				$missing_caps[$cap] = $restriction_if_no_cap;
4061 4061
 			}
4062 4062
 		}
4063 4063
 		return $missing_caps;
@@ -4069,7 +4069,7 @@  discard block
 block discarded – undo
4069 4069
 	 * one of 'read', 'edit', or 'delete'
4070 4070
 	 */
4071 4071
 	public function cap_contexts_to_cap_action_map() {
4072
-		return apply_filters( 'FHEE__EEM_Base__cap_contexts_to_cap_action_map', $this->_cap_contexts_to_cap_action_map, $this );
4072
+		return apply_filters('FHEE__EEM_Base__cap_contexts_to_cap_action_map', $this->_cap_contexts_to_cap_action_map, $this);
4073 4073
 	}
4074 4074
 
4075 4075
 
@@ -4080,19 +4080,19 @@  discard block
 block discarded – undo
4080 4080
 	 * @return string one of EEM_Base::cap_contexts_to_cap_action_map() values
4081 4081
 	 * @throws \EE_Error
4082 4082
 	 */
4083
-	public function cap_action_for_context( $context ) {
4083
+	public function cap_action_for_context($context) {
4084 4084
 		$mapping = $this->cap_contexts_to_cap_action_map();
4085
-		if( isset( $mapping[ $context ] ) ) {
4086
-			return $mapping[ $context ];
4085
+		if (isset($mapping[$context])) {
4086
+			return $mapping[$context];
4087 4087
 		}
4088
-		if( $action = apply_filters( 'FHEE__EEM_Base__cap_action_for_context', null, $this, $mapping, $context ) ) {
4088
+		if ($action = apply_filters('FHEE__EEM_Base__cap_action_for_context', null, $this, $mapping, $context)) {
4089 4089
 			return $action;
4090 4090
 		}
4091 4091
 		throw new EE_Error(
4092 4092
 			sprintf(
4093
-				__( 'Cannot find capability restrictions for context "%1$s", allowed values are:%2$s', 'event_espresso' ),
4093
+				__('Cannot find capability restrictions for context "%1$s", allowed values are:%2$s', 'event_espresso'),
4094 4094
 				$context,
4095
-				implode(',', array_keys( $this->cap_contexts_to_cap_action_map() ) )
4095
+				implode(',', array_keys($this->cap_contexts_to_cap_action_map()))
4096 4096
 			)
4097 4097
 		);
4098 4098
 
@@ -4103,7 +4103,7 @@  discard block
 block discarded – undo
4103 4103
 	 * @return array
4104 4104
 	 */
4105 4105
 	static public function valid_cap_contexts() {
4106
-		return apply_filters( 'FHEE__EEM_Base__valid_cap_contexts', array(
4106
+		return apply_filters('FHEE__EEM_Base__valid_cap_contexts', array(
4107 4107
 			self::caps_read,
4108 4108
 			self::caps_read_admin,
4109 4109
 			self::caps_edit,
@@ -4119,17 +4119,17 @@  discard block
 block discarded – undo
4119 4119
 	 * @return bool
4120 4120
 	 * @throws \EE_Error
4121 4121
 	 */
4122
-	static public function verify_is_valid_cap_context( $context ) {
4122
+	static public function verify_is_valid_cap_context($context) {
4123 4123
 		$valid_cap_contexts = EEM_Base::valid_cap_contexts();
4124
-		if( in_array( $context, $valid_cap_contexts ) ) {
4124
+		if (in_array($context, $valid_cap_contexts)) {
4125 4125
 			return true;
4126
-		}else{
4126
+		} else {
4127 4127
 			throw new EE_Error(
4128 4128
 				sprintf(
4129
-					__( 'Context "%1$s" passed into model "%2$s" is not a valid context. They are: %3$s', 'event_espresso' ),
4129
+					__('Context "%1$s" passed into model "%2$s" is not a valid context. They are: %3$s', 'event_espresso'),
4130 4130
 					$context,
4131
-					'EEM_Base' ,
4132
-					implode(',', $valid_cap_contexts )
4131
+					'EEM_Base',
4132
+					implode(',', $valid_cap_contexts)
4133 4133
 				)
4134 4134
 			);
4135 4135
 		}
Please login to merge, or discard this patch.
Doc Comments   +16 added lines, -13 removed lines patch added patch discarded remove patch
@@ -744,7 +744,7 @@  discard block
 block discarded – undo
744 744
 	 * Returns the name of the field's name that points to the WP_User table
745 745
 	 *  on this model (or follows the _model_chain_to_wp_user and uses that model's
746 746
 	 * foreign key to the WP_User table)
747
-	 * @return string|boolean string on success, boolean false when there is no
747
+	 * @return string|false string on success, boolean false when there is no
748 748
 	 * foreign key to the WP_User table
749 749
 	 */
750 750
 	function wp_user_field_name() {
@@ -840,6 +840,7 @@  discard block
 block discarded – undo
840 840
 	 * If you would like to use these custom selections in WHERE, GROUP_BY, or HAVING clauses, you must instead provide an array.
841 841
 	 * Array keys are the aliases used to refer to this selection, and values are to be numerically-indexed arrays, where 0 is the selection
842 842
 	 * and 1 is the data type. Eg, array('count'=>array('COUNT(REG_ID)','%d'))
843
+	 * @param string $columns_to_select
843 844
 	 * @return stdClass[] like results of $wpdb->get_results($sql,OBJECT), (ie, output type is OBJECT)
844 845
 	 */
845 846
 	public function  get_all_wpdb_results($query_params = array(), $output = ARRAY_A, $columns_to_select = null){
@@ -1333,7 +1334,7 @@  discard block
 block discarded – undo
1333 1334
 	 * Deletes a single row from the DB given the model object's primary key value. (eg, EE_Attendee->ID()'s value).
1334 1335
 	 * Wrapper for EEM_Base::delete()
1335 1336
 	 * @param mixed $id
1336
-	 * @return boolean whether the row got deleted or not
1337
+	 * @return integer whether the row got deleted or not
1337 1338
 	 */
1338 1339
 	public function delete_by_ID( $id ){
1339 1340
 		return $this->delete( array(
@@ -1453,7 +1454,7 @@  discard block
 block discarded – undo
1453 1454
 
1454 1455
 	/**
1455 1456
 	 * This sets up our delete where sql and accounts for if we have secondary tables that will have rows deleted as well.
1456
-	 * @param  array  $objects_for_deletion This should be the values returned by $this->_get_all_wpdb_results()
1457
+	 * @param  stdClass[]  $objects_for_deletion This should be the values returned by $this->_get_all_wpdb_results()
1457 1458
 	 * @param boolean $allow_blocking       if TRUE, matched objects will only be deleted if there is no related model info
1458 1459
 	 * that blocks it (ie, there' sno other data that depends on this data); if false, deletes regardless of other objects
1459 1460
 	 * which may depend on it. Its generally advisable to always leave this as TRUE, otherwise you could easily corrupt your DB
@@ -1666,7 +1667,6 @@  discard block
 block discarded – undo
1666 1667
 	 * 'hasAndBelongsToMany' relationships: checks that there isn't already an entry in the join table, and adds one.
1667 1668
 	 * If one of the model Objects has not yet been saved to the database, it is saved before adding the entry in the join table
1668 1669
 	 *
1669
-	 * @param EE_Base_Class/int $thisModelObject
1670 1670
 	 * @param EE_Base_Class/int $id_or_obj EE_base_Class or ID of other Model Object
1671 1671
 	 * @param string $relationName, key in EEM_Base::_relations
1672 1672
 	 * an attendee to a group, you also want to specify which role they will have in that group. So you would use this parameter to specify array('role-column-name'=>'role-id')
@@ -1688,8 +1688,8 @@  discard block
 block discarded – undo
1688 1688
 	 *
1689 1689
 	 * 'hasAndBelongsToMany' relationships:removes any existing entry in the join table between the two models.
1690 1690
 	 *
1691
-	 * @param EE_Base_Class/int $id_or_obj
1692
-	 * @param EE_Base_Class/int $other_model_id_or_obj EE_Base_Class or ID of other Model Object
1691
+	 * @param EE_CPT_Base $id_or_obj
1692
+	 * @param EE_Term_Taxonomy $other_model_id_or_obj EE_Base_Class or ID of other Model Object
1693 1693
 	 * @param string $relationName key in EEM_Base::_relations
1694 1694
 	 * @return boolean of success
1695 1695
 	 * @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.
@@ -1765,7 +1765,7 @@  discard block
 block discarded – undo
1765 1765
 	/**
1766 1766
 	 * Instead of getting the related model objects, simply counts them. Ignores default_where_conditions by default,
1767 1767
 	 * unless otherwise specified in the $query_params
1768
-	 * @param int/EE_Base_Class $id_or_obj
1768
+	 * @param EE_Event $id_or_obj
1769 1769
 	 * @param string $model_name like 'Event', or 'Registration'
1770 1770
 	 * @param array $query_params like EEM_Base::get_all's
1771 1771
 	 * @param string $field_to_count name of field to count by. By default, uses primary key
@@ -2153,7 +2153,7 @@  discard block
 block discarded – undo
2153 2153
 	/**
2154 2154
 	 * Finds all the fields that correspond to the given table
2155 2155
 	 * @param string $table_alias, array key in EEM_Base::_tables
2156
-	 * @return EE_Model_Field_Base[]
2156
+	 * @return EE_Model_Field_Base
2157 2157
 	 */
2158 2158
 	function _get_fields_for_table($table_alias){
2159 2159
 		return $this->_fields[$table_alias];
@@ -3215,8 +3215,8 @@  discard block
 block discarded – undo
3215 3215
 	/**
3216 3216
 	 * gets the field object of type 'primary_key' from the fieldsSettings attribute.
3217 3217
 	 * Eg, on EE_Answer that would be ANS_ID field object
3218
-	 * @param $field_obj
3219
-	 * @return EE_Model_Field_Base
3218
+	 * @param EE_Model_Field_Base $field_obj
3219
+	 * @return boolean
3220 3220
 	 */
3221 3221
 	public function is_primary_key_field( $field_obj ){
3222 3222
 		return $field_obj instanceof EE_Primary_Key_Field_Base ? TRUE : FALSE;
@@ -3310,7 +3310,7 @@  discard block
 block discarded – undo
3310 3310
 	 * Gets the actual table for the table alias
3311 3311
 	 * @param string $table_alias eg Event, Event_Meta, Registration, Transaction, but maybe
3312 3312
 	 * a table alias with a model chain prefix, like 'Venue__Event_Venue___Event_Meta'. Either one works
3313
-	 * @return EE_Table_Base
3313
+	 * @return string
3314 3314
 	 */
3315 3315
 	function get_table_for_alias($table_alias){
3316 3316
 		$table_alias_sans_model_relation_chain_prefix = EE_Model_Parser::remove_table_alias_model_relation_chain_prefix($table_alias);
@@ -3410,7 +3410,7 @@  discard block
 block discarded – undo
3410 3410
 	 * The purpose of this method is to allow us to create a model object that is not in the db that holds default values.
3411 3411
 	 * A typical example of where this is used is when creating a new item and the initial load of a form.  We dont' necessarily want to test for if the object is present but just assume it is BUT load the defaults from the object (as set in the model_field!).
3412 3412
 	 *
3413
-	 * @return EE_Base_Class single EE_Base_Class object with default values for the properties.
3413
+	 * @return boolean single EE_Base_Class object with default values for the properties.
3414 3414
 	 */
3415 3415
 	public function create_default_object() {
3416 3416
 
@@ -3580,6 +3580,9 @@  discard block
 block discarded – undo
3580 3580
 		return $this_model_fields_n_values;
3581 3581
 	}
3582 3582
 
3583
+	/**
3584
+	 * @param string $cols_n_values
3585
+	 */
3583 3586
 	protected function _get_column_value_with_table_alias_or_not( $cols_n_values, $qualified_column, $regular_column ){
3584 3587
 		//ask the field what it think it's table_name.column_name should be, and call it the "qualified column"
3585 3588
 		//does the field on the model relate to this column retrieved from the db?
@@ -3815,7 +3818,7 @@  discard block
 block discarded – undo
3815 3818
 	}
3816 3819
 	/**
3817 3820
 	 * Read comments for assume_values_already_prepared_by_model_object()
3818
-	 * @return int
3821
+	 * @return boolean
3819 3822
 	 */
3820 3823
 	public function get_assumption_concerning_values_already_prepared_by_model_object(){
3821 3824
 		return $this->_values_already_prepared_by_model_object;
Please login to merge, or discard this patch.
Braces   +129 added lines, -119 removed lines patch added patch discarded remove patch
@@ -504,7 +504,7 @@  discard block
 block discarded – undo
504 504
 		if( isset( $this->_cap_restriction_generators[ $context ] ) &&
505 505
 				$this->_cap_restriction_generators[ $context ] instanceof EE_Restriction_Generator_Base ) {
506 506
 			return $this->_cap_restriction_generators[ $context ]->generate_restrictions();
507
-		}else{
507
+		} else{
508 508
 			return array();
509 509
 		}
510 510
 }
@@ -578,8 +578,9 @@  discard block
 block discarded – undo
578 578
 	 * @return array
579 579
 	 */
580 580
 	 public function status_array( $translated = FALSE ) {
581
-	 	if ( !array_key_exists('Status', $this->_model_relations ) )
582
-	 		return array();
581
+	 	if ( !array_key_exists('Status', $this->_model_relations ) ) {
582
+	 		 		return array();
583
+	 	}
583 584
 	 	$model_name = $this->get_this_model_name();
584 585
 	 	$status_type = str_replace(' ', '_', strtolower( str_replace('_', ' ', $model_name) ) );
585 586
 	 	$stati = EEM_Status::instance()->get_all(array(array('STS_type' => $status_type) ) );
@@ -758,13 +759,13 @@  discard block
 block discarded – undo
758 759
 				$last_model_name = end( $models_to_follow_to_wp_users );
759 760
 				$model_with_fk_to_wp_users = EE_Registry::instance()->load_model( $last_model_name );
760 761
 				$model_chain_to_wp_user = $this->_model_chain_to_wp_user . '.';
761
-			}else{
762
+			} else{
762 763
 				$model_with_fk_to_wp_users = $this;
763 764
 				$model_chain_to_wp_user = '';
764 765
 			}
765 766
 			$wp_user_field = $model_with_fk_to_wp_users->get_foreign_key_to( 'WP_User' );
766 767
 			return $model_chain_to_wp_user . $wp_user_field->get_name();
767
-		}catch( EE_Error $e ) {
768
+		} catch( EE_Error $e ) {
768 769
 			return false;
769 770
 		}
770 771
 	}
@@ -792,11 +793,11 @@  discard block
 block discarded – undo
792 793
 	public function is_owned() {
793 794
 		if( $this->model_chain_to_wp_user() ){
794 795
 			return true;
795
-		}else{
796
+		} else{
796 797
 			try{
797 798
 				$this->get_foreign_key_to( 'WP_User' );
798 799
 				return true;
799
-			}catch( EE_Error $e ){
800
+			} catch( EE_Error $e ){
800 801
 				return false;
801 802
 			}
802 803
 		}
@@ -819,9 +820,9 @@  discard block
 block discarded – undo
819 820
 		//remember the custom selections, if any
820 821
 		if(is_array($columns_to_select)){
821 822
 			$this->_custom_selections = $columns_to_select;
822
-		}elseif(is_string($columns_to_select)){
823
+		} elseif(is_string($columns_to_select)){
823 824
 			$this->_custom_selections = array($this->_custom_selections);
824
-		}else{
825
+		} else{
825 826
 			$this->_custom_selections = array();
826 827
 		}
827 828
 
@@ -872,7 +873,7 @@  discard block
 block discarded – undo
872 873
 				$select_sql_array[] = "{$selection_and_datatype[0]} AS $alias";
873 874
 			}
874 875
 			$columns_to_select_string = implode(", ",$select_sql_array);
875
-		}else{
876
+		} else{
876 877
 			$columns_to_select_string = $columns_to_select;
877 878
 		}
878 879
 		return $columns_to_select_string;
@@ -900,10 +901,10 @@  discard block
 block discarded – undo
900 901
 	function get_one_by_ID($id){
901 902
 		if( $this->get_from_entity_map( $id ) ){
902 903
 			return $this->get_from_entity_map( $id );
903
-		}elseif( $this->has_primary_key_field ( ) ) {
904
+		} elseif( $this->has_primary_key_field ( ) ) {
904 905
 			$primary_key_name = $this->get_primary_key_field()->get_name();
905 906
 			return $this->get_one(array(array($primary_key_name => $id)));
906
-		}else{
907
+		} else{
907 908
 			//no primary key, so the $id must be from the get_index_primary_key_string()
908 909
 			return $this->get_one( array( $this->parse_index_primary_key_string( $id ) ) );
909 910
 		}
@@ -925,7 +926,7 @@  discard block
 block discarded – undo
925 926
 		$items = $this->get_all($query_params);
926 927
 		if(empty($items)){
927 928
 			return null;
928
-		}else{
929
+		} else{
929 930
 			return array_shift($items);
930 931
 		}
931 932
 	}
@@ -1177,7 +1178,7 @@  discard block
 block discarded – undo
1177 1178
 				//get the model object's PK, as we'll want this if we need to insert a row into secondary tables
1178 1179
 				if( $this->has_primary_key_field() ){
1179 1180
 					$main_table_pk_value = $wpdb_result[ $this->get_primary_key_field()->get_qualified_column() ];
1180
-				}else{
1181
+				} else{
1181 1182
 					//if there's no primary key, we basically can't support having a 2nd table on the model (we could but it woudl be lots of work)
1182 1183
 					$main_table_pk_value = null;
1183 1184
 				}
@@ -1216,7 +1217,7 @@  discard block
 block discarded – undo
1216 1217
 		if( $keep_model_objs_in_sync && ! $this->_values_already_prepared_by_model_object ){
1217 1218
 			if( $this->has_primary_key_field() ){
1218 1219
 				$model_objs_affected_ids = $this->get_col( $query_params );
1219
-			}else{
1220
+			} else{
1220 1221
 				//we need to select a bunch of columns and then combine them into the the "index primary key string"s
1221 1222
 				$models_affected_key_columns = $this->_get_all_wpdb_results($query_params, ARRAY_A );
1222 1223
 				$model_objs_affected_ids = array();
@@ -1276,9 +1277,9 @@  discard block
 block discarded – undo
1276 1277
 
1277 1278
 		if( $field_to_select ){
1278 1279
 			$field = $this->field_settings_for( $field_to_select );
1279
-		}elseif( $this->has_primary_key_field ( ) ){
1280
+		} elseif( $this->has_primary_key_field ( ) ){
1280 1281
 			$field = $this->get_primary_key_field();
1281
-		}else{
1282
+		} else{
1282 1283
 			//no primary key, just grab the first column
1283 1284
 			$field = reset( $this->field_settings());
1284 1285
 		}
@@ -1302,7 +1303,7 @@  discard block
 block discarded – undo
1302 1303
 		$col = $this->get_col( $query_params, $field_to_select );
1303 1304
 		if( ! empty( $col ) ) {
1304 1305
 			return reset( $col );
1305
-		}else{
1306
+		} else{
1306 1307
 			return NULL;
1307 1308
 		}
1308 1309
 	}
@@ -1385,7 +1386,7 @@  discard block
 block discarded – undo
1385 1386
 
1386 1387
 			//		/echo "delete sql:$SQL";
1387 1388
 			$rows_deleted = $this->_do_wpdb_query( 'query', array( $SQL ) );
1388
-		}else{
1389
+		} else{
1389 1390
 			$rows_deleted = 0;
1390 1391
 		}
1391 1392
 
@@ -1427,7 +1428,7 @@  discard block
 block discarded – undo
1427 1428
 		//first, if $ignore_this_model_obj was supplied, get its model
1428 1429
 		if($ignore_this_model_obj && $ignore_this_model_obj instanceof EE_Base_Class){
1429 1430
 			$ignored_model = $ignore_this_model_obj->get_model();
1430
-		}else{
1431
+		} else{
1431 1432
 			$ignored_model = null;
1432 1433
 		}
1433 1434
 		//now check all the relations of $this_model_obj_or_id and see if there
@@ -1440,7 +1441,7 @@  discard block
 block discarded – undo
1440 1441
 				if($ignored_model && $relation_name == $ignored_model->get_this_model_name()){
1441 1442
 					$related_model_objects = $relation_obj->get_all_related($this_model_obj_or_id,array(
1442 1443
 					array($ignored_model->get_primary_key_field()->get_name() => array('!=',$ignore_this_model_obj->ID()))));
1443
-				}else{
1444
+				} else{
1444 1445
 					$related_model_objects = $relation_obj->get_all_related($this_model_obj_or_id);
1445 1446
 				}
1446 1447
 
@@ -1477,24 +1478,28 @@  discard block
 block discarded – undo
1477 1478
 				}
1478 1479
 
1479 1480
 				//primary table deletes
1480
-				if ( isset( $delete_object[$primary_table->get_fully_qualified_pk_column()] ) )
1481
-					$deletes[$primary_table->get_fully_qualified_pk_column()][] = $delete_object[$primary_table->get_fully_qualified_pk_column()];
1481
+				if ( isset( $delete_object[$primary_table->get_fully_qualified_pk_column()] ) ) {
1482
+									$deletes[$primary_table->get_fully_qualified_pk_column()][] = $delete_object[$primary_table->get_fully_qualified_pk_column()];
1483
+				}
1482 1484
 
1483 1485
 				//other tables
1484 1486
 				if ( !empty( $other_tables ) ) {
1485 1487
 					foreach ( $other_tables as $ot ) {
1486 1488
 
1487 1489
 						//first check if we've got the foreign key column here.
1488
-						if ( isset( $delete_object[$ot->get_fully_qualified_fk_column()] ) )
1489
-							$deletes[$ot->get_fully_qualified_pk_column()][] = $delete_object[$ot->get_fully_qualified_fk_column()];
1490
+						if ( isset( $delete_object[$ot->get_fully_qualified_fk_column()] ) ) {
1491
+													$deletes[$ot->get_fully_qualified_pk_column()][] = $delete_object[$ot->get_fully_qualified_fk_column()];
1492
+						}
1490 1493
 
1491 1494
 						//wait! it's entirely possible that we'll have a the primary key for this table in here if it's a foreign key for one of the other secondary tables
1492
-						if ( isset( $delete_object[$ot->get_fully_qualified_pk_column()] ) )
1493
-							$deletes[$ot->get_fully_qualified_pk_column()][] = $delete_object[$ot->get_fully_qualified_pk_column()];
1495
+						if ( isset( $delete_object[$ot->get_fully_qualified_pk_column()] ) ) {
1496
+													$deletes[$ot->get_fully_qualified_pk_column()][] = $delete_object[$ot->get_fully_qualified_pk_column()];
1497
+						}
1494 1498
 
1495 1499
 						//finally, it is possible that the fk for this table is found in the fully qualified pk column for the fk table, so let's see if that's there!
1496
-						if ( isset( $delete_object[$ot->get_fully_qualified_pk_on_fk_table()]) )
1497
-							$deletes[$ot->get_fully_qualified_pk_column()][] = $delete_object[$ot->get_fully_qualified_pk_column()];
1500
+						if ( isset( $delete_object[$ot->get_fully_qualified_pk_on_fk_table()]) ) {
1501
+													$deletes[$ot->get_fully_qualified_pk_column()][] = $delete_object[$ot->get_fully_qualified_pk_column()];
1502
+						}
1498 1503
 					}
1499 1504
 				}
1500 1505
 			}
@@ -1507,7 +1512,7 @@  discard block
 block discarded – undo
1507 1512
 			}
1508 1513
 
1509 1514
 			return !empty($query) ? implode(' AND ', $query ) : '';
1510
-		}elseif(count($this->get_combined_primary_key_fields()) > 1){
1515
+		} elseif(count($this->get_combined_primary_key_fields()) > 1){
1511 1516
 			$ways_to_identify_a_row = array();
1512 1517
 			$fields = $this->get_combined_primary_key_fields();
1513 1518
 			//note: because there' sno primary key, that means nothing else  can be pointing to this model, right?
@@ -1519,7 +1524,7 @@  discard block
 block discarded – undo
1519 1524
 				$ways_to_identify_a_row[] = "(".implode(" AND ",$values_for_each_cpk_for_a_row).")";
1520 1525
 			}
1521 1526
 			return implode(" OR ",$ways_to_identify_a_row);
1522
-		}else{
1527
+		} else{
1523 1528
 			//so there's no primary key and no combined key...
1524 1529
 			//sorry, can't help you
1525 1530
 			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)));
@@ -1541,10 +1546,10 @@  discard block
 block discarded – undo
1541 1546
 		if($field_to_count){
1542 1547
 			$field_obj = $this->field_settings_for($field_to_count);
1543 1548
 			$column_to_count = $field_obj->get_qualified_column();
1544
-		}elseif($this->has_primary_key_field ()){
1549
+		} elseif($this->has_primary_key_field ()){
1545 1550
 			$pk_field_obj = $this->get_primary_key_field();
1546 1551
 			$column_to_count = $pk_field_obj->get_qualified_column();
1547
-		}else{//there's no primary key
1552
+		} else{//there's no primary key
1548 1553
 			$column_to_count = '*';
1549 1554
 		}
1550 1555
 
@@ -1566,7 +1571,7 @@  discard block
 block discarded – undo
1566 1571
 		if($field_to_sum){
1567 1572
 			$field_obj = $this->field_settings_for($field_to_sum);
1568 1573
 
1569
-		}else{
1574
+		} else{
1570 1575
 			$field_obj = $this->get_primary_key_field();
1571 1576
 		}
1572 1577
 		$column_to_count = $field_obj->get_qualified_column();
@@ -1575,7 +1580,7 @@  discard block
 block discarded – undo
1575 1580
 		$return_value = $this->_do_wpdb_query('get_var',array( $SQL ) );
1576 1581
 		if($field_obj->get_wpdb_data_type() == '%d' || $field_obj->get_wpdb_data_type() == '%s' ){
1577 1582
 			return (int)$return_value;
1578
-		}else{//must be %f
1583
+		} else{//must be %f
1579 1584
 			return (float)$return_value;
1580 1585
 		}
1581 1586
 	}
@@ -1614,10 +1619,10 @@  discard block
 block discarded – undo
1614 1619
 			$wpdb->show_errors( $old_show_errors_value );
1615 1620
 			if( ! empty( $wpdb->last_error ) ){
1616 1621
 				throw new EE_Error( sprintf( __( 'WPDB Error: "%s"', 'event_espresso' ), $wpdb->last_error ) );
1617
-			}elseif( $result === false ){
1622
+			} elseif( $result === false ){
1618 1623
 				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 ) ) );
1619 1624
 			}
1620
-		}elseif( $result === false ) {
1625
+		} elseif( $result === false ) {
1621 1626
 			EE_Error::add_error( sprintf( __( 'A database error has occurred. Turn on WP_DEBUG for more information.', 'event_espresso' )), __FILE__, __FUNCTION__, __LINE__);
1622 1627
 		}
1623 1628
 		return $result;
@@ -1831,7 +1836,7 @@  discard block
 block discarded – undo
1831 1836
 		$results = $this->get_all_related($id_or_obj,$other_model_name,$query_params);
1832 1837
 		if( $results ){
1833 1838
 			return array_shift($results);
1834
-		}else{
1839
+		} else{
1835 1840
 			return null;
1836 1841
 		}
1837 1842
 
@@ -1902,7 +1907,7 @@  discard block
 block discarded – undo
1902 1907
 			 */
1903 1908
 			do_action( 'AHEE__EEM_Base__insert__end', $this, $field_n_values, $new_id );
1904 1909
 			return $new_id;
1905
-		}else{
1910
+		} else{
1906 1911
 			return FALSE;
1907 1912
 		}
1908 1913
 	}
@@ -1943,9 +1948,9 @@  discard block
 block discarded – undo
1943 1948
 	public function get_one_conflicting($obj_or_fields_array, $include_primary_key = true ){
1944 1949
 		if($obj_or_fields_array instanceof EE_Base_Class){
1945 1950
 			$fields_n_values = $obj_or_fields_array->model_field_array();
1946
-		}elseif( is_array($obj_or_fields_array)){
1951
+		} elseif( is_array($obj_or_fields_array)){
1947 1952
 			$fields_n_values = $obj_or_fields_array;
1948
-		}else{
1953
+		} else{
1949 1954
 			throw new EE_Error(sprintf(__("%s get_all_conflicting should be called with a model object or an array of field names and values, you provided %d", "event_espresso"),get_class($this),$obj_or_fields_array));
1950 1955
 		}
1951 1956
 		$query_params = array();
@@ -1961,7 +1966,7 @@  discard block
 block discarded – undo
1961 1966
 		//if there is nothing to base this search on, then we shouldn't find anything
1962 1967
 		if( empty( $query_params ) ){
1963 1968
 			return array();
1964
-		}else{
1969
+		} else{
1965 1970
 			return $this->get_one($query_params);
1966 1971
 		}
1967 1972
 	}
@@ -2034,12 +2039,12 @@  discard block
 block discarded – undo
2034 2039
 		if($this->has_primary_key_field()){
2035 2040
 			if($this->get_primary_key_field()->is_auto_increment()){
2036 2041
 				return $wpdb->insert_id;
2037
-			}else{
2042
+			} else{
2038 2043
 				//it's not an auto-increment primary key, so
2039 2044
 				//it must have been supplied
2040 2045
 				return $fields_n_values[$this->get_primary_key_field()->get_name()];
2041 2046
 			}
2042
-		}else{
2047
+		} else{
2043 2048
 			//we can't return a  primary key because there is none. instead return
2044 2049
 			//a unique string indicating this model
2045 2050
 			return $this->get_index_primary_key_string($fields_n_values);
@@ -2086,7 +2091,7 @@  discard block
 block discarded – undo
2086 2091
 					//leave the value alone
2087 2092
 			}
2088 2093
 			return $value;
2089
-		}else{
2094
+		} else{
2090 2095
 			return $value;
2091 2096
 		}
2092 2097
 	}
@@ -2179,7 +2184,7 @@  discard block
 block discarded – undo
2179 2184
 		if(array_key_exists('group_by', $query_params)){
2180 2185
 			if(is_array($query_params['group_by'])){
2181 2186
 				$this->_extract_related_models_from_sub_params_array_values($query_params['group_by'],$query_info_carrier,'group_by');
2182
-			}elseif( ! empty ( $query_params['group_by'] )){
2187
+			} elseif( ! empty ( $query_params['group_by'] )){
2183 2188
 				$this->_extract_related_model_info_from_query_param( $query_params['group_by'],$query_info_carrier,'group_by');
2184 2189
 			}
2185 2190
 		}
@@ -2187,10 +2192,11 @@  discard block
 block discarded – undo
2187 2192
 			$this->_extract_related_models_from_sub_params_array_keys($query_params[0], $query_info_carrier,'having');
2188 2193
 		}
2189 2194
 		if(array_key_exists('order_by', $query_params)){
2190
-			if ( is_array( $query_params['order_by'] ) )
2191
-				$this->_extract_related_models_from_sub_params_array_keys($query_params['order_by'],$query_info_carrier,'order_by');
2192
-			elseif( ! empty( $query_params['order_by'] ))
2193
-				$this->_extract_related_model_info_from_query_param( $query_params['order_by'], $query_info_carrier,'order_by');
2195
+			if ( is_array( $query_params['order_by'] ) ) {
2196
+							$this->_extract_related_models_from_sub_params_array_keys($query_params['order_by'],$query_info_carrier,'order_by');
2197
+			} elseif( ! empty( $query_params['order_by'] )) {
2198
+							$this->_extract_related_model_info_from_query_param( $query_params['order_by'], $query_info_carrier,'order_by');
2199
+			}
2194 2200
 		}
2195 2201
 		if(array_key_exists('force_join', $query_params)){
2196 2202
 			$this->_extract_related_models_from_sub_params_array_values($query_params['force_join'],$query_info_carrier,'force_join');
@@ -2222,10 +2228,10 @@  discard block
 block discarded – undo
2222 2228
 					if (! is_array($possibly_array_of_params)){
2223 2229
 						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"),
2224 2230
 							$param,$possibly_array_of_params));
2225
-					}else{
2231
+					} else{
2226 2232
 						$this->_extract_related_models_from_sub_params_array_keys($possibly_array_of_params, $model_query_info_carrier,$query_param_type);
2227 2233
 					}
2228
-				}elseif($query_param_type === 0 //ie WHERE
2234
+				} elseif($query_param_type === 0 //ie WHERE
2229 2235
 						&& is_array($possibly_array_of_params)
2230 2236
 						&& isset($possibly_array_of_params[2])
2231 2237
 						&& $possibly_array_of_params[2] == true){
@@ -2281,7 +2287,7 @@  discard block
 block discarded – undo
2281 2287
 	function _create_model_query_info_carrier($query_params){
2282 2288
 		if( isset( $query_params[0] ) ) {
2283 2289
 			$where_query_params = $query_params[0];
2284
-		}else{
2290
+		} else{
2285 2291
 			$where_query_params = array();
2286 2292
 		}
2287 2293
 		//first check if we should alter the query to account for caps or not
@@ -2303,7 +2309,7 @@  discard block
 block discarded – undo
2303 2309
 		}
2304 2310
 		if( array_key_exists( 'default_where_conditions',$query_params) && ! empty( $query_params['default_where_conditions'] )){
2305 2311
 			$use_default_where_conditions = $query_params['default_where_conditions'];
2306
-		}else{
2312
+		} else{
2307 2313
 			$use_default_where_conditions = 'all';
2308 2314
 		}
2309 2315
 		$where_query_params = array_merge($this->_get_default_where_conditions_for_models_in_query($query_object,$use_default_where_conditions,$where_query_params), $where_query_params );
@@ -2326,7 +2332,7 @@  discard block
 block discarded – undo
2326 2332
 				}
2327 2333
 				//they passed us an array for the limit. Assume it's like array(50,25), meaning offset by 50, and get 25
2328 2334
 				$query_object->set_limit_sql(" LIMIT ".$query_params['limit'][0].",".$query_params['limit'][1]);
2329
-			}elseif( ! empty ( $query_params['limit'] )){
2335
+			} elseif( ! empty ( $query_params['limit'] )){
2330 2336
 				$query_object->set_limit_sql((" LIMIT ".$query_params['limit']));
2331 2337
 			}
2332 2338
 		}
@@ -2348,11 +2354,11 @@  discard block
 block discarded – undo
2348 2354
 					$order_array[] = $this->_deduce_column_name_from_query_param($field_name_to_order_by).SP.$order;
2349 2355
 				}
2350 2356
 				$query_object->set_order_by_sql(" ORDER BY ".implode(",",$order_array));
2351
-			}elseif( ! empty ( $query_params['order_by'] )){
2357
+			} elseif( ! empty ( $query_params['order_by'] )){
2352 2358
 				$this->_extract_related_model_info_from_query_param($query_params['order_by'],$query_object,'order',$query_params['order_by']);
2353 2359
 				if(isset($query_params['order'])){
2354 2360
 					$order = $this->_extract_order($query_params['order']);
2355
-				}else{
2361
+				} else{
2356 2362
 					$order = 'DESC';
2357 2363
 				}
2358 2364
 				$query_object->set_order_by_sql(" ORDER BY ".$this->_deduce_column_name_from_query_param($query_params['order_by']).SP.$order);
@@ -2375,7 +2381,7 @@  discard block
 block discarded – undo
2375 2381
 					$group_by_array[] = $this->_deduce_column_name_from_query_param($field_name_to_group_by);
2376 2382
 				}
2377 2383
 				$query_object->set_group_by_sql(" GROUP BY ".implode(", ",$group_by_array));
2378
-			}elseif( ! empty ( $query_params['group_by'] )){
2384
+			} elseif( ! empty ( $query_params['group_by'] )){
2379 2385
 				$query_object->set_group_by_sql(" GROUP BY ".$this->_deduce_column_name_from_query_param($query_params['group_by']));
2380 2386
 			}
2381 2387
 		}
@@ -2399,8 +2405,9 @@  discard block
 block discarded – undo
2399 2405
 			}
2400 2406
 		}
2401 2407
 		$main_model_join_sql = $query_object->get_main_model_join_sql();
2402
-		if ( empty( $main_model_join_sql ) )
2403
-			$query_object->set_main_model_join_sql($this->_construct_internal_join());
2408
+		if ( empty( $main_model_join_sql ) ) {
2409
+					$query_object->set_main_model_join_sql($this->_construct_internal_join());
2410
+		}
2404 2411
 		return $query_object;
2405 2412
 	}
2406 2413
 
@@ -2433,7 +2440,7 @@  discard block
 block discarded – undo
2433 2440
 	private function _extract_order($should_be_order_string){
2434 2441
 		if(in_array($should_be_order_string, $this->_allowed_order_values)){
2435 2442
 			return $should_be_order_string;
2436
-		}else{
2443
+		} else{
2437 2444
 			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));
2438 2445
 		}
2439 2446
 	}
@@ -2459,7 +2466,7 @@  discard block
 block discarded – undo
2459 2466
 		}
2460 2467
 		if( in_array($use_default_where_conditions, array('all','this_model_only')) ){
2461 2468
 			$universal_query_params = $this->_get_default_where_conditions();
2462
-		}else{
2469
+		} else{
2463 2470
 			$universal_query_params = array();
2464 2471
 		}
2465 2472
 
@@ -2499,14 +2506,14 @@  discard block
 block discarded – undo
2499 2506
 		foreach($default_where_conditions as $key => $val){
2500 2507
 			if( isset($provided_where_conditions[$key])){
2501 2508
 				$none_overridden = false;
2502
-			}else{
2509
+			} else{
2503 2510
 				$null_friendly_where_conditions[$or_condition_key_for_defaults]['AND'][$key] = $val;
2504 2511
 			}
2505 2512
 		}
2506 2513
 		if( $none_overridden && $default_where_conditions){
2507 2514
 			if($model->has_primary_key_field()){
2508 2515
 				$null_friendly_where_conditions[$or_condition_key_for_defaults][$model_relation_path.".".$model->primary_key_name()] = array('IS NULL');
2509
-			}else{
2516
+			} else{
2510 2517
 				//@todo NO PK, use other defaults
2511 2518
 			}
2512 2519
 		}
@@ -2522,8 +2529,9 @@  discard block
 block discarded – undo
2522 2529
 	 * @return array like EEM_Base::get_all's $query_params[0] (where conditions)
2523 2530
 	 */
2524 2531
 	private function _get_default_where_conditions($model_relation_path = null){
2525
-		if ( $this->_ignore_where_strategy )
2526
-			return array();
2532
+		if ( $this->_ignore_where_strategy ) {
2533
+					return array();
2534
+		}
2527 2535
 
2528 2536
 		return $this->_default_where_conditions_strategy->get_default_where_conditions($model_relation_path);
2529 2537
 	}
@@ -2597,7 +2605,7 @@  discard block
 block discarded – undo
2597 2605
 		if(array_key_exists($query_param,$this_model_fields)){
2598 2606
 			if($allow_fields){
2599 2607
 				return;
2600
-			}else{
2608
+			} else{
2601 2609
 				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"),
2602 2610
 						$query_param,get_class($this),$query_param_type,$original_query_param));
2603 2611
 			}
@@ -2606,7 +2614,7 @@  discard block
 block discarded – undo
2606 2614
 		elseif(in_array($query_param, $this->_logic_query_param_keys, TRUE)){
2607 2615
 			if($allow_logic_query_params){
2608 2616
 				return;
2609
-			}else{
2617
+			} else{
2610 2618
 				throw new EE_Error(
2611 2619
 					sprintf(
2612 2620
 						__( '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' ),
@@ -2636,12 +2644,12 @@  discard block
 block discarded – undo
2636 2644
 					//we should actually end in a field name, not a model like this!
2637 2645
 					throw new EE_Error(sprintf(__("Query param '%s' (of type %s on model %s) shouldn't end on a period (.) ", "event_espresso"),
2638 2646
 					$query_param,$query_param_type,get_class($this),$valid_related_model_name));
2639
-				}else{
2647
+				} else{
2640 2648
 					$related_model_obj = $this->get_related_model_obj($valid_related_model_name);
2641 2649
 					$related_model_obj->_extract_related_model_info_from_query_param($query_param, $passed_in_query_info, $query_param_type, $original_query_param);
2642 2650
 					return;
2643 2651
 				}
2644
-			}elseif($query_param == $valid_related_model_name){
2652
+			} elseif($query_param == $valid_related_model_name){
2645 2653
 				$this->_add_join_to_model($valid_related_model_name, $passed_in_query_info,$original_query_param);
2646 2654
 				return;
2647 2655
 			}
@@ -2701,7 +2709,7 @@  discard block
 block discarded – undo
2701 2709
 		$SQL = $this->_construct_condition_clause_recursive($where_params, ' AND ');
2702 2710
 		if($SQL){
2703 2711
 			return " WHERE ". $SQL;
2704
-		}else{
2712
+		} else{
2705 2713
 			return '';
2706 2714
 		}
2707 2715
 	}
@@ -2716,7 +2724,7 @@  discard block
 block discarded – undo
2716 2724
 		$SQL = $this->_construct_condition_clause_recursive($having_params, ' AND ');
2717 2725
 		if($SQL){
2718 2726
 			return " HAVING ". $SQL;
2719
-		}else{
2727
+		} else{
2720 2728
 			return '';
2721 2729
 		}
2722 2730
 
@@ -2739,7 +2747,7 @@  discard block
 block discarded – undo
2739 2747
 			$model_instance=call_user_func($model_name."::instance");
2740 2748
 			/* @var $model_instance EEM_Base */
2741 2749
 			return $model_instance->field_settings_for($field_name);
2742
-		}else{
2750
+		} else{
2743 2751
 			throw new EE_Error(sprintf(__('No model named %s exists, with classname %s and filepath %s','event_espresso'),$model_name,$model_class,$model_filepath));
2744 2752
 		}
2745 2753
 	}
@@ -2772,14 +2780,14 @@  discard block
 block discarded – undo
2772 2780
 						$where_clauses[] = " (". $this->_construct_condition_clause_recursive($op_and_value_or_sub_condition, ' OR ') .")";
2773 2781
 						break;
2774 2782
 				}
2775
-			}else{
2783
+			} else{
2776 2784
 				$field_obj = $this->_deduce_field_from_query_param($query_param);
2777 2785
 
2778 2786
 				//if it's not a normal field, maybe it's a custom selection?
2779 2787
 				if( ! $field_obj){
2780 2788
 					if(isset( $this->_custom_selections[$query_param][1])){
2781 2789
 						$field_obj = $this->_custom_selections[$query_param][1];
2782
-					}else{
2790
+					} else{
2783 2791
 						throw new EE_Error(sprintf(__("%s is neither a valid model field name, nor a custom selection", "event_espresso"),$query_param));
2784 2792
 					}
2785 2793
 				}
@@ -2789,7 +2797,7 @@  discard block
 block discarded – undo
2789 2797
 		}
2790 2798
 		if($where_clauses){
2791 2799
 			$SQL = implode($glue,$where_clauses);
2792
-		}else{
2800
+		} else{
2793 2801
 			$SQL = '';
2794 2802
 		}
2795 2803
 		return $SQL;
@@ -2809,11 +2817,11 @@  discard block
 block discarded – undo
2809 2817
 		if( $field ){
2810 2818
 			$table_alias_prefix = EE_Model_Parser::extract_table_alias_model_relation_chain_from_query_param( $field->get_model_name(), $query_param );
2811 2819
 			return $table_alias_prefix . $field->get_qualified_column();
2812
-		}elseif(array_key_exists($query_param,$this->_custom_selections)){
2820
+		} elseif(array_key_exists($query_param,$this->_custom_selections)){
2813 2821
 			//maybe it's custom selection item?
2814 2822
 			//if so, just use it as the "column name"
2815 2823
 			return $query_param;
2816
-		}else{
2824
+		} else{
2817 2825
 			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)));
2818 2826
 		}
2819 2827
 	}
@@ -2830,7 +2838,7 @@  discard block
 block discarded – undo
2830 2838
 		$pos_of_star = strpos($condition_query_param_key, '*');
2831 2839
 		if($pos_of_star === FALSE){
2832 2840
 			return $condition_query_param_key;
2833
-		}else{
2841
+		} else{
2834 2842
 			$condition_query_param_sans_star = substr($condition_query_param_key, 0, $pos_of_star);
2835 2843
 			return $condition_query_param_sans_star;
2836 2844
 		}
@@ -2856,7 +2864,7 @@  discard block
 block discarded – undo
2856 2864
 				throw new EE_Error(sprintf(__("You setup a query parameter like you were going to specify an operator, but didn't. You provided '(%s)', but the operator should be at array key index 0 (eg array('>',32))", "event_espresso"), implode(",",$php_array_like_string)));
2857 2865
 			}
2858 2866
 			$value = isset($op_and_value[1]) ? $op_and_value[1] : null;
2859
-		}else{
2867
+		} else{
2860 2868
 			$operator = '=';
2861 2869
 			$value = $op_and_value;
2862 2870
 		}
@@ -2864,7 +2872,7 @@  discard block
 block discarded – undo
2864 2872
 		//check to see if the value is actually another field
2865 2873
 		if(is_array($op_and_value) && isset($op_and_value[2]) && $op_and_value[2] == true){
2866 2874
 			return $operator.SP.$this->_deduce_column_name_from_query_param($value);
2867
-		}elseif(in_array($operator, $this->_in_style_operators) && is_array($value)){
2875
+		} elseif(in_array($operator, $this->_in_style_operators) && is_array($value)){
2868 2876
 			//in this case, the value should be an array, or at least a comma-separated list
2869 2877
 			//it will need to handle a little differently
2870 2878
 			$cleaned_value = $this->_construct_in_value($value, $field_obj);
@@ -2872,8 +2880,9 @@  discard block
 block discarded – undo
2872 2880
 			return $operator.SP.$cleaned_value;
2873 2881
 		} elseif( in_array( $operator, $this->_between_style_operators ) && is_array( $value ) ) {
2874 2882
 			//the value should be an array with count of two.
2875
-			if ( count($value) !== 2 )
2876
-				throw new EE_Error( sprintf( __("The '%s' operator must be used with an array of values and there must be exactly TWO values in that array.", 'event_espresso'), "BETWEEN" ) );
2883
+			if ( count($value) !== 2 ) {
2884
+							throw new EE_Error( sprintf( __("The '%s' operator must be used with an array of values and there must be exactly TWO values in that array.", 'event_espresso'), "BETWEEN" ) );
2885
+			}
2877 2886
 			$cleaned_value = $this->_construct_between_value( $value, $field_obj );
2878 2887
 			return $operator.SP.$cleaned_value;
2879 2888
 		} elseif( in_array( $operator, $this->_null_style_operators ) ) {
@@ -2881,17 +2890,17 @@  discard block
 block discarded – undo
2881 2890
 				throw new EE_Error(sprintf(__("You attempted to give a value  (%s) while using a NULL-style operator (%s). That isn't valid", "event_espresso"),$value,$operator));
2882 2891
 			}
2883 2892
 			return $operator;
2884
-		}elseif( $operator == 'LIKE' && ! is_array($value)){
2893
+		} elseif( $operator == 'LIKE' && ! is_array($value)){
2885 2894
 			//if the operator is 'LIKE', we want to allow percent signs (%) and not
2886 2895
 			//remove other junk. So just treat it as a string.
2887 2896
 			return $operator.SP.$this->_wpdb_prepare_using_field($value, '%s');
2888
-		}elseif( ! in_array($operator, $this->_in_style_operators) && ! is_array($value)){
2897
+		} elseif( ! in_array($operator, $this->_in_style_operators) && ! is_array($value)){
2889 2898
 			return $operator.SP.$this->_wpdb_prepare_using_field($value,$field_obj);
2890
-		}elseif(in_array($operator, $this->_in_style_operators) && ! is_array($value)){
2899
+		} elseif(in_array($operator, $this->_in_style_operators) && ! is_array($value)){
2891 2900
 			throw new EE_Error(sprintf(__("Operator '%s' must be used with an array of values, eg 'Registration.REG_ID' => array('%s',array(1,2,3))",'event_espresso'),$operator, $operator));
2892
-		}elseif( ! in_array($operator, $this->_in_style_operators) && is_array($value)){
2901
+		} elseif( ! in_array($operator, $this->_in_style_operators) && is_array($value)){
2893 2902
 			throw new EE_Error(sprintf(__("Operator '%s' must be used with a single value, not an array. Eg 'Registration.REG_ID => array('%s',23))",'event_espresso'),$operator,$operator));
2894
-		}else{
2903
+		} else{
2895 2904
 			throw new EE_Error(sprintf(__("It appears you've provided some totally invalid query parameters. Operator and value were:'%s', which isn't right at all", "event_espresso"),  http_build_query($op_and_value)));
2896 2905
 		}
2897 2906
 	}
@@ -2960,7 +2969,7 @@  discard block
 block discarded – undo
2960 2969
 		global $wpdb;
2961 2970
 		if($field_obj instanceof EE_Model_Field_Base){
2962 2971
 			return $wpdb->prepare($field_obj->get_wpdb_data_type(),$this->_prepare_value_for_use_in_db($value, $field_obj));
2963
-		}else{//$field_obj should really just be a data type
2972
+		} else{//$field_obj should really just be a data type
2964 2973
 			if( ! in_array($field_obj,$this->_valid_wpdb_data_types)){
2965 2974
 				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)));
2966 2975
 			}
@@ -2989,14 +2998,14 @@  discard block
 block discarded – undo
2989 2998
 		if($number_of_parts == 1){
2990 2999
 			$field_name = $last_query_param_part;
2991 3000
 			$model_obj = $this;
2992
-		}else{// $number_of_parts >= 2
3001
+		} else{// $number_of_parts >= 2
2993 3002
 			//the last part is the column name, and there are only 2parts. therefore...
2994 3003
 			$field_name = $last_query_param_part;
2995 3004
 			$model_obj = $this->get_related_model_obj( $query_param_parts[ $number_of_parts - 2 ]);
2996 3005
 		}
2997 3006
 		try{
2998 3007
 			return $model_obj->field_settings_for($field_name);
2999
-		}catch(EE_Error $e){
3008
+		} catch(EE_Error $e){
3000 3009
 			return null;
3001 3010
 		}
3002 3011
 	}
@@ -3015,7 +3024,7 @@  discard block
 block discarded – undo
3015 3024
 		$field = isset($all_fields[$field_name]) ? $all_fields[$field_name] : FALSE;
3016 3025
 		if($field){
3017 3026
 			return $field->get_qualified_column();
3018
-		}else{
3027
+		} else{
3019 3028
 			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)));
3020 3029
 		}
3021 3030
 	}
@@ -3081,7 +3090,7 @@  discard block
 block discarded – undo
3081 3090
 					//the FROM statement, BUT the primary table isn't. So we want
3082 3091
 					//to add the inverse join sql
3083 3092
 					$SQL .= $table_obj->get_inverse_join_sql($alias_prefixed);
3084
-				}else{
3093
+				} else{
3085 3094
 					//just add a regular JOIN to this table from the primary table
3086 3095
 					$SQL .= $table_obj->get_join_sql($alias_prefixed);
3087 3096
 				}
@@ -3196,7 +3205,7 @@  discard block
 block discarded – undo
3196 3205
 		$fieldSettings = $this->field_settings(true);
3197 3206
 		if( isset($fieldSettings[$fieldName])){
3198 3207
 			return true;
3199
-		}else{
3208
+		} else{
3200 3209
 			return false;
3201 3210
 		}
3202 3211
 	}
@@ -3210,7 +3219,7 @@  discard block
 block discarded – undo
3210 3219
 		$relations = $this->relation_settings();
3211 3220
 		if(isset($relations[$relation_name])){
3212 3221
 			return true;
3213
-		}else{
3222
+		} else{
3214 3223
 			return false;
3215 3224
 		}
3216 3225
 	}
@@ -3261,7 +3270,7 @@  discard block
 block discarded – undo
3261 3270
 			try{
3262 3271
 				$this->get_primary_key_field();
3263 3272
 				$this->_has_primary_key_field = true;
3264
-			}catch(EE_Error $e){
3273
+			} catch(EE_Error $e){
3265 3274
 				$this->_has_primary_key_field = false;
3266 3275
 			}
3267 3276
 		}
@@ -3340,7 +3349,7 @@  discard block
 block discarded – undo
3340 3349
 				}
3341 3350
 			}
3342 3351
 			return $this->_cached_fields;
3343
-		}else{
3352
+		} else{
3344 3353
 			if( $this->_cached_fields_non_db_only === NULL ){
3345 3354
 				$this->_cached_fields_non_db_only = array();
3346 3355
 				foreach($this->_fields as $fields_corresponding_to_table){
@@ -3473,7 +3482,7 @@  discard block
 block discarded – undo
3473 3482
 			if(empty( $this_model_fields_n_values[$this->primary_key_name()] )){
3474 3483
 				return NULL;
3475 3484
 			}
3476
-		}else if($this->unique_indexes()){
3485
+		} else if($this->unique_indexes()){
3477 3486
 			$first_column = reset($this_model_fields_n_values);
3478 3487
 			if(empty($first_column)){
3479 3488
 				return NULL;
@@ -3488,7 +3497,7 @@  discard block
 block discarded – undo
3488 3497
 				// add this new object to the entity map
3489 3498
 				$classInstance = $this->add_to_entity_map( $classInstance );
3490 3499
 			}
3491
-		}else{
3500
+		} else{
3492 3501
 			$classInstance = EE_Registry::instance()->load_class( $className, array( $this_model_fields_n_values, $this->_timezone ), TRUE, FALSE );
3493 3502
 		}
3494 3503
 
@@ -3573,11 +3582,12 @@  discard block
 block discarded – undo
3573 3582
 						$this_model_fields_n_values[$field_name] = $field_obj->get_default_value();
3574 3583
 					}
3575 3584
 				}
3576
-			}else{
3585
+			} else{
3577 3586
 				//the table's rows existed. Use their values
3578 3587
 				foreach( $this->_get_fields_for_table( $table_alias ) as $field_name => $field_obj ) {
3579
-					if( ! $field_obj->is_db_only_field() )
3580
-					$this_model_fields_n_values[$field_name] = $this->_get_column_value_with_table_alias_or_not($cols_n_values, $field_obj->get_qualified_column(), $field_obj->get_table_column() );
3588
+					if( ! $field_obj->is_db_only_field() ) {
3589
+										$this_model_fields_n_values[$field_name] = $this->_get_column_value_with_table_alias_or_not($cols_n_values, $field_obj->get_qualified_column(), $field_obj->get_table_column() );
3590
+					}
3581 3591
 				}
3582 3592
 			}
3583 3593
 		}
@@ -3591,9 +3601,9 @@  discard block
 block discarded – undo
3591 3601
 		if( isset( $cols_n_values[ $qualified_column ] ) ){
3592 3602
 			$value = $cols_n_values[ $qualified_column ];
3593 3603
 
3594
-		}elseif( isset( $cols_n_values[ $regular_column ] ) ){
3604
+		} elseif( isset( $cols_n_values[ $regular_column ] ) ){
3595 3605
 			$value = $cols_n_values[ $regular_column ];
3596
-		}else{
3606
+		} else{
3597 3607
 			$value = NULL;
3598 3608
 		}
3599 3609
 
@@ -3626,7 +3636,7 @@  discard block
 block discarded – undo
3626 3636
 				}
3627 3637
 			}
3628 3638
 			return $obj_in_map;
3629
-		}else{
3639
+		} else{
3630 3640
 			return $this->get_one_by_ID( $id );
3631 3641
 		}
3632 3642
 	}
@@ -3661,7 +3671,7 @@  discard block
 block discarded – undo
3661 3671
 				}
3662 3672
 			}
3663 3673
 			return $obj_in_map;
3664
-		}else{
3674
+		} else{
3665 3675
 			$this->add_to_entity_map( $replacing_model_obj );
3666 3676
 			return $replacing_model_obj;
3667 3677
 		}
@@ -3691,7 +3701,7 @@  discard block
 block discarded – undo
3691 3701
 	public function item_name($quantity = 1){
3692 3702
 		if($quantity == 1){
3693 3703
 			return $this->singular_item;
3694
-		}else{
3704
+		} else{
3695 3705
 			return $this->plural_item;
3696 3706
 		}
3697 3707
 	}
@@ -3753,14 +3763,14 @@  discard block
 block discarded – undo
3753 3763
 		$primary_key_field = $this->get_primary_key_field();
3754 3764
 		if( $base_class_obj_or_id instanceof $className ){
3755 3765
 			$model_object = $base_class_obj_or_id;
3756
-		}elseif( $primary_key_field instanceof EE_Primary_Key_Int_Field && (
3766
+		} elseif( $primary_key_field instanceof EE_Primary_Key_Int_Field && (
3757 3767
 				is_int( $base_class_obj_or_id ) ||
3758 3768
 				is_string( $base_class_obj_or_id ) )){//assume it's an ID. either a proper integer or a string representing an integer (eg "101" instead of 101)
3759 3769
 			$model_object = $this->get_one_by_ID($base_class_obj_or_id);
3760
-		}elseif( $primary_key_field instanceof EE_Primary_Key_String_Field && is_string($base_class_obj_or_id) ){
3770
+		} elseif( $primary_key_field instanceof EE_Primary_Key_String_Field && is_string($base_class_obj_or_id) ){
3761 3771
 			//assume its a string representation of the object
3762 3772
 			$model_object = $this->get_one_by_ID($base_class_obj_or_id);
3763
-		}else{
3773
+		} else{
3764 3774
 			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)));
3765 3775
 		}
3766 3776
 		if( $model_object->ID() == NULL && $ensure_is_in_db){
@@ -3784,13 +3794,13 @@  discard block
 block discarded – undo
3784 3794
 		if( $base_class_obj_or_id instanceof $className ){
3785 3795
 			/** @var $base_class_obj_or_id EE_Base_Class */
3786 3796
 			$id = $base_class_obj_or_id->ID();
3787
-		}elseif(is_int($base_class_obj_or_id)){
3797
+		} elseif(is_int($base_class_obj_or_id)){
3788 3798
 			//assume it's an ID
3789 3799
 			$id = $base_class_obj_or_id;
3790
-		}elseif(is_string($base_class_obj_or_id)){
3800
+		} elseif(is_string($base_class_obj_or_id)){
3791 3801
 			//assume its a string representation of the object
3792 3802
 			$id = $base_class_obj_or_id;
3793
-		}else{
3803
+		} else{
3794 3804
 			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)));
3795 3805
 		}
3796 3806
 		return $id;
@@ -3921,9 +3931,9 @@  discard block
 block discarded – undo
3921 3931
 
3922 3932
 		if($model_object_or_attributes_array instanceof EE_Base_Class){
3923 3933
 			$attributes_array = $model_object_or_attributes_array->model_field_array();
3924
-		}elseif(is_array($model_object_or_attributes_array)){
3934
+		} elseif(is_array($model_object_or_attributes_array)){
3925 3935
 			$attributes_array = $model_object_or_attributes_array;
3926
-		}else{
3936
+		} else{
3927 3937
 			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));
3928 3938
 		}
3929 3939
 		//even copies obviously won't have the same ID, so remove the primary key
@@ -3933,7 +3943,7 @@  discard block
 block discarded – undo
3933 3943
 		}
3934 3944
 		if(isset($query_params[0])){
3935 3945
 			$query_params[0] = array_merge($attributes_array,$query_params);
3936
-		}else{
3946
+		} else{
3937 3947
 			$query_params[0] = $attributes_array;
3938 3948
 		}
3939 3949
 		return $this->get_all($query_params);
@@ -3956,7 +3966,7 @@  discard block
 block discarded – undo
3956 3966
 		$copies = $this->get_all_copies($model_object_or_attributes_array,$query_params);
3957 3967
 		if(is_array($copies)){
3958 3968
 			return array_shift($copies);
3959
-		}else{
3969
+		} else{
3960 3970
 			return null;
3961 3971
 		}
3962 3972
 	}
@@ -3988,7 +3998,7 @@  discard block
 block discarded – undo
3988 3998
 		$sql_operator = isset($this->_valid_operators[$operator_supplied]) ? $this->_valid_operators[$operator_supplied] : null;
3989 3999
 		if($sql_operator){
3990 4000
 			return $sql_operator;
3991
-		}else{
4001
+		} else{
3992 4002
 			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))));
3993 4003
 		}
3994 4004
 	}
@@ -4127,7 +4137,7 @@  discard block
 block discarded – undo
4127 4137
 		$valid_cap_contexts = EEM_Base::valid_cap_contexts();
4128 4138
 		if( in_array( $context, $valid_cap_contexts ) ) {
4129 4139
 			return true;
4130
-		}else{
4140
+		} else{
4131 4141
 			throw new EE_Error(
4132 4142
 				sprintf(
4133 4143
 					__( 'Context "%1$s" passed into model "%2$s" is not a valid context. They are: %3$s', 'event_espresso' ),
Please login to merge, or discard this patch.
core/db_models/EEM_CPT_Base.model.php 2 patches
Spacing   +83 added lines, -83 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1 1
 <?php
2
-define('EE_Event_Category_Taxonomy','espresso_event_category');
2
+define('EE_Event_Category_Taxonomy', 'espresso_event_category');
3 3
 /**
4 4
  *
5 5
  * EEM_CPT_Base
@@ -16,7 +16,7 @@  discard block
 block discarded – undo
16 16
  * @author 				Mike Nelson
17 17
  *
18 18
  */
19
-abstract class EEM_CPT_Base extends EEM_Soft_Delete_Base{
19
+abstract class EEM_CPT_Base extends EEM_Soft_Delete_Base {
20 20
 
21 21
 	/**
22 22
 	 * @var string post_status_trashed - the wp post status for trashed cpts
@@ -44,42 +44,42 @@  discard block
 block discarded – undo
44 44
 	 * @param string $timezone
45 45
 	 * @throws \EE_Error
46 46
 	 */
47
-	protected function __construct( $timezone = NULL ){
47
+	protected function __construct($timezone = NULL) {
48 48
 
49 49
 		//adds a relationship to Term_Taxonomy for all these models. For this to work
50 50
 		//Term_Relationship must have a relation to each model subclassing EE_CPT_Base explicitly
51 51
 		//eg, in EEM_Term_Relationship, inside the _model_relations array, there must be an entry
52 52
 		//with key equalling the subclassing model's model name (eg 'Event' or 'Venue'), and the value
53 53
 		//must also be new EE_HABTM_Relation('Term_Relationship');
54
-		$this->_model_relations['Term_Taxonomy'] =new EE_HABTM_Relation('Term_Relationship');
54
+		$this->_model_relations['Term_Taxonomy'] = new EE_HABTM_Relation('Term_Relationship');
55 55
 		$primary_table_name = NULL;
56 56
 		//add  the common _status field to all CPT primary tables.
57
-		foreach ( $this->_tables as $alias => $table_obj ) {
58
-			if ( $table_obj instanceof EE_Primary_Table ) {
57
+		foreach ($this->_tables as $alias => $table_obj) {
58
+			if ($table_obj instanceof EE_Primary_Table) {
59 59
 				$primary_table_name = $alias;
60 60
 			}
61 61
 		}
62 62
 		//set default wp post statuses if child has not already set.
63
-		if ( ! isset( $this->_fields[$primary_table_name]['status'] )) {
63
+		if ( ! isset($this->_fields[$primary_table_name]['status'])) {
64 64
 			$this->_fields[$primary_table_name]['status'] = new EE_WP_Post_Status_Field('post_status', __("Event Status", "event_espresso"), false, 'draft');
65 65
 		}
66
-		if( ! isset( $this->_fields[$primary_table_name]['to_ping'])){
67
-			$this->_fields[$primary_table_name]['to_ping'] = new EE_DB_Only_Text_Field('to_ping', __( 'To Ping', 'event_espresso' ), FALSE, '');
66
+		if ( ! isset($this->_fields[$primary_table_name]['to_ping'])) {
67
+			$this->_fields[$primary_table_name]['to_ping'] = new EE_DB_Only_Text_Field('to_ping', __('To Ping', 'event_espresso'), FALSE, '');
68 68
 		}
69
-		if( ! isset( $this->_fields[$primary_table_name]['pinged'])){
70
-			$this->_fields[$primary_table_name]['pinged'] = new EE_DB_Only_Text_Field('pinged', __( 'Pinged', 'event_espresso' ), FALSE, '');
69
+		if ( ! isset($this->_fields[$primary_table_name]['pinged'])) {
70
+			$this->_fields[$primary_table_name]['pinged'] = new EE_DB_Only_Text_Field('pinged', __('Pinged', 'event_espresso'), FALSE, '');
71 71
 		}
72 72
 
73
-		if( ! isset( $this->_fields[$primary_table_name]['comment_status'])){
74
-			$this->_fields[$primary_table_name]['comment_status'] = new EE_Plain_Text_Field('comment_status', __('Comment Status', 'event_espresso' ), FALSE, 'open');
73
+		if ( ! isset($this->_fields[$primary_table_name]['comment_status'])) {
74
+			$this->_fields[$primary_table_name]['comment_status'] = new EE_Plain_Text_Field('comment_status', __('Comment Status', 'event_espresso'), FALSE, 'open');
75 75
 		}
76 76
 
77
-		if( ! isset( $this->_fields[$primary_table_name]['ping_status'])){
77
+		if ( ! isset($this->_fields[$primary_table_name]['ping_status'])) {
78 78
 			$this->_fields[$primary_table_name]['ping_status'] = new EE_Plain_Text_Field('ping_status', __('Ping Status', 'event_espresso'), FALSE, 'open');
79 79
 		}
80 80
 
81
-		if( ! isset( $this->_fields[$primary_table_name]['post_content_filtered'])){
82
-			$this->_fields[$primary_table_name]['post_content_filtered'] = new EE_DB_Only_Text_Field('post_content_filtered', __( 'Post Content Filtered', 'event_espresso' ), FALSE, '');
81
+		if ( ! isset($this->_fields[$primary_table_name]['post_content_filtered'])) {
82
+			$this->_fields[$primary_table_name]['post_content_filtered'] = new EE_DB_Only_Text_Field('post_content_filtered', __('Post Content Filtered', 'event_espresso'), FALSE, '');
83 83
 		}
84 84
 		parent::__construct($timezone);
85 85
 
@@ -92,7 +92,7 @@  discard block
 block discarded – undo
92 92
 	 */
93 93
 	public function public_event_stati() {
94 94
 		// @see wp-includes/post.php
95
-		return get_post_stati( array( 'public' => TRUE ));
95
+		return get_post_stati(array('public' => TRUE));
96 96
 	}
97 97
 
98 98
 
@@ -103,7 +103,7 @@  discard block
 block discarded – undo
103 103
 	 * @return string
104 104
 	 * @throws EE_Error
105 105
 	 */
106
-	public function deleted_field_name(){
106
+	public function deleted_field_name() {
107 107
 		throw new EE_Error(sprintf(__("EEM_CPT_Base should nto call deleted_field_name! It should instead use post_status_field_name", "event_espresso")));
108 108
 	}
109 109
 
@@ -114,12 +114,12 @@  discard block
 block discarded – undo
114 114
 	 * @return string
115 115
 	 * @throws EE_Error
116 116
 	 */
117
-	public function post_status_field_name(){
117
+	public function post_status_field_name() {
118 118
 		$field = $this->get_a_field_of_type('EE_WP_Post_Status_Field');
119
-		if($field){
119
+		if ($field) {
120 120
 			return $field->get_name();
121
-		}else{
122
-			throw new EE_Error(sprintf(__('We are trying to find the post status flag field on %s, but none was found. Are you sure there is a field of type EE_Trashed_Flag_Field in %s constructor?','event_espresso'),get_class($this),get_class($this)));
121
+		} else {
122
+			throw new EE_Error(sprintf(__('We are trying to find the post status flag field on %s, but none was found. Are you sure there is a field of type EE_Trashed_Flag_Field in %s constructor?', 'event_espresso'), get_class($this), get_class($this)));
123 123
 		}
124 124
 	}
125 125
 
@@ -130,9 +130,9 @@  discard block
 block discarded – undo
130 130
 	 * @param array $query_params like EEM_Base::get_all's $query_params
131 131
 	 * @return array like EEM_Base::get_all's $query_params
132 132
 	 */
133
-	protected function _alter_query_params_so_only_trashed_items_included($query_params){
134
-		$post_status_field_name=$this->post_status_field_name();
135
-		$query_params[0][$post_status_field_name]=self::post_status_trashed;
133
+	protected function _alter_query_params_so_only_trashed_items_included($query_params) {
134
+		$post_status_field_name = $this->post_status_field_name();
135
+		$query_params[0][$post_status_field_name] = self::post_status_trashed;
136 136
 		return $query_params;
137 137
 	}
138 138
 
@@ -143,9 +143,9 @@  discard block
 block discarded – undo
143 143
 	 * @param array $query_params
144 144
 	 * @return array
145 145
 	 */
146
-	protected function _alter_query_params_so_deleted_and_undeleted_items_included($query_params){
147
-		$post_status_field_name=$this->post_status_field_name();
148
-		$query_params[0][$post_status_field_name]=array('IN',array_keys($this->get_status_array()));
146
+	protected function _alter_query_params_so_deleted_and_undeleted_items_included($query_params) {
147
+		$post_status_field_name = $this->post_status_field_name();
148
+		$query_params[0][$post_status_field_name] = array('IN', array_keys($this->get_status_array()));
149 149
 		return $query_params;
150 150
 	}
151 151
 
@@ -157,11 +157,11 @@  discard block
 block discarded – undo
157 157
 	 * @param array $query_params like EEM_Base::get_all
158 158
 	 * @return boolean success
159 159
 	 */
160
-	function delete_or_restore($delete=true,$query_params = array()){
161
-		$post_status_field_name=$this->post_status_field_name();
160
+	function delete_or_restore($delete = true, $query_params = array()) {
161
+		$post_status_field_name = $this->post_status_field_name();
162 162
 		$query_params = $this->_alter_query_params_so_deleted_and_undeleted_items_included($query_params);
163 163
 		$new_status = $delete ? self::post_status_trashed : 'draft';
164
-		if ( $this->update (array($post_status_field_name=>$new_status), $query_params )) {
164
+		if ($this->update(array($post_status_field_name=>$new_status), $query_params)) {
165 165
 			return TRUE;
166 166
 		} else {
167 167
 			return FALSE;
@@ -178,7 +178,7 @@  discard block
 block discarded – undo
178 178
 	 */
179 179
 	public function meta_table() {
180 180
 		$meta_table = $this->_get_other_tables();
181
-		$meta_table = reset( $meta_table );
181
+		$meta_table = reset($meta_table);
182 182
 		return $meta_table instanceof EE_Secondary_Table ? $meta_table->get_table_name() : NULL;
183 183
 	}
184 184
 
@@ -190,16 +190,16 @@  discard block
 block discarded – undo
190 190
 	 * @param  bool $all triggers whether we include DB_Only fields or JUST non DB_Only fields.  Defaults to false (no db only fields)
191 191
 	 * @return array
192 192
 	 */
193
-	public function get_meta_table_fields( $all = FALSE ) {
193
+	public function get_meta_table_fields($all = FALSE) {
194 194
 		$all_fields = $fields_to_return = array();
195
-		foreach ( $this->_tables as $alias => $table_obj ) {
196
-			if ( $table_obj instanceof EE_Secondary_Table )
197
-				$all_fields = array_merge( $this->_get_fields_for_table($alias), $all_fields );
195
+		foreach ($this->_tables as $alias => $table_obj) {
196
+			if ($table_obj instanceof EE_Secondary_Table)
197
+				$all_fields = array_merge($this->_get_fields_for_table($alias), $all_fields);
198 198
 		}
199 199
 
200
-		if ( !$all ) {
201
-			foreach ( $all_fields as $name => $obj ) {
202
-				if ( $obj instanceof EE_DB_Only_Field_Base )
200
+		if ( ! $all) {
201
+			foreach ($all_fields as $name => $obj) {
202
+				if ($obj instanceof EE_DB_Only_Field_Base)
203 203
 					continue;
204 204
 				$fields_to_return[] = $name;
205 205
 			}
@@ -222,13 +222,13 @@  discard block
 block discarded – undo
222 222
 	 * @param int $parent_term_taxonomy_id
223 223
 	 * @return EE_Term_Taxonomy
224 224
 	 */
225
-	function add_event_category(EE_CPT_Base $cpt_model_object, $category_name, $category_description ='',$parent_term_taxonomy_id = null){
225
+	function add_event_category(EE_CPT_Base $cpt_model_object, $category_name, $category_description = '', $parent_term_taxonomy_id = null) {
226 226
 		//create term
227
-		require_once( EE_MODELS . 'EEM_Term.model.php');
227
+		require_once(EE_MODELS.'EEM_Term.model.php');
228 228
 		//first, check for a term by the same name or slug
229 229
 		$category_slug = sanitize_title($category_name);
230
-		$term = EEM_Term::instance()->get_one(array(array('OR'=>array('name'=>$category_name,'slug'=>$category_slug))));
231
-		if( ! $term ){
230
+		$term = EEM_Term::instance()->get_one(array(array('OR'=>array('name'=>$category_name, 'slug'=>$category_slug))));
231
+		if ( ! $term) {
232 232
 			$term = EE_Term::new_instance(array(
233 233
 				'name'=>$category_name,
234 234
 				'slug'=>$category_slug
@@ -236,10 +236,10 @@  discard block
 block discarded – undo
236 236
 			$term->save();
237 237
 		}
238 238
 		//make sure there's a term-taxonomy entry too
239
-		require_once( EE_MODELS . 'EEM_Term_Taxonomy.model.php');
240
-		$term_taxonomy = EEM_Term_Taxonomy::instance()->get_one(array(array('term_id'=>$term->ID(),'taxonomy'=>EE_Event_Category_Taxonomy)));
239
+		require_once(EE_MODELS.'EEM_Term_Taxonomy.model.php');
240
+		$term_taxonomy = EEM_Term_Taxonomy::instance()->get_one(array(array('term_id'=>$term->ID(), 'taxonomy'=>EE_Event_Category_Taxonomy)));
241 241
 		/** @var $term_taxonomy EE_Term_Taxonomy */
242
-		if( ! $term_taxonomy ){
242
+		if ( ! $term_taxonomy) {
243 243
 			$term_taxonomy = EE_Term_Taxonomy::new_instance(array(
244 244
 				'term_id'=>$term->ID(),
245 245
 				'taxonomy'=>EE_Event_Category_Taxonomy,
@@ -248,7 +248,7 @@  discard block
 block discarded – undo
248 248
 				'parent'=>$parent_term_taxonomy_id
249 249
 			));
250 250
 			$term_taxonomy->save();
251
-		}else{
251
+		} else {
252 252
 			$term_taxonomy->set_count($term_taxonomy->count() + 1);
253 253
 			$term_taxonomy->save();
254 254
 		}
@@ -263,11 +263,11 @@  discard block
 block discarded – undo
263 263
 	 * @param string $category_name name of the event category (term)
264 264
 	 * @return bool
265 265
 	 */
266
-	function remove_event_category(EE_CPT_Base $cpt_model_object_event, $category_name){
266
+	function remove_event_category(EE_CPT_Base $cpt_model_object_event, $category_name) {
267 267
 		//find the term_taxonomy by that name
268
-		$term_taxonomy = $this->get_first_related($cpt_model_object_event, 'Term_Taxonomy', array(array('Term.name'=>$category_name,'taxonomy'=>EE_Event_Category_Taxonomy)));
268
+		$term_taxonomy = $this->get_first_related($cpt_model_object_event, 'Term_Taxonomy', array(array('Term.name'=>$category_name, 'taxonomy'=>EE_Event_Category_Taxonomy)));
269 269
 		/** @var $term_taxonomy EE_Term_Taxonomy */
270
-		if( $term_taxonomy ){
270
+		if ($term_taxonomy) {
271 271
 			$term_taxonomy->set_count($term_taxonomy->count() - 1);
272 272
 			$term_taxonomy->save();
273 273
 		}
@@ -287,8 +287,8 @@  discard block
 block discarded – undo
287 287
 	 * @param string|array $attr Optional. Query string or array of attributes.
288 288
 	 * @return string HTML image element
289 289
 	 */
290
-	public function get_feature_image( $id, $size = 'thumbnail', $attr = '' ) {
291
-		return get_the_post_thumbnail( $id, $size, $attr );
290
+	public function get_feature_image($id, $size = 'thumbnail', $attr = '') {
291
+		return get_the_post_thumbnail($id, $size, $attr);
292 292
 	}
293 293
 
294 294
 
@@ -301,10 +301,10 @@  discard block
 block discarded – undo
301 301
 	 * @global array $wp_post_statuses set in wp core for storing all the post stati
302 302
 	 * @return array
303 303
 	 */
304
-	public function get_post_statuses(){
304
+	public function get_post_statuses() {
305 305
 		global $wp_post_statuses;
306 306
 		$statuses = array();
307
-		foreach($wp_post_statuses as $post_status => $args_object){
307
+		foreach ($wp_post_statuses as $post_status => $args_object) {
308 308
 			$statuses[$post_status] = $args_object->label;
309 309
 		}
310 310
 		return $statuses;
@@ -319,9 +319,9 @@  discard block
 block discarded – undo
319 319
 	public function get_status_array() {
320 320
 		$statuses = $this->get_post_statuses();
321 321
 		//first the global filter
322
-		$statuses = apply_filters( 'FHEE_EEM_CPT_Base__get_status_array', $statuses );
322
+		$statuses = apply_filters('FHEE_EEM_CPT_Base__get_status_array', $statuses);
323 323
 		//now the class specific filter
324
-		$statuses = apply_filters( 'FHEE_EEM_' . get_class($this) . '__get_status_array', $statuses );
324
+		$statuses = apply_filters('FHEE_EEM_'.get_class($this).'__get_status_array', $statuses);
325 325
 		return $statuses;
326 326
 	}
327 327
 
@@ -333,7 +333,7 @@  discard block
 block discarded – undo
333 333
 	 */
334 334
 	public function get_custom_post_statuses() {
335 335
 		$new_stati = array();
336
-		foreach ( $this->_custom_stati as $status => $props ) {
336
+		foreach ($this->_custom_stati as $status => $props) {
337 337
 			$new_stati[$status] = $props['label'];
338 338
 		}
339 339
 		return $new_stati;
@@ -349,24 +349,24 @@  discard block
 block discarded – undo
349 349
 	 * @param WP_Post|array $post
350 350
 	 * @return EE_CPT_Base
351 351
 	 */
352
-	public function instantiate_class_from_post_object_orig($post){
353
-		$post = (array)$post;
352
+	public function instantiate_class_from_post_object_orig($post) {
353
+		$post = (array) $post;
354 354
 		$has_all_necessary_fields_for_table = true;
355 355
 		//check if the post has fields on the meta table already
356
-		foreach($this->_get_other_tables() as $table_obj){
356
+		foreach ($this->_get_other_tables() as $table_obj) {
357 357
 			$fields_for_that_table = $this->_get_fields_for_table($table_obj->get_table_alias());
358
-			foreach($fields_for_that_table as $field_obj){
359
-				if( ! isset($post[$field_obj->get_table_column()])
360
-					&& ! isset($post[$field_obj->get_qualified_column()])){
358
+			foreach ($fields_for_that_table as $field_obj) {
359
+				if ( ! isset($post[$field_obj->get_table_column()])
360
+					&& ! isset($post[$field_obj->get_qualified_column()])) {
361 361
 					$has_all_necessary_fields_for_table = false;
362 362
 				}
363 363
 			}
364 364
 		}
365 365
 		//if we don't have all the fields we need, then just fetch the proper model from the DB
366
-		if( ! $has_all_necessary_fields_for_table){
366
+		if ( ! $has_all_necessary_fields_for_table) {
367 367
 
368 368
 			return $this->get_one_by_ID($post['ID']);
369
-		}else{
369
+		} else {
370 370
 			return $this->instantiate_class_from_array_or_object($post);
371 371
 		}
372 372
 	}
@@ -377,30 +377,30 @@  discard block
 block discarded – undo
377 377
 	 * @param null $post
378 378
 	 * @return EE_Base_Class|EE_Soft_Delete_Base_Class
379 379
 	 */
380
-	public function instantiate_class_from_post_object( $post = NULL ){
381
-		if ( empty( $post )) {
380
+	public function instantiate_class_from_post_object($post = NULL) {
381
+		if (empty($post)) {
382 382
 			global $post;
383 383
 		}
384
-		$post = (array)$post;
384
+		$post = (array) $post;
385 385
 		$tables_needing_to_be_queried = array();
386 386
 		//check if the post has fields on the meta table already
387
-		foreach($this->get_tables() as $table_obj){
387
+		foreach ($this->get_tables() as $table_obj) {
388 388
 			$fields_for_that_table = $this->_get_fields_for_table($table_obj->get_table_alias());
389
-			foreach($fields_for_that_table as $field_obj){
390
-				if( ! isset($post[$field_obj->get_table_column()])
391
-					&& ! isset($post[$field_obj->get_qualified_column()])){
389
+			foreach ($fields_for_that_table as $field_obj) {
390
+				if ( ! isset($post[$field_obj->get_table_column()])
391
+					&& ! isset($post[$field_obj->get_qualified_column()])) {
392 392
 					$tables_needing_to_be_queried[$table_obj->get_table_alias()] = $table_obj;
393 393
 				}
394 394
 			}
395 395
 		}
396 396
 		//if we don't have all the fields we need, then just fetch the proper model from the DB
397
-		if( $tables_needing_to_be_queried){
398
-			if(count($tables_needing_to_be_queried) == 1 && reset($tables_needing_to_be_queried) instanceof EE_Secondary_Table){
397
+		if ($tables_needing_to_be_queried) {
398
+			if (count($tables_needing_to_be_queried) == 1 && reset($tables_needing_to_be_queried) instanceof EE_Secondary_Table) {
399 399
 				//so we're only missing data from a secondary table. Well that's not too hard to query for
400 400
 				$table_to_query = reset($tables_needing_to_be_queried);
401
-				$missing_data = $this->_do_wpdb_query( 'get_row', array( 'SELECT * FROM ' . $table_to_query->get_table_name() . ' WHERE ' . $table_to_query->get_fk_on_table() . ' = ' . $post['ID'], ARRAY_A ));
402
-				if ( ! empty( $missing_data )) {
403
-					$post = array_merge( $post, $missing_data );
401
+				$missing_data = $this->_do_wpdb_query('get_row', array('SELECT * FROM '.$table_to_query->get_table_name().' WHERE '.$table_to_query->get_fk_on_table().' = '.$post['ID'], ARRAY_A));
402
+				if ( ! empty($missing_data)) {
403
+					$post = array_merge($post, $missing_data);
404 404
 				}
405 405
 			} else {
406 406
 				return $this->get_one_by_ID($post['ID']);
@@ -417,15 +417,15 @@  discard block
 block discarded – undo
417 417
 	 * @throws EE_Error
418 418
 	 * @return string
419 419
 	 */
420
-	public function post_type(){
420
+	public function post_type() {
421 421
 		$post_type_field = NULL;
422
-		foreach($this->field_settings(true) as $field_obj){
423
-			if($field_obj instanceof EE_WP_Post_Type_Field){
424
-				$post_type_field = $field_obj;break;
422
+		foreach ($this->field_settings(true) as $field_obj) {
423
+			if ($field_obj instanceof EE_WP_Post_Type_Field) {
424
+				$post_type_field = $field_obj; break;
425 425
 			}
426 426
 		}
427
-		if($post_type_field == NULL){
428
-			throw new EE_Error(sprintf(__("CPT Model %s should have a field of type EE_WP_Post_Type, but doesnt", "event_espresso"),get_class($this)));
427
+		if ($post_type_field == NULL) {
428
+			throw new EE_Error(sprintf(__("CPT Model %s should have a field of type EE_WP_Post_Type, but doesnt", "event_espresso"), get_class($this)));
429 429
 		}
430 430
 		return $post_type_field->get_default_value();
431 431
 	}
Please login to merge, or discard this patch.
Braces   +9 added lines, -7 removed lines patch added patch discarded remove patch
@@ -118,7 +118,7 @@  discard block
 block discarded – undo
118 118
 		$field = $this->get_a_field_of_type('EE_WP_Post_Status_Field');
119 119
 		if($field){
120 120
 			return $field->get_name();
121
-		}else{
121
+		} else{
122 122
 			throw new EE_Error(sprintf(__('We are trying to find the post status flag field on %s, but none was found. Are you sure there is a field of type EE_Trashed_Flag_Field in %s constructor?','event_espresso'),get_class($this),get_class($this)));
123 123
 		}
124 124
 	}
@@ -193,14 +193,16 @@  discard block
 block discarded – undo
193 193
 	public function get_meta_table_fields( $all = FALSE ) {
194 194
 		$all_fields = $fields_to_return = array();
195 195
 		foreach ( $this->_tables as $alias => $table_obj ) {
196
-			if ( $table_obj instanceof EE_Secondary_Table )
197
-				$all_fields = array_merge( $this->_get_fields_for_table($alias), $all_fields );
196
+			if ( $table_obj instanceof EE_Secondary_Table ) {
197
+							$all_fields = array_merge( $this->_get_fields_for_table($alias), $all_fields );
198
+			}
198 199
 		}
199 200
 
200 201
 		if ( !$all ) {
201 202
 			foreach ( $all_fields as $name => $obj ) {
202
-				if ( $obj instanceof EE_DB_Only_Field_Base )
203
-					continue;
203
+				if ( $obj instanceof EE_DB_Only_Field_Base ) {
204
+									continue;
205
+				}
204 206
 				$fields_to_return[] = $name;
205 207
 			}
206 208
 		} else {
@@ -248,7 +250,7 @@  discard block
 block discarded – undo
248 250
 				'parent'=>$parent_term_taxonomy_id
249 251
 			));
250 252
 			$term_taxonomy->save();
251
-		}else{
253
+		} else{
252 254
 			$term_taxonomy->set_count($term_taxonomy->count() + 1);
253 255
 			$term_taxonomy->save();
254 256
 		}
@@ -366,7 +368,7 @@  discard block
 block discarded – undo
366 368
 		if( ! $has_all_necessary_fields_for_table){
367 369
 
368 370
 			return $this->get_one_by_ID($post['ID']);
369
-		}else{
371
+		} else{
370 372
 			return $this->instantiate_class_from_array_or_object($post);
371 373
 		}
372 374
 	}
Please login to merge, or discard this patch.