stats.php 11 KB

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