PluginProbe ʕ •ᴥ•ʔ
GiveWP – Donation Plugin and Fundraising Platform / 2.2.0
GiveWP – Donation Plugin and Fundraising Platform v2.2.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-donor-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-donor-reports-table.php
395 lines
1 <?php
2 /**
3 * Donor 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_Donor_Reports_Table Class
24 *
25 * Renders the Donor Reports table
26 *
27 * @since 1.0
28 */
29 class Give_Donor_Reports_Table extends WP_List_Table {
30
31 /**
32 * Number of items per page
33 *
34 * @var int
35 * @since 1.0
36 */
37 public $per_page = 30;
38
39 /**
40 * Number of donors found
41 *
42 * @var int
43 * @since 1.0
44 */
45 public $count = 0;
46
47 /**
48 * Total donors
49 *
50 * @var int
51 * @since 1.0
52 */
53 public $total = 0;
54
55 /**
56 * Get things started
57 *
58 * @since 1.0
59 * @see WP_List_Table::__construct()
60 */
61 public function __construct() {
62 global $status, $page;
63
64 // Set parent defaults
65 parent::__construct( array(
66 'singular' => esc_html__( 'Donor', 'give' ), // Singular name of the listed records
67 'plural' => esc_html__( 'Donors', 'give' ), // Plural name of the listed records
68 'ajax' => false,// Does this table support ajax?
69 ) );
70
71 }
72
73 /**
74 * Remove default search field in favor for repositioned location
75 *
76 * Reposition the search field
77 *
78 * @since 1.0
79 * @access public
80 *
81 * @param string $text Label for the search box
82 * @param string $input_id ID of the search box
83 *
84 * @return false
85 */
86 public function search_box( $text, $input_id ) {
87 return false;
88 }
89
90 /**
91 * Show the search field
92 *
93 * @since 1.0
94 * @access public
95 *
96 * @param string $text Label for the search box
97 * @param string $input_id ID of the search box
98 *
99 * @return void
100 */
101 public function give_search_box( $text, $input_id ) {
102 $input_id = $input_id . '-search-input';
103
104 if ( ! empty( $_REQUEST['orderby'] ) ) {
105 echo '<input type="hidden" name="orderby" value="' . esc_attr( $_REQUEST['orderby'] ) . '" />';
106 }
107 if ( ! empty( $_REQUEST['order'] ) ) {
108 echo '<input type="hidden" name="order" value="' . esc_attr( $_REQUEST['order'] ) . '" />';
109 }
110 ?>
111 <p class="search-box donor-search" role="search">
112 <label class="screen-reader-text" for="<?php echo $input_id ?>"><?php echo $text; ?>:</label>
113 <input type="search" id="<?php echo $input_id ?>" name="s" value="<?php _admin_search_query(); ?>" />
114 <?php submit_button( $text, 'button', false, false, array( 'ID' => 'search-submit' ) ); ?>
115 </p>
116 <?php
117 }
118
119 /**
120 * Generate the table navigation above or below the table
121 *
122 * @since 1.0
123 * @access protected
124 *
125 * @param string $which
126 */
127 protected function display_tablenav( $which ) {
128
129 if ( 'top' === $which ) {
130 wp_nonce_field( 'bulk-' . $this->_args['plural'] );
131 }
132 ?>
133 <div class="tablenav give-clearfix <?php echo esc_attr( $which ); ?>">
134
135 <?php if ( 'top' === $which ) { ?>
136 <h2 class="alignleft reports-earnings-title">
137 <?php esc_html_e( 'Donors Report', 'give' ); ?>
138 </h2>
139 <?php } ?>
140
141 <div class="alignright tablenav-right">
142 <div class="actions bulkactions">
143 <?php
144 if ( 'top' === $which ) {
145 $this->give_search_box( esc_html__( 'Search Donors', 'give' ), 'give-donors-report-search' );
146 }
147
148 $this->bulk_actions( $which ); ?>
149
150 </div>
151 <?php
152 $this->extra_tablenav( $which );
153 $this->pagination( $which );
154 ?>
155 </div>
156
157
158 <br class="clear"/>
159
160 </div>
161 <?php
162 }
163
164 /**
165 * This function renders most of the columns in the list table.
166 *
167 * @access public
168 * @since 1.0
169 *
170 * @param array $item Contains all the data of the donors
171 * @param string $column_name The name of the column
172 *
173 * @return string Column Name
174 */
175 public function column_default( $item, $column_name ) {
176
177 switch ( $column_name ) {
178
179 case 'name' :
180 $name = '#' . $item['id'] . ' ';
181 $name .= ! empty( $item['name'] ) ? $item['name'] : '<em>' . esc_html__( 'Unnamed Donor', 'give' ) . '</em>';
182 $view_url = admin_url( 'edit.php?post_type=give_forms&page=give-donors&view=overview&id=' . $item['id'] );
183 $value = '<a href="' . esc_url( $view_url ) . '">' . $name . '</a>';
184 break;
185
186 case 'num_donations' :
187 $value = sprintf(
188 '<a href="%s">%s</a>',
189 admin_url( 'edit.php?post_type=give_forms&page=give-payment-history&donor=' . absint( $item['id'] ) ),
190 esc_html( $item['num_donations'] )
191 );
192 break;
193
194 case 'amount_spent' :
195 $value = give_currency_filter( give_format_amount( $item[ $column_name ], array( 'sanitize' => false ) ) );
196 break;
197
198 default:
199 $value = isset( $item[ $column_name ] ) ? $item[ $column_name ] : null;
200 break;
201 }
202
203 return apply_filters( "give_report_column_{$column_name}", $value, $item['id'] );
204 }
205
206 /**
207 * Retrieve the table columns
208 *
209 * @access public
210 * @since 1.0
211 * @return array $columns Array of all the list table columns
212 */
213 public function get_columns() {
214 $columns = array(
215 'name' => __( 'Name', 'give' ),
216 'email' => __( 'Email', 'give' ),
217 'num_donations' => __( 'Donations', 'give' ),
218 'amount_spent' => __( 'Total Donated', 'give' ),
219 );
220
221 return apply_filters( 'give_report_donor_columns', $columns );
222
223 }
224
225 /**
226 * Get the sortable columns
227 *
228 * @access public
229 * @since 1.0
230 * @return array Array of all the sortable columns
231 */
232 public function get_sortable_columns() {
233 return array(
234 'id' => array( 'id', true ),
235 'name' => array( 'name', true ),
236 'num_donations' => array( 'purchase_count', false ),
237 'amount_spent' => array( 'purchase_value', false ),
238 );
239 }
240
241 /**
242 * Outputs the reporting views
243 *
244 * @access public
245 * @since 1.0
246 * @return void
247 */
248 public function bulk_actions( $which = '' ) {
249
250 }
251
252 /**
253 * Retrieve the current page number
254 *
255 * @access public
256 * @since 1.0
257 * @return int Current page number
258 */
259 public function get_paged() {
260 return isset( $_GET['paged'] ) ? absint( $_GET['paged'] ) : 1;
261 }
262
263 /**
264 * Retrieves the search query string
265 *
266 * @access public
267 * @since 1.0
268 * @return mixed string If search is present, false otherwise
269 */
270 public function get_search() {
271 return ! empty( $_GET['s'] ) ? urldecode( trim( $_GET['s'] ) ) : false;
272 }
273
274 /**
275 * Build all the reports data
276 *
277 * @access public
278 * @since 1.0
279 * @global object $wpdb Used to query the database using the WordPress
280 * Database API
281 * @return array $reports_data All the data for donor reports
282 */
283 public function reports_data() {
284 global $wpdb;
285
286 $data = array();
287
288 // Get donor query.
289 $args = $this->get_donor_query();
290 $donors = Give()->donors->get_donors( $args );
291
292 if ( $donors ) {
293
294 $this->count = count( $donors );
295
296 foreach ( $donors as $donor ) {
297
298 $user_id = ! empty( $donor->user_id ) ? absint( $donor->user_id ) : 0;
299
300 $data[] = array(
301 'id' => $donor->id,
302 'user_id' => $user_id,
303 'name' => $donor->name,
304 'email' => $donor->email,
305 'num_donations' => $donor->purchase_count,
306 'amount_spent' => $donor->purchase_value,
307 );
308 }
309 }
310
311 return $data;
312 }
313
314 /**
315 * Get donor count.
316 *
317 * @since 1.8.1
318 * @access private
319 */
320 private function get_donor_count() {
321 // Get donor query.
322 $_donor_query = $this->get_donor_query();
323
324 $_donor_query['number'] = -1;
325 $_donor_query['offset'] = 0;
326 $donors = Give()->donors->get_donors( $_donor_query );
327
328 return count( $donors );
329 }
330
331 /**
332 * Get donor query.
333 *
334 * @since 1.8.1
335 * @access public
336 * @return array
337 */
338 public function get_donor_query() {
339 $paged = $this->get_paged();
340 $offset = $this->per_page * ( $paged - 1 );
341 $search = $this->get_search();
342 $order = isset( $_GET['order'] ) ? sanitize_text_field( $_GET['order'] ) : 'DESC';
343 $orderby = isset( $_GET['orderby'] ) ? sanitize_text_field( $_GET['orderby'] ) : 'id';
344
345 $args = array(
346 'number' => $this->per_page,
347 'offset' => $offset,
348 'order' => $order,
349 'orderby' => $orderby,
350 );
351
352 if( $search ) {
353 if ( is_email( $search ) ) {
354 $args['email'] = $search;
355 } elseif ( is_numeric( $search ) ) {
356 $args['id'] = $search;
357 } else {
358 $args['name'] = $search;
359 }
360 }
361
362 return $args;
363 }
364
365 /**
366 * Setup the final data for the table
367 *
368 * @access public
369 * @since 1.0
370 * @uses Give_Donor_Reports_Table::get_columns()
371 * @uses WP_List_Table::get_sortable_columns()
372 * @uses Give_Donor_Reports_Table::get_pagenum()
373 * @uses Give_Donor_Reports_Table::get_total_donors()
374 * @return void
375 */
376 public function prepare_items() {
377
378 $columns = $this->get_columns();
379 $hidden = array(); // No hidden columns
380 $sortable = $this->get_sortable_columns();
381
382 $this->_column_headers = array( $columns, $hidden, $sortable );
383
384 $this->items = $this->reports_data();
385
386 $this->total = $this->get_donor_count();
387
388 $this->set_pagination_args( array(
389 'total_items' => $this->total,
390 'per_page' => $this->per_page,
391 'total_pages' => ceil( $this->total / $this->per_page ),
392 ) );
393 }
394 }
395