PluginProbe ʕ •ᴥ•ʔ
SureCart – Ecommerce Made Easy For Selling Physical Products, Digital Downloads, Subscriptions, Donations, & Payments / 4.6.0
SureCart – Ecommerce Made Easy For Selling Physical Products, Digital Downloads, Subscriptions, Donations, & Payments v4.6.0
4.6.2 4.6.1 4.6.0 4.5.1 4.5.0 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 10 months ago AffiliationReferralsListTable.php 7 months ago AffiliationReferralsScriptsController.php 2 years ago
AffiliationReferralsListTable.php
467 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_merge(
115 [
116 'date' => esc_html__( 'Date', 'surecart' ),
117 'status' => esc_html__( 'Status', 'surecart' ),
118 'payout_status' => esc_html__( 'Payout Status', 'surecart' ),
119 'payout_date' => esc_html__( 'Payout Date', 'surecart' ),
120 'affiliate' => esc_html__( 'Affiliate', 'surecart' ),
121 'description' => esc_html__( 'Description', 'surecart' ),
122 'order' => esc_html__( 'Order', 'surecart' ),
123 'commission' => esc_html__( 'Commission', 'surecart' ),
124 'mode' => '',
125 ],
126 parent::get_columns()
127 );
128 }
129
130 /**
131 * Handle the date column.
132 *
133 * @param \SureCart\Models\Referral $referral The Referral model.
134 *
135 * @return string
136 */
137 public function column_date( $referral ) {
138 ob_start();
139 echo esc_attr( $referral->created_at_date_time );
140 ?>
141
142 <?php
143 echo wp_kses_post(
144 $this->row_actions(
145 array_filter(
146 array(
147 'view' => '<a href="' . esc_url( \SureCart::getUrl()->edit( 'affiliate-referrals', $referral->id ) ) . '" aria-label="' . esc_attr__( 'View', 'surecart' ) . '">' . esc_html__( 'View', 'surecart' ) . '</a>',
148 'edit' => '<a href="' . esc_url( \SureCart::getUrl()->edit( 'affiliate-referrals', $referral->id ) ) . '" aria-label="' . esc_attr__( 'Edit', 'surecart' ) . '">' . esc_html__( 'Edit', 'surecart' ) . '</a>',
149 'approve' => '<a href="' . esc_url( $this->get_action_url( $referral->id, 'approve' ) ) . '" aria-label="' . esc_attr__( 'Approve', 'surecart' ) . '">' . esc_html__( 'Approve', 'surecart' ) . '</a>',
150 'deny' => '<a href="' . esc_url( $this->get_action_url( $referral->id, 'deny' ) ) . '" aria-label="' . esc_attr__( 'Deny', 'surecart' ) . '">' . esc_html__( 'Deny', 'surecart' ) . '</a>',
151 '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>',
152 'delete' => '<a href="' . esc_url( $this->get_action_url( $referral->id, 'delete' ) ) . '" aria-label="' . esc_attr__( 'Delete', 'surecart' ) . '">' . esc_html__( 'Delete', 'surecart' ) . '</a>',
153 ),
154 function ( $action, $key ) use ( $referral ) {
155 // only view a paid referral.
156 if ( 'view' === $key && 'paid' !== $referral->status ) {
157 return false;
158 }
159
160 // don't edit a paid referral.
161 if ( 'paid' === $referral->status && 'view' !== $key ) {
162 return false;
163 }
164
165 // don't approve approved referral.
166 if ( 'approve' === $key && 'approved' === $referral->status ) {
167 return false;
168 }
169
170 // don't deny denied referral.
171 if ( 'deny' === $key && 'denied' === $referral->status ) {
172 return false;
173 }
174
175 // don't make reviewing reviewing referral.
176 if ( 'make_reviewing' === $key && 'reviewing' === $referral->status ) {
177 return false;
178 }
179
180 return true;
181 },
182 ARRAY_FILTER_USE_BOTH
183 )
184 )
185 )
186 ?>
187 <?php
188 return ob_get_clean();
189 }
190
191 /**
192 * Handle the status column.
193 *
194 * @param \SureCart\Models\Referral $referral The Referral model.
195 *
196 * @return string
197 */
198 public function column_status( $referral ) {
199 if ( empty( $referral->status_display_text ) ) {
200 return '';
201 }
202 ob_start();
203 ?>
204 <sc-tag type="<?php echo esc_attr( $referral->status_type ); ?>">
205 <?php echo esc_html( $referral->status_display_text ); ?>
206 </sc-tag>
207 <?php
208 return ob_get_clean();
209 }
210
211 /**
212 * Handle the payout status column.
213 *
214 * @param \SureCart\Models\Referral $referral The Referral model.
215 *
216 * @return string
217 */
218 public function column_payout_status( $referral ) {
219 if ( empty( $referral->payout ) ) {
220 return '_';
221 }
222
223 $type = 'completed' === $referral->payout->status ? 'success' : 'warning';
224
225 return '<sc-tag type="' . $type . '">' . $referral->payout->status_display_text . ' </sc-tag>';
226 }
227
228 /**
229 * Handle the payout date column.
230 *
231 * @param \SureCart\Models\Referral $referral The Referral model.
232 *
233 * @return string
234 */
235 public function column_payout_date( $referral ) {
236 if ( empty( $referral->payout ) ) {
237 return '_';
238 }
239
240 return date_i18n( get_option( 'date_format' ), $referral->payout->created_at );
241 }
242
243
244 /**
245 * Handle the affiliate column.
246 *
247 * @param \SureCart\Models\Referral $referral The Referral model.
248 *
249 * @return string
250 */
251 public function column_affiliate( $referral ) {
252 $affiliation = $referral->affiliation ?? null;
253 if ( empty( $affiliation->id ) ) {
254 return '-';
255 }
256 ob_start();
257 ?>
258 <div class="sc-affiliate-name">
259 <a href="<?php echo esc_url( \SureCart::getUrl()->edit( 'affiliates', $affiliation->id ) ); ?>">
260 <?php echo esc_html( $affiliation->display_name ); ?>
261 </a>
262 </div>
263 <?php
264 return ob_get_clean();
265 }
266
267 /**
268 * Handle the description column.
269 *
270 * @param \SureCart\Models\Referral $referral The Referral model.
271 *
272 * @return string
273 */
274 public function column_description( $referral ) {
275 return esc_html( $referral->description );
276 }
277
278 /**
279 * Handle the order column.
280 *
281 * @param \SureCart\Models\Referral $referral The Referral model.
282 *
283 * @return string
284 */
285 public function column_order( $referral ) {
286 $checkout = $referral->checkout ?? null;
287 if ( empty( $checkout->order->id ) ) {
288 return '-';
289 }
290 ob_start();
291 ?>
292 <a aria-label="<?php esc_attr_e( 'View Order', 'surecart' ); ?>" href="<?php echo esc_url( \SureCart::getUrl()->edit( 'order', $checkout->order->id ) ); ?>">
293 #<?php echo esc_html( $checkout->order->number ?? $checkout->order->id ); ?>
294 </a>
295 <?php
296 return ob_get_clean();
297 }
298
299 /**
300 * Handle the commission column.
301 *
302 * @param \SureCart\Models\Referral $referral The Referral model.
303 *
304 * @return string
305 */
306 public function column_commission( $referral ) {
307 return Currency::format( $referral->commission_amount, $referral->currency );
308 }
309
310 /**
311 * Get the table data
312 *
313 * @return \SureCart\Models\Collection;
314 */
315 private function table_data() {
316 $mode = sanitize_text_field( wp_unslash( $_GET['mode'] ?? '' ) );
317 $conditions = array(
318 'query' => $this->get_search_query(),
319 'status' => [ $this->getFilteredStatus() ],
320 'expand' => [
321 'affiliation',
322 'checkout',
323 'checkout.order',
324 'payout',
325 ],
326 );
327
328 if ( ! empty( $mode ) ) {
329 $conditions['live_mode'] = 'live' === $mode;
330 }
331
332 return Referral::where( $conditions )->paginate(
333 array(
334 'per_page' => $this->get_items_per_page( 'affiliate_referrals' ),
335 'page' => $this->get_pagenum(),
336 )
337 );
338 }
339
340 /**
341 * Nothing found.
342 *
343 * @return void
344 */
345 public function no_items() {
346 if ( $this->error ) {
347 echo esc_html( $this->error );
348 return;
349 }
350 echo esc_html_e( 'No affiliate referrals found . ', 'surecart' );
351 }
352
353 /**
354 * Displays extra table navigation.
355 *
356 * @param string $which Top or bottom placement.
357 */
358 protected function extra_tablenav( $which ) {
359 ?>
360 <input type="hidden" name="page" value="sc-affiliate-referrals" />
361
362 <?php if ( ! empty( $_GET['status'] ) ) : // phpcs:ignore WordPress.Security.NonceVerification.Recommended ?>
363 <input type="hidden" name="status" value="<?php echo esc_attr( $_GET['status'] ); ?>" />
364 <?php endif; ?>
365
366 <div class="alignleft actions">
367 <?php
368 if ( 'top' === $which ) {
369 ob_start();
370 $this->mode_dropdown();
371
372 /**
373 * Fires before the Filter button on the Posts and Pages list tables.
374 *
375 * The Filter button allows sorting by date and/or category on the
376 * Posts list table, and sorting by date on the Pages list table.
377 *
378 * @since 2.1.0
379 * @since 4.4.0 The `$post_type` parameter was added.
380 * @since 4.6.0 The `$which` parameter was added.
381 *
382 * @param string $post_type The post type slug.
383 * @param string $which The location of the extra table nav markup:
384 * 'top' or 'bottom' for WP_Posts_List_Table,
385 * 'bar' for WP_Media_List_Table.
386 */
387 do_action( 'restrict_manage_affiliate_referrals', $this->screen->post_type, $which );
388
389 $output = ob_get_clean();
390
391 if ( ! empty( $output ) ) {
392 echo $output; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
393 submit_button( __( 'Filter', 'surecart' ), '', 'filter_action', false, array( 'id' => 'filter-by-mode-submit' ) );
394 }
395 }
396
397 ?>
398 </div>
399
400 <?php
401 /**
402 * Fires immediately following the closing "actions" div in the tablenav
403 * for the affiliate referrals list table.
404 *
405 * @param string $which The location of the extra table nav markup: 'top' or 'bottom'.
406 */
407 do_action( 'manage_affiliate_referrals_extra_tablenav', $which );
408 }
409
410 /**
411 * Get filtered status / default status.
412 *
413 * @return string|null
414 */
415 private function getFilteredStatus() {
416 if ( empty( $_GET['status'] ) || 'all' === $_GET['status'] ) {
417 return null;
418 }
419
420 // transform in payout status.
421 if ( 'in_payout' === $_GET['status'] ) {
422 return 'paid';
423 }
424
425 return sanitize_text_field( wp_unslash( $_GET['status'] ) );
426 }
427
428 /**
429 * Get all statuses.
430 *
431 * @return array
432 */
433 private function getStatuses(): array {
434 return array(
435 'all' => __( 'All', 'surecart' ),
436 'reviewing' => __( 'Reviewing', 'surecart' ),
437 'approved' => __( 'Approved', 'surecart' ),
438 'denied' => __( 'Denied', 'surecart' ),
439 'canceled' => __( 'Canceled', 'surecart' ),
440 'in_payout' => __( 'In Payout', 'surecart' ),
441 );
442 }
443
444 /**
445 * Get action url.
446 *
447 * @param int $id The id.
448 * @param string $action The action.
449 *
450 * @return string
451 */
452 public function get_action_url( $id, $action ) {
453 return esc_url(
454 add_query_arg(
455 array_filter(
456 [
457 'action' => $action,
458 'nonce' => wp_create_nonce( $action . '_affiliation' ),
459 'id' => $id,
460 ]
461 ),
462 esc_url_raw( admin_url( 'admin.php?page=sc-affiliate-referrals' ) )
463 )
464 );
465 }
466 }
467