PageRenderTime 51ms CodeModel.GetById 23ms RepoModel.GetById 1ms app.codeStats 0ms

/mod/quiz/report/responses/report.php

https://github.com/mkassaei/Moodle-Question-Engine-2
PHP | 245 lines | 154 code | 42 blank | 49 comment | 38 complexity | 67448c82799fde2bd45b02e5928bbb80 MD5 | raw file
  1. <?php
  2. // This file is part of Moodle - http://moodle.org/
  3. //
  4. // Moodle is free software: you can redistribute it and/or modify
  5. // it under the terms of the GNU General Public License as published by
  6. // the Free Software Foundation, either version 3 of the License, or
  7. // (at your option) any later version.
  8. //
  9. // Moodle is distributed in the hope that it will be useful,
  10. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. // GNU General Public License for more details.
  13. //
  14. // You should have received a copy of the GNU General Public License
  15. // along with Moodle. If not, see <http://www.gnu.org/licenses/>.
  16. /**
  17. * This file defines the quiz responses report class.
  18. *
  19. * @package quiz_responses
  20. * @copyright 2006 Jean-Michel Vedrine
  21. * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  22. */
  23. require_once($CFG->dirroot.'/mod/quiz/report/attemptsreport.php');
  24. require_once($CFG->dirroot.'/mod/quiz/report/responses/responsessettings_form.php');
  25. require_once($CFG->dirroot.'/mod/quiz/report/responses/responses_table.php');
  26. /**
  27. * Quiz report subclass for the responses report.
  28. *
  29. * This report lists some combination of
  30. * * what question each student saw (this makes sense if random questions were used).
  31. * * the response they gave,
  32. * * and what the right answer is.
  33. *
  34. * Like the overview report, there are options for showing students with/without
  35. * attempts, and for deleting selected attempts.
  36. *
  37. * @copyright 1999 onwards Martin Dougiamas and others {@link http://moodle.com}
  38. * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  39. */
  40. class quiz_responses_report extends quiz_attempt_report {
  41. function display($quiz, $cm, $course) {
  42. global $CFG, $COURSE;
  43. $this->context = get_context_instance(CONTEXT_MODULE, $cm->id);
  44. $download = optional_param('download', '', PARAM_ALPHA);
  45. list($currentgroup, $students, $groupstudents, $allowed) =
  46. $this->load_relevant_students($cm);
  47. $pageoptions = array();
  48. $pageoptions['id'] = $cm->id;
  49. $pageoptions['mode'] = 'responses';
  50. $reporturl = new moodle_url($CFG->wwwroot . '/mod/quiz/report.php', $pageoptions);
  51. $qmsubselect = quiz_report_qm_filter_select($quiz);
  52. $mform = new mod_quiz_report_responses_settings($reporturl,
  53. array('qmsubselect' => $qmsubselect, 'quiz' => $quiz, 'currentgroup' => $currentgroup));
  54. if ($fromform = $mform->get_data()) {
  55. $attemptsmode = $fromform->attemptsmode;
  56. if ($qmsubselect) {
  57. $qmfilter = $fromform->qmfilter;
  58. } else {
  59. $qmfilter = 0;
  60. }
  61. set_user_preference('quiz_report_responses_qtext', $fromform->qtext);
  62. set_user_preference('quiz_report_responses_resp', $fromform->resp);
  63. set_user_preference('quiz_report_responses_right', $fromform->right);
  64. set_user_preference('quiz_report_pagesize', $fromform->pagesize);
  65. $includeqtext = $fromform->qtext;
  66. $includeresp = $fromform->resp;
  67. $includeright = $fromform->right;
  68. $pagesize = $fromform->pagesize;
  69. } else {
  70. $attemptsmode = optional_param('attemptsmode', null, PARAM_INT);
  71. if ($qmsubselect) {
  72. $qmfilter = optional_param('qmfilter', 0, PARAM_INT);
  73. } else {
  74. $qmfilter = 0;
  75. }
  76. $includeqtext = get_user_preferences('quiz_report_responses_qtext', 0);
  77. $includeresp = get_user_preferences('quiz_report_responses_resp', 1);
  78. $includeright = get_user_preferences('quiz_report_responses_right', 0);
  79. $pagesize = get_user_preferences('quiz_report_pagesize', 0);
  80. }
  81. $this->validate_common_options($attemptsmode, $pagesize, $course, $currentgroup);
  82. if (!$includeqtext && !$includeresp && !$includeright) {
  83. $includeresp = 1;
  84. set_user_preference('quiz_report_responses_resp', 1);
  85. }
  86. // We only want to show the checkbox to delete attempts
  87. // if the user has permissions and if the report mode is showing attempts.
  88. $candelete = has_capability('mod/quiz:deleteattempts', $this->context)
  89. && ($attemptsmode != QUIZ_REPORT_ATTEMPTS_STUDENTS_WITH_NO);
  90. $displayoptions = array();
  91. $displayoptions['attemptsmode'] = $attemptsmode;
  92. $displayoptions['qmfilter'] = $qmfilter;
  93. $displayoptions['qtext'] = $includeqtext;
  94. $displayoptions['resp'] = $includeresp;
  95. $displayoptions['right'] = $includeright;
  96. if ($attemptsmode == QUIZ_REPORT_ATTEMPTS_ALL) {
  97. // This option is only available to users who can access all groups in
  98. // groups mode, so setting allowed to empty (which means all quiz attempts
  99. // are accessible, is not a security porblem.
  100. $allowed = array();
  101. }
  102. if ($attemptids = optional_param('attemptid', array(), PARAM_INT) && confirm_sesskey()) {
  103. require_capability('mod/quiz:deleteattempts', $this->context);
  104. $this->delete_selected_attempts($quiz, $cm, $attemptids, $allowed);
  105. redirect($reporturl->out(false, $displayoptions));
  106. }
  107. // Load the required questions.
  108. $questions = quiz_report_get_significant_questions($quiz);
  109. $table = new quiz_report_responses_table($quiz , $qmsubselect, $groupstudents,
  110. $students, $questions, $candelete, $reporturl, $displayoptions);
  111. $filename = quiz_report_download_filename(get_string('responsesfilename', 'quiz_responses'),
  112. $course->shortname, $quiz->name);
  113. $table->is_downloading($download, $filename,
  114. $COURSE->shortname . ' ' . format_string($quiz->name, true));
  115. // ou-specific begins 11236
  116. if ($table->is_downloading()) {
  117. if (empty($CFG->extramemorylimit)) {
  118. raise_memory_limit('128M');
  119. } else {
  120. raise_memory_limit($CFG->extramemorylimit);
  121. }
  122. }
  123. // ou-specific ends 11236
  124. if (!$table->is_downloading()) {
  125. // Only print headers if not asked to download data
  126. $this->print_header_and_tabs($cm, $course, $quiz, 'responses');
  127. }
  128. if ($groupmode = groups_get_activity_groupmode($cm)) { // Groups are being used
  129. if (!$table->is_downloading()) {
  130. groups_print_activity_menu($cm, $reporturl->out(false, $displayoptions));
  131. }
  132. }
  133. // Print information on the number of existing attempts
  134. if (!$table->is_downloading()) { //do not print notices when downloading
  135. if ($strattemptnum = quiz_num_attempt_summary($quiz, $cm, true, $currentgroup)) {
  136. echo '<div class="quizattemptcounts">' . $strattemptnum . '</div>';
  137. }
  138. }
  139. $nostudents = false;
  140. if (!$students) {
  141. notify(get_string('nostudentsyet'));
  142. $nostudents = true;
  143. }else if ($currentgroup && !$groupstudents) {
  144. notify(get_string('nostudentsingroup'));
  145. $nostudents = true;
  146. }
  147. if (!$table->is_downloading()) {
  148. // Print display options
  149. $mform->set_data($displayoptions + compact('pagesize'));
  150. $mform->display();
  151. }
  152. if (!$nostudents || ($attemptsmode == QUIZ_REPORT_ATTEMPTS_ALL)) {
  153. // Print information on the grading method and whether we are displaying
  154. if (!$table->is_downloading()) { //do not print notices when downloading
  155. if ($strattempthighlight = quiz_report_highlighting_grading_method($quiz, $qmsubselect, $qmfilter)) {
  156. echo '<div class="quizattemptcounts">' . $strattempthighlight . '</div>';
  157. }
  158. }
  159. list($fields, $from, $where, $params) =
  160. $this->base_sql($quiz, $qmsubselect, $qmfilter, $attemptsmode, $allowed);
  161. $table->set_count_sql("SELECT COUNT(1) FROM $from WHERE $where", $params);
  162. $table->set_sql($fields, $from, $where, $params);
  163. // Define table columns
  164. $columns = array();
  165. $headers = array();
  166. if (!$table->is_downloading() && $candelete) {
  167. $columns[] = 'checkbox';
  168. $headers[] = NULL;
  169. }
  170. $this->add_user_columns($table, $columns, $headers);
  171. if ($table->is_downloading()) {
  172. $this->add_time_columns($columns, $headers);
  173. }
  174. $this->add_grade_columns($quiz, $columns, $headers);
  175. foreach ($questions as $id => $question) {
  176. if ($displayoptions['qtext']) {
  177. $columns[] = 'question' . $id;
  178. $headers[] = get_string('questionx', 'question', $question->number);
  179. }
  180. if ($displayoptions['resp']) {
  181. $columns[] = 'response' . $id;
  182. $headers[] = get_string('responsex', 'quiz_responses', $question->number);
  183. }
  184. if ($displayoptions['right']) {
  185. $columns[] = 'right' . $id;
  186. $headers[] = get_string('rightanswerx', 'quiz_responses', $question->number);
  187. }
  188. }
  189. $table->define_columns($columns);
  190. $table->define_headers($headers);
  191. $table->sortable(true, 'uniqueid');
  192. // Set up the table
  193. $table->define_baseurl($reporturl->out(false, $displayoptions));
  194. $this->configure_user_columns($table);
  195. $table->no_sorting('feedbacktext');
  196. $table->column_class('sumgrades', 'bold');
  197. $table->set_attribute('id', 'attempts');
  198. $table->collapsible(true);
  199. $table->out($pagesize, true);
  200. }
  201. return true;
  202. }
  203. }