stats.php 11 KB

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