stats.php 11 KB

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