class-ldlms-model-activity.php
3.5 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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
<?php
/**
* Class for LDLMS_Model_Activity.
*
* @package LearnDash\Activity
* @since 3.5.0
*/
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
if ( ( ! class_exists( 'LDLMS_Model_Activity' ) ) && ( class_exists( 'LDLMS_Model' ) ) ) {
/**
* Class for LearnDash Model Activity
*/
class LDLMS_Model_Activity extends LDLMS_Model {
/**
* Activity ID.
*
* @since 3.5.0
*
* @var int Activity row ID.
*/
public $activity_id = 0;
/**
* Activity user ID.
*
* @since 3.5.0
*
* @var int Activity user ID.
*/
public $user_id = 0;
/**
* Activity post/step ID.
*
* @since 3.5.0
*
* @var int Activity post/step ID.
*/
public $post_id = 0;
/**
* Activity course ID.
*
* @since 3.5.0
*
* @var int Activity course ID.
*/
public $course_id = 0;
/**
* Activity type.
*
* @since 3.5.0
*
* @var string Activity type. 'course', 'lesson', 'topic', 'access', 'group', etc..
*/
public $activity_type = '';
/**
* Activity status.
*
* @since 3.5.0
*
* @var bool Activity status. Completed is true.
*/
public $activity_status = 0;
/**
* Activity started timestamp.
*
* @since 3.5.0
*
* @var int Activity started timestamp (GMT).
*/
public $activity_started = 0;
/**
* Activity completed timestamp.
*
* @since 3.5.0
*
* @var int Activity completed timestamp (GMT).
*/
public $activity_completed = 0;
/**
* Activity updated timestamp.
*
* @since 3.5.0
*
* @var int Activity update timestamp (GMT).
*/
public $activity_updated = 0;
/**
* Activity meta.
*
* @since 3.5.0
*
* @var array Activity meta.
*/
public $activity_meta = 0;
/**
* Class constructor.
*
* @since 3.2.0
*
* @param mixed $activity Activity.
*/
public function __construct( $activity = '' ) {
$this->cast( $activity );
}
/**
* Cast Activity
*
* @param mixed $activity Activity.
*/
public function cast( $activity = '' ) {
$this_reflection = new ReflectionObject( $this );
$this_reflection_properties = $this_reflection->getProperties();
if ( is_object( $activity ) ) {
$activity_reflection = new ReflectionObject( $activity );
foreach ( $this_reflection_properties as $this_reflection_property ) {
$name = $this_reflection_property->getName();
if ( $activity_reflection->hasProperty( $name ) ) {
$activity_property = $activity_reflection->getProperty( $name );
$activity_property->setAccessible( true );
$this->{$name} = $activity_property->getValue( $activity );
}
}
} elseif ( is_array( $activity ) ) {
foreach ( $this_reflection_properties as $this_reflection_property ) {
$name = $this_reflection_property->getName();
if ( isset( $activity[ $name ] ) ) {
$this->{$name} = $activity[ $name ];
}
}
}
$this->format_vars();
}
/**
* Format variables
*/
public function format_vars() {
$this->activity_id = absint( $this->activity_id );
$this->user_id = absint( $this->user_id );
$this->post_id = absint( $this->post_id );
$this->course_id = absint( $this->course_id );
$this->activity_type = esc_attr( $this->activity_type );
$this->activity_status = (bool) $this->activity_status;
$this->activity_started = absint( $this->activity_started );
$this->activity_completed = absint( $this->activity_completed );
$this->activity_updated = absint( $this->activity_updated );
}
}
}