course_session_report.php 6.4 KB

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