diff --git a/mod/quiz/attempt.php b/mod/quiz/attempt.php
index 691f56f86ac06..7ae877b69997f 100644
--- a/mod/quiz/attempt.php
+++ b/mod/quiz/attempt.php
@@ -120,19 +120,12 @@
echo $OUTPUT->header();
}
-if ($attemptobj->is_preview_user()) {
-
- // Heading.
- echo $OUTPUT->heading(get_string('previewquiz', 'quiz', format_string($attemptobj->get_quiz_name())));
- $attemptobj->print_restart_preview_button();
-
+if ($attemptobj->is_preview_user() && $messages) {
// Inform teachers of any restrictions that would apply to students at this point.
- if ($messages) {
- echo $OUTPUT->box_start('quizaccessnotices');
- echo $OUTPUT->heading(get_string('accessnoticesheader', 'quiz'), 3);
- $accessmanager->print_messages($messages);
- echo $OUTPUT->box_end();
- }
+ echo $OUTPUT->box_start('quizaccessnotices');
+ echo $OUTPUT->heading(get_string('accessnoticesheader', 'quiz'), 3);
+ $accessmanager->print_messages($messages);
+ echo $OUTPUT->box_end();
}
// Start the form
diff --git a/mod/quiz/attemptlib.php b/mod/quiz/attemptlib.php
index 868093cc94515..7adc972805b80 100644
--- a/mod/quiz/attemptlib.php
+++ b/mod/quiz/attemptlib.php
@@ -847,14 +847,18 @@ public function get_question_html_head_contributions($slot) {
}
/**
- * Print the HTML for the start new preview button.
- */
- public function print_restart_preview_button() {
- global $CFG, $OUTPUT;
- echo $OUTPUT->container_start('controls');
- $url = new moodle_url($this->start_attempt_url(), array('forcenew' => true));
- echo $OUTPUT->single_button($url, get_string('startagain', 'quiz'));
- echo $OUTPUT->container_end();
+ * Print the HTML for the start new preview button, if the current user
+ * is allowed to see one.
+ */
+ public function restart_preview_button() {
+ global $OUTPUT;
+ if ($this->is_preview() && $this->is_preview_user()) {
+ return $OUTPUT->single_button(new moodle_url(
+ $this->start_attempt_url(), array('forcenew' => true)),
+ get_string('startnewpreview', 'quiz'));
+ } else {
+ return '';
+ }
}
/**
@@ -1221,7 +1225,8 @@ public function get_contents() {
}
$content .= $this->get_before_button_bits();
$content .= $this->get_question_buttons() . "\n";
- $content .= '
' . "\n" . $this->get_end_bits() . "\n
\n";
+ $content .= '' . "\n" . $this->get_end_bits() .
+ $this->attemptobj->restart_preview_button() . "\n
\n";
$bc = new block_contents();
$bc->id = 'quiznavigation';
diff --git a/mod/quiz/lang/en/quiz.php b/mod/quiz/lang/en/quiz.php
index 4731b4f7f65cb..9963b6d23dbac 100644
--- a/mod/quiz/lang/en/quiz.php
+++ b/mod/quiz/lang/en/quiz.php
@@ -100,6 +100,7 @@
$string['attemptsonly'] = 'Show only students with attempts';
$string['attemptsunlimited'] = 'Unlimited attempts';
$string['back'] = 'Back to preview question';
+$string['backtocourse'] = 'Back to the course';
$string['backtoquestionlist'] = 'Back to question list';
$string['backtoquiz'] = 'Back to quiz editing';
$string['basicideasofquiz'] = 'The basic ideas of quiz-making';
@@ -734,6 +735,7 @@
$string['specificquestionnotonquiz'] = 'Specified question is not on the specified quiz';
$string['startagain'] = 'Start again';
$string['startedon'] = 'Started on';
+$string['startnewpreview'] = 'Start a new preview';
$string['statenotloaded'] = 'The state for question {$a} has not been loaded from the database';
$string['status'] = 'Status';
$string['stoponerror'] = 'Stop on error';
diff --git a/mod/quiz/locallib.php b/mod/quiz/locallib.php
index bef0e2b2bf931..b35d13b4b693e 100644
--- a/mod/quiz/locallib.php
+++ b/mod/quiz/locallib.php
@@ -404,6 +404,19 @@ function quiz_has_feedback($quiz) {
return $cache[$quiz->id];
}
+function quiz_no_questions_message($quiz, $cm, $context) {
+ global $OUTPUT;
+
+ $output = '';
+ $output .= $OUTPUT->notification(get_string('noquestions', 'quiz'));
+ if (has_capability('mod/quiz:manage', $context)) {
+ $output .= $OUTPUT->single_button(new moodle_url('/mod/quiz/edit.php',
+ array('cmid' => $cm->id)), get_string('editquiz', 'quiz'), 'get');
+ }
+
+ return $output;
+}
+
/**
* Update the sumgrades field of the quiz. This needs to be called whenever
* the grading structure of the quiz is changed. For example if a question is
diff --git a/mod/quiz/report.php b/mod/quiz/report.php
index 243b4faedabf5..1135b4db30448 100644
--- a/mod/quiz/report.php
+++ b/mod/quiz/report.php
@@ -84,11 +84,6 @@
print_error('reportnotfound', 'quiz', '', $mode);
}
-// If no questions have been set up yet redirect to edit.php
-if (!$quiz->questions and has_capability('mod/quiz:manage', $context)) {
- redirect('edit.php?cmid=' . $cm->id);
-}
-
add_to_log($course->id, 'quiz', 'report', 'report.php?id=' . $cm->id . '&mode=' . $mode,
$quiz->id, $cm->id);
diff --git a/mod/quiz/report/grading/report.php b/mod/quiz/report/grading/report.php
index efaa4117191c2..f0feb6642c1b0 100644
--- a/mod/quiz/report/grading/report.php
+++ b/mod/quiz/report/grading/report.php
@@ -127,7 +127,10 @@ function display($quiz, $cm, $course) {
$this->print_header_and_tabs($cm, $course, $quiz, 'grading');
// What sort of page to display?
- if (!$slot) {
+ if (!quiz_questions_in_quiz($quiz->questions)) {
+ echo quiz_no_questions_message($quiz, $cm, $this->context);
+
+ } else if (!$slot) {
$this->display_index($includeauto);
} else {
diff --git a/mod/quiz/report/overview/report.php b/mod/quiz/report/overview/report.php
index 59ea18a325834..008f018a1b5ff 100644
--- a/mod/quiz/report/overview/report.php
+++ b/mod/quiz/report/overview/report.php
@@ -187,25 +187,22 @@ function display($quiz, $cm, $course) {
}
}
- $nostudents = false;
- if (!$students) {
- if (!$table->is_downloading()) {
+ $hasquestions = quiz_questions_in_quiz($quiz->questions);
+ if (!$table->is_downloading()) {
+ if (!$hasquestions) {
+ echo quiz_no_questions_message($quiz, $cm, $this->context);
+ } else if (!$students) {
echo $OUTPUT->notification(get_string('nostudentsyet'));
- }
- $nostudents = true;
- } else if ($currentgroup && !$groupstudents) {
- if (!$table->is_downloading()) {
+ } else if ($currentgroup && !$groupstudents) {
echo $OUTPUT->notification(get_string('nostudentsingroup'));
}
- $nostudents = true;
- }
- if (!$table->is_downloading()) {
// Print display options
$mform->display();
}
- if (!$nostudents || ($attemptsmode == QUIZ_REPORT_ATTEMPTS_ALL)) {
+ $hasstudents = $students && (!$currentgroup || $groupstudents);
+ if ($hasquestions && ($hasstudents || ($attemptsmode == QUIZ_REPORT_ATTEMPTS_ALL))) {
// Construct the SQL
$fields = $DB->sql_concat('u.id', "'#'", 'COALESCE(quiza.attempt, 0)') . ' AS uniqueid, ';
if ($qmsubselect) {
diff --git a/mod/quiz/report/reportlib.php b/mod/quiz/report/reportlib.php
index 2006671667a41..2d3295191fb31 100644
--- a/mod/quiz/report/reportlib.php
+++ b/mod/quiz/report/reportlib.php
@@ -96,6 +96,10 @@ function quiz_report_get_significant_questions($quiz) {
global $DB;
$questionids = quiz_questions_in_quiz($quiz->questions);
+ if (empty($questionids)) {
+ return array();
+ }
+
list($usql, $params) = $DB->get_in_or_equal(explode(',', $questionids));
$params[] = $quiz->id;
$questions = $DB->get_records_sql("
diff --git a/mod/quiz/report/responses/report.php b/mod/quiz/report/responses/report.php
index 4ee74565371c1..214b7b0f13870 100644
--- a/mod/quiz/report/responses/report.php
+++ b/mod/quiz/report/responses/report.php
@@ -116,6 +116,8 @@ function display($quiz, $cm, $course) {
$displayoptions['resp'] = $includeresp;
$displayoptions['right'] = $includeright;
+ $mform->set_data($displayoptions + array('pagesize' => $pagesize));
+
if ($attemptsmode == QUIZ_REPORT_ATTEMPTS_ALL) {
// 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
@@ -159,25 +161,23 @@ function display($quiz, $cm, $course) {
echo '' . $strattemptnum . '
';
}
}
- $nostudents = false;
- if (!$students) {
- if (!$table->is_downloading()) {
+
+ $hasquestions = quiz_questions_in_quiz($quiz->questions);
+ if (!$table->is_downloading()) {
+ if (!$hasquestions) {
+ echo quiz_no_questions_message($quiz, $cm, $this->context);
+ } else if (!$students) {
echo $OUTPUT->notification(get_string('nostudentsyet'));
- }
- $nostudents = true;
- } else if ($currentgroup && !$groupstudents) {
- if (!$table->is_downloading()) {
+ } else if ($currentgroup && !$groupstudents) {
echo $OUTPUT->notification(get_string('nostudentsingroup'));
}
- $nostudents = true;
- }
- if (!$table->is_downloading()) {
+
// Print display options
- $mform->set_data($displayoptions + array('pagesize' => $pagesize));
$mform->display();
}
- if (!$nostudents || ($attemptsmode == QUIZ_REPORT_ATTEMPTS_ALL)) {
+ $hasstudents = $students && (!$currentgroup || $groupstudents);
+ if ($hasquestions && ($hasstudents || $attemptsmode == QUIZ_REPORT_ATTEMPTS_ALL)) {
// Print information on the grading method and whether we are displaying
if (!$table->is_downloading()) { //do not print notices when downloading
if ($strattempthighlight = quiz_report_highlighting_grading_method($quiz, $qmsubselect, $qmfilter)) {
diff --git a/mod/quiz/report/statistics/report.php b/mod/quiz/report/statistics/report.php
index 0378d66c14566..85a527b5815a8 100644
--- a/mod/quiz/report/statistics/report.php
+++ b/mod/quiz/report/statistics/report.php
@@ -139,10 +139,6 @@ public function display($quiz, $cm, $course) {
$nostudentsingroup, $useallattempts, $groupstudents, $questions);
$quizinfo = $this->get_formatted_quiz_info_data($course, $cm, $quiz, $quizstats);
- if (!$this->table->is_downloading() && $s == 0) {
- echo $OUTPUT->heading(get_string('noattempts', 'quiz'));
- }
-
// Set up the table, if there is data.
if ($s) {
$this->table->setup($quiz, $cm->id, $reporturl, $s);
@@ -159,6 +155,12 @@ public function display($quiz, $cm, $course) {
}
}
+ if (!quiz_questions_in_quiz($quiz->questions)) {
+ echo quiz_no_questions_message($quiz, $cm, $context);
+ } else if (!$this->table->is_downloading() && $s == 0) {
+ echo $OUTPUT->notification(get_string('noattempts', 'quiz'));
+ }
+
// Print display options form.
$mform->set_data(array('useallattempts' => $useallattempts));
$mform->display();
diff --git a/mod/quiz/review.php b/mod/quiz/review.php
index fa01ca7c9aacb..d67a46140b6f0 100644
--- a/mod/quiz/review.php
+++ b/mod/quiz/review.php
@@ -119,12 +119,6 @@
echo $OUTPUT->header();
}
-// Print heading.
-if ($attemptobj->is_preview_user() && $attemptobj->is_own_attempt()) {
- $attemptobj->print_restart_preview_button();
-}
-echo $OUTPUT->heading($strreviewtitle);
-
// Summary table start ============================================================================
// Work out some time-related things.
diff --git a/mod/quiz/summary.php b/mod/quiz/summary.php
index b87314a207dda..dd1b996230a65 100644
--- a/mod/quiz/summary.php
+++ b/mod/quiz/summary.php
@@ -94,10 +94,7 @@
// Print heading.
echo $OUTPUT->heading(format_string($attemptobj->get_quiz_name()));
-if ($attemptobj->is_preview_user()) {
- $attemptobj->print_restart_preview_button();
-}
-echo $OUTPUT->heading($title);
+echo $OUTPUT->heading($title, 3);
// Prepare the summary table header
$table = new html_table();
diff --git a/mod/quiz/view.php b/mod/quiz/view.php
index 5fa34820ed0c3..172d536f8adb2 100644
--- a/mod/quiz/view.php
+++ b/mod/quiz/view.php
@@ -345,10 +345,9 @@
echo $OUTPUT->box_start('quizattempt');
$buttontext = ''; // This will be set something if as start/continue attempt button should appear.
if (!quiz_clean_layout($quiz->questions, true)) {
- echo $OUTPUT->heading(get_string('noquestions', 'quiz'));
- echo $OUTPUT->render(new single_button(new moodle_url('/mod/quiz/edit.php',
- array('cmid' => $cm->id)), get_string('editquiz', 'quiz'), 'get'));
- $buttontext = false;
+ echo quiz_no_questions_message($quiz, $cm, $context);
+ $buttontext = '';
+
} else {
if ($unfinished) {
if ($canattempt) {
@@ -356,6 +355,7 @@
} else if ($canpreview) {
$buttontext = get_string('continuepreview', 'quiz');
}
+
} else {
if ($canattempt) {
$messages = $accessmanager->prevent_new_attempt($numattempts, $lastfinishedattempt);
@@ -366,6 +366,7 @@
} else {
$buttontext = get_string('reattemptquiz', 'quiz');
}
+
} else if ($canpreview) {
$buttontext = get_string('previewquiznow', 'quiz');
}
@@ -386,7 +387,8 @@
if ($buttontext) {
$accessmanager->print_start_attempt_button($canpreview, $buttontext, $unfinished);
} else if ($buttontext === '') {
- echo $OUTPUT->continue_button($CFG->wwwroot . '/course/view.php?id=' . $course->id);
+ echo $OUTPUT->single_button(new moodle_url('/course/view.php', array('id' => $course->id)),
+ get_string('backtocourse', 'quiz'), 'get', array('class' => 'continuebutton'));
}
echo $OUTPUT->box_end();