mark comp time
Signed-off-by: Jeff <jeff@gotenzing.com>
Showing
2 changed files
with
19 additions
and
12 deletions
| 1 | .dataTables_wrapper .dataTables_length select{ | 1 | .dataTables_wrapper .dataTables_length select{ |
| 2 | width: 50px !important; | 2 | width: 50px !important; |
| 3 | } | 3 | } |
| 4 | table > tbody tr > td:last-child{ | ||
| 5 | width: 50px !important; | ||
| 6 | } | ||
| 7 | |||
| 4 | /*# sourceMappingURL=course-admin.css.map */ | 8 | /*# sourceMappingURL=course-admin.css.map */ |
| ... | \ No newline at end of file | ... | \ No newline at end of file | ... | ... |
| ... | @@ -37,19 +37,22 @@ if ( ( class_exists( 'LearnDash_Settings_Metabox' ) ) && ( ! class_exists( 'Lear | ... | @@ -37,19 +37,22 @@ if ( ( class_exists( 'LearnDash_Settings_Metabox' ) ) && ( ! class_exists( 'Lear |
| 37 | 37 | ||
| 38 | if ( ( ! empty( $course_id ) ) && ( get_post_type( $course_id ) === learndash_get_post_type_slug( 'course' ) ) ) { | 38 | if ( ( ! empty( $course_id ) ) && ( get_post_type( $course_id ) === learndash_get_post_type_slug( 'course' ) ) ) { |
| 39 | $users = learndash_get_course_users_access_from_meta( $course_id ); | 39 | $users = learndash_get_course_users_access_from_meta( $course_id ); |
| 40 | 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>'; | 40 | echo '<table style="table-layout:fixed;" id="markcomplete" width="100%"> <thead><tr><th>Enrolment Date</th><th>User Account</th><th>Email</th><th>First Name</th><th>Last Name</th><th>Last Online</th><th>Mark Complete</th></tr></thead>'; |
| 41 | foreach($users as $user){ | 41 | foreach($users as $user_id){ |
| 42 | $user_info = get_userdata($user); | 42 | $user_info = get_userdata($user_id); |
| 43 | $course_status = learndash_course_status( $course_id ,$user); | 43 | $course_status = learndash_course_status( $course_id ,$user_id); |
| 44 | if( $course_status != "Completed" ){ | 44 | if( $course_status != "Completed" ){ |
| 45 | $course_enrolled_since = ld_course_access_from( $course_id, $user ); | 45 | $course_enrolled_since = ld_course_access_from( $course_id, $user_id ); |
| 46 | $course_enrolled_since = learndash_adjust_date_time_display( $course_enrolled_since, 'Y-m-d H:i:s' ); | 46 | $course_enrolled_since = learndash_adjust_date_time_display( $course_enrolled_since, 'Y-m-d H:i:s' ); |
| 47 | $online = "Offline"; | 47 | $online = ""; |
| 48 | if(is_user_online( $user )){ | 48 | if(is_user_online( $user_id )){ |
| 49 | $online = "Online"; | 49 | $online = "Online"; |
| 50 | }else{ | ||
| 51 | $online = user_last_online($user_id); | ||
| 50 | } | 52 | } |
| 51 | 53 | ||
| 52 | 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>'; | 54 | echo '<tr><td>'. $course_enrolled_since .'</td><td> <a href="'.get_edit_user_link( $user_id ).'">'.$user_info->user_login.' |
| 55 | </a> </td><td><a href="mailto:'.$user_info->user_email .'">'.$user_info->user_email .'</a></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_id.'" data-course-id="'.$course_id.'" >Mark Complete</button></td></tr>'; | ||
| 53 | } | 56 | } |
| 54 | } | 57 | } |
| 55 | echo "</table>"; | 58 | echo "</table>"; |
| ... | @@ -136,7 +139,6 @@ function course_admin_script() { | ... | @@ -136,7 +139,6 @@ function course_admin_script() { |
| 136 | 139 | ||
| 137 | //Update user online status | 140 | //Update user online status |
| 138 | add_action('init', 'users_status_init'); | 141 | add_action('init', 'users_status_init'); |
| 139 | add_action('admin_init', 'users_status_init'); | ||
| 140 | function users_status_init(){ | 142 | function users_status_init(){ |
| 141 | $logged_in_users = get_transient('users_status'); //Get the active users from the transient. | 143 | $logged_in_users = get_transient('users_status'); //Get the active users from the transient. |
| 142 | $user = wp_get_current_user(); //Get the current user's data | 144 | $user = wp_get_current_user(); //Get the current user's data |
| ... | @@ -148,7 +150,7 @@ function users_status_init(){ | ... | @@ -148,7 +150,7 @@ function users_status_init(){ |
| 148 | 'username' => $user->user_login, | 150 | 'username' => $user->user_login, |
| 149 | 'last' => time(), | 151 | 'last' => time(), |
| 150 | ); | 152 | ); |
| 151 | set_transient('users_status', $logged_in_users, 900); //Set this transient to expire 15 minutes after it is created. | 153 | set_transient('users_status', $logged_in_users, 0); |
| 152 | } | 154 | } |
| 153 | } | 155 | } |
| 154 | 156 | ||
| ... | @@ -161,10 +163,11 @@ function is_user_online($id){ | ... | @@ -161,10 +163,11 @@ function is_user_online($id){ |
| 161 | //Check when a user was last online. | 163 | //Check when a user was last online. |
| 162 | function user_last_online($id){ | 164 | function user_last_online($id){ |
| 163 | $logged_in_users = get_transient('users_status'); //Get the active users from the transient. | 165 | $logged_in_users = get_transient('users_status'); //Get the active users from the transient. |
| 164 | |||
| 165 | //Determine if the user has ever been logged in (and return their last active date if so). | 166 | //Determine if the user has ever been logged in (and return their last active date if so). |
| 166 | if ( isset($logged_in_users[$id]['last']) ){ | 167 | if ( isset($logged_in_users[$id]['last']) ){ |
| 167 | return $logged_in_users[$id]['last']; | 168 | $date = new DateTime('@'.$logged_in_users[$id]['last']); |
| 169 | $date->setTimezone(new DateTimeZone('America/Toronto')); | ||
| 170 | return $date->format('Y-m-d H:i:s'); | ||
| 168 | } else { | 171 | } else { |
| 169 | return false; | 172 | return false; |
| 170 | } | 173 | } | ... | ... |
-
Please register or sign in to post a comment