stats.php 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281
  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. $question_obj->type
  47. );
  48. $data[$question_id]['name'] = cut($question_obj->question, 100);
  49. $data[$question_id]['type'] = $question_obj->get_question_type_name();
  50. $percentange = 0;
  51. if ($count_students) {
  52. $percentange = $count_users / $count_students*100;
  53. }
  54. $data[$question_id]['students_who_try_exercise'] = Display::bar_progress(
  55. $percentange,
  56. false,
  57. $count_users .' / '.$count_students
  58. );
  59. $data[$question_id]['lowest_score'] = round($exercise_stats['min'], 2);
  60. $data[$question_id]['average_score'] = round($exercise_stats['average'], 2);
  61. $data[$question_id]['highest_score'] = round($exercise_stats['max'], 2);
  62. $data[$question_id]['max_score'] = round($question_obj->weighting, 2);
  63. }
  64. }
  65. // Format A table
  66. $table = new HTML_Table(array('class' => 'data_table'));
  67. $row = 0;
  68. $column = 0;
  69. foreach ($headers as $header) {
  70. $table->setHeaderContents($row, $column, $header);
  71. $column++;
  72. }
  73. $row++;
  74. foreach ($data as $row_table) {
  75. $column = 0;
  76. foreach ($row_table as $cell) {
  77. $table->setCellContents($row, $column, $cell);
  78. $table->updateCellAttributes($row, $column, 'align="center"');
  79. $column++;
  80. }
  81. $table->updateRowAttributes($row, $row % 2 ? 'class="row_even"' : 'class="row_odd"', true);
  82. $row++;
  83. }
  84. $content = $table->toHtml();
  85. // Format B
  86. $headers = array(
  87. get_lang('Question'),
  88. get_lang('Answer'),
  89. get_lang('Correct'),
  90. get_lang('NumberStudentWhoSelectedIt')
  91. );
  92. $data = array();
  93. if (!empty($question_list)) {
  94. $id = 0;
  95. foreach ($question_list as $question_id) {
  96. $question_obj = Question::read($question_id);
  97. $exercise_stats = ExerciseLib::get_student_stats_by_question(
  98. $question_id,
  99. $exercise_id,
  100. $courseCode,
  101. $sessionId
  102. );
  103. $answer = new Answer($question_id);
  104. $answer_count = $answer->selectNbrAnswers();
  105. for ($answer_id = 1; $answer_id <= $answer_count; $answer_id++) {
  106. $answer_info = $answer->selectAnswer($answer_id);
  107. $is_correct = $answer->isCorrect($answer_id);
  108. $correct_answer = $is_correct == 1 ? get_lang('Yes') : get_lang('No');
  109. $real_answer_id = $answer->selectAutoId($answer_id);
  110. // Overwriting values depending of the question
  111. switch ($question_obj->type) {
  112. case FILL_IN_BLANKS :
  113. $answer_info_db = $answer_info;
  114. $answer_info = substr($answer_info, 0, strpos($answer_info, '::'));
  115. $correct_answer = $is_correct;
  116. $answers = $objExercise->fill_in_blank_answer_to_array($answer_info);
  117. $counter = 0;
  118. foreach ($answers as $answer_item) {
  119. if ($counter == 0) {
  120. $data[$id]['name'] = cut($question_obj->question, 100);
  121. } else {
  122. $data[$id]['name'] = '-';
  123. }
  124. $data[$id]['answer'] = $answer_item;
  125. $answer_item = api_substr($answer_item, 1);
  126. $answer_item = api_substr($answer_item, 0, api_strlen($answer_item) -1);
  127. $data[$id]['answer'] = $answer_item;
  128. $data[$id]['correct'] = '-';
  129. $count = ExerciseLib::getNumberStudentsFillBlanksAnwserCount($question_id, $exercise_id);
  130. $count = $count[$counter];
  131. $percentange = 0;
  132. if (!empty($count_students)) {
  133. $percentange = $count/$count_students*100;
  134. }
  135. $data[$id]['attempts'] = Display::bar_progress($percentange, false, $count .' / '.$count_students);
  136. $id++;
  137. $counter++;
  138. }
  139. break;
  140. case MATCHING:
  141. //no break
  142. case MATCHING_DRAGGABLE:
  143. if ($is_correct == 0) {
  144. if ($answer_id == 1) {
  145. $data[$id]['name'] = cut($question_obj->question, 100);
  146. } else {
  147. $data[$id]['name'] = '-';
  148. }
  149. $correct = '';
  150. for ($i = 1; $i <= $answer_count; $i++) {
  151. $is_correct_i = $answer->isCorrect($i);
  152. if ($is_correct_i != 0 && $is_correct_i == $answer_id) {
  153. $correct = $answer->selectAnswer($i);
  154. break;
  155. }
  156. }
  157. $data[$id]['answer'] = $correct;
  158. $data[$id]['correct'] = $answer_info;
  159. $count = ExerciseLib::get_number_students_answer_count(
  160. $answer_id,
  161. $question_id,
  162. $exercise_id,
  163. $courseCode,
  164. $sessionId,
  165. MATCHING
  166. );
  167. $percentange = 0;
  168. if (!empty($count_students)) {
  169. $percentange = $count/$count_students*100;
  170. }
  171. $data[$id]['attempts'] = Display::bar_progress($percentange, false, $count .' / '.$count_students);
  172. }
  173. break;
  174. case HOT_SPOT:
  175. if ($answer_id == 1) {
  176. $data[$id]['name'] = cut($question_obj->question, 100);
  177. } else {
  178. $data[$id]['name'] = '-';
  179. }
  180. $data[$id]['answer'] = $answer_info;
  181. $data[$id]['correct'] = '-';
  182. $count = ExerciseLib::get_number_students_answer_hotspot_count(
  183. $answer_id,
  184. $question_id,
  185. $exercise_id,
  186. $courseCode,
  187. $sessionId
  188. );
  189. $percentange = 0;
  190. if (!empty($count_students)) {
  191. $percentange = $count/$count_students*100;
  192. }
  193. $data[$id]['attempts'] = Display::bar_progress($percentange, false, $count .' / '.$count_students);
  194. break;
  195. default:
  196. if ($answer_id == 1) {
  197. $data[$id]['name'] = cut($question_obj->question, 100);
  198. } else {
  199. $data[$id]['name'] = '-';
  200. }
  201. $data[$id]['answer'] = $answer_info;
  202. $data[$id]['correct'] = $correct_answer;
  203. $count = ExerciseLib::get_number_students_answer_count(
  204. $real_answer_id,
  205. $question_id,
  206. $exercise_id,
  207. $courseCode,
  208. $sessionId
  209. );
  210. $percentange = 0;
  211. if (!empty($count_students)) {
  212. $percentange = $count/$count_students*100;
  213. }
  214. $data[$id]['attempts'] = Display::bar_progress($percentange, false, $count .' / '.$count_students);
  215. }
  216. $id++;
  217. }
  218. }
  219. }
  220. // Format A table
  221. $table = new HTML_Table(array('class' => 'data_table'));
  222. $row = 0;
  223. $column = 0;
  224. foreach ($headers as $header) {
  225. $table->setHeaderContents($row, $column, $header);
  226. $column++;
  227. }
  228. $row++;
  229. foreach ($data as $row_table) {
  230. $column = 0;
  231. foreach ($row_table as $cell) {
  232. $table->setCellContents($row, $column, $cell);
  233. $table->updateCellAttributes($row, $column, 'align="center"');
  234. $column++;
  235. }
  236. $table->updateRowAttributes($row, $row % 2 ? 'class="row_even"' : 'class="row_odd"', true);
  237. $row++;
  238. }
  239. $content .= $table->toHtml();
  240. $interbreadcrumb[] = array("url" => "exercise.php?gradebook=$gradebook&".api_get_cidreq(), "name" => get_lang('Exercises'));
  241. $interbreadcrumb[] = array("url" => "admin.php?exerciseId=$exercise_id&".api_get_cidreq(), "name" => $objExercise->name);
  242. $tpl = new Template(get_lang('ReportByQuestion'));
  243. $actions = '<a href="exercise_report.php?exerciseId='.intval($_GET['exerciseId']).'&'.api_get_cidreq().'">' .
  244. Display :: return_icon('back.png', get_lang('GoBackToQuestionList'),'',ICON_SIZE_MEDIUM).'</a>';
  245. $actions = Display::div($actions, array('class'=> 'actions'));
  246. $content = $actions.$content;
  247. $tpl->assign('content', $content);
  248. $tpl->display_one_col_template();