@@ -68,7 +68,7 @@ discard block |
||
68 | 68 | * @return EEG_Paypal_Standard |
69 | 69 | */ |
70 | 70 | public function __construct() { |
71 | - $this->set_uses_separate_IPN_request( true ) ; |
|
71 | + $this->set_uses_separate_IPN_request(true); |
|
72 | 72 | parent::__construct(); |
73 | 73 | } |
74 | 74 | |
@@ -78,11 +78,11 @@ discard block |
||
78 | 78 | * Also sets the gateway url class variable based on whether debug mode is enabled or not |
79 | 79 | * @param array $settings_array |
80 | 80 | */ |
81 | - public function set_settings($settings_array){ |
|
81 | + public function set_settings($settings_array) { |
|
82 | 82 | parent::set_settings($settings_array); |
83 | - if($this->_debug_mode){ |
|
83 | + if ($this->_debug_mode) { |
|
84 | 84 | $this->_gateway_url = 'https://www.sandbox.paypal.com/cgi-bin/webscr'; |
85 | - }else{ |
|
85 | + } else { |
|
86 | 86 | $this->_gateway_url = 'https://www.paypal.com/cgi-bin/webscr'; |
87 | 87 | } |
88 | 88 | } |
@@ -97,7 +97,7 @@ discard block |
||
97 | 97 | * @param string $cancel_url URL to send the user to after a cancelled payment attempt on teh payment provider's website |
98 | 98 | * @return EEI_Payment |
99 | 99 | */ |
100 | - public function set_redirection_info( $payment, $billing_info = array(), $return_url = NULL, $notify_url = NULL, $cancel_url = NULL ){ |
|
100 | + public function set_redirection_info($payment, $billing_info = array(), $return_url = NULL, $notify_url = NULL, $cancel_url = NULL) { |
|
101 | 101 | $redirect_args = array(); |
102 | 102 | $transaction = $payment->transaction(); |
103 | 103 | $primary_registrant = $transaction->primary_registration(); |
@@ -107,42 +107,42 @@ discard block |
||
107 | 107 | |
108 | 108 | $total_discounts_to_cart_total = $transaction->paid(); |
109 | 109 | //only itemize the order if we're paying for the rest of the order's amount |
110 | - if( $payment->amount() == $transaction->total() ) { |
|
111 | - $payment->update_extra_meta( EEG_Paypal_Standard::itemized_payment_option_name, true ); |
|
110 | + if ($payment->amount() == $transaction->total()) { |
|
111 | + $payment->update_extra_meta(EEG_Paypal_Standard::itemized_payment_option_name, true); |
|
112 | 112 | //this payment is for the remaining transaction amount, |
113 | 113 | //keep track of exactly how much the itemized order amount equals |
114 | 114 | $itemized_sum = 0; |
115 | 115 | $shipping_previously_added = 0; |
116 | 116 | //so let's show all the line items |
117 | - foreach($total_line_item->get_items() as $line_item){ |
|
118 | - if ( $line_item instanceof EE_Line_Item ) { |
|
117 | + foreach ($total_line_item->get_items() as $line_item) { |
|
118 | + if ($line_item instanceof EE_Line_Item) { |
|
119 | 119 | //it's some kind of discount |
120 | - if( $line_item->total() < 0 ) { |
|
121 | - $total_discounts_to_cart_total += abs( $line_item->total() ); |
|
120 | + if ($line_item->total() < 0) { |
|
121 | + $total_discounts_to_cart_total += abs($line_item->total()); |
|
122 | 122 | $itemized_sum += $line_item->total(); |
123 | 123 | continue; |
124 | 124 | } |
125 | 125 | //dont include shipping again. |
126 | - if( strpos( $line_item->code(), 'paypal_shipping_') === 0 ) { |
|
126 | + if (strpos($line_item->code(), 'paypal_shipping_') === 0) { |
|
127 | 127 | $shipping_previously_added = $line_item->total(); |
128 | 128 | continue; |
129 | 129 | } |
130 | - $redirect_args[ 'item_name_' . $item_num ] = substr( |
|
131 | - sprintf( _x( '%1$s for %2$s', 'Ticket for Event', 'event_espresso' ), $line_item->name(), $line_item->ticket_event_name() ), |
|
130 | + $redirect_args['item_name_'.$item_num] = substr( |
|
131 | + sprintf(_x('%1$s for %2$s', 'Ticket for Event', 'event_espresso'), $line_item->name(), $line_item->ticket_event_name()), |
|
132 | 132 | 0, 127 |
133 | 133 | ); |
134 | - $redirect_args[ 'amount_' . $item_num ] = $line_item->unit_price(); |
|
135 | - $redirect_args[ 'quantity_' . $item_num ] = $line_item->quantity(); |
|
134 | + $redirect_args['amount_'.$item_num] = $line_item->unit_price(); |
|
135 | + $redirect_args['quantity_'.$item_num] = $line_item->quantity(); |
|
136 | 136 | //if we're not letting PayPal calculate shipping, tell them its 0 |
137 | - if ( ! $this->_paypal_shipping ) { |
|
138 | - $redirect_args[ 'shipping_' . $item_num ] = '0'; |
|
139 | - $redirect_args[ 'shipping2_' . $item_num ] = '0'; |
|
137 | + if ( ! $this->_paypal_shipping) { |
|
138 | + $redirect_args['shipping_'.$item_num] = '0'; |
|
139 | + $redirect_args['shipping2_'.$item_num] = '0'; |
|
140 | 140 | } |
141 | 141 | $item_num++; |
142 | 142 | $itemized_sum += $line_item->total(); |
143 | 143 | } |
144 | 144 | } |
145 | - $taxes_li = $this->_line_item->get_taxes_subtotal( $total_line_item ); |
|
145 | + $taxes_li = $this->_line_item->get_taxes_subtotal($total_line_item); |
|
146 | 146 | //ideally itemized sum equals the transaction total. but if not (which is weird) |
147 | 147 | //and the itemized sum is LESS than the transaction total |
148 | 148 | //add another line item |
@@ -152,47 +152,47 @@ discard block |
||
152 | 152 | $transaction->total() - $itemized_sum - $taxes_li->total() - $shipping_previously_added, |
153 | 153 | 2 |
154 | 154 | ); |
155 | - if( $itemized_sum_diff_from_txn_total < 0 ) { |
|
155 | + if ($itemized_sum_diff_from_txn_total < 0) { |
|
156 | 156 | //itemized sum is too big |
157 | - $total_discounts_to_cart_total += abs( $itemized_sum_diff_from_txn_total ); |
|
158 | - } elseif( $itemized_sum_diff_from_txn_total > 0 ) { |
|
159 | - $redirect_args[ 'item_name_' . $item_num ] = substr( |
|
160 | - __( 'Other charges', 'event_espresso' ), 0, 127 ); |
|
161 | - $redirect_args[ 'amount_' . $item_num ] = $this->format_currency( $itemized_sum_diff_from_txn_total ); |
|
162 | - $redirect_args[ 'quantity_' . $item_num ] = 1; |
|
157 | + $total_discounts_to_cart_total += abs($itemized_sum_diff_from_txn_total); |
|
158 | + } elseif ($itemized_sum_diff_from_txn_total > 0) { |
|
159 | + $redirect_args['item_name_'.$item_num] = substr( |
|
160 | + __('Other charges', 'event_espresso'), 0, 127 ); |
|
161 | + $redirect_args['amount_'.$item_num] = $this->format_currency($itemized_sum_diff_from_txn_total); |
|
162 | + $redirect_args['quantity_'.$item_num] = 1; |
|
163 | 163 | $item_num++; |
164 | 164 | } |
165 | - if( $total_discounts_to_cart_total > 0 ) { |
|
166 | - $redirect_args[ 'discount_amount_cart' ] = $this->format_currency( $total_discounts_to_cart_total ); |
|
165 | + if ($total_discounts_to_cart_total > 0) { |
|
166 | + $redirect_args['discount_amount_cart'] = $this->format_currency($total_discounts_to_cart_total); |
|
167 | 167 | } |
168 | 168 | //add our taxes to the order if we're NOT using PayPal's |
169 | - if( ! $this->_paypal_taxes ){ |
|
169 | + if ( ! $this->_paypal_taxes) { |
|
170 | 170 | $redirect_args['tax_cart'] = $total_line_item->get_total_tax(); |
171 | 171 | } |
172 | 172 | } else { |
173 | - $payment->update_extra_meta( EEG_Paypal_Standard::itemized_payment_option_name, false ); |
|
173 | + $payment->update_extra_meta(EEG_Paypal_Standard::itemized_payment_option_name, false); |
|
174 | 174 | //partial payment that's not for the remaining amount, so we can't send an itemized list |
175 | - $redirect_args['item_name_' . $item_num] = substr( |
|
176 | - sprintf( __('Payment of %1$s for %2$s', "event_espresso"), $payment->amount(), $primary_registrant->reg_code() ), |
|
175 | + $redirect_args['item_name_'.$item_num] = substr( |
|
176 | + sprintf(__('Payment of %1$s for %2$s', "event_espresso"), $payment->amount(), $primary_registrant->reg_code()), |
|
177 | 177 | 0, 127 |
178 | 178 | ); |
179 | - $redirect_args['amount_' . $item_num] = $payment->amount(); |
|
180 | - $redirect_args['shipping_' . $item_num ] = '0'; |
|
181 | - $redirect_args['shipping2_' . $item_num ] = '0'; |
|
179 | + $redirect_args['amount_'.$item_num] = $payment->amount(); |
|
180 | + $redirect_args['shipping_'.$item_num] = '0'; |
|
181 | + $redirect_args['shipping2_'.$item_num] = '0'; |
|
182 | 182 | $redirect_args['tax_cart'] = '0'; |
183 | 183 | $item_num++; |
184 | 184 | } |
185 | 185 | |
186 | - if($this->_debug_mode){ |
|
187 | - $redirect_args['item_name_' . $item_num] = 'DEBUG INFO (this item only added in sandbox mode'; |
|
188 | - $redirect_args['amount_' . $item_num] = 0; |
|
186 | + if ($this->_debug_mode) { |
|
187 | + $redirect_args['item_name_'.$item_num] = 'DEBUG INFO (this item only added in sandbox mode'; |
|
188 | + $redirect_args['amount_'.$item_num] = 0; |
|
189 | 189 | $redirect_args['on0_'.$item_num] = 'NOTIFY URL'; |
190 | - $redirect_args['os0_' . $item_num] = $notify_url; |
|
190 | + $redirect_args['os0_'.$item_num] = $notify_url; |
|
191 | 191 | $redirect_args['on1_'.$item_num] = 'RETURN URL'; |
192 | - $redirect_args['os1_' . $item_num] = $return_url; |
|
192 | + $redirect_args['os1_'.$item_num] = $return_url; |
|
193 | 193 | // $redirect_args['option_index_' . $item_num] = 1; // <-- dunno if this is needed ? |
194 | - $redirect_args['shipping_' . $item_num ] = '0'; |
|
195 | - $redirect_args['shipping2_' . $item_num ] = '0'; |
|
194 | + $redirect_args['shipping_'.$item_num] = '0'; |
|
195 | + $redirect_args['shipping2_'.$item_num] = '0'; |
|
196 | 196 | } |
197 | 197 | |
198 | 198 | $redirect_args['business'] = $this->_paypal_id; |
@@ -202,14 +202,14 @@ discard block |
||
202 | 202 | $redirect_args['cmd'] = '_cart'; |
203 | 203 | $redirect_args['upload'] = 1; |
204 | 204 | $redirect_args['currency_code'] = $payment->currency_code(); |
205 | - $redirect_args['rm'] = 2;//makes the user return with method=POST |
|
206 | - if($this->_image_url){ |
|
205 | + $redirect_args['rm'] = 2; //makes the user return with method=POST |
|
206 | + if ($this->_image_url) { |
|
207 | 207 | $redirect_args['image_url'] = $this->_image_url; |
208 | 208 | } |
209 | 209 | $redirect_args['no_shipping'] = $this->_shipping_details; |
210 | - $redirect_args['bn'] = 'EventEspresso_SP';//EE will blow up if you change this |
|
210 | + $redirect_args['bn'] = 'EventEspresso_SP'; //EE will blow up if you change this |
|
211 | 211 | |
212 | - $redirect_args = apply_filters( "FHEE__EEG_Paypal_Standard__set_redirection_info__arguments", $redirect_args, $this ); |
|
212 | + $redirect_args = apply_filters("FHEE__EEG_Paypal_Standard__set_redirection_info__arguments", $redirect_args, $this); |
|
213 | 213 | |
214 | 214 | $payment->set_redirect_url($this->_gateway_url); |
215 | 215 | $payment->set_redirect_args($redirect_args); |
@@ -230,55 +230,55 @@ discard block |
||
230 | 230 | * @return \EEI_Payment updated |
231 | 231 | * @throws \EE_Error |
232 | 232 | */ |
233 | - public function handle_payment_update( $update_info, $transaction ){ |
|
233 | + public function handle_payment_update($update_info, $transaction) { |
|
234 | 234 | //verify there's payment data that's been sent |
235 | - if ( empty( $update_info[ 'payment_status' ] ) || empty( $update_info[ 'txn_id' ] ) ) { |
|
235 | + if (empty($update_info['payment_status']) || empty($update_info['txn_id'])) { |
|
236 | 236 | // waaaait... is this a PDT request? (see https://developer.paypal.com/docs/classic/products/payment-data-transfer/) |
237 | 237 | // indicated by the "tx" argument? If so, we don't need it. We'll just use the IPN data when it comes |
238 | - if ( isset( $update_info[ 'tx' ] ) ) { |
|
238 | + if (isset($update_info['tx'])) { |
|
239 | 239 | return $transaction->last_payment(); |
240 | 240 | } else { |
241 | 241 | return null; |
242 | 242 | } |
243 | 243 | } |
244 | - $payment = $this->_pay_model->get_payment_by_txn_id_chq_nmbr( $update_info[ 'txn_id' ] ); |
|
245 | - if ( ! $payment instanceof EEI_Payment ) { |
|
244 | + $payment = $this->_pay_model->get_payment_by_txn_id_chq_nmbr($update_info['txn_id']); |
|
245 | + if ( ! $payment instanceof EEI_Payment) { |
|
246 | 246 | $payment = $transaction->last_payment(); |
247 | 247 | } |
248 | 248 | // ok, then validate the IPN. Even if we've already processed this payment, |
249 | 249 | // let PayPal know we don't want to hear from them anymore! |
250 | - if ( ! $this->validate_ipn( $update_info, $payment ) ) { |
|
250 | + if ( ! $this->validate_ipn($update_info, $payment)) { |
|
251 | 251 | return $payment; |
252 | 252 | } |
253 | 253 | //ok, well let's process this payment then! |
254 | - switch ( $update_info[ 'payment_status' ] ) { |
|
254 | + switch ($update_info['payment_status']) { |
|
255 | 255 | |
256 | 256 | case 'Completed' : |
257 | 257 | $status = $this->_pay_model->approved_status(); |
258 | - $gateway_response = __( 'The payment is approved.', 'event_espresso' ); |
|
258 | + $gateway_response = __('The payment is approved.', 'event_espresso'); |
|
259 | 259 | break; |
260 | 260 | |
261 | 261 | case 'Pending' : |
262 | 262 | $status = $this->_pay_model->pending_status(); |
263 | - $gateway_response = __( 'The payment is in progress. Another message will be sent when payment is approved.', 'event_espresso' ); |
|
263 | + $gateway_response = __('The payment is in progress. Another message will be sent when payment is approved.', 'event_espresso'); |
|
264 | 264 | break; |
265 | 265 | |
266 | 266 | case 'Denied' : |
267 | 267 | $status = $this->_pay_model->declined_status(); |
268 | - $gateway_response = __( 'The payment has been declined.', 'event_espresso' ); |
|
268 | + $gateway_response = __('The payment has been declined.', 'event_espresso'); |
|
269 | 269 | break; |
270 | 270 | |
271 | 271 | case 'Expired' : |
272 | 272 | case 'Failed' : |
273 | 273 | $status = $this->_pay_model->failed_status(); |
274 | - $gateway_response = __( 'The payment failed for technical reasons or expired.', 'event_espresso' ); |
|
274 | + $gateway_response = __('The payment failed for technical reasons or expired.', 'event_espresso'); |
|
275 | 275 | break; |
276 | 276 | |
277 | 277 | case 'Refunded' : |
278 | 278 | case 'Partially_Refunded' : |
279 | 279 | // even though it's a refund, we consider the payment as approved, it just has a negative value |
280 | 280 | $status = $this->_pay_model->approved_status(); |
281 | - $gateway_response = __( 'The payment has been refunded. Please update registrations accordingly.', 'event_espresso' ); |
|
281 | + $gateway_response = __('The payment has been refunded. Please update registrations accordingly.', 'event_espresso'); |
|
282 | 282 | break; |
283 | 283 | |
284 | 284 | case 'Voided' : |
@@ -286,25 +286,25 @@ discard block |
||
286 | 286 | case 'Canceled_Reversal' : |
287 | 287 | default : |
288 | 288 | $status = $this->_pay_model->cancelled_status(); |
289 | - $gateway_response = __( 'The payment was cancelled, reversed, or voided. Please update registrations accordingly.', 'event_espresso' ); |
|
289 | + $gateway_response = __('The payment was cancelled, reversed, or voided. Please update registrations accordingly.', 'event_espresso'); |
|
290 | 290 | break; |
291 | 291 | |
292 | 292 | } |
293 | 293 | |
294 | 294 | //check if we've already processed this payment |
295 | - if ( $payment instanceof EEI_Payment ) { |
|
295 | + if ($payment instanceof EEI_Payment) { |
|
296 | 296 | //payment exists. if this has the exact same status and amount, don't bother updating. just return |
297 | - if ( $payment->status() == $status && $payment->amount() == $update_info[ 'mc_gross' ] ) { |
|
297 | + if ($payment->status() == $status && $payment->amount() == $update_info['mc_gross']) { |
|
298 | 298 | // DUPLICATED IPN! dont bother updating transaction foo!; |
299 | - $message_log = sprintf( __( 'It appears we have received a duplicate IPN from PayPal for payment %d', 'event_espresso' ), $payment->ID() ); |
|
299 | + $message_log = sprintf(__('It appears we have received a duplicate IPN from PayPal for payment %d', 'event_espresso'), $payment->ID()); |
|
300 | 300 | } else { |
301 | 301 | // new payment yippee !!! |
302 | - $payment->set_status( $status ); |
|
303 | - $payment->set_amount( floatval( $update_info[ 'mc_gross' ] ) ); |
|
304 | - $payment->set_gateway_response( $gateway_response ); |
|
305 | - $payment->set_details( $update_info ); |
|
306 | - $payment->set_txn_id_chq_nmbr( $update_info[ 'txn_id' ] ); |
|
307 | - $message_log = sprintf( __( 'Updated payment either from IPN or as part of POST from PayPal', 'event_espresso' ) ); |
|
302 | + $payment->set_status($status); |
|
303 | + $payment->set_amount(floatval($update_info['mc_gross'])); |
|
304 | + $payment->set_gateway_response($gateway_response); |
|
305 | + $payment->set_details($update_info); |
|
306 | + $payment->set_txn_id_chq_nmbr($update_info['txn_id']); |
|
307 | + $message_log = sprintf(__('Updated payment either from IPN or as part of POST from PayPal', 'event_espresso')); |
|
308 | 308 | } |
309 | 309 | $this->log( |
310 | 310 | array( |
@@ -316,11 +316,11 @@ discard block |
||
316 | 316 | $payment |
317 | 317 | ); |
318 | 318 | } |
319 | - do_action( 'FHEE__EEG_Paypal_Standard__handle_payment_update__payment_processed', $payment, $this ); |
|
319 | + do_action('FHEE__EEG_Paypal_Standard__handle_payment_update__payment_processed', $payment, $this); |
|
320 | 320 | // kill request here if this is a refund |
321 | - if ( $update_info[ 'payment_status' ] == 'Refunded' || $update_info[ 'payment_status' ] == 'Partially_Refunded' ) { |
|
322 | - if ( apply_filters( 'FHEE__EEG_Paypal_Standard__handle_payment_update__kill_refund_request', true ) ) { |
|
323 | - status_header( 200 ); |
|
321 | + if ($update_info['payment_status'] == 'Refunded' || $update_info['payment_status'] == 'Partially_Refunded') { |
|
322 | + if (apply_filters('FHEE__EEG_Paypal_Standard__handle_payment_update__kill_refund_request', true)) { |
|
323 | + status_header(200); |
|
324 | 324 | exit(); |
325 | 325 | } |
326 | 326 | } |
@@ -336,9 +336,9 @@ discard block |
||
336 | 336 | * @param EE_Payment|EEI_Payment $payment |
337 | 337 | * @return boolean |
338 | 338 | */ |
339 | - public function validate_ipn( $update_info, $payment ) { |
|
339 | + public function validate_ipn($update_info, $payment) { |
|
340 | 340 | //allow us to skip validating IPNs with PayPal (useful for testing) |
341 | - if ( apply_filters( 'FHEE__EEG_Paypal_Standard__validate_ipn__skip', false ) ) { |
|
341 | + if (apply_filters('FHEE__EEG_Paypal_Standard__validate_ipn__skip', false)) { |
|
342 | 342 | return true; |
343 | 343 | } |
344 | 344 | //...otherwise, we actually don't care what the $update_info is, we need to look |
@@ -346,22 +346,22 @@ discard block |
||
346 | 346 | // Reading POSTed data directly from $_POST causes serialization issues with array data in the POST. |
347 | 347 | // Instead, read raw POST data from the input stream. |
348 | 348 | // @see https://gist.github.com/xcommerce-gists/3440401 |
349 | - $raw_post_data = file_get_contents( 'php://input' ); |
|
350 | - $raw_post_array = explode( '&', $raw_post_data ); |
|
349 | + $raw_post_data = file_get_contents('php://input'); |
|
350 | + $raw_post_array = explode('&', $raw_post_data); |
|
351 | 351 | $update_info = array(); |
352 | - foreach ( $raw_post_array as $keyval ) { |
|
353 | - $keyval = explode( '=', $keyval ); |
|
354 | - if ( count( $keyval ) == 2 ) |
|
355 | - $update_info[ $keyval[ 0 ] ] = urldecode( $keyval[ 1 ] ); |
|
352 | + foreach ($raw_post_array as $keyval) { |
|
353 | + $keyval = explode('=', $keyval); |
|
354 | + if (count($keyval) == 2) |
|
355 | + $update_info[$keyval[0]] = urldecode($keyval[1]); |
|
356 | 356 | } |
357 | 357 | // read the IPN message sent from PayPal and prepend 'cmd=_notify-validate' |
358 | 358 | $req = 'cmd=_notify-validate'; |
359 | - $get_magic_quotes_exists = function_exists( 'get_magic_quotes_gpc' ) ? true : false; |
|
360 | - foreach ( $update_info as $key => $value ) { |
|
361 | - if ( $get_magic_quotes_exists && get_magic_quotes_gpc() == 1 ) { |
|
362 | - $value = urlencode( stripslashes( $value ) ); |
|
359 | + $get_magic_quotes_exists = function_exists('get_magic_quotes_gpc') ? true : false; |
|
360 | + foreach ($update_info as $key => $value) { |
|
361 | + if ($get_magic_quotes_exists && get_magic_quotes_gpc() == 1) { |
|
362 | + $value = urlencode(stripslashes($value)); |
|
363 | 363 | } else { |
364 | - $value = urlencode( $value ); |
|
364 | + $value = urlencode($value); |
|
365 | 365 | } |
366 | 366 | $req .= "&$key=$value"; |
367 | 367 | } |
@@ -371,34 +371,34 @@ discard block |
||
371 | 371 | array( |
372 | 372 | 'body' => $req, |
373 | 373 | 'sslverify' => false, |
374 | - 'timeout' => 60 , |
|
374 | + 'timeout' => 60, |
|
375 | 375 | // make sure to set a site specific unique "user-agent" string since the WordPres default gets declined by PayPal |
376 | 376 | // plz see: https://github.com/websharks/s2member/issues/610 |
377 | - 'user-agent' => 'Event Espresso v' . EVENT_ESPRESSO_VERSION . '; ' . home_url(), |
|
377 | + 'user-agent' => 'Event Espresso v'.EVENT_ESPRESSO_VERSION.'; '.home_url(), |
|
378 | 378 | 'httpversion' => '1.1' |
379 | 379 | ) |
380 | 380 | ); |
381 | 381 | // then check the response |
382 | - if ( ! is_wp_error( $response ) && array_key_exists( 'body', $response ) && strcmp( $response[ 'body' ], "VERIFIED" ) == 0 ) { |
|
382 | + if ( ! is_wp_error($response) && array_key_exists('body', $response) && strcmp($response['body'], "VERIFIED") == 0) { |
|
383 | 383 | return true; |
384 | 384 | } else { |
385 | 385 | // huh, something's wack... the IPN didn't validate. We must have replied to the IPN incorrectly, |
386 | 386 | // or their API must have changed: http://www.paypalobjects.com/en_US/ebook/PP_OrderManagement_IntegrationGuide/ipn.html |
387 | - if( is_wp_error( $response ) ) { |
|
387 | + if (is_wp_error($response)) { |
|
388 | 388 | $error_msg = sprintf( |
389 | - __( 'WP Error. Code: "%1$s", Message: "%2$s", Data: "%3$s"', 'event_espresso' ), |
|
389 | + __('WP Error. Code: "%1$s", Message: "%2$s", Data: "%3$s"', 'event_espresso'), |
|
390 | 390 | $response->get_error_code(), |
391 | 391 | $response->get_error_message(), |
392 | - print_r( $response->get_error_data, true ) |
|
392 | + print_r($response->get_error_data, true) |
|
393 | 393 | ); |
394 | - } elseif( is_array( $response ) && isset( $response[ 'body' ] ) ) { |
|
395 | - $error_msg = $response[ 'body' ]; |
|
394 | + } elseif (is_array($response) && isset($response['body'])) { |
|
395 | + $error_msg = $response['body']; |
|
396 | 396 | } else { |
397 | - $error_msg = print_r( $response, true ); |
|
397 | + $error_msg = print_r($response, true); |
|
398 | 398 | } |
399 | - $payment->set_gateway_response( sprintf( __( "IPN Validation failed! Paypal responded with '%s'", "event_espresso" ), $error_msg ) ); |
|
400 | - $payment->set_details( array( 'REQUEST' => $update_info, 'VALIDATION_RESPONSE' => $response ) ); |
|
401 | - $payment->set_status( EEM_Payment::status_id_failed ); |
|
399 | + $payment->set_gateway_response(sprintf(__("IPN Validation failed! Paypal responded with '%s'", "event_espresso"), $error_msg)); |
|
400 | + $payment->set_details(array('REQUEST' => $update_info, 'VALIDATION_RESPONSE' => $response)); |
|
401 | + $payment->set_status(EEM_Payment::status_id_failed); |
|
402 | 402 | // log the results |
403 | 403 | $this->log( |
404 | 404 | array( |
@@ -420,9 +420,9 @@ discard block |
||
420 | 420 | */ |
421 | 421 | protected function _process_response_url() { |
422 | 422 | EE_Registry::instance()->load_helper('URL'); |
423 | - if ( isset( $_SERVER[ 'HTTP_HOST' ], $_SERVER[ 'REQUEST_URI' ] ) ) { |
|
423 | + if (isset($_SERVER['HTTP_HOST'], $_SERVER['REQUEST_URI'])) { |
|
424 | 424 | $url = is_ssl() ? 'https://' : 'http://'; |
425 | - $url .= EEH_URL::filter_input_server_url( 'HTTP_HOST' ); |
|
425 | + $url .= EEH_URL::filter_input_server_url('HTTP_HOST'); |
|
426 | 426 | $url .= EEH_URL::filter_input_server_url(); |
427 | 427 | } else { |
428 | 428 | $url = 'unknown'; |
@@ -438,30 +438,30 @@ discard block |
||
438 | 438 | * like the taxes or shipping |
439 | 439 | * @param EEI_Payment $payment |
440 | 440 | */ |
441 | - public function update_txn_based_on_payment( $payment ) { |
|
441 | + public function update_txn_based_on_payment($payment) { |
|
442 | 442 | $update_info = $payment->details(); |
443 | 443 | $transaction = $payment->transaction(); |
444 | - $payment_was_itemized = $payment->get_extra_meta( EEG_Paypal_Standard::itemized_payment_option_name, true, false ); |
|
445 | - if( ! $transaction ){ |
|
446 | - $this->log( __( 'Payment with ID %d has no related transaction, and so update_txn_based_on_payment couldn\'t be executed properly', 'event_espresso' ), $payment ); |
|
444 | + $payment_was_itemized = $payment->get_extra_meta(EEG_Paypal_Standard::itemized_payment_option_name, true, false); |
|
445 | + if ( ! $transaction) { |
|
446 | + $this->log(__('Payment with ID %d has no related transaction, and so update_txn_based_on_payment couldn\'t be executed properly', 'event_espresso'), $payment); |
|
447 | 447 | return; |
448 | 448 | } |
449 | - if( ! is_array( $update_info ) || ! isset( $update_info[ 'mc_shipping' ] ) || ! isset( $update_info[ 'tax' ] ) ) { |
|
449 | + if ( ! is_array($update_info) || ! isset($update_info['mc_shipping']) || ! isset($update_info['tax'])) { |
|
450 | 450 | $this->log( |
451 | 451 | array( |
452 | 452 | 'url' => $this->_process_response_url(), |
453 | - 'message' => __( 'Could not update transaction based on payment because the payment details have not yet been put on the payment. This normally happens during the IPN or returning from PayPal', 'event_espresso' ), |
|
453 | + 'message' => __('Could not update transaction based on payment because the payment details have not yet been put on the payment. This normally happens during the IPN or returning from PayPal', 'event_espresso'), |
|
454 | 454 | 'payment' => $payment->model_field_array() |
455 | 455 | ), |
456 | 456 | $payment |
457 | 457 | ); |
458 | 458 | return; |
459 | 459 | } |
460 | - if( $payment->status() !== $this->_pay_model->approved_status() ) { |
|
460 | + if ($payment->status() !== $this->_pay_model->approved_status()) { |
|
461 | 461 | $this->log( |
462 | 462 | array( |
463 | 463 | 'url' => $this->_process_response_url(), |
464 | - 'message' => __( 'We shouldn\'t update transactions taxes or shipping data from non-approved payments', 'event_espresso' ), |
|
464 | + 'message' => __('We shouldn\'t update transactions taxes or shipping data from non-approved payments', 'event_espresso'), |
|
465 | 465 | 'payment' => $payment->model_field_array() |
466 | 466 | ), |
467 | 467 | $payment |
@@ -471,43 +471,43 @@ discard block |
||
471 | 471 | $grand_total_needs_resaving = false; |
472 | 472 | |
473 | 473 | //might paypal have changed the taxes? |
474 | - if( $this->_paypal_taxes && $payment_was_itemized ){ |
|
474 | + if ($this->_paypal_taxes && $payment_was_itemized) { |
|
475 | 475 | //note that we're doing this BEFORE adding shipping; we actually want PayPal's shipping to remain non-taxable |
476 | - $this->_line_item->set_line_items_taxable( $transaction->total_line_item(), true, 'paypal_shipping' ); |
|
476 | + $this->_line_item->set_line_items_taxable($transaction->total_line_item(), true, 'paypal_shipping'); |
|
477 | 477 | $this->_line_item->set_total_tax_to( |
478 | 478 | $transaction->total_line_item(), |
479 | - floatval( $update_info['tax'] ), |
|
480 | - __( 'Taxes', 'event_espresso' ), |
|
481 | - __( 'Calculated by Paypal', 'event_espresso' ), |
|
479 | + floatval($update_info['tax']), |
|
480 | + __('Taxes', 'event_espresso'), |
|
481 | + __('Calculated by Paypal', 'event_espresso'), |
|
482 | 482 | 'paypal_tax' |
483 | 483 | ); |
484 | 484 | $grand_total_needs_resaving = TRUE; |
485 | 485 | } |
486 | 486 | |
487 | - $shipping_amount = floatval( $update_info[ 'mc_shipping' ] ); |
|
487 | + $shipping_amount = floatval($update_info['mc_shipping']); |
|
488 | 488 | //might paypal have added shipping? |
489 | - if( $this->_paypal_shipping && $shipping_amount && $payment_was_itemized ){ |
|
489 | + if ($this->_paypal_shipping && $shipping_amount && $payment_was_itemized) { |
|
490 | 490 | $this->_line_item->add_unrelated_item( |
491 | 491 | $transaction->total_line_item(), |
492 | - sprintf( __('Shipping for transaction %1$s', 'event_espresso'), $transaction->ID() ), |
|
492 | + sprintf(__('Shipping for transaction %1$s', 'event_espresso'), $transaction->ID()), |
|
493 | 493 | $shipping_amount, |
494 | 494 | __('Shipping charges calculated by Paypal', 'event_espresso'), |
495 | 495 | 1, |
496 | 496 | false, |
497 | - 'paypal_shipping_' . $transaction->ID() |
|
497 | + 'paypal_shipping_'.$transaction->ID() |
|
498 | 498 | ); |
499 | 499 | $grand_total_needs_resaving = true; |
500 | 500 | } |
501 | 501 | |
502 | - if( $grand_total_needs_resaving ){ |
|
503 | - $transaction->total_line_item()->save_this_and_descendants_to_txn( $transaction->ID() ); |
|
504 | - $registration_processor = EE_Registry::instance()->load_class( 'Registration_Processor' ); |
|
505 | - $registration_processor->update_registration_final_prices( $transaction ); |
|
502 | + if ($grand_total_needs_resaving) { |
|
503 | + $transaction->total_line_item()->save_this_and_descendants_to_txn($transaction->ID()); |
|
504 | + $registration_processor = EE_Registry::instance()->load_class('Registration_Processor'); |
|
505 | + $registration_processor->update_registration_final_prices($transaction); |
|
506 | 506 | } |
507 | 507 | $this->log( |
508 | 508 | array( |
509 | 509 | 'url' => $this->_process_response_url(), |
510 | - 'message' => __( 'Updated transaction related to payment', 'event_espresso' ), |
|
510 | + 'message' => __('Updated transaction related to payment', 'event_espresso'), |
|
511 | 511 | 'transaction (updated)' => $transaction->model_field_array(), |
512 | 512 | 'payment (updated)' => $payment->model_field_array(), |
513 | 513 | 'use_paypal_shipping' => $this->_paypal_shipping, |
@@ -809,7 +809,7 @@ discard block |
||
809 | 809 | * Returns the name of the field's name that points to the WP_User table |
810 | 810 | * on this model (or follows the _model_chain_to_wp_user and uses that model's |
811 | 811 | * foreign key to the WP_User table) |
812 | - * @return string|boolean string on success, boolean false when there is no |
|
812 | + * @return string|false string on success, boolean false when there is no |
|
813 | 813 | * foreign key to the WP_User table |
814 | 814 | */ |
815 | 815 | function wp_user_field_name() { |
@@ -906,6 +906,7 @@ discard block |
||
906 | 906 | * If you would like to use these custom selections in WHERE, GROUP_BY, or HAVING clauses, you must instead provide an array. |
907 | 907 | * Array keys are the aliases used to refer to this selection, and values are to be numerically-indexed arrays, where 0 is the selection |
908 | 908 | * and 1 is the data type. Eg, array('count'=>array('COUNT(REG_ID)','%d')) |
909 | + * @param string $columns_to_select |
|
909 | 910 | * @return array|stdClass[] like results of $wpdb->get_results($sql,OBJECT), (ie, output type is OBJECT) |
910 | 911 | */ |
911 | 912 | public function get_all_wpdb_results($query_params = array(), $output = ARRAY_A, $columns_to_select = null){ |
@@ -1248,7 +1249,7 @@ discard block |
||
1248 | 1249 | * @param bool $pretty Whether to return the pretty formats (true) or not (false). |
1249 | 1250 | * @throws EE_Error If the given field_name is not of the EE_Datetime_Field type. |
1250 | 1251 | * |
1251 | - * @return array formats in an array with the date format first, and the time format last. |
|
1252 | + * @return string[] formats in an array with the date format first, and the time format last. |
|
1252 | 1253 | */ |
1253 | 1254 | public function get_formats_for( $field_name, $pretty = false ) { |
1254 | 1255 | $field_settings = $this->field_settings_for( $field_name ); |
@@ -1283,7 +1284,7 @@ discard block |
||
1283 | 1284 | * |
1284 | 1285 | * @throws EE_Error If the given field_name is not of the EE_Datetime_Field type. |
1285 | 1286 | * |
1286 | - * @return int|string If the given field_name is not of the EE_Datetime_Field type, then an EE_Error |
|
1287 | + * @return string|null If the given field_name is not of the EE_Datetime_Field type, then an EE_Error |
|
1287 | 1288 | * exception is triggered. |
1288 | 1289 | */ |
1289 | 1290 | public function current_time_for_query( $field_name, $timestamp = false, $what = 'both' ) { |
@@ -1982,7 +1983,7 @@ discard block |
||
1982 | 1983 | /** |
1983 | 1984 | * Verifies the EE addons' database is up-to-date and records that we've done it on |
1984 | 1985 | * EEM_Base::$_db_verification_level |
1985 | - * @param $wpdb_method |
|
1986 | + * @param string $wpdb_method |
|
1986 | 1987 | * @param $arguments_to_provide |
1987 | 1988 | * @return string |
1988 | 1989 | */ |
@@ -2050,7 +2051,6 @@ discard block |
||
2050 | 2051 | * 'hasAndBelongsToMany' relationships: checks that there isn't already an entry in the join table, and adds one. |
2051 | 2052 | * If one of the model Objects has not yet been saved to the database, it is saved before adding the entry in the join table |
2052 | 2053 | * |
2053 | - * @param EE_Base_Class/int $thisModelObject |
|
2054 | 2054 | * @param EE_Base_Class/int $id_or_obj EE_base_Class or ID of other Model Object |
2055 | 2055 | * @param string $relationName, key in EEM_Base::_relations |
2056 | 2056 | * an attendee to a group, you also want to specify which role they will have in that group. So you would use this parameter to specify array('role-column-name'=>'role-id') |
@@ -2072,8 +2072,8 @@ discard block |
||
2072 | 2072 | * |
2073 | 2073 | * 'hasAndBelongsToMany' relationships:removes any existing entry in the join table between the two models. |
2074 | 2074 | * |
2075 | - * @param EE_Base_Class/int $id_or_obj |
|
2076 | - * @param EE_Base_Class/int $other_model_id_or_obj EE_Base_Class or ID of other Model Object |
|
2075 | + * @param EE_CPT_Base $id_or_obj |
|
2076 | + * @param EE_Term_Taxonomy $other_model_id_or_obj EE_Base_Class or ID of other Model Object |
|
2077 | 2077 | * @param string $relationName key in EEM_Base::_relations |
2078 | 2078 | * @return boolean of success |
2079 | 2079 | * @param array $where_query This allows you to enter further query params for the relation to for relation to methods that allow you to further specify extra columns to join by (such as HABTM). Keep in mind that the only acceptable query_params is strict "col" => "value" pairs because these will be inserted in any new rows created as well. |
@@ -2149,7 +2149,7 @@ discard block |
||
2149 | 2149 | /** |
2150 | 2150 | * Instead of getting the related model objects, simply counts them. Ignores default_where_conditions by default, |
2151 | 2151 | * unless otherwise specified in the $query_params |
2152 | - * @param int/EE_Base_Class $id_or_obj |
|
2152 | + * @param EE_Event $id_or_obj |
|
2153 | 2153 | * @param string $model_name like 'Event', or 'Registration' |
2154 | 2154 | * @param array $query_params like EEM_Base::get_all's |
2155 | 2155 | * @param string $field_to_count name of field to count by. By default, uses primary key |
@@ -2538,7 +2538,7 @@ discard block |
||
2538 | 2538 | /** |
2539 | 2539 | * Finds all the fields that correspond to the given table |
2540 | 2540 | * @param string $table_alias, array key in EEM_Base::_tables |
2541 | - * @return EE_Model_Field_Base[] |
|
2541 | + * @return EE_Model_Field_Base |
|
2542 | 2542 | */ |
2543 | 2543 | function _get_fields_for_table($table_alias){ |
2544 | 2544 | return $this->_fields[$table_alias]; |
@@ -3630,8 +3630,8 @@ discard block |
||
3630 | 3630 | /** |
3631 | 3631 | * gets the field object of type 'primary_key' from the fieldsSettings attribute. |
3632 | 3632 | * Eg, on EE_Answer that would be ANS_ID field object |
3633 | - * @param $field_obj |
|
3634 | - * @return EE_Model_Field_Base |
|
3633 | + * @param EE_Model_Field_Base $field_obj |
|
3634 | + * @return boolean |
|
3635 | 3635 | */ |
3636 | 3636 | public function is_primary_key_field( $field_obj ){ |
3637 | 3637 | return $field_obj instanceof EE_Primary_Key_Field_Base ? TRUE : FALSE; |
@@ -3725,7 +3725,7 @@ discard block |
||
3725 | 3725 | * Gets the actual table for the table alias |
3726 | 3726 | * @param string $table_alias eg Event, Event_Meta, Registration, Transaction, but maybe |
3727 | 3727 | * a table alias with a model chain prefix, like 'Venue__Event_Venue___Event_Meta'. Either one works |
3728 | - * @return EE_Table_Base |
|
3728 | + * @return string |
|
3729 | 3729 | */ |
3730 | 3730 | function get_table_for_alias($table_alias){ |
3731 | 3731 | $table_alias_sans_model_relation_chain_prefix = EE_Model_Parser::remove_table_alias_model_relation_chain_prefix($table_alias); |
@@ -3852,7 +3852,7 @@ discard block |
||
3852 | 3852 | * The purpose of this method is to allow us to create a model object that is not in the db that holds default values. |
3853 | 3853 | * A typical example of where this is used is when creating a new item and the initial load of a form. We dont' necessarily want to test for if the object is present but just assume it is BUT load the defaults from the object (as set in the model_field!). |
3854 | 3854 | * |
3855 | - * @return EE_Base_Class single EE_Base_Class object with default values for the properties. |
|
3855 | + * @return boolean single EE_Base_Class object with default values for the properties. |
|
3856 | 3856 | */ |
3857 | 3857 | public function create_default_object() { |
3858 | 3858 | |
@@ -4242,7 +4242,7 @@ discard block |
||
4242 | 4242 | } |
4243 | 4243 | /** |
4244 | 4244 | * Read comments for assume_values_already_prepared_by_model_object() |
4245 | - * @return int |
|
4245 | + * @return boolean |
|
4246 | 4246 | */ |
4247 | 4247 | public function get_assumption_concerning_values_already_prepared_by_model_object(){ |
4248 | 4248 | return $this->_values_already_prepared_by_model_object; |
@@ -604,10 +604,10 @@ discard block |
||
604 | 604 | $stati = EEM_Status::instance()->get_all(array(array('STS_type' => $status_type) ) ); |
605 | 605 | $status_array = array(); |
606 | 606 | foreach ( $stati as $status ) { |
607 | - $status_array[ $status->ID() ] = $status->get('STS_code'); |
|
608 | - } |
|
609 | - return $translated ? EEM_Status::instance()->localized_status($status_array, FALSE, 'sentence') : $status_array; |
|
610 | - } |
|
607 | + $status_array[ $status->ID() ] = $status->get('STS_code'); |
|
608 | + } |
|
609 | + return $translated ? EEM_Status::instance()->localized_status($status_array, FALSE, 'sentence') : $status_array; |
|
610 | + } |
|
611 | 611 | |
612 | 612 | |
613 | 613 | |
@@ -617,7 +617,7 @@ discard block |
||
617 | 617 | * |
618 | 618 | * @var array $0 (where) array { |
619 | 619 | * eg: array('QST_display_text'=>'Are you bob?','QST_admin_text'=>'Determine if user is bob') |
620 | - * becomes |
|
620 | + * becomes |
|
621 | 621 | * SQL >> "...WHERE QST_display_text = 'Are you bob?' AND QST_admin_text = 'Determine if user is bob'...") |
622 | 622 | * |
623 | 623 | * To add WHERE conditions based on related models (and even models-related-to-related-models) prepend the model's name |
@@ -1605,7 +1605,7 @@ discard block |
||
1605 | 1605 | * Deletes a single row from the DB given the model object's primary key value. (eg, EE_Attendee->ID()'s value). |
1606 | 1606 | * Wrapper for EEM_Base::delete() |
1607 | 1607 | * @param mixed $id |
1608 | - * @param boolean $allow_blocking if TRUE, matched objects will only be deleted if there is no related model info |
|
1608 | + * @param boolean $allow_blocking if TRUE, matched objects will only be deleted if there is no related model info |
|
1609 | 1609 | * that blocks it (ie, there' sno other data that depends on this data); if false, deletes regardless of other objects |
1610 | 1610 | * which may depend on it. Its generally advisable to always leave this as TRUE, otherwise you could easily corrupt your DB |
1611 | 1611 | * @return boolean whether the row got deleted or not |
@@ -23,7 +23,7 @@ discard block |
||
23 | 23 | * @since EE4 |
24 | 24 | * |
25 | 25 | */ |
26 | -abstract class EEM_Base extends EE_Base{ |
|
26 | +abstract class EEM_Base extends EE_Base { |
|
27 | 27 | |
28 | 28 | //admin posty |
29 | 29 | //basic -> grants access to mine -> if they don't have it, select none |
@@ -235,7 +235,7 @@ discard block |
||
235 | 235 | * Flag indicating whether this model has a primary key or not |
236 | 236 | * @var boolean |
237 | 237 | */ |
238 | - protected $_has_primary_key_field=null; |
|
238 | + protected $_has_primary_key_field = null; |
|
239 | 239 | |
240 | 240 | /** |
241 | 241 | * Whether or not this model is based off a table in WP core only (CPTs should set |
@@ -297,19 +297,19 @@ discard block |
||
297 | 297 | * operators that work like 'BETWEEN'. Typically used for datetime calculations, i.e. "BETWEEN '12-1-2011' AND '12-31-2012'" |
298 | 298 | * @var array |
299 | 299 | */ |
300 | - protected $_between_style_operators = array( 'BETWEEN' ); |
|
300 | + protected $_between_style_operators = array('BETWEEN'); |
|
301 | 301 | |
302 | 302 | /** |
303 | 303 | * operators that are used for handling NUll and !NULL queries. Typically used for when checking if a row exists on a join table. |
304 | 304 | * @var array |
305 | 305 | */ |
306 | - protected $_null_style_operators = array( 'IS NOT NULL', 'IS NULL'); |
|
306 | + protected $_null_style_operators = array('IS NOT NULL', 'IS NULL'); |
|
307 | 307 | |
308 | 308 | /** |
309 | 309 | * Allowed values for $query_params['order'] for ordering in queries |
310 | 310 | * @var array |
311 | 311 | */ |
312 | - protected $_allowed_order_values = array('asc','desc','ASC','DESC'); |
|
312 | + protected $_allowed_order_values = array('asc', 'desc', 'ASC', 'DESC'); |
|
313 | 313 | |
314 | 314 | /** |
315 | 315 | * When these are keys in a WHERE or HAVING clause, they are handled much differently |
@@ -323,13 +323,13 @@ discard block |
||
323 | 323 | * 'where', but 'where' clauses are so common that we thought we'd omit it |
324 | 324 | * @var array |
325 | 325 | */ |
326 | - private $_allowed_query_params = array(0, 'limit','order_by','group_by','having','force_join','order','on_join_limit','default_where_conditions', 'caps'); |
|
326 | + private $_allowed_query_params = array(0, 'limit', 'order_by', 'group_by', 'having', 'force_join', 'order', 'on_join_limit', 'default_where_conditions', 'caps'); |
|
327 | 327 | |
328 | 328 | /** |
329 | 329 | * All the data types that can be used in $wpdb->prepare statements. |
330 | 330 | * @var array |
331 | 331 | */ |
332 | - private $_valid_wpdb_data_types = array('%d','%s','%f'); |
|
332 | + private $_valid_wpdb_data_types = array('%d', '%s', '%f'); |
|
333 | 333 | |
334 | 334 | /** |
335 | 335 | * EE_Registry Object |
@@ -362,17 +362,17 @@ discard block |
||
362 | 362 | /** |
363 | 363 | * constant used to show EEM_Base has not yet verified the db on this http request |
364 | 364 | */ |
365 | - const db_verified_none = 0; |
|
365 | + const db_verified_none = 0; |
|
366 | 366 | /** |
367 | 367 | * constant used to show EEM_Base has verified the EE core db on this http request, |
368 | 368 | * but not the addons' dbs |
369 | 369 | */ |
370 | - const db_verified_core = 1; |
|
370 | + const db_verified_core = 1; |
|
371 | 371 | /** |
372 | 372 | * constant used to show EEM_Base has verified the addons' dbs (and implicitly |
373 | 373 | * the EE core db too) |
374 | 374 | */ |
375 | - const db_verified_addons = 2; |
|
375 | + const db_verified_addons = 2; |
|
376 | 376 | |
377 | 377 | /** |
378 | 378 | * indicates whether an EEM_Base child has already re-verified the DB |
@@ -409,13 +409,13 @@ discard block |
||
409 | 409 | * @param null $timezone |
410 | 410 | * @throws \EE_Error |
411 | 411 | */ |
412 | - protected function __construct( $timezone = NULL ){ |
|
412 | + protected function __construct($timezone = NULL) { |
|
413 | 413 | // check that the model has not been loaded too soon |
414 | - if ( ! did_action( 'AHEE__EE_System__load_espresso_addons' )) { |
|
415 | - throw new EE_Error ( |
|
414 | + if ( ! did_action('AHEE__EE_System__load_espresso_addons')) { |
|
415 | + throw new EE_Error( |
|
416 | 416 | sprintf( |
417 | - __( 'The %1$s model can not be loaded before the "AHEE__EE_System__load_espresso_addons" hook has been called. This gives other addons a chance to extend this model.', 'event_espresso' ), |
|
418 | - get_class( $this ) |
|
417 | + __('The %1$s model can not be loaded before the "AHEE__EE_System__load_espresso_addons" hook has been called. This gives other addons a chance to extend this model.', 'event_espresso'), |
|
418 | + get_class($this) |
|
419 | 419 | ) |
420 | 420 | ); |
421 | 421 | } |
@@ -425,11 +425,11 @@ discard block |
||
425 | 425 | * just use EE_Register_Model_Extension |
426 | 426 | * @var EE_Table_Base[] $_tables |
427 | 427 | */ |
428 | - $this->_tables = apply_filters( 'FHEE__'.get_class($this).'__construct__tables', $this->_tables ); |
|
429 | - foreach($this->_tables as $table_alias => $table_obj){ |
|
428 | + $this->_tables = apply_filters('FHEE__'.get_class($this).'__construct__tables', $this->_tables); |
|
429 | + foreach ($this->_tables as $table_alias => $table_obj) { |
|
430 | 430 | /** @var $table_obj EE_Table_Base */ |
431 | 431 | $table_obj->_construct_finalize_with_alias($table_alias); |
432 | - if( $table_obj instanceof EE_Secondary_Table ){ |
|
432 | + if ($table_obj instanceof EE_Secondary_Table) { |
|
433 | 433 | /** @var $table_obj EE_Secondary_Table */ |
434 | 434 | $table_obj->_construct_finalize_set_table_to_join_with($this->_get_main_table()); |
435 | 435 | } |
@@ -439,54 +439,54 @@ discard block |
||
439 | 439 | * EE_Register_Model_Extension |
440 | 440 | * @param EE_Model_Field_Base[] $_fields |
441 | 441 | */ |
442 | - $this->_fields = apply_filters('FHEE__'.get_class($this).'__construct__fields',$this->_fields); |
|
442 | + $this->_fields = apply_filters('FHEE__'.get_class($this).'__construct__fields', $this->_fields); |
|
443 | 443 | $this->_invalidate_field_caches(); |
444 | - foreach($this->_fields as $table_alias => $fields_for_table){ |
|
445 | - if ( ! array_key_exists( $table_alias, $this->_tables )){ |
|
446 | - throw new EE_Error(sprintf(__("Table alias %s does not exist in EEM_Base child's _tables array. Only tables defined are %s",'event_espresso'),$table_alias,implode(",",$this->_fields))); |
|
444 | + foreach ($this->_fields as $table_alias => $fields_for_table) { |
|
445 | + if ( ! array_key_exists($table_alias, $this->_tables)) { |
|
446 | + throw new EE_Error(sprintf(__("Table alias %s does not exist in EEM_Base child's _tables array. Only tables defined are %s", 'event_espresso'), $table_alias, implode(",", $this->_fields))); |
|
447 | 447 | } |
448 | - foreach($fields_for_table as $field_name => $field_obj){ |
|
448 | + foreach ($fields_for_table as $field_name => $field_obj) { |
|
449 | 449 | /** @var $field_obj EE_Model_Field_Base | EE_Primary_Key_Field_Base */ |
450 | 450 | //primary key field base has a slightly different _construct_finalize |
451 | 451 | /** @var $field_obj EE_Model_Field_Base */ |
452 | - $field_obj->_construct_finalize( $table_alias, $field_name, $this->get_this_model_name() ); |
|
452 | + $field_obj->_construct_finalize($table_alias, $field_name, $this->get_this_model_name()); |
|
453 | 453 | } |
454 | 454 | } |
455 | 455 | |
456 | 456 | // everything is related to Extra_Meta |
457 | - if( get_class($this) != 'EEM_Extra_Meta'){ |
|
457 | + if (get_class($this) != 'EEM_Extra_Meta') { |
|
458 | 458 | //make extra meta related to everything, but don't block deleting things just |
459 | 459 | //because they have related extra meta info. For now just orphan those extra meta |
460 | 460 | //in the future we should automatically delete them |
461 | - $this->_model_relations['Extra_Meta'] = new EE_Has_Many_Any_Relation( FALSE ); |
|
461 | + $this->_model_relations['Extra_Meta'] = new EE_Has_Many_Any_Relation(FALSE); |
|
462 | 462 | } |
463 | 463 | //and change logs |
464 | - if( get_class( $this) != 'EEM_Change_Log' ) { |
|
465 | - $this->_model_relations[ 'Change_Log' ] = new EE_Has_Many_Any_Relation( FALSE ); |
|
464 | + if (get_class($this) != 'EEM_Change_Log') { |
|
465 | + $this->_model_relations['Change_Log'] = new EE_Has_Many_Any_Relation(FALSE); |
|
466 | 466 | } |
467 | 467 | /** |
468 | 468 | * Filters the list of relations on a model. It is best to NOT use this directly and instead just use |
469 | 469 | * EE_Register_Model_Extension |
470 | 470 | * @param EE_Model_Relation_Base[] $_model_relations |
471 | 471 | */ |
472 | - $this->_model_relations = apply_filters('FHEE__'.get_class($this).'__construct__model_relations',$this->_model_relations); |
|
473 | - foreach($this->_model_relations as $model_name => $relation_obj){ |
|
472 | + $this->_model_relations = apply_filters('FHEE__'.get_class($this).'__construct__model_relations', $this->_model_relations); |
|
473 | + foreach ($this->_model_relations as $model_name => $relation_obj) { |
|
474 | 474 | /** @var $relation_obj EE_Model_Relation_Base */ |
475 | 475 | $relation_obj->_construct_finalize_set_models($this->get_this_model_name(), $model_name); |
476 | 476 | } |
477 | - foreach($this->_indexes as $index_name => $index_obj){ |
|
477 | + foreach ($this->_indexes as $index_name => $index_obj) { |
|
478 | 478 | /** @var $index_obj EE_Index */ |
479 | 479 | $index_obj->_construct_finalize($index_name, $this->get_this_model_name()); |
480 | 480 | } |
481 | 481 | |
482 | 482 | $this->set_timezone($timezone); |
483 | 483 | //finalize default where condition strategy, or set default |
484 | - if( ! $this->_default_where_conditions_strategy){ |
|
484 | + if ( ! $this->_default_where_conditions_strategy) { |
|
485 | 485 | //nothing was set during child constructor, so set default |
486 | 486 | $this->_default_where_conditions_strategy = new EE_Default_Where_Conditions(); |
487 | 487 | } |
488 | 488 | $this->_default_where_conditions_strategy->_finalize_construct($this); |
489 | - if( ! $this->_minimum_where_conditions_strategy){ |
|
489 | + if ( ! $this->_minimum_where_conditions_strategy) { |
|
490 | 490 | //nothing was set during child constructor, so set default |
491 | 491 | $this->_minimum_where_conditions_strategy = new EE_Default_Where_Conditions(); |
492 | 492 | } |
@@ -494,15 +494,15 @@ discard block |
||
494 | 494 | |
495 | 495 | //if the cap slug hasn't been set, and we haven't set it to false on purpose |
496 | 496 | //to indicate to NOT set it, set it to the logical default |
497 | - if( $this->_caps_slug === null ) { |
|
498 | - EE_Registry::instance()->load_helper( 'Inflector' ); |
|
499 | - $this->_caps_slug = EEH_Inflector::pluralize_and_lower( $this->get_this_model_name() ); |
|
497 | + if ($this->_caps_slug === null) { |
|
498 | + EE_Registry::instance()->load_helper('Inflector'); |
|
499 | + $this->_caps_slug = EEH_Inflector::pluralize_and_lower($this->get_this_model_name()); |
|
500 | 500 | } |
501 | 501 | //initialize the standard cap restriction generators if none were specified by the child constructor |
502 | - if( $this->_cap_restriction_generators !== false ){ |
|
503 | - foreach( $this->cap_contexts_to_cap_action_map() as $cap_context => $action ){ |
|
504 | - if( ! isset( $this->_cap_restriction_generators[ $cap_context ] ) ) { |
|
505 | - $this->_cap_restriction_generators[ $cap_context ] = apply_filters( |
|
502 | + if ($this->_cap_restriction_generators !== false) { |
|
503 | + foreach ($this->cap_contexts_to_cap_action_map() as $cap_context => $action) { |
|
504 | + if ( ! isset($this->_cap_restriction_generators[$cap_context])) { |
|
505 | + $this->_cap_restriction_generators[$cap_context] = apply_filters( |
|
506 | 506 | 'FHEE__EEM_Base___construct__standard_cap_restriction_generator', |
507 | 507 | new EE_Restriction_Generator_Protected(), |
508 | 508 | $cap_context, |
@@ -512,23 +512,23 @@ discard block |
||
512 | 512 | } |
513 | 513 | } |
514 | 514 | //if there are cap restriction generators, use them to make the default cap restrictions |
515 | - if( $this->_cap_restriction_generators !== false ){ |
|
516 | - foreach( $this->_cap_restriction_generators as $context => $generator_object ) { |
|
517 | - if( ! $generator_object ){ |
|
515 | + if ($this->_cap_restriction_generators !== false) { |
|
516 | + foreach ($this->_cap_restriction_generators as $context => $generator_object) { |
|
517 | + if ( ! $generator_object) { |
|
518 | 518 | continue; |
519 | 519 | } |
520 | - if( ! $generator_object instanceof EE_Restriction_Generator_Base ){ |
|
520 | + if ( ! $generator_object instanceof EE_Restriction_Generator_Base) { |
|
521 | 521 | throw new EE_Error( |
522 | 522 | sprintf( |
523 | - __( 'Index "%1$s" in the model %2$s\'s _cap_restriction_generators is not a child of EE_Restriction_Generator_Base. It should be that or NULL.', 'event_espresso' ), |
|
523 | + __('Index "%1$s" in the model %2$s\'s _cap_restriction_generators is not a child of EE_Restriction_Generator_Base. It should be that or NULL.', 'event_espresso'), |
|
524 | 524 | $context, |
525 | 525 | $this->get_this_model_name() |
526 | 526 | ) |
527 | 527 | ); |
528 | 528 | } |
529 | - $action = $this->cap_action_for_context( $context ); |
|
530 | - if( ! $generator_object->construction_finalized() ){ |
|
531 | - $generator_object->_construct_finalize( $this, $action ); |
|
529 | + $action = $this->cap_action_for_context($context); |
|
530 | + if ( ! $generator_object->construction_finalized()) { |
|
531 | + $generator_object->_construct_finalize($this, $action); |
|
532 | 532 | } |
533 | 533 | |
534 | 534 | } |
@@ -542,11 +542,11 @@ discard block |
||
542 | 542 | * @param string $context one of EEM_Base::valid_cap_contexts() |
543 | 543 | * @return EE_Default_Where_Conditions[] |
544 | 544 | */ |
545 | - protected function _generate_cap_restrictions( $context ){ |
|
546 | - if( isset( $this->_cap_restriction_generators[ $context ] ) && |
|
547 | - $this->_cap_restriction_generators[ $context ] instanceof EE_Restriction_Generator_Base ) { |
|
548 | - return $this->_cap_restriction_generators[ $context ]->generate_restrictions(); |
|
549 | - }else{ |
|
545 | + protected function _generate_cap_restrictions($context) { |
|
546 | + if (isset($this->_cap_restriction_generators[$context]) && |
|
547 | + $this->_cap_restriction_generators[$context] instanceof EE_Restriction_Generator_Base) { |
|
548 | + return $this->_cap_restriction_generators[$context]->generate_restrictions(); |
|
549 | + } else { |
|
550 | 550 | return array(); |
551 | 551 | } |
552 | 552 | } |
@@ -559,16 +559,16 @@ discard block |
||
559 | 559 | * @param string $timezone string representing the timezone we want to set for returned Date Time Strings (and any incoming timezone data that gets saved). Note this just sends the timezone info to the date time model field objects. Default is NULL (and will be assumed using the set timezone in the 'timezone_string' wp option) |
560 | 560 | * @return static (as in the concrete child class) |
561 | 561 | */ |
562 | - public static function instance( $timezone = NULL ){ |
|
562 | + public static function instance($timezone = NULL) { |
|
563 | 563 | |
564 | 564 | // check if instance of Espresso_model already exists |
565 | 565 | if ( ! static::$_instance instanceof static) { |
566 | 566 | // instantiate Espresso_model |
567 | - static::$_instance = new static( $timezone ); |
|
567 | + static::$_instance = new static($timezone); |
|
568 | 568 | } |
569 | 569 | |
570 | 570 | //we might have a timezone set, let set_timezone decide what to do with it |
571 | - static::$_instance->set_timezone( $timezone ); |
|
571 | + static::$_instance->set_timezone($timezone); |
|
572 | 572 | |
573 | 573 | // Espresso_model object |
574 | 574 | return static::$_instance; |
@@ -581,11 +581,11 @@ discard block |
||
581 | 581 | * @param null | string $timezone |
582 | 582 | * @return static |
583 | 583 | */ |
584 | - public static function reset( $timezone = NULL ){ |
|
585 | - if ( ! is_null( static::$_instance ) ) { |
|
584 | + public static function reset($timezone = NULL) { |
|
585 | + if ( ! is_null(static::$_instance)) { |
|
586 | 586 | static::$_instance = null; |
587 | 587 | |
588 | - return self::instance( $timezone ); |
|
588 | + return self::instance($timezone); |
|
589 | 589 | } |
590 | 590 | return null; |
591 | 591 | } |
@@ -596,15 +596,15 @@ discard block |
||
596 | 596 | * @param boolean $translated return localized strings or JUST the array. |
597 | 597 | * @return array |
598 | 598 | */ |
599 | - public function status_array( $translated = FALSE ) { |
|
600 | - if ( !array_key_exists('Status', $this->_model_relations ) ) |
|
599 | + public function status_array($translated = FALSE) { |
|
600 | + if ( ! array_key_exists('Status', $this->_model_relations)) |
|
601 | 601 | return array(); |
602 | 602 | $model_name = $this->get_this_model_name(); |
603 | - $status_type = str_replace(' ', '_', strtolower( str_replace('_', ' ', $model_name) ) ); |
|
604 | - $stati = EEM_Status::instance()->get_all(array(array('STS_type' => $status_type) ) ); |
|
603 | + $status_type = str_replace(' ', '_', strtolower(str_replace('_', ' ', $model_name))); |
|
604 | + $stati = EEM_Status::instance()->get_all(array(array('STS_type' => $status_type))); |
|
605 | 605 | $status_array = array(); |
606 | - foreach ( $stati as $status ) { |
|
607 | - $status_array[ $status->ID() ] = $status->get('STS_code'); |
|
606 | + foreach ($stati as $status) { |
|
607 | + $status_array[$status->ID()] = $status->get('STS_code'); |
|
608 | 608 | } |
609 | 609 | return $translated ? EEM_Status::instance()->localized_status($status_array, FALSE, 'sentence') : $status_array; |
610 | 610 | } |
@@ -787,7 +787,7 @@ discard block |
||
787 | 787 | * 'order_by'=>array('ANS_value'=>'ASC') |
788 | 788 | * )); |
789 | 789 | */ |
790 | - function get_all($query_params = array()){ |
|
790 | + function get_all($query_params = array()) { |
|
791 | 791 | return $this->_create_objects($this->_get_all_wpdb_results($query_params, ARRAY_A, NULL)); |
792 | 792 | } |
793 | 793 | |
@@ -797,10 +797,10 @@ discard block |
||
797 | 797 | * @param array $query_params @see EEM_Base::get_all() |
798 | 798 | * @return array like EEM_Base::get_all |
799 | 799 | */ |
800 | - function alter_query_params_to_only_include_mine( $query_params = array() ) { |
|
800 | + function alter_query_params_to_only_include_mine($query_params = array()) { |
|
801 | 801 | $wp_user_field_name = $this->wp_user_field_name(); |
802 | - if( $wp_user_field_name ){ |
|
803 | - $query_params[0][ $wp_user_field_name ] = get_current_user_id(); |
|
802 | + if ($wp_user_field_name) { |
|
803 | + $query_params[0][$wp_user_field_name] = get_current_user_id(); |
|
804 | 804 | } |
805 | 805 | return $query_params; |
806 | 806 | } |
@@ -813,19 +813,19 @@ discard block |
||
813 | 813 | * foreign key to the WP_User table |
814 | 814 | */ |
815 | 815 | function wp_user_field_name() { |
816 | - try{ |
|
817 | - if( ! empty( $this->_model_chain_to_wp_user ) ) { |
|
818 | - $models_to_follow_to_wp_users = explode( '.', $this->_model_chain_to_wp_user ); |
|
819 | - $last_model_name = end( $models_to_follow_to_wp_users ); |
|
820 | - $model_with_fk_to_wp_users = EE_Registry::instance()->load_model( $last_model_name ); |
|
821 | - $model_chain_to_wp_user = $this->_model_chain_to_wp_user . '.'; |
|
822 | - }else{ |
|
816 | + try { |
|
817 | + if ( ! empty($this->_model_chain_to_wp_user)) { |
|
818 | + $models_to_follow_to_wp_users = explode('.', $this->_model_chain_to_wp_user); |
|
819 | + $last_model_name = end($models_to_follow_to_wp_users); |
|
820 | + $model_with_fk_to_wp_users = EE_Registry::instance()->load_model($last_model_name); |
|
821 | + $model_chain_to_wp_user = $this->_model_chain_to_wp_user.'.'; |
|
822 | + } else { |
|
823 | 823 | $model_with_fk_to_wp_users = $this; |
824 | 824 | $model_chain_to_wp_user = ''; |
825 | 825 | } |
826 | - $wp_user_field = $model_with_fk_to_wp_users->get_foreign_key_to( 'WP_User' ); |
|
827 | - return $model_chain_to_wp_user . $wp_user_field->get_name(); |
|
828 | - }catch( EE_Error $e ) { |
|
826 | + $wp_user_field = $model_with_fk_to_wp_users->get_foreign_key_to('WP_User'); |
|
827 | + return $model_chain_to_wp_user.$wp_user_field->get_name(); |
|
828 | + } catch (EE_Error $e) { |
|
829 | 829 | return false; |
830 | 830 | } |
831 | 831 | } |
@@ -839,7 +839,7 @@ discard block |
||
839 | 839 | * (or transiently-related model) |
840 | 840 | * @return string |
841 | 841 | */ |
842 | - public function model_chain_to_wp_user(){ |
|
842 | + public function model_chain_to_wp_user() { |
|
843 | 843 | return $this->_model_chain_to_wp_user; |
844 | 844 | } |
845 | 845 | |
@@ -851,13 +851,13 @@ discard block |
||
851 | 851 | * @return boolean |
852 | 852 | */ |
853 | 853 | public function is_owned() { |
854 | - if( $this->model_chain_to_wp_user() ){ |
|
854 | + if ($this->model_chain_to_wp_user()) { |
|
855 | 855 | return true; |
856 | - }else{ |
|
857 | - try{ |
|
858 | - $this->get_foreign_key_to( 'WP_User' ); |
|
856 | + } else { |
|
857 | + try { |
|
858 | + $this->get_foreign_key_to('WP_User'); |
|
859 | 859 | return true; |
860 | - }catch( EE_Error $e ){ |
|
860 | + } catch (EE_Error $e) { |
|
861 | 861 | return false; |
862 | 862 | } |
863 | 863 | } |
@@ -876,21 +876,21 @@ discard block |
||
876 | 876 | * and 1 is the data type. Eg, array('count'=>array('COUNT(REG_ID)','%d')) |
877 | 877 | * @return array | stdClass[] like results of $wpdb->get_results($sql,OBJECT), (ie, output type is OBJECT) |
878 | 878 | */ |
879 | - protected function _get_all_wpdb_results($query_params = array(), $output = ARRAY_A, $columns_to_select = null){ |
|
879 | + protected function _get_all_wpdb_results($query_params = array(), $output = ARRAY_A, $columns_to_select = null) { |
|
880 | 880 | //remember the custom selections, if any |
881 | - if(is_array($columns_to_select)){ |
|
881 | + if (is_array($columns_to_select)) { |
|
882 | 882 | $this->_custom_selections = $columns_to_select; |
883 | - }elseif(is_string($columns_to_select)){ |
|
883 | + }elseif (is_string($columns_to_select)) { |
|
884 | 884 | $this->_custom_selections = array($this->_custom_selections); |
885 | - }else{ |
|
885 | + } else { |
|
886 | 886 | $this->_custom_selections = array(); |
887 | 887 | } |
888 | 888 | |
889 | 889 | $model_query_info = $this->_create_model_query_info_carrier($query_params); |
890 | 890 | $select_expressions = $columns_to_select ? $this->_construct_select_from_input($columns_to_select) : $this->_construct_default_select_sql($model_query_info); |
891 | - $SQL ="SELECT $select_expressions ".$this->_construct_2nd_half_of_select_query($model_query_info); |
|
891 | + $SQL = "SELECT $select_expressions ".$this->_construct_2nd_half_of_select_query($model_query_info); |
|
892 | 892 | // echo "sql:$SQL"; |
893 | - $results = $this->_do_wpdb_query( 'get_results', array($SQL, $output ) );// $wpdb->get_results($SQL, $output); |
|
893 | + $results = $this->_do_wpdb_query('get_results', array($SQL, $output)); // $wpdb->get_results($SQL, $output); |
|
894 | 894 | return $results; |
895 | 895 | } |
896 | 896 | |
@@ -908,7 +908,7 @@ discard block |
||
908 | 908 | * and 1 is the data type. Eg, array('count'=>array('COUNT(REG_ID)','%d')) |
909 | 909 | * @return array|stdClass[] like results of $wpdb->get_results($sql,OBJECT), (ie, output type is OBJECT) |
910 | 910 | */ |
911 | - public function get_all_wpdb_results($query_params = array(), $output = ARRAY_A, $columns_to_select = null){ |
|
911 | + public function get_all_wpdb_results($query_params = array(), $output = ARRAY_A, $columns_to_select = null) { |
|
912 | 912 | return $this->_get_all_wpdb_results($query_params, $output, $columns_to_select); |
913 | 913 | } |
914 | 914 | |
@@ -920,12 +920,12 @@ discard block |
||
920 | 920 | * @throws EE_Error |
921 | 921 | * @return string |
922 | 922 | */ |
923 | - private function _construct_select_from_input($columns_to_select){ |
|
924 | - if(is_array($columns_to_select)){ |
|
923 | + private function _construct_select_from_input($columns_to_select) { |
|
924 | + if (is_array($columns_to_select)) { |
|
925 | 925 | $select_sql_array = array(); |
926 | 926 | |
927 | - foreach($columns_to_select as $alias => $selection_and_datatype){ |
|
928 | - if( ! is_array($selection_and_datatype) || ! isset($selection_and_datatype[1])){ |
|
927 | + foreach ($columns_to_select as $alias => $selection_and_datatype) { |
|
928 | + if ( ! is_array($selection_and_datatype) || ! isset($selection_and_datatype[1])) { |
|
929 | 929 | throw new EE_Error( |
930 | 930 | sprintf( |
931 | 931 | __( |
@@ -937,24 +937,24 @@ discard block |
||
937 | 937 | ) |
938 | 938 | ); |
939 | 939 | } |
940 | - if( ! in_array( $selection_and_datatype[1],$this->_valid_wpdb_data_types)){ |
|
940 | + if ( ! in_array($selection_and_datatype[1], $this->_valid_wpdb_data_types)) { |
|
941 | 941 | throw new EE_Error( |
942 | 942 | sprintf( |
943 | 943 | __( |
944 | 944 | "Datatype %s (for selection '%s' and alias '%s') is not a valid wpdb datatype (eg %%s)", |
945 | 945 | "event_espresso" |
946 | 946 | ), |
947 | - $selection_and_datatype[ 1 ], |
|
948 | - $selection_and_datatype[ 0 ], |
|
947 | + $selection_and_datatype[1], |
|
948 | + $selection_and_datatype[0], |
|
949 | 949 | $alias, |
950 | - implode( ",", $this->_valid_wpdb_data_types ) |
|
950 | + implode(",", $this->_valid_wpdb_data_types) |
|
951 | 951 | ) |
952 | 952 | ); |
953 | 953 | } |
954 | 954 | $select_sql_array[] = "{$selection_and_datatype[0]} AS $alias"; |
955 | 955 | } |
956 | - $columns_to_select_string = implode(", ",$select_sql_array); |
|
957 | - }else{ |
|
956 | + $columns_to_select_string = implode(", ", $select_sql_array); |
|
957 | + } else { |
|
958 | 958 | $columns_to_select_string = $columns_to_select; |
959 | 959 | } |
960 | 960 | return $columns_to_select_string; |
@@ -967,7 +967,7 @@ discard block |
||
967 | 967 | * Convenient wrapper for getting the primary key field's name. Eg, on Registration, this would be 'REG_ID' |
968 | 968 | * @return string |
969 | 969 | */ |
970 | - function primary_key_name(){ |
|
970 | + function primary_key_name() { |
|
971 | 971 | return $this->get_primary_key_field()->get_name(); |
972 | 972 | } |
973 | 973 | |
@@ -979,14 +979,14 @@ discard block |
||
979 | 979 | * @param mixed $id int or string, depending on the type of the model's primary key |
980 | 980 | * @return EE_Base_Class |
981 | 981 | */ |
982 | - function get_one_by_ID($id){ |
|
983 | - if( $this->get_from_entity_map( $id ) ){ |
|
984 | - return $this->get_from_entity_map( $id ); |
|
982 | + function get_one_by_ID($id) { |
|
983 | + if ($this->get_from_entity_map($id)) { |
|
984 | + return $this->get_from_entity_map($id); |
|
985 | 985 | } |
986 | 986 | return $this->get_one( |
987 | 987 | $this->alter_query_params_to_restrict_by_ID( |
988 | 988 | $id, |
989 | - array( 'default_where_conditions' => 'minimum' ) |
|
989 | + array('default_where_conditions' => 'minimum') |
|
990 | 990 | ) |
991 | 991 | ); |
992 | 992 | } |
@@ -998,15 +998,15 @@ discard block |
||
998 | 998 | * @param array $query_params |
999 | 999 | * @return array of normal query params, @see EEM_Base::get_all |
1000 | 1000 | */ |
1001 | - public function alter_query_params_to_restrict_by_ID( $id, $query_params = array() ) { |
|
1002 | - if( ! isset( $query_params[ 0 ] ) ) { |
|
1003 | - $query_params[ 0 ] = array(); |
|
1001 | + public function alter_query_params_to_restrict_by_ID($id, $query_params = array()) { |
|
1002 | + if ( ! isset($query_params[0])) { |
|
1003 | + $query_params[0] = array(); |
|
1004 | 1004 | } |
1005 | - if( $this->has_primary_key_field ( ) ) { |
|
1006 | - $query_params[ 0 ][ $this->primary_key_name() ] = $id ; |
|
1007 | - }else{ |
|
1005 | + if ($this->has_primary_key_field( )) { |
|
1006 | + $query_params[0][$this->primary_key_name()] = $id; |
|
1007 | + } else { |
|
1008 | 1008 | //no primary key, so the $id must be from the get_index_primary_key_string() |
1009 | - $query_params[0] = array_replace_recursive( $query_params[ 0 ], $this->parse_index_primary_key_string( $id ) ); |
|
1009 | + $query_params[0] = array_replace_recursive($query_params[0], $this->parse_index_primary_key_string($id)); |
|
1010 | 1010 | } |
1011 | 1011 | return $query_params; |
1012 | 1012 | } |
@@ -1018,16 +1018,16 @@ discard block |
||
1018 | 1018 | * @param array $query_params like EEM_Base's $query_params variable. |
1019 | 1019 | * @return EE_Base_Class | NULL |
1020 | 1020 | */ |
1021 | - function get_one($query_params = array()){ |
|
1022 | - if( ! is_array( $query_params ) ){ |
|
1023 | - EE_Error::doing_it_wrong('EEM_Base::get_one', sprintf( __( '$query_params should be an array, you passed a variable of type %s', 'event_espresso' ), gettype( $query_params ) ), '4.6.0' ); |
|
1021 | + function get_one($query_params = array()) { |
|
1022 | + if ( ! is_array($query_params)) { |
|
1023 | + EE_Error::doing_it_wrong('EEM_Base::get_one', sprintf(__('$query_params should be an array, you passed a variable of type %s', 'event_espresso'), gettype($query_params)), '4.6.0'); |
|
1024 | 1024 | $query_params = array(); |
1025 | 1025 | } |
1026 | 1026 | $query_params['limit'] = 1; |
1027 | 1027 | $items = $this->get_all($query_params); |
1028 | - if(empty($items)){ |
|
1028 | + if (empty($items)) { |
|
1029 | 1029 | return null; |
1030 | - }else{ |
|
1030 | + } else { |
|
1031 | 1031 | return array_shift($items); |
1032 | 1032 | } |
1033 | 1033 | } |
@@ -1051,8 +1051,8 @@ discard block |
||
1051 | 1051 | * |
1052 | 1052 | * @return EE_Base_Class[]|array |
1053 | 1053 | */ |
1054 | - public function next_x( $current_field_value, $field_to_order_by = null, $limit = 1, $query_params = array(), $columns_to_select = null ) { |
|
1055 | - return $this->_get_consecutive( $current_field_value, '>', $field_to_order_by, $limit, $query_params, $columns_to_select ); |
|
1054 | + public function next_x($current_field_value, $field_to_order_by = null, $limit = 1, $query_params = array(), $columns_to_select = null) { |
|
1055 | + return $this->_get_consecutive($current_field_value, '>', $field_to_order_by, $limit, $query_params, $columns_to_select); |
|
1056 | 1056 | } |
1057 | 1057 | |
1058 | 1058 | |
@@ -1075,8 +1075,8 @@ discard block |
||
1075 | 1075 | * |
1076 | 1076 | * @return EE_Base_Class[]|array |
1077 | 1077 | */ |
1078 | - public function previous_x( $current_field_value, $field_to_order_by = null, $limit = 1, $query_params = array(), $columns_to_select = null ) { |
|
1079 | - return $this->_get_consecutive( $current_field_value, '<', $field_to_order_by, $limit, $query_params, $columns_to_select ); |
|
1078 | + public function previous_x($current_field_value, $field_to_order_by = null, $limit = 1, $query_params = array(), $columns_to_select = null) { |
|
1079 | + return $this->_get_consecutive($current_field_value, '<', $field_to_order_by, $limit, $query_params, $columns_to_select); |
|
1080 | 1080 | } |
1081 | 1081 | |
1082 | 1082 | |
@@ -1098,9 +1098,9 @@ discard block |
||
1098 | 1098 | * |
1099 | 1099 | * @return EE_Base_Class|null|array() |
1100 | 1100 | */ |
1101 | - public function next( $current_field_value, $field_to_order_by = null, $query_params = array(), $columns_to_select = null ) { |
|
1102 | - $results = $this->_get_consecutive( $current_field_value, '>', $field_to_order_by, 1, $query_params, $columns_to_select ); |
|
1103 | - return empty( $results ) ? null : reset( $results ); |
|
1101 | + public function next($current_field_value, $field_to_order_by = null, $query_params = array(), $columns_to_select = null) { |
|
1102 | + $results = $this->_get_consecutive($current_field_value, '>', $field_to_order_by, 1, $query_params, $columns_to_select); |
|
1103 | + return empty($results) ? null : reset($results); |
|
1104 | 1104 | } |
1105 | 1105 | |
1106 | 1106 | |
@@ -1122,9 +1122,9 @@ discard block |
||
1122 | 1122 | * |
1123 | 1123 | * @return EE_Base_Class|null|array() |
1124 | 1124 | */ |
1125 | - public function previous( $current_field_value, $field_to_order_by = null, $query_params = array(), $columns_to_select = null ) { |
|
1126 | - $results = $this->_get_consecutive( $current_field_value, '<', $field_to_order_by, 1, $query_params, $columns_to_select ); |
|
1127 | - return empty( $results ) ? null : reset( $results ); |
|
1125 | + public function previous($current_field_value, $field_to_order_by = null, $query_params = array(), $columns_to_select = null) { |
|
1126 | + $results = $this->_get_consecutive($current_field_value, '<', $field_to_order_by, 1, $query_params, $columns_to_select); |
|
1127 | + return empty($results) ? null : reset($results); |
|
1128 | 1128 | } |
1129 | 1129 | |
1130 | 1130 | |
@@ -1150,40 +1150,40 @@ discard block |
||
1150 | 1150 | * @return EE_Base_Class[]|array |
1151 | 1151 | * @throws EE_Error |
1152 | 1152 | */ |
1153 | - protected function _get_consecutive( $current_field_value, $operand = '>', $field_to_order_by = null, $limit = 1, $query_params = array(), $columns_to_select = null ) { |
|
1153 | + protected function _get_consecutive($current_field_value, $operand = '>', $field_to_order_by = null, $limit = 1, $query_params = array(), $columns_to_select = null) { |
|
1154 | 1154 | //if $field_to_order_by is empty then let's assume we're ordering by the primary key. |
1155 | - if ( empty( $field_to_order_by ) ) { |
|
1156 | - if ( $this->has_primary_key_field() ) { |
|
1155 | + if (empty($field_to_order_by)) { |
|
1156 | + if ($this->has_primary_key_field()) { |
|
1157 | 1157 | $field_to_order_by = $this->get_primary_key_field()->get_name(); |
1158 | 1158 | } else { |
1159 | 1159 | |
1160 | - if ( WP_DEBUG ) { |
|
1161 | - throw new EE_Error( __( 'EEM_Base::_get_consecutive() has been called with no $field_to_order_by argument and there is no primary key on the field. Please provide the field you would like to use as the base for retrieving the next item(s).', 'event_espresso' ) ); |
|
1160 | + if (WP_DEBUG) { |
|
1161 | + throw new EE_Error(__('EEM_Base::_get_consecutive() has been called with no $field_to_order_by argument and there is no primary key on the field. Please provide the field you would like to use as the base for retrieving the next item(s).', 'event_espresso')); |
|
1162 | 1162 | } |
1163 | - EE_Error::add_error( __('There was an error with the query.', 'event_espresso') ); |
|
1163 | + EE_Error::add_error(__('There was an error with the query.', 'event_espresso')); |
|
1164 | 1164 | return array(); |
1165 | 1165 | } |
1166 | 1166 | } |
1167 | 1167 | |
1168 | - if( ! is_array( $query_params ) ){ |
|
1169 | - EE_Error::doing_it_wrong('EEM_Base::_get_consecutive', sprintf( __( '$query_params should be an array, you passed a variable of type %s', 'event_espresso' ), gettype( $query_params ) ), '4.6.0' ); |
|
1168 | + if ( ! is_array($query_params)) { |
|
1169 | + EE_Error::doing_it_wrong('EEM_Base::_get_consecutive', sprintf(__('$query_params should be an array, you passed a variable of type %s', 'event_espresso'), gettype($query_params)), '4.6.0'); |
|
1170 | 1170 | $query_params = array(); |
1171 | 1171 | } |
1172 | 1172 | |
1173 | 1173 | //let's add the where query param for consecutive look up. |
1174 | - $query_params[0][ $field_to_order_by ] = array( $operand, $current_field_value ); |
|
1174 | + $query_params[0][$field_to_order_by] = array($operand, $current_field_value); |
|
1175 | 1175 | $query_params['limit'] = $limit; |
1176 | 1176 | |
1177 | 1177 | //set direction |
1178 | - $incoming_orderby = isset( $query_params['order_by'] ) ? $query_params['order_by'] : array(); |
|
1179 | - $query_params['order_by'] = $operand == '>' ? array( $field_to_order_by => 'ASC' ) + $incoming_orderby : array( $field_to_order_by => 'DESC') + $incoming_orderby; |
|
1178 | + $incoming_orderby = isset($query_params['order_by']) ? $query_params['order_by'] : array(); |
|
1179 | + $query_params['order_by'] = $operand == '>' ? array($field_to_order_by => 'ASC') + $incoming_orderby : array($field_to_order_by => 'DESC') + $incoming_orderby; |
|
1180 | 1180 | |
1181 | 1181 | //if $columns_to_select is empty then that means we're returning EE_Base_Class objects |
1182 | - if ( empty( $columns_to_select ) ) { |
|
1183 | - return $this->get_all( $query_params ); |
|
1182 | + if (empty($columns_to_select)) { |
|
1183 | + return $this->get_all($query_params); |
|
1184 | 1184 | } else { |
1185 | 1185 | //getting just the fields |
1186 | - return $this->_get_all_wpdb_results( $query_params, ARRAY_A, $columns_to_select ); |
|
1186 | + return $this->_get_all_wpdb_results($query_params, ARRAY_A, $columns_to_select); |
|
1187 | 1187 | } |
1188 | 1188 | } |
1189 | 1189 | |
@@ -1194,18 +1194,18 @@ discard block |
||
1194 | 1194 | * This sets the _timezone property after model object has been instantiated. |
1195 | 1195 | * @param null | string $timezone valid PHP DateTimeZone timezone string |
1196 | 1196 | */ |
1197 | - public function set_timezone( $timezone ) { |
|
1198 | - if ( $timezone !== null ) { |
|
1197 | + public function set_timezone($timezone) { |
|
1198 | + if ($timezone !== null) { |
|
1199 | 1199 | $this->_timezone = $timezone; |
1200 | 1200 | } |
1201 | 1201 | //note we need to loop through relations and set the timezone on those objects as well. |
1202 | - foreach ( $this->_model_relations as $relation ) { |
|
1203 | - $relation->set_timezone( $timezone ); |
|
1202 | + foreach ($this->_model_relations as $relation) { |
|
1203 | + $relation->set_timezone($timezone); |
|
1204 | 1204 | } |
1205 | 1205 | //and finally we do the same for any datetime fields |
1206 | - foreach ( $this->_fields as $field ) { |
|
1207 | - if ( $field instanceof EE_Datetime_Field ) { |
|
1208 | - $field->set_timezone( $timezone ); |
|
1206 | + foreach ($this->_fields as $field) { |
|
1207 | + if ($field instanceof EE_Datetime_Field) { |
|
1208 | + $field->set_timezone($timezone); |
|
1209 | 1209 | } |
1210 | 1210 | } |
1211 | 1211 | } |
@@ -1220,9 +1220,9 @@ discard block |
||
1220 | 1220 | */ |
1221 | 1221 | public function get_timezone() { |
1222 | 1222 | //first validate if timezone is set. If not, then let's set it be whatever is set on the model fields. |
1223 | - if ( empty( $this->_timezone ) ) { |
|
1224 | - foreach( $this->_fields as $field ) { |
|
1225 | - if ( $field instanceof EE_Datetime_Field ) { |
|
1223 | + if (empty($this->_timezone)) { |
|
1224 | + foreach ($this->_fields as $field) { |
|
1225 | + if ($field instanceof EE_Datetime_Field) { |
|
1226 | 1226 | $this->set_timezone($field->get_timezone()); |
1227 | 1227 | break; |
1228 | 1228 | } |
@@ -1230,9 +1230,9 @@ discard block |
||
1230 | 1230 | } |
1231 | 1231 | |
1232 | 1232 | //if timezone STILL empty then return the default timezone for the site. |
1233 | - if ( empty( $this->_timezone ) ) { |
|
1234 | - EE_Registry::instance()->load_helper( 'DTT_Helper' ); |
|
1235 | - $this->set_timezone( EEH_DTT_Helper::get_timezone() ); |
|
1233 | + if (empty($this->_timezone)) { |
|
1234 | + EE_Registry::instance()->load_helper('DTT_Helper'); |
|
1235 | + $this->set_timezone(EEH_DTT_Helper::get_timezone()); |
|
1236 | 1236 | } |
1237 | 1237 | return $this->_timezone; |
1238 | 1238 | } |
@@ -1250,19 +1250,19 @@ discard block |
||
1250 | 1250 | * |
1251 | 1251 | * @return array formats in an array with the date format first, and the time format last. |
1252 | 1252 | */ |
1253 | - public function get_formats_for( $field_name, $pretty = false ) { |
|
1254 | - $field_settings = $this->field_settings_for( $field_name ); |
|
1253 | + public function get_formats_for($field_name, $pretty = false) { |
|
1254 | + $field_settings = $this->field_settings_for($field_name); |
|
1255 | 1255 | |
1256 | 1256 | //if not a valid EE_Datetime_Field then throw error |
1257 | - if ( ! $field_settings instanceof EE_Datetime_Field ) { |
|
1258 | - throw new EE_Error( sprintf( __('The field sent into EEM_Base::get_formats_for (%s) is not registered as a EE_Datetime_Field. Please check the spelling and make sure you are submitting the right field name to retrieve date_formats for.', 'event_espresso' ), $field_name ) ); |
|
1257 | + if ( ! $field_settings instanceof EE_Datetime_Field) { |
|
1258 | + throw new EE_Error(sprintf(__('The field sent into EEM_Base::get_formats_for (%s) is not registered as a EE_Datetime_Field. Please check the spelling and make sure you are submitting the right field name to retrieve date_formats for.', 'event_espresso'), $field_name)); |
|
1259 | 1259 | } |
1260 | 1260 | |
1261 | 1261 | //while we are here, let's make sure the timezone internally in EEM_Base matches what is stored on |
1262 | 1262 | //the field. |
1263 | 1263 | $this->_timezone = $field_settings->get_timezone(); |
1264 | 1264 | |
1265 | - return array( $field_settings->get_date_format( $pretty ), $field_settings->get_time_format( $pretty ) ); |
|
1265 | + return array($field_settings->get_date_format($pretty), $field_settings->get_time_format($pretty)); |
|
1266 | 1266 | } |
1267 | 1267 | |
1268 | 1268 | |
@@ -1286,25 +1286,25 @@ discard block |
||
1286 | 1286 | * @return int|string If the given field_name is not of the EE_Datetime_Field type, then an EE_Error |
1287 | 1287 | * exception is triggered. |
1288 | 1288 | */ |
1289 | - public function current_time_for_query( $field_name, $timestamp = false, $what = 'both' ) { |
|
1290 | - $formats = $this->get_formats_for( $field_name ); |
|
1289 | + public function current_time_for_query($field_name, $timestamp = false, $what = 'both') { |
|
1290 | + $formats = $this->get_formats_for($field_name); |
|
1291 | 1291 | |
1292 | - $DateTime = new DateTime( "now", new DateTimeZone( $this->_timezone ) ); |
|
1292 | + $DateTime = new DateTime("now", new DateTimeZone($this->_timezone)); |
|
1293 | 1293 | |
1294 | - if ( $timestamp ) { |
|
1295 | - return $DateTime->format( 'U' ); |
|
1294 | + if ($timestamp) { |
|
1295 | + return $DateTime->format('U'); |
|
1296 | 1296 | } |
1297 | 1297 | |
1298 | 1298 | //not returning timestamp, so return formatted string in timezone. |
1299 | - switch( $what ) { |
|
1299 | + switch ($what) { |
|
1300 | 1300 | case 'time' : |
1301 | - return $DateTime->format( $formats[1] ); |
|
1301 | + return $DateTime->format($formats[1]); |
|
1302 | 1302 | break; |
1303 | 1303 | case 'date' : |
1304 | - return $DateTime->format( $formats[0] ); |
|
1304 | + return $DateTime->format($formats[0]); |
|
1305 | 1305 | break; |
1306 | 1306 | default : |
1307 | - return $DateTime->format( implode( ' ', $formats ) ); |
|
1307 | + return $DateTime->format(implode(' ', $formats)); |
|
1308 | 1308 | break; |
1309 | 1309 | } |
1310 | 1310 | } |
@@ -1328,20 +1328,20 @@ discard block |
||
1328 | 1328 | * 'U', this is ignored. |
1329 | 1329 | * @return DateTime |
1330 | 1330 | */ |
1331 | - public function convert_datetime_for_query( $field_name, $timestring, $incoming_format, $timezone = '' ) { |
|
1331 | + public function convert_datetime_for_query($field_name, $timestring, $incoming_format, $timezone = '') { |
|
1332 | 1332 | |
1333 | 1333 | //just using this to ensure the timezone is set correctly internally |
1334 | - $this->get_formats_for( $field_name ); |
|
1334 | + $this->get_formats_for($field_name); |
|
1335 | 1335 | |
1336 | 1336 | //load EEH_DTT_Helper |
1337 | - EE_Registry::instance()->load_helper( 'DTT_Helper' ); |
|
1338 | - $set_timezone = empty( $timezone ) ? EEH_DTT_Helper::get_timezone() : $timezone; |
|
1337 | + EE_Registry::instance()->load_helper('DTT_Helper'); |
|
1338 | + $set_timezone = empty($timezone) ? EEH_DTT_Helper::get_timezone() : $timezone; |
|
1339 | 1339 | |
1340 | - $incomingDateTime = date_create_from_format( $incoming_format, $timestring, new DateTimeZone( $set_timezone ) ); |
|
1341 | - if( $incomingDateTime ) { |
|
1342 | - return $incomingDateTime->setTimeZone( new DateTimeZone( $this->_timezone ) ); |
|
1340 | + $incomingDateTime = date_create_from_format($incoming_format, $timestring, new DateTimeZone($set_timezone)); |
|
1341 | + if ($incomingDateTime) { |
|
1342 | + return $incomingDateTime->setTimeZone(new DateTimeZone($this->_timezone)); |
|
1343 | 1343 | } else { |
1344 | - return new DateTime( null, new DateTimeZone( $set_timezone ) ); |
|
1344 | + return new DateTime(null, new DateTimeZone($set_timezone)); |
|
1345 | 1345 | } |
1346 | 1346 | } |
1347 | 1347 | |
@@ -1352,7 +1352,7 @@ discard block |
||
1352 | 1352 | * Gets all the tables comprising this model. Array keys are the table aliases, and values are EE_Table objects |
1353 | 1353 | * @return EE_Table_Base[] |
1354 | 1354 | */ |
1355 | - function get_tables(){ |
|
1355 | + function get_tables() { |
|
1356 | 1356 | return $this->_tables; |
1357 | 1357 | } |
1358 | 1358 | |
@@ -1386,9 +1386,9 @@ discard block |
||
1386 | 1386 | * be aware that model objects being used could get out-of-sync with the database |
1387 | 1387 | * @return int how many rows got updated or FALSE if something went wrong with the query (wp returns FALSE or num rows affected which *could* include 0 which DOES NOT mean the query was bad) |
1388 | 1388 | */ |
1389 | - function update($fields_n_values, $query_params, $keep_model_objs_in_sync = TRUE){ |
|
1390 | - if( ! is_array( $query_params ) ){ |
|
1391 | - EE_Error::doing_it_wrong('EEM_Base::update', sprintf( __( '$query_params should be an array, you passed a variable of type %s', 'event_espresso' ), gettype( $query_params ) ), '4.6.0' ); |
|
1389 | + function update($fields_n_values, $query_params, $keep_model_objs_in_sync = TRUE) { |
|
1390 | + if ( ! is_array($query_params)) { |
|
1391 | + EE_Error::doing_it_wrong('EEM_Base::update', sprintf(__('$query_params should be an array, you passed a variable of type %s', 'event_espresso'), gettype($query_params)), '4.6.0'); |
|
1392 | 1392 | $query_params = array(); |
1393 | 1393 | } |
1394 | 1394 | /** |
@@ -1398,7 +1398,7 @@ discard block |
||
1398 | 1398 | * @param array $fields_n_values the updated fields and their new values |
1399 | 1399 | * @param array $query_params @see EEM_Base::get_all() |
1400 | 1400 | */ |
1401 | - do_action( 'AHEE__EEM_Base__update__begin',$this, $fields_n_values, $query_params ); |
|
1401 | + do_action('AHEE__EEM_Base__update__begin', $this, $fields_n_values, $query_params); |
|
1402 | 1402 | /** |
1403 | 1403 | * Filters the fields about to be updated given the query parameters. You can provide the |
1404 | 1404 | * $query_params to $this->get_all() to find exactly which records will be updated |
@@ -1406,10 +1406,10 @@ discard block |
||
1406 | 1406 | * @param EEM_Base $model the model being queried |
1407 | 1407 | * @param array $query_params see EEM_Base::get_all() |
1408 | 1408 | */ |
1409 | - $fields_n_values = apply_filters( 'FHEE__EEM_Base__update__fields_n_values', $fields_n_values, $this, $query_params ); |
|
1409 | + $fields_n_values = apply_filters('FHEE__EEM_Base__update__fields_n_values', $fields_n_values, $this, $query_params); |
|
1410 | 1410 | //need to verify that, for any entry we want to update, there are entries in each secondary table. |
1411 | 1411 | //to do that, for each table, verify that it's PK isn't null. |
1412 | - $tables= $this->get_tables(); |
|
1412 | + $tables = $this->get_tables(); |
|
1413 | 1413 | |
1414 | 1414 | //and if the other tables don't have a row for each table-to-be-updated, we'll insert one with whatever values available in the current update query |
1415 | 1415 | //NOTE: we should make this code more efficient by NOT querying twice |
@@ -1419,29 +1419,29 @@ discard block |
||
1419 | 1419 | //we want to make sure the default_where strategy is ignored |
1420 | 1420 | $this->_ignore_where_strategy = TRUE; |
1421 | 1421 | $wpdb_select_results = $this->_get_all_wpdb_results($query_params); |
1422 | - foreach( $wpdb_select_results as $wpdb_result ){ |
|
1422 | + foreach ($wpdb_select_results as $wpdb_result) { |
|
1423 | 1423 | // type cast stdClass as array |
1424 | - $wpdb_result = (array)$wpdb_result; |
|
1424 | + $wpdb_result = (array) $wpdb_result; |
|
1425 | 1425 | //get the model object's PK, as we'll want this if we need to insert a row into secondary tables |
1426 | - if( $this->has_primary_key_field() ){ |
|
1427 | - $main_table_pk_value = $wpdb_result[ $this->get_primary_key_field()->get_qualified_column() ]; |
|
1428 | - }else{ |
|
1426 | + if ($this->has_primary_key_field()) { |
|
1427 | + $main_table_pk_value = $wpdb_result[$this->get_primary_key_field()->get_qualified_column()]; |
|
1428 | + } else { |
|
1429 | 1429 | //if there's no primary key, we basically can't support having a 2nd table on the model (we could but it would be lots of work) |
1430 | 1430 | $main_table_pk_value = null; |
1431 | 1431 | } |
1432 | 1432 | //if there are more than 1 tables, we'll want to verify that each table for this model has an entry in the other tables |
1433 | 1433 | //and if the other tables don't have a row for each table-to-be-updated, we'll insert one with whatever values available in the current update query |
1434 | - if(count($tables) > 1){ |
|
1434 | + if (count($tables) > 1) { |
|
1435 | 1435 | //foreach matching row in the DB, ensure that each table's PK isn't null. If so, there must not be an entry |
1436 | 1436 | //in that table, and so we'll want to insert one |
1437 | - foreach($tables as $table_obj){ |
|
1437 | + foreach ($tables as $table_obj) { |
|
1438 | 1438 | $this_table_pk_column = $table_obj->get_fully_qualified_pk_column(); |
1439 | 1439 | //if there is no private key for this table on the results, it means there's no entry |
1440 | 1440 | //in this table, right? so insert a row in the current table, using any fields available |
1441 | - if( ! ( array_key_exists( $this_table_pk_column, $wpdb_result) && $wpdb_result[ $this_table_pk_column ] )){ |
|
1441 | + if ( ! (array_key_exists($this_table_pk_column, $wpdb_result) && $wpdb_result[$this_table_pk_column])) { |
|
1442 | 1442 | $success = $this->_insert_into_specific_table($table_obj, $fields_n_values, $main_table_pk_value); |
1443 | 1443 | //if we died here, report the error |
1444 | - if( ! $success ) { |
|
1444 | + if ( ! $success) { |
|
1445 | 1445 | return false; |
1446 | 1446 | } |
1447 | 1447 | } |
@@ -1461,44 +1461,44 @@ discard block |
||
1461 | 1461 | //if this wasn't called from a model object (to update itself) |
1462 | 1462 | //then we want to make sure we keep all the existing |
1463 | 1463 | //model objects in sync with the db |
1464 | - if( $keep_model_objs_in_sync && ! $this->_values_already_prepared_by_model_object ){ |
|
1465 | - if( $this->has_primary_key_field() ){ |
|
1466 | - $model_objs_affected_ids = $this->get_col( $query_params ); |
|
1467 | - }else{ |
|
1464 | + if ($keep_model_objs_in_sync && ! $this->_values_already_prepared_by_model_object) { |
|
1465 | + if ($this->has_primary_key_field()) { |
|
1466 | + $model_objs_affected_ids = $this->get_col($query_params); |
|
1467 | + } else { |
|
1468 | 1468 | //we need to select a bunch of columns and then combine them into the the "index primary key string"s |
1469 | - $models_affected_key_columns = $this->_get_all_wpdb_results($query_params, ARRAY_A ); |
|
1469 | + $models_affected_key_columns = $this->_get_all_wpdb_results($query_params, ARRAY_A); |
|
1470 | 1470 | $model_objs_affected_ids = array(); |
1471 | - foreach( $models_affected_key_columns as $row ){ |
|
1472 | - $combined_index_key = $this->get_index_primary_key_string( $row ); |
|
1473 | - $model_objs_affected_ids[ $combined_index_key ] = $combined_index_key; |
|
1471 | + foreach ($models_affected_key_columns as $row) { |
|
1472 | + $combined_index_key = $this->get_index_primary_key_string($row); |
|
1473 | + $model_objs_affected_ids[$combined_index_key] = $combined_index_key; |
|
1474 | 1474 | } |
1475 | 1475 | |
1476 | 1476 | } |
1477 | 1477 | |
1478 | - if( ! $model_objs_affected_ids ){ |
|
1478 | + if ( ! $model_objs_affected_ids) { |
|
1479 | 1479 | //wait wait wait- if nothing was affected let's stop here |
1480 | 1480 | return 0; |
1481 | 1481 | } |
1482 | - foreach( $model_objs_affected_ids as $id ){ |
|
1483 | - $model_obj_in_entity_map = $this->get_from_entity_map( $id ); |
|
1484 | - if( $model_obj_in_entity_map ){ |
|
1485 | - foreach( $fields_n_values as $field => $new_value ){ |
|
1486 | - $model_obj_in_entity_map->set( $field, $new_value ); |
|
1482 | + foreach ($model_objs_affected_ids as $id) { |
|
1483 | + $model_obj_in_entity_map = $this->get_from_entity_map($id); |
|
1484 | + if ($model_obj_in_entity_map) { |
|
1485 | + foreach ($fields_n_values as $field => $new_value) { |
|
1486 | + $model_obj_in_entity_map->set($field, $new_value); |
|
1487 | 1487 | } |
1488 | 1488 | } |
1489 | 1489 | } |
1490 | 1490 | //if there is a primary key on this model, we can now do a slight optimization |
1491 | - if( $this->has_primary_key_field() ){ |
|
1491 | + if ($this->has_primary_key_field()) { |
|
1492 | 1492 | //we already know what we want to update. So let's make the query simpler so it's a little more efficient |
1493 | 1493 | $query_params = array( |
1494 | - array( $this->primary_key_name() => array( 'IN', $model_objs_affected_ids ) ), |
|
1495 | - 'limit' => count( $model_objs_affected_ids ), 'default_where_conditions' => 'none' ); |
|
1494 | + array($this->primary_key_name() => array('IN', $model_objs_affected_ids)), |
|
1495 | + 'limit' => count($model_objs_affected_ids), 'default_where_conditions' => 'none' ); |
|
1496 | 1496 | } |
1497 | 1497 | } |
1498 | 1498 | |
1499 | - $model_query_info = $this->_create_model_query_info_carrier( $query_params ); |
|
1500 | - $SQL = "UPDATE ".$model_query_info->get_full_join_sql()." SET ".$this->_construct_update_sql($fields_n_values).$model_query_info->get_where_sql();//note: doesn't use _construct_2nd_half_of_select_query() because doesn't accept LIMIT, ORDER BY, etc. |
|
1501 | - $rows_affected = $this->_do_wpdb_query('query', array( $SQL ) ); |
|
1499 | + $model_query_info = $this->_create_model_query_info_carrier($query_params); |
|
1500 | + $SQL = "UPDATE ".$model_query_info->get_full_join_sql()." SET ".$this->_construct_update_sql($fields_n_values).$model_query_info->get_where_sql(); //note: doesn't use _construct_2nd_half_of_select_query() because doesn't accept LIMIT, ORDER BY, etc. |
|
1501 | + $rows_affected = $this->_do_wpdb_query('query', array($SQL)); |
|
1502 | 1502 | /** |
1503 | 1503 | * Action called after a model update call has been made. |
1504 | 1504 | * |
@@ -1507,8 +1507,8 @@ discard block |
||
1507 | 1507 | * @param array $query_params @see EEM_Base::get_all() |
1508 | 1508 | * @param int $rows_affected |
1509 | 1509 | */ |
1510 | - do_action( 'AHEE__EEM_Base__update__end',$this, $fields_n_values, $query_params, $rows_affected ); |
|
1511 | - return $rows_affected;//how many supposedly got updated |
|
1510 | + do_action('AHEE__EEM_Base__update__end', $this, $fields_n_values, $query_params, $rows_affected); |
|
1511 | + return $rows_affected; //how many supposedly got updated |
|
1512 | 1512 | } |
1513 | 1513 | |
1514 | 1514 | /** |
@@ -1520,22 +1520,22 @@ discard block |
||
1520 | 1520 | * @param string $field_to_select |
1521 | 1521 | * @return array just like $wpdb->get_col() |
1522 | 1522 | */ |
1523 | - public function get_col( $query_params = array(), $field_to_select = NULL ){ |
|
1523 | + public function get_col($query_params = array(), $field_to_select = NULL) { |
|
1524 | 1524 | |
1525 | - if( $field_to_select ){ |
|
1526 | - $field = $this->field_settings_for( $field_to_select ); |
|
1527 | - }elseif( $this->has_primary_key_field ( ) ){ |
|
1525 | + if ($field_to_select) { |
|
1526 | + $field = $this->field_settings_for($field_to_select); |
|
1527 | + }elseif ($this->has_primary_key_field( )) { |
|
1528 | 1528 | $field = $this->get_primary_key_field(); |
1529 | - }else{ |
|
1529 | + } else { |
|
1530 | 1530 | //no primary key, just grab the first column |
1531 | - $field = reset( $this->field_settings()); |
|
1531 | + $field = reset($this->field_settings()); |
|
1532 | 1532 | } |
1533 | 1533 | |
1534 | 1534 | |
1535 | 1535 | $model_query_info = $this->_create_model_query_info_carrier($query_params); |
1536 | 1536 | $select_expressions = $field->get_qualified_column(); |
1537 | - $SQL ="SELECT $select_expressions ".$this->_construct_2nd_half_of_select_query($model_query_info); |
|
1538 | - $results = $this->_do_wpdb_query('get_col', array( $SQL ) ); |
|
1537 | + $SQL = "SELECT $select_expressions ".$this->_construct_2nd_half_of_select_query($model_query_info); |
|
1538 | + $results = $this->_do_wpdb_query('get_col', array($SQL)); |
|
1539 | 1539 | return $results; |
1540 | 1540 | } |
1541 | 1541 | |
@@ -1545,12 +1545,12 @@ discard block |
||
1545 | 1545 | * @param string $field_to_select @see EEM_Base::get_col() |
1546 | 1546 | * @return string |
1547 | 1547 | */ |
1548 | - public function get_var( $query_params = array(), $field_to_select = NULL ) { |
|
1549 | - $query_params[ 'limit' ] = 1; |
|
1550 | - $col = $this->get_col( $query_params, $field_to_select ); |
|
1551 | - if( ! empty( $col ) ) { |
|
1552 | - return reset( $col ); |
|
1553 | - }else{ |
|
1548 | + public function get_var($query_params = array(), $field_to_select = NULL) { |
|
1549 | + $query_params['limit'] = 1; |
|
1550 | + $col = $this->get_col($query_params, $field_to_select); |
|
1551 | + if ( ! empty($col)) { |
|
1552 | + return reset($col); |
|
1553 | + } else { |
|
1554 | 1554 | return NULL; |
1555 | 1555 | } |
1556 | 1556 | } |
@@ -1564,19 +1564,19 @@ discard block |
||
1564 | 1564 | * @param array $fields_n_values array keys are field names on this model, and values are what those fields should be updated to in the DB |
1565 | 1565 | * @return string of SQL |
1566 | 1566 | */ |
1567 | - function _construct_update_sql($fields_n_values){ |
|
1567 | + function _construct_update_sql($fields_n_values) { |
|
1568 | 1568 | /** @type WPDB $wpdb */ |
1569 | 1569 | global $wpdb; |
1570 | 1570 | $cols_n_values = array(); |
1571 | - foreach($fields_n_values as $field_name => $value){ |
|
1571 | + foreach ($fields_n_values as $field_name => $value) { |
|
1572 | 1572 | $field_obj = $this->field_settings_for($field_name); |
1573 | 1573 | //if the value is NULL, we want to assign the value to that. |
1574 | 1574 | //wpdb->prepare doesn't really handle that properly |
1575 | - $prepared_value = $this->_prepare_value_or_use_default( $field_obj, $fields_n_values ); |
|
1576 | - $value_sql = $prepared_value===NULL ? 'NULL' : $wpdb->prepare( $field_obj->get_wpdb_data_type(), $prepared_value ); |
|
1575 | + $prepared_value = $this->_prepare_value_or_use_default($field_obj, $fields_n_values); |
|
1576 | + $value_sql = $prepared_value === NULL ? 'NULL' : $wpdb->prepare($field_obj->get_wpdb_data_type(), $prepared_value); |
|
1577 | 1577 | $cols_n_values[] = $field_obj->get_qualified_column()."=".$value_sql; |
1578 | 1578 | } |
1579 | - return implode(",",$cols_n_values); |
|
1579 | + return implode(",", $cols_n_values); |
|
1580 | 1580 | |
1581 | 1581 | } |
1582 | 1582 | |
@@ -1589,10 +1589,10 @@ discard block |
||
1589 | 1589 | * @param boolean $allow_blocking whether to block deletion if related things exist, or not |
1590 | 1590 | * @return boolean whether the row got deleted or not |
1591 | 1591 | */ |
1592 | - public function delete_permanently_by_ID( $id, $allow_blocking = true ) { |
|
1592 | + public function delete_permanently_by_ID($id, $allow_blocking = true) { |
|
1593 | 1593 | return $this->delete_permanently( |
1594 | 1594 | array( |
1595 | - array( $this->get_primary_key_field()->get_name() => $id ), |
|
1595 | + array($this->get_primary_key_field()->get_name() => $id), |
|
1596 | 1596 | 'limit' => 1 |
1597 | 1597 | ), |
1598 | 1598 | $allow_blocking |
@@ -1610,10 +1610,10 @@ discard block |
||
1610 | 1610 | * which may depend on it. Its generally advisable to always leave this as TRUE, otherwise you could easily corrupt your DB |
1611 | 1611 | * @return boolean whether the row got deleted or not |
1612 | 1612 | */ |
1613 | - public function delete_by_ID( $id, $allow_blocking = true ){ |
|
1613 | + public function delete_by_ID($id, $allow_blocking = true) { |
|
1614 | 1614 | return $this->delete( |
1615 | 1615 | array( |
1616 | - array( $this->get_primary_key_field()->get_name() => $id ), |
|
1616 | + array($this->get_primary_key_field()->get_name() => $id), |
|
1617 | 1617 | 'limit' => 1 |
1618 | 1618 | ), |
1619 | 1619 | $allow_blocking |
@@ -1627,7 +1627,7 @@ discard block |
||
1627 | 1627 | * @param boolean $allow_blocking |
1628 | 1628 | * @return @see EEM_Base::delete_permanently |
1629 | 1629 | */ |
1630 | - function delete($query_params,$allow_blocking = true){ |
|
1630 | + function delete($query_params, $allow_blocking = true) { |
|
1631 | 1631 | return $this->delete_permanently($query_params, $allow_blocking); |
1632 | 1632 | } |
1633 | 1633 | |
@@ -1643,7 +1643,7 @@ discard block |
||
1643 | 1643 | * which may depend on it. Its generally advisable to always leave this as TRUE, otherwise you could easily corrupt your DB |
1644 | 1644 | * @return int how many rows got deleted |
1645 | 1645 | */ |
1646 | - function delete_permanently($query_params,$allow_blocking = true){ |
|
1646 | + function delete_permanently($query_params, $allow_blocking = true) { |
|
1647 | 1647 | /** |
1648 | 1648 | * Action called just before performing a real deletion query. You can use the |
1649 | 1649 | * model and its $query_params to find exactly which items will be deleted |
@@ -1652,34 +1652,34 @@ discard block |
||
1652 | 1652 | * @param boolean $allow_blocking whether or not to allow related model objects |
1653 | 1653 | * to block (prevent) this deletion |
1654 | 1654 | */ |
1655 | - do_action( 'AHEE__EEM_Base__delete__begin', $this, $query_params, $allow_blocking ); |
|
1655 | + do_action('AHEE__EEM_Base__delete__begin', $this, $query_params, $allow_blocking); |
|
1656 | 1656 | //some MySQL databases may be running safe mode, which may restrict |
1657 | 1657 | //deletion if there is no KEY column used in the WHERE statement of a deletion. |
1658 | 1658 | //to get around this, we first do a SELECT, get all the IDs, and then run another query |
1659 | 1659 | //to delete them |
1660 | 1660 | $items_for_deletion = $this->_get_all_wpdb_results($query_params); |
1661 | - $deletion_where = $this->_setup_ids_for_delete( $items_for_deletion, $allow_blocking); |
|
1662 | - if($deletion_where){ |
|
1661 | + $deletion_where = $this->_setup_ids_for_delete($items_for_deletion, $allow_blocking); |
|
1662 | + if ($deletion_where) { |
|
1663 | 1663 | //echo "objects for deletion:";var_dump($objects_for_deletion); |
1664 | 1664 | $model_query_info = $this->_create_model_query_info_carrier($query_params); |
1665 | 1665 | $table_aliases = array(); |
1666 | - foreach(array_keys($this->_tables) as $table_alias){ |
|
1666 | + foreach (array_keys($this->_tables) as $table_alias) { |
|
1667 | 1667 | $table_aliases[] = $table_alias; |
1668 | 1668 | } |
1669 | - $SQL = "DELETE ".implode(", ",$table_aliases)." FROM ".$model_query_info->get_full_join_sql()." WHERE ".$deletion_where; |
|
1669 | + $SQL = "DELETE ".implode(", ", $table_aliases)." FROM ".$model_query_info->get_full_join_sql()." WHERE ".$deletion_where; |
|
1670 | 1670 | |
1671 | 1671 | // /echo "delete sql:$SQL"; |
1672 | - $rows_deleted = $this->_do_wpdb_query( 'query', array( $SQL ) ); |
|
1673 | - }else{ |
|
1672 | + $rows_deleted = $this->_do_wpdb_query('query', array($SQL)); |
|
1673 | + } else { |
|
1674 | 1674 | $rows_deleted = 0; |
1675 | 1675 | } |
1676 | 1676 | |
1677 | 1677 | //and lastly make sure those items are removed from the entity map; if they could be put into it at all |
1678 | - if( $this->has_primary_key_field() ){ |
|
1679 | - foreach($items_for_deletion as $item_for_deletion_row ){ |
|
1680 | - $pk_value = $item_for_deletion_row[ $this->get_primary_key_field()->get_qualified_column() ]; |
|
1681 | - if( isset( $this->_entity_map[ $pk_value ] ) ){ |
|
1682 | - unset( $this->_entity_map[ $pk_value ] ); |
|
1678 | + if ($this->has_primary_key_field()) { |
|
1679 | + foreach ($items_for_deletion as $item_for_deletion_row) { |
|
1680 | + $pk_value = $item_for_deletion_row[$this->get_primary_key_field()->get_qualified_column()]; |
|
1681 | + if (isset($this->_entity_map[$pk_value])) { |
|
1682 | + unset($this->_entity_map[$pk_value]); |
|
1683 | 1683 | } |
1684 | 1684 | } |
1685 | 1685 | } |
@@ -1691,8 +1691,8 @@ discard block |
||
1691 | 1691 | * @param array $query_params @see EEM_Base::get_all() |
1692 | 1692 | * @param int $rows_deleted |
1693 | 1693 | */ |
1694 | - do_action( 'AHEE__EEM_Base__delete__end', $this, $query_params, $rows_deleted ); |
|
1695 | - return $rows_deleted;//how many supposedly got deleted |
|
1694 | + do_action('AHEE__EEM_Base__delete__end', $this, $query_params, $rows_deleted); |
|
1695 | + return $rows_deleted; //how many supposedly got deleted |
|
1696 | 1696 | } |
1697 | 1697 | |
1698 | 1698 | |
@@ -1708,28 +1708,28 @@ discard block |
||
1708 | 1708 | * blocking its deletion before removing the relation between A and B |
1709 | 1709 | * @return boolean |
1710 | 1710 | */ |
1711 | - public function delete_is_blocked_by_related_models($this_model_obj_or_id, $ignore_this_model_obj = null){ |
|
1711 | + public function delete_is_blocked_by_related_models($this_model_obj_or_id, $ignore_this_model_obj = null) { |
|
1712 | 1712 | //first, if $ignore_this_model_obj was supplied, get its model |
1713 | - if($ignore_this_model_obj && $ignore_this_model_obj instanceof EE_Base_Class){ |
|
1713 | + if ($ignore_this_model_obj && $ignore_this_model_obj instanceof EE_Base_Class) { |
|
1714 | 1714 | $ignored_model = $ignore_this_model_obj->get_model(); |
1715 | - }else{ |
|
1715 | + } else { |
|
1716 | 1716 | $ignored_model = null; |
1717 | 1717 | } |
1718 | 1718 | //now check all the relations of $this_model_obj_or_id and see if there |
1719 | 1719 | //are any related model objects blocking it? |
1720 | 1720 | $is_blocked = false; |
1721 | - foreach($this->_model_relations as $relation_name => $relation_obj){ |
|
1722 | - if( $relation_obj->block_delete_if_related_models_exist()){ |
|
1721 | + foreach ($this->_model_relations as $relation_name => $relation_obj) { |
|
1722 | + if ($relation_obj->block_delete_if_related_models_exist()) { |
|
1723 | 1723 | //if $ignore_this_model_obj was supplied, then for the query |
1724 | 1724 | //on that model needs to be told to ignore $ignore_this_model_obj |
1725 | - if($ignored_model && $relation_name == $ignored_model->get_this_model_name()){ |
|
1726 | - $related_model_objects = $relation_obj->get_all_related($this_model_obj_or_id,array( |
|
1727 | - array($ignored_model->get_primary_key_field()->get_name() => array('!=',$ignore_this_model_obj->ID())))); |
|
1728 | - }else{ |
|
1725 | + if ($ignored_model && $relation_name == $ignored_model->get_this_model_name()) { |
|
1726 | + $related_model_objects = $relation_obj->get_all_related($this_model_obj_or_id, array( |
|
1727 | + array($ignored_model->get_primary_key_field()->get_name() => array('!=', $ignore_this_model_obj->ID())))); |
|
1728 | + } else { |
|
1729 | 1729 | $related_model_objects = $relation_obj->get_all_related($this_model_obj_or_id); |
1730 | 1730 | } |
1731 | 1731 | |
1732 | - if($related_model_objects){ |
|
1732 | + if ($related_model_objects) { |
|
1733 | 1733 | EE_Error::add_error($relation_obj->get_deletion_error_message(), __FILE__, __FUNCTION__, __LINE__); |
1734 | 1734 | $is_blocked = true; |
1735 | 1735 | } |
@@ -1749,65 +1749,65 @@ discard block |
||
1749 | 1749 | * @throws EE_Error |
1750 | 1750 | * @return string everything that comes after the WHERE statement. |
1751 | 1751 | */ |
1752 | - protected function _setup_ids_for_delete( $objects_for_deletion, $allow_blocking = true) { |
|
1753 | - if($this->has_primary_key_field()){ |
|
1752 | + protected function _setup_ids_for_delete($objects_for_deletion, $allow_blocking = true) { |
|
1753 | + if ($this->has_primary_key_field()) { |
|
1754 | 1754 | $primary_table = $this->_get_main_table(); |
1755 | 1755 | $other_tables = $this->_get_other_tables(); |
1756 | 1756 | $deletes = $query = array(); |
1757 | - foreach ( $objects_for_deletion as $delete_object ) { |
|
1757 | + foreach ($objects_for_deletion as $delete_object) { |
|
1758 | 1758 | //before we mark this object for deletion, |
1759 | 1759 | //make sure there's no related objects blocking its deletion (if we're checking) |
1760 | - if( $allow_blocking && $this->delete_is_blocked_by_related_models($delete_object[$primary_table->get_fully_qualified_pk_column()]) ){ |
|
1760 | + if ($allow_blocking && $this->delete_is_blocked_by_related_models($delete_object[$primary_table->get_fully_qualified_pk_column()])) { |
|
1761 | 1761 | continue; |
1762 | 1762 | } |
1763 | 1763 | |
1764 | 1764 | //primary table deletes |
1765 | - if ( isset( $delete_object[$primary_table->get_fully_qualified_pk_column()] ) ) |
|
1765 | + if (isset($delete_object[$primary_table->get_fully_qualified_pk_column()])) |
|
1766 | 1766 | $deletes[$primary_table->get_fully_qualified_pk_column()][] = $delete_object[$primary_table->get_fully_qualified_pk_column()]; |
1767 | 1767 | |
1768 | 1768 | //other tables |
1769 | - if ( !empty( $other_tables ) ) { |
|
1770 | - foreach ( $other_tables as $ot ) { |
|
1769 | + if ( ! empty($other_tables)) { |
|
1770 | + foreach ($other_tables as $ot) { |
|
1771 | 1771 | |
1772 | 1772 | //first check if we've got the foreign key column here. |
1773 | - if ( isset( $delete_object[$ot->get_fully_qualified_fk_column()] ) ) |
|
1773 | + if (isset($delete_object[$ot->get_fully_qualified_fk_column()])) |
|
1774 | 1774 | $deletes[$ot->get_fully_qualified_pk_column()][] = $delete_object[$ot->get_fully_qualified_fk_column()]; |
1775 | 1775 | |
1776 | 1776 | //wait! it's entirely possible that we'll have a the primary key for this table in here if it's a foreign key for one of the other secondary tables |
1777 | - if ( isset( $delete_object[$ot->get_fully_qualified_pk_column()] ) ) |
|
1777 | + if (isset($delete_object[$ot->get_fully_qualified_pk_column()])) |
|
1778 | 1778 | $deletes[$ot->get_fully_qualified_pk_column()][] = $delete_object[$ot->get_fully_qualified_pk_column()]; |
1779 | 1779 | |
1780 | 1780 | //finally, it is possible that the fk for this table is found in the fully qualified pk column for the fk table, so let's see if that's there! |
1781 | - if ( isset( $delete_object[$ot->get_fully_qualified_pk_on_fk_table()]) ) |
|
1781 | + if (isset($delete_object[$ot->get_fully_qualified_pk_on_fk_table()])) |
|
1782 | 1782 | $deletes[$ot->get_fully_qualified_pk_column()][] = $delete_object[$ot->get_fully_qualified_pk_column()]; |
1783 | 1783 | } |
1784 | 1784 | } |
1785 | 1785 | } |
1786 | 1786 | |
1787 | 1787 | //we should have deletes now, so let's just go through and setup the where statement |
1788 | - foreach ( $deletes as $column => $values ) { |
|
1788 | + foreach ($deletes as $column => $values) { |
|
1789 | 1789 | //make sure we have unique $values; |
1790 | 1790 | $values = array_unique($values); |
1791 | - $query[] = $column . ' IN(' . implode(",",$values) . ')'; |
|
1791 | + $query[] = $column.' IN('.implode(",", $values).')'; |
|
1792 | 1792 | } |
1793 | 1793 | |
1794 | - return !empty($query) ? implode(' AND ', $query ) : ''; |
|
1795 | - }elseif(count($this->get_combined_primary_key_fields()) > 1){ |
|
1794 | + return ! empty($query) ? implode(' AND ', $query) : ''; |
|
1795 | + }elseif (count($this->get_combined_primary_key_fields()) > 1) { |
|
1796 | 1796 | $ways_to_identify_a_row = array(); |
1797 | 1797 | $fields = $this->get_combined_primary_key_fields(); |
1798 | 1798 | //note: because there' sno primary key, that means nothing else can be pointing to this model, right? |
1799 | - foreach($objects_for_deletion as $delete_object){ |
|
1799 | + foreach ($objects_for_deletion as $delete_object) { |
|
1800 | 1800 | $values_for_each_cpk_for_a_row = array(); |
1801 | - foreach($fields as $cpk_field){ |
|
1801 | + foreach ($fields as $cpk_field) { |
|
1802 | 1802 | $values_for_each_cpk_for_a_row[] = $cpk_field->get_qualified_column()."=".$delete_object[$cpk_field->get_qualified_column()]; |
1803 | 1803 | } |
1804 | - $ways_to_identify_a_row[] = "(".implode(" AND ",$values_for_each_cpk_for_a_row).")"; |
|
1804 | + $ways_to_identify_a_row[] = "(".implode(" AND ", $values_for_each_cpk_for_a_row).")"; |
|
1805 | 1805 | } |
1806 | - return implode(" OR ",$ways_to_identify_a_row); |
|
1807 | - }else{ |
|
1806 | + return implode(" OR ", $ways_to_identify_a_row); |
|
1807 | + } else { |
|
1808 | 1808 | //so there's no primary key and no combined key... |
1809 | 1809 | //sorry, can't help you |
1810 | - throw new EE_Error(sprintf(__("Cannot delete objects of type %s because there is no primary key NOR combined key", "event_espresso"),get_class($this))); |
|
1810 | + throw new EE_Error(sprintf(__("Cannot delete objects of type %s because there is no primary key NOR combined key", "event_espresso"), get_class($this))); |
|
1811 | 1811 | } |
1812 | 1812 | } |
1813 | 1813 | |
@@ -1821,21 +1821,21 @@ discard block |
||
1821 | 1821 | * @param bool $distinct if we want to only count the distinct values for the column then you can trigger that by the setting $distinct to TRUE; |
1822 | 1822 | * @return int |
1823 | 1823 | */ |
1824 | - function count($query_params =array(),$field_to_count = NULL, $distinct = FALSE){ |
|
1824 | + function count($query_params = array(), $field_to_count = NULL, $distinct = FALSE) { |
|
1825 | 1825 | $model_query_info = $this->_create_model_query_info_carrier($query_params); |
1826 | - if($field_to_count){ |
|
1826 | + if ($field_to_count) { |
|
1827 | 1827 | $field_obj = $this->field_settings_for($field_to_count); |
1828 | 1828 | $column_to_count = $field_obj->get_qualified_column(); |
1829 | - }elseif($this->has_primary_key_field ()){ |
|
1829 | + }elseif ($this->has_primary_key_field()) { |
|
1830 | 1830 | $pk_field_obj = $this->get_primary_key_field(); |
1831 | 1831 | $column_to_count = $pk_field_obj->get_qualified_column(); |
1832 | - }else{//there's no primary key |
|
1832 | + } else {//there's no primary key |
|
1833 | 1833 | $column_to_count = '*'; |
1834 | 1834 | } |
1835 | 1835 | |
1836 | - $column_to_count = $distinct ? "DISTINCT (" . $column_to_count . " )" : $column_to_count; |
|
1837 | - $SQL ="SELECT COUNT(".$column_to_count.")" . $this->_construct_2nd_half_of_select_query($model_query_info); |
|
1838 | - return (int)$this->_do_wpdb_query( 'get_var', array( $SQL) ); |
|
1836 | + $column_to_count = $distinct ? "DISTINCT (".$column_to_count." )" : $column_to_count; |
|
1837 | + $SQL = "SELECT COUNT(".$column_to_count.")".$this->_construct_2nd_half_of_select_query($model_query_info); |
|
1838 | + return (int) $this->_do_wpdb_query('get_var', array($SQL)); |
|
1839 | 1839 | } |
1840 | 1840 | |
1841 | 1841 | /** |
@@ -1845,23 +1845,23 @@ discard block |
||
1845 | 1845 | * @param string $field_to_sum name of field (array key in $_fields array) |
1846 | 1846 | * @return float |
1847 | 1847 | */ |
1848 | - function sum($query_params, $field_to_sum = NULL){ |
|
1848 | + function sum($query_params, $field_to_sum = NULL) { |
|
1849 | 1849 | $model_query_info = $this->_create_model_query_info_carrier($query_params); |
1850 | 1850 | |
1851 | - if($field_to_sum){ |
|
1851 | + if ($field_to_sum) { |
|
1852 | 1852 | $field_obj = $this->field_settings_for($field_to_sum); |
1853 | 1853 | |
1854 | - }else{ |
|
1854 | + } else { |
|
1855 | 1855 | $field_obj = $this->get_primary_key_field(); |
1856 | 1856 | } |
1857 | 1857 | $column_to_count = $field_obj->get_qualified_column(); |
1858 | 1858 | |
1859 | - $SQL ="SELECT SUM(".$column_to_count.")" . $this->_construct_2nd_half_of_select_query($model_query_info); |
|
1860 | - $return_value = $this->_do_wpdb_query('get_var',array( $SQL ) ); |
|
1861 | - if($field_obj->get_wpdb_data_type() == '%d' || $field_obj->get_wpdb_data_type() == '%s' ){ |
|
1862 | - return (float)$return_value; |
|
1863 | - }else{//must be %f |
|
1864 | - return (float)$return_value; |
|
1859 | + $SQL = "SELECT SUM(".$column_to_count.")".$this->_construct_2nd_half_of_select_query($model_query_info); |
|
1860 | + $return_value = $this->_do_wpdb_query('get_var', array($SQL)); |
|
1861 | + if ($field_obj->get_wpdb_data_type() == '%d' || $field_obj->get_wpdb_data_type() == '%s') { |
|
1862 | + return (float) $return_value; |
|
1863 | + } else {//must be %f |
|
1864 | + return (float) $return_value; |
|
1865 | 1865 | } |
1866 | 1866 | } |
1867 | 1867 | |
@@ -1876,33 +1876,33 @@ discard block |
||
1876 | 1876 | * @global wpdb $wpdb |
1877 | 1877 | * @return mixed |
1878 | 1878 | */ |
1879 | - protected function _do_wpdb_query( $wpdb_method, $arguments_to_provide ){ |
|
1879 | + protected function _do_wpdb_query($wpdb_method, $arguments_to_provide) { |
|
1880 | 1880 | //if we're in maintenance mode level 2, DON'T run any queries |
1881 | 1881 | //because level 2 indicates the database needs updating and |
1882 | 1882 | //is probably out of sync with the code |
1883 | - if( ! EE_Maintenance_Mode::instance()->models_can_query()){ |
|
1883 | + if ( ! EE_Maintenance_Mode::instance()->models_can_query()) { |
|
1884 | 1884 | throw new EE_Error(sprintf(__("Event Espresso Level 2 Maintenance mode is active. That means EE can not run ANY database queries until the necessary migration scripts have run which will take EE out of maintenance mode level 2. Please inform support of this error.", "event_espresso"))); |
1885 | 1885 | } |
1886 | 1886 | /** @type WPDB $wpdb */ |
1887 | 1887 | global $wpdb; |
1888 | - if( ! method_exists( $wpdb, $wpdb_method ) ){ |
|
1889 | - throw new EE_Error( sprintf( __( 'There is no method named "%s" on Wordpress\' $wpdb object','event_espresso' ), $wpdb_method ) ); |
|
1888 | + if ( ! method_exists($wpdb, $wpdb_method)) { |
|
1889 | + throw new EE_Error(sprintf(__('There is no method named "%s" on Wordpress\' $wpdb object', 'event_espresso'), $wpdb_method)); |
|
1890 | 1890 | } |
1891 | - if( WP_DEBUG ){ |
|
1891 | + if (WP_DEBUG) { |
|
1892 | 1892 | $old_show_errors_value = $wpdb->show_errors; |
1893 | - $wpdb->show_errors( FALSE ); |
|
1894 | - } |
|
1895 | - $result = $this->_process_wpdb_query( $wpdb_method, $arguments_to_provide ); |
|
1896 | - $this->show_db_query_if_previously_requested( $wpdb->last_query ); |
|
1897 | - if( WP_DEBUG ){ |
|
1898 | - $wpdb->show_errors( $old_show_errors_value ); |
|
1899 | - if( ! empty( $wpdb->last_error ) ){ |
|
1900 | - throw new EE_Error( sprintf( __( 'WPDB Error: "%s"', 'event_espresso' ), $wpdb->last_error ) ); |
|
1901 | - }elseif( $result === false ){ |
|
1902 | - throw new EE_Error( sprintf( __( 'WPDB Error occurred, but no error message was logged by wpdb! The wpdb method called was "%1$s" and the arguments were "%2$s"', 'event_espresso' ), $wpdb_method, var_export( $arguments_to_provide, true ) ) ); |
|
1893 | + $wpdb->show_errors(FALSE); |
|
1894 | + } |
|
1895 | + $result = $this->_process_wpdb_query($wpdb_method, $arguments_to_provide); |
|
1896 | + $this->show_db_query_if_previously_requested($wpdb->last_query); |
|
1897 | + if (WP_DEBUG) { |
|
1898 | + $wpdb->show_errors($old_show_errors_value); |
|
1899 | + if ( ! empty($wpdb->last_error)) { |
|
1900 | + throw new EE_Error(sprintf(__('WPDB Error: "%s"', 'event_espresso'), $wpdb->last_error)); |
|
1901 | + }elseif ($result === false) { |
|
1902 | + throw new EE_Error(sprintf(__('WPDB Error occurred, but no error message was logged by wpdb! The wpdb method called was "%1$s" and the arguments were "%2$s"', 'event_espresso'), $wpdb_method, var_export($arguments_to_provide, true))); |
|
1903 | 1903 | } |
1904 | - }elseif( $result === false ) { |
|
1905 | - EE_Error::add_error( sprintf( __( 'A database error has occurred. Turn on WP_DEBUG for more information.', 'event_espresso' )), __FILE__, __FUNCTION__, __LINE__); |
|
1904 | + }elseif ($result === false) { |
|
1905 | + EE_Error::add_error(sprintf(__('A database error has occurred. Turn on WP_DEBUG for more information.', 'event_espresso')), __FILE__, __FUNCTION__, __LINE__); |
|
1906 | 1906 | } |
1907 | 1907 | return $result; |
1908 | 1908 | } |
@@ -1918,23 +1918,23 @@ discard block |
||
1918 | 1918 | * @param array $arguments_to_provide |
1919 | 1919 | * @return mixed |
1920 | 1920 | */ |
1921 | - private function _process_wpdb_query( $wpdb_method, $arguments_to_provide ) { |
|
1921 | + private function _process_wpdb_query($wpdb_method, $arguments_to_provide) { |
|
1922 | 1922 | /** @type WPDB $wpdb */ |
1923 | 1923 | global $wpdb; |
1924 | 1924 | $wpdb->last_error = null; |
1925 | - $result = call_user_func_array( array( $wpdb, $wpdb_method ), $arguments_to_provide ); |
|
1925 | + $result = call_user_func_array(array($wpdb, $wpdb_method), $arguments_to_provide); |
|
1926 | 1926 | // was there an error running the query? |
1927 | - if ( ( $result === false || ! empty( $wpdb->last_error ) ) ) { |
|
1928 | - switch ( EEM_Base::$_db_verification_level ) { |
|
1927 | + if (($result === false || ! empty($wpdb->last_error))) { |
|
1928 | + switch (EEM_Base::$_db_verification_level) { |
|
1929 | 1929 | |
1930 | 1930 | case EEM_Base::db_verified_none : |
1931 | 1931 | // let's double-check core's DB |
1932 | - $error_message = $this->_verify_core_db( $wpdb_method, $arguments_to_provide ); |
|
1932 | + $error_message = $this->_verify_core_db($wpdb_method, $arguments_to_provide); |
|
1933 | 1933 | break; |
1934 | 1934 | |
1935 | 1935 | case EEM_Base::db_verified_core : |
1936 | 1936 | // STILL NO LOVE?? verify all the addons too. Maybe they need to be fixed |
1937 | - $error_message = $this->_verify_addons_db( $wpdb_method, $arguments_to_provide ); |
|
1937 | + $error_message = $this->_verify_addons_db($wpdb_method, $arguments_to_provide); |
|
1938 | 1938 | break; |
1939 | 1939 | |
1940 | 1940 | case EEM_Base::db_verified_addons : |
@@ -1942,11 +1942,11 @@ discard block |
||
1942 | 1942 | return $result; |
1943 | 1943 | break; |
1944 | 1944 | } |
1945 | - if ( ! empty( $error_message ) ) { |
|
1946 | - EE_Log::instance()->log( __FILE__, __FUNCTION__, $error_message, 'error' ); |
|
1947 | - trigger_error( $error_message ); |
|
1945 | + if ( ! empty($error_message)) { |
|
1946 | + EE_Log::instance()->log(__FILE__, __FUNCTION__, $error_message, 'error'); |
|
1947 | + trigger_error($error_message); |
|
1948 | 1948 | } |
1949 | - return $this->_process_wpdb_query( $wpdb_method, $arguments_to_provide ); |
|
1949 | + return $this->_process_wpdb_query($wpdb_method, $arguments_to_provide); |
|
1950 | 1950 | |
1951 | 1951 | } |
1952 | 1952 | |
@@ -1962,18 +1962,18 @@ discard block |
||
1962 | 1962 | * @param array $arguments_to_provide |
1963 | 1963 | * @return string |
1964 | 1964 | */ |
1965 | - private function _verify_core_db( $wpdb_method, $arguments_to_provide ){ |
|
1965 | + private function _verify_core_db($wpdb_method, $arguments_to_provide) { |
|
1966 | 1966 | /** @type WPDB $wpdb */ |
1967 | 1967 | global $wpdb; |
1968 | 1968 | //ok remember that we've already attempted fixing the core db, in case the problem persists |
1969 | 1969 | EEM_Base::$_db_verification_level = EEM_Base::db_verified_core; |
1970 | 1970 | $error_message = sprintf( |
1971 | - __( 'WPDB Error "%1$s" while running wpdb method "%2$s" with arguments %3$s. Automatically attempting to fix EE Core DB', 'event_espresso' ), |
|
1971 | + __('WPDB Error "%1$s" while running wpdb method "%2$s" with arguments %3$s. Automatically attempting to fix EE Core DB', 'event_espresso'), |
|
1972 | 1972 | $wpdb->last_error, |
1973 | 1973 | $wpdb_method, |
1974 | - json_encode( $arguments_to_provide ) |
|
1974 | + json_encode($arguments_to_provide) |
|
1975 | 1975 | ); |
1976 | - EE_System::instance()->initialize_db_if_no_migrations_required( false, true ); |
|
1976 | + EE_System::instance()->initialize_db_if_no_migrations_required(false, true); |
|
1977 | 1977 | return $error_message; |
1978 | 1978 | } |
1979 | 1979 | |
@@ -1986,16 +1986,16 @@ discard block |
||
1986 | 1986 | * @param $arguments_to_provide |
1987 | 1987 | * @return string |
1988 | 1988 | */ |
1989 | - private function _verify_addons_db( $wpdb_method, $arguments_to_provide ) { |
|
1989 | + private function _verify_addons_db($wpdb_method, $arguments_to_provide) { |
|
1990 | 1990 | /** @type WPDB $wpdb */ |
1991 | 1991 | global $wpdb; |
1992 | 1992 | //ok remember that we've already attempted fixing the addons dbs, in case the problem persists |
1993 | 1993 | EEM_Base::$_db_verification_level = EEM_Base::db_verified_addons; |
1994 | 1994 | $error_message = sprintf( |
1995 | - __( 'WPDB AGAIN: Error "%1$s" while running the same method and arguments as before. Automatically attempting to fix EE Addons DB', 'event_espresso' ), |
|
1995 | + __('WPDB AGAIN: Error "%1$s" while running the same method and arguments as before. Automatically attempting to fix EE Addons DB', 'event_espresso'), |
|
1996 | 1996 | $wpdb->last_error, |
1997 | 1997 | $wpdb_method, |
1998 | - json_encode( $arguments_to_provide ) |
|
1998 | + json_encode($arguments_to_provide) |
|
1999 | 1999 | ); |
2000 | 2000 | EE_System::instance()->initialize_addons(); |
2001 | 2001 | return $error_message; |
@@ -2010,7 +2010,7 @@ discard block |
||
2010 | 2010 | * @param EE_Model_Query_Info_Carrier $model_query_info |
2011 | 2011 | * @return string |
2012 | 2012 | */ |
2013 | - private function _construct_2nd_half_of_select_query(EE_Model_Query_Info_Carrier $model_query_info){ |
|
2013 | + private function _construct_2nd_half_of_select_query(EE_Model_Query_Info_Carrier $model_query_info) { |
|
2014 | 2014 | return " FROM ".$model_query_info->get_full_join_sql(). |
2015 | 2015 | $model_query_info->get_where_sql(). |
2016 | 2016 | $model_query_info->get_group_by_sql(). |
@@ -2023,7 +2023,7 @@ discard block |
||
2023 | 2023 | * Set to easily debug the next X queries ran from this model. |
2024 | 2024 | * @param int $count |
2025 | 2025 | */ |
2026 | - function show_next_x_db_queries($count = 1){ |
|
2026 | + function show_next_x_db_queries($count = 1) { |
|
2027 | 2027 | $this->_show_next_x_db_queries = $count; |
2028 | 2028 | } |
2029 | 2029 | |
@@ -2032,8 +2032,8 @@ discard block |
||
2032 | 2032 | /** |
2033 | 2033 | * @param $sql_query |
2034 | 2034 | */ |
2035 | - function show_db_query_if_previously_requested($sql_query){ |
|
2036 | - if($this->_show_next_x_db_queries > 0){ |
|
2035 | + function show_db_query_if_previously_requested($sql_query) { |
|
2036 | + if ($this->_show_next_x_db_queries > 0) { |
|
2037 | 2037 | echo $sql_query; |
2038 | 2038 | $this->_show_next_x_db_queries--; |
2039 | 2039 | } |
@@ -2057,9 +2057,9 @@ discard block |
||
2057 | 2057 | * @param array $extra_join_model_fields_n_values This allows you to enter further query params for the relation to for relation to methods that allow you to further specify extra columns to join by (such as HABTM). Keep in mind that the only acceptable query_params is strict "col" => "value" pairs because these will be inserted in any new rows created as well. |
2058 | 2058 | * @return EE_Base_Class which was added as a relation. Object referred to by $other_model_id_or_obj |
2059 | 2059 | */ |
2060 | - public function add_relationship_to($id_or_obj,$other_model_id_or_obj, $relationName, $extra_join_model_fields_n_values = array()){ |
|
2060 | + public function add_relationship_to($id_or_obj, $other_model_id_or_obj, $relationName, $extra_join_model_fields_n_values = array()) { |
|
2061 | 2061 | $relation_obj = $this->related_settings_for($relationName); |
2062 | - return $relation_obj->add_relation_to( $id_or_obj, $other_model_id_or_obj, $extra_join_model_fields_n_values); |
|
2062 | + return $relation_obj->add_relation_to($id_or_obj, $other_model_id_or_obj, $extra_join_model_fields_n_values); |
|
2063 | 2063 | } |
2064 | 2064 | |
2065 | 2065 | /** |
@@ -2078,9 +2078,9 @@ discard block |
||
2078 | 2078 | * @return boolean of success |
2079 | 2079 | * @param array $where_query This allows you to enter further query params for the relation to for relation to methods that allow you to further specify extra columns to join by (such as HABTM). Keep in mind that the only acceptable query_params is strict "col" => "value" pairs because these will be inserted in any new rows created as well. |
2080 | 2080 | */ |
2081 | - public function remove_relationship_to($id_or_obj, $other_model_id_or_obj, $relationName, $where_query= array() ){ |
|
2081 | + public function remove_relationship_to($id_or_obj, $other_model_id_or_obj, $relationName, $where_query = array()) { |
|
2082 | 2082 | $relation_obj = $this->related_settings_for($relationName); |
2083 | - return $relation_obj->remove_relation_to($id_or_obj, $other_model_id_or_obj, $where_query ); |
|
2083 | + return $relation_obj->remove_relation_to($id_or_obj, $other_model_id_or_obj, $where_query); |
|
2084 | 2084 | } |
2085 | 2085 | |
2086 | 2086 | |
@@ -2093,9 +2093,9 @@ discard block |
||
2093 | 2093 | * @param EE_Base_Class[] objects to which relations were removed |
2094 | 2094 | * @return \EE_Base_Class[] |
2095 | 2095 | */ |
2096 | - public function remove_relations($id_or_obj,$relationName,$where_query_params = array()){ |
|
2096 | + public function remove_relations($id_or_obj, $relationName, $where_query_params = array()) { |
|
2097 | 2097 | $relation_obj = $this->related_settings_for($relationName); |
2098 | - return $relation_obj->remove_relations($id_or_obj, $where_query_params ); |
|
2098 | + return $relation_obj->remove_relations($id_or_obj, $where_query_params); |
|
2099 | 2099 | } |
2100 | 2100 | |
2101 | 2101 | |
@@ -2108,10 +2108,10 @@ discard block |
||
2108 | 2108 | * @param array $query_params like EEM_Base::get_all |
2109 | 2109 | * @return EE_Base_Class[] |
2110 | 2110 | */ |
2111 | - function get_all_related($id_or_obj, $model_name, $query_params = null){ |
|
2111 | + function get_all_related($id_or_obj, $model_name, $query_params = null) { |
|
2112 | 2112 | $model_obj = $this->ensure_is_obj($id_or_obj); |
2113 | 2113 | $relation_settings = $this->related_settings_for($model_name); |
2114 | - return $relation_settings->get_all_related($model_obj,$query_params); |
|
2114 | + return $relation_settings->get_all_related($model_obj, $query_params); |
|
2115 | 2115 | } |
2116 | 2116 | |
2117 | 2117 | /** |
@@ -2124,10 +2124,10 @@ discard block |
||
2124 | 2124 | * @param array $query_params |
2125 | 2125 | * @return int how many deleted |
2126 | 2126 | */ |
2127 | - public function delete_related($id_or_obj,$model_name, $query_params = array()){ |
|
2127 | + public function delete_related($id_or_obj, $model_name, $query_params = array()) { |
|
2128 | 2128 | $model_obj = $this->ensure_is_obj($id_or_obj); |
2129 | 2129 | $relation_settings = $this->related_settings_for($model_name); |
2130 | - return $relation_settings->delete_all_related($model_obj,$query_params); |
|
2130 | + return $relation_settings->delete_all_related($model_obj, $query_params); |
|
2131 | 2131 | } |
2132 | 2132 | |
2133 | 2133 | /** |
@@ -2140,10 +2140,10 @@ discard block |
||
2140 | 2140 | * @param array $query_params |
2141 | 2141 | * @return int how many deleted |
2142 | 2142 | */ |
2143 | - public function delete_related_permanently($id_or_obj,$model_name, $query_params = array()){ |
|
2143 | + public function delete_related_permanently($id_or_obj, $model_name, $query_params = array()) { |
|
2144 | 2144 | $model_obj = $this->ensure_is_obj($id_or_obj); |
2145 | 2145 | $relation_settings = $this->related_settings_for($model_name); |
2146 | - return $relation_settings->delete_related_permanently($model_obj,$query_params); |
|
2146 | + return $relation_settings->delete_related_permanently($model_obj, $query_params); |
|
2147 | 2147 | } |
2148 | 2148 | |
2149 | 2149 | /** |
@@ -2156,17 +2156,17 @@ discard block |
||
2156 | 2156 | * @param bool $distinct if we want to only count the distinct values for the column then you can trigger that by the setting $distinct to TRUE; |
2157 | 2157 | * @return int |
2158 | 2158 | */ |
2159 | - function count_related($id_or_obj,$model_name,$query_params = array(),$field_to_count = null, $distinct = FALSE){ |
|
2159 | + function count_related($id_or_obj, $model_name, $query_params = array(), $field_to_count = null, $distinct = FALSE) { |
|
2160 | 2160 | $related_model = $this->get_related_model_obj($model_name); |
2161 | 2161 | //we're just going to use the query params on the related model's normal get_all query, |
2162 | 2162 | //except add a condition to say to match the current mod |
2163 | - if( ! isset($query_params['default_where_conditions'])){ |
|
2164 | - $query_params['default_where_conditions']='none'; |
|
2163 | + if ( ! isset($query_params['default_where_conditions'])) { |
|
2164 | + $query_params['default_where_conditions'] = 'none'; |
|
2165 | 2165 | } |
2166 | 2166 | $this_model_name = $this->get_this_model_name(); |
2167 | 2167 | $this_pk_field_name = $this->get_primary_key_field()->get_name(); |
2168 | - $query_params[0][$this_model_name.".".$this_pk_field_name]=$id_or_obj; |
|
2169 | - return $related_model->count($query_params,$field_to_count,$distinct); |
|
2168 | + $query_params[0][$this_model_name.".".$this_pk_field_name] = $id_or_obj; |
|
2169 | + return $related_model->count($query_params, $field_to_count, $distinct); |
|
2170 | 2170 | } |
2171 | 2171 | |
2172 | 2172 | |
@@ -2180,21 +2180,21 @@ discard block |
||
2180 | 2180 | * @param string $field_to_sum name of field to count by. By default, uses primary key |
2181 | 2181 | * @return float |
2182 | 2182 | */ |
2183 | - function sum_related($id_or_obj,$model_name,$query_params,$field_to_sum = null){ |
|
2183 | + function sum_related($id_or_obj, $model_name, $query_params, $field_to_sum = null) { |
|
2184 | 2184 | $related_model = $this->get_related_model_obj($model_name); |
2185 | - if( ! is_array( $query_params ) ){ |
|
2186 | - EE_Error::doing_it_wrong('EEM_Base::sum_related', sprintf( __( '$query_params should be an array, you passed a variable of type %s', 'event_espresso' ), gettype( $query_params ) ), '4.6.0' ); |
|
2185 | + if ( ! is_array($query_params)) { |
|
2186 | + EE_Error::doing_it_wrong('EEM_Base::sum_related', sprintf(__('$query_params should be an array, you passed a variable of type %s', 'event_espresso'), gettype($query_params)), '4.6.0'); |
|
2187 | 2187 | $query_params = array(); |
2188 | 2188 | } |
2189 | 2189 | //we're just going to use the query params on the related model's normal get_all query, |
2190 | 2190 | //except add a condition to say to match the current mod |
2191 | - if( ! isset($query_params['default_where_conditions'])){ |
|
2192 | - $query_params['default_where_conditions']='none'; |
|
2191 | + if ( ! isset($query_params['default_where_conditions'])) { |
|
2192 | + $query_params['default_where_conditions'] = 'none'; |
|
2193 | 2193 | } |
2194 | 2194 | $this_model_name = $this->get_this_model_name(); |
2195 | 2195 | $this_pk_field_name = $this->get_primary_key_field()->get_name(); |
2196 | - $query_params[0][$this_model_name.".".$this_pk_field_name]=$id_or_obj; |
|
2197 | - return $related_model->sum($query_params,$field_to_sum); |
|
2196 | + $query_params[0][$this_model_name.".".$this_pk_field_name] = $id_or_obj; |
|
2197 | + return $related_model->sum($query_params, $field_to_sum); |
|
2198 | 2198 | } |
2199 | 2199 | |
2200 | 2200 | |
@@ -2206,12 +2206,12 @@ discard block |
||
2206 | 2206 | * @param array $query_params like EEM_Base::get_all's |
2207 | 2207 | * @return EE_Base_Class |
2208 | 2208 | */ |
2209 | - public function get_first_related( EE_Base_Class $id_or_obj, $other_model_name, $query_params ){ |
|
2210 | - $query_params['limit']=1; |
|
2211 | - $results = $this->get_all_related($id_or_obj,$other_model_name,$query_params); |
|
2212 | - if( $results ){ |
|
2209 | + public function get_first_related(EE_Base_Class $id_or_obj, $other_model_name, $query_params) { |
|
2210 | + $query_params['limit'] = 1; |
|
2211 | + $results = $this->get_all_related($id_or_obj, $other_model_name, $query_params); |
|
2212 | + if ($results) { |
|
2213 | 2213 | return array_shift($results); |
2214 | - }else{ |
|
2214 | + } else { |
|
2215 | 2215 | return null; |
2216 | 2216 | } |
2217 | 2217 | |
@@ -2221,8 +2221,8 @@ discard block |
||
2221 | 2221 | * Gets the model's name as it's expected in queries. For example, if this is EEM_Event model, that would be Event |
2222 | 2222 | * @return string |
2223 | 2223 | */ |
2224 | - function get_this_model_name(){ |
|
2225 | - return str_replace("EEM_","",get_class($this)); |
|
2224 | + function get_this_model_name() { |
|
2225 | + return str_replace("EEM_", "", get_class($this)); |
|
2226 | 2226 | } |
2227 | 2227 | |
2228 | 2228 | /** |
@@ -2230,14 +2230,14 @@ discard block |
||
2230 | 2230 | * @return EE_Any_Foreign_Model_Name_Field |
2231 | 2231 | * @throws EE_Error |
2232 | 2232 | */ |
2233 | - public function get_field_containing_related_model_name(){ |
|
2234 | - foreach($this->field_settings(true) as $field){ |
|
2235 | - if($field instanceof EE_Any_Foreign_Model_Name_Field){ |
|
2233 | + public function get_field_containing_related_model_name() { |
|
2234 | + foreach ($this->field_settings(true) as $field) { |
|
2235 | + if ($field instanceof EE_Any_Foreign_Model_Name_Field) { |
|
2236 | 2236 | $field_with_model_name = $field; |
2237 | 2237 | } |
2238 | 2238 | } |
2239 | - if( !isset($field_with_model_name) || !$field_with_model_name ){ |
|
2240 | - throw new EE_Error(sprintf(__("There is no EE_Any_Foreign_Model_Name field on model %s", "event_espresso"), $this->get_this_model_name() )); |
|
2239 | + if ( ! isset($field_with_model_name) || ! $field_with_model_name) { |
|
2240 | + throw new EE_Error(sprintf(__("There is no EE_Any_Foreign_Model_Name field on model %s", "event_espresso"), $this->get_this_model_name())); |
|
2241 | 2241 | } |
2242 | 2242 | return $field_with_model_name; |
2243 | 2243 | } |
@@ -2258,19 +2258,19 @@ discard block |
||
2258 | 2258 | * @return int new primary key on main table that got inserted |
2259 | 2259 | * @throws EE_Error |
2260 | 2260 | */ |
2261 | - function insert($field_n_values){ |
|
2261 | + function insert($field_n_values) { |
|
2262 | 2262 | /** |
2263 | 2263 | * Filters the fields and their values before inserting an item using the models |
2264 | 2264 | * @param array $fields_n_values keys are the fields and values are their new values |
2265 | 2265 | * @param EEM_Base $model the model used |
2266 | 2266 | */ |
2267 | - $field_n_values = apply_filters( 'FHEE__EEM_Base__insert__fields_n_values', $field_n_values, $this ); |
|
2268 | - if($this->_satisfies_unique_indexes($field_n_values)){ |
|
2267 | + $field_n_values = apply_filters('FHEE__EEM_Base__insert__fields_n_values', $field_n_values, $this); |
|
2268 | + if ($this->_satisfies_unique_indexes($field_n_values)) { |
|
2269 | 2269 | $main_table = $this->_get_main_table(); |
2270 | 2270 | $new_id = $this->_insert_into_specific_table($main_table, $field_n_values, false); |
2271 | - if( $new_id !== false ) { |
|
2272 | - foreach($this->_get_other_tables() as $other_table){ |
|
2273 | - $this->_insert_into_specific_table($other_table, $field_n_values,$new_id); |
|
2271 | + if ($new_id !== false) { |
|
2272 | + foreach ($this->_get_other_tables() as $other_table) { |
|
2273 | + $this->_insert_into_specific_table($other_table, $field_n_values, $new_id); |
|
2274 | 2274 | } |
2275 | 2275 | } |
2276 | 2276 | /** |
@@ -2280,9 +2280,9 @@ discard block |
||
2280 | 2280 | * @param array $fields_n_values fields and their values |
2281 | 2281 | * @param int|string the ID of the newly-inserted model object |
2282 | 2282 | */ |
2283 | - do_action( 'AHEE__EEM_Base__insert__end', $this, $field_n_values, $new_id ); |
|
2283 | + do_action('AHEE__EEM_Base__insert__end', $this, $field_n_values, $new_id); |
|
2284 | 2284 | return $new_id; |
2285 | - }else{ |
|
2285 | + } else { |
|
2286 | 2286 | return FALSE; |
2287 | 2287 | } |
2288 | 2288 | } |
@@ -2295,11 +2295,11 @@ discard block |
||
2295 | 2295 | * @param string $action |
2296 | 2296 | * @return boolean |
2297 | 2297 | */ |
2298 | - protected function _satisfies_unique_indexes($field_n_values,$action = 'insert'){ |
|
2299 | - foreach($this->unique_indexes() as $index_name => $index){ |
|
2298 | + protected function _satisfies_unique_indexes($field_n_values, $action = 'insert') { |
|
2299 | + foreach ($this->unique_indexes() as $index_name => $index) { |
|
2300 | 2300 | $uniqueness_where_params = array_intersect_key($field_n_values, $index->fields()); |
2301 | - if($this->exists(array($uniqueness_where_params))){ |
|
2302 | - EE_Error::add_error(sprintf(__("Could not %s %s. %s uniqueness index failed. Fields %s must form a unique set, but an entry already exists with values %s.", "event_espresso"),$action,$this->_get_class_name(),$index_name,implode(",",$index->field_names()),http_build_query($uniqueness_where_params)), __FILE__, __FUNCTION__, __LINE__ ); |
|
2301 | + if ($this->exists(array($uniqueness_where_params))) { |
|
2302 | + EE_Error::add_error(sprintf(__("Could not %s %s. %s uniqueness index failed. Fields %s must form a unique set, but an entry already exists with values %s.", "event_espresso"), $action, $this->_get_class_name(), $index_name, implode(",", $index->field_names()), http_build_query($uniqueness_where_params)), __FILE__, __FUNCTION__, __LINE__); |
|
2303 | 2303 | return false; |
2304 | 2304 | } |
2305 | 2305 | } |
@@ -2320,28 +2320,28 @@ discard block |
||
2320 | 2320 | * @throws EE_Error |
2321 | 2321 | * @return EE_Base_Class |
2322 | 2322 | */ |
2323 | - public function get_one_conflicting($obj_or_fields_array, $include_primary_key = true ){ |
|
2324 | - if($obj_or_fields_array instanceof EE_Base_Class){ |
|
2323 | + public function get_one_conflicting($obj_or_fields_array, $include_primary_key = true) { |
|
2324 | + if ($obj_or_fields_array instanceof EE_Base_Class) { |
|
2325 | 2325 | $fields_n_values = $obj_or_fields_array->model_field_array(); |
2326 | - }elseif( is_array($obj_or_fields_array)){ |
|
2326 | + }elseif (is_array($obj_or_fields_array)) { |
|
2327 | 2327 | $fields_n_values = $obj_or_fields_array; |
2328 | - }else{ |
|
2329 | - throw new EE_Error(sprintf(__("%s get_all_conflicting should be called with a model object or an array of field names and values, you provided %d", "event_espresso"),get_class($this),$obj_or_fields_array)); |
|
2328 | + } else { |
|
2329 | + throw new EE_Error(sprintf(__("%s get_all_conflicting should be called with a model object or an array of field names and values, you provided %d", "event_espresso"), get_class($this), $obj_or_fields_array)); |
|
2330 | 2330 | } |
2331 | - $query_params = array( 'default_where_conditions' => 'minimum' ); |
|
2332 | - if( $this->has_primary_key_field() && |
|
2333 | - ( $include_primary_key || $this->get_primary_key_field() instanceof EE_Primary_Key_String_Field) && |
|
2334 | - isset($fields_n_values[$this->primary_key_name()])){ |
|
2331 | + $query_params = array('default_where_conditions' => 'minimum'); |
|
2332 | + if ($this->has_primary_key_field() && |
|
2333 | + ($include_primary_key || $this->get_primary_key_field() instanceof EE_Primary_Key_String_Field) && |
|
2334 | + isset($fields_n_values[$this->primary_key_name()])) { |
|
2335 | 2335 | $query_params[0]['OR'][$this->primary_key_name()] = $fields_n_values[$this->primary_key_name()]; |
2336 | 2336 | } |
2337 | - foreach($this->unique_indexes() as $unique_index_name=>$unique_index){ |
|
2337 | + foreach ($this->unique_indexes() as $unique_index_name=>$unique_index) { |
|
2338 | 2338 | $uniqueness_where_params = array_intersect_key($fields_n_values, $unique_index->fields()); |
2339 | 2339 | $query_params[0]['OR']['AND*'.$unique_index_name] = $uniqueness_where_params; |
2340 | 2340 | } |
2341 | 2341 | //if there is nothing to base this search on, then we shouldn't find anything |
2342 | - if( ! isset( $query_params[0] ) || ( isset( $query_params[0] ) && empty( $query_params[0] ) ) ) { |
|
2342 | + if ( ! isset($query_params[0]) || (isset($query_params[0]) && empty($query_params[0]))) { |
|
2343 | 2343 | return array(); |
2344 | - }else{ |
|
2344 | + } else { |
|
2345 | 2345 | return $this->get_one($query_params); |
2346 | 2346 | } |
2347 | 2347 | } |
@@ -2351,7 +2351,7 @@ discard block |
||
2351 | 2351 | * @param array $query_params |
2352 | 2352 | * @return boolean |
2353 | 2353 | */ |
2354 | - function exists($query_params){ |
|
2354 | + function exists($query_params) { |
|
2355 | 2355 | $query_params['limit'] = 1; |
2356 | 2356 | return $this->count($query_params) > 0; |
2357 | 2357 | } |
@@ -2361,7 +2361,7 @@ discard block |
||
2361 | 2361 | * @param int|string $id |
2362 | 2362 | * @return boolean |
2363 | 2363 | */ |
2364 | - function exists_by_ID($id){ |
|
2364 | + function exists_by_ID($id) { |
|
2365 | 2365 | return $this->exists(array('default_where_conditions'=>'none', array($this->primary_key_name() => $id))); |
2366 | 2366 | } |
2367 | 2367 | |
@@ -2381,45 +2381,45 @@ discard block |
||
2381 | 2381 | * @global WPDB $wpdb only used to get the $wpdb->insert_id after performing an insert |
2382 | 2382 | * @return int ID of new row inserted, or FALSE on failure |
2383 | 2383 | */ |
2384 | - protected function _insert_into_specific_table(EE_Table_Base $table, $fields_n_values, $new_id = 0 ){ |
|
2384 | + protected function _insert_into_specific_table(EE_Table_Base $table, $fields_n_values, $new_id = 0) { |
|
2385 | 2385 | global $wpdb; |
2386 | 2386 | $insertion_col_n_values = array(); |
2387 | 2387 | $format_for_insertion = array(); |
2388 | 2388 | $fields_on_table = $this->_get_fields_for_table($table->get_table_alias()); |
2389 | - foreach($fields_on_table as $field_name => $field_obj){ |
|
2389 | + foreach ($fields_on_table as $field_name => $field_obj) { |
|
2390 | 2390 | //check if its an auto-incrementing column, in which case we should just leave it to do its autoincrement thing |
2391 | - if($field_obj->is_auto_increment()){ |
|
2391 | + if ($field_obj->is_auto_increment()) { |
|
2392 | 2392 | continue; |
2393 | 2393 | } |
2394 | 2394 | $prepared_value = $this->_prepare_value_or_use_default($field_obj, $fields_n_values); |
2395 | 2395 | //if the value we want to assign it to is NULL, just don't mention it for the insertion |
2396 | - if( $prepared_value !== NULL ){ |
|
2397 | - $insertion_col_n_values[ $field_obj->get_table_column() ] = $prepared_value; |
|
2396 | + if ($prepared_value !== NULL) { |
|
2397 | + $insertion_col_n_values[$field_obj->get_table_column()] = $prepared_value; |
|
2398 | 2398 | $format_for_insertion[] = $field_obj->get_wpdb_data_type(); |
2399 | 2399 | } |
2400 | 2400 | } |
2401 | 2401 | |
2402 | - if($table instanceof EE_Secondary_Table && $new_id){ |
|
2402 | + if ($table instanceof EE_Secondary_Table && $new_id) { |
|
2403 | 2403 | //its not the main table, so we should have already saved the main table's PK which we just inserted |
2404 | 2404 | //so add the fk to the main table as a column |
2405 | 2405 | $insertion_col_n_values[$table->get_fk_on_table()] = $new_id; |
2406 | - $format_for_insertion[]='%d';//yes right now we're only allowing these foreign keys to be INTs |
|
2406 | + $format_for_insertion[] = '%d'; //yes right now we're only allowing these foreign keys to be INTs |
|
2407 | 2407 | } |
2408 | 2408 | //insert the new entry |
2409 | - $result = $this->_do_wpdb_query( 'insert', array( $table->get_table_name(), $insertion_col_n_values, $format_for_insertion ) ); |
|
2410 | - if( $result === false ) { |
|
2409 | + $result = $this->_do_wpdb_query('insert', array($table->get_table_name(), $insertion_col_n_values, $format_for_insertion)); |
|
2410 | + if ($result === false) { |
|
2411 | 2411 | return false; |
2412 | 2412 | } |
2413 | 2413 | //ok, now what do we return for the ID of the newly-inserted thing? |
2414 | - if($this->has_primary_key_field()){ |
|
2415 | - if($this->get_primary_key_field()->is_auto_increment()){ |
|
2414 | + if ($this->has_primary_key_field()) { |
|
2415 | + if ($this->get_primary_key_field()->is_auto_increment()) { |
|
2416 | 2416 | return $wpdb->insert_id; |
2417 | - }else{ |
|
2417 | + } else { |
|
2418 | 2418 | //it's not an auto-increment primary key, so |
2419 | 2419 | //it must have been supplied |
2420 | 2420 | return $fields_n_values[$this->get_primary_key_field()->get_name()]; |
2421 | 2421 | } |
2422 | - }else{ |
|
2422 | + } else { |
|
2423 | 2423 | //we can't return a primary key because there is none. instead return |
2424 | 2424 | //a unique string indicating this model |
2425 | 2425 | return $this->get_index_primary_key_string($fields_n_values); |
@@ -2434,15 +2434,15 @@ discard block |
||
2434 | 2434 | * @param array $fields_n_values |
2435 | 2435 | * @return mixed string|int|float depending on what the table column will be expecting |
2436 | 2436 | */ |
2437 | - protected function _prepare_value_or_use_default( $field_obj, $fields_n_values ){ |
|
2437 | + protected function _prepare_value_or_use_default($field_obj, $fields_n_values) { |
|
2438 | 2438 | //if this field doesn't allow nullable, don't allow it |
2439 | - if( ! $field_obj->is_nullable() && ( |
|
2440 | - ! isset( $fields_n_values[ $field_obj->get_name() ] ) || |
|
2441 | - $fields_n_values[ $field_obj->get_name() ] === NULL ) ){ |
|
2442 | - $fields_n_values[ $field_obj->get_name() ] = $field_obj->get_default_value(); |
|
2439 | + if ( ! $field_obj->is_nullable() && ( |
|
2440 | + ! isset($fields_n_values[$field_obj->get_name()]) || |
|
2441 | + $fields_n_values[$field_obj->get_name()] === NULL )) { |
|
2442 | + $fields_n_values[$field_obj->get_name()] = $field_obj->get_default_value(); |
|
2443 | 2443 | } |
2444 | - $unprepared_value = isset( $fields_n_values[ $field_obj->get_name() ] ) ? $fields_n_values[ $field_obj->get_name() ] : NULL; |
|
2445 | - return $this->_prepare_value_for_use_in_db( $unprepared_value, $field_obj); |
|
2444 | + $unprepared_value = isset($fields_n_values[$field_obj->get_name()]) ? $fields_n_values[$field_obj->get_name()] : NULL; |
|
2445 | + return $this->_prepare_value_for_use_in_db($unprepared_value, $field_obj); |
|
2446 | 2446 | } |
2447 | 2447 | |
2448 | 2448 | |
@@ -2454,9 +2454,9 @@ discard block |
||
2454 | 2454 | * @param EE_Model_Field_Base $field field which will be doing the preparing of the value. If null, we assume $value is a custom selection |
2455 | 2455 | * @return mixed a value ready for use in the database for insertions, updating, or in a where clause |
2456 | 2456 | */ |
2457 | - private function _prepare_value_for_use_in_db($value, $field){ |
|
2458 | - if($field && $field instanceof EE_Model_Field_Base){ |
|
2459 | - switch( $this->_values_already_prepared_by_model_object ){ |
|
2457 | + private function _prepare_value_for_use_in_db($value, $field) { |
|
2458 | + if ($field && $field instanceof EE_Model_Field_Base) { |
|
2459 | + switch ($this->_values_already_prepared_by_model_object) { |
|
2460 | 2460 | /** @noinspection PhpMissingBreakStatementInspection */ |
2461 | 2461 | case self::not_prepared_by_model_object: |
2462 | 2462 | $value = $field->prepare_for_set($value); |
@@ -2467,7 +2467,7 @@ discard block |
||
2467 | 2467 | //leave the value alone |
2468 | 2468 | } |
2469 | 2469 | return $value; |
2470 | - }else{ |
|
2470 | + } else { |
|
2471 | 2471 | return $value; |
2472 | 2472 | } |
2473 | 2473 | } |
@@ -2477,13 +2477,13 @@ discard block |
||
2477 | 2477 | * @return EE_Primary_Table |
2478 | 2478 | * @throws EE_Error |
2479 | 2479 | */ |
2480 | - protected function _get_main_table(){ |
|
2481 | - foreach($this->_tables as $table){ |
|
2482 | - if($table instanceof EE_Primary_Table){ |
|
2480 | + protected function _get_main_table() { |
|
2481 | + foreach ($this->_tables as $table) { |
|
2482 | + if ($table instanceof EE_Primary_Table) { |
|
2483 | 2483 | return $table; |
2484 | 2484 | } |
2485 | 2485 | } |
2486 | - throw new EE_Error(sprintf(__('There are no main tables on %s. They should be added to _tables array in the constructor','event_espresso'),get_class($this))); |
|
2486 | + throw new EE_Error(sprintf(__('There are no main tables on %s. They should be added to _tables array in the constructor', 'event_espresso'), get_class($this))); |
|
2487 | 2487 | } |
2488 | 2488 | |
2489 | 2489 | /** |
@@ -2502,7 +2502,7 @@ discard block |
||
2502 | 2502 | */ |
2503 | 2503 | public function second_table() { |
2504 | 2504 | // grab second table from tables array |
2505 | - $second_table = end( $this->_tables ); |
|
2505 | + $second_table = end($this->_tables); |
|
2506 | 2506 | return $second_table instanceof EE_Secondary_Table ? $second_table->get_table_name() : NULL; |
2507 | 2507 | } |
2508 | 2508 | |
@@ -2515,8 +2515,8 @@ discard block |
||
2515 | 2515 | * @param string $table_alias |
2516 | 2516 | * @return EE_Primary_Table | EE_Secondary_Table |
2517 | 2517 | */ |
2518 | - public function get_table_obj_by_alias( $table_alias = '' ) { |
|
2519 | - return isset( $this->_tables[ $table_alias ] ) ? $this->_tables[ $table_alias ] : NULL; |
|
2518 | + public function get_table_obj_by_alias($table_alias = '') { |
|
2519 | + return isset($this->_tables[$table_alias]) ? $this->_tables[$table_alias] : NULL; |
|
2520 | 2520 | } |
2521 | 2521 | |
2522 | 2522 | |
@@ -2525,10 +2525,10 @@ discard block |
||
2525 | 2525 | * Gets all the tables of type EE_Other_Table from EEM_CPT_Basel_Model::_tables |
2526 | 2526 | * @return EE_Secondary_Table[] |
2527 | 2527 | */ |
2528 | - protected function _get_other_tables(){ |
|
2529 | - $other_tables =array(); |
|
2530 | - foreach($this->_tables as $table_alias => $table){ |
|
2531 | - if($table instanceof EE_Secondary_Table){ |
|
2528 | + protected function _get_other_tables() { |
|
2529 | + $other_tables = array(); |
|
2530 | + foreach ($this->_tables as $table_alias => $table) { |
|
2531 | + if ($table instanceof EE_Secondary_Table) { |
|
2532 | 2532 | $other_tables[$table_alias] = $table; |
2533 | 2533 | } |
2534 | 2534 | } |
@@ -2540,7 +2540,7 @@ discard block |
||
2540 | 2540 | * @param string $table_alias, array key in EEM_Base::_tables |
2541 | 2541 | * @return EE_Model_Field_Base[] |
2542 | 2542 | */ |
2543 | - function _get_fields_for_table($table_alias){ |
|
2543 | + function _get_fields_for_table($table_alias) { |
|
2544 | 2544 | return $this->_fields[$table_alias]; |
2545 | 2545 | } |
2546 | 2546 | |
@@ -2552,29 +2552,29 @@ discard block |
||
2552 | 2552 | * @param array $query_params like EEM_Base::get_all's $query_parameters['where'] |
2553 | 2553 | * @return EE_Model_Query_Info_Carrier |
2554 | 2554 | */ |
2555 | - function _extract_related_models_from_query($query_params){ |
|
2555 | + function _extract_related_models_from_query($query_params) { |
|
2556 | 2556 | $query_info_carrier = new EE_Model_Query_Info_Carrier(); |
2557 | - if(array_key_exists(0,$query_params)){ |
|
2558 | - $this->_extract_related_models_from_sub_params_array_keys($query_params[0], $query_info_carrier,0); |
|
2559 | - } |
|
2560 | - if(array_key_exists('group_by', $query_params)){ |
|
2561 | - if(is_array($query_params['group_by'])){ |
|
2562 | - $this->_extract_related_models_from_sub_params_array_values($query_params['group_by'],$query_info_carrier,'group_by'); |
|
2563 | - }elseif( ! empty ( $query_params['group_by'] )){ |
|
2564 | - $this->_extract_related_model_info_from_query_param( $query_params['group_by'],$query_info_carrier,'group_by'); |
|
2557 | + if (array_key_exists(0, $query_params)) { |
|
2558 | + $this->_extract_related_models_from_sub_params_array_keys($query_params[0], $query_info_carrier, 0); |
|
2559 | + } |
|
2560 | + if (array_key_exists('group_by', $query_params)) { |
|
2561 | + if (is_array($query_params['group_by'])) { |
|
2562 | + $this->_extract_related_models_from_sub_params_array_values($query_params['group_by'], $query_info_carrier, 'group_by'); |
|
2563 | + }elseif ( ! empty ($query_params['group_by'])) { |
|
2564 | + $this->_extract_related_model_info_from_query_param($query_params['group_by'], $query_info_carrier, 'group_by'); |
|
2565 | 2565 | } |
2566 | 2566 | } |
2567 | - if(array_key_exists('having',$query_params)){ |
|
2568 | - $this->_extract_related_models_from_sub_params_array_keys($query_params[0], $query_info_carrier,'having'); |
|
2567 | + if (array_key_exists('having', $query_params)) { |
|
2568 | + $this->_extract_related_models_from_sub_params_array_keys($query_params[0], $query_info_carrier, 'having'); |
|
2569 | 2569 | } |
2570 | - if(array_key_exists('order_by', $query_params)){ |
|
2571 | - if ( is_array( $query_params['order_by'] ) ) |
|
2572 | - $this->_extract_related_models_from_sub_params_array_keys($query_params['order_by'],$query_info_carrier,'order_by'); |
|
2573 | - elseif( ! empty( $query_params['order_by'] )) |
|
2574 | - $this->_extract_related_model_info_from_query_param( $query_params['order_by'], $query_info_carrier,'order_by'); |
|
2570 | + if (array_key_exists('order_by', $query_params)) { |
|
2571 | + if (is_array($query_params['order_by'])) |
|
2572 | + $this->_extract_related_models_from_sub_params_array_keys($query_params['order_by'], $query_info_carrier, 'order_by'); |
|
2573 | + elseif ( ! empty($query_params['order_by'])) |
|
2574 | + $this->_extract_related_model_info_from_query_param($query_params['order_by'], $query_info_carrier, 'order_by'); |
|
2575 | 2575 | } |
2576 | - if(array_key_exists('force_join', $query_params)){ |
|
2577 | - $this->_extract_related_models_from_sub_params_array_values($query_params['force_join'],$query_info_carrier,'force_join'); |
|
2576 | + if (array_key_exists('force_join', $query_params)) { |
|
2577 | + $this->_extract_related_models_from_sub_params_array_values($query_params['force_join'], $query_info_carrier, 'force_join'); |
|
2578 | 2578 | } |
2579 | 2579 | return $query_info_carrier; |
2580 | 2580 | } |
@@ -2587,34 +2587,34 @@ discard block |
||
2587 | 2587 | * @throws EE_Error |
2588 | 2588 | * @return \EE_Model_Query_Info_Carrier |
2589 | 2589 | */ |
2590 | - private function _extract_related_models_from_sub_params_array_keys($sub_query_params, EE_Model_Query_Info_Carrier $model_query_info_carrier,$query_param_type){ |
|
2591 | - if (!empty($sub_query_params)){ |
|
2590 | + private function _extract_related_models_from_sub_params_array_keys($sub_query_params, EE_Model_Query_Info_Carrier $model_query_info_carrier, $query_param_type) { |
|
2591 | + if ( ! empty($sub_query_params)) { |
|
2592 | 2592 | $sub_query_params = (array) $sub_query_params; |
2593 | - foreach($sub_query_params as $param => $possibly_array_of_params){ |
|
2593 | + foreach ($sub_query_params as $param => $possibly_array_of_params) { |
|
2594 | 2594 | //$param could be simply 'EVT_ID', or it could be 'Registrations.REG_ID', or even 'Registrations.Transactions.Payments.PAY_amount' |
2595 | - $this->_extract_related_model_info_from_query_param( $param, $model_query_info_carrier,$query_param_type); |
|
2595 | + $this->_extract_related_model_info_from_query_param($param, $model_query_info_carrier, $query_param_type); |
|
2596 | 2596 | |
2597 | 2597 | //if $possibly_array_of_params is an array, try recursing into it, searching for keys which |
2598 | 2598 | //indicate needed joins. Eg, array('NOT'=>array('Registration.TXN_ID'=>23)). In this case, we tried |
2599 | 2599 | //extracting models out of the 'NOT', which obviously wasn't successful, and then we recurse into the value |
2600 | 2600 | //of array('Registration.TXN_ID'=>23) |
2601 | 2601 | $query_param_sans_stars = $this->_remove_stars_and_anything_after_from_condition_query_param_key($param); |
2602 | - if(in_array($query_param_sans_stars, $this->_logic_query_param_keys,true)){ |
|
2603 | - if (! is_array($possibly_array_of_params)){ |
|
2602 | + if (in_array($query_param_sans_stars, $this->_logic_query_param_keys, true)) { |
|
2603 | + if ( ! is_array($possibly_array_of_params)) { |
|
2604 | 2604 | throw new EE_Error(sprintf(__("You used a special where query param %s, but the value isn't an array of where query params, it's just %s'. It should be an array, eg array('EVT_ID'=>23,'OR'=>array('Venue.VNU_ID'=>32,'Venue.VNU_name'=>'monkey_land'))", "event_espresso"), |
2605 | - $param,$possibly_array_of_params)); |
|
2606 | - }else{ |
|
2607 | - $this->_extract_related_models_from_sub_params_array_keys($possibly_array_of_params, $model_query_info_carrier,$query_param_type); |
|
2605 | + $param, $possibly_array_of_params)); |
|
2606 | + } else { |
|
2607 | + $this->_extract_related_models_from_sub_params_array_keys($possibly_array_of_params, $model_query_info_carrier, $query_param_type); |
|
2608 | 2608 | } |
2609 | - }elseif($query_param_type === 0 //ie WHERE |
|
2609 | + }elseif ($query_param_type === 0 //ie WHERE |
|
2610 | 2610 | && is_array($possibly_array_of_params) |
2611 | 2611 | && isset($possibly_array_of_params[2]) |
2612 | - && $possibly_array_of_params[2] == true){ |
|
2612 | + && $possibly_array_of_params[2] == true) { |
|
2613 | 2613 | //then $possible_array_of_params looks something like array('<','DTT_sold',true) |
2614 | 2614 | //indicating that $possible_array_of_params[1] is actually a field name, |
2615 | 2615 | //from which we should extract query parameters! |
2616 | - if(! isset($possibly_array_of_params[0]) || ! isset($possibly_array_of_params[1])){ |
|
2617 | - throw new EE_Error(sprintf(__("Improperly formed query parameter %s. It should be numerically indexed like array('<','DTT_sold',true); but you provided %s", "event_espresso"),$query_param_type,implode(",",$possibly_array_of_params))); |
|
2616 | + if ( ! isset($possibly_array_of_params[0]) || ! isset($possibly_array_of_params[1])) { |
|
2617 | + throw new EE_Error(sprintf(__("Improperly formed query parameter %s. It should be numerically indexed like array('<','DTT_sold',true); but you provided %s", "event_espresso"), $query_param_type, implode(",", $possibly_array_of_params))); |
|
2618 | 2618 | } |
2619 | 2619 | $this->_extract_related_model_info_from_query_param($possibly_array_of_params[1], $model_query_info_carrier, $query_param_type); |
2620 | 2620 | } |
@@ -2633,14 +2633,14 @@ discard block |
||
2633 | 2633 | * @throws EE_Error |
2634 | 2634 | * @return \EE_Model_Query_Info_Carrier |
2635 | 2635 | */ |
2636 | - private function _extract_related_models_from_sub_params_array_values($sub_query_params, EE_Model_Query_Info_Carrier $model_query_info_carrier,$query_param_type){ |
|
2637 | - if (!empty($sub_query_params)){ |
|
2638 | - if(!is_array($sub_query_params)){ |
|
2639 | - throw new EE_Error(sprintf(__("Query parameter %s should be an array, but it isn't.", "event_espresso"),$sub_query_params)); |
|
2636 | + private function _extract_related_models_from_sub_params_array_values($sub_query_params, EE_Model_Query_Info_Carrier $model_query_info_carrier, $query_param_type) { |
|
2637 | + if ( ! empty($sub_query_params)) { |
|
2638 | + if ( ! is_array($sub_query_params)) { |
|
2639 | + throw new EE_Error(sprintf(__("Query parameter %s should be an array, but it isn't.", "event_espresso"), $sub_query_params)); |
|
2640 | 2640 | } |
2641 | - foreach($sub_query_params as $param){ |
|
2641 | + foreach ($sub_query_params as $param) { |
|
2642 | 2642 | //$param could be simply 'EVT_ID', or it could be 'Registrations.REG_ID', or even 'Registrations.Transactions.Payments.PAY_amount' |
2643 | - $this->_extract_related_model_info_from_query_param( $param, $model_query_info_carrier, $query_param_type); |
|
2643 | + $this->_extract_related_model_info_from_query_param($param, $model_query_info_carrier, $query_param_type); |
|
2644 | 2644 | } |
2645 | 2645 | } |
2646 | 2646 | return $model_query_info_carrier; |
@@ -2659,81 +2659,81 @@ discard block |
||
2659 | 2659 | * @throws EE_Error |
2660 | 2660 | * @return EE_Model_Query_Info_Carrier |
2661 | 2661 | */ |
2662 | - function _create_model_query_info_carrier($query_params){ |
|
2663 | - if( ! is_array( $query_params ) ){ |
|
2664 | - EE_Error::doing_it_wrong('EEM_Base::_create_model_query_info_carrier', sprintf( __( '$query_params should be an array, you passed a variable of type %s', 'event_espresso' ), gettype( $query_params ) ), '4.6.0' ); |
|
2662 | + function _create_model_query_info_carrier($query_params) { |
|
2663 | + if ( ! is_array($query_params)) { |
|
2664 | + EE_Error::doing_it_wrong('EEM_Base::_create_model_query_info_carrier', sprintf(__('$query_params should be an array, you passed a variable of type %s', 'event_espresso'), gettype($query_params)), '4.6.0'); |
|
2665 | 2665 | $query_params = array(); |
2666 | 2666 | } |
2667 | - if( isset( $query_params[0] ) ) { |
|
2667 | + if (isset($query_params[0])) { |
|
2668 | 2668 | $where_query_params = $query_params[0]; |
2669 | - }else{ |
|
2669 | + } else { |
|
2670 | 2670 | $where_query_params = array(); |
2671 | 2671 | } |
2672 | 2672 | //first check if we should alter the query to account for caps or not |
2673 | 2673 | //because the caps might require us to do extra joins |
2674 | - if( isset( $query_params[ 'caps' ] ) && $query_params[ 'caps' ] != 'none' ) { |
|
2675 | - $query_params[0] = $where_query_params = array_replace_recursive( $where_query_params, $this->caps_where_conditions( $query_params[ 'caps' ] ) ); |
|
2674 | + if (isset($query_params['caps']) && $query_params['caps'] != 'none') { |
|
2675 | + $query_params[0] = $where_query_params = array_replace_recursive($where_query_params, $this->caps_where_conditions($query_params['caps'])); |
|
2676 | 2676 | } |
2677 | 2677 | $query_object = $this->_extract_related_models_from_query($query_params); |
2678 | 2678 | |
2679 | 2679 | //verify where_query_params has NO numeric indexes.... that's simply not how you use it! |
2680 | - foreach($where_query_params as $key => $value){ |
|
2681 | - if(is_int($key)){ |
|
2682 | - throw new EE_Error(sprintf(__("WHERE query params must NOT be numerically-indexed. You provided the array key '%s' for value '%s' while querying model %s. All the query params provided were '%s' Please read documentation on EEM_Base::get_all.", "event_espresso"),$key, var_export( $value, true ), var_export( $query_params, true ), get_class($this))); |
|
2680 | + foreach ($where_query_params as $key => $value) { |
|
2681 | + if (is_int($key)) { |
|
2682 | + throw new EE_Error(sprintf(__("WHERE query params must NOT be numerically-indexed. You provided the array key '%s' for value '%s' while querying model %s. All the query params provided were '%s' Please read documentation on EEM_Base::get_all.", "event_espresso"), $key, var_export($value, true), var_export($query_params, true), get_class($this))); |
|
2683 | 2683 | } |
2684 | 2684 | } |
2685 | - if( array_key_exists( 'default_where_conditions',$query_params) && ! empty( $query_params['default_where_conditions'] )){ |
|
2685 | + if (array_key_exists('default_where_conditions', $query_params) && ! empty($query_params['default_where_conditions'])) { |
|
2686 | 2686 | $use_default_where_conditions = $query_params['default_where_conditions']; |
2687 | - }else{ |
|
2687 | + } else { |
|
2688 | 2688 | $use_default_where_conditions = 'all'; |
2689 | 2689 | } |
2690 | - $where_query_params = array_merge($this->_get_default_where_conditions_for_models_in_query($query_object,$use_default_where_conditions,$where_query_params), $where_query_params ); |
|
2691 | - $query_object->set_where_sql( $this->_construct_where_clause($where_query_params)); |
|
2690 | + $where_query_params = array_merge($this->_get_default_where_conditions_for_models_in_query($query_object, $use_default_where_conditions, $where_query_params), $where_query_params); |
|
2691 | + $query_object->set_where_sql($this->_construct_where_clause($where_query_params)); |
|
2692 | 2692 | |
2693 | 2693 | |
2694 | 2694 | //if this is a "on_join_limit" then we are limiting on on a specific table in a multi_table join. So we need to setup a subquery and use that for the main join. Note for now this only works on the primary table for the model. So for instance, you could set the limit array like this: |
2695 | 2695 | //array( 'on_join_limit' => array('Primary_Table_Alias', array(1,10) ) ) |
2696 | - if ( array_key_exists('on_join_limit', $query_params ) && ! empty( $query_params['on_join_limit'] )) { |
|
2697 | - $query_object->set_main_model_join_sql( $this->_construct_limit_join_select( $query_params['on_join_limit'][0], $query_params['on_join_limit'][1] ) ); |
|
2696 | + if (array_key_exists('on_join_limit', $query_params) && ! empty($query_params['on_join_limit'])) { |
|
2697 | + $query_object->set_main_model_join_sql($this->_construct_limit_join_select($query_params['on_join_limit'][0], $query_params['on_join_limit'][1])); |
|
2698 | 2698 | } |
2699 | 2699 | |
2700 | 2700 | |
2701 | 2701 | //set limit |
2702 | - if(array_key_exists('limit',$query_params)){ |
|
2703 | - if(is_array($query_params['limit'])){ |
|
2704 | - if( ! isset($query_params['limit'][0]) || ! isset($query_params['limit'][1])){ |
|
2705 | - $e = sprintf(__("Invalid DB query. You passed '%s' for the LIMIT, but only the following are valid: an integer, string representing an integer, a string like 'int,int', or an array like array(int,int)", "event_espresso"), http_build_query($query_params['limit'])); |
|
2702 | + if (array_key_exists('limit', $query_params)) { |
|
2703 | + if (is_array($query_params['limit'])) { |
|
2704 | + if ( ! isset($query_params['limit'][0]) || ! isset($query_params['limit'][1])) { |
|
2705 | + $e = sprintf(__("Invalid DB query. You passed '%s' for the LIMIT, but only the following are valid: an integer, string representing an integer, a string like 'int,int', or an array like array(int,int)", "event_espresso"), http_build_query($query_params['limit'])); |
|
2706 | 2706 | throw new EE_Error($e."|".$e); |
2707 | 2707 | } |
2708 | 2708 | //they passed us an array for the limit. Assume it's like array(50,25), meaning offset by 50, and get 25 |
2709 | 2709 | $query_object->set_limit_sql(" LIMIT ".$query_params['limit'][0].",".$query_params['limit'][1]); |
2710 | - }elseif( ! empty ( $query_params['limit'] )){ |
|
2710 | + }elseif ( ! empty ($query_params['limit'])) { |
|
2711 | 2711 | $query_object->set_limit_sql((" LIMIT ".$query_params['limit'])); |
2712 | 2712 | } |
2713 | 2713 | } |
2714 | 2714 | //set order by |
2715 | - if(array_key_exists('order_by',$query_params)){ |
|
2716 | - if(is_array($query_params['order_by'])){ |
|
2715 | + if (array_key_exists('order_by', $query_params)) { |
|
2716 | + if (is_array($query_params['order_by'])) { |
|
2717 | 2717 | //if they're using 'order_by' as an array, they can't use 'order' (because 'order_by' must |
2718 | 2718 | //specify whether to ascend or descend on each field. Eg 'order_by'=>array('EVT_ID'=>'ASC'). So |
2719 | 2719 | //including 'order' wouldn't make any sense if 'order_by' has already specified which way to order! |
2720 | - if(array_key_exists('order', $query_params)){ |
|
2720 | + if (array_key_exists('order', $query_params)) { |
|
2721 | 2721 | throw new EE_Error(sprintf(__("In querying %s, we are using query parameter 'order_by' as an array (keys:%s,values:%s), and so we can't use query parameter 'order' (value %s). You should just use the 'order_by' parameter ", "event_espresso"), |
2722 | - get_class($this),implode(", ",array_keys($query_params['order_by'])),implode(", ",$query_params['order_by']),$query_params['order'])); |
|
2722 | + get_class($this), implode(", ", array_keys($query_params['order_by'])), implode(", ", $query_params['order_by']), $query_params['order'])); |
|
2723 | 2723 | } |
2724 | - $this->_extract_related_models_from_sub_params_array_keys($query_params['order_by'],$query_object,'order_by'); |
|
2724 | + $this->_extract_related_models_from_sub_params_array_keys($query_params['order_by'], $query_object, 'order_by'); |
|
2725 | 2725 | //assume it's an array of fields to order by |
2726 | 2726 | $order_array = array(); |
2727 | - foreach($query_params['order_by'] as $field_name_to_order_by => $order){ |
|
2727 | + foreach ($query_params['order_by'] as $field_name_to_order_by => $order) { |
|
2728 | 2728 | $order = $this->_extract_order($order); |
2729 | 2729 | $order_array[] = $this->_deduce_column_name_from_query_param($field_name_to_order_by).SP.$order; |
2730 | 2730 | } |
2731 | - $query_object->set_order_by_sql(" ORDER BY ".implode(",",$order_array)); |
|
2732 | - }elseif( ! empty ( $query_params['order_by'] )){ |
|
2733 | - $this->_extract_related_model_info_from_query_param($query_params['order_by'],$query_object,'order',$query_params['order_by']); |
|
2734 | - if(isset($query_params['order'])){ |
|
2731 | + $query_object->set_order_by_sql(" ORDER BY ".implode(",", $order_array)); |
|
2732 | + }elseif ( ! empty ($query_params['order_by'])) { |
|
2733 | + $this->_extract_related_model_info_from_query_param($query_params['order_by'], $query_object, 'order', $query_params['order_by']); |
|
2734 | + if (isset($query_params['order'])) { |
|
2735 | 2735 | $order = $this->_extract_order($query_params['order']); |
2736 | - }else{ |
|
2736 | + } else { |
|
2737 | 2737 | $order = 'DESC'; |
2738 | 2738 | } |
2739 | 2739 | $query_object->set_order_by_sql(" ORDER BY ".$this->_deduce_column_name_from_query_param($query_params['order_by']).SP.$order); |
@@ -2741,46 +2741,46 @@ discard block |
||
2741 | 2741 | } |
2742 | 2742 | |
2743 | 2743 | //if 'order_by' wasn't set, maybe they are just using 'order' on its own? |
2744 | - if( ! array_key_exists('order_by',$query_params) && array_key_exists('order',$query_params) && ! empty( $query_params['order'] )){ |
|
2744 | + if ( ! array_key_exists('order_by', $query_params) && array_key_exists('order', $query_params) && ! empty($query_params['order'])) { |
|
2745 | 2745 | $pk_field = $this->get_primary_key_field(); |
2746 | 2746 | $order = $this->_extract_order($query_params['order']); |
2747 | 2747 | $query_object->set_order_by_sql(" ORDER BY ".$pk_field->get_qualified_column().SP.$order); |
2748 | 2748 | } |
2749 | 2749 | |
2750 | 2750 | //set group by |
2751 | - if(array_key_exists('group_by',$query_params)){ |
|
2752 | - if(is_array($query_params['group_by'])){ |
|
2751 | + if (array_key_exists('group_by', $query_params)) { |
|
2752 | + if (is_array($query_params['group_by'])) { |
|
2753 | 2753 | //it's an array, so assume we'll be grouping by a bunch of stuff |
2754 | 2754 | $group_by_array = array(); |
2755 | - foreach($query_params['group_by'] as $field_name_to_group_by){ |
|
2755 | + foreach ($query_params['group_by'] as $field_name_to_group_by) { |
|
2756 | 2756 | $group_by_array[] = $this->_deduce_column_name_from_query_param($field_name_to_group_by); |
2757 | 2757 | } |
2758 | - $query_object->set_group_by_sql(" GROUP BY ".implode(", ",$group_by_array)); |
|
2759 | - }elseif( ! empty ( $query_params['group_by'] )){ |
|
2758 | + $query_object->set_group_by_sql(" GROUP BY ".implode(", ", $group_by_array)); |
|
2759 | + }elseif ( ! empty ($query_params['group_by'])) { |
|
2760 | 2760 | $query_object->set_group_by_sql(" GROUP BY ".$this->_deduce_column_name_from_query_param($query_params['group_by'])); |
2761 | 2761 | } |
2762 | 2762 | } |
2763 | 2763 | //set having |
2764 | - if(array_key_exists('having',$query_params) && $query_params['having']){ |
|
2765 | - $query_object->set_having_sql( $this->_construct_having_clause($query_params['having'])); |
|
2764 | + if (array_key_exists('having', $query_params) && $query_params['having']) { |
|
2765 | + $query_object->set_having_sql($this->_construct_having_clause($query_params['having'])); |
|
2766 | 2766 | } |
2767 | 2767 | |
2768 | 2768 | //now, just verify they didn't pass anything wack |
2769 | - foreach($query_params as $query_key => $query_value){ |
|
2770 | - if( ! in_array($query_key,$this->_allowed_query_params,true)){ |
|
2769 | + foreach ($query_params as $query_key => $query_value) { |
|
2770 | + if ( ! in_array($query_key, $this->_allowed_query_params, true)) { |
|
2771 | 2771 | throw new EE_Error( |
2772 | 2772 | sprintf( |
2773 | - __("You passed %s as a query parameter to %s, which is illegal! The allowed query parameters are %s",'event_espresso'), |
|
2773 | + __("You passed %s as a query parameter to %s, which is illegal! The allowed query parameters are %s", 'event_espresso'), |
|
2774 | 2774 | $query_key, |
2775 | 2775 | get_class($this), |
2776 | 2776 | // print_r( $this->_allowed_query_params, TRUE ) |
2777 | - implode( ',', $this->_allowed_query_params ) |
|
2777 | + implode(',', $this->_allowed_query_params) |
|
2778 | 2778 | ) |
2779 | 2779 | ); |
2780 | 2780 | } |
2781 | 2781 | } |
2782 | 2782 | $main_model_join_sql = $query_object->get_main_model_join_sql(); |
2783 | - if ( empty( $main_model_join_sql ) ) |
|
2783 | + if (empty($main_model_join_sql)) |
|
2784 | 2784 | $query_object->set_main_model_join_sql($this->_construct_internal_join()); |
2785 | 2785 | return $query_object; |
2786 | 2786 | } |
@@ -2791,17 +2791,17 @@ discard block |
||
2791 | 2791 | * @param string $context one of EEM_Base::valid_cap_contexts() |
2792 | 2792 | * @return array like EEM_Base::get_all() 's $query_params[0] |
2793 | 2793 | */ |
2794 | - public function caps_where_conditions( $context = self::caps_read ) { |
|
2795 | - EEM_Base::verify_is_valid_cap_context( $context ); |
|
2794 | + public function caps_where_conditions($context = self::caps_read) { |
|
2795 | + EEM_Base::verify_is_valid_cap_context($context); |
|
2796 | 2796 | $cap_where_conditions = array(); |
2797 | - $cap_restrictions = $this->caps_missing( $context ); |
|
2797 | + $cap_restrictions = $this->caps_missing($context); |
|
2798 | 2798 | /** |
2799 | 2799 | * @var $cap_restrictions EE_Default_Where_Conditions[] |
2800 | 2800 | */ |
2801 | - foreach( $cap_restrictions as $cap => $restriction_if_no_cap ) { |
|
2802 | - $cap_where_conditions = array_replace_recursive( $cap_where_conditions, $restriction_if_no_cap->get_default_where_conditions() ); |
|
2801 | + foreach ($cap_restrictions as $cap => $restriction_if_no_cap) { |
|
2802 | + $cap_where_conditions = array_replace_recursive($cap_where_conditions, $restriction_if_no_cap->get_default_where_conditions()); |
|
2803 | 2803 | } |
2804 | - return apply_filters( 'FHEE__EEM_Base__caps_where_conditions__return', $cap_where_conditions, $this, $context, $cap_restrictions ); |
|
2804 | + return apply_filters('FHEE__EEM_Base__caps_where_conditions__return', $cap_where_conditions, $this, $context, $cap_restrictions); |
|
2805 | 2805 | } |
2806 | 2806 | |
2807 | 2807 | /** |
@@ -2811,11 +2811,11 @@ discard block |
||
2811 | 2811 | * @return string either ASC, asc, DESC or desc |
2812 | 2812 | * @throws EE_Error |
2813 | 2813 | */ |
2814 | - private function _extract_order($should_be_order_string){ |
|
2815 | - if(in_array($should_be_order_string, $this->_allowed_order_values)){ |
|
2814 | + private function _extract_order($should_be_order_string) { |
|
2815 | + if (in_array($should_be_order_string, $this->_allowed_order_values)) { |
|
2816 | 2816 | return $should_be_order_string; |
2817 | - }else{ |
|
2818 | - throw new EE_Error(sprintf(__("While performing a query on '%s', tried to use '%s' as an order parameter. ", "event_espresso"),get_class($this),$should_be_order_string)); |
|
2817 | + } else { |
|
2818 | + throw new EE_Error(sprintf(__("While performing a query on '%s', tried to use '%s' as an order parameter. ", "event_espresso"), get_class($this), $should_be_order_string)); |
|
2819 | 2819 | } |
2820 | 2820 | } |
2821 | 2821 | |
@@ -2833,7 +2833,7 @@ discard block |
||
2833 | 2833 | * @throws EE_Error |
2834 | 2834 | * @return array like $query_params[0], see EEM_Base::get_all for documentation |
2835 | 2835 | */ |
2836 | - private function _get_default_where_conditions_for_models_in_query(EE_Model_Query_Info_Carrier $query_info_carrier,$use_default_where_conditions = 'all',$where_query_params = array()){ |
|
2836 | + private function _get_default_where_conditions_for_models_in_query(EE_Model_Query_Info_Carrier $query_info_carrier, $use_default_where_conditions = 'all', $where_query_params = array()) { |
|
2837 | 2837 | $allowed_used_default_where_conditions_values = array( |
2838 | 2838 | 'all', |
2839 | 2839 | 'this_model_only', |
@@ -2841,23 +2841,23 @@ discard block |
||
2841 | 2841 | 'minimum', |
2842 | 2842 | 'none' |
2843 | 2843 | ); |
2844 | - if( ! in_array($use_default_where_conditions,$allowed_used_default_where_conditions_values)){ |
|
2845 | - throw new EE_Error(sprintf(__("You passed an invalid value to the query parameter 'default_where_conditions' of '%s'. Allowed values are %s", "event_espresso"),$use_default_where_conditions,implode(", ",$allowed_used_default_where_conditions_values))); |
|
2844 | + if ( ! in_array($use_default_where_conditions, $allowed_used_default_where_conditions_values)) { |
|
2845 | + throw new EE_Error(sprintf(__("You passed an invalid value to the query parameter 'default_where_conditions' of '%s'. Allowed values are %s", "event_espresso"), $use_default_where_conditions, implode(", ", $allowed_used_default_where_conditions_values))); |
|
2846 | 2846 | } |
2847 | - if( in_array($use_default_where_conditions, array('all','this_model_only')) ){ |
|
2847 | + if (in_array($use_default_where_conditions, array('all', 'this_model_only'))) { |
|
2848 | 2848 | $universal_query_params = $this->_get_default_where_conditions(); |
2849 | - }elseif( $use_default_where_conditions == 'minimum' ) { |
|
2849 | + }elseif ($use_default_where_conditions == 'minimum') { |
|
2850 | 2850 | $universal_query_params = $this->_get_minimum_where_conditions(); |
2851 | - }else{ |
|
2851 | + } else { |
|
2852 | 2852 | $universal_query_params = array(); |
2853 | 2853 | } |
2854 | 2854 | |
2855 | - if(in_array($use_default_where_conditions,array('all', 'minimum', 'other_models_only'))){ |
|
2856 | - foreach($query_info_carrier->get_model_names_included() as $model_relation_path => $model_name){ |
|
2855 | + if (in_array($use_default_where_conditions, array('all', 'minimum', 'other_models_only'))) { |
|
2856 | + foreach ($query_info_carrier->get_model_names_included() as $model_relation_path => $model_name) { |
|
2857 | 2857 | $related_model = $this->get_related_model_obj($model_name); |
2858 | - if( $use_default_where_conditions == 'minimum' ) { |
|
2858 | + if ($use_default_where_conditions == 'minimum') { |
|
2859 | 2859 | $related_model_universal_where_params = $related_model->_get_minimum_where_conditions($model_relation_path); |
2860 | - }else{ |
|
2860 | + } else { |
|
2861 | 2861 | $related_model_universal_where_params = $related_model->_get_default_where_conditions($model_relation_path); |
2862 | 2862 | } |
2863 | 2863 | |
@@ -2884,22 +2884,22 @@ discard block |
||
2884 | 2884 | * @param string $model_relation_path like 'Transaction.Payment.' |
2885 | 2885 | * @return array like EEM_Base::get_all's $query_params[0] |
2886 | 2886 | */ |
2887 | - private function _override_defaults_or_make_null_friendly($default_where_conditions,$provided_where_conditions,$model,$model_relation_path){ |
|
2887 | + private function _override_defaults_or_make_null_friendly($default_where_conditions, $provided_where_conditions, $model, $model_relation_path) { |
|
2888 | 2888 | $null_friendly_where_conditions = array(); |
2889 | 2889 | $none_overridden = true; |
2890 | 2890 | $or_condition_key_for_defaults = 'OR*'.get_class($model); |
2891 | 2891 | |
2892 | - foreach($default_where_conditions as $key => $val){ |
|
2893 | - if( isset($provided_where_conditions[$key])){ |
|
2892 | + foreach ($default_where_conditions as $key => $val) { |
|
2893 | + if (isset($provided_where_conditions[$key])) { |
|
2894 | 2894 | $none_overridden = false; |
2895 | - }else{ |
|
2895 | + } else { |
|
2896 | 2896 | $null_friendly_where_conditions[$or_condition_key_for_defaults]['AND'][$key] = $val; |
2897 | 2897 | } |
2898 | 2898 | } |
2899 | - if( $none_overridden && $default_where_conditions){ |
|
2900 | - if($model->has_primary_key_field()){ |
|
2899 | + if ($none_overridden && $default_where_conditions) { |
|
2900 | + if ($model->has_primary_key_field()) { |
|
2901 | 2901 | $null_friendly_where_conditions[$or_condition_key_for_defaults][$model_relation_path.".".$model->primary_key_name()] = array('IS NULL'); |
2902 | - }else{ |
|
2902 | + } else { |
|
2903 | 2903 | //@todo NO PK, use other defaults |
2904 | 2904 | } |
2905 | 2905 | } |
@@ -2914,8 +2914,8 @@ discard block |
||
2914 | 2914 | * @param string $model_relation_path eg, path from Event to Payment is "Registration.Transaction.Payment." |
2915 | 2915 | * @return array like EEM_Base::get_all's $query_params[0] (where conditions) |
2916 | 2916 | */ |
2917 | - protected function _get_default_where_conditions($model_relation_path = null){ |
|
2918 | - if ( $this->_ignore_where_strategy ) |
|
2917 | + protected function _get_default_where_conditions($model_relation_path = null) { |
|
2918 | + if ($this->_ignore_where_strategy) |
|
2919 | 2919 | return array(); |
2920 | 2920 | |
2921 | 2921 | return $this->_default_where_conditions_strategy->get_default_where_conditions($model_relation_path); |
@@ -2930,8 +2930,8 @@ discard block |
||
2930 | 2930 | * @param string $model_relation_path eg, path from Event to Payment is "Registration.Transaction.Payment." |
2931 | 2931 | * @return array like EEM_Base::get_all's $query_params[0] (where conditions) |
2932 | 2932 | */ |
2933 | - protected function _get_minimum_where_conditions($model_relation_path = null){ |
|
2934 | - if ( $this->_ignore_where_strategy ) |
|
2933 | + protected function _get_minimum_where_conditions($model_relation_path = null) { |
|
2934 | + if ($this->_ignore_where_strategy) |
|
2935 | 2935 | return array(); |
2936 | 2936 | |
2937 | 2937 | return $this->_minimum_where_conditions_strategy->get_default_where_conditions($model_relation_path); |
@@ -2942,13 +2942,13 @@ discard block |
||
2942 | 2942 | * @param EE_Model_Query_Info_Carrier $model_query_info |
2943 | 2943 | * @return string |
2944 | 2944 | */ |
2945 | - private function _construct_default_select_sql(EE_Model_Query_Info_Carrier $model_query_info){ |
|
2945 | + private function _construct_default_select_sql(EE_Model_Query_Info_Carrier $model_query_info) { |
|
2946 | 2946 | $selects = $this->_get_columns_to_select_for_this_model(); |
2947 | - foreach($model_query_info->get_model_names_included() as $model_relation_chain => $name_of_other_model_included){ |
|
2947 | + foreach ($model_query_info->get_model_names_included() as $model_relation_chain => $name_of_other_model_included) { |
|
2948 | 2948 | $other_model_included = $this->get_related_model_obj($name_of_other_model_included); |
2949 | 2949 | $selects = array_merge($selects, $other_model_included->_get_columns_to_select_for_this_model($model_relation_chain)); |
2950 | 2950 | } |
2951 | - return implode(", ",$selects); |
|
2951 | + return implode(", ", $selects); |
|
2952 | 2952 | } |
2953 | 2953 | |
2954 | 2954 | /** |
@@ -2957,19 +2957,19 @@ discard block |
||
2957 | 2957 | * @param string $model_relation_chain like 'Question.Question_Group.Event' |
2958 | 2958 | * @return array numerically indexed, values are columns to select and rename, eg "Event.ID AS 'Event.ID'" |
2959 | 2959 | */ |
2960 | - public function _get_columns_to_select_for_this_model($model_relation_chain = ''){ |
|
2960 | + public function _get_columns_to_select_for_this_model($model_relation_chain = '') { |
|
2961 | 2961 | $fields = $this->field_settings(); |
2962 | 2962 | $selects = array(); |
2963 | 2963 | $table_alias_with_model_relation_chain_prefix = EE_Model_Parser::extract_table_alias_model_relation_chain_prefix($model_relation_chain, $this->get_this_model_name()); |
2964 | - foreach($fields as $field_obj){ |
|
2965 | - $selects[] = $table_alias_with_model_relation_chain_prefix . $field_obj->get_table_alias().".".$field_obj->get_table_column()." AS '".$table_alias_with_model_relation_chain_prefix.$field_obj->get_table_alias().".".$field_obj->get_table_column()."'"; |
|
2964 | + foreach ($fields as $field_obj) { |
|
2965 | + $selects[] = $table_alias_with_model_relation_chain_prefix.$field_obj->get_table_alias().".".$field_obj->get_table_column()." AS '".$table_alias_with_model_relation_chain_prefix.$field_obj->get_table_alias().".".$field_obj->get_table_column()."'"; |
|
2966 | 2966 | } |
2967 | 2967 | //make sure we are also getting the PKs of each table |
2968 | 2968 | $tables = $this->get_tables(); |
2969 | - if(count($tables) > 1){ |
|
2970 | - foreach($tables as $table_obj){ |
|
2971 | - $qualified_pk_column = $table_alias_with_model_relation_chain_prefix . $table_obj->get_fully_qualified_pk_column(); |
|
2972 | - if( ! in_array($qualified_pk_column,$selects)){ |
|
2969 | + if (count($tables) > 1) { |
|
2970 | + foreach ($tables as $table_obj) { |
|
2971 | + $qualified_pk_column = $table_alias_with_model_relation_chain_prefix.$table_obj->get_fully_qualified_pk_column(); |
|
2972 | + if ( ! in_array($qualified_pk_column, $selects)) { |
|
2973 | 2973 | $selects[] = "$qualified_pk_column AS '$qualified_pk_column'"; |
2974 | 2974 | } |
2975 | 2975 | } |
@@ -2993,66 +2993,66 @@ discard block |
||
2993 | 2993 | * @throws EE_Error |
2994 | 2994 | * @return void only modifies the EEM_Related_Model_Info_Carrier passed into it |
2995 | 2995 | */ |
2996 | - private function _extract_related_model_info_from_query_param( $query_param, EE_Model_Query_Info_Carrier $passed_in_query_info, $query_param_type, $original_query_param = NULL ){ |
|
2997 | - if($original_query_param == NULL){ |
|
2996 | + private function _extract_related_model_info_from_query_param($query_param, EE_Model_Query_Info_Carrier $passed_in_query_info, $query_param_type, $original_query_param = NULL) { |
|
2997 | + if ($original_query_param == NULL) { |
|
2998 | 2998 | $original_query_param = $query_param; |
2999 | 2999 | } |
3000 | 3000 | $query_param = $this->_remove_stars_and_anything_after_from_condition_query_param_key($query_param); |
3001 | 3001 | /** @var $allow_logic_query_params bool whether or not to allow logic_query_params like 'NOT','OR', or 'AND' */ |
3002 | - $allow_logic_query_params = in_array($query_param_type,array('where','having')); |
|
3003 | - $allow_fields = in_array($query_param_type,array('where','having','order_by','group_by','order')); |
|
3002 | + $allow_logic_query_params = in_array($query_param_type, array('where', 'having')); |
|
3003 | + $allow_fields = in_array($query_param_type, array('where', 'having', 'order_by', 'group_by', 'order')); |
|
3004 | 3004 | //check to see if we have a field on this model |
3005 | 3005 | $this_model_fields = $this->field_settings(true); |
3006 | - if(array_key_exists($query_param,$this_model_fields)){ |
|
3007 | - if($allow_fields){ |
|
3006 | + if (array_key_exists($query_param, $this_model_fields)) { |
|
3007 | + if ($allow_fields) { |
|
3008 | 3008 | return; |
3009 | - }else{ |
|
3009 | + } else { |
|
3010 | 3010 | throw new EE_Error(sprintf(__("Using a field name (%s) on model %s is not allowed on this query param type '%s'. Original query param was %s", "event_espresso"), |
3011 | - $query_param,get_class($this),$query_param_type,$original_query_param)); |
|
3011 | + $query_param, get_class($this), $query_param_type, $original_query_param)); |
|
3012 | 3012 | } |
3013 | 3013 | } |
3014 | 3014 | //check if this is a special logic query param |
3015 | - elseif(in_array($query_param, $this->_logic_query_param_keys, TRUE)){ |
|
3016 | - if($allow_logic_query_params){ |
|
3015 | + elseif (in_array($query_param, $this->_logic_query_param_keys, TRUE)) { |
|
3016 | + if ($allow_logic_query_params) { |
|
3017 | 3017 | return; |
3018 | - }else{ |
|
3018 | + } else { |
|
3019 | 3019 | throw new EE_Error( |
3020 | 3020 | sprintf( |
3021 | - __( 'Logic query params ("%1$s") are being used incorrectly with the following query param ("%2$s") on model %3$s. %4$sAdditional Info:%4$s%5$s', 'event_espresso' ), |
|
3022 | - implode( '", "', $this->_logic_query_param_keys ), |
|
3023 | - $query_param , |
|
3024 | - get_class( $this ), |
|
3021 | + __('Logic query params ("%1$s") are being used incorrectly with the following query param ("%2$s") on model %3$s. %4$sAdditional Info:%4$s%5$s', 'event_espresso'), |
|
3022 | + implode('", "', $this->_logic_query_param_keys), |
|
3023 | + $query_param, |
|
3024 | + get_class($this), |
|
3025 | 3025 | '<br />', |
3026 | - "\t" . ' $passed_in_query_info = <pre>' . print_r( $passed_in_query_info, TRUE ) . '</pre>' . "\n\t" . ' $query_param_type = ' . $query_param_type . "\n\t" . ' $original_query_param = ' . $original_query_param |
|
3026 | + "\t".' $passed_in_query_info = <pre>'.print_r($passed_in_query_info, TRUE).'</pre>'."\n\t".' $query_param_type = '.$query_param_type."\n\t".' $original_query_param = '.$original_query_param |
|
3027 | 3027 | ) |
3028 | 3028 | ); |
3029 | 3029 | } |
3030 | 3030 | } |
3031 | 3031 | |
3032 | 3032 | //check if it's a custom selection |
3033 | - elseif(array_key_exists($query_param,$this->_custom_selections)){ |
|
3033 | + elseif (array_key_exists($query_param, $this->_custom_selections)) { |
|
3034 | 3034 | return; |
3035 | 3035 | } |
3036 | 3036 | |
3037 | 3037 | //check if has a model name at the beginning |
3038 | 3038 | //and |
3039 | 3039 | //check if it's a field on a related model |
3040 | - foreach($this->_model_relations as $valid_related_model_name=>$relation_obj){ |
|
3041 | - if(strpos($query_param, $valid_related_model_name.".") === 0){ |
|
3042 | - $this->_add_join_to_model($valid_related_model_name, $passed_in_query_info,$original_query_param); |
|
3040 | + foreach ($this->_model_relations as $valid_related_model_name=>$relation_obj) { |
|
3041 | + if (strpos($query_param, $valid_related_model_name.".") === 0) { |
|
3042 | + $this->_add_join_to_model($valid_related_model_name, $passed_in_query_info, $original_query_param); |
|
3043 | 3043 | $query_param = substr($query_param, strlen($valid_related_model_name.".")); |
3044 | - if($query_param == ''){ |
|
3044 | + if ($query_param == '') { |
|
3045 | 3045 | //nothing left to $query_param |
3046 | 3046 | //we should actually end in a field name, not a model like this! |
3047 | 3047 | throw new EE_Error(sprintf(__("Query param '%s' (of type %s on model %s) shouldn't end on a period (.) ", "event_espresso"), |
3048 | - $query_param,$query_param_type,get_class($this),$valid_related_model_name)); |
|
3049 | - }else{ |
|
3048 | + $query_param, $query_param_type, get_class($this), $valid_related_model_name)); |
|
3049 | + } else { |
|
3050 | 3050 | $related_model_obj = $this->get_related_model_obj($valid_related_model_name); |
3051 | 3051 | $related_model_obj->_extract_related_model_info_from_query_param($query_param, $passed_in_query_info, $query_param_type, $original_query_param); |
3052 | 3052 | return; |
3053 | 3053 | } |
3054 | - }elseif($query_param == $valid_related_model_name){ |
|
3055 | - $this->_add_join_to_model($valid_related_model_name, $passed_in_query_info,$original_query_param); |
|
3054 | + }elseif ($query_param == $valid_related_model_name) { |
|
3055 | + $this->_add_join_to_model($valid_related_model_name, $passed_in_query_info, $original_query_param); |
|
3056 | 3056 | return; |
3057 | 3057 | } |
3058 | 3058 | } |
@@ -3062,7 +3062,7 @@ discard block |
||
3062 | 3062 | //and we previously confirmed it wasn't a logic query param or field on the current model |
3063 | 3063 | //it's wack, that's what it is |
3064 | 3064 | throw new EE_Error(sprintf(__("There is no model named '%s' related to %s. Query param type is %s and original query param is %s", "event_espresso"), |
3065 | - $query_param,get_class($this),$query_param_type,$original_query_param)); |
|
3065 | + $query_param, get_class($this), $query_param_type, $original_query_param)); |
|
3066 | 3066 | |
3067 | 3067 | } |
3068 | 3068 | |
@@ -3079,26 +3079,26 @@ discard block |
||
3079 | 3079 | * what models to prepend onto its default query params or in case it wants to rename tables (in case there are multiple joins to the same table) |
3080 | 3080 | * @return void |
3081 | 3081 | */ |
3082 | - private function _add_join_to_model($model_name, EE_Model_Query_Info_Carrier $passed_in_query_info,$original_query_param){ |
|
3082 | + private function _add_join_to_model($model_name, EE_Model_Query_Info_Carrier $passed_in_query_info, $original_query_param) { |
|
3083 | 3083 | $relation_obj = $this->related_settings_for($model_name); |
3084 | 3084 | |
3085 | 3085 | $model_relation_chain = EE_Model_Parser::extract_model_relation_chain($model_name, $original_query_param); |
3086 | 3086 | //check if the relation is HABTM, because then we're essentially doing two joins |
3087 | 3087 | //If so, join first to the JOIN table, and add its data types, and then continue as normal |
3088 | - if($relation_obj instanceof EE_HABTM_Relation){ |
|
3088 | + if ($relation_obj instanceof EE_HABTM_Relation) { |
|
3089 | 3089 | $join_model_obj = $relation_obj->get_join_model(); |
3090 | 3090 | //replace the model specified with the join model for this relation chain, whi |
3091 | 3091 | $relation_chain_to_join_model = EE_Model_Parser::replace_model_name_with_join_model_name_in_model_relation_chain($model_name, $join_model_obj->get_this_model_name(), $model_relation_chain); |
3092 | 3092 | $new_query_info = new EE_Model_Query_Info_Carrier( |
3093 | 3093 | array($relation_chain_to_join_model => $join_model_obj->get_this_model_name()), |
3094 | 3094 | $relation_obj->get_join_to_intermediate_model_statement($relation_chain_to_join_model)); |
3095 | - $passed_in_query_info->merge( $new_query_info ); |
|
3095 | + $passed_in_query_info->merge($new_query_info); |
|
3096 | 3096 | } |
3097 | 3097 | //now just join to the other table pointed to by the relation object, and add its data types |
3098 | 3098 | $new_query_info = new EE_Model_Query_Info_Carrier( |
3099 | 3099 | array($model_relation_chain=>$model_name), |
3100 | 3100 | $relation_obj->get_join_statement($model_relation_chain)); |
3101 | - $passed_in_query_info->merge( $new_query_info ); |
|
3101 | + $passed_in_query_info->merge($new_query_info); |
|
3102 | 3102 | } |
3103 | 3103 | |
3104 | 3104 | |
@@ -3107,11 +3107,11 @@ discard block |
||
3107 | 3107 | * @param array $where_params like EEM_Base::get_all |
3108 | 3108 | * @return string of SQL |
3109 | 3109 | */ |
3110 | - private function _construct_where_clause($where_params){ |
|
3110 | + private function _construct_where_clause($where_params) { |
|
3111 | 3111 | $SQL = $this->_construct_condition_clause_recursive($where_params, ' AND '); |
3112 | - if($SQL){ |
|
3113 | - return " WHERE ". $SQL; |
|
3114 | - }else{ |
|
3112 | + if ($SQL) { |
|
3113 | + return " WHERE ".$SQL; |
|
3114 | + } else { |
|
3115 | 3115 | return ''; |
3116 | 3116 | } |
3117 | 3117 | } |
@@ -3122,11 +3122,11 @@ discard block |
||
3122 | 3122 | * @param array $having_params |
3123 | 3123 | * @return string |
3124 | 3124 | */ |
3125 | - private function _construct_having_clause($having_params){ |
|
3125 | + private function _construct_having_clause($having_params) { |
|
3126 | 3126 | $SQL = $this->_construct_condition_clause_recursive($having_params, ' AND '); |
3127 | - if($SQL){ |
|
3128 | - return " HAVING ". $SQL; |
|
3129 | - }else{ |
|
3127 | + if ($SQL) { |
|
3128 | + return " HAVING ".$SQL; |
|
3129 | + } else { |
|
3130 | 3130 | return ''; |
3131 | 3131 | } |
3132 | 3132 | |
@@ -3140,17 +3140,17 @@ discard block |
||
3140 | 3140 | * @return EE_Model_Field_Base |
3141 | 3141 | * @throws EE_Error |
3142 | 3142 | */ |
3143 | - protected function _get_field_on_model($field_name,$model_name){ |
|
3143 | + protected function _get_field_on_model($field_name, $model_name) { |
|
3144 | 3144 | $model_class = 'EEM_'.$model_name; |
3145 | 3145 | $model_filepath = $model_class.".model.php"; |
3146 | - EE_Registry::instance()->load_helper( 'File' ); |
|
3147 | - if ( is_readable($model_filepath)){ |
|
3146 | + EE_Registry::instance()->load_helper('File'); |
|
3147 | + if (is_readable($model_filepath)) { |
|
3148 | 3148 | require_once($model_filepath); |
3149 | - $model_instance=call_user_func($model_name."::instance"); |
|
3149 | + $model_instance = call_user_func($model_name."::instance"); |
|
3150 | 3150 | /* @var $model_instance EEM_Base */ |
3151 | 3151 | return $model_instance->field_settings_for($field_name); |
3152 | - }else{ |
|
3153 | - throw new EE_Error(sprintf(__('No model named %s exists, with classname %s and filepath %s','event_espresso'),$model_name,$model_class,$model_filepath)); |
|
3152 | + } else { |
|
3153 | + throw new EE_Error(sprintf(__('No model named %s exists, with classname %s and filepath %s', 'event_espresso'), $model_name, $model_class, $model_filepath)); |
|
3154 | 3154 | } |
3155 | 3155 | } |
3156 | 3156 | |
@@ -3163,43 +3163,43 @@ discard block |
||
3163 | 3163 | * @throws EE_Error |
3164 | 3164 | * @return string of SQL |
3165 | 3165 | */ |
3166 | - private function _construct_condition_clause_recursive($where_params, $glue = ' AND'){ |
|
3167 | - $where_clauses=array(); |
|
3168 | - foreach($where_params as $query_param => $op_and_value_or_sub_condition){ |
|
3169 | - $query_param = $this->_remove_stars_and_anything_after_from_condition_query_param_key($query_param);//str_replace("*",'',$query_param); |
|
3170 | - if(in_array($query_param,$this->_logic_query_param_keys)){ |
|
3171 | - switch($query_param){ |
|
3166 | + private function _construct_condition_clause_recursive($where_params, $glue = ' AND') { |
|
3167 | + $where_clauses = array(); |
|
3168 | + foreach ($where_params as $query_param => $op_and_value_or_sub_condition) { |
|
3169 | + $query_param = $this->_remove_stars_and_anything_after_from_condition_query_param_key($query_param); //str_replace("*",'',$query_param); |
|
3170 | + if (in_array($query_param, $this->_logic_query_param_keys)) { |
|
3171 | + switch ($query_param) { |
|
3172 | 3172 | case 'not': |
3173 | 3173 | case 'NOT': |
3174 | - $where_clauses[] = "! (". $this->_construct_condition_clause_recursive($op_and_value_or_sub_condition, $glue).")"; |
|
3174 | + $where_clauses[] = "! (".$this->_construct_condition_clause_recursive($op_and_value_or_sub_condition, $glue).")"; |
|
3175 | 3175 | break; |
3176 | 3176 | case 'and': |
3177 | 3177 | case 'AND': |
3178 | - $where_clauses[] = " (". $this->_construct_condition_clause_recursive($op_and_value_or_sub_condition, ' AND ') .")"; |
|
3178 | + $where_clauses[] = " (".$this->_construct_condition_clause_recursive($op_and_value_or_sub_condition, ' AND ').")"; |
|
3179 | 3179 | break; |
3180 | 3180 | case 'or': |
3181 | 3181 | case 'OR': |
3182 | - $where_clauses[] = " (". $this->_construct_condition_clause_recursive($op_and_value_or_sub_condition, ' OR ') .")"; |
|
3182 | + $where_clauses[] = " (".$this->_construct_condition_clause_recursive($op_and_value_or_sub_condition, ' OR ').")"; |
|
3183 | 3183 | break; |
3184 | 3184 | } |
3185 | - }else{ |
|
3185 | + } else { |
|
3186 | 3186 | $field_obj = $this->_deduce_field_from_query_param($query_param); |
3187 | 3187 | |
3188 | 3188 | //if it's not a normal field, maybe it's a custom selection? |
3189 | - if( ! $field_obj){ |
|
3190 | - if(isset( $this->_custom_selections[$query_param][1])){ |
|
3189 | + if ( ! $field_obj) { |
|
3190 | + if (isset($this->_custom_selections[$query_param][1])) { |
|
3191 | 3191 | $field_obj = $this->_custom_selections[$query_param][1]; |
3192 | - }else{ |
|
3193 | - throw new EE_Error(sprintf(__("%s is neither a valid model field name, nor a custom selection", "event_espresso"),$query_param)); |
|
3192 | + } else { |
|
3193 | + throw new EE_Error(sprintf(__("%s is neither a valid model field name, nor a custom selection", "event_espresso"), $query_param)); |
|
3194 | 3194 | } |
3195 | 3195 | } |
3196 | 3196 | $op_and_value_sql = $this->_construct_op_and_value($op_and_value_or_sub_condition, $field_obj); |
3197 | - $where_clauses[]=$this->_deduce_column_name_from_query_param($query_param).SP.$op_and_value_sql; |
|
3197 | + $where_clauses[] = $this->_deduce_column_name_from_query_param($query_param).SP.$op_and_value_sql; |
|
3198 | 3198 | } |
3199 | 3199 | } |
3200 | - if($where_clauses){ |
|
3201 | - $SQL = implode($glue,$where_clauses); |
|
3202 | - }else{ |
|
3200 | + if ($where_clauses) { |
|
3201 | + $SQL = implode($glue, $where_clauses); |
|
3202 | + } else { |
|
3203 | 3203 | $SQL = ''; |
3204 | 3204 | } |
3205 | 3205 | return $SQL; |
@@ -3213,18 +3213,18 @@ discard block |
||
3213 | 3213 | * @throws EE_Error |
3214 | 3214 | * @return string table alias and column name for SQL, eg "Transaction.TXN_ID" |
3215 | 3215 | */ |
3216 | - private function _deduce_column_name_from_query_param($query_param){ |
|
3216 | + private function _deduce_column_name_from_query_param($query_param) { |
|
3217 | 3217 | $field = $this->_deduce_field_from_query_param($query_param); |
3218 | 3218 | |
3219 | - if( $field ){ |
|
3220 | - $table_alias_prefix = EE_Model_Parser::extract_table_alias_model_relation_chain_from_query_param( $field->get_model_name(), $query_param ); |
|
3221 | - return $table_alias_prefix . $field->get_qualified_column(); |
|
3222 | - }elseif(array_key_exists($query_param,$this->_custom_selections)){ |
|
3219 | + if ($field) { |
|
3220 | + $table_alias_prefix = EE_Model_Parser::extract_table_alias_model_relation_chain_from_query_param($field->get_model_name(), $query_param); |
|
3221 | + return $table_alias_prefix.$field->get_qualified_column(); |
|
3222 | + }elseif (array_key_exists($query_param, $this->_custom_selections)) { |
|
3223 | 3223 | //maybe it's custom selection item? |
3224 | 3224 | //if so, just use it as the "column name" |
3225 | 3225 | return $query_param; |
3226 | - }else{ |
|
3227 | - throw new EE_Error(sprintf(__("%s is not a valid field on this model, nor a custom selection (%s)", "event_espresso"),$query_param,implode(",",$this->_custom_selections))); |
|
3226 | + } else { |
|
3227 | + throw new EE_Error(sprintf(__("%s is not a valid field on this model, nor a custom selection (%s)", "event_espresso"), $query_param, implode(",", $this->_custom_selections))); |
|
3228 | 3228 | } |
3229 | 3229 | } |
3230 | 3230 | |
@@ -3236,11 +3236,11 @@ discard block |
||
3236 | 3236 | * @param string $condition_query_param_key |
3237 | 3237 | * @return string |
3238 | 3238 | */ |
3239 | - private function _remove_stars_and_anything_after_from_condition_query_param_key($condition_query_param_key){ |
|
3239 | + private function _remove_stars_and_anything_after_from_condition_query_param_key($condition_query_param_key) { |
|
3240 | 3240 | $pos_of_star = strpos($condition_query_param_key, '*'); |
3241 | - if($pos_of_star === FALSE){ |
|
3241 | + if ($pos_of_star === FALSE) { |
|
3242 | 3242 | return $condition_query_param_key; |
3243 | - }else{ |
|
3243 | + } else { |
|
3244 | 3244 | $condition_query_param_sans_star = substr($condition_query_param_key, 0, $pos_of_star); |
3245 | 3245 | return $condition_query_param_sans_star; |
3246 | 3246 | } |
@@ -3255,54 +3255,54 @@ discard block |
||
3255 | 3255 | * @throws EE_Error |
3256 | 3256 | * @return string |
3257 | 3257 | */ |
3258 | - private function _construct_op_and_value($op_and_value, $field_obj){ |
|
3259 | - if(is_array( $op_and_value )){ |
|
3258 | + private function _construct_op_and_value($op_and_value, $field_obj) { |
|
3259 | + if (is_array($op_and_value)) { |
|
3260 | 3260 | $operator = isset($op_and_value[0]) ? $this->_prepare_operator_for_sql($op_and_value[0]) : null; |
3261 | - if( ! $operator){ |
|
3261 | + if ( ! $operator) { |
|
3262 | 3262 | $php_array_like_string = array(); |
3263 | - foreach($op_and_value as $key => $value){ |
|
3263 | + foreach ($op_and_value as $key => $value) { |
|
3264 | 3264 | $php_array_like_string[] = "$key=>$value"; |
3265 | 3265 | } |
3266 | - throw new EE_Error(sprintf(__("You setup a query parameter like you were going to specify an operator, but didn't. You provided '(%s)', but the operator should be at array key index 0 (eg array('>',32))", "event_espresso"), implode(",",$php_array_like_string))); |
|
3266 | + throw new EE_Error(sprintf(__("You setup a query parameter like you were going to specify an operator, but didn't. You provided '(%s)', but the operator should be at array key index 0 (eg array('>',32))", "event_espresso"), implode(",", $php_array_like_string))); |
|
3267 | 3267 | } |
3268 | 3268 | $value = isset($op_and_value[1]) ? $op_and_value[1] : null; |
3269 | - }else{ |
|
3269 | + } else { |
|
3270 | 3270 | $operator = '='; |
3271 | 3271 | $value = $op_and_value; |
3272 | 3272 | } |
3273 | 3273 | |
3274 | 3274 | //check to see if the value is actually another field |
3275 | - if(is_array($op_and_value) && isset($op_and_value[2]) && $op_and_value[2] == true){ |
|
3275 | + if (is_array($op_and_value) && isset($op_and_value[2]) && $op_and_value[2] == true) { |
|
3276 | 3276 | return $operator.SP.$this->_deduce_column_name_from_query_param($value); |
3277 | - }elseif(in_array($operator, $this->_in_style_operators) && is_array($value)){ |
|
3277 | + }elseif (in_array($operator, $this->_in_style_operators) && is_array($value)) { |
|
3278 | 3278 | //in this case, the value should be an array, or at least a comma-separated list |
3279 | 3279 | //it will need to handle a little differently |
3280 | 3280 | $cleaned_value = $this->_construct_in_value($value, $field_obj); |
3281 | 3281 | //note: $cleaned_value has already been run through $wpdb->prepare() |
3282 | 3282 | return $operator.SP.$cleaned_value; |
3283 | - } elseif( in_array( $operator, $this->_between_style_operators ) && is_array( $value ) ) { |
|
3283 | + } elseif (in_array($operator, $this->_between_style_operators) && is_array($value)) { |
|
3284 | 3284 | //the value should be an array with count of two. |
3285 | - if ( count($value) !== 2 ) |
|
3286 | - throw new EE_Error( sprintf( __("The '%s' operator must be used with an array of values and there must be exactly TWO values in that array.", 'event_espresso'), "BETWEEN" ) ); |
|
3287 | - $cleaned_value = $this->_construct_between_value( $value, $field_obj ); |
|
3285 | + if (count($value) !== 2) |
|
3286 | + throw new EE_Error(sprintf(__("The '%s' operator must be used with an array of values and there must be exactly TWO values in that array.", 'event_espresso'), "BETWEEN")); |
|
3287 | + $cleaned_value = $this->_construct_between_value($value, $field_obj); |
|
3288 | 3288 | return $operator.SP.$cleaned_value; |
3289 | - } elseif( in_array( $operator, $this->_null_style_operators ) ) { |
|
3290 | - if($value != NULL){ |
|
3291 | - throw new EE_Error(sprintf(__("You attempted to give a value (%s) while using a NULL-style operator (%s). That isn't valid", "event_espresso"),$value,$operator)); |
|
3289 | + } elseif (in_array($operator, $this->_null_style_operators)) { |
|
3290 | + if ($value != NULL) { |
|
3291 | + throw new EE_Error(sprintf(__("You attempted to give a value (%s) while using a NULL-style operator (%s). That isn't valid", "event_espresso"), $value, $operator)); |
|
3292 | 3292 | } |
3293 | 3293 | return $operator; |
3294 | - }elseif( $operator == 'LIKE' && ! is_array($value)){ |
|
3294 | + }elseif ($operator == 'LIKE' && ! is_array($value)) { |
|
3295 | 3295 | //if the operator is 'LIKE', we want to allow percent signs (%) and not |
3296 | 3296 | //remove other junk. So just treat it as a string. |
3297 | 3297 | return $operator.SP.$this->_wpdb_prepare_using_field($value, '%s'); |
3298 | - }elseif( ! in_array($operator, $this->_in_style_operators) && ! is_array($value)){ |
|
3299 | - return $operator.SP.$this->_wpdb_prepare_using_field($value,$field_obj); |
|
3300 | - }elseif(in_array($operator, $this->_in_style_operators) && ! is_array($value)){ |
|
3301 | - throw new EE_Error(sprintf(__("Operator '%s' must be used with an array of values, eg 'Registration.REG_ID' => array('%s',array(1,2,3))",'event_espresso'),$operator, $operator)); |
|
3302 | - }elseif( ! in_array($operator, $this->_in_style_operators) && is_array($value)){ |
|
3303 | - throw new EE_Error(sprintf(__("Operator '%s' must be used with a single value, not an array. Eg 'Registration.REG_ID => array('%s',23))",'event_espresso'),$operator,$operator)); |
|
3304 | - }else{ |
|
3305 | - throw new EE_Error(sprintf(__("It appears you've provided some totally invalid query parameters. Operator and value were:'%s', which isn't right at all", "event_espresso"), http_build_query($op_and_value))); |
|
3298 | + }elseif ( ! in_array($operator, $this->_in_style_operators) && ! is_array($value)) { |
|
3299 | + return $operator.SP.$this->_wpdb_prepare_using_field($value, $field_obj); |
|
3300 | + }elseif (in_array($operator, $this->_in_style_operators) && ! is_array($value)) { |
|
3301 | + throw new EE_Error(sprintf(__("Operator '%s' must be used with an array of values, eg 'Registration.REG_ID' => array('%s',array(1,2,3))", 'event_espresso'), $operator, $operator)); |
|
3302 | + }elseif ( ! in_array($operator, $this->_in_style_operators) && is_array($value)) { |
|
3303 | + throw new EE_Error(sprintf(__("Operator '%s' must be used with a single value, not an array. Eg 'Registration.REG_ID => array('%s',23))", 'event_espresso'), $operator, $operator)); |
|
3304 | + } else { |
|
3305 | + throw new EE_Error(sprintf(__("It appears you've provided some totally invalid query parameters. Operator and value were:'%s', which isn't right at all", "event_espresso"), http_build_query($op_and_value))); |
|
3306 | 3306 | } |
3307 | 3307 | } |
3308 | 3308 | |
@@ -3314,12 +3314,12 @@ discard block |
||
3314 | 3314 | * @param EE_Model_Field_Base|string $field_obj if string, it should be the datatype to be used when querying, eg '%s' |
3315 | 3315 | * @return string |
3316 | 3316 | */ |
3317 | - function _construct_between_value( $values, $field_obj ) { |
|
3317 | + function _construct_between_value($values, $field_obj) { |
|
3318 | 3318 | $cleaned_values = array(); |
3319 | - foreach ( $values as $value ) { |
|
3320 | - $cleaned_values[] = $this->_wpdb_prepare_using_field($value,$field_obj); |
|
3319 | + foreach ($values as $value) { |
|
3320 | + $cleaned_values[] = $this->_wpdb_prepare_using_field($value, $field_obj); |
|
3321 | 3321 | } |
3322 | - return $cleaned_values[0] . " AND " . $cleaned_values[1]; |
|
3322 | + return $cleaned_values[0]." AND ".$cleaned_values[1]; |
|
3323 | 3323 | } |
3324 | 3324 | |
3325 | 3325 | |
@@ -3335,26 +3335,26 @@ discard block |
||
3335 | 3335 | * @param EE_Model_Field_Base|string $field_obj if string, it should be a wpdb data type like '%s', or '%d' |
3336 | 3336 | * @return string of SQL to follow an 'IN' or 'NOT IN' operator |
3337 | 3337 | */ |
3338 | - function _construct_in_value($values, $field_obj){ |
|
3338 | + function _construct_in_value($values, $field_obj) { |
|
3339 | 3339 | //check if the value is a CSV list |
3340 | - if(is_string($values)){ |
|
3340 | + if (is_string($values)) { |
|
3341 | 3341 | //in which case, turn it into an array |
3342 | - $values = explode(",",$values); |
|
3342 | + $values = explode(",", $values); |
|
3343 | 3343 | } |
3344 | 3344 | $cleaned_values = array(); |
3345 | - foreach($values as $value){ |
|
3346 | - $cleaned_values[] = $this->_wpdb_prepare_using_field($value,$field_obj); |
|
3345 | + foreach ($values as $value) { |
|
3346 | + $cleaned_values[] = $this->_wpdb_prepare_using_field($value, $field_obj); |
|
3347 | 3347 | } |
3348 | 3348 | //we would just LOVE to leave $cleaned_values as an empty array, and return the value as "()", |
3349 | 3349 | //but unfortunately that's invalid SQL. So instead we return a string which we KNOW will evaluate to be the empty set |
3350 | 3350 | //which is effectively equivalent to returning "()". We don't return "(0)" because that only works for auto-incrementing columns |
3351 | - if(empty($cleaned_values)){ |
|
3351 | + if (empty($cleaned_values)) { |
|
3352 | 3352 | $all_fields = $this->field_settings(); |
3353 | 3353 | $a_field = array_shift($all_fields); |
3354 | 3354 | $main_table = $this->_get_main_table(); |
3355 | 3355 | $cleaned_values[] = "SELECT ".$a_field->get_table_column()." FROM ".$main_table->get_table_name()." WHERE FALSE"; |
3356 | 3356 | } |
3357 | - return "(".implode(",",$cleaned_values).")"; |
|
3357 | + return "(".implode(",", $cleaned_values).")"; |
|
3358 | 3358 | } |
3359 | 3359 | |
3360 | 3360 | |
@@ -3366,16 +3366,16 @@ discard block |
||
3366 | 3366 | * @throws EE_Error |
3367 | 3367 | * @return false|null|string |
3368 | 3368 | */ |
3369 | - private function _wpdb_prepare_using_field($value,$field_obj){ |
|
3369 | + private function _wpdb_prepare_using_field($value, $field_obj) { |
|
3370 | 3370 | /** @type WPDB $wpdb */ |
3371 | 3371 | global $wpdb; |
3372 | - if($field_obj instanceof EE_Model_Field_Base){ |
|
3373 | - return $wpdb->prepare($field_obj->get_wpdb_data_type(),$this->_prepare_value_for_use_in_db($value, $field_obj)); |
|
3374 | - }else{//$field_obj should really just be a data type |
|
3375 | - if( ! in_array($field_obj,$this->_valid_wpdb_data_types)){ |
|
3376 | - throw new EE_Error(sprintf(__("%s is not a valid wpdb datatype. Valid ones are %s", "event_espresso"),$field_obj,implode(",",$this->_valid_wpdb_data_types))); |
|
3372 | + if ($field_obj instanceof EE_Model_Field_Base) { |
|
3373 | + return $wpdb->prepare($field_obj->get_wpdb_data_type(), $this->_prepare_value_for_use_in_db($value, $field_obj)); |
|
3374 | + } else {//$field_obj should really just be a data type |
|
3375 | + if ( ! in_array($field_obj, $this->_valid_wpdb_data_types)) { |
|
3376 | + throw new EE_Error(sprintf(__("%s is not a valid wpdb datatype. Valid ones are %s", "event_espresso"), $field_obj, implode(",", $this->_valid_wpdb_data_types))); |
|
3377 | 3377 | } |
3378 | - return $wpdb->prepare($field_obj,$value); |
|
3378 | + return $wpdb->prepare($field_obj, $value); |
|
3379 | 3379 | } |
3380 | 3380 | } |
3381 | 3381 | |
@@ -3387,27 +3387,27 @@ discard block |
||
3387 | 3387 | * @throws EE_Error |
3388 | 3388 | * @return EE_Model_Field_Base |
3389 | 3389 | */ |
3390 | - protected function _deduce_field_from_query_param($query_param_name){ |
|
3390 | + protected function _deduce_field_from_query_param($query_param_name) { |
|
3391 | 3391 | //ok, now proceed with deducing which part is the model's name, and which is the field's name |
3392 | 3392 | //which will help us find the database table and column |
3393 | 3393 | |
3394 | - $query_param_parts = explode(".",$query_param_name); |
|
3395 | - if(empty($query_param_parts)){ |
|
3396 | - throw new EE_Error(sprintf(__("_extract_column_name is empty when trying to extract column and table name from %s",'event_espresso'),$query_param_name)); |
|
3394 | + $query_param_parts = explode(".", $query_param_name); |
|
3395 | + if (empty($query_param_parts)) { |
|
3396 | + throw new EE_Error(sprintf(__("_extract_column_name is empty when trying to extract column and table name from %s", 'event_espresso'), $query_param_name)); |
|
3397 | 3397 | } |
3398 | 3398 | $number_of_parts = count($query_param_parts); |
3399 | - $last_query_param_part = $query_param_parts[ count($query_param_parts) - 1 ]; |
|
3400 | - if($number_of_parts == 1){ |
|
3399 | + $last_query_param_part = $query_param_parts[count($query_param_parts) - 1]; |
|
3400 | + if ($number_of_parts == 1) { |
|
3401 | 3401 | $field_name = $last_query_param_part; |
3402 | 3402 | $model_obj = $this; |
3403 | - }else{// $number_of_parts >= 2 |
|
3403 | + } else {// $number_of_parts >= 2 |
|
3404 | 3404 | //the last part is the column name, and there are only 2parts. therefore... |
3405 | 3405 | $field_name = $last_query_param_part; |
3406 | - $model_obj = $this->get_related_model_obj( $query_param_parts[ $number_of_parts - 2 ]); |
|
3406 | + $model_obj = $this->get_related_model_obj($query_param_parts[$number_of_parts - 2]); |
|
3407 | 3407 | } |
3408 | - try{ |
|
3408 | + try { |
|
3409 | 3409 | return $model_obj->field_settings_for($field_name); |
3410 | - }catch(EE_Error $e){ |
|
3410 | + } catch (EE_Error $e) { |
|
3411 | 3411 | return null; |
3412 | 3412 | } |
3413 | 3413 | } |
@@ -3421,13 +3421,13 @@ discard block |
||
3421 | 3421 | * @throws EE_Error |
3422 | 3422 | * @return string |
3423 | 3423 | */ |
3424 | - function _get_qualified_column_for_field($field_name){ |
|
3424 | + function _get_qualified_column_for_field($field_name) { |
|
3425 | 3425 | $all_fields = $this->field_settings(); |
3426 | 3426 | $field = isset($all_fields[$field_name]) ? $all_fields[$field_name] : FALSE; |
3427 | - if($field){ |
|
3427 | + if ($field) { |
|
3428 | 3428 | return $field->get_qualified_column(); |
3429 | - }else{ |
|
3430 | - throw new EE_Error(sprintf(__("There is no field titled %s on model %s. Either the query trying to use it is bad, or you need to add it to the list of fields on the model.",'event_espresso'),$field_name,get_class($this))); |
|
3429 | + } else { |
|
3430 | + throw new EE_Error(sprintf(__("There is no field titled %s on model %s. Either the query trying to use it is bad, or you need to add it to the list of fields on the model.", 'event_espresso'), $field_name, get_class($this))); |
|
3431 | 3431 | } |
3432 | 3432 | } |
3433 | 3433 | |
@@ -3441,14 +3441,14 @@ discard block |
||
3441 | 3441 | * @param mixed|string $limit The limit for this select |
3442 | 3442 | * @return string The final select join element for the query. |
3443 | 3443 | */ |
3444 | - function _construct_limit_join_select( $table_alias, $limit ) { |
|
3444 | + function _construct_limit_join_select($table_alias, $limit) { |
|
3445 | 3445 | $SQL = ''; |
3446 | 3446 | |
3447 | - foreach ( $this->_tables as $table_obj ) { |
|
3448 | - if ( $table_obj instanceof EE_Primary_Table ) { |
|
3449 | - $SQL .= $table_alias == $table_obj->get_table_alias() ? $table_obj->get_select_join_limit( $limit ) : SP.$table_obj->get_table_name()." AS ".$table_obj->get_table_alias().SP; |
|
3450 | - } elseif ( $table_obj instanceof EE_Secondary_Table ) { |
|
3451 | - $SQL .= $table_alias == $table_obj->get_table_alias() ? $table_obj->get_select_join_limit_join($limit) : SP . $table_obj->get_join_sql( $table_alias ).SP; |
|
3447 | + foreach ($this->_tables as $table_obj) { |
|
3448 | + if ($table_obj instanceof EE_Primary_Table) { |
|
3449 | + $SQL .= $table_alias == $table_obj->get_table_alias() ? $table_obj->get_select_join_limit($limit) : SP.$table_obj->get_table_name()." AS ".$table_obj->get_table_alias().SP; |
|
3450 | + } elseif ($table_obj instanceof EE_Secondary_Table) { |
|
3451 | + $SQL .= $table_alias == $table_obj->get_table_alias() ? $table_obj->get_select_join_limit_join($limit) : SP.$table_obj->get_join_sql($table_alias).SP; |
|
3452 | 3452 | } |
3453 | 3453 | } |
3454 | 3454 | return $SQL; |
@@ -3461,7 +3461,7 @@ discard block |
||
3461 | 3461 | * Eg "wp_post AS Event" or "wp_post AS Event INNER JOIN wp_postmeta Event_Meta ON Event.ID = Event_Meta.post_id" |
3462 | 3462 | * @return string SQL |
3463 | 3463 | */ |
3464 | - function _construct_internal_join(){ |
|
3464 | + function _construct_internal_join() { |
|
3465 | 3465 | $SQL = $this->_get_main_table()->get_table_sql(); |
3466 | 3466 | $SQL .= $this->_construct_internal_join_to_table_with_alias($this->_get_main_table()->get_table_alias()); |
3467 | 3467 | return $SQL; |
@@ -3482,17 +3482,17 @@ discard block |
||
3482 | 3482 | * @param string $alias_prefixed table alias to join to (this table should already be in the FROM SQL clause) |
3483 | 3483 | * @return string |
3484 | 3484 | */ |
3485 | - function _construct_internal_join_to_table_with_alias($alias_prefixed){ |
|
3485 | + function _construct_internal_join_to_table_with_alias($alias_prefixed) { |
|
3486 | 3486 | $SQL = ''; |
3487 | 3487 | $alias_sans_prefix = EE_Model_Parser::remove_table_alias_model_relation_chain_prefix($alias_prefixed); |
3488 | - foreach($this->_tables as $table_obj){ |
|
3489 | - if($table_obj instanceof EE_Secondary_Table){//table is secondary table |
|
3490 | - if($alias_sans_prefix == $table_obj->get_table_alias()){ |
|
3488 | + foreach ($this->_tables as $table_obj) { |
|
3489 | + if ($table_obj instanceof EE_Secondary_Table) {//table is secondary table |
|
3490 | + if ($alias_sans_prefix == $table_obj->get_table_alias()) { |
|
3491 | 3491 | //so we're joining to this table, meaning the table is already in |
3492 | 3492 | //the FROM statement, BUT the primary table isn't. So we want |
3493 | 3493 | //to add the inverse join sql |
3494 | 3494 | $SQL .= $table_obj->get_inverse_join_sql($alias_prefixed); |
3495 | - }else{ |
|
3495 | + } else { |
|
3496 | 3496 | //just add a regular JOIN to this table from the primary table |
3497 | 3497 | $SQL .= $table_obj->get_join_sql($alias_prefixed); |
3498 | 3498 | } |
@@ -3506,9 +3506,9 @@ discard block |
||
3506 | 3506 | * This should be a growing array of keys being table-columns (eg 'EVT_ID' and 'Event.EVT_ID'), and values being their data type (eg, '%s', '%d', etc) |
3507 | 3507 | * @return array |
3508 | 3508 | */ |
3509 | - function _get_data_types(){ |
|
3509 | + function _get_data_types() { |
|
3510 | 3510 | $data_types = array(); |
3511 | - foreach(array_values($this->field_settings()) as $field_obj){ |
|
3511 | + foreach (array_values($this->field_settings()) as $field_obj) { |
|
3512 | 3512 | //$data_types[$field_obj->get_table_column()] = $field_obj->get_wpdb_data_type(); |
3513 | 3513 | /** @var $field_obj EE_Model_Field_Base */ |
3514 | 3514 | $data_types[$field_obj->get_qualified_column()] = $field_obj->get_wpdb_data_type(); |
@@ -3524,11 +3524,11 @@ discard block |
||
3524 | 3524 | * @throws EE_Error |
3525 | 3525 | * @return EEM_Base |
3526 | 3526 | */ |
3527 | - function get_related_model_obj($model_name){ |
|
3527 | + function get_related_model_obj($model_name) { |
|
3528 | 3528 | |
3529 | 3529 | $model_classname = "EEM_".$model_name; |
3530 | - if(!class_exists($model_classname)){ |
|
3531 | - throw new EE_Error(sprintf(__("You specified a related model named %s in your query. No such model exists, if it did, it would have the classname %s",'event_espresso'),$model_name,$model_classname)); |
|
3530 | + if ( ! class_exists($model_classname)) { |
|
3531 | + throw new EE_Error(sprintf(__("You specified a related model named %s in your query. No such model exists, if it did, it would have the classname %s", 'event_espresso'), $model_name, $model_classname)); |
|
3532 | 3532 | } |
3533 | 3533 | $model_obj = call_user_func($model_classname."::instance"); |
3534 | 3534 | return $model_obj; |
@@ -3539,7 +3539,7 @@ discard block |
||
3539 | 3539 | * Returns the array of EE_ModelRelations for this model. |
3540 | 3540 | * @return EE_Model_Relation_Base[] |
3541 | 3541 | */ |
3542 | - public function relation_settings(){ |
|
3542 | + public function relation_settings() { |
|
3543 | 3543 | return $this->_model_relations; |
3544 | 3544 | } |
3545 | 3545 | |
@@ -3549,10 +3549,10 @@ discard block |
||
3549 | 3549 | * (Eg, without an event, datetimes have little purpose.) |
3550 | 3550 | * @return EE_Belongs_To_Relation[] |
3551 | 3551 | */ |
3552 | - public function belongs_to_relations(){ |
|
3552 | + public function belongs_to_relations() { |
|
3553 | 3553 | $belongs_to_relations = array(); |
3554 | - foreach($this->relation_settings() as $model_name => $relation_obj){ |
|
3555 | - if($relation_obj instanceof EE_Belongs_To_Relation){ |
|
3554 | + foreach ($this->relation_settings() as $model_name => $relation_obj) { |
|
3555 | + if ($relation_obj instanceof EE_Belongs_To_Relation) { |
|
3556 | 3556 | $belongs_to_relations[$model_name] = $relation_obj; |
3557 | 3557 | } |
3558 | 3558 | } |
@@ -3567,15 +3567,15 @@ discard block |
||
3567 | 3567 | * @throws EE_Error |
3568 | 3568 | * @return EE_Model_Relation_Base |
3569 | 3569 | */ |
3570 | - public function related_settings_for($relation_name){ |
|
3571 | - $relatedModels=$this->relation_settings(); |
|
3572 | - if(!array_key_exists($relation_name,$relatedModels)){ |
|
3570 | + public function related_settings_for($relation_name) { |
|
3571 | + $relatedModels = $this->relation_settings(); |
|
3572 | + if ( ! array_key_exists($relation_name, $relatedModels)) { |
|
3573 | 3573 | throw new EE_Error( |
3574 | 3574 | sprintf( |
3575 | - __('Cannot get %s related to %s. There is no model relation of that type. There is, however, %s...','event_espresso'), |
|
3575 | + __('Cannot get %s related to %s. There is no model relation of that type. There is, however, %s...', 'event_espresso'), |
|
3576 | 3576 | $relation_name, |
3577 | 3577 | $this->_get_class_name(), |
3578 | - implode( ', ', array_keys( $relatedModels )) |
|
3578 | + implode(', ', array_keys($relatedModels)) |
|
3579 | 3579 | ) |
3580 | 3580 | ); |
3581 | 3581 | } |
@@ -3590,10 +3590,10 @@ discard block |
||
3590 | 3590 | * @throws EE_Error |
3591 | 3591 | * @return EE_Model_Field_Base |
3592 | 3592 | */ |
3593 | - public function field_settings_for($fieldName){ |
|
3594 | - $fieldSettings=$this->field_settings(true); |
|
3595 | - if( ! array_key_exists($fieldName,$fieldSettings)){ |
|
3596 | - throw new EE_Error(sprintf(__("There is no field/column '%s' on '%s'",'event_espresso'),$fieldName,get_class($this))); |
|
3593 | + public function field_settings_for($fieldName) { |
|
3594 | + $fieldSettings = $this->field_settings(true); |
|
3595 | + if ( ! array_key_exists($fieldName, $fieldSettings)) { |
|
3596 | + throw new EE_Error(sprintf(__("There is no field/column '%s' on '%s'", 'event_espresso'), $fieldName, get_class($this))); |
|
3597 | 3597 | } |
3598 | 3598 | return $fieldSettings[$fieldName]; |
3599 | 3599 | } |
@@ -3603,11 +3603,11 @@ discard block |
||
3603 | 3603 | * @param string $fieldName a key in the model's _field_settings array |
3604 | 3604 | * @return boolean |
3605 | 3605 | */ |
3606 | - public function has_field($fieldName){ |
|
3606 | + public function has_field($fieldName) { |
|
3607 | 3607 | $fieldSettings = $this->field_settings(true); |
3608 | - if( isset($fieldSettings[$fieldName])){ |
|
3608 | + if (isset($fieldSettings[$fieldName])) { |
|
3609 | 3609 | return true; |
3610 | - }else{ |
|
3610 | + } else { |
|
3611 | 3611 | return false; |
3612 | 3612 | } |
3613 | 3613 | } |
@@ -3617,11 +3617,11 @@ discard block |
||
3617 | 3617 | * @param string $relation_name possibly one of the keys in the relation_settings array |
3618 | 3618 | * @return boolean |
3619 | 3619 | */ |
3620 | - public function has_relation($relation_name){ |
|
3620 | + public function has_relation($relation_name) { |
|
3621 | 3621 | $relations = $this->relation_settings(); |
3622 | - if(isset($relations[$relation_name])){ |
|
3622 | + if (isset($relations[$relation_name])) { |
|
3623 | 3623 | return true; |
3624 | - }else{ |
|
3624 | + } else { |
|
3625 | 3625 | return false; |
3626 | 3626 | } |
3627 | 3627 | } |
@@ -3633,7 +3633,7 @@ discard block |
||
3633 | 3633 | * @param $field_obj |
3634 | 3634 | * @return EE_Model_Field_Base |
3635 | 3635 | */ |
3636 | - public function is_primary_key_field( $field_obj ){ |
|
3636 | + public function is_primary_key_field($field_obj) { |
|
3637 | 3637 | return $field_obj instanceof EE_Primary_Key_Field_Base ? TRUE : FALSE; |
3638 | 3638 | } |
3639 | 3639 | |
@@ -3645,16 +3645,16 @@ discard block |
||
3645 | 3645 | * @return EE_Model_Field_Base |
3646 | 3646 | * @throws EE_Error |
3647 | 3647 | */ |
3648 | - public function get_primary_key_field(){ |
|
3649 | - if( $this->_primary_key_field === NULL ){ |
|
3650 | - foreach( $this->field_settings( TRUE ) as $field_obj ){ |
|
3651 | - if( $this->is_primary_key_field( $field_obj )){ |
|
3648 | + public function get_primary_key_field() { |
|
3649 | + if ($this->_primary_key_field === NULL) { |
|
3650 | + foreach ($this->field_settings(TRUE) as $field_obj) { |
|
3651 | + if ($this->is_primary_key_field($field_obj)) { |
|
3652 | 3652 | $this->_primary_key_field = $field_obj; |
3653 | 3653 | break; |
3654 | 3654 | } |
3655 | 3655 | } |
3656 | - if( ! $this->_primary_key_field instanceof EE_Primary_Key_Field_Base ){ |
|
3657 | - throw new EE_Error(sprintf(__("There is no Primary Key defined on model %s",'event_espresso'),get_class($this))); |
|
3656 | + if ( ! $this->_primary_key_field instanceof EE_Primary_Key_Field_Base) { |
|
3657 | + throw new EE_Error(sprintf(__("There is no Primary Key defined on model %s", 'event_espresso'), get_class($this))); |
|
3658 | 3658 | } |
3659 | 3659 | } |
3660 | 3660 | return $this->_primary_key_field; |
@@ -3667,12 +3667,12 @@ discard block |
||
3667 | 3667 | * Internally does some caching. |
3668 | 3668 | * @return boolean |
3669 | 3669 | */ |
3670 | - public function has_primary_key_field(){ |
|
3671 | - if($this->_has_primary_key_field === null){ |
|
3672 | - try{ |
|
3670 | + public function has_primary_key_field() { |
|
3671 | + if ($this->_has_primary_key_field === null) { |
|
3672 | + try { |
|
3673 | 3673 | $this->get_primary_key_field(); |
3674 | 3674 | $this->_has_primary_key_field = true; |
3675 | - }catch(EE_Error $e){ |
|
3675 | + } catch (EE_Error $e) { |
|
3676 | 3676 | $this->_has_primary_key_field = false; |
3677 | 3677 | } |
3678 | 3678 | } |
@@ -3686,9 +3686,9 @@ discard block |
||
3686 | 3686 | * @param string $field_class_name class name of field that you want to find. Eg, EE_Datetime_Field, EE_Foreign_Key_Field, etc |
3687 | 3687 | * @return EE_Model_Field_Base or null if none is found |
3688 | 3688 | */ |
3689 | - public function get_a_field_of_type($field_class_name){ |
|
3690 | - foreach($this->field_settings() as $field){ |
|
3691 | - if( $field instanceof $field_class_name ){ |
|
3689 | + public function get_a_field_of_type($field_class_name) { |
|
3690 | + foreach ($this->field_settings() as $field) { |
|
3691 | + if ($field instanceof $field_class_name) { |
|
3692 | 3692 | return $field; |
3693 | 3693 | } |
3694 | 3694 | } |
@@ -3702,21 +3702,21 @@ discard block |
||
3702 | 3702 | * @return EE_Foreign_Key_Field_Base |
3703 | 3703 | * @throws EE_Error |
3704 | 3704 | */ |
3705 | - public function get_foreign_key_to($model_name){ |
|
3706 | - if( ! isset( $this->_cache_foreign_key_to_fields[ $model_name ] ) ){ |
|
3707 | - foreach($this->field_settings() as $field){ |
|
3705 | + public function get_foreign_key_to($model_name) { |
|
3706 | + if ( ! isset($this->_cache_foreign_key_to_fields[$model_name])) { |
|
3707 | + foreach ($this->field_settings() as $field) { |
|
3708 | 3708 | // if(is_subclass_of($field, 'EE_Foreign_Key_Field_Base')){ |
3709 | - if( $field instanceof EE_Foreign_Key_Field_Base ){ |
|
3710 | - if (in_array($model_name,$field->get_model_names_pointed_to() ) ) { |
|
3711 | - $this->_cache_foreign_key_to_fields[ $model_name ] = $field; |
|
3709 | + if ($field instanceof EE_Foreign_Key_Field_Base) { |
|
3710 | + if (in_array($model_name, $field->get_model_names_pointed_to())) { |
|
3711 | + $this->_cache_foreign_key_to_fields[$model_name] = $field; |
|
3712 | 3712 | } |
3713 | 3713 | } |
3714 | 3714 | } |
3715 | - if( ! isset( $this->_cache_foreign_key_to_fields[ $model_name ] ) ){ |
|
3716 | - throw new EE_Error(sprintf(__("There is no foreign key field pointing to model %s on model %s",'event_espresso'),$model_name,get_class($this))); |
|
3715 | + if ( ! isset($this->_cache_foreign_key_to_fields[$model_name])) { |
|
3716 | + throw new EE_Error(sprintf(__("There is no foreign key field pointing to model %s on model %s", 'event_espresso'), $model_name, get_class($this))); |
|
3717 | 3717 | } |
3718 | 3718 | } |
3719 | - return $this->_cache_foreign_key_to_fields[ $model_name ]; |
|
3719 | + return $this->_cache_foreign_key_to_fields[$model_name]; |
|
3720 | 3720 | } |
3721 | 3721 | |
3722 | 3722 | |
@@ -3727,7 +3727,7 @@ discard block |
||
3727 | 3727 | * a table alias with a model chain prefix, like 'Venue__Event_Venue___Event_Meta'. Either one works |
3728 | 3728 | * @return EE_Table_Base |
3729 | 3729 | */ |
3730 | - function get_table_for_alias($table_alias){ |
|
3730 | + function get_table_for_alias($table_alias) { |
|
3731 | 3731 | $table_alias_sans_model_relation_chain_prefix = EE_Model_Parser::remove_table_alias_model_relation_chain_prefix($table_alias); |
3732 | 3732 | return $this->_tables[$table_alias_sans_model_relation_chain_prefix]->get_table_name(); |
3733 | 3733 | } |
@@ -3740,25 +3740,25 @@ discard block |
||
3740 | 3740 | * @param bool $include_db_only_fields flag indicating whether or not to include the db-only fields |
3741 | 3741 | * @return EE_Model_Field_Base[] where the keys are the field's name |
3742 | 3742 | */ |
3743 | - public function field_settings($include_db_only_fields = false){ |
|
3744 | - if( $include_db_only_fields ){ |
|
3745 | - if( $this->_cached_fields === NULL ){ |
|
3743 | + public function field_settings($include_db_only_fields = false) { |
|
3744 | + if ($include_db_only_fields) { |
|
3745 | + if ($this->_cached_fields === NULL) { |
|
3746 | 3746 | $this->_cached_fields = array(); |
3747 | - foreach($this->_fields as $fields_corresponding_to_table){ |
|
3748 | - foreach($fields_corresponding_to_table as $field_name => $field_obj){ |
|
3749 | - $this->_cached_fields[$field_name]=$field_obj; |
|
3747 | + foreach ($this->_fields as $fields_corresponding_to_table) { |
|
3748 | + foreach ($fields_corresponding_to_table as $field_name => $field_obj) { |
|
3749 | + $this->_cached_fields[$field_name] = $field_obj; |
|
3750 | 3750 | } |
3751 | 3751 | } |
3752 | 3752 | } |
3753 | 3753 | return $this->_cached_fields; |
3754 | - }else{ |
|
3755 | - if( $this->_cached_fields_non_db_only === NULL ){ |
|
3754 | + } else { |
|
3755 | + if ($this->_cached_fields_non_db_only === NULL) { |
|
3756 | 3756 | $this->_cached_fields_non_db_only = array(); |
3757 | - foreach($this->_fields as $fields_corresponding_to_table){ |
|
3758 | - foreach($fields_corresponding_to_table as $field_name => $field_obj){ |
|
3757 | + foreach ($this->_fields as $fields_corresponding_to_table) { |
|
3758 | + foreach ($fields_corresponding_to_table as $field_name => $field_obj) { |
|
3759 | 3759 | /** @var $field_obj EE_Model_Field_Base */ |
3760 | - if( ! $field_obj->is_db_only_field() ){ |
|
3761 | - $this->_cached_fields_non_db_only[$field_name]=$field_obj; |
|
3760 | + if ( ! $field_obj->is_db_only_field()) { |
|
3761 | + $this->_cached_fields_non_db_only[$field_name] = $field_obj; |
|
3762 | 3762 | } |
3763 | 3763 | } |
3764 | 3764 | } |
@@ -3777,67 +3777,67 @@ discard block |
||
3777 | 3777 | * @return \EE_Base_Class[] array keys are primary keys (if there is a primary key on the model. if not, numerically indexed) |
3778 | 3778 | * @throws \EE_Error |
3779 | 3779 | */ |
3780 | - protected function _create_objects( $rows = array() ) { |
|
3781 | - $array_of_objects=array(); |
|
3782 | - if(empty($rows)){ |
|
3780 | + protected function _create_objects($rows = array()) { |
|
3781 | + $array_of_objects = array(); |
|
3782 | + if (empty($rows)) { |
|
3783 | 3783 | return array(); |
3784 | 3784 | } |
3785 | 3785 | $count_if_model_has_no_primary_key = 0; |
3786 | 3786 | $has_primary_key = $this->has_primary_key_field(); |
3787 | - if( $has_primary_key ) { |
|
3787 | + if ($has_primary_key) { |
|
3788 | 3788 | $primary_key_field = $this->get_primary_key_field(); |
3789 | 3789 | } else { |
3790 | 3790 | $primary_key_field = null; |
3791 | 3791 | } |
3792 | - foreach ( $rows as $row ) { |
|
3793 | - if(empty($row)){ |
|
3792 | + foreach ($rows as $row) { |
|
3793 | + if (empty($row)) { |
|
3794 | 3794 | //wp did its weird thing where it returns an array like array(0=>null), which is totally not helpful... |
3795 | 3795 | return array(); |
3796 | 3796 | } |
3797 | 3797 | //check if we've already set this object in the results array, |
3798 | 3798 | //in which case there's no need to process it further (again) |
3799 | - if( $has_primary_key ) { |
|
3799 | + if ($has_primary_key) { |
|
3800 | 3800 | $table_pk_value = $this->_get_column_value_with_table_alias_or_not( |
3801 | 3801 | $row, |
3802 | 3802 | $primary_key_field->get_qualified_column(), |
3803 | 3803 | $primary_key_field->get_table_column() |
3804 | 3804 | ); |
3805 | - if( $table_pk_value && |
|
3806 | - isset( $array_of_objects[ $table_pk_value ] ) ) { |
|
3805 | + if ($table_pk_value && |
|
3806 | + isset($array_of_objects[$table_pk_value])) { |
|
3807 | 3807 | continue; |
3808 | 3808 | } |
3809 | 3809 | } |
3810 | - $classInstance=$this->instantiate_class_from_array_or_object($row); |
|
3811 | - if( ! $classInstance ) { |
|
3810 | + $classInstance = $this->instantiate_class_from_array_or_object($row); |
|
3811 | + if ( ! $classInstance) { |
|
3812 | 3812 | throw new EE_Error( |
3813 | 3813 | sprintf( |
3814 | - __( 'Could not create instance of class %s from row %s', 'event_espresso' ), |
|
3814 | + __('Could not create instance of class %s from row %s', 'event_espresso'), |
|
3815 | 3815 | $this->get_this_model_name(), |
3816 | - http_build_query( $row ) |
|
3816 | + http_build_query($row) |
|
3817 | 3817 | ) |
3818 | 3818 | ); |
3819 | 3819 | } |
3820 | 3820 | //set the timezone on the instantiated objects |
3821 | - $classInstance->set_timezone( $this->_timezone ); |
|
3821 | + $classInstance->set_timezone($this->_timezone); |
|
3822 | 3822 | //make sure if there is any timezone setting present that we set the timezone for the object |
3823 | 3823 | $key = $has_primary_key ? $classInstance->ID() : $count_if_model_has_no_primary_key++; |
3824 | - $array_of_objects[ $key ] = $classInstance; |
|
3824 | + $array_of_objects[$key] = $classInstance; |
|
3825 | 3825 | //also, for all the relations of type BelongsTo, see if we can cache |
3826 | 3826 | //those related models |
3827 | 3827 | //(we could do this for other relations too, but if there are conditions |
3828 | 3828 | //that filtered out some fo the results, then we'd be caching an incomplete set |
3829 | 3829 | //so it requires a little more thought than just caching them immediately...) |
3830 | - foreach($this->_model_relations as $modelName => $relation_obj){ |
|
3831 | - if( $relation_obj instanceof EE_Belongs_To_Relation){ |
|
3830 | + foreach ($this->_model_relations as $modelName => $relation_obj) { |
|
3831 | + if ($relation_obj instanceof EE_Belongs_To_Relation) { |
|
3832 | 3832 | //check if this model's INFO is present. If so, cache it on the model |
3833 | 3833 | $other_model = $relation_obj->get_other_model(); |
3834 | 3834 | |
3835 | 3835 | $other_model_obj_maybe = $other_model->instantiate_class_from_array_or_object($row); |
3836 | 3836 | |
3837 | 3837 | //if we managed to make a model object from the results, cache it on the main model object |
3838 | - if( $other_model_obj_maybe ){ |
|
3838 | + if ($other_model_obj_maybe) { |
|
3839 | 3839 | //set timezone on these other model objects if they are present |
3840 | - $other_model_obj_maybe->set_timezone( $this->_timezone ); |
|
3840 | + $other_model_obj_maybe->set_timezone($this->_timezone); |
|
3841 | 3841 | $classInstance->cache($modelName, $other_model_obj_maybe); |
3842 | 3842 | } |
3843 | 3843 | } |
@@ -3858,12 +3858,12 @@ discard block |
||
3858 | 3858 | |
3859 | 3859 | $this_model_fields_and_values = array(); |
3860 | 3860 | //setup the row using default values; |
3861 | - foreach ( $this->field_settings() as $field_name => $field_obj ) { |
|
3861 | + foreach ($this->field_settings() as $field_name => $field_obj) { |
|
3862 | 3862 | $this_model_fields_and_values[$field_name] = $field_obj->get_default_value(); |
3863 | 3863 | } |
3864 | 3864 | |
3865 | 3865 | $className = $this->_get_class_name(); |
3866 | - $classInstance = EE_Registry::instance()->load_class( $className, array( $this_model_fields_and_values ), FALSE, FALSE ); |
|
3866 | + $classInstance = EE_Registry::instance()->load_class($className, array($this_model_fields_and_values), FALSE, FALSE); |
|
3867 | 3867 | |
3868 | 3868 | return $classInstance; |
3869 | 3869 | } |
@@ -3876,45 +3876,45 @@ discard block |
||
3876 | 3876 | * or an stdClass where each property is the name of a column, |
3877 | 3877 | * @return EE_Base_Class |
3878 | 3878 | */ |
3879 | - public function instantiate_class_from_array_or_object($cols_n_values){ |
|
3880 | - if( ! is_array( $cols_n_values ) && is_object( $cols_n_values )) { |
|
3881 | - $cols_n_values = get_object_vars( $cols_n_values ); |
|
3879 | + public function instantiate_class_from_array_or_object($cols_n_values) { |
|
3880 | + if ( ! is_array($cols_n_values) && is_object($cols_n_values)) { |
|
3881 | + $cols_n_values = get_object_vars($cols_n_values); |
|
3882 | 3882 | } |
3883 | 3883 | $primary_key = NULL; |
3884 | 3884 | //make sure the array only has keys that are fields/columns on this model |
3885 | - $this_model_fields_n_values = $this->_deduce_fields_n_values_from_cols_n_values( $cols_n_values ); |
|
3886 | - if( $this->has_primary_key_field() && isset( $this_model_fields_n_values[ $this->primary_key_name() ] ) ){ |
|
3887 | - $primary_key = $this_model_fields_n_values[ $this->primary_key_name() ]; |
|
3885 | + $this_model_fields_n_values = $this->_deduce_fields_n_values_from_cols_n_values($cols_n_values); |
|
3886 | + if ($this->has_primary_key_field() && isset($this_model_fields_n_values[$this->primary_key_name()])) { |
|
3887 | + $primary_key = $this_model_fields_n_values[$this->primary_key_name()]; |
|
3888 | 3888 | } |
3889 | - $className=$this->_get_class_name(); |
|
3889 | + $className = $this->_get_class_name(); |
|
3890 | 3890 | |
3891 | 3891 | //check we actually found results that we can use to build our model object |
3892 | 3892 | //if not, return null |
3893 | - if( $this->has_primary_key_field()){ |
|
3894 | - if(empty( $this_model_fields_n_values[$this->primary_key_name()] )){ |
|
3893 | + if ($this->has_primary_key_field()) { |
|
3894 | + if (empty($this_model_fields_n_values[$this->primary_key_name()])) { |
|
3895 | 3895 | return NULL; |
3896 | 3896 | } |
3897 | - }else if($this->unique_indexes()){ |
|
3897 | + } else if ($this->unique_indexes()) { |
|
3898 | 3898 | $first_column = reset($this_model_fields_n_values); |
3899 | - if(empty($first_column)){ |
|
3899 | + if (empty($first_column)) { |
|
3900 | 3900 | return NULL; |
3901 | 3901 | } |
3902 | 3902 | } |
3903 | 3903 | |
3904 | 3904 | // if there is no primary key or the object doesn't already exist in the entity map, then create a new instance |
3905 | - if ( $primary_key){ |
|
3906 | - $classInstance = $this->get_from_entity_map( $primary_key ); |
|
3907 | - if( ! $classInstance) { |
|
3908 | - $classInstance = EE_Registry::instance()->load_class( $className, array( $this_model_fields_n_values, $this->_timezone ), TRUE, FALSE ); |
|
3905 | + if ($primary_key) { |
|
3906 | + $classInstance = $this->get_from_entity_map($primary_key); |
|
3907 | + if ( ! $classInstance) { |
|
3908 | + $classInstance = EE_Registry::instance()->load_class($className, array($this_model_fields_n_values, $this->_timezone), TRUE, FALSE); |
|
3909 | 3909 | // add this new object to the entity map |
3910 | - $classInstance = $this->add_to_entity_map( $classInstance ); |
|
3910 | + $classInstance = $this->add_to_entity_map($classInstance); |
|
3911 | 3911 | } |
3912 | - }else{ |
|
3913 | - $classInstance = EE_Registry::instance()->load_class( $className, array( $this_model_fields_n_values, $this->_timezone ), TRUE, FALSE ); |
|
3912 | + } else { |
|
3913 | + $classInstance = EE_Registry::instance()->load_class($className, array($this_model_fields_n_values, $this->_timezone), TRUE, FALSE); |
|
3914 | 3914 | } |
3915 | 3915 | |
3916 | 3916 | //it is entirely possible that the instantiated class object has a set timezone_string db field and has set it's internal _timezone property accordingly (see new_instance_from_db in model objects particularly EE_Event for example). In this case, we want to make sure the model object doesn't have its timezone string overwritten by any timezone property currently set here on the model so, we intentionally override the model _timezone property with the model_object timezone property. |
3917 | - $this->set_timezone( $classInstance->get_timezone() ); |
|
3917 | + $this->set_timezone($classInstance->get_timezone()); |
|
3918 | 3918 | return $classInstance; |
3919 | 3919 | } |
3920 | 3920 | /** |
@@ -3922,8 +3922,8 @@ discard block |
||
3922 | 3922 | * @param int|string $id the ID of the model object |
3923 | 3923 | * @return EE_Base_Class |
3924 | 3924 | */ |
3925 | - public function get_from_entity_map( $id ){ |
|
3926 | - return isset( $this->_entity_map[ $id ] ) ? $this->_entity_map[ $id ] : NULL; |
|
3925 | + public function get_from_entity_map($id) { |
|
3926 | + return isset($this->_entity_map[$id]) ? $this->_entity_map[$id] : NULL; |
|
3927 | 3927 | } |
3928 | 3928 | |
3929 | 3929 | |
@@ -3942,21 +3942,21 @@ discard block |
||
3942 | 3942 | * @throws EE_Error |
3943 | 3943 | * @return \EE_Base_Class |
3944 | 3944 | */ |
3945 | - public function add_to_entity_map( EE_Base_Class $object) { |
|
3945 | + public function add_to_entity_map(EE_Base_Class $object) { |
|
3946 | 3946 | $className = $this->_get_class_name(); |
3947 | - if( ! $object instanceof $className ){ |
|
3948 | - throw new EE_Error(sprintf(__("You tried adding a %s to a mapping of %ss", "event_espresso"),is_object( $object ) ? get_class( $object ) : $object, $className ) ); |
|
3947 | + if ( ! $object instanceof $className) { |
|
3948 | + throw new EE_Error(sprintf(__("You tried adding a %s to a mapping of %ss", "event_espresso"), is_object($object) ? get_class($object) : $object, $className)); |
|
3949 | 3949 | } |
3950 | 3950 | /** @var $object EE_Base_Class */ |
3951 | - if ( ! $object->ID() ){ |
|
3952 | - throw new EE_Error(sprintf(__("You tried storing a model object with NO ID in the %s entity mapper.", "event_espresso"),get_class($this))); |
|
3951 | + if ( ! $object->ID()) { |
|
3952 | + throw new EE_Error(sprintf(__("You tried storing a model object with NO ID in the %s entity mapper.", "event_espresso"), get_class($this))); |
|
3953 | 3953 | } |
3954 | 3954 | // double check it's not already there |
3955 | - $classInstance = $this->get_from_entity_map( $object->ID() ); |
|
3956 | - if ( $classInstance ) { |
|
3955 | + $classInstance = $this->get_from_entity_map($object->ID()); |
|
3956 | + if ($classInstance) { |
|
3957 | 3957 | return $classInstance; |
3958 | 3958 | } else { |
3959 | - $this->_entity_map[ $object->ID() ] = $object; |
|
3959 | + $this->_entity_map[$object->ID()] = $object; |
|
3960 | 3960 | return $object; |
3961 | 3961 | } |
3962 | 3962 | } |
@@ -3969,8 +3969,8 @@ discard block |
||
3969 | 3969 | * @param array $cols_n_values |
3970 | 3970 | * @return array |
3971 | 3971 | */ |
3972 | - public function deduce_fields_n_values_from_cols_n_values( $cols_n_values ) { |
|
3973 | - return $this->_deduce_fields_n_values_from_cols_n_values( $cols_n_values ); |
|
3972 | + public function deduce_fields_n_values_from_cols_n_values($cols_n_values) { |
|
3973 | + return $this->_deduce_fields_n_values_from_cols_n_values($cols_n_values); |
|
3974 | 3974 | } |
3975 | 3975 | |
3976 | 3976 | |
@@ -3983,40 +3983,40 @@ discard block |
||
3983 | 3983 | * @param string $cols_n_values |
3984 | 3984 | * @return array |
3985 | 3985 | */ |
3986 | - protected function _deduce_fields_n_values_from_cols_n_values( $cols_n_values ){ |
|
3986 | + protected function _deduce_fields_n_values_from_cols_n_values($cols_n_values) { |
|
3987 | 3987 | $this_model_fields_n_values = array(); |
3988 | - foreach( $this->get_tables() as $table_alias => $table_obj ) { |
|
3989 | - $table_pk_value = $this->_get_column_value_with_table_alias_or_not($cols_n_values, $table_obj->get_fully_qualified_pk_column(), $table_obj->get_pk_column() ); |
|
3988 | + foreach ($this->get_tables() as $table_alias => $table_obj) { |
|
3989 | + $table_pk_value = $this->_get_column_value_with_table_alias_or_not($cols_n_values, $table_obj->get_fully_qualified_pk_column(), $table_obj->get_pk_column()); |
|
3990 | 3990 | //there is a primary key on this table and its not set. Use defaults for all its columns |
3991 | - if( $table_obj->get_pk_column() && $table_pk_value === NULL ){ |
|
3992 | - foreach( $this->_get_fields_for_table( $table_alias ) as $field_name => $field_obj ) { |
|
3993 | - if( ! $field_obj->is_db_only_field() ){ |
|
3991 | + if ($table_obj->get_pk_column() && $table_pk_value === NULL) { |
|
3992 | + foreach ($this->_get_fields_for_table($table_alias) as $field_name => $field_obj) { |
|
3993 | + if ( ! $field_obj->is_db_only_field()) { |
|
3994 | 3994 | //prepare field as if its coming from db |
3995 | - $prepared_value = $field_obj->prepare_for_set( $field_obj->get_default_value() ); |
|
3996 | - $this_model_fields_n_values[$field_name] = $field_obj->prepare_for_use_in_db( $prepared_value ); |
|
3995 | + $prepared_value = $field_obj->prepare_for_set($field_obj->get_default_value()); |
|
3996 | + $this_model_fields_n_values[$field_name] = $field_obj->prepare_for_use_in_db($prepared_value); |
|
3997 | 3997 | } |
3998 | 3998 | } |
3999 | - }else{ |
|
3999 | + } else { |
|
4000 | 4000 | //the table's rows existed. Use their values |
4001 | - foreach( $this->_get_fields_for_table( $table_alias ) as $field_name => $field_obj ) { |
|
4002 | - if( ! $field_obj->is_db_only_field() ) |
|
4003 | - $this_model_fields_n_values[$field_name] = $this->_get_column_value_with_table_alias_or_not($cols_n_values, $field_obj->get_qualified_column(), $field_obj->get_table_column() ); |
|
4001 | + foreach ($this->_get_fields_for_table($table_alias) as $field_name => $field_obj) { |
|
4002 | + if ( ! $field_obj->is_db_only_field()) |
|
4003 | + $this_model_fields_n_values[$field_name] = $this->_get_column_value_with_table_alias_or_not($cols_n_values, $field_obj->get_qualified_column(), $field_obj->get_table_column()); |
|
4004 | 4004 | } |
4005 | 4005 | } |
4006 | 4006 | } |
4007 | 4007 | return $this_model_fields_n_values; |
4008 | 4008 | } |
4009 | 4009 | |
4010 | - protected function _get_column_value_with_table_alias_or_not( $cols_n_values, $qualified_column, $regular_column ){ |
|
4010 | + protected function _get_column_value_with_table_alias_or_not($cols_n_values, $qualified_column, $regular_column) { |
|
4011 | 4011 | //ask the field what it think it's table_name.column_name should be, and call it the "qualified column" |
4012 | 4012 | //does the field on the model relate to this column retrieved from the db? |
4013 | 4013 | //or is it a db-only field? (not relating to the model) |
4014 | - if( isset( $cols_n_values[ $qualified_column ] ) ){ |
|
4015 | - $value = $cols_n_values[ $qualified_column ]; |
|
4014 | + if (isset($cols_n_values[$qualified_column])) { |
|
4015 | + $value = $cols_n_values[$qualified_column]; |
|
4016 | 4016 | |
4017 | - }elseif( isset( $cols_n_values[ $regular_column ] ) ){ |
|
4018 | - $value = $cols_n_values[ $regular_column ]; |
|
4019 | - }else{ |
|
4017 | + }elseif (isset($cols_n_values[$regular_column])) { |
|
4018 | + $value = $cols_n_values[$regular_column]; |
|
4019 | + } else { |
|
4020 | 4020 | $value = NULL; |
4021 | 4021 | } |
4022 | 4022 | |
@@ -4034,23 +4034,23 @@ discard block |
||
4034 | 4034 | * @param int|string $id |
4035 | 4035 | * @return EE_Base_Class |
4036 | 4036 | */ |
4037 | - public function refresh_entity_map_from_db( $id ){ |
|
4038 | - $obj_in_map = $this->get_from_entity_map( $id ); |
|
4039 | - if( $obj_in_map ){ |
|
4040 | - $wpdb_results = $this->_get_all_wpdb_results( array( array ( $this->get_primary_key_field()->get_name() => $id ), 'limit' => 1 ) ); |
|
4041 | - if( $wpdb_results && is_array( $wpdb_results ) ){ |
|
4042 | - $one_row = reset( $wpdb_results ); |
|
4043 | - foreach( $this->_deduce_fields_n_values_from_cols_n_values($one_row ) as $field_name => $db_value ) { |
|
4044 | - $obj_in_map->set_from_db( $field_name, $db_value ); |
|
4037 | + public function refresh_entity_map_from_db($id) { |
|
4038 | + $obj_in_map = $this->get_from_entity_map($id); |
|
4039 | + if ($obj_in_map) { |
|
4040 | + $wpdb_results = $this->_get_all_wpdb_results(array(array($this->get_primary_key_field()->get_name() => $id), 'limit' => 1)); |
|
4041 | + if ($wpdb_results && is_array($wpdb_results)) { |
|
4042 | + $one_row = reset($wpdb_results); |
|
4043 | + foreach ($this->_deduce_fields_n_values_from_cols_n_values($one_row) as $field_name => $db_value) { |
|
4044 | + $obj_in_map->set_from_db($field_name, $db_value); |
|
4045 | 4045 | } |
4046 | 4046 | //clear the cache of related model objects |
4047 | - foreach ( $this->relation_settings() as $relation_name => $relation_obj ){ |
|
4048 | - $obj_in_map->clear_cache($relation_name, NULL, TRUE ); |
|
4047 | + foreach ($this->relation_settings() as $relation_name => $relation_obj) { |
|
4048 | + $obj_in_map->clear_cache($relation_name, NULL, TRUE); |
|
4049 | 4049 | } |
4050 | 4050 | } |
4051 | 4051 | return $obj_in_map; |
4052 | - }else{ |
|
4053 | - return $this->get_one_by_ID( $id ); |
|
4052 | + } else { |
|
4053 | + return $this->get_one_by_ID($id); |
|
4054 | 4054 | } |
4055 | 4055 | } |
4056 | 4056 | |
@@ -4068,24 +4068,24 @@ discard block |
||
4068 | 4068 | * @param EE_Base_Class $replacing_model_obj |
4069 | 4069 | * @return \EE_Base_Class |
4070 | 4070 | */ |
4071 | - public function refresh_entity_map_with( $id, $replacing_model_obj ) { |
|
4072 | - $obj_in_map = $this->get_from_entity_map( $id ); |
|
4073 | - if( $obj_in_map ){ |
|
4074 | - if( $replacing_model_obj instanceof EE_Base_Class ){ |
|
4075 | - foreach( $replacing_model_obj->model_field_array() as $field_name => $value ) { |
|
4076 | - $obj_in_map->set( $field_name, $value ); |
|
4071 | + public function refresh_entity_map_with($id, $replacing_model_obj) { |
|
4072 | + $obj_in_map = $this->get_from_entity_map($id); |
|
4073 | + if ($obj_in_map) { |
|
4074 | + if ($replacing_model_obj instanceof EE_Base_Class) { |
|
4075 | + foreach ($replacing_model_obj->model_field_array() as $field_name => $value) { |
|
4076 | + $obj_in_map->set($field_name, $value); |
|
4077 | 4077 | } |
4078 | 4078 | //make the model object in the entity map's cache match the $replacing_model_obj |
4079 | - foreach ( $this->relation_settings() as $relation_name => $relation_obj ){ |
|
4080 | - $obj_in_map->clear_cache($relation_name, NULL, TRUE ); |
|
4081 | - foreach( $replacing_model_obj->get_all_from_cache( $relation_name ) as $cache_id => $cached_obj ) { |
|
4082 | - $obj_in_map->cache( $relation_name, $cached_obj, $cache_id ); |
|
4079 | + foreach ($this->relation_settings() as $relation_name => $relation_obj) { |
|
4080 | + $obj_in_map->clear_cache($relation_name, NULL, TRUE); |
|
4081 | + foreach ($replacing_model_obj->get_all_from_cache($relation_name) as $cache_id => $cached_obj) { |
|
4082 | + $obj_in_map->cache($relation_name, $cached_obj, $cache_id); |
|
4083 | 4083 | } |
4084 | 4084 | } |
4085 | 4085 | } |
4086 | 4086 | return $obj_in_map; |
4087 | - }else{ |
|
4088 | - $this->add_to_entity_map( $replacing_model_obj ); |
|
4087 | + } else { |
|
4088 | + $this->add_to_entity_map($replacing_model_obj); |
|
4089 | 4089 | return $replacing_model_obj; |
4090 | 4090 | } |
4091 | 4091 | } |
@@ -4098,7 +4098,7 @@ discard block |
||
4098 | 4098 | * require_once($this->_getClassName().".class.php"); |
4099 | 4099 | * @return string |
4100 | 4100 | */ |
4101 | - private function _get_class_name(){ |
|
4101 | + private function _get_class_name() { |
|
4102 | 4102 | return "EE_".$this->get_this_model_name(); |
4103 | 4103 | } |
4104 | 4104 | |
@@ -4111,10 +4111,10 @@ discard block |
||
4111 | 4111 | * @param int $quantity |
4112 | 4112 | * @return string |
4113 | 4113 | */ |
4114 | - public function item_name($quantity = 1){ |
|
4115 | - if($quantity == 1){ |
|
4114 | + public function item_name($quantity = 1) { |
|
4115 | + if ($quantity == 1) { |
|
4116 | 4116 | return $this->singular_item; |
4117 | - }else{ |
|
4117 | + } else { |
|
4118 | 4118 | return $this->plural_item; |
4119 | 4119 | } |
4120 | 4120 | } |
@@ -4143,13 +4143,13 @@ discard block |
||
4143 | 4143 | * @throws EE_Error |
4144 | 4144 | * @return mixed whatever the plugin which calls add_filter decides |
4145 | 4145 | */ |
4146 | - public function __call($methodName,$args){ |
|
4147 | - $className=get_class($this); |
|
4148 | - $tagName="FHEE__{$className}__{$methodName}"; |
|
4149 | - if(!has_filter($tagName)){ |
|
4146 | + public function __call($methodName, $args) { |
|
4147 | + $className = get_class($this); |
|
4148 | + $tagName = "FHEE__{$className}__{$methodName}"; |
|
4149 | + if ( ! has_filter($tagName)) { |
|
4150 | 4150 | throw new EE_Error( |
4151 | 4151 | sprintf( |
4152 | - __( 'Method %1$s on model %2$s does not exist! You can create one with the following code in functions.php or in a plugin: %4$s function my_callback(%4$s \$previousReturnValue, EEM_Base \$object\ $argsArray=NULL ){%4$s /*function body*/%4$s return \$whatever;%4$s }%4$s add_filter( \'%3$s\', \'my_callback\', 10, 3 );', 'event_espresso' ), |
|
4152 | + __('Method %1$s on model %2$s does not exist! You can create one with the following code in functions.php or in a plugin: %4$s function my_callback(%4$s \$previousReturnValue, EEM_Base \$object\ $argsArray=NULL ){%4$s /*function body*/%4$s return \$whatever;%4$s }%4$s add_filter( \'%3$s\', \'my_callback\', 10, 3 );', 'event_espresso'), |
|
4153 | 4153 | $methodName, |
4154 | 4154 | $className, |
4155 | 4155 | $tagName, |
@@ -4158,7 +4158,7 @@ discard block |
||
4158 | 4158 | ); |
4159 | 4159 | } |
4160 | 4160 | |
4161 | - return apply_filters($tagName,null,$this,$args); |
|
4161 | + return apply_filters($tagName, null, $this, $args); |
|
4162 | 4162 | } |
4163 | 4163 | |
4164 | 4164 | |
@@ -4171,22 +4171,22 @@ discard block |
||
4171 | 4171 | * @throws EE_Error |
4172 | 4172 | * @return EE_Base_Class |
4173 | 4173 | */ |
4174 | - public function ensure_is_obj( $base_class_obj_or_id, $ensure_is_in_db = FALSE ){ |
|
4174 | + public function ensure_is_obj($base_class_obj_or_id, $ensure_is_in_db = FALSE) { |
|
4175 | 4175 | $className = $this->_get_class_name(); |
4176 | 4176 | $primary_key_field = $this->get_primary_key_field(); |
4177 | - if( $base_class_obj_or_id instanceof $className ){ |
|
4177 | + if ($base_class_obj_or_id instanceof $className) { |
|
4178 | 4178 | $model_object = $base_class_obj_or_id; |
4179 | - }elseif( $primary_key_field instanceof EE_Primary_Key_Int_Field && ( |
|
4180 | - is_int( $base_class_obj_or_id ) || |
|
4181 | - is_string( $base_class_obj_or_id ) )){//assume it's an ID. either a proper integer or a string representing an integer (eg "101" instead of 101) |
|
4179 | + }elseif ($primary_key_field instanceof EE_Primary_Key_Int_Field && ( |
|
4180 | + is_int($base_class_obj_or_id) || |
|
4181 | + is_string($base_class_obj_or_id) )) {//assume it's an ID. either a proper integer or a string representing an integer (eg "101" instead of 101) |
|
4182 | 4182 | $model_object = $this->get_one_by_ID($base_class_obj_or_id); |
4183 | - }elseif( $primary_key_field instanceof EE_Primary_Key_String_Field && is_string($base_class_obj_or_id) ){ |
|
4183 | + }elseif ($primary_key_field instanceof EE_Primary_Key_String_Field && is_string($base_class_obj_or_id)) { |
|
4184 | 4184 | //assume its a string representation of the object |
4185 | 4185 | $model_object = $this->get_one_by_ID($base_class_obj_or_id); |
4186 | - }else{ |
|
4187 | - throw new EE_Error(sprintf(__("'%s' is neither an object of type %s, nor an ID! Its full value is '%s'",'event_espresso'),$base_class_obj_or_id,$this->_get_class_name(),print_r($base_class_obj_or_id,true))); |
|
4186 | + } else { |
|
4187 | + throw new EE_Error(sprintf(__("'%s' is neither an object of type %s, nor an ID! Its full value is '%s'", 'event_espresso'), $base_class_obj_or_id, $this->_get_class_name(), print_r($base_class_obj_or_id, true))); |
|
4188 | 4188 | } |
4189 | - if( $model_object->ID() == NULL && $ensure_is_in_db){ |
|
4189 | + if ($model_object->ID() == NULL && $ensure_is_in_db) { |
|
4190 | 4190 | $model_object->save(); |
4191 | 4191 | } |
4192 | 4192 | return $model_object; |
@@ -4202,19 +4202,19 @@ discard block |
||
4202 | 4202 | * @return int|string depending on the type of this model object's ID |
4203 | 4203 | * @throws EE_Error |
4204 | 4204 | */ |
4205 | - public function ensure_is_ID($base_class_obj_or_id){ |
|
4205 | + public function ensure_is_ID($base_class_obj_or_id) { |
|
4206 | 4206 | $className = $this->_get_class_name(); |
4207 | - if( $base_class_obj_or_id instanceof $className ){ |
|
4207 | + if ($base_class_obj_or_id instanceof $className) { |
|
4208 | 4208 | /** @var $base_class_obj_or_id EE_Base_Class */ |
4209 | 4209 | $id = $base_class_obj_or_id->ID(); |
4210 | - }elseif(is_int($base_class_obj_or_id)){ |
|
4210 | + }elseif (is_int($base_class_obj_or_id)) { |
|
4211 | 4211 | //assume it's an ID |
4212 | 4212 | $id = $base_class_obj_or_id; |
4213 | - }elseif(is_string($base_class_obj_or_id)){ |
|
4213 | + }elseif (is_string($base_class_obj_or_id)) { |
|
4214 | 4214 | //assume its a string representation of the object |
4215 | 4215 | $id = $base_class_obj_or_id; |
4216 | - }else{ |
|
4217 | - throw new EE_Error(sprintf(__("'%s' is neither an object of type %s, nor an ID! Its full value is '%s'",'event_espresso'),$base_class_obj_or_id,$this->_get_class_name(),print_r($base_class_obj_or_id,true))); |
|
4216 | + } else { |
|
4217 | + throw new EE_Error(sprintf(__("'%s' is neither an object of type %s, nor an ID! Its full value is '%s'", 'event_espresso'), $base_class_obj_or_id, $this->_get_class_name(), print_r($base_class_obj_or_id, true))); |
|
4218 | 4218 | } |
4219 | 4219 | return $id; |
4220 | 4220 | } |
@@ -4237,14 +4237,14 @@ discard block |
||
4237 | 4237 | * @param int $values_already_prepared like one of the constants on EEM_Base |
4238 | 4238 | * @return void |
4239 | 4239 | */ |
4240 | - public function assume_values_already_prepared_by_model_object($values_already_prepared = self::not_prepared_by_model_object){ |
|
4240 | + public function assume_values_already_prepared_by_model_object($values_already_prepared = self::not_prepared_by_model_object) { |
|
4241 | 4241 | $this->_values_already_prepared_by_model_object = $values_already_prepared; |
4242 | 4242 | } |
4243 | 4243 | /** |
4244 | 4244 | * Read comments for assume_values_already_prepared_by_model_object() |
4245 | 4245 | * @return int |
4246 | 4246 | */ |
4247 | - public function get_assumption_concerning_values_already_prepared_by_model_object(){ |
|
4247 | + public function get_assumption_concerning_values_already_prepared_by_model_object() { |
|
4248 | 4248 | return $this->_values_already_prepared_by_model_object; |
4249 | 4249 | } |
4250 | 4250 | |
@@ -4252,17 +4252,17 @@ discard block |
||
4252 | 4252 | * Gets all the indexes on this model |
4253 | 4253 | * @return EE_Index[] |
4254 | 4254 | */ |
4255 | - public function indexes(){ |
|
4255 | + public function indexes() { |
|
4256 | 4256 | return $this->_indexes; |
4257 | 4257 | } |
4258 | 4258 | /** |
4259 | 4259 | * Gets all the Unique Indexes on this model |
4260 | 4260 | * @return EE_Unique_Index[] |
4261 | 4261 | */ |
4262 | - public function unique_indexes(){ |
|
4262 | + public function unique_indexes() { |
|
4263 | 4263 | $unique_indexes = array(); |
4264 | - foreach($this->_indexes as $name => $index){ |
|
4265 | - if($index instanceof EE_Unique_Index){ |
|
4264 | + foreach ($this->_indexes as $name => $index) { |
|
4265 | + if ($index instanceof EE_Unique_Index) { |
|
4266 | 4266 | $unique_indexes [$name] = $index; |
4267 | 4267 | } |
4268 | 4268 | } |
@@ -4275,9 +4275,9 @@ discard block |
||
4275 | 4275 | * on a primary index |
4276 | 4276 | * @return EE_Model_Field_Base[] |
4277 | 4277 | */ |
4278 | - public function get_combined_primary_key_fields(){ |
|
4279 | - foreach($this->indexes() as $index){ |
|
4280 | - if($index instanceof EE_Primary_Key_Index){ |
|
4278 | + public function get_combined_primary_key_fields() { |
|
4279 | + foreach ($this->indexes() as $index) { |
|
4280 | + if ($index instanceof EE_Primary_Key_Index) { |
|
4281 | 4281 | return $index->fields(); |
4282 | 4282 | } |
4283 | 4283 | } |
@@ -4290,7 +4290,7 @@ discard block |
||
4290 | 4290 | * @param array $cols_n_values keys are field names, values are their values |
4291 | 4291 | * @return string |
4292 | 4292 | */ |
4293 | - public function get_index_primary_key_string($cols_n_values){ |
|
4293 | + public function get_index_primary_key_string($cols_n_values) { |
|
4294 | 4294 | $cols_n_values_for_primary_key_index = array_intersect_key($cols_n_values, $this->get_combined_primary_key_fields()); |
4295 | 4295 | return http_build_query($cols_n_values_for_primary_key_index); |
4296 | 4296 | } |
@@ -4302,13 +4302,13 @@ discard block |
||
4302 | 4302 | * @param string $index_primary_key_string |
4303 | 4303 | * @return null|array |
4304 | 4304 | */ |
4305 | - function parse_index_primary_key_string( $index_primary_key_string) { |
|
4305 | + function parse_index_primary_key_string($index_primary_key_string) { |
|
4306 | 4306 | $key_fields = $this->get_combined_primary_key_fields(); |
4307 | 4307 | //check all of them are in the $id |
4308 | 4308 | $key_vals_in_combined_pk = array(); |
4309 | - parse_str( $index_primary_key_string, $key_vals_in_combined_pk ); |
|
4310 | - foreach( $key_fields as $key_field_name => $field_obj ) { |
|
4311 | - if( ! isset( $key_vals_in_combined_pk[ $key_field_name ] ) ){ |
|
4309 | + parse_str($index_primary_key_string, $key_vals_in_combined_pk); |
|
4310 | + foreach ($key_fields as $key_field_name => $field_obj) { |
|
4311 | + if ( ! isset($key_vals_in_combined_pk[$key_field_name])) { |
|
4312 | 4312 | return NULL; |
4313 | 4313 | } |
4314 | 4314 | } |
@@ -4321,10 +4321,10 @@ discard block |
||
4321 | 4321 | * @param array $key_vals |
4322 | 4322 | * @return boolean |
4323 | 4323 | */ |
4324 | - function has_all_combined_primary_key_fields( $key_vals ) { |
|
4325 | - $keys_it_should_have = array_keys( $this->get_combined_primary_key_fields() ); |
|
4326 | - foreach( $keys_it_should_have as $key ){ |
|
4327 | - if( ! isset( $key_vals[ $key ] ) ){ |
|
4324 | + function has_all_combined_primary_key_fields($key_vals) { |
|
4325 | + $keys_it_should_have = array_keys($this->get_combined_primary_key_fields()); |
|
4326 | + foreach ($keys_it_should_have as $key) { |
|
4327 | + if ( ! isset($key_vals[$key])) { |
|
4328 | 4328 | return false; |
4329 | 4329 | } |
4330 | 4330 | } |
@@ -4340,23 +4340,23 @@ discard block |
||
4340 | 4340 | * @throws EE_Error |
4341 | 4341 | * @return \EE_Base_Class[] Array keys are object IDs (if there is a primary key on the model. if not, numerically indexed) |
4342 | 4342 | */ |
4343 | - public function get_all_copies($model_object_or_attributes_array, $query_params = array()){ |
|
4343 | + public function get_all_copies($model_object_or_attributes_array, $query_params = array()) { |
|
4344 | 4344 | |
4345 | - if($model_object_or_attributes_array instanceof EE_Base_Class){ |
|
4345 | + if ($model_object_or_attributes_array instanceof EE_Base_Class) { |
|
4346 | 4346 | $attributes_array = $model_object_or_attributes_array->model_field_array(); |
4347 | - }elseif(is_array($model_object_or_attributes_array)){ |
|
4347 | + }elseif (is_array($model_object_or_attributes_array)) { |
|
4348 | 4348 | $attributes_array = $model_object_or_attributes_array; |
4349 | - }else{ |
|
4350 | - throw new EE_Error(sprintf(__("get_all_copies should be provided with either a model object or an array of field-value-pairs, but was given %s", "event_espresso"),$model_object_or_attributes_array)); |
|
4349 | + } else { |
|
4350 | + throw new EE_Error(sprintf(__("get_all_copies should be provided with either a model object or an array of field-value-pairs, but was given %s", "event_espresso"), $model_object_or_attributes_array)); |
|
4351 | 4351 | } |
4352 | 4352 | //even copies obviously won't have the same ID, so remove the primary key |
4353 | 4353 | //from the WHERE conditions for finding copies (if there is a primary key, of course) |
4354 | - if($this->has_primary_key_field() && isset($attributes_array[$this->primary_key_name()])){ |
|
4354 | + if ($this->has_primary_key_field() && isset($attributes_array[$this->primary_key_name()])) { |
|
4355 | 4355 | unset($attributes_array[$this->primary_key_name()]); |
4356 | 4356 | } |
4357 | - if(isset($query_params[0])){ |
|
4358 | - $query_params[0] = array_merge($attributes_array,$query_params); |
|
4359 | - }else{ |
|
4357 | + if (isset($query_params[0])) { |
|
4358 | + $query_params[0] = array_merge($attributes_array, $query_params); |
|
4359 | + } else { |
|
4360 | 4360 | $query_params[0] = $attributes_array; |
4361 | 4361 | } |
4362 | 4362 | return $this->get_all($query_params); |
@@ -4370,16 +4370,16 @@ discard block |
||
4370 | 4370 | * @param array $query_params |
4371 | 4371 | * @return EE_Base_Class |
4372 | 4372 | */ |
4373 | - function get_one_copy($model_object_or_attributes_array,$query_params = array()){ |
|
4374 | - if( ! is_array( $query_params ) ){ |
|
4375 | - EE_Error::doing_it_wrong('EEM_Base::get_one_copy', sprintf( __( '$query_params should be an array, you passed a variable of type %s', 'event_espresso' ), gettype( $query_params ) ), '4.6.0' ); |
|
4373 | + function get_one_copy($model_object_or_attributes_array, $query_params = array()) { |
|
4374 | + if ( ! is_array($query_params)) { |
|
4375 | + EE_Error::doing_it_wrong('EEM_Base::get_one_copy', sprintf(__('$query_params should be an array, you passed a variable of type %s', 'event_espresso'), gettype($query_params)), '4.6.0'); |
|
4376 | 4376 | $query_params = array(); |
4377 | 4377 | } |
4378 | 4378 | $query_params['limit'] = 1; |
4379 | - $copies = $this->get_all_copies($model_object_or_attributes_array,$query_params); |
|
4380 | - if(is_array($copies)){ |
|
4379 | + $copies = $this->get_all_copies($model_object_or_attributes_array, $query_params); |
|
4380 | + if (is_array($copies)) { |
|
4381 | 4381 | return array_shift($copies); |
4382 | - }else{ |
|
4382 | + } else { |
|
4383 | 4383 | return null; |
4384 | 4384 | } |
4385 | 4385 | } |
@@ -4393,10 +4393,10 @@ discard block |
||
4393 | 4393 | * @param int|string $id the value of the primary key to update |
4394 | 4394 | * @return int number of rows updated |
4395 | 4395 | */ |
4396 | - public function update_by_ID($fields_n_values,$id){ |
|
4396 | + public function update_by_ID($fields_n_values, $id) { |
|
4397 | 4397 | $query_params = array(0=>array($this->get_primary_key_field()->get_name() => $id), |
4398 | 4398 | 'default_where_conditions'=>'other_models_only',); |
4399 | - return $this->update($fields_n_values,$query_params); |
|
4399 | + return $this->update($fields_n_values, $query_params); |
|
4400 | 4400 | } |
4401 | 4401 | |
4402 | 4402 | |
@@ -4407,12 +4407,12 @@ discard block |
||
4407 | 4407 | * @return string an operator which can be used in SQL |
4408 | 4408 | * @throws EE_Error |
4409 | 4409 | */ |
4410 | - private function _prepare_operator_for_sql($operator_supplied){ |
|
4410 | + private function _prepare_operator_for_sql($operator_supplied) { |
|
4411 | 4411 | $sql_operator = isset($this->_valid_operators[$operator_supplied]) ? $this->_valid_operators[$operator_supplied] : null; |
4412 | - if($sql_operator){ |
|
4412 | + if ($sql_operator) { |
|
4413 | 4413 | return $sql_operator; |
4414 | - }else{ |
|
4415 | - throw new EE_Error(sprintf(__("The operator '%s' is not in the list of valid operators: %s", "event_espresso"),$operator_supplied,implode(",",array_keys($this->_valid_operators)))); |
|
4414 | + } else { |
|
4415 | + throw new EE_Error(sprintf(__("The operator '%s' is not in the list of valid operators: %s", "event_espresso"), $operator_supplied, implode(",", array_keys($this->_valid_operators)))); |
|
4416 | 4416 | } |
4417 | 4417 | } |
4418 | 4418 | |
@@ -4422,10 +4422,10 @@ discard block |
||
4422 | 4422 | * @param array $query_params like get_all's |
4423 | 4423 | * @return string[] |
4424 | 4424 | */ |
4425 | - public function get_all_names($query_params = array()){ |
|
4425 | + public function get_all_names($query_params = array()) { |
|
4426 | 4426 | $objs = $this->get_all($query_params); |
4427 | 4427 | $names = array(); |
4428 | - foreach($objs as $obj){ |
|
4428 | + foreach ($objs as $obj) { |
|
4429 | 4429 | $names[$obj->ID()] = $obj->name(); |
4430 | 4430 | } |
4431 | 4431 | return $names; |
@@ -4440,22 +4440,22 @@ discard block |
||
4440 | 4440 | * @param boolean $filter_out_empty_ids if a model object has an ID of '' or 0, don't bother including it in the returned array |
4441 | 4441 | * @return array |
4442 | 4442 | */ |
4443 | - public function get_IDs( $model_objects, $filter_out_empty_ids = false) { |
|
4444 | - if( ! $this->has_primary_key_field() ) { |
|
4445 | - if( WP_DEBUG ) { |
|
4446 | - EE_Error::add_error( __( 'Trying to get IDs from a model than has no primary key', 'event_espresso' ), __FILE__, __FUNCTION__, __LINE__ ); |
|
4443 | + public function get_IDs($model_objects, $filter_out_empty_ids = false) { |
|
4444 | + if ( ! $this->has_primary_key_field()) { |
|
4445 | + if (WP_DEBUG) { |
|
4446 | + EE_Error::add_error(__('Trying to get IDs from a model than has no primary key', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__); |
|
4447 | 4447 | return array(); |
4448 | 4448 | } |
4449 | 4449 | } |
4450 | 4450 | $IDs = array(); |
4451 | - foreach( $model_objects as $model_object ) { |
|
4451 | + foreach ($model_objects as $model_object) { |
|
4452 | 4452 | $id = $model_object->ID(); |
4453 | - if( ! $id ) { |
|
4454 | - if( $filter_out_empty_ids ) { |
|
4453 | + if ( ! $id) { |
|
4454 | + if ($filter_out_empty_ids) { |
|
4455 | 4455 | continue; |
4456 | 4456 | } |
4457 | - if( WP_DEBUG ) { |
|
4458 | - EE_Error::add_error(__( 'Called %1$s on a model object that has no ID and so probably hasn\'t been saved to the database', 'event_espresso' ), __FILE__, __FUNCTION__, __LINE__ ); |
|
4457 | + if (WP_DEBUG) { |
|
4458 | + EE_Error::add_error(__('Called %1$s on a model object that has no ID and so probably hasn\'t been saved to the database', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__); |
|
4459 | 4459 | } |
4460 | 4460 | } |
4461 | 4461 | $IDs[] = $id; |
@@ -4468,8 +4468,8 @@ discard block |
||
4468 | 4468 | * are no capabilities that relate to this model returns false |
4469 | 4469 | * @return string|false |
4470 | 4470 | */ |
4471 | - public function cap_slug(){ |
|
4472 | - return apply_filters( 'FHEE__EEM_Base__cap_slug', $this->_caps_slug, $this); |
|
4471 | + public function cap_slug() { |
|
4472 | + return apply_filters('FHEE__EEM_Base__cap_slug', $this->_caps_slug, $this); |
|
4473 | 4473 | } |
4474 | 4474 | |
4475 | 4475 | /** |
@@ -4481,27 +4481,27 @@ discard block |
||
4481 | 4481 | * @param string $context |
4482 | 4482 | * @return EE_Default_Where_Conditions[] indexed by associated capability |
4483 | 4483 | */ |
4484 | - public function cap_restrictions( $context = EEM_Base::caps_read ) { |
|
4485 | - EEM_Base::verify_is_valid_cap_context( $context ); |
|
4484 | + public function cap_restrictions($context = EEM_Base::caps_read) { |
|
4485 | + EEM_Base::verify_is_valid_cap_context($context); |
|
4486 | 4486 | //check if we ought to run the restriction generator first |
4487 | - if( isset( $this->_cap_restriction_generators[ $context ] ) && |
|
4488 | - $this->_cap_restriction_generators[ $context ] instanceof EE_Restriction_Generator_Base && |
|
4489 | - ! $this->_cap_restriction_generators[ $context ]->has_generated_cap_restrictions() ) { |
|
4490 | - $this->_cap_restrictions[ $context ] = array_merge( $this->_cap_restrictions[ $context ], $this->_cap_restriction_generators[ $context ]->generate_restrictions() ); |
|
4487 | + if (isset($this->_cap_restriction_generators[$context]) && |
|
4488 | + $this->_cap_restriction_generators[$context] instanceof EE_Restriction_Generator_Base && |
|
4489 | + ! $this->_cap_restriction_generators[$context]->has_generated_cap_restrictions()) { |
|
4490 | + $this->_cap_restrictions[$context] = array_merge($this->_cap_restrictions[$context], $this->_cap_restriction_generators[$context]->generate_restrictions()); |
|
4491 | 4491 | } |
4492 | 4492 | //and make sure we've finalized the construction of each restriction |
4493 | - foreach( $this->_cap_restrictions[ $context ] as $where_conditions_obj ) { |
|
4494 | - $where_conditions_obj->_finalize_construct( $this ); |
|
4493 | + foreach ($this->_cap_restrictions[$context] as $where_conditions_obj) { |
|
4494 | + $where_conditions_obj->_finalize_construct($this); |
|
4495 | 4495 | } |
4496 | 4496 | |
4497 | - return $this->_cap_restrictions[ $context ]; |
|
4497 | + return $this->_cap_restrictions[$context]; |
|
4498 | 4498 | } |
4499 | 4499 | |
4500 | 4500 | /** |
4501 | 4501 | * Indicating whether or not this model thinks its a wp core model |
4502 | 4502 | * @return boolean |
4503 | 4503 | */ |
4504 | - public function is_wp_core_model(){ |
|
4504 | + public function is_wp_core_model() { |
|
4505 | 4505 | return $this->_wp_core_model; |
4506 | 4506 | } |
4507 | 4507 | |
@@ -4511,12 +4511,12 @@ discard block |
||
4511 | 4511 | * @param string $context one of EEM_Base::caps_ constants |
4512 | 4512 | * @return EE_Default_Where_Conditions[] indexed by capability name |
4513 | 4513 | */ |
4514 | - public function caps_missing( $context = EEM_Base::caps_read ) { |
|
4514 | + public function caps_missing($context = EEM_Base::caps_read) { |
|
4515 | 4515 | $missing_caps = array(); |
4516 | - $cap_restrictions = $this->cap_restrictions( $context ); |
|
4517 | - foreach( $cap_restrictions as $cap => $restriction_if_no_cap ) { |
|
4518 | - if( ! EE_Capabilities::instance()->current_user_can( $cap, $this->get_this_model_name() . '_model_applying_caps') ) { |
|
4519 | - $missing_caps[ $cap ] = $restriction_if_no_cap; |
|
4516 | + $cap_restrictions = $this->cap_restrictions($context); |
|
4517 | + foreach ($cap_restrictions as $cap => $restriction_if_no_cap) { |
|
4518 | + if ( ! EE_Capabilities::instance()->current_user_can($cap, $this->get_this_model_name().'_model_applying_caps')) { |
|
4519 | + $missing_caps[$cap] = $restriction_if_no_cap; |
|
4520 | 4520 | } |
4521 | 4521 | } |
4522 | 4522 | return $missing_caps; |
@@ -4528,7 +4528,7 @@ discard block |
||
4528 | 4528 | * one of 'read', 'edit', or 'delete' |
4529 | 4529 | */ |
4530 | 4530 | public function cap_contexts_to_cap_action_map() { |
4531 | - return apply_filters( 'FHEE__EEM_Base__cap_contexts_to_cap_action_map', $this->_cap_contexts_to_cap_action_map, $this ); |
|
4531 | + return apply_filters('FHEE__EEM_Base__cap_contexts_to_cap_action_map', $this->_cap_contexts_to_cap_action_map, $this); |
|
4532 | 4532 | } |
4533 | 4533 | |
4534 | 4534 | |
@@ -4539,19 +4539,19 @@ discard block |
||
4539 | 4539 | * @return string one of EEM_Base::cap_contexts_to_cap_action_map() values |
4540 | 4540 | * @throws \EE_Error |
4541 | 4541 | */ |
4542 | - public function cap_action_for_context( $context ) { |
|
4542 | + public function cap_action_for_context($context) { |
|
4543 | 4543 | $mapping = $this->cap_contexts_to_cap_action_map(); |
4544 | - if( isset( $mapping[ $context ] ) ) { |
|
4545 | - return $mapping[ $context ]; |
|
4544 | + if (isset($mapping[$context])) { |
|
4545 | + return $mapping[$context]; |
|
4546 | 4546 | } |
4547 | - if( $action = apply_filters( 'FHEE__EEM_Base__cap_action_for_context', null, $this, $mapping, $context ) ) { |
|
4547 | + if ($action = apply_filters('FHEE__EEM_Base__cap_action_for_context', null, $this, $mapping, $context)) { |
|
4548 | 4548 | return $action; |
4549 | 4549 | } |
4550 | 4550 | throw new EE_Error( |
4551 | 4551 | sprintf( |
4552 | - __( 'Cannot find capability restrictions for context "%1$s", allowed values are:%2$s', 'event_espresso' ), |
|
4552 | + __('Cannot find capability restrictions for context "%1$s", allowed values are:%2$s', 'event_espresso'), |
|
4553 | 4553 | $context, |
4554 | - implode(',', array_keys( $this->cap_contexts_to_cap_action_map() ) ) |
|
4554 | + implode(',', array_keys($this->cap_contexts_to_cap_action_map())) |
|
4555 | 4555 | ) |
4556 | 4556 | ); |
4557 | 4557 | |
@@ -4562,7 +4562,7 @@ discard block |
||
4562 | 4562 | * @return array |
4563 | 4563 | */ |
4564 | 4564 | static public function valid_cap_contexts() { |
4565 | - return apply_filters( 'FHEE__EEM_Base__valid_cap_contexts', array( |
|
4565 | + return apply_filters('FHEE__EEM_Base__valid_cap_contexts', array( |
|
4566 | 4566 | self::caps_read, |
4567 | 4567 | self::caps_read_admin, |
4568 | 4568 | self::caps_edit, |
@@ -4578,17 +4578,17 @@ discard block |
||
4578 | 4578 | * @return bool |
4579 | 4579 | * @throws \EE_Error |
4580 | 4580 | */ |
4581 | - static public function verify_is_valid_cap_context( $context ) { |
|
4581 | + static public function verify_is_valid_cap_context($context) { |
|
4582 | 4582 | $valid_cap_contexts = EEM_Base::valid_cap_contexts(); |
4583 | - if( in_array( $context, $valid_cap_contexts ) ) { |
|
4583 | + if (in_array($context, $valid_cap_contexts)) { |
|
4584 | 4584 | return true; |
4585 | - }else{ |
|
4585 | + } else { |
|
4586 | 4586 | throw new EE_Error( |
4587 | 4587 | sprintf( |
4588 | - __( 'Context "%1$s" passed into model "%2$s" is not a valid context. They are: %3$s', 'event_espresso' ), |
|
4588 | + __('Context "%1$s" passed into model "%2$s" is not a valid context. They are: %3$s', 'event_espresso'), |
|
4589 | 4589 | $context, |
4590 | - 'EEM_Base' , |
|
4591 | - implode(',', $valid_cap_contexts ) |
|
4590 | + 'EEM_Base', |
|
4591 | + implode(',', $valid_cap_contexts) |
|
4592 | 4592 | ) |
4593 | 4593 | ); |
4594 | 4594 | } |
@@ -546,7 +546,7 @@ discard block |
||
546 | 546 | if( isset( $this->_cap_restriction_generators[ $context ] ) && |
547 | 547 | $this->_cap_restriction_generators[ $context ] instanceof EE_Restriction_Generator_Base ) { |
548 | 548 | return $this->_cap_restriction_generators[ $context ]->generate_restrictions(); |
549 | - }else{ |
|
549 | + } else{ |
|
550 | 550 | return array(); |
551 | 551 | } |
552 | 552 | } |
@@ -597,8 +597,9 @@ discard block |
||
597 | 597 | * @return array |
598 | 598 | */ |
599 | 599 | public function status_array( $translated = FALSE ) { |
600 | - if ( !array_key_exists('Status', $this->_model_relations ) ) |
|
601 | - return array(); |
|
600 | + if ( !array_key_exists('Status', $this->_model_relations ) ) { |
|
601 | + return array(); |
|
602 | + } |
|
602 | 603 | $model_name = $this->get_this_model_name(); |
603 | 604 | $status_type = str_replace(' ', '_', strtolower( str_replace('_', ' ', $model_name) ) ); |
604 | 605 | $stati = EEM_Status::instance()->get_all(array(array('STS_type' => $status_type) ) ); |
@@ -819,13 +820,13 @@ discard block |
||
819 | 820 | $last_model_name = end( $models_to_follow_to_wp_users ); |
820 | 821 | $model_with_fk_to_wp_users = EE_Registry::instance()->load_model( $last_model_name ); |
821 | 822 | $model_chain_to_wp_user = $this->_model_chain_to_wp_user . '.'; |
822 | - }else{ |
|
823 | + } else{ |
|
823 | 824 | $model_with_fk_to_wp_users = $this; |
824 | 825 | $model_chain_to_wp_user = ''; |
825 | 826 | } |
826 | 827 | $wp_user_field = $model_with_fk_to_wp_users->get_foreign_key_to( 'WP_User' ); |
827 | 828 | return $model_chain_to_wp_user . $wp_user_field->get_name(); |
828 | - }catch( EE_Error $e ) { |
|
829 | + } catch( EE_Error $e ) { |
|
829 | 830 | return false; |
830 | 831 | } |
831 | 832 | } |
@@ -853,11 +854,11 @@ discard block |
||
853 | 854 | public function is_owned() { |
854 | 855 | if( $this->model_chain_to_wp_user() ){ |
855 | 856 | return true; |
856 | - }else{ |
|
857 | + } else{ |
|
857 | 858 | try{ |
858 | 859 | $this->get_foreign_key_to( 'WP_User' ); |
859 | 860 | return true; |
860 | - }catch( EE_Error $e ){ |
|
861 | + } catch( EE_Error $e ){ |
|
861 | 862 | return false; |
862 | 863 | } |
863 | 864 | } |
@@ -880,9 +881,9 @@ discard block |
||
880 | 881 | //remember the custom selections, if any |
881 | 882 | if(is_array($columns_to_select)){ |
882 | 883 | $this->_custom_selections = $columns_to_select; |
883 | - }elseif(is_string($columns_to_select)){ |
|
884 | + } elseif(is_string($columns_to_select)){ |
|
884 | 885 | $this->_custom_selections = array($this->_custom_selections); |
885 | - }else{ |
|
886 | + } else{ |
|
886 | 887 | $this->_custom_selections = array(); |
887 | 888 | } |
888 | 889 | |
@@ -954,7 +955,7 @@ discard block |
||
954 | 955 | $select_sql_array[] = "{$selection_and_datatype[0]} AS $alias"; |
955 | 956 | } |
956 | 957 | $columns_to_select_string = implode(", ",$select_sql_array); |
957 | - }else{ |
|
958 | + } else{ |
|
958 | 959 | $columns_to_select_string = $columns_to_select; |
959 | 960 | } |
960 | 961 | return $columns_to_select_string; |
@@ -1004,7 +1005,7 @@ discard block |
||
1004 | 1005 | } |
1005 | 1006 | if( $this->has_primary_key_field ( ) ) { |
1006 | 1007 | $query_params[ 0 ][ $this->primary_key_name() ] = $id ; |
1007 | - }else{ |
|
1008 | + } else{ |
|
1008 | 1009 | //no primary key, so the $id must be from the get_index_primary_key_string() |
1009 | 1010 | $query_params[0] = array_replace_recursive( $query_params[ 0 ], $this->parse_index_primary_key_string( $id ) ); |
1010 | 1011 | } |
@@ -1027,7 +1028,7 @@ discard block |
||
1027 | 1028 | $items = $this->get_all($query_params); |
1028 | 1029 | if(empty($items)){ |
1029 | 1030 | return null; |
1030 | - }else{ |
|
1031 | + } else{ |
|
1031 | 1032 | return array_shift($items); |
1032 | 1033 | } |
1033 | 1034 | } |
@@ -1425,7 +1426,7 @@ discard block |
||
1425 | 1426 | //get the model object's PK, as we'll want this if we need to insert a row into secondary tables |
1426 | 1427 | if( $this->has_primary_key_field() ){ |
1427 | 1428 | $main_table_pk_value = $wpdb_result[ $this->get_primary_key_field()->get_qualified_column() ]; |
1428 | - }else{ |
|
1429 | + } else{ |
|
1429 | 1430 | //if there's no primary key, we basically can't support having a 2nd table on the model (we could but it would be lots of work) |
1430 | 1431 | $main_table_pk_value = null; |
1431 | 1432 | } |
@@ -1464,7 +1465,7 @@ discard block |
||
1464 | 1465 | if( $keep_model_objs_in_sync && ! $this->_values_already_prepared_by_model_object ){ |
1465 | 1466 | if( $this->has_primary_key_field() ){ |
1466 | 1467 | $model_objs_affected_ids = $this->get_col( $query_params ); |
1467 | - }else{ |
|
1468 | + } else{ |
|
1468 | 1469 | //we need to select a bunch of columns and then combine them into the the "index primary key string"s |
1469 | 1470 | $models_affected_key_columns = $this->_get_all_wpdb_results($query_params, ARRAY_A ); |
1470 | 1471 | $model_objs_affected_ids = array(); |
@@ -1524,9 +1525,9 @@ discard block |
||
1524 | 1525 | |
1525 | 1526 | if( $field_to_select ){ |
1526 | 1527 | $field = $this->field_settings_for( $field_to_select ); |
1527 | - }elseif( $this->has_primary_key_field ( ) ){ |
|
1528 | + } elseif( $this->has_primary_key_field ( ) ){ |
|
1528 | 1529 | $field = $this->get_primary_key_field(); |
1529 | - }else{ |
|
1530 | + } else{ |
|
1530 | 1531 | //no primary key, just grab the first column |
1531 | 1532 | $field = reset( $this->field_settings()); |
1532 | 1533 | } |
@@ -1550,7 +1551,7 @@ discard block |
||
1550 | 1551 | $col = $this->get_col( $query_params, $field_to_select ); |
1551 | 1552 | if( ! empty( $col ) ) { |
1552 | 1553 | return reset( $col ); |
1553 | - }else{ |
|
1554 | + } else{ |
|
1554 | 1555 | return NULL; |
1555 | 1556 | } |
1556 | 1557 | } |
@@ -1670,7 +1671,7 @@ discard block |
||
1670 | 1671 | |
1671 | 1672 | // /echo "delete sql:$SQL"; |
1672 | 1673 | $rows_deleted = $this->_do_wpdb_query( 'query', array( $SQL ) ); |
1673 | - }else{ |
|
1674 | + } else{ |
|
1674 | 1675 | $rows_deleted = 0; |
1675 | 1676 | } |
1676 | 1677 | |
@@ -1712,7 +1713,7 @@ discard block |
||
1712 | 1713 | //first, if $ignore_this_model_obj was supplied, get its model |
1713 | 1714 | if($ignore_this_model_obj && $ignore_this_model_obj instanceof EE_Base_Class){ |
1714 | 1715 | $ignored_model = $ignore_this_model_obj->get_model(); |
1715 | - }else{ |
|
1716 | + } else{ |
|
1716 | 1717 | $ignored_model = null; |
1717 | 1718 | } |
1718 | 1719 | //now check all the relations of $this_model_obj_or_id and see if there |
@@ -1725,7 +1726,7 @@ discard block |
||
1725 | 1726 | if($ignored_model && $relation_name == $ignored_model->get_this_model_name()){ |
1726 | 1727 | $related_model_objects = $relation_obj->get_all_related($this_model_obj_or_id,array( |
1727 | 1728 | array($ignored_model->get_primary_key_field()->get_name() => array('!=',$ignore_this_model_obj->ID())))); |
1728 | - }else{ |
|
1729 | + } else{ |
|
1729 | 1730 | $related_model_objects = $relation_obj->get_all_related($this_model_obj_or_id); |
1730 | 1731 | } |
1731 | 1732 | |
@@ -1762,24 +1763,28 @@ discard block |
||
1762 | 1763 | } |
1763 | 1764 | |
1764 | 1765 | //primary table deletes |
1765 | - if ( isset( $delete_object[$primary_table->get_fully_qualified_pk_column()] ) ) |
|
1766 | - $deletes[$primary_table->get_fully_qualified_pk_column()][] = $delete_object[$primary_table->get_fully_qualified_pk_column()]; |
|
1766 | + if ( isset( $delete_object[$primary_table->get_fully_qualified_pk_column()] ) ) { |
|
1767 | + $deletes[$primary_table->get_fully_qualified_pk_column()][] = $delete_object[$primary_table->get_fully_qualified_pk_column()]; |
|
1768 | + } |
|
1767 | 1769 | |
1768 | 1770 | //other tables |
1769 | 1771 | if ( !empty( $other_tables ) ) { |
1770 | 1772 | foreach ( $other_tables as $ot ) { |
1771 | 1773 | |
1772 | 1774 | //first check if we've got the foreign key column here. |
1773 | - if ( isset( $delete_object[$ot->get_fully_qualified_fk_column()] ) ) |
|
1774 | - $deletes[$ot->get_fully_qualified_pk_column()][] = $delete_object[$ot->get_fully_qualified_fk_column()]; |
|
1775 | + if ( isset( $delete_object[$ot->get_fully_qualified_fk_column()] ) ) { |
|
1776 | + $deletes[$ot->get_fully_qualified_pk_column()][] = $delete_object[$ot->get_fully_qualified_fk_column()]; |
|
1777 | + } |
|
1775 | 1778 | |
1776 | 1779 | //wait! it's entirely possible that we'll have a the primary key for this table in here if it's a foreign key for one of the other secondary tables |
1777 | - if ( isset( $delete_object[$ot->get_fully_qualified_pk_column()] ) ) |
|
1778 | - $deletes[$ot->get_fully_qualified_pk_column()][] = $delete_object[$ot->get_fully_qualified_pk_column()]; |
|
1780 | + if ( isset( $delete_object[$ot->get_fully_qualified_pk_column()] ) ) { |
|
1781 | + $deletes[$ot->get_fully_qualified_pk_column()][] = $delete_object[$ot->get_fully_qualified_pk_column()]; |
|
1782 | + } |
|
1779 | 1783 | |
1780 | 1784 | //finally, it is possible that the fk for this table is found in the fully qualified pk column for the fk table, so let's see if that's there! |
1781 | - if ( isset( $delete_object[$ot->get_fully_qualified_pk_on_fk_table()]) ) |
|
1782 | - $deletes[$ot->get_fully_qualified_pk_column()][] = $delete_object[$ot->get_fully_qualified_pk_column()]; |
|
1785 | + if ( isset( $delete_object[$ot->get_fully_qualified_pk_on_fk_table()]) ) { |
|
1786 | + $deletes[$ot->get_fully_qualified_pk_column()][] = $delete_object[$ot->get_fully_qualified_pk_column()]; |
|
1787 | + } |
|
1783 | 1788 | } |
1784 | 1789 | } |
1785 | 1790 | } |
@@ -1792,7 +1797,7 @@ discard block |
||
1792 | 1797 | } |
1793 | 1798 | |
1794 | 1799 | return !empty($query) ? implode(' AND ', $query ) : ''; |
1795 | - }elseif(count($this->get_combined_primary_key_fields()) > 1){ |
|
1800 | + } elseif(count($this->get_combined_primary_key_fields()) > 1){ |
|
1796 | 1801 | $ways_to_identify_a_row = array(); |
1797 | 1802 | $fields = $this->get_combined_primary_key_fields(); |
1798 | 1803 | //note: because there' sno primary key, that means nothing else can be pointing to this model, right? |
@@ -1804,7 +1809,7 @@ discard block |
||
1804 | 1809 | $ways_to_identify_a_row[] = "(".implode(" AND ",$values_for_each_cpk_for_a_row).")"; |
1805 | 1810 | } |
1806 | 1811 | return implode(" OR ",$ways_to_identify_a_row); |
1807 | - }else{ |
|
1812 | + } else{ |
|
1808 | 1813 | //so there's no primary key and no combined key... |
1809 | 1814 | //sorry, can't help you |
1810 | 1815 | throw new EE_Error(sprintf(__("Cannot delete objects of type %s because there is no primary key NOR combined key", "event_espresso"),get_class($this))); |
@@ -1826,10 +1831,10 @@ discard block |
||
1826 | 1831 | if($field_to_count){ |
1827 | 1832 | $field_obj = $this->field_settings_for($field_to_count); |
1828 | 1833 | $column_to_count = $field_obj->get_qualified_column(); |
1829 | - }elseif($this->has_primary_key_field ()){ |
|
1834 | + } elseif($this->has_primary_key_field ()){ |
|
1830 | 1835 | $pk_field_obj = $this->get_primary_key_field(); |
1831 | 1836 | $column_to_count = $pk_field_obj->get_qualified_column(); |
1832 | - }else{//there's no primary key |
|
1837 | + } else{//there's no primary key |
|
1833 | 1838 | $column_to_count = '*'; |
1834 | 1839 | } |
1835 | 1840 | |
@@ -1851,7 +1856,7 @@ discard block |
||
1851 | 1856 | if($field_to_sum){ |
1852 | 1857 | $field_obj = $this->field_settings_for($field_to_sum); |
1853 | 1858 | |
1854 | - }else{ |
|
1859 | + } else{ |
|
1855 | 1860 | $field_obj = $this->get_primary_key_field(); |
1856 | 1861 | } |
1857 | 1862 | $column_to_count = $field_obj->get_qualified_column(); |
@@ -1860,7 +1865,7 @@ discard block |
||
1860 | 1865 | $return_value = $this->_do_wpdb_query('get_var',array( $SQL ) ); |
1861 | 1866 | if($field_obj->get_wpdb_data_type() == '%d' || $field_obj->get_wpdb_data_type() == '%s' ){ |
1862 | 1867 | return (float)$return_value; |
1863 | - }else{//must be %f |
|
1868 | + } else{//must be %f |
|
1864 | 1869 | return (float)$return_value; |
1865 | 1870 | } |
1866 | 1871 | } |
@@ -1898,10 +1903,10 @@ discard block |
||
1898 | 1903 | $wpdb->show_errors( $old_show_errors_value ); |
1899 | 1904 | if( ! empty( $wpdb->last_error ) ){ |
1900 | 1905 | throw new EE_Error( sprintf( __( 'WPDB Error: "%s"', 'event_espresso' ), $wpdb->last_error ) ); |
1901 | - }elseif( $result === false ){ |
|
1906 | + } elseif( $result === false ){ |
|
1902 | 1907 | throw new EE_Error( sprintf( __( 'WPDB Error occurred, but no error message was logged by wpdb! The wpdb method called was "%1$s" and the arguments were "%2$s"', 'event_espresso' ), $wpdb_method, var_export( $arguments_to_provide, true ) ) ); |
1903 | 1908 | } |
1904 | - }elseif( $result === false ) { |
|
1909 | + } elseif( $result === false ) { |
|
1905 | 1910 | EE_Error::add_error( sprintf( __( 'A database error has occurred. Turn on WP_DEBUG for more information.', 'event_espresso' )), __FILE__, __FUNCTION__, __LINE__); |
1906 | 1911 | } |
1907 | 1912 | return $result; |
@@ -2211,7 +2216,7 @@ discard block |
||
2211 | 2216 | $results = $this->get_all_related($id_or_obj,$other_model_name,$query_params); |
2212 | 2217 | if( $results ){ |
2213 | 2218 | return array_shift($results); |
2214 | - }else{ |
|
2219 | + } else{ |
|
2215 | 2220 | return null; |
2216 | 2221 | } |
2217 | 2222 | |
@@ -2282,7 +2287,7 @@ discard block |
||
2282 | 2287 | */ |
2283 | 2288 | do_action( 'AHEE__EEM_Base__insert__end', $this, $field_n_values, $new_id ); |
2284 | 2289 | return $new_id; |
2285 | - }else{ |
|
2290 | + } else{ |
|
2286 | 2291 | return FALSE; |
2287 | 2292 | } |
2288 | 2293 | } |
@@ -2323,9 +2328,9 @@ discard block |
||
2323 | 2328 | public function get_one_conflicting($obj_or_fields_array, $include_primary_key = true ){ |
2324 | 2329 | if($obj_or_fields_array instanceof EE_Base_Class){ |
2325 | 2330 | $fields_n_values = $obj_or_fields_array->model_field_array(); |
2326 | - }elseif( is_array($obj_or_fields_array)){ |
|
2331 | + } elseif( is_array($obj_or_fields_array)){ |
|
2327 | 2332 | $fields_n_values = $obj_or_fields_array; |
2328 | - }else{ |
|
2333 | + } else{ |
|
2329 | 2334 | throw new EE_Error(sprintf(__("%s get_all_conflicting should be called with a model object or an array of field names and values, you provided %d", "event_espresso"),get_class($this),$obj_or_fields_array)); |
2330 | 2335 | } |
2331 | 2336 | $query_params = array( 'default_where_conditions' => 'minimum' ); |
@@ -2341,7 +2346,7 @@ discard block |
||
2341 | 2346 | //if there is nothing to base this search on, then we shouldn't find anything |
2342 | 2347 | if( ! isset( $query_params[0] ) || ( isset( $query_params[0] ) && empty( $query_params[0] ) ) ) { |
2343 | 2348 | return array(); |
2344 | - }else{ |
|
2349 | + } else{ |
|
2345 | 2350 | return $this->get_one($query_params); |
2346 | 2351 | } |
2347 | 2352 | } |
@@ -2414,12 +2419,12 @@ discard block |
||
2414 | 2419 | if($this->has_primary_key_field()){ |
2415 | 2420 | if($this->get_primary_key_field()->is_auto_increment()){ |
2416 | 2421 | return $wpdb->insert_id; |
2417 | - }else{ |
|
2422 | + } else{ |
|
2418 | 2423 | //it's not an auto-increment primary key, so |
2419 | 2424 | //it must have been supplied |
2420 | 2425 | return $fields_n_values[$this->get_primary_key_field()->get_name()]; |
2421 | 2426 | } |
2422 | - }else{ |
|
2427 | + } else{ |
|
2423 | 2428 | //we can't return a primary key because there is none. instead return |
2424 | 2429 | //a unique string indicating this model |
2425 | 2430 | return $this->get_index_primary_key_string($fields_n_values); |
@@ -2467,7 +2472,7 @@ discard block |
||
2467 | 2472 | //leave the value alone |
2468 | 2473 | } |
2469 | 2474 | return $value; |
2470 | - }else{ |
|
2475 | + } else{ |
|
2471 | 2476 | return $value; |
2472 | 2477 | } |
2473 | 2478 | } |
@@ -2560,7 +2565,7 @@ discard block |
||
2560 | 2565 | if(array_key_exists('group_by', $query_params)){ |
2561 | 2566 | if(is_array($query_params['group_by'])){ |
2562 | 2567 | $this->_extract_related_models_from_sub_params_array_values($query_params['group_by'],$query_info_carrier,'group_by'); |
2563 | - }elseif( ! empty ( $query_params['group_by'] )){ |
|
2568 | + } elseif( ! empty ( $query_params['group_by'] )){ |
|
2564 | 2569 | $this->_extract_related_model_info_from_query_param( $query_params['group_by'],$query_info_carrier,'group_by'); |
2565 | 2570 | } |
2566 | 2571 | } |
@@ -2568,10 +2573,11 @@ discard block |
||
2568 | 2573 | $this->_extract_related_models_from_sub_params_array_keys($query_params[0], $query_info_carrier,'having'); |
2569 | 2574 | } |
2570 | 2575 | if(array_key_exists('order_by', $query_params)){ |
2571 | - if ( is_array( $query_params['order_by'] ) ) |
|
2572 | - $this->_extract_related_models_from_sub_params_array_keys($query_params['order_by'],$query_info_carrier,'order_by'); |
|
2573 | - elseif( ! empty( $query_params['order_by'] )) |
|
2574 | - $this->_extract_related_model_info_from_query_param( $query_params['order_by'], $query_info_carrier,'order_by'); |
|
2576 | + if ( is_array( $query_params['order_by'] ) ) { |
|
2577 | + $this->_extract_related_models_from_sub_params_array_keys($query_params['order_by'],$query_info_carrier,'order_by'); |
|
2578 | + } elseif( ! empty( $query_params['order_by'] )) { |
|
2579 | + $this->_extract_related_model_info_from_query_param( $query_params['order_by'], $query_info_carrier,'order_by'); |
|
2580 | + } |
|
2575 | 2581 | } |
2576 | 2582 | if(array_key_exists('force_join', $query_params)){ |
2577 | 2583 | $this->_extract_related_models_from_sub_params_array_values($query_params['force_join'],$query_info_carrier,'force_join'); |
@@ -2603,10 +2609,10 @@ discard block |
||
2603 | 2609 | if (! is_array($possibly_array_of_params)){ |
2604 | 2610 | throw new EE_Error(sprintf(__("You used a special where query param %s, but the value isn't an array of where query params, it's just %s'. It should be an array, eg array('EVT_ID'=>23,'OR'=>array('Venue.VNU_ID'=>32,'Venue.VNU_name'=>'monkey_land'))", "event_espresso"), |
2605 | 2611 | $param,$possibly_array_of_params)); |
2606 | - }else{ |
|
2612 | + } else{ |
|
2607 | 2613 | $this->_extract_related_models_from_sub_params_array_keys($possibly_array_of_params, $model_query_info_carrier,$query_param_type); |
2608 | 2614 | } |
2609 | - }elseif($query_param_type === 0 //ie WHERE |
|
2615 | + } elseif($query_param_type === 0 //ie WHERE |
|
2610 | 2616 | && is_array($possibly_array_of_params) |
2611 | 2617 | && isset($possibly_array_of_params[2]) |
2612 | 2618 | && $possibly_array_of_params[2] == true){ |
@@ -2666,7 +2672,7 @@ discard block |
||
2666 | 2672 | } |
2667 | 2673 | if( isset( $query_params[0] ) ) { |
2668 | 2674 | $where_query_params = $query_params[0]; |
2669 | - }else{ |
|
2675 | + } else{ |
|
2670 | 2676 | $where_query_params = array(); |
2671 | 2677 | } |
2672 | 2678 | //first check if we should alter the query to account for caps or not |
@@ -2684,7 +2690,7 @@ discard block |
||
2684 | 2690 | } |
2685 | 2691 | if( array_key_exists( 'default_where_conditions',$query_params) && ! empty( $query_params['default_where_conditions'] )){ |
2686 | 2692 | $use_default_where_conditions = $query_params['default_where_conditions']; |
2687 | - }else{ |
|
2693 | + } else{ |
|
2688 | 2694 | $use_default_where_conditions = 'all'; |
2689 | 2695 | } |
2690 | 2696 | $where_query_params = array_merge($this->_get_default_where_conditions_for_models_in_query($query_object,$use_default_where_conditions,$where_query_params), $where_query_params ); |
@@ -2707,7 +2713,7 @@ discard block |
||
2707 | 2713 | } |
2708 | 2714 | //they passed us an array for the limit. Assume it's like array(50,25), meaning offset by 50, and get 25 |
2709 | 2715 | $query_object->set_limit_sql(" LIMIT ".$query_params['limit'][0].",".$query_params['limit'][1]); |
2710 | - }elseif( ! empty ( $query_params['limit'] )){ |
|
2716 | + } elseif( ! empty ( $query_params['limit'] )){ |
|
2711 | 2717 | $query_object->set_limit_sql((" LIMIT ".$query_params['limit'])); |
2712 | 2718 | } |
2713 | 2719 | } |
@@ -2729,11 +2735,11 @@ discard block |
||
2729 | 2735 | $order_array[] = $this->_deduce_column_name_from_query_param($field_name_to_order_by).SP.$order; |
2730 | 2736 | } |
2731 | 2737 | $query_object->set_order_by_sql(" ORDER BY ".implode(",",$order_array)); |
2732 | - }elseif( ! empty ( $query_params['order_by'] )){ |
|
2738 | + } elseif( ! empty ( $query_params['order_by'] )){ |
|
2733 | 2739 | $this->_extract_related_model_info_from_query_param($query_params['order_by'],$query_object,'order',$query_params['order_by']); |
2734 | 2740 | if(isset($query_params['order'])){ |
2735 | 2741 | $order = $this->_extract_order($query_params['order']); |
2736 | - }else{ |
|
2742 | + } else{ |
|
2737 | 2743 | $order = 'DESC'; |
2738 | 2744 | } |
2739 | 2745 | $query_object->set_order_by_sql(" ORDER BY ".$this->_deduce_column_name_from_query_param($query_params['order_by']).SP.$order); |
@@ -2756,7 +2762,7 @@ discard block |
||
2756 | 2762 | $group_by_array[] = $this->_deduce_column_name_from_query_param($field_name_to_group_by); |
2757 | 2763 | } |
2758 | 2764 | $query_object->set_group_by_sql(" GROUP BY ".implode(", ",$group_by_array)); |
2759 | - }elseif( ! empty ( $query_params['group_by'] )){ |
|
2765 | + } elseif( ! empty ( $query_params['group_by'] )){ |
|
2760 | 2766 | $query_object->set_group_by_sql(" GROUP BY ".$this->_deduce_column_name_from_query_param($query_params['group_by'])); |
2761 | 2767 | } |
2762 | 2768 | } |
@@ -2780,8 +2786,9 @@ discard block |
||
2780 | 2786 | } |
2781 | 2787 | } |
2782 | 2788 | $main_model_join_sql = $query_object->get_main_model_join_sql(); |
2783 | - if ( empty( $main_model_join_sql ) ) |
|
2784 | - $query_object->set_main_model_join_sql($this->_construct_internal_join()); |
|
2789 | + if ( empty( $main_model_join_sql ) ) { |
|
2790 | + $query_object->set_main_model_join_sql($this->_construct_internal_join()); |
|
2791 | + } |
|
2785 | 2792 | return $query_object; |
2786 | 2793 | } |
2787 | 2794 | |
@@ -2814,7 +2821,7 @@ discard block |
||
2814 | 2821 | private function _extract_order($should_be_order_string){ |
2815 | 2822 | if(in_array($should_be_order_string, $this->_allowed_order_values)){ |
2816 | 2823 | return $should_be_order_string; |
2817 | - }else{ |
|
2824 | + } else{ |
|
2818 | 2825 | throw new EE_Error(sprintf(__("While performing a query on '%s', tried to use '%s' as an order parameter. ", "event_espresso"),get_class($this),$should_be_order_string)); |
2819 | 2826 | } |
2820 | 2827 | } |
@@ -2846,9 +2853,9 @@ discard block |
||
2846 | 2853 | } |
2847 | 2854 | if( in_array($use_default_where_conditions, array('all','this_model_only')) ){ |
2848 | 2855 | $universal_query_params = $this->_get_default_where_conditions(); |
2849 | - }elseif( $use_default_where_conditions == 'minimum' ) { |
|
2856 | + } elseif( $use_default_where_conditions == 'minimum' ) { |
|
2850 | 2857 | $universal_query_params = $this->_get_minimum_where_conditions(); |
2851 | - }else{ |
|
2858 | + } else{ |
|
2852 | 2859 | $universal_query_params = array(); |
2853 | 2860 | } |
2854 | 2861 | |
@@ -2857,7 +2864,7 @@ discard block |
||
2857 | 2864 | $related_model = $this->get_related_model_obj($model_name); |
2858 | 2865 | if( $use_default_where_conditions == 'minimum' ) { |
2859 | 2866 | $related_model_universal_where_params = $related_model->_get_minimum_where_conditions($model_relation_path); |
2860 | - }else{ |
|
2867 | + } else{ |
|
2861 | 2868 | $related_model_universal_where_params = $related_model->_get_default_where_conditions($model_relation_path); |
2862 | 2869 | } |
2863 | 2870 | |
@@ -2892,14 +2899,14 @@ discard block |
||
2892 | 2899 | foreach($default_where_conditions as $key => $val){ |
2893 | 2900 | if( isset($provided_where_conditions[$key])){ |
2894 | 2901 | $none_overridden = false; |
2895 | - }else{ |
|
2902 | + } else{ |
|
2896 | 2903 | $null_friendly_where_conditions[$or_condition_key_for_defaults]['AND'][$key] = $val; |
2897 | 2904 | } |
2898 | 2905 | } |
2899 | 2906 | if( $none_overridden && $default_where_conditions){ |
2900 | 2907 | if($model->has_primary_key_field()){ |
2901 | 2908 | $null_friendly_where_conditions[$or_condition_key_for_defaults][$model_relation_path.".".$model->primary_key_name()] = array('IS NULL'); |
2902 | - }else{ |
|
2909 | + } else{ |
|
2903 | 2910 | //@todo NO PK, use other defaults |
2904 | 2911 | } |
2905 | 2912 | } |
@@ -2915,8 +2922,9 @@ discard block |
||
2915 | 2922 | * @return array like EEM_Base::get_all's $query_params[0] (where conditions) |
2916 | 2923 | */ |
2917 | 2924 | protected function _get_default_where_conditions($model_relation_path = null){ |
2918 | - if ( $this->_ignore_where_strategy ) |
|
2919 | - return array(); |
|
2925 | + if ( $this->_ignore_where_strategy ) { |
|
2926 | + return array(); |
|
2927 | + } |
|
2920 | 2928 | |
2921 | 2929 | return $this->_default_where_conditions_strategy->get_default_where_conditions($model_relation_path); |
2922 | 2930 | } |
@@ -2931,8 +2939,9 @@ discard block |
||
2931 | 2939 | * @return array like EEM_Base::get_all's $query_params[0] (where conditions) |
2932 | 2940 | */ |
2933 | 2941 | protected function _get_minimum_where_conditions($model_relation_path = null){ |
2934 | - if ( $this->_ignore_where_strategy ) |
|
2935 | - return array(); |
|
2942 | + if ( $this->_ignore_where_strategy ) { |
|
2943 | + return array(); |
|
2944 | + } |
|
2936 | 2945 | |
2937 | 2946 | return $this->_minimum_where_conditions_strategy->get_default_where_conditions($model_relation_path); |
2938 | 2947 | } |
@@ -3006,7 +3015,7 @@ discard block |
||
3006 | 3015 | if(array_key_exists($query_param,$this_model_fields)){ |
3007 | 3016 | if($allow_fields){ |
3008 | 3017 | return; |
3009 | - }else{ |
|
3018 | + } else{ |
|
3010 | 3019 | throw new EE_Error(sprintf(__("Using a field name (%s) on model %s is not allowed on this query param type '%s'. Original query param was %s", "event_espresso"), |
3011 | 3020 | $query_param,get_class($this),$query_param_type,$original_query_param)); |
3012 | 3021 | } |
@@ -3015,7 +3024,7 @@ discard block |
||
3015 | 3024 | elseif(in_array($query_param, $this->_logic_query_param_keys, TRUE)){ |
3016 | 3025 | if($allow_logic_query_params){ |
3017 | 3026 | return; |
3018 | - }else{ |
|
3027 | + } else{ |
|
3019 | 3028 | throw new EE_Error( |
3020 | 3029 | sprintf( |
3021 | 3030 | __( 'Logic query params ("%1$s") are being used incorrectly with the following query param ("%2$s") on model %3$s. %4$sAdditional Info:%4$s%5$s', 'event_espresso' ), |
@@ -3046,12 +3055,12 @@ discard block |
||
3046 | 3055 | //we should actually end in a field name, not a model like this! |
3047 | 3056 | throw new EE_Error(sprintf(__("Query param '%s' (of type %s on model %s) shouldn't end on a period (.) ", "event_espresso"), |
3048 | 3057 | $query_param,$query_param_type,get_class($this),$valid_related_model_name)); |
3049 | - }else{ |
|
3058 | + } else{ |
|
3050 | 3059 | $related_model_obj = $this->get_related_model_obj($valid_related_model_name); |
3051 | 3060 | $related_model_obj->_extract_related_model_info_from_query_param($query_param, $passed_in_query_info, $query_param_type, $original_query_param); |
3052 | 3061 | return; |
3053 | 3062 | } |
3054 | - }elseif($query_param == $valid_related_model_name){ |
|
3063 | + } elseif($query_param == $valid_related_model_name){ |
|
3055 | 3064 | $this->_add_join_to_model($valid_related_model_name, $passed_in_query_info,$original_query_param); |
3056 | 3065 | return; |
3057 | 3066 | } |
@@ -3111,7 +3120,7 @@ discard block |
||
3111 | 3120 | $SQL = $this->_construct_condition_clause_recursive($where_params, ' AND '); |
3112 | 3121 | if($SQL){ |
3113 | 3122 | return " WHERE ". $SQL; |
3114 | - }else{ |
|
3123 | + } else{ |
|
3115 | 3124 | return ''; |
3116 | 3125 | } |
3117 | 3126 | } |
@@ -3126,7 +3135,7 @@ discard block |
||
3126 | 3135 | $SQL = $this->_construct_condition_clause_recursive($having_params, ' AND '); |
3127 | 3136 | if($SQL){ |
3128 | 3137 | return " HAVING ". $SQL; |
3129 | - }else{ |
|
3138 | + } else{ |
|
3130 | 3139 | return ''; |
3131 | 3140 | } |
3132 | 3141 | |
@@ -3149,7 +3158,7 @@ discard block |
||
3149 | 3158 | $model_instance=call_user_func($model_name."::instance"); |
3150 | 3159 | /* @var $model_instance EEM_Base */ |
3151 | 3160 | return $model_instance->field_settings_for($field_name); |
3152 | - }else{ |
|
3161 | + } else{ |
|
3153 | 3162 | throw new EE_Error(sprintf(__('No model named %s exists, with classname %s and filepath %s','event_espresso'),$model_name,$model_class,$model_filepath)); |
3154 | 3163 | } |
3155 | 3164 | } |
@@ -3182,14 +3191,14 @@ discard block |
||
3182 | 3191 | $where_clauses[] = " (". $this->_construct_condition_clause_recursive($op_and_value_or_sub_condition, ' OR ') .")"; |
3183 | 3192 | break; |
3184 | 3193 | } |
3185 | - }else{ |
|
3194 | + } else{ |
|
3186 | 3195 | $field_obj = $this->_deduce_field_from_query_param($query_param); |
3187 | 3196 | |
3188 | 3197 | //if it's not a normal field, maybe it's a custom selection? |
3189 | 3198 | if( ! $field_obj){ |
3190 | 3199 | if(isset( $this->_custom_selections[$query_param][1])){ |
3191 | 3200 | $field_obj = $this->_custom_selections[$query_param][1]; |
3192 | - }else{ |
|
3201 | + } else{ |
|
3193 | 3202 | throw new EE_Error(sprintf(__("%s is neither a valid model field name, nor a custom selection", "event_espresso"),$query_param)); |
3194 | 3203 | } |
3195 | 3204 | } |
@@ -3199,7 +3208,7 @@ discard block |
||
3199 | 3208 | } |
3200 | 3209 | if($where_clauses){ |
3201 | 3210 | $SQL = implode($glue,$where_clauses); |
3202 | - }else{ |
|
3211 | + } else{ |
|
3203 | 3212 | $SQL = ''; |
3204 | 3213 | } |
3205 | 3214 | return $SQL; |
@@ -3219,11 +3228,11 @@ discard block |
||
3219 | 3228 | if( $field ){ |
3220 | 3229 | $table_alias_prefix = EE_Model_Parser::extract_table_alias_model_relation_chain_from_query_param( $field->get_model_name(), $query_param ); |
3221 | 3230 | return $table_alias_prefix . $field->get_qualified_column(); |
3222 | - }elseif(array_key_exists($query_param,$this->_custom_selections)){ |
|
3231 | + } elseif(array_key_exists($query_param,$this->_custom_selections)){ |
|
3223 | 3232 | //maybe it's custom selection item? |
3224 | 3233 | //if so, just use it as the "column name" |
3225 | 3234 | return $query_param; |
3226 | - }else{ |
|
3235 | + } else{ |
|
3227 | 3236 | throw new EE_Error(sprintf(__("%s is not a valid field on this model, nor a custom selection (%s)", "event_espresso"),$query_param,implode(",",$this->_custom_selections))); |
3228 | 3237 | } |
3229 | 3238 | } |
@@ -3240,7 +3249,7 @@ discard block |
||
3240 | 3249 | $pos_of_star = strpos($condition_query_param_key, '*'); |
3241 | 3250 | if($pos_of_star === FALSE){ |
3242 | 3251 | return $condition_query_param_key; |
3243 | - }else{ |
|
3252 | + } else{ |
|
3244 | 3253 | $condition_query_param_sans_star = substr($condition_query_param_key, 0, $pos_of_star); |
3245 | 3254 | return $condition_query_param_sans_star; |
3246 | 3255 | } |
@@ -3266,7 +3275,7 @@ discard block |
||
3266 | 3275 | throw new EE_Error(sprintf(__("You setup a query parameter like you were going to specify an operator, but didn't. You provided '(%s)', but the operator should be at array key index 0 (eg array('>',32))", "event_espresso"), implode(",",$php_array_like_string))); |
3267 | 3276 | } |
3268 | 3277 | $value = isset($op_and_value[1]) ? $op_and_value[1] : null; |
3269 | - }else{ |
|
3278 | + } else{ |
|
3270 | 3279 | $operator = '='; |
3271 | 3280 | $value = $op_and_value; |
3272 | 3281 | } |
@@ -3274,7 +3283,7 @@ discard block |
||
3274 | 3283 | //check to see if the value is actually another field |
3275 | 3284 | if(is_array($op_and_value) && isset($op_and_value[2]) && $op_and_value[2] == true){ |
3276 | 3285 | return $operator.SP.$this->_deduce_column_name_from_query_param($value); |
3277 | - }elseif(in_array($operator, $this->_in_style_operators) && is_array($value)){ |
|
3286 | + } elseif(in_array($operator, $this->_in_style_operators) && is_array($value)){ |
|
3278 | 3287 | //in this case, the value should be an array, or at least a comma-separated list |
3279 | 3288 | //it will need to handle a little differently |
3280 | 3289 | $cleaned_value = $this->_construct_in_value($value, $field_obj); |
@@ -3282,8 +3291,9 @@ discard block |
||
3282 | 3291 | return $operator.SP.$cleaned_value; |
3283 | 3292 | } elseif( in_array( $operator, $this->_between_style_operators ) && is_array( $value ) ) { |
3284 | 3293 | //the value should be an array with count of two. |
3285 | - if ( count($value) !== 2 ) |
|
3286 | - throw new EE_Error( sprintf( __("The '%s' operator must be used with an array of values and there must be exactly TWO values in that array.", 'event_espresso'), "BETWEEN" ) ); |
|
3294 | + if ( count($value) !== 2 ) { |
|
3295 | + throw new EE_Error( sprintf( __("The '%s' operator must be used with an array of values and there must be exactly TWO values in that array.", 'event_espresso'), "BETWEEN" ) ); |
|
3296 | + } |
|
3287 | 3297 | $cleaned_value = $this->_construct_between_value( $value, $field_obj ); |
3288 | 3298 | return $operator.SP.$cleaned_value; |
3289 | 3299 | } elseif( in_array( $operator, $this->_null_style_operators ) ) { |
@@ -3291,17 +3301,17 @@ discard block |
||
3291 | 3301 | throw new EE_Error(sprintf(__("You attempted to give a value (%s) while using a NULL-style operator (%s). That isn't valid", "event_espresso"),$value,$operator)); |
3292 | 3302 | } |
3293 | 3303 | return $operator; |
3294 | - }elseif( $operator == 'LIKE' && ! is_array($value)){ |
|
3304 | + } elseif( $operator == 'LIKE' && ! is_array($value)){ |
|
3295 | 3305 | //if the operator is 'LIKE', we want to allow percent signs (%) and not |
3296 | 3306 | //remove other junk. So just treat it as a string. |
3297 | 3307 | return $operator.SP.$this->_wpdb_prepare_using_field($value, '%s'); |
3298 | - }elseif( ! in_array($operator, $this->_in_style_operators) && ! is_array($value)){ |
|
3308 | + } elseif( ! in_array($operator, $this->_in_style_operators) && ! is_array($value)){ |
|
3299 | 3309 | return $operator.SP.$this->_wpdb_prepare_using_field($value,$field_obj); |
3300 | - }elseif(in_array($operator, $this->_in_style_operators) && ! is_array($value)){ |
|
3310 | + } elseif(in_array($operator, $this->_in_style_operators) && ! is_array($value)){ |
|
3301 | 3311 | throw new EE_Error(sprintf(__("Operator '%s' must be used with an array of values, eg 'Registration.REG_ID' => array('%s',array(1,2,3))",'event_espresso'),$operator, $operator)); |
3302 | - }elseif( ! in_array($operator, $this->_in_style_operators) && is_array($value)){ |
|
3312 | + } elseif( ! in_array($operator, $this->_in_style_operators) && is_array($value)){ |
|
3303 | 3313 | throw new EE_Error(sprintf(__("Operator '%s' must be used with a single value, not an array. Eg 'Registration.REG_ID => array('%s',23))",'event_espresso'),$operator,$operator)); |
3304 | - }else{ |
|
3314 | + } else{ |
|
3305 | 3315 | throw new EE_Error(sprintf(__("It appears you've provided some totally invalid query parameters. Operator and value were:'%s', which isn't right at all", "event_espresso"), http_build_query($op_and_value))); |
3306 | 3316 | } |
3307 | 3317 | } |
@@ -3371,7 +3381,7 @@ discard block |
||
3371 | 3381 | global $wpdb; |
3372 | 3382 | if($field_obj instanceof EE_Model_Field_Base){ |
3373 | 3383 | return $wpdb->prepare($field_obj->get_wpdb_data_type(),$this->_prepare_value_for_use_in_db($value, $field_obj)); |
3374 | - }else{//$field_obj should really just be a data type |
|
3384 | + } else{//$field_obj should really just be a data type |
|
3375 | 3385 | if( ! in_array($field_obj,$this->_valid_wpdb_data_types)){ |
3376 | 3386 | throw new EE_Error(sprintf(__("%s is not a valid wpdb datatype. Valid ones are %s", "event_espresso"),$field_obj,implode(",",$this->_valid_wpdb_data_types))); |
3377 | 3387 | } |
@@ -3400,14 +3410,14 @@ discard block |
||
3400 | 3410 | if($number_of_parts == 1){ |
3401 | 3411 | $field_name = $last_query_param_part; |
3402 | 3412 | $model_obj = $this; |
3403 | - }else{// $number_of_parts >= 2 |
|
3413 | + } else{// $number_of_parts >= 2 |
|
3404 | 3414 | //the last part is the column name, and there are only 2parts. therefore... |
3405 | 3415 | $field_name = $last_query_param_part; |
3406 | 3416 | $model_obj = $this->get_related_model_obj( $query_param_parts[ $number_of_parts - 2 ]); |
3407 | 3417 | } |
3408 | 3418 | try{ |
3409 | 3419 | return $model_obj->field_settings_for($field_name); |
3410 | - }catch(EE_Error $e){ |
|
3420 | + } catch(EE_Error $e){ |
|
3411 | 3421 | return null; |
3412 | 3422 | } |
3413 | 3423 | } |
@@ -3426,7 +3436,7 @@ discard block |
||
3426 | 3436 | $field = isset($all_fields[$field_name]) ? $all_fields[$field_name] : FALSE; |
3427 | 3437 | if($field){ |
3428 | 3438 | return $field->get_qualified_column(); |
3429 | - }else{ |
|
3439 | + } else{ |
|
3430 | 3440 | throw new EE_Error(sprintf(__("There is no field titled %s on model %s. Either the query trying to use it is bad, or you need to add it to the list of fields on the model.",'event_espresso'),$field_name,get_class($this))); |
3431 | 3441 | } |
3432 | 3442 | } |
@@ -3492,7 +3502,7 @@ discard block |
||
3492 | 3502 | //the FROM statement, BUT the primary table isn't. So we want |
3493 | 3503 | //to add the inverse join sql |
3494 | 3504 | $SQL .= $table_obj->get_inverse_join_sql($alias_prefixed); |
3495 | - }else{ |
|
3505 | + } else{ |
|
3496 | 3506 | //just add a regular JOIN to this table from the primary table |
3497 | 3507 | $SQL .= $table_obj->get_join_sql($alias_prefixed); |
3498 | 3508 | } |
@@ -3607,7 +3617,7 @@ discard block |
||
3607 | 3617 | $fieldSettings = $this->field_settings(true); |
3608 | 3618 | if( isset($fieldSettings[$fieldName])){ |
3609 | 3619 | return true; |
3610 | - }else{ |
|
3620 | + } else{ |
|
3611 | 3621 | return false; |
3612 | 3622 | } |
3613 | 3623 | } |
@@ -3621,7 +3631,7 @@ discard block |
||
3621 | 3631 | $relations = $this->relation_settings(); |
3622 | 3632 | if(isset($relations[$relation_name])){ |
3623 | 3633 | return true; |
3624 | - }else{ |
|
3634 | + } else{ |
|
3625 | 3635 | return false; |
3626 | 3636 | } |
3627 | 3637 | } |
@@ -3672,7 +3682,7 @@ discard block |
||
3672 | 3682 | try{ |
3673 | 3683 | $this->get_primary_key_field(); |
3674 | 3684 | $this->_has_primary_key_field = true; |
3675 | - }catch(EE_Error $e){ |
|
3685 | + } catch(EE_Error $e){ |
|
3676 | 3686 | $this->_has_primary_key_field = false; |
3677 | 3687 | } |
3678 | 3688 | } |
@@ -3751,7 +3761,7 @@ discard block |
||
3751 | 3761 | } |
3752 | 3762 | } |
3753 | 3763 | return $this->_cached_fields; |
3754 | - }else{ |
|
3764 | + } else{ |
|
3755 | 3765 | if( $this->_cached_fields_non_db_only === NULL ){ |
3756 | 3766 | $this->_cached_fields_non_db_only = array(); |
3757 | 3767 | foreach($this->_fields as $fields_corresponding_to_table){ |
@@ -3894,7 +3904,7 @@ discard block |
||
3894 | 3904 | if(empty( $this_model_fields_n_values[$this->primary_key_name()] )){ |
3895 | 3905 | return NULL; |
3896 | 3906 | } |
3897 | - }else if($this->unique_indexes()){ |
|
3907 | + } else if($this->unique_indexes()){ |
|
3898 | 3908 | $first_column = reset($this_model_fields_n_values); |
3899 | 3909 | if(empty($first_column)){ |
3900 | 3910 | return NULL; |
@@ -3909,7 +3919,7 @@ discard block |
||
3909 | 3919 | // add this new object to the entity map |
3910 | 3920 | $classInstance = $this->add_to_entity_map( $classInstance ); |
3911 | 3921 | } |
3912 | - }else{ |
|
3922 | + } else{ |
|
3913 | 3923 | $classInstance = EE_Registry::instance()->load_class( $className, array( $this_model_fields_n_values, $this->_timezone ), TRUE, FALSE ); |
3914 | 3924 | } |
3915 | 3925 | |
@@ -3996,11 +4006,12 @@ discard block |
||
3996 | 4006 | $this_model_fields_n_values[$field_name] = $field_obj->prepare_for_use_in_db( $prepared_value ); |
3997 | 4007 | } |
3998 | 4008 | } |
3999 | - }else{ |
|
4009 | + } else{ |
|
4000 | 4010 | //the table's rows existed. Use their values |
4001 | 4011 | foreach( $this->_get_fields_for_table( $table_alias ) as $field_name => $field_obj ) { |
4002 | - if( ! $field_obj->is_db_only_field() ) |
|
4003 | - $this_model_fields_n_values[$field_name] = $this->_get_column_value_with_table_alias_or_not($cols_n_values, $field_obj->get_qualified_column(), $field_obj->get_table_column() ); |
|
4012 | + if( ! $field_obj->is_db_only_field() ) { |
|
4013 | + $this_model_fields_n_values[$field_name] = $this->_get_column_value_with_table_alias_or_not($cols_n_values, $field_obj->get_qualified_column(), $field_obj->get_table_column() ); |
|
4014 | + } |
|
4004 | 4015 | } |
4005 | 4016 | } |
4006 | 4017 | } |
@@ -4014,9 +4025,9 @@ discard block |
||
4014 | 4025 | if( isset( $cols_n_values[ $qualified_column ] ) ){ |
4015 | 4026 | $value = $cols_n_values[ $qualified_column ]; |
4016 | 4027 | |
4017 | - }elseif( isset( $cols_n_values[ $regular_column ] ) ){ |
|
4028 | + } elseif( isset( $cols_n_values[ $regular_column ] ) ){ |
|
4018 | 4029 | $value = $cols_n_values[ $regular_column ]; |
4019 | - }else{ |
|
4030 | + } else{ |
|
4020 | 4031 | $value = NULL; |
4021 | 4032 | } |
4022 | 4033 | |
@@ -4049,7 +4060,7 @@ discard block |
||
4049 | 4060 | } |
4050 | 4061 | } |
4051 | 4062 | return $obj_in_map; |
4052 | - }else{ |
|
4063 | + } else{ |
|
4053 | 4064 | return $this->get_one_by_ID( $id ); |
4054 | 4065 | } |
4055 | 4066 | } |
@@ -4084,7 +4095,7 @@ discard block |
||
4084 | 4095 | } |
4085 | 4096 | } |
4086 | 4097 | return $obj_in_map; |
4087 | - }else{ |
|
4098 | + } else{ |
|
4088 | 4099 | $this->add_to_entity_map( $replacing_model_obj ); |
4089 | 4100 | return $replacing_model_obj; |
4090 | 4101 | } |
@@ -4114,7 +4125,7 @@ discard block |
||
4114 | 4125 | public function item_name($quantity = 1){ |
4115 | 4126 | if($quantity == 1){ |
4116 | 4127 | return $this->singular_item; |
4117 | - }else{ |
|
4128 | + } else{ |
|
4118 | 4129 | return $this->plural_item; |
4119 | 4130 | } |
4120 | 4131 | } |
@@ -4176,14 +4187,14 @@ discard block |
||
4176 | 4187 | $primary_key_field = $this->get_primary_key_field(); |
4177 | 4188 | if( $base_class_obj_or_id instanceof $className ){ |
4178 | 4189 | $model_object = $base_class_obj_or_id; |
4179 | - }elseif( $primary_key_field instanceof EE_Primary_Key_Int_Field && ( |
|
4190 | + } elseif( $primary_key_field instanceof EE_Primary_Key_Int_Field && ( |
|
4180 | 4191 | is_int( $base_class_obj_or_id ) || |
4181 | 4192 | is_string( $base_class_obj_or_id ) )){//assume it's an ID. either a proper integer or a string representing an integer (eg "101" instead of 101) |
4182 | 4193 | $model_object = $this->get_one_by_ID($base_class_obj_or_id); |
4183 | - }elseif( $primary_key_field instanceof EE_Primary_Key_String_Field && is_string($base_class_obj_or_id) ){ |
|
4194 | + } elseif( $primary_key_field instanceof EE_Primary_Key_String_Field && is_string($base_class_obj_or_id) ){ |
|
4184 | 4195 | //assume its a string representation of the object |
4185 | 4196 | $model_object = $this->get_one_by_ID($base_class_obj_or_id); |
4186 | - }else{ |
|
4197 | + } else{ |
|
4187 | 4198 | throw new EE_Error(sprintf(__("'%s' is neither an object of type %s, nor an ID! Its full value is '%s'",'event_espresso'),$base_class_obj_or_id,$this->_get_class_name(),print_r($base_class_obj_or_id,true))); |
4188 | 4199 | } |
4189 | 4200 | if( $model_object->ID() == NULL && $ensure_is_in_db){ |
@@ -4207,13 +4218,13 @@ discard block |
||
4207 | 4218 | if( $base_class_obj_or_id instanceof $className ){ |
4208 | 4219 | /** @var $base_class_obj_or_id EE_Base_Class */ |
4209 | 4220 | $id = $base_class_obj_or_id->ID(); |
4210 | - }elseif(is_int($base_class_obj_or_id)){ |
|
4221 | + } elseif(is_int($base_class_obj_or_id)){ |
|
4211 | 4222 | //assume it's an ID |
4212 | 4223 | $id = $base_class_obj_or_id; |
4213 | - }elseif(is_string($base_class_obj_or_id)){ |
|
4224 | + } elseif(is_string($base_class_obj_or_id)){ |
|
4214 | 4225 | //assume its a string representation of the object |
4215 | 4226 | $id = $base_class_obj_or_id; |
4216 | - }else{ |
|
4227 | + } else{ |
|
4217 | 4228 | throw new EE_Error(sprintf(__("'%s' is neither an object of type %s, nor an ID! Its full value is '%s'",'event_espresso'),$base_class_obj_or_id,$this->_get_class_name(),print_r($base_class_obj_or_id,true))); |
4218 | 4229 | } |
4219 | 4230 | return $id; |
@@ -4344,9 +4355,9 @@ discard block |
||
4344 | 4355 | |
4345 | 4356 | if($model_object_or_attributes_array instanceof EE_Base_Class){ |
4346 | 4357 | $attributes_array = $model_object_or_attributes_array->model_field_array(); |
4347 | - }elseif(is_array($model_object_or_attributes_array)){ |
|
4358 | + } elseif(is_array($model_object_or_attributes_array)){ |
|
4348 | 4359 | $attributes_array = $model_object_or_attributes_array; |
4349 | - }else{ |
|
4360 | + } else{ |
|
4350 | 4361 | throw new EE_Error(sprintf(__("get_all_copies should be provided with either a model object or an array of field-value-pairs, but was given %s", "event_espresso"),$model_object_or_attributes_array)); |
4351 | 4362 | } |
4352 | 4363 | //even copies obviously won't have the same ID, so remove the primary key |
@@ -4356,7 +4367,7 @@ discard block |
||
4356 | 4367 | } |
4357 | 4368 | if(isset($query_params[0])){ |
4358 | 4369 | $query_params[0] = array_merge($attributes_array,$query_params); |
4359 | - }else{ |
|
4370 | + } else{ |
|
4360 | 4371 | $query_params[0] = $attributes_array; |
4361 | 4372 | } |
4362 | 4373 | return $this->get_all($query_params); |
@@ -4379,7 +4390,7 @@ discard block |
||
4379 | 4390 | $copies = $this->get_all_copies($model_object_or_attributes_array,$query_params); |
4380 | 4391 | if(is_array($copies)){ |
4381 | 4392 | return array_shift($copies); |
4382 | - }else{ |
|
4393 | + } else{ |
|
4383 | 4394 | return null; |
4384 | 4395 | } |
4385 | 4396 | } |
@@ -4411,7 +4422,7 @@ discard block |
||
4411 | 4422 | $sql_operator = isset($this->_valid_operators[$operator_supplied]) ? $this->_valid_operators[$operator_supplied] : null; |
4412 | 4423 | if($sql_operator){ |
4413 | 4424 | return $sql_operator; |
4414 | - }else{ |
|
4425 | + } else{ |
|
4415 | 4426 | throw new EE_Error(sprintf(__("The operator '%s' is not in the list of valid operators: %s", "event_espresso"),$operator_supplied,implode(",",array_keys($this->_valid_operators)))); |
4416 | 4427 | } |
4417 | 4428 | } |
@@ -4582,7 +4593,7 @@ discard block |
||
4582 | 4593 | $valid_cap_contexts = EEM_Base::valid_cap_contexts(); |
4583 | 4594 | if( in_array( $context, $valid_cap_contexts ) ) { |
4584 | 4595 | return true; |
4585 | - }else{ |
|
4596 | + } else{ |
|
4586 | 4597 | throw new EE_Error( |
4587 | 4598 | sprintf( |
4588 | 4599 | __( 'Context "%1$s" passed into model "%2$s" is not a valid context. They are: %3$s', 'event_espresso' ), |
@@ -1,7 +1,7 @@ discard block |
||
1 | 1 | <div id="admin-primary-mbox-dv" class="admin-primary-mbox-dv"> |
2 | 2 | |
3 | 3 | <h3 class="admin-primary-mbox-h4 hdr-has-icon"> |
4 | - <span class="dashicons dashicons-cart"></span><?php _e( 'Transaction Items', 'event_espresso' );?> |
|
4 | + <span class="dashicons dashicons-cart"></span><?php _e('Transaction Items', 'event_espresso'); ?> |
|
5 | 5 | </h3> |
6 | 6 | |
7 | 7 | <div class="admin-primary-mbox-tbl-wrap"> |
@@ -10,27 +10,27 @@ discard block |
||
10 | 10 | </div> |
11 | 11 | |
12 | 12 | <a id="display-additional-transaction-session-info" class="display-the-hidden smaller-text" rel="additional-transaction-session-info"> |
13 | - <span class="dashicons dashicons-plus-alt"></span><?php _e( 'view additional transaction session details', 'event_espresso' );?> |
|
13 | + <span class="dashicons dashicons-plus-alt"></span><?php _e('view additional transaction session details', 'event_espresso'); ?> |
|
14 | 14 | </a> |
15 | 15 | |
16 | 16 | <div id="additional-transaction-session-info-dv" class="hidden"> |
17 | 17 | |
18 | 18 | <a id="hide-additional-transaction-session-info" class="hide-the-displayed hidden smaller-text" rel="additional-transaction-session-info"> |
19 | - <span class="dashicons dashicons-dismiss"></span><?php _e( 'hide additional transaction session details', 'event_espresso' );?> |
|
19 | + <span class="dashicons dashicons-dismiss"></span><?php _e('hide additional transaction session details', 'event_espresso'); ?> |
|
20 | 20 | </a> |
21 | 21 | <br class="clear"/> |
22 | 22 | |
23 | - <h3 class="admin-primary-mbox-h4"><?php _e( 'Transaction Session Details', 'event_espresso' );?></h3> |
|
23 | + <h3 class="admin-primary-mbox-h4"><?php _e('Transaction Session Details', 'event_espresso'); ?></h3> |
|
24 | 24 | |
25 | 25 | <table id="admin-primary-mbox-txn-extra-session-info-tbl" class="form-table skinny-rows"> |
26 | 26 | <tbody> |
27 | - <?php foreach ( $txn_details as $key => $txn_detail ) : ?> |
|
27 | + <?php foreach ($txn_details as $key => $txn_detail) : ?> |
|
28 | 28 | <tr> |
29 | 29 | <th> |
30 | - <label for="<?php echo $key;?>"><?php echo $txn_detail['label'];?></label> |
|
30 | + <label for="<?php echo $key; ?>"><?php echo $txn_detail['label']; ?></label> |
|
31 | 31 | </th> |
32 | 32 | <td> |
33 | - <?php echo $txn_detail['value'];?> |
|
33 | + <?php echo $txn_detail['value']; ?> |
|
34 | 34 | </td> |
35 | 35 | </tr> |
36 | 36 | <?php endforeach; // $txn_details?> |
@@ -40,10 +40,10 @@ discard block |
||
40 | 40 | <br class="clear"/> |
41 | 41 | |
42 | 42 | |
43 | - <?php if ( $attendee instanceof EE_Attendee && ( $grand_raw_total > 0 || $TXN_status != 'TCM' || ! empty( $payments ) ) ) : ?> |
|
43 | + <?php if ($attendee instanceof EE_Attendee && ($grand_raw_total > 0 || $TXN_status != 'TCM' || ! empty($payments))) : ?> |
|
44 | 44 | |
45 | 45 | <h3 class="admin-primary-mbox-h4 hdr-has-icon"> |
46 | - <span class="ee-icon ee-icon-cash"></span><?php _e( 'Payment Details', 'event_espresso' );?> |
|
46 | + <span class="ee-icon ee-icon-cash"></span><?php _e('Payment Details', 'event_espresso'); ?> |
|
47 | 47 | </h3> |
48 | 48 | |
49 | 49 | <div class="admin-primary-mbox-tbl-wrap"> |
@@ -52,75 +52,75 @@ discard block |
||
52 | 52 | <tr> |
53 | 53 | <th></th> |
54 | 54 | <th class="jst-cntr"></th> |
55 | - <th class="jst-cntr"><?php _e( 'ID', 'event_espresso' );?></th> |
|
56 | - <th class="jst-left"><?php _e( 'Date', 'event_espresso' );?></th> |
|
57 | - <th class="jst-cntr"><?php _e( 'Source', 'event_espresso' );?></th> |
|
58 | - <th class="jst-left"><?php _e( 'Method', 'event_espresso' );?></th> |
|
59 | - <th class="jst-left"><?php _e( 'Gateway Response', 'event_espresso' );?></th> |
|
60 | - <th class="jst-left"><?php _e( 'TXN ID / CHQ #', 'event_espresso' );?></th> |
|
61 | - <th class="jst-left"><?php _e( 'P.O. / S.O. #', 'event_espresso' );?></th> |
|
62 | - <th class="jst-left"><?php _e( 'Notes / Extra Accounting', 'event_espresso' );?></th> |
|
63 | - <!--<th class="jst-left"><?php _e( 'Details', 'event_espresso' );?></th>--> |
|
64 | - <th class="jst-cntr"><?php _e( 'Amount', 'event_espresso' );?></th> |
|
55 | + <th class="jst-cntr"><?php _e('ID', 'event_espresso'); ?></th> |
|
56 | + <th class="jst-left"><?php _e('Date', 'event_espresso'); ?></th> |
|
57 | + <th class="jst-cntr"><?php _e('Source', 'event_espresso'); ?></th> |
|
58 | + <th class="jst-left"><?php _e('Method', 'event_espresso'); ?></th> |
|
59 | + <th class="jst-left"><?php _e('Gateway Response', 'event_espresso'); ?></th> |
|
60 | + <th class="jst-left"><?php _e('TXN ID / CHQ #', 'event_espresso'); ?></th> |
|
61 | + <th class="jst-left"><?php _e('P.O. / S.O. #', 'event_espresso'); ?></th> |
|
62 | + <th class="jst-left"><?php _e('Notes / Extra Accounting', 'event_espresso'); ?></th> |
|
63 | + <!--<th class="jst-left"><?php _e('Details', 'event_espresso'); ?></th>--> |
|
64 | + <th class="jst-cntr"><?php _e('Amount', 'event_espresso'); ?></th> |
|
65 | 65 | </tr> |
66 | 66 | </thead> |
67 | 67 | <tbody> |
68 | - <?php if ( $payments ) : ?> |
|
68 | + <?php if ($payments) : ?> |
|
69 | 69 | <?php $payment_total = 0; ?> |
70 | - <?php foreach ( $payments as $PAY_ID => $payment ) : ?> |
|
71 | - <tr id="txn-admin-payment-tr-<?php echo $PAY_ID;?>"> |
|
70 | + <?php foreach ($payments as $PAY_ID => $payment) : ?> |
|
71 | + <tr id="txn-admin-payment-tr-<?php echo $PAY_ID; ?>"> |
|
72 | 72 | <td> |
73 | 73 | <span id="payment-status-<?php echo $PAY_ID; ?>" class="ee-status-strip-td ee-status-strip pymt-status-<?php echo $payment->STS_ID(); ?>"></span> |
74 | - <div id="payment-STS_ID-<?php echo $PAY_ID;?>" class="hidden"><?php echo $payment->STS_ID();?></div> |
|
75 | - <div id="reg-payments-<?php echo $PAY_ID;?>" class="hidden"><?php echo json_encode( $existing_reg_payments[ $PAY_ID ] );?></div> |
|
74 | + <div id="payment-STS_ID-<?php echo $PAY_ID; ?>" class="hidden"><?php echo $payment->STS_ID(); ?></div> |
|
75 | + <div id="reg-payments-<?php echo $PAY_ID; ?>" class="hidden"><?php echo json_encode($existing_reg_payments[$PAY_ID]); ?></div> |
|
76 | 76 | </td> |
77 | 77 | <td class=" jst-cntr"> |
78 | 78 | <ul class="txn-overview-actions-ul"> |
79 | 79 | <li> |
80 | - <a class="txn-admin-payment-action-edit-lnk" title="<?php esc_attr_e( 'Edit Payment', 'event_espresso' );?>" data-payment-id="<?php echo $PAY_ID;?>"> |
|
80 | + <a class="txn-admin-payment-action-edit-lnk" title="<?php esc_attr_e('Edit Payment', 'event_espresso'); ?>" data-payment-id="<?php echo $PAY_ID; ?>"> |
|
81 | 81 | <div class="dashicons dashicons-edit" style="margin: 0;"></div> |
82 | 82 | </a> |
83 | 83 | </li> |
84 | 84 | <li> |
85 | - <a class="txn-admin-payment-action-delete-lnk" title="<?php esc_attr_e( 'Delete Payment', 'event_espresso' );?>" data-payment-id="<?php echo $PAY_ID;?>"> |
|
85 | + <a class="txn-admin-payment-action-delete-lnk" title="<?php esc_attr_e('Delete Payment', 'event_espresso'); ?>" data-payment-id="<?php echo $PAY_ID; ?>"> |
|
86 | 86 | <div class="dashicons dashicons-trash" style="margin: 0;"></div> |
87 | 87 | </a> |
88 | 88 | </li> |
89 | 89 | </ul> |
90 | 90 | </td> |
91 | 91 | <td class=" jst-rght"> |
92 | - <div id="payment-id-<?php echo $PAY_ID;?>"><?php echo $PAY_ID;?></div> |
|
92 | + <div id="payment-id-<?php echo $PAY_ID; ?>"><?php echo $PAY_ID; ?></div> |
|
93 | 93 | </td> |
94 | 94 | <td class=" jst-left"> |
95 | - <div id="payment-date-<?php echo $PAY_ID;?>" class="payment-date-dv"><?php echo $payment->timestamp('Y-m-d', 'g:i a');?></div> |
|
95 | + <div id="payment-date-<?php echo $PAY_ID; ?>" class="payment-date-dv"><?php echo $payment->timestamp('Y-m-d', 'g:i a'); ?></div> |
|
96 | 96 | </td> |
97 | 97 | <td class=" jst-cntr"> |
98 | - <div id="payment-method-<?php echo $PAY_ID;?>"> |
|
99 | - <?php echo $payment->source();?> |
|
98 | + <div id="payment-method-<?php echo $PAY_ID; ?>"> |
|
99 | + <?php echo $payment->source(); ?> |
|
100 | 100 | </div> |
101 | 101 | </td> |
102 | 102 | <td class=" jst-left"> |
103 | - <div id="payment-gateway-<?php echo $PAY_ID;?>"> |
|
104 | - <?php echo $payment->payment_method() ? $payment->payment_method()->admin_name() : __("Unknown", 'event_espresso');?> |
|
103 | + <div id="payment-gateway-<?php echo $PAY_ID; ?>"> |
|
104 | + <?php echo $payment->payment_method() ? $payment->payment_method()->admin_name() : __("Unknown", 'event_espresso'); ?> |
|
105 | 105 | </div> |
106 | - <div id="payment-gateway-id-<?php echo $PAY_ID;?>" class="hidden"><?php echo $payment->payment_method() ? $payment->payment_method()->ID() : 0;?></div> |
|
106 | + <div id="payment-gateway-id-<?php echo $PAY_ID; ?>" class="hidden"><?php echo $payment->payment_method() ? $payment->payment_method()->ID() : 0; ?></div> |
|
107 | 107 | </td> |
108 | 108 | <td class=" jst-left"> |
109 | - <div id="payment-response-<?php echo $PAY_ID;?>"><?php echo $payment->gateway_response();?></div> |
|
109 | + <div id="payment-response-<?php echo $PAY_ID; ?>"><?php echo $payment->gateway_response(); ?></div> |
|
110 | 110 | </td> |
111 | 111 | <td class=" jst-left"> |
112 | - <div id="payment-txn-id-chq-nmbr-<?php echo $PAY_ID;?>"><?php echo $payment->txn_id_chq_nmbr();?></div> |
|
112 | + <div id="payment-txn-id-chq-nmbr-<?php echo $PAY_ID; ?>"><?php echo $payment->txn_id_chq_nmbr(); ?></div> |
|
113 | 113 | </td> |
114 | 114 | <td class=" jst-left"> |
115 | - <div id="payment-po-nmbr-<?php echo $PAY_ID;?>"><?php echo $payment->po_number();?></div> |
|
115 | + <div id="payment-po-nmbr-<?php echo $PAY_ID; ?>"><?php echo $payment->po_number(); ?></div> |
|
116 | 116 | </td> |
117 | 117 | <td class=" jst-left"> |
118 | - <div id="payment-accntng-<?php echo $PAY_ID;?>"><?php echo $payment->extra_accntng();?></div> |
|
118 | + <div id="payment-accntng-<?php echo $PAY_ID; ?>"><?php echo $payment->extra_accntng(); ?></div> |
|
119 | 119 | </td> |
120 | 120 | <td class=" jst-rght"> |
121 | - <?php $payment_class = $payment->amount() > 0 ? 'txn-admin-payment-status-' . $payment->STS_ID() : 'txn-admin-payment-status-PDC'; ?> |
|
122 | - <span class="<?php echo $payment_class;?>"> |
|
123 | - <div id="payment-amount-<?php echo $PAY_ID;?>" style="display:inline;"><?php echo EEH_Template::format_currency($payment->amount(), FALSE, FALSE ); ?></div> |
|
121 | + <?php $payment_class = $payment->amount() > 0 ? 'txn-admin-payment-status-'.$payment->STS_ID() : 'txn-admin-payment-status-PDC'; ?> |
|
122 | + <span class="<?php echo $payment_class; ?>"> |
|
123 | + <div id="payment-amount-<?php echo $PAY_ID; ?>" style="display:inline;"><?php echo EEH_Template::format_currency($payment->amount(), FALSE, FALSE); ?></div> |
|
124 | 124 | </span> |
125 | 125 | </td> |
126 | 126 | </tr> |
@@ -130,25 +130,25 @@ discard block |
||
130 | 130 | <?php endforeach; // $payment?> |
131 | 131 | <?php |
132 | 132 | $pay_totals_class = $payment_total > $grand_raw_total ? ' important-notice' : ''; |
133 | - $overpaid = $payment_total > $grand_raw_total ? '<span id="overpaid">' . __( 'This transaction has been overpaid ! ', 'event_espresso' ) . '</span>' : ''; |
|
133 | + $overpaid = $payment_total > $grand_raw_total ? '<span id="overpaid">'.__('This transaction has been overpaid ! ', 'event_espresso').'</span>' : ''; |
|
134 | 134 | ?> |
135 | 135 | <tr id="txn-admin-no-payments-tr" class="admin-primary-mbox-total-tr hidden"> |
136 | 136 | <td class=" jst-rght" colspan="11"> |
137 | - <span class="important-notice"><?php _e( 'No payments have been applied to this transaction yet. Click "Apply Payment" below to make a payment.', 'event_espresso' ); ?></span> |
|
137 | + <span class="important-notice"><?php _e('No payments have been applied to this transaction yet. Click "Apply Payment" below to make a payment.', 'event_espresso'); ?></span> |
|
138 | 138 | </td> |
139 | 139 | </tr> |
140 | - <tr id="txn-admin-payments-total-tr" class="admin-primary-mbox-total-tr<?php echo $pay_totals_class;?>"> |
|
141 | - <th class=" jst-rght" colspan="10"><span id="payments-total-spn"><?php echo $overpaid . sprintf( __( 'Payments Total %s', 'event_espresso' ), '(' . EE_Registry::instance()->CFG->currency->code . ')' );?></span></th> |
|
142 | - <th class=" jst-rght"><span id="txn-admin-payment-total"><?php echo EEH_Template::format_currency($payment_total, FALSE, FALSE);?></span></th> |
|
140 | + <tr id="txn-admin-payments-total-tr" class="admin-primary-mbox-total-tr<?php echo $pay_totals_class; ?>"> |
|
141 | + <th class=" jst-rght" colspan="10"><span id="payments-total-spn"><?php echo $overpaid.sprintf(__('Payments Total %s', 'event_espresso'), '('.EE_Registry::instance()->CFG->currency->code.')'); ?></span></th> |
|
142 | + <th class=" jst-rght"><span id="txn-admin-payment-total"><?php echo EEH_Template::format_currency($payment_total, FALSE, FALSE); ?></span></th> |
|
143 | 143 | </tr> |
144 | 144 | <?php else : ?> |
145 | 145 | <tr id="txn-admin-no-payments-tr" class="admin-primary-mbox-total-tr"> |
146 | 146 | <td class=" jst-rght" colspan="11"> |
147 | - <span class="important-notice"><?php _e( 'No payments have been applied to this transaction yet. Click "Apply Payment" below to make a payment.', 'event_espresso' ); ?></span> |
|
147 | + <span class="important-notice"><?php _e('No payments have been applied to this transaction yet. Click "Apply Payment" below to make a payment.', 'event_espresso'); ?></span> |
|
148 | 148 | </td> |
149 | 149 | </tr> |
150 | 150 | <tr id="txn-admin-payments-total-tr" class="admin-primary-mbox-total-tr hidden"> |
151 | - <th class=" jst-rght" colspan="10"><span id="payments-total-spn"><?php echo __( 'Payments Total', 'event_espresso' );?></span></th> |
|
151 | + <th class=" jst-rght" colspan="10"><span id="payments-total-spn"><?php echo __('Payments Total', 'event_espresso'); ?></span></th> |
|
152 | 152 | <th class=" jst-rght"><span id="txn-admin-payment-total"></span></th> |
153 | 153 | </tr> |
154 | 154 | <?php endif; // $payments?> |
@@ -161,12 +161,12 @@ discard block |
||
161 | 161 | <td class=" jst-cntr"> |
162 | 162 | <ul class="txn-overview-actions-ul"> |
163 | 163 | <li> |
164 | - <a class="txn-admin-payment-action-edit-lnk" title="<?php esc_attr_e( 'Edit Payment', 'event_espresso' );?>" data-payment-id="PAY_ID"> |
|
164 | + <a class="txn-admin-payment-action-edit-lnk" title="<?php esc_attr_e('Edit Payment', 'event_espresso'); ?>" data-payment-id="PAY_ID"> |
|
165 | 165 | <div class="dashicons dashicons-edit" style="margin: 0;"></div> |
166 | 166 | </a> |
167 | 167 | </li> |
168 | 168 | <li> |
169 | - <a class="txn-admin-payment-action-delete-lnk" title="<?php esc_attr_e( 'Delete Payment', 'event_espresso' );?>" data-payment-id="PAY_ID"> |
|
169 | + <a class="txn-admin-payment-action-delete-lnk" title="<?php esc_attr_e('Delete Payment', 'event_espresso'); ?>" data-payment-id="PAY_ID"> |
|
170 | 170 | <div class="dashicons dashicons-trash" style="margin: 0;"></div> |
171 | 171 | </a> |
172 | 172 | </li> |
@@ -213,12 +213,12 @@ discard block |
||
213 | 213 | <ul id="txn-admin-payment-options-ul"> |
214 | 214 | <li> |
215 | 215 | <a id="display-txn-admin-apply-payment" class="button-primary no-icon no-hide" rel="txn-admin-apply-payment" > <!--display-the-hidden --> |
216 | - <?php _e( 'Apply Payment', 'event_espresso' );?> |
|
216 | + <?php _e('Apply Payment', 'event_espresso'); ?> |
|
217 | 217 | </a> |
218 | 218 | </li> |
219 | 219 | <li> |
220 | 220 | <a id="display-txn-admin-apply-refund" class="button-secondary no-icon no-hide" rel="txn-admin-apply-refund" > <!--display-the-hidden --> |
221 | - <?php _e( 'Apply Refund', 'event_espresso' );?> |
|
221 | + <?php _e('Apply Refund', 'event_espresso'); ?> |
|
222 | 222 | </a> |
223 | 223 | </li> |
224 | 224 | </ul> |
@@ -228,14 +228,14 @@ discard block |
||
228 | 228 | |
229 | 229 | <h2 id="admin-modal-dialog-apply-payment-h2" class="admin-modal-dialog-h2 hdr-has-icon" style="display:none;"> |
230 | 230 | <div class="ee-icon ee-icon-cash-add float-left"></div> |
231 | - <?php echo __( 'Apply a Payment to Transaction #', 'event_espresso' ) . $txn_nmbr['value'];?> |
|
231 | + <?php echo __('Apply a Payment to Transaction #', 'event_espresso').$txn_nmbr['value']; ?> |
|
232 | 232 | </h2> |
233 | 233 | |
234 | 234 | <h2 id="admin-modal-dialog-edit-payment-h2" class="admin-modal-dialog-h2 hdr-has-icon" style="display:none;"> |
235 | 235 | <div class="ee-icon ee-icon-cash-edit float-left"></div> |
236 | 236 | <?php |
237 | 237 | echo sprintf( |
238 | - __( 'Edit Payment #%s for Transaction #%s', 'event_espresso' ), |
|
238 | + __('Edit Payment #%s for Transaction #%s', 'event_espresso'), |
|
239 | 239 | '<span></span>', |
240 | 240 | $txn_nmbr['value'] |
241 | 241 | ); |
@@ -246,7 +246,7 @@ discard block |
||
246 | 246 | <div class="ee-icon ee-icon-cash-edit float-left"></div> |
247 | 247 | <?php |
248 | 248 | echo sprintf( |
249 | - __( 'Edit Refund #%s for Transaction #%s', 'event_espresso' ), |
|
249 | + __('Edit Refund #%s for Transaction #%s', 'event_espresso'), |
|
250 | 250 | '<span></span>', |
251 | 251 | $txn_nmbr['value'] |
252 | 252 | ); |
@@ -255,14 +255,14 @@ discard block |
||
255 | 255 | |
256 | 256 | <h2 id="admin-modal-dialog-apply-refund-h2" class="admin-modal-dialog-h2 hdr-has-icon" style="display:none;"> |
257 | 257 | <div class="ee-icon ee-icon-cash-remove float-left"></div> |
258 | - <?php echo __( 'Apply a Refund to Transaction #', 'event_espresso' ) . $txn_nmbr['value'];?> |
|
258 | + <?php echo __('Apply a Refund to Transaction #', 'event_espresso').$txn_nmbr['value']; ?> |
|
259 | 259 | </h2> |
260 | 260 | |
261 | 261 | <form name="txn-admin-apply-payment-frm" id="txn-admin-apply-payment-frm" action="<?php echo $apply_payment_form_url; ?>"> |
262 | 262 | <div class="admin-modal-dialog-wrap"> |
263 | 263 | <div class="admin-modal-dialog-inner"> |
264 | 264 | |
265 | - <input type="hidden" name="espresso_apply_payment_nonce" id="espresso_apply_payment_nonce" value="<?php echo wp_create_nonce( 'espresso_apply_payment_nonce' );?>"/> |
|
265 | + <input type="hidden" name="espresso_apply_payment_nonce" id="espresso_apply_payment_nonce" value="<?php echo wp_create_nonce('espresso_apply_payment_nonce'); ?>"/> |
|
266 | 266 | <input type="hidden" name="espresso_ajax" id="espresso-ajax" value="0"/> |
267 | 267 | <input type="hidden" name="noheader" id="txn-admin-noheader-inp" value="0"/> |
268 | 268 | <input type="hidden" name="txn_admin_payment[PAY_ID]" id="txn-admin-payment-payment-id-inp" class="txn-admin-apply-payment-inp" value="0"/> |
@@ -270,108 +270,108 @@ discard block |
||
270 | 270 | <input type="hidden" name="txn_admin_payment[type]" id="txn-admin-payment-type-inp" value="1"/> |
271 | 271 | <input type="hidden" name="txn_admin_payment[details]" id="txn-admin-payment-details-inp" value=""/> |
272 | 272 | <input type="hidden" name="txn_admin_delete_payment_form_url" id="txn-admin-delete-payment-form-url-inp" value="<?php echo $delete_payment_form_url; ?>"/> |
273 | - <input type="hidden" name="txn_admin_todays_date" id="txn-admin-todays-date-inp" value="<?php echo date( 'Y-m-d h:i a', current_time( 'timestamp' )); ?>"/> |
|
273 | + <input type="hidden" name="txn_admin_todays_date" id="txn-admin-todays-date-inp" value="<?php echo date('Y-m-d h:i a', current_time('timestamp')); ?>"/> |
|
274 | 274 | |
275 | 275 | <div class="txn-admin-apply-payment-date-dv admin-modal-dialog-row"> |
276 | - <div class="validation-notice-dv"><?php _e( 'The following is a required field', 'event_espresso' );?></div> |
|
277 | - <label for="txn-admin-payment-date-inp" class=""><?php _e( 'Payment Date', 'event_espresso' );?></label> |
|
278 | - <input name="[date]txn_admin_payment" id="txn-admin-payment-date-inp" class="txn-admin-apply-payment-inp required" type="text" value="<?php echo date( 'Y-m-d g:i a', current_time( 'timestamp' )); ?>"/> |
|
279 | - <p class="description"><?php _e( 'The date the payment was actually made on', 'event_espresso' );?></p> |
|
276 | + <div class="validation-notice-dv"><?php _e('The following is a required field', 'event_espresso'); ?></div> |
|
277 | + <label for="txn-admin-payment-date-inp" class=""><?php _e('Payment Date', 'event_espresso'); ?></label> |
|
278 | + <input name="[date]txn_admin_payment" id="txn-admin-payment-date-inp" class="txn-admin-apply-payment-inp required" type="text" value="<?php echo date('Y-m-d g:i a', current_time('timestamp')); ?>"/> |
|
279 | + <p class="description"><?php _e('The date the payment was actually made on', 'event_espresso'); ?></p> |
|
280 | 280 | </div> |
281 | 281 | |
282 | 282 | <div class="txn-admin-apply-payment-amount-dv admin-modal-dialog-row"> |
283 | - <div class="validation-notice-dv"><?php _e( 'The following is a required field', 'event_espresso' );?></div> |
|
284 | - <label for="txn-admin-payment-amount-inp" class=""><?php _e( 'Amount', 'event_espresso' );?></label> |
|
283 | + <div class="validation-notice-dv"><?php _e('The following is a required field', 'event_espresso'); ?></div> |
|
284 | + <label for="txn-admin-payment-amount-inp" class=""><?php _e('Amount', 'event_espresso'); ?></label> |
|
285 | 285 | <input name="txn_admin_payment[amount]" id="txn-admin-payment-amount-inp" class="txn-admin-apply-payment-inp required" type="text" value=""/> |
286 | - <p class="description"><?php _e( 'The amount of the payment', 'event_espresso' );?></p> |
|
286 | + <p class="description"><?php _e('The amount of the payment', 'event_espresso'); ?></p> |
|
287 | 287 | </div> |
288 | 288 | |
289 | 289 | <div class="txn-admin-apply-payment-method-dv admin-modal-dialog-row"> |
290 | - <div class="validation-notice-dv"><?php _e( 'The following is a required field', 'event_espresso' );?></div> |
|
291 | - <label for="txn-admin-payment-method-inp" class=""><?php _e( 'Method of Payment', 'event_espresso' );?></label> |
|
290 | + <div class="validation-notice-dv"><?php _e('The following is a required field', 'event_espresso'); ?></div> |
|
291 | + <label for="txn-admin-payment-method-inp" class=""><?php _e('Method of Payment', 'event_espresso'); ?></label> |
|
292 | 292 | <select name="txn_admin_payment[PMD_ID]" id="txn-admin-payment-method-slct" class="txn-admin-apply-payment-slct required" type="text" > |
293 | - <?php foreach ( $payment_methods as $method ) : ?> |
|
293 | + <?php foreach ($payment_methods as $method) : ?> |
|
294 | 294 | <?php $selected = $method->slug() == 'cash' ? ' selected="selected"' : ''; ?> |
295 | - <option id="payment-method-opt-<?php echo $method->slug(); ?>" value="<?php echo $method->ID(); ?>"<?php echo $selected; ?>><?php echo sanitize_key( $method->admin_desc() ) ? substr( $method->admin_desc(), 0, 128) : $method->admin_name() ; ?> </option> |
|
295 | + <option id="payment-method-opt-<?php echo $method->slug(); ?>" value="<?php echo $method->ID(); ?>"<?php echo $selected; ?>><?php echo sanitize_key($method->admin_desc()) ? substr($method->admin_desc(), 0, 128) : $method->admin_name(); ?> </option> |
|
296 | 296 | <?php endforeach; ?> |
297 | 297 | </select> |
298 | - <p class="description"><?php _e( 'Whether the payment was made via PayPal, Credit Card, Cheque, or Cash', 'event_espresso' );?></p> |
|
298 | + <p class="description"><?php _e('Whether the payment was made via PayPal, Credit Card, Cheque, or Cash', 'event_espresso'); ?></p> |
|
299 | 299 | </div> |
300 | 300 | |
301 | 301 | <div class="mop-PP mop-CC mop-CHQ mop"> |
302 | 302 | <div class="txn-admin-apply-payment-gw-txn-id-dv admin-modal-dialog-row"> |
303 | - <label for="txn-admin-payment-txn-id-inp" class=""><?php _e( 'TXN ID / CHQ #', 'event_espresso' );?></label> |
|
303 | + <label for="txn-admin-payment-txn-id-inp" class=""><?php _e('TXN ID / CHQ #', 'event_espresso'); ?></label> |
|
304 | 304 | <input name="txn_admin_payment[txn_id_chq_nmbr]" id="txn-admin-payment-txn-id-chq-nmbr-inp" class="txn-admin-apply-payment-inp" type="text" maxlength="100"/> |
305 | - <p class="description"><?php _e( 'The Transaction ID sent back from the payment gateway, or the Cheque #', 'event_espresso' );?></p> |
|
305 | + <p class="description"><?php _e('The Transaction ID sent back from the payment gateway, or the Cheque #', 'event_espresso'); ?></p> |
|
306 | 306 | </div> |
307 | 307 | </div> |
308 | 308 | |
309 | 309 | <div class="mop-CC mop" style="display:none"> |
310 | 310 | <div class="txn-admin-apply-payment-response-dv admin-modal-dialog-row"> |
311 | - <label for="txn-admin-payment-gateway-response-inp" class=""><?php _e( 'Gateway Response', 'event_espresso' );?></label> |
|
311 | + <label for="txn-admin-payment-gateway-response-inp" class=""><?php _e('Gateway Response', 'event_espresso'); ?></label> |
|
312 | 312 | <input name="txn_admin_payment[gateway_response]" id="txn-admin-payment-gateway-response-inp" class="txn-admin-apply-payment-inp" type="text"/> |
313 | - <p class="description"><?php _e( 'The gateway response string (optional)', 'event_espresso' );?></p> |
|
313 | + <p class="description"><?php _e('The gateway response string (optional)', 'event_espresso'); ?></p> |
|
314 | 314 | </div> |
315 | 315 | </div> |
316 | 316 | |
317 | 317 | <div class="mop-PP mop-CC mop"> |
318 | 318 | <div class="txn-admin-apply-payment-status-dv admin-modal-dialog-row"> |
319 | - <label for="txn-admin-payment-status-inp" class=""><?php _e( 'Payment Status', 'event_espresso' );?></label> |
|
319 | + <label for="txn-admin-payment-status-inp" class=""><?php _e('Payment Status', 'event_espresso'); ?></label> |
|
320 | 320 | <select name="txn_admin_payment[status]" id="txn-admin-payment-status-slct" class="txn-admin-apply-payment-slct" type="text" > |
321 | - <?php foreach ( $payment_status as $STS_ID => $STS_code ) : ?> |
|
321 | + <?php foreach ($payment_status as $STS_ID => $STS_code) : ?> |
|
322 | 322 | <?php $selected = $STS_ID == 'PAP' ? ' selected="selected"' : ''; ?> |
323 | 323 | <option id="payment-status-opt-<?php echo $STS_ID; ?>" value="<?php echo $STS_ID; ?>"<?php echo $selected; ?>><?php echo $STS_code; ?> </option> |
324 | 324 | <?php endforeach; ?> |
325 | 325 | </select> |
326 | - <p class="description"><?php _e( 'Whether the payment was approved, cancelled, declined or failed after submission to the gateway', 'event_espresso' );?></p> |
|
326 | + <p class="description"><?php _e('Whether the payment was approved, cancelled, declined or failed after submission to the gateway', 'event_espresso'); ?></p> |
|
327 | 327 | </div> |
328 | 328 | </div> |
329 | 329 | |
330 | 330 | <div class="txn-admin-apply-payment-po-nmbr-dv admin-modal-dialog-row"> |
331 | - <label for="txn-admin-payment-po-nmbr-inp" class=""><?php _e( 'P.O. / S.O. #', 'event_espresso' );?></label> |
|
331 | + <label for="txn-admin-payment-po-nmbr-inp" class=""><?php _e('P.O. / S.O. #', 'event_espresso'); ?></label> |
|
332 | 332 | <input name="txn_admin_payment[po_number]" id="txn-admin-payment-po-nmbr-inp" class="txn-admin-apply-payment-inp" type="text" maxlength="100"/> |
333 | - <p class="description"><?php _e( 'The Purchase or Sales Order Number if any (optional)', 'event_espresso' );?></p> |
|
333 | + <p class="description"><?php _e('The Purchase or Sales Order Number if any (optional)', 'event_espresso'); ?></p> |
|
334 | 334 | </div> |
335 | 335 | |
336 | 336 | <div class="txn-admin-apply-payment-accounting-dv admin-modal-dialog-row"> |
337 | - <label for="txn-admin-payment-accounting-inp" class="last"><?php _e( 'Notes / Extra Accounting', 'event_espresso' );?></label> |
|
337 | + <label for="txn-admin-payment-accounting-inp" class="last"><?php _e('Notes / Extra Accounting', 'event_espresso'); ?></label> |
|
338 | 338 | <input name="txn_admin_payment[accounting]" id="txn-admin-payment-accounting-inp" class="txn-admin-apply-payment-inp" type="text" value="<?php echo $REG_code; ?>" maxlength="100"/> <input type="hidden" id="txn-admin-reg-code-inp" value="<?php echo $REG_code; ?>"/> |
339 | - <p class="description"><?php _e( 'An extra field you may use for accounting purposes or simple notes. Defaults to the primary registrant\'s registration code.', 'event_espresso' );?></p> |
|
339 | + <p class="description"><?php _e('An extra field you may use for accounting purposes or simple notes. Defaults to the primary registrant\'s registration code.', 'event_espresso'); ?></p> |
|
340 | 340 | </div> |
341 | 341 | |
342 | 342 | <div class="txn-admin-apply-payment-registrations-dv admin-modal-dialog-row"> |
343 | - <label for="txn-admin-payment-registrations-inp" class="last"><?php _e( 'Registrations to Apply Payment to:', 'event_espresso' ); ?></label> |
|
343 | + <label for="txn-admin-payment-registrations-inp" class="last"><?php _e('Registrations to Apply Payment to:', 'event_espresso'); ?></label> |
|
344 | 344 | <label class="txn-admin-apply-payment-to-registrations-lbl"> |
345 | 345 | <input type="radio" value="1" id="txn-admin-apply-payment-to-all-registrations-inp" name="txn_admin_payment[apply_to_all_registrations]" checked="checked"/> |
346 | - <?php _e( 'ALL Registrations', 'event_espresso' ); ?> |
|
346 | + <?php _e('ALL Registrations', 'event_espresso'); ?> |
|
347 | 347 | </label> |
348 | 348 | <label class="txn-admin-apply-payment-to-registrations-lbl"> |
349 | 349 | <input type="radio" value="0" id="txn-admin-apply-payment-to-some-registrations-inp" name="txn_admin_payment[apply_to_all_registrations]" /> |
350 | - <?php _e( 'Just the following Registrations', 'event_espresso' ); ?> |
|
350 | + <?php _e('Just the following Registrations', 'event_espresso'); ?> |
|
351 | 351 | </label> |
352 | 352 | <?php echo $registrations_to_apply_payment_to; ?> |
353 | 353 | </div> |
354 | 354 | |
355 | 355 | <div class="txn-admin-payment-reg-status-dv admin-modal-dialog-row"> |
356 | - <label for="txn-admin-payment-reg-status-inp" class="last"><?php _e( 'Change Registration Status?', 'event_espresso' );?></label> |
|
356 | + <label for="txn-admin-payment-reg-status-inp" class="last"><?php _e('Change Registration Status?', 'event_espresso'); ?></label> |
|
357 | 357 | <?php echo $status_change_select; ?> |
358 | - <p class="description"><?php _e( 'If you wish to change the status for the registrations selected above, then select which status from this dropdown.', 'event_espresso' ); ?></p> |
|
358 | + <p class="description"><?php _e('If you wish to change the status for the registrations selected above, then select which status from this dropdown.', 'event_espresso'); ?></p> |
|
359 | 359 | <br/> |
360 | 360 | </div> |
361 | 361 | |
362 | 362 | <div class="txn-admin-apply-payment-send-notifications-dv admin-modal-dialog-row"> |
363 | 363 | |
364 | - <label for="txn-admin-payment-send-notifications-inp" class="last"><?php _e( 'Send Related Messages?', 'event_espresso' );?></label> |
|
364 | + <label for="txn-admin-payment-send-notifications-inp" class="last"><?php _e('Send Related Messages?', 'event_espresso'); ?></label> |
|
365 | 365 | <label class="txn-admin-payment-send-notifications-lbl"> |
366 | 366 | <input type="checkbox" value="1" name="txn_payments[send_notifications]" checked="checked" aria-checked="true" style="vertical-align: middle;"> |
367 | - <?php _e( 'Payment Messages?', 'event_espresso' ); ?> |
|
367 | + <?php _e('Payment Messages?', 'event_espresso'); ?> |
|
368 | 368 | </label> |
369 | 369 | <label class="txn-admin-payment-send-notifications-lbl"> |
370 | 370 | <input type="checkbox" value="1" name="txn_reg_status_change[send_notifications]" style="vertical-align: middle;"> |
371 | - <?php _e( 'Registration Messages?', 'event_espresso' ); ?> |
|
371 | + <?php _e('Registration Messages?', 'event_espresso'); ?> |
|
372 | 372 | </label> |
373 | 373 | <br class="clear-float"/> |
374 | - <p class="description"><?php printf( __('By default %1$sa payment message is sent to the primary registrant%2$s after submitting this form.%3$sHowever, if you check the "Registration Messages" box, the system will also send any related messages matching the status of the registrations to %1$seach registration for this transaction%2$s.', 'event_espresso'), '<strong>', '</strong>', '<br />' ); ?></p> |
|
374 | + <p class="description"><?php printf(__('By default %1$sa payment message is sent to the primary registrant%2$s after submitting this form.%3$sHowever, if you check the "Registration Messages" box, the system will also send any related messages matching the status of the registrations to %1$seach registration for this transaction%2$s.', 'event_espresso'), '<strong>', '</strong>', '<br />'); ?></p> |
|
375 | 375 | <label></label> |
376 | 376 | </div> |
377 | 377 | <div class="clear"></div> |
@@ -382,27 +382,27 @@ discard block |
||
382 | 382 | <ul id="admin-modal-dialog-options-ul"> |
383 | 383 | <li> |
384 | 384 | <a id="txn-admin-modal-dialog-apply-payment-lnk" class="button-primary no-icon" style="display:none;" > |
385 | - <?php _e( 'Apply Payment', 'event_espresso' );?> |
|
385 | + <?php _e('Apply Payment', 'event_espresso'); ?> |
|
386 | 386 | </a> |
387 | 387 | </li> |
388 | 388 | <li> |
389 | 389 | <a id="txn-admin-modal-dialog-edit-payment-lnk" class="button-primary no-icon" style="display:none;" > |
390 | - <?php _e( 'Save Payment Details', 'event_espresso' );?> |
|
390 | + <?php _e('Save Payment Details', 'event_espresso'); ?> |
|
391 | 391 | </a> |
392 | 392 | </li> |
393 | 393 | <li> |
394 | 394 | <a id="txn-admin-modal-dialog-edit-refund-lnk" class="button-primary no-icon" style="display:none;" > |
395 | - <?php _e( 'Save Refund Details', 'event_espresso' );?> |
|
395 | + <?php _e('Save Refund Details', 'event_espresso'); ?> |
|
396 | 396 | </a> |
397 | 397 | </li> |
398 | 398 | <li> |
399 | 399 | <a id="txn-admin-modal-dialog-apply-refund-lnk" class="button-primary no-icon" style="display:none;" > |
400 | - <?php _e( 'Apply Refund', 'event_espresso' );?> |
|
400 | + <?php _e('Apply Refund', 'event_espresso'); ?> |
|
401 | 401 | </a> |
402 | 402 | </li> |
403 | 403 | <li> |
404 | 404 | <a id="txn-admin-modal-dialog-cancel-lnk" class="button-secondary no-icon" > |
405 | - <?php _e( 'Cancel', 'event_espresso' );?> |
|
405 | + <?php _e('Cancel', 'event_espresso'); ?> |
|
406 | 406 | </a> |
407 | 407 | </li> |
408 | 408 | <li> |
@@ -419,29 +419,29 @@ discard block |
||
419 | 419 | |
420 | 420 | <h2 id="admin-modal-dialog-delete-payment-h2" class="admin-modal-dialog-h2 hdr-has-icon" style="display:none;"> |
421 | 421 | <span class="ee-icon ee-icon-cash-add"></span> |
422 | - <?php echo __( 'Delete Payment/Refund for Transaction #', 'event_espresso' ) . $txn_nmbr['value'];?> |
|
422 | + <?php echo __('Delete Payment/Refund for Transaction #', 'event_espresso').$txn_nmbr['value']; ?> |
|
423 | 423 | </h2> |
424 | 424 | |
425 | 425 | <form name="txn-admin-delete-payment-frm" id="txn-admin-delete-payment-frm" action="<?php echo $delete_payment_url; ?>"> |
426 | 426 | <div class="admin-modal-dialog-wrap"> |
427 | 427 | <div class="admin-modal-dialog-inner"> |
428 | 428 | |
429 | - <input type="hidden" name="espresso_delete_payment_nonce" id="espresso_delete_payment_nonce" value="<?php echo wp_create_nonce( 'espresso_delete_payment_nonce' );?>"/> |
|
429 | + <input type="hidden" name="espresso_delete_payment_nonce" id="espresso_delete_payment_nonce" value="<?php echo wp_create_nonce('espresso_delete_payment_nonce'); ?>"/> |
|
430 | 430 | <input type="hidden" name="delete_espresso_ajax" id="delete-espresso-ajax" value="0"/> |
431 | 431 | <input type="hidden" name="delete_noheader" id="delete-txn-admin-noheader-inp" value="0"/> |
432 | 432 | <input type="hidden" name="delete_txn_admin_payment[PAY_ID]" id="delete-txn-admin-payment-payment-id-inp" class="txn-admin-apply-payment-inp" value="0"/> |
433 | 433 | <input type="hidden" name="delete_txn_admin_payment[TXN_ID]" id="delete-txn-admin-payment-txn-id-inp" value="<?php echo $txn_nmbr['value']; ?>"/> |
434 | 434 | |
435 | 435 | <div class="txn-admin-apply-payment-accounting-dv admin-modal-dialog-row"> |
436 | - <label for="delete-txn-admin-payment-reg-status-inp" class="last"><?php _e( 'Change Registration Status?', 'event_espresso' );?></label> |
|
436 | + <label for="delete-txn-admin-payment-reg-status-inp" class="last"><?php _e('Change Registration Status?', 'event_espresso'); ?></label> |
|
437 | 437 | <?php echo $delete_status_change_select; ?> |
438 | - <p class="description"><?php printf( __('If you wish to change the status of all the registrations associated with this transaction after deleting this payment/refund, then select which status from this dropdown. %sNote: ALL registrations associated with this transaction will be updated to this new status.%s', 'event_espresso'), '<strong>', '</strong>' ); ?></p> |
|
438 | + <p class="description"><?php printf(__('If you wish to change the status of all the registrations associated with this transaction after deleting this payment/refund, then select which status from this dropdown. %sNote: ALL registrations associated with this transaction will be updated to this new status.%s', 'event_espresso'), '<strong>', '</strong>'); ?></p> |
|
439 | 439 | </div> |
440 | 440 | |
441 | 441 | <div class="ee-attention txn-admin-apply-payment-accounting-dv admin-modal-dialog-row"> |
442 | - <label for="delete-txn-admin-payment-accounting-inp" class="last"><?php _e( 'Send Related Messages?', 'event_espresso' );?></label> |
|
442 | + <label for="delete-txn-admin-payment-accounting-inp" class="last"><?php _e('Send Related Messages?', 'event_espresso'); ?></label> |
|
443 | 443 | <input type="checkbox" value="1" name="delete_txn_reg_status_change[send_notifications]"> |
444 | - <p class="description"><?php _e( 'If you check this box, the system will send any related registration messages matching the status of the registrations to each registration for this transaction. No Payment notifications are sent when deleting a payment.', 'event_espresso' );?></p> |
|
444 | + <p class="description"><?php _e('If you check this box, the system will send any related registration messages matching the status of the registrations to each registration for this transaction. No Payment notifications are sent when deleting a payment.', 'event_espresso'); ?></p> |
|
445 | 445 | </div> |
446 | 446 | <div class="clear"></div> |
447 | 447 | |
@@ -451,12 +451,12 @@ discard block |
||
451 | 451 | <ul id="del-admin-modal-dialog-options-ul"> |
452 | 452 | <li> |
453 | 453 | <a id="txn-admin-modal-dialog-delete-lnk" class="button-primary no-icon" style="display:none;" > |
454 | - <?php _e( 'Delete', 'event_espresso' );?> |
|
454 | + <?php _e('Delete', 'event_espresso'); ?> |
|
455 | 455 | </a> |
456 | 456 | </li> |
457 | 457 | <li> |
458 | 458 | <a id="del-txn-admin-modal-dialog-cancel-lnk" class="button-secondary no-icon" > |
459 | - <?php _e( 'Cancel', 'event_espresso' );?> |
|
459 | + <?php _e('Cancel', 'event_espresso'); ?> |
|
460 | 460 | </a> |
461 | 461 | </li> |
462 | 462 | <li> |
@@ -472,30 +472,30 @@ discard block |
||
472 | 472 | <?php endif; // $grand_raw_total > 0?> |
473 | 473 | |
474 | 474 | <?php |
475 | - if ( WP_DEBUG ) { |
|
476 | - $delivered_messages = get_option( 'EED_Messages__payment', array() ); |
|
477 | - if ( isset( $delivered_messages[ $TXN_ID ] )) { |
|
475 | + if (WP_DEBUG) { |
|
476 | + $delivered_messages = get_option('EED_Messages__payment', array()); |
|
477 | + if (isset($delivered_messages[$TXN_ID])) { |
|
478 | 478 | ?> |
479 | - <h4 class="admin-primary-mbox-h4 hdr-has-icon"><span class="dashicons dashicons-email-alt"></span><?php _e( 'Messages Sent to Primary Registrant', 'event_espresso' );?></h4> |
|
479 | + <h4 class="admin-primary-mbox-h4 hdr-has-icon"><span class="dashicons dashicons-email-alt"></span><?php _e('Messages Sent to Primary Registrant', 'event_espresso'); ?></h4> |
|
480 | 480 | |
481 | 481 | <div class="admin-primary-mbox-tbl-wrap"> |
482 | 482 | <table class="admin-primary-mbox-tbl"> |
483 | 483 | <thead> |
484 | 484 | <tr> |
485 | - <th class="jst-left"><?php _e( 'Date & Time', 'event_espresso' );?></th> |
|
486 | - <th class="jst-left"><?php _e( 'Message Type', 'event_espresso' );?></th> |
|
487 | - <th class="jst-left"><?php _e( 'Payment Status Upon Sending', 'event_espresso' );?></th> |
|
488 | - <th class="jst-left"><?php _e( 'TXN Status Upon Sending', 'event_espresso' );?></th> |
|
485 | + <th class="jst-left"><?php _e('Date & Time', 'event_espresso'); ?></th> |
|
486 | + <th class="jst-left"><?php _e('Message Type', 'event_espresso'); ?></th> |
|
487 | + <th class="jst-left"><?php _e('Payment Status Upon Sending', 'event_espresso'); ?></th> |
|
488 | + <th class="jst-left"><?php _e('TXN Status Upon Sending', 'event_espresso'); ?></th> |
|
489 | 489 | </tr> |
490 | 490 | </thead> |
491 | 491 | <tbody> |
492 | - <?php foreach ( $delivered_messages[ $TXN_ID ] as $timestamp => $delivered_message ) : |
|
492 | + <?php foreach ($delivered_messages[$TXN_ID] as $timestamp => $delivered_message) : |
|
493 | 493 | ?> |
494 | 494 | <tr> |
495 | - <td class="jst-left"><?php echo gmdate( get_option('date_format') . ' ' . get_option('time_format'), ( $timestamp + ( get_option( 'gmt_offset' ) * HOUR_IN_SECONDS ) ) );?></td> |
|
496 | - <td class="jst-left"><?php echo isset( $delivered_message['message_type'] ) ? $delivered_message['message_type'] : '';?></td> |
|
497 | - <td class="jst-left"><?php echo isset( $delivered_message['pay_status'] ) ? $delivered_message['pay_status'] : '';?></td> |
|
498 | - <td class="jst-left"><?php echo isset( $delivered_message['txn_status'] ) ? $delivered_message['txn_status'] : '';?></td> |
|
495 | + <td class="jst-left"><?php echo gmdate(get_option('date_format').' '.get_option('time_format'), ($timestamp + (get_option('gmt_offset') * HOUR_IN_SECONDS))); ?></td> |
|
496 | + <td class="jst-left"><?php echo isset($delivered_message['message_type']) ? $delivered_message['message_type'] : ''; ?></td> |
|
497 | + <td class="jst-left"><?php echo isset($delivered_message['pay_status']) ? $delivered_message['pay_status'] : ''; ?></td> |
|
498 | + <td class="jst-left"><?php echo isset($delivered_message['txn_status']) ? $delivered_message['txn_status'] : ''; ?></td> |
|
499 | 499 | </tr> |
500 | 500 | <?php endforeach; // $delivered_messages?> |
501 | 501 | </tbody> |
@@ -1,5 +1,5 @@ discard block |
||
1 | -<?php if ( !defined( 'EVENT_ESPRESSO_VERSION' ) ) { |
|
2 | - exit( 'No direct script access allowed' ); |
|
1 | +<?php if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
|
2 | + exit('No direct script access allowed'); |
|
3 | 3 | } |
4 | 4 | /** |
5 | 5 | * Event Espresso |
@@ -34,7 +34,7 @@ discard block |
||
34 | 34 | * @param boolean $allow_blocking ignored, because we never block soft deletes |
35 | 35 | * @return bool|int |
36 | 36 | */ |
37 | - protected function _delete( $allow_blocking = true ) { |
|
37 | + protected function _delete($allow_blocking = true) { |
|
38 | 38 | return $this->delete_or_restore(); |
39 | 39 | } |
40 | 40 | |
@@ -44,23 +44,23 @@ discard block |
||
44 | 44 | * @param bool $delete true=>delete, false=>restore |
45 | 45 | * @return bool|int |
46 | 46 | */ |
47 | - public function delete_or_restore( $delete = true ) { |
|
47 | + public function delete_or_restore($delete = true) { |
|
48 | 48 | /** |
49 | 49 | * Called just before trashing (soft delete) or restoring a trashed item. |
50 | 50 | * |
51 | 51 | * @param EE_Base_Class $model_object about to be trashed or restored |
52 | 52 | * @param bool $delete true the item is being trashed, false the item is being restored. |
53 | 53 | */ |
54 | - do_action( 'AHEE__EE_Soft_Delete_Base_Class__delete_or_restore__before', $this, $delete ); |
|
54 | + do_action('AHEE__EE_Soft_Delete_Base_Class__delete_or_restore__before', $this, $delete); |
|
55 | 55 | $model = $this->get_model(); |
56 | - $result = $model->delete_or_restore_by_ID( $delete, $this->ID() ); |
|
56 | + $result = $model->delete_or_restore_by_ID($delete, $this->ID()); |
|
57 | 57 | /** |
58 | 58 | * Called just after trashing (soft delete) or restoring a trashed item. |
59 | 59 | * @param EE_Base_Class $model_object that was just trashed or restored. |
60 | 60 | * @param bool $delete true the item is being trashed, false the item is being restored. |
61 | 61 | * @param bool|int $result |
62 | 62 | */ |
63 | - do_action( 'AHEE__EE_Soft_Delete_Base_Class__delete_or_restore__after', $this, $delete, $result ); |
|
63 | + do_action('AHEE__EE_Soft_Delete_Base_Class__delete_or_restore__after', $this, $delete, $result); |
|
64 | 64 | return $result; |
65 | 65 | } |
66 | 66 | |
@@ -71,6 +71,6 @@ discard block |
||
71 | 71 | * @return bool|int |
72 | 72 | */ |
73 | 73 | public function restore() { |
74 | - return $this->delete_or_restore( false ); |
|
74 | + return $this->delete_or_restore(false); |
|
75 | 75 | } |
76 | 76 | } |
77 | 77 | \ No newline at end of file |
@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php |
2 | -define('EE_Event_Category_Taxonomy','espresso_event_category'); |
|
2 | +define('EE_Event_Category_Taxonomy', 'espresso_event_category'); |
|
3 | 3 | /** |
4 | 4 | * |
5 | 5 | * EEM_CPT_Base |
@@ -16,7 +16,7 @@ discard block |
||
16 | 16 | * @author Mike Nelson |
17 | 17 | * |
18 | 18 | */ |
19 | -abstract class EEM_CPT_Base extends EEM_Soft_Delete_Base{ |
|
19 | +abstract class EEM_CPT_Base extends EEM_Soft_Delete_Base { |
|
20 | 20 | |
21 | 21 | /** |
22 | 22 | * @var string post_status_publish - the wp post status for published cpts |
@@ -69,56 +69,56 @@ discard block |
||
69 | 69 | * @param string $timezone |
70 | 70 | * @throws \EE_Error |
71 | 71 | */ |
72 | - protected function __construct( $timezone = NULL ){ |
|
72 | + protected function __construct($timezone = NULL) { |
|
73 | 73 | |
74 | 74 | //adds a relationship to Term_Taxonomy for all these models. For this to work |
75 | 75 | //Term_Relationship must have a relation to each model subclassing EE_CPT_Base explicitly |
76 | 76 | //eg, in EEM_Term_Relationship, inside the _model_relations array, there must be an entry |
77 | 77 | //with key equalling the subclassing model's model name (eg 'Event' or 'Venue'), and the value |
78 | 78 | //must also be new EE_HABTM_Relation('Term_Relationship'); |
79 | - $this->_model_relations['Term_Taxonomy'] =new EE_HABTM_Relation('Term_Relationship'); |
|
80 | - $this->_model_relations[ 'Post_Meta' ] = new EE_Has_Many_Relation( false ); |
|
79 | + $this->_model_relations['Term_Taxonomy'] = new EE_HABTM_Relation('Term_Relationship'); |
|
80 | + $this->_model_relations['Post_Meta'] = new EE_Has_Many_Relation(false); |
|
81 | 81 | $primary_table_name = NULL; |
82 | 82 | //add the common _status field to all CPT primary tables. |
83 | - foreach ( $this->_tables as $alias => $table_obj ) { |
|
84 | - if ( $table_obj instanceof EE_Primary_Table ) { |
|
83 | + foreach ($this->_tables as $alias => $table_obj) { |
|
84 | + if ($table_obj instanceof EE_Primary_Table) { |
|
85 | 85 | $primary_table_name = $alias; |
86 | 86 | } |
87 | 87 | } |
88 | 88 | //set default wp post statuses if child has not already set. |
89 | - if ( ! isset( $this->_fields[$primary_table_name]['status'] )) { |
|
89 | + if ( ! isset($this->_fields[$primary_table_name]['status'])) { |
|
90 | 90 | $this->_fields[$primary_table_name]['status'] = new EE_WP_Post_Status_Field('post_status', __("Event Status", "event_espresso"), false, 'draft'); |
91 | 91 | } |
92 | - if( ! isset( $this->_fields[$primary_table_name]['to_ping'])){ |
|
93 | - $this->_fields[$primary_table_name]['to_ping'] = new EE_DB_Only_Text_Field('to_ping', __( 'To Ping', 'event_espresso' ), FALSE, ''); |
|
92 | + if ( ! isset($this->_fields[$primary_table_name]['to_ping'])) { |
|
93 | + $this->_fields[$primary_table_name]['to_ping'] = new EE_DB_Only_Text_Field('to_ping', __('To Ping', 'event_espresso'), FALSE, ''); |
|
94 | 94 | } |
95 | - if( ! isset( $this->_fields[$primary_table_name]['pinged'])){ |
|
96 | - $this->_fields[$primary_table_name]['pinged'] = new EE_DB_Only_Text_Field('pinged', __( 'Pinged', 'event_espresso' ), FALSE, ''); |
|
95 | + if ( ! isset($this->_fields[$primary_table_name]['pinged'])) { |
|
96 | + $this->_fields[$primary_table_name]['pinged'] = new EE_DB_Only_Text_Field('pinged', __('Pinged', 'event_espresso'), FALSE, ''); |
|
97 | 97 | } |
98 | 98 | |
99 | - if( ! isset( $this->_fields[$primary_table_name]['comment_status'])){ |
|
100 | - $this->_fields[$primary_table_name]['comment_status'] = new EE_Plain_Text_Field('comment_status', __('Comment Status', 'event_espresso' ), FALSE, 'open'); |
|
99 | + if ( ! isset($this->_fields[$primary_table_name]['comment_status'])) { |
|
100 | + $this->_fields[$primary_table_name]['comment_status'] = new EE_Plain_Text_Field('comment_status', __('Comment Status', 'event_espresso'), FALSE, 'open'); |
|
101 | 101 | } |
102 | 102 | |
103 | - if( ! isset( $this->_fields[$primary_table_name]['ping_status'])){ |
|
103 | + if ( ! isset($this->_fields[$primary_table_name]['ping_status'])) { |
|
104 | 104 | $this->_fields[$primary_table_name]['ping_status'] = new EE_Plain_Text_Field('ping_status', __('Ping Status', 'event_espresso'), FALSE, 'open'); |
105 | 105 | } |
106 | 106 | |
107 | - if( ! isset( $this->_fields[$primary_table_name]['post_content_filtered'])){ |
|
108 | - $this->_fields[$primary_table_name]['post_content_filtered'] = new EE_DB_Only_Text_Field('post_content_filtered', __( 'Post Content Filtered', 'event_espresso' ), FALSE, ''); |
|
107 | + if ( ! isset($this->_fields[$primary_table_name]['post_content_filtered'])) { |
|
108 | + $this->_fields[$primary_table_name]['post_content_filtered'] = new EE_DB_Only_Text_Field('post_content_filtered', __('Post Content Filtered', 'event_espresso'), FALSE, ''); |
|
109 | 109 | } |
110 | - if( ! isset( $this->_model_relations[ 'Post_Meta' ] ) ) { |
|
110 | + if ( ! isset($this->_model_relations['Post_Meta'])) { |
|
111 | 111 | //don't block deletes though because we want to maintain the current behaviour |
112 | - $this->_model_relations[ 'Post_Meta' ] = new EE_Has_Many_Relation( false ); |
|
112 | + $this->_model_relations['Post_Meta'] = new EE_Has_Many_Relation(false); |
|
113 | 113 | } |
114 | - if( ! $this->_minimum_where_conditions_strategy instanceof EE_Default_Where_Conditions ){ |
|
114 | + if ( ! $this->_minimum_where_conditions_strategy instanceof EE_Default_Where_Conditions) { |
|
115 | 115 | //nothing was set during child constructor, so set default |
116 | - $this->_minimum_where_conditions_strategy = new EE_CPT_Minimum_Where_Conditions( $this->post_type() ); |
|
116 | + $this->_minimum_where_conditions_strategy = new EE_CPT_Minimum_Where_Conditions($this->post_type()); |
|
117 | 117 | } |
118 | - if( ! $this->_default_where_conditions_strategy instanceof EE_Default_Where_Conditions ) { |
|
118 | + if ( ! $this->_default_where_conditions_strategy instanceof EE_Default_Where_Conditions) { |
|
119 | 119 | //nothing was set during child constructor, so set default |
120 | 120 | //it's ok for child classes to specify this, but generally this is more DRY |
121 | - $this->_default_where_conditions_strategy = new EE_CPT_Where_Conditions( $this->post_type() ); |
|
121 | + $this->_default_where_conditions_strategy = new EE_CPT_Where_Conditions($this->post_type()); |
|
122 | 122 | } |
123 | 123 | parent::__construct($timezone); |
124 | 124 | |
@@ -131,7 +131,7 @@ discard block |
||
131 | 131 | */ |
132 | 132 | public function public_event_stati() { |
133 | 133 | // @see wp-includes/post.php |
134 | - return get_post_stati( array( 'public' => TRUE )); |
|
134 | + return get_post_stati(array('public' => TRUE)); |
|
135 | 135 | } |
136 | 136 | |
137 | 137 | |
@@ -142,7 +142,7 @@ discard block |
||
142 | 142 | * @return string |
143 | 143 | * @throws EE_Error |
144 | 144 | */ |
145 | - public function deleted_field_name(){ |
|
145 | + public function deleted_field_name() { |
|
146 | 146 | throw new EE_Error(sprintf(__("EEM_CPT_Base should nto call deleted_field_name! It should instead use post_status_field_name", "event_espresso"))); |
147 | 147 | } |
148 | 148 | |
@@ -153,12 +153,12 @@ discard block |
||
153 | 153 | * @return string |
154 | 154 | * @throws EE_Error |
155 | 155 | */ |
156 | - public function post_status_field_name(){ |
|
156 | + public function post_status_field_name() { |
|
157 | 157 | $field = $this->get_a_field_of_type('EE_WP_Post_Status_Field'); |
158 | - if($field){ |
|
158 | + if ($field) { |
|
159 | 159 | return $field->get_name(); |
160 | - }else{ |
|
161 | - throw new EE_Error(sprintf(__('We are trying to find the post status flag field on %s, but none was found. Are you sure there is a field of type EE_Trashed_Flag_Field in %s constructor?','event_espresso'),get_class($this),get_class($this))); |
|
160 | + } else { |
|
161 | + throw new EE_Error(sprintf(__('We are trying to find the post status flag field on %s, but none was found. Are you sure there is a field of type EE_Trashed_Flag_Field in %s constructor?', 'event_espresso'), get_class($this), get_class($this))); |
|
162 | 162 | } |
163 | 163 | } |
164 | 164 | |
@@ -169,9 +169,9 @@ discard block |
||
169 | 169 | * @param array $query_params like EEM_Base::get_all's $query_params |
170 | 170 | * @return array like EEM_Base::get_all's $query_params |
171 | 171 | */ |
172 | - protected function _alter_query_params_so_only_trashed_items_included($query_params){ |
|
173 | - $post_status_field_name=$this->post_status_field_name(); |
|
174 | - $query_params[0][$post_status_field_name]=self::post_status_trashed; |
|
172 | + protected function _alter_query_params_so_only_trashed_items_included($query_params) { |
|
173 | + $post_status_field_name = $this->post_status_field_name(); |
|
174 | + $query_params[0][$post_status_field_name] = self::post_status_trashed; |
|
175 | 175 | return $query_params; |
176 | 176 | } |
177 | 177 | |
@@ -182,8 +182,8 @@ discard block |
||
182 | 182 | * @param array $query_params |
183 | 183 | * @return array |
184 | 184 | */ |
185 | - protected function _alter_query_params_so_deleted_and_undeleted_items_included($query_params){ |
|
186 | - $query_params[ 'default_where_conditions' ] = 'minimum'; |
|
185 | + protected function _alter_query_params_so_deleted_and_undeleted_items_included($query_params) { |
|
186 | + $query_params['default_where_conditions'] = 'minimum'; |
|
187 | 187 | return $query_params; |
188 | 188 | } |
189 | 189 | |
@@ -195,11 +195,11 @@ discard block |
||
195 | 195 | * @param array $query_params like EEM_Base::get_all |
196 | 196 | * @return boolean success |
197 | 197 | */ |
198 | - function delete_or_restore($delete=true,$query_params = array()){ |
|
199 | - $post_status_field_name=$this->post_status_field_name(); |
|
198 | + function delete_or_restore($delete = true, $query_params = array()) { |
|
199 | + $post_status_field_name = $this->post_status_field_name(); |
|
200 | 200 | $query_params = $this->_alter_query_params_so_deleted_and_undeleted_items_included($query_params); |
201 | 201 | $new_status = $delete ? self::post_status_trashed : 'draft'; |
202 | - if ( $this->update (array($post_status_field_name=>$new_status), $query_params )) { |
|
202 | + if ($this->update(array($post_status_field_name=>$new_status), $query_params)) { |
|
203 | 203 | return TRUE; |
204 | 204 | } else { |
205 | 205 | return FALSE; |
@@ -216,7 +216,7 @@ discard block |
||
216 | 216 | */ |
217 | 217 | public function meta_table() { |
218 | 218 | $meta_table = $this->_get_other_tables(); |
219 | - $meta_table = reset( $meta_table ); |
|
219 | + $meta_table = reset($meta_table); |
|
220 | 220 | return $meta_table instanceof EE_Secondary_Table ? $meta_table->get_table_name() : NULL; |
221 | 221 | } |
222 | 222 | |
@@ -228,16 +228,16 @@ discard block |
||
228 | 228 | * @param bool $all triggers whether we include DB_Only fields or JUST non DB_Only fields. Defaults to false (no db only fields) |
229 | 229 | * @return array |
230 | 230 | */ |
231 | - public function get_meta_table_fields( $all = FALSE ) { |
|
231 | + public function get_meta_table_fields($all = FALSE) { |
|
232 | 232 | $all_fields = $fields_to_return = array(); |
233 | - foreach ( $this->_tables as $alias => $table_obj ) { |
|
234 | - if ( $table_obj instanceof EE_Secondary_Table ) |
|
235 | - $all_fields = array_merge( $this->_get_fields_for_table($alias), $all_fields ); |
|
233 | + foreach ($this->_tables as $alias => $table_obj) { |
|
234 | + if ($table_obj instanceof EE_Secondary_Table) |
|
235 | + $all_fields = array_merge($this->_get_fields_for_table($alias), $all_fields); |
|
236 | 236 | } |
237 | 237 | |
238 | - if ( !$all ) { |
|
239 | - foreach ( $all_fields as $name => $obj ) { |
|
240 | - if ( $obj instanceof EE_DB_Only_Field_Base ) |
|
238 | + if ( ! $all) { |
|
239 | + foreach ($all_fields as $name => $obj) { |
|
240 | + if ($obj instanceof EE_DB_Only_Field_Base) |
|
241 | 241 | continue; |
242 | 242 | $fields_to_return[] = $name; |
243 | 243 | } |
@@ -260,13 +260,13 @@ discard block |
||
260 | 260 | * @param int $parent_term_taxonomy_id |
261 | 261 | * @return EE_Term_Taxonomy |
262 | 262 | */ |
263 | - function add_event_category(EE_CPT_Base $cpt_model_object, $category_name, $category_description ='',$parent_term_taxonomy_id = null){ |
|
263 | + function add_event_category(EE_CPT_Base $cpt_model_object, $category_name, $category_description = '', $parent_term_taxonomy_id = null) { |
|
264 | 264 | //create term |
265 | - require_once( EE_MODELS . 'EEM_Term.model.php'); |
|
265 | + require_once(EE_MODELS.'EEM_Term.model.php'); |
|
266 | 266 | //first, check for a term by the same name or slug |
267 | 267 | $category_slug = sanitize_title($category_name); |
268 | - $term = EEM_Term::instance()->get_one(array(array('OR'=>array('name'=>$category_name,'slug'=>$category_slug)))); |
|
269 | - if( ! $term ){ |
|
268 | + $term = EEM_Term::instance()->get_one(array(array('OR'=>array('name'=>$category_name, 'slug'=>$category_slug)))); |
|
269 | + if ( ! $term) { |
|
270 | 270 | $term = EE_Term::new_instance(array( |
271 | 271 | 'name'=>$category_name, |
272 | 272 | 'slug'=>$category_slug |
@@ -274,10 +274,10 @@ discard block |
||
274 | 274 | $term->save(); |
275 | 275 | } |
276 | 276 | //make sure there's a term-taxonomy entry too |
277 | - require_once( EE_MODELS . 'EEM_Term_Taxonomy.model.php'); |
|
278 | - $term_taxonomy = EEM_Term_Taxonomy::instance()->get_one(array(array('term_id'=>$term->ID(),'taxonomy'=>EE_Event_Category_Taxonomy))); |
|
277 | + require_once(EE_MODELS.'EEM_Term_Taxonomy.model.php'); |
|
278 | + $term_taxonomy = EEM_Term_Taxonomy::instance()->get_one(array(array('term_id'=>$term->ID(), 'taxonomy'=>EE_Event_Category_Taxonomy))); |
|
279 | 279 | /** @var $term_taxonomy EE_Term_Taxonomy */ |
280 | - if( ! $term_taxonomy ){ |
|
280 | + if ( ! $term_taxonomy) { |
|
281 | 281 | $term_taxonomy = EE_Term_Taxonomy::new_instance(array( |
282 | 282 | 'term_id'=>$term->ID(), |
283 | 283 | 'taxonomy'=>EE_Event_Category_Taxonomy, |
@@ -286,7 +286,7 @@ discard block |
||
286 | 286 | 'parent'=>$parent_term_taxonomy_id |
287 | 287 | )); |
288 | 288 | $term_taxonomy->save(); |
289 | - }else{ |
|
289 | + } else { |
|
290 | 290 | $term_taxonomy->set_count($term_taxonomy->count() + 1); |
291 | 291 | $term_taxonomy->save(); |
292 | 292 | } |
@@ -301,11 +301,11 @@ discard block |
||
301 | 301 | * @param string $category_name name of the event category (term) |
302 | 302 | * @return bool |
303 | 303 | */ |
304 | - function remove_event_category(EE_CPT_Base $cpt_model_object_event, $category_name){ |
|
304 | + function remove_event_category(EE_CPT_Base $cpt_model_object_event, $category_name) { |
|
305 | 305 | //find the term_taxonomy by that name |
306 | - $term_taxonomy = $this->get_first_related($cpt_model_object_event, 'Term_Taxonomy', array(array('Term.name'=>$category_name,'taxonomy'=>EE_Event_Category_Taxonomy))); |
|
306 | + $term_taxonomy = $this->get_first_related($cpt_model_object_event, 'Term_Taxonomy', array(array('Term.name'=>$category_name, 'taxonomy'=>EE_Event_Category_Taxonomy))); |
|
307 | 307 | /** @var $term_taxonomy EE_Term_Taxonomy */ |
308 | - if( $term_taxonomy ){ |
|
308 | + if ($term_taxonomy) { |
|
309 | 309 | $term_taxonomy->set_count($term_taxonomy->count() - 1); |
310 | 310 | $term_taxonomy->save(); |
311 | 311 | } |
@@ -325,8 +325,8 @@ discard block |
||
325 | 325 | * @param string|array $attr Optional. Query string or array of attributes. |
326 | 326 | * @return string HTML image element |
327 | 327 | */ |
328 | - public function get_feature_image( $id, $size = 'thumbnail', $attr = '' ) { |
|
329 | - return get_the_post_thumbnail( $id, $size, $attr ); |
|
328 | + public function get_feature_image($id, $size = 'thumbnail', $attr = '') { |
|
329 | + return get_the_post_thumbnail($id, $size, $attr); |
|
330 | 330 | } |
331 | 331 | |
332 | 332 | |
@@ -339,10 +339,10 @@ discard block |
||
339 | 339 | * @global array $wp_post_statuses set in wp core for storing all the post stati |
340 | 340 | * @return array |
341 | 341 | */ |
342 | - public function get_post_statuses(){ |
|
342 | + public function get_post_statuses() { |
|
343 | 343 | global $wp_post_statuses; |
344 | 344 | $statuses = array(); |
345 | - foreach($wp_post_statuses as $post_status => $args_object){ |
|
345 | + foreach ($wp_post_statuses as $post_status => $args_object) { |
|
346 | 346 | $statuses[$post_status] = $args_object->label; |
347 | 347 | } |
348 | 348 | return $statuses; |
@@ -357,9 +357,9 @@ discard block |
||
357 | 357 | public function get_status_array() { |
358 | 358 | $statuses = $this->get_post_statuses(); |
359 | 359 | //first the global filter |
360 | - $statuses = apply_filters( 'FHEE_EEM_CPT_Base__get_status_array', $statuses ); |
|
360 | + $statuses = apply_filters('FHEE_EEM_CPT_Base__get_status_array', $statuses); |
|
361 | 361 | //now the class specific filter |
362 | - $statuses = apply_filters( 'FHEE_EEM_' . get_class($this) . '__get_status_array', $statuses ); |
|
362 | + $statuses = apply_filters('FHEE_EEM_'.get_class($this).'__get_status_array', $statuses); |
|
363 | 363 | return $statuses; |
364 | 364 | } |
365 | 365 | |
@@ -371,7 +371,7 @@ discard block |
||
371 | 371 | */ |
372 | 372 | public function get_custom_post_statuses() { |
373 | 373 | $new_stati = array(); |
374 | - foreach ( $this->_custom_stati as $status => $props ) { |
|
374 | + foreach ($this->_custom_stati as $status => $props) { |
|
375 | 375 | $new_stati[$status] = $props['label']; |
376 | 376 | } |
377 | 377 | return $new_stati; |
@@ -387,24 +387,24 @@ discard block |
||
387 | 387 | * @param WP_Post|array $post |
388 | 388 | * @return EE_CPT_Base |
389 | 389 | */ |
390 | - public function instantiate_class_from_post_object_orig($post){ |
|
391 | - $post = (array)$post; |
|
390 | + public function instantiate_class_from_post_object_orig($post) { |
|
391 | + $post = (array) $post; |
|
392 | 392 | $has_all_necessary_fields_for_table = true; |
393 | 393 | //check if the post has fields on the meta table already |
394 | - foreach($this->_get_other_tables() as $table_obj){ |
|
394 | + foreach ($this->_get_other_tables() as $table_obj) { |
|
395 | 395 | $fields_for_that_table = $this->_get_fields_for_table($table_obj->get_table_alias()); |
396 | - foreach($fields_for_that_table as $field_obj){ |
|
397 | - if( ! isset($post[$field_obj->get_table_column()]) |
|
398 | - && ! isset($post[$field_obj->get_qualified_column()])){ |
|
396 | + foreach ($fields_for_that_table as $field_obj) { |
|
397 | + if ( ! isset($post[$field_obj->get_table_column()]) |
|
398 | + && ! isset($post[$field_obj->get_qualified_column()])) { |
|
399 | 399 | $has_all_necessary_fields_for_table = false; |
400 | 400 | } |
401 | 401 | } |
402 | 402 | } |
403 | 403 | //if we don't have all the fields we need, then just fetch the proper model from the DB |
404 | - if( ! $has_all_necessary_fields_for_table){ |
|
404 | + if ( ! $has_all_necessary_fields_for_table) { |
|
405 | 405 | |
406 | 406 | return $this->get_one_by_ID($post['ID']); |
407 | - }else{ |
|
407 | + } else { |
|
408 | 408 | return $this->instantiate_class_from_array_or_object($post); |
409 | 409 | } |
410 | 410 | } |
@@ -415,30 +415,30 @@ discard block |
||
415 | 415 | * @param null $post |
416 | 416 | * @return EE_Base_Class|EE_Soft_Delete_Base_Class |
417 | 417 | */ |
418 | - public function instantiate_class_from_post_object( $post = NULL ){ |
|
419 | - if ( empty( $post )) { |
|
418 | + public function instantiate_class_from_post_object($post = NULL) { |
|
419 | + if (empty($post)) { |
|
420 | 420 | global $post; |
421 | 421 | } |
422 | - $post = (array)$post; |
|
422 | + $post = (array) $post; |
|
423 | 423 | $tables_needing_to_be_queried = array(); |
424 | 424 | //check if the post has fields on the meta table already |
425 | - foreach($this->get_tables() as $table_obj){ |
|
425 | + foreach ($this->get_tables() as $table_obj) { |
|
426 | 426 | $fields_for_that_table = $this->_get_fields_for_table($table_obj->get_table_alias()); |
427 | - foreach($fields_for_that_table as $field_obj){ |
|
428 | - if( ! isset($post[$field_obj->get_table_column()]) |
|
429 | - && ! isset($post[$field_obj->get_qualified_column()])){ |
|
427 | + foreach ($fields_for_that_table as $field_obj) { |
|
428 | + if ( ! isset($post[$field_obj->get_table_column()]) |
|
429 | + && ! isset($post[$field_obj->get_qualified_column()])) { |
|
430 | 430 | $tables_needing_to_be_queried[$table_obj->get_table_alias()] = $table_obj; |
431 | 431 | } |
432 | 432 | } |
433 | 433 | } |
434 | 434 | //if we don't have all the fields we need, then just fetch the proper model from the DB |
435 | - if( $tables_needing_to_be_queried){ |
|
436 | - if(count($tables_needing_to_be_queried) == 1 && reset($tables_needing_to_be_queried) instanceof EE_Secondary_Table){ |
|
435 | + if ($tables_needing_to_be_queried) { |
|
436 | + if (count($tables_needing_to_be_queried) == 1 && reset($tables_needing_to_be_queried) instanceof EE_Secondary_Table) { |
|
437 | 437 | //so we're only missing data from a secondary table. Well that's not too hard to query for |
438 | 438 | $table_to_query = reset($tables_needing_to_be_queried); |
439 | - $missing_data = $this->_do_wpdb_query( 'get_row', array( 'SELECT * FROM ' . $table_to_query->get_table_name() . ' WHERE ' . $table_to_query->get_fk_on_table() . ' = ' . $post['ID'], ARRAY_A )); |
|
440 | - if ( ! empty( $missing_data )) { |
|
441 | - $post = array_merge( $post, $missing_data ); |
|
439 | + $missing_data = $this->_do_wpdb_query('get_row', array('SELECT * FROM '.$table_to_query->get_table_name().' WHERE '.$table_to_query->get_fk_on_table().' = '.$post['ID'], ARRAY_A)); |
|
440 | + if ( ! empty($missing_data)) { |
|
441 | + $post = array_merge($post, $missing_data); |
|
442 | 442 | } |
443 | 443 | } else { |
444 | 444 | return $this->get_one_by_ID($post['ID']); |
@@ -455,15 +455,15 @@ discard block |
||
455 | 455 | * @throws EE_Error |
456 | 456 | * @return string |
457 | 457 | */ |
458 | - public function post_type(){ |
|
458 | + public function post_type() { |
|
459 | 459 | $post_type_field = NULL; |
460 | - foreach($this->field_settings(true) as $field_obj){ |
|
461 | - if($field_obj instanceof EE_WP_Post_Type_Field){ |
|
462 | - $post_type_field = $field_obj;break; |
|
460 | + foreach ($this->field_settings(true) as $field_obj) { |
|
461 | + if ($field_obj instanceof EE_WP_Post_Type_Field) { |
|
462 | + $post_type_field = $field_obj; break; |
|
463 | 463 | } |
464 | 464 | } |
465 | - if($post_type_field == NULL){ |
|
466 | - throw new EE_Error(sprintf(__("CPT Model %s should have a field of type EE_WP_Post_Type, but doesnt", "event_espresso"),get_class($this))); |
|
465 | + if ($post_type_field == NULL) { |
|
466 | + throw new EE_Error(sprintf(__("CPT Model %s should have a field of type EE_WP_Post_Type, but doesnt", "event_espresso"), get_class($this))); |
|
467 | 467 | } |
468 | 468 | return $post_type_field->get_default_value(); |
469 | 469 | } |
@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php |
2 | -if (!defined('EVENT_ESPRESSO_VERSION') ) |
|
2 | +if ( ! defined('EVENT_ESPRESSO_VERSION')) |
|
3 | 3 | exit('NO direct script access allowed'); |
4 | 4 | |
5 | 5 | /** |
@@ -271,7 +271,7 @@ discard block |
||
271 | 271 | * @param bool $preview indicate whether a preview is being generated or not. |
272 | 272 | * @return void |
273 | 273 | */ |
274 | - public function set_messages($data, EE_messenger $active_messenger, $context = '', $preview = FALSE ) { |
|
274 | + public function set_messages($data, EE_messenger $active_messenger, $context = '', $preview = FALSE) { |
|
275 | 275 | |
276 | 276 | $this->_active_messenger = $active_messenger; |
277 | 277 | |
@@ -280,10 +280,10 @@ discard block |
||
280 | 280 | |
281 | 281 | //this is a special method that allows child message types to trigger an exit from generating messages early (in cases where there may be a delay on send). |
282 | 282 | $exit = $this->_trigger_exit(); |
283 | - if ( $exit && ! $this->_preview ) return FALSE; |
|
283 | + if ($exit && ! $this->_preview) return FALSE; |
|
284 | 284 | |
285 | 285 | //todo: need to move require into registration hook but for now we'll require here. |
286 | - EE_Registry::instance()->load_helper( 'Parse_Shortcodes' ); |
|
286 | + EE_Registry::instance()->load_helper('Parse_Shortcodes'); |
|
287 | 287 | //get shortcode_replace instance- set when _get_messages is called in child... |
288 | 288 | $this->_shortcode_replace = new EEH_Parse_Shortcodes(); |
289 | 289 | |
@@ -294,9 +294,9 @@ discard block |
||
294 | 294 | $this->_data_handler = ! $this->_preview ? $this->_data_handler : 'Preview'; |
295 | 295 | |
296 | 296 | //if there is an incoming context then this is a preview so let's ONLY show the given context! |
297 | - if ( !empty( $context ) ) { |
|
298 | - $cntxt = ! empty( $this->_contexts[$context] ) ? $this->_contexts[$context] : ''; |
|
299 | - if ( ! empty( $cntxt ) ) { |
|
297 | + if ( ! empty($context)) { |
|
298 | + $cntxt = ! empty($this->_contexts[$context]) ? $this->_contexts[$context] : ''; |
|
299 | + if ( ! empty($cntxt)) { |
|
300 | 300 | $this->_contexts = array(); |
301 | 301 | $this->_contexts[$context] = $cntxt; |
302 | 302 | } |
@@ -305,7 +305,7 @@ discard block |
||
305 | 305 | $exit = $this->_init_data(); |
306 | 306 | |
307 | 307 | //final check for if we exit or not cause child objects may have run conditionals that cleared out data so no addresees generated. |
308 | - if ( $exit ) return FALSE; |
|
308 | + if ($exit) return FALSE; |
|
309 | 309 | |
310 | 310 | $this->_get_templates(); //get the templates that have been set with this type and for the given messenger that have been saved in the database. |
311 | 311 | $this->_assemble_messages(); |
@@ -341,7 +341,7 @@ discard block |
||
341 | 341 | * @param int $id Optional. Integer corresponding to the value for the primary key of a EE_Base_Class_Object |
342 | 342 | * @return mixed ( EE_Base_Class||EE_Base_Class[] ) |
343 | 343 | */ |
344 | - abstract protected function _get_data_for_context( $context, EE_Registration $registration, $id ); |
|
344 | + abstract protected function _get_data_for_context($context, EE_Registration $registration, $id); |
|
345 | 345 | |
346 | 346 | |
347 | 347 | |
@@ -373,7 +373,7 @@ discard block |
||
373 | 373 | * |
374 | 374 | * @return int |
375 | 375 | */ |
376 | - protected function _get_id_for_msg_url( $context, EE_Registration $registration ) { |
|
376 | + protected function _get_id_for_msg_url($context, EE_Registration $registration) { |
|
377 | 377 | return 0; |
378 | 378 | } |
379 | 379 | |
@@ -406,28 +406,28 @@ discard block |
||
406 | 406 | * |
407 | 407 | * @return string generated url |
408 | 408 | */ |
409 | - public function get_url_trigger( $context, $sending_messenger, EE_Registration $registration ) { |
|
409 | + public function get_url_trigger($context, $sending_messenger, EE_Registration $registration) { |
|
410 | 410 | |
411 | 411 | //validate context |
412 | 412 | //valid context? |
413 | - if ( !isset( $this->_contexts[$context] ) ) { |
|
414 | - throw new EE_Error( sprintf( __('The context %s is not a valid context for %s.', 'event_espresso'), $context, get_class( $this ) ) ); |
|
413 | + if ( ! isset($this->_contexts[$context])) { |
|
414 | + throw new EE_Error(sprintf(__('The context %s is not a valid context for %s.', 'event_espresso'), $context, get_class($this))); |
|
415 | 415 | } |
416 | 416 | |
417 | 417 | //valid sending_messenger? |
418 | 418 | $not_valid_msgr = FALSE; |
419 | - foreach ( $this->_with_messengers as $generating => $sendings ) { |
|
420 | - if ( empty( $sendings ) || array_search( $sending_messenger, $sendings ) === FALSE ) { |
|
419 | + foreach ($this->_with_messengers as $generating => $sendings) { |
|
420 | + if (empty($sendings) || array_search($sending_messenger, $sendings) === FALSE) { |
|
421 | 421 | $not_valid_msgr = TRUE; |
422 | 422 | } |
423 | 423 | } |
424 | 424 | |
425 | - if ( $not_valid_msgr ) { |
|
426 | - throw new EE_Error( sprintf( __('The given sending messenger string (%s) does not match a valid sending messenger with the %s. If this is incorrect, make sure that the message type has defined this messenger as a sending messenger in its $_with_messengers array.', 'event_espresso'), $sending_messenger, get_class( $this ) ) ); |
|
425 | + if ($not_valid_msgr) { |
|
426 | + throw new EE_Error(sprintf(__('The given sending messenger string (%s) does not match a valid sending messenger with the %s. If this is incorrect, make sure that the message type has defined this messenger as a sending messenger in its $_with_messengers array.', 'event_espresso'), $sending_messenger, get_class($this))); |
|
427 | 427 | } |
428 | 428 | |
429 | 429 | EE_Registry::instance()->load_helper('MSG_Template'); |
430 | - return EEH_MSG_Template::generate_url_trigger( $sending_messenger, $this->_active_messenger->name, $context, $this->name, $registration, $this->_GRP_ID, $this->_get_id_for_msg_url( $context, $registration ) ); |
|
430 | + return EEH_MSG_Template::generate_url_trigger($sending_messenger, $this->_active_messenger->name, $context, $this->name, $registration, $this->_GRP_ID, $this->_get_id_for_msg_url($context, $registration)); |
|
431 | 431 | } |
432 | 432 | |
433 | 433 | |
@@ -448,19 +448,19 @@ discard block |
||
448 | 448 | * |
449 | 449 | * @return mixed (EE_Base_Class||EE_Base_Class[]) |
450 | 450 | */ |
451 | - public function get_data_for_context( $context, EE_Registration $registration, $id = 0 ) { |
|
451 | + public function get_data_for_context($context, EE_Registration $registration, $id = 0) { |
|
452 | 452 | //valid context? |
453 | - if ( !isset( $this->_contexts[$context] ) ) { |
|
454 | - throw new EE_Error( sprintf( __('The context %s is not a valid context for %s.', 'event_espresso'), $context, get_class( $this ) ) ); |
|
453 | + if ( ! isset($this->_contexts[$context])) { |
|
454 | + throw new EE_Error(sprintf(__('The context %s is not a valid context for %s.', 'event_espresso'), $context, get_class($this))); |
|
455 | 455 | } |
456 | 456 | |
457 | 457 | //get data and apply global and class specific filters on it. |
458 | - $data = apply_filters( 'FHEE__EE_message_type__get_data_for_context__data', $this->_get_data_for_context( $context, $registration, $id ), $this ); |
|
459 | - $data = apply_filters( 'FHEE__' . get_class( $this ) . '__get_data_for_context__data', $data, $this ); |
|
458 | + $data = apply_filters('FHEE__EE_message_type__get_data_for_context__data', $this->_get_data_for_context($context, $registration, $id), $this); |
|
459 | + $data = apply_filters('FHEE__'.get_class($this).'__get_data_for_context__data', $data, $this); |
|
460 | 460 | |
461 | 461 | //if empty then something went wrong! |
462 | - if ( empty( $data ) ) { |
|
463 | - throw new EE_Error( sprintf( __('There is no data retrieved, it is possible that the id given (%d) does not match any value in the database for the corresponding EE_Base_Class used by the data handler for the %s message type.', 'event_espresso'), $id, $this->name ) ); |
|
462 | + if (empty($data)) { |
|
463 | + throw new EE_Error(sprintf(__('There is no data retrieved, it is possible that the id given (%d) does not match any value in the database for the corresponding EE_Base_Class used by the data handler for the %s message type.', 'event_espresso'), $id, $this->name)); |
|
464 | 464 | } |
465 | 465 | |
466 | 466 | return $data; |
@@ -495,7 +495,7 @@ discard block |
||
495 | 495 | */ |
496 | 496 | public function with_messengers() { |
497 | 497 | |
498 | - return apply_filters( 'FHEE__EE_message_type__get_with_messengers__with_messengers__' . get_class( $this ), $this->_with_messengers); |
|
498 | + return apply_filters('FHEE__EE_message_type__get_with_messengers__with_messengers__'.get_class($this), $this->_with_messengers); |
|
499 | 499 | } |
500 | 500 | |
501 | 501 | |
@@ -513,9 +513,9 @@ discard block |
||
513 | 513 | * @access public |
514 | 514 | * @return void |
515 | 515 | */ |
516 | - public function get_message_type_admin_page_content($page, $action = NULL, $extra = array(), $messengers = array() ) { |
|
516 | + public function get_message_type_admin_page_content($page, $action = NULL, $extra = array(), $messengers = array()) { |
|
517 | 517 | //we can also further refine the context by action (if present). |
518 | - return $this->_get_admin_page_content( $page, $action, $extra, $messengers ); |
|
518 | + return $this->_get_admin_page_content($page, $action, $extra, $messengers); |
|
519 | 519 | } |
520 | 520 | |
521 | 521 | |
@@ -559,8 +559,8 @@ discard block |
||
559 | 559 | */ |
560 | 560 | public function get_master_templates() { |
561 | 561 | //first class specific filter then filter that by the global filter. |
562 | - $master_templates = apply_filters( 'FHEE__' . get_class( $this ) . '__get_master_templates', $this->_master_templates ); |
|
563 | - return apply_filters( 'FHEE__EE_message_type__get_master_templates', $master_templates, $this ); |
|
562 | + $master_templates = apply_filters('FHEE__'.get_class($this).'__get_master_templates', $this->_master_templates); |
|
563 | + return apply_filters('FHEE__EE_message_type__get_master_templates', $master_templates, $this); |
|
564 | 564 | } |
565 | 565 | |
566 | 566 | |
@@ -579,31 +579,31 @@ discard block |
||
579 | 579 | /** |
580 | 580 | * first let's make sure that incoming data isn't empty! |
581 | 581 | */ |
582 | - if ( is_array($this->_data) && empty($this->_data) && !$this->_preview ) { |
|
583 | - $msg = sprintf( __( '"%s" message type incoming data is empty. There is nothing to work with so why are you bugging me?', 'event_espresso'), $this->label['singular'] ); |
|
584 | - throw new EE_Error( $msg ); |
|
582 | + if (is_array($this->_data) && empty($this->_data) && ! $this->_preview) { |
|
583 | + $msg = sprintf(__('"%s" message type incoming data is empty. There is nothing to work with so why are you bugging me?', 'event_espresso'), $this->label['singular']); |
|
584 | + throw new EE_Error($msg); |
|
585 | 585 | } |
586 | 586 | |
587 | - if ( empty( $this->_data_handler) ) { |
|
588 | - $msg = sprintf( __('Hey %s hasn\'t declared a handler for the incoming data, so I\'m stuck', 'event_espresso'), __CLASS__ ); |
|
589 | - throw new EE_Error( $msg ); |
|
587 | + if (empty($this->_data_handler)) { |
|
588 | + $msg = sprintf(__('Hey %s hasn\'t declared a handler for the incoming data, so I\'m stuck', 'event_espresso'), __CLASS__); |
|
589 | + throw new EE_Error($msg); |
|
590 | 590 | } |
591 | 591 | |
592 | 592 | |
593 | 593 | //setup class name for the data handler |
594 | - $classname = 'EE_Messages_' . $this->_data_handler . '_incoming_data'; |
|
594 | + $classname = 'EE_Messages_'.$this->_data_handler.'_incoming_data'; |
|
595 | 595 | |
596 | 596 | //check that the class exists |
597 | - if ( !class_exists( $classname ) ) { |
|
597 | + if ( ! class_exists($classname)) { |
|
598 | 598 | |
599 | 599 | $msg[] = __('uhoh, Something went wrong and no data handler is found', 'event_espresso'); |
600 | - $msg[] = sprintf( __('The %s class has set the "$_data_handler" property but the string included (%s) does not match any existing "EE_Messages_incoming_data" classes (found in "/includes/core/messages/data_class"). Looking for %s.', 'event_espresso'), __CLASS__, $this->_data_handler, $classname ); |
|
601 | - throw new EE_error( implode('||', $msg) ); |
|
600 | + $msg[] = sprintf(__('The %s class has set the "$_data_handler" property but the string included (%s) does not match any existing "EE_Messages_incoming_data" classes (found in "/includes/core/messages/data_class"). Looking for %s.', 'event_espresso'), __CLASS__, $this->_data_handler, $classname); |
|
601 | + throw new EE_error(implode('||', $msg)); |
|
602 | 602 | } |
603 | 603 | |
604 | 604 | //k lets get the prepared data object and replace existing data property with it. |
605 | - $a = new ReflectionClass( $classname ); |
|
606 | - $this->_data = $a->newInstance( $this->_data ); |
|
605 | + $a = new ReflectionClass($classname); |
|
606 | + $this->_data = $a->newInstance($this->_data); |
|
607 | 607 | |
608 | 608 | $this->_set_default_addressee_data(); |
609 | 609 | return $this->_process_data(); |
@@ -619,15 +619,15 @@ discard block |
||
619 | 619 | protected function _process_data() { |
620 | 620 | //at a minimum, we NEED EE_Attendee objects. |
621 | 621 | |
622 | - if ( empty( $this->_data->attendees ) ) |
|
623 | - return TRUE; //EXIT! |
|
622 | + if (empty($this->_data->attendees)) |
|
623 | + return TRUE; //EXIT! |
|
624 | 624 | |
625 | 625 | //process addressees for each context. Child classes will have to have methods for each context defined to handle the processing of the data object within them |
626 | - foreach ( $this->_contexts as $context => $details ) { |
|
627 | - $xpctd_method = '_' . $context . '_addressees'; |
|
628 | - if ( !method_exists( $this, $xpctd_method ) ) |
|
629 | - throw new EE_Error( sprintf( __('The data for %1$s message type cannot be prepared because there is no set method for doing so. The expected method name is "%2$s" please doublecheck the %1$s message type class and make sure that method is present', 'event_espresso'), $this->label['singular'], $xpctd_method) ); |
|
630 | - $this->_addressees[$context] = call_user_func( array( $this, $xpctd_method ) ); |
|
626 | + foreach ($this->_contexts as $context => $details) { |
|
627 | + $xpctd_method = '_'.$context.'_addressees'; |
|
628 | + if ( ! method_exists($this, $xpctd_method)) |
|
629 | + throw new EE_Error(sprintf(__('The data for %1$s message type cannot be prepared because there is no set method for doing so. The expected method name is "%2$s" please doublecheck the %1$s message type class and make sure that method is present', 'event_espresso'), $this->label['singular'], $xpctd_method)); |
|
630 | + $this->_addressees[$context] = call_user_func(array($this, $xpctd_method)); |
|
631 | 631 | } |
632 | 632 | return FALSE; //DON'T EXIT |
633 | 633 | } |
@@ -662,8 +662,8 @@ discard block |
||
662 | 662 | 'total_ticket_count' => $this->_data->total_ticket_count |
663 | 663 | ); |
664 | 664 | |
665 | - if ( is_array( $this->_data->primary_attendee_data ) ) { |
|
666 | - $this->_default_addressee_data = array_merge( $this->_default_addressee_data, $this->_data->primary_attendee_data ); |
|
665 | + if (is_array($this->_data->primary_attendee_data)) { |
|
666 | + $this->_default_addressee_data = array_merge($this->_default_addressee_data, $this->_data->primary_attendee_data); |
|
667 | 667 | $this->_default_addressee_data['primary_att_obj'] = $this->_data->primary_attendee_data['att_obj']; |
668 | 668 | $this->_default_addressee_data['primary_reg_obj'] = $this->_data->primary_attendee_data['reg_obj']; |
669 | 669 | } |
@@ -681,26 +681,26 @@ discard block |
||
681 | 681 | * see abstract declaration in parent class for details, children message types can override these valid shortcodes if desired (we include all for all contexts by default). |
682 | 682 | */ |
683 | 683 | protected function _set_valid_shortcodes() { |
684 | - $all_shortcodes = array( 'attendee_list', 'attendee', 'datetime_list', 'datetime', 'event_list', 'event_meta', 'event', 'organization', 'recipient_details', 'recipient_list', 'ticket_list', 'ticket', 'transaction', 'venue', 'primary_registration_details', 'primary_registration_list', 'event_author', 'email', 'messenger' ); |
|
684 | + $all_shortcodes = array('attendee_list', 'attendee', 'datetime_list', 'datetime', 'event_list', 'event_meta', 'event', 'organization', 'recipient_details', 'recipient_list', 'ticket_list', 'ticket', 'transaction', 'venue', 'primary_registration_details', 'primary_registration_list', 'event_author', 'email', 'messenger'); |
|
685 | 685 | $contexts = $this->get_contexts(); |
686 | - foreach ( $contexts as $context => $details ) { |
|
686 | + foreach ($contexts as $context => $details) { |
|
687 | 687 | $this->_valid_shortcodes[$context] = $all_shortcodes; |
688 | 688 | |
689 | 689 | //make sure non admin context does not include the event_author shortcodes |
690 | - if ( $context != 'admin' ) { |
|
691 | - if( ($key = array_search('event_author', $this->_valid_shortcodes[$context] ) ) !== false) { |
|
690 | + if ($context != 'admin') { |
|
691 | + if (($key = array_search('event_author', $this->_valid_shortcodes[$context])) !== false) { |
|
692 | 692 | unset($this->_valid_shortcodes[$context][$key]); |
693 | 693 | } |
694 | 694 | } |
695 | 695 | } |
696 | 696 | |
697 | 697 | //make sure admin context does not include the recipient_details shortcodes IF we have admin context hooked in message types might not have that context. |
698 | - if ( !empty( $this->_valid_shortcodes['admin'] ) ) { |
|
699 | - if( ($key = array_search('recipient_details', $this->_valid_shortcodes['admin'] ) ) !== false) { |
|
698 | + if ( ! empty($this->_valid_shortcodes['admin'])) { |
|
699 | + if (($key = array_search('recipient_details', $this->_valid_shortcodes['admin'])) !== false) { |
|
700 | 700 | unset($this->_valid_shortcodes['admin'][$key]); |
701 | 701 | } |
702 | 702 | //make sure admin context does not include the recipient_details shortcodes |
703 | - if( ($key = array_search('recipient_list', $this->_valid_shortcodes['admin'] ) ) !== false) { |
|
703 | + if (($key = array_search('recipient_list', $this->_valid_shortcodes['admin'])) !== false) { |
|
704 | 704 | unset($this->_valid_shortcodes['admin'][$key]); |
705 | 705 | } |
706 | 706 | } |
@@ -713,8 +713,8 @@ discard block |
||
713 | 713 | * @param array $new_config array of valid shortcodes (by context) |
714 | 714 | * @return void sets valid_shortcodes property |
715 | 715 | */ |
716 | - public function reset_valid_shortcodes_config( $new_config ) { |
|
717 | - foreach ( $new_config as $context => $shortcodes ) { |
|
716 | + public function reset_valid_shortcodes_config($new_config) { |
|
717 | + foreach ($new_config as $context => $shortcodes) { |
|
718 | 718 | $this->_valid_shortcodes[$context] = $shortcodes; |
719 | 719 | } |
720 | 720 | } |
@@ -734,7 +734,7 @@ discard block |
||
734 | 734 | $addressees = array(); |
735 | 735 | |
736 | 736 | //first we need to get the event admin user id for all the events and setup an addressee object for each unique admin user. |
737 | - foreach ( $this->_data->events as $line_ref => $event ) { |
|
737 | + foreach ($this->_data->events as $line_ref => $event) { |
|
738 | 738 | $admin_id = $this->_get_event_admin_id($event['ID']); |
739 | 739 | //get the user_id for the event |
740 | 740 | $admin_ids[] = $admin_id; |
@@ -746,14 +746,14 @@ discard block |
||
746 | 746 | $admin_ids = array_unique($admin_ids); |
747 | 747 | |
748 | 748 | //k now we can loop through the event_admins and setup the addressee data. |
749 | - foreach ( $admin_ids as $event_admin ) { |
|
749 | + foreach ($admin_ids as $event_admin) { |
|
750 | 750 | $aee = array( |
751 | 751 | 'user_id' => $event_admin, |
752 | 752 | 'events' => $admin_events[$event_admin], |
753 | 753 | 'attendees' => $this->_data->attendees |
754 | 754 | ); |
755 | - $aee = array_merge( $this->_default_addressee_data, $aee ); |
|
756 | - $addressees[] = new EE_Messages_Addressee( $aee ); |
|
755 | + $aee = array_merge($this->_default_addressee_data, $aee); |
|
756 | + $addressees[] = new EE_Messages_Addressee($aee); |
|
757 | 757 | } |
758 | 758 | |
759 | 759 | return $addressees; |
@@ -773,7 +773,7 @@ discard block |
||
773 | 773 | $aee['attendees'] = $this->_data->attendees; |
774 | 774 | |
775 | 775 | //great now we can instantiate the $addressee object and return (as an array); |
776 | - $add[] = new EE_Messages_Addressee( $aee ); |
|
776 | + $add[] = new EE_Messages_Addressee($aee); |
|
777 | 777 | return $add; |
778 | 778 | } |
779 | 779 | |
@@ -792,34 +792,34 @@ discard block |
||
792 | 792 | //use to verify unique attendee emails... we don't want to sent multiple copies to the same attendee do we? |
793 | 793 | $already_processed = array(); |
794 | 794 | |
795 | - foreach ( $this->_data->attendees as $att_id => $details ) { |
|
795 | + foreach ($this->_data->attendees as $att_id => $details) { |
|
796 | 796 | //set the attendee array to blank on each loop; |
797 | 797 | $aee = array(); |
798 | 798 | |
799 | - if ( isset( $this->_data->reg_obj ) && ( $this->_data->reg_obj->attendee_ID() != $att_id ) && $this->_single_message ) continue; |
|
799 | + if (isset($this->_data->reg_obj) && ($this->_data->reg_obj->attendee_ID() != $att_id) && $this->_single_message) continue; |
|
800 | 800 | |
801 | 801 | //is $this->_regs_for_sending present? If so, let's make sure we ONLY generate addressee for registrations in that array. |
802 | - if ( ! empty( $this->_regs_for_sending ) && is_array( $this->_regs_for_sending ) ) { |
|
803 | - $regs_allowed = array_intersect_key( array_flip( $this->_regs_for_sending ), $details['reg_objs'] ); |
|
804 | - if ( empty( $regs_allowed ) ) { |
|
802 | + if ( ! empty($this->_regs_for_sending) && is_array($this->_regs_for_sending)) { |
|
803 | + $regs_allowed = array_intersect_key(array_flip($this->_regs_for_sending), $details['reg_objs']); |
|
804 | + if (empty($regs_allowed)) { |
|
805 | 805 | continue; |
806 | 806 | } |
807 | 807 | } |
808 | 808 | |
809 | - if ( in_array( $details['attendee_email'], $already_processed ) ) |
|
809 | + if (in_array($details['attendee_email'], $already_processed)) |
|
810 | 810 | continue; |
811 | 811 | |
812 | 812 | $already_processed[] = $details['attendee_email']; |
813 | 813 | |
814 | - foreach ( $details as $item => $value ) { |
|
814 | + foreach ($details as $item => $value) { |
|
815 | 815 | $aee[$item] = $value; |
816 | - if ( $item == 'line_ref' ) { |
|
817 | - foreach ( $value as $event_id ) { |
|
816 | + if ($item == 'line_ref') { |
|
817 | + foreach ($value as $event_id) { |
|
818 | 818 | $aee['events'][$event_id] = $this->_data->events[$event_id]; |
819 | 819 | } |
820 | 820 | } |
821 | 821 | |
822 | - if ( $item == 'attendee_email' ) { |
|
822 | + if ($item == 'attendee_email') { |
|
823 | 823 | $aee['attendee_email'] = $value; |
824 | 824 | } |
825 | 825 | |
@@ -834,8 +834,8 @@ discard block |
||
834 | 834 | $aee['attendees'] = $this->_data->attendees; |
835 | 835 | |
836 | 836 | //merge in the primary attendee data |
837 | - $aee = array_merge( $this->_default_addressee_data, $aee ); |
|
838 | - $add[] = new EE_Messages_Addressee( $aee ); |
|
837 | + $aee = array_merge($this->_default_addressee_data, $aee); |
|
838 | + $add[] = new EE_Messages_Addressee($aee); |
|
839 | 839 | } |
840 | 840 | |
841 | 841 | return $add; |
@@ -860,46 +860,46 @@ discard block |
||
860 | 860 | ); |
861 | 861 | |
862 | 862 | //in vanilla EE we're assuming there's only one event. However, if there are multiple events then we'll just use the default templates instead of different templates per event (which could create problems). |
863 | - if ( count($this->_data->events) === 1 ) { |
|
864 | - foreach ( $this->_data->events as $event ) { |
|
863 | + if (count($this->_data->events) === 1) { |
|
864 | + foreach ($this->_data->events as $event) { |
|
865 | 865 | $EVT_ID = $event['ID']; |
866 | 866 | } |
867 | 867 | } |
868 | 868 | // is there a Group ID in the incoming request? |
869 | - EE_Registry::instance()->load_core( 'Request_Handler' ); |
|
869 | + EE_Registry::instance()->load_core('Request_Handler'); |
|
870 | 870 | // if not, set a default value of false |
871 | - $GRP_ID = EE_Registry::instance()->REQ->get( 'GRP_ID', false ); |
|
871 | + $GRP_ID = EE_Registry::instance()->REQ->get('GRP_ID', false); |
|
872 | 872 | //if this is a preview then we just get whatever message group is for the preview and skip this part! |
873 | - if ( $this->_preview && $GRP_ID ) { |
|
874 | - $mtpg = EEM_Message_Template_Group::instance()->get_one_by_ID( $GRP_ID ); |
|
873 | + if ($this->_preview && $GRP_ID) { |
|
874 | + $mtpg = EEM_Message_Template_Group::instance()->get_one_by_ID($GRP_ID); |
|
875 | 875 | } else { |
876 | 876 | //not a preview or test send so lets continue on our way! |
877 | 877 | //is there an evt_id? If so let's get that. template. |
878 | - if ( !empty( $EVT_ID ) ) { |
|
878 | + if ( ! empty($EVT_ID)) { |
|
879 | 879 | $evt_qa = array( |
880 | 880 | 'Event.EVT_ID' => $EVT_ID |
881 | 881 | ); |
882 | - $qa = array_merge( $template_qa, $evt_qa ); |
|
883 | - $mtpg = EEM_Message_Template_Group::instance()->get_one( array( $qa ) ); |
|
882 | + $qa = array_merge($template_qa, $evt_qa); |
|
883 | + $mtpg = EEM_Message_Template_Group::instance()->get_one(array($qa)); |
|
884 | 884 | } |
885 | 885 | |
886 | 886 | //is there a 'GRP_ID' ? if so let's get that. |
887 | 887 | |
888 | 888 | //if global template is NOT an override, and there is a 'GRP_ID' in the request, then we'll assume a specific template has ben requested. |
889 | - if ( $GRP_ID ) { |
|
890 | - $mtpg = EEM_Message_Template_Group::instance()->get_one_by_ID( $GRP_ID ); |
|
889 | + if ($GRP_ID) { |
|
890 | + $mtpg = EEM_Message_Template_Group::instance()->get_one_by_ID($GRP_ID); |
|
891 | 891 | } |
892 | 892 | |
893 | 893 | |
894 | 894 | $template_qa['MTP_is_global'] = TRUE; |
895 | 895 | |
896 | 896 | //this gets the current global template (message template group) for the active messenger and message type. |
897 | - $global_mtpg = EEM_Message_Template_Group::instance()->get_one( array( $template_qa ) ); |
|
897 | + $global_mtpg = EEM_Message_Template_Group::instance()->get_one(array($template_qa)); |
|
898 | 898 | |
899 | - $mtpg = $mtpg instanceof EE_Message_Template_Group && ! $global_mtpg->get( 'MTP_is_override' ) ? $mtpg : $global_mtpg; |
|
899 | + $mtpg = $mtpg instanceof EE_Message_Template_Group && ! $global_mtpg->get('MTP_is_override') ? $mtpg : $global_mtpg; |
|
900 | 900 | } |
901 | 901 | |
902 | - if ( ! $mtpg instanceof EE_Message_Template_Group ) { |
|
902 | + if ( ! $mtpg instanceof EE_Message_Template_Group) { |
|
903 | 903 | //get out because we can't process anything, there are no message template groups |
904 | 904 | // and thus some sort of bad setup issues. |
905 | 905 | return false; |
@@ -915,8 +915,8 @@ discard block |
||
915 | 915 | |
916 | 916 | |
917 | 917 | |
918 | - foreach ( $templates as $context => $template_fields ) { |
|
919 | - foreach( $template_fields as $template_field=> $template_obj ) { |
|
918 | + foreach ($templates as $context => $template_fields) { |
|
919 | + foreach ($template_fields as $template_field=> $template_obj) { |
|
920 | 920 | $this->_templates[$template_field][$context] = $template_obj->get('MTP_content'); |
921 | 921 | } |
922 | 922 | } |
@@ -931,11 +931,11 @@ discard block |
||
931 | 931 | protected function _assemble_messages() { |
932 | 932 | //make sure any set messages object is cleared |
933 | 933 | $this->messages = array(); |
934 | - foreach ( $this->_addressees as $context => $addressees ) { |
|
935 | - foreach ( $addressees as $addressee ) { |
|
934 | + foreach ($this->_addressees as $context => $addressees) { |
|
935 | + foreach ($addressees as $addressee) { |
|
936 | 936 | $message = $this->_setup_message_object($context, $addressee); |
937 | 937 | //only assign message if everything went okay |
938 | - if ( $message ) { |
|
938 | + if ($message) { |
|
939 | 939 | $message->template_pack = $this->_template_pack; |
940 | 940 | $message->variation = $this->_variation; |
941 | 941 | $this->messages[] = $message; |
@@ -959,22 +959,22 @@ discard block |
||
959 | 959 | $m_shortcodes = $this->_active_messenger->get_valid_shortcodes(); |
960 | 960 | |
961 | 961 | //if the 'to' field is empty (messages will ALWAYS have a "to" field, then we get out because this context is turned off) EXCEPT if we're previewing |
962 | - if ( ( isset( $this->_templates['to'][$context] ) && empty( $this->_templates['to'][$context] ) ) && !$this->_preview ) |
|
962 | + if ((isset($this->_templates['to'][$context]) && empty($this->_templates['to'][$context])) && ! $this->_preview) |
|
963 | 963 | return false; |
964 | 964 | |
965 | - if ( empty( $this->_templates ) ) { |
|
965 | + if (empty($this->_templates)) { |
|
966 | 966 | //unable to setup any messages because there are no templates. Some sort of catastrophic setup |
967 | 967 | //issue exists |
968 | 968 | return false; |
969 | 969 | } |
970 | 970 | |
971 | - foreach ( $this->_templates as $field => $ctxt ) { |
|
971 | + foreach ($this->_templates as $field => $ctxt) { |
|
972 | 972 | //let's setup the valid shortcodes for the incoming context. |
973 | 973 | $valid_shortcodes = $mt_shortcodes[$context]; |
974 | 974 | //merge in valid shortcodes for the field. |
975 | 975 | $shortcodes = isset($m_shortcodes[$field]) ? $m_shortcodes[$field] : $valid_shortcodes; |
976 | - if ( isset( $this->_templates[$field][$context] ) ) { |
|
977 | - $message->{$field} = $this->_shortcode_replace->parse_message_template($this->_templates[$field][$context], $addressee, $shortcodes, $this, $this->_active_messenger, $context, $this->_GRP_ID ); |
|
976 | + if (isset($this->_templates[$field][$context])) { |
|
977 | + $message->{$field} = $this->_shortcode_replace->parse_message_template($this->_templates[$field][$context], $addressee, $shortcodes, $this, $this->_active_messenger, $context, $this->_GRP_ID); |
|
978 | 978 | } |
979 | 979 | } |
980 | 980 | return $message; |
@@ -38,8 +38,8 @@ discard block |
||
38 | 38 | * @return EED_Single_Page_Checkout |
39 | 39 | */ |
40 | 40 | public static function instance() { |
41 | - add_filter( 'EED_Single_Page_Checkout__SPCO_active', '__return_true' ); |
|
42 | - return parent::get_instance( __CLASS__ ); |
|
41 | + add_filter('EED_Single_Page_Checkout__SPCO_active', '__return_true'); |
|
42 | + return parent::get_instance(__CLASS__); |
|
43 | 43 | } |
44 | 44 | |
45 | 45 | |
@@ -84,22 +84,22 @@ discard block |
||
84 | 84 | */ |
85 | 85 | public static function set_hooks_admin() { |
86 | 86 | EED_Single_Page_Checkout::set_definitions(); |
87 | - if ( defined( 'DOING_AJAX' )) { |
|
87 | + if (defined('DOING_AJAX')) { |
|
88 | 88 | // going to start an output buffer in case anything gets accidentally output that might disrupt our JSON response |
89 | 89 | ob_start(); |
90 | 90 | EED_Single_Page_Checkout::load_request_handler(); |
91 | 91 | EED_Single_Page_Checkout::load_reg_steps(); |
92 | 92 | } else { |
93 | 93 | // hook into the top of pre_get_posts to set the reg step routing, which gives other modules or plugins a chance to modify the reg steps, but just before the routes get called |
94 | - add_action( 'pre_get_posts', array( 'EED_Single_Page_Checkout', 'load_reg_steps' ), 1 ); |
|
94 | + add_action('pre_get_posts', array('EED_Single_Page_Checkout', 'load_reg_steps'), 1); |
|
95 | 95 | } |
96 | 96 | // set ajax hooks |
97 | - add_action( 'wp_ajax_process_reg_step', array( 'EED_Single_Page_Checkout', 'process_reg_step' )); |
|
98 | - add_action( 'wp_ajax_nopriv_process_reg_step', array( 'EED_Single_Page_Checkout', 'process_reg_step' )); |
|
99 | - add_action( 'wp_ajax_display_spco_reg_step', array( 'EED_Single_Page_Checkout', 'display_reg_step' )); |
|
100 | - add_action( 'wp_ajax_nopriv_display_spco_reg_step', array( 'EED_Single_Page_Checkout', 'display_reg_step' )); |
|
101 | - add_action( 'wp_ajax_update_reg_step', array( 'EED_Single_Page_Checkout', 'update_reg_step' )); |
|
102 | - add_action( 'wp_ajax_nopriv_update_reg_step', array( 'EED_Single_Page_Checkout', 'update_reg_step' )); |
|
97 | + add_action('wp_ajax_process_reg_step', array('EED_Single_Page_Checkout', 'process_reg_step')); |
|
98 | + add_action('wp_ajax_nopriv_process_reg_step', array('EED_Single_Page_Checkout', 'process_reg_step')); |
|
99 | + add_action('wp_ajax_display_spco_reg_step', array('EED_Single_Page_Checkout', 'display_reg_step')); |
|
100 | + add_action('wp_ajax_nopriv_display_spco_reg_step', array('EED_Single_Page_Checkout', 'display_reg_step')); |
|
101 | + add_action('wp_ajax_update_reg_step', array('EED_Single_Page_Checkout', 'update_reg_step')); |
|
102 | + add_action('wp_ajax_nopriv_update_reg_step', array('EED_Single_Page_Checkout', 'update_reg_step')); |
|
103 | 103 | } |
104 | 104 | |
105 | 105 | |
@@ -108,8 +108,8 @@ discard block |
||
108 | 108 | * process ajax request |
109 | 109 | * @param string $ajax_action |
110 | 110 | */ |
111 | - public static function process_ajax_request( $ajax_action ) { |
|
112 | - EE_Registry::instance()->REQ->set( 'action', $ajax_action ); |
|
111 | + public static function process_ajax_request($ajax_action) { |
|
112 | + EE_Registry::instance()->REQ->set('action', $ajax_action); |
|
113 | 113 | EED_Single_Page_Checkout::instance()->_initialize(); |
114 | 114 | } |
115 | 115 | |
@@ -119,7 +119,7 @@ discard block |
||
119 | 119 | * ajax display registration step |
120 | 120 | */ |
121 | 121 | public static function display_reg_step() { |
122 | - EED_Single_Page_Checkout::process_ajax_request( 'display_spco_reg_step' ); |
|
122 | + EED_Single_Page_Checkout::process_ajax_request('display_spco_reg_step'); |
|
123 | 123 | } |
124 | 124 | |
125 | 125 | |
@@ -128,7 +128,7 @@ discard block |
||
128 | 128 | * ajax process registration step |
129 | 129 | */ |
130 | 130 | public static function process_reg_step() { |
131 | - EED_Single_Page_Checkout::process_ajax_request( 'process_reg_step' ); |
|
131 | + EED_Single_Page_Checkout::process_ajax_request('process_reg_step'); |
|
132 | 132 | } |
133 | 133 | |
134 | 134 | |
@@ -137,7 +137,7 @@ discard block |
||
137 | 137 | * ajax process registration step |
138 | 138 | */ |
139 | 139 | public static function update_reg_step() { |
140 | - EED_Single_Page_Checkout::process_ajax_request( 'update_reg_step' ); |
|
140 | + EED_Single_Page_Checkout::process_ajax_request('update_reg_step'); |
|
141 | 141 | } |
142 | 142 | |
143 | 143 | |
@@ -149,7 +149,7 @@ discard block |
||
149 | 149 | * @return void |
150 | 150 | */ |
151 | 151 | public static function update_checkout() { |
152 | - EED_Single_Page_Checkout::process_ajax_request( 'update_checkout' ); |
|
152 | + EED_Single_Page_Checkout::process_ajax_request('update_checkout'); |
|
153 | 153 | } |
154 | 154 | |
155 | 155 | |
@@ -162,8 +162,8 @@ discard block |
||
162 | 162 | */ |
163 | 163 | public static function load_request_handler() { |
164 | 164 | // load core Request_Handler class |
165 | - if ( ! isset( EE_Registry::instance()->REQ )) { |
|
166 | - EE_Registry::instance()->load_core( 'Request_Handler' ); |
|
165 | + if ( ! isset(EE_Registry::instance()->REQ)) { |
|
166 | + EE_Registry::instance()->load_core('Request_Handler'); |
|
167 | 167 | } |
168 | 168 | } |
169 | 169 | |
@@ -176,14 +176,14 @@ discard block |
||
176 | 176 | * @return void |
177 | 177 | */ |
178 | 178 | public static function set_definitions() { |
179 | - define( 'SPCO_BASE_PATH', rtrim( str_replace( array( '\\', '/' ), DS, plugin_dir_path( __FILE__ )), DS ) . DS ); |
|
180 | - define( 'SPCO_CSS_URL', plugin_dir_url( __FILE__ ) . 'css' . DS ); |
|
181 | - define( 'SPCO_IMG_URL', plugin_dir_url( __FILE__ ) . 'img' . DS ); |
|
182 | - define( 'SPCO_JS_URL', plugin_dir_url( __FILE__ ) . 'js' . DS ); |
|
183 | - define( 'SPCO_INC_PATH', SPCO_BASE_PATH . 'inc' . DS ); |
|
184 | - define( 'SPCO_REG_STEPS_PATH', SPCO_BASE_PATH . 'reg_steps' . DS ); |
|
185 | - define( 'SPCO_TEMPLATES_PATH', SPCO_BASE_PATH . 'templates' . DS ); |
|
186 | - EEH_Autoloader::register_autoloaders_for_each_file_in_folder( SPCO_BASE_PATH, TRUE ); |
|
179 | + define('SPCO_BASE_PATH', rtrim(str_replace(array('\\', '/'), DS, plugin_dir_path(__FILE__)), DS).DS); |
|
180 | + define('SPCO_CSS_URL', plugin_dir_url(__FILE__).'css'.DS); |
|
181 | + define('SPCO_IMG_URL', plugin_dir_url(__FILE__).'img'.DS); |
|
182 | + define('SPCO_JS_URL', plugin_dir_url(__FILE__).'js'.DS); |
|
183 | + define('SPCO_INC_PATH', SPCO_BASE_PATH.'inc'.DS); |
|
184 | + define('SPCO_REG_STEPS_PATH', SPCO_BASE_PATH.'reg_steps'.DS); |
|
185 | + define('SPCO_TEMPLATES_PATH', SPCO_BASE_PATH.'templates'.DS); |
|
186 | + EEH_Autoloader::register_autoloaders_for_each_file_in_folder(SPCO_BASE_PATH, TRUE); |
|
187 | 187 | } |
188 | 188 | |
189 | 189 | |
@@ -198,7 +198,7 @@ discard block |
||
198 | 198 | */ |
199 | 199 | public static function load_reg_steps() { |
200 | 200 | static $reg_steps_loaded = FALSE; |
201 | - if ( $reg_steps_loaded ) { |
|
201 | + if ($reg_steps_loaded) { |
|
202 | 202 | return; |
203 | 203 | } |
204 | 204 | // filter list of reg_steps |
@@ -207,24 +207,24 @@ discard block |
||
207 | 207 | EED_Single_Page_Checkout::get_reg_steps() |
208 | 208 | ); |
209 | 209 | // sort by key (order) |
210 | - ksort( $reg_steps_to_load ); |
|
210 | + ksort($reg_steps_to_load); |
|
211 | 211 | // loop through folders |
212 | - foreach ( $reg_steps_to_load as $order => $reg_step ) { |
|
212 | + foreach ($reg_steps_to_load as $order => $reg_step) { |
|
213 | 213 | // we need a |
214 | - if ( isset( $reg_step['file_path'], $reg_step['class_name'], $reg_step['slug'] )) { |
|
214 | + if (isset($reg_step['file_path'], $reg_step['class_name'], $reg_step['slug'])) { |
|
215 | 215 | // copy over to the reg_steps_array |
216 | - EED_Single_Page_Checkout::$_reg_steps_array[ $order ] = $reg_step; |
|
216 | + EED_Single_Page_Checkout::$_reg_steps_array[$order] = $reg_step; |
|
217 | 217 | // register custom key route for each reg step |
218 | 218 | // ie: step=>"slug" - this is the entire reason we load the reg steps array now |
219 | - EE_Config::register_route( $reg_step['slug'], 'EED_Single_Page_Checkout', 'run', 'step' ); |
|
219 | + EE_Config::register_route($reg_step['slug'], 'EED_Single_Page_Checkout', 'run', 'step'); |
|
220 | 220 | // add AJAX or other hooks |
221 | - if ( isset( $reg_step['has_hooks'] ) && $reg_step['has_hooks'] ) { |
|
221 | + if (isset($reg_step['has_hooks']) && $reg_step['has_hooks']) { |
|
222 | 222 | // setup autoloaders if necessary |
223 | - if ( ! class_exists( $reg_step['class_name'] )) { |
|
224 | - EEH_Autoloader::register_autoloaders_for_each_file_in_folder( $reg_step['file_path'], TRUE ); |
|
223 | + if ( ! class_exists($reg_step['class_name'])) { |
|
224 | + EEH_Autoloader::register_autoloaders_for_each_file_in_folder($reg_step['file_path'], TRUE); |
|
225 | 225 | } |
226 | - if ( is_callable( $reg_step['class_name'], 'set_hooks' )) { |
|
227 | - call_user_func( array( $reg_step['class_name'], 'set_hooks' )); |
|
226 | + if (is_callable($reg_step['class_name'], 'set_hooks')) { |
|
227 | + call_user_func(array($reg_step['class_name'], 'set_hooks')); |
|
228 | 228 | } |
229 | 229 | } |
230 | 230 | } |
@@ -243,28 +243,28 @@ discard block |
||
243 | 243 | */ |
244 | 244 | public static function get_reg_steps() { |
245 | 245 | $reg_steps = EE_Registry::instance()->CFG->registration->reg_steps; |
246 | - if ( empty( $reg_steps )) { |
|
246 | + if (empty($reg_steps)) { |
|
247 | 247 | $reg_steps = array( |
248 | 248 | 10 => array( |
249 | - 'file_path' => SPCO_REG_STEPS_PATH . 'attendee_information', |
|
249 | + 'file_path' => SPCO_REG_STEPS_PATH.'attendee_information', |
|
250 | 250 | 'class_name' => 'EE_SPCO_Reg_Step_Attendee_Information', |
251 | 251 | 'slug' => 'attendee_information', |
252 | 252 | 'has_hooks' => FALSE |
253 | 253 | ), |
254 | 254 | 20 => array( |
255 | - 'file_path' => SPCO_REG_STEPS_PATH . 'registration_confirmation', |
|
255 | + 'file_path' => SPCO_REG_STEPS_PATH.'registration_confirmation', |
|
256 | 256 | 'class_name' => 'EE_SPCO_Reg_Step_Registration_Confirmation', |
257 | 257 | 'slug' => 'registration_confirmation', |
258 | 258 | 'has_hooks' => FALSE |
259 | 259 | ), |
260 | 260 | 30 => array( |
261 | - 'file_path' => SPCO_REG_STEPS_PATH . 'payment_options', |
|
261 | + 'file_path' => SPCO_REG_STEPS_PATH.'payment_options', |
|
262 | 262 | 'class_name' => 'EE_SPCO_Reg_Step_Payment_Options', |
263 | 263 | 'slug' => 'payment_options', |
264 | 264 | 'has_hooks' => TRUE |
265 | 265 | ), |
266 | 266 | 999 => array( |
267 | - 'file_path' => SPCO_REG_STEPS_PATH . 'finalize_registration', |
|
267 | + 'file_path' => SPCO_REG_STEPS_PATH.'finalize_registration', |
|
268 | 268 | 'class_name' => 'EE_SPCO_Reg_Step_Finalize_Registration', |
269 | 269 | 'slug' => 'finalize_registration', |
270 | 270 | 'has_hooks' => FALSE |
@@ -284,9 +284,9 @@ discard block |
||
284 | 284 | */ |
285 | 285 | public static function registration_checkout_for_admin() { |
286 | 286 | EED_Single_Page_Checkout::load_reg_steps(); |
287 | - EE_Registry::instance()->REQ->set( 'step', 'attendee_information' ); |
|
288 | - EE_Registry::instance()->REQ->set( 'action', 'display_spco_reg_step' ); |
|
289 | - EE_Registry::instance()->REQ->set( 'process_form_submission', false ); |
|
287 | + EE_Registry::instance()->REQ->set('step', 'attendee_information'); |
|
288 | + EE_Registry::instance()->REQ->set('action', 'display_spco_reg_step'); |
|
289 | + EE_Registry::instance()->REQ->set('process_form_submission', false); |
|
290 | 290 | EED_Single_Page_Checkout::instance()->_initialize(); |
291 | 291 | EED_Single_Page_Checkout::instance()->_display_spco_reg_form(); |
292 | 292 | return EE_Registry::instance()->REQ->get_output(); |
@@ -302,14 +302,14 @@ discard block |
||
302 | 302 | */ |
303 | 303 | public static function process_registration_from_admin() { |
304 | 304 | EED_Single_Page_Checkout::load_reg_steps(); |
305 | - EE_Registry::instance()->REQ->set( 'step', 'attendee_information' ); |
|
306 | - EE_Registry::instance()->REQ->set( 'action', 'process_reg_step' ); |
|
307 | - EE_Registry::instance()->REQ->set( 'process_form_submission', true ); |
|
305 | + EE_Registry::instance()->REQ->set('step', 'attendee_information'); |
|
306 | + EE_Registry::instance()->REQ->set('action', 'process_reg_step'); |
|
307 | + EE_Registry::instance()->REQ->set('process_form_submission', true); |
|
308 | 308 | EED_Single_Page_Checkout::instance()->_initialize(); |
309 | - if ( EED_Single_Page_Checkout::instance()->checkout->current_step->completed() ) { |
|
310 | - $final_reg_step = end( EED_Single_Page_Checkout::instance()->checkout->reg_steps ); |
|
311 | - if ( $final_reg_step instanceof EE_SPCO_Reg_Step_Finalize_Registration ) { |
|
312 | - if ( $final_reg_step->process_reg_step() ) { |
|
309 | + if (EED_Single_Page_Checkout::instance()->checkout->current_step->completed()) { |
|
310 | + $final_reg_step = end(EED_Single_Page_Checkout::instance()->checkout->reg_steps); |
|
311 | + if ($final_reg_step instanceof EE_SPCO_Reg_Step_Finalize_Registration) { |
|
312 | + if ($final_reg_step->process_reg_step()) { |
|
313 | 313 | return EED_Single_Page_Checkout::instance()->checkout->transaction; |
314 | 314 | } |
315 | 315 | } |
@@ -326,11 +326,11 @@ discard block |
||
326 | 326 | * @param WP_Query $WP_Query |
327 | 327 | * @return void |
328 | 328 | */ |
329 | - public function run( $WP_Query ) { |
|
329 | + public function run($WP_Query) { |
|
330 | 330 | if ( |
331 | 331 | $WP_Query instanceof WP_Query |
332 | 332 | && $WP_Query->is_main_query() |
333 | - && apply_filters( 'FHEE__EED_Single_Page_Checkout__run', true ) |
|
333 | + && apply_filters('FHEE__EED_Single_Page_Checkout__run', true) |
|
334 | 334 | ) { |
335 | 335 | $this->_initialize(); |
336 | 336 | } |
@@ -346,8 +346,8 @@ discard block |
||
346 | 346 | * @param WP_Query $WP_Query |
347 | 347 | * @return void |
348 | 348 | */ |
349 | - public static function init( $WP_Query ) { |
|
350 | - EED_Single_Page_Checkout::instance()->run( $WP_Query ); |
|
349 | + public static function init($WP_Query) { |
|
350 | + EED_Single_Page_Checkout::instance()->run($WP_Query); |
|
351 | 351 | } |
352 | 352 | |
353 | 353 | |
@@ -361,35 +361,35 @@ discard block |
||
361 | 361 | */ |
362 | 362 | private function _initialize() { |
363 | 363 | // ensure SPCO doesn't run twice |
364 | - if ( EED_Single_Page_Checkout::$_initialized ) { |
|
364 | + if (EED_Single_Page_Checkout::$_initialized) { |
|
365 | 365 | return; |
366 | 366 | } |
367 | 367 | // setup the EE_Checkout object |
368 | 368 | $this->checkout = $this->_initialize_checkout(); |
369 | 369 | // filter checkout |
370 | - $this->checkout = apply_filters( 'FHEE__EED_Single_Page_Checkout___initialize__checkout', $this->checkout ); |
|
370 | + $this->checkout = apply_filters('FHEE__EED_Single_Page_Checkout___initialize__checkout', $this->checkout); |
|
371 | 371 | // get the $_GET |
372 | 372 | $this->_get_request_vars(); |
373 | 373 | // filter continue_reg |
374 | - $this->checkout->continue_reg = apply_filters( 'FHEE__EED_Single_Page_Checkout__init___continue_reg', TRUE, $this->checkout ); |
|
374 | + $this->checkout->continue_reg = apply_filters('FHEE__EED_Single_Page_Checkout__init___continue_reg', TRUE, $this->checkout); |
|
375 | 375 | // load the reg steps array |
376 | - if ( ! $this->_load_and_instantiate_reg_steps() ) { |
|
376 | + if ( ! $this->_load_and_instantiate_reg_steps()) { |
|
377 | 377 | EED_Single_Page_Checkout::$_initialized = true; |
378 | 378 | return; |
379 | 379 | } |
380 | 380 | // set the current step |
381 | - $this->checkout->set_current_step( $this->checkout->step ); |
|
381 | + $this->checkout->set_current_step($this->checkout->step); |
|
382 | 382 | // and the next step |
383 | 383 | $this->checkout->set_next_step(); |
384 | 384 | // was there already a valid transaction in the checkout from the session ? |
385 | - if ( ! $this->checkout->transaction instanceof EE_Transaction ) { |
|
385 | + if ( ! $this->checkout->transaction instanceof EE_Transaction) { |
|
386 | 386 | // get transaction from db or session |
387 | 387 | $this->checkout->transaction = $this->checkout->reg_url_link && ! is_admin() |
388 | 388 | ? $this->_get_transaction_and_cart_for_previous_visit() |
389 | 389 | : $this->_get_cart_for_current_session_and_setup_new_transaction(); |
390 | - if ( ! $this->checkout->transaction instanceof EE_Transaction ) { |
|
390 | + if ( ! $this->checkout->transaction instanceof EE_Transaction) { |
|
391 | 391 | EE_Error::add_error( |
392 | - __( 'Your Registration and Transaction information could not be retrieved from the db.', 'event_espresso' ), |
|
392 | + __('Your Registration and Transaction information could not be retrieved from the db.', 'event_espresso'), |
|
393 | 393 | __FILE__, __FUNCTION__, __LINE__ |
394 | 394 | ); |
395 | 395 | // add some style and make it dance |
@@ -399,10 +399,10 @@ discard block |
||
399 | 399 | return; |
400 | 400 | } |
401 | 401 | // and the registrations for the transaction |
402 | - $this->_get_registrations( $this->checkout->transaction ); |
|
402 | + $this->_get_registrations($this->checkout->transaction); |
|
403 | 403 | } |
404 | 404 | // verify that everything has been setup correctly |
405 | - if ( ! $this->_final_verifications() ) { |
|
405 | + if ( ! $this->_final_verifications()) { |
|
406 | 406 | EED_Single_Page_Checkout::$_initialized = true; |
407 | 407 | return; |
408 | 408 | } |
@@ -427,9 +427,9 @@ discard block |
||
427 | 427 | // set no cache headers and constants |
428 | 428 | EE_System::do_not_cache(); |
429 | 429 | // add anchor |
430 | - add_action( 'loop_start', array( $this, 'set_checkout_anchor' ), 1 ); |
|
430 | + add_action('loop_start', array($this, 'set_checkout_anchor'), 1); |
|
431 | 431 | // remove transaction lock |
432 | - add_action( 'shutdown', array( $this, 'unlock_transaction' ), 1 ); |
|
432 | + add_action('shutdown', array($this, 'unlock_transaction'), 1); |
|
433 | 433 | } |
434 | 434 | |
435 | 435 | |
@@ -446,20 +446,20 @@ discard block |
||
446 | 446 | // look in session for existing checkout |
447 | 447 | $checkout = EE_Registry::instance()->SSN->checkout(); |
448 | 448 | // verify |
449 | - if ( ! $checkout instanceof EE_Checkout ) { |
|
449 | + if ( ! $checkout instanceof EE_Checkout) { |
|
450 | 450 | // instantiate EE_Checkout object for handling the properties of the current checkout process |
451 | - $checkout = EE_Registry::instance()->load_file( SPCO_INC_PATH, 'EE_Checkout', 'class', array(), FALSE ); |
|
451 | + $checkout = EE_Registry::instance()->load_file(SPCO_INC_PATH, 'EE_Checkout', 'class', array(), FALSE); |
|
452 | 452 | // verify again |
453 | - if ( ! $checkout instanceof EE_Checkout ) { |
|
454 | - throw new EE_Error( __( 'The EE_Checkout class could not be loaded.', 'event_espresso' ) ); |
|
453 | + if ( ! $checkout instanceof EE_Checkout) { |
|
454 | + throw new EE_Error(__('The EE_Checkout class could not be loaded.', 'event_espresso')); |
|
455 | 455 | } |
456 | 456 | } else { |
457 | - if ( $checkout->current_step->is_final_step() && $checkout->exit_spco() === true ) { |
|
458 | - wp_safe_redirect( $checkout->redirect_url ); |
|
457 | + if ($checkout->current_step->is_final_step() && $checkout->exit_spco() === true) { |
|
458 | + wp_safe_redirect($checkout->redirect_url); |
|
459 | 459 | exit(); |
460 | 460 | } |
461 | 461 | } |
462 | - $checkout = apply_filters( 'FHEE__EED_Single_Page_Checkout___initialize_checkout__checkout', $checkout ); |
|
462 | + $checkout = apply_filters('FHEE__EED_Single_Page_Checkout___initialize_checkout__checkout', $checkout); |
|
463 | 463 | // reset anything that needs a clean slate for each request |
464 | 464 | $checkout->reset_for_current_request(); |
465 | 465 | return $checkout; |
@@ -477,24 +477,24 @@ discard block |
||
477 | 477 | // load classes |
478 | 478 | EED_Single_Page_Checkout::load_request_handler(); |
479 | 479 | //make sure this request is marked as belonging to EE |
480 | - EE_Registry::instance()->REQ->set_espresso_page( TRUE ); |
|
480 | + EE_Registry::instance()->REQ->set_espresso_page(TRUE); |
|
481 | 481 | // which step is being requested ? |
482 | - $this->checkout->step = EE_Registry::instance()->REQ->get( 'step', $this->_get_first_step() ); |
|
482 | + $this->checkout->step = EE_Registry::instance()->REQ->get('step', $this->_get_first_step()); |
|
483 | 483 | // which step is being edited ? |
484 | - $this->checkout->edit_step = EE_Registry::instance()->REQ->get( 'edit_step', '' ); |
|
484 | + $this->checkout->edit_step = EE_Registry::instance()->REQ->get('edit_step', ''); |
|
485 | 485 | // and what we're doing on the current step |
486 | - $this->checkout->action = EE_Registry::instance()->REQ->get( 'action', 'display_spco_reg_step' ); |
|
486 | + $this->checkout->action = EE_Registry::instance()->REQ->get('action', 'display_spco_reg_step'); |
|
487 | 487 | // returning to edit ? |
488 | - $this->checkout->reg_url_link = EE_Registry::instance()->REQ->get( 'e_reg_url_link', '' ); |
|
488 | + $this->checkout->reg_url_link = EE_Registry::instance()->REQ->get('e_reg_url_link', ''); |
|
489 | 489 | // or some other kind of revisit ? |
490 | - $this->checkout->revisit = EE_Registry::instance()->REQ->get( 'revisit', FALSE ); |
|
490 | + $this->checkout->revisit = EE_Registry::instance()->REQ->get('revisit', FALSE); |
|
491 | 491 | // and whether or not to generate a reg form for this request |
492 | - $this->checkout->generate_reg_form = EE_Registry::instance()->REQ->get( 'generate_reg_form', TRUE ); // TRUE FALSE |
|
492 | + $this->checkout->generate_reg_form = EE_Registry::instance()->REQ->get('generate_reg_form', TRUE); // TRUE FALSE |
|
493 | 493 | // and whether or not to process a reg form submission for this request |
494 | - $this->checkout->process_form_submission = EE_Registry::instance()->REQ->get( 'process_form_submission', FALSE ); // TRUE FALSE |
|
494 | + $this->checkout->process_form_submission = EE_Registry::instance()->REQ->get('process_form_submission', FALSE); // TRUE FALSE |
|
495 | 495 | $this->checkout->process_form_submission = $this->checkout->action !== 'display_spco_reg_step' |
496 | 496 | ? $this->checkout->process_form_submission |
497 | - : FALSE; // TRUE FALSE |
|
497 | + : FALSE; // TRUE FALSE |
|
498 | 498 | //$this->_display_request_vars(); |
499 | 499 | } |
500 | 500 | |
@@ -507,17 +507,17 @@ discard block |
||
507 | 507 | * @return void |
508 | 508 | */ |
509 | 509 | protected function _display_request_vars() { |
510 | - if ( ! WP_DEBUG ) { |
|
510 | + if ( ! WP_DEBUG) { |
|
511 | 511 | return; |
512 | 512 | } |
513 | - EEH_Debug_Tools::printr( $_REQUEST, '$_REQUEST', __FILE__, __LINE__ ); |
|
514 | - EEH_Debug_Tools::printr( $this->checkout->step, '$this->checkout->step', __FILE__, __LINE__ ); |
|
515 | - EEH_Debug_Tools::printr( $this->checkout->edit_step, '$this->checkout->edit_step', __FILE__, __LINE__ ); |
|
516 | - EEH_Debug_Tools::printr( $this->checkout->action, '$this->checkout->action', __FILE__, __LINE__ ); |
|
517 | - EEH_Debug_Tools::printr( $this->checkout->reg_url_link, '$this->checkout->reg_url_link', __FILE__, __LINE__ ); |
|
518 | - EEH_Debug_Tools::printr( $this->checkout->revisit, '$this->checkout->revisit', __FILE__, __LINE__ ); |
|
519 | - EEH_Debug_Tools::printr( $this->checkout->generate_reg_form, '$this->checkout->generate_reg_form', __FILE__, __LINE__ ); |
|
520 | - EEH_Debug_Tools::printr( $this->checkout->process_form_submission, '$this->checkout->process_form_submission', __FILE__, __LINE__ ); |
|
513 | + EEH_Debug_Tools::printr($_REQUEST, '$_REQUEST', __FILE__, __LINE__); |
|
514 | + EEH_Debug_Tools::printr($this->checkout->step, '$this->checkout->step', __FILE__, __LINE__); |
|
515 | + EEH_Debug_Tools::printr($this->checkout->edit_step, '$this->checkout->edit_step', __FILE__, __LINE__); |
|
516 | + EEH_Debug_Tools::printr($this->checkout->action, '$this->checkout->action', __FILE__, __LINE__); |
|
517 | + EEH_Debug_Tools::printr($this->checkout->reg_url_link, '$this->checkout->reg_url_link', __FILE__, __LINE__); |
|
518 | + EEH_Debug_Tools::printr($this->checkout->revisit, '$this->checkout->revisit', __FILE__, __LINE__); |
|
519 | + EEH_Debug_Tools::printr($this->checkout->generate_reg_form, '$this->checkout->generate_reg_form', __FILE__, __LINE__); |
|
520 | + EEH_Debug_Tools::printr($this->checkout->process_form_submission, '$this->checkout->process_form_submission', __FILE__, __LINE__); |
|
521 | 521 | } |
522 | 522 | |
523 | 523 | |
@@ -531,8 +531,8 @@ discard block |
||
531 | 531 | * @return array |
532 | 532 | */ |
533 | 533 | private function _get_first_step() { |
534 | - $first_step = reset( EED_Single_Page_Checkout::$_reg_steps_array ); |
|
535 | - return isset( $first_step['slug'] ) ? $first_step['slug'] : 'attendee_information'; |
|
534 | + $first_step = reset(EED_Single_Page_Checkout::$_reg_steps_array); |
|
535 | + return isset($first_step['slug']) ? $first_step['slug'] : 'attendee_information'; |
|
536 | 536 | } |
537 | 537 | |
538 | 538 | |
@@ -548,27 +548,27 @@ discard block |
||
548 | 548 | private function _load_and_instantiate_reg_steps() { |
549 | 549 | // have reg_steps already been instantiated ? |
550 | 550 | if ( |
551 | - empty( $this->checkout->reg_steps ) || |
|
552 | - apply_filters( 'FHEE__Single_Page_Checkout__load_reg_steps__reload_reg_steps', false, $this->checkout ) |
|
551 | + empty($this->checkout->reg_steps) || |
|
552 | + apply_filters('FHEE__Single_Page_Checkout__load_reg_steps__reload_reg_steps', false, $this->checkout) |
|
553 | 553 | ) { |
554 | 554 | // if not, then loop through raw reg steps array |
555 | - foreach ( EED_Single_Page_Checkout::$_reg_steps_array as $order => $reg_step ) { |
|
556 | - if ( ! $this->_load_and_instantiate_reg_step( $reg_step, $order )) { |
|
555 | + foreach (EED_Single_Page_Checkout::$_reg_steps_array as $order => $reg_step) { |
|
556 | + if ( ! $this->_load_and_instantiate_reg_step($reg_step, $order)) { |
|
557 | 557 | return false; |
558 | 558 | } |
559 | 559 | } |
560 | 560 | EE_Registry::instance()->CFG->registration->skip_reg_confirmation = TRUE; |
561 | 561 | EE_Registry::instance()->CFG->registration->reg_confirmation_last = TRUE; |
562 | 562 | // skip the registration_confirmation page ? |
563 | - if ( EE_Registry::instance()->CFG->registration->skip_reg_confirmation ) { |
|
563 | + if (EE_Registry::instance()->CFG->registration->skip_reg_confirmation) { |
|
564 | 564 | // just remove it from the reg steps array |
565 | - $this->checkout->remove_reg_step( 'registration_confirmation', false ); |
|
565 | + $this->checkout->remove_reg_step('registration_confirmation', false); |
|
566 | 566 | } else if ( |
567 | 567 | EE_Registry::instance()->CFG->registration->reg_confirmation_last |
568 | - && isset( $this->checkout->reg_steps['registration_confirmation'] ) |
|
568 | + && isset($this->checkout->reg_steps['registration_confirmation']) |
|
569 | 569 | ) { |
570 | 570 | // set the order to something big like 100 |
571 | - $this->checkout->set_reg_step_order( 'registration_confirmation', 100 ); |
|
571 | + $this->checkout->set_reg_step_order('registration_confirmation', 100); |
|
572 | 572 | } |
573 | 573 | // filter the array for good luck |
574 | 574 | $this->checkout->reg_steps = apply_filters( |
@@ -578,13 +578,13 @@ discard block |
||
578 | 578 | // finally re-sort based on the reg step class order properties |
579 | 579 | $this->checkout->sort_reg_steps(); |
580 | 580 | } else { |
581 | - foreach ( $this->checkout->reg_steps as $reg_step ) { |
|
581 | + foreach ($this->checkout->reg_steps as $reg_step) { |
|
582 | 582 | // set all current step stati to FALSE |
583 | - $reg_step->set_is_current_step( FALSE ); |
|
583 | + $reg_step->set_is_current_step(FALSE); |
|
584 | 584 | } |
585 | 585 | } |
586 | - if ( empty( $this->checkout->reg_steps )) { |
|
587 | - EE_Error::add_error( __( 'No Reg Steps were loaded..', 'event_espresso' ), __FILE__, __FUNCTION__, __LINE__); |
|
586 | + if (empty($this->checkout->reg_steps)) { |
|
587 | + EE_Error::add_error(__('No Reg Steps were loaded..', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__); |
|
588 | 588 | return false; |
589 | 589 | } |
590 | 590 | // make reg step details available to JS |
@@ -602,10 +602,10 @@ discard block |
||
602 | 602 | * @param int $order |
603 | 603 | * @return bool |
604 | 604 | */ |
605 | - private function _load_and_instantiate_reg_step( $reg_step = array(), $order = 0 ) { |
|
605 | + private function _load_and_instantiate_reg_step($reg_step = array(), $order = 0) { |
|
606 | 606 | |
607 | 607 | // we need a file_path, class_name, and slug to add a reg step |
608 | - if ( isset( $reg_step['file_path'], $reg_step['class_name'], $reg_step['slug'] )) { |
|
608 | + if (isset($reg_step['file_path'], $reg_step['class_name'], $reg_step['slug'])) { |
|
609 | 609 | // if editing a specific step, but this is NOT that step... (and it's not the 'finalize_registration' step) |
610 | 610 | if ( |
611 | 611 | $this->checkout->reg_url_link |
@@ -623,26 +623,26 @@ discard block |
||
623 | 623 | FALSE |
624 | 624 | ); |
625 | 625 | // did we gets the goods ? |
626 | - if ( $reg_step_obj instanceof EE_SPCO_Reg_Step ) { |
|
626 | + if ($reg_step_obj instanceof EE_SPCO_Reg_Step) { |
|
627 | 627 | // set reg step order based on config |
628 | - $reg_step_obj->set_order( $order ); |
|
628 | + $reg_step_obj->set_order($order); |
|
629 | 629 | // add instantiated reg step object to the master reg steps array |
630 | - $this->checkout->add_reg_step( $reg_step_obj ); |
|
630 | + $this->checkout->add_reg_step($reg_step_obj); |
|
631 | 631 | } else { |
632 | 632 | EE_Error::add_error( |
633 | - __( 'The current step could not be set.', 'event_espresso' ), |
|
633 | + __('The current step could not be set.', 'event_espresso'), |
|
634 | 634 | __FILE__, __FUNCTION__, __LINE__ |
635 | 635 | ); |
636 | 636 | return false; |
637 | 637 | } |
638 | 638 | } else { |
639 | - if ( WP_DEBUG ) { |
|
639 | + if (WP_DEBUG) { |
|
640 | 640 | EE_Error::add_error( |
641 | 641 | sprintf( |
642 | - __( 'A registration step could not be loaded. One or more of the following data points is invalid:%4$s%5$sFile Path: %1$s%6$s%5$sClass Name: %2$s%6$s%5$sSlug: %3$s%6$s%7$s', 'event_espresso' ), |
|
643 | - isset( $reg_step['file_path'] ) ? $reg_step['file_path'] : '', |
|
644 | - isset( $reg_step['class_name'] ) ? $reg_step['class_name'] : '', |
|
645 | - isset( $reg_step['slug'] ) ? $reg_step['slug'] : '', |
|
642 | + __('A registration step could not be loaded. One or more of the following data points is invalid:%4$s%5$sFile Path: %1$s%6$s%5$sClass Name: %2$s%6$s%5$sSlug: %3$s%6$s%7$s', 'event_espresso'), |
|
643 | + isset($reg_step['file_path']) ? $reg_step['file_path'] : '', |
|
644 | + isset($reg_step['class_name']) ? $reg_step['class_name'] : '', |
|
645 | + isset($reg_step['slug']) ? $reg_step['slug'] : '', |
|
646 | 646 | '<ul>', |
647 | 647 | '<li>', |
648 | 648 | '</li>', |
@@ -666,16 +666,16 @@ discard block |
||
666 | 666 | */ |
667 | 667 | private function _get_transaction_and_cart_for_previous_visit() { |
668 | 668 | /** @var $TXN_model EEM_Transaction */ |
669 | - $TXN_model = EE_Registry::instance()->load_model( 'Transaction' ); |
|
669 | + $TXN_model = EE_Registry::instance()->load_model('Transaction'); |
|
670 | 670 | // because the reg_url_link is present in the request, this is a return visit to SPCO, so we'll get the transaction data from the db |
671 | - $transaction = $TXN_model->get_transaction_from_reg_url_link( $this->checkout->reg_url_link ); |
|
671 | + $transaction = $TXN_model->get_transaction_from_reg_url_link($this->checkout->reg_url_link); |
|
672 | 672 | // verify transaction |
673 | - if ( $transaction instanceof EE_Transaction ) { |
|
673 | + if ($transaction instanceof EE_Transaction) { |
|
674 | 674 | // and get the cart that was used for that transaction |
675 | - $this->checkout->cart = $this->_get_cart_for_transaction( $transaction ); |
|
675 | + $this->checkout->cart = $this->_get_cart_for_transaction($transaction); |
|
676 | 676 | return $transaction; |
677 | 677 | } else { |
678 | - EE_Error::add_error( __( 'Your Registration and Transaction information could not be retrieved from the db.', 'event_espresso' ), __FILE__, __FUNCTION__, __LINE__); |
|
678 | + EE_Error::add_error(__('Your Registration and Transaction information could not be retrieved from the db.', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__); |
|
679 | 679 | return NULL; |
680 | 680 | } |
681 | 681 | } |
@@ -689,11 +689,11 @@ discard block |
||
689 | 689 | * @param EE_Transaction $transaction |
690 | 690 | * @return EE_Cart |
691 | 691 | */ |
692 | - private function _get_cart_for_transaction( $transaction ) { |
|
693 | - $cart = $transaction instanceof EE_Transaction ? EE_Cart::get_cart_from_txn( $transaction ) : NULL; |
|
692 | + private function _get_cart_for_transaction($transaction) { |
|
693 | + $cart = $transaction instanceof EE_Transaction ? EE_Cart::get_cart_from_txn($transaction) : NULL; |
|
694 | 694 | // verify cart |
695 | - if ( ! $cart instanceof EE_Cart ) { |
|
696 | - $cart = EE_Registry::instance()->load_core( 'Cart' ); |
|
695 | + if ( ! $cart instanceof EE_Cart) { |
|
696 | + $cart = EE_Registry::instance()->load_core('Cart'); |
|
697 | 697 | } |
698 | 698 | return $cart; |
699 | 699 | } |
@@ -708,8 +708,8 @@ discard block |
||
708 | 708 | * @param EE_Transaction $transaction |
709 | 709 | * @return EE_Cart |
710 | 710 | */ |
711 | - public function get_cart_for_transaction( EE_Transaction $transaction ) { |
|
712 | - return EE_Cart::get_cart_from_txn( $transaction ); |
|
711 | + public function get_cart_for_transaction(EE_Transaction $transaction) { |
|
712 | + return EE_Cart::get_cart_from_txn($transaction); |
|
713 | 713 | } |
714 | 714 | |
715 | 715 | |
@@ -724,17 +724,17 @@ discard block |
||
724 | 724 | private function _get_cart_for_current_session_and_setup_new_transaction() { |
725 | 725 | // if there's no transaction, then this is the FIRST visit to SPCO |
726 | 726 | // so load up the cart ( passing nothing for the TXN because it doesn't exist yet ) |
727 | - $this->checkout->cart = $this->_get_cart_for_transaction( NULL ); |
|
727 | + $this->checkout->cart = $this->_get_cart_for_transaction(NULL); |
|
728 | 728 | // and then create a new transaction |
729 | 729 | $transaction = $this->_initialize_transaction(); |
730 | 730 | // verify transaction |
731 | - if ( $transaction instanceof EE_Transaction ) { |
|
731 | + if ($transaction instanceof EE_Transaction) { |
|
732 | 732 | // save it so that we have an ID for other objects to use |
733 | 733 | $transaction->save(); |
734 | 734 | // and save TXN data to the cart |
735 | - $this->checkout->cart->get_grand_total()->save_this_and_descendants_to_txn( $transaction->ID() ); |
|
735 | + $this->checkout->cart->get_grand_total()->save_this_and_descendants_to_txn($transaction->ID()); |
|
736 | 736 | } else { |
737 | - EE_Error::add_error( __( 'A Valid Transaction could not be initialized.', 'event_espresso' ), __FILE__, __FUNCTION__, __LINE__ ); |
|
737 | + EE_Error::add_error(__('A Valid Transaction could not be initialized.', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__); |
|
738 | 738 | } |
739 | 739 | return $transaction; |
740 | 740 | } |
@@ -754,15 +754,15 @@ discard block |
||
754 | 754 | // grab the cart grand total |
755 | 755 | $cart_total = $this->checkout->cart->get_cart_grand_total(); |
756 | 756 | // create new TXN |
757 | - return EE_Transaction::new_instance( array( |
|
757 | + return EE_Transaction::new_instance(array( |
|
758 | 758 | 'TXN_timestamp' => time(), |
759 | 759 | 'TXN_reg_steps' => $this->checkout->initialize_txn_reg_steps_array(), |
760 | 760 | 'TXN_total' => $cart_total > 0 ? $cart_total : 0, |
761 | 761 | 'TXN_paid' => 0, |
762 | 762 | 'STS_ID' => EEM_Transaction::failed_status_code, |
763 | 763 | )); |
764 | - } catch( Exception $e ) { |
|
765 | - EE_Error::add_error( $e->getMessage(), __FILE__, __FUNCTION__, __LINE__); |
|
764 | + } catch (Exception $e) { |
|
765 | + EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__); |
|
766 | 766 | } |
767 | 767 | return NULL; |
768 | 768 | } |
@@ -776,34 +776,34 @@ discard block |
||
776 | 776 | * @param EE_Transaction $transaction |
777 | 777 | * @return EE_Cart |
778 | 778 | */ |
779 | - private function _get_registrations( EE_Transaction $transaction ) { |
|
779 | + private function _get_registrations(EE_Transaction $transaction) { |
|
780 | 780 | // first step: grab the registrants { : o |
781 | - $registrations = $transaction->registrations( $this->checkout->reg_cache_where_params, true ); |
|
781 | + $registrations = $transaction->registrations($this->checkout->reg_cache_where_params, true); |
|
782 | 782 | // verify registrations have been set |
783 | - if ( empty( $registrations )) { |
|
783 | + if (empty($registrations)) { |
|
784 | 784 | // if no cached registrations, then check the db |
785 | - $registrations = $transaction->registrations( $this->checkout->reg_cache_where_params, false ); |
|
785 | + $registrations = $transaction->registrations($this->checkout->reg_cache_where_params, false); |
|
786 | 786 | // still nothing ? well as long as this isn't a revisit |
787 | - if ( empty( $registrations ) && ! $this->checkout->revisit ) { |
|
787 | + if (empty($registrations) && ! $this->checkout->revisit) { |
|
788 | 788 | // generate new registrations from scratch |
789 | - $registrations = $this->_initialize_registrations( $transaction ); |
|
789 | + $registrations = $this->_initialize_registrations($transaction); |
|
790 | 790 | } |
791 | 791 | } |
792 | 792 | // sort by their original registration order |
793 | - usort( $registrations, array( 'EED_Single_Page_Checkout', 'sort_registrations_by_REG_count' )); |
|
793 | + usort($registrations, array('EED_Single_Page_Checkout', 'sort_registrations_by_REG_count')); |
|
794 | 794 | // then loop thru the array |
795 | - foreach ( $registrations as $registration ) { |
|
795 | + foreach ($registrations as $registration) { |
|
796 | 796 | // verify each registration |
797 | - if ( $registration instanceof EE_Registration ) { |
|
797 | + if ($registration instanceof EE_Registration) { |
|
798 | 798 | // we display all attendee info for the primary registrant |
799 | - if ( $this->checkout->reg_url_link == $registration->reg_url_link() && $registration->is_primary_registrant() ) { |
|
799 | + if ($this->checkout->reg_url_link == $registration->reg_url_link() && $registration->is_primary_registrant()) { |
|
800 | 800 | $this->checkout->primary_revisit = TRUE; |
801 | 801 | break; |
802 | - } else if ( $this->checkout->revisit && $this->checkout->reg_url_link != $registration->reg_url_link() ) { |
|
802 | + } else if ($this->checkout->revisit && $this->checkout->reg_url_link != $registration->reg_url_link()) { |
|
803 | 803 | // but hide info if it doesn't belong to you |
804 | - $transaction->clear_cache( 'Registration', $registration->ID() ); |
|
804 | + $transaction->clear_cache('Registration', $registration->ID()); |
|
805 | 805 | } |
806 | - $this->checkout->set_reg_status_updated( $registration->ID(), false ); |
|
806 | + $this->checkout->set_reg_status_updated($registration->ID(), false); |
|
807 | 807 | } |
808 | 808 | } |
809 | 809 | } |
@@ -817,17 +817,17 @@ discard block |
||
817 | 817 | * @param EE_Transaction $transaction |
818 | 818 | * @return array |
819 | 819 | */ |
820 | - private function _initialize_registrations( EE_Transaction $transaction ) { |
|
820 | + private function _initialize_registrations(EE_Transaction $transaction) { |
|
821 | 821 | $att_nmbr = 0; |
822 | 822 | $registrations = array(); |
823 | - if ( $transaction instanceof EE_Transaction ) { |
|
823 | + if ($transaction instanceof EE_Transaction) { |
|
824 | 824 | /** @type EE_Registration_Processor $registration_processor */ |
825 | - $registration_processor = EE_Registry::instance()->load_class( 'Registration_Processor' ); |
|
825 | + $registration_processor = EE_Registry::instance()->load_class('Registration_Processor'); |
|
826 | 826 | $this->checkout->total_ticket_count = $this->checkout->cart->all_ticket_quantity_count(); |
827 | 827 | // now let's add the cart items to the $transaction |
828 | - foreach ( $this->checkout->cart->get_tickets() as $line_item ) { |
|
828 | + foreach ($this->checkout->cart->get_tickets() as $line_item) { |
|
829 | 829 | //do the following for each ticket of this type they selected |
830 | - for ( $x = 1; $x <= $line_item->quantity(); $x++ ) { |
|
830 | + for ($x = 1; $x <= $line_item->quantity(); $x++) { |
|
831 | 831 | $att_nmbr++; |
832 | 832 | $registration = $registration_processor->generate_ONE_registration_from_line_item( |
833 | 833 | $line_item, |
@@ -835,12 +835,12 @@ discard block |
||
835 | 835 | $att_nmbr, |
836 | 836 | $this->checkout->total_ticket_count |
837 | 837 | ); |
838 | - if ( $registration instanceof EE_Registration ) { |
|
839 | - $registrations[ $registration->ID() ] = $registration; |
|
838 | + if ($registration instanceof EE_Registration) { |
|
839 | + $registrations[$registration->ID()] = $registration; |
|
840 | 840 | } |
841 | 841 | } |
842 | 842 | } |
843 | - $registration_processor->fix_reg_final_price_rounding_issue( $transaction ); |
|
843 | + $registration_processor->fix_reg_final_price_rounding_issue($transaction); |
|
844 | 844 | } |
845 | 845 | return $registrations; |
846 | 846 | } |
@@ -855,12 +855,12 @@ discard block |
||
855 | 855 | * @param EE_Registration $reg_B |
856 | 856 | * @return array() |
857 | 857 | */ |
858 | - public static function sort_registrations_by_REG_count( EE_Registration $reg_A, EE_Registration $reg_B ) { |
|
858 | + public static function sort_registrations_by_REG_count(EE_Registration $reg_A, EE_Registration $reg_B) { |
|
859 | 859 | // this shouldn't ever happen within the same TXN, but oh well |
860 | - if ( $reg_A->count() == $reg_B->count() ) { |
|
860 | + if ($reg_A->count() == $reg_B->count()) { |
|
861 | 861 | return 0; |
862 | 862 | } |
863 | - return ( $reg_A->count() > $reg_B->count() ) ? 1 : -1; |
|
863 | + return ($reg_A->count() > $reg_B->count()) ? 1 : -1; |
|
864 | 864 | } |
865 | 865 | |
866 | 866 | |
@@ -875,35 +875,35 @@ discard block |
||
875 | 875 | */ |
876 | 876 | private function _final_verifications() { |
877 | 877 | // filter checkout |
878 | - $this->checkout = apply_filters( 'FHEE__EED_Single_Page_Checkout___final_verifications__checkout', $this->checkout ); |
|
878 | + $this->checkout = apply_filters('FHEE__EED_Single_Page_Checkout___final_verifications__checkout', $this->checkout); |
|
879 | 879 | //verify that current step is still set correctly |
880 | - if ( ! $this->checkout->current_step instanceof EE_SPCO_Reg_Step ) { |
|
881 | - EE_Error::add_error( __( 'We\'re sorry but the registration process can not proceed because one or more registration steps were not setup correctly. Please refresh the page and try again or contact support.', 'event_espresso' ), __FILE__, __FUNCTION__, __LINE__ ); |
|
880 | + if ( ! $this->checkout->current_step instanceof EE_SPCO_Reg_Step) { |
|
881 | + EE_Error::add_error(__('We\'re sorry but the registration process can not proceed because one or more registration steps were not setup correctly. Please refresh the page and try again or contact support.', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__); |
|
882 | 882 | return false; |
883 | 883 | } |
884 | 884 | // if returning to SPCO, then verify that primary registrant is set |
885 | - if ( ! empty( $this->checkout->reg_url_link )) { |
|
885 | + if ( ! empty($this->checkout->reg_url_link)) { |
|
886 | 886 | $valid_registrant = $this->checkout->transaction->primary_registration(); |
887 | - if ( ! $valid_registrant instanceof EE_Registration ) { |
|
888 | - EE_Error::add_error( __( 'We\'re sorry but there appears to be an error with the "reg_url_link" or the primary registrant for this transaction. Please refresh the page and try again or contact support.', 'event_espresso' ), __FILE__, __FUNCTION__, __LINE__ ); |
|
887 | + if ( ! $valid_registrant instanceof EE_Registration) { |
|
888 | + EE_Error::add_error(__('We\'re sorry but there appears to be an error with the "reg_url_link" or the primary registrant for this transaction. Please refresh the page and try again or contact support.', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__); |
|
889 | 889 | return false; |
890 | 890 | } |
891 | 891 | $valid_registrant = null; |
892 | - foreach ( $this->checkout->transaction->registrations( $this->checkout->reg_cache_where_params ) as $registration ) { |
|
893 | - if ( $registration instanceof EE_Registration ) { |
|
894 | - if ( $registration->reg_url_link() == $this->checkout->reg_url_link ) { |
|
892 | + foreach ($this->checkout->transaction->registrations($this->checkout->reg_cache_where_params) as $registration) { |
|
893 | + if ($registration instanceof EE_Registration) { |
|
894 | + if ($registration->reg_url_link() == $this->checkout->reg_url_link) { |
|
895 | 895 | $valid_registrant = $registration; |
896 | 896 | } |
897 | 897 | } |
898 | 898 | } |
899 | - if ( ! $valid_registrant instanceof EE_Registration ) { |
|
900 | - EE_Error::add_error( __( 'We\'re sorry but there appears to be an error with the "reg_url_link" or the transaction itself. Please refresh the page and try again or contact support.', 'event_espresso' ), __FILE__, __FUNCTION__, __LINE__ ); |
|
899 | + if ( ! $valid_registrant instanceof EE_Registration) { |
|
900 | + EE_Error::add_error(__('We\'re sorry but there appears to be an error with the "reg_url_link" or the transaction itself. Please refresh the page and try again or contact support.', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__); |
|
901 | 901 | return false; |
902 | 902 | } |
903 | 903 | } |
904 | 904 | // now that things have been kinda sufficiently verified, |
905 | 905 | // let's add the checkout to the session so that's available other systems |
906 | - EE_Registry::instance()->SSN->set_checkout( $this->checkout ); |
|
906 | + EE_Registry::instance()->SSN->set_checkout($this->checkout); |
|
907 | 907 | return true; |
908 | 908 | } |
909 | 909 | |
@@ -919,28 +919,28 @@ discard block |
||
919 | 919 | * @access private |
920 | 920 | * @param bool $reinitializing |
921 | 921 | */ |
922 | - private function _initialize_reg_steps( $reinitializing = false ) { |
|
923 | - $this->checkout->set_reg_step_initiated( $this->checkout->current_step ); |
|
922 | + private function _initialize_reg_steps($reinitializing = false) { |
|
923 | + $this->checkout->set_reg_step_initiated($this->checkout->current_step); |
|
924 | 924 | // loop thru all steps to call their individual "initialize" methods and set i18n strings for JS |
925 | - foreach ( $this->checkout->reg_steps as $reg_step ) { |
|
926 | - if ( ! $reg_step->initialize_reg_step() ) { |
|
925 | + foreach ($this->checkout->reg_steps as $reg_step) { |
|
926 | + if ( ! $reg_step->initialize_reg_step()) { |
|
927 | 927 | // if not initialized then maybe this step is being removed... |
928 | - if ( $reg_step->is_current_step() && ! $reinitializing ) { |
|
928 | + if ($reg_step->is_current_step() && ! $reinitializing) { |
|
929 | 929 | // if it was the current step, then we need to start over here |
930 | - $this->_initialize_reg_steps( true ); |
|
930 | + $this->_initialize_reg_steps(true); |
|
931 | 931 | return; |
932 | 932 | } |
933 | 933 | continue; |
934 | 934 | } |
935 | 935 | // i18n |
936 | 936 | $reg_step->translate_js_strings(); |
937 | - if ( $reg_step->is_current_step() ) { |
|
937 | + if ($reg_step->is_current_step()) { |
|
938 | 938 | // the text that appears on the reg step form submit button |
939 | 939 | $reg_step->set_submit_button_text(); |
940 | 940 | } |
941 | 941 | } |
942 | 942 | // dynamically creates hook point like: AHEE__Single_Page_Checkout___initialize_reg_step__attendee_information |
943 | - do_action( "AHEE__Single_Page_Checkout___initialize_reg_step__{$this->checkout->current_step->slug()}", $this->checkout->current_step ); |
|
943 | + do_action("AHEE__Single_Page_Checkout___initialize_reg_step__{$this->checkout->current_step->slug()}", $this->checkout->current_step); |
|
944 | 944 | } |
945 | 945 | |
946 | 946 | |
@@ -953,39 +953,39 @@ discard block |
||
953 | 953 | */ |
954 | 954 | private function _check_form_submission() { |
955 | 955 | //does this request require the reg form to be generated ? |
956 | - if ( $this->checkout->generate_reg_form ) { |
|
956 | + if ($this->checkout->generate_reg_form) { |
|
957 | 957 | // ever heard that song by Blue Rodeo ? |
958 | 958 | try { |
959 | 959 | $this->checkout->current_step->reg_form = $this->checkout->current_step->generate_reg_form(); |
960 | 960 | // if not displaying a form, then check for form submission |
961 | - if ( $this->checkout->process_form_submission && $this->checkout->current_step->reg_form->was_submitted() ) { |
|
961 | + if ($this->checkout->process_form_submission && $this->checkout->current_step->reg_form->was_submitted()) { |
|
962 | 962 | // clear out any old data in case this step is being run again |
963 | - $this->checkout->current_step->set_valid_data( array() ); |
|
963 | + $this->checkout->current_step->set_valid_data(array()); |
|
964 | 964 | // capture submitted form data |
965 | 965 | $this->checkout->current_step->reg_form->receive_form_submission( |
966 | - apply_filters( 'FHEE__Single_Page_Checkout___check_form_submission__request_params', EE_Registry::instance()->REQ->params(), $this->checkout ) |
|
966 | + apply_filters('FHEE__Single_Page_Checkout___check_form_submission__request_params', EE_Registry::instance()->REQ->params(), $this->checkout) |
|
967 | 967 | ); |
968 | 968 | // validate submitted form data |
969 | - if ( ! $this->checkout->current_step->reg_form->is_valid() || ! $this->checkout->continue_reg ) { |
|
969 | + if ( ! $this->checkout->current_step->reg_form->is_valid() || ! $this->checkout->continue_reg) { |
|
970 | 970 | // thou shall not pass !!! |
971 | 971 | $this->checkout->continue_reg = FALSE; |
972 | 972 | // any form validation errors? |
973 | - if ( $this->checkout->current_step->reg_form->submission_error_message() != '' ) { |
|
973 | + if ($this->checkout->current_step->reg_form->submission_error_message() != '') { |
|
974 | 974 | $submission_error_messages = array(); |
975 | 975 | // bad, bad, bad registrant |
976 | - foreach( $this->checkout->current_step->reg_form->get_validation_errors_accumulated() as $validation_error ){ |
|
977 | - if ( $validation_error instanceof EE_Validation_Error ) { |
|
978 | - $submission_error_messages[] = sprintf( __( '%s : %s', 'event_espresso' ), $validation_error->get_form_section()->html_label_text(), $validation_error->getMessage() ); |
|
976 | + foreach ($this->checkout->current_step->reg_form->get_validation_errors_accumulated() as $validation_error) { |
|
977 | + if ($validation_error instanceof EE_Validation_Error) { |
|
978 | + $submission_error_messages[] = sprintf(__('%s : %s', 'event_espresso'), $validation_error->get_form_section()->html_label_text(), $validation_error->getMessage()); |
|
979 | 979 | } |
980 | 980 | } |
981 | - EE_Error::add_error( join( '<br />', $submission_error_messages ), __FILE__, __FUNCTION__, __LINE__ ); |
|
981 | + EE_Error::add_error(join('<br />', $submission_error_messages), __FILE__, __FUNCTION__, __LINE__); |
|
982 | 982 | } |
983 | 983 | // well not really... what will happen is we'll just get redirected back to redo the current step |
984 | 984 | $this->go_to_next_step(); |
985 | 985 | return; |
986 | 986 | } |
987 | 987 | } |
988 | - } catch( EE_Error $e ) { |
|
988 | + } catch (EE_Error $e) { |
|
989 | 989 | $e->get_error(); |
990 | 990 | } |
991 | 991 | } |
@@ -1001,38 +1001,38 @@ discard block |
||
1001 | 1001 | */ |
1002 | 1002 | private function _process_form_action() { |
1003 | 1003 | // what cha wanna do? |
1004 | - switch( $this->checkout->action ) { |
|
1004 | + switch ($this->checkout->action) { |
|
1005 | 1005 | // AJAX next step reg form |
1006 | 1006 | case 'display_spco_reg_step' : |
1007 | 1007 | $this->checkout->redirect = FALSE; |
1008 | - if ( EE_Registry::instance()->REQ->ajax ) { |
|
1009 | - $this->checkout->json_response->set_reg_step_html( $this->checkout->current_step->display_reg_form() ); |
|
1008 | + if (EE_Registry::instance()->REQ->ajax) { |
|
1009 | + $this->checkout->json_response->set_reg_step_html($this->checkout->current_step->display_reg_form()); |
|
1010 | 1010 | } |
1011 | 1011 | break; |
1012 | 1012 | |
1013 | 1013 | default : |
1014 | 1014 | // meh... do one of those other steps first |
1015 | - if ( ! empty( $this->checkout->action ) && is_callable( array( $this->checkout->current_step, $this->checkout->action ))) { |
|
1015 | + if ( ! empty($this->checkout->action) && is_callable(array($this->checkout->current_step, $this->checkout->action))) { |
|
1016 | 1016 | // dynamically creates hook point like: AHEE__Single_Page_Checkout__before_attendee_information__process_reg_step |
1017 | - do_action( "AHEE__Single_Page_Checkout__before_{$this->checkout->current_step->slug()}__{$this->checkout->action}", $this->checkout->current_step ); |
|
1017 | + do_action("AHEE__Single_Page_Checkout__before_{$this->checkout->current_step->slug()}__{$this->checkout->action}", $this->checkout->current_step); |
|
1018 | 1018 | // call action on current step |
1019 | - if ( call_user_func( array( $this->checkout->current_step, $this->checkout->action )) ) { |
|
1019 | + if (call_user_func(array($this->checkout->current_step, $this->checkout->action))) { |
|
1020 | 1020 | // good registrant, you get to proceed |
1021 | - if ( $this->checkout->current_step->success_message() != '' ) { |
|
1022 | - if ( apply_filters( 'FHEE__Single_Page_Checkout___process_form_action__display_success', false ) ) { |
|
1023 | - EE_Error::add_success( $this->checkout->current_step->success_message() . '<br />' . $this->checkout->next_step->_instructions() ); |
|
1021 | + if ($this->checkout->current_step->success_message() != '') { |
|
1022 | + if (apply_filters('FHEE__Single_Page_Checkout___process_form_action__display_success', false)) { |
|
1023 | + EE_Error::add_success($this->checkout->current_step->success_message().'<br />'.$this->checkout->next_step->_instructions()); |
|
1024 | 1024 | } |
1025 | 1025 | } |
1026 | 1026 | // pack it up, pack it in... |
1027 | 1027 | $this->_setup_redirect(); |
1028 | 1028 | } |
1029 | 1029 | // dynamically creates hook point like: AHEE__Single_Page_Checkout__after_payment_options__process_reg_step |
1030 | - do_action( "AHEE__Single_Page_Checkout__after_{$this->checkout->current_step->slug()}__{$this->checkout->action}", $this->checkout->current_step ); |
|
1030 | + do_action("AHEE__Single_Page_Checkout__after_{$this->checkout->current_step->slug()}__{$this->checkout->action}", $this->checkout->current_step); |
|
1031 | 1031 | |
1032 | 1032 | } else { |
1033 | 1033 | EE_Error::add_error( |
1034 | 1034 | sprintf( |
1035 | - __( 'The requested form action "%s" does not exist for the current "%s" registration step.', 'event_espresso' ), |
|
1035 | + __('The requested form action "%s" does not exist for the current "%s" registration step.', 'event_espresso'), |
|
1036 | 1036 | $this->checkout->action, |
1037 | 1037 | $this->checkout->current_step->name() |
1038 | 1038 | ), |
@@ -1058,10 +1058,10 @@ discard block |
||
1058 | 1058 | public function add_styles_and_scripts() { |
1059 | 1059 | // i18n |
1060 | 1060 | $this->translate_js_strings(); |
1061 | - if ( $this->checkout->admin_request ) { |
|
1062 | - add_action('admin_enqueue_scripts', array($this, 'enqueue_styles_and_scripts'), 10 ); |
|
1061 | + if ($this->checkout->admin_request) { |
|
1062 | + add_action('admin_enqueue_scripts', array($this, 'enqueue_styles_and_scripts'), 10); |
|
1063 | 1063 | } else { |
1064 | - add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_styles_and_scripts' ), 10 ); |
|
1064 | + add_action('wp_enqueue_scripts', array($this, 'enqueue_styles_and_scripts'), 10); |
|
1065 | 1065 | } |
1066 | 1066 | } |
1067 | 1067 | |
@@ -1077,42 +1077,42 @@ discard block |
||
1077 | 1077 | EE_Registry::$i18n_js_strings['revisit'] = $this->checkout->revisit; |
1078 | 1078 | EE_Registry::$i18n_js_strings['e_reg_url_link'] = $this->checkout->reg_url_link; |
1079 | 1079 | EE_Registry::$i18n_js_strings['server_error'] = __('An unknown error occurred on the server while attempting to process your request. Please refresh the page and try again or contact support.', 'event_espresso'); |
1080 | - EE_Registry::$i18n_js_strings['invalid_json_response'] = __( 'An invalid response was returned from the server while attempting to process your request. Please refresh the page and try again or contact support.', 'event_espresso' ); |
|
1081 | - EE_Registry::$i18n_js_strings['validation_error'] = __( 'There appears to be a problem with the form validation configuration! Please check the admin settings or contact support.', 'event_espresso' ); |
|
1082 | - EE_Registry::$i18n_js_strings['invalid_payment_method'] = __( 'There appears to be a problem with the payment method configuration! Please refresh the page and try again or contact support.', 'event_espresso' ); |
|
1080 | + EE_Registry::$i18n_js_strings['invalid_json_response'] = __('An invalid response was returned from the server while attempting to process your request. Please refresh the page and try again or contact support.', 'event_espresso'); |
|
1081 | + EE_Registry::$i18n_js_strings['validation_error'] = __('There appears to be a problem with the form validation configuration! Please check the admin settings or contact support.', 'event_espresso'); |
|
1082 | + EE_Registry::$i18n_js_strings['invalid_payment_method'] = __('There appears to be a problem with the payment method configuration! Please refresh the page and try again or contact support.', 'event_espresso'); |
|
1083 | 1083 | EE_Registry::$i18n_js_strings['reg_step_error'] = __('This registration step could not be completed. Please refresh the page and try again.', 'event_espresso'); |
1084 | 1084 | EE_Registry::$i18n_js_strings['invalid_coupon'] = __('We\'re sorry but that coupon code does not appear to be valid. If this is incorrect, please contact the site administrator.', 'event_espresso'); |
1085 | - EE_Registry::$i18n_js_strings['process_registration'] = sprintf( __( 'Please wait while we process your registration.%sDo not refresh the page or navigate away while this is happening.%sThank you for your patience.', 'event_espresso' ), '<br/>', '<br/>' ); |
|
1086 | - EE_Registry::$i18n_js_strings['language'] = get_bloginfo( 'language' ); |
|
1085 | + EE_Registry::$i18n_js_strings['process_registration'] = sprintf(__('Please wait while we process your registration.%sDo not refresh the page or navigate away while this is happening.%sThank you for your patience.', 'event_espresso'), '<br/>', '<br/>'); |
|
1086 | + EE_Registry::$i18n_js_strings['language'] = get_bloginfo('language'); |
|
1087 | 1087 | EE_Registry::$i18n_js_strings['EESID'] = EE_Registry::instance()->SSN->id(); |
1088 | 1088 | EE_Registry::$i18n_js_strings['currency'] = EE_Registry::instance()->CFG->currency; |
1089 | 1089 | EE_Registry::$i18n_js_strings['datepicker_yearRange'] = '-150:+20'; |
1090 | - EE_Registry::$i18n_js_strings['timer_years'] = __( 'years', 'event_espresso' ); |
|
1091 | - EE_Registry::$i18n_js_strings['timer_months'] = __( 'months', 'event_espresso' ); |
|
1092 | - EE_Registry::$i18n_js_strings['timer_weeks'] = __( 'weeks', 'event_espresso' ); |
|
1093 | - EE_Registry::$i18n_js_strings['timer_days'] = __( 'days', 'event_espresso' ); |
|
1094 | - EE_Registry::$i18n_js_strings['timer_hours'] = __( 'hours', 'event_espresso' ); |
|
1095 | - EE_Registry::$i18n_js_strings['timer_minutes'] = __( 'minutes', 'event_espresso' ); |
|
1096 | - EE_Registry::$i18n_js_strings['timer_seconds'] = __( 'seconds', 'event_espresso' ); |
|
1097 | - EE_Registry::$i18n_js_strings['timer_year'] = __( 'year', 'event_espresso' ); |
|
1098 | - EE_Registry::$i18n_js_strings['timer_month'] = __( 'month', 'event_espresso' ); |
|
1099 | - EE_Registry::$i18n_js_strings['timer_week'] = __( 'week', 'event_espresso' ); |
|
1100 | - EE_Registry::$i18n_js_strings['timer_day'] = __( 'day', 'event_espresso' ); |
|
1101 | - EE_Registry::$i18n_js_strings['timer_hour'] = __( 'hour', 'event_espresso' ); |
|
1102 | - EE_Registry::$i18n_js_strings['timer_minute'] = __( 'minute', 'event_espresso' ); |
|
1103 | - EE_Registry::$i18n_js_strings['timer_second'] = __( 'second', 'event_espresso' ); |
|
1090 | + EE_Registry::$i18n_js_strings['timer_years'] = __('years', 'event_espresso'); |
|
1091 | + EE_Registry::$i18n_js_strings['timer_months'] = __('months', 'event_espresso'); |
|
1092 | + EE_Registry::$i18n_js_strings['timer_weeks'] = __('weeks', 'event_espresso'); |
|
1093 | + EE_Registry::$i18n_js_strings['timer_days'] = __('days', 'event_espresso'); |
|
1094 | + EE_Registry::$i18n_js_strings['timer_hours'] = __('hours', 'event_espresso'); |
|
1095 | + EE_Registry::$i18n_js_strings['timer_minutes'] = __('minutes', 'event_espresso'); |
|
1096 | + EE_Registry::$i18n_js_strings['timer_seconds'] = __('seconds', 'event_espresso'); |
|
1097 | + EE_Registry::$i18n_js_strings['timer_year'] = __('year', 'event_espresso'); |
|
1098 | + EE_Registry::$i18n_js_strings['timer_month'] = __('month', 'event_espresso'); |
|
1099 | + EE_Registry::$i18n_js_strings['timer_week'] = __('week', 'event_espresso'); |
|
1100 | + EE_Registry::$i18n_js_strings['timer_day'] = __('day', 'event_espresso'); |
|
1101 | + EE_Registry::$i18n_js_strings['timer_hour'] = __('hour', 'event_espresso'); |
|
1102 | + EE_Registry::$i18n_js_strings['timer_minute'] = __('minute', 'event_espresso'); |
|
1103 | + EE_Registry::$i18n_js_strings['timer_second'] = __('second', 'event_espresso'); |
|
1104 | 1104 | EE_Registry::$i18n_js_strings['registration_expiration_notice'] = sprintf( |
1105 | - __( '%1$sWe\'re sorry, but your registration time has expired.%2$s%3$s%4$sIf you still wish to complete your registration, please return to the %5$sEvent List%6$sEvent List%7$s and reselect your tickets if available. Please except our apologies for any inconvenience this may have caused.%8$s', 'event_espresso' ), |
|
1105 | + __('%1$sWe\'re sorry, but your registration time has expired.%2$s%3$s%4$sIf you still wish to complete your registration, please return to the %5$sEvent List%6$sEvent List%7$s and reselect your tickets if available. Please except our apologies for any inconvenience this may have caused.%8$s', 'event_espresso'), |
|
1106 | 1106 | '<h4 class="important-notice">', |
1107 | 1107 | '</h4>', |
1108 | 1108 | '<br />', |
1109 | 1109 | '<p>', |
1110 | - '<a href="'. get_post_type_archive_link( 'espresso_events' ) . '" title="', |
|
1110 | + '<a href="'.get_post_type_archive_link('espresso_events').'" title="', |
|
1111 | 1111 | '">', |
1112 | 1112 | '</a>', |
1113 | 1113 | '</p>' |
1114 | 1114 | ); |
1115 | - EE_Registry::$i18n_js_strings[ 'ajax_submit' ] = apply_filters( 'FHEE__Single_Page_Checkout__translate_js_strings__ajax_submit', true ); |
|
1115 | + EE_Registry::$i18n_js_strings['ajax_submit'] = apply_filters('FHEE__Single_Page_Checkout__translate_js_strings__ajax_submit', true); |
|
1116 | 1116 | } |
1117 | 1117 | |
1118 | 1118 | |
@@ -1125,25 +1125,25 @@ discard block |
||
1125 | 1125 | */ |
1126 | 1126 | public function enqueue_styles_and_scripts() { |
1127 | 1127 | // load css |
1128 | - wp_register_style( 'single_page_checkout', SPCO_CSS_URL . 'single_page_checkout.css', array(), EVENT_ESPRESSO_VERSION ); |
|
1129 | - wp_enqueue_style( 'single_page_checkout' ); |
|
1128 | + wp_register_style('single_page_checkout', SPCO_CSS_URL.'single_page_checkout.css', array(), EVENT_ESPRESSO_VERSION); |
|
1129 | + wp_enqueue_style('single_page_checkout'); |
|
1130 | 1130 | // load JS |
1131 | - wp_register_script( 'jquery_plugin', EE_THIRD_PARTY_URL . 'jquery .plugin.min.js', array( 'jquery' ), '1.0.1', TRUE ); |
|
1132 | - wp_register_script( 'jquery_countdown', EE_THIRD_PARTY_URL . 'jquery .countdown.min.js', array( 'jquery_plugin' ), '2.0.2', TRUE ); |
|
1133 | - wp_register_script( 'single_page_checkout', SPCO_JS_URL . 'single_page_checkout.js', array( 'espresso_core', 'underscore', 'ee_form_section_validation', 'jquery_countdown' ), EVENT_ESPRESSO_VERSION, TRUE ); |
|
1134 | - wp_enqueue_script( 'single_page_checkout' ); |
|
1131 | + wp_register_script('jquery_plugin', EE_THIRD_PARTY_URL.'jquery .plugin.min.js', array('jquery'), '1.0.1', TRUE); |
|
1132 | + wp_register_script('jquery_countdown', EE_THIRD_PARTY_URL.'jquery .countdown.min.js', array('jquery_plugin'), '2.0.2', TRUE); |
|
1133 | + wp_register_script('single_page_checkout', SPCO_JS_URL.'single_page_checkout.js', array('espresso_core', 'underscore', 'ee_form_section_validation', 'jquery_countdown'), EVENT_ESPRESSO_VERSION, TRUE); |
|
1134 | + wp_enqueue_script('single_page_checkout'); |
|
1135 | 1135 | |
1136 | 1136 | /** |
1137 | 1137 | * global action hook for enqueueing styles and scripts with |
1138 | 1138 | * spco calls. |
1139 | 1139 | */ |
1140 | - do_action( 'AHEE__EED_Single_Page_Checkout__enqueue_styles_and_scripts', $this ); |
|
1140 | + do_action('AHEE__EED_Single_Page_Checkout__enqueue_styles_and_scripts', $this); |
|
1141 | 1141 | |
1142 | 1142 | /** |
1143 | 1143 | * dynamic action hook for enqueueing styles and scripts with spco calls. |
1144 | 1144 | * The hook will end up being something like AHEE__EED_Single_Page_Checkout__enqueue_styles_and_scripts__attendee_information |
1145 | 1145 | */ |
1146 | - do_action( 'AHEE__EED_Single_Page_Checkout__enqueue_styles_and_scripts__' . $this->checkout->current_step->slug(), $this ); |
|
1146 | + do_action('AHEE__EED_Single_Page_Checkout__enqueue_styles_and_scripts__'.$this->checkout->current_step->slug(), $this); |
|
1147 | 1147 | |
1148 | 1148 | // add css and JS for current step |
1149 | 1149 | $this->checkout->current_step->enqueue_styles_and_scripts(); |
@@ -1159,20 +1159,20 @@ discard block |
||
1159 | 1159 | */ |
1160 | 1160 | private function _display_spco_reg_form() { |
1161 | 1161 | // if registering via the admin, just display the reg form for the current step |
1162 | - if ( $this->checkout->admin_request ) { |
|
1163 | - EE_Registry::instance()->REQ->add_output( $this->checkout->current_step->display_reg_form() ); |
|
1162 | + if ($this->checkout->admin_request) { |
|
1163 | + EE_Registry::instance()->REQ->add_output($this->checkout->current_step->display_reg_form()); |
|
1164 | 1164 | } else { |
1165 | 1165 | // add powered by EE msg |
1166 | - add_action( 'AHEE__SPCO__reg_form_footer', array( 'EED_Single_Page_Checkout', 'display_registration_footer' )); |
|
1166 | + add_action('AHEE__SPCO__reg_form_footer', array('EED_Single_Page_Checkout', 'display_registration_footer')); |
|
1167 | 1167 | |
1168 | - $empty_cart = count( $this->checkout->transaction->registrations( $this->checkout->reg_cache_where_params ) ) < 1 ? true : false; |
|
1168 | + $empty_cart = count($this->checkout->transaction->registrations($this->checkout->reg_cache_where_params)) < 1 ? true : false; |
|
1169 | 1169 | $cookies_not_set_msg = ''; |
1170 | - if ( $empty_cart ) { |
|
1171 | - if ( ! isset( $_COOKIE[ 'ee_cookie_test' ] ) ) { |
|
1170 | + if ($empty_cart) { |
|
1171 | + if ( ! isset($_COOKIE['ee_cookie_test'])) { |
|
1172 | 1172 | $cookies_not_set_msg = apply_filters( |
1173 | 1173 | 'FHEE__Single_Page_Checkout__display_spco_reg_form__cookies_not_set_msg', |
1174 | 1174 | sprintf( |
1175 | - __( '%1$s%3$sIt appears your browser is not currently set to accept Cookies%4$s%5$sIn order to register for events, you need to enable cookies.%7$sIf you require assistance, then click the following link to learn how to %8$senable cookies%9$s%6$s%2$s', 'event_espresso' ), |
|
1175 | + __('%1$s%3$sIt appears your browser is not currently set to accept Cookies%4$s%5$sIn order to register for events, you need to enable cookies.%7$sIf you require assistance, then click the following link to learn how to %8$senable cookies%9$s%6$s%2$s', 'event_espresso'), |
|
1176 | 1176 | '<div class="ee-attention">', |
1177 | 1177 | '</div>', |
1178 | 1178 | '<h6 class="important-notice">', |
@@ -1193,7 +1193,7 @@ discard block |
||
1193 | 1193 | 'layout_strategy' => |
1194 | 1194 | new EE_Template_Layout( |
1195 | 1195 | array( |
1196 | - 'layout_template_file' => SPCO_TEMPLATES_PATH . 'registration_page_wrapper.template.php', |
|
1196 | + 'layout_template_file' => SPCO_TEMPLATES_PATH.'registration_page_wrapper.template.php', |
|
1197 | 1197 | 'template_args' => array( |
1198 | 1198 | 'empty_cart' => $empty_cart, |
1199 | 1199 | 'revisit' => $this->checkout->revisit, |
@@ -1202,8 +1202,8 @@ discard block |
||
1202 | 1202 | 'empty_msg' => apply_filters( |
1203 | 1203 | 'FHEE__Single_Page_Checkout__display_spco_reg_form__empty_msg', |
1204 | 1204 | sprintf( |
1205 | - __( 'You need to %1$sReturn to Events list%2$sselect at least one event%3$s before you can proceed with the registration process.', 'event_espresso' ), |
|
1206 | - '<a href="' . get_post_type_archive_link( 'espresso_events' ) . '" title="', |
|
1205 | + __('You need to %1$sReturn to Events list%2$sselect at least one event%3$s before you can proceed with the registration process.', 'event_espresso'), |
|
1206 | + '<a href="'.get_post_type_archive_link('espresso_events').'" title="', |
|
1207 | 1207 | '">', |
1208 | 1208 | '</a>' |
1209 | 1209 | ) |
@@ -1211,14 +1211,14 @@ discard block |
||
1211 | 1211 | 'cookies_not_set_msg' => $cookies_not_set_msg, |
1212 | 1212 | 'registration_time_limit' => $this->checkout->get_registration_time_limit(), |
1213 | 1213 | 'session_expiration' => |
1214 | - gmdate( 'M d, Y H:i:s', EE_Registry::instance()->SSN->expiration() + ( get_option( 'gmt_offset' ) * HOUR_IN_SECONDS ) ) |
|
1214 | + gmdate('M d, Y H:i:s', EE_Registry::instance()->SSN->expiration() + (get_option('gmt_offset') * HOUR_IN_SECONDS)) |
|
1215 | 1215 | ) |
1216 | 1216 | ) |
1217 | 1217 | ) |
1218 | 1218 | ) |
1219 | 1219 | ); |
1220 | 1220 | // load template and add to output sent that gets filtered into the_content() |
1221 | - EE_Registry::instance()->REQ->add_output( $this->checkout->registration_form->get_html_and_js() ); |
|
1221 | + EE_Registry::instance()->REQ->add_output($this->checkout->registration_form->get_html_and_js()); |
|
1222 | 1222 | } |
1223 | 1223 | } |
1224 | 1224 | |
@@ -1232,8 +1232,8 @@ discard block |
||
1232 | 1232 | * @internal param string $label |
1233 | 1233 | * @return string |
1234 | 1234 | */ |
1235 | - public function add_extra_finalize_registration_inputs( $next_step ) { |
|
1236 | - if ( $next_step == 'finalize_registration' ) { |
|
1235 | + public function add_extra_finalize_registration_inputs($next_step) { |
|
1236 | + if ($next_step == 'finalize_registration') { |
|
1237 | 1237 | echo '<div id="spco-extra-finalize_registration-inputs-dv"></div>'; |
1238 | 1238 | } |
1239 | 1239 | } |
@@ -1247,18 +1247,18 @@ discard block |
||
1247 | 1247 | * @return string |
1248 | 1248 | */ |
1249 | 1249 | public static function display_registration_footer() { |
1250 | - if ( apply_filters( 'FHEE__EE_Front__Controller__show_reg_footer', EE_Registry::instance()->CFG->admin->show_reg_footer ) ) { |
|
1251 | - EE_Registry::instance()->CFG->admin->affiliate_id = ! empty( EE_Registry::instance()->CFG->admin->affiliate_id ) ? EE_Registry::instance()->CFG->admin->affiliate_id : 'default'; |
|
1252 | - $url = add_query_arg( array( 'ap_id' => EE_Registry::instance()->CFG->admin->affiliate_id ), 'https://eventespresso.com/' ); |
|
1253 | - $url = apply_filters( 'FHEE__EE_Front_Controller__registration_footer__url', $url ); |
|
1250 | + if (apply_filters('FHEE__EE_Front__Controller__show_reg_footer', EE_Registry::instance()->CFG->admin->show_reg_footer)) { |
|
1251 | + EE_Registry::instance()->CFG->admin->affiliate_id = ! empty(EE_Registry::instance()->CFG->admin->affiliate_id) ? EE_Registry::instance()->CFG->admin->affiliate_id : 'default'; |
|
1252 | + $url = add_query_arg(array('ap_id' => EE_Registry::instance()->CFG->admin->affiliate_id), 'https://eventespresso.com/'); |
|
1253 | + $url = apply_filters('FHEE__EE_Front_Controller__registration_footer__url', $url); |
|
1254 | 1254 | echo apply_filters( |
1255 | 1255 | 'FHEE__EE_Front_Controller__display_registration_footer', |
1256 | 1256 | sprintf( |
1257 | - __( '%1$sEvent Registration Powered by Event Espresso%2$sEvent Registration and Ticketing%3$s Powered by %4$sEvent Espresso - Event Registration and Management System for WordPress%5$sEvent Espresso%6$s', 'event_espresso' ), |
|
1258 | - '<div id="espresso-registration-footer-dv"><a href="' . $url . '" title="', |
|
1257 | + __('%1$sEvent Registration Powered by Event Espresso%2$sEvent Registration and Ticketing%3$s Powered by %4$sEvent Espresso - Event Registration and Management System for WordPress%5$sEvent Espresso%6$s', 'event_espresso'), |
|
1258 | + '<div id="espresso-registration-footer-dv"><a href="'.$url.'" title="', |
|
1259 | 1259 | '" target="_blank">', |
1260 | 1260 | '</a>', |
1261 | - '<a href="' . $url . '" title="', |
|
1261 | + '<a href="'.$url.'" title="', |
|
1262 | 1262 | '" target="_blank">', |
1263 | 1263 | '</a></div>' |
1264 | 1264 | ) |
@@ -1289,12 +1289,12 @@ discard block |
||
1289 | 1289 | * @return array |
1290 | 1290 | */ |
1291 | 1291 | private function _setup_redirect() { |
1292 | - if ( $this->checkout->continue_reg && $this->checkout->next_step instanceof EE_SPCO_Reg_Step ) { |
|
1292 | + if ($this->checkout->continue_reg && $this->checkout->next_step instanceof EE_SPCO_Reg_Step) { |
|
1293 | 1293 | $this->checkout->redirect = TRUE; |
1294 | - if ( empty( $this->checkout->redirect_url )) { |
|
1294 | + if (empty($this->checkout->redirect_url)) { |
|
1295 | 1295 | $this->checkout->redirect_url = $this->checkout->next_step->reg_step_url(); |
1296 | 1296 | } |
1297 | - $this->checkout->redirect_url = apply_filters( 'FHEE__EED_Single_Page_Checkout___setup_redirect__checkout_redirect_url', $this->checkout->redirect_url, $this->checkout ); |
|
1297 | + $this->checkout->redirect_url = apply_filters('FHEE__EED_Single_Page_Checkout___setup_redirect__checkout_redirect_url', $this->checkout->redirect_url, $this->checkout); |
|
1298 | 1298 | } |
1299 | 1299 | } |
1300 | 1300 | |
@@ -1307,12 +1307,12 @@ discard block |
||
1307 | 1307 | * @return void |
1308 | 1308 | */ |
1309 | 1309 | public function go_to_next_step() { |
1310 | - if ( EE_Registry::instance()->REQ->ajax ) { |
|
1310 | + if (EE_Registry::instance()->REQ->ajax) { |
|
1311 | 1311 | // capture contents of output buffer we started earlier in the request, and insert into JSON response |
1312 | - $this->checkout->json_response->set_unexpected_errors( ob_get_clean() ); |
|
1312 | + $this->checkout->json_response->set_unexpected_errors(ob_get_clean()); |
|
1313 | 1313 | } |
1314 | 1314 | // just return for these conditions |
1315 | - if ( $this->checkout->admin_request || $this->checkout->action == 'redirect_form' || $this->checkout->action == 'update_checkout' ) { |
|
1315 | + if ($this->checkout->admin_request || $this->checkout->action == 'redirect_form' || $this->checkout->action == 'update_checkout') { |
|
1316 | 1316 | return; |
1317 | 1317 | } |
1318 | 1318 | // AJAX response |
@@ -1333,7 +1333,7 @@ discard block |
||
1333 | 1333 | */ |
1334 | 1334 | protected function _handle_json_response() { |
1335 | 1335 | // if this is an ajax request |
1336 | - if ( EE_Registry::instance()->REQ->ajax ) { |
|
1336 | + if (EE_Registry::instance()->REQ->ajax) { |
|
1337 | 1337 | // DEBUG LOG |
1338 | 1338 | //$this->checkout->log( |
1339 | 1339 | // __CLASS__, __FUNCTION__, __LINE__, |
@@ -1343,10 +1343,10 @@ discard block |
||
1343 | 1343 | // 'continue_reg' => $this->checkout->continue_reg, |
1344 | 1344 | // ) |
1345 | 1345 | //); |
1346 | - $this->checkout->json_response->set_registration_time_limit( $this->checkout->get_registration_time_limit() ); |
|
1347 | - $this->checkout->json_response->set_payment_amount( $this->checkout->amount_owing ); |
|
1346 | + $this->checkout->json_response->set_registration_time_limit($this->checkout->get_registration_time_limit()); |
|
1347 | + $this->checkout->json_response->set_payment_amount($this->checkout->amount_owing); |
|
1348 | 1348 | // just send the ajax ( |
1349 | - $json_response = apply_filters( 'FHEE__EE_Single_Page_Checkout__JSON_response', $this->checkout->json_response ); |
|
1349 | + $json_response = apply_filters('FHEE__EE_Single_Page_Checkout__JSON_response', $this->checkout->json_response); |
|
1350 | 1350 | $this->unlock_transaction(); |
1351 | 1351 | echo $json_response; |
1352 | 1352 | exit(); |
@@ -1363,9 +1363,9 @@ discard block |
||
1363 | 1363 | */ |
1364 | 1364 | protected function _handle_html_redirects() { |
1365 | 1365 | // going somewhere ? |
1366 | - if ( $this->checkout->redirect && ! empty( $this->checkout->redirect_url ) ) { |
|
1366 | + if ($this->checkout->redirect && ! empty($this->checkout->redirect_url)) { |
|
1367 | 1367 | // store notices in a transient |
1368 | - EE_Error::get_notices( false, true, true ); |
|
1368 | + EE_Error::get_notices(false, true, true); |
|
1369 | 1369 | $this->unlock_transaction(); |
1370 | 1370 | // DEBUG LOG |
1371 | 1371 | //$this->checkout->log( |
@@ -1376,7 +1376,7 @@ discard block |
||
1376 | 1376 | // 'headers_list' => headers_list(), |
1377 | 1377 | // ) |
1378 | 1378 | //); |
1379 | - wp_safe_redirect( $this->checkout->redirect_url ); |
|
1379 | + wp_safe_redirect($this->checkout->redirect_url); |
|
1380 | 1380 | exit(); |
1381 | 1381 | } |
1382 | 1382 | } |