PluginProbe ʕ •ᴥ•ʔ
GiveWP – Donation Plugin and Fundraising Platform / 2.1.0
GiveWP – Donation Plugin and Fundraising Platform v2.1.0
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 8 years ago class-earnings-report.php 8 years ago class-form-reports-table.php 8 years ago class-forms-report.php 8 years ago class-gateways-report.php 8 years ago class-gateways-reports-table.php 8 years ago class-give-graph.php 8 years ago graphing.php 8 years ago reports.php 8 years ago
class-form-reports-table.php
353 lines
1 <?php
2 /**
3 * Download Reports Table Class
4 *
5 * @package Give
6 * @subpackage Admin/Reports
7 * @copyright Copyright (c) 2016, WordImpress
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( array(
60 'singular' => give_get_forms_label_singular(), // Singular name of the listed records.
61 'plural' => give_get_forms_label_plural(), // Plural name of the listed records.
62 'ajax' => false // Does this table support ajax?
63 ) );
64
65 add_action( 'give_report_view_actions', array( $this, 'category_filter' ) );
66 $this->query();
67
68 }
69
70 /**
71 * This function renders most of the columns in the list table.
72 *
73 * @param array $item Contains all the data of the donation form
74 * @param string $column_name The name of the column
75 *
76 * @access public
77 * @since 1.0
78 *
79 * @return string Column Name
80 */
81 public function column_default( $item, $column_name ) {
82 switch ( $column_name ) {
83 case 'title':
84 $title = empty( $item['title'] ) ? sprintf( __( 'Untitled (#%s)', 'give' ), $item['ID'] ) : $item['title'];
85
86 return sprintf(
87 '<a href="%s">%s</a>',
88 get_edit_post_link( $item['ID'] ),
89 $title
90 );
91 case 'sales':
92 return sprintf(
93 '<a href="%s">%s</a>',
94 admin_url( 'edit.php?post_type=give_forms&page=give-payment-history&form_id=' . urlencode( $item['ID'] ) ),
95 $item['sales']
96 );
97 case 'earnings' :
98 return give_currency_filter( give_format_amount( $item[ $column_name ], array( 'sanitize' => false ) ) );
99 case 'average_sales' :
100 return round( $item[ $column_name ] );
101 case 'average_earnings' :
102 return give_currency_filter( give_format_amount( $item[ $column_name ], array( 'sanitize' => false ) ) );
103 case 'details' :
104 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>';
105 default:
106 return $item[ $column_name ];
107 }
108 }
109
110 /**
111 * Retrieve the table columns
112 *
113 * @access public
114 * @since 1.0
115 *
116 * @return array $columns Array of all the list table columns
117 */
118 public function get_columns() {
119 $columns = array(
120 'title' => esc_html__( 'Form', 'give' ),
121 'sales' => esc_html__( 'Donations', 'give' ),
122 'earnings' => esc_html__( 'Income', 'give' ),
123 'average_sales' => esc_html__( 'Monthly Average Donations', 'give' ),
124 'average_earnings' => esc_html__( 'Monthly Average Income', 'give' ),
125 'details' => esc_html__( 'Detailed Report', 'give' )
126 );
127
128 return $columns;
129 }
130
131 /**
132 * Retrieve the table's sortable columns
133 *
134 * @access public
135 * @since 1.0
136 *
137 * @return array Array of all the sortable columns
138 */
139 public function get_sortable_columns() {
140 return array(
141 'title' => array( 'title', true ),
142 'sales' => array( 'sales', false ),
143 'earnings' => array( 'earnings', false ),
144 );
145 }
146
147 /**
148 * Retrieve the current page number
149 *
150 * @access public
151 * @since 1.0
152 *
153 * @return int Current page number
154 */
155 public function get_paged() {
156 return isset( $_GET['paged'] ) ? absint( $_GET['paged'] ) : 1;
157 }
158
159 /**
160 * Retrieve the category being viewed
161 *
162 * @access public
163 * @since 1.0
164 *
165 * @return int Category ID
166 */
167 public function get_category() {
168 return isset( $_GET['category'] ) ? absint( $_GET['category'] ) : 0;
169 }
170
171 /**
172 * Outputs the reporting views
173 *
174 * @access public
175 * @since 1.0
176 *
177 * @return void
178 */
179 public function bulk_actions( $which = '' ) {
180
181 }
182
183 /**
184 * Generate the table navigation above or below the table
185 *
186 * @since 1.0
187 * @access protected
188 *
189 * @param string $which
190 */
191 protected function display_tablenav( $which ) {
192
193 if ( 'top' === $which ) {
194 wp_nonce_field( 'bulk-' . $this->_args['plural'] );
195 }
196 ?>
197 <div class="tablenav give-clearfix <?php echo esc_attr( $which ); ?>">
198
199 <?php if ( 'top' === $which ) { ?>
200 <h2 class="alignleft reports-earnings-title screen-reader-text">
201 <?php _e( 'Donation Forms Report', 'give' ); ?>
202 </h2>
203 <?php } ?>
204
205 <div class="alignright tablenav-right">
206 <div class="actions bulkactions">
207 <?php $this->bulk_actions( $which ); ?>
208 </div>
209 <?php
210 $this->extra_tablenav( $which );
211 $this->pagination( $which );
212 ?>
213 </div>
214
215 <br class="clear" />
216
217 </div>
218 <?php
219 }
220
221 /**
222 * Attaches the category filter to the log views
223 *
224 * @access public
225 * @since 1.0
226 *
227 * @return void
228 */
229 public function category_filter() {
230
231 $categories = get_terms( 'form_category' );
232 if ( $categories && ! is_wp_error( $categories ) ) {
233 echo Give()->html->category_dropdown( 'category', $this->get_category() );
234 }
235 }
236
237 /**
238 * Performs the donation forms query
239 *
240 * @access public
241 * @since 1.0
242 *
243 * @return void
244 */
245 public function query() {
246
247 $orderby = isset( $_GET['orderby'] ) ? $_GET['orderby'] : 'title';
248 $order = isset( $_GET['order'] ) ? $_GET['order'] : 'DESC';
249 $category = $this->get_category();
250
251 $args = array(
252 'post_type' => 'give_forms',
253 'post_status' => 'publish',
254 'order' => $order,
255 'fields' => 'ids',
256 'posts_per_page' => $this->per_page,
257 'paged' => $this->get_paged(),
258 'suppress_filters' => true
259 );
260
261 if ( ! empty( $category ) ) {
262 $args['tax_query'] = array(
263 array(
264 'taxonomy' => 'form_category',
265 'terms' => $category
266 )
267 );
268 }
269
270 switch ( $orderby ) :
271 case 'title' :
272 $args['orderby'] = 'title';
273 break;
274
275 case 'sales' :
276 $args['orderby'] = 'meta_value_num';
277 $args['meta_key'] = '_give_form_sales';
278 break;
279
280 case 'earnings' :
281 $args['orderby'] = 'meta_value_num';
282 $args['meta_key'] = '_give_form_earnings';
283 break;
284 endswitch;
285
286 $args = apply_filters( 'give_form_reports_prepare_items_args', $args, $this );
287
288 $this->donation_forms = new WP_Query( $args );
289
290 // Store total number of donation forms count.
291 $this->count = $this->donation_forms->found_posts;
292
293 }
294
295 /**
296 * Build all the reports data
297 *
298 * @access public
299 * @since 1.0
300 *
301 * @return array $reports_data All the data for donor reports
302 */
303 public function reports_data() {
304 $reports_data = array();
305
306 $give_forms = $this->donation_forms->posts;
307
308 if ( $give_forms ) {
309 foreach ( $give_forms as $form ) {
310 $reports_data[] = array(
311 'ID' => $form,
312 'title' => get_the_title( $form ),
313 'sales' => give_get_form_sales_stats( $form ),
314 'earnings' => give_get_form_earnings_stats( $form ),
315 'average_sales' => give_get_average_monthly_form_sales( $form ),
316 'average_earnings' => give_get_average_monthly_form_earnings( $form )
317 );
318 }
319 }
320
321 return $reports_data;
322 }
323
324 /**
325 * Setup the final data for the table
326 *
327 * @access public
328 * @since 1.5
329 *
330 * @uses Give_Form_Reports_Table::get_columns()
331 * @uses Give_Form_Reports_Table::get_sortable_columns()
332 * @uses Give_Form_Reports_Table::reports_data()
333 * @uses Give_Form_Reports_Table::get_pagenum()
334 *
335 * @return void
336 */
337 public function prepare_items() {
338 $columns = $this->get_columns();
339 $hidden = array(); // No hidden columns
340 $sortable = $this->get_sortable_columns();
341 $this->_column_headers = array( $columns, $hidden, $sortable );
342 $this->items = $this->reports_data();
343 $total_items = $this->count;
344
345 $this->set_pagination_args( array(
346 'total_items' => $total_items,
347 'per_page' => $this->per_page,
348 'total_pages' => ceil( $total_items / $this->per_page )
349 )
350 );
351 }
352 }
353