class-ldlms-factory-user.php
2.61 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
<?php
/**
* LearnDash Factory User Class.
* This is a factory class used to instantiate user related data.
*
* @since 3.4.0
* @package LearnDash
*/
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
if ( ( ! class_exists( 'LDLMS_Factory_User' ) ) && ( class_exists( 'LDLMS_Factory' ) ) ) {
/**
* Class for LearnDash Factory User.
*
* @since 2.5.0
* @uses LDLMS_Factory
*/
class LDLMS_Factory_User extends LDLMS_Factory {
/**
* Get a User Instance.
*
* @param int|object $user Either user_id integer or WP_User instance.
* @param bool $reload True to force reload of instance.
*
* @return object|null Instance of `LDLMS_Model_User` or null
*/
public static function user( $user = null, $reload = false ) {
$model = 'LDLMS_Model_User';
if ( ! empty( $user ) ) {
$user_id = 0;
if ( is_a( $user, 'WP_User' ) ) {
$user_id = absint( $user->ID );
} else {
$user_id = absint( $user );
}
if ( ( ! empty( $user_id ) ) ) {
if ( true === $reload ) {
self::remove_instance( $model, $user_id );
}
return self::add_instance( $model, $user_id, $user_id );
}
}
return null;
}
/**
* Get a User Course Progress Instance.
*
* @param int|object $user Either user_id integer or WP_User instance.
* @param bool $reload To force reload of instance.
*
* @return object|null Instance of `LDLMS_Model_User_Course_Progress` or null
*/
public static function course_progress( $user = null, $reload = false ) {
$model = 'LDLMS_Model_User_Course_Progress';
$user_id = 0;
if ( is_a( $user, 'WP_User' ) ) {
$user_id = absint( $user->ID );
} else {
$user_id = absint( $user );
}
if ( ! empty( $user_id ) ) {
if ( true === $reload ) {
self::remove_instance( $model, $user_id );
}
return self::add_instance( $model, $user_id, $user_id );
}
return null;
}
/**
* Get a User Course Progress Instance.
*
* @param int|object $user Either user_id integer or WP_User instance.
* @param bool $reload To force reload of instance.
*
* @return object|null Instance of `LDLMS_Model_User_Quiz_Progress` or null
*/
public static function quiz_progress( $user = null, $reload = false ) {
$model = 'LDLMS_Model_User_Quiz_Progress';
$user_id = 0;
if ( is_a( $user, 'WP_User' ) ) {
$user_id = absint( $user->ID );
} else {
$user_id = absint( $user );
}
if ( ! empty( $user_id ) ) {
if ( true === $reload ) {
self::remove_instance( $model, $user_id );
}
return self::add_instance( $model, $user_id, $user_id );
}
return null;
}
}
}