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 / AffiliationPayouts / AffiliationPayoutsListTable.php
surecart / app / src / Controllers / Admin / AffiliationPayouts Last commit date
AffiliationPayoutsController.php 10 months ago AffiliationPayoutsListTable.php 1 year ago AffiliationPayoutsScriptsController.php 2 years ago
AffiliationPayoutsListTable.php
346 lines
1 <?php
2
3 namespace SureCart\Controllers\Admin\AffiliationPayouts;
4
5 use SureCart\Controllers\Admin\Tables\ListTable;
6 use SureCart\Models\Payout;
7
8 /**
9 * Create a new table class that will extend the WP_List_Table
10 */
11 class AffiliationPayoutsListTable extends ListTable {
12
13 /**
14 * Checkbox column.
15 *
16 * @var boolean
17 */
18 public $checkbox = true;
19
20 /**
21 * Error message.
22 *
23 * @var string
24 */
25 public $error = '';
26
27 /**
28 * Pages.
29 *
30 * @var array
31 */
32 public $pages = array();
33
34 /**
35 * Prepare the items for the table to process
36 *
37 * @return void
38 */
39 public function prepare_items() {
40 $columns = $this->get_columns();
41 $hidden = $this->get_hidden_columns();
42 $sortable = $this->get_sortable_columns();
43
44 $this->_column_headers = array( $columns, $hidden, $sortable );
45
46 $query = $this->table_data();
47
48 if ( is_wp_error( $query ) ) {
49 $this->error = $query->get_error_message();
50 $this->items = array();
51 return;
52 }
53
54 $this->set_pagination_args(
55 array(
56 'total_items' => $query->pagination->count,
57 'per_page' => $this->get_items_per_page( 'affiliate_payouts' ),
58 )
59 );
60
61 $this->items = $query->data;
62 }
63
64 /**
65 * Get views for the list table status links.
66 *
67 * @global int $post_id
68 * @global string $comment_status
69 * @global string $comment_type
70 */
71 protected function get_views() {
72 foreach ( $this->getStatuses() as $status => $label ) {
73 $current_link_attributes = '';
74 $link = admin_url( 'admin.php?page=sc-affiliate-payouts' );
75
76 if ( ! empty( $_GET['status'] ) ) {
77 if ( $status === $_GET['status'] ) {
78 $current_link_attributes = ' class="current" aria-current="page"';
79 }
80 } elseif ( 'all' === $status ) {
81 $current_link_attributes = ' class="current" aria-current="page"';
82 }
83
84 $link = add_query_arg( 'status', $status, $link );
85
86 $link = esc_url( $link );
87
88 $status_links[ $status ] = "<a href='$link'$current_link_attributes>" . $label . '</a>';
89 }
90
91 /**
92 * Filters the comment status links.
93 *
94 * @since 2.5.0
95 * @since 5.1.0 The 'Mine' link was added.
96 *
97 * @param string[] $status_links An associative array of fully-formed comment status links. Includes 'All', 'Mine','Pending', 'Approved', 'Spam', and 'Trash'.
98 * */
99 return apply_filters( 'payout_status_links', $status_links );
100 }
101
102 /**
103 * Override the parent columns method. Defines the columns to use in your listing table
104 *
105 * @return array
106 */
107 public function get_columns() {
108 return array_merge(
109 [
110 'date' => __( 'Date', 'surecart' ),
111 'status' => __( 'Status', 'surecart' ),
112 'affiliate' => __( 'Affiliate', 'surecart' ),
113 'payout_email' => __( 'Payout Email', 'surecart' ),
114 'period_end' => __( 'Period End', 'surecart' ),
115 'referrals' => __( 'Referrals', 'surecart' ),
116 'amount' => __( 'Amount', 'surecart' ),
117 ],
118 parent::get_columns()
119 );
120 }
121
122 /**
123 * Handle the date column.
124 *
125 * @param \SureCart\Models\Payout $payout The Payout model.
126 *
127 * @return string
128 */
129 public function column_date( $payout ) {
130 $date = esc_attr( $payout->created_at_date_time );
131
132 $actions = wp_kses_post(
133 $this->row_actions(
134 array_filter(
135 array(
136 'complete' => '<a href="' . esc_url( $this->get_action_url( $payout->id, 'complete' ) ) . '">' . esc_html__( 'Complete', 'surecart' ) . '</a>',
137 'make_processing' => '<a href="' . esc_url( $this->get_action_url( $payout->id, 'make_processing' ) ) . '">' . esc_html__( 'Make Processing', 'surecart' ) . '</a>',
138 'delete' => '<a href="' . esc_url( $this->get_action_url( $payout->id, 'delete' ) ) . '">' . esc_html__( 'Delete', 'surecart' ) . '</a>',
139 ),
140 function ( $action, $key ) use ( $payout ) {
141 if ( 'complete' === $key && 'completed' === $payout->status ) {
142 return false;
143 }
144
145 if ( 'make_processing' === $key && 'processing' === $payout->status ) {
146 return false;
147 }
148
149 return true;
150 },
151 ARRAY_FILTER_USE_BOTH
152 )
153 )
154 );
155
156 return $date . $actions;
157 }
158
159 /**
160 * Handle the status column.
161 *
162 * @param \SureCart\Models\Payout $payout The Payout model.
163 *
164 * @return string
165 */
166 public function column_status( $payout ) {
167 $type = 'completed' === $payout->status ? 'success' : 'warning';
168
169 return '<sc-tag type="' . $type . '">' . $payout->status_display_text . ' </sc-tag>';
170 }
171
172 /**
173 * Handle the affiliate column.
174 *
175 * @param \SureCart\Models\Payout $payout The Payout model.
176 *
177 * @return string
178 */
179 public function column_affiliate( $payout ) {
180 $affiliation = $payout->affiliation ?? null;
181 if ( empty( $affiliation->id ) ) {
182 return '';
183 }
184
185 ob_start();
186 ?>
187 <div class="sc-affiliate-name">
188 <a href="<?php echo esc_url( \SureCart::getUrl()->edit( 'affiliates', $affiliation->id ) ); ?>">
189 <?php echo esc_html( $affiliation->display_name ); ?>
190 </a>
191 </div>
192 <?php
193 return ob_get_clean();
194 }
195
196 /**
197 * Handle the payout email column.
198 *
199 * @param \SureCart\Models\Payout $payout The Payout model.
200 *
201 * @return string
202 */
203 public function column_payout_email( $payout ) {
204 return esc_html( $payout->affiliation->payout_email );
205 }
206
207 /**
208 * Handle the period end column.
209 *
210 * @param \SureCart\Models\Payout $payout The Payout model.
211 *
212 * @return string
213 */
214 public function column_period_end( $payout ) {
215 return $payout->end_at_date;
216 }
217
218 /**
219 * Handle the referrals column.
220 *
221 * @param \SureCart\Models\Payout $payout The Payout model.
222 *
223 * @return string
224 */
225 public function column_referrals( $payout ) {
226 return (int) $payout->referrals->pagination->count;
227 }
228
229 /**
230 * Handle the amount column.
231 *
232 * @param \SureCart\Models\Payout $payout The Payout model.
233 *
234 * @return string
235 */
236 public function column_amount( $payout ) {
237 return $payout->total_commission_display_amount;
238 }
239
240 /**
241 * Get the table data
242 *
243 * @return \SureCart\Models\Collection
244 */
245 private function table_data() {
246 return Payout::where(
247 array(
248 'query' => $this->get_search_query(),
249 'status' => [ $this->getFilteredStatus() ],
250 'expand' => [
251 'affiliation',
252 'referrals',
253 ],
254 )
255 )->paginate(
256 array(
257 'per_page' => $this->get_items_per_page( 'affiliate_payouts' ),
258 'page' => $this->get_pagenum(),
259 )
260 );
261 }
262
263 /**
264 * Nothing found.
265 *
266 * @return void
267 */
268 public function no_items() {
269 if ( $this->error ) {
270 echo esc_html( $this->error );
271 return;
272 }
273 echo esc_html_e( 'No affiliate payouts found.', 'surecart' );
274 }
275
276 /**
277 * Displays extra table navigation.
278 *
279 * @param string $which Top or bottom placement.
280 */
281 protected function extra_tablenav( $which ) {
282 ?>
283 <input type="hidden" name="page" value="sc-affiliate-payouts" />
284
285 <?php if ( ! empty( $_GET['status'] ) ) : // phpcs:ignore WordPress.Security.NonceVerification.Recommended ?>
286 <input type="hidden" name="status" value="<?php echo esc_attr( $_GET['status'] ); ?>" />
287 <?php endif; ?>
288
289 <?php
290 /**
291 * Fires immediately following the closing "actions" div in the tablenav
292 * for the affiliate_payouts list table.
293 *
294 * @param string $which The location of the extra table nav markup: 'top' or 'bottom'.
295 */
296 do_action( 'manage_affiliate_payouts_extra_tablenav', $which );
297 }
298
299 /**
300 * Get filtered status / default status.
301 *
302 * @return string|null
303 */
304 private function getFilteredStatus() {
305 if ( empty( $_GET['status'] ) || 'all' === $_GET['status'] ) {
306 return null;
307 }
308
309 return sanitize_text_field( wp_unslash( $_GET['status'] ) );
310 }
311
312 /**
313 * Get all statuses.
314 *
315 * @return array
316 */
317 private function getStatuses(): array {
318 return array(
319 'all' => __( 'All', 'surecart' ),
320 'processing' => __( 'Processing', 'surecart' ),
321 'completed' => __( 'Completed', 'surecart' ),
322 );
323 }
324
325 /**
326 * Get action url.
327 *
328 * @param int $id The id.
329 * @param string $action The action.
330 *
331 * @return string
332 */
333 public function get_action_url( $id, $action ) {
334 return esc_url(
335 add_query_arg(
336 [
337 'action' => $action,
338 'nonce' => wp_create_nonce( $action . '_affiliation_payout' ),
339 'id' => $id,
340 ],
341 esc_url_raw( admin_url( 'admin.php?page=sc-affiliate-payouts' ) )
342 )
343 );
344 }
345 }
346