@@ -1,6 +1,6 @@ discard block |
||
1 | 1 | <?php |
2 | -if ( ! defined( 'EVENT_ESPRESSO_VERSION' ) ) { |
|
3 | - exit( 'No direct script access allowed' ); |
|
2 | +if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
|
3 | + exit('No direct script access allowed'); |
|
4 | 4 | } |
5 | 5 | |
6 | 6 | |
@@ -50,9 +50,9 @@ discard block |
||
50 | 50 | * |
51 | 51 | * @param EE_Registration[] $registrations |
52 | 52 | */ |
53 | - public function __construct( $registrations ) { |
|
53 | + public function __construct($registrations) { |
|
54 | 54 | $this->_registrations = $registrations; |
55 | - $this->_calculate_registrations_per_line_item_code( $registrations ); |
|
55 | + $this->_calculate_registrations_per_line_item_code($registrations); |
|
56 | 56 | // these reg statuses should NOT increment the line item quantity |
57 | 57 | $this->_closed_reg_statuses = EEM_Registration::closed_reg_statuses(); |
58 | 58 | } |
@@ -65,20 +65,20 @@ discard block |
||
65 | 65 | * @param EE_Registration[] $registrations |
66 | 66 | * @return void |
67 | 67 | */ |
68 | - protected function _calculate_registrations_per_line_item_code( $registrations ) { |
|
69 | - foreach ( $registrations as $registration ) { |
|
68 | + protected function _calculate_registrations_per_line_item_code($registrations) { |
|
69 | + foreach ($registrations as $registration) { |
|
70 | 70 | $line_item_code = EEM_Line_Item::instance()->get_var( |
71 | 71 | EEM_Line_Item::instance()->line_item_for_registration_query_params( |
72 | 72 | $registration, |
73 | - array( 'limit' => 1 ) |
|
73 | + array('limit' => 1) |
|
74 | 74 | ), |
75 | 75 | 'LIN_code' |
76 | 76 | ); |
77 | - if ( $line_item_code ) { |
|
78 | - if ( ! isset( $this->_line_item_registrations[ $line_item_code ] ) ) { |
|
79 | - $this->_line_item_registrations[ $line_item_code ] = array(); |
|
77 | + if ($line_item_code) { |
|
78 | + if ( ! isset($this->_line_item_registrations[$line_item_code])) { |
|
79 | + $this->_line_item_registrations[$line_item_code] = array(); |
|
80 | 80 | } |
81 | - $this->_line_item_registrations[ $line_item_code ][ $registration->ID() ] = $registration; |
|
81 | + $this->_line_item_registrations[$line_item_code][$registration->ID()] = $registration; |
|
82 | 82 | } |
83 | 83 | } |
84 | 84 | } |
@@ -92,9 +92,9 @@ discard block |
||
92 | 92 | * @param EEI_Line_Item $line_item |
93 | 93 | * @return \EEI_Line_Item |
94 | 94 | */ |
95 | - public function process( EEI_Line_Item $line_item ) { |
|
96 | - $this->_adjust_line_item_quantity( $line_item ); |
|
97 | - if ( ! $line_item->children() ) { |
|
95 | + public function process(EEI_Line_Item $line_item) { |
|
96 | + $this->_adjust_line_item_quantity($line_item); |
|
97 | + if ( ! $line_item->children()) { |
|
98 | 98 | return $line_item; |
99 | 99 | } |
100 | 100 | //the original running total (taking ALL tickets into account) |
@@ -103,11 +103,11 @@ discard block |
||
103 | 103 | $running_total_of_children_under_consideration = 0; |
104 | 104 | // let's also track the quantity of tickets that pertain to the registrations |
105 | 105 | $total_child_ticket_quantity = 0; |
106 | - foreach ( $line_item->children() as $child_line_item ) { |
|
106 | + foreach ($line_item->children() as $child_line_item) { |
|
107 | 107 | $original_li_total = $child_line_item->is_percent() |
108 | 108 | ? $running_total_of_children * $child_line_item->percent() / 100 |
109 | 109 | : $child_line_item->unit_price() * $child_line_item->quantity(); |
110 | - $this->process( $child_line_item ); |
|
110 | + $this->process($child_line_item); |
|
111 | 111 | // If this line item is a normal line item that isn't for a ticket, |
112 | 112 | // we want to modify its total (and unit price if not a percentage line item) |
113 | 113 | // so it reflects only that portion of the surcharge/discount shared by these registrations |
@@ -121,8 +121,8 @@ discard block |
||
121 | 121 | $child_line_item->set_total( |
122 | 122 | $running_total_of_children_under_consideration * $percent_of_running_total |
123 | 123 | ); |
124 | - if ( ! $child_line_item->is_percent() ) { |
|
125 | - $child_line_item->set_unit_price( $child_line_item->total() / $child_line_item->quantity() ); |
|
124 | + if ( ! $child_line_item->is_percent()) { |
|
125 | + $child_line_item->set_unit_price($child_line_item->total() / $child_line_item->quantity()); |
|
126 | 126 | } |
127 | 127 | } else if ( |
128 | 128 | $line_item->type() === EEM_Line_Item::type_line_item |
@@ -139,28 +139,28 @@ discard block |
||
139 | 139 | // unless it IS a cancellation and the current registration is cancelled |
140 | 140 | $child_line_item->is_cancelled() |
141 | 141 | && $this->_current_registration instanceof EE_Registration |
142 | - && in_array( $this->_current_registration->status_ID(), $this->_closed_reg_statuses ) |
|
142 | + && in_array($this->_current_registration->status_ID(), $this->_closed_reg_statuses) |
|
143 | 143 | ) |
144 | 144 | ) |
145 | 145 | ) { |
146 | - $child_line_item->set_quantity( $line_item->quantity() ); |
|
147 | - $child_line_item->set_total( $child_line_item->unit_price() * $child_line_item->quantity() ); |
|
146 | + $child_line_item->set_quantity($line_item->quantity()); |
|
147 | + $child_line_item->set_total($child_line_item->unit_price() * $child_line_item->quantity()); |
|
148 | 148 | } |
149 | 149 | } |
150 | 150 | $running_total_of_children += $original_li_total; |
151 | 151 | $running_total_of_children_under_consideration += $child_line_item->total(); |
152 | - if ( $child_line_item->OBJ_type() == 'Ticket' ) { |
|
152 | + if ($child_line_item->OBJ_type() == 'Ticket') { |
|
153 | 153 | $total_child_ticket_quantity += $child_line_item->quantity(); |
154 | 154 | } |
155 | 155 | } |
156 | - $line_item->set_total( $running_total_of_children_under_consideration ); |
|
157 | - if ( $line_item->quantity() ) { |
|
158 | - $line_item->set_unit_price( $running_total_of_children_under_consideration / $line_item->quantity() ); |
|
156 | + $line_item->set_total($running_total_of_children_under_consideration); |
|
157 | + if ($line_item->quantity()) { |
|
158 | + $line_item->set_unit_price($running_total_of_children_under_consideration / $line_item->quantity()); |
|
159 | 159 | } else { |
160 | - $line_item->set_unit_price( 0 ); |
|
160 | + $line_item->set_unit_price(0); |
|
161 | 161 | } |
162 | - if ( $line_item->OBJ_type() == 'Event' ) { |
|
163 | - $line_item->set_quantity( $total_child_ticket_quantity ); |
|
162 | + if ($line_item->OBJ_type() == 'Event') { |
|
163 | + $line_item->set_quantity($total_child_ticket_quantity); |
|
164 | 164 | } |
165 | 165 | return $line_item; |
166 | 166 | } |
@@ -174,18 +174,18 @@ discard block |
||
174 | 174 | * @param EEI_Line_Item $line_item |
175 | 175 | * @return EEI_Line_Item |
176 | 176 | */ |
177 | - protected function _adjust_line_item_quantity( EEI_Line_Item $line_item ) { |
|
177 | + protected function _adjust_line_item_quantity(EEI_Line_Item $line_item) { |
|
178 | 178 | // is this a ticket ? |
179 | - if ( $line_item->type() === EEM_Line_Item::type_line_item && $line_item->OBJ_type() == 'Ticket' ) { |
|
179 | + if ($line_item->type() === EEM_Line_Item::type_line_item && $line_item->OBJ_type() == 'Ticket') { |
|
180 | 180 | $this->_current_registration = null; |
181 | 181 | $quantity = 0; |
182 | 182 | // if this ticket is billable at this moment, then we should have a positive quantity |
183 | 183 | if ( |
184 | - isset( $this->_line_item_registrations[ $line_item->code() ] ) |
|
185 | - && is_array( $this->_line_item_registrations[ $line_item->code() ] ) |
|
184 | + isset($this->_line_item_registrations[$line_item->code()]) |
|
185 | + && is_array($this->_line_item_registrations[$line_item->code()]) |
|
186 | 186 | ) { |
187 | 187 | // set quantity based on number of open registrations for this ticket |
188 | - foreach ( $this->_line_item_registrations[ $line_item->code() ] as $registration ) { |
|
188 | + foreach ($this->_line_item_registrations[$line_item->code()] as $registration) { |
|
189 | 189 | if ( |
190 | 190 | $registration instanceof EE_Registration |
191 | 191 | ) { |
@@ -194,8 +194,8 @@ discard block |
||
194 | 194 | } |
195 | 195 | } |
196 | 196 | } |
197 | - $line_item->set_quantity( $quantity ); |
|
198 | - $line_item->set_total( $line_item->unit_price() * $line_item->quantity() ); |
|
197 | + $line_item->set_quantity($quantity); |
|
198 | + $line_item->set_total($line_item->unit_price() * $line_item->quantity()); |
|
199 | 199 | } |
200 | 200 | return $line_item; |
201 | 201 | } |
@@ -1,5 +1,5 @@ discard block |
||
1 | -<?php if ( !defined( 'EVENT_ESPRESSO_VERSION' ) ) { |
|
2 | - exit( 'No direct script access allowed' ); |
|
1 | +<?php if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
|
2 | + exit('No direct script access allowed'); |
|
3 | 3 | } |
4 | 4 | /** |
5 | 5 | * Event Espresso |
@@ -50,9 +50,9 @@ discard block |
||
50 | 50 | * date_format and the second value is the time format |
51 | 51 | * @return EE_Line_Item |
52 | 52 | */ |
53 | - public static function new_instance( $props_n_values = array(), $timezone = null, $date_formats = array() ) { |
|
54 | - $has_object = parent::_check_for_object( $props_n_values, __CLASS__, $timezone, $date_formats ); |
|
55 | - return $has_object ? $has_object : new self( $props_n_values, false, $timezone, $date_formats ); |
|
53 | + public static function new_instance($props_n_values = array(), $timezone = null, $date_formats = array()) { |
|
54 | + $has_object = parent::_check_for_object($props_n_values, __CLASS__, $timezone, $date_formats); |
|
55 | + return $has_object ? $has_object : new self($props_n_values, false, $timezone, $date_formats); |
|
56 | 56 | } |
57 | 57 | |
58 | 58 | |
@@ -63,8 +63,8 @@ discard block |
||
63 | 63 | * the website will be used. |
64 | 64 | * @return EE_Line_Item |
65 | 65 | */ |
66 | - public static function new_instance_from_db( $props_n_values = array(), $timezone = null ) { |
|
67 | - return new self( $props_n_values, TRUE, $timezone ); |
|
66 | + public static function new_instance_from_db($props_n_values = array(), $timezone = null) { |
|
67 | + return new self($props_n_values, TRUE, $timezone); |
|
68 | 68 | } |
69 | 69 | |
70 | 70 | |
@@ -75,10 +75,10 @@ discard block |
||
75 | 75 | * @param bool $bydb |
76 | 76 | * @param string $timezone |
77 | 77 | */ |
78 | - protected function __construct( $fieldValues = array(), $bydb = FALSE, $timezone = '' ) { |
|
79 | - parent::__construct( $fieldValues, $bydb, $timezone ); |
|
80 | - if ( ! $this->get( 'LIN_code' ) ) { |
|
81 | - $this->set_code( $this->generate_code() ); |
|
78 | + protected function __construct($fieldValues = array(), $bydb = FALSE, $timezone = '') { |
|
79 | + parent::__construct($fieldValues, $bydb, $timezone); |
|
80 | + if ( ! $this->get('LIN_code')) { |
|
81 | + $this->set_code($this->generate_code()); |
|
82 | 82 | } |
83 | 83 | } |
84 | 84 | |
@@ -89,7 +89,7 @@ discard block |
||
89 | 89 | * @return int |
90 | 90 | */ |
91 | 91 | public function ID() { |
92 | - return $this->get( 'LIN_ID' ); |
|
92 | + return $this->get('LIN_ID'); |
|
93 | 93 | } |
94 | 94 | |
95 | 95 | |
@@ -99,7 +99,7 @@ discard block |
||
99 | 99 | * @return int |
100 | 100 | */ |
101 | 101 | public function TXN_ID() { |
102 | - return $this->get( 'TXN_ID' ); |
|
102 | + return $this->get('TXN_ID'); |
|
103 | 103 | } |
104 | 104 | |
105 | 105 | |
@@ -108,8 +108,8 @@ discard block |
||
108 | 108 | * Sets TXN_ID |
109 | 109 | * @param int $TXN_ID |
110 | 110 | */ |
111 | - public function set_TXN_ID( $TXN_ID ) { |
|
112 | - $this->set( 'TXN_ID', $TXN_ID ); |
|
111 | + public function set_TXN_ID($TXN_ID) { |
|
112 | + $this->set('TXN_ID', $TXN_ID); |
|
113 | 113 | } |
114 | 114 | |
115 | 115 | |
@@ -119,9 +119,9 @@ discard block |
||
119 | 119 | * @return string |
120 | 120 | */ |
121 | 121 | public function name() { |
122 | - $name = $this->get( 'LIN_name' ); |
|
123 | - if( ! $name ){ |
|
124 | - $name = ucwords( str_replace( '-', ' ', $this->type() ) ); |
|
122 | + $name = $this->get('LIN_name'); |
|
123 | + if ( ! $name) { |
|
124 | + $name = ucwords(str_replace('-', ' ', $this->type())); |
|
125 | 125 | } |
126 | 126 | return $name; |
127 | 127 | } |
@@ -132,8 +132,8 @@ discard block |
||
132 | 132 | * Sets name |
133 | 133 | * @param string $name |
134 | 134 | */ |
135 | - public function set_name( $name ) { |
|
136 | - $this->set( 'LIN_name', $name ); |
|
135 | + public function set_name($name) { |
|
136 | + $this->set('LIN_name', $name); |
|
137 | 137 | } |
138 | 138 | |
139 | 139 | |
@@ -143,7 +143,7 @@ discard block |
||
143 | 143 | * @return string |
144 | 144 | */ |
145 | 145 | public function desc() { |
146 | - return $this->get( 'LIN_desc' ); |
|
146 | + return $this->get('LIN_desc'); |
|
147 | 147 | } |
148 | 148 | |
149 | 149 | |
@@ -152,8 +152,8 @@ discard block |
||
152 | 152 | * Sets desc |
153 | 153 | * @param string $desc |
154 | 154 | */ |
155 | - public function set_desc( $desc ) { |
|
156 | - $this->set( 'LIN_desc', $desc ); |
|
155 | + public function set_desc($desc) { |
|
156 | + $this->set('LIN_desc', $desc); |
|
157 | 157 | } |
158 | 158 | |
159 | 159 | |
@@ -163,7 +163,7 @@ discard block |
||
163 | 163 | * @return int |
164 | 164 | */ |
165 | 165 | public function quantity() { |
166 | - return $this->get( 'LIN_quantity' ); |
|
166 | + return $this->get('LIN_quantity'); |
|
167 | 167 | } |
168 | 168 | |
169 | 169 | |
@@ -172,8 +172,8 @@ discard block |
||
172 | 172 | * Sets quantity |
173 | 173 | * @param int $quantity |
174 | 174 | */ |
175 | - function set_quantity( $quantity ) { |
|
176 | - $this->set( 'LIN_quantity', max( $quantity, 0 ) ); |
|
175 | + function set_quantity($quantity) { |
|
176 | + $this->set('LIN_quantity', max($quantity, 0)); |
|
177 | 177 | } |
178 | 178 | |
179 | 179 | |
@@ -183,7 +183,7 @@ discard block |
||
183 | 183 | * @return string |
184 | 184 | */ |
185 | 185 | public function OBJ_ID() { |
186 | - return $this->get( 'OBJ_ID' ); |
|
186 | + return $this->get('OBJ_ID'); |
|
187 | 187 | } |
188 | 188 | |
189 | 189 | |
@@ -192,8 +192,8 @@ discard block |
||
192 | 192 | * Sets item_id |
193 | 193 | * @param string $item_id |
194 | 194 | */ |
195 | - public function set_OBJ_ID( $item_id ) { |
|
196 | - $this->set( 'OBJ_ID', $item_id ); |
|
195 | + public function set_OBJ_ID($item_id) { |
|
196 | + $this->set('OBJ_ID', $item_id); |
|
197 | 197 | } |
198 | 198 | |
199 | 199 | |
@@ -203,7 +203,7 @@ discard block |
||
203 | 203 | * @return string |
204 | 204 | */ |
205 | 205 | public function OBJ_type() { |
206 | - return $this->get( 'OBJ_type' ); |
|
206 | + return $this->get('OBJ_type'); |
|
207 | 207 | } |
208 | 208 | |
209 | 209 | |
@@ -240,8 +240,8 @@ discard block |
||
240 | 240 | * Sets item_type |
241 | 241 | * @param string $OBJ_type |
242 | 242 | */ |
243 | - public function set_OBJ_type( $OBJ_type ) { |
|
244 | - $this->set( 'OBJ_type', $OBJ_type ); |
|
243 | + public function set_OBJ_type($OBJ_type) { |
|
244 | + $this->set('OBJ_type', $OBJ_type); |
|
245 | 245 | } |
246 | 246 | |
247 | 247 | |
@@ -251,7 +251,7 @@ discard block |
||
251 | 251 | * @return float |
252 | 252 | */ |
253 | 253 | public function unit_price() { |
254 | - return $this->get( 'LIN_unit_price' ); |
|
254 | + return $this->get('LIN_unit_price'); |
|
255 | 255 | } |
256 | 256 | |
257 | 257 | |
@@ -261,8 +261,8 @@ discard block |
||
261 | 261 | * |
262 | 262 | * @param float $unit_price |
263 | 263 | */ |
264 | - public function set_unit_price( $unit_price ) { |
|
265 | - $this->set( 'LIN_unit_price', $unit_price ); |
|
264 | + public function set_unit_price($unit_price) { |
|
265 | + $this->set('LIN_unit_price', $unit_price); |
|
266 | 266 | } |
267 | 267 | |
268 | 268 | |
@@ -273,19 +273,19 @@ discard block |
||
273 | 273 | * @return boolean |
274 | 274 | */ |
275 | 275 | public function is_percent() { |
276 | - if( $this->is_tax_sub_total() ) { |
|
276 | + if ($this->is_tax_sub_total()) { |
|
277 | 277 | //tax subtotals HAVE a percent on them, that percentage only applies |
278 | 278 | //to taxable items, so its' an exception. Treat it like a flat line item |
279 | 279 | return false; |
280 | 280 | } |
281 | - $unit_price = abs( $this->get( 'LIN_unit_price' ) ); |
|
282 | - $percent = abs( $this->get( 'LIN_percent' ) ); |
|
283 | - if ( $unit_price < .001 && $percent ) { |
|
281 | + $unit_price = abs($this->get('LIN_unit_price')); |
|
282 | + $percent = abs($this->get('LIN_percent')); |
|
283 | + if ($unit_price < .001 && $percent) { |
|
284 | 284 | return TRUE; |
285 | - } elseif ( $unit_price >= .001 && !$percent ) { |
|
285 | + } elseif ($unit_price >= .001 && ! $percent) { |
|
286 | 286 | return FALSE; |
287 | - } elseif ( $unit_price >= .001 && $percent ) { |
|
288 | - throw new EE_Error( sprintf( __( "A Line Item can not have a unit price of (%s) AND a percent (%s)!", "event_espresso" ), $unit_price, $percent ) ); |
|
287 | + } elseif ($unit_price >= .001 && $percent) { |
|
288 | + throw new EE_Error(sprintf(__("A Line Item can not have a unit price of (%s) AND a percent (%s)!", "event_espresso"), $unit_price, $percent)); |
|
289 | 289 | } else { |
290 | 290 | // if they're both 0, assume its not a percent item |
291 | 291 | return FALSE; |
@@ -299,7 +299,7 @@ discard block |
||
299 | 299 | * @return float |
300 | 300 | */ |
301 | 301 | public function percent() { |
302 | - return $this->get( 'LIN_percent' ); |
|
302 | + return $this->get('LIN_percent'); |
|
303 | 303 | } |
304 | 304 | |
305 | 305 | |
@@ -308,8 +308,8 @@ discard block |
||
308 | 308 | * Sets percent (between 100-0.01) |
309 | 309 | * @param float $percent |
310 | 310 | */ |
311 | - public function set_percent( $percent ) { |
|
312 | - $this->set( 'LIN_percent', $percent ); |
|
311 | + public function set_percent($percent) { |
|
312 | + $this->set('LIN_percent', $percent); |
|
313 | 313 | } |
314 | 314 | |
315 | 315 | |
@@ -319,7 +319,7 @@ discard block |
||
319 | 319 | * @return float |
320 | 320 | */ |
321 | 321 | public function total() { |
322 | - return $this->get( 'LIN_total' ); |
|
322 | + return $this->get('LIN_total'); |
|
323 | 323 | } |
324 | 324 | |
325 | 325 | |
@@ -328,8 +328,8 @@ discard block |
||
328 | 328 | * Sets total |
329 | 329 | * @param float $total |
330 | 330 | */ |
331 | - public function set_total( $total ) { |
|
332 | - $this->set( 'LIN_total', $total ); |
|
331 | + public function set_total($total) { |
|
332 | + $this->set('LIN_total', $total); |
|
333 | 333 | } |
334 | 334 | |
335 | 335 | |
@@ -339,7 +339,7 @@ discard block |
||
339 | 339 | * @return int |
340 | 340 | */ |
341 | 341 | public function order() { |
342 | - return $this->get( 'LIN_order' ); |
|
342 | + return $this->get('LIN_order'); |
|
343 | 343 | } |
344 | 344 | |
345 | 345 | |
@@ -348,8 +348,8 @@ discard block |
||
348 | 348 | * Sets order |
349 | 349 | * @param int $order |
350 | 350 | */ |
351 | - public function set_order( $order ) { |
|
352 | - $this->set( 'LIN_order', $order ); |
|
351 | + public function set_order($order) { |
|
352 | + $this->set('LIN_order', $order); |
|
353 | 353 | } |
354 | 354 | |
355 | 355 | |
@@ -359,7 +359,7 @@ discard block |
||
359 | 359 | * @return int |
360 | 360 | */ |
361 | 361 | public function parent_ID() { |
362 | - return $this->get( 'LIN_parent' ); |
|
362 | + return $this->get('LIN_parent'); |
|
363 | 363 | } |
364 | 364 | |
365 | 365 | |
@@ -368,8 +368,8 @@ discard block |
||
368 | 368 | * Sets parent |
369 | 369 | * @param int $parent |
370 | 370 | */ |
371 | - public function set_parent_ID( $parent ) { |
|
372 | - $this->set( 'LIN_parent', $parent ); |
|
371 | + public function set_parent_ID($parent) { |
|
372 | + $this->set('LIN_parent', $parent); |
|
373 | 373 | } |
374 | 374 | |
375 | 375 | |
@@ -379,7 +379,7 @@ discard block |
||
379 | 379 | * @return string |
380 | 380 | */ |
381 | 381 | public function type() { |
382 | - return $this->get( 'LIN_type' ); |
|
382 | + return $this->get('LIN_type'); |
|
383 | 383 | } |
384 | 384 | |
385 | 385 | |
@@ -388,8 +388,8 @@ discard block |
||
388 | 388 | * Sets type |
389 | 389 | * @param string $type |
390 | 390 | */ |
391 | - public function set_type( $type ) { |
|
392 | - $this->set( 'LIN_type', $type ); |
|
391 | + public function set_type($type) { |
|
392 | + $this->set('LIN_type', $type); |
|
393 | 393 | } |
394 | 394 | |
395 | 395 | |
@@ -402,8 +402,8 @@ discard block |
||
402 | 402 | * @return EE_Line_Item |
403 | 403 | */ |
404 | 404 | public function parent() { |
405 | - if( $this->ID() ) { |
|
406 | - return $this->get_model()->get_one_by_ID( $this->parent_ID() ); |
|
405 | + if ($this->ID()) { |
|
406 | + return $this->get_model()->get_one_by_ID($this->parent_ID()); |
|
407 | 407 | } else { |
408 | 408 | return $this->_parent; |
409 | 409 | } |
@@ -416,13 +416,13 @@ discard block |
||
416 | 416 | * @return EE_Line_Item[] |
417 | 417 | */ |
418 | 418 | public function children() { |
419 | - if ( $this->ID() ) { |
|
419 | + if ($this->ID()) { |
|
420 | 420 | return $this->get_model()->get_all( |
421 | 421 | array( |
422 | - array( 'LIN_parent' => $this->ID() ), |
|
423 | - 'order_by' => array( 'LIN_order' => 'ASC' ) ) ); |
|
422 | + array('LIN_parent' => $this->ID()), |
|
423 | + 'order_by' => array('LIN_order' => 'ASC') ) ); |
|
424 | 424 | } else { |
425 | - if ( ! is_array( $this->_children ) ) { |
|
425 | + if ( ! is_array($this->_children)) { |
|
426 | 426 | $this->_children = array(); |
427 | 427 | } |
428 | 428 | return $this->_children; |
@@ -436,7 +436,7 @@ discard block |
||
436 | 436 | * @return string |
437 | 437 | */ |
438 | 438 | public function code() { |
439 | - return $this->get( 'LIN_code' ); |
|
439 | + return $this->get('LIN_code'); |
|
440 | 440 | } |
441 | 441 | |
442 | 442 | |
@@ -445,8 +445,8 @@ discard block |
||
445 | 445 | * Sets code |
446 | 446 | * @param string $code |
447 | 447 | */ |
448 | - public function set_code( $code ) { |
|
449 | - $this->set( 'LIN_code', $code ); |
|
448 | + public function set_code($code) { |
|
449 | + $this->set('LIN_code', $code); |
|
450 | 450 | } |
451 | 451 | |
452 | 452 | |
@@ -456,7 +456,7 @@ discard block |
||
456 | 456 | * @return boolean |
457 | 457 | */ |
458 | 458 | public function is_taxable() { |
459 | - return $this->get( 'LIN_is_taxable' ); |
|
459 | + return $this->get('LIN_is_taxable'); |
|
460 | 460 | } |
461 | 461 | |
462 | 462 | |
@@ -465,8 +465,8 @@ discard block |
||
465 | 465 | * Sets is_taxable |
466 | 466 | * @param boolean $is_taxable |
467 | 467 | */ |
468 | - public function set_is_taxable( $is_taxable ) { |
|
469 | - $this->set( 'LIN_is_taxable', $is_taxable ); |
|
468 | + public function set_is_taxable($is_taxable) { |
|
469 | + $this->set('LIN_is_taxable', $is_taxable); |
|
470 | 470 | } |
471 | 471 | |
472 | 472 | |
@@ -481,7 +481,7 @@ discard block |
||
481 | 481 | */ |
482 | 482 | public function get_object() { |
483 | 483 | $model_name_of_related_obj = $this->OBJ_type(); |
484 | - return $this->get_model()->has_relation( $model_name_of_related_obj ) ? $this->get_first_related( $model_name_of_related_obj ) : NULL; |
|
484 | + return $this->get_model()->has_relation($model_name_of_related_obj) ? $this->get_first_related($model_name_of_related_obj) : NULL; |
|
485 | 485 | } |
486 | 486 | |
487 | 487 | |
@@ -492,11 +492,11 @@ discard block |
||
492 | 492 | * @param array $query_params |
493 | 493 | * @return EE_Ticket |
494 | 494 | */ |
495 | - public function ticket( $query_params = array() ) { |
|
495 | + public function ticket($query_params = array()) { |
|
496 | 496 | //we're going to assume that when this method is called we always want to receive the attached ticket EVEN if that ticket is archived. This can be overridden via the incoming $query_params argument |
497 | - $remove_defaults = array( 'default_where_conditions' => 'none' ); |
|
498 | - $query_params = array_merge( $remove_defaults, $query_params ); |
|
499 | - return $this->get_first_related( 'Ticket', $query_params ); |
|
497 | + $remove_defaults = array('default_where_conditions' => 'none'); |
|
498 | + $query_params = array_merge($remove_defaults, $query_params); |
|
499 | + return $this->get_first_related('Ticket', $query_params); |
|
500 | 500 | } |
501 | 501 | |
502 | 502 | |
@@ -506,11 +506,11 @@ discard block |
||
506 | 506 | * @return EE_Datetime | NULL |
507 | 507 | */ |
508 | 508 | public function get_ticket_datetime() { |
509 | - if ( $this->OBJ_type() === 'Ticket' ) { |
|
509 | + if ($this->OBJ_type() === 'Ticket') { |
|
510 | 510 | $ticket = $this->ticket(); |
511 | - if ( $ticket instanceof EE_Ticket ) { |
|
511 | + if ($ticket instanceof EE_Ticket) { |
|
512 | 512 | $datetime = $ticket->first_datetime(); |
513 | - if ( $datetime instanceof EE_Datetime ) { |
|
513 | + if ($datetime instanceof EE_Datetime) { |
|
514 | 514 | return $datetime; |
515 | 515 | } |
516 | 516 | } |
@@ -526,9 +526,9 @@ discard block |
||
526 | 526 | * @return string |
527 | 527 | */ |
528 | 528 | public function ticket_event_name() { |
529 | - $event_name = __( "Unknown", "event_espresso" ); |
|
529 | + $event_name = __("Unknown", "event_espresso"); |
|
530 | 530 | $event = $this->ticket_event(); |
531 | - if ( $event instanceof EE_Event ) { |
|
531 | + if ($event instanceof EE_Event) { |
|
532 | 532 | $event_name = $event->name(); |
533 | 533 | } |
534 | 534 | return $event_name; |
@@ -542,9 +542,9 @@ discard block |
||
542 | 542 | public function ticket_event() { |
543 | 543 | $event = null; |
544 | 544 | $ticket = $this->ticket(); |
545 | - if ( $ticket instanceof EE_Ticket ) { |
|
545 | + if ($ticket instanceof EE_Ticket) { |
|
546 | 546 | $datetime = $ticket->first_datetime(); |
547 | - if ( $datetime instanceof EE_Datetime ) { |
|
547 | + if ($datetime instanceof EE_Datetime) { |
|
548 | 548 | $event = $datetime->event(); |
549 | 549 | } |
550 | 550 | } |
@@ -559,11 +559,11 @@ discard block |
||
559 | 559 | * @param string $time_format |
560 | 560 | * @return string |
561 | 561 | */ |
562 | - public function ticket_datetime_start( $date_format = '', $time_format = '' ) { |
|
563 | - $first_datetime_string = __( "Unknown", "event_espresso" ); |
|
562 | + public function ticket_datetime_start($date_format = '', $time_format = '') { |
|
563 | + $first_datetime_string = __("Unknown", "event_espresso"); |
|
564 | 564 | $datetime = $this->get_ticket_datetime(); |
565 | - if ( $datetime ) { |
|
566 | - $first_datetime_string = $datetime->start_date_and_time( $date_format, $time_format ); |
|
565 | + if ($datetime) { |
|
566 | + $first_datetime_string = $datetime->start_date_and_time($date_format, $time_format); |
|
567 | 567 | } |
568 | 568 | return $first_datetime_string; |
569 | 569 | } |
@@ -578,26 +578,26 @@ discard block |
||
578 | 578 | * @return bool success |
579 | 579 | * @throws \EE_Error |
580 | 580 | */ |
581 | - public function add_child_line_item( EEI_Line_Item $line_item, $set_order = true ) { |
|
581 | + public function add_child_line_item(EEI_Line_Item $line_item, $set_order = true) { |
|
582 | 582 | // should we calculate the LIN_order for this line item ? |
583 | - if ( $set_order || $line_item->order() === null ) { |
|
584 | - $line_item->set_order( count( $this->children() ) ); |
|
583 | + if ($set_order || $line_item->order() === null) { |
|
584 | + $line_item->set_order(count($this->children())); |
|
585 | 585 | } |
586 | - if ( $this->ID() ) { |
|
586 | + if ($this->ID()) { |
|
587 | 587 | //check for any duplicate line items (with the same code), if so, this replaces it |
588 | - $line_item_with_same_code = $this->get_child_line_item( $line_item->code() ); |
|
589 | - if( $line_item_with_same_code instanceof EE_Line_Item && $line_item_with_same_code !== $line_item ) { |
|
590 | - $this->delete_child_line_item( $line_item_with_same_code->code() ); |
|
588 | + $line_item_with_same_code = $this->get_child_line_item($line_item->code()); |
|
589 | + if ($line_item_with_same_code instanceof EE_Line_Item && $line_item_with_same_code !== $line_item) { |
|
590 | + $this->delete_child_line_item($line_item_with_same_code->code()); |
|
591 | 591 | } |
592 | - $line_item->set_parent_ID( $this->ID() ); |
|
593 | - if( $this->TXN_ID() ){ |
|
594 | - $line_item->set_TXN_ID( $this->TXN_ID() ); |
|
592 | + $line_item->set_parent_ID($this->ID()); |
|
593 | + if ($this->TXN_ID()) { |
|
594 | + $line_item->set_TXN_ID($this->TXN_ID()); |
|
595 | 595 | } |
596 | 596 | return $line_item->save(); |
597 | 597 | } else { |
598 | - $this->_children[ $line_item->code() ] = $line_item; |
|
599 | - if( $line_item->parent() != $this ) { |
|
600 | - $line_item->set_parent( $this ); |
|
598 | + $this->_children[$line_item->code()] = $line_item; |
|
599 | + if ($line_item->parent() != $this) { |
|
600 | + $line_item->set_parent($this); |
|
601 | 601 | } |
602 | 602 | return TRUE; |
603 | 603 | } |
@@ -611,16 +611,16 @@ discard block |
||
611 | 611 | * @param EE_Line_Item $line_item |
612 | 612 | * |
613 | 613 | */ |
614 | - public function set_parent( $line_item ) { |
|
615 | - if ( $this->ID() ) { |
|
616 | - if( ! $line_item->ID() ) { |
|
614 | + public function set_parent($line_item) { |
|
615 | + if ($this->ID()) { |
|
616 | + if ( ! $line_item->ID()) { |
|
617 | 617 | $line_item->save(); |
618 | 618 | } |
619 | - $this->set_parent_ID( $line_item->ID() ); |
|
619 | + $this->set_parent_ID($line_item->ID()); |
|
620 | 620 | $this->save(); |
621 | 621 | } else { |
622 | 622 | $this->_parent = $line_item; |
623 | - $this->set_parent_ID( $line_item->ID() ); |
|
623 | + $this->set_parent_ID($line_item->ID()); |
|
624 | 624 | } |
625 | 625 | } |
626 | 626 | |
@@ -633,11 +633,11 @@ discard block |
||
633 | 633 | * @param string $code |
634 | 634 | * @return EE_Line_Item |
635 | 635 | */ |
636 | - public function get_child_line_item( $code ) { |
|
637 | - if ( $this->ID() ) { |
|
638 | - return $this->get_model()->get_one( array( array( 'LIN_parent' => $this->ID(), 'LIN_code' => $code ) ) ); |
|
636 | + public function get_child_line_item($code) { |
|
637 | + if ($this->ID()) { |
|
638 | + return $this->get_model()->get_one(array(array('LIN_parent' => $this->ID(), 'LIN_code' => $code))); |
|
639 | 639 | } else { |
640 | - return isset( $this->_children[ $code ] ) ? $this->_children[ $code ] : null; |
|
640 | + return isset($this->_children[$code]) ? $this->_children[$code] : null; |
|
641 | 641 | } |
642 | 642 | } |
643 | 643 | |
@@ -648,10 +648,10 @@ discard block |
||
648 | 648 | * @return int |
649 | 649 | */ |
650 | 650 | public function delete_children_line_items() { |
651 | - if ( $this->ID() ) { |
|
652 | - return $this->get_model()->delete( array( array( 'LIN_parent' => $this->ID() ) ) ); |
|
651 | + if ($this->ID()) { |
|
652 | + return $this->get_model()->delete(array(array('LIN_parent' => $this->ID()))); |
|
653 | 653 | } else { |
654 | - $count = count( $this->_children ); |
|
654 | + $count = count($this->_children); |
|
655 | 655 | $this->_children = array(); |
656 | 656 | return $count; |
657 | 657 | } |
@@ -668,25 +668,25 @@ discard block |
||
668 | 668 | * @param bool $stop_search_once_found |
669 | 669 | * @return int count of items deleted (or simply removed from the line item's cache, if not has not been saved to the DB yet) |
670 | 670 | */ |
671 | - public function delete_child_line_item( $code, $stop_search_once_found = true ) { |
|
672 | - if ( $this->ID() ) { |
|
671 | + public function delete_child_line_item($code, $stop_search_once_found = true) { |
|
672 | + if ($this->ID()) { |
|
673 | 673 | $items_deleted = 0; |
674 | - if( $this->code() == $code ) { |
|
675 | - $items_deleted += EEH_Line_Item::delete_all_child_items( $this ); |
|
674 | + if ($this->code() == $code) { |
|
675 | + $items_deleted += EEH_Line_Item::delete_all_child_items($this); |
|
676 | 676 | $items_deleted += (int) $this->delete(); |
677 | - if( $stop_search_once_found ){ |
|
677 | + if ($stop_search_once_found) { |
|
678 | 678 | return $items_deleted; |
679 | 679 | } |
680 | 680 | } |
681 | - foreach( $this->children() as $child_line_item ) { |
|
682 | - $items_deleted += $child_line_item->delete_child_line_item( $code, $stop_search_once_found ); |
|
681 | + foreach ($this->children() as $child_line_item) { |
|
682 | + $items_deleted += $child_line_item->delete_child_line_item($code, $stop_search_once_found); |
|
683 | 683 | } |
684 | 684 | return $items_deleted; |
685 | 685 | } else { |
686 | - if( isset( $this->_children[ $code ] ) ) { |
|
687 | - unset( $this->_children[ $code ] ); |
|
686 | + if (isset($this->_children[$code])) { |
|
687 | + unset($this->_children[$code]); |
|
688 | 688 | return 1; |
689 | - }else{ |
|
689 | + } else { |
|
690 | 690 | return 0; |
691 | 691 | } |
692 | 692 | } |
@@ -699,9 +699,9 @@ discard block |
||
699 | 699 | * @return boolean |
700 | 700 | */ |
701 | 701 | public function delete_if_childless_subtotal() { |
702 | - if( $this->ID() && |
|
702 | + if ($this->ID() && |
|
703 | 703 | $this->type() == EEM_Line_Item::type_sub_total && |
704 | - ! $this->children() ) { |
|
704 | + ! $this->children()) { |
|
705 | 705 | return $this->delete(); |
706 | 706 | } else { |
707 | 707 | return false; |
@@ -716,7 +716,7 @@ discard block |
||
716 | 716 | */ |
717 | 717 | public function generate_code() { |
718 | 718 | // each line item in the cart requires a unique identifier |
719 | - return md5( $this->get( 'OBJ_type' ) . $this->get( 'OBJ_ID' ) . microtime() ); |
|
719 | + return md5($this->get('OBJ_type').$this->get('OBJ_ID').microtime()); |
|
720 | 720 | } |
721 | 721 | |
722 | 722 | |
@@ -799,7 +799,7 @@ discard block |
||
799 | 799 | * @return string like '2, 004.00', formatted according to the localized currency |
800 | 800 | */ |
801 | 801 | public function unit_price_no_code() { |
802 | - return $this->get_pretty( 'LIN_unit_price', 'no_currency_code' ); |
|
802 | + return $this->get_pretty('LIN_unit_price', 'no_currency_code'); |
|
803 | 803 | } |
804 | 804 | |
805 | 805 | |
@@ -809,7 +809,7 @@ discard block |
||
809 | 809 | * @return string like '2, 004.00', formatted according to the localized currency |
810 | 810 | */ |
811 | 811 | public function total_no_code() { |
812 | - return $this->get_pretty( 'LIN_total', 'no_currency_code' ); |
|
812 | + return $this->get_pretty('LIN_total', 'no_currency_code'); |
|
813 | 813 | } |
814 | 814 | |
815 | 815 | |
@@ -829,17 +829,17 @@ discard block |
||
829 | 829 | $tax_total = $this->recalculate_taxes_and_tax_total(); |
830 | 830 | $total = $pre_tax_total + $tax_total; |
831 | 831 | // no negative totals plz |
832 | - $total = max( $total, 0 ); |
|
833 | - $this->set_total( $total ); |
|
832 | + $total = max($total, 0); |
|
833 | + $this->set_total($total); |
|
834 | 834 | //only update the related transaction's total |
835 | 835 | //if we intend to save this line item and its a grand total |
836 | - if( |
|
836 | + if ( |
|
837 | 837 | $this->allow_persist() && |
838 | 838 | $this->type() === EEM_Line_Item::type_total && |
839 | 839 | $this->transaction() instanceof EE_Transaction |
840 | - ){ |
|
841 | - $this->transaction()->set_total( $total ); |
|
842 | - if ( $this->transaction()->ID() ) { |
|
840 | + ) { |
|
841 | + $this->transaction()->set_total($total); |
|
842 | + if ($this->transaction()->ID()) { |
|
843 | 843 | $this->transaction()->save(); |
844 | 844 | } |
845 | 845 | } |
@@ -858,47 +858,47 @@ discard block |
||
858 | 858 | public function recalculate_pre_tax_total() { |
859 | 859 | $total = 0; |
860 | 860 | $my_children = $this->children(); |
861 | - $has_children = ! empty( $my_children ); |
|
862 | - if ( $has_children && $this->is_line_item() ) { |
|
863 | - $total = $this->_recalculate_pretax_total_for_line_item( $total, $my_children ); |
|
864 | - } elseif ( ! $has_children && ( $this->is_sub_line_item() || $this->is_line_item() ) ) { |
|
861 | + $has_children = ! empty($my_children); |
|
862 | + if ($has_children && $this->is_line_item()) { |
|
863 | + $total = $this->_recalculate_pretax_total_for_line_item($total, $my_children); |
|
864 | + } elseif ( ! $has_children && ($this->is_sub_line_item() || $this->is_line_item())) { |
|
865 | 865 | $total = $this->unit_price() * $this->quantity(); |
866 | - } elseif( $this->is_sub_total() || $this->is_total() ) { |
|
867 | - $total = $this->_recalculate_pretax_total_for_subtotal( $total, $my_children ); |
|
868 | - } elseif ( $this->is_tax_sub_total() || $this->is_tax() || $this->is_cancelled() ) { |
|
866 | + } elseif ($this->is_sub_total() || $this->is_total()) { |
|
867 | + $total = $this->_recalculate_pretax_total_for_subtotal($total, $my_children); |
|
868 | + } elseif ($this->is_tax_sub_total() || $this->is_tax() || $this->is_cancelled()) { |
|
869 | 869 | // completely ignore tax totals, tax sub-totals, and cancelled line items, when calculating the pre-tax-total |
870 | 870 | return 0; |
871 | 871 | } |
872 | 872 | // ensure all non-line items and non-sub-line-items have a quantity of 1 (except for Events) |
873 | - if( |
|
873 | + if ( |
|
874 | 874 | ! $this->is_line_item() && |
875 | 875 | ! $this->is_sub_line_item() && |
876 | 876 | ! $this->is_cancellation() |
877 | 877 | ) { |
878 | - if ( $this->OBJ_type() !== 'Event' ) { |
|
879 | - $this->set_quantity( 1 ); |
|
878 | + if ($this->OBJ_type() !== 'Event') { |
|
879 | + $this->set_quantity(1); |
|
880 | 880 | } |
881 | - if( ! $this->is_percent() ) { |
|
882 | - $this->set_unit_price( $this->total() ); |
|
881 | + if ( ! $this->is_percent()) { |
|
882 | + $this->set_unit_price($this->total()); |
|
883 | 883 | } |
884 | 884 | } |
885 | 885 | |
886 | 886 | //we don't want to bother saving grand totals, because that needs to factor in taxes anyways |
887 | 887 | //so it ought to be |
888 | - if( ! $this->is_total() ) { |
|
889 | - $this->set_total( $total ); |
|
888 | + if ( ! $this->is_total()) { |
|
889 | + $this->set_total($total); |
|
890 | 890 | //if not a percent line item, make sure we keep the unit price in sync |
891 | - if( |
|
891 | + if ( |
|
892 | 892 | $has_children |
893 | 893 | && $this->is_line_item() |
894 | 894 | && ! $this->is_percent() |
895 | 895 | ) { |
896 | - if( $this->quantity() === 0 ){ |
|
896 | + if ($this->quantity() === 0) { |
|
897 | 897 | $new_unit_price = 0; |
898 | 898 | } else { |
899 | 899 | $new_unit_price = $this->total() / $this->quantity(); |
900 | 900 | } |
901 | - $this->set_unit_price( $new_unit_price ); |
|
901 | + $this->set_unit_price($new_unit_price); |
|
902 | 902 | } |
903 | 903 | $this->maybe_save(); |
904 | 904 | } |
@@ -918,39 +918,39 @@ discard block |
||
918 | 918 | * @return float |
919 | 919 | * @throws \EE_Error |
920 | 920 | */ |
921 | - protected function _recalculate_pretax_total_for_subtotal( $calculated_total_so_far, $my_children = null ) { |
|
922 | - if( $my_children === null ) { |
|
921 | + protected function _recalculate_pretax_total_for_subtotal($calculated_total_so_far, $my_children = null) { |
|
922 | + if ($my_children === null) { |
|
923 | 923 | $my_children = $this->children(); |
924 | 924 | } |
925 | 925 | //get the total of all its children |
926 | - foreach ( $my_children as $child_line_item ) { |
|
927 | - if ( $child_line_item instanceof EE_Line_Item && ! $child_line_item->is_cancellation() ) { |
|
926 | + foreach ($my_children as $child_line_item) { |
|
927 | + if ($child_line_item instanceof EE_Line_Item && ! $child_line_item->is_cancellation()) { |
|
928 | 928 | // percentage line items are based on total so far |
929 | - if ( $child_line_item->is_percent() ) { |
|
929 | + if ($child_line_item->is_percent()) { |
|
930 | 930 | //round as we go so that the line items add up ok |
931 | 931 | $percent_total = round( |
932 | 932 | $calculated_total_so_far * $child_line_item->percent() / 100, |
933 | 933 | EE_Registry::instance()->CFG->currency->dec_plc |
934 | 934 | ); |
935 | - $child_line_item->set_total( $percent_total ); |
|
935 | + $child_line_item->set_total($percent_total); |
|
936 | 936 | //so far all percent line items should have a quantity of 1 |
937 | 937 | //(ie, no double percent discounts. Although that might be requested someday) |
938 | - $child_line_item->set_quantity( 1 ); |
|
938 | + $child_line_item->set_quantity(1); |
|
939 | 939 | $child_line_item->maybe_save(); |
940 | 940 | $calculated_total_so_far += $percent_total; |
941 | 941 | } else { |
942 | 942 | //verify flat sub-line-item quantities match their parent |
943 | - if( $child_line_item->is_sub_line_item() ) { |
|
944 | - $child_line_item->set_quantity( $this->quantity() ); |
|
943 | + if ($child_line_item->is_sub_line_item()) { |
|
944 | + $child_line_item->set_quantity($this->quantity()); |
|
945 | 945 | } |
946 | 946 | $calculated_total_so_far += $child_line_item->recalculate_pre_tax_total(); |
947 | 947 | } |
948 | 948 | } |
949 | 949 | } |
950 | 950 | |
951 | - if( $this->is_sub_total() ){ |
|
951 | + if ($this->is_sub_total()) { |
|
952 | 952 | // no negative totals plz |
953 | - $calculated_total_so_far = max( $calculated_total_so_far, 0 ); |
|
953 | + $calculated_total_so_far = max($calculated_total_so_far, 0); |
|
954 | 954 | } |
955 | 955 | return $calculated_total_so_far; |
956 | 956 | } |
@@ -968,8 +968,8 @@ discard block |
||
968 | 968 | * @return float |
969 | 969 | * @throws \EE_Error |
970 | 970 | */ |
971 | - protected function _recalculate_pretax_total_for_line_item( $calculated_total_so_far, $my_children = null ) { |
|
972 | - if( $my_children === null ) { |
|
971 | + protected function _recalculate_pretax_total_for_line_item($calculated_total_so_far, $my_children = null) { |
|
972 | + if ($my_children === null) { |
|
973 | 973 | $my_children = $this->children(); |
974 | 974 | } |
975 | 975 | //we need to keep track of the running total for a single item, |
@@ -977,10 +977,10 @@ discard block |
||
977 | 977 | $unit_price_for_total = 0; |
978 | 978 | $quantity_for_total = 1; |
979 | 979 | //get the total of all its children |
980 | - foreach ( $my_children as $child_line_item ) { |
|
981 | - if ( $child_line_item instanceof EE_Line_Item && |
|
980 | + foreach ($my_children as $child_line_item) { |
|
981 | + if ($child_line_item instanceof EE_Line_Item && |
|
982 | 982 | ! $child_line_item->is_cancellation()) { |
983 | - if ( $child_line_item->is_percent() ) { |
|
983 | + if ($child_line_item->is_percent()) { |
|
984 | 984 | //it should be the unit-price-so-far multiplied by teh percent multiplied by the quantity |
985 | 985 | //not total multiplied by percent, because that ignores rounding along-the-way |
986 | 986 | $percent_unit_price = round( |
@@ -988,17 +988,17 @@ discard block |
||
988 | 988 | EE_Registry::instance()->CFG->currency->dec_plc |
989 | 989 | ); |
990 | 990 | $percent_total = $percent_unit_price * $quantity_for_total; |
991 | - $child_line_item->set_total( $percent_total ); |
|
991 | + $child_line_item->set_total($percent_total); |
|
992 | 992 | //so far all percent line items should have a quantity of 1 |
993 | 993 | //(ie, no double percent discounts. Although that might be requested someday) |
994 | - $child_line_item->set_quantity( 1 ); |
|
994 | + $child_line_item->set_quantity(1); |
|
995 | 995 | $child_line_item->maybe_save(); |
996 | 996 | $calculated_total_so_far += $percent_total; |
997 | 997 | $unit_price_for_total += $percent_unit_price; |
998 | 998 | } else { |
999 | 999 | //verify flat sub-line-item quantities match their parent |
1000 | - if( $child_line_item->is_sub_line_item() ) { |
|
1001 | - $child_line_item->set_quantity( $this->quantity() ); |
|
1000 | + if ($child_line_item->is_sub_line_item()) { |
|
1001 | + $child_line_item->set_quantity($this->quantity()); |
|
1002 | 1002 | } |
1003 | 1003 | $quantity_for_total = $child_line_item->quantity(); |
1004 | 1004 | $calculated_total_so_far += $child_line_item->recalculate_pre_tax_total(); |
@@ -1022,10 +1022,10 @@ discard block |
||
1022 | 1022 | //calculate the pretax total |
1023 | 1023 | $taxable_total = $this->taxable_total(); |
1024 | 1024 | $tax_total = 0; |
1025 | - foreach ( $taxes as $tax ) { |
|
1025 | + foreach ($taxes as $tax) { |
|
1026 | 1026 | $total_on_this_tax = $taxable_total * $tax->percent() / 100; |
1027 | 1027 | //remember the total on this line item |
1028 | - $tax->set_total( $total_on_this_tax ); |
|
1028 | + $tax->set_total($total_on_this_tax); |
|
1029 | 1029 | $tax_total += $tax->total(); |
1030 | 1030 | } |
1031 | 1031 | $this->_recalculate_tax_sub_total(); |
@@ -1039,21 +1039,21 @@ discard block |
||
1039 | 1039 | * @return void |
1040 | 1040 | */ |
1041 | 1041 | private function _recalculate_tax_sub_total() { |
1042 | - if ( $this->is_tax_sub_total() ) { |
|
1042 | + if ($this->is_tax_sub_total()) { |
|
1043 | 1043 | $total = 0; |
1044 | 1044 | $total_percent = 0; |
1045 | 1045 | //simply loop through all its children (which should be taxes) and sum their total |
1046 | - foreach ( $this->children() as $child_tax ) { |
|
1047 | - if ( $child_tax instanceof EE_Line_Item ) { |
|
1046 | + foreach ($this->children() as $child_tax) { |
|
1047 | + if ($child_tax instanceof EE_Line_Item) { |
|
1048 | 1048 | $total += $child_tax->total(); |
1049 | 1049 | $total_percent += $child_tax->percent(); |
1050 | 1050 | } |
1051 | 1051 | } |
1052 | - $this->set_total( $total ); |
|
1053 | - $this->set_percent( $total_percent ); |
|
1054 | - } elseif ( $this->is_total() ) { |
|
1055 | - foreach ( $this->children() as $maybe_tax_subtotal ) { |
|
1056 | - if ( $maybe_tax_subtotal instanceof EE_Line_Item ) { |
|
1052 | + $this->set_total($total); |
|
1053 | + $this->set_percent($total_percent); |
|
1054 | + } elseif ($this->is_total()) { |
|
1055 | + foreach ($this->children() as $maybe_tax_subtotal) { |
|
1056 | + if ($maybe_tax_subtotal instanceof EE_Line_Item) { |
|
1057 | 1057 | $maybe_tax_subtotal->_recalculate_tax_sub_total(); |
1058 | 1058 | } |
1059 | 1059 | } |
@@ -1069,8 +1069,8 @@ discard block |
||
1069 | 1069 | public function get_total_tax() { |
1070 | 1070 | $this->_recalculate_tax_sub_total(); |
1071 | 1071 | $total = 0; |
1072 | - foreach ( $this->tax_descendants() as $tax_line_item ) { |
|
1073 | - if ( $tax_line_item instanceof EE_Line_Item ) { |
|
1072 | + foreach ($this->tax_descendants() as $tax_line_item) { |
|
1073 | + if ($tax_line_item instanceof EE_Line_Item) { |
|
1074 | 1074 | $total += $tax_line_item->total(); |
1075 | 1075 | } |
1076 | 1076 | } |
@@ -1084,15 +1084,15 @@ discard block |
||
1084 | 1084 | */ |
1085 | 1085 | public function get_items_total() { |
1086 | 1086 | //by default, let's make sure we're consistent with the existing line item |
1087 | - if( $this->is_total() ) { |
|
1088 | - $pretax_subtotal_li = EEH_Line_Item::get_pre_tax_subtotal( $this ); |
|
1089 | - if( $pretax_subtotal_li instanceof EE_Line_Item ) { |
|
1087 | + if ($this->is_total()) { |
|
1088 | + $pretax_subtotal_li = EEH_Line_Item::get_pre_tax_subtotal($this); |
|
1089 | + if ($pretax_subtotal_li instanceof EE_Line_Item) { |
|
1090 | 1090 | return $pretax_subtotal_li->total(); |
1091 | 1091 | } |
1092 | 1092 | } |
1093 | 1093 | $total = 0; |
1094 | - foreach ( $this->get_items() as $item ) { |
|
1095 | - if ( $item instanceof EE_Line_Item ) { |
|
1094 | + foreach ($this->get_items() as $item) { |
|
1095 | + if ($item instanceof EE_Line_Item) { |
|
1096 | 1096 | $total += $item->total(); |
1097 | 1097 | } |
1098 | 1098 | } |
@@ -1107,7 +1107,7 @@ discard block |
||
1107 | 1107 | * @return EE_Line_Item[] |
1108 | 1108 | */ |
1109 | 1109 | public function tax_descendants() { |
1110 | - return EEH_Line_Item::get_tax_descendants( $this ); |
|
1110 | + return EEH_Line_Item::get_tax_descendants($this); |
|
1111 | 1111 | } |
1112 | 1112 | |
1113 | 1113 | |
@@ -1117,7 +1117,7 @@ discard block |
||
1117 | 1117 | * @return EE_Line_Item[] |
1118 | 1118 | */ |
1119 | 1119 | public function get_items() { |
1120 | - return EEH_Line_Item::get_line_item_descendants( $this ); |
|
1120 | + return EEH_Line_Item::get_line_item_descendants($this); |
|
1121 | 1121 | } |
1122 | 1122 | |
1123 | 1123 | |
@@ -1133,22 +1133,22 @@ discard block |
||
1133 | 1133 | */ |
1134 | 1134 | public function taxable_total() { |
1135 | 1135 | $total = 0; |
1136 | - if ( $this->children() ) { |
|
1137 | - foreach ( $this->children() as $child_line_item ) { |
|
1138 | - if ( $child_line_item->type() === EEM_Line_Item::type_line_item && $child_line_item->is_taxable()) { |
|
1136 | + if ($this->children()) { |
|
1137 | + foreach ($this->children() as $child_line_item) { |
|
1138 | + if ($child_line_item->type() === EEM_Line_Item::type_line_item && $child_line_item->is_taxable()) { |
|
1139 | 1139 | //if it's a percent item, only take into account the percent |
1140 | 1140 | //that's taxable too (the taxable total so far) |
1141 | - if( $child_line_item->is_percent() ) { |
|
1142 | - $total = $total + ( $total * $child_line_item->percent() / 100 ); |
|
1143 | - }else{ |
|
1141 | + if ($child_line_item->is_percent()) { |
|
1142 | + $total = $total + ($total * $child_line_item->percent() / 100); |
|
1143 | + } else { |
|
1144 | 1144 | $total += $child_line_item->total(); |
1145 | 1145 | } |
1146 | - }elseif( $child_line_item->type() === EEM_Line_Item::type_sub_total ){ |
|
1146 | + }elseif ($child_line_item->type() === EEM_Line_Item::type_sub_total) { |
|
1147 | 1147 | $total += $child_line_item->taxable_total(); |
1148 | 1148 | } |
1149 | 1149 | } |
1150 | 1150 | } |
1151 | - return max( $total, 0 ); |
|
1151 | + return max($total, 0); |
|
1152 | 1152 | } |
1153 | 1153 | |
1154 | 1154 | |
@@ -1158,7 +1158,7 @@ discard block |
||
1158 | 1158 | * @return EE_Transaction |
1159 | 1159 | */ |
1160 | 1160 | public function transaction() { |
1161 | - return $this->get_first_related( 'Transaction' ); |
|
1161 | + return $this->get_first_related('Transaction'); |
|
1162 | 1162 | } |
1163 | 1163 | |
1164 | 1164 | |
@@ -1171,18 +1171,18 @@ discard block |
||
1171 | 1171 | * @param int $txn_id if none is provided, assumes $this->TXN_ID() |
1172 | 1172 | * @return int count of items saved |
1173 | 1173 | */ |
1174 | - public function save_this_and_descendants_to_txn( $txn_id = NULL ) { |
|
1174 | + public function save_this_and_descendants_to_txn($txn_id = NULL) { |
|
1175 | 1175 | $count = 0; |
1176 | - if ( ! $txn_id ) { |
|
1176 | + if ( ! $txn_id) { |
|
1177 | 1177 | $txn_id = $this->TXN_ID(); |
1178 | 1178 | } |
1179 | - $this->set_TXN_ID( $txn_id ); |
|
1179 | + $this->set_TXN_ID($txn_id); |
|
1180 | 1180 | $children = $this->children(); |
1181 | 1181 | $count += $this->save() ? 1 : 0; |
1182 | - foreach ( $children as $child_line_item ) { |
|
1183 | - if ( $child_line_item instanceof EE_Line_Item ) { |
|
1184 | - $child_line_item->set_parent_ID( $this->ID() ); |
|
1185 | - $count += $child_line_item->save_this_and_descendants_to_txn( $txn_id ); |
|
1182 | + foreach ($children as $child_line_item) { |
|
1183 | + if ($child_line_item instanceof EE_Line_Item) { |
|
1184 | + $child_line_item->set_parent_ID($this->ID()); |
|
1185 | + $count += $child_line_item->save_this_and_descendants_to_txn($txn_id); |
|
1186 | 1186 | } |
1187 | 1187 | } |
1188 | 1188 | return $count; |
@@ -1199,9 +1199,9 @@ discard block |
||
1199 | 1199 | $count = 0; |
1200 | 1200 | $children = $this->children(); |
1201 | 1201 | $count += $this->save() ? 1 : 0; |
1202 | - foreach ( $children as $child_line_item ) { |
|
1203 | - if ( $child_line_item instanceof EE_Line_Item ) { |
|
1204 | - $child_line_item->set_parent_ID( $this->ID() ); |
|
1202 | + foreach ($children as $child_line_item) { |
|
1203 | + if ($child_line_item instanceof EE_Line_Item) { |
|
1204 | + $child_line_item->set_parent_ID($this->ID()); |
|
1205 | 1205 | $count += $child_line_item->save_this_and_descendants(); |
1206 | 1206 | } |
1207 | 1207 | } |
@@ -1215,8 +1215,8 @@ discard block |
||
1215 | 1215 | * @return EE_Line_Item[] |
1216 | 1216 | */ |
1217 | 1217 | function get_cancellations() { |
1218 | - EE_Registry::instance()->load_helper( 'Line_Item' ); |
|
1219 | - return EEH_Line_Item::get_descendants_of_type( $this, EEM_Line_Item::type_cancellation ); |
|
1218 | + EE_Registry::instance()->load_helper('Line_Item'); |
|
1219 | + return EEH_Line_Item::get_descendants_of_type($this, EEM_Line_Item::type_cancellation); |
|
1220 | 1220 | } |
1221 | 1221 | |
1222 | 1222 | |
@@ -1226,9 +1226,9 @@ discard block |
||
1226 | 1226 | * @param string $type one of the constants on EEM_Line_Item |
1227 | 1227 | * @return EE_Line_Item[] |
1228 | 1228 | */ |
1229 | - protected function _get_descendants_of_type( $type ) { |
|
1230 | - EE_Error::doing_it_wrong( 'EE_Line_Item::_get_descendants_of_type()', __('Method replaced with EEH_Line_Item::get_descendants_of_type()', 'event_espresso'), '4.6.0' ); |
|
1231 | - return EEH_Line_Item::get_descendants_of_type( $this, $type ); |
|
1229 | + protected function _get_descendants_of_type($type) { |
|
1230 | + EE_Error::doing_it_wrong('EE_Line_Item::_get_descendants_of_type()', __('Method replaced with EEH_Line_Item::get_descendants_of_type()', 'event_espresso'), '4.6.0'); |
|
1231 | + return EEH_Line_Item::get_descendants_of_type($this, $type); |
|
1232 | 1232 | } |
1233 | 1233 | |
1234 | 1234 | |
@@ -1238,9 +1238,9 @@ discard block |
||
1238 | 1238 | * @param string $type like one of the EEM_Line_Item::type_* |
1239 | 1239 | * @return EE_Line_Item |
1240 | 1240 | */ |
1241 | - public function get_nearest_descendant_of_type( $type ) { |
|
1242 | - EE_Error::doing_it_wrong( 'EE_Line_Item::get_nearest_descendant_of_type()', __('Method replaced with EEH_Line_Item::get_nearest_descendant_of_type()', 'event_espresso'), '4.6.0' ); |
|
1243 | - return EEH_Line_Item::get_nearest_descendant_of_type( $this, $type ); |
|
1241 | + public function get_nearest_descendant_of_type($type) { |
|
1242 | + EE_Error::doing_it_wrong('EE_Line_Item::get_nearest_descendant_of_type()', __('Method replaced with EEH_Line_Item::get_nearest_descendant_of_type()', 'event_espresso'), '4.6.0'); |
|
1243 | + return EEH_Line_Item::get_nearest_descendant_of_type($this, $type); |
|
1244 | 1244 | } |
1245 | 1245 | |
1246 | 1246 | |
@@ -1251,7 +1251,7 @@ discard block |
||
1251 | 1251 | * @return int count of items saved |
1252 | 1252 | */ |
1253 | 1253 | public function maybe_save() { |
1254 | - if ( $this->ID() ) { |
|
1254 | + if ($this->ID()) { |
|
1255 | 1255 | return $this->save(); |
1256 | 1256 | } |
1257 | 1257 | return false; |
@@ -1,4 +1,4 @@ discard block |
||
1 | -<?php if (!defined('EVENT_ESPRESSO_VERSION')) { exit('No direct script access allowed'); } |
|
1 | +<?php if ( ! defined('EVENT_ESPRESSO_VERSION')) { exit('No direct script access allowed'); } |
|
2 | 2 | /** |
3 | 3 | * |
4 | 4 | * EEH_Line_Item |
@@ -45,8 +45,8 @@ discard block |
||
45 | 45 | * @return boolean success |
46 | 46 | * @throws \EE_Error |
47 | 47 | */ |
48 | - public static function add_unrelated_item( EE_Line_Item $parent_line_item, $name, $unit_price, $description = '', $quantity = 1, $taxable = FALSE, $code = NULL ){ |
|
49 | - $items_subtotal = self::get_pre_tax_subtotal( $parent_line_item ); |
|
48 | + public static function add_unrelated_item(EE_Line_Item $parent_line_item, $name, $unit_price, $description = '', $quantity = 1, $taxable = FALSE, $code = NULL) { |
|
49 | + $items_subtotal = self::get_pre_tax_subtotal($parent_line_item); |
|
50 | 50 | $line_item = EE_Line_Item::new_instance(array( |
51 | 51 | 'LIN_name' => $name, |
52 | 52 | 'LIN_desc' => $description, |
@@ -54,7 +54,7 @@ discard block |
||
54 | 54 | 'LIN_quantity' => $quantity, |
55 | 55 | 'LIN_percent' => null, |
56 | 56 | 'LIN_is_taxable' => $taxable, |
57 | - 'LIN_order' => $items_subtotal instanceof EE_Line_Item ? count( $items_subtotal->children() ) : 0, |
|
57 | + 'LIN_order' => $items_subtotal instanceof EE_Line_Item ? count($items_subtotal->children()) : 0, |
|
58 | 58 | 'LIN_total' => (float) $unit_price * (int) $quantity, |
59 | 59 | 'LIN_type'=> EEM_Line_Item::type_line_item, |
60 | 60 | 'LIN_code' => $code, |
@@ -64,7 +64,7 @@ discard block |
||
64 | 64 | $line_item, |
65 | 65 | $parent_line_item |
66 | 66 | ); |
67 | - return self::add_item( $parent_line_item, $line_item ); |
|
67 | + return self::add_item($parent_line_item, $line_item); |
|
68 | 68 | } |
69 | 69 | |
70 | 70 | |
@@ -86,7 +86,7 @@ discard block |
||
86 | 86 | * @return boolean success |
87 | 87 | * @throws \EE_Error |
88 | 88 | */ |
89 | - public static function add_percentage_based_item( EE_Line_Item $parent_line_item, $name, $percentage_amount, $description = '', $taxable = FALSE ){ |
|
89 | + public static function add_percentage_based_item(EE_Line_Item $parent_line_item, $name, $percentage_amount, $description = '', $taxable = FALSE) { |
|
90 | 90 | $line_item = EE_Line_Item::new_instance(array( |
91 | 91 | 'LIN_name' => $name, |
92 | 92 | 'LIN_desc' => $description, |
@@ -94,7 +94,7 @@ discard block |
||
94 | 94 | 'LIN_percent' => $percentage_amount, |
95 | 95 | 'LIN_quantity' => NULL, |
96 | 96 | 'LIN_is_taxable' => $taxable, |
97 | - 'LIN_total' => (float) ( $percentage_amount * ( $parent_line_item->total() / 100 ) ), |
|
97 | + 'LIN_total' => (float) ($percentage_amount * ($parent_line_item->total() / 100)), |
|
98 | 98 | 'LIN_type'=> EEM_Line_Item::type_line_item, |
99 | 99 | 'LIN_parent' => $parent_line_item->ID() |
100 | 100 | )); |
@@ -102,7 +102,7 @@ discard block |
||
102 | 102 | 'FHEE__EEH_Line_Item__add_percentage_based_item__line_item', |
103 | 103 | $line_item |
104 | 104 | ); |
105 | - return self::add_item( $parent_line_item, $line_item ); |
|
105 | + return self::add_item($parent_line_item, $line_item); |
|
106 | 106 | } |
107 | 107 | |
108 | 108 | |
@@ -123,15 +123,15 @@ discard block |
||
123 | 123 | * @return \EE_Line_Item |
124 | 124 | * @throws \EE_Error |
125 | 125 | */ |
126 | - public static function add_ticket_purchase( EE_Line_Item $total_line_item, EE_Ticket $ticket, $qty = 1 ){ |
|
127 | - if ( ! $total_line_item instanceof EE_Line_Item || ! $total_line_item->is_total() ) { |
|
128 | - throw new EE_Error( sprintf( __( 'A valid line item total is required in order to add tickets. A line item of type "%s" was passed.', 'event_espresso' ), $ticket->ID(), $total_line_item->ID() ) ); |
|
126 | + public static function add_ticket_purchase(EE_Line_Item $total_line_item, EE_Ticket $ticket, $qty = 1) { |
|
127 | + if ( ! $total_line_item instanceof EE_Line_Item || ! $total_line_item->is_total()) { |
|
128 | + throw new EE_Error(sprintf(__('A valid line item total is required in order to add tickets. A line item of type "%s" was passed.', 'event_espresso'), $ticket->ID(), $total_line_item->ID())); |
|
129 | 129 | } |
130 | 130 | // either increment the qty for an existing ticket |
131 | - $line_item = self::increment_ticket_qty_if_already_in_cart( $total_line_item, $ticket, $qty ); |
|
131 | + $line_item = self::increment_ticket_qty_if_already_in_cart($total_line_item, $ticket, $qty); |
|
132 | 132 | // or add a new one |
133 | - if ( ! $line_item instanceof EE_Line_Item ) { |
|
134 | - $line_item = self::create_ticket_line_item( $total_line_item, $ticket, $qty ); |
|
133 | + if ( ! $line_item instanceof EE_Line_Item) { |
|
134 | + $line_item = self::create_ticket_line_item($total_line_item, $ticket, $qty); |
|
135 | 135 | } |
136 | 136 | $total_line_item->recalculate_total_including_taxes(); |
137 | 137 | return $line_item; |
@@ -147,11 +147,11 @@ discard block |
||
147 | 147 | * @return \EE_Line_Item |
148 | 148 | * @throws \EE_Error |
149 | 149 | */ |
150 | - public static function increment_ticket_qty_if_already_in_cart( EE_Line_Item $total_line_item, EE_Ticket $ticket, $qty = 1 ) { |
|
150 | + public static function increment_ticket_qty_if_already_in_cart(EE_Line_Item $total_line_item, EE_Ticket $ticket, $qty = 1) { |
|
151 | 151 | $line_item = null; |
152 | - if ( $total_line_item instanceof EE_Line_Item && $total_line_item->is_total() ) { |
|
153 | - $ticket_line_items = EEH_Line_Item::get_ticket_line_items( $total_line_item ); |
|
154 | - foreach ( (array)$ticket_line_items as $ticket_line_item ) { |
|
152 | + if ($total_line_item instanceof EE_Line_Item && $total_line_item->is_total()) { |
|
153 | + $ticket_line_items = EEH_Line_Item::get_ticket_line_items($total_line_item); |
|
154 | + foreach ((array) $ticket_line_items as $ticket_line_item) { |
|
155 | 155 | if ( |
156 | 156 | $ticket_line_item instanceof EE_Line_Item |
157 | 157 | && (int) $ticket_line_item->OBJ_ID() === (int) $ticket->ID() |
@@ -161,8 +161,8 @@ discard block |
||
161 | 161 | } |
162 | 162 | } |
163 | 163 | } |
164 | - if ( $line_item instanceof EE_Line_Item ) { |
|
165 | - EEH_Line_Item::increment_quantity( $line_item, $qty ); |
|
164 | + if ($line_item instanceof EE_Line_Item) { |
|
165 | + EEH_Line_Item::increment_quantity($line_item, $qty); |
|
166 | 166 | return $line_item; |
167 | 167 | } |
168 | 168 | return null; |
@@ -179,16 +179,16 @@ discard block |
||
179 | 179 | * @return void |
180 | 180 | * @throws \EE_Error |
181 | 181 | */ |
182 | - public static function increment_quantity( EE_Line_Item $line_item, $qty = 1 ) { |
|
183 | - if( ! $line_item->is_percent() ) { |
|
182 | + public static function increment_quantity(EE_Line_Item $line_item, $qty = 1) { |
|
183 | + if ( ! $line_item->is_percent()) { |
|
184 | 184 | $qty += $line_item->quantity(); |
185 | - $line_item->set_quantity( $qty ); |
|
186 | - $line_item->set_total( $line_item->unit_price() * $qty ); |
|
185 | + $line_item->set_quantity($qty); |
|
186 | + $line_item->set_total($line_item->unit_price() * $qty); |
|
187 | 187 | $line_item->save(); |
188 | 188 | } |
189 | - foreach( $line_item->children() as $child ) { |
|
190 | - if( $child->is_sub_line_item() ) { |
|
191 | - EEH_Line_Item::update_quantity( $child, $qty ); |
|
189 | + foreach ($line_item->children() as $child) { |
|
190 | + if ($child->is_sub_line_item()) { |
|
191 | + EEH_Line_Item::update_quantity($child, $qty); |
|
192 | 192 | } |
193 | 193 | } |
194 | 194 | } |
@@ -204,17 +204,17 @@ discard block |
||
204 | 204 | * @return void |
205 | 205 | * @throws \EE_Error |
206 | 206 | */ |
207 | - public static function decrement_quantity( EE_Line_Item $line_item, $qty = 1 ) { |
|
208 | - if( ! $line_item->is_percent() ) { |
|
207 | + public static function decrement_quantity(EE_Line_Item $line_item, $qty = 1) { |
|
208 | + if ( ! $line_item->is_percent()) { |
|
209 | 209 | $qty = $line_item->quantity() - $qty; |
210 | - $qty = max( $qty, 0 ); |
|
211 | - $line_item->set_quantity( $qty ); |
|
212 | - $line_item->set_total( $line_item->unit_price() * $qty ); |
|
210 | + $qty = max($qty, 0); |
|
211 | + $line_item->set_quantity($qty); |
|
212 | + $line_item->set_total($line_item->unit_price() * $qty); |
|
213 | 213 | $line_item->save(); |
214 | 214 | } |
215 | - foreach( $line_item->children() as $child ) { |
|
216 | - if( $child->is_sub_line_item() ) { |
|
217 | - EEH_Line_Item::update_quantity( $child, $qty ); |
|
215 | + foreach ($line_item->children() as $child) { |
|
216 | + if ($child->is_sub_line_item()) { |
|
217 | + EEH_Line_Item::update_quantity($child, $qty); |
|
218 | 218 | } |
219 | 219 | } |
220 | 220 | } |
@@ -229,15 +229,15 @@ discard block |
||
229 | 229 | * @param int $new_quantity |
230 | 230 | * @throws \EE_Error |
231 | 231 | */ |
232 | - public static function update_quantity( EE_Line_Item $line_item, $new_quantity ) { |
|
233 | - if( ! $line_item->is_percent() ) { |
|
234 | - $line_item->set_quantity( $new_quantity ); |
|
235 | - $line_item->set_total( $line_item->unit_price() * $new_quantity ); |
|
232 | + public static function update_quantity(EE_Line_Item $line_item, $new_quantity) { |
|
233 | + if ( ! $line_item->is_percent()) { |
|
234 | + $line_item->set_quantity($new_quantity); |
|
235 | + $line_item->set_total($line_item->unit_price() * $new_quantity); |
|
236 | 236 | $line_item->save(); |
237 | 237 | } |
238 | - foreach( $line_item->children() as $child ) { |
|
239 | - if( $child->is_sub_line_item() ) { |
|
240 | - EEH_Line_Item::update_quantity( $child, $new_quantity ); |
|
238 | + foreach ($line_item->children() as $child) { |
|
239 | + if ($child->is_sub_line_item()) { |
|
240 | + EEH_Line_Item::update_quantity($child, $new_quantity); |
|
241 | 241 | } |
242 | 242 | } |
243 | 243 | } |
@@ -252,43 +252,43 @@ discard block |
||
252 | 252 | * @return \EE_Line_Item |
253 | 253 | * @throws \EE_Error |
254 | 254 | */ |
255 | - public static function create_ticket_line_item( EE_Line_Item $total_line_item, EE_Ticket $ticket, $qty = 1 ) { |
|
255 | + public static function create_ticket_line_item(EE_Line_Item $total_line_item, EE_Ticket $ticket, $qty = 1) { |
|
256 | 256 | $datetimes = $ticket->datetimes(); |
257 | - $first_datetime = reset( $datetimes ); |
|
258 | - if( $first_datetime instanceof EE_Datetime && $first_datetime->event() instanceof EE_Event ) { |
|
257 | + $first_datetime = reset($datetimes); |
|
258 | + if ($first_datetime instanceof EE_Datetime && $first_datetime->event() instanceof EE_Event) { |
|
259 | 259 | $first_datetime_name = $first_datetime->event()->name(); |
260 | 260 | } else { |
261 | - $first_datetime_name = __( 'Event', 'event_espresso' ); |
|
261 | + $first_datetime_name = __('Event', 'event_espresso'); |
|
262 | 262 | } |
263 | - $event = sprintf( _x( '(For %1$s)', '(For Event Name)', 'event_espresso' ), $first_datetime_name ); |
|
263 | + $event = sprintf(_x('(For %1$s)', '(For Event Name)', 'event_espresso'), $first_datetime_name); |
|
264 | 264 | // get event subtotal line |
265 | - $events_sub_total = self::get_event_line_item_for_ticket( $total_line_item, $ticket ); |
|
265 | + $events_sub_total = self::get_event_line_item_for_ticket($total_line_item, $ticket); |
|
266 | 266 | // add $ticket to cart |
267 | - $line_item = EE_Line_Item::new_instance( array( |
|
267 | + $line_item = EE_Line_Item::new_instance(array( |
|
268 | 268 | 'LIN_name' => $ticket->name(), |
269 | - 'LIN_desc' => $ticket->description() !== '' ? $ticket->description() . ' ' . $event : $event, |
|
269 | + 'LIN_desc' => $ticket->description() !== '' ? $ticket->description().' '.$event : $event, |
|
270 | 270 | 'LIN_unit_price' => $ticket->price(), |
271 | 271 | 'LIN_quantity' => $qty, |
272 | 272 | 'LIN_is_taxable' => $ticket->taxable(), |
273 | - 'LIN_order' => count( $events_sub_total->children() ), |
|
273 | + 'LIN_order' => count($events_sub_total->children()), |
|
274 | 274 | 'LIN_total' => $ticket->price() * $qty, |
275 | 275 | 'LIN_type' => EEM_Line_Item::type_line_item, |
276 | 276 | 'OBJ_ID' => $ticket->ID(), |
277 | 277 | 'OBJ_type' => 'Ticket' |
278 | - ) ); |
|
278 | + )); |
|
279 | 279 | $line_item = apply_filters( |
280 | 280 | 'FHEE__EEH_Line_Item__create_ticket_line_item__line_item', |
281 | 281 | $line_item |
282 | 282 | ); |
283 | - $events_sub_total->add_child_line_item( $line_item ); |
|
283 | + $events_sub_total->add_child_line_item($line_item); |
|
284 | 284 | //now add the sub-line items |
285 | 285 | $running_total_for_ticket = 0; |
286 | - foreach ( $ticket->prices( array( 'order_by' => array( 'PRC_order' => 'ASC' ) ) ) as $price ) { |
|
286 | + foreach ($ticket->prices(array('order_by' => array('PRC_order' => 'ASC'))) as $price) { |
|
287 | 287 | $sign = $price->is_discount() ? -1 : 1; |
288 | 288 | $price_total = $price->is_percent() |
289 | 289 | ? $running_total_for_ticket * $price->amount() / 100 |
290 | 290 | : $price->amount() * $qty; |
291 | - $sub_line_item = EE_Line_Item::new_instance( array( |
|
291 | + $sub_line_item = EE_Line_Item::new_instance(array( |
|
292 | 292 | 'LIN_name' => $price->name(), |
293 | 293 | 'LIN_desc' => $price->desc(), |
294 | 294 | 'LIN_quantity' => $price->is_percent() ? null : $qty, |
@@ -298,18 +298,18 @@ discard block |
||
298 | 298 | 'LIN_type' => EEM_Line_Item::type_sub_line_item, |
299 | 299 | 'OBJ_ID' => $price->ID(), |
300 | 300 | 'OBJ_type' => 'Price' |
301 | - ) ); |
|
301 | + )); |
|
302 | 302 | $sub_line_item = apply_filters( |
303 | 303 | 'FHEE__EEH_Line_Item__create_ticket_line_item__sub_line_item', |
304 | 304 | $sub_line_item |
305 | 305 | ); |
306 | - if ( $price->is_percent() ) { |
|
307 | - $sub_line_item->set_percent( $sign * $price->amount() ); |
|
306 | + if ($price->is_percent()) { |
|
307 | + $sub_line_item->set_percent($sign * $price->amount()); |
|
308 | 308 | } else { |
309 | - $sub_line_item->set_unit_price( $sign * $price->amount() ); |
|
309 | + $sub_line_item->set_unit_price($sign * $price->amount()); |
|
310 | 310 | } |
311 | 311 | $running_total_for_ticket += $price_total; |
312 | - $line_item->add_child_line_item( $sub_line_item ); |
|
312 | + $line_item->add_child_line_item($sub_line_item); |
|
313 | 313 | } |
314 | 314 | return $line_item; |
315 | 315 | } |
@@ -329,11 +329,11 @@ discard block |
||
329 | 329 | * @return boolean |
330 | 330 | * @throws \EE_Error |
331 | 331 | */ |
332 | - public static function add_item( EE_Line_Item $total_line_item, EE_Line_Item $item ){ |
|
333 | - $pre_tax_subtotal = self::get_pre_tax_subtotal( $total_line_item ); |
|
334 | - if ( $pre_tax_subtotal instanceof EE_Line_Item ){ |
|
332 | + public static function add_item(EE_Line_Item $total_line_item, EE_Line_Item $item) { |
|
333 | + $pre_tax_subtotal = self::get_pre_tax_subtotal($total_line_item); |
|
334 | + if ($pre_tax_subtotal instanceof EE_Line_Item) { |
|
335 | 335 | $success = $pre_tax_subtotal->add_child_line_item($item); |
336 | - }else{ |
|
336 | + } else { |
|
337 | 337 | return FALSE; |
338 | 338 | } |
339 | 339 | $total_line_item->recalculate_total_including_taxes(); |
@@ -352,34 +352,34 @@ discard block |
||
352 | 352 | * @return bool success |
353 | 353 | * @throws \EE_Error |
354 | 354 | */ |
355 | - public static function cancel_ticket_line_item( EE_Line_Item $ticket_line_item, $qty = 1 ) { |
|
355 | + public static function cancel_ticket_line_item(EE_Line_Item $ticket_line_item, $qty = 1) { |
|
356 | 356 | // validate incoming line_item |
357 | - if ( $ticket_line_item->OBJ_type() !== 'Ticket' ) { |
|
357 | + if ($ticket_line_item->OBJ_type() !== 'Ticket') { |
|
358 | 358 | throw new EE_Error( |
359 | 359 | sprintf( |
360 | - __( 'The supplied line item must have an Object Type of "Ticket", not %1$s.', 'event_espresso' ), |
|
360 | + __('The supplied line item must have an Object Type of "Ticket", not %1$s.', 'event_espresso'), |
|
361 | 361 | $ticket_line_item->type() |
362 | 362 | ) |
363 | 363 | ); |
364 | 364 | } |
365 | - if ( $ticket_line_item->quantity() < $qty ) { |
|
365 | + if ($ticket_line_item->quantity() < $qty) { |
|
366 | 366 | throw new EE_Error( |
367 | 367 | sprintf( |
368 | - __( 'Can not cancel %1$d ticket(s) because the supplied line item has a quantity of %2$d.', 'event_espresso' ), |
|
368 | + __('Can not cancel %1$d ticket(s) because the supplied line item has a quantity of %2$d.', 'event_espresso'), |
|
369 | 369 | $qty, |
370 | 370 | $ticket_line_item->quantity() |
371 | 371 | ) |
372 | 372 | ); |
373 | 373 | } |
374 | 374 | // decrement ticket quantity; don't rely on auto-fixing when recalculating totals to do this |
375 | - $ticket_line_item->set_quantity( $ticket_line_item->quantity() - $qty ); |
|
376 | - foreach( $ticket_line_item->children() as $child_line_item ) { |
|
377 | - if( |
|
375 | + $ticket_line_item->set_quantity($ticket_line_item->quantity() - $qty); |
|
376 | + foreach ($ticket_line_item->children() as $child_line_item) { |
|
377 | + if ( |
|
378 | 378 | $child_line_item->is_sub_line_item() |
379 | 379 | && ! $child_line_item->is_percent() |
380 | 380 | && ! $child_line_item->is_cancellation() |
381 | 381 | ) { |
382 | - $child_line_item->set_quantity( $child_line_item->quantity() - $qty ); |
|
382 | + $child_line_item->set_quantity($child_line_item->quantity() - $qty); |
|
383 | 383 | } |
384 | 384 | } |
385 | 385 | // get cancellation sub line item |
@@ -387,37 +387,37 @@ discard block |
||
387 | 387 | $ticket_line_item, |
388 | 388 | EEM_Line_Item::type_cancellation |
389 | 389 | ); |
390 | - $cancellation_line_item = reset( $cancellation_line_item ); |
|
390 | + $cancellation_line_item = reset($cancellation_line_item); |
|
391 | 391 | // verify that this ticket was indeed previously cancelled |
392 | - if ( $cancellation_line_item instanceof EE_Line_Item ) { |
|
392 | + if ($cancellation_line_item instanceof EE_Line_Item) { |
|
393 | 393 | // increment cancelled quantity |
394 | - $cancellation_line_item->set_quantity( $cancellation_line_item->quantity() + $qty ); |
|
394 | + $cancellation_line_item->set_quantity($cancellation_line_item->quantity() + $qty); |
|
395 | 395 | } else { |
396 | 396 | // create cancellation sub line item |
397 | - $cancellation_line_item = EE_Line_Item::new_instance( array( |
|
398 | - 'LIN_name' => __( 'Cancellation', 'event_espresso' ), |
|
397 | + $cancellation_line_item = EE_Line_Item::new_instance(array( |
|
398 | + 'LIN_name' => __('Cancellation', 'event_espresso'), |
|
399 | 399 | 'LIN_desc' => sprintf( |
400 | - _x( 'Cancelled %1$s : %2$s', 'Cancelled Ticket Name : 2015-01-01 11:11', 'event_espresso' ), |
|
400 | + _x('Cancelled %1$s : %2$s', 'Cancelled Ticket Name : 2015-01-01 11:11', 'event_espresso'), |
|
401 | 401 | $ticket_line_item->name(), |
402 | - current_time( get_option( 'date_format' ) . ' ' . get_option( 'time_format' ) ) |
|
402 | + current_time(get_option('date_format').' '.get_option('time_format')) |
|
403 | 403 | ), |
404 | 404 | 'LIN_unit_price' => 0, // $ticket_line_item->unit_price() |
405 | 405 | 'LIN_quantity' => $qty, |
406 | 406 | 'LIN_is_taxable' => $ticket_line_item->is_taxable(), |
407 | - 'LIN_order' => count( $ticket_line_item->children() ), |
|
407 | + 'LIN_order' => count($ticket_line_item->children()), |
|
408 | 408 | 'LIN_total' => 0, // $ticket_line_item->unit_price() |
409 | 409 | 'LIN_type' => EEM_Line_Item::type_cancellation, |
410 | - ) ); |
|
411 | - $ticket_line_item->add_child_line_item( $cancellation_line_item ); |
|
410 | + )); |
|
411 | + $ticket_line_item->add_child_line_item($cancellation_line_item); |
|
412 | 412 | } |
413 | - if ( $ticket_line_item->save_this_and_descendants() > 0 ) { |
|
413 | + if ($ticket_line_item->save_this_and_descendants() > 0) { |
|
414 | 414 | // decrement parent line item quantity |
415 | 415 | $event_line_item = $ticket_line_item->parent(); |
416 | - if ( $event_line_item instanceof EE_Line_Item && $event_line_item->OBJ_type() === 'Event' ) { |
|
417 | - $event_line_item->set_quantity( $event_line_item->quantity() - $qty ); |
|
416 | + if ($event_line_item instanceof EE_Line_Item && $event_line_item->OBJ_type() === 'Event') { |
|
417 | + $event_line_item->set_quantity($event_line_item->quantity() - $qty); |
|
418 | 418 | $event_line_item->save(); |
419 | 419 | } |
420 | - EEH_Line_Item::get_grand_total_and_recalculate_everything( $ticket_line_item ); |
|
420 | + EEH_Line_Item::get_grand_total_and_recalculate_everything($ticket_line_item); |
|
421 | 421 | return true; |
422 | 422 | } |
423 | 423 | return false; |
@@ -435,12 +435,12 @@ discard block |
||
435 | 435 | * @return bool success |
436 | 436 | * @throws \EE_Error |
437 | 437 | */ |
438 | - public static function reinstate_canceled_ticket_line_item( EE_Line_Item $ticket_line_item, $qty = 1 ) { |
|
438 | + public static function reinstate_canceled_ticket_line_item(EE_Line_Item $ticket_line_item, $qty = 1) { |
|
439 | 439 | // validate incoming line_item |
440 | - if ( $ticket_line_item->OBJ_type() !== 'Ticket' ) { |
|
440 | + if ($ticket_line_item->OBJ_type() !== 'Ticket') { |
|
441 | 441 | throw new EE_Error( |
442 | 442 | sprintf( |
443 | - __( 'The supplied line item must have an Object Type of "Ticket", not %1$s.', 'event_espresso' ), |
|
443 | + __('The supplied line item must have an Object Type of "Ticket", not %1$s.', 'event_espresso'), |
|
444 | 444 | $ticket_line_item->type() |
445 | 445 | ) |
446 | 446 | ); |
@@ -450,42 +450,42 @@ discard block |
||
450 | 450 | $ticket_line_item, |
451 | 451 | EEM_Line_Item::type_cancellation |
452 | 452 | ); |
453 | - $cancellation_line_item = reset( $cancellation_line_item ); |
|
453 | + $cancellation_line_item = reset($cancellation_line_item); |
|
454 | 454 | // verify that this ticket was indeed previously cancelled |
455 | - if ( ! $cancellation_line_item instanceof EE_Line_Item ) { |
|
455 | + if ( ! $cancellation_line_item instanceof EE_Line_Item) { |
|
456 | 456 | return false; |
457 | 457 | } |
458 | - if ( $cancellation_line_item->quantity() > $qty ) { |
|
458 | + if ($cancellation_line_item->quantity() > $qty) { |
|
459 | 459 | // decrement cancelled quantity |
460 | - $cancellation_line_item->set_quantity( $cancellation_line_item->quantity() - $qty ); |
|
461 | - } else if ( $cancellation_line_item->quantity() == $qty ) { |
|
460 | + $cancellation_line_item->set_quantity($cancellation_line_item->quantity() - $qty); |
|
461 | + } else if ($cancellation_line_item->quantity() == $qty) { |
|
462 | 462 | // decrement cancelled quantity in case anyone still has the object kicking around |
463 | - $cancellation_line_item->set_quantity( $cancellation_line_item->quantity() - $qty ); |
|
463 | + $cancellation_line_item->set_quantity($cancellation_line_item->quantity() - $qty); |
|
464 | 464 | // delete because quantity will end up as 0 |
465 | 465 | $cancellation_line_item->delete(); |
466 | 466 | // and attempt to destroy the object, |
467 | 467 | // even though PHP won't actually destroy it until it needs the memory |
468 | - unset( $cancellation_line_item ); |
|
468 | + unset($cancellation_line_item); |
|
469 | 469 | } else { |
470 | 470 | // what ?!?! negative quantity ?!?! |
471 | 471 | throw new EE_Error( |
472 | 472 | sprintf( |
473 | - __( 'Can not reinstate %1$d cancelled ticket(s) because the cancelled ticket quantity is only %2$d.', |
|
474 | - 'event_espresso' ), |
|
473 | + __('Can not reinstate %1$d cancelled ticket(s) because the cancelled ticket quantity is only %2$d.', |
|
474 | + 'event_espresso'), |
|
475 | 475 | $qty, |
476 | 476 | $cancellation_line_item->quantity() |
477 | 477 | ) |
478 | 478 | ); |
479 | 479 | } |
480 | 480 | // increment ticket quantity |
481 | - $ticket_line_item->set_quantity( $ticket_line_item->quantity() + $qty ); |
|
482 | - if ( $ticket_line_item->save_this_and_descendants() > 0 ) { |
|
481 | + $ticket_line_item->set_quantity($ticket_line_item->quantity() + $qty); |
|
482 | + if ($ticket_line_item->save_this_and_descendants() > 0) { |
|
483 | 483 | // increment parent line item quantity |
484 | 484 | $event_line_item = $ticket_line_item->parent(); |
485 | - if ( $event_line_item instanceof EE_Line_Item && $event_line_item->OBJ_type() === 'Event' ) { |
|
486 | - $event_line_item->set_quantity( $event_line_item->quantity() + $qty ); |
|
485 | + if ($event_line_item instanceof EE_Line_Item && $event_line_item->OBJ_type() === 'Event') { |
|
486 | + $event_line_item->set_quantity($event_line_item->quantity() + $qty); |
|
487 | 487 | } |
488 | - EEH_Line_Item::get_grand_total_and_recalculate_everything( $ticket_line_item ); |
|
488 | + EEH_Line_Item::get_grand_total_and_recalculate_everything($ticket_line_item); |
|
489 | 489 | return true; |
490 | 490 | } |
491 | 491 | return false; |
@@ -500,8 +500,8 @@ discard block |
||
500 | 500 | * @param EE_Line_Item $line_item |
501 | 501 | * @return \EE_Line_Item |
502 | 502 | */ |
503 | - public static function get_grand_total_and_recalculate_everything( EE_Line_Item $line_item ){ |
|
504 | - $grand_total_line_item = EEH_Line_Item::find_transaction_grand_total_for_line_item( $line_item ); |
|
503 | + public static function get_grand_total_and_recalculate_everything(EE_Line_Item $line_item) { |
|
504 | + $grand_total_line_item = EEH_Line_Item::find_transaction_grand_total_for_line_item($line_item); |
|
505 | 505 | return $grand_total_line_item->recalculate_total_including_taxes(); |
506 | 506 | } |
507 | 507 | |
@@ -514,11 +514,11 @@ discard block |
||
514 | 514 | * @return \EE_Line_Item |
515 | 515 | * @throws \EE_Error |
516 | 516 | */ |
517 | - public static function get_pre_tax_subtotal( EE_Line_Item $total_line_item ){ |
|
518 | - $pre_tax_subtotal = $total_line_item->get_child_line_item( 'pre-tax-subtotal' ); |
|
517 | + public static function get_pre_tax_subtotal(EE_Line_Item $total_line_item) { |
|
518 | + $pre_tax_subtotal = $total_line_item->get_child_line_item('pre-tax-subtotal'); |
|
519 | 519 | return $pre_tax_subtotal instanceof EE_Line_Item |
520 | 520 | ? $pre_tax_subtotal |
521 | - : self::create_pre_tax_subtotal( $total_line_item ); |
|
521 | + : self::create_pre_tax_subtotal($total_line_item); |
|
522 | 522 | } |
523 | 523 | |
524 | 524 | |
@@ -530,9 +530,9 @@ discard block |
||
530 | 530 | * @return \EE_Line_Item |
531 | 531 | * @throws \EE_Error |
532 | 532 | */ |
533 | - public static function get_taxes_subtotal( EE_Line_Item $total_line_item ){ |
|
534 | - $taxes = $total_line_item->get_child_line_item( 'taxes' ); |
|
535 | - return $taxes ? $taxes : self::create_taxes_subtotal( $total_line_item ); |
|
533 | + public static function get_taxes_subtotal(EE_Line_Item $total_line_item) { |
|
534 | + $taxes = $total_line_item->get_child_line_item('taxes'); |
|
535 | + return $taxes ? $taxes : self::create_taxes_subtotal($total_line_item); |
|
536 | 536 | } |
537 | 537 | |
538 | 538 | |
@@ -545,12 +545,12 @@ discard block |
||
545 | 545 | * @return void |
546 | 546 | * @throws \EE_Error |
547 | 547 | */ |
548 | - public static function set_TXN_ID( EE_Line_Item $line_item, $transaction = NULL ){ |
|
549 | - if( $transaction ){ |
|
548 | + public static function set_TXN_ID(EE_Line_Item $line_item, $transaction = NULL) { |
|
549 | + if ($transaction) { |
|
550 | 550 | /** @type EEM_Transaction $EEM_Transaction */ |
551 | - $EEM_Transaction = EE_Registry::instance()->load_model( 'Transaction' ); |
|
552 | - $TXN_ID = $EEM_Transaction->ensure_is_ID( $transaction ); |
|
553 | - $line_item->set_TXN_ID( $TXN_ID ); |
|
551 | + $EEM_Transaction = EE_Registry::instance()->load_model('Transaction'); |
|
552 | + $TXN_ID = $EEM_Transaction->ensure_is_ID($transaction); |
|
553 | + $line_item->set_TXN_ID($TXN_ID); |
|
554 | 554 | } |
555 | 555 | } |
556 | 556 | |
@@ -565,8 +565,8 @@ discard block |
||
565 | 565 | * @return \EE_Line_Item of type total |
566 | 566 | * @throws \EE_Error |
567 | 567 | */ |
568 | - public static function create_total_line_item( $transaction = NULL ){ |
|
569 | - $total_line_item = EE_Line_Item::new_instance( array( |
|
568 | + public static function create_total_line_item($transaction = NULL) { |
|
569 | + $total_line_item = EE_Line_Item::new_instance(array( |
|
570 | 570 | 'LIN_code' => 'total', |
571 | 571 | 'LIN_name' => __('Grand Total', 'event_espresso'), |
572 | 572 | 'LIN_type' => EEM_Line_Item::type_total, |
@@ -576,9 +576,9 @@ discard block |
||
576 | 576 | 'FHEE__EEH_Line_Item__create_total_line_item__total_line_item', |
577 | 577 | $total_line_item |
578 | 578 | ); |
579 | - self::set_TXN_ID( $total_line_item, $transaction ); |
|
580 | - self::create_pre_tax_subtotal( $total_line_item, $transaction ); |
|
581 | - self::create_taxes_subtotal( $total_line_item, $transaction ); |
|
579 | + self::set_TXN_ID($total_line_item, $transaction); |
|
580 | + self::create_pre_tax_subtotal($total_line_item, $transaction); |
|
581 | + self::create_taxes_subtotal($total_line_item, $transaction); |
|
582 | 582 | return $total_line_item; |
583 | 583 | } |
584 | 584 | |
@@ -592,19 +592,19 @@ discard block |
||
592 | 592 | * @return EE_Line_Item |
593 | 593 | * @throws \EE_Error |
594 | 594 | */ |
595 | - protected static function create_pre_tax_subtotal( EE_Line_Item $total_line_item, $transaction = NULL ){ |
|
596 | - $pre_tax_line_item = EE_Line_Item::new_instance( array( |
|
595 | + protected static function create_pre_tax_subtotal(EE_Line_Item $total_line_item, $transaction = NULL) { |
|
596 | + $pre_tax_line_item = EE_Line_Item::new_instance(array( |
|
597 | 597 | 'LIN_code' => 'pre-tax-subtotal', |
598 | - 'LIN_name' => __( 'Pre-Tax Subtotal', 'event_espresso' ), |
|
598 | + 'LIN_name' => __('Pre-Tax Subtotal', 'event_espresso'), |
|
599 | 599 | 'LIN_type' => EEM_Line_Item::type_sub_total |
600 | - ) ); |
|
600 | + )); |
|
601 | 601 | $pre_tax_line_item = apply_filters( |
602 | 602 | 'FHEE__EEH_Line_Item__create_pre_tax_subtotal__pre_tax_line_item', |
603 | 603 | $pre_tax_line_item |
604 | 604 | ); |
605 | - self::set_TXN_ID( $pre_tax_line_item, $transaction ); |
|
606 | - $total_line_item->add_child_line_item( $pre_tax_line_item ); |
|
607 | - self::create_event_subtotal( $pre_tax_line_item, $transaction ); |
|
605 | + self::set_TXN_ID($pre_tax_line_item, $transaction); |
|
606 | + $total_line_item->add_child_line_item($pre_tax_line_item); |
|
607 | + self::create_event_subtotal($pre_tax_line_item, $transaction); |
|
608 | 608 | return $pre_tax_line_item; |
609 | 609 | } |
610 | 610 | |
@@ -619,21 +619,21 @@ discard block |
||
619 | 619 | * @return EE_Line_Item |
620 | 620 | * @throws \EE_Error |
621 | 621 | */ |
622 | - protected static function create_taxes_subtotal( EE_Line_Item $total_line_item, $transaction = NULL ){ |
|
622 | + protected static function create_taxes_subtotal(EE_Line_Item $total_line_item, $transaction = NULL) { |
|
623 | 623 | $tax_line_item = EE_Line_Item::new_instance(array( |
624 | 624 | 'LIN_code' => 'taxes', |
625 | 625 | 'LIN_name' => __('Taxes', 'event_espresso'), |
626 | 626 | 'LIN_type' => EEM_Line_Item::type_tax_sub_total, |
627 | - 'LIN_order' => 1000,//this should always come last |
|
627 | + 'LIN_order' => 1000, //this should always come last |
|
628 | 628 | )); |
629 | 629 | $tax_line_item = apply_filters( |
630 | 630 | 'FHEE__EEH_Line_Item__create_taxes_subtotal__tax_line_item', |
631 | 631 | $tax_line_item |
632 | 632 | ); |
633 | - self::set_TXN_ID( $tax_line_item, $transaction ); |
|
634 | - $total_line_item->add_child_line_item( $tax_line_item ); |
|
633 | + self::set_TXN_ID($tax_line_item, $transaction); |
|
634 | + $total_line_item->add_child_line_item($tax_line_item); |
|
635 | 635 | //and lastly, add the actual taxes |
636 | - self::apply_taxes( $total_line_item ); |
|
636 | + self::apply_taxes($total_line_item); |
|
637 | 637 | return $tax_line_item; |
638 | 638 | } |
639 | 639 | |
@@ -648,11 +648,11 @@ discard block |
||
648 | 648 | * @return EE_Line_Item |
649 | 649 | * @throws \EE_Error |
650 | 650 | */ |
651 | - public static function create_event_subtotal( EE_Line_Item $pre_tax_line_item, $transaction = NULL, $event = NULL ){ |
|
651 | + public static function create_event_subtotal(EE_Line_Item $pre_tax_line_item, $transaction = NULL, $event = NULL) { |
|
652 | 652 | $event_line_item = EE_Line_Item::new_instance(array( |
653 | - 'LIN_code' => self::get_event_code( $event ), |
|
654 | - 'LIN_name' => self::get_event_name( $event ), |
|
655 | - 'LIN_desc' => self::get_event_desc( $event ), |
|
653 | + 'LIN_code' => self::get_event_code($event), |
|
654 | + 'LIN_name' => self::get_event_name($event), |
|
655 | + 'LIN_desc' => self::get_event_desc($event), |
|
656 | 656 | 'LIN_type' => EEM_Line_Item::type_sub_total, |
657 | 657 | 'OBJ_type' => 'Event', |
658 | 658 | 'OBJ_ID' => $event instanceof EE_Event ? $event->ID() : 0 |
@@ -661,8 +661,8 @@ discard block |
||
661 | 661 | 'FHEE__EEH_Line_Item__create_event_subtotal__event_line_item', |
662 | 662 | $event_line_item |
663 | 663 | ); |
664 | - self::set_TXN_ID( $event_line_item, $transaction ); |
|
665 | - $pre_tax_line_item->add_child_line_item( $event_line_item ); |
|
664 | + self::set_TXN_ID($event_line_item, $transaction); |
|
665 | + $pre_tax_line_item->add_child_line_item($event_line_item); |
|
666 | 666 | return $event_line_item; |
667 | 667 | } |
668 | 668 | |
@@ -675,8 +675,8 @@ discard block |
||
675 | 675 | * @return string |
676 | 676 | * @throws \EE_Error |
677 | 677 | */ |
678 | - public static function get_event_code( $event ) { |
|
679 | - return 'event-' . ( $event instanceof EE_Event ? $event->ID() : '0' ); |
|
678 | + public static function get_event_code($event) { |
|
679 | + return 'event-'.($event instanceof EE_Event ? $event->ID() : '0'); |
|
680 | 680 | } |
681 | 681 | |
682 | 682 | /** |
@@ -684,8 +684,8 @@ discard block |
||
684 | 684 | * @param EE_Event $event |
685 | 685 | * @return string |
686 | 686 | */ |
687 | - public static function get_event_name( $event ) { |
|
688 | - return $event instanceof EE_Event ? $event->name() : __( 'Event', 'event_espresso' ); |
|
687 | + public static function get_event_name($event) { |
|
688 | + return $event instanceof EE_Event ? $event->name() : __('Event', 'event_espresso'); |
|
689 | 689 | } |
690 | 690 | |
691 | 691 | /** |
@@ -693,7 +693,7 @@ discard block |
||
693 | 693 | * @param EE_Event $event |
694 | 694 | * @return string |
695 | 695 | */ |
696 | - public static function get_event_desc( $event ) { |
|
696 | + public static function get_event_desc($event) { |
|
697 | 697 | return $event instanceof EE_Event ? $event->short_description() : ''; |
698 | 698 | } |
699 | 699 | |
@@ -707,27 +707,27 @@ discard block |
||
707 | 707 | * @throws \EE_Error |
708 | 708 | * @return EE_Line_Item |
709 | 709 | */ |
710 | - public static function get_event_line_item_for_ticket( EE_Line_Item $grand_total, EE_Ticket $ticket ) { |
|
710 | + public static function get_event_line_item_for_ticket(EE_Line_Item $grand_total, EE_Ticket $ticket) { |
|
711 | 711 | $first_datetime = $ticket->first_datetime(); |
712 | - if ( ! $first_datetime instanceof EE_Datetime ) { |
|
712 | + if ( ! $first_datetime instanceof EE_Datetime) { |
|
713 | 713 | throw new EE_Error( |
714 | - sprintf( __( 'The supplied ticket (ID %d) has no datetimes', 'event_espresso' ), $ticket->ID() ) |
|
714 | + sprintf(__('The supplied ticket (ID %d) has no datetimes', 'event_espresso'), $ticket->ID()) |
|
715 | 715 | ); |
716 | 716 | } |
717 | 717 | $event = $first_datetime->event(); |
718 | - if ( ! $event instanceof EE_Event ) { |
|
718 | + if ( ! $event instanceof EE_Event) { |
|
719 | 719 | throw new EE_Error( |
720 | 720 | sprintf( |
721 | - __( 'The supplied ticket (ID %d) has no event data associated with it.', 'event_espresso' ), |
|
721 | + __('The supplied ticket (ID %d) has no event data associated with it.', 'event_espresso'), |
|
722 | 722 | $ticket->ID() |
723 | 723 | ) |
724 | 724 | ); |
725 | 725 | } |
726 | - $events_sub_total = EEH_Line_Item::get_event_line_item( $grand_total, $event ); |
|
727 | - if ( ! $events_sub_total instanceof EE_Line_Item ) { |
|
726 | + $events_sub_total = EEH_Line_Item::get_event_line_item($grand_total, $event); |
|
727 | + if ( ! $events_sub_total instanceof EE_Line_Item) { |
|
728 | 728 | throw new EE_Error( |
729 | 729 | sprintf( |
730 | - __( 'There is no events sub-total for ticket %s on total line item %d', 'event_espresso' ), |
|
730 | + __('There is no events sub-total for ticket %s on total line item %d', 'event_espresso'), |
|
731 | 731 | $ticket->ID(), |
732 | 732 | $grand_total->ID() |
733 | 733 | ) |
@@ -746,31 +746,31 @@ discard block |
||
746 | 746 | * @return EE_Line_Item for the event subtotal which is a child of $grand_total |
747 | 747 | * @throws \EE_Error |
748 | 748 | */ |
749 | - public static function get_event_line_item( EE_Line_Item $grand_total, $event ) { |
|
749 | + public static function get_event_line_item(EE_Line_Item $grand_total, $event) { |
|
750 | 750 | /** @type EE_Event $event */ |
751 | - $event = EEM_Event::instance()->ensure_is_obj( $event, true ); |
|
751 | + $event = EEM_Event::instance()->ensure_is_obj($event, true); |
|
752 | 752 | $event_line_item = NULL; |
753 | 753 | $found = false; |
754 | - foreach ( EEH_Line_Item::get_event_subtotals( $grand_total ) as $event_line_item ) { |
|
754 | + foreach (EEH_Line_Item::get_event_subtotals($grand_total) as $event_line_item) { |
|
755 | 755 | // default event subtotal, we should only ever find this the first time this method is called |
756 | - if ( ! $event_line_item->OBJ_ID() ) { |
|
756 | + if ( ! $event_line_item->OBJ_ID()) { |
|
757 | 757 | // let's use this! but first... set the event details |
758 | - EEH_Line_Item::set_event_subtotal_details( $event_line_item, $event ); |
|
758 | + EEH_Line_Item::set_event_subtotal_details($event_line_item, $event); |
|
759 | 759 | $found = true; |
760 | 760 | break; |
761 | - } else if ( $event_line_item->OBJ_ID() === $event->ID() ) { |
|
761 | + } else if ($event_line_item->OBJ_ID() === $event->ID()) { |
|
762 | 762 | // found existing line item for this event in the cart, so break out of loop and use this one |
763 | 763 | $found = true; |
764 | 764 | break; |
765 | 765 | } |
766 | 766 | } |
767 | - if ( ! $found ) { |
|
767 | + if ( ! $found) { |
|
768 | 768 | //there is no event sub-total yet, so add it |
769 | - $pre_tax_subtotal = EEH_Line_Item::get_pre_tax_subtotal( $grand_total ); |
|
769 | + $pre_tax_subtotal = EEH_Line_Item::get_pre_tax_subtotal($grand_total); |
|
770 | 770 | // create a new "event" subtotal below that |
771 | - $event_line_item = EEH_Line_Item::create_event_subtotal( $pre_tax_subtotal, null, $event ); |
|
771 | + $event_line_item = EEH_Line_Item::create_event_subtotal($pre_tax_subtotal, null, $event); |
|
772 | 772 | // and set the event details |
773 | - EEH_Line_Item::set_event_subtotal_details( $event_line_item, $event ); |
|
773 | + EEH_Line_Item::set_event_subtotal_details($event_line_item, $event); |
|
774 | 774 | } |
775 | 775 | return $event_line_item; |
776 | 776 | } |
@@ -791,13 +791,13 @@ discard block |
||
791 | 791 | EE_Event $event, |
792 | 792 | $transaction = null |
793 | 793 | ) { |
794 | - if ( $event instanceof EE_Event ) { |
|
795 | - $event_line_item->set_code( self::get_event_code( $event ) ); |
|
796 | - $event_line_item->set_name( self::get_event_name( $event ) ); |
|
797 | - $event_line_item->set_desc( self::get_event_desc( $event ) ); |
|
798 | - $event_line_item->set_OBJ_ID( $event->ID() ); |
|
794 | + if ($event instanceof EE_Event) { |
|
795 | + $event_line_item->set_code(self::get_event_code($event)); |
|
796 | + $event_line_item->set_name(self::get_event_name($event)); |
|
797 | + $event_line_item->set_desc(self::get_event_desc($event)); |
|
798 | + $event_line_item->set_OBJ_ID($event->ID()); |
|
799 | 799 | } |
800 | - self::set_TXN_ID( $event_line_item, $transaction ); |
|
800 | + self::set_TXN_ID($event_line_item, $transaction); |
|
801 | 801 | } |
802 | 802 | |
803 | 803 | |
@@ -810,19 +810,19 @@ discard block |
||
810 | 810 | * @param EE_Line_Item $total_line_item of type EEM_Line_Item::type_total |
811 | 811 | * @throws \EE_Error |
812 | 812 | */ |
813 | - public static function apply_taxes( EE_Line_Item $total_line_item ){ |
|
813 | + public static function apply_taxes(EE_Line_Item $total_line_item) { |
|
814 | 814 | /** @type EEM_Price $EEM_Price */ |
815 | - $EEM_Price = EE_Registry::instance()->load_model( 'Price' ); |
|
815 | + $EEM_Price = EE_Registry::instance()->load_model('Price'); |
|
816 | 816 | // get array of taxes via Price Model |
817 | 817 | $ordered_taxes = $EEM_Price->get_all_prices_that_are_taxes(); |
818 | - ksort( $ordered_taxes ); |
|
819 | - $taxes_line_item = self::get_taxes_subtotal( $total_line_item ); |
|
818 | + ksort($ordered_taxes); |
|
819 | + $taxes_line_item = self::get_taxes_subtotal($total_line_item); |
|
820 | 820 | //just to be safe, remove its old tax line items |
821 | 821 | $taxes_line_item->delete_children_line_items(); |
822 | 822 | //loop thru taxes |
823 | - foreach ( $ordered_taxes as $order => $taxes ) { |
|
824 | - foreach ( $taxes as $tax ) { |
|
825 | - if ( $tax instanceof EE_Price ) { |
|
823 | + foreach ($ordered_taxes as $order => $taxes) { |
|
824 | + foreach ($taxes as $tax) { |
|
825 | + if ($tax instanceof EE_Price) { |
|
826 | 826 | $tax_line_item = EE_Line_Item::new_instance( |
827 | 827 | array( |
828 | 828 | 'LIN_name' => $tax->name(), |
@@ -840,7 +840,7 @@ discard block |
||
840 | 840 | 'FHEE__EEH_Line_Item__apply_taxes__tax_line_item', |
841 | 841 | $tax_line_item |
842 | 842 | ); |
843 | - $taxes_line_item->add_child_line_item( $tax_line_item ); |
|
843 | + $taxes_line_item->add_child_line_item($tax_line_item); |
|
844 | 844 | } |
845 | 845 | } |
846 | 846 | } |
@@ -857,10 +857,10 @@ discard block |
||
857 | 857 | * @return float |
858 | 858 | * @throws \EE_Error |
859 | 859 | */ |
860 | - public static function ensure_taxes_applied( $total_line_item ){ |
|
861 | - $taxes_subtotal = self::get_taxes_subtotal( $total_line_item ); |
|
862 | - if( ! $taxes_subtotal->children()){ |
|
863 | - self::apply_taxes( $total_line_item ); |
|
860 | + public static function ensure_taxes_applied($total_line_item) { |
|
861 | + $taxes_subtotal = self::get_taxes_subtotal($total_line_item); |
|
862 | + if ( ! $taxes_subtotal->children()) { |
|
863 | + self::apply_taxes($total_line_item); |
|
864 | 864 | } |
865 | 865 | return $taxes_subtotal->total(); |
866 | 866 | } |
@@ -874,16 +874,16 @@ discard block |
||
874 | 874 | * @return bool |
875 | 875 | * @throws \EE_Error |
876 | 876 | */ |
877 | - public static function delete_all_child_items( EE_Line_Item $parent_line_item ) { |
|
877 | + public static function delete_all_child_items(EE_Line_Item $parent_line_item) { |
|
878 | 878 | $deleted = 0; |
879 | - foreach ( $parent_line_item->children() as $child_line_item ) { |
|
880 | - if ( $child_line_item instanceof EE_Line_Item ) { |
|
881 | - $deleted += EEH_Line_Item::delete_all_child_items( $child_line_item ); |
|
882 | - if ( $child_line_item->ID() ) { |
|
879 | + foreach ($parent_line_item->children() as $child_line_item) { |
|
880 | + if ($child_line_item instanceof EE_Line_Item) { |
|
881 | + $deleted += EEH_Line_Item::delete_all_child_items($child_line_item); |
|
882 | + if ($child_line_item->ID()) { |
|
883 | 883 | $child_line_item->delete(); |
884 | - unset( $child_line_item ); |
|
884 | + unset($child_line_item); |
|
885 | 885 | } else { |
886 | - $parent_line_item->delete_child_line_item( $child_line_item->code() ); |
|
886 | + $parent_line_item->delete_child_line_item($child_line_item->code()); |
|
887 | 887 | } |
888 | 888 | $deleted++; |
889 | 889 | } |
@@ -905,9 +905,9 @@ discard block |
||
905 | 905 | * @param array|bool|string $line_item_codes |
906 | 906 | * @return int number of items successfully removed |
907 | 907 | */ |
908 | - public static function delete_items( EE_Line_Item $total_line_item, $line_item_codes = FALSE ) { |
|
908 | + public static function delete_items(EE_Line_Item $total_line_item, $line_item_codes = FALSE) { |
|
909 | 909 | |
910 | - if( $total_line_item->type() !== EEM_Line_Item::type_total ){ |
|
910 | + if ($total_line_item->type() !== EEM_Line_Item::type_total) { |
|
911 | 911 | EE_Error::doing_it_wrong( |
912 | 912 | 'EEH_Line_Item::delete_items', |
913 | 913 | __( |
@@ -917,20 +917,20 @@ discard block |
||
917 | 917 | '4.6.18' |
918 | 918 | ); |
919 | 919 | } |
920 | - do_action( 'AHEE_log', __FILE__, __FUNCTION__, '' ); |
|
920 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
921 | 921 | |
922 | 922 | // check if only a single line_item_id was passed |
923 | - if ( ! empty( $line_item_codes ) && ! is_array( $line_item_codes )) { |
|
923 | + if ( ! empty($line_item_codes) && ! is_array($line_item_codes)) { |
|
924 | 924 | // place single line_item_id in an array to appear as multiple line_item_ids |
925 | - $line_item_codes = array ( $line_item_codes ); |
|
925 | + $line_item_codes = array($line_item_codes); |
|
926 | 926 | } |
927 | 927 | $removals = 0; |
928 | 928 | // cycle thru line_item_ids |
929 | - foreach ( $line_item_codes as $line_item_id ) { |
|
929 | + foreach ($line_item_codes as $line_item_id) { |
|
930 | 930 | $removals += $total_line_item->delete_child_line_item($line_item_id); |
931 | 931 | } |
932 | 932 | |
933 | - if ( $removals > 0 ) { |
|
933 | + if ($removals > 0) { |
|
934 | 934 | $total_line_item->recalculate_taxes_and_tax_total(); |
935 | 935 | return $removals; |
936 | 936 | } else { |
@@ -963,33 +963,33 @@ discard block |
||
963 | 963 | $code = null, |
964 | 964 | $add_to_existing_line_item = false |
965 | 965 | ) { |
966 | - $tax_subtotal = self::get_taxes_subtotal( $total_line_item ); |
|
966 | + $tax_subtotal = self::get_taxes_subtotal($total_line_item); |
|
967 | 967 | $taxable_total = $total_line_item->taxable_total(); |
968 | 968 | |
969 | - if( $add_to_existing_line_item ) { |
|
970 | - $new_tax = $tax_subtotal->get_child_line_item( $code ); |
|
969 | + if ($add_to_existing_line_item) { |
|
970 | + $new_tax = $tax_subtotal->get_child_line_item($code); |
|
971 | 971 | EEM_Line_Item::instance()->delete( |
972 | - array( array( 'LIN_code' => array( '!=', $code ), 'LIN_parent' => $tax_subtotal->ID() ) ) |
|
972 | + array(array('LIN_code' => array('!=', $code), 'LIN_parent' => $tax_subtotal->ID())) |
|
973 | 973 | ); |
974 | 974 | } else { |
975 | 975 | $new_tax = null; |
976 | 976 | $tax_subtotal->delete_children_line_items(); |
977 | 977 | } |
978 | - if( $new_tax ) { |
|
979 | - $new_tax->set_total( $new_tax->total() + $amount ); |
|
980 | - $new_tax->set_percent( $taxable_total ? $new_tax->total() / $taxable_total * 100 : 0 ); |
|
978 | + if ($new_tax) { |
|
979 | + $new_tax->set_total($new_tax->total() + $amount); |
|
980 | + $new_tax->set_percent($taxable_total ? $new_tax->total() / $taxable_total * 100 : 0); |
|
981 | 981 | } else { |
982 | 982 | //no existing tax item. Create it |
983 | - $new_tax = EE_Line_Item::new_instance( array( |
|
983 | + $new_tax = EE_Line_Item::new_instance(array( |
|
984 | 984 | 'TXN_ID' => $total_line_item->TXN_ID(), |
985 | - 'LIN_name' => $name ? $name : __( 'Tax', 'event_espresso' ), |
|
985 | + 'LIN_name' => $name ? $name : __('Tax', 'event_espresso'), |
|
986 | 986 | 'LIN_desc' => $description ? $description : '', |
987 | - 'LIN_percent' => $taxable_total ? ( $amount / $taxable_total * 100 ) : 0, |
|
987 | + 'LIN_percent' => $taxable_total ? ($amount / $taxable_total * 100) : 0, |
|
988 | 988 | 'LIN_total' => $amount, |
989 | 989 | 'LIN_parent' => $tax_subtotal->ID(), |
990 | 990 | 'LIN_type' => EEM_Line_Item::type_tax, |
991 | 991 | 'LIN_code' => $code |
992 | - ) ); |
|
992 | + )); |
|
993 | 993 | } |
994 | 994 | |
995 | 995 | $new_tax = apply_filters( |
@@ -998,7 +998,7 @@ discard block |
||
998 | 998 | $total_line_item |
999 | 999 | ); |
1000 | 1000 | $new_tax->save(); |
1001 | - $tax_subtotal->set_total( $new_tax->total() ); |
|
1001 | + $tax_subtotal->set_total($new_tax->total()); |
|
1002 | 1002 | $tax_subtotal->save(); |
1003 | 1003 | $total_line_item->recalculate_total_including_taxes(); |
1004 | 1004 | return $new_tax; |
@@ -1020,14 +1020,14 @@ discard block |
||
1020 | 1020 | $code_substring_for_whitelist = null |
1021 | 1021 | ) { |
1022 | 1022 | $whitelisted = false; |
1023 | - if( $code_substring_for_whitelist !== null ) { |
|
1024 | - $whitelisted = strpos( $line_item->code(), $code_substring_for_whitelist ) !== false ? true : false; |
|
1023 | + if ($code_substring_for_whitelist !== null) { |
|
1024 | + $whitelisted = strpos($line_item->code(), $code_substring_for_whitelist) !== false ? true : false; |
|
1025 | 1025 | } |
1026 | - if( ! $whitelisted && $line_item->is_line_item() ) { |
|
1027 | - $line_item->set_is_taxable( $taxable ); |
|
1026 | + if ( ! $whitelisted && $line_item->is_line_item()) { |
|
1027 | + $line_item->set_is_taxable($taxable); |
|
1028 | 1028 | } |
1029 | - foreach( $line_item->children() as $child_line_item ) { |
|
1030 | - EEH_Line_Item::set_line_items_taxable( $child_line_item, $taxable, $code_substring_for_whitelist ); |
|
1029 | + foreach ($line_item->children() as $child_line_item) { |
|
1030 | + EEH_Line_Item::set_line_items_taxable($child_line_item, $taxable, $code_substring_for_whitelist); |
|
1031 | 1031 | } |
1032 | 1032 | } |
1033 | 1033 | |
@@ -1040,8 +1040,8 @@ discard block |
||
1040 | 1040 | * @param \EE_Line_Item $parent_line_item - the line item to find descendants of |
1041 | 1041 | * @return EE_Line_Item[] |
1042 | 1042 | */ |
1043 | - public static function get_event_subtotals( EE_Line_Item $parent_line_item ) { |
|
1044 | - return self::get_subtotals_of_object_type( $parent_line_item, 'Event' ); |
|
1043 | + public static function get_event_subtotals(EE_Line_Item $parent_line_item) { |
|
1044 | + return self::get_subtotals_of_object_type($parent_line_item, 'Event'); |
|
1045 | 1045 | } |
1046 | 1046 | |
1047 | 1047 | |
@@ -1054,7 +1054,7 @@ discard block |
||
1054 | 1054 | * @param string $obj_type |
1055 | 1055 | * @return EE_Line_Item[] |
1056 | 1056 | */ |
1057 | - public static function get_subtotals_of_object_type( EE_Line_Item $parent_line_item, $obj_type = '' ) { |
|
1057 | + public static function get_subtotals_of_object_type(EE_Line_Item $parent_line_item, $obj_type = '') { |
|
1058 | 1058 | return self::_get_descendants_by_type_and_object_type( |
1059 | 1059 | $parent_line_item, |
1060 | 1060 | EEM_Line_Item::type_sub_total, |
@@ -1071,8 +1071,8 @@ discard block |
||
1071 | 1071 | * @param \EE_Line_Item $parent_line_item - the line item to find descendants of |
1072 | 1072 | * @return EE_Line_Item[] |
1073 | 1073 | */ |
1074 | - public static function get_ticket_line_items( EE_Line_Item $parent_line_item ) { |
|
1075 | - return self::get_line_items_of_object_type( $parent_line_item, 'Ticket' ); |
|
1074 | + public static function get_ticket_line_items(EE_Line_Item $parent_line_item) { |
|
1075 | + return self::get_line_items_of_object_type($parent_line_item, 'Ticket'); |
|
1076 | 1076 | } |
1077 | 1077 | |
1078 | 1078 | |
@@ -1085,8 +1085,8 @@ discard block |
||
1085 | 1085 | * @param string $obj_type |
1086 | 1086 | * @return EE_Line_Item[] |
1087 | 1087 | */ |
1088 | - public static function get_line_items_of_object_type( EE_Line_Item $parent_line_item, $obj_type = '' ) { |
|
1089 | - return self::_get_descendants_by_type_and_object_type( $parent_line_item, EEM_Line_Item::type_line_item, $obj_type ); |
|
1088 | + public static function get_line_items_of_object_type(EE_Line_Item $parent_line_item, $obj_type = '') { |
|
1089 | + return self::_get_descendants_by_type_and_object_type($parent_line_item, EEM_Line_Item::type_line_item, $obj_type); |
|
1090 | 1090 | } |
1091 | 1091 | |
1092 | 1092 | |
@@ -1097,8 +1097,8 @@ discard block |
||
1097 | 1097 | * @param \EE_Line_Item $parent_line_item - the line item to find descendants of |
1098 | 1098 | * @return EE_Line_Item[] |
1099 | 1099 | */ |
1100 | - public static function get_tax_descendants( EE_Line_Item $parent_line_item ) { |
|
1101 | - return EEH_Line_Item::get_descendants_of_type( $parent_line_item, EEM_Line_Item::type_tax ); |
|
1100 | + public static function get_tax_descendants(EE_Line_Item $parent_line_item) { |
|
1101 | + return EEH_Line_Item::get_descendants_of_type($parent_line_item, EEM_Line_Item::type_tax); |
|
1102 | 1102 | } |
1103 | 1103 | |
1104 | 1104 | |
@@ -1109,8 +1109,8 @@ discard block |
||
1109 | 1109 | * @param \EE_Line_Item $parent_line_item - the line item to find descendants of |
1110 | 1110 | * @return EE_Line_Item[] |
1111 | 1111 | */ |
1112 | - public static function get_line_item_descendants( EE_Line_Item $parent_line_item ) { |
|
1113 | - return EEH_Line_Item::get_descendants_of_type( $parent_line_item, EEM_Line_Item::type_line_item ); |
|
1112 | + public static function get_line_item_descendants(EE_Line_Item $parent_line_item) { |
|
1113 | + return EEH_Line_Item::get_descendants_of_type($parent_line_item, EEM_Line_Item::type_line_item); |
|
1114 | 1114 | } |
1115 | 1115 | |
1116 | 1116 | |
@@ -1123,8 +1123,8 @@ discard block |
||
1123 | 1123 | * @param string $line_item_type one of the EEM_Line_Item constants |
1124 | 1124 | * @return EE_Line_Item[] |
1125 | 1125 | */ |
1126 | - public static function get_descendants_of_type( EE_Line_Item $parent_line_item, $line_item_type ) { |
|
1127 | - return self::_get_descendants_by_type_and_object_type( $parent_line_item, $line_item_type, NULL ); |
|
1126 | + public static function get_descendants_of_type(EE_Line_Item $parent_line_item, $line_item_type) { |
|
1127 | + return self::_get_descendants_by_type_and_object_type($parent_line_item, $line_item_type, NULL); |
|
1128 | 1128 | } |
1129 | 1129 | |
1130 | 1130 | |
@@ -1143,8 +1143,8 @@ discard block |
||
1143 | 1143 | $obj_type = null |
1144 | 1144 | ) { |
1145 | 1145 | $objects = array(); |
1146 | - foreach ( $parent_line_item->children() as $child_line_item ) { |
|
1147 | - if ( $child_line_item instanceof EE_Line_Item ) { |
|
1146 | + foreach ($parent_line_item->children() as $child_line_item) { |
|
1147 | + if ($child_line_item instanceof EE_Line_Item) { |
|
1148 | 1148 | if ( |
1149 | 1149 | $child_line_item->type() === $line_item_type |
1150 | 1150 | && ( |
@@ -1184,7 +1184,7 @@ discard block |
||
1184 | 1184 | $OBJ_type = '', |
1185 | 1185 | $OBJ_IDs = array() |
1186 | 1186 | ) { |
1187 | - return self::_get_descendants_by_object_type_and_object_ID( $parent_line_item, $OBJ_type, $OBJ_IDs ); |
|
1187 | + return self::_get_descendants_by_object_type_and_object_ID($parent_line_item, $OBJ_type, $OBJ_IDs); |
|
1188 | 1188 | } |
1189 | 1189 | |
1190 | 1190 | |
@@ -1203,12 +1203,12 @@ discard block |
||
1203 | 1203 | $OBJ_IDs |
1204 | 1204 | ) { |
1205 | 1205 | $objects = array(); |
1206 | - foreach ( $parent_line_item->children() as $child_line_item ) { |
|
1207 | - if ( $child_line_item instanceof EE_Line_Item ) { |
|
1206 | + foreach ($parent_line_item->children() as $child_line_item) { |
|
1207 | + if ($child_line_item instanceof EE_Line_Item) { |
|
1208 | 1208 | if ( |
1209 | - is_array( $OBJ_IDs ) |
|
1209 | + is_array($OBJ_IDs) |
|
1210 | 1210 | && $child_line_item->OBJ_type() === $OBJ_type |
1211 | - && in_array( $child_line_item->OBJ_ID(), $OBJ_IDs ) |
|
1211 | + && in_array($child_line_item->OBJ_ID(), $OBJ_IDs) |
|
1212 | 1212 | ) { |
1213 | 1213 | $objects[] = $child_line_item; |
1214 | 1214 | } else { |
@@ -1238,8 +1238,8 @@ discard block |
||
1238 | 1238 | * @param string $type like one of the EEM_Line_Item::type_* |
1239 | 1239 | * @return EE_Line_Item |
1240 | 1240 | */ |
1241 | - public static function get_nearest_descendant_of_type( EE_Line_Item $parent_line_item, $type ) { |
|
1242 | - return self::_get_nearest_descendant( $parent_line_item, 'LIN_type' , $type ); |
|
1241 | + public static function get_nearest_descendant_of_type(EE_Line_Item $parent_line_item, $type) { |
|
1242 | + return self::_get_nearest_descendant($parent_line_item, 'LIN_type', $type); |
|
1243 | 1243 | } |
1244 | 1244 | |
1245 | 1245 | |
@@ -1253,8 +1253,8 @@ discard block |
||
1253 | 1253 | * @param string $code any value used for LIN_code |
1254 | 1254 | * @return EE_Line_Item |
1255 | 1255 | */ |
1256 | - public static function get_nearest_descendant_having_code( EE_Line_Item $parent_line_item, $code ) { |
|
1257 | - return self::_get_nearest_descendant( $parent_line_item, 'LIN_code' , $code ); |
|
1256 | + public static function get_nearest_descendant_having_code(EE_Line_Item $parent_line_item, $code) { |
|
1257 | + return self::_get_nearest_descendant($parent_line_item, 'LIN_code', $code); |
|
1258 | 1258 | } |
1259 | 1259 | |
1260 | 1260 | |
@@ -1268,15 +1268,15 @@ discard block |
||
1268 | 1268 | * @param string $value any value stored in $search_field |
1269 | 1269 | * @return EE_Line_Item |
1270 | 1270 | */ |
1271 | - protected static function _get_nearest_descendant( EE_Line_Item $parent_line_item, $search_field, $value ) { |
|
1272 | - foreach( $parent_line_item->children() as $child ){ |
|
1273 | - if ( $child->get( $search_field ) == $value ){ |
|
1271 | + protected static function _get_nearest_descendant(EE_Line_Item $parent_line_item, $search_field, $value) { |
|
1272 | + foreach ($parent_line_item->children() as $child) { |
|
1273 | + if ($child->get($search_field) == $value) { |
|
1274 | 1274 | return $child; |
1275 | 1275 | } |
1276 | 1276 | } |
1277 | - foreach( $parent_line_item->children() as $child ){ |
|
1278 | - $descendant_found = self::_get_nearest_descendant( $child, $search_field, $value ); |
|
1279 | - if ( $descendant_found ){ |
|
1277 | + foreach ($parent_line_item->children() as $child) { |
|
1278 | + $descendant_found = self::_get_nearest_descendant($child, $search_field, $value); |
|
1279 | + if ($descendant_found) { |
|
1280 | 1280 | return $descendant_found; |
1281 | 1281 | } |
1282 | 1282 | } |
@@ -1293,24 +1293,24 @@ discard block |
||
1293 | 1293 | * @return \EE_Line_Item |
1294 | 1294 | * @throws \EE_Error |
1295 | 1295 | */ |
1296 | - public static function find_transaction_grand_total_for_line_item( EE_Line_Item $line_item ){ |
|
1297 | - if ( $line_item->TXN_ID() ) { |
|
1298 | - $total_line_item = $line_item->transaction()->total_line_item( false ); |
|
1299 | - if ( $total_line_item instanceof EE_Line_Item ) { |
|
1296 | + public static function find_transaction_grand_total_for_line_item(EE_Line_Item $line_item) { |
|
1297 | + if ($line_item->TXN_ID()) { |
|
1298 | + $total_line_item = $line_item->transaction()->total_line_item(false); |
|
1299 | + if ($total_line_item instanceof EE_Line_Item) { |
|
1300 | 1300 | return $total_line_item; |
1301 | 1301 | } |
1302 | 1302 | } else { |
1303 | 1303 | $line_item_parent = $line_item->parent(); |
1304 | - if ( $line_item_parent instanceof EE_Line_Item ) { |
|
1305 | - if ( $line_item_parent->is_total() ) { |
|
1304 | + if ($line_item_parent instanceof EE_Line_Item) { |
|
1305 | + if ($line_item_parent->is_total()) { |
|
1306 | 1306 | return $line_item_parent; |
1307 | 1307 | } |
1308 | - return EEH_Line_Item::find_transaction_grand_total_for_line_item( $line_item_parent ); |
|
1308 | + return EEH_Line_Item::find_transaction_grand_total_for_line_item($line_item_parent); |
|
1309 | 1309 | } |
1310 | 1310 | } |
1311 | 1311 | throw new EE_Error( |
1312 | 1312 | sprintf( |
1313 | - __( 'A valid grand total for line item %1$d was not found.', 'event_espresso' ), |
|
1313 | + __('A valid grand total for line item %1$d was not found.', 'event_espresso'), |
|
1314 | 1314 | $line_item->ID() |
1315 | 1315 | ) |
1316 | 1316 | ); |
@@ -1327,31 +1327,31 @@ discard block |
||
1327 | 1327 | * @return void |
1328 | 1328 | * @throws \EE_Error |
1329 | 1329 | */ |
1330 | - public static function visualize( EE_Line_Item $line_item, $indentation = 0 ){ |
|
1330 | + public static function visualize(EE_Line_Item $line_item, $indentation = 0) { |
|
1331 | 1331 | echo defined('EE_TESTS_DIR') ? "\n" : '<br />'; |
1332 | - if ( ! $indentation ) { |
|
1333 | - echo defined( 'EE_TESTS_DIR' ) ? "\n" : '<br />'; |
|
1332 | + if ( ! $indentation) { |
|
1333 | + echo defined('EE_TESTS_DIR') ? "\n" : '<br />'; |
|
1334 | 1334 | } |
1335 | - for( $i = 0; $i < $indentation; $i++ ){ |
|
1335 | + for ($i = 0; $i < $indentation; $i++) { |
|
1336 | 1336 | echo ". "; |
1337 | 1337 | } |
1338 | 1338 | $breakdown = ''; |
1339 | - if ( $line_item->is_line_item()){ |
|
1340 | - if ( $line_item->is_percent() ) { |
|
1339 | + if ($line_item->is_line_item()) { |
|
1340 | + if ($line_item->is_percent()) { |
|
1341 | 1341 | $breakdown = "{$line_item->percent()}%"; |
1342 | 1342 | } else { |
1343 | - $breakdown = '$' . "{$line_item->unit_price()} x {$line_item->quantity()}"; |
|
1343 | + $breakdown = '$'."{$line_item->unit_price()} x {$line_item->quantity()}"; |
|
1344 | 1344 | } |
1345 | 1345 | } |
1346 | - echo $line_item->name() . " [ ID:{$line_item->ID()} | qty:{$line_item->quantity()} ] {$line_item->type()} : " . '$' . "{$line_item->total()}"; |
|
1347 | - if ( $breakdown ) { |
|
1346 | + echo $line_item->name()." [ ID:{$line_item->ID()} | qty:{$line_item->quantity()} ] {$line_item->type()} : ".'$'."{$line_item->total()}"; |
|
1347 | + if ($breakdown) { |
|
1348 | 1348 | echo " ( {$breakdown} )"; |
1349 | 1349 | } |
1350 | - if( $line_item->is_taxable() ){ |
|
1350 | + if ($line_item->is_taxable()) { |
|
1351 | 1351 | echo " * taxable"; |
1352 | 1352 | } |
1353 | - if( $line_item->children() ){ |
|
1354 | - foreach($line_item->children() as $child){ |
|
1353 | + if ($line_item->children()) { |
|
1354 | + foreach ($line_item->children() as $child) { |
|
1355 | 1355 | self::visualize($child, $indentation + 1); |
1356 | 1356 | } |
1357 | 1357 | } |
@@ -1392,97 +1392,97 @@ discard block |
||
1392 | 1392 | * is theirs, which can be done with |
1393 | 1393 | * `EEM_Line_Item::instance()->get_line_item_for_registration( $registration );` |
1394 | 1394 | */ |
1395 | - public static function calculate_reg_final_prices_per_line_item( EE_Line_Item $line_item, $billable_ticket_quantities = array() ) { |
|
1395 | + public static function calculate_reg_final_prices_per_line_item(EE_Line_Item $line_item, $billable_ticket_quantities = array()) { |
|
1396 | 1396 | //init running grand total if not already |
1397 | - if ( ! isset( $running_totals[ 'total' ] ) ) { |
|
1398 | - $running_totals[ 'total' ] = 0; |
|
1397 | + if ( ! isset($running_totals['total'])) { |
|
1398 | + $running_totals['total'] = 0; |
|
1399 | 1399 | } |
1400 | - if( ! isset( $running_totals[ 'taxable' ] ) ) { |
|
1401 | - $running_totals[ 'taxable' ] = array( 'total' => 0 ); |
|
1400 | + if ( ! isset($running_totals['taxable'])) { |
|
1401 | + $running_totals['taxable'] = array('total' => 0); |
|
1402 | 1402 | } |
1403 | - foreach ( $line_item->children() as $child_line_item ) { |
|
1404 | - switch ( $child_line_item->type() ) { |
|
1403 | + foreach ($line_item->children() as $child_line_item) { |
|
1404 | + switch ($child_line_item->type()) { |
|
1405 | 1405 | |
1406 | 1406 | case EEM_Line_Item::type_sub_total : |
1407 | - $running_totals_from_subtotal = EEH_Line_Item::calculate_reg_final_prices_per_line_item( $child_line_item, $billable_ticket_quantities ); |
|
1407 | + $running_totals_from_subtotal = EEH_Line_Item::calculate_reg_final_prices_per_line_item($child_line_item, $billable_ticket_quantities); |
|
1408 | 1408 | //combine arrays but preserve numeric keys |
1409 | - $running_totals = array_replace_recursive( $running_totals_from_subtotal, $running_totals ); |
|
1410 | - $running_totals[ 'total' ] += $running_totals_from_subtotal[ 'total' ]; |
|
1411 | - $running_totals[ 'taxable'][ 'total' ] += $running_totals_from_subtotal[ 'taxable' ][ 'total' ]; |
|
1409 | + $running_totals = array_replace_recursive($running_totals_from_subtotal, $running_totals); |
|
1410 | + $running_totals['total'] += $running_totals_from_subtotal['total']; |
|
1411 | + $running_totals['taxable']['total'] += $running_totals_from_subtotal['taxable']['total']; |
|
1412 | 1412 | break; |
1413 | 1413 | |
1414 | 1414 | case EEM_Line_Item::type_tax_sub_total : |
1415 | 1415 | |
1416 | 1416 | //find how much the taxes percentage is |
1417 | - if ( $child_line_item->percent() !== 0 ) { |
|
1417 | + if ($child_line_item->percent() !== 0) { |
|
1418 | 1418 | $tax_percent_decimal = $child_line_item->percent() / 100; |
1419 | 1419 | } else { |
1420 | 1420 | $tax_percent_decimal = EE_Taxes::get_total_taxes_percentage() / 100; |
1421 | 1421 | } |
1422 | 1422 | //and apply to all the taxable totals, and add to the pretax totals |
1423 | - foreach ( $running_totals as $line_item_id => $this_running_total ) { |
|
1423 | + foreach ($running_totals as $line_item_id => $this_running_total) { |
|
1424 | 1424 | //"total" and "taxable" array key is an exception |
1425 | - if ( $line_item_id === 'taxable' ) { |
|
1425 | + if ($line_item_id === 'taxable') { |
|
1426 | 1426 | continue; |
1427 | 1427 | } |
1428 | - $taxable_total = $running_totals[ 'taxable' ][ $line_item_id ]; |
|
1429 | - $running_totals[ $line_item_id ] += ( $taxable_total * $tax_percent_decimal ); |
|
1428 | + $taxable_total = $running_totals['taxable'][$line_item_id]; |
|
1429 | + $running_totals[$line_item_id] += ($taxable_total * $tax_percent_decimal); |
|
1430 | 1430 | } |
1431 | 1431 | break; |
1432 | 1432 | |
1433 | 1433 | case EEM_Line_Item::type_line_item : |
1434 | 1434 | |
1435 | 1435 | // ticket line items or ???? |
1436 | - if ( $child_line_item->OBJ_type() === 'Ticket' ) { |
|
1436 | + if ($child_line_item->OBJ_type() === 'Ticket') { |
|
1437 | 1437 | // kk it's a ticket |
1438 | - if ( isset( $running_totals[ $child_line_item->ID() ] ) ) { |
|
1438 | + if (isset($running_totals[$child_line_item->ID()])) { |
|
1439 | 1439 | //huh? that shouldn't happen. |
1440 | - $running_totals[ 'total' ] += $child_line_item->total(); |
|
1440 | + $running_totals['total'] += $child_line_item->total(); |
|
1441 | 1441 | } else { |
1442 | 1442 | //its not in our running totals yet. great. |
1443 | - if ( $child_line_item->is_taxable() ) { |
|
1443 | + if ($child_line_item->is_taxable()) { |
|
1444 | 1444 | $taxable_amount = $child_line_item->unit_price(); |
1445 | 1445 | } else { |
1446 | 1446 | $taxable_amount = 0; |
1447 | 1447 | } |
1448 | 1448 | // are we only calculating totals for some tickets? |
1449 | - if ( isset( $billable_ticket_quantities[ $child_line_item->OBJ_ID() ] ) ) { |
|
1450 | - $quantity = $billable_ticket_quantities[ $child_line_item->OBJ_ID() ]; |
|
1451 | - $running_totals[ $child_line_item->ID() ] = $quantity |
|
1449 | + if (isset($billable_ticket_quantities[$child_line_item->OBJ_ID()])) { |
|
1450 | + $quantity = $billable_ticket_quantities[$child_line_item->OBJ_ID()]; |
|
1451 | + $running_totals[$child_line_item->ID()] = $quantity |
|
1452 | 1452 | ? $child_line_item->unit_price() |
1453 | 1453 | : 0; |
1454 | - $running_totals[ 'taxable' ][ $child_line_item->ID() ] = $quantity |
|
1454 | + $running_totals['taxable'][$child_line_item->ID()] = $quantity |
|
1455 | 1455 | ? $taxable_amount |
1456 | 1456 | : 0; |
1457 | 1457 | } else { |
1458 | 1458 | $quantity = $child_line_item->quantity(); |
1459 | - $running_totals[ $child_line_item->ID() ] = $child_line_item->unit_price(); |
|
1460 | - $running_totals[ 'taxable' ][ $child_line_item->ID() ] = $taxable_amount; |
|
1459 | + $running_totals[$child_line_item->ID()] = $child_line_item->unit_price(); |
|
1460 | + $running_totals['taxable'][$child_line_item->ID()] = $taxable_amount; |
|
1461 | 1461 | } |
1462 | - $running_totals[ 'taxable' ][ 'total' ] += $taxable_amount * $quantity; |
|
1463 | - $running_totals[ 'total' ] += $child_line_item->unit_price() * $quantity; |
|
1462 | + $running_totals['taxable']['total'] += $taxable_amount * $quantity; |
|
1463 | + $running_totals['total'] += $child_line_item->unit_price() * $quantity; |
|
1464 | 1464 | } |
1465 | 1465 | } else { |
1466 | 1466 | // it's some other type of item added to the cart |
1467 | 1467 | // it should affect the running totals |
1468 | 1468 | // basically we want to convert it into a PERCENT modifier. Because |
1469 | 1469 | // more clearly affect all registration's final price equally |
1470 | - $line_items_percent_of_running_total = $running_totals[ 'total' ] > 0 |
|
1471 | - ? ( $child_line_item->total() / $running_totals[ 'total' ] ) + 1 |
|
1470 | + $line_items_percent_of_running_total = $running_totals['total'] > 0 |
|
1471 | + ? ($child_line_item->total() / $running_totals['total']) + 1 |
|
1472 | 1472 | : 1; |
1473 | - foreach ( $running_totals as $line_item_id => $this_running_total ) { |
|
1473 | + foreach ($running_totals as $line_item_id => $this_running_total) { |
|
1474 | 1474 | //the "taxable" array key is an exception |
1475 | - if ( $line_item_id === 'taxable' ) { |
|
1475 | + if ($line_item_id === 'taxable') { |
|
1476 | 1476 | continue; |
1477 | 1477 | } |
1478 | 1478 | // update the running totals |
1479 | 1479 | // yes this actually even works for the running grand total! |
1480 | - $running_totals[ $line_item_id ] = |
|
1480 | + $running_totals[$line_item_id] = |
|
1481 | 1481 | $line_items_percent_of_running_total * $this_running_total; |
1482 | 1482 | |
1483 | - if ( $child_line_item->is_taxable() ) { |
|
1484 | - $running_totals[ 'taxable' ][ $line_item_id ] = |
|
1485 | - $line_items_percent_of_running_total * $running_totals[ 'taxable' ][ $line_item_id ]; |
|
1483 | + if ($child_line_item->is_taxable()) { |
|
1484 | + $running_totals['taxable'][$line_item_id] = |
|
1485 | + $line_items_percent_of_running_total * $running_totals['taxable'][$line_item_id]; |
|
1486 | 1486 | } |
1487 | 1487 | } |
1488 | 1488 | } |
@@ -1500,16 +1500,16 @@ discard block |
||
1500 | 1500 | * @return float | null |
1501 | 1501 | * @throws \OutOfRangeException |
1502 | 1502 | */ |
1503 | - public static function calculate_final_price_for_ticket_line_item( \EE_Line_Item $total_line_item, \EE_Line_Item $ticket_line_item ) { |
|
1503 | + public static function calculate_final_price_for_ticket_line_item(\EE_Line_Item $total_line_item, \EE_Line_Item $ticket_line_item) { |
|
1504 | 1504 | static $final_prices_per_ticket_line_item = array(); |
1505 | - if ( empty( $final_prices_per_ticket_line_item ) ) { |
|
1505 | + if (empty($final_prices_per_ticket_line_item)) { |
|
1506 | 1506 | $final_prices_per_ticket_line_item = \EEH_Line_Item::calculate_reg_final_prices_per_line_item( |
1507 | 1507 | $total_line_item |
1508 | 1508 | ); |
1509 | 1509 | } |
1510 | 1510 | //ok now find this new registration's final price |
1511 | - if ( isset( $final_prices_per_ticket_line_item[ $ticket_line_item->ID() ] ) ) { |
|
1512 | - return $final_prices_per_ticket_line_item[ $ticket_line_item->ID() ]; |
|
1511 | + if (isset($final_prices_per_ticket_line_item[$ticket_line_item->ID()])) { |
|
1512 | + return $final_prices_per_ticket_line_item[$ticket_line_item->ID()]; |
|
1513 | 1513 | } |
1514 | 1514 | $message = sprintf( |
1515 | 1515 | __( |
@@ -1518,10 +1518,10 @@ discard block |
||
1518 | 1518 | ), |
1519 | 1519 | $ticket_line_item->ID() |
1520 | 1520 | ); |
1521 | - if ( WP_DEBUG ) { |
|
1522 | - throw new \OutOfRangeException( $message ); |
|
1521 | + if (WP_DEBUG) { |
|
1522 | + throw new \OutOfRangeException($message); |
|
1523 | 1523 | } else { |
1524 | - EE_Log::instance()->log( __CLASS__, __FUNCTION__, $message ); |
|
1524 | + EE_Log::instance()->log(__CLASS__, __FUNCTION__, $message); |
|
1525 | 1525 | } |
1526 | 1526 | return null; |
1527 | 1527 | } |
@@ -1537,15 +1537,15 @@ discard block |
||
1537 | 1537 | * @return \EE_Line_Item |
1538 | 1538 | * @throws \EE_Error |
1539 | 1539 | */ |
1540 | - public static function billable_line_item_tree( EE_Line_Item $line_item, $registrations ) { |
|
1541 | - $copy_li = EEH_Line_Item::billable_line_item( $line_item, $registrations ); |
|
1542 | - foreach ( $line_item->children() as $child_li ) { |
|
1543 | - $copy_li->add_child_line_item( EEH_Line_Item::billable_line_item_tree( $child_li, $registrations ) ); |
|
1540 | + public static function billable_line_item_tree(EE_Line_Item $line_item, $registrations) { |
|
1541 | + $copy_li = EEH_Line_Item::billable_line_item($line_item, $registrations); |
|
1542 | + foreach ($line_item->children() as $child_li) { |
|
1543 | + $copy_li->add_child_line_item(EEH_Line_Item::billable_line_item_tree($child_li, $registrations)); |
|
1544 | 1544 | } |
1545 | 1545 | //if this is the grand total line item, make sure the totals all add up |
1546 | 1546 | //(we could have duplicated this logic AS we copied the line items, but |
1547 | 1547 | //it seems DRYer this way) |
1548 | - if ( $copy_li->type() === EEM_Line_Item::type_total ) { |
|
1548 | + if ($copy_li->type() === EEM_Line_Item::type_total) { |
|
1549 | 1549 | $copy_li->recalculate_total_including_taxes(); |
1550 | 1550 | } |
1551 | 1551 | return $copy_li; |
@@ -1562,24 +1562,24 @@ discard block |
||
1562 | 1562 | * @throws \EE_Error |
1563 | 1563 | * @param EE_Registration[] $registrations |
1564 | 1564 | */ |
1565 | - public static function billable_line_item( EE_Line_Item $line_item, $registrations ) { |
|
1565 | + public static function billable_line_item(EE_Line_Item $line_item, $registrations) { |
|
1566 | 1566 | $new_li_fields = $line_item->model_field_array(); |
1567 | - if ( $line_item->type() === EEM_Line_Item::type_line_item && |
|
1567 | + if ($line_item->type() === EEM_Line_Item::type_line_item && |
|
1568 | 1568 | $line_item->OBJ_type() === 'Ticket' |
1569 | 1569 | ) { |
1570 | 1570 | $count = 0; |
1571 | - foreach ( $registrations as $registration ) { |
|
1572 | - if ( $line_item->OBJ_ID() === $registration->ticket_ID() && |
|
1573 | - in_array( $registration->status_ID(), EEM_Registration::reg_statuses_that_allow_payment() ) |
|
1571 | + foreach ($registrations as $registration) { |
|
1572 | + if ($line_item->OBJ_ID() === $registration->ticket_ID() && |
|
1573 | + in_array($registration->status_ID(), EEM_Registration::reg_statuses_that_allow_payment()) |
|
1574 | 1574 | ) { |
1575 | 1575 | $count++; |
1576 | 1576 | } |
1577 | 1577 | } |
1578 | - $new_li_fields[ 'LIN_quantity' ] = $count; |
|
1578 | + $new_li_fields['LIN_quantity'] = $count; |
|
1579 | 1579 | } |
1580 | 1580 | //don't set the total. We'll leave that up to the code that calculates it |
1581 | - unset( $new_li_fields[ 'LIN_ID' ], $new_li_fields[ 'LIN_parent' ], $new_li_fields[ 'LIN_total' ] ); |
|
1582 | - return EE_Line_Item::new_instance( $new_li_fields ); |
|
1581 | + unset($new_li_fields['LIN_ID'], $new_li_fields['LIN_parent'], $new_li_fields['LIN_total']); |
|
1582 | + return EE_Line_Item::new_instance($new_li_fields); |
|
1583 | 1583 | } |
1584 | 1584 | |
1585 | 1585 | |
@@ -1592,19 +1592,19 @@ discard block |
||
1592 | 1592 | * @return \EE_Line_Item|null |
1593 | 1593 | * @throws \EE_Error |
1594 | 1594 | */ |
1595 | - public static function non_empty_line_items( EE_Line_Item $line_item ) { |
|
1596 | - $copied_li = EEH_Line_Item::non_empty_line_item( $line_item ); |
|
1597 | - if ( $copied_li === null ) { |
|
1595 | + public static function non_empty_line_items(EE_Line_Item $line_item) { |
|
1596 | + $copied_li = EEH_Line_Item::non_empty_line_item($line_item); |
|
1597 | + if ($copied_li === null) { |
|
1598 | 1598 | return null; |
1599 | 1599 | } |
1600 | 1600 | //if this is an event subtotal, we want to only include it if it |
1601 | 1601 | //has a non-zero total and at least one ticket line item child |
1602 | 1602 | $ticket_children = 0; |
1603 | - foreach ( $line_item->children() as $child_li ) { |
|
1604 | - $child_li_copy = EEH_Line_Item::non_empty_line_items( $child_li ); |
|
1605 | - if ( $child_li_copy !== null ) { |
|
1606 | - $copied_li->add_child_line_item( $child_li_copy ); |
|
1607 | - if ( $child_li_copy->type() === EEM_Line_Item::type_line_item && |
|
1603 | + foreach ($line_item->children() as $child_li) { |
|
1604 | + $child_li_copy = EEH_Line_Item::non_empty_line_items($child_li); |
|
1605 | + if ($child_li_copy !== null) { |
|
1606 | + $copied_li->add_child_line_item($child_li_copy); |
|
1607 | + if ($child_li_copy->type() === EEM_Line_Item::type_line_item && |
|
1608 | 1608 | $child_li_copy->OBJ_type() === 'Ticket' |
1609 | 1609 | ) { |
1610 | 1610 | $ticket_children++; |
@@ -1634,8 +1634,8 @@ discard block |
||
1634 | 1634 | * @return EE_Line_Item |
1635 | 1635 | * @throws \EE_Error |
1636 | 1636 | */ |
1637 | - public static function non_empty_line_item( EE_Line_Item $line_item ) { |
|
1638 | - if ( $line_item->type() === EEM_Line_Item::type_line_item && |
|
1637 | + public static function non_empty_line_item(EE_Line_Item $line_item) { |
|
1638 | + if ($line_item->type() === EEM_Line_Item::type_line_item && |
|
1639 | 1639 | $line_item->OBJ_type() === 'Ticket' && |
1640 | 1640 | $line_item->quantity() === 0 |
1641 | 1641 | ) { |
@@ -1643,8 +1643,8 @@ discard block |
||
1643 | 1643 | } |
1644 | 1644 | $new_li_fields = $line_item->model_field_array(); |
1645 | 1645 | //don't set the total. We'll leave that up to the code that calculates it |
1646 | - unset( $new_li_fields[ 'LIN_ID' ], $new_li_fields[ 'LIN_parent' ] ); |
|
1647 | - return EE_Line_Item::new_instance( $new_li_fields ); |
|
1646 | + unset($new_li_fields['LIN_ID'], $new_li_fields['LIN_parent']); |
|
1647 | + return EE_Line_Item::new_instance($new_li_fields); |
|
1648 | 1648 | } |
1649 | 1649 | |
1650 | 1650 | |
@@ -1656,9 +1656,9 @@ discard block |
||
1656 | 1656 | * @return \EE_Line_Item |
1657 | 1657 | * @throws \EE_Error |
1658 | 1658 | */ |
1659 | - public static function get_items_subtotal( EE_Line_Item $total_line_item ){ |
|
1660 | - EE_Error::doing_it_wrong( 'EEH_Line_Item::get_items_subtotal()', __('Method replaced with EEH_Line_Item::get_pre_tax_subtotal()', 'event_espresso'), '4.6.0' ); |
|
1661 | - return self::get_pre_tax_subtotal( $total_line_item ); |
|
1659 | + public static function get_items_subtotal(EE_Line_Item $total_line_item) { |
|
1660 | + EE_Error::doing_it_wrong('EEH_Line_Item::get_items_subtotal()', __('Method replaced with EEH_Line_Item::get_pre_tax_subtotal()', 'event_espresso'), '4.6.0'); |
|
1661 | + return self::get_pre_tax_subtotal($total_line_item); |
|
1662 | 1662 | } |
1663 | 1663 | |
1664 | 1664 | |
@@ -1669,9 +1669,9 @@ discard block |
||
1669 | 1669 | * @return \EE_Line_Item |
1670 | 1670 | * @throws \EE_Error |
1671 | 1671 | */ |
1672 | - public static function create_default_total_line_item( $transaction = NULL) { |
|
1673 | - EE_Error::doing_it_wrong( 'EEH_Line_Item::create_default_total_line_item()', __('Method replaced with EEH_Line_Item::create_total_line_item()', 'event_espresso'), '4.6.0' ); |
|
1674 | - return self::create_total_line_item( $transaction ); |
|
1672 | + public static function create_default_total_line_item($transaction = NULL) { |
|
1673 | + EE_Error::doing_it_wrong('EEH_Line_Item::create_default_total_line_item()', __('Method replaced with EEH_Line_Item::create_total_line_item()', 'event_espresso'), '4.6.0'); |
|
1674 | + return self::create_total_line_item($transaction); |
|
1675 | 1675 | } |
1676 | 1676 | |
1677 | 1677 | |
@@ -1683,9 +1683,9 @@ discard block |
||
1683 | 1683 | * @return \EE_Line_Item |
1684 | 1684 | * @throws \EE_Error |
1685 | 1685 | */ |
1686 | - public static function create_default_tickets_subtotal( EE_Line_Item $total_line_item, $transaction = NULL) { |
|
1687 | - EE_Error::doing_it_wrong( 'EEH_Line_Item::create_default_tickets_subtotal()', __('Method replaced with EEH_Line_Item::create_pre_tax_subtotal()', 'event_espresso'), '4.6.0' ); |
|
1688 | - return self::create_pre_tax_subtotal( $total_line_item, $transaction ); |
|
1686 | + public static function create_default_tickets_subtotal(EE_Line_Item $total_line_item, $transaction = NULL) { |
|
1687 | + EE_Error::doing_it_wrong('EEH_Line_Item::create_default_tickets_subtotal()', __('Method replaced with EEH_Line_Item::create_pre_tax_subtotal()', 'event_espresso'), '4.6.0'); |
|
1688 | + return self::create_pre_tax_subtotal($total_line_item, $transaction); |
|
1689 | 1689 | } |
1690 | 1690 | |
1691 | 1691 | |
@@ -1697,9 +1697,9 @@ discard block |
||
1697 | 1697 | * @return \EE_Line_Item |
1698 | 1698 | * @throws \EE_Error |
1699 | 1699 | */ |
1700 | - public static function create_default_taxes_subtotal( EE_Line_Item $total_line_item, $transaction = NULL) { |
|
1701 | - EE_Error::doing_it_wrong( 'EEH_Line_Item::create_default_taxes_subtotal()', __('Method replaced with EEH_Line_Item::create_taxes_subtotal()', 'event_espresso'), '4.6.0' ); |
|
1702 | - return self::create_taxes_subtotal( $total_line_item, $transaction ); |
|
1700 | + public static function create_default_taxes_subtotal(EE_Line_Item $total_line_item, $transaction = NULL) { |
|
1701 | + EE_Error::doing_it_wrong('EEH_Line_Item::create_default_taxes_subtotal()', __('Method replaced with EEH_Line_Item::create_taxes_subtotal()', 'event_espresso'), '4.6.0'); |
|
1702 | + return self::create_taxes_subtotal($total_line_item, $transaction); |
|
1703 | 1703 | } |
1704 | 1704 | |
1705 | 1705 | |
@@ -1711,9 +1711,9 @@ discard block |
||
1711 | 1711 | * @return \EE_Line_Item |
1712 | 1712 | * @throws \EE_Error |
1713 | 1713 | */ |
1714 | - public static function create_default_event_subtotal( EE_Line_Item $total_line_item, $transaction = NULL) { |
|
1715 | - EE_Error::doing_it_wrong( 'EEH_Line_Item::create_default_event_subtotal()', __('Method replaced with EEH_Line_Item::create_event_subtotal()', 'event_espresso'), '4.6.0' ); |
|
1716 | - return self::create_event_subtotal( $total_line_item, $transaction ); |
|
1714 | + public static function create_default_event_subtotal(EE_Line_Item $total_line_item, $transaction = NULL) { |
|
1715 | + EE_Error::doing_it_wrong('EEH_Line_Item::create_default_event_subtotal()', __('Method replaced with EEH_Line_Item::create_event_subtotal()', 'event_espresso'), '4.6.0'); |
|
1716 | + return self::create_event_subtotal($total_line_item, $transaction); |
|
1717 | 1717 | } |
1718 | 1718 | |
1719 | 1719 |
@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php if ( ! defined('EVENT_ESPRESSO_VERSION')) exit('No direct script access allowed'); |
2 | -require_once ( EE_MODELS . 'EEM_Base.model.php' ); |
|
2 | +require_once (EE_MODELS.'EEM_Base.model.php'); |
|
3 | 3 | |
4 | 4 | /** |
5 | 5 | * |
@@ -21,60 +21,60 @@ discard block |
||
21 | 21 | * Please instead use the EEM_Attendee::system_question_* constants |
22 | 22 | * @deprecated |
23 | 23 | */ |
24 | - const fname_question_id=1; |
|
24 | + const fname_question_id = 1; |
|
25 | 25 | |
26 | 26 | /** |
27 | 27 | * @deprecated |
28 | 28 | */ |
29 | - const lname_question_id=2; |
|
29 | + const lname_question_id = 2; |
|
30 | 30 | |
31 | 31 | |
32 | 32 | /** |
33 | 33 | * @deprecated |
34 | 34 | */ |
35 | - const email_question_id=3; |
|
35 | + const email_question_id = 3; |
|
36 | 36 | |
37 | 37 | |
38 | 38 | /** |
39 | 39 | * @deprecated |
40 | 40 | */ |
41 | - const address_question_id=4; |
|
41 | + const address_question_id = 4; |
|
42 | 42 | |
43 | 43 | |
44 | 44 | /** |
45 | 45 | * @deprecated |
46 | 46 | */ |
47 | - const address2_question_id=5; |
|
47 | + const address2_question_id = 5; |
|
48 | 48 | |
49 | 49 | |
50 | 50 | /** |
51 | 51 | * @deprecated |
52 | 52 | */ |
53 | - const city_question_id=6; |
|
53 | + const city_question_id = 6; |
|
54 | 54 | |
55 | 55 | |
56 | 56 | /** |
57 | 57 | * @deprecated |
58 | 58 | */ |
59 | - const state_question_id=7; |
|
59 | + const state_question_id = 7; |
|
60 | 60 | |
61 | 61 | |
62 | 62 | /** |
63 | 63 | * @deprecated |
64 | 64 | */ |
65 | - const country_question_id=8; |
|
65 | + const country_question_id = 8; |
|
66 | 66 | |
67 | 67 | |
68 | 68 | /** |
69 | 69 | * @deprecated |
70 | 70 | */ |
71 | - const zip_question_id=9; |
|
71 | + const zip_question_id = 9; |
|
72 | 72 | |
73 | 73 | |
74 | 74 | /** |
75 | 75 | * @deprecated |
76 | 76 | */ |
77 | - const phone_question_id=10; |
|
77 | + const phone_question_id = 10; |
|
78 | 78 | |
79 | 79 | /** |
80 | 80 | * When looking for questions that correspond to attendee fields, |
@@ -119,9 +119,9 @@ discard block |
||
119 | 119 | * @access protected |
120 | 120 | * @param null $timezone |
121 | 121 | */ |
122 | - protected function __construct( $timezone = NULL ) { |
|
123 | - $this->singular_item = __('Attendee','event_espresso'); |
|
124 | - $this->plural_item = __('Attendees','event_espresso'); |
|
122 | + protected function __construct($timezone = NULL) { |
|
123 | + $this->singular_item = __('Attendee', 'event_espresso'); |
|
124 | + $this->plural_item = __('Attendees', 'event_espresso'); |
|
125 | 125 | $this->_tables = array( |
126 | 126 | 'Attendee_CPT'=> new EE_Primary_Table('posts', 'ID'), |
127 | 127 | 'Attendee_Meta'=>new EE_Secondary_Table('esp_attendee_meta', 'ATTM_ID', 'ATT_ID') |
@@ -132,40 +132,40 @@ discard block |
||
132 | 132 | 'ATT_full_name'=>new EE_Plain_Text_Field('post_title', __("Attendee Full Name", "event_espresso"), false, __("Unknown", "event_espresso")), |
133 | 133 | 'ATT_bio'=>new EE_Post_Content_Field('post_content', __("Attendee Biography", "event_espresso"), false, __("No Biography Provided", "event_espresso")), |
134 | 134 | 'ATT_slug'=>new EE_Slug_Field('post_name', __("Attendee URL Slug", "event_espresso"), false), |
135 | - 'ATT_created'=>new EE_Datetime_Field('post_date', __("Time Attendee Created", "event_espresso"), false, EE_Datetime_Field::now ), |
|
135 | + 'ATT_created'=>new EE_Datetime_Field('post_date', __("Time Attendee Created", "event_espresso"), false, EE_Datetime_Field::now), |
|
136 | 136 | 'ATT_short_bio'=>new EE_Simple_HTML_Field('post_excerpt', __("Attendee Short Biography", "event_espresso"), true, __("No Biography Provided", "event_espresso")), |
137 | - 'ATT_modified'=>new EE_Datetime_Field('post_modified', __("Time Attendee Last Modified", "event_espresso"), FALSE, EE_Datetime_Field::now ), |
|
138 | - 'ATT_author'=>new EE_WP_User_Field('post_author', __("Creator ID of the first Event attended", "event_espresso"), false ), |
|
137 | + 'ATT_modified'=>new EE_Datetime_Field('post_modified', __("Time Attendee Last Modified", "event_espresso"), FALSE, EE_Datetime_Field::now), |
|
138 | + 'ATT_author'=>new EE_WP_User_Field('post_author', __("Creator ID of the first Event attended", "event_espresso"), false), |
|
139 | 139 | 'ATT_parent'=>new EE_DB_Only_Int_Field('post_parent', __("Parent Attendee (unused)", "event_espresso"), false, 0), |
140 | - 'post_type'=>new EE_WP_Post_Type_Field('espresso_attendees'),// EE_DB_Only_Text_Field('post_type', __("Post Type of Attendee", "event_espresso"), false,'espresso_attendees'), |
|
140 | + 'post_type'=>new EE_WP_Post_Type_Field('espresso_attendees'), // EE_DB_Only_Text_Field('post_type', __("Post Type of Attendee", "event_espresso"), false,'espresso_attendees'), |
|
141 | 141 | 'status' => new EE_WP_Post_Status_Field('post_status', __('Attendee Status', 'event_espresso'), false, 'publish') |
142 | 142 | ), |
143 | 143 | 'Attendee_Meta'=>array( |
144 | - 'ATTM_ID'=> new EE_DB_Only_Int_Field('ATTM_ID', __('Attendee Meta Row ID','event_espresso'), false), |
|
144 | + 'ATTM_ID'=> new EE_DB_Only_Int_Field('ATTM_ID', __('Attendee Meta Row ID', 'event_espresso'), false), |
|
145 | 145 | 'ATT_ID_fk'=>new EE_DB_Only_Int_Field('ATT_ID', __("Foreign Key to Attendee in Post Table", "event_espresso"), false), |
146 | - 'ATT_fname'=>new EE_Plain_Text_Field('ATT_fname', __('First Name','event_espresso'), true, ''), |
|
147 | - 'ATT_lname'=>new EE_Plain_Text_Field('ATT_lname', __('Last Name','event_espresso'), true, ''), |
|
148 | - 'ATT_address'=>new EE_Plain_Text_Field('ATT_address', __('Address Part 1','event_espresso'), true, ''), |
|
149 | - 'ATT_address2'=>new EE_Plain_Text_Field('ATT_address2', __('Address Part 2','event_espresso'), true, ''), |
|
150 | - 'ATT_city'=>new EE_Plain_Text_Field('ATT_city', __('City','event_espresso'), true, ''), |
|
151 | - 'STA_ID'=>new EE_Foreign_Key_Int_Field('STA_ID', __('State','event_espresso'), true,0,'State'), |
|
152 | - 'CNT_ISO'=>new EE_Foreign_Key_String_Field('CNT_ISO', __('Country','event_espresso'), true,'','Country'), |
|
153 | - 'ATT_zip'=>new EE_Plain_Text_Field('ATT_zip', __('ZIP/Postal Code','event_espresso'), true, ''), |
|
154 | - 'ATT_email'=>new EE_Email_Field('ATT_email', __('Email Address','event_espresso'), true, ''), |
|
155 | - 'ATT_phone'=>new EE_Plain_Text_Field('ATT_phone', __('Phone','event_espresso'), true, '') |
|
146 | + 'ATT_fname'=>new EE_Plain_Text_Field('ATT_fname', __('First Name', 'event_espresso'), true, ''), |
|
147 | + 'ATT_lname'=>new EE_Plain_Text_Field('ATT_lname', __('Last Name', 'event_espresso'), true, ''), |
|
148 | + 'ATT_address'=>new EE_Plain_Text_Field('ATT_address', __('Address Part 1', 'event_espresso'), true, ''), |
|
149 | + 'ATT_address2'=>new EE_Plain_Text_Field('ATT_address2', __('Address Part 2', 'event_espresso'), true, ''), |
|
150 | + 'ATT_city'=>new EE_Plain_Text_Field('ATT_city', __('City', 'event_espresso'), true, ''), |
|
151 | + 'STA_ID'=>new EE_Foreign_Key_Int_Field('STA_ID', __('State', 'event_espresso'), true, 0, 'State'), |
|
152 | + 'CNT_ISO'=>new EE_Foreign_Key_String_Field('CNT_ISO', __('Country', 'event_espresso'), true, '', 'Country'), |
|
153 | + 'ATT_zip'=>new EE_Plain_Text_Field('ATT_zip', __('ZIP/Postal Code', 'event_espresso'), true, ''), |
|
154 | + 'ATT_email'=>new EE_Email_Field('ATT_email', __('Email Address', 'event_espresso'), true, ''), |
|
155 | + 'ATT_phone'=>new EE_Plain_Text_Field('ATT_phone', __('Phone', 'event_espresso'), true, '') |
|
156 | 156 | )); |
157 | 157 | $this->_model_relations = array( |
158 | 158 | 'Registration'=>new EE_Has_Many_Relation(), |
159 | 159 | 'State'=>new EE_Belongs_To_Relation(), |
160 | 160 | 'Country'=>new EE_Belongs_To_Relation(), |
161 | - 'Event'=>new EE_HABTM_Relation('Registration', FALSE ), |
|
161 | + 'Event'=>new EE_HABTM_Relation('Registration', FALSE), |
|
162 | 162 | 'WP_User' => new EE_Belongs_To_Relation(), |
163 | - 'Message' => new EE_Has_Many_Any_Relation( false ), //allow deletion of attendees even if they have messages in the queue for them. |
|
163 | + 'Message' => new EE_Has_Many_Any_Relation(false), //allow deletion of attendees even if they have messages in the queue for them. |
|
164 | 164 | 'Term_Relationship' => new EE_Has_Many_Relation(), |
165 | 165 | 'Term_Taxonomy'=>new EE_HABTM_Relation('Term_Relationship'), |
166 | 166 | ); |
167 | 167 | $this->_caps_slug = 'contacts'; |
168 | - parent::__construct( $timezone ); |
|
168 | + parent::__construct($timezone); |
|
169 | 169 | |
170 | 170 | } |
171 | 171 | |
@@ -175,8 +175,8 @@ discard block |
||
175 | 175 | * @param string $system_question_string |
176 | 176 | * @return string|null if not found |
177 | 177 | */ |
178 | - public function get_attendee_field_for_system_question( $system_question_string ) { |
|
179 | - return isset( $this->_system_question_to_attendee_field_name[ $system_question_string ] ) ? $this->_system_question_to_attendee_field_name[ $system_question_string ] : null; |
|
178 | + public function get_attendee_field_for_system_question($system_question_string) { |
|
179 | + return isset($this->_system_question_to_attendee_field_name[$system_question_string]) ? $this->_system_question_to_attendee_field_name[$system_question_string] : null; |
|
180 | 180 | } |
181 | 181 | |
182 | 182 | |
@@ -187,8 +187,8 @@ discard block |
||
187 | 187 | * @param EE_Transaction/int $transaction_id_or_obj EE_Transaction or its ID |
188 | 188 | * @return EE_Attendee[] |
189 | 189 | */ |
190 | - public function get_attendees_for_transaction( $transaction_id_or_obj ){ |
|
191 | - return $this->get_all( array( array( |
|
190 | + public function get_attendees_for_transaction($transaction_id_or_obj) { |
|
191 | + return $this->get_all(array(array( |
|
192 | 192 | 'Registration.Transaction.TXN_ID' => $transaction_id_or_obj instanceof EE_Transaction ? $transaction_id_or_obj->ID() : $transaction_id_or_obj |
193 | 193 | ))); |
194 | 194 | } |
@@ -203,9 +203,9 @@ discard block |
||
203 | 203 | * @return mixed array on success, FALSE on fail |
204 | 204 | * @deprecated |
205 | 205 | */ |
206 | - public function get_attendee_by_ID( $ATT_ID = FALSE ) { |
|
206 | + public function get_attendee_by_ID($ATT_ID = FALSE) { |
|
207 | 207 | // retrieve a particular EE_Attendee |
208 | - return $this->get_one_by_ID( $ATT_ID ); |
|
208 | + return $this->get_one_by_ID($ATT_ID); |
|
209 | 209 | } |
210 | 210 | |
211 | 211 | |
@@ -218,14 +218,14 @@ discard block |
||
218 | 218 | * @param array $where_cols_n_values |
219 | 219 | * @return mixed array on success, FALSE on fail |
220 | 220 | */ |
221 | - public function get_attendee( $where_cols_n_values = array() ) { |
|
221 | + public function get_attendee($where_cols_n_values = array()) { |
|
222 | 222 | |
223 | - if ( empty( $where_cols_n_values )) { |
|
223 | + if (empty($where_cols_n_values)) { |
|
224 | 224 | return FALSE; |
225 | 225 | } |
226 | - $attendee = $this->get_all( array($where_cols_n_values )); |
|
227 | - if ( ! empty( $attendee )) { |
|
228 | - return array_shift( $attendee ); |
|
226 | + $attendee = $this->get_all(array($where_cols_n_values)); |
|
227 | + if ( ! empty($attendee)) { |
|
228 | + return array_shift($attendee); |
|
229 | 229 | } else { |
230 | 230 | return FALSE; |
231 | 231 | } |
@@ -241,20 +241,20 @@ discard block |
||
241 | 241 | * @param array $where_cols_n_values |
242 | 242 | * @return bool|mixed |
243 | 243 | */ |
244 | - public function find_existing_attendee( $where_cols_n_values = NULL ) { |
|
244 | + public function find_existing_attendee($where_cols_n_values = NULL) { |
|
245 | 245 | // search by combo of first and last names plus the email address |
246 | - $attendee_data_keys = array( 'ATT_fname' => $this->_ATT_fname, 'ATT_lname' => $this->_ATT_lname, 'ATT_email' => $this->_ATT_email ); |
|
246 | + $attendee_data_keys = array('ATT_fname' => $this->_ATT_fname, 'ATT_lname' => $this->_ATT_lname, 'ATT_email' => $this->_ATT_email); |
|
247 | 247 | // no search params means attendee object already exists. |
248 | - $where_cols_n_values = is_array( $where_cols_n_values ) && ! empty( $where_cols_n_values ) ? $where_cols_n_values : $attendee_data_keys; |
|
248 | + $where_cols_n_values = is_array($where_cols_n_values) && ! empty($where_cols_n_values) ? $where_cols_n_values : $attendee_data_keys; |
|
249 | 249 | $valid_data = TRUE; |
250 | 250 | // check for required values |
251 | - $valid_data = isset( $where_cols_n_values['ATT_fname'] ) && ! empty( $where_cols_n_values['ATT_fname'] ) ? $valid_data : FALSE; |
|
252 | - $valid_data = isset( $where_cols_n_values['ATT_lname'] ) && ! empty( $where_cols_n_values['ATT_lname'] ) ? $valid_data : FALSE; |
|
253 | - $valid_data = isset( $where_cols_n_values['ATT_email'] ) && ! empty( $where_cols_n_values['ATT_email'] ) ? $valid_data : FALSE; |
|
251 | + $valid_data = isset($where_cols_n_values['ATT_fname']) && ! empty($where_cols_n_values['ATT_fname']) ? $valid_data : FALSE; |
|
252 | + $valid_data = isset($where_cols_n_values['ATT_lname']) && ! empty($where_cols_n_values['ATT_lname']) ? $valid_data : FALSE; |
|
253 | + $valid_data = isset($where_cols_n_values['ATT_email']) && ! empty($where_cols_n_values['ATT_email']) ? $valid_data : FALSE; |
|
254 | 254 | |
255 | - if ( $valid_data ) { |
|
256 | - $attendee = $this->get_attendee( $where_cols_n_values ); |
|
257 | - if ( $attendee instanceof EE_Attendee ) { |
|
255 | + if ($valid_data) { |
|
256 | + $attendee = $this->get_attendee($where_cols_n_values); |
|
257 | + if ($attendee instanceof EE_Attendee) { |
|
258 | 258 | return $attendee; |
259 | 259 | } |
260 | 260 | } |
@@ -272,12 +272,12 @@ discard block |
||
272 | 272 | * @param array $ids array of EE_Registration ids |
273 | 273 | * @return EE_Attendee[] |
274 | 274 | */ |
275 | - public function get_array_of_contacts_from_reg_ids( $ids ) { |
|
275 | + public function get_array_of_contacts_from_reg_ids($ids) { |
|
276 | 276 | $ids = (array) $ids; |
277 | 277 | $_where = array( |
278 | - 'Registration.REG_ID' => array( 'in', $ids ) |
|
278 | + 'Registration.REG_ID' => array('in', $ids) |
|
279 | 279 | ); |
280 | - return $this->get_all( array( $_where ) ); |
|
280 | + return $this->get_all(array($_where)); |
|
281 | 281 | } |
282 | 282 | |
283 | 283 |
@@ -36,53 +36,53 @@ discard block |
||
36 | 36 | <h2 id="invoice-hdr"><?php _e('Order Confirmation', 'event_espresso')?></h2> |
37 | 37 | <h3 id="invoice-date"><?php _e('Date:', 'event_espresso')?> <span class="plain-text">[registration_date]</span></h3> |
38 | 38 | <h3 id="invoice-txn-id"><?php _e('Transaction ID:', 'event_espresso')?> <span class="plain-text">[transaction_id]</span></h3> |
39 | - <h3 id="invoice-txn-status"><?php _e('Status:', 'event_espresso')?> <span class="<?php echo $transaction->status_ID()?> plain-text"><?php echo $transaction->pretty_status();?></span></h3> |
|
39 | + <h3 id="invoice-txn-status"><?php _e('Status:', 'event_espresso')?> <span class="<?php echo $transaction->status_ID()?> plain-text"><?php echo $transaction->pretty_status(); ?></span></h3> |
|
40 | 40 | </div> |
41 | 41 | </td> |
42 | 42 | </tr> |
43 | 43 | </table> |
44 | 44 | <div class="events"> |
45 | - <?php foreach($events_for_txn as $event_id => $event){ |
|
46 | - ?><h3 class="section-title event-name"><img class="icon" src="<?php echo EE_IMAGES_URL.'calendar_year-24x24.png';?>"><?php _e("Event Name:","event_espresso")?> <span class="plain-text"><?php echo $event->name();?></span> <span class="small-text link">[ <a href='<?php echo $event->get_permalink()?>'><?php _e('view', 'event_espresso'); ?></a> ]</span></h3> |
|
47 | - <?php if (strlen($event->description()>1)){?><p class="event-description"><?php $event->description()?></p><?php }?> |
|
45 | + <?php foreach ($events_for_txn as $event_id => $event) { |
|
46 | + ?><h3 class="section-title event-name"><img class="icon" src="<?php echo EE_IMAGES_URL.'calendar_year-24x24.png'; ?>"><?php _e("Event Name:", "event_espresso")?> <span class="plain-text"><?php echo $event->name(); ?></span> <span class="small-text link">[ <a href='<?php echo $event->get_permalink()?>'><?php _e('view', 'event_espresso'); ?></a> ]</span></h3> |
|
47 | + <?php if (strlen($event->description() > 1)) {?><p class="event-description"><?php $event->description()?></p><?php }?> |
|
48 | 48 | <ul class="tickets-per-event"> |
49 | - <?php foreach($ticket_line_items_per_event[$event_id] as $line_item_id => $line_item){ |
|
49 | + <?php foreach ($ticket_line_items_per_event[$event_id] as $line_item_id => $line_item) { |
|
50 | 50 | $ticket = $line_item->ticket(); |
51 | - $taxable_html = $ticket->taxable() ? '*': ''; |
|
51 | + $taxable_html = $ticket->taxable() ? '*' : ''; |
|
52 | 52 | $subitems = $line_item->children(); |
53 | - $ticket_uses = $ticket->get_pretty('TKT_uses', __("any", "event_espresso")); |
|
53 | + $ticket_uses = $ticket->get_pretty('TKT_uses', __("any", "event_espresso")); |
|
54 | 54 | ?> |
55 | 55 | <li class="event-ticket"> |
56 | 56 | <div class="ticket-details"> |
57 | 57 | <table class="invoice-amount"> |
58 | 58 | <thead> |
59 | 59 | <tr class="header_row"> |
60 | - <th class="name-column"><?php _e("Ticket", "event_espresso");?></th> |
|
61 | - <th colspan="2" class="desc-column"><?php _e("Description", "event_espresso");?></th> |
|
62 | - <th class="number-column item_c"><?php _e("Quantity", "event_espresso");?></th> |
|
63 | - <th class="number-column item_c"><?php _e("Price", "event_espresso");?></th> |
|
64 | - <th class="number-column item_r"><?php _e("Total", "event_espresso");?></th> |
|
60 | + <th class="name-column"><?php _e("Ticket", "event_espresso"); ?></th> |
|
61 | + <th colspan="2" class="desc-column"><?php _e("Description", "event_espresso"); ?></th> |
|
62 | + <th class="number-column item_c"><?php _e("Quantity", "event_espresso"); ?></th> |
|
63 | + <th class="number-column item_c"><?php _e("Price", "event_espresso"); ?></th> |
|
64 | + <th class="number-column item_r"><?php _e("Total", "event_espresso"); ?></th> |
|
65 | 65 | </tr> |
66 | 66 | </thead> |
67 | 67 | <tbody> |
68 | - <?php if( count($subitems) < 2){?> |
|
68 | + <?php if (count($subitems) < 2) {?> |
|
69 | 69 | <tr class="item"> |
70 | 70 | <td><?php echo $line_item->name().$taxable_html?></td> |
71 | - <td colspan="2"><?php echo $line_item->desc();?><p class="ticket-note"><?php echo sprintf(__('This ticket can be used once at %s of the dates/times below.', 'event_espresso'), $ticket_uses); ?></p></td> |
|
71 | + <td colspan="2"><?php echo $line_item->desc(); ?><p class="ticket-note"><?php echo sprintf(__('This ticket can be used once at %s of the dates/times below.', 'event_espresso'), $ticket_uses); ?></p></td> |
|
72 | 72 | <td class="item_c"><?php echo $line_item->quantity()?></td> |
73 | 73 | <td class="item_c"><?php echo $line_item->unit_price_no_code()?></td> |
74 | 74 | <td class="item_r"><?php echo $line_item->total_no_code()?></td> |
75 | 75 | </tr> |
76 | - <?php }else{?> |
|
76 | + <?php } else {?> |
|
77 | 77 | <tr class="item"> |
78 | 78 | <td class="aln-left"><?php echo $line_item->name().$taxable_html?></td> |
79 | - <td colspan="2"><?php echo $line_item->desc();?><p class="ticket-note"><?php echo sprintf(__('This ticket can be used once at %s of the dates/times below.', 'event_espresso'), $ticket_uses); ?></p></td> |
|
79 | + <td colspan="2"><?php echo $line_item->desc(); ?><p class="ticket-note"><?php echo sprintf(__('This ticket can be used once at %s of the dates/times below.', 'event_espresso'), $ticket_uses); ?></p></td> |
|
80 | 80 | <td class="item_c"><?php echo $line_item->quantity()?></td> |
81 | 81 | <td class="item_c"><?php echo $line_item->unit_price_no_code()?></td> |
82 | 82 | <td class="item_r"><?php echo $line_item->total_no_code()?></td> |
83 | 83 | </tr> |
84 | - <?php foreach($subitems as $sub_line_item){ |
|
85 | - $is_percent = $sub_line_item->is_percent();?> |
|
84 | + <?php foreach ($subitems as $sub_line_item) { |
|
85 | + $is_percent = $sub_line_item->is_percent(); ?> |
|
86 | 86 | <tr class="subitem-row"> |
87 | 87 | <td class="subitem"><?php echo $sub_line_item->name()?></td> |
88 | 88 | <td colspan="2"><?php echo $sub_line_item->desc()?></td> |
@@ -93,7 +93,7 @@ discard block |
||
93 | 93 | <?php } ?> |
94 | 94 | <tr class="total_tr odd"> |
95 | 95 | <td colspan="4"></td> |
96 | - <td class="total" nowrap="nowrap"><?php _e("Ticket Total:", "event_espresso");?></td> |
|
96 | + <td class="total" nowrap="nowrap"><?php _e("Ticket Total:", "event_espresso"); ?></td> |
|
97 | 97 | <td class="item_r"><?php echo $line_item->total_no_code()?></td> |
98 | 98 | </tr> |
99 | 99 | <?php }?> |
@@ -104,22 +104,22 @@ discard block |
||
104 | 104 | <div class="reg-details-for-ticket"> |
105 | 105 | <div class="ticket-time-and-place-details"> |
106 | 106 | <div class="ticket-time-details"> |
107 | - <h4 class="sub-section-title no-bottom-margin"><img class="icon" src="<?php echo EE_IMAGES_URL.'clock-16x16.png';?>"><?php echo _n("Date/Time:","Dates/Times:",count($ticket->datetimes()), "event_espresso");?></h4> |
|
107 | + <h4 class="sub-section-title no-bottom-margin"><img class="icon" src="<?php echo EE_IMAGES_URL.'clock-16x16.png'; ?>"><?php echo _n("Date/Time:", "Dates/Times:", count($ticket->datetimes()), "event_espresso"); ?></h4> |
|
108 | 108 | <ul class="event-dates"> |
109 | - <?php foreach($ticket->datetimes_ordered() as $datetime){ |
|
109 | + <?php foreach ($ticket->datetimes_ordered() as $datetime) { |
|
110 | 110 | /* @var $datetime EE_Datetime */ ?> |
111 | 111 | <li><?php |
112 | - echo $datetime->name() ? '<b>'.$datetime->name().' </b>' : '' ; |
|
113 | - echo sprintf(__("%s - %s (%s)", "event_espresso"),$datetime->start_date_and_time(),$datetime->end_date_and_time(),$datetime->get_timezone()); |
|
112 | + echo $datetime->name() ? '<b>'.$datetime->name().' </b>' : ''; |
|
113 | + echo sprintf(__("%s - %s (%s)", "event_espresso"), $datetime->start_date_and_time(), $datetime->end_date_and_time(), $datetime->get_timezone()); |
|
114 | 114 | echo $datetime->description() ? '<p class="ticket-note">'.$datetime->description().'</p>' : '' ?></li> |
115 | 115 | <?php }?> |
116 | 116 | </ul> |
117 | 117 | </div> |
118 | - <?php if ($event->venues()){?> |
|
118 | + <?php if ($event->venues()) {?> |
|
119 | 119 | <div class="ticket-place-details"> |
120 | - <h4 class="sub-section-title no-bottom-margin"><img class="icon" src="<?php echo EE_IMAGES_URL.'location-pin-16x16.png';?>"><?php echo _n("Venue:","Venues:",count($event->venues()), "event_espresso");?></h4> |
|
120 | + <h4 class="sub-section-title no-bottom-margin"><img class="icon" src="<?php echo EE_IMAGES_URL.'location-pin-16x16.png'; ?>"><?php echo _n("Venue:", "Venues:", count($event->venues()), "event_espresso"); ?></h4> |
|
121 | 121 | <ul class="event-venues"> |
122 | - <?php foreach($event->venues() as $venue){?> |
|
122 | + <?php foreach ($event->venues() as $venue) {?> |
|
123 | 123 | <li><?php echo $venue->name()?> <span class="small-text">[ <a href='<?php echo $venue->get_permalink()?>'><?php _e('view', 'event_espresso'); ?></a> ]</span></li> |
124 | 124 | <?php } ?> |
125 | 125 | </ul> |
@@ -127,34 +127,34 @@ discard block |
||
127 | 127 | <?php }?> |
128 | 128 | </div> |
129 | 129 | <div class="ticket-registrations-area"> |
130 | - <h4 class="sub-section-title"><img class="icon" src="<?php echo EE_IMAGES_URL.'users-16x16.png';?>"><?php echo __("Registration Details", "event_espresso");?> <span class="small-text link">[ <a class="print_button noPrint" href="<?php echo $edit_reg_info_url; ?>"><?php _e('edit', 'event_espresso'); ?></a> ]</span></h4> |
|
130 | + <h4 class="sub-section-title"><img class="icon" src="<?php echo EE_IMAGES_URL.'users-16x16.png'; ?>"><?php echo __("Registration Details", "event_espresso"); ?> <span class="small-text link">[ <a class="print_button noPrint" href="<?php echo $edit_reg_info_url; ?>"><?php _e('edit', 'event_espresso'); ?></a> ]</span></h4> |
|
131 | 131 | <ul class="ticket-registrations-list"> |
132 | - <?php foreach($registrations_per_line_item[$line_item_id] as $registration){ |
|
132 | + <?php foreach ($registrations_per_line_item[$line_item_id] as $registration) { |
|
133 | 133 | /* @var $registration EE_Registration */ |
134 | 134 | $attendee = $registration->attendee(); |
135 | - $answers = $registration->answers(array('order_by'=>array('Question.Question_Group_Question.QGQ_order'=>'ASC')));?> |
|
135 | + $answers = $registration->answers(array('order_by'=>array('Question.Question_Group_Question.QGQ_order'=>'ASC'))); ?> |
|
136 | 136 | <li class="ticket-registration"> |
137 | 137 | <table class="registration-details"> |
138 | 138 | <tr class="odd"> |
139 | - <th><?php echo _e("Registration Code:", "event_espresso");?></th> |
|
140 | - <td><?php echo $registration->reg_code();?> - <span class="<?php echo $registration->status_ID()?>"><?php echo $registration->pretty_status()?></span></td> |
|
139 | + <th><?php echo _e("Registration Code:", "event_espresso"); ?></th> |
|
140 | + <td><?php echo $registration->reg_code(); ?> - <span class="<?php echo $registration->status_ID()?>"><?php echo $registration->pretty_status()?></span></td> |
|
141 | 141 | </tr> |
142 | 142 | <?php |
143 | - foreach($event->question_groups() as $question_group){ |
|
144 | - ?><tr><th><?php $question_group->e('QSG_name');?></th><td></td></tr><?php |
|
143 | + foreach ($event->question_groups() as $question_group) { |
|
144 | + ?><tr><th><?php $question_group->e('QSG_name'); ?></th><td></td></tr><?php |
|
145 | 145 | $has_personal_info = false; |
146 | - foreach($question_group->questions() as $question){ |
|
147 | - if( in_array($question->system_ID(),$questions_to_skip)){ |
|
146 | + foreach ($question_group->questions() as $question) { |
|
147 | + if (in_array($question->system_ID(), $questions_to_skip)) { |
|
148 | 148 | $has_personal_info = true; |
149 | 149 | continue; |
150 | 150 | } |
151 | 151 | ?><tr> |
152 | 152 | <th><?php echo $question->display_text()?></th> |
153 | - <td><?php echo $registration->answer_value_to_question($question);?></td> |
|
153 | + <td><?php echo $registration->answer_value_to_question($question); ?></td> |
|
154 | 154 | </tr><?php |
155 | 155 | } |
156 | - if($has_personal_info){ |
|
157 | - ?><tr><th><?php _e('Attendee', 'event_espresso');?></th><td><?php echo sprintf(__('%s (%s)', "event_espresso"),$attendee->full_name(),$attendee->email())?></td></tr><?php |
|
156 | + if ($has_personal_info) { |
|
157 | + ?><tr><th><?php _e('Attendee', 'event_espresso'); ?></th><td><?php echo sprintf(__('%s (%s)', "event_espresso"), $attendee->full_name(), $attendee->email())?></td></tr><?php |
|
158 | 158 | } |
159 | 159 | } |
160 | 160 | ?> |
@@ -171,21 +171,21 @@ discard block |
||
171 | 171 | <?php }?> |
172 | 172 | </div> |
173 | 173 | <div class="taxes"> |
174 | - <?php if ($tax_total_line_item && $tax_total_line_item->children()){?> |
|
175 | - <h3 class="section-title"><?php _e("Taxes",'event_espresso')?></h3> |
|
174 | + <?php if ($tax_total_line_item && $tax_total_line_item->children()) {?> |
|
175 | + <h3 class="section-title"><?php _e("Taxes", 'event_espresso')?></h3> |
|
176 | 176 | <table class="invoice-amount"> |
177 | 177 | |
178 | 178 | <thead> |
179 | 179 | <tr class="header_row"> |
180 | - <th class="left ticket_th"><?php _e("Tax Name", "event_espresso");?></th> |
|
181 | - <th class="left"><?php _e('Description', 'event_espresso');?></th> |
|
180 | + <th class="left ticket_th"><?php _e("Tax Name", "event_espresso"); ?></th> |
|
181 | + <th class="left"><?php _e('Description', 'event_espresso'); ?></th> |
|
182 | 182 | <th class="event_th item_c"><?php _e('Rate', 'event_espresso'); ?></th> |
183 | 183 | <th class="subtotal_th"><?php _e('Tax Amount', 'event_espresso'); ?></th> |
184 | 184 | </tr> |
185 | 185 | </thead> |
186 | 186 | <tbody> |
187 | 187 | <?php |
188 | - foreach($tax_total_line_item->children() as $child_tax){?> |
|
188 | + foreach ($tax_total_line_item->children() as $child_tax) {?> |
|
189 | 189 | <tr> |
190 | 190 | <td><?php echo $child_tax->name()?></td> |
191 | 191 | <td><?php echo $child_tax->desc()?></td> |
@@ -195,26 +195,26 @@ discard block |
||
195 | 195 | <?php } ?> |
196 | 196 | <tr class="total_tr odd"> |
197 | 197 | <td class="total_tr" colspan="2"></td> |
198 | - <td class="total"><?php _e("Tax Total:", "event_espresso");?></td> |
|
198 | + <td class="total"><?php _e("Tax Total:", "event_espresso"); ?></td> |
|
199 | 199 | <td class="item_r"><?php echo $tax_total_line_item->total_no_code()?></td> |
200 | 200 | </tr> |
201 | 201 | </tbody> |
202 | 202 | |
203 | 203 | </table> |
204 | 204 | <?php }?> |
205 | - <p><?php _e("* taxable items", "event_espresso");?></p> |
|
205 | + <p><?php _e("* taxable items", "event_espresso"); ?></p> |
|
206 | 206 | </div> |
207 | 207 | <div class="grand-total-dv"> |
208 | - <h2 class="grand-total"><?php printf(__("Grand Total: %s", "event_espresso"),EEH_Template::format_currency($total_cost));?></h2> |
|
208 | + <h2 class="grand-total"><?php printf(__("Grand Total: %s", "event_espresso"), EEH_Template::format_currency($total_cost)); ?></h2> |
|
209 | 209 | </div> |
210 | 210 | <div class="payment-dv"> |
211 | - <h3 class="section-title"><?php _e("Payments",'event_espresso')?></h3> |
|
211 | + <h3 class="section-title"><?php _e("Payments", 'event_espresso')?></h3> |
|
212 | 212 | <p>[instructions]</p> |
213 | 213 | <table class="invoice-amount"> |
214 | 214 | <thead> |
215 | 215 | <tr class="header_row"> |
216 | 216 | <th><span class=""><?php _e('Payment Method', 'event_espresso'); ?></span></th> |
217 | - <th class='left datetime_th'><?php _e("Date",'event_espresso')?></th> |
|
217 | + <th class='left datetime_th'><?php _e("Date", 'event_espresso')?></th> |
|
218 | 218 | <th><span class=""><?php _e('Transaction Id / Cheque #', 'event_espresso'); ?></span></th> |
219 | 219 | <th><span class=""><?php _e('P.O. / S.O.#', 'event_espresso'); ?></span></th> |
220 | 220 | <th><span class=""><?php _e('Status', 'event_espresso'); ?></span></th> |
@@ -224,11 +224,11 @@ discard block |
||
224 | 224 | <tbody> |
225 | 225 | <?php |
226 | 226 | $c = false; |
227 | - if(!empty($payments)){ |
|
227 | + if ( ! empty($payments)) { |
|
228 | 228 | |
229 | - foreach($payments as $payment){ |
|
229 | + foreach ($payments as $payment) { |
|
230 | 230 | /* @var $payment EE_Payment */?> |
231 | - <tr class='item <?php echo (($c = !$c) ? ' odd' : '')?>'> |
|
231 | + <tr class='item <?php echo (($c = ! $c) ? ' odd' : '')?>'> |
|
232 | 232 | <td><?php $payment->e('PAY_gateway')?></td> |
233 | 233 | <td><?php echo $payment->timestamp()?></td> |
234 | 234 | <td><?php $payment->e('PAY_txn_id_chq_nmbr')?></td> |
@@ -237,17 +237,17 @@ discard block |
||
237 | 237 | <td class='item_r'><?php echo $payment->amount_no_code()?></td> |
238 | 238 | </tr> |
239 | 239 | <?php } |
240 | - }else{?> |
|
240 | + } else {?> |
|
241 | 241 | <tr class='item'> |
242 | - <td class='aln-cntr' colspan="6"><?php _e("No approved payments have been received.",'event_espresso')?> </td> |
|
242 | + <td class='aln-cntr' colspan="6"><?php _e("No approved payments have been received.", 'event_espresso')?> </td> |
|
243 | 243 | </tr> |
244 | 244 | <?php } |
245 | - ?><tr class="item" ><td class='aln-cntr' colspan="6"><?php if($amount_owed){?><a class="noPrint" href='<?php echo $retry_payment_url?>'><?php _e("Please make a payment.", "event_espresso");}?></a></td></tr> |
|
245 | + ?><tr class="item" ><td class='aln-cntr' colspan="6"><?php if ($amount_owed) {?><a class="noPrint" href='<?php echo $retry_payment_url?>'><?php _e("Please make a payment.", "event_espresso"); }?></a></td></tr> |
|
246 | 246 | </tbody> |
247 | 247 | <tfoot> |
248 | 248 | <tr class='total_tr'><td colspan="4"> </td> |
249 | - <td class="item_r"><?php _e('Total Paid','event_espresso')?></td> |
|
250 | - <td class="item_r"><?php echo EEH_Template::format_currency($amount_pd,false,false)?> </td> |
|
249 | + <td class="item_r"><?php _e('Total Paid', 'event_espresso')?></td> |
|
250 | + <td class="item_r"><?php echo EEH_Template::format_currency($amount_pd, false, false)?> </td> |
|
251 | 251 | </tr> |
252 | 252 | <?php //echo $discount; ?> |
253 | 253 | <tr class="total_tr odd"> |
@@ -259,20 +259,20 @@ discard block |
||
259 | 259 | </table> |
260 | 260 | </div> |
261 | 261 | <div class="additional-info-dv"> |
262 | - <h3 class="section-title"><?php _e("Additional Information:", "event_espresso");?></h3> |
|
262 | + <h3 class="section-title"><?php _e("Additional Information:", "event_espresso"); ?></h3> |
|
263 | 263 | <div class="additional-info"> |
264 | - <?php if($venues_for_events){?> |
|
265 | - <h2><?php echo _n("Venue Details:", "Venues Details:", "event_espresso",count($venues_for_events));?></h2> |
|
264 | + <?php if ($venues_for_events) {?> |
|
265 | + <h2><?php echo _n("Venue Details:", "Venues Details:", "event_espresso", count($venues_for_events)); ?></h2> |
|
266 | 266 | <table class="venue-list"> |
267 | - <?php foreach($venues_for_events as $venue){?> |
|
267 | + <?php foreach ($venues_for_events as $venue) {?> |
|
268 | 268 | <tr class="venue-details"> |
269 | 269 | <td class="venue-details-part venue-address-dv"> |
270 | 270 | <h3><a href='<?php echo $venue->get_permalink()?>'><?php |
271 | 271 | echo $venue->name() |
272 | 272 | ?></a></h3> |
273 | 273 | <p><?php echo $venue->description()?></p> |
274 | - <?php echo EEH_Address::format($venue);?></td> |
|
275 | - <?php if($venue->enable_for_gmap()){?> |
|
274 | + <?php echo EEH_Address::format($venue); ?></td> |
|
275 | + <?php if ($venue->enable_for_gmap()) {?> |
|
276 | 276 | <td class="venue-details-part venue-image-dv"><?php echo EEH_Venue_View::espresso_google_static_map($venue)?></td> |
277 | 277 | <?php } ?> |
278 | 278 | </tr> |
@@ -23,15 +23,15 @@ discard block |
||
23 | 23 | </td> |
24 | 24 | <td> |
25 | 25 | <div id="invoice-info"> |
26 | - <h2 id="invoice-hdr"><?php _e( 'Order Confirmation', 'event_espresso' ) ?></h2> |
|
26 | + <h2 id="invoice-hdr"><?php _e('Order Confirmation', 'event_espresso') ?></h2> |
|
27 | 27 | |
28 | - <h3 id="invoice-date"><?php _e( 'Date:', 'event_espresso' ) ?> |
|
28 | + <h3 id="invoice-date"><?php _e('Date:', 'event_espresso') ?> |
|
29 | 29 | <span class="plain-text">[PRIMARY_REGISTRANT_REGISTRATION_DATE]</span></h3> |
30 | 30 | |
31 | - <h3 id="invoice-txn-id"><?php _e( 'Transaction ID:', 'event_espresso' ) ?> |
|
31 | + <h3 id="invoice-txn-id"><?php _e('Transaction ID:', 'event_espresso') ?> |
|
32 | 32 | <span class="plain-text">[TXN_ID]</span></h3> |
33 | 33 | |
34 | - <h3 id="invoice-txn-status"><?php _e( 'Status:', 'event_espresso' ) ?> |
|
34 | + <h3 id="invoice-txn-status"><?php _e('Status:', 'event_espresso') ?> |
|
35 | 35 | <span class="[TXN_STATUS_ID] plain-text">[TXN_STATUS]</span></h3> |
36 | 36 | </div> |
37 | 37 | </td> |
@@ -41,15 +41,15 @@ discard block |
||
41 | 41 | [EVENT_LIST] |
42 | 42 | </div> |
43 | 43 | <div class="taxes"> |
44 | - <h3 class="section-title"><?php _e( "Additional Charges/Discounts", 'event_espresso' ) ?></h3> |
|
44 | + <h3 class="section-title"><?php _e("Additional Charges/Discounts", 'event_espresso') ?></h3> |
|
45 | 45 | <table class="invoice-amount"> |
46 | 46 | <thead> |
47 | 47 | <tr class="header_row"> |
48 | - <th class="left ticket_th"><?php _e( "Name", "event_espresso" ); ?></th> |
|
49 | - <th class="left"><?php _e( 'Description', 'event_espresso' ); ?></th> |
|
50 | - <th class="event_th item_c"><?php _e( 'Quantity', 'event_espresso' ); ?></th> |
|
51 | - <th class="event_th item_c"><?php _e( 'Unit Price', 'event_espresso' ); ?></th> |
|
52 | - <th class="subtotal_th"><?php _e( 'Total', 'event_espresso' ); ?></th> |
|
48 | + <th class="left ticket_th"><?php _e("Name", "event_espresso"); ?></th> |
|
49 | + <th class="left"><?php _e('Description', 'event_espresso'); ?></th> |
|
50 | + <th class="event_th item_c"><?php _e('Quantity', 'event_espresso'); ?></th> |
|
51 | + <th class="event_th item_c"><?php _e('Unit Price', 'event_espresso'); ?></th> |
|
52 | + <th class="subtotal_th"><?php _e('Total', 'event_espresso'); ?></th> |
|
53 | 53 | </tr> |
54 | 54 | </thead> |
55 | 55 | <tbody> |
@@ -60,15 +60,15 @@ discard block |
||
60 | 60 | </table> |
61 | 61 | </div> |
62 | 62 | <div class="taxes"> |
63 | - <h3 class="section-title"><?php _e( "Taxes", 'event_espresso' ) ?></h3> |
|
64 | - <p><?php printf( __( '%s*%s Taxable items. The total amount collected for taxes is reflected in the total(s) below.', 'event_espresso' ), '<strong>', '</strong>' ); ?></p> |
|
63 | + <h3 class="section-title"><?php _e("Taxes", 'event_espresso') ?></h3> |
|
64 | + <p><?php printf(__('%s*%s Taxable items. The total amount collected for taxes is reflected in the total(s) below.', 'event_espresso'), '<strong>', '</strong>'); ?></p> |
|
65 | 65 | <table class="invoice-amount"> |
66 | 66 | <thead> |
67 | 67 | <tr class="header_row"> |
68 | - <th class="left ticket_th"><?php _e( "Tax Name", "event_espresso" ); ?></th> |
|
69 | - <th class="left"><?php _e( 'Description', 'event_espresso' ); ?></th> |
|
70 | - <th class="event_th item_c"><?php _e( 'Rate', 'event_espresso' ); ?></th> |
|
71 | - <th class="subtotal_th"><?php _e( 'Tax Amount', 'event_espresso' ); ?></th> |
|
68 | + <th class="left ticket_th"><?php _e("Tax Name", "event_espresso"); ?></th> |
|
69 | + <th class="left"><?php _e('Description', 'event_espresso'); ?></th> |
|
70 | + <th class="event_th item_c"><?php _e('Rate', 'event_espresso'); ?></th> |
|
71 | + <th class="subtotal_th"><?php _e('Tax Amount', 'event_espresso'); ?></th> |
|
72 | 72 | </tr> |
73 | 73 | </thead> |
74 | 74 | <tbody> |
@@ -79,19 +79,19 @@ discard block |
||
79 | 79 | </table> |
80 | 80 | </div> |
81 | 81 | <div class="grand-total-dv"> |
82 | - <h2 class="grand-total"><?php printf( __( "Grand Total: %s", "event_espresso" ), '[TOTAL_COST]' ); ?></h2> |
|
82 | + <h2 class="grand-total"><?php printf(__("Grand Total: %s", "event_espresso"), '[TOTAL_COST]'); ?></h2> |
|
83 | 83 | </div> |
84 | 84 | <div class="payment-dv"> |
85 | - <h3 class="section-title"><?php _e( "Payments", 'event_espresso' ) ?></h3> |
|
85 | + <h3 class="section-title"><?php _e("Payments", 'event_espresso') ?></h3> |
|
86 | 86 | <table class="invoice-amount"> |
87 | 87 | <thead> |
88 | 88 | <tr class="header_row"> |
89 | - <th><span class=""><?php _e( 'Payment Method', 'event_espresso' ); ?></span></th> |
|
90 | - <th class='left datetime_th'><?php _e( "Date", 'event_espresso' ) ?></th> |
|
91 | - <th><span class=""><?php _e( 'Transaction Id / Cheque #', 'event_espresso' ); ?></span></th> |
|
92 | - <th><span class=""><?php _e( 'P.O. / S.O.#', 'event_espresso' ); ?></span></th> |
|
93 | - <th><span class=""><?php _e( 'Status', 'event_espresso' ); ?></span></th> |
|
94 | - <th><?php _e( 'Amount', 'event_espresso' ); ?></th> |
|
89 | + <th><span class=""><?php _e('Payment Method', 'event_espresso'); ?></span></th> |
|
90 | + <th class='left datetime_th'><?php _e("Date", 'event_espresso') ?></th> |
|
91 | + <th><span class=""><?php _e('Transaction Id / Cheque #', 'event_espresso'); ?></span></th> |
|
92 | + <th><span class=""><?php _e('P.O. / S.O.#', 'event_espresso'); ?></span></th> |
|
93 | + <th><span class=""><?php _e('Status', 'event_espresso'); ?></span></th> |
|
94 | + <th><?php _e('Amount', 'event_espresso'); ?></th> |
|
95 | 95 | </tr> |
96 | 96 | </thead> |
97 | 97 | <tbody> |
@@ -105,21 +105,21 @@ discard block |
||
105 | 105 | <tfoot> |
106 | 106 | <tr class='total_tr'> |
107 | 107 | <td colspan="4"> </td> |
108 | - <td class="item_r"><?php _e( 'Total Paid', 'event_espresso' ) ?></td> |
|
108 | + <td class="item_r"><?php _e('Total Paid', 'event_espresso') ?></td> |
|
109 | 109 | <td class="item_r">[TOTAL_AMOUNT_PAID]</td> |
110 | 110 | </tr> |
111 | 111 | <tr class="total_tr odd"> |
112 | 112 | <td colspan="4"> </td> |
113 | - <td class="total" id="total_currency"><?php _e( 'Amount Owed:', 'event_espresso' ); ?></td> |
|
113 | + <td class="total" id="total_currency"><?php _e('Amount Owed:', 'event_espresso'); ?></td> |
|
114 | 114 | <td class="total">[TOTAL_OWING]</td> |
115 | 115 | </tr> |
116 | 116 | </tfoot> |
117 | 117 | </table> |
118 | 118 | </div> |
119 | 119 | <div class="additional-info-dv"> |
120 | - <h3 class="section-title"><?php _e( "Additional Information:", "event_espresso" ); ?></h3> |
|
120 | + <h3 class="section-title"><?php _e("Additional Information:", "event_espresso"); ?></h3> |
|
121 | 121 | <div class="additional-info"> |
122 | - <h2><?php _e( "Venue Details:", "event_espresso" ); ?></h2> |
|
122 | + <h2><?php _e("Venue Details:", "event_espresso"); ?></h2> |
|
123 | 123 | <table class="venue-list"> |
124 | 124 | <tr class="venue-details"> |
125 | 125 | <td class="venue-details-part venue-address-dv"> |
@@ -1,7 +1,7 @@ discard block |
||
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 | -require_once( EE_MODELS . 'EEM_Base.model.php' ); |
|
4 | +require_once(EE_MODELS.'EEM_Base.model.php'); |
|
5 | 5 | |
6 | 6 | |
7 | 7 | |
@@ -24,18 +24,18 @@ discard block |
||
24 | 24 | * |
25 | 25 | * @param string $timezone |
26 | 26 | */ |
27 | - protected function __construct( $timezone = null ) { |
|
28 | - $this->singular_item = __( 'Term Relationship', 'event_espresso' ); |
|
29 | - $this->plural_item = __( 'Term Relationships', 'event_espresso' ); |
|
27 | + protected function __construct($timezone = null) { |
|
28 | + $this->singular_item = __('Term Relationship', 'event_espresso'); |
|
29 | + $this->plural_item = __('Term Relationships', 'event_espresso'); |
|
30 | 30 | $this->_tables = array( |
31 | - 'Term_Relationship' => new EE_Primary_Table( 'term_relationships' ), |
|
31 | + 'Term_Relationship' => new EE_Primary_Table('term_relationships'), |
|
32 | 32 | ); |
33 | - $models_this_can_attach_to = array_keys( EE_Registry::instance()->cpt_models() ); |
|
33 | + $models_this_can_attach_to = array_keys(EE_Registry::instance()->cpt_models()); |
|
34 | 34 | $this->_fields = array( |
35 | 35 | 'Term_Relationship' => array( |
36 | 36 | 'object_id' => new EE_Foreign_Key_Int_Field( |
37 | 37 | 'object_id', |
38 | - __( 'Object(Post) ID', 'event_espresso' ), |
|
38 | + __('Object(Post) ID', 'event_espresso'), |
|
39 | 39 | false, |
40 | 40 | 0, |
41 | 41 | $models_this_can_attach_to |
@@ -51,63 +51,63 @@ discard block |
||
51 | 51 | 'Term_Taxonomy' |
52 | 52 | ), |
53 | 53 | 'term_order' => new EE_Integer_Field( |
54 | - 'term_order', __( 'Term Order', 'event_espresso' ), false, 0 |
|
54 | + 'term_order', __('Term Order', 'event_espresso'), false, 0 |
|
55 | 55 | ), |
56 | 56 | ), |
57 | 57 | ); |
58 | 58 | $this->_model_relations = array( |
59 | 59 | 'Term_Taxonomy' => new EE_Belongs_To_Relation(), |
60 | 60 | ); |
61 | - foreach ( $models_this_can_attach_to as $model_name ) { |
|
62 | - $this->_model_relations[ $model_name ] = new EE_Belongs_To_Relation(); |
|
61 | + foreach ($models_this_can_attach_to as $model_name) { |
|
62 | + $this->_model_relations[$model_name] = new EE_Belongs_To_Relation(); |
|
63 | 63 | } |
64 | 64 | $this->_indexes = array( |
65 | - 'PRIMARY' => new EE_Primary_Key_Index( array( 'object_id', 'term_taxonomy_id' ) ), |
|
65 | + 'PRIMARY' => new EE_Primary_Key_Index(array('object_id', 'term_taxonomy_id')), |
|
66 | 66 | ); |
67 | 67 | $path_to_event_model = 'Event.'; |
68 | - $this->_cap_restriction_generators[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Event_Related_Public( |
|
68 | + $this->_cap_restriction_generators[EEM_Base::caps_read] = new EE_Restriction_Generator_Event_Related_Public( |
|
69 | 69 | $path_to_event_model |
70 | 70 | ); |
71 | - $this->_cap_restriction_generators[ EEM_Base::caps_read_admin ] = new EE_Restriction_Generator_Event_Related_Protected( |
|
71 | + $this->_cap_restriction_generators[EEM_Base::caps_read_admin] = new EE_Restriction_Generator_Event_Related_Protected( |
|
72 | 72 | $path_to_event_model |
73 | 73 | ); |
74 | - $this->_cap_restriction_generators[ EEM_Base::caps_edit ] = new EE_Restriction_Generator_Event_Related_Protected( |
|
74 | + $this->_cap_restriction_generators[EEM_Base::caps_edit] = new EE_Restriction_Generator_Event_Related_Protected( |
|
75 | 75 | $path_to_event_model |
76 | 76 | ); |
77 | - $this->_cap_restriction_generators[ EEM_Base::caps_delete ] = new EE_Restriction_Generator_Event_Related_Protected( |
|
77 | + $this->_cap_restriction_generators[EEM_Base::caps_delete] = new EE_Restriction_Generator_Event_Related_Protected( |
|
78 | 78 | $path_to_event_model, EEM_Base::caps_edit |
79 | 79 | ); |
80 | 80 | $path_to_tax_model = 'Term_Taxonomy.'; |
81 | 81 | //add cap restrictions for editing term relations to the "ee_assign_*" |
82 | 82 | //and for deleting term relations too |
83 | - $cap_contexts_affected = array( EEM_Base::caps_edit, EEM_Base::caps_delete ); |
|
84 | - foreach ( $cap_contexts_affected as $cap_context_affected ) { |
|
85 | - $this->_cap_restrictions[ $cap_context_affected ]['ee_assign_event_category'] = new EE_Default_Where_Conditions( |
|
83 | + $cap_contexts_affected = array(EEM_Base::caps_edit, EEM_Base::caps_delete); |
|
84 | + foreach ($cap_contexts_affected as $cap_context_affected) { |
|
85 | + $this->_cap_restrictions[$cap_context_affected]['ee_assign_event_category'] = new EE_Default_Where_Conditions( |
|
86 | 86 | array( |
87 | - $path_to_tax_model . 'taxonomy*ee_assign_event_category' => array( |
|
87 | + $path_to_tax_model.'taxonomy*ee_assign_event_category' => array( |
|
88 | 88 | '!=', |
89 | 89 | 'espresso_event_categories', |
90 | 90 | ), |
91 | 91 | ) |
92 | 92 | ); |
93 | - $this->_cap_restrictions[ $cap_context_affected ]['ee_assign_venue_category'] = new EE_Default_Where_Conditions( |
|
93 | + $this->_cap_restrictions[$cap_context_affected]['ee_assign_venue_category'] = new EE_Default_Where_Conditions( |
|
94 | 94 | array( |
95 | - $path_to_tax_model . 'taxonomy*ee_assign_venue_category' => array( |
|
95 | + $path_to_tax_model.'taxonomy*ee_assign_venue_category' => array( |
|
96 | 96 | '!=', |
97 | 97 | 'espresso_venue_categories', |
98 | 98 | ), |
99 | 99 | ) |
100 | 100 | ); |
101 | - $this->_cap_restrictions[ $cap_context_affected ]['ee_assign_event_type'] = new EE_Default_Where_Conditions( |
|
101 | + $this->_cap_restrictions[$cap_context_affected]['ee_assign_event_type'] = new EE_Default_Where_Conditions( |
|
102 | 102 | array( |
103 | - $path_to_tax_model . 'taxonomy*ee_assign_event_type' => array( '!=', 'espresso_event_type' ), |
|
103 | + $path_to_tax_model.'taxonomy*ee_assign_event_type' => array('!=', 'espresso_event_type'), |
|
104 | 104 | ) |
105 | 105 | ); |
106 | 106 | } |
107 | - parent::__construct( $timezone ); |
|
107 | + parent::__construct($timezone); |
|
108 | 108 | add_filter( |
109 | 109 | 'FHEE__Read__create_model_query_params', |
110 | - array( 'EEM_Term_Relationship', 'rest_api_query_params' ), |
|
110 | + array('EEM_Term_Relationship', 'rest_api_query_params'), |
|
111 | 111 | 10, |
112 | 112 | 3 |
113 | 113 | ); |
@@ -122,12 +122,12 @@ discard block |
||
122 | 122 | * @global wpdb $wpdb |
123 | 123 | * @return int the number of rows affected |
124 | 124 | */ |
125 | - public function update_term_taxonomy_counts( $term_taxonomy_id = null ) { |
|
125 | + public function update_term_taxonomy_counts($term_taxonomy_id = null) { |
|
126 | 126 | //because this uses a subquery and sometimes assigning to column to be another column's |
127 | 127 | //value, we just write the SQL directly. |
128 | 128 | global $wpdb; |
129 | - if ( $term_taxonomy_id ) { |
|
130 | - $second_operand = $wpdb->prepare( '%d', $term_taxonomy_id ); |
|
129 | + if ($term_taxonomy_id) { |
|
130 | + $second_operand = $wpdb->prepare('%d', $term_taxonomy_id); |
|
131 | 131 | } else { |
132 | 132 | $second_operand = 'tr.term_taxonomy_id'; |
133 | 133 | } |
@@ -152,10 +152,10 @@ discard block |
||
152 | 152 | * @param array $field_n_values @see EEM_Base::insert |
153 | 153 | * @return boolean |
154 | 154 | */ |
155 | - public function insert( $field_n_values ) { |
|
156 | - $return = parent::insert( $field_n_values ); |
|
157 | - if ( isset( $field_n_values['term_taxonomy_id'] ) ) { |
|
158 | - $this->update_term_taxonomy_counts( $field_n_values['term_taxonomy_id'] ); |
|
155 | + public function insert($field_n_values) { |
|
156 | + $return = parent::insert($field_n_values); |
|
157 | + if (isset($field_n_values['term_taxonomy_id'])) { |
|
158 | + $this->update_term_taxonomy_counts($field_n_values['term_taxonomy_id']); |
|
159 | 159 | } |
160 | 160 | return $return; |
161 | 161 | } |
@@ -175,9 +175,9 @@ discard block |
||
175 | 175 | * could get out-of-sync with the database |
176 | 176 | * @return int |
177 | 177 | */ |
178 | - public function update( $fields_n_values, $query_params, $keep_model_objs_in_sync = true ) { |
|
179 | - $count = parent::update( $fields_n_values, $query_params, $keep_model_objs_in_sync ); |
|
180 | - if ( $count ) { |
|
178 | + public function update($fields_n_values, $query_params, $keep_model_objs_in_sync = true) { |
|
179 | + $count = parent::update($fields_n_values, $query_params, $keep_model_objs_in_sync); |
|
180 | + if ($count) { |
|
181 | 181 | $this->update_term_taxonomy_counts(); |
182 | 182 | } |
183 | 183 | return $count; |
@@ -193,9 +193,9 @@ discard block |
||
193 | 193 | * @param boolean $allow_blocking |
194 | 194 | * @return int @see EEM_Base::delete |
195 | 195 | */ |
196 | - public function delete( $query_params, $allow_blocking = true ) { |
|
197 | - $count = parent::delete( $query_params, $allow_blocking ); |
|
198 | - if ( $count ) { |
|
196 | + public function delete($query_params, $allow_blocking = true) { |
|
197 | + $count = parent::delete($query_params, $allow_blocking); |
|
198 | + if ($count) { |
|
199 | 199 | $this->update_term_taxonomy_counts(); |
200 | 200 | } |
201 | 201 | return $count; |
@@ -212,11 +212,11 @@ discard block |
||
212 | 212 | * @param EEM_Base $model |
213 | 213 | * @return array |
214 | 214 | */ |
215 | - public static function rest_api_query_params( $model_query_params, $querystring_query_params, $model ) { |
|
216 | - if ( $model === EEM_Term_Relationship::instance() ) { |
|
217 | - $taxonomies = get_taxonomies( array( 'show_in_rest' => true ) ); |
|
218 | - if ( ! empty( $taxonomies ) ) { |
|
219 | - $model_query_params[0]['Term_Taxonomy.taxonomy'] = array( 'IN', $taxonomies ); |
|
215 | + public static function rest_api_query_params($model_query_params, $querystring_query_params, $model) { |
|
216 | + if ($model === EEM_Term_Relationship::instance()) { |
|
217 | + $taxonomies = get_taxonomies(array('show_in_rest' => true)); |
|
218 | + if ( ! empty($taxonomies)) { |
|
219 | + $model_query_params[0]['Term_Taxonomy.taxonomy'] = array('IN', $taxonomies); |
|
220 | 220 | } |
221 | 221 | } |
222 | 222 | return $model_query_params; |
@@ -554,7 +554,7 @@ discard block |
||
554 | 554 | if( isset( $this->_cap_restriction_generators[ $context ] ) && |
555 | 555 | $this->_cap_restriction_generators[ $context ] instanceof EE_Restriction_Generator_Base ) { |
556 | 556 | return $this->_cap_restriction_generators[ $context ]->generate_restrictions(); |
557 | - }else{ |
|
557 | + } else{ |
|
558 | 558 | return array(); |
559 | 559 | } |
560 | 560 | } |
@@ -812,13 +812,13 @@ discard block |
||
812 | 812 | $last_model_name = end( $models_to_follow_to_wp_users ); |
813 | 813 | $model_with_fk_to_wp_users = EE_Registry::instance()->load_model( $last_model_name ); |
814 | 814 | $model_chain_to_wp_user = $this->_model_chain_to_wp_user . '.'; |
815 | - }else{ |
|
815 | + } else{ |
|
816 | 816 | $model_with_fk_to_wp_users = $this; |
817 | 817 | $model_chain_to_wp_user = ''; |
818 | 818 | } |
819 | 819 | $wp_user_field = $model_with_fk_to_wp_users->get_foreign_key_to( 'WP_User' ); |
820 | 820 | return $model_chain_to_wp_user . $wp_user_field->get_name(); |
821 | - }catch( EE_Error $e ) { |
|
821 | + } catch( EE_Error $e ) { |
|
822 | 822 | return false; |
823 | 823 | } |
824 | 824 | } |
@@ -846,11 +846,11 @@ discard block |
||
846 | 846 | public function is_owned() { |
847 | 847 | if( $this->model_chain_to_wp_user() ){ |
848 | 848 | return true; |
849 | - }else{ |
|
849 | + } else{ |
|
850 | 850 | try{ |
851 | 851 | $this->get_foreign_key_to( 'WP_User' ); |
852 | 852 | return true; |
853 | - }catch( EE_Error $e ){ |
|
853 | + } catch( EE_Error $e ){ |
|
854 | 854 | return false; |
855 | 855 | } |
856 | 856 | } |
@@ -946,7 +946,7 @@ discard block |
||
946 | 946 | $select_sql_array[] = "{$selection_and_datatype[0]} AS $alias"; |
947 | 947 | } |
948 | 948 | $columns_to_select_string = implode(", ",$select_sql_array); |
949 | - }else{ |
|
949 | + } else{ |
|
950 | 950 | $columns_to_select_string = $columns_to_select; |
951 | 951 | } |
952 | 952 | return $columns_to_select_string; |
@@ -1004,7 +1004,7 @@ discard block |
||
1004 | 1004 | $conditions_from_id = $this->parse_index_primary_key_string( $id ); |
1005 | 1005 | if( $conditions_from_id === null ) { |
1006 | 1006 | $query_params[ 0 ][ $this->primary_key_name() ] = $id ; |
1007 | - }else{ |
|
1007 | + } else{ |
|
1008 | 1008 | //no primary key, so the $id must be from the get_index_primary_key_string() |
1009 | 1009 | $query_params[0] = array_replace_recursive( $query_params[ 0 ], $this->parse_index_primary_key_string( $id ) ); |
1010 | 1010 | } |
@@ -1031,7 +1031,7 @@ discard block |
||
1031 | 1031 | $items = $this->get_all($query_params); |
1032 | 1032 | if(empty($items)){ |
1033 | 1033 | return null; |
1034 | - }else{ |
|
1034 | + } else{ |
|
1035 | 1035 | return array_shift($items); |
1036 | 1036 | } |
1037 | 1037 | } |
@@ -1417,7 +1417,7 @@ discard block |
||
1417 | 1417 | //get the model object's PK, as we'll want this if we need to insert a row into secondary tables |
1418 | 1418 | if( $this->has_primary_key_field() ){ |
1419 | 1419 | $main_table_pk_value = $wpdb_result[ $this->get_primary_key_field()->get_qualified_column() ]; |
1420 | - }else{ |
|
1420 | + } else{ |
|
1421 | 1421 | //if there's no primary key, we basically can't support having a 2nd table on the model (we could but it would be lots of work) |
1422 | 1422 | $main_table_pk_value = null; |
1423 | 1423 | } |
@@ -1456,7 +1456,7 @@ discard block |
||
1456 | 1456 | if( $keep_model_objs_in_sync && ! $this->_values_already_prepared_by_model_object ){ |
1457 | 1457 | if( $this->has_primary_key_field() ){ |
1458 | 1458 | $model_objs_affected_ids = $this->get_col( $query_params ); |
1459 | - }else{ |
|
1459 | + } else{ |
|
1460 | 1460 | //we need to select a bunch of columns and then combine them into the the "index primary key string"s |
1461 | 1461 | $models_affected_key_columns = $this->_get_all_wpdb_results($query_params, ARRAY_A ); |
1462 | 1462 | $model_objs_affected_ids = array(); |
@@ -1520,9 +1520,9 @@ discard block |
||
1520 | 1520 | |
1521 | 1521 | if( $field_to_select ){ |
1522 | 1522 | $field = $this->field_settings_for( $field_to_select ); |
1523 | - }elseif( $this->has_primary_key_field ( ) ){ |
|
1523 | + } elseif( $this->has_primary_key_field ( ) ){ |
|
1524 | 1524 | $field = $this->get_primary_key_field(); |
1525 | - }else{ |
|
1525 | + } else{ |
|
1526 | 1526 | //no primary key, just grab the first column |
1527 | 1527 | $field = reset( $this->field_settings()); |
1528 | 1528 | } |
@@ -1549,7 +1549,7 @@ discard block |
||
1549 | 1549 | $col = $this->get_col( $query_params, $field_to_select ); |
1550 | 1550 | if( ! empty( $col ) ) { |
1551 | 1551 | return reset( $col ); |
1552 | - }else{ |
|
1552 | + } else{ |
|
1553 | 1553 | return NULL; |
1554 | 1554 | } |
1555 | 1555 | } |
@@ -1676,7 +1676,7 @@ discard block |
||
1676 | 1676 | |
1677 | 1677 | // /echo "delete sql:$SQL"; |
1678 | 1678 | $rows_deleted = $this->_do_wpdb_query( 'query', array( $SQL ) ); |
1679 | - }else{ |
|
1679 | + } else{ |
|
1680 | 1680 | $rows_deleted = 0; |
1681 | 1681 | } |
1682 | 1682 | |
@@ -1720,7 +1720,7 @@ discard block |
||
1720 | 1720 | //first, if $ignore_this_model_obj was supplied, get its model |
1721 | 1721 | if($ignore_this_model_obj && $ignore_this_model_obj instanceof EE_Base_Class){ |
1722 | 1722 | $ignored_model = $ignore_this_model_obj->get_model(); |
1723 | - }else{ |
|
1723 | + } else{ |
|
1724 | 1724 | $ignored_model = null; |
1725 | 1725 | } |
1726 | 1726 | //now check all the relations of $this_model_obj_or_id and see if there |
@@ -1733,7 +1733,7 @@ discard block |
||
1733 | 1733 | if($ignored_model && $relation_name === $ignored_model->get_this_model_name()){ |
1734 | 1734 | $related_model_objects = $relation_obj->get_all_related($this_model_obj_or_id,array( |
1735 | 1735 | array($ignored_model->get_primary_key_field()->get_name() => array('!=',$ignore_this_model_obj->ID())))); |
1736 | - }else{ |
|
1736 | + } else{ |
|
1737 | 1737 | $related_model_objects = $relation_obj->get_all_related($this_model_obj_or_id); |
1738 | 1738 | } |
1739 | 1739 | |
@@ -1806,7 +1806,7 @@ discard block |
||
1806 | 1806 | } |
1807 | 1807 | |
1808 | 1808 | return !empty($query) ? implode(' AND ', $query ) : ''; |
1809 | - }elseif(count($this->get_combined_primary_key_fields()) > 1){ |
|
1809 | + } elseif(count($this->get_combined_primary_key_fields()) > 1){ |
|
1810 | 1810 | $ways_to_identify_a_row = array(); |
1811 | 1811 | $fields = $this->get_combined_primary_key_fields(); |
1812 | 1812 | //note: because there' sno primary key, that means nothing else can be pointing to this model, right? |
@@ -1822,7 +1822,7 @@ discard block |
||
1822 | 1822 | $ways_to_identify_a_row[] = "(".implode(" AND ",$values_for_each_cpk_for_a_row).")"; |
1823 | 1823 | } |
1824 | 1824 | return implode(" OR ",$ways_to_identify_a_row); |
1825 | - }else{ |
|
1825 | + } else{ |
|
1826 | 1826 | //so there's no primary key and no combined key... |
1827 | 1827 | //sorry, can't help you |
1828 | 1828 | 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))); |
@@ -1846,10 +1846,10 @@ discard block |
||
1846 | 1846 | if($field_to_count){ |
1847 | 1847 | $field_obj = $this->field_settings_for($field_to_count); |
1848 | 1848 | $column_to_count = $field_obj->get_qualified_column(); |
1849 | - }elseif($this->has_primary_key_field ()){ |
|
1849 | + } elseif($this->has_primary_key_field ()){ |
|
1850 | 1850 | $pk_field_obj = $this->get_primary_key_field(); |
1851 | 1851 | $column_to_count = $pk_field_obj->get_qualified_column(); |
1852 | - }else{ |
|
1852 | + } else{ |
|
1853 | 1853 | //there's no primary key |
1854 | 1854 | //if we're counting distinct items, and there's no primary key, |
1855 | 1855 | //we need to list out the columns for distinction; |
@@ -1887,7 +1887,7 @@ discard block |
||
1887 | 1887 | if($field_to_sum){ |
1888 | 1888 | $field_obj = $this->field_settings_for($field_to_sum); |
1889 | 1889 | |
1890 | - }else{ |
|
1890 | + } else{ |
|
1891 | 1891 | $field_obj = $this->get_primary_key_field(); |
1892 | 1892 | } |
1893 | 1893 | $column_to_count = $field_obj->get_qualified_column(); |
@@ -1897,7 +1897,7 @@ discard block |
||
1897 | 1897 | $data_type = $field_obj->get_wpdb_data_type(); |
1898 | 1898 | if( $data_type === '%d' || $data_type === '%s' ){ |
1899 | 1899 | return (float)$return_value; |
1900 | - }else{//must be %f |
|
1900 | + } else{//must be %f |
|
1901 | 1901 | return (float)$return_value; |
1902 | 1902 | } |
1903 | 1903 | } |
@@ -1935,10 +1935,10 @@ discard block |
||
1935 | 1935 | $wpdb->show_errors( $old_show_errors_value ); |
1936 | 1936 | if( ! empty( $wpdb->last_error ) ){ |
1937 | 1937 | throw new EE_Error( sprintf( __( 'WPDB Error: "%s"', 'event_espresso' ), $wpdb->last_error ) ); |
1938 | - }elseif( $result === false ){ |
|
1938 | + } elseif( $result === false ){ |
|
1939 | 1939 | 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 ) ) ); |
1940 | 1940 | } |
1941 | - }elseif( $result === false ) { |
|
1941 | + } elseif( $result === false ) { |
|
1942 | 1942 | EE_Error::add_error( |
1943 | 1943 | sprintf( |
1944 | 1944 | __( 'A database error has occurred. Turn on WP_DEBUG for more information.||A database error occurred doing wpdb method "%1$s", with arguments "%2$s". The error was "%3$s"', 'event_espresso' ), |
@@ -2280,7 +2280,7 @@ discard block |
||
2280 | 2280 | $results = $this->get_all_related($id_or_obj,$other_model_name,$query_params); |
2281 | 2281 | if( $results ){ |
2282 | 2282 | return array_shift($results); |
2283 | - }else{ |
|
2283 | + } else{ |
|
2284 | 2284 | return null; |
2285 | 2285 | } |
2286 | 2286 | |
@@ -2351,7 +2351,7 @@ discard block |
||
2351 | 2351 | */ |
2352 | 2352 | do_action( 'AHEE__EEM_Base__insert__end', $this, $field_n_values, $new_id ); |
2353 | 2353 | return $new_id; |
2354 | - }else{ |
|
2354 | + } else{ |
|
2355 | 2355 | return FALSE; |
2356 | 2356 | } |
2357 | 2357 | } |
@@ -2413,9 +2413,9 @@ discard block |
||
2413 | 2413 | public function get_one_conflicting($obj_or_fields_array, $include_primary_key = true ){ |
2414 | 2414 | if($obj_or_fields_array instanceof EE_Base_Class){ |
2415 | 2415 | $fields_n_values = $obj_or_fields_array->model_field_array(); |
2416 | - }elseif( is_array($obj_or_fields_array)){ |
|
2416 | + } elseif( is_array($obj_or_fields_array)){ |
|
2417 | 2417 | $fields_n_values = $obj_or_fields_array; |
2418 | - }else{ |
|
2418 | + } else{ |
|
2419 | 2419 | throw new EE_Error( |
2420 | 2420 | sprintf( |
2421 | 2421 | __( |
@@ -2440,7 +2440,7 @@ discard block |
||
2440 | 2440 | //if there is nothing to base this search on, then we shouldn't find anything |
2441 | 2441 | if( empty( $query_params ) ){ |
2442 | 2442 | return array(); |
2443 | - }else{ |
|
2443 | + } else{ |
|
2444 | 2444 | return $this->get_one($query_params); |
2445 | 2445 | } |
2446 | 2446 | } |
@@ -2521,12 +2521,12 @@ discard block |
||
2521 | 2521 | if($this->has_primary_key_field()){ |
2522 | 2522 | if($this->get_primary_key_field()->is_auto_increment()){ |
2523 | 2523 | return $wpdb->insert_id; |
2524 | - }else{ |
|
2524 | + } else{ |
|
2525 | 2525 | //it's not an auto-increment primary key, so |
2526 | 2526 | //it must have been supplied |
2527 | 2527 | return $fields_n_values[$this->get_primary_key_field()->get_name()]; |
2528 | 2528 | } |
2529 | - }else{ |
|
2529 | + } else{ |
|
2530 | 2530 | //we can't return a primary key because there is none. instead return |
2531 | 2531 | //a unique string indicating this model |
2532 | 2532 | return $this->get_index_primary_key_string($fields_n_values); |
@@ -2578,7 +2578,7 @@ discard block |
||
2578 | 2578 | //leave the value alone |
2579 | 2579 | } |
2580 | 2580 | return $value; |
2581 | - }else{ |
|
2581 | + } else{ |
|
2582 | 2582 | return $value; |
2583 | 2583 | } |
2584 | 2584 | } |
@@ -2747,10 +2747,10 @@ discard block |
||
2747 | 2747 | if (! is_array($possibly_array_of_params)){ |
2748 | 2748 | 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"), |
2749 | 2749 | $param,$possibly_array_of_params)); |
2750 | - }else{ |
|
2750 | + } else{ |
|
2751 | 2751 | $this->_extract_related_models_from_sub_params_array_keys($possibly_array_of_params, $model_query_info_carrier,$query_param_type); |
2752 | 2752 | } |
2753 | - }elseif($query_param_type === 0 //ie WHERE |
|
2753 | + } elseif($query_param_type === 0 //ie WHERE |
|
2754 | 2754 | && is_array($possibly_array_of_params) |
2755 | 2755 | && isset($possibly_array_of_params[2]) |
2756 | 2756 | && $possibly_array_of_params[2] == true){ |
@@ -3028,7 +3028,7 @@ discard block |
||
3028 | 3028 | private function _extract_order($should_be_order_string){ |
3029 | 3029 | if(in_array($should_be_order_string, $this->_allowed_order_values)){ |
3030 | 3030 | return $should_be_order_string; |
3031 | - }else{ |
|
3031 | + } else{ |
|
3032 | 3032 | 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)); |
3033 | 3033 | } |
3034 | 3034 | } |
@@ -3106,7 +3106,7 @@ discard block |
||
3106 | 3106 | foreach($default_where_conditions as $key => $val){ |
3107 | 3107 | if( isset($provided_where_conditions[$key])){ |
3108 | 3108 | $none_overridden = false; |
3109 | - }else{ |
|
3109 | + } else{ |
|
3110 | 3110 | $null_friendly_where_conditions[$or_condition_key_for_defaults]['AND'][$key] = $val; |
3111 | 3111 | } |
3112 | 3112 | } |
@@ -3232,7 +3232,7 @@ discard block |
||
3232 | 3232 | if(array_key_exists($query_param,$this_model_fields)){ |
3233 | 3233 | if($allow_fields){ |
3234 | 3234 | return; |
3235 | - }else{ |
|
3235 | + } else{ |
|
3236 | 3236 | 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"), |
3237 | 3237 | $query_param,get_class($this),$query_param_type,$original_query_param)); |
3238 | 3238 | } |
@@ -3241,7 +3241,7 @@ discard block |
||
3241 | 3241 | elseif(in_array($query_param, $this->_logic_query_param_keys, TRUE)){ |
3242 | 3242 | if($allow_logic_query_params){ |
3243 | 3243 | return; |
3244 | - }else{ |
|
3244 | + } else{ |
|
3245 | 3245 | throw new EE_Error( |
3246 | 3246 | sprintf( |
3247 | 3247 | __( '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' ), |
@@ -3272,12 +3272,12 @@ discard block |
||
3272 | 3272 | //we should actually end in a field name, not a model like this! |
3273 | 3273 | throw new EE_Error(sprintf(__("Query param '%s' (of type %s on model %s) shouldn't end on a period (.) ", "event_espresso"), |
3274 | 3274 | $query_param,$query_param_type,get_class($this),$valid_related_model_name)); |
3275 | - }else{ |
|
3275 | + } else{ |
|
3276 | 3276 | $related_model_obj = $this->get_related_model_obj($valid_related_model_name); |
3277 | 3277 | $related_model_obj->_extract_related_model_info_from_query_param($query_param, $passed_in_query_info, $query_param_type, $original_query_param); |
3278 | 3278 | return; |
3279 | 3279 | } |
3280 | - }elseif($query_param === $valid_related_model_name){ |
|
3280 | + } elseif($query_param === $valid_related_model_name){ |
|
3281 | 3281 | $this->_add_join_to_model($valid_related_model_name, $passed_in_query_info,$original_query_param); |
3282 | 3282 | return; |
3283 | 3283 | } |
@@ -3342,7 +3342,7 @@ discard block |
||
3342 | 3342 | $SQL = $this->_construct_condition_clause_recursive($where_params, ' AND '); |
3343 | 3343 | if($SQL){ |
3344 | 3344 | return " WHERE ". $SQL; |
3345 | - }else{ |
|
3345 | + } else{ |
|
3346 | 3346 | return ''; |
3347 | 3347 | } |
3348 | 3348 | } |
@@ -3361,7 +3361,7 @@ discard block |
||
3361 | 3361 | $SQL = $this->_construct_condition_clause_recursive($having_params, ' AND '); |
3362 | 3362 | if($SQL){ |
3363 | 3363 | return " HAVING ". $SQL; |
3364 | - }else{ |
|
3364 | + } else{ |
|
3365 | 3365 | return ''; |
3366 | 3366 | } |
3367 | 3367 | |
@@ -3383,7 +3383,7 @@ discard block |
||
3383 | 3383 | $model_instance=call_user_func($model_name."::instance"); |
3384 | 3384 | /* @var $model_instance EEM_Base */ |
3385 | 3385 | return $model_instance->field_settings_for($field_name); |
3386 | - }else{ |
|
3386 | + } else{ |
|
3387 | 3387 | throw new EE_Error(sprintf(__('No model named %s exists, with classname %s and filepath %s','event_espresso'),$model_name,$model_class,$model_filepath)); |
3388 | 3388 | } |
3389 | 3389 | } |
@@ -3416,14 +3416,14 @@ discard block |
||
3416 | 3416 | $where_clauses[] = " (". $this->_construct_condition_clause_recursive($op_and_value_or_sub_condition, ' OR ') .")"; |
3417 | 3417 | break; |
3418 | 3418 | } |
3419 | - }else{ |
|
3419 | + } else{ |
|
3420 | 3420 | $field_obj = $this->_deduce_field_from_query_param($query_param); |
3421 | 3421 | |
3422 | 3422 | //if it's not a normal field, maybe it's a custom selection? |
3423 | 3423 | if( ! $field_obj){ |
3424 | 3424 | if(isset( $this->_custom_selections[$query_param][1])){ |
3425 | 3425 | $field_obj = $this->_custom_selections[$query_param][1]; |
3426 | - }else{ |
|
3426 | + } else{ |
|
3427 | 3427 | throw new EE_Error(sprintf(__("%s is neither a valid model field name, nor a custom selection", "event_espresso"),$query_param)); |
3428 | 3428 | } |
3429 | 3429 | } |
@@ -3448,11 +3448,11 @@ discard block |
||
3448 | 3448 | if( $field ){ |
3449 | 3449 | $table_alias_prefix = EE_Model_Parser::extract_table_alias_model_relation_chain_from_query_param( $field->get_model_name(), $query_param ); |
3450 | 3450 | return $table_alias_prefix . $field->get_qualified_column(); |
3451 | - }elseif(array_key_exists($query_param,$this->_custom_selections)){ |
|
3451 | + } elseif(array_key_exists($query_param,$this->_custom_selections)){ |
|
3452 | 3452 | //maybe it's custom selection item? |
3453 | 3453 | //if so, just use it as the "column name" |
3454 | 3454 | return $query_param; |
3455 | - }else{ |
|
3455 | + } else{ |
|
3456 | 3456 | 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))); |
3457 | 3457 | } |
3458 | 3458 | } |
@@ -3469,7 +3469,7 @@ discard block |
||
3469 | 3469 | $pos_of_star = strpos($condition_query_param_key, '*'); |
3470 | 3470 | if($pos_of_star === FALSE){ |
3471 | 3471 | return $condition_query_param_key; |
3472 | - }else{ |
|
3472 | + } else{ |
|
3473 | 3473 | $condition_query_param_sans_star = substr($condition_query_param_key, 0, $pos_of_star); |
3474 | 3474 | return $condition_query_param_sans_star; |
3475 | 3475 | } |
@@ -3654,7 +3654,7 @@ discard block |
||
3654 | 3654 | global $wpdb; |
3655 | 3655 | if($field_obj instanceof EE_Model_Field_Base){ |
3656 | 3656 | return $wpdb->prepare($field_obj->get_wpdb_data_type(),$this->_prepare_value_for_use_in_db($value, $field_obj)); |
3657 | - }else{//$field_obj should really just be a data type |
|
3657 | + } else{//$field_obj should really just be a data type |
|
3658 | 3658 | if( ! in_array($field_obj,$this->_valid_wpdb_data_types)){ |
3659 | 3659 | 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))); |
3660 | 3660 | } |
@@ -3683,14 +3683,14 @@ discard block |
||
3683 | 3683 | if($number_of_parts === 1){ |
3684 | 3684 | $field_name = $last_query_param_part; |
3685 | 3685 | $model_obj = $this; |
3686 | - }else{// $number_of_parts >= 2 |
|
3686 | + } else{// $number_of_parts >= 2 |
|
3687 | 3687 | //the last part is the column name, and there are only 2parts. therefore... |
3688 | 3688 | $field_name = $last_query_param_part; |
3689 | 3689 | $model_obj = $this->get_related_model_obj( $query_param_parts[ $number_of_parts - 2 ]); |
3690 | 3690 | } |
3691 | 3691 | try{ |
3692 | 3692 | return $model_obj->field_settings_for($field_name); |
3693 | - }catch(EE_Error $e){ |
|
3693 | + } catch(EE_Error $e){ |
|
3694 | 3694 | return null; |
3695 | 3695 | } |
3696 | 3696 | } |
@@ -3709,7 +3709,7 @@ discard block |
||
3709 | 3709 | $field = isset($all_fields[$field_name]) ? $all_fields[$field_name] : FALSE; |
3710 | 3710 | if($field){ |
3711 | 3711 | return $field->get_qualified_column(); |
3712 | - }else{ |
|
3712 | + } else{ |
|
3713 | 3713 | 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))); |
3714 | 3714 | } |
3715 | 3715 | } |
@@ -3780,7 +3780,7 @@ discard block |
||
3780 | 3780 | //the FROM statement, BUT the primary table isn't. So we want |
3781 | 3781 | //to add the inverse join sql |
3782 | 3782 | $SQL .= $table_obj->get_inverse_join_sql($alias_prefixed); |
3783 | - }else{ |
|
3783 | + } else{ |
|
3784 | 3784 | //just add a regular JOIN to this table from the primary table |
3785 | 3785 | $SQL .= $table_obj->get_join_sql($alias_prefixed); |
3786 | 3786 | } |
@@ -3893,7 +3893,7 @@ discard block |
||
3893 | 3893 | $fieldSettings = $this->field_settings(true); |
3894 | 3894 | if( isset($fieldSettings[$fieldName])){ |
3895 | 3895 | return true; |
3896 | - }else{ |
|
3896 | + } else{ |
|
3897 | 3897 | return false; |
3898 | 3898 | } |
3899 | 3899 | } |
@@ -3907,7 +3907,7 @@ discard block |
||
3907 | 3907 | $relations = $this->relation_settings(); |
3908 | 3908 | if(isset($relations[$relation_name])){ |
3909 | 3909 | return true; |
3910 | - }else{ |
|
3910 | + } else{ |
|
3911 | 3911 | return false; |
3912 | 3912 | } |
3913 | 3913 | } |
@@ -3958,7 +3958,7 @@ discard block |
||
3958 | 3958 | try{ |
3959 | 3959 | $this->get_primary_key_field(); |
3960 | 3960 | $this->_has_primary_key_field = true; |
3961 | - }catch(EE_Error $e){ |
|
3961 | + } catch(EE_Error $e){ |
|
3962 | 3962 | $this->_has_primary_key_field = false; |
3963 | 3963 | } |
3964 | 3964 | } |
@@ -4038,7 +4038,7 @@ discard block |
||
4038 | 4038 | } |
4039 | 4039 | } |
4040 | 4040 | return $this->_cached_fields; |
4041 | - }else{ |
|
4041 | + } else{ |
|
4042 | 4042 | if( $this->_cached_fields_non_db_only === NULL ){ |
4043 | 4043 | $this->_cached_fields_non_db_only = array(); |
4044 | 4044 | foreach($this->_fields as $fields_corresponding_to_table){ |
@@ -4174,7 +4174,7 @@ discard block |
||
4174 | 4174 | if(empty( $this_model_fields_n_values[$this->primary_key_name()] )){ |
4175 | 4175 | return NULL; |
4176 | 4176 | } |
4177 | - }else if($this->unique_indexes()){ |
|
4177 | + } else if($this->unique_indexes()){ |
|
4178 | 4178 | $first_column = reset($this_model_fields_n_values); |
4179 | 4179 | if(empty($first_column)){ |
4180 | 4180 | return NULL; |
@@ -4189,7 +4189,7 @@ discard block |
||
4189 | 4189 | // add this new object to the entity map |
4190 | 4190 | $classInstance = $this->add_to_entity_map( $classInstance ); |
4191 | 4191 | } |
4192 | - }else{ |
|
4192 | + } else{ |
|
4193 | 4193 | $classInstance = EE_Registry::instance()->load_class( $className, array( $this_model_fields_n_values, $this->_timezone ), TRUE, FALSE ); |
4194 | 4194 | } |
4195 | 4195 | |
@@ -4302,7 +4302,7 @@ discard block |
||
4302 | 4302 | $this_model_fields_n_values[$field_name] = $field_obj->prepare_for_use_in_db( $prepared_value ); |
4303 | 4303 | } |
4304 | 4304 | } |
4305 | - }else{ |
|
4305 | + } else{ |
|
4306 | 4306 | //the table's rows existed. Use their values |
4307 | 4307 | foreach( $this->_get_fields_for_table( $table_alias ) as $field_name => $field_obj ) { |
4308 | 4308 | if( ! $field_obj->is_db_only_field() ){ |
@@ -4332,7 +4332,7 @@ discard block |
||
4332 | 4332 | //or is it a db-only field? (not relating to the model) |
4333 | 4333 | if( isset( $cols_n_values[ $qualified_column ] ) ){ |
4334 | 4334 | $value = $cols_n_values[ $qualified_column ]; |
4335 | - }elseif( isset( $cols_n_values[ $regular_column ] ) ){ |
|
4335 | + } elseif( isset( $cols_n_values[ $regular_column ] ) ){ |
|
4336 | 4336 | $value = $cols_n_values[ $regular_column ]; |
4337 | 4337 | } |
4338 | 4338 | return $value; |
@@ -4366,7 +4366,7 @@ discard block |
||
4366 | 4366 | } |
4367 | 4367 | } |
4368 | 4368 | return $obj_in_map; |
4369 | - }else{ |
|
4369 | + } else{ |
|
4370 | 4370 | return $this->get_one_by_ID( $id ); |
4371 | 4371 | } |
4372 | 4372 | } |
@@ -4401,7 +4401,7 @@ discard block |
||
4401 | 4401 | } |
4402 | 4402 | } |
4403 | 4403 | return $obj_in_map; |
4404 | - }else{ |
|
4404 | + } else{ |
|
4405 | 4405 | $this->add_to_entity_map( $replacing_model_obj ); |
4406 | 4406 | return $replacing_model_obj; |
4407 | 4407 | } |
@@ -4546,13 +4546,13 @@ discard block |
||
4546 | 4546 | if( $base_class_obj_or_id instanceof $className ){ |
4547 | 4547 | /** @var $base_class_obj_or_id EE_Base_Class */ |
4548 | 4548 | $id = $base_class_obj_or_id->ID(); |
4549 | - }elseif(is_int($base_class_obj_or_id)){ |
|
4549 | + } elseif(is_int($base_class_obj_or_id)){ |
|
4550 | 4550 | //assume it's an ID |
4551 | 4551 | $id = $base_class_obj_or_id; |
4552 | - }elseif(is_string($base_class_obj_or_id)){ |
|
4552 | + } elseif(is_string($base_class_obj_or_id)){ |
|
4553 | 4553 | //assume its a string representation of the object |
4554 | 4554 | $id = $base_class_obj_or_id; |
4555 | - }else{ |
|
4555 | + } else{ |
|
4556 | 4556 | 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))); |
4557 | 4557 | } |
4558 | 4558 | return $id; |
@@ -4700,9 +4700,9 @@ discard block |
||
4700 | 4700 | |
4701 | 4701 | if($model_object_or_attributes_array instanceof EE_Base_Class){ |
4702 | 4702 | $attributes_array = $model_object_or_attributes_array->model_field_array(); |
4703 | - }elseif(is_array($model_object_or_attributes_array)){ |
|
4703 | + } elseif(is_array($model_object_or_attributes_array)){ |
|
4704 | 4704 | $attributes_array = $model_object_or_attributes_array; |
4705 | - }else{ |
|
4705 | + } else{ |
|
4706 | 4706 | 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)); |
4707 | 4707 | } |
4708 | 4708 | //even copies obviously won't have the same ID, so remove the primary key |
@@ -4712,7 +4712,7 @@ discard block |
||
4712 | 4712 | } |
4713 | 4713 | if(isset($query_params[0])){ |
4714 | 4714 | $query_params[0] = array_merge($attributes_array,$query_params); |
4715 | - }else{ |
|
4715 | + } else{ |
|
4716 | 4716 | $query_params[0] = $attributes_array; |
4717 | 4717 | } |
4718 | 4718 | return $this->get_all($query_params); |
@@ -4737,7 +4737,7 @@ discard block |
||
4737 | 4737 | $copies = $this->get_all_copies($model_object_or_attributes_array,$query_params); |
4738 | 4738 | if(is_array($copies)){ |
4739 | 4739 | return array_shift($copies); |
4740 | - }else{ |
|
4740 | + } else{ |
|
4741 | 4741 | return null; |
4742 | 4742 | } |
4743 | 4743 | } |
@@ -4771,7 +4771,7 @@ discard block |
||
4771 | 4771 | $sql_operator = isset($this->_valid_operators[$operator_supplied]) ? $this->_valid_operators[$operator_supplied] : null; |
4772 | 4772 | if($sql_operator){ |
4773 | 4773 | return $sql_operator; |
4774 | - }else{ |
|
4774 | + } else{ |
|
4775 | 4775 | 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)))); |
4776 | 4776 | } |
4777 | 4777 | } |
@@ -4976,7 +4976,7 @@ discard block |
||
4976 | 4976 | $valid_cap_contexts = EEM_Base::valid_cap_contexts(); |
4977 | 4977 | if( in_array( $context, $valid_cap_contexts ) ) { |
4978 | 4978 | return true; |
4979 | - }else{ |
|
4979 | + } else{ |
|
4980 | 4980 | throw new EE_Error( |
4981 | 4981 | sprintf( |
4982 | 4982 | __( 'Context "%1$s" passed into model "%2$s" is not a valid context. They are: %3$s', 'event_espresso' ), |
@@ -23,7 +23,7 @@ discard block |
||
23 | 23 | * @since EE4 |
24 | 24 | * |
25 | 25 | */ |
26 | -abstract class EEM_Base extends EE_Base{ |
|
26 | +abstract class EEM_Base extends EE_Base { |
|
27 | 27 | |
28 | 28 | //admin posty |
29 | 29 | //basic -> grants access to mine -> if they don't have it, select none |
@@ -243,7 +243,7 @@ discard block |
||
243 | 243 | * Flag indicating whether this model has a primary key or not |
244 | 244 | * @var boolean |
245 | 245 | */ |
246 | - protected $_has_primary_key_field=null; |
|
246 | + protected $_has_primary_key_field = null; |
|
247 | 247 | |
248 | 248 | /** |
249 | 249 | * Whether or not this model is based off a table in WP core only (CPTs should set |
@@ -305,19 +305,19 @@ discard block |
||
305 | 305 | * operators that work like 'BETWEEN'. Typically used for datetime calculations, i.e. "BETWEEN '12-1-2011' AND '12-31-2012'" |
306 | 306 | * @var array |
307 | 307 | */ |
308 | - protected $_between_style_operators = array( 'BETWEEN' ); |
|
308 | + protected $_between_style_operators = array('BETWEEN'); |
|
309 | 309 | |
310 | 310 | /** |
311 | 311 | * operators that are used for handling NUll and !NULL queries. Typically used for when checking if a row exists on a join table. |
312 | 312 | * @var array |
313 | 313 | */ |
314 | - protected $_null_style_operators = array( 'IS NOT NULL', 'IS NULL'); |
|
314 | + protected $_null_style_operators = array('IS NOT NULL', 'IS NULL'); |
|
315 | 315 | |
316 | 316 | /** |
317 | 317 | * Allowed values for $query_params['order'] for ordering in queries |
318 | 318 | * @var array |
319 | 319 | */ |
320 | - protected $_allowed_order_values = array('asc','desc','ASC','DESC'); |
|
320 | + protected $_allowed_order_values = array('asc', 'desc', 'ASC', 'DESC'); |
|
321 | 321 | |
322 | 322 | /** |
323 | 323 | * When these are keys in a WHERE or HAVING clause, they are handled much differently |
@@ -331,13 +331,13 @@ discard block |
||
331 | 331 | * 'where', but 'where' clauses are so common that we thought we'd omit it |
332 | 332 | * @var array |
333 | 333 | */ |
334 | - private $_allowed_query_params = array(0, 'limit','order_by','group_by','having','force_join','order','on_join_limit','default_where_conditions', 'caps'); |
|
334 | + private $_allowed_query_params = array(0, 'limit', 'order_by', 'group_by', 'having', 'force_join', 'order', 'on_join_limit', 'default_where_conditions', 'caps'); |
|
335 | 335 | |
336 | 336 | /** |
337 | 337 | * All the data types that can be used in $wpdb->prepare statements. |
338 | 338 | * @var array |
339 | 339 | */ |
340 | - private $_valid_wpdb_data_types = array('%d','%s','%f'); |
|
340 | + private $_valid_wpdb_data_types = array('%d', '%s', '%f'); |
|
341 | 341 | |
342 | 342 | /** |
343 | 343 | * EE_Registry Object |
@@ -370,17 +370,17 @@ discard block |
||
370 | 370 | /** |
371 | 371 | * constant used to show EEM_Base has not yet verified the db on this http request |
372 | 372 | */ |
373 | - const db_verified_none = 0; |
|
373 | + const db_verified_none = 0; |
|
374 | 374 | /** |
375 | 375 | * constant used to show EEM_Base has verified the EE core db on this http request, |
376 | 376 | * but not the addons' dbs |
377 | 377 | */ |
378 | - const db_verified_core = 1; |
|
378 | + const db_verified_core = 1; |
|
379 | 379 | /** |
380 | 380 | * constant used to show EEM_Base has verified the addons' dbs (and implicitly |
381 | 381 | * the EE core db too) |
382 | 382 | */ |
383 | - const db_verified_addons = 2; |
|
383 | + const db_verified_addons = 2; |
|
384 | 384 | |
385 | 385 | /** |
386 | 386 | * indicates whether an EEM_Base child has already re-verified the DB |
@@ -411,13 +411,13 @@ discard block |
||
411 | 411 | * @param null $timezone |
412 | 412 | * @throws \EE_Error |
413 | 413 | */ |
414 | - protected function __construct( $timezone = NULL ){ |
|
414 | + protected function __construct($timezone = NULL) { |
|
415 | 415 | // check that the model has not been loaded too soon |
416 | - if ( ! did_action( 'AHEE__EE_System__load_espresso_addons' )) { |
|
417 | - throw new EE_Error ( |
|
416 | + if ( ! did_action('AHEE__EE_System__load_espresso_addons')) { |
|
417 | + throw new EE_Error( |
|
418 | 418 | sprintf( |
419 | - __( 'The %1$s model can not be loaded before the "AHEE__EE_System__load_espresso_addons" hook has been called. This gives other addons a chance to extend this model.', 'event_espresso' ), |
|
420 | - get_class( $this ) |
|
419 | + __('The %1$s model can not be loaded before the "AHEE__EE_System__load_espresso_addons" hook has been called. This gives other addons a chance to extend this model.', 'event_espresso'), |
|
420 | + get_class($this) |
|
421 | 421 | ) |
422 | 422 | ); |
423 | 423 | } |
@@ -425,7 +425,7 @@ discard block |
||
425 | 425 | /** |
426 | 426 | * Set blogid for models to current blog. However we ONLY do this if $_model_query_blog_id is not already set. |
427 | 427 | */ |
428 | - if ( empty( EEM_Base::$_model_query_blog_id ) ) { |
|
428 | + if (empty(EEM_Base::$_model_query_blog_id)) { |
|
429 | 429 | EEM_Base::set_model_query_blog_id(); |
430 | 430 | } |
431 | 431 | |
@@ -434,11 +434,11 @@ discard block |
||
434 | 434 | * just use EE_Register_Model_Extension |
435 | 435 | * @var EE_Table_Base[] $_tables |
436 | 436 | */ |
437 | - $this->_tables = apply_filters( 'FHEE__'.get_class($this).'__construct__tables', $this->_tables ); |
|
438 | - foreach($this->_tables as $table_alias => $table_obj){ |
|
437 | + $this->_tables = apply_filters('FHEE__'.get_class($this).'__construct__tables', $this->_tables); |
|
438 | + foreach ($this->_tables as $table_alias => $table_obj) { |
|
439 | 439 | /** @var $table_obj EE_Table_Base */ |
440 | 440 | $table_obj->_construct_finalize_with_alias($table_alias); |
441 | - if( $table_obj instanceof EE_Secondary_Table ){ |
|
441 | + if ($table_obj instanceof EE_Secondary_Table) { |
|
442 | 442 | /** @var $table_obj EE_Secondary_Table */ |
443 | 443 | $table_obj->_construct_finalize_set_table_to_join_with($this->_get_main_table()); |
444 | 444 | } |
@@ -448,54 +448,54 @@ discard block |
||
448 | 448 | * EE_Register_Model_Extension |
449 | 449 | * @param EE_Model_Field_Base[] $_fields |
450 | 450 | */ |
451 | - $this->_fields = apply_filters('FHEE__'.get_class($this).'__construct__fields',$this->_fields); |
|
451 | + $this->_fields = apply_filters('FHEE__'.get_class($this).'__construct__fields', $this->_fields); |
|
452 | 452 | $this->_invalidate_field_caches(); |
453 | - foreach($this->_fields as $table_alias => $fields_for_table){ |
|
454 | - if ( ! array_key_exists( $table_alias, $this->_tables )){ |
|
455 | - throw new EE_Error(sprintf(__("Table alias %s does not exist in EEM_Base child's _tables array. Only tables defined are %s",'event_espresso'),$table_alias,implode(",",$this->_fields))); |
|
453 | + foreach ($this->_fields as $table_alias => $fields_for_table) { |
|
454 | + if ( ! array_key_exists($table_alias, $this->_tables)) { |
|
455 | + throw new EE_Error(sprintf(__("Table alias %s does not exist in EEM_Base child's _tables array. Only tables defined are %s", 'event_espresso'), $table_alias, implode(",", $this->_fields))); |
|
456 | 456 | } |
457 | - foreach($fields_for_table as $field_name => $field_obj){ |
|
457 | + foreach ($fields_for_table as $field_name => $field_obj) { |
|
458 | 458 | /** @var $field_obj EE_Model_Field_Base | EE_Primary_Key_Field_Base */ |
459 | 459 | //primary key field base has a slightly different _construct_finalize |
460 | 460 | /** @var $field_obj EE_Model_Field_Base */ |
461 | - $field_obj->_construct_finalize( $table_alias, $field_name, $this->get_this_model_name() ); |
|
461 | + $field_obj->_construct_finalize($table_alias, $field_name, $this->get_this_model_name()); |
|
462 | 462 | } |
463 | 463 | } |
464 | 464 | |
465 | 465 | // everything is related to Extra_Meta |
466 | - if( get_class($this) !== 'EEM_Extra_Meta'){ |
|
466 | + if (get_class($this) !== 'EEM_Extra_Meta') { |
|
467 | 467 | //make extra meta related to everything, but don't block deleting things just |
468 | 468 | //because they have related extra meta info. For now just orphan those extra meta |
469 | 469 | //in the future we should automatically delete them |
470 | - $this->_model_relations['Extra_Meta'] = new EE_Has_Many_Any_Relation( FALSE ); |
|
470 | + $this->_model_relations['Extra_Meta'] = new EE_Has_Many_Any_Relation(FALSE); |
|
471 | 471 | } |
472 | 472 | //and change logs |
473 | - if( get_class( $this) !== 'EEM_Change_Log' ) { |
|
474 | - $this->_model_relations[ 'Change_Log' ] = new EE_Has_Many_Any_Relation( FALSE ); |
|
473 | + if (get_class($this) !== 'EEM_Change_Log') { |
|
474 | + $this->_model_relations['Change_Log'] = new EE_Has_Many_Any_Relation(FALSE); |
|
475 | 475 | } |
476 | 476 | /** |
477 | 477 | * Filters the list of relations on a model. It is best to NOT use this directly and instead just use |
478 | 478 | * EE_Register_Model_Extension |
479 | 479 | * @param EE_Model_Relation_Base[] $_model_relations |
480 | 480 | */ |
481 | - $this->_model_relations = apply_filters('FHEE__'.get_class($this).'__construct__model_relations',$this->_model_relations); |
|
482 | - foreach($this->_model_relations as $model_name => $relation_obj){ |
|
481 | + $this->_model_relations = apply_filters('FHEE__'.get_class($this).'__construct__model_relations', $this->_model_relations); |
|
482 | + foreach ($this->_model_relations as $model_name => $relation_obj) { |
|
483 | 483 | /** @var $relation_obj EE_Model_Relation_Base */ |
484 | 484 | $relation_obj->_construct_finalize_set_models($this->get_this_model_name(), $model_name); |
485 | 485 | } |
486 | - foreach($this->_indexes as $index_name => $index_obj){ |
|
486 | + foreach ($this->_indexes as $index_name => $index_obj) { |
|
487 | 487 | /** @var $index_obj EE_Index */ |
488 | 488 | $index_obj->_construct_finalize($index_name, $this->get_this_model_name()); |
489 | 489 | } |
490 | 490 | |
491 | 491 | $this->set_timezone($timezone); |
492 | 492 | //finalize default where condition strategy, or set default |
493 | - if( ! $this->_default_where_conditions_strategy){ |
|
493 | + if ( ! $this->_default_where_conditions_strategy) { |
|
494 | 494 | //nothing was set during child constructor, so set default |
495 | 495 | $this->_default_where_conditions_strategy = new EE_Default_Where_Conditions(); |
496 | 496 | } |
497 | 497 | $this->_default_where_conditions_strategy->_finalize_construct($this); |
498 | - if( ! $this->_minimum_where_conditions_strategy){ |
|
498 | + if ( ! $this->_minimum_where_conditions_strategy) { |
|
499 | 499 | //nothing was set during child constructor, so set default |
500 | 500 | $this->_minimum_where_conditions_strategy = new EE_Default_Where_Conditions(); |
501 | 501 | } |
@@ -503,14 +503,14 @@ discard block |
||
503 | 503 | |
504 | 504 | //if the cap slug hasn't been set, and we haven't set it to false on purpose |
505 | 505 | //to indicate to NOT set it, set it to the logical default |
506 | - if( $this->_caps_slug === null ) { |
|
507 | - $this->_caps_slug = EEH_Inflector::pluralize_and_lower( $this->get_this_model_name() ); |
|
506 | + if ($this->_caps_slug === null) { |
|
507 | + $this->_caps_slug = EEH_Inflector::pluralize_and_lower($this->get_this_model_name()); |
|
508 | 508 | } |
509 | 509 | //initialize the standard cap restriction generators if none were specified by the child constructor |
510 | - if( $this->_cap_restriction_generators !== false ){ |
|
511 | - foreach( $this->cap_contexts_to_cap_action_map() as $cap_context => $action ){ |
|
512 | - if( ! isset( $this->_cap_restriction_generators[ $cap_context ] ) ) { |
|
513 | - $this->_cap_restriction_generators[ $cap_context ] = apply_filters( |
|
510 | + if ($this->_cap_restriction_generators !== false) { |
|
511 | + foreach ($this->cap_contexts_to_cap_action_map() as $cap_context => $action) { |
|
512 | + if ( ! isset($this->_cap_restriction_generators[$cap_context])) { |
|
513 | + $this->_cap_restriction_generators[$cap_context] = apply_filters( |
|
514 | 514 | 'FHEE__EEM_Base___construct__standard_cap_restriction_generator', |
515 | 515 | new EE_Restriction_Generator_Protected(), |
516 | 516 | $cap_context, |
@@ -520,23 +520,23 @@ discard block |
||
520 | 520 | } |
521 | 521 | } |
522 | 522 | //if there are cap restriction generators, use them to make the default cap restrictions |
523 | - if( $this->_cap_restriction_generators !== false ){ |
|
524 | - foreach( $this->_cap_restriction_generators as $context => $generator_object ) { |
|
525 | - if( ! $generator_object ){ |
|
523 | + if ($this->_cap_restriction_generators !== false) { |
|
524 | + foreach ($this->_cap_restriction_generators as $context => $generator_object) { |
|
525 | + if ( ! $generator_object) { |
|
526 | 526 | continue; |
527 | 527 | } |
528 | - if( ! $generator_object instanceof EE_Restriction_Generator_Base ){ |
|
528 | + if ( ! $generator_object instanceof EE_Restriction_Generator_Base) { |
|
529 | 529 | throw new EE_Error( |
530 | 530 | sprintf( |
531 | - __( 'Index "%1$s" in the model %2$s\'s _cap_restriction_generators is not a child of EE_Restriction_Generator_Base. It should be that or NULL.', 'event_espresso' ), |
|
531 | + __('Index "%1$s" in the model %2$s\'s _cap_restriction_generators is not a child of EE_Restriction_Generator_Base. It should be that or NULL.', 'event_espresso'), |
|
532 | 532 | $context, |
533 | 533 | $this->get_this_model_name() |
534 | 534 | ) |
535 | 535 | ); |
536 | 536 | } |
537 | - $action = $this->cap_action_for_context( $context ); |
|
538 | - if( ! $generator_object->construction_finalized() ){ |
|
539 | - $generator_object->_construct_finalize( $this, $action ); |
|
537 | + $action = $this->cap_action_for_context($context); |
|
538 | + if ( ! $generator_object->construction_finalized()) { |
|
539 | + $generator_object->_construct_finalize($this, $action); |
|
540 | 540 | } |
541 | 541 | |
542 | 542 | } |
@@ -550,11 +550,11 @@ discard block |
||
550 | 550 | * @param string $context one of EEM_Base::valid_cap_contexts() |
551 | 551 | * @return EE_Default_Where_Conditions[] |
552 | 552 | */ |
553 | - protected function _generate_cap_restrictions( $context ){ |
|
554 | - if( isset( $this->_cap_restriction_generators[ $context ] ) && |
|
555 | - $this->_cap_restriction_generators[ $context ] instanceof EE_Restriction_Generator_Base ) { |
|
556 | - return $this->_cap_restriction_generators[ $context ]->generate_restrictions(); |
|
557 | - }else{ |
|
553 | + protected function _generate_cap_restrictions($context) { |
|
554 | + if (isset($this->_cap_restriction_generators[$context]) && |
|
555 | + $this->_cap_restriction_generators[$context] instanceof EE_Restriction_Generator_Base) { |
|
556 | + return $this->_cap_restriction_generators[$context]->generate_restrictions(); |
|
557 | + } else { |
|
558 | 558 | return array(); |
559 | 559 | } |
560 | 560 | } |
@@ -566,7 +566,7 @@ discard block |
||
566 | 566 | * @param int $blog_id If provided then will set the blog_id for the models to this id. If not provided then the |
567 | 567 | * value for get_current_blog_id() will be used. |
568 | 568 | */ |
569 | - public static function set_model_query_blog_id( $blog_id = 0 ) { |
|
569 | + public static function set_model_query_blog_id($blog_id = 0) { |
|
570 | 570 | EEM_Base::$_model_query_blog_id = $blog_id > 0 ? (int) $blog_id : get_current_blog_id(); |
571 | 571 | } |
572 | 572 | |
@@ -591,16 +591,16 @@ discard block |
||
591 | 591 | * @param string $timezone string representing the timezone we want to set for returned Date Time Strings (and any incoming timezone data that gets saved). Note this just sends the timezone info to the date time model field objects. Default is NULL (and will be assumed using the set timezone in the 'timezone_string' wp option) |
592 | 592 | * @return static (as in the concrete child class) |
593 | 593 | */ |
594 | - public static function instance( $timezone = NULL ){ |
|
594 | + public static function instance($timezone = NULL) { |
|
595 | 595 | |
596 | 596 | // check if instance of Espresso_model already exists |
597 | 597 | if ( ! static::$_instance instanceof static) { |
598 | 598 | // instantiate Espresso_model |
599 | - static::$_instance = new static( $timezone ); |
|
599 | + static::$_instance = new static($timezone); |
|
600 | 600 | } |
601 | 601 | |
602 | 602 | //we might have a timezone set, let set_timezone decide what to do with it |
603 | - static::$_instance->set_timezone( $timezone ); |
|
603 | + static::$_instance->set_timezone($timezone); |
|
604 | 604 | |
605 | 605 | // Espresso_model object |
606 | 606 | return static::$_instance; |
@@ -614,24 +614,24 @@ discard block |
||
614 | 614 | * @return EEM_Base|null (if the model was already instantiated, returns it, with |
615 | 615 | * all its properties reset; if it wasn't instantiated, returns null) |
616 | 616 | */ |
617 | - public static function reset( $timezone = NULL ){ |
|
618 | - if ( static::$_instance instanceof EEM_Base ) { |
|
617 | + public static function reset($timezone = NULL) { |
|
618 | + if (static::$_instance instanceof EEM_Base) { |
|
619 | 619 | //let's try to NOT swap out the current instance for a new one |
620 | 620 | //because if someone has a reference to it, we can't remove their reference |
621 | 621 | //so it's best to keep using the same reference, but change the original object |
622 | 622 | //reset all its properties to their original values as defined in the class |
623 | - $r = new ReflectionClass( get_class( static::$_instance ) ); |
|
623 | + $r = new ReflectionClass(get_class(static::$_instance)); |
|
624 | 624 | $static_properties = $r->getStaticProperties(); |
625 | - foreach( $r->getDefaultProperties() as $property => $value ) { |
|
625 | + foreach ($r->getDefaultProperties() as $property => $value) { |
|
626 | 626 | //don't set instance to null like it was originally, |
627 | 627 | //but it's static anyways, and we're ignoring static properties (for now at least) |
628 | - if( ! isset( $static_properties[ $property ] ) ) { |
|
628 | + if ( ! isset($static_properties[$property])) { |
|
629 | 629 | static::$_instance->{$property} = $value; |
630 | 630 | } |
631 | 631 | } |
632 | 632 | //and then directly call its constructor again, like we would if we |
633 | 633 | //were creating a new one |
634 | - static::$_instance->__construct( $timezone ); |
|
634 | + static::$_instance->__construct($timezone); |
|
635 | 635 | return self::instance(); |
636 | 636 | } |
637 | 637 | return null; |
@@ -646,19 +646,19 @@ discard block |
||
646 | 646 | * @return array |
647 | 647 | * @throws \EE_Error |
648 | 648 | */ |
649 | - public function status_array( $translated = FALSE ) { |
|
650 | - if ( ! array_key_exists( 'Status', $this->_model_relations ) ) { |
|
649 | + public function status_array($translated = FALSE) { |
|
650 | + if ( ! array_key_exists('Status', $this->_model_relations)) { |
|
651 | 651 | return array(); |
652 | 652 | } |
653 | 653 | $model_name = $this->get_this_model_name(); |
654 | - $status_type = str_replace( ' ', '_', strtolower( str_replace( '_', ' ', $model_name ) ) ); |
|
655 | - $stati = EEM_Status::instance()->get_all( array( array( 'STS_type' => $status_type ) ) ); |
|
654 | + $status_type = str_replace(' ', '_', strtolower(str_replace('_', ' ', $model_name))); |
|
655 | + $stati = EEM_Status::instance()->get_all(array(array('STS_type' => $status_type))); |
|
656 | 656 | $status_array = array(); |
657 | - foreach ( $stati as $status ) { |
|
658 | - $status_array[ $status->ID() ] = $status->get( 'STS_code' ); |
|
657 | + foreach ($stati as $status) { |
|
658 | + $status_array[$status->ID()] = $status->get('STS_code'); |
|
659 | 659 | } |
660 | 660 | return $translated |
661 | - ? EEM_Status::instance()->localized_status( $status_array, false, 'sentence' ) |
|
661 | + ? EEM_Status::instance()->localized_status($status_array, false, 'sentence') |
|
662 | 662 | : $status_array; |
663 | 663 | } |
664 | 664 | |
@@ -791,10 +791,10 @@ discard block |
||
791 | 791 | * )); |
792 | 792 | * @throws \EE_Error |
793 | 793 | */ |
794 | - public function get_all($query_params = array()){ |
|
795 | - if( isset( $query_params[ 'limit' ] ) |
|
796 | - && ! isset( $query_params[ 'group_by' ] ) ) { |
|
797 | - $query_params[ 'group_by' ] = array_keys( $this->get_combined_primary_key_fields() ); |
|
794 | + public function get_all($query_params = array()) { |
|
795 | + if (isset($query_params['limit']) |
|
796 | + && ! isset($query_params['group_by'])) { |
|
797 | + $query_params['group_by'] = array_keys($this->get_combined_primary_key_fields()); |
|
798 | 798 | } |
799 | 799 | return $this->_create_objects($this->_get_all_wpdb_results($query_params, ARRAY_A, NULL)); |
800 | 800 | } |
@@ -805,10 +805,10 @@ discard block |
||
805 | 805 | * @param array $query_params @see EEM_Base::get_all() |
806 | 806 | * @return array like EEM_Base::get_all |
807 | 807 | */ |
808 | - public function alter_query_params_to_only_include_mine( $query_params = array() ) { |
|
808 | + public function alter_query_params_to_only_include_mine($query_params = array()) { |
|
809 | 809 | $wp_user_field_name = $this->wp_user_field_name(); |
810 | - if( $wp_user_field_name ){ |
|
811 | - $query_params[0][ $wp_user_field_name ] = get_current_user_id(); |
|
810 | + if ($wp_user_field_name) { |
|
811 | + $query_params[0][$wp_user_field_name] = get_current_user_id(); |
|
812 | 812 | } |
813 | 813 | return $query_params; |
814 | 814 | } |
@@ -821,19 +821,19 @@ discard block |
||
821 | 821 | * foreign key to the WP_User table |
822 | 822 | */ |
823 | 823 | public function wp_user_field_name() { |
824 | - try{ |
|
825 | - if( ! empty( $this->_model_chain_to_wp_user ) ) { |
|
826 | - $models_to_follow_to_wp_users = explode( '.', $this->_model_chain_to_wp_user ); |
|
827 | - $last_model_name = end( $models_to_follow_to_wp_users ); |
|
828 | - $model_with_fk_to_wp_users = EE_Registry::instance()->load_model( $last_model_name ); |
|
829 | - $model_chain_to_wp_user = $this->_model_chain_to_wp_user . '.'; |
|
830 | - }else{ |
|
824 | + try { |
|
825 | + if ( ! empty($this->_model_chain_to_wp_user)) { |
|
826 | + $models_to_follow_to_wp_users = explode('.', $this->_model_chain_to_wp_user); |
|
827 | + $last_model_name = end($models_to_follow_to_wp_users); |
|
828 | + $model_with_fk_to_wp_users = EE_Registry::instance()->load_model($last_model_name); |
|
829 | + $model_chain_to_wp_user = $this->_model_chain_to_wp_user.'.'; |
|
830 | + } else { |
|
831 | 831 | $model_with_fk_to_wp_users = $this; |
832 | 832 | $model_chain_to_wp_user = ''; |
833 | 833 | } |
834 | - $wp_user_field = $model_with_fk_to_wp_users->get_foreign_key_to( 'WP_User' ); |
|
835 | - return $model_chain_to_wp_user . $wp_user_field->get_name(); |
|
836 | - }catch( EE_Error $e ) { |
|
834 | + $wp_user_field = $model_with_fk_to_wp_users->get_foreign_key_to('WP_User'); |
|
835 | + return $model_chain_to_wp_user.$wp_user_field->get_name(); |
|
836 | + } catch (EE_Error $e) { |
|
837 | 837 | return false; |
838 | 838 | } |
839 | 839 | } |
@@ -847,7 +847,7 @@ discard block |
||
847 | 847 | * (or transiently-related model) |
848 | 848 | * @return string |
849 | 849 | */ |
850 | - public function model_chain_to_wp_user(){ |
|
850 | + public function model_chain_to_wp_user() { |
|
851 | 851 | return $this->_model_chain_to_wp_user; |
852 | 852 | } |
853 | 853 | |
@@ -859,13 +859,13 @@ discard block |
||
859 | 859 | * @return boolean |
860 | 860 | */ |
861 | 861 | public function is_owned() { |
862 | - if( $this->model_chain_to_wp_user() ){ |
|
862 | + if ($this->model_chain_to_wp_user()) { |
|
863 | 863 | return true; |
864 | - }else{ |
|
865 | - try{ |
|
866 | - $this->get_foreign_key_to( 'WP_User' ); |
|
864 | + } else { |
|
865 | + try { |
|
866 | + $this->get_foreign_key_to('WP_User'); |
|
867 | 867 | return true; |
868 | - }catch( EE_Error $e ){ |
|
868 | + } catch (EE_Error $e) { |
|
869 | 869 | return false; |
870 | 870 | } |
871 | 871 | } |
@@ -887,17 +887,17 @@ discard block |
||
887 | 887 | * @return array | stdClass[] like results of $wpdb->get_results($sql,OBJECT), (ie, output type is OBJECT) |
888 | 888 | * @throws \EE_Error |
889 | 889 | */ |
890 | - protected function _get_all_wpdb_results($query_params = array(), $output = ARRAY_A, $columns_to_select = null){ |
|
890 | + protected function _get_all_wpdb_results($query_params = array(), $output = ARRAY_A, $columns_to_select = null) { |
|
891 | 891 | // remember the custom selections, if any, and type cast as array |
892 | 892 | // (unless $columns_to_select is an object, then just set as an empty array) |
893 | 893 | // Note: (array) 'some string' === array( 'some string' ) |
894 | - $this->_custom_selections = ! is_object( $columns_to_select ) ? (array) $columns_to_select : array(); |
|
895 | - $model_query_info = $this->_create_model_query_info_carrier( $query_params ); |
|
894 | + $this->_custom_selections = ! is_object($columns_to_select) ? (array) $columns_to_select : array(); |
|
895 | + $model_query_info = $this->_create_model_query_info_carrier($query_params); |
|
896 | 896 | $select_expressions = $columns_to_select !== null |
897 | - ? $this->_construct_select_from_input( $columns_to_select ) |
|
898 | - : $this->_construct_default_select_sql( $model_query_info ); |
|
899 | - $SQL = "SELECT $select_expressions " . $this->_construct_2nd_half_of_select_query( $model_query_info ); |
|
900 | - return $this->_do_wpdb_query( 'get_results', array( $SQL, $output ) ); |
|
897 | + ? $this->_construct_select_from_input($columns_to_select) |
|
898 | + : $this->_construct_default_select_sql($model_query_info); |
|
899 | + $SQL = "SELECT $select_expressions ".$this->_construct_2nd_half_of_select_query($model_query_info); |
|
900 | + return $this->_do_wpdb_query('get_results', array($SQL, $output)); |
|
901 | 901 | } |
902 | 902 | |
903 | 903 | /** |
@@ -915,7 +915,7 @@ discard block |
||
915 | 915 | * @return array|stdClass[] like results of $wpdb->get_results($sql,OBJECT), (ie, output type is OBJECT) |
916 | 916 | * @throws \EE_Error |
917 | 917 | */ |
918 | - public function get_all_wpdb_results($query_params = array(), $output = ARRAY_A, $columns_to_select = null){ |
|
918 | + public function get_all_wpdb_results($query_params = array(), $output = ARRAY_A, $columns_to_select = null) { |
|
919 | 919 | return $this->_get_all_wpdb_results($query_params, $output, $columns_to_select); |
920 | 920 | } |
921 | 921 | |
@@ -927,12 +927,12 @@ discard block |
||
927 | 927 | * @throws EE_Error |
928 | 928 | * @return string |
929 | 929 | */ |
930 | - private function _construct_select_from_input($columns_to_select){ |
|
931 | - if(is_array($columns_to_select)){ |
|
930 | + private function _construct_select_from_input($columns_to_select) { |
|
931 | + if (is_array($columns_to_select)) { |
|
932 | 932 | $select_sql_array = array(); |
933 | 933 | |
934 | - foreach($columns_to_select as $alias => $selection_and_datatype){ |
|
935 | - if( ! is_array($selection_and_datatype) || ! isset($selection_and_datatype[1])){ |
|
934 | + foreach ($columns_to_select as $alias => $selection_and_datatype) { |
|
935 | + if ( ! is_array($selection_and_datatype) || ! isset($selection_and_datatype[1])) { |
|
936 | 936 | throw new EE_Error( |
937 | 937 | sprintf( |
938 | 938 | __( |
@@ -944,24 +944,24 @@ discard block |
||
944 | 944 | ) |
945 | 945 | ); |
946 | 946 | } |
947 | - if( ! in_array( $selection_and_datatype[1],$this->_valid_wpdb_data_types)){ |
|
947 | + if ( ! in_array($selection_and_datatype[1], $this->_valid_wpdb_data_types)) { |
|
948 | 948 | throw new EE_Error( |
949 | 949 | sprintf( |
950 | 950 | __( |
951 | 951 | "Datatype %s (for selection '%s' and alias '%s') is not a valid wpdb datatype (eg %%s)", |
952 | 952 | "event_espresso" |
953 | 953 | ), |
954 | - $selection_and_datatype[ 1 ], |
|
955 | - $selection_and_datatype[ 0 ], |
|
954 | + $selection_and_datatype[1], |
|
955 | + $selection_and_datatype[0], |
|
956 | 956 | $alias, |
957 | - implode( ",", $this->_valid_wpdb_data_types ) |
|
957 | + implode(",", $this->_valid_wpdb_data_types) |
|
958 | 958 | ) |
959 | 959 | ); |
960 | 960 | } |
961 | 961 | $select_sql_array[] = "{$selection_and_datatype[0]} AS $alias"; |
962 | 962 | } |
963 | - $columns_to_select_string = implode(", ",$select_sql_array); |
|
964 | - }else{ |
|
963 | + $columns_to_select_string = implode(", ", $select_sql_array); |
|
964 | + } else { |
|
965 | 965 | $columns_to_select_string = $columns_to_select; |
966 | 966 | } |
967 | 967 | return $columns_to_select_string; |
@@ -976,7 +976,7 @@ discard block |
||
976 | 976 | * @return string |
977 | 977 | * @throws \EE_Error |
978 | 978 | */ |
979 | - public function primary_key_name(){ |
|
979 | + public function primary_key_name() { |
|
980 | 980 | return $this->get_primary_key_field()->get_name(); |
981 | 981 | } |
982 | 982 | |
@@ -988,14 +988,14 @@ discard block |
||
988 | 988 | * @param mixed $id int or string, depending on the type of the model's primary key |
989 | 989 | * @return EE_Base_Class |
990 | 990 | */ |
991 | - public function get_one_by_ID($id){ |
|
992 | - if( $this->get_from_entity_map( $id ) ){ |
|
993 | - return $this->get_from_entity_map( $id ); |
|
991 | + public function get_one_by_ID($id) { |
|
992 | + if ($this->get_from_entity_map($id)) { |
|
993 | + return $this->get_from_entity_map($id); |
|
994 | 994 | } |
995 | 995 | return $this->get_one( |
996 | 996 | $this->alter_query_params_to_restrict_by_ID( |
997 | 997 | $id, |
998 | - array( 'default_where_conditions' => 'minimum' ) |
|
998 | + array('default_where_conditions' => 'minimum') |
|
999 | 999 | ) |
1000 | 1000 | ); |
1001 | 1001 | } |
@@ -1012,16 +1012,16 @@ discard block |
||
1012 | 1012 | * @return array of normal query params, @see EEM_Base::get_all |
1013 | 1013 | * @throws \EE_Error |
1014 | 1014 | */ |
1015 | - public function alter_query_params_to_restrict_by_ID( $id, $query_params = array() ) { |
|
1016 | - if( ! isset( $query_params[ 0 ] ) ) { |
|
1017 | - $query_params[ 0 ] = array(); |
|
1015 | + public function alter_query_params_to_restrict_by_ID($id, $query_params = array()) { |
|
1016 | + if ( ! isset($query_params[0])) { |
|
1017 | + $query_params[0] = array(); |
|
1018 | 1018 | } |
1019 | - $conditions_from_id = $this->parse_index_primary_key_string( $id ); |
|
1020 | - if( $conditions_from_id === null ) { |
|
1021 | - $query_params[ 0 ][ $this->primary_key_name() ] = $id ; |
|
1022 | - }else{ |
|
1019 | + $conditions_from_id = $this->parse_index_primary_key_string($id); |
|
1020 | + if ($conditions_from_id === null) { |
|
1021 | + $query_params[0][$this->primary_key_name()] = $id; |
|
1022 | + } else { |
|
1023 | 1023 | //no primary key, so the $id must be from the get_index_primary_key_string() |
1024 | - $query_params[0] = array_replace_recursive( $query_params[ 0 ], $this->parse_index_primary_key_string( $id ) ); |
|
1024 | + $query_params[0] = array_replace_recursive($query_params[0], $this->parse_index_primary_key_string($id)); |
|
1025 | 1025 | } |
1026 | 1026 | return $query_params; |
1027 | 1027 | } |
@@ -1037,16 +1037,16 @@ discard block |
||
1037 | 1037 | * @return EE_Base_Class|EE_Soft_Delete_Base_Class|NULL |
1038 | 1038 | * @throws \EE_Error |
1039 | 1039 | */ |
1040 | - public function get_one($query_params = array()){ |
|
1041 | - if( ! is_array( $query_params ) ){ |
|
1042 | - 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' ); |
|
1040 | + public function get_one($query_params = array()) { |
|
1041 | + if ( ! is_array($query_params)) { |
|
1042 | + 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'); |
|
1043 | 1043 | $query_params = array(); |
1044 | 1044 | } |
1045 | 1045 | $query_params['limit'] = 1; |
1046 | 1046 | $items = $this->get_all($query_params); |
1047 | - if(empty($items)){ |
|
1047 | + if (empty($items)) { |
|
1048 | 1048 | return null; |
1049 | - }else{ |
|
1049 | + } else { |
|
1050 | 1050 | return array_shift($items); |
1051 | 1051 | } |
1052 | 1052 | } |
@@ -1069,8 +1069,8 @@ discard block |
||
1069 | 1069 | * @return EE_Base_Class[]|array |
1070 | 1070 | * @throws \EE_Error |
1071 | 1071 | */ |
1072 | - public function next_x( $current_field_value, $field_to_order_by = null, $limit = 1, $query_params = array(), $columns_to_select = null ) { |
|
1073 | - return $this->_get_consecutive( $current_field_value, '>', $field_to_order_by, $limit, $query_params, $columns_to_select ); |
|
1072 | + public function next_x($current_field_value, $field_to_order_by = null, $limit = 1, $query_params = array(), $columns_to_select = null) { |
|
1073 | + return $this->_get_consecutive($current_field_value, '>', $field_to_order_by, $limit, $query_params, $columns_to_select); |
|
1074 | 1074 | } |
1075 | 1075 | |
1076 | 1076 | |
@@ -1091,8 +1091,8 @@ discard block |
||
1091 | 1091 | * @return EE_Base_Class[]|array |
1092 | 1092 | * @throws \EE_Error |
1093 | 1093 | */ |
1094 | - public function previous_x( $current_field_value, $field_to_order_by = null, $limit = 1, $query_params = array(), $columns_to_select = null ) { |
|
1095 | - return $this->_get_consecutive( $current_field_value, '<', $field_to_order_by, $limit, $query_params, $columns_to_select ); |
|
1094 | + public function previous_x($current_field_value, $field_to_order_by = null, $limit = 1, $query_params = array(), $columns_to_select = null) { |
|
1095 | + return $this->_get_consecutive($current_field_value, '<', $field_to_order_by, $limit, $query_params, $columns_to_select); |
|
1096 | 1096 | } |
1097 | 1097 | |
1098 | 1098 | |
@@ -1113,9 +1113,9 @@ discard block |
||
1113 | 1113 | * @return EE_Base_Class|null|array() |
1114 | 1114 | * @throws \EE_Error |
1115 | 1115 | */ |
1116 | - public function next( $current_field_value, $field_to_order_by = null, $query_params = array(), $columns_to_select = null ) { |
|
1117 | - $results = $this->_get_consecutive( $current_field_value, '>', $field_to_order_by, 1, $query_params, $columns_to_select ); |
|
1118 | - return empty( $results ) ? null : reset( $results ); |
|
1116 | + public function next($current_field_value, $field_to_order_by = null, $query_params = array(), $columns_to_select = null) { |
|
1117 | + $results = $this->_get_consecutive($current_field_value, '>', $field_to_order_by, 1, $query_params, $columns_to_select); |
|
1118 | + return empty($results) ? null : reset($results); |
|
1119 | 1119 | } |
1120 | 1120 | |
1121 | 1121 | |
@@ -1137,9 +1137,9 @@ discard block |
||
1137 | 1137 | * @return EE_Base_Class|null|array() |
1138 | 1138 | * @throws EE_Error |
1139 | 1139 | */ |
1140 | - public function previous( $current_field_value, $field_to_order_by = null, $query_params = array(), $columns_to_select = null ) { |
|
1141 | - $results = $this->_get_consecutive( $current_field_value, '<', $field_to_order_by, 1, $query_params, $columns_to_select ); |
|
1142 | - return empty( $results ) ? null : reset( $results ); |
|
1140 | + public function previous($current_field_value, $field_to_order_by = null, $query_params = array(), $columns_to_select = null) { |
|
1141 | + $results = $this->_get_consecutive($current_field_value, '<', $field_to_order_by, 1, $query_params, $columns_to_select); |
|
1142 | + return empty($results) ? null : reset($results); |
|
1143 | 1143 | } |
1144 | 1144 | |
1145 | 1145 | |
@@ -1160,42 +1160,42 @@ discard block |
||
1160 | 1160 | * @return EE_Base_Class[]|array |
1161 | 1161 | * @throws EE_Error |
1162 | 1162 | */ |
1163 | - protected function _get_consecutive( $current_field_value, $operand = '>', $field_to_order_by = null, $limit = 1, $query_params = array(), $columns_to_select = null ) { |
|
1163 | + protected function _get_consecutive($current_field_value, $operand = '>', $field_to_order_by = null, $limit = 1, $query_params = array(), $columns_to_select = null) { |
|
1164 | 1164 | //if $field_to_order_by is empty then let's assume we're ordering by the primary key. |
1165 | - if ( empty( $field_to_order_by ) ) { |
|
1166 | - if ( $this->has_primary_key_field() ) { |
|
1165 | + if (empty($field_to_order_by)) { |
|
1166 | + if ($this->has_primary_key_field()) { |
|
1167 | 1167 | $field_to_order_by = $this->get_primary_key_field()->get_name(); |
1168 | 1168 | } else { |
1169 | 1169 | |
1170 | - if ( WP_DEBUG ) { |
|
1171 | - 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' ) ); |
|
1170 | + if (WP_DEBUG) { |
|
1171 | + 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')); |
|
1172 | 1172 | } |
1173 | - EE_Error::add_error( __('There was an error with the query.', 'event_espresso') ); |
|
1173 | + EE_Error::add_error(__('There was an error with the query.', 'event_espresso')); |
|
1174 | 1174 | return array(); |
1175 | 1175 | } |
1176 | 1176 | } |
1177 | 1177 | |
1178 | - if( ! is_array( $query_params ) ){ |
|
1179 | - 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' ); |
|
1178 | + if ( ! is_array($query_params)) { |
|
1179 | + 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'); |
|
1180 | 1180 | $query_params = array(); |
1181 | 1181 | } |
1182 | 1182 | |
1183 | 1183 | //let's add the where query param for consecutive look up. |
1184 | - $query_params[0][ $field_to_order_by ] = array( $operand, $current_field_value ); |
|
1184 | + $query_params[0][$field_to_order_by] = array($operand, $current_field_value); |
|
1185 | 1185 | $query_params['limit'] = $limit; |
1186 | 1186 | |
1187 | 1187 | //set direction |
1188 | - $incoming_orderby = isset( $query_params['order_by'] ) ? (array)$query_params['order_by'] : array(); |
|
1188 | + $incoming_orderby = isset($query_params['order_by']) ? (array) $query_params['order_by'] : array(); |
|
1189 | 1189 | $query_params['order_by'] = $operand === '>' |
1190 | - ? array( $field_to_order_by => 'ASC' ) + $incoming_orderby |
|
1191 | - : array( $field_to_order_by => 'DESC') + $incoming_orderby; |
|
1190 | + ? array($field_to_order_by => 'ASC') + $incoming_orderby |
|
1191 | + : array($field_to_order_by => 'DESC') + $incoming_orderby; |
|
1192 | 1192 | |
1193 | 1193 | //if $columns_to_select is empty then that means we're returning EE_Base_Class objects |
1194 | - if ( empty( $columns_to_select ) ) { |
|
1195 | - return $this->get_all( $query_params ); |
|
1194 | + if (empty($columns_to_select)) { |
|
1195 | + return $this->get_all($query_params); |
|
1196 | 1196 | } else { |
1197 | 1197 | //getting just the fields |
1198 | - return $this->_get_all_wpdb_results( $query_params, ARRAY_A, $columns_to_select ); |
|
1198 | + return $this->_get_all_wpdb_results($query_params, ARRAY_A, $columns_to_select); |
|
1199 | 1199 | } |
1200 | 1200 | } |
1201 | 1201 | |
@@ -1206,18 +1206,18 @@ discard block |
||
1206 | 1206 | * This sets the _timezone property after model object has been instantiated. |
1207 | 1207 | * @param null | string $timezone valid PHP DateTimeZone timezone string |
1208 | 1208 | */ |
1209 | - public function set_timezone( $timezone ) { |
|
1210 | - if ( $timezone !== null ) { |
|
1209 | + public function set_timezone($timezone) { |
|
1210 | + if ($timezone !== null) { |
|
1211 | 1211 | $this->_timezone = $timezone; |
1212 | 1212 | } |
1213 | 1213 | //note we need to loop through relations and set the timezone on those objects as well. |
1214 | - foreach ( $this->_model_relations as $relation ) { |
|
1215 | - $relation->set_timezone( $timezone ); |
|
1214 | + foreach ($this->_model_relations as $relation) { |
|
1215 | + $relation->set_timezone($timezone); |
|
1216 | 1216 | } |
1217 | 1217 | //and finally we do the same for any datetime fields |
1218 | - foreach ( $this->_fields as $field ) { |
|
1219 | - if ( $field instanceof EE_Datetime_Field ) { |
|
1220 | - $field->set_timezone( $timezone ); |
|
1218 | + foreach ($this->_fields as $field) { |
|
1219 | + if ($field instanceof EE_Datetime_Field) { |
|
1220 | + $field->set_timezone($timezone); |
|
1221 | 1221 | } |
1222 | 1222 | } |
1223 | 1223 | } |
@@ -1232,9 +1232,9 @@ discard block |
||
1232 | 1232 | */ |
1233 | 1233 | public function get_timezone() { |
1234 | 1234 | //first validate if timezone is set. If not, then let's set it be whatever is set on the model fields. |
1235 | - if ( empty( $this->_timezone ) ) { |
|
1236 | - foreach( $this->_fields as $field ) { |
|
1237 | - if ( $field instanceof EE_Datetime_Field ) { |
|
1235 | + if (empty($this->_timezone)) { |
|
1236 | + foreach ($this->_fields as $field) { |
|
1237 | + if ($field instanceof EE_Datetime_Field) { |
|
1238 | 1238 | $this->set_timezone($field->get_timezone()); |
1239 | 1239 | break; |
1240 | 1240 | } |
@@ -1242,8 +1242,8 @@ discard block |
||
1242 | 1242 | } |
1243 | 1243 | |
1244 | 1244 | //if timezone STILL empty then return the default timezone for the site. |
1245 | - if ( empty( $this->_timezone ) ) { |
|
1246 | - $this->set_timezone( EEH_DTT_Helper::get_timezone() ); |
|
1245 | + if (empty($this->_timezone)) { |
|
1246 | + $this->set_timezone(EEH_DTT_Helper::get_timezone()); |
|
1247 | 1247 | } |
1248 | 1248 | return $this->_timezone; |
1249 | 1249 | } |
@@ -1261,19 +1261,19 @@ discard block |
||
1261 | 1261 | * |
1262 | 1262 | * @return array formats in an array with the date format first, and the time format last. |
1263 | 1263 | */ |
1264 | - public function get_formats_for( $field_name, $pretty = false ) { |
|
1265 | - $field_settings = $this->field_settings_for( $field_name ); |
|
1264 | + public function get_formats_for($field_name, $pretty = false) { |
|
1265 | + $field_settings = $this->field_settings_for($field_name); |
|
1266 | 1266 | |
1267 | 1267 | //if not a valid EE_Datetime_Field then throw error |
1268 | - if ( ! $field_settings instanceof EE_Datetime_Field ) { |
|
1269 | - throw new EE_Error( sprintf( __('The field sent into EEM_Base::get_formats_for (%s) is not registered as a EE_Datetime_Field. Please check the spelling and make sure you are submitting the right field name to retrieve date_formats for.', 'event_espresso' ), $field_name ) ); |
|
1268 | + if ( ! $field_settings instanceof EE_Datetime_Field) { |
|
1269 | + throw new EE_Error(sprintf(__('The field sent into EEM_Base::get_formats_for (%s) is not registered as a EE_Datetime_Field. Please check the spelling and make sure you are submitting the right field name to retrieve date_formats for.', 'event_espresso'), $field_name)); |
|
1270 | 1270 | } |
1271 | 1271 | |
1272 | 1272 | //while we are here, let's make sure the timezone internally in EEM_Base matches what is stored on |
1273 | 1273 | //the field. |
1274 | 1274 | $this->_timezone = $field_settings->get_timezone(); |
1275 | 1275 | |
1276 | - return array( $field_settings->get_date_format( $pretty ), $field_settings->get_time_format( $pretty ) ); |
|
1276 | + return array($field_settings->get_date_format($pretty), $field_settings->get_time_format($pretty)); |
|
1277 | 1277 | } |
1278 | 1278 | |
1279 | 1279 | |
@@ -1297,25 +1297,25 @@ discard block |
||
1297 | 1297 | * @return int|string If the given field_name is not of the EE_Datetime_Field type, then an EE_Error |
1298 | 1298 | * exception is triggered. |
1299 | 1299 | */ |
1300 | - public function current_time_for_query( $field_name, $timestamp = false, $what = 'both' ) { |
|
1301 | - $formats = $this->get_formats_for( $field_name ); |
|
1300 | + public function current_time_for_query($field_name, $timestamp = false, $what = 'both') { |
|
1301 | + $formats = $this->get_formats_for($field_name); |
|
1302 | 1302 | |
1303 | - $DateTime = new DateTime( "now", new DateTimeZone( $this->_timezone ) ); |
|
1303 | + $DateTime = new DateTime("now", new DateTimeZone($this->_timezone)); |
|
1304 | 1304 | |
1305 | - if ( $timestamp ) { |
|
1306 | - return $DateTime->format( 'U' ); |
|
1305 | + if ($timestamp) { |
|
1306 | + return $DateTime->format('U'); |
|
1307 | 1307 | } |
1308 | 1308 | |
1309 | 1309 | //not returning timestamp, so return formatted string in timezone. |
1310 | - switch( $what ) { |
|
1310 | + switch ($what) { |
|
1311 | 1311 | case 'time' : |
1312 | - return $DateTime->format( $formats[1] ); |
|
1312 | + return $DateTime->format($formats[1]); |
|
1313 | 1313 | break; |
1314 | 1314 | case 'date' : |
1315 | - return $DateTime->format( $formats[0] ); |
|
1315 | + return $DateTime->format($formats[0]); |
|
1316 | 1316 | break; |
1317 | 1317 | default : |
1318 | - return $DateTime->format( implode( ' ', $formats ) ); |
|
1318 | + return $DateTime->format(implode(' ', $formats)); |
|
1319 | 1319 | break; |
1320 | 1320 | } |
1321 | 1321 | } |
@@ -1337,17 +1337,17 @@ discard block |
||
1337 | 1337 | * @return DateTime |
1338 | 1338 | * @throws \EE_Error |
1339 | 1339 | */ |
1340 | - public function convert_datetime_for_query( $field_name, $timestring, $incoming_format, $timezone = '' ) { |
|
1340 | + public function convert_datetime_for_query($field_name, $timestring, $incoming_format, $timezone = '') { |
|
1341 | 1341 | |
1342 | 1342 | //just using this to ensure the timezone is set correctly internally |
1343 | - $this->get_formats_for( $field_name ); |
|
1343 | + $this->get_formats_for($field_name); |
|
1344 | 1344 | |
1345 | 1345 | //load EEH_DTT_Helper |
1346 | - $set_timezone = empty( $timezone ) ? EEH_DTT_Helper::get_timezone() : $timezone; |
|
1346 | + $set_timezone = empty($timezone) ? EEH_DTT_Helper::get_timezone() : $timezone; |
|
1347 | 1347 | |
1348 | - $incomingDateTime = date_create_from_format( $incoming_format, $timestring, new DateTimeZone( $set_timezone ) ); |
|
1348 | + $incomingDateTime = date_create_from_format($incoming_format, $timestring, new DateTimeZone($set_timezone)); |
|
1349 | 1349 | |
1350 | - return $incomingDateTime->setTimezone( new DateTimeZone( $this->_timezone ) ); |
|
1350 | + return $incomingDateTime->setTimezone(new DateTimeZone($this->_timezone)); |
|
1351 | 1351 | } |
1352 | 1352 | |
1353 | 1353 | |
@@ -1357,7 +1357,7 @@ discard block |
||
1357 | 1357 | * Gets all the tables comprising this model. Array keys are the table aliases, and values are EE_Table objects |
1358 | 1358 | * @return EE_Table_Base[] |
1359 | 1359 | */ |
1360 | - public function get_tables(){ |
|
1360 | + public function get_tables() { |
|
1361 | 1361 | return $this->_tables; |
1362 | 1362 | } |
1363 | 1363 | |
@@ -1393,9 +1393,9 @@ discard block |
||
1393 | 1393 | * @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) |
1394 | 1394 | * @throws \EE_Error |
1395 | 1395 | */ |
1396 | - public function update($fields_n_values, $query_params, $keep_model_objs_in_sync = TRUE){ |
|
1397 | - if( ! is_array( $query_params ) ){ |
|
1398 | - 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' ); |
|
1396 | + public function update($fields_n_values, $query_params, $keep_model_objs_in_sync = TRUE) { |
|
1397 | + if ( ! is_array($query_params)) { |
|
1398 | + 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'); |
|
1399 | 1399 | $query_params = array(); |
1400 | 1400 | } |
1401 | 1401 | /** |
@@ -1405,7 +1405,7 @@ discard block |
||
1405 | 1405 | * @param array $fields_n_values the updated fields and their new values |
1406 | 1406 | * @param array $query_params @see EEM_Base::get_all() |
1407 | 1407 | */ |
1408 | - do_action( 'AHEE__EEM_Base__update__begin',$this, $fields_n_values, $query_params ); |
|
1408 | + do_action('AHEE__EEM_Base__update__begin', $this, $fields_n_values, $query_params); |
|
1409 | 1409 | /** |
1410 | 1410 | * Filters the fields about to be updated given the query parameters. You can provide the |
1411 | 1411 | * $query_params to $this->get_all() to find exactly which records will be updated |
@@ -1413,10 +1413,10 @@ discard block |
||
1413 | 1413 | * @param EEM_Base $model the model being queried |
1414 | 1414 | * @param array $query_params see EEM_Base::get_all() |
1415 | 1415 | */ |
1416 | - $fields_n_values = (array)apply_filters( 'FHEE__EEM_Base__update__fields_n_values', $fields_n_values, $this, $query_params ); |
|
1416 | + $fields_n_values = (array) apply_filters('FHEE__EEM_Base__update__fields_n_values', $fields_n_values, $this, $query_params); |
|
1417 | 1417 | //need to verify that, for any entry we want to update, there are entries in each secondary table. |
1418 | 1418 | //to do that, for each table, verify that it's PK isn't null. |
1419 | - $tables= $this->get_tables(); |
|
1419 | + $tables = $this->get_tables(); |
|
1420 | 1420 | |
1421 | 1421 | //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 |
1422 | 1422 | //NOTE: we should make this code more efficient by NOT querying twice |
@@ -1426,29 +1426,29 @@ discard block |
||
1426 | 1426 | //we want to make sure the default_where strategy is ignored |
1427 | 1427 | $this->_ignore_where_strategy = TRUE; |
1428 | 1428 | $wpdb_select_results = $this->_get_all_wpdb_results($query_params); |
1429 | - foreach( $wpdb_select_results as $wpdb_result ){ |
|
1429 | + foreach ($wpdb_select_results as $wpdb_result) { |
|
1430 | 1430 | // type cast stdClass as array |
1431 | - $wpdb_result = (array)$wpdb_result; |
|
1431 | + $wpdb_result = (array) $wpdb_result; |
|
1432 | 1432 | //get the model object's PK, as we'll want this if we need to insert a row into secondary tables |
1433 | - if( $this->has_primary_key_field() ){ |
|
1434 | - $main_table_pk_value = $wpdb_result[ $this->get_primary_key_field()->get_qualified_column() ]; |
|
1435 | - }else{ |
|
1433 | + if ($this->has_primary_key_field()) { |
|
1434 | + $main_table_pk_value = $wpdb_result[$this->get_primary_key_field()->get_qualified_column()]; |
|
1435 | + } else { |
|
1436 | 1436 | //if there's no primary key, we basically can't support having a 2nd table on the model (we could but it would be lots of work) |
1437 | 1437 | $main_table_pk_value = null; |
1438 | 1438 | } |
1439 | 1439 | //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 |
1440 | 1440 | //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 |
1441 | - if(count($tables) > 1){ |
|
1441 | + if (count($tables) > 1) { |
|
1442 | 1442 | //foreach matching row in the DB, ensure that each table's PK isn't null. If so, there must not be an entry |
1443 | 1443 | //in that table, and so we'll want to insert one |
1444 | - foreach($tables as $table_obj){ |
|
1444 | + foreach ($tables as $table_obj) { |
|
1445 | 1445 | $this_table_pk_column = $table_obj->get_fully_qualified_pk_column(); |
1446 | 1446 | //if there is no private key for this table on the results, it means there's no entry |
1447 | 1447 | //in this table, right? so insert a row in the current table, using any fields available |
1448 | - if( ! ( array_key_exists( $this_table_pk_column, $wpdb_result) && $wpdb_result[ $this_table_pk_column ] )){ |
|
1448 | + if ( ! (array_key_exists($this_table_pk_column, $wpdb_result) && $wpdb_result[$this_table_pk_column])) { |
|
1449 | 1449 | $success = $this->_insert_into_specific_table($table_obj, $fields_n_values, $main_table_pk_value); |
1450 | 1450 | //if we died here, report the error |
1451 | - if( ! $success ) { |
|
1451 | + if ( ! $success) { |
|
1452 | 1452 | return false; |
1453 | 1453 | } |
1454 | 1454 | } |
@@ -1468,44 +1468,44 @@ discard block |
||
1468 | 1468 | //if this wasn't called from a model object (to update itself) |
1469 | 1469 | //then we want to make sure we keep all the existing |
1470 | 1470 | //model objects in sync with the db |
1471 | - if( $keep_model_objs_in_sync && ! $this->_values_already_prepared_by_model_object ){ |
|
1472 | - if( $this->has_primary_key_field() ){ |
|
1473 | - $model_objs_affected_ids = $this->get_col( $query_params ); |
|
1474 | - }else{ |
|
1471 | + if ($keep_model_objs_in_sync && ! $this->_values_already_prepared_by_model_object) { |
|
1472 | + if ($this->has_primary_key_field()) { |
|
1473 | + $model_objs_affected_ids = $this->get_col($query_params); |
|
1474 | + } else { |
|
1475 | 1475 | //we need to select a bunch of columns and then combine them into the the "index primary key string"s |
1476 | - $models_affected_key_columns = $this->_get_all_wpdb_results($query_params, ARRAY_A ); |
|
1476 | + $models_affected_key_columns = $this->_get_all_wpdb_results($query_params, ARRAY_A); |
|
1477 | 1477 | $model_objs_affected_ids = array(); |
1478 | - foreach( $models_affected_key_columns as $row ){ |
|
1479 | - $combined_index_key = $this->get_index_primary_key_string( $row ); |
|
1480 | - $model_objs_affected_ids[ $combined_index_key ] = $combined_index_key; |
|
1478 | + foreach ($models_affected_key_columns as $row) { |
|
1479 | + $combined_index_key = $this->get_index_primary_key_string($row); |
|
1480 | + $model_objs_affected_ids[$combined_index_key] = $combined_index_key; |
|
1481 | 1481 | } |
1482 | 1482 | |
1483 | 1483 | } |
1484 | 1484 | |
1485 | - if( ! $model_objs_affected_ids ){ |
|
1485 | + if ( ! $model_objs_affected_ids) { |
|
1486 | 1486 | //wait wait wait- if nothing was affected let's stop here |
1487 | 1487 | return 0; |
1488 | 1488 | } |
1489 | - foreach( $model_objs_affected_ids as $id ){ |
|
1490 | - $model_obj_in_entity_map = $this->get_from_entity_map( $id ); |
|
1491 | - if( $model_obj_in_entity_map ){ |
|
1492 | - foreach( $fields_n_values as $field => $new_value ){ |
|
1493 | - $model_obj_in_entity_map->set( $field, $new_value ); |
|
1489 | + foreach ($model_objs_affected_ids as $id) { |
|
1490 | + $model_obj_in_entity_map = $this->get_from_entity_map($id); |
|
1491 | + if ($model_obj_in_entity_map) { |
|
1492 | + foreach ($fields_n_values as $field => $new_value) { |
|
1493 | + $model_obj_in_entity_map->set($field, $new_value); |
|
1494 | 1494 | } |
1495 | 1495 | } |
1496 | 1496 | } |
1497 | 1497 | //if there is a primary key on this model, we can now do a slight optimization |
1498 | - if( $this->has_primary_key_field() ){ |
|
1498 | + if ($this->has_primary_key_field()) { |
|
1499 | 1499 | //we already know what we want to update. So let's make the query simpler so it's a little more efficient |
1500 | 1500 | $query_params = array( |
1501 | - array( $this->primary_key_name() => array( 'IN', $model_objs_affected_ids ) ), |
|
1502 | - 'limit' => count( $model_objs_affected_ids ), 'default_where_conditions' => 'none' ); |
|
1501 | + array($this->primary_key_name() => array('IN', $model_objs_affected_ids)), |
|
1502 | + 'limit' => count($model_objs_affected_ids), 'default_where_conditions' => 'none' ); |
|
1503 | 1503 | } |
1504 | 1504 | } |
1505 | 1505 | |
1506 | - $model_query_info = $this->_create_model_query_info_carrier( $query_params ); |
|
1507 | - $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. |
|
1508 | - $rows_affected = $this->_do_wpdb_query('query', array( $SQL ) ); |
|
1506 | + $model_query_info = $this->_create_model_query_info_carrier($query_params); |
|
1507 | + $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. |
|
1508 | + $rows_affected = $this->_do_wpdb_query('query', array($SQL)); |
|
1509 | 1509 | /** |
1510 | 1510 | * Action called after a model update call has been made. |
1511 | 1511 | * |
@@ -1514,8 +1514,8 @@ discard block |
||
1514 | 1514 | * @param array $query_params @see EEM_Base::get_all() |
1515 | 1515 | * @param int $rows_affected |
1516 | 1516 | */ |
1517 | - do_action( 'AHEE__EEM_Base__update__end',$this, $fields_n_values, $query_params, $rows_affected ); |
|
1518 | - return $rows_affected;//how many supposedly got updated |
|
1517 | + do_action('AHEE__EEM_Base__update__end', $this, $fields_n_values, $query_params, $rows_affected); |
|
1518 | + return $rows_affected; //how many supposedly got updated |
|
1519 | 1519 | } |
1520 | 1520 | |
1521 | 1521 | |
@@ -1531,22 +1531,22 @@ discard block |
||
1531 | 1531 | * @return array just like $wpdb->get_col() |
1532 | 1532 | * @throws \EE_Error |
1533 | 1533 | */ |
1534 | - public function get_col( $query_params = array(), $field_to_select = NULL ){ |
|
1534 | + public function get_col($query_params = array(), $field_to_select = NULL) { |
|
1535 | 1535 | |
1536 | - if( $field_to_select ){ |
|
1537 | - $field = $this->field_settings_for( $field_to_select ); |
|
1538 | - }elseif( $this->has_primary_key_field ( ) ){ |
|
1536 | + if ($field_to_select) { |
|
1537 | + $field = $this->field_settings_for($field_to_select); |
|
1538 | + }elseif ($this->has_primary_key_field( )) { |
|
1539 | 1539 | $field = $this->get_primary_key_field(); |
1540 | - }else{ |
|
1540 | + } else { |
|
1541 | 1541 | //no primary key, just grab the first column |
1542 | - $field = reset( $this->field_settings()); |
|
1542 | + $field = reset($this->field_settings()); |
|
1543 | 1543 | } |
1544 | 1544 | |
1545 | 1545 | |
1546 | 1546 | $model_query_info = $this->_create_model_query_info_carrier($query_params); |
1547 | 1547 | $select_expressions = $field->get_qualified_column(); |
1548 | - $SQL ="SELECT $select_expressions ".$this->_construct_2nd_half_of_select_query($model_query_info); |
|
1549 | - return $this->_do_wpdb_query('get_col', array( $SQL ) ); |
|
1548 | + $SQL = "SELECT $select_expressions ".$this->_construct_2nd_half_of_select_query($model_query_info); |
|
1549 | + return $this->_do_wpdb_query('get_col', array($SQL)); |
|
1550 | 1550 | } |
1551 | 1551 | |
1552 | 1552 | |
@@ -1559,12 +1559,12 @@ discard block |
||
1559 | 1559 | * @return string |
1560 | 1560 | * @throws \EE_Error |
1561 | 1561 | */ |
1562 | - public function get_var( $query_params = array(), $field_to_select = NULL ) { |
|
1563 | - $query_params[ 'limit' ] = 1; |
|
1564 | - $col = $this->get_col( $query_params, $field_to_select ); |
|
1565 | - if( ! empty( $col ) ) { |
|
1566 | - return reset( $col ); |
|
1567 | - }else{ |
|
1562 | + public function get_var($query_params = array(), $field_to_select = NULL) { |
|
1563 | + $query_params['limit'] = 1; |
|
1564 | + $col = $this->get_col($query_params, $field_to_select); |
|
1565 | + if ( ! empty($col)) { |
|
1566 | + return reset($col); |
|
1567 | + } else { |
|
1568 | 1568 | return NULL; |
1569 | 1569 | } |
1570 | 1570 | } |
@@ -1580,19 +1580,19 @@ discard block |
||
1580 | 1580 | * @return string of SQL |
1581 | 1581 | * @throws \EE_Error |
1582 | 1582 | */ |
1583 | - public function _construct_update_sql($fields_n_values){ |
|
1583 | + public function _construct_update_sql($fields_n_values) { |
|
1584 | 1584 | /** @type WPDB $wpdb */ |
1585 | 1585 | global $wpdb; |
1586 | 1586 | $cols_n_values = array(); |
1587 | - foreach($fields_n_values as $field_name => $value){ |
|
1587 | + foreach ($fields_n_values as $field_name => $value) { |
|
1588 | 1588 | $field_obj = $this->field_settings_for($field_name); |
1589 | 1589 | //if the value is NULL, we want to assign the value to that. |
1590 | 1590 | //wpdb->prepare doesn't really handle that properly |
1591 | - $prepared_value = $this->_prepare_value_or_use_default( $field_obj, $fields_n_values ); |
|
1592 | - $value_sql = $prepared_value===NULL ? 'NULL' : $wpdb->prepare( $field_obj->get_wpdb_data_type(), $prepared_value ); |
|
1591 | + $prepared_value = $this->_prepare_value_or_use_default($field_obj, $fields_n_values); |
|
1592 | + $value_sql = $prepared_value === NULL ? 'NULL' : $wpdb->prepare($field_obj->get_wpdb_data_type(), $prepared_value); |
|
1593 | 1593 | $cols_n_values[] = $field_obj->get_qualified_column()."=".$value_sql; |
1594 | 1594 | } |
1595 | - return implode(",",$cols_n_values); |
|
1595 | + return implode(",", $cols_n_values); |
|
1596 | 1596 | |
1597 | 1597 | } |
1598 | 1598 | |
@@ -1608,10 +1608,10 @@ discard block |
||
1608 | 1608 | * @return boolean whether the row got deleted or not |
1609 | 1609 | * @throws \EE_Error |
1610 | 1610 | */ |
1611 | - public function delete_permanently_by_ID( $id ) { |
|
1611 | + public function delete_permanently_by_ID($id) { |
|
1612 | 1612 | return $this->delete_permanently( |
1613 | 1613 | array( |
1614 | - array( $this->get_primary_key_field()->get_name() => $id ), |
|
1614 | + array($this->get_primary_key_field()->get_name() => $id), |
|
1615 | 1615 | 'limit' => 1 |
1616 | 1616 | ) |
1617 | 1617 | ); |
@@ -1627,10 +1627,10 @@ discard block |
||
1627 | 1627 | * @return boolean whether the row got deleted or not |
1628 | 1628 | * @throws \EE_Error |
1629 | 1629 | */ |
1630 | - public function delete_by_ID( $id ){ |
|
1630 | + public function delete_by_ID($id) { |
|
1631 | 1631 | return $this->delete( |
1632 | 1632 | array( |
1633 | - array( $this->get_primary_key_field()->get_name() => $id ), |
|
1633 | + array($this->get_primary_key_field()->get_name() => $id), |
|
1634 | 1634 | 'limit' => 1 |
1635 | 1635 | ) |
1636 | 1636 | ); |
@@ -1649,7 +1649,7 @@ discard block |
||
1649 | 1649 | * @return int how many rows got deleted |
1650 | 1650 | * @throws \EE_Error |
1651 | 1651 | */ |
1652 | - public function delete($query_params,$allow_blocking = true){ |
|
1652 | + public function delete($query_params, $allow_blocking = true) { |
|
1653 | 1653 | return $this->delete_permanently($query_params, $allow_blocking); |
1654 | 1654 | } |
1655 | 1655 | |
@@ -1667,7 +1667,7 @@ discard block |
||
1667 | 1667 | * @return int how many rows got deleted |
1668 | 1668 | * @throws \EE_Error |
1669 | 1669 | */ |
1670 | - public function delete_permanently($query_params,$allow_blocking = true){ |
|
1670 | + public function delete_permanently($query_params, $allow_blocking = true) { |
|
1671 | 1671 | /** |
1672 | 1672 | * Action called just before performing a real deletion query. You can use the |
1673 | 1673 | * model and its $query_params to find exactly which items will be deleted |
@@ -1676,31 +1676,31 @@ discard block |
||
1676 | 1676 | * @param boolean $allow_blocking whether or not to allow related model objects |
1677 | 1677 | * to block (prevent) this deletion |
1678 | 1678 | */ |
1679 | - do_action( 'AHEE__EEM_Base__delete__begin', $this, $query_params, $allow_blocking ); |
|
1679 | + do_action('AHEE__EEM_Base__delete__begin', $this, $query_params, $allow_blocking); |
|
1680 | 1680 | //some MySQL databases may be running safe mode, which may restrict |
1681 | 1681 | //deletion if there is no KEY column used in the WHERE statement of a deletion. |
1682 | 1682 | //to get around this, we first do a SELECT, get all the IDs, and then run another query |
1683 | 1683 | //to delete them |
1684 | 1684 | $items_for_deletion = $this->_get_all_wpdb_results($query_params); |
1685 | - $deletion_where = $this->_setup_ids_for_delete( $items_for_deletion, $allow_blocking); |
|
1686 | - if($deletion_where){ |
|
1685 | + $deletion_where = $this->_setup_ids_for_delete($items_for_deletion, $allow_blocking); |
|
1686 | + if ($deletion_where) { |
|
1687 | 1687 | //echo "objects for deletion:";var_dump($objects_for_deletion); |
1688 | 1688 | $model_query_info = $this->_create_model_query_info_carrier($query_params); |
1689 | - $table_aliases = array_keys( $this->_tables ); |
|
1690 | - $SQL = "DELETE ".implode(", ",$table_aliases)." FROM ".$model_query_info->get_full_join_sql()." WHERE ".$deletion_where; |
|
1689 | + $table_aliases = array_keys($this->_tables); |
|
1690 | + $SQL = "DELETE ".implode(", ", $table_aliases)." FROM ".$model_query_info->get_full_join_sql()." WHERE ".$deletion_where; |
|
1691 | 1691 | |
1692 | 1692 | // /echo "delete sql:$SQL"; |
1693 | - $rows_deleted = $this->_do_wpdb_query( 'query', array( $SQL ) ); |
|
1694 | - }else{ |
|
1693 | + $rows_deleted = $this->_do_wpdb_query('query', array($SQL)); |
|
1694 | + } else { |
|
1695 | 1695 | $rows_deleted = 0; |
1696 | 1696 | } |
1697 | 1697 | |
1698 | 1698 | //and lastly make sure those items are removed from the entity map; if they could be put into it at all |
1699 | - if( $this->has_primary_key_field() ){ |
|
1700 | - foreach($items_for_deletion as $item_for_deletion_row ){ |
|
1701 | - $pk_value = $item_for_deletion_row[ $this->get_primary_key_field()->get_qualified_column() ]; |
|
1702 | - if( isset( $this->_entity_map[ EEM_Base::$_model_query_blog_id ][ $pk_value ] ) ){ |
|
1703 | - unset( $this->_entity_map[ EEM_Base::$_model_query_blog_id ][ $pk_value ] ); |
|
1699 | + if ($this->has_primary_key_field()) { |
|
1700 | + foreach ($items_for_deletion as $item_for_deletion_row) { |
|
1701 | + $pk_value = $item_for_deletion_row[$this->get_primary_key_field()->get_qualified_column()]; |
|
1702 | + if (isset($this->_entity_map[EEM_Base::$_model_query_blog_id][$pk_value])) { |
|
1703 | + unset($this->_entity_map[EEM_Base::$_model_query_blog_id][$pk_value]); |
|
1704 | 1704 | } |
1705 | 1705 | } |
1706 | 1706 | } |
@@ -1712,8 +1712,8 @@ discard block |
||
1712 | 1712 | * @param array $query_params @see EEM_Base::get_all() |
1713 | 1713 | * @param int $rows_deleted |
1714 | 1714 | */ |
1715 | - do_action( 'AHEE__EEM_Base__delete__end', $this, $query_params, $rows_deleted ); |
|
1716 | - return $rows_deleted;//how many supposedly got deleted |
|
1715 | + do_action('AHEE__EEM_Base__delete__end', $this, $query_params, $rows_deleted); |
|
1716 | + return $rows_deleted; //how many supposedly got deleted |
|
1717 | 1717 | } |
1718 | 1718 | |
1719 | 1719 | |
@@ -1731,28 +1731,28 @@ discard block |
||
1731 | 1731 | * @return boolean |
1732 | 1732 | * @throws \EE_Error |
1733 | 1733 | */ |
1734 | - public function delete_is_blocked_by_related_models($this_model_obj_or_id, $ignore_this_model_obj = null){ |
|
1734 | + public function delete_is_blocked_by_related_models($this_model_obj_or_id, $ignore_this_model_obj = null) { |
|
1735 | 1735 | //first, if $ignore_this_model_obj was supplied, get its model |
1736 | - if($ignore_this_model_obj && $ignore_this_model_obj instanceof EE_Base_Class){ |
|
1736 | + if ($ignore_this_model_obj && $ignore_this_model_obj instanceof EE_Base_Class) { |
|
1737 | 1737 | $ignored_model = $ignore_this_model_obj->get_model(); |
1738 | - }else{ |
|
1738 | + } else { |
|
1739 | 1739 | $ignored_model = null; |
1740 | 1740 | } |
1741 | 1741 | //now check all the relations of $this_model_obj_or_id and see if there |
1742 | 1742 | //are any related model objects blocking it? |
1743 | 1743 | $is_blocked = false; |
1744 | - foreach($this->_model_relations as $relation_name => $relation_obj){ |
|
1745 | - if( $relation_obj->block_delete_if_related_models_exist()){ |
|
1744 | + foreach ($this->_model_relations as $relation_name => $relation_obj) { |
|
1745 | + if ($relation_obj->block_delete_if_related_models_exist()) { |
|
1746 | 1746 | //if $ignore_this_model_obj was supplied, then for the query |
1747 | 1747 | //on that model needs to be told to ignore $ignore_this_model_obj |
1748 | - if($ignored_model && $relation_name === $ignored_model->get_this_model_name()){ |
|
1749 | - $related_model_objects = $relation_obj->get_all_related($this_model_obj_or_id,array( |
|
1750 | - array($ignored_model->get_primary_key_field()->get_name() => array('!=',$ignore_this_model_obj->ID())))); |
|
1751 | - }else{ |
|
1748 | + if ($ignored_model && $relation_name === $ignored_model->get_this_model_name()) { |
|
1749 | + $related_model_objects = $relation_obj->get_all_related($this_model_obj_or_id, array( |
|
1750 | + array($ignored_model->get_primary_key_field()->get_name() => array('!=', $ignore_this_model_obj->ID())))); |
|
1751 | + } else { |
|
1752 | 1752 | $related_model_objects = $relation_obj->get_all_related($this_model_obj_or_id); |
1753 | 1753 | } |
1754 | 1754 | |
1755 | - if($related_model_objects){ |
|
1755 | + if ($related_model_objects) { |
|
1756 | 1756 | EE_Error::add_error($relation_obj->get_deletion_error_message(), __FILE__, __FUNCTION__, __LINE__); |
1757 | 1757 | $is_blocked = true; |
1758 | 1758 | } |
@@ -1772,75 +1772,75 @@ discard block |
||
1772 | 1772 | * @throws EE_Error |
1773 | 1773 | * @return string everything that comes after the WHERE statement. |
1774 | 1774 | */ |
1775 | - protected function _setup_ids_for_delete( $objects_for_deletion, $allow_blocking = true) { |
|
1776 | - if($this->has_primary_key_field()){ |
|
1775 | + protected function _setup_ids_for_delete($objects_for_deletion, $allow_blocking = true) { |
|
1776 | + if ($this->has_primary_key_field()) { |
|
1777 | 1777 | $primary_table = $this->_get_main_table(); |
1778 | 1778 | $other_tables = $this->_get_other_tables(); |
1779 | 1779 | $deletes = $query = array(); |
1780 | - foreach ( $objects_for_deletion as $delete_object ) { |
|
1780 | + foreach ($objects_for_deletion as $delete_object) { |
|
1781 | 1781 | //before we mark this object for deletion, |
1782 | 1782 | //make sure there's no related objects blocking its deletion (if we're checking) |
1783 | 1783 | if ( |
1784 | 1784 | $allow_blocking |
1785 | 1785 | && $this->delete_is_blocked_by_related_models( |
1786 | - $delete_object[ $primary_table->get_fully_qualified_pk_column() ] |
|
1786 | + $delete_object[$primary_table->get_fully_qualified_pk_column()] |
|
1787 | 1787 | ) |
1788 | 1788 | ) { |
1789 | 1789 | continue; |
1790 | 1790 | } |
1791 | 1791 | //primary table deletes |
1792 | - if ( isset( $delete_object[ $primary_table->get_fully_qualified_pk_column() ] ) ) { |
|
1793 | - $deletes[ $primary_table->get_fully_qualified_pk_column() ][] = $delete_object[ $primary_table->get_fully_qualified_pk_column() ]; |
|
1792 | + if (isset($delete_object[$primary_table->get_fully_qualified_pk_column()])) { |
|
1793 | + $deletes[$primary_table->get_fully_qualified_pk_column()][] = $delete_object[$primary_table->get_fully_qualified_pk_column()]; |
|
1794 | 1794 | } |
1795 | 1795 | //other tables |
1796 | - if ( ! empty( $other_tables ) ) { |
|
1797 | - foreach ( $other_tables as $ot ) { |
|
1796 | + if ( ! empty($other_tables)) { |
|
1797 | + foreach ($other_tables as $ot) { |
|
1798 | 1798 | //first check if we've got the foreign key column here. |
1799 | - if ( isset( $delete_object[ $ot->get_fully_qualified_fk_column() ] ) ) { |
|
1800 | - $deletes[ $ot->get_fully_qualified_pk_column() ][] = $delete_object[ $ot->get_fully_qualified_fk_column() ]; |
|
1799 | + if (isset($delete_object[$ot->get_fully_qualified_fk_column()])) { |
|
1800 | + $deletes[$ot->get_fully_qualified_pk_column()][] = $delete_object[$ot->get_fully_qualified_fk_column()]; |
|
1801 | 1801 | } |
1802 | 1802 | // wait! it's entirely possible that we'll have a the primary key |
1803 | 1803 | // for this table in here, if it's a foreign key for one of the other secondary tables |
1804 | - if ( isset( $delete_object[ $ot->get_fully_qualified_pk_column() ] ) ) { |
|
1805 | - $deletes[ $ot->get_fully_qualified_pk_column() ][] = $delete_object[ $ot->get_fully_qualified_pk_column() ]; |
|
1804 | + if (isset($delete_object[$ot->get_fully_qualified_pk_column()])) { |
|
1805 | + $deletes[$ot->get_fully_qualified_pk_column()][] = $delete_object[$ot->get_fully_qualified_pk_column()]; |
|
1806 | 1806 | } |
1807 | 1807 | // finally, it is possible that the fk for this table is found |
1808 | 1808 | // in the fully qualified pk column for the fk table, so let's see if that's there! |
1809 | - if ( isset( $delete_object[ $ot->get_fully_qualified_pk_on_fk_table() ] ) ) { |
|
1810 | - $deletes[ $ot->get_fully_qualified_pk_column() ][] = $delete_object[ $ot->get_fully_qualified_pk_column() ]; |
|
1809 | + if (isset($delete_object[$ot->get_fully_qualified_pk_on_fk_table()])) { |
|
1810 | + $deletes[$ot->get_fully_qualified_pk_column()][] = $delete_object[$ot->get_fully_qualified_pk_column()]; |
|
1811 | 1811 | } |
1812 | 1812 | } |
1813 | 1813 | } |
1814 | 1814 | } |
1815 | 1815 | |
1816 | 1816 | //we should have deletes now, so let's just go through and setup the where statement |
1817 | - foreach ( $deletes as $column => $values ) { |
|
1817 | + foreach ($deletes as $column => $values) { |
|
1818 | 1818 | //make sure we have unique $values; |
1819 | 1819 | $values = array_unique($values); |
1820 | - $query[] = $column . ' IN(' . implode(",",$values) . ')'; |
|
1820 | + $query[] = $column.' IN('.implode(",", $values).')'; |
|
1821 | 1821 | } |
1822 | 1822 | |
1823 | - return !empty($query) ? implode(' AND ', $query ) : ''; |
|
1824 | - }elseif(count($this->get_combined_primary_key_fields()) > 1){ |
|
1823 | + return ! empty($query) ? implode(' AND ', $query) : ''; |
|
1824 | + }elseif (count($this->get_combined_primary_key_fields()) > 1) { |
|
1825 | 1825 | $ways_to_identify_a_row = array(); |
1826 | 1826 | $fields = $this->get_combined_primary_key_fields(); |
1827 | 1827 | //note: because there' sno primary key, that means nothing else can be pointing to this model, right? |
1828 | - foreach($objects_for_deletion as $delete_object){ |
|
1828 | + foreach ($objects_for_deletion as $delete_object) { |
|
1829 | 1829 | $values_for_each_cpk_for_a_row = array(); |
1830 | - foreach($fields as $cpk_field){ |
|
1831 | - if ( $cpk_field instanceof EE_Model_Field_Base ){ |
|
1830 | + foreach ($fields as $cpk_field) { |
|
1831 | + if ($cpk_field instanceof EE_Model_Field_Base) { |
|
1832 | 1832 | $values_for_each_cpk_for_a_row[] = $cpk_field->get_qualified_column() |
1833 | 1833 | . "=" |
1834 | - . $delete_object[ $cpk_field->get_qualified_column() ]; |
|
1834 | + . $delete_object[$cpk_field->get_qualified_column()]; |
|
1835 | 1835 | } |
1836 | 1836 | } |
1837 | - $ways_to_identify_a_row[] = "(".implode(" AND ",$values_for_each_cpk_for_a_row).")"; |
|
1837 | + $ways_to_identify_a_row[] = "(".implode(" AND ", $values_for_each_cpk_for_a_row).")"; |
|
1838 | 1838 | } |
1839 | - return implode(" OR ",$ways_to_identify_a_row); |
|
1840 | - }else{ |
|
1839 | + return implode(" OR ", $ways_to_identify_a_row); |
|
1840 | + } else { |
|
1841 | 1841 | //so there's no primary key and no combined key... |
1842 | 1842 | //sorry, can't help you |
1843 | - 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))); |
|
1843 | + 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))); |
|
1844 | 1844 | } |
1845 | 1845 | } |
1846 | 1846 | |
@@ -1856,34 +1856,34 @@ discard block |
||
1856 | 1856 | * @return int |
1857 | 1857 | * @throws \EE_Error |
1858 | 1858 | */ |
1859 | - public function count($query_params =array(),$field_to_count = NULL, $distinct = FALSE){ |
|
1859 | + public function count($query_params = array(), $field_to_count = NULL, $distinct = FALSE) { |
|
1860 | 1860 | $model_query_info = $this->_create_model_query_info_carrier($query_params); |
1861 | - if($field_to_count){ |
|
1861 | + if ($field_to_count) { |
|
1862 | 1862 | $field_obj = $this->field_settings_for($field_to_count); |
1863 | 1863 | $column_to_count = $field_obj->get_qualified_column(); |
1864 | - }elseif($this->has_primary_key_field ()){ |
|
1864 | + }elseif ($this->has_primary_key_field()) { |
|
1865 | 1865 | $pk_field_obj = $this->get_primary_key_field(); |
1866 | 1866 | $column_to_count = $pk_field_obj->get_qualified_column(); |
1867 | - }else{ |
|
1867 | + } else { |
|
1868 | 1868 | //there's no primary key |
1869 | 1869 | //if we're counting distinct items, and there's no primary key, |
1870 | 1870 | //we need to list out the columns for distinction; |
1871 | 1871 | //otherwise we can just use star |
1872 | - if( $distinct ) { |
|
1872 | + if ($distinct) { |
|
1873 | 1873 | $columns_to_use = array(); |
1874 | - foreach( $this->get_combined_primary_key_fields() as $field_obj ) { |
|
1874 | + foreach ($this->get_combined_primary_key_fields() as $field_obj) { |
|
1875 | 1875 | $columns_to_use[] = $field_obj->get_qualified_column(); |
1876 | 1876 | } |
1877 | - $column_to_count = implode(',', $columns_to_use ); |
|
1877 | + $column_to_count = implode(',', $columns_to_use); |
|
1878 | 1878 | } else { |
1879 | 1879 | $column_to_count = '*'; |
1880 | 1880 | } |
1881 | 1881 | |
1882 | 1882 | } |
1883 | 1883 | |
1884 | - $column_to_count = $distinct ? "DISTINCT " . $column_to_count : $column_to_count; |
|
1885 | - $SQL ="SELECT COUNT(".$column_to_count.")" . $this->_construct_2nd_half_of_select_query($model_query_info); |
|
1886 | - return (int)$this->_do_wpdb_query( 'get_var', array( $SQL) ); |
|
1884 | + $column_to_count = $distinct ? "DISTINCT ".$column_to_count : $column_to_count; |
|
1885 | + $SQL = "SELECT COUNT(".$column_to_count.")".$this->_construct_2nd_half_of_select_query($model_query_info); |
|
1886 | + return (int) $this->_do_wpdb_query('get_var', array($SQL)); |
|
1887 | 1887 | } |
1888 | 1888 | |
1889 | 1889 | |
@@ -1896,24 +1896,24 @@ discard block |
||
1896 | 1896 | * @return float |
1897 | 1897 | * @throws \EE_Error |
1898 | 1898 | */ |
1899 | - public function sum($query_params, $field_to_sum = NULL){ |
|
1899 | + public function sum($query_params, $field_to_sum = NULL) { |
|
1900 | 1900 | $model_query_info = $this->_create_model_query_info_carrier($query_params); |
1901 | 1901 | |
1902 | - if($field_to_sum){ |
|
1902 | + if ($field_to_sum) { |
|
1903 | 1903 | $field_obj = $this->field_settings_for($field_to_sum); |
1904 | 1904 | |
1905 | - }else{ |
|
1905 | + } else { |
|
1906 | 1906 | $field_obj = $this->get_primary_key_field(); |
1907 | 1907 | } |
1908 | 1908 | $column_to_count = $field_obj->get_qualified_column(); |
1909 | 1909 | |
1910 | - $SQL ="SELECT SUM(".$column_to_count.")" . $this->_construct_2nd_half_of_select_query($model_query_info); |
|
1911 | - $return_value = $this->_do_wpdb_query('get_var',array( $SQL ) ); |
|
1910 | + $SQL = "SELECT SUM(".$column_to_count.")".$this->_construct_2nd_half_of_select_query($model_query_info); |
|
1911 | + $return_value = $this->_do_wpdb_query('get_var', array($SQL)); |
|
1912 | 1912 | $data_type = $field_obj->get_wpdb_data_type(); |
1913 | - if( $data_type === '%d' || $data_type === '%s' ){ |
|
1914 | - return (float)$return_value; |
|
1915 | - }else{//must be %f |
|
1916 | - return (float)$return_value; |
|
1913 | + if ($data_type === '%d' || $data_type === '%s') { |
|
1914 | + return (float) $return_value; |
|
1915 | + } else {//must be %f |
|
1916 | + return (float) $return_value; |
|
1917 | 1917 | } |
1918 | 1918 | } |
1919 | 1919 | |
@@ -1928,37 +1928,37 @@ discard block |
||
1928 | 1928 | * @global wpdb $wpdb |
1929 | 1929 | * @return mixed |
1930 | 1930 | */ |
1931 | - protected function _do_wpdb_query( $wpdb_method, $arguments_to_provide ){ |
|
1931 | + protected function _do_wpdb_query($wpdb_method, $arguments_to_provide) { |
|
1932 | 1932 | //if we're in maintenance mode level 2, DON'T run any queries |
1933 | 1933 | //because level 2 indicates the database needs updating and |
1934 | 1934 | //is probably out of sync with the code |
1935 | - if( ! EE_Maintenance_Mode::instance()->models_can_query()){ |
|
1935 | + if ( ! EE_Maintenance_Mode::instance()->models_can_query()) { |
|
1936 | 1936 | 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"))); |
1937 | 1937 | } |
1938 | 1938 | /** @type WPDB $wpdb */ |
1939 | 1939 | global $wpdb; |
1940 | - if( ! method_exists( $wpdb, $wpdb_method ) ){ |
|
1941 | - throw new EE_Error( sprintf( __( 'There is no method named "%s" on Wordpress\' $wpdb object','event_espresso' ), $wpdb_method ) ); |
|
1940 | + if ( ! method_exists($wpdb, $wpdb_method)) { |
|
1941 | + throw new EE_Error(sprintf(__('There is no method named "%s" on Wordpress\' $wpdb object', 'event_espresso'), $wpdb_method)); |
|
1942 | 1942 | } |
1943 | - if( WP_DEBUG ){ |
|
1943 | + if (WP_DEBUG) { |
|
1944 | 1944 | $old_show_errors_value = $wpdb->show_errors; |
1945 | - $wpdb->show_errors( FALSE ); |
|
1946 | - } |
|
1947 | - $result = $this->_process_wpdb_query( $wpdb_method, $arguments_to_provide ); |
|
1948 | - $this->show_db_query_if_previously_requested( $wpdb->last_query ); |
|
1949 | - if( WP_DEBUG ){ |
|
1950 | - $wpdb->show_errors( $old_show_errors_value ); |
|
1951 | - if( ! empty( $wpdb->last_error ) ){ |
|
1952 | - throw new EE_Error( sprintf( __( 'WPDB Error: "%s"', 'event_espresso' ), $wpdb->last_error ) ); |
|
1953 | - }elseif( $result === false ){ |
|
1954 | - 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 ) ) ); |
|
1945 | + $wpdb->show_errors(FALSE); |
|
1946 | + } |
|
1947 | + $result = $this->_process_wpdb_query($wpdb_method, $arguments_to_provide); |
|
1948 | + $this->show_db_query_if_previously_requested($wpdb->last_query); |
|
1949 | + if (WP_DEBUG) { |
|
1950 | + $wpdb->show_errors($old_show_errors_value); |
|
1951 | + if ( ! empty($wpdb->last_error)) { |
|
1952 | + throw new EE_Error(sprintf(__('WPDB Error: "%s"', 'event_espresso'), $wpdb->last_error)); |
|
1953 | + }elseif ($result === false) { |
|
1954 | + 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))); |
|
1955 | 1955 | } |
1956 | - }elseif( $result === false ) { |
|
1956 | + }elseif ($result === false) { |
|
1957 | 1957 | EE_Error::add_error( |
1958 | 1958 | sprintf( |
1959 | - __( 'A database error has occurred. Turn on WP_DEBUG for more information.||A database error occurred doing wpdb method "%1$s", with arguments "%2$s". The error was "%3$s"', 'event_espresso' ), |
|
1959 | + __('A database error has occurred. Turn on WP_DEBUG for more information.||A database error occurred doing wpdb method "%1$s", with arguments "%2$s". The error was "%3$s"', 'event_espresso'), |
|
1960 | 1960 | $wpdb_method, |
1961 | - var_export( $arguments_to_provide, true ), |
|
1961 | + var_export($arguments_to_provide, true), |
|
1962 | 1962 | $wpdb->last_error |
1963 | 1963 | ), |
1964 | 1964 | __FILE__, |
@@ -1980,26 +1980,26 @@ discard block |
||
1980 | 1980 | * @param array $arguments_to_provide |
1981 | 1981 | * @return mixed |
1982 | 1982 | */ |
1983 | - private function _process_wpdb_query( $wpdb_method, $arguments_to_provide ) { |
|
1983 | + private function _process_wpdb_query($wpdb_method, $arguments_to_provide) { |
|
1984 | 1984 | /** @type WPDB $wpdb */ |
1985 | 1985 | global $wpdb; |
1986 | 1986 | $wpdb->last_error = null; |
1987 | - $result = call_user_func_array( array( $wpdb, $wpdb_method ), $arguments_to_provide ); |
|
1987 | + $result = call_user_func_array(array($wpdb, $wpdb_method), $arguments_to_provide); |
|
1988 | 1988 | // was there an error running the query? but we don't care on new activations |
1989 | 1989 | // (we're going to setup the DB anyway on new activations) |
1990 | - if ( ( $result === false || ! empty( $wpdb->last_error ) ) |
|
1990 | + if (($result === false || ! empty($wpdb->last_error)) |
|
1991 | 1991 | && EE_System::instance()->detect_req_type() !== EE_System::req_type_new_activation |
1992 | 1992 | ) { |
1993 | - switch ( EEM_Base::$_db_verification_level ) { |
|
1993 | + switch (EEM_Base::$_db_verification_level) { |
|
1994 | 1994 | |
1995 | 1995 | case EEM_Base::db_verified_none : |
1996 | 1996 | // let's double-check core's DB |
1997 | - $error_message = $this->_verify_core_db( $wpdb_method, $arguments_to_provide ); |
|
1997 | + $error_message = $this->_verify_core_db($wpdb_method, $arguments_to_provide); |
|
1998 | 1998 | break; |
1999 | 1999 | |
2000 | 2000 | case EEM_Base::db_verified_core : |
2001 | 2001 | // STILL NO LOVE?? verify all the addons too. Maybe they need to be fixed |
2002 | - $error_message = $this->_verify_addons_db( $wpdb_method, $arguments_to_provide ); |
|
2002 | + $error_message = $this->_verify_addons_db($wpdb_method, $arguments_to_provide); |
|
2003 | 2003 | break; |
2004 | 2004 | |
2005 | 2005 | case EEM_Base::db_verified_addons : |
@@ -2007,11 +2007,11 @@ discard block |
||
2007 | 2007 | return $result; |
2008 | 2008 | break; |
2009 | 2009 | } |
2010 | - if ( ! empty( $error_message ) ) { |
|
2011 | - EE_Log::instance()->log( __FILE__, __FUNCTION__, $error_message, 'error' ); |
|
2012 | - trigger_error( $error_message ); |
|
2010 | + if ( ! empty($error_message)) { |
|
2011 | + EE_Log::instance()->log(__FILE__, __FUNCTION__, $error_message, 'error'); |
|
2012 | + trigger_error($error_message); |
|
2013 | 2013 | } |
2014 | - return $this->_process_wpdb_query( $wpdb_method, $arguments_to_provide ); |
|
2014 | + return $this->_process_wpdb_query($wpdb_method, $arguments_to_provide); |
|
2015 | 2015 | |
2016 | 2016 | } |
2017 | 2017 | |
@@ -2027,18 +2027,18 @@ discard block |
||
2027 | 2027 | * @param array $arguments_to_provide |
2028 | 2028 | * @return string |
2029 | 2029 | */ |
2030 | - private function _verify_core_db( $wpdb_method, $arguments_to_provide ){ |
|
2030 | + private function _verify_core_db($wpdb_method, $arguments_to_provide) { |
|
2031 | 2031 | /** @type WPDB $wpdb */ |
2032 | 2032 | global $wpdb; |
2033 | 2033 | //ok remember that we've already attempted fixing the core db, in case the problem persists |
2034 | 2034 | EEM_Base::$_db_verification_level = EEM_Base::db_verified_core; |
2035 | 2035 | $error_message = sprintf( |
2036 | - __( 'WPDB Error "%1$s" while running wpdb method "%2$s" with arguments %3$s. Automatically attempting to fix EE Core DB', 'event_espresso' ), |
|
2036 | + __('WPDB Error "%1$s" while running wpdb method "%2$s" with arguments %3$s. Automatically attempting to fix EE Core DB', 'event_espresso'), |
|
2037 | 2037 | $wpdb->last_error, |
2038 | 2038 | $wpdb_method, |
2039 | - json_encode( $arguments_to_provide ) |
|
2039 | + json_encode($arguments_to_provide) |
|
2040 | 2040 | ); |
2041 | - EE_System::instance()->initialize_db_if_no_migrations_required( false, true ); |
|
2041 | + EE_System::instance()->initialize_db_if_no_migrations_required(false, true); |
|
2042 | 2042 | return $error_message; |
2043 | 2043 | } |
2044 | 2044 | |
@@ -2051,16 +2051,16 @@ discard block |
||
2051 | 2051 | * @param $arguments_to_provide |
2052 | 2052 | * @return string |
2053 | 2053 | */ |
2054 | - private function _verify_addons_db( $wpdb_method, $arguments_to_provide ) { |
|
2054 | + private function _verify_addons_db($wpdb_method, $arguments_to_provide) { |
|
2055 | 2055 | /** @type WPDB $wpdb */ |
2056 | 2056 | global $wpdb; |
2057 | 2057 | //ok remember that we've already attempted fixing the addons dbs, in case the problem persists |
2058 | 2058 | EEM_Base::$_db_verification_level = EEM_Base::db_verified_addons; |
2059 | 2059 | $error_message = sprintf( |
2060 | - __( 'WPDB AGAIN: Error "%1$s" while running the same method and arguments as before. Automatically attempting to fix EE Addons DB', 'event_espresso' ), |
|
2060 | + __('WPDB AGAIN: Error "%1$s" while running the same method and arguments as before. Automatically attempting to fix EE Addons DB', 'event_espresso'), |
|
2061 | 2061 | $wpdb->last_error, |
2062 | 2062 | $wpdb_method, |
2063 | - json_encode( $arguments_to_provide ) |
|
2063 | + json_encode($arguments_to_provide) |
|
2064 | 2064 | ); |
2065 | 2065 | EE_System::instance()->initialize_addons(); |
2066 | 2066 | return $error_message; |
@@ -2075,7 +2075,7 @@ discard block |
||
2075 | 2075 | * @param EE_Model_Query_Info_Carrier $model_query_info |
2076 | 2076 | * @return string |
2077 | 2077 | */ |
2078 | - private function _construct_2nd_half_of_select_query(EE_Model_Query_Info_Carrier $model_query_info){ |
|
2078 | + private function _construct_2nd_half_of_select_query(EE_Model_Query_Info_Carrier $model_query_info) { |
|
2079 | 2079 | return " FROM ".$model_query_info->get_full_join_sql(). |
2080 | 2080 | $model_query_info->get_where_sql(). |
2081 | 2081 | $model_query_info->get_group_by_sql(). |
@@ -2088,7 +2088,7 @@ discard block |
||
2088 | 2088 | * Set to easily debug the next X queries ran from this model. |
2089 | 2089 | * @param int $count |
2090 | 2090 | */ |
2091 | - public function show_next_x_db_queries($count = 1){ |
|
2091 | + public function show_next_x_db_queries($count = 1) { |
|
2092 | 2092 | $this->_show_next_x_db_queries = $count; |
2093 | 2093 | } |
2094 | 2094 | |
@@ -2097,8 +2097,8 @@ discard block |
||
2097 | 2097 | /** |
2098 | 2098 | * @param $sql_query |
2099 | 2099 | */ |
2100 | - public function show_db_query_if_previously_requested($sql_query){ |
|
2101 | - if($this->_show_next_x_db_queries > 0){ |
|
2100 | + public function show_db_query_if_previously_requested($sql_query) { |
|
2101 | + if ($this->_show_next_x_db_queries > 0) { |
|
2102 | 2102 | echo $sql_query; |
2103 | 2103 | $this->_show_next_x_db_queries--; |
2104 | 2104 | } |
@@ -2122,9 +2122,9 @@ discard block |
||
2122 | 2122 | * @return EE_Base_Class which was added as a relation. Object referred to by $other_model_id_or_obj |
2123 | 2123 | * @throws \EE_Error |
2124 | 2124 | */ |
2125 | - public function add_relationship_to($id_or_obj,$other_model_id_or_obj, $relationName, $extra_join_model_fields_n_values = array()){ |
|
2125 | + public function add_relationship_to($id_or_obj, $other_model_id_or_obj, $relationName, $extra_join_model_fields_n_values = array()) { |
|
2126 | 2126 | $relation_obj = $this->related_settings_for($relationName); |
2127 | - return $relation_obj->add_relation_to( $id_or_obj, $other_model_id_or_obj, $extra_join_model_fields_n_values); |
|
2127 | + return $relation_obj->add_relation_to($id_or_obj, $other_model_id_or_obj, $extra_join_model_fields_n_values); |
|
2128 | 2128 | } |
2129 | 2129 | |
2130 | 2130 | |
@@ -2143,9 +2143,9 @@ discard block |
||
2143 | 2143 | * @throws \EE_Error |
2144 | 2144 | * @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. |
2145 | 2145 | */ |
2146 | - public function remove_relationship_to($id_or_obj, $other_model_id_or_obj, $relationName, $where_query= array() ){ |
|
2146 | + public function remove_relationship_to($id_or_obj, $other_model_id_or_obj, $relationName, $where_query = array()) { |
|
2147 | 2147 | $relation_obj = $this->related_settings_for($relationName); |
2148 | - return $relation_obj->remove_relation_to($id_or_obj, $other_model_id_or_obj, $where_query ); |
|
2148 | + return $relation_obj->remove_relation_to($id_or_obj, $other_model_id_or_obj, $where_query); |
|
2149 | 2149 | } |
2150 | 2150 | |
2151 | 2151 | |
@@ -2158,9 +2158,9 @@ discard block |
||
2158 | 2158 | * @return \EE_Base_Class[] |
2159 | 2159 | * @throws \EE_Error |
2160 | 2160 | */ |
2161 | - public function remove_relations($id_or_obj,$relationName,$where_query_params = array()){ |
|
2161 | + public function remove_relations($id_or_obj, $relationName, $where_query_params = array()) { |
|
2162 | 2162 | $relation_obj = $this->related_settings_for($relationName); |
2163 | - return $relation_obj->remove_relations($id_or_obj, $where_query_params ); |
|
2163 | + return $relation_obj->remove_relations($id_or_obj, $where_query_params); |
|
2164 | 2164 | } |
2165 | 2165 | |
2166 | 2166 | |
@@ -2176,10 +2176,10 @@ discard block |
||
2176 | 2176 | * @return EE_Base_Class[] |
2177 | 2177 | * @throws \EE_Error |
2178 | 2178 | */ |
2179 | - public function get_all_related($id_or_obj, $model_name, $query_params = null){ |
|
2179 | + public function get_all_related($id_or_obj, $model_name, $query_params = null) { |
|
2180 | 2180 | $model_obj = $this->ensure_is_obj($id_or_obj); |
2181 | 2181 | $relation_settings = $this->related_settings_for($model_name); |
2182 | - return $relation_settings->get_all_related($model_obj,$query_params); |
|
2182 | + return $relation_settings->get_all_related($model_obj, $query_params); |
|
2183 | 2183 | } |
2184 | 2184 | |
2185 | 2185 | |
@@ -2196,10 +2196,10 @@ discard block |
||
2196 | 2196 | * @return int how many deleted |
2197 | 2197 | * @throws \EE_Error |
2198 | 2198 | */ |
2199 | - public function delete_related($id_or_obj,$model_name, $query_params = array()){ |
|
2199 | + public function delete_related($id_or_obj, $model_name, $query_params = array()) { |
|
2200 | 2200 | $model_obj = $this->ensure_is_obj($id_or_obj); |
2201 | 2201 | $relation_settings = $this->related_settings_for($model_name); |
2202 | - return $relation_settings->delete_all_related($model_obj,$query_params); |
|
2202 | + return $relation_settings->delete_all_related($model_obj, $query_params); |
|
2203 | 2203 | } |
2204 | 2204 | |
2205 | 2205 | |
@@ -2216,10 +2216,10 @@ discard block |
||
2216 | 2216 | * @return int how many deleted |
2217 | 2217 | * @throws \EE_Error |
2218 | 2218 | */ |
2219 | - public function delete_related_permanently($id_or_obj,$model_name, $query_params = array()){ |
|
2219 | + public function delete_related_permanently($id_or_obj, $model_name, $query_params = array()) { |
|
2220 | 2220 | $model_obj = $this->ensure_is_obj($id_or_obj); |
2221 | 2221 | $relation_settings = $this->related_settings_for($model_name); |
2222 | - return $relation_settings->delete_related_permanently($model_obj,$query_params); |
|
2222 | + return $relation_settings->delete_related_permanently($model_obj, $query_params); |
|
2223 | 2223 | } |
2224 | 2224 | |
2225 | 2225 | |
@@ -2236,17 +2236,17 @@ discard block |
||
2236 | 2236 | * @return int |
2237 | 2237 | * @throws \EE_Error |
2238 | 2238 | */ |
2239 | - public function count_related($id_or_obj,$model_name,$query_params = array(),$field_to_count = null, $distinct = FALSE){ |
|
2239 | + public function count_related($id_or_obj, $model_name, $query_params = array(), $field_to_count = null, $distinct = FALSE) { |
|
2240 | 2240 | $related_model = $this->get_related_model_obj($model_name); |
2241 | 2241 | //we're just going to use the query params on the related model's normal get_all query, |
2242 | 2242 | //except add a condition to say to match the current mod |
2243 | - if( ! isset($query_params['default_where_conditions'])){ |
|
2244 | - $query_params['default_where_conditions']='none'; |
|
2243 | + if ( ! isset($query_params['default_where_conditions'])) { |
|
2244 | + $query_params['default_where_conditions'] = 'none'; |
|
2245 | 2245 | } |
2246 | 2246 | $this_model_name = $this->get_this_model_name(); |
2247 | 2247 | $this_pk_field_name = $this->get_primary_key_field()->get_name(); |
2248 | - $query_params[0][$this_model_name.".".$this_pk_field_name]=$id_or_obj; |
|
2249 | - return $related_model->count($query_params,$field_to_count,$distinct); |
|
2248 | + $query_params[0][$this_model_name.".".$this_pk_field_name] = $id_or_obj; |
|
2249 | + return $related_model->count($query_params, $field_to_count, $distinct); |
|
2250 | 2250 | } |
2251 | 2251 | |
2252 | 2252 | |
@@ -2262,21 +2262,21 @@ discard block |
||
2262 | 2262 | * @return float |
2263 | 2263 | * @throws \EE_Error |
2264 | 2264 | */ |
2265 | - public function sum_related($id_or_obj,$model_name,$query_params,$field_to_sum = null){ |
|
2265 | + public function sum_related($id_or_obj, $model_name, $query_params, $field_to_sum = null) { |
|
2266 | 2266 | $related_model = $this->get_related_model_obj($model_name); |
2267 | - if( ! is_array( $query_params ) ){ |
|
2268 | - 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' ); |
|
2267 | + if ( ! is_array($query_params)) { |
|
2268 | + 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'); |
|
2269 | 2269 | $query_params = array(); |
2270 | 2270 | } |
2271 | 2271 | //we're just going to use the query params on the related model's normal get_all query, |
2272 | 2272 | //except add a condition to say to match the current mod |
2273 | - if( ! isset($query_params['default_where_conditions'])){ |
|
2274 | - $query_params['default_where_conditions']='none'; |
|
2273 | + if ( ! isset($query_params['default_where_conditions'])) { |
|
2274 | + $query_params['default_where_conditions'] = 'none'; |
|
2275 | 2275 | } |
2276 | 2276 | $this_model_name = $this->get_this_model_name(); |
2277 | 2277 | $this_pk_field_name = $this->get_primary_key_field()->get_name(); |
2278 | - $query_params[0][$this_model_name.".".$this_pk_field_name]=$id_or_obj; |
|
2279 | - return $related_model->sum($query_params,$field_to_sum); |
|
2278 | + $query_params[0][$this_model_name.".".$this_pk_field_name] = $id_or_obj; |
|
2279 | + return $related_model->sum($query_params, $field_to_sum); |
|
2280 | 2280 | } |
2281 | 2281 | |
2282 | 2282 | |
@@ -2290,12 +2290,12 @@ discard block |
||
2290 | 2290 | * @return EE_Base_Class |
2291 | 2291 | * @throws \EE_Error |
2292 | 2292 | */ |
2293 | - public function get_first_related( EE_Base_Class $id_or_obj, $other_model_name, $query_params ){ |
|
2294 | - $query_params['limit']=1; |
|
2295 | - $results = $this->get_all_related($id_or_obj,$other_model_name,$query_params); |
|
2296 | - if( $results ){ |
|
2293 | + public function get_first_related(EE_Base_Class $id_or_obj, $other_model_name, $query_params) { |
|
2294 | + $query_params['limit'] = 1; |
|
2295 | + $results = $this->get_all_related($id_or_obj, $other_model_name, $query_params); |
|
2296 | + if ($results) { |
|
2297 | 2297 | return array_shift($results); |
2298 | - }else{ |
|
2298 | + } else { |
|
2299 | 2299 | return null; |
2300 | 2300 | } |
2301 | 2301 | |
@@ -2305,8 +2305,8 @@ discard block |
||
2305 | 2305 | * Gets the model's name as it's expected in queries. For example, if this is EEM_Event model, that would be Event |
2306 | 2306 | * @return string |
2307 | 2307 | */ |
2308 | - public function get_this_model_name(){ |
|
2309 | - return str_replace("EEM_","",get_class($this)); |
|
2308 | + public function get_this_model_name() { |
|
2309 | + return str_replace("EEM_", "", get_class($this)); |
|
2310 | 2310 | } |
2311 | 2311 | |
2312 | 2312 | /** |
@@ -2314,14 +2314,14 @@ discard block |
||
2314 | 2314 | * @return EE_Any_Foreign_Model_Name_Field |
2315 | 2315 | * @throws EE_Error |
2316 | 2316 | */ |
2317 | - public function get_field_containing_related_model_name(){ |
|
2318 | - foreach($this->field_settings(true) as $field){ |
|
2319 | - if($field instanceof EE_Any_Foreign_Model_Name_Field){ |
|
2317 | + public function get_field_containing_related_model_name() { |
|
2318 | + foreach ($this->field_settings(true) as $field) { |
|
2319 | + if ($field instanceof EE_Any_Foreign_Model_Name_Field) { |
|
2320 | 2320 | $field_with_model_name = $field; |
2321 | 2321 | } |
2322 | 2322 | } |
2323 | - if( !isset($field_with_model_name) || !$field_with_model_name ){ |
|
2324 | - throw new EE_Error(sprintf(__("There is no EE_Any_Foreign_Model_Name field on model %s", "event_espresso"), $this->get_this_model_name() )); |
|
2323 | + if ( ! isset($field_with_model_name) || ! $field_with_model_name) { |
|
2324 | + throw new EE_Error(sprintf(__("There is no EE_Any_Foreign_Model_Name field on model %s", "event_espresso"), $this->get_this_model_name())); |
|
2325 | 2325 | } |
2326 | 2326 | return $field_with_model_name; |
2327 | 2327 | } |
@@ -2342,19 +2342,19 @@ discard block |
||
2342 | 2342 | * @return int new primary key on main table that got inserted |
2343 | 2343 | * @throws EE_Error |
2344 | 2344 | */ |
2345 | - public function insert($field_n_values){ |
|
2345 | + public function insert($field_n_values) { |
|
2346 | 2346 | /** |
2347 | 2347 | * Filters the fields and their values before inserting an item using the models |
2348 | 2348 | * @param array $fields_n_values keys are the fields and values are their new values |
2349 | 2349 | * @param EEM_Base $model the model used |
2350 | 2350 | */ |
2351 | - $field_n_values = (array)apply_filters( 'FHEE__EEM_Base__insert__fields_n_values', $field_n_values, $this ); |
|
2352 | - if($this->_satisfies_unique_indexes($field_n_values)){ |
|
2351 | + $field_n_values = (array) apply_filters('FHEE__EEM_Base__insert__fields_n_values', $field_n_values, $this); |
|
2352 | + if ($this->_satisfies_unique_indexes($field_n_values)) { |
|
2353 | 2353 | $main_table = $this->_get_main_table(); |
2354 | 2354 | $new_id = $this->_insert_into_specific_table($main_table, $field_n_values, false); |
2355 | - if( $new_id !== false ) { |
|
2356 | - foreach($this->_get_other_tables() as $other_table){ |
|
2357 | - $this->_insert_into_specific_table($other_table, $field_n_values,$new_id); |
|
2355 | + if ($new_id !== false) { |
|
2356 | + foreach ($this->_get_other_tables() as $other_table) { |
|
2357 | + $this->_insert_into_specific_table($other_table, $field_n_values, $new_id); |
|
2358 | 2358 | } |
2359 | 2359 | } |
2360 | 2360 | /** |
@@ -2364,9 +2364,9 @@ discard block |
||
2364 | 2364 | * @param array $fields_n_values fields and their values |
2365 | 2365 | * @param int|string the ID of the newly-inserted model object |
2366 | 2366 | */ |
2367 | - do_action( 'AHEE__EEM_Base__insert__end', $this, $field_n_values, $new_id ); |
|
2367 | + do_action('AHEE__EEM_Base__insert__end', $this, $field_n_values, $new_id); |
|
2368 | 2368 | return $new_id; |
2369 | - }else{ |
|
2369 | + } else { |
|
2370 | 2370 | return FALSE; |
2371 | 2371 | } |
2372 | 2372 | } |
@@ -2381,10 +2381,10 @@ discard block |
||
2381 | 2381 | * @return boolean |
2382 | 2382 | * @throws \EE_Error |
2383 | 2383 | */ |
2384 | - protected function _satisfies_unique_indexes($field_n_values,$action = 'insert'){ |
|
2385 | - foreach($this->unique_indexes() as $index_name => $index){ |
|
2384 | + protected function _satisfies_unique_indexes($field_n_values, $action = 'insert') { |
|
2385 | + foreach ($this->unique_indexes() as $index_name => $index) { |
|
2386 | 2386 | $uniqueness_where_params = array_intersect_key($field_n_values, $index->fields()); |
2387 | - if($this->exists(array($uniqueness_where_params))){ |
|
2387 | + if ($this->exists(array($uniqueness_where_params))) { |
|
2388 | 2388 | EE_Error::add_error( |
2389 | 2389 | sprintf( |
2390 | 2390 | __( |
@@ -2394,8 +2394,8 @@ discard block |
||
2394 | 2394 | $action, |
2395 | 2395 | $this->_get_class_name(), |
2396 | 2396 | $index_name, |
2397 | - implode( ",", $index->field_names() ), |
|
2398 | - http_build_query( $uniqueness_where_params ) |
|
2397 | + implode(",", $index->field_names()), |
|
2398 | + http_build_query($uniqueness_where_params) |
|
2399 | 2399 | ), |
2400 | 2400 | __FILE__, |
2401 | 2401 | __FUNCTION__, |
@@ -2425,37 +2425,37 @@ discard block |
||
2425 | 2425 | * @throws EE_Error |
2426 | 2426 | * @return EE_Base_Class|array |
2427 | 2427 | */ |
2428 | - public function get_one_conflicting($obj_or_fields_array, $include_primary_key = true ){ |
|
2429 | - if($obj_or_fields_array instanceof EE_Base_Class){ |
|
2428 | + public function get_one_conflicting($obj_or_fields_array, $include_primary_key = true) { |
|
2429 | + if ($obj_or_fields_array instanceof EE_Base_Class) { |
|
2430 | 2430 | $fields_n_values = $obj_or_fields_array->model_field_array(); |
2431 | - }elseif( is_array($obj_or_fields_array)){ |
|
2431 | + }elseif (is_array($obj_or_fields_array)) { |
|
2432 | 2432 | $fields_n_values = $obj_or_fields_array; |
2433 | - }else{ |
|
2433 | + } else { |
|
2434 | 2434 | throw new EE_Error( |
2435 | 2435 | sprintf( |
2436 | 2436 | __( |
2437 | 2437 | "%s get_all_conflicting should be called with a model object or an array of field names and values, you provided %d", |
2438 | 2438 | "event_espresso" |
2439 | 2439 | ), |
2440 | - get_class( $this ), |
|
2440 | + get_class($this), |
|
2441 | 2441 | $obj_or_fields_array |
2442 | 2442 | ) |
2443 | 2443 | ); |
2444 | 2444 | } |
2445 | 2445 | $query_params = array(); |
2446 | - if( $this->has_primary_key_field() && |
|
2447 | - ( $include_primary_key || $this->get_primary_key_field() instanceof EE_Primary_Key_String_Field) && |
|
2448 | - isset($fields_n_values[$this->primary_key_name()])){ |
|
2446 | + if ($this->has_primary_key_field() && |
|
2447 | + ($include_primary_key || $this->get_primary_key_field() instanceof EE_Primary_Key_String_Field) && |
|
2448 | + isset($fields_n_values[$this->primary_key_name()])) { |
|
2449 | 2449 | $query_params[0]['OR'][$this->primary_key_name()] = $fields_n_values[$this->primary_key_name()]; |
2450 | 2450 | } |
2451 | - foreach($this->unique_indexes() as $unique_index_name=>$unique_index){ |
|
2451 | + foreach ($this->unique_indexes() as $unique_index_name=>$unique_index) { |
|
2452 | 2452 | $uniqueness_where_params = array_intersect_key($fields_n_values, $unique_index->fields()); |
2453 | 2453 | $query_params[0]['OR']['AND*'.$unique_index_name] = $uniqueness_where_params; |
2454 | 2454 | } |
2455 | 2455 | //if there is nothing to base this search on, then we shouldn't find anything |
2456 | - if( empty( $query_params ) ){ |
|
2456 | + if (empty($query_params)) { |
|
2457 | 2457 | return array(); |
2458 | - }else{ |
|
2458 | + } else { |
|
2459 | 2459 | return $this->get_one($query_params); |
2460 | 2460 | } |
2461 | 2461 | } |
@@ -2469,7 +2469,7 @@ discard block |
||
2469 | 2469 | * @return boolean |
2470 | 2470 | * @throws \EE_Error |
2471 | 2471 | */ |
2472 | - public function exists($query_params){ |
|
2472 | + public function exists($query_params) { |
|
2473 | 2473 | $query_params['limit'] = 1; |
2474 | 2474 | return $this->count($query_params) > 0; |
2475 | 2475 | } |
@@ -2483,7 +2483,7 @@ discard block |
||
2483 | 2483 | * @return boolean |
2484 | 2484 | * @throws \EE_Error |
2485 | 2485 | */ |
2486 | - public function exists_by_ID($id){ |
|
2486 | + public function exists_by_ID($id) { |
|
2487 | 2487 | return $this->exists(array('default_where_conditions'=>'none', array($this->primary_key_name() => $id))); |
2488 | 2488 | } |
2489 | 2489 | |
@@ -2503,45 +2503,45 @@ discard block |
||
2503 | 2503 | * @global WPDB $wpdb only used to get the $wpdb->insert_id after performing an insert |
2504 | 2504 | * @return int ID of new row inserted, or FALSE on failure |
2505 | 2505 | */ |
2506 | - protected function _insert_into_specific_table(EE_Table_Base $table, $fields_n_values, $new_id = 0 ){ |
|
2506 | + protected function _insert_into_specific_table(EE_Table_Base $table, $fields_n_values, $new_id = 0) { |
|
2507 | 2507 | global $wpdb; |
2508 | 2508 | $insertion_col_n_values = array(); |
2509 | 2509 | $format_for_insertion = array(); |
2510 | 2510 | $fields_on_table = $this->_get_fields_for_table($table->get_table_alias()); |
2511 | - foreach($fields_on_table as $field_name => $field_obj){ |
|
2511 | + foreach ($fields_on_table as $field_name => $field_obj) { |
|
2512 | 2512 | //check if its an auto-incrementing column, in which case we should just leave it to do its autoincrement thing |
2513 | - if($field_obj->is_auto_increment()){ |
|
2513 | + if ($field_obj->is_auto_increment()) { |
|
2514 | 2514 | continue; |
2515 | 2515 | } |
2516 | 2516 | $prepared_value = $this->_prepare_value_or_use_default($field_obj, $fields_n_values); |
2517 | 2517 | //if the value we want to assign it to is NULL, just don't mention it for the insertion |
2518 | - if( $prepared_value !== NULL ){ |
|
2519 | - $insertion_col_n_values[ $field_obj->get_table_column() ] = $prepared_value; |
|
2518 | + if ($prepared_value !== NULL) { |
|
2519 | + $insertion_col_n_values[$field_obj->get_table_column()] = $prepared_value; |
|
2520 | 2520 | $format_for_insertion[] = $field_obj->get_wpdb_data_type(); |
2521 | 2521 | } |
2522 | 2522 | } |
2523 | 2523 | |
2524 | - if($table instanceof EE_Secondary_Table && $new_id){ |
|
2524 | + if ($table instanceof EE_Secondary_Table && $new_id) { |
|
2525 | 2525 | //its not the main table, so we should have already saved the main table's PK which we just inserted |
2526 | 2526 | //so add the fk to the main table as a column |
2527 | 2527 | $insertion_col_n_values[$table->get_fk_on_table()] = $new_id; |
2528 | - $format_for_insertion[]='%d';//yes right now we're only allowing these foreign keys to be INTs |
|
2528 | + $format_for_insertion[] = '%d'; //yes right now we're only allowing these foreign keys to be INTs |
|
2529 | 2529 | } |
2530 | 2530 | //insert the new entry |
2531 | - $result = $this->_do_wpdb_query( 'insert', array( $table->get_table_name(), $insertion_col_n_values, $format_for_insertion ) ); |
|
2532 | - if( $result === false ) { |
|
2531 | + $result = $this->_do_wpdb_query('insert', array($table->get_table_name(), $insertion_col_n_values, $format_for_insertion)); |
|
2532 | + if ($result === false) { |
|
2533 | 2533 | return false; |
2534 | 2534 | } |
2535 | 2535 | //ok, now what do we return for the ID of the newly-inserted thing? |
2536 | - if($this->has_primary_key_field()){ |
|
2537 | - if($this->get_primary_key_field()->is_auto_increment()){ |
|
2536 | + if ($this->has_primary_key_field()) { |
|
2537 | + if ($this->get_primary_key_field()->is_auto_increment()) { |
|
2538 | 2538 | return $wpdb->insert_id; |
2539 | - }else{ |
|
2539 | + } else { |
|
2540 | 2540 | //it's not an auto-increment primary key, so |
2541 | 2541 | //it must have been supplied |
2542 | 2542 | return $fields_n_values[$this->get_primary_key_field()->get_name()]; |
2543 | 2543 | } |
2544 | - }else{ |
|
2544 | + } else { |
|
2545 | 2545 | //we can't return a primary key because there is none. instead return |
2546 | 2546 | //a unique string indicating this model |
2547 | 2547 | return $this->get_index_primary_key_string($fields_n_values); |
@@ -2560,15 +2560,15 @@ discard block |
||
2560 | 2560 | * @return mixed string|int|float depending on what the table column will be expecting |
2561 | 2561 | * @throws \EE_Error |
2562 | 2562 | */ |
2563 | - protected function _prepare_value_or_use_default( $field_obj, $fields_n_values ){ |
|
2563 | + protected function _prepare_value_or_use_default($field_obj, $fields_n_values) { |
|
2564 | 2564 | //if this field doesn't allow nullable, don't allow it |
2565 | - if( ! $field_obj->is_nullable() && ( |
|
2566 | - ! isset( $fields_n_values[ $field_obj->get_name() ] ) || |
|
2567 | - $fields_n_values[ $field_obj->get_name() ] === NULL ) ){ |
|
2568 | - $fields_n_values[ $field_obj->get_name() ] = $field_obj->get_default_value(); |
|
2565 | + if ( ! $field_obj->is_nullable() && ( |
|
2566 | + ! isset($fields_n_values[$field_obj->get_name()]) || |
|
2567 | + $fields_n_values[$field_obj->get_name()] === NULL )) { |
|
2568 | + $fields_n_values[$field_obj->get_name()] = $field_obj->get_default_value(); |
|
2569 | 2569 | } |
2570 | - $unprepared_value = isset( $fields_n_values[ $field_obj->get_name() ] ) ? $fields_n_values[ $field_obj->get_name() ] : NULL; |
|
2571 | - return $this->_prepare_value_for_use_in_db( $unprepared_value, $field_obj); |
|
2570 | + $unprepared_value = isset($fields_n_values[$field_obj->get_name()]) ? $fields_n_values[$field_obj->get_name()] : NULL; |
|
2571 | + return $this->_prepare_value_for_use_in_db($unprepared_value, $field_obj); |
|
2572 | 2572 | } |
2573 | 2573 | |
2574 | 2574 | |
@@ -2580,9 +2580,9 @@ discard block |
||
2580 | 2580 | * @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 |
2581 | 2581 | * @return mixed a value ready for use in the database for insertions, updating, or in a where clause |
2582 | 2582 | */ |
2583 | - private function _prepare_value_for_use_in_db($value, $field){ |
|
2584 | - if($field && $field instanceof EE_Model_Field_Base){ |
|
2585 | - switch( $this->_values_already_prepared_by_model_object ){ |
|
2583 | + private function _prepare_value_for_use_in_db($value, $field) { |
|
2584 | + if ($field && $field instanceof EE_Model_Field_Base) { |
|
2585 | + switch ($this->_values_already_prepared_by_model_object) { |
|
2586 | 2586 | /** @noinspection PhpMissingBreakStatementInspection */ |
2587 | 2587 | case self::not_prepared_by_model_object: |
2588 | 2588 | $value = $field->prepare_for_set($value); |
@@ -2593,7 +2593,7 @@ discard block |
||
2593 | 2593 | //leave the value alone |
2594 | 2594 | } |
2595 | 2595 | return $value; |
2596 | - }else{ |
|
2596 | + } else { |
|
2597 | 2597 | return $value; |
2598 | 2598 | } |
2599 | 2599 | } |
@@ -2603,13 +2603,13 @@ discard block |
||
2603 | 2603 | * @return EE_Primary_Table |
2604 | 2604 | * @throws EE_Error |
2605 | 2605 | */ |
2606 | - protected function _get_main_table(){ |
|
2607 | - foreach($this->_tables as $table){ |
|
2608 | - if($table instanceof EE_Primary_Table){ |
|
2606 | + protected function _get_main_table() { |
|
2607 | + foreach ($this->_tables as $table) { |
|
2608 | + if ($table instanceof EE_Primary_Table) { |
|
2609 | 2609 | return $table; |
2610 | 2610 | } |
2611 | 2611 | } |
2612 | - 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))); |
|
2612 | + 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))); |
|
2613 | 2613 | } |
2614 | 2614 | |
2615 | 2615 | |
@@ -2632,7 +2632,7 @@ discard block |
||
2632 | 2632 | */ |
2633 | 2633 | public function second_table() { |
2634 | 2634 | // grab second table from tables array |
2635 | - $second_table = end( $this->_tables ); |
|
2635 | + $second_table = end($this->_tables); |
|
2636 | 2636 | return $second_table instanceof EE_Secondary_Table ? $second_table->get_table_name() : NULL; |
2637 | 2637 | } |
2638 | 2638 | |
@@ -2645,8 +2645,8 @@ discard block |
||
2645 | 2645 | * @param string $table_alias |
2646 | 2646 | * @return EE_Primary_Table | EE_Secondary_Table |
2647 | 2647 | */ |
2648 | - public function get_table_obj_by_alias( $table_alias = '' ) { |
|
2649 | - return isset( $this->_tables[ $table_alias ] ) ? $this->_tables[ $table_alias ] : NULL; |
|
2648 | + public function get_table_obj_by_alias($table_alias = '') { |
|
2649 | + return isset($this->_tables[$table_alias]) ? $this->_tables[$table_alias] : NULL; |
|
2650 | 2650 | } |
2651 | 2651 | |
2652 | 2652 | |
@@ -2655,10 +2655,10 @@ discard block |
||
2655 | 2655 | * Gets all the tables of type EE_Other_Table from EEM_CPT_Basel_Model::_tables |
2656 | 2656 | * @return EE_Secondary_Table[] |
2657 | 2657 | */ |
2658 | - protected function _get_other_tables(){ |
|
2659 | - $other_tables =array(); |
|
2660 | - foreach($this->_tables as $table_alias => $table){ |
|
2661 | - if($table instanceof EE_Secondary_Table){ |
|
2658 | + protected function _get_other_tables() { |
|
2659 | + $other_tables = array(); |
|
2660 | + foreach ($this->_tables as $table_alias => $table) { |
|
2661 | + if ($table instanceof EE_Secondary_Table) { |
|
2662 | 2662 | $other_tables[$table_alias] = $table; |
2663 | 2663 | } |
2664 | 2664 | } |
@@ -2670,7 +2670,7 @@ discard block |
||
2670 | 2670 | * @param string $table_alias, array key in EEM_Base::_tables |
2671 | 2671 | * @return EE_Model_Field_Base[] |
2672 | 2672 | */ |
2673 | - public function _get_fields_for_table($table_alias){ |
|
2673 | + public function _get_fields_for_table($table_alias) { |
|
2674 | 2674 | return $this->_fields[$table_alias]; |
2675 | 2675 | } |
2676 | 2676 | |
@@ -2686,19 +2686,19 @@ discard block |
||
2686 | 2686 | * @return EE_Model_Query_Info_Carrier |
2687 | 2687 | * @throws \EE_Error |
2688 | 2688 | */ |
2689 | - public function _extract_related_models_from_query($query_params){ |
|
2689 | + public function _extract_related_models_from_query($query_params) { |
|
2690 | 2690 | $query_info_carrier = new EE_Model_Query_Info_Carrier(); |
2691 | - if ( array_key_exists( 0, $query_params ) ) { |
|
2692 | - $this->_extract_related_models_from_sub_params_array_keys( $query_params[0], $query_info_carrier, 0 ); |
|
2691 | + if (array_key_exists(0, $query_params)) { |
|
2692 | + $this->_extract_related_models_from_sub_params_array_keys($query_params[0], $query_info_carrier, 0); |
|
2693 | 2693 | } |
2694 | - if ( array_key_exists( 'group_by', $query_params ) ) { |
|
2695 | - if ( is_array( $query_params['group_by'] ) ) { |
|
2694 | + if (array_key_exists('group_by', $query_params)) { |
|
2695 | + if (is_array($query_params['group_by'])) { |
|
2696 | 2696 | $this->_extract_related_models_from_sub_params_array_values( |
2697 | 2697 | $query_params['group_by'], |
2698 | 2698 | $query_info_carrier, |
2699 | 2699 | 'group_by' |
2700 | 2700 | ); |
2701 | - } elseif ( ! empty ( $query_params['group_by'] ) ) { |
|
2701 | + } elseif ( ! empty ($query_params['group_by'])) { |
|
2702 | 2702 | $this->_extract_related_model_info_from_query_param( |
2703 | 2703 | $query_params['group_by'], |
2704 | 2704 | $query_info_carrier, |
@@ -2706,21 +2706,21 @@ discard block |
||
2706 | 2706 | ); |
2707 | 2707 | } |
2708 | 2708 | } |
2709 | - if ( array_key_exists( 'having', $query_params ) ) { |
|
2709 | + if (array_key_exists('having', $query_params)) { |
|
2710 | 2710 | $this->_extract_related_models_from_sub_params_array_keys( |
2711 | 2711 | $query_params[0], |
2712 | 2712 | $query_info_carrier, |
2713 | 2713 | 'having' |
2714 | 2714 | ); |
2715 | 2715 | } |
2716 | - if ( array_key_exists( 'order_by', $query_params ) ) { |
|
2717 | - if ( is_array( $query_params['order_by'] ) ) { |
|
2716 | + if (array_key_exists('order_by', $query_params)) { |
|
2717 | + if (is_array($query_params['order_by'])) { |
|
2718 | 2718 | $this->_extract_related_models_from_sub_params_array_keys( |
2719 | 2719 | $query_params['order_by'], |
2720 | 2720 | $query_info_carrier, |
2721 | 2721 | 'order_by' |
2722 | 2722 | ); |
2723 | - } elseif ( ! empty( $query_params['order_by'] ) ) { |
|
2723 | + } elseif ( ! empty($query_params['order_by'])) { |
|
2724 | 2724 | $this->_extract_related_model_info_from_query_param( |
2725 | 2725 | $query_params['order_by'], |
2726 | 2726 | $query_info_carrier, |
@@ -2728,7 +2728,7 @@ discard block |
||
2728 | 2728 | ); |
2729 | 2729 | } |
2730 | 2730 | } |
2731 | - if ( array_key_exists( 'force_join', $query_params ) ) { |
|
2731 | + if (array_key_exists('force_join', $query_params)) { |
|
2732 | 2732 | $this->_extract_related_models_from_sub_params_array_values( |
2733 | 2733 | $query_params['force_join'], |
2734 | 2734 | $query_info_carrier, |
@@ -2746,34 +2746,34 @@ discard block |
||
2746 | 2746 | * @throws EE_Error |
2747 | 2747 | * @return \EE_Model_Query_Info_Carrier |
2748 | 2748 | */ |
2749 | - 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){ |
|
2750 | - if (!empty($sub_query_params)){ |
|
2749 | + 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) { |
|
2750 | + if ( ! empty($sub_query_params)) { |
|
2751 | 2751 | $sub_query_params = (array) $sub_query_params; |
2752 | - foreach($sub_query_params as $param => $possibly_array_of_params){ |
|
2752 | + foreach ($sub_query_params as $param => $possibly_array_of_params) { |
|
2753 | 2753 | //$param could be simply 'EVT_ID', or it could be 'Registrations.REG_ID', or even 'Registrations.Transactions.Payments.PAY_amount' |
2754 | - $this->_extract_related_model_info_from_query_param( $param, $model_query_info_carrier,$query_param_type); |
|
2754 | + $this->_extract_related_model_info_from_query_param($param, $model_query_info_carrier, $query_param_type); |
|
2755 | 2755 | |
2756 | 2756 | //if $possibly_array_of_params is an array, try recursing into it, searching for keys which |
2757 | 2757 | //indicate needed joins. Eg, array('NOT'=>array('Registration.TXN_ID'=>23)). In this case, we tried |
2758 | 2758 | //extracting models out of the 'NOT', which obviously wasn't successful, and then we recurse into the value |
2759 | 2759 | //of array('Registration.TXN_ID'=>23) |
2760 | 2760 | $query_param_sans_stars = $this->_remove_stars_and_anything_after_from_condition_query_param_key($param); |
2761 | - if(in_array($query_param_sans_stars, $this->_logic_query_param_keys,true)){ |
|
2762 | - if (! is_array($possibly_array_of_params)){ |
|
2761 | + if (in_array($query_param_sans_stars, $this->_logic_query_param_keys, true)) { |
|
2762 | + if ( ! is_array($possibly_array_of_params)) { |
|
2763 | 2763 | 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"), |
2764 | - $param,$possibly_array_of_params)); |
|
2765 | - }else{ |
|
2766 | - $this->_extract_related_models_from_sub_params_array_keys($possibly_array_of_params, $model_query_info_carrier,$query_param_type); |
|
2764 | + $param, $possibly_array_of_params)); |
|
2765 | + } else { |
|
2766 | + $this->_extract_related_models_from_sub_params_array_keys($possibly_array_of_params, $model_query_info_carrier, $query_param_type); |
|
2767 | 2767 | } |
2768 | - }elseif($query_param_type === 0 //ie WHERE |
|
2768 | + }elseif ($query_param_type === 0 //ie WHERE |
|
2769 | 2769 | && is_array($possibly_array_of_params) |
2770 | 2770 | && isset($possibly_array_of_params[2]) |
2771 | - && $possibly_array_of_params[2] == true){ |
|
2771 | + && $possibly_array_of_params[2] == true) { |
|
2772 | 2772 | //then $possible_array_of_params looks something like array('<','DTT_sold',true) |
2773 | 2773 | //indicating that $possible_array_of_params[1] is actually a field name, |
2774 | 2774 | //from which we should extract query parameters! |
2775 | - if( ! isset($possibly_array_of_params[0], $possibly_array_of_params[1] ) ) { |
|
2776 | - 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))); |
|
2775 | + if ( ! isset($possibly_array_of_params[0], $possibly_array_of_params[1])) { |
|
2776 | + 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))); |
|
2777 | 2777 | } |
2778 | 2778 | $this->_extract_related_model_info_from_query_param($possibly_array_of_params[1], $model_query_info_carrier, $query_param_type); |
2779 | 2779 | } |
@@ -2792,14 +2792,14 @@ discard block |
||
2792 | 2792 | * @throws EE_Error |
2793 | 2793 | * @return \EE_Model_Query_Info_Carrier |
2794 | 2794 | */ |
2795 | - 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){ |
|
2796 | - if (!empty($sub_query_params)){ |
|
2797 | - if(!is_array($sub_query_params)){ |
|
2798 | - throw new EE_Error(sprintf(__("Query parameter %s should be an array, but it isn't.", "event_espresso"),$sub_query_params)); |
|
2795 | + 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) { |
|
2796 | + if ( ! empty($sub_query_params)) { |
|
2797 | + if ( ! is_array($sub_query_params)) { |
|
2798 | + throw new EE_Error(sprintf(__("Query parameter %s should be an array, but it isn't.", "event_espresso"), $sub_query_params)); |
|
2799 | 2799 | } |
2800 | - foreach($sub_query_params as $param){ |
|
2800 | + foreach ($sub_query_params as $param) { |
|
2801 | 2801 | //$param could be simply 'EVT_ID', or it could be 'Registrations.REG_ID', or even 'Registrations.Transactions.Payments.PAY_amount' |
2802 | - $this->_extract_related_model_info_from_query_param( $param, $model_query_info_carrier, $query_param_type); |
|
2802 | + $this->_extract_related_model_info_from_query_param($param, $model_query_info_carrier, $query_param_type); |
|
2803 | 2803 | } |
2804 | 2804 | } |
2805 | 2805 | return $model_query_info_carrier; |
@@ -2818,8 +2818,8 @@ discard block |
||
2818 | 2818 | * @throws EE_Error |
2819 | 2819 | * @return EE_Model_Query_Info_Carrier |
2820 | 2820 | */ |
2821 | - public function _create_model_query_info_carrier($query_params){ |
|
2822 | - if ( ! is_array( $query_params ) ) { |
|
2821 | + public function _create_model_query_info_carrier($query_params) { |
|
2822 | + if ( ! is_array($query_params)) { |
|
2823 | 2823 | EE_Error::doing_it_wrong( |
2824 | 2824 | 'EEM_Base::_create_model_query_info_carrier', |
2825 | 2825 | sprintf( |
@@ -2827,16 +2827,16 @@ discard block |
||
2827 | 2827 | '$query_params should be an array, you passed a variable of type %s', |
2828 | 2828 | 'event_espresso' |
2829 | 2829 | ), |
2830 | - gettype( $query_params ) |
|
2830 | + gettype($query_params) |
|
2831 | 2831 | ), |
2832 | 2832 | '4.6.0' |
2833 | 2833 | ); |
2834 | 2834 | $query_params = array(); |
2835 | 2835 | } |
2836 | - $where_query_params = isset( $query_params[0] ) ? $query_params[0] : array(); |
|
2836 | + $where_query_params = isset($query_params[0]) ? $query_params[0] : array(); |
|
2837 | 2837 | //first check if we should alter the query to account for caps or not |
2838 | 2838 | //because the caps might require us to do extra joins |
2839 | - if ( isset( $query_params['caps'] ) && $query_params['caps'] !== 'none' ) { |
|
2839 | + if (isset($query_params['caps']) && $query_params['caps'] !== 'none') { |
|
2840 | 2840 | $query_params[0] = $where_query_params = array_replace_recursive( |
2841 | 2841 | $where_query_params, |
2842 | 2842 | $this->caps_where_conditions( |
@@ -2844,10 +2844,10 @@ discard block |
||
2844 | 2844 | ) |
2845 | 2845 | ); |
2846 | 2846 | } |
2847 | - $query_object = $this->_extract_related_models_from_query( $query_params ); |
|
2847 | + $query_object = $this->_extract_related_models_from_query($query_params); |
|
2848 | 2848 | //verify where_query_params has NO numeric indexes.... that's simply not how you use it! |
2849 | - foreach ( $where_query_params as $key => $value ) { |
|
2850 | - if ( is_int( $key ) ) { |
|
2849 | + foreach ($where_query_params as $key => $value) { |
|
2850 | + if (is_int($key)) { |
|
2851 | 2851 | throw new EE_Error( |
2852 | 2852 | sprintf( |
2853 | 2853 | __( |
@@ -2855,16 +2855,16 @@ discard block |
||
2855 | 2855 | "event_espresso" |
2856 | 2856 | ), |
2857 | 2857 | $key, |
2858 | - var_export( $value, true ), |
|
2859 | - var_export( $query_params, true ), |
|
2860 | - get_class( $this ) |
|
2858 | + var_export($value, true), |
|
2859 | + var_export($query_params, true), |
|
2860 | + get_class($this) |
|
2861 | 2861 | ) |
2862 | 2862 | ); |
2863 | 2863 | } |
2864 | 2864 | } |
2865 | 2865 | if ( |
2866 | - array_key_exists( 'default_where_conditions', $query_params ) |
|
2867 | - && ! empty( $query_params['default_where_conditions'] ) |
|
2866 | + array_key_exists('default_where_conditions', $query_params) |
|
2867 | + && ! empty($query_params['default_where_conditions']) |
|
2868 | 2868 | ) { |
2869 | 2869 | $use_default_where_conditions = $query_params['default_where_conditions']; |
2870 | 2870 | } else { |
@@ -2878,13 +2878,13 @@ discard block |
||
2878 | 2878 | ), |
2879 | 2879 | $where_query_params |
2880 | 2880 | ); |
2881 | - $query_object->set_where_sql( $this->_construct_where_clause( $where_query_params ) ); |
|
2881 | + $query_object->set_where_sql($this->_construct_where_clause($where_query_params)); |
|
2882 | 2882 | // if this is a "on_join_limit" then we are limiting on on a specific table in a multi_table join. |
2883 | 2883 | // So we need to setup a subquery and use that for the main join. |
2884 | 2884 | // Note for now this only works on the primary table for the model. |
2885 | 2885 | // So for instance, you could set the limit array like this: |
2886 | 2886 | // array( 'on_join_limit' => array('Primary_Table_Alias', array(1,10) ) ) |
2887 | - if ( array_key_exists( 'on_join_limit', $query_params ) && ! empty( $query_params['on_join_limit'] ) ) { |
|
2887 | + if (array_key_exists('on_join_limit', $query_params) && ! empty($query_params['on_join_limit'])) { |
|
2888 | 2888 | $query_object->set_main_model_join_sql( |
2889 | 2889 | $this->_construct_limit_join_select( |
2890 | 2890 | $query_params['on_join_limit'][0], |
@@ -2893,40 +2893,40 @@ discard block |
||
2893 | 2893 | ); |
2894 | 2894 | } |
2895 | 2895 | //set limit |
2896 | - if ( array_key_exists( 'limit', $query_params ) ) { |
|
2897 | - if ( is_array( $query_params['limit'] ) ) { |
|
2898 | - if ( ! isset( $query_params['limit'][0], $query_params['limit'][1] ) ) { |
|
2896 | + if (array_key_exists('limit', $query_params)) { |
|
2897 | + if (is_array($query_params['limit'])) { |
|
2898 | + if ( ! isset($query_params['limit'][0], $query_params['limit'][1])) { |
|
2899 | 2899 | $e = sprintf( |
2900 | 2900 | __( |
2901 | 2901 | "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)", |
2902 | 2902 | "event_espresso" |
2903 | 2903 | ), |
2904 | - http_build_query( $query_params['limit'] ) |
|
2904 | + http_build_query($query_params['limit']) |
|
2905 | 2905 | ); |
2906 | - throw new EE_Error( $e . "|" . $e ); |
|
2906 | + throw new EE_Error($e."|".$e); |
|
2907 | 2907 | } |
2908 | 2908 | //they passed us an array for the limit. Assume it's like array(50,25), meaning offset by 50, and get 25 |
2909 | - $query_object->set_limit_sql( " LIMIT " . $query_params['limit'][0] . "," . $query_params['limit'][1] ); |
|
2910 | - } elseif ( ! empty ( $query_params['limit'] ) ) { |
|
2911 | - $query_object->set_limit_sql( " LIMIT " . $query_params['limit'] ); |
|
2909 | + $query_object->set_limit_sql(" LIMIT ".$query_params['limit'][0].",".$query_params['limit'][1]); |
|
2910 | + } elseif ( ! empty ($query_params['limit'])) { |
|
2911 | + $query_object->set_limit_sql(" LIMIT ".$query_params['limit']); |
|
2912 | 2912 | } |
2913 | 2913 | } |
2914 | 2914 | //set order by |
2915 | - if ( array_key_exists( 'order_by', $query_params ) ) { |
|
2916 | - if ( is_array( $query_params['order_by'] ) ) { |
|
2915 | + if (array_key_exists('order_by', $query_params)) { |
|
2916 | + if (is_array($query_params['order_by'])) { |
|
2917 | 2917 | //if they're using 'order_by' as an array, they can't use 'order' (because 'order_by' must |
2918 | 2918 | //specify whether to ascend or descend on each field. Eg 'order_by'=>array('EVT_ID'=>'ASC'). So |
2919 | 2919 | //including 'order' wouldn't make any sense if 'order_by' has already specified which way to order! |
2920 | - if ( array_key_exists( 'order', $query_params ) ) { |
|
2920 | + if (array_key_exists('order', $query_params)) { |
|
2921 | 2921 | throw new EE_Error( |
2922 | 2922 | sprintf( |
2923 | 2923 | __( |
2924 | 2924 | "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 ", |
2925 | 2925 | "event_espresso" |
2926 | 2926 | ), |
2927 | - get_class( $this ), |
|
2928 | - implode( ", ", array_keys( $query_params['order_by'] ) ), |
|
2929 | - implode( ", ", $query_params['order_by'] ), |
|
2927 | + get_class($this), |
|
2928 | + implode(", ", array_keys($query_params['order_by'])), |
|
2929 | + implode(", ", $query_params['order_by']), |
|
2930 | 2930 | $query_params['order'] |
2931 | 2931 | ) |
2932 | 2932 | ); |
@@ -2938,57 +2938,57 @@ discard block |
||
2938 | 2938 | ); |
2939 | 2939 | //assume it's an array of fields to order by |
2940 | 2940 | $order_array = array(); |
2941 | - foreach ( $query_params['order_by'] as $field_name_to_order_by => $order ) { |
|
2942 | - $order = $this->_extract_order( $order ); |
|
2943 | - $order_array[] = $this->_deduce_column_name_from_query_param( $field_name_to_order_by ) . SP . $order; |
|
2941 | + foreach ($query_params['order_by'] as $field_name_to_order_by => $order) { |
|
2942 | + $order = $this->_extract_order($order); |
|
2943 | + $order_array[] = $this->_deduce_column_name_from_query_param($field_name_to_order_by).SP.$order; |
|
2944 | 2944 | } |
2945 | - $query_object->set_order_by_sql( " ORDER BY " . implode( ",", $order_array ) ); |
|
2946 | - } elseif ( ! empty ( $query_params['order_by'] ) ) { |
|
2945 | + $query_object->set_order_by_sql(" ORDER BY ".implode(",", $order_array)); |
|
2946 | + } elseif ( ! empty ($query_params['order_by'])) { |
|
2947 | 2947 | $this->_extract_related_model_info_from_query_param( |
2948 | 2948 | $query_params['order_by'], |
2949 | 2949 | $query_object, |
2950 | 2950 | 'order', |
2951 | 2951 | $query_params['order_by'] |
2952 | 2952 | ); |
2953 | - $order = isset( $query_params['order'] ) |
|
2954 | - ? $this->_extract_order( $query_params['order'] ) |
|
2953 | + $order = isset($query_params['order']) |
|
2954 | + ? $this->_extract_order($query_params['order']) |
|
2955 | 2955 | : 'DESC'; |
2956 | 2956 | $query_object->set_order_by_sql( |
2957 | - " ORDER BY " . $this->_deduce_column_name_from_query_param( $query_params['order_by'] ) . SP . $order |
|
2957 | + " ORDER BY ".$this->_deduce_column_name_from_query_param($query_params['order_by']).SP.$order |
|
2958 | 2958 | ); |
2959 | 2959 | } |
2960 | 2960 | } |
2961 | 2961 | //if 'order_by' wasn't set, maybe they are just using 'order' on its own? |
2962 | - if ( ! array_key_exists( 'order_by', $query_params ) |
|
2963 | - && array_key_exists( 'order', $query_params ) |
|
2964 | - && ! empty( $query_params['order'] ) |
|
2962 | + if ( ! array_key_exists('order_by', $query_params) |
|
2963 | + && array_key_exists('order', $query_params) |
|
2964 | + && ! empty($query_params['order']) |
|
2965 | 2965 | ) { |
2966 | 2966 | $pk_field = $this->get_primary_key_field(); |
2967 | - $order = $this->_extract_order( $query_params['order'] ); |
|
2968 | - $query_object->set_order_by_sql( " ORDER BY " . $pk_field->get_qualified_column() . SP . $order ); |
|
2967 | + $order = $this->_extract_order($query_params['order']); |
|
2968 | + $query_object->set_order_by_sql(" ORDER BY ".$pk_field->get_qualified_column().SP.$order); |
|
2969 | 2969 | } |
2970 | 2970 | //set group by |
2971 | - if ( array_key_exists( 'group_by', $query_params ) ) { |
|
2972 | - if ( is_array( $query_params['group_by'] ) ) { |
|
2971 | + if (array_key_exists('group_by', $query_params)) { |
|
2972 | + if (is_array($query_params['group_by'])) { |
|
2973 | 2973 | //it's an array, so assume we'll be grouping by a bunch of stuff |
2974 | 2974 | $group_by_array = array(); |
2975 | - foreach ( $query_params['group_by'] as $field_name_to_group_by ) { |
|
2976 | - $group_by_array[] = $this->_deduce_column_name_from_query_param( $field_name_to_group_by ); |
|
2975 | + foreach ($query_params['group_by'] as $field_name_to_group_by) { |
|
2976 | + $group_by_array[] = $this->_deduce_column_name_from_query_param($field_name_to_group_by); |
|
2977 | 2977 | } |
2978 | - $query_object->set_group_by_sql( " GROUP BY " . implode( ", ", $group_by_array ) ); |
|
2979 | - } elseif ( ! empty ( $query_params['group_by'] ) ) { |
|
2978 | + $query_object->set_group_by_sql(" GROUP BY ".implode(", ", $group_by_array)); |
|
2979 | + } elseif ( ! empty ($query_params['group_by'])) { |
|
2980 | 2980 | $query_object->set_group_by_sql( |
2981 | - " GROUP BY " . $this->_deduce_column_name_from_query_param( $query_params['group_by'] ) |
|
2981 | + " GROUP BY ".$this->_deduce_column_name_from_query_param($query_params['group_by']) |
|
2982 | 2982 | ); |
2983 | 2983 | } |
2984 | 2984 | } |
2985 | 2985 | //set having |
2986 | - if ( array_key_exists( 'having', $query_params ) && $query_params['having'] ) { |
|
2987 | - $query_object->set_having_sql( $this->_construct_having_clause( $query_params['having'] ) ); |
|
2986 | + if (array_key_exists('having', $query_params) && $query_params['having']) { |
|
2987 | + $query_object->set_having_sql($this->_construct_having_clause($query_params['having'])); |
|
2988 | 2988 | } |
2989 | 2989 | //now, just verify they didn't pass anything wack |
2990 | - foreach ( $query_params as $query_key => $query_value ) { |
|
2991 | - if ( ! in_array( $query_key, $this->_allowed_query_params, true ) ) { |
|
2990 | + foreach ($query_params as $query_key => $query_value) { |
|
2991 | + if ( ! in_array($query_key, $this->_allowed_query_params, true)) { |
|
2992 | 2992 | throw new EE_Error( |
2993 | 2993 | sprintf( |
2994 | 2994 | __( |
@@ -2996,16 +2996,16 @@ discard block |
||
2996 | 2996 | 'event_espresso' |
2997 | 2997 | ), |
2998 | 2998 | $query_key, |
2999 | - get_class( $this ), |
|
2999 | + get_class($this), |
|
3000 | 3000 | // print_r( $this->_allowed_query_params, TRUE ) |
3001 | - implode( ',', $this->_allowed_query_params ) |
|
3001 | + implode(',', $this->_allowed_query_params) |
|
3002 | 3002 | ) |
3003 | 3003 | ); |
3004 | 3004 | } |
3005 | 3005 | } |
3006 | 3006 | $main_model_join_sql = $query_object->get_main_model_join_sql(); |
3007 | - if ( empty( $main_model_join_sql ) ) { |
|
3008 | - $query_object->set_main_model_join_sql( $this->_construct_internal_join() ); |
|
3007 | + if (empty($main_model_join_sql)) { |
|
3008 | + $query_object->set_main_model_join_sql($this->_construct_internal_join()); |
|
3009 | 3009 | } |
3010 | 3010 | return $query_object; |
3011 | 3011 | } |
@@ -3020,17 +3020,17 @@ discard block |
||
3020 | 3020 | * @return array like EEM_Base::get_all() 's $query_params[0] |
3021 | 3021 | * @throws \EE_Error |
3022 | 3022 | */ |
3023 | - public function caps_where_conditions( $context = self::caps_read ) { |
|
3024 | - EEM_Base::verify_is_valid_cap_context( $context ); |
|
3023 | + public function caps_where_conditions($context = self::caps_read) { |
|
3024 | + EEM_Base::verify_is_valid_cap_context($context); |
|
3025 | 3025 | $cap_where_conditions = array(); |
3026 | - $cap_restrictions = $this->caps_missing( $context ); |
|
3026 | + $cap_restrictions = $this->caps_missing($context); |
|
3027 | 3027 | /** |
3028 | 3028 | * @var $cap_restrictions EE_Default_Where_Conditions[] |
3029 | 3029 | */ |
3030 | - foreach( $cap_restrictions as $cap => $restriction_if_no_cap ) { |
|
3031 | - $cap_where_conditions = array_replace_recursive( $cap_where_conditions, $restriction_if_no_cap->get_default_where_conditions() ); |
|
3030 | + foreach ($cap_restrictions as $cap => $restriction_if_no_cap) { |
|
3031 | + $cap_where_conditions = array_replace_recursive($cap_where_conditions, $restriction_if_no_cap->get_default_where_conditions()); |
|
3032 | 3032 | } |
3033 | - return apply_filters( 'FHEE__EEM_Base__caps_where_conditions__return', $cap_where_conditions, $this, $context, $cap_restrictions ); |
|
3033 | + return apply_filters('FHEE__EEM_Base__caps_where_conditions__return', $cap_where_conditions, $this, $context, $cap_restrictions); |
|
3034 | 3034 | } |
3035 | 3035 | |
3036 | 3036 | /** |
@@ -3040,11 +3040,11 @@ discard block |
||
3040 | 3040 | * @return string either ASC, asc, DESC or desc |
3041 | 3041 | * @throws EE_Error |
3042 | 3042 | */ |
3043 | - private function _extract_order($should_be_order_string){ |
|
3044 | - if(in_array($should_be_order_string, $this->_allowed_order_values)){ |
|
3043 | + private function _extract_order($should_be_order_string) { |
|
3044 | + if (in_array($should_be_order_string, $this->_allowed_order_values)) { |
|
3045 | 3045 | return $should_be_order_string; |
3046 | - }else{ |
|
3047 | - 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)); |
|
3046 | + } else { |
|
3047 | + 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)); |
|
3048 | 3048 | } |
3049 | 3049 | } |
3050 | 3050 | |
@@ -3062,7 +3062,7 @@ discard block |
||
3062 | 3062 | * @throws EE_Error |
3063 | 3063 | * @return array like $query_params[0], see EEM_Base::get_all for documentation |
3064 | 3064 | */ |
3065 | - 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()){ |
|
3065 | + 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()) { |
|
3066 | 3066 | $allowed_used_default_where_conditions_values = array( |
3067 | 3067 | 'all', |
3068 | 3068 | 'this_model_only', |
@@ -3070,17 +3070,17 @@ discard block |
||
3070 | 3070 | 'minimum', |
3071 | 3071 | 'none' |
3072 | 3072 | ); |
3073 | - if( ! in_array($use_default_where_conditions,$allowed_used_default_where_conditions_values)){ |
|
3074 | - 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))); |
|
3073 | + if ( ! in_array($use_default_where_conditions, $allowed_used_default_where_conditions_values)) { |
|
3074 | + 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))); |
|
3075 | 3075 | } |
3076 | 3076 | $universal_query_params = array(); |
3077 | - if( $use_default_where_conditions === 'all' || $use_default_where_conditions === 'this_model_only' ){ |
|
3077 | + if ($use_default_where_conditions === 'all' || $use_default_where_conditions === 'this_model_only') { |
|
3078 | 3078 | $universal_query_params = $this->_get_default_where_conditions(); |
3079 | - } else if( $use_default_where_conditions === 'minimum' ) { |
|
3079 | + } else if ($use_default_where_conditions === 'minimum') { |
|
3080 | 3080 | $universal_query_params = $this->_get_minimum_where_conditions(); |
3081 | 3081 | } |
3082 | - if(in_array($use_default_where_conditions,array('all','other_models_only'))){ |
|
3083 | - foreach($query_info_carrier->get_model_names_included() as $model_relation_path => $model_name){ |
|
3082 | + if (in_array($use_default_where_conditions, array('all', 'other_models_only'))) { |
|
3083 | + foreach ($query_info_carrier->get_model_names_included() as $model_relation_path => $model_name) { |
|
3084 | 3084 | $related_model = $this->get_related_model_obj($model_name); |
3085 | 3085 | $related_model_universal_where_params = $related_model->_get_default_where_conditions($model_relation_path); |
3086 | 3086 | $overrides = $this->_override_defaults_or_make_null_friendly( |
@@ -3113,20 +3113,20 @@ discard block |
||
3113 | 3113 | * @return array like EEM_Base::get_all's $query_params[0] |
3114 | 3114 | * @throws \EE_Error |
3115 | 3115 | */ |
3116 | - private function _override_defaults_or_make_null_friendly($default_where_conditions,$provided_where_conditions,$model,$model_relation_path){ |
|
3116 | + private function _override_defaults_or_make_null_friendly($default_where_conditions, $provided_where_conditions, $model, $model_relation_path) { |
|
3117 | 3117 | $null_friendly_where_conditions = array(); |
3118 | 3118 | $none_overridden = true; |
3119 | 3119 | $or_condition_key_for_defaults = 'OR*'.get_class($model); |
3120 | 3120 | |
3121 | - foreach($default_where_conditions as $key => $val){ |
|
3122 | - if( isset($provided_where_conditions[$key])){ |
|
3121 | + foreach ($default_where_conditions as $key => $val) { |
|
3122 | + if (isset($provided_where_conditions[$key])) { |
|
3123 | 3123 | $none_overridden = false; |
3124 | - }else{ |
|
3124 | + } else { |
|
3125 | 3125 | $null_friendly_where_conditions[$or_condition_key_for_defaults]['AND'][$key] = $val; |
3126 | 3126 | } |
3127 | 3127 | } |
3128 | - if( $none_overridden && $default_where_conditions){ |
|
3129 | - if($model->has_primary_key_field()){ |
|
3128 | + if ($none_overridden && $default_where_conditions) { |
|
3129 | + if ($model->has_primary_key_field()) { |
|
3130 | 3130 | $null_friendly_where_conditions[$or_condition_key_for_defaults][$model_relation_path.".".$model->primary_key_name()] = array('IS NULL'); |
3131 | 3131 | }/*else{ |
3132 | 3132 | //@todo NO PK, use other defaults |
@@ -3143,8 +3143,8 @@ discard block |
||
3143 | 3143 | * @param string $model_relation_path eg, path from Event to Payment is "Registration.Transaction.Payment." |
3144 | 3144 | * @return array like EEM_Base::get_all's $query_params[0] (where conditions) |
3145 | 3145 | */ |
3146 | - private function _get_default_where_conditions($model_relation_path = null){ |
|
3147 | - if ( $this->_ignore_where_strategy ){ |
|
3146 | + private function _get_default_where_conditions($model_relation_path = null) { |
|
3147 | + if ($this->_ignore_where_strategy) { |
|
3148 | 3148 | return array(); |
3149 | 3149 | } |
3150 | 3150 | return $this->_default_where_conditions_strategy->get_default_where_conditions($model_relation_path); |
@@ -3158,8 +3158,8 @@ discard block |
||
3158 | 3158 | * @param string $model_relation_path eg, path from Event to Payment is "Registration.Transaction.Payment." |
3159 | 3159 | * @return array like EEM_Base::get_all's $query_params[0] (where conditions) |
3160 | 3160 | */ |
3161 | - protected function _get_minimum_where_conditions($model_relation_path = null){ |
|
3162 | - if ( $this->_ignore_where_strategy ){ |
|
3161 | + protected function _get_minimum_where_conditions($model_relation_path = null) { |
|
3162 | + if ($this->_ignore_where_strategy) { |
|
3163 | 3163 | return array(); |
3164 | 3164 | } |
3165 | 3165 | return $this->_minimum_where_conditions_strategy->get_default_where_conditions($model_relation_path); |
@@ -3175,16 +3175,16 @@ discard block |
||
3175 | 3175 | * @return string |
3176 | 3176 | * @throws \EE_Error |
3177 | 3177 | */ |
3178 | - private function _construct_default_select_sql(EE_Model_Query_Info_Carrier $model_query_info){ |
|
3178 | + private function _construct_default_select_sql(EE_Model_Query_Info_Carrier $model_query_info) { |
|
3179 | 3179 | $selects = $this->_get_columns_to_select_for_this_model(); |
3180 | - foreach($model_query_info->get_model_names_included() as $model_relation_chain => $name_of_other_model_included){ |
|
3180 | + foreach ($model_query_info->get_model_names_included() as $model_relation_chain => $name_of_other_model_included) { |
|
3181 | 3181 | $other_model_included = $this->get_related_model_obj($name_of_other_model_included); |
3182 | - $other_model_selects = $other_model_included->_get_columns_to_select_for_this_model( $model_relation_chain ); |
|
3183 | - foreach ( $other_model_selects as $key => $value ) { |
|
3182 | + $other_model_selects = $other_model_included->_get_columns_to_select_for_this_model($model_relation_chain); |
|
3183 | + foreach ($other_model_selects as $key => $value) { |
|
3184 | 3184 | $selects[] = $value; |
3185 | 3185 | } |
3186 | 3186 | } |
3187 | - return implode(", ",$selects); |
|
3187 | + return implode(", ", $selects); |
|
3188 | 3188 | } |
3189 | 3189 | |
3190 | 3190 | /** |
@@ -3193,19 +3193,19 @@ discard block |
||
3193 | 3193 | * @param string $model_relation_chain like 'Question.Question_Group.Event' |
3194 | 3194 | * @return array numerically indexed, values are columns to select and rename, eg "Event.ID AS 'Event.ID'" |
3195 | 3195 | */ |
3196 | - public function _get_columns_to_select_for_this_model($model_relation_chain = ''){ |
|
3196 | + public function _get_columns_to_select_for_this_model($model_relation_chain = '') { |
|
3197 | 3197 | $fields = $this->field_settings(); |
3198 | 3198 | $selects = array(); |
3199 | 3199 | $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()); |
3200 | - foreach($fields as $field_obj){ |
|
3201 | - $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()."'"; |
|
3200 | + foreach ($fields as $field_obj) { |
|
3201 | + $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()."'"; |
|
3202 | 3202 | } |
3203 | 3203 | //make sure we are also getting the PKs of each table |
3204 | 3204 | $tables = $this->get_tables(); |
3205 | - if(count($tables) > 1){ |
|
3206 | - foreach($tables as $table_obj){ |
|
3207 | - $qualified_pk_column = $table_alias_with_model_relation_chain_prefix . $table_obj->get_fully_qualified_pk_column(); |
|
3208 | - if( ! in_array($qualified_pk_column,$selects)){ |
|
3205 | + if (count($tables) > 1) { |
|
3206 | + foreach ($tables as $table_obj) { |
|
3207 | + $qualified_pk_column = $table_alias_with_model_relation_chain_prefix.$table_obj->get_fully_qualified_pk_column(); |
|
3208 | + if ( ! in_array($qualified_pk_column, $selects)) { |
|
3209 | 3209 | $selects[] = "$qualified_pk_column AS '$qualified_pk_column'"; |
3210 | 3210 | } |
3211 | 3211 | } |
@@ -3235,65 +3235,65 @@ discard block |
||
3235 | 3235 | $query_param_type, |
3236 | 3236 | $original_query_param = null |
3237 | 3237 | ) { |
3238 | - if( $original_query_param === null ){ |
|
3238 | + if ($original_query_param === null) { |
|
3239 | 3239 | $original_query_param = $query_param; |
3240 | 3240 | } |
3241 | 3241 | $query_param = $this->_remove_stars_and_anything_after_from_condition_query_param_key($query_param); |
3242 | 3242 | /** @var $allow_logic_query_params bool whether or not to allow logic_query_params like 'NOT','OR', or 'AND' */ |
3243 | - $allow_logic_query_params = in_array($query_param_type,array('where','having')); |
|
3244 | - $allow_fields = in_array($query_param_type,array('where','having','order_by','group_by','order')); |
|
3243 | + $allow_logic_query_params = in_array($query_param_type, array('where', 'having')); |
|
3244 | + $allow_fields = in_array($query_param_type, array('where', 'having', 'order_by', 'group_by', 'order')); |
|
3245 | 3245 | //check to see if we have a field on this model |
3246 | 3246 | $this_model_fields = $this->field_settings(true); |
3247 | - if(array_key_exists($query_param,$this_model_fields)){ |
|
3248 | - if($allow_fields){ |
|
3247 | + if (array_key_exists($query_param, $this_model_fields)) { |
|
3248 | + if ($allow_fields) { |
|
3249 | 3249 | return; |
3250 | - }else{ |
|
3250 | + } else { |
|
3251 | 3251 | 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"), |
3252 | - $query_param,get_class($this),$query_param_type,$original_query_param)); |
|
3252 | + $query_param, get_class($this), $query_param_type, $original_query_param)); |
|
3253 | 3253 | } |
3254 | 3254 | } |
3255 | 3255 | //check if this is a special logic query param |
3256 | - elseif(in_array($query_param, $this->_logic_query_param_keys, TRUE)){ |
|
3257 | - if($allow_logic_query_params){ |
|
3256 | + elseif (in_array($query_param, $this->_logic_query_param_keys, TRUE)) { |
|
3257 | + if ($allow_logic_query_params) { |
|
3258 | 3258 | return; |
3259 | - }else{ |
|
3259 | + } else { |
|
3260 | 3260 | throw new EE_Error( |
3261 | 3261 | sprintf( |
3262 | - __( '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' ), |
|
3263 | - implode( '", "', $this->_logic_query_param_keys ), |
|
3264 | - $query_param , |
|
3265 | - get_class( $this ), |
|
3262 | + __('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'), |
|
3263 | + implode('", "', $this->_logic_query_param_keys), |
|
3264 | + $query_param, |
|
3265 | + get_class($this), |
|
3266 | 3266 | '<br />', |
3267 | - "\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 |
|
3267 | + "\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 |
|
3268 | 3268 | ) |
3269 | 3269 | ); |
3270 | 3270 | } |
3271 | 3271 | } |
3272 | 3272 | |
3273 | 3273 | //check if it's a custom selection |
3274 | - elseif(array_key_exists($query_param,$this->_custom_selections)){ |
|
3274 | + elseif (array_key_exists($query_param, $this->_custom_selections)) { |
|
3275 | 3275 | return; |
3276 | 3276 | } |
3277 | 3277 | |
3278 | 3278 | //check if has a model name at the beginning |
3279 | 3279 | //and |
3280 | 3280 | //check if it's a field on a related model |
3281 | - foreach($this->_model_relations as $valid_related_model_name=>$relation_obj){ |
|
3282 | - if(strpos($query_param, $valid_related_model_name.".") === 0){ |
|
3283 | - $this->_add_join_to_model($valid_related_model_name, $passed_in_query_info,$original_query_param); |
|
3281 | + foreach ($this->_model_relations as $valid_related_model_name=>$relation_obj) { |
|
3282 | + if (strpos($query_param, $valid_related_model_name.".") === 0) { |
|
3283 | + $this->_add_join_to_model($valid_related_model_name, $passed_in_query_info, $original_query_param); |
|
3284 | 3284 | $query_param = substr($query_param, strlen($valid_related_model_name.".")); |
3285 | - if($query_param === ''){ |
|
3285 | + if ($query_param === '') { |
|
3286 | 3286 | //nothing left to $query_param |
3287 | 3287 | //we should actually end in a field name, not a model like this! |
3288 | 3288 | throw new EE_Error(sprintf(__("Query param '%s' (of type %s on model %s) shouldn't end on a period (.) ", "event_espresso"), |
3289 | - $query_param,$query_param_type,get_class($this),$valid_related_model_name)); |
|
3290 | - }else{ |
|
3289 | + $query_param, $query_param_type, get_class($this), $valid_related_model_name)); |
|
3290 | + } else { |
|
3291 | 3291 | $related_model_obj = $this->get_related_model_obj($valid_related_model_name); |
3292 | 3292 | $related_model_obj->_extract_related_model_info_from_query_param($query_param, $passed_in_query_info, $query_param_type, $original_query_param); |
3293 | 3293 | return; |
3294 | 3294 | } |
3295 | - }elseif($query_param === $valid_related_model_name){ |
|
3296 | - $this->_add_join_to_model($valid_related_model_name, $passed_in_query_info,$original_query_param); |
|
3295 | + }elseif ($query_param === $valid_related_model_name) { |
|
3296 | + $this->_add_join_to_model($valid_related_model_name, $passed_in_query_info, $original_query_param); |
|
3297 | 3297 | return; |
3298 | 3298 | } |
3299 | 3299 | } |
@@ -3303,7 +3303,7 @@ discard block |
||
3303 | 3303 | //and we previously confirmed it wasn't a logic query param or field on the current model |
3304 | 3304 | //it's wack, that's what it is |
3305 | 3305 | 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"), |
3306 | - $query_param,get_class($this),$query_param_type,$original_query_param)); |
|
3306 | + $query_param, get_class($this), $query_param_type, $original_query_param)); |
|
3307 | 3307 | |
3308 | 3308 | } |
3309 | 3309 | |
@@ -3322,26 +3322,26 @@ discard block |
||
3322 | 3322 | * @return void |
3323 | 3323 | * @throws \EE_Error |
3324 | 3324 | */ |
3325 | - private function _add_join_to_model($model_name, EE_Model_Query_Info_Carrier $passed_in_query_info,$original_query_param){ |
|
3325 | + private function _add_join_to_model($model_name, EE_Model_Query_Info_Carrier $passed_in_query_info, $original_query_param) { |
|
3326 | 3326 | $relation_obj = $this->related_settings_for($model_name); |
3327 | 3327 | |
3328 | 3328 | $model_relation_chain = EE_Model_Parser::extract_model_relation_chain($model_name, $original_query_param); |
3329 | 3329 | //check if the relation is HABTM, because then we're essentially doing two joins |
3330 | 3330 | //If so, join first to the JOIN table, and add its data types, and then continue as normal |
3331 | - if($relation_obj instanceof EE_HABTM_Relation){ |
|
3331 | + if ($relation_obj instanceof EE_HABTM_Relation) { |
|
3332 | 3332 | $join_model_obj = $relation_obj->get_join_model(); |
3333 | 3333 | //replace the model specified with the join model for this relation chain, whi |
3334 | 3334 | $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); |
3335 | 3335 | $new_query_info = new EE_Model_Query_Info_Carrier( |
3336 | 3336 | array($relation_chain_to_join_model => $join_model_obj->get_this_model_name()), |
3337 | 3337 | $relation_obj->get_join_to_intermediate_model_statement($relation_chain_to_join_model)); |
3338 | - $passed_in_query_info->merge( $new_query_info ); |
|
3338 | + $passed_in_query_info->merge($new_query_info); |
|
3339 | 3339 | } |
3340 | 3340 | //now just join to the other table pointed to by the relation object, and add its data types |
3341 | 3341 | $new_query_info = new EE_Model_Query_Info_Carrier( |
3342 | 3342 | array($model_relation_chain=>$model_name), |
3343 | 3343 | $relation_obj->get_join_statement($model_relation_chain)); |
3344 | - $passed_in_query_info->merge( $new_query_info ); |
|
3344 | + $passed_in_query_info->merge($new_query_info); |
|
3345 | 3345 | } |
3346 | 3346 | |
3347 | 3347 | |
@@ -3353,11 +3353,11 @@ discard block |
||
3353 | 3353 | * @return string of SQL |
3354 | 3354 | * @throws \EE_Error |
3355 | 3355 | */ |
3356 | - private function _construct_where_clause($where_params){ |
|
3356 | + private function _construct_where_clause($where_params) { |
|
3357 | 3357 | $SQL = $this->_construct_condition_clause_recursive($where_params, ' AND '); |
3358 | - if($SQL){ |
|
3359 | - return " WHERE ". $SQL; |
|
3360 | - }else{ |
|
3358 | + if ($SQL) { |
|
3359 | + return " WHERE ".$SQL; |
|
3360 | + } else { |
|
3361 | 3361 | return ''; |
3362 | 3362 | } |
3363 | 3363 | } |
@@ -3372,11 +3372,11 @@ discard block |
||
3372 | 3372 | * @return string |
3373 | 3373 | * @throws \EE_Error |
3374 | 3374 | */ |
3375 | - private function _construct_having_clause($having_params){ |
|
3375 | + private function _construct_having_clause($having_params) { |
|
3376 | 3376 | $SQL = $this->_construct_condition_clause_recursive($having_params, ' AND '); |
3377 | - if($SQL){ |
|
3378 | - return " HAVING ". $SQL; |
|
3379 | - }else{ |
|
3377 | + if ($SQL) { |
|
3378 | + return " HAVING ".$SQL; |
|
3379 | + } else { |
|
3380 | 3380 | return ''; |
3381 | 3381 | } |
3382 | 3382 | |
@@ -3390,16 +3390,16 @@ discard block |
||
3390 | 3390 | * @return EE_Model_Field_Base |
3391 | 3391 | * @throws EE_Error |
3392 | 3392 | */ |
3393 | - protected function _get_field_on_model($field_name,$model_name){ |
|
3393 | + protected function _get_field_on_model($field_name, $model_name) { |
|
3394 | 3394 | $model_class = 'EEM_'.$model_name; |
3395 | 3395 | $model_filepath = $model_class.".model.php"; |
3396 | - if ( is_readable($model_filepath)){ |
|
3396 | + if (is_readable($model_filepath)) { |
|
3397 | 3397 | require_once($model_filepath); |
3398 | - $model_instance=call_user_func($model_name."::instance"); |
|
3398 | + $model_instance = call_user_func($model_name."::instance"); |
|
3399 | 3399 | /* @var $model_instance EEM_Base */ |
3400 | 3400 | return $model_instance->field_settings_for($field_name); |
3401 | - }else{ |
|
3402 | - throw new EE_Error(sprintf(__('No model named %s exists, with classname %s and filepath %s','event_espresso'),$model_name,$model_class,$model_filepath)); |
|
3401 | + } else { |
|
3402 | + throw new EE_Error(sprintf(__('No model named %s exists, with classname %s and filepath %s', 'event_espresso'), $model_name, $model_class, $model_filepath)); |
|
3403 | 3403 | } |
3404 | 3404 | } |
3405 | 3405 | |
@@ -3412,41 +3412,41 @@ discard block |
||
3412 | 3412 | * @throws EE_Error |
3413 | 3413 | * @return string of SQL |
3414 | 3414 | */ |
3415 | - private function _construct_condition_clause_recursive($where_params, $glue = ' AND'){ |
|
3416 | - $where_clauses=array(); |
|
3417 | - foreach($where_params as $query_param => $op_and_value_or_sub_condition){ |
|
3418 | - $query_param = $this->_remove_stars_and_anything_after_from_condition_query_param_key($query_param);//str_replace("*",'',$query_param); |
|
3419 | - if(in_array($query_param,$this->_logic_query_param_keys)){ |
|
3420 | - switch($query_param){ |
|
3415 | + private function _construct_condition_clause_recursive($where_params, $glue = ' AND') { |
|
3416 | + $where_clauses = array(); |
|
3417 | + foreach ($where_params as $query_param => $op_and_value_or_sub_condition) { |
|
3418 | + $query_param = $this->_remove_stars_and_anything_after_from_condition_query_param_key($query_param); //str_replace("*",'',$query_param); |
|
3419 | + if (in_array($query_param, $this->_logic_query_param_keys)) { |
|
3420 | + switch ($query_param) { |
|
3421 | 3421 | case 'not': |
3422 | 3422 | case 'NOT': |
3423 | - $where_clauses[] = "! (". $this->_construct_condition_clause_recursive($op_and_value_or_sub_condition, $glue).")"; |
|
3423 | + $where_clauses[] = "! (".$this->_construct_condition_clause_recursive($op_and_value_or_sub_condition, $glue).")"; |
|
3424 | 3424 | break; |
3425 | 3425 | case 'and': |
3426 | 3426 | case 'AND': |
3427 | - $where_clauses[] = " (". $this->_construct_condition_clause_recursive($op_and_value_or_sub_condition, ' AND ') .")"; |
|
3427 | + $where_clauses[] = " (".$this->_construct_condition_clause_recursive($op_and_value_or_sub_condition, ' AND ').")"; |
|
3428 | 3428 | break; |
3429 | 3429 | case 'or': |
3430 | 3430 | case 'OR': |
3431 | - $where_clauses[] = " (". $this->_construct_condition_clause_recursive($op_and_value_or_sub_condition, ' OR ') .")"; |
|
3431 | + $where_clauses[] = " (".$this->_construct_condition_clause_recursive($op_and_value_or_sub_condition, ' OR ').")"; |
|
3432 | 3432 | break; |
3433 | 3433 | } |
3434 | - }else{ |
|
3434 | + } else { |
|
3435 | 3435 | $field_obj = $this->_deduce_field_from_query_param($query_param); |
3436 | 3436 | |
3437 | 3437 | //if it's not a normal field, maybe it's a custom selection? |
3438 | - if( ! $field_obj){ |
|
3439 | - if(isset( $this->_custom_selections[$query_param][1])){ |
|
3438 | + if ( ! $field_obj) { |
|
3439 | + if (isset($this->_custom_selections[$query_param][1])) { |
|
3440 | 3440 | $field_obj = $this->_custom_selections[$query_param][1]; |
3441 | - }else{ |
|
3442 | - throw new EE_Error(sprintf(__("%s is neither a valid model field name, nor a custom selection", "event_espresso"),$query_param)); |
|
3441 | + } else { |
|
3442 | + throw new EE_Error(sprintf(__("%s is neither a valid model field name, nor a custom selection", "event_espresso"), $query_param)); |
|
3443 | 3443 | } |
3444 | 3444 | } |
3445 | 3445 | $op_and_value_sql = $this->_construct_op_and_value($op_and_value_or_sub_condition, $field_obj); |
3446 | - $where_clauses[]=$this->_deduce_column_name_from_query_param($query_param).SP.$op_and_value_sql; |
|
3446 | + $where_clauses[] = $this->_deduce_column_name_from_query_param($query_param).SP.$op_and_value_sql; |
|
3447 | 3447 | } |
3448 | 3448 | } |
3449 | - return $where_clauses ? implode( $glue, $where_clauses ) : ''; |
|
3449 | + return $where_clauses ? implode($glue, $where_clauses) : ''; |
|
3450 | 3450 | } |
3451 | 3451 | |
3452 | 3452 | |
@@ -3457,18 +3457,18 @@ discard block |
||
3457 | 3457 | * @throws EE_Error |
3458 | 3458 | * @return string table alias and column name for SQL, eg "Transaction.TXN_ID" |
3459 | 3459 | */ |
3460 | - private function _deduce_column_name_from_query_param($query_param){ |
|
3460 | + private function _deduce_column_name_from_query_param($query_param) { |
|
3461 | 3461 | $field = $this->_deduce_field_from_query_param($query_param); |
3462 | 3462 | |
3463 | - if( $field ){ |
|
3464 | - $table_alias_prefix = EE_Model_Parser::extract_table_alias_model_relation_chain_from_query_param( $field->get_model_name(), $query_param ); |
|
3465 | - return $table_alias_prefix . $field->get_qualified_column(); |
|
3466 | - }elseif(array_key_exists($query_param,$this->_custom_selections)){ |
|
3463 | + if ($field) { |
|
3464 | + $table_alias_prefix = EE_Model_Parser::extract_table_alias_model_relation_chain_from_query_param($field->get_model_name(), $query_param); |
|
3465 | + return $table_alias_prefix.$field->get_qualified_column(); |
|
3466 | + }elseif (array_key_exists($query_param, $this->_custom_selections)) { |
|
3467 | 3467 | //maybe it's custom selection item? |
3468 | 3468 | //if so, just use it as the "column name" |
3469 | 3469 | return $query_param; |
3470 | - }else{ |
|
3471 | - 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))); |
|
3470 | + } else { |
|
3471 | + 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))); |
|
3472 | 3472 | } |
3473 | 3473 | } |
3474 | 3474 | |
@@ -3480,11 +3480,11 @@ discard block |
||
3480 | 3480 | * @param string $condition_query_param_key |
3481 | 3481 | * @return string |
3482 | 3482 | */ |
3483 | - private function _remove_stars_and_anything_after_from_condition_query_param_key($condition_query_param_key){ |
|
3483 | + private function _remove_stars_and_anything_after_from_condition_query_param_key($condition_query_param_key) { |
|
3484 | 3484 | $pos_of_star = strpos($condition_query_param_key, '*'); |
3485 | - if($pos_of_star === FALSE){ |
|
3485 | + if ($pos_of_star === FALSE) { |
|
3486 | 3486 | return $condition_query_param_key; |
3487 | - }else{ |
|
3487 | + } else { |
|
3488 | 3488 | $condition_query_param_sans_star = substr($condition_query_param_key, 0, $pos_of_star); |
3489 | 3489 | return $condition_query_param_sans_star; |
3490 | 3490 | } |
@@ -3499,12 +3499,12 @@ discard block |
||
3499 | 3499 | * @throws EE_Error |
3500 | 3500 | * @return string |
3501 | 3501 | */ |
3502 | - private function _construct_op_and_value($op_and_value, $field_obj){ |
|
3503 | - if ( is_array( $op_and_value ) ) { |
|
3504 | - $operator = isset( $op_and_value[0] ) ? $this->_prepare_operator_for_sql( $op_and_value[0] ) : null; |
|
3505 | - if ( ! $operator ) { |
|
3502 | + private function _construct_op_and_value($op_and_value, $field_obj) { |
|
3503 | + if (is_array($op_and_value)) { |
|
3504 | + $operator = isset($op_and_value[0]) ? $this->_prepare_operator_for_sql($op_and_value[0]) : null; |
|
3505 | + if ( ! $operator) { |
|
3506 | 3506 | $php_array_like_string = array(); |
3507 | - foreach ( $op_and_value as $key => $value ) { |
|
3507 | + foreach ($op_and_value as $key => $value) { |
|
3508 | 3508 | $php_array_like_string[] = "$key=>$value"; |
3509 | 3509 | } |
3510 | 3510 | throw new EE_Error( |
@@ -3513,27 +3513,27 @@ discard block |
||
3513 | 3513 | "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))", |
3514 | 3514 | "event_espresso" |
3515 | 3515 | ), |
3516 | - implode( ",", $php_array_like_string ) |
|
3516 | + implode(",", $php_array_like_string) |
|
3517 | 3517 | ) |
3518 | 3518 | ); |
3519 | 3519 | } |
3520 | - $value = isset( $op_and_value[1] ) ? $op_and_value[1] : null; |
|
3520 | + $value = isset($op_and_value[1]) ? $op_and_value[1] : null; |
|
3521 | 3521 | } else { |
3522 | 3522 | $operator = '='; |
3523 | 3523 | $value = $op_and_value; |
3524 | 3524 | } |
3525 | 3525 | //check to see if the value is actually another field |
3526 | - if ( is_array( $op_and_value ) && isset( $op_and_value[2] ) && $op_and_value[2] == true ) { |
|
3527 | - return $operator . SP . $this->_deduce_column_name_from_query_param( $value ); |
|
3528 | - } elseif ( in_array( $operator, $this->_in_style_operators ) && is_array( $value ) ) { |
|
3526 | + if (is_array($op_and_value) && isset($op_and_value[2]) && $op_and_value[2] == true) { |
|
3527 | + return $operator.SP.$this->_deduce_column_name_from_query_param($value); |
|
3528 | + } elseif (in_array($operator, $this->_in_style_operators) && is_array($value)) { |
|
3529 | 3529 | //in this case, the value should be an array, or at least a comma-separated list |
3530 | 3530 | //it will need to handle a little differently |
3531 | - $cleaned_value = $this->_construct_in_value( $value, $field_obj ); |
|
3531 | + $cleaned_value = $this->_construct_in_value($value, $field_obj); |
|
3532 | 3532 | //note: $cleaned_value has already been run through $wpdb->prepare() |
3533 | - return $operator . SP . $cleaned_value; |
|
3534 | - } elseif ( in_array( $operator, $this->_between_style_operators ) && is_array( $value ) ) { |
|
3533 | + return $operator.SP.$cleaned_value; |
|
3534 | + } elseif (in_array($operator, $this->_between_style_operators) && is_array($value)) { |
|
3535 | 3535 | //the value should be an array with count of two. |
3536 | - if ( count( $value ) !== 2 ) { |
|
3536 | + if (count($value) !== 2) { |
|
3537 | 3537 | throw new EE_Error( |
3538 | 3538 | sprintf( |
3539 | 3539 | __( |
@@ -3544,10 +3544,10 @@ discard block |
||
3544 | 3544 | ) |
3545 | 3545 | ); |
3546 | 3546 | } |
3547 | - $cleaned_value = $this->_construct_between_value( $value, $field_obj ); |
|
3548 | - return $operator . SP . $cleaned_value; |
|
3549 | - } elseif ( in_array( $operator, $this->_null_style_operators ) ) { |
|
3550 | - if ( $value !== null ) { |
|
3547 | + $cleaned_value = $this->_construct_between_value($value, $field_obj); |
|
3548 | + return $operator.SP.$cleaned_value; |
|
3549 | + } elseif (in_array($operator, $this->_null_style_operators)) { |
|
3550 | + if ($value !== null) { |
|
3551 | 3551 | throw new EE_Error( |
3552 | 3552 | sprintf( |
3553 | 3553 | __( |
@@ -3560,13 +3560,13 @@ discard block |
||
3560 | 3560 | ); |
3561 | 3561 | } |
3562 | 3562 | return $operator; |
3563 | - } elseif ( $operator === 'LIKE' && ! is_array( $value ) ) { |
|
3563 | + } elseif ($operator === 'LIKE' && ! is_array($value)) { |
|
3564 | 3564 | //if the operator is 'LIKE', we want to allow percent signs (%) and not |
3565 | 3565 | //remove other junk. So just treat it as a string. |
3566 | - return $operator . SP . $this->_wpdb_prepare_using_field( $value, '%s' ); |
|
3567 | - } elseif ( ! in_array( $operator, $this->_in_style_operators ) && ! is_array( $value ) ) { |
|
3568 | - return $operator . SP . $this->_wpdb_prepare_using_field( $value, $field_obj ); |
|
3569 | - } elseif ( in_array( $operator, $this->_in_style_operators ) && ! is_array( $value ) ) { |
|
3566 | + return $operator.SP.$this->_wpdb_prepare_using_field($value, '%s'); |
|
3567 | + } elseif ( ! in_array($operator, $this->_in_style_operators) && ! is_array($value)) { |
|
3568 | + return $operator.SP.$this->_wpdb_prepare_using_field($value, $field_obj); |
|
3569 | + } elseif (in_array($operator, $this->_in_style_operators) && ! is_array($value)) { |
|
3570 | 3570 | throw new EE_Error( |
3571 | 3571 | sprintf( |
3572 | 3572 | __( |
@@ -3577,7 +3577,7 @@ discard block |
||
3577 | 3577 | $operator |
3578 | 3578 | ) |
3579 | 3579 | ); |
3580 | - } elseif ( ! in_array( $operator, $this->_in_style_operators ) && is_array( $value ) ) { |
|
3580 | + } elseif ( ! in_array($operator, $this->_in_style_operators) && is_array($value)) { |
|
3581 | 3581 | throw new EE_Error( |
3582 | 3582 | sprintf( |
3583 | 3583 | __( |
@@ -3595,7 +3595,7 @@ discard block |
||
3595 | 3595 | "It appears you've provided some totally invalid query parameters. Operator and value were:'%s', which isn't right at all", |
3596 | 3596 | "event_espresso" |
3597 | 3597 | ), |
3598 | - http_build_query( $op_and_value ) |
|
3598 | + http_build_query($op_and_value) |
|
3599 | 3599 | ) |
3600 | 3600 | ); |
3601 | 3601 | } |
@@ -3611,12 +3611,12 @@ discard block |
||
3611 | 3611 | * @return string |
3612 | 3612 | * @throws \EE_Error |
3613 | 3613 | */ |
3614 | - public function _construct_between_value( $values, $field_obj ) { |
|
3614 | + public function _construct_between_value($values, $field_obj) { |
|
3615 | 3615 | $cleaned_values = array(); |
3616 | - foreach ( $values as $value ) { |
|
3617 | - $cleaned_values[] = $this->_wpdb_prepare_using_field($value,$field_obj); |
|
3616 | + foreach ($values as $value) { |
|
3617 | + $cleaned_values[] = $this->_wpdb_prepare_using_field($value, $field_obj); |
|
3618 | 3618 | } |
3619 | - return $cleaned_values[0] . " AND " . $cleaned_values[1]; |
|
3619 | + return $cleaned_values[0]." AND ".$cleaned_values[1]; |
|
3620 | 3620 | } |
3621 | 3621 | |
3622 | 3622 | |
@@ -3633,26 +3633,26 @@ discard block |
||
3633 | 3633 | * @return string of SQL to follow an 'IN' or 'NOT IN' operator |
3634 | 3634 | * @throws \EE_Error |
3635 | 3635 | */ |
3636 | - public function _construct_in_value($values, $field_obj){ |
|
3636 | + public function _construct_in_value($values, $field_obj) { |
|
3637 | 3637 | //check if the value is a CSV list |
3638 | - if(is_string($values)){ |
|
3638 | + if (is_string($values)) { |
|
3639 | 3639 | //in which case, turn it into an array |
3640 | - $values = explode(",",$values); |
|
3640 | + $values = explode(",", $values); |
|
3641 | 3641 | } |
3642 | 3642 | $cleaned_values = array(); |
3643 | - foreach($values as $value){ |
|
3644 | - $cleaned_values[] = $this->_wpdb_prepare_using_field($value,$field_obj); |
|
3643 | + foreach ($values as $value) { |
|
3644 | + $cleaned_values[] = $this->_wpdb_prepare_using_field($value, $field_obj); |
|
3645 | 3645 | } |
3646 | 3646 | //we would just LOVE to leave $cleaned_values as an empty array, and return the value as "()", |
3647 | 3647 | //but unfortunately that's invalid SQL. So instead we return a string which we KNOW will evaluate to be the empty set |
3648 | 3648 | //which is effectively equivalent to returning "()". We don't return "(0)" because that only works for auto-incrementing columns |
3649 | - if(empty($cleaned_values)){ |
|
3649 | + if (empty($cleaned_values)) { |
|
3650 | 3650 | $all_fields = $this->field_settings(); |
3651 | 3651 | $a_field = array_shift($all_fields); |
3652 | 3652 | $main_table = $this->_get_main_table(); |
3653 | 3653 | $cleaned_values[] = "SELECT ".$a_field->get_table_column()." FROM ".$main_table->get_table_name()." WHERE FALSE"; |
3654 | 3654 | } |
3655 | - return "(".implode(",",$cleaned_values).")"; |
|
3655 | + return "(".implode(",", $cleaned_values).")"; |
|
3656 | 3656 | } |
3657 | 3657 | |
3658 | 3658 | |
@@ -3664,16 +3664,16 @@ discard block |
||
3664 | 3664 | * @throws EE_Error |
3665 | 3665 | * @return false|null|string |
3666 | 3666 | */ |
3667 | - private function _wpdb_prepare_using_field($value,$field_obj){ |
|
3667 | + private function _wpdb_prepare_using_field($value, $field_obj) { |
|
3668 | 3668 | /** @type WPDB $wpdb */ |
3669 | 3669 | global $wpdb; |
3670 | - if($field_obj instanceof EE_Model_Field_Base){ |
|
3671 | - return $wpdb->prepare($field_obj->get_wpdb_data_type(),$this->_prepare_value_for_use_in_db($value, $field_obj)); |
|
3672 | - }else{//$field_obj should really just be a data type |
|
3673 | - if( ! in_array($field_obj,$this->_valid_wpdb_data_types)){ |
|
3674 | - 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))); |
|
3670 | + if ($field_obj instanceof EE_Model_Field_Base) { |
|
3671 | + return $wpdb->prepare($field_obj->get_wpdb_data_type(), $this->_prepare_value_for_use_in_db($value, $field_obj)); |
|
3672 | + } else {//$field_obj should really just be a data type |
|
3673 | + if ( ! in_array($field_obj, $this->_valid_wpdb_data_types)) { |
|
3674 | + 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))); |
|
3675 | 3675 | } |
3676 | - return $wpdb->prepare($field_obj,$value); |
|
3676 | + return $wpdb->prepare($field_obj, $value); |
|
3677 | 3677 | } |
3678 | 3678 | } |
3679 | 3679 | |
@@ -3685,27 +3685,27 @@ discard block |
||
3685 | 3685 | * @throws EE_Error |
3686 | 3686 | * @return EE_Model_Field_Base |
3687 | 3687 | */ |
3688 | - protected function _deduce_field_from_query_param($query_param_name){ |
|
3688 | + protected function _deduce_field_from_query_param($query_param_name) { |
|
3689 | 3689 | //ok, now proceed with deducing which part is the model's name, and which is the field's name |
3690 | 3690 | //which will help us find the database table and column |
3691 | 3691 | |
3692 | - $query_param_parts = explode(".",$query_param_name); |
|
3693 | - if(empty($query_param_parts)){ |
|
3694 | - 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)); |
|
3692 | + $query_param_parts = explode(".", $query_param_name); |
|
3693 | + if (empty($query_param_parts)) { |
|
3694 | + 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)); |
|
3695 | 3695 | } |
3696 | 3696 | $number_of_parts = count($query_param_parts); |
3697 | - $last_query_param_part = $query_param_parts[ count($query_param_parts) - 1 ]; |
|
3698 | - if($number_of_parts === 1){ |
|
3697 | + $last_query_param_part = $query_param_parts[count($query_param_parts) - 1]; |
|
3698 | + if ($number_of_parts === 1) { |
|
3699 | 3699 | $field_name = $last_query_param_part; |
3700 | 3700 | $model_obj = $this; |
3701 | - }else{// $number_of_parts >= 2 |
|
3701 | + } else {// $number_of_parts >= 2 |
|
3702 | 3702 | //the last part is the column name, and there are only 2parts. therefore... |
3703 | 3703 | $field_name = $last_query_param_part; |
3704 | - $model_obj = $this->get_related_model_obj( $query_param_parts[ $number_of_parts - 2 ]); |
|
3704 | + $model_obj = $this->get_related_model_obj($query_param_parts[$number_of_parts - 2]); |
|
3705 | 3705 | } |
3706 | - try{ |
|
3706 | + try { |
|
3707 | 3707 | return $model_obj->field_settings_for($field_name); |
3708 | - }catch(EE_Error $e){ |
|
3708 | + } catch (EE_Error $e) { |
|
3709 | 3709 | return null; |
3710 | 3710 | } |
3711 | 3711 | } |
@@ -3719,13 +3719,13 @@ discard block |
||
3719 | 3719 | * @throws EE_Error |
3720 | 3720 | * @return string |
3721 | 3721 | */ |
3722 | - public function _get_qualified_column_for_field($field_name){ |
|
3722 | + public function _get_qualified_column_for_field($field_name) { |
|
3723 | 3723 | $all_fields = $this->field_settings(); |
3724 | 3724 | $field = isset($all_fields[$field_name]) ? $all_fields[$field_name] : FALSE; |
3725 | - if($field){ |
|
3725 | + if ($field) { |
|
3726 | 3726 | return $field->get_qualified_column(); |
3727 | - }else{ |
|
3728 | - 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))); |
|
3727 | + } else { |
|
3728 | + 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))); |
|
3729 | 3729 | } |
3730 | 3730 | } |
3731 | 3731 | |
@@ -3739,17 +3739,17 @@ discard block |
||
3739 | 3739 | * @param mixed|string $limit The limit for this select |
3740 | 3740 | * @return string The final select join element for the query. |
3741 | 3741 | */ |
3742 | - public function _construct_limit_join_select( $table_alias, $limit ) { |
|
3742 | + public function _construct_limit_join_select($table_alias, $limit) { |
|
3743 | 3743 | $SQL = ''; |
3744 | - foreach ( $this->_tables as $table_obj ) { |
|
3745 | - if ( $table_obj instanceof EE_Primary_Table ) { |
|
3744 | + foreach ($this->_tables as $table_obj) { |
|
3745 | + if ($table_obj instanceof EE_Primary_Table) { |
|
3746 | 3746 | $SQL .= $table_alias === $table_obj->get_table_alias() |
3747 | - ? $table_obj->get_select_join_limit( $limit ) |
|
3748 | - : SP . $table_obj->get_table_name() . " AS " . $table_obj->get_table_alias() . SP; |
|
3749 | - } elseif ( $table_obj instanceof EE_Secondary_Table ) { |
|
3747 | + ? $table_obj->get_select_join_limit($limit) |
|
3748 | + : SP.$table_obj->get_table_name()." AS ".$table_obj->get_table_alias().SP; |
|
3749 | + } elseif ($table_obj instanceof EE_Secondary_Table) { |
|
3750 | 3750 | $SQL .= $table_alias === $table_obj->get_table_alias() |
3751 | - ? $table_obj->get_select_join_limit_join( $limit ) |
|
3752 | - : SP . $table_obj->get_join_sql( $table_alias ) . SP; |
|
3751 | + ? $table_obj->get_select_join_limit_join($limit) |
|
3752 | + : SP.$table_obj->get_join_sql($table_alias).SP; |
|
3753 | 3753 | } |
3754 | 3754 | } |
3755 | 3755 | return $SQL; |
@@ -3764,7 +3764,7 @@ discard block |
||
3764 | 3764 | * @return string SQL |
3765 | 3765 | * @throws \EE_Error |
3766 | 3766 | */ |
3767 | - public function _construct_internal_join(){ |
|
3767 | + public function _construct_internal_join() { |
|
3768 | 3768 | $SQL = $this->_get_main_table()->get_table_sql(); |
3769 | 3769 | $SQL .= $this->_construct_internal_join_to_table_with_alias($this->_get_main_table()->get_table_alias()); |
3770 | 3770 | return $SQL; |
@@ -3785,17 +3785,17 @@ discard block |
||
3785 | 3785 | * @param string $alias_prefixed table alias to join to (this table should already be in the FROM SQL clause) |
3786 | 3786 | * @return string |
3787 | 3787 | */ |
3788 | - public function _construct_internal_join_to_table_with_alias($alias_prefixed){ |
|
3788 | + public function _construct_internal_join_to_table_with_alias($alias_prefixed) { |
|
3789 | 3789 | $SQL = ''; |
3790 | 3790 | $alias_sans_prefix = EE_Model_Parser::remove_table_alias_model_relation_chain_prefix($alias_prefixed); |
3791 | - foreach($this->_tables as $table_obj){ |
|
3792 | - if($table_obj instanceof EE_Secondary_Table){//table is secondary table |
|
3793 | - if($alias_sans_prefix === $table_obj->get_table_alias()){ |
|
3791 | + foreach ($this->_tables as $table_obj) { |
|
3792 | + if ($table_obj instanceof EE_Secondary_Table) {//table is secondary table |
|
3793 | + if ($alias_sans_prefix === $table_obj->get_table_alias()) { |
|
3794 | 3794 | //so we're joining to this table, meaning the table is already in |
3795 | 3795 | //the FROM statement, BUT the primary table isn't. So we want |
3796 | 3796 | //to add the inverse join sql |
3797 | 3797 | $SQL .= $table_obj->get_inverse_join_sql($alias_prefixed); |
3798 | - }else{ |
|
3798 | + } else { |
|
3799 | 3799 | //just add a regular JOIN to this table from the primary table |
3800 | 3800 | $SQL .= $table_obj->get_join_sql($alias_prefixed); |
3801 | 3801 | } |
@@ -3809,9 +3809,9 @@ discard block |
||
3809 | 3809 | * 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) |
3810 | 3810 | * @return array |
3811 | 3811 | */ |
3812 | - public function _get_data_types(){ |
|
3812 | + public function _get_data_types() { |
|
3813 | 3813 | $data_types = array(); |
3814 | - foreach( $this->field_settings() as $field_obj){ |
|
3814 | + foreach ($this->field_settings() as $field_obj) { |
|
3815 | 3815 | //$data_types[$field_obj->get_table_column()] = $field_obj->get_wpdb_data_type(); |
3816 | 3816 | /** @var $field_obj EE_Model_Field_Base */ |
3817 | 3817 | $data_types[$field_obj->get_qualified_column()] = $field_obj->get_wpdb_data_type(); |
@@ -3827,10 +3827,10 @@ discard block |
||
3827 | 3827 | * @throws EE_Error |
3828 | 3828 | * @return EEM_Base |
3829 | 3829 | */ |
3830 | - public function get_related_model_obj($model_name){ |
|
3830 | + public function get_related_model_obj($model_name) { |
|
3831 | 3831 | $model_classname = "EEM_".$model_name; |
3832 | - if(!class_exists($model_classname)){ |
|
3833 | - 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)); |
|
3832 | + if ( ! class_exists($model_classname)) { |
|
3833 | + 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)); |
|
3834 | 3834 | } |
3835 | 3835 | return call_user_func($model_classname."::instance"); |
3836 | 3836 | } |
@@ -3840,7 +3840,7 @@ discard block |
||
3840 | 3840 | * Returns the array of EE_ModelRelations for this model. |
3841 | 3841 | * @return EE_Model_Relation_Base[] |
3842 | 3842 | */ |
3843 | - public function relation_settings(){ |
|
3843 | + public function relation_settings() { |
|
3844 | 3844 | return $this->_model_relations; |
3845 | 3845 | } |
3846 | 3846 | |
@@ -3850,10 +3850,10 @@ discard block |
||
3850 | 3850 | * (Eg, without an event, datetimes have little purpose.) |
3851 | 3851 | * @return EE_Belongs_To_Relation[] |
3852 | 3852 | */ |
3853 | - public function belongs_to_relations(){ |
|
3853 | + public function belongs_to_relations() { |
|
3854 | 3854 | $belongs_to_relations = array(); |
3855 | - foreach($this->relation_settings() as $model_name => $relation_obj){ |
|
3856 | - if($relation_obj instanceof EE_Belongs_To_Relation){ |
|
3855 | + foreach ($this->relation_settings() as $model_name => $relation_obj) { |
|
3856 | + if ($relation_obj instanceof EE_Belongs_To_Relation) { |
|
3857 | 3857 | $belongs_to_relations[$model_name] = $relation_obj; |
3858 | 3858 | } |
3859 | 3859 | } |
@@ -3868,15 +3868,15 @@ discard block |
||
3868 | 3868 | * @throws EE_Error |
3869 | 3869 | * @return EE_Model_Relation_Base |
3870 | 3870 | */ |
3871 | - public function related_settings_for($relation_name){ |
|
3872 | - $relatedModels=$this->relation_settings(); |
|
3873 | - if(!array_key_exists($relation_name,$relatedModels)){ |
|
3871 | + public function related_settings_for($relation_name) { |
|
3872 | + $relatedModels = $this->relation_settings(); |
|
3873 | + if ( ! array_key_exists($relation_name, $relatedModels)) { |
|
3874 | 3874 | throw new EE_Error( |
3875 | 3875 | sprintf( |
3876 | - __('Cannot get %s related to %s. There is no model relation of that type. There is, however, %s...','event_espresso'), |
|
3876 | + __('Cannot get %s related to %s. There is no model relation of that type. There is, however, %s...', 'event_espresso'), |
|
3877 | 3877 | $relation_name, |
3878 | 3878 | $this->_get_class_name(), |
3879 | - implode( ', ', array_keys( $relatedModels )) |
|
3879 | + implode(', ', array_keys($relatedModels)) |
|
3880 | 3880 | ) |
3881 | 3881 | ); |
3882 | 3882 | } |
@@ -3891,10 +3891,10 @@ discard block |
||
3891 | 3891 | * @throws EE_Error |
3892 | 3892 | * @return EE_Model_Field_Base |
3893 | 3893 | */ |
3894 | - public function field_settings_for($fieldName){ |
|
3895 | - $fieldSettings=$this->field_settings(true); |
|
3896 | - if( ! array_key_exists($fieldName,$fieldSettings)){ |
|
3897 | - throw new EE_Error(sprintf(__("There is no field/column '%s' on '%s'",'event_espresso'),$fieldName,get_class($this))); |
|
3894 | + public function field_settings_for($fieldName) { |
|
3895 | + $fieldSettings = $this->field_settings(true); |
|
3896 | + if ( ! array_key_exists($fieldName, $fieldSettings)) { |
|
3897 | + throw new EE_Error(sprintf(__("There is no field/column '%s' on '%s'", 'event_espresso'), $fieldName, get_class($this))); |
|
3898 | 3898 | } |
3899 | 3899 | return $fieldSettings[$fieldName]; |
3900 | 3900 | } |
@@ -3904,11 +3904,11 @@ discard block |
||
3904 | 3904 | * @param string $fieldName a key in the model's _field_settings array |
3905 | 3905 | * @return boolean |
3906 | 3906 | */ |
3907 | - public function has_field($fieldName){ |
|
3907 | + public function has_field($fieldName) { |
|
3908 | 3908 | $fieldSettings = $this->field_settings(true); |
3909 | - if( isset($fieldSettings[$fieldName])){ |
|
3909 | + if (isset($fieldSettings[$fieldName])) { |
|
3910 | 3910 | return true; |
3911 | - }else{ |
|
3911 | + } else { |
|
3912 | 3912 | return false; |
3913 | 3913 | } |
3914 | 3914 | } |
@@ -3918,11 +3918,11 @@ discard block |
||
3918 | 3918 | * @param string $relation_name possibly one of the keys in the relation_settings array |
3919 | 3919 | * @return boolean |
3920 | 3920 | */ |
3921 | - public function has_relation($relation_name){ |
|
3921 | + public function has_relation($relation_name) { |
|
3922 | 3922 | $relations = $this->relation_settings(); |
3923 | - if(isset($relations[$relation_name])){ |
|
3923 | + if (isset($relations[$relation_name])) { |
|
3924 | 3924 | return true; |
3925 | - }else{ |
|
3925 | + } else { |
|
3926 | 3926 | return false; |
3927 | 3927 | } |
3928 | 3928 | } |
@@ -3934,7 +3934,7 @@ discard block |
||
3934 | 3934 | * @param $field_obj |
3935 | 3935 | * @return boolean |
3936 | 3936 | */ |
3937 | - public function is_primary_key_field( $field_obj ){ |
|
3937 | + public function is_primary_key_field($field_obj) { |
|
3938 | 3938 | return $field_obj instanceof EE_Primary_Key_Field_Base ? TRUE : FALSE; |
3939 | 3939 | } |
3940 | 3940 | |
@@ -3946,16 +3946,16 @@ discard block |
||
3946 | 3946 | * @return EE_Model_Field_Base |
3947 | 3947 | * @throws EE_Error |
3948 | 3948 | */ |
3949 | - public function get_primary_key_field(){ |
|
3950 | - if( $this->_primary_key_field === NULL ){ |
|
3951 | - foreach( $this->field_settings( TRUE ) as $field_obj ){ |
|
3952 | - if( $this->is_primary_key_field( $field_obj )){ |
|
3949 | + public function get_primary_key_field() { |
|
3950 | + if ($this->_primary_key_field === NULL) { |
|
3951 | + foreach ($this->field_settings(TRUE) as $field_obj) { |
|
3952 | + if ($this->is_primary_key_field($field_obj)) { |
|
3953 | 3953 | $this->_primary_key_field = $field_obj; |
3954 | 3954 | break; |
3955 | 3955 | } |
3956 | 3956 | } |
3957 | - if( ! $this->_primary_key_field instanceof EE_Primary_Key_Field_Base ){ |
|
3958 | - throw new EE_Error(sprintf(__("There is no Primary Key defined on model %s",'event_espresso'),get_class($this))); |
|
3957 | + if ( ! $this->_primary_key_field instanceof EE_Primary_Key_Field_Base) { |
|
3958 | + throw new EE_Error(sprintf(__("There is no Primary Key defined on model %s", 'event_espresso'), get_class($this))); |
|
3959 | 3959 | } |
3960 | 3960 | } |
3961 | 3961 | return $this->_primary_key_field; |
@@ -3968,12 +3968,12 @@ discard block |
||
3968 | 3968 | * Internally does some caching. |
3969 | 3969 | * @return boolean |
3970 | 3970 | */ |
3971 | - public function has_primary_key_field(){ |
|
3972 | - if($this->_has_primary_key_field === null){ |
|
3973 | - try{ |
|
3971 | + public function has_primary_key_field() { |
|
3972 | + if ($this->_has_primary_key_field === null) { |
|
3973 | + try { |
|
3974 | 3974 | $this->get_primary_key_field(); |
3975 | 3975 | $this->_has_primary_key_field = true; |
3976 | - }catch(EE_Error $e){ |
|
3976 | + } catch (EE_Error $e) { |
|
3977 | 3977 | $this->_has_primary_key_field = false; |
3978 | 3978 | } |
3979 | 3979 | } |
@@ -3987,9 +3987,9 @@ discard block |
||
3987 | 3987 | * @param string $field_class_name class name of field that you want to find. Eg, EE_Datetime_Field, EE_Foreign_Key_Field, etc |
3988 | 3988 | * @return EE_Model_Field_Base or null if none is found |
3989 | 3989 | */ |
3990 | - public function get_a_field_of_type($field_class_name){ |
|
3991 | - foreach($this->field_settings() as $field){ |
|
3992 | - if( $field instanceof $field_class_name ){ |
|
3990 | + public function get_a_field_of_type($field_class_name) { |
|
3991 | + foreach ($this->field_settings() as $field) { |
|
3992 | + if ($field instanceof $field_class_name) { |
|
3993 | 3993 | return $field; |
3994 | 3994 | } |
3995 | 3995 | } |
@@ -4003,22 +4003,22 @@ discard block |
||
4003 | 4003 | * @return EE_Foreign_Key_Field_Base |
4004 | 4004 | * @throws EE_Error |
4005 | 4005 | */ |
4006 | - public function get_foreign_key_to($model_name){ |
|
4007 | - if( ! isset( $this->_cache_foreign_key_to_fields[ $model_name ] ) ){ |
|
4008 | - foreach($this->field_settings() as $field){ |
|
4009 | - if( |
|
4006 | + public function get_foreign_key_to($model_name) { |
|
4007 | + if ( ! isset($this->_cache_foreign_key_to_fields[$model_name])) { |
|
4008 | + foreach ($this->field_settings() as $field) { |
|
4009 | + if ( |
|
4010 | 4010 | $field instanceof EE_Foreign_Key_Field_Base |
4011 | - && in_array($model_name,$field->get_model_names_pointed_to() ) |
|
4011 | + && in_array($model_name, $field->get_model_names_pointed_to()) |
|
4012 | 4012 | ) { |
4013 | - $this->_cache_foreign_key_to_fields[ $model_name ] = $field; |
|
4013 | + $this->_cache_foreign_key_to_fields[$model_name] = $field; |
|
4014 | 4014 | break; |
4015 | 4015 | } |
4016 | 4016 | } |
4017 | - if( ! isset( $this->_cache_foreign_key_to_fields[ $model_name ] ) ){ |
|
4018 | - 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))); |
|
4017 | + if ( ! isset($this->_cache_foreign_key_to_fields[$model_name])) { |
|
4018 | + 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))); |
|
4019 | 4019 | } |
4020 | 4020 | } |
4021 | - return $this->_cache_foreign_key_to_fields[ $model_name ]; |
|
4021 | + return $this->_cache_foreign_key_to_fields[$model_name]; |
|
4022 | 4022 | } |
4023 | 4023 | |
4024 | 4024 | |
@@ -4029,7 +4029,7 @@ discard block |
||
4029 | 4029 | * a table alias with a model chain prefix, like 'Venue__Event_Venue___Event_Meta'. Either one works |
4030 | 4030 | * @return EE_Table_Base |
4031 | 4031 | */ |
4032 | - public function get_table_for_alias($table_alias){ |
|
4032 | + public function get_table_for_alias($table_alias) { |
|
4033 | 4033 | $table_alias_sans_model_relation_chain_prefix = EE_Model_Parser::remove_table_alias_model_relation_chain_prefix($table_alias); |
4034 | 4034 | return $this->_tables[$table_alias_sans_model_relation_chain_prefix]->get_table_name(); |
4035 | 4035 | } |
@@ -4042,25 +4042,25 @@ discard block |
||
4042 | 4042 | * @param bool $include_db_only_fields flag indicating whether or not to include the db-only fields |
4043 | 4043 | * @return EE_Model_Field_Base[] where the keys are the field's name |
4044 | 4044 | */ |
4045 | - public function field_settings($include_db_only_fields = false){ |
|
4046 | - if( $include_db_only_fields ){ |
|
4047 | - if( $this->_cached_fields === NULL ){ |
|
4045 | + public function field_settings($include_db_only_fields = false) { |
|
4046 | + if ($include_db_only_fields) { |
|
4047 | + if ($this->_cached_fields === NULL) { |
|
4048 | 4048 | $this->_cached_fields = array(); |
4049 | - foreach($this->_fields as $fields_corresponding_to_table){ |
|
4050 | - foreach($fields_corresponding_to_table as $field_name => $field_obj){ |
|
4051 | - $this->_cached_fields[$field_name]=$field_obj; |
|
4049 | + foreach ($this->_fields as $fields_corresponding_to_table) { |
|
4050 | + foreach ($fields_corresponding_to_table as $field_name => $field_obj) { |
|
4051 | + $this->_cached_fields[$field_name] = $field_obj; |
|
4052 | 4052 | } |
4053 | 4053 | } |
4054 | 4054 | } |
4055 | 4055 | return $this->_cached_fields; |
4056 | - }else{ |
|
4057 | - if( $this->_cached_fields_non_db_only === NULL ){ |
|
4056 | + } else { |
|
4057 | + if ($this->_cached_fields_non_db_only === NULL) { |
|
4058 | 4058 | $this->_cached_fields_non_db_only = array(); |
4059 | - foreach($this->_fields as $fields_corresponding_to_table){ |
|
4060 | - foreach($fields_corresponding_to_table as $field_name => $field_obj){ |
|
4059 | + foreach ($this->_fields as $fields_corresponding_to_table) { |
|
4060 | + foreach ($fields_corresponding_to_table as $field_name => $field_obj) { |
|
4061 | 4061 | /** @var $field_obj EE_Model_Field_Base */ |
4062 | - if( ! $field_obj->is_db_only_field() ){ |
|
4063 | - $this->_cached_fields_non_db_only[$field_name]=$field_obj; |
|
4062 | + if ( ! $field_obj->is_db_only_field()) { |
|
4063 | + $this->_cached_fields_non_db_only[$field_name] = $field_obj; |
|
4064 | 4064 | } |
4065 | 4065 | } |
4066 | 4066 | } |
@@ -4079,60 +4079,60 @@ discard block |
||
4079 | 4079 | * @return \EE_Base_Class[] array keys are primary keys (if there is a primary key on the model. if not, numerically indexed) |
4080 | 4080 | * @throws \EE_Error |
4081 | 4081 | */ |
4082 | - protected function _create_objects( $rows = array() ) { |
|
4083 | - $array_of_objects=array(); |
|
4084 | - if(empty($rows)){ |
|
4082 | + protected function _create_objects($rows = array()) { |
|
4083 | + $array_of_objects = array(); |
|
4084 | + if (empty($rows)) { |
|
4085 | 4085 | return array(); |
4086 | 4086 | } |
4087 | 4087 | $count_if_model_has_no_primary_key = 0; |
4088 | 4088 | $has_primary_key = $this->has_primary_key_field(); |
4089 | 4089 | $primary_key_field = $has_primary_key ? $this->get_primary_key_field() : null; |
4090 | - foreach ( (array)$rows as $row ) { |
|
4091 | - if(empty($row)){ |
|
4090 | + foreach ((array) $rows as $row) { |
|
4091 | + if (empty($row)) { |
|
4092 | 4092 | //wp did its weird thing where it returns an array like array(0=>null), which is totally not helpful... |
4093 | 4093 | return array(); |
4094 | 4094 | } |
4095 | 4095 | //check if we've already set this object in the results array, |
4096 | 4096 | //in which case there's no need to process it further (again) |
4097 | - if( $has_primary_key ) { |
|
4097 | + if ($has_primary_key) { |
|
4098 | 4098 | $table_pk_value = $this->_get_column_value_with_table_alias_or_not( |
4099 | 4099 | $row, |
4100 | 4100 | $primary_key_field->get_qualified_column(), |
4101 | 4101 | $primary_key_field->get_table_column() |
4102 | 4102 | ); |
4103 | - if( $table_pk_value && isset( $array_of_objects[ $table_pk_value ] ) ) { |
|
4103 | + if ($table_pk_value && isset($array_of_objects[$table_pk_value])) { |
|
4104 | 4104 | continue; |
4105 | 4105 | } |
4106 | 4106 | } |
4107 | 4107 | $classInstance = $this->instantiate_class_from_array_or_object($row); |
4108 | - if( ! $classInstance ) { |
|
4108 | + if ( ! $classInstance) { |
|
4109 | 4109 | throw new EE_Error( |
4110 | 4110 | sprintf( |
4111 | - __( 'Could not create instance of class %s from row %s', 'event_espresso' ), |
|
4111 | + __('Could not create instance of class %s from row %s', 'event_espresso'), |
|
4112 | 4112 | $this->get_this_model_name(), |
4113 | - http_build_query( $row ) |
|
4113 | + http_build_query($row) |
|
4114 | 4114 | ) |
4115 | 4115 | ); |
4116 | 4116 | } |
4117 | 4117 | //set the timezone on the instantiated objects |
4118 | - $classInstance->set_timezone( $this->_timezone ); |
|
4118 | + $classInstance->set_timezone($this->_timezone); |
|
4119 | 4119 | //make sure if there is any timezone setting present that we set the timezone for the object |
4120 | 4120 | $key = $has_primary_key ? $classInstance->ID() : $count_if_model_has_no_primary_key++; |
4121 | - $array_of_objects[ $key ] = $classInstance; |
|
4121 | + $array_of_objects[$key] = $classInstance; |
|
4122 | 4122 | //also, for all the relations of type BelongsTo, see if we can cache |
4123 | 4123 | //those related models |
4124 | 4124 | //(we could do this for other relations too, but if there are conditions |
4125 | 4125 | //that filtered out some fo the results, then we'd be caching an incomplete set |
4126 | 4126 | //so it requires a little more thought than just caching them immediately...) |
4127 | - foreach($this->_model_relations as $modelName => $relation_obj){ |
|
4128 | - if( $relation_obj instanceof EE_Belongs_To_Relation){ |
|
4127 | + foreach ($this->_model_relations as $modelName => $relation_obj) { |
|
4128 | + if ($relation_obj instanceof EE_Belongs_To_Relation) { |
|
4129 | 4129 | //check if this model's INFO is present. If so, cache it on the model |
4130 | 4130 | $other_model = $relation_obj->get_other_model(); |
4131 | 4131 | $other_model_obj_maybe = $other_model->instantiate_class_from_array_or_object($row); |
4132 | 4132 | //if we managed to make a model object from the results, cache it on the main model object |
4133 | - if( $other_model_obj_maybe ){ |
|
4133 | + if ($other_model_obj_maybe) { |
|
4134 | 4134 | //set timezone on these other model objects if they are present |
4135 | - $other_model_obj_maybe->set_timezone( $this->_timezone ); |
|
4135 | + $other_model_obj_maybe->set_timezone($this->_timezone); |
|
4136 | 4136 | $classInstance->cache($modelName, $other_model_obj_maybe); |
4137 | 4137 | } |
4138 | 4138 | } |
@@ -4153,12 +4153,12 @@ discard block |
||
4153 | 4153 | |
4154 | 4154 | $this_model_fields_and_values = array(); |
4155 | 4155 | //setup the row using default values; |
4156 | - foreach ( $this->field_settings() as $field_name => $field_obj ) { |
|
4156 | + foreach ($this->field_settings() as $field_name => $field_obj) { |
|
4157 | 4157 | $this_model_fields_and_values[$field_name] = $field_obj->get_default_value(); |
4158 | 4158 | } |
4159 | 4159 | |
4160 | 4160 | $className = $this->_get_class_name(); |
4161 | - $classInstance = EE_Registry::instance()->load_class( $className, array( $this_model_fields_and_values ), FALSE, FALSE ); |
|
4161 | + $classInstance = EE_Registry::instance()->load_class($className, array($this_model_fields_and_values), FALSE, FALSE); |
|
4162 | 4162 | |
4163 | 4163 | return $classInstance; |
4164 | 4164 | } |
@@ -4171,45 +4171,45 @@ discard block |
||
4171 | 4171 | * @return EE_Base_Class |
4172 | 4172 | * @throws \EE_Error |
4173 | 4173 | */ |
4174 | - public function instantiate_class_from_array_or_object($cols_n_values){ |
|
4175 | - if( ! is_array( $cols_n_values ) && is_object( $cols_n_values )) { |
|
4176 | - $cols_n_values = get_object_vars( $cols_n_values ); |
|
4174 | + public function instantiate_class_from_array_or_object($cols_n_values) { |
|
4175 | + if ( ! is_array($cols_n_values) && is_object($cols_n_values)) { |
|
4176 | + $cols_n_values = get_object_vars($cols_n_values); |
|
4177 | 4177 | } |
4178 | 4178 | $primary_key = NULL; |
4179 | 4179 | //make sure the array only has keys that are fields/columns on this model |
4180 | - $this_model_fields_n_values = $this->_deduce_fields_n_values_from_cols_n_values( $cols_n_values ); |
|
4181 | - if( $this->has_primary_key_field() && isset( $this_model_fields_n_values[ $this->primary_key_name() ] ) ){ |
|
4182 | - $primary_key = $this_model_fields_n_values[ $this->primary_key_name() ]; |
|
4180 | + $this_model_fields_n_values = $this->_deduce_fields_n_values_from_cols_n_values($cols_n_values); |
|
4181 | + if ($this->has_primary_key_field() && isset($this_model_fields_n_values[$this->primary_key_name()])) { |
|
4182 | + $primary_key = $this_model_fields_n_values[$this->primary_key_name()]; |
|
4183 | 4183 | } |
4184 | - $className=$this->_get_class_name(); |
|
4184 | + $className = $this->_get_class_name(); |
|
4185 | 4185 | |
4186 | 4186 | //check we actually found results that we can use to build our model object |
4187 | 4187 | //if not, return null |
4188 | - if( $this->has_primary_key_field()){ |
|
4189 | - if(empty( $this_model_fields_n_values[$this->primary_key_name()] )){ |
|
4188 | + if ($this->has_primary_key_field()) { |
|
4189 | + if (empty($this_model_fields_n_values[$this->primary_key_name()])) { |
|
4190 | 4190 | return NULL; |
4191 | 4191 | } |
4192 | - }else if($this->unique_indexes()){ |
|
4192 | + } else if ($this->unique_indexes()) { |
|
4193 | 4193 | $first_column = reset($this_model_fields_n_values); |
4194 | - if(empty($first_column)){ |
|
4194 | + if (empty($first_column)) { |
|
4195 | 4195 | return NULL; |
4196 | 4196 | } |
4197 | 4197 | } |
4198 | 4198 | |
4199 | 4199 | // if there is no primary key or the object doesn't already exist in the entity map, then create a new instance |
4200 | - if ( $primary_key){ |
|
4201 | - $classInstance = $this->get_from_entity_map( $primary_key ); |
|
4202 | - if( ! $classInstance) { |
|
4203 | - $classInstance = EE_Registry::instance()->load_class( $className, array( $this_model_fields_n_values, $this->_timezone ), TRUE, FALSE ); |
|
4200 | + if ($primary_key) { |
|
4201 | + $classInstance = $this->get_from_entity_map($primary_key); |
|
4202 | + if ( ! $classInstance) { |
|
4203 | + $classInstance = EE_Registry::instance()->load_class($className, array($this_model_fields_n_values, $this->_timezone), TRUE, FALSE); |
|
4204 | 4204 | // add this new object to the entity map |
4205 | - $classInstance = $this->add_to_entity_map( $classInstance ); |
|
4205 | + $classInstance = $this->add_to_entity_map($classInstance); |
|
4206 | 4206 | } |
4207 | - }else{ |
|
4208 | - $classInstance = EE_Registry::instance()->load_class( $className, array( $this_model_fields_n_values, $this->_timezone ), TRUE, FALSE ); |
|
4207 | + } else { |
|
4208 | + $classInstance = EE_Registry::instance()->load_class($className, array($this_model_fields_n_values, $this->_timezone), TRUE, FALSE); |
|
4209 | 4209 | } |
4210 | 4210 | |
4211 | 4211 | //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. |
4212 | - $this->set_timezone( $classInstance->get_timezone() ); |
|
4212 | + $this->set_timezone($classInstance->get_timezone()); |
|
4213 | 4213 | return $classInstance; |
4214 | 4214 | } |
4215 | 4215 | /** |
@@ -4217,8 +4217,8 @@ discard block |
||
4217 | 4217 | * @param int|string $id the ID of the model object |
4218 | 4218 | * @return EE_Base_Class |
4219 | 4219 | */ |
4220 | - public function get_from_entity_map( $id ){ |
|
4221 | - return isset( $this->_entity_map[ EEM_Base::$_model_query_blog_id ][ $id ] ) ? $this->_entity_map[ EEM_Base::$_model_query_blog_id ][ $id ] : NULL; |
|
4220 | + public function get_from_entity_map($id) { |
|
4221 | + return isset($this->_entity_map[EEM_Base::$_model_query_blog_id][$id]) ? $this->_entity_map[EEM_Base::$_model_query_blog_id][$id] : NULL; |
|
4222 | 4222 | } |
4223 | 4223 | |
4224 | 4224 | |
@@ -4240,21 +4240,21 @@ discard block |
||
4240 | 4240 | * @throws EE_Error |
4241 | 4241 | * @return \EE_Base_Class |
4242 | 4242 | */ |
4243 | - public function add_to_entity_map( EE_Base_Class $object) { |
|
4243 | + public function add_to_entity_map(EE_Base_Class $object) { |
|
4244 | 4244 | $className = $this->_get_class_name(); |
4245 | - if( ! $object instanceof $className ){ |
|
4246 | - 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 ) ); |
|
4245 | + if ( ! $object instanceof $className) { |
|
4246 | + 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)); |
|
4247 | 4247 | } |
4248 | 4248 | /** @var $object EE_Base_Class */ |
4249 | - if ( ! $object->ID() ){ |
|
4250 | - throw new EE_Error(sprintf(__("You tried storing a model object with NO ID in the %s entity mapper.", "event_espresso"),get_class($this))); |
|
4249 | + if ( ! $object->ID()) { |
|
4250 | + throw new EE_Error(sprintf(__("You tried storing a model object with NO ID in the %s entity mapper.", "event_espresso"), get_class($this))); |
|
4251 | 4251 | } |
4252 | 4252 | // double check it's not already there |
4253 | - $classInstance = $this->get_from_entity_map( $object->ID() ); |
|
4254 | - if ( $classInstance ) { |
|
4253 | + $classInstance = $this->get_from_entity_map($object->ID()); |
|
4254 | + if ($classInstance) { |
|
4255 | 4255 | return $classInstance; |
4256 | 4256 | } else { |
4257 | - $this->_entity_map[ EEM_Base::$_model_query_blog_id ][ $object->ID() ] = $object; |
|
4257 | + $this->_entity_map[EEM_Base::$_model_query_blog_id][$object->ID()] = $object; |
|
4258 | 4258 | return $object; |
4259 | 4259 | } |
4260 | 4260 | } |
@@ -4268,13 +4268,13 @@ discard block |
||
4268 | 4268 | * @param int|string $id the ID of the model object |
4269 | 4269 | * @return boolean |
4270 | 4270 | */ |
4271 | - public function clear_entity_map( $id = null ) { |
|
4272 | - if ( empty( $id ) ) { |
|
4273 | - $this->_entity_map[ EEM_Base::$_model_query_blog_id ] = array(); |
|
4271 | + public function clear_entity_map($id = null) { |
|
4272 | + if (empty($id)) { |
|
4273 | + $this->_entity_map[EEM_Base::$_model_query_blog_id] = array(); |
|
4274 | 4274 | return true; |
4275 | 4275 | } |
4276 | - if ( isset( $this->_entity_map[ EEM_Base::$_model_query_blog_id ][ $id ] ) ) { |
|
4277 | - unset( $this->_entity_map[ EEM_Base::$_model_query_blog_id ][ $id ] ); |
|
4276 | + if (isset($this->_entity_map[EEM_Base::$_model_query_blog_id][$id])) { |
|
4277 | + unset($this->_entity_map[EEM_Base::$_model_query_blog_id][$id]); |
|
4278 | 4278 | return true; |
4279 | 4279 | } |
4280 | 4280 | return false; |
@@ -4290,8 +4290,8 @@ discard block |
||
4290 | 4290 | * @param array $cols_n_values |
4291 | 4291 | * @return array |
4292 | 4292 | */ |
4293 | - public function deduce_fields_n_values_from_cols_n_values( $cols_n_values ) { |
|
4294 | - return $this->_deduce_fields_n_values_from_cols_n_values( $cols_n_values ); |
|
4293 | + public function deduce_fields_n_values_from_cols_n_values($cols_n_values) { |
|
4294 | + return $this->_deduce_fields_n_values_from_cols_n_values($cols_n_values); |
|
4295 | 4295 | } |
4296 | 4296 | |
4297 | 4297 | |
@@ -4304,23 +4304,23 @@ discard block |
||
4304 | 4304 | * @param string $cols_n_values |
4305 | 4305 | * @return array |
4306 | 4306 | */ |
4307 | - protected function _deduce_fields_n_values_from_cols_n_values( $cols_n_values ){ |
|
4307 | + protected function _deduce_fields_n_values_from_cols_n_values($cols_n_values) { |
|
4308 | 4308 | $this_model_fields_n_values = array(); |
4309 | - foreach( $this->get_tables() as $table_alias => $table_obj ) { |
|
4310 | - $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() ); |
|
4309 | + foreach ($this->get_tables() as $table_alias => $table_obj) { |
|
4310 | + $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()); |
|
4311 | 4311 | //there is a primary key on this table and its not set. Use defaults for all its columns |
4312 | - if( $table_pk_value === null && $table_obj->get_pk_column() ){ |
|
4313 | - foreach( $this->_get_fields_for_table( $table_alias ) as $field_name => $field_obj ) { |
|
4314 | - if( ! $field_obj->is_db_only_field() ){ |
|
4312 | + if ($table_pk_value === null && $table_obj->get_pk_column()) { |
|
4313 | + foreach ($this->_get_fields_for_table($table_alias) as $field_name => $field_obj) { |
|
4314 | + if ( ! $field_obj->is_db_only_field()) { |
|
4315 | 4315 | //prepare field as if its coming from db |
4316 | - $prepared_value = $field_obj->prepare_for_set( $field_obj->get_default_value() ); |
|
4317 | - $this_model_fields_n_values[$field_name] = $field_obj->prepare_for_use_in_db( $prepared_value ); |
|
4316 | + $prepared_value = $field_obj->prepare_for_set($field_obj->get_default_value()); |
|
4317 | + $this_model_fields_n_values[$field_name] = $field_obj->prepare_for_use_in_db($prepared_value); |
|
4318 | 4318 | } |
4319 | 4319 | } |
4320 | - }else{ |
|
4320 | + } else { |
|
4321 | 4321 | //the table's rows existed. Use their values |
4322 | - foreach( $this->_get_fields_for_table( $table_alias ) as $field_name => $field_obj ) { |
|
4323 | - if( ! $field_obj->is_db_only_field() ){ |
|
4322 | + foreach ($this->_get_fields_for_table($table_alias) as $field_name => $field_obj) { |
|
4323 | + if ( ! $field_obj->is_db_only_field()) { |
|
4324 | 4324 | $this_model_fields_n_values[$field_name] = $this->_get_column_value_with_table_alias_or_not( |
4325 | 4325 | $cols_n_values, $field_obj->get_qualified_column(), |
4326 | 4326 | $field_obj->get_table_column() |
@@ -4340,15 +4340,15 @@ discard block |
||
4340 | 4340 | * @param $regular_column |
4341 | 4341 | * @return null |
4342 | 4342 | */ |
4343 | - protected function _get_column_value_with_table_alias_or_not( $cols_n_values, $qualified_column, $regular_column ){ |
|
4343 | + protected function _get_column_value_with_table_alias_or_not($cols_n_values, $qualified_column, $regular_column) { |
|
4344 | 4344 | $value = null; |
4345 | 4345 | //ask the field what it think it's table_name.column_name should be, and call it the "qualified column" |
4346 | 4346 | //does the field on the model relate to this column retrieved from the db? |
4347 | 4347 | //or is it a db-only field? (not relating to the model) |
4348 | - if( isset( $cols_n_values[ $qualified_column ] ) ){ |
|
4349 | - $value = $cols_n_values[ $qualified_column ]; |
|
4350 | - }elseif( isset( $cols_n_values[ $regular_column ] ) ){ |
|
4351 | - $value = $cols_n_values[ $regular_column ]; |
|
4348 | + if (isset($cols_n_values[$qualified_column])) { |
|
4349 | + $value = $cols_n_values[$qualified_column]; |
|
4350 | + }elseif (isset($cols_n_values[$regular_column])) { |
|
4351 | + $value = $cols_n_values[$regular_column]; |
|
4352 | 4352 | } |
4353 | 4353 | return $value; |
4354 | 4354 | } |
@@ -4364,25 +4364,25 @@ discard block |
||
4364 | 4364 | * @return EE_Base_Class |
4365 | 4365 | * @throws \EE_Error |
4366 | 4366 | */ |
4367 | - public function refresh_entity_map_from_db( $id ){ |
|
4368 | - $obj_in_map = $this->get_from_entity_map( $id ); |
|
4369 | - if( $obj_in_map ){ |
|
4367 | + public function refresh_entity_map_from_db($id) { |
|
4368 | + $obj_in_map = $this->get_from_entity_map($id); |
|
4369 | + if ($obj_in_map) { |
|
4370 | 4370 | $wpdb_results = $this->_get_all_wpdb_results( |
4371 | - array( array( $this->get_primary_key_field()->get_name() => $id ), 'limit' => 1 ) |
|
4371 | + array(array($this->get_primary_key_field()->get_name() => $id), 'limit' => 1) |
|
4372 | 4372 | ); |
4373 | - if( $wpdb_results && is_array( $wpdb_results ) ){ |
|
4374 | - $one_row = reset( $wpdb_results ); |
|
4375 | - foreach( $this->_deduce_fields_n_values_from_cols_n_values($one_row ) as $field_name => $db_value ) { |
|
4376 | - $obj_in_map->set_from_db( $field_name, $db_value ); |
|
4373 | + if ($wpdb_results && is_array($wpdb_results)) { |
|
4374 | + $one_row = reset($wpdb_results); |
|
4375 | + foreach ($this->_deduce_fields_n_values_from_cols_n_values($one_row) as $field_name => $db_value) { |
|
4376 | + $obj_in_map->set_from_db($field_name, $db_value); |
|
4377 | 4377 | } |
4378 | 4378 | //clear the cache of related model objects |
4379 | - foreach ( $this->relation_settings() as $relation_name => $relation_obj ){ |
|
4380 | - $obj_in_map->clear_cache($relation_name, NULL, TRUE ); |
|
4379 | + foreach ($this->relation_settings() as $relation_name => $relation_obj) { |
|
4380 | + $obj_in_map->clear_cache($relation_name, NULL, TRUE); |
|
4381 | 4381 | } |
4382 | 4382 | } |
4383 | 4383 | return $obj_in_map; |
4384 | - }else{ |
|
4385 | - return $this->get_one_by_ID( $id ); |
|
4384 | + } else { |
|
4385 | + return $this->get_one_by_ID($id); |
|
4386 | 4386 | } |
4387 | 4387 | } |
4388 | 4388 | |
@@ -4400,24 +4400,24 @@ discard block |
||
4400 | 4400 | * @return \EE_Base_Class |
4401 | 4401 | * @throws \EE_Error |
4402 | 4402 | */ |
4403 | - public function refresh_entity_map_with( $id, $replacing_model_obj ) { |
|
4404 | - $obj_in_map = $this->get_from_entity_map( $id ); |
|
4405 | - if( $obj_in_map ){ |
|
4406 | - if( $replacing_model_obj instanceof EE_Base_Class ){ |
|
4407 | - foreach( $replacing_model_obj->model_field_array() as $field_name => $value ) { |
|
4408 | - $obj_in_map->set( $field_name, $value ); |
|
4403 | + public function refresh_entity_map_with($id, $replacing_model_obj) { |
|
4404 | + $obj_in_map = $this->get_from_entity_map($id); |
|
4405 | + if ($obj_in_map) { |
|
4406 | + if ($replacing_model_obj instanceof EE_Base_Class) { |
|
4407 | + foreach ($replacing_model_obj->model_field_array() as $field_name => $value) { |
|
4408 | + $obj_in_map->set($field_name, $value); |
|
4409 | 4409 | } |
4410 | 4410 | //make the model object in the entity map's cache match the $replacing_model_obj |
4411 | - foreach ( $this->relation_settings() as $relation_name => $relation_obj ){ |
|
4412 | - $obj_in_map->clear_cache($relation_name, NULL, TRUE ); |
|
4413 | - foreach( $replacing_model_obj->get_all_from_cache( $relation_name ) as $cache_id => $cached_obj ) { |
|
4414 | - $obj_in_map->cache( $relation_name, $cached_obj, $cache_id ); |
|
4411 | + foreach ($this->relation_settings() as $relation_name => $relation_obj) { |
|
4412 | + $obj_in_map->clear_cache($relation_name, NULL, TRUE); |
|
4413 | + foreach ($replacing_model_obj->get_all_from_cache($relation_name) as $cache_id => $cached_obj) { |
|
4414 | + $obj_in_map->cache($relation_name, $cached_obj, $cache_id); |
|
4415 | 4415 | } |
4416 | 4416 | } |
4417 | 4417 | } |
4418 | 4418 | return $obj_in_map; |
4419 | - }else{ |
|
4420 | - $this->add_to_entity_map( $replacing_model_obj ); |
|
4419 | + } else { |
|
4420 | + $this->add_to_entity_map($replacing_model_obj); |
|
4421 | 4421 | return $replacing_model_obj; |
4422 | 4422 | } |
4423 | 4423 | } |
@@ -4430,7 +4430,7 @@ discard block |
||
4430 | 4430 | * require_once($this->_getClassName().".class.php"); |
4431 | 4431 | * @return string |
4432 | 4432 | */ |
4433 | - private function _get_class_name(){ |
|
4433 | + private function _get_class_name() { |
|
4434 | 4434 | return "EE_".$this->get_this_model_name(); |
4435 | 4435 | } |
4436 | 4436 | |
@@ -4443,8 +4443,8 @@ discard block |
||
4443 | 4443 | * @param int $quantity |
4444 | 4444 | * @return string |
4445 | 4445 | */ |
4446 | - public function item_name($quantity = 1){ |
|
4447 | - return (int)$quantity === 1 ? $this->singular_item : $this->plural_item; |
|
4446 | + public function item_name($quantity = 1) { |
|
4447 | + return (int) $quantity === 1 ? $this->singular_item : $this->plural_item; |
|
4448 | 4448 | } |
4449 | 4449 | |
4450 | 4450 | |
@@ -4471,13 +4471,13 @@ discard block |
||
4471 | 4471 | * @throws EE_Error |
4472 | 4472 | * @return mixed whatever the plugin which calls add_filter decides |
4473 | 4473 | */ |
4474 | - public function __call($methodName,$args){ |
|
4475 | - $className=get_class($this); |
|
4476 | - $tagName="FHEE__{$className}__{$methodName}"; |
|
4477 | - if(!has_filter($tagName)){ |
|
4474 | + public function __call($methodName, $args) { |
|
4475 | + $className = get_class($this); |
|
4476 | + $tagName = "FHEE__{$className}__{$methodName}"; |
|
4477 | + if ( ! has_filter($tagName)) { |
|
4478 | 4478 | throw new EE_Error( |
4479 | 4479 | sprintf( |
4480 | - __( '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' ), |
|
4480 | + __('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'), |
|
4481 | 4481 | $methodName, |
4482 | 4482 | $className, |
4483 | 4483 | $tagName, |
@@ -4486,7 +4486,7 @@ discard block |
||
4486 | 4486 | ); |
4487 | 4487 | } |
4488 | 4488 | |
4489 | - return apply_filters($tagName,null,$this,$args); |
|
4489 | + return apply_filters($tagName, null, $this, $args); |
|
4490 | 4490 | } |
4491 | 4491 | |
4492 | 4492 | |
@@ -4504,28 +4504,28 @@ discard block |
||
4504 | 4504 | * @throws EE_Error |
4505 | 4505 | * @return EE_Base_Class |
4506 | 4506 | */ |
4507 | - public function ensure_is_obj( $base_class_obj_or_id, $ensure_is_in_db = FALSE ){ |
|
4507 | + public function ensure_is_obj($base_class_obj_or_id, $ensure_is_in_db = FALSE) { |
|
4508 | 4508 | $className = $this->_get_class_name(); |
4509 | - if ( $base_class_obj_or_id instanceof $className ) { |
|
4509 | + if ($base_class_obj_or_id instanceof $className) { |
|
4510 | 4510 | $model_object = $base_class_obj_or_id; |
4511 | 4511 | } else { |
4512 | 4512 | $primary_key_field = $this->get_primary_key_field(); |
4513 | 4513 | if ( |
4514 | 4514 | $primary_key_field instanceof EE_Primary_Key_Int_Field |
4515 | 4515 | && ( |
4516 | - is_int( $base_class_obj_or_id ) |
|
4517 | - || is_string( $base_class_obj_or_id ) |
|
4516 | + is_int($base_class_obj_or_id) |
|
4517 | + || is_string($base_class_obj_or_id) |
|
4518 | 4518 | ) |
4519 | 4519 | ) { |
4520 | 4520 | // assume it's an ID. |
4521 | 4521 | // either a proper integer or a string representing an integer (eg "101" instead of 101) |
4522 | - $model_object = $this->get_one_by_ID( $base_class_obj_or_id ); |
|
4522 | + $model_object = $this->get_one_by_ID($base_class_obj_or_id); |
|
4523 | 4523 | } else if ( |
4524 | 4524 | $primary_key_field instanceof EE_Primary_Key_String_Field |
4525 | - && is_string( $base_class_obj_or_id ) |
|
4525 | + && is_string($base_class_obj_or_id) |
|
4526 | 4526 | ) { |
4527 | 4527 | // assume its a string representation of the object |
4528 | - $model_object = $this->get_one_by_ID( $base_class_obj_or_id ); |
|
4528 | + $model_object = $this->get_one_by_ID($base_class_obj_or_id); |
|
4529 | 4529 | } else { |
4530 | 4530 | throw new EE_Error( |
4531 | 4531 | sprintf( |
@@ -4535,12 +4535,12 @@ discard block |
||
4535 | 4535 | ), |
4536 | 4536 | $base_class_obj_or_id, |
4537 | 4537 | $this->_get_class_name(), |
4538 | - print_r( $base_class_obj_or_id, true ) |
|
4538 | + print_r($base_class_obj_or_id, true) |
|
4539 | 4539 | ) |
4540 | 4540 | ); |
4541 | 4541 | } |
4542 | 4542 | } |
4543 | - if ( $ensure_is_in_db && $model_object->ID() !== null ) { |
|
4543 | + if ($ensure_is_in_db && $model_object->ID() !== null) { |
|
4544 | 4544 | $model_object->save(); |
4545 | 4545 | } |
4546 | 4546 | return $model_object; |
@@ -4556,19 +4556,19 @@ discard block |
||
4556 | 4556 | * @return int|string depending on the type of this model object's ID |
4557 | 4557 | * @throws EE_Error |
4558 | 4558 | */ |
4559 | - public function ensure_is_ID($base_class_obj_or_id){ |
|
4559 | + public function ensure_is_ID($base_class_obj_or_id) { |
|
4560 | 4560 | $className = $this->_get_class_name(); |
4561 | - if( $base_class_obj_or_id instanceof $className ){ |
|
4561 | + if ($base_class_obj_or_id instanceof $className) { |
|
4562 | 4562 | /** @var $base_class_obj_or_id EE_Base_Class */ |
4563 | 4563 | $id = $base_class_obj_or_id->ID(); |
4564 | - }elseif(is_int($base_class_obj_or_id)){ |
|
4564 | + }elseif (is_int($base_class_obj_or_id)) { |
|
4565 | 4565 | //assume it's an ID |
4566 | 4566 | $id = $base_class_obj_or_id; |
4567 | - }elseif(is_string($base_class_obj_or_id)){ |
|
4567 | + }elseif (is_string($base_class_obj_or_id)) { |
|
4568 | 4568 | //assume its a string representation of the object |
4569 | 4569 | $id = $base_class_obj_or_id; |
4570 | - }else{ |
|
4571 | - 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))); |
|
4570 | + } else { |
|
4571 | + 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))); |
|
4572 | 4572 | } |
4573 | 4573 | return $id; |
4574 | 4574 | } |
@@ -4591,14 +4591,14 @@ discard block |
||
4591 | 4591 | * @param int $values_already_prepared like one of the constants on EEM_Base |
4592 | 4592 | * @return void |
4593 | 4593 | */ |
4594 | - public function assume_values_already_prepared_by_model_object($values_already_prepared = self::not_prepared_by_model_object){ |
|
4594 | + public function assume_values_already_prepared_by_model_object($values_already_prepared = self::not_prepared_by_model_object) { |
|
4595 | 4595 | $this->_values_already_prepared_by_model_object = $values_already_prepared; |
4596 | 4596 | } |
4597 | 4597 | /** |
4598 | 4598 | * Read comments for assume_values_already_prepared_by_model_object() |
4599 | 4599 | * @return int |
4600 | 4600 | */ |
4601 | - public function get_assumption_concerning_values_already_prepared_by_model_object(){ |
|
4601 | + public function get_assumption_concerning_values_already_prepared_by_model_object() { |
|
4602 | 4602 | return $this->_values_already_prepared_by_model_object; |
4603 | 4603 | } |
4604 | 4604 | |
@@ -4606,17 +4606,17 @@ discard block |
||
4606 | 4606 | * Gets all the indexes on this model |
4607 | 4607 | * @return EE_Index[] |
4608 | 4608 | */ |
4609 | - public function indexes(){ |
|
4609 | + public function indexes() { |
|
4610 | 4610 | return $this->_indexes; |
4611 | 4611 | } |
4612 | 4612 | /** |
4613 | 4613 | * Gets all the Unique Indexes on this model |
4614 | 4614 | * @return EE_Unique_Index[] |
4615 | 4615 | */ |
4616 | - public function unique_indexes(){ |
|
4616 | + public function unique_indexes() { |
|
4617 | 4617 | $unique_indexes = array(); |
4618 | - foreach($this->_indexes as $name => $index){ |
|
4619 | - if($index instanceof EE_Unique_Index){ |
|
4618 | + foreach ($this->_indexes as $name => $index) { |
|
4619 | + if ($index instanceof EE_Unique_Index) { |
|
4620 | 4620 | $unique_indexes [$name] = $index; |
4621 | 4621 | } |
4622 | 4622 | } |
@@ -4634,13 +4634,13 @@ discard block |
||
4634 | 4634 | * @return EE_Model_Field_Base[] indexed by the field's name |
4635 | 4635 | * @throws \EE_Error |
4636 | 4636 | */ |
4637 | - public function get_combined_primary_key_fields(){ |
|
4638 | - foreach($this->indexes() as $index){ |
|
4639 | - if($index instanceof EE_Primary_Key_Index){ |
|
4637 | + public function get_combined_primary_key_fields() { |
|
4638 | + foreach ($this->indexes() as $index) { |
|
4639 | + if ($index instanceof EE_Primary_Key_Index) { |
|
4640 | 4640 | return $index->fields(); |
4641 | 4641 | } |
4642 | 4642 | } |
4643 | - return array( $this->primary_key_name() => $this->get_primary_key_field()); |
|
4643 | + return array($this->primary_key_name() => $this->get_primary_key_field()); |
|
4644 | 4644 | } |
4645 | 4645 | |
4646 | 4646 | |
@@ -4654,7 +4654,7 @@ discard block |
||
4654 | 4654 | * @return string |
4655 | 4655 | * @throws \EE_Error |
4656 | 4656 | */ |
4657 | - public function get_index_primary_key_string($cols_n_values){ |
|
4657 | + public function get_index_primary_key_string($cols_n_values) { |
|
4658 | 4658 | $cols_n_values_for_primary_key_index = array_intersect_key($cols_n_values, $this->get_combined_primary_key_fields()); |
4659 | 4659 | return http_build_query($cols_n_values_for_primary_key_index); |
4660 | 4660 | } |
@@ -4669,13 +4669,13 @@ discard block |
||
4669 | 4669 | * @return null|array |
4670 | 4670 | * @throws \EE_Error |
4671 | 4671 | */ |
4672 | - public function parse_index_primary_key_string( $index_primary_key_string) { |
|
4672 | + public function parse_index_primary_key_string($index_primary_key_string) { |
|
4673 | 4673 | $key_fields = $this->get_combined_primary_key_fields(); |
4674 | 4674 | //check all of them are in the $id |
4675 | 4675 | $key_vals_in_combined_pk = array(); |
4676 | - parse_str( $index_primary_key_string, $key_vals_in_combined_pk ); |
|
4677 | - foreach( $key_fields as $key_field_name => $field_obj ) { |
|
4678 | - if( ! isset( $key_vals_in_combined_pk[ $key_field_name ] ) ){ |
|
4676 | + parse_str($index_primary_key_string, $key_vals_in_combined_pk); |
|
4677 | + foreach ($key_fields as $key_field_name => $field_obj) { |
|
4678 | + if ( ! isset($key_vals_in_combined_pk[$key_field_name])) { |
|
4679 | 4679 | return NULL; |
4680 | 4680 | } |
4681 | 4681 | } |
@@ -4692,10 +4692,10 @@ discard block |
||
4692 | 4692 | * @return boolean |
4693 | 4693 | * @throws \EE_Error |
4694 | 4694 | */ |
4695 | - public function has_all_combined_primary_key_fields( $key_vals ) { |
|
4696 | - $keys_it_should_have = array_keys( $this->get_combined_primary_key_fields() ); |
|
4697 | - foreach( $keys_it_should_have as $key ){ |
|
4698 | - if( ! isset( $key_vals[ $key ] ) ){ |
|
4695 | + public function has_all_combined_primary_key_fields($key_vals) { |
|
4696 | + $keys_it_should_have = array_keys($this->get_combined_primary_key_fields()); |
|
4697 | + foreach ($keys_it_should_have as $key) { |
|
4698 | + if ( ! isset($key_vals[$key])) { |
|
4699 | 4699 | return false; |
4700 | 4700 | } |
4701 | 4701 | } |
@@ -4711,23 +4711,23 @@ discard block |
||
4711 | 4711 | * @throws EE_Error |
4712 | 4712 | * @return \EE_Base_Class[] Array keys are object IDs (if there is a primary key on the model. if not, numerically indexed) |
4713 | 4713 | */ |
4714 | - public function get_all_copies($model_object_or_attributes_array, $query_params = array()){ |
|
4714 | + public function get_all_copies($model_object_or_attributes_array, $query_params = array()) { |
|
4715 | 4715 | |
4716 | - if($model_object_or_attributes_array instanceof EE_Base_Class){ |
|
4716 | + if ($model_object_or_attributes_array instanceof EE_Base_Class) { |
|
4717 | 4717 | $attributes_array = $model_object_or_attributes_array->model_field_array(); |
4718 | - }elseif(is_array($model_object_or_attributes_array)){ |
|
4718 | + }elseif (is_array($model_object_or_attributes_array)) { |
|
4719 | 4719 | $attributes_array = $model_object_or_attributes_array; |
4720 | - }else{ |
|
4721 | - 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)); |
|
4720 | + } else { |
|
4721 | + 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)); |
|
4722 | 4722 | } |
4723 | 4723 | //even copies obviously won't have the same ID, so remove the primary key |
4724 | 4724 | //from the WHERE conditions for finding copies (if there is a primary key, of course) |
4725 | - if($this->has_primary_key_field() && isset($attributes_array[$this->primary_key_name()])){ |
|
4725 | + if ($this->has_primary_key_field() && isset($attributes_array[$this->primary_key_name()])) { |
|
4726 | 4726 | unset($attributes_array[$this->primary_key_name()]); |
4727 | 4727 | } |
4728 | - if(isset($query_params[0])){ |
|
4729 | - $query_params[0] = array_merge($attributes_array,$query_params); |
|
4730 | - }else{ |
|
4728 | + if (isset($query_params[0])) { |
|
4729 | + $query_params[0] = array_merge($attributes_array, $query_params); |
|
4730 | + } else { |
|
4731 | 4731 | $query_params[0] = $attributes_array; |
4732 | 4732 | } |
4733 | 4733 | return $this->get_all($query_params); |
@@ -4743,16 +4743,16 @@ discard block |
||
4743 | 4743 | * @return EE_Base_Class |
4744 | 4744 | * @throws \EE_Error |
4745 | 4745 | */ |
4746 | - public function get_one_copy($model_object_or_attributes_array,$query_params = array()){ |
|
4747 | - if( ! is_array( $query_params ) ){ |
|
4748 | - 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' ); |
|
4746 | + public function get_one_copy($model_object_or_attributes_array, $query_params = array()) { |
|
4747 | + if ( ! is_array($query_params)) { |
|
4748 | + 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'); |
|
4749 | 4749 | $query_params = array(); |
4750 | 4750 | } |
4751 | 4751 | $query_params['limit'] = 1; |
4752 | - $copies = $this->get_all_copies($model_object_or_attributes_array,$query_params); |
|
4753 | - if(is_array($copies)){ |
|
4752 | + $copies = $this->get_all_copies($model_object_or_attributes_array, $query_params); |
|
4753 | + if (is_array($copies)) { |
|
4754 | 4754 | return array_shift($copies); |
4755 | - }else{ |
|
4755 | + } else { |
|
4756 | 4756 | return null; |
4757 | 4757 | } |
4758 | 4758 | } |
@@ -4768,10 +4768,10 @@ discard block |
||
4768 | 4768 | * @return int number of rows updated |
4769 | 4769 | * @throws \EE_Error |
4770 | 4770 | */ |
4771 | - public function update_by_ID($fields_n_values,$id){ |
|
4771 | + public function update_by_ID($fields_n_values, $id) { |
|
4772 | 4772 | $query_params = array(0=>array($this->get_primary_key_field()->get_name() => $id), |
4773 | 4773 | 'default_where_conditions'=>'other_models_only',); |
4774 | - return $this->update($fields_n_values,$query_params); |
|
4774 | + return $this->update($fields_n_values, $query_params); |
|
4775 | 4775 | } |
4776 | 4776 | |
4777 | 4777 | |
@@ -4782,12 +4782,12 @@ discard block |
||
4782 | 4782 | * @return string an operator which can be used in SQL |
4783 | 4783 | * @throws EE_Error |
4784 | 4784 | */ |
4785 | - private function _prepare_operator_for_sql($operator_supplied){ |
|
4785 | + private function _prepare_operator_for_sql($operator_supplied) { |
|
4786 | 4786 | $sql_operator = isset($this->_valid_operators[$operator_supplied]) ? $this->_valid_operators[$operator_supplied] : null; |
4787 | - if($sql_operator){ |
|
4787 | + if ($sql_operator) { |
|
4788 | 4788 | return $sql_operator; |
4789 | - }else{ |
|
4790 | - 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)))); |
|
4789 | + } else { |
|
4790 | + 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)))); |
|
4791 | 4791 | } |
4792 | 4792 | } |
4793 | 4793 | |
@@ -4801,10 +4801,10 @@ discard block |
||
4801 | 4801 | * @return string[] |
4802 | 4802 | * @throws \EE_Error |
4803 | 4803 | */ |
4804 | - public function get_all_names($query_params = array()){ |
|
4804 | + public function get_all_names($query_params = array()) { |
|
4805 | 4805 | $objs = $this->get_all($query_params); |
4806 | 4806 | $names = array(); |
4807 | - foreach($objs as $obj){ |
|
4807 | + foreach ($objs as $obj) { |
|
4808 | 4808 | $names[$obj->ID()] = $obj->name(); |
4809 | 4809 | } |
4810 | 4810 | return $names; |
@@ -4823,11 +4823,11 @@ discard block |
||
4823 | 4823 | * @return array |
4824 | 4824 | * @throws \EE_Error |
4825 | 4825 | */ |
4826 | - public function get_IDs( $model_objects, $filter_out_empty_ids = false) { |
|
4827 | - if( ! $this->has_primary_key_field() ) { |
|
4828 | - if( WP_DEBUG ) { |
|
4826 | + public function get_IDs($model_objects, $filter_out_empty_ids = false) { |
|
4827 | + if ( ! $this->has_primary_key_field()) { |
|
4828 | + if (WP_DEBUG) { |
|
4829 | 4829 | EE_Error::add_error( |
4830 | - __( 'Trying to get IDs from a model than has no primary key', 'event_espresso' ), |
|
4830 | + __('Trying to get IDs from a model than has no primary key', 'event_espresso'), |
|
4831 | 4831 | __FILE__, |
4832 | 4832 | __FUNCTION__, |
4833 | 4833 | __LINE__ |
@@ -4835,13 +4835,13 @@ discard block |
||
4835 | 4835 | } |
4836 | 4836 | } |
4837 | 4837 | $IDs = array(); |
4838 | - foreach( $model_objects as $model_object ) { |
|
4838 | + foreach ($model_objects as $model_object) { |
|
4839 | 4839 | $id = $model_object->ID(); |
4840 | - if( ! $id ) { |
|
4841 | - if( $filter_out_empty_ids ) { |
|
4840 | + if ( ! $id) { |
|
4841 | + if ($filter_out_empty_ids) { |
|
4842 | 4842 | continue; |
4843 | 4843 | } |
4844 | - if ( WP_DEBUG ) { |
|
4844 | + if (WP_DEBUG) { |
|
4845 | 4845 | EE_Error::add_error( |
4846 | 4846 | __( |
4847 | 4847 | 'Called %1$s on a model object that has no ID and so probably hasn\'t been saved to the database', |
@@ -4863,8 +4863,8 @@ discard block |
||
4863 | 4863 | * are no capabilities that relate to this model returns false |
4864 | 4864 | * @return string|false |
4865 | 4865 | */ |
4866 | - public function cap_slug(){ |
|
4867 | - return apply_filters( 'FHEE__EEM_Base__cap_slug', $this->_caps_slug, $this); |
|
4866 | + public function cap_slug() { |
|
4867 | + return apply_filters('FHEE__EEM_Base__cap_slug', $this->_caps_slug, $this); |
|
4868 | 4868 | } |
4869 | 4869 | |
4870 | 4870 | |
@@ -4879,34 +4879,34 @@ discard block |
||
4879 | 4879 | * @return EE_Default_Where_Conditions[] indexed by associated capability |
4880 | 4880 | * @throws \EE_Error |
4881 | 4881 | */ |
4882 | - public function cap_restrictions( $context = EEM_Base::caps_read ) { |
|
4883 | - EEM_Base::verify_is_valid_cap_context( $context ); |
|
4882 | + public function cap_restrictions($context = EEM_Base::caps_read) { |
|
4883 | + EEM_Base::verify_is_valid_cap_context($context); |
|
4884 | 4884 | //check if we ought to run the restriction generator first |
4885 | - if( |
|
4886 | - isset( $this->_cap_restriction_generators[ $context ] ) |
|
4887 | - && $this->_cap_restriction_generators[ $context ] instanceof EE_Restriction_Generator_Base |
|
4888 | - && ! $this->_cap_restriction_generators[ $context ]->has_generated_cap_restrictions() |
|
4885 | + if ( |
|
4886 | + isset($this->_cap_restriction_generators[$context]) |
|
4887 | + && $this->_cap_restriction_generators[$context] instanceof EE_Restriction_Generator_Base |
|
4888 | + && ! $this->_cap_restriction_generators[$context]->has_generated_cap_restrictions() |
|
4889 | 4889 | ) { |
4890 | - $this->_cap_restrictions[ $context ] = array_merge( |
|
4891 | - $this->_cap_restrictions[ $context ], |
|
4892 | - $this->_cap_restriction_generators[ $context ]->generate_restrictions() |
|
4890 | + $this->_cap_restrictions[$context] = array_merge( |
|
4891 | + $this->_cap_restrictions[$context], |
|
4892 | + $this->_cap_restriction_generators[$context]->generate_restrictions() |
|
4893 | 4893 | ); |
4894 | 4894 | } |
4895 | 4895 | //and make sure we've finalized the construction of each restriction |
4896 | - foreach( $this->_cap_restrictions[ $context ] as $where_conditions_obj ) { |
|
4897 | - if ( $where_conditions_obj instanceof EE_Default_Where_Conditions ) { |
|
4898 | - $where_conditions_obj->_finalize_construct( $this ); |
|
4896 | + foreach ($this->_cap_restrictions[$context] as $where_conditions_obj) { |
|
4897 | + if ($where_conditions_obj instanceof EE_Default_Where_Conditions) { |
|
4898 | + $where_conditions_obj->_finalize_construct($this); |
|
4899 | 4899 | } |
4900 | 4900 | } |
4901 | 4901 | |
4902 | - return $this->_cap_restrictions[ $context ]; |
|
4902 | + return $this->_cap_restrictions[$context]; |
|
4903 | 4903 | } |
4904 | 4904 | |
4905 | 4905 | /** |
4906 | 4906 | * Indicating whether or not this model thinks its a wp core model |
4907 | 4907 | * @return boolean |
4908 | 4908 | */ |
4909 | - public function is_wp_core_model(){ |
|
4909 | + public function is_wp_core_model() { |
|
4910 | 4910 | return $this->_wp_core_model; |
4911 | 4911 | } |
4912 | 4912 | |
@@ -4920,12 +4920,12 @@ discard block |
||
4920 | 4920 | * @return EE_Default_Where_Conditions[] indexed by capability name |
4921 | 4921 | * @throws \EE_Error |
4922 | 4922 | */ |
4923 | - public function caps_missing( $context = EEM_Base::caps_read ) { |
|
4923 | + public function caps_missing($context = EEM_Base::caps_read) { |
|
4924 | 4924 | $missing_caps = array(); |
4925 | - $cap_restrictions = $this->cap_restrictions( $context ); |
|
4926 | - foreach( $cap_restrictions as $cap => $restriction_if_no_cap ) { |
|
4927 | - if( ! EE_Capabilities::instance()->current_user_can( $cap, $this->get_this_model_name() . '_model_applying_caps') ) { |
|
4928 | - $missing_caps[ $cap ] = $restriction_if_no_cap; |
|
4925 | + $cap_restrictions = $this->cap_restrictions($context); |
|
4926 | + foreach ($cap_restrictions as $cap => $restriction_if_no_cap) { |
|
4927 | + if ( ! EE_Capabilities::instance()->current_user_can($cap, $this->get_this_model_name().'_model_applying_caps')) { |
|
4928 | + $missing_caps[$cap] = $restriction_if_no_cap; |
|
4929 | 4929 | } |
4930 | 4930 | } |
4931 | 4931 | return $missing_caps; |
@@ -4937,7 +4937,7 @@ discard block |
||
4937 | 4937 | * one of 'read', 'edit', or 'delete' |
4938 | 4938 | */ |
4939 | 4939 | public function cap_contexts_to_cap_action_map() { |
4940 | - return apply_filters( 'FHEE__EEM_Base__cap_contexts_to_cap_action_map', $this->_cap_contexts_to_cap_action_map, $this ); |
|
4940 | + return apply_filters('FHEE__EEM_Base__cap_contexts_to_cap_action_map', $this->_cap_contexts_to_cap_action_map, $this); |
|
4941 | 4941 | } |
4942 | 4942 | |
4943 | 4943 | |
@@ -4948,19 +4948,19 @@ discard block |
||
4948 | 4948 | * @return string one of EEM_Base::cap_contexts_to_cap_action_map() values |
4949 | 4949 | * @throws \EE_Error |
4950 | 4950 | */ |
4951 | - public function cap_action_for_context( $context ) { |
|
4951 | + public function cap_action_for_context($context) { |
|
4952 | 4952 | $mapping = $this->cap_contexts_to_cap_action_map(); |
4953 | - if( isset( $mapping[ $context ] ) ) { |
|
4954 | - return $mapping[ $context ]; |
|
4953 | + if (isset($mapping[$context])) { |
|
4954 | + return $mapping[$context]; |
|
4955 | 4955 | } |
4956 | - if( $action = apply_filters( 'FHEE__EEM_Base__cap_action_for_context', null, $this, $mapping, $context ) ) { |
|
4956 | + if ($action = apply_filters('FHEE__EEM_Base__cap_action_for_context', null, $this, $mapping, $context)) { |
|
4957 | 4957 | return $action; |
4958 | 4958 | } |
4959 | 4959 | throw new EE_Error( |
4960 | 4960 | sprintf( |
4961 | - __( 'Cannot find capability restrictions for context "%1$s", allowed values are:%2$s', 'event_espresso' ), |
|
4961 | + __('Cannot find capability restrictions for context "%1$s", allowed values are:%2$s', 'event_espresso'), |
|
4962 | 4962 | $context, |
4963 | - implode(',', array_keys( $this->cap_contexts_to_cap_action_map() ) ) |
|
4963 | + implode(',', array_keys($this->cap_contexts_to_cap_action_map())) |
|
4964 | 4964 | ) |
4965 | 4965 | ); |
4966 | 4966 | |
@@ -4971,7 +4971,7 @@ discard block |
||
4971 | 4971 | * @return array |
4972 | 4972 | */ |
4973 | 4973 | static public function valid_cap_contexts() { |
4974 | - return apply_filters( 'FHEE__EEM_Base__valid_cap_contexts', array( |
|
4974 | + return apply_filters('FHEE__EEM_Base__valid_cap_contexts', array( |
|
4975 | 4975 | self::caps_read, |
4976 | 4976 | self::caps_read_admin, |
4977 | 4977 | self::caps_edit, |
@@ -4987,17 +4987,17 @@ discard block |
||
4987 | 4987 | * @return bool |
4988 | 4988 | * @throws \EE_Error |
4989 | 4989 | */ |
4990 | - static public function verify_is_valid_cap_context( $context ) { |
|
4990 | + static public function verify_is_valid_cap_context($context) { |
|
4991 | 4991 | $valid_cap_contexts = EEM_Base::valid_cap_contexts(); |
4992 | - if( in_array( $context, $valid_cap_contexts ) ) { |
|
4992 | + if (in_array($context, $valid_cap_contexts)) { |
|
4993 | 4993 | return true; |
4994 | - }else{ |
|
4994 | + } else { |
|
4995 | 4995 | throw new EE_Error( |
4996 | 4996 | sprintf( |
4997 | - __( 'Context "%1$s" passed into model "%2$s" is not a valid context. They are: %3$s', 'event_espresso' ), |
|
4997 | + __('Context "%1$s" passed into model "%2$s" is not a valid context. They are: %3$s', 'event_espresso'), |
|
4998 | 4998 | $context, |
4999 | - 'EEM_Base' , |
|
5000 | - implode(',', $valid_cap_contexts ) |
|
4999 | + 'EEM_Base', |
|
5000 | + implode(',', $valid_cap_contexts) |
|
5001 | 5001 | ) |
5002 | 5002 | ); |
5003 | 5003 | } |
@@ -1,7 +1,7 @@ discard block |
||
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 | -require_once( EE_MODELS . 'EEM_Base.model.php' ); |
|
4 | +require_once(EE_MODELS.'EEM_Base.model.php'); |
|
5 | 5 | |
6 | 6 | |
7 | 7 | |
@@ -25,65 +25,65 @@ discard block |
||
25 | 25 | * |
26 | 26 | * @param string $timezone |
27 | 27 | */ |
28 | - protected function __construct( $timezone = null ) { |
|
29 | - $this->singular_item = __( 'Term', 'event_espresso' ); |
|
30 | - $this->plural_item = __( 'Terms', 'event_espresso' ); |
|
28 | + protected function __construct($timezone = null) { |
|
29 | + $this->singular_item = __('Term', 'event_espresso'); |
|
30 | + $this->plural_item = __('Terms', 'event_espresso'); |
|
31 | 31 | $this->_tables = array( |
32 | - 'Term' => new EE_Primary_Table( 'terms', 'term_id' ), |
|
32 | + 'Term' => new EE_Primary_Table('terms', 'term_id'), |
|
33 | 33 | ); |
34 | 34 | $this->_fields = array( |
35 | 35 | 'Term' => array( |
36 | - 'term_id' => new EE_Primary_Key_Int_Field( 'term_id', __( 'Term ID', 'event_espresso' ) ), |
|
37 | - 'name' => new EE_Plain_Text_Field( 'name', __( 'Term Name', 'event_espresso' ), false, '' ), |
|
38 | - 'slug' => new EE_Slug_Field( 'slug', __( 'Term Slug', 'event_espresso' ), false ), |
|
39 | - 'term_group' => new EE_Integer_Field( 'term_group', __( "Term Group", "event_espresso" ), false, 0 ), |
|
36 | + 'term_id' => new EE_Primary_Key_Int_Field('term_id', __('Term ID', 'event_espresso')), |
|
37 | + 'name' => new EE_Plain_Text_Field('name', __('Term Name', 'event_espresso'), false, ''), |
|
38 | + 'slug' => new EE_Slug_Field('slug', __('Term Slug', 'event_espresso'), false), |
|
39 | + 'term_group' => new EE_Integer_Field('term_group', __("Term Group", "event_espresso"), false, 0), |
|
40 | 40 | ), |
41 | 41 | ); |
42 | 42 | $this->_model_relations = array( |
43 | 43 | 'Term_Taxonomy' => new EE_Has_Many_Relation(), |
44 | 44 | ); |
45 | 45 | $path_to_tax_model = 'Term_Taxonomy'; |
46 | - $this->_cap_restriction_generators[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Public(); |
|
47 | - $this->_cap_restriction_generators[ EEM_Base::caps_read_admin ] = new EE_Restriction_Generator_Taxonomy_Protected( |
|
46 | + $this->_cap_restriction_generators[EEM_Base::caps_read] = new EE_Restriction_Generator_Public(); |
|
47 | + $this->_cap_restriction_generators[EEM_Base::caps_read_admin] = new EE_Restriction_Generator_Taxonomy_Protected( |
|
48 | 48 | $path_to_tax_model |
49 | 49 | ); |
50 | - $this->_cap_restriction_generators[ EEM_Base::caps_edit ] = false; |
|
51 | - $this->_cap_restriction_generators[ EEM_Base::caps_delete ] = false; |
|
52 | - $path_to_tax_model = $path_to_tax_model . '.'; |
|
50 | + $this->_cap_restriction_generators[EEM_Base::caps_edit] = false; |
|
51 | + $this->_cap_restriction_generators[EEM_Base::caps_delete] = false; |
|
52 | + $path_to_tax_model = $path_to_tax_model.'.'; |
|
53 | 53 | //add cap restrictions for editing relating to the "ee_edit_*" |
54 | - $this->_cap_restrictions[ EEM_Base::caps_edit ]['ee_edit_event_category'] = new EE_Default_Where_Conditions( |
|
54 | + $this->_cap_restrictions[EEM_Base::caps_edit]['ee_edit_event_category'] = new EE_Default_Where_Conditions( |
|
55 | 55 | array( |
56 | - $path_to_tax_model . 'taxonomy*ee_edit_event_category' => array( '!=', 'espresso_event_categories' ), |
|
56 | + $path_to_tax_model.'taxonomy*ee_edit_event_category' => array('!=', 'espresso_event_categories'), |
|
57 | 57 | ) |
58 | 58 | ); |
59 | - $this->_cap_restrictions[ EEM_Base::caps_edit ]['ee_edit_venue_category'] = new EE_Default_Where_Conditions( |
|
59 | + $this->_cap_restrictions[EEM_Base::caps_edit]['ee_edit_venue_category'] = new EE_Default_Where_Conditions( |
|
60 | 60 | array( |
61 | - $path_to_tax_model . 'taxonomy*ee_edit_venue_category' => array( '!=', 'espresso_venue_categories' ), |
|
61 | + $path_to_tax_model.'taxonomy*ee_edit_venue_category' => array('!=', 'espresso_venue_categories'), |
|
62 | 62 | ) |
63 | 63 | ); |
64 | - $this->_cap_restrictions[ EEM_Base::caps_edit ]['ee_edit_event_type'] = new EE_Default_Where_Conditions( |
|
64 | + $this->_cap_restrictions[EEM_Base::caps_edit]['ee_edit_event_type'] = new EE_Default_Where_Conditions( |
|
65 | 65 | array( |
66 | - $path_to_tax_model . 'taxonomy*ee_edit_event_type' => array( '!=', 'espresso_event_type' ), |
|
66 | + $path_to_tax_model.'taxonomy*ee_edit_event_type' => array('!=', 'espresso_event_type'), |
|
67 | 67 | ) |
68 | 68 | ); |
69 | 69 | //add cap restrictions for deleting relating to the "ee_deleting_*" |
70 | - $this->_cap_restrictions[ EEM_Base::caps_delete ]['ee_delete_event_category'] = new EE_Default_Where_Conditions( |
|
70 | + $this->_cap_restrictions[EEM_Base::caps_delete]['ee_delete_event_category'] = new EE_Default_Where_Conditions( |
|
71 | 71 | array( |
72 | - $path_to_tax_model . 'taxonomy*ee_delete_event_category' => array( '!=', 'espresso_event_categories' ), |
|
72 | + $path_to_tax_model.'taxonomy*ee_delete_event_category' => array('!=', 'espresso_event_categories'), |
|
73 | 73 | ) |
74 | 74 | ); |
75 | - $this->_cap_restrictions[ EEM_Base::caps_delete ]['ee_delete_venue_category'] = new EE_Default_Where_Conditions( |
|
75 | + $this->_cap_restrictions[EEM_Base::caps_delete]['ee_delete_venue_category'] = new EE_Default_Where_Conditions( |
|
76 | 76 | array( |
77 | - $path_to_tax_model . 'taxonomy*ee_delete_venue_category' => array( '!=', 'espresso_venue_categories' ), |
|
77 | + $path_to_tax_model.'taxonomy*ee_delete_venue_category' => array('!=', 'espresso_venue_categories'), |
|
78 | 78 | ) |
79 | 79 | ); |
80 | - $this->_cap_restrictions[ EEM_Base::caps_delete ]['ee_delete_event_type'] = new EE_Default_Where_Conditions( |
|
80 | + $this->_cap_restrictions[EEM_Base::caps_delete]['ee_delete_event_type'] = new EE_Default_Where_Conditions( |
|
81 | 81 | array( |
82 | - $path_to_tax_model . 'taxonomy*ee_delete_event_type' => array( '!=', 'espresso_event_type' ), |
|
82 | + $path_to_tax_model.'taxonomy*ee_delete_event_type' => array('!=', 'espresso_event_type'), |
|
83 | 83 | ) |
84 | 84 | ); |
85 | - parent::__construct( $timezone ); |
|
86 | - add_filter( 'FHEE__Read__create_model_query_params', array( 'EEM_Term', 'rest_api_query_params' ), 10, 3 ); |
|
85 | + parent::__construct($timezone); |
|
86 | + add_filter('FHEE__Read__create_model_query_params', array('EEM_Term', 'rest_api_query_params'), 10, 3); |
|
87 | 87 | } |
88 | 88 | |
89 | 89 | |
@@ -95,18 +95,18 @@ discard block |
||
95 | 95 | * @param bool $show_uncategorized |
96 | 96 | * @return \EE_Base_Class[] |
97 | 97 | */ |
98 | - public function get_all_ee_categories( $show_uncategorized = false ) { |
|
98 | + public function get_all_ee_categories($show_uncategorized = false) { |
|
99 | 99 | $where_params = array( |
100 | 100 | 'Term_Taxonomy.taxonomy' => 'espresso_event_categories', |
101 | - 'NOT' => array( 'name' => __( 'Uncategorized', 'event_espresso' ) ), |
|
101 | + 'NOT' => array('name' => __('Uncategorized', 'event_espresso')), |
|
102 | 102 | ); |
103 | - if ( $show_uncategorized ) { |
|
104 | - unset( $where_params['NOT'] ); |
|
103 | + if ($show_uncategorized) { |
|
104 | + unset($where_params['NOT']); |
|
105 | 105 | } |
106 | 106 | return EEM_Term::instance()->get_all( |
107 | 107 | array( |
108 | 108 | $where_params, |
109 | - 'order_by' => array( 'name' => 'ASC' ), |
|
109 | + 'order_by' => array('name' => 'ASC'), |
|
110 | 110 | ) |
111 | 111 | ); |
112 | 112 | } |
@@ -120,8 +120,8 @@ discard block |
||
120 | 120 | * @param string $post_type |
121 | 121 | * @return array |
122 | 122 | */ |
123 | - public function get_all_CPT_post_tags( $post_type = '' ) { |
|
124 | - switch ( $post_type ) { |
|
123 | + public function get_all_CPT_post_tags($post_type = '') { |
|
124 | + switch ($post_type) { |
|
125 | 125 | case 'espresso_events' : |
126 | 126 | return $this->get_all_event_post_tags(); |
127 | 127 | break; |
@@ -131,7 +131,7 @@ discard block |
||
131 | 131 | default : |
132 | 132 | $event_tags = $this->get_all_event_post_tags(); |
133 | 133 | $venue_tags = $this->get_all_venue_post_tags(); |
134 | - return array_merge( $event_tags, $venue_tags ); |
|
134 | + return array_merge($event_tags, $venue_tags); |
|
135 | 135 | } |
136 | 136 | } |
137 | 137 | |
@@ -149,15 +149,15 @@ discard block |
||
149 | 149 | 'Term_Taxonomy.taxonomy' => 'post_tag', |
150 | 150 | 'Term_Taxonomy.Event.post_type' => 'espresso_events', |
151 | 151 | ), |
152 | - 'order_by' => array( 'name' => 'ASC' ), |
|
153 | - 'force_join' => array( 'Term_Taxonomy.Event' ), |
|
152 | + 'order_by' => array('name' => 'ASC'), |
|
153 | + 'force_join' => array('Term_Taxonomy.Event'), |
|
154 | 154 | ) |
155 | 155 | ); |
156 | - foreach ( $post_tags as $key => $post_tag ) { |
|
157 | - if ( ! isset( $post_tags[ $key ]->post_type ) ) { |
|
158 | - $post_tags[ $key ]->post_type = array(); |
|
156 | + foreach ($post_tags as $key => $post_tag) { |
|
157 | + if ( ! isset($post_tags[$key]->post_type)) { |
|
158 | + $post_tags[$key]->post_type = array(); |
|
159 | 159 | } |
160 | - $post_tags[ $key ]->post_type[] = 'espresso_events'; |
|
160 | + $post_tags[$key]->post_type[] = 'espresso_events'; |
|
161 | 161 | } |
162 | 162 | return $post_tags; |
163 | 163 | } |
@@ -176,15 +176,15 @@ discard block |
||
176 | 176 | 'Term_Taxonomy.taxonomy' => 'post_tag', |
177 | 177 | 'Term_Taxonomy.Venue.post_type' => 'espresso_venues', |
178 | 178 | ), |
179 | - 'order_by' => array( 'name' => 'ASC' ), |
|
180 | - 'force_join' => array( 'Term_Taxonomy' ), |
|
179 | + 'order_by' => array('name' => 'ASC'), |
|
180 | + 'force_join' => array('Term_Taxonomy'), |
|
181 | 181 | ) |
182 | 182 | ); |
183 | - foreach ( $post_tags as $key => $post_tag ) { |
|
184 | - if ( ! isset( $post_tags[ $key ]->post_type ) ) { |
|
185 | - $post_tags[ $key ]->post_type = array(); |
|
183 | + foreach ($post_tags as $key => $post_tag) { |
|
184 | + if ( ! isset($post_tags[$key]->post_type)) { |
|
185 | + $post_tags[$key]->post_type = array(); |
|
186 | 186 | } |
187 | - $post_tags[ $key ]->post_type[] = 'espresso_venues'; |
|
187 | + $post_tags[$key]->post_type[] = 'espresso_venues'; |
|
188 | 188 | } |
189 | 189 | return $post_tags; |
190 | 190 | } |
@@ -200,11 +200,11 @@ discard block |
||
200 | 200 | * @param EEM_Base $model |
201 | 201 | * @return array |
202 | 202 | */ |
203 | - public static function rest_api_query_params( $model_query_params, $querystring_query_params, $model ) { |
|
204 | - if ( $model === EEM_Term::instance() ) { |
|
205 | - $taxonomies = get_taxonomies( array( 'show_in_rest' => true ) ); |
|
206 | - if ( ! empty( $taxonomies ) ) { |
|
207 | - $model_query_params[0]['Term_Taxonomy.taxonomy'] = array( 'IN', $taxonomies ); |
|
203 | + public static function rest_api_query_params($model_query_params, $querystring_query_params, $model) { |
|
204 | + if ($model === EEM_Term::instance()) { |
|
205 | + $taxonomies = get_taxonomies(array('show_in_rest' => true)); |
|
206 | + if ( ! empty($taxonomies)) { |
|
207 | + $model_query_params[0]['Term_Taxonomy.taxonomy'] = array('IN', $taxonomies); |
|
208 | 208 | } |
209 | 209 | } |
210 | 210 | return $model_query_params; |