stats.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294
  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]['correct'] = '-';
  128. $count = ExerciseLib::get_number_students_answer_count(
  129. $real_answer_id,
  130. $question_id,
  131. $exercise_id,
  132. $courseCode,
  133. $sessionId,
  134. FILL_IN_BLANKS,
  135. $answer_info_db,
  136. $answer_item
  137. );
  138. $percentange = 0;
  139. if (!empty($count_students)) {
  140. $percentange = $count/$count_students*100;
  141. }
  142. $data[$id]['attempts'] = Display::bar_progress($percentange, false, $count .' / '.$count_students);
  143. $id++;
  144. $counter++;
  145. }
  146. break;
  147. case MATCHING:
  148. //no break
  149. case MATCHING_DRAGGABLE:
  150. if ($is_correct == 0) {
  151. if ($answer_id == 1) {
  152. $data[$id]['name'] = cut($question_obj->question, 100);
  153. } else {
  154. $data[$id]['name'] = '-';
  155. }
  156. $correct = '';
  157. for ($i = 1; $i <= $answer_count; $i++) {
  158. $is_correct_i = $answer->isCorrect($i);
  159. if ($is_correct_i != 0 && $is_correct_i == $answer_id) {
  160. $correct = $answer->selectAnswer($i);
  161. break;
  162. }
  163. }
  164. $data[$id]['answer'] = $correct;
  165. $data[$id]['correct'] = $answer_info;
  166. $count = ExerciseLib::get_number_students_answer_count(
  167. $answer_id,
  168. $question_id,
  169. $exercise_id,
  170. $courseCode,
  171. $sessionId,
  172. MATCHING
  173. );
  174. $percentange = 0;
  175. if (!empty($count_students)) {
  176. $percentange = $count/$count_students*100;
  177. }
  178. $data[$id]['attempts'] = Display::bar_progress($percentange, false, $count .' / '.$count_students);
  179. }
  180. break;
  181. case HOT_SPOT:
  182. if ($answer_id == 1) {
  183. $data[$id]['name'] = cut($question_obj->question, 100);
  184. } else {
  185. $data[$id]['name'] = '-';
  186. }
  187. $data[$id]['answer'] = $answer_info;
  188. $data[$id]['correct'] = '-';
  189. $count = ExerciseLib::get_number_students_answer_hotspot_count(
  190. $answer_id,
  191. $question_id,
  192. $exercise_id,
  193. $courseCode,
  194. $sessionId
  195. );
  196. $percentange = 0;
  197. if (!empty($count_students)) {
  198. $percentange = $count/$count_students*100;
  199. }
  200. $data[$id]['attempts'] = Display::bar_progress($percentange, false, $count .' / '.$count_students);
  201. break;
  202. default:
  203. if ($answer_id == 1) {
  204. $data[$id]['name'] = cut($question_obj->question, 100);
  205. } else {
  206. $data[$id]['name'] = '-';
  207. }
  208. $data[$id]['answer'] = $answer_info;
  209. $data[$id]['correct'] = $correct_answer;
  210. $count = ExerciseLib::get_number_students_answer_count(
  211. $real_answer_id,
  212. $question_id,
  213. $exercise_id,
  214. $courseCode,
  215. $sessionId
  216. );
  217. $percentange = 0;
  218. if (!empty($count_students)) {
  219. $percentange = $count/$count_students*100;
  220. }
  221. $data[$id]['attempts'] = Display::bar_progress($percentange, false, $count .' / '.$count_students);
  222. }
  223. $id++;
  224. }
  225. }
  226. }
  227. // Format A table
  228. $table = new HTML_Table(array('class' => 'data_table'));
  229. $row = 0;
  230. $column = 0;
  231. foreach ($headers as $header) {
  232. $table->setHeaderContents($row, $column, $header);
  233. $column++;
  234. }
  235. $row++;
  236. foreach ($data as $row_table) {
  237. $column = 0;
  238. foreach ($row_table as $cell) {
  239. $table->setCellContents($row, $column, $cell);
  240. $table->updateCellAttributes($row, $column, 'align="center"');
  241. $column++;
  242. }
  243. $table->updateRowAttributes($row, $row % 2 ? 'class="row_even"' : 'class="row_odd"', true);
  244. $row++;
  245. }
  246. $content .= $table->toHtml();
  247. $interbreadcrumb[] = array("url" => "exercise.php?gradebook=$gradebook&".api_get_cidreq(), "name" => get_lang('Exercises'));
  248. $interbreadcrumb[] = array("url" => "admin.php?exerciseId=$exercise_id&".api_get_cidreq(), "name" => $objExercise->name);
  249. $tpl = new Template(get_lang('ReportByQuestion'));
  250. //$actions = array();
  251. //$actions[]= array(get_lang('Back'), Display::return_icon('back.png', get_lang('Back'), 'exercise_report.php?'.$exercise_id));
  252. //$tpl->set_actions($actions);
  253. $actions = '<a href="exercise_report.php?exerciseId='.intval($_GET['exerciseId']).'&'.api_get_cidreq().'">' .
  254. Display :: return_icon('back.png', get_lang('GoBackToQuestionList'),'',ICON_SIZE_MEDIUM).'</a>';
  255. $actions = Display::div($actions, array('class'=> 'actions'));
  256. $content = $actions.$content;
  257. $tpl->assign('content', $content);
  258. $tpl->display_one_col_template();