LLMS_Analytics::get_students( $search )
Description Description
Source Source
File: includes/class.llms.analytics.php
public static function get_students( $search ) { $student_arrays = array(); $students_large = array(); $students_small = array(); if ( ! empty( $search->students ) ) { //create new course object $course = new LLMS_Course( $search->product_id ); foreach ( $search->students as $student ) { //get student name $first_name = get_user_meta( $student->user_id, 'first_name', true ); $last_name = get_user_meta( $student->user_id, 'last_name', true ); $profile_link = '<a href="' . get_admin_url( '', 'admin.php?page=llms-students&tab=profile&student=' . $student->user_id ) . '">View</a>'; //get student progress information $student_progress = $course->get_student_progress( $student->user_id ); $start_date = LLMS_Date::db_date( $student_progress->start_date ); //set variables for lesson progress statistics $completed_lesson_count = 0; $last_completed_lesson = ''; $last_completed_lesson_date = 0; $all_lesson_count = 0; if ( ! empty( $student_progress->lessons ) ) { $all_lesson_count = count( $student_progress->lessons ); foreach ( $student_progress->lessons as $lesson ) { if ( $lesson['is_complete'] ) { //add 1 to completed lesson count $completed_lesson_count++; //if lesson completed date is > than the previous completed lesson date //Set the last completed lesson and date if ( $lesson['completed_date'] > $last_completed_lesson_date ) { $last_completed_lesson = get_the_title( $lesson['id'] ); $last_completed_lesson_date = LLMS_Date::db_date( $lesson['completed_date'] ); } } } } // End if(). //calculate % complete if ( 0 == $all_lesson_count ) { $completion_percent = '0%'; } else { $completion_percent = ( LLMS_Number::whole_number( $completed_lesson_count / $all_lesson_count ) . '%' ); } //add data to large table array $student_data = array( $last_name, $first_name, $start_date, $completion_percent, ( $last_completed_lesson ? $last_completed_lesson . ', ' . $last_completed_lesson_date : '' ), $profile_link, ); array_push( $students_large, $student_data ); //add data to small table $student_data = array( $first_name, $last_name, $profile_link, ); array_push( $students_small, $student_data ); } // End foreach(). $student_arrays['large'] = $students_large; $student_arrays['small'] = $students_small; return $student_arrays; }// End if(). }
Expand full source code Collapse full source code View on GitHub