mark as completed
Signed-off-by: Jeff <jeff@gotenzing.com>
Showing
5 changed files
with
49 additions
and
2 deletions
| 1 | {"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 | ... | \ No newline at end of file |
| 1 | {"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 | ... | \ No newline at end of file |
| ... | @@ -37,14 +37,19 @@ if ( ( class_exists( 'LearnDash_Settings_Metabox' ) ) && ( ! class_exists( 'Lear | ... | @@ -37,14 +37,19 @@ 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>Mark Complete</th></tr></thead>'; | 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>'; |
| 41 | foreach($users as $user){ | 41 | foreach($users as $user){ |
| 42 | $user_info = get_userdata($user); | 42 | $user_info = get_userdata($user); |
| 43 | $course_status = learndash_course_status( $course_id ,$user); | 43 | $course_status = learndash_course_status( $course_id ,$user); |
| 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 ); |
| 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 | 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>'; | 47 | $online = "Offline"; |
| 48 | if(is_user_online( $user )){ | ||
| 49 | $online = "Online"; | ||
| 50 | } | ||
| 51 | |||
| 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>'; | ||
| 48 | } | 53 | } |
| 49 | } | 54 | } |
| 50 | echo "</table>"; | 55 | echo "</table>"; |
| ... | @@ -127,3 +132,40 @@ function course_admin_script() { | ... | @@ -127,3 +132,40 @@ function course_admin_script() { |
| 127 | 132 | ||
| 128 | 133 | ||
| 129 | } | 134 | } |
| 135 | |||
| 136 | |||
| 137 | //Update user online status | ||
| 138 | add_action('init', 'users_status_init'); | ||
| 139 | add_action('admin_init', 'users_status_init'); | ||
| 140 | function users_status_init(){ | ||
| 141 | $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 | ||
| 143 | |||
| 144 | //Update the user if they are not on the list, or if they have not been online in the last 900 seconds (15 minutes) | ||
| 145 | if ( !isset($logged_in_users[$user->ID]['last']) || $logged_in_users[$user->ID]['last'] <= time()-900 ){ | ||
| 146 | $logged_in_users[$user->ID] = array( | ||
| 147 | 'id' => $user->ID, | ||
| 148 | 'username' => $user->user_login, | ||
| 149 | 'last' => time(), | ||
| 150 | ); | ||
| 151 | set_transient('users_status', $logged_in_users, 900); //Set this transient to expire 15 minutes after it is created. | ||
| 152 | } | ||
| 153 | } | ||
| 154 | |||
| 155 | //Check if a user has been online in the last 15 minutes | ||
| 156 | function is_user_online($id){ | ||
| 157 | $logged_in_users = get_transient('users_status'); //Get the active users from the transient. | ||
| 158 | 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). | ||
| 159 | } | ||
| 160 | |||
| 161 | //Check when a user was last online. | ||
| 162 | function user_last_online($id){ | ||
| 163 | $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 | if ( isset($logged_in_users[$id]['last']) ){ | ||
| 167 | return $logged_in_users[$id]['last']; | ||
| 168 | } else { | ||
| 169 | return false; | ||
| 170 | } | ||
| 171 | } | ||
| ... | \ No newline at end of file | ... | \ No newline at end of file | ... | ... |
-
Please register or sign in to post a comment