Completed
Pull Request — master (#1907)
by
unknown
19:56
created

Give_Donors_Report   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 110
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
dl 0
loc 110
rs 10
c 0
b 0
f 0
wmc 5
lcom 1
cbo 1

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 9 1
A add_settings_page() 0 5 1
B get_settings() 0 34 1
A output() 0 5 1
A render_report_donors_field() 0 3 1
1
<?php
0 ignored issues
show
Coding Style Compatibility introduced by
For compatibility and reusability of your code, PSR1 recommends that a file should introduce either new symbols (like classes, functions, etc.) or have side-effects (like outputting something, or including other files), but not both at the same time. The first symbol is defined on line 23 and the first side effect is on line 13.

The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.

The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.

To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.

Loading history...
2
/**
3
 * Give Reports Page/Tab
4
 *
5
 * @package     Give
6
 * @subpackage  Classes/Give_Donors_Report
7
 * @copyright   Copyright (c) 2016, WordImpress
8
 * @license     http://opensource.org/licenses/gpl-2.0.php GNU Public License
9
 * @since       1.8
10
 */
11
12
if ( ! defined( 'ABSPATH' ) ) {
13
	exit; // Exit if accessed directly
14
}
15
16
if ( ! class_exists( 'Give_Donors_Report' ) ) :
17
18
	/**
19
	 * Give_Donors_Report.
20
	 *
21
	 * @sine 1.8
22
	 */
23
	class Give_Donors_Report {
24
25
		/**
26
		 * Setting page id.
27
		 *
28
		 * @since 1.8
29
		 * @var   string
30
		 */
31
		protected $id = '';
32
33
		/**
34
		 * Setting page label.
35
		 *
36
		 * @since 1.8
37
		 * @var   string
38
		 */
39
		protected $label = '';
40
41
		/**
42
		 * Constructor.
43
		 */
44
		public function __construct() {
45
			$this->id    = 'donors';
46
			$this->label = esc_html__( 'Donors', 'give' );
47
48
			add_filter( 'give-reports_tabs_array', array( $this, 'add_settings_page' ), 20 );
49
			add_action( "give-reports_settings_{$this->id}_page", array( $this, 'output' ) );
50
			add_action( 'give_admin_field_report_donors', array( $this, 'render_report_donors_field' ), 10, 2 );
51
52
		}
53
54
		/**
55
		 * Add this page to settings.
56
		 *
57
		 * @since  1.8
58
		 * @param  array $pages List of pages.
59
		 * @return array
60
		 */
61
		public function add_settings_page( $pages ) {
62
			$pages[ $this->id ] = $this->label;
63
64
			return $pages;
65
		}
66
67
		/**
68
		 * Get settings array.
69
		 *
70
		 * @since  1.8
71
		 * @return array
72
		 */
73
		public function get_settings() {
74
			// Hide save button.
75
			$GLOBALS['give_hide_save_button'] = true;
76
77
			/**
78
			 * Filter the settings.
79
			 *
80
			 * @since  1.8
81
			 * @param  array $settings
82
			 */
83
			$settings = apply_filters(
84
				'give_get_settings_' . $this->id,
85
				array(
86
					array(
87
						'id'   => 'give_reports_donors',
88
						'type' => 'title',
89
						'table_html' => false
90
					),
91
					array(
92
						'id'   => 'donors',
93
						'name' => esc_html__( 'Donors', 'give' ),
94
						'type' => 'report_donors',
95
					),
96
					array(
97
						'id'   => 'give_reports_donors',
98
						'type' => 'sectionend',
99
						'table_html' => false
100
					)
101
				)
102
			);
103
104
			// Output.
105
			return $settings;
106
		}
107
108
		/**
109
		 * Output the settings.
110
		 *
111
		 * @since  1.8
112
		 * @return void
113
		 */
114
		public function output() {
115
			$settings = $this->get_settings();
116
117
			Give_Admin_Settings::output_fields( $settings, 'give_settings' );
118
		}
119
120
		/**
121
		 * Render report donors field
122
		 *
123
		 * @since  1.8
124
		 * @access public
125
		 *
126
		 * @param $field
127
		 * @param $option_value
128
		 */
129
		public function render_report_donors_field( $field, $option_value ) {
0 ignored issues
show
Unused Code introduced by
The parameter $field is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $option_value is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
130
			do_action( 'give_reports_view_donors');
131
		}
132
	}
133
134
endif;
135
136
return new Give_Donors_Report();
137