stats.php 9.9 KB

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