course_session_report.php 8.9 KB

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