diff --git a/mod/quiz/report/attemptsreport.php b/mod/quiz/report/attemptsreport.php index 7900117ab6a..49bdb8d99f1 100644 --- a/mod/quiz/report/attemptsreport.php +++ b/mod/quiz/report/attemptsreport.php @@ -242,16 +242,16 @@ abstract class quiz_attempts_report extends quiz_default_report { * @param array $columns the list of columns. * @param array $headers the columns headings. * @param moodle_url $reporturl the URL of this report. - * @param array $displayoptions the display options. + * @param mod_quiz_attempts_report_options $options the display options. * @param bool $collapsible whether to allow columns in the report to be collapsed. */ protected function set_up_table_columns($table, $columns, $headers, $reporturl, - $displayoptions, $collapsible) { + mod_quiz_attempts_report_options $options, $collapsible) { $table->define_columns($columns); $table->define_headers($headers); $table->sortable(true, 'uniqueid'); - $table->define_baseurl($reporturl->out(false, $displayoptions)); + $table->define_baseurl($options->get_url()); $this->configure_user_columns($table); diff --git a/mod/quiz/report/attemptsreport_options.php b/mod/quiz/report/attemptsreport_options.php index 212357bd812..c9d9953f4a1 100644 --- a/mod/quiz/report/attemptsreport_options.php +++ b/mod/quiz/report/attemptsreport_options.php @@ -36,6 +36,9 @@ require_once($CFG->libdir . '/formslib.php'); */ class mod_quiz_attempts_report_options { + /** @var string the report mode. */ + public $mode; + /** @var object the settings for the quiz being reported on. */ public $quiz; @@ -74,7 +77,8 @@ class mod_quiz_attempts_report_options { * @param object $quiz the settings for the quiz being reported on. * @param object $cm the course module objects for the quiz being reported on. */ - public function __construct($quiz, $cm, $course) { + public function __construct($mode, $quiz, $cm, $course) { + $this->mode = $mode; $this->quiz = $quiz; $this->cm = $cm; $this->course = $course; @@ -82,6 +86,25 @@ class mod_quiz_attempts_report_options { $this->usercanseegrades = quiz_report_should_show_grades($quiz); } + /** + * @return array the URL parameters required to show the report with these options. + */ + protected function get_url_params() { + return array( + 'id' => $this->cm->id, + 'mode' => $this->mode, + 'attemptsmode' => $this->attempts, + 'qmfilter' => $this->onlygraded, + ); + } + + /** + * @return moodle_url the URL to show the report with these options. + */ + public function get_url() { + return new moodle_url('/mod/quiz/report.php', $this->get_url_params()); + } + /** * Process the data we get when the settings form is submitted. This includes * updating the fields of this class, and updating the user preferences diff --git a/mod/quiz/report/attemptsreport_table.php b/mod/quiz/report/attemptsreport_table.php index c4dffa6d781..59c5bf38d4f 100755 --- a/mod/quiz/report/attemptsreport_table.php +++ b/mod/quiz/report/attemptsreport_table.php @@ -52,6 +52,7 @@ abstract class quiz_attempts_report_table extends table_sql { protected $quiz; protected $context; protected $qmsubselect; + protected $options; protected $qmfilter; protected $attemptsmode; protected $groupstudents; @@ -59,21 +60,21 @@ abstract class quiz_attempts_report_table extends table_sql { protected $questions; protected $includecheckboxes; - public function __construct($uniqueid, $quiz, $context, $qmsubselect, $qmfilter, - $attemptsmode, $groupstudents, $students, $questions, $includecheckboxes, - $reporturl, $displayoptions) { + public function __construct($uniqueid, $quiz, $context, $qmsubselect, + mod_quiz_attempts_report_options $options, $groupstudents, $students, + $questions, $reporturl) { parent::__construct($uniqueid); $this->quiz = $quiz; $this->context = $context; $this->qmsubselect = $qmsubselect; - $this->qmfilter = $qmfilter; - $this->attemptsmode = $attemptsmode; + $this->qmfilter = $options->onlygraded; + $this->attemptsmode = $options->attempts; $this->groupstudents = $groupstudents; $this->students = $students; $this->questions = $questions; - $this->includecheckboxes = $includecheckboxes; + $this->includecheckboxes = $options->checkboxcolumn; $this->reporturl = $reporturl; - $this->displayoptions = $displayoptions; + $this->options = $options; } public function col_checkbox($attempt) { diff --git a/mod/quiz/report/overview/overview_options.php b/mod/quiz/report/overview/overview_options.php index bb75c3442fb..e985c098587 100644 --- a/mod/quiz/report/overview/overview_options.php +++ b/mod/quiz/report/overview/overview_options.php @@ -42,6 +42,13 @@ class quiz_overview_options extends mod_quiz_attempts_report_options { /** @var bool whether to show marks for each question (slot). */ public $slotmarks = true; + protected function get_url_params() { + $params = parent::get_url_params(); + $params['regradefilter'] = $this->onlyregraded; + $params['detailedmarks'] = $this->slotmarks; + return $params; + } + public function get_initial_form_data() { $toform = parent::get_initial_form_data(); $toform->regradefilter = $this->onlyregraded; diff --git a/mod/quiz/report/overview/overview_table.php b/mod/quiz/report/overview/overview_table.php index a8b25fab441..8a7909245d1 100644 --- a/mod/quiz/report/overview/overview_table.php +++ b/mod/quiz/report/overview/overview_table.php @@ -38,13 +38,11 @@ class quiz_overview_table extends quiz_attempts_report_table { protected $regradedqs = array(); - public function __construct($quiz, $context, $qmsubselect, $qmfilter, - $attemptsmode, $groupstudents, $students, $detailedmarks, - $questions, $includecheckboxes, $reporturl, $displayoptions) { + public function __construct($quiz, $context, $qmsubselect, + quiz_overview_options $options, $groupstudents, $students, $questions, $reporturl) { parent::__construct('mod-quiz-report-overview-report', $quiz , $context, - $qmsubselect, $qmfilter, $attemptsmode, $groupstudents, $students, - $questions, $includecheckboxes, $reporturl, $displayoptions); - $this->detailedmarks = $detailedmarks; + $qmsubselect, $options, $groupstudents, $students, $questions, $reporturl); + $this->detailedmarks = $options->slotmarks; } public function build_table() { diff --git a/mod/quiz/report/overview/report.php b/mod/quiz/report/overview/report.php index 040d012663f..3870fd2774d 100644 --- a/mod/quiz/report/overview/report.php +++ b/mod/quiz/report/overview/report.php @@ -44,7 +44,7 @@ class quiz_overview_report extends quiz_attempts_report { list($currentgroup, $students, $groupstudents, $allowed) = $this->init('overview', 'quiz_overview_settings_form', $quiz, $cm, $course); - $options = new quiz_overview_options($quiz, $cm, $course); + $options = new quiz_overview_options('overview', $quiz, $cm, $course); if ($fromform = $this->form->get_data()) { $options->process_settings_from_form($fromform); @@ -53,11 +53,6 @@ class quiz_overview_report extends quiz_attempts_report { $options->process_settings_from_params(); } - $displayoptions = array(); - $displayoptions['attemptsmode'] = $options->attempts; - $displayoptions['qmfilter'] = $options->onlygraded; - $displayoptions['regradefilter'] = $options->onlyregraded; - $this->form->set_data($options->get_initial_form_data()); if ($options->attempts == self::ALL_ATTEMPTS) { @@ -74,8 +69,7 @@ class quiz_overview_report extends quiz_attempts_report { $courseshortname = format_string($course->shortname, true, array('context' => context_course::instance($course->id))); $table = new quiz_overview_table($quiz, $this->context, $this->qmsubselect, - $options->onlygraded, $options->attempts, $groupstudents, $students, $options->slotmarks, - $questions, $options->checkboxcolumn, $this->get_base_url(), $displayoptions); + $options, $groupstudents, $students, $questions, $this->get_base_url()); $filename = quiz_report_download_filename(get_string('overviewfilename', 'quiz_overview'), $courseshortname, $quiz->name); $table->is_downloading($options->download, $filename, @@ -90,14 +84,14 @@ class quiz_overview_report extends quiz_attempts_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($this->get_base_url()->out(false, $displayoptions)); + redirect($options->get_url()); } } 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($this->get_base_url()->out(false, $displayoptions)); + redirect($options->get_url()); } } } @@ -108,17 +102,17 @@ class quiz_overview_report extends quiz_attempts_report { if ($regradeall && confirm_sesskey()) { require_capability('mod/quiz:regrade', $this->context); $this->regrade_attempts($quiz, false, $groupstudents); - redirect($this->get_base_url()->out(false, $displayoptions), '', 5); + redirect($options->get_url(), '', 5); } else if ($regradealldry && confirm_sesskey()) { require_capability('mod/quiz:regrade', $this->context); $this->regrade_attempts($quiz, true, $groupstudents); - redirect($this->get_base_url()->out(false, $displayoptions), '', 5); + redirect($options->get_url(), '', 5); } else if ($regradealldrydo && confirm_sesskey()) { require_capability('mod/quiz:regrade', $this->context); $this->regrade_attempts_needing_it($quiz, $groupstudents); - redirect($this->get_base_url()->out(false, $displayoptions), '', 5); + redirect($options->get_url(), '', 5); } // Start output. @@ -130,7 +124,7 @@ class quiz_overview_report extends quiz_attempts_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, $this->get_base_url()->out(true, $displayoptions)); + groups_print_activity_menu($cm, $options->get_url()); } } @@ -212,8 +206,7 @@ class quiz_overview_report extends quiz_attempts_report { $regradealllabel = get_string('regradeall', 'quiz_overview'); } - $displayurl = new moodle_url($this->get_base_url(), - $displayoptions + array('sesskey' => sesskey())); + $displayurl = new moodle_url($options->get_url(), array('sesskey' => sesskey())); echo '
'; echo '
'; echo '
'; @@ -272,8 +265,7 @@ class quiz_overview_report extends quiz_attempts_report { $this->add_grade_columns($quiz, $options->usercanseegrades, $columns, $headers, false); - $this->set_up_table_columns( - $table, $columns, $headers, $this->get_base_url(), $displayoptions, false); + $this->set_up_table_columns($table, $columns, $headers, $this->get_base_url(), $options, false); $table->set_attribute('class', 'generaltable generalbox grades'); $table->out($options->pagesize, true); diff --git a/mod/quiz/report/responses/report.php b/mod/quiz/report/responses/report.php index 439a4a39c76..5401ec1d7ff 100644 --- a/mod/quiz/report/responses/report.php +++ b/mod/quiz/report/responses/report.php @@ -52,7 +52,7 @@ class quiz_responses_report extends quiz_attempts_report { list($currentgroup, $students, $groupstudents, $allowed) = $this->init('responses', 'quiz_responses_settings_form', $quiz, $cm, $course); - $options = new quiz_responses_options($quiz, $cm, $course); + $options = new quiz_responses_options('responses', $quiz, $cm, $course); if ($fromform = $this->form->get_data()) { $options->process_settings_from_form($fromform); @@ -61,13 +61,6 @@ class quiz_responses_report extends quiz_attempts_report { $options->process_settings_from_params(); } - $displayoptions = array(); - $displayoptions['attemptsmode'] = $options->attempts; - $displayoptions['qmfilter'] = $options->onlygraded; - $displayoptions['qtext'] = $options->showqtext; - $displayoptions['resp'] = $options->showresponses; - $displayoptions['right'] = $options->showright; - $this->form->set_data($options->get_initial_form_data()); if ($options->attempts == self::ALL_ATTEMPTS) { @@ -84,8 +77,7 @@ class quiz_responses_report extends quiz_attempts_report { $courseshortname = format_string($course->shortname, true, array('context' => context_course::instance($course->id))); $table = new quiz_responses_table($quiz, $this->context, $this->qmsubselect, - $options->onlygraded, $options->attempts, $groupstudents, $students, - $questions, $options->checkboxcolumn, $this->get_base_url(), $displayoptions); + $options, $groupstudents, $students, $questions, $this->get_base_url()); $filename = quiz_report_download_filename(get_string('responsesfilename', 'quiz_responses'), $courseshortname, $quiz->name); $table->is_downloading($options->download, $filename, @@ -100,7 +92,7 @@ class quiz_responses_report extends quiz_attempts_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($this->get_base_url()->out(false, $displayoptions)); + redirect($options->get_url()); } } } @@ -114,7 +106,7 @@ class quiz_responses_report extends quiz_attempts_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, $this->get_base_url()->out(true, $displayoptions)); + groups_print_activity_menu($cm, $options->get_url()); } } @@ -194,7 +186,7 @@ class quiz_responses_report extends quiz_attempts_report { $table->sortable(true, 'uniqueid'); // Set up the table. - $table->define_baseurl($this->get_base_url()->out(true, $displayoptions)); + $table->define_baseurl($options->get_url()); $this->configure_user_columns($table); diff --git a/mod/quiz/report/responses/responses_options.php b/mod/quiz/report/responses/responses_options.php index 9db643592b0..52a7c966201 100644 --- a/mod/quiz/report/responses/responses_options.php +++ b/mod/quiz/report/responses/responses_options.php @@ -45,6 +45,14 @@ class quiz_responses_options extends mod_quiz_attempts_report_options { /** @var bool whether to show the correct response columns. */ public $showright = false; + protected function get_url_params() { + $params = parent::get_url_params(); + $params['qtext'] = $this->showqtext; + $params['resp'] = $this->showresponses; + $params['right'] = $this->showright; + return $params; + } + public function get_initial_form_data() { $toform = parent::get_initial_form_data(); $toform->qtext = $this->showqtext; diff --git a/mod/quiz/report/responses/responses_table.php b/mod/quiz/report/responses/responses_table.php index b1570b0ce1a..9da4b1aabaf 100644 --- a/mod/quiz/report/responses/responses_table.php +++ b/mod/quiz/report/responses/responses_table.php @@ -36,12 +36,10 @@ require_once($CFG->dirroot . '/mod/quiz/report/attemptsreport_table.php'); */ class quiz_responses_table extends quiz_attempts_report_table { - public function __construct($quiz, $context, $qmsubselect, $qmfilter, - $attemptsmode, $groupstudents, $students, - $questions, $includecheckboxes, $reporturl, $displayoptions) { + public function __construct($quiz, $context, $qmsubselect, quiz_responses_options $options, + $groupstudents, $students, $questions, $reporturl) { parent::__construct('mod-quiz-report-responses-report', $quiz, $context, - $qmsubselect, $qmfilter, $attemptsmode, $groupstudents, $students, - $questions, $includecheckboxes, $reporturl, $displayoptions); + $qmsubselect, $options, $groupstudents, $students, $questions, $reporturl); } public function build_table() {