lp_report.php 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * Report from students for learning path
  5. */
  6. require_once __DIR__.'/../inc/global.inc.php';
  7. $isAllowedToEdit = api_is_allowed_to_edit(null, true);
  8. if (!$isAllowedToEdit) {
  9. api_not_allowed(true);
  10. }
  11. $lpTable = Database::get_course_table(TABLE_LP_MAIN);
  12. $lpId = isset($_GET['lp_id']) ? intval($_GET['lp_id']) : false;
  13. if (empty($lpId)) {
  14. api_not_allowed(true);
  15. }
  16. $sessionId = api_get_session_id();
  17. $courseId = api_get_course_int_id();
  18. $courseCode = api_get_course_id();
  19. if (empty($sessionId)) {
  20. $status = STUDENT;
  21. $users = CourseManager::get_user_list_from_course_code(
  22. $courseCode,
  23. 0,
  24. null,
  25. null,
  26. $status
  27. );
  28. } else {
  29. $status = 0; // student
  30. $users = CourseManager::get_user_list_from_course_code(
  31. $courseCode,
  32. $sessionId,
  33. null,
  34. null,
  35. $status
  36. );
  37. }
  38. $lpInfo = Database::select(
  39. '*',
  40. $lpTable,
  41. array(
  42. 'where' => array(
  43. 'c_id = ? AND ' => $courseId,
  44. 'id = ?' => $lpId
  45. )
  46. ),
  47. 'first'
  48. );
  49. $userList = [];
  50. $showEmail = api_get_setting('show_email_addresses');
  51. if (!empty($users)) {
  52. foreach ($users as $user) {
  53. $userInfo = api_get_user_info($user['user_id']);
  54. $lpTime = Tracking::get_time_spent_in_lp(
  55. $user['user_id'],
  56. $courseCode,
  57. array($lpId),
  58. $sessionId
  59. );
  60. $lpScore = Tracking::get_avg_student_score(
  61. $user['user_id'],
  62. $courseCode,
  63. array($lpId),
  64. $sessionId
  65. );
  66. $lpProgress = Tracking::get_avg_student_progress(
  67. $user['user_id'],
  68. $courseCode,
  69. array($lpId),
  70. $sessionId
  71. );
  72. $lpLastConnection = Tracking::get_last_connection_time_in_lp(
  73. $user['user_id'],
  74. $courseCode,
  75. array($lpId),
  76. $sessionId
  77. );
  78. $lpLastConnection = empty($lpLastConnection) ? '-' : api_convert_and_format_date(
  79. $lpLastConnection,
  80. DATE_TIME_FORMAT_LONG
  81. );
  82. $userList[] = [
  83. 'id' => $user['user_id'],
  84. 'first_name' => $userInfo['firstname'],
  85. 'last_name' => $userInfo['lastname'],
  86. 'email' => $showEmail === 'true' ? $userInfo['email'] : '',
  87. 'lp_time' => api_time_to_hms($lpTime),
  88. 'lp_score' => is_numeric($lpScore) ? "$lpScore%" : $lpScore,
  89. 'lp_progress' => "$lpProgress%",
  90. 'lp_last_connection' => $lpLastConnection
  91. ];
  92. }
  93. }
  94. // View
  95. $interbreadcrumb[] = [
  96. 'url' => api_get_path(WEB_CODE_PATH).'lp/lp_controller.php?'.api_get_cidreq(),
  97. 'name' => get_lang('LearningPaths')
  98. ];
  99. $actions = Display::url(
  100. Display::return_icon(
  101. 'back.png',
  102. get_lang('Back'),
  103. array(),
  104. ICON_SIZE_MEDIUM
  105. ),
  106. api_get_path(WEB_CODE_PATH).'lp/lp_controller.php?'.api_get_cidreq()
  107. );
  108. $template = new Template(get_lang('StudentScore'));
  109. $template->assign('user_list', $userList);
  110. $template->assign('session_id', api_get_session_id());
  111. $template->assign('course_code', api_get_course_id());
  112. $template->assign('lp_id', $lpId);
  113. $template->assign('show_email', $showEmail === 'true');
  114. $layout = $template->get_template('learnpath/report.tpl');
  115. $template->assign('header', $lpInfo['name']);
  116. $template->assign(
  117. 'actions',
  118. Display::toolbarAction('lp_actions', [$actions])
  119. );
  120. $template->assign('content', $template->fetch($layout));
  121. $template->display_one_col_template();