From 9e67e357eb12ee537c53712ccc5cf35a9f179505 Mon Sep 17 00:00:00 2001 From: Tim Hunt Date: Thu, 5 Apr 2012 17:25:35 +0100 Subject: [PATCH] MDL-32322 quiz_reports: move some more options into the options class. --- mod/quiz/report/attemptsreport.php | 5 ++-- mod/quiz/report/attemptsreport_options.php | 26 +++++++++---------- mod/quiz/report/overview/overview_options.php | 8 +++++- mod/quiz/report/overview/report.php | 14 +++------- mod/quiz/report/responses/report.php | 13 +++------- .../report/responses/responses_options.php | 5 ++++ 6 files changed, 36 insertions(+), 35 deletions(-) diff --git a/mod/quiz/report/attemptsreport.php b/mod/quiz/report/attemptsreport.php index b4854c2c5a7..7900117ab6a 100644 --- a/mod/quiz/report/attemptsreport.php +++ b/mod/quiz/report/attemptsreport.php @@ -218,12 +218,13 @@ abstract class quiz_attempts_report extends quiz_default_report { * Add all the grade and feedback columns, if applicable, to the $columns * and $headers arrays. * @param object $quiz the quiz settings. + * @param bool $usercanseegrades whether the user is allowed to see grades for this quiz. * @param array $columns the list of columns. Added to. * @param array $headers the columns headings. Added to. * @param bool $includefeedback whether to include the feedbacktext columns */ - protected function add_grade_columns($quiz, &$columns, &$headers, $includefeedback = true) { - if (quiz_report_should_show_grades($quiz)) { + protected function add_grade_columns($quiz, $usercanseegrades, &$columns, &$headers, $includefeedback = true) { + if ($usercanseegrades) { $columns[] = 'sumgrades'; $headers[] = get_string('grade', 'quiz') . '/' . quiz_format_grade($quiz, $quiz->grade); diff --git a/mod/quiz/report/attemptsreport_options.php b/mod/quiz/report/attemptsreport_options.php index ca105542889..212357bd812 100644 --- a/mod/quiz/report/attemptsreport_options.php +++ b/mod/quiz/report/attemptsreport_options.php @@ -45,32 +45,30 @@ class mod_quiz_attempts_report_options { /** @var object the course settings for the course the quiz is in. */ public $course; - /** - * @var string quiz_attempts_report:: constants. - */ + /** @var string quiz_attempts_report:: constants. */ public $attempts = quiz_attempts_report::STUDENTS_WITH; - /** - * @var int the currently selected group. 0 if no group is selected. - */ + /** @var int the currently selected group. 0 if no group is selected. */ public $group = 0; /** - * @var bool wether to show all finished attmepts, or just the one that gave + * @var bool whether to show all finished attmepts, or just the one that gave * the final grade for the user. */ public $onlygraded = false; - /** - * @var int Number of attempts to show per page. - */ + /** @var int Number of attempts to show per page. */ public $pagesize = quiz_attempts_report::DEFAULT_PAGE_SIZE; - /** - * @var string whether the data should be downloaded in some format, or '' to display it. - */ + /** @var string whether the data should be downloaded in some format, or '' to display it. */ public $download = ''; + /** @var bool whether the current user has permission to see grades. */ + public $usercanseegrades; + + /** @var bool whether the report table should have a column of checkboxes. */ + public $checkboxcolumn = false; + /** * Constructor. * @param object $quiz the settings for the quiz being reported on. @@ -80,6 +78,8 @@ class mod_quiz_attempts_report_options { $this->quiz = $quiz; $this->cm = $cm; $this->course = $course; + + $this->usercanseegrades = quiz_report_should_show_grades($quiz); } /** diff --git a/mod/quiz/report/overview/overview_options.php b/mod/quiz/report/overview/overview_options.php index 9a861af418d..bb75c3442fb 100644 --- a/mod/quiz/report/overview/overview_options.php +++ b/mod/quiz/report/overview/overview_options.php @@ -79,8 +79,14 @@ class quiz_overview_options extends mod_quiz_attempts_report_options { public function resolve_dependencies() { parent::resolve_dependencies(); - if (!quiz_report_should_show_grades($this->quiz)) { + if (!$this->usercanseegrades) { $this->slotmarks = false; } + + // We only want to show the checkbox to delete attempts + // if the user has permissions and if the report mode is showing attempts. + $this->checkboxcolumn = has_any_capability( + array('mod/quiz:regrade', 'mod/quiz:deleteattempts'), context_module::instance($this->cm->id)) + && ($this->attempts != quiz_attempts_report::STUDENTS_WITH_NO); } } diff --git a/mod/quiz/report/overview/report.php b/mod/quiz/report/overview/report.php index fb1c2e1ec8f..040d012663f 100644 --- a/mod/quiz/report/overview/report.php +++ b/mod/quiz/report/overview/report.php @@ -60,12 +60,6 @@ class quiz_overview_report extends quiz_attempts_report { $this->form->set_data($options->get_initial_form_data()); - // We only want to show the checkbox to delete attempts - // if the user has permissions and if the report mode is showing attempts. - $includecheckboxes = has_any_capability( - array('mod/quiz:regrade', 'mod/quiz:deleteattempts'), $this->context) - && ($options->attempts != self::STUDENTS_WITH_NO); - if ($options->attempts == self::ALL_ATTEMPTS) { // This option is only available to users who can access all groups in // groups mode, so setting allowed to empty (which means all quiz attempts @@ -81,7 +75,7 @@ class quiz_overview_report extends quiz_attempts_report { 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, $includecheckboxes, $this->get_base_url(), $displayoptions); + $questions, $options->checkboxcolumn, $this->get_base_url(), $displayoptions); $filename = quiz_report_download_filename(get_string('overviewfilename', 'quiz_overview'), $courseshortname, $quiz->name); $table->is_downloading($options->download, $filename, @@ -246,7 +240,7 @@ class quiz_overview_report extends quiz_attempts_report { $columns = array(); $headers = array(); - if (!$table->is_downloading() && $includecheckboxes) { + if (!$table->is_downloading() && $options->checkboxcolumn) { $columns[] = 'checkbox'; $headers[] = null; } @@ -276,7 +270,7 @@ class quiz_overview_report extends quiz_attempts_report { $headers[] = get_string('regrade', 'quiz_overview'); } - $this->add_grade_columns($quiz, $columns, $headers, false); + $this->add_grade_columns($quiz, $options->usercanseegrades, $columns, $headers, false); $this->set_up_table_columns( $table, $columns, $headers, $this->get_base_url(), $displayoptions, false); @@ -285,7 +279,7 @@ class quiz_overview_report extends quiz_attempts_report { $table->out($options->pagesize, true); } - if (!$table->is_downloading() && quiz_report_should_show_grades($quiz)) { + if (!$table->is_downloading() && $options->usercanseegrades) { if ($currentgroup && $groupstudents) { list($usql, $params) = $DB->get_in_or_equal($groupstudents); $params[] = $quiz->id; diff --git a/mod/quiz/report/responses/report.php b/mod/quiz/report/responses/report.php index 329e81c5a36..439a4a39c76 100644 --- a/mod/quiz/report/responses/report.php +++ b/mod/quiz/report/responses/report.php @@ -70,11 +70,6 @@ class quiz_responses_report extends quiz_attempts_report { $this->form->set_data($options->get_initial_form_data()); - // We only want to show the checkbox to delete attempts - // if the user has permissions and if the report mode is showing attempts. - $includecheckboxes = has_capability('mod/quiz:deleteattempts', $this->context) - && ($options->attempts != self::STUDENTS_WITH_NO); - if ($options->attempts == self::ALL_ATTEMPTS) { // This option is only available to users who can access all groups in // groups mode, so setting allowed to empty (which means all quiz attempts @@ -90,10 +85,10 @@ class quiz_responses_report extends quiz_attempts_report { array('context' => context_course::instance($course->id))); $table = new quiz_responses_table($quiz, $this->context, $this->qmsubselect, $options->onlygraded, $options->attempts, $groupstudents, $students, - $questions, $includecheckboxes, $this->get_base_url(), $displayoptions); + $questions, $options->checkboxcolumn, $this->get_base_url(), $displayoptions); $filename = quiz_report_download_filename(get_string('responsesfilename', 'quiz_responses'), $courseshortname, $quiz->name); - $table->is_downloading(optional_param('download', '', PARAM_ALPHA), $filename, + $table->is_downloading($options->download, $filename, $courseshortname . ' ' . format_string($quiz->name, true)); if ($table->is_downloading()) { raise_memory_limit(MEMORY_EXTRA); @@ -166,7 +161,7 @@ class quiz_responses_report extends quiz_attempts_report { $columns = array(); $headers = array(); - if (!$table->is_downloading() && $includecheckboxes) { + if (!$table->is_downloading() && $options->checkboxcolumn) { $columns[] = 'checkbox'; $headers[] = null; } @@ -177,7 +172,7 @@ class quiz_responses_report extends quiz_attempts_report { $this->add_time_columns($columns, $headers); } - $this->add_grade_columns($quiz, $columns, $headers); + $this->add_grade_columns($quiz, $options->usercanseegrades, $columns, $headers); foreach ($questions as $id => $question) { if ($options->showqtext) { diff --git a/mod/quiz/report/responses/responses_options.php b/mod/quiz/report/responses/responses_options.php index 406b3bbc9ef..9db643592b0 100644 --- a/mod/quiz/report/responses/responses_options.php +++ b/mod/quiz/report/responses/responses_options.php @@ -93,5 +93,10 @@ class quiz_responses_options extends mod_quiz_attempts_report_options { // We have to show at least something. $this->showresponses = true; } + + // We only want to show the checkbox to delete attempts + // if the user has permissions and if the report mode is showing attempts. + $this->checkboxcolumn = has_capability('mod/quiz:deleteattempts', context_module::instance($this->cm->id)) + && ($this->attempts != quiz_attempts_report::STUDENTS_WITH_NO); } }