course_session_report.php 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * Report
  5. * @package chamilo.tracking
  6. */
  7. $language_file = array ('registration', 'index', 'tracking', 'exercice','survey');
  8. $cidReset = true;
  9. require_once '../inc/global.inc.php';
  10. require_once api_get_path(LIBRARY_PATH).'pear/Spreadsheet_Excel_Writer/Writer.php';
  11. require_once api_get_path(SYS_CODE_PATH).'exercice/exercise.class.php';
  12. require_once api_get_path(SYS_CODE_PATH).'exercice/question.class.php';
  13. require_once api_get_path(SYS_CODE_PATH).'newscorm/learnpathList.class.php';
  14. require_once api_get_path(SYS_CODE_PATH).'newscorm/learnpath.class.php';
  15. require_once api_get_path(SYS_CODE_PATH).'newscorm/learnpathList.class.php';
  16. $this_section = "session_my_space";
  17. $is_allowedToTrack = $is_courseAdmin || $is_platformAdmin || $is_courseCoach || $is_sessionAdmin;
  18. if (!$is_allowedToTrack) {
  19. api_not_allowed(true);
  20. }
  21. $export_to_xls = false;
  22. if (isset($_GET['export'])) {
  23. $export_to_xls = true;
  24. }
  25. if (api_is_platform_admin() ) {
  26. $global = true;
  27. } else {
  28. $global = false;
  29. }
  30. $global = true;
  31. $session_id = isset($_GET['session_id']) ? intval($_GET['session_id']) : null;
  32. if (empty($session_id)) {
  33. $session_id = 1;
  34. }
  35. $form = new FormValidator('search_simple','POST','','',null,false);
  36. //Get session list
  37. $session_list = SessionManager::get_sessions_list(array(), array('name'));
  38. $my_session_list = array();
  39. foreach($session_list as $sesion_item) {
  40. $my_session_list[$sesion_item['id']] = $sesion_item['name'];
  41. }
  42. if (count($session_list) == 0) {
  43. $my_session_list[0] = get_lang('None');
  44. }
  45. $form->addElement('select', 'session_id', get_lang('Sessions'), $my_session_list);
  46. $form->addElement('style_submit_button','submit',get_lang('Filter'));
  47. if (!empty($_REQUEST['score'])) $filter_score = intval($_REQUEST['score']); else $filter_score = 70;
  48. if (!empty($_REQUEST['session_id'])) $session_id = intval($_REQUEST['session_id']); else $session_id = 0;
  49. if (empty($session_id)) {
  50. $session_id = key($my_session_list);
  51. }
  52. $form->setDefaults(array('session_id'=>$session_id));
  53. $course_list = SessionManager::get_course_list_by_session_id($session_id);
  54. if (!$export_to_xls) {
  55. Display :: display_header(get_lang("MySpace"));
  56. echo '<div class="actions">';
  57. if ($global) {
  58. echo MySpace::getTopMenu();
  59. } else {
  60. echo '<div style="float:left; clear:left">
  61. <a href="courseLog.php?'.api_get_cidreq().'&studentlist=true">'.get_lang('StudentsTracking').'</a>&nbsp;|
  62. <a href="courseLog.php?'.api_get_cidreq().'&studentlist=false">'.get_lang('CourseTracking').'</a>&nbsp;';
  63. echo '</div>';
  64. }
  65. echo '</div>';
  66. if (api_is_platform_admin()) {
  67. echo MySpace::getAdminActions();
  68. }
  69. echo '<h2>'.get_lang('LPExerciseResultsBySession').'</h2>';
  70. $form->display();
  71. Display::display_normal_message(get_lang('StudentScoreAverageIsCalculatedBaseInAllLPsAndAllAttempts'));
  72. }
  73. $users = SessionManager::get_users_by_session($session_id);
  74. $course_average = $course_average_counter = array();
  75. $counter = 0;
  76. $main_result = array();
  77. //Getting course list
  78. foreach ($course_list as $current_course ) {
  79. $course_info = api_get_course_info($current_course['code']);
  80. $_course = $course_info;
  81. $attempt_result = array();
  82. //Getting LP list
  83. $list = new learnpathList('', $current_course['code'], $session_id);
  84. $lp_list = $list->get_flat_list();
  85. // Looping LPs
  86. foreach ($lp_list as $lp_id =>$lp) {
  87. $exercise_list = get_all_exercises_from_lp($lp_id, $course_info['real_id']);
  88. // Looping Chamilo Exercises in LP
  89. foreach ($exercise_list as $exercise) {
  90. $exercise_stats = get_all_exercise_event_from_lp($exercise['path'], $course_info['id'], $session_id);
  91. // Looping Exercise Attempts
  92. foreach ($exercise_stats as $stats) {
  93. $attempt_result[$stats['exe_user_id']]['result'] += $stats['exe_result'] / $stats['exe_weighting'];
  94. $attempt_result[$stats['exe_user_id']]['attempts']++;
  95. }
  96. }
  97. }
  98. $main_result[$current_course['code']] = $attempt_result;
  99. }
  100. //var_dump($main_result);
  101. $total_average_score = 0;
  102. $total_average_score_count = 0;
  103. if (!empty($users) && is_array($users)) {
  104. $html_result .= '<table class="data_table">';
  105. $html_result .= '<tr><th>'.get_lang('User').'</th>';
  106. foreach($course_list as $item ) {
  107. $html_result .= '<th>'.$item['title'].'<br /> '.get_lang('AverageScore').' %</th>';
  108. }
  109. $html_result .= '<th>'.get_lang('AverageScore').' %</th>';
  110. $html_result .= '<th>'.get_lang('LastConnexionDate').'</th></tr>';
  111. foreach ($users as $user) {
  112. $total_student = 0;
  113. $counter ++;
  114. $s_css_class = 'row_even';
  115. if ($counter % 2 ==0 ) {
  116. $s_css_class = 'row_odd';
  117. }
  118. $html_result .= "<tr class='$s_css_class'>
  119. <td >";
  120. $html_result .= $user['firstname'].' '.$user['lastname'];
  121. $html_result .= "</td>";
  122. // Getting course list
  123. $counter = 0;
  124. $total_result_by_user = 0;
  125. foreach ($course_list as $current_course ) {
  126. $total_course = 0;
  127. $html_result .= "<td>";
  128. $result = '-';
  129. if (isset($main_result[$current_course['code']][$user['user_id']])) {
  130. $user_info_stat = $main_result[$current_course['code']][$user['user_id']];
  131. if (!empty($user_info_stat['result']) && !empty($user_info_stat['attempts'])) {
  132. $result = round(
  133. $user_info_stat['result'] / $user_info_stat['attempts'] * 100,
  134. 2
  135. );
  136. $total_course += $result;
  137. $total_result_by_user += $result;
  138. $course_average[$current_course['code']] += $total_course;
  139. $course_average_counter[$current_course['code']]++;
  140. $result = $result . ' (' . $user_info_stat['attempts'] . ' ' . get_lang(
  141. 'Attempts'
  142. ) . ')';
  143. $counter++;
  144. }
  145. }
  146. $html_result .= $result;
  147. $html_result .= "</td>";
  148. }
  149. if (empty($counter)) {
  150. $total_student = '-';
  151. } else {
  152. $total_student = $total_result_by_user/$counter;
  153. $total_average_score+=$total_student;
  154. $total_average_score_count++;
  155. }
  156. $string_date=Tracking :: get_last_connection_date($user['user_id'],true);
  157. $html_result .="<td>$total_student</td><td>$string_date</td></tr>";
  158. }
  159. $html_result .="<tr><th>".get_lang('AverageScore')."</th>";
  160. $total_average = 0;
  161. $counter = 0;
  162. foreach($course_list as $course_item) {
  163. if (!empty($course_average_counter[$course_item['code']])) {
  164. $average_per_course = round($course_average[$course_item['code']]/($course_average_counter[$course_item['code']]*100)*100,2);
  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. $filename = 'exam-reporting-'.date('Y-m-d-h:i:s').'.xls';
  190. if ($export_to_xls) {
  191. echo $html_result;
  192. export_complete_report_xls($filename, $export_array);
  193. exit;
  194. }
  195. function sort_user($a, $b) {
  196. if (is_numeric($a['score']) && is_numeric($b['score'])) {
  197. echo $a['score'].' : '.$b['score'];
  198. echo '<br />';
  199. if ($a['score'] < $b['score']) {
  200. return 1;
  201. }
  202. return 0;
  203. }
  204. return 1;
  205. }
  206. function export_complete_report_xls($filename, $array) {
  207. global $charset;
  208. $workbook = new Spreadsheet_Excel_Writer();
  209. $workbook ->setTempDir(api_get_path(SYS_ARCHIVE_PATH));
  210. $workbook->send($filename);
  211. $workbook->setVersion(8); // BIFF8
  212. $worksheet =& $workbook->addWorksheet('Report');
  213. //$worksheet->setInputEncoding(api_get_system_encoding());
  214. $worksheet->setInputEncoding($charset);
  215. /*
  216. $line = 0;
  217. $column = 1; // Skip the first column (row titles)
  218. foreach ($array as $elem) {
  219. $worksheet->write($line, $column, $elem);
  220. $column++;
  221. }
  222. $workbook->close();*/
  223. exit;
  224. }
  225. Display :: display_footer();