course_session_report.php 6.5 KB

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