@@ -10,7 +10,7 @@ discard block |
||
10 | 10 | * @since $VID:$ |
11 | 11 | * |
12 | 12 | */ |
13 | -class EE_PMT_Paypal_Standard extends EE_PMT_Base{ |
|
13 | +class EE_PMT_Paypal_Standard extends EE_PMT_Base { |
|
14 | 14 | |
15 | 15 | const shipping_info_none = 1; |
16 | 16 | const shipping_info_optional = 0; |
@@ -46,7 +46,7 @@ discard block |
||
46 | 46 | * @param \EE_Transaction $transaction |
47 | 47 | * @return NULL |
48 | 48 | */ |
49 | - public function generate_new_billing_form( EE_Transaction $transaction = NULL ) { |
|
49 | + public function generate_new_billing_form(EE_Transaction $transaction = NULL) { |
|
50 | 50 | return NULL; |
51 | 51 | } |
52 | 52 | |
@@ -59,13 +59,13 @@ discard block |
||
59 | 59 | * @throws \EE_Error |
60 | 60 | */ |
61 | 61 | public function generate_new_settings_form() { |
62 | - require_once( $this->file_folder() . 'EE_Paypal_Standard_Form.form.php' ); |
|
63 | - $form = new EE_Paypal_Standard_Form( $this ); |
|
64 | - $form->get_input( 'PMD_debug_mode' )->set_html_label_text( |
|
65 | - sprintf( __( "Use PayPal Sandbox %s", 'event_espresso' ), $this->get_help_tab_link() ) |
|
62 | + require_once($this->file_folder().'EE_Paypal_Standard_Form.form.php'); |
|
63 | + $form = new EE_Paypal_Standard_Form($this); |
|
64 | + $form->get_input('PMD_debug_mode')->set_html_label_text( |
|
65 | + sprintf(__("Use PayPal Sandbox %s", 'event_espresso'), $this->get_help_tab_link()) |
|
66 | 66 | ); |
67 | - $form->get_input( 'shipping_details' )->set_html_label_text( |
|
68 | - sprintf( __( "Shipping Address Options %s", "event_espresso" ), $this->get_help_tab_link() ) |
|
67 | + $form->get_input('shipping_details')->set_html_label_text( |
|
68 | + sprintf(__("Shipping Address Options %s", "event_espresso"), $this->get_help_tab_link()) |
|
69 | 69 | ); |
70 | 70 | return $form; |
71 | 71 | } |
@@ -77,7 +77,7 @@ discard block |
||
77 | 77 | * @see EE_PMT_Base::help_tabs_config() |
78 | 78 | * @return array |
79 | 79 | */ |
80 | - public function help_tabs_config(){ |
|
80 | + public function help_tabs_config() { |
|
81 | 81 | return array( |
82 | 82 | $this->get_help_tab_name() => array( |
83 | 83 | 'title'=> __("PayPal Standard Settings", 'event_espresso'), |
@@ -99,13 +99,13 @@ discard block |
||
99 | 99 | * @return EE_Payment |
100 | 100 | * @throws \EE_Error |
101 | 101 | */ |
102 | - public function finalize_payment_for($transaction){ |
|
102 | + public function finalize_payment_for($transaction) { |
|
103 | 103 | // PayPal standard actually sends the IPN info along with the user when they return to our site |
104 | 104 | // so in case the IPN is arriving later, let's try to process an IPN! |
105 | - if( $_SERVER['REQUEST_METHOD'] === 'POST' ){ |
|
106 | - return $this->handle_ipn($_POST, $transaction ); |
|
107 | - }else{ |
|
108 | - return parent::finalize_payment_for( $transaction ); |
|
105 | + if ($_SERVER['REQUEST_METHOD'] === 'POST') { |
|
106 | + return $this->handle_ipn($_POST, $transaction); |
|
107 | + } else { |
|
108 | + return parent::finalize_payment_for($transaction); |
|
109 | 109 | } |
110 | 110 | } |
111 | 111 |
@@ -151,8 +151,8 @@ |
||
151 | 151 | } |
152 | 152 | $query_params = $this->_disable_default_where_conditions_on_query_param($query_params); |
153 | 153 | $query_param_where_this_model_pk = $this->get_this_model()->get_this_model_name() |
154 | - . "." |
|
155 | - . $this->get_this_model()->get_primary_key_field()->get_name(); |
|
154 | + . "." |
|
155 | + . $this->get_this_model()->get_primary_key_field()->get_name(); |
|
156 | 156 | $model_object_id = $this->_get_model_object_id( $model_object_or_id ); |
157 | 157 | $query_params[0][$query_param_where_this_model_pk] = $model_object_id; |
158 | 158 | return $this->get_other_model()->get_all($query_params); |
@@ -13,7 +13,7 @@ discard block |
||
13 | 13 | * @subpackage core |
14 | 14 | * @author Michael Nelson |
15 | 15 | */ |
16 | -abstract class EE_Model_Relation_Base{ |
|
16 | +abstract class EE_Model_Relation_Base { |
|
17 | 17 | /** |
18 | 18 | * The model name of which this relation is a component (ie, the model that called new EE_Model_Relation_Base) |
19 | 19 | * @var string eg Event, Question_Group, Registration |
@@ -48,9 +48,9 @@ discard block |
||
48 | 48 | * @param boolean $block_deletes if there are related models across this relation, block (prevent and add an error) the deletion of this model |
49 | 49 | * @param string $blocking_delete_error_message a customized error message on blocking deletes instead of the default |
50 | 50 | */ |
51 | - public function __construct($block_deletes, $blocking_delete_error_message){ |
|
51 | + public function __construct($block_deletes, $blocking_delete_error_message) { |
|
52 | 52 | $this->_blocking_delete = $block_deletes; |
53 | - $this->_blocking_delete_error_message=$blocking_delete_error_message; |
|
53 | + $this->_blocking_delete_error_message = $blocking_delete_error_message; |
|
54 | 54 | } |
55 | 55 | |
56 | 56 | |
@@ -60,12 +60,12 @@ discard block |
||
60 | 60 | * @param $other_model_name |
61 | 61 | * @throws EE_Error |
62 | 62 | */ |
63 | - public function _construct_finalize_set_models($this_model_name, $other_model_name){ |
|
63 | + public function _construct_finalize_set_models($this_model_name, $other_model_name) { |
|
64 | 64 | $this->_this_model_name = $this_model_name; |
65 | 65 | $this->_other_model_name = $other_model_name; |
66 | - if(is_string($this->_blocking_delete)){ |
|
66 | + if (is_string($this->_blocking_delete)) { |
|
67 | 67 | throw new EE_Error(sprintf(__("When instantiating the relation of type %s from %s to %s, the \$block_deletes argument should be a boolean, not a string (%s)", "event_espresso"), |
68 | - get_class($this),$this_model_name,$other_model_name,$this->_blocking_delete)); |
|
68 | + get_class($this), $this_model_name, $other_model_name, $this->_blocking_delete)); |
|
69 | 69 | } |
70 | 70 | } |
71 | 71 | |
@@ -75,7 +75,7 @@ discard block |
||
75 | 75 | * Gets the model where this relation is defined. |
76 | 76 | * @return EEM_Base |
77 | 77 | */ |
78 | - public function get_this_model(){ |
|
78 | + public function get_this_model() { |
|
79 | 79 | return $this->_get_model($this->_this_model_name); |
80 | 80 | } |
81 | 81 | |
@@ -86,7 +86,7 @@ discard block |
||
86 | 86 | * this relation object was defined on get_this_model(), get_other_model() is the other one) |
87 | 87 | * @return EEM_Base |
88 | 88 | */ |
89 | - public function get_other_model(){ |
|
89 | + public function get_other_model() { |
|
90 | 90 | return $this->_get_model($this->_other_model_name); |
91 | 91 | } |
92 | 92 | |
@@ -97,9 +97,9 @@ discard block |
||
97 | 97 | * @param string $model_name like Event, Question_Group, etc. omit the EEM_ |
98 | 98 | * @return EEM_Base |
99 | 99 | */ |
100 | - protected function _get_model($model_name){ |
|
101 | - $modelInstance = EE_Registry::instance()->load_model( $model_name ); |
|
102 | - $modelInstance->set_timezone( $this->_timezone ); |
|
100 | + protected function _get_model($model_name) { |
|
101 | + $modelInstance = EE_Registry::instance()->load_model($model_name); |
|
102 | + $modelInstance->set_timezone($this->_timezone); |
|
103 | 103 | return $modelInstance; |
104 | 104 | } |
105 | 105 | |
@@ -109,8 +109,8 @@ discard block |
||
109 | 109 | * entirely possible that relations may be called from a model and we need to make sure those relations have their timezone set correctly. |
110 | 110 | * @param string $timezone timezone to set. |
111 | 111 | */ |
112 | - public function set_timezone( $timezone ) { |
|
113 | - if($timezone !== NULL){ |
|
112 | + public function set_timezone($timezone) { |
|
113 | + if ($timezone !== NULL) { |
|
114 | 114 | $this->_timezone = $timezone; |
115 | 115 | } |
116 | 116 | } |
@@ -126,8 +126,8 @@ discard block |
||
126 | 126 | * @param string $extra_join_sql |
127 | 127 | * @return string |
128 | 128 | */ |
129 | - protected function _left_join($other_table,$other_table_alias,$other_table_column,$this_table_alias,$this_table_join_column, $extra_join_sql = ''){ |
|
130 | - return " LEFT JOIN ".$other_table." AS ".$other_table_alias. " ON ".$other_table_alias.".".$other_table_column."=".$this_table_alias.".".$this_table_join_column. ($extra_join_sql ? " AND $extra_join_sql" : ''); |
|
129 | + protected function _left_join($other_table, $other_table_alias, $other_table_column, $this_table_alias, $this_table_join_column, $extra_join_sql = '') { |
|
130 | + return " LEFT JOIN ".$other_table." AS ".$other_table_alias." ON ".$other_table_alias.".".$other_table_column."=".$this_table_alias.".".$this_table_join_column.($extra_join_sql ? " AND $extra_join_sql" : ''); |
|
131 | 131 | } |
132 | 132 | |
133 | 133 | |
@@ -145,15 +145,15 @@ discard block |
||
145 | 145 | * @return EE_Base_Class[] |
146 | 146 | * @throws \EE_Error |
147 | 147 | */ |
148 | - public function get_all_related($model_object_or_id, $query_params = array(), $values_already_prepared_by_model_object = false ){ |
|
149 | - if( $values_already_prepared_by_model_object !== false ) { |
|
150 | - EE_Error::doing_it_wrong( 'EE_Model_Relation_Base::get_all_related', __( 'The argument $values_already_prepared_by_model_object is no longer used.', 'event_espresso' ), '4.8.1' ); |
|
148 | + public function get_all_related($model_object_or_id, $query_params = array(), $values_already_prepared_by_model_object = false) { |
|
149 | + if ($values_already_prepared_by_model_object !== false) { |
|
150 | + EE_Error::doing_it_wrong('EE_Model_Relation_Base::get_all_related', __('The argument $values_already_prepared_by_model_object is no longer used.', 'event_espresso'), '4.8.1'); |
|
151 | 151 | } |
152 | 152 | $query_params = $this->_disable_default_where_conditions_on_query_param($query_params); |
153 | 153 | $query_param_where_this_model_pk = $this->get_this_model()->get_this_model_name() |
154 | 154 | . "." |
155 | 155 | . $this->get_this_model()->get_primary_key_field()->get_name(); |
156 | - $model_object_id = $this->_get_model_object_id( $model_object_or_id ); |
|
156 | + $model_object_id = $this->_get_model_object_id($model_object_or_id); |
|
157 | 157 | $query_params[0][$query_param_where_this_model_pk] = $model_object_id; |
158 | 158 | return $this->get_other_model()->get_all($query_params); |
159 | 159 | } |
@@ -165,9 +165,9 @@ discard block |
||
165 | 165 | * @param string $query_params |
166 | 166 | * @return array |
167 | 167 | */ |
168 | - protected function _disable_default_where_conditions_on_query_param($query_params){ |
|
169 | - if( ! isset($query_params['default_where_conditions'])){ |
|
170 | - $query_params['default_where_conditions']='none'; |
|
168 | + protected function _disable_default_where_conditions_on_query_param($query_params) { |
|
169 | + if ( ! isset($query_params['default_where_conditions'])) { |
|
170 | + $query_params['default_where_conditions'] = 'none'; |
|
171 | 171 | } |
172 | 172 | return $query_params; |
173 | 173 | } |
@@ -185,15 +185,15 @@ discard block |
||
185 | 185 | * @return int of how many related models got deleted |
186 | 186 | * @throws \EE_Error |
187 | 187 | */ |
188 | - public function delete_all_related($model_object_or_id,$query_params = array()){ |
|
188 | + public function delete_all_related($model_object_or_id, $query_params = array()) { |
|
189 | 189 | //for each thing we would delete, |
190 | - $related_model_objects = $this->get_all_related($model_object_or_id,$query_params); |
|
190 | + $related_model_objects = $this->get_all_related($model_object_or_id, $query_params); |
|
191 | 191 | //determine if it's blocked by anything else before it can be deleted |
192 | 192 | $deleted_count = 0; |
193 | - foreach($related_model_objects as $related_model_object){ |
|
193 | + foreach ($related_model_objects as $related_model_object) { |
|
194 | 194 | $delete_is_blocked = $this->get_other_model()->delete_is_blocked_by_related_models($related_model_object, $model_object_or_id); |
195 | 195 | /* @var $model_object_or_id EE_Base_Class */ |
196 | - if( ! $delete_is_blocked ){ |
|
196 | + if ( ! $delete_is_blocked) { |
|
197 | 197 | $this->remove_relation_to($model_object_or_id, $related_model_object); |
198 | 198 | $related_model_object->delete(); |
199 | 199 | $deleted_count++; |
@@ -215,27 +215,27 @@ discard block |
||
215 | 215 | * @return int of how many related models got deleted |
216 | 216 | * @throws \EE_Error |
217 | 217 | */ |
218 | - public function delete_related_permanently($model_object_or_id,$query_params = array()){ |
|
218 | + public function delete_related_permanently($model_object_or_id, $query_params = array()) { |
|
219 | 219 | //for each thing we would delete, |
220 | - $related_model_objects = $this->get_all_related($model_object_or_id,$query_params); |
|
220 | + $related_model_objects = $this->get_all_related($model_object_or_id, $query_params); |
|
221 | 221 | //determine if it's blocked by anything else before it can be deleted |
222 | 222 | $deleted_count = 0; |
223 | - foreach($related_model_objects as $related_model_object){ |
|
223 | + foreach ($related_model_objects as $related_model_object) { |
|
224 | 224 | $delete_is_blocked = $this->get_other_model()->delete_is_blocked_by_related_models($related_model_object, $model_object_or_id); |
225 | 225 | /* @var $model_object_or_id EE_Base_Class */ |
226 | - if( $related_model_object instanceof EE_Soft_Delete_Base_Class ){ |
|
226 | + if ($related_model_object instanceof EE_Soft_Delete_Base_Class) { |
|
227 | 227 | $this->remove_relation_to($model_object_or_id, $related_model_object); |
228 | 228 | $deleted_count++; |
229 | - if( ! $delete_is_blocked ){ |
|
229 | + if ( ! $delete_is_blocked) { |
|
230 | 230 | $related_model_object->delete_permanently(); |
231 | - }else{ |
|
231 | + } else { |
|
232 | 232 | //delete is blocked |
233 | 233 | //brent and darren, in this case, wanted to just soft delete it then |
234 | 234 | $related_model_object->delete(); |
235 | 235 | } |
236 | - }else{ |
|
236 | + } else { |
|
237 | 237 | //its not a soft-deletable thing anyways. do the normal logic. |
238 | - if( ! $delete_is_blocked ){ |
|
238 | + if ( ! $delete_is_blocked) { |
|
239 | 239 | $this->remove_relation_to($model_object_or_id, $related_model_object); |
240 | 240 | $related_model_object->delete(); |
241 | 241 | $deleted_count++; |
@@ -255,11 +255,11 @@ discard block |
||
255 | 255 | */ |
256 | 256 | protected function _get_model_object_id($model_object_or_id) { |
257 | 257 | $model_object_id = $model_object_or_id; |
258 | - if($model_object_or_id instanceof EE_Base_Class){ |
|
258 | + if ($model_object_or_id instanceof EE_Base_Class) { |
|
259 | 259 | $model_object_id = $model_object_or_id->ID(); |
260 | 260 | } |
261 | - if( ! $model_object_id){ |
|
262 | - throw new EE_Error(sprintf(__("Sorry, we cant get the related %s model objects to %s model object before it has an ID. You can solve that by just saving it before trying to get its related model objects", "event_espresso"),$this->get_other_model()->get_this_model_name(),$this->get_this_model()->get_this_model_name())); |
|
261 | + if ( ! $model_object_id) { |
|
262 | + throw new EE_Error(sprintf(__("Sorry, we cant get the related %s model objects to %s model object before it has an ID. You can solve that by just saving it before trying to get its related model objects", "event_espresso"), $this->get_other_model()->get_this_model_name(), $this->get_this_model()->get_this_model_name())); |
|
263 | 263 | } |
264 | 264 | return $model_object_id; |
265 | 265 | } |
@@ -313,10 +313,10 @@ discard block |
||
313 | 313 | * @return EE_Base_Class[] |
314 | 314 | * @throws \EE_Error |
315 | 315 | */ |
316 | - public function remove_relations($this_obj_or_id,$where_query_param = array()){ |
|
317 | - $related_things = $this->get_all_related($this_obj_or_id,array($where_query_param)); |
|
316 | + public function remove_relations($this_obj_or_id, $where_query_param = array()) { |
|
317 | + $related_things = $this->get_all_related($this_obj_or_id, array($where_query_param)); |
|
318 | 318 | $objs_removed = array(); |
319 | - foreach($related_things as $related_thing){ |
|
319 | + foreach ($related_things as $related_thing) { |
|
320 | 320 | $objs_removed[] = $this->remove_relation_to($this_obj_or_id, $related_thing); |
321 | 321 | } |
322 | 322 | return $objs_removed; |
@@ -329,7 +329,7 @@ discard block |
||
329 | 329 | * related objects exist, returns false. |
330 | 330 | * @return boolean |
331 | 331 | */ |
332 | - public function block_delete_if_related_models_exist(){ |
|
332 | + public function block_delete_if_related_models_exist() { |
|
333 | 333 | return $this->_blocking_delete; |
334 | 334 | } |
335 | 335 | |
@@ -338,13 +338,13 @@ discard block |
||
338 | 338 | * Gets the error message to show |
339 | 339 | * @return string |
340 | 340 | */ |
341 | - public function get_deletion_error_message(){ |
|
342 | - if($this->_blocking_delete_error_message){ |
|
341 | + public function get_deletion_error_message() { |
|
342 | + if ($this->_blocking_delete_error_message) { |
|
343 | 343 | return $this->_blocking_delete_error_message; |
344 | - }else{ |
|
344 | + } else { |
|
345 | 345 | // return sprintf(__('Cannot delete %1$s when there are related %2$s', "event_espresso"),$this->get_this_model()->item_name(2),$this->get_other_model()->item_name(2)); |
346 | 346 | return sprintf( |
347 | - __( 'This %1$s is currently linked to one or more %2$s records. If this %1$s is incorrect, then please remove it from all %3$s before attempting to delete it.', "event_espresso"), |
|
347 | + __('This %1$s is currently linked to one or more %2$s records. If this %1$s is incorrect, then please remove it from all %3$s before attempting to delete it.', "event_espresso"), |
|
348 | 348 | $this->get_this_model()->item_name(1), |
349 | 349 | $this->get_other_model()->item_name(1), |
350 | 350 | $this->get_other_model()->item_name(2) |
@@ -228,12 +228,12 @@ discard block |
||
228 | 228 | $deleted_count++; |
229 | 229 | if( ! $delete_is_blocked ){ |
230 | 230 | $related_model_object->delete_permanently(); |
231 | - }else{ |
|
231 | + } else{ |
|
232 | 232 | //delete is blocked |
233 | 233 | //brent and darren, in this case, wanted to just soft delete it then |
234 | 234 | $related_model_object->delete(); |
235 | 235 | } |
236 | - }else{ |
|
236 | + } else{ |
|
237 | 237 | //its not a soft-deletable thing anyways. do the normal logic. |
238 | 238 | if( ! $delete_is_blocked ){ |
239 | 239 | $this->remove_relation_to($model_object_or_id, $related_model_object); |
@@ -341,7 +341,7 @@ discard block |
||
341 | 341 | public function get_deletion_error_message(){ |
342 | 342 | if($this->_blocking_delete_error_message){ |
343 | 343 | return $this->_blocking_delete_error_message; |
344 | - }else{ |
|
344 | + } else{ |
|
345 | 345 | // return sprintf(__('Cannot delete %1$s when there are related %2$s', "event_espresso"),$this->get_this_model()->item_name(2),$this->get_other_model()->item_name(2)); |
346 | 346 | return sprintf( |
347 | 347 | __( 'This %1$s is currently linked to one or more %2$s records. If this %1$s is incorrect, then please remove it from all %3$s before attempting to delete it.', "event_espresso"), |
@@ -119,9 +119,9 @@ discard block |
||
119 | 119 | |
120 | 120 | /** |
121 | 121 | * @param $other_table |
122 | - * @param $other_table_alias |
|
122 | + * @param string $other_table_alias |
|
123 | 123 | * @param $other_table_column |
124 | - * @param $this_table_alias |
|
124 | + * @param string $this_table_alias |
|
125 | 125 | * @param $this_table_join_column |
126 | 126 | * @param string $extra_join_sql |
127 | 127 | * @return string |
@@ -163,7 +163,7 @@ discard block |
||
163 | 163 | /** |
164 | 164 | * Alters the $query_params to disable default where conditions, unless otherwise specified |
165 | 165 | * @param string $query_params |
166 | - * @return array |
|
166 | + * @return string |
|
167 | 167 | */ |
168 | 168 | protected function _disable_default_where_conditions_on_query_param($query_params){ |
169 | 169 | if( ! isset($query_params['default_where_conditions'])){ |
@@ -180,7 +180,7 @@ discard block |
||
180 | 180 | * Note: If the related model is extends EEM_Soft_Delete_Base, then the related |
181 | 181 | * model objects will only be soft-deleted. |
182 | 182 | * |
183 | - * @param EE_Base_Class|int|string $model_object_or_id |
|
183 | + * @param EE_Base_Class|null $model_object_or_id |
|
184 | 184 | * @param array $query_params |
185 | 185 | * @return int of how many related models got deleted |
186 | 186 | * @throws \EE_Error |
@@ -210,7 +210,7 @@ discard block |
||
210 | 210 | * Note: If the related model is extends EEM_Soft_Delete_Base, then the related |
211 | 211 | * model objects will only be soft-deleted. |
212 | 212 | * |
213 | - * @param EE_Base_Class|int|string $model_object_or_id |
|
213 | + * @param EE_Base_Class|null $model_object_or_id |
|
214 | 214 | * @param array $query_params |
215 | 215 | * @return int of how many related models got deleted |
216 | 216 | * @throws \EE_Error |
@@ -1,6 +1,6 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | |
3 | -require_once( EE_MODELS . 'relations/EE_Model_Relation_Base.php'); |
|
3 | +require_once(EE_MODELS.'relations/EE_Model_Relation_Base.php'); |
|
4 | 4 | |
5 | 5 | |
6 | 6 | |
@@ -11,7 +11,7 @@ discard block |
||
11 | 11 | * @subpackage core |
12 | 12 | * @author Michael Nelson |
13 | 13 | */ |
14 | -class EE_HABTM_Relation extends EE_Model_Relation_Base{ |
|
14 | +class EE_HABTM_Relation extends EE_Model_Relation_Base { |
|
15 | 15 | /** |
16 | 16 | * Model which defines the relation between two other models. Eg, the EE_Event_Question_Group model, |
17 | 17 | * which joins EE_Event and EE_Question_Group |
@@ -32,7 +32,7 @@ discard block |
||
32 | 32 | * @param boolean $block_deletes for this type of relation, we block by default for now. if there are related models across this relation, block (prevent and add an error) the deletion of this model |
33 | 33 | * @param string $blocking_delete_error_message a customized error message on blocking deletes instead of the default |
34 | 34 | */ |
35 | - public function __construct($joining_model_name,$block_deletes = true, $blocking_delete_error_message =''){ |
|
35 | + public function __construct($joining_model_name, $block_deletes = true, $blocking_delete_error_message = '') { |
|
36 | 36 | $this->_joining_model_name = $joining_model_name; |
37 | 37 | parent::__construct($block_deletes, $blocking_delete_error_message); |
38 | 38 | } |
@@ -40,7 +40,7 @@ discard block |
||
40 | 40 | * Gets the joining model's object |
41 | 41 | * @return EEM_Base |
42 | 42 | */ |
43 | - public function get_join_model(){ |
|
43 | + public function get_join_model() { |
|
44 | 44 | return $this->_get_model($this->_joining_model_name); |
45 | 45 | } |
46 | 46 | |
@@ -53,21 +53,21 @@ discard block |
||
53 | 53 | * @return string of SQL |
54 | 54 | * @throws \EE_Error |
55 | 55 | */ |
56 | - public function get_join_to_intermediate_model_statement($model_relation_chain){ |
|
56 | + public function get_join_to_intermediate_model_statement($model_relation_chain) { |
|
57 | 57 | //create sql like |
58 | 58 | //LEFT JOIN join_table AS join_table_alias ON this_table_alias.this_table_pk = join_table_alias.join_table_fk_to_this |
59 | 59 | //LEFT JOIN other_table AS other_table_alias ON join_table_alias.join_table_fk_to_other = other_table_alias.other_table_pk |
60 | 60 | //remember the model relation chain to the JOIN model, because we'll |
61 | 61 | //need it for get_join_statement() |
62 | 62 | $this->_model_relation_chain_to_join_model = $model_relation_chain; |
63 | - $this_table_pk_field = $this->get_this_model()->get_primary_key_field();//get_foreign_key_to($this->get_other_model()->get_this_model_name()); |
|
63 | + $this_table_pk_field = $this->get_this_model()->get_primary_key_field(); //get_foreign_key_to($this->get_other_model()->get_this_model_name()); |
|
64 | 64 | $join_table_fk_field_to_this_table = $this->get_join_model()->get_foreign_key_to($this->get_this_model()->get_this_model_name()); |
65 | - $this_table_alias = EE_Model_Parser::extract_table_alias_model_relation_chain_prefix($model_relation_chain, $this->get_this_model()->get_this_model_name()) . $this_table_pk_field->get_table_alias(); |
|
65 | + $this_table_alias = EE_Model_Parser::extract_table_alias_model_relation_chain_prefix($model_relation_chain, $this->get_this_model()->get_this_model_name()).$this_table_pk_field->get_table_alias(); |
|
66 | 66 | |
67 | - $join_table_alias = EE_Model_Parser::extract_table_alias_model_relation_chain_prefix($model_relation_chain, $this->get_join_model()->get_this_model_name()) . $join_table_fk_field_to_this_table->get_table_alias(); |
|
67 | + $join_table_alias = EE_Model_Parser::extract_table_alias_model_relation_chain_prefix($model_relation_chain, $this->get_join_model()->get_this_model_name()).$join_table_fk_field_to_this_table->get_table_alias(); |
|
68 | 68 | $join_table = $this->get_join_model()->get_table_for_alias($join_table_alias); |
69 | 69 | //phew! ok, we have all the info we need, now we can create the SQL join string |
70 | - $SQL = $this->_left_join($join_table, $join_table_alias, $join_table_fk_field_to_this_table->get_table_column(), $this_table_alias, $this_table_pk_field->get_table_column()) . $this->get_join_model()->_construct_internal_join_to_table_with_alias($join_table_alias); |
|
70 | + $SQL = $this->_left_join($join_table, $join_table_alias, $join_table_fk_field_to_this_table->get_table_column(), $this_table_alias, $this_table_pk_field->get_table_column()).$this->get_join_model()->_construct_internal_join_to_table_with_alias($join_table_alias); |
|
71 | 71 | |
72 | 72 | return $SQL; |
73 | 73 | } |
@@ -84,18 +84,18 @@ discard block |
||
84 | 84 | * @return string of SQL |
85 | 85 | * @throws \EE_Error |
86 | 86 | */ |
87 | - public function get_join_statement($model_relation_chain){ |
|
88 | - if( $this->_model_relation_chain_to_join_model === NULL ){ |
|
89 | - throw new EE_Error( sprintf( __( 'When using EE_HABTM_Relation to create a join, you must call get_join_to_intermediate_model_statement BEFORE get_join_statement', 'event_espresso' ))); |
|
87 | + public function get_join_statement($model_relation_chain) { |
|
88 | + if ($this->_model_relation_chain_to_join_model === NULL) { |
|
89 | + throw new EE_Error(sprintf(__('When using EE_HABTM_Relation to create a join, you must call get_join_to_intermediate_model_statement BEFORE get_join_statement', 'event_espresso'))); |
|
90 | 90 | } |
91 | 91 | $join_table_fk_field_to_this_table = $this->get_join_model()->get_foreign_key_to($this->get_this_model()->get_this_model_name()); |
92 | - $join_table_alias = EE_Model_Parser::extract_table_alias_model_relation_chain_prefix($this->_model_relation_chain_to_join_model, $this->get_join_model()->get_this_model_name()) . $join_table_fk_field_to_this_table->get_table_alias(); |
|
92 | + $join_table_alias = EE_Model_Parser::extract_table_alias_model_relation_chain_prefix($this->_model_relation_chain_to_join_model, $this->get_join_model()->get_this_model_name()).$join_table_fk_field_to_this_table->get_table_alias(); |
|
93 | 93 | $other_table_pk_field = $this->get_other_model()->get_primary_key_field(); |
94 | 94 | $join_table_fk_field_to_other_table = $this->get_join_model()->get_foreign_key_to($this->get_other_model()->get_this_model_name()); |
95 | - $other_table_alias = EE_Model_Parser::extract_table_alias_model_relation_chain_prefix($model_relation_chain, $this->get_other_model()->get_this_model_name()) . $other_table_pk_field->get_table_alias(); |
|
95 | + $other_table_alias = EE_Model_Parser::extract_table_alias_model_relation_chain_prefix($model_relation_chain, $this->get_other_model()->get_this_model_name()).$other_table_pk_field->get_table_alias(); |
|
96 | 96 | $other_table = $this->get_other_model()->get_table_for_alias($other_table_alias); |
97 | 97 | |
98 | - $SQL = $this->_left_join($other_table, $other_table_alias, $other_table_pk_field->get_table_column(), $join_table_alias, $join_table_fk_field_to_other_table->get_table_column()) . $this->get_other_model()->_construct_internal_join_to_table_with_alias($other_table_alias); |
|
98 | + $SQL = $this->_left_join($other_table, $other_table_alias, $other_table_pk_field->get_table_column(), $join_table_alias, $join_table_fk_field_to_other_table->get_table_column()).$this->get_other_model()->_construct_internal_join_to_table_with_alias($other_table_alias); |
|
99 | 99 | return $SQL; |
100 | 100 | } |
101 | 101 | |
@@ -112,37 +112,37 @@ discard block |
||
112 | 112 | * @return EE_Base_Class |
113 | 113 | * @throws \EE_Error |
114 | 114 | */ |
115 | - public function add_relation_to($this_obj_or_id, $other_obj_or_id, $extra_join_model_fields_n_values = array() ){ |
|
115 | + public function add_relation_to($this_obj_or_id, $other_obj_or_id, $extra_join_model_fields_n_values = array()) { |
|
116 | 116 | $this_model_obj = $this->get_this_model()->ensure_is_obj($this_obj_or_id, true); |
117 | 117 | $other_model_obj = $this->get_other_model()->ensure_is_obj($other_obj_or_id, true); |
118 | 118 | //check if such a relationship already exists |
119 | 119 | $join_model_fk_to_this_model = $this->get_join_model()->get_foreign_key_to($this->get_this_model()->get_this_model_name()); |
120 | 120 | $join_model_fk_to_other_model = $this->get_join_model()->get_foreign_key_to($this->get_other_model()->get_this_model_name()); |
121 | 121 | |
122 | - $cols_n_values = array( |
|
122 | + $cols_n_values = array( |
|
123 | 123 | $join_model_fk_to_this_model->get_name() => $this_model_obj->ID(), |
124 | 124 | $join_model_fk_to_other_model->get_name() => $other_model_obj->ID()); |
125 | 125 | |
126 | 126 | //if $where_query exists lets add them to the query_params. |
127 | - if ( !empty( $extra_join_model_fields_n_values ) ) { |
|
127 | + if ( ! empty($extra_join_model_fields_n_values)) { |
|
128 | 128 | //make sure we strip any of the join model names from the $where_query cause we don't need that in here (why? because client code may have used the same conditionals for get_all_related which DOES need the join model name) |
129 | 129 | //make sure we strip THIS models name from the query param |
130 | 130 | $parsed_query = array(); |
131 | - foreach ( $extra_join_model_fields_n_values as $query_param => $val ) { |
|
132 | - $query_param = str_replace($this->get_join_model()->get_this_model_name().".","", $query_param); |
|
131 | + foreach ($extra_join_model_fields_n_values as $query_param => $val) { |
|
132 | + $query_param = str_replace($this->get_join_model()->get_this_model_name().".", "", $query_param); |
|
133 | 133 | $parsed_query[$query_param] = $val; |
134 | 134 | } |
135 | - $cols_n_values = array_merge( $cols_n_values, $parsed_query ); |
|
135 | + $cols_n_values = array_merge($cols_n_values, $parsed_query); |
|
136 | 136 | } |
137 | 137 | |
138 | - $query_params = array( $cols_n_values ); |
|
138 | + $query_params = array($cols_n_values); |
|
139 | 139 | |
140 | 140 | |
141 | 141 | $existing_entry_in_join_table = $this->get_join_model()->get_one($query_params); |
142 | 142 | //if there is already an entry in the join table, indicating a relationship, we're done |
143 | 143 | //again, if you want more sophisticated logic or insertions (handling more columns than just 2 foreign keys to |
144 | 144 | //the other tables, use the joining model directly! |
145 | - if( ! $existing_entry_in_join_table ){ |
|
145 | + if ( ! $existing_entry_in_join_table) { |
|
146 | 146 | $this->get_join_model()->insert($cols_n_values); |
147 | 147 | } |
148 | 148 | return $other_model_obj; |
@@ -160,30 +160,30 @@ discard block |
||
160 | 160 | * @return EE_Base_Class |
161 | 161 | * @throws \EE_Error |
162 | 162 | */ |
163 | - public function remove_relation_to($this_obj_or_id, $other_obj_or_id, $where_query = array() ){ |
|
163 | + public function remove_relation_to($this_obj_or_id, $other_obj_or_id, $where_query = array()) { |
|
164 | 164 | $this_model_obj = $this->get_this_model()->ensure_is_obj($this_obj_or_id, true); |
165 | 165 | $other_model_obj = $this->get_other_model()->ensure_is_obj($other_obj_or_id, true); |
166 | 166 | //check if such a relationship already exists |
167 | 167 | $join_model_fk_to_this_model = $this->get_join_model()->get_foreign_key_to($this->get_this_model()->get_this_model_name()); |
168 | 168 | $join_model_fk_to_other_model = $this->get_join_model()->get_foreign_key_to($this->get_other_model()->get_this_model_name()); |
169 | 169 | |
170 | - $cols_n_values = array( |
|
170 | + $cols_n_values = array( |
|
171 | 171 | $join_model_fk_to_this_model->get_name() => $this_model_obj->ID(), |
172 | 172 | $join_model_fk_to_other_model->get_name() => $other_model_obj->ID()); |
173 | 173 | |
174 | 174 | //if $where_query exists lets add them to the query_params. |
175 | - if ( !empty( $where_query ) ) { |
|
175 | + if ( ! empty($where_query)) { |
|
176 | 176 | //make sure we strip any of the join model names from the $where_query cause we don't need that in here (why? because client code may have used the same conditionals for get_all_related which DOES need the join model name) |
177 | 177 | //make sure we strip THIS models name from the query param |
178 | 178 | $parsed_query = array(); |
179 | - foreach ( $where_query as $query_param => $val ) { |
|
180 | - $query_param = str_replace($this->get_join_model()->get_this_model_name().".","", $query_param); |
|
179 | + foreach ($where_query as $query_param => $val) { |
|
180 | + $query_param = str_replace($this->get_join_model()->get_this_model_name().".", "", $query_param); |
|
181 | 181 | $parsed_query[$query_param] = $val; |
182 | 182 | } |
183 | - $cols_n_values = array_merge( $cols_n_values, $parsed_query ); |
|
183 | + $cols_n_values = array_merge($cols_n_values, $parsed_query); |
|
184 | 184 | } |
185 | 185 | |
186 | - $this->get_join_model()->delete( array($cols_n_values) ); |
|
186 | + $this->get_join_model()->delete(array($cols_n_values)); |
|
187 | 187 | return $other_model_obj; |
188 | 188 | } |
189 | 189 | } |
@@ -8,7 +8,7 @@ discard block |
||
8 | 8 | * @subpackage core |
9 | 9 | * @author Michael Nelson |
10 | 10 | */ |
11 | -class EE_HABTM_Any_Relation extends EE_HABTM_Relation{ |
|
11 | +class EE_HABTM_Any_Relation extends EE_HABTM_Relation { |
|
12 | 12 | /** |
13 | 13 | * |
14 | 14 | * @var string |
@@ -22,8 +22,8 @@ discard block |
||
22 | 22 | * @param boolean $block_deletes for this type of relation, we block by default for now. if there are related models across this relation, block (prevent and add an error) the deletion of this model |
23 | 23 | * @param string $blocking_delete_error_message a customized error message on blocking deletes instead of the default |
24 | 24 | */ |
25 | - public function __construct( $block_deletes = true, $blocking_delete_error_message =''){ |
|
26 | - parent::__construct( 'Extra_Join', $block_deletes, $blocking_delete_error_message); |
|
25 | + public function __construct($block_deletes = true, $blocking_delete_error_message = '') { |
|
26 | + parent::__construct('Extra_Join', $block_deletes, $blocking_delete_error_message); |
|
27 | 27 | } |
28 | 28 | |
29 | 29 | |
@@ -33,13 +33,13 @@ discard block |
||
33 | 33 | * @param $other_model_name |
34 | 34 | * @throws EE_Error |
35 | 35 | */ |
36 | - public function _construct_finalize_set_models( $this_model_name, $other_model_name){ |
|
37 | - if( $this_model_name < $other_model_name ) { |
|
36 | + public function _construct_finalize_set_models($this_model_name, $other_model_name) { |
|
37 | + if ($this_model_name < $other_model_name) { |
|
38 | 38 | $this->_alphabetically_first_model_name = $this_model_name; |
39 | - } else{ |
|
39 | + } else { |
|
40 | 40 | $this->_alphabetically_first_model_name = $other_model_name; |
41 | 41 | } |
42 | - parent::_construct_finalize_set_models( $this_model_name, $other_model_name ); |
|
42 | + parent::_construct_finalize_set_models($this_model_name, $other_model_name); |
|
43 | 43 | } |
44 | 44 | |
45 | 45 | |
@@ -50,14 +50,14 @@ discard block |
||
50 | 50 | * @return EE_Model_Field_Base |
51 | 51 | * @throws \EE_Error |
52 | 52 | */ |
53 | - public function get_join_table_fk_field_to( $model_name, $id_or_name_field ) { |
|
53 | + public function get_join_table_fk_field_to($model_name, $id_or_name_field) { |
|
54 | 54 | $order = null; |
55 | - if( $model_name === $this->_alphabetically_first_model_name ) { |
|
55 | + if ($model_name === $this->_alphabetically_first_model_name) { |
|
56 | 56 | $order = 'first'; |
57 | 57 | } else { |
58 | 58 | $order = 'second'; |
59 | 59 | } |
60 | - return $this->get_join_model()->field_settings_for( 'EXJ_' . $order . '_model_' . $id_or_name_field ); |
|
60 | + return $this->get_join_model()->field_settings_for('EXJ_'.$order.'_model_'.$id_or_name_field); |
|
61 | 61 | } |
62 | 62 | |
63 | 63 | |
@@ -69,7 +69,7 @@ discard block |
||
69 | 69 | * @return string of SQL |
70 | 70 | * @throws \EE_Error |
71 | 71 | */ |
72 | - public function get_join_to_intermediate_model_statement($model_relation_chain){ |
|
72 | + public function get_join_to_intermediate_model_statement($model_relation_chain) { |
|
73 | 73 | //create sql like |
74 | 74 | //LEFT JOIN join_table AS join_table_alias ON this_table_alias.this_table_pk = join_table_alias.join_table_fk_to_this |
75 | 75 | //LEFT JOIN other_table AS other_table_alias ON join_table_alias.join_table_fk_to_other = other_table_alias.other_table_pk |
@@ -83,8 +83,8 @@ discard block |
||
83 | 83 | $field_with_model_name = $this->get_join_table_fk_field_to( |
84 | 84 | $this->get_this_model()->get_this_model_name(), |
85 | 85 | 'name' ); |
86 | - $this_table_alias = EE_Model_Parser::extract_table_alias_model_relation_chain_prefix($model_relation_chain, $this->get_this_model()->get_this_model_name()) . $this_table_pk_field->get_table_alias(); |
|
87 | - $join_table_alias = EE_Model_Parser::extract_table_alias_model_relation_chain_prefix($model_relation_chain, $this->get_join_model()->get_this_model_name()) . $join_table_fk_field_to_this_table->get_table_alias(); |
|
86 | + $this_table_alias = EE_Model_Parser::extract_table_alias_model_relation_chain_prefix($model_relation_chain, $this->get_this_model()->get_this_model_name()).$this_table_pk_field->get_table_alias(); |
|
87 | + $join_table_alias = EE_Model_Parser::extract_table_alias_model_relation_chain_prefix($model_relation_chain, $this->get_join_model()->get_this_model_name()).$join_table_fk_field_to_this_table->get_table_alias(); |
|
88 | 88 | $join_table = $this->get_join_model()->get_table_for_alias($join_table_alias); |
89 | 89 | //phew! ok, we have all the info we need, now we can create the SQL join string |
90 | 90 | $SQL = $this->_left_join( |
@@ -93,7 +93,7 @@ discard block |
||
93 | 93 | $join_table_fk_field_to_this_table->get_table_column(), |
94 | 94 | $this_table_alias, |
95 | 95 | $this_table_pk_field->get_table_column(), |
96 | - $field_with_model_name->get_qualified_column()."='".$this->get_this_model()->get_this_model_name()."'" ) . |
|
96 | + $field_with_model_name->get_qualified_column()."='".$this->get_this_model()->get_this_model_name()."'" ). |
|
97 | 97 | $this->get_join_model()->_construct_internal_join_to_table_with_alias($join_table_alias); |
98 | 98 | |
99 | 99 | return $SQL; |
@@ -111,9 +111,9 @@ discard block |
||
111 | 111 | * @return string of SQL |
112 | 112 | * @throws \EE_Error |
113 | 113 | */ |
114 | - public function get_join_statement($model_relation_chain){ |
|
115 | - if( $this->_model_relation_chain_to_join_model === NULL ){ |
|
116 | - throw new EE_Error( sprintf( __( 'When using EE_HABTM_Relation to create a join, you must call get_join_to_intermediate_model_statement BEFORE get_join_statement', 'event_espresso' ))); |
|
114 | + public function get_join_statement($model_relation_chain) { |
|
115 | + if ($this->_model_relation_chain_to_join_model === NULL) { |
|
116 | + throw new EE_Error(sprintf(__('When using EE_HABTM_Relation to create a join, you must call get_join_to_intermediate_model_statement BEFORE get_join_statement', 'event_espresso'))); |
|
117 | 117 | } |
118 | 118 | $join_table_fk_field_to_this_table = $this->get_join_table_fk_field_to( |
119 | 119 | $this->get_this_model()->get_this_model_name(), |
@@ -125,10 +125,10 @@ discard block |
||
125 | 125 | $this->get_other_model()->get_this_model_name(), |
126 | 126 | 'name' ); |
127 | 127 | |
128 | - $join_table_alias = EE_Model_Parser::extract_table_alias_model_relation_chain_prefix($this->_model_relation_chain_to_join_model, $this->get_join_model()->get_this_model_name()) . $join_table_fk_field_to_this_table->get_table_alias(); |
|
128 | + $join_table_alias = EE_Model_Parser::extract_table_alias_model_relation_chain_prefix($this->_model_relation_chain_to_join_model, $this->get_join_model()->get_this_model_name()).$join_table_fk_field_to_this_table->get_table_alias(); |
|
129 | 129 | |
130 | 130 | $other_table_pk_field = $this->get_other_model()->get_primary_key_field(); |
131 | - $other_table_alias = EE_Model_Parser::extract_table_alias_model_relation_chain_prefix($model_relation_chain, $this->get_other_model()->get_this_model_name()) . $other_table_pk_field->get_table_alias(); |
|
131 | + $other_table_alias = EE_Model_Parser::extract_table_alias_model_relation_chain_prefix($model_relation_chain, $this->get_other_model()->get_this_model_name()).$other_table_pk_field->get_table_alias(); |
|
132 | 132 | $other_table = $this->get_other_model()->get_table_for_alias($other_table_alias); |
133 | 133 | |
134 | 134 | $SQL = $this->_left_join( |
@@ -138,7 +138,7 @@ discard block |
||
138 | 138 | $join_table_alias, |
139 | 139 | $join_table_fk_field_to_other_table->get_table_column(), |
140 | 140 | $field_with_other_model_name->get_qualified_column()."='".$this->get_other_model()->get_this_model_name()."'" |
141 | - ) . |
|
141 | + ). |
|
142 | 142 | $this->get_other_model()->_construct_internal_join_to_table_with_alias($other_table_alias); |
143 | 143 | return $SQL; |
144 | 144 | } |
@@ -154,7 +154,7 @@ discard block |
||
154 | 154 | * @return EE_Base_Class |
155 | 155 | * @throws \EE_Error |
156 | 156 | */ |
157 | - public function add_relation_to($this_obj_or_id, $other_obj_or_id, $extra_join_model_fields_n_values = array() ){ |
|
157 | + public function add_relation_to($this_obj_or_id, $other_obj_or_id, $extra_join_model_fields_n_values = array()) { |
|
158 | 158 | $this_model_obj = $this->get_this_model()->ensure_is_obj($this_obj_or_id, true); |
159 | 159 | $other_model_obj = $this->get_other_model()->ensure_is_obj($other_obj_or_id, true); |
160 | 160 | //check if such a relationship already exists |
@@ -171,32 +171,32 @@ discard block |
||
171 | 171 | $this->get_other_model()->get_this_model_name(), |
172 | 172 | 'name' ); |
173 | 173 | |
174 | - $cols_n_values = array( |
|
174 | + $cols_n_values = array( |
|
175 | 175 | $join_model_fk_to_this_model->get_name() => $this_model_obj->ID(), |
176 | 176 | $join_model_name_field_to_this_model->get_name() => $this_model_obj->get_model()->get_this_model_name(), |
177 | 177 | $join_model_fk_to_other_model->get_name() => $other_model_obj->ID(), |
178 | 178 | $join_model_name_field_to_other_model->get_name() => $other_model_obj->get_model()->get_this_model_name() ); |
179 | 179 | |
180 | 180 | //if $where_query exists lets add them to the query_params. |
181 | - if ( !empty( $extra_join_model_fields_n_values ) ) { |
|
181 | + if ( ! empty($extra_join_model_fields_n_values)) { |
|
182 | 182 | //make sure we strip any of the join model names from the $where_query cause we don't need that in here (why? because client code may have used the same conditionals for get_all_related which DOES need the join model name) |
183 | 183 | //make sure we strip THIS models name from the query param |
184 | 184 | $parsed_query = array(); |
185 | - foreach ( $extra_join_model_fields_n_values as $query_param => $val ) { |
|
186 | - $query_param = str_replace($this->get_join_model()->get_this_model_name().".","", $query_param); |
|
185 | + foreach ($extra_join_model_fields_n_values as $query_param => $val) { |
|
186 | + $query_param = str_replace($this->get_join_model()->get_this_model_name().".", "", $query_param); |
|
187 | 187 | $parsed_query[$query_param] = $val; |
188 | 188 | } |
189 | - $cols_n_values = array_merge( $cols_n_values, $parsed_query ); |
|
189 | + $cols_n_values = array_merge($cols_n_values, $parsed_query); |
|
190 | 190 | } |
191 | 191 | |
192 | - $query_params = array( $cols_n_values ); |
|
192 | + $query_params = array($cols_n_values); |
|
193 | 193 | |
194 | 194 | |
195 | 195 | $existing_entry_in_join_table = $this->get_join_model()->get_one($query_params); |
196 | 196 | //if there is already an entry in the join table, indicating a relationship, we're done |
197 | 197 | //again, if you want more sophisticated logic or insertions (handling more columns than just 2 foreign keys to |
198 | 198 | //the other tables, use the joining model directly! |
199 | - if( ! $existing_entry_in_join_table ){ |
|
199 | + if ( ! $existing_entry_in_join_table) { |
|
200 | 200 | $this->get_join_model()->insert($cols_n_values); |
201 | 201 | } |
202 | 202 | return $other_model_obj; |
@@ -214,7 +214,7 @@ discard block |
||
214 | 214 | * @return EE_Base_Class |
215 | 215 | * @throws \EE_Error |
216 | 216 | */ |
217 | - public function remove_relation_to($this_obj_or_id, $other_obj_or_id, $where_query = array() ){ |
|
217 | + public function remove_relation_to($this_obj_or_id, $other_obj_or_id, $where_query = array()) { |
|
218 | 218 | $this_model_obj = $this->get_this_model()->ensure_is_obj($this_obj_or_id, true); |
219 | 219 | $other_model_obj = $this->get_other_model()->ensure_is_obj($other_obj_or_id, true); |
220 | 220 | //check if such a relationship already exists |
@@ -231,25 +231,25 @@ discard block |
||
231 | 231 | $this->get_other_model()->get_this_model_name(), |
232 | 232 | 'name' ); |
233 | 233 | |
234 | - $cols_n_values = array( |
|
234 | + $cols_n_values = array( |
|
235 | 235 | $join_model_fk_to_this_model->get_name() => $this_model_obj->ID(), |
236 | 236 | $join_model_name_field_to_this_model->get_name() => $this_model_obj->get_model()->get_this_model_name(), |
237 | 237 | $join_model_fk_to_other_model->get_name() => $other_model_obj->ID(), |
238 | 238 | $join_model_name_field_to_other_model->get_name() => $other_model_obj->get_model()->get_this_model_name() ); |
239 | 239 | |
240 | 240 | //if $where_query exists lets add them to the query_params. |
241 | - if ( !empty( $where_query ) ) { |
|
241 | + if ( ! empty($where_query)) { |
|
242 | 242 | //make sure we strip any of the join model names from the $where_query cause we don't need that in here (why? because client code may have used the same conditionals for get_all_related which DOES need the join model name) |
243 | 243 | //make sure we strip THIS models name from the query param |
244 | 244 | $parsed_query = array(); |
245 | - foreach ( $where_query as $query_param => $val ) { |
|
246 | - $query_param = str_replace($this->get_join_model()->get_this_model_name().".","", $query_param); |
|
245 | + foreach ($where_query as $query_param => $val) { |
|
246 | + $query_param = str_replace($this->get_join_model()->get_this_model_name().".", "", $query_param); |
|
247 | 247 | $parsed_query[$query_param] = $val; |
248 | 248 | } |
249 | - $cols_n_values = array_merge( $cols_n_values, $parsed_query ); |
|
249 | + $cols_n_values = array_merge($cols_n_values, $parsed_query); |
|
250 | 250 | } |
251 | 251 | |
252 | - $this->get_join_model()->delete( array($cols_n_values) ); |
|
252 | + $this->get_join_model()->delete(array($cols_n_values)); |
|
253 | 253 | return $other_model_obj; |
254 | 254 | } |
255 | 255 | } |
@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php |
2 | -require_once( EE_MODELS . 'relations/EE_Model_Relation_Base.php'); |
|
2 | +require_once(EE_MODELS.'relations/EE_Model_Relation_Base.php'); |
|
3 | 3 | |
4 | 4 | |
5 | 5 | |
@@ -11,7 +11,7 @@ discard block |
||
11 | 11 | * @subpackage core |
12 | 12 | * @author Michael Nelson |
13 | 13 | */ |
14 | -class EE_Has_Many_Relation extends EE_Model_Relation_Base{ |
|
14 | +class EE_Has_Many_Relation extends EE_Model_Relation_Base { |
|
15 | 15 | |
16 | 16 | /** |
17 | 17 | * Object representing the relationship between two models. Has_Many_Relations are where the OTHER model has the foreign key |
@@ -21,7 +21,7 @@ discard block |
||
21 | 21 | * @param boolean $block_deletes For this type of relation, we block by default. If there are related models across this relation, block (prevent and add an error) the deletion of this model |
22 | 22 | * @param string $blocking_delete_error_message a customized error message on blocking deletes instead of the default |
23 | 23 | */ |
24 | - public function __construct($block_deletes = true, $blocking_delete_error_message = null){ |
|
24 | + public function __construct($block_deletes = true, $blocking_delete_error_message = null) { |
|
25 | 25 | parent::__construct($block_deletes, $blocking_delete_error_message); |
26 | 26 | } |
27 | 27 | |
@@ -34,13 +34,13 @@ discard block |
||
34 | 34 | * @return string of SQL, eg "LEFT JOIN table_name AS table_alias ON this_model_primary_table.pk = other_model_primary_table.fk" etc |
35 | 35 | * @throws \EE_Error |
36 | 36 | */ |
37 | - public function get_join_statement( $model_relation_chain){ |
|
37 | + public function get_join_statement($model_relation_chain) { |
|
38 | 38 | //create the sql string like |
39 | 39 | // LEFT JOIN other_table AS table_alias ON this_table_alias.pk = other_table_alias.fk extra_join_conditions |
40 | 40 | $this_table_pk_field = $this->get_this_model()->get_primary_key_field(); |
41 | 41 | $other_table_fk_field = $this->get_other_model()->get_foreign_key_to($this->get_this_model()->get_this_model_name()); |
42 | - $pk_table_alias = EE_Model_Parser::extract_table_alias_model_relation_chain_prefix($model_relation_chain, $this->get_this_model()->get_this_model_name()) . $this_table_pk_field->get_table_alias(); |
|
43 | - $fk_table_alias = EE_Model_Parser::extract_table_alias_model_relation_chain_prefix($model_relation_chain, $this->get_other_model()->get_this_model_name()) . $other_table_fk_field->get_table_alias(); |
|
42 | + $pk_table_alias = EE_Model_Parser::extract_table_alias_model_relation_chain_prefix($model_relation_chain, $this->get_this_model()->get_this_model_name()).$this_table_pk_field->get_table_alias(); |
|
43 | + $fk_table_alias = EE_Model_Parser::extract_table_alias_model_relation_chain_prefix($model_relation_chain, $this->get_other_model()->get_this_model_name()).$other_table_fk_field->get_table_alias(); |
|
44 | 44 | $fk_table = $this->get_other_model()->get_table_for_alias($fk_table_alias); |
45 | 45 | |
46 | 46 | return $this->_left_join($fk_table, $fk_table_alias, $other_table_fk_field->get_table_column(), $pk_table_alias, $this_table_pk_field->get_table_column()).$this->get_other_model()->_construct_internal_join_to_table_with_alias($fk_table_alias); |
@@ -57,13 +57,13 @@ discard block |
||
57 | 57 | * @return \EE_Base_Class |
58 | 58 | * @throws \EE_Error |
59 | 59 | */ |
60 | - public function add_relation_to($this_obj_or_id, $other_obj_or_id, $extra_join_model_fields_n_values = array() ){ |
|
60 | + public function add_relation_to($this_obj_or_id, $other_obj_or_id, $extra_join_model_fields_n_values = array()) { |
|
61 | 61 | $this_model_obj = $this->get_this_model()->ensure_is_obj($this_obj_or_id, true); |
62 | 62 | $other_model_obj = $this->get_other_model()->ensure_is_obj($other_obj_or_id, true); |
63 | 63 | |
64 | 64 | //find the field on the other model which is a foreign key to this model |
65 | 65 | $fk_field_on_other_model = $this->get_other_model()->get_foreign_key_to($this->get_this_model()->get_this_model_name()); |
66 | - if($other_model_obj->get($fk_field_on_other_model->get_name()) != $this_model_obj->ID()){ |
|
66 | + if ($other_model_obj->get($fk_field_on_other_model->get_name()) != $this_model_obj->ID()) { |
|
67 | 67 | //set that field on the other model to this model's ID |
68 | 68 | $other_model_obj->set($fk_field_on_other_model->get_name(), $this_model_obj->ID()); |
69 | 69 | $other_model_obj->save(); |
@@ -83,12 +83,12 @@ discard block |
||
83 | 83 | * @return \EE_Base_Class |
84 | 84 | * @throws \EE_Error |
85 | 85 | */ |
86 | - public function remove_relation_to($this_obj_or_id, $other_obj_or_id, $where_query = array()){ |
|
86 | + public function remove_relation_to($this_obj_or_id, $other_obj_or_id, $where_query = array()) { |
|
87 | 87 | $other_model_obj = $this->get_other_model()->ensure_is_obj($other_obj_or_id, true); |
88 | 88 | //find the field on the other model which is a foreign key to this model |
89 | 89 | $fk_field_on_other_model = $this->get_other_model()->get_foreign_key_to($this->get_this_model()->get_this_model_name()); |
90 | 90 | //set that field on the other model to this model's ID |
91 | - $other_model_obj->set($fk_field_on_other_model->get_name(),null, true); |
|
91 | + $other_model_obj->set($fk_field_on_other_model->get_name(), null, true); |
|
92 | 92 | $other_model_obj->save(); |
93 | 93 | return $other_model_obj; |
94 | 94 | } |
@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php |
2 | -require_once( EE_MODELS . 'relations/EE_Has_Many_Relation.php'); |
|
2 | +require_once(EE_MODELS.'relations/EE_Has_Many_Relation.php'); |
|
3 | 3 | |
4 | 4 | |
5 | 5 | |
@@ -11,7 +11,7 @@ discard block |
||
11 | 11 | * @subpackage core |
12 | 12 | * @author Michael Nelson |
13 | 13 | */ |
14 | -class EE_Has_Many_Revision_Relation extends EE_Has_Many_Relation{ |
|
14 | +class EE_Has_Many_Revision_Relation extends EE_Has_Many_Relation { |
|
15 | 15 | |
16 | 16 | |
17 | 17 | /** |
@@ -44,7 +44,7 @@ discard block |
||
44 | 44 | * @param boolean $block_deletes For this type of relation, we block by default. If there are related models across this relation, block (prevent and add an error) the deletion of this model |
45 | 45 | * @param string $blocking_delete_error_message a customized error message on blocking deletes instead of the default |
46 | 46 | */ |
47 | - public function __construct($primary_cpt_field, $parent_pk_relation_field, $block_deletes = true, $blocking_delete_error_message = null){ |
|
47 | + public function __construct($primary_cpt_field, $parent_pk_relation_field, $block_deletes = true, $blocking_delete_error_message = null) { |
|
48 | 48 | $this->_primary_cpt_field = $primary_cpt_field; |
49 | 49 | $this->_parent_pk_relation_field = $parent_pk_relation_field; |
50 | 50 | parent::__construct($block_deletes, $blocking_delete_error_message); |
@@ -61,7 +61,7 @@ discard block |
||
61 | 61 | * @return \EE_Base_Class |
62 | 62 | * @throws \EE_Error |
63 | 63 | */ |
64 | - public function add_relation_to($this_obj_or_id, $other_obj_or_id, $extra_join_model_fields_n_values = array() ){ |
|
64 | + public function add_relation_to($this_obj_or_id, $other_obj_or_id, $extra_join_model_fields_n_values = array()) { |
|
65 | 65 | $this_model_obj = $this->get_this_model()->ensure_is_obj($this_obj_or_id, true); |
66 | 66 | $other_model_obj = $this->get_other_model()->ensure_is_obj($other_obj_or_id); |
67 | 67 | |
@@ -69,7 +69,7 @@ discard block |
||
69 | 69 | $other_model_obj = $this->_check_for_revision($this_model_obj, $other_model_obj); |
70 | 70 | |
71 | 71 | //if is array, then we've already done the add_relation so let's get out |
72 | - if ( is_array( $other_model_obj ) ){ |
|
72 | + if (is_array($other_model_obj)) { |
|
73 | 73 | return $other_model_obj[0]; |
74 | 74 | } |
75 | 75 | //find the field on the other model which is a foreign key to this model |
@@ -91,15 +91,15 @@ discard block |
||
91 | 91 | * @return \EE_Base_Class |
92 | 92 | * @throws \EE_Error |
93 | 93 | */ |
94 | - public function remove_relation_to($this_obj_or_id, $other_obj_or_id, $where_query = array()){ |
|
94 | + public function remove_relation_to($this_obj_or_id, $other_obj_or_id, $where_query = array()) { |
|
95 | 95 | $this_model_obj = $this->get_this_model()->ensure_is_obj($this_obj_or_id); |
96 | 96 | $other_model_obj = $this->get_other_model()->ensure_is_obj($other_obj_or_id); |
97 | 97 | //handle possible revisions |
98 | - $other_model_obj = $this->_check_for_revision( $this_model_obj, $other_model_obj, TRUE ); |
|
98 | + $other_model_obj = $this->_check_for_revision($this_model_obj, $other_model_obj, TRUE); |
|
99 | 99 | |
100 | 100 | |
101 | 101 | //if is array, then we've already done the add_relation so let's get out |
102 | - if ( is_array( $other_model_obj ) ){ |
|
102 | + if (is_array($other_model_obj)) { |
|
103 | 103 | return $other_model_obj[0]; |
104 | 104 | } |
105 | 105 | |
@@ -108,12 +108,12 @@ discard block |
||
108 | 108 | |
109 | 109 | |
110 | 110 | //set that field on the other model to this model's ID |
111 | - if ( $this->_blocking_delete ) { |
|
112 | - $other_model_obj->set($fk_field_on_other_model->get_name(),null,true); |
|
111 | + if ($this->_blocking_delete) { |
|
112 | + $other_model_obj->set($fk_field_on_other_model->get_name(), null, true); |
|
113 | 113 | $other_model_obj->save(); |
114 | 114 | } else { |
115 | 115 | $other_model_obj->delete(); |
116 | - $other_model_obj->set($fk_field_on_other_model->get_name(),null,true); |
|
116 | + $other_model_obj->set($fk_field_on_other_model->get_name(), null, true); |
|
117 | 117 | return $other_model_obj; |
118 | 118 | } |
119 | 119 | return $other_model_obj; |
@@ -130,17 +130,17 @@ discard block |
||
130 | 130 | * @return EE_Base_Class[] |
131 | 131 | * @throws \EE_Error |
132 | 132 | */ |
133 | - public function get_all_related( $model_object_or_id, $query_params = array(), $values_already_prepared_by_model_object = false ) { |
|
134 | - if( $values_already_prepared_by_model_object !== false ) { |
|
135 | - EE_Error::doing_it_wrong( 'EE_Model_Relation_Base::get_all_related', __( 'The argument $values_already_prepared_by_model_object is no longer used.', 'event_espresso' ), '4.8.1' ); |
|
133 | + public function get_all_related($model_object_or_id, $query_params = array(), $values_already_prepared_by_model_object = false) { |
|
134 | + if ($values_already_prepared_by_model_object !== false) { |
|
135 | + EE_Error::doing_it_wrong('EE_Model_Relation_Base::get_all_related', __('The argument $values_already_prepared_by_model_object is no longer used.', 'event_espresso'), '4.8.1'); |
|
136 | 136 | } |
137 | 137 | |
138 | 138 | //if this is an autosave then we're going to get things differently |
139 | - if ( defined('DOING_AUTOSAVE') && DOING_AUTOSAVE ) { |
|
140 | - return $this->_do_autosave_get_all($model_object_or_id, $query_params ); |
|
139 | + if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) { |
|
140 | + return $this->_do_autosave_get_all($model_object_or_id, $query_params); |
|
141 | 141 | } |
142 | 142 | |
143 | - return parent::get_all_related( $model_object_or_id, $query_params ); |
|
143 | + return parent::get_all_related($model_object_or_id, $query_params); |
|
144 | 144 | } |
145 | 145 | |
146 | 146 | |
@@ -156,22 +156,22 @@ discard block |
||
156 | 156 | * @return \EE_Base_Class[] |
157 | 157 | * @throws \EE_Error |
158 | 158 | */ |
159 | - protected function _do_autosave_get_all( $model_object_or_id, $query_params, $deprecated = false ) { |
|
159 | + protected function _do_autosave_get_all($model_object_or_id, $query_params, $deprecated = false) { |
|
160 | 160 | |
161 | 161 | //first we check if the post_id for the incoming query is for an autosave. If it isn't that's what we want! |
162 | - $model_object_id = $this->_get_model_object_id( $model_object_or_id ); |
|
162 | + $model_object_id = $this->_get_model_object_id($model_object_or_id); |
|
163 | 163 | |
164 | - $autosave = wp_get_post_autosave( $model_object_id ); |
|
164 | + $autosave = wp_get_post_autosave($model_object_id); |
|
165 | 165 | $id_to_use = $autosave ? $autosave->ID : $model_object_id; |
166 | 166 | |
167 | - $autosave_relations = parent::get_all_related( $id_to_use, $query_params ); |
|
167 | + $autosave_relations = parent::get_all_related($id_to_use, $query_params); |
|
168 | 168 | $parent_ids = $parents = array(); |
169 | 169 | $return_objs = array(); |
170 | 170 | |
171 | 171 | //k this is where things differ because NOW what we're going to do is get the PARENTS for the get all related (and we'll also start setting up the return_objs array containing related that DON'T have parent ids, for those that DON'T have parents to merge with our returned objects); |
172 | - foreach ( $autosave_relations as $a_r ) { |
|
172 | + foreach ($autosave_relations as $a_r) { |
|
173 | 173 | $pid = $a_r->parent(); |
174 | - if ( !empty( $pid ) ) { |
|
174 | + if ( ! empty($pid)) { |
|
175 | 175 | $parent_ids[] = $pid; |
176 | 176 | } else { |
177 | 177 | $return_objs[] = $a_r; |
@@ -179,17 +179,17 @@ discard block |
||
179 | 179 | } |
180 | 180 | |
181 | 181 | //we have to make sure we also include the ORIGINAL values |
182 | - $originals = parent::get_all_related($model_object_or_id, $query_params ); |
|
182 | + $originals = parent::get_all_related($model_object_or_id, $query_params); |
|
183 | 183 | |
184 | 184 | //merge $originals with $return_objs |
185 | - if ( $originals ) { |
|
185 | + if ($originals) { |
|
186 | 186 | $return_objs = array_merge($originals, $return_objs); |
187 | 187 | } |
188 | 188 | |
189 | 189 | //now we setup the query to get all the parents |
190 | - if ( !empty( $parent_ids ) ) { |
|
190 | + if ( ! empty($parent_ids)) { |
|
191 | 191 | $query_param_where_this_model_pk = $this->get_this_model()->get_this_model_name().".".$this->get_this_model()->get_primary_key_field()->get_name(); |
192 | - $query_param[0][$query_param_where_this_model_pk] = array('IN', $parent_ids ); |
|
192 | + $query_param[0][$query_param_where_this_model_pk] = array('IN', $parent_ids); |
|
193 | 193 | $parents = $this->get_other_model()->get_all($query_params); |
194 | 194 | } |
195 | 195 | |
@@ -197,7 +197,7 @@ discard block |
||
197 | 197 | |
198 | 198 | |
199 | 199 | //now merge parents with our current $return_objs and send back |
200 | - return array_merge( $parents, $return_objs ); |
|
200 | + return array_merge($parents, $return_objs); |
|
201 | 201 | } |
202 | 202 | |
203 | 203 | |
@@ -211,42 +211,42 @@ discard block |
||
211 | 211 | * @return EE_Base_Class. ($other_obj); |
212 | 212 | * @throws \EE_Error |
213 | 213 | */ |
214 | - protected function _check_for_revision( $this_obj, $other_obj, $remove_relation = FALSE ) { |
|
214 | + protected function _check_for_revision($this_obj, $other_obj, $remove_relation = FALSE) { |
|
215 | 215 | $pk_on_related_model = $this->get_other_model()->get_primary_key_field()->get_name(); |
216 | 216 | //now we need to determine if we're in a WP revision save cause if we are we need to do some special handling |
217 | - if ( $this_obj->post_type() === 'revision' ) { |
|
217 | + if ($this_obj->post_type() === 'revision') { |
|
218 | 218 | //first if $other_obj fk = this_obj pk then we know that this is a pk object, let's make sure there is a matching set for the autosave if there is then we save over it, if there isn't then we need to create a new one. |
219 | 219 | $parent_evt_id = $this_obj->parent(); |
220 | 220 | /*var_dump($parent_evt_id); |
221 | 221 | var_dump($this_obj); |
222 | 222 | var_dump($other_obj);/**/ |
223 | 223 | |
224 | - if ( !empty($parent_evt_id) && $parent_evt_id == $other_obj->get($this->_primary_cpt_field) ) { |
|
224 | + if ( ! empty($parent_evt_id) && $parent_evt_id == $other_obj->get($this->_primary_cpt_field)) { |
|
225 | 225 | //let's do query on this objects model to see if the incoming pk value on the obj matches any parents in this objects table. |
226 | - $has_parent_obj = $this->get_other_model()->get_one( array( array( $this->_parent_pk_relation_field => $other_obj->ID(), $this->_primary_cpt_field => $this_obj->ID() ) ) ); |
|
226 | + $has_parent_obj = $this->get_other_model()->get_one(array(array($this->_parent_pk_relation_field => $other_obj->ID(), $this->_primary_cpt_field => $this_obj->ID()))); |
|
227 | 227 | |
228 | - if ( $has_parent_obj ) { |
|
228 | + if ($has_parent_obj) { |
|
229 | 229 | //this makes sure the update on the current obj happens to the revision's row NOT the parent row. |
230 | 230 | |
231 | - $other_obj->set( $this->_parent_pk_relation_field, $other_obj->ID()); |
|
232 | - $other_obj->set($pk_on_related_model, $has_parent_obj->ID() ); |
|
231 | + $other_obj->set($this->_parent_pk_relation_field, $other_obj->ID()); |
|
232 | + $other_obj->set($pk_on_related_model, $has_parent_obj->ID()); |
|
233 | 233 | $other_obj->set($this->_primary_cpt_field, $this_obj->ID()); |
234 | 234 | |
235 | - if ( !$remove_relation ) { |
|
235 | + if ( ! $remove_relation) { |
|
236 | 236 | $other_obj->save(); |
237 | - return array( $other_obj ); |
|
238 | - } elseif ( $remove_relation && !$this->_blocking_delete) { |
|
237 | + return array($other_obj); |
|
238 | + } elseif ($remove_relation && ! $this->_blocking_delete) { |
|
239 | 239 | $other_obj->delete(); |
240 | 240 | $other_obj->set($this->_parent_pk_relation_field, NULL, true); |
241 | 241 | return array($other_obj); |
242 | 242 | } |
243 | 243 | |
244 | 244 | } else { |
245 | - $other_obj->set( $this->_parent_pk_relation_field, $other_obj->ID() ); |
|
246 | - $other_obj->set( $this->_primary_cpt_field, $this_obj->ID() ); |
|
245 | + $other_obj->set($this->_parent_pk_relation_field, $other_obj->ID()); |
|
246 | + $other_obj->set($this->_primary_cpt_field, $this_obj->ID()); |
|
247 | 247 | $other_obj->set($pk_on_related_model, NULL, true); //ensure we create a new row for the autosave with parent id the same as the incoming ID. |
248 | 248 | $other_obj->save(); //make sure we insert. |
249 | - return array( $other_obj ); |
|
249 | + return array($other_obj); |
|
250 | 250 | } |
251 | 251 | } |
252 | 252 | |
@@ -259,24 +259,24 @@ discard block |
||
259 | 259 | } else { |
260 | 260 | |
261 | 261 | //we only need to do the below IF this is not a remove relation |
262 | - if ( !$remove_relation ) { |
|
262 | + if ( ! $remove_relation) { |
|
263 | 263 | //okay this is is a normal update/save/remove so, let's make sure the other object is not a revision of the current object. |
264 | 264 | //the other object will likely NOT have the correct fk on it (which is the primary_cpt_field_mame) so we must retrieve from the db to get that first. |
265 | 265 | $existing_other_obj = $this->get_other_model()->get_one_by_ID($other_obj->ID()); |
266 | 266 | $potential_revision_id = is_object($existing_other_obj) ? $existing_other_obj->get($this->_primary_cpt_field) : NULL; |
267 | 267 | |
268 | - if ( $parent_this_obj_id = wp_is_post_revision($potential_revision_id) ) { |
|
268 | + if ($parent_this_obj_id = wp_is_post_revision($potential_revision_id)) { |
|
269 | 269 | //yes the OTHER object is linked to the revision of the parent, not the parent itself. That means we need to make the other_object an attachment of this_obj and then duplicate other_obj for the revision. |
270 | - $other_obj->set($this->_primary_cpt_field, $this_obj->ID() ); |
|
270 | + $other_obj->set($this->_primary_cpt_field, $this_obj->ID()); |
|
271 | 271 | $other_obj->save(); |
272 | 272 | |
273 | 273 | //now create a new other_obj and fill with details from existing object |
274 | 274 | $new_obj = $other_obj; |
275 | - $new_obj->set( $this->_primary_cpt_field, $potential_revision_id ); |
|
276 | - $new_obj->set( $this->_parent_pk_relation_field, $other_obj->ID() ); |
|
277 | - $new_obj->set( $pk_on_related_model, NULL ); |
|
275 | + $new_obj->set($this->_primary_cpt_field, $potential_revision_id); |
|
276 | + $new_obj->set($this->_parent_pk_relation_field, $other_obj->ID()); |
|
277 | + $new_obj->set($pk_on_related_model, NULL); |
|
278 | 278 | $new_obj->save(); |
279 | - return array( $new_obj ); |
|
279 | + return array($new_obj); |
|
280 | 280 | } |
281 | 281 | |
282 | 282 | } |
@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php |
2 | -require_once( EE_MODELS . 'relations/EE_Belongs_To_Relation.php'); |
|
2 | +require_once(EE_MODELS.'relations/EE_Belongs_To_Relation.php'); |
|
3 | 3 | |
4 | 4 | |
5 | 5 | |
@@ -23,7 +23,7 @@ discard block |
||
23 | 23 | * @return string |
24 | 24 | * @throws \EE_Error |
25 | 25 | */ |
26 | - public function get_join_statement( $model_relation_chain) { |
|
26 | + public function get_join_statement($model_relation_chain) { |
|
27 | 27 | //create the sql string like |
28 | 28 | $this_table_fk_field = $this->get_this_model()->get_foreign_key_to($this->get_other_model()->get_this_model_name()); |
29 | 29 | //ALSO, need to get the field with the model name |
@@ -31,8 +31,8 @@ discard block |
||
31 | 31 | |
32 | 32 | |
33 | 33 | $other_table_pk_field = $this->get_other_model()->get_primary_key_field(); |
34 | - $this_table_alias = EE_Model_Parser::extract_table_alias_model_relation_chain_prefix($model_relation_chain,$this->get_this_model()->get_this_model_name()) . $this_table_fk_field->get_table_alias(); |
|
35 | - $other_table_alias = EE_Model_Parser::extract_table_alias_model_relation_chain_prefix($model_relation_chain, $this->get_other_model()->get_this_model_name()) . $other_table_pk_field->get_table_alias(); |
|
34 | + $this_table_alias = EE_Model_Parser::extract_table_alias_model_relation_chain_prefix($model_relation_chain, $this->get_this_model()->get_this_model_name()).$this_table_fk_field->get_table_alias(); |
|
35 | + $other_table_alias = EE_Model_Parser::extract_table_alias_model_relation_chain_prefix($model_relation_chain, $this->get_other_model()->get_this_model_name()).$other_table_pk_field->get_table_alias(); |
|
36 | 36 | $other_table = $this->get_other_model()->get_table_for_alias($other_table_alias); |
37 | 37 | return $this->_left_join($other_table, |
38 | 38 | $other_table_alias, |
@@ -80,12 +80,12 @@ discard block |
||
80 | 80 | */ |
81 | 81 | public function remove_relation_to($this_obj_or_id, $other_obj_or_id, $where_query = array()) { |
82 | 82 | $this_model_obj = $this->get_this_model()->ensure_is_obj($this_obj_or_id, true); |
83 | - $other_model_obj = $this->get_other_model()->ensure_is_obj( $other_obj_or_id ); |
|
83 | + $other_model_obj = $this->get_other_model()->ensure_is_obj($other_obj_or_id); |
|
84 | 84 | //find the field on the other model which is a foreign key to this model |
85 | 85 | $fk_on_this_model = $this->get_this_model()->get_foreign_key_to($this->get_other_model()->get_this_model_name()); |
86 | 86 | //set that field on the other model to this model's ID |
87 | 87 | $this_model_obj->set($fk_on_this_model->get_name(), null, true); |
88 | - $this_model_obj->set($this->get_this_model()->get_field_containing_related_model_name()->get_name(),null,true); |
|
88 | + $this_model_obj->set($this->get_this_model()->get_field_containing_related_model_name()->get_name(), null, true); |
|
89 | 89 | $this_model_obj->save(); |
90 | 90 | return $other_model_obj; |
91 | 91 | } |
@@ -4,7 +4,7 @@ discard block |
||
4 | 4 | /* |
5 | 5 | * |
6 | 6 | */ |
7 | -require_once( EE_MODELS . 'relations/EE_Model_Relation_Base.php'); |
|
7 | +require_once(EE_MODELS.'relations/EE_Model_Relation_Base.php'); |
|
8 | 8 | |
9 | 9 | |
10 | 10 | |
@@ -19,7 +19,7 @@ discard block |
||
19 | 19 | * @subpackage core |
20 | 20 | * @author Michael Nelson |
21 | 21 | */ |
22 | -class EE_Has_Many_Any_Relation extends EE_Has_Many_Relation{ |
|
22 | +class EE_Has_Many_Any_Relation extends EE_Has_Many_Relation { |
|
23 | 23 | |
24 | 24 | /** |
25 | 25 | * Gets the SQL string for performing the join between this model and the other model. |
@@ -28,13 +28,13 @@ discard block |
||
28 | 28 | * @return string of SQL, eg "LEFT JOIN table_name AS table_alias ON this_model_primary_table.pk = other_model_primary_table.fk" etc |
29 | 29 | * @throws \EE_Error |
30 | 30 | */ |
31 | - public function get_join_statement( $model_relation_chain){ |
|
31 | + public function get_join_statement($model_relation_chain) { |
|
32 | 32 | //create the sql string like |
33 | 33 | // LEFT JOIN other_table AS table_alias ON this_table_alias.pk = other_table_alias.fk extra_join_conditions |
34 | 34 | $this_table_pk_field = $this->get_this_model()->get_primary_key_field(); |
35 | 35 | $other_table_fk_field = $this->get_other_model()->get_foreign_key_to($this->get_this_model()->get_this_model_name()); |
36 | - $pk_table_alias = EE_Model_Parser::extract_table_alias_model_relation_chain_prefix($model_relation_chain, $this->get_this_model()->get_this_model_name()) . $this_table_pk_field->get_table_alias(); |
|
37 | - $fk_table_alias = EE_Model_Parser::extract_table_alias_model_relation_chain_prefix($model_relation_chain, $this->get_other_model()->get_this_model_name()) . $other_table_fk_field->get_table_alias(); |
|
36 | + $pk_table_alias = EE_Model_Parser::extract_table_alias_model_relation_chain_prefix($model_relation_chain, $this->get_this_model()->get_this_model_name()).$this_table_pk_field->get_table_alias(); |
|
37 | + $fk_table_alias = EE_Model_Parser::extract_table_alias_model_relation_chain_prefix($model_relation_chain, $this->get_other_model()->get_this_model_name()).$other_table_fk_field->get_table_alias(); |
|
38 | 38 | $fk_table = $this->get_other_model()->get_table_for_alias($fk_table_alias); |
39 | 39 | $field_with_model_name = $this->get_other_model()->get_field_containing_related_model_name(); |
40 | 40 | |
@@ -43,7 +43,7 @@ discard block |
||
43 | 43 | $other_table_fk_field->get_table_column(), |
44 | 44 | $pk_table_alias, |
45 | 45 | $this_table_pk_field->get_table_column(), |
46 | - $fk_table_alias . '.' . $field_with_model_name->get_table_column() . "='" . $this->get_this_model()->get_this_model_name() . "'" ) |
|
46 | + $fk_table_alias.'.'.$field_with_model_name->get_table_column()."='".$this->get_this_model()->get_this_model_name()."'") |
|
47 | 47 | .$this->get_other_model()->_construct_internal_join_to_table_with_alias($fk_table_alias); |
48 | 48 | } |
49 | 49 | |
@@ -58,7 +58,7 @@ discard block |
||
58 | 58 | * @return \EE_Base_Class |
59 | 59 | * @throws \EE_Error |
60 | 60 | */ |
61 | - public function add_relation_to($this_obj_or_id, $other_obj_or_id, $extra_join_model_fields_n_values = array() ){ |
|
61 | + public function add_relation_to($this_obj_or_id, $other_obj_or_id, $extra_join_model_fields_n_values = array()) { |
|
62 | 62 | $this_model_obj = $this->get_this_model()->ensure_is_obj($this_obj_or_id, true); |
63 | 63 | $other_model_obj = $this->get_other_model()->ensure_is_obj($other_obj_or_id, true); |
64 | 64 | |
@@ -83,12 +83,12 @@ discard block |
||
83 | 83 | * @return \EE_Base_Class |
84 | 84 | * @throws \EE_Error |
85 | 85 | */ |
86 | - public function remove_relation_to($this_obj_or_id, $other_obj_or_id, $where_query = array()){ |
|
86 | + public function remove_relation_to($this_obj_or_id, $other_obj_or_id, $where_query = array()) { |
|
87 | 87 | $other_model_obj = $this->get_other_model()->ensure_is_obj($other_obj_or_id, true); |
88 | 88 | //find the field on the other model which is a foreign key to this model |
89 | 89 | $fk_field_on_other_model = $this->get_other_model()->get_foreign_key_to($this->get_this_model()->get_this_model_name()); |
90 | 90 | //set that field on the other model to this model's ID |
91 | - $other_model_obj->set($fk_field_on_other_model->get_name(),null, true); |
|
91 | + $other_model_obj->set($fk_field_on_other_model->get_name(), null, true); |
|
92 | 92 | $other_model_obj->set($this->get_other_model()->get_field_containing_related_model_name()->get_name(), null, true); |
93 | 93 | $other_model_obj->save(); |
94 | 94 | return $other_model_obj; |
@@ -131,8 +131,7 @@ discard block |
||
131 | 131 | return; |
132 | 132 | } |
133 | 133 | echo '<h5>For Tag: '. $tag .'</h5>'; |
134 | - } |
|
135 | - else { |
|
134 | + } else { |
|
136 | 135 | $hook=$wp_filter; |
137 | 136 | ksort( $hook ); |
138 | 137 | } |
@@ -200,7 +199,7 @@ discard block |
||
200 | 199 | if( isset( $this->_start_times[ $timer_name ] ) ){ |
201 | 200 | $start_time = $this->_start_times[ $timer_name ]; |
202 | 201 | unset( $this->_start_times[ $timer_name ] ); |
203 | - }else{ |
|
202 | + } else{ |
|
204 | 203 | $start_time = array_pop( $this->_start_times ); |
205 | 204 | } |
206 | 205 | $total_time = microtime( TRUE ) - $start_time; |
@@ -187,7 +187,7 @@ discard block |
||
187 | 187 | |
188 | 188 | /** |
189 | 189 | * start_timer |
190 | - * @param null $timer_name |
|
190 | + * @param string $timer_name |
|
191 | 191 | */ |
192 | 192 | public function start_timer( $timer_name = NULL ){ |
193 | 193 | $this->_start_times[$timer_name] = microtime( TRUE ); |
@@ -444,7 +444,7 @@ discard block |
||
444 | 444 | |
445 | 445 | |
446 | 446 | /** |
447 | - * @param mixed $var |
|
447 | + * @param string $var |
|
448 | 448 | * @param string $var_name |
449 | 449 | * @param string $file |
450 | 450 | * @param int $line |
@@ -1,4 +1,4 @@ discard block |
||
1 | -<?php if ( ! defined('EVENT_ESPRESSO_VERSION')) {exit('No direct script access allowed');} |
|
1 | +<?php if ( ! defined('EVENT_ESPRESSO_VERSION')) {exit('No direct script access allowed'); } |
|
2 | 2 | /** |
3 | 3 | * Class EEH_Debug_Tools |
4 | 4 | * |
@@ -8,7 +8,7 @@ discard block |
||
8 | 8 | * @since 4.0 |
9 | 9 | * |
10 | 10 | */ |
11 | -class EEH_Debug_Tools{ |
|
11 | +class EEH_Debug_Tools { |
|
12 | 12 | |
13 | 13 | /** |
14 | 14 | * instance of the EEH_Autoloader object |
@@ -41,7 +41,7 @@ discard block |
||
41 | 41 | */ |
42 | 42 | public static function instance() { |
43 | 43 | // check if class object is instantiated, and instantiated properly |
44 | - if ( ! self::$_instance instanceof EEH_Debug_Tools ) { |
|
44 | + if ( ! self::$_instance instanceof EEH_Debug_Tools) { |
|
45 | 45 | self::$_instance = new self(); |
46 | 46 | } |
47 | 47 | return self::$_instance; |
@@ -57,21 +57,21 @@ discard block |
||
57 | 57 | */ |
58 | 58 | private function __construct() { |
59 | 59 | // load Kint PHP debugging library |
60 | - if ( ! class_exists( 'Kint' ) && file_exists( EE_PLUGIN_DIR_PATH . 'tests' . DS . 'kint' . DS . 'Kint.class.php' )){ |
|
60 | + if ( ! class_exists('Kint') && file_exists(EE_PLUGIN_DIR_PATH.'tests'.DS.'kint'.DS.'Kint.class.php')) { |
|
61 | 61 | // despite EE4 having a check for an existing copy of the Kint debugging class, |
62 | 62 | // if another plugin was loaded AFTER EE4 and they did NOT perform a similar check, |
63 | 63 | // then hilarity would ensue as PHP throws a "Cannot redeclare class Kint" error |
64 | 64 | // so we've moved it to our test folder so that it is not included with production releases |
65 | 65 | // plz use https://wordpress.org/plugins/kint-debugger/ if testing production versions of EE |
66 | - require_once( EE_PLUGIN_DIR_PATH . 'tests' . DS . 'kint' . DS . 'Kint.class.php' ); |
|
66 | + require_once(EE_PLUGIN_DIR_PATH.'tests'.DS.'kint'.DS.'Kint.class.php'); |
|
67 | 67 | } |
68 | 68 | // if ( ! defined('DOING_AJAX') || $_REQUEST['noheader'] !== 'true' || ! isset( $_REQUEST['noheader'], $_REQUEST['TB_iframe'] ) ) { |
69 | 69 | //add_action( 'shutdown', array($this,'espresso_session_footer_dump') ); |
70 | 70 | // } |
71 | - $plugin = basename( EE_PLUGIN_DIR_PATH ); |
|
72 | - add_action( "activate_{$plugin}", array( 'EEH_Debug_Tools', 'ee_plugin_activation_errors' )); |
|
73 | - add_action( 'activated_plugin', array( 'EEH_Debug_Tools', 'ee_plugin_activation_errors' )); |
|
74 | - add_action( 'shutdown', array( 'EEH_Debug_Tools', 'show_db_name' )); |
|
71 | + $plugin = basename(EE_PLUGIN_DIR_PATH); |
|
72 | + add_action("activate_{$plugin}", array('EEH_Debug_Tools', 'ee_plugin_activation_errors')); |
|
73 | + add_action('activated_plugin', array('EEH_Debug_Tools', 'ee_plugin_activation_errors')); |
|
74 | + add_action('shutdown', array('EEH_Debug_Tools', 'show_db_name')); |
|
75 | 75 | } |
76 | 76 | |
77 | 77 | |
@@ -82,10 +82,10 @@ discard block |
||
82 | 82 | * @return void |
83 | 83 | */ |
84 | 84 | public static function show_db_name() { |
85 | - if ( ! defined( 'DOING_AJAX' ) && ( defined( 'EE_ERROR_EMAILS' ) && EE_ERROR_EMAILS )) { |
|
86 | - echo '<p style="font-size:10px;font-weight:normal;color:#E76700;margin: 1em 2em; text-align: right;">DB_NAME: '. DB_NAME .'</p>'; |
|
85 | + if ( ! defined('DOING_AJAX') && (defined('EE_ERROR_EMAILS') && EE_ERROR_EMAILS)) { |
|
86 | + echo '<p style="font-size:10px;font-weight:normal;color:#E76700;margin: 1em 2em; text-align: right;">DB_NAME: '.DB_NAME.'</p>'; |
|
87 | 87 | } |
88 | - if ( EE_DEBUG ) { |
|
88 | + if (EE_DEBUG) { |
|
89 | 89 | EEH_Debug_Tools::instance()->show_times(); |
90 | 90 | } |
91 | 91 | } |
@@ -99,15 +99,15 @@ discard block |
||
99 | 99 | */ |
100 | 100 | public function espresso_session_footer_dump() { |
101 | 101 | if ( |
102 | - ( defined( 'WP_DEBUG' ) && WP_DEBUG ) |
|
103 | - && ! defined( 'DOING_AJAX' ) |
|
104 | - && class_exists( 'Kint' ) |
|
105 | - && function_exists( 'wp_get_current_user' ) |
|
106 | - && current_user_can( 'update_core' ) |
|
107 | - && class_exists( 'EE_Registry' ) |
|
102 | + (defined('WP_DEBUG') && WP_DEBUG) |
|
103 | + && ! defined('DOING_AJAX') |
|
104 | + && class_exists('Kint') |
|
105 | + && function_exists('wp_get_current_user') |
|
106 | + && current_user_can('update_core') |
|
107 | + && class_exists('EE_Registry') |
|
108 | 108 | ) { |
109 | - Kint::dump( EE_Registry::instance()->SSN->id() ); |
|
110 | - Kint::dump( EE_Registry::instance()->SSN ); |
|
109 | + Kint::dump(EE_Registry::instance()->SSN->id()); |
|
110 | + Kint::dump(EE_Registry::instance()->SSN); |
|
111 | 111 | // Kint::dump( EE_Registry::instance()->SSN->get_session_data('cart')->get_tickets() ); |
112 | 112 | $this->espresso_list_hooked_functions(); |
113 | 113 | $this->show_times(); |
@@ -124,27 +124,27 @@ discard block |
||
124 | 124 | * @param string $tag |
125 | 125 | * @return void |
126 | 126 | */ |
127 | - public function espresso_list_hooked_functions( $tag='' ){ |
|
127 | + public function espresso_list_hooked_functions($tag = '') { |
|
128 | 128 | global $wp_filter; |
129 | 129 | echo '<br/><br/><br/><h3>Hooked Functions</h3>'; |
130 | - if ( $tag ) { |
|
131 | - $hook[$tag]=$wp_filter[$tag]; |
|
132 | - if ( ! is_array( $hook[$tag] )) { |
|
133 | - trigger_error( "Nothing found for '$tag' hook", E_USER_WARNING ); |
|
130 | + if ($tag) { |
|
131 | + $hook[$tag] = $wp_filter[$tag]; |
|
132 | + if ( ! is_array($hook[$tag])) { |
|
133 | + trigger_error("Nothing found for '$tag' hook", E_USER_WARNING); |
|
134 | 134 | return; |
135 | 135 | } |
136 | - echo '<h5>For Tag: '. $tag .'</h5>'; |
|
136 | + echo '<h5>For Tag: '.$tag.'</h5>'; |
|
137 | 137 | } |
138 | 138 | else { |
139 | - $hook=$wp_filter; |
|
140 | - ksort( $hook ); |
|
139 | + $hook = $wp_filter; |
|
140 | + ksort($hook); |
|
141 | 141 | } |
142 | - foreach( $hook as $tag_name => $priorities ) { |
|
142 | + foreach ($hook as $tag_name => $priorities) { |
|
143 | 143 | echo "<br />>>>>>\t<strong>$tag_name</strong><br />"; |
144 | - ksort( $priorities ); |
|
145 | - foreach( $priorities as $priority => $function ){ |
|
144 | + ksort($priorities); |
|
145 | + foreach ($priorities as $priority => $function) { |
|
146 | 146 | echo $priority; |
147 | - foreach( $function as $name => $properties ) { |
|
147 | + foreach ($function as $name => $properties) { |
|
148 | 148 | echo "\t$name<br />"; |
149 | 149 | } |
150 | 150 | } |
@@ -159,15 +159,15 @@ discard block |
||
159 | 159 | * @param string $hook_name |
160 | 160 | * @return array |
161 | 161 | */ |
162 | - public static function registered_filter_callbacks( $hook_name = '' ) { |
|
162 | + public static function registered_filter_callbacks($hook_name = '') { |
|
163 | 163 | $filters = array(); |
164 | 164 | global $wp_filter; |
165 | - if ( isset( $wp_filter[ $hook_name ] ) ) { |
|
166 | - $filters[ $hook_name ] = array(); |
|
167 | - foreach ( $wp_filter[ $hook_name ] as $priority => $callbacks ) { |
|
168 | - $filters[ $hook_name ][ $priority ] = array(); |
|
169 | - foreach ( $callbacks as $callback ) { |
|
170 | - $filters[ $hook_name ][ $priority ][] = $callback['function']; |
|
165 | + if (isset($wp_filter[$hook_name])) { |
|
166 | + $filters[$hook_name] = array(); |
|
167 | + foreach ($wp_filter[$hook_name] as $priority => $callbacks) { |
|
168 | + $filters[$hook_name][$priority] = array(); |
|
169 | + foreach ($callbacks as $callback) { |
|
170 | + $filters[$hook_name][$priority][] = $callback['function']; |
|
171 | 171 | } |
172 | 172 | } |
173 | 173 | } |
@@ -179,7 +179,7 @@ discard block |
||
179 | 179 | /** |
180 | 180 | * reset_times |
181 | 181 | */ |
182 | - public function reset_times(){ |
|
182 | + public function reset_times() { |
|
183 | 183 | $this->_times = array(); |
184 | 184 | } |
185 | 185 | |
@@ -189,8 +189,8 @@ discard block |
||
189 | 189 | * start_timer |
190 | 190 | * @param null $timer_name |
191 | 191 | */ |
192 | - public function start_timer( $timer_name = NULL ){ |
|
193 | - $this->_start_times[$timer_name] = microtime( TRUE ); |
|
192 | + public function start_timer($timer_name = NULL) { |
|
193 | + $this->_start_times[$timer_name] = microtime(TRUE); |
|
194 | 194 | } |
195 | 195 | |
196 | 196 | |
@@ -199,15 +199,15 @@ discard block |
||
199 | 199 | * stop_timer |
200 | 200 | * @param string $timer_name |
201 | 201 | */ |
202 | - public function stop_timer( $timer_name = '' ){ |
|
202 | + public function stop_timer($timer_name = '') { |
|
203 | 203 | $timer_name = $timer_name !== '' ? $timer_name : get_called_class(); |
204 | - if( isset( $this->_start_times[ $timer_name ] ) ){ |
|
205 | - $start_time = $this->_start_times[ $timer_name ]; |
|
206 | - unset( $this->_start_times[ $timer_name ] ); |
|
207 | - }else{ |
|
208 | - $start_time = array_pop( $this->_start_times ); |
|
204 | + if (isset($this->_start_times[$timer_name])) { |
|
205 | + $start_time = $this->_start_times[$timer_name]; |
|
206 | + unset($this->_start_times[$timer_name]); |
|
207 | + } else { |
|
208 | + $start_time = array_pop($this->_start_times); |
|
209 | 209 | } |
210 | - $this->_times[ $timer_name ] = number_format( microtime( true ) - $start_time, 8 ); |
|
210 | + $this->_times[$timer_name] = number_format(microtime(true) - $start_time, 8); |
|
211 | 211 | } |
212 | 212 | |
213 | 213 | |
@@ -217,10 +217,10 @@ discard block |
||
217 | 217 | * @param boolean $output_now whether to echo now, or wait until EEH_Debug_Tools::show_times() is called |
218 | 218 | * @return void |
219 | 219 | */ |
220 | - public function measure_memory( $label, $output_now = false ) { |
|
221 | - $memory_used = $this->convert( memory_get_peak_usage( true ) ); |
|
222 | - $this->_memory_usage_points[ $label ] = $memory_used; |
|
223 | - if( $output_now ) { |
|
220 | + public function measure_memory($label, $output_now = false) { |
|
221 | + $memory_used = $this->convert(memory_get_peak_usage(true)); |
|
222 | + $this->_memory_usage_points[$label] = $memory_used; |
|
223 | + if ($output_now) { |
|
224 | 224 | echo "\r\n<br>$label : $memory_used"; |
225 | 225 | } |
226 | 226 | } |
@@ -230,9 +230,9 @@ discard block |
||
230 | 230 | * @param int $size |
231 | 231 | * @return string |
232 | 232 | */ |
233 | - public function convert( $size ) { |
|
234 | - $unit=array('b','kb','mb','gb','tb','pb'); |
|
235 | - return @round( $size / pow( 1024, $i = floor( log( $size, 1024 ) ) ), 2 ) . ' ' . $unit[ absint( $i ) ]; |
|
233 | + public function convert($size) { |
|
234 | + $unit = array('b', 'kb', 'mb', 'gb', 'tb', 'pb'); |
|
235 | + return @round($size / pow(1024, $i = floor(log($size, 1024))), 2).' '.$unit[absint($i)]; |
|
236 | 236 | } |
237 | 237 | |
238 | 238 | |
@@ -242,25 +242,25 @@ discard block |
||
242 | 242 | * @param bool $output_now |
243 | 243 | * @return string |
244 | 244 | */ |
245 | - public function show_times($output_now=true){ |
|
245 | + public function show_times($output_now = true) { |
|
246 | 246 | $output = ''; |
247 | - if ( ! empty( $this->_times )) { |
|
247 | + if ( ! empty($this->_times)) { |
|
248 | 248 | $total = 0; |
249 | 249 | $output .= '<h2 style="margin:1em .5em 0;">Times:</h2>'; |
250 | 250 | $output .= '<span style="color:#9999CC; font-size:.8em; margin:0 1.5em 0;">( in milliseconds )</span><br />'; |
251 | - foreach( $this->_times as $timer_name => $total_time ) { |
|
252 | - $output .= $this->format_time( $timer_name, $total_time ); |
|
251 | + foreach ($this->_times as $timer_name => $total_time) { |
|
252 | + $output .= $this->format_time($timer_name, $total_time); |
|
253 | 253 | $total += $total_time; |
254 | 254 | } |
255 | 255 | $output .= '<br />'; |
256 | 256 | $output .= '<h4 style="margin:1em .5em 0;">TOTAL TIME</h4>'; |
257 | - $output .= $this->format_time( '', $total ); |
|
257 | + $output .= $this->format_time('', $total); |
|
258 | 258 | $output .= '<br />'; |
259 | 259 | } |
260 | - if ( ! empty( $this->_memory_usage_points )) { |
|
261 | - $output .= '<h2 style="margin:1em .5em 0;">Memory</h2>' . implode( '<br />', $this->_memory_usage_points ); |
|
260 | + if ( ! empty($this->_memory_usage_points)) { |
|
261 | + $output .= '<h2 style="margin:1em .5em 0;">Memory</h2>'.implode('<br />', $this->_memory_usage_points); |
|
262 | 262 | } |
263 | - if( $output_now ){ |
|
263 | + if ($output_now) { |
|
264 | 264 | echo $output; |
265 | 265 | return ''; |
266 | 266 | } |
@@ -274,9 +274,9 @@ discard block |
||
274 | 274 | * @param float $total_time |
275 | 275 | * @return string |
276 | 276 | */ |
277 | - public function format_time( $timer_name, $total_time ) { |
|
277 | + public function format_time($timer_name, $total_time) { |
|
278 | 278 | $total_time = $total_time * 1000; |
279 | - switch ( $total_time ) { |
|
279 | + switch ($total_time) { |
|
280 | 280 | case $total_time < 0.01 : |
281 | 281 | $color = '#8A549A'; |
282 | 282 | $bold = 'normal'; |
@@ -307,7 +307,7 @@ discard block |
||
307 | 307 | . '; font-weight:' |
308 | 308 | . $bold |
309 | 309 | . '; font-size:1.2em;">' |
310 | - . str_pad( number_format( $total_time, 5 ), 11, '0', STR_PAD_LEFT ) |
|
310 | + . str_pad(number_format($total_time, 5), 11, '0', STR_PAD_LEFT) |
|
311 | 311 | . '</span> ' |
312 | 312 | . $timer_name |
313 | 313 | . '<br />'; |
@@ -321,25 +321,25 @@ discard block |
||
321 | 321 | * @return void |
322 | 322 | */ |
323 | 323 | public static function ee_plugin_activation_errors() { |
324 | - if ( WP_DEBUG ) { |
|
324 | + if (WP_DEBUG) { |
|
325 | 325 | $activation_errors = ob_get_contents(); |
326 | - if ( ! empty( $activation_errors ) ) { |
|
327 | - $activation_errors = date( 'Y-m-d H:i:s' ) . "\n" . $activation_errors; |
|
326 | + if ( ! empty($activation_errors)) { |
|
327 | + $activation_errors = date('Y-m-d H:i:s')."\n".$activation_errors; |
|
328 | 328 | } |
329 | - espresso_load_required( 'EEH_File', EE_HELPERS . 'EEH_File.helper.php' ); |
|
330 | - if ( class_exists( 'EEH_File' )) { |
|
329 | + espresso_load_required('EEH_File', EE_HELPERS.'EEH_File.helper.php'); |
|
330 | + if (class_exists('EEH_File')) { |
|
331 | 331 | try { |
332 | - EEH_File::ensure_file_exists_and_is_writable( EVENT_ESPRESSO_UPLOAD_DIR . 'logs' . DS . 'espresso_plugin_activation_errors.html' ); |
|
333 | - EEH_File::write_to_file( EVENT_ESPRESSO_UPLOAD_DIR . 'logs' . DS . 'espresso_plugin_activation_errors.html', $activation_errors ); |
|
334 | - } catch( EE_Error $e ){ |
|
335 | - EE_Error::add_error( sprintf( __( 'The Event Espresso activation errors file could not be setup because: %s', 'event_espresso' ), $e->getMessage() ), __FILE__, __FUNCTION__, __LINE__ ); |
|
332 | + EEH_File::ensure_file_exists_and_is_writable(EVENT_ESPRESSO_UPLOAD_DIR.'logs'.DS.'espresso_plugin_activation_errors.html'); |
|
333 | + EEH_File::write_to_file(EVENT_ESPRESSO_UPLOAD_DIR.'logs'.DS.'espresso_plugin_activation_errors.html', $activation_errors); |
|
334 | + } catch (EE_Error $e) { |
|
335 | + EE_Error::add_error(sprintf(__('The Event Espresso activation errors file could not be setup because: %s', 'event_espresso'), $e->getMessage()), __FILE__, __FUNCTION__, __LINE__); |
|
336 | 336 | } |
337 | 337 | } else { |
338 | 338 | // old school attempt |
339 | - file_put_contents( EVENT_ESPRESSO_UPLOAD_DIR . 'logs' . DS . 'espresso_plugin_activation_errors.html', $activation_errors ); |
|
339 | + file_put_contents(EVENT_ESPRESSO_UPLOAD_DIR.'logs'.DS.'espresso_plugin_activation_errors.html', $activation_errors); |
|
340 | 340 | } |
341 | - $activation_errors = get_option( 'ee_plugin_activation_errors', '' ) . $activation_errors; |
|
342 | - update_option( 'ee_plugin_activation_errors', $activation_errors ); |
|
341 | + $activation_errors = get_option('ee_plugin_activation_errors', '').$activation_errors; |
|
342 | + update_option('ee_plugin_activation_errors', $activation_errors); |
|
343 | 343 | } |
344 | 344 | } |
345 | 345 | |
@@ -355,22 +355,22 @@ discard block |
||
355 | 355 | * @param int $error_type |
356 | 356 | * @uses trigger_error() |
357 | 357 | */ |
358 | - public function doing_it_wrong( $function, $message, $version, $error_type = E_USER_NOTICE ) { |
|
359 | - do_action( 'AHEE__EEH_Debug_Tools__doing_it_wrong_run', $function, $message, $version); |
|
360 | - $version = $version === null ? '' : sprintf( __('(This message was added in version %s of Event Espresso.', 'event_espresso' ), $version ); |
|
361 | - $error_message = sprintf( esc_html__('%1$s was called %2$sincorrectly%3$s. %4$s %5$s','event_espresso' ), $function, '<strong>', '</strong>', $message, $version ); |
|
358 | + public function doing_it_wrong($function, $message, $version, $error_type = E_USER_NOTICE) { |
|
359 | + do_action('AHEE__EEH_Debug_Tools__doing_it_wrong_run', $function, $message, $version); |
|
360 | + $version = $version === null ? '' : sprintf(__('(This message was added in version %s of Event Espresso.', 'event_espresso'), $version); |
|
361 | + $error_message = sprintf(esc_html__('%1$s was called %2$sincorrectly%3$s. %4$s %5$s', 'event_espresso'), $function, '<strong>', '</strong>', $message, $version); |
|
362 | 362 | |
363 | 363 | //don't trigger error if doing ajax, instead we'll add a transient EE_Error notice that in theory should show on the next request. |
364 | - if ( defined( 'DOING_AJAX' ) && DOING_AJAX ) { |
|
365 | - $error_message .= ' ' . esc_html__( 'This is a doing_it_wrong message that was triggered during an ajax request. The request params on this request were: ', 'event_espresso' ); |
|
364 | + if (defined('DOING_AJAX') && DOING_AJAX) { |
|
365 | + $error_message .= ' '.esc_html__('This is a doing_it_wrong message that was triggered during an ajax request. The request params on this request were: ', 'event_espresso'); |
|
366 | 366 | $error_message .= '<ul><li>'; |
367 | - $error_message .= implode( '</li><li>', EE_Registry::instance()->REQ->params() ); |
|
367 | + $error_message .= implode('</li><li>', EE_Registry::instance()->REQ->params()); |
|
368 | 368 | $error_message .= '</ul>'; |
369 | - EE_Error::add_error( $error_message, 'debug::doing_it_wrong', $function, '42' ); |
|
369 | + EE_Error::add_error($error_message, 'debug::doing_it_wrong', $function, '42'); |
|
370 | 370 | //now we set this on the transient so it shows up on the next request. |
371 | - EE_Error::get_notices( false, true ); |
|
371 | + EE_Error::get_notices(false, true); |
|
372 | 372 | } else { |
373 | - trigger_error( $error_message, $error_type ); |
|
373 | + trigger_error($error_message, $error_type); |
|
374 | 374 | } |
375 | 375 | } |
376 | 376 | |
@@ -392,22 +392,22 @@ discard block |
||
392 | 392 | * @param string $debug_index |
393 | 393 | * @param string $debug_key |
394 | 394 | */ |
395 | - public static function log( $class='', $func = '', $line = '', $info = array(), $display_request = false, $debug_index = '', $debug_key = 'EE_DEBUG_SPCO' ) { |
|
396 | - if ( WP_DEBUG && false ) { |
|
397 | - $debug_key = $debug_key . '_' . EE_Session::instance()->id(); |
|
398 | - $debug_data = get_option( $debug_key, array() ); |
|
395 | + public static function log($class = '', $func = '', $line = '', $info = array(), $display_request = false, $debug_index = '', $debug_key = 'EE_DEBUG_SPCO') { |
|
396 | + if (WP_DEBUG && false) { |
|
397 | + $debug_key = $debug_key.'_'.EE_Session::instance()->id(); |
|
398 | + $debug_data = get_option($debug_key, array()); |
|
399 | 399 | $default_data = array( |
400 | - $class => $func . '() : ' . $line, |
|
400 | + $class => $func.'() : '.$line, |
|
401 | 401 | 'REQ' => $display_request ? $_REQUEST : '', |
402 | 402 | ); |
403 | 403 | // don't serialize objects |
404 | - $info = self::strip_objects( $info ); |
|
405 | - $index = ! empty( $debug_index ) ? $debug_index : 0; |
|
406 | - if ( ! isset( $debug_data[$index] ) ) { |
|
404 | + $info = self::strip_objects($info); |
|
405 | + $index = ! empty($debug_index) ? $debug_index : 0; |
|
406 | + if ( ! isset($debug_data[$index])) { |
|
407 | 407 | $debug_data[$index] = array(); |
408 | 408 | } |
409 | - $debug_data[$index][microtime()] = array_merge( $default_data, $info ); |
|
410 | - update_option( $debug_key, $debug_data ); |
|
409 | + $debug_data[$index][microtime()] = array_merge($default_data, $info); |
|
410 | + update_option($debug_key, $debug_data); |
|
411 | 411 | } |
412 | 412 | } |
413 | 413 | |
@@ -419,26 +419,26 @@ discard block |
||
419 | 419 | * @param array $info |
420 | 420 | * @return array |
421 | 421 | */ |
422 | - public static function strip_objects( $info = array() ) { |
|
423 | - foreach ( $info as $key => $value ) { |
|
424 | - if ( is_array( $value ) ) { |
|
425 | - $info[ $key ] = self::strip_objects( $value ); |
|
426 | - } else if ( is_object( $value ) ) { |
|
427 | - $object_class = get_class( $value ); |
|
428 | - $info[ $object_class ] = array(); |
|
429 | - $info[ $object_class ][ 'ID' ] = method_exists( $value, 'ID' ) ? $value->ID() : spl_object_hash( $value ); |
|
430 | - if ( method_exists( $value, 'ID' ) ) { |
|
431 | - $info[ $object_class ][ 'ID' ] = $value->ID(); |
|
422 | + public static function strip_objects($info = array()) { |
|
423 | + foreach ($info as $key => $value) { |
|
424 | + if (is_array($value)) { |
|
425 | + $info[$key] = self::strip_objects($value); |
|
426 | + } else if (is_object($value)) { |
|
427 | + $object_class = get_class($value); |
|
428 | + $info[$object_class] = array(); |
|
429 | + $info[$object_class]['ID'] = method_exists($value, 'ID') ? $value->ID() : spl_object_hash($value); |
|
430 | + if (method_exists($value, 'ID')) { |
|
431 | + $info[$object_class]['ID'] = $value->ID(); |
|
432 | 432 | } |
433 | - if ( method_exists( $value, 'status' ) ) { |
|
434 | - $info[ $object_class ][ 'status' ] = $value->status(); |
|
435 | - } else if ( method_exists( $value, 'status_ID' ) ) { |
|
436 | - $info[ $object_class ][ 'status' ] = $value->status_ID(); |
|
433 | + if (method_exists($value, 'status')) { |
|
434 | + $info[$object_class]['status'] = $value->status(); |
|
435 | + } else if (method_exists($value, 'status_ID')) { |
|
436 | + $info[$object_class]['status'] = $value->status_ID(); |
|
437 | 437 | } |
438 | - unset( $info[ $key ] ); |
|
438 | + unset($info[$key]); |
|
439 | 439 | } |
440 | 440 | } |
441 | - return (array)$info; |
|
441 | + return (array) $info; |
|
442 | 442 | } |
443 | 443 | |
444 | 444 | |
@@ -451,23 +451,23 @@ discard block |
||
451 | 451 | * @param int $header |
452 | 452 | * @param bool $die |
453 | 453 | */ |
454 | - public static function printv( $var, $var_name = '', $file = __FILE__, $line = __LINE__, $header = 5, $die = false ) { |
|
454 | + public static function printv($var, $var_name = '', $file = __FILE__, $line = __LINE__, $header = 5, $die = false) { |
|
455 | 455 | $var_name = ! $var_name ? 'string' : $var_name; |
456 | 456 | $heading_tag = 'h'; |
457 | - $heading_tag .= is_int( $header ) ? $header : 5; |
|
458 | - $var_name = ucwords( str_replace( '$', '', $var_name ) ); |
|
459 | - $is_method = method_exists( $var_name, $var ); |
|
460 | - $var_name = ucwords( str_replace( '_', ' ', $var_name ) ); |
|
457 | + $heading_tag .= is_int($header) ? $header : 5; |
|
458 | + $var_name = ucwords(str_replace('$', '', $var_name)); |
|
459 | + $is_method = method_exists($var_name, $var); |
|
460 | + $var_name = ucwords(str_replace('_', ' ', $var_name)); |
|
461 | 461 | $margin = is_admin() ? ' 180px' : '0'; |
462 | - $result = '<' . $heading_tag . ' style="color:#2EA2CC; margin:25px 0 0' . $margin . ';"><b>' . $var_name . '</b>'; |
|
462 | + $result = '<'.$heading_tag.' style="color:#2EA2CC; margin:25px 0 0'.$margin.';"><b>'.$var_name.'</b>'; |
|
463 | 463 | $result .= $is_method |
464 | - ? '<span style="color:#999">::</span><span style="color:#E76700">' . $var . '()</span><br />' |
|
465 | - : '<span style="color:#999"> : </span><span style="color:#E76700">' . $var . '</span><br />'; |
|
466 | - $result .= '<span style="font-size:9px;font-weight:normal;color:#666;line-height: 12px;">' . $file; |
|
467 | - $result .= '<br />line no: ' . $line . '</span>'; |
|
468 | - $result .= '</' . $heading_tag . '>'; |
|
469 | - if ( $die ) { |
|
470 | - die( $result ); |
|
464 | + ? '<span style="color:#999">::</span><span style="color:#E76700">'.$var.'()</span><br />' |
|
465 | + : '<span style="color:#999"> : </span><span style="color:#E76700">'.$var.'</span><br />'; |
|
466 | + $result .= '<span style="font-size:9px;font-weight:normal;color:#666;line-height: 12px;">'.$file; |
|
467 | + $result .= '<br />line no: '.$line.'</span>'; |
|
468 | + $result .= '</'.$heading_tag.'>'; |
|
469 | + if ($die) { |
|
470 | + die($result); |
|
471 | 471 | } else { |
472 | 472 | echo $result; |
473 | 473 | } |
@@ -482,36 +482,36 @@ discard block |
||
482 | 482 | * @param int $header |
483 | 483 | * @param bool $die |
484 | 484 | */ |
485 | - public static function printr( $var, $var_name = '', $file = __FILE__, $line = __LINE__, $header = 5, $die = false ) { |
|
485 | + public static function printr($var, $var_name = '', $file = __FILE__, $line = __LINE__, $header = 5, $die = false) { |
|
486 | 486 | // return; |
487 | - $file = str_replace( rtrim( ABSPATH, '\\/' ), '', $file ); |
|
487 | + $file = str_replace(rtrim(ABSPATH, '\\/'), '', $file); |
|
488 | 488 | //$print_r = false; |
489 | - if ( is_string( $var ) ) { |
|
490 | - EEH_Debug_Tools::printv( $var, $var_name, $file, $line, $header, $die ); |
|
489 | + if (is_string($var)) { |
|
490 | + EEH_Debug_Tools::printv($var, $var_name, $file, $line, $header, $die); |
|
491 | 491 | return; |
492 | - } else if ( is_object( $var ) ) { |
|
492 | + } else if (is_object($var)) { |
|
493 | 493 | $var_name = ! $var_name ? 'object' : $var_name; |
494 | 494 | //$print_r = true; |
495 | - } else if ( is_array( $var ) ) { |
|
495 | + } else if (is_array($var)) { |
|
496 | 496 | $var_name = ! $var_name ? 'array' : $var_name; |
497 | 497 | //$print_r = true; |
498 | - } else if ( is_numeric( $var ) ) { |
|
498 | + } else if (is_numeric($var)) { |
|
499 | 499 | $var_name = ! $var_name ? 'numeric' : $var_name; |
500 | - } else if ( is_null( $var ) ) { |
|
500 | + } else if (is_null($var)) { |
|
501 | 501 | $var_name = ! $var_name ? 'null' : $var_name; |
502 | 502 | } |
503 | 503 | $heading_tag = 'h'; |
504 | - $heading_tag .= is_int( $header ) ? $header : 5; |
|
505 | - $var_name = ucwords( str_replace( array( '$', '_' ), array( '', ' ' ), $var_name ) ); |
|
504 | + $heading_tag .= is_int($header) ? $header : 5; |
|
505 | + $var_name = ucwords(str_replace(array('$', '_'), array('', ' '), $var_name)); |
|
506 | 506 | $margin = is_admin() ? ' 180px' : '0'; |
507 | - $result = '<' . $heading_tag . ' style="color:#2EA2CC; margin:25px 0 0'.$margin.';"><b>' . $var_name . '</b>'; |
|
507 | + $result = '<'.$heading_tag.' style="color:#2EA2CC; margin:25px 0 0'.$margin.';"><b>'.$var_name.'</b>'; |
|
508 | 508 | $result .= '<span style="color:#999;"> : </span><span style="color:#E76700;">'; |
509 | 509 | $result .= '<pre style="color:#999; padding:1em; background: #fff">'; |
510 | - $result .= var_export( $var, true ); |
|
511 | - $result .= '</pre></span><br /><span style="font-size:9px;font-weight:normal;color:#666;line-height: 12px;'.$margin.'">' . $file; |
|
512 | - $result .= '<br />line no: ' . $line . '</span></' . $heading_tag . '>'; |
|
513 | - if ( $die ) { |
|
514 | - die( $result ); |
|
510 | + $result .= var_export($var, true); |
|
511 | + $result .= '</pre></span><br /><span style="font-size:9px;font-weight:normal;color:#666;line-height: 12px;'.$margin.'">'.$file; |
|
512 | + $result .= '<br />line no: '.$line.'</span></'.$heading_tag.'>'; |
|
513 | + if ($die) { |
|
514 | + die($result); |
|
515 | 515 | } else { |
516 | 516 | echo $result; |
517 | 517 | } |
@@ -528,8 +528,8 @@ discard block |
||
528 | 528 | * borrowed from Kint Debugger |
529 | 529 | * Plugin URI: http://upthemes.com/plugins/kint-debugger/ |
530 | 530 | */ |
531 | -if ( class_exists('Kint') && ! function_exists( 'dump_wp_query' ) ) { |
|
532 | - function dump_wp_query(){ |
|
531 | +if (class_exists('Kint') && ! function_exists('dump_wp_query')) { |
|
532 | + function dump_wp_query() { |
|
533 | 533 | global $wp_query; |
534 | 534 | d($wp_query); |
535 | 535 | } |
@@ -539,8 +539,8 @@ discard block |
||
539 | 539 | * borrowed from Kint Debugger |
540 | 540 | * Plugin URI: http://upthemes.com/plugins/kint-debugger/ |
541 | 541 | */ |
542 | -if ( class_exists('Kint') && ! function_exists( 'dump_wp' ) ) { |
|
543 | - function dump_wp(){ |
|
542 | +if (class_exists('Kint') && ! function_exists('dump_wp')) { |
|
543 | + function dump_wp() { |
|
544 | 544 | global $wp; |
545 | 545 | d($wp); |
546 | 546 | } |
@@ -550,8 +550,8 @@ discard block |
||
550 | 550 | * borrowed from Kint Debugger |
551 | 551 | * Plugin URI: http://upthemes.com/plugins/kint-debugger/ |
552 | 552 | */ |
553 | -if ( class_exists('Kint') && ! function_exists( 'dump_post' ) ) { |
|
554 | - function dump_post(){ |
|
553 | +if (class_exists('Kint') && ! function_exists('dump_post')) { |
|
554 | + function dump_post() { |
|
555 | 555 | global $post; |
556 | 556 | d($post); |
557 | 557 | } |