|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* Payments Export Class. |
|
4
|
|
|
* |
|
5
|
|
|
* This class handles payment export in batches. |
|
6
|
|
|
* |
|
7
|
|
|
* @package Give |
|
8
|
|
|
* @subpackage Admin/Reports |
|
9
|
|
|
* @copyright Copyright (c) 2016, WordImpress |
|
10
|
|
|
* @license https://opensource.org/licenses/gpl-license GNU Public License |
|
11
|
|
|
* @since 2.1 |
|
12
|
|
|
*/ |
|
13
|
|
|
|
|
14
|
|
|
// Exit if accessed directly. |
|
15
|
|
|
if ( ! defined( 'ABSPATH' ) ) { |
|
16
|
|
|
exit; |
|
17
|
|
|
} |
|
18
|
|
|
|
|
19
|
|
|
/** |
|
20
|
|
|
* Give_Export_Donations_CSV Class |
|
21
|
|
|
* |
|
22
|
|
|
* @since 2.1 |
|
23
|
|
|
*/ |
|
24
|
|
|
class Give_Export_Donations_CSV extends Give_Batch_Export { |
|
25
|
|
|
|
|
26
|
|
|
/** |
|
27
|
|
|
* Our export type. Used for export-type specific filters/actions. |
|
28
|
|
|
* |
|
29
|
|
|
* @since 2.1 |
|
30
|
|
|
* |
|
31
|
|
|
* @var string |
|
32
|
|
|
*/ |
|
33
|
|
|
public $export_type = 'payments'; |
|
34
|
|
|
|
|
35
|
|
|
/** |
|
36
|
|
|
* Form submission data. |
|
37
|
|
|
* |
|
38
|
|
|
* @since 2.1 |
|
39
|
|
|
* |
|
40
|
|
|
* @var array |
|
41
|
|
|
*/ |
|
42
|
|
|
private $data = array(); |
|
43
|
|
|
|
|
44
|
|
|
/** |
|
45
|
|
|
* Form submission data. |
|
46
|
|
|
* |
|
47
|
|
|
* @since 2.1 |
|
48
|
|
|
* |
|
49
|
|
|
* @var array |
|
50
|
|
|
*/ |
|
51
|
|
|
private $cols = array(); |
|
52
|
|
|
|
|
53
|
|
|
/** |
|
54
|
|
|
* Form ID. |
|
55
|
|
|
* |
|
56
|
|
|
* @since 2.1 |
|
57
|
|
|
* |
|
58
|
|
|
* @var string |
|
59
|
|
|
*/ |
|
60
|
|
|
private $form_id = ''; |
|
61
|
|
|
|
|
62
|
|
|
/** |
|
63
|
|
|
* Form tags ids. |
|
64
|
|
|
* |
|
65
|
|
|
* @since 2.1 |
|
66
|
|
|
* |
|
67
|
|
|
* @var array |
|
68
|
|
|
*/ |
|
69
|
|
|
private $tags = ''; |
|
70
|
|
|
|
|
71
|
|
|
|
|
72
|
|
|
/** |
|
73
|
|
|
* Form categories ids. |
|
74
|
|
|
* |
|
75
|
|
|
* @since 2.1 |
|
76
|
|
|
* |
|
77
|
|
|
* @var array |
|
78
|
|
|
*/ |
|
79
|
|
|
private $categories = ''; |
|
80
|
|
|
|
|
81
|
|
|
/** |
|
82
|
|
|
* Set the properties specific to the export. |
|
83
|
|
|
* |
|
84
|
|
|
* @since 2.1 |
|
85
|
|
|
* |
|
86
|
|
|
* @param array $request The Form Data passed into the batch processing. |
|
87
|
|
|
*/ |
|
88
|
|
|
public function set_properties( $request ) { |
|
89
|
|
|
|
|
90
|
|
|
// Set data from form submission |
|
91
|
|
|
if ( isset( $_POST['form'] ) ) { |
|
|
|
|
|
|
92
|
|
|
parse_str( $_POST['form'], $this->data ); |
|
|
|
|
|
|
93
|
|
|
} |
|
94
|
|
|
|
|
95
|
|
|
$this->form = $this->data['forms']; |
|
96
|
|
|
$this->categories = ! empty( $request['give_forms_categories'] ) ? (array) $request['give_forms_categories'] : array(); |
|
97
|
|
|
$this->tags = ! empty( $request['give_forms_tags'] ) ? (array) $request['give_forms_tags'] : array(); |
|
98
|
|
|
$this->form_id = $this->get_form_ids( $request ); |
|
|
|
|
|
|
99
|
|
|
$this->price_id = isset( $request['give_price_option'] ) && ( 'all' !== $request['give_price_option'] && '' !== $request['give_price_option'] ) ? absint( $request['give_price_option'] ) : null; |
|
100
|
|
|
$this->start = isset( $request['start'] ) ? sanitize_text_field( $request['start'] ) : ''; |
|
101
|
|
|
$this->end = isset( $request['end'] ) ? sanitize_text_field( $request['end'] ) : ''; |
|
102
|
|
|
$this->status = isset( $request['status'] ) ? sanitize_text_field( $request['status'] ) : 'complete'; |
|
103
|
|
|
} |
|
104
|
|
|
|
|
105
|
|
|
/** |
|
106
|
|
|
* Get donation form id list |
|
107
|
|
|
* |
|
108
|
|
|
* @since 2.1 |
|
109
|
|
|
* |
|
110
|
|
|
* @param array $request form data that need to be exported |
|
111
|
|
|
* |
|
112
|
|
|
* @return array|boolean|null $form get all the donation id that need to be exported |
|
113
|
|
|
*/ |
|
114
|
|
|
public function get_form_ids( $request = array() ) { |
|
115
|
|
|
$form = ! empty( $request['forms'] ) && 0 !== $request['forms'] ? absint( $request['forms'] ) : null; |
|
116
|
|
|
|
|
117
|
|
|
$form_ids = ! empty( $request['form_ids'] ) ? sanitize_text_field( $request['form_ids'] ) : null; |
|
118
|
|
|
|
|
119
|
|
|
if ( empty( $form ) && ! empty( $form_ids ) && ( ! empty( $this->categories ) || ! empty( $this->tags ) ) ) { |
|
120
|
|
|
$form = explode( ',', $form_ids ); |
|
121
|
|
|
} |
|
122
|
|
|
|
|
123
|
|
|
return $form; |
|
124
|
|
|
} |
|
125
|
|
|
|
|
126
|
|
|
/** |
|
127
|
|
|
* Set the CSV columns. |
|
128
|
|
|
* |
|
129
|
|
|
* @access public |
|
130
|
|
|
* |
|
131
|
|
|
* @since 2.1 |
|
132
|
|
|
* |
|
133
|
|
|
* @return array|bool $cols All the columns. |
|
134
|
|
|
*/ |
|
135
|
|
|
public function csv_cols() { |
|
136
|
|
|
|
|
137
|
|
|
$columns = isset( $this->data['give_give_donations_export_option'] ) ? $this->data['give_give_donations_export_option'] : array(); |
|
138
|
|
|
|
|
139
|
|
|
// We need columns. |
|
140
|
|
|
if ( empty( $columns ) ) { |
|
141
|
|
|
return false; |
|
142
|
|
|
} |
|
143
|
|
|
|
|
144
|
|
|
$this->cols = $this->get_cols( $columns ); |
|
145
|
|
|
|
|
146
|
|
|
return $this->cols; |
|
147
|
|
|
} |
|
148
|
|
|
|
|
149
|
|
|
|
|
150
|
|
|
/** |
|
151
|
|
|
* CSV file columns. |
|
152
|
|
|
* |
|
153
|
|
|
* @since 2.1 |
|
154
|
|
|
* |
|
155
|
|
|
* @param array $columns |
|
156
|
|
|
* |
|
157
|
|
|
* @return array |
|
158
|
|
|
*/ |
|
159
|
|
|
private function get_cols( $columns ) { |
|
160
|
|
|
|
|
161
|
|
|
$cols = array(); |
|
162
|
|
|
|
|
163
|
|
|
foreach ( $columns as $key => $value ) { |
|
164
|
|
|
|
|
165
|
|
|
switch ( $key ) { |
|
166
|
|
|
case 'donation_id' : |
|
167
|
|
|
$cols['donation_id'] = __( 'Donation ID', 'give' ); |
|
168
|
|
|
break; |
|
169
|
|
|
case 'seq_id' : |
|
170
|
|
|
$cols['seq_id'] = __( 'Donation Number', 'give' ); |
|
171
|
|
|
break; |
|
172
|
|
|
case 'first_name' : |
|
173
|
|
|
$cols['first_name'] = __( 'First Name', 'give' ); |
|
174
|
|
|
break; |
|
175
|
|
|
case 'last_name' : |
|
176
|
|
|
$cols['last_name'] = __( 'Last Name', 'give' ); |
|
177
|
|
|
break; |
|
178
|
|
|
case 'email' : |
|
179
|
|
|
$cols['email'] = __( 'Email Address', 'give' ); |
|
180
|
|
|
break; |
|
181
|
|
|
case 'company' : |
|
182
|
|
|
$cols['company'] = __( 'Company Name', 'give' ); |
|
183
|
|
|
break; |
|
184
|
|
View Code Duplication |
case 'address' : |
|
|
|
|
|
|
185
|
|
|
$cols['address_line1'] = __( 'Address 1', 'give' ); |
|
186
|
|
|
$cols['address_line2'] = __( 'Address 2', 'give' ); |
|
187
|
|
|
$cols['address_city'] = __( 'City', 'give' ); |
|
188
|
|
|
$cols['address_state'] = __( 'State', 'give' ); |
|
189
|
|
|
$cols['address_zip'] = __( 'Zip', 'give' ); |
|
190
|
|
|
$cols['address_country'] = __( 'Country', 'give' ); |
|
191
|
|
|
break; |
|
192
|
|
|
case 'donation_total' : |
|
193
|
|
|
$cols['donation_total'] = __( 'Donation Total', 'give' ); |
|
194
|
|
|
break; |
|
195
|
|
|
case 'currency_code' : |
|
196
|
|
|
$cols['currency_code'] = __( 'Currency Code', 'give' ); |
|
197
|
|
|
break; |
|
198
|
|
|
case 'currency_symbol' : |
|
199
|
|
|
$cols['currency_symbol'] = __( 'Currency Symbol', 'give' ); |
|
200
|
|
|
break; |
|
201
|
|
|
case 'donation_status' : |
|
202
|
|
|
$cols['donation_status'] = __( 'Donation Status', 'give' ); |
|
203
|
|
|
break; |
|
204
|
|
|
case 'payment_gateway' : |
|
205
|
|
|
$cols['payment_gateway'] = __( 'Payment Gateway', 'give' ); |
|
206
|
|
|
break; |
|
207
|
|
|
case 'form_id' : |
|
208
|
|
|
$cols['form_id'] = __( 'Form ID', 'give' ); |
|
209
|
|
|
break; |
|
210
|
|
|
case 'form_title' : |
|
211
|
|
|
$cols['form_title'] = __( 'Form Title', 'give' ); |
|
212
|
|
|
break; |
|
213
|
|
|
case 'form_level_id' : |
|
214
|
|
|
$cols['form_level_id'] = __( 'Level ID', 'give' ); |
|
215
|
|
|
break; |
|
216
|
|
|
case 'form_level_title' : |
|
217
|
|
|
$cols['form_level_title'] = __( 'Level Title', 'give' ); |
|
218
|
|
|
break; |
|
219
|
|
|
case 'donation_date' : |
|
220
|
|
|
$cols['donation_date'] = __( 'Donation Date', 'give' ); |
|
221
|
|
|
break; |
|
222
|
|
|
case 'donation_time' : |
|
223
|
|
|
$cols['donation_time'] = __( 'Donation Time', 'give' ); |
|
224
|
|
|
break; |
|
225
|
|
|
case 'userid' : |
|
226
|
|
|
$cols['userid'] = __( 'User ID', 'give' ); |
|
227
|
|
|
break; |
|
228
|
|
|
case 'donorid' : |
|
229
|
|
|
$cols['donorid'] = __( 'Donor ID', 'give' ); |
|
230
|
|
|
break; |
|
231
|
|
|
case 'donor_ip' : |
|
232
|
|
|
$cols['donor_ip'] = __( 'Donor IP Address', 'give' ); |
|
233
|
|
|
break; |
|
234
|
|
|
default: |
|
235
|
|
|
$cols[ $key ] = $key; |
|
236
|
|
|
|
|
237
|
|
|
} |
|
238
|
|
|
} |
|
239
|
|
|
|
|
240
|
|
|
/** |
|
241
|
|
|
* Filter to get columns name when exporting donation |
|
242
|
|
|
* |
|
243
|
|
|
* @since 2.1 |
|
244
|
|
|
* |
|
245
|
|
|
* @param array $cols columns name for CSV |
|
246
|
|
|
* @param array $columns columns select by admin to export |
|
247
|
|
|
*/ |
|
248
|
|
|
return (array) apply_filters( 'give_export_donation_get_columns_name', $cols, $columns ); |
|
249
|
|
|
} |
|
250
|
|
|
|
|
251
|
|
|
/** |
|
252
|
|
|
* Get the donation argument |
|
253
|
|
|
* |
|
254
|
|
|
* @since 2.1 |
|
255
|
|
|
* |
|
256
|
|
|
* @param array $args donation argument |
|
257
|
|
|
* |
|
258
|
|
|
* @return array $args donation argument |
|
259
|
|
|
*/ |
|
260
|
|
|
public function get_donation_argument( $args = array() ) { |
|
261
|
|
|
$defaults = array( |
|
262
|
|
|
'number' => 30, |
|
263
|
|
|
'page' => $this->step, |
|
264
|
|
|
'status' => $this->status, |
|
265
|
|
|
); |
|
266
|
|
|
// Date query. |
|
267
|
|
|
if ( ! empty( $this->start ) || ! empty( $this->end ) ) { |
|
268
|
|
|
if ( ! empty( $this->start ) ) { |
|
269
|
|
|
$defaults['date_query'][0]['after'] = date( 'Y-n-d 00:00:00', strtotime( $this->start ) ); |
|
270
|
|
|
} |
|
271
|
|
|
if ( ! empty( $this->end ) ) { |
|
272
|
|
|
$defaults['date_query'][0]['before'] = date( 'Y-n-d 00:00:00', strtotime( $this->end ) ); |
|
273
|
|
|
} |
|
274
|
|
|
} |
|
275
|
|
|
|
|
276
|
|
|
if ( ! empty( $this->form_id ) ) { |
|
277
|
|
|
$defaults['give_forms'] = is_array( $this->form_id ) ? $this->form_id : array( $this->form_id ); |
|
278
|
|
|
} |
|
279
|
|
|
|
|
280
|
|
|
return wp_parse_args( $args, $defaults ); |
|
281
|
|
|
} |
|
282
|
|
|
|
|
283
|
|
|
/** |
|
284
|
|
|
* Get the Export Data. |
|
285
|
|
|
* |
|
286
|
|
|
* @access public |
|
287
|
|
|
* |
|
288
|
|
|
* @since 2.1 |
|
289
|
|
|
* |
|
290
|
|
|
* @global object $wpdb Used to query the database using the WordPress database API. |
|
291
|
|
|
* |
|
292
|
|
|
* @return array $data The data for the CSV file. |
|
293
|
|
|
*/ |
|
294
|
|
|
public function get_data() { |
|
295
|
|
|
|
|
296
|
|
|
$data = array(); |
|
297
|
|
|
$i = 0; |
|
298
|
|
|
|
|
299
|
|
|
// Payment query. |
|
300
|
|
|
$payments = give_get_payments( $this->get_donation_argument() ); |
|
301
|
|
|
|
|
302
|
|
|
if ( $payments ) { |
|
|
|
|
|
|
303
|
|
|
|
|
304
|
|
|
foreach ( $payments as $payment ) { |
|
305
|
|
|
|
|
306
|
|
|
$columns = $this->csv_cols(); |
|
307
|
|
|
$payment = new Give_Payment( $payment->ID ); |
|
308
|
|
|
$payment_meta = $payment->payment_meta; |
|
309
|
|
|
$address = $payment->address; |
|
310
|
|
|
|
|
311
|
|
|
// Set columns |
|
312
|
|
|
if ( ! empty( $columns['donation_id'] ) ) { |
|
313
|
|
|
$data[ $i ]['donation_id'] = $payment->ID; |
|
314
|
|
|
} |
|
315
|
|
|
|
|
316
|
|
|
if ( ! empty( $columns['seq_id'] ) ) { |
|
317
|
|
|
$data[ $i ]['seq_id'] = Give()->seq_donation_number->get_serial_code( $payment->ID ); |
|
318
|
|
|
} |
|
319
|
|
|
|
|
320
|
|
View Code Duplication |
if ( ! empty( $columns['first_name'] ) ) { |
|
|
|
|
|
|
321
|
|
|
$data[ $i ]['first_name'] = isset( $payment->first_name ) ? $payment->first_name : ''; |
|
322
|
|
|
} |
|
323
|
|
|
|
|
324
|
|
View Code Duplication |
if ( ! empty( $columns['last_name'] ) ) { |
|
|
|
|
|
|
325
|
|
|
$data[ $i ]['last_name'] = isset( $payment->last_name ) ? $payment->last_name : ''; |
|
326
|
|
|
} |
|
327
|
|
|
|
|
328
|
|
|
if ( ! empty( $columns['email'] ) ) { |
|
329
|
|
|
$data[ $i ]['email'] = $payment->email; |
|
330
|
|
|
} |
|
331
|
|
|
|
|
332
|
|
|
if ( ! empty( $columns['company'] ) ) { |
|
333
|
|
|
$data[ $i ]['company'] = empty( $payment_meta['_give_donation_company'] ) ? '' : str_replace( "\'", "'", $payment_meta['_give_donation_company'] ); |
|
334
|
|
|
} |
|
335
|
|
|
|
|
336
|
|
View Code Duplication |
if ( ! empty( $columns['address_line1'] ) ) { |
|
|
|
|
|
|
337
|
|
|
$data[ $i ]['address_line1'] = isset( $address['line1'] ) ? $address['line1'] : ''; |
|
338
|
|
|
$data[ $i ]['address_line2'] = isset( $address['line2'] ) ? $address['line2'] : ''; |
|
339
|
|
|
$data[ $i ]['address_city'] = isset( $address['city'] ) ? $address['city'] : ''; |
|
340
|
|
|
$data[ $i ]['address_state'] = isset( $address['state'] ) ? $address['state'] : ''; |
|
341
|
|
|
$data[ $i ]['address_zip'] = isset( $address['zip'] ) ? $address['zip'] : ''; |
|
342
|
|
|
$data[ $i ]['address_country'] = isset( $address['country'] ) ? $address['country'] : ''; |
|
343
|
|
|
} |
|
344
|
|
|
|
|
345
|
|
|
if ( ! empty( $columns['donation_total'] ) ) { |
|
346
|
|
|
$data[ $i ]['donation_total'] = give_format_amount( give_donation_amount( $payment->ID ) ); |
|
347
|
|
|
} |
|
348
|
|
|
|
|
349
|
|
|
if ( ! empty( $columns['currency_code'] ) ) { |
|
350
|
|
|
$data[ $i ]['currency_code'] = empty( $payment_meta['_give_payment_currency'] ) ? give_get_currency() : $payment_meta['_give_payment_currency']; |
|
351
|
|
|
} |
|
352
|
|
|
|
|
353
|
|
|
if ( ! empty( $columns['currency_symbol'] ) ) { |
|
354
|
|
|
$currency_code = $data[ $i ]['currency_code']; |
|
355
|
|
|
$data[ $i ]['currency_symbol'] = give_currency_symbol( $currency_code, true ); |
|
|
|
|
|
|
356
|
|
|
} |
|
357
|
|
|
|
|
358
|
|
|
if ( ! empty( $columns['donation_status'] ) ) { |
|
359
|
|
|
$data[ $i ]['donation_status'] = give_get_payment_status( $payment, true ); |
|
360
|
|
|
} |
|
361
|
|
|
|
|
362
|
|
|
if ( ! empty( $columns['payment_gateway'] ) ) { |
|
363
|
|
|
$data[ $i ]['payment_gateway'] = $payment->gateway; |
|
364
|
|
|
} |
|
365
|
|
|
|
|
366
|
|
|
if ( ! empty( $columns['form_id'] ) ) { |
|
367
|
|
|
$data[ $i ]['form_id'] = $payment->form_id; |
|
368
|
|
|
} |
|
369
|
|
|
|
|
370
|
|
|
if ( ! empty( $columns['form_title'] ) ) { |
|
371
|
|
|
$data[ $i ]['form_title'] = get_the_title( $payment->form_id ); |
|
372
|
|
|
} |
|
373
|
|
|
|
|
374
|
|
|
if ( ! empty( $columns['form_level_id'] ) ) { |
|
375
|
|
|
$data[ $i ]['form_level_id'] = $payment->price_id; |
|
376
|
|
|
} |
|
377
|
|
|
|
|
378
|
|
|
if ( ! empty( $columns['form_level_title'] ) ) { |
|
379
|
|
|
$var_prices = give_has_variable_prices( $payment_meta['form_id'] ); |
|
380
|
|
|
if ( empty( $var_prices ) ) { |
|
381
|
|
|
$data[ $i ]['form_level_title'] = ''; |
|
382
|
|
|
} else { |
|
383
|
|
|
$prices_atts = ''; |
|
384
|
|
View Code Duplication |
if ( $variable_prices = give_get_variable_prices( $payment_meta['form_id'] ) ) { |
|
|
|
|
|
|
385
|
|
|
foreach ( $variable_prices as $variable_price ) { |
|
386
|
|
|
$prices_atts[ $variable_price['_give_id']['level_id'] ] = give_format_amount( $variable_price['_give_amount'] ); |
|
387
|
|
|
} |
|
388
|
|
|
} |
|
389
|
|
|
$data[ $i ]['form_level_title'] = give_get_price_option_name( $payment->form_id, $payment->price_id ); |
|
390
|
|
|
} |
|
391
|
|
|
} |
|
392
|
|
|
|
|
393
|
|
|
if ( ! empty( $columns['donation_date'] ) ) { |
|
394
|
|
|
$payment_date = strtotime( $payment->date ); |
|
395
|
|
|
$data[ $i ]['donation_date'] = date( give_date_format(), $payment_date ); |
|
396
|
|
|
} |
|
397
|
|
|
|
|
398
|
|
|
if ( ! empty( $columns['donation_time'] ) ) { |
|
399
|
|
|
$payment_date = strtotime( $payment->date ); |
|
400
|
|
|
$data[ $i ]['donation_time'] = date_i18n( 'H', $payment_date ) . ':' . date( 'i', $payment_date ); |
|
401
|
|
|
} |
|
402
|
|
|
|
|
403
|
|
|
if ( ! empty( $columns['userid'] ) ) { |
|
404
|
|
|
$data[ $i ]['userid'] = $payment->user_id; |
|
405
|
|
|
} |
|
406
|
|
|
|
|
407
|
|
|
if ( ! empty( $columns['donorid'] ) ) { |
|
408
|
|
|
$data[ $i ]['donorid'] = $payment->customer_id; |
|
409
|
|
|
} |
|
410
|
|
|
|
|
411
|
|
|
if ( ! empty( $columns['donor_ip'] ) ) { |
|
412
|
|
|
$data[ $i ]['donor_ip'] = give_get_payment_user_ip( $payment->ID ); |
|
413
|
|
|
} |
|
414
|
|
|
|
|
415
|
|
|
// Add custom field data. |
|
416
|
|
|
// First we remove the standard included keys from above. |
|
417
|
|
|
$remove_keys = array( |
|
418
|
|
|
'donation_id', |
|
419
|
|
|
'seq_id', |
|
420
|
|
|
'first_name', |
|
421
|
|
|
'last_name', |
|
422
|
|
|
'email', |
|
423
|
|
|
'address_line1', |
|
424
|
|
|
'address_line2', |
|
425
|
|
|
'address_city', |
|
426
|
|
|
'address_state', |
|
427
|
|
|
'address_zip', |
|
428
|
|
|
'address_country', |
|
429
|
|
|
'donation_total', |
|
430
|
|
|
'payment_gateway', |
|
431
|
|
|
'form_id', |
|
432
|
|
|
'form_title', |
|
433
|
|
|
'form_level_id', |
|
434
|
|
|
'form_level_title', |
|
435
|
|
|
'donation_date', |
|
436
|
|
|
'donation_time', |
|
437
|
|
|
'userid', |
|
438
|
|
|
'donorid', |
|
439
|
|
|
'donor_ip', |
|
440
|
|
|
); |
|
441
|
|
|
|
|
442
|
|
|
// Removing above keys... |
|
443
|
|
|
foreach ( $remove_keys as $key ) { |
|
444
|
|
|
unset( $columns[ $key ] ); |
|
445
|
|
|
} |
|
446
|
|
|
|
|
447
|
|
|
// Now loop through remaining meta fields. |
|
448
|
|
|
foreach ( $columns as $col ) { |
|
|
|
|
|
|
449
|
|
|
$field_data = get_post_meta( $payment->ID, $col, true ); |
|
450
|
|
|
$data[ $i ][ $col ] = $field_data; |
|
451
|
|
|
unset( $columns[ $col ] ); |
|
452
|
|
|
} |
|
453
|
|
|
|
|
454
|
|
|
/** |
|
455
|
|
|
* Filter to modify Donation CSV data when exporting donation |
|
456
|
|
|
* |
|
457
|
|
|
* @since 2.1 |
|
458
|
|
|
* |
|
459
|
|
|
* @param array Donation data |
|
460
|
|
|
* @param array $payment Donation data |
|
461
|
|
|
* @param array $columns Donation data $columns that are not being merge |
|
462
|
|
|
* @param array Donation columns |
|
463
|
|
|
* |
|
464
|
|
|
* @return array Donation data |
|
465
|
|
|
*/ |
|
466
|
|
|
$data[ $i ] = apply_filters( 'give_export_donation_data', $data[ $i ], $payment, $columns, $this ); |
|
467
|
|
|
|
|
468
|
|
|
$new_data = array(); |
|
469
|
|
|
$old_data = $data[ $i ]; |
|
470
|
|
|
|
|
471
|
|
|
// sorting the columns bas on row |
|
472
|
|
|
foreach ( $this->csv_cols() as $key => $value ) { |
|
|
|
|
|
|
473
|
|
|
if ( array_key_exists( $key, $old_data ) ) { |
|
474
|
|
|
$new_data[ $key ] = $old_data[ $key ]; |
|
475
|
|
|
} |
|
476
|
|
|
} |
|
477
|
|
|
|
|
478
|
|
|
$data[ $i ] = $new_data; |
|
479
|
|
|
|
|
480
|
|
|
// Increment iterator. |
|
481
|
|
|
$i ++; |
|
482
|
|
|
|
|
483
|
|
|
} |
|
484
|
|
|
|
|
485
|
|
|
$data = apply_filters( 'give_export_get_data', $data ); |
|
486
|
|
|
$data = apply_filters( "give_export_get_data_{$this->export_type}", $data ); |
|
487
|
|
|
|
|
488
|
|
|
return $data; |
|
489
|
|
|
|
|
490
|
|
|
} |
|
491
|
|
|
|
|
492
|
|
|
return array(); |
|
493
|
|
|
|
|
494
|
|
|
} |
|
495
|
|
|
|
|
496
|
|
|
/** |
|
497
|
|
|
* Return the calculated completion percentage. |
|
498
|
|
|
* |
|
499
|
|
|
* @since 2.1 |
|
500
|
|
|
* |
|
501
|
|
|
* @return int |
|
502
|
|
|
*/ |
|
503
|
|
|
public function get_percentage_complete() { |
|
504
|
|
|
$args = $this->get_donation_argument( array( 'number' => - 1 ) ); |
|
505
|
|
|
if ( isset( $args['page'] ) ) { |
|
506
|
|
|
unset( $args['page'] ); |
|
507
|
|
|
} |
|
508
|
|
|
$query = give_get_payments( $args ); |
|
509
|
|
|
$total = count( $query ); |
|
510
|
|
|
$percentage = 100; |
|
511
|
|
|
if ( $total > 0 ) { |
|
512
|
|
|
$percentage = ( ( 30 * $this->step ) / $total ) * 100; |
|
513
|
|
|
} |
|
514
|
|
|
if ( $percentage > 100 ) { |
|
515
|
|
|
$percentage = 100; |
|
516
|
|
|
} |
|
517
|
|
|
|
|
518
|
|
|
return $percentage; |
|
519
|
|
|
} |
|
520
|
|
|
|
|
521
|
|
|
/** |
|
522
|
|
|
* Print the CSV rows for the current step. |
|
523
|
|
|
* |
|
524
|
|
|
* @access public |
|
525
|
|
|
* |
|
526
|
|
|
* @since 2.1 |
|
527
|
|
|
* |
|
528
|
|
|
* @return string|false |
|
529
|
|
|
*/ |
|
530
|
|
View Code Duplication |
public function print_csv_rows() { |
|
|
|
|
|
|
531
|
|
|
|
|
532
|
|
|
$row_data = ''; |
|
533
|
|
|
$data = $this->get_data(); |
|
534
|
|
|
$cols = $this->get_csv_cols(); |
|
535
|
|
|
|
|
536
|
|
|
if ( $data ) { |
|
|
|
|
|
|
537
|
|
|
|
|
538
|
|
|
// Output each row |
|
539
|
|
|
foreach ( $data as $row ) { |
|
540
|
|
|
$i = 1; |
|
541
|
|
|
foreach ( $row as $col_id => $column ) { |
|
542
|
|
|
// Make sure the column is valid |
|
543
|
|
|
if ( array_key_exists( $col_id, $cols ) ) { |
|
544
|
|
|
$row_data .= '"' . preg_replace( '/"/', "'", $column ) . '"'; |
|
545
|
|
|
$row_data .= $i == count( $cols ) ? '' : ','; |
|
546
|
|
|
$i ++; |
|
547
|
|
|
} |
|
548
|
|
|
} |
|
549
|
|
|
$row_data .= "\r\n"; |
|
550
|
|
|
} |
|
551
|
|
|
|
|
552
|
|
|
$this->stash_step_data( $row_data ); |
|
553
|
|
|
|
|
554
|
|
|
return $row_data; |
|
555
|
|
|
} |
|
556
|
|
|
|
|
557
|
|
|
return false; |
|
558
|
|
|
} |
|
559
|
|
|
} |