From 5ca45fddab3c6cc74afe1726c88a78c9096ee924 Mon Sep 17 00:00:00 2001
From: Tim Hunt <T.J.Hunt@open.ac.uk>
Date: Wed, 4 Apr 2012 18:52:23 +0100
Subject: [PATCH] MDL-32322 quiz reports: eliminate more duplication.

---
 mod/quiz/report/attemptsreport_form.php             | 13 +++++++++++++
 mod/quiz/report/overview/overviewsettings_form.php  |  7 +------
 .../report/responses/responsessettings_form.php     |  7 +------
 3 files changed, 15 insertions(+), 12 deletions(-)

diff --git a/mod/quiz/report/attemptsreport_form.php b/mod/quiz/report/attemptsreport_form.php
index 11a6c8f369c..286bd1f04df 100644
--- a/mod/quiz/report/attemptsreport_form.php
+++ b/mod/quiz/report/attemptsreport_form.php
@@ -88,4 +88,17 @@ abstract class mod_quiz_attempt_report_form extends moodleform {
      * @param MoodleQuickForm $mform the form we are building.
      */
     protected abstract function definition_inner(MoodleQuickForm $mform);
+
+    /**
+     * Create the standard checkbox for the 'include highest graded only' option.
+     *
+     * @param MoodleQuickForm $mform the form we are building.
+     */
+    protected function create_qmfilter_checkbox(MoodleQuickForm $mform) {
+        $gm = html_writer::tag('span', quiz_get_grading_option_name(
+                $this->_customdata['quiz']->grademethod), array('class' => 'highlight'));
+        return $mform->createElement('advcheckbox', 'qmfilter',
+                get_string('showattempts', 'quiz_overview'),
+                get_string('optonlygradedattempts', 'quiz_overview', $gm), null, array(0, 1));
+    }
 }
diff --git a/mod/quiz/report/overview/overviewsettings_form.php b/mod/quiz/report/overview/overviewsettings_form.php
index 5c45048ca85..6c2638ab65e 100644
--- a/mod/quiz/report/overview/overviewsettings_form.php
+++ b/mod/quiz/report/overview/overviewsettings_form.php
@@ -38,12 +38,7 @@ class quiz_overview_settings_form extends mod_quiz_attempt_report_form {
     protected function definition_inner(MoodleQuickForm $mform) {
         $showattemptsgrp = array();
         if ($this->_customdata['qmsubselect']) {
-            $gm = '<span class="highlight">' .
-                    quiz_get_grading_option_name($this->_customdata['quiz']->grademethod) .
-                    '</span>';
-            $showattemptsgrp[] = $mform->createElement('advcheckbox', 'qmfilter',
-                    get_string('showattempts', 'quiz_overview'),
-                    get_string('optonlygradedattempts', 'quiz_overview', $gm), null, array(0, 1));
+            $showattemptsgrp[] = $this->create_qmfilter_checkbox($mform);
         }
         if (has_capability('mod/quiz:regrade', $this->_customdata['context'])) {
             $showattemptsgrp[] = $mform->createElement('advcheckbox', 'regradefilter',
diff --git a/mod/quiz/report/responses/responsessettings_form.php b/mod/quiz/report/responses/responsessettings_form.php
index f30878b9319..80746fc7928 100644
--- a/mod/quiz/report/responses/responsessettings_form.php
+++ b/mod/quiz/report/responses/responsessettings_form.php
@@ -37,12 +37,7 @@ require_once($CFG->dirroot . '/mod/quiz/report/attemptsreport_form.php');
 class quiz_responses_settings_form extends mod_quiz_attempt_report_form {
     protected function definition_inner(MoodleQuickForm $mform) {
         if ($this->_customdata['qmsubselect']) {
-            $gm = '<span class="highlight">' .
-                    quiz_get_grading_option_name($this->_customdata['quiz']->grademethod) .
-                    '</span>';
-            $mform->addElement('advcheckbox', 'qmfilter',
-                    get_string('showattempts', 'quiz_overview'),
-                    get_string('optonlygradedattempts', 'quiz_overview', $gm), null, array(0, 1));
+            $mform->addElement($this->create_qmfilter_checkbox($mform));
         }
 
         $colsgroup = array();