lp_results_by_user.php 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. *
  5. * Exercise results from Learning paths
  6. *
  7. * @todo implement pagination
  8. * @package chamilo.tracking
  9. */
  10. require_once '../inc/global.inc.php';
  11. $this_section = SECTION_TRACKING;
  12. $is_allowedToTrack = $is_courseAdmin || $is_platformAdmin || $is_courseCoach || $is_sessionAdmin;
  13. if (!$is_allowedToTrack) {
  14. Display :: display_header(null);
  15. api_not_allowed();
  16. Display :: display_footer();
  17. }
  18. $export_to_csv = false;
  19. if (isset($_GET['export'])) {
  20. $export_to_csv = true;
  21. }
  22. if (api_is_platform_admin() ) {
  23. $global = true;
  24. } else {
  25. $global = false;
  26. }
  27. if ($global) {
  28. $temp_course_list = CourseManager :: get_courses_list();
  29. foreach($temp_course_list as $temp_course_item) {
  30. $course_item = CourseManager ::get_course_information($temp_course_item['code']);
  31. $course_list[]= array('db_name' =>$course_item['db_name'],'code'=>$course_item['code'], 'title'=>$course_item['title']);
  32. }
  33. } else {
  34. $current_course['db_name'] = $_course['dbName'];
  35. $current_course['code'] = $_course['id'];
  36. $course_list = array($current_course);
  37. }
  38. $new_course_select = array();
  39. foreach($course_list as $data) {
  40. $new_course_select[$data['code']] = $data['title'];
  41. }
  42. $form = new FormValidator('search_simple','POST','','',null,false);
  43. $form->addElement('select','course_code',get_lang('Course'), $new_course_select);
  44. if ($global) {
  45. $form->addElement('hidden','view','admin');
  46. } else {
  47. //Get exam lists
  48. $course_id = api_get_course_int_id();
  49. $t_quiz = Database::get_course_table(TABLE_QUIZ_TEST);
  50. $sqlExercices = " SELECT quiz.title,id FROM ".$t_quiz." AS quiz WHERE c_id = $course_id AND active='1' ORDER BY quiz.title ASC";
  51. $resultExercices = Database::query($sqlExercices);
  52. $exercise_list[0] = get_lang('All');
  53. while($a_exercices = Database::fetch_array($resultExercices)) {
  54. $exercise_list[$a_exercices['id']] = $a_exercices['title'];
  55. }
  56. $form->addElement('select', 'exercise_id', get_lang('Exercise'), $exercise_list);
  57. }
  58. //$form->addElement('submit','submit',get_lang('Filter'));
  59. $form->addButtonFilter(get_lang('Filter'));
  60. if (!empty($_REQUEST['course_code']))
  61. $selected_course = $_REQUEST['course_code'];
  62. if (!empty($selected_course)) {
  63. $selected_course = api_get_course_info($selected_course);
  64. $course_list = array($selected_course);
  65. }
  66. if (!$export_to_csv) {
  67. Display :: display_header(get_lang('Reporting'));
  68. echo '<div class="actions" style ="font-size:10pt;">';
  69. if ($global) {
  70. echo '<div style="float:right"> <a href="'.api_get_self().'?export=1&score='.$filter_score.'&exercise_id='.$exercise_id.'"><img align="absbottom" src="../img/csv.gif">&nbsp;'.get_lang('ExportAsCSV').'</a>' .
  71. '<a href="javascript: void(0);" onclick="javascript: window.print()"><img align="absbottom" src="../img/printmgr.gif">&nbsp;'.get_lang('Print').'</a></div>';
  72. $menu_items[] = '<a href="'.api_get_path(WEB_CODE_PATH).'mySpace/?view=teacher">'.get_lang('TeacherInterface').'</a>';
  73. if (api_is_platform_admin()) {
  74. $menu_items[] = '<a href="'.api_get_path(WEB_CODE_PATH).'mySpace/?view=admin">'.get_lang('AdminInterface').'</a>';
  75. } else {
  76. $menu_items[] = '<a href="'.api_get_path(WEB_CODE_PATH).'mySpace/?view=coach">'.get_lang('AdminInterface').'</a>';
  77. }
  78. $menu_items[] = get_lang('ExamTracking');
  79. $nb_menu_items = count($menu_items);
  80. if($nb_menu_items>1) {
  81. foreach($menu_items as $key=> $item) {
  82. echo $item;
  83. if($key!=$nb_menu_items-1) {
  84. echo ' | ';
  85. }
  86. }
  87. echo '<br />';
  88. }
  89. } else {
  90. echo '<a href="courseLog.php?'.api_get_cidreq().'&studentlist=true">'.get_lang('StudentsTracking').'</a>&nbsp;|
  91. <a href="courseLog.php?'.api_get_cidreq().'&studentlist=false">'.get_lang('CourseTracking').'</a>&nbsp;|&nbsp';
  92. echo '<a href="courseLog.php?'.api_get_cidreq().'&studentlist=resources">'.get_lang('ResourcesTracking').'</a>';
  93. echo ' | '.get_lang('ExamTracking').'';
  94. echo '<a href="'.api_get_self().'?export=1&score='.$filter_score.'&exercise_id='.$exercise_id.'"><img align="absbottom" src="../img/excel.gif">&nbsp;'.get_lang('ExportAsXLS').'</a><br /><br />';
  95. }
  96. echo '</div>';
  97. echo '<br /><br />';
  98. $form->display();
  99. }
  100. $main_result = array();
  101. $session_id = 0;
  102. $user_list = array();
  103. //Getting course list
  104. foreach($course_list as $current_course ) {
  105. $course_info = api_get_course_info($current_course['code']);
  106. $_course = $course_info;
  107. //Getting LP list
  108. $list = new LearnpathList('', $current_course['code'], $session_id);
  109. $lp_list = $list->get_flat_list();
  110. // Looping LPs
  111. $lps = array();
  112. foreach ($lp_list as $lp_id =>$lp) {
  113. $exercise_list = Event::get_all_exercises_from_lp($lp_id, $course_info['real_id']);
  114. $attempt_result = array();
  115. //Looping Chamilo Exercises in LP
  116. foreach ($exercise_list as $exercise) {
  117. $exercise_stats = Event::get_all_exercise_event_from_lp(
  118. $exercise['path'],
  119. $course_info['real_id'],
  120. $session_id
  121. );
  122. // Looping Exercise Attempts
  123. foreach ($exercise_stats as $stats) {
  124. $attempt_result[$exercise['id']]['users'][$stats['exe_user_id']][$stats['exe_id']] = $stats;
  125. $user_list[$stats['exe_user_id']] = $stats['exe_user_id'];
  126. }
  127. $exercise_list_name[$exercise['id']] = $exercise['title'];
  128. }
  129. $lps[$lp_id] = array('lp_name' =>$lp['lp_name'], 'exercises' =>$attempt_result);
  130. $lp_list_name[$lp_id] = $lp['lp_name'];
  131. }
  132. $main_result[$current_course['code']] = $lps;
  133. }
  134. if (!empty($user_list)) {
  135. foreach($user_list as $user_id) {
  136. $user_data = api_get_user_info($user_id);
  137. $user_list_name[$user_id] = api_get_person_name(
  138. $user_data['firstname'],
  139. $user_data['lastname']
  140. );
  141. }
  142. }
  143. $export_array = array();
  144. if (!empty($main_result)) {
  145. $html_result .= '<table class="data_table">';
  146. $html_result .= '<tr><th>'.get_lang('Course').'</th>';
  147. $html_result .= '<th>'.get_lang('LearningPath').'</th>';
  148. $html_result .= '<th>'.get_lang('Exercise').'</th>';
  149. $html_result .= '<th>'.get_lang('User').'</th>';
  150. $html_result .= '<th>'.get_lang('Attempt').'</th>';
  151. $html_result .= '<th>'.get_lang('Date').'</th>';
  152. $html_result .= '<th>'.get_lang('Results').'</th>';
  153. $html_result .= '</tr>';
  154. foreach ($main_result as $course_code => $lps) {
  155. if (empty($lps)) {
  156. continue;
  157. }
  158. foreach ($lps as $lp_id => $lp_data) {
  159. $exercises = $lp_data['exercises'];
  160. foreach ($exercises as $exercise_id => $exercise_data) {
  161. $users = $exercise_data['users'];
  162. foreach($users as $user_id => $attempts) {
  163. $attempt = 1;
  164. foreach($attempts as $exe_id => $attempt_data) {
  165. $html_result .= '<tr colspan="">';
  166. $html_result .= Display::tag('td', $course_code);
  167. $html_result .= Display::tag('td', $lp_list_name[$lp_id]);
  168. $html_result .= Display::tag('td', $exercise_list_name[$exercise_id]);
  169. $html_result .= Display::tag('td', $user_list_name[$user_id]);
  170. $result = $attempt_data['exe_result'].' / '.$attempt_data['exe_weighting'];
  171. $html_result .= Display::tag('td', $attempt);
  172. $html_result .= Display::tag('td', api_get_local_time($attempt_data['exe_date']));
  173. $html_result .= Display::tag('td', $result);
  174. $html_result .= '</tr>';
  175. $export_array[] = array(
  176. $course_code,
  177. $lp_list_name[$lp_id],
  178. $exercise_list_name[$exercise_id],
  179. $user_list_name[$user_id],
  180. $attempt,
  181. api_get_local_time($attempt_data['exe_date']),
  182. $result,
  183. );
  184. $attempt++;
  185. }
  186. }
  187. }
  188. }
  189. }
  190. $html_result .='</table>';
  191. }
  192. if (!$export_to_csv) {
  193. echo $html_result;
  194. }
  195. $filename = 'learning_path_results-'.date('Y-m-d-h:i:s').'.xls';
  196. if ($export_to_csv) {
  197. export_complete_report_csv($filename, $export_array);
  198. exit;
  199. }
  200. function export_complete_report_csv($filename, $array)
  201. {
  202. $header[] = array(
  203. get_lang('Course'),
  204. get_lang('LearningPath'),
  205. get_lang('Exercise'),
  206. get_lang('User'),
  207. get_lang('Attempt'),
  208. get_lang('Date'),
  209. get_lang('Results'),
  210. );
  211. if (!empty($array)) {
  212. $array = array_merge($header, $array);
  213. Export :: arrayToCsv($array, $filename);
  214. }
  215. exit;
  216. }
  217. Display :: display_footer();