stats.php 9.9 KB

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