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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 / Instructors_List.php
tutor / classes Last commit date
Addons.php 3 years ago Admin.php 3 years ago Ajax.php 3 years ago Announcements.php 3 years ago Assets.php 3 years ago Backend_Page_Trait.php 3 years ago Course.php 3 years ago Course_Embed.php 3 years ago Course_Filter.php 3 years ago Course_List.php 3 years ago Course_Settings_Tabs.php 3 years ago Course_Widget.php 3 years ago Custom_Validation.php 3 years ago Dashboard.php 3 years ago FormHandler.php 3 years ago Frontend.php 3 years ago Gutenberg.php 3 years ago Input.php 3 years ago Instructor.php 3 years ago Instructors_List.php 3 years ago Lesson.php 3 years ago Options_V2.php 3 years ago Post_types.php 3 years ago Private_Course_Access.php 3 years ago Q_and_A.php 3 years ago Question_Answers_List.php 3 years ago Quiz.php 3 years ago Quiz_Attempts_List.php 3 years ago RestAPI.php 3 years ago Reviews.php 3 years ago Rewrite_Rules.php 3 years ago Shortcode.php 3 years ago Student.php 3 years ago Students_List.php 3 years ago Taxonomies.php 3 years ago Template.php 3 years ago Theme_Compatibility.php 3 years ago Tools.php 3 years ago Tools_V2.php 3 years ago Tutor.php 3 years ago TutorEDD.php 3 years ago Tutor_Base.php 3 years ago Tutor_Setup.php 3 years ago Upgrader.php 3 years ago User.php 3 years ago Utils.php 3 years ago Video_Stream.php 3 years ago Withdraw.php 3 years ago Withdraw_Requests_List.php 3 years ago WooCommerce.php 3 years ago
Instructors_List.php
281 lines
1 <?php
2 /**
3 * Manage Instructor List
4 *
5 * @package Tutor
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 use TUTOR\Students_List;
18 use TUTOR\Backend_Page_Trait;
19
20 /**
21 * Instructors_List class
22 *
23 * @since 1.0.0
24 */
25 class Instructors_List {
26
27 const INSTRUCTOR_LIST_PAGE = 'tutor-instructors';
28
29 /**
30 * Trait for utilities
31 *
32 * @var $page_title
33 */
34
35 use Backend_Page_Trait;
36
37 /**
38 * Page Title
39 *
40 * @var $page_title
41 */
42 public $page_title;
43
44 /**
45 * Bulk Action
46 *
47 * @var $bulk_action
48 */
49 public $bulk_action = true;
50
51 /**
52 * Constructor
53 *
54 * @since 1.0.0
55 * @return void
56 */
57 public function __construct() {
58 $this->page_title = __( 'Instructor', 'tutor' );
59
60 /**
61 * Handle bulk action
62 *
63 * @since 2.0.0
64 */
65 add_action( 'wp_ajax_tutor_instructor_bulk_action', array( $this, 'instructor_bulk_action' ) );
66 }
67
68 /**
69 * Available tabs that will visible on the right side of page navbar
70 *
71 * @since 2.0.0
72 *
73 * @param string $search instructor search | optional.
74 * @param string $course_id course id that belong to instructor | optional.
75 * @param string $date user registered date | optional.
76 *
77 * @return array
78 */
79 public function tabs_key_value( $search = '', $course_id = '', $date = '' ): array {
80 $url = get_pagenum_link();
81 $approve = tutor_utils()->get_total_instructors( $search, array( 'approved' ), $course_id, $date );
82 $pending = tutor_utils()->get_total_instructors( $search, array( 'pending' ), $course_id, $date );
83 $blocked = tutor_utils()->get_total_instructors( $search, array( 'blocked' ), $course_id, $date );
84 $tabs = array(
85 array(
86 'key' => 'all',
87 'title' => __( 'All', 'tutor' ),
88 'value' => $approve + $pending + $blocked,
89 'url' => $url . '&data=all',
90 ),
91 array(
92 'key' => 'approved',
93 'title' => __( 'Approve', 'tutor' ),
94 'value' => $approve,
95 'url' => $url . '&data=approved',
96 ),
97 array(
98 'key' => 'pending',
99 'title' => __( 'Pending', 'tutor' ),
100 'value' => $pending,
101 'url' => $url . '&data=pending',
102 ),
103 array(
104 'key' => 'blocked',
105 'title' => __( 'Block', 'tutor' ),
106 'value' => $blocked,
107 'url' => $url . '&data=blocked',
108 ),
109 );
110 return $tabs;
111 }
112
113 /**
114 * Prepare bulk actions that will show on dropdown options
115 *
116 * @since 2.0.0
117 * @return array
118 */
119 public function prpare_bulk_actions(): array {
120 $actions = array(
121 $this->bulk_action_default(),
122 $this->bulk_action_approved(),
123 $this->bulk_action_pending(),
124 $this->bulk_action_blocked(),
125 );
126 return $actions;
127 }
128
129 /**
130 * Handle bulk action for instructor delete
131 *
132 * @since 2.0.0
133 * @return string JSON response.
134 */
135 public function instructor_bulk_action() {
136 tutor_utils()->checking_nonce();
137
138 $action = Input::post( 'bulk-action', '' );
139 $bulk_ids = Input::post( 'bulk-ids', '' );
140
141 Input::has( 'bulkIds' ) ? $bulk_ids = Input::post( 'bulkIds' ) : 0;
142
143 if ( '' === $action || '' === $bulk_ids ) {
144 return wp_send_json_error();
145 }
146 if ( 'delete' === $action ) {
147 // Delete user from student_list class.
148 do_action( 'tutor_before_instructor_delete', $bulk_ids );
149 $response = Students_List::delete_students( $bulk_ids );
150 do_action( 'tutor_after_instructor_delete', $bulk_ids );
151 } else {
152 do_action( 'tutor_before_instructor_update', $bulk_ids );
153 $response = self::update_instructors( $action, $bulk_ids );
154 do_action( 'tutor_after_instructor_delete', $bulk_ids );
155 }
156
157 $message = 'Instructor status updated';
158
159 return true === $response ? wp_send_json_success( array( 'status' => $message ) ) : wp_send_json_error();
160 }
161
162 /**
163 * Execute bulk action for enrollment list ex: complete | cancel
164 *
165 * @since 2.0.0
166 *
167 * @param string $status hold status for updating.
168 * @param string $user_ids ids that need to update.
169 *
170 * @return bool
171 */
172 public static function update_instructors( $status, $user_ids ): bool {
173 global $wpdb;
174 $status = sanitize_text_field( $status );
175 $instructor_table = $wpdb->usermeta;
176
177 //phpcs:disable WordPress.DB.PreparedSQL.InterpolatedNotPrepared
178 $update = $wpdb->query(
179 $wpdb->prepare(
180 "UPDATE {$instructor_table} SET meta_value = %s
181 WHERE user_id IN ($user_ids)
182 AND meta_key = %s",
183 $status,
184 '_tutor_instructor_status'
185 )
186 );
187 //phpcs:enable WordPress.DB.PreparedSQL.InterpolatedNotPrepared
188
189 // Remove role.
190 if ( 'pending' === $status || 'blocked' === $status ) {
191 $arr = explode( ',', $user_ids );
192 foreach ( $arr as $instructor_id ) {
193 $instructor_id = (int) sanitize_text_field( $instructor_id );
194 self::remove_instructor_role( $instructor_id, $status );
195 }
196 }
197
198 if ( 'approved' === $status ) {
199 $arr = explode( ',', $user_ids );
200 foreach ( $arr as $instructor_id ) {
201 $instructor_id = (int) sanitize_text_field( $instructor_id );
202 self::add_instructor_role( $instructor_id, $status );
203 }
204 }
205 return false === $update ? false : true;
206 }
207
208 /**
209 * Get total course.
210 *
211 * @since 1.0.0
212 *
213 * @param object $item item.
214 * @return void
215 */
216 public function column_total_course( $item ) {
217 global $wpdb;
218 $course_post_type = tutor()->course_post_type;
219
220 $total_course = (int) $wpdb->get_var(
221 $wpdb->prepare(
222 "SELECT count(ID) from {$wpdb->posts}
223 WHERE post_author=%d AND post_type=%s ",
224 $item->ID,
225 $course_post_type
226 )
227 );
228
229 echo esc_html( $total_course );
230 }
231
232 /**
233 * Initialize instructor_role to a user
234 *
235 * @since 1.0.0
236 *
237 * @param integer $instructor_id | user id that need to add role.
238 * @param string $status | status that will added with role (approved).
239 *
240 * @return void
241 */
242 protected static function add_instructor_role( int $instructor_id, string $status ) {
243 $instructor_id = sanitize_text_field( $instructor_id );
244 $status = sanitize_text_field( $status );
245
246 do_action( 'tutor_before_approved_instructor', $instructor_id );
247
248 update_user_meta( $instructor_id, '_tutor_instructor_status', $status );
249 update_user_meta( $instructor_id, '_tutor_instructor_approved', tutor_time() );
250
251 $instructor = new \WP_User( $instructor_id );
252 $instructor->add_role( tutor()->instructor_role );
253
254 // TODO: send E-Mail to this user about instructor approval, should via hook.
255 do_action( 'tutor_after_approved_instructor', $instructor_id );
256 }
257
258 /**
259 * Initialize instructor_role to a user
260 *
261 * @since 1.0.0
262 *
263 * @param int $instructor_id | user id that need to add role.
264 * @param string $status | status that will added with role (approved).
265 *
266 * @return void
267 */
268 protected static function remove_instructor_role( int $instructor_id, string $status ) {
269 $instructor_id = sanitize_text_field( $instructor_id );
270 $status = sanitize_text_field( $status );
271
272 do_action( 'tutor_before_blocked_instructor', $instructor_id );
273 update_user_meta( $instructor_id, '_tutor_instructor_status', $status );
274
275 $instructor = new \WP_User( $instructor_id );
276 $instructor->remove_role( tutor()->instructor_role );
277 do_action( 'tutor_after_blocked_instructor', $instructor_id );
278 }
279
280 }
281