MDL-32322 quiz reports: refactor the settings forms to eliminate duplication.

This commit is contained in:
Tim Hunt 2012-04-04 18:29:39 +01:00
parent 4747c788c0
commit 2639a68ad5
3 changed files with 97 additions and 92 deletions

View File

@ -0,0 +1,91 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Base class for the settings form for {@link quiz_attempt_report}s.
*
* @package mod_quiz
* @copyright 2012 The Open University
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die();
require_once($CFG->libdir . '/formslib.php');
/**
* Base class for the settings form for {@link quiz_attempt_report}s.
*
* @copyright 2012 The Open University
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
abstract class mod_quiz_attempt_report_form extends moodleform {
protected function definition() {
$mform = $this->_form;
$mform->addElement('header', 'preferencespage',
get_string('preferencespage', 'quiz_overview'));
if (!$this->_customdata['currentgroup']) {
$studentsstring = get_string('participants');
} else {
$a = new stdClass();
$a->coursestudent = get_string('participants');
$a->groupname = groups_get_group_name($this->_customdata['currentgroup']);
if (20 < strlen($a->groupname)) {
$studentsstring = get_string('studentingrouplong', 'quiz_overview', $a);
} else {
$studentsstring = get_string('studentingroup', 'quiz_overview', $a);
}
}
$options = array();
if (!$this->_customdata['currentgroup']) {
$options[QUIZ_REPORT_ATTEMPTS_ALL] = get_string('optallattempts', 'quiz_overview');
}
if ($this->_customdata['currentgroup'] ||
!is_inside_frontpage($this->_customdata['context'])) {
$options[QUIZ_REPORT_ATTEMPTS_ALL_STUDENTS] =
get_string('optallstudents', 'quiz_overview', $studentsstring);
$options[QUIZ_REPORT_ATTEMPTS_STUDENTS_WITH] =
get_string('optattemptsonly', 'quiz_overview', $studentsstring);
$options[QUIZ_REPORT_ATTEMPTS_STUDENTS_WITH_NO] =
get_string('optnoattemptsonly', 'quiz_overview', $studentsstring);
}
$mform->addElement('select', 'attemptsmode',
get_string('show', 'quiz_overview'), $options);
$this->definition_inner($mform);
$mform->addElement('header', 'preferencesuser',
get_string('preferencesuser', 'quiz_overview'));
$mform->addElement('text', 'pagesize', get_string('pagesize', 'quiz_overview'));
$mform->setType('pagesize', PARAM_INT);
$mform->addElement('submit', 'submitbutton',
get_string('preferencessave', 'quiz_overview'));
}
/**
* Add any report-specific options to the form.
*
* @param MoodleQuickForm $mform the form we are building.
*/
protected abstract function definition_inner(MoodleQuickForm $mform);
}

View File

