From 4ee07f620b30197ff2d2afc2ce9e9297f424d3be Mon Sep 17 00:00:00 2001 From: Julio Montoya Date: Tue, 14 Jan 2020 09:19:47 +0100 Subject: [PATCH] Change $totalTimeInLearningPaths calculations BT#16348 --- main/inc/lib/certificate.lib.php | 33 +++++++++++++++++++++++++------- 1 file changed, 26 insertions(+), 7 deletions(-) diff --git a/main/inc/lib/certificate.lib.php b/main/inc/lib/certificate.lib.php index f1f39df158..a59c0907b0 100755 --- a/main/inc/lib/certificate.lib.php +++ b/main/inc/lib/certificate.lib.php @@ -712,6 +712,8 @@ class Certificate extends Model $totalTimeInLearningPaths = 0; $sessionsApproved = []; $coursesApproved = []; + $courseList = []; + if ($sessions) { foreach ($sessions as $session) { $allCoursesApproved = []; @@ -736,19 +738,29 @@ class Certificate extends Model true ); + + // Find time spent in LP + $timeSpent = Tracking::get_time_spent_in_lp( + $this->user_id, + $courseCode, + [], + $session['session_id'] + ); + + if (!isset($courseList[$course['real_id']])) { + $courseList[$course['real_id']]['approved'] = false; + $courseList[$course['real_id']]['time_spent'] = 0; + } + if ($result) { + $courseList[$course['real_id']]['approved'] = true; $coursesApproved[$course['real_id']] = $courseInfo['title']; // Find time spent in LP - $totalTimeInLearningPaths += Tracking::get_time_spent_in_lp( - $this->user_id, - $courseCode, - [], - $session['session_id'] - ); - + //$totalTimeInLearningPaths += $timeSpent; $allCoursesApproved[] = true; } + $courseList[$course['real_id']]['time_spent'] += $timeSpent; } } @@ -758,6 +770,13 @@ class Certificate extends Model } } + $totalTimeInLearningPaths = 0; + foreach ($courseList as $courseId => $courseData) { + if ($courseData['approved'] === true) { + $totalTimeInLearningPaths += $courseData['time_spent']; + } + } + $skill = new Skill(); // Ofaj $skills = $skill->getStudentSkills($this->user_id, 2);