stats.php 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291
  1. <?php
  2. /* See license terms in /license.txt */
  3. require_once '../inc/global.inc.php';
  4. $this_section = SECTION_COURSES;
  5. $exercise_id = isset($_GET['exerciseId']) && !empty($_GET['exerciseId']) ? intval($_GET['exerciseId']) : 0;
  6. $gradebook = isset($gradebook) ? $gradebook : null;
  7. $objExercise = new Exercise();
  8. $result = $objExercise->read($exercise_id);
  9. if (!$result) {
  10. api_not_allowed(true);
  11. }
  12. $sessionId = api_get_session_id();
  13. $courseCode = api_get_course_id();
  14. if (empty($sessionId)) {
  15. $students = CourseManager :: get_student_list_from_course_code($courseCode, false);
  16. } else {
  17. $students = CourseManager :: get_student_list_from_course_code($courseCode, true, $sessionId);
  18. }
  19. $count_students = count($students);
  20. $question_list = $objExercise->get_validated_question_list();
  21. $data = array();
  22. // Question title # of students who tool it Lowest score Average Highest score Maximum score
  23. $headers = array(
  24. get_lang('Question'),
  25. get_lang('QuestionType'),
  26. get_lang('NumberStudentWhoSelectedIt'),
  27. get_lang('LowestScore'),
  28. get_lang('AverageScore'),
  29. get_lang('HighestScore'),
  30. get_lang('Weighting')
  31. );
  32. if (!empty($question_list)) {
  33. foreach ($question_list as $question_id) {
  34. $question_obj = Question::read($question_id);
  35. $exercise_stats = ExerciseLib::get_student_stats_by_question(
  36. $question_id,
  37. $exercise_id,
  38. $courseCode,
  39. $sessionId
  40. );
  41. $count_users = ExerciseLib::get_number_students_question_with_answer_count(
  42. $question_id,
  43. $exercise_id,
  44. $courseCode,
  45. $sessionId
  46. );
  47. $data[$question_id]['name'] = cut($question_obj->question, 100);
  48. $data[$question_id]['type'] = $question_obj->get_question_type_name();
  49. $percentange = 0;
  50. if ($count_students) {
  51. $percentange = $count_users / $count_students*100;
  52. }
  53. $data[$question_id]['students_who_try_exercise'] = Display::bar_progress(
  54. $percentange,
  55. false,
  56. $count_users .' / '.$count_students
  57. );
  58. $data[$question_id]['lowest_score'] = round($exercise_stats['min'], 2);
  59. $data[$question_id]['average_score'] = round($exercise_stats['average'], 2);
  60. $data[$question_id]['highest_score'] = round($exercise_stats['max'], 2);
  61. $data[$question_id]['max_score'] = round($question_obj->weighting, 2);
  62. }
  63. }
  64. // Format A table
  65. $table = new HTML_Table(array('class' => 'data_table'));
  66. $row = 0;
  67. $column = 0;
  68. foreach ($headers as $header) {
  69. $table->setHeaderContents($row, $column, $header);
  70. $column++;
  71. }
  72. $row++;
  73. foreach ($data as $row_table) {
  74. $column = 0;
  75. foreach ($row_table as $cell) {
  76. $table->setCellContents($row, $column, $cell);
  77. $table->updateCellAttributes($row, $column, 'align="center"');
  78. $column++;
  79. }
  80. $table->updateRowAttributes($row, $row % 2 ? 'class="row_even"' : 'class="row_odd"', true);
  81. $row++;
  82. }
  83. $content = $table->toHtml();
  84. // Format B
  85. $headers = array(
  86. get_lang('Question'),
  87. get_lang('Answer'),
  88. get_lang('Correct'),
  89. get_lang('NumberStudentWhoSelectedIt')
  90. );
  91. $data = array();
  92. if (!empty($question_list)) {
  93. $id = 0;
  94. foreach ($question_list as $question_id) {
  95. $question_obj = Question::read($question_id);
  96. $exercise_stats = ExerciseLib::get_student_stats_by_question(
  97. $question_id,
  98. $exercise_id,
  99. $courseCode,
  100. $sessionId
  101. );
  102. $answer = new Answer($question_id);
  103. $answer_count = $answer->selectNbrAnswers();
  104. for ($answer_id = 1; $answer_id <= $answer_count; $answer_id++) {
  105. $answer_info = $answer->selectAnswer($answer_id);
  106. $is_correct = $answer->isCorrect($answer_id);
  107. $correct_answer = $is_correct == 1 ? get_lang('Yes') : get_lang('No');
  108. $real_answer_id = $answer->selectAutoId($answer_id);
  109. // Overwriting values depending of the question
  110. switch ($question_obj->type) {
  111. case FILL_IN_BLANKS :
  112. $answer_info_db = $answer_info;
  113. $answer_info = substr($answer_info, 0, strpos($answer_info, '::'));
  114. $correct_answer = $is_correct;
  115. $answers = $objExercise->fill_in_blank_answer_to_array($answer_info);
  116. $counter = 0;
  117. foreach ($answers as $answer_item) {
  118. if ($counter == 0) {
  119. $data[$id]['name'] = cut($question_obj->question, 100);
  120. } else {
  121. $data[$id]['name'] = '-';
  122. }
  123. $data[$id]['answer'] = $answer_item;
  124. $answer_item = api_substr($answer_item, 1);
  125. $answer_item = api_substr($answer_item, 0, api_strlen($answer_item) -1);
  126. $data[$id]['correct'] = '-';
  127. $count = ExerciseLib::get_number_students_answer_count(
  128. $real_answer_id,
  129. $question_id,
  130. $exercise_id,
  131. $courseCode,
  132. $sessionId,
  133. FILL_IN_BLANKS,
  134. $answer_info_db,
  135. $answer_item
  136. );
  137. $percentange = 0;
  138. if (!empty($count_students)) {
  139. $percentange = $count/$count_students*100;
  140. }
  141. $data[$id]['attempts'] = Display::bar_progress($percentange, false, $count .' / '.$count_students);
  142. $id++;
  143. $counter++;
  144. }
  145. break;
  146. case MATCHING:
  147. if ($is_correct == 0) {
  148. if ($answer_id == 1) {
  149. $data[$id]['name'] = cut($question_obj->question, 100);
  150. } else {
  151. $data[$id]['name'] = '-';
  152. }
  153. $correct = '';
  154. for ($i = 1; $i <= $answer_count; $i++) {
  155. $is_correct_i = $answer->isCorrect($i);
  156. if ($is_correct_i != 0 && $is_correct_i == $answer_id) {
  157. $correct = $answer->selectAnswer($i);
  158. break;
  159. }
  160. }
  161. $data[$id]['answer'] = $correct;
  162. $data[$id]['correct'] = $answer_info;
  163. $count = ExerciseLib::get_number_students_answer_count(
  164. $answer_id,
  165. $question_id,
  166. $exercise_id,
  167. $courseCode,
  168. $sessionId,
  169. MATCHING
  170. );
  171. $percentange = 0;
  172. if (!empty($count_students)) {
  173. $percentange = $count/$count_students*100;
  174. }
  175. $data[$id]['attempts'] = Display::bar_progress($percentange, false, $count .' / '.$count_students);
  176. }
  177. break;
  178. case HOT_SPOT:
  179. if ($answer_id == 1) {
  180. $data[$id]['name'] = cut($question_obj->question, 100);
  181. } else {
  182. $data[$id]['name'] = '-';
  183. }
  184. $data[$id]['answer'] = $answer_info;
  185. $data[$id]['correct'] = '-';
  186. $count = ExerciseLib::get_number_students_answer_hotspot_count(
  187. $answer_id,
  188. $question_id,
  189. $exercise_id,
  190. $courseCode,
  191. $sessionId
  192. );
  193. $percentange = 0;
  194. if (!empty($count_students)) {
  195. $percentange = $count/$count_students*100;
  196. }
  197. $data[$id]['attempts'] = Display::bar_progress($percentange, false, $count .' / '.$count_students);
  198. break;
  199. default:
  200. if ($answer_id == 1) {
  201. $data[$id]['name'] = cut($question_obj->question, 100);
  202. } else {
  203. $data[$id]['name'] = '-';
  204. }
  205. $data[$id]['answer'] = $answer_info;
  206. $data[$id]['correct'] = $correct_answer;
  207. $count = ExerciseLib::get_number_students_answer_count(
  208. $real_answer_id,
  209. $question_id,
  210. $exercise_id,
  211. $courseCode,
  212. $sessionId
  213. );
  214. $percentange = 0;
  215. if (!empty($count_students)) {
  216. $percentange = $count/$count_students*100;
  217. }
  218. $data[$id]['attempts'] = Display::bar_progress($percentange, false, $count .' / '.$count_students);
  219. }
  220. $id++;
  221. }
  222. }
  223. }
  224. // Format A table
  225. $table = new HTML_Table(array('class' => 'data_table'));
  226. $row = 0;
  227. $column = 0;
  228. foreach ($headers as $header) {
  229. $table->setHeaderContents($row, $column, $header);
  230. $column++;
  231. }
  232. $row++;
  233. foreach ($data as $row_table) {
  234. $column = 0;
  235. foreach ($row_table as $cell) {
  236. $table->setCellContents($row, $column, $cell);
  237. $table->updateCellAttributes($row, $column, 'align="center"');
  238. $column++;
  239. }
  240. $table->updateRowAttributes($row, $row % 2 ? 'class="row_even"' : 'class="row_odd"', true);
  241. $row++;
  242. }
  243. $content .= $table->toHtml();
  244. $interbreadcrumb[] = array ("url" => "exercice.php?gradebook=$gradebook", "name" => get_lang('Exercices'));
  245. $interbreadcrumb[] = array ("url" => "admin.php?exerciseId=$exercise_id","name" => $objExercise->name);
  246. $tpl = new Template(get_lang('ReportByQuestion'));
  247. //$actions = array();
  248. //$actions[]= array(get_lang('Back'), Display::return_icon('back.png', get_lang('Back'), 'exercise_report.php?'.$exercise_id));
  249. //$tpl->set_actions($actions);
  250. $actions = '<a href="exercise_report.php?exerciseId='.intval($_GET['exerciseId']).'">' .
  251. Display :: return_icon('back.png', get_lang('GoBackToQuestionList'),'',ICON_SIZE_MEDIUM).'</a>';
  252. $actions = Display::div($actions, array('class'=> 'actions'));
  253. $content = $actions.$content;
  254. $tpl->assign('content', $content);
  255. $tpl->display_one_col_template();