@@ -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 |
@@ -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 | * EES_Espresso_Txn_Page |
4 | 4 | * |
@@ -27,7 +27,7 @@ discard block |
||
27 | 27 | * @return void |
28 | 28 | */ |
29 | 29 | public static function set_hooks() { |
30 | - add_action( 'wp_loaded', array( 'EES_Espresso_Txn_Page', 'set_definitions' ), 2 ); |
|
30 | + add_action('wp_loaded', array('EES_Espresso_Txn_Page', 'set_definitions'), 2); |
|
31 | 31 | } |
32 | 32 | |
33 | 33 | /** |
@@ -48,8 +48,8 @@ discard block |
||
48 | 48 | * @return void |
49 | 49 | */ |
50 | 50 | public static function set_definitions() { |
51 | - define( 'TXN_PAGE_ASSETS_URL', plugin_dir_url( __FILE__ ) . 'assets' . DS ); |
|
52 | - define( 'TXN_PAGE_TEMPLATES_PATH', str_replace( '\\', DS, plugin_dir_path( __FILE__ )) . 'templates' . DS ); |
|
51 | + define('TXN_PAGE_ASSETS_URL', plugin_dir_url(__FILE__).'assets'.DS); |
|
52 | + define('TXN_PAGE_TEMPLATES_PATH', str_replace('\\', DS, plugin_dir_path(__FILE__)).'templates'.DS); |
|
53 | 53 | } |
54 | 54 | |
55 | 55 | |
@@ -66,18 +66,18 @@ discard block |
||
66 | 66 | * @throws \Exception |
67 | 67 | * @throws \EE_Error |
68 | 68 | */ |
69 | - public function run( WP $WP ) { |
|
69 | + public function run(WP $WP) { |
|
70 | 70 | $this->_current_txn = null; |
71 | - if ( EE_Registry::instance()->REQ->is_set('e_reg_url_link' )){ |
|
71 | + if (EE_Registry::instance()->REQ->is_set('e_reg_url_link')) { |
|
72 | 72 | /** @var EEM_Transaction $EEM_Transaction */ |
73 | - $EEM_Transaction = EE_Registry::instance()->load_model( 'Transaction' ); |
|
73 | + $EEM_Transaction = EE_Registry::instance()->load_model('Transaction'); |
|
74 | 74 | $this->_current_txn = $EEM_Transaction->get_transaction_from_reg_url_link(); |
75 | 75 | } |
76 | - if ( $this->_current_txn instanceof EE_Transaction ) { |
|
76 | + if ($this->_current_txn instanceof EE_Transaction) { |
|
77 | 77 | $payment_method = null; |
78 | - $payment_method_slug = EE_Registry::instance()->REQ->get( 'ee_payment_method', NULL ); |
|
79 | - if( $payment_method_slug ) { |
|
80 | - $payment_method = EEM_Payment_Method::instance()->get_one_by_slug( $payment_method_slug ); |
|
78 | + $payment_method_slug = EE_Registry::instance()->REQ->get('ee_payment_method', NULL); |
|
79 | + if ($payment_method_slug) { |
|
80 | + $payment_method = EEM_Payment_Method::instance()->get_one_by_slug($payment_method_slug); |
|
81 | 81 | } |
82 | 82 | /** @type EE_Payment_Processor $payment_processor */ |
83 | 83 | $payment_processor = EE_Registry::instance()->load_core('Payment_Processor'); |
@@ -87,7 +87,7 @@ discard block |
||
87 | 87 | $payment_method |
88 | 88 | ); |
89 | 89 | //allow gateways to add a filter to stop rendering the page |
90 | - if( apply_filters( 'FHEE__EES_Espresso_Txn_Page__run__exit', FALSE ) ){ |
|
90 | + if (apply_filters('FHEE__EES_Espresso_Txn_Page__run__exit', FALSE)) { |
|
91 | 91 | exit; |
92 | 92 | } |
93 | 93 | } |
@@ -104,8 +104,8 @@ discard block |
||
104 | 104 | * @param array $attributes |
105 | 105 | * @return string |
106 | 106 | */ |
107 | - public function process_shortcode( $attributes = array() ) { |
|
108 | - return __( 'This is the Event Espresso Transactions page. This page receives instant payment notification (IPN) requests and should have a status of published, but should not be easily accessible by site visitors. Do not add it to your website\'s navigation menu or link to it from another page. Also, do not delete it or change its status to private.', 'event_espresso' ); |
|
107 | + public function process_shortcode($attributes = array()) { |
|
108 | + return __('This is the Event Espresso Transactions page. This page receives instant payment notification (IPN) requests and should have a status of published, but should not be easily accessible by site visitors. Do not add it to your website\'s navigation menu or link to it from another page. Also, do not delete it or change its status to private.', 'event_espresso'); |
|
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; |