lp_report.php 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  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. $export = isset($_GET['export']) ? true : false;
  14. if (empty($lpId)) {
  15. api_not_allowed(true);
  16. }
  17. $sessionId = api_get_session_id();
  18. $courseId = api_get_course_int_id();
  19. $courseCode = api_get_course_id();
  20. if (empty($sessionId)) {
  21. $status = STUDENT;
  22. $users = CourseManager::get_user_list_from_course_code(
  23. $courseCode,
  24. 0,
  25. null,
  26. null,
  27. $status
  28. );
  29. } else {
  30. $status = 0; // student
  31. $users = CourseManager::get_user_list_from_course_code(
  32. $courseCode,
  33. $sessionId,
  34. null,
  35. null,
  36. $status
  37. );
  38. }
  39. $lpInfo = Database::select(
  40. '*',
  41. $lpTable,
  42. [
  43. 'where' => [
  44. 'c_id = ? AND ' => $courseId,
  45. 'id = ?' => $lpId,
  46. ],
  47. ],
  48. 'first'
  49. );
  50. $userList = [];
  51. $showEmail = api_get_setting('show_email_addresses');
  52. if (!empty($users)) {
  53. foreach ($users as $user) {
  54. $userInfo = api_get_user_info($user['user_id']);
  55. $lpTime = Tracking::get_time_spent_in_lp(
  56. $user['user_id'],
  57. $courseCode,
  58. [$lpId],
  59. $sessionId
  60. );
  61. $lpScore = Tracking::get_avg_student_score(
  62. $user['user_id'],
  63. $courseCode,
  64. [$lpId],
  65. $sessionId
  66. );
  67. $lpProgress = Tracking::get_avg_student_progress(
  68. $user['user_id'],
  69. $courseCode,
  70. [$lpId],
  71. $sessionId
  72. );
  73. $lpLastConnection = Tracking::get_last_connection_time_in_lp(
  74. $user['user_id'],
  75. $courseCode,
  76. $lpId,
  77. $sessionId
  78. );
  79. $lpLastConnection = empty($lpLastConnection) ? '-' : api_convert_and_format_date(
  80. $lpLastConnection,
  81. DATE_TIME_FORMAT_LONG
  82. );
  83. $userList[] = [
  84. 'id' => $user['user_id'],
  85. 'first_name' => $userInfo['firstname'],
  86. 'last_name' => $userInfo['lastname'],
  87. 'email' => $showEmail === 'true' ? $userInfo['email'] : '',
  88. 'lp_time' => api_time_to_hms($lpTime),
  89. 'lp_score' => is_numeric($lpScore) ? "$lpScore%" : $lpScore,
  90. 'lp_progress' => "$lpProgress%",
  91. 'lp_last_connection' => $lpLastConnection,
  92. ];
  93. }
  94. } else {
  95. Display::addFlash(Display::return_message(get_lang('NoUserAdded'), 'warning'));
  96. }
  97. // View
  98. $interbreadcrumb[] = [
  99. 'url' => api_get_path(WEB_CODE_PATH).'lp/lp_controller.php?'.api_get_cidreq(),
  100. 'name' => get_lang('LearningPaths'),
  101. ];
  102. $actions = Display::url(
  103. Display::return_icon(
  104. 'back.png',
  105. get_lang('Back'),
  106. [],
  107. ICON_SIZE_MEDIUM
  108. ),
  109. api_get_path(WEB_CODE_PATH).'lp/lp_controller.php?'.api_get_cidreq()
  110. );
  111. if (!empty($users)) {
  112. $actions .= Display::url(
  113. Display::return_icon(
  114. 'pdf.png',
  115. get_lang('ExportToPdf'),
  116. [],
  117. ICON_SIZE_MEDIUM
  118. ),
  119. api_get_path(WEB_CODE_PATH).'lp/lp_controller.php?'.api_get_cidreq().'&action=report&export=pdf&lp_id='.$lpId
  120. );
  121. }
  122. $template = new Template(get_lang('StudentScore'));
  123. $template->assign('user_list', $userList);
  124. $template->assign('session_id', api_get_session_id());
  125. $template->assign('course_code', api_get_course_id());
  126. $template->assign('lp_id', $lpId);
  127. $template->assign('show_email', $showEmail === 'true');
  128. $template->assign('export', (int) $export);
  129. $layout = $template->get_template('learnpath/report.tpl');
  130. $template->assign('header', $lpInfo['name']);
  131. $template->assign(
  132. 'actions',
  133. Display::toolbarAction('lp_actions', [$actions])
  134. );
  135. $result = $template->fetch($layout);
  136. $template->assign('content', $result);
  137. if ($export) {
  138. $pdfParams = [
  139. 'filename' => get_lang('StudentScore').'_'.api_get_local_time(),
  140. //'pdf_title' => $title,
  141. //'course_code' => $course_code
  142. ];
  143. $pdf = new PDF('A4', 'P', $pdfParams);
  144. $pdf->html_to_pdf_with_template(
  145. $result,
  146. false,
  147. false,
  148. true
  149. );
  150. exit;
  151. }
  152. $template->display_one_col_template();