@@ -12,7 +12,7 @@ discard block |
||
12 | 12 | */ |
13 | 13 | |
14 | 14 | // Exit if accessed directly. |
15 | -if ( ! defined( 'ABSPATH' ) ) { |
|
15 | +if ( ! defined('ABSPATH')) { |
|
16 | 16 | exit; |
17 | 17 | } |
18 | 18 | |
@@ -70,23 +70,23 @@ discard block |
||
70 | 70 | * |
71 | 71 | * @param array $request The Form Data passed into the batch processing |
72 | 72 | */ |
73 | - public function set_properties( $request ) { |
|
73 | + public function set_properties($request) { |
|
74 | 74 | |
75 | 75 | // Set data from form submission |
76 | - if ( isset( $_POST['form'] ) ) { |
|
77 | - parse_str( $_POST['form'], $this->data ); |
|
76 | + if (isset($_POST['form'])) { |
|
77 | + parse_str($_POST['form'], $this->data); |
|
78 | 78 | } |
79 | 79 | |
80 | 80 | $this->form = $this->data['forms']; |
81 | 81 | |
82 | 82 | // Setup donor ids cache. |
83 | - if ( ! empty( $this->form ) ) { |
|
83 | + if ( ! empty($this->form)) { |
|
84 | 84 | // Cache donor ids to output unique list of donor. |
85 | - $this->query_id = give_clean( $_REQUEST['give_export_option']['query_id'] ); |
|
85 | + $this->query_id = give_clean($_REQUEST['give_export_option']['query_id']); |
|
86 | 86 | $this->cache_donor_ids(); |
87 | 87 | } |
88 | 88 | |
89 | - $this->price_id = ! empty( $request['give_price_option'] ) && 'all' !== $request['give_price_option'] ? absint( $request['give_price_option'] ) : null; |
|
89 | + $this->price_id = ! empty($request['give_price_option']) && 'all' !== $request['give_price_option'] ? absint($request['give_price_option']) : null; |
|
90 | 90 | |
91 | 91 | } |
92 | 92 | |
@@ -101,12 +101,12 @@ discard block |
||
101 | 101 | // Fetch already cached donor ids. |
102 | 102 | $donor_ids = $this->donor_ids; |
103 | 103 | |
104 | - if ( $cached_donor_ids = Give_Cache::get( $this->query_id, true ) ) { |
|
105 | - $donor_ids = array_unique( array_merge( $cached_donor_ids, $this->donor_ids ) ); |
|
104 | + if ($cached_donor_ids = Give_Cache::get($this->query_id, true)) { |
|
105 | + $donor_ids = array_unique(array_merge($cached_donor_ids, $this->donor_ids)); |
|
106 | 106 | } |
107 | 107 | |
108 | - $donor_ids = array_values( $donor_ids ); |
|
109 | - Give_Cache::set( $this->query_id, $donor_ids, HOUR_IN_SECONDS, true ); |
|
108 | + $donor_ids = array_values($donor_ids); |
|
109 | + Give_Cache::set($this->query_id, $donor_ids, HOUR_IN_SECONDS, true); |
|
110 | 110 | } |
111 | 111 | |
112 | 112 | /** |
@@ -118,14 +118,14 @@ discard block |
||
118 | 118 | */ |
119 | 119 | public function csv_cols() { |
120 | 120 | |
121 | - $columns = isset( $this->data['give_export_option'] ) ? $this->data['give_export_option'] : array(); |
|
121 | + $columns = isset($this->data['give_export_option']) ? $this->data['give_export_option'] : array(); |
|
122 | 122 | |
123 | 123 | // We need columns. |
124 | - if ( empty( $columns ) ) { |
|
124 | + if (empty($columns)) { |
|
125 | 125 | return false; |
126 | 126 | } |
127 | 127 | |
128 | - $cols = $this->get_cols( $columns ); |
|
128 | + $cols = $this->get_cols($columns); |
|
129 | 129 | |
130 | 130 | return $cols; |
131 | 131 | } |
@@ -137,41 +137,41 @@ discard block |
||
137 | 137 | * |
138 | 138 | * @return array |
139 | 139 | */ |
140 | - private function get_cols( $columns ) { |
|
140 | + private function get_cols($columns) { |
|
141 | 141 | |
142 | 142 | $cols = array(); |
143 | 143 | |
144 | - foreach ( $columns as $key => $value ) { |
|
144 | + foreach ($columns as $key => $value) { |
|
145 | 145 | |
146 | - switch ( $key ) { |
|
146 | + switch ($key) { |
|
147 | 147 | case 'full_name' : |
148 | - $cols['full_name'] = esc_html__( 'Full Name', 'give' ); |
|
148 | + $cols['full_name'] = esc_html__('Full Name', 'give'); |
|
149 | 149 | break; |
150 | 150 | case 'email' : |
151 | - $cols['email'] = esc_html__( 'Email Address', 'give' ); |
|
151 | + $cols['email'] = esc_html__('Email Address', 'give'); |
|
152 | 152 | break; |
153 | 153 | case 'address' : |
154 | - $cols['address_line1'] = esc_html__( 'Address', 'give' ); |
|
155 | - $cols['address_line2'] = esc_html__( 'Address 2', 'give' ); |
|
156 | - $cols['address_city'] = esc_html__( 'City', 'give' ); |
|
157 | - $cols['address_state'] = esc_html__( 'State', 'give' ); |
|
158 | - $cols['address_zip'] = esc_html__( 'Zip', 'give' ); |
|
159 | - $cols['address_country'] = esc_html__( 'Country', 'give' ); |
|
154 | + $cols['address_line1'] = esc_html__('Address', 'give'); |
|
155 | + $cols['address_line2'] = esc_html__('Address 2', 'give'); |
|
156 | + $cols['address_city'] = esc_html__('City', 'give'); |
|
157 | + $cols['address_state'] = esc_html__('State', 'give'); |
|
158 | + $cols['address_zip'] = esc_html__('Zip', 'give'); |
|
159 | + $cols['address_country'] = esc_html__('Country', 'give'); |
|
160 | 160 | break; |
161 | 161 | case 'userid' : |
162 | - $cols['userid'] = esc_html__( 'User ID', 'give' ); |
|
162 | + $cols['userid'] = esc_html__('User ID', 'give'); |
|
163 | 163 | break; |
164 | 164 | case 'donation_form' : |
165 | - $cols['donation_form'] = esc_html__( 'Donation Form', 'give' ); |
|
165 | + $cols['donation_form'] = esc_html__('Donation Form', 'give'); |
|
166 | 166 | break; |
167 | 167 | case 'date_first_donated' : |
168 | - $cols['date_first_donated'] = esc_html__( 'First Donation Date', 'give' ); |
|
168 | + $cols['date_first_donated'] = esc_html__('First Donation Date', 'give'); |
|
169 | 169 | break; |
170 | 170 | case 'donations' : |
171 | - $cols['donations'] = esc_html__( 'Number of Donations', 'give' ); |
|
171 | + $cols['donations'] = esc_html__('Number of Donations', 'give'); |
|
172 | 172 | break; |
173 | 173 | case 'donation_sum' : |
174 | - $cols['donation_sum'] = esc_html__( 'Sum of Donations', 'give' ); |
|
174 | + $cols['donation_sum'] = esc_html__('Sum of Donations', 'give'); |
|
175 | 175 | break; |
176 | 176 | } |
177 | 177 | } |
@@ -192,29 +192,29 @@ discard block |
||
192 | 192 | $i = 0; |
193 | 193 | |
194 | 194 | $data = array(); |
195 | - $cached_donor_ids = Give_Cache::get( $this->query_id, true ); |
|
195 | + $cached_donor_ids = Give_Cache::get($this->query_id, true); |
|
196 | 196 | |
197 | - if ( ! empty( $this->form ) ) { |
|
197 | + if ( ! empty($this->form)) { |
|
198 | 198 | |
199 | 199 | // Export donors for a specific donation form and also within specified timeframe |
200 | 200 | $args = array( |
201 | 201 | 'output' => 'payments', // Use 'posts' to get standard post objects |
202 | - 'post_type' => array( 'give_payment' ), |
|
202 | + 'post_type' => array('give_payment'), |
|
203 | 203 | 'number' => 30, |
204 | 204 | 'paged' => $this->step, |
205 | 205 | 'status' => 'publish', |
206 | 206 | 'meta_key' => '_give_payment_form_id', |
207 | - 'meta_value' => absint( $this->form ), |
|
207 | + 'meta_value' => absint($this->form), |
|
208 | 208 | ); |
209 | 209 | |
210 | 210 | // Check for date option filter |
211 | - if ( ! empty( $this->data['donor_export_start_date'] ) || ! empty( $this->data['donor_export_end_date'] ) ) { |
|
212 | - $args['start_date'] = ! empty( $this->data['donor_export_start_date'] ) ? date( 'Y-n-d 00:00:00', strtotime( $this->data['donor_export_start_date'] ) ) : date( 'Y-n-d 23:59:59', '1970-1-01 00:00:00' ); |
|
213 | - $args['end_date'] = ! empty( $this->data['donor_export_end_date'] ) ? date( 'Y-n-d 23:59:59', strtotime( $this->data['donor_export_end_date'] ) ) : date( 'Y-n-d 23:59:59', current_time( 'timestamp' ) ); |
|
211 | + if ( ! empty($this->data['donor_export_start_date']) || ! empty($this->data['donor_export_end_date'])) { |
|
212 | + $args['start_date'] = ! empty($this->data['donor_export_start_date']) ? date('Y-n-d 00:00:00', strtotime($this->data['donor_export_start_date'])) : date('Y-n-d 23:59:59', '1970-1-01 00:00:00'); |
|
213 | + $args['end_date'] = ! empty($this->data['donor_export_end_date']) ? date('Y-n-d 23:59:59', strtotime($this->data['donor_export_end_date'])) : date('Y-n-d 23:59:59', current_time('timestamp')); |
|
214 | 214 | } |
215 | 215 | |
216 | 216 | // Check for price option. |
217 | - if ( null !== $this->price_id ) { |
|
217 | + if (null !== $this->price_id) { |
|
218 | 218 | $args['meta_query'] = array( |
219 | 219 | array( |
220 | 220 | 'key' => '_give_payment_price_id', |
@@ -223,45 +223,43 @@ discard block |
||
223 | 223 | ); |
224 | 224 | } |
225 | 225 | |
226 | - $payments_query = new Give_Payments_Query( $args ); |
|
226 | + $payments_query = new Give_Payments_Query($args); |
|
227 | 227 | $payments = $payments_query->get_payments(); |
228 | 228 | |
229 | - if ( $payments ) { |
|
229 | + if ($payments) { |
|
230 | 230 | /* @var Give_Payment $payment */ |
231 | - foreach ( $payments as $payment ) { |
|
231 | + foreach ($payments as $payment) { |
|
232 | 232 | // Set donation sum. |
233 | - $this->payment_stats[ $payment->customer_id ]['donation_sum'] = isset( $this->payment_stats[ $payment->customer_id ]['donation_sum'] ) ? |
|
234 | - $this->payment_stats[ $payment->customer_id ]['donation_sum'] : |
|
235 | - 0; |
|
236 | - $this->payment_stats[ $payment->customer_id ]['donation_sum'] += $payment->total; |
|
233 | + $this->payment_stats[$payment->customer_id]['donation_sum'] = isset($this->payment_stats[$payment->customer_id]['donation_sum']) ? |
|
234 | + $this->payment_stats[$payment->customer_id]['donation_sum'] : 0; |
|
235 | + $this->payment_stats[$payment->customer_id]['donation_sum'] += $payment->total; |
|
237 | 236 | |
238 | 237 | // Set donation count. |
239 | - $this->payment_stats[ $payment->customer_id ]['donations'] = isset( $this->payment_stats[ $payment->customer_id ]['donations'] ) ? |
|
240 | - ++ $this->payment_stats[ $payment->customer_id ]['donations'] : |
|
241 | - 1; |
|
238 | + $this->payment_stats[$payment->customer_id]['donations'] = isset($this->payment_stats[$payment->customer_id]['donations']) ? |
|
239 | + ++$this->payment_stats[$payment->customer_id]['donations'] : 1; |
|
242 | 240 | |
243 | 241 | // Set donation form name. |
244 | - $this->payment_stats[ $payment->customer_id ]['form_title'] = $payment->form_title; |
|
242 | + $this->payment_stats[$payment->customer_id]['form_title'] = $payment->form_title; |
|
245 | 243 | |
246 | 244 | // Continue if donor already included. |
247 | - if ( empty( $payment->customer_id ) || |
|
248 | - in_array( $payment->customer_id, $cached_donor_ids ) |
|
245 | + if (empty($payment->customer_id) || |
|
246 | + in_array($payment->customer_id, $cached_donor_ids) |
|
249 | 247 | ) { |
250 | 248 | continue; |
251 | 249 | } |
252 | 250 | |
253 | 251 | $this->donor_ids[] = $cached_donor_ids[] = $payment->customer_id; |
254 | 252 | |
255 | - $i ++; |
|
253 | + $i++; |
|
256 | 254 | } |
257 | 255 | |
258 | - if ( ! empty( $this->donor_ids ) ) { |
|
259 | - foreach ( $this->donor_ids as $donor_id ) { |
|
260 | - $donor = Give()->donors->get_donor_by( 'id', $donor_id ); |
|
261 | - $donor->donation_form_title = $this->payment_stats[ $donor_id ]['form_title']; |
|
262 | - $donor->purchase_count = $this->payment_stats[ $donor_id ]['donations']; |
|
263 | - $donor->purchase_value = $this->payment_stats[ $donor_id ]['donation_sum']; |
|
264 | - $data[] = $this->set_donor_data( $i, $data, $donor ); |
|
256 | + if ( ! empty($this->donor_ids)) { |
|
257 | + foreach ($this->donor_ids as $donor_id) { |
|
258 | + $donor = Give()->donors->get_donor_by('id', $donor_id); |
|
259 | + $donor->donation_form_title = $this->payment_stats[$donor_id]['form_title']; |
|
260 | + $donor->purchase_count = $this->payment_stats[$donor_id]['donations']; |
|
261 | + $donor->purchase_value = $this->payment_stats[$donor_id]['donation_sum']; |
|
262 | + $data[] = $this->set_donor_data($i, $data, $donor); |
|
265 | 263 | } |
266 | 264 | |
267 | 265 | // Cache donor ids only if admin export donor for specific form. |
@@ -271,7 +269,7 @@ discard block |
||
271 | 269 | } else { |
272 | 270 | |
273 | 271 | // Export all donors. |
274 | - $offset = 30 * ( $this->step - 1 ); |
|
272 | + $offset = 30 * ($this->step - 1); |
|
275 | 273 | |
276 | 274 | $args = array( |
277 | 275 | 'number' => 30, |
@@ -279,31 +277,31 @@ discard block |
||
279 | 277 | ); |
280 | 278 | |
281 | 279 | // Check for date option filter |
282 | - if ( ! empty( $this->data['donor_export_start_date'] ) || ! empty( $this->data['donor_export_end_date'] ) ) { |
|
280 | + if ( ! empty($this->data['donor_export_start_date']) || ! empty($this->data['donor_export_end_date'])) { |
|
283 | 281 | $args['date'] = array( |
284 | - 'start' => ! empty( $this->data['donor_export_start_date'] ) ? date( 'Y-n-d 00:00:00', strtotime( $this->data['donor_export_start_date'] ) ) : date( 'Y-n-d 23:59:59', '1970-1-01 00:00:00' ), |
|
285 | - 'end' => ! empty( $this->data['donor_export_end_date'] ) ? date( 'Y-n-d 23:59:59', strtotime( $this->data['donor_export_end_date'] ) ) : date( 'Y-n-d 23:59:59', current_time( 'timestamp' ) ), |
|
282 | + 'start' => ! empty($this->data['donor_export_start_date']) ? date('Y-n-d 00:00:00', strtotime($this->data['donor_export_start_date'])) : date('Y-n-d 23:59:59', '1970-1-01 00:00:00'), |
|
283 | + 'end' => ! empty($this->data['donor_export_end_date']) ? date('Y-n-d 23:59:59', strtotime($this->data['donor_export_end_date'])) : date('Y-n-d 23:59:59', current_time('timestamp')), |
|
286 | 284 | ); |
287 | 285 | } |
288 | 286 | |
289 | - $donors = Give()->donors->get_donors( $args ); |
|
287 | + $donors = Give()->donors->get_donors($args); |
|
290 | 288 | |
291 | - foreach ( $donors as $donor ) { |
|
289 | + foreach ($donors as $donor) { |
|
292 | 290 | |
293 | 291 | // Continue if donor already included. |
294 | - if ( empty( $donor->id ) || empty( $donor->payment_ids ) ) { |
|
292 | + if (empty($donor->id) || empty($donor->payment_ids)) { |
|
295 | 293 | continue; |
296 | 294 | } |
297 | 295 | |
298 | - $payment = new Give_Payment( $donor->payment_ids ); |
|
296 | + $payment = new Give_Payment($donor->payment_ids); |
|
299 | 297 | $donor->donation_form_title = $payment->form_title; |
300 | - $data[] = $this->set_donor_data( $i, $data, $donor ); |
|
301 | - $i ++; |
|
298 | + $data[] = $this->set_donor_data($i, $data, $donor); |
|
299 | + $i++; |
|
302 | 300 | } |
303 | 301 | }// End if(). |
304 | 302 | |
305 | - $data = apply_filters( 'give_export_get_data', $data ); |
|
306 | - $data = apply_filters( "give_export_get_data_{$this->export_type}", $data ); |
|
303 | + $data = apply_filters('give_export_get_data', $data); |
|
304 | + $data = apply_filters("give_export_get_data_{$this->export_type}", $data); |
|
307 | 305 | |
308 | 306 | return $data; |
309 | 307 | } |
@@ -319,18 +317,18 @@ discard block |
||
319 | 317 | $percentage = 0; |
320 | 318 | |
321 | 319 | // We can't count the number when getting them for a specific form. |
322 | - if ( empty( $this->form ) ) { |
|
320 | + if (empty($this->form)) { |
|
323 | 321 | |
324 | 322 | $total = Give()->donors->count(); |
325 | 323 | |
326 | - if ( $total > 0 ) { |
|
324 | + if ($total > 0) { |
|
327 | 325 | |
328 | - $percentage = ( ( 30 * $this->step ) / $total ) * 100; |
|
326 | + $percentage = ((30 * $this->step) / $total) * 100; |
|
329 | 327 | |
330 | 328 | } |
331 | 329 | } |
332 | 330 | |
333 | - if ( $percentage > 100 ) { |
|
331 | + if ($percentage > 100) { |
|
334 | 332 | $percentage = 100; |
335 | 333 | } |
336 | 334 | |
@@ -346,51 +344,51 @@ discard block |
||
346 | 344 | * |
347 | 345 | * @return mixed |
348 | 346 | */ |
349 | - private function set_donor_data( $i, $data, $donor ) { |
|
347 | + private function set_donor_data($i, $data, $donor) { |
|
350 | 348 | |
351 | 349 | $columns = $this->csv_cols(); |
352 | 350 | |
353 | 351 | // Set address variable |
354 | 352 | $address = ''; |
355 | - if ( isset( $donor->user_id ) && $donor->user_id > 0 ) { |
|
356 | - $address = give_get_donor_address( $donor->user_id ); |
|
353 | + if (isset($donor->user_id) && $donor->user_id > 0) { |
|
354 | + $address = give_get_donor_address($donor->user_id); |
|
357 | 355 | } |
358 | 356 | |
359 | 357 | // Set columns |
360 | - if ( ! empty( $columns['full_name'] ) ) { |
|
361 | - $data[ $i ]['full_name'] = $donor->name; |
|
358 | + if ( ! empty($columns['full_name'])) { |
|
359 | + $data[$i]['full_name'] = $donor->name; |
|
362 | 360 | } |
363 | - if ( ! empty( $columns['email'] ) ) { |
|
364 | - $data[ $i ]['email'] = $donor->email; |
|
361 | + if ( ! empty($columns['email'])) { |
|
362 | + $data[$i]['email'] = $donor->email; |
|
365 | 363 | } |
366 | - if ( ! empty( $columns['address_line1'] ) ) { |
|
367 | - |
|
368 | - $data[ $i ]['address_line1'] = isset( $address['line1'] ) ? $address['line1'] : ''; |
|
369 | - $data[ $i ]['address_line2'] = isset( $address['line2'] ) ? $address['line2'] : ''; |
|
370 | - $data[ $i ]['address_city'] = isset( $address['city'] ) ? $address['city'] : ''; |
|
371 | - $data[ $i ]['address_state'] = isset( $address['state'] ) ? $address['state'] : ''; |
|
372 | - $data[ $i ]['address_zip'] = isset( $address['zip'] ) ? $address['zip'] : ''; |
|
373 | - $data[ $i ]['address_country'] = isset( $address['country'] ) ? $address['country'] : ''; |
|
364 | + if ( ! empty($columns['address_line1'])) { |
|
365 | + |
|
366 | + $data[$i]['address_line1'] = isset($address['line1']) ? $address['line1'] : ''; |
|
367 | + $data[$i]['address_line2'] = isset($address['line2']) ? $address['line2'] : ''; |
|
368 | + $data[$i]['address_city'] = isset($address['city']) ? $address['city'] : ''; |
|
369 | + $data[$i]['address_state'] = isset($address['state']) ? $address['state'] : ''; |
|
370 | + $data[$i]['address_zip'] = isset($address['zip']) ? $address['zip'] : ''; |
|
371 | + $data[$i]['address_country'] = isset($address['country']) ? $address['country'] : ''; |
|
374 | 372 | } |
375 | - if ( ! empty( $columns['userid'] ) ) { |
|
376 | - $data[ $i ]['userid'] = ! empty( $donor->user_id ) ? $donor->user_id : ''; |
|
373 | + if ( ! empty($columns['userid'])) { |
|
374 | + $data[$i]['userid'] = ! empty($donor->user_id) ? $donor->user_id : ''; |
|
377 | 375 | } |
378 | - if ( ! empty( $columns['donation_form'] ) ) { |
|
379 | - $data[ $i ]['donation_form'] = ! empty( $donor->donation_form_title ) ? $donor->donation_form_title : ''; |
|
376 | + if ( ! empty($columns['donation_form'])) { |
|
377 | + $data[$i]['donation_form'] = ! empty($donor->donation_form_title) ? $donor->donation_form_title : ''; |
|
380 | 378 | } |
381 | - if ( ! empty( $columns['date_first_donated'] ) ) { |
|
382 | - $data[ $i ]['date_first_donated'] = date_i18n( give_date_format(), strtotime( $donor->date_created ) ); |
|
379 | + if ( ! empty($columns['date_first_donated'])) { |
|
380 | + $data[$i]['date_first_donated'] = date_i18n(give_date_format(), strtotime($donor->date_created)); |
|
383 | 381 | } |
384 | - if ( ! empty( $columns['donations'] ) ) { |
|
385 | - $data[ $i ]['donations'] = $donor->purchase_count; |
|
382 | + if ( ! empty($columns['donations'])) { |
|
383 | + $data[$i]['donations'] = $donor->purchase_count; |
|
386 | 384 | } |
387 | - if ( ! empty( $columns['donation_sum'] ) ) { |
|
388 | - $data[ $i ]['donation_sum'] = give_format_amount( $donor->purchase_value, array( 'sanitize' => false ) ); |
|
385 | + if ( ! empty($columns['donation_sum'])) { |
|
386 | + $data[$i]['donation_sum'] = give_format_amount($donor->purchase_value, array('sanitize' => false)); |
|
389 | 387 | } |
390 | 388 | |
391 | - $data[ $i ] = apply_filters( 'give_export_set_donor_data', $data[ $i ], $donor ); |
|
389 | + $data[$i] = apply_filters('give_export_set_donor_data', $data[$i], $donor); |
|
392 | 390 | |
393 | - return $data[ $i ]; |
|
391 | + return $data[$i]; |
|
394 | 392 | |
395 | 393 | } |
396 | 394 | |
@@ -400,9 +398,9 @@ discard block |
||
400 | 398 | * @param array $request |
401 | 399 | * @param Give_Batch_Export $export |
402 | 400 | */ |
403 | - public function unset_properties( $request, $export ) { |
|
404 | - if ( $export->done ) { |
|
405 | - Give_Cache::delete( "give_cache_{$this->query_id}" ); |
|
401 | + public function unset_properties($request, $export) { |
|
402 | + if ($export->done) { |
|
403 | + Give_Cache::delete("give_cache_{$this->query_id}"); |
|
406 | 404 | } |
407 | 405 | } |
408 | 406 | } |
409 | 407 | \ No newline at end of file |