MDL-32322 quiz_reports: move some more options into the options class.

This commit is contained in:
Tim Hunt 2012-04-05 17:25:35 +01:00
parent ac4d91575a
commit 9e67e357eb
6 changed files with 36 additions and 35 deletions

View File

@ -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);

View File

@ -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);
}
/**

View File

@ -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);
}
}

View File

@ -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;

View File

@ -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) {

View File

@ -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);
}
}