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
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
<?php
/**
* Individual Student's Course Table
*
* @package LifterLMS/Admin/Reporting/Tables/Classes
*
* @since 3.2.0
* @version 3.35.0
*/
defined( 'ABSPATH' ) || exit;
/**
* LLMS_Table_Student_Course class
*
* @since 3.2.0
* @since 3.21.0 Unknown.
* @since 3.35.0 Get student ID more reliably.
*/
class LLMS_Table_Student_Course extends LLMS_Admin_Table {
/**
* Unique ID for the Table
*
* @var string
*/
protected $id = 'student-course';
/**
* Stores the current section while building the table
* used by $this->output_section_row_html() to determine
* if a new section header needs to be output
*
* @var int
*/
private $current_section = null;
/**
* If true, tfoot will add ajax pagination links
*
* @var boolean
*/
protected $is_paginated = false;
/**
* Results sort order
* 'ASC' or 'DESC'
* Only applicable of $orderby is not set
*
* @var string
*/
protected $order = 'ASC';
/**
* Field results are sorted by
*
* @var string
*/
protected $orderby = 'name';
/**
* Instance of LLMS_Student
*
* @var null
*/
public $student = null;
/**
* Get the HTML for the actions column on the table
*
* @param obj $lesson LLMS_Lesson..
* @return string
* @since 3.29.0
* @version 3.29.0
*/
private function get_actions_html( $lesson ) {
$html = '';
if ( llms_show_mark_complete_button( $lesson ) ) {
if ( $this->student->is_complete( $lesson->get( 'id' ) ) ) {
$action = 'incomplete';
$icon = 'exclamation-triangle';
$text = __( 'Mark Incomplete', 'lifterlms' );
} else {
$action = 'complete';
$icon = 'check';
$text = __( 'Mark Complete', 'lifterlms' );
}
$html = '
<form action="" method="POST">
<input name="student_id" type="hidden" value="' . $this->student->get( 'id' ) . '">
<input name="lesson_id" type="hidden" value="' . $lesson->get( 'id' ) . '">
<button class="llms-button-secondary square small tip--bottom-left" data-tip="' . esc_attr( $text ) . '" name="llms-lesson-action" type="submit" value="' . $action . '">
<i class="fa fa-' . $icon . '" aria-hidden="true"></i>
</button>
' . wp_nonce_field( 'llms-admin-lesson-progression', 'llms-admin-progression-nonce', false, false ) . '
</form>
';
}
return $html;
}
/**
* Retrieve data for the columns
*
* @param string $key the column id / key
* @param int $lesson Instance of an LLMS_Lesson
* @return mixed
* @since 3.2.0
* @version 3.29.0
*/
public function get_data( $key, $lesson ) {
switch ( $key ) {
case 'actions':
$value = $this->get_actions_html( $lesson );
break;
case 'completed':
$date = $this->student->get_completion_date( $lesson->get( 'id' ) );
$value = $date ? $date : '–';
break;
case 'grade':
$grade = $this->student->get_grade( $lesson->get( 'id' ) );
$value = is_numeric( $grade ) ? $grade . '%' : $grade;
break;
case 'id':
$value = $this->get_post_link( $lesson->get( 'id' ) );
break;
case 'name':
$value = $lesson->get( 'title' );
break;
case 'quiz':
$q = $lesson->get( 'quiz' );
if ( $q ) {
$url = esc_url(
add_query_arg(
array(
'quiz_id' => $q,
'lesson_id' => $lesson->get( 'id' ),
)
)
);
$value = '<a href="' . $url . '">' . get_the_title( $q ) . '</a>';
} else {
$value = '–';
}
break;
default:
$value = $key;
}// End switch().
return $this->filter_get_data( $value, $key, $lesson );
}
/**
* Execute a query to retrieve results from the table
*
* @param array $args array of query args
* @return void
* @since 3.2.0
* @version 3.2.0
*/
public function get_results( $args = array() ) {
$course = new LLMS_Course( absint( $args['course_id'] ) );
if ( is_numeric( $args['student'] ) ) {
$args['student'] = new LLMS_Student( $args['student'] );
}
$this->student = $args['student'];
$this->tbody_data = $course->get_lessons();
}
/**
* Output a section title row for each course Section
*
* @param obj $lesson the current lesson instance
* @return void
* @since 3.2.0
* @version 3.21.0
*/
public function output_section_row_html( $lesson ) {
if ( $lesson instanceof LLMS_Lesson ) {
$sid = $lesson->get_parent_section();
if ( $this->current_section != $sid ) {
echo '<tr><td>' . $sid . '</td><td class="section-title" colspan="' . ( $this->get_columns_count() - 1 ) . '">' . sprintf( _x( 'Section: %s', 'section title', 'lifterlms' ), get_the_title( $sid ) ) . '</td></tr>';
$this->current_section = $sid;
}
}
}
/**
* Allow custom hooks to be registered for use within the class
*
* @return void
* @since 3.2.0
* @version 3.21.0
*/
protected function register_hooks() {
add_action( 'llms_table_before_tr', array( $this, 'output_section_row_html' ), 10, 1 );
}
/**
* Define the structure of arguments used to pass to the get_results method
*
* @since 2.3.0
* @since 3.35.0 Get student ID more reliably.
*
* @return array
*/
public function set_args() {
$student = false;
if ( ! empty( $this->student ) ) {
$student = $this->student->get_id();
} elseif ( ! empty( $_GET['student_id'] ) ) {
$student = llms_filter_input( INPUT_GET, 'student_id', FILTER_SANITIZE_NUMBER_INT );
}
return array(
'page' => $this->get_current_page(),
'student' => $student,
);
}
/**
* Define the structure of the table
*
* @return array
* @since 3.2.0
* @version 3.29.0
*/
public function set_columns() {
return array(
'id' => array(
'title' => __( 'ID', 'lifterlms' ),
),
'name' => array(
'title' => __( 'Name', 'lifterlms' ),
),
'quiz' => array(
'title' => __( 'Quiz', 'lifterlms' ),
),
'grade' => array(
'title' => __( 'Grade', 'lifterlms' ),
),
'completed' => array(
'title' => __( 'Completed', 'lifterlms' ),
),
'actions' => array(
'exportable' => false,
'title' => __( 'Actions', 'lifterlms' ),
),
);
}
}