@ -25,7 +25,7 @@
defined('MOODLE_INTERNAL') || die();
require_once($CFG->libdir . '/formslib.php');
require_once($CFG->dirroot . '/mod/quiz/report/attemptsreport_form.php');
/**
@ -34,42 +34,8 @@ require_once($CFG->libdir . '/formslib.php');
* @copyright 2008 Jamie Pratt
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class quiz_overview_settings_form extends moodleform {
protected function definition() {
$mform = $this->_form;
$mform->addElement('header', 'preferencespage',
get_string('preferencespage', 'quiz_overview'));
if (!$this->_customdata['currentgroup']) {
$studentsstring = get_string('participants');
} else {
$a = new stdClass();
$a->coursestudent = get_string('participants');
$a->groupname = groups_get_group_name($this->_customdata['currentgroup']);
if (20 < strlen($a->groupname)) {
$studentsstring = get_string('studentingrouplong', 'quiz_overview', $a);
} else {
$studentsstring = get_string('studentingroup', 'quiz_overview', $a);
}
}
$options = array();
if (!$this->_customdata['currentgroup']) {
$options[QUIZ_REPORT_ATTEMPTS_ALL] = get_string('optallattempts', 'quiz_overview');
}
if ($this->_customdata['currentgroup'] ||
!is_inside_frontpage($this->_customdata['context'])) {
$options[QUIZ_REPORT_ATTEMPTS_ALL_STUDENTS] =
get_string('optallstudents', 'quiz_overview', $studentsstring);
$options[QUIZ_REPORT_ATTEMPTS_STUDENTS_WITH] =
get_string('optattemptsonly', 'quiz_overview', $studentsstring);
$options[QUIZ_REPORT_ATTEMPTS_STUDENTS_WITH_NO] =
get_string('optnoattemptsonly', 'quiz_overview', $studentsstring);
}
$mform->addElement('select', 'attemptsmode',
get_string('show', 'quiz_overview'), $options);
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">' .
@ -89,16 +55,7 @@ class quiz_overview_settings_form extends moodleform {
get_string('showattempts', 'quiz_overview'), '<br />', false);
}
$mform->addElement('header', 'preferencesuser',
get_string('preferencesuser', 'quiz_overview'));
$mform->addElement('text', 'pagesize', get_string('pagesize', 'quiz_overview'));
$mform->setType('pagesize', PARAM_INT);
$mform->addElement('selectyesno', 'detailedmarks',
get_string('showdetailedmarks', 'quiz_overview'));
$mform->addElement('submit', 'submitbutton',
get_string('preferencessave', 'quiz_overview'));
}
}

View File

@ -25,7 +25,7 @@
defined('MOODLE_INTERNAL') || die();
require_once($CFG->libdir . '/formslib.php');
require_once($CFG->dirroot . '/mod/quiz/report/attemptsreport_form.php');
/**
@ -34,42 +34,8 @@ require_once($CFG->libdir . '/formslib.php');
* @copyright 2008 Jean-Michel Vedrine
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class quiz_responses_settings_form extends moodleform {
protected function definition() {
$mform = $this->_form;
$mform->addElement('header', 'preferencespage',
get_string('preferencespage', 'quiz_overview'));
if (!$this->_customdata['currentgroup']) {
$studentsstring = get_string('participants');
} else {
$a = new stdClass();
$a->coursestudent = get_string('participants');
$a->groupname = groups_get_group_name($this->_customdata['currentgroup']);
if (20 < strlen($a->groupname)) {
$studentsstring = get_string('studentingrouplong', 'quiz_overview', $a);
} else {
$studentsstring = get_string('studentingroup', 'quiz_overview', $a);
}
}
$options = array();
if (!$this->_customdata['currentgroup']) {
$options[QUIZ_REPORT_ATTEMPTS_ALL] = get_string('optallattempts', 'quiz_overview');
}
if ($this->_customdata['currentgroup'] ||
!is_inside_frontpage($this->_customdata['context'])) {
$options[QUIZ_REPORT_ATTEMPTS_ALL_STUDENTS] =
get_string('optallstudents', 'quiz_overview', $studentsstring);
$options[QUIZ_REPORT_ATTEMPTS_STUDENTS_WITH] =
get_string('optattemptsonly', 'quiz_overview', $studentsstring);
$options[QUIZ_REPORT_ATTEMPTS_STUDENTS_WITH_NO] =
get_string('optnoattemptsonly', 'quiz_overview', $studentsstring);
}
$mform->addElement('select', 'attemptsmode',
get_string('show', 'quiz_overview'), $options);
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) .
@ -88,14 +54,5 @@ class quiz_responses_settings_form extends moodleform {
get_string('summaryofrightanswer', 'quiz_responses'));
$mform->addGroup($colsgroup, null,
get_string('include', 'quiz_responses'), '<br />', false);
$mform->addElement('header', 'preferencesuser',
get_string('preferencesuser', 'quiz_overview'));
$mform->addElement('text', 'pagesize', get_string('pagesize', 'quiz_overview'));
$mform->setType('pagesize', PARAM_INT);
$mform->addElement('submit', 'submitbutton',
get_string('preferencessave', 'quiz_overview'));
}
}