PluginProbe ʕ •ᴥ•ʔ
SureCart – Ecommerce Made Easy For Selling Physical Products, Digital Downloads, Subscriptions, Donations, & Payments / 3.0.0-beta2
SureCart – Ecommerce Made Easy For Selling Physical Products, Digital Downloads, Subscriptions, Donations, & Payments v3.0.0-beta2
4.7.0 4.6.6 4.6.5 4.6.4 4.6.3 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 2 years ago AffiliationReferralsListTable.php 2 years ago AffiliationReferralsScriptsController.php 2 years ago
AffiliationReferralsListTable.php
427 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
9 /**
10 * Create a new table class that will extend the WP_List_Table
11 */
12 class AffiliationReferralsListTable extends ListTable {
13
14 /**
15 * Checkbox
16 *
17 * @var boolean
18 */
19 public $checkbox = true;
20
21 /**
22 * Error
23 *
24 * @var string
25 */
26 public $error = '';
27
28 /**
29 * Pages
30 *
31 * @var array
32 */
33 public $pages = array();
34
35 /**
36 * Prepare the items for the table to process
37 *
38 * @return void
39 */
40 public function prepare_items() {
41 $columns = $this->get_columns();
42 $hidden = $this->get_hidden_columns();
43 $sortable = $this->get_sortable_columns();
44
45 $this->_column_headers = array( $columns, $hidden, $sortable );
46
47 $query = $this->table_data();
48
49 if ( is_wp_error( $query ) ) {
50 $this->error = $query->get_error_message();
51 $this->items = array();
52 return;
53 }
54
55 $this->set_pagination_args(
56 array(
57 'total_items' => $query->pagination->count,
58 'per_page' => $this->get_items_per_page( 'affiliate_referrals' ),
59 )
60 );
61
62 $this->items = $query->data;
63 }
64
65 /**
66 * Get views for the list table status links.
67 *
68 * @global int $post_id
69 * @global string $comment_status
70 * @global string $comment_type
71 *
72 * @return string
73 */
74 protected function get_views() {
75 foreach ( $this->getStatuses() as $status => $label ) {
76 $link = admin_url( 'admin.php?page=sc-affiliate-referrals' );
77
78 $current_link_attributes = '';
79
80 if ( ! empty( $_GET['status'] ) ) {
81 if ( $status === $_GET['status'] ) {
82 $current_link_attributes = ' class="current" aria-current="page"';
83 }
84 } elseif ( 'all' === $status ) {
85 $current_link_attributes = ' class="current" aria-current="page"';
86 }
87
88 $link = add_query_arg( 'status', $status, $link );
89 if ( isset( $_GET['live_mode'] ) ) {
90 $link = add_query_arg( 'live_mode', sanitize_text_field($_GET['live_mode']), $link );
91 }
92
93 $link = esc_url( $link );
94
95 $status_links[ $status ] = "<a href='$link'$current_link_attributes>" . $label . '</a>';
96 }
97
98 /**
99 * Filters the affiliation referrals status links.
100 *
101 * @since 2.5.0
102 * @since 5.1.0 The 'Mine' link was added.
103 *
104 * @param string[] $status_links An associative array of fully-formed affiliation referrals status links. Includes 'All', 'Reviewing', 'Approved', 'Denied', 'Cancelled' and 'Paid Out'.
105 * */
106 return apply_filters( 'sc_affiliation_referrals_status_links', $status_links );
107 }
108
109 /**
110 * Override the parent columns method. Defines the columns to use in your listing table
111 *
112 * @return array
113 */
114 public function get_columns() {
115 return array(
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 }
127
128 /**
129 * Handle the date column.
130 *
131 * @param \SureCart\Models\Referral $referral The Referral model.
132 *
133 * @return string
134 */
135 public function column_date( $referral ) {
136 ob_start();
137 echo wp_kses_post( date_i18n( get_option( 'date_format' ), $referral->created_at ) );
138 ?>
139 <?php
140 echo wp_kses_post(
141 $this->row_actions(
142 array_filter(
143 array(
144 'view' => '<a href="' . esc_url( \SureCart::getUrl()->edit( 'affiliate-referrals', $referral->id ) ) . '" aria-label="' . esc_attr__( 'View', 'surecart' ) . '">' . esc_html__( 'View', 'surecart' ) . '</a>',
145 'edit' => '<a href="' . esc_url( \SureCart::getUrl()->edit( 'affiliate-referrals', $referral->id ) ) . '" aria-label="' . esc_attr__( 'Edit', 'surecart' ) . '">' . esc_html__( 'Edit', 'surecart' ) . '</a>',
146 'approve' => '<a href="' . esc_url( $this->get_action_url( $referral->id, 'approve' ) ) . '" aria-label="' . esc_attr__( 'Approve', 'surecart' ) . '">' . esc_html__( 'Approve', 'surecart' ) . '</a>',
147 'deny' => '<a href="' . esc_url( $this->get_action_url( $referral->id, 'deny' ) ) . '" aria-label="' . esc_attr__( 'Deny', 'surecart' ) . '">' . esc_html__( 'Deny', 'surecart' ) . '</a>',
148 '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>',
149 'delete' => '<a href="' . esc_url( $this->get_action_url( $referral->id, 'delete' ) ) . '" aria-label="' . esc_attr__( 'Delete', 'surecart' ) . '">' . esc_html__( 'Delete', 'surecart' ) . '</a>',
150 ),
151 function ( $action, $key ) use ( $referral ) {
152 // only view a paid referral.
153 if ( 'view' === $key && 'paid' !== $referral->status ) {
154 return false;
155 }
156
157 // don't edit a paid referral.
158 if ( 'paid' === $referral->status && 'view' !== $key ) {
159 return false;
160 }
161
162 // don't approve approved referral.
163 if ( 'approve' === $key && 'approved' === $referral->status ) {
164 return false;
165 }
166
167 // don't deny denied referral.
168 if ( 'deny' === $key && 'denied' === $referral->status ) {
169 return false;
170 }
171
172 // don't make reviewing reviewing referral.
173 if ( 'make_reviewing' === $key && 'reviewing' === $referral->status ) {
174 return false;
175 }
176
177 return true;
178 },
179 ARRAY_FILTER_USE_BOTH
180 )
181 )
182 )
183 ?>
184 <?php
185 return ob_get_clean();
186 }
187
188 /**
189 * Handle the status column.
190 *
191 * @param \SureCart\Models\Referral $referral The Referral model.
192 *
193 * @return string
194 */
195 public function column_status( $referral ) {
196 if ( empty( $referral->status_display_text ) ) {
197 return '';
198 }
199 ob_start();
200 ?>
201 <sc-tag type="<?php echo esc_attr( $referral->status_type ); ?>">
202 <?php echo esc_html( $referral->status_display_text ); ?>
203 </sc-tag>
204 <?php
205 return ob_get_clean();
206 }
207
208 /**
209 * Handle the payout status column.
210 *
211 * @param \SureCart\Models\Referral $referral The Referral model.
212 *
213 * @return string
214 */
215 public function column_payout_status( $referral ) {
216 if ( empty( $referral->payout ) ) {
217 return '_';
218 }
219
220 $type = 'completed' === $referral->payout->status ? 'success' : 'warning';
221
222 return '<sc-tag type="' . $type . '">' . $referral->payout->status_display_text . ' </sc-tag>';
223 }
224
225 /**
226 * Handle the payout date column.
227 *
228 * @param \SureCart\Models\Referral $referral The Referral model.
229 *
230 * @return string
231 */
232 public function column_payout_date( $referral ) {
233 if ( empty( $referral->payout ) ) {
234 return '_';
235 }
236
237 return date_i18n( get_option( 'date_format' ), $referral->payout->created_at );
238 }
239
240
241 /**
242 * Handle the affiliate column.
243 *
244 * @param \SureCart\Models\Referral $referral The Referral model.
245 *
246 * @return string
247 */
248 public function column_affiliate( $referral ) {
249 $affiliation = $referral->affiliation ?? null;
250 if ( empty( $affiliation->id ) ) {
251 return '-';
252 }
253 ob_start();
254 ?>
255 <div class="sc-affiliate-name">
256 <a href="<?php echo esc_url( \SureCart::getUrl()->edit( 'affiliates', $affiliation->id ) ); ?>">
257 <?php echo esc_html( $affiliation->display_name ); ?>
258 </a>
259 </div>
260 <?php
261 return ob_get_clean();
262 }
263
264 /**
265 * Handle the description column.
266 *
267 * @param \SureCart\Models\Referral $referral The Referral model.
268 *
269 * @return string
270 */
271 public function column_description( $referral ) {
272 return esc_html( $referral->description );
273 }
274
275 /**
276 * Handle the order column.
277 *
278 * @param \SureCart\Models\Referral $referral The Referral model.
279 *
280 * @return string
281 */
282 public function column_order( $referral ) {
283 $checkout = $referral->checkout ?? null;
284 if ( empty( $checkout->order->id ) ) {
285 return '-';
286 }
287 ob_start();
288 ?>
289 <a aria-label="<?php echo esc_attr__( 'View Order', 'surecart' ); ?>" href="<?php echo esc_url( \SureCart::getUrl()->edit( 'order', $checkout->order->id ) ); ?>">
290 #<?php echo esc_html( $checkout->order->number ?? $checkout->order->id ); ?>
291 </a>
292 <?php
293 return ob_get_clean();
294 }
295
296 /**
297 * Handle the commission column.
298 *
299 * @param \SureCart\Models\Referral $referral The Referral model.
300 *
301 * @return string
302 */
303 public function column_commission( $referral ) {
304 return Currency::format( $referral->commission_amount, $referral->currency );
305 }
306
307 /**
308 * Get the table data
309 *
310 * @return \SureCart\Models\Collection;
311 */
312 private function table_data() {
313 return Referral::where(
314 array(
315 'query' => $this->get_search_query(),
316 'status' => [ $this->getFilteredStatus() ],
317 'live_mode' => 'false' !== sanitize_text_field( wp_unslash( $_GET['live_mode'] ?? '' ) ), // phpcs:ignore WordPress.Security.NonceVerification.Recommended
318 'expand' => [
319 'affiliation',
320 'checkout',
321 'checkout.order',
322 'payout',
323 ],
324 )
325 )->paginate(
326 array(
327 'per_page' => $this->get_items_per_page( 'affiliate_referrals' ),
328 'page' => $this->get_pagenum(),
329 )
330 );
331 }
332
333 /**
334 * Nothing found.
335 *
336 * @return void
337 */
338 public function no_items() {
339 if ( $this->error ) {
340 echo esc_html( $this->error );
341 return;
342 }
343 echo esc_html_e( 'No affiliate referrals found . ', 'surecart' );
344 }
345
346 /**
347 * Displays extra table navigation.
348 *
349 * @param string $which Top or bottom placement.
350 */
351 protected function extra_tablenav( $which ) {
352 ?>
353 <input type="hidden" name="page" value="sc-affiliate-requests" />
354
355 <?php if ( ! empty( $_GET['status'] ) ) : // phpcs:ignore WordPress.Security.NonceVerification.Recommended ?>
356 <input type="hidden" name="status" value="<?php echo esc_attr( $_GET['status'] ); ?>" />
357 <?php endif; ?>
358
359 <?php
360 /**
361 * Fires immediately following the closing "actions" div in the tablenav
362 * for the affiliate referrals list table.
363 *
364 * @param string $which The location of the extra table nav markup: 'top' or 'bottom'.
365 */
366 do_action( 'manage_affiliate_referrals_extra_tablenav', $which );
367 }
368
369 /**
370 * Get filtered status / default status.
371 *
372 * @return string|null
373 */
374 private function getFilteredStatus() {
375 if ( empty( $_GET['status'] ) || 'all' === $_GET['status'] ) {
376 return null;
377 }
378
379 // transform in payout status.
380 if ( 'in_payout' === $_GET['status'] ) {
381 return 'paid';
382 }
383
384 return sanitize_text_field( wp_unslash( $_GET['status'] ) );
385 }
386
387 /**
388 * Get all statuses.
389 *
390 * @return array
391 */
392 private function getStatuses(): array {
393 return array(
394 'all' => __( 'All', 'surecart' ),
395 'reviewing' => __( 'Reviewing', 'surecart' ),
396 'approved' => __( 'Approved', 'surecart' ),
397 'denied' => __( 'Denied', 'surecart' ),
398 'canceled' => __( 'Canceled', 'surecart' ),
399 'in_payout' => __( 'In Payout', 'surecart' ),
400 );
401 }
402
403 /**
404 * Get action url.
405 *
406 * @param int $id The id.
407 * @param string $action The action.
408 *
409 * @return string
410 */
411 public function get_action_url( $id, $action ) {
412 return esc_url(
413 add_query_arg(
414 array_filter(
415 [
416 'action' => $action,
417 'nonce' => wp_create_nonce( $action . '_affiliation' ),
418 'id' => $id,
419 'live_mode' => $_GET['live_mode'] ?? '',
420 ]
421 ),
422 esc_url_raw( admin_url( 'admin.php?page=sc-affiliate-referrals' ) )
423 )
424 );
425 }
426 }
427