lp_results_by_user.php 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270
  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. /**
  11. * Code
  12. */
  13. $language_file = array ('registration', 'index', 'tracking', 'exercice','survey');
  14. require_once '../inc/global.inc.php';
  15. require_once api_get_path(LIBRARY_PATH).'formvalidator/FormValidator.class.php';
  16. require_once api_get_path(LIBRARY_PATH).'pear/Spreadsheet_Excel_Writer/Writer.php';
  17. $this_section = SECTION_TRACKING;
  18. $is_allowedToTrack = $is_courseAdmin || $is_platformAdmin || $is_courseCoach || $is_sessionAdmin;
  19. if (!$is_allowedToTrack) {
  20. Display :: display_header(null);
  21. api_not_allowed();
  22. Display :: display_footer();
  23. }
  24. $export_to_csv = false;
  25. if (isset($_GET['export'])) {
  26. $export_to_csv = true;
  27. }
  28. if (api_is_platform_admin() ) {
  29. $global = true;
  30. } else {
  31. $global = false;
  32. }
  33. if ($global) {
  34. $temp_course_list = CourseManager :: get_courses_list();
  35. foreach($temp_course_list as $temp_course_item) {
  36. $course_item = CourseManager ::get_course_information($temp_course_item['code']);
  37. $course_list[]= array('db_name' =>$course_item['db_name'],'code'=>$course_item['code'], 'title'=>$course_item['title']);
  38. }
  39. } else {
  40. $current_course['db_name'] = $_course['dbName'];
  41. $current_course['code'] = $_course['id'];
  42. $course_list = array($current_course);
  43. }
  44. $new_course_select = array();
  45. foreach($course_list as $data) {
  46. $new_course_select[$data['code']] = $data['title'];
  47. }
  48. $form = new FormValidator('search_simple','POST','','',null,false);
  49. $form->addElement('select','course_code',get_lang('Course'), $new_course_select);
  50. if ($global) {
  51. $form->addElement('hidden','view','admin');
  52. } else {
  53. //Get exam lists
  54. $t_quiz = Database::get_course_table(TABLE_QUIZ_TEST,$_course['db_name']);
  55. $sqlExercices = " SELECT quiz.title,id FROM ".$t_quiz." AS quiz WHERE active='1' ORDER BY quiz.title ASC";
  56. $resultExercices = Database::query($sqlExercices);
  57. $exercise_list[0] = get_lang('All');
  58. while($a_exercices = Database::fetch_array($resultExercices)) {
  59. $exercise_list[$a_exercices['id']] = $a_exercices['title'];
  60. }
  61. $form->addElement('select', 'exercise_id', get_lang('Exercise'), $exercise_list);
  62. }
  63. //$form->addElement('submit','submit',get_lang('Filter'));
  64. $form->addElement('style_submit_button','submit', get_lang('Filter'),'class="search"' );
  65. if (!empty($_REQUEST['course_code']))
  66. $selected_course = $_REQUEST['course_code'];
  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.'"><img align="absbottom" src="../img/csv.gif">&nbsp;'.get_lang('ExportAsCSV').'</a>' .
  76. '<a href="javascript: void(0);" onclick="javascript: window.print()"><img align="absbottom" src="../img/printmgr.gif">&nbsp;'.get_lang('Print').'</a></div>';
  77. $menu_items[] = '<a href="'.api_get_path(WEB_CODE_PATH).'mySpace/?view=teacher">'.get_lang('TeacherInterface').'</a>';
  78. if (api_is_platform_admin()) {
  79. $menu_items[] = '<a href="'.api_get_path(WEB_CODE_PATH).'mySpace/?view=admin">'.get_lang('AdminInterface').'</a>';
  80. } else {
  81. $menu_items[] = '<a href="'.api_get_path(WEB_CODE_PATH).'mySpace/?view=coach">'.get_lang('AdminInterface').'</a>';
  82. }
  83. $menu_items[] = get_lang('ExamTracking');
  84. $nb_menu_items = count($menu_items);
  85. if($nb_menu_items>1) {
  86. foreach($menu_items as $key=> $item) {
  87. echo $item;
  88. if($key!=$nb_menu_items-1) {
  89. echo ' | ';
  90. }
  91. }
  92. echo '<br />';
  93. }
  94. } else {
  95. echo '<a href="courseLog.php?'.api_get_cidreq().'&studentlist=true">'.get_lang('StudentsTracking').'</a>&nbsp;|
  96. <a href="courseLog.php?'.api_get_cidreq().'&studentlist=false">'.get_lang('CourseTracking').'</a>&nbsp;|&nbsp';
  97. echo '<a href="courseLog.php?'.api_get_cidreq().'&studentlist=resources">'.get_lang('ResourcesTracking').'</a>';
  98. echo ' | '.get_lang('ExamTracking').'';
  99. echo '<a href="'.api_get_self().'?export=1&score='.$filter_score.'&exercise_id='.$exercise_id.'"><img align="absbottom" src="../img/excel.gif">&nbsp;'.get_lang('ExportAsXLS').'</a><br /><br />';
  100. }
  101. echo '</div>';
  102. echo '<br /><br />';
  103. $form->display();
  104. //echo '<h3>'.sprintf(get_lang('FilteringWithScoreX'), $filter_score).'%</h3>';
  105. }
  106. require_once api_get_path(SYS_CODE_PATH).'newscorm/learnpathList.class.php';
  107. $main_result = array();
  108. $session_id = 0;
  109. $user_list = array();
  110. //Getting course list
  111. foreach($course_list as $current_course ) {
  112. $course_info = api_get_course_info($current_course['code']);
  113. $_course = $course_info;
  114. //Getting LP list
  115. $list = new learnpathList('', $current_course['code'], $session_id);
  116. $lp_list = $list->get_flat_list();
  117. // Looping LPs
  118. $lps = array();
  119. foreach ($lp_list as $lp_id =>$lp) {
  120. $exercise_list = get_all_exercises_from_lp($lp_id, $course_info['real_id']);
  121. $attempt_result = array();
  122. //Looping Chamilo Exercises in LP
  123. foreach ($exercise_list as $exercise) {
  124. $exercise_stats = get_all_exercise_event_from_lp($exercise['path'], $course_info['id'], $session_id);
  125. //Looping Exercise Attempts
  126. foreach($exercise_stats as $stats) {
  127. //$attempt_result[$exercise['id']]['users'][$stats['exe_user_id']][$stats['exe_id']] = array('exe_result' =>$stats['exe_result'],'exe_weighting' =>$stats['exe_weighting']);
  128. $attempt_result[$exercise['id']]['users'][$stats['exe_user_id']][$stats['exe_id']] = $stats;
  129. $user_list[$stats['exe_user_id']] = $stats['exe_user_id'];
  130. }
  131. $exercise_list_name[$exercise['id']] = $exercise['title'];
  132. }
  133. $lps[$lp_id] = array('lp_name' =>$lp['lp_name'], 'exercises' =>$attempt_result);
  134. $lp_list_name[$lp_id] = $lp['lp_name'];
  135. }
  136. $main_result[$current_course['code']] = $lps;
  137. }
  138. //echo '<pre>';print_r($main_result);
  139. if (!empty($user_list)) {
  140. foreach($user_list as $user_id) {
  141. $user_data = api_get_user_info($user_id);
  142. $user_list_name[$user_id] = api_get_person_name($user_data['firstname'],$user_data['lastname']);
  143. }
  144. }
  145. $export_array = array();
  146. if (!empty($main_result)) {
  147. $html_result .= '<table class="data_table">';
  148. $html_result .= '<tr><th>'.get_lang('Course').'</th>';
  149. $html_result .= '<th>'.get_lang('LearningPath').'</th>';
  150. $html_result .= '<th>'.get_lang('Exercise').'</th>';
  151. $html_result .= '<th>'.get_lang('User').'</th>';
  152. $html_result .= '<th>'.get_lang('Attempt').'</th>';
  153. $html_result .= '<th>'.get_lang('Date').'</th>';
  154. $html_result .= '<th>'.get_lang('Results').'</th>';
  155. $html_result .= '</tr>';
  156. foreach ($main_result as $course_code => $lps) {
  157. if (empty($lps)) {
  158. continue;
  159. }
  160. foreach($lps as $lp_id => $lp_data) {
  161. $exercises = $lp_data['exercises'];
  162. foreach($exercises as $exercise_id => $exercise_data) {
  163. $users = $exercise_data['users'];
  164. foreach($users as $user_id => $attempts) {
  165. $attempt = 1;
  166. foreach($attempts as $exe_id => $attempt_data) {
  167. $html_result .= '<tr colspan="">';
  168. $html_result .= Display::tag('td', $course_code);
  169. $html_result .= Display::tag('td', $lp_list_name[$lp_id]);
  170. $html_result .= Display::tag('td', $exercise_list_name[$exercise_id]);
  171. $html_result .= Display::tag('td', $user_list_name[$user_id]);
  172. $result = $attempt_data['exe_result'].' / '.$attempt_data['exe_weighting'];
  173. $html_result .= Display::tag('td', $attempt);
  174. $html_result .= Display::tag('td', api_get_local_time($attempt_data['exe_date']));
  175. $html_result .= Display::tag('td', $result);
  176. $html_result .= '</tr>';
  177. $export_array[]= array($course_code, $lp_list_name[$lp_id], $exercise_list_name[$exercise_id], $user_list_name[$user_id], $attempt, api_get_local_time($attempt_data['exe_date']), $result);
  178. $attempt++;
  179. }
  180. }
  181. }
  182. }
  183. }
  184. $html_result .='</table>';
  185. }
  186. if (!$export_to_csv) {
  187. echo $html_result;
  188. }
  189. $filename = 'learning_path_results-'.date('Y-m-d-h:i:s').'.xls';
  190. if ($export_to_csv) {
  191. export_complete_report_csv($filename, $export_array);
  192. exit;
  193. }
  194. function export_complete_report_csv($filename, $array) {
  195. require_once api_get_path(LIBRARY_PATH).'export.lib.inc.php';
  196. $header[] = array(get_lang('Course'),get_lang('LearningPath'), get_lang('Exercise'), get_lang('User'),get_lang('Attempt'), get_lang('Date'),get_lang('Results'));
  197. if (!empty($array)) {
  198. $array = array_merge($header, $array);
  199. Export :: export_table_csv($array, $filename);
  200. }
  201. exit;
  202. /*
  203. * Too much encoding problems while exporting to XLS, keep it simple
  204. *
  205. *
  206. global $global, $filter_score;
  207. $workbook = new Spreadsheet_Excel_Writer();
  208. $workbook ->setTempDir(api_get_path(SYS_ARCHIVE_PATH));
  209. $workbook->send($filename);
  210. $workbook->setVersion(8); // BIFF8
  211. $worksheet =& $workbook->addWorksheet('Report');
  212. $worksheet->setInputEncoding(api_get_system_encoding());
  213. $line = 0;
  214. $column = 0; //skip the first column (row titles)
  215. $worksheet->write($line,$column,get_lang('Course'));
  216. $column++;
  217. $worksheet->write($line,$column,get_lang('LearningPath'));
  218. $column++;
  219. $worksheet->write($line,$column,get_lang('Exercise'));
  220. $column++;
  221. $worksheet->write($line,$column,get_lang('User'));
  222. $column++;
  223. $worksheet->write($line,$column,get_lang('Attempt'));
  224. $column++;
  225. $worksheet->write($line,$column,get_lang('Date'));
  226. $column++;
  227. $worksheet->write($line,$column,get_lang('Results'));
  228. $column++;
  229. $line++;
  230. foreach ($array as $row) {
  231. $column = 0;
  232. foreach ($row as $item) {
  233. $worksheet->write($line,$column,html_entity_decode(strip_tags($item)));
  234. $column++;
  235. }
  236. $line++;
  237. }
  238. $line++;
  239. $workbook->close();
  240. exit;*/
  241. }
  242. Display :: display_footer();