lp_results_by_user.php 9.1 KB

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