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.2 3.5.0 3.6.0 3.6.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 days ago Admin.php 4 days ago Ajax.php 4 days ago Announcements.php 4 days ago Assets.php 1 day ago Backend_Page_Trait.php 1 year ago BaseController.php 1 year ago Config.php 4 days ago Container.php 11 months ago Course.php 4 days ago Course_Embed.php 3 years ago Course_Filter.php 4 days ago Course_List.php 4 days ago Course_Settings_Tabs.php 4 days ago Course_Widget.php 1 year ago Custom_Validation.php 4 days ago Dashboard.php 4 days ago Earnings.php 9 months ago FormHandler.php 4 days ago Frontend.php 4 days ago Gutenberg.php 1 year ago Icon.php 4 days ago Input.php 4 days ago Instructor.php 4 days ago Instructors_List.php 4 days ago Lesson.php 4 days ago Options_V2.php 4 days ago Permalink.php 4 days ago Post_types.php 5 days ago Private_Course_Access.php 4 days ago Q_And_A.php 4 days ago Question_Answers_List.php 11 months ago Quiz.php 1 day ago QuizBuilder.php 4 days ago Quiz_Attempts_List.php 1 day ago RestAPI.php 1 day ago Reviews.php 4 days ago Rewrite_Rules.php 2 years ago SampleCourse.php 4 days ago Shortcode.php 4 days ago Singleton.php 1 year ago Student.php 4 days ago Students_List.php 1 year ago Taxonomies.php 1 year ago Template.php 4 days ago Theme_Compatibility.php 3 years ago Tools.php 1 year ago Tools_V2.php 1 month ago Tutor.php 4 days ago TutorEDD.php 4 days ago Tutor_Base.php 2 years ago Tutor_Setup.php 4 days ago Upgrader.php 4 days ago User.php 4 days ago UserPreference.php 4 days ago Utils.php 1 day ago Video_Stream.php 3 years ago WhatsNew.php 1 day ago Withdraw.php 4 days ago Withdraw_Requests_List.php 11 months ago WooCommerce.php 4 days ago
Withdraw_Requests_List.php
255 lines
1 <?php
2 /**
3 * Manage withdrawals
4 *
5 * @package Tutor\Withdraw
6 * @author Themeum <support@themeum.com>
7 * @link https://themeum.com
8 * @since 1.0.0
9 */
10
11 namespace TUTOR;
12
13 if ( ! defined( 'ABSPATH' ) ) {
14 exit;
15 }
16 /**
17 * Handle withdraw request logic
18 *
19 * @since 1.0.0
20 */
21 class Withdraw_Requests_List {
22 /**
23 * List page slug
24 *
25 * @since 1.0.0
26 *
27 * @var string
28 */
29 const WITHDRAW_REQUEST_LIST_PAGE = 'tutor_withdraw_requests';
30
31 /**
32 * Register hooks, resolve dependencies
33 *
34 * @since 1.0.0
35 */
36 public function __construct() {
37 /**
38 * Approve or reject withdraw request
39 */
40 add_action( 'wp_ajax_tutor_admin_withdraw_action', array( $this, 'update_withdraw_status' ) );
41 }
42
43 /**
44 * Page title fallback
45 *
46 * @since 3.5.0
47 *
48 * @param string $name Property name.
49 *
50 * @return string
51 */
52 public function __get( $name ) {
53 if ( 'page_title' === $name ) {
54 return esc_html__( 'Withdraw Requests', 'tutor' );
55 }
56 }
57
58 /**
59 * Available tabs that will visible on the right side of page navbar
60 *
61 * @since 2.0.0
62 *
63 * @param string $date withdraw request date | optional.
64 * @param string $search search by instructor name or email | optional.
65 *
66 * @return array
67 */
68 public function tabs_key_value( $date = '', $search = '' ): array {
69 $approved = self::tabs_data( 'approved', $date, $search );
70 $pending = self::tabs_data( 'pending', $date, $search );
71 $rejected = self::tabs_data( 'rejected', $date, $search );
72
73 $url = apply_filters( 'tutor_data_tab_base_url', get_pagenum_link() );
74 $tabs = array(
75 array(
76 'key' => '',
77 'title' => __( 'All', 'tutor' ),
78 'value' => $approved + $pending + $rejected,
79 'url' => $url . '&data=all',
80 ),
81 array(
82 'key' => 'approved',
83 'title' => __( 'Approved', 'tutor' ),
84 'value' => $approved,
85 'url' => $url . '&data=approved',
86 ),
87 array(
88 'key' => 'pending',
89 'title' => __( 'Pending', 'tutor' ),
90 'value' => $pending,
91 'url' => $url . '&data=pending',
92 ),
93 array(
94 'key' => 'rejected',
95 'title' => __( 'Rejected', 'tutor' ),
96 'value' => $rejected,
97 'url' => $url . '&data=rejected',
98 ),
99 );
100 return $tabs;
101 }
102
103 /**
104 * Get counted number of withdraw list by status ex: approved | pending | rejected
105 *
106 * @since 2.0.0
107 *
108 * @param string $status status required | available : (approved | pending | rejected).
109 * @param string $date withdraw request date | optional | YYYY-MM-DD.
110 * @param string $search search by instructor name or email | optional.
111 *
112 * @return int
113 */
114 public static function tabs_data( string $status, $date = '', $search = '' ): int {
115 global $wpdb;
116 $withdraw_table = $wpdb->prefix . 'tutor_withdraws';
117 $user_table = $wpdb->users;
118 $status = sanitize_text_field( $status );
119 $date = sanitize_text_field( $date );
120 $search = sanitize_text_field( $search );
121 // Prepare date query.
122 $date_query = '';
123 if ( '' !== $date ) {
124 $date_query = "AND DATE(withdraw.created_at) = CAST('{$date}' AS DATE) ";
125 }
126
127 // Prepare search query.
128 $search = '%' . $wpdb->esc_like( $search ) . '%';
129
130 $count = $wpdb->get_var(
131 $wpdb->prepare(
132 "SELECT count(*) FROM {$withdraw_table} AS withdraw
133 INNER JOIN {$user_table} AS user
134 ON user.ID = withdraw.user_id
135 WHERE withdraw.status = %s
136 {$date_query}
137 AND ( user.user_login LIKE %s OR user.user_nicename LIKE %s OR user.user_email LIKE %s OR user.display_name LIKE %s )
138 ",
139 $status,
140 $search,
141 $search,
142 $search,
143 $search
144 )
145 );
146 return $count ? $count : 0;
147 }
148
149 /**
150 * Handle ajax request for updating withdraw status | available status (approved, rejected, pending)
151 *
152 * @since 2.0.0
153 *
154 * @return string json response.
155 */
156 public function update_withdraw_status() {
157 tutor_utils()->checking_nonce();
158
159 // Check if user is privileged.
160 if ( ! current_user_can( 'administrator' ) ) {
161 wp_send_json_error( tutor_utils()->error_message() );
162 }
163
164 $status = Input::post( 'action-type', '' );
165 $withdraw_id = Input::post( 'withdraw-id', '' );
166 $reject_type = Input::post( 'reject-type', '' );
167 $reject_comment = Input::post( 'reject-comment', '' );
168
169 if ( '' === $withdraw_id ) {
170 return false;
171 } else {
172 $update = self::update( $status, $withdraw_id, $reject_type, $reject_comment );
173 return $update ? wp_send_json( true ) : false;
174 }
175 exit;
176 }
177
178 /**
179 * Update withdraw status | available status (approved, rejected, pending)
180 *
181 * @since v2.0.0
182 *
183 * @param string $status | required.
184 * @param int $withdraw_id | required.
185 * @param string $reject_type | optional.
186 * @param string $reject_comment | optional.
187 *
188 * @return bool json response.
189 */
190 public static function update( string $status, int $withdraw_id, $reject_type = '', $reject_comment = '' ): bool {
191 global $wpdb;
192 $withdraw_table = $wpdb->prefix . 'tutor_withdraws';
193 $withdraw_id = sanitize_text_field( $withdraw_id );
194 $status = sanitize_text_field( $status );
195
196 // Prepare data for update.
197 $data = array(
198 'status' => $status,
199 'updated_at' => gmdate( 'Y-m-d H:i:s' ),
200 );
201
202 // If rejected then append reject_type and comment with method_data.
203 if ( 'rejected' === $status ) {
204 $withdraw = self::get_withdraw_by_id( $withdraw_id );
205 if ( $withdraw ) {
206 $details = unserialize( $withdraw->method_data );
207
208 $details['rejects'] = array(
209 'reject_type' => sanitize_text_field( $reject_type ),
210 'reject_comment' => sanitize_text_field( $reject_comment ),
211 );
212 $data['method_data'] = maybe_serialize( $details );
213
214 // Trigger email after rejecting withdraw.
215 do_action( 'tutor_after_rejected_withdraw', $withdraw_id );
216 }
217 } else {
218 do_action( 'tutor_after_approved_withdraw', $withdraw_id );
219 }
220
221 // Update.
222 $update = $wpdb->update(
223 $withdraw_table,
224 $data,
225 array(
226 'withdraw_id' => $withdraw_id,
227 )
228 );
229 return $update ? true : false;
230 }
231
232
233 /**
234 * Get withdraw by id
235 *
236 * @since v2.0.0
237 *
238 * @param int $withdraw_id | required.
239 *
240 * @return object withdraw list.
241 */
242 public static function get_withdraw_by_id( int $withdraw_id ) {
243 global $wpdb;
244 $withdraw_table = $wpdb->prefix . 'tutor_withdraws';
245 return $wpdb->get_row(
246 $wpdb->prepare(
247 " SELECT *FROM {$withdraw_table}
248 WHERE withdraw_id = %d
249 ",
250 $withdraw_id
251 )
252 );
253 }
254 }
255