lp_report.php 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  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. if (!empty($users)) {
  51. foreach ($users as $user) {
  52. $userInfo = api_get_user_info($user['user_id']);
  53. $lpTime = Tracking::get_time_spent_in_lp(
  54. $user['user_id'],
  55. $courseCode,
  56. array($lpId),
  57. $sessionId
  58. );
  59. $lpScore = Tracking::get_avg_student_score(
  60. $user['user_id'],
  61. $courseCode,
  62. array($lpId),
  63. $sessionId
  64. );
  65. $lpProgress = Tracking::get_avg_student_progress(
  66. $user['user_id'],
  67. $courseCode,
  68. array($lpId),
  69. $sessionId
  70. );
  71. $lpLastConnection = Tracking::get_last_connection_time_in_lp(
  72. $user['user_id'],
  73. $courseCode,
  74. array($lpId),
  75. $sessionId
  76. );
  77. $lpLastConnection = empty($lpLastConnection) ? '-' : api_convert_and_format_date(
  78. $lpLastConnection,
  79. DATE_TIME_FORMAT_LONG
  80. );
  81. $userList[] = [
  82. 'id' => $user['user_id'],
  83. 'first_name' => $userInfo['firstname'],
  84. 'last_name' => $userInfo['lastname'],
  85. 'lp_time' => api_time_to_hms($lpTime),
  86. 'lp_score' => is_numeric($lpScore) ? "$lpScore%" : $lpScore,
  87. 'lp_progress' => "$lpProgress%",
  88. 'lp_last_connection' => $lpLastConnection
  89. ];
  90. }
  91. }
  92. // View
  93. $interbreadcrumb[] = [
  94. 'url' => api_get_path(WEB_CODE_PATH) . 'lp/lp_controller.php?'.api_get_cidreq(),
  95. 'name' => get_lang('LearningPaths')
  96. ];
  97. $actions = Display::url(
  98. Display::return_icon(
  99. 'back.png',
  100. get_lang('Back'),
  101. array(),
  102. ICON_SIZE_MEDIUM
  103. ),
  104. api_get_path(WEB_CODE_PATH) . 'lp/lp_controller.php?' . api_get_cidreq()
  105. );
  106. $template = new Template(get_lang('StudentScore'));
  107. $template->assign('user_list', $userList);
  108. $template->assign('session_id', api_get_session_id());
  109. $template->assign('course_code', api_get_course_id());
  110. $template->assign('lp_id', $lpId);
  111. $layout = $template->get_template('learnpath/report.tpl');
  112. $template->assign('header', $lpInfo['name']);
  113. $template->assign('actions', $actions);
  114. $template->assign('content', $template->fetch($layout));
  115. $template->display_one_col_template();