Passed
Push — master ( e53b80...bdf164 )
by Brian
04:19
created

GetPaid_Reports   A

Complexity

Total Complexity 12

Size/Duplication

Total Lines 126
Duplicated Lines 0 %

Importance

Changes 3
Bugs 0 Features 0
Metric Value
eloc 51
c 3
b 0
f 0
dl 0
loc 126
rs 10
wmc 12

7 Methods

Rating   Name   Duplication   Size   Complexity  
A display_exports_tab() 0 4 1
A __construct() 0 5 1
A display_reports_page() 0 42 5
A get_tabs() 0 8 1
A register_reports_page() 0 9 1
A display_reports_tab() 0 4 1
A download_graph() 0 5 2
1
<?php
2
/**
3
 * Contains the reports class
4
 *
5
 *
6
 */
7
8
defined( 'ABSPATH' ) || exit;
9
10
/**
11
 * GetPaid_Reports Class.
12
 */
13
class GetPaid_Reports {
14
15
	/**
16
	 * Class constructor.
17
	 *
18
	 */
19
	public function __construct() {
20
		add_action( 'admin_menu', array( $this, 'register_reports_page' ), 20 );
21
		add_action( 'wpinv_reports_tab_reports', array( $this, 'display_reports_tab' ) );
22
		add_action( 'wpinv_reports_tab_export', array( $this, 'display_exports_tab' ) );
23
		add_action( 'getpaid_authenticated_admin_action_download_graph', array( $this, 'download_graph' ) );
24
	}
25
26
	/**
27
	 * Registers the reports page.
28
	 *
29
	 */
30
	public function register_reports_page() {
31
32
		add_submenu_page(
33
            'wpinv',
34
            __( 'Reports', 'invoicing' ),
35
            __( 'Reports', 'invoicing' ),
36
            wpinv_get_capability(),
37
            'wpinv-reports',
38
            array( $this, 'display_reports_page' )
39
		);
40
41
	}
42
43
	/**
44
	 * Displays the reports page.
45
	 *
46
	 */
47
	public function display_reports_page() {
48
49
		// Prepare variables.
50
		$tabs        = $this->get_tabs();
51
		$current_tab = isset( $_GET['tab'] ) ? sanitize_text_field( $_GET['tab'] ) : 'reports';
52
		$current_tab = array_key_exists( $current_tab, $tabs ) ? $current_tab : 'reports';
53
54
		// Display the current tab.
55
		?>
56
57
        <div class="wrap">
58
59
			<h1><?php echo sanitize_text_field( $tabs[ $current_tab ] ); ?></h1>
60
61
			<nav class="nav-tab-wrapper">
62
63
				<?php
64
					foreach( $tabs as $key => $label ) {
65
66
						$key   = sanitize_text_field( $key );
67
						$label = sanitize_text_field( $label );
68
						$class = $key == $current_tab ? 'nav-tab nav-tab-active' : 'nav-tab';
69
						$url   = esc_url(
70
							add_query_arg( 'tab', $key, admin_url( 'admin.php?page=wpinv-reports' ) )
71
						);
72
73
						echo "\n\t\t\t<a href='$url' class='$class'>$label</a>";
74
75
					}
76
				?>
77
78
			</nav>
79
80
			<div class="bsui <?php echo esc_attr( $current_tab ); ?>">
81
				<?php do_action( "wpinv_reports_tab_{$current_tab}" ); ?>
82
			</div>
83
84
        </div>
85
		<?php
86
87
			wp_enqueue_script( 'chart-js', WPINV_PLUGIN_URL . 'assets/js/chart.bundle.min.js', array( 'jquery' ), '2.9.4', true );
88
			wp_enqueue_style( 'chart-js', WPINV_PLUGIN_URL . 'assets/css/chart.min.css', array(), '2.9.4' );
89
90
	}
91
92
	/**
93
	 * Retrieves reports page tabs.
94
	 *
95
	 * @return array
96
	 */
97
	public function get_tabs() {
98
99
		$tabs = array(
100
			'reports' => __( 'Reports', 'invoicing' ),
101
			'export'  => __( 'Export', 'invoicing' ),
102
		);
103
104
		return apply_filters( 'getpaid_report_tabs', $tabs );
105
	}
106
107
	/**
108
	 * Displays the reports tab.
109
	 *
110
	 */
111
	public function display_reports_tab() {
112
113
		$reports = new GetPaid_Reports_Report();
114
		$reports->display();
115
116
	}
117
118
	/**
119
	 * Displays the exports tab.
120
	 *
121
	 */
122
	public function display_exports_tab() {
123
124
		$exports = new GetPaid_Reports_Export();
0 ignored issues
show
Bug introduced by
The type GetPaid_Reports_Export was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
125
		$exports->display();
126
127
	}
128
129
	/**
130
	 * Donwnloads a graph.
131
	 *
132
	 * @param array $args
133
	 */
134
	public function download_graph( $args ) {
135
136
		if ( ! empty( $args['graph'] ) ) {
137
			$downloader = new GetPaid_Graph_Downloader();
138
			$downloader->download( $args['graph'] );
139
		}
140
141
	}
142
143
}
144