PluginProbe
Tutor LMS – eLearning and online course solution / 3.9.2
Tutor LMS – eLearning and online course solution v3.9.2
4.0.7 4.0.6 4.0.5 4.0.4 4.0.3 4.0.2 4.0.1 4.0.0 3.9.15 3.9.14 3.9.13 3.9.12 3.9.11 trunk 1.0.0 1.0.0-alpha 1.0.1 1.0.2 1.0.3 1.0.4 1.0.5 1.0.6 1.0.7 1.0.8 1.0.9 All 191 releases
tutor / models / UserModel.php

UserModel.php in Tutor LMS – eLearning and online course solution 3.9.2, at models/UserModel.php

104 lines 2.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * User Model
4 *
5 * @package Tutor\Models
6 * @author Themeum <support@themeum.com>
7 * @link https://themeum.com
8 * @since 3.0.0
9 */
10
11 namespace Tutor\Models;
12
13 use TUTOR\Course;
14 use Tutor\Helpers\QueryHelper;
15
16 /**
17 * UserModel class
18 */
19 class UserModel {
20
21 /**
22 * Get user list
23 *
24 * @since 3.0.0
25 *
26 * @see https://developer.wordpress.org/reference/classes/wp_user_query/
27 *
28 * @param array $args args.
29 *
30 * @return \WP_User_Query
31 */
32 public function get_users_list( array $args ) {
33 $default_args = array(
34 'orderby' => 'ID',
35 'order' => 'DESC',
36 'number' => 10,
37 'offset' => 0,
38 'role' => '',
39 'fields' => array( 'ID', 'user_login', 'display_name', 'user_email', 'user_url', 'registered' ),
40 );
41
42 $args = wp_parse_args( $args, $default_args );
43 $args = apply_filters( 'tutor_user_list_args', $args );
44
45 return new \WP_User_Query( $args );
46 }
47
48 /**
49 * Get unenrolled users of a course/bundle
50 *
51 * @since 3.0.0
52 *
53 * @param int $object_id Course/Bundle id.
54 * @param array $search_clause Search condition.
55 * @param integer $limit List limit.
56 * @param integer $offset Offset.
57 *
58 * @return array
59 */
60 public function get_unenrolled_users( $object_id, $search_clause = array(), $limit = 10, $offset = 0 ) {
61 global $wpdb;
62
63 $primary_table = "{$wpdb->users} AS u";
64 $joining_tables = array(
65 array(
66 'type' => 'LEFT',
67 'table' => "{$wpdb->posts} p",
68 'on' => "p.post_type = 'tutor_enrolled' AND p.post_parent = {$object_id} AND u.ID = p.post_author",
69 ),
70 );
71
72 $response = QueryHelper::get_joined_data(
73 $primary_table,
74 $joining_tables,
75 array(
76 'distinct u.ID',
77 'u.user_login',
78 'u.user_email',
79 'u.display_name',
80 'CASE WHEN p.ID IS NOT NULL THEN 1 ELSE 0 END AS is_enrolled',
81 'p.post_status',
82 ),
83 array(),
84 $search_clause,
85 'ID',
86 $limit,
87 $offset
88 );
89
90 foreach ( $response['results'] as $result ) {
91 // Typecast `is_enrolled` to int.
92 $result->is_enrolled = (int) $result->is_enrolled;
93
94 // Add enrollment status.
95 $result->enrollment_status = in_array( $result->post_status, array( 'cancel', 'cancelled', 'canceled' ) ) ? __( 'Cancelled', 'tutor' ) : ( 'completed' === $result->post_status ? __( 'Approved', 'tutor' ) : ( 'pending' === $result->post_status ? __( 'Pending', 'tutor' ) : $result->post_status ) );
96
97 // Add avatar URL for the user.
98 $result->avatar_url = get_avatar_url( $result->ID );
99 }
100
101 return $response;
102 }
103 }
104