lp_results_by_user.php 8.4 KB

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