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 / Affiliations / AffiliationsListTable.php
surecart / app / src / Controllers / Admin / Affiliations Last commit date
AffiliationsController.php 2 years ago AffiliationsListTable.php 2 months ago AffiliationsScriptsController.php 2 years ago
AffiliationsListTable.php
352 lines
1 <?php
2
3 namespace SureCart\Controllers\Admin\Affiliations;
4
5 use SureCart\Controllers\Admin\Tables\ListTable;
6 use SureCart\Models\Affiliation;
7 use WP_Error;
8
9 /**
10 * Affiliations List Table
11 */
12 class AffiliationsListTable extends ListTable {
13 public $checkbox = true;
14 public $error = '';
15 public $pages = array();
16
17 /**
18 * Prepare the items for the table to process
19 *
20 * @return void
21 */
22 public function prepare_items() {
23 $columns = $this->get_columns();
24 $hidden = $this->get_hidden_columns();
25 $sortable = $this->get_sortable_columns();
26
27 $this->_column_headers = array( $columns, $hidden, $sortable );
28
29 $query = $this->table_data();
30
31 if ( is_wp_error( $query ) ) {
32 $this->error = $query->get_error_message();
33 $this->items = array();
34 return;
35 }
36
37 $this->set_pagination_args(
38 array(
39 'total_items' => $query->pagination->count,
40 'per_page' => $this->get_items_per_page( 'affiliations' ),
41 )
42 );
43
44 $this->items = $query->data;
45 }
46
47 /**
48 * Get views for the list table status links.
49 *
50 * @global int $post_id
51 * @global string $comment_status
52 * @global string $comment_type
53 */
54 protected function get_views() {
55 foreach ( $this->getStatuses() as $status => $label ) {
56 $link = admin_url( 'admin.php?page=sc-affiliates' );
57 $current_link_attributes = '';
58
59 if ( ! empty( $_GET['status'] ) ) {
60 if ( $status === $_GET['status'] ) {
61 $current_link_attributes = ' class="current" aria-current="page"';
62 }
63 } elseif ( 'all' === $status ) {
64 $current_link_attributes = ' class="current" aria-current="page"';
65 }
66
67 $link = add_query_arg( 'status', $status, $link );
68
69 $link = esc_url( $link );
70
71 $status_links[ $status ] = "<a href='$link'$current_link_attributes>" . $label . '</a>';
72 }
73
74 /**
75 * Filters the comment status links.
76 *
77 * @since 2.5.0
78 * @since 5.1.0 The 'Mine' link was added.
79 *
80 * @param string[] $status_links An associative array of fully-formed comment status links. Includes 'All', 'Mine',
81 * 'Pending', 'Approved', 'Spam', and 'Trash'.
82 */
83 return apply_filters( 'comment_status_links', $status_links );
84 }
85
86 /**
87 * Override the parent columns method. Defines the columns to use in your listing table
88 *
89 * @return array
90 */
91 public function get_columns() {
92 return array_merge(
93 [
94 'name' => __( 'Name', 'surecart' ),
95 'email' => __( 'Email', 'surecart' ),
96 'status' => __( 'Status', 'surecart' ),
97 'clicks' => __( 'Clicks', 'surecart' ),
98 'referrals' => __( 'Referrals', 'surecart' ),
99 'total_commission_amount' => __( 'Total Earnings', 'surecart' ),
100 'total_not_paid_commission_amount' => __( 'Unpaid Earnings', 'surecart' ),
101 'date' => __( 'Date', 'surecart' ),
102 ],
103 parent::get_columns()
104 );
105 }
106
107 /**
108 * Define which columns are hidden.
109 *
110 * @return array
111 */
112 public function get_hidden_columns() {
113 return array();
114 }
115
116 /**
117 * Get the table data.
118 *
119 * @return object|WP_Error
120 */
121 private function table_data() {
122 $affiliates_query = Affiliation::where(
123 array(
124 'active' => $this->getFilteredStatus(),
125 'query' => $this->get_search_query(),
126 'expand' => [
127 'clicks',
128 'referrals',
129 ],
130 )
131 );
132
133 return $affiliates_query->paginate(
134 array(
135 'per_page' => $this->get_items_per_page( 'affiliate' ),
136 'page' => $this->get_pagenum(),
137 )
138 );
139 }
140
141 /**
142 * Nothing found.
143 *
144 * @return void
145 */
146 public function no_items() {
147 if ( $this->error ) {
148 echo esc_html( $this->error );
149 return;
150 }
151 echo esc_html_e( 'No affiliates found.', 'surecart' );
152 }
153
154 /**
155 * Published column
156 *
157 * @param \SureCart\Models\Affiliation $affiliation Affiliation model.
158 *
159 * @return string
160 */
161 public function column_status( $affiliation ) {
162 ob_start();
163 ?>
164 <sc-tag type="<?php echo esc_attr( $affiliation->status_type ); ?>">
165 <?php echo esc_html( $affiliation->status_display_text ); ?>
166 </sc-tag>
167 <?php
168 return ob_get_clean();
169 }
170
171 /**
172 * Total clicks column.
173 *
174 * @param \SureCart\Models\Affiliation $affiliation Affiliation model.
175 * @return int
176 */
177 public function column_clicks( $affiliation ) {
178 return esc_html( $affiliation->clicks->pagination->count ?? 0 );
179 }
180
181 /**
182 * Total referrals column.
183 *
184 * @param \SureCart\Models\Affiliation $affiliation Affiliation model.
185 * @return int
186 */
187 public function column_referrals( $affiliation ) {
188 return esc_html( $affiliation->referrals->pagination->count ?? 0 );
189 }
190
191 /**
192 * Total commission amount column.
193 *
194 * @param \SureCart\Models\Affiliation $affiliation Affiliation model.
195 * @return string
196 */
197 public function column_total_commission_amount( $affiliation ) {
198 return $affiliation->total_commission_display_amount;
199 }
200
201 /**
202 * Total unpaid commission amount column.
203 *
204 * @param \SureCart\Models\Affiliation $affiliation Affiliation model.
205 * @return string
206 */
207 public function column_total_not_paid_commission_amount( $affiliation ) {
208 return $affiliation->total_not_paid_commission_display_amount;
209 }
210
211 /**
212 * Name column.
213 *
214 * @param \SureCart\Models\Affiliation $affiliation Affiliation model.
215 *
216 * @return string
217 */
218 public function column_name( $affiliation ) {
219 ob_start();
220 ?>
221
222 <div class="sc-affiliate-name">
223 <a href="<?php echo esc_url( \SureCart::getUrl()->edit( 'affiliates', $affiliation->id ) ); ?>">
224 <?php echo esc_html( $affiliation->first_name . ' ' . $affiliation->last_name ); ?>
225 </a>
226 <?php
227 echo $this->row_actions(
228 array(
229 'view' => '<a href="' . esc_url( \SureCart::getUrl()->edit( 'affiliates', $affiliation->id ) ) . '" aria-label="' . esc_attr__( 'View Affiliate', 'surecart' ) . '">' . esc_html__( 'View Details', 'surecart' ) . '</a>',
230 'trash' => $this->action_toggle_activate( $affiliation ),
231 )
232 );
233 ?>
234 </div>
235 <?php
236 return ob_get_clean();
237 }
238
239 /**
240 * Define what data to show on each column of the table
241 *
242 * @param \SureCart\Models\Affiliation $affiliation Affiliation model.
243 * @param string $column_name - Current column name.
244 *
245 * @return mixed
246 */
247 public function column_default( $affiliation, $column_name ) {
248 // Call the parent method to handle custom columns
249 parent::column_default( $affiliation, $column_name );
250
251 switch ( $column_name ) {
252 case 'description':
253 case 'email':
254 return esc_html( $affiliation->$column_name ?? '' );
255 }
256 }
257
258 /**
259 * Displays extra table navigation.
260 *
261 * @param string $which Top or bottom placement.
262 */
263 protected function extra_tablenav( $which ) {
264 ?>
265 <input type="hidden" name="page" value="sc-affiliates" />
266
267 <?php if ( ! empty( $_GET['status'] ) ) : // phpcs:ignore WordPress.Security.NonceVerification.Recommended ?>
268 <input type="hidden" name="status" value="<?php echo esc_attr( $_GET['status'] ); ?>" />
269 <?php endif; ?>
270
271 <?php
272 /**
273 * Fires immediately following the closing "actions" div in the tablenav
274 * for the affiliates list table.
275 *
276 * @param string $which The location of the extra table nav markup: 'top' or 'bottom'.
277 */
278 do_action( 'manage_affiliates_extra_tablenav', $which );
279 }
280
281 /**
282 * Toggle archive action link and text.
283 *
284 * @param \SureCart\Models\Affiliation $affiliation Affiliation model.
285 * @return string
286 */
287 public function action_toggle_activate( $affiliation ) {
288 $text = $affiliation->active ? __( 'Deactivate', 'surecart' ) : __( 'Activate', 'surecart' );
289 $confirm_message = $affiliation->active ? __( 'Are you sure you want to deactivate this affilate?', 'surecart' ) : __( 'Are you sure you want to activate this affiliate?', 'surecart' );
290 $link = $this->get_toggle_activate_url( $affiliation->id, $affiliation->active ? 'deactivate' : 'activate' );
291
292 return sprintf(
293 // translators: %1s: confirm message, %2s: link, %3s: aria label, %4s: text.
294 '<a class="submitdelete" onclick="return confirm(\'%1s\')" href="%2s" aria-label="%3s">%4s</a>',
295 esc_attr( $confirm_message ),
296 esc_url( $link ),
297 esc_attr__( 'Toggle Affiliate active status', 'surecart' ),
298 esc_html( $text )
299 );
300 }
301
302 /**
303 * Get the toggle activate URL.
304 *
305 * @param string $id Model id.
306 * @param string $action Action activate or deactivate.
307 *
308 * @return string URL for the page.
309 */
310 public function get_toggle_activate_url( $id, $action ) {
311 return esc_url(
312 add_query_arg(
313 [
314 'action' => $action,
315 'nonce' => wp_create_nonce( $action . '_affiliation' ),
316 'id' => $id,
317 ],
318 esc_url_raw( admin_url( 'admin.php?page=sc-affiliates' ) )
319 )
320 );
321 }
322
323 /**
324 * Get filtered status / default status.
325 *
326 * @return string|null
327 */
328 private function getFilteredStatus() {
329 $status = sanitize_text_field( wp_unslash( $_GET['status'] ?? '' ) );
330 $transforms = [
331 'all' => null,
332 'active' => '1',
333 'inactive' => '0',
334 ];
335
336 return $transforms[ $status ] ?? null;
337 }
338
339 /**
340 * Get all affiliation statuses.
341 *
342 * @return array
343 */
344 private function getStatuses(): array {
345 return array(
346 'all' => __( 'All', 'surecart' ),
347 'active' => __( 'Active', 'surecart' ),
348 'inactive' => __( 'Inactive', 'surecart' ),
349 );
350 }
351 }
352