@@ -1,7 +1,7 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | if ( ! defined('EVENT_ESPRESSO_VERSION')) { exit('NO direct script access allowed'); } |
3 | 3 | |
4 | -require_once( EE_HELPERS . 'EEH_Base.helper.php' ); |
|
4 | +require_once(EE_HELPERS.'EEH_Base.helper.php'); |
|
5 | 5 | |
6 | 6 | /** |
7 | 7 | * EE_Array |
@@ -26,8 +26,8 @@ discard block |
||
26 | 26 | * @param array $array2 an array of objects |
27 | 27 | * @return array an array of objects found in array 1 that aren't found in array 2. |
28 | 28 | */ |
29 | - public static function object_array_diff( $array1, $array2 ) { |
|
30 | - return array_udiff( $array1, $array2, array('self', '_compare_objects' )); |
|
29 | + public static function object_array_diff($array1, $array2) { |
|
30 | + return array_udiff($array1, $array2, array('self', '_compare_objects')); |
|
31 | 31 | } |
32 | 32 | |
33 | 33 | /** |
@@ -35,7 +35,7 @@ discard block |
||
35 | 35 | * @param array $arr |
36 | 36 | * @return boolean |
37 | 37 | */ |
38 | - public static function is_associative_array($arr){ |
|
38 | + public static function is_associative_array($arr) { |
|
39 | 39 | return array_keys($arr) !== range(0, count($arr) - 1); |
40 | 40 | } |
41 | 41 | |
@@ -45,7 +45,7 @@ discard block |
||
45 | 45 | * @param array $arr |
46 | 46 | * @return mixed what ever is in the array |
47 | 47 | */ |
48 | - public static function get_one_item_from_array($arr){ |
|
48 | + public static function get_one_item_from_array($arr) { |
|
49 | 49 | $item = end($arr); |
50 | 50 | reset($arr); |
51 | 51 | return $item; |
@@ -56,16 +56,16 @@ discard block |
||
56 | 56 | * @param mixed $arr |
57 | 57 | * @return boolean |
58 | 58 | */ |
59 | - public static function is_multi_dimensional_array($arr){ |
|
60 | - if(is_array($arr)){ |
|
59 | + public static function is_multi_dimensional_array($arr) { |
|
60 | + if (is_array($arr)) { |
|
61 | 61 | $first_item = reset($arr); |
62 | - if(is_array($first_item)){ |
|
63 | - return true;//yep, there's at least 2 levels to this array |
|
64 | - }else{ |
|
65 | - return false;//nope, only 1 level |
|
62 | + if (is_array($first_item)) { |
|
63 | + return true; //yep, there's at least 2 levels to this array |
|
64 | + } else { |
|
65 | + return false; //nope, only 1 level |
|
66 | 66 | } |
67 | - }else{ |
|
68 | - return false;//its not an array at all! |
|
67 | + } else { |
|
68 | + return false; //its not an array at all! |
|
69 | 69 | } |
70 | 70 | } |
71 | 71 | |
@@ -76,8 +76,8 @@ discard block |
||
76 | 76 | * @param mixed $default |
77 | 77 | * @return mixed |
78 | 78 | */ |
79 | - public static function is_set( $arr, $index, $default ) { |
|
80 | - return isset( $arr[ $index ] ) ? $arr[ $index ] : $default; |
|
79 | + public static function is_set($arr, $index, $default) { |
|
80 | + return isset($arr[$index]) ? $arr[$index] : $default; |
|
81 | 81 | } |
82 | 82 | |
83 | 83 | /** |
@@ -85,12 +85,12 @@ discard block |
||
85 | 85 | * @param mixed $value usually a string, but could be an array or object |
86 | 86 | * @return mixed the UN-serialized data |
87 | 87 | */ |
88 | - public static function maybe_unserialize( $value ) { |
|
88 | + public static function maybe_unserialize($value) { |
|
89 | 89 | $data = maybe_unserialize($value); |
90 | 90 | //it's possible that this still has serialized data if its the session. WP has a bug, http://core.trac.wordpress.org/ticket/26118 that doesnt' unserialize this automatically. |
91 | 91 | $token = 'C'; |
92 | 92 | $data = is_string($data) ? trim($data) : $data; |
93 | - if ( is_string($data) && strlen($data) > 1 && $data[0] == $token && preg_match( "/^{$token}:[0-9]+:/s", $data ) ) { |
|
93 | + if (is_string($data) && strlen($data) > 1 && $data[0] == $token && preg_match("/^{$token}:[0-9]+:/s", $data)) { |
|
94 | 94 | return unserialize($data); |
95 | 95 | } else { |
96 | 96 | return $data; |
@@ -109,30 +109,30 @@ discard block |
||
109 | 109 | * @param bool $preserve_keys whether or not to reset numerically indexed arrays |
110 | 110 | * @return array |
111 | 111 | */ |
112 | - public static function insert_into_array( $target_array = array(), $array_to_insert = array(), $offset = null, $add_before = true, $preserve_keys = true ) { |
|
112 | + public static function insert_into_array($target_array = array(), $array_to_insert = array(), $offset = null, $add_before = true, $preserve_keys = true) { |
|
113 | 113 | // ensure incoming arrays are actually arrays |
114 | - $target_array = (array)$target_array; |
|
115 | - $array_to_insert = (array)$array_to_insert; |
|
114 | + $target_array = (array) $target_array; |
|
115 | + $array_to_insert = (array) $array_to_insert; |
|
116 | 116 | // if no offset key was supplied |
117 | - if ( empty( $offset )) { |
|
117 | + if (empty($offset)) { |
|
118 | 118 | // use start or end of $target_array based on whether we are adding before or not |
119 | - $offset = $add_before ? 0 : count( $target_array ); |
|
119 | + $offset = $add_before ? 0 : count($target_array); |
|
120 | 120 | } |
121 | 121 | // if offset key is a string, then find the corresponding numeric location for that element |
122 | - $offset = is_int( $offset ) ? $offset : array_search( $offset, array_keys( $target_array ) ); |
|
122 | + $offset = is_int($offset) ? $offset : array_search($offset, array_keys($target_array)); |
|
123 | 123 | // add one to the offset if adding after |
124 | 124 | $offset = $add_before ? $offset : $offset + 1; |
125 | 125 | // but ensure offset does not exceed the length of the array |
126 | - $offset = $offset > count( $target_array ) ? count( $target_array ) : $offset; |
|
126 | + $offset = $offset > count($target_array) ? count($target_array) : $offset; |
|
127 | 127 | // reindex array ??? |
128 | - if ( $preserve_keys ) { |
|
128 | + if ($preserve_keys) { |
|
129 | 129 | // take a slice of the target array from the beginning till the offset, |
130 | 130 | // then add the new data |
131 | 131 | // then add another slice that starts at the offset and goes till the end |
132 | - return array_slice( $target_array, 0, $offset, true ) + $array_to_insert + array_slice( $target_array, $offset, null, true ); |
|
132 | + return array_slice($target_array, 0, $offset, true) + $array_to_insert + array_slice($target_array, $offset, null, true); |
|
133 | 133 | } else { |
134 | 134 | // since we don't want to preserve keys, we can use array_splice |
135 | - array_splice( $target_array, $offset, 0, $array_to_insert ); |
|
135 | + array_splice($target_array, $offset, 0, $array_to_insert); |
|
136 | 136 | return $target_array; |
137 | 137 | } |
138 | 138 | } |
@@ -150,9 +150,9 @@ discard block |
||
150 | 150 | * @param array $array2 |
151 | 151 | * @return array |
152 | 152 | */ |
153 | - public static function merge_arrays_and_overwrite_keys( array $array1, array $array2 ) { |
|
154 | - foreach ( $array2 as $key => $value ) { |
|
155 | - $array1[ $key ] = $value; |
|
153 | + public static function merge_arrays_and_overwrite_keys(array $array1, array $array2) { |
|
154 | + foreach ($array2 as $key => $value) { |
|
155 | + $array1[$key] = $value; |
|
156 | 156 | } |
157 | 157 | return $array1; |
158 | 158 | } |
@@ -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'] ); |
@@ -4404,7 +4404,7 @@ discard block |
||
4404 | 4404 | $model_object = $this->get_one_by_ID( $base_class_obj_or_id ); |
4405 | 4405 | } else if ( |
4406 | 4406 | $primary_key_field instanceof EE_Primary_Key_String_Field |
4407 | - && is_string( $base_class_obj_or_id ) |
|
4407 | + && is_string( $base_class_obj_or_id ) |
|
4408 | 4408 | ) { |
4409 | 4409 | // assume its a string representation of the object |
4410 | 4410 | $model_object = $this->get_one_by_ID( $base_class_obj_or_id ); |
@@ -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,18 +2977,18 @@ 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'))){ |
|
2989 | + if (in_array($use_default_where_conditions, array('all', 'other_models_only'))) { |
|
2990 | 2990 | EE_Registry::instance()->load_helper('Array'); |
2991 | - foreach($query_info_carrier->get_model_names_included() as $model_relation_path => $model_name){ |
|
2991 | + foreach ($query_info_carrier->get_model_names_included() as $model_relation_path => $model_name) { |
|
2992 | 2992 | $related_model = $this->get_related_model_obj($model_name); |
2993 | 2993 | $related_model_universal_where_params = $related_model->_get_default_where_conditions($model_relation_path); |
2994 | 2994 | $overrides = $this->_override_defaults_or_make_null_friendly( |
@@ -3021,20 +3021,20 @@ discard block |
||
3021 | 3021 | * @return array like EEM_Base::get_all's $query_params[0] |
3022 | 3022 | * @throws \EE_Error |
3023 | 3023 | */ |
3024 | - private function _override_defaults_or_make_null_friendly($default_where_conditions,$provided_where_conditions,$model,$model_relation_path){ |
|
3024 | + private function _override_defaults_or_make_null_friendly($default_where_conditions, $provided_where_conditions, $model, $model_relation_path) { |
|
3025 | 3025 | $null_friendly_where_conditions = array(); |
3026 | 3026 | $none_overridden = true; |
3027 | 3027 | $or_condition_key_for_defaults = 'OR*'.get_class($model); |
3028 | 3028 | |
3029 | - foreach($default_where_conditions as $key => $val){ |
|
3030 | - if( isset($provided_where_conditions[$key])){ |
|
3029 | + foreach ($default_where_conditions as $key => $val) { |
|
3030 | + if (isset($provided_where_conditions[$key])) { |
|
3031 | 3031 | $none_overridden = false; |
3032 | - }else{ |
|
3032 | + } else { |
|
3033 | 3033 | $null_friendly_where_conditions[$or_condition_key_for_defaults]['AND'][$key] = $val; |
3034 | 3034 | } |
3035 | 3035 | } |
3036 | - if( $none_overridden && $default_where_conditions){ |
|
3037 | - if($model->has_primary_key_field()){ |
|
3036 | + if ($none_overridden && $default_where_conditions) { |
|
3037 | + if ($model->has_primary_key_field()) { |
|
3038 | 3038 | $null_friendly_where_conditions[$or_condition_key_for_defaults][$model_relation_path.".".$model->primary_key_name()] = array('IS NULL'); |
3039 | 3039 | }/*else{ |
3040 | 3040 | //@todo NO PK, use other defaults |
@@ -3051,8 +3051,8 @@ discard block |
||
3051 | 3051 | * @param string $model_relation_path eg, path from Event to Payment is "Registration.Transaction.Payment." |
3052 | 3052 | * @return array like EEM_Base::get_all's $query_params[0] (where conditions) |
3053 | 3053 | */ |
3054 | - private function _get_default_where_conditions($model_relation_path = null){ |
|
3055 | - if ( $this->_ignore_where_strategy ){ |
|
3054 | + private function _get_default_where_conditions($model_relation_path = null) { |
|
3055 | + if ($this->_ignore_where_strategy) { |
|
3056 | 3056 | return array(); |
3057 | 3057 | } |
3058 | 3058 | return $this->_default_where_conditions_strategy->get_default_where_conditions($model_relation_path); |
@@ -3066,8 +3066,8 @@ discard block |
||
3066 | 3066 | * @param string $model_relation_path eg, path from Event to Payment is "Registration.Transaction.Payment." |
3067 | 3067 | * @return array like EEM_Base::get_all's $query_params[0] (where conditions) |
3068 | 3068 | */ |
3069 | - protected function _get_minimum_where_conditions($model_relation_path = null){ |
|
3070 | - if ( $this->_ignore_where_strategy ){ |
|
3069 | + protected function _get_minimum_where_conditions($model_relation_path = null) { |
|
3070 | + if ($this->_ignore_where_strategy) { |
|
3071 | 3071 | return array(); |
3072 | 3072 | } |
3073 | 3073 | return $this->_minimum_where_conditions_strategy->get_default_where_conditions($model_relation_path); |
@@ -3083,16 +3083,16 @@ discard block |
||
3083 | 3083 | * @return string |
3084 | 3084 | * @throws \EE_Error |
3085 | 3085 | */ |
3086 | - private function _construct_default_select_sql(EE_Model_Query_Info_Carrier $model_query_info){ |
|
3086 | + private function _construct_default_select_sql(EE_Model_Query_Info_Carrier $model_query_info) { |
|
3087 | 3087 | $selects = $this->_get_columns_to_select_for_this_model(); |
3088 | - foreach($model_query_info->get_model_names_included() as $model_relation_chain => $name_of_other_model_included){ |
|
3088 | + foreach ($model_query_info->get_model_names_included() as $model_relation_chain => $name_of_other_model_included) { |
|
3089 | 3089 | $other_model_included = $this->get_related_model_obj($name_of_other_model_included); |
3090 | - $other_model_selects = $other_model_included->_get_columns_to_select_for_this_model( $model_relation_chain ); |
|
3091 | - foreach ( $other_model_selects as $key => $value ) { |
|
3090 | + $other_model_selects = $other_model_included->_get_columns_to_select_for_this_model($model_relation_chain); |
|
3091 | + foreach ($other_model_selects as $key => $value) { |
|
3092 | 3092 | $selects[] = $value; |
3093 | 3093 | } |
3094 | 3094 | } |
3095 | - return implode(", ",$selects); |
|
3095 | + return implode(", ", $selects); |
|
3096 | 3096 | } |
3097 | 3097 | |
3098 | 3098 | /** |
@@ -3101,19 +3101,19 @@ discard block |
||
3101 | 3101 | * @param string $model_relation_chain like 'Question.Question_Group.Event' |
3102 | 3102 | * @return array numerically indexed, values are columns to select and rename, eg "Event.ID AS 'Event.ID'" |
3103 | 3103 | */ |
3104 | - public function _get_columns_to_select_for_this_model($model_relation_chain = ''){ |
|
3104 | + public function _get_columns_to_select_for_this_model($model_relation_chain = '') { |
|
3105 | 3105 | $fields = $this->field_settings(); |
3106 | 3106 | $selects = array(); |
3107 | 3107 | $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()); |
3108 | - foreach($fields as $field_obj){ |
|
3109 | - $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 | + foreach ($fields as $field_obj) { |
|
3109 | + $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()."'"; |
|
3110 | 3110 | } |
3111 | 3111 | //make sure we are also getting the PKs of each table |
3112 | 3112 | $tables = $this->get_tables(); |
3113 | - if(count($tables) > 1){ |
|
3114 | - foreach($tables as $table_obj){ |
|
3115 | - $qualified_pk_column = $table_alias_with_model_relation_chain_prefix . $table_obj->get_fully_qualified_pk_column(); |
|
3116 | - if( ! in_array($qualified_pk_column,$selects)){ |
|
3113 | + if (count($tables) > 1) { |
|
3114 | + foreach ($tables as $table_obj) { |
|
3115 | + $qualified_pk_column = $table_alias_with_model_relation_chain_prefix.$table_obj->get_fully_qualified_pk_column(); |
|
3116 | + if ( ! in_array($qualified_pk_column, $selects)) { |
|
3117 | 3117 | $selects[] = "$qualified_pk_column AS '$qualified_pk_column'"; |
3118 | 3118 | } |
3119 | 3119 | } |
@@ -3143,65 +3143,65 @@ discard block |
||
3143 | 3143 | $query_param_type, |
3144 | 3144 | $original_query_param = null |
3145 | 3145 | ) { |
3146 | - if( $original_query_param === null ){ |
|
3146 | + if ($original_query_param === null) { |
|
3147 | 3147 | $original_query_param = $query_param; |
3148 | 3148 | } |
3149 | 3149 | $query_param = $this->_remove_stars_and_anything_after_from_condition_query_param_key($query_param); |
3150 | 3150 | /** @var $allow_logic_query_params bool whether or not to allow logic_query_params like 'NOT','OR', or 'AND' */ |
3151 | - $allow_logic_query_params = in_array($query_param_type,array('where','having')); |
|
3152 | - $allow_fields = in_array($query_param_type,array('where','having','order_by','group_by','order')); |
|
3151 | + $allow_logic_query_params = in_array($query_param_type, array('where', 'having')); |
|
3152 | + $allow_fields = in_array($query_param_type, array('where', 'having', 'order_by', 'group_by', 'order')); |
|
3153 | 3153 | //check to see if we have a field on this model |
3154 | 3154 | $this_model_fields = $this->field_settings(true); |
3155 | - if(array_key_exists($query_param,$this_model_fields)){ |
|
3156 | - if($allow_fields){ |
|
3155 | + if (array_key_exists($query_param, $this_model_fields)) { |
|
3156 | + if ($allow_fields) { |
|
3157 | 3157 | return; |
3158 | - }else{ |
|
3158 | + } else { |
|
3159 | 3159 | 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"), |
3160 | - $query_param,get_class($this),$query_param_type,$original_query_param)); |
|
3160 | + $query_param, get_class($this), $query_param_type, $original_query_param)); |
|
3161 | 3161 | } |
3162 | 3162 | } |
3163 | 3163 | //check if this is a special logic query param |
3164 | - elseif(in_array($query_param, $this->_logic_query_param_keys, TRUE)){ |
|
3165 | - if($allow_logic_query_params){ |
|
3164 | + elseif (in_array($query_param, $this->_logic_query_param_keys, TRUE)) { |
|
3165 | + if ($allow_logic_query_params) { |
|
3166 | 3166 | return; |
3167 | - }else{ |
|
3167 | + } else { |
|
3168 | 3168 | throw new EE_Error( |
3169 | 3169 | sprintf( |
3170 | - __( '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' ), |
|
3171 | - implode( '", "', $this->_logic_query_param_keys ), |
|
3172 | - $query_param , |
|
3173 | - get_class( $this ), |
|
3170 | + __('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'), |
|
3171 | + implode('", "', $this->_logic_query_param_keys), |
|
3172 | + $query_param, |
|
3173 | + get_class($this), |
|
3174 | 3174 | '<br />', |
3175 | - "\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 |
|
3175 | + "\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 |
|
3176 | 3176 | ) |
3177 | 3177 | ); |
3178 | 3178 | } |
3179 | 3179 | } |
3180 | 3180 | |
3181 | 3181 | //check if it's a custom selection |
3182 | - elseif(array_key_exists($query_param,$this->_custom_selections)){ |
|
3182 | + elseif (array_key_exists($query_param, $this->_custom_selections)) { |
|
3183 | 3183 | return; |
3184 | 3184 | } |
3185 | 3185 | |
3186 | 3186 | //check if has a model name at the beginning |
3187 | 3187 | //and |
3188 | 3188 | //check if it's a field on a related model |
3189 | - foreach($this->_model_relations as $valid_related_model_name=>$relation_obj){ |
|
3190 | - if(strpos($query_param, $valid_related_model_name.".") === 0){ |
|
3191 | - $this->_add_join_to_model($valid_related_model_name, $passed_in_query_info,$original_query_param); |
|
3189 | + foreach ($this->_model_relations as $valid_related_model_name=>$relation_obj) { |
|
3190 | + if (strpos($query_param, $valid_related_model_name.".") === 0) { |
|
3191 | + $this->_add_join_to_model($valid_related_model_name, $passed_in_query_info, $original_query_param); |
|
3192 | 3192 | $query_param = substr($query_param, strlen($valid_related_model_name.".")); |
3193 | - if($query_param === ''){ |
|
3193 | + if ($query_param === '') { |
|
3194 | 3194 | //nothing left to $query_param |
3195 | 3195 | //we should actually end in a field name, not a model like this! |
3196 | 3196 | throw new EE_Error(sprintf(__("Query param '%s' (of type %s on model %s) shouldn't end on a period (.) ", "event_espresso"), |
3197 | - $query_param,$query_param_type,get_class($this),$valid_related_model_name)); |
|
3198 | - }else{ |
|
3197 | + $query_param, $query_param_type, get_class($this), $valid_related_model_name)); |
|
3198 | + } else { |
|
3199 | 3199 | $related_model_obj = $this->get_related_model_obj($valid_related_model_name); |
3200 | 3200 | $related_model_obj->_extract_related_model_info_from_query_param($query_param, $passed_in_query_info, $query_param_type, $original_query_param); |
3201 | 3201 | return; |
3202 | 3202 | } |
3203 | - }elseif($query_param === $valid_related_model_name){ |
|
3204 | - $this->_add_join_to_model($valid_related_model_name, $passed_in_query_info,$original_query_param); |
|
3203 | + }elseif ($query_param === $valid_related_model_name) { |
|
3204 | + $this->_add_join_to_model($valid_related_model_name, $passed_in_query_info, $original_query_param); |
|
3205 | 3205 | return; |
3206 | 3206 | } |
3207 | 3207 | } |
@@ -3211,7 +3211,7 @@ discard block |
||
3211 | 3211 | //and we previously confirmed it wasn't a logic query param or field on the current model |
3212 | 3212 | //it's wack, that's what it is |
3213 | 3213 | 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"), |
3214 | - $query_param,get_class($this),$query_param_type,$original_query_param)); |
|
3214 | + $query_param, get_class($this), $query_param_type, $original_query_param)); |
|
3215 | 3215 | |
3216 | 3216 | } |
3217 | 3217 | |
@@ -3230,26 +3230,26 @@ discard block |
||
3230 | 3230 | * @return void |
3231 | 3231 | * @throws \EE_Error |
3232 | 3232 | */ |
3233 | - private function _add_join_to_model($model_name, EE_Model_Query_Info_Carrier $passed_in_query_info,$original_query_param){ |
|
3233 | + private function _add_join_to_model($model_name, EE_Model_Query_Info_Carrier $passed_in_query_info, $original_query_param) { |
|
3234 | 3234 | $relation_obj = $this->related_settings_for($model_name); |
3235 | 3235 | |
3236 | 3236 | $model_relation_chain = EE_Model_Parser::extract_model_relation_chain($model_name, $original_query_param); |
3237 | 3237 | //check if the relation is HABTM, because then we're essentially doing two joins |
3238 | 3238 | //If so, join first to the JOIN table, and add its data types, and then continue as normal |
3239 | - if($relation_obj instanceof EE_HABTM_Relation){ |
|
3239 | + if ($relation_obj instanceof EE_HABTM_Relation) { |
|
3240 | 3240 | $join_model_obj = $relation_obj->get_join_model(); |
3241 | 3241 | //replace the model specified with the join model for this relation chain, whi |
3242 | 3242 | $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); |
3243 | 3243 | $new_query_info = new EE_Model_Query_Info_Carrier( |
3244 | 3244 | array($relation_chain_to_join_model => $join_model_obj->get_this_model_name()), |
3245 | 3245 | $relation_obj->get_join_to_intermediate_model_statement($relation_chain_to_join_model)); |
3246 | - $passed_in_query_info->merge( $new_query_info ); |
|
3246 | + $passed_in_query_info->merge($new_query_info); |
|
3247 | 3247 | } |
3248 | 3248 | //now just join to the other table pointed to by the relation object, and add its data types |
3249 | 3249 | $new_query_info = new EE_Model_Query_Info_Carrier( |
3250 | 3250 | array($model_relation_chain=>$model_name), |
3251 | 3251 | $relation_obj->get_join_statement($model_relation_chain)); |
3252 | - $passed_in_query_info->merge( $new_query_info ); |
|
3252 | + $passed_in_query_info->merge($new_query_info); |
|
3253 | 3253 | } |
3254 | 3254 | |
3255 | 3255 | |
@@ -3261,11 +3261,11 @@ discard block |
||
3261 | 3261 | * @return string of SQL |
3262 | 3262 | * @throws \EE_Error |
3263 | 3263 | */ |
3264 | - private function _construct_where_clause($where_params){ |
|
3264 | + private function _construct_where_clause($where_params) { |
|
3265 | 3265 | $SQL = $this->_construct_condition_clause_recursive($where_params, ' AND '); |
3266 | - if($SQL){ |
|
3267 | - return " WHERE ". $SQL; |
|
3268 | - }else{ |
|
3266 | + if ($SQL) { |
|
3267 | + return " WHERE ".$SQL; |
|
3268 | + } else { |
|
3269 | 3269 | return ''; |
3270 | 3270 | } |
3271 | 3271 | } |
@@ -3280,11 +3280,11 @@ discard block |
||
3280 | 3280 | * @return string |
3281 | 3281 | * @throws \EE_Error |
3282 | 3282 | */ |
3283 | - private function _construct_having_clause($having_params){ |
|
3283 | + private function _construct_having_clause($having_params) { |
|
3284 | 3284 | $SQL = $this->_construct_condition_clause_recursive($having_params, ' AND '); |
3285 | - if($SQL){ |
|
3286 | - return " HAVING ". $SQL; |
|
3287 | - }else{ |
|
3285 | + if ($SQL) { |
|
3286 | + return " HAVING ".$SQL; |
|
3287 | + } else { |
|
3288 | 3288 | return ''; |
3289 | 3289 | } |
3290 | 3290 | |
@@ -3298,17 +3298,17 @@ discard block |
||
3298 | 3298 | * @return EE_Model_Field_Base |
3299 | 3299 | * @throws EE_Error |
3300 | 3300 | */ |
3301 | - protected function _get_field_on_model($field_name,$model_name){ |
|
3301 | + protected function _get_field_on_model($field_name, $model_name) { |
|
3302 | 3302 | $model_class = 'EEM_'.$model_name; |
3303 | 3303 | $model_filepath = $model_class.".model.php"; |
3304 | - EE_Registry::instance()->load_helper( 'File' ); |
|
3305 | - if ( is_readable($model_filepath)){ |
|
3304 | + EE_Registry::instance()->load_helper('File'); |
|
3305 | + if (is_readable($model_filepath)) { |
|
3306 | 3306 | require_once($model_filepath); |
3307 | - $model_instance=call_user_func($model_name."::instance"); |
|
3307 | + $model_instance = call_user_func($model_name."::instance"); |
|
3308 | 3308 | /* @var $model_instance EEM_Base */ |
3309 | 3309 | return $model_instance->field_settings_for($field_name); |
3310 | - }else{ |
|
3311 | - 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 | + } else { |
|
3311 | + throw new EE_Error(sprintf(__('No model named %s exists, with classname %s and filepath %s', 'event_espresso'), $model_name, $model_class, $model_filepath)); |
|
3312 | 3312 | } |
3313 | 3313 | } |
3314 | 3314 | |
@@ -3321,41 +3321,41 @@ discard block |
||
3321 | 3321 | * @throws EE_Error |
3322 | 3322 | * @return string of SQL |
3323 | 3323 | */ |
3324 | - private function _construct_condition_clause_recursive($where_params, $glue = ' AND'){ |
|
3325 | - $where_clauses=array(); |
|
3326 | - foreach($where_params as $query_param => $op_and_value_or_sub_condition){ |
|
3327 | - $query_param = $this->_remove_stars_and_anything_after_from_condition_query_param_key($query_param);//str_replace("*",'',$query_param); |
|
3328 | - if(in_array($query_param,$this->_logic_query_param_keys)){ |
|
3329 | - switch($query_param){ |
|
3324 | + private function _construct_condition_clause_recursive($where_params, $glue = ' AND') { |
|
3325 | + $where_clauses = array(); |
|
3326 | + foreach ($where_params as $query_param => $op_and_value_or_sub_condition) { |
|
3327 | + $query_param = $this->_remove_stars_and_anything_after_from_condition_query_param_key($query_param); //str_replace("*",'',$query_param); |
|
3328 | + if (in_array($query_param, $this->_logic_query_param_keys)) { |
|
3329 | + switch ($query_param) { |
|
3330 | 3330 | case 'not': |
3331 | 3331 | case 'NOT': |
3332 | - $where_clauses[] = "! (". $this->_construct_condition_clause_recursive($op_and_value_or_sub_condition, $glue).")"; |
|
3332 | + $where_clauses[] = "! (".$this->_construct_condition_clause_recursive($op_and_value_or_sub_condition, $glue).")"; |
|
3333 | 3333 | break; |
3334 | 3334 | case 'and': |
3335 | 3335 | case 'AND': |
3336 | - $where_clauses[] = " (". $this->_construct_condition_clause_recursive($op_and_value_or_sub_condition, ' AND ') .")"; |
|
3336 | + $where_clauses[] = " (".$this->_construct_condition_clause_recursive($op_and_value_or_sub_condition, ' AND ').")"; |
|
3337 | 3337 | break; |
3338 | 3338 | case 'or': |
3339 | 3339 | case 'OR': |
3340 | - $where_clauses[] = " (". $this->_construct_condition_clause_recursive($op_and_value_or_sub_condition, ' OR ') .")"; |
|
3340 | + $where_clauses[] = " (".$this->_construct_condition_clause_recursive($op_and_value_or_sub_condition, ' OR ').")"; |
|
3341 | 3341 | break; |
3342 | 3342 | } |
3343 | - }else{ |
|
3343 | + } else { |
|
3344 | 3344 | $field_obj = $this->_deduce_field_from_query_param($query_param); |
3345 | 3345 | |
3346 | 3346 | //if it's not a normal field, maybe it's a custom selection? |
3347 | - if( ! $field_obj){ |
|
3348 | - if(isset( $this->_custom_selections[$query_param][1])){ |
|
3347 | + if ( ! $field_obj) { |
|
3348 | + if (isset($this->_custom_selections[$query_param][1])) { |
|
3349 | 3349 | $field_obj = $this->_custom_selections[$query_param][1]; |
3350 | - }else{ |
|
3351 | - throw new EE_Error(sprintf(__("%s is neither a valid model field name, nor a custom selection", "event_espresso"),$query_param)); |
|
3350 | + } else { |
|
3351 | + throw new EE_Error(sprintf(__("%s is neither a valid model field name, nor a custom selection", "event_espresso"), $query_param)); |
|
3352 | 3352 | } |
3353 | 3353 | } |
3354 | 3354 | $op_and_value_sql = $this->_construct_op_and_value($op_and_value_or_sub_condition, $field_obj); |
3355 | - $where_clauses[]=$this->_deduce_column_name_from_query_param($query_param).SP.$op_and_value_sql; |
|
3355 | + $where_clauses[] = $this->_deduce_column_name_from_query_param($query_param).SP.$op_and_value_sql; |
|
3356 | 3356 | } |
3357 | 3357 | } |
3358 | - return $where_clauses ? implode( $glue, $where_clauses ) : ''; |
|
3358 | + return $where_clauses ? implode($glue, $where_clauses) : ''; |
|
3359 | 3359 | } |
3360 | 3360 | |
3361 | 3361 | |
@@ -3366,18 +3366,18 @@ discard block |
||
3366 | 3366 | * @throws EE_Error |
3367 | 3367 | * @return string table alias and column name for SQL, eg "Transaction.TXN_ID" |
3368 | 3368 | */ |
3369 | - private function _deduce_column_name_from_query_param($query_param){ |
|
3369 | + private function _deduce_column_name_from_query_param($query_param) { |
|
3370 | 3370 | $field = $this->_deduce_field_from_query_param($query_param); |
3371 | 3371 | |
3372 | - if( $field ){ |
|
3373 | - $table_alias_prefix = EE_Model_Parser::extract_table_alias_model_relation_chain_from_query_param( $field->get_model_name(), $query_param ); |
|
3374 | - return $table_alias_prefix . $field->get_qualified_column(); |
|
3375 | - }elseif(array_key_exists($query_param,$this->_custom_selections)){ |
|
3372 | + if ($field) { |
|
3373 | + $table_alias_prefix = EE_Model_Parser::extract_table_alias_model_relation_chain_from_query_param($field->get_model_name(), $query_param); |
|
3374 | + return $table_alias_prefix.$field->get_qualified_column(); |
|
3375 | + }elseif (array_key_exists($query_param, $this->_custom_selections)) { |
|
3376 | 3376 | //maybe it's custom selection item? |
3377 | 3377 | //if so, just use it as the "column name" |
3378 | 3378 | return $query_param; |
3379 | - }else{ |
|
3380 | - 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 | + } else { |
|
3380 | + 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))); |
|
3381 | 3381 | } |
3382 | 3382 | } |
3383 | 3383 | |
@@ -3389,11 +3389,11 @@ discard block |
||
3389 | 3389 | * @param string $condition_query_param_key |
3390 | 3390 | * @return string |
3391 | 3391 | */ |
3392 | - private function _remove_stars_and_anything_after_from_condition_query_param_key($condition_query_param_key){ |
|
3392 | + private function _remove_stars_and_anything_after_from_condition_query_param_key($condition_query_param_key) { |
|
3393 | 3393 | $pos_of_star = strpos($condition_query_param_key, '*'); |
3394 | - if($pos_of_star === FALSE){ |
|
3394 | + if ($pos_of_star === FALSE) { |
|
3395 | 3395 | return $condition_query_param_key; |
3396 | - }else{ |
|
3396 | + } else { |
|
3397 | 3397 | $condition_query_param_sans_star = substr($condition_query_param_key, 0, $pos_of_star); |
3398 | 3398 | return $condition_query_param_sans_star; |
3399 | 3399 | } |
@@ -3408,12 +3408,12 @@ discard block |
||
3408 | 3408 | * @throws EE_Error |
3409 | 3409 | * @return string |
3410 | 3410 | */ |
3411 | - private function _construct_op_and_value($op_and_value, $field_obj){ |
|
3412 | - if ( is_array( $op_and_value ) ) { |
|
3413 | - $operator = isset( $op_and_value[0] ) ? $this->_prepare_operator_for_sql( $op_and_value[0] ) : null; |
|
3414 | - if ( ! $operator ) { |
|
3411 | + private function _construct_op_and_value($op_and_value, $field_obj) { |
|
3412 | + if (is_array($op_and_value)) { |
|
3413 | + $operator = isset($op_and_value[0]) ? $this->_prepare_operator_for_sql($op_and_value[0]) : null; |
|
3414 | + if ( ! $operator) { |
|
3415 | 3415 | $php_array_like_string = array(); |
3416 | - foreach ( $op_and_value as $key => $value ) { |
|
3416 | + foreach ($op_and_value as $key => $value) { |
|
3417 | 3417 | $php_array_like_string[] = "$key=>$value"; |
3418 | 3418 | } |
3419 | 3419 | throw new EE_Error( |
@@ -3422,27 +3422,27 @@ discard block |
||
3422 | 3422 | "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))", |
3423 | 3423 | "event_espresso" |
3424 | 3424 | ), |
3425 | - implode( ",", $php_array_like_string ) |
|
3425 | + implode(",", $php_array_like_string) |
|
3426 | 3426 | ) |
3427 | 3427 | ); |
3428 | 3428 | } |
3429 | - $value = isset( $op_and_value[1] ) ? $op_and_value[1] : null; |
|
3429 | + $value = isset($op_and_value[1]) ? $op_and_value[1] : null; |
|
3430 | 3430 | } else { |
3431 | 3431 | $operator = '='; |
3432 | 3432 | $value = $op_and_value; |
3433 | 3433 | } |
3434 | 3434 | //check to see if the value is actually another field |
3435 | - if ( is_array( $op_and_value ) && isset( $op_and_value[2] ) && $op_and_value[2] == true ) { |
|
3436 | - return $operator . SP . $this->_deduce_column_name_from_query_param( $value ); |
|
3437 | - } elseif ( in_array( $operator, $this->_in_style_operators ) && is_array( $value ) ) { |
|
3435 | + if (is_array($op_and_value) && isset($op_and_value[2]) && $op_and_value[2] == true) { |
|
3436 | + return $operator.SP.$this->_deduce_column_name_from_query_param($value); |
|
3437 | + } elseif (in_array($operator, $this->_in_style_operators) && is_array($value)) { |
|
3438 | 3438 | //in this case, the value should be an array, or at least a comma-separated list |
3439 | 3439 | //it will need to handle a little differently |
3440 | - $cleaned_value = $this->_construct_in_value( $value, $field_obj ); |
|
3440 | + $cleaned_value = $this->_construct_in_value($value, $field_obj); |
|
3441 | 3441 | //note: $cleaned_value has already been run through $wpdb->prepare() |
3442 | - return $operator . SP . $cleaned_value; |
|
3443 | - } elseif ( in_array( $operator, $this->_between_style_operators ) && is_array( $value ) ) { |
|
3442 | + return $operator.SP.$cleaned_value; |
|
3443 | + } elseif (in_array($operator, $this->_between_style_operators) && is_array($value)) { |
|
3444 | 3444 | //the value should be an array with count of two. |
3445 | - if ( count( $value ) !== 2 ) { |
|
3445 | + if (count($value) !== 2) { |
|
3446 | 3446 | throw new EE_Error( |
3447 | 3447 | sprintf( |
3448 | 3448 | __( |
@@ -3453,10 +3453,10 @@ discard block |
||
3453 | 3453 | ) |
3454 | 3454 | ); |
3455 | 3455 | } |
3456 | - $cleaned_value = $this->_construct_between_value( $value, $field_obj ); |
|
3457 | - return $operator . SP . $cleaned_value; |
|
3458 | - } elseif ( in_array( $operator, $this->_null_style_operators ) ) { |
|
3459 | - if ( $value !== null ) { |
|
3456 | + $cleaned_value = $this->_construct_between_value($value, $field_obj); |
|
3457 | + return $operator.SP.$cleaned_value; |
|
3458 | + } elseif (in_array($operator, $this->_null_style_operators)) { |
|
3459 | + if ($value !== null) { |
|
3460 | 3460 | throw new EE_Error( |
3461 | 3461 | sprintf( |
3462 | 3462 | __( |
@@ -3469,13 +3469,13 @@ discard block |
||
3469 | 3469 | ); |
3470 | 3470 | } |
3471 | 3471 | return $operator; |
3472 | - } elseif ( $operator === 'LIKE' && ! is_array( $value ) ) { |
|
3472 | + } elseif ($operator === 'LIKE' && ! is_array($value)) { |
|
3473 | 3473 | //if the operator is 'LIKE', we want to allow percent signs (%) and not |
3474 | 3474 | //remove other junk. So just treat it as a string. |
3475 | - return $operator . SP . $this->_wpdb_prepare_using_field( $value, '%s' ); |
|
3476 | - } elseif ( ! in_array( $operator, $this->_in_style_operators ) && ! is_array( $value ) ) { |
|
3477 | - return $operator . SP . $this->_wpdb_prepare_using_field( $value, $field_obj ); |
|
3478 | - } elseif ( in_array( $operator, $this->_in_style_operators ) && ! is_array( $value ) ) { |
|
3475 | + return $operator.SP.$this->_wpdb_prepare_using_field($value, '%s'); |
|
3476 | + } elseif ( ! in_array($operator, $this->_in_style_operators) && ! is_array($value)) { |
|
3477 | + return $operator.SP.$this->_wpdb_prepare_using_field($value, $field_obj); |
|
3478 | + } elseif (in_array($operator, $this->_in_style_operators) && ! is_array($value)) { |
|
3479 | 3479 | throw new EE_Error( |
3480 | 3480 | sprintf( |
3481 | 3481 | __( |
@@ -3486,7 +3486,7 @@ discard block |
||
3486 | 3486 | $operator |
3487 | 3487 | ) |
3488 | 3488 | ); |
3489 | - } elseif ( ! in_array( $operator, $this->_in_style_operators ) && is_array( $value ) ) { |
|
3489 | + } elseif ( ! in_array($operator, $this->_in_style_operators) && is_array($value)) { |
|
3490 | 3490 | throw new EE_Error( |
3491 | 3491 | sprintf( |
3492 | 3492 | __( |
@@ -3504,7 +3504,7 @@ discard block |
||
3504 | 3504 | "It appears you've provided some totally invalid query parameters. Operator and value were:'%s', which isn't right at all", |
3505 | 3505 | "event_espresso" |
3506 | 3506 | ), |
3507 | - http_build_query( $op_and_value ) |
|
3507 | + http_build_query($op_and_value) |
|
3508 | 3508 | ) |
3509 | 3509 | ); |
3510 | 3510 | } |
@@ -3520,12 +3520,12 @@ discard block |
||
3520 | 3520 | * @return string |
3521 | 3521 | * @throws \EE_Error |
3522 | 3522 | */ |
3523 | - public function _construct_between_value( $values, $field_obj ) { |
|
3523 | + public function _construct_between_value($values, $field_obj) { |
|
3524 | 3524 | $cleaned_values = array(); |
3525 | - foreach ( $values as $value ) { |
|
3526 | - $cleaned_values[] = $this->_wpdb_prepare_using_field($value,$field_obj); |
|
3525 | + foreach ($values as $value) { |
|
3526 | + $cleaned_values[] = $this->_wpdb_prepare_using_field($value, $field_obj); |
|
3527 | 3527 | } |
3528 | - return $cleaned_values[0] . " AND " . $cleaned_values[1]; |
|
3528 | + return $cleaned_values[0]." AND ".$cleaned_values[1]; |
|
3529 | 3529 | } |
3530 | 3530 | |
3531 | 3531 | |
@@ -3542,26 +3542,26 @@ discard block |
||
3542 | 3542 | * @return string of SQL to follow an 'IN' or 'NOT IN' operator |
3543 | 3543 | * @throws \EE_Error |
3544 | 3544 | */ |
3545 | - public function _construct_in_value($values, $field_obj){ |
|
3545 | + public function _construct_in_value($values, $field_obj) { |
|
3546 | 3546 | //check if the value is a CSV list |
3547 | - if(is_string($values)){ |
|
3547 | + if (is_string($values)) { |
|
3548 | 3548 | //in which case, turn it into an array |
3549 | - $values = explode(",",$values); |
|
3549 | + $values = explode(",", $values); |
|
3550 | 3550 | } |
3551 | 3551 | $cleaned_values = array(); |
3552 | - foreach($values as $value){ |
|
3553 | - $cleaned_values[] = $this->_wpdb_prepare_using_field($value,$field_obj); |
|
3552 | + foreach ($values as $value) { |
|
3553 | + $cleaned_values[] = $this->_wpdb_prepare_using_field($value, $field_obj); |
|
3554 | 3554 | } |
3555 | 3555 | //we would just LOVE to leave $cleaned_values as an empty array, and return the value as "()", |
3556 | 3556 | //but unfortunately that's invalid SQL. So instead we return a string which we KNOW will evaluate to be the empty set |
3557 | 3557 | //which is effectively equivalent to returning "()". We don't return "(0)" because that only works for auto-incrementing columns |
3558 | - if(empty($cleaned_values)){ |
|
3558 | + if (empty($cleaned_values)) { |
|
3559 | 3559 | $all_fields = $this->field_settings(); |
3560 | 3560 | $a_field = array_shift($all_fields); |
3561 | 3561 | $main_table = $this->_get_main_table(); |
3562 | 3562 | $cleaned_values[] = "SELECT ".$a_field->get_table_column()." FROM ".$main_table->get_table_name()." WHERE FALSE"; |
3563 | 3563 | } |
3564 | - return "(".implode(",",$cleaned_values).")"; |
|
3564 | + return "(".implode(",", $cleaned_values).")"; |
|
3565 | 3565 | } |
3566 | 3566 | |
3567 | 3567 | |
@@ -3573,16 +3573,16 @@ discard block |
||
3573 | 3573 | * @throws EE_Error |
3574 | 3574 | * @return false|null|string |
3575 | 3575 | */ |
3576 | - private function _wpdb_prepare_using_field($value,$field_obj){ |
|
3576 | + private function _wpdb_prepare_using_field($value, $field_obj) { |
|
3577 | 3577 | /** @type WPDB $wpdb */ |
3578 | 3578 | global $wpdb; |
3579 | - if($field_obj instanceof EE_Model_Field_Base){ |
|
3580 | - return $wpdb->prepare($field_obj->get_wpdb_data_type(),$this->_prepare_value_for_use_in_db($value, $field_obj)); |
|
3581 | - }else{//$field_obj should really just be a data type |
|
3582 | - if( ! in_array($field_obj,$this->_valid_wpdb_data_types)){ |
|
3583 | - 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))); |
|
3579 | + if ($field_obj instanceof EE_Model_Field_Base) { |
|
3580 | + return $wpdb->prepare($field_obj->get_wpdb_data_type(), $this->_prepare_value_for_use_in_db($value, $field_obj)); |
|
3581 | + } else {//$field_obj should really just be a data type |
|
3582 | + if ( ! in_array($field_obj, $this->_valid_wpdb_data_types)) { |
|
3583 | + 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))); |
|
3584 | 3584 | } |
3585 | - return $wpdb->prepare($field_obj,$value); |
|
3585 | + return $wpdb->prepare($field_obj, $value); |
|
3586 | 3586 | } |
3587 | 3587 | } |
3588 | 3588 | |
@@ -3594,27 +3594,27 @@ discard block |
||
3594 | 3594 | * @throws EE_Error |
3595 | 3595 | * @return EE_Model_Field_Base |
3596 | 3596 | */ |
3597 | - protected function _deduce_field_from_query_param($query_param_name){ |
|
3597 | + protected function _deduce_field_from_query_param($query_param_name) { |
|
3598 | 3598 | //ok, now proceed with deducing which part is the model's name, and which is the field's name |
3599 | 3599 | //which will help us find the database table and column |
3600 | 3600 | |
3601 | - $query_param_parts = explode(".",$query_param_name); |
|
3602 | - if(empty($query_param_parts)){ |
|
3603 | - 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)); |
|
3601 | + $query_param_parts = explode(".", $query_param_name); |
|
3602 | + if (empty($query_param_parts)) { |
|
3603 | + 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)); |
|
3604 | 3604 | } |
3605 | 3605 | $number_of_parts = count($query_param_parts); |
3606 | - $last_query_param_part = $query_param_parts[ count($query_param_parts) - 1 ]; |
|
3607 | - if($number_of_parts === 1){ |
|
3606 | + $last_query_param_part = $query_param_parts[count($query_param_parts) - 1]; |
|
3607 | + if ($number_of_parts === 1) { |
|
3608 | 3608 | $field_name = $last_query_param_part; |
3609 | 3609 | $model_obj = $this; |
3610 | - }else{// $number_of_parts >= 2 |
|
3610 | + } else {// $number_of_parts >= 2 |
|
3611 | 3611 | //the last part is the column name, and there are only 2parts. therefore... |
3612 | 3612 | $field_name = $last_query_param_part; |
3613 | - $model_obj = $this->get_related_model_obj( $query_param_parts[ $number_of_parts - 2 ]); |
|
3613 | + $model_obj = $this->get_related_model_obj($query_param_parts[$number_of_parts - 2]); |
|
3614 | 3614 | } |
3615 | - try{ |
|
3615 | + try { |
|
3616 | 3616 | return $model_obj->field_settings_for($field_name); |
3617 | - }catch(EE_Error $e){ |
|
3617 | + } catch (EE_Error $e) { |
|
3618 | 3618 | return null; |
3619 | 3619 | } |
3620 | 3620 | } |
@@ -3628,13 +3628,13 @@ discard block |
||
3628 | 3628 | * @throws EE_Error |
3629 | 3629 | * @return string |
3630 | 3630 | */ |
3631 | - public function _get_qualified_column_for_field($field_name){ |
|
3631 | + public function _get_qualified_column_for_field($field_name) { |
|
3632 | 3632 | $all_fields = $this->field_settings(); |
3633 | 3633 | $field = isset($all_fields[$field_name]) ? $all_fields[$field_name] : FALSE; |
3634 | - if($field){ |
|
3634 | + if ($field) { |
|
3635 | 3635 | return $field->get_qualified_column(); |
3636 | - }else{ |
|
3637 | - 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 | + } else { |
|
3637 | + 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))); |
|
3638 | 3638 | } |
3639 | 3639 | } |
3640 | 3640 | |
@@ -3648,17 +3648,17 @@ discard block |
||
3648 | 3648 | * @param mixed|string $limit The limit for this select |
3649 | 3649 | * @return string The final select join element for the query. |
3650 | 3650 | */ |
3651 | - public function _construct_limit_join_select( $table_alias, $limit ) { |
|
3651 | + public function _construct_limit_join_select($table_alias, $limit) { |
|
3652 | 3652 | $SQL = ''; |
3653 | - foreach ( $this->_tables as $table_obj ) { |
|
3654 | - if ( $table_obj instanceof EE_Primary_Table ) { |
|
3653 | + foreach ($this->_tables as $table_obj) { |
|
3654 | + if ($table_obj instanceof EE_Primary_Table) { |
|
3655 | 3655 | $SQL .= $table_alias === $table_obj->get_table_alias() |
3656 | - ? $table_obj->get_select_join_limit( $limit ) |
|
3657 | - : SP . $table_obj->get_table_name() . " AS " . $table_obj->get_table_alias() . SP; |
|
3658 | - } elseif ( $table_obj instanceof EE_Secondary_Table ) { |
|
3656 | + ? $table_obj->get_select_join_limit($limit) |
|
3657 | + : SP.$table_obj->get_table_name()." AS ".$table_obj->get_table_alias().SP; |
|
3658 | + } elseif ($table_obj instanceof EE_Secondary_Table) { |
|
3659 | 3659 | $SQL .= $table_alias === $table_obj->get_table_alias() |
3660 | - ? $table_obj->get_select_join_limit_join( $limit ) |
|
3661 | - : SP . $table_obj->get_join_sql( $table_alias ) . SP; |
|
3660 | + ? $table_obj->get_select_join_limit_join($limit) |
|
3661 | + : SP.$table_obj->get_join_sql($table_alias).SP; |
|
3662 | 3662 | } |
3663 | 3663 | } |
3664 | 3664 | return $SQL; |
@@ -3673,7 +3673,7 @@ discard block |
||
3673 | 3673 | * @return string SQL |
3674 | 3674 | * @throws \EE_Error |
3675 | 3675 | */ |
3676 | - public function _construct_internal_join(){ |
|
3676 | + public function _construct_internal_join() { |
|
3677 | 3677 | $SQL = $this->_get_main_table()->get_table_sql(); |
3678 | 3678 | $SQL .= $this->_construct_internal_join_to_table_with_alias($this->_get_main_table()->get_table_alias()); |
3679 | 3679 | return $SQL; |
@@ -3694,17 +3694,17 @@ discard block |
||
3694 | 3694 | * @param string $alias_prefixed table alias to join to (this table should already be in the FROM SQL clause) |
3695 | 3695 | * @return string |
3696 | 3696 | */ |
3697 | - public function _construct_internal_join_to_table_with_alias($alias_prefixed){ |
|
3697 | + public function _construct_internal_join_to_table_with_alias($alias_prefixed) { |
|
3698 | 3698 | $SQL = ''; |
3699 | 3699 | $alias_sans_prefix = EE_Model_Parser::remove_table_alias_model_relation_chain_prefix($alias_prefixed); |
3700 | - foreach($this->_tables as $table_obj){ |
|
3701 | - if($table_obj instanceof EE_Secondary_Table){//table is secondary table |
|
3702 | - if($alias_sans_prefix === $table_obj->get_table_alias()){ |
|
3700 | + foreach ($this->_tables as $table_obj) { |
|
3701 | + if ($table_obj instanceof EE_Secondary_Table) {//table is secondary table |
|
3702 | + if ($alias_sans_prefix === $table_obj->get_table_alias()) { |
|
3703 | 3703 | //so we're joining to this table, meaning the table is already in |
3704 | 3704 | //the FROM statement, BUT the primary table isn't. So we want |
3705 | 3705 | //to add the inverse join sql |
3706 | 3706 | $SQL .= $table_obj->get_inverse_join_sql($alias_prefixed); |
3707 | - }else{ |
|
3707 | + } else { |
|
3708 | 3708 | //just add a regular JOIN to this table from the primary table |
3709 | 3709 | $SQL .= $table_obj->get_join_sql($alias_prefixed); |
3710 | 3710 | } |
@@ -3718,9 +3718,9 @@ discard block |
||
3718 | 3718 | * 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) |
3719 | 3719 | * @return array |
3720 | 3720 | */ |
3721 | - public function _get_data_types(){ |
|
3721 | + public function _get_data_types() { |
|
3722 | 3722 | $data_types = array(); |
3723 | - foreach( $this->field_settings() as $field_obj){ |
|
3723 | + foreach ($this->field_settings() as $field_obj) { |
|
3724 | 3724 | //$data_types[$field_obj->get_table_column()] = $field_obj->get_wpdb_data_type(); |
3725 | 3725 | /** @var $field_obj EE_Model_Field_Base */ |
3726 | 3726 | $data_types[$field_obj->get_qualified_column()] = $field_obj->get_wpdb_data_type(); |
@@ -3736,10 +3736,10 @@ discard block |
||
3736 | 3736 | * @throws EE_Error |
3737 | 3737 | * @return EEM_Base |
3738 | 3738 | */ |
3739 | - public function get_related_model_obj($model_name){ |
|
3739 | + public function get_related_model_obj($model_name) { |
|
3740 | 3740 | $model_classname = "EEM_".$model_name; |
3741 | - if(!class_exists($model_classname)){ |
|
3742 | - 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 | + if ( ! class_exists($model_classname)) { |
|
3742 | + 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)); |
|
3743 | 3743 | } |
3744 | 3744 | return call_user_func($model_classname."::instance"); |
3745 | 3745 | } |
@@ -3749,7 +3749,7 @@ discard block |
||
3749 | 3749 | * Returns the array of EE_ModelRelations for this model. |
3750 | 3750 | * @return EE_Model_Relation_Base[] |
3751 | 3751 | */ |
3752 | - public function relation_settings(){ |
|
3752 | + public function relation_settings() { |
|
3753 | 3753 | return $this->_model_relations; |
3754 | 3754 | } |
3755 | 3755 | |
@@ -3759,10 +3759,10 @@ discard block |
||
3759 | 3759 | * (Eg, without an event, datetimes have little purpose.) |
3760 | 3760 | * @return EE_Belongs_To_Relation[] |
3761 | 3761 | */ |
3762 | - public function belongs_to_relations(){ |
|
3762 | + public function belongs_to_relations() { |
|
3763 | 3763 | $belongs_to_relations = array(); |
3764 | - foreach($this->relation_settings() as $model_name => $relation_obj){ |
|
3765 | - if($relation_obj instanceof EE_Belongs_To_Relation){ |
|
3764 | + foreach ($this->relation_settings() as $model_name => $relation_obj) { |
|
3765 | + if ($relation_obj instanceof EE_Belongs_To_Relation) { |
|
3766 | 3766 | $belongs_to_relations[$model_name] = $relation_obj; |
3767 | 3767 | } |
3768 | 3768 | } |
@@ -3777,15 +3777,15 @@ discard block |
||
3777 | 3777 | * @throws EE_Error |
3778 | 3778 | * @return EE_Model_Relation_Base |
3779 | 3779 | */ |
3780 | - public function related_settings_for($relation_name){ |
|
3781 | - $relatedModels=$this->relation_settings(); |
|
3782 | - if(!array_key_exists($relation_name,$relatedModels)){ |
|
3780 | + public function related_settings_for($relation_name) { |
|
3781 | + $relatedModels = $this->relation_settings(); |
|
3782 | + if ( ! array_key_exists($relation_name, $relatedModels)) { |
|
3783 | 3783 | throw new EE_Error( |
3784 | 3784 | sprintf( |
3785 | - __('Cannot get %s related to %s. There is no model relation of that type. There is, however, %s...','event_espresso'), |
|
3785 | + __('Cannot get %s related to %s. There is no model relation of that type. There is, however, %s...', 'event_espresso'), |
|
3786 | 3786 | $relation_name, |
3787 | 3787 | $this->_get_class_name(), |
3788 | - implode( ', ', array_keys( $relatedModels )) |
|
3788 | + implode(', ', array_keys($relatedModels)) |
|
3789 | 3789 | ) |
3790 | 3790 | ); |
3791 | 3791 | } |
@@ -3800,10 +3800,10 @@ discard block |
||
3800 | 3800 | * @throws EE_Error |
3801 | 3801 | * @return EE_Model_Field_Base |
3802 | 3802 | */ |
3803 | - public function field_settings_for($fieldName){ |
|
3804 | - $fieldSettings=$this->field_settings(true); |
|
3805 | - if( ! array_key_exists($fieldName,$fieldSettings)){ |
|
3806 | - throw new EE_Error(sprintf(__("There is no field/column '%s' on '%s'",'event_espresso'),$fieldName,get_class($this))); |
|
3803 | + public function field_settings_for($fieldName) { |
|
3804 | + $fieldSettings = $this->field_settings(true); |
|
3805 | + if ( ! array_key_exists($fieldName, $fieldSettings)) { |
|
3806 | + throw new EE_Error(sprintf(__("There is no field/column '%s' on '%s'", 'event_espresso'), $fieldName, get_class($this))); |
|
3807 | 3807 | } |
3808 | 3808 | return $fieldSettings[$fieldName]; |
3809 | 3809 | } |
@@ -3813,11 +3813,11 @@ discard block |
||
3813 | 3813 | * @param string $fieldName a key in the model's _field_settings array |
3814 | 3814 | * @return boolean |
3815 | 3815 | */ |
3816 | - public function has_field($fieldName){ |
|
3816 | + public function has_field($fieldName) { |
|
3817 | 3817 | $fieldSettings = $this->field_settings(true); |
3818 | - if( isset($fieldSettings[$fieldName])){ |
|
3818 | + if (isset($fieldSettings[$fieldName])) { |
|
3819 | 3819 | return true; |
3820 | - }else{ |
|
3820 | + } else { |
|
3821 | 3821 | return false; |
3822 | 3822 | } |
3823 | 3823 | } |
@@ -3827,11 +3827,11 @@ discard block |
||
3827 | 3827 | * @param string $relation_name possibly one of the keys in the relation_settings array |
3828 | 3828 | * @return boolean |
3829 | 3829 | */ |
3830 | - public function has_relation($relation_name){ |
|
3830 | + public function has_relation($relation_name) { |
|
3831 | 3831 | $relations = $this->relation_settings(); |
3832 | - if(isset($relations[$relation_name])){ |
|
3832 | + if (isset($relations[$relation_name])) { |
|
3833 | 3833 | return true; |
3834 | - }else{ |
|
3834 | + } else { |
|
3835 | 3835 | return false; |
3836 | 3836 | } |
3837 | 3837 | } |
@@ -3843,7 +3843,7 @@ discard block |
||
3843 | 3843 | * @param $field_obj |
3844 | 3844 | * @return EE_Model_Field_Base |
3845 | 3845 | */ |
3846 | - public function is_primary_key_field( $field_obj ){ |
|
3846 | + public function is_primary_key_field($field_obj) { |
|
3847 | 3847 | return $field_obj instanceof EE_Primary_Key_Field_Base ? TRUE : FALSE; |
3848 | 3848 | } |
3849 | 3849 | |
@@ -3855,16 +3855,16 @@ discard block |
||
3855 | 3855 | * @return EE_Model_Field_Base |
3856 | 3856 | * @throws EE_Error |
3857 | 3857 | */ |
3858 | - public function get_primary_key_field(){ |
|
3859 | - if( $this->_primary_key_field === NULL ){ |
|
3860 | - foreach( $this->field_settings( TRUE ) as $field_obj ){ |
|
3861 | - if( $this->is_primary_key_field( $field_obj )){ |
|
3858 | + public function get_primary_key_field() { |
|
3859 | + if ($this->_primary_key_field === NULL) { |
|
3860 | + foreach ($this->field_settings(TRUE) as $field_obj) { |
|
3861 | + if ($this->is_primary_key_field($field_obj)) { |
|
3862 | 3862 | $this->_primary_key_field = $field_obj; |
3863 | 3863 | break; |
3864 | 3864 | } |
3865 | 3865 | } |
3866 | - if( ! $this->_primary_key_field instanceof EE_Primary_Key_Field_Base ){ |
|
3867 | - throw new EE_Error(sprintf(__("There is no Primary Key defined on model %s",'event_espresso'),get_class($this))); |
|
3866 | + if ( ! $this->_primary_key_field instanceof EE_Primary_Key_Field_Base) { |
|
3867 | + throw new EE_Error(sprintf(__("There is no Primary Key defined on model %s", 'event_espresso'), get_class($this))); |
|
3868 | 3868 | } |
3869 | 3869 | } |
3870 | 3870 | return $this->_primary_key_field; |
@@ -3877,12 +3877,12 @@ discard block |
||
3877 | 3877 | * Internally does some caching. |
3878 | 3878 | * @return boolean |
3879 | 3879 | */ |
3880 | - public function has_primary_key_field(){ |
|
3881 | - if($this->_has_primary_key_field === null){ |
|
3882 | - try{ |
|
3880 | + public function has_primary_key_field() { |
|
3881 | + if ($this->_has_primary_key_field === null) { |
|
3882 | + try { |
|
3883 | 3883 | $this->get_primary_key_field(); |
3884 | 3884 | $this->_has_primary_key_field = true; |
3885 | - }catch(EE_Error $e){ |
|
3885 | + } catch (EE_Error $e) { |
|
3886 | 3886 | $this->_has_primary_key_field = false; |
3887 | 3887 | } |
3888 | 3888 | } |
@@ -3896,9 +3896,9 @@ discard block |
||
3896 | 3896 | * @param string $field_class_name class name of field that you want to find. Eg, EE_Datetime_Field, EE_Foreign_Key_Field, etc |
3897 | 3897 | * @return EE_Model_Field_Base or null if none is found |
3898 | 3898 | */ |
3899 | - public function get_a_field_of_type($field_class_name){ |
|
3900 | - foreach($this->field_settings() as $field){ |
|
3901 | - if( $field instanceof $field_class_name ){ |
|
3899 | + public function get_a_field_of_type($field_class_name) { |
|
3900 | + foreach ($this->field_settings() as $field) { |
|
3901 | + if ($field instanceof $field_class_name) { |
|
3902 | 3902 | return $field; |
3903 | 3903 | } |
3904 | 3904 | } |
@@ -3912,21 +3912,21 @@ discard block |
||
3912 | 3912 | * @return EE_Foreign_Key_Field_Base |
3913 | 3913 | * @throws EE_Error |
3914 | 3914 | */ |
3915 | - public function get_foreign_key_to($model_name){ |
|
3916 | - if( ! isset( $this->_cache_foreign_key_to_fields[ $model_name ] ) ){ |
|
3917 | - foreach($this->field_settings() as $field){ |
|
3918 | - if( |
|
3915 | + public function get_foreign_key_to($model_name) { |
|
3916 | + if ( ! isset($this->_cache_foreign_key_to_fields[$model_name])) { |
|
3917 | + foreach ($this->field_settings() as $field) { |
|
3918 | + if ( |
|
3919 | 3919 | $field instanceof EE_Foreign_Key_Field_Base |
3920 | - && in_array($model_name,$field->get_model_names_pointed_to() ) |
|
3920 | + && in_array($model_name, $field->get_model_names_pointed_to()) |
|
3921 | 3921 | ) { |
3922 | - $this->_cache_foreign_key_to_fields[ $model_name ] = $field; |
|
3922 | + $this->_cache_foreign_key_to_fields[$model_name] = $field; |
|
3923 | 3923 | } |
3924 | 3924 | } |
3925 | - if( ! isset( $this->_cache_foreign_key_to_fields[ $model_name ] ) ){ |
|
3926 | - 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 | + if ( ! isset($this->_cache_foreign_key_to_fields[$model_name])) { |
|
3926 | + 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))); |
|
3927 | 3927 | } |
3928 | 3928 | } |
3929 | - return $this->_cache_foreign_key_to_fields[ $model_name ]; |
|
3929 | + return $this->_cache_foreign_key_to_fields[$model_name]; |
|
3930 | 3930 | } |
3931 | 3931 | |
3932 | 3932 | |
@@ -3937,7 +3937,7 @@ discard block |
||
3937 | 3937 | * a table alias with a model chain prefix, like 'Venue__Event_Venue___Event_Meta'. Either one works |
3938 | 3938 | * @return EE_Table_Base |
3939 | 3939 | */ |
3940 | - public function get_table_for_alias($table_alias){ |
|
3940 | + public function get_table_for_alias($table_alias) { |
|
3941 | 3941 | $table_alias_sans_model_relation_chain_prefix = EE_Model_Parser::remove_table_alias_model_relation_chain_prefix($table_alias); |
3942 | 3942 | return $this->_tables[$table_alias_sans_model_relation_chain_prefix]->get_table_name(); |
3943 | 3943 | } |
@@ -3950,25 +3950,25 @@ discard block |
||
3950 | 3950 | * @param bool $include_db_only_fields flag indicating whether or not to include the db-only fields |
3951 | 3951 | * @return EE_Model_Field_Base[] where the keys are the field's name |
3952 | 3952 | */ |
3953 | - public function field_settings($include_db_only_fields = false){ |
|
3954 | - if( $include_db_only_fields ){ |
|
3955 | - if( $this->_cached_fields === NULL ){ |
|
3953 | + public function field_settings($include_db_only_fields = false) { |
|
3954 | + if ($include_db_only_fields) { |
|
3955 | + if ($this->_cached_fields === NULL) { |
|
3956 | 3956 | $this->_cached_fields = array(); |
3957 | - foreach($this->_fields as $fields_corresponding_to_table){ |
|
3958 | - foreach($fields_corresponding_to_table as $field_name => $field_obj){ |
|
3959 | - $this->_cached_fields[$field_name]=$field_obj; |
|
3957 | + foreach ($this->_fields as $fields_corresponding_to_table) { |
|
3958 | + foreach ($fields_corresponding_to_table as $field_name => $field_obj) { |
|
3959 | + $this->_cached_fields[$field_name] = $field_obj; |
|
3960 | 3960 | } |
3961 | 3961 | } |
3962 | 3962 | } |
3963 | 3963 | return $this->_cached_fields; |
3964 | - }else{ |
|
3965 | - if( $this->_cached_fields_non_db_only === NULL ){ |
|
3964 | + } else { |
|
3965 | + if ($this->_cached_fields_non_db_only === NULL) { |
|
3966 | 3966 | $this->_cached_fields_non_db_only = array(); |
3967 | - foreach($this->_fields as $fields_corresponding_to_table){ |
|
3968 | - foreach($fields_corresponding_to_table as $field_name => $field_obj){ |
|
3967 | + foreach ($this->_fields as $fields_corresponding_to_table) { |
|
3968 | + foreach ($fields_corresponding_to_table as $field_name => $field_obj) { |
|
3969 | 3969 | /** @var $field_obj EE_Model_Field_Base */ |
3970 | - if( ! $field_obj->is_db_only_field() ){ |
|
3971 | - $this->_cached_fields_non_db_only[$field_name]=$field_obj; |
|
3970 | + if ( ! $field_obj->is_db_only_field()) { |
|
3971 | + $this->_cached_fields_non_db_only[$field_name] = $field_obj; |
|
3972 | 3972 | } |
3973 | 3973 | } |
3974 | 3974 | } |
@@ -3987,60 +3987,60 @@ discard block |
||
3987 | 3987 | * @return \EE_Base_Class[] array keys are primary keys (if there is a primary key on the model. if not, numerically indexed) |
3988 | 3988 | * @throws \EE_Error |
3989 | 3989 | */ |
3990 | - protected function _create_objects( $rows = array() ) { |
|
3991 | - $array_of_objects=array(); |
|
3992 | - if(empty($rows)){ |
|
3990 | + protected function _create_objects($rows = array()) { |
|
3991 | + $array_of_objects = array(); |
|
3992 | + if (empty($rows)) { |
|
3993 | 3993 | return array(); |
3994 | 3994 | } |
3995 | 3995 | $count_if_model_has_no_primary_key = 0; |
3996 | 3996 | $has_primary_key = $this->has_primary_key_field(); |
3997 | 3997 | $primary_key_field = $has_primary_key ? $this->get_primary_key_field() : null; |
3998 | - foreach ( (array)$rows as $row ) { |
|
3999 | - if(empty($row)){ |
|
3998 | + foreach ((array) $rows as $row) { |
|
3999 | + if (empty($row)) { |
|
4000 | 4000 | //wp did its weird thing where it returns an array like array(0=>null), which is totally not helpful... |
4001 | 4001 | return array(); |
4002 | 4002 | } |
4003 | 4003 | //check if we've already set this object in the results array, |
4004 | 4004 | //in which case there's no need to process it further (again) |
4005 | - if( $has_primary_key ) { |
|
4005 | + if ($has_primary_key) { |
|
4006 | 4006 | $table_pk_value = $this->_get_column_value_with_table_alias_or_not( |
4007 | 4007 | $row, |
4008 | 4008 | $primary_key_field->get_qualified_column(), |
4009 | 4009 | $primary_key_field->get_table_column() |
4010 | 4010 | ); |
4011 | - if( $table_pk_value && isset( $array_of_objects[ $table_pk_value ] ) ) { |
|
4011 | + if ($table_pk_value && isset($array_of_objects[$table_pk_value])) { |
|
4012 | 4012 | continue; |
4013 | 4013 | } |
4014 | 4014 | } |
4015 | 4015 | $classInstance = $this->instantiate_class_from_array_or_object($row); |
4016 | - if( ! $classInstance ) { |
|
4016 | + if ( ! $classInstance) { |
|
4017 | 4017 | throw new EE_Error( |
4018 | 4018 | sprintf( |
4019 | - __( 'Could not create instance of class %s from row %s', 'event_espresso' ), |
|
4019 | + __('Could not create instance of class %s from row %s', 'event_espresso'), |
|
4020 | 4020 | $this->get_this_model_name(), |
4021 | - http_build_query( $row ) |
|
4021 | + http_build_query($row) |
|
4022 | 4022 | ) |
4023 | 4023 | ); |
4024 | 4024 | } |
4025 | 4025 | //set the timezone on the instantiated objects |
4026 | - $classInstance->set_timezone( $this->_timezone ); |
|
4026 | + $classInstance->set_timezone($this->_timezone); |
|
4027 | 4027 | //make sure if there is any timezone setting present that we set the timezone for the object |
4028 | 4028 | $key = $has_primary_key ? $classInstance->ID() : $count_if_model_has_no_primary_key++; |
4029 | - $array_of_objects[ $key ] = $classInstance; |
|
4029 | + $array_of_objects[$key] = $classInstance; |
|
4030 | 4030 | //also, for all the relations of type BelongsTo, see if we can cache |
4031 | 4031 | //those related models |
4032 | 4032 | //(we could do this for other relations too, but if there are conditions |
4033 | 4033 | //that filtered out some fo the results, then we'd be caching an incomplete set |
4034 | 4034 | //so it requires a little more thought than just caching them immediately...) |
4035 | - foreach($this->_model_relations as $modelName => $relation_obj){ |
|
4036 | - if( $relation_obj instanceof EE_Belongs_To_Relation){ |
|
4035 | + foreach ($this->_model_relations as $modelName => $relation_obj) { |
|
4036 | + if ($relation_obj instanceof EE_Belongs_To_Relation) { |
|
4037 | 4037 | //check if this model's INFO is present. If so, cache it on the model |
4038 | 4038 | $other_model = $relation_obj->get_other_model(); |
4039 | 4039 | $other_model_obj_maybe = $other_model->instantiate_class_from_array_or_object($row); |
4040 | 4040 | //if we managed to make a model object from the results, cache it on the main model object |
4041 | - if( $other_model_obj_maybe ){ |
|
4041 | + if ($other_model_obj_maybe) { |
|
4042 | 4042 | //set timezone on these other model objects if they are present |
4043 | - $other_model_obj_maybe->set_timezone( $this->_timezone ); |
|
4043 | + $other_model_obj_maybe->set_timezone($this->_timezone); |
|
4044 | 4044 | $classInstance->cache($modelName, $other_model_obj_maybe); |
4045 | 4045 | } |
4046 | 4046 | } |
@@ -4061,12 +4061,12 @@ discard block |
||
4061 | 4061 | |
4062 | 4062 | $this_model_fields_and_values = array(); |
4063 | 4063 | //setup the row using default values; |
4064 | - foreach ( $this->field_settings() as $field_name => $field_obj ) { |
|
4064 | + foreach ($this->field_settings() as $field_name => $field_obj) { |
|
4065 | 4065 | $this_model_fields_and_values[$field_name] = $field_obj->get_default_value(); |
4066 | 4066 | } |
4067 | 4067 | |
4068 | 4068 | $className = $this->_get_class_name(); |
4069 | - $classInstance = EE_Registry::instance()->load_class( $className, array( $this_model_fields_and_values ), FALSE, FALSE ); |
|
4069 | + $classInstance = EE_Registry::instance()->load_class($className, array($this_model_fields_and_values), FALSE, FALSE); |
|
4070 | 4070 | |
4071 | 4071 | return $classInstance; |
4072 | 4072 | } |
@@ -4079,45 +4079,45 @@ discard block |
||
4079 | 4079 | * @return EE_Base_Class |
4080 | 4080 | * @throws \EE_Error |
4081 | 4081 | */ |
4082 | - public function instantiate_class_from_array_or_object($cols_n_values){ |
|
4083 | - if( ! is_array( $cols_n_values ) && is_object( $cols_n_values )) { |
|
4084 | - $cols_n_values = get_object_vars( $cols_n_values ); |
|
4082 | + public function instantiate_class_from_array_or_object($cols_n_values) { |
|
4083 | + if ( ! is_array($cols_n_values) && is_object($cols_n_values)) { |
|
4084 | + $cols_n_values = get_object_vars($cols_n_values); |
|
4085 | 4085 | } |
4086 | 4086 | $primary_key = NULL; |
4087 | 4087 | //make sure the array only has keys that are fields/columns on this model |
4088 | - $this_model_fields_n_values = $this->_deduce_fields_n_values_from_cols_n_values( $cols_n_values ); |
|
4089 | - if( $this->has_primary_key_field() && isset( $this_model_fields_n_values[ $this->primary_key_name() ] ) ){ |
|
4090 | - $primary_key = $this_model_fields_n_values[ $this->primary_key_name() ]; |
|
4088 | + $this_model_fields_n_values = $this->_deduce_fields_n_values_from_cols_n_values($cols_n_values); |
|
4089 | + if ($this->has_primary_key_field() && isset($this_model_fields_n_values[$this->primary_key_name()])) { |
|
4090 | + $primary_key = $this_model_fields_n_values[$this->primary_key_name()]; |
|
4091 | 4091 | } |
4092 | - $className=$this->_get_class_name(); |
|
4092 | + $className = $this->_get_class_name(); |
|
4093 | 4093 | |
4094 | 4094 | //check we actually found results that we can use to build our model object |
4095 | 4095 | //if not, return null |
4096 | - if( $this->has_primary_key_field()){ |
|
4097 | - if(empty( $this_model_fields_n_values[$this->primary_key_name()] )){ |
|
4096 | + if ($this->has_primary_key_field()) { |
|
4097 | + if (empty($this_model_fields_n_values[$this->primary_key_name()])) { |
|
4098 | 4098 | return NULL; |
4099 | 4099 | } |
4100 | - }else if($this->unique_indexes()){ |
|
4100 | + } else if ($this->unique_indexes()) { |
|
4101 | 4101 | $first_column = reset($this_model_fields_n_values); |
4102 | - if(empty($first_column)){ |
|
4102 | + if (empty($first_column)) { |
|
4103 | 4103 | return NULL; |
4104 | 4104 | } |
4105 | 4105 | } |
4106 | 4106 | |
4107 | 4107 | // if there is no primary key or the object doesn't already exist in the entity map, then create a new instance |
4108 | - if ( $primary_key){ |
|
4109 | - $classInstance = $this->get_from_entity_map( $primary_key ); |
|
4110 | - if( ! $classInstance) { |
|
4111 | - $classInstance = EE_Registry::instance()->load_class( $className, array( $this_model_fields_n_values, $this->_timezone ), TRUE, FALSE ); |
|
4108 | + if ($primary_key) { |
|
4109 | + $classInstance = $this->get_from_entity_map($primary_key); |
|
4110 | + if ( ! $classInstance) { |
|
4111 | + $classInstance = EE_Registry::instance()->load_class($className, array($this_model_fields_n_values, $this->_timezone), TRUE, FALSE); |
|
4112 | 4112 | // add this new object to the entity map |
4113 | - $classInstance = $this->add_to_entity_map( $classInstance ); |
|
4113 | + $classInstance = $this->add_to_entity_map($classInstance); |
|
4114 | 4114 | } |
4115 | - }else{ |
|
4116 | - $classInstance = EE_Registry::instance()->load_class( $className, array( $this_model_fields_n_values, $this->_timezone ), TRUE, FALSE ); |
|
4115 | + } else { |
|
4116 | + $classInstance = EE_Registry::instance()->load_class($className, array($this_model_fields_n_values, $this->_timezone), TRUE, FALSE); |
|
4117 | 4117 | } |
4118 | 4118 | |
4119 | 4119 | //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. |
4120 | - $this->set_timezone( $classInstance->get_timezone() ); |
|
4120 | + $this->set_timezone($classInstance->get_timezone()); |
|
4121 | 4121 | return $classInstance; |
4122 | 4122 | } |
4123 | 4123 | /** |
@@ -4125,8 +4125,8 @@ discard block |
||
4125 | 4125 | * @param int|string $id the ID of the model object |
4126 | 4126 | * @return EE_Base_Class |
4127 | 4127 | */ |
4128 | - public function get_from_entity_map( $id ){ |
|
4129 | - return isset( $this->_entity_map[ $id ] ) ? $this->_entity_map[ $id ] : NULL; |
|
4128 | + public function get_from_entity_map($id) { |
|
4129 | + return isset($this->_entity_map[$id]) ? $this->_entity_map[$id] : NULL; |
|
4130 | 4130 | } |
4131 | 4131 | |
4132 | 4132 | |
@@ -4145,21 +4145,21 @@ discard block |
||
4145 | 4145 | * @throws EE_Error |
4146 | 4146 | * @return \EE_Base_Class |
4147 | 4147 | */ |
4148 | - public function add_to_entity_map( EE_Base_Class $object) { |
|
4148 | + public function add_to_entity_map(EE_Base_Class $object) { |
|
4149 | 4149 | $className = $this->_get_class_name(); |
4150 | - if( ! $object instanceof $className ){ |
|
4151 | - 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 | + if ( ! $object instanceof $className) { |
|
4151 | + 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)); |
|
4152 | 4152 | } |
4153 | 4153 | /** @var $object EE_Base_Class */ |
4154 | - if ( ! $object->ID() ){ |
|
4155 | - 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 | + if ( ! $object->ID()) { |
|
4155 | + throw new EE_Error(sprintf(__("You tried storing a model object with NO ID in the %s entity mapper.", "event_espresso"), get_class($this))); |
|
4156 | 4156 | } |
4157 | 4157 | // double check it's not already there |
4158 | - $classInstance = $this->get_from_entity_map( $object->ID() ); |
|
4159 | - if ( $classInstance ) { |
|
4158 | + $classInstance = $this->get_from_entity_map($object->ID()); |
|
4159 | + if ($classInstance) { |
|
4160 | 4160 | return $classInstance; |
4161 | 4161 | } else { |
4162 | - $this->_entity_map[ $object->ID() ] = $object; |
|
4162 | + $this->_entity_map[$object->ID()] = $object; |
|
4163 | 4163 | return $object; |
4164 | 4164 | } |
4165 | 4165 | } |
@@ -4172,8 +4172,8 @@ discard block |
||
4172 | 4172 | * @param array $cols_n_values |
4173 | 4173 | * @return array |
4174 | 4174 | */ |
4175 | - public function deduce_fields_n_values_from_cols_n_values( $cols_n_values ) { |
|
4176 | - return $this->_deduce_fields_n_values_from_cols_n_values( $cols_n_values ); |
|
4175 | + public function deduce_fields_n_values_from_cols_n_values($cols_n_values) { |
|
4176 | + return $this->_deduce_fields_n_values_from_cols_n_values($cols_n_values); |
|
4177 | 4177 | } |
4178 | 4178 | |
4179 | 4179 | |
@@ -4186,23 +4186,23 @@ discard block |
||
4186 | 4186 | * @param string $cols_n_values |
4187 | 4187 | * @return array |
4188 | 4188 | */ |
4189 | - protected function _deduce_fields_n_values_from_cols_n_values( $cols_n_values ){ |
|
4189 | + protected function _deduce_fields_n_values_from_cols_n_values($cols_n_values) { |
|
4190 | 4190 | $this_model_fields_n_values = array(); |
4191 | - foreach( $this->get_tables() as $table_alias => $table_obj ) { |
|
4192 | - $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 | + foreach ($this->get_tables() as $table_alias => $table_obj) { |
|
4192 | + $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()); |
|
4193 | 4193 | //there is a primary key on this table and its not set. Use defaults for all its columns |
4194 | - if( $table_pk_value === null && $table_obj->get_pk_column() ){ |
|
4195 | - foreach( $this->_get_fields_for_table( $table_alias ) as $field_name => $field_obj ) { |
|
4196 | - if( ! $field_obj->is_db_only_field() ){ |
|
4194 | + if ($table_pk_value === null && $table_obj->get_pk_column()) { |
|
4195 | + foreach ($this->_get_fields_for_table($table_alias) as $field_name => $field_obj) { |
|
4196 | + if ( ! $field_obj->is_db_only_field()) { |
|
4197 | 4197 | //prepare field as if its coming from db |
4198 | - $prepared_value = $field_obj->prepare_for_set( $field_obj->get_default_value() ); |
|
4199 | - $this_model_fields_n_values[$field_name] = $field_obj->prepare_for_use_in_db( $prepared_value ); |
|
4198 | + $prepared_value = $field_obj->prepare_for_set($field_obj->get_default_value()); |
|
4199 | + $this_model_fields_n_values[$field_name] = $field_obj->prepare_for_use_in_db($prepared_value); |
|
4200 | 4200 | } |
4201 | 4201 | } |
4202 | - }else{ |
|
4202 | + } else { |
|
4203 | 4203 | //the table's rows existed. Use their values |
4204 | - foreach( $this->_get_fields_for_table( $table_alias ) as $field_name => $field_obj ) { |
|
4205 | - if( ! $field_obj->is_db_only_field() ){ |
|
4204 | + foreach ($this->_get_fields_for_table($table_alias) as $field_name => $field_obj) { |
|
4205 | + if ( ! $field_obj->is_db_only_field()) { |
|
4206 | 4206 | $this_model_fields_n_values[$field_name] = $this->_get_column_value_with_table_alias_or_not( |
4207 | 4207 | $cols_n_values, $field_obj->get_qualified_column(), |
4208 | 4208 | $field_obj->get_table_column() |
@@ -4222,15 +4222,15 @@ discard block |
||
4222 | 4222 | * @param $regular_column |
4223 | 4223 | * @return null |
4224 | 4224 | */ |
4225 | - protected function _get_column_value_with_table_alias_or_not( $cols_n_values, $qualified_column, $regular_column ){ |
|
4225 | + protected function _get_column_value_with_table_alias_or_not($cols_n_values, $qualified_column, $regular_column) { |
|
4226 | 4226 | $value = null; |
4227 | 4227 | //ask the field what it think it's table_name.column_name should be, and call it the "qualified column" |
4228 | 4228 | //does the field on the model relate to this column retrieved from the db? |
4229 | 4229 | //or is it a db-only field? (not relating to the model) |
4230 | - if( isset( $cols_n_values[ $qualified_column ] ) ){ |
|
4231 | - $value = $cols_n_values[ $qualified_column ]; |
|
4232 | - }elseif( isset( $cols_n_values[ $regular_column ] ) ){ |
|
4233 | - $value = $cols_n_values[ $regular_column ]; |
|
4230 | + if (isset($cols_n_values[$qualified_column])) { |
|
4231 | + $value = $cols_n_values[$qualified_column]; |
|
4232 | + }elseif (isset($cols_n_values[$regular_column])) { |
|
4233 | + $value = $cols_n_values[$regular_column]; |
|
4234 | 4234 | } |
4235 | 4235 | return $value; |
4236 | 4236 | } |
@@ -4246,25 +4246,25 @@ discard block |
||
4246 | 4246 | * @return EE_Base_Class |
4247 | 4247 | * @throws \EE_Error |
4248 | 4248 | */ |
4249 | - public function refresh_entity_map_from_db( $id ){ |
|
4250 | - $obj_in_map = $this->get_from_entity_map( $id ); |
|
4251 | - if( $obj_in_map ){ |
|
4249 | + public function refresh_entity_map_from_db($id) { |
|
4250 | + $obj_in_map = $this->get_from_entity_map($id); |
|
4251 | + if ($obj_in_map) { |
|
4252 | 4252 | $wpdb_results = $this->_get_all_wpdb_results( |
4253 | - array( array( $this->get_primary_key_field()->get_name() => $id ), 'limit' => 1 ) |
|
4253 | + array(array($this->get_primary_key_field()->get_name() => $id), 'limit' => 1) |
|
4254 | 4254 | ); |
4255 | - if( $wpdb_results && is_array( $wpdb_results ) ){ |
|
4256 | - $one_row = reset( $wpdb_results ); |
|
4257 | - foreach( $this->_deduce_fields_n_values_from_cols_n_values($one_row ) as $field_name => $db_value ) { |
|
4258 | - $obj_in_map->set_from_db( $field_name, $db_value ); |
|
4255 | + if ($wpdb_results && is_array($wpdb_results)) { |
|
4256 | + $one_row = reset($wpdb_results); |
|
4257 | + foreach ($this->_deduce_fields_n_values_from_cols_n_values($one_row) as $field_name => $db_value) { |
|
4258 | + $obj_in_map->set_from_db($field_name, $db_value); |
|
4259 | 4259 | } |
4260 | 4260 | //clear the cache of related model objects |
4261 | - foreach ( $this->relation_settings() as $relation_name => $relation_obj ){ |
|
4262 | - $obj_in_map->clear_cache($relation_name, NULL, TRUE ); |
|
4261 | + foreach ($this->relation_settings() as $relation_name => $relation_obj) { |
|
4262 | + $obj_in_map->clear_cache($relation_name, NULL, TRUE); |
|
4263 | 4263 | } |
4264 | 4264 | } |
4265 | 4265 | return $obj_in_map; |
4266 | - }else{ |
|
4267 | - return $this->get_one_by_ID( $id ); |
|
4266 | + } else { |
|
4267 | + return $this->get_one_by_ID($id); |
|
4268 | 4268 | } |
4269 | 4269 | } |
4270 | 4270 | |
@@ -4282,24 +4282,24 @@ discard block |
||
4282 | 4282 | * @return \EE_Base_Class |
4283 | 4283 | * @throws \EE_Error |
4284 | 4284 | */ |
4285 | - public function refresh_entity_map_with( $id, $replacing_model_obj ) { |
|
4286 | - $obj_in_map = $this->get_from_entity_map( $id ); |
|
4287 | - if( $obj_in_map ){ |
|
4288 | - if( $replacing_model_obj instanceof EE_Base_Class ){ |
|
4289 | - foreach( $replacing_model_obj->model_field_array() as $field_name => $value ) { |
|
4290 | - $obj_in_map->set( $field_name, $value ); |
|
4285 | + public function refresh_entity_map_with($id, $replacing_model_obj) { |
|
4286 | + $obj_in_map = $this->get_from_entity_map($id); |
|
4287 | + if ($obj_in_map) { |
|
4288 | + if ($replacing_model_obj instanceof EE_Base_Class) { |
|
4289 | + foreach ($replacing_model_obj->model_field_array() as $field_name => $value) { |
|
4290 | + $obj_in_map->set($field_name, $value); |
|
4291 | 4291 | } |
4292 | 4292 | //make the model object in the entity map's cache match the $replacing_model_obj |
4293 | - foreach ( $this->relation_settings() as $relation_name => $relation_obj ){ |
|
4294 | - $obj_in_map->clear_cache($relation_name, NULL, TRUE ); |
|
4295 | - foreach( $replacing_model_obj->get_all_from_cache( $relation_name ) as $cache_id => $cached_obj ) { |
|
4296 | - $obj_in_map->cache( $relation_name, $cached_obj, $cache_id ); |
|
4293 | + foreach ($this->relation_settings() as $relation_name => $relation_obj) { |
|
4294 | + $obj_in_map->clear_cache($relation_name, NULL, TRUE); |
|
4295 | + foreach ($replacing_model_obj->get_all_from_cache($relation_name) as $cache_id => $cached_obj) { |
|
4296 | + $obj_in_map->cache($relation_name, $cached_obj, $cache_id); |
|
4297 | 4297 | } |
4298 | 4298 | } |
4299 | 4299 | } |
4300 | 4300 | return $obj_in_map; |
4301 | - }else{ |
|
4302 | - $this->add_to_entity_map( $replacing_model_obj ); |
|
4301 | + } else { |
|
4302 | + $this->add_to_entity_map($replacing_model_obj); |
|
4303 | 4303 | return $replacing_model_obj; |
4304 | 4304 | } |
4305 | 4305 | } |
@@ -4312,7 +4312,7 @@ discard block |
||
4312 | 4312 | * require_once($this->_getClassName().".class.php"); |
4313 | 4313 | * @return string |
4314 | 4314 | */ |
4315 | - private function _get_class_name(){ |
|
4315 | + private function _get_class_name() { |
|
4316 | 4316 | return "EE_".$this->get_this_model_name(); |
4317 | 4317 | } |
4318 | 4318 | |
@@ -4325,8 +4325,8 @@ discard block |
||
4325 | 4325 | * @param int $quantity |
4326 | 4326 | * @return string |
4327 | 4327 | */ |
4328 | - public function item_name($quantity = 1){ |
|
4329 | - return (int)$quantity === 1 ? $this->singular_item : $this->plural_item; |
|
4328 | + public function item_name($quantity = 1) { |
|
4329 | + return (int) $quantity === 1 ? $this->singular_item : $this->plural_item; |
|
4330 | 4330 | } |
4331 | 4331 | |
4332 | 4332 | |
@@ -4353,13 +4353,13 @@ discard block |
||
4353 | 4353 | * @throws EE_Error |
4354 | 4354 | * @return mixed whatever the plugin which calls add_filter decides |
4355 | 4355 | */ |
4356 | - public function __call($methodName,$args){ |
|
4357 | - $className=get_class($this); |
|
4358 | - $tagName="FHEE__{$className}__{$methodName}"; |
|
4359 | - if(!has_filter($tagName)){ |
|
4356 | + public function __call($methodName, $args) { |
|
4357 | + $className = get_class($this); |
|
4358 | + $tagName = "FHEE__{$className}__{$methodName}"; |
|
4359 | + if ( ! has_filter($tagName)) { |
|
4360 | 4360 | throw new EE_Error( |
4361 | 4361 | sprintf( |
4362 | - __( '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' ), |
|
4362 | + __('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'), |
|
4363 | 4363 | $methodName, |
4364 | 4364 | $className, |
4365 | 4365 | $tagName, |
@@ -4368,7 +4368,7 @@ discard block |
||
4368 | 4368 | ); |
4369 | 4369 | } |
4370 | 4370 | |
4371 | - return apply_filters($tagName,null,$this,$args); |
|
4371 | + return apply_filters($tagName, null, $this, $args); |
|
4372 | 4372 | } |
4373 | 4373 | |
4374 | 4374 | |
@@ -4386,28 +4386,28 @@ discard block |
||
4386 | 4386 | * @throws EE_Error |
4387 | 4387 | * @return EE_Base_Class |
4388 | 4388 | */ |
4389 | - public function ensure_is_obj( $base_class_obj_or_id, $ensure_is_in_db = FALSE ){ |
|
4389 | + public function ensure_is_obj($base_class_obj_or_id, $ensure_is_in_db = FALSE) { |
|
4390 | 4390 | $className = $this->_get_class_name(); |
4391 | - if ( $base_class_obj_or_id instanceof $className ) { |
|
4391 | + if ($base_class_obj_or_id instanceof $className) { |
|
4392 | 4392 | $model_object = $base_class_obj_or_id; |
4393 | 4393 | } else { |
4394 | 4394 | $primary_key_field = $this->get_primary_key_field(); |
4395 | 4395 | if ( |
4396 | 4396 | $primary_key_field instanceof EE_Primary_Key_Int_Field |
4397 | 4397 | && ( |
4398 | - is_int( $base_class_obj_or_id ) |
|
4399 | - || is_string( $base_class_obj_or_id ) |
|
4398 | + is_int($base_class_obj_or_id) |
|
4399 | + || is_string($base_class_obj_or_id) |
|
4400 | 4400 | ) |
4401 | 4401 | ) { |
4402 | 4402 | // assume it's an ID. |
4403 | 4403 | // either a proper integer or a string representing an integer (eg "101" instead of 101) |
4404 | - $model_object = $this->get_one_by_ID( $base_class_obj_or_id ); |
|
4404 | + $model_object = $this->get_one_by_ID($base_class_obj_or_id); |
|
4405 | 4405 | } else if ( |
4406 | 4406 | $primary_key_field instanceof EE_Primary_Key_String_Field |
4407 | - && is_string( $base_class_obj_or_id ) |
|
4407 | + && is_string($base_class_obj_or_id) |
|
4408 | 4408 | ) { |
4409 | 4409 | // assume its a string representation of the object |
4410 | - $model_object = $this->get_one_by_ID( $base_class_obj_or_id ); |
|
4410 | + $model_object = $this->get_one_by_ID($base_class_obj_or_id); |
|
4411 | 4411 | } else { |
4412 | 4412 | throw new EE_Error( |
4413 | 4413 | sprintf( |
@@ -4417,12 +4417,12 @@ discard block |
||
4417 | 4417 | ), |
4418 | 4418 | $base_class_obj_or_id, |
4419 | 4419 | $this->_get_class_name(), |
4420 | - print_r( $base_class_obj_or_id, true ) |
|
4420 | + print_r($base_class_obj_or_id, true) |
|
4421 | 4421 | ) |
4422 | 4422 | ); |
4423 | 4423 | } |
4424 | 4424 | } |
4425 | - if ( $ensure_is_in_db && $model_object->ID() !== null ) { |
|
4425 | + if ($ensure_is_in_db && $model_object->ID() !== null) { |
|
4426 | 4426 | $model_object->save(); |
4427 | 4427 | } |
4428 | 4428 | return $model_object; |
@@ -4438,19 +4438,19 @@ discard block |
||
4438 | 4438 | * @return int|string depending on the type of this model object's ID |
4439 | 4439 | * @throws EE_Error |
4440 | 4440 | */ |
4441 | - public function ensure_is_ID($base_class_obj_or_id){ |
|
4441 | + public function ensure_is_ID($base_class_obj_or_id) { |
|
4442 | 4442 | $className = $this->_get_class_name(); |
4443 | - if( $base_class_obj_or_id instanceof $className ){ |
|
4443 | + if ($base_class_obj_or_id instanceof $className) { |
|
4444 | 4444 | /** @var $base_class_obj_or_id EE_Base_Class */ |
4445 | 4445 | $id = $base_class_obj_or_id->ID(); |
4446 | - }elseif(is_int($base_class_obj_or_id)){ |
|
4446 | + }elseif (is_int($base_class_obj_or_id)) { |
|
4447 | 4447 | //assume it's an ID |
4448 | 4448 | $id = $base_class_obj_or_id; |
4449 | - }elseif(is_string($base_class_obj_or_id)){ |
|
4449 | + }elseif (is_string($base_class_obj_or_id)) { |
|
4450 | 4450 | //assume its a string representation of the object |
4451 | 4451 | $id = $base_class_obj_or_id; |
4452 | - }else{ |
|
4453 | - 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))); |
|
4452 | + } else { |
|
4453 | + 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))); |
|
4454 | 4454 | } |
4455 | 4455 | return $id; |
4456 | 4456 | } |
@@ -4473,14 +4473,14 @@ discard block |
||
4473 | 4473 | * @param int $values_already_prepared like one of the constants on EEM_Base |
4474 | 4474 | * @return void |
4475 | 4475 | */ |
4476 | - public function assume_values_already_prepared_by_model_object($values_already_prepared = self::not_prepared_by_model_object){ |
|
4476 | + public function assume_values_already_prepared_by_model_object($values_already_prepared = self::not_prepared_by_model_object) { |
|
4477 | 4477 | $this->_values_already_prepared_by_model_object = $values_already_prepared; |
4478 | 4478 | } |
4479 | 4479 | /** |
4480 | 4480 | * Read comments for assume_values_already_prepared_by_model_object() |
4481 | 4481 | * @return int |
4482 | 4482 | */ |
4483 | - public function get_assumption_concerning_values_already_prepared_by_model_object(){ |
|
4483 | + public function get_assumption_concerning_values_already_prepared_by_model_object() { |
|
4484 | 4484 | return $this->_values_already_prepared_by_model_object; |
4485 | 4485 | } |
4486 | 4486 | |
@@ -4488,17 +4488,17 @@ discard block |
||
4488 | 4488 | * Gets all the indexes on this model |
4489 | 4489 | * @return EE_Index[] |
4490 | 4490 | */ |
4491 | - public function indexes(){ |
|
4491 | + public function indexes() { |
|
4492 | 4492 | return $this->_indexes; |
4493 | 4493 | } |
4494 | 4494 | /** |
4495 | 4495 | * Gets all the Unique Indexes on this model |
4496 | 4496 | * @return EE_Unique_Index[] |
4497 | 4497 | */ |
4498 | - public function unique_indexes(){ |
|
4498 | + public function unique_indexes() { |
|
4499 | 4499 | $unique_indexes = array(); |
4500 | - foreach($this->_indexes as $name => $index){ |
|
4501 | - if($index instanceof EE_Unique_Index){ |
|
4500 | + foreach ($this->_indexes as $name => $index) { |
|
4501 | + if ($index instanceof EE_Unique_Index) { |
|
4502 | 4502 | $unique_indexes [$name] = $index; |
4503 | 4503 | } |
4504 | 4504 | } |
@@ -4516,9 +4516,9 @@ discard block |
||
4516 | 4516 | * @return EE_Model_Field_Base[] |
4517 | 4517 | * @throws \EE_Error |
4518 | 4518 | */ |
4519 | - public function get_combined_primary_key_fields(){ |
|
4520 | - foreach($this->indexes() as $index){ |
|
4521 | - if($index instanceof EE_Primary_Key_Index){ |
|
4519 | + public function get_combined_primary_key_fields() { |
|
4520 | + foreach ($this->indexes() as $index) { |
|
4521 | + if ($index instanceof EE_Primary_Key_Index) { |
|
4522 | 4522 | return $index->fields(); |
4523 | 4523 | } |
4524 | 4524 | } |
@@ -4535,7 +4535,7 @@ discard block |
||
4535 | 4535 | * @return string |
4536 | 4536 | * @throws \EE_Error |
4537 | 4537 | */ |
4538 | - public function get_index_primary_key_string($cols_n_values){ |
|
4538 | + public function get_index_primary_key_string($cols_n_values) { |
|
4539 | 4539 | $cols_n_values_for_primary_key_index = array_intersect_key($cols_n_values, $this->get_combined_primary_key_fields()); |
4540 | 4540 | return http_build_query($cols_n_values_for_primary_key_index); |
4541 | 4541 | } |
@@ -4550,13 +4550,13 @@ discard block |
||
4550 | 4550 | * @return null|array |
4551 | 4551 | * @throws \EE_Error |
4552 | 4552 | */ |
4553 | - public function parse_index_primary_key_string( $index_primary_key_string) { |
|
4553 | + public function parse_index_primary_key_string($index_primary_key_string) { |
|
4554 | 4554 | $key_fields = $this->get_combined_primary_key_fields(); |
4555 | 4555 | //check all of them are in the $id |
4556 | 4556 | $key_vals_in_combined_pk = array(); |
4557 | - parse_str( $index_primary_key_string, $key_vals_in_combined_pk ); |
|
4558 | - foreach( $key_fields as $key_field_name => $field_obj ) { |
|
4559 | - if( ! isset( $key_vals_in_combined_pk[ $key_field_name ] ) ){ |
|
4557 | + parse_str($index_primary_key_string, $key_vals_in_combined_pk); |
|
4558 | + foreach ($key_fields as $key_field_name => $field_obj) { |
|
4559 | + if ( ! isset($key_vals_in_combined_pk[$key_field_name])) { |
|
4560 | 4560 | return NULL; |
4561 | 4561 | } |
4562 | 4562 | } |
@@ -4573,10 +4573,10 @@ discard block |
||
4573 | 4573 | * @return boolean |
4574 | 4574 | * @throws \EE_Error |
4575 | 4575 | */ |
4576 | - public function has_all_combined_primary_key_fields( $key_vals ) { |
|
4577 | - $keys_it_should_have = array_keys( $this->get_combined_primary_key_fields() ); |
|
4578 | - foreach( $keys_it_should_have as $key ){ |
|
4579 | - if( ! isset( $key_vals[ $key ] ) ){ |
|
4576 | + public function has_all_combined_primary_key_fields($key_vals) { |
|
4577 | + $keys_it_should_have = array_keys($this->get_combined_primary_key_fields()); |
|
4578 | + foreach ($keys_it_should_have as $key) { |
|
4579 | + if ( ! isset($key_vals[$key])) { |
|
4580 | 4580 | return false; |
4581 | 4581 | } |
4582 | 4582 | } |
@@ -4592,23 +4592,23 @@ discard block |
||
4592 | 4592 | * @throws EE_Error |
4593 | 4593 | * @return \EE_Base_Class[] Array keys are object IDs (if there is a primary key on the model. if not, numerically indexed) |
4594 | 4594 | */ |
4595 | - public function get_all_copies($model_object_or_attributes_array, $query_params = array()){ |
|
4595 | + public function get_all_copies($model_object_or_attributes_array, $query_params = array()) { |
|
4596 | 4596 | |
4597 | - if($model_object_or_attributes_array instanceof EE_Base_Class){ |
|
4597 | + if ($model_object_or_attributes_array instanceof EE_Base_Class) { |
|
4598 | 4598 | $attributes_array = $model_object_or_attributes_array->model_field_array(); |
4599 | - }elseif(is_array($model_object_or_attributes_array)){ |
|
4599 | + }elseif (is_array($model_object_or_attributes_array)) { |
|
4600 | 4600 | $attributes_array = $model_object_or_attributes_array; |
4601 | - }else{ |
|
4602 | - 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)); |
|
4601 | + } else { |
|
4602 | + 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)); |
|
4603 | 4603 | } |
4604 | 4604 | //even copies obviously won't have the same ID, so remove the primary key |
4605 | 4605 | //from the WHERE conditions for finding copies (if there is a primary key, of course) |
4606 | - if($this->has_primary_key_field() && isset($attributes_array[$this->primary_key_name()])){ |
|
4606 | + if ($this->has_primary_key_field() && isset($attributes_array[$this->primary_key_name()])) { |
|
4607 | 4607 | unset($attributes_array[$this->primary_key_name()]); |
4608 | 4608 | } |
4609 | - if(isset($query_params[0])){ |
|
4610 | - $query_params[0] = array_merge($attributes_array,$query_params); |
|
4611 | - }else{ |
|
4609 | + if (isset($query_params[0])) { |
|
4610 | + $query_params[0] = array_merge($attributes_array, $query_params); |
|
4611 | + } else { |
|
4612 | 4612 | $query_params[0] = $attributes_array; |
4613 | 4613 | } |
4614 | 4614 | return $this->get_all($query_params); |
@@ -4624,16 +4624,16 @@ discard block |
||
4624 | 4624 | * @return EE_Base_Class |
4625 | 4625 | * @throws \EE_Error |
4626 | 4626 | */ |
4627 | - public function get_one_copy($model_object_or_attributes_array,$query_params = array()){ |
|
4628 | - if( ! is_array( $query_params ) ){ |
|
4629 | - 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' ); |
|
4627 | + public function get_one_copy($model_object_or_attributes_array, $query_params = array()) { |
|
4628 | + if ( ! is_array($query_params)) { |
|
4629 | + 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'); |
|
4630 | 4630 | $query_params = array(); |
4631 | 4631 | } |
4632 | 4632 | $query_params['limit'] = 1; |
4633 | - $copies = $this->get_all_copies($model_object_or_attributes_array,$query_params); |
|
4634 | - if(is_array($copies)){ |
|
4633 | + $copies = $this->get_all_copies($model_object_or_attributes_array, $query_params); |
|
4634 | + if (is_array($copies)) { |
|
4635 | 4635 | return array_shift($copies); |
4636 | - }else{ |
|
4636 | + } else { |
|
4637 | 4637 | return null; |
4638 | 4638 | } |
4639 | 4639 | } |
@@ -4649,10 +4649,10 @@ discard block |
||
4649 | 4649 | * @return int number of rows updated |
4650 | 4650 | * @throws \EE_Error |
4651 | 4651 | */ |
4652 | - public function update_by_ID($fields_n_values,$id){ |
|
4652 | + public function update_by_ID($fields_n_values, $id) { |
|
4653 | 4653 | $query_params = array(0=>array($this->get_primary_key_field()->get_name() => $id), |
4654 | 4654 | 'default_where_conditions'=>'other_models_only',); |
4655 | - return $this->update($fields_n_values,$query_params); |
|
4655 | + return $this->update($fields_n_values, $query_params); |
|
4656 | 4656 | } |
4657 | 4657 | |
4658 | 4658 | |
@@ -4663,12 +4663,12 @@ discard block |
||
4663 | 4663 | * @return string an operator which can be used in SQL |
4664 | 4664 | * @throws EE_Error |
4665 | 4665 | */ |
4666 | - private function _prepare_operator_for_sql($operator_supplied){ |
|
4666 | + private function _prepare_operator_for_sql($operator_supplied) { |
|
4667 | 4667 | $sql_operator = isset($this->_valid_operators[$operator_supplied]) ? $this->_valid_operators[$operator_supplied] : null; |
4668 | - if($sql_operator){ |
|
4668 | + if ($sql_operator) { |
|
4669 | 4669 | return $sql_operator; |
4670 | - }else{ |
|
4671 | - 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)))); |
|
4670 | + } else { |
|
4671 | + 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)))); |
|
4672 | 4672 | } |
4673 | 4673 | } |
4674 | 4674 | |
@@ -4682,10 +4682,10 @@ discard block |
||
4682 | 4682 | * @return string[] |
4683 | 4683 | * @throws \EE_Error |
4684 | 4684 | */ |
4685 | - public function get_all_names($query_params = array()){ |
|
4685 | + public function get_all_names($query_params = array()) { |
|
4686 | 4686 | $objs = $this->get_all($query_params); |
4687 | 4687 | $names = array(); |
4688 | - foreach($objs as $obj){ |
|
4688 | + foreach ($objs as $obj) { |
|
4689 | 4689 | $names[$obj->ID()] = $obj->name(); |
4690 | 4690 | } |
4691 | 4691 | return $names; |
@@ -4704,11 +4704,11 @@ discard block |
||
4704 | 4704 | * @return array |
4705 | 4705 | * @throws \EE_Error |
4706 | 4706 | */ |
4707 | - public function get_IDs( $model_objects, $filter_out_empty_ids = false) { |
|
4708 | - if( ! $this->has_primary_key_field() ) { |
|
4709 | - if( WP_DEBUG ) { |
|
4707 | + public function get_IDs($model_objects, $filter_out_empty_ids = false) { |
|
4708 | + if ( ! $this->has_primary_key_field()) { |
|
4709 | + if (WP_DEBUG) { |
|
4710 | 4710 | EE_Error::add_error( |
4711 | - __( 'Trying to get IDs from a model than has no primary key', 'event_espresso' ), |
|
4711 | + __('Trying to get IDs from a model than has no primary key', 'event_espresso'), |
|
4712 | 4712 | __FILE__, |
4713 | 4713 | __FUNCTION__, |
4714 | 4714 | __LINE__ |
@@ -4716,13 +4716,13 @@ discard block |
||
4716 | 4716 | } |
4717 | 4717 | } |
4718 | 4718 | $IDs = array(); |
4719 | - foreach( $model_objects as $model_object ) { |
|
4719 | + foreach ($model_objects as $model_object) { |
|
4720 | 4720 | $id = $model_object->ID(); |
4721 | - if( ! $id ) { |
|
4722 | - if( $filter_out_empty_ids ) { |
|
4721 | + if ( ! $id) { |
|
4722 | + if ($filter_out_empty_ids) { |
|
4723 | 4723 | continue; |
4724 | 4724 | } |
4725 | - if ( WP_DEBUG ) { |
|
4725 | + if (WP_DEBUG) { |
|
4726 | 4726 | EE_Error::add_error( |
4727 | 4727 | __( |
4728 | 4728 | 'Called %1$s on a model object that has no ID and so probably hasn\'t been saved to the database', |
@@ -4744,8 +4744,8 @@ discard block |
||
4744 | 4744 | * are no capabilities that relate to this model returns false |
4745 | 4745 | * @return string|false |
4746 | 4746 | */ |
4747 | - public function cap_slug(){ |
|
4748 | - return apply_filters( 'FHEE__EEM_Base__cap_slug', $this->_caps_slug, $this); |
|
4747 | + public function cap_slug() { |
|
4748 | + return apply_filters('FHEE__EEM_Base__cap_slug', $this->_caps_slug, $this); |
|
4749 | 4749 | } |
4750 | 4750 | |
4751 | 4751 | |
@@ -4760,34 +4760,34 @@ discard block |
||
4760 | 4760 | * @return EE_Default_Where_Conditions[] indexed by associated capability |
4761 | 4761 | * @throws \EE_Error |
4762 | 4762 | */ |
4763 | - public function cap_restrictions( $context = EEM_Base::caps_read ) { |
|
4764 | - EEM_Base::verify_is_valid_cap_context( $context ); |
|
4763 | + public function cap_restrictions($context = EEM_Base::caps_read) { |
|
4764 | + EEM_Base::verify_is_valid_cap_context($context); |
|
4765 | 4765 | //check if we ought to run the restriction generator first |
4766 | - if( |
|
4767 | - isset( $this->_cap_restriction_generators[ $context ] ) |
|
4768 | - && $this->_cap_restriction_generators[ $context ] instanceof EE_Restriction_Generator_Base |
|
4769 | - && ! $this->_cap_restriction_generators[ $context ]->has_generated_cap_restrictions() |
|
4766 | + if ( |
|
4767 | + isset($this->_cap_restriction_generators[$context]) |
|
4768 | + && $this->_cap_restriction_generators[$context] instanceof EE_Restriction_Generator_Base |
|
4769 | + && ! $this->_cap_restriction_generators[$context]->has_generated_cap_restrictions() |
|
4770 | 4770 | ) { |
4771 | - $this->_cap_restrictions[ $context ] = array_merge( |
|
4772 | - $this->_cap_restrictions[ $context ], |
|
4773 | - $this->_cap_restriction_generators[ $context ]->generate_restrictions() |
|
4771 | + $this->_cap_restrictions[$context] = array_merge( |
|
4772 | + $this->_cap_restrictions[$context], |
|
4773 | + $this->_cap_restriction_generators[$context]->generate_restrictions() |
|
4774 | 4774 | ); |
4775 | 4775 | } |
4776 | 4776 | //and make sure we've finalized the construction of each restriction |
4777 | - foreach( $this->_cap_restrictions[ $context ] as $where_conditions_obj ) { |
|
4778 | - if ( $where_conditions_obj instanceof EE_Default_Where_Conditions ) { |
|
4779 | - $where_conditions_obj->_finalize_construct( $this ); |
|
4777 | + foreach ($this->_cap_restrictions[$context] as $where_conditions_obj) { |
|
4778 | + if ($where_conditions_obj instanceof EE_Default_Where_Conditions) { |
|
4779 | + $where_conditions_obj->_finalize_construct($this); |
|
4780 | 4780 | } |
4781 | 4781 | } |
4782 | 4782 | |
4783 | - return $this->_cap_restrictions[ $context ]; |
|
4783 | + return $this->_cap_restrictions[$context]; |
|
4784 | 4784 | } |
4785 | 4785 | |
4786 | 4786 | /** |
4787 | 4787 | * Indicating whether or not this model thinks its a wp core model |
4788 | 4788 | * @return boolean |
4789 | 4789 | */ |
4790 | - public function is_wp_core_model(){ |
|
4790 | + public function is_wp_core_model() { |
|
4791 | 4791 | return $this->_wp_core_model; |
4792 | 4792 | } |
4793 | 4793 | |
@@ -4801,12 +4801,12 @@ discard block |
||
4801 | 4801 | * @return EE_Default_Where_Conditions[] indexed by capability name |
4802 | 4802 | * @throws \EE_Error |
4803 | 4803 | */ |
4804 | - public function caps_missing( $context = EEM_Base::caps_read ) { |
|
4804 | + public function caps_missing($context = EEM_Base::caps_read) { |
|
4805 | 4805 | $missing_caps = array(); |
4806 | - $cap_restrictions = $this->cap_restrictions( $context ); |
|
4807 | - foreach( $cap_restrictions as $cap => $restriction_if_no_cap ) { |
|
4808 | - if( ! EE_Capabilities::instance()->current_user_can( $cap, $this->get_this_model_name() . '_model_applying_caps') ) { |
|
4809 | - $missing_caps[ $cap ] = $restriction_if_no_cap; |
|
4806 | + $cap_restrictions = $this->cap_restrictions($context); |
|
4807 | + foreach ($cap_restrictions as $cap => $restriction_if_no_cap) { |
|
4808 | + if ( ! EE_Capabilities::instance()->current_user_can($cap, $this->get_this_model_name().'_model_applying_caps')) { |
|
4809 | + $missing_caps[$cap] = $restriction_if_no_cap; |
|
4810 | 4810 | } |
4811 | 4811 | } |
4812 | 4812 | return $missing_caps; |
@@ -4818,7 +4818,7 @@ discard block |
||
4818 | 4818 | * one of 'read', 'edit', or 'delete' |
4819 | 4819 | */ |
4820 | 4820 | public function cap_contexts_to_cap_action_map() { |
4821 | - return apply_filters( 'FHEE__EEM_Base__cap_contexts_to_cap_action_map', $this->_cap_contexts_to_cap_action_map, $this ); |
|
4821 | + return apply_filters('FHEE__EEM_Base__cap_contexts_to_cap_action_map', $this->_cap_contexts_to_cap_action_map, $this); |
|
4822 | 4822 | } |
4823 | 4823 | |
4824 | 4824 | |
@@ -4829,19 +4829,19 @@ discard block |
||
4829 | 4829 | * @return string one of EEM_Base::cap_contexts_to_cap_action_map() values |
4830 | 4830 | * @throws \EE_Error |
4831 | 4831 | */ |
4832 | - public function cap_action_for_context( $context ) { |
|
4832 | + public function cap_action_for_context($context) { |
|
4833 | 4833 | $mapping = $this->cap_contexts_to_cap_action_map(); |
4834 | - if( isset( $mapping[ $context ] ) ) { |
|
4835 | - return $mapping[ $context ]; |
|
4834 | + if (isset($mapping[$context])) { |
|
4835 | + return $mapping[$context]; |
|
4836 | 4836 | } |
4837 | - if( $action = apply_filters( 'FHEE__EEM_Base__cap_action_for_context', null, $this, $mapping, $context ) ) { |
|
4837 | + if ($action = apply_filters('FHEE__EEM_Base__cap_action_for_context', null, $this, $mapping, $context)) { |
|
4838 | 4838 | return $action; |
4839 | 4839 | } |
4840 | 4840 | throw new EE_Error( |
4841 | 4841 | sprintf( |
4842 | - __( 'Cannot find capability restrictions for context "%1$s", allowed values are:%2$s', 'event_espresso' ), |
|
4842 | + __('Cannot find capability restrictions for context "%1$s", allowed values are:%2$s', 'event_espresso'), |
|
4843 | 4843 | $context, |
4844 | - implode(',', array_keys( $this->cap_contexts_to_cap_action_map() ) ) |
|
4844 | + implode(',', array_keys($this->cap_contexts_to_cap_action_map())) |
|
4845 | 4845 | ) |
4846 | 4846 | ); |
4847 | 4847 | |
@@ -4852,7 +4852,7 @@ discard block |
||
4852 | 4852 | * @return array |
4853 | 4853 | */ |
4854 | 4854 | static public function valid_cap_contexts() { |
4855 | - return apply_filters( 'FHEE__EEM_Base__valid_cap_contexts', array( |
|
4855 | + return apply_filters('FHEE__EEM_Base__valid_cap_contexts', array( |
|
4856 | 4856 | self::caps_read, |
4857 | 4857 | self::caps_read_admin, |
4858 | 4858 | self::caps_edit, |
@@ -4868,17 +4868,17 @@ discard block |
||
4868 | 4868 | * @return bool |
4869 | 4869 | * @throws \EE_Error |
4870 | 4870 | */ |
4871 | - static public function verify_is_valid_cap_context( $context ) { |
|
4871 | + static public function verify_is_valid_cap_context($context) { |
|
4872 | 4872 | $valid_cap_contexts = EEM_Base::valid_cap_contexts(); |
4873 | - if( in_array( $context, $valid_cap_contexts ) ) { |
|
4873 | + if (in_array($context, $valid_cap_contexts)) { |
|
4874 | 4874 | return true; |
4875 | - }else{ |
|
4875 | + } else { |
|
4876 | 4876 | throw new EE_Error( |
4877 | 4877 | sprintf( |
4878 | - __( 'Context "%1$s" passed into model "%2$s" is not a valid context. They are: %3$s', 'event_espresso' ), |
|
4878 | + __('Context "%1$s" passed into model "%2$s" is not a valid context. They are: %3$s', 'event_espresso'), |
|
4879 | 4879 | $context, |
4880 | - 'EEM_Base' , |
|
4881 | - implode(',', $valid_cap_contexts ) |
|
4880 | + 'EEM_Base', |
|
4881 | + implode(',', $valid_cap_contexts) |
|
4882 | 4882 | ) |
4883 | 4883 | ); |
4884 | 4884 | } |
@@ -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 | } |
@@ -3029,7 +3029,7 @@ discard block |
||
3029 | 3029 | foreach($default_where_conditions as $key => $val){ |
3030 | 3030 | if( isset($provided_where_conditions[$key])){ |
3031 | 3031 | $none_overridden = false; |
3032 | - }else{ |
|
3032 | + } else{ |
|
3033 | 3033 | $null_friendly_where_conditions[$or_condition_key_for_defaults]['AND'][$key] = $val; |
3034 | 3034 | } |
3035 | 3035 | } |
@@ -3155,7 +3155,7 @@ discard block |
||
3155 | 3155 | if(array_key_exists($query_param,$this_model_fields)){ |
3156 | 3156 | if($allow_fields){ |
3157 | 3157 | return; |
3158 | - }else{ |
|
3158 | + } else{ |
|
3159 | 3159 | 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"), |
3160 | 3160 | $query_param,get_class($this),$query_param_type,$original_query_param)); |
3161 | 3161 | } |
@@ -3164,7 +3164,7 @@ discard block |
||
3164 | 3164 | elseif(in_array($query_param, $this->_logic_query_param_keys, TRUE)){ |
3165 | 3165 | if($allow_logic_query_params){ |
3166 | 3166 | return; |
3167 | - }else{ |
|
3167 | + } else{ |
|
3168 | 3168 | throw new EE_Error( |
3169 | 3169 | sprintf( |
3170 | 3170 | __( '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' ), |
@@ -3195,12 +3195,12 @@ discard block |
||
3195 | 3195 | //we should actually end in a field name, not a model like this! |
3196 | 3196 | throw new EE_Error(sprintf(__("Query param '%s' (of type %s on model %s) shouldn't end on a period (.) ", "event_espresso"), |
3197 | 3197 | $query_param,$query_param_type,get_class($this),$valid_related_model_name)); |
3198 | - }else{ |
|
3198 | + } else{ |
|
3199 | 3199 | $related_model_obj = $this->get_related_model_obj($valid_related_model_name); |
3200 | 3200 | $related_model_obj->_extract_related_model_info_from_query_param($query_param, $passed_in_query_info, $query_param_type, $original_query_param); |
3201 | 3201 | return; |
3202 | 3202 | } |
3203 | - }elseif($query_param === $valid_related_model_name){ |
|
3203 | + } elseif($query_param === $valid_related_model_name){ |
|
3204 | 3204 | $this->_add_join_to_model($valid_related_model_name, $passed_in_query_info,$original_query_param); |
3205 | 3205 | return; |
3206 | 3206 | } |
@@ -3265,7 +3265,7 @@ discard block |
||
3265 | 3265 | $SQL = $this->_construct_condition_clause_recursive($where_params, ' AND '); |
3266 | 3266 | if($SQL){ |
3267 | 3267 | return " WHERE ". $SQL; |
3268 | - }else{ |
|
3268 | + } else{ |
|
3269 | 3269 | return ''; |
3270 | 3270 | } |
3271 | 3271 | } |
@@ -3284,7 +3284,7 @@ discard block |
||
3284 | 3284 | $SQL = $this->_construct_condition_clause_recursive($having_params, ' AND '); |
3285 | 3285 | if($SQL){ |
3286 | 3286 | return " HAVING ". $SQL; |
3287 | - }else{ |
|
3287 | + } else{ |
|
3288 | 3288 | return ''; |
3289 | 3289 | } |
3290 | 3290 | |
@@ -3307,7 +3307,7 @@ discard block |
||
3307 | 3307 | $model_instance=call_user_func($model_name."::instance"); |
3308 | 3308 | /* @var $model_instance EEM_Base */ |
3309 | 3309 | return $model_instance->field_settings_for($field_name); |
3310 | - }else{ |
|
3310 | + } else{ |
|
3311 | 3311 | throw new EE_Error(sprintf(__('No model named %s exists, with classname %s and filepath %s','event_espresso'),$model_name,$model_class,$model_filepath)); |
3312 | 3312 | } |
3313 | 3313 | } |
@@ -3340,14 +3340,14 @@ discard block |
||
3340 | 3340 | $where_clauses[] = " (". $this->_construct_condition_clause_recursive($op_and_value_or_sub_condition, ' OR ') .")"; |
3341 | 3341 | break; |
3342 | 3342 | } |
3343 | - }else{ |
|
3343 | + } else{ |
|
3344 | 3344 | $field_obj = $this->_deduce_field_from_query_param($query_param); |
3345 | 3345 | |
3346 | 3346 | //if it's not a normal field, maybe it's a custom selection? |
3347 | 3347 | if( ! $field_obj){ |
3348 | 3348 | if(isset( $this->_custom_selections[$query_param][1])){ |
3349 | 3349 | $field_obj = $this->_custom_selections[$query_param][1]; |
3350 | - }else{ |
|
3350 | + } else{ |
|
3351 | 3351 | throw new EE_Error(sprintf(__("%s is neither a valid model field name, nor a custom selection", "event_espresso"),$query_param)); |
3352 | 3352 | } |
3353 | 3353 | } |
@@ -3372,11 +3372,11 @@ discard block |
||
3372 | 3372 | if( $field ){ |
3373 | 3373 | $table_alias_prefix = EE_Model_Parser::extract_table_alias_model_relation_chain_from_query_param( $field->get_model_name(), $query_param ); |
3374 | 3374 | return $table_alias_prefix . $field->get_qualified_column(); |
3375 | - }elseif(array_key_exists($query_param,$this->_custom_selections)){ |
|
3375 | + } elseif(array_key_exists($query_param,$this->_custom_selections)){ |
|
3376 | 3376 | //maybe it's custom selection item? |
3377 | 3377 | //if so, just use it as the "column name" |
3378 | 3378 | return $query_param; |
3379 | - }else{ |
|
3379 | + } else{ |
|
3380 | 3380 | 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))); |
3381 | 3381 | } |
3382 | 3382 | } |
@@ -3393,7 +3393,7 @@ discard block |
||
3393 | 3393 | $pos_of_star = strpos($condition_query_param_key, '*'); |
3394 | 3394 | if($pos_of_star === FALSE){ |
3395 | 3395 | return $condition_query_param_key; |
3396 | - }else{ |
|
3396 | + } else{ |
|
3397 | 3397 | $condition_query_param_sans_star = substr($condition_query_param_key, 0, $pos_of_star); |
3398 | 3398 | return $condition_query_param_sans_star; |
3399 | 3399 | } |
@@ -3578,7 +3578,7 @@ discard block |
||
3578 | 3578 | global $wpdb; |
3579 | 3579 | if($field_obj instanceof EE_Model_Field_Base){ |
3580 | 3580 | return $wpdb->prepare($field_obj->get_wpdb_data_type(),$this->_prepare_value_for_use_in_db($value, $field_obj)); |
3581 | - }else{//$field_obj should really just be a data type |
|
3581 | + } else{//$field_obj should really just be a data type |
|
3582 | 3582 | if( ! in_array($field_obj,$this->_valid_wpdb_data_types)){ |
3583 | 3583 | 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))); |
3584 | 3584 | } |
@@ -3607,14 +3607,14 @@ discard block |
||
3607 | 3607 | if($number_of_parts === 1){ |
3608 | 3608 | $field_name = $last_query_param_part; |
3609 | 3609 | $model_obj = $this; |
3610 | - }else{// $number_of_parts >= 2 |
|
3610 | + } else{// $number_of_parts >= 2 |
|
3611 | 3611 | //the last part is the column name, and there are only 2parts. therefore... |
3612 | 3612 | $field_name = $last_query_param_part; |
3613 | 3613 | $model_obj = $this->get_related_model_obj( $query_param_parts[ $number_of_parts - 2 ]); |
3614 | 3614 | } |
3615 | 3615 | try{ |
3616 | 3616 | return $model_obj->field_settings_for($field_name); |
3617 | - }catch(EE_Error $e){ |
|
3617 | + } catch(EE_Error $e){ |
|
3618 | 3618 | return null; |
3619 | 3619 | } |
3620 | 3620 | } |
@@ -3633,7 +3633,7 @@ discard block |
||
3633 | 3633 | $field = isset($all_fields[$field_name]) ? $all_fields[$field_name] : FALSE; |
3634 | 3634 | if($field){ |
3635 | 3635 | return $field->get_qualified_column(); |
3636 | - }else{ |
|
3636 | + } else{ |
|
3637 | 3637 | 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))); |
3638 | 3638 | } |
3639 | 3639 | } |
@@ -3704,7 +3704,7 @@ discard block |
||
3704 | 3704 | //the FROM statement, BUT the primary table isn't. So we want |
3705 | 3705 | //to add the inverse join sql |
3706 | 3706 | $SQL .= $table_obj->get_inverse_join_sql($alias_prefixed); |
3707 | - }else{ |
|
3707 | + } else{ |
|
3708 | 3708 | //just add a regular JOIN to this table from the primary table |
3709 | 3709 | $SQL .= $table_obj->get_join_sql($alias_prefixed); |
3710 | 3710 | } |
@@ -3817,7 +3817,7 @@ discard block |
||
3817 | 3817 | $fieldSettings = $this->field_settings(true); |
3818 | 3818 | if( isset($fieldSettings[$fieldName])){ |
3819 | 3819 | return true; |
3820 | - }else{ |
|
3820 | + } else{ |
|
3821 | 3821 | return false; |
3822 | 3822 | } |
3823 | 3823 | } |
@@ -3831,7 +3831,7 @@ discard block |
||
3831 | 3831 | $relations = $this->relation_settings(); |
3832 | 3832 | if(isset($relations[$relation_name])){ |
3833 | 3833 | return true; |
3834 | - }else{ |
|
3834 | + } else{ |
|
3835 | 3835 | return false; |
3836 | 3836 | } |
3837 | 3837 | } |
@@ -3882,7 +3882,7 @@ discard block |
||
3882 | 3882 | try{ |
3883 | 3883 | $this->get_primary_key_field(); |
3884 | 3884 | $this->_has_primary_key_field = true; |
3885 | - }catch(EE_Error $e){ |
|
3885 | + } catch(EE_Error $e){ |
|
3886 | 3886 | $this->_has_primary_key_field = false; |
3887 | 3887 | } |
3888 | 3888 | } |
@@ -3961,7 +3961,7 @@ discard block |
||
3961 | 3961 | } |
3962 | 3962 | } |
3963 | 3963 | return $this->_cached_fields; |
3964 | - }else{ |
|
3964 | + } else{ |
|
3965 | 3965 | if( $this->_cached_fields_non_db_only === NULL ){ |
3966 | 3966 | $this->_cached_fields_non_db_only = array(); |
3967 | 3967 | foreach($this->_fields as $fields_corresponding_to_table){ |
@@ -4097,7 +4097,7 @@ discard block |
||
4097 | 4097 | if(empty( $this_model_fields_n_values[$this->primary_key_name()] )){ |
4098 | 4098 | return NULL; |
4099 | 4099 | } |
4100 | - }else if($this->unique_indexes()){ |
|
4100 | + } else if($this->unique_indexes()){ |
|
4101 | 4101 | $first_column = reset($this_model_fields_n_values); |
4102 | 4102 | if(empty($first_column)){ |
4103 | 4103 | return NULL; |
@@ -4112,7 +4112,7 @@ discard block |
||
4112 | 4112 | // add this new object to the entity map |
4113 | 4113 | $classInstance = $this->add_to_entity_map( $classInstance ); |
4114 | 4114 | } |
4115 | - }else{ |
|
4115 | + } else{ |
|
4116 | 4116 | $classInstance = EE_Registry::instance()->load_class( $className, array( $this_model_fields_n_values, $this->_timezone ), TRUE, FALSE ); |
4117 | 4117 | } |
4118 | 4118 | |
@@ -4199,7 +4199,7 @@ discard block |
||
4199 | 4199 | $this_model_fields_n_values[$field_name] = $field_obj->prepare_for_use_in_db( $prepared_value ); |
4200 | 4200 | } |
4201 | 4201 | } |
4202 | - }else{ |
|
4202 | + } else{ |
|
4203 | 4203 | //the table's rows existed. Use their values |
4204 | 4204 | foreach( $this->_get_fields_for_table( $table_alias ) as $field_name => $field_obj ) { |
4205 | 4205 | if( ! $field_obj->is_db_only_field() ){ |
@@ -4229,7 +4229,7 @@ discard block |
||
4229 | 4229 | //or is it a db-only field? (not relating to the model) |
4230 | 4230 | if( isset( $cols_n_values[ $qualified_column ] ) ){ |
4231 | 4231 | $value = $cols_n_values[ $qualified_column ]; |
4232 | - }elseif( isset( $cols_n_values[ $regular_column ] ) ){ |
|
4232 | + } elseif( isset( $cols_n_values[ $regular_column ] ) ){ |
|
4233 | 4233 | $value = $cols_n_values[ $regular_column ]; |
4234 | 4234 | } |
4235 | 4235 | return $value; |
@@ -4263,7 +4263,7 @@ discard block |
||
4263 | 4263 | } |
4264 | 4264 | } |
4265 | 4265 | return $obj_in_map; |
4266 | - }else{ |
|
4266 | + } else{ |
|
4267 | 4267 | return $this->get_one_by_ID( $id ); |
4268 | 4268 | } |
4269 | 4269 | } |
@@ -4298,7 +4298,7 @@ discard block |
||
4298 | 4298 | } |
4299 | 4299 | } |
4300 | 4300 | return $obj_in_map; |
4301 | - }else{ |
|
4301 | + } else{ |
|
4302 | 4302 | $this->add_to_entity_map( $replacing_model_obj ); |
4303 | 4303 | return $replacing_model_obj; |
4304 | 4304 | } |
@@ -4443,13 +4443,13 @@ discard block |
||
4443 | 4443 | if( $base_class_obj_or_id instanceof $className ){ |
4444 | 4444 | /** @var $base_class_obj_or_id EE_Base_Class */ |
4445 | 4445 | $id = $base_class_obj_or_id->ID(); |
4446 | - }elseif(is_int($base_class_obj_or_id)){ |
|
4446 | + } elseif(is_int($base_class_obj_or_id)){ |
|
4447 | 4447 | //assume it's an ID |
4448 | 4448 | $id = $base_class_obj_or_id; |
4449 | - }elseif(is_string($base_class_obj_or_id)){ |
|
4449 | + } elseif(is_string($base_class_obj_or_id)){ |
|
4450 | 4450 | //assume its a string representation of the object |
4451 | 4451 | $id = $base_class_obj_or_id; |
4452 | - }else{ |
|
4452 | + } else{ |
|
4453 | 4453 | 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))); |
4454 | 4454 | } |
4455 | 4455 | return $id; |
@@ -4596,9 +4596,9 @@ discard block |
||
4596 | 4596 | |
4597 | 4597 | if($model_object_or_attributes_array instanceof EE_Base_Class){ |
4598 | 4598 | $attributes_array = $model_object_or_attributes_array->model_field_array(); |
4599 | - }elseif(is_array($model_object_or_attributes_array)){ |
|
4599 | + } elseif(is_array($model_object_or_attributes_array)){ |
|
4600 | 4600 | $attributes_array = $model_object_or_attributes_array; |
4601 | - }else{ |
|
4601 | + } else{ |
|
4602 | 4602 | 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)); |
4603 | 4603 | } |
4604 | 4604 | //even copies obviously won't have the same ID, so remove the primary key |
@@ -4608,7 +4608,7 @@ discard block |
||
4608 | 4608 | } |
4609 | 4609 | if(isset($query_params[0])){ |
4610 | 4610 | $query_params[0] = array_merge($attributes_array,$query_params); |
4611 | - }else{ |
|
4611 | + } else{ |
|
4612 | 4612 | $query_params[0] = $attributes_array; |
4613 | 4613 | } |
4614 | 4614 | return $this->get_all($query_params); |
@@ -4633,7 +4633,7 @@ discard block |
||
4633 | 4633 | $copies = $this->get_all_copies($model_object_or_attributes_array,$query_params); |
4634 | 4634 | if(is_array($copies)){ |
4635 | 4635 | return array_shift($copies); |
4636 | - }else{ |
|
4636 | + } else{ |
|
4637 | 4637 | return null; |
4638 | 4638 | } |
4639 | 4639 | } |
@@ -4667,7 +4667,7 @@ discard block |
||
4667 | 4667 | $sql_operator = isset($this->_valid_operators[$operator_supplied]) ? $this->_valid_operators[$operator_supplied] : null; |
4668 | 4668 | if($sql_operator){ |
4669 | 4669 | return $sql_operator; |
4670 | - }else{ |
|
4670 | + } else{ |
|
4671 | 4671 | 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)))); |
4672 | 4672 | } |
4673 | 4673 | } |
@@ -4872,7 +4872,7 @@ discard block |
||
4872 | 4872 | $valid_cap_contexts = EEM_Base::valid_cap_contexts(); |
4873 | 4873 | if( in_array( $context, $valid_cap_contexts ) ) { |
4874 | 4874 | return true; |
4875 | - }else{ |
|
4875 | + } else{ |
|
4876 | 4876 | throw new EE_Error( |
4877 | 4877 | sprintf( |
4878 | 4878 | __( 'Context "%1$s" passed into model "%2$s" is not a valid context. They are: %3$s', 'event_espresso' ), |
@@ -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 | |
@@ -58,16 +58,16 @@ discard block |
||
58 | 58 | */ |
59 | 59 | public function lock() { |
60 | 60 | // attempt to set lock, but if that fails... |
61 | - if ( ! $this->add_extra_meta( 'lock', time(), true ) ) { |
|
61 | + if ( ! $this->add_extra_meta('lock', time(), true)) { |
|
62 | 62 | // then attempt to remove the lock in case it is expired |
63 | - if ( $this->_remove_expired_lock() ) { |
|
63 | + if ($this->_remove_expired_lock()) { |
|
64 | 64 | // if removal was successful, then try setting lock again |
65 | 65 | $this->lock(); |
66 | 66 | } else { |
67 | 67 | // but if the lock can not be removed, then throw an exception |
68 | 68 | throw new EE_Error( |
69 | 69 | sprintf( |
70 | - __( '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' ), |
|
70 | + __('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 | 71 | $this->ID() |
72 | 72 | ) |
73 | 73 | ); |
@@ -86,7 +86,7 @@ discard block |
||
86 | 86 | * @throws \EE_Error |
87 | 87 | */ |
88 | 88 | public function unlock() { |
89 | - return $this->delete_extra_meta( 'lock' ); |
|
89 | + return $this->delete_extra_meta('lock'); |
|
90 | 90 | } |
91 | 91 | |
92 | 92 | |
@@ -107,7 +107,7 @@ discard block |
||
107 | 107 | */ |
108 | 108 | public function is_locked() { |
109 | 109 | // if TXN is not locked, then return false immediately |
110 | - if ( ! $this->_get_lock() ) { |
|
110 | + if ( ! $this->_get_lock()) { |
|
111 | 111 | return false; |
112 | 112 | } |
113 | 113 | // if not, then let's try and remove the lock in case it's expired... |
@@ -128,7 +128,7 @@ discard block |
||
128 | 128 | * @throws \EE_Error |
129 | 129 | */ |
130 | 130 | protected function _get_lock() { |
131 | - return (int)$this->get_extra_meta( 'lock', true, 0 ); |
|
131 | + return (int) $this->get_extra_meta('lock', true, 0); |
|
132 | 132 | } |
133 | 133 | |
134 | 134 | |
@@ -143,7 +143,7 @@ discard block |
||
143 | 143 | */ |
144 | 144 | protected function _remove_expired_lock() { |
145 | 145 | $locked = $this->_get_lock(); |
146 | - if ( $locked && time() - EE_Transaction::LOCK_EXPIRATION > $locked ) { |
|
146 | + if ($locked && time() - EE_Transaction::LOCK_EXPIRATION > $locked) { |
|
147 | 147 | return $this->unlock(); |
148 | 148 | } |
149 | 149 | return 0; |
@@ -158,8 +158,8 @@ discard block |
||
158 | 158 | * @param float $total total value of transaction |
159 | 159 | * @throws \EE_Error |
160 | 160 | */ |
161 | - public function set_total( $total = 0.00 ) { |
|
162 | - $this->set( 'TXN_total', (float)$total ); |
|
161 | + public function set_total($total = 0.00) { |
|
162 | + $this->set('TXN_total', (float) $total); |
|
163 | 163 | } |
164 | 164 | |
165 | 165 | |
@@ -171,8 +171,8 @@ discard block |
||
171 | 171 | * @param float $total_paid total amount paid to date (sum of all payments) |
172 | 172 | * @throws \EE_Error |
173 | 173 | */ |
174 | - public function set_paid( $total_paid = 0.00 ) { |
|
175 | - $this->set( 'TXN_paid', (float)$total_paid ); |
|
174 | + public function set_paid($total_paid = 0.00) { |
|
175 | + $this->set('TXN_paid', (float) $total_paid); |
|
176 | 176 | } |
177 | 177 | |
178 | 178 | |
@@ -184,8 +184,8 @@ discard block |
||
184 | 184 | * @param string $status whether the transaction is open, declined, accepted, or any number of custom values that can be set |
185 | 185 | * @throws \EE_Error |
186 | 186 | */ |
187 | - public function set_status( $status = '' ) { |
|
188 | - $this->set( 'STS_ID', $status ); |
|
187 | + public function set_status($status = '') { |
|
188 | + $this->set('STS_ID', $status); |
|
189 | 189 | } |
190 | 190 | |
191 | 191 | |
@@ -197,8 +197,8 @@ discard block |
||
197 | 197 | * @param string $hash_salt required for some payment gateways |
198 | 198 | * @throws \EE_Error |
199 | 199 | */ |
200 | - public function set_hash_salt( $hash_salt = '' ) { |
|
201 | - $this->set( 'TXN_hash_salt', $hash_salt ); |
|
200 | + public function set_hash_salt($hash_salt = '') { |
|
201 | + $this->set('TXN_hash_salt', $hash_salt); |
|
202 | 202 | } |
203 | 203 | |
204 | 204 | |
@@ -209,8 +209,8 @@ discard block |
||
209 | 209 | * @param array $txn_reg_steps |
210 | 210 | * @throws \EE_Error |
211 | 211 | */ |
212 | - public function set_reg_steps( array $txn_reg_steps ) { |
|
213 | - $this->set( 'TXN_reg_steps', $txn_reg_steps ); |
|
212 | + public function set_reg_steps(array $txn_reg_steps) { |
|
213 | + $this->set('TXN_reg_steps', $txn_reg_steps); |
|
214 | 214 | } |
215 | 215 | |
216 | 216 | |
@@ -222,8 +222,8 @@ discard block |
||
222 | 222 | * @throws \EE_Error |
223 | 223 | */ |
224 | 224 | public function reg_steps() { |
225 | - $TXN_reg_steps = $this->get( 'TXN_reg_steps' ); |
|
226 | - return is_array( $TXN_reg_steps ) ? (array)$TXN_reg_steps : array(); |
|
225 | + $TXN_reg_steps = $this->get('TXN_reg_steps'); |
|
226 | + return is_array($TXN_reg_steps) ? (array) $TXN_reg_steps : array(); |
|
227 | 227 | } |
228 | 228 | |
229 | 229 | |
@@ -233,7 +233,7 @@ discard block |
||
233 | 233 | * @throws \EE_Error |
234 | 234 | */ |
235 | 235 | public function pretty_total() { |
236 | - return $this->get_pretty( 'TXN_total' ); |
|
236 | + return $this->get_pretty('TXN_total'); |
|
237 | 237 | } |
238 | 238 | |
239 | 239 | |
@@ -245,7 +245,7 @@ discard block |
||
245 | 245 | * @throws \EE_Error |
246 | 246 | */ |
247 | 247 | public function pretty_paid() { |
248 | - return $this->get_pretty( 'TXN_paid' ); |
|
248 | + return $this->get_pretty('TXN_paid'); |
|
249 | 249 | } |
250 | 250 | |
251 | 251 | |
@@ -258,7 +258,7 @@ discard block |
||
258 | 258 | * @throws \EE_Error |
259 | 259 | */ |
260 | 260 | public function remaining() { |
261 | - return (float)( $this->total() - $this->paid() ); |
|
261 | + return (float) ($this->total() - $this->paid()); |
|
262 | 262 | } |
263 | 263 | |
264 | 264 | |
@@ -271,7 +271,7 @@ discard block |
||
271 | 271 | * @throws \EE_Error |
272 | 272 | */ |
273 | 273 | public function total() { |
274 | - return (float)$this->get( 'TXN_total' ); |
|
274 | + return (float) $this->get('TXN_total'); |
|
275 | 275 | } |
276 | 276 | |
277 | 277 | |
@@ -284,7 +284,7 @@ discard block |
||
284 | 284 | * @throws \EE_Error |
285 | 285 | */ |
286 | 286 | public function paid() { |
287 | - return (float)$this->get( 'TXN_paid' ); |
|
287 | + return (float) $this->get('TXN_paid'); |
|
288 | 288 | } |
289 | 289 | |
290 | 290 | |
@@ -296,9 +296,9 @@ discard block |
||
296 | 296 | * @throws \EE_Error |
297 | 297 | */ |
298 | 298 | public function get_cart_session() { |
299 | - $session_data = (array)$this->get( 'TXN_session_data' ); |
|
300 | - return isset( $session_data[ 'cart' ] ) && $session_data[ 'cart' ] instanceof EE_Cart |
|
301 | - ? $session_data[ 'cart' ] |
|
299 | + $session_data = (array) $this->get('TXN_session_data'); |
|
300 | + return isset($session_data['cart']) && $session_data['cart'] instanceof EE_Cart |
|
301 | + ? $session_data['cart'] |
|
302 | 302 | : null; |
303 | 303 | } |
304 | 304 | |
@@ -311,8 +311,8 @@ discard block |
||
311 | 311 | * @throws \EE_Error |
312 | 312 | */ |
313 | 313 | public function session_data() { |
314 | - $session_data = $this->get( 'TXN_session_data' ); |
|
315 | - if ( empty( $session_data ) ) { |
|
314 | + $session_data = $this->get('TXN_session_data'); |
|
315 | + if (empty($session_data)) { |
|
316 | 316 | $session_data = array( |
317 | 317 | 'id' => null, |
318 | 318 | 'user_id' => null, |
@@ -335,11 +335,11 @@ discard block |
||
335 | 335 | * @param EE_Session|array $session_data |
336 | 336 | * @throws \EE_Error |
337 | 337 | */ |
338 | - public function set_txn_session_data( $session_data ) { |
|
339 | - if ( $session_data instanceof EE_Session ) { |
|
340 | - $this->set( 'TXN_session_data', $session_data->get_session_data( NULL, TRUE )); |
|
338 | + public function set_txn_session_data($session_data) { |
|
339 | + if ($session_data instanceof EE_Session) { |
|
340 | + $this->set('TXN_session_data', $session_data->get_session_data(NULL, TRUE)); |
|
341 | 341 | } else { |
342 | - $this->set( 'TXN_session_data', $session_data ); |
|
342 | + $this->set('TXN_session_data', $session_data); |
|
343 | 343 | } |
344 | 344 | } |
345 | 345 | |
@@ -352,7 +352,7 @@ discard block |
||
352 | 352 | * @throws \EE_Error |
353 | 353 | */ |
354 | 354 | public function hash_salt_() { |
355 | - return $this->get( 'TXN_hash_salt' ); |
|
355 | + return $this->get('TXN_hash_salt'); |
|
356 | 356 | } |
357 | 357 | |
358 | 358 | |
@@ -372,13 +372,13 @@ discard block |
||
372 | 372 | * @return string | int |
373 | 373 | * @throws \EE_Error |
374 | 374 | */ |
375 | - public function datetime( $format = FALSE, $gmt = FALSE ) { |
|
376 | - if ( $format ) { |
|
377 | - return $this->get_pretty( 'TXN_timestamp' ); |
|
378 | - } else if ( $gmt ) { |
|
379 | - return $this->get_raw( 'TXN_timestamp' ); |
|
375 | + public function datetime($format = FALSE, $gmt = FALSE) { |
|
376 | + if ($format) { |
|
377 | + return $this->get_pretty('TXN_timestamp'); |
|
378 | + } else if ($gmt) { |
|
379 | + return $this->get_raw('TXN_timestamp'); |
|
380 | 380 | } else { |
381 | - return $this->get( 'TXN_timestamp' ); |
|
381 | + return $this->get('TXN_timestamp'); |
|
382 | 382 | } |
383 | 383 | } |
384 | 384 | |
@@ -392,8 +392,8 @@ discard block |
||
392 | 392 | * @return EE_Registration[] |
393 | 393 | * @throws \EE_Error |
394 | 394 | */ |
395 | - public function registrations( $query_params = array(), $get_cached = FALSE ) { |
|
396 | - $query_params = ( empty( $query_params ) || ! is_array( $query_params ) ) |
|
395 | + public function registrations($query_params = array(), $get_cached = FALSE) { |
|
396 | + $query_params = (empty($query_params) || ! is_array($query_params)) |
|
397 | 397 | ? array( |
398 | 398 | 'order_by' => array( |
399 | 399 | 'Event.EVT_name' => 'ASC', |
@@ -403,7 +403,7 @@ discard block |
||
403 | 403 | ) |
404 | 404 | : $query_params; |
405 | 405 | $query_params = $get_cached ? array() : $query_params; |
406 | - return $this->get_many_related( 'Registration', $query_params ); |
|
406 | + return $this->get_many_related('Registration', $query_params); |
|
407 | 407 | } |
408 | 408 | |
409 | 409 | |
@@ -416,7 +416,7 @@ discard block |
||
416 | 416 | * @throws \EE_Error |
417 | 417 | */ |
418 | 418 | public function attendees() { |
419 | - return $this->get_many_related( 'Attendee', array( array( 'Registration.Transaction.TXN_ID' => $this->ID() ) ) ); |
|
419 | + return $this->get_many_related('Attendee', array(array('Registration.Transaction.TXN_ID' => $this->ID()))); |
|
420 | 420 | } |
421 | 421 | |
422 | 422 | |
@@ -428,8 +428,8 @@ discard block |
||
428 | 428 | * @return EE_Payment[] |
429 | 429 | * @throws \EE_Error |
430 | 430 | */ |
431 | - public function payments( $query_params = array() ) { |
|
432 | - return $this->get_many_related( 'Payment', $query_params ); |
|
431 | + public function payments($query_params = array()) { |
|
432 | + return $this->get_many_related('Payment', $query_params); |
|
433 | 433 | } |
434 | 434 | |
435 | 435 | |
@@ -441,8 +441,8 @@ discard block |
||
441 | 441 | * @throws \EE_Error |
442 | 442 | */ |
443 | 443 | public function approved_payments() { |
444 | - EE_Registry::instance()->load_model( 'Payment' ); |
|
445 | - return $this->get_many_related( 'Payment', array( array( 'STS_ID' => EEM_Payment::status_id_approved ), 'order_by' => array( 'PAY_timestamp' => 'DESC' ) ) ); |
|
444 | + EE_Registry::instance()->load_model('Payment'); |
|
445 | + return $this->get_many_related('Payment', array(array('STS_ID' => EEM_Payment::status_id_approved), 'order_by' => array('PAY_timestamp' => 'DESC'))); |
|
446 | 446 | } |
447 | 447 | |
448 | 448 | |
@@ -454,8 +454,8 @@ discard block |
||
454 | 454 | * @return string |
455 | 455 | * @throws \EE_Error |
456 | 456 | */ |
457 | - public function e_pretty_status( $show_icons = FALSE ) { |
|
458 | - echo $this->pretty_status( $show_icons ); |
|
457 | + public function e_pretty_status($show_icons = FALSE) { |
|
458 | + echo $this->pretty_status($show_icons); |
|
459 | 459 | } |
460 | 460 | |
461 | 461 | |
@@ -467,10 +467,10 @@ discard block |
||
467 | 467 | * @return string |
468 | 468 | * @throws \EE_Error |
469 | 469 | */ |
470 | - public function pretty_status( $show_icons = FALSE ) { |
|
471 | - $status = EEM_Status::instance()->localized_status( array( $this->status_ID() => __( 'unknown', 'event_espresso' ) ), FALSE, 'sentence' ); |
|
470 | + public function pretty_status($show_icons = FALSE) { |
|
471 | + $status = EEM_Status::instance()->localized_status(array($this->status_ID() => __('unknown', 'event_espresso')), FALSE, 'sentence'); |
|
472 | 472 | $icon = ''; |
473 | - switch ( $this->status_ID() ) { |
|
473 | + switch ($this->status_ID()) { |
|
474 | 474 | case EEM_Transaction::complete_status_code: |
475 | 475 | $icon = $show_icons ? '<span class="dashicons dashicons-yes ee-icon-size-24 green-text"></span>' : ''; |
476 | 476 | break; |
@@ -487,7 +487,7 @@ discard block |
||
487 | 487 | $icon = $show_icons ? '<span class="dashicons dashicons-plus ee-icon-size-16 orange-text"></span>' : ''; |
488 | 488 | break; |
489 | 489 | } |
490 | - return $icon . $status[ $this->status_ID() ]; |
|
490 | + return $icon.$status[$this->status_ID()]; |
|
491 | 491 | } |
492 | 492 | |
493 | 493 | |
@@ -499,7 +499,7 @@ discard block |
||
499 | 499 | * @throws \EE_Error |
500 | 500 | */ |
501 | 501 | public function status_ID() { |
502 | - return $this->get( 'STS_ID' ); |
|
502 | + return $this->get('STS_ID'); |
|
503 | 503 | } |
504 | 504 | |
505 | 505 | |
@@ -511,7 +511,7 @@ discard block |
||
511 | 511 | * @throws \EE_Error |
512 | 512 | */ |
513 | 513 | public function is_free() { |
514 | - return EEH_Money::compare_floats( $this->get( 'TXN_total' ), 0, '==' ); |
|
514 | + return EEH_Money::compare_floats($this->get('TXN_total'), 0, '=='); |
|
515 | 515 | } |
516 | 516 | |
517 | 517 | |
@@ -591,12 +591,12 @@ discard block |
||
591 | 591 | * @return string |
592 | 592 | * @throws \EE_Error |
593 | 593 | */ |
594 | - public function invoice_url( $type = 'html' ) { |
|
594 | + public function invoice_url($type = 'html') { |
|
595 | 595 | $REG = $this->primary_registration(); |
596 | - if ( ! $REG instanceof EE_Registration ) { |
|
596 | + if ( ! $REG instanceof EE_Registration) { |
|
597 | 597 | return ''; |
598 | 598 | } |
599 | - return $REG->invoice_url( $type ); |
|
599 | + return $REG->invoice_url($type); |
|
600 | 600 | } |
601 | 601 | |
602 | 602 | |
@@ -608,7 +608,7 @@ discard block |
||
608 | 608 | * @throws \EE_Error |
609 | 609 | */ |
610 | 610 | public function primary_registration() { |
611 | - return $this->get_first_related( 'Registration', array( array( 'REG_count' => EEM_Registration::PRIMARY_REGISTRANT_COUNT ) ) ); |
|
611 | + return $this->get_first_related('Registration', array(array('REG_count' => EEM_Registration::PRIMARY_REGISTRANT_COUNT))); |
|
612 | 612 | } |
613 | 613 | |
614 | 614 | |
@@ -620,12 +620,12 @@ discard block |
||
620 | 620 | * @return string |
621 | 621 | * @throws \EE_Error |
622 | 622 | */ |
623 | - public function receipt_url( $type = 'html' ) { |
|
623 | + public function receipt_url($type = 'html') { |
|
624 | 624 | $REG = $this->primary_registration(); |
625 | - if ( ! $REG instanceof EE_Registration ) { |
|
625 | + if ( ! $REG instanceof EE_Registration) { |
|
626 | 626 | return ''; |
627 | 627 | } |
628 | - return $REG->receipt_url( $type ); |
|
628 | + return $REG->receipt_url($type); |
|
629 | 629 | } |
630 | 630 | |
631 | 631 | |
@@ -653,15 +653,15 @@ discard block |
||
653 | 653 | * @return boolean |
654 | 654 | * @throws \EE_Error |
655 | 655 | */ |
656 | - public function update_based_on_payments(){ |
|
656 | + public function update_based_on_payments() { |
|
657 | 657 | EE_Error::doing_it_wrong( |
658 | - __CLASS__ . '::' . __FUNCTION__, |
|
659 | - sprintf( __( 'This method is deprecated. Please use "%s" instead', 'event_espresso' ), 'EE_Transaction_Processor::update_transaction_and_registrations_after_checkout_or_payment()' ), |
|
658 | + __CLASS__.'::'.__FUNCTION__, |
|
659 | + sprintf(__('This method is deprecated. Please use "%s" instead', 'event_espresso'), 'EE_Transaction_Processor::update_transaction_and_registrations_after_checkout_or_payment()'), |
|
660 | 660 | '4.6.0' |
661 | 661 | ); |
662 | 662 | /** @type EE_Transaction_Processor $transaction_processor */ |
663 | - $transaction_processor = EE_Registry::instance()->load_class( 'Transaction_Processor' ); |
|
664 | - return $transaction_processor->update_transaction_and_registrations_after_checkout_or_payment( $this ); |
|
663 | + $transaction_processor = EE_Registry::instance()->load_class('Transaction_Processor'); |
|
664 | + return $transaction_processor->update_transaction_and_registrations_after_checkout_or_payment($this); |
|
665 | 665 | } |
666 | 666 | |
667 | 667 | |
@@ -671,7 +671,7 @@ discard block |
||
671 | 671 | * @throws \EE_Error |
672 | 672 | */ |
673 | 673 | public function gateway_response_on_transaction() { |
674 | - $payment = $this->get_first_related( 'Payment' ); |
|
674 | + $payment = $this->get_first_related('Payment'); |
|
675 | 675 | return $payment instanceof EE_Payment ? $payment->gateway_response() : ''; |
676 | 676 | } |
677 | 677 | |
@@ -684,7 +684,7 @@ discard block |
||
684 | 684 | * @throws \EE_Error |
685 | 685 | */ |
686 | 686 | public function status_obj() { |
687 | - return $this->get_first_related( 'Status' ); |
|
687 | + return $this->get_first_related('Status'); |
|
688 | 688 | } |
689 | 689 | |
690 | 690 | |
@@ -696,8 +696,8 @@ discard block |
||
696 | 696 | * @return EE_Extra_Meta |
697 | 697 | * @throws \EE_Error |
698 | 698 | */ |
699 | - public function extra_meta( $query_params = array() ) { |
|
700 | - return $this->get_many_related( 'Extra_Meta', $query_params ); |
|
699 | + public function extra_meta($query_params = array()) { |
|
700 | + return $this->get_many_related('Extra_Meta', $query_params); |
|
701 | 701 | } |
702 | 702 | |
703 | 703 | |
@@ -709,8 +709,8 @@ discard block |
||
709 | 709 | * @return EE_Base_Class the relation was added to |
710 | 710 | * @throws \EE_Error |
711 | 711 | */ |
712 | - public function add_registration( EE_Registration $registration ) { |
|
713 | - return $this->_add_relation_to( $registration, 'Registration' ); |
|
712 | + public function add_registration(EE_Registration $registration) { |
|
713 | + return $this->_add_relation_to($registration, 'Registration'); |
|
714 | 714 | } |
715 | 715 | |
716 | 716 | |
@@ -723,8 +723,8 @@ discard block |
||
723 | 723 | * @return EE_Base_Class that was removed from being related |
724 | 724 | * @throws \EE_Error |
725 | 725 | */ |
726 | - public function remove_registration_with_id( $registration_or_id ) { |
|
727 | - return $this->_remove_relation_to( $registration_or_id, 'Registration' ); |
|
726 | + public function remove_registration_with_id($registration_or_id) { |
|
727 | + return $this->_remove_relation_to($registration_or_id, 'Registration'); |
|
728 | 728 | } |
729 | 729 | |
730 | 730 | |
@@ -736,7 +736,7 @@ discard block |
||
736 | 736 | * @throws \EE_Error |
737 | 737 | */ |
738 | 738 | public function items_purchased() { |
739 | - return $this->line_items( array( array( 'LIN_type' => EEM_Line_Item::type_line_item ) ) ); |
|
739 | + return $this->line_items(array(array('LIN_type' => EEM_Line_Item::type_line_item))); |
|
740 | 740 | } |
741 | 741 | |
742 | 742 | |
@@ -748,8 +748,8 @@ discard block |
||
748 | 748 | * @return EE_Base_Class the relation was added to |
749 | 749 | * @throws \EE_Error |
750 | 750 | */ |
751 | - public function add_line_item( EE_Line_Item $line_item ) { |
|
752 | - return $this->_add_relation_to( $line_item, 'Line_Item' ); |
|
751 | + public function add_line_item(EE_Line_Item $line_item) { |
|
752 | + return $this->_add_relation_to($line_item, 'Line_Item'); |
|
753 | 753 | } |
754 | 754 | |
755 | 755 | |
@@ -761,8 +761,8 @@ discard block |
||
761 | 761 | * @return EE_Line_Item[] |
762 | 762 | * @throws \EE_Error |
763 | 763 | */ |
764 | - public function line_items( $query_params = array() ) { |
|
765 | - return $this->get_many_related( 'Line_Item', $query_params ); |
|
764 | + public function line_items($query_params = array()) { |
|
765 | + return $this->get_many_related('Line_Item', $query_params); |
|
766 | 766 | } |
767 | 767 | |
768 | 768 | |
@@ -774,7 +774,7 @@ discard block |
||
774 | 774 | * @throws \EE_Error |
775 | 775 | */ |
776 | 776 | public function tax_items() { |
777 | - return $this->line_items( array( array( 'LIN_type' => EEM_Line_Item::type_tax ) ) ); |
|
777 | + return $this->line_items(array(array('LIN_type' => EEM_Line_Item::type_tax))); |
|
778 | 778 | } |
779 | 779 | |
780 | 780 | |
@@ -787,10 +787,10 @@ discard block |
||
787 | 787 | * @throws \EE_Error |
788 | 788 | */ |
789 | 789 | public function total_line_item() { |
790 | - $item = $this->get_first_related( 'Line_Item', array( array( 'LIN_type' => EEM_Line_Item::type_total ) ) ); |
|
791 | - if( ! $item ){ |
|
792 | - EE_Registry::instance()->load_helper( 'Line_Item' ); |
|
793 | - $item = EEH_Line_Item::create_total_line_item( $this ); |
|
790 | + $item = $this->get_first_related('Line_Item', array(array('LIN_type' => EEM_Line_Item::type_total))); |
|
791 | + if ( ! $item) { |
|
792 | + EE_Registry::instance()->load_helper('Line_Item'); |
|
793 | + $item = EEH_Line_Item::create_total_line_item($this); |
|
794 | 794 | } |
795 | 795 | return $item; |
796 | 796 | } |
@@ -806,10 +806,10 @@ discard block |
||
806 | 806 | */ |
807 | 807 | public function tax_total() { |
808 | 808 | $tax_line_item = $this->tax_total_line_item(); |
809 | - if ( $tax_line_item ) { |
|
810 | - return (float)$tax_line_item->total(); |
|
809 | + if ($tax_line_item) { |
|
810 | + return (float) $tax_line_item->total(); |
|
811 | 811 | } else { |
812 | - return (float)0; |
|
812 | + return (float) 0; |
|
813 | 813 | } |
814 | 814 | } |
815 | 815 | |
@@ -822,7 +822,7 @@ discard block |
||
822 | 822 | * @throws \EE_Error |
823 | 823 | */ |
824 | 824 | public function tax_total_line_item() { |
825 | - return EEH_Line_Item::get_taxes_subtotal( $this->total_line_item() ); |
|
825 | + return EEH_Line_Item::get_taxes_subtotal($this->total_line_item()); |
|
826 | 826 | } |
827 | 827 | |
828 | 828 | |
@@ -833,20 +833,20 @@ discard block |
||
833 | 833 | * @return EE_Form_Section_Proper |
834 | 834 | * @throws \EE_Error |
835 | 835 | */ |
836 | - public function billing_info(){ |
|
836 | + public function billing_info() { |
|
837 | 837 | $payment_method = $this->payment_method(); |
838 | - if ( !$payment_method){ |
|
838 | + if ( ! $payment_method) { |
|
839 | 839 | 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__); |
840 | 840 | return false; |
841 | 841 | } |
842 | 842 | $primary_reg = $this->primary_registration(); |
843 | - if ( ! $primary_reg ) { |
|
844 | - EE_Error::add_error( __( "Cannot get billing info for gateway %s on transaction because no primary registration exists", "event_espresso" ), __FILE__, __FUNCTION__, __LINE__ ); |
|
843 | + if ( ! $primary_reg) { |
|
844 | + EE_Error::add_error(__("Cannot get billing info for gateway %s on transaction because no primary registration exists", "event_espresso"), __FILE__, __FUNCTION__, __LINE__); |
|
845 | 845 | return FALSE; |
846 | 846 | } |
847 | 847 | $attendee = $primary_reg->attendee(); |
848 | - if ( ! $attendee ) { |
|
849 | - 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__ ); |
|
848 | + if ( ! $attendee) { |
|
849 | + 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__); |
|
850 | 850 | return FALSE; |
851 | 851 | } |
852 | 852 | return $attendee->billing_info_for_payment_method($payment_method); |
@@ -887,15 +887,15 @@ discard block |
||
887 | 887 | * @return EE_Payment_Method |
888 | 888 | * @throws \EE_Error |
889 | 889 | */ |
890 | - public function payment_method(){ |
|
890 | + public function payment_method() { |
|
891 | 891 | $pm = $this->get_first_related('Payment_Method'); |
892 | - if( $pm instanceof EE_Payment_Method ){ |
|
892 | + if ($pm instanceof EE_Payment_Method) { |
|
893 | 893 | return $pm; |
894 | - }else{ |
|
894 | + } else { |
|
895 | 895 | $last_payment = $this->last_payment(); |
896 | - if( $last_payment instanceof EE_Payment && $last_payment->payment_method() ){ |
|
896 | + if ($last_payment instanceof EE_Payment && $last_payment->payment_method()) { |
|
897 | 897 | return $last_payment->payment_method(); |
898 | - }else{ |
|
898 | + } else { |
|
899 | 899 | return NULL; |
900 | 900 | } |
901 | 901 | } |
@@ -910,7 +910,7 @@ discard block |
||
910 | 910 | * @throws \EE_Error |
911 | 911 | */ |
912 | 912 | public function last_payment() { |
913 | - return $this->get_first_related( 'Payment', array( 'order_by' => array( 'PAY_ID' => 'desc' ) ) ); |
|
913 | + return $this->get_first_related('Payment', array('order_by' => array('PAY_ID' => 'desc'))); |
|
914 | 914 | } |
915 | 915 | |
916 | 916 | |
@@ -921,8 +921,8 @@ discard block |
||
921 | 921 | * @return EE_Line_Item[] |
922 | 922 | * @throws \EE_Error |
923 | 923 | */ |
924 | - public function non_ticket_line_items(){ |
|
925 | - return EEM_Line_Item::instance()->get_all_non_ticket_line_items_for_transaction( $this->ID() ); |
|
924 | + public function non_ticket_line_items() { |
|
925 | + return EEM_Line_Item::instance()->get_all_non_ticket_line_items_for_transaction($this->ID()); |
|
926 | 926 | } |
927 | 927 | |
928 | 928 |
@@ -68,7 +68,7 @@ discard block |
||
68 | 68 | * @return EEG_Paypal_Standard |
69 | 69 | */ |
70 | 70 | public function __construct() { |
71 | - $this->set_uses_separate_IPN_request( true ) ; |
|
71 | + $this->set_uses_separate_IPN_request(true); |
|
72 | 72 | parent::__construct(); |
73 | 73 | } |
74 | 74 | |
@@ -78,7 +78,7 @@ discard block |
||
78 | 78 | * Also sets the gateway url class variable based on whether debug mode is enabled or not |
79 | 79 | * @param array $settings_array |
80 | 80 | */ |
81 | - public function set_settings($settings_array){ |
|
81 | + public function set_settings($settings_array) { |
|
82 | 82 | parent::set_settings($settings_array); |
83 | 83 | $this->_gateway_url = $this->_debug_mode |
84 | 84 | ? 'https://www.sandbox.paypal.com/cgi-bin/webscr' |
@@ -114,42 +114,42 @@ discard block |
||
114 | 114 | |
115 | 115 | $total_discounts_to_cart_total = $transaction->paid(); |
116 | 116 | //only itemize the order if we're paying for the rest of the order's amount |
117 | - if( EEH_Money::compare_floats( $payment->amount(), $transaction->total(), '==' ) ) { |
|
118 | - $payment->update_extra_meta( EEG_Paypal_Standard::itemized_payment_option_name, true ); |
|
117 | + if (EEH_Money::compare_floats($payment->amount(), $transaction->total(), '==')) { |
|
118 | + $payment->update_extra_meta(EEG_Paypal_Standard::itemized_payment_option_name, true); |
|
119 | 119 | //this payment is for the remaining transaction amount, |
120 | 120 | //keep track of exactly how much the itemized order amount equals |
121 | 121 | $itemized_sum = 0; |
122 | 122 | $shipping_previously_added = 0; |
123 | 123 | //so let's show all the line items |
124 | - foreach($total_line_item->get_items() as $line_item){ |
|
125 | - if ( $line_item instanceof EE_Line_Item ) { |
|
124 | + foreach ($total_line_item->get_items() as $line_item) { |
|
125 | + if ($line_item instanceof EE_Line_Item) { |
|
126 | 126 | //it's some kind of discount |
127 | - if( $line_item->total() < 0 ) { |
|
128 | - $total_discounts_to_cart_total += abs( $line_item->total() ); |
|
127 | + if ($line_item->total() < 0) { |
|
128 | + $total_discounts_to_cart_total += abs($line_item->total()); |
|
129 | 129 | $itemized_sum += $line_item->total(); |
130 | 130 | continue; |
131 | 131 | } |
132 | 132 | //dont include shipping again. |
133 | - if( strpos( $line_item->code(), 'paypal_shipping_') === 0 ) { |
|
133 | + if (strpos($line_item->code(), 'paypal_shipping_') === 0) { |
|
134 | 134 | $shipping_previously_added = $line_item->total(); |
135 | 135 | continue; |
136 | 136 | } |
137 | - $redirect_args[ 'item_name_' . $item_num ] = substr( |
|
138 | - sprintf( _x( '%1$s for %2$s', 'Ticket for Event', 'event_espresso' ), $line_item->name(), $line_item->ticket_event_name() ), |
|
137 | + $redirect_args['item_name_'.$item_num] = substr( |
|
138 | + sprintf(_x('%1$s for %2$s', 'Ticket for Event', 'event_espresso'), $line_item->name(), $line_item->ticket_event_name()), |
|
139 | 139 | 0, 127 |
140 | 140 | ); |
141 | - $redirect_args[ 'amount_' . $item_num ] = $line_item->unit_price(); |
|
142 | - $redirect_args[ 'quantity_' . $item_num ] = $line_item->quantity(); |
|
141 | + $redirect_args['amount_'.$item_num] = $line_item->unit_price(); |
|
142 | + $redirect_args['quantity_'.$item_num] = $line_item->quantity(); |
|
143 | 143 | //if we're not letting PayPal calculate shipping, tell them its 0 |
144 | - if ( ! $this->_paypal_shipping ) { |
|
145 | - $redirect_args[ 'shipping_' . $item_num ] = '0'; |
|
146 | - $redirect_args[ 'shipping2_' . $item_num ] = '0'; |
|
144 | + if ( ! $this->_paypal_shipping) { |
|
145 | + $redirect_args['shipping_'.$item_num] = '0'; |
|
146 | + $redirect_args['shipping2_'.$item_num] = '0'; |
|
147 | 147 | } |
148 | 148 | $item_num++; |
149 | 149 | $itemized_sum += $line_item->total(); |
150 | 150 | } |
151 | 151 | } |
152 | - $taxes_li = $this->_line_item->get_taxes_subtotal( $total_line_item ); |
|
152 | + $taxes_li = $this->_line_item->get_taxes_subtotal($total_line_item); |
|
153 | 153 | //ideally itemized sum equals the transaction total. but if not (which is weird) |
154 | 154 | //and the itemized sum is LESS than the transaction total |
155 | 155 | //add another line item |
@@ -159,47 +159,47 @@ discard block |
||
159 | 159 | $transaction->total() - $itemized_sum - $taxes_li->total() - $shipping_previously_added, |
160 | 160 | 2 |
161 | 161 | ); |
162 | - if( $itemized_sum_diff_from_txn_total < 0 ) { |
|
162 | + if ($itemized_sum_diff_from_txn_total < 0) { |
|
163 | 163 | //itemized sum is too big |
164 | - $total_discounts_to_cart_total += abs( $itemized_sum_diff_from_txn_total ); |
|
165 | - } elseif( $itemized_sum_diff_from_txn_total > 0 ) { |
|
166 | - $redirect_args[ 'item_name_' . $item_num ] = substr( |
|
167 | - __( 'Other charges', 'event_espresso' ), 0, 127 ); |
|
168 | - $redirect_args[ 'amount_' . $item_num ] = $this->format_currency( $itemized_sum_diff_from_txn_total ); |
|
169 | - $redirect_args[ 'quantity_' . $item_num ] = 1; |
|
164 | + $total_discounts_to_cart_total += abs($itemized_sum_diff_from_txn_total); |
|
165 | + } elseif ($itemized_sum_diff_from_txn_total > 0) { |
|
166 | + $redirect_args['item_name_'.$item_num] = substr( |
|
167 | + __('Other charges', 'event_espresso'), 0, 127 ); |
|
168 | + $redirect_args['amount_'.$item_num] = $this->format_currency($itemized_sum_diff_from_txn_total); |
|
169 | + $redirect_args['quantity_'.$item_num] = 1; |
|
170 | 170 | $item_num++; |
171 | 171 | } |
172 | - if( $total_discounts_to_cart_total > 0 ) { |
|
173 | - $redirect_args[ 'discount_amount_cart' ] = $this->format_currency( $total_discounts_to_cart_total ); |
|
172 | + if ($total_discounts_to_cart_total > 0) { |
|
173 | + $redirect_args['discount_amount_cart'] = $this->format_currency($total_discounts_to_cart_total); |
|
174 | 174 | } |
175 | 175 | //add our taxes to the order if we're NOT using PayPal's |
176 | - if( ! $this->_paypal_taxes ){ |
|
176 | + if ( ! $this->_paypal_taxes) { |
|
177 | 177 | $redirect_args['tax_cart'] = $total_line_item->get_total_tax(); |
178 | 178 | } |
179 | 179 | } else { |
180 | - $payment->update_extra_meta( EEG_Paypal_Standard::itemized_payment_option_name, false ); |
|
180 | + $payment->update_extra_meta(EEG_Paypal_Standard::itemized_payment_option_name, false); |
|
181 | 181 | //partial payment that's not for the remaining amount, so we can't send an itemized list |
182 | - $redirect_args['item_name_' . $item_num] = substr( |
|
183 | - sprintf( __('Payment of %1$s for %2$s', "event_espresso"), $payment->amount(), $primary_registrant->reg_code() ), |
|
182 | + $redirect_args['item_name_'.$item_num] = substr( |
|
183 | + sprintf(__('Payment of %1$s for %2$s', "event_espresso"), $payment->amount(), $primary_registrant->reg_code()), |
|
184 | 184 | 0, 127 |
185 | 185 | ); |
186 | - $redirect_args['amount_' . $item_num] = $payment->amount(); |
|
187 | - $redirect_args['shipping_' . $item_num ] = '0'; |
|
188 | - $redirect_args['shipping2_' . $item_num ] = '0'; |
|
186 | + $redirect_args['amount_'.$item_num] = $payment->amount(); |
|
187 | + $redirect_args['shipping_'.$item_num] = '0'; |
|
188 | + $redirect_args['shipping2_'.$item_num] = '0'; |
|
189 | 189 | $redirect_args['tax_cart'] = '0'; |
190 | 190 | $item_num++; |
191 | 191 | } |
192 | 192 | |
193 | - if($this->_debug_mode){ |
|
194 | - $redirect_args['item_name_' . $item_num] = 'DEBUG INFO (this item only added in sandbox mode'; |
|
195 | - $redirect_args['amount_' . $item_num] = 0; |
|
193 | + if ($this->_debug_mode) { |
|
194 | + $redirect_args['item_name_'.$item_num] = 'DEBUG INFO (this item only added in sandbox mode'; |
|
195 | + $redirect_args['amount_'.$item_num] = 0; |
|
196 | 196 | $redirect_args['on0_'.$item_num] = 'NOTIFY URL'; |
197 | - $redirect_args['os0_' . $item_num] = $notify_url; |
|
197 | + $redirect_args['os0_'.$item_num] = $notify_url; |
|
198 | 198 | $redirect_args['on1_'.$item_num] = 'RETURN URL'; |
199 | - $redirect_args['os1_' . $item_num] = $return_url; |
|
199 | + $redirect_args['os1_'.$item_num] = $return_url; |
|
200 | 200 | // $redirect_args['option_index_' . $item_num] = 1; // <-- dunno if this is needed ? |
201 | - $redirect_args['shipping_' . $item_num ] = '0'; |
|
202 | - $redirect_args['shipping2_' . $item_num ] = '0'; |
|
201 | + $redirect_args['shipping_'.$item_num] = '0'; |
|
202 | + $redirect_args['shipping2_'.$item_num] = '0'; |
|
203 | 203 | } |
204 | 204 | |
205 | 205 | $redirect_args['business'] = $this->_paypal_id; |
@@ -209,14 +209,14 @@ discard block |
||
209 | 209 | $redirect_args['cmd'] = '_cart'; |
210 | 210 | $redirect_args['upload'] = 1; |
211 | 211 | $redirect_args['currency_code'] = $payment->currency_code(); |
212 | - $redirect_args['rm'] = 2;//makes the user return with method=POST |
|
213 | - if($this->_image_url){ |
|
212 | + $redirect_args['rm'] = 2; //makes the user return with method=POST |
|
213 | + if ($this->_image_url) { |
|
214 | 214 | $redirect_args['image_url'] = $this->_image_url; |
215 | 215 | } |
216 | 216 | $redirect_args['no_shipping'] = $this->_shipping_details; |
217 | - $redirect_args['bn'] = 'EventEspresso_SP';//EE will blow up if you change this |
|
217 | + $redirect_args['bn'] = 'EventEspresso_SP'; //EE will blow up if you change this |
|
218 | 218 | |
219 | - $redirect_args = apply_filters( "FHEE__EEG_Paypal_Standard__set_redirection_info__arguments", $redirect_args, $this ); |
|
219 | + $redirect_args = apply_filters("FHEE__EEG_Paypal_Standard__set_redirection_info__arguments", $redirect_args, $this); |
|
220 | 220 | |
221 | 221 | $payment->set_redirect_url($this->_gateway_url); |
222 | 222 | $payment->set_redirect_args($redirect_args); |
@@ -224,7 +224,7 @@ discard block |
||
224 | 224 | $this->log( |
225 | 225 | array( |
226 | 226 | 'message' => sprintf( |
227 | - __( 'PayPal payment request initiated.', 'event_espresso' ) |
|
227 | + __('PayPal payment request initiated.', 'event_espresso') |
|
228 | 228 | ), |
229 | 229 | 'transaction' => $transaction->model_field_array(), |
230 | 230 | ), |
@@ -244,14 +244,14 @@ discard block |
||
244 | 244 | * @return \EEI_Payment updated |
245 | 245 | * @throws \EE_Error |
246 | 246 | */ |
247 | - public function handle_payment_update( $update_info, $transaction ){ |
|
247 | + public function handle_payment_update($update_info, $transaction) { |
|
248 | 248 | // verify there's payment data that's been sent |
249 | - if ( empty( $update_info[ 'payment_status' ] ) || empty( $update_info[ 'txn_id' ] ) ) { |
|
249 | + if (empty($update_info['payment_status']) || empty($update_info['txn_id'])) { |
|
250 | 250 | // log the results |
251 | 251 | $this->log( |
252 | 252 | array( |
253 | 253 | 'message' => sprintf( |
254 | - __( 'PayPal IPN response is missing critical payment data. This may indicate a PDT request and require your PayPal account settings to be corrected.', 'event_espresso' ) |
|
254 | + __('PayPal IPN response is missing critical payment data. This may indicate a PDT request and require your PayPal account settings to be corrected.', 'event_espresso') |
|
255 | 255 | ), |
256 | 256 | 'update_info' => $update_info, |
257 | 257 | ), |
@@ -259,50 +259,50 @@ discard block |
||
259 | 259 | ); |
260 | 260 | // waaaait... is this a PDT request? (see https://developer.paypal.com/docs/classic/products/payment-data-transfer/) |
261 | 261 | // indicated by the "tx" argument? If so, we don't need it. We'll just use the IPN data when it comes |
262 | - if ( isset( $update_info[ 'tx' ] ) ) { |
|
262 | + if (isset($update_info['tx'])) { |
|
263 | 263 | return $transaction->last_payment(); |
264 | 264 | } else { |
265 | 265 | return null; |
266 | 266 | } |
267 | 267 | } |
268 | - $payment = $this->_pay_model->get_payment_by_txn_id_chq_nmbr( $update_info[ 'txn_id' ] ); |
|
269 | - if ( ! $payment instanceof EEI_Payment ) { |
|
268 | + $payment = $this->_pay_model->get_payment_by_txn_id_chq_nmbr($update_info['txn_id']); |
|
269 | + if ( ! $payment instanceof EEI_Payment) { |
|
270 | 270 | $payment = $transaction->last_payment(); |
271 | 271 | } |
272 | 272 | // ok, then validate the IPN. Even if we've already processed this payment, |
273 | 273 | // let PayPal know we don't want to hear from them anymore! |
274 | - if ( ! $this->validate_ipn( $update_info, $payment ) ) { |
|
274 | + if ( ! $this->validate_ipn($update_info, $payment)) { |
|
275 | 275 | return $payment; |
276 | 276 | } |
277 | 277 | //ok, well let's process this payment then! |
278 | - switch ( $update_info[ 'payment_status' ] ) { |
|
278 | + switch ($update_info['payment_status']) { |
|
279 | 279 | |
280 | 280 | case 'Completed' : |
281 | 281 | $status = $this->_pay_model->approved_status(); |
282 | - $gateway_response = __( 'The payment is approved.', 'event_espresso' ); |
|
282 | + $gateway_response = __('The payment is approved.', 'event_espresso'); |
|
283 | 283 | break; |
284 | 284 | |
285 | 285 | case 'Pending' : |
286 | 286 | $status = $this->_pay_model->pending_status(); |
287 | - $gateway_response = __( 'The payment is in progress. Another message will be sent when payment is approved.', 'event_espresso' ); |
|
287 | + $gateway_response = __('The payment is in progress. Another message will be sent when payment is approved.', 'event_espresso'); |
|
288 | 288 | break; |
289 | 289 | |
290 | 290 | case 'Denied' : |
291 | 291 | $status = $this->_pay_model->declined_status(); |
292 | - $gateway_response = __( 'The payment has been declined.', 'event_espresso' ); |
|
292 | + $gateway_response = __('The payment has been declined.', 'event_espresso'); |
|
293 | 293 | break; |
294 | 294 | |
295 | 295 | case 'Expired' : |
296 | 296 | case 'Failed' : |
297 | 297 | $status = $this->_pay_model->failed_status(); |
298 | - $gateway_response = __( 'The payment failed for technical reasons or expired.', 'event_espresso' ); |
|
298 | + $gateway_response = __('The payment failed for technical reasons or expired.', 'event_espresso'); |
|
299 | 299 | break; |
300 | 300 | |
301 | 301 | case 'Refunded' : |
302 | 302 | case 'Partially_Refunded' : |
303 | 303 | // even though it's a refund, we consider the payment as approved, it just has a negative value |
304 | 304 | $status = $this->_pay_model->approved_status(); |
305 | - $gateway_response = __( 'The payment has been refunded. Please update registrations accordingly.', 'event_espresso' ); |
|
305 | + $gateway_response = __('The payment has been refunded. Please update registrations accordingly.', 'event_espresso'); |
|
306 | 306 | break; |
307 | 307 | |
308 | 308 | case 'Voided' : |
@@ -310,28 +310,28 @@ discard block |
||
310 | 310 | case 'Canceled_Reversal' : |
311 | 311 | default : |
312 | 312 | $status = $this->_pay_model->cancelled_status(); |
313 | - $gateway_response = __( 'The payment was cancelled, reversed, or voided. Please update registrations accordingly.', 'event_espresso' ); |
|
313 | + $gateway_response = __('The payment was cancelled, reversed, or voided. Please update registrations accordingly.', 'event_espresso'); |
|
314 | 314 | break; |
315 | 315 | |
316 | 316 | } |
317 | 317 | |
318 | 318 | //check if we've already processed this payment |
319 | - if ( $payment instanceof EEI_Payment ) { |
|
319 | + if ($payment instanceof EEI_Payment) { |
|
320 | 320 | //payment exists. if this has the exact same status and amount, don't bother updating. just return |
321 | - if ( $payment->status() === $status && (float)$payment->amount() === (float)$update_info[ 'mc_gross' ] ) { |
|
321 | + if ($payment->status() === $status && (float) $payment->amount() === (float) $update_info['mc_gross']) { |
|
322 | 322 | // DUPLICATED IPN! dont bother updating transaction foo!; |
323 | 323 | $message_log = sprintf( |
324 | - __( 'It appears we have received a duplicate IPN from PayPal for payment %d', 'event_espresso' ), |
|
324 | + __('It appears we have received a duplicate IPN from PayPal for payment %d', 'event_espresso'), |
|
325 | 325 | $payment->ID() |
326 | 326 | ); |
327 | 327 | } else { |
328 | 328 | // new payment yippee !!! |
329 | - $payment->set_status( $status ); |
|
330 | - $payment->set_amount( (float)$update_info[ 'mc_gross' ] ); |
|
331 | - $payment->set_gateway_response( $gateway_response ); |
|
332 | - $payment->set_details( $update_info ); |
|
333 | - $payment->set_txn_id_chq_nmbr( $update_info[ 'txn_id' ] ); |
|
334 | - $message_log = __( 'Updated payment either from IPN or as part of POST from PayPal', 'event_espresso' ); |
|
329 | + $payment->set_status($status); |
|
330 | + $payment->set_amount((float) $update_info['mc_gross']); |
|
331 | + $payment->set_gateway_response($gateway_response); |
|
332 | + $payment->set_details($update_info); |
|
333 | + $payment->set_txn_id_chq_nmbr($update_info['txn_id']); |
|
334 | + $message_log = __('Updated payment either from IPN or as part of POST from PayPal', 'event_espresso'); |
|
335 | 335 | } |
336 | 336 | $this->log( |
337 | 337 | array( |
@@ -343,16 +343,16 @@ discard block |
||
343 | 343 | $payment |
344 | 344 | ); |
345 | 345 | } |
346 | - do_action( 'FHEE__EEG_Paypal_Standard__handle_payment_update__payment_processed', $payment, $this ); |
|
346 | + do_action('FHEE__EEG_Paypal_Standard__handle_payment_update__payment_processed', $payment, $this); |
|
347 | 347 | // kill request here if this is a refund |
348 | 348 | if ( |
349 | 349 | ( |
350 | - $update_info[ 'payment_status' ] === 'Refunded' |
|
351 | - || $update_info[ 'payment_status' ] === 'Partially_Refunded' |
|
350 | + $update_info['payment_status'] === 'Refunded' |
|
351 | + || $update_info['payment_status'] === 'Partially_Refunded' |
|
352 | 352 | ) |
353 | - && apply_filters( 'FHEE__EEG_Paypal_Standard__handle_payment_update__kill_refund_request', true ) |
|
353 | + && apply_filters('FHEE__EEG_Paypal_Standard__handle_payment_update__kill_refund_request', true) |
|
354 | 354 | ) { |
355 | - status_header( 200 ); |
|
355 | + status_header(200); |
|
356 | 356 | exit(); |
357 | 357 | } |
358 | 358 | return $payment; |
@@ -369,9 +369,9 @@ discard block |
||
369 | 369 | * @return boolean |
370 | 370 | * @throws \EE_Error |
371 | 371 | */ |
372 | - public function validate_ipn( $update_info, $payment ) { |
|
372 | + public function validate_ipn($update_info, $payment) { |
|
373 | 373 | //allow us to skip validating IPNs with PayPal (useful for testing) |
374 | - if ( apply_filters( 'FHEE__EEG_Paypal_Standard__validate_ipn__skip', false ) ) { |
|
374 | + if (apply_filters('FHEE__EEG_Paypal_Standard__validate_ipn__skip', false)) { |
|
375 | 375 | return true; |
376 | 376 | } |
377 | 377 | //...otherwise, we actually don't care what the $update_info is, we need to look |
@@ -379,22 +379,22 @@ discard block |
||
379 | 379 | // Reading POSTed data directly from $_POST causes serialization issues with array data in the POST. |
380 | 380 | // Instead, read raw POST data from the input stream. |
381 | 381 | // @see https://gist.github.com/xcommerce-gists/3440401 |
382 | - $raw_post_data = file_get_contents( 'php://input' ); |
|
383 | - $raw_post_array = explode( '&', $raw_post_data ); |
|
382 | + $raw_post_data = file_get_contents('php://input'); |
|
383 | + $raw_post_array = explode('&', $raw_post_data); |
|
384 | 384 | $update_info = array(); |
385 | - foreach ( $raw_post_array as $keyval ) { |
|
386 | - $keyval = explode( '=', $keyval ); |
|
387 | - if ( count( $keyval ) === 2 ) { |
|
388 | - $update_info[ $keyval[ 0 ] ] = urldecode( $keyval[ 1 ] ); |
|
385 | + foreach ($raw_post_array as $keyval) { |
|
386 | + $keyval = explode('=', $keyval); |
|
387 | + if (count($keyval) === 2) { |
|
388 | + $update_info[$keyval[0]] = urldecode($keyval[1]); |
|
389 | 389 | } |
390 | 390 | } |
391 | 391 | // read the IPN message sent from PayPal and prepend 'cmd=_notify-validate' |
392 | 392 | $req = 'cmd=_notify-validate'; |
393 | - $uses_get_magic_quotes = function_exists( 'get_magic_quotes_gpc' ) && get_magic_quotes_gpc() === 1 |
|
393 | + $uses_get_magic_quotes = function_exists('get_magic_quotes_gpc') && get_magic_quotes_gpc() === 1 |
|
394 | 394 | ? true |
395 | 395 | : false; |
396 | - foreach ( $update_info as $key => $value ) { |
|
397 | - $value = $uses_get_magic_quotes ? urlencode( stripslashes( $value ) ) : urlencode( $value ); |
|
396 | + foreach ($update_info as $key => $value) { |
|
397 | + $value = $uses_get_magic_quotes ? urlencode(stripslashes($value)) : urlencode($value); |
|
398 | 398 | $req .= "&$key=$value"; |
399 | 399 | } |
400 | 400 | // HTTP POST the complete, unaltered IPN back to PayPal |
@@ -403,38 +403,38 @@ discard block |
||
403 | 403 | array( |
404 | 404 | 'body' => $req, |
405 | 405 | 'sslverify' => false, |
406 | - 'timeout' => 60 , |
|
406 | + 'timeout' => 60, |
|
407 | 407 | // make sure to set a site specific unique "user-agent" string since the WordPres default gets declined by PayPal |
408 | 408 | // plz see: https://github.com/websharks/s2member/issues/610 |
409 | - 'user-agent' => 'Event Espresso v' . EVENT_ESPRESSO_VERSION . '; ' . home_url(), |
|
409 | + 'user-agent' => 'Event Espresso v'.EVENT_ESPRESSO_VERSION.'; '.home_url(), |
|
410 | 410 | 'httpversion' => '1.1' |
411 | 411 | ) |
412 | 412 | ); |
413 | 413 | // then check the response |
414 | 414 | if ( |
415 | - array_key_exists( 'body', $response ) |
|
416 | - && ! is_wp_error( $response ) |
|
417 | - && strcmp( $response[ 'body' ], "VERIFIED" ) === 0 |
|
415 | + array_key_exists('body', $response) |
|
416 | + && ! is_wp_error($response) |
|
417 | + && strcmp($response['body'], "VERIFIED") === 0 |
|
418 | 418 | ) { |
419 | 419 | return true; |
420 | 420 | } |
421 | 421 | // huh, something's wack... the IPN didn't validate. We must have replied to the IPN incorrectly, |
422 | 422 | // or their API must have changed: http://www.paypalobjects.com/en_US/ebook/PP_OrderManagement_IntegrationGuide/ipn.html |
423 | - if( $response instanceof WP_Error ) { |
|
423 | + if ($response instanceof WP_Error) { |
|
424 | 424 | $error_msg = sprintf( |
425 | - __( 'WP Error. Code: "%1$s", Message: "%2$s", Data: "%3$s"', 'event_espresso' ), |
|
425 | + __('WP Error. Code: "%1$s", Message: "%2$s", Data: "%3$s"', 'event_espresso'), |
|
426 | 426 | $response->get_error_code(), |
427 | 427 | $response->get_error_message(), |
428 | - print_r( $response->get_error_data(), true ) |
|
428 | + print_r($response->get_error_data(), true) |
|
429 | 429 | ); |
430 | - } elseif( is_array( $response ) && isset( $response[ 'body' ] ) ) { |
|
431 | - $error_msg = $response[ 'body' ]; |
|
430 | + } elseif (is_array($response) && isset($response['body'])) { |
|
431 | + $error_msg = $response['body']; |
|
432 | 432 | } else { |
433 | - $error_msg = print_r( $response, true ); |
|
433 | + $error_msg = print_r($response, true); |
|
434 | 434 | } |
435 | - $payment->set_gateway_response( sprintf( __( "IPN Validation failed! Paypal responded with '%s'", "event_espresso" ), $error_msg ) ); |
|
436 | - $payment->set_details( array( 'REQUEST' => $update_info, 'VALIDATION_RESPONSE' => $response ) ); |
|
437 | - $payment->set_status( EEM_Payment::status_id_failed ); |
|
435 | + $payment->set_gateway_response(sprintf(__("IPN Validation failed! Paypal responded with '%s'", "event_espresso"), $error_msg)); |
|
436 | + $payment->set_details(array('REQUEST' => $update_info, 'VALIDATION_RESPONSE' => $response)); |
|
437 | + $payment->set_status(EEM_Payment::status_id_failed); |
|
438 | 438 | // log the results |
439 | 439 | $this->log( |
440 | 440 | array( |
@@ -455,9 +455,9 @@ discard block |
||
455 | 455 | */ |
456 | 456 | protected function _process_response_url() { |
457 | 457 | EE_Registry::instance()->load_helper('URL'); |
458 | - if ( isset( $_SERVER[ 'HTTP_HOST' ], $_SERVER[ 'REQUEST_URI' ] ) ) { |
|
458 | + if (isset($_SERVER['HTTP_HOST'], $_SERVER['REQUEST_URI'])) { |
|
459 | 459 | $url = is_ssl() ? 'https://' : 'http://'; |
460 | - $url .= EEH_URL::filter_input_server_url( 'HTTP_HOST' ); |
|
460 | + $url .= EEH_URL::filter_input_server_url('HTTP_HOST'); |
|
461 | 461 | $url .= EEH_URL::filter_input_server_url(); |
462 | 462 | } else { |
463 | 463 | $url = 'unknown'; |
@@ -474,12 +474,12 @@ discard block |
||
474 | 474 | * @param EEI_Payment $payment |
475 | 475 | * @throws \EE_Error |
476 | 476 | */ |
477 | - public function update_txn_based_on_payment( $payment ) { |
|
477 | + public function update_txn_based_on_payment($payment) { |
|
478 | 478 | $update_info = $payment->details(); |
479 | 479 | /** @var EE_Transaction $transaction */ |
480 | 480 | $transaction = $payment->transaction(); |
481 | - $payment_was_itemized = $payment->get_extra_meta( EEG_Paypal_Standard::itemized_payment_option_name, true, false ); |
|
482 | - if( ! $transaction ){ |
|
481 | + $payment_was_itemized = $payment->get_extra_meta(EEG_Paypal_Standard::itemized_payment_option_name, true, false); |
|
482 | + if ( ! $transaction) { |
|
483 | 483 | $this->log( |
484 | 484 | __( |
485 | 485 | 'Payment with ID %d has no related transaction, and so update_txn_based_on_payment couldn\'t be executed properly', |
@@ -489,10 +489,10 @@ discard block |
||
489 | 489 | ); |
490 | 490 | return; |
491 | 491 | } |
492 | - if( |
|
493 | - ! is_array( $update_info ) |
|
494 | - || ! isset( $update_info[ 'mc_shipping' ] ) |
|
495 | - || ! isset( $update_info[ 'tax' ] ) |
|
492 | + if ( |
|
493 | + ! is_array($update_info) |
|
494 | + || ! isset($update_info['mc_shipping']) |
|
495 | + || ! isset($update_info['tax']) |
|
496 | 496 | ) { |
497 | 497 | $this->log( |
498 | 498 | array( |
@@ -507,7 +507,7 @@ discard block |
||
507 | 507 | ); |
508 | 508 | return; |
509 | 509 | } |
510 | - if( $payment->status() !== $this->_pay_model->approved_status() ) { |
|
510 | + if ($payment->status() !== $this->_pay_model->approved_status()) { |
|
511 | 511 | $this->log( |
512 | 512 | array( |
513 | 513 | 'message' => __( |
@@ -526,44 +526,44 @@ discard block |
||
526 | 526 | $transaction_total_line_item = $transaction->total_line_item(); |
527 | 527 | |
528 | 528 | //might paypal have changed the taxes? |
529 | - if( $this->_paypal_taxes && $payment_was_itemized ) { |
|
529 | + if ($this->_paypal_taxes && $payment_was_itemized) { |
|
530 | 530 | // note that we're doing this BEFORE adding shipping; |
531 | 531 | // we actually want PayPal's shipping to remain non-taxable |
532 | - $this->_line_item->set_line_items_taxable( $transaction_total_line_item, true, 'paypal_shipping' ); |
|
532 | + $this->_line_item->set_line_items_taxable($transaction_total_line_item, true, 'paypal_shipping'); |
|
533 | 533 | $this->_line_item->set_total_tax_to( |
534 | 534 | $transaction_total_line_item, |
535 | - (float)$update_info['tax'], |
|
536 | - __( 'Taxes', 'event_espresso' ), |
|
537 | - __( 'Calculated by Paypal', 'event_espresso' ), |
|
535 | + (float) $update_info['tax'], |
|
536 | + __('Taxes', 'event_espresso'), |
|
537 | + __('Calculated by Paypal', 'event_espresso'), |
|
538 | 538 | 'paypal_tax' |
539 | 539 | ); |
540 | 540 | $grand_total_needs_resaving = TRUE; |
541 | 541 | } |
542 | 542 | |
543 | - $shipping_amount = (float)$update_info[ 'mc_shipping' ]; |
|
543 | + $shipping_amount = (float) $update_info['mc_shipping']; |
|
544 | 544 | //might paypal have added shipping? |
545 | - if( $this->_paypal_shipping && $shipping_amount && $payment_was_itemized ){ |
|
545 | + if ($this->_paypal_shipping && $shipping_amount && $payment_was_itemized) { |
|
546 | 546 | $this->_line_item->add_unrelated_item( |
547 | 547 | $transaction_total_line_item, |
548 | - sprintf( __('Shipping for transaction %1$s', 'event_espresso'), $transaction->ID() ), |
|
548 | + sprintf(__('Shipping for transaction %1$s', 'event_espresso'), $transaction->ID()), |
|
549 | 549 | $shipping_amount, |
550 | 550 | __('Shipping charges calculated by Paypal', 'event_espresso'), |
551 | 551 | 1, |
552 | 552 | false, |
553 | - 'paypal_shipping_' . $transaction->ID() |
|
553 | + 'paypal_shipping_'.$transaction->ID() |
|
554 | 554 | ); |
555 | 555 | $grand_total_needs_resaving = true; |
556 | 556 | } |
557 | 557 | |
558 | - if( $grand_total_needs_resaving ){ |
|
559 | - $transaction_total_line_item->save_this_and_descendants_to_txn( $transaction->ID() ); |
|
558 | + if ($grand_total_needs_resaving) { |
|
559 | + $transaction_total_line_item->save_this_and_descendants_to_txn($transaction->ID()); |
|
560 | 560 | /** @var EE_Registration_Processor $registration_processor */ |
561 | - $registration_processor = EE_Registry::instance()->load_class( 'Registration_Processor' ); |
|
562 | - $registration_processor->update_registration_final_prices( $transaction ); |
|
561 | + $registration_processor = EE_Registry::instance()->load_class('Registration_Processor'); |
|
562 | + $registration_processor->update_registration_final_prices($transaction); |
|
563 | 563 | } |
564 | 564 | $this->log( |
565 | 565 | array( |
566 | - 'message' => __( 'Updated transaction related to payment', 'event_espresso' ), |
|
566 | + 'message' => __('Updated transaction related to payment', 'event_espresso'), |
|
567 | 567 | 'url' => $this->_process_response_url(), |
568 | 568 | 'transaction (updated)' => $transaction->model_field_array(), |
569 | 569 | 'payment (updated)' => $payment->model_field_array(), |