stats.php 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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. $students = CourseManager :: get_student_list_from_course_code(api_get_course_id(), false);
  17. $question_list = $objExercise->get_validated_question_list();
  18. $data = array();
  19. //Question title # of students who tool it Lowest score Average Highest score Maximum score
  20. $headers = array(
  21. get_lang('Question'),
  22. get_lang('NumberOfStudentsWhoTryTheExercise'),
  23. get_lang('LowestScore'),
  24. get_lang('AverageScore'),
  25. get_lang('HighestScore'),
  26. get_lang('MaximumScore')
  27. );
  28. if (!empty($question_list)) {
  29. foreach($question_list as $question_id) {
  30. $question_obj = Question::read($question_id);
  31. $exercise_stats = get_student_stats_by_question($question_id, $exercise_id, api_get_course_id(), api_get_session_id());
  32. $data[$question_id]['name'] = cut($question_obj->question, 100);
  33. $data[$question_id]['students_who_try_exercise'] = $exercise_stats['users'];
  34. $data[$question_id]['lowest_score'] = $exercise_stats['min'];
  35. $data[$question_id]['average_score'] = $exercise_stats['average'];
  36. $data[$question_id]['highest_score'] = $exercise_stats['max'];
  37. $data[$question_id]['max_score'] = $question_obj->weighting;
  38. }
  39. }
  40. //Format A table
  41. $table = new HTML_Table(array('class' => 'data_table'));
  42. $row = 0;
  43. $column = 0;
  44. foreach ($headers as $header) {
  45. $table->setHeaderContents($row, $column, $header);
  46. $column++;
  47. }
  48. $row++;
  49. foreach ($data as $row_table) {
  50. $column = 0;
  51. foreach ($row_table as $cell) {
  52. $table->setCellContents($row, $column, $cell);
  53. $table->updateCellAttributes($row, $column, 'align="center"');
  54. $column++;
  55. }
  56. $table->updateRowAttributes($row, $row % 2 ? 'class="row_even"' : 'class="row_odd"', true);
  57. $row++;
  58. }
  59. $content = $table->toHtml();
  60. //Format B
  61. $headers = array(
  62. get_lang('Question'),
  63. get_lang('Answer'),
  64. get_lang('Correct'),
  65. get_lang('NumberStudentWhoSelectedIt'),
  66. get_lang('HighestScore'),
  67. get_lang('MaximumScore')
  68. );
  69. $interbreadcrumb[] = array ("url" => "exercice.php?gradebook=$gradebook", "name" => get_lang('Exercices'));
  70. $interbreadcrumb[] = array ("url" => "admin.php?exerciseId=$exercise_id","name" => $objExercise->name);
  71. $tpl = new Template(get_lang('Stats'));
  72. $tpl->assign('content', $content);
  73. $tpl->display_one_col_template();