lp_results_by_user.php 8.4 KB

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