← All changes
|
includes/admin/tools/data/class-give-tools-recount-form-stats.php
+47
-32
2.3.0
→
4.17.0
View file →
| @@ -4,9 +4,9 @@ | ||
| 4 | 4 | * |
| 5 | 5 | * This class handles batch processing of recounting earnings and stats |
| 6 | 6 | * |
| 7 | 7 | * @subpackage Admin/Tools/Give_Tools_Recount_Stats |
| 8 | - * @copyright Copyright (c) 2016, WordImpress | |
| 8 | + * @copyright Copyright (c) 2016, GiveWP | |
| 9 | 9 | * @license https://opensource.org/licenses/gpl-license GNU Public License |
| 10 | 10 | * @since 1.5 |
| 11 | 11 | */ |
| 12 | 12 | |
| @@ -23,8 +23,9 @@ | ||
| 23 | 23 | class Give_Tools_Recount_Form_Stats extends Give_Batch_Export { |
| 24 | 24 | |
| 25 | 25 | /** |
| 26 | 26 | * Our export type. Used for export-type specific filters/actions |
| 27 | + * | |
| 27 | 28 | * @var string |
| 28 | 29 | * @since 1.5 |
| 29 | 30 | */ |
| 30 | 31 | public $export_type = ''; |
| @@ -30,8 +31,9 @@ | ||
| 30 | 31 | public $export_type = ''; |
| 31 | 32 | |
| 32 | 33 | /** |
| 33 | 34 | * Allows for a non-form batch processing to be run. |
| 35 | + * | |
| 34 | 36 | * @since 1.5 |
| 35 | 37 | * @var boolean |
| 36 | 38 | */ |
| 37 | 39 | public $is_void = true; |
| @@ -37,8 +39,9 @@ | ||
| 37 | 39 | public $is_void = true; |
| 38 | 40 | |
| 39 | 41 | /** |
| 40 | 42 | * Sets the number of items to pull on each step |
| 43 | + * | |
| 41 | 44 | * @since 1.5 |
| 42 | 45 | * @var integer |
| 43 | 46 | */ |
| 44 | 47 | public $per_step = 30; |
| @@ -44,8 +47,9 @@ | ||
| 44 | 47 | public $per_step = 30; |
| 45 | 48 | |
| 46 | 49 | /** |
| 47 | 50 | * Sets the donation form ID to recalculate |
| 51 | + * | |
| 48 | 52 | * @since 1.5 |
| 49 | 53 | * @var integer |
| 50 | 54 | */ |
| 51 | 55 | protected $form_id = 0; |
| @@ -68,9 +72,9 @@ | ||
| 68 | 72 | * @return bool |
| 69 | 73 | */ |
| 70 | 74 | public function get_data() { |
| 71 | 75 | |
| 72 | - $accepted_statuses = apply_filters( 'give_recount_accepted_statuses', array( 'publish' ) ); | |
| 76 | + $accepted_statuses = apply_filters( 'give_recount_accepted_statuses', [ 'publish' ] ); | |
| 73 | 77 | |
| 74 | 78 | if ( $this->step == 1 ) { |
| 75 | 79 | $this->delete_data( 'give_temp_recount_form_stats' ); |
| 76 | 80 | } |
| @@ -77,22 +81,25 @@ | ||
| 77 | 81 | |
| 78 | 82 | $totals = $this->get_stored_data( 'give_temp_recount_form_stats' ); |
| 79 | 83 | |
| 80 | 84 | if ( false === $totals ) { |
| 81 | - $totals = array( | |
| 85 | + $totals = [ | |
| 82 | 86 | 'earnings' => (float) 0, |
| 83 | 87 | 'sales' => 0, |
| 84 | - ); | |
| 88 | + ]; | |
| 85 | 89 | $this->store_data( 'give_temp_recount_form_stats', $totals ); |
| 86 | 90 | } |
| 87 | 91 | |
| 88 | - $args = apply_filters( 'give_recount_form_stats_args', array( | |
| 89 | - 'give_forms' => $this->form_id, | |
| 90 | - 'number' => $this->per_step, | |
| 91 | - 'status' => $accepted_statuses, | |
| 92 | - 'paged' => $this->step, | |
| 93 | - 'fields' => 'ids', | |
| 94 | - ) ); | |
| 92 | + $args = apply_filters( | |
| 93 | + 'give_recount_form_stats_args', | |
| 94 | + [ | |
| 95 | + 'give_forms' => $this->form_id, | |
| 96 | + 'number' => $this->per_step, | |
| 97 | + 'status' => $accepted_statuses, | |
| 98 | + 'paged' => $this->step, | |
| 99 | + 'fields' => 'ids', | |
| 100 | + ] | |
| 101 | + ); | |
| 95 | 102 | |
| 96 | 103 | $payments = new Give_Payments_Query( $args ); |
| 97 | 104 | $payments = $payments->get_payments(); |
| 98 | 105 | |
| @@ -108,8 +115,10 @@ | ||
| 108 | 115 | if ( $payment->form_id != $this->form_id ) { |
| 109 | 116 | continue; |
| 110 | 117 | } |
| 111 | 118 | |
| 119 | + $currency_code = give_get_payment_currency_code( $payment->ID ); | |
| 120 | + | |
| 112 | 121 | /** |
| 113 | 122 | * Filter the payment amount. |
| 114 | 123 | * |
| 115 | 124 | * @since 2.1 |
| @@ -115,16 +124,20 @@ | ||
| 115 | 124 | * @since 2.1 |
| 116 | 125 | */ |
| 117 | 126 | $earning_amount = apply_filters( |
| 118 | 127 | 'give_donation_amount', |
| 119 | - give_format_amount( $payment->total, array( 'donation_id' => $payment->ID ) ), | |
| 128 | + give_format_amount( $payment->total, [ 'donation_id' => $payment->ID ] ), | |
| 120 | 129 | $payment->total, |
| 121 | 130 | $payment->ID, |
| 122 | - array( 'type' => 'stats', 'currency' => false, 'amount' => false ) | |
| 131 | + [ | |
| 132 | + 'type' => 'stats', | |
| 133 | + 'currency' => false, | |
| 134 | + 'amount' => false, | |
| 135 | + ] | |
| 123 | 136 | ); |
| 124 | 137 | |
| 125 | 138 | $totals['sales'] ++; |
| 126 | - $totals['earnings'] += (float) give_maybe_sanitize_amount( $earning_amount ); | |
| 139 | + $totals['earnings'] += (float) give_maybe_sanitize_amount( $earning_amount, [ 'currency' => $currency_code ] ); | |
| 127 | 140 | |
| 128 | 141 | } |
| 129 | 142 | |
| 130 | 143 | $this->store_data( 'give_temp_recount_form_stats', $totals ); |
| @@ -131,9 +144,8 @@ | ||
| 131 | 144 | |
| 132 | 145 | return true; |
| 133 | 146 | } |
| 134 | 147 | |
| 135 | - | |
| 136 | 148 | give_update_meta( $this->form_id, '_give_form_sales', $totals['sales'] ); |
| 137 | 149 | give_update_meta( $this->form_id, '_give_form_earnings', give_sanitize_amount_for_db( $totals['earnings'] ) ); |
| 138 | 150 | |
| 139 | 151 | return false; |
| @@ -149,19 +161,22 @@ | ||
| 149 | 161 | if ( $this->step == 1 ) { |
| 150 | 162 | $this->delete_data( 'give_recount_total_' . $this->form_id ); |
| 151 | 163 | } |
| 152 | 164 | |
| 153 | - $accepted_statuses = apply_filters( 'give_recount_accepted_statuses', array( 'publish' ) ); | |
| 165 | + $accepted_statuses = apply_filters( 'give_recount_accepted_statuses', [ 'publish' ] ); | |
| 154 | 166 | $total = $this->get_stored_data( 'give_recount_total_' . $this->form_id ); |
| 155 | 167 | |
| 156 | 168 | if ( false === $total ) { |
| 157 | 169 | $total = 0; |
| 158 | - $args = apply_filters( 'give_recount_form_stats_total_args', array( | |
| 159 | - 'give_forms' => $this->form_id, | |
| 160 | - 'number' => - 1, | |
| 161 | - 'status' => $accepted_statuses, | |
| 162 | - 'fields' => 'ids', | |
| 163 | - ) ); | |
| 170 | + $args = apply_filters( | |
| 171 | + 'give_recount_form_stats_total_args', | |
| 172 | + [ | |
| 173 | + 'give_forms' => $this->form_id, | |
| 174 | + 'number' => - 1, | |
| 175 | + 'status' => $accepted_statuses, | |
| 176 | + 'fields' => 'ids', | |
| 177 | + ] | |
| 178 | + ); | |
| 164 | 179 | |
| 165 | 180 | $payments = new Give_Payments_Query( $args ); |
| 166 | 181 | $total = count( $payments->get_payments() ); |
| 167 | 182 | $this->store_data( 'give_recount_total_' . $this->form_id, $total ); |
| @@ -200,9 +215,9 @@ | ||
| 200 | 215 | */ |
| 201 | 216 | public function process_step() { |
| 202 | 217 | |
| 203 | 218 | if ( ! $this->can_export() ) { |
| 204 | - wp_die( esc_html__( 'You do not have permission to recount stats.', 'give' ), esc_html__( 'Error', 'give' ), array( 'response' => 403 ) ); | |
| 219 | + wp_die( esc_html__( 'You do not have permission to recount stats.', 'give' ), esc_html__( 'Error', 'give' ), [ 'response' => 403 ] ); | |
| 205 | 220 | } |
| 206 | 221 | |
| 207 | 222 | $had_data = $this->get_data(); |
| 208 | 223 | |
| @@ -213,9 +228,9 @@ | ||
| 213 | 228 | } else { |
| 214 | 229 | $this->delete_data( 'give_recount_total_' . $this->form_id ); |
| 215 | 230 | $this->delete_data( 'give_temp_recount_form_stats' ); |
| 216 | 231 | $this->done = true; |
| 217 | - $this->message = sprintf( esc_html__( 'Donation counts and income amount statistics successfully recounted for "%s".', 'give' ), get_the_title( $this->form_id ) ); | |
| 232 | + $this->message = sprintf( esc_html__( 'Donation counts and revenue amount statistics successfully recounted for "%s".', 'give' ), get_the_title( $this->form_id ) ); | |
| 218 | 233 | |
| 219 | 234 | return false; |
| 220 | 235 | } |
| 221 | 236 | } |
| @@ -269,9 +284,9 @@ | ||
| 269 | 284 | * |
| 270 | 285 | * @since 1.5 |
| 271 | 286 | * |
| 272 | 287 | * @param string $key The option_name |
| 273 | - * @param mixed $value The value to store | |
| 288 | + * @param mixed $value The value to store | |
| 274 | 289 | * |
| 275 | 290 | * @return void |
| 276 | 291 | */ |
| 277 | 292 | private function store_data( $key, $value ) { |
| @@ -278,19 +293,19 @@ | ||
| 278 | 293 | global $wpdb; |
| 279 | 294 | |
| 280 | 295 | $value = is_array( $value ) ? wp_json_encode( $value ) : esc_attr( $value ); |
| 281 | 296 | |
| 282 | - $data = array( | |
| 297 | + $data = [ | |
| 283 | 298 | 'option_name' => $key, |
| 284 | 299 | 'option_value' => $value, |
| 285 | 300 | 'autoload' => 'no', |
| 286 | - ); | |
| 301 | + ]; | |
| 287 | 302 | |
| 288 | - $formats = array( | |
| 303 | + $formats = [ | |
| 289 | 304 | '%s', |
| 290 | 305 | '%s', |
| 291 | 306 | '%s', |
| 292 | - ); | |
| 307 | + ]; | |
| 293 | 308 | |
| 294 | 309 | $wpdb->replace( $wpdb->options, $data, $formats ); |
| 295 | 310 | } |
| 296 | 311 | |
| @@ -304,9 +319,9 @@ | ||
| 304 | 319 | * @return void |
| 305 | 320 | */ |
| 306 | 321 | private function delete_data( $key ) { |
| 307 | 322 | global $wpdb; |
| 308 | - $wpdb->delete( $wpdb->options, array( 'option_name' => $key ) ); | |
| 323 | + $wpdb->delete( $wpdb->options, [ 'option_name' => $key ] ); | |
| 309 | 324 | } |
| 310 | 325 | |
| 311 | 326 | /** |
| 312 | 327 | * Unset the properties specific to the donors export. |
| @@ -312,9 +327,9 @@ | ||
| 312 | 327 | * Unset the properties specific to the donors export. |
| 313 | 328 | * |
| 314 | 329 | * @since 2.3.0 |
| 315 | 330 | * |
| 316 | - * @param array $request | |
| 331 | + * @param array $request | |
| 317 | 332 | * @param Give_Batch_Export $export |
| 318 | 333 | */ |
| 319 | 334 | public function unset_properties( $request, $export ) { |
| 320 | 335 | if ( $export->done ) { |
| @@ -322,5 +337,5 @@ | ||
| 322 | 337 | $this->delete_data( 'give_temp_recount_form_stats' ); |
| 323 | 338 | $this->delete_data( 'give_recount_total_' . $this->form_id ); |
| 324 | 339 | } |
| 325 | 340 | } |
| 326 | -} | |
| 341 | +} | |