Test Failed
Push — issues/2980 ( 6931f9 )
by Ravinder
05:32
created

Give_Export_Donations::html()   B

Complexity

Conditions 2
Paths 2

Size

Total Lines 259
Code Lines 82

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 82
nc 2
nop 0
dl 0
loc 259
rs 8.2857
c 0
b 0
f 0

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
/**
3
 * Give Export Donations Settings
4
 *
5
 * @package     Give
6
 * @subpackage  Classes/Give_Settings_Data
7
 * @copyright   Copyright (c) 2016, WordImpress
8
 * @license     http://opensource.org/licenses/gpl-2.0.php GNU Public License
9
 * @since       2.1
10
 */
11
12
if ( ! defined( 'ABSPATH' ) ) {
13
	exit; // Exit if accessed directly
14
}
15
16
if ( ! class_exists( 'Give_Export_Donations' ) ) {
17
18
	/**
19
	 * Give_Settings_CSV.
20
	 *
21
	 * @sine 2.1
22
	 */
23
	final class Give_Export_Donations {
24
		/**
25
		 * Importer type
26
		 *
27
		 * @since 2.1
28
		 * @var string
29
		 */
30
		private $exporter_type = 'export_donations';
31
32
		/**
33
		 * Instance.
34
		 *
35
		 * @since 2.1
36
		 */
37
		static private $instance;
38
39
		/**
40
		 * Singleton pattern.
41
		 *
42
		 * @since 2.1
43
		 *
44
		 * @access private
45
		 */
46
		private function __construct() {
47
		}
48
49
		/**
50
		 * Get instance.
51
		 *
52
		 * @since 2.1
53
		 *
54
		 * @access public
55
		 *
56
		 * @return static
57
		 */
58
		public static function get_instance() {
59
			if ( null === static::$instance ) {
60
				self::$instance = new static();
61
			}
62
63
			return self::$instance;
64
		}
65
66
		/**
67
		 * Setup
68
		 *
69
		 * @since 2.1
70
		 *
71
		 * @return void
72
		 */
73
		public function setup() {
74
			$this->setup_hooks();
75
		}
76
77
78
		/**
79
		 * Setup Hooks.
80
		 *
81
		 * @since 2.1
82
		 *
83
		 * @return void
84
		 */
85
		private function setup_hooks() {
86
			if ( ! $this->is_donations_export_page() ) {
87
				return;
88
			}
89
90
			// Do not render main export tools page.
91
			remove_action( 'give_admin_field_tools_export', array(
92
				'Give_Settings_Export',
93
				'render_export_field'
0 ignored issues
show
introduced by
Comma required after last value in array declaration
Loading history...
94
			), 10 );
95
96
			// Render donation export page
97
			add_action( 'give_admin_field_tools_export', array( $this, 'render_page' ) );
98
99
			// Print the HTML.
100
			add_action( 'give_tools_export_donations_form_start', array( $this, 'html' ) );
101
		}
102
103
		/**
104
		 * Print the HTML for core setting exporter.
105
		 *
106
		 * @since 2.1
107
		 */
108
		public function html() {
109
			?>
110
			<section>
111
				<table class="widefat export-options-table give-table">
112
					<tbody>
113
					<tr class="top">
114
						<td colspan="2">
115
							<h2 id="give-export-title"><?php _e( 'Export Donation History and Custom Fields to CSV', 'give' ) ?></h2>
116
							<p class="give-field-description"><?php _e( 'Download an export of donors for specific donation forms with the option to include custom fields.', 'give' ) ?></p>
117
						</th>
118
					</tr>
119
120
					<tr>
121
						<td scope="row" class="row-title">
122
							<label
123
								for="give-form-for-csv-export"><?php _e( 'Filter by Donation Form:', 'give' ); ?></label>
124
						</th>
125
						<td class="give-field-wrap">
126
							<div class="give-clearfix give-clearfix">
127
								<?php
128
								$args = array(
129
									'name'        => 'forms',
130
									'id'          => 'give-form-for-csv-export',
131
									'chosen'      => true,
132
									'number'      => - 1,
133
									'placeholder' => esc_attr__( 'All Forms', 'give' ),
134
								);
135
								echo Give()->html->forms_dropdown( $args );
0 ignored issues
show
introduced by
Expected a sanitizing function (see Codex for 'Data Validation'), but instead saw 'Give'
Loading history...
136
								?>
137
							</div>
138
						</td>
139
					</tr>
140
141
					<tr>
142
						<td scope="row" class="row-title">
143
							<label for="give-payment-export-start"><?php _e( 'Filter by Date:', 'give' ); ?></label>
144
						</td>
145
						<td class="give-field-wrap">
146
							<div class="give-clearfix give-clearfix">
147
								<?php
148
								$args = array(
149
									'id'          => 'give-payment-export-start',
150
									'name'        => 'start',
151
									'placeholder' => esc_attr__( 'Start date', 'give' ),
152
								);
153
								echo Give()->html->date_field( $args ); ?>
0 ignored issues
show
introduced by
Expected a sanitizing function (see Codex for 'Data Validation'), but instead saw 'Give'
Loading history...
154
								<?php
155
								$args = array(
156
									'id'          => 'give-payment-export-end',
157
									'name'        => 'end',
158
									'placeholder' => esc_attr__( 'End date', 'give' ),
159
								);
160
								echo Give()->html->date_field( $args ); ?>
0 ignored issues
show
introduced by
Expected a sanitizing function (see Codex for 'Data Validation'), but instead saw 'Give'
Loading history...
161
							</div>
162
						</td>
163
					</tr>
164
165
					<tr>
166
						<td scope="row" class="row-title">
167
							<label
168
								for="give-export-donations-status"><?php _e( 'Filter by Status:', 'give' ); ?></label>
169
						</th>
170
						<td>
171
							<div class="give-clearfix give-clearfix">
172
								<select name="status" id="give-export-donations-status">
173
									<option value="any"><?php _e( 'All Statuses', 'give' ); ?></option>
174
									<?php
175
									$statuses = give_get_payment_statuses();
176
									foreach ( $statuses as $status => $label ) {
177
										echo '<option value="' . $status . '">' . $label . '</option>';
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not '$status'
Loading history...
introduced by
Expected next thing to be a escaping function, not '$label'
Loading history...
178
									}
179
									?>
180
								</select>
181
							</div>
182
						</td>
183
					</tr>
184
185
					<tr>
186
						<td scope="row" class="row-title">
187
							<label><?php _e( 'Standard Columns:', 'give' ); ?></label>
188
						</th>
189
						<td>
190
							<div class="give-clearfix give-clearfix">
191
								<ul class="give-export-option-ul">
192
									<li>
193
										<label for="give-export-donation-id">
194
											<input type="checkbox" checked
195
											       name="give_give_donations_export_option[donation_id]"
196
											       id="give-export-donation-id"><?php _e( 'Donation ID', 'give' ); ?>
197
										</label>
198
									</li>
199
									<li>
200
										<label for="give-export-first-name">
201
											<input type="checkbox" checked
202
											       name="give_give_donations_export_option[first_name]"
203
											       id="give-export-first-name"><?php _e( 'Donor\'s First Name', 'give' ); ?>
204
										</label>
205
									</li>
206
									<li>
207
										<label for="give-export-last-name">
208
											<input type="checkbox" checked
209
											       name="give_give_donations_export_option[last_name]"
210
											       id="give-export-last-name"><?php _e( 'Donor\'s Last Name', 'give' ); ?>
211
										</label>
212
									</li>
213
									<li>
214
										<label for="give-export-email">
215
											<input type="checkbox" checked
216
											       name="give_give_donations_export_option[email]"
217
											       id="give-export-email"><?php _e( 'Donor\'s Email', 'give' ); ?>
218
										</label>
219
									</li>
220
									<li>
221
										<label for="give-export-address">
222
											<input type="checkbox" checked
223
											       name="give_give_donations_export_option[address]"
224
											       id="give-export-address"><?php _e( 'Donor\'s Billing Address', 'give' ); ?>
225
										</label>
226
									</li>
227
									<li>
228
										<label for="give-export-donation-sum">
229
											<input type="checkbox" checked
230
											       name="give_give_donations_export_option[donation_total]"
231
											       id="give-export-donation-sum"><?php _e( 'Donation Total', 'give' ); ?>
232
										</label>
233
									</li>
234
									<li>
235
										<label for="give-export-donation-status">
236
											<input type="checkbox" checked
237
											       name="give_give_donations_export_option[donation_status]"
238
											       id="give-export-donation-status"><?php _e( 'Donation Status', 'give' ); ?>
239
										</label>
240
									</li>
241
									<li>
242
										<label for="give-export-payment-gateway">
243
											<input type="checkbox" checked
244
											       name="give_give_donations_export_option[payment_gateway]"
245
											       id="give-export-payment-gateway"><?php _e( 'Payment Gateway', 'give' ); ?>
246
										</label>
247
									</li>
248
									<li>
249
										<label for="give-export-donation-form-id">
250
											<input type="checkbox" checked
251
											       name="give_give_donations_export_option[form_id]"
252
											       id="give-export-donation-form-id"><?php _e( 'Donation Form ID', 'give' ); ?>
253
										</label>
254
									</li>
255
									<li>
256
										<label for="give-export-donation-form-title">
257
											<input type="checkbox" checked
258
											       name="give_give_donations_export_option[form_title]"
259
											       id="give-export-donation-form-title"><?php _e( 'Donation Form Title', 'give' ); ?>
260
										</label>
261
									</li>
262
									<li>
263
										<label for="give-export-donation-form-level-id">
264
											<input type="checkbox" checked
265
											       name="give_give_donations_export_option[form_level_id]"
266
											       id="give-export-donation-form-level-id"><?php _e( 'Donation Form Level ID', 'give' ); ?>
267
										</label>
268
									</li>
269
									<li>
270
										<label for="give-export-donation-form-level-title">
271
											<input type="checkbox" checked
272
											       name="give_give_donations_export_option[form_level_title]"
273
											       id="give-export-donation-form-level-title"><?php _e( 'Donation Form Level Title', 'give' ); ?>
274
										</label>
275
									</li>
276
									<li>
277
										<label for="give-export-donation-date">
278
											<input type="checkbox" checked
279
											       name="give_give_donations_export_option[donation_date]"
280
											       id="give-export-donation-date"><?php _e( 'Donation Date', 'give' ); ?>
281
										</label>
282
									</li>
283
									<li>
284
										<label for="give-export-donation-time">
285
											<input type="checkbox" checked
286
											       name="give_give_donations_export_option[donation_time]"
287
											       id="give-export-donation-time"><?php _e( 'Donation Time', 'give' ); ?>
288
										</label>
289
									</li>
290
291
									<li>
292
										<label for="give-export-userid">
293
											<input type="checkbox" checked
294
											       name="give_give_donations_export_option[userid]"
295
											       id="give-export-userid"><?php _e( 'User ID', 'give' ); ?>
296
										</label>
297
									</li>
298
									<li>
299
										<label for="give-export-donorid">
300
											<input type="checkbox" checked
301
											       name="give_give_donations_export_option[donorid]"
302
											       id="give-export-donorid"><?php _e( 'Donor ID', 'give' ); ?>
303
										</label>
304
									</li>
305
									<li>
306
										<label for="give-export-donor-ip">
307
											<input type="checkbox" checked
308
											       name="give_give_donations_export_option[donor_ip]"
309
											       id="give-export-donor-ip"><?php _e( 'Donor IP Address', 'give' ); ?>
310
										</label>
311
									</li>
312
								</ul>
313
							</div>
314
						</td>
315
					</tr>
316
317
					<tr  class="give-hidden give-export-donations-hide give-export-donations-ffm">
318
						<td scope="row" class="row-title">
319
							<label><?php _e( 'Form Field Manager Fields:', 'give' ); ?></label>
320
						</th>
321
						<td class="give-field-wrap">
322
							<div class="give-clearfix give-clearfix">
323
								<ul class="give-export-option-ul"></ul>
324
								<p class="give-field-description"><?php _e( 'The following fields have been created by Form Field Manager.', 'give' ); ?></p>
325
							</div>
326
						</td>
327
					</tr>
328
329
					<tr 
330
					    class="give-hidden give-export-donations-hide give-export-donations-standard-fields">
331
						<td scope="row" class="row-title">
332
							<label><?php _e( 'Custom Field Columns:', 'give' ); ?></label>
333
						</th>
334
						<td class="give-field-wrap">
335
							<div class="give-clearfix give-clearfix">
336
								<ul class="give-export-option-ul"></ul>
337
								<p class="give-field-description"><?php _e( 'The following fields may have been created by custom code, or another plugin.', 'give' ); ?></p>
338
							</div>
339
						</td>
340
					</tr>
341
342
					<tr  class="give-hidden give-export-donations-hide give-export-donations-hidden-fields">
343
						<td scope="row" class="row-title">
344
							<label><?php _e( 'Hidden Custom Field Columns:', 'give' ); ?></label>
345
						</th>
346
						<td class="give-field-wrap">
347
							<div class="give-clearfix give-clearfix">
348
								<ul class="give-export-option-ul"></ul>
349
								<p class="give-field-description"><?php _e( 'The following hidden custom fields contain data created by Give Core, a Give Add-on, another plugin, etc.<br/>Hidden fields are generally used for programming logic, but you may contain data you would like to export.', 'give' ); ?></p>
350
							</div>
351
						</td>
352
					</tr>
353
354
					<tr class="end">
355
						<td></th>
356
						<td>
357
							<?php wp_nonce_field( 'give_ajax_export', 'give_ajax_export' ); ?>
358
							<input type="hidden" name="give-export-class" value="Give_Export_Donations_CSV"/>
359
							<input type="submit" value="Generate CSV" class="button button-primary">
360
						</th>
361
					</tr>
362
					</tbody>
363
				</table>
364
			</section>
365
			<?php
366
		}
367
368
		/**
369
		 * Render donations export page
370
		 *
371
		 * @since 2.1
372
		 */
373
		public function render_page() {
374
			/**
375
			 * Fires before displaying the export div tools.
376
			 *
377
			 * @since 2.1
378
			 */
379
			do_action( 'give_tools_export_donations_main_before' );
380
			?>
381
			<div id="poststuff">
382
				<div class="postbox">
383
					<h1 class="give-export-h1" align="center"><?php _e( 'Export Donations', 'give' ); ?></h1>
384
					<div class="inside give-tools-setting-page-export give-export_donations">
385
						<?php
386
						/**
387
						 * Fires before from start.
388
						 *
389
						 * @since 2.1
390
						 */
391
						do_action( 'give_tools_export_donations_form_before_start' );
392
						?>
393
						<form method="post" id="give-export_donations-form"
394
						      class="give-export-form tools-setting-page-export tools-setting-page-export"
395
						      enctype="multipart/form-data">
396
397
							<?php
398
							/**
399
							 * Fires just after form start.
400
							 *
401
							 * @since 2.1
402
							 */
403
							do_action( 'give_tools_export_donations_form_start' );
404
							?>
405
406
							<?php
407
							/**
408
							 * Fires just after before form end.
409
							 *
410
							 * @since 2.1
411
							 */
412
							do_action( 'give_tools_export_donations_form_end' );
413
							?>
414
						</form>
415
						<?php
416
						/**
417
						 * Fires just after form end.
418
						 *
419
						 * @since 2.1
420
						 */
421
						do_action( 'give_tools_iexport_donations_form_after_end' );
422
						?>
423
					</div><!-- .inside -->
424
				</div><!-- .postbox -->
425
			</div><!-- #poststuff -->
426
			<?php
427
			/**
428
			 * Fires after displaying the export div tools.
429
			 *
430
			 * @since 2.1
431
			 */
432
			do_action( 'give_tools_export_donations_main_after' );
433
		}
434
435
		/**
436
		 * Get if current page export donations page or not
437
		 *
438
		 * @since 2.1
439
		 * @return bool
440
		 */
441
		private function is_donations_export_page() {
442
			return 'export' === give_get_current_setting_tab() && isset( $_GET['type'] ) && $this->exporter_type === give_clean( $_GET['type'] );
0 ignored issues
show
introduced by
Detected access of super global var $_GET, probably need manual inspection.
Loading history...
introduced by
Detected usage of a non-sanitized input variable: $_GET
Loading history...
443
		}
444
	}
445
446
	Give_Export_Donations::get_instance()->setup();
447
}
448