PluginProbe ʕ •ᴥ•ʔ
GiveWP – Donation Plugin and Fundraising Platform / 2.1.8
GiveWP – Donation Plugin and Fundraising Platform v2.1.8
4.16.7.2 4.16.7.1 4.16.7 4.16.6.1 4.16.6 4.16.5.1 4.16.5 4.16.4 4.16.3 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 / tools / logs / class-sales-logs-list-table.php
give / includes / admin / tools / logs Last commit date
class-api-requests-logs-list-table.php 7 years ago class-gateway-error-logs-list-table.php 7 years ago class-sales-logs-list-table.php 7 years ago class-update-logs-list-table.php 7 years ago logs.php 7 years ago
class-sales-logs-list-table.php
427 lines
1 <?php
2 /**
3 * Sales Log View 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 */
10
11 // Exit if accessed directly.
12 if ( ! defined( 'ABSPATH' ) ) {
13 exit;
14 }
15
16 // Load WP_List_Table if not loaded.
17 if ( ! class_exists( 'WP_List_Table' ) ) {
18 require_once ABSPATH . 'wp-admin/includes/class-wp-list-table.php';
19 }
20
21 /**
22 * Give_Sales_Log_Table Class
23 *
24 * Renders the sales log list table
25 *
26 * @since 1.0
27 */
28 class Give_Sales_Log_Table extends WP_List_Table {
29 /**
30 * Number of results to show per page
31 *
32 * @since 1.0
33 * @var int
34 */
35 public $per_page = 30;
36
37 /**
38 * Get things started
39 *
40 * @since 1.0
41 * @see WP_List_Table::__construct()
42 */
43 public function __construct() {
44 global $status, $page;
45
46 // Set parent defaults
47 parent::__construct( array(
48 'singular' => give_get_forms_label_singular(), // Singular name of the listed records
49 'plural' => give_get_forms_label_plural(), // Plural name of the listed records
50 'ajax' => false,// Does this table support ajax?
51 ) );
52
53 add_action( 'give_log_view_actions', array( $this, 'give_forms_filter' ) );
54 }
55
56 /**
57 * This function renders most of the columns in the list table.
58 *
59 * @access public
60 * @since 1.0
61 *
62 * @param array $item Contains all the data of the discount code
63 * @param string $column_name The name of the column
64 *
65 * @return string Column Name
66 */
67 public function column_default( $item, $column_name ) {
68
69 /* @var Give_Payment $payment */
70 $payment = give_get_payment_by( 'id', $item['payment_id'] );
71
72 switch ( $column_name ) {
73 case 'form' :
74 $form_title = get_the_title( $item[ $column_name ] );
75 $form_title = empty( $form_title ) ? sprintf( __( 'Untitled (#%s)', 'give' ), $item[ $column_name ] ) : $form_title;
76 return '<a href="' . esc_url( add_query_arg( 'form', $item[ $column_name ] ) ) . '" >' . esc_html( $form_title ). '</a>';
77
78 case 'amount' :
79 $value = give_currency_filter( give_format_amount( $item['amount'], array( 'sanitize' => false, 'donation_id' => $item['payment_id'] ) ), array( 'currency_code' => give_get_payment_currency_code( $item['payment_id'] ) ) );
80 $value .= sprintf( '<br><small>%1$s %2$s</small>', __( 'via', 'give' ), give_get_gateway_admin_label( $payment->gateway ) );
81
82 return $value;
83
84 case 'status' :
85
86 $value = '<div class="give-donation-status status-' . sanitize_title( give_get_payment_status( $payment, true ) ) . '"><span class="give-donation-status-icon"></span> ' . give_get_payment_status( $payment, true ) . '</div>';
87
88 if ( $payment->mode == 'test' ) {
89 $value .= Give()->tooltips->render_span( array(
90 'label' => __( 'This donation was made in test mode.', 'give' ),
91 'tag_content' => __( 'Test', 'give' ),
92 'attributes' => array(
93 'class' => 'give-item-label give-item-label-orange give-test-mode-transactions-label',
94 ),
95 ) );
96 }
97
98 return $value;
99
100 case 'donation' :
101 $serial_code = Give()->seq_donation_number->get_serial_code( $payment );
102 $value = Give()->tooltips->render_link( array(
103 'label' => sprintf( __( 'View Donation %s', 'give' ), $serial_code ),
104 'tag_content' => $serial_code,
105 'link' => esc_url( add_query_arg( 'id', $payment->ID, admin_url( 'edit.php?post_type=give_forms&page=give-payment-history&view=view-payment-details' ) ) ),
106 ) );
107
108 if ( ! empty( $item['donor_id'] ) ) {
109 $value .= sprintf(
110 '&nbsp;%1$s&nbsp;<a href="%2$s">%3$s</a><br>',
111 esc_html__( 'by', 'give' ),
112 admin_url( 'edit.php?post_type=give_forms&page=give-payment-history&donor=' . $item['donor_id'] ),
113 $item['donor_name']
114 );
115 } else {
116 $value .= sprintf(
117 '&nbsp;%1$s&nbsp;%2$s<br>',
118 esc_html__( 'by', 'give' ),
119 __( 'No donor attached', 'give' )
120 );;
121 }
122
123 return $value;
124
125 default:
126 return $item[ $column_name ];
127 }
128 }
129
130 /**
131 * Retrieve the table columns
132 *
133 * @access public
134 * @since 1.0
135 * @return array $columns Array of all the list table columns
136 */
137 public function get_columns() {
138 $columns = array(
139 'ID' => __( 'Log ID', 'give' ),
140 'donation' => __( 'Donation', 'give' ),
141 'form' => __( 'Form', 'give' ),
142 'status' => __( 'Status', 'give' ),
143 'amount' => __( 'Donation Amount', 'give' ),
144 'date' => __( 'Date', 'give' ),
145 );
146
147 return $columns;
148 }
149
150 /**
151 * Retrieve the current page number
152 *
153 * @access public
154 * @since 1.0
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 * Retrieves the user we are filtering logs by, if any
163 *
164 * @access public
165 * @since 1.0
166 * @return mixed int If User ID, string If Email/Login
167 */
168 public function get_filtered_user() {
169 return isset( $_GET['user'] ) ? absint( $_GET['user'] ) : false;
170 }
171
172 /**
173 * Retrieves the ID of the give_form we're filtering logs by
174 *
175 * @access public
176 * @since 1.0
177 * @return int Download ID
178 */
179 public function get_filtered_give_form() {
180 return ! empty( $_GET['form'] ) ? absint( $_GET['form'] ) : false;
181 }
182
183 /**
184 * Retrieves the search query string
185 *
186 * @access public
187 * @since 1.0
188 * @return string|bool string If search is present, false otherwise
189 */
190 public function get_search() {
191 return ! empty( $_GET['s'] ) ? urldecode( trim( $_GET['s'] ) ) : false;
192 }
193
194
195 /**
196 * Display Tablenav (extended)
197 *
198 * Display the table navigation above or below the table even when no items in the logs, so nav doesn't disappear
199 *
200 * @see : https://github.com/WordImpress/Give/issues/564
201 *
202 * @since 1.4.1
203 * @access protected
204 *
205 * @param string $which
206 */
207 protected function display_tablenav( $which ) {
208 ?>
209 <div class="tablenav <?php echo esc_attr( $which ); ?>">
210
211 <?php if ( 'top' === $which ) : ?>
212 <div class="alignleft actions bulkactions">
213 <?php $this->bulk_actions( $which ); ?>
214 </div>
215 <?php endif; ?>
216
217 <?php
218 $this->extra_tablenav( $which );
219 $this->pagination( $which );
220 ?>
221
222 <br class="clear"/>
223 </div>
224 <?php
225 }
226
227
228 /**
229 * Gets the meta query for the log query
230 *
231 * This is used to return log entries that match our search query, user query, or form query
232 *
233 * @since 1.0
234 * @access public
235 *
236 * @return array $meta_query
237 */
238 public function get_meta_query() {
239 $user = $this->get_filtered_user();
240 $give_form = $this->get_filtered_give_form();
241
242 $meta_query = array();
243
244 if ( $user ) {
245 // Show only logs from a specific user.
246 $meta_query[] = array(
247 'key' => '_give_log_user_id',
248 'value' => $user,
249 );
250 }
251
252 if ( $give_form ) {
253 $meta_query[] = array(
254 'key' => '_give_log_form_id',
255 'value' => $give_form,
256 );
257 }
258
259 $search = $this->get_search();
260 if ( $search ) {
261 if ( is_email( $search ) ) {
262 // This is an email search. We use this to ensure it works for guest users and logged-in users.
263 $key = '_give_log_user_info';
264 $compare = 'LIKE';
265 } else {
266 // Look for a user
267 $key = '_give_log_user_id';
268 $compare = 'LIKE';
269
270 if ( ! is_numeric( $search ) ) {
271 // Searching for user by username
272 $user = get_user_by( 'login', $search );
273
274 if ( $user ) {
275 // Found one, set meta value to user's ID.
276 $search = $user->ID;
277 } else {
278 // No user found so let's do a real search query.
279 $users = new WP_User_Query( array(
280 'search' => $search,
281 'search_columns' => array( 'user_url', 'user_nicename' ),
282 'number' => 1,
283 'fields' => 'ids',
284 ) );
285
286 $found_user = $users->get_results();
287
288 if ( $found_user ) {
289 $search = $found_user[0];
290 }
291 }
292 }
293 }
294
295 if ( ! $this->file_search ) {
296 // Meta query only works for non file name search.
297 $meta_query[] = array(
298 'key' => $key,
299 'value' => $search,
300 'compare' => $compare,
301 );
302
303 }
304 }
305
306 return $meta_query;
307 }
308
309 /**
310 * Outputs the log views
311 *
312 * @access public
313 * @since 1.0
314 * @param string $which
315 * @return void
316 */
317 function bulk_actions( $which = '' ) {
318 give_log_views();
319 }
320
321 /**
322 * Sets up the forms filter
323 *
324 * @access public
325 * @since 1.0
326 * @return void
327 */
328 public function give_forms_filter() {
329 echo Give()->html->forms_dropdown( array(
330 'selected' => $this->get_filtered_give_form(),
331 'name' => 'form',
332 'id' => 'give-log-form-filter',
333 'chosen' => true,
334 ) );
335 }
336
337 /**
338 * Gets the log entries for the current view
339 *
340 * @access public
341 * @since 1.0
342 *
343 * @return array $logs_data Array of all the Log entires
344 */
345 public function get_logs() {
346 $logs_data = array();
347 $log_query = $this->get_query_params();
348 $logs = Give()->logs->get_connected_logs( $log_query );
349
350 if ( $logs ) {
351 foreach ( $logs as $log ) {
352 /* @var Give_payment $payment */
353 $payment = new Give_Payment( $log->log_parent );
354
355 // Make sure this payment hasn't been deleted
356 if ( get_post( $payment->ID ) ) :
357 $logs_data[] = array(
358 'ID' => '<span class="give-item-label give-item-label-gray">' . $log->ID . '</span>',
359 'payment_id' => $payment->ID,
360 'form' => $payment->form_id,
361 'amount' => $payment->total,
362 'donor_id' => $payment->customer_id,
363 'donor_name' => trim( "{$payment->first_name} $payment->last_name" ),
364 'date' => $payment->date,
365 );
366
367 endif;
368 }
369 }
370
371 return $logs_data;
372 }
373
374 /**
375 * Setup the final data for the table
376 *
377 * @access public
378 * @since 1.0
379 * @uses Give_Sales_Log_Table::get_columns()
380 * @uses WP_List_Table::get_sortable_columns()
381 * @uses Give_Sales_Log_Table::get_pagenum()
382 * @uses Give_Sales_Log_Table::get_logs()
383 * @uses Give_Sales_Log_Table::get_log_count()
384 *
385 * @return void
386 */
387 public function prepare_items() {
388 $columns = $this->get_columns();
389 $hidden = array();
390 $sortable = $this->get_sortable_columns();
391 $this->_column_headers = array( $columns, $hidden, $sortable );
392 $current_page = $this->get_pagenum();
393 $this->items = $this->get_logs();
394 $total_items = Give()->logs->get_log_count( 0, 'sale', $this->get_meta_query() );
395
396 $this->set_pagination_args( array(
397 'total_items' => $total_items,
398 'per_page' => $this->per_page,
399 'total_pages' => ceil( $total_items / $this->per_page ),
400 )
401 );
402 }
403
404
405 /**
406 * Get log query param.
407 *
408 * @since 2.0
409 * @access public
410 *
411 * @return array
412 */
413 public function get_query_params() {
414 $paged = $this->get_paged();
415 $user = $this->get_filtered_user();
416
417 $log_query = array(
418 'log_type' => 'sale',
419 'paged' => $paged,
420 'meta_query' => $this->get_meta_query(),
421 'number' => $this->per_page,
422 );
423
424 return $log_query;
425 }
426 }
427