1
0
mirror of https://github.com/moodle/moodle.git synced 2025-03-06 00:39:54 +01:00

MDL-32322 quiz reports: pass options object -> table, not separate args.

This commit is contained in:
Tim Hunt 2012-04-05 18:01:04 +01:00
parent 9e67e357eb
commit e97d60adce
9 changed files with 72 additions and 53 deletions

@ -242,16 +242,16 @@ abstract class quiz_attempts_report extends quiz_default_report {
* @param array $columns the list of columns. * @param array $columns the list of columns.
* @param array $headers the columns headings. * @param array $headers the columns headings.
* @param moodle_url $reporturl the URL of this report. * @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. * @param bool $collapsible whether to allow columns in the report to be collapsed.
*/ */
protected function set_up_table_columns($table, $columns, $headers, $reporturl, 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_columns($columns);
$table->define_headers($headers); $table->define_headers($headers);
$table->sortable(true, 'uniqueid'); $table->sortable(true, 'uniqueid');
$table->define_baseurl($reporturl->out(false, $displayoptions)); $table->define_baseurl($options->get_url());
$this->configure_user_columns($table); $this->configure_user_columns($table);

@ -36,6 +36,9 @@ require_once($CFG->libdir . '/formslib.php');
*/ */
class mod_quiz_attempts_report_options { class mod_quiz_attempts_report_options {
/** @var string the report mode. */
public $mode;
/** @var object the settings for the quiz being reported on. */ /** @var object the settings for the quiz being reported on. */
public $quiz; 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 $quiz the settings for the quiz being reported on.
* @param object $cm the course module objects 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->quiz = $quiz;
$this->cm = $cm; $this->cm = $cm;
$this->course = $course; $this->course = $course;
@ -82,6 +86,25 @@ class mod_quiz_attempts_report_options {
$this->usercanseegrades = quiz_report_should_show_grades($quiz); $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 * Process the data we get when the settings form is submitted. This includes
* updating the fields of this class, and updating the user preferences * updating the fields of this class, and updating the user preferences

@ -52,6 +52,7 @@ abstract class quiz_attempts_report_table extends table_sql {
protected $quiz; protected $quiz;
protected $context; protected $context;
protected $qmsubselect; protected $qmsubselect;
protected $options;
protected $qmfilter; protected $qmfilter;
protected $attemptsmode; protected $attemptsmode;
protected $groupstudents; protected $groupstudents;
@ -59,21 +60,21 @@ abstract class quiz_attempts_report_table extends table_sql {
protected $questions; protected $questions;
protected $includecheckboxes; protected $includecheckboxes;
public function __construct($uniqueid, $quiz, $context, $qmsubselect, $qmfilter, public function __construct($uniqueid, $quiz, $context, $qmsubselect,
$attemptsmode, $groupstudents, $students, $questions, $includecheckboxes, mod_quiz_attempts_report_options $options, $groupstudents, $students,
$reporturl, $displayoptions) { $questions, $reporturl) {
parent::__construct($uniqueid); parent::__construct($uniqueid);
$this->quiz = $quiz; $this->quiz = $quiz;
$this->context = $context; $this->context = $context;
$this->qmsubselect = $qmsubselect; $this->qmsubselect = $qmsubselect;
$this->qmfilter = $qmfilter; $this->qmfilter = $options->onlygraded;
$this->attemptsmode = $attemptsmode; $this->attemptsmode = $options->attempts;
$this->groupstudents = $groupstudents; $this->groupstudents = $groupstudents;
$this->students = $students; $this->students = $students;
$this->questions = $questions; $this->questions = $questions;
$this->includecheckboxes = $includecheckboxes; $this->includecheckboxes = $options->checkboxcolumn;
$this->reporturl = $reporturl; $this->reporturl = $reporturl;
$this->displayoptions = $displayoptions; $this->options = $options;
} }
public function col_checkbox($attempt) { public function col_checkbox($attempt) {

@ -42,6 +42,13 @@ class quiz_overview_options extends mod_quiz_attempts_report_options {
/** @var bool whether to show marks for each question (slot). */ /** @var bool whether to show marks for each question (slot). */
public $slotmarks = true; 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() { public function get_initial_form_data() {
$toform = parent::get_initial_form_data(); $toform = parent::get_initial_form_data();
$toform->regradefilter = $this->onlyregraded; $toform->regradefilter = $this->onlyregraded;

@ -38,13 +38,11 @@ class quiz_overview_table extends quiz_attempts_report_table {
protected $regradedqs = array(); protected $regradedqs = array();
public function __construct($quiz, $context, $qmsubselect, $qmfilter, public function __construct($quiz, $context, $qmsubselect,
$attemptsmode, $groupstudents, $students, $detailedmarks, quiz_overview_options $options, $groupstudents, $students, $questions, $reporturl) {
$questions, $includecheckboxes, $reporturl, $displayoptions) {
parent::__construct('mod-quiz-report-overview-report', $quiz , $context, parent::__construct('mod-quiz-report-overview-report', $quiz , $context,
$qmsubselect, $qmfilter, $attemptsmode, $groupstudents, $students, $qmsubselect, $options, $groupstudents, $students, $questions, $reporturl);
$questions, $includecheckboxes, $reporturl, $displayoptions); $this->detailedmarks = $options->slotmarks;
$this->detailedmarks = $detailedmarks;
} }
public function build_table() { public function build_table() {

@ -44,7 +44,7 @@ class quiz_overview_report extends quiz_attempts_report {
list($currentgroup, $students, $groupstudents, $allowed) = list($currentgroup, $students, $groupstudents, $allowed) =
$this->init('overview', 'quiz_overview_settings_form', $quiz, $cm, $course); $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()) { if ($fromform = $this->form->get_data()) {
$options->process_settings_from_form($fromform); $options->process_settings_from_form($fromform);
@ -53,11 +53,6 @@ class quiz_overview_report extends quiz_attempts_report {
$options->process_settings_from_params(); $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()); $this->form->set_data($options->get_initial_form_data());
if ($options->attempts == self::ALL_ATTEMPTS) { if ($options->attempts == self::ALL_ATTEMPTS) {
@ -74,8 +69,7 @@ class quiz_overview_report extends quiz_attempts_report {
$courseshortname = format_string($course->shortname, true, $courseshortname = format_string($course->shortname, true,
array('context' => context_course::instance($course->id))); array('context' => context_course::instance($course->id)));
$table = new quiz_overview_table($quiz, $this->context, $this->qmsubselect, $table = new quiz_overview_table($quiz, $this->context, $this->qmsubselect,
$options->onlygraded, $options->attempts, $groupstudents, $students, $options->slotmarks, $options, $groupstudents, $students, $questions, $this->get_base_url());
$questions, $options->checkboxcolumn, $this->get_base_url(), $displayoptions);
$filename = quiz_report_download_filename(get_string('overviewfilename', 'quiz_overview'), $filename = quiz_report_download_filename(get_string('overviewfilename', 'quiz_overview'),
$courseshortname, $quiz->name); $courseshortname, $quiz->name);
$table->is_downloading($options->download, $filename, $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)) { if ($attemptids = optional_param_array('attemptid', array(), PARAM_INT)) {
require_capability('mod/quiz:deleteattempts', $this->context); require_capability('mod/quiz:deleteattempts', $this->context);
$this->delete_selected_attempts($quiz, $cm, $attemptids, $allowed); $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()) { } else if (optional_param('regrade', 0, PARAM_BOOL) && confirm_sesskey()) {
if ($attemptids = optional_param_array('attemptid', array(), PARAM_INT)) { if ($attemptids = optional_param_array('attemptid', array(), PARAM_INT)) {
require_capability('mod/quiz:regrade', $this->context); require_capability('mod/quiz:regrade', $this->context);
$this->regrade_attempts($quiz, false, $groupstudents, $attemptids); $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()) { if ($regradeall && confirm_sesskey()) {
require_capability('mod/quiz:regrade', $this->context); require_capability('mod/quiz:regrade', $this->context);
$this->regrade_attempts($quiz, false, $groupstudents); $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()) { } else if ($regradealldry && confirm_sesskey()) {
require_capability('mod/quiz:regrade', $this->context); require_capability('mod/quiz:regrade', $this->context);
$this->regrade_attempts($quiz, true, $groupstudents); $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()) { } else if ($regradealldrydo && confirm_sesskey()) {
require_capability('mod/quiz:regrade', $this->context); require_capability('mod/quiz:regrade', $this->context);
$this->regrade_attempts_needing_it($quiz, $groupstudents); $this->regrade_attempts_needing_it($quiz, $groupstudents);
redirect($this->get_base_url()->out(false, $displayoptions), '', 5); redirect($options->get_url(), '', 5);
} }
// Start output. // Start output.
@ -130,7 +124,7 @@ class quiz_overview_report extends quiz_attempts_report {
if ($groupmode = groups_get_activity_groupmode($cm)) { if ($groupmode = groups_get_activity_groupmode($cm)) {
// Groups are being used, so output the group selector if we are not downloading. // Groups are being used, so output the group selector if we are not downloading.
if (!$table->is_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 = $regradealllabel =
get_string('regradeall', 'quiz_overview'); get_string('regradeall', 'quiz_overview');
} }
$displayurl = new moodle_url($this->get_base_url(), $displayurl = new moodle_url($options->get_url(), array('sesskey' => sesskey()));
$displayoptions + array('sesskey' => sesskey()));
echo '<div class="mdl-align">'; echo '<div class="mdl-align">';
echo '<form action="'.$displayurl->out_omit_querystring().'">'; echo '<form action="'.$displayurl->out_omit_querystring().'">';
echo '<div>'; echo '<div>';
@ -272,8 +265,7 @@ class quiz_overview_report extends quiz_attempts_report {
$this->add_grade_columns($quiz, $options->usercanseegrades, $columns, $headers, false); $this->add_grade_columns($quiz, $options->usercanseegrades, $columns, $headers, false);
$this->set_up_table_columns( $this->set_up_table_columns($table, $columns, $headers, $this->get_base_url(), $options, false);
$table, $columns, $headers, $this->get_base_url(), $displayoptions, false);
$table->set_attribute('class', 'generaltable generalbox grades'); $table->set_attribute('class', 'generaltable generalbox grades');
$table->out($options->pagesize, true); $table->out($options->pagesize, true);

@ -52,7 +52,7 @@ class quiz_responses_report extends quiz_attempts_report {
list($currentgroup, $students, $groupstudents, $allowed) = list($currentgroup, $students, $groupstudents, $allowed) =
$this->init('responses', 'quiz_responses_settings_form', $quiz, $cm, $course); $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()) { if ($fromform = $this->form->get_data()) {
$options->process_settings_from_form($fromform); $options->process_settings_from_form($fromform);
@ -61,13 +61,6 @@ class quiz_responses_report extends quiz_attempts_report {
$options->process_settings_from_params(); $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()); $this->form->set_data($options->get_initial_form_data());
if ($options->attempts == self::ALL_ATTEMPTS) { if ($options->attempts == self::ALL_ATTEMPTS) {
@ -84,8 +77,7 @@ class quiz_responses_report extends quiz_attempts_report {
$courseshortname = format_string($course->shortname, true, $courseshortname = format_string($course->shortname, true,
array('context' => context_course::instance($course->id))); array('context' => context_course::instance($course->id)));
$table = new quiz_responses_table($quiz, $this->context, $this->qmsubselect, $table = new quiz_responses_table($quiz, $this->context, $this->qmsubselect,
$options->onlygraded, $options->attempts, $groupstudents, $students, $options, $groupstudents, $students, $questions, $this->get_base_url());
$questions, $options->checkboxcolumn, $this->get_base_url(), $displayoptions);
$filename = quiz_report_download_filename(get_string('responsesfilename', 'quiz_responses'), $filename = quiz_report_download_filename(get_string('responsesfilename', 'quiz_responses'),
$courseshortname, $quiz->name); $courseshortname, $quiz->name);
$table->is_downloading($options->download, $filename, $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)) { if ($attemptids = optional_param_array('attemptid', array(), PARAM_INT)) {
require_capability('mod/quiz:deleteattempts', $this->context); require_capability('mod/quiz:deleteattempts', $this->context);
$this->delete_selected_attempts($quiz, $cm, $attemptids, $allowed); $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)) { if ($groupmode = groups_get_activity_groupmode($cm)) {
// Groups are being used, so output the group selector if we are not downloading. // Groups are being used, so output the group selector if we are not downloading.
if (!$table->is_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'); $table->sortable(true, 'uniqueid');
// Set up the table. // 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); $this->configure_user_columns($table);

@ -45,6 +45,14 @@ class quiz_responses_options extends mod_quiz_attempts_report_options {
/** @var bool whether to show the correct response columns. */ /** @var bool whether to show the correct response columns. */
public $showright = false; 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() { public function get_initial_form_data() {
$toform = parent::get_initial_form_data(); $toform = parent::get_initial_form_data();
$toform->qtext = $this->showqtext; $toform->qtext = $this->showqtext;

@ -36,12 +36,10 @@ require_once($CFG->dirroot . '/mod/quiz/report/attemptsreport_table.php');
*/ */
class quiz_responses_table extends quiz_attempts_report_table { class quiz_responses_table extends quiz_attempts_report_table {
public function __construct($quiz, $context, $qmsubselect, $qmfilter, public function __construct($quiz, $context, $qmsubselect, quiz_responses_options $options,
$attemptsmode, $groupstudents, $students, $groupstudents, $students, $questions, $reporturl) {
$questions, $includecheckboxes, $reporturl, $displayoptions) {
parent::__construct('mod-quiz-report-responses-report', $quiz, $context, parent::__construct('mod-quiz-report-responses-report', $quiz, $context,
$qmsubselect, $qmfilter, $attemptsmode, $groupstudents, $students, $qmsubselect, $options, $groupstudents, $students, $questions, $reporturl);
$questions, $includecheckboxes, $reporturl, $displayoptions);
} }
public function build_table() { public function build_table() {