course_session_report.php 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * Report.
  5. *
  6. * @package chamilo.tracking
  7. */
  8. $cidReset = true;
  9. require_once __DIR__.'/../inc/global.inc.php';
  10. $session_id = isset($_GET['session_id']) ? intval($_GET['session_id']) : null;
  11. $this_section = 'session_my_space';
  12. $is_allowedToTrack = Tracking::isAllowToTrack($session_id);
  13. if (!$is_allowedToTrack) {
  14. api_not_allowed(true);
  15. }
  16. $export_to_xls = false;
  17. if (isset($_GET['export'])) {
  18. $export_to_xls = true;
  19. }
  20. if (api_is_platform_admin()) {
  21. $global = true;
  22. } else {
  23. $global = false;
  24. }
  25. $global = true;
  26. if (empty($session_id)) {
  27. $session_id = 1;
  28. }
  29. $form = new FormValidator('search_simple', 'POST', '', '', null, false);
  30. //Get session list
  31. $session_list = SessionManager::get_sessions_list([], ['name']);
  32. $my_session_list = [];
  33. foreach ($session_list as $sesion_item) {
  34. $my_session_list[$sesion_item['id']] = $sesion_item['name'];
  35. }
  36. if (count($session_list) == 0) {
  37. $my_session_list[0] = get_lang('none');
  38. }
  39. $form->addElement('select', 'session_id', get_lang('Course sessions'), $my_session_list);
  40. $form->addButtonFilter(get_lang('Filter'));
  41. if (!empty($_REQUEST['score'])) {
  42. $filter_score = intval($_REQUEST['score']);
  43. } else {
  44. $filter_score = 70;
  45. }
  46. if (!empty($_REQUEST['session_id'])) {
  47. $session_id = intval($_REQUEST['session_id']);
  48. } else {
  49. $session_id = 0;
  50. }
  51. if (empty($session_id)) {
  52. $session_id = key($my_session_list);
  53. }
  54. $form->setDefaults(['session_id' => $session_id]);
  55. $course_list = SessionManager::get_course_list_by_session_id($session_id);
  56. if (!$export_to_xls) {
  57. Display :: display_header(get_lang("Reporting"));
  58. echo '<div class="actions">';
  59. if ($global) {
  60. echo MySpace::getTopMenu();
  61. } else {
  62. echo '<div style="float:left; clear:left">
  63. <a href="courseLog.php?'.api_get_cidreq().'&studentlist=true">'.get_lang('Report on learners').'</a>&nbsp;|
  64. <a href="courseLog.php?'.api_get_cidreq().'&studentlist=false">'.get_lang('Course report').'</a>&nbsp;';
  65. echo '</div>';
  66. }
  67. echo '</div>';
  68. if (api_is_platform_admin()) {
  69. echo MySpace::getAdminActions();
  70. }
  71. echo '<h2>'.get_lang('Results of learning paths exercises by session').'</h2>';
  72. $form->display();
  73. echo Display::return_message(get_lang('Learner score average is calculated bases on all learning paths and all attempts'));
  74. }
  75. $users = SessionManager::get_users_by_session($session_id);
  76. $course_average = $course_average_counter = [];
  77. $counter = 0;
  78. $main_result = [];
  79. // Getting course list
  80. foreach ($course_list as $current_course) {
  81. $course_info = api_get_course_info($current_course['code']);
  82. $_course = $course_info;
  83. $attempt_result = [];
  84. // Getting LP list
  85. $list = new LearnpathList('', $course_info, $session_id);
  86. $lp_list = $list->get_flat_list();
  87. // Looping LPs
  88. foreach ($lp_list as $lp_id => $lp) {
  89. $exercise_list = Event::get_all_exercises_from_lp($lp_id, $course_info['real_id']);
  90. // Looping Chamilo Exercises in LP
  91. foreach ($exercise_list as $exercise) {
  92. $exercise_stats = Event::get_all_exercise_event_from_lp(
  93. $exercise['path'],
  94. $course_info['real_id'],
  95. $session_id
  96. );
  97. // Looping Exercise Attempts
  98. foreach ($exercise_stats as $stats) {
  99. $attempt_result[$stats['exe_user_id']]['result'] += $stats['score'] / $stats['max_score'];
  100. $attempt_result[$stats['exe_user_id']]['attempts']++;
  101. }
  102. }
  103. }
  104. $main_result[$current_course['code']] = $attempt_result;
  105. }
  106. $total_average_score = 0;
  107. $total_average_score_count = 0;
  108. $html_result = '';
  109. if (!empty($users) && is_array($users)) {
  110. $html_result .= '<table class="data_table">';
  111. $html_result .= '<tr><th>'.get_lang('User').'</th>';
  112. foreach ($course_list as $item) {
  113. $html_result .= '<th>'.$item['title'].'<br /> '.get_lang('Average score').' %</th>';
  114. }
  115. $html_result .= '<th>'.get_lang('Average score').' %</th>';
  116. $html_result .= '<th>'.get_lang('Last connexion date').'</th></tr>';
  117. foreach ($users as $user) {
  118. $total_student = 0;
  119. $counter++;
  120. $s_css_class = 'row_even';
  121. if ($counter % 2 == 0) {
  122. $s_css_class = 'row_odd';
  123. }
  124. $html_result .= "<tr class='$s_css_class'>
  125. <td >";
  126. $html_result .= $user['firstname'].' '.$user['lastname'];
  127. $html_result .= "</td>";
  128. // Getting course list
  129. $counter = 0;
  130. $total_result_by_user = 0;
  131. foreach ($course_list as $current_course) {
  132. $total_course = 0;
  133. $html_result .= "<td>";
  134. $result = '-';
  135. if (isset($main_result[$current_course['code']][$user['user_id']])) {
  136. $user_info_stat = $main_result[$current_course['code']][$user['user_id']];
  137. if (!empty($user_info_stat['result']) && !empty($user_info_stat['attempts'])) {
  138. $result = round(
  139. $user_info_stat['result'] / $user_info_stat['attempts'] * 100,
  140. 2
  141. );
  142. $total_course += $result;
  143. $total_result_by_user += $result;
  144. $course_average[$current_course['code']] += $total_course;
  145. $course_average_counter[$current_course['code']]++;
  146. $result = $result.' ('.$user_info_stat['attempts'].' '.get_lang('Attempts').')';
  147. $counter++;
  148. }
  149. }
  150. $html_result .= $result;
  151. $html_result .= "</td>";
  152. }
  153. if (empty($counter)) {
  154. $total_student = '-';
  155. } else {
  156. $total_student = $total_result_by_user / $counter;
  157. $total_average_score += $total_student;
  158. $total_average_score_count++;
  159. }
  160. $string_date = Tracking::get_last_connection_date($user['user_id'], true);
  161. $html_result .= "<td>$total_student</td><td>$string_date</td></tr>";
  162. }
  163. $html_result .= "<tr><th>".get_lang('Average score')."</th>";
  164. $total_average = 0;
  165. $counter = 0;
  166. foreach ($course_list as $course_item) {
  167. if (!empty($course_average_counter[$course_item['code']])) {
  168. $average_per_course = round(
  169. $course_average[$course_item['code']] / ($course_average_counter[$course_item['code']] * 100) * 100,
  170. 2
  171. );
  172. } else {
  173. $average_per_course = 0;
  174. }
  175. if (!empty($average_per_course)) {
  176. $counter++;
  177. }
  178. $total_average = $total_average + $average_per_course;
  179. $html_result .= "<td>$average_per_course</td>";
  180. }
  181. if (!empty($total_average_score_count)) {
  182. $total_average = round($total_average_score / ($total_average_score_count * 100) * 100, 2);
  183. } else {
  184. $total_average = '-';
  185. }
  186. $html_result .= '<td>'.$total_average.'</td>';
  187. $html_result .= "<td>-</td>";
  188. $html_result .= "</tr>";
  189. $html_result .= '</table>';
  190. } else {
  191. echo Display::return_message(get_lang('No results found'), 'warning');
  192. }
  193. if (!$export_to_xls) {
  194. echo $html_result;
  195. }
  196. Display::display_footer();