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.1 3.6.2 3.6.3 3.6.4 3.7.0 3.7.1 3.7.2 3.7.3 3.7.4 3.8.0 3.8.1 3.8.2 3.8.3 3.9.0 3.9.1 3.9.10 3.9.2 3.9.3 3.9.4 3.9.5 3.9.6 3.9.7 3.9.8 3.9.9
tutor / classes / Withdraw_Requests_List.php
tutor / classes Last commit date
Addons.php 4 years ago Admin.php 4 years ago Ajax.php 4 years ago Assets.php 4 years ago Course.php 4 years ago Course_Filter.php 4 years ago Course_Settings_Tabs.php 4 years ago Course_Widget.php 4 years ago Custom_Validation.php 5 years ago Dashboard.php 4 years ago Email.php 5 years ago FormHandler.php 4 years ago Frontend.php 5 years ago Gutenberg.php 4 years ago Instructor.php 4 years ago Instructors_List.php 4 years ago Lesson.php 4 years ago Options.php 4 years ago Post_types.php 4 years ago Private_Course_Access.php 5 years ago Q_and_A.php 4 years ago Question_Answers_List.php 4 years ago Quiz.php 4 years ago Quiz_Attempts_List.php 4 years ago RestAPI.php 4 years ago Rewrite_Rules.php 4 years ago Shortcode.php 4 years ago Student.php 4 years ago Students_List.php 4 years ago Taxonomies.php 4 years ago Template.php 4 years ago Theme_Compatibility.php 5 years ago Tools.php 4 years ago Tutor.php 4 years ago TutorEDD.php 4 years ago Tutor_Base.php 5 years ago Tutor_List_Table.php 4 years ago Tutor_Setup.php 4 years ago Upgrader.php 4 years ago User.php 4 years ago Utils.php 4 years ago Video_Stream.php 4 years ago Withdraw.php 4 years ago Withdraw_Requests_List.php 4 years ago WooCommerce.php 4 years ago
Withdraw_Requests_List.php
241 lines
1 <?php
2 namespace TUTOR;
3
4 if ( ! defined( 'ABSPATH' ) ) {
5 exit;
6 }
7
8 if ( ! class_exists( 'Tutor_List_Table' ) ) {
9 include_once tutor()->path . 'classes/Tutor_List_Table.php';
10 }
11
12 class Withdraw_Requests_List extends \Tutor_List_Table {
13
14 const WITHDRAW_REQUEST_LIST_PAGE = 'tutor_withdraw_requests';
15
16 function __construct() {
17 global $status, $page;
18
19 // Set parent defaults
20 parent::__construct(
21 array(
22 'singular' => 'withdraw', // singular name of the listed records
23 'plural' => 'withdraw', // plural name of the listed records
24 'ajax' => false, // does this table support ajax?
25 )
26 );
27
28 $this->process_bulk_action();
29 }
30
31 function column_default( $item, $column_name ) {
32 switch ( $column_name ) {
33 case 'testing_col':
34 return $item->$column_name;
35 default:
36 return print_r( $item, true ); // Show the whole array for troubleshooting purposes
37 }
38 }
39
40 function column_cb( $item ) {
41 return sprintf(
42 '<input type="checkbox" name="%1$s[]" value="%2$s" />',
43 /*$1%s*/ $this->_args['singular'], // Let's simply repurpose the table's singular label ("student")
44 /*$2%s*/ $item->withdraw_id // The value of the checkbox should be the record's id
45 );
46 }
47
48 function column_requested_user( $item ) {
49 echo '<p>' . $item->user_name . '</p><p>' . $item->user_email . '</p>';
50
51 $actions = array();
52 switch ( $item->status ) {
53 case 'pending':
54 $actions['approved'] = sprintf(
55 '<a href="?page=%s&action=%s&withdraw_id=%s">' . __( 'Approve', 'tutor' ) . '</a>',
56 self::WITHDRAW_REQUEST_LIST_PAGE,
57 'approved',
58 $item->withdraw_id
59 );
60 $actions['rejected'] = sprintf( '<a href="?page=%s&action=%s&withdraw_id=%s">' . __( 'Rejected', 'tutor' ) . '</a>', self::WITHDRAW_REQUEST_LIST_PAGE, 'rejected', $item->withdraw_id );
61 break;
62 case 'approved':
63 $actions['rejected'] = sprintf( '<a href="?page=%s&action=%s&withdraw_id=%s">' . __( 'Rejected', 'tutor' ) . '</a>', self::WITHDRAW_REQUEST_LIST_PAGE, 'rejected', $item->withdraw_id );
64 break;
65 case 'rejected':
66 $actions['approved'] = sprintf( '<a href="?page=%s&action=%s&withdraw_id=%s">' . __( 'Approve', 'tutor' ) . '</a>', self::WITHDRAW_REQUEST_LIST_PAGE, 'approved', $item->withdraw_id );
67 break;
68 }
69
70 $actions['delete'] = sprintf( '<a href="?page=%s&action=%s&withdraw_id=%s" onclick="return confirm(\'' . __( 'Are you Sure? It can not be undone.', 'tutor' ) . '\')">' . __( 'Delete', 'tutor' ) . '</a>', self::WITHDRAW_REQUEST_LIST_PAGE, 'delete', $item->withdraw_id );
71
72 return '<div class="withdraw-list-row-actions">' . $this->row_actions( $actions ) . '</div>';
73 }
74 function column_withdraw_method( $item ) {
75 if ( $item->method_data ) {
76 $data = maybe_unserialize( $item->method_data );
77
78 $method_name = tutor_utils()->avalue_dot( 'withdraw_method_name', $data );
79
80 if ( $method_name ) {
81 echo '<p><strong>' . $method_name . '</strong></p>';
82 }
83
84 unset( $data['withdraw_method_key'], $data['withdraw_method_name'] );
85
86 if ( tutor_utils()->count( $data ) ) {
87 foreach ( $data as $method_field ) {
88 $label = tutor_utils()->avalue_dot( 'label', $method_field );
89 $value = tutor_utils()->avalue_dot( 'value', $method_field );
90 echo '<p class="withdraw-method-data-row"> <span class="withdraw-method-label">' . $label . '</span> : <span class="withdraw-method-value">' . $value . '</span> </p>';
91 }
92 }
93 }
94 return '';
95 }
96
97 function column_requested_at( $item ) {
98 echo '<p>' . date_i18n( get_option( 'date_format' ) . ' ' . get_option( 'time_format' ), strtotime( $item->created_at ) ) . '</p>';
99 }
100
101 function column_amount( $item ) {
102 $available_status = array(
103 'pending' => __( 'pending', 'tutor' ),
104 'approved' => __( 'approved', 'tutor' ),
105 'rejected' => __( 'rejected', 'tutor' ),
106 );
107 echo '<p>' . tutor_utils()->tutor_price( $item->amount ) . '</p>';
108 echo '<p="withdraw-status withdraw-status-' . $item->status . '">' . __( isset( $available_status[ $item->status ] ) ? $available_status[ $item->status ] : $item->status, 'tutor' ) . '</span></p>';
109 }
110
111 function get_columns() {
112 $columns = array(
113 'cb' => '<input type="checkbox" />', // Render a checkbox instead of text
114 'requested_user' => __( 'Requested By', 'tutor' ),
115 'amount' => __( 'Amount', 'tutor' ),
116 'withdraw_method' => __( 'Withdrawal Method', 'tutor' ),
117 'requested_at' => __( 'Requested Time', 'tutor' ),
118 );
119 return $columns;
120 }
121
122 function get_bulk_actions() {
123 $actions = array(
124 // 'delete' => 'Delete'
125 );
126 return $actions;
127 }
128
129 function process_bulk_action() {
130 global $wpdb;
131
132 $withdraw_page_url = admin_url( 'admin.php?page=' . self::WITHDRAW_REQUEST_LIST_PAGE );
133 $date = date( 'Y-m-d H:i:s', tutor_time() );
134 $redirect = false;
135
136 // Detect when a bulk action is being triggered...
137 if ( 'delete' === $this->current_action() ) {
138 $should_withdraw_delete = apply_filters( 'tutor_should_withdraw_delete', true );
139
140 if ( $should_withdraw_delete ) {
141 $withdraw_id = (int) $_GET['withdraw_id'];
142
143 do_action( 'tutor_before_delete_withdraw', $withdraw_id );
144
145 $wpdb->delete( $wpdb->prefix . 'tutor_withdraws', array( 'withdraw_id' => $withdraw_id ) );
146
147 do_action( 'tutor_after_delete_withdraw', $withdraw_id );
148
149 $redirect = true;
150 } else {
151 wp_die( 'Items deleted (or they would be if we had items to delete)!' );
152 }
153 }
154
155 /**
156 * Reject Withdraw
157 */
158 if ( 'approved' === $this->current_action() ) {
159 $withdraw_id = (int) $_GET['withdraw_id'];
160 $withdraw = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM {$wpdb->prefix}tutor_withdraws WHERE withdraw_id = %d ", $withdraw_id ) );
161 if ( ! $withdraw || $withdraw->status === 'approved' ) {
162 return;
163 }
164
165 do_action( 'tutor_before_approved_withdraw', $withdraw_id );
166
167 $wpdb->update(
168 $wpdb->prefix . 'tutor_withdraws',
169 array(
170 'status' => 'approved',
171 'updated_at' => $date,
172 ),
173 array( 'withdraw_id' => $withdraw_id )
174 );
175
176 do_action( 'tutor_after_approved_withdraw', $withdraw_id );
177
178 $redirect = true;
179 }
180
181 /**
182 * Rejected
183 */
184 if ( 'rejected' === $this->current_action() ) {
185 $withdraw_id = (int) $_GET['withdraw_id'];
186 $withdraw = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM {$wpdb->prefix}tutor_withdraws WHERE withdraw_id = %d ", $withdraw_id ) );
187 if ( ! $withdraw || $withdraw->status === 'rejected' ) {
188 return;
189 }
190
191 do_action( 'tutor_before_rejected_withdraw', $withdraw_id );
192
193 $wpdb->update(
194 $wpdb->prefix . 'tutor_withdraws',
195 array(
196 'status' => 'rejected',
197 'updated_at' => $date,
198 ),
199 array( 'withdraw_id' => $withdraw_id )
200 );
201
202 do_action( 'tutor_after_rejected_withdraw', $withdraw_id );
203
204 $redirect = true;
205 }
206
207 if($this->current_action()) {
208 wp_redirect( $withdraw_page_url );
209 exit;
210 }
211 }
212
213 function prepare_items() {
214 $per_page = 20;
215
216 $search_term = '';
217 if ( isset( $_REQUEST['s'] ) ) {
218 $search_term = sanitize_text_field( $_REQUEST['s'] );
219 }
220
221 $columns = $this->get_columns();
222 $hidden = array();
223
224 $this->_column_headers = array( $columns, $hidden );
225 $current_page = $this->get_pagenum();
226
227 $start = ( $current_page - 1 ) * $per_page;
228 $withdraw_requests = tutor_utils()->get_withdrawals_history( null, compact( 'start', 'per_page', 'search_term' ) );
229 $this->items = $withdraw_requests->results;
230 $count_result = $withdraw_requests->count;
231
232 $this->set_pagination_args(
233 array(
234 'total_items' => $count_result,
235 'per_page' => $per_page,
236 'total_pages' => ceil( $count_result / $per_page ),
237 )
238 );
239 }
240 }
241