5db9e236 by Jeff Balicki

mark as completed

Signed-off-by: Jeff <jeff@gotenzing.com>
1 parent 128fa44e
.dataTables_wrapper .dataTables_length select{
width: 50px !important;
}
/*# sourceMappingURL=course-admin.css.map */
\ No newline at end of file
......
{"version":3,"sources":["course-admin.css"],"names":[],"mappings":"AAAA;EACE,sBAAsB;AACxB","file":"course-admin.css","sourcesContent":[".dataTables_wrapper .dataTables_length select{\n width: 50px !important;\n}"]}
\ No newline at end of file
.dataTables_wrapper .dataTables_length select{width:50px!important}
/*# sourceMappingURL=course-admin.min.css.map */
\ No newline at end of file
{"version":3,"sources":["course-admin.css"],"names":[],"mappings":"AAAA,8CACE,MAAA","sourcesContent":[".dataTables_wrapper .dataTables_length select{\n width: 50px !important;\n}"]}
\ No newline at end of file
......@@ -37,14 +37,19 @@ if ( ( class_exists( 'LearnDash_Settings_Metabox' ) ) && ( ! class_exists( 'Lear
if ( ( ! empty( $course_id ) ) && ( get_post_type( $course_id ) === learndash_get_post_type_slug( 'course' ) ) ) {
$users = learndash_get_course_users_access_from_meta( $course_id );
echo '<table id="markcomplete" width="100%"> <thead><tr><th>Enrolment Date</th><th>Email</th><th>First Name</th><th>Last Name</th><th>Mark Complete</th></tr></thead>';
echo '<table id="markcomplete" width="100%"> <thead><tr><th>Enrolment Date</th><th>Email</th><th>First Name</th><th>Last Name</th><th>Online</th><th>Mark Complete</th></tr></thead>';
foreach($users as $user){
$user_info = get_userdata($user);
$course_status = learndash_course_status( $course_id ,$user);
if( $course_status != "Completed" ){
$course_enrolled_since = ld_course_access_from( $course_id, $user );
$course_enrolled_since = learndash_adjust_date_time_display( $course_enrolled_since, 'Y-m-d H:i:s' );
echo '<tr><td>'. $course_enrolled_since .'</td><td>'. $user_info->user_email .'</td><td>'.$user_info->first_name.'</td><td>'.$user_info->last_name.'</td><td><button class="mark_as_complete components-button is-primary" data-user-id="'.$user.'" data-course-id="'.$course_id.'" >Mark Complete</button></td></tr>';
$online = "Offline";
if(is_user_online( $user )){
$online = "Online";
}
echo '<tr><td>'. $course_enrolled_since .'</td><td>'. $user_info->user_email .'</td><td>'.$user_info->first_name.'</td><td>'.$user_info->last_name.'</td><td>'. $online .'</td><td><button class="mark_as_complete components-button is-primary" data-user-id="'.$user.'" data-course-id="'.$course_id.'" >Mark Complete</button></td></tr>';
}
}
echo "</table>";
......@@ -127,3 +132,40 @@ function course_admin_script() {
}
//Update user online status
add_action('init', 'users_status_init');
add_action('admin_init', 'users_status_init');
function users_status_init(){
$logged_in_users = get_transient('users_status'); //Get the active users from the transient.
$user = wp_get_current_user(); //Get the current user's data
//Update the user if they are not on the list, or if they have not been online in the last 900 seconds (15 minutes)
if ( !isset($logged_in_users[$user->ID]['last']) || $logged_in_users[$user->ID]['last'] <= time()-900 ){
$logged_in_users[$user->ID] = array(
'id' => $user->ID,
'username' => $user->user_login,
'last' => time(),
);
set_transient('users_status', $logged_in_users, 900); //Set this transient to expire 15 minutes after it is created.
}
}
//Check if a user has been online in the last 15 minutes
function is_user_online($id){
$logged_in_users = get_transient('users_status'); //Get the active users from the transient.
return isset($logged_in_users[$id]['last']) && $logged_in_users[$id]['last'] > time()-900; //Return boolean if the user has been online in the last 900 seconds (15 minutes).
}
//Check when a user was last online.
function user_last_online($id){
$logged_in_users = get_transient('users_status'); //Get the active users from the transient.
//Determine if the user has ever been logged in (and return their last active date if so).
if ( isset($logged_in_users[$id]['last']) ){
return $logged_in_users[$id]['last'];
} else {
return false;
}
}
\ No newline at end of file
......