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.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 2 years ago AffiliationPayoutsListTable.php 1 year ago AffiliationPayoutsScriptsController.php 2 years ago
AffiliationPayoutsListTable.php
343 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(
109 'date' => __( 'Date', 'surecart' ),
110 'status' => __( 'Status', 'surecart' ),
111 'affiliate' => __( 'Affiliate', 'surecart' ),
112 'payout_email' => __( 'Payout Email', 'surecart' ),
113 'period_end' => __( 'Period End', 'surecart' ),
114 'referrals' => __( 'Referrals', 'surecart' ),
115 'amount' => __( 'Amount', 'surecart' ),
116 );
117 }
118
119 /**
120 * Handle the date column.
121 *
122 * @param \SureCart\Models\Payout $payout The Payout model.
123 *
124 * @return string
125 */
126 public function column_date( $payout ) {
127 $date = date_i18n( get_option( 'date_format' ), $payout->created_at );
128
129 $actions = wp_kses_post(
130 $this->row_actions(
131 array_filter(
132 array(
133 'complete' => '<a href="' . esc_url( $this->get_action_url( $payout->id, 'complete' ) ) . '">' . esc_html__( 'Complete', 'surecart' ) . '</a>',
134 'make_processing' => '<a href="' . esc_url( $this->get_action_url( $payout->id, 'make_processing' ) ) . '">' . esc_html__( 'Make Processing', 'surecart' ) . '</a>',
135 'delete' => '<a href="' . esc_url( $this->get_action_url( $payout->id, 'delete' ) ) . '">' . esc_html__( 'Delete', 'surecart' ) . '</a>',
136 ),
137 function( $action, $key ) use ( $payout ) {
138 if ( 'complete' === $key && 'completed' === $payout->status ) {
139 return false;
140 }
141
142 if ( 'make_processing' === $key && 'processing' === $payout->status ) {
143 return false;
144 }
145
146 return true;
147 },
148 ARRAY_FILTER_USE_BOTH
149 )
150 )
151 );
152
153 return $date . $actions;
154 }
155
156 /**
157 * Handle the status column.
158 *
159 * @param \SureCart\Models\Payout $payout The Payout model.
160 *
161 * @return string
162 */
163 public function column_status( $payout ) {
164 $type = 'completed' === $payout->status ? 'success' : 'warning';
165
166 return '<sc-tag type="' . $type . '">' . $payout->status_display_text . ' </sc-tag>';
167 }
168
169 /**
170 * Handle the affiliate column.
171 *
172 * @param \SureCart\Models\Payout $payout The Payout model.
173 *
174 * @return string
175 */
176 public function column_affiliate( $payout ) {
177 $affiliation = $payout->affiliation ?? null;
178 if ( empty( $affiliation->id ) ) {
179 return '';
180 }
181
182 ob_start();
183 ?>
184 <div class="sc-affiliate-name">
185 <a href="<?php echo esc_url( \SureCart::getUrl()->edit( 'affiliates', $affiliation->id ) ); ?>">
186 <?php echo esc_html( $affiliation->display_name ); ?>
187 </a>
188 </div>
189 <?php
190 return ob_get_clean();
191 }
192
193 /**
194 * Handle the payout email column.
195 *
196 * @param \SureCart\Models\Payout $payout The Payout model.
197 *
198 * @return string
199 */
200 public function column_payout_email( $payout ) {
201 return esc_html( $payout->affiliation->payout_email );
202 }
203
204 /**
205 * Handle the period end column.
206 *
207 * @param \SureCart\Models\Payout $payout The Payout model.
208 *
209 * @return string
210 */
211 public function column_period_end( $payout ) {
212 return "<sc-format-date date='$payout->end_date' type='timestamp' month='short' day='numeric' year='numeric' ></sc-format-date>";
213 }
214
215 /**
216 * Handle the referrals column.
217 *
218 * @param \SureCart\Models\Payout $payout The Payout model.
219 *
220 * @return string
221 */
222 public function column_referrals( $payout ) {
223 return (int) $payout->referrals->pagination->count;
224 }
225
226 /**
227 * Handle the amount column.
228 *
229 * @param \SureCart\Models\Payout $payout The Payout model.
230 *
231 * @return string
232 */
233 public function column_amount( $payout ) {
234 return '<sc-format-number type="currency" currency="' . $payout->currency . '" value="' . $payout->total_commission_amount . '"></sc-format-number>';
235 }
236
237 /**
238 * Get the table data
239 *
240 * @return \SureCart\Models\Collection
241 */
242 private function table_data() {
243 return Payout::where(
244 array(
245 'query' => $this->get_search_query(),
246 'status' => [ $this->getFilteredStatus() ],
247 'expand' => [
248 'affiliation',
249 'referrals',
250 ],
251 )
252 )->paginate(
253 array(
254 'per_page' => $this->get_items_per_page( 'affiliate_payouts' ),
255 'page' => $this->get_pagenum(),
256 )
257 );
258 }
259
260 /**
261 * Nothing found.
262 *
263 * @return void
264 */
265 public function no_items() {
266 if ( $this->error ) {
267 echo esc_html( $this->error );
268 return;
269 }
270 echo esc_html_e( 'No affiliate payouts found.', 'surecart' );
271 }
272
273 /**
274 * Displays extra table navigation.
275 *
276 * @param string $which Top or bottom placement.
277 */
278 protected function extra_tablenav( $which ) {
279 ?>
280 <input type="hidden" name="page" value="sc-affiliate-payouts" />
281
282 <?php if ( ! empty( $_GET['status'] ) ) : // phpcs:ignore WordPress.Security.NonceVerification.Recommended ?>
283 <input type="hidden" name="status" value="<?php echo esc_attr( $_GET['status'] ); ?>" />
284 <?php endif; ?>
285
286 <?php
287 /**
288 * Fires immediately following the closing "actions" div in the tablenav
289 * for the affiliate_payouts list table.
290 *
291 * @param string $which The location of the extra table nav markup: 'top' or 'bottom'.
292 */
293 do_action( 'manage_affiliate_payouts_extra_tablenav', $which );
294 }
295
296 /**
297 * Get filtered status / default status.
298 *
299 * @return string|null
300 */
301 private function getFilteredStatus() {
302 if ( empty( $_GET['status'] ) || 'all' === $_GET['status'] ) {
303 return null;
304 }
305
306 return sanitize_text_field( wp_unslash( $_GET['status'] ) );
307 }
308
309 /**
310 * Get all statuses.
311 *
312 * @return array
313 */
314 private function getStatuses(): array {
315 return array(
316 'all' => __( 'All', 'surecart' ),
317 'processing' => __( 'Processing', 'surecart' ),
318 'completed' => __( 'Completed', 'surecart' ),
319 );
320 }
321
322 /**
323 * Get action url.
324 *
325 * @param int $id The id.
326 * @param string $action The action.
327 *
328 * @return string
329 */
330 public function get_action_url( $id, $action ) {
331 return esc_url(
332 add_query_arg(
333 [
334 'action' => $action,
335 'nonce' => wp_create_nonce( $action . '_affiliation_payout' ),
336 'id' => $id,
337 ],
338 esc_url_raw( admin_url( 'admin.php?page=sc-affiliate-payouts' ) )
339 )
340 );
341 }
342 }
343