@@ -54,7 +54,7 @@ discard block |
||
54 | 54 | * If that also fails, then an exception is thrown. |
55 | 55 | * |
56 | 56 | * @access public |
57 | - * @return boolean |
|
57 | + * @return boolean|null |
|
58 | 58 | * @throws \EE_Error |
59 | 59 | */ |
60 | 60 | public function lock() { |
@@ -103,7 +103,7 @@ discard block |
||
103 | 103 | * We also check that the lock isn't expired, and remove it if it is |
104 | 104 | * |
105 | 105 | * @access public |
106 | - * @return int |
|
106 | + * @return boolean |
|
107 | 107 | * @throws \EE_Error |
108 | 108 | */ |
109 | 109 | public function is_locked() { |
@@ -409,7 +409,7 @@ discard block |
||
409 | 409 | * Gets all the attendees for this transaction (handy for use with EE_Attendee's get_registrations_for_event function |
410 | 410 | * for getting attendees and how many registrations they each have for an event) |
411 | 411 | * |
412 | - * @return mixed EE_Attendee[] by default, int if $output is set to 'COUNT' |
|
412 | + * @return EE_Base_Class[] EE_Attendee[] by default, int if $output is set to 'COUNT' |
|
413 | 413 | * @throws \EE_Error |
414 | 414 | */ |
415 | 415 | public function attendees() { |
@@ -690,7 +690,7 @@ discard block |
||
690 | 690 | * Gets all the extra meta info on this payment |
691 | 691 | * |
692 | 692 | * @param array $query_params like EEM_Base::get_all |
693 | - * @return EE_Extra_Meta |
|
693 | + * @return EE_Base_Class[] |
|
694 | 694 | * @throws \EE_Error |
695 | 695 | */ |
696 | 696 | public function extra_meta( $query_params = array() ) { |
@@ -867,7 +867,7 @@ discard block |
||
867 | 867 | * Sets PMD_ID |
868 | 868 | * |
869 | 869 | * @param int $PMD_ID |
870 | - * @return boolean |
|
870 | + * @return boolean|null |
|
871 | 871 | * @throws \EE_Error |
872 | 872 | */ |
873 | 873 | public function set_payment_method_ID($PMD_ID) { |
@@ -2,12 +2,12 @@ discard block |
||
2 | 2 | exit( 'No direct script access allowed' ); |
3 | 3 | } |
4 | 4 | /** |
5 | - * EE_Transaction class |
|
6 | - * |
|
7 | - * @package Event Espresso |
|
8 | - * @subpackage includes/classes/EE_Transaction.class.php |
|
9 | - * @author Brent Christensen |
|
10 | - */ |
|
5 | + * EE_Transaction class |
|
6 | + * |
|
7 | + * @package Event Espresso |
|
8 | + * @subpackage includes/classes/EE_Transaction.class.php |
|
9 | + * @author Brent Christensen |
|
10 | + */ |
|
11 | 11 | class EE_Transaction extends EE_Base_Class implements EEI_Transaction { |
12 | 12 | |
13 | 13 | /** |
@@ -132,7 +132,6 @@ discard block |
||
132 | 132 | /** |
133 | 133 | * remove_expired_lock |
134 | 134 | * If the lock on this transaction is expired, then we want to remove it so that the transaction can be updated |
135 | - |
|
136 | 135 | * |
137 | 136 | *@access public |
138 | 137 | * @return int |
@@ -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 | * EE_Transaction class |
@@ -25,11 +25,11 @@ discard block |
||
25 | 25 | * @return EE_Transaction |
26 | 26 | * @throws \EE_Error |
27 | 27 | */ |
28 | - public static function new_instance( $props_n_values = array(), $timezone = null, $date_formats = array() ) { |
|
29 | - $has_object = parent::_check_for_object( $props_n_values, __CLASS__, $timezone, $date_formats ); |
|
28 | + public static function new_instance($props_n_values = array(), $timezone = null, $date_formats = array()) { |
|
29 | + $has_object = parent::_check_for_object($props_n_values, __CLASS__, $timezone, $date_formats); |
|
30 | 30 | return $has_object |
31 | 31 | ? $has_object |
32 | - : new self( $props_n_values, false, $timezone, $date_formats ); |
|
32 | + : new self($props_n_values, false, $timezone, $date_formats); |
|
33 | 33 | } |
34 | 34 | |
35 | 35 | |
@@ -41,8 +41,8 @@ discard block |
||
41 | 41 | * @return EE_Transaction |
42 | 42 | * @throws \EE_Error |
43 | 43 | */ |
44 | - public static function new_instance_from_db( $props_n_values = array(), $timezone = null ) { |
|
45 | - return new self( $props_n_values, TRUE, $timezone ); |
|
44 | + public static function new_instance_from_db($props_n_values = array(), $timezone = null) { |
|
45 | + return new self($props_n_values, TRUE, $timezone); |
|
46 | 46 | } |
47 | 47 | |
48 | 48 | |
@@ -59,16 +59,16 @@ discard block |
||
59 | 59 | */ |
60 | 60 | public function lock() { |
61 | 61 | // attempt to set lock, but if that fails... |
62 | - if ( ! $this->add_extra_meta( 'lock', time(), true ) ) { |
|
62 | + if ( ! $this->add_extra_meta('lock', time(), true)) { |
|
63 | 63 | // then attempt to remove the lock in case it is expired |
64 | - if ( $this->_remove_expired_lock() ) { |
|
64 | + if ($this->_remove_expired_lock()) { |
|
65 | 65 | // if removal was successful, then try setting lock again |
66 | 66 | $this->lock(); |
67 | 67 | } else { |
68 | 68 | // but if the lock can not be removed, then throw an exception |
69 | 69 | throw new EE_Error( |
70 | 70 | sprintf( |
71 | - __( 'Could not lock Transaction %1$d because it is already locked, meaning another part of the system is currently editing it. It should already be unlocked by the time you read this, so please refresh the page and try again.', 'event_espresso' ), |
|
71 | + __('Could not lock Transaction %1$d because it is already locked, meaning another part of the system is currently editing it. It should already be unlocked by the time you read this, so please refresh the page and try again.', 'event_espresso'), |
|
72 | 72 | $this->ID() |
73 | 73 | ) |
74 | 74 | ); |
@@ -87,7 +87,7 @@ discard block |
||
87 | 87 | * @throws \EE_Error |
88 | 88 | */ |
89 | 89 | public function unlock() { |
90 | - return $this->delete_extra_meta( 'lock' ); |
|
90 | + return $this->delete_extra_meta('lock'); |
|
91 | 91 | } |
92 | 92 | |
93 | 93 | |
@@ -124,7 +124,7 @@ discard block |
||
124 | 124 | * @throws \EE_Error |
125 | 125 | */ |
126 | 126 | protected function get_lock() { |
127 | - return (int)$this->get_extra_meta( 'lock', true, 0 ); |
|
127 | + return (int) $this->get_extra_meta('lock', true, 0); |
|
128 | 128 | } |
129 | 129 | |
130 | 130 | |
@@ -140,7 +140,7 @@ discard block |
||
140 | 140 | */ |
141 | 141 | protected function _remove_expired_lock() { |
142 | 142 | $locked = $this->get_lock(); |
143 | - if ( $locked && time() - EE_Transaction::LOCK_EXPIRATION > $locked ) { |
|
143 | + if ($locked && time() - EE_Transaction::LOCK_EXPIRATION > $locked) { |
|
144 | 144 | return $this->unlock(); |
145 | 145 | } |
146 | 146 | return 0; |
@@ -155,8 +155,8 @@ discard block |
||
155 | 155 | * @param float $total total value of transaction |
156 | 156 | * @throws \EE_Error |
157 | 157 | */ |
158 | - public function set_total( $total = 0.00 ) { |
|
159 | - $this->set( 'TXN_total', (float)$total ); |
|
158 | + public function set_total($total = 0.00) { |
|
159 | + $this->set('TXN_total', (float) $total); |
|
160 | 160 | } |
161 | 161 | |
162 | 162 | |
@@ -168,8 +168,8 @@ discard block |
||
168 | 168 | * @param float $total_paid total amount paid to date (sum of all payments) |
169 | 169 | * @throws \EE_Error |
170 | 170 | */ |
171 | - public function set_paid( $total_paid = 0.00 ) { |
|
172 | - $this->set( 'TXN_paid', (float)$total_paid ); |
|
171 | + public function set_paid($total_paid = 0.00) { |
|
172 | + $this->set('TXN_paid', (float) $total_paid); |
|
173 | 173 | } |
174 | 174 | |
175 | 175 | |
@@ -181,8 +181,8 @@ discard block |
||
181 | 181 | * @param string $status whether the transaction is open, declined, accepted, or any number of custom values that can be set |
182 | 182 | * @throws \EE_Error |
183 | 183 | */ |
184 | - public function set_status( $status = '' ) { |
|
185 | - $this->set( 'STS_ID', $status ); |
|
184 | + public function set_status($status = '') { |
|
185 | + $this->set('STS_ID', $status); |
|
186 | 186 | } |
187 | 187 | |
188 | 188 | |
@@ -194,8 +194,8 @@ discard block |
||
194 | 194 | * @param string $hash_salt required for some payment gateways |
195 | 195 | * @throws \EE_Error |
196 | 196 | */ |
197 | - public function set_hash_salt( $hash_salt = '' ) { |
|
198 | - $this->set( 'TXN_hash_salt', $hash_salt ); |
|
197 | + public function set_hash_salt($hash_salt = '') { |
|
198 | + $this->set('TXN_hash_salt', $hash_salt); |
|
199 | 199 | } |
200 | 200 | |
201 | 201 | |
@@ -206,8 +206,8 @@ discard block |
||
206 | 206 | * @param array $txn_reg_steps |
207 | 207 | * @throws \EE_Error |
208 | 208 | */ |
209 | - public function set_reg_steps( array $txn_reg_steps ) { |
|
210 | - $this->set( 'TXN_reg_steps', $txn_reg_steps ); |
|
209 | + public function set_reg_steps(array $txn_reg_steps) { |
|
210 | + $this->set('TXN_reg_steps', $txn_reg_steps); |
|
211 | 211 | } |
212 | 212 | |
213 | 213 | |
@@ -219,8 +219,8 @@ discard block |
||
219 | 219 | * @throws \EE_Error |
220 | 220 | */ |
221 | 221 | public function reg_steps() { |
222 | - $TXN_reg_steps = $this->get( 'TXN_reg_steps' ); |
|
223 | - return is_array( $TXN_reg_steps ) ? (array)$TXN_reg_steps : array(); |
|
222 | + $TXN_reg_steps = $this->get('TXN_reg_steps'); |
|
223 | + return is_array($TXN_reg_steps) ? (array) $TXN_reg_steps : array(); |
|
224 | 224 | } |
225 | 225 | |
226 | 226 | |
@@ -230,7 +230,7 @@ discard block |
||
230 | 230 | * @throws \EE_Error |
231 | 231 | */ |
232 | 232 | public function pretty_total() { |
233 | - return $this->get_pretty( 'TXN_total' ); |
|
233 | + return $this->get_pretty('TXN_total'); |
|
234 | 234 | } |
235 | 235 | |
236 | 236 | |
@@ -242,7 +242,7 @@ discard block |
||
242 | 242 | * @throws \EE_Error |
243 | 243 | */ |
244 | 244 | public function pretty_paid() { |
245 | - return $this->get_pretty( 'TXN_paid' ); |
|
245 | + return $this->get_pretty('TXN_paid'); |
|
246 | 246 | } |
247 | 247 | |
248 | 248 | |
@@ -255,7 +255,7 @@ discard block |
||
255 | 255 | * @throws \EE_Error |
256 | 256 | */ |
257 | 257 | public function remaining() { |
258 | - return (float)( $this->total() - $this->paid() ); |
|
258 | + return (float) ($this->total() - $this->paid()); |
|
259 | 259 | } |
260 | 260 | |
261 | 261 | |
@@ -268,7 +268,7 @@ discard block |
||
268 | 268 | * @throws \EE_Error |
269 | 269 | */ |
270 | 270 | public function total() { |
271 | - return (float)$this->get( 'TXN_total' ); |
|
271 | + return (float) $this->get('TXN_total'); |
|
272 | 272 | } |
273 | 273 | |
274 | 274 | |
@@ -281,7 +281,7 @@ discard block |
||
281 | 281 | * @throws \EE_Error |
282 | 282 | */ |
283 | 283 | public function paid() { |
284 | - return (float)$this->get( 'TXN_paid' ); |
|
284 | + return (float) $this->get('TXN_paid'); |
|
285 | 285 | } |
286 | 286 | |
287 | 287 | |
@@ -293,9 +293,9 @@ discard block |
||
293 | 293 | * @throws \EE_Error |
294 | 294 | */ |
295 | 295 | public function get_cart_session() { |
296 | - $session_data = (array)$this->get( 'TXN_session_data' ); |
|
297 | - return isset( $session_data[ 'cart' ] ) && $session_data[ 'cart' ] instanceof EE_Cart |
|
298 | - ? $session_data[ 'cart' ] |
|
296 | + $session_data = (array) $this->get('TXN_session_data'); |
|
297 | + return isset($session_data['cart']) && $session_data['cart'] instanceof EE_Cart |
|
298 | + ? $session_data['cart'] |
|
299 | 299 | : null; |
300 | 300 | } |
301 | 301 | |
@@ -308,8 +308,8 @@ discard block |
||
308 | 308 | * @throws \EE_Error |
309 | 309 | */ |
310 | 310 | public function session_data() { |
311 | - $session_data = $this->get( 'TXN_session_data' ); |
|
312 | - if ( empty( $session_data ) ) { |
|
311 | + $session_data = $this->get('TXN_session_data'); |
|
312 | + if (empty($session_data)) { |
|
313 | 313 | $session_data = array( |
314 | 314 | 'id' => null, |
315 | 315 | 'user_id' => null, |
@@ -332,11 +332,11 @@ discard block |
||
332 | 332 | * @param EE_Session|array $session_data |
333 | 333 | * @throws \EE_Error |
334 | 334 | */ |
335 | - public function set_txn_session_data( $session_data ) { |
|
336 | - if ( $session_data instanceof EE_Session ) { |
|
337 | - $this->set( 'TXN_session_data', $session_data->get_session_data( NULL, TRUE )); |
|
335 | + public function set_txn_session_data($session_data) { |
|
336 | + if ($session_data instanceof EE_Session) { |
|
337 | + $this->set('TXN_session_data', $session_data->get_session_data(NULL, TRUE)); |
|
338 | 338 | } else { |
339 | - $this->set( 'TXN_session_data', $session_data ); |
|
339 | + $this->set('TXN_session_data', $session_data); |
|
340 | 340 | } |
341 | 341 | } |
342 | 342 | |
@@ -349,7 +349,7 @@ discard block |
||
349 | 349 | * @throws \EE_Error |
350 | 350 | */ |
351 | 351 | public function hash_salt_() { |
352 | - return $this->get( 'TXN_hash_salt' ); |
|
352 | + return $this->get('TXN_hash_salt'); |
|
353 | 353 | } |
354 | 354 | |
355 | 355 | |
@@ -369,13 +369,13 @@ discard block |
||
369 | 369 | * @return string | int |
370 | 370 | * @throws \EE_Error |
371 | 371 | */ |
372 | - public function datetime( $format = FALSE, $gmt = FALSE ) { |
|
373 | - if ( $format ) { |
|
374 | - return $this->get_pretty( 'TXN_timestamp' ); |
|
375 | - } else if ( $gmt ) { |
|
376 | - return $this->get_raw( 'TXN_timestamp' ); |
|
372 | + public function datetime($format = FALSE, $gmt = FALSE) { |
|
373 | + if ($format) { |
|
374 | + return $this->get_pretty('TXN_timestamp'); |
|
375 | + } else if ($gmt) { |
|
376 | + return $this->get_raw('TXN_timestamp'); |
|
377 | 377 | } else { |
378 | - return $this->get( 'TXN_timestamp' ); |
|
378 | + return $this->get('TXN_timestamp'); |
|
379 | 379 | } |
380 | 380 | } |
381 | 381 | |
@@ -389,8 +389,8 @@ discard block |
||
389 | 389 | * @return EE_Registration[] |
390 | 390 | * @throws \EE_Error |
391 | 391 | */ |
392 | - public function registrations( $query_params = array(), $get_cached = FALSE ) { |
|
393 | - $query_params = ( empty( $query_params ) || ! is_array( $query_params ) ) |
|
392 | + public function registrations($query_params = array(), $get_cached = FALSE) { |
|
393 | + $query_params = (empty($query_params) || ! is_array($query_params)) |
|
394 | 394 | ? array( |
395 | 395 | 'order_by' => array( |
396 | 396 | 'Event.EVT_name' => 'ASC', |
@@ -400,7 +400,7 @@ discard block |
||
400 | 400 | ) |
401 | 401 | : $query_params; |
402 | 402 | $query_params = $get_cached ? array() : $query_params; |
403 | - return $this->get_many_related( 'Registration', $query_params ); |
|
403 | + return $this->get_many_related('Registration', $query_params); |
|
404 | 404 | } |
405 | 405 | |
406 | 406 | |
@@ -413,7 +413,7 @@ discard block |
||
413 | 413 | * @throws \EE_Error |
414 | 414 | */ |
415 | 415 | public function attendees() { |
416 | - return $this->get_many_related( 'Attendee', array( array( 'Registration.Transaction.TXN_ID' => $this->ID() ) ) ); |
|
416 | + return $this->get_many_related('Attendee', array(array('Registration.Transaction.TXN_ID' => $this->ID()))); |
|
417 | 417 | } |
418 | 418 | |
419 | 419 | |
@@ -425,8 +425,8 @@ discard block |
||
425 | 425 | * @return EE_Payment[] |
426 | 426 | * @throws \EE_Error |
427 | 427 | */ |
428 | - public function payments( $query_params = array() ) { |
|
429 | - return $this->get_many_related( 'Payment', $query_params ); |
|
428 | + public function payments($query_params = array()) { |
|
429 | + return $this->get_many_related('Payment', $query_params); |
|
430 | 430 | } |
431 | 431 | |
432 | 432 | |
@@ -438,8 +438,8 @@ discard block |
||
438 | 438 | * @throws \EE_Error |
439 | 439 | */ |
440 | 440 | public function approved_payments() { |
441 | - EE_Registry::instance()->load_model( 'Payment' ); |
|
442 | - return $this->get_many_related( 'Payment', array( array( 'STS_ID' => EEM_Payment::status_id_approved ), 'order_by' => array( 'PAY_timestamp' => 'DESC' ) ) ); |
|
441 | + EE_Registry::instance()->load_model('Payment'); |
|
442 | + return $this->get_many_related('Payment', array(array('STS_ID' => EEM_Payment::status_id_approved), 'order_by' => array('PAY_timestamp' => 'DESC'))); |
|
443 | 443 | } |
444 | 444 | |
445 | 445 | |
@@ -451,8 +451,8 @@ discard block |
||
451 | 451 | * @return string |
452 | 452 | * @throws \EE_Error |
453 | 453 | */ |
454 | - public function e_pretty_status( $show_icons = FALSE ) { |
|
455 | - echo $this->pretty_status( $show_icons ); |
|
454 | + public function e_pretty_status($show_icons = FALSE) { |
|
455 | + echo $this->pretty_status($show_icons); |
|
456 | 456 | } |
457 | 457 | |
458 | 458 | |
@@ -464,10 +464,10 @@ discard block |
||
464 | 464 | * @return string |
465 | 465 | * @throws \EE_Error |
466 | 466 | */ |
467 | - public function pretty_status( $show_icons = FALSE ) { |
|
468 | - $status = EEM_Status::instance()->localized_status( array( $this->status_ID() => __( 'unknown', 'event_espresso' ) ), FALSE, 'sentence' ); |
|
467 | + public function pretty_status($show_icons = FALSE) { |
|
468 | + $status = EEM_Status::instance()->localized_status(array($this->status_ID() => __('unknown', 'event_espresso')), FALSE, 'sentence'); |
|
469 | 469 | $icon = ''; |
470 | - switch ( $this->status_ID() ) { |
|
470 | + switch ($this->status_ID()) { |
|
471 | 471 | case EEM_Transaction::complete_status_code: |
472 | 472 | $icon = $show_icons ? '<span class="dashicons dashicons-yes ee-icon-size-24 green-text"></span>' : ''; |
473 | 473 | break; |
@@ -484,7 +484,7 @@ discard block |
||
484 | 484 | $icon = $show_icons ? '<span class="dashicons dashicons-plus ee-icon-size-16 orange-text"></span>' : ''; |
485 | 485 | break; |
486 | 486 | } |
487 | - return $icon . $status[ $this->status_ID() ]; |
|
487 | + return $icon.$status[$this->status_ID()]; |
|
488 | 488 | } |
489 | 489 | |
490 | 490 | |
@@ -496,7 +496,7 @@ discard block |
||
496 | 496 | * @throws \EE_Error |
497 | 497 | */ |
498 | 498 | public function status_ID() { |
499 | - return $this->get( 'STS_ID' ); |
|
499 | + return $this->get('STS_ID'); |
|
500 | 500 | } |
501 | 501 | |
502 | 502 | |
@@ -508,7 +508,7 @@ discard block |
||
508 | 508 | * @throws \EE_Error |
509 | 509 | */ |
510 | 510 | public function is_free() { |
511 | - return (float)$this->get( 'TXN_total' ) === (float)0 ? TRUE : FALSE; |
|
511 | + return (float) $this->get('TXN_total') === (float) 0 ? TRUE : FALSE; |
|
512 | 512 | } |
513 | 513 | |
514 | 514 | |
@@ -588,12 +588,12 @@ discard block |
||
588 | 588 | * @return string |
589 | 589 | * @throws \EE_Error |
590 | 590 | */ |
591 | - public function invoice_url( $type = 'html' ) { |
|
591 | + public function invoice_url($type = 'html') { |
|
592 | 592 | $REG = $this->primary_registration(); |
593 | - if ( ! $REG instanceof EE_Registration ) { |
|
593 | + if ( ! $REG instanceof EE_Registration) { |
|
594 | 594 | return ''; |
595 | 595 | } |
596 | - return $REG->invoice_url( $type ); |
|
596 | + return $REG->invoice_url($type); |
|
597 | 597 | } |
598 | 598 | |
599 | 599 | |
@@ -605,7 +605,7 @@ discard block |
||
605 | 605 | * @throws \EE_Error |
606 | 606 | */ |
607 | 607 | public function primary_registration() { |
608 | - return $this->get_first_related( 'Registration', array( array( 'REG_count' => EEM_Registration::PRIMARY_REGISTRANT_COUNT ) ) ); |
|
608 | + return $this->get_first_related('Registration', array(array('REG_count' => EEM_Registration::PRIMARY_REGISTRANT_COUNT))); |
|
609 | 609 | } |
610 | 610 | |
611 | 611 | |
@@ -617,12 +617,12 @@ discard block |
||
617 | 617 | * @return string |
618 | 618 | * @throws \EE_Error |
619 | 619 | */ |
620 | - public function receipt_url( $type = 'html' ) { |
|
620 | + public function receipt_url($type = 'html') { |
|
621 | 621 | $REG = $this->primary_registration(); |
622 | - if ( ! $REG instanceof EE_Registration ) { |
|
622 | + if ( ! $REG instanceof EE_Registration) { |
|
623 | 623 | return ''; |
624 | 624 | } |
625 | - return $REG->receipt_url( $type ); |
|
625 | + return $REG->receipt_url($type); |
|
626 | 626 | } |
627 | 627 | |
628 | 628 | |
@@ -650,15 +650,15 @@ discard block |
||
650 | 650 | * @return boolean |
651 | 651 | * @throws \EE_Error |
652 | 652 | */ |
653 | - public function update_based_on_payments(){ |
|
653 | + public function update_based_on_payments() { |
|
654 | 654 | EE_Error::doing_it_wrong( |
655 | - __CLASS__ . '::' . __FUNCTION__, |
|
656 | - sprintf( __( 'This method is deprecated. Please use "%s" instead', 'event_espresso' ), 'EE_Transaction_Processor::update_transaction_and_registrations_after_checkout_or_payment()' ), |
|
655 | + __CLASS__.'::'.__FUNCTION__, |
|
656 | + sprintf(__('This method is deprecated. Please use "%s" instead', 'event_espresso'), 'EE_Transaction_Processor::update_transaction_and_registrations_after_checkout_or_payment()'), |
|
657 | 657 | '4.6.0' |
658 | 658 | ); |
659 | 659 | /** @type EE_Transaction_Processor $transaction_processor */ |
660 | - $transaction_processor = EE_Registry::instance()->load_class( 'Transaction_Processor' ); |
|
661 | - return $transaction_processor->update_transaction_and_registrations_after_checkout_or_payment( $this ); |
|
660 | + $transaction_processor = EE_Registry::instance()->load_class('Transaction_Processor'); |
|
661 | + return $transaction_processor->update_transaction_and_registrations_after_checkout_or_payment($this); |
|
662 | 662 | } |
663 | 663 | |
664 | 664 | |
@@ -668,7 +668,7 @@ discard block |
||
668 | 668 | * @throws \EE_Error |
669 | 669 | */ |
670 | 670 | public function gateway_response_on_transaction() { |
671 | - $payment = $this->get_first_related( 'Payment' ); |
|
671 | + $payment = $this->get_first_related('Payment'); |
|
672 | 672 | return $payment instanceof EE_Payment ? $payment->gateway_response() : ''; |
673 | 673 | } |
674 | 674 | |
@@ -681,7 +681,7 @@ discard block |
||
681 | 681 | * @throws \EE_Error |
682 | 682 | */ |
683 | 683 | public function status_obj() { |
684 | - return $this->get_first_related( 'Status' ); |
|
684 | + return $this->get_first_related('Status'); |
|
685 | 685 | } |
686 | 686 | |
687 | 687 | |
@@ -693,8 +693,8 @@ discard block |
||
693 | 693 | * @return EE_Extra_Meta |
694 | 694 | * @throws \EE_Error |
695 | 695 | */ |
696 | - public function extra_meta( $query_params = array() ) { |
|
697 | - return $this->get_many_related( 'Extra_Meta', $query_params ); |
|
696 | + public function extra_meta($query_params = array()) { |
|
697 | + return $this->get_many_related('Extra_Meta', $query_params); |
|
698 | 698 | } |
699 | 699 | |
700 | 700 | |
@@ -706,8 +706,8 @@ discard block |
||
706 | 706 | * @return EE_Base_Class the relation was added to |
707 | 707 | * @throws \EE_Error |
708 | 708 | */ |
709 | - public function add_registration( EE_Registration $registration ) { |
|
710 | - return $this->_add_relation_to( $registration, 'Registration' ); |
|
709 | + public function add_registration(EE_Registration $registration) { |
|
710 | + return $this->_add_relation_to($registration, 'Registration'); |
|
711 | 711 | } |
712 | 712 | |
713 | 713 | |
@@ -720,8 +720,8 @@ discard block |
||
720 | 720 | * @return EE_Base_Class that was removed from being related |
721 | 721 | * @throws \EE_Error |
722 | 722 | */ |
723 | - public function remove_registration_with_id( $registration_or_id ) { |
|
724 | - return $this->_remove_relation_to( $registration_or_id, 'Registration' ); |
|
723 | + public function remove_registration_with_id($registration_or_id) { |
|
724 | + return $this->_remove_relation_to($registration_or_id, 'Registration'); |
|
725 | 725 | } |
726 | 726 | |
727 | 727 | |
@@ -733,7 +733,7 @@ discard block |
||
733 | 733 | * @throws \EE_Error |
734 | 734 | */ |
735 | 735 | public function items_purchased() { |
736 | - return $this->line_items( array( array( 'LIN_type' => EEM_Line_Item::type_line_item ) ) ); |
|
736 | + return $this->line_items(array(array('LIN_type' => EEM_Line_Item::type_line_item))); |
|
737 | 737 | } |
738 | 738 | |
739 | 739 | |
@@ -745,8 +745,8 @@ discard block |
||
745 | 745 | * @return EE_Base_Class the relation was added to |
746 | 746 | * @throws \EE_Error |
747 | 747 | */ |
748 | - public function add_line_item( EE_Line_Item $line_item ) { |
|
749 | - return $this->_add_relation_to( $line_item, 'Line_Item' ); |
|
748 | + public function add_line_item(EE_Line_Item $line_item) { |
|
749 | + return $this->_add_relation_to($line_item, 'Line_Item'); |
|
750 | 750 | } |
751 | 751 | |
752 | 752 | |
@@ -758,8 +758,8 @@ discard block |
||
758 | 758 | * @return EE_Line_Item[] |
759 | 759 | * @throws \EE_Error |
760 | 760 | */ |
761 | - public function line_items( $query_params = array() ) { |
|
762 | - return $this->get_many_related( 'Line_Item', $query_params ); |
|
761 | + public function line_items($query_params = array()) { |
|
762 | + return $this->get_many_related('Line_Item', $query_params); |
|
763 | 763 | } |
764 | 764 | |
765 | 765 | |
@@ -771,7 +771,7 @@ discard block |
||
771 | 771 | * @throws \EE_Error |
772 | 772 | */ |
773 | 773 | public function tax_items() { |
774 | - return $this->line_items( array( array( 'LIN_type' => EEM_Line_Item::type_tax ) ) ); |
|
774 | + return $this->line_items(array(array('LIN_type' => EEM_Line_Item::type_tax))); |
|
775 | 775 | } |
776 | 776 | |
777 | 777 | |
@@ -784,10 +784,10 @@ discard block |
||
784 | 784 | * @throws \EE_Error |
785 | 785 | */ |
786 | 786 | public function total_line_item() { |
787 | - $item = $this->get_first_related( 'Line_Item', array( array( 'LIN_type' => EEM_Line_Item::type_total ) ) ); |
|
788 | - if( ! $item ){ |
|
789 | - EE_Registry::instance()->load_helper( 'Line_Item' ); |
|
790 | - $item = EEH_Line_Item::create_total_line_item( $this ); |
|
787 | + $item = $this->get_first_related('Line_Item', array(array('LIN_type' => EEM_Line_Item::type_total))); |
|
788 | + if ( ! $item) { |
|
789 | + EE_Registry::instance()->load_helper('Line_Item'); |
|
790 | + $item = EEH_Line_Item::create_total_line_item($this); |
|
791 | 791 | } |
792 | 792 | return $item; |
793 | 793 | } |
@@ -803,10 +803,10 @@ discard block |
||
803 | 803 | */ |
804 | 804 | public function tax_total() { |
805 | 805 | $tax_line_item = $this->tax_total_line_item(); |
806 | - if ( $tax_line_item ) { |
|
807 | - return (float)$tax_line_item->total(); |
|
806 | + if ($tax_line_item) { |
|
807 | + return (float) $tax_line_item->total(); |
|
808 | 808 | } else { |
809 | - return (float)0; |
|
809 | + return (float) 0; |
|
810 | 810 | } |
811 | 811 | } |
812 | 812 | |
@@ -819,7 +819,7 @@ discard block |
||
819 | 819 | * @throws \EE_Error |
820 | 820 | */ |
821 | 821 | public function tax_total_line_item() { |
822 | - return EEH_Line_Item::get_taxes_subtotal( $this->total_line_item() ); |
|
822 | + return EEH_Line_Item::get_taxes_subtotal($this->total_line_item()); |
|
823 | 823 | } |
824 | 824 | |
825 | 825 | |
@@ -830,20 +830,20 @@ discard block |
||
830 | 830 | * @return EE_Form_Section_Proper |
831 | 831 | * @throws \EE_Error |
832 | 832 | */ |
833 | - public function billing_info(){ |
|
833 | + public function billing_info() { |
|
834 | 834 | $payment_method = $this->payment_method(); |
835 | - if ( !$payment_method){ |
|
835 | + if ( ! $payment_method) { |
|
836 | 836 | EE_Error::add_error(__("Could not find billing info for transaction because no gateway has been used for it yet", "event_espresso"), __FILE__, __FUNCTION__, __LINE__); |
837 | 837 | return false; |
838 | 838 | } |
839 | 839 | $primary_reg = $this->primary_registration(); |
840 | - if ( ! $primary_reg ) { |
|
841 | - EE_Error::add_error( __( "Cannot get billing info for gateway %s on transaction because no primary registration exists", "event_espresso" ), __FILE__, __FUNCTION__, __LINE__ ); |
|
840 | + if ( ! $primary_reg) { |
|
841 | + EE_Error::add_error(__("Cannot get billing info for gateway %s on transaction because no primary registration exists", "event_espresso"), __FILE__, __FUNCTION__, __LINE__); |
|
842 | 842 | return FALSE; |
843 | 843 | } |
844 | 844 | $attendee = $primary_reg->attendee(); |
845 | - if ( ! $attendee ) { |
|
846 | - EE_Error::add_error( __( "Cannot get billing info for gateway %s on transaction because the primary registration has no attendee exists", "event_espresso" ), __FILE__, __FUNCTION__, __LINE__ ); |
|
845 | + if ( ! $attendee) { |
|
846 | + EE_Error::add_error(__("Cannot get billing info for gateway %s on transaction because the primary registration has no attendee exists", "event_espresso"), __FILE__, __FUNCTION__, __LINE__); |
|
847 | 847 | return FALSE; |
848 | 848 | } |
849 | 849 | return $attendee->billing_info_for_payment_method($payment_method); |
@@ -884,15 +884,15 @@ discard block |
||
884 | 884 | * @return EE_Payment_Method |
885 | 885 | * @throws \EE_Error |
886 | 886 | */ |
887 | - public function payment_method(){ |
|
887 | + public function payment_method() { |
|
888 | 888 | $pm = $this->get_first_related('Payment_Method'); |
889 | - if( $pm instanceof EE_Payment_Method ){ |
|
889 | + if ($pm instanceof EE_Payment_Method) { |
|
890 | 890 | return $pm; |
891 | - }else{ |
|
891 | + } else { |
|
892 | 892 | $last_payment = $this->last_payment(); |
893 | - if( $last_payment instanceof EE_Payment && $last_payment->payment_method() ){ |
|
893 | + if ($last_payment instanceof EE_Payment && $last_payment->payment_method()) { |
|
894 | 894 | return $last_payment->payment_method(); |
895 | - }else{ |
|
895 | + } else { |
|
896 | 896 | return NULL; |
897 | 897 | } |
898 | 898 | } |
@@ -907,7 +907,7 @@ discard block |
||
907 | 907 | * @throws \EE_Error |
908 | 908 | */ |
909 | 909 | public function last_payment() { |
910 | - return $this->get_first_related( 'Payment', array( 'order_by' => array( 'PAY_ID' => 'desc' ) ) ); |
|
910 | + return $this->get_first_related('Payment', array('order_by' => array('PAY_ID' => 'desc'))); |
|
911 | 911 | } |
912 | 912 | |
913 | 913 | |
@@ -918,8 +918,8 @@ discard block |
||
918 | 918 | * @return EE_Line_Item[] |
919 | 919 | * @throws \EE_Error |
920 | 920 | */ |
921 | - public function non_ticket_line_items(){ |
|
922 | - return EEM_Line_Item::instance()->get_all_non_ticket_line_items_for_transaction( $this->ID() ); |
|
921 | + public function non_ticket_line_items() { |
|
922 | + return EEM_Line_Item::instance()->get_all_non_ticket_line_items_for_transaction($this->ID()); |
|
923 | 923 | } |
924 | 924 | |
925 | 925 |
@@ -756,7 +756,7 @@ discard block |
||
756 | 756 | * Returns the name of the field's name that points to the WP_User table |
757 | 757 | * on this model (or follows the _model_chain_to_wp_user and uses that model's |
758 | 758 | * foreign key to the WP_User table) |
759 | - * @return string|boolean string on success, boolean false when there is no |
|
759 | + * @return string|false string on success, boolean false when there is no |
|
760 | 760 | * foreign key to the WP_User table |
761 | 761 | */ |
762 | 762 | public function wp_user_field_name() { |
@@ -851,6 +851,7 @@ discard block |
||
851 | 851 | * If you would like to use these custom selections in WHERE, GROUP_BY, or HAVING clauses, you must instead provide an array. |
852 | 852 | * Array keys are the aliases used to refer to this selection, and values are to be numerically-indexed arrays, where 0 is the selection |
853 | 853 | * and 1 is the data type. Eg, array('count'=>array('COUNT(REG_ID)','%d')) |
854 | + * @param string $columns_to_select |
|
854 | 855 | * @return array|stdClass[] like results of $wpdb->get_results($sql,OBJECT), (ie, output type is OBJECT) |
855 | 856 | * @throws \EE_Error |
856 | 857 | */ |
@@ -1196,7 +1197,7 @@ discard block |
||
1196 | 1197 | * @param bool $pretty Whether to return the pretty formats (true) or not (false). |
1197 | 1198 | * @throws EE_Error If the given field_name is not of the EE_Datetime_Field type. |
1198 | 1199 | * |
1199 | - * @return array formats in an array with the date format first, and the time format last. |
|
1200 | + * @return string[] formats in an array with the date format first, and the time format last. |
|
1200 | 1201 | */ |
1201 | 1202 | public function get_formats_for( $field_name, $pretty = false ) { |
1202 | 1203 | $field_settings = $this->field_settings_for( $field_name ); |
@@ -1231,7 +1232,7 @@ discard block |
||
1231 | 1232 | * |
1232 | 1233 | * @throws EE_Error If the given field_name is not of the EE_Datetime_Field type. |
1233 | 1234 | * |
1234 | - * @return int|string If the given field_name is not of the EE_Datetime_Field type, then an EE_Error |
|
1235 | + * @return string|null If the given field_name is not of the EE_Datetime_Field type, then an EE_Error |
|
1235 | 1236 | * exception is triggered. |
1236 | 1237 | */ |
1237 | 1238 | public function current_time_for_query( $field_name, $timestamp = false, $what = 'both' ) { |
@@ -1543,7 +1544,7 @@ discard block |
||
1543 | 1544 | * Wrapper for EEM_Base::delete_permanently() |
1544 | 1545 | * |
1545 | 1546 | * @param mixed $id |
1546 | - * @return boolean whether the row got deleted or not |
|
1547 | + * @return integer whether the row got deleted or not |
|
1547 | 1548 | * @throws \EE_Error |
1548 | 1549 | */ |
1549 | 1550 | public function delete_permanently_by_ID( $id ) { |
@@ -1562,7 +1563,7 @@ discard block |
||
1562 | 1563 | * Wrapper for EEM_Base::delete() |
1563 | 1564 | * |
1564 | 1565 | * @param mixed $id |
1565 | - * @return boolean whether the row got deleted or not |
|
1566 | + * @return integer whether the row got deleted or not |
|
1566 | 1567 | * @throws \EE_Error |
1567 | 1568 | */ |
1568 | 1569 | public function delete_by_ID( $id ){ |
@@ -1958,7 +1959,7 @@ discard block |
||
1958 | 1959 | /** |
1959 | 1960 | * Verifies the EE addons' database is up-to-date and records that we've done it on |
1960 | 1961 | * EEM_Base::$_db_verification_level |
1961 | - * @param $wpdb_method |
|
1962 | + * @param string $wpdb_method |
|
1962 | 1963 | * @param $arguments_to_provide |
1963 | 1964 | * @return string |
1964 | 1965 | */ |
@@ -2053,6 +2054,8 @@ discard block |
||
2053 | 2054 | * @return boolean of success |
2054 | 2055 | * @throws \EE_Error |
2055 | 2056 | * @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. |
2057 | + * @param EE_CPT_Base $id_or_obj |
|
2058 | + * @param EE_Term_Taxonomy $other_model_id_or_obj |
|
2056 | 2059 | */ |
2057 | 2060 | public function remove_relationship_to($id_or_obj, $other_model_id_or_obj, $relationName, $where_query= array() ){ |
2058 | 2061 | $relation_obj = $this->related_settings_for($relationName); |
@@ -2144,6 +2147,7 @@ discard block |
||
2144 | 2147 | * @param array $query_params like EEM_Base::get_all's |
2145 | 2148 | * @param string $field_to_count name of field to count by. By default, uses primary key |
2146 | 2149 | * @param bool $distinct if we want to only count the distinct values for the column then you can trigger that by the setting $distinct to TRUE; |
2150 | + * @param EE_Event $id_or_obj |
|
2147 | 2151 | * @return int |
2148 | 2152 | * @throws \EE_Error |
2149 | 2153 | */ |
@@ -2575,7 +2579,7 @@ discard block |
||
2575 | 2579 | /** |
2576 | 2580 | * Finds all the fields that correspond to the given table |
2577 | 2581 | * @param string $table_alias, array key in EEM_Base::_tables |
2578 | - * @return EE_Model_Field_Base[] |
|
2582 | + * @return EE_Model_Field_Base |
|
2579 | 2583 | */ |
2580 | 2584 | public function _get_fields_for_table($table_alias){ |
2581 | 2585 | return $this->_fields[$table_alias]; |
@@ -3838,8 +3842,8 @@ discard block |
||
3838 | 3842 | /** |
3839 | 3843 | * gets the field object of type 'primary_key' from the fieldsSettings attribute. |
3840 | 3844 | * Eg, on EE_Answer that would be ANS_ID field object |
3841 | - * @param $field_obj |
|
3842 | - * @return EE_Model_Field_Base |
|
3845 | + * @param EE_Model_Field_Base $field_obj |
|
3846 | + * @return boolean |
|
3843 | 3847 | */ |
3844 | 3848 | public function is_primary_key_field( $field_obj ){ |
3845 | 3849 | return $field_obj instanceof EE_Primary_Key_Field_Base ? TRUE : FALSE; |
@@ -3933,7 +3937,7 @@ discard block |
||
3933 | 3937 | * Gets the actual table for the table alias |
3934 | 3938 | * @param string $table_alias eg Event, Event_Meta, Registration, Transaction, but maybe |
3935 | 3939 | * a table alias with a model chain prefix, like 'Venue__Event_Venue___Event_Meta'. Either one works |
3936 | - * @return EE_Table_Base |
|
3940 | + * @return string |
|
3937 | 3941 | */ |
3938 | 3942 | public function get_table_for_alias($table_alias){ |
3939 | 3943 | $table_alias_sans_model_relation_chain_prefix = EE_Model_Parser::remove_table_alias_model_relation_chain_prefix($table_alias); |
@@ -4053,7 +4057,7 @@ discard block |
||
4053 | 4057 | * The purpose of this method is to allow us to create a model object that is not in the db that holds default values. |
4054 | 4058 | * A typical example of where this is used is when creating a new item and the initial load of a form. We dont' necessarily want to test for if the object is present but just assume it is BUT load the defaults from the object (as set in the model_field!). |
4055 | 4059 | * |
4056 | - * @return EE_Base_Class single EE_Base_Class object with default values for the properties. |
|
4060 | + * @return boolean single EE_Base_Class object with default values for the properties. |
|
4057 | 4061 | */ |
4058 | 4062 | public function create_default_object() { |
4059 | 4063 | |
@@ -4467,7 +4471,7 @@ discard block |
||
4467 | 4471 | } |
4468 | 4472 | /** |
4469 | 4473 | * Read comments for assume_values_already_prepared_by_model_object() |
4470 | - * @return int |
|
4474 | + * @return boolean |
|
4471 | 4475 | */ |
4472 | 4476 | public function get_assumption_concerning_values_already_prepared_by_model_object(){ |
4473 | 4477 | return $this->_values_already_prepared_by_model_object; |
@@ -616,11 +616,11 @@ discard block |
||
616 | 616 | * Gets all the EE_Base_Class objects which match the $query_params, by querying the DB. |
617 | 617 | * |
618 | 618 | * @param array $query_params { |
619 | - * @var array $0 (where) array { |
|
619 | + * @var array $0 (where) array { |
|
620 | 620 | * eg: array('QST_display_text'=>'Are you bob?','QST_admin_text'=>'Determine if user is bob') |
621 | - * becomes |
|
621 | + * becomes |
|
622 | 622 | * SQL >> "...WHERE QST_display_text = 'Are you bob?' AND QST_admin_text = 'Determine if user is bob'...") |
623 | - * To add WHERE conditions based on related models (and even models-related-to-related-models) prepend the model's name |
|
623 | + * To add WHERE conditions based on related models (and even models-related-to-related-models) prepend the model's name |
|
624 | 624 | * onto the field name. Eg, EEM_Event::instance()->get_all(array(array('Venue.VNU_ID'=>12))); |
625 | 625 | * becomes |
626 | 626 | * SQL >> "SELECT * FROM wp_posts AS Event_CPT |
@@ -640,7 +640,7 @@ discard block |
||
640 | 640 | * SQL >> "...WHERE QST_display_text LIKE '%bob%' AND QST_ID < 34 AND QST_wp_user IN (1,2,7,23)...". |
641 | 641 | * Valid operators so far: =, !=, <, <=, >, >=, LIKE, NOT LIKE, IN (followed by numeric-indexed array), |
642 | 642 | * NOT IN (dido), BETWEEN (followed by an array with exactly 2 date strings), IS NULL, and IS NOT NULL |
643 | - * Values can be a string, int, or float. They can also be arrays IFF the operator is IN. |
|
643 | + * Values can be a string, int, or float. They can also be arrays IFF the operator is IN. |
|
644 | 644 | * Also, values can actually be field names. To indicate the value is a field, |
645 | 645 | * simply provide a third array item (true) to the operator-value array like so: |
646 | 646 | * eg: array( 'DTT_reg_limit' => array('>', 'DTT_sold', TRUE) ) |
@@ -649,7 +649,7 @@ discard block |
||
649 | 649 | * Note: you can also use related model field names like you would any other field name. |
650 | 650 | * eg: array('Datetime.DTT_reg_limit'=>array('=','Datetime.DTT_sold',TRUE) |
651 | 651 | * could be used if you were querying EEM_Tickets (because Datetime is directly related to tickets) |
652 | - * Also, by default all the where conditions are AND'd together. |
|
652 | + * Also, by default all the where conditions are AND'd together. |
|
653 | 653 | * To override this, add an array key 'OR' (or 'AND') and the array to be OR'd together |
654 | 654 | * eg: array('OR'=>array('TXN_ID' => 23 , 'TXN_timestamp__>' => 345678912)) |
655 | 655 | * becomes |
@@ -664,17 +664,17 @@ discard block |
||
664 | 664 | * eg array('OR'=>array('NOT'=>array('TXN_total' => 50, 'TXN_paid'=>23)),AND=>array('TXN_ID'=>1,'STS_ID'=>'TIN') |
665 | 665 | * becomes |
666 | 666 | * SQL >> "...where ! (TXN_total =50 OR TXN_paid =23) AND TXN_ID=1 AND STS_ID='TIN'" |
667 | - * They can be nested indefinitely. |
|
667 | + * They can be nested indefinitely. |
|
668 | 668 | * eg: array('OR'=>array('TXN_total' => 23, 'NOT'=> array( 'TXN_timestamp'=> 345678912, 'AND'=>array('TXN_paid' => 53, 'STS_ID' => 'TIN')))) |
669 | 669 | * becomes |
670 | 670 | * SQL >> "...WHERE TXN_total = 23 OR ! (TXN_timestamp = 345678912 OR (TXN_paid = 53 AND STS_ID = 'TIN'))..." |
671 | - * GOTCHA: |
|
671 | + * GOTCHA: |
|
672 | 672 | * because this is an array, array keys must be unique, making it impossible to place two or more where conditions applying to the same field. |
673 | 673 | * eg: array('PAY_timestamp'=>array('>',$start_date),'PAY_timestamp'=>array('<',$end_date),'PAY_timestamp'=>array('!=',$special_date)), |
674 | 674 | * as PHP enforces that the array keys must be unique, thus removing the first two array entries with key 'PAY_timestamp'. |
675 | 675 | * becomes |
676 | 676 | * SQL >> "PAY_timestamp != 4234232", ignoring the first two PAY_timestamp conditions). |
677 | - * To overcome this, you can add a '*' character to the end of the field's name, followed by anything. |
|
677 | + * To overcome this, you can add a '*' character to the end of the field's name, followed by anything. |
|
678 | 678 | * These will be removed when generating the SQL string, but allow for the array keys to be unique. |
679 | 679 | * eg: you could rewrite the previous query as: |
680 | 680 | * array('PAY_timestamp'=>array('>',$start_date),'PAY_timestamp*1st'=>array('<',$end_date),'PAY_timestamp*2nd'=>array('!=',$special_date)) |
@@ -695,14 +695,14 @@ discard block |
||
695 | 695 | * descending order. Acceptable values are 'ASC' or 'DESC'. If, 'order_by' isn't used, but 'order' is, then it is assumed you want to order by the primary key. |
696 | 696 | * Eg, EEM_Event::instance()->get_all(array('order_by'=>'Datetime.DTT_EVT_start','order'=>'ASC'); //(will join with the Datetime model's table(s) and order by its field DTT_EVT_start) |
697 | 697 | * or EEM_Registration::instance()->get_all(array('order'=>'ASC'));//will make SQL "SELECT * FROM wp_esp_registration ORDER BY REG_ID ASC" |
698 | - * @var mixed $group_by name of field to order by, or an array of fields. Eg either 'group_by'=>'VNU_ID', or 'group_by'=>array('EVT_name','Registration.Transaction.TXN_total') |
|
699 | - * @var array $having exactly like WHERE parameters array, except these conditions apply to the grouped results (whereas WHERE conditions apply to the pre-grouped results) |
|
700 | - * @var array $force_join forces a join with the models named. Should be an numerically-indexed array where values are models to be joined in the query.Eg |
|
698 | + * @var mixed $group_by name of field to order by, or an array of fields. Eg either 'group_by'=>'VNU_ID', or 'group_by'=>array('EVT_name','Registration.Transaction.TXN_total') |
|
699 | + * @var array $having exactly like WHERE parameters array, except these conditions apply to the grouped results (whereas WHERE conditions apply to the pre-grouped results) |
|
700 | + * @var array $force_join forces a join with the models named. Should be an numerically-indexed array where values are models to be joined in the query.Eg |
|
701 | 701 | * array('Attendee','Payment','Datetime'). You may join with transient models using period, eg "Registration.Transaction.Payment". |
702 | 702 | * You will probably only want to do this in hopes of increasing efficiency, as related models which belongs to the current model |
703 | 703 | * (ie, the current model has a foreign key to them, like how Registration belongs to Attendee) can be cached in order |
704 | 704 | * to avoid future queries |
705 | - * @var string $default_where_conditions can be set to 'none', 'this_model_only', 'other_models_only', or 'all'. set this to 'none' to disable all default where conditions. Eg, usually soft-deleted objects are filtered-out |
|
705 | + * @var string $default_where_conditions can be set to 'none', 'this_model_only', 'other_models_only', or 'all'. set this to 'none' to disable all default where conditions. Eg, usually soft-deleted objects are filtered-out |
|
706 | 706 | * if you want to include them, set this query param to 'none'. If you want to ONLY disable THIS model's default where conditions |
707 | 707 | * set it to 'other_models_only'. If you only want this model's default where conditions added to the query, use 'this_model_only'. |
708 | 708 | * If you want to use all default where conditions (default), set to 'all'. |
@@ -1070,7 +1070,7 @@ discard block |
||
1070 | 1070 | * can indicate just the columns you |
1071 | 1071 | * want and a single array indexed by |
1072 | 1072 | * the columns will be returned. |
1073 | - * @return EE_Base_Class|null|array() |
|
1073 | + * @return EE_Base_Class|null|array() |
|
1074 | 1074 | * @throws EE_Error |
1075 | 1075 | */ |
1076 | 1076 | public function previous( $current_field_value, $field_to_order_by = null, $query_params = array(), $columns_to_select = null ) { |
@@ -1720,7 +1720,7 @@ discard block |
||
1720 | 1720 | //make sure there's no related objects blocking its deletion (if we're checking) |
1721 | 1721 | if ( |
1722 | 1722 | $allow_blocking |
1723 | - && $this->delete_is_blocked_by_related_models( |
|
1723 | + && $this->delete_is_blocked_by_related_models( |
|
1724 | 1724 | $delete_object[ $primary_table->get_fully_qualified_pk_column() ] |
1725 | 1725 | ) |
1726 | 1726 | ) { |
@@ -2867,8 +2867,8 @@ discard block |
||
2867 | 2867 | } |
2868 | 2868 | //if 'order_by' wasn't set, maybe they are just using 'order' on its own? |
2869 | 2869 | if ( ! array_key_exists( 'order_by', $query_params ) |
2870 | - && array_key_exists( 'order', $query_params ) |
|
2871 | - && ! empty( $query_params['order'] ) |
|
2870 | + && array_key_exists( 'order', $query_params ) |
|
2871 | + && ! empty( $query_params['order'] ) |
|
2872 | 2872 | ) { |
2873 | 2873 | $pk_field = $this->get_primary_key_field(); |
2874 | 2874 | $order = $this->_extract_order( $query_params['order'] ); |
@@ -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 |
@@ -236,7 +236,7 @@ discard block |
||
236 | 236 | * Flag indicating whether this model has a primary key or not |
237 | 237 | * @var boolean |
238 | 238 | */ |
239 | - protected $_has_primary_key_field=null; |
|
239 | + protected $_has_primary_key_field = null; |
|
240 | 240 | |
241 | 241 | /** |
242 | 242 | * Whether or not this model is based off a table in WP core only (CPTs should set |
@@ -298,19 +298,19 @@ discard block |
||
298 | 298 | * operators that work like 'BETWEEN'. Typically used for datetime calculations, i.e. "BETWEEN '12-1-2011' AND '12-31-2012'" |
299 | 299 | * @var array |
300 | 300 | */ |
301 | - protected $_between_style_operators = array( 'BETWEEN' ); |
|
301 | + protected $_between_style_operators = array('BETWEEN'); |
|
302 | 302 | |
303 | 303 | /** |
304 | 304 | * operators that are used for handling NUll and !NULL queries. Typically used for when checking if a row exists on a join table. |
305 | 305 | * @var array |
306 | 306 | */ |
307 | - protected $_null_style_operators = array( 'IS NOT NULL', 'IS NULL'); |
|
307 | + protected $_null_style_operators = array('IS NOT NULL', 'IS NULL'); |
|
308 | 308 | |
309 | 309 | /** |
310 | 310 | * Allowed values for $query_params['order'] for ordering in queries |
311 | 311 | * @var array |
312 | 312 | */ |
313 | - protected $_allowed_order_values = array('asc','desc','ASC','DESC'); |
|
313 | + protected $_allowed_order_values = array('asc', 'desc', 'ASC', 'DESC'); |
|
314 | 314 | |
315 | 315 | /** |
316 | 316 | * When these are keys in a WHERE or HAVING clause, they are handled much differently |
@@ -324,13 +324,13 @@ discard block |
||
324 | 324 | * 'where', but 'where' clauses are so common that we thought we'd omit it |
325 | 325 | * @var array |
326 | 326 | */ |
327 | - private $_allowed_query_params = array(0, 'limit','order_by','group_by','having','force_join','order','on_join_limit','default_where_conditions', 'caps'); |
|
327 | + private $_allowed_query_params = array(0, 'limit', 'order_by', 'group_by', 'having', 'force_join', 'order', 'on_join_limit', 'default_where_conditions', 'caps'); |
|
328 | 328 | |
329 | 329 | /** |
330 | 330 | * All the data types that can be used in $wpdb->prepare statements. |
331 | 331 | * @var array |
332 | 332 | */ |
333 | - private $_valid_wpdb_data_types = array('%d','%s','%f'); |
|
333 | + private $_valid_wpdb_data_types = array('%d', '%s', '%f'); |
|
334 | 334 | |
335 | 335 | /** |
336 | 336 | * EE_Registry Object |
@@ -363,17 +363,17 @@ discard block |
||
363 | 363 | /** |
364 | 364 | * constant used to show EEM_Base has not yet verified the db on this http request |
365 | 365 | */ |
366 | - const db_verified_none = 0; |
|
366 | + const db_verified_none = 0; |
|
367 | 367 | /** |
368 | 368 | * constant used to show EEM_Base has verified the EE core db on this http request, |
369 | 369 | * but not the addons' dbs |
370 | 370 | */ |
371 | - const db_verified_core = 1; |
|
371 | + const db_verified_core = 1; |
|
372 | 372 | /** |
373 | 373 | * constant used to show EEM_Base has verified the addons' dbs (and implicitly |
374 | 374 | * the EE core db too) |
375 | 375 | */ |
376 | - const db_verified_addons = 2; |
|
376 | + const db_verified_addons = 2; |
|
377 | 377 | |
378 | 378 | /** |
379 | 379 | * indicates whether an EEM_Base child has already re-verified the DB |
@@ -404,13 +404,13 @@ discard block |
||
404 | 404 | * @param null $timezone |
405 | 405 | * @throws \EE_Error |
406 | 406 | */ |
407 | - protected function __construct( $timezone = NULL ){ |
|
407 | + protected function __construct($timezone = NULL) { |
|
408 | 408 | // check that the model has not been loaded too soon |
409 | - if ( ! did_action( 'AHEE__EE_System__load_espresso_addons' )) { |
|
410 | - throw new EE_Error ( |
|
409 | + if ( ! did_action('AHEE__EE_System__load_espresso_addons')) { |
|
410 | + throw new EE_Error( |
|
411 | 411 | sprintf( |
412 | - __( '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' ), |
|
413 | - get_class( $this ) |
|
412 | + __('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'), |
|
413 | + get_class($this) |
|
414 | 414 | ) |
415 | 415 | ); |
416 | 416 | } |
@@ -420,11 +420,11 @@ discard block |
||
420 | 420 | * just use EE_Register_Model_Extension |
421 | 421 | * @var EE_Table_Base[] $_tables |
422 | 422 | */ |
423 | - $this->_tables = apply_filters( 'FHEE__'.get_class($this).'__construct__tables', $this->_tables ); |
|
424 | - foreach($this->_tables as $table_alias => $table_obj){ |
|
423 | + $this->_tables = apply_filters('FHEE__'.get_class($this).'__construct__tables', $this->_tables); |
|
424 | + foreach ($this->_tables as $table_alias => $table_obj) { |
|
425 | 425 | /** @var $table_obj EE_Table_Base */ |
426 | 426 | $table_obj->_construct_finalize_with_alias($table_alias); |
427 | - if( $table_obj instanceof EE_Secondary_Table ){ |
|
427 | + if ($table_obj instanceof EE_Secondary_Table) { |
|
428 | 428 | /** @var $table_obj EE_Secondary_Table */ |
429 | 429 | $table_obj->_construct_finalize_set_table_to_join_with($this->_get_main_table()); |
430 | 430 | } |
@@ -434,54 +434,54 @@ discard block |
||
434 | 434 | * EE_Register_Model_Extension |
435 | 435 | * @param EE_Model_Field_Base[] $_fields |
436 | 436 | */ |
437 | - $this->_fields = apply_filters('FHEE__'.get_class($this).'__construct__fields',$this->_fields); |
|
437 | + $this->_fields = apply_filters('FHEE__'.get_class($this).'__construct__fields', $this->_fields); |
|
438 | 438 | $this->_invalidate_field_caches(); |
439 | - foreach($this->_fields as $table_alias => $fields_for_table){ |
|
440 | - if ( ! array_key_exists( $table_alias, $this->_tables )){ |
|
441 | - throw new EE_Error(sprintf(__("Table alias %s does not exist in EEM_Base child's _tables array. Only tables defined are %s",'event_espresso'),$table_alias,implode(",",$this->_fields))); |
|
439 | + foreach ($this->_fields as $table_alias => $fields_for_table) { |
|
440 | + if ( ! array_key_exists($table_alias, $this->_tables)) { |
|
441 | + 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))); |
|
442 | 442 | } |
443 | - foreach($fields_for_table as $field_name => $field_obj){ |
|
443 | + foreach ($fields_for_table as $field_name => $field_obj) { |
|
444 | 444 | /** @var $field_obj EE_Model_Field_Base | EE_Primary_Key_Field_Base */ |
445 | 445 | //primary key field base has a slightly different _construct_finalize |
446 | 446 | /** @var $field_obj EE_Model_Field_Base */ |
447 | - $field_obj->_construct_finalize( $table_alias, $field_name, $this->get_this_model_name() ); |
|
447 | + $field_obj->_construct_finalize($table_alias, $field_name, $this->get_this_model_name()); |
|
448 | 448 | } |
449 | 449 | } |
450 | 450 | |
451 | 451 | // everything is related to Extra_Meta |
452 | - if( get_class($this) !== 'EEM_Extra_Meta'){ |
|
452 | + if (get_class($this) !== 'EEM_Extra_Meta') { |
|
453 | 453 | //make extra meta related to everything, but don't block deleting things just |
454 | 454 | //because they have related extra meta info. For now just orphan those extra meta |
455 | 455 | //in the future we should automatically delete them |
456 | - $this->_model_relations['Extra_Meta'] = new EE_Has_Many_Any_Relation( FALSE ); |
|
456 | + $this->_model_relations['Extra_Meta'] = new EE_Has_Many_Any_Relation(FALSE); |
|
457 | 457 | } |
458 | 458 | //and change logs |
459 | - if( get_class( $this) !== 'EEM_Change_Log' ) { |
|
460 | - $this->_model_relations[ 'Change_Log' ] = new EE_Has_Many_Any_Relation( FALSE ); |
|
459 | + if (get_class($this) !== 'EEM_Change_Log') { |
|
460 | + $this->_model_relations['Change_Log'] = new EE_Has_Many_Any_Relation(FALSE); |
|
461 | 461 | } |
462 | 462 | /** |
463 | 463 | * Filters the list of relations on a model. It is best to NOT use this directly and instead just use |
464 | 464 | * EE_Register_Model_Extension |
465 | 465 | * @param EE_Model_Relation_Base[] $_model_relations |
466 | 466 | */ |
467 | - $this->_model_relations = apply_filters('FHEE__'.get_class($this).'__construct__model_relations',$this->_model_relations); |
|
468 | - foreach($this->_model_relations as $model_name => $relation_obj){ |
|
467 | + $this->_model_relations = apply_filters('FHEE__'.get_class($this).'__construct__model_relations', $this->_model_relations); |
|
468 | + foreach ($this->_model_relations as $model_name => $relation_obj) { |
|
469 | 469 | /** @var $relation_obj EE_Model_Relation_Base */ |
470 | 470 | $relation_obj->_construct_finalize_set_models($this->get_this_model_name(), $model_name); |
471 | 471 | } |
472 | - foreach($this->_indexes as $index_name => $index_obj){ |
|
472 | + foreach ($this->_indexes as $index_name => $index_obj) { |
|
473 | 473 | /** @var $index_obj EE_Index */ |
474 | 474 | $index_obj->_construct_finalize($index_name, $this->get_this_model_name()); |
475 | 475 | } |
476 | 476 | |
477 | 477 | $this->set_timezone($timezone); |
478 | 478 | //finalize default where condition strategy, or set default |
479 | - if( ! $this->_default_where_conditions_strategy){ |
|
479 | + if ( ! $this->_default_where_conditions_strategy) { |
|
480 | 480 | //nothing was set during child constructor, so set default |
481 | 481 | $this->_default_where_conditions_strategy = new EE_Default_Where_Conditions(); |
482 | 482 | } |
483 | 483 | $this->_default_where_conditions_strategy->_finalize_construct($this); |
484 | - if( ! $this->_minimum_where_conditions_strategy){ |
|
484 | + if ( ! $this->_minimum_where_conditions_strategy) { |
|
485 | 485 | //nothing was set during child constructor, so set default |
486 | 486 | $this->_minimum_where_conditions_strategy = new EE_Default_Where_Conditions(); |
487 | 487 | } |
@@ -489,15 +489,15 @@ discard block |
||
489 | 489 | |
490 | 490 | //if the cap slug hasn't been set, and we haven't set it to false on purpose |
491 | 491 | //to indicate to NOT set it, set it to the logical default |
492 | - if( $this->_caps_slug === null ) { |
|
493 | - EE_Registry::instance()->load_helper( 'Inflector' ); |
|
494 | - $this->_caps_slug = EEH_Inflector::pluralize_and_lower( $this->get_this_model_name() ); |
|
492 | + if ($this->_caps_slug === null) { |
|
493 | + EE_Registry::instance()->load_helper('Inflector'); |
|
494 | + $this->_caps_slug = EEH_Inflector::pluralize_and_lower($this->get_this_model_name()); |
|
495 | 495 | } |
496 | 496 | //initialize the standard cap restriction generators if none were specified by the child constructor |
497 | - if( $this->_cap_restriction_generators !== false ){ |
|
498 | - foreach( $this->cap_contexts_to_cap_action_map() as $cap_context => $action ){ |
|
499 | - if( ! isset( $this->_cap_restriction_generators[ $cap_context ] ) ) { |
|
500 | - $this->_cap_restriction_generators[ $cap_context ] = apply_filters( |
|
497 | + if ($this->_cap_restriction_generators !== false) { |
|
498 | + foreach ($this->cap_contexts_to_cap_action_map() as $cap_context => $action) { |
|
499 | + if ( ! isset($this->_cap_restriction_generators[$cap_context])) { |
|
500 | + $this->_cap_restriction_generators[$cap_context] = apply_filters( |
|
501 | 501 | 'FHEE__EEM_Base___construct__standard_cap_restriction_generator', |
502 | 502 | new EE_Restriction_Generator_Protected(), |
503 | 503 | $cap_context, |
@@ -507,23 +507,23 @@ discard block |
||
507 | 507 | } |
508 | 508 | } |
509 | 509 | //if there are cap restriction generators, use them to make the default cap restrictions |
510 | - if( $this->_cap_restriction_generators !== false ){ |
|
511 | - foreach( $this->_cap_restriction_generators as $context => $generator_object ) { |
|
512 | - if( ! $generator_object ){ |
|
510 | + if ($this->_cap_restriction_generators !== false) { |
|
511 | + foreach ($this->_cap_restriction_generators as $context => $generator_object) { |
|
512 | + if ( ! $generator_object) { |
|
513 | 513 | continue; |
514 | 514 | } |
515 | - if( ! $generator_object instanceof EE_Restriction_Generator_Base ){ |
|
515 | + if ( ! $generator_object instanceof EE_Restriction_Generator_Base) { |
|
516 | 516 | throw new EE_Error( |
517 | 517 | sprintf( |
518 | - __( 'Index "%1$s" in the model %2$s\'s _cap_restriction_generators is not a child of EE_Restriction_Generator_Base. It should be that or NULL.', 'event_espresso' ), |
|
518 | + __('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'), |
|
519 | 519 | $context, |
520 | 520 | $this->get_this_model_name() |
521 | 521 | ) |
522 | 522 | ); |
523 | 523 | } |
524 | - $action = $this->cap_action_for_context( $context ); |
|
525 | - if( ! $generator_object->construction_finalized() ){ |
|
526 | - $generator_object->_construct_finalize( $this, $action ); |
|
524 | + $action = $this->cap_action_for_context($context); |
|
525 | + if ( ! $generator_object->construction_finalized()) { |
|
526 | + $generator_object->_construct_finalize($this, $action); |
|
527 | 527 | } |
528 | 528 | |
529 | 529 | } |
@@ -537,11 +537,11 @@ discard block |
||
537 | 537 | * @param string $context one of EEM_Base::valid_cap_contexts() |
538 | 538 | * @return EE_Default_Where_Conditions[] |
539 | 539 | */ |
540 | - protected function _generate_cap_restrictions( $context ){ |
|
541 | - if( isset( $this->_cap_restriction_generators[ $context ] ) && |
|
542 | - $this->_cap_restriction_generators[ $context ] instanceof EE_Restriction_Generator_Base ) { |
|
543 | - return $this->_cap_restriction_generators[ $context ]->generate_restrictions(); |
|
544 | - }else{ |
|
540 | + protected function _generate_cap_restrictions($context) { |
|
541 | + if (isset($this->_cap_restriction_generators[$context]) && |
|
542 | + $this->_cap_restriction_generators[$context] instanceof EE_Restriction_Generator_Base) { |
|
543 | + return $this->_cap_restriction_generators[$context]->generate_restrictions(); |
|
544 | + } else { |
|
545 | 545 | return array(); |
546 | 546 | } |
547 | 547 | } |
@@ -554,16 +554,16 @@ discard block |
||
554 | 554 | * @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) |
555 | 555 | * @return static (as in the concrete child class) |
556 | 556 | */ |
557 | - public static function instance( $timezone = NULL ){ |
|
557 | + public static function instance($timezone = NULL) { |
|
558 | 558 | |
559 | 559 | // check if instance of Espresso_model already exists |
560 | 560 | if ( ! static::$_instance instanceof static) { |
561 | 561 | // instantiate Espresso_model |
562 | - static::$_instance = new static( $timezone ); |
|
562 | + static::$_instance = new static($timezone); |
|
563 | 563 | } |
564 | 564 | |
565 | 565 | //we might have a timezone set, let set_timezone decide what to do with it |
566 | - static::$_instance->set_timezone( $timezone ); |
|
566 | + static::$_instance->set_timezone($timezone); |
|
567 | 567 | |
568 | 568 | // Espresso_model object |
569 | 569 | return static::$_instance; |
@@ -576,11 +576,11 @@ discard block |
||
576 | 576 | * @param null | string $timezone |
577 | 577 | * @return static |
578 | 578 | */ |
579 | - public static function reset( $timezone = NULL ){ |
|
580 | - if ( ! is_null( static::$_instance ) ) { |
|
579 | + public static function reset($timezone = NULL) { |
|
580 | + if ( ! is_null(static::$_instance)) { |
|
581 | 581 | static::$_instance = null; |
582 | 582 | |
583 | - return self::instance( $timezone ); |
|
583 | + return self::instance($timezone); |
|
584 | 584 | } |
585 | 585 | return null; |
586 | 586 | } |
@@ -594,19 +594,19 @@ discard block |
||
594 | 594 | * @return array |
595 | 595 | * @throws \EE_Error |
596 | 596 | */ |
597 | - public function status_array( $translated = FALSE ) { |
|
598 | - if ( ! array_key_exists( 'Status', $this->_model_relations ) ) { |
|
597 | + public function status_array($translated = FALSE) { |
|
598 | + if ( ! array_key_exists('Status', $this->_model_relations)) { |
|
599 | 599 | return array(); |
600 | 600 | } |
601 | 601 | $model_name = $this->get_this_model_name(); |
602 | - $status_type = str_replace( ' ', '_', strtolower( str_replace( '_', ' ', $model_name ) ) ); |
|
603 | - $stati = EEM_Status::instance()->get_all( array( array( 'STS_type' => $status_type ) ) ); |
|
602 | + $status_type = str_replace(' ', '_', strtolower(str_replace('_', ' ', $model_name))); |
|
603 | + $stati = EEM_Status::instance()->get_all(array(array('STS_type' => $status_type))); |
|
604 | 604 | $status_array = array(); |
605 | - foreach ( $stati as $status ) { |
|
606 | - $status_array[ $status->ID() ] = $status->get( 'STS_code' ); |
|
605 | + foreach ($stati as $status) { |
|
606 | + $status_array[$status->ID()] = $status->get('STS_code'); |
|
607 | 607 | } |
608 | 608 | return $translated |
609 | - ? EEM_Status::instance()->localized_status( $status_array, false, 'sentence' ) |
|
609 | + ? EEM_Status::instance()->localized_status($status_array, false, 'sentence') |
|
610 | 610 | : $status_array; |
611 | 611 | } |
612 | 612 | |
@@ -734,7 +734,7 @@ discard block |
||
734 | 734 | * )); |
735 | 735 | * @throws \EE_Error |
736 | 736 | */ |
737 | - public function get_all($query_params = array()){ |
|
737 | + public function get_all($query_params = array()) { |
|
738 | 738 | return $this->_create_objects($this->_get_all_wpdb_results($query_params, ARRAY_A, NULL)); |
739 | 739 | } |
740 | 740 | |
@@ -744,10 +744,10 @@ discard block |
||
744 | 744 | * @param array $query_params @see EEM_Base::get_all() |
745 | 745 | * @return array like EEM_Base::get_all |
746 | 746 | */ |
747 | - public function alter_query_params_to_only_include_mine( $query_params = array() ) { |
|
747 | + public function alter_query_params_to_only_include_mine($query_params = array()) { |
|
748 | 748 | $wp_user_field_name = $this->wp_user_field_name(); |
749 | - if( $wp_user_field_name ){ |
|
750 | - $query_params[0][ $wp_user_field_name ] = get_current_user_id(); |
|
749 | + if ($wp_user_field_name) { |
|
750 | + $query_params[0][$wp_user_field_name] = get_current_user_id(); |
|
751 | 751 | } |
752 | 752 | return $query_params; |
753 | 753 | } |
@@ -760,19 +760,19 @@ discard block |
||
760 | 760 | * foreign key to the WP_User table |
761 | 761 | */ |
762 | 762 | public function wp_user_field_name() { |
763 | - try{ |
|
764 | - if( ! empty( $this->_model_chain_to_wp_user ) ) { |
|
765 | - $models_to_follow_to_wp_users = explode( '.', $this->_model_chain_to_wp_user ); |
|
766 | - $last_model_name = end( $models_to_follow_to_wp_users ); |
|
767 | - $model_with_fk_to_wp_users = EE_Registry::instance()->load_model( $last_model_name ); |
|
768 | - $model_chain_to_wp_user = $this->_model_chain_to_wp_user . '.'; |
|
769 | - }else{ |
|
763 | + try { |
|
764 | + if ( ! empty($this->_model_chain_to_wp_user)) { |
|
765 | + $models_to_follow_to_wp_users = explode('.', $this->_model_chain_to_wp_user); |
|
766 | + $last_model_name = end($models_to_follow_to_wp_users); |
|
767 | + $model_with_fk_to_wp_users = EE_Registry::instance()->load_model($last_model_name); |
|
768 | + $model_chain_to_wp_user = $this->_model_chain_to_wp_user.'.'; |
|
769 | + } else { |
|
770 | 770 | $model_with_fk_to_wp_users = $this; |
771 | 771 | $model_chain_to_wp_user = ''; |
772 | 772 | } |
773 | - $wp_user_field = $model_with_fk_to_wp_users->get_foreign_key_to( 'WP_User' ); |
|
774 | - return $model_chain_to_wp_user . $wp_user_field->get_name(); |
|
775 | - }catch( EE_Error $e ) { |
|
773 | + $wp_user_field = $model_with_fk_to_wp_users->get_foreign_key_to('WP_User'); |
|
774 | + return $model_chain_to_wp_user.$wp_user_field->get_name(); |
|
775 | + } catch (EE_Error $e) { |
|
776 | 776 | return false; |
777 | 777 | } |
778 | 778 | } |
@@ -786,7 +786,7 @@ discard block |
||
786 | 786 | * (or transiently-related model) |
787 | 787 | * @return string |
788 | 788 | */ |
789 | - public function model_chain_to_wp_user(){ |
|
789 | + public function model_chain_to_wp_user() { |
|
790 | 790 | return $this->_model_chain_to_wp_user; |
791 | 791 | } |
792 | 792 | |
@@ -798,13 +798,13 @@ discard block |
||
798 | 798 | * @return boolean |
799 | 799 | */ |
800 | 800 | public function is_owned() { |
801 | - if( $this->model_chain_to_wp_user() ){ |
|
801 | + if ($this->model_chain_to_wp_user()) { |
|
802 | 802 | return true; |
803 | - }else{ |
|
804 | - try{ |
|
805 | - $this->get_foreign_key_to( 'WP_User' ); |
|
803 | + } else { |
|
804 | + try { |
|
805 | + $this->get_foreign_key_to('WP_User'); |
|
806 | 806 | return true; |
807 | - }catch( EE_Error $e ){ |
|
807 | + } catch (EE_Error $e) { |
|
808 | 808 | return false; |
809 | 809 | } |
810 | 810 | } |
@@ -826,17 +826,17 @@ discard block |
||
826 | 826 | * @return array | stdClass[] like results of $wpdb->get_results($sql,OBJECT), (ie, output type is OBJECT) |
827 | 827 | * @throws \EE_Error |
828 | 828 | */ |
829 | - protected function _get_all_wpdb_results($query_params = array(), $output = ARRAY_A, $columns_to_select = null){ |
|
829 | + protected function _get_all_wpdb_results($query_params = array(), $output = ARRAY_A, $columns_to_select = null) { |
|
830 | 830 | // remember the custom selections, if any, and type cast as array |
831 | 831 | // (unless $columns_to_select is an object, then just set as an empty array) |
832 | 832 | // Note: (array) 'some string' === array( 'some string' ) |
833 | - $this->_custom_selections = ! is_object( $columns_to_select ) ? (array) $columns_to_select : array(); |
|
834 | - $model_query_info = $this->_create_model_query_info_carrier( $query_params ); |
|
833 | + $this->_custom_selections = ! is_object($columns_to_select) ? (array) $columns_to_select : array(); |
|
834 | + $model_query_info = $this->_create_model_query_info_carrier($query_params); |
|
835 | 835 | $select_expressions = $columns_to_select !== null |
836 | - ? $this->_construct_select_from_input( $columns_to_select ) |
|
837 | - : $this->_construct_default_select_sql( $model_query_info ); |
|
838 | - $SQL = "SELECT $select_expressions " . $this->_construct_2nd_half_of_select_query( $model_query_info ); |
|
839 | - return $this->_do_wpdb_query( 'get_results', array( $SQL, $output ) ); |
|
836 | + ? $this->_construct_select_from_input($columns_to_select) |
|
837 | + : $this->_construct_default_select_sql($model_query_info); |
|
838 | + $SQL = "SELECT $select_expressions ".$this->_construct_2nd_half_of_select_query($model_query_info); |
|
839 | + return $this->_do_wpdb_query('get_results', array($SQL, $output)); |
|
840 | 840 | } |
841 | 841 | |
842 | 842 | /** |
@@ -854,7 +854,7 @@ discard block |
||
854 | 854 | * @return array|stdClass[] like results of $wpdb->get_results($sql,OBJECT), (ie, output type is OBJECT) |
855 | 855 | * @throws \EE_Error |
856 | 856 | */ |
857 | - public function get_all_wpdb_results($query_params = array(), $output = ARRAY_A, $columns_to_select = null){ |
|
857 | + public function get_all_wpdb_results($query_params = array(), $output = ARRAY_A, $columns_to_select = null) { |
|
858 | 858 | return $this->_get_all_wpdb_results($query_params, $output, $columns_to_select); |
859 | 859 | } |
860 | 860 | |
@@ -866,12 +866,12 @@ discard block |
||
866 | 866 | * @throws EE_Error |
867 | 867 | * @return string |
868 | 868 | */ |
869 | - private function _construct_select_from_input($columns_to_select){ |
|
870 | - if(is_array($columns_to_select)){ |
|
869 | + private function _construct_select_from_input($columns_to_select) { |
|
870 | + if (is_array($columns_to_select)) { |
|
871 | 871 | $select_sql_array = array(); |
872 | 872 | |
873 | - foreach($columns_to_select as $alias => $selection_and_datatype){ |
|
874 | - if( ! is_array($selection_and_datatype) || ! isset($selection_and_datatype[1])){ |
|
873 | + foreach ($columns_to_select as $alias => $selection_and_datatype) { |
|
874 | + if ( ! is_array($selection_and_datatype) || ! isset($selection_and_datatype[1])) { |
|
875 | 875 | throw new EE_Error( |
876 | 876 | sprintf( |
877 | 877 | __( |
@@ -883,24 +883,24 @@ discard block |
||
883 | 883 | ) |
884 | 884 | ); |
885 | 885 | } |
886 | - if( ! in_array( $selection_and_datatype[1],$this->_valid_wpdb_data_types)){ |
|
886 | + if ( ! in_array($selection_and_datatype[1], $this->_valid_wpdb_data_types)) { |
|
887 | 887 | throw new EE_Error( |
888 | 888 | sprintf( |
889 | 889 | __( |
890 | 890 | "Datatype %s (for selection '%s' and alias '%s') is not a valid wpdb datatype (eg %%s)", |
891 | 891 | "event_espresso" |
892 | 892 | ), |
893 | - $selection_and_datatype[ 1 ], |
|
894 | - $selection_and_datatype[ 0 ], |
|
893 | + $selection_and_datatype[1], |
|
894 | + $selection_and_datatype[0], |
|
895 | 895 | $alias, |
896 | - implode( ",", $this->_valid_wpdb_data_types ) |
|
896 | + implode(",", $this->_valid_wpdb_data_types) |
|
897 | 897 | ) |
898 | 898 | ); |
899 | 899 | } |
900 | 900 | $select_sql_array[] = "{$selection_and_datatype[0]} AS $alias"; |
901 | 901 | } |
902 | - $columns_to_select_string = implode(", ",$select_sql_array); |
|
903 | - }else{ |
|
902 | + $columns_to_select_string = implode(", ", $select_sql_array); |
|
903 | + } else { |
|
904 | 904 | $columns_to_select_string = $columns_to_select; |
905 | 905 | } |
906 | 906 | return $columns_to_select_string; |
@@ -915,7 +915,7 @@ discard block |
||
915 | 915 | * @return string |
916 | 916 | * @throws \EE_Error |
917 | 917 | */ |
918 | - public function primary_key_name(){ |
|
918 | + public function primary_key_name() { |
|
919 | 919 | return $this->get_primary_key_field()->get_name(); |
920 | 920 | } |
921 | 921 | |
@@ -927,14 +927,14 @@ discard block |
||
927 | 927 | * @param mixed $id int or string, depending on the type of the model's primary key |
928 | 928 | * @return EE_Base_Class |
929 | 929 | */ |
930 | - public function get_one_by_ID($id){ |
|
931 | - if( $this->get_from_entity_map( $id ) ){ |
|
932 | - return $this->get_from_entity_map( $id ); |
|
930 | + public function get_one_by_ID($id) { |
|
931 | + if ($this->get_from_entity_map($id)) { |
|
932 | + return $this->get_from_entity_map($id); |
|
933 | 933 | } |
934 | 934 | return $this->get_one( |
935 | 935 | $this->alter_query_params_to_restrict_by_ID( |
936 | 936 | $id, |
937 | - array( 'default_where_conditions' => 'minimum' ) |
|
937 | + array('default_where_conditions' => 'minimum') |
|
938 | 938 | ) |
939 | 939 | ); |
940 | 940 | } |
@@ -950,15 +950,15 @@ discard block |
||
950 | 950 | * @return array of normal query params, @see EEM_Base::get_all |
951 | 951 | * @throws \EE_Error |
952 | 952 | */ |
953 | - public function alter_query_params_to_restrict_by_ID( $id, $query_params = array() ) { |
|
954 | - if( ! isset( $query_params[ 0 ] ) ) { |
|
955 | - $query_params[ 0 ] = array(); |
|
953 | + public function alter_query_params_to_restrict_by_ID($id, $query_params = array()) { |
|
954 | + if ( ! isset($query_params[0])) { |
|
955 | + $query_params[0] = array(); |
|
956 | 956 | } |
957 | - if( $this->has_primary_key_field ( ) ) { |
|
958 | - $query_params[ 0 ][ $this->primary_key_name() ] = $id ; |
|
959 | - }else{ |
|
957 | + if ($this->has_primary_key_field( )) { |
|
958 | + $query_params[0][$this->primary_key_name()] = $id; |
|
959 | + } else { |
|
960 | 960 | //no primary key, so the $id must be from the get_index_primary_key_string() |
961 | - $query_params[0] = array_replace_recursive( $query_params[ 0 ], $this->parse_index_primary_key_string( $id ) ); |
|
961 | + $query_params[0] = array_replace_recursive($query_params[0], $this->parse_index_primary_key_string($id)); |
|
962 | 962 | } |
963 | 963 | return $query_params; |
964 | 964 | } |
@@ -973,16 +973,16 @@ discard block |
||
973 | 973 | * @return EE_Base_Class | NULL |
974 | 974 | * @throws \EE_Error |
975 | 975 | */ |
976 | - public function get_one($query_params = array()){ |
|
977 | - if( ! is_array( $query_params ) ){ |
|
978 | - EE_Error::doing_it_wrong('EEM_Base::get_one', sprintf( __( '$query_params should be an array, you passed a variable of type %s', 'event_espresso' ), gettype( $query_params ) ), '4.6.0' ); |
|
976 | + public function get_one($query_params = array()) { |
|
977 | + if ( ! is_array($query_params)) { |
|
978 | + 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'); |
|
979 | 979 | $query_params = array(); |
980 | 980 | } |
981 | 981 | $query_params['limit'] = 1; |
982 | 982 | $items = $this->get_all($query_params); |
983 | - if(empty($items)){ |
|
983 | + if (empty($items)) { |
|
984 | 984 | return null; |
985 | - }else{ |
|
985 | + } else { |
|
986 | 986 | return array_shift($items); |
987 | 987 | } |
988 | 988 | } |
@@ -1005,8 +1005,8 @@ discard block |
||
1005 | 1005 | * @return EE_Base_Class[]|array |
1006 | 1006 | * @throws \EE_Error |
1007 | 1007 | */ |
1008 | - public function next_x( $current_field_value, $field_to_order_by = null, $limit = 1, $query_params = array(), $columns_to_select = null ) { |
|
1009 | - return $this->_get_consecutive( $current_field_value, '>', $field_to_order_by, $limit, $query_params, $columns_to_select ); |
|
1008 | + public function next_x($current_field_value, $field_to_order_by = null, $limit = 1, $query_params = array(), $columns_to_select = null) { |
|
1009 | + return $this->_get_consecutive($current_field_value, '>', $field_to_order_by, $limit, $query_params, $columns_to_select); |
|
1010 | 1010 | } |
1011 | 1011 | |
1012 | 1012 | |
@@ -1027,8 +1027,8 @@ discard block |
||
1027 | 1027 | * @return EE_Base_Class[]|array |
1028 | 1028 | * @throws \EE_Error |
1029 | 1029 | */ |
1030 | - public function previous_x( $current_field_value, $field_to_order_by = null, $limit = 1, $query_params = array(), $columns_to_select = null ) { |
|
1031 | - return $this->_get_consecutive( $current_field_value, '<', $field_to_order_by, $limit, $query_params, $columns_to_select ); |
|
1030 | + public function previous_x($current_field_value, $field_to_order_by = null, $limit = 1, $query_params = array(), $columns_to_select = null) { |
|
1031 | + return $this->_get_consecutive($current_field_value, '<', $field_to_order_by, $limit, $query_params, $columns_to_select); |
|
1032 | 1032 | } |
1033 | 1033 | |
1034 | 1034 | |
@@ -1049,9 +1049,9 @@ discard block |
||
1049 | 1049 | * @return EE_Base_Class|null|array() |
1050 | 1050 | * @throws \EE_Error |
1051 | 1051 | */ |
1052 | - public function next( $current_field_value, $field_to_order_by = null, $query_params = array(), $columns_to_select = null ) { |
|
1053 | - $results = $this->_get_consecutive( $current_field_value, '>', $field_to_order_by, 1, $query_params, $columns_to_select ); |
|
1054 | - return empty( $results ) ? null : reset( $results ); |
|
1052 | + public function next($current_field_value, $field_to_order_by = null, $query_params = array(), $columns_to_select = null) { |
|
1053 | + $results = $this->_get_consecutive($current_field_value, '>', $field_to_order_by, 1, $query_params, $columns_to_select); |
|
1054 | + return empty($results) ? null : reset($results); |
|
1055 | 1055 | } |
1056 | 1056 | |
1057 | 1057 | |
@@ -1073,9 +1073,9 @@ discard block |
||
1073 | 1073 | * @return EE_Base_Class|null|array() |
1074 | 1074 | * @throws EE_Error |
1075 | 1075 | */ |
1076 | - public function previous( $current_field_value, $field_to_order_by = null, $query_params = array(), $columns_to_select = null ) { |
|
1077 | - $results = $this->_get_consecutive( $current_field_value, '<', $field_to_order_by, 1, $query_params, $columns_to_select ); |
|
1078 | - return empty( $results ) ? null : reset( $results ); |
|
1076 | + public function previous($current_field_value, $field_to_order_by = null, $query_params = array(), $columns_to_select = null) { |
|
1077 | + $results = $this->_get_consecutive($current_field_value, '<', $field_to_order_by, 1, $query_params, $columns_to_select); |
|
1078 | + return empty($results) ? null : reset($results); |
|
1079 | 1079 | } |
1080 | 1080 | |
1081 | 1081 | |
@@ -1096,42 +1096,42 @@ discard block |
||
1096 | 1096 | * @return EE_Base_Class[]|array |
1097 | 1097 | * @throws EE_Error |
1098 | 1098 | */ |
1099 | - protected function _get_consecutive( $current_field_value, $operand = '>', $field_to_order_by = null, $limit = 1, $query_params = array(), $columns_to_select = null ) { |
|
1099 | + protected function _get_consecutive($current_field_value, $operand = '>', $field_to_order_by = null, $limit = 1, $query_params = array(), $columns_to_select = null) { |
|
1100 | 1100 | //if $field_to_order_by is empty then let's assume we're ordering by the primary key. |
1101 | - if ( empty( $field_to_order_by ) ) { |
|
1102 | - if ( $this->has_primary_key_field() ) { |
|
1101 | + if (empty($field_to_order_by)) { |
|
1102 | + if ($this->has_primary_key_field()) { |
|
1103 | 1103 | $field_to_order_by = $this->get_primary_key_field()->get_name(); |
1104 | 1104 | } else { |
1105 | 1105 | |
1106 | - if ( WP_DEBUG ) { |
|
1107 | - 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' ) ); |
|
1106 | + if (WP_DEBUG) { |
|
1107 | + 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')); |
|
1108 | 1108 | } |
1109 | - EE_Error::add_error( __('There was an error with the query.', 'event_espresso') ); |
|
1109 | + EE_Error::add_error(__('There was an error with the query.', 'event_espresso')); |
|
1110 | 1110 | return array(); |
1111 | 1111 | } |
1112 | 1112 | } |
1113 | 1113 | |
1114 | - if( ! is_array( $query_params ) ){ |
|
1115 | - 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' ); |
|
1114 | + if ( ! is_array($query_params)) { |
|
1115 | + 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'); |
|
1116 | 1116 | $query_params = array(); |
1117 | 1117 | } |
1118 | 1118 | |
1119 | 1119 | //let's add the where query param for consecutive look up. |
1120 | - $query_params[0][ $field_to_order_by ] = array( $operand, $current_field_value ); |
|
1120 | + $query_params[0][$field_to_order_by] = array($operand, $current_field_value); |
|
1121 | 1121 | $query_params['limit'] = $limit; |
1122 | 1122 | |
1123 | 1123 | //set direction |
1124 | - $incoming_orderby = isset( $query_params['order_by'] ) ? (array)$query_params['order_by'] : array(); |
|
1124 | + $incoming_orderby = isset($query_params['order_by']) ? (array) $query_params['order_by'] : array(); |
|
1125 | 1125 | $query_params['order_by'] = $operand === '>' |
1126 | - ? array( $field_to_order_by => 'ASC' ) + $incoming_orderby |
|
1127 | - : array( $field_to_order_by => 'DESC') + $incoming_orderby; |
|
1126 | + ? array($field_to_order_by => 'ASC') + $incoming_orderby |
|
1127 | + : array($field_to_order_by => 'DESC') + $incoming_orderby; |
|
1128 | 1128 | |
1129 | 1129 | //if $columns_to_select is empty then that means we're returning EE_Base_Class objects |
1130 | - if ( empty( $columns_to_select ) ) { |
|
1131 | - return $this->get_all( $query_params ); |
|
1130 | + if (empty($columns_to_select)) { |
|
1131 | + return $this->get_all($query_params); |
|
1132 | 1132 | } else { |
1133 | 1133 | //getting just the fields |
1134 | - return $this->_get_all_wpdb_results( $query_params, ARRAY_A, $columns_to_select ); |
|
1134 | + return $this->_get_all_wpdb_results($query_params, ARRAY_A, $columns_to_select); |
|
1135 | 1135 | } |
1136 | 1136 | } |
1137 | 1137 | |
@@ -1142,18 +1142,18 @@ discard block |
||
1142 | 1142 | * This sets the _timezone property after model object has been instantiated. |
1143 | 1143 | * @param null | string $timezone valid PHP DateTimeZone timezone string |
1144 | 1144 | */ |
1145 | - public function set_timezone( $timezone ) { |
|
1146 | - if ( $timezone !== null ) { |
|
1145 | + public function set_timezone($timezone) { |
|
1146 | + if ($timezone !== null) { |
|
1147 | 1147 | $this->_timezone = $timezone; |
1148 | 1148 | } |
1149 | 1149 | //note we need to loop through relations and set the timezone on those objects as well. |
1150 | - foreach ( $this->_model_relations as $relation ) { |
|
1151 | - $relation->set_timezone( $timezone ); |
|
1150 | + foreach ($this->_model_relations as $relation) { |
|
1151 | + $relation->set_timezone($timezone); |
|
1152 | 1152 | } |
1153 | 1153 | //and finally we do the same for any datetime fields |
1154 | - foreach ( $this->_fields as $field ) { |
|
1155 | - if ( $field instanceof EE_Datetime_Field ) { |
|
1156 | - $field->set_timezone( $timezone ); |
|
1154 | + foreach ($this->_fields as $field) { |
|
1155 | + if ($field instanceof EE_Datetime_Field) { |
|
1156 | + $field->set_timezone($timezone); |
|
1157 | 1157 | } |
1158 | 1158 | } |
1159 | 1159 | } |
@@ -1168,9 +1168,9 @@ discard block |
||
1168 | 1168 | */ |
1169 | 1169 | public function get_timezone() { |
1170 | 1170 | //first validate if timezone is set. If not, then let's set it be whatever is set on the model fields. |
1171 | - if ( empty( $this->_timezone ) ) { |
|
1172 | - foreach( $this->_fields as $field ) { |
|
1173 | - if ( $field instanceof EE_Datetime_Field ) { |
|
1171 | + if (empty($this->_timezone)) { |
|
1172 | + foreach ($this->_fields as $field) { |
|
1173 | + if ($field instanceof EE_Datetime_Field) { |
|
1174 | 1174 | $this->set_timezone($field->get_timezone()); |
1175 | 1175 | break; |
1176 | 1176 | } |
@@ -1178,9 +1178,9 @@ discard block |
||
1178 | 1178 | } |
1179 | 1179 | |
1180 | 1180 | //if timezone STILL empty then return the default timezone for the site. |
1181 | - if ( empty( $this->_timezone ) ) { |
|
1182 | - EE_Registry::instance()->load_helper( 'DTT_Helper' ); |
|
1183 | - $this->set_timezone( EEH_DTT_Helper::get_timezone() ); |
|
1181 | + if (empty($this->_timezone)) { |
|
1182 | + EE_Registry::instance()->load_helper('DTT_Helper'); |
|
1183 | + $this->set_timezone(EEH_DTT_Helper::get_timezone()); |
|
1184 | 1184 | } |
1185 | 1185 | return $this->_timezone; |
1186 | 1186 | } |
@@ -1198,19 +1198,19 @@ discard block |
||
1198 | 1198 | * |
1199 | 1199 | * @return array formats in an array with the date format first, and the time format last. |
1200 | 1200 | */ |
1201 | - public function get_formats_for( $field_name, $pretty = false ) { |
|
1202 | - $field_settings = $this->field_settings_for( $field_name ); |
|
1201 | + public function get_formats_for($field_name, $pretty = false) { |
|
1202 | + $field_settings = $this->field_settings_for($field_name); |
|
1203 | 1203 | |
1204 | 1204 | //if not a valid EE_Datetime_Field then throw error |
1205 | - if ( ! $field_settings instanceof EE_Datetime_Field ) { |
|
1206 | - 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 ) ); |
|
1205 | + if ( ! $field_settings instanceof EE_Datetime_Field) { |
|
1206 | + 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)); |
|
1207 | 1207 | } |
1208 | 1208 | |
1209 | 1209 | //while we are here, let's make sure the timezone internally in EEM_Base matches what is stored on |
1210 | 1210 | //the field. |
1211 | 1211 | $this->_timezone = $field_settings->get_timezone(); |
1212 | 1212 | |
1213 | - return array( $field_settings->get_date_format( $pretty ), $field_settings->get_time_format( $pretty ) ); |
|
1213 | + return array($field_settings->get_date_format($pretty), $field_settings->get_time_format($pretty)); |
|
1214 | 1214 | } |
1215 | 1215 | |
1216 | 1216 | |
@@ -1234,25 +1234,25 @@ discard block |
||
1234 | 1234 | * @return int|string If the given field_name is not of the EE_Datetime_Field type, then an EE_Error |
1235 | 1235 | * exception is triggered. |
1236 | 1236 | */ |
1237 | - public function current_time_for_query( $field_name, $timestamp = false, $what = 'both' ) { |
|
1238 | - $formats = $this->get_formats_for( $field_name ); |
|
1237 | + public function current_time_for_query($field_name, $timestamp = false, $what = 'both') { |
|
1238 | + $formats = $this->get_formats_for($field_name); |
|
1239 | 1239 | |
1240 | - $DateTime = new DateTime( "now", new DateTimeZone( $this->_timezone ) ); |
|
1240 | + $DateTime = new DateTime("now", new DateTimeZone($this->_timezone)); |
|
1241 | 1241 | |
1242 | - if ( $timestamp ) { |
|
1243 | - return $DateTime->format( 'U' ); |
|
1242 | + if ($timestamp) { |
|
1243 | + return $DateTime->format('U'); |
|
1244 | 1244 | } |
1245 | 1245 | |
1246 | 1246 | //not returning timestamp, so return formatted string in timezone. |
1247 | - switch( $what ) { |
|
1247 | + switch ($what) { |
|
1248 | 1248 | case 'time' : |
1249 | - return $DateTime->format( $formats[1] ); |
|
1249 | + return $DateTime->format($formats[1]); |
|
1250 | 1250 | break; |
1251 | 1251 | case 'date' : |
1252 | - return $DateTime->format( $formats[0] ); |
|
1252 | + return $DateTime->format($formats[0]); |
|
1253 | 1253 | break; |
1254 | 1254 | default : |
1255 | - return $DateTime->format( implode( ' ', $formats ) ); |
|
1255 | + return $DateTime->format(implode(' ', $formats)); |
|
1256 | 1256 | break; |
1257 | 1257 | } |
1258 | 1258 | } |
@@ -1274,18 +1274,18 @@ discard block |
||
1274 | 1274 | * @return DateTime |
1275 | 1275 | * @throws \EE_Error |
1276 | 1276 | */ |
1277 | - public function convert_datetime_for_query( $field_name, $timestring, $incoming_format, $timezone = '' ) { |
|
1277 | + public function convert_datetime_for_query($field_name, $timestring, $incoming_format, $timezone = '') { |
|
1278 | 1278 | |
1279 | 1279 | //just using this to ensure the timezone is set correctly internally |
1280 | - $this->get_formats_for( $field_name ); |
|
1280 | + $this->get_formats_for($field_name); |
|
1281 | 1281 | |
1282 | 1282 | //load EEH_DTT_Helper |
1283 | - EE_Registry::instance()->load_helper( 'DTT_Helper' ); |
|
1284 | - $set_timezone = empty( $timezone ) ? EEH_DTT_Helper::get_timezone() : $timezone; |
|
1283 | + EE_Registry::instance()->load_helper('DTT_Helper'); |
|
1284 | + $set_timezone = empty($timezone) ? EEH_DTT_Helper::get_timezone() : $timezone; |
|
1285 | 1285 | |
1286 | - $incomingDateTime = date_create_from_format( $incoming_format, $timestring, new DateTimeZone( $set_timezone ) ); |
|
1286 | + $incomingDateTime = date_create_from_format($incoming_format, $timestring, new DateTimeZone($set_timezone)); |
|
1287 | 1287 | |
1288 | - return $incomingDateTime->setTimezone( new DateTimeZone( $this->_timezone ) ); |
|
1288 | + return $incomingDateTime->setTimezone(new DateTimeZone($this->_timezone)); |
|
1289 | 1289 | } |
1290 | 1290 | |
1291 | 1291 | |
@@ -1295,7 +1295,7 @@ discard block |
||
1295 | 1295 | * Gets all the tables comprising this model. Array keys are the table aliases, and values are EE_Table objects |
1296 | 1296 | * @return EE_Table_Base[] |
1297 | 1297 | */ |
1298 | - public function get_tables(){ |
|
1298 | + public function get_tables() { |
|
1299 | 1299 | return $this->_tables; |
1300 | 1300 | } |
1301 | 1301 | |
@@ -1331,9 +1331,9 @@ discard block |
||
1331 | 1331 | * @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) |
1332 | 1332 | * @throws \EE_Error |
1333 | 1333 | */ |
1334 | - public function update($fields_n_values, $query_params, $keep_model_objs_in_sync = TRUE){ |
|
1335 | - if( ! is_array( $query_params ) ){ |
|
1336 | - 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' ); |
|
1334 | + public function update($fields_n_values, $query_params, $keep_model_objs_in_sync = TRUE) { |
|
1335 | + if ( ! is_array($query_params)) { |
|
1336 | + 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'); |
|
1337 | 1337 | $query_params = array(); |
1338 | 1338 | } |
1339 | 1339 | /** |
@@ -1343,7 +1343,7 @@ discard block |
||
1343 | 1343 | * @param array $fields_n_values the updated fields and their new values |
1344 | 1344 | * @param array $query_params @see EEM_Base::get_all() |
1345 | 1345 | */ |
1346 | - do_action( 'AHEE__EEM_Base__update__begin',$this, $fields_n_values, $query_params ); |
|
1346 | + do_action('AHEE__EEM_Base__update__begin', $this, $fields_n_values, $query_params); |
|
1347 | 1347 | /** |
1348 | 1348 | * Filters the fields about to be updated given the query parameters. You can provide the |
1349 | 1349 | * $query_params to $this->get_all() to find exactly which records will be updated |
@@ -1351,10 +1351,10 @@ discard block |
||
1351 | 1351 | * @param EEM_Base $model the model being queried |
1352 | 1352 | * @param array $query_params see EEM_Base::get_all() |
1353 | 1353 | */ |
1354 | - $fields_n_values = (array)apply_filters( 'FHEE__EEM_Base__update__fields_n_values', $fields_n_values, $this, $query_params ); |
|
1354 | + $fields_n_values = (array) apply_filters('FHEE__EEM_Base__update__fields_n_values', $fields_n_values, $this, $query_params); |
|
1355 | 1355 | //need to verify that, for any entry we want to update, there are entries in each secondary table. |
1356 | 1356 | //to do that, for each table, verify that it's PK isn't null. |
1357 | - $tables= $this->get_tables(); |
|
1357 | + $tables = $this->get_tables(); |
|
1358 | 1358 | |
1359 | 1359 | //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 |
1360 | 1360 | //NOTE: we should make this code more efficient by NOT querying twice |
@@ -1364,29 +1364,29 @@ discard block |
||
1364 | 1364 | //we want to make sure the default_where strategy is ignored |
1365 | 1365 | $this->_ignore_where_strategy = TRUE; |
1366 | 1366 | $wpdb_select_results = $this->_get_all_wpdb_results($query_params); |
1367 | - foreach( $wpdb_select_results as $wpdb_result ){ |
|
1367 | + foreach ($wpdb_select_results as $wpdb_result) { |
|
1368 | 1368 | // type cast stdClass as array |
1369 | - $wpdb_result = (array)$wpdb_result; |
|
1369 | + $wpdb_result = (array) $wpdb_result; |
|
1370 | 1370 | //get the model object's PK, as we'll want this if we need to insert a row into secondary tables |
1371 | - if( $this->has_primary_key_field() ){ |
|
1372 | - $main_table_pk_value = $wpdb_result[ $this->get_primary_key_field()->get_qualified_column() ]; |
|
1373 | - }else{ |
|
1371 | + if ($this->has_primary_key_field()) { |
|
1372 | + $main_table_pk_value = $wpdb_result[$this->get_primary_key_field()->get_qualified_column()]; |
|
1373 | + } else { |
|
1374 | 1374 | //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) |
1375 | 1375 | $main_table_pk_value = null; |
1376 | 1376 | } |
1377 | 1377 | //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 |
1378 | 1378 | //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 |
1379 | - if(count($tables) > 1){ |
|
1379 | + if (count($tables) > 1) { |
|
1380 | 1380 | //foreach matching row in the DB, ensure that each table's PK isn't null. If so, there must not be an entry |
1381 | 1381 | //in that table, and so we'll want to insert one |
1382 | - foreach($tables as $table_obj){ |
|
1382 | + foreach ($tables as $table_obj) { |
|
1383 | 1383 | $this_table_pk_column = $table_obj->get_fully_qualified_pk_column(); |
1384 | 1384 | //if there is no private key for this table on the results, it means there's no entry |
1385 | 1385 | //in this table, right? so insert a row in the current table, using any fields available |
1386 | - if( ! ( array_key_exists( $this_table_pk_column, $wpdb_result) && $wpdb_result[ $this_table_pk_column ] )){ |
|
1386 | + if ( ! (array_key_exists($this_table_pk_column, $wpdb_result) && $wpdb_result[$this_table_pk_column])) { |
|
1387 | 1387 | $success = $this->_insert_into_specific_table($table_obj, $fields_n_values, $main_table_pk_value); |
1388 | 1388 | //if we died here, report the error |
1389 | - if( ! $success ) { |
|
1389 | + if ( ! $success) { |
|
1390 | 1390 | return false; |
1391 | 1391 | } |
1392 | 1392 | } |
@@ -1406,44 +1406,44 @@ discard block |
||
1406 | 1406 | //if this wasn't called from a model object (to update itself) |
1407 | 1407 | //then we want to make sure we keep all the existing |
1408 | 1408 | //model objects in sync with the db |
1409 | - if( $keep_model_objs_in_sync && ! $this->_values_already_prepared_by_model_object ){ |
|
1410 | - if( $this->has_primary_key_field() ){ |
|
1411 | - $model_objs_affected_ids = $this->get_col( $query_params ); |
|
1412 | - }else{ |
|
1409 | + if ($keep_model_objs_in_sync && ! $this->_values_already_prepared_by_model_object) { |
|
1410 | + if ($this->has_primary_key_field()) { |
|
1411 | + $model_objs_affected_ids = $this->get_col($query_params); |
|
1412 | + } else { |
|
1413 | 1413 | //we need to select a bunch of columns and then combine them into the the "index primary key string"s |
1414 | - $models_affected_key_columns = $this->_get_all_wpdb_results($query_params, ARRAY_A ); |
|
1414 | + $models_affected_key_columns = $this->_get_all_wpdb_results($query_params, ARRAY_A); |
|
1415 | 1415 | $model_objs_affected_ids = array(); |
1416 | - foreach( $models_affected_key_columns as $row ){ |
|
1417 | - $combined_index_key = $this->get_index_primary_key_string( $row ); |
|
1418 | - $model_objs_affected_ids[ $combined_index_key ] = $combined_index_key; |
|
1416 | + foreach ($models_affected_key_columns as $row) { |
|
1417 | + $combined_index_key = $this->get_index_primary_key_string($row); |
|
1418 | + $model_objs_affected_ids[$combined_index_key] = $combined_index_key; |
|
1419 | 1419 | } |
1420 | 1420 | |
1421 | 1421 | } |
1422 | 1422 | |
1423 | - if( ! $model_objs_affected_ids ){ |
|
1423 | + if ( ! $model_objs_affected_ids) { |
|
1424 | 1424 | //wait wait wait- if nothing was affected let's stop here |
1425 | 1425 | return 0; |
1426 | 1426 | } |
1427 | - foreach( $model_objs_affected_ids as $id ){ |
|
1428 | - $model_obj_in_entity_map = $this->get_from_entity_map( $id ); |
|
1429 | - if( $model_obj_in_entity_map ){ |
|
1430 | - foreach( $fields_n_values as $field => $new_value ){ |
|
1431 | - $model_obj_in_entity_map->set( $field, $new_value ); |
|
1427 | + foreach ($model_objs_affected_ids as $id) { |
|
1428 | + $model_obj_in_entity_map = $this->get_from_entity_map($id); |
|
1429 | + if ($model_obj_in_entity_map) { |
|
1430 | + foreach ($fields_n_values as $field => $new_value) { |
|
1431 | + $model_obj_in_entity_map->set($field, $new_value); |
|
1432 | 1432 | } |
1433 | 1433 | } |
1434 | 1434 | } |
1435 | 1435 | //if there is a primary key on this model, we can now do a slight optimization |
1436 | - if( $this->has_primary_key_field() ){ |
|
1436 | + if ($this->has_primary_key_field()) { |
|
1437 | 1437 | //we already know what we want to update. So let's make the query simpler so it's a little more efficient |
1438 | 1438 | $query_params = array( |
1439 | - array( $this->primary_key_name() => array( 'IN', $model_objs_affected_ids ) ), |
|
1440 | - 'limit' => count( $model_objs_affected_ids ), 'default_where_conditions' => 'none' ); |
|
1439 | + array($this->primary_key_name() => array('IN', $model_objs_affected_ids)), |
|
1440 | + 'limit' => count($model_objs_affected_ids), 'default_where_conditions' => 'none' ); |
|
1441 | 1441 | } |
1442 | 1442 | } |
1443 | 1443 | |
1444 | - $model_query_info = $this->_create_model_query_info_carrier( $query_params ); |
|
1445 | - $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. |
|
1446 | - $rows_affected = $this->_do_wpdb_query('query', array( $SQL ) ); |
|
1444 | + $model_query_info = $this->_create_model_query_info_carrier($query_params); |
|
1445 | + $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. |
|
1446 | + $rows_affected = $this->_do_wpdb_query('query', array($SQL)); |
|
1447 | 1447 | /** |
1448 | 1448 | * Action called after a model update call has been made. |
1449 | 1449 | * |
@@ -1452,8 +1452,8 @@ discard block |
||
1452 | 1452 | * @param array $query_params @see EEM_Base::get_all() |
1453 | 1453 | * @param int $rows_affected |
1454 | 1454 | */ |
1455 | - do_action( 'AHEE__EEM_Base__update__end',$this, $fields_n_values, $query_params, $rows_affected ); |
|
1456 | - return $rows_affected;//how many supposedly got updated |
|
1455 | + do_action('AHEE__EEM_Base__update__end', $this, $fields_n_values, $query_params, $rows_affected); |
|
1456 | + return $rows_affected; //how many supposedly got updated |
|
1457 | 1457 | } |
1458 | 1458 | |
1459 | 1459 | |
@@ -1469,22 +1469,22 @@ discard block |
||
1469 | 1469 | * @return array just like $wpdb->get_col() |
1470 | 1470 | * @throws \EE_Error |
1471 | 1471 | */ |
1472 | - public function get_col( $query_params = array(), $field_to_select = NULL ){ |
|
1472 | + public function get_col($query_params = array(), $field_to_select = NULL) { |
|
1473 | 1473 | |
1474 | - if( $field_to_select ){ |
|
1475 | - $field = $this->field_settings_for( $field_to_select ); |
|
1476 | - }elseif( $this->has_primary_key_field ( ) ){ |
|
1474 | + if ($field_to_select) { |
|
1475 | + $field = $this->field_settings_for($field_to_select); |
|
1476 | + }elseif ($this->has_primary_key_field( )) { |
|
1477 | 1477 | $field = $this->get_primary_key_field(); |
1478 | - }else{ |
|
1478 | + } else { |
|
1479 | 1479 | //no primary key, just grab the first column |
1480 | - $field = reset( $this->field_settings()); |
|
1480 | + $field = reset($this->field_settings()); |
|
1481 | 1481 | } |
1482 | 1482 | |
1483 | 1483 | |
1484 | 1484 | $model_query_info = $this->_create_model_query_info_carrier($query_params); |
1485 | 1485 | $select_expressions = $field->get_qualified_column(); |
1486 | - $SQL ="SELECT $select_expressions ".$this->_construct_2nd_half_of_select_query($model_query_info); |
|
1487 | - return $this->_do_wpdb_query('get_col', array( $SQL ) ); |
|
1486 | + $SQL = "SELECT $select_expressions ".$this->_construct_2nd_half_of_select_query($model_query_info); |
|
1487 | + return $this->_do_wpdb_query('get_col', array($SQL)); |
|
1488 | 1488 | } |
1489 | 1489 | |
1490 | 1490 | |
@@ -1497,12 +1497,12 @@ discard block |
||
1497 | 1497 | * @return string |
1498 | 1498 | * @throws \EE_Error |
1499 | 1499 | */ |
1500 | - public function get_var( $query_params = array(), $field_to_select = NULL ) { |
|
1501 | - $query_params[ 'limit' ] = 1; |
|
1502 | - $col = $this->get_col( $query_params, $field_to_select ); |
|
1503 | - if( ! empty( $col ) ) { |
|
1504 | - return reset( $col ); |
|
1505 | - }else{ |
|
1500 | + public function get_var($query_params = array(), $field_to_select = NULL) { |
|
1501 | + $query_params['limit'] = 1; |
|
1502 | + $col = $this->get_col($query_params, $field_to_select); |
|
1503 | + if ( ! empty($col)) { |
|
1504 | + return reset($col); |
|
1505 | + } else { |
|
1506 | 1506 | return NULL; |
1507 | 1507 | } |
1508 | 1508 | } |
@@ -1518,19 +1518,19 @@ discard block |
||
1518 | 1518 | * @return string of SQL |
1519 | 1519 | * @throws \EE_Error |
1520 | 1520 | */ |
1521 | - public function _construct_update_sql($fields_n_values){ |
|
1521 | + public function _construct_update_sql($fields_n_values) { |
|
1522 | 1522 | /** @type WPDB $wpdb */ |
1523 | 1523 | global $wpdb; |
1524 | 1524 | $cols_n_values = array(); |
1525 | - foreach($fields_n_values as $field_name => $value){ |
|
1525 | + foreach ($fields_n_values as $field_name => $value) { |
|
1526 | 1526 | $field_obj = $this->field_settings_for($field_name); |
1527 | 1527 | //if the value is NULL, we want to assign the value to that. |
1528 | 1528 | //wpdb->prepare doesn't really handle that properly |
1529 | - $prepared_value = $this->_prepare_value_or_use_default( $field_obj, $fields_n_values ); |
|
1530 | - $value_sql = $prepared_value===NULL ? 'NULL' : $wpdb->prepare( $field_obj->get_wpdb_data_type(), $prepared_value ); |
|
1529 | + $prepared_value = $this->_prepare_value_or_use_default($field_obj, $fields_n_values); |
|
1530 | + $value_sql = $prepared_value === NULL ? 'NULL' : $wpdb->prepare($field_obj->get_wpdb_data_type(), $prepared_value); |
|
1531 | 1531 | $cols_n_values[] = $field_obj->get_qualified_column()."=".$value_sql; |
1532 | 1532 | } |
1533 | - return implode(",",$cols_n_values); |
|
1533 | + return implode(",", $cols_n_values); |
|
1534 | 1534 | |
1535 | 1535 | } |
1536 | 1536 | |
@@ -1546,10 +1546,10 @@ discard block |
||
1546 | 1546 | * @return boolean whether the row got deleted or not |
1547 | 1547 | * @throws \EE_Error |
1548 | 1548 | */ |
1549 | - public function delete_permanently_by_ID( $id ) { |
|
1549 | + public function delete_permanently_by_ID($id) { |
|
1550 | 1550 | return $this->delete_permanently( |
1551 | 1551 | array( |
1552 | - array( $this->get_primary_key_field()->get_name() => $id ), |
|
1552 | + array($this->get_primary_key_field()->get_name() => $id), |
|
1553 | 1553 | 'limit' => 1 |
1554 | 1554 | ) |
1555 | 1555 | ); |
@@ -1565,10 +1565,10 @@ discard block |
||
1565 | 1565 | * @return boolean whether the row got deleted or not |
1566 | 1566 | * @throws \EE_Error |
1567 | 1567 | */ |
1568 | - public function delete_by_ID( $id ){ |
|
1568 | + public function delete_by_ID($id) { |
|
1569 | 1569 | return $this->delete( |
1570 | 1570 | array( |
1571 | - array( $this->get_primary_key_field()->get_name() => $id ), |
|
1571 | + array($this->get_primary_key_field()->get_name() => $id), |
|
1572 | 1572 | 'limit' => 1 |
1573 | 1573 | ) |
1574 | 1574 | ); |
@@ -1587,7 +1587,7 @@ discard block |
||
1587 | 1587 | * @return int how many rows got deleted |
1588 | 1588 | * @throws \EE_Error |
1589 | 1589 | */ |
1590 | - public function delete($query_params,$allow_blocking = true){ |
|
1590 | + public function delete($query_params, $allow_blocking = true) { |
|
1591 | 1591 | return $this->delete_permanently($query_params, $allow_blocking); |
1592 | 1592 | } |
1593 | 1593 | |
@@ -1605,7 +1605,7 @@ discard block |
||
1605 | 1605 | * @return int how many rows got deleted |
1606 | 1606 | * @throws \EE_Error |
1607 | 1607 | */ |
1608 | - public function delete_permanently($query_params,$allow_blocking = true){ |
|
1608 | + public function delete_permanently($query_params, $allow_blocking = true) { |
|
1609 | 1609 | /** |
1610 | 1610 | * Action called just before performing a real deletion query. You can use the |
1611 | 1611 | * model and its $query_params to find exactly which items will be deleted |
@@ -1614,31 +1614,31 @@ discard block |
||
1614 | 1614 | * @param boolean $allow_blocking whether or not to allow related model objects |
1615 | 1615 | * to block (prevent) this deletion |
1616 | 1616 | */ |
1617 | - do_action( 'AHEE__EEM_Base__delete__begin', $this, $query_params, $allow_blocking ); |
|
1617 | + do_action('AHEE__EEM_Base__delete__begin', $this, $query_params, $allow_blocking); |
|
1618 | 1618 | //some MySQL databases may be running safe mode, which may restrict |
1619 | 1619 | //deletion if there is no KEY column used in the WHERE statement of a deletion. |
1620 | 1620 | //to get around this, we first do a SELECT, get all the IDs, and then run another query |
1621 | 1621 | //to delete them |
1622 | 1622 | $items_for_deletion = $this->_get_all_wpdb_results($query_params); |
1623 | - $deletion_where = $this->_setup_ids_for_delete( $items_for_deletion, $allow_blocking); |
|
1624 | - if($deletion_where){ |
|
1623 | + $deletion_where = $this->_setup_ids_for_delete($items_for_deletion, $allow_blocking); |
|
1624 | + if ($deletion_where) { |
|
1625 | 1625 | //echo "objects for deletion:";var_dump($objects_for_deletion); |
1626 | 1626 | $model_query_info = $this->_create_model_query_info_carrier($query_params); |
1627 | - $table_aliases = array_keys( $this->_tables ); |
|
1628 | - $SQL = "DELETE ".implode(", ",$table_aliases)." FROM ".$model_query_info->get_full_join_sql()." WHERE ".$deletion_where; |
|
1627 | + $table_aliases = array_keys($this->_tables); |
|
1628 | + $SQL = "DELETE ".implode(", ", $table_aliases)." FROM ".$model_query_info->get_full_join_sql()." WHERE ".$deletion_where; |
|
1629 | 1629 | |
1630 | 1630 | // /echo "delete sql:$SQL"; |
1631 | - $rows_deleted = $this->_do_wpdb_query( 'query', array( $SQL ) ); |
|
1632 | - }else{ |
|
1631 | + $rows_deleted = $this->_do_wpdb_query('query', array($SQL)); |
|
1632 | + } else { |
|
1633 | 1633 | $rows_deleted = 0; |
1634 | 1634 | } |
1635 | 1635 | |
1636 | 1636 | //and lastly make sure those items are removed from the entity map; if they could be put into it at all |
1637 | - if( $this->has_primary_key_field() ){ |
|
1638 | - foreach($items_for_deletion as $item_for_deletion_row ){ |
|
1639 | - $pk_value = $item_for_deletion_row[ $this->get_primary_key_field()->get_qualified_column() ]; |
|
1640 | - if( isset( $this->_entity_map[ $pk_value ] ) ){ |
|
1641 | - unset( $this->_entity_map[ $pk_value ] ); |
|
1637 | + if ($this->has_primary_key_field()) { |
|
1638 | + foreach ($items_for_deletion as $item_for_deletion_row) { |
|
1639 | + $pk_value = $item_for_deletion_row[$this->get_primary_key_field()->get_qualified_column()]; |
|
1640 | + if (isset($this->_entity_map[$pk_value])) { |
|
1641 | + unset($this->_entity_map[$pk_value]); |
|
1642 | 1642 | } |
1643 | 1643 | } |
1644 | 1644 | } |
@@ -1650,8 +1650,8 @@ discard block |
||
1650 | 1650 | * @param array $query_params @see EEM_Base::get_all() |
1651 | 1651 | * @param int $rows_deleted |
1652 | 1652 | */ |
1653 | - do_action( 'AHEE__EEM_Base__delete__end', $this, $query_params, $rows_deleted ); |
|
1654 | - return $rows_deleted;//how many supposedly got deleted |
|
1653 | + do_action('AHEE__EEM_Base__delete__end', $this, $query_params, $rows_deleted); |
|
1654 | + return $rows_deleted; //how many supposedly got deleted |
|
1655 | 1655 | } |
1656 | 1656 | |
1657 | 1657 | |
@@ -1669,28 +1669,28 @@ discard block |
||
1669 | 1669 | * @return boolean |
1670 | 1670 | * @throws \EE_Error |
1671 | 1671 | */ |
1672 | - public function delete_is_blocked_by_related_models($this_model_obj_or_id, $ignore_this_model_obj = null){ |
|
1672 | + public function delete_is_blocked_by_related_models($this_model_obj_or_id, $ignore_this_model_obj = null) { |
|
1673 | 1673 | //first, if $ignore_this_model_obj was supplied, get its model |
1674 | - if($ignore_this_model_obj && $ignore_this_model_obj instanceof EE_Base_Class){ |
|
1674 | + if ($ignore_this_model_obj && $ignore_this_model_obj instanceof EE_Base_Class) { |
|
1675 | 1675 | $ignored_model = $ignore_this_model_obj->get_model(); |
1676 | - }else{ |
|
1676 | + } else { |
|
1677 | 1677 | $ignored_model = null; |
1678 | 1678 | } |
1679 | 1679 | //now check all the relations of $this_model_obj_or_id and see if there |
1680 | 1680 | //are any related model objects blocking it? |
1681 | 1681 | $is_blocked = false; |
1682 | - foreach($this->_model_relations as $relation_name => $relation_obj){ |
|
1683 | - if( $relation_obj->block_delete_if_related_models_exist()){ |
|
1682 | + foreach ($this->_model_relations as $relation_name => $relation_obj) { |
|
1683 | + if ($relation_obj->block_delete_if_related_models_exist()) { |
|
1684 | 1684 | //if $ignore_this_model_obj was supplied, then for the query |
1685 | 1685 | //on that model needs to be told to ignore $ignore_this_model_obj |
1686 | - if($ignored_model && $relation_name === $ignored_model->get_this_model_name()){ |
|
1687 | - $related_model_objects = $relation_obj->get_all_related($this_model_obj_or_id,array( |
|
1688 | - array($ignored_model->get_primary_key_field()->get_name() => array('!=',$ignore_this_model_obj->ID())))); |
|
1689 | - }else{ |
|
1686 | + if ($ignored_model && $relation_name === $ignored_model->get_this_model_name()) { |
|
1687 | + $related_model_objects = $relation_obj->get_all_related($this_model_obj_or_id, array( |
|
1688 | + array($ignored_model->get_primary_key_field()->get_name() => array('!=', $ignore_this_model_obj->ID())))); |
|
1689 | + } else { |
|
1690 | 1690 | $related_model_objects = $relation_obj->get_all_related($this_model_obj_or_id); |
1691 | 1691 | } |
1692 | 1692 | |
1693 | - if($related_model_objects){ |
|
1693 | + if ($related_model_objects) { |
|
1694 | 1694 | EE_Error::add_error($relation_obj->get_deletion_error_message(), __FILE__, __FUNCTION__, __LINE__); |
1695 | 1695 | $is_blocked = true; |
1696 | 1696 | } |
@@ -1710,71 +1710,71 @@ discard block |
||
1710 | 1710 | * @throws EE_Error |
1711 | 1711 | * @return string everything that comes after the WHERE statement. |
1712 | 1712 | */ |
1713 | - protected function _setup_ids_for_delete( $objects_for_deletion, $allow_blocking = true) { |
|
1714 | - if($this->has_primary_key_field()){ |
|
1713 | + protected function _setup_ids_for_delete($objects_for_deletion, $allow_blocking = true) { |
|
1714 | + if ($this->has_primary_key_field()) { |
|
1715 | 1715 | $primary_table = $this->_get_main_table(); |
1716 | 1716 | $other_tables = $this->_get_other_tables(); |
1717 | 1717 | $deletes = $query = array(); |
1718 | - foreach ( $objects_for_deletion as $delete_object ) { |
|
1718 | + foreach ($objects_for_deletion as $delete_object) { |
|
1719 | 1719 | //before we mark this object for deletion, |
1720 | 1720 | //make sure there's no related objects blocking its deletion (if we're checking) |
1721 | 1721 | if ( |
1722 | 1722 | $allow_blocking |
1723 | 1723 | && $this->delete_is_blocked_by_related_models( |
1724 | - $delete_object[ $primary_table->get_fully_qualified_pk_column() ] |
|
1724 | + $delete_object[$primary_table->get_fully_qualified_pk_column()] |
|
1725 | 1725 | ) |
1726 | 1726 | ) { |
1727 | 1727 | continue; |
1728 | 1728 | } |
1729 | 1729 | //primary table deletes |
1730 | - if ( isset( $delete_object[ $primary_table->get_fully_qualified_pk_column() ] ) ) { |
|
1731 | - $deletes[ $primary_table->get_fully_qualified_pk_column() ][] = $delete_object[ $primary_table->get_fully_qualified_pk_column() ]; |
|
1730 | + if (isset($delete_object[$primary_table->get_fully_qualified_pk_column()])) { |
|
1731 | + $deletes[$primary_table->get_fully_qualified_pk_column()][] = $delete_object[$primary_table->get_fully_qualified_pk_column()]; |
|
1732 | 1732 | } |
1733 | 1733 | //other tables |
1734 | - if ( ! empty( $other_tables ) ) { |
|
1735 | - foreach ( $other_tables as $ot ) { |
|
1734 | + if ( ! empty($other_tables)) { |
|
1735 | + foreach ($other_tables as $ot) { |
|
1736 | 1736 | //first check if we've got the foreign key column here. |
1737 | - if ( isset( $delete_object[ $ot->get_fully_qualified_fk_column() ] ) ) { |
|
1738 | - $deletes[ $ot->get_fully_qualified_pk_column() ][] = $delete_object[ $ot->get_fully_qualified_fk_column() ]; |
|
1737 | + if (isset($delete_object[$ot->get_fully_qualified_fk_column()])) { |
|
1738 | + $deletes[$ot->get_fully_qualified_pk_column()][] = $delete_object[$ot->get_fully_qualified_fk_column()]; |
|
1739 | 1739 | } |
1740 | 1740 | // wait! it's entirely possible that we'll have a the primary key |
1741 | 1741 | // for this table in here, if it's a foreign key for one of the other secondary tables |
1742 | - if ( isset( $delete_object[ $ot->get_fully_qualified_pk_column() ] ) ) { |
|
1743 | - $deletes[ $ot->get_fully_qualified_pk_column() ][] = $delete_object[ $ot->get_fully_qualified_pk_column() ]; |
|
1742 | + if (isset($delete_object[$ot->get_fully_qualified_pk_column()])) { |
|
1743 | + $deletes[$ot->get_fully_qualified_pk_column()][] = $delete_object[$ot->get_fully_qualified_pk_column()]; |
|
1744 | 1744 | } |
1745 | 1745 | // finally, it is possible that the fk for this table is found |
1746 | 1746 | // in the fully qualified pk column for the fk table, so let's see if that's there! |
1747 | - if ( isset( $delete_object[ $ot->get_fully_qualified_pk_on_fk_table() ] ) ) { |
|
1748 | - $deletes[ $ot->get_fully_qualified_pk_column() ][] = $delete_object[ $ot->get_fully_qualified_pk_column() ]; |
|
1747 | + if (isset($delete_object[$ot->get_fully_qualified_pk_on_fk_table()])) { |
|
1748 | + $deletes[$ot->get_fully_qualified_pk_column()][] = $delete_object[$ot->get_fully_qualified_pk_column()]; |
|
1749 | 1749 | } |
1750 | 1750 | } |
1751 | 1751 | } |
1752 | 1752 | } |
1753 | 1753 | |
1754 | 1754 | //we should have deletes now, so let's just go through and setup the where statement |
1755 | - foreach ( $deletes as $column => $values ) { |
|
1755 | + foreach ($deletes as $column => $values) { |
|
1756 | 1756 | //make sure we have unique $values; |
1757 | 1757 | $values = array_unique($values); |
1758 | - $query[] = $column . ' IN(' . implode(",",$values) . ')'; |
|
1758 | + $query[] = $column.' IN('.implode(",", $values).')'; |
|
1759 | 1759 | } |
1760 | 1760 | |
1761 | - return !empty($query) ? implode(' AND ', $query ) : ''; |
|
1762 | - }elseif(count($this->get_combined_primary_key_fields()) > 1){ |
|
1761 | + return ! empty($query) ? implode(' AND ', $query) : ''; |
|
1762 | + }elseif (count($this->get_combined_primary_key_fields()) > 1) { |
|
1763 | 1763 | $ways_to_identify_a_row = array(); |
1764 | 1764 | $fields = $this->get_combined_primary_key_fields(); |
1765 | 1765 | //note: because there' sno primary key, that means nothing else can be pointing to this model, right? |
1766 | - foreach($objects_for_deletion as $delete_object){ |
|
1766 | + foreach ($objects_for_deletion as $delete_object) { |
|
1767 | 1767 | $values_for_each_cpk_for_a_row = array(); |
1768 | - foreach($fields as $cpk_field){ |
|
1768 | + foreach ($fields as $cpk_field) { |
|
1769 | 1769 | $values_for_each_cpk_for_a_row[] = $cpk_field->get_qualified_column()."=".$delete_object[$cpk_field->get_qualified_column()]; |
1770 | 1770 | } |
1771 | - $ways_to_identify_a_row[] = "(".implode(" AND ",$values_for_each_cpk_for_a_row).")"; |
|
1771 | + $ways_to_identify_a_row[] = "(".implode(" AND ", $values_for_each_cpk_for_a_row).")"; |
|
1772 | 1772 | } |
1773 | - return implode(" OR ",$ways_to_identify_a_row); |
|
1774 | - }else{ |
|
1773 | + return implode(" OR ", $ways_to_identify_a_row); |
|
1774 | + } else { |
|
1775 | 1775 | //so there's no primary key and no combined key... |
1776 | 1776 | //sorry, can't help you |
1777 | - 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))); |
|
1777 | + 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))); |
|
1778 | 1778 | } |
1779 | 1779 | } |
1780 | 1780 | |
@@ -1790,21 +1790,21 @@ discard block |
||
1790 | 1790 | * @return int |
1791 | 1791 | * @throws \EE_Error |
1792 | 1792 | */ |
1793 | - public function count($query_params =array(),$field_to_count = NULL, $distinct = FALSE){ |
|
1793 | + public function count($query_params = array(), $field_to_count = NULL, $distinct = FALSE) { |
|
1794 | 1794 | $model_query_info = $this->_create_model_query_info_carrier($query_params); |
1795 | - if($field_to_count){ |
|
1795 | + if ($field_to_count) { |
|
1796 | 1796 | $field_obj = $this->field_settings_for($field_to_count); |
1797 | 1797 | $column_to_count = $field_obj->get_qualified_column(); |
1798 | - }elseif($this->has_primary_key_field ()){ |
|
1798 | + }elseif ($this->has_primary_key_field()) { |
|
1799 | 1799 | $pk_field_obj = $this->get_primary_key_field(); |
1800 | 1800 | $column_to_count = $pk_field_obj->get_qualified_column(); |
1801 | - }else{//there's no primary key |
|
1801 | + } else {//there's no primary key |
|
1802 | 1802 | $column_to_count = '*'; |
1803 | 1803 | } |
1804 | 1804 | |
1805 | - $column_to_count = $distinct ? "DISTINCT (" . $column_to_count . " )" : $column_to_count; |
|
1806 | - $SQL ="SELECT COUNT(".$column_to_count.")" . $this->_construct_2nd_half_of_select_query($model_query_info); |
|
1807 | - return (int)$this->_do_wpdb_query( 'get_var', array( $SQL) ); |
|
1805 | + $column_to_count = $distinct ? "DISTINCT (".$column_to_count." )" : $column_to_count; |
|
1806 | + $SQL = "SELECT COUNT(".$column_to_count.")".$this->_construct_2nd_half_of_select_query($model_query_info); |
|
1807 | + return (int) $this->_do_wpdb_query('get_var', array($SQL)); |
|
1808 | 1808 | } |
1809 | 1809 | |
1810 | 1810 | |
@@ -1817,24 +1817,24 @@ discard block |
||
1817 | 1817 | * @return float |
1818 | 1818 | * @throws \EE_Error |
1819 | 1819 | */ |
1820 | - public function sum($query_params, $field_to_sum = NULL){ |
|
1820 | + public function sum($query_params, $field_to_sum = NULL) { |
|
1821 | 1821 | $model_query_info = $this->_create_model_query_info_carrier($query_params); |
1822 | 1822 | |
1823 | - if($field_to_sum){ |
|
1823 | + if ($field_to_sum) { |
|
1824 | 1824 | $field_obj = $this->field_settings_for($field_to_sum); |
1825 | 1825 | |
1826 | - }else{ |
|
1826 | + } else { |
|
1827 | 1827 | $field_obj = $this->get_primary_key_field(); |
1828 | 1828 | } |
1829 | 1829 | $column_to_count = $field_obj->get_qualified_column(); |
1830 | 1830 | |
1831 | - $SQL ="SELECT SUM(".$column_to_count.")" . $this->_construct_2nd_half_of_select_query($model_query_info); |
|
1832 | - $return_value = $this->_do_wpdb_query('get_var',array( $SQL ) ); |
|
1831 | + $SQL = "SELECT SUM(".$column_to_count.")".$this->_construct_2nd_half_of_select_query($model_query_info); |
|
1832 | + $return_value = $this->_do_wpdb_query('get_var', array($SQL)); |
|
1833 | 1833 | $data_type = $field_obj->get_wpdb_data_type(); |
1834 | - if( $data_type === '%d' || $data_type === '%s' ){ |
|
1835 | - return (float)$return_value; |
|
1836 | - }else{//must be %f |
|
1837 | - return (float)$return_value; |
|
1834 | + if ($data_type === '%d' || $data_type === '%s') { |
|
1835 | + return (float) $return_value; |
|
1836 | + } else {//must be %f |
|
1837 | + return (float) $return_value; |
|
1838 | 1838 | } |
1839 | 1839 | } |
1840 | 1840 | |
@@ -1849,33 +1849,33 @@ discard block |
||
1849 | 1849 | * @global wpdb $wpdb |
1850 | 1850 | * @return mixed |
1851 | 1851 | */ |
1852 | - protected function _do_wpdb_query( $wpdb_method, $arguments_to_provide ){ |
|
1852 | + protected function _do_wpdb_query($wpdb_method, $arguments_to_provide) { |
|
1853 | 1853 | //if we're in maintenance mode level 2, DON'T run any queries |
1854 | 1854 | //because level 2 indicates the database needs updating and |
1855 | 1855 | //is probably out of sync with the code |
1856 | - if( ! EE_Maintenance_Mode::instance()->models_can_query()){ |
|
1856 | + if ( ! EE_Maintenance_Mode::instance()->models_can_query()) { |
|
1857 | 1857 | 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"))); |
1858 | 1858 | } |
1859 | 1859 | /** @type WPDB $wpdb */ |
1860 | 1860 | global $wpdb; |
1861 | - if( ! method_exists( $wpdb, $wpdb_method ) ){ |
|
1862 | - throw new EE_Error( sprintf( __( 'There is no method named "%s" on Wordpress\' $wpdb object','event_espresso' ), $wpdb_method ) ); |
|
1861 | + if ( ! method_exists($wpdb, $wpdb_method)) { |
|
1862 | + throw new EE_Error(sprintf(__('There is no method named "%s" on Wordpress\' $wpdb object', 'event_espresso'), $wpdb_method)); |
|
1863 | 1863 | } |
1864 | - if( WP_DEBUG ){ |
|
1864 | + if (WP_DEBUG) { |
|
1865 | 1865 | $old_show_errors_value = $wpdb->show_errors; |
1866 | - $wpdb->show_errors( FALSE ); |
|
1867 | - } |
|
1868 | - $result = $this->_process_wpdb_query( $wpdb_method, $arguments_to_provide ); |
|
1869 | - $this->show_db_query_if_previously_requested( $wpdb->last_query ); |
|
1870 | - if( WP_DEBUG ){ |
|
1871 | - $wpdb->show_errors( $old_show_errors_value ); |
|
1872 | - if( ! empty( $wpdb->last_error ) ){ |
|
1873 | - throw new EE_Error( sprintf( __( 'WPDB Error: "%s"', 'event_espresso' ), $wpdb->last_error ) ); |
|
1874 | - }elseif( $result === false ){ |
|
1875 | - 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 ) ) ); |
|
1866 | + $wpdb->show_errors(FALSE); |
|
1867 | + } |
|
1868 | + $result = $this->_process_wpdb_query($wpdb_method, $arguments_to_provide); |
|
1869 | + $this->show_db_query_if_previously_requested($wpdb->last_query); |
|
1870 | + if (WP_DEBUG) { |
|
1871 | + $wpdb->show_errors($old_show_errors_value); |
|
1872 | + if ( ! empty($wpdb->last_error)) { |
|
1873 | + throw new EE_Error(sprintf(__('WPDB Error: "%s"', 'event_espresso'), $wpdb->last_error)); |
|
1874 | + }elseif ($result === false) { |
|
1875 | + 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))); |
|
1876 | 1876 | } |
1877 | - }elseif( $result === false ) { |
|
1878 | - EE_Error::add_error( sprintf( __( 'A database error has occurred. Turn on WP_DEBUG for more information.', 'event_espresso' )), __FILE__, __FUNCTION__, __LINE__); |
|
1877 | + }elseif ($result === false) { |
|
1878 | + EE_Error::add_error(sprintf(__('A database error has occurred. Turn on WP_DEBUG for more information.', 'event_espresso')), __FILE__, __FUNCTION__, __LINE__); |
|
1879 | 1879 | } |
1880 | 1880 | return $result; |
1881 | 1881 | } |
@@ -1891,26 +1891,26 @@ discard block |
||
1891 | 1891 | * @param array $arguments_to_provide |
1892 | 1892 | * @return mixed |
1893 | 1893 | */ |
1894 | - private function _process_wpdb_query( $wpdb_method, $arguments_to_provide ) { |
|
1894 | + private function _process_wpdb_query($wpdb_method, $arguments_to_provide) { |
|
1895 | 1895 | /** @type WPDB $wpdb */ |
1896 | 1896 | global $wpdb; |
1897 | 1897 | $wpdb->last_error = null; |
1898 | - $result = call_user_func_array( array( $wpdb, $wpdb_method ), $arguments_to_provide ); |
|
1898 | + $result = call_user_func_array(array($wpdb, $wpdb_method), $arguments_to_provide); |
|
1899 | 1899 | // was there an error running the query? but we don't care on new activations |
1900 | 1900 | // (we're going to setup the DB anyway on new activations) |
1901 | - if ( ( $result === false || ! empty( $wpdb->last_error ) ) |
|
1901 | + if (($result === false || ! empty($wpdb->last_error)) |
|
1902 | 1902 | && EE_System::instance()->detect_req_type() !== EE_System::req_type_new_activation |
1903 | 1903 | ) { |
1904 | - switch ( EEM_Base::$_db_verification_level ) { |
|
1904 | + switch (EEM_Base::$_db_verification_level) { |
|
1905 | 1905 | |
1906 | 1906 | case EEM_Base::db_verified_none : |
1907 | 1907 | // let's double-check core's DB |
1908 | - $error_message = $this->_verify_core_db( $wpdb_method, $arguments_to_provide ); |
|
1908 | + $error_message = $this->_verify_core_db($wpdb_method, $arguments_to_provide); |
|
1909 | 1909 | break; |
1910 | 1910 | |
1911 | 1911 | case EEM_Base::db_verified_core : |
1912 | 1912 | // STILL NO LOVE?? verify all the addons too. Maybe they need to be fixed |
1913 | - $error_message = $this->_verify_addons_db( $wpdb_method, $arguments_to_provide ); |
|
1913 | + $error_message = $this->_verify_addons_db($wpdb_method, $arguments_to_provide); |
|
1914 | 1914 | break; |
1915 | 1915 | |
1916 | 1916 | case EEM_Base::db_verified_addons : |
@@ -1918,11 +1918,11 @@ discard block |
||
1918 | 1918 | return $result; |
1919 | 1919 | break; |
1920 | 1920 | } |
1921 | - if ( ! empty( $error_message ) ) { |
|
1922 | - EE_Log::instance()->log( __FILE__, __FUNCTION__, $error_message, 'error' ); |
|
1923 | - trigger_error( $error_message ); |
|
1921 | + if ( ! empty($error_message)) { |
|
1922 | + EE_Log::instance()->log(__FILE__, __FUNCTION__, $error_message, 'error'); |
|
1923 | + trigger_error($error_message); |
|
1924 | 1924 | } |
1925 | - return $this->_process_wpdb_query( $wpdb_method, $arguments_to_provide ); |
|
1925 | + return $this->_process_wpdb_query($wpdb_method, $arguments_to_provide); |
|
1926 | 1926 | |
1927 | 1927 | } |
1928 | 1928 | |
@@ -1938,18 +1938,18 @@ discard block |
||
1938 | 1938 | * @param array $arguments_to_provide |
1939 | 1939 | * @return string |
1940 | 1940 | */ |
1941 | - private function _verify_core_db( $wpdb_method, $arguments_to_provide ){ |
|
1941 | + private function _verify_core_db($wpdb_method, $arguments_to_provide) { |
|
1942 | 1942 | /** @type WPDB $wpdb */ |
1943 | 1943 | global $wpdb; |
1944 | 1944 | //ok remember that we've already attempted fixing the core db, in case the problem persists |
1945 | 1945 | EEM_Base::$_db_verification_level = EEM_Base::db_verified_core; |
1946 | 1946 | $error_message = sprintf( |
1947 | - __( 'WPDB Error "%1$s" while running wpdb method "%2$s" with arguments %3$s. Automatically attempting to fix EE Core DB', 'event_espresso' ), |
|
1947 | + __('WPDB Error "%1$s" while running wpdb method "%2$s" with arguments %3$s. Automatically attempting to fix EE Core DB', 'event_espresso'), |
|
1948 | 1948 | $wpdb->last_error, |
1949 | 1949 | $wpdb_method, |
1950 | - json_encode( $arguments_to_provide ) |
|
1950 | + json_encode($arguments_to_provide) |
|
1951 | 1951 | ); |
1952 | - EE_System::instance()->initialize_db_if_no_migrations_required( false, true ); |
|
1952 | + EE_System::instance()->initialize_db_if_no_migrations_required(false, true); |
|
1953 | 1953 | return $error_message; |
1954 | 1954 | } |
1955 | 1955 | |
@@ -1962,16 +1962,16 @@ discard block |
||
1962 | 1962 | * @param $arguments_to_provide |
1963 | 1963 | * @return string |
1964 | 1964 | */ |
1965 | - private function _verify_addons_db( $wpdb_method, $arguments_to_provide ) { |
|
1965 | + private function _verify_addons_db($wpdb_method, $arguments_to_provide) { |
|
1966 | 1966 | /** @type WPDB $wpdb */ |
1967 | 1967 | global $wpdb; |
1968 | 1968 | //ok remember that we've already attempted fixing the addons dbs, in case the problem persists |
1969 | 1969 | EEM_Base::$_db_verification_level = EEM_Base::db_verified_addons; |
1970 | 1970 | $error_message = sprintf( |
1971 | - __( 'WPDB AGAIN: Error "%1$s" while running the same method and arguments as before. Automatically attempting to fix EE Addons DB', 'event_espresso' ), |
|
1971 | + __('WPDB AGAIN: Error "%1$s" while running the same method and arguments as before. Automatically attempting to fix EE Addons DB', 'event_espresso'), |
|
1972 | 1972 | $wpdb->last_error, |
1973 | 1973 | $wpdb_method, |
1974 | - json_encode( $arguments_to_provide ) |
|
1974 | + json_encode($arguments_to_provide) |
|
1975 | 1975 | ); |
1976 | 1976 | EE_System::instance()->initialize_addons(); |
1977 | 1977 | return $error_message; |
@@ -1986,7 +1986,7 @@ discard block |
||
1986 | 1986 | * @param EE_Model_Query_Info_Carrier $model_query_info |
1987 | 1987 | * @return string |
1988 | 1988 | */ |
1989 | - private function _construct_2nd_half_of_select_query(EE_Model_Query_Info_Carrier $model_query_info){ |
|
1989 | + private function _construct_2nd_half_of_select_query(EE_Model_Query_Info_Carrier $model_query_info) { |
|
1990 | 1990 | return " FROM ".$model_query_info->get_full_join_sql(). |
1991 | 1991 | $model_query_info->get_where_sql(). |
1992 | 1992 | $model_query_info->get_group_by_sql(). |
@@ -1999,7 +1999,7 @@ discard block |
||
1999 | 1999 | * Set to easily debug the next X queries ran from this model. |
2000 | 2000 | * @param int $count |
2001 | 2001 | */ |
2002 | - public function show_next_x_db_queries($count = 1){ |
|
2002 | + public function show_next_x_db_queries($count = 1) { |
|
2003 | 2003 | $this->_show_next_x_db_queries = $count; |
2004 | 2004 | } |
2005 | 2005 | |
@@ -2008,8 +2008,8 @@ discard block |
||
2008 | 2008 | /** |
2009 | 2009 | * @param $sql_query |
2010 | 2010 | */ |
2011 | - public function show_db_query_if_previously_requested($sql_query){ |
|
2012 | - if($this->_show_next_x_db_queries > 0){ |
|
2011 | + public function show_db_query_if_previously_requested($sql_query) { |
|
2012 | + if ($this->_show_next_x_db_queries > 0) { |
|
2013 | 2013 | echo $sql_query; |
2014 | 2014 | $this->_show_next_x_db_queries--; |
2015 | 2015 | } |
@@ -2033,9 +2033,9 @@ discard block |
||
2033 | 2033 | * @return EE_Base_Class which was added as a relation. Object referred to by $other_model_id_or_obj |
2034 | 2034 | * @throws \EE_Error |
2035 | 2035 | */ |
2036 | - public function add_relationship_to($id_or_obj,$other_model_id_or_obj, $relationName, $extra_join_model_fields_n_values = array()){ |
|
2036 | + public function add_relationship_to($id_or_obj, $other_model_id_or_obj, $relationName, $extra_join_model_fields_n_values = array()) { |
|
2037 | 2037 | $relation_obj = $this->related_settings_for($relationName); |
2038 | - return $relation_obj->add_relation_to( $id_or_obj, $other_model_id_or_obj, $extra_join_model_fields_n_values); |
|
2038 | + return $relation_obj->add_relation_to($id_or_obj, $other_model_id_or_obj, $extra_join_model_fields_n_values); |
|
2039 | 2039 | } |
2040 | 2040 | |
2041 | 2041 | |
@@ -2054,9 +2054,9 @@ discard block |
||
2054 | 2054 | * @throws \EE_Error |
2055 | 2055 | * @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. |
2056 | 2056 | */ |
2057 | - public function remove_relationship_to($id_or_obj, $other_model_id_or_obj, $relationName, $where_query= array() ){ |
|
2057 | + public function remove_relationship_to($id_or_obj, $other_model_id_or_obj, $relationName, $where_query = array()) { |
|
2058 | 2058 | $relation_obj = $this->related_settings_for($relationName); |
2059 | - return $relation_obj->remove_relation_to($id_or_obj, $other_model_id_or_obj, $where_query ); |
|
2059 | + return $relation_obj->remove_relation_to($id_or_obj, $other_model_id_or_obj, $where_query); |
|
2060 | 2060 | } |
2061 | 2061 | |
2062 | 2062 | |
@@ -2069,9 +2069,9 @@ discard block |
||
2069 | 2069 | * @return \EE_Base_Class[] |
2070 | 2070 | * @throws \EE_Error |
2071 | 2071 | */ |
2072 | - public function remove_relations($id_or_obj,$relationName,$where_query_params = array()){ |
|
2072 | + public function remove_relations($id_or_obj, $relationName, $where_query_params = array()) { |
|
2073 | 2073 | $relation_obj = $this->related_settings_for($relationName); |
2074 | - return $relation_obj->remove_relations($id_or_obj, $where_query_params ); |
|
2074 | + return $relation_obj->remove_relations($id_or_obj, $where_query_params); |
|
2075 | 2075 | } |
2076 | 2076 | |
2077 | 2077 | |
@@ -2087,10 +2087,10 @@ discard block |
||
2087 | 2087 | * @return EE_Base_Class[] |
2088 | 2088 | * @throws \EE_Error |
2089 | 2089 | */ |
2090 | - public function get_all_related($id_or_obj, $model_name, $query_params = null){ |
|
2090 | + public function get_all_related($id_or_obj, $model_name, $query_params = null) { |
|
2091 | 2091 | $model_obj = $this->ensure_is_obj($id_or_obj); |
2092 | 2092 | $relation_settings = $this->related_settings_for($model_name); |
2093 | - return $relation_settings->get_all_related($model_obj,$query_params); |
|
2093 | + return $relation_settings->get_all_related($model_obj, $query_params); |
|
2094 | 2094 | } |
2095 | 2095 | |
2096 | 2096 | |
@@ -2107,10 +2107,10 @@ discard block |
||
2107 | 2107 | * @return int how many deleted |
2108 | 2108 | * @throws \EE_Error |
2109 | 2109 | */ |
2110 | - public function delete_related($id_or_obj,$model_name, $query_params = array()){ |
|
2110 | + public function delete_related($id_or_obj, $model_name, $query_params = array()) { |
|
2111 | 2111 | $model_obj = $this->ensure_is_obj($id_or_obj); |
2112 | 2112 | $relation_settings = $this->related_settings_for($model_name); |
2113 | - return $relation_settings->delete_all_related($model_obj,$query_params); |
|
2113 | + return $relation_settings->delete_all_related($model_obj, $query_params); |
|
2114 | 2114 | } |
2115 | 2115 | |
2116 | 2116 | |
@@ -2127,10 +2127,10 @@ discard block |
||
2127 | 2127 | * @return int how many deleted |
2128 | 2128 | * @throws \EE_Error |
2129 | 2129 | */ |
2130 | - public function delete_related_permanently($id_or_obj,$model_name, $query_params = array()){ |
|
2130 | + public function delete_related_permanently($id_or_obj, $model_name, $query_params = array()) { |
|
2131 | 2131 | $model_obj = $this->ensure_is_obj($id_or_obj); |
2132 | 2132 | $relation_settings = $this->related_settings_for($model_name); |
2133 | - return $relation_settings->delete_related_permanently($model_obj,$query_params); |
|
2133 | + return $relation_settings->delete_related_permanently($model_obj, $query_params); |
|
2134 | 2134 | } |
2135 | 2135 | |
2136 | 2136 | |
@@ -2147,17 +2147,17 @@ discard block |
||
2147 | 2147 | * @return int |
2148 | 2148 | * @throws \EE_Error |
2149 | 2149 | */ |
2150 | - public function count_related($id_or_obj,$model_name,$query_params = array(),$field_to_count = null, $distinct = FALSE){ |
|
2150 | + public function count_related($id_or_obj, $model_name, $query_params = array(), $field_to_count = null, $distinct = FALSE) { |
|
2151 | 2151 | $related_model = $this->get_related_model_obj($model_name); |
2152 | 2152 | //we're just going to use the query params on the related model's normal get_all query, |
2153 | 2153 | //except add a condition to say to match the current mod |
2154 | - if( ! isset($query_params['default_where_conditions'])){ |
|
2155 | - $query_params['default_where_conditions']='none'; |
|
2154 | + if ( ! isset($query_params['default_where_conditions'])) { |
|
2155 | + $query_params['default_where_conditions'] = 'none'; |
|
2156 | 2156 | } |
2157 | 2157 | $this_model_name = $this->get_this_model_name(); |
2158 | 2158 | $this_pk_field_name = $this->get_primary_key_field()->get_name(); |
2159 | - $query_params[0][$this_model_name.".".$this_pk_field_name]=$id_or_obj; |
|
2160 | - return $related_model->count($query_params,$field_to_count,$distinct); |
|
2159 | + $query_params[0][$this_model_name.".".$this_pk_field_name] = $id_or_obj; |
|
2160 | + return $related_model->count($query_params, $field_to_count, $distinct); |
|
2161 | 2161 | } |
2162 | 2162 | |
2163 | 2163 | |
@@ -2173,21 +2173,21 @@ discard block |
||
2173 | 2173 | * @return float |
2174 | 2174 | * @throws \EE_Error |
2175 | 2175 | */ |
2176 | - public function sum_related($id_or_obj,$model_name,$query_params,$field_to_sum = null){ |
|
2176 | + public function sum_related($id_or_obj, $model_name, $query_params, $field_to_sum = null) { |
|
2177 | 2177 | $related_model = $this->get_related_model_obj($model_name); |
2178 | - if( ! is_array( $query_params ) ){ |
|
2179 | - 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' ); |
|
2178 | + if ( ! is_array($query_params)) { |
|
2179 | + 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'); |
|
2180 | 2180 | $query_params = array(); |
2181 | 2181 | } |
2182 | 2182 | //we're just going to use the query params on the related model's normal get_all query, |
2183 | 2183 | //except add a condition to say to match the current mod |
2184 | - if( ! isset($query_params['default_where_conditions'])){ |
|
2185 | - $query_params['default_where_conditions']='none'; |
|
2184 | + if ( ! isset($query_params['default_where_conditions'])) { |
|
2185 | + $query_params['default_where_conditions'] = 'none'; |
|
2186 | 2186 | } |
2187 | 2187 | $this_model_name = $this->get_this_model_name(); |
2188 | 2188 | $this_pk_field_name = $this->get_primary_key_field()->get_name(); |
2189 | - $query_params[0][$this_model_name.".".$this_pk_field_name]=$id_or_obj; |
|
2190 | - return $related_model->sum($query_params,$field_to_sum); |
|
2189 | + $query_params[0][$this_model_name.".".$this_pk_field_name] = $id_or_obj; |
|
2190 | + return $related_model->sum($query_params, $field_to_sum); |
|
2191 | 2191 | } |
2192 | 2192 | |
2193 | 2193 | |
@@ -2201,12 +2201,12 @@ discard block |
||
2201 | 2201 | * @return EE_Base_Class |
2202 | 2202 | * @throws \EE_Error |
2203 | 2203 | */ |
2204 | - public function get_first_related( EE_Base_Class $id_or_obj, $other_model_name, $query_params ){ |
|
2205 | - $query_params['limit']=1; |
|
2206 | - $results = $this->get_all_related($id_or_obj,$other_model_name,$query_params); |
|
2207 | - if( $results ){ |
|
2204 | + public function get_first_related(EE_Base_Class $id_or_obj, $other_model_name, $query_params) { |
|
2205 | + $query_params['limit'] = 1; |
|
2206 | + $results = $this->get_all_related($id_or_obj, $other_model_name, $query_params); |
|
2207 | + if ($results) { |
|
2208 | 2208 | return array_shift($results); |
2209 | - }else{ |
|
2209 | + } else { |
|
2210 | 2210 | return null; |
2211 | 2211 | } |
2212 | 2212 | |
@@ -2216,8 +2216,8 @@ discard block |
||
2216 | 2216 | * Gets the model's name as it's expected in queries. For example, if this is EEM_Event model, that would be Event |
2217 | 2217 | * @return string |
2218 | 2218 | */ |
2219 | - public function get_this_model_name(){ |
|
2220 | - return str_replace("EEM_","",get_class($this)); |
|
2219 | + public function get_this_model_name() { |
|
2220 | + return str_replace("EEM_", "", get_class($this)); |
|
2221 | 2221 | } |
2222 | 2222 | |
2223 | 2223 | /** |
@@ -2225,14 +2225,14 @@ discard block |
||
2225 | 2225 | * @return EE_Any_Foreign_Model_Name_Field |
2226 | 2226 | * @throws EE_Error |
2227 | 2227 | */ |
2228 | - public function get_field_containing_related_model_name(){ |
|
2229 | - foreach($this->field_settings(true) as $field){ |
|
2230 | - if($field instanceof EE_Any_Foreign_Model_Name_Field){ |
|
2228 | + public function get_field_containing_related_model_name() { |
|
2229 | + foreach ($this->field_settings(true) as $field) { |
|
2230 | + if ($field instanceof EE_Any_Foreign_Model_Name_Field) { |
|
2231 | 2231 | $field_with_model_name = $field; |
2232 | 2232 | } |
2233 | 2233 | } |
2234 | - if( !isset($field_with_model_name) || !$field_with_model_name ){ |
|
2235 | - throw new EE_Error(sprintf(__("There is no EE_Any_Foreign_Model_Name field on model %s", "event_espresso"), $this->get_this_model_name() )); |
|
2234 | + if ( ! isset($field_with_model_name) || ! $field_with_model_name) { |
|
2235 | + throw new EE_Error(sprintf(__("There is no EE_Any_Foreign_Model_Name field on model %s", "event_espresso"), $this->get_this_model_name())); |
|
2236 | 2236 | } |
2237 | 2237 | return $field_with_model_name; |
2238 | 2238 | } |
@@ -2253,19 +2253,19 @@ discard block |
||
2253 | 2253 | * @return int new primary key on main table that got inserted |
2254 | 2254 | * @throws EE_Error |
2255 | 2255 | */ |
2256 | - public function insert($field_n_values){ |
|
2256 | + public function insert($field_n_values) { |
|
2257 | 2257 | /** |
2258 | 2258 | * Filters the fields and their values before inserting an item using the models |
2259 | 2259 | * @param array $fields_n_values keys are the fields and values are their new values |
2260 | 2260 | * @param EEM_Base $model the model used |
2261 | 2261 | */ |
2262 | - $field_n_values = (array)apply_filters( 'FHEE__EEM_Base__insert__fields_n_values', $field_n_values, $this ); |
|
2263 | - if($this->_satisfies_unique_indexes($field_n_values)){ |
|
2262 | + $field_n_values = (array) apply_filters('FHEE__EEM_Base__insert__fields_n_values', $field_n_values, $this); |
|
2263 | + if ($this->_satisfies_unique_indexes($field_n_values)) { |
|
2264 | 2264 | $main_table = $this->_get_main_table(); |
2265 | 2265 | $new_id = $this->_insert_into_specific_table($main_table, $field_n_values, false); |
2266 | - if( $new_id !== false ) { |
|
2267 | - foreach($this->_get_other_tables() as $other_table){ |
|
2268 | - $this->_insert_into_specific_table($other_table, $field_n_values,$new_id); |
|
2266 | + if ($new_id !== false) { |
|
2267 | + foreach ($this->_get_other_tables() as $other_table) { |
|
2268 | + $this->_insert_into_specific_table($other_table, $field_n_values, $new_id); |
|
2269 | 2269 | } |
2270 | 2270 | } |
2271 | 2271 | /** |
@@ -2275,9 +2275,9 @@ discard block |
||
2275 | 2275 | * @param array $fields_n_values fields and their values |
2276 | 2276 | * @param int|string the ID of the newly-inserted model object |
2277 | 2277 | */ |
2278 | - do_action( 'AHEE__EEM_Base__insert__end', $this, $field_n_values, $new_id ); |
|
2278 | + do_action('AHEE__EEM_Base__insert__end', $this, $field_n_values, $new_id); |
|
2279 | 2279 | return $new_id; |
2280 | - }else{ |
|
2280 | + } else { |
|
2281 | 2281 | return FALSE; |
2282 | 2282 | } |
2283 | 2283 | } |
@@ -2292,10 +2292,10 @@ discard block |
||
2292 | 2292 | * @return boolean |
2293 | 2293 | * @throws \EE_Error |
2294 | 2294 | */ |
2295 | - protected function _satisfies_unique_indexes($field_n_values,$action = 'insert'){ |
|
2296 | - foreach($this->unique_indexes() as $index_name => $index){ |
|
2295 | + protected function _satisfies_unique_indexes($field_n_values, $action = 'insert') { |
|
2296 | + foreach ($this->unique_indexes() as $index_name => $index) { |
|
2297 | 2297 | $uniqueness_where_params = array_intersect_key($field_n_values, $index->fields()); |
2298 | - if($this->exists(array($uniqueness_where_params))){ |
|
2298 | + if ($this->exists(array($uniqueness_where_params))) { |
|
2299 | 2299 | EE_Error::add_error( |
2300 | 2300 | sprintf( |
2301 | 2301 | __( |
@@ -2305,8 +2305,8 @@ discard block |
||
2305 | 2305 | $action, |
2306 | 2306 | $this->_get_class_name(), |
2307 | 2307 | $index_name, |
2308 | - implode( ",", $index->field_names() ), |
|
2309 | - http_build_query( $uniqueness_where_params ) |
|
2308 | + implode(",", $index->field_names()), |
|
2309 | + http_build_query($uniqueness_where_params) |
|
2310 | 2310 | ), |
2311 | 2311 | __FILE__, |
2312 | 2312 | __FUNCTION__, |
@@ -2332,37 +2332,37 @@ discard block |
||
2332 | 2332 | * @throws EE_Error |
2333 | 2333 | * @return EE_Base_Class |
2334 | 2334 | */ |
2335 | - public function get_one_conflicting($obj_or_fields_array, $include_primary_key = true ){ |
|
2336 | - if($obj_or_fields_array instanceof EE_Base_Class){ |
|
2335 | + public function get_one_conflicting($obj_or_fields_array, $include_primary_key = true) { |
|
2336 | + if ($obj_or_fields_array instanceof EE_Base_Class) { |
|
2337 | 2337 | $fields_n_values = $obj_or_fields_array->model_field_array(); |
2338 | - }elseif( is_array($obj_or_fields_array)){ |
|
2338 | + }elseif (is_array($obj_or_fields_array)) { |
|
2339 | 2339 | $fields_n_values = $obj_or_fields_array; |
2340 | - }else{ |
|
2340 | + } else { |
|
2341 | 2341 | throw new EE_Error( |
2342 | 2342 | sprintf( |
2343 | 2343 | __( |
2344 | 2344 | "%s get_all_conflicting should be called with a model object or an array of field names and values, you provided %d", |
2345 | 2345 | "event_espresso" |
2346 | 2346 | ), |
2347 | - get_class( $this ), |
|
2347 | + get_class($this), |
|
2348 | 2348 | $obj_or_fields_array |
2349 | 2349 | ) |
2350 | 2350 | ); |
2351 | 2351 | } |
2352 | 2352 | $query_params = array(); |
2353 | - if( $this->has_primary_key_field() && |
|
2354 | - ( $include_primary_key || $this->get_primary_key_field() instanceof EE_Primary_Key_String_Field) && |
|
2355 | - isset($fields_n_values[$this->primary_key_name()])){ |
|
2353 | + if ($this->has_primary_key_field() && |
|
2354 | + ($include_primary_key || $this->get_primary_key_field() instanceof EE_Primary_Key_String_Field) && |
|
2355 | + isset($fields_n_values[$this->primary_key_name()])) { |
|
2356 | 2356 | $query_params[0]['OR'][$this->primary_key_name()] = $fields_n_values[$this->primary_key_name()]; |
2357 | 2357 | } |
2358 | - foreach($this->unique_indexes() as $unique_index_name=>$unique_index){ |
|
2358 | + foreach ($this->unique_indexes() as $unique_index_name=>$unique_index) { |
|
2359 | 2359 | $uniqueness_where_params = array_intersect_key($fields_n_values, $unique_index->fields()); |
2360 | 2360 | $query_params[0]['OR']['AND*'.$unique_index_name] = $uniqueness_where_params; |
2361 | 2361 | } |
2362 | 2362 | //if there is nothing to base this search on, then we shouldn't find anything |
2363 | - if( empty( $query_params ) ){ |
|
2363 | + if (empty($query_params)) { |
|
2364 | 2364 | return array(); |
2365 | - }else{ |
|
2365 | + } else { |
|
2366 | 2366 | return $this->get_one($query_params); |
2367 | 2367 | } |
2368 | 2368 | } |
@@ -2376,7 +2376,7 @@ discard block |
||
2376 | 2376 | * @return boolean |
2377 | 2377 | * @throws \EE_Error |
2378 | 2378 | */ |
2379 | - public function exists($query_params){ |
|
2379 | + public function exists($query_params) { |
|
2380 | 2380 | $query_params['limit'] = 1; |
2381 | 2381 | return $this->count($query_params) > 0; |
2382 | 2382 | } |
@@ -2390,7 +2390,7 @@ discard block |
||
2390 | 2390 | * @return boolean |
2391 | 2391 | * @throws \EE_Error |
2392 | 2392 | */ |
2393 | - public function exists_by_ID($id){ |
|
2393 | + public function exists_by_ID($id) { |
|
2394 | 2394 | return $this->exists(array('default_where_conditions'=>'none', array($this->primary_key_name() => $id))); |
2395 | 2395 | } |
2396 | 2396 | |
@@ -2410,45 +2410,45 @@ discard block |
||
2410 | 2410 | * @global WPDB $wpdb only used to get the $wpdb->insert_id after performing an insert |
2411 | 2411 | * @return int ID of new row inserted, or FALSE on failure |
2412 | 2412 | */ |
2413 | - protected function _insert_into_specific_table(EE_Table_Base $table, $fields_n_values, $new_id = 0 ){ |
|
2413 | + protected function _insert_into_specific_table(EE_Table_Base $table, $fields_n_values, $new_id = 0) { |
|
2414 | 2414 | global $wpdb; |
2415 | 2415 | $insertion_col_n_values = array(); |
2416 | 2416 | $format_for_insertion = array(); |
2417 | 2417 | $fields_on_table = $this->_get_fields_for_table($table->get_table_alias()); |
2418 | - foreach($fields_on_table as $field_name => $field_obj){ |
|
2418 | + foreach ($fields_on_table as $field_name => $field_obj) { |
|
2419 | 2419 | //check if its an auto-incrementing column, in which case we should just leave it to do its autoincrement thing |
2420 | - if($field_obj->is_auto_increment()){ |
|
2420 | + if ($field_obj->is_auto_increment()) { |
|
2421 | 2421 | continue; |
2422 | 2422 | } |
2423 | 2423 | $prepared_value = $this->_prepare_value_or_use_default($field_obj, $fields_n_values); |
2424 | 2424 | //if the value we want to assign it to is NULL, just don't mention it for the insertion |
2425 | - if( $prepared_value !== NULL ){ |
|
2426 | - $insertion_col_n_values[ $field_obj->get_table_column() ] = $prepared_value; |
|
2425 | + if ($prepared_value !== NULL) { |
|
2426 | + $insertion_col_n_values[$field_obj->get_table_column()] = $prepared_value; |
|
2427 | 2427 | $format_for_insertion[] = $field_obj->get_wpdb_data_type(); |
2428 | 2428 | } |
2429 | 2429 | } |
2430 | 2430 | |
2431 | - if($table instanceof EE_Secondary_Table && $new_id){ |
|
2431 | + if ($table instanceof EE_Secondary_Table && $new_id) { |
|
2432 | 2432 | //its not the main table, so we should have already saved the main table's PK which we just inserted |
2433 | 2433 | //so add the fk to the main table as a column |
2434 | 2434 | $insertion_col_n_values[$table->get_fk_on_table()] = $new_id; |
2435 | - $format_for_insertion[]='%d';//yes right now we're only allowing these foreign keys to be INTs |
|
2435 | + $format_for_insertion[] = '%d'; //yes right now we're only allowing these foreign keys to be INTs |
|
2436 | 2436 | } |
2437 | 2437 | //insert the new entry |
2438 | - $result = $this->_do_wpdb_query( 'insert', array( $table->get_table_name(), $insertion_col_n_values, $format_for_insertion ) ); |
|
2439 | - if( $result === false ) { |
|
2438 | + $result = $this->_do_wpdb_query('insert', array($table->get_table_name(), $insertion_col_n_values, $format_for_insertion)); |
|
2439 | + if ($result === false) { |
|
2440 | 2440 | return false; |
2441 | 2441 | } |
2442 | 2442 | //ok, now what do we return for the ID of the newly-inserted thing? |
2443 | - if($this->has_primary_key_field()){ |
|
2444 | - if($this->get_primary_key_field()->is_auto_increment()){ |
|
2443 | + if ($this->has_primary_key_field()) { |
|
2444 | + if ($this->get_primary_key_field()->is_auto_increment()) { |
|
2445 | 2445 | return $wpdb->insert_id; |
2446 | - }else{ |
|
2446 | + } else { |
|
2447 | 2447 | //it's not an auto-increment primary key, so |
2448 | 2448 | //it must have been supplied |
2449 | 2449 | return $fields_n_values[$this->get_primary_key_field()->get_name()]; |
2450 | 2450 | } |
2451 | - }else{ |
|
2451 | + } else { |
|
2452 | 2452 | //we can't return a primary key because there is none. instead return |
2453 | 2453 | //a unique string indicating this model |
2454 | 2454 | return $this->get_index_primary_key_string($fields_n_values); |
@@ -2467,15 +2467,15 @@ discard block |
||
2467 | 2467 | * @return mixed string|int|float depending on what the table column will be expecting |
2468 | 2468 | * @throws \EE_Error |
2469 | 2469 | */ |
2470 | - protected function _prepare_value_or_use_default( $field_obj, $fields_n_values ){ |
|
2470 | + protected function _prepare_value_or_use_default($field_obj, $fields_n_values) { |
|
2471 | 2471 | //if this field doesn't allow nullable, don't allow it |
2472 | - if( ! $field_obj->is_nullable() && ( |
|
2473 | - ! isset( $fields_n_values[ $field_obj->get_name() ] ) || |
|
2474 | - $fields_n_values[ $field_obj->get_name() ] === NULL ) ){ |
|
2475 | - $fields_n_values[ $field_obj->get_name() ] = $field_obj->get_default_value(); |
|
2472 | + if ( ! $field_obj->is_nullable() && ( |
|
2473 | + ! isset($fields_n_values[$field_obj->get_name()]) || |
|
2474 | + $fields_n_values[$field_obj->get_name()] === NULL )) { |
|
2475 | + $fields_n_values[$field_obj->get_name()] = $field_obj->get_default_value(); |
|
2476 | 2476 | } |
2477 | - $unprepared_value = isset( $fields_n_values[ $field_obj->get_name() ] ) ? $fields_n_values[ $field_obj->get_name() ] : NULL; |
|
2478 | - return $this->_prepare_value_for_use_in_db( $unprepared_value, $field_obj); |
|
2477 | + $unprepared_value = isset($fields_n_values[$field_obj->get_name()]) ? $fields_n_values[$field_obj->get_name()] : NULL; |
|
2478 | + return $this->_prepare_value_for_use_in_db($unprepared_value, $field_obj); |
|
2479 | 2479 | } |
2480 | 2480 | |
2481 | 2481 | |
@@ -2487,9 +2487,9 @@ discard block |
||
2487 | 2487 | * @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 |
2488 | 2488 | * @return mixed a value ready for use in the database for insertions, updating, or in a where clause |
2489 | 2489 | */ |
2490 | - private function _prepare_value_for_use_in_db($value, $field){ |
|
2491 | - if($field && $field instanceof EE_Model_Field_Base){ |
|
2492 | - switch( $this->_values_already_prepared_by_model_object ){ |
|
2490 | + private function _prepare_value_for_use_in_db($value, $field) { |
|
2491 | + if ($field && $field instanceof EE_Model_Field_Base) { |
|
2492 | + switch ($this->_values_already_prepared_by_model_object) { |
|
2493 | 2493 | /** @noinspection PhpMissingBreakStatementInspection */ |
2494 | 2494 | case self::not_prepared_by_model_object: |
2495 | 2495 | $value = $field->prepare_for_set($value); |
@@ -2500,7 +2500,7 @@ discard block |
||
2500 | 2500 | //leave the value alone |
2501 | 2501 | } |
2502 | 2502 | return $value; |
2503 | - }else{ |
|
2503 | + } else { |
|
2504 | 2504 | return $value; |
2505 | 2505 | } |
2506 | 2506 | } |
@@ -2510,13 +2510,13 @@ discard block |
||
2510 | 2510 | * @return EE_Primary_Table |
2511 | 2511 | * @throws EE_Error |
2512 | 2512 | */ |
2513 | - protected function _get_main_table(){ |
|
2514 | - foreach($this->_tables as $table){ |
|
2515 | - if($table instanceof EE_Primary_Table){ |
|
2513 | + protected function _get_main_table() { |
|
2514 | + foreach ($this->_tables as $table) { |
|
2515 | + if ($table instanceof EE_Primary_Table) { |
|
2516 | 2516 | return $table; |
2517 | 2517 | } |
2518 | 2518 | } |
2519 | - 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))); |
|
2519 | + 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))); |
|
2520 | 2520 | } |
2521 | 2521 | |
2522 | 2522 | |
@@ -2539,7 +2539,7 @@ discard block |
||
2539 | 2539 | */ |
2540 | 2540 | public function second_table() { |
2541 | 2541 | // grab second table from tables array |
2542 | - $second_table = end( $this->_tables ); |
|
2542 | + $second_table = end($this->_tables); |
|
2543 | 2543 | return $second_table instanceof EE_Secondary_Table ? $second_table->get_table_name() : NULL; |
2544 | 2544 | } |
2545 | 2545 | |
@@ -2552,8 +2552,8 @@ discard block |
||
2552 | 2552 | * @param string $table_alias |
2553 | 2553 | * @return EE_Primary_Table | EE_Secondary_Table |
2554 | 2554 | */ |
2555 | - public function get_table_obj_by_alias( $table_alias = '' ) { |
|
2556 | - return isset( $this->_tables[ $table_alias ] ) ? $this->_tables[ $table_alias ] : NULL; |
|
2555 | + public function get_table_obj_by_alias($table_alias = '') { |
|
2556 | + return isset($this->_tables[$table_alias]) ? $this->_tables[$table_alias] : NULL; |
|
2557 | 2557 | } |
2558 | 2558 | |
2559 | 2559 | |
@@ -2562,10 +2562,10 @@ discard block |
||
2562 | 2562 | * Gets all the tables of type EE_Other_Table from EEM_CPT_Basel_Model::_tables |
2563 | 2563 | * @return EE_Secondary_Table[] |
2564 | 2564 | */ |
2565 | - protected function _get_other_tables(){ |
|
2566 | - $other_tables =array(); |
|
2567 | - foreach($this->_tables as $table_alias => $table){ |
|
2568 | - if($table instanceof EE_Secondary_Table){ |
|
2565 | + protected function _get_other_tables() { |
|
2566 | + $other_tables = array(); |
|
2567 | + foreach ($this->_tables as $table_alias => $table) { |
|
2568 | + if ($table instanceof EE_Secondary_Table) { |
|
2569 | 2569 | $other_tables[$table_alias] = $table; |
2570 | 2570 | } |
2571 | 2571 | } |
@@ -2577,7 +2577,7 @@ discard block |
||
2577 | 2577 | * @param string $table_alias, array key in EEM_Base::_tables |
2578 | 2578 | * @return EE_Model_Field_Base[] |
2579 | 2579 | */ |
2580 | - public function _get_fields_for_table($table_alias){ |
|
2580 | + public function _get_fields_for_table($table_alias) { |
|
2581 | 2581 | return $this->_fields[$table_alias]; |
2582 | 2582 | } |
2583 | 2583 | |
@@ -2593,19 +2593,19 @@ discard block |
||
2593 | 2593 | * @return EE_Model_Query_Info_Carrier |
2594 | 2594 | * @throws \EE_Error |
2595 | 2595 | */ |
2596 | - public function _extract_related_models_from_query($query_params){ |
|
2596 | + public function _extract_related_models_from_query($query_params) { |
|
2597 | 2597 | $query_info_carrier = new EE_Model_Query_Info_Carrier(); |
2598 | - if ( array_key_exists( 0, $query_params ) ) { |
|
2599 | - $this->_extract_related_models_from_sub_params_array_keys( $query_params[0], $query_info_carrier, 0 ); |
|
2598 | + if (array_key_exists(0, $query_params)) { |
|
2599 | + $this->_extract_related_models_from_sub_params_array_keys($query_params[0], $query_info_carrier, 0); |
|
2600 | 2600 | } |
2601 | - if ( array_key_exists( 'group_by', $query_params ) ) { |
|
2602 | - if ( is_array( $query_params['group_by'] ) ) { |
|
2601 | + if (array_key_exists('group_by', $query_params)) { |
|
2602 | + if (is_array($query_params['group_by'])) { |
|
2603 | 2603 | $this->_extract_related_models_from_sub_params_array_values( |
2604 | 2604 | $query_params['group_by'], |
2605 | 2605 | $query_info_carrier, |
2606 | 2606 | 'group_by' |
2607 | 2607 | ); |
2608 | - } elseif ( ! empty ( $query_params['group_by'] ) ) { |
|
2608 | + } elseif ( ! empty ($query_params['group_by'])) { |
|
2609 | 2609 | $this->_extract_related_model_info_from_query_param( |
2610 | 2610 | $query_params['group_by'], |
2611 | 2611 | $query_info_carrier, |
@@ -2613,21 +2613,21 @@ discard block |
||
2613 | 2613 | ); |
2614 | 2614 | } |
2615 | 2615 | } |
2616 | - if ( array_key_exists( 'having', $query_params ) ) { |
|
2616 | + if (array_key_exists('having', $query_params)) { |
|
2617 | 2617 | $this->_extract_related_models_from_sub_params_array_keys( |
2618 | 2618 | $query_params[0], |
2619 | 2619 | $query_info_carrier, |
2620 | 2620 | 'having' |
2621 | 2621 | ); |
2622 | 2622 | } |
2623 | - if ( array_key_exists( 'order_by', $query_params ) ) { |
|
2624 | - if ( is_array( $query_params['order_by'] ) ) { |
|
2623 | + if (array_key_exists('order_by', $query_params)) { |
|
2624 | + if (is_array($query_params['order_by'])) { |
|
2625 | 2625 | $this->_extract_related_models_from_sub_params_array_keys( |
2626 | 2626 | $query_params['order_by'], |
2627 | 2627 | $query_info_carrier, |
2628 | 2628 | 'order_by' |
2629 | 2629 | ); |
2630 | - } elseif ( ! empty( $query_params['order_by'] ) ) { |
|
2630 | + } elseif ( ! empty($query_params['order_by'])) { |
|
2631 | 2631 | $this->_extract_related_model_info_from_query_param( |
2632 | 2632 | $query_params['order_by'], |
2633 | 2633 | $query_info_carrier, |
@@ -2635,7 +2635,7 @@ discard block |
||
2635 | 2635 | ); |
2636 | 2636 | } |
2637 | 2637 | } |
2638 | - if ( array_key_exists( 'force_join', $query_params ) ) { |
|
2638 | + if (array_key_exists('force_join', $query_params)) { |
|
2639 | 2639 | $this->_extract_related_models_from_sub_params_array_values( |
2640 | 2640 | $query_params['force_join'], |
2641 | 2641 | $query_info_carrier, |
@@ -2653,34 +2653,34 @@ discard block |
||
2653 | 2653 | * @throws EE_Error |
2654 | 2654 | * @return \EE_Model_Query_Info_Carrier |
2655 | 2655 | */ |
2656 | - 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){ |
|
2657 | - if (!empty($sub_query_params)){ |
|
2656 | + 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) { |
|
2657 | + if ( ! empty($sub_query_params)) { |
|
2658 | 2658 | $sub_query_params = (array) $sub_query_params; |
2659 | - foreach($sub_query_params as $param => $possibly_array_of_params){ |
|
2659 | + foreach ($sub_query_params as $param => $possibly_array_of_params) { |
|
2660 | 2660 | //$param could be simply 'EVT_ID', or it could be 'Registrations.REG_ID', or even 'Registrations.Transactions.Payments.PAY_amount' |
2661 | - $this->_extract_related_model_info_from_query_param( $param, $model_query_info_carrier,$query_param_type); |
|
2661 | + $this->_extract_related_model_info_from_query_param($param, $model_query_info_carrier, $query_param_type); |
|
2662 | 2662 | |
2663 | 2663 | //if $possibly_array_of_params is an array, try recursing into it, searching for keys which |
2664 | 2664 | //indicate needed joins. Eg, array('NOT'=>array('Registration.TXN_ID'=>23)). In this case, we tried |
2665 | 2665 | //extracting models out of the 'NOT', which obviously wasn't successful, and then we recurse into the value |
2666 | 2666 | //of array('Registration.TXN_ID'=>23) |
2667 | 2667 | $query_param_sans_stars = $this->_remove_stars_and_anything_after_from_condition_query_param_key($param); |
2668 | - if(in_array($query_param_sans_stars, $this->_logic_query_param_keys,true)){ |
|
2669 | - if (! is_array($possibly_array_of_params)){ |
|
2668 | + if (in_array($query_param_sans_stars, $this->_logic_query_param_keys, true)) { |
|
2669 | + if ( ! is_array($possibly_array_of_params)) { |
|
2670 | 2670 | 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"), |
2671 | - $param,$possibly_array_of_params)); |
|
2672 | - }else{ |
|
2673 | - $this->_extract_related_models_from_sub_params_array_keys($possibly_array_of_params, $model_query_info_carrier,$query_param_type); |
|
2671 | + $param, $possibly_array_of_params)); |
|
2672 | + } else { |
|
2673 | + $this->_extract_related_models_from_sub_params_array_keys($possibly_array_of_params, $model_query_info_carrier, $query_param_type); |
|
2674 | 2674 | } |
2675 | - }elseif($query_param_type === 0 //ie WHERE |
|
2675 | + }elseif ($query_param_type === 0 //ie WHERE |
|
2676 | 2676 | && is_array($possibly_array_of_params) |
2677 | 2677 | && isset($possibly_array_of_params[2]) |
2678 | - && $possibly_array_of_params[2] == true){ |
|
2678 | + && $possibly_array_of_params[2] == true) { |
|
2679 | 2679 | //then $possible_array_of_params looks something like array('<','DTT_sold',true) |
2680 | 2680 | //indicating that $possible_array_of_params[1] is actually a field name, |
2681 | 2681 | //from which we should extract query parameters! |
2682 | - if( ! isset($possibly_array_of_params[0], $possibly_array_of_params[1] ) ) { |
|
2683 | - 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))); |
|
2682 | + if ( ! isset($possibly_array_of_params[0], $possibly_array_of_params[1])) { |
|
2683 | + 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))); |
|
2684 | 2684 | } |
2685 | 2685 | $this->_extract_related_model_info_from_query_param($possibly_array_of_params[1], $model_query_info_carrier, $query_param_type); |
2686 | 2686 | } |
@@ -2699,14 +2699,14 @@ discard block |
||
2699 | 2699 | * @throws EE_Error |
2700 | 2700 | * @return \EE_Model_Query_Info_Carrier |
2701 | 2701 | */ |
2702 | - 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){ |
|
2703 | - if (!empty($sub_query_params)){ |
|
2704 | - if(!is_array($sub_query_params)){ |
|
2705 | - throw new EE_Error(sprintf(__("Query parameter %s should be an array, but it isn't.", "event_espresso"),$sub_query_params)); |
|
2702 | + 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) { |
|
2703 | + if ( ! empty($sub_query_params)) { |
|
2704 | + if ( ! is_array($sub_query_params)) { |
|
2705 | + throw new EE_Error(sprintf(__("Query parameter %s should be an array, but it isn't.", "event_espresso"), $sub_query_params)); |
|
2706 | 2706 | } |
2707 | - foreach($sub_query_params as $param){ |
|
2707 | + foreach ($sub_query_params as $param) { |
|
2708 | 2708 | //$param could be simply 'EVT_ID', or it could be 'Registrations.REG_ID', or even 'Registrations.Transactions.Payments.PAY_amount' |
2709 | - $this->_extract_related_model_info_from_query_param( $param, $model_query_info_carrier, $query_param_type); |
|
2709 | + $this->_extract_related_model_info_from_query_param($param, $model_query_info_carrier, $query_param_type); |
|
2710 | 2710 | } |
2711 | 2711 | } |
2712 | 2712 | return $model_query_info_carrier; |
@@ -2725,8 +2725,8 @@ discard block |
||
2725 | 2725 | * @throws EE_Error |
2726 | 2726 | * @return EE_Model_Query_Info_Carrier |
2727 | 2727 | */ |
2728 | - public function _create_model_query_info_carrier($query_params){ |
|
2729 | - if ( ! is_array( $query_params ) ) { |
|
2728 | + public function _create_model_query_info_carrier($query_params) { |
|
2729 | + if ( ! is_array($query_params)) { |
|
2730 | 2730 | EE_Error::doing_it_wrong( |
2731 | 2731 | 'EEM_Base::_create_model_query_info_carrier', |
2732 | 2732 | sprintf( |
@@ -2734,16 +2734,16 @@ discard block |
||
2734 | 2734 | '$query_params should be an array, you passed a variable of type %s', |
2735 | 2735 | 'event_espresso' |
2736 | 2736 | ), |
2737 | - gettype( $query_params ) |
|
2737 | + gettype($query_params) |
|
2738 | 2738 | ), |
2739 | 2739 | '4.6.0' |
2740 | 2740 | ); |
2741 | 2741 | $query_params = array(); |
2742 | 2742 | } |
2743 | - $where_query_params = isset( $query_params[0] ) ? $query_params[0] : array(); |
|
2743 | + $where_query_params = isset($query_params[0]) ? $query_params[0] : array(); |
|
2744 | 2744 | //first check if we should alter the query to account for caps or not |
2745 | 2745 | //because the caps might require us to do extra joins |
2746 | - if ( isset( $query_params['caps'] ) && $query_params['caps'] !== 'none' ) { |
|
2746 | + if (isset($query_params['caps']) && $query_params['caps'] !== 'none') { |
|
2747 | 2747 | $query_params[0] = $where_query_params = array_replace_recursive( |
2748 | 2748 | $where_query_params, |
2749 | 2749 | $this->caps_where_conditions( |
@@ -2751,10 +2751,10 @@ discard block |
||
2751 | 2751 | ) |
2752 | 2752 | ); |
2753 | 2753 | } |
2754 | - $query_object = $this->_extract_related_models_from_query( $query_params ); |
|
2754 | + $query_object = $this->_extract_related_models_from_query($query_params); |
|
2755 | 2755 | //verify where_query_params has NO numeric indexes.... that's simply not how you use it! |
2756 | - foreach ( $where_query_params as $key => $value ) { |
|
2757 | - if ( is_int( $key ) ) { |
|
2756 | + foreach ($where_query_params as $key => $value) { |
|
2757 | + if (is_int($key)) { |
|
2758 | 2758 | throw new EE_Error( |
2759 | 2759 | sprintf( |
2760 | 2760 | __( |
@@ -2762,16 +2762,16 @@ discard block |
||
2762 | 2762 | "event_espresso" |
2763 | 2763 | ), |
2764 | 2764 | $key, |
2765 | - var_export( $value, true ), |
|
2766 | - var_export( $query_params, true ), |
|
2767 | - get_class( $this ) |
|
2765 | + var_export($value, true), |
|
2766 | + var_export($query_params, true), |
|
2767 | + get_class($this) |
|
2768 | 2768 | ) |
2769 | 2769 | ); |
2770 | 2770 | } |
2771 | 2771 | } |
2772 | 2772 | if ( |
2773 | - array_key_exists( 'default_where_conditions', $query_params ) |
|
2774 | - && ! empty( $query_params['default_where_conditions'] ) |
|
2773 | + array_key_exists('default_where_conditions', $query_params) |
|
2774 | + && ! empty($query_params['default_where_conditions']) |
|
2775 | 2775 | ) { |
2776 | 2776 | $use_default_where_conditions = $query_params['default_where_conditions']; |
2777 | 2777 | } else { |
@@ -2785,13 +2785,13 @@ discard block |
||
2785 | 2785 | ), |
2786 | 2786 | $where_query_params |
2787 | 2787 | ); |
2788 | - $query_object->set_where_sql( $this->_construct_where_clause( $where_query_params ) ); |
|
2788 | + $query_object->set_where_sql($this->_construct_where_clause($where_query_params)); |
|
2789 | 2789 | // if this is a "on_join_limit" then we are limiting on on a specific table in a multi_table join. |
2790 | 2790 | // So we need to setup a subquery and use that for the main join. |
2791 | 2791 | // Note for now this only works on the primary table for the model. |
2792 | 2792 | // So for instance, you could set the limit array like this: |
2793 | 2793 | // array( 'on_join_limit' => array('Primary_Table_Alias', array(1,10) ) ) |
2794 | - if ( array_key_exists( 'on_join_limit', $query_params ) && ! empty( $query_params['on_join_limit'] ) ) { |
|
2794 | + if (array_key_exists('on_join_limit', $query_params) && ! empty($query_params['on_join_limit'])) { |
|
2795 | 2795 | $query_object->set_main_model_join_sql( |
2796 | 2796 | $this->_construct_limit_join_select( |
2797 | 2797 | $query_params['on_join_limit'][0], |
@@ -2800,40 +2800,40 @@ discard block |
||
2800 | 2800 | ); |
2801 | 2801 | } |
2802 | 2802 | //set limit |
2803 | - if ( array_key_exists( 'limit', $query_params ) ) { |
|
2804 | - if ( is_array( $query_params['limit'] ) ) { |
|
2805 | - if ( ! isset( $query_params['limit'][0], $query_params['limit'][1] ) ) { |
|
2803 | + if (array_key_exists('limit', $query_params)) { |
|
2804 | + if (is_array($query_params['limit'])) { |
|
2805 | + if ( ! isset($query_params['limit'][0], $query_params['limit'][1])) { |
|
2806 | 2806 | $e = sprintf( |
2807 | 2807 | __( |
2808 | 2808 | "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)", |
2809 | 2809 | "event_espresso" |
2810 | 2810 | ), |
2811 | - http_build_query( $query_params['limit'] ) |
|
2811 | + http_build_query($query_params['limit']) |
|
2812 | 2812 | ); |
2813 | - throw new EE_Error( $e . "|" . $e ); |
|
2813 | + throw new EE_Error($e."|".$e); |
|
2814 | 2814 | } |
2815 | 2815 | //they passed us an array for the limit. Assume it's like array(50,25), meaning offset by 50, and get 25 |
2816 | - $query_object->set_limit_sql( " LIMIT " . $query_params['limit'][0] . "," . $query_params['limit'][1] ); |
|
2817 | - } elseif ( ! empty ( $query_params['limit'] ) ) { |
|
2818 | - $query_object->set_limit_sql( " LIMIT " . $query_params['limit'] ); |
|
2816 | + $query_object->set_limit_sql(" LIMIT ".$query_params['limit'][0].",".$query_params['limit'][1]); |
|
2817 | + } elseif ( ! empty ($query_params['limit'])) { |
|
2818 | + $query_object->set_limit_sql(" LIMIT ".$query_params['limit']); |
|
2819 | 2819 | } |
2820 | 2820 | } |
2821 | 2821 | //set order by |
2822 | - if ( array_key_exists( 'order_by', $query_params ) ) { |
|
2823 | - if ( is_array( $query_params['order_by'] ) ) { |
|
2822 | + if (array_key_exists('order_by', $query_params)) { |
|
2823 | + if (is_array($query_params['order_by'])) { |
|
2824 | 2824 | //if they're using 'order_by' as an array, they can't use 'order' (because 'order_by' must |
2825 | 2825 | //specify whether to ascend or descend on each field. Eg 'order_by'=>array('EVT_ID'=>'ASC'). So |
2826 | 2826 | //including 'order' wouldn't make any sense if 'order_by' has already specified which way to order! |
2827 | - if ( array_key_exists( 'order', $query_params ) ) { |
|
2827 | + if (array_key_exists('order', $query_params)) { |
|
2828 | 2828 | throw new EE_Error( |
2829 | 2829 | sprintf( |
2830 | 2830 | __( |
2831 | 2831 | "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 ", |
2832 | 2832 | "event_espresso" |
2833 | 2833 | ), |
2834 | - get_class( $this ), |
|
2835 | - implode( ", ", array_keys( $query_params['order_by'] ) ), |
|
2836 | - implode( ", ", $query_params['order_by'] ), |
|
2834 | + get_class($this), |
|
2835 | + implode(", ", array_keys($query_params['order_by'])), |
|
2836 | + implode(", ", $query_params['order_by']), |
|
2837 | 2837 | $query_params['order'] |
2838 | 2838 | ) |
2839 | 2839 | ); |
@@ -2845,57 +2845,57 @@ discard block |
||
2845 | 2845 | ); |
2846 | 2846 | //assume it's an array of fields to order by |
2847 | 2847 | $order_array = array(); |
2848 | - foreach ( $query_params['order_by'] as $field_name_to_order_by => $order ) { |
|
2849 | - $order = $this->_extract_order( $order ); |
|
2850 | - $order_array[] = $this->_deduce_column_name_from_query_param( $field_name_to_order_by ) . SP . $order; |
|
2848 | + foreach ($query_params['order_by'] as $field_name_to_order_by => $order) { |
|
2849 | + $order = $this->_extract_order($order); |
|
2850 | + $order_array[] = $this->_deduce_column_name_from_query_param($field_name_to_order_by).SP.$order; |
|
2851 | 2851 | } |
2852 | - $query_object->set_order_by_sql( " ORDER BY " . implode( ",", $order_array ) ); |
|
2853 | - } elseif ( ! empty ( $query_params['order_by'] ) ) { |
|
2852 | + $query_object->set_order_by_sql(" ORDER BY ".implode(",", $order_array)); |
|
2853 | + } elseif ( ! empty ($query_params['order_by'])) { |
|
2854 | 2854 | $this->_extract_related_model_info_from_query_param( |
2855 | 2855 | $query_params['order_by'], |
2856 | 2856 | $query_object, |
2857 | 2857 | 'order', |
2858 | 2858 | $query_params['order_by'] |
2859 | 2859 | ); |
2860 | - $order = isset( $query_params['order'] ) |
|
2861 | - ? $this->_extract_order( $query_params['order'] ) |
|
2860 | + $order = isset($query_params['order']) |
|
2861 | + ? $this->_extract_order($query_params['order']) |
|
2862 | 2862 | : 'DESC'; |
2863 | 2863 | $query_object->set_order_by_sql( |
2864 | - " ORDER BY " . $this->_deduce_column_name_from_query_param( $query_params['order_by'] ) . SP . $order |
|
2864 | + " ORDER BY ".$this->_deduce_column_name_from_query_param($query_params['order_by']).SP.$order |
|
2865 | 2865 | ); |
2866 | 2866 | } |
2867 | 2867 | } |
2868 | 2868 | //if 'order_by' wasn't set, maybe they are just using 'order' on its own? |
2869 | - if ( ! array_key_exists( 'order_by', $query_params ) |
|
2870 | - && array_key_exists( 'order', $query_params ) |
|
2871 | - && ! empty( $query_params['order'] ) |
|
2869 | + if ( ! array_key_exists('order_by', $query_params) |
|
2870 | + && array_key_exists('order', $query_params) |
|
2871 | + && ! empty($query_params['order']) |
|
2872 | 2872 | ) { |
2873 | 2873 | $pk_field = $this->get_primary_key_field(); |
2874 | - $order = $this->_extract_order( $query_params['order'] ); |
|
2875 | - $query_object->set_order_by_sql( " ORDER BY " . $pk_field->get_qualified_column() . SP . $order ); |
|
2874 | + $order = $this->_extract_order($query_params['order']); |
|
2875 | + $query_object->set_order_by_sql(" ORDER BY ".$pk_field->get_qualified_column().SP.$order); |
|
2876 | 2876 | } |
2877 | 2877 | //set group by |
2878 | - if ( array_key_exists( 'group_by', $query_params ) ) { |
|
2879 | - if ( is_array( $query_params['group_by'] ) ) { |
|
2878 | + if (array_key_exists('group_by', $query_params)) { |
|
2879 | + if (is_array($query_params['group_by'])) { |
|
2880 | 2880 | //it's an array, so assume we'll be grouping by a bunch of stuff |
2881 | 2881 | $group_by_array = array(); |
2882 | - foreach ( $query_params['group_by'] as $field_name_to_group_by ) { |
|
2883 | - $group_by_array[] = $this->_deduce_column_name_from_query_param( $field_name_to_group_by ); |
|
2882 | + foreach ($query_params['group_by'] as $field_name_to_group_by) { |
|
2883 | + $group_by_array[] = $this->_deduce_column_name_from_query_param($field_name_to_group_by); |
|
2884 | 2884 | } |
2885 | - $query_object->set_group_by_sql( " GROUP BY " . implode( ", ", $group_by_array ) ); |
|
2886 | - } elseif ( ! empty ( $query_params['group_by'] ) ) { |
|
2885 | + $query_object->set_group_by_sql(" GROUP BY ".implode(", ", $group_by_array)); |
|
2886 | + } elseif ( ! empty ($query_params['group_by'])) { |
|
2887 | 2887 | $query_object->set_group_by_sql( |
2888 | - " GROUP BY " . $this->_deduce_column_name_from_query_param( $query_params['group_by'] ) |
|
2888 | + " GROUP BY ".$this->_deduce_column_name_from_query_param($query_params['group_by']) |
|
2889 | 2889 | ); |
2890 | 2890 | } |
2891 | 2891 | } |
2892 | 2892 | //set having |
2893 | - if ( array_key_exists( 'having', $query_params ) && $query_params['having'] ) { |
|
2894 | - $query_object->set_having_sql( $this->_construct_having_clause( $query_params['having'] ) ); |
|
2893 | + if (array_key_exists('having', $query_params) && $query_params['having']) { |
|
2894 | + $query_object->set_having_sql($this->_construct_having_clause($query_params['having'])); |
|
2895 | 2895 | } |
2896 | 2896 | //now, just verify they didn't pass anything wack |
2897 | - foreach ( $query_params as $query_key => $query_value ) { |
|
2898 | - if ( ! in_array( $query_key, $this->_allowed_query_params, true ) ) { |
|
2897 | + foreach ($query_params as $query_key => $query_value) { |
|
2898 | + if ( ! in_array($query_key, $this->_allowed_query_params, true)) { |
|
2899 | 2899 | throw new EE_Error( |
2900 | 2900 | sprintf( |
2901 | 2901 | __( |
@@ -2903,16 +2903,16 @@ discard block |
||
2903 | 2903 | 'event_espresso' |
2904 | 2904 | ), |
2905 | 2905 | $query_key, |
2906 | - get_class( $this ), |
|
2906 | + get_class($this), |
|
2907 | 2907 | // print_r( $this->_allowed_query_params, TRUE ) |
2908 | - implode( ',', $this->_allowed_query_params ) |
|
2908 | + implode(',', $this->_allowed_query_params) |
|
2909 | 2909 | ) |
2910 | 2910 | ); |
2911 | 2911 | } |
2912 | 2912 | } |
2913 | 2913 | $main_model_join_sql = $query_object->get_main_model_join_sql(); |
2914 | - if ( empty( $main_model_join_sql ) ) { |
|
2915 | - $query_object->set_main_model_join_sql( $this->_construct_internal_join() ); |
|
2914 | + if (empty($main_model_join_sql)) { |
|
2915 | + $query_object->set_main_model_join_sql($this->_construct_internal_join()); |
|
2916 | 2916 | } |
2917 | 2917 | return $query_object; |
2918 | 2918 | } |
@@ -2927,17 +2927,17 @@ discard block |
||
2927 | 2927 | * @return array like EEM_Base::get_all() 's $query_params[0] |
2928 | 2928 | * @throws \EE_Error |
2929 | 2929 | */ |
2930 | - public function caps_where_conditions( $context = self::caps_read ) { |
|
2931 | - EEM_Base::verify_is_valid_cap_context( $context ); |
|
2930 | + public function caps_where_conditions($context = self::caps_read) { |
|
2931 | + EEM_Base::verify_is_valid_cap_context($context); |
|
2932 | 2932 | $cap_where_conditions = array(); |
2933 | - $cap_restrictions = $this->caps_missing( $context ); |
|
2933 | + $cap_restrictions = $this->caps_missing($context); |
|
2934 | 2934 | /** |
2935 | 2935 | * @var $cap_restrictions EE_Default_Where_Conditions[] |
2936 | 2936 | */ |
2937 | - foreach( $cap_restrictions as $cap => $restriction_if_no_cap ) { |
|
2938 | - $cap_where_conditions = array_replace_recursive( $cap_where_conditions, $restriction_if_no_cap->get_default_where_conditions() ); |
|
2937 | + foreach ($cap_restrictions as $cap => $restriction_if_no_cap) { |
|
2938 | + $cap_where_conditions = array_replace_recursive($cap_where_conditions, $restriction_if_no_cap->get_default_where_conditions()); |
|
2939 | 2939 | } |
2940 | - return apply_filters( 'FHEE__EEM_Base__caps_where_conditions__return', $cap_where_conditions, $this, $context, $cap_restrictions ); |
|
2940 | + return apply_filters('FHEE__EEM_Base__caps_where_conditions__return', $cap_where_conditions, $this, $context, $cap_restrictions); |
|
2941 | 2941 | } |
2942 | 2942 | |
2943 | 2943 | /** |
@@ -2947,11 +2947,11 @@ discard block |
||
2947 | 2947 | * @return string either ASC, asc, DESC or desc |
2948 | 2948 | * @throws EE_Error |
2949 | 2949 | */ |
2950 | - private function _extract_order($should_be_order_string){ |
|
2951 | - if(in_array($should_be_order_string, $this->_allowed_order_values)){ |
|
2950 | + private function _extract_order($should_be_order_string) { |
|
2951 | + if (in_array($should_be_order_string, $this->_allowed_order_values)) { |
|
2952 | 2952 | return $should_be_order_string; |
2953 | - }else{ |
|
2954 | - 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)); |
|
2953 | + } else { |
|
2954 | + 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)); |
|
2955 | 2955 | } |
2956 | 2956 | } |
2957 | 2957 | |
@@ -2969,7 +2969,7 @@ discard block |
||
2969 | 2969 | * @throws EE_Error |
2970 | 2970 | * @return array like $query_params[0], see EEM_Base::get_all for documentation |
2971 | 2971 | */ |
2972 | - 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()){ |
|
2972 | + 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()) { |
|
2973 | 2973 | $allowed_used_default_where_conditions_values = array( |
2974 | 2974 | 'all', |
2975 | 2975 | 'this_model_only', |
@@ -2977,17 +2977,17 @@ discard block |
||
2977 | 2977 | 'minimum', |
2978 | 2978 | 'none' |
2979 | 2979 | ); |
2980 | - if( ! in_array($use_default_where_conditions,$allowed_used_default_where_conditions_values)){ |
|
2981 | - 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))); |
|
2980 | + if ( ! in_array($use_default_where_conditions, $allowed_used_default_where_conditions_values)) { |
|
2981 | + 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))); |
|
2982 | 2982 | } |
2983 | 2983 | $universal_query_params = array(); |
2984 | - if( $use_default_where_conditions === 'all' || $use_default_where_conditions === 'this_model_only' ){ |
|
2984 | + if ($use_default_where_conditions === 'all' || $use_default_where_conditions === 'this_model_only') { |
|
2985 | 2985 | $universal_query_params = $this->_get_default_where_conditions(); |
2986 | - } else if( $use_default_where_conditions === 'minimum' ) { |
|
2986 | + } else if ($use_default_where_conditions === 'minimum') { |
|
2987 | 2987 | $universal_query_params = $this->_get_minimum_where_conditions(); |
2988 | 2988 | } |
2989 | - if(in_array($use_default_where_conditions,array('all','other_models_only'))){ |
|
2990 | - foreach($query_info_carrier->get_model_names_included() as $model_relation_path => $model_name){ |
|
2989 | + if (in_array($use_default_where_conditions, array('all', 'other_models_only'))) { |
|
2990 | + foreach ($query_info_carrier->get_model_names_included() as $model_relation_path => $model_name) { |
|
2991 | 2991 | $related_model = $this->get_related_model_obj($model_name); |
2992 | 2992 | $related_model_universal_where_params = $related_model->_get_default_where_conditions($model_relation_path); |
2993 | 2993 | $overrides = $this->_override_defaults_or_make_null_friendly( |
@@ -2996,8 +2996,8 @@ discard block |
||
2996 | 2996 | $related_model, |
2997 | 2997 | $model_relation_path |
2998 | 2998 | ); |
2999 | - foreach ( $overrides as $key => $value ) { |
|
3000 | - $universal_query_params[ $key ] = $value; |
|
2999 | + foreach ($overrides as $key => $value) { |
|
3000 | + $universal_query_params[$key] = $value; |
|
3001 | 3001 | } |
3002 | 3002 | } |
3003 | 3003 | } |
@@ -3019,20 +3019,20 @@ discard block |
||
3019 | 3019 | * @return array like EEM_Base::get_all's $query_params[0] |
3020 | 3020 | * @throws \EE_Error |
3021 | 3021 | */ |
3022 | - private function _override_defaults_or_make_null_friendly($default_where_conditions,$provided_where_conditions,$model,$model_relation_path){ |
|
3022 | + private function _override_defaults_or_make_null_friendly($default_where_conditions, $provided_where_conditions, $model, $model_relation_path) { |
|
3023 | 3023 | $null_friendly_where_conditions = array(); |
3024 | 3024 | $none_overridden = true; |
3025 | 3025 | $or_condition_key_for_defaults = 'OR*'.get_class($model); |
3026 | 3026 | |
3027 | - foreach($default_where_conditions as $key => $val){ |
|
3028 | - if( isset($provided_where_conditions[$key])){ |
|
3027 | + foreach ($default_where_conditions as $key => $val) { |
|
3028 | + if (isset($provided_where_conditions[$key])) { |
|
3029 | 3029 | $none_overridden = false; |
3030 | - }else{ |
|
3030 | + } else { |
|
3031 | 3031 | $null_friendly_where_conditions[$or_condition_key_for_defaults]['AND'][$key] = $val; |
3032 | 3032 | } |
3033 | 3033 | } |
3034 | - if( $none_overridden && $default_where_conditions){ |
|
3035 | - if($model->has_primary_key_field()){ |
|
3034 | + if ($none_overridden && $default_where_conditions) { |
|
3035 | + if ($model->has_primary_key_field()) { |
|
3036 | 3036 | $null_friendly_where_conditions[$or_condition_key_for_defaults][$model_relation_path.".".$model->primary_key_name()] = array('IS NULL'); |
3037 | 3037 | }/*else{ |
3038 | 3038 | //@todo NO PK, use other defaults |
@@ -3049,8 +3049,8 @@ discard block |
||
3049 | 3049 | * @param string $model_relation_path eg, path from Event to Payment is "Registration.Transaction.Payment." |
3050 | 3050 | * @return array like EEM_Base::get_all's $query_params[0] (where conditions) |
3051 | 3051 | */ |
3052 | - private function _get_default_where_conditions($model_relation_path = null){ |
|
3053 | - if ( $this->_ignore_where_strategy ){ |
|
3052 | + private function _get_default_where_conditions($model_relation_path = null) { |
|
3053 | + if ($this->_ignore_where_strategy) { |
|
3054 | 3054 | return array(); |
3055 | 3055 | } |
3056 | 3056 | return $this->_default_where_conditions_strategy->get_default_where_conditions($model_relation_path); |
@@ -3064,8 +3064,8 @@ discard block |
||
3064 | 3064 | * @param string $model_relation_path eg, path from Event to Payment is "Registration.Transaction.Payment." |
3065 | 3065 | * @return array like EEM_Base::get_all's $query_params[0] (where conditions) |
3066 | 3066 | */ |
3067 | - protected function _get_minimum_where_conditions($model_relation_path = null){ |
|
3068 | - if ( $this->_ignore_where_strategy ){ |
|
3067 | + protected function _get_minimum_where_conditions($model_relation_path = null) { |
|
3068 | + if ($this->_ignore_where_strategy) { |
|
3069 | 3069 | return array(); |
3070 | 3070 | } |
3071 | 3071 | return $this->_minimum_where_conditions_strategy->get_default_where_conditions($model_relation_path); |
@@ -3081,16 +3081,16 @@ discard block |
||
3081 | 3081 | * @return string |
3082 | 3082 | * @throws \EE_Error |
3083 | 3083 | */ |
3084 | - private function _construct_default_select_sql(EE_Model_Query_Info_Carrier $model_query_info){ |
|
3084 | + private function _construct_default_select_sql(EE_Model_Query_Info_Carrier $model_query_info) { |
|
3085 | 3085 | $selects = $this->_get_columns_to_select_for_this_model(); |
3086 | - foreach($model_query_info->get_model_names_included() as $model_relation_chain => $name_of_other_model_included){ |
|
3086 | + foreach ($model_query_info->get_model_names_included() as $model_relation_chain => $name_of_other_model_included) { |
|
3087 | 3087 | $other_model_included = $this->get_related_model_obj($name_of_other_model_included); |
3088 | - $other_model_selects = $other_model_included->_get_columns_to_select_for_this_model( $model_relation_chain ); |
|
3089 | - foreach ( $other_model_selects as $key => $value ) { |
|
3088 | + $other_model_selects = $other_model_included->_get_columns_to_select_for_this_model($model_relation_chain); |
|
3089 | + foreach ($other_model_selects as $key => $value) { |
|
3090 | 3090 | $selects[] = $value; |
3091 | 3091 | } |
3092 | 3092 | } |
3093 | - return implode(", ",$selects); |
|
3093 | + return implode(", ", $selects); |
|
3094 | 3094 | } |
3095 | 3095 | |
3096 | 3096 | /** |
@@ -3099,19 +3099,19 @@ discard block |
||
3099 | 3099 | * @param string $model_relation_chain like 'Question.Question_Group.Event' |
3100 | 3100 | * @return array numerically indexed, values are columns to select and rename, eg "Event.ID AS 'Event.ID'" |
3101 | 3101 | */ |
3102 | - public function _get_columns_to_select_for_this_model($model_relation_chain = ''){ |
|
3102 | + public function _get_columns_to_select_for_this_model($model_relation_chain = '') { |
|
3103 | 3103 | $fields = $this->field_settings(); |
3104 | 3104 | $selects = array(); |
3105 | 3105 | $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()); |
3106 | - foreach($fields as $field_obj){ |
|
3107 | - $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()."'"; |
|
3106 | + foreach ($fields as $field_obj) { |
|
3107 | + $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()."'"; |
|
3108 | 3108 | } |
3109 | 3109 | //make sure we are also getting the PKs of each table |
3110 | 3110 | $tables = $this->get_tables(); |
3111 | - if(count($tables) > 1){ |
|
3112 | - foreach($tables as $table_obj){ |
|
3113 | - $qualified_pk_column = $table_alias_with_model_relation_chain_prefix . $table_obj->get_fully_qualified_pk_column(); |
|
3114 | - if( ! in_array($qualified_pk_column,$selects)){ |
|
3111 | + if (count($tables) > 1) { |
|
3112 | + foreach ($tables as $table_obj) { |
|
3113 | + $qualified_pk_column = $table_alias_with_model_relation_chain_prefix.$table_obj->get_fully_qualified_pk_column(); |
|
3114 | + if ( ! in_array($qualified_pk_column, $selects)) { |
|
3115 | 3115 | $selects[] = "$qualified_pk_column AS '$qualified_pk_column'"; |
3116 | 3116 | } |
3117 | 3117 | } |
@@ -3141,65 +3141,65 @@ discard block |
||
3141 | 3141 | $query_param_type, |
3142 | 3142 | $original_query_param = null |
3143 | 3143 | ) { |
3144 | - if( $original_query_param === null ){ |
|
3144 | + if ($original_query_param === null) { |
|
3145 | 3145 | $original_query_param = $query_param; |
3146 | 3146 | } |
3147 | 3147 | $query_param = $this->_remove_stars_and_anything_after_from_condition_query_param_key($query_param); |
3148 | 3148 | /** @var $allow_logic_query_params bool whether or not to allow logic_query_params like 'NOT','OR', or 'AND' */ |
3149 | - $allow_logic_query_params = in_array($query_param_type,array('where','having')); |
|
3150 | - $allow_fields = in_array($query_param_type,array('where','having','order_by','group_by','order')); |
|
3149 | + $allow_logic_query_params = in_array($query_param_type, array('where', 'having')); |
|
3150 | + $allow_fields = in_array($query_param_type, array('where', 'having', 'order_by', 'group_by', 'order')); |
|
3151 | 3151 | //check to see if we have a field on this model |
3152 | 3152 | $this_model_fields = $this->field_settings(true); |
3153 | - if(array_key_exists($query_param,$this_model_fields)){ |
|
3154 | - if($allow_fields){ |
|
3153 | + if (array_key_exists($query_param, $this_model_fields)) { |
|
3154 | + if ($allow_fields) { |
|
3155 | 3155 | return; |
3156 | - }else{ |
|
3156 | + } else { |
|
3157 | 3157 | 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"), |
3158 | - $query_param,get_class($this),$query_param_type,$original_query_param)); |
|
3158 | + $query_param, get_class($this), $query_param_type, $original_query_param)); |
|
3159 | 3159 | } |
3160 | 3160 | } |
3161 | 3161 | //check if this is a special logic query param |
3162 | - elseif(in_array($query_param, $this->_logic_query_param_keys, TRUE)){ |
|
3163 | - if($allow_logic_query_params){ |
|
3162 | + elseif (in_array($query_param, $this->_logic_query_param_keys, TRUE)) { |
|
3163 | + if ($allow_logic_query_params) { |
|
3164 | 3164 | return; |
3165 | - }else{ |
|
3165 | + } else { |
|
3166 | 3166 | throw new EE_Error( |
3167 | 3167 | sprintf( |
3168 | - __( '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' ), |
|
3169 | - implode( '", "', $this->_logic_query_param_keys ), |
|
3170 | - $query_param , |
|
3171 | - get_class( $this ), |
|
3168 | + __('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'), |
|
3169 | + implode('", "', $this->_logic_query_param_keys), |
|
3170 | + $query_param, |
|
3171 | + get_class($this), |
|
3172 | 3172 | '<br />', |
3173 | - "\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 |
|
3173 | + "\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 |
|
3174 | 3174 | ) |
3175 | 3175 | ); |
3176 | 3176 | } |
3177 | 3177 | } |
3178 | 3178 | |
3179 | 3179 | //check if it's a custom selection |
3180 | - elseif(array_key_exists($query_param,$this->_custom_selections)){ |
|
3180 | + elseif (array_key_exists($query_param, $this->_custom_selections)) { |
|
3181 | 3181 | return; |
3182 | 3182 | } |
3183 | 3183 | |
3184 | 3184 | //check if has a model name at the beginning |
3185 | 3185 | //and |
3186 | 3186 | //check if it's a field on a related model |
3187 | - foreach($this->_model_relations as $valid_related_model_name=>$relation_obj){ |
|
3188 | - if(strpos($query_param, $valid_related_model_name.".") === 0){ |
|
3189 | - $this->_add_join_to_model($valid_related_model_name, $passed_in_query_info,$original_query_param); |
|
3187 | + foreach ($this->_model_relations as $valid_related_model_name=>$relation_obj) { |
|
3188 | + if (strpos($query_param, $valid_related_model_name.".") === 0) { |
|
3189 | + $this->_add_join_to_model($valid_related_model_name, $passed_in_query_info, $original_query_param); |
|
3190 | 3190 | $query_param = substr($query_param, strlen($valid_related_model_name.".")); |
3191 | - if($query_param === ''){ |
|
3191 | + if ($query_param === '') { |
|
3192 | 3192 | //nothing left to $query_param |
3193 | 3193 | //we should actually end in a field name, not a model like this! |
3194 | 3194 | throw new EE_Error(sprintf(__("Query param '%s' (of type %s on model %s) shouldn't end on a period (.) ", "event_espresso"), |
3195 | - $query_param,$query_param_type,get_class($this),$valid_related_model_name)); |
|
3196 | - }else{ |
|
3195 | + $query_param, $query_param_type, get_class($this), $valid_related_model_name)); |
|
3196 | + } else { |
|
3197 | 3197 | $related_model_obj = $this->get_related_model_obj($valid_related_model_name); |
3198 | 3198 | $related_model_obj->_extract_related_model_info_from_query_param($query_param, $passed_in_query_info, $query_param_type, $original_query_param); |
3199 | 3199 | return; |
3200 | 3200 | } |
3201 | - }elseif($query_param === $valid_related_model_name){ |
|
3202 | - $this->_add_join_to_model($valid_related_model_name, $passed_in_query_info,$original_query_param); |
|
3201 | + }elseif ($query_param === $valid_related_model_name) { |
|
3202 | + $this->_add_join_to_model($valid_related_model_name, $passed_in_query_info, $original_query_param); |
|
3203 | 3203 | return; |
3204 | 3204 | } |
3205 | 3205 | } |
@@ -3209,7 +3209,7 @@ discard block |
||
3209 | 3209 | //and we previously confirmed it wasn't a logic query param or field on the current model |
3210 | 3210 | //it's wack, that's what it is |
3211 | 3211 | 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"), |
3212 | - $query_param,get_class($this),$query_param_type,$original_query_param)); |
|
3212 | + $query_param, get_class($this), $query_param_type, $original_query_param)); |
|
3213 | 3213 | |
3214 | 3214 | } |
3215 | 3215 | |
@@ -3228,26 +3228,26 @@ discard block |
||
3228 | 3228 | * @return void |
3229 | 3229 | * @throws \EE_Error |
3230 | 3230 | */ |
3231 | - private function _add_join_to_model($model_name, EE_Model_Query_Info_Carrier $passed_in_query_info,$original_query_param){ |
|
3231 | + private function _add_join_to_model($model_name, EE_Model_Query_Info_Carrier $passed_in_query_info, $original_query_param) { |
|
3232 | 3232 | $relation_obj = $this->related_settings_for($model_name); |
3233 | 3233 | |
3234 | 3234 | $model_relation_chain = EE_Model_Parser::extract_model_relation_chain($model_name, $original_query_param); |
3235 | 3235 | //check if the relation is HABTM, because then we're essentially doing two joins |
3236 | 3236 | //If so, join first to the JOIN table, and add its data types, and then continue as normal |
3237 | - if($relation_obj instanceof EE_HABTM_Relation){ |
|
3237 | + if ($relation_obj instanceof EE_HABTM_Relation) { |
|
3238 | 3238 | $join_model_obj = $relation_obj->get_join_model(); |
3239 | 3239 | //replace the model specified with the join model for this relation chain, whi |
3240 | 3240 | $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); |
3241 | 3241 | $new_query_info = new EE_Model_Query_Info_Carrier( |
3242 | 3242 | array($relation_chain_to_join_model => $join_model_obj->get_this_model_name()), |
3243 | 3243 | $relation_obj->get_join_to_intermediate_model_statement($relation_chain_to_join_model)); |
3244 | - $passed_in_query_info->merge( $new_query_info ); |
|
3244 | + $passed_in_query_info->merge($new_query_info); |
|
3245 | 3245 | } |
3246 | 3246 | //now just join to the other table pointed to by the relation object, and add its data types |
3247 | 3247 | $new_query_info = new EE_Model_Query_Info_Carrier( |
3248 | 3248 | array($model_relation_chain=>$model_name), |
3249 | 3249 | $relation_obj->get_join_statement($model_relation_chain)); |
3250 | - $passed_in_query_info->merge( $new_query_info ); |
|
3250 | + $passed_in_query_info->merge($new_query_info); |
|
3251 | 3251 | } |
3252 | 3252 | |
3253 | 3253 | |
@@ -3259,11 +3259,11 @@ discard block |
||
3259 | 3259 | * @return string of SQL |
3260 | 3260 | * @throws \EE_Error |
3261 | 3261 | */ |
3262 | - private function _construct_where_clause($where_params){ |
|
3262 | + private function _construct_where_clause($where_params) { |
|
3263 | 3263 | $SQL = $this->_construct_condition_clause_recursive($where_params, ' AND '); |
3264 | - if($SQL){ |
|
3265 | - return " WHERE ". $SQL; |
|
3266 | - }else{ |
|
3264 | + if ($SQL) { |
|
3265 | + return " WHERE ".$SQL; |
|
3266 | + } else { |
|
3267 | 3267 | return ''; |
3268 | 3268 | } |
3269 | 3269 | } |
@@ -3278,11 +3278,11 @@ discard block |
||
3278 | 3278 | * @return string |
3279 | 3279 | * @throws \EE_Error |
3280 | 3280 | */ |
3281 | - private function _construct_having_clause($having_params){ |
|
3281 | + private function _construct_having_clause($having_params) { |
|
3282 | 3282 | $SQL = $this->_construct_condition_clause_recursive($having_params, ' AND '); |
3283 | - if($SQL){ |
|
3284 | - return " HAVING ". $SQL; |
|
3285 | - }else{ |
|
3283 | + if ($SQL) { |
|
3284 | + return " HAVING ".$SQL; |
|
3285 | + } else { |
|
3286 | 3286 | return ''; |
3287 | 3287 | } |
3288 | 3288 | |
@@ -3296,17 +3296,17 @@ discard block |
||
3296 | 3296 | * @return EE_Model_Field_Base |
3297 | 3297 | * @throws EE_Error |
3298 | 3298 | */ |
3299 | - protected function _get_field_on_model($field_name,$model_name){ |
|
3299 | + protected function _get_field_on_model($field_name, $model_name) { |
|
3300 | 3300 | $model_class = 'EEM_'.$model_name; |
3301 | 3301 | $model_filepath = $model_class.".model.php"; |
3302 | - EE_Registry::instance()->load_helper( 'File' ); |
|
3303 | - if ( is_readable($model_filepath)){ |
|
3302 | + EE_Registry::instance()->load_helper('File'); |
|
3303 | + if (is_readable($model_filepath)) { |
|
3304 | 3304 | require_once($model_filepath); |
3305 | - $model_instance=call_user_func($model_name."::instance"); |
|
3305 | + $model_instance = call_user_func($model_name."::instance"); |
|
3306 | 3306 | /* @var $model_instance EEM_Base */ |
3307 | 3307 | return $model_instance->field_settings_for($field_name); |
3308 | - }else{ |
|
3309 | - throw new EE_Error(sprintf(__('No model named %s exists, with classname %s and filepath %s','event_espresso'),$model_name,$model_class,$model_filepath)); |
|
3308 | + } else { |
|
3309 | + throw new EE_Error(sprintf(__('No model named %s exists, with classname %s and filepath %s', 'event_espresso'), $model_name, $model_class, $model_filepath)); |
|
3310 | 3310 | } |
3311 | 3311 | } |
3312 | 3312 | |
@@ -3319,41 +3319,41 @@ discard block |
||
3319 | 3319 | * @throws EE_Error |
3320 | 3320 | * @return string of SQL |
3321 | 3321 | */ |
3322 | - private function _construct_condition_clause_recursive($where_params, $glue = ' AND'){ |
|
3323 | - $where_clauses=array(); |
|
3324 | - foreach($where_params as $query_param => $op_and_value_or_sub_condition){ |
|
3325 | - $query_param = $this->_remove_stars_and_anything_after_from_condition_query_param_key($query_param);//str_replace("*",'',$query_param); |
|
3326 | - if(in_array($query_param,$this->_logic_query_param_keys)){ |
|
3327 | - switch($query_param){ |
|
3322 | + private function _construct_condition_clause_recursive($where_params, $glue = ' AND') { |
|
3323 | + $where_clauses = array(); |
|
3324 | + foreach ($where_params as $query_param => $op_and_value_or_sub_condition) { |
|
3325 | + $query_param = $this->_remove_stars_and_anything_after_from_condition_query_param_key($query_param); //str_replace("*",'',$query_param); |
|
3326 | + if (in_array($query_param, $this->_logic_query_param_keys)) { |
|
3327 | + switch ($query_param) { |
|
3328 | 3328 | case 'not': |
3329 | 3329 | case 'NOT': |
3330 | - $where_clauses[] = "! (". $this->_construct_condition_clause_recursive($op_and_value_or_sub_condition, $glue).")"; |
|
3330 | + $where_clauses[] = "! (".$this->_construct_condition_clause_recursive($op_and_value_or_sub_condition, $glue).")"; |
|
3331 | 3331 | break; |
3332 | 3332 | case 'and': |
3333 | 3333 | case 'AND': |
3334 | - $where_clauses[] = " (". $this->_construct_condition_clause_recursive($op_and_value_or_sub_condition, ' AND ') .")"; |
|
3334 | + $where_clauses[] = " (".$this->_construct_condition_clause_recursive($op_and_value_or_sub_condition, ' AND ').")"; |
|
3335 | 3335 | break; |
3336 | 3336 | case 'or': |
3337 | 3337 | case 'OR': |
3338 | - $where_clauses[] = " (". $this->_construct_condition_clause_recursive($op_and_value_or_sub_condition, ' OR ') .")"; |
|
3338 | + $where_clauses[] = " (".$this->_construct_condition_clause_recursive($op_and_value_or_sub_condition, ' OR ').")"; |
|
3339 | 3339 | break; |
3340 | 3340 | } |
3341 | - }else{ |
|
3341 | + } else { |
|
3342 | 3342 | $field_obj = $this->_deduce_field_from_query_param($query_param); |
3343 | 3343 | |
3344 | 3344 | //if it's not a normal field, maybe it's a custom selection? |
3345 | - if( ! $field_obj){ |
|
3346 | - if(isset( $this->_custom_selections[$query_param][1])){ |
|
3345 | + if ( ! $field_obj) { |
|
3346 | + if (isset($this->_custom_selections[$query_param][1])) { |
|
3347 | 3347 | $field_obj = $this->_custom_selections[$query_param][1]; |
3348 | - }else{ |
|
3349 | - throw new EE_Error(sprintf(__("%s is neither a valid model field name, nor a custom selection", "event_espresso"),$query_param)); |
|
3348 | + } else { |
|
3349 | + throw new EE_Error(sprintf(__("%s is neither a valid model field name, nor a custom selection", "event_espresso"), $query_param)); |
|
3350 | 3350 | } |
3351 | 3351 | } |
3352 | 3352 | $op_and_value_sql = $this->_construct_op_and_value($op_and_value_or_sub_condition, $field_obj); |
3353 | - $where_clauses[]=$this->_deduce_column_name_from_query_param($query_param).SP.$op_and_value_sql; |
|
3353 | + $where_clauses[] = $this->_deduce_column_name_from_query_param($query_param).SP.$op_and_value_sql; |
|
3354 | 3354 | } |
3355 | 3355 | } |
3356 | - return $where_clauses ? implode( $glue, $where_clauses ) : ''; |
|
3356 | + return $where_clauses ? implode($glue, $where_clauses) : ''; |
|
3357 | 3357 | } |
3358 | 3358 | |
3359 | 3359 | |
@@ -3364,18 +3364,18 @@ discard block |
||
3364 | 3364 | * @throws EE_Error |
3365 | 3365 | * @return string table alias and column name for SQL, eg "Transaction.TXN_ID" |
3366 | 3366 | */ |
3367 | - private function _deduce_column_name_from_query_param($query_param){ |
|
3367 | + private function _deduce_column_name_from_query_param($query_param) { |
|
3368 | 3368 | $field = $this->_deduce_field_from_query_param($query_param); |
3369 | 3369 | |
3370 | - if( $field ){ |
|
3371 | - $table_alias_prefix = EE_Model_Parser::extract_table_alias_model_relation_chain_from_query_param( $field->get_model_name(), $query_param ); |
|
3372 | - return $table_alias_prefix . $field->get_qualified_column(); |
|
3373 | - }elseif(array_key_exists($query_param,$this->_custom_selections)){ |
|
3370 | + if ($field) { |
|
3371 | + $table_alias_prefix = EE_Model_Parser::extract_table_alias_model_relation_chain_from_query_param($field->get_model_name(), $query_param); |
|
3372 | + return $table_alias_prefix.$field->get_qualified_column(); |
|
3373 | + }elseif (array_key_exists($query_param, $this->_custom_selections)) { |
|
3374 | 3374 | //maybe it's custom selection item? |
3375 | 3375 | //if so, just use it as the "column name" |
3376 | 3376 | return $query_param; |
3377 | - }else{ |
|
3378 | - 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))); |
|
3377 | + } else { |
|
3378 | + 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))); |
|
3379 | 3379 | } |
3380 | 3380 | } |
3381 | 3381 | |
@@ -3387,11 +3387,11 @@ discard block |
||
3387 | 3387 | * @param string $condition_query_param_key |
3388 | 3388 | * @return string |
3389 | 3389 | */ |
3390 | - private function _remove_stars_and_anything_after_from_condition_query_param_key($condition_query_param_key){ |
|
3390 | + private function _remove_stars_and_anything_after_from_condition_query_param_key($condition_query_param_key) { |
|
3391 | 3391 | $pos_of_star = strpos($condition_query_param_key, '*'); |
3392 | - if($pos_of_star === FALSE){ |
|
3392 | + if ($pos_of_star === FALSE) { |
|
3393 | 3393 | return $condition_query_param_key; |
3394 | - }else{ |
|
3394 | + } else { |
|
3395 | 3395 | $condition_query_param_sans_star = substr($condition_query_param_key, 0, $pos_of_star); |
3396 | 3396 | return $condition_query_param_sans_star; |
3397 | 3397 | } |
@@ -3406,12 +3406,12 @@ discard block |
||
3406 | 3406 | * @throws EE_Error |
3407 | 3407 | * @return string |
3408 | 3408 | */ |
3409 | - private function _construct_op_and_value($op_and_value, $field_obj){ |
|
3410 | - if ( is_array( $op_and_value ) ) { |
|
3411 | - $operator = isset( $op_and_value[0] ) ? $this->_prepare_operator_for_sql( $op_and_value[0] ) : null; |
|
3412 | - if ( ! $operator ) { |
|
3409 | + private function _construct_op_and_value($op_and_value, $field_obj) { |
|
3410 | + if (is_array($op_and_value)) { |
|
3411 | + $operator = isset($op_and_value[0]) ? $this->_prepare_operator_for_sql($op_and_value[0]) : null; |
|
3412 | + if ( ! $operator) { |
|
3413 | 3413 | $php_array_like_string = array(); |
3414 | - foreach ( $op_and_value as $key => $value ) { |
|
3414 | + foreach ($op_and_value as $key => $value) { |
|
3415 | 3415 | $php_array_like_string[] = "$key=>$value"; |
3416 | 3416 | } |
3417 | 3417 | throw new EE_Error( |
@@ -3420,27 +3420,27 @@ discard block |
||
3420 | 3420 | "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))", |
3421 | 3421 | "event_espresso" |
3422 | 3422 | ), |
3423 | - implode( ",", $php_array_like_string ) |
|
3423 | + implode(",", $php_array_like_string) |
|
3424 | 3424 | ) |
3425 | 3425 | ); |
3426 | 3426 | } |
3427 | - $value = isset( $op_and_value[1] ) ? $op_and_value[1] : null; |
|
3427 | + $value = isset($op_and_value[1]) ? $op_and_value[1] : null; |
|
3428 | 3428 | } else { |
3429 | 3429 | $operator = '='; |
3430 | 3430 | $value = $op_and_value; |
3431 | 3431 | } |
3432 | 3432 | //check to see if the value is actually another field |
3433 | - if ( is_array( $op_and_value ) && isset( $op_and_value[2] ) && $op_and_value[2] == true ) { |
|
3434 | - return $operator . SP . $this->_deduce_column_name_from_query_param( $value ); |
|
3435 | - } elseif ( in_array( $operator, $this->_in_style_operators ) && is_array( $value ) ) { |
|
3433 | + if (is_array($op_and_value) && isset($op_and_value[2]) && $op_and_value[2] == true) { |
|
3434 | + return $operator.SP.$this->_deduce_column_name_from_query_param($value); |
|
3435 | + } elseif (in_array($operator, $this->_in_style_operators) && is_array($value)) { |
|
3436 | 3436 | //in this case, the value should be an array, or at least a comma-separated list |
3437 | 3437 | //it will need to handle a little differently |
3438 | - $cleaned_value = $this->_construct_in_value( $value, $field_obj ); |
|
3438 | + $cleaned_value = $this->_construct_in_value($value, $field_obj); |
|
3439 | 3439 | //note: $cleaned_value has already been run through $wpdb->prepare() |
3440 | - return $operator . SP . $cleaned_value; |
|
3441 | - } elseif ( in_array( $operator, $this->_between_style_operators ) && is_array( $value ) ) { |
|
3440 | + return $operator.SP.$cleaned_value; |
|
3441 | + } elseif (in_array($operator, $this->_between_style_operators) && is_array($value)) { |
|
3442 | 3442 | //the value should be an array with count of two. |
3443 | - if ( count( $value ) !== 2 ) { |
|
3443 | + if (count($value) !== 2) { |
|
3444 | 3444 | throw new EE_Error( |
3445 | 3445 | sprintf( |
3446 | 3446 | __( |
@@ -3451,10 +3451,10 @@ discard block |
||
3451 | 3451 | ) |
3452 | 3452 | ); |
3453 | 3453 | } |
3454 | - $cleaned_value = $this->_construct_between_value( $value, $field_obj ); |
|
3455 | - return $operator . SP . $cleaned_value; |
|
3456 | - } elseif ( in_array( $operator, $this->_null_style_operators ) ) { |
|
3457 | - if ( $value !== null ) { |
|
3454 | + $cleaned_value = $this->_construct_between_value($value, $field_obj); |
|
3455 | + return $operator.SP.$cleaned_value; |
|
3456 | + } elseif (in_array($operator, $this->_null_style_operators)) { |
|
3457 | + if ($value !== null) { |
|
3458 | 3458 | throw new EE_Error( |
3459 | 3459 | sprintf( |
3460 | 3460 | __( |
@@ -3467,13 +3467,13 @@ discard block |
||
3467 | 3467 | ); |
3468 | 3468 | } |
3469 | 3469 | return $operator; |
3470 | - } elseif ( $operator === 'LIKE' && ! is_array( $value ) ) { |
|
3470 | + } elseif ($operator === 'LIKE' && ! is_array($value)) { |
|
3471 | 3471 | //if the operator is 'LIKE', we want to allow percent signs (%) and not |
3472 | 3472 | //remove other junk. So just treat it as a string. |
3473 | - return $operator . SP . $this->_wpdb_prepare_using_field( $value, '%s' ); |
|
3474 | - } elseif ( ! in_array( $operator, $this->_in_style_operators ) && ! is_array( $value ) ) { |
|
3475 | - return $operator . SP . $this->_wpdb_prepare_using_field( $value, $field_obj ); |
|
3476 | - } elseif ( in_array( $operator, $this->_in_style_operators ) && ! is_array( $value ) ) { |
|
3473 | + return $operator.SP.$this->_wpdb_prepare_using_field($value, '%s'); |
|
3474 | + } elseif ( ! in_array($operator, $this->_in_style_operators) && ! is_array($value)) { |
|
3475 | + return $operator.SP.$this->_wpdb_prepare_using_field($value, $field_obj); |
|
3476 | + } elseif (in_array($operator, $this->_in_style_operators) && ! is_array($value)) { |
|
3477 | 3477 | throw new EE_Error( |
3478 | 3478 | sprintf( |
3479 | 3479 | __( |
@@ -3484,7 +3484,7 @@ discard block |
||
3484 | 3484 | $operator |
3485 | 3485 | ) |
3486 | 3486 | ); |
3487 | - } elseif ( ! in_array( $operator, $this->_in_style_operators ) && is_array( $value ) ) { |
|
3487 | + } elseif ( ! in_array($operator, $this->_in_style_operators) && is_array($value)) { |
|
3488 | 3488 | throw new EE_Error( |
3489 | 3489 | sprintf( |
3490 | 3490 | __( |
@@ -3502,7 +3502,7 @@ discard block |
||
3502 | 3502 | "It appears you've provided some totally invalid query parameters. Operator and value were:'%s', which isn't right at all", |
3503 | 3503 | "event_espresso" |
3504 | 3504 | ), |
3505 | - http_build_query( $op_and_value ) |
|
3505 | + http_build_query($op_and_value) |
|
3506 | 3506 | ) |
3507 | 3507 | ); |
3508 | 3508 | } |
@@ -3518,12 +3518,12 @@ discard block |
||
3518 | 3518 | * @return string |
3519 | 3519 | * @throws \EE_Error |
3520 | 3520 | */ |
3521 | - public function _construct_between_value( $values, $field_obj ) { |
|
3521 | + public function _construct_between_value($values, $field_obj) { |
|
3522 | 3522 | $cleaned_values = array(); |
3523 | - foreach ( $values as $value ) { |
|
3524 | - $cleaned_values[] = $this->_wpdb_prepare_using_field($value,$field_obj); |
|
3523 | + foreach ($values as $value) { |
|
3524 | + $cleaned_values[] = $this->_wpdb_prepare_using_field($value, $field_obj); |
|
3525 | 3525 | } |
3526 | - return $cleaned_values[0] . " AND " . $cleaned_values[1]; |
|
3526 | + return $cleaned_values[0]." AND ".$cleaned_values[1]; |
|
3527 | 3527 | } |
3528 | 3528 | |
3529 | 3529 | |
@@ -3540,26 +3540,26 @@ discard block |
||
3540 | 3540 | * @return string of SQL to follow an 'IN' or 'NOT IN' operator |
3541 | 3541 | * @throws \EE_Error |
3542 | 3542 | */ |
3543 | - public function _construct_in_value($values, $field_obj){ |
|
3543 | + public function _construct_in_value($values, $field_obj) { |
|
3544 | 3544 | //check if the value is a CSV list |
3545 | - if(is_string($values)){ |
|
3545 | + if (is_string($values)) { |
|
3546 | 3546 | //in which case, turn it into an array |
3547 | - $values = explode(",",$values); |
|
3547 | + $values = explode(",", $values); |
|
3548 | 3548 | } |
3549 | 3549 | $cleaned_values = array(); |
3550 | - foreach($values as $value){ |
|
3551 | - $cleaned_values[] = $this->_wpdb_prepare_using_field($value,$field_obj); |
|
3550 | + foreach ($values as $value) { |
|
3551 | + $cleaned_values[] = $this->_wpdb_prepare_using_field($value, $field_obj); |
|
3552 | 3552 | } |
3553 | 3553 | //we would just LOVE to leave $cleaned_values as an empty array, and return the value as "()", |
3554 | 3554 | //but unfortunately that's invalid SQL. So instead we return a string which we KNOW will evaluate to be the empty set |
3555 | 3555 | //which is effectively equivalent to returning "()". We don't return "(0)" because that only works for auto-incrementing columns |
3556 | - if(empty($cleaned_values)){ |
|
3556 | + if (empty($cleaned_values)) { |
|
3557 | 3557 | $all_fields = $this->field_settings(); |
3558 | 3558 | $a_field = array_shift($all_fields); |
3559 | 3559 | $main_table = $this->_get_main_table(); |
3560 | 3560 | $cleaned_values[] = "SELECT ".$a_field->get_table_column()." FROM ".$main_table->get_table_name()." WHERE FALSE"; |
3561 | 3561 | } |
3562 | - return "(".implode(",",$cleaned_values).")"; |
|
3562 | + return "(".implode(",", $cleaned_values).")"; |
|
3563 | 3563 | } |
3564 | 3564 | |
3565 | 3565 | |
@@ -3571,16 +3571,16 @@ discard block |
||
3571 | 3571 | * @throws EE_Error |
3572 | 3572 | * @return false|null|string |
3573 | 3573 | */ |
3574 | - private function _wpdb_prepare_using_field($value,$field_obj){ |
|
3574 | + private function _wpdb_prepare_using_field($value, $field_obj) { |
|
3575 | 3575 | /** @type WPDB $wpdb */ |
3576 | 3576 | global $wpdb; |
3577 | - if($field_obj instanceof EE_Model_Field_Base){ |
|
3578 | - return $wpdb->prepare($field_obj->get_wpdb_data_type(),$this->_prepare_value_for_use_in_db($value, $field_obj)); |
|
3579 | - }else{//$field_obj should really just be a data type |
|
3580 | - if( ! in_array($field_obj,$this->_valid_wpdb_data_types)){ |
|
3581 | - 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))); |
|
3577 | + if ($field_obj instanceof EE_Model_Field_Base) { |
|
3578 | + return $wpdb->prepare($field_obj->get_wpdb_data_type(), $this->_prepare_value_for_use_in_db($value, $field_obj)); |
|
3579 | + } else {//$field_obj should really just be a data type |
|
3580 | + if ( ! in_array($field_obj, $this->_valid_wpdb_data_types)) { |
|
3581 | + 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))); |
|
3582 | 3582 | } |
3583 | - return $wpdb->prepare($field_obj,$value); |
|
3583 | + return $wpdb->prepare($field_obj, $value); |
|
3584 | 3584 | } |
3585 | 3585 | } |
3586 | 3586 | |
@@ -3592,27 +3592,27 @@ discard block |
||
3592 | 3592 | * @throws EE_Error |
3593 | 3593 | * @return EE_Model_Field_Base |
3594 | 3594 | */ |
3595 | - protected function _deduce_field_from_query_param($query_param_name){ |
|
3595 | + protected function _deduce_field_from_query_param($query_param_name) { |
|
3596 | 3596 | //ok, now proceed with deducing which part is the model's name, and which is the field's name |
3597 | 3597 | //which will help us find the database table and column |
3598 | 3598 | |
3599 | - $query_param_parts = explode(".",$query_param_name); |
|
3600 | - if(empty($query_param_parts)){ |
|
3601 | - 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)); |
|
3599 | + $query_param_parts = explode(".", $query_param_name); |
|
3600 | + if (empty($query_param_parts)) { |
|
3601 | + 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)); |
|
3602 | 3602 | } |
3603 | 3603 | $number_of_parts = count($query_param_parts); |
3604 | - $last_query_param_part = $query_param_parts[ count($query_param_parts) - 1 ]; |
|
3605 | - if($number_of_parts === 1){ |
|
3604 | + $last_query_param_part = $query_param_parts[count($query_param_parts) - 1]; |
|
3605 | + if ($number_of_parts === 1) { |
|
3606 | 3606 | $field_name = $last_query_param_part; |
3607 | 3607 | $model_obj = $this; |
3608 | - }else{// $number_of_parts >= 2 |
|
3608 | + } else {// $number_of_parts >= 2 |
|
3609 | 3609 | //the last part is the column name, and there are only 2parts. therefore... |
3610 | 3610 | $field_name = $last_query_param_part; |
3611 | - $model_obj = $this->get_related_model_obj( $query_param_parts[ $number_of_parts - 2 ]); |
|
3611 | + $model_obj = $this->get_related_model_obj($query_param_parts[$number_of_parts - 2]); |
|
3612 | 3612 | } |
3613 | - try{ |
|
3613 | + try { |
|
3614 | 3614 | return $model_obj->field_settings_for($field_name); |
3615 | - }catch(EE_Error $e){ |
|
3615 | + } catch (EE_Error $e) { |
|
3616 | 3616 | return null; |
3617 | 3617 | } |
3618 | 3618 | } |
@@ -3626,13 +3626,13 @@ discard block |
||
3626 | 3626 | * @throws EE_Error |
3627 | 3627 | * @return string |
3628 | 3628 | */ |
3629 | - public function _get_qualified_column_for_field($field_name){ |
|
3629 | + public function _get_qualified_column_for_field($field_name) { |
|
3630 | 3630 | $all_fields = $this->field_settings(); |
3631 | 3631 | $field = isset($all_fields[$field_name]) ? $all_fields[$field_name] : FALSE; |
3632 | - if($field){ |
|
3632 | + if ($field) { |
|
3633 | 3633 | return $field->get_qualified_column(); |
3634 | - }else{ |
|
3635 | - 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))); |
|
3634 | + } else { |
|
3635 | + 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))); |
|
3636 | 3636 | } |
3637 | 3637 | } |
3638 | 3638 | |
@@ -3646,17 +3646,17 @@ discard block |
||
3646 | 3646 | * @param mixed|string $limit The limit for this select |
3647 | 3647 | * @return string The final select join element for the query. |
3648 | 3648 | */ |
3649 | - public function _construct_limit_join_select( $table_alias, $limit ) { |
|
3649 | + public function _construct_limit_join_select($table_alias, $limit) { |
|
3650 | 3650 | $SQL = ''; |
3651 | - foreach ( $this->_tables as $table_obj ) { |
|
3652 | - if ( $table_obj instanceof EE_Primary_Table ) { |
|
3651 | + foreach ($this->_tables as $table_obj) { |
|
3652 | + if ($table_obj instanceof EE_Primary_Table) { |
|
3653 | 3653 | $SQL .= $table_alias === $table_obj->get_table_alias() |
3654 | - ? $table_obj->get_select_join_limit( $limit ) |
|
3655 | - : SP . $table_obj->get_table_name() . " AS " . $table_obj->get_table_alias() . SP; |
|
3656 | - } elseif ( $table_obj instanceof EE_Secondary_Table ) { |
|
3654 | + ? $table_obj->get_select_join_limit($limit) |
|
3655 | + : SP.$table_obj->get_table_name()." AS ".$table_obj->get_table_alias().SP; |
|
3656 | + } elseif ($table_obj instanceof EE_Secondary_Table) { |
|
3657 | 3657 | $SQL .= $table_alias === $table_obj->get_table_alias() |
3658 | - ? $table_obj->get_select_join_limit_join( $limit ) |
|
3659 | - : SP . $table_obj->get_join_sql( $table_alias ) . SP; |
|
3658 | + ? $table_obj->get_select_join_limit_join($limit) |
|
3659 | + : SP.$table_obj->get_join_sql($table_alias).SP; |
|
3660 | 3660 | } |
3661 | 3661 | } |
3662 | 3662 | return $SQL; |
@@ -3671,7 +3671,7 @@ discard block |
||
3671 | 3671 | * @return string SQL |
3672 | 3672 | * @throws \EE_Error |
3673 | 3673 | */ |
3674 | - public function _construct_internal_join(){ |
|
3674 | + public function _construct_internal_join() { |
|
3675 | 3675 | $SQL = $this->_get_main_table()->get_table_sql(); |
3676 | 3676 | $SQL .= $this->_construct_internal_join_to_table_with_alias($this->_get_main_table()->get_table_alias()); |
3677 | 3677 | return $SQL; |
@@ -3692,17 +3692,17 @@ discard block |
||
3692 | 3692 | * @param string $alias_prefixed table alias to join to (this table should already be in the FROM SQL clause) |
3693 | 3693 | * @return string |
3694 | 3694 | */ |
3695 | - public function _construct_internal_join_to_table_with_alias($alias_prefixed){ |
|
3695 | + public function _construct_internal_join_to_table_with_alias($alias_prefixed) { |
|
3696 | 3696 | $SQL = ''; |
3697 | 3697 | $alias_sans_prefix = EE_Model_Parser::remove_table_alias_model_relation_chain_prefix($alias_prefixed); |
3698 | - foreach($this->_tables as $table_obj){ |
|
3699 | - if($table_obj instanceof EE_Secondary_Table){//table is secondary table |
|
3700 | - if($alias_sans_prefix === $table_obj->get_table_alias()){ |
|
3698 | + foreach ($this->_tables as $table_obj) { |
|
3699 | + if ($table_obj instanceof EE_Secondary_Table) {//table is secondary table |
|
3700 | + if ($alias_sans_prefix === $table_obj->get_table_alias()) { |
|
3701 | 3701 | //so we're joining to this table, meaning the table is already in |
3702 | 3702 | //the FROM statement, BUT the primary table isn't. So we want |
3703 | 3703 | //to add the inverse join sql |
3704 | 3704 | $SQL .= $table_obj->get_inverse_join_sql($alias_prefixed); |
3705 | - }else{ |
|
3705 | + } else { |
|
3706 | 3706 | //just add a regular JOIN to this table from the primary table |
3707 | 3707 | $SQL .= $table_obj->get_join_sql($alias_prefixed); |
3708 | 3708 | } |
@@ -3716,9 +3716,9 @@ discard block |
||
3716 | 3716 | * 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) |
3717 | 3717 | * @return array |
3718 | 3718 | */ |
3719 | - public function _get_data_types(){ |
|
3719 | + public function _get_data_types() { |
|
3720 | 3720 | $data_types = array(); |
3721 | - foreach( $this->field_settings() as $field_obj){ |
|
3721 | + foreach ($this->field_settings() as $field_obj) { |
|
3722 | 3722 | //$data_types[$field_obj->get_table_column()] = $field_obj->get_wpdb_data_type(); |
3723 | 3723 | /** @var $field_obj EE_Model_Field_Base */ |
3724 | 3724 | $data_types[$field_obj->get_qualified_column()] = $field_obj->get_wpdb_data_type(); |
@@ -3734,10 +3734,10 @@ discard block |
||
3734 | 3734 | * @throws EE_Error |
3735 | 3735 | * @return EEM_Base |
3736 | 3736 | */ |
3737 | - public function get_related_model_obj($model_name){ |
|
3737 | + public function get_related_model_obj($model_name) { |
|
3738 | 3738 | $model_classname = "EEM_".$model_name; |
3739 | - if(!class_exists($model_classname)){ |
|
3740 | - 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)); |
|
3739 | + if ( ! class_exists($model_classname)) { |
|
3740 | + 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)); |
|
3741 | 3741 | } |
3742 | 3742 | return call_user_func($model_classname."::instance"); |
3743 | 3743 | } |
@@ -3747,7 +3747,7 @@ discard block |
||
3747 | 3747 | * Returns the array of EE_ModelRelations for this model. |
3748 | 3748 | * @return EE_Model_Relation_Base[] |
3749 | 3749 | */ |
3750 | - public function relation_settings(){ |
|
3750 | + public function relation_settings() { |
|
3751 | 3751 | return $this->_model_relations; |
3752 | 3752 | } |
3753 | 3753 | |
@@ -3757,10 +3757,10 @@ discard block |
||
3757 | 3757 | * (Eg, without an event, datetimes have little purpose.) |
3758 | 3758 | * @return EE_Belongs_To_Relation[] |
3759 | 3759 | */ |
3760 | - public function belongs_to_relations(){ |
|
3760 | + public function belongs_to_relations() { |
|
3761 | 3761 | $belongs_to_relations = array(); |
3762 | - foreach($this->relation_settings() as $model_name => $relation_obj){ |
|
3763 | - if($relation_obj instanceof EE_Belongs_To_Relation){ |
|
3762 | + foreach ($this->relation_settings() as $model_name => $relation_obj) { |
|
3763 | + if ($relation_obj instanceof EE_Belongs_To_Relation) { |
|
3764 | 3764 | $belongs_to_relations[$model_name] = $relation_obj; |
3765 | 3765 | } |
3766 | 3766 | } |
@@ -3775,15 +3775,15 @@ discard block |
||
3775 | 3775 | * @throws EE_Error |
3776 | 3776 | * @return EE_Model_Relation_Base |
3777 | 3777 | */ |
3778 | - public function related_settings_for($relation_name){ |
|
3779 | - $relatedModels=$this->relation_settings(); |
|
3780 | - if(!array_key_exists($relation_name,$relatedModels)){ |
|
3778 | + public function related_settings_for($relation_name) { |
|
3779 | + $relatedModels = $this->relation_settings(); |
|
3780 | + if ( ! array_key_exists($relation_name, $relatedModels)) { |
|
3781 | 3781 | throw new EE_Error( |
3782 | 3782 | sprintf( |
3783 | - __('Cannot get %s related to %s. There is no model relation of that type. There is, however, %s...','event_espresso'), |
|
3783 | + __('Cannot get %s related to %s. There is no model relation of that type. There is, however, %s...', 'event_espresso'), |
|
3784 | 3784 | $relation_name, |
3785 | 3785 | $this->_get_class_name(), |
3786 | - implode( ', ', array_keys( $relatedModels )) |
|
3786 | + implode(', ', array_keys($relatedModels)) |
|
3787 | 3787 | ) |
3788 | 3788 | ); |
3789 | 3789 | } |
@@ -3798,10 +3798,10 @@ discard block |
||
3798 | 3798 | * @throws EE_Error |
3799 | 3799 | * @return EE_Model_Field_Base |
3800 | 3800 | */ |
3801 | - public function field_settings_for($fieldName){ |
|
3802 | - $fieldSettings=$this->field_settings(true); |
|
3803 | - if( ! array_key_exists($fieldName,$fieldSettings)){ |
|
3804 | - throw new EE_Error(sprintf(__("There is no field/column '%s' on '%s'",'event_espresso'),$fieldName,get_class($this))); |
|
3801 | + public function field_settings_for($fieldName) { |
|
3802 | + $fieldSettings = $this->field_settings(true); |
|
3803 | + if ( ! array_key_exists($fieldName, $fieldSettings)) { |
|
3804 | + throw new EE_Error(sprintf(__("There is no field/column '%s' on '%s'", 'event_espresso'), $fieldName, get_class($this))); |
|
3805 | 3805 | } |
3806 | 3806 | return $fieldSettings[$fieldName]; |
3807 | 3807 | } |
@@ -3811,11 +3811,11 @@ discard block |
||
3811 | 3811 | * @param string $fieldName a key in the model's _field_settings array |
3812 | 3812 | * @return boolean |
3813 | 3813 | */ |
3814 | - public function has_field($fieldName){ |
|
3814 | + public function has_field($fieldName) { |
|
3815 | 3815 | $fieldSettings = $this->field_settings(true); |
3816 | - if( isset($fieldSettings[$fieldName])){ |
|
3816 | + if (isset($fieldSettings[$fieldName])) { |
|
3817 | 3817 | return true; |
3818 | - }else{ |
|
3818 | + } else { |
|
3819 | 3819 | return false; |
3820 | 3820 | } |
3821 | 3821 | } |
@@ -3825,11 +3825,11 @@ discard block |
||
3825 | 3825 | * @param string $relation_name possibly one of the keys in the relation_settings array |
3826 | 3826 | * @return boolean |
3827 | 3827 | */ |
3828 | - public function has_relation($relation_name){ |
|
3828 | + public function has_relation($relation_name) { |
|
3829 | 3829 | $relations = $this->relation_settings(); |
3830 | - if(isset($relations[$relation_name])){ |
|
3830 | + if (isset($relations[$relation_name])) { |
|
3831 | 3831 | return true; |
3832 | - }else{ |
|
3832 | + } else { |
|
3833 | 3833 | return false; |
3834 | 3834 | } |
3835 | 3835 | } |
@@ -3841,7 +3841,7 @@ discard block |
||
3841 | 3841 | * @param $field_obj |
3842 | 3842 | * @return EE_Model_Field_Base |
3843 | 3843 | */ |
3844 | - public function is_primary_key_field( $field_obj ){ |
|
3844 | + public function is_primary_key_field($field_obj) { |
|
3845 | 3845 | return $field_obj instanceof EE_Primary_Key_Field_Base ? TRUE : FALSE; |
3846 | 3846 | } |
3847 | 3847 | |
@@ -3853,16 +3853,16 @@ discard block |
||
3853 | 3853 | * @return EE_Model_Field_Base |
3854 | 3854 | * @throws EE_Error |
3855 | 3855 | */ |
3856 | - public function get_primary_key_field(){ |
|
3857 | - if( $this->_primary_key_field === NULL ){ |
|
3858 | - foreach( $this->field_settings( TRUE ) as $field_obj ){ |
|
3859 | - if( $this->is_primary_key_field( $field_obj )){ |
|
3856 | + public function get_primary_key_field() { |
|
3857 | + if ($this->_primary_key_field === NULL) { |
|
3858 | + foreach ($this->field_settings(TRUE) as $field_obj) { |
|
3859 | + if ($this->is_primary_key_field($field_obj)) { |
|
3860 | 3860 | $this->_primary_key_field = $field_obj; |
3861 | 3861 | break; |
3862 | 3862 | } |
3863 | 3863 | } |
3864 | - if( ! $this->_primary_key_field instanceof EE_Primary_Key_Field_Base ){ |
|
3865 | - throw new EE_Error(sprintf(__("There is no Primary Key defined on model %s",'event_espresso'),get_class($this))); |
|
3864 | + if ( ! $this->_primary_key_field instanceof EE_Primary_Key_Field_Base) { |
|
3865 | + throw new EE_Error(sprintf(__("There is no Primary Key defined on model %s", 'event_espresso'), get_class($this))); |
|
3866 | 3866 | } |
3867 | 3867 | } |
3868 | 3868 | return $this->_primary_key_field; |
@@ -3875,12 +3875,12 @@ discard block |
||
3875 | 3875 | * Internally does some caching. |
3876 | 3876 | * @return boolean |
3877 | 3877 | */ |
3878 | - public function has_primary_key_field(){ |
|
3879 | - if($this->_has_primary_key_field === null){ |
|
3880 | - try{ |
|
3878 | + public function has_primary_key_field() { |
|
3879 | + if ($this->_has_primary_key_field === null) { |
|
3880 | + try { |
|
3881 | 3881 | $this->get_primary_key_field(); |
3882 | 3882 | $this->_has_primary_key_field = true; |
3883 | - }catch(EE_Error $e){ |
|
3883 | + } catch (EE_Error $e) { |
|
3884 | 3884 | $this->_has_primary_key_field = false; |
3885 | 3885 | } |
3886 | 3886 | } |
@@ -3894,9 +3894,9 @@ discard block |
||
3894 | 3894 | * @param string $field_class_name class name of field that you want to find. Eg, EE_Datetime_Field, EE_Foreign_Key_Field, etc |
3895 | 3895 | * @return EE_Model_Field_Base or null if none is found |
3896 | 3896 | */ |
3897 | - public function get_a_field_of_type($field_class_name){ |
|
3898 | - foreach($this->field_settings() as $field){ |
|
3899 | - if( $field instanceof $field_class_name ){ |
|
3897 | + public function get_a_field_of_type($field_class_name) { |
|
3898 | + foreach ($this->field_settings() as $field) { |
|
3899 | + if ($field instanceof $field_class_name) { |
|
3900 | 3900 | return $field; |
3901 | 3901 | } |
3902 | 3902 | } |
@@ -3910,21 +3910,21 @@ discard block |
||
3910 | 3910 | * @return EE_Foreign_Key_Field_Base |
3911 | 3911 | * @throws EE_Error |
3912 | 3912 | */ |
3913 | - public function get_foreign_key_to($model_name){ |
|
3914 | - if( ! isset( $this->_cache_foreign_key_to_fields[ $model_name ] ) ){ |
|
3915 | - foreach($this->field_settings() as $field){ |
|
3916 | - if( |
|
3913 | + public function get_foreign_key_to($model_name) { |
|
3914 | + if ( ! isset($this->_cache_foreign_key_to_fields[$model_name])) { |
|
3915 | + foreach ($this->field_settings() as $field) { |
|
3916 | + if ( |
|
3917 | 3917 | $field instanceof EE_Foreign_Key_Field_Base |
3918 | - && in_array($model_name,$field->get_model_names_pointed_to() ) |
|
3918 | + && in_array($model_name, $field->get_model_names_pointed_to()) |
|
3919 | 3919 | ) { |
3920 | - $this->_cache_foreign_key_to_fields[ $model_name ] = $field; |
|
3920 | + $this->_cache_foreign_key_to_fields[$model_name] = $field; |
|
3921 | 3921 | } |
3922 | 3922 | } |
3923 | - if( ! isset( $this->_cache_foreign_key_to_fields[ $model_name ] ) ){ |
|
3924 | - 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))); |
|
3923 | + if ( ! isset($this->_cache_foreign_key_to_fields[$model_name])) { |
|
3924 | + 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))); |
|
3925 | 3925 | } |
3926 | 3926 | } |
3927 | - return $this->_cache_foreign_key_to_fields[ $model_name ]; |
|
3927 | + return $this->_cache_foreign_key_to_fields[$model_name]; |
|
3928 | 3928 | } |
3929 | 3929 | |
3930 | 3930 | |
@@ -3935,7 +3935,7 @@ discard block |
||
3935 | 3935 | * a table alias with a model chain prefix, like 'Venue__Event_Venue___Event_Meta'. Either one works |
3936 | 3936 | * @return EE_Table_Base |
3937 | 3937 | */ |
3938 | - public function get_table_for_alias($table_alias){ |
|
3938 | + public function get_table_for_alias($table_alias) { |
|
3939 | 3939 | $table_alias_sans_model_relation_chain_prefix = EE_Model_Parser::remove_table_alias_model_relation_chain_prefix($table_alias); |
3940 | 3940 | return $this->_tables[$table_alias_sans_model_relation_chain_prefix]->get_table_name(); |
3941 | 3941 | } |
@@ -3948,25 +3948,25 @@ discard block |
||
3948 | 3948 | * @param bool $include_db_only_fields flag indicating whether or not to include the db-only fields |
3949 | 3949 | * @return EE_Model_Field_Base[] where the keys are the field's name |
3950 | 3950 | */ |
3951 | - public function field_settings($include_db_only_fields = false){ |
|
3952 | - if( $include_db_only_fields ){ |
|
3953 | - if( $this->_cached_fields === NULL ){ |
|
3951 | + public function field_settings($include_db_only_fields = false) { |
|
3952 | + if ($include_db_only_fields) { |
|
3953 | + if ($this->_cached_fields === NULL) { |
|
3954 | 3954 | $this->_cached_fields = array(); |
3955 | - foreach($this->_fields as $fields_corresponding_to_table){ |
|
3956 | - foreach($fields_corresponding_to_table as $field_name => $field_obj){ |
|
3957 | - $this->_cached_fields[$field_name]=$field_obj; |
|
3955 | + foreach ($this->_fields as $fields_corresponding_to_table) { |
|
3956 | + foreach ($fields_corresponding_to_table as $field_name => $field_obj) { |
|
3957 | + $this->_cached_fields[$field_name] = $field_obj; |
|
3958 | 3958 | } |
3959 | 3959 | } |
3960 | 3960 | } |
3961 | 3961 | return $this->_cached_fields; |
3962 | - }else{ |
|
3963 | - if( $this->_cached_fields_non_db_only === NULL ){ |
|
3962 | + } else { |
|
3963 | + if ($this->_cached_fields_non_db_only === NULL) { |
|
3964 | 3964 | $this->_cached_fields_non_db_only = array(); |
3965 | - foreach($this->_fields as $fields_corresponding_to_table){ |
|
3966 | - foreach($fields_corresponding_to_table as $field_name => $field_obj){ |
|
3965 | + foreach ($this->_fields as $fields_corresponding_to_table) { |
|
3966 | + foreach ($fields_corresponding_to_table as $field_name => $field_obj) { |
|
3967 | 3967 | /** @var $field_obj EE_Model_Field_Base */ |
3968 | - if( ! $field_obj->is_db_only_field() ){ |
|
3969 | - $this->_cached_fields_non_db_only[$field_name]=$field_obj; |
|
3968 | + if ( ! $field_obj->is_db_only_field()) { |
|
3969 | + $this->_cached_fields_non_db_only[$field_name] = $field_obj; |
|
3970 | 3970 | } |
3971 | 3971 | } |
3972 | 3972 | } |
@@ -3985,60 +3985,60 @@ discard block |
||
3985 | 3985 | * @return \EE_Base_Class[] array keys are primary keys (if there is a primary key on the model. if not, numerically indexed) |
3986 | 3986 | * @throws \EE_Error |
3987 | 3987 | */ |
3988 | - protected function _create_objects( $rows = array() ) { |
|
3989 | - $array_of_objects=array(); |
|
3990 | - if(empty($rows)){ |
|
3988 | + protected function _create_objects($rows = array()) { |
|
3989 | + $array_of_objects = array(); |
|
3990 | + if (empty($rows)) { |
|
3991 | 3991 | return array(); |
3992 | 3992 | } |
3993 | 3993 | $count_if_model_has_no_primary_key = 0; |
3994 | 3994 | $has_primary_key = $this->has_primary_key_field(); |
3995 | 3995 | $primary_key_field = $has_primary_key ? $this->get_primary_key_field() : null; |
3996 | - foreach ( (array)$rows as $row ) { |
|
3997 | - if(empty($row)){ |
|
3996 | + foreach ((array) $rows as $row) { |
|
3997 | + if (empty($row)) { |
|
3998 | 3998 | //wp did its weird thing where it returns an array like array(0=>null), which is totally not helpful... |
3999 | 3999 | return array(); |
4000 | 4000 | } |
4001 | 4001 | //check if we've already set this object in the results array, |
4002 | 4002 | //in which case there's no need to process it further (again) |
4003 | - if( $has_primary_key ) { |
|
4003 | + if ($has_primary_key) { |
|
4004 | 4004 | $table_pk_value = $this->_get_column_value_with_table_alias_or_not( |
4005 | 4005 | $row, |
4006 | 4006 | $primary_key_field->get_qualified_column(), |
4007 | 4007 | $primary_key_field->get_table_column() |
4008 | 4008 | ); |
4009 | - if( $table_pk_value && isset( $array_of_objects[ $table_pk_value ] ) ) { |
|
4009 | + if ($table_pk_value && isset($array_of_objects[$table_pk_value])) { |
|
4010 | 4010 | continue; |
4011 | 4011 | } |
4012 | 4012 | } |
4013 | 4013 | $classInstance = $this->instantiate_class_from_array_or_object($row); |
4014 | - if( ! $classInstance ) { |
|
4014 | + if ( ! $classInstance) { |
|
4015 | 4015 | throw new EE_Error( |
4016 | 4016 | sprintf( |
4017 | - __( 'Could not create instance of class %s from row %s', 'event_espresso' ), |
|
4017 | + __('Could not create instance of class %s from row %s', 'event_espresso'), |
|
4018 | 4018 | $this->get_this_model_name(), |
4019 | - http_build_query( $row ) |
|
4019 | + http_build_query($row) |
|
4020 | 4020 | ) |
4021 | 4021 | ); |
4022 | 4022 | } |
4023 | 4023 | //set the timezone on the instantiated objects |
4024 | - $classInstance->set_timezone( $this->_timezone ); |
|
4024 | + $classInstance->set_timezone($this->_timezone); |
|
4025 | 4025 | //make sure if there is any timezone setting present that we set the timezone for the object |
4026 | 4026 | $key = $has_primary_key ? $classInstance->ID() : $count_if_model_has_no_primary_key++; |
4027 | - $array_of_objects[ $key ] = $classInstance; |
|
4027 | + $array_of_objects[$key] = $classInstance; |
|
4028 | 4028 | //also, for all the relations of type BelongsTo, see if we can cache |
4029 | 4029 | //those related models |
4030 | 4030 | //(we could do this for other relations too, but if there are conditions |
4031 | 4031 | //that filtered out some fo the results, then we'd be caching an incomplete set |
4032 | 4032 | //so it requires a little more thought than just caching them immediately...) |
4033 | - foreach($this->_model_relations as $modelName => $relation_obj){ |
|
4034 | - if( $relation_obj instanceof EE_Belongs_To_Relation){ |
|
4033 | + foreach ($this->_model_relations as $modelName => $relation_obj) { |
|
4034 | + if ($relation_obj instanceof EE_Belongs_To_Relation) { |
|
4035 | 4035 | //check if this model's INFO is present. If so, cache it on the model |
4036 | 4036 | $other_model = $relation_obj->get_other_model(); |
4037 | 4037 | $other_model_obj_maybe = $other_model->instantiate_class_from_array_or_object($row); |
4038 | 4038 | //if we managed to make a model object from the results, cache it on the main model object |
4039 | - if( $other_model_obj_maybe ){ |
|
4039 | + if ($other_model_obj_maybe) { |
|
4040 | 4040 | //set timezone on these other model objects if they are present |
4041 | - $other_model_obj_maybe->set_timezone( $this->_timezone ); |
|
4041 | + $other_model_obj_maybe->set_timezone($this->_timezone); |
|
4042 | 4042 | $classInstance->cache($modelName, $other_model_obj_maybe); |
4043 | 4043 | } |
4044 | 4044 | } |
@@ -4059,12 +4059,12 @@ discard block |
||
4059 | 4059 | |
4060 | 4060 | $this_model_fields_and_values = array(); |
4061 | 4061 | //setup the row using default values; |
4062 | - foreach ( $this->field_settings() as $field_name => $field_obj ) { |
|
4062 | + foreach ($this->field_settings() as $field_name => $field_obj) { |
|
4063 | 4063 | $this_model_fields_and_values[$field_name] = $field_obj->get_default_value(); |
4064 | 4064 | } |
4065 | 4065 | |
4066 | 4066 | $className = $this->_get_class_name(); |
4067 | - $classInstance = EE_Registry::instance()->load_class( $className, array( $this_model_fields_and_values ), FALSE, FALSE ); |
|
4067 | + $classInstance = EE_Registry::instance()->load_class($className, array($this_model_fields_and_values), FALSE, FALSE); |
|
4068 | 4068 | |
4069 | 4069 | return $classInstance; |
4070 | 4070 | } |
@@ -4077,45 +4077,45 @@ discard block |
||
4077 | 4077 | * @return EE_Base_Class |
4078 | 4078 | * @throws \EE_Error |
4079 | 4079 | */ |
4080 | - public function instantiate_class_from_array_or_object($cols_n_values){ |
|
4081 | - if( ! is_array( $cols_n_values ) && is_object( $cols_n_values )) { |
|
4082 | - $cols_n_values = get_object_vars( $cols_n_values ); |
|
4080 | + public function instantiate_class_from_array_or_object($cols_n_values) { |
|
4081 | + if ( ! is_array($cols_n_values) && is_object($cols_n_values)) { |
|
4082 | + $cols_n_values = get_object_vars($cols_n_values); |
|
4083 | 4083 | } |
4084 | 4084 | $primary_key = NULL; |
4085 | 4085 | //make sure the array only has keys that are fields/columns on this model |
4086 | - $this_model_fields_n_values = $this->_deduce_fields_n_values_from_cols_n_values( $cols_n_values ); |
|
4087 | - if( $this->has_primary_key_field() && isset( $this_model_fields_n_values[ $this->primary_key_name() ] ) ){ |
|
4088 | - $primary_key = $this_model_fields_n_values[ $this->primary_key_name() ]; |
|
4086 | + $this_model_fields_n_values = $this->_deduce_fields_n_values_from_cols_n_values($cols_n_values); |
|
4087 | + if ($this->has_primary_key_field() && isset($this_model_fields_n_values[$this->primary_key_name()])) { |
|
4088 | + $primary_key = $this_model_fields_n_values[$this->primary_key_name()]; |
|
4089 | 4089 | } |
4090 | - $className=$this->_get_class_name(); |
|
4090 | + $className = $this->_get_class_name(); |
|
4091 | 4091 | |
4092 | 4092 | //check we actually found results that we can use to build our model object |
4093 | 4093 | //if not, return null |
4094 | - if( $this->has_primary_key_field()){ |
|
4095 | - if(empty( $this_model_fields_n_values[$this->primary_key_name()] )){ |
|
4094 | + if ($this->has_primary_key_field()) { |
|
4095 | + if (empty($this_model_fields_n_values[$this->primary_key_name()])) { |
|
4096 | 4096 | return NULL; |
4097 | 4097 | } |
4098 | - }else if($this->unique_indexes()){ |
|
4098 | + } else if ($this->unique_indexes()) { |
|
4099 | 4099 | $first_column = reset($this_model_fields_n_values); |
4100 | - if(empty($first_column)){ |
|
4100 | + if (empty($first_column)) { |
|
4101 | 4101 | return NULL; |
4102 | 4102 | } |
4103 | 4103 | } |
4104 | 4104 | |
4105 | 4105 | // if there is no primary key or the object doesn't already exist in the entity map, then create a new instance |
4106 | - if ( $primary_key){ |
|
4107 | - $classInstance = $this->get_from_entity_map( $primary_key ); |
|
4108 | - if( ! $classInstance) { |
|
4109 | - $classInstance = EE_Registry::instance()->load_class( $className, array( $this_model_fields_n_values, $this->_timezone ), TRUE, FALSE ); |
|
4106 | + if ($primary_key) { |
|
4107 | + $classInstance = $this->get_from_entity_map($primary_key); |
|
4108 | + if ( ! $classInstance) { |
|
4109 | + $classInstance = EE_Registry::instance()->load_class($className, array($this_model_fields_n_values, $this->_timezone), TRUE, FALSE); |
|
4110 | 4110 | // add this new object to the entity map |
4111 | - $classInstance = $this->add_to_entity_map( $classInstance ); |
|
4111 | + $classInstance = $this->add_to_entity_map($classInstance); |
|
4112 | 4112 | } |
4113 | - }else{ |
|
4114 | - $classInstance = EE_Registry::instance()->load_class( $className, array( $this_model_fields_n_values, $this->_timezone ), TRUE, FALSE ); |
|
4113 | + } else { |
|
4114 | + $classInstance = EE_Registry::instance()->load_class($className, array($this_model_fields_n_values, $this->_timezone), TRUE, FALSE); |
|
4115 | 4115 | } |
4116 | 4116 | |
4117 | 4117 | //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. |
4118 | - $this->set_timezone( $classInstance->get_timezone() ); |
|
4118 | + $this->set_timezone($classInstance->get_timezone()); |
|
4119 | 4119 | return $classInstance; |
4120 | 4120 | } |
4121 | 4121 | /** |
@@ -4123,8 +4123,8 @@ discard block |
||
4123 | 4123 | * @param int|string $id the ID of the model object |
4124 | 4124 | * @return EE_Base_Class |
4125 | 4125 | */ |
4126 | - public function get_from_entity_map( $id ){ |
|
4127 | - return isset( $this->_entity_map[ $id ] ) ? $this->_entity_map[ $id ] : NULL; |
|
4126 | + public function get_from_entity_map($id) { |
|
4127 | + return isset($this->_entity_map[$id]) ? $this->_entity_map[$id] : NULL; |
|
4128 | 4128 | } |
4129 | 4129 | |
4130 | 4130 | |
@@ -4143,21 +4143,21 @@ discard block |
||
4143 | 4143 | * @throws EE_Error |
4144 | 4144 | * @return \EE_Base_Class |
4145 | 4145 | */ |
4146 | - public function add_to_entity_map( EE_Base_Class $object) { |
|
4146 | + public function add_to_entity_map(EE_Base_Class $object) { |
|
4147 | 4147 | $className = $this->_get_class_name(); |
4148 | - if( ! $object instanceof $className ){ |
|
4149 | - 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 ) ); |
|
4148 | + if ( ! $object instanceof $className) { |
|
4149 | + 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)); |
|
4150 | 4150 | } |
4151 | 4151 | /** @var $object EE_Base_Class */ |
4152 | - if ( ! $object->ID() ){ |
|
4153 | - throw new EE_Error(sprintf(__("You tried storing a model object with NO ID in the %s entity mapper.", "event_espresso"),get_class($this))); |
|
4152 | + if ( ! $object->ID()) { |
|
4153 | + throw new EE_Error(sprintf(__("You tried storing a model object with NO ID in the %s entity mapper.", "event_espresso"), get_class($this))); |
|
4154 | 4154 | } |
4155 | 4155 | // double check it's not already there |
4156 | - $classInstance = $this->get_from_entity_map( $object->ID() ); |
|
4157 | - if ( $classInstance ) { |
|
4156 | + $classInstance = $this->get_from_entity_map($object->ID()); |
|
4157 | + if ($classInstance) { |
|
4158 | 4158 | return $classInstance; |
4159 | 4159 | } else { |
4160 | - $this->_entity_map[ $object->ID() ] = $object; |
|
4160 | + $this->_entity_map[$object->ID()] = $object; |
|
4161 | 4161 | return $object; |
4162 | 4162 | } |
4163 | 4163 | } |
@@ -4170,8 +4170,8 @@ discard block |
||
4170 | 4170 | * @param array $cols_n_values |
4171 | 4171 | * @return array |
4172 | 4172 | */ |
4173 | - public function deduce_fields_n_values_from_cols_n_values( $cols_n_values ) { |
|
4174 | - return $this->_deduce_fields_n_values_from_cols_n_values( $cols_n_values ); |
|
4173 | + public function deduce_fields_n_values_from_cols_n_values($cols_n_values) { |
|
4174 | + return $this->_deduce_fields_n_values_from_cols_n_values($cols_n_values); |
|
4175 | 4175 | } |
4176 | 4176 | |
4177 | 4177 | |
@@ -4184,23 +4184,23 @@ discard block |
||
4184 | 4184 | * @param string $cols_n_values |
4185 | 4185 | * @return array |
4186 | 4186 | */ |
4187 | - protected function _deduce_fields_n_values_from_cols_n_values( $cols_n_values ){ |
|
4187 | + protected function _deduce_fields_n_values_from_cols_n_values($cols_n_values) { |
|
4188 | 4188 | $this_model_fields_n_values = array(); |
4189 | - foreach( $this->get_tables() as $table_alias => $table_obj ) { |
|
4190 | - $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() ); |
|
4189 | + foreach ($this->get_tables() as $table_alias => $table_obj) { |
|
4190 | + $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()); |
|
4191 | 4191 | //there is a primary key on this table and its not set. Use defaults for all its columns |
4192 | - if( $table_pk_value === null && $table_obj->get_pk_column() ){ |
|
4193 | - foreach( $this->_get_fields_for_table( $table_alias ) as $field_name => $field_obj ) { |
|
4194 | - if( ! $field_obj->is_db_only_field() ){ |
|
4192 | + if ($table_pk_value === null && $table_obj->get_pk_column()) { |
|
4193 | + foreach ($this->_get_fields_for_table($table_alias) as $field_name => $field_obj) { |
|
4194 | + if ( ! $field_obj->is_db_only_field()) { |
|
4195 | 4195 | //prepare field as if its coming from db |
4196 | - $prepared_value = $field_obj->prepare_for_set( $field_obj->get_default_value() ); |
|
4197 | - $this_model_fields_n_values[$field_name] = $field_obj->prepare_for_use_in_db( $prepared_value ); |
|
4196 | + $prepared_value = $field_obj->prepare_for_set($field_obj->get_default_value()); |
|
4197 | + $this_model_fields_n_values[$field_name] = $field_obj->prepare_for_use_in_db($prepared_value); |
|
4198 | 4198 | } |
4199 | 4199 | } |
4200 | - }else{ |
|
4200 | + } else { |
|
4201 | 4201 | //the table's rows existed. Use their values |
4202 | - foreach( $this->_get_fields_for_table( $table_alias ) as $field_name => $field_obj ) { |
|
4203 | - if( ! $field_obj->is_db_only_field() ){ |
|
4202 | + foreach ($this->_get_fields_for_table($table_alias) as $field_name => $field_obj) { |
|
4203 | + if ( ! $field_obj->is_db_only_field()) { |
|
4204 | 4204 | $this_model_fields_n_values[$field_name] = $this->_get_column_value_with_table_alias_or_not( |
4205 | 4205 | $cols_n_values, $field_obj->get_qualified_column(), |
4206 | 4206 | $field_obj->get_table_column() |
@@ -4220,15 +4220,15 @@ discard block |
||
4220 | 4220 | * @param $regular_column |
4221 | 4221 | * @return null |
4222 | 4222 | */ |
4223 | - protected function _get_column_value_with_table_alias_or_not( $cols_n_values, $qualified_column, $regular_column ){ |
|
4223 | + protected function _get_column_value_with_table_alias_or_not($cols_n_values, $qualified_column, $regular_column) { |
|
4224 | 4224 | $value = null; |
4225 | 4225 | //ask the field what it think it's table_name.column_name should be, and call it the "qualified column" |
4226 | 4226 | //does the field on the model relate to this column retrieved from the db? |
4227 | 4227 | //or is it a db-only field? (not relating to the model) |
4228 | - if( isset( $cols_n_values[ $qualified_column ] ) ){ |
|
4229 | - $value = $cols_n_values[ $qualified_column ]; |
|
4230 | - }elseif( isset( $cols_n_values[ $regular_column ] ) ){ |
|
4231 | - $value = $cols_n_values[ $regular_column ]; |
|
4228 | + if (isset($cols_n_values[$qualified_column])) { |
|
4229 | + $value = $cols_n_values[$qualified_column]; |
|
4230 | + }elseif (isset($cols_n_values[$regular_column])) { |
|
4231 | + $value = $cols_n_values[$regular_column]; |
|
4232 | 4232 | } |
4233 | 4233 | return $value; |
4234 | 4234 | } |
@@ -4244,25 +4244,25 @@ discard block |
||
4244 | 4244 | * @return EE_Base_Class |
4245 | 4245 | * @throws \EE_Error |
4246 | 4246 | */ |
4247 | - public function refresh_entity_map_from_db( $id ){ |
|
4248 | - $obj_in_map = $this->get_from_entity_map( $id ); |
|
4249 | - if( $obj_in_map ){ |
|
4247 | + public function refresh_entity_map_from_db($id) { |
|
4248 | + $obj_in_map = $this->get_from_entity_map($id); |
|
4249 | + if ($obj_in_map) { |
|
4250 | 4250 | $wpdb_results = $this->_get_all_wpdb_results( |
4251 | - array( array( $this->get_primary_key_field()->get_name() => $id ), 'limit' => 1 ) |
|
4251 | + array(array($this->get_primary_key_field()->get_name() => $id), 'limit' => 1) |
|
4252 | 4252 | ); |
4253 | - if( $wpdb_results && is_array( $wpdb_results ) ){ |
|
4254 | - $one_row = reset( $wpdb_results ); |
|
4255 | - foreach( $this->_deduce_fields_n_values_from_cols_n_values($one_row ) as $field_name => $db_value ) { |
|
4256 | - $obj_in_map->set_from_db( $field_name, $db_value ); |
|
4253 | + if ($wpdb_results && is_array($wpdb_results)) { |
|
4254 | + $one_row = reset($wpdb_results); |
|
4255 | + foreach ($this->_deduce_fields_n_values_from_cols_n_values($one_row) as $field_name => $db_value) { |
|
4256 | + $obj_in_map->set_from_db($field_name, $db_value); |
|
4257 | 4257 | } |
4258 | 4258 | //clear the cache of related model objects |
4259 | - foreach ( $this->relation_settings() as $relation_name => $relation_obj ){ |
|
4260 | - $obj_in_map->clear_cache($relation_name, NULL, TRUE ); |
|
4259 | + foreach ($this->relation_settings() as $relation_name => $relation_obj) { |
|
4260 | + $obj_in_map->clear_cache($relation_name, NULL, TRUE); |
|
4261 | 4261 | } |
4262 | 4262 | } |
4263 | 4263 | return $obj_in_map; |
4264 | - }else{ |
|
4265 | - return $this->get_one_by_ID( $id ); |
|
4264 | + } else { |
|
4265 | + return $this->get_one_by_ID($id); |
|
4266 | 4266 | } |
4267 | 4267 | } |
4268 | 4268 | |
@@ -4280,24 +4280,24 @@ discard block |
||
4280 | 4280 | * @return \EE_Base_Class |
4281 | 4281 | * @throws \EE_Error |
4282 | 4282 | */ |
4283 | - public function refresh_entity_map_with( $id, $replacing_model_obj ) { |
|
4284 | - $obj_in_map = $this->get_from_entity_map( $id ); |
|
4285 | - if( $obj_in_map ){ |
|
4286 | - if( $replacing_model_obj instanceof EE_Base_Class ){ |
|
4287 | - foreach( $replacing_model_obj->model_field_array() as $field_name => $value ) { |
|
4288 | - $obj_in_map->set( $field_name, $value ); |
|
4283 | + public function refresh_entity_map_with($id, $replacing_model_obj) { |
|
4284 | + $obj_in_map = $this->get_from_entity_map($id); |
|
4285 | + if ($obj_in_map) { |
|
4286 | + if ($replacing_model_obj instanceof EE_Base_Class) { |
|
4287 | + foreach ($replacing_model_obj->model_field_array() as $field_name => $value) { |
|
4288 | + $obj_in_map->set($field_name, $value); |
|
4289 | 4289 | } |
4290 | 4290 | //make the model object in the entity map's cache match the $replacing_model_obj |
4291 | - foreach ( $this->relation_settings() as $relation_name => $relation_obj ){ |
|
4292 | - $obj_in_map->clear_cache($relation_name, NULL, TRUE ); |
|
4293 | - foreach( $replacing_model_obj->get_all_from_cache( $relation_name ) as $cache_id => $cached_obj ) { |
|
4294 | - $obj_in_map->cache( $relation_name, $cached_obj, $cache_id ); |
|
4291 | + foreach ($this->relation_settings() as $relation_name => $relation_obj) { |
|
4292 | + $obj_in_map->clear_cache($relation_name, NULL, TRUE); |
|
4293 | + foreach ($replacing_model_obj->get_all_from_cache($relation_name) as $cache_id => $cached_obj) { |
|
4294 | + $obj_in_map->cache($relation_name, $cached_obj, $cache_id); |
|
4295 | 4295 | } |
4296 | 4296 | } |
4297 | 4297 | } |
4298 | 4298 | return $obj_in_map; |
4299 | - }else{ |
|
4300 | - $this->add_to_entity_map( $replacing_model_obj ); |
|
4299 | + } else { |
|
4300 | + $this->add_to_entity_map($replacing_model_obj); |
|
4301 | 4301 | return $replacing_model_obj; |
4302 | 4302 | } |
4303 | 4303 | } |
@@ -4310,7 +4310,7 @@ discard block |
||
4310 | 4310 | * require_once($this->_getClassName().".class.php"); |
4311 | 4311 | * @return string |
4312 | 4312 | */ |
4313 | - private function _get_class_name(){ |
|
4313 | + private function _get_class_name() { |
|
4314 | 4314 | return "EE_".$this->get_this_model_name(); |
4315 | 4315 | } |
4316 | 4316 | |
@@ -4323,8 +4323,8 @@ discard block |
||
4323 | 4323 | * @param int $quantity |
4324 | 4324 | * @return string |
4325 | 4325 | */ |
4326 | - public function item_name($quantity = 1){ |
|
4327 | - return (int)$quantity === 1 ? $this->singular_item : $this->plural_item; |
|
4326 | + public function item_name($quantity = 1) { |
|
4327 | + return (int) $quantity === 1 ? $this->singular_item : $this->plural_item; |
|
4328 | 4328 | } |
4329 | 4329 | |
4330 | 4330 | |
@@ -4351,13 +4351,13 @@ discard block |
||
4351 | 4351 | * @throws EE_Error |
4352 | 4352 | * @return mixed whatever the plugin which calls add_filter decides |
4353 | 4353 | */ |
4354 | - public function __call($methodName,$args){ |
|
4355 | - $className=get_class($this); |
|
4356 | - $tagName="FHEE__{$className}__{$methodName}"; |
|
4357 | - if(!has_filter($tagName)){ |
|
4354 | + public function __call($methodName, $args) { |
|
4355 | + $className = get_class($this); |
|
4356 | + $tagName = "FHEE__{$className}__{$methodName}"; |
|
4357 | + if ( ! has_filter($tagName)) { |
|
4358 | 4358 | throw new EE_Error( |
4359 | 4359 | sprintf( |
4360 | - __( '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' ), |
|
4360 | + __('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'), |
|
4361 | 4361 | $methodName, |
4362 | 4362 | $className, |
4363 | 4363 | $tagName, |
@@ -4366,7 +4366,7 @@ discard block |
||
4366 | 4366 | ); |
4367 | 4367 | } |
4368 | 4368 | |
4369 | - return apply_filters($tagName,null,$this,$args); |
|
4369 | + return apply_filters($tagName, null, $this, $args); |
|
4370 | 4370 | } |
4371 | 4371 | |
4372 | 4372 | |
@@ -4384,34 +4384,34 @@ discard block |
||
4384 | 4384 | * @throws EE_Error |
4385 | 4385 | * @return EE_Base_Class |
4386 | 4386 | */ |
4387 | - public function ensure_is_obj( $base_class_obj_or_id, $ensure_is_in_db = FALSE ){ |
|
4387 | + public function ensure_is_obj($base_class_obj_or_id, $ensure_is_in_db = FALSE) { |
|
4388 | 4388 | $className = $this->_get_class_name(); |
4389 | 4389 | $primary_key_field = $this->get_primary_key_field(); |
4390 | - if( $base_class_obj_or_id instanceof $className ){ |
|
4390 | + if ($base_class_obj_or_id instanceof $className) { |
|
4391 | 4391 | $model_object = $base_class_obj_or_id; |
4392 | - }elseif( |
|
4392 | + }elseif ( |
|
4393 | 4393 | $primary_key_field instanceof EE_Primary_Key_Int_Field |
4394 | 4394 | && ( |
4395 | - is_int( $base_class_obj_or_id ) |
|
4396 | - || is_string( $base_class_obj_or_id ) |
|
4395 | + is_int($base_class_obj_or_id) |
|
4396 | + || is_string($base_class_obj_or_id) |
|
4397 | 4397 | ) |
4398 | - ){ |
|
4398 | + ) { |
|
4399 | 4399 | //assume it's an ID. either a proper integer or a string representing an integer (eg "101" instead of 101) |
4400 | - $model_object = $this->get_one_by_ID( $base_class_obj_or_id ); |
|
4401 | - } else if( $primary_key_field instanceof EE_Primary_Key_String_Field && is_string( $base_class_obj_or_id ) ){ |
|
4400 | + $model_object = $this->get_one_by_ID($base_class_obj_or_id); |
|
4401 | + } else if ($primary_key_field instanceof EE_Primary_Key_String_Field && is_string($base_class_obj_or_id)) { |
|
4402 | 4402 | // assume its a string representation of the object |
4403 | - $model_object = $this->get_one_by_ID( $base_class_obj_or_id ); |
|
4404 | - }else{ |
|
4403 | + $model_object = $this->get_one_by_ID($base_class_obj_or_id); |
|
4404 | + } else { |
|
4405 | 4405 | throw new EE_Error( |
4406 | 4406 | sprintf( |
4407 | - __( "'%s' is neither an object of type %s, nor an ID! Its full value is '%s'", 'event_espresso' ), |
|
4407 | + __("'%s' is neither an object of type %s, nor an ID! Its full value is '%s'", 'event_espresso'), |
|
4408 | 4408 | $base_class_obj_or_id, |
4409 | 4409 | $this->_get_class_name(), |
4410 | - print_r($base_class_obj_or_id,true) |
|
4410 | + print_r($base_class_obj_or_id, true) |
|
4411 | 4411 | ) |
4412 | 4412 | ); |
4413 | 4413 | } |
4414 | - if( $ensure_is_in_db && $model_object->ID() !== null ){ |
|
4414 | + if ($ensure_is_in_db && $model_object->ID() !== null) { |
|
4415 | 4415 | $model_object->save(); |
4416 | 4416 | } |
4417 | 4417 | return $model_object; |
@@ -4427,19 +4427,19 @@ discard block |
||
4427 | 4427 | * @return int|string depending on the type of this model object's ID |
4428 | 4428 | * @throws EE_Error |
4429 | 4429 | */ |
4430 | - public function ensure_is_ID($base_class_obj_or_id){ |
|
4430 | + public function ensure_is_ID($base_class_obj_or_id) { |
|
4431 | 4431 | $className = $this->_get_class_name(); |
4432 | - if( $base_class_obj_or_id instanceof $className ){ |
|
4432 | + if ($base_class_obj_or_id instanceof $className) { |
|
4433 | 4433 | /** @var $base_class_obj_or_id EE_Base_Class */ |
4434 | 4434 | $id = $base_class_obj_or_id->ID(); |
4435 | - }elseif(is_int($base_class_obj_or_id)){ |
|
4435 | + }elseif (is_int($base_class_obj_or_id)) { |
|
4436 | 4436 | //assume it's an ID |
4437 | 4437 | $id = $base_class_obj_or_id; |
4438 | - }elseif(is_string($base_class_obj_or_id)){ |
|
4438 | + }elseif (is_string($base_class_obj_or_id)) { |
|
4439 | 4439 | //assume its a string representation of the object |
4440 | 4440 | $id = $base_class_obj_or_id; |
4441 | - }else{ |
|
4442 | - 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))); |
|
4441 | + } else { |
|
4442 | + 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))); |
|
4443 | 4443 | } |
4444 | 4444 | return $id; |
4445 | 4445 | } |
@@ -4462,14 +4462,14 @@ discard block |
||
4462 | 4462 | * @param int $values_already_prepared like one of the constants on EEM_Base |
4463 | 4463 | * @return void |
4464 | 4464 | */ |
4465 | - public function assume_values_already_prepared_by_model_object($values_already_prepared = self::not_prepared_by_model_object){ |
|
4465 | + public function assume_values_already_prepared_by_model_object($values_already_prepared = self::not_prepared_by_model_object) { |
|
4466 | 4466 | $this->_values_already_prepared_by_model_object = $values_already_prepared; |
4467 | 4467 | } |
4468 | 4468 | /** |
4469 | 4469 | * Read comments for assume_values_already_prepared_by_model_object() |
4470 | 4470 | * @return int |
4471 | 4471 | */ |
4472 | - public function get_assumption_concerning_values_already_prepared_by_model_object(){ |
|
4472 | + public function get_assumption_concerning_values_already_prepared_by_model_object() { |
|
4473 | 4473 | return $this->_values_already_prepared_by_model_object; |
4474 | 4474 | } |
4475 | 4475 | |
@@ -4477,17 +4477,17 @@ discard block |
||
4477 | 4477 | * Gets all the indexes on this model |
4478 | 4478 | * @return EE_Index[] |
4479 | 4479 | */ |
4480 | - public function indexes(){ |
|
4480 | + public function indexes() { |
|
4481 | 4481 | return $this->_indexes; |
4482 | 4482 | } |
4483 | 4483 | /** |
4484 | 4484 | * Gets all the Unique Indexes on this model |
4485 | 4485 | * @return EE_Unique_Index[] |
4486 | 4486 | */ |
4487 | - public function unique_indexes(){ |
|
4487 | + public function unique_indexes() { |
|
4488 | 4488 | $unique_indexes = array(); |
4489 | - foreach($this->_indexes as $name => $index){ |
|
4490 | - if($index instanceof EE_Unique_Index){ |
|
4489 | + foreach ($this->_indexes as $name => $index) { |
|
4490 | + if ($index instanceof EE_Unique_Index) { |
|
4491 | 4491 | $unique_indexes [$name] = $index; |
4492 | 4492 | } |
4493 | 4493 | } |
@@ -4505,9 +4505,9 @@ discard block |
||
4505 | 4505 | * @return EE_Model_Field_Base[] |
4506 | 4506 | * @throws \EE_Error |
4507 | 4507 | */ |
4508 | - public function get_combined_primary_key_fields(){ |
|
4509 | - foreach($this->indexes() as $index){ |
|
4510 | - if($index instanceof EE_Primary_Key_Index){ |
|
4508 | + public function get_combined_primary_key_fields() { |
|
4509 | + foreach ($this->indexes() as $index) { |
|
4510 | + if ($index instanceof EE_Primary_Key_Index) { |
|
4511 | 4511 | return $index->fields(); |
4512 | 4512 | } |
4513 | 4513 | } |
@@ -4524,7 +4524,7 @@ discard block |
||
4524 | 4524 | * @return string |
4525 | 4525 | * @throws \EE_Error |
4526 | 4526 | */ |
4527 | - public function get_index_primary_key_string($cols_n_values){ |
|
4527 | + public function get_index_primary_key_string($cols_n_values) { |
|
4528 | 4528 | $cols_n_values_for_primary_key_index = array_intersect_key($cols_n_values, $this->get_combined_primary_key_fields()); |
4529 | 4529 | return http_build_query($cols_n_values_for_primary_key_index); |
4530 | 4530 | } |
@@ -4539,13 +4539,13 @@ discard block |
||
4539 | 4539 | * @return null|array |
4540 | 4540 | * @throws \EE_Error |
4541 | 4541 | */ |
4542 | - public function parse_index_primary_key_string( $index_primary_key_string) { |
|
4542 | + public function parse_index_primary_key_string($index_primary_key_string) { |
|
4543 | 4543 | $key_fields = $this->get_combined_primary_key_fields(); |
4544 | 4544 | //check all of them are in the $id |
4545 | 4545 | $key_vals_in_combined_pk = array(); |
4546 | - parse_str( $index_primary_key_string, $key_vals_in_combined_pk ); |
|
4547 | - foreach( $key_fields as $key_field_name => $field_obj ) { |
|
4548 | - if( ! isset( $key_vals_in_combined_pk[ $key_field_name ] ) ){ |
|
4546 | + parse_str($index_primary_key_string, $key_vals_in_combined_pk); |
|
4547 | + foreach ($key_fields as $key_field_name => $field_obj) { |
|
4548 | + if ( ! isset($key_vals_in_combined_pk[$key_field_name])) { |
|
4549 | 4549 | return NULL; |
4550 | 4550 | } |
4551 | 4551 | } |
@@ -4562,10 +4562,10 @@ discard block |
||
4562 | 4562 | * @return boolean |
4563 | 4563 | * @throws \EE_Error |
4564 | 4564 | */ |
4565 | - public function has_all_combined_primary_key_fields( $key_vals ) { |
|
4566 | - $keys_it_should_have = array_keys( $this->get_combined_primary_key_fields() ); |
|
4567 | - foreach( $keys_it_should_have as $key ){ |
|
4568 | - if( ! isset( $key_vals[ $key ] ) ){ |
|
4565 | + public function has_all_combined_primary_key_fields($key_vals) { |
|
4566 | + $keys_it_should_have = array_keys($this->get_combined_primary_key_fields()); |
|
4567 | + foreach ($keys_it_should_have as $key) { |
|
4568 | + if ( ! isset($key_vals[$key])) { |
|
4569 | 4569 | return false; |
4570 | 4570 | } |
4571 | 4571 | } |
@@ -4581,23 +4581,23 @@ discard block |
||
4581 | 4581 | * @throws EE_Error |
4582 | 4582 | * @return \EE_Base_Class[] Array keys are object IDs (if there is a primary key on the model. if not, numerically indexed) |
4583 | 4583 | */ |
4584 | - public function get_all_copies($model_object_or_attributes_array, $query_params = array()){ |
|
4584 | + public function get_all_copies($model_object_or_attributes_array, $query_params = array()) { |
|
4585 | 4585 | |
4586 | - if($model_object_or_attributes_array instanceof EE_Base_Class){ |
|
4586 | + if ($model_object_or_attributes_array instanceof EE_Base_Class) { |
|
4587 | 4587 | $attributes_array = $model_object_or_attributes_array->model_field_array(); |
4588 | - }elseif(is_array($model_object_or_attributes_array)){ |
|
4588 | + }elseif (is_array($model_object_or_attributes_array)) { |
|
4589 | 4589 | $attributes_array = $model_object_or_attributes_array; |
4590 | - }else{ |
|
4591 | - 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)); |
|
4590 | + } else { |
|
4591 | + 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)); |
|
4592 | 4592 | } |
4593 | 4593 | //even copies obviously won't have the same ID, so remove the primary key |
4594 | 4594 | //from the WHERE conditions for finding copies (if there is a primary key, of course) |
4595 | - if($this->has_primary_key_field() && isset($attributes_array[$this->primary_key_name()])){ |
|
4595 | + if ($this->has_primary_key_field() && isset($attributes_array[$this->primary_key_name()])) { |
|
4596 | 4596 | unset($attributes_array[$this->primary_key_name()]); |
4597 | 4597 | } |
4598 | - if(isset($query_params[0])){ |
|
4599 | - $query_params[0] = array_merge($attributes_array,$query_params); |
|
4600 | - }else{ |
|
4598 | + if (isset($query_params[0])) { |
|
4599 | + $query_params[0] = array_merge($attributes_array, $query_params); |
|
4600 | + } else { |
|
4601 | 4601 | $query_params[0] = $attributes_array; |
4602 | 4602 | } |
4603 | 4603 | return $this->get_all($query_params); |
@@ -4613,16 +4613,16 @@ discard block |
||
4613 | 4613 | * @return EE_Base_Class |
4614 | 4614 | * @throws \EE_Error |
4615 | 4615 | */ |
4616 | - public function get_one_copy($model_object_or_attributes_array,$query_params = array()){ |
|
4617 | - if( ! is_array( $query_params ) ){ |
|
4618 | - 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' ); |
|
4616 | + public function get_one_copy($model_object_or_attributes_array, $query_params = array()) { |
|
4617 | + if ( ! is_array($query_params)) { |
|
4618 | + 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'); |
|
4619 | 4619 | $query_params = array(); |
4620 | 4620 | } |
4621 | 4621 | $query_params['limit'] = 1; |
4622 | - $copies = $this->get_all_copies($model_object_or_attributes_array,$query_params); |
|
4623 | - if(is_array($copies)){ |
|
4622 | + $copies = $this->get_all_copies($model_object_or_attributes_array, $query_params); |
|
4623 | + if (is_array($copies)) { |
|
4624 | 4624 | return array_shift($copies); |
4625 | - }else{ |
|
4625 | + } else { |
|
4626 | 4626 | return null; |
4627 | 4627 | } |
4628 | 4628 | } |
@@ -4638,10 +4638,10 @@ discard block |
||
4638 | 4638 | * @return int number of rows updated |
4639 | 4639 | * @throws \EE_Error |
4640 | 4640 | */ |
4641 | - public function update_by_ID($fields_n_values,$id){ |
|
4641 | + public function update_by_ID($fields_n_values, $id) { |
|
4642 | 4642 | $query_params = array(0=>array($this->get_primary_key_field()->get_name() => $id), |
4643 | 4643 | 'default_where_conditions'=>'other_models_only',); |
4644 | - return $this->update($fields_n_values,$query_params); |
|
4644 | + return $this->update($fields_n_values, $query_params); |
|
4645 | 4645 | } |
4646 | 4646 | |
4647 | 4647 | |
@@ -4652,12 +4652,12 @@ discard block |
||
4652 | 4652 | * @return string an operator which can be used in SQL |
4653 | 4653 | * @throws EE_Error |
4654 | 4654 | */ |
4655 | - private function _prepare_operator_for_sql($operator_supplied){ |
|
4655 | + private function _prepare_operator_for_sql($operator_supplied) { |
|
4656 | 4656 | $sql_operator = isset($this->_valid_operators[$operator_supplied]) ? $this->_valid_operators[$operator_supplied] : null; |
4657 | - if($sql_operator){ |
|
4657 | + if ($sql_operator) { |
|
4658 | 4658 | return $sql_operator; |
4659 | - }else{ |
|
4660 | - 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)))); |
|
4659 | + } else { |
|
4660 | + 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)))); |
|
4661 | 4661 | } |
4662 | 4662 | } |
4663 | 4663 | |
@@ -4671,10 +4671,10 @@ discard block |
||
4671 | 4671 | * @return string[] |
4672 | 4672 | * @throws \EE_Error |
4673 | 4673 | */ |
4674 | - public function get_all_names($query_params = array()){ |
|
4674 | + public function get_all_names($query_params = array()) { |
|
4675 | 4675 | $objs = $this->get_all($query_params); |
4676 | 4676 | $names = array(); |
4677 | - foreach($objs as $obj){ |
|
4677 | + foreach ($objs as $obj) { |
|
4678 | 4678 | $names[$obj->ID()] = $obj->name(); |
4679 | 4679 | } |
4680 | 4680 | return $names; |
@@ -4693,11 +4693,11 @@ discard block |
||
4693 | 4693 | * @return array |
4694 | 4694 | * @throws \EE_Error |
4695 | 4695 | */ |
4696 | - public function get_IDs( $model_objects, $filter_out_empty_ids = false) { |
|
4697 | - if( ! $this->has_primary_key_field() ) { |
|
4698 | - if( WP_DEBUG ) { |
|
4696 | + public function get_IDs($model_objects, $filter_out_empty_ids = false) { |
|
4697 | + if ( ! $this->has_primary_key_field()) { |
|
4698 | + if (WP_DEBUG) { |
|
4699 | 4699 | EE_Error::add_error( |
4700 | - __( 'Trying to get IDs from a model than has no primary key', 'event_espresso' ), |
|
4700 | + __('Trying to get IDs from a model than has no primary key', 'event_espresso'), |
|
4701 | 4701 | __FILE__, |
4702 | 4702 | __FUNCTION__, |
4703 | 4703 | __LINE__ |
@@ -4705,13 +4705,13 @@ discard block |
||
4705 | 4705 | } |
4706 | 4706 | } |
4707 | 4707 | $IDs = array(); |
4708 | - foreach( $model_objects as $model_object ) { |
|
4708 | + foreach ($model_objects as $model_object) { |
|
4709 | 4709 | $id = $model_object->ID(); |
4710 | - if( ! $id ) { |
|
4711 | - if( $filter_out_empty_ids ) { |
|
4710 | + if ( ! $id) { |
|
4711 | + if ($filter_out_empty_ids) { |
|
4712 | 4712 | continue; |
4713 | 4713 | } |
4714 | - if ( WP_DEBUG ) { |
|
4714 | + if (WP_DEBUG) { |
|
4715 | 4715 | EE_Error::add_error( |
4716 | 4716 | __( |
4717 | 4717 | 'Called %1$s on a model object that has no ID and so probably hasn\'t been saved to the database', |
@@ -4733,8 +4733,8 @@ discard block |
||
4733 | 4733 | * are no capabilities that relate to this model returns false |
4734 | 4734 | * @return string|false |
4735 | 4735 | */ |
4736 | - public function cap_slug(){ |
|
4737 | - return apply_filters( 'FHEE__EEM_Base__cap_slug', $this->_caps_slug, $this); |
|
4736 | + public function cap_slug() { |
|
4737 | + return apply_filters('FHEE__EEM_Base__cap_slug', $this->_caps_slug, $this); |
|
4738 | 4738 | } |
4739 | 4739 | |
4740 | 4740 | |
@@ -4749,34 +4749,34 @@ discard block |
||
4749 | 4749 | * @return EE_Default_Where_Conditions[] indexed by associated capability |
4750 | 4750 | * @throws \EE_Error |
4751 | 4751 | */ |
4752 | - public function cap_restrictions( $context = EEM_Base::caps_read ) { |
|
4753 | - EEM_Base::verify_is_valid_cap_context( $context ); |
|
4752 | + public function cap_restrictions($context = EEM_Base::caps_read) { |
|
4753 | + EEM_Base::verify_is_valid_cap_context($context); |
|
4754 | 4754 | //check if we ought to run the restriction generator first |
4755 | - if( |
|
4756 | - isset( $this->_cap_restriction_generators[ $context ] ) |
|
4757 | - && $this->_cap_restriction_generators[ $context ] instanceof EE_Restriction_Generator_Base |
|
4758 | - && ! $this->_cap_restriction_generators[ $context ]->has_generated_cap_restrictions() |
|
4755 | + if ( |
|
4756 | + isset($this->_cap_restriction_generators[$context]) |
|
4757 | + && $this->_cap_restriction_generators[$context] instanceof EE_Restriction_Generator_Base |
|
4758 | + && ! $this->_cap_restriction_generators[$context]->has_generated_cap_restrictions() |
|
4759 | 4759 | ) { |
4760 | - $this->_cap_restrictions[ $context ] = array_merge( |
|
4761 | - $this->_cap_restrictions[ $context ], |
|
4762 | - $this->_cap_restriction_generators[ $context ]->generate_restrictions() |
|
4760 | + $this->_cap_restrictions[$context] = array_merge( |
|
4761 | + $this->_cap_restrictions[$context], |
|
4762 | + $this->_cap_restriction_generators[$context]->generate_restrictions() |
|
4763 | 4763 | ); |
4764 | 4764 | } |
4765 | 4765 | //and make sure we've finalized the construction of each restriction |
4766 | - foreach( $this->_cap_restrictions[ $context ] as $where_conditions_obj ) { |
|
4767 | - if ( $where_conditions_obj instanceof EE_Default_Where_Conditions ) { |
|
4768 | - $where_conditions_obj->_finalize_construct( $this ); |
|
4766 | + foreach ($this->_cap_restrictions[$context] as $where_conditions_obj) { |
|
4767 | + if ($where_conditions_obj instanceof EE_Default_Where_Conditions) { |
|
4768 | + $where_conditions_obj->_finalize_construct($this); |
|
4769 | 4769 | } |
4770 | 4770 | } |
4771 | 4771 | |
4772 | - return $this->_cap_restrictions[ $context ]; |
|
4772 | + return $this->_cap_restrictions[$context]; |
|
4773 | 4773 | } |
4774 | 4774 | |
4775 | 4775 | /** |
4776 | 4776 | * Indicating whether or not this model thinks its a wp core model |
4777 | 4777 | * @return boolean |
4778 | 4778 | */ |
4779 | - public function is_wp_core_model(){ |
|
4779 | + public function is_wp_core_model() { |
|
4780 | 4780 | return $this->_wp_core_model; |
4781 | 4781 | } |
4782 | 4782 | |
@@ -4790,12 +4790,12 @@ discard block |
||
4790 | 4790 | * @return EE_Default_Where_Conditions[] indexed by capability name |
4791 | 4791 | * @throws \EE_Error |
4792 | 4792 | */ |
4793 | - public function caps_missing( $context = EEM_Base::caps_read ) { |
|
4793 | + public function caps_missing($context = EEM_Base::caps_read) { |
|
4794 | 4794 | $missing_caps = array(); |
4795 | - $cap_restrictions = $this->cap_restrictions( $context ); |
|
4796 | - foreach( $cap_restrictions as $cap => $restriction_if_no_cap ) { |
|
4797 | - if( ! EE_Capabilities::instance()->current_user_can( $cap, $this->get_this_model_name() . '_model_applying_caps') ) { |
|
4798 | - $missing_caps[ $cap ] = $restriction_if_no_cap; |
|
4795 | + $cap_restrictions = $this->cap_restrictions($context); |
|
4796 | + foreach ($cap_restrictions as $cap => $restriction_if_no_cap) { |
|
4797 | + if ( ! EE_Capabilities::instance()->current_user_can($cap, $this->get_this_model_name().'_model_applying_caps')) { |
|
4798 | + $missing_caps[$cap] = $restriction_if_no_cap; |
|
4799 | 4799 | } |
4800 | 4800 | } |
4801 | 4801 | return $missing_caps; |
@@ -4807,7 +4807,7 @@ discard block |
||
4807 | 4807 | * one of 'read', 'edit', or 'delete' |
4808 | 4808 | */ |
4809 | 4809 | public function cap_contexts_to_cap_action_map() { |
4810 | - return apply_filters( 'FHEE__EEM_Base__cap_contexts_to_cap_action_map', $this->_cap_contexts_to_cap_action_map, $this ); |
|
4810 | + return apply_filters('FHEE__EEM_Base__cap_contexts_to_cap_action_map', $this->_cap_contexts_to_cap_action_map, $this); |
|
4811 | 4811 | } |
4812 | 4812 | |
4813 | 4813 | |
@@ -4818,19 +4818,19 @@ discard block |
||
4818 | 4818 | * @return string one of EEM_Base::cap_contexts_to_cap_action_map() values |
4819 | 4819 | * @throws \EE_Error |
4820 | 4820 | */ |
4821 | - public function cap_action_for_context( $context ) { |
|
4821 | + public function cap_action_for_context($context) { |
|
4822 | 4822 | $mapping = $this->cap_contexts_to_cap_action_map(); |
4823 | - if( isset( $mapping[ $context ] ) ) { |
|
4824 | - return $mapping[ $context ]; |
|
4823 | + if (isset($mapping[$context])) { |
|
4824 | + return $mapping[$context]; |
|
4825 | 4825 | } |
4826 | - if( $action = apply_filters( 'FHEE__EEM_Base__cap_action_for_context', null, $this, $mapping, $context ) ) { |
|
4826 | + if ($action = apply_filters('FHEE__EEM_Base__cap_action_for_context', null, $this, $mapping, $context)) { |
|
4827 | 4827 | return $action; |
4828 | 4828 | } |
4829 | 4829 | throw new EE_Error( |
4830 | 4830 | sprintf( |
4831 | - __( 'Cannot find capability restrictions for context "%1$s", allowed values are:%2$s', 'event_espresso' ), |
|
4831 | + __('Cannot find capability restrictions for context "%1$s", allowed values are:%2$s', 'event_espresso'), |
|
4832 | 4832 | $context, |
4833 | - implode(',', array_keys( $this->cap_contexts_to_cap_action_map() ) ) |
|
4833 | + implode(',', array_keys($this->cap_contexts_to_cap_action_map())) |
|
4834 | 4834 | ) |
4835 | 4835 | ); |
4836 | 4836 | |
@@ -4841,7 +4841,7 @@ discard block |
||
4841 | 4841 | * @return array |
4842 | 4842 | */ |
4843 | 4843 | static public function valid_cap_contexts() { |
4844 | - return apply_filters( 'FHEE__EEM_Base__valid_cap_contexts', array( |
|
4844 | + return apply_filters('FHEE__EEM_Base__valid_cap_contexts', array( |
|
4845 | 4845 | self::caps_read, |
4846 | 4846 | self::caps_read_admin, |
4847 | 4847 | self::caps_edit, |
@@ -4857,17 +4857,17 @@ discard block |
||
4857 | 4857 | * @return bool |
4858 | 4858 | * @throws \EE_Error |
4859 | 4859 | */ |
4860 | - static public function verify_is_valid_cap_context( $context ) { |
|
4860 | + static public function verify_is_valid_cap_context($context) { |
|
4861 | 4861 | $valid_cap_contexts = EEM_Base::valid_cap_contexts(); |
4862 | - if( in_array( $context, $valid_cap_contexts ) ) { |
|
4862 | + if (in_array($context, $valid_cap_contexts)) { |
|
4863 | 4863 | return true; |
4864 | - }else{ |
|
4864 | + } else { |
|
4865 | 4865 | throw new EE_Error( |
4866 | 4866 | sprintf( |
4867 | - __( 'Context "%1$s" passed into model "%2$s" is not a valid context. They are: %3$s', 'event_espresso' ), |
|
4867 | + __('Context "%1$s" passed into model "%2$s" is not a valid context. They are: %3$s', 'event_espresso'), |
|
4868 | 4868 | $context, |
4869 | - 'EEM_Base' , |
|
4870 | - implode(',', $valid_cap_contexts ) |
|
4869 | + 'EEM_Base', |
|
4870 | + implode(',', $valid_cap_contexts) |
|
4871 | 4871 | ) |
4872 | 4872 | ); |
4873 | 4873 | } |
@@ -541,7 +541,7 @@ discard block |
||
541 | 541 | if( isset( $this->_cap_restriction_generators[ $context ] ) && |
542 | 542 | $this->_cap_restriction_generators[ $context ] instanceof EE_Restriction_Generator_Base ) { |
543 | 543 | return $this->_cap_restriction_generators[ $context ]->generate_restrictions(); |
544 | - }else{ |
|
544 | + } else{ |
|
545 | 545 | return array(); |
546 | 546 | } |
547 | 547 | } |
@@ -766,13 +766,13 @@ discard block |
||
766 | 766 | $last_model_name = end( $models_to_follow_to_wp_users ); |
767 | 767 | $model_with_fk_to_wp_users = EE_Registry::instance()->load_model( $last_model_name ); |
768 | 768 | $model_chain_to_wp_user = $this->_model_chain_to_wp_user . '.'; |
769 | - }else{ |
|
769 | + } else{ |
|
770 | 770 | $model_with_fk_to_wp_users = $this; |
771 | 771 | $model_chain_to_wp_user = ''; |
772 | 772 | } |
773 | 773 | $wp_user_field = $model_with_fk_to_wp_users->get_foreign_key_to( 'WP_User' ); |
774 | 774 | return $model_chain_to_wp_user . $wp_user_field->get_name(); |
775 | - }catch( EE_Error $e ) { |
|
775 | + } catch( EE_Error $e ) { |
|
776 | 776 | return false; |
777 | 777 | } |
778 | 778 | } |
@@ -800,11 +800,11 @@ discard block |
||
800 | 800 | public function is_owned() { |
801 | 801 | if( $this->model_chain_to_wp_user() ){ |
802 | 802 | return true; |
803 | - }else{ |
|
803 | + } else{ |
|
804 | 804 | try{ |
805 | 805 | $this->get_foreign_key_to( 'WP_User' ); |
806 | 806 | return true; |
807 | - }catch( EE_Error $e ){ |
|
807 | + } catch( EE_Error $e ){ |
|
808 | 808 | return false; |
809 | 809 | } |
810 | 810 | } |
@@ -900,7 +900,7 @@ discard block |
||
900 | 900 | $select_sql_array[] = "{$selection_and_datatype[0]} AS $alias"; |
901 | 901 | } |
902 | 902 | $columns_to_select_string = implode(", ",$select_sql_array); |
903 | - }else{ |
|
903 | + } else{ |
|
904 | 904 | $columns_to_select_string = $columns_to_select; |
905 | 905 | } |
906 | 906 | return $columns_to_select_string; |
@@ -956,7 +956,7 @@ discard block |
||
956 | 956 | } |
957 | 957 | if( $this->has_primary_key_field ( ) ) { |
958 | 958 | $query_params[ 0 ][ $this->primary_key_name() ] = $id ; |
959 | - }else{ |
|
959 | + } else{ |
|
960 | 960 | //no primary key, so the $id must be from the get_index_primary_key_string() |
961 | 961 | $query_params[0] = array_replace_recursive( $query_params[ 0 ], $this->parse_index_primary_key_string( $id ) ); |
962 | 962 | } |
@@ -982,7 +982,7 @@ discard block |
||
982 | 982 | $items = $this->get_all($query_params); |
983 | 983 | if(empty($items)){ |
984 | 984 | return null; |
985 | - }else{ |
|
985 | + } else{ |
|
986 | 986 | return array_shift($items); |
987 | 987 | } |
988 | 988 | } |
@@ -1370,7 +1370,7 @@ discard block |
||
1370 | 1370 | //get the model object's PK, as we'll want this if we need to insert a row into secondary tables |
1371 | 1371 | if( $this->has_primary_key_field() ){ |
1372 | 1372 | $main_table_pk_value = $wpdb_result[ $this->get_primary_key_field()->get_qualified_column() ]; |
1373 | - }else{ |
|
1373 | + } else{ |
|
1374 | 1374 | //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) |
1375 | 1375 | $main_table_pk_value = null; |
1376 | 1376 | } |
@@ -1409,7 +1409,7 @@ discard block |
||
1409 | 1409 | if( $keep_model_objs_in_sync && ! $this->_values_already_prepared_by_model_object ){ |
1410 | 1410 | if( $this->has_primary_key_field() ){ |
1411 | 1411 | $model_objs_affected_ids = $this->get_col( $query_params ); |
1412 | - }else{ |
|
1412 | + } else{ |
|
1413 | 1413 | //we need to select a bunch of columns and then combine them into the the "index primary key string"s |
1414 | 1414 | $models_affected_key_columns = $this->_get_all_wpdb_results($query_params, ARRAY_A ); |
1415 | 1415 | $model_objs_affected_ids = array(); |
@@ -1473,9 +1473,9 @@ discard block |
||
1473 | 1473 | |
1474 | 1474 | if( $field_to_select ){ |
1475 | 1475 | $field = $this->field_settings_for( $field_to_select ); |
1476 | - }elseif( $this->has_primary_key_field ( ) ){ |
|
1476 | + } elseif( $this->has_primary_key_field ( ) ){ |
|
1477 | 1477 | $field = $this->get_primary_key_field(); |
1478 | - }else{ |
|
1478 | + } else{ |
|
1479 | 1479 | //no primary key, just grab the first column |
1480 | 1480 | $field = reset( $this->field_settings()); |
1481 | 1481 | } |
@@ -1502,7 +1502,7 @@ discard block |
||
1502 | 1502 | $col = $this->get_col( $query_params, $field_to_select ); |
1503 | 1503 | if( ! empty( $col ) ) { |
1504 | 1504 | return reset( $col ); |
1505 | - }else{ |
|
1505 | + } else{ |
|
1506 | 1506 | return NULL; |
1507 | 1507 | } |
1508 | 1508 | } |
@@ -1629,7 +1629,7 @@ discard block |
||
1629 | 1629 | |
1630 | 1630 | // /echo "delete sql:$SQL"; |
1631 | 1631 | $rows_deleted = $this->_do_wpdb_query( 'query', array( $SQL ) ); |
1632 | - }else{ |
|
1632 | + } else{ |
|
1633 | 1633 | $rows_deleted = 0; |
1634 | 1634 | } |
1635 | 1635 | |
@@ -1673,7 +1673,7 @@ discard block |
||
1673 | 1673 | //first, if $ignore_this_model_obj was supplied, get its model |
1674 | 1674 | if($ignore_this_model_obj && $ignore_this_model_obj instanceof EE_Base_Class){ |
1675 | 1675 | $ignored_model = $ignore_this_model_obj->get_model(); |
1676 | - }else{ |
|
1676 | + } else{ |
|
1677 | 1677 | $ignored_model = null; |
1678 | 1678 | } |
1679 | 1679 | //now check all the relations of $this_model_obj_or_id and see if there |
@@ -1686,7 +1686,7 @@ discard block |
||
1686 | 1686 | if($ignored_model && $relation_name === $ignored_model->get_this_model_name()){ |
1687 | 1687 | $related_model_objects = $relation_obj->get_all_related($this_model_obj_or_id,array( |
1688 | 1688 | array($ignored_model->get_primary_key_field()->get_name() => array('!=',$ignore_this_model_obj->ID())))); |
1689 | - }else{ |
|
1689 | + } else{ |
|
1690 | 1690 | $related_model_objects = $relation_obj->get_all_related($this_model_obj_or_id); |
1691 | 1691 | } |
1692 | 1692 | |
@@ -1759,7 +1759,7 @@ discard block |
||
1759 | 1759 | } |
1760 | 1760 | |
1761 | 1761 | return !empty($query) ? implode(' AND ', $query ) : ''; |
1762 | - }elseif(count($this->get_combined_primary_key_fields()) > 1){ |
|
1762 | + } elseif(count($this->get_combined_primary_key_fields()) > 1){ |
|
1763 | 1763 | $ways_to_identify_a_row = array(); |
1764 | 1764 | $fields = $this->get_combined_primary_key_fields(); |
1765 | 1765 | //note: because there' sno primary key, that means nothing else can be pointing to this model, right? |
@@ -1771,7 +1771,7 @@ discard block |
||
1771 | 1771 | $ways_to_identify_a_row[] = "(".implode(" AND ",$values_for_each_cpk_for_a_row).")"; |
1772 | 1772 | } |
1773 | 1773 | return implode(" OR ",$ways_to_identify_a_row); |
1774 | - }else{ |
|
1774 | + } else{ |
|
1775 | 1775 | //so there's no primary key and no combined key... |
1776 | 1776 | //sorry, can't help you |
1777 | 1777 | 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))); |
@@ -1795,10 +1795,10 @@ discard block |
||
1795 | 1795 | if($field_to_count){ |
1796 | 1796 | $field_obj = $this->field_settings_for($field_to_count); |
1797 | 1797 | $column_to_count = $field_obj->get_qualified_column(); |
1798 | - }elseif($this->has_primary_key_field ()){ |
|
1798 | + } elseif($this->has_primary_key_field ()){ |
|
1799 | 1799 | $pk_field_obj = $this->get_primary_key_field(); |
1800 | 1800 | $column_to_count = $pk_field_obj->get_qualified_column(); |
1801 | - }else{//there's no primary key |
|
1801 | + } else{//there's no primary key |
|
1802 | 1802 | $column_to_count = '*'; |
1803 | 1803 | } |
1804 | 1804 | |
@@ -1823,7 +1823,7 @@ discard block |
||
1823 | 1823 | if($field_to_sum){ |
1824 | 1824 | $field_obj = $this->field_settings_for($field_to_sum); |
1825 | 1825 | |
1826 | - }else{ |
|
1826 | + } else{ |
|
1827 | 1827 | $field_obj = $this->get_primary_key_field(); |
1828 | 1828 | } |
1829 | 1829 | $column_to_count = $field_obj->get_qualified_column(); |
@@ -1833,7 +1833,7 @@ discard block |
||
1833 | 1833 | $data_type = $field_obj->get_wpdb_data_type(); |
1834 | 1834 | if( $data_type === '%d' || $data_type === '%s' ){ |
1835 | 1835 | return (float)$return_value; |
1836 | - }else{//must be %f |
|
1836 | + } else{//must be %f |
|
1837 | 1837 | return (float)$return_value; |
1838 | 1838 | } |
1839 | 1839 | } |
@@ -1871,10 +1871,10 @@ discard block |
||
1871 | 1871 | $wpdb->show_errors( $old_show_errors_value ); |
1872 | 1872 | if( ! empty( $wpdb->last_error ) ){ |
1873 | 1873 | throw new EE_Error( sprintf( __( 'WPDB Error: "%s"', 'event_espresso' ), $wpdb->last_error ) ); |
1874 | - }elseif( $result === false ){ |
|
1874 | + } elseif( $result === false ){ |
|
1875 | 1875 | 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 ) ) ); |
1876 | 1876 | } |
1877 | - }elseif( $result === false ) { |
|
1877 | + } elseif( $result === false ) { |
|
1878 | 1878 | EE_Error::add_error( sprintf( __( 'A database error has occurred. Turn on WP_DEBUG for more information.', 'event_espresso' )), __FILE__, __FUNCTION__, __LINE__); |
1879 | 1879 | } |
1880 | 1880 | return $result; |
@@ -2206,7 +2206,7 @@ discard block |
||
2206 | 2206 | $results = $this->get_all_related($id_or_obj,$other_model_name,$query_params); |
2207 | 2207 | if( $results ){ |
2208 | 2208 | return array_shift($results); |
2209 | - }else{ |
|
2209 | + } else{ |
|
2210 | 2210 | return null; |
2211 | 2211 | } |
2212 | 2212 | |
@@ -2277,7 +2277,7 @@ discard block |
||
2277 | 2277 | */ |
2278 | 2278 | do_action( 'AHEE__EEM_Base__insert__end', $this, $field_n_values, $new_id ); |
2279 | 2279 | return $new_id; |
2280 | - }else{ |
|
2280 | + } else{ |
|
2281 | 2281 | return FALSE; |
2282 | 2282 | } |
2283 | 2283 | } |
@@ -2335,9 +2335,9 @@ discard block |
||
2335 | 2335 | public function get_one_conflicting($obj_or_fields_array, $include_primary_key = true ){ |
2336 | 2336 | if($obj_or_fields_array instanceof EE_Base_Class){ |
2337 | 2337 | $fields_n_values = $obj_or_fields_array->model_field_array(); |
2338 | - }elseif( is_array($obj_or_fields_array)){ |
|
2338 | + } elseif( is_array($obj_or_fields_array)){ |
|
2339 | 2339 | $fields_n_values = $obj_or_fields_array; |
2340 | - }else{ |
|
2340 | + } else{ |
|
2341 | 2341 | throw new EE_Error( |
2342 | 2342 | sprintf( |
2343 | 2343 | __( |
@@ -2362,7 +2362,7 @@ discard block |
||
2362 | 2362 | //if there is nothing to base this search on, then we shouldn't find anything |
2363 | 2363 | if( empty( $query_params ) ){ |
2364 | 2364 | return array(); |
2365 | - }else{ |
|
2365 | + } else{ |
|
2366 | 2366 | return $this->get_one($query_params); |
2367 | 2367 | } |
2368 | 2368 | } |
@@ -2443,12 +2443,12 @@ discard block |
||
2443 | 2443 | if($this->has_primary_key_field()){ |
2444 | 2444 | if($this->get_primary_key_field()->is_auto_increment()){ |
2445 | 2445 | return $wpdb->insert_id; |
2446 | - }else{ |
|
2446 | + } else{ |
|
2447 | 2447 | //it's not an auto-increment primary key, so |
2448 | 2448 | //it must have been supplied |
2449 | 2449 | return $fields_n_values[$this->get_primary_key_field()->get_name()]; |
2450 | 2450 | } |
2451 | - }else{ |
|
2451 | + } else{ |
|
2452 | 2452 | //we can't return a primary key because there is none. instead return |
2453 | 2453 | //a unique string indicating this model |
2454 | 2454 | return $this->get_index_primary_key_string($fields_n_values); |
@@ -2500,7 +2500,7 @@ discard block |
||
2500 | 2500 | //leave the value alone |
2501 | 2501 | } |
2502 | 2502 | return $value; |
2503 | - }else{ |
|
2503 | + } else{ |
|
2504 | 2504 | return $value; |
2505 | 2505 | } |
2506 | 2506 | } |
@@ -2669,10 +2669,10 @@ discard block |
||
2669 | 2669 | if (! is_array($possibly_array_of_params)){ |
2670 | 2670 | 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"), |
2671 | 2671 | $param,$possibly_array_of_params)); |
2672 | - }else{ |
|
2672 | + } else{ |
|
2673 | 2673 | $this->_extract_related_models_from_sub_params_array_keys($possibly_array_of_params, $model_query_info_carrier,$query_param_type); |
2674 | 2674 | } |
2675 | - }elseif($query_param_type === 0 //ie WHERE |
|
2675 | + } elseif($query_param_type === 0 //ie WHERE |
|
2676 | 2676 | && is_array($possibly_array_of_params) |
2677 | 2677 | && isset($possibly_array_of_params[2]) |
2678 | 2678 | && $possibly_array_of_params[2] == true){ |
@@ -2950,7 +2950,7 @@ discard block |
||
2950 | 2950 | private function _extract_order($should_be_order_string){ |
2951 | 2951 | if(in_array($should_be_order_string, $this->_allowed_order_values)){ |
2952 | 2952 | return $should_be_order_string; |
2953 | - }else{ |
|
2953 | + } else{ |
|
2954 | 2954 | 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)); |
2955 | 2955 | } |
2956 | 2956 | } |
@@ -3027,7 +3027,7 @@ discard block |
||
3027 | 3027 | foreach($default_where_conditions as $key => $val){ |
3028 | 3028 | if( isset($provided_where_conditions[$key])){ |
3029 | 3029 | $none_overridden = false; |
3030 | - }else{ |
|
3030 | + } else{ |
|
3031 | 3031 | $null_friendly_where_conditions[$or_condition_key_for_defaults]['AND'][$key] = $val; |
3032 | 3032 | } |
3033 | 3033 | } |
@@ -3153,7 +3153,7 @@ discard block |
||
3153 | 3153 | if(array_key_exists($query_param,$this_model_fields)){ |
3154 | 3154 | if($allow_fields){ |
3155 | 3155 | return; |
3156 | - }else{ |
|
3156 | + } else{ |
|
3157 | 3157 | 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"), |
3158 | 3158 | $query_param,get_class($this),$query_param_type,$original_query_param)); |
3159 | 3159 | } |
@@ -3162,7 +3162,7 @@ discard block |
||
3162 | 3162 | elseif(in_array($query_param, $this->_logic_query_param_keys, TRUE)){ |
3163 | 3163 | if($allow_logic_query_params){ |
3164 | 3164 | return; |
3165 | - }else{ |
|
3165 | + } else{ |
|
3166 | 3166 | throw new EE_Error( |
3167 | 3167 | sprintf( |
3168 | 3168 | __( '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' ), |
@@ -3193,12 +3193,12 @@ discard block |
||
3193 | 3193 | //we should actually end in a field name, not a model like this! |
3194 | 3194 | throw new EE_Error(sprintf(__("Query param '%s' (of type %s on model %s) shouldn't end on a period (.) ", "event_espresso"), |
3195 | 3195 | $query_param,$query_param_type,get_class($this),$valid_related_model_name)); |
3196 | - }else{ |
|
3196 | + } else{ |
|
3197 | 3197 | $related_model_obj = $this->get_related_model_obj($valid_related_model_name); |
3198 | 3198 | $related_model_obj->_extract_related_model_info_from_query_param($query_param, $passed_in_query_info, $query_param_type, $original_query_param); |
3199 | 3199 | return; |
3200 | 3200 | } |
3201 | - }elseif($query_param === $valid_related_model_name){ |
|
3201 | + } elseif($query_param === $valid_related_model_name){ |
|
3202 | 3202 | $this->_add_join_to_model($valid_related_model_name, $passed_in_query_info,$original_query_param); |
3203 | 3203 | return; |
3204 | 3204 | } |
@@ -3263,7 +3263,7 @@ discard block |
||
3263 | 3263 | $SQL = $this->_construct_condition_clause_recursive($where_params, ' AND '); |
3264 | 3264 | if($SQL){ |
3265 | 3265 | return " WHERE ". $SQL; |
3266 | - }else{ |
|
3266 | + } else{ |
|
3267 | 3267 | return ''; |
3268 | 3268 | } |
3269 | 3269 | } |
@@ -3282,7 +3282,7 @@ discard block |
||
3282 | 3282 | $SQL = $this->_construct_condition_clause_recursive($having_params, ' AND '); |
3283 | 3283 | if($SQL){ |
3284 | 3284 | return " HAVING ". $SQL; |
3285 | - }else{ |
|
3285 | + } else{ |
|
3286 | 3286 | return ''; |
3287 | 3287 | } |
3288 | 3288 | |
@@ -3305,7 +3305,7 @@ discard block |
||
3305 | 3305 | $model_instance=call_user_func($model_name."::instance"); |
3306 | 3306 | /* @var $model_instance EEM_Base */ |
3307 | 3307 | return $model_instance->field_settings_for($field_name); |
3308 | - }else{ |
|
3308 | + } else{ |
|
3309 | 3309 | throw new EE_Error(sprintf(__('No model named %s exists, with classname %s and filepath %s','event_espresso'),$model_name,$model_class,$model_filepath)); |
3310 | 3310 | } |
3311 | 3311 | } |
@@ -3338,14 +3338,14 @@ discard block |
||
3338 | 3338 | $where_clauses[] = " (". $this->_construct_condition_clause_recursive($op_and_value_or_sub_condition, ' OR ') .")"; |
3339 | 3339 | break; |
3340 | 3340 | } |
3341 | - }else{ |
|
3341 | + } else{ |
|
3342 | 3342 | $field_obj = $this->_deduce_field_from_query_param($query_param); |
3343 | 3343 | |
3344 | 3344 | //if it's not a normal field, maybe it's a custom selection? |
3345 | 3345 | if( ! $field_obj){ |
3346 | 3346 | if(isset( $this->_custom_selections[$query_param][1])){ |
3347 | 3347 | $field_obj = $this->_custom_selections[$query_param][1]; |
3348 | - }else{ |
|
3348 | + } else{ |
|
3349 | 3349 | throw new EE_Error(sprintf(__("%s is neither a valid model field name, nor a custom selection", "event_espresso"),$query_param)); |
3350 | 3350 | } |
3351 | 3351 | } |
@@ -3370,11 +3370,11 @@ discard block |
||
3370 | 3370 | if( $field ){ |
3371 | 3371 | $table_alias_prefix = EE_Model_Parser::extract_table_alias_model_relation_chain_from_query_param( $field->get_model_name(), $query_param ); |
3372 | 3372 | return $table_alias_prefix . $field->get_qualified_column(); |
3373 | - }elseif(array_key_exists($query_param,$this->_custom_selections)){ |
|
3373 | + } elseif(array_key_exists($query_param,$this->_custom_selections)){ |
|
3374 | 3374 | //maybe it's custom selection item? |
3375 | 3375 | //if so, just use it as the "column name" |
3376 | 3376 | return $query_param; |
3377 | - }else{ |
|
3377 | + } else{ |
|
3378 | 3378 | 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))); |
3379 | 3379 | } |
3380 | 3380 | } |
@@ -3391,7 +3391,7 @@ discard block |
||
3391 | 3391 | $pos_of_star = strpos($condition_query_param_key, '*'); |
3392 | 3392 | if($pos_of_star === FALSE){ |
3393 | 3393 | return $condition_query_param_key; |
3394 | - }else{ |
|
3394 | + } else{ |
|
3395 | 3395 | $condition_query_param_sans_star = substr($condition_query_param_key, 0, $pos_of_star); |
3396 | 3396 | return $condition_query_param_sans_star; |
3397 | 3397 | } |
@@ -3576,7 +3576,7 @@ discard block |
||
3576 | 3576 | global $wpdb; |
3577 | 3577 | if($field_obj instanceof EE_Model_Field_Base){ |
3578 | 3578 | return $wpdb->prepare($field_obj->get_wpdb_data_type(),$this->_prepare_value_for_use_in_db($value, $field_obj)); |
3579 | - }else{//$field_obj should really just be a data type |
|
3579 | + } else{//$field_obj should really just be a data type |
|
3580 | 3580 | if( ! in_array($field_obj,$this->_valid_wpdb_data_types)){ |
3581 | 3581 | 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))); |
3582 | 3582 | } |
@@ -3605,14 +3605,14 @@ discard block |
||
3605 | 3605 | if($number_of_parts === 1){ |
3606 | 3606 | $field_name = $last_query_param_part; |
3607 | 3607 | $model_obj = $this; |
3608 | - }else{// $number_of_parts >= 2 |
|
3608 | + } else{// $number_of_parts >= 2 |
|
3609 | 3609 | //the last part is the column name, and there are only 2parts. therefore... |
3610 | 3610 | $field_name = $last_query_param_part; |
3611 | 3611 | $model_obj = $this->get_related_model_obj( $query_param_parts[ $number_of_parts - 2 ]); |
3612 | 3612 | } |
3613 | 3613 | try{ |
3614 | 3614 | return $model_obj->field_settings_for($field_name); |
3615 | - }catch(EE_Error $e){ |
|
3615 | + } catch(EE_Error $e){ |
|
3616 | 3616 | return null; |
3617 | 3617 | } |
3618 | 3618 | } |
@@ -3631,7 +3631,7 @@ discard block |
||
3631 | 3631 | $field = isset($all_fields[$field_name]) ? $all_fields[$field_name] : FALSE; |
3632 | 3632 | if($field){ |
3633 | 3633 | return $field->get_qualified_column(); |
3634 | - }else{ |
|
3634 | + } else{ |
|
3635 | 3635 | 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))); |
3636 | 3636 | } |
3637 | 3637 | } |
@@ -3702,7 +3702,7 @@ discard block |
||
3702 | 3702 | //the FROM statement, BUT the primary table isn't. So we want |
3703 | 3703 | //to add the inverse join sql |
3704 | 3704 | $SQL .= $table_obj->get_inverse_join_sql($alias_prefixed); |
3705 | - }else{ |
|
3705 | + } else{ |
|
3706 | 3706 | //just add a regular JOIN to this table from the primary table |
3707 | 3707 | $SQL .= $table_obj->get_join_sql($alias_prefixed); |
3708 | 3708 | } |
@@ -3815,7 +3815,7 @@ discard block |
||
3815 | 3815 | $fieldSettings = $this->field_settings(true); |
3816 | 3816 | if( isset($fieldSettings[$fieldName])){ |
3817 | 3817 | return true; |
3818 | - }else{ |
|
3818 | + } else{ |
|
3819 | 3819 | return false; |
3820 | 3820 | } |
3821 | 3821 | } |
@@ -3829,7 +3829,7 @@ discard block |
||
3829 | 3829 | $relations = $this->relation_settings(); |
3830 | 3830 | if(isset($relations[$relation_name])){ |
3831 | 3831 | return true; |
3832 | - }else{ |
|
3832 | + } else{ |
|
3833 | 3833 | return false; |
3834 | 3834 | } |
3835 | 3835 | } |
@@ -3880,7 +3880,7 @@ discard block |
||
3880 | 3880 | try{ |
3881 | 3881 | $this->get_primary_key_field(); |
3882 | 3882 | $this->_has_primary_key_field = true; |
3883 | - }catch(EE_Error $e){ |
|
3883 | + } catch(EE_Error $e){ |
|
3884 | 3884 | $this->_has_primary_key_field = false; |
3885 | 3885 | } |
3886 | 3886 | } |
@@ -3959,7 +3959,7 @@ discard block |
||
3959 | 3959 | } |
3960 | 3960 | } |
3961 | 3961 | return $this->_cached_fields; |
3962 | - }else{ |
|
3962 | + } else{ |
|
3963 | 3963 | if( $this->_cached_fields_non_db_only === NULL ){ |
3964 | 3964 | $this->_cached_fields_non_db_only = array(); |
3965 | 3965 | foreach($this->_fields as $fields_corresponding_to_table){ |
@@ -4095,7 +4095,7 @@ discard block |
||
4095 | 4095 | if(empty( $this_model_fields_n_values[$this->primary_key_name()] )){ |
4096 | 4096 | return NULL; |
4097 | 4097 | } |
4098 | - }else if($this->unique_indexes()){ |
|
4098 | + } else if($this->unique_indexes()){ |
|
4099 | 4099 | $first_column = reset($this_model_fields_n_values); |
4100 | 4100 | if(empty($first_column)){ |
4101 | 4101 | return NULL; |
@@ -4110,7 +4110,7 @@ discard block |
||
4110 | 4110 | // add this new object to the entity map |
4111 | 4111 | $classInstance = $this->add_to_entity_map( $classInstance ); |
4112 | 4112 | } |
4113 | - }else{ |
|
4113 | + } else{ |
|
4114 | 4114 | $classInstance = EE_Registry::instance()->load_class( $className, array( $this_model_fields_n_values, $this->_timezone ), TRUE, FALSE ); |
4115 | 4115 | } |
4116 | 4116 | |
@@ -4197,7 +4197,7 @@ discard block |
||
4197 | 4197 | $this_model_fields_n_values[$field_name] = $field_obj->prepare_for_use_in_db( $prepared_value ); |
4198 | 4198 | } |
4199 | 4199 | } |
4200 | - }else{ |
|
4200 | + } else{ |
|
4201 | 4201 | //the table's rows existed. Use their values |
4202 | 4202 | foreach( $this->_get_fields_for_table( $table_alias ) as $field_name => $field_obj ) { |
4203 | 4203 | if( ! $field_obj->is_db_only_field() ){ |
@@ -4227,7 +4227,7 @@ discard block |
||
4227 | 4227 | //or is it a db-only field? (not relating to the model) |
4228 | 4228 | if( isset( $cols_n_values[ $qualified_column ] ) ){ |
4229 | 4229 | $value = $cols_n_values[ $qualified_column ]; |
4230 | - }elseif( isset( $cols_n_values[ $regular_column ] ) ){ |
|
4230 | + } elseif( isset( $cols_n_values[ $regular_column ] ) ){ |
|
4231 | 4231 | $value = $cols_n_values[ $regular_column ]; |
4232 | 4232 | } |
4233 | 4233 | return $value; |
@@ -4261,7 +4261,7 @@ discard block |
||
4261 | 4261 | } |
4262 | 4262 | } |
4263 | 4263 | return $obj_in_map; |
4264 | - }else{ |
|
4264 | + } else{ |
|
4265 | 4265 | return $this->get_one_by_ID( $id ); |
4266 | 4266 | } |
4267 | 4267 | } |
@@ -4296,7 +4296,7 @@ discard block |
||
4296 | 4296 | } |
4297 | 4297 | } |
4298 | 4298 | return $obj_in_map; |
4299 | - }else{ |
|
4299 | + } else{ |
|
4300 | 4300 | $this->add_to_entity_map( $replacing_model_obj ); |
4301 | 4301 | return $replacing_model_obj; |
4302 | 4302 | } |
@@ -4389,7 +4389,7 @@ discard block |
||
4389 | 4389 | $primary_key_field = $this->get_primary_key_field(); |
4390 | 4390 | if( $base_class_obj_or_id instanceof $className ){ |
4391 | 4391 | $model_object = $base_class_obj_or_id; |
4392 | - }elseif( |
|
4392 | + } elseif( |
|
4393 | 4393 | $primary_key_field instanceof EE_Primary_Key_Int_Field |
4394 | 4394 | && ( |
4395 | 4395 | is_int( $base_class_obj_or_id ) |
@@ -4401,7 +4401,7 @@ discard block |
||
4401 | 4401 | } else if( $primary_key_field instanceof EE_Primary_Key_String_Field && is_string( $base_class_obj_or_id ) ){ |
4402 | 4402 | // assume its a string representation of the object |
4403 | 4403 | $model_object = $this->get_one_by_ID( $base_class_obj_or_id ); |
4404 | - }else{ |
|
4404 | + } else{ |
|
4405 | 4405 | throw new EE_Error( |
4406 | 4406 | sprintf( |
4407 | 4407 | __( "'%s' is neither an object of type %s, nor an ID! Its full value is '%s'", 'event_espresso' ), |
@@ -4432,13 +4432,13 @@ discard block |
||
4432 | 4432 | if( $base_class_obj_or_id instanceof $className ){ |
4433 | 4433 | /** @var $base_class_obj_or_id EE_Base_Class */ |
4434 | 4434 | $id = $base_class_obj_or_id->ID(); |
4435 | - }elseif(is_int($base_class_obj_or_id)){ |
|
4435 | + } elseif(is_int($base_class_obj_or_id)){ |
|
4436 | 4436 | //assume it's an ID |
4437 | 4437 | $id = $base_class_obj_or_id; |
4438 | - }elseif(is_string($base_class_obj_or_id)){ |
|
4438 | + } elseif(is_string($base_class_obj_or_id)){ |
|
4439 | 4439 | //assume its a string representation of the object |
4440 | 4440 | $id = $base_class_obj_or_id; |
4441 | - }else{ |
|
4441 | + } else{ |
|
4442 | 4442 | 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))); |
4443 | 4443 | } |
4444 | 4444 | return $id; |
@@ -4585,9 +4585,9 @@ discard block |
||
4585 | 4585 | |
4586 | 4586 | if($model_object_or_attributes_array instanceof EE_Base_Class){ |
4587 | 4587 | $attributes_array = $model_object_or_attributes_array->model_field_array(); |
4588 | - }elseif(is_array($model_object_or_attributes_array)){ |
|
4588 | + } elseif(is_array($model_object_or_attributes_array)){ |
|
4589 | 4589 | $attributes_array = $model_object_or_attributes_array; |
4590 | - }else{ |
|
4590 | + } else{ |
|
4591 | 4591 | 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)); |
4592 | 4592 | } |
4593 | 4593 | //even copies obviously won't have the same ID, so remove the primary key |
@@ -4597,7 +4597,7 @@ discard block |
||
4597 | 4597 | } |
4598 | 4598 | if(isset($query_params[0])){ |
4599 | 4599 | $query_params[0] = array_merge($attributes_array,$query_params); |
4600 | - }else{ |
|
4600 | + } else{ |
|
4601 | 4601 | $query_params[0] = $attributes_array; |
4602 | 4602 | } |
4603 | 4603 | return $this->get_all($query_params); |
@@ -4622,7 +4622,7 @@ discard block |
||
4622 | 4622 | $copies = $this->get_all_copies($model_object_or_attributes_array,$query_params); |
4623 | 4623 | if(is_array($copies)){ |
4624 | 4624 | return array_shift($copies); |
4625 | - }else{ |
|
4625 | + } else{ |
|
4626 | 4626 | return null; |
4627 | 4627 | } |
4628 | 4628 | } |
@@ -4656,7 +4656,7 @@ discard block |
||
4656 | 4656 | $sql_operator = isset($this->_valid_operators[$operator_supplied]) ? $this->_valid_operators[$operator_supplied] : null; |
4657 | 4657 | if($sql_operator){ |
4658 | 4658 | return $sql_operator; |
4659 | - }else{ |
|
4659 | + } else{ |
|
4660 | 4660 | 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)))); |
4661 | 4661 | } |
4662 | 4662 | } |
@@ -4861,7 +4861,7 @@ discard block |
||
4861 | 4861 | $valid_cap_contexts = EEM_Base::valid_cap_contexts(); |
4862 | 4862 | if( in_array( $context, $valid_cap_contexts ) ) { |
4863 | 4863 | return true; |
4864 | - }else{ |
|
4864 | + } else{ |
|
4865 | 4865 | throw new EE_Error( |
4866 | 4866 | sprintf( |
4867 | 4867 | __( 'Context "%1$s" passed into model "%2$s" is not a valid context. They are: %3$s', 'event_espresso' ), |
@@ -38,7 +38,7 @@ |
||
38 | 38 | } |
39 | 39 | /** |
40 | 40 | * Gets the joining model's object |
41 | - * @return EEM_Base |
|
41 | + * @return boolean |
|
42 | 42 | */ |
43 | 43 | public function get_join_model(){ |
44 | 44 | return $this->_get_model($this->_joining_model_name); |
@@ -1,6 +1,6 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | |
3 | -require_once( EE_MODELS . 'relations/EE_Model_Relation_Base.php'); |
|
3 | +require_once(EE_MODELS.'relations/EE_Model_Relation_Base.php'); |
|
4 | 4 | |
5 | 5 | |
6 | 6 | |
@@ -11,7 +11,7 @@ discard block |
||
11 | 11 | * @subpackage core |
12 | 12 | * @author Michael Nelson |
13 | 13 | */ |
14 | -class EE_HABTM_Relation extends EE_Model_Relation_Base{ |
|
14 | +class EE_HABTM_Relation extends EE_Model_Relation_Base { |
|
15 | 15 | /** |
16 | 16 | * Model which defines the relation between two other models. Eg, the EE_Event_Question_Group model, |
17 | 17 | * which joins EE_Event and EE_Question_Group |
@@ -32,7 +32,7 @@ discard block |
||
32 | 32 | * @param boolean $block_deletes for this type of relation, we block by default for now. if there are related models across this relation, block (prevent and add an error) the deletion of this model |
33 | 33 | * @param string $blocking_delete_error_message a customized error message on blocking deletes instead of the default |
34 | 34 | */ |
35 | - public function __construct($joining_model_name,$block_deletes = true, $blocking_delete_error_message =''){ |
|
35 | + public function __construct($joining_model_name, $block_deletes = true, $blocking_delete_error_message = '') { |
|
36 | 36 | $this->_joining_model_name = $joining_model_name; |
37 | 37 | parent::__construct($block_deletes, $blocking_delete_error_message); |
38 | 38 | } |
@@ -40,7 +40,7 @@ discard block |
||
40 | 40 | * Gets the joining model's object |
41 | 41 | * @return EEM_Base |
42 | 42 | */ |
43 | - public function get_join_model(){ |
|
43 | + public function get_join_model() { |
|
44 | 44 | return $this->_get_model($this->_joining_model_name); |
45 | 45 | } |
46 | 46 | |
@@ -53,21 +53,21 @@ discard block |
||
53 | 53 | * @return string of SQL |
54 | 54 | * @throws \EE_Error |
55 | 55 | */ |
56 | - public function get_join_to_intermediate_model_statement($model_relation_chain){ |
|
56 | + public function get_join_to_intermediate_model_statement($model_relation_chain) { |
|
57 | 57 | //create sql like |
58 | 58 | //LEFT JOIN join_table AS join_table_alias ON this_table_alias.this_table_pk = join_table_alias.join_table_fk_to_this |
59 | 59 | //LEFT JOIN other_table AS other_table_alias ON join_table_alias.join_table_fk_to_other = other_table_alias.other_table_pk |
60 | 60 | //remember the model relation chain to the JOIN model, because we'll |
61 | 61 | //need it for get_join_statement() |
62 | 62 | $this->_model_relation_chain_to_join_model = $model_relation_chain; |
63 | - $this_table_pk_field = $this->get_this_model()->get_primary_key_field();//get_foreign_key_to($this->get_other_model()->get_this_model_name()); |
|
63 | + $this_table_pk_field = $this->get_this_model()->get_primary_key_field(); //get_foreign_key_to($this->get_other_model()->get_this_model_name()); |
|
64 | 64 | $join_table_fk_field_to_this_table = $this->get_join_model()->get_foreign_key_to($this->get_this_model()->get_this_model_name()); |
65 | - $this_table_alias = EE_Model_Parser::extract_table_alias_model_relation_chain_prefix($model_relation_chain, $this->get_this_model()->get_this_model_name()) . $this_table_pk_field->get_table_alias(); |
|
65 | + $this_table_alias = EE_Model_Parser::extract_table_alias_model_relation_chain_prefix($model_relation_chain, $this->get_this_model()->get_this_model_name()).$this_table_pk_field->get_table_alias(); |
|
66 | 66 | |
67 | - $join_table_alias = EE_Model_Parser::extract_table_alias_model_relation_chain_prefix($model_relation_chain, $this->get_join_model()->get_this_model_name()) . $join_table_fk_field_to_this_table->get_table_alias(); |
|
67 | + $join_table_alias = EE_Model_Parser::extract_table_alias_model_relation_chain_prefix($model_relation_chain, $this->get_join_model()->get_this_model_name()).$join_table_fk_field_to_this_table->get_table_alias(); |
|
68 | 68 | $join_table = $this->get_join_model()->get_table_for_alias($join_table_alias); |
69 | 69 | //phew! ok, we have all the info we need, now we can create the SQL join string |
70 | - $SQL = $this->_left_join($join_table, $join_table_alias, $join_table_fk_field_to_this_table->get_table_column(), $this_table_alias, $this_table_pk_field->get_table_column()) . $this->get_join_model()->_construct_internal_join_to_table_with_alias($join_table_alias); |
|
70 | + $SQL = $this->_left_join($join_table, $join_table_alias, $join_table_fk_field_to_this_table->get_table_column(), $this_table_alias, $this_table_pk_field->get_table_column()).$this->get_join_model()->_construct_internal_join_to_table_with_alias($join_table_alias); |
|
71 | 71 | |
72 | 72 | return $SQL; |
73 | 73 | } |
@@ -84,18 +84,18 @@ discard block |
||
84 | 84 | * @return string of SQL |
85 | 85 | * @throws \EE_Error |
86 | 86 | */ |
87 | - public function get_join_statement($model_relation_chain){ |
|
88 | - if( $this->_model_relation_chain_to_join_model === NULL ){ |
|
89 | - throw new EE_Error( sprintf( __( 'When using EE_HABTM_Relation to create a join, you must call get_join_to_intermediate_model_statement BEFORE get_join_statement', 'event_espresso' ))); |
|
87 | + public function get_join_statement($model_relation_chain) { |
|
88 | + if ($this->_model_relation_chain_to_join_model === NULL) { |
|
89 | + throw new EE_Error(sprintf(__('When using EE_HABTM_Relation to create a join, you must call get_join_to_intermediate_model_statement BEFORE get_join_statement', 'event_espresso'))); |
|
90 | 90 | } |
91 | 91 | $join_table_fk_field_to_this_table = $this->get_join_model()->get_foreign_key_to($this->get_this_model()->get_this_model_name()); |
92 | - $join_table_alias = EE_Model_Parser::extract_table_alias_model_relation_chain_prefix($this->_model_relation_chain_to_join_model, $this->get_join_model()->get_this_model_name()) . $join_table_fk_field_to_this_table->get_table_alias(); |
|
92 | + $join_table_alias = EE_Model_Parser::extract_table_alias_model_relation_chain_prefix($this->_model_relation_chain_to_join_model, $this->get_join_model()->get_this_model_name()).$join_table_fk_field_to_this_table->get_table_alias(); |
|
93 | 93 | $other_table_pk_field = $this->get_other_model()->get_primary_key_field(); |
94 | 94 | $join_table_fk_field_to_other_table = $this->get_join_model()->get_foreign_key_to($this->get_other_model()->get_this_model_name()); |
95 | - $other_table_alias = EE_Model_Parser::extract_table_alias_model_relation_chain_prefix($model_relation_chain, $this->get_other_model()->get_this_model_name()) . $other_table_pk_field->get_table_alias(); |
|
95 | + $other_table_alias = EE_Model_Parser::extract_table_alias_model_relation_chain_prefix($model_relation_chain, $this->get_other_model()->get_this_model_name()).$other_table_pk_field->get_table_alias(); |
|
96 | 96 | $other_table = $this->get_other_model()->get_table_for_alias($other_table_alias); |
97 | 97 | |
98 | - $SQL = $this->_left_join($other_table, $other_table_alias, $other_table_pk_field->get_table_column(), $join_table_alias, $join_table_fk_field_to_other_table->get_table_column()) . $this->get_other_model()->_construct_internal_join_to_table_with_alias($other_table_alias); |
|
98 | + $SQL = $this->_left_join($other_table, $other_table_alias, $other_table_pk_field->get_table_column(), $join_table_alias, $join_table_fk_field_to_other_table->get_table_column()).$this->get_other_model()->_construct_internal_join_to_table_with_alias($other_table_alias); |
|
99 | 99 | return $SQL; |
100 | 100 | } |
101 | 101 | |
@@ -112,37 +112,37 @@ discard block |
||
112 | 112 | * @return EE_Base_Class |
113 | 113 | * @throws \EE_Error |
114 | 114 | */ |
115 | - public function add_relation_to($this_obj_or_id, $other_obj_or_id, $extra_join_model_fields_n_values = array() ){ |
|
115 | + public function add_relation_to($this_obj_or_id, $other_obj_or_id, $extra_join_model_fields_n_values = array()) { |
|
116 | 116 | $this_model_obj = $this->get_this_model()->ensure_is_obj($this_obj_or_id, true); |
117 | 117 | $other_model_obj = $this->get_other_model()->ensure_is_obj($other_obj_or_id, true); |
118 | 118 | //check if such a relationship already exists |
119 | 119 | $join_model_fk_to_this_model = $this->get_join_model()->get_foreign_key_to($this->get_this_model()->get_this_model_name()); |
120 | 120 | $join_model_fk_to_other_model = $this->get_join_model()->get_foreign_key_to($this->get_other_model()->get_this_model_name()); |
121 | 121 | |
122 | - $cols_n_values = array( |
|
122 | + $cols_n_values = array( |
|
123 | 123 | $join_model_fk_to_this_model->get_name() => $this_model_obj->ID(), |
124 | 124 | $join_model_fk_to_other_model->get_name() => $other_model_obj->ID()); |
125 | 125 | |
126 | 126 | //if $where_query exists lets add them to the query_params. |
127 | - if ( !empty( $extra_join_model_fields_n_values ) ) { |
|
127 | + if ( ! empty($extra_join_model_fields_n_values)) { |
|
128 | 128 | //make sure we strip any of the join model names from the $where_query cause we don't need that in here (why? because client code may have used the same conditionals for get_all_related which DOES need the join model name) |
129 | 129 | //make sure we strip THIS models name from the query param |
130 | 130 | $parsed_query = array(); |
131 | - foreach ( $extra_join_model_fields_n_values as $query_param => $val ) { |
|
132 | - $query_param = str_replace($this->get_join_model()->get_this_model_name().".","", $query_param); |
|
131 | + foreach ($extra_join_model_fields_n_values as $query_param => $val) { |
|
132 | + $query_param = str_replace($this->get_join_model()->get_this_model_name().".", "", $query_param); |
|
133 | 133 | $parsed_query[$query_param] = $val; |
134 | 134 | } |
135 | - $cols_n_values = array_merge( $cols_n_values, $parsed_query ); |
|
135 | + $cols_n_values = array_merge($cols_n_values, $parsed_query); |
|
136 | 136 | } |
137 | 137 | |
138 | - $query_params = array( $cols_n_values ); |
|
138 | + $query_params = array($cols_n_values); |
|
139 | 139 | |
140 | 140 | |
141 | 141 | $existing_entry_in_join_table = $this->get_join_model()->get_one($query_params); |
142 | 142 | //if there is already an entry in the join table, indicating a relationship, we're done |
143 | 143 | //again, if you want more sophisticated logic or insertions (handling more columns than just 2 foreign keys to |
144 | 144 | //the other tables, use the joining model directly! |
145 | - if( ! $existing_entry_in_join_table ){ |
|
145 | + if ( ! $existing_entry_in_join_table) { |
|
146 | 146 | $this->get_join_model()->insert($cols_n_values); |
147 | 147 | } |
148 | 148 | return $other_model_obj; |
@@ -160,30 +160,30 @@ discard block |
||
160 | 160 | * @return EE_Base_Class |
161 | 161 | * @throws \EE_Error |
162 | 162 | */ |
163 | - public function remove_relation_to($this_obj_or_id, $other_obj_or_id, $where_query = array() ){ |
|
163 | + public function remove_relation_to($this_obj_or_id, $other_obj_or_id, $where_query = array()) { |
|
164 | 164 | $this_model_obj = $this->get_this_model()->ensure_is_obj($this_obj_or_id, true); |
165 | 165 | $other_model_obj = $this->get_other_model()->ensure_is_obj($other_obj_or_id, true); |
166 | 166 | //check if such a relationship already exists |
167 | 167 | $join_model_fk_to_this_model = $this->get_join_model()->get_foreign_key_to($this->get_this_model()->get_this_model_name()); |
168 | 168 | $join_model_fk_to_other_model = $this->get_join_model()->get_foreign_key_to($this->get_other_model()->get_this_model_name()); |
169 | 169 | |
170 | - $cols_n_values = array( |
|
170 | + $cols_n_values = array( |
|
171 | 171 | $join_model_fk_to_this_model->get_name() => $this_model_obj->ID(), |
172 | 172 | $join_model_fk_to_other_model->get_name() => $other_model_obj->ID()); |
173 | 173 | |
174 | 174 | //if $where_query exists lets add them to the query_params. |
175 | - if ( !empty( $where_query ) ) { |
|
175 | + if ( ! empty($where_query)) { |
|
176 | 176 | //make sure we strip any of the join model names from the $where_query cause we don't need that in here (why? because client code may have used the same conditionals for get_all_related which DOES need the join model name) |
177 | 177 | //make sure we strip THIS models name from the query param |
178 | 178 | $parsed_query = array(); |
179 | - foreach ( $where_query as $query_param => $val ) { |
|
180 | - $query_param = str_replace($this->get_join_model()->get_this_model_name().".","", $query_param); |
|
179 | + foreach ($where_query as $query_param => $val) { |
|
180 | + $query_param = str_replace($this->get_join_model()->get_this_model_name().".", "", $query_param); |
|
181 | 181 | $parsed_query[$query_param] = $val; |
182 | 182 | } |
183 | - $cols_n_values = array_merge( $cols_n_values, $parsed_query ); |
|
183 | + $cols_n_values = array_merge($cols_n_values, $parsed_query); |
|
184 | 184 | } |
185 | 185 | |
186 | - $this->get_join_model()->delete( array($cols_n_values) ); |
|
186 | + $this->get_join_model()->delete(array($cols_n_values)); |
|
187 | 187 | return $other_model_obj; |
188 | 188 | } |
189 | 189 | } |
@@ -73,7 +73,7 @@ discard block |
||
73 | 73 | |
74 | 74 | /** |
75 | 75 | * Gets the model where this relation is defined. |
76 | - * @return EEM_Base |
|
76 | + * @return boolean |
|
77 | 77 | */ |
78 | 78 | public function get_this_model(){ |
79 | 79 | return $this->_get_model($this->_this_model_name); |
@@ -84,7 +84,7 @@ discard block |
||
84 | 84 | /** |
85 | 85 | * Gets the model which this relation establishes the relation TO (ie, |
86 | 86 | * this relation object was defined on get_this_model(), get_other_model() is the other one) |
87 | - * @return EEM_Base |
|
87 | + * @return boolean |
|
88 | 88 | */ |
89 | 89 | public function get_other_model(){ |
90 | 90 | return $this->_get_model($this->_other_model_name); |
@@ -95,7 +95,7 @@ discard block |
||
95 | 95 | /** |
96 | 96 | * Internally used by get_this_model() and get_other_model() |
97 | 97 | * @param string $model_name like Event, Question_Group, etc. omit the EEM_ |
98 | - * @return EEM_Base |
|
98 | + * @return boolean |
|
99 | 99 | */ |
100 | 100 | protected function _get_model($model_name){ |
101 | 101 | $modelInstance = EE_Registry::instance()->load_model( $model_name ); |
@@ -119,9 +119,9 @@ discard block |
||
119 | 119 | |
120 | 120 | /** |
121 | 121 | * @param $other_table |
122 | - * @param $other_table_alias |
|
122 | + * @param string $other_table_alias |
|
123 | 123 | * @param $other_table_column |
124 | - * @param $this_table_alias |
|
124 | + * @param string $this_table_alias |
|
125 | 125 | * @param $this_table_join_column |
126 | 126 | * @param string $extra_join_sql |
127 | 127 | * @return string |
@@ -163,7 +163,7 @@ discard block |
||
163 | 163 | /** |
164 | 164 | * Alters the $query_params to disable default where conditions, unless otherwise specified |
165 | 165 | * @param string $query_params |
166 | - * @return array |
|
166 | + * @return string |
|
167 | 167 | */ |
168 | 168 | protected function _disable_default_where_conditions_on_query_param($query_params){ |
169 | 169 | if( ! isset($query_params['default_where_conditions'])){ |
@@ -180,7 +180,7 @@ discard block |
||
180 | 180 | * Note: If the related model is extends EEM_Soft_Delete_Base, then the related |
181 | 181 | * model objects will only be soft-deleted. |
182 | 182 | * |
183 | - * @param EE_Base_Class|int|string $model_object_or_id |
|
183 | + * @param EE_Base_Class|null $model_object_or_id |
|
184 | 184 | * @param array $query_params |
185 | 185 | * @return int of how many related models got deleted |
186 | 186 | * @throws \EE_Error |
@@ -210,7 +210,7 @@ discard block |
||
210 | 210 | * Note: If the related model is extends EEM_Soft_Delete_Base, then the related |
211 | 211 | * model objects will only be soft-deleted. |
212 | 212 | * |
213 | - * @param EE_Base_Class|int|string $model_object_or_id |
|
213 | + * @param EE_Base_Class|null $model_object_or_id |
|
214 | 214 | * @param array $query_params |
215 | 215 | * @return int of how many related models got deleted |
216 | 216 | * @throws \EE_Error |
@@ -151,8 +151,8 @@ |
||
151 | 151 | } |
152 | 152 | $query_params = $this->_disable_default_where_conditions_on_query_param($query_params); |
153 | 153 | $query_param_where_this_model_pk = $this->get_this_model()->get_this_model_name() |
154 | - . "." |
|
155 | - . $this->get_this_model()->get_primary_key_field()->get_name(); |
|
154 | + . "." |
|
155 | + . $this->get_this_model()->get_primary_key_field()->get_name(); |
|
156 | 156 | $model_object_id = $this->_get_model_object_id( $model_object_or_id ); |
157 | 157 | $query_params[0][$query_param_where_this_model_pk] = $model_object_id; |
158 | 158 | return $this->get_other_model()->get_all($query_params); |
@@ -13,7 +13,7 @@ discard block |
||
13 | 13 | * @subpackage core |
14 | 14 | * @author Michael Nelson |
15 | 15 | */ |
16 | -abstract class EE_Model_Relation_Base{ |
|
16 | +abstract class EE_Model_Relation_Base { |
|
17 | 17 | /** |
18 | 18 | * The model name of which this relation is a component (ie, the model that called new EE_Model_Relation_Base) |
19 | 19 | * @var string eg Event, Question_Group, Registration |
@@ -48,9 +48,9 @@ discard block |
||
48 | 48 | * @param boolean $block_deletes if there are related models across this relation, block (prevent and add an error) the deletion of this model |
49 | 49 | * @param string $blocking_delete_error_message a customized error message on blocking deletes instead of the default |
50 | 50 | */ |
51 | - public function __construct($block_deletes, $blocking_delete_error_message){ |
|
51 | + public function __construct($block_deletes, $blocking_delete_error_message) { |
|
52 | 52 | $this->_blocking_delete = $block_deletes; |
53 | - $this->_blocking_delete_error_message=$blocking_delete_error_message; |
|
53 | + $this->_blocking_delete_error_message = $blocking_delete_error_message; |
|
54 | 54 | } |
55 | 55 | |
56 | 56 | |
@@ -60,12 +60,12 @@ discard block |
||
60 | 60 | * @param $other_model_name |
61 | 61 | * @throws EE_Error |
62 | 62 | */ |
63 | - public function _construct_finalize_set_models($this_model_name, $other_model_name){ |
|
63 | + public function _construct_finalize_set_models($this_model_name, $other_model_name) { |
|
64 | 64 | $this->_this_model_name = $this_model_name; |
65 | 65 | $this->_other_model_name = $other_model_name; |
66 | - if(is_string($this->_blocking_delete)){ |
|
66 | + if (is_string($this->_blocking_delete)) { |
|
67 | 67 | throw new EE_Error(sprintf(__("When instantiating the relation of type %s from %s to %s, the \$block_deletes argument should be a boolean, not a string (%s)", "event_espresso"), |
68 | - get_class($this),$this_model_name,$other_model_name,$this->_blocking_delete)); |
|
68 | + get_class($this), $this_model_name, $other_model_name, $this->_blocking_delete)); |
|
69 | 69 | } |
70 | 70 | } |
71 | 71 | |
@@ -75,7 +75,7 @@ discard block |
||
75 | 75 | * Gets the model where this relation is defined. |
76 | 76 | * @return EEM_Base |
77 | 77 | */ |
78 | - public function get_this_model(){ |
|
78 | + public function get_this_model() { |
|
79 | 79 | return $this->_get_model($this->_this_model_name); |
80 | 80 | } |
81 | 81 | |
@@ -86,7 +86,7 @@ discard block |
||
86 | 86 | * this relation object was defined on get_this_model(), get_other_model() is the other one) |
87 | 87 | * @return EEM_Base |
88 | 88 | */ |
89 | - public function get_other_model(){ |
|
89 | + public function get_other_model() { |
|
90 | 90 | return $this->_get_model($this->_other_model_name); |
91 | 91 | } |
92 | 92 | |
@@ -97,9 +97,9 @@ discard block |
||
97 | 97 | * @param string $model_name like Event, Question_Group, etc. omit the EEM_ |
98 | 98 | * @return EEM_Base |
99 | 99 | */ |
100 | - protected function _get_model($model_name){ |
|
101 | - $modelInstance = EE_Registry::instance()->load_model( $model_name ); |
|
102 | - $modelInstance->set_timezone( $this->_timezone ); |
|
100 | + protected function _get_model($model_name) { |
|
101 | + $modelInstance = EE_Registry::instance()->load_model($model_name); |
|
102 | + $modelInstance->set_timezone($this->_timezone); |
|
103 | 103 | return $modelInstance; |
104 | 104 | } |
105 | 105 | |
@@ -109,8 +109,8 @@ discard block |
||
109 | 109 | * entirely possible that relations may be called from a model and we need to make sure those relations have their timezone set correctly. |
110 | 110 | * @param string $timezone timezone to set. |
111 | 111 | */ |
112 | - public function set_timezone( $timezone ) { |
|
113 | - if($timezone !== NULL){ |
|
112 | + public function set_timezone($timezone) { |
|
113 | + if ($timezone !== NULL) { |
|
114 | 114 | $this->_timezone = $timezone; |
115 | 115 | } |
116 | 116 | } |
@@ -126,8 +126,8 @@ discard block |
||
126 | 126 | * @param string $extra_join_sql |
127 | 127 | * @return string |
128 | 128 | */ |
129 | - protected function _left_join($other_table,$other_table_alias,$other_table_column,$this_table_alias,$this_table_join_column, $extra_join_sql = ''){ |
|
130 | - return " LEFT JOIN ".$other_table." AS ".$other_table_alias. " ON ".$other_table_alias.".".$other_table_column."=".$this_table_alias.".".$this_table_join_column. ($extra_join_sql ? " AND $extra_join_sql" : ''); |
|
129 | + protected function _left_join($other_table, $other_table_alias, $other_table_column, $this_table_alias, $this_table_join_column, $extra_join_sql = '') { |
|
130 | + return " LEFT JOIN ".$other_table." AS ".$other_table_alias." ON ".$other_table_alias.".".$other_table_column."=".$this_table_alias.".".$this_table_join_column.($extra_join_sql ? " AND $extra_join_sql" : ''); |
|
131 | 131 | } |
132 | 132 | |
133 | 133 | |
@@ -145,15 +145,15 @@ discard block |
||
145 | 145 | * @return EE_Base_Class[] |
146 | 146 | * @throws \EE_Error |
147 | 147 | */ |
148 | - public function get_all_related($model_object_or_id, $query_params = array(), $values_already_prepared_by_model_object = false ){ |
|
149 | - if( $values_already_prepared_by_model_object !== false ) { |
|
150 | - EE_Error::doing_it_wrong( 'EE_Model_Relation_Base::get_all_related', __( 'The argument $values_already_prepared_by_model_object is no longer used.', 'event_espresso' ), '4.8.1' ); |
|
148 | + public function get_all_related($model_object_or_id, $query_params = array(), $values_already_prepared_by_model_object = false) { |
|
149 | + if ($values_already_prepared_by_model_object !== false) { |
|
150 | + EE_Error::doing_it_wrong('EE_Model_Relation_Base::get_all_related', __('The argument $values_already_prepared_by_model_object is no longer used.', 'event_espresso'), '4.8.1'); |
|
151 | 151 | } |
152 | 152 | $query_params = $this->_disable_default_where_conditions_on_query_param($query_params); |
153 | 153 | $query_param_where_this_model_pk = $this->get_this_model()->get_this_model_name() |
154 | 154 | . "." |
155 | 155 | . $this->get_this_model()->get_primary_key_field()->get_name(); |
156 | - $model_object_id = $this->_get_model_object_id( $model_object_or_id ); |
|
156 | + $model_object_id = $this->_get_model_object_id($model_object_or_id); |
|
157 | 157 | $query_params[0][$query_param_where_this_model_pk] = $model_object_id; |
158 | 158 | return $this->get_other_model()->get_all($query_params); |
159 | 159 | } |
@@ -165,9 +165,9 @@ discard block |
||
165 | 165 | * @param string $query_params |
166 | 166 | * @return array |
167 | 167 | */ |
168 | - protected function _disable_default_where_conditions_on_query_param($query_params){ |
|
169 | - if( ! isset($query_params['default_where_conditions'])){ |
|
170 | - $query_params['default_where_conditions']='none'; |
|
168 | + protected function _disable_default_where_conditions_on_query_param($query_params) { |
|
169 | + if ( ! isset($query_params['default_where_conditions'])) { |
|
170 | + $query_params['default_where_conditions'] = 'none'; |
|
171 | 171 | } |
172 | 172 | return $query_params; |
173 | 173 | } |
@@ -185,15 +185,15 @@ discard block |
||
185 | 185 | * @return int of how many related models got deleted |
186 | 186 | * @throws \EE_Error |
187 | 187 | */ |
188 | - public function delete_all_related($model_object_or_id,$query_params = array()){ |
|
188 | + public function delete_all_related($model_object_or_id, $query_params = array()) { |
|
189 | 189 | //for each thing we would delete, |
190 | - $related_model_objects = $this->get_all_related($model_object_or_id,$query_params); |
|
190 | + $related_model_objects = $this->get_all_related($model_object_or_id, $query_params); |
|
191 | 191 | //determine if it's blocked by anything else before it can be deleted |
192 | 192 | $deleted_count = 0; |
193 | - foreach($related_model_objects as $related_model_object){ |
|
193 | + foreach ($related_model_objects as $related_model_object) { |
|
194 | 194 | $delete_is_blocked = $this->get_other_model()->delete_is_blocked_by_related_models($related_model_object, $model_object_or_id); |
195 | 195 | /* @var $model_object_or_id EE_Base_Class */ |
196 | - if( ! $delete_is_blocked ){ |
|
196 | + if ( ! $delete_is_blocked) { |
|
197 | 197 | $this->remove_relation_to($model_object_or_id, $related_model_object); |
198 | 198 | $related_model_object->delete(); |
199 | 199 | $deleted_count++; |
@@ -215,27 +215,27 @@ discard block |
||
215 | 215 | * @return int of how many related models got deleted |
216 | 216 | * @throws \EE_Error |
217 | 217 | */ |
218 | - public function delete_related_permanently($model_object_or_id,$query_params = array()){ |
|
218 | + public function delete_related_permanently($model_object_or_id, $query_params = array()) { |
|
219 | 219 | //for each thing we would delete, |
220 | - $related_model_objects = $this->get_all_related($model_object_or_id,$query_params); |
|
220 | + $related_model_objects = $this->get_all_related($model_object_or_id, $query_params); |
|
221 | 221 | //determine if it's blocked by anything else before it can be deleted |
222 | 222 | $deleted_count = 0; |
223 | - foreach($related_model_objects as $related_model_object){ |
|
223 | + foreach ($related_model_objects as $related_model_object) { |
|
224 | 224 | $delete_is_blocked = $this->get_other_model()->delete_is_blocked_by_related_models($related_model_object, $model_object_or_id); |
225 | 225 | /* @var $model_object_or_id EE_Base_Class */ |
226 | - if( $related_model_object instanceof EE_Soft_Delete_Base_Class ){ |
|
226 | + if ($related_model_object instanceof EE_Soft_Delete_Base_Class) { |
|
227 | 227 | $this->remove_relation_to($model_object_or_id, $related_model_object); |
228 | 228 | $deleted_count++; |
229 | - if( ! $delete_is_blocked ){ |
|
229 | + if ( ! $delete_is_blocked) { |
|
230 | 230 | $related_model_object->delete_permanently(); |
231 | - }else{ |
|
231 | + } else { |
|
232 | 232 | //delete is blocked |
233 | 233 | //brent and darren, in this case, wanted to just soft delete it then |
234 | 234 | $related_model_object->delete(); |
235 | 235 | } |
236 | - }else{ |
|
236 | + } else { |
|
237 | 237 | //its not a soft-deletable thing anyways. do the normal logic. |
238 | - if( ! $delete_is_blocked ){ |
|
238 | + if ( ! $delete_is_blocked) { |
|
239 | 239 | $this->remove_relation_to($model_object_or_id, $related_model_object); |
240 | 240 | $related_model_object->delete(); |
241 | 241 | $deleted_count++; |
@@ -255,11 +255,11 @@ discard block |
||
255 | 255 | */ |
256 | 256 | protected function _get_model_object_id($model_object_or_id) { |
257 | 257 | $model_object_id = $model_object_or_id; |
258 | - if($model_object_or_id instanceof EE_Base_Class){ |
|
258 | + if ($model_object_or_id instanceof EE_Base_Class) { |
|
259 | 259 | $model_object_id = $model_object_or_id->ID(); |
260 | 260 | } |
261 | - if( ! $model_object_id){ |
|
262 | - throw new EE_Error(sprintf(__("Sorry, we cant get the related %s model objects to %s model object before it has an ID. You can solve that by just saving it before trying to get its related model objects", "event_espresso"),$this->get_other_model()->get_this_model_name(),$this->get_this_model()->get_this_model_name())); |
|
261 | + if ( ! $model_object_id) { |
|
262 | + throw new EE_Error(sprintf(__("Sorry, we cant get the related %s model objects to %s model object before it has an ID. You can solve that by just saving it before trying to get its related model objects", "event_espresso"), $this->get_other_model()->get_this_model_name(), $this->get_this_model()->get_this_model_name())); |
|
263 | 263 | } |
264 | 264 | return $model_object_id; |
265 | 265 | } |
@@ -313,10 +313,10 @@ discard block |
||
313 | 313 | * @return EE_Base_Class[] |
314 | 314 | * @throws \EE_Error |
315 | 315 | */ |
316 | - public function remove_relations($this_obj_or_id,$where_query_param = array()){ |
|
317 | - $related_things = $this->get_all_related($this_obj_or_id,array($where_query_param)); |
|
316 | + public function remove_relations($this_obj_or_id, $where_query_param = array()) { |
|
317 | + $related_things = $this->get_all_related($this_obj_or_id, array($where_query_param)); |
|
318 | 318 | $objs_removed = array(); |
319 | - foreach($related_things as $related_thing){ |
|
319 | + foreach ($related_things as $related_thing) { |
|
320 | 320 | $objs_removed[] = $this->remove_relation_to($this_obj_or_id, $related_thing); |
321 | 321 | } |
322 | 322 | return $objs_removed; |
@@ -329,7 +329,7 @@ discard block |
||
329 | 329 | * related objects exist, returns false. |
330 | 330 | * @return boolean |
331 | 331 | */ |
332 | - public function block_delete_if_related_models_exist(){ |
|
332 | + public function block_delete_if_related_models_exist() { |
|
333 | 333 | return $this->_blocking_delete; |
334 | 334 | } |
335 | 335 | |
@@ -338,13 +338,13 @@ discard block |
||
338 | 338 | * Gets the error message to show |
339 | 339 | * @return string |
340 | 340 | */ |
341 | - public function get_deletion_error_message(){ |
|
342 | - if($this->_blocking_delete_error_message){ |
|
341 | + public function get_deletion_error_message() { |
|
342 | + if ($this->_blocking_delete_error_message) { |
|
343 | 343 | return $this->_blocking_delete_error_message; |
344 | - }else{ |
|
344 | + } else { |
|
345 | 345 | // return sprintf(__('Cannot delete %1$s when there are related %2$s', "event_espresso"),$this->get_this_model()->item_name(2),$this->get_other_model()->item_name(2)); |
346 | 346 | return sprintf( |
347 | - __( 'This %1$s is currently linked to one or more %2$s records. If this %1$s is incorrect, then please remove it from all %3$s before attempting to delete it.', "event_espresso"), |
|
347 | + __('This %1$s is currently linked to one or more %2$s records. If this %1$s is incorrect, then please remove it from all %3$s before attempting to delete it.', "event_espresso"), |
|
348 | 348 | $this->get_this_model()->item_name(1), |
349 | 349 | $this->get_other_model()->item_name(1), |
350 | 350 | $this->get_other_model()->item_name(2) |
@@ -228,12 +228,12 @@ discard block |
||
228 | 228 | $deleted_count++; |
229 | 229 | if( ! $delete_is_blocked ){ |
230 | 230 | $related_model_object->delete_permanently(); |
231 | - }else{ |
|
231 | + } else{ |
|
232 | 232 | //delete is blocked |
233 | 233 | //brent and darren, in this case, wanted to just soft delete it then |
234 | 234 | $related_model_object->delete(); |
235 | 235 | } |
236 | - }else{ |
|
236 | + } else{ |
|
237 | 237 | //its not a soft-deletable thing anyways. do the normal logic. |
238 | 238 | if( ! $delete_is_blocked ){ |
239 | 239 | $this->remove_relation_to($model_object_or_id, $related_model_object); |
@@ -341,7 +341,7 @@ discard block |
||
341 | 341 | public function get_deletion_error_message(){ |
342 | 342 | if($this->_blocking_delete_error_message){ |
343 | 343 | return $this->_blocking_delete_error_message; |
344 | - }else{ |
|
344 | + } else{ |
|
345 | 345 | // return sprintf(__('Cannot delete %1$s when there are related %2$s', "event_espresso"),$this->get_this_model()->item_name(2),$this->get_other_model()->item_name(2)); |
346 | 346 | return sprintf( |
347 | 347 | __( 'This %1$s is currently linked to one or more %2$s records. If this %1$s is incorrect, then please remove it from all %3$s before attempting to delete it.', "event_espresso"), |
@@ -403,7 +403,7 @@ |
||
403 | 403 | |
404 | 404 | |
405 | 405 | /** |
406 | - * @param mixed $var |
|
406 | + * @param string $var |
|
407 | 407 | * @param string $var_name |
408 | 408 | * @param string $file |
409 | 409 | * @param int $line |
@@ -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 | * Class EEH_Debug_Tools |
4 | 4 | * |
@@ -8,7 +8,7 @@ discard block |
||
8 | 8 | * @since 4.0 |
9 | 9 | * |
10 | 10 | */ |
11 | -class EEH_Debug_Tools{ |
|
11 | +class EEH_Debug_Tools { |
|
12 | 12 | |
13 | 13 | /** |
14 | 14 | * instance of the EEH_Autoloader object |
@@ -41,7 +41,7 @@ discard block |
||
41 | 41 | */ |
42 | 42 | public static function instance() { |
43 | 43 | // check if class object is instantiated, and instantiated properly |
44 | - if ( ! self::$_instance instanceof EEH_Debug_Tools ) { |
|
44 | + if ( ! self::$_instance instanceof EEH_Debug_Tools) { |
|
45 | 45 | self::$_instance = new self(); |
46 | 46 | } |
47 | 47 | return self::$_instance; |
@@ -57,21 +57,21 @@ discard block |
||
57 | 57 | */ |
58 | 58 | private function __construct() { |
59 | 59 | // load Kint PHP debugging library |
60 | - if ( ! class_exists( 'Kint' ) && file_exists( EE_PLUGIN_DIR_PATH . 'tests' . DS . 'kint' . DS . 'Kint.class.php' )){ |
|
60 | + if ( ! class_exists('Kint') && file_exists(EE_PLUGIN_DIR_PATH.'tests'.DS.'kint'.DS.'Kint.class.php')) { |
|
61 | 61 | // despite EE4 having a check for an existing copy of the Kint debugging class, |
62 | 62 | // if another plugin was loaded AFTER EE4 and they did NOT perform a similar check, |
63 | 63 | // then hilarity would ensue as PHP throws a "Cannot redeclare class Kint" error |
64 | 64 | // so we've moved it to our test folder so that it is not included with production releases |
65 | 65 | // plz use https://wordpress.org/plugins/kint-debugger/ if testing production versions of EE |
66 | - require_once( EE_PLUGIN_DIR_PATH . 'tests' . DS . 'kint' . DS . 'Kint.class.php' ); |
|
66 | + require_once(EE_PLUGIN_DIR_PATH.'tests'.DS.'kint'.DS.'Kint.class.php'); |
|
67 | 67 | } |
68 | 68 | // if ( ! defined('DOING_AJAX') || $_REQUEST['noheader'] !== 'true' || ! isset( $_REQUEST['noheader'], $_REQUEST['TB_iframe'] ) ) { |
69 | 69 | //add_action( 'shutdown', array($this,'espresso_session_footer_dump') ); |
70 | 70 | // } |
71 | - $plugin = basename( EE_PLUGIN_DIR_PATH ); |
|
72 | - add_action( "activate_{$plugin}", array( 'EEH_Debug_Tools', 'ee_plugin_activation_errors' )); |
|
73 | - add_action( 'activated_plugin', array( 'EEH_Debug_Tools', 'ee_plugin_activation_errors' )); |
|
74 | - add_action( 'shutdown', array( 'EEH_Debug_Tools', 'show_db_name' )); |
|
71 | + $plugin = basename(EE_PLUGIN_DIR_PATH); |
|
72 | + add_action("activate_{$plugin}", array('EEH_Debug_Tools', 'ee_plugin_activation_errors')); |
|
73 | + add_action('activated_plugin', array('EEH_Debug_Tools', 'ee_plugin_activation_errors')); |
|
74 | + add_action('shutdown', array('EEH_Debug_Tools', 'show_db_name')); |
|
75 | 75 | } |
76 | 76 | |
77 | 77 | |
@@ -82,8 +82,8 @@ discard block |
||
82 | 82 | * @return void |
83 | 83 | */ |
84 | 84 | public static function show_db_name() { |
85 | - if ( ! defined( 'DOING_AJAX' ) && ( defined( 'EE_ERROR_EMAILS' ) && EE_ERROR_EMAILS )) { |
|
86 | - echo '<p style="font-size:10px;font-weight:normal;color:#E76700;margin: 1em 2em; text-align: right;">DB_NAME: '. DB_NAME .'</p>'; |
|
85 | + if ( ! defined('DOING_AJAX') && (defined('EE_ERROR_EMAILS') && EE_ERROR_EMAILS)) { |
|
86 | + echo '<p style="font-size:10px;font-weight:normal;color:#E76700;margin: 1em 2em; text-align: right;">DB_NAME: '.DB_NAME.'</p>'; |
|
87 | 87 | } |
88 | 88 | } |
89 | 89 | |
@@ -96,15 +96,15 @@ discard block |
||
96 | 96 | */ |
97 | 97 | public function espresso_session_footer_dump() { |
98 | 98 | if ( |
99 | - ( defined( 'WP_DEBUG' ) && WP_DEBUG ) |
|
100 | - && ! defined( 'DOING_AJAX' ) |
|
101 | - && class_exists( 'Kint' ) |
|
102 | - && function_exists( 'wp_get_current_user' ) |
|
103 | - && current_user_can( 'update_core' ) |
|
104 | - && class_exists( 'EE_Registry' ) |
|
99 | + (defined('WP_DEBUG') && WP_DEBUG) |
|
100 | + && ! defined('DOING_AJAX') |
|
101 | + && class_exists('Kint') |
|
102 | + && function_exists('wp_get_current_user') |
|
103 | + && current_user_can('update_core') |
|
104 | + && class_exists('EE_Registry') |
|
105 | 105 | ) { |
106 | - Kint::dump( EE_Registry::instance()->SSN->id() ); |
|
107 | - Kint::dump( EE_Registry::instance()->SSN ); |
|
106 | + Kint::dump(EE_Registry::instance()->SSN->id()); |
|
107 | + Kint::dump(EE_Registry::instance()->SSN); |
|
108 | 108 | // Kint::dump( EE_Registry::instance()->SSN->get_session_data('cart')->get_tickets() ); |
109 | 109 | $this->espresso_list_hooked_functions(); |
110 | 110 | $this->show_times(); |
@@ -121,27 +121,27 @@ discard block |
||
121 | 121 | * @param string $tag |
122 | 122 | * @return void |
123 | 123 | */ |
124 | - public function espresso_list_hooked_functions( $tag='' ){ |
|
124 | + public function espresso_list_hooked_functions($tag = '') { |
|
125 | 125 | global $wp_filter; |
126 | 126 | echo '<br/><br/><br/><h3>Hooked Functions</h3>'; |
127 | - if ( $tag ) { |
|
128 | - $hook[$tag]=$wp_filter[$tag]; |
|
129 | - if ( ! is_array( $hook[$tag] )) { |
|
130 | - trigger_error( "Nothing found for '$tag' hook", E_USER_WARNING ); |
|
127 | + if ($tag) { |
|
128 | + $hook[$tag] = $wp_filter[$tag]; |
|
129 | + if ( ! is_array($hook[$tag])) { |
|
130 | + trigger_error("Nothing found for '$tag' hook", E_USER_WARNING); |
|
131 | 131 | return; |
132 | 132 | } |
133 | - echo '<h5>For Tag: '. $tag .'</h5>'; |
|
133 | + echo '<h5>For Tag: '.$tag.'</h5>'; |
|
134 | 134 | } |
135 | 135 | else { |
136 | - $hook=$wp_filter; |
|
137 | - ksort( $hook ); |
|
136 | + $hook = $wp_filter; |
|
137 | + ksort($hook); |
|
138 | 138 | } |
139 | - foreach( $hook as $tag_name => $priorities ) { |
|
139 | + foreach ($hook as $tag_name => $priorities) { |
|
140 | 140 | echo "<br />>>>>>\t<strong>$tag_name</strong><br />"; |
141 | - ksort( $priorities ); |
|
142 | - foreach( $priorities as $priority => $function ){ |
|
141 | + ksort($priorities); |
|
142 | + foreach ($priorities as $priority => $function) { |
|
143 | 143 | echo $priority; |
144 | - foreach( $function as $name => $properties ) { |
|
144 | + foreach ($function as $name => $properties) { |
|
145 | 145 | echo "\t$name<br />"; |
146 | 146 | } |
147 | 147 | } |
@@ -156,15 +156,15 @@ discard block |
||
156 | 156 | * @param string $hook_name |
157 | 157 | * @return array |
158 | 158 | */ |
159 | - public static function registered_filter_callbacks( $hook_name = '' ) { |
|
159 | + public static function registered_filter_callbacks($hook_name = '') { |
|
160 | 160 | $filters = array(); |
161 | 161 | global $wp_filter; |
162 | - if ( isset( $wp_filter[ $hook_name ] ) ) { |
|
163 | - $filters[ $hook_name ] = array(); |
|
164 | - foreach ( $wp_filter[ $hook_name ] as $priority => $callbacks ) { |
|
165 | - $filters[ $hook_name ][ $priority ] = array(); |
|
166 | - foreach ( $callbacks as $callback ) { |
|
167 | - $filters[ $hook_name ][ $priority ][] = $callback['function']; |
|
162 | + if (isset($wp_filter[$hook_name])) { |
|
163 | + $filters[$hook_name] = array(); |
|
164 | + foreach ($wp_filter[$hook_name] as $priority => $callbacks) { |
|
165 | + $filters[$hook_name][$priority] = array(); |
|
166 | + foreach ($callbacks as $callback) { |
|
167 | + $filters[$hook_name][$priority][] = $callback['function']; |
|
168 | 168 | } |
169 | 169 | } |
170 | 170 | } |
@@ -176,7 +176,7 @@ discard block |
||
176 | 176 | /** |
177 | 177 | * reset_times |
178 | 178 | */ |
179 | - public function reset_times(){ |
|
179 | + public function reset_times() { |
|
180 | 180 | $this->_times = array(); |
181 | 181 | } |
182 | 182 | |
@@ -186,8 +186,8 @@ discard block |
||
186 | 186 | * start_timer |
187 | 187 | * @param null $timer_name |
188 | 188 | */ |
189 | - public function start_timer( $timer_name = NULL ){ |
|
190 | - $this->_start_times[$timer_name] = microtime( TRUE ); |
|
189 | + public function start_timer($timer_name = NULL) { |
|
190 | + $this->_start_times[$timer_name] = microtime(TRUE); |
|
191 | 191 | } |
192 | 192 | |
193 | 193 | |
@@ -196,15 +196,15 @@ discard block |
||
196 | 196 | * stop_timer |
197 | 197 | * @param string $timer_name |
198 | 198 | */ |
199 | - public function stop_timer($timer_name = 'default'){ |
|
200 | - if( isset( $this->_start_times[ $timer_name ] ) ){ |
|
201 | - $start_time = $this->_start_times[ $timer_name ]; |
|
202 | - unset( $this->_start_times[ $timer_name ] ); |
|
203 | - }else{ |
|
204 | - $start_time = array_pop( $this->_start_times ); |
|
199 | + public function stop_timer($timer_name = 'default') { |
|
200 | + if (isset($this->_start_times[$timer_name])) { |
|
201 | + $start_time = $this->_start_times[$timer_name]; |
|
202 | + unset($this->_start_times[$timer_name]); |
|
203 | + } else { |
|
204 | + $start_time = array_pop($this->_start_times); |
|
205 | 205 | } |
206 | - $total_time = microtime( TRUE ) - $start_time; |
|
207 | - switch ( $total_time ) { |
|
206 | + $total_time = microtime(TRUE) - $start_time; |
|
207 | + switch ($total_time) { |
|
208 | 208 | case $total_time < 0.00001 : |
209 | 209 | $color = '#8A549A'; |
210 | 210 | $bold = 'normal'; |
@@ -230,7 +230,7 @@ discard block |
||
230 | 230 | $bold = 'bold'; |
231 | 231 | break; |
232 | 232 | } |
233 | - $this->_times[] = '<hr /><div style="display: inline-block; min-width: 10px; margin:0 1em; color:'.$color.'; font-weight:'.$bold.'; font-size:1.2em;">' . number_format( $total_time, 8 ) . '</div> ' . $timer_name; |
|
233 | + $this->_times[] = '<hr /><div style="display: inline-block; min-width: 10px; margin:0 1em; color:'.$color.'; font-weight:'.$bold.'; font-size:1.2em;">'.number_format($total_time, 8).'</div> '.$timer_name; |
|
234 | 234 | } |
235 | 235 | /** |
236 | 236 | * Measure the memory usage by PHP so far. |
@@ -238,10 +238,10 @@ discard block |
||
238 | 238 | * @param boolean $output_now whether to echo now, or wait until EEH_Debug_Tools::show_times() is called |
239 | 239 | * @return void |
240 | 240 | */ |
241 | - public function measure_memory( $label, $output_now = false ) { |
|
242 | - $memory_used = $this->convert( memory_get_peak_usage( true ) ); |
|
243 | - $this->_memory_usage_points[ $label ] = $memory_used; |
|
244 | - if( $output_now ) { |
|
241 | + public function measure_memory($label, $output_now = false) { |
|
242 | + $memory_used = $this->convert(memory_get_peak_usage(true)); |
|
243 | + $this->_memory_usage_points[$label] = $memory_used; |
|
244 | + if ($output_now) { |
|
245 | 245 | echo "\r\n<br>$label : $memory_used"; |
246 | 246 | } |
247 | 247 | } |
@@ -251,9 +251,9 @@ discard block |
||
251 | 251 | * @param int $size |
252 | 252 | * @return string |
253 | 253 | */ |
254 | - public function convert( $size ) { |
|
255 | - $unit=array('b','kb','mb','gb','tb','pb'); |
|
256 | - return @round( $size / pow( 1024, $i = floor( log( $size, 1024 ) ) ), 2 ) . ' ' . $unit[ absint( $i ) ]; |
|
254 | + public function convert($size) { |
|
255 | + $unit = array('b', 'kb', 'mb', 'gb', 'tb', 'pb'); |
|
256 | + return @round($size / pow(1024, $i = floor(log($size, 1024))), 2).' '.$unit[absint($i)]; |
|
257 | 257 | } |
258 | 258 | |
259 | 259 | |
@@ -263,9 +263,9 @@ discard block |
||
263 | 263 | * @param bool $output_now |
264 | 264 | * @return string |
265 | 265 | */ |
266 | - public function show_times($output_now=true){ |
|
267 | - $output = '<h2>Times:</h2>' . implode("<br>",$this->_times) . '<h2>Memory</h2>' . implode('<br>', $this->_memory_usage_points ); |
|
268 | - if($output_now){ |
|
266 | + public function show_times($output_now = true) { |
|
267 | + $output = '<h2>Times:</h2>'.implode("<br>", $this->_times).'<h2>Memory</h2>'.implode('<br>', $this->_memory_usage_points); |
|
268 | + if ($output_now) { |
|
269 | 269 | echo $output; |
270 | 270 | return ''; |
271 | 271 | } |
@@ -280,25 +280,25 @@ discard block |
||
280 | 280 | * @return void |
281 | 281 | */ |
282 | 282 | public static function ee_plugin_activation_errors() { |
283 | - if ( WP_DEBUG ) { |
|
283 | + if (WP_DEBUG) { |
|
284 | 284 | $activation_errors = ob_get_contents(); |
285 | - if ( ! empty( $activation_errors ) ) { |
|
286 | - $activation_errors = date( 'Y-m-d H:i:s' ) . "\n" . $activation_errors; |
|
285 | + if ( ! empty($activation_errors)) { |
|
286 | + $activation_errors = date('Y-m-d H:i:s')."\n".$activation_errors; |
|
287 | 287 | } |
288 | - espresso_load_required( 'EEH_File', EE_HELPERS . 'EEH_File.helper.php' ); |
|
289 | - if ( class_exists( 'EEH_File' )) { |
|
288 | + espresso_load_required('EEH_File', EE_HELPERS.'EEH_File.helper.php'); |
|
289 | + if (class_exists('EEH_File')) { |
|
290 | 290 | try { |
291 | - EEH_File::ensure_file_exists_and_is_writable( EVENT_ESPRESSO_UPLOAD_DIR . 'logs' . DS . 'espresso_plugin_activation_errors.html' ); |
|
292 | - EEH_File::write_to_file( EVENT_ESPRESSO_UPLOAD_DIR . 'logs' . DS . 'espresso_plugin_activation_errors.html', $activation_errors ); |
|
293 | - } catch( EE_Error $e ){ |
|
294 | - EE_Error::add_error( sprintf( __( 'The Event Espresso activation errors file could not be setup because: %s', 'event_espresso' ), $e->getMessage() ), __FILE__, __FUNCTION__, __LINE__ ); |
|
291 | + EEH_File::ensure_file_exists_and_is_writable(EVENT_ESPRESSO_UPLOAD_DIR.'logs'.DS.'espresso_plugin_activation_errors.html'); |
|
292 | + EEH_File::write_to_file(EVENT_ESPRESSO_UPLOAD_DIR.'logs'.DS.'espresso_plugin_activation_errors.html', $activation_errors); |
|
293 | + } catch (EE_Error $e) { |
|
294 | + EE_Error::add_error(sprintf(__('The Event Espresso activation errors file could not be setup because: %s', 'event_espresso'), $e->getMessage()), __FILE__, __FUNCTION__, __LINE__); |
|
295 | 295 | } |
296 | 296 | } else { |
297 | 297 | // old school attempt |
298 | - file_put_contents( EVENT_ESPRESSO_UPLOAD_DIR . 'logs' . DS . 'espresso_plugin_activation_errors.html', $activation_errors ); |
|
298 | + file_put_contents(EVENT_ESPRESSO_UPLOAD_DIR.'logs'.DS.'espresso_plugin_activation_errors.html', $activation_errors); |
|
299 | 299 | } |
300 | - $activation_errors = get_option( 'ee_plugin_activation_errors', '' ) . $activation_errors; |
|
301 | - update_option( 'ee_plugin_activation_errors', $activation_errors ); |
|
300 | + $activation_errors = get_option('ee_plugin_activation_errors', '').$activation_errors; |
|
301 | + update_option('ee_plugin_activation_errors', $activation_errors); |
|
302 | 302 | } |
303 | 303 | } |
304 | 304 | |
@@ -314,22 +314,22 @@ discard block |
||
314 | 314 | * @param int $error_type |
315 | 315 | * @uses trigger_error() |
316 | 316 | */ |
317 | - public function doing_it_wrong( $function, $message, $version, $error_type = E_USER_NOTICE ) { |
|
318 | - do_action( 'AHEE__EEH_Debug_Tools__doing_it_wrong_run', $function, $message, $version); |
|
319 | - $version = $version === null ? '' : sprintf( __('(This message was added in version %s of Event Espresso.', 'event_espresso' ), $version ); |
|
320 | - $error_message = sprintf( esc_html__('%1$s was called %2$sincorrectly%3$s. %4$s %5$s','event_espresso' ), $function, '<strong>', '</strong>', $message, $version ); |
|
317 | + public function doing_it_wrong($function, $message, $version, $error_type = E_USER_NOTICE) { |
|
318 | + do_action('AHEE__EEH_Debug_Tools__doing_it_wrong_run', $function, $message, $version); |
|
319 | + $version = $version === null ? '' : sprintf(__('(This message was added in version %s of Event Espresso.', 'event_espresso'), $version); |
|
320 | + $error_message = sprintf(esc_html__('%1$s was called %2$sincorrectly%3$s. %4$s %5$s', 'event_espresso'), $function, '<strong>', '</strong>', $message, $version); |
|
321 | 321 | |
322 | 322 | //don't trigger error if doing ajax, instead we'll add a transient EE_Error notice that in theory should show on the next request. |
323 | - if ( defined( 'DOING_AJAX' ) && DOING_AJAX ) { |
|
324 | - $error_message .= esc_html__( 'This is a doing_it_wrong message that was triggered during an ajax request. The request params on this request were: ', 'event_espresso' ); |
|
323 | + if (defined('DOING_AJAX') && DOING_AJAX) { |
|
324 | + $error_message .= esc_html__('This is a doing_it_wrong message that was triggered during an ajax request. The request params on this request were: ', 'event_espresso'); |
|
325 | 325 | $error_message .= '<ul><li>'; |
326 | - $error_message .= implode( '</li><li>', EE_Registry::instance()->REQ->params() ); |
|
326 | + $error_message .= implode('</li><li>', EE_Registry::instance()->REQ->params()); |
|
327 | 327 | $error_message .= '</ul>'; |
328 | - EE_Error::add_error( $error_message, 'debug::doing_it_wrong', $function, '42' ); |
|
328 | + EE_Error::add_error($error_message, 'debug::doing_it_wrong', $function, '42'); |
|
329 | 329 | //now we set this on the transient so it shows up on the next request. |
330 | - EE_Error::get_notices( is_admin(), true ); |
|
330 | + EE_Error::get_notices(is_admin(), true); |
|
331 | 331 | } else { |
332 | - trigger_error( $error_message, $error_type ); |
|
332 | + trigger_error($error_message, $error_type); |
|
333 | 333 | } |
334 | 334 | } |
335 | 335 | |
@@ -351,22 +351,22 @@ discard block |
||
351 | 351 | * @param string $debug_index |
352 | 352 | * @param string $debug_key |
353 | 353 | */ |
354 | - public static function log( $class='', $func = '', $line = '', $info = array(), $display_request = false, $debug_index = '', $debug_key = 'EE_DEBUG_SPCO' ) { |
|
355 | - if ( WP_DEBUG && false ) { |
|
356 | - $debug_key = $debug_key . '_' . EE_Session::instance()->id(); |
|
357 | - $debug_data = get_option( $debug_key, array() ); |
|
354 | + public static function log($class = '', $func = '', $line = '', $info = array(), $display_request = false, $debug_index = '', $debug_key = 'EE_DEBUG_SPCO') { |
|
355 | + if (WP_DEBUG && false) { |
|
356 | + $debug_key = $debug_key.'_'.EE_Session::instance()->id(); |
|
357 | + $debug_data = get_option($debug_key, array()); |
|
358 | 358 | $default_data = array( |
359 | - $class => $func . '() : ' . $line, |
|
359 | + $class => $func.'() : '.$line, |
|
360 | 360 | 'REQ' => $display_request ? $_REQUEST : '', |
361 | 361 | ); |
362 | 362 | // don't serialize objects |
363 | - $info = self::strip_objects( $info ); |
|
364 | - $index = ! empty( $debug_index ) ? $debug_index : 0; |
|
365 | - if ( ! isset( $debug_data[$index] ) ) { |
|
363 | + $info = self::strip_objects($info); |
|
364 | + $index = ! empty($debug_index) ? $debug_index : 0; |
|
365 | + if ( ! isset($debug_data[$index])) { |
|
366 | 366 | $debug_data[$index] = array(); |
367 | 367 | } |
368 | - $debug_data[$index][microtime()] = array_merge( $default_data, $info ); |
|
369 | - update_option( $debug_key, $debug_data ); |
|
368 | + $debug_data[$index][microtime()] = array_merge($default_data, $info); |
|
369 | + update_option($debug_key, $debug_data); |
|
370 | 370 | } |
371 | 371 | } |
372 | 372 | |
@@ -378,26 +378,26 @@ discard block |
||
378 | 378 | * @param array $info |
379 | 379 | * @return array |
380 | 380 | */ |
381 | - public static function strip_objects( $info = array() ) { |
|
382 | - foreach ( $info as $key => $value ) { |
|
383 | - if ( is_array( $value ) ) { |
|
384 | - $info[ $key ] = self::strip_objects( $value ); |
|
385 | - } else if ( is_object( $value ) ) { |
|
386 | - $object_class = get_class( $value ); |
|
387 | - $info[ $object_class ] = array(); |
|
388 | - $info[ $object_class ][ 'ID' ] = method_exists( $value, 'ID' ) ? $value->ID() : spl_object_hash( $value ); |
|
389 | - if ( method_exists( $value, 'ID' ) ) { |
|
390 | - $info[ $object_class ][ 'ID' ] = $value->ID(); |
|
381 | + public static function strip_objects($info = array()) { |
|
382 | + foreach ($info as $key => $value) { |
|
383 | + if (is_array($value)) { |
|
384 | + $info[$key] = self::strip_objects($value); |
|
385 | + } else if (is_object($value)) { |
|
386 | + $object_class = get_class($value); |
|
387 | + $info[$object_class] = array(); |
|
388 | + $info[$object_class]['ID'] = method_exists($value, 'ID') ? $value->ID() : spl_object_hash($value); |
|
389 | + if (method_exists($value, 'ID')) { |
|
390 | + $info[$object_class]['ID'] = $value->ID(); |
|
391 | 391 | } |
392 | - if ( method_exists( $value, 'status' ) ) { |
|
393 | - $info[ $object_class ][ 'status' ] = $value->status(); |
|
394 | - } else if ( method_exists( $value, 'status_ID' ) ) { |
|
395 | - $info[ $object_class ][ 'status' ] = $value->status_ID(); |
|
392 | + if (method_exists($value, 'status')) { |
|
393 | + $info[$object_class]['status'] = $value->status(); |
|
394 | + } else if (method_exists($value, 'status_ID')) { |
|
395 | + $info[$object_class]['status'] = $value->status_ID(); |
|
396 | 396 | } |
397 | - unset( $info[ $key ] ); |
|
397 | + unset($info[$key]); |
|
398 | 398 | } |
399 | 399 | } |
400 | - return (array)$info; |
|
400 | + return (array) $info; |
|
401 | 401 | } |
402 | 402 | |
403 | 403 | |
@@ -410,22 +410,22 @@ discard block |
||
410 | 410 | * @param int $header |
411 | 411 | * @param bool $die |
412 | 412 | */ |
413 | - public static function printv( $var, $var_name = '', $file = __FILE__, $line = __LINE__, $header = 5, $die = false ) { |
|
413 | + public static function printv($var, $var_name = '', $file = __FILE__, $line = __LINE__, $header = 5, $die = false) { |
|
414 | 414 | $var_name = ! $var_name ? 'string' : $var_name; |
415 | 415 | $heading_tag = 'h'; |
416 | - $heading_tag .= is_int( $header ) ? $header : 5; |
|
417 | - $var_name = ucwords( str_replace( '$', '', $var_name ) ); |
|
418 | - $is_method = method_exists( $var_name, $var ); |
|
419 | - $var_name = ucwords( str_replace( '_', ' ', $var_name ) ); |
|
420 | - $result = '<' . $heading_tag . ' style="color:#2EA2CC; margin:25px 0 0;"><b>' . $var_name . '</b>'; |
|
416 | + $heading_tag .= is_int($header) ? $header : 5; |
|
417 | + $var_name = ucwords(str_replace('$', '', $var_name)); |
|
418 | + $is_method = method_exists($var_name, $var); |
|
419 | + $var_name = ucwords(str_replace('_', ' ', $var_name)); |
|
420 | + $result = '<'.$heading_tag.' style="color:#2EA2CC; margin:25px 0 0;"><b>'.$var_name.'</b>'; |
|
421 | 421 | $result .= $is_method |
422 | - ? '<span style="color:#999">::</span><span style="color:#E76700">' . $var . '()</span><br />' |
|
423 | - : '<span style="color:#999"> : </span><span style="color:#E76700">' . $var . '</span><br />'; |
|
424 | - $result .= '<span style="font-size:9px;font-weight:normal;color:#666;line-height: 12px;">' . $file; |
|
425 | - $result .= '<br />line no: ' . $line . '</span>'; |
|
426 | - $result .= '</' . $heading_tag . '>'; |
|
427 | - if ( $die ) { |
|
428 | - die( $result ); |
|
422 | + ? '<span style="color:#999">::</span><span style="color:#E76700">'.$var.'()</span><br />' |
|
423 | + : '<span style="color:#999"> : </span><span style="color:#E76700">'.$var.'</span><br />'; |
|
424 | + $result .= '<span style="font-size:9px;font-weight:normal;color:#666;line-height: 12px;">'.$file; |
|
425 | + $result .= '<br />line no: '.$line.'</span>'; |
|
426 | + $result .= '</'.$heading_tag.'>'; |
|
427 | + if ($die) { |
|
428 | + die($result); |
|
429 | 429 | } else { |
430 | 430 | echo $result; |
431 | 431 | } |
@@ -440,35 +440,35 @@ discard block |
||
440 | 440 | * @param int $header |
441 | 441 | * @param bool $die |
442 | 442 | */ |
443 | - public static function printr( $var, $var_name = '', $file = __FILE__, $line = __LINE__, $header = 5, $die = false ) { |
|
443 | + public static function printr($var, $var_name = '', $file = __FILE__, $line = __LINE__, $header = 5, $die = false) { |
|
444 | 444 | // return; |
445 | - $file = str_replace( rtrim( ABSPATH, '\\/' ), '', $file ); |
|
445 | + $file = str_replace(rtrim(ABSPATH, '\\/'), '', $file); |
|
446 | 446 | //$print_r = false; |
447 | - if ( is_string( $var ) ) { |
|
448 | - EEH_Debug_Tools::printv( $var, $var_name, $file, $line, $header, $die ); |
|
447 | + if (is_string($var)) { |
|
448 | + EEH_Debug_Tools::printv($var, $var_name, $file, $line, $header, $die); |
|
449 | 449 | return; |
450 | - } else if ( is_object( $var ) ) { |
|
450 | + } else if (is_object($var)) { |
|
451 | 451 | $var_name = ! $var_name ? 'object' : $var_name; |
452 | 452 | //$print_r = true; |
453 | - } else if ( is_array( $var ) ) { |
|
453 | + } else if (is_array($var)) { |
|
454 | 454 | $var_name = ! $var_name ? 'array' : $var_name; |
455 | 455 | //$print_r = true; |
456 | - } else if ( is_numeric( $var ) ) { |
|
456 | + } else if (is_numeric($var)) { |
|
457 | 457 | $var_name = ! $var_name ? 'numeric' : $var_name; |
458 | - } else if ( is_null( $var ) ) { |
|
458 | + } else if (is_null($var)) { |
|
459 | 459 | $var_name = ! $var_name ? 'null' : $var_name; |
460 | 460 | } |
461 | 461 | $heading_tag = 'h'; |
462 | - $heading_tag .= is_int( $header ) ? $header : 5; |
|
463 | - $var_name = ucwords( str_replace( array( '$', '_' ), array( '', ' ' ), $var_name ) ); |
|
464 | - $result = '<' . $heading_tag . ' style="color:#2EA2CC; margin:25px 0 0;"><b>' . $var_name . '</b>'; |
|
462 | + $heading_tag .= is_int($header) ? $header : 5; |
|
463 | + $var_name = ucwords(str_replace(array('$', '_'), array('', ' '), $var_name)); |
|
464 | + $result = '<'.$heading_tag.' style="color:#2EA2CC; margin:25px 0 0;"><b>'.$var_name.'</b>'; |
|
465 | 465 | $result .= '<span style="color:#999;"> : </span><span style="color:#E76700;">'; |
466 | 466 | $result .= '<pre style="color:#999; padding:1em; background: #fff">'; |
467 | - $result .= var_export( $var, true ); |
|
468 | - $result .= '</pre></span><br /><span style="font-size:9px;font-weight:normal;color:#666;line-height: 12px;">' . $file; |
|
469 | - $result .= '<br />line no: ' . $line . '</span></' . $heading_tag . '>'; |
|
470 | - if ( $die ) { |
|
471 | - die( $result ); |
|
467 | + $result .= var_export($var, true); |
|
468 | + $result .= '</pre></span><br /><span style="font-size:9px;font-weight:normal;color:#666;line-height: 12px;">'.$file; |
|
469 | + $result .= '<br />line no: '.$line.'</span></'.$heading_tag.'>'; |
|
470 | + if ($die) { |
|
471 | + die($result); |
|
472 | 472 | } else { |
473 | 473 | echo $result; |
474 | 474 | } |
@@ -485,8 +485,8 @@ discard block |
||
485 | 485 | * borrowed from Kint Debugger |
486 | 486 | * Plugin URI: http://upthemes.com/plugins/kint-debugger/ |
487 | 487 | */ |
488 | -if ( class_exists('Kint') && ! function_exists( 'dump_wp_query' ) ) { |
|
489 | - function dump_wp_query(){ |
|
488 | +if (class_exists('Kint') && ! function_exists('dump_wp_query')) { |
|
489 | + function dump_wp_query() { |
|
490 | 490 | global $wp_query; |
491 | 491 | d($wp_query); |
492 | 492 | } |
@@ -496,8 +496,8 @@ discard block |
||
496 | 496 | * borrowed from Kint Debugger |
497 | 497 | * Plugin URI: http://upthemes.com/plugins/kint-debugger/ |
498 | 498 | */ |
499 | -if ( class_exists('Kint') && ! function_exists( 'dump_wp' ) ) { |
|
500 | - function dump_wp(){ |
|
499 | +if (class_exists('Kint') && ! function_exists('dump_wp')) { |
|
500 | + function dump_wp() { |
|
501 | 501 | global $wp; |
502 | 502 | d($wp); |
503 | 503 | } |
@@ -507,8 +507,8 @@ discard block |
||
507 | 507 | * borrowed from Kint Debugger |
508 | 508 | * Plugin URI: http://upthemes.com/plugins/kint-debugger/ |
509 | 509 | */ |
510 | -if ( class_exists('Kint') && ! function_exists( 'dump_post' ) ) { |
|
511 | - function dump_post(){ |
|
510 | +if (class_exists('Kint') && ! function_exists('dump_post')) { |
|
511 | + function dump_post() { |
|
512 | 512 | global $post; |
513 | 513 | d($post); |
514 | 514 | } |
@@ -131,8 +131,7 @@ discard block |
||
131 | 131 | return; |
132 | 132 | } |
133 | 133 | echo '<h5>For Tag: '. $tag .'</h5>'; |
134 | - } |
|
135 | - else { |
|
134 | + } else { |
|
136 | 135 | $hook=$wp_filter; |
137 | 136 | ksort( $hook ); |
138 | 137 | } |
@@ -200,7 +199,7 @@ discard block |
||
200 | 199 | if( isset( $this->_start_times[ $timer_name ] ) ){ |
201 | 200 | $start_time = $this->_start_times[ $timer_name ]; |
202 | 201 | unset( $this->_start_times[ $timer_name ] ); |
203 | - }else{ |
|
202 | + } else{ |
|
204 | 203 | $start_time = array_pop( $this->_start_times ); |
205 | 204 | } |
206 | 205 | $total_time = microtime( TRUE ) - $start_time; |
@@ -251,7 +251,7 @@ discard block |
||
251 | 251 | |
252 | 252 | /** |
253 | 253 | * returns true if ANY reg status was updated during checkout |
254 | - * @return array |
|
254 | + * @return boolean |
|
255 | 255 | */ |
256 | 256 | public function any_reg_status_updated() { |
257 | 257 | foreach ( $this->reg_status_updated as $reg_status ) { |
@@ -276,7 +276,7 @@ discard block |
||
276 | 276 | |
277 | 277 | /** |
278 | 278 | * @param $REG_ID |
279 | - * @param $reg_status |
|
279 | + * @param boolean $reg_status |
|
280 | 280 | */ |
281 | 281 | public function set_reg_status_updated( $REG_ID, $reg_status ) { |
282 | 282 | $this->reg_status_updated[ $REG_ID ] = filter_var( $reg_status, FILTER_VALIDATE_BOOLEAN ); |
@@ -633,7 +633,7 @@ discard block |
||
633 | 633 | * reset_reg_steps |
634 | 634 | * |
635 | 635 | * @access public |
636 | - * @return bool |
|
636 | + * @return boolean|null |
|
637 | 637 | */ |
638 | 638 | public function reset_reg_steps() { |
639 | 639 | $this->sort_reg_steps(); |
@@ -748,7 +748,7 @@ discard block |
||
748 | 748 | * stores whether any updates were made to the TXN or it's related registrations |
749 | 749 | * |
750 | 750 | * @access public |
751 | - * @return bool |
|
751 | + * @return boolean|null |
|
752 | 752 | * @throws \EE_Error |
753 | 753 | */ |
754 | 754 | public function track_transaction_and_registration_status_updates() { |
@@ -1110,6 +1110,7 @@ discard block |
||
1110 | 1110 | * |
1111 | 1111 | * @param string | int $reg_cache_ID |
1112 | 1112 | * @param EE_Registration $registration |
1113 | + * @param integer $reg_cache_ID |
|
1113 | 1114 | * @return void |
1114 | 1115 | * @throws \EE_Error |
1115 | 1116 | */ |
@@ -242,9 +242,9 @@ discard block |
||
242 | 242 | $this->reg_page_base_url = EE_Registry::instance()->CFG->core->reg_page_url(); |
243 | 243 | $this->thank_you_page_url = EE_Registry::instance()->CFG->core->thank_you_page_url(); |
244 | 244 | $this->cancel_page_url = EE_Registry::instance()->CFG->core->cancel_page_url(); |
245 | - $this->continue_reg = apply_filters( 'FHEE__EE_Checkout___construct___continue_reg', TRUE ); |
|
245 | + $this->continue_reg = apply_filters('FHEE__EE_Checkout___construct___continue_reg', TRUE); |
|
246 | 246 | $this->admin_request = is_admin() && ! EE_Registry::instance()->REQ->ajax; |
247 | - $this->reg_cache_where_params = array( 'order_by' => array( 'REG_count' => 'ASC' )); |
|
247 | + $this->reg_cache_where_params = array('order_by' => array('REG_count' => 'ASC')); |
|
248 | 248 | } |
249 | 249 | |
250 | 250 | |
@@ -254,8 +254,8 @@ discard block |
||
254 | 254 | * @return array |
255 | 255 | */ |
256 | 256 | public function any_reg_status_updated() { |
257 | - foreach ( $this->reg_status_updated as $reg_status ) { |
|
258 | - if ( $reg_status ) { |
|
257 | + foreach ($this->reg_status_updated as $reg_status) { |
|
258 | + if ($reg_status) { |
|
259 | 259 | return true; |
260 | 260 | } |
261 | 261 | } |
@@ -268,8 +268,8 @@ discard block |
||
268 | 268 | * @param $REG_ID |
269 | 269 | * @return array |
270 | 270 | */ |
271 | - public function reg_status_updated( $REG_ID ) { |
|
272 | - return isset( $this->reg_status_updated[ $REG_ID ] ) ? $this->reg_status_updated[ $REG_ID ] : false; |
|
271 | + public function reg_status_updated($REG_ID) { |
|
272 | + return isset($this->reg_status_updated[$REG_ID]) ? $this->reg_status_updated[$REG_ID] : false; |
|
273 | 273 | } |
274 | 274 | |
275 | 275 | |
@@ -278,8 +278,8 @@ discard block |
||
278 | 278 | * @param $REG_ID |
279 | 279 | * @param $reg_status |
280 | 280 | */ |
281 | - public function set_reg_status_updated( $REG_ID, $reg_status ) { |
|
282 | - $this->reg_status_updated[ $REG_ID ] = filter_var( $reg_status, FILTER_VALIDATE_BOOLEAN ); |
|
281 | + public function set_reg_status_updated($REG_ID, $reg_status) { |
|
282 | + $this->reg_status_updated[$REG_ID] = filter_var($reg_status, FILTER_VALIDATE_BOOLEAN); |
|
283 | 283 | } |
284 | 284 | |
285 | 285 | |
@@ -300,7 +300,7 @@ discard block |
||
300 | 300 | * can ONLY be set by the Finalize_Registration reg step |
301 | 301 | */ |
302 | 302 | public function set_exit_spco() { |
303 | - if ( $this->current_step instanceof EE_SPCO_Reg_Step_Finalize_Registration ) { |
|
303 | + if ($this->current_step instanceof EE_SPCO_Reg_Step_Finalize_Registration) { |
|
304 | 304 | $this->exit_spco = true; |
305 | 305 | } |
306 | 306 | } |
@@ -317,12 +317,12 @@ discard block |
||
317 | 317 | */ |
318 | 318 | public function reset_for_current_request() { |
319 | 319 | $this->process_form_submission = FALSE; |
320 | - $this->continue_reg = apply_filters( 'FHEE__EE_Checkout___construct___continue_reg', true ); |
|
320 | + $this->continue_reg = apply_filters('FHEE__EE_Checkout___construct___continue_reg', true); |
|
321 | 321 | $this->admin_request = is_admin() && ! EE_Registry::instance()->REQ->front_ajax; |
322 | 322 | $this->continue_reg = true; |
323 | 323 | $this->redirect = false; |
324 | 324 | // don't reset the cached redirect form if we're about to be asked to display it !!! |
325 | - if ( EE_Registry::instance()->REQ->get( 'action', 'display_spco_reg_step' ) !== 'redirect_form' ) { |
|
325 | + if (EE_Registry::instance()->REQ->get('action', 'display_spco_reg_step') !== 'redirect_form') { |
|
326 | 326 | $this->redirect_form = ''; |
327 | 327 | } |
328 | 328 | $this->redirect_url = ''; |
@@ -339,8 +339,8 @@ discard block |
||
339 | 339 | * @param EE_SPCO_Reg_Step $reg_step_obj |
340 | 340 | * @return void |
341 | 341 | */ |
342 | - public function add_reg_step( EE_SPCO_Reg_Step $reg_step_obj ) { |
|
343 | - $this->reg_steps[ $reg_step_obj->slug() ] = $reg_step_obj; |
|
342 | + public function add_reg_step(EE_SPCO_Reg_Step $reg_step_obj) { |
|
343 | + $this->reg_steps[$reg_step_obj->slug()] = $reg_step_obj; |
|
344 | 344 | } |
345 | 345 | |
346 | 346 | |
@@ -356,22 +356,22 @@ discard block |
||
356 | 356 | * @return void |
357 | 357 | * @throws \EE_Error |
358 | 358 | */ |
359 | - public function skip_reg_step( $reg_step_slug = '' ) { |
|
360 | - $step_to_skip = $this->find_reg_step( $reg_step_slug ); |
|
361 | - if ( $step_to_skip instanceof EE_SPCO_Reg_Step && $step_to_skip->is_current_step() ) { |
|
362 | - $step_to_skip->set_is_current_step( false ); |
|
359 | + public function skip_reg_step($reg_step_slug = '') { |
|
360 | + $step_to_skip = $this->find_reg_step($reg_step_slug); |
|
361 | + if ($step_to_skip instanceof EE_SPCO_Reg_Step && $step_to_skip->is_current_step()) { |
|
362 | + $step_to_skip->set_is_current_step(false); |
|
363 | 363 | $step_to_skip->set_completed(); |
364 | 364 | // advance to the next step |
365 | - $this->set_current_step( $this->next_step->slug() ); |
|
365 | + $this->set_current_step($this->next_step->slug()); |
|
366 | 366 | // also reset the step param in the request in case any other code references that directly |
367 | - EE_Registry::instance()->REQ->set( 'step', $this->current_step->slug() ); |
|
367 | + EE_Registry::instance()->REQ->set('step', $this->current_step->slug()); |
|
368 | 368 | // since we are skipping a step and setting the current step to be what was previously the next step, |
369 | 369 | // we need to check that the next step is now correct, and not still set to the current step. |
370 | - if ( $this->current_step->slug() === $this->next_step->slug() ) { |
|
370 | + if ($this->current_step->slug() === $this->next_step->slug()) { |
|
371 | 371 | // correctly setup the next step |
372 | 372 | $this->set_next_step(); |
373 | 373 | } |
374 | - $this->set_reg_step_initiated( $this->current_step ); |
|
374 | + $this->set_reg_step_initiated($this->current_step); |
|
375 | 375 | } |
376 | 376 | } |
377 | 377 | |
@@ -385,16 +385,16 @@ discard block |
||
385 | 385 | * @param bool $reset whether to reset reg steps after removal |
386 | 386 | * @throws EE_Error |
387 | 387 | */ |
388 | - public function remove_reg_step( $reg_step_slug = '', $reset = true ) { |
|
389 | - unset( $this->reg_steps[ $reg_step_slug ] ); |
|
390 | - if ( $this->transaction instanceof EE_Transaction ) { |
|
388 | + public function remove_reg_step($reg_step_slug = '', $reset = true) { |
|
389 | + unset($this->reg_steps[$reg_step_slug]); |
|
390 | + if ($this->transaction instanceof EE_Transaction) { |
|
391 | 391 | /** @type EE_Transaction_Processor $transaction_processor */ |
392 | - $transaction_processor = EE_Registry::instance()->load_class( 'Transaction_Processor' ); |
|
392 | + $transaction_processor = EE_Registry::instance()->load_class('Transaction_Processor'); |
|
393 | 393 | // now remove reg step from TXN and save |
394 | - $transaction_processor->remove_reg_step( $this->transaction, $reg_step_slug ); |
|
394 | + $transaction_processor->remove_reg_step($this->transaction, $reg_step_slug); |
|
395 | 395 | $this->transaction->save(); |
396 | 396 | } |
397 | - if ( $reset ) { |
|
397 | + if ($reset) { |
|
398 | 398 | $this->reset_reg_steps(); |
399 | 399 | } |
400 | 400 | } |
@@ -409,9 +409,9 @@ discard block |
||
409 | 409 | * @param int $order |
410 | 410 | * @return void |
411 | 411 | */ |
412 | - public function set_reg_step_order( $reg_step_slug = '', $order = 100 ) { |
|
413 | - if ( isset( $this->reg_steps[ $reg_step_slug ] )) { |
|
414 | - $this->reg_steps[ $reg_step_slug ]->set_order( $order ); |
|
412 | + public function set_reg_step_order($reg_step_slug = '', $order = 100) { |
|
413 | + if (isset($this->reg_steps[$reg_step_slug])) { |
|
414 | + $this->reg_steps[$reg_step_slug]->set_order($order); |
|
415 | 415 | } |
416 | 416 | } |
417 | 417 | |
@@ -424,25 +424,25 @@ discard block |
||
424 | 424 | * @param string $current_step |
425 | 425 | * @return void |
426 | 426 | */ |
427 | - public function set_current_step( $current_step ) { |
|
427 | + public function set_current_step($current_step) { |
|
428 | 428 | // grab what step we're on |
429 | - $this->current_step = isset( $this->reg_steps[ $current_step ] ) ? $this->reg_steps[ $current_step ] : reset( $this->reg_steps ); |
|
429 | + $this->current_step = isset($this->reg_steps[$current_step]) ? $this->reg_steps[$current_step] : reset($this->reg_steps); |
|
430 | 430 | // verify instance |
431 | - if ( $this->current_step instanceof EE_SPCO_Reg_Step ) { |
|
431 | + if ($this->current_step instanceof EE_SPCO_Reg_Step) { |
|
432 | 432 | // we don't want to repeat completed steps if this is the first time through SPCO |
433 | - if ( $this->continue_reg && ! $this->revisit && $this->current_step->completed() ) { |
|
433 | + if ($this->continue_reg && ! $this->revisit && $this->current_step->completed()) { |
|
434 | 434 | // so advance to the next step |
435 | 435 | $this->set_next_step(); |
436 | - if ( $this->next_step instanceof EE_SPCO_Reg_Step ) { |
|
436 | + if ($this->next_step instanceof EE_SPCO_Reg_Step) { |
|
437 | 437 | // and attempt to set it as the current step |
438 | - $this->set_current_step( $this->next_step->slug() ); |
|
438 | + $this->set_current_step($this->next_step->slug()); |
|
439 | 439 | } |
440 | 440 | return; |
441 | 441 | } |
442 | - $this->current_step->set_is_current_step( TRUE ); |
|
442 | + $this->current_step->set_is_current_step(TRUE); |
|
443 | 443 | } else { |
444 | 444 | EE_Error::add_error( |
445 | - __( 'The current step could not be set.', 'event_espresso' ), |
|
445 | + __('The current step could not be set.', 'event_espresso'), |
|
446 | 446 | __FILE__, __FUNCTION__, __LINE__ |
447 | 447 | ); |
448 | 448 | } |
@@ -459,20 +459,20 @@ discard block |
||
459 | 459 | */ |
460 | 460 | public function set_next_step() { |
461 | 461 | // set pointer to start of array |
462 | - reset( $this->reg_steps ); |
|
462 | + reset($this->reg_steps); |
|
463 | 463 | // if there is more than one step |
464 | - if ( count( $this->reg_steps ) > 1 ) { |
|
464 | + if (count($this->reg_steps) > 1) { |
|
465 | 465 | // advance to the current step and set pointer |
466 | - while ( key( $this->reg_steps ) !== $this->current_step->slug() && key( $this->reg_steps ) !== '' ) { |
|
467 | - next( $this->reg_steps ); |
|
466 | + while (key($this->reg_steps) !== $this->current_step->slug() && key($this->reg_steps) !== '') { |
|
467 | + next($this->reg_steps); |
|
468 | 468 | } |
469 | 469 | } |
470 | 470 | // advance one more spot ( if it exists ) |
471 | - $this->next_step = next( $this->reg_steps ); |
|
471 | + $this->next_step = next($this->reg_steps); |
|
472 | 472 | // verify instance |
473 | - $this->next_step = $this->next_step instanceof EE_SPCO_Reg_Step ? $this->next_step : NULL; |
|
473 | + $this->next_step = $this->next_step instanceof EE_SPCO_Reg_Step ? $this->next_step : NULL; |
|
474 | 474 | // then back to current step to reset |
475 | - prev( $this->reg_steps ); |
|
475 | + prev($this->reg_steps); |
|
476 | 476 | } |
477 | 477 | |
478 | 478 | |
@@ -486,8 +486,8 @@ discard block |
||
486 | 486 | * @return EE_SPCO_Reg_Step | null |
487 | 487 | */ |
488 | 488 | public function get_next_reg_step() { |
489 | - $next = next( $this->reg_steps ); |
|
490 | - prev( $this->reg_steps ); |
|
489 | + $next = next($this->reg_steps); |
|
490 | + prev($this->reg_steps); |
|
491 | 491 | return $next instanceof EE_SPCO_Reg_Step ? $next : null; |
492 | 492 | } |
493 | 493 | |
@@ -502,8 +502,8 @@ discard block |
||
502 | 502 | * @return EE_SPCO_Reg_Step | null |
503 | 503 | */ |
504 | 504 | public function get_prev_reg_step() { |
505 | - $prev = prev( $this->reg_steps ); |
|
506 | - next( $this->reg_steps ); |
|
505 | + $prev = prev($this->reg_steps); |
|
506 | + next($this->reg_steps); |
|
507 | 507 | return $prev instanceof EE_SPCO_Reg_Step ? $prev : null; |
508 | 508 | } |
509 | 509 | |
@@ -516,8 +516,8 @@ discard block |
||
516 | 516 | * @return void |
517 | 517 | */ |
518 | 518 | public function sort_reg_steps() { |
519 | - $reg_step_sorting_callback = apply_filters( 'FHEE__EE_Checkout__sort_reg_steps__reg_step_sorting_callback', 'reg_step_sorting_callback' ); |
|
520 | - uasort( $this->reg_steps, array( $this, $reg_step_sorting_callback )); |
|
519 | + $reg_step_sorting_callback = apply_filters('FHEE__EE_Checkout__sort_reg_steps__reg_step_sorting_callback', 'reg_step_sorting_callback'); |
|
520 | + uasort($this->reg_steps, array($this, $reg_step_sorting_callback)); |
|
521 | 521 | } |
522 | 522 | |
523 | 523 | |
@@ -530,19 +530,19 @@ discard block |
||
530 | 530 | * @param string $reg_step_slug |
531 | 531 | * @return EE_SPCO_Reg_Step|null |
532 | 532 | */ |
533 | - public function find_reg_step( $reg_step_slug = '' ) { |
|
534 | - if ( ! empty( $reg_step_slug ) ) { |
|
533 | + public function find_reg_step($reg_step_slug = '') { |
|
534 | + if ( ! empty($reg_step_slug)) { |
|
535 | 535 | // copy reg step array |
536 | 536 | $reg_steps = $this->reg_steps; |
537 | 537 | // set pointer to start of array |
538 | - reset( $reg_steps ); |
|
538 | + reset($reg_steps); |
|
539 | 539 | // if there is more than one step |
540 | - if ( count( $reg_steps ) > 1 ) { |
|
540 | + if (count($reg_steps) > 1) { |
|
541 | 541 | // advance to the current step and set pointer |
542 | - while ( key( $reg_steps ) !== $reg_step_slug && key( $reg_steps ) !== '' ) { |
|
543 | - next( $reg_steps ); |
|
542 | + while (key($reg_steps) !== $reg_step_slug && key($reg_steps) !== '') { |
|
543 | + next($reg_steps); |
|
544 | 544 | } |
545 | - return current( $reg_steps ); |
|
545 | + return current($reg_steps); |
|
546 | 546 | } |
547 | 547 | } |
548 | 548 | return null; |
@@ -558,17 +558,17 @@ discard block |
||
558 | 558 | * @param EE_SPCO_Reg_Step $reg_step_B |
559 | 559 | * @return array() |
560 | 560 | */ |
561 | - public function reg_step_sorting_callback( EE_SPCO_Reg_Step $reg_step_A, EE_SPCO_Reg_Step $reg_step_B ) { |
|
561 | + public function reg_step_sorting_callback(EE_SPCO_Reg_Step $reg_step_A, EE_SPCO_Reg_Step $reg_step_B) { |
|
562 | 562 | // send finalize_registration step to the end of the array |
563 | - if ( $reg_step_A->slug() === 'finalize_registration' ) { |
|
563 | + if ($reg_step_A->slug() === 'finalize_registration') { |
|
564 | 564 | return 1; |
565 | - } else if ( $reg_step_B->slug() === 'finalize_registration' ) { |
|
565 | + } else if ($reg_step_B->slug() === 'finalize_registration') { |
|
566 | 566 | return -1; |
567 | 567 | } |
568 | - if ( $reg_step_A->order() === $reg_step_B->order() ) { |
|
568 | + if ($reg_step_A->order() === $reg_step_B->order()) { |
|
569 | 569 | return 0; |
570 | 570 | } |
571 | - return ( $reg_step_A->order() > $reg_step_B->order() ) ? 1 : -1; |
|
571 | + return ($reg_step_A->order() > $reg_step_B->order()) ? 1 : -1; |
|
572 | 572 | } |
573 | 573 | |
574 | 574 | |
@@ -580,7 +580,7 @@ discard block |
||
580 | 580 | * @param EE_SPCO_Reg_Step $reg_step |
581 | 581 | * @throws \EE_Error |
582 | 582 | */ |
583 | - public function set_reg_step_initiated( EE_SPCO_Reg_Step $reg_step ) { |
|
583 | + public function set_reg_step_initiated(EE_SPCO_Reg_Step $reg_step) { |
|
584 | 584 | // call set_reg_step_initiated ??? |
585 | 585 | if ( |
586 | 586 | // first time visiting SPCO ? |
@@ -593,13 +593,13 @@ discard block |
||
593 | 593 | ) |
594 | 594 | ) { |
595 | 595 | /** @type EE_Transaction_Processor $transaction_processor */ |
596 | - $transaction_processor = EE_Registry::instance()->load_class( 'Transaction_Processor' ); |
|
596 | + $transaction_processor = EE_Registry::instance()->load_class('Transaction_Processor'); |
|
597 | 597 | // set the start time for this reg step |
598 | - if ( ! $transaction_processor->set_reg_step_initiated( $this->transaction, $reg_step->slug() ) ) { |
|
599 | - if ( WP_DEBUG ) { |
|
598 | + if ( ! $transaction_processor->set_reg_step_initiated($this->transaction, $reg_step->slug())) { |
|
599 | + if (WP_DEBUG) { |
|
600 | 600 | EE_Error::add_error( |
601 | 601 | sprintf( |
602 | - __( 'The "%1$s" registration step was not initialized properly.', 'event_espresso' ), |
|
602 | + __('The "%1$s" registration step was not initialized properly.', 'event_espresso'), |
|
603 | 603 | $reg_step->name() |
604 | 604 | ), |
605 | 605 | __FILE__, __FUNCTION__, __LINE__ |
@@ -618,10 +618,10 @@ discard block |
||
618 | 618 | * @return void |
619 | 619 | */ |
620 | 620 | public function set_reg_step_JSON_info() { |
621 | - EE_Registry::$i18n_js_strings[ 'reg_steps' ] = array(); |
|
621 | + EE_Registry::$i18n_js_strings['reg_steps'] = array(); |
|
622 | 622 | // pass basic reg step data to JS |
623 | - foreach ( $this->reg_steps as $reg_step ) { |
|
624 | - EE_Registry::$i18n_js_strings[ 'reg_steps' ][] = $reg_step->slug(); |
|
623 | + foreach ($this->reg_steps as $reg_step) { |
|
624 | + EE_Registry::$i18n_js_strings['reg_steps'][] = $reg_step->slug(); |
|
625 | 625 | } |
626 | 626 | // reset reg step html |
627 | 627 | // $this->json_response->set_reg_step_html( '' ); |
@@ -637,7 +637,7 @@ discard block |
||
637 | 637 | */ |
638 | 638 | public function reset_reg_steps() { |
639 | 639 | $this->sort_reg_steps(); |
640 | - $this->set_current_step( EE_Registry::instance()->REQ->get( 'step' )); |
|
640 | + $this->set_current_step(EE_Registry::instance()->REQ->get('step')); |
|
641 | 641 | $this->set_next_step(); |
642 | 642 | // the text that appears on the reg step form submit button |
643 | 643 | $this->current_step->set_submit_button_text(); |
@@ -654,9 +654,9 @@ discard block |
||
654 | 654 | */ |
655 | 655 | public function get_registration_time_limit() { |
656 | 656 | |
657 | - $registration_time_limit = (float)( EE_Registry::instance() ->SSN->expiration() - time() ); |
|
657 | + $registration_time_limit = (float) (EE_Registry::instance() ->SSN->expiration() - time()); |
|
658 | 658 | $time_limit_format = $registration_time_limit > 60 * MINUTE_IN_SECONDS ? 'H:i:s' : 'i:s'; |
659 | - $registration_time_limit = gmdate( $time_limit_format, $registration_time_limit ); |
|
659 | + $registration_time_limit = gmdate($time_limit_format, $registration_time_limit); |
|
660 | 660 | return apply_filters( |
661 | 661 | 'FHEE__EE_Checkout__get_registration_time_limit__registration_time_limit', |
662 | 662 | $registration_time_limit |
@@ -676,7 +676,7 @@ discard block |
||
676 | 676 | // overpaid TXN |
677 | 677 | // free TXN ( total = 0.00 ) |
678 | 678 | // then payment required is TRUE |
679 | - return ! ( $this->admin_request || $this->transaction->is_completed() || $this->transaction->is_overpaid() || $this->transaction->is_free() ) ? TRUE : FALSE; |
|
679 | + return ! ($this->admin_request || $this->transaction->is_completed() || $this->transaction->is_overpaid() || $this->transaction->is_free()) ? TRUE : FALSE; |
|
680 | 680 | } |
681 | 681 | |
682 | 682 | |
@@ -689,8 +689,8 @@ discard block |
||
689 | 689 | */ |
690 | 690 | public function initialize_txn_reg_steps_array() { |
691 | 691 | $txn_reg_steps_array = array(); |
692 | - foreach ( $this->reg_steps as $reg_step ) { |
|
693 | - $txn_reg_steps_array[ $reg_step->slug() ] = FALSE; |
|
692 | + foreach ($this->reg_steps as $reg_step) { |
|
693 | + $txn_reg_steps_array[$reg_step->slug()] = FALSE; |
|
694 | 694 | } |
695 | 695 | return $txn_reg_steps_array; |
696 | 696 | } |
@@ -707,15 +707,15 @@ discard block |
||
707 | 707 | public function update_txn_reg_steps_array() { |
708 | 708 | $updated = false; |
709 | 709 | /** @type EE_Transaction_Processor $transaction_processor */ |
710 | - $transaction_processor = EE_Registry::instance()->load_class( 'Transaction_Processor' ); |
|
711 | - foreach ( $this->reg_steps as $reg_step ) { |
|
712 | - if ( $reg_step->completed() ) { |
|
713 | - $updated = $transaction_processor->set_reg_step_completed( $this->transaction, $reg_step->slug() ) |
|
710 | + $transaction_processor = EE_Registry::instance()->load_class('Transaction_Processor'); |
|
711 | + foreach ($this->reg_steps as $reg_step) { |
|
712 | + if ($reg_step->completed()) { |
|
713 | + $updated = $transaction_processor->set_reg_step_completed($this->transaction, $reg_step->slug()) |
|
714 | 714 | ? true |
715 | 715 | : $updated; |
716 | 716 | } |
717 | 717 | } |
718 | - if ( $updated ) { |
|
718 | + if ($updated) { |
|
719 | 719 | $this->transaction->save(); |
720 | 720 | } |
721 | 721 | return $updated; |
@@ -731,14 +731,14 @@ discard block |
||
731 | 731 | * @throws \EE_Error |
732 | 732 | */ |
733 | 733 | public function stash_transaction_and_checkout() { |
734 | - if ( ! $this->revisit ) { |
|
734 | + if ( ! $this->revisit) { |
|
735 | 735 | $this->update_txn_reg_steps_array(); |
736 | 736 | } |
737 | 737 | $this->track_transaction_and_registration_status_updates(); |
738 | 738 | // save all data to the db, but suppress errors |
739 | 739 | //$this->save_all_data( FALSE ); |
740 | 740 | // cache the checkout in the session |
741 | - EE_Registry::instance()->SSN->set_checkout( $this ); |
|
741 | + EE_Registry::instance()->SSN->set_checkout($this); |
|
742 | 742 | } |
743 | 743 | |
744 | 744 | |
@@ -753,21 +753,21 @@ discard block |
||
753 | 753 | */ |
754 | 754 | public function track_transaction_and_registration_status_updates() { |
755 | 755 | // verify the transaction |
756 | - if ( $this->transaction instanceof EE_Transaction ) { |
|
756 | + if ($this->transaction instanceof EE_Transaction) { |
|
757 | 757 | /** @type EE_Transaction_Payments $transaction_payments */ |
758 | - $transaction_payments = EE_Registry::instance()->load_class( 'Transaction_Payments' ); |
|
758 | + $transaction_payments = EE_Registry::instance()->load_class('Transaction_Payments'); |
|
759 | 759 | /** @type EE_Transaction_Processor $transaction_processor */ |
760 | - $transaction_processor = EE_Registry::instance()->load_class( 'Transaction_Processor' ); |
|
760 | + $transaction_processor = EE_Registry::instance()->load_class('Transaction_Processor'); |
|
761 | 761 | // has there been a TXN status change during this checkout? |
762 | - if ( $transaction_payments->txn_status_updated() || $transaction_processor->txn_status_updated() ) { |
|
762 | + if ($transaction_payments->txn_status_updated() || $transaction_processor->txn_status_updated()) { |
|
763 | 763 | $this->txn_status_updated = true; |
764 | 764 | } |
765 | 765 | /** @type EE_Registration_Processor $registration_processor */ |
766 | - $registration_processor = EE_Registry::instance()->load_class( 'Registration_Processor' ); |
|
766 | + $registration_processor = EE_Registry::instance()->load_class('Registration_Processor'); |
|
767 | 767 | // grab the saved registrations from the transaction |
768 | - foreach ( $this->transaction->registrations( $this->reg_cache_where_params ) as $registration ) { |
|
769 | - if ( $registration_processor->reg_status_updated( $registration->ID() ) ) { |
|
770 | - $this->set_reg_status_updated( $registration->ID(), true ); |
|
768 | + foreach ($this->transaction->registrations($this->reg_cache_where_params) as $registration) { |
|
769 | + if ($registration_processor->reg_status_updated($registration->ID())) { |
|
770 | + $this->set_reg_status_updated($registration->ID(), true); |
|
771 | 771 | } |
772 | 772 | } |
773 | 773 | } |
@@ -788,7 +788,7 @@ discard block |
||
788 | 788 | * @return bool |
789 | 789 | * @throws \EE_Error |
790 | 790 | */ |
791 | - public function visit_allows_processing_of_this_registration( EE_Registration $registration ) { |
|
791 | + public function visit_allows_processing_of_this_registration(EE_Registration $registration) { |
|
792 | 792 | return ! $this->revisit |
793 | 793 | || $this->primary_revisit |
794 | 794 | || ( |
@@ -821,18 +821,18 @@ discard block |
||
821 | 821 | * @return bool |
822 | 822 | * @throws \EE_Error |
823 | 823 | */ |
824 | - public function save_all_data( $show_errors = TRUE ) { |
|
824 | + public function save_all_data($show_errors = TRUE) { |
|
825 | 825 | // verify the transaction |
826 | - if ( $this->transaction instanceof EE_Transaction ) { |
|
826 | + if ($this->transaction instanceof EE_Transaction) { |
|
827 | 827 | // save to ensure that TXN has ID |
828 | 828 | $this->transaction->save(); |
829 | 829 | // grab the saved registrations from the transaction |
830 | - foreach ( $this->transaction->registrations( $this->reg_cache_where_params ) as $registration ) { |
|
831 | - $this->_save_registration( $registration, $show_errors ); |
|
830 | + foreach ($this->transaction->registrations($this->reg_cache_where_params) as $registration) { |
|
831 | + $this->_save_registration($registration, $show_errors); |
|
832 | 832 | } |
833 | 833 | } else { |
834 | - if ( $show_errors ) { |
|
835 | - EE_Error::add_error( __( 'A valid Transaction was not found when attempting to save your registration information.', 'event_espresso' ), __FILE__, __FUNCTION__, __LINE__); |
|
834 | + if ($show_errors) { |
|
835 | + EE_Error::add_error(__('A valid Transaction was not found when attempting to save your registration information.', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__); |
|
836 | 836 | } |
837 | 837 | return FALSE; |
838 | 838 | } |
@@ -849,32 +849,32 @@ discard block |
||
849 | 849 | * @return void |
850 | 850 | * @throws \EE_Error |
851 | 851 | */ |
852 | - private function _save_registration( $registration, $show_errors = TRUE ) { |
|
852 | + private function _save_registration($registration, $show_errors = TRUE) { |
|
853 | 853 | // verify object |
854 | - if ( $registration instanceof EE_Registration ) { |
|
854 | + if ($registration instanceof EE_Registration) { |
|
855 | 855 | // should this registration be processed during this visit ? |
856 | - if ( $this->visit_allows_processing_of_this_registration( $registration ) ) { |
|
856 | + if ($this->visit_allows_processing_of_this_registration($registration)) { |
|
857 | 857 | //set TXN ID |
858 | - if ( ! $registration->transaction_ID() ) { |
|
859 | - $registration->set_transaction_id( $this->transaction->ID() ); |
|
858 | + if ( ! $registration->transaction_ID()) { |
|
859 | + $registration->set_transaction_id($this->transaction->ID()); |
|
860 | 860 | } |
861 | 861 | // verify and save the attendee |
862 | - $this->_save_registration_attendee( $registration, $show_errors ); |
|
862 | + $this->_save_registration_attendee($registration, $show_errors); |
|
863 | 863 | // save answers to reg form questions |
864 | - $this->_save_registration_answers( $registration, $show_errors ); |
|
864 | + $this->_save_registration_answers($registration, $show_errors); |
|
865 | 865 | // save changes |
866 | 866 | $registration->save(); |
867 | 867 | // update txn cache |
868 | - if ( ! $this->transaction->update_cache_after_object_save( 'Registration', $registration )) { |
|
869 | - if ( $show_errors ) { |
|
870 | - EE_Error::add_error( __( 'The newly saved Registration object could not be cached on the Transaction.', 'event_espresso' ), __FILE__, __FUNCTION__, __LINE__); |
|
868 | + if ( ! $this->transaction->update_cache_after_object_save('Registration', $registration)) { |
|
869 | + if ($show_errors) { |
|
870 | + EE_Error::add_error(__('The newly saved Registration object could not be cached on the Transaction.', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__); |
|
871 | 871 | } |
872 | 872 | } |
873 | 873 | } |
874 | 874 | } else { |
875 | - if ( $show_errors ) { |
|
875 | + if ($show_errors) { |
|
876 | 876 | EE_Error::add_error( |
877 | - __( 'An invalid Registration object was discovered when attempting to save your registration information.', 'event_espresso' ), |
|
877 | + __('An invalid Registration object was discovered when attempting to save your registration information.', 'event_espresso'), |
|
878 | 878 | __FILE__, __FUNCTION__, __LINE__ |
879 | 879 | ); |
880 | 880 | } |
@@ -891,25 +891,25 @@ discard block |
||
891 | 891 | * @return void |
892 | 892 | * @throws \EE_Error |
893 | 893 | */ |
894 | - private function _save_registration_attendee( $registration, $show_errors = TRUE ) { |
|
895 | - if ( $registration->attendee() instanceof EE_Attendee ) { |
|
894 | + private function _save_registration_attendee($registration, $show_errors = TRUE) { |
|
895 | + if ($registration->attendee() instanceof EE_Attendee) { |
|
896 | 896 | // save so that ATT has ID |
897 | 897 | $registration->attendee()->save(); |
898 | - if ( ! $registration->update_cache_after_object_save( 'Attendee', $registration->attendee() ) ) { |
|
899 | - if ( $show_errors ) { |
|
898 | + if ( ! $registration->update_cache_after_object_save('Attendee', $registration->attendee())) { |
|
899 | + if ($show_errors) { |
|
900 | 900 | EE_Error::add_error( |
901 | - __( 'The newly saved Attendee object could not be cached on the registration.', 'event_espresso' ), |
|
901 | + __('The newly saved Attendee object could not be cached on the registration.', 'event_espresso'), |
|
902 | 902 | __FILE__, __FUNCTION__, __LINE__ |
903 | 903 | ); |
904 | 904 | } |
905 | 905 | } |
906 | 906 | } else { |
907 | - if ( $show_errors ) { |
|
907 | + if ($show_errors) { |
|
908 | 908 | EE_Error::add_error( |
909 | 909 | sprintf( |
910 | 910 | '%1$s||%1$s $attendee = %2$s', |
911 | - __( 'Either no Attendee information was found, or an invalid Attendee object was discovered when attempting to save your registration information.', 'event_espresso' ), |
|
912 | - var_export( $registration->attendee(), true ) |
|
911 | + __('Either no Attendee information was found, or an invalid Attendee object was discovered when attempting to save your registration information.', 'event_espresso'), |
|
912 | + var_export($registration->attendee(), true) |
|
913 | 913 | ), |
914 | 914 | __FILE__, __FUNCTION__, __LINE__ |
915 | 915 | ); |
@@ -927,25 +927,25 @@ discard block |
||
927 | 927 | * @return void |
928 | 928 | * @throws \EE_Error |
929 | 929 | */ |
930 | - private function _save_registration_answers( $registration, $show_errors = TRUE ) { |
|
930 | + private function _save_registration_answers($registration, $show_errors = TRUE) { |
|
931 | 931 | // now save the answers |
932 | - foreach ( $registration->answers() as $cache_key => $answer ) { |
|
932 | + foreach ($registration->answers() as $cache_key => $answer) { |
|
933 | 933 | // verify object |
934 | - if ( $answer instanceof EE_Answer ) { |
|
935 | - $answer->set_registration( $registration->ID() ); |
|
934 | + if ($answer instanceof EE_Answer) { |
|
935 | + $answer->set_registration($registration->ID()); |
|
936 | 936 | $answer->save(); |
937 | - if ( ! $registration->update_cache_after_object_save( 'Answer', $answer, $cache_key )) { |
|
938 | - if ( $show_errors ) { |
|
937 | + if ( ! $registration->update_cache_after_object_save('Answer', $answer, $cache_key)) { |
|
938 | + if ($show_errors) { |
|
939 | 939 | EE_Error::add_error( |
940 | - __( 'The newly saved Answer object could not be cached on the registration.', 'event_espresso' ), |
|
940 | + __('The newly saved Answer object could not be cached on the registration.', 'event_espresso'), |
|
941 | 941 | __FILE__, __FUNCTION__, __LINE__ |
942 | 942 | ); |
943 | 943 | } |
944 | 944 | } |
945 | 945 | } else { |
946 | - if ( $show_errors ) { |
|
946 | + if ($show_errors) { |
|
947 | 947 | EE_Error::add_error( |
948 | - __( 'An invalid Answer object was discovered when attempting to save your registration information.', 'event_espresso' ), |
|
948 | + __('An invalid Answer object was discovered when attempting to save your registration information.', 'event_espresso'), |
|
949 | 949 | __FILE__, __FUNCTION__, __LINE__ |
950 | 950 | ); |
951 | 951 | } |
@@ -964,7 +964,7 @@ discard block |
||
964 | 964 | * @return bool |
965 | 965 | * @throws \EE_Error |
966 | 966 | */ |
967 | - public function refresh_all_entities( $from_db = false ) { |
|
967 | + public function refresh_all_entities($from_db = false) { |
|
968 | 968 | $from_db = $this->current_step->is_final_step() || $this->action === 'process_gateway_response' |
969 | 969 | ? true |
970 | 970 | : $from_db; |
@@ -988,11 +988,11 @@ discard block |
||
988 | 988 | */ |
989 | 989 | protected function refresh_from_db() { |
990 | 990 | // verify the transaction |
991 | - if ( $this->transaction instanceof EE_Transaction && $this->transaction->ID() ) { |
|
991 | + if ($this->transaction instanceof EE_Transaction && $this->transaction->ID()) { |
|
992 | 992 | // pull fresh TXN data from the db |
993 | - $this->transaction = $this->transaction->get_model()->refresh_entity_map_from_db( $this->transaction->ID() ); |
|
993 | + $this->transaction = $this->transaction->get_model()->refresh_entity_map_from_db($this->transaction->ID()); |
|
994 | 994 | // update EE_Checkout's cached primary_attendee object |
995 | - $this->primary_attendee_obj = $this->_refresh_primary_attendee_obj_from_db( $this->transaction ); |
|
995 | + $this->primary_attendee_obj = $this->_refresh_primary_attendee_obj_from_db($this->transaction); |
|
996 | 996 | // update EE_Checkout's cached payment object |
997 | 997 | $payment = $this->transaction->last_payment(); |
998 | 998 | $this->payment = $payment instanceof EE_Payment ? $payment : $this->payment; |
@@ -1000,15 +1000,15 @@ discard block |
||
1000 | 1000 | $payment_method = $this->payment instanceof EE_Payment ? $this->payment->payment_method() : null; |
1001 | 1001 | $this->payment_method = $payment_method instanceof EE_Payment_Method ? $payment_method : $this->payment_method; |
1002 | 1002 | //now refresh the cart, based on the TXN |
1003 | - $this->cart = EE_Cart::get_cart_from_txn( $this->transaction ); |
|
1003 | + $this->cart = EE_Cart::get_cart_from_txn($this->transaction); |
|
1004 | 1004 | // verify and update the cart because inaccurate totals are not so much fun |
1005 | - if ( $this->cart instanceof EE_Cart ) { |
|
1005 | + if ($this->cart instanceof EE_Cart) { |
|
1006 | 1006 | $this->cart->get_grand_total()->recalculate_total_including_taxes(); |
1007 | 1007 | } else { |
1008 | - $this->cart = EE_Registry::instance()->load_core( 'Cart' ); |
|
1008 | + $this->cart = EE_Registry::instance()->load_core('Cart'); |
|
1009 | 1009 | } |
1010 | 1010 | } else { |
1011 | - EE_Error::add_error( __( 'A valid Transaction was not found when attempting to update the model entity mapper.', 'event_espresso' ), __FILE__, __FUNCTION__, __LINE__); |
|
1011 | + EE_Error::add_error(__('A valid Transaction was not found when attempting to update the model entity mapper.', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__); |
|
1012 | 1012 | return FALSE; |
1013 | 1013 | } |
1014 | 1014 | return TRUE; |
@@ -1023,21 +1023,21 @@ discard block |
||
1023 | 1023 | * @return EE_Attendee | null |
1024 | 1024 | * @throws \EE_Error |
1025 | 1025 | */ |
1026 | - protected function _refresh_primary_attendee_obj_from_db( EE_Transaction $transaction ) { |
|
1026 | + protected function _refresh_primary_attendee_obj_from_db(EE_Transaction $transaction) { |
|
1027 | 1027 | |
1028 | 1028 | $primary_attendee_obj = null; |
1029 | 1029 | // grab the saved registrations from the transaction |
1030 | - foreach ( $transaction->registrations( $this->reg_cache_where_params, true ) as $registration ) { |
|
1030 | + foreach ($transaction->registrations($this->reg_cache_where_params, true) as $registration) { |
|
1031 | 1031 | // verify object |
1032 | - if ( $registration instanceof EE_Registration ) { |
|
1032 | + if ($registration instanceof EE_Registration) { |
|
1033 | 1033 | $attendee = $registration->attendee(); |
1034 | 1034 | // verify object && maybe cache primary_attendee_obj ? |
1035 | - if ( $attendee instanceof EE_Attendee&& $registration->is_primary_registrant() ) { |
|
1035 | + if ($attendee instanceof EE_Attendee && $registration->is_primary_registrant()) { |
|
1036 | 1036 | $primary_attendee_obj = $attendee; |
1037 | 1037 | } |
1038 | 1038 | } else { |
1039 | 1039 | EE_Error::add_error( |
1040 | - __( 'An invalid Registration object was discovered when attempting to update the model entity mapper.', 'event_espresso' ), |
|
1040 | + __('An invalid Registration object was discovered when attempting to update the model entity mapper.', 'event_espresso'), |
|
1041 | 1041 | __FILE__, __FUNCTION__, __LINE__ |
1042 | 1042 | ); |
1043 | 1043 | } |
@@ -1058,45 +1058,45 @@ discard block |
||
1058 | 1058 | */ |
1059 | 1059 | protected function refresh_entity_map() { |
1060 | 1060 | // verify the transaction |
1061 | - if ( $this->transaction instanceof EE_Transaction && $this->transaction->ID() ) { |
|
1061 | + if ($this->transaction instanceof EE_Transaction && $this->transaction->ID()) { |
|
1062 | 1062 | // never cache payment info |
1063 | - $this->transaction->clear_cache( 'Payment' ); |
|
1063 | + $this->transaction->clear_cache('Payment'); |
|
1064 | 1064 | /** @type EE_Transaction_Processor $transaction_processor */ |
1065 | - $transaction_processor = EE_Registry::instance()->load_class( 'Transaction_Processor' ); |
|
1065 | + $transaction_processor = EE_Registry::instance()->load_class('Transaction_Processor'); |
|
1066 | 1066 | // is the Payment Options Reg Step completed ? |
1067 | - if ( $transaction_processor->reg_step_completed( $this->transaction, 'payment_options' ) ) { |
|
1067 | + if ($transaction_processor->reg_step_completed($this->transaction, 'payment_options')) { |
|
1068 | 1068 | // then check for payments and update TXN accordingly |
1069 | 1069 | /** @type EE_Transaction_Payments $transaction_payments */ |
1070 | - $transaction_payments = EE_Registry::instance()->load_class( 'Transaction_Payments' ); |
|
1071 | - $transaction_payments->calculate_total_payments_and_update_status( $this->transaction ); |
|
1070 | + $transaction_payments = EE_Registry::instance()->load_class('Transaction_Payments'); |
|
1071 | + $transaction_payments->calculate_total_payments_and_update_status($this->transaction); |
|
1072 | 1072 | } |
1073 | 1073 | // grab the saved registrations from the transaction |
1074 | 1074 | foreach ( |
1075 | - $this->transaction->registrations( $this->reg_cache_where_params ) as $reg_cache_ID => $registration |
|
1075 | + $this->transaction->registrations($this->reg_cache_where_params) as $reg_cache_ID => $registration |
|
1076 | 1076 | ) { |
1077 | - $this->_refresh_registration( $reg_cache_ID, $registration ); |
|
1077 | + $this->_refresh_registration($reg_cache_ID, $registration); |
|
1078 | 1078 | } |
1079 | 1079 | // make sure our cached TXN is added to the model entity mapper |
1080 | - $this->transaction = $this->transaction->get_model()->refresh_entity_map_with( $this->transaction->ID(), $this->transaction ); |
|
1080 | + $this->transaction = $this->transaction->get_model()->refresh_entity_map_with($this->transaction->ID(), $this->transaction); |
|
1081 | 1081 | |
1082 | 1082 | } else { |
1083 | - EE_Error::add_error( __( 'A valid Transaction was not found when attempting to update the model entity mapper.', 'event_espresso' ), __FILE__, __FUNCTION__, __LINE__); |
|
1083 | + EE_Error::add_error(__('A valid Transaction was not found when attempting to update the model entity mapper.', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__); |
|
1084 | 1084 | return FALSE; |
1085 | 1085 | } |
1086 | 1086 | // verify and update the cart because inaccurate totals are not so much fun |
1087 | - if ( $this->cart instanceof EE_Cart ) { |
|
1087 | + if ($this->cart instanceof EE_Cart) { |
|
1088 | 1088 | $grand_total = $this->cart->get_grand_total(); |
1089 | - if ( $grand_total instanceof EE_Line_Item && $grand_total->ID() ) { |
|
1089 | + if ($grand_total instanceof EE_Line_Item && $grand_total->ID()) { |
|
1090 | 1090 | $grand_total->recalculate_total_including_taxes(); |
1091 | 1091 | $grand_total = $grand_total->get_model()->refresh_entity_map_with( |
1092 | 1092 | $this->cart->get_grand_total()->ID(), |
1093 | 1093 | $this->cart->get_grand_total() |
1094 | 1094 | ); |
1095 | 1095 | } |
1096 | - if ( $grand_total instanceof EE_Line_Item ) { |
|
1097 | - $this->cart = EE_Cart::instance( $grand_total ); |
|
1096 | + if ($grand_total instanceof EE_Line_Item) { |
|
1097 | + $this->cart = EE_Cart::instance($grand_total); |
|
1098 | 1098 | } else { |
1099 | - EE_Error::add_error( __( 'A valid Cart was not found when attempting to update the model entity mapper.', 'event_espresso' ), __FILE__, __FUNCTION__, __LINE__ ); |
|
1099 | + EE_Error::add_error(__('A valid Cart was not found when attempting to update the model entity mapper.', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__); |
|
1100 | 1100 | return false; |
1101 | 1101 | } |
1102 | 1102 | } |
@@ -1113,19 +1113,19 @@ discard block |
||
1113 | 1113 | * @return void |
1114 | 1114 | * @throws \EE_Error |
1115 | 1115 | */ |
1116 | - protected function _refresh_registration( $reg_cache_ID, $registration ) { |
|
1116 | + protected function _refresh_registration($reg_cache_ID, $registration) { |
|
1117 | 1117 | |
1118 | 1118 | // verify object |
1119 | - if ( $registration instanceof EE_Registration ) { |
|
1119 | + if ($registration instanceof EE_Registration) { |
|
1120 | 1120 | // update the entity mapper attendee |
1121 | - $this->_refresh_registration_attendee( $registration ); |
|
1121 | + $this->_refresh_registration_attendee($registration); |
|
1122 | 1122 | // update the entity mapper answers for reg form questions |
1123 | - $this->_refresh_registration_answers( $registration ); |
|
1123 | + $this->_refresh_registration_answers($registration); |
|
1124 | 1124 | // make sure the cached registration is added to the model entity mapper |
1125 | - $registration->get_model()->refresh_entity_map_with( $reg_cache_ID, $registration ); |
|
1125 | + $registration->get_model()->refresh_entity_map_with($reg_cache_ID, $registration); |
|
1126 | 1126 | } else { |
1127 | 1127 | EE_Error::add_error( |
1128 | - __( 'An invalid Registration object was discovered when attempting to update the model entity mapper.', 'event_espresso' ), |
|
1128 | + __('An invalid Registration object was discovered when attempting to update the model entity mapper.', 'event_espresso'), |
|
1129 | 1129 | __FILE__, __FUNCTION__, __LINE__ |
1130 | 1130 | ); |
1131 | 1131 | } |
@@ -1140,15 +1140,15 @@ discard block |
||
1140 | 1140 | * @return void |
1141 | 1141 | * @throws \EE_Error |
1142 | 1142 | */ |
1143 | - protected function _refresh_registration_attendee( $registration ) { |
|
1143 | + protected function _refresh_registration_attendee($registration) { |
|
1144 | 1144 | |
1145 | 1145 | $attendee = $registration->attendee(); |
1146 | 1146 | // verify object |
1147 | - if ( $attendee instanceof EE_Attendee && $attendee->ID() ) { |
|
1147 | + if ($attendee instanceof EE_Attendee && $attendee->ID()) { |
|
1148 | 1148 | // make sure the cached attendee is added to the model entity mapper |
1149 | - $registration->attendee()->get_model()->refresh_entity_map_with( $attendee->ID(), $attendee ); |
|
1149 | + $registration->attendee()->get_model()->refresh_entity_map_with($attendee->ID(), $attendee); |
|
1150 | 1150 | // maybe cache primary_attendee_obj ? |
1151 | - if ( $registration->is_primary_registrant() ) { |
|
1151 | + if ($registration->is_primary_registrant()) { |
|
1152 | 1152 | $this->primary_attendee_obj = $attendee; |
1153 | 1153 | } |
1154 | 1154 | } |
@@ -1163,19 +1163,19 @@ discard block |
||
1163 | 1163 | * @return void |
1164 | 1164 | * @throws \EE_Error |
1165 | 1165 | */ |
1166 | - protected function _refresh_registration_answers( $registration ) { |
|
1166 | + protected function _refresh_registration_answers($registration) { |
|
1167 | 1167 | |
1168 | 1168 | // now update the answers |
1169 | - foreach ( $registration->answers() as $cache_key => $answer ) { |
|
1169 | + foreach ($registration->answers() as $cache_key => $answer) { |
|
1170 | 1170 | // verify object |
1171 | - if ( $answer instanceof EE_Answer ) { |
|
1172 | - if ( $answer->ID() ) { |
|
1171 | + if ($answer instanceof EE_Answer) { |
|
1172 | + if ($answer->ID()) { |
|
1173 | 1173 | // make sure the cached answer is added to the model entity mapper |
1174 | - $answer->get_model()->refresh_entity_map_with( $answer->ID(), $answer ); |
|
1174 | + $answer->get_model()->refresh_entity_map_with($answer->ID(), $answer); |
|
1175 | 1175 | } |
1176 | 1176 | } else { |
1177 | 1177 | EE_Error::add_error( |
1178 | - __( 'An invalid Answer object was discovered when attempting to update the model entity mapper.', 'event_espresso' ), |
|
1178 | + __('An invalid Answer object was discovered when attempting to update the model entity mapper.', 'event_espresso'), |
|
1179 | 1179 | __FILE__, __FUNCTION__, __LINE__ |
1180 | 1180 | ); |
1181 | 1181 | } |
@@ -1190,7 +1190,7 @@ discard block |
||
1190 | 1190 | * this will reinstate the EE_Checkout object on each EE_SPCO_Reg_Step object |
1191 | 1191 | */ |
1192 | 1192 | public function __wakeup() { |
1193 | - foreach ( $this->reg_steps as $reg_step ) { |
|
1193 | + foreach ($this->reg_steps as $reg_step) { |
|
1194 | 1194 | $reg_step->checkout = $this; |
1195 | 1195 | } |
1196 | 1196 | } |
@@ -1207,12 +1207,12 @@ discard block |
||
1207 | 1207 | * @param bool $display_request |
1208 | 1208 | * @throws \EE_Error |
1209 | 1209 | */ |
1210 | - public function log( $class = '', $func = '', $line = '', $info = array(), $display_request = false ) { |
|
1210 | + public function log($class = '', $func = '', $line = '', $info = array(), $display_request = false) { |
|
1211 | 1211 | $disabled = true; |
1212 | - if ( WP_DEBUG && ! $disabled ) { |
|
1213 | - $debug_data = get_option( 'EE_DEBUG_SPCO_' . EE_Session::instance()->id(), array() ); |
|
1212 | + if (WP_DEBUG && ! $disabled) { |
|
1213 | + $debug_data = get_option('EE_DEBUG_SPCO_'.EE_Session::instance()->id(), array()); |
|
1214 | 1214 | $default_data = array( |
1215 | - $class => $func . '() : ' . $line, |
|
1215 | + $class => $func.'() : '.$line, |
|
1216 | 1216 | 'request->step' => $this->step, |
1217 | 1217 | 'request->action' => $this->action, |
1218 | 1218 | 'current_step->slug' => $this->current_step instanceof EE_SPCO_Reg_Step ? |
@@ -1224,24 +1224,24 @@ discard block |
||
1224 | 1224 | 'reg_url_link' => $this->reg_url_link, |
1225 | 1225 | 'REQ' => $display_request ? $_REQUEST : '', |
1226 | 1226 | ); |
1227 | - if ( $this->transaction instanceof EE_Transaction ) { |
|
1228 | - $default_data[ 'TXN_status' ] = $this->transaction->status_ID(); |
|
1229 | - $default_data[ 'TXN_reg_steps' ] = $this->transaction->reg_steps(); |
|
1230 | - foreach ( $this->transaction->registrations( $this->reg_cache_where_params ) as $REG_ID => $registration ) { |
|
1231 | - $default_data[ 'registrations' ][ $REG_ID ] = $registration->status_ID(); |
|
1227 | + if ($this->transaction instanceof EE_Transaction) { |
|
1228 | + $default_data['TXN_status'] = $this->transaction->status_ID(); |
|
1229 | + $default_data['TXN_reg_steps'] = $this->transaction->reg_steps(); |
|
1230 | + foreach ($this->transaction->registrations($this->reg_cache_where_params) as $REG_ID => $registration) { |
|
1231 | + $default_data['registrations'][$REG_ID] = $registration->status_ID(); |
|
1232 | 1232 | } |
1233 | - if ( $this->transaction->ID() ) { |
|
1234 | - $TXN_ID = 'EE_Transaction: ' . $this->transaction->ID(); |
|
1233 | + if ($this->transaction->ID()) { |
|
1234 | + $TXN_ID = 'EE_Transaction: '.$this->transaction->ID(); |
|
1235 | 1235 | // don't serialize objects |
1236 | - $info = $this->_strip_objects( $info ); |
|
1237 | - if ( ! isset( $debug_data[ $TXN_ID ] ) ) { |
|
1238 | - $debug_data[ $TXN_ID ] = array(); |
|
1236 | + $info = $this->_strip_objects($info); |
|
1237 | + if ( ! isset($debug_data[$TXN_ID])) { |
|
1238 | + $debug_data[$TXN_ID] = array(); |
|
1239 | 1239 | } |
1240 | - $debug_data[ $TXN_ID ][ microtime() ] = array_merge( |
|
1240 | + $debug_data[$TXN_ID][microtime()] = array_merge( |
|
1241 | 1241 | $default_data, |
1242 | 1242 | $info |
1243 | 1243 | ); |
1244 | - update_option( 'EE_DEBUG_SPCO_' . EE_Session::instance()->id(), $debug_data ); |
|
1244 | + update_option('EE_DEBUG_SPCO_'.EE_Session::instance()->id(), $debug_data); |
|
1245 | 1245 | } |
1246 | 1246 | } |
1247 | 1247 | } |
@@ -1254,23 +1254,23 @@ discard block |
||
1254 | 1254 | * @param array $info |
1255 | 1255 | * @return array |
1256 | 1256 | */ |
1257 | - public function _strip_objects( $info = array() ) { |
|
1258 | - foreach ( (array)$info as $key => $value ) { |
|
1259 | - if ( is_array( $value )) { |
|
1260 | - $info[ $key ] = $this->_strip_objects( $value ); |
|
1261 | - } else if ( is_object( $value ) ) { |
|
1262 | - $object_class = get_class( $value ); |
|
1263 | - $info[ $object_class ] = array(); |
|
1264 | - $info[ $object_class ][ 'ID' ] = method_exists( $value, 'ID' ) ? $value->ID() : 0; |
|
1265 | - if ( method_exists( $value, 'status' ) ) { |
|
1266 | - $info[ $object_class ][ 'status' ] = $value->status(); |
|
1267 | - } else if ( method_exists( $value, 'status_ID' ) ) { |
|
1268 | - $info[ $object_class ][ 'status' ] = $value->status_ID(); |
|
1257 | + public function _strip_objects($info = array()) { |
|
1258 | + foreach ((array) $info as $key => $value) { |
|
1259 | + if (is_array($value)) { |
|
1260 | + $info[$key] = $this->_strip_objects($value); |
|
1261 | + } else if (is_object($value)) { |
|
1262 | + $object_class = get_class($value); |
|
1263 | + $info[$object_class] = array(); |
|
1264 | + $info[$object_class]['ID'] = method_exists($value, 'ID') ? $value->ID() : 0; |
|
1265 | + if (method_exists($value, 'status')) { |
|
1266 | + $info[$object_class]['status'] = $value->status(); |
|
1267 | + } else if (method_exists($value, 'status_ID')) { |
|
1268 | + $info[$object_class]['status'] = $value->status_ID(); |
|
1269 | 1269 | } |
1270 | - unset( $info[ $key ] ); |
|
1270 | + unset($info[$key]); |
|
1271 | 1271 | } |
1272 | 1272 | } |
1273 | - return (array)$info; |
|
1273 | + return (array) $info; |
|
1274 | 1274 | } |
1275 | 1275 | |
1276 | 1276 |
@@ -8,7 +8,7 @@ discard block |
||
8 | 8 | * @subpackage core |
9 | 9 | * @author Michael Nelson |
10 | 10 | */ |
11 | -class EE_HABTM_Any_Relation extends EE_HABTM_Relation{ |
|
11 | +class EE_HABTM_Any_Relation extends EE_HABTM_Relation { |
|
12 | 12 | /** |
13 | 13 | * |
14 | 14 | * @var string |
@@ -22,8 +22,8 @@ discard block |
||
22 | 22 | * @param boolean $block_deletes for this type of relation, we block by default for now. if there are related models across this relation, block (prevent and add an error) the deletion of this model |
23 | 23 | * @param string $blocking_delete_error_message a customized error message on blocking deletes instead of the default |
24 | 24 | */ |
25 | - public function __construct( $block_deletes = true, $blocking_delete_error_message =''){ |
|
26 | - parent::__construct( 'Extra_Join', $block_deletes, $blocking_delete_error_message); |
|
25 | + public function __construct($block_deletes = true, $blocking_delete_error_message = '') { |
|
26 | + parent::__construct('Extra_Join', $block_deletes, $blocking_delete_error_message); |
|
27 | 27 | } |
28 | 28 | |
29 | 29 | |
@@ -33,13 +33,13 @@ discard block |
||
33 | 33 | * @param $other_model_name |
34 | 34 | * @throws EE_Error |
35 | 35 | */ |
36 | - public function _construct_finalize_set_models( $this_model_name, $other_model_name){ |
|
37 | - if( $this_model_name < $other_model_name ) { |
|
36 | + public function _construct_finalize_set_models($this_model_name, $other_model_name) { |
|
37 | + if ($this_model_name < $other_model_name) { |
|
38 | 38 | $this->_alphabetically_first_model_name = $this_model_name; |
39 | - } else{ |
|
39 | + } else { |
|
40 | 40 | $this->_alphabetically_first_model_name = $other_model_name; |
41 | 41 | } |
42 | - parent::_construct_finalize_set_models( $this_model_name, $other_model_name ); |
|
42 | + parent::_construct_finalize_set_models($this_model_name, $other_model_name); |
|
43 | 43 | } |
44 | 44 | |
45 | 45 | |
@@ -50,14 +50,14 @@ discard block |
||
50 | 50 | * @return EE_Model_Field_Base |
51 | 51 | * @throws \EE_Error |
52 | 52 | */ |
53 | - public function get_join_table_fk_field_to( $model_name, $id_or_name_field ) { |
|
53 | + public function get_join_table_fk_field_to($model_name, $id_or_name_field) { |
|
54 | 54 | $order = null; |
55 | - if( $model_name === $this->_alphabetically_first_model_name ) { |
|
55 | + if ($model_name === $this->_alphabetically_first_model_name) { |
|
56 | 56 | $order = 'first'; |
57 | 57 | } else { |
58 | 58 | $order = 'second'; |
59 | 59 | } |
60 | - return $this->get_join_model()->field_settings_for( 'EXJ_' . $order . '_model_' . $id_or_name_field ); |
|
60 | + return $this->get_join_model()->field_settings_for('EXJ_'.$order.'_model_'.$id_or_name_field); |
|
61 | 61 | } |
62 | 62 | |
63 | 63 | |
@@ -69,7 +69,7 @@ discard block |
||
69 | 69 | * @return string of SQL |
70 | 70 | * @throws \EE_Error |
71 | 71 | */ |
72 | - public function get_join_to_intermediate_model_statement($model_relation_chain){ |
|
72 | + public function get_join_to_intermediate_model_statement($model_relation_chain) { |
|
73 | 73 | //create sql like |
74 | 74 | //LEFT JOIN join_table AS join_table_alias ON this_table_alias.this_table_pk = join_table_alias.join_table_fk_to_this |
75 | 75 | //LEFT JOIN other_table AS other_table_alias ON join_table_alias.join_table_fk_to_other = other_table_alias.other_table_pk |
@@ -83,8 +83,8 @@ discard block |
||
83 | 83 | $field_with_model_name = $this->get_join_table_fk_field_to( |
84 | 84 | $this->get_this_model()->get_this_model_name(), |
85 | 85 | 'name' ); |
86 | - $this_table_alias = EE_Model_Parser::extract_table_alias_model_relation_chain_prefix($model_relation_chain, $this->get_this_model()->get_this_model_name()) . $this_table_pk_field->get_table_alias(); |
|
87 | - $join_table_alias = EE_Model_Parser::extract_table_alias_model_relation_chain_prefix($model_relation_chain, $this->get_join_model()->get_this_model_name()) . $join_table_fk_field_to_this_table->get_table_alias(); |
|
86 | + $this_table_alias = EE_Model_Parser::extract_table_alias_model_relation_chain_prefix($model_relation_chain, $this->get_this_model()->get_this_model_name()).$this_table_pk_field->get_table_alias(); |
|
87 | + $join_table_alias = EE_Model_Parser::extract_table_alias_model_relation_chain_prefix($model_relation_chain, $this->get_join_model()->get_this_model_name()).$join_table_fk_field_to_this_table->get_table_alias(); |
|
88 | 88 | $join_table = $this->get_join_model()->get_table_for_alias($join_table_alias); |
89 | 89 | //phew! ok, we have all the info we need, now we can create the SQL join string |
90 | 90 | $SQL = $this->_left_join( |
@@ -93,7 +93,7 @@ discard block |
||
93 | 93 | $join_table_fk_field_to_this_table->get_table_column(), |
94 | 94 | $this_table_alias, |
95 | 95 | $this_table_pk_field->get_table_column(), |
96 | - $field_with_model_name->get_qualified_column()."='".$this->get_this_model()->get_this_model_name()."'" ) . |
|
96 | + $field_with_model_name->get_qualified_column()."='".$this->get_this_model()->get_this_model_name()."'" ). |
|
97 | 97 | $this->get_join_model()->_construct_internal_join_to_table_with_alias($join_table_alias); |
98 | 98 | |
99 | 99 | return $SQL; |
@@ -111,9 +111,9 @@ discard block |
||
111 | 111 | * @return string of SQL |
112 | 112 | * @throws \EE_Error |
113 | 113 | */ |
114 | - public function get_join_statement($model_relation_chain){ |
|
115 | - if( $this->_model_relation_chain_to_join_model === NULL ){ |
|
116 | - throw new EE_Error( sprintf( __( 'When using EE_HABTM_Relation to create a join, you must call get_join_to_intermediate_model_statement BEFORE get_join_statement', 'event_espresso' ))); |
|
114 | + public function get_join_statement($model_relation_chain) { |
|
115 | + if ($this->_model_relation_chain_to_join_model === NULL) { |
|
116 | + throw new EE_Error(sprintf(__('When using EE_HABTM_Relation to create a join, you must call get_join_to_intermediate_model_statement BEFORE get_join_statement', 'event_espresso'))); |
|
117 | 117 | } |
118 | 118 | $join_table_fk_field_to_this_table = $this->get_join_table_fk_field_to( |
119 | 119 | $this->get_this_model()->get_this_model_name(), |
@@ -125,10 +125,10 @@ discard block |
||
125 | 125 | $this->get_other_model()->get_this_model_name(), |
126 | 126 | 'name' ); |
127 | 127 | |
128 | - $join_table_alias = EE_Model_Parser::extract_table_alias_model_relation_chain_prefix($this->_model_relation_chain_to_join_model, $this->get_join_model()->get_this_model_name()) . $join_table_fk_field_to_this_table->get_table_alias(); |
|
128 | + $join_table_alias = EE_Model_Parser::extract_table_alias_model_relation_chain_prefix($this->_model_relation_chain_to_join_model, $this->get_join_model()->get_this_model_name()).$join_table_fk_field_to_this_table->get_table_alias(); |
|
129 | 129 | |
130 | 130 | $other_table_pk_field = $this->get_other_model()->get_primary_key_field(); |
131 | - $other_table_alias = EE_Model_Parser::extract_table_alias_model_relation_chain_prefix($model_relation_chain, $this->get_other_model()->get_this_model_name()) . $other_table_pk_field->get_table_alias(); |
|
131 | + $other_table_alias = EE_Model_Parser::extract_table_alias_model_relation_chain_prefix($model_relation_chain, $this->get_other_model()->get_this_model_name()).$other_table_pk_field->get_table_alias(); |
|
132 | 132 | $other_table = $this->get_other_model()->get_table_for_alias($other_table_alias); |
133 | 133 | |
134 | 134 | $SQL = $this->_left_join( |
@@ -138,7 +138,7 @@ discard block |
||
138 | 138 | $join_table_alias, |
139 | 139 | $join_table_fk_field_to_other_table->get_table_column(), |
140 | 140 | $field_with_other_model_name->get_qualified_column()."='".$this->get_other_model()->get_this_model_name()."'" |
141 | - ) . |
|
141 | + ). |
|
142 | 142 | $this->get_other_model()->_construct_internal_join_to_table_with_alias($other_table_alias); |
143 | 143 | return $SQL; |
144 | 144 | } |
@@ -154,7 +154,7 @@ discard block |
||
154 | 154 | * @return EE_Base_Class |
155 | 155 | * @throws \EE_Error |
156 | 156 | */ |
157 | - public function add_relation_to($this_obj_or_id, $other_obj_or_id, $extra_join_model_fields_n_values = array() ){ |
|
157 | + public function add_relation_to($this_obj_or_id, $other_obj_or_id, $extra_join_model_fields_n_values = array()) { |
|
158 | 158 | $this_model_obj = $this->get_this_model()->ensure_is_obj($this_obj_or_id, true); |
159 | 159 | $other_model_obj = $this->get_other_model()->ensure_is_obj($other_obj_or_id, true); |
160 | 160 | //check if such a relationship already exists |
@@ -171,32 +171,32 @@ discard block |
||
171 | 171 | $this->get_other_model()->get_this_model_name(), |
172 | 172 | 'name' ); |
173 | 173 | |
174 | - $cols_n_values = array( |
|
174 | + $cols_n_values = array( |
|
175 | 175 | $join_model_fk_to_this_model->get_name() => $this_model_obj->ID(), |
176 | 176 | $join_model_name_field_to_this_model->get_name() => $this_model_obj->get_model()->get_this_model_name(), |
177 | 177 | $join_model_fk_to_other_model->get_name() => $other_model_obj->ID(), |
178 | 178 | $join_model_name_field_to_other_model->get_name() => $other_model_obj->get_model()->get_this_model_name() ); |
179 | 179 | |
180 | 180 | //if $where_query exists lets add them to the query_params. |
181 | - if ( !empty( $extra_join_model_fields_n_values ) ) { |
|
181 | + if ( ! empty($extra_join_model_fields_n_values)) { |
|
182 | 182 | //make sure we strip any of the join model names from the $where_query cause we don't need that in here (why? because client code may have used the same conditionals for get_all_related which DOES need the join model name) |
183 | 183 | //make sure we strip THIS models name from the query param |
184 | 184 | $parsed_query = array(); |
185 | - foreach ( $extra_join_model_fields_n_values as $query_param => $val ) { |
|
186 | - $query_param = str_replace($this->get_join_model()->get_this_model_name().".","", $query_param); |
|
185 | + foreach ($extra_join_model_fields_n_values as $query_param => $val) { |
|
186 | + $query_param = str_replace($this->get_join_model()->get_this_model_name().".", "", $query_param); |
|
187 | 187 | $parsed_query[$query_param] = $val; |
188 | 188 | } |
189 | - $cols_n_values = array_merge( $cols_n_values, $parsed_query ); |
|
189 | + $cols_n_values = array_merge($cols_n_values, $parsed_query); |
|
190 | 190 | } |
191 | 191 | |
192 | - $query_params = array( $cols_n_values ); |
|
192 | + $query_params = array($cols_n_values); |
|
193 | 193 | |
194 | 194 | |
195 | 195 | $existing_entry_in_join_table = $this->get_join_model()->get_one($query_params); |
196 | 196 | //if there is already an entry in the join table, indicating a relationship, we're done |
197 | 197 | //again, if you want more sophisticated logic or insertions (handling more columns than just 2 foreign keys to |
198 | 198 | //the other tables, use the joining model directly! |
199 | - if( ! $existing_entry_in_join_table ){ |
|
199 | + if ( ! $existing_entry_in_join_table) { |
|
200 | 200 | $this->get_join_model()->insert($cols_n_values); |
201 | 201 | } |
202 | 202 | return $other_model_obj; |
@@ -214,7 +214,7 @@ discard block |
||
214 | 214 | * @return EE_Base_Class |
215 | 215 | * @throws \EE_Error |
216 | 216 | */ |
217 | - public function remove_relation_to($this_obj_or_id, $other_obj_or_id, $where_query = array() ){ |
|
217 | + public function remove_relation_to($this_obj_or_id, $other_obj_or_id, $where_query = array()) { |
|
218 | 218 | $this_model_obj = $this->get_this_model()->ensure_is_obj($this_obj_or_id, true); |
219 | 219 | $other_model_obj = $this->get_other_model()->ensure_is_obj($other_obj_or_id, true); |
220 | 220 | //check if such a relationship already exists |
@@ -231,25 +231,25 @@ discard block |
||
231 | 231 | $this->get_other_model()->get_this_model_name(), |
232 | 232 | 'name' ); |
233 | 233 | |
234 | - $cols_n_values = array( |
|
234 | + $cols_n_values = array( |
|
235 | 235 | $join_model_fk_to_this_model->get_name() => $this_model_obj->ID(), |
236 | 236 | $join_model_name_field_to_this_model->get_name() => $this_model_obj->get_model()->get_this_model_name(), |
237 | 237 | $join_model_fk_to_other_model->get_name() => $other_model_obj->ID(), |
238 | 238 | $join_model_name_field_to_other_model->get_name() => $other_model_obj->get_model()->get_this_model_name() ); |
239 | 239 | |
240 | 240 | //if $where_query exists lets add them to the query_params. |
241 | - if ( !empty( $where_query ) ) { |
|
241 | + if ( ! empty($where_query)) { |
|
242 | 242 | //make sure we strip any of the join model names from the $where_query cause we don't need that in here (why? because client code may have used the same conditionals for get_all_related which DOES need the join model name) |
243 | 243 | //make sure we strip THIS models name from the query param |
244 | 244 | $parsed_query = array(); |
245 | - foreach ( $where_query as $query_param => $val ) { |
|
246 | - $query_param = str_replace($this->get_join_model()->get_this_model_name().".","", $query_param); |
|
245 | + foreach ($where_query as $query_param => $val) { |
|
246 | + $query_param = str_replace($this->get_join_model()->get_this_model_name().".", "", $query_param); |
|
247 | 247 | $parsed_query[$query_param] = $val; |
248 | 248 | } |
249 | - $cols_n_values = array_merge( $cols_n_values, $parsed_query ); |
|
249 | + $cols_n_values = array_merge($cols_n_values, $parsed_query); |
|
250 | 250 | } |
251 | 251 | |
252 | - $this->get_join_model()->delete( array($cols_n_values) ); |
|
252 | + $this->get_join_model()->delete(array($cols_n_values)); |
|
253 | 253 | return $other_model_obj; |
254 | 254 | } |
255 | 255 | } |
@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php |
2 | -require_once( EE_MODELS . 'relations/EE_Model_Relation_Base.php'); |
|
2 | +require_once(EE_MODELS.'relations/EE_Model_Relation_Base.php'); |
|
3 | 3 | |
4 | 4 | |
5 | 5 | |
@@ -11,7 +11,7 @@ discard block |
||
11 | 11 | * @subpackage core |
12 | 12 | * @author Michael Nelson |
13 | 13 | */ |
14 | -class EE_Has_Many_Relation extends EE_Model_Relation_Base{ |
|
14 | +class EE_Has_Many_Relation extends EE_Model_Relation_Base { |
|
15 | 15 | |
16 | 16 | /** |
17 | 17 | * Object representing the relationship between two models. Has_Many_Relations are where the OTHER model has the foreign key |
@@ -21,7 +21,7 @@ discard block |
||
21 | 21 | * @param boolean $block_deletes For this type of relation, we block by default. If there are related models across this relation, block (prevent and add an error) the deletion of this model |
22 | 22 | * @param string $blocking_delete_error_message a customized error message on blocking deletes instead of the default |
23 | 23 | */ |
24 | - public function __construct($block_deletes = true, $blocking_delete_error_message = null){ |
|
24 | + public function __construct($block_deletes = true, $blocking_delete_error_message = null) { |
|
25 | 25 | parent::__construct($block_deletes, $blocking_delete_error_message); |
26 | 26 | } |
27 | 27 | |
@@ -34,13 +34,13 @@ discard block |
||
34 | 34 | * @return string of SQL, eg "LEFT JOIN table_name AS table_alias ON this_model_primary_table.pk = other_model_primary_table.fk" etc |
35 | 35 | * @throws \EE_Error |
36 | 36 | */ |
37 | - public function get_join_statement( $model_relation_chain){ |
|
37 | + public function get_join_statement($model_relation_chain) { |
|
38 | 38 | //create the sql string like |
39 | 39 | // LEFT JOIN other_table AS table_alias ON this_table_alias.pk = other_table_alias.fk extra_join_conditions |
40 | 40 | $this_table_pk_field = $this->get_this_model()->get_primary_key_field(); |
41 | 41 | $other_table_fk_field = $this->get_other_model()->get_foreign_key_to($this->get_this_model()->get_this_model_name()); |
42 | - $pk_table_alias = EE_Model_Parser::extract_table_alias_model_relation_chain_prefix($model_relation_chain, $this->get_this_model()->get_this_model_name()) . $this_table_pk_field->get_table_alias(); |
|
43 | - $fk_table_alias = EE_Model_Parser::extract_table_alias_model_relation_chain_prefix($model_relation_chain, $this->get_other_model()->get_this_model_name()) . $other_table_fk_field->get_table_alias(); |
|
42 | + $pk_table_alias = EE_Model_Parser::extract_table_alias_model_relation_chain_prefix($model_relation_chain, $this->get_this_model()->get_this_model_name()).$this_table_pk_field->get_table_alias(); |
|
43 | + $fk_table_alias = EE_Model_Parser::extract_table_alias_model_relation_chain_prefix($model_relation_chain, $this->get_other_model()->get_this_model_name()).$other_table_fk_field->get_table_alias(); |
|
44 | 44 | $fk_table = $this->get_other_model()->get_table_for_alias($fk_table_alias); |
45 | 45 | |
46 | 46 | return $this->_left_join($fk_table, $fk_table_alias, $other_table_fk_field->get_table_column(), $pk_table_alias, $this_table_pk_field->get_table_column()).$this->get_other_model()->_construct_internal_join_to_table_with_alias($fk_table_alias); |
@@ -57,13 +57,13 @@ discard block |
||
57 | 57 | * @return \EE_Base_Class |
58 | 58 | * @throws \EE_Error |
59 | 59 | */ |
60 | - public function add_relation_to($this_obj_or_id, $other_obj_or_id, $extra_join_model_fields_n_values = array() ){ |
|
60 | + public function add_relation_to($this_obj_or_id, $other_obj_or_id, $extra_join_model_fields_n_values = array()) { |
|
61 | 61 | $this_model_obj = $this->get_this_model()->ensure_is_obj($this_obj_or_id, true); |
62 | 62 | $other_model_obj = $this->get_other_model()->ensure_is_obj($other_obj_or_id, true); |
63 | 63 | |
64 | 64 | //find the field on the other model which is a foreign key to this model |
65 | 65 | $fk_field_on_other_model = $this->get_other_model()->get_foreign_key_to($this->get_this_model()->get_this_model_name()); |
66 | - if($other_model_obj->get($fk_field_on_other_model->get_name()) != $this_model_obj->ID()){ |
|
66 | + if ($other_model_obj->get($fk_field_on_other_model->get_name()) != $this_model_obj->ID()) { |
|
67 | 67 | //set that field on the other model to this model's ID |
68 | 68 | $other_model_obj->set($fk_field_on_other_model->get_name(), $this_model_obj->ID()); |
69 | 69 | $other_model_obj->save(); |
@@ -83,12 +83,12 @@ discard block |
||
83 | 83 | * @return \EE_Base_Class |
84 | 84 | * @throws \EE_Error |
85 | 85 | */ |
86 | - public function remove_relation_to($this_obj_or_id, $other_obj_or_id, $where_query = array()){ |
|
86 | + public function remove_relation_to($this_obj_or_id, $other_obj_or_id, $where_query = array()) { |
|
87 | 87 | $other_model_obj = $this->get_other_model()->ensure_is_obj($other_obj_or_id, true); |
88 | 88 | //find the field on the other model which is a foreign key to this model |
89 | 89 | $fk_field_on_other_model = $this->get_other_model()->get_foreign_key_to($this->get_this_model()->get_this_model_name()); |
90 | 90 | //set that field on the other model to this model's ID |
91 | - $other_model_obj->set($fk_field_on_other_model->get_name(),null, true); |
|
91 | + $other_model_obj->set($fk_field_on_other_model->get_name(), null, true); |
|
92 | 92 | $other_model_obj->save(); |
93 | 93 | return $other_model_obj; |
94 | 94 | } |
@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php |
2 | -require_once( EE_MODELS . 'relations/EE_Has_Many_Relation.php'); |
|
2 | +require_once(EE_MODELS.'relations/EE_Has_Many_Relation.php'); |
|
3 | 3 | |
4 | 4 | |
5 | 5 | |
@@ -11,7 +11,7 @@ discard block |
||
11 | 11 | * @subpackage core |
12 | 12 | * @author Michael Nelson |
13 | 13 | */ |
14 | -class EE_Has_Many_Revision_Relation extends EE_Has_Many_Relation{ |
|
14 | +class EE_Has_Many_Revision_Relation extends EE_Has_Many_Relation { |
|
15 | 15 | |
16 | 16 | |
17 | 17 | /** |
@@ -44,7 +44,7 @@ discard block |
||
44 | 44 | * @param boolean $block_deletes For this type of relation, we block by default. If there are related models across this relation, block (prevent and add an error) the deletion of this model |
45 | 45 | * @param string $blocking_delete_error_message a customized error message on blocking deletes instead of the default |
46 | 46 | */ |
47 | - public function __construct($primary_cpt_field, $parent_pk_relation_field, $block_deletes = true, $blocking_delete_error_message = null){ |
|
47 | + public function __construct($primary_cpt_field, $parent_pk_relation_field, $block_deletes = true, $blocking_delete_error_message = null) { |
|
48 | 48 | $this->_primary_cpt_field = $primary_cpt_field; |
49 | 49 | $this->_parent_pk_relation_field = $parent_pk_relation_field; |
50 | 50 | parent::__construct($block_deletes, $blocking_delete_error_message); |
@@ -61,7 +61,7 @@ discard block |
||
61 | 61 | * @return \EE_Base_Class |
62 | 62 | * @throws \EE_Error |
63 | 63 | */ |
64 | - public function add_relation_to($this_obj_or_id, $other_obj_or_id, $extra_join_model_fields_n_values = array() ){ |
|
64 | + public function add_relation_to($this_obj_or_id, $other_obj_or_id, $extra_join_model_fields_n_values = array()) { |
|
65 | 65 | $this_model_obj = $this->get_this_model()->ensure_is_obj($this_obj_or_id, true); |
66 | 66 | $other_model_obj = $this->get_other_model()->ensure_is_obj($other_obj_or_id); |
67 | 67 | |
@@ -69,7 +69,7 @@ discard block |
||
69 | 69 | $other_model_obj = $this->_check_for_revision($this_model_obj, $other_model_obj); |
70 | 70 | |
71 | 71 | //if is array, then we've already done the add_relation so let's get out |
72 | - if ( is_array( $other_model_obj ) ){ |
|
72 | + if (is_array($other_model_obj)) { |
|
73 | 73 | return $other_model_obj[0]; |
74 | 74 | } |
75 | 75 | //find the field on the other model which is a foreign key to this model |
@@ -91,15 +91,15 @@ discard block |
||
91 | 91 | * @return \EE_Base_Class |
92 | 92 | * @throws \EE_Error |
93 | 93 | */ |
94 | - public function remove_relation_to($this_obj_or_id, $other_obj_or_id, $where_query = array()){ |
|
94 | + public function remove_relation_to($this_obj_or_id, $other_obj_or_id, $where_query = array()) { |
|
95 | 95 | $this_model_obj = $this->get_this_model()->ensure_is_obj($this_obj_or_id); |
96 | 96 | $other_model_obj = $this->get_other_model()->ensure_is_obj($other_obj_or_id); |
97 | 97 | //handle possible revisions |
98 | - $other_model_obj = $this->_check_for_revision( $this_model_obj, $other_model_obj, TRUE ); |
|
98 | + $other_model_obj = $this->_check_for_revision($this_model_obj, $other_model_obj, TRUE); |
|
99 | 99 | |
100 | 100 | |
101 | 101 | //if is array, then we've already done the add_relation so let's get out |
102 | - if ( is_array( $other_model_obj ) ){ |
|
102 | + if (is_array($other_model_obj)) { |
|
103 | 103 | return $other_model_obj[0]; |
104 | 104 | } |
105 | 105 | |
@@ -108,12 +108,12 @@ discard block |
||
108 | 108 | |
109 | 109 | |
110 | 110 | //set that field on the other model to this model's ID |
111 | - if ( $this->_blocking_delete ) { |
|
112 | - $other_model_obj->set($fk_field_on_other_model->get_name(),null,true); |
|
111 | + if ($this->_blocking_delete) { |
|
112 | + $other_model_obj->set($fk_field_on_other_model->get_name(), null, true); |
|
113 | 113 | $other_model_obj->save(); |
114 | 114 | } else { |
115 | 115 | $other_model_obj->delete(); |
116 | - $other_model_obj->set($fk_field_on_other_model->get_name(),null,true); |
|
116 | + $other_model_obj->set($fk_field_on_other_model->get_name(), null, true); |
|
117 | 117 | return $other_model_obj; |
118 | 118 | } |
119 | 119 | return $other_model_obj; |
@@ -130,17 +130,17 @@ discard block |
||
130 | 130 | * @return EE_Base_Class[] |
131 | 131 | * @throws \EE_Error |
132 | 132 | */ |
133 | - public function get_all_related( $model_object_or_id, $query_params = array(), $values_already_prepared_by_model_object = false ) { |
|
134 | - if( $values_already_prepared_by_model_object !== false ) { |
|
135 | - EE_Error::doing_it_wrong( 'EE_Model_Relation_Base::get_all_related', __( 'The argument $values_already_prepared_by_model_object is no longer used.', 'event_espresso' ), '4.8.1' ); |
|
133 | + public function get_all_related($model_object_or_id, $query_params = array(), $values_already_prepared_by_model_object = false) { |
|
134 | + if ($values_already_prepared_by_model_object !== false) { |
|
135 | + EE_Error::doing_it_wrong('EE_Model_Relation_Base::get_all_related', __('The argument $values_already_prepared_by_model_object is no longer used.', 'event_espresso'), '4.8.1'); |
|
136 | 136 | } |
137 | 137 | |
138 | 138 | //if this is an autosave then we're going to get things differently |
139 | - if ( defined('DOING_AUTOSAVE') && DOING_AUTOSAVE ) { |
|
140 | - return $this->_do_autosave_get_all($model_object_or_id, $query_params ); |
|
139 | + if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) { |
|
140 | + return $this->_do_autosave_get_all($model_object_or_id, $query_params); |
|
141 | 141 | } |
142 | 142 | |
143 | - return parent::get_all_related( $model_object_or_id, $query_params ); |
|
143 | + return parent::get_all_related($model_object_or_id, $query_params); |
|
144 | 144 | } |
145 | 145 | |
146 | 146 | |
@@ -156,22 +156,22 @@ discard block |
||
156 | 156 | * @return \EE_Base_Class[] |
157 | 157 | * @throws \EE_Error |
158 | 158 | */ |
159 | - protected function _do_autosave_get_all( $model_object_or_id, $query_params, $deprecated = false ) { |
|
159 | + protected function _do_autosave_get_all($model_object_or_id, $query_params, $deprecated = false) { |
|
160 | 160 | |
161 | 161 | //first we check if the post_id for the incoming query is for an autosave. If it isn't that's what we want! |
162 | - $model_object_id = $this->_get_model_object_id( $model_object_or_id ); |
|
162 | + $model_object_id = $this->_get_model_object_id($model_object_or_id); |
|
163 | 163 | |
164 | - $autosave = wp_get_post_autosave( $model_object_id ); |
|
164 | + $autosave = wp_get_post_autosave($model_object_id); |
|
165 | 165 | $id_to_use = $autosave ? $autosave->ID : $model_object_id; |
166 | 166 | |
167 | - $autosave_relations = parent::get_all_related( $id_to_use, $query_params ); |
|
167 | + $autosave_relations = parent::get_all_related($id_to_use, $query_params); |
|
168 | 168 | $parent_ids = $parents = array(); |
169 | 169 | $return_objs = array(); |
170 | 170 | |
171 | 171 | //k this is where things differ because NOW what we're going to do is get the PARENTS for the get all related (and we'll also start setting up the return_objs array containing related that DON'T have parent ids, for those that DON'T have parents to merge with our returned objects); |
172 | - foreach ( $autosave_relations as $a_r ) { |
|
172 | + foreach ($autosave_relations as $a_r) { |
|
173 | 173 | $pid = $a_r->parent(); |
174 | - if ( !empty( $pid ) ) { |
|
174 | + if ( ! empty($pid)) { |
|
175 | 175 | $parent_ids[] = $pid; |
176 | 176 | } else { |
177 | 177 | $return_objs[] = $a_r; |
@@ -179,17 +179,17 @@ discard block |
||
179 | 179 | } |
180 | 180 | |
181 | 181 | //we have to make sure we also include the ORIGINAL values |
182 | - $originals = parent::get_all_related($model_object_or_id, $query_params ); |
|
182 | + $originals = parent::get_all_related($model_object_or_id, $query_params); |
|
183 | 183 | |
184 | 184 | //merge $originals with $return_objs |
185 | - if ( $originals ) { |
|
185 | + if ($originals) { |
|
186 | 186 | $return_objs = array_merge($originals, $return_objs); |
187 | 187 | } |
188 | 188 | |
189 | 189 | //now we setup the query to get all the parents |
190 | - if ( !empty( $parent_ids ) ) { |
|
190 | + if ( ! empty($parent_ids)) { |
|
191 | 191 | $query_param_where_this_model_pk = $this->get_this_model()->get_this_model_name().".".$this->get_this_model()->get_primary_key_field()->get_name(); |
192 | - $query_param[0][$query_param_where_this_model_pk] = array('IN', $parent_ids ); |
|
192 | + $query_param[0][$query_param_where_this_model_pk] = array('IN', $parent_ids); |
|
193 | 193 | $parents = $this->get_other_model()->get_all($query_params); |
194 | 194 | } |
195 | 195 | |
@@ -197,7 +197,7 @@ discard block |
||
197 | 197 | |
198 | 198 | |
199 | 199 | //now merge parents with our current $return_objs and send back |
200 | - return array_merge( $parents, $return_objs ); |
|
200 | + return array_merge($parents, $return_objs); |
|
201 | 201 | } |
202 | 202 | |
203 | 203 | |
@@ -211,42 +211,42 @@ discard block |
||
211 | 211 | * @return EE_Base_Class. ($other_obj); |
212 | 212 | * @throws \EE_Error |
213 | 213 | */ |
214 | - protected function _check_for_revision( $this_obj, $other_obj, $remove_relation = FALSE ) { |
|
214 | + protected function _check_for_revision($this_obj, $other_obj, $remove_relation = FALSE) { |
|
215 | 215 | $pk_on_related_model = $this->get_other_model()->get_primary_key_field()->get_name(); |
216 | 216 | //now we need to determine if we're in a WP revision save cause if we are we need to do some special handling |
217 | - if ( $this_obj->post_type() === 'revision' ) { |
|
217 | + if ($this_obj->post_type() === 'revision') { |
|
218 | 218 | //first if $other_obj fk = this_obj pk then we know that this is a pk object, let's make sure there is a matching set for the autosave if there is then we save over it, if there isn't then we need to create a new one. |
219 | 219 | $parent_evt_id = $this_obj->parent(); |
220 | 220 | /*var_dump($parent_evt_id); |
221 | 221 | var_dump($this_obj); |
222 | 222 | var_dump($other_obj);/**/ |
223 | 223 | |
224 | - if ( !empty($parent_evt_id) && $parent_evt_id == $other_obj->get($this->_primary_cpt_field) ) { |
|
224 | + if ( ! empty($parent_evt_id) && $parent_evt_id == $other_obj->get($this->_primary_cpt_field)) { |
|
225 | 225 | //let's do query on this objects model to see if the incoming pk value on the obj matches any parents in this objects table. |
226 | - $has_parent_obj = $this->get_other_model()->get_one( array( array( $this->_parent_pk_relation_field => $other_obj->ID(), $this->_primary_cpt_field => $this_obj->ID() ) ) ); |
|
226 | + $has_parent_obj = $this->get_other_model()->get_one(array(array($this->_parent_pk_relation_field => $other_obj->ID(), $this->_primary_cpt_field => $this_obj->ID()))); |
|
227 | 227 | |
228 | - if ( $has_parent_obj ) { |
|
228 | + if ($has_parent_obj) { |
|
229 | 229 | //this makes sure the update on the current obj happens to the revision's row NOT the parent row. |
230 | 230 | |
231 | - $other_obj->set( $this->_parent_pk_relation_field, $other_obj->ID()); |
|
232 | - $other_obj->set($pk_on_related_model, $has_parent_obj->ID() ); |
|
231 | + $other_obj->set($this->_parent_pk_relation_field, $other_obj->ID()); |
|
232 | + $other_obj->set($pk_on_related_model, $has_parent_obj->ID()); |
|
233 | 233 | $other_obj->set($this->_primary_cpt_field, $this_obj->ID()); |
234 | 234 | |
235 | - if ( !$remove_relation ) { |
|
235 | + if ( ! $remove_relation) { |
|
236 | 236 | $other_obj->save(); |
237 | - return array( $other_obj ); |
|
238 | - } elseif ( $remove_relation && !$this->_blocking_delete) { |
|
237 | + return array($other_obj); |
|
238 | + } elseif ($remove_relation && ! $this->_blocking_delete) { |
|
239 | 239 | $other_obj->delete(); |
240 | 240 | $other_obj->set($this->_parent_pk_relation_field, NULL, true); |
241 | 241 | return array($other_obj); |
242 | 242 | } |
243 | 243 | |
244 | 244 | } else { |
245 | - $other_obj->set( $this->_parent_pk_relation_field, $other_obj->ID() ); |
|
246 | - $other_obj->set( $this->_primary_cpt_field, $this_obj->ID() ); |
|
245 | + $other_obj->set($this->_parent_pk_relation_field, $other_obj->ID()); |
|
246 | + $other_obj->set($this->_primary_cpt_field, $this_obj->ID()); |
|
247 | 247 | $other_obj->set($pk_on_related_model, NULL, true); //ensure we create a new row for the autosave with parent id the same as the incoming ID. |
248 | 248 | $other_obj->save(); //make sure we insert. |
249 | - return array( $other_obj ); |
|
249 | + return array($other_obj); |
|
250 | 250 | } |
251 | 251 | } |
252 | 252 | |
@@ -259,24 +259,24 @@ discard block |
||
259 | 259 | } else { |
260 | 260 | |
261 | 261 | //we only need to do the below IF this is not a remove relation |
262 | - if ( !$remove_relation ) { |
|
262 | + if ( ! $remove_relation) { |
|
263 | 263 | //okay this is is a normal update/save/remove so, let's make sure the other object is not a revision of the current object. |
264 | 264 | //the other object will likely NOT have the correct fk on it (which is the primary_cpt_field_mame) so we must retrieve from the db to get that first. |
265 | 265 | $existing_other_obj = $this->get_other_model()->get_one_by_ID($other_obj->ID()); |
266 | 266 | $potential_revision_id = is_object($existing_other_obj) ? $existing_other_obj->get($this->_primary_cpt_field) : NULL; |
267 | 267 | |
268 | - if ( $parent_this_obj_id = wp_is_post_revision($potential_revision_id) ) { |
|
268 | + if ($parent_this_obj_id = wp_is_post_revision($potential_revision_id)) { |
|
269 | 269 | //yes the OTHER object is linked to the revision of the parent, not the parent itself. That means we need to make the other_object an attachment of this_obj and then duplicate other_obj for the revision. |
270 | - $other_obj->set($this->_primary_cpt_field, $this_obj->ID() ); |
|
270 | + $other_obj->set($this->_primary_cpt_field, $this_obj->ID()); |
|
271 | 271 | $other_obj->save(); |
272 | 272 | |
273 | 273 | //now create a new other_obj and fill with details from existing object |
274 | 274 | $new_obj = $other_obj; |
275 | - $new_obj->set( $this->_primary_cpt_field, $potential_revision_id ); |
|
276 | - $new_obj->set( $this->_parent_pk_relation_field, $other_obj->ID() ); |
|
277 | - $new_obj->set( $pk_on_related_model, NULL ); |
|
275 | + $new_obj->set($this->_primary_cpt_field, $potential_revision_id); |
|
276 | + $new_obj->set($this->_parent_pk_relation_field, $other_obj->ID()); |
|
277 | + $new_obj->set($pk_on_related_model, NULL); |
|
278 | 278 | $new_obj->save(); |
279 | - return array( $new_obj ); |
|
279 | + return array($new_obj); |
|
280 | 280 | } |
281 | 281 | |
282 | 282 | } |