lp_report.php 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. use Chamilo\CoreBundle\Framework\Container;
  4. /*
  5. * Report from students for learning path
  6. */
  7. //require_once '../inc/global.inc.php';
  8. $isAllowedToEdit = api_is_allowed_to_edit(null, true);
  9. if (!$isAllowedToEdit) {
  10. api_not_allowed(true);
  11. }
  12. $lpTable = Database::get_course_table(TABLE_LP_MAIN);
  13. $lpId = isset($_GET['lp_id']) ? intval($_GET['lp_id']) : 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. array(
  43. 'where' => array(
  44. 'c_id = ? AND ' => $courseId,
  45. 'id = ?' => $lpId
  46. )
  47. ),
  48. 'first'
  49. );
  50. $userList = [];
  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. 'lp_time' => api_time_to_hms($lpTime),
  87. 'lp_score' => is_numeric($lpScore) ? "$lpScore%" : $lpScore,
  88. 'lp_progress' => "$lpProgress%",
  89. 'lp_last_connection' => $lpLastConnection
  90. ];
  91. }
  92. }
  93. // View
  94. $interbreadcrumb[] = [
  95. 'url' => api_get_path(WEB_CODE_PATH) . 'newscorm/lp_controller.php',
  96. 'name' => get_lang('LearningPaths')
  97. ];
  98. $actions = Display::url(
  99. Display::return_icon(
  100. 'back.png',
  101. get_lang('Back'),
  102. array(),
  103. ICON_SIZE_MEDIUM
  104. ),
  105. api_get_path(WEB_CODE_PATH) . 'newscorm/lp_controller.php?' . api_get_cidreq()
  106. );
  107. $template = \Chamilo\CoreBundle\Framework\Container::getTwig();
  108. $template->addGlobal('user_list', $userList);
  109. $template->addGlobal('session_id', api_get_session_id());
  110. $template->addGlobal('course_code', api_get_course_id());
  111. $template->addGlobal('lp_id', $lpId);
  112. $template->addGlobal('header', $lpInfo['name']);
  113. $template->addGlobal('actions', $actions);
  114. echo $template->render('@template_style/learnpath/report.html.twig');