We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Display the total hours and minutes that students have spent on a course.
Find a proper place to show the asked value (for example, a report, or Courses -> [Course] -> Manage.
In case it helps, here's a hook that shows the total time spent by a student on all complete courses in the Reports -> Students table
add_filter( 'sensei_analysis_overview_columns', function( $columns, $instance ) { if ( ! $instance instanceof Sensei_Reports_Overview_List_Table_Students ) { return $columns; } $columns['sum_of_days'] = __( 'Total Days to Complete Courses', 'sensei-lms' ); return $columns; }, 10, 2 ); add_filter( 'sensei_analysis_overview_column_data', function( $column_data, $item, $instance ) { if ( ! $instance instanceof Sensei_Reports_Overview_List_Table_Students ) { return $column_data; } $completed_course_ids = Sensei_Utils::sensei_activity_ids( [ 'user_id' => $item->ID, 'type' => 'sensei_course_status', 'status' => 'complete', ] ); $column_data['sum_of_days'] = ( is_array( $completed_course_ids ) && count( $completed_course_ids ) > 0 ) ? get_sum_days_to_completion( $completed_course_ids, $item->ID ) : 0; return $column_data; }, 10, 3 ); function get_sum_days_to_completion( array $course_ids, int $user_id ) : float { if ( empty( $course_ids ) ) { return 0; } global $wpdb; $query = " SELECT SUM( aggregated.days_to_completion ) FROM ( SELECT GREATEST( CEIL( TIMESTAMPDIFF(SECOND, STR_TO_DATE( {$wpdb->commentmeta}.meta_value, '%Y-%m-%d %H:%i:%s' ), {$wpdb->comments}.comment_date ) / 86400 ), 1 ) AS days_to_completion FROM {$wpdb->comments} LEFT JOIN {$wpdb->commentmeta} ON {$wpdb->comments}.comment_ID = {$wpdb->commentmeta}.comment_id AND {$wpdb->commentmeta}.meta_key = 'start' WHERE {$wpdb->comments}.comment_type = 'sensei_course_status' AND {$wpdb->comments}.comment_approved = 'complete' AND {$wpdb->comments}.comment_post_ID IN ( " . implode( ',', array_map( 'intval', $course_ids ) ) . " ) AND {$wpdb->comments}.user_id = {$user_id} GROUP BY {$wpdb->comments}.comment_post_ID ) AS aggregated"; // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.PreparedSQL.NotPrepared, WordPress.DB.DirectDatabaseQuery.NoCaching -- Performance improvement. return (float) $wpdb->get_var( $query ); }
p1725367444476299-slack-C07418EJ0
The text was updated successfully, but these errors were encountered:
No branches or pull requests
Is your feature request related to a problem? Please describe
Display the total hours and minutes that students have spent on a course.
Describe the solution you'd like
Find a proper place to show the asked value (for example, a report, or Courses -> [Course] -> Manage.
In case it helps, here's a hook that shows the total time spent by a student on all complete courses in the Reports -> Students table
Additional context
p1725367444476299-slack-C07418EJ0
The text was updated successfully, but these errors were encountered: