mirror of
https://github.com/moodle/moodle.git
synced 2025-04-19 07:25:30 +02:00
MDL-60607 quiz reports: move duplicate code to superclass method
This commit is contained in:
parent
40f1801c4b
commit
eefa2c88e0
@ -138,6 +138,46 @@ abstract class quiz_attempts_report extends quiz_default_report {
|
||||
return array($currentgroup, $studentsjoins, $groupstudentsjoins, $groupstudentsjoins);
|
||||
}
|
||||
|
||||
/**
|
||||
* Outputs the things you commonly want at the top of a quiz report.
|
||||
*
|
||||
* Calls through to {@link print_header_and_tabs()} and then
|
||||
* outputs the standard group selector, number of attempts summary,
|
||||
* and messages to cover common cases when the report can't be shown.
|
||||
*
|
||||
* @param stdClass $cm the course_module information.
|
||||
* @param stdClass $coures the course settings.
|
||||
* @param stdClass $quiz the quiz settings.
|
||||
* @param mod_quiz_attempts_report_options $options the current report settings.
|
||||
* @param int $currentgroup the current group.
|
||||
* @param bool $hasquestions whether there are any questions in the quiz.
|
||||
* @param bool $hasstudents whether there are any relevant students.
|
||||
*/
|
||||
protected function print_standard_header_and_messages($cm, $course, $quiz,
|
||||
$options, $currentgroup, $hasquestions, $hasstudents) {
|
||||
global $OUTPUT;
|
||||
|
||||
$this->print_header_and_tabs($cm, $course, $quiz, $this->mode);
|
||||
|
||||
if (groups_get_activity_groupmode($cm)) {
|
||||
// Groups are being used, so output the group selector if we are not downloading.
|
||||
groups_print_activity_menu($cm, $options->get_url());
|
||||
}
|
||||
|
||||
// Print information on the number of existing attempts.
|
||||
if ($strattemptnum = quiz_num_attempt_summary($quiz, $cm, true, $currentgroup)) {
|
||||
echo '<div class="quizattemptcounts">' . $strattemptnum . '</div>';
|
||||
}
|
||||
|
||||
if (!$hasquestions) {
|
||||
echo quiz_no_questions_message($quiz, $cm, $this->context);
|
||||
} else if (!$hasstudents) {
|
||||
echo $OUTPUT->notification(get_string('nostudentsyet'));
|
||||
} else if ($currentgroup && !$this->hasgroupstudents) {
|
||||
echo $OUTPUT->notification(get_string('nostudentsingroup'));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Add all the user-related columns to the $columns and $headers arrays.
|
||||
* @param table_sql $table the table being constructed.
|
||||
|
@ -98,36 +98,13 @@ class quiz_overview_report extends quiz_attempts_report {
|
||||
$this->course = $course; // Hack to make this available in process_actions.
|
||||
$this->process_actions($quiz, $cm, $currentgroup, $groupstudentsjoins, $allowedjoins, $options->get_url());
|
||||
|
||||
$hasquestions = quiz_has_questions($quiz->id);
|
||||
|
||||
// Start output.
|
||||
if (!$table->is_downloading()) {
|
||||
// Only print headers if not asked to download data.
|
||||
$this->print_header_and_tabs($cm, $course, $quiz, $this->mode);
|
||||
}
|
||||
|
||||
if ($groupmode = groups_get_activity_groupmode($cm)) {
|
||||
// Groups are being used, so output the group selector if we are not downloading.
|
||||
if (!$table->is_downloading()) {
|
||||
groups_print_activity_menu($cm, $options->get_url());
|
||||
}
|
||||
}
|
||||
|
||||
// Print information on the number of existing attempts.
|
||||
if (!$table->is_downloading()) {
|
||||
// Do not print notices when downloading.
|
||||
if ($strattemptnum = quiz_num_attempt_summary($quiz, $cm, true, $currentgroup)) {
|
||||
echo '<div class="quizattemptcounts">' . $strattemptnum . '</div>';
|
||||
}
|
||||
}
|
||||
|
||||
$hasquestions = quiz_has_questions($quiz->id);
|
||||
if (!$table->is_downloading()) {
|
||||
if (!$hasquestions) {
|
||||
echo quiz_no_questions_message($quiz, $cm, $this->context);
|
||||
} else if (!$hasstudents) {
|
||||
echo $OUTPUT->notification(get_string('nostudentsyet'));
|
||||
} else if ($currentgroup && !$this->hasgroupstudents) {
|
||||
echo $OUTPUT->notification(get_string('nostudentsingroup'));
|
||||
}
|
||||
$this->print_standard_header_and_messages($cm, $course, $quiz,
|
||||
$options, $currentgroup, $hasquestions, $hasstudents);
|
||||
|
||||
// Print the display options.
|
||||
$this->form->display();
|
||||
|
@ -111,36 +111,13 @@ class quiz_responses_report extends quiz_attempts_report {
|
||||
|
||||
$this->process_actions($quiz, $cm, $currentgroup, $groupstudentsjoins, $allowedjoins, $options->get_url());
|
||||
|
||||
$hasquestions = quiz_has_questions($quiz->id);
|
||||
|
||||
// Start output.
|
||||
if (!$table->is_downloading()) {
|
||||
// Only print headers if not asked to download data.
|
||||
$this->print_header_and_tabs($cm, $course, $quiz, $this->mode);
|
||||
}
|
||||
|
||||
if ($groupmode = groups_get_activity_groupmode($cm)) {
|
||||
// Groups are being used, so output the group selector if we are not downloading.
|
||||
if (!$table->is_downloading()) {
|
||||
groups_print_activity_menu($cm, $options->get_url());
|
||||
}
|
||||
}
|
||||
|
||||
// Print information on the number of existing attempts.
|
||||
if (!$table->is_downloading()) {
|
||||
// Do not print notices when downloading.
|
||||
if ($strattemptnum = quiz_num_attempt_summary($quiz, $cm, true, $currentgroup)) {
|
||||
echo '<div class="quizattemptcounts">' . $strattemptnum . '</div>';
|
||||
}
|
||||
}
|
||||
|
||||
$hasquestions = quiz_has_questions($quiz->id);
|
||||
if (!$table->is_downloading()) {
|
||||
if (!$hasquestions) {
|
||||
echo quiz_no_questions_message($quiz, $cm, $this->context);
|
||||
} else if (!$hasstudents) {
|
||||
echo $OUTPUT->notification(get_string('nostudentsyet'));
|
||||
} else if ($currentgroup && !$this->hasgroupstudents) {
|
||||
echo $OUTPUT->notification(get_string('nostudentsingroup'));
|
||||
}
|
||||
$this->print_standard_header_and_messages($cm, $course, $quiz,
|
||||
$options, $currentgroup, $hasquestions, $hasstudents);
|
||||
|
||||
// Print the display options.
|
||||
$this->form->display();
|
||||
|
Loading…
x
Reference in New Issue
Block a user