lp_results_by_user.php 9.1 KB

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