Skip to content

Commit

Permalink
MDL-20636 Move restart preview button into the quiz nav block & remov…
Browse files Browse the repository at this point in the history
…e unnecessary titles.

Also, remove automatic redirects to the quiz edit page. Show a message and a button instead.
  • Loading branch information
timhunt committed Feb 25, 2011
1 parent 22cebed commit 3c6185e
Show file tree
Hide file tree
Showing 13 changed files with 76 additions and 69 deletions.
17 changes: 5 additions & 12 deletions mod/quiz/attempt.php
Expand Up @@ -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
Expand Down
23 changes: 14 additions & 9 deletions mod/quiz/attemptlib.php
Expand Up @@ -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 '';
}
}

/**
Expand Down Expand Up @@ -1221,7 +1225,8 @@ public function get_contents() {
}
$content .= $this->get_before_button_bits();
$content .= $this->get_question_buttons() . "\n";
$content .= '<div class="othernav">' . "\n" . $this->get_end_bits() . "\n</div>\n";
$content .= '<div class="othernav">' . "\n" . $this->get_end_bits() .
$this->attemptobj->restart_preview_button() . "\n</div>\n";

$bc = new block_contents();
$bc->id = 'quiznavigation';
Expand Down
2 changes: 2 additions & 0 deletions mod/quiz/lang/en/quiz.php
Expand Up @@ -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';
Expand Down Expand Up @@ -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';
Expand Down
13 changes: 13 additions & 0 deletions mod/quiz/locallib.php
Expand Up @@ -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
Expand Down
5 changes: 0 additions & 5 deletions mod/quiz/report.php
Expand Up @@ -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);

Expand Down
5 changes: 4 additions & 1 deletion mod/quiz/report/grading/report.php
Expand Up @@ -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 {
Expand Down
19 changes: 8 additions & 11 deletions mod/quiz/report/overview/report.php
Expand Up @@ -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) {
Expand Down
4 changes: 4 additions & 0 deletions mod/quiz/report/reportlib.php
Expand Up @@ -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("
Expand Down
24 changes: 12 additions & 12 deletions mod/quiz/report/responses/report.php
Expand Up @@ -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
Expand Down Expand Up @@ -159,25 +161,23 @@ function display($quiz, $cm, $course) {
echo '<div class="quizattemptcounts">' . $strattemptnum . '</div>';
}
}
$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)) {
Expand Down
10 changes: 6 additions & 4 deletions mod/quiz/report/statistics/report.php
Expand Up @@ -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);
Expand All @@ -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();
Expand Down
6 changes: 0 additions & 6 deletions mod/quiz/review.php
Expand Up @@ -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.
Expand Down
5 changes: 1 addition & 4 deletions mod/quiz/summary.php
Expand Up @@ -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();
Expand Down
12 changes: 7 additions & 5 deletions mod/quiz/view.php
Expand Up @@ -345,17 +345,17 @@
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) {
$buttontext = get_string('continueattemptquiz', 'quiz');
} else if ($canpreview) {
$buttontext = get_string('continuepreview', 'quiz');
}

} else {
if ($canattempt) {
$messages = $accessmanager->prevent_new_attempt($numattempts, $lastfinishedattempt);
Expand All @@ -366,6 +366,7 @@
} else {
$buttontext = get_string('reattemptquiz', 'quiz');
}

} else if ($canpreview) {
$buttontext = get_string('previewquiznow', 'quiz');
}
Expand All @@ -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();

Expand Down

0 comments on commit 3c6185e

Please sign in to comment.