diff --git a/mod/quiz/report/attemptsreport.php b/mod/quiz/report/attemptsreport.php index c0012d1862a..a976e529425 100644 --- a/mod/quiz/report/attemptsreport.php +++ b/mod/quiz/report/attemptsreport.php @@ -48,12 +48,56 @@ abstract class quiz_attempt_report extends quiz_default_report { /** @var int include all enroled users. */ const ALL_STUDENTS = 3; + /** @var string the mode this report is. */ + protected $mode; + /** @var object the quiz context. */ protected $context; + /** @var mod_quiz_attempt_report_form The settings form to use. */ + protected $form; + + /** @var string SQL fragment for selecting the attempt that gave the final grade, + * if applicable. */ + protected $qmsubselect; + /** @var boolean caches the results of {@link should_show_grades()}. */ protected $showgrades = null; + /** + * Initialise various aspects of this report. + * + * @param string $mode + * @param string $formclass + * @param object $quiz + * @param object $cm + * @param object $course + */ + protected function init($mode, $formclass, $quiz, $cm, $course) { + $this->mode = $mode; + + $this->context = context_module::instance($cm->id); + + list($currentgroup, $students, $groupstudents, $allowed) = + $this->load_relevant_students($cm, $course); + + $this->qmsubselect = quiz_report_qm_filter_select($quiz); + + $this->form = new $formclass($this->get_base_url(), + array('qmsubselect' => $this->qmsubselect, 'quiz' => $quiz, + 'currentgroup' => $currentgroup, 'context' => $this->context)); + + return array($currentgroup, $students, $groupstudents, $allowed); + } + + /** + * @return moodle_url the base URL for this report. + */ + protected function get_base_url() { + return new moodle_url('/mod/quiz/report.php', + array('id' => $this->context->instanceid, 'mode' => $this->mode)); + } + /** * Should the grades be displayed in this report. That depends on the quiz * display options, and whether the quiz is graded. diff --git a/mod/quiz/report/overview/report.php b/mod/quiz/report/overview/report.php index 0565aa8ca08..7c8050424d7 100644 --- a/mod/quiz/report/overview/report.php +++ b/mod/quiz/report/overview/report.php @@ -41,30 +41,15 @@ class quiz_overview_report extends quiz_attempt_report { public function display($quiz, $cm, $course) { global $CFG, $DB, $OUTPUT; - $this->context = context_module::instance($cm->id); - - $download = optional_param('download', '', PARAM_ALPHA); - list($currentgroup, $students, $groupstudents, $allowed) = - $this->load_relevant_students($cm, $course); + $this->init('overview', 'quiz_overview_settings_form', $quiz, $cm, $course); - $pageoptions = array(); - $pageoptions['id'] = $cm->id; - $pageoptions['mode'] = 'overview'; - - $reporturl = new moodle_url('/mod/quiz/report.php', $pageoptions); - $qmsubselect = quiz_report_qm_filter_select($quiz); - - $mform = new quiz_overview_settings_form($reporturl, - array('qmsubselect' => $qmsubselect, 'quiz' => $quiz, - 'currentgroup' => $currentgroup, 'context' => $this->context)); - - if ($fromform = $mform->get_data()) { + if ($fromform = $this->form->get_data()) { $regradeall = false; $regradealldry = false; $regradealldrydo = false; $attemptsmode = $fromform->attemptsmode; - if ($qmsubselect) { + if ($this->qmsubselect) { $qmfilter = $fromform->qmfilter; } else { $qmfilter = 0; @@ -80,7 +65,7 @@ class quiz_overview_report extends quiz_attempt_report { $regradealldry = optional_param('regradealldry', 0, PARAM_BOOL); $regradealldrydo = optional_param('regradealldrydo', 0, PARAM_BOOL); $attemptsmode = optional_param('attemptsmode', null, PARAM_INT); - if ($qmsubselect) { + if ($this->qmsubselect) { $qmfilter = optional_param('qmfilter', 0, PARAM_INT); } else { $qmfilter = 0; @@ -96,7 +81,7 @@ class quiz_overview_report extends quiz_attempt_report { $displayoptions['qmfilter'] = $qmfilter; $displayoptions['regradefilter'] = $regradefilter; - $mform->set_data($displayoptions + + $this->form->set_data($displayoptions + array('detailedmarks' => $detailedmarks, 'pagesize' => $pagesize)); if (!$this->should_show_grades($quiz)) { @@ -122,12 +107,12 @@ class quiz_overview_report extends quiz_attempt_report { // Prepare for downloading, if applicable. $courseshortname = format_string($course->shortname, true, array('context' => context_course::instance($course->id))); - $table = new quiz_overview_table($quiz, $this->context, $qmsubselect, + $table = new quiz_overview_table($quiz, $this->context, $this->qmsubselect, $qmfilter, $attemptsmode, $groupstudents, $students, $detailedmarks, - $questions, $includecheckboxes, $reporturl, $displayoptions); + $questions, $includecheckboxes, $this->get_base_url(), $displayoptions); $filename = quiz_report_download_filename(get_string('overviewfilename', 'quiz_overview'), $courseshortname, $quiz->name); - $table->is_downloading($download, $filename, + $table->is_downloading(optional_param('download', '', PARAM_ALPHA), $filename, $courseshortname . ' ' . format_string($quiz->name, true)); if ($table->is_downloading()) { raise_memory_limit(MEMORY_EXTRA); @@ -139,14 +124,14 @@ class quiz_overview_report extends quiz_attempt_report { if ($attemptids = optional_param_array('attemptid', array(), PARAM_INT)) { require_capability('mod/quiz:deleteattempts', $this->context); $this->delete_selected_attempts($quiz, $cm, $attemptids, $allowed); - redirect($reporturl->out(false, $displayoptions)); + redirect($this->get_base_url()->out(false, $displayoptions)); } } else if (optional_param('regrade', 0, PARAM_BOOL) && confirm_sesskey()) { if ($attemptids = optional_param_array('attemptid', array(), PARAM_INT)) { require_capability('mod/quiz:regrade', $this->context); $this->regrade_attempts($quiz, false, $groupstudents, $attemptids); - redirect($reporturl->out(false, $displayoptions)); + redirect($this->get_base_url()->out(false, $displayoptions)); } } } @@ -154,17 +139,17 @@ class quiz_overview_report extends quiz_attempt_report { if ($regradeall && confirm_sesskey()) { require_capability('mod/quiz:regrade', $this->context); $this->regrade_attempts($quiz, false, $groupstudents); - redirect($reporturl->out(false, $displayoptions), '', 5); + redirect($this->get_base_url()->out(false, $displayoptions), '', 5); } else if ($regradealldry && confirm_sesskey()) { require_capability('mod/quiz:regrade', $this->context); $this->regrade_attempts($quiz, true, $groupstudents); - redirect($reporturl->out(false, $displayoptions), '', 5); + redirect($this->get_base_url()->out(false, $displayoptions), '', 5); } else if ($regradealldrydo && confirm_sesskey()) { require_capability('mod/quiz:regrade', $this->context); $this->regrade_attempts_needing_it($quiz, $groupstudents); - redirect($reporturl->out(false, $displayoptions), '', 5); + redirect($this->get_base_url()->out(false, $displayoptions), '', 5); } // Start output. @@ -176,7 +161,7 @@ class quiz_overview_report extends quiz_attempt_report { if ($groupmode = groups_get_activity_groupmode($cm)) { // Groups are being used, so output the group selector if we are not downloading. if (!$table->is_downloading()) { - groups_print_activity_menu($cm, $reporturl->out(true, $displayoptions)); + groups_print_activity_menu($cm, $this->get_base_url()->out(true, $displayoptions)); } } @@ -199,7 +184,7 @@ class quiz_overview_report extends quiz_attempt_report { } // Print the display options. - $mform->display(); + $this->form->display(); } $hasstudents = $students && (!$currentgroup || $groupstudents); @@ -207,10 +192,10 @@ class quiz_overview_report extends quiz_attempt_report { // Construct the SQL. $fields = $DB->sql_concat('u.id', "'#'", 'COALESCE(quiza.attempt, 0)') . ' AS uniqueid, '; - if ($qmsubselect) { + if ($this->qmsubselect) { $fields .= "(CASE " . - " WHEN $qmsubselect THEN 1" . + " WHEN {$this->qmsubselect} THEN 1" . " ELSE 0 " . "END) AS gradedattempt, "; } @@ -258,7 +243,7 @@ class quiz_overview_report extends quiz_attempt_report { $regradealllabel = get_string('regradeall', 'quiz_overview'); } - $displayurl = new moodle_url($reporturl, + $displayurl = new moodle_url($this->get_base_url(), $displayoptions + array('sesskey' => sesskey())); echo '