← All changes
|
includes/admin/tools/data/class-give-tools-recount-all-stats.php
+33
-22
2.3.2
→
4.17.0
View file →
| @@ -110,15 +110,18 @@ | ||
| 110 | 110 | |
| 111 | 111 | $payments = $this->get_stored_data( 'give_temp_all_payments_data' ); |
| 112 | 112 | |
| 113 | 113 | if ( empty( $payments ) ) { |
| 114 | - $args = apply_filters( 'give_recount_form_stats_args', array( | |
| 115 | - 'give_forms' => $all_forms, | |
| 116 | - 'number' => $this->per_step, | |
| 117 | - 'status' => $accepted_statuses, | |
| 118 | - 'paged' => $this->step, | |
| 119 | - 'output' => 'give_payments', | |
| 120 | - ) ); | |
| 114 | + $args = apply_filters( | |
| 115 | + 'give_recount_form_stats_args', | |
| 116 | + array( | |
| 117 | + 'give_forms' => $all_forms, | |
| 118 | + 'number' => $this->per_step, | |
| 119 | + 'status' => $accepted_statuses, | |
| 120 | + 'paged' => $this->step, | |
| 121 | + 'output' => 'give_payments', | |
| 122 | + ) | |
| 123 | + ); | |
| 121 | 124 | |
| 122 | 125 | $payments_query = new Give_Payments_Query( $args ); |
| 123 | 126 | $payments = $payments_query->get_payments(); |
| 124 | 127 | } |
| @@ -124,13 +127,13 @@ | ||
| 124 | 127 | } |
| 125 | 128 | |
| 126 | 129 | if ( ! empty( $payments ) ) { |
| 127 | 130 | |
| 128 | - //Loop through payments | |
| 131 | + // Loop through payments | |
| 129 | 132 | foreach ( $payments as $payment ) { |
| 130 | 133 | |
| 131 | 134 | $payment_id = ( ! empty( $payment['ID'] ) ? absint( $payment['ID'] ) : ( ! empty( $payment->ID ) ? absint( $payment->ID ) : false ) ); |
| 132 | - $payment = new Give_Payment( $payment_id ); | |
| 135 | + $payment = new Give_Payment( $payment_id ); | |
| 133 | 136 | |
| 134 | 137 | // Prevent payments that have all ready been retrieved from a previous sales log from counting again. |
| 135 | 138 | if ( in_array( $payment->ID, $processed_payments ) ) { |
| 136 | 139 | continue; |
| @@ -171,9 +174,9 @@ | ||
| 171 | 174 | |
| 172 | 175 | // Get the list of form ids which does not contain any payment record. |
| 173 | 176 | $remaining_form_ids = array_diff( $all_forms, array_keys( $totals ) ); |
| 174 | 177 | foreach ( $remaining_form_ids as $form_id ) { |
| 175 | - //If array key doesn't exist, create it | |
| 178 | + // If array key doesn't exist, create it | |
| 176 | 179 | if ( ! array_key_exists( $form_id, $totals ) ) { |
| 177 | 180 | $totals[ $form_id ] = array( |
| 178 | 181 | 'sales' => (int) 0, |
| 179 | 182 | 'earnings' => (float) 0, |
| @@ -186,9 +189,8 @@ | ||
| 186 | 189 | |
| 187 | 190 | return true; |
| 188 | 191 | } |
| 189 | 192 | |
| 190 | - | |
| 191 | 193 | foreach ( $totals as $key => $stats ) { |
| 192 | 194 | give_update_meta( $key, '_give_form_sales', $stats['sales'] ); |
| 193 | 195 | give_update_meta( $key, '_give_form_earnings', give_sanitize_amount_for_db( $stats['earnings'] ) ); |
| 194 | 196 | } |
| @@ -328,15 +330,18 @@ | ||
| 328 | 330 | $all_forms = get_posts( $args ); |
| 329 | 331 | |
| 330 | 332 | $this->store_data( 'give_temp_form_ids', $all_forms ); |
| 331 | 333 | |
| 332 | - $args = apply_filters( 'give_recount_form_stats_total_args', array( | |
| 333 | - 'give_forms' => $all_forms, | |
| 334 | - 'number' => $this->per_step, | |
| 335 | - 'status' => $accepted_statuses, | |
| 336 | - 'page' => $this->step, | |
| 337 | - 'output' => 'payments', | |
| 338 | - ) ); | |
| 334 | + $args = apply_filters( | |
| 335 | + 'give_recount_form_stats_total_args', | |
| 336 | + array( | |
| 337 | + 'give_forms' => $all_forms, | |
| 338 | + 'number' => $this->per_step, | |
| 339 | + 'status' => $accepted_statuses, | |
| 340 | + 'page' => $this->step, | |
| 341 | + 'output' => 'payments', | |
| 342 | + ) | |
| 343 | + ); | |
| 339 | 344 | |
| 340 | 345 | $payments_query = new Give_Payments_Query( $args ); |
| 341 | 346 | $payments = $payments_query->get_payments(); |
| 342 | 347 | |
| @@ -349,9 +354,9 @@ | ||
| 349 | 354 | foreach ( $payments as $payment ) { |
| 350 | 355 | |
| 351 | 356 | $form_id = $payment->form_id; |
| 352 | 357 | |
| 353 | - //If for some reason somehow the form_ID isn't set check payment meta | |
| 358 | + // If for some reason somehow the form_ID isn't set check payment meta | |
| 354 | 359 | if ( empty( $payment->form_id ) ) { |
| 355 | 360 | $payment_meta = $payment->get_meta(); |
| 356 | 361 | $form_id = isset( $payment_meta['form_id'] ) ? $payment_meta['form_id'] : 0; |
| 357 | 362 | } |
| @@ -359,8 +364,10 @@ | ||
| 359 | 364 | if ( ! in_array( $payment->post_status, $accepted_statuses ) ) { |
| 360 | 365 | continue; |
| 361 | 366 | } |
| 362 | 367 | |
| 368 | + $currency_code = give_get_payment_currency_code( $payment->ID ); | |
| 369 | + | |
| 363 | 370 | if ( ! array_key_exists( $payment->ID, $payment_items ) ) { |
| 364 | 371 | |
| 365 | 372 | /** |
| 366 | 373 | * Filter the payment amount. |
| @@ -371,15 +378,19 @@ | ||
| 371 | 378 | 'give_donation_amount', |
| 372 | 379 | give_format_amount( $payment->total, array( 'donation_id' => $payment->ID ) ), |
| 373 | 380 | $payment->total, |
| 374 | 381 | $payment->ID, |
| 375 | - array( 'type' => 'stats', 'currency' => false, 'amount' => false ) | |
| 382 | + array( | |
| 383 | + 'type' => 'stats', | |
| 384 | + 'currency' => false, | |
| 385 | + 'amount' => false, | |
| 386 | + ) | |
| 376 | 387 | ); |
| 377 | 388 | |
| 378 | 389 | $payment_items[ $payment->ID ] = array( |
| 379 | 390 | 'id' => $form_id, |
| 380 | 391 | 'payment_id' => $payment->ID, |
| 381 | - 'price' => (float) give_maybe_sanitize_amount( $payment_total ), | |
| 392 | + 'price' => (float) give_maybe_sanitize_amount( $payment_total, array( 'currency' => $currency_code ) ), | |
| 382 | 393 | ); |
| 383 | 394 | } |
| 384 | 395 | } |
| 385 | 396 | } |
| @@ -462,9 +473,9 @@ | ||
| 462 | 473 | * Unset the properties specific to the donors export. |
| 463 | 474 | * |
| 464 | 475 | * @since 2.3.0 |
| 465 | 476 | * |
| 466 | - * @param array $request | |
| 477 | + * @param array $request | |
| 467 | 478 | * @param Give_Batch_Export $export |
| 468 | 479 | */ |
| 469 | 480 | public function unset_properties( $request, $export ) { |
| 470 | 481 | if ( $export->done ) { |