stats.php 10 KB

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