PluginProbe ʕ •ᴥ•ʔ
GiveWP – Donation Plugin and Fundraising Platform / 2.27.2
GiveWP – Donation Plugin and Fundraising Platform v2.27.2
4.16.2 4.16.1 4.16.0 4.15.5 4.15.4 4.15.3 4.15.2 4.15.1 4.15.0 2.3.0 2.3.1 2.3.2 2.30.0 2.31.0 2.31.1 2.32.0 2.33.0 2.33.1 2.33.2 2.33.3 2.33.4 2.33.5 2.4.0 2.4.1 2.4.2 2.4.3 2.4.4 2.4.5 2.4.6 2.4.7 2.5.0 2.5.1 2.5.10 2.5.11 2.5.12 2.5.13 2.5.2 2.5.3 2.5.4 2.5.5 2.5.6 2.5.7 2.5.8 2.5.9 2.6.0 2.6.1 2.6.2 2.6.3 2.7.0 2.7.1 2.7.2 2.7.3 2.7.4 2.7.5 2.8.0 2.8.1 2.9.0 2.9.1 2.9.2 2.9.3 2.9.4 2.9.5 2.9.6 2.9.7 3.0.0 3.0.1 3.0.2 3.0.3 3.0.4 3.1.0 3.1.1 3.1.2 3.10.0 3.11.0 3.12.0 3.12.1 3.12.2 3.12.3 3.13.0 3.14.0 3.14.1 3.14.2 3.15.0 3.15.1 3.16.0 3.16.1 3.16.2 3.16.3 3.16.4 3.16.5 3.17.0 3.17.1 3.17.2 3.18.0 3.19.0 3.19.1 3.19.2 3.19.3 3.19.4 3.2.0 3.2.1 3.2.2 3.20.0 3.21.0 3.21.1 3.22.0 3.22.1 3.22.2 3.3.0 3.3.1 3.4.0 3.4.1 3.4.2 3.5.0 3.5.1 3.6.0 3.6.1 3.6.2 3.7.0 3.8.0 3.9.0 4.0.0 4.1.0 4.1.1 4.10.0 4.10.1 4.11.0 4.12.0 4.13.0 4.13.1 4.13.2 4.14.0 4.14.1 4.14.2 4.14.3 4.14.4 4.14.5 4.14.6 4.2.0 4.2.1 4.3.0 4.3.1 4.3.2 4.4.0 4.5.0 4.6.1 4.7.0 4.7.1 4.8.0 4.8.1 4.9.0 trunk 1.9.0 2.0.0 2.0.1 2.0.2 2.0.3 2.0.4 2.0.5 2.0.6 2.0.7 2.1.0 2.1.1 2.1.2 2.1.3 2.1.4 2.1.5 2.1.6 2.1.7 2.1.8 2.10.0 2.10.1 2.10.2 2.10.3 2.10.4 2.11.0 2.11.1 2.11.2 2.11.3 2.12.0 2.12.1 2.12.2 2.12.3 2.13.0 2.13.1 2.13.2 2.13.3 2.13.4 2.14.0 2.15.0 2.16.0 2.16.1 2.17.0 2.17.1 2.17.3 2.18.0 2.18.1 2.19.1 2.19.2 2.19.3 2.19.4 2.19.5 2.19.6 2.19.7 2.19.8 2.2.0 2.2.1 2.2.2 2.2.3 2.2.4 2.2.5 2.2.6 2.20.0 2.20.1 2.20.2 2.21.0 2.21.1 2.21.2 2.21.3 2.21.4 2.22.0 2.22.1 2.22.2 2.22.3 2.23.0 2.23.1 2.23.2 2.24.0 2.24.1 2.24.2 2.25.0 2.25.1 2.25.2 2.25.3 2.26.0 2.27.0 2.27.1 2.27.2 2.27.3 2.28.0 2.29.0 2.29.1 2.29.2
give / includes / admin / reports / class-form-reports-table.php
give / includes / admin / reports Last commit date
class-donor-reports-table.php 6 years ago class-earnings-report.php 5 years ago class-form-reports-table.php 5 years ago class-forms-report.php 7 years ago class-gateways-report.php 7 years ago class-gateways-reports-table.php 4 years ago class-give-graph.php 4 years ago graphing.php 4 years ago reports.php 5 years ago
class-form-reports-table.php
356 lines
1 <?php
2 /**
3 * Download Reports Table Class
4 *
5 * @package Give
6 * @subpackage Admin/Reports
7 * @copyright Copyright (c) 2016, GiveWP
8 * @license https://opensource.org/licenses/gpl-license GNU Public License
9 * @since 1.0
10 */
11
12 // Exit if accessed directly.
13 if ( ! defined( 'ABSPATH' ) ) {
14 exit;
15 }
16
17 // Load WP_List_Table if not loaded
18 if ( ! class_exists( 'WP_List_Table' ) ) {
19 require_once ABSPATH . 'wp-admin/includes/class-wp-list-table.php';
20 }
21
22 /**
23 * Give_Form_Reports_Table Class
24 *
25 * Renders the Form Reports table
26 *
27 * @since 1.0
28 */
29 class Give_Form_Reports_Table extends WP_List_Table {
30
31 /**
32 * @var int Number of items per page
33 * @since 1.0
34 */
35 public $per_page = 30;
36
37 /**
38 * @var object Query results of all the donation forms
39 * @since 1.0
40 */
41 private $donation_forms;
42
43 /**
44 * @var int Total number of Donation Forms
45 * @since 1.8.11
46 */
47 public $count;
48
49 /**
50 * Get things started
51 *
52 * @since 1.0
53 * @see WP_List_Table::__construct()
54 */
55 public function __construct() {
56 global $status, $page;
57
58 // Set parent defaults
59 parent::__construct(
60 [
61 'singular' => give_get_forms_label_singular(), // Singular name of the listed records.
62 'plural' => give_get_forms_label_plural(), // Plural name of the listed records.
63 'ajax' => false, // Does this table support ajax?
64 ]
65 );
66
67 add_action( 'give_report_view_actions', [ $this, 'category_filter' ] );
68 $this->query();
69
70 }
71
72 /**
73 * This function renders most of the columns in the list table.
74 *
75 * @param array $item Contains all the data of the donation form
76 * @param string $column_name The name of the column
77 *
78 * @access public
79 * @since 1.0
80 *
81 * @return string Column Name
82 */
83 public function column_default( $item, $column_name ) {
84 switch ( $column_name ) {
85 case 'title':
86 $title = empty( $item['title'] ) ? sprintf( __( 'Untitled (#%s)', 'give' ), $item['ID'] ) : $item['title'];
87
88 return sprintf(
89 '<a href="%s">%s</a>',
90 get_edit_post_link( $item['ID'] ),
91 $title
92 );
93 case 'sales':
94 return sprintf(
95 '<a href="%s">%s</a>',
96 admin_url( 'edit.php?post_type=give_forms&page=give-payment-history&form_id=' . urlencode( $item['ID'] ) ),
97 $item['sales']
98 );
99 case 'earnings':
100 return give_currency_filter( give_format_amount( $item[ $column_name ], [ 'sanitize' => false ] ) );
101 case 'average_sales':
102 return round( $item[ $column_name ] );
103 case 'average_earnings':
104 return give_currency_filter( give_format_amount( $item[ $column_name ], [ 'sanitize' => false ] ) );
105 case 'details':
106 return '<a href="' . admin_url( 'edit.php?post_type=give_forms&page=give-reports&tab=forms&form-id=' . $item['ID'] ) . '">' . esc_html__( 'View Detailed Report', 'give' ) . '</a>';
107 default:
108 return $item[ $column_name ];
109 }
110 }
111
112 /**
113 * Retrieve the table columns
114 *
115 * @access public
116 * @since 1.0
117 *
118 * @return array $columns Array of all the list table columns
119 */
120 public function get_columns() {
121 $columns = [
122 'title' => esc_html__( 'Form', 'give' ),
123 'sales' => esc_html__( 'Donations', 'give' ),
124 'earnings' => esc_html__( 'Revenue', 'give' ),
125 'average_sales' => esc_html__( 'Monthly Average Donations', 'give' ),
126 'average_earnings' => esc_html__( 'Monthly Average Revenue', 'give' ),
127 'details' => esc_html__( 'Detailed Report', 'give' ),
128 ];
129
130 return $columns;
131 }
132
133 /**
134 * Retrieve the table's sortable columns
135 *
136 * @access public
137 * @since 1.0
138 *
139 * @return array Array of all the sortable columns
140 */
141 public function get_sortable_columns() {
142 return [
143 'title' => [ 'title', true ],
144 'sales' => [ 'sales', false ],
145 'earnings' => [ 'earnings', false ],
146 ];
147 }
148
149 /**
150 * Retrieve the current page number
151 *
152 * @access public
153 * @since 1.0
154 *
155 * @return int Current page number
156 */
157 public function get_paged() {
158 return isset( $_GET['paged'] ) ? absint( $_GET['paged'] ) : 1;
159 }
160
161 /**
162 * Retrieve the category being viewed
163 *
164 * @access public
165 * @since 1.0
166 *
167 * @return int Category ID
168 */
169 public function get_category() {
170 return isset( $_GET['category'] ) ? absint( $_GET['category'] ) : 0;
171 }
172
173 /**
174 * Outputs the reporting views
175 *
176 * @access public
177 * @since 1.0
178 *
179 * @return void
180 */
181 public function bulk_actions( $which = '' ) {
182
183 }
184
185 /**
186 * Generate the table navigation above or below the table
187 *
188 * @since 1.0
189 * @access protected
190 *
191 * @param string $which
192 */
193 protected function display_tablenav( $which ) {
194
195 if ( 'top' === $which ) {
196 wp_nonce_field( 'bulk-' . $this->_args['plural'] );
197 }
198 ?>
199 <div class="tablenav give-clearfix <?php echo esc_attr( $which ); ?>">
200
201 <?php if ( 'top' === $which ) { ?>
202 <h2 class="alignleft reports-earnings-title screen-reader-text">
203 <?php _e( 'Donation Forms Report', 'give' ); ?>
204 </h2>
205 <?php } ?>
206
207 <div class="alignright tablenav-right">
208 <div class="actions bulkactions">
209 <?php $this->bulk_actions( $which ); ?>
210 </div>
211 <?php
212 $this->extra_tablenav( $which );
213 $this->pagination( $which );
214 ?>
215 </div>
216
217 <br class="clear" />
218
219 </div>
220 <?php
221 }
222
223 /**
224 * Attaches the category filter to the log views
225 *
226 * @access public
227 * @since 1.0
228 *
229 * @return void
230 */
231 public function category_filter() {
232
233 $categories = get_terms( 'form_category' );
234 if ( $categories && ! is_wp_error( $categories ) ) {
235 echo Give()->html->category_dropdown( 'category', $this->get_category() );
236 }
237 }
238
239 /**
240 * Performs the donation forms query
241 *
242 * @access public
243 * @since 1.0
244 *
245 * @return void
246 */
247 public function query() {
248
249 $orderby = isset( $_GET['orderby'] ) ? $_GET['orderby'] : 'title';
250 $order = isset( $_GET['order'] ) ? $_GET['order'] : 'DESC';
251 $category = $this->get_category();
252
253 $args = [
254 'post_type' => 'give_forms',
255 'post_status' => 'publish',
256 'order' => $order,
257 'fields' => 'ids',
258 'posts_per_page' => $this->per_page,
259 'paged' => $this->get_paged(),
260 'suppress_filters' => true,
261 ];
262
263 if ( ! empty( $category ) ) {
264 $args['tax_query'] = [
265 [
266 'taxonomy' => 'form_category',
267 'terms' => $category,
268 ],
269 ];
270 }
271
272 switch ( $orderby ) :
273 case 'title':
274 $args['orderby'] = 'title';
275 break;
276
277 case 'sales':
278 $args['orderby'] = 'meta_value_num';
279 $args['meta_key'] = '_give_form_sales';
280 break;
281
282 case 'earnings':
283 $args['orderby'] = 'meta_value_num';
284 $args['meta_key'] = '_give_form_earnings';
285 break;
286 endswitch;
287
288 $args = apply_filters( 'give_form_reports_prepare_items_args', $args, $this );
289
290 $this->donation_forms = new WP_Query( $args );
291
292 // Store total number of donation forms count.
293 $this->count = $this->donation_forms->found_posts;
294
295 }
296
297 /**
298 * Build all the reports data
299 *
300 * @access public
301 * @since 1.0
302 *
303 * @return array $reports_data All the data for donor reports
304 */
305 public function reports_data() {
306 $reports_data = [];
307
308 $give_forms = $this->donation_forms->posts;
309
310 if ( $give_forms ) {
311 foreach ( $give_forms as $form ) {
312 $reports_data[] = [
313 'ID' => $form,
314 'title' => get_the_title( $form ),
315 'sales' => give_get_form_sales_stats( $form ),
316 'earnings' => give_get_form_earnings_stats( $form ),
317 'average_sales' => give_get_average_monthly_form_sales( $form ),
318 'average_earnings' => give_get_average_monthly_form_earnings( $form ),
319 ];
320 }
321 }
322
323 return $reports_data;
324 }
325
326 /**
327 * Setup the final data for the table
328 *
329 * @access public
330 * @since 1.5
331 *
332 * @uses Give_Form_Reports_Table::get_columns()
333 * @uses Give_Form_Reports_Table::get_sortable_columns()
334 * @uses Give_Form_Reports_Table::reports_data()
335 * @uses Give_Form_Reports_Table::get_pagenum()
336 *
337 * @return void
338 */
339 public function prepare_items() {
340 $columns = $this->get_columns();
341 $hidden = []; // No hidden columns
342 $sortable = $this->get_sortable_columns();
343 $this->_column_headers = [ $columns, $hidden, $sortable ];
344 $this->items = $this->reports_data();
345 $total_items = $this->count;
346
347 $this->set_pagination_args(
348 [
349 'total_items' => $total_items,
350 'per_page' => $this->per_page,
351 'total_pages' => ceil( $total_items / $this->per_page ),
352 ]
353 );
354 }
355 }
356