PluginProbe ʕ •ᴥ•ʔ
SureCart – Ecommerce Made Easy For Selling Physical Products, Digital Downloads, Subscriptions, Donations, & Payments / 3.0.3
SureCart – Ecommerce Made Easy For Selling Physical Products, Digital Downloads, Subscriptions, Donations, & Payments v3.0.3
4.4.2 4.4.1 4.4.0 4.3.3 4.3.2 4.3.1 4.3.0 4.2.3 4.2.2 4.2.1 1.0.3 1.0.4 1.0.5 1.0.6 1.1.0 1.1.1 1.1.10 1.1.11 1.1.12 1.1.13 1.1.14 1.1.15 1.1.16 1.1.17 1.1.18 1.1.19 1.1.2 1.1.3 1.1.4 1.1.5 1.1.6 1.1.7 1.1.8 1.1.9 1.10.0 1.10.1 1.10.2 1.10.3 1.10.4 1.11.0 1.11.1 1.11.2 1.2.0 1.2.1 1.2.2 1.2.3 1.2.4 1.2.5 1.3.0 1.3.1 1.3.2 1.3.3 1.3.4 1.4.0 1.4.1 1.4.2 1.5.0 1.5.1 1.5.2 1.5.3 1.5.4 1.5.5 1.5.6 1.5.7 1.5.8 1.6.0 1.6.1 1.6.2 1.6.3 1.6.4 1.7.0 1.7.1 1.7.2 1.8.0 1.8.1 1.8.2 1.8.3 1.8.4 1.8.5 1.9.0 1.9.1 1.9.2 1.9.3 1.9.4 1.9.5 2.0.0 2.0.1 2.1.0 2.1.1 2.1.2 2.1.3 2.1.4 2.10.0 2.10.1 2.11.0 2.11.1 2.11.2 2.11.3 2.11.4 2.12.0 2.13.0 2.14.0 2.14.1 2.15.0 2.15.1 2.16.0 2.16.1 2.16.2 2.16.3 2.17.0 2.17.1 2.17.2 2.18.0 2.19.0 2.19.2 2.19.3 2.19.4 2.2.0 2.2.1 2.20.0 2.20.1 2.20.2 2.20.3 2.20.4 2.20.5 2.20.6 2.21.0 2.22.0 2.22.1 2.23.0 2.24.0 2.25.0 2.25.1 2.25.2 2.26.0 2.27.0 2.27.1 2.28.0 2.29.0 2.29.1 2.29.2 2.29.3 2.29.4 2.3.0 2.3.1 2.30.0 2.31.0 2.31.1 2.31.2 2.31.3 2.4.0 2.4.1 2.4.2 2.4.3 2.4.4 2.40.0 2.40.1 2.5.0 2.5.1 2.5.2 2.6.0 2.6.1 2.6.2 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.8.2 2.8.3 2.8.4 2.9.0 3.0.0 3.0.0-RC1 3.0.0-RC2 3.0.0-beta1 3.0.0-beta2 3.0.1 3.0.2 3.0.3 3.0.4 3.0.5 3.1.0 3.1.1 3.1.2 3.1.3 3.1.4 3.1.5 3.1.6 3.10.0 3.10.1 3.11.0 3.12.0 3.13.0 3.13.1 3.13.2 3.13.3 3.13.4 3.14.0 3.15.0 3.15.1 3.15.2 3.15.3 3.15.4 3.15.5 3.16.0 3.16.1 3.16.2 3.16.3 3.16.4 3.16.5 3.16.6 3.16.7 3.16.8 3.17.0 3.17.1 3.17.2 3.17.3 3.17.4 3.17.5 3.17.6 3.18.0 3.19.0 3.19.1 3.19.2 3.2.0 3.2.1 3.2.2 3.20.0 3.20.1 3.3.0 3.3.1 3.4.0 3.4.1 3.4.2 3.4.3 3.5.0 3.5.1 3.5.2 3.5.3 3.6.0 3.6.1 3.6.2 3.7.0 3.7.1 3.7.2 3.7.3 3.8.0 3.8.1 3.8.2 3.8.3 3.8.4 3.8.5 3.9.0 4.0.0 4.0.1 4.0.2 4.0.3 trunk 4.1.0 0.2.19.1 4.1.1 1.0.0 4.2.0 1.0.1 1.0.2
surecart / app / src / Controllers / Admin / AffiliationReferrals / AffiliationReferralsListTable.php
surecart / app / src / Controllers / Admin / AffiliationReferrals Last commit date
AffiliationReferralsController.php 1 year ago AffiliationReferralsListTable.php 1 year ago AffiliationReferralsScriptsController.php 2 years ago
AffiliationReferralsListTable.php
463 lines
1 <?php
2
3 namespace SureCart\Controllers\Admin\AffiliationReferrals;
4
5 use SureCart\Controllers\Admin\Tables\ListTable;
6 use SureCart\Models\Referral;
7 use SureCart\Support\Currency;
8 use SureCart\Controllers\Admin\Tables\HasModeFilter;
9
10 /**
11 * Create a new table class that will extend the WP_List_Table
12 */
13 class AffiliationReferralsListTable extends ListTable {
14 use HasModeFilter;
15
16 /**
17 * Checkbox
18 *
19 * @var boolean
20 */
21 public $checkbox = true;
22
23 /**
24 * Error
25 *
26 * @var string
27 */
28 public $error = '';
29
30 /**
31 * Pages
32 *
33 * @var array
34 */
35 public $pages = array();
36
37 /**
38 * Prepare the items for the table to process
39 *
40 * @return void
41 */
42 public function prepare_items() {
43 $columns = $this->get_columns();
44 $hidden = $this->get_hidden_columns();
45 $sortable = $this->get_sortable_columns();
46
47 $this->_column_headers = array( $columns, $hidden, $sortable );
48
49 $query = $this->table_data();
50
51 if ( is_wp_error( $query ) ) {
52 $this->error = $query->get_error_message();
53 $this->items = array();
54 return;
55 }
56
57 $this->set_pagination_args(
58 array(
59 'total_items' => $query->pagination->count,
60 'per_page' => $this->get_items_per_page( 'affiliate_referrals' ),
61 )
62 );
63
64 $this->items = $query->data;
65 }
66
67 /**
68 * Get views for the list table status links.
69 *
70 * @global int $post_id
71 * @global string $comment_status
72 * @global string $comment_type
73 *
74 * @return string
75 */
76 protected function get_views() {
77 foreach ( $this->getStatuses() as $status => $label ) {
78 $link = admin_url( 'admin.php?page=sc-affiliate-referrals' );
79
80 $current_link_attributes = '';
81
82 if ( ! empty( $_GET['status'] ) ) {
83 if ( $status === $_GET['status'] ) {
84 $current_link_attributes = ' class="current" aria-current="page"';
85 }
86 } elseif ( 'all' === $status ) {
87 $current_link_attributes = ' class="current" aria-current="page"';
88 }
89
90 $link = add_query_arg( 'status', $status, $link );
91
92 $link = esc_url( $link );
93
94 $status_links[ $status ] = "<a href='$link'$current_link_attributes>" . $label . '</a>';
95 }
96
97 /**
98 * Filters the affiliation referrals status links.
99 *
100 * @since 2.5.0
101 * @since 5.1.0 The 'Mine' link was added.
102 *
103 * @param string[] $status_links An associative array of fully-formed affiliation referrals status links. Includes 'All', 'Reviewing', 'Approved', 'Denied', 'Cancelled' and 'Paid Out'.
104 * */
105 return apply_filters( 'sc_affiliation_referrals_status_links', $status_links );
106 }
107
108 /**
109 * Override the parent columns method. Defines the columns to use in your listing table
110 *
111 * @return array
112 */
113 public function get_columns() {
114 return array(
115 'date' => esc_html__( 'Date', 'surecart' ),
116 'status' => esc_html__( 'Status', 'surecart' ),
117 'payout_status' => esc_html__( 'Payout Status', 'surecart' ),
118 'payout_date' => esc_html__( 'Payout Date', 'surecart' ),
119 'affiliate' => esc_html__( 'Affiliate', 'surecart' ),
120 'description' => esc_html__( 'Description', 'surecart' ),
121 'order' => esc_html__( 'Order', 'surecart' ),
122 'commission' => esc_html__( 'Commission', 'surecart' ),
123 'mode' => '',
124 );
125 }
126
127 /**
128 * Handle the date column.
129 *
130 * @param \SureCart\Models\Referral $referral The Referral model.
131 *
132 * @return string
133 */
134 public function column_date( $referral ) {
135 ob_start();
136 echo wp_kses_post( date_i18n( get_option( 'date_format' ), $referral->created_at ) );
137 ?>
138 <?php
139 echo wp_kses_post(
140 $this->row_actions(
141 array_filter(
142 array(
143 'view' => '<a href="' . esc_url( \SureCart::getUrl()->edit( 'affiliate-referrals', $referral->id ) ) . '" aria-label="' . esc_attr__( 'View', 'surecart' ) . '">' . esc_html__( 'View', 'surecart' ) . '</a>',
144 'edit' => '<a href="' . esc_url( \SureCart::getUrl()->edit( 'affiliate-referrals', $referral->id ) ) . '" aria-label="' . esc_attr__( 'Edit', 'surecart' ) . '">' . esc_html__( 'Edit', 'surecart' ) . '</a>',
145 'approve' => '<a href="' . esc_url( $this->get_action_url( $referral->id, 'approve' ) ) . '" aria-label="' . esc_attr__( 'Approve', 'surecart' ) . '">' . esc_html__( 'Approve', 'surecart' ) . '</a>',
146 'deny' => '<a href="' . esc_url( $this->get_action_url( $referral->id, 'deny' ) ) . '" aria-label="' . esc_attr__( 'Deny', 'surecart' ) . '">' . esc_html__( 'Deny', 'surecart' ) . '</a>',
147 'make_reviewing' => '<a href="' . esc_url( $this->get_action_url( $referral->id, 'make_reviewing' ) ) . '" aria-label="' . esc_attr__( 'Make Reviewing', 'surecart' ) . '">' . esc_html__( 'Make Reviewing', 'surecart' ) . '</a>',
148 'delete' => '<a href="' . esc_url( $this->get_action_url( $referral->id, 'delete' ) ) . '" aria-label="' . esc_attr__( 'Delete', 'surecart' ) . '">' . esc_html__( 'Delete', 'surecart' ) . '</a>',
149 ),
150 function ( $action, $key ) use ( $referral ) {
151 // only view a paid referral.
152 if ( 'view' === $key && 'paid' !== $referral->status ) {
153 return false;
154 }
155
156 // don't edit a paid referral.
157 if ( 'paid' === $referral->status && 'view' !== $key ) {
158 return false;
159 }
160
161 // don't approve approved referral.
162 if ( 'approve' === $key && 'approved' === $referral->status ) {
163 return false;
164 }
165
166 // don't deny denied referral.
167 if ( 'deny' === $key && 'denied' === $referral->status ) {
168 return false;
169 }
170
171 // don't make reviewing reviewing referral.
172 if ( 'make_reviewing' === $key && 'reviewing' === $referral->status ) {
173 return false;
174 }
175
176 return true;
177 },
178 ARRAY_FILTER_USE_BOTH
179 )
180 )
181 )
182 ?>
183 <?php
184 return ob_get_clean();
185 }
186
187 /**
188 * Handle the status column.
189 *
190 * @param \SureCart\Models\Referral $referral The Referral model.
191 *
192 * @return string
193 */
194 public function column_status( $referral ) {
195 if ( empty( $referral->status_display_text ) ) {
196 return '';
197 }
198 ob_start();
199 ?>
200 <sc-tag type="<?php echo esc_attr( $referral->status_type ); ?>">
201 <?php echo esc_html( $referral->status_display_text ); ?>
202 </sc-tag>
203 <?php
204 return ob_get_clean();
205 }
206
207 /**
208 * Handle the payout status column.
209 *
210 * @param \SureCart\Models\Referral $referral The Referral model.
211 *
212 * @return string
213 */
214 public function column_payout_status( $referral ) {
215 if ( empty( $referral->payout ) ) {
216 return '_';
217 }
218
219 $type = 'completed' === $referral->payout->status ? 'success' : 'warning';
220
221 return '<sc-tag type="' . $type . '">' . $referral->payout->status_display_text . ' </sc-tag>';
222 }
223
224 /**
225 * Handle the payout date column.
226 *
227 * @param \SureCart\Models\Referral $referral The Referral model.
228 *
229 * @return string
230 */
231 public function column_payout_date( $referral ) {
232 if ( empty( $referral->payout ) ) {
233 return '_';
234 }
235
236 return date_i18n( get_option( 'date_format' ), $referral->payout->created_at );
237 }
238
239
240 /**
241 * Handle the affiliate column.
242 *
243 * @param \SureCart\Models\Referral $referral The Referral model.
244 *
245 * @return string
246 */
247 public function column_affiliate( $referral ) {
248 $affiliation = $referral->affiliation ?? null;
249 if ( empty( $affiliation->id ) ) {
250 return '-';
251 }
252 ob_start();
253 ?>
254 <div class="sc-affiliate-name">
255 <a href="<?php echo esc_url( \SureCart::getUrl()->edit( 'affiliates', $affiliation->id ) ); ?>">
256 <?php echo esc_html( $affiliation->display_name ); ?>
257 </a>
258 </div>
259 <?php
260 return ob_get_clean();
261 }
262
263 /**
264 * Handle the description column.
265 *
266 * @param \SureCart\Models\Referral $referral The Referral model.
267 *
268 * @return string
269 */
270 public function column_description( $referral ) {
271 return esc_html( $referral->description );
272 }
273
274 /**
275 * Handle the order column.
276 *
277 * @param \SureCart\Models\Referral $referral The Referral model.
278 *
279 * @return string
280 */
281 public function column_order( $referral ) {
282 $checkout = $referral->checkout ?? null;
283 if ( empty( $checkout->order->id ) ) {
284 return '-';
285 }
286 ob_start();
287 ?>
288 <a aria-label="<?php esc_attr_e( 'View Order', 'surecart' ); ?>" href="<?php echo esc_url( \SureCart::getUrl()->edit( 'order', $checkout->order->id ) ); ?>">
289 #<?php echo esc_html( $checkout->order->number ?? $checkout->order->id ); ?>
290 </a>
291 <?php
292 return ob_get_clean();
293 }
294
295 /**
296 * Handle the commission column.
297 *
298 * @param \SureCart\Models\Referral $referral The Referral model.
299 *
300 * @return string
301 */
302 public function column_commission( $referral ) {
303 return Currency::format( $referral->commission_amount, $referral->currency );
304 }
305
306 /**
307 * Get the table data
308 *
309 * @return \SureCart\Models\Collection;
310 */
311 private function table_data() {
312 $mode = sanitize_text_field( wp_unslash( $_GET['mode'] ?? '' ) );
313 $conditions = array(
314 'query' => $this->get_search_query(),
315 'status' => [ $this->getFilteredStatus() ],
316 'expand' => [
317 'affiliation',
318 'checkout',
319 'checkout.order',
320 'payout',
321 ],
322 );
323
324 if ( ! empty( $mode ) ) {
325 $conditions['live_mode'] = 'live' === $mode;
326 }
327
328 return Referral::where($conditions)->paginate(
329 array(
330 'per_page' => $this->get_items_per_page( 'affiliate_referrals' ),
331 'page' => $this->get_pagenum(),
332 )
333 );
334 }
335
336 /**
337 * Nothing found.
338 *
339 * @return void
340 */
341 public function no_items() {
342 if ( $this->error ) {
343 echo esc_html( $this->error );
344 return;
345 }
346 echo esc_html_e( 'No affiliate referrals found . ', 'surecart' );
347 }
348
349 /**
350 * Displays extra table navigation.
351 *
352 * @param string $which Top or bottom placement.
353 */
354 protected function extra_tablenav( $which ) {
355 ?>
356 <input type="hidden" name="page" value="sc-affiliate-referrals" />
357
358 <?php if ( ! empty( $_GET['status'] ) ) : // phpcs:ignore WordPress.Security.NonceVerification.Recommended ?>
359 <input type="hidden" name="status" value="<?php echo esc_attr( $_GET['status'] ); ?>" />
360 <?php endif; ?>
361
362 <div class="alignleft actions">
363 <?php
364 if ( 'top' === $which ) {
365 ob_start();
366 $this->mode_dropdown();
367
368 /**
369 * Fires before the Filter button on the Posts and Pages list tables.
370 *
371 * The Filter button allows sorting by date and/or category on the
372 * Posts list table, and sorting by date on the Pages list table.
373 *
374 * @since 2.1.0
375 * @since 4.4.0 The `$post_type` parameter was added.
376 * @since 4.6.0 The `$which` parameter was added.
377 *
378 * @param string $post_type The post type slug.
379 * @param string $which The location of the extra table nav markup:
380 * 'top' or 'bottom' for WP_Posts_List_Table,
381 * 'bar' for WP_Media_List_Table.
382 */
383 do_action( 'restrict_manage_affiliate_referrals', $this->screen->post_type, $which );
384
385 $output = ob_get_clean();
386
387 if ( ! empty( $output ) ) {
388 echo $output; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
389 submit_button( __( 'Filter' ), '', 'filter_action', false, array( 'id' => 'filter-by-mode-submit' ) );
390 }
391 }
392
393 ?>
394 </div>
395
396 <?php
397 /**
398 * Fires immediately following the closing "actions" div in the tablenav
399 * for the affiliate referrals list table.
400 *
401 * @param string $which The location of the extra table nav markup: 'top' or 'bottom'.
402 */
403 do_action( 'manage_affiliate_referrals_extra_tablenav', $which );
404 }
405
406 /**
407 * Get filtered status / default status.
408 *
409 * @return string|null
410 */
411 private function getFilteredStatus() {
412 if ( empty( $_GET['status'] ) || 'all' === $_GET['status'] ) {
413 return null;
414 }
415
416 // transform in payout status.
417 if ( 'in_payout' === $_GET['status'] ) {
418 return 'paid';
419 }
420
421 return sanitize_text_field( wp_unslash( $_GET['status'] ) );
422 }
423
424 /**
425 * Get all statuses.
426 *
427 * @return array
428 */
429 private function getStatuses(): array {
430 return array(
431 'all' => __( 'All', 'surecart' ),
432 'reviewing' => __( 'Reviewing', 'surecart' ),
433 'approved' => __( 'Approved', 'surecart' ),
434 'denied' => __( 'Denied', 'surecart' ),
435 'canceled' => __( 'Canceled', 'surecart' ),
436 'in_payout' => __( 'In Payout', 'surecart' ),
437 );
438 }
439
440 /**
441 * Get action url.
442 *
443 * @param int $id The id.
444 * @param string $action The action.
445 *
446 * @return string
447 */
448 public function get_action_url( $id, $action ) {
449 return esc_url(
450 add_query_arg(
451 array_filter(
452 [
453 'action' => $action,
454 'nonce' => wp_create_nonce( $action . '_affiliation' ),
455 'id' => $id,
456 ]
457 ),
458 esc_url_raw( admin_url( 'admin.php?page=sc-affiliate-referrals' ) )
459 )
460 );
461 }
462 }
463