lp_results_by_user.php 8.9 KB

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