diff --git a/main/inc/lib/tracking.lib.php b/main/inc/lib/tracking.lib.php index fff56ec5901..ca47048b146 100755 --- a/main/inc/lib/tracking.lib.php +++ b/main/inc/lib/tracking.lib.php @@ -8709,12 +8709,15 @@ public static function generateReport(string $reportType, array $selectedUserLis $session = api_get_session_info($row['session_id']); $course = api_get_course_info_by_id($row['c_id']); + $sessionName = $session['name'] ?? ''; + $courseTitle = $course['title'] ?? ''; + if ($reportType == 'time_report') { $rows[] = [ $user['lastname'], $user['firstname'], - $session['name'], - $course['title'], + $sessionName, + $courseTitle, api_get_local_time($row['login_course_date']), api_get_local_time($row['logout_course_date']), gmdate('H:i:s', $row['time']), @@ -8724,8 +8727,8 @@ public static function generateReport(string $reportType, array $selectedUserLis $rows[] = [ $user['lastname'], $user['firstname'], - $session['name'], - $course['title'], + $sessionName, + $courseTitle, $row['lp_name'], api_get_local_time(date('Y-m-d H:i:s', $row['start_time'])), $extraFieldValue['value'] ?? '', diff --git a/main/install/configuration.dist.php b/main/install/configuration.dist.php index e970c69be8d..917afabbb30 100644 --- a/main/install/configuration.dist.php +++ b/main/install/configuration.dist.php @@ -1953,6 +1953,9 @@ //Create an extra field for courses with identifier "theoretical_time" //$_configuration['display_theoretical_time'] = false; +// Enable improved tracking section in main/mySpace/myStudents.php +//$_configuration['improve_tracking_in_mystudent_php'] = false; + // Add teachers column in course list. // $_configuration['add_teachers_in_course_list'] = false; diff --git a/main/mySpace/myStudents.php b/main/mySpace/myStudents.php index 53a4e18f0fd..77ab0f5d799 100755 --- a/main/mySpace/myStudents.php +++ b/main/mySpace/myStudents.php @@ -1195,6 +1195,111 @@ echo MyStudents::userCareersTable($student_id); } +// Session progress section +if (api_get_configuration_value('improve_tracking_in_mystudent_php')) { + $orderCondition = null; + if (api_get_configuration_value('session_list_order')) { + $orderCondition = ' ORDER BY s.position ASC'; + } + $sessions = SessionManager::getSessionsFollowedByUser( + $student_id, + null, + null, + null, + false, + false, + false, + $orderCondition + ); + $sessionProgressTitle = get_lang('synthesis'); + $sessionProgressHeading = '

'.$sessionProgressTitle.'

'; + $sessionProgressList = []; + $totalSessionsProgress = 0; + foreach ($sessions as $sessionItem) { + $courses = SessionManager::get_course_list_by_session_id($sessionItem['id']); + $courseProgressSum = 0; + $courseCount = 0; + foreach ($courses as $courseItem) { + $courseInfoItem = api_get_course_info_by_id($courseItem['real_id']); + $courseCodeItem = $courseInfoItem['code']; + if (CourseManager::is_user_subscribed_in_course($student_id, $courseCodeItem, true, $sessionItem['id'])) { + $progressValue = Tracking::get_avg_student_progress( + $student_id, + $courseCodeItem, + [], + $sessionItem['id'] + ); + if (is_numeric($progressValue)) { + $courseProgressSum += $progressValue; + } + $courseCount++; + } + } + $progress = $courseCount > 0 ? round($courseProgressSum / $courseCount, 2) : 0; + $sessionProgressList[] = [ + 'name' => $sessionItem['name'], + 'progress' => $progress, + ]; + $totalSessionsProgress += $progress; + } + $avgSessionsProgress = !empty($sessionProgressList) ? round($totalSessionsProgress / count($sessionProgressList), 2) : 0; + + // Calculate last week's time spent in courses using Tracking::generateReport + $aLastWeek = get_last_week(); + $startWeek = date('Y-m-d', $aLastWeek[0]); + $endWeek = date('Y-m-d', $aLastWeek[6]); + $report = Tracking::generateReport('time_report', [$student_id], $startWeek, $endWeek); + $timeSeconds = 0; + foreach ($report['rows'] as $reportRow) { + $timeParts = explode(':', $reportRow[6]); + if (count($timeParts) === 3) { + [$hours, $minutes, $seconds] = array_map('intval', $timeParts); + $timeSeconds += ($hours * 3600) + ($minutes * 60) + $seconds; + } + } + $timeSpentLastWeek = api_time_to_hms($timeSeconds); + $timeContent = '
'; + $timeContent .= Display::return_icon('clock.png', get_lang('TimeSpentLastWeek'), [], ICON_SIZE_MEDIUM); + $timeContent .= ' '.$timeSpentLastWeek; + $timeContent .= '
'; + $timePanel = Display::panel($timeContent, get_lang('TimeSpentInCoursesLastWeek')); + + $donutContent = '
'; + $donutContent .= '
'; + $donutContent .= ''.$avgSessionsProgress.'%'; + $donutContent .= '
'; + $donutContent .= '
'; + $donutPanel = Display::panel($donutContent, get_lang('AverageProgressInSessions')); + + $sessionBars = ''; + foreach ($sessionProgressList as $item) { + $sessionBars .= '

'.Security::remove_XSS($item['name']).'

'; + $sessionBars .= '
'; + $sessionBars .= '
'.$item['progress'].'%
'; + $sessionBars .= '
'; + } + $sessionBarsPanel = Display::panel($sessionBars); + + $sessionProgressHtml = '
'; + $sessionProgressHtml .= '
'.$sessionBarsPanel.'
'; + $sessionProgressHtml .= '
'; + $sessionProgressHtml .= $donutPanel; + $sessionProgressHtml .= $timePanel; + $sessionProgressHtml .= '
'; + $sessionProgressHtml .= '
'; + echo Display::panel($sessionProgressHtml, '', '', 'default', $sessionProgressHeading); + echo ""; +} + echo MyStudents::getBlockForSkills( $student_id, $courseInfo ? $courseInfo['real_id'] : 0,