From 70010ce5f026b51db4c8c112b10058deda8f7585 Mon Sep 17 00:00:00 2001 From: Christian Date: Thu, 11 Nov 2021 12:57:39 -0500 Subject: [PATCH] Learnpath: Add option to show the max progress instead average - refs BT#19309 --- main/inc/lib/tracking.lib.php | 30 ++++++++++++++++++++++++----- main/install/configuration.dist.php | 3 ++- main/tracking/courseLog.php | 5 ++++- 3 files changed, 31 insertions(+), 7 deletions(-) diff --git a/main/inc/lib/tracking.lib.php b/main/inc/lib/tracking.lib.php index 2566d746d7..956ac2ac49 100755 --- a/main/inc/lib/tracking.lib.php +++ b/main/inc/lib/tracking.lib.php @@ -3011,8 +3011,9 @@ class Tracking * @param bool $returnArray Will return an array of the type: * [sum_of_progresses, number] if it is set to true * @param bool $onlySeriousGame Optional. Limit average to lp on seriousgame mode + * @param bool $maxInsteadAvg Optional. It will return the max progress instead the average * - * @return float Average progress of the user in this course from 0 to 100 + * @return float Average or max progress of the user in this course from 0 to 100 */ public static function get_avg_student_progress( $studentId, @@ -3020,7 +3021,8 @@ class Tracking $lpIdList = [], $sessionId = null, $returnArray = false, - $onlySeriousGame = false + $onlySeriousGame = false, + $maxInsteadAvg = false ) { // If there is at least one learning path and one student. if (empty($studentId)) { @@ -3146,6 +3148,11 @@ class Tracking if (!empty($newProgress)) { $sum = array_sum($newProgress); $average = $sum / $total; + + // It will return the max progress instead the average + if ($maxInsteadAvg) { + return max($newProgress); + } } if ($returnArray) { @@ -5230,6 +5237,7 @@ class Tracking if (!empty($session_id)) { $sessionCondition = " AND s.id = $session_id"; } + $lpShowMaxProgress = api_get_configuration_value('lp_show_max_progress_instead_of_average'); // Get the list of sessions where the user is subscribed as student if (api_is_multiple_url_enabled()) { @@ -5345,7 +5353,12 @@ class Tracking $time = api_time_to_hms($total_time_login); $progress = self::get_avg_student_progress( $user_id, - $course_code + $course_code, + [], + null, + false, + false, + $lpShowMaxProgress ); $bestScore = self::get_avg_student_score( $user_id, @@ -5786,7 +5799,10 @@ class Tracking $user_id, $course_code, [], - $session_id_from_get + $session_id_from_get, + false, + false, + $lpShowMaxProgress ); $total_time_login = self::get_time_spent_on_the_course( @@ -8990,11 +9006,15 @@ class TrackingCourseLog true ); + $lpShowMaxProgress = api_get_configuration_value('lp_show_max_progress_instead_of_average'); $avg_student_progress = Tracking::get_avg_student_progress( $user['user_id'], $course_code, [], - $session_id + $session_id, + false, + false, + $lpShowMaxProgress ); if (empty($avg_student_progress)) { diff --git a/main/install/configuration.dist.php b/main/install/configuration.dist.php index c9b6ca7f95..d0f3c2c3f0 100755 --- a/main/install/configuration.dist.php +++ b/main/install/configuration.dist.php @@ -490,7 +490,8 @@ ALTER TABLE sys_announcement ADD COLUMN visible_boss INT DEFAULT 0; //$_configuration['tracking_skip_generic_data'] = false; // Show view accordion lp_category //$_configuration['lp_category_accordion'] = false; -// +// Show the best progress instead of averages in reporting of learnpaths +// $_configuration['lp_show_max_progress_instead_of_average'] = false; // Show view accordion lp_item_view // $_configuration['lp_view_accordion'] = false; // Allow export learning paths to students diff --git a/main/tracking/courseLog.php b/main/tracking/courseLog.php index 52dcfefcd0..426488eee1 100755 --- a/main/tracking/courseLog.php +++ b/main/tracking/courseLog.php @@ -29,6 +29,7 @@ $sortByFirstName = api_sort_by_first_name(); $from_myspace = false; $from = isset($_GET['from']) ? $_GET['from'] : null; $origin = api_get_origin(); +$lpShowMaxProgress = api_get_configuration_value('lp_show_max_progress_instead_of_average'); // Starting the output buffering when we are exporting the information. $export_csv = isset($_GET['export']) && 'csv' === $_GET['export'] ? true : false; @@ -682,10 +683,12 @@ if ($nbStudents > 0) { false ); $headers['training_time'] = get_lang('TrainingTime'); + + $courseProgressHeadTitle = ($lpShowMaxProgress ? get_lang('ScormAndLPMaxProgress'): get_lang('ScormAndLPProgressTotalAverage')); $table->set_header( $headerCounter++, get_lang('CourseProgress').' '. - Display::return_icon('info3.gif', get_lang('ScormAndLPProgressTotalAverage'), [], ICON_SIZE_TINY), + Display::return_icon('info3.gif', $courseProgressHeadTitle, [], ICON_SIZE_TINY), false ); $headers['course_progress'] = get_lang('CourseProgress');