stats.php 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249
  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'] = Text::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 = 0;
  45. if ($count_students) {
  46. $percentange = $count_users/$count_students*100;
  47. }
  48. $data[$question_id]['students_who_try_exercise'] = Display::bar_progress($percentange, false, $count_users .' / '.$count_students);
  49. $data[$question_id]['lowest_score'] = round($exercise_stats['min'], 2);
  50. $data[$question_id]['average_score'] = round($exercise_stats['average'], 2);
  51. $data[$question_id]['highest_score'] = round($exercise_stats['max'], 2);
  52. $data[$question_id]['max_score'] = round($question_obj->weighting, 2);
  53. }
  54. }
  55. //Format A table
  56. $table = new HTML_Table(array('class' => 'data_table'));
  57. $row = 0;
  58. $column = 0;
  59. foreach ($headers as $header) {
  60. $table->setHeaderContents($row, $column, $header);
  61. $column++;
  62. }
  63. $row++;
  64. foreach ($data as $row_table) {
  65. $column = 0;
  66. foreach ($row_table as $cell) {
  67. $table->setCellContents($row, $column, $cell);
  68. $table->updateCellAttributes($row, $column, 'align="center"');
  69. $column++;
  70. }
  71. $table->updateRowAttributes($row, $row % 2 ? 'class="row_even"' : 'class="row_odd"', true);
  72. $row++;
  73. }
  74. $content = $table->toHtml();
  75. //Format B
  76. $headers = array(
  77. get_lang('Question'),
  78. get_lang('Answer'),
  79. get_lang('Correct'),
  80. get_lang('NumberStudentWhoSelectedIt')
  81. );
  82. $data = array();
  83. if (!empty($question_list)) {
  84. $id = 0;
  85. foreach ($question_list as $question_id) {
  86. $question_obj = Question::read($question_id);
  87. $exercise_stats = get_student_stats_by_question($question_id, $exercise_id, api_get_course_id(), api_get_session_id());
  88. $answer = new Answer($question_id);
  89. $answer_count = $answer->selectNbrAnswers();
  90. for ($answer_id = 1; $answer_id <= $answer_count; $answer_id++) {
  91. $answer_info = $answer->selectAnswer($answer_id);
  92. $is_correct = $answer->isCorrect($answer_id);
  93. $correct_answer = $is_correct == 1 ? get_lang('Yes') : get_lang('No');
  94. $real_answer_id = $answer->selectAutoId($answer_id);
  95. //$data[$id]['name'] .=$answer_count;
  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 = get_number_students_answer_count($real_answer_id, $question_id, $exercise_id, api_get_course_id(), api_get_session_id(), FILL_IN_BLANKS, $answer_info_db, $answer_item);
  115. $percentange = 0;
  116. if (!empty($count_students)) {
  117. $percentange = $count/$count_students*100;
  118. }
  119. $data[$id]['attempts'] = Display::bar_progress($percentange, false, $count .' / '.$count_students);
  120. $id++;
  121. $counter++;
  122. }
  123. break;
  124. case MATCHING:
  125. if ($is_correct == 0) {
  126. if ($answer_id == 1) {
  127. $data[$id]['name'] = Text::cut($question_obj->question, 100);
  128. } else {
  129. $data[$id]['name'] = '-';
  130. }
  131. $correct = '';
  132. for ($i = 1; $i <= $answer_count; $i++) {
  133. $is_correct_i = $answer->isCorrect($i);
  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 = get_number_students_answer_count($answer_id, $question_id, $exercise_id, api_get_course_id(), api_get_session_id(), MATCHING);
  142. $percentange = 0;
  143. if (!empty($count_students)) {
  144. $percentange = $count/$count_students*100;
  145. }
  146. $data[$id]['attempts'] = Display::bar_progress($percentange, false, $count .' / '.$count_students);
  147. }
  148. break;
  149. case HOT_SPOT:
  150. if ($answer_id == 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 = get_number_students_answer_hotspot_count($answer_id, $question_id, $exercise_id, api_get_course_id(), api_get_session_id());
  158. $percentange = 0;
  159. if (!empty($count_students)) {
  160. $percentange = $count/$count_students*100;
  161. }
  162. $data[$id]['attempts'] = Display::bar_progress($percentange, false, $count .' / '.$count_students);
  163. break;
  164. default:
  165. if ($answer_id == 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 = get_number_students_answer_count($real_answer_id, $question_id, $exercise_id, api_get_course_id(), api_get_session_id());
  173. $percentange = 0;
  174. if (!empty($count_students)) {
  175. $percentange = $count/$count_students*100;
  176. }
  177. $data[$id]['attempts'] = Display::bar_progress($percentange, false, $count .' / '.$count_students);
  178. }
  179. $id++;
  180. }
  181. }
  182. }
  183. //Format A table
  184. $table = new HTML_Table(array('class' => 'data_table'));
  185. $row = 0;
  186. $column = 0;
  187. foreach ($headers as $header) {
  188. $table->setHeaderContents($row, $column, $header);
  189. $column++;
  190. }
  191. $row++;
  192. foreach ($data as $row_table) {
  193. $column = 0;
  194. foreach ($row_table as $cell) {
  195. $table->setCellContents($row, $column, $cell);
  196. $table->updateCellAttributes($row, $column, 'align="center"');
  197. $column++;
  198. }
  199. $table->updateRowAttributes($row, $row % 2 ? 'class="row_even"' : 'class="row_odd"', true);
  200. $row++;
  201. }
  202. $content .= $table->toHtml();
  203. $interbreadcrumb[] = array ("url" => "exercice.php?gradebook=$gradebook", "name" => get_lang('Exercices'));
  204. $interbreadcrumb[] = array ("url" => "admin.php?exerciseId=$exercise_id","name" => $objExercise->name);
  205. $tpl = new Template(get_lang('ReportByQuestion'));
  206. //$actions = array();
  207. //$actions[]= array(get_lang('Back'), Display::return_icon('back.png', get_lang('Back'), 'exercise_report.php?'.$exercise_id));
  208. //$tpl->set_actions($actions);
  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();