LLMS_Table_Student_Courses

LLMS_Table_Student_Courses class


Source Source

File: includes/admin/reporting/tables/llms.table.student.courses.php

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
class LLMS_Table_Student_Courses extends LLMS_Admin_Table {
 
    /**
     * Unique ID for the Table
     *
     * @var  string
     */
    protected $id = 'student-courses';
 
    /**
     * If true, tfoot will add ajax pagination links
     *
     * @var  boolean
     */
    protected $is_paginated = true;
 
    /**
     * 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
     */
    protected $student = null;
 
    /**
     * Retrieve data for the columns
     *
     * @param    string $key        the column id / key
     * @param    int    $course_id  ID of the course
     * @return   mixed
     * @since    3.2.0
     * @version  3.13.0
     */
    public function get_data( $key, $course_id ) {
 
        $course = new LLMS_Course( $course_id );
 
        switch ( $key ) {
 
            case 'progress':
                $value = $this->student->get_progress( $course->get( 'id' ), 'course' ) . '%';
                break;
 
            case 'completed':
                $date  = $this->student->get_completion_date( $course->get( 'id' ) );
                $value = $date ? $date : '–';
                break;
 
            case 'grade':
                $grade = $this->student->get_grade( $course->get( 'id' ) );
                $value = is_numeric( $grade ) ? $grade . '%' : $grade;
 
                break;
 
            case 'id':
                $value = $course->get( 'id' );
                if ( current_user_can( 'edit_post', $value ) ) {
                    $value = $this->get_post_link( $value );
                }
                break;
 
            case 'name':
                $id = $course->get( 'id' );
                if ( current_user_can( 'edit_post', $id ) ) {
                    $url   = esc_url(
                        add_query_arg(
                            array(
                                'course_id'  => $course->get( 'id' ),
                                'page'       => 'llms-reporting',
                                'stab'       => 'courses',
                                'student_id' => $this->student->get_id(),
                            ),
                            admin_url( 'admin.php' )
                        )
                    );
                    $value = '<a href="' . $url . '">' . $course->get( 'title' ) . '</a>';
                } else {
                    $value = $course->get( 'title' );
                }
                break;
 
            case 'status':
                $value = llms_get_enrollment_status_name( $this->student->get_enrollment_status( $course->get( 'id' ) ) );
                break;
 
            case 'updated':
                $value = $this->student->get_enrollment_date( $course->get( 'id' ), 'updated' );
                break;
 
            default:
                $value = $key;
 
        }// End switch().
 
        return $this->filter_get_data( $value, $key, $course_id );
 
    }
 
    /**
     * 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() ) {
 
        $args = $this->clean_args( $args );
 
        if ( is_numeric( $args['student'] ) ) {
            $args['student'] = new LLMS_Student( $args['student'] );
        }
 
        $this->student = $args['student'];
 
        if ( isset( $args['page'] ) ) {
            $this->current_page = absint( $args['page'] );
        }
 
        $per = apply_filters( 'llms_gradebook_' . $this->id . '_per_page', 20 );
 
        $order = ! empty( $args['order'] ) ? $args['order'] : 'ASC';
        $order = in_array( $order, array( 'ASC', 'DESC' ) ) ? $order : 'ASC';
 
        if ( isset( $args['order'] ) ) {
            $this->order = $order;
        }
        if ( isset( $args['orderby'] ) ) {
            $this->orderby = $args['orderby'];
        }
 
        switch ( $this->orderby ) {
 
            case 'updated':
                $orderby = 'upm.updated_date';
                break;
 
            case 'name':
            default:
                $orderby = 'p.post_title';
 
        }
 
        $courses = $this->student->get_courses(
            array(
                'limit'   => $per,
                'skip'    => ( $this->current_page - 1 ) * $per,
                'orderby' => $orderby,
                'order'   => $order,
            )
        );
 
        if ( $courses['more'] ) {
            $this->is_last_page = false;
        }
 
        $this->tbody_data = $courses['results'];
 
    }
 
    /**
     * Define the structure of arguments used to pass to the get_results method
     *
     * @since 2.3.0
     * @since 3.35.0 Sanitize `$_GET` data.
     *
     * @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.2.0
     */
    public function set_columns() {
        return array(
            'id'        => array(
                'title' => __( 'ID', 'lifterlms' ),
            ),
            'name'      => array(
                'title'    => __( 'Name', 'lifterlms' ),
                'sortable' => true,
            ),
            'status'    => array(
                'title' => __( 'Status', 'lifterlms' ),
            ),
            'grade'     => array(
                'title' => __( 'Grade', 'lifterlms' ),
            ),
            'progress'  => array(
                'title' => __( 'Progress', 'lifterlms' ),
            ),
            'updated'   => array(
                'title'    => __( 'Updated', 'lifterlms' ),
                'sortable' => true,
            ),
            'completed' => array(
                'title' => __( 'Completed', 'lifterlms' ),
            ),
        );
    }
 
    /**
     * Empty message displayed when no results are found
     *
     * @return   string
     * @since    3.2.0
     * @version  3.2.0
     */
    protected function set_empty_message() {
        return __( 'This student is not enrolled in any courses.', 'lifterlms' );
    }
 
}


Top ↑

Methods Methods

  • get_data — Retrieve data for the columns
  • get_results — Execute a query to retrieve results from the table
  • set_args — Define the structure of arguments used to pass to the get_results method
  • set_columns — Define the structure of the table
  • set_empty_message — Empty message displayed when no results are found

Top ↑

Changelog Changelog

Changelog
Version Description
3.2.0
3.13.0 Introduced.

Top ↑

User Contributed Notes User Contributed Notes

You must log in before being able to contribute a note or feedback.