MDL-3633 Don't show the attempt number column on the quiz view page if the quiz only allows one attempt.

This commit is contained in:
tjhunt 2008-09-04 09:22:37 +00:00
parent 237806f4f0
commit 152d3c0242
5 changed files with 64 additions and 29 deletions

View file

@ -319,37 +319,57 @@ class quiz_access_manager {
* @param object $attempt the attempt object
* @return string some HTML, the $linktext either unmodified or wrapped in a link to the review page.
*/
public function make_review_link($linktext, $attempt, $canpreview, $reviewoptions) {
public function make_review_link($attempt, $canpreview, $reviewoptions) {
global $CFG;
/// If review of responses is not allowed, or the attempt is still open, don't link.
if (!$reviewoptions->responses || !$attempt->timefinish) {
return $linktext;
if (!$attempt->timefinish) {
return '';
}
if (!$reviewoptions->responses) {
$message = $this->cannot_review_message($reviewoptions, true);
if ($message) {
return '<span class="noreviewmessage">' . $message . '</span>';
} else {
return '';
}
}
$linktext = get_string('review', 'quiz');
/// It is OK to link, does it need to be in a secure window?
if ($this->securewindow_required($canpreview)) {
return $this->_securewindowrule->make_review_link($linktext, $attempt->id);
} else {
return '<a href="' . $this->_quizobj->review_url($attempt->id) . '">' . $linktext . '</a>';
return '<a href="' . $this->_quizobj->review_url($attempt->id) . '" title="' .
get_string('reviewthisattempt', 'quiz') . '">' . $linktext . '</a>';
}
}
/**
* If $reviewoptions->responses is false, meaning that students can't review this
* attempt at the moment, return an appropriate string explaining why.
*
* @param object $reviewoptions as obtained from quiz_get_reviewoptions.
* @param boolean $short if true, return a shorter string.
* @return string an appropraite message.
*/
public function cannot_review_message($reviewoptions) {
public function cannot_review_message($reviewoptions, $short = false) {
$quiz = $this->_quizobj->get_quiz();
if ($short) {
$langstrsuffix = 'short';
$dateformat = get_string('strftimedatetimeshort', 'langconfig');
} else {
$langstrsuffix = '';
$dateformat = '';
}
if ($reviewoptions->quizstate == QUIZ_STATE_IMMEDIATELY) {
return '';
} else if ($reviewoptions->quizstate == QUIZ_STATE_OPEN && $quiz->timeclose &&
($quiz->review & QUIZ_REVIEW_CLOSED & QUIZ_REVIEW_RESPONSES)) {
return get_string('noreviewuntil', 'quiz', userdate($quiz->timeclose));
return get_string('noreviewuntil' . $langstrsuffix, 'quiz', userdate($quiz->timeclose, $dateformat));
} else {
return get_string('noreview', 'quiz');
return get_string('noreview' . $langstrsuffix, 'quiz');
}
}
}
@ -711,7 +731,7 @@ class securewindow_access_rule extends quiz_access_rule_base {
* @return string HTML for the link.
*/
public function make_review_link($linktext, $attemptid) {
return link_to_popup_window($this->_quizobj->review_url($attemptid),
return button_to_popup_window($this->_quizobj->review_url($attemptid),
'quizpopup', $linktext, '', '', '', $this->windowoptions, true);
}

View file

@ -1,7 +1,8 @@
<?php // $Id$
/**
* This page prints a review of a particular question attempt
*
* This page allows the teacher to enter a manual grade for a particular question.
* This page is expected to only be used in a popup window.
* *
* @license http://www.gnu.org/copyleft/gpl.html GNU Public License
* @package quiz
*/
@ -12,15 +13,7 @@
$attemptid =required_param('attempt', PARAM_INT); // attempt id
$questionid =required_param('question', PARAM_INT); // question id
if (! $attempt = $DB->get_record('quiz_attempts', array('uniqueid' => $attemptid))) {
print_error('invalidattemptid', 'quiz');
}
if (! $quiz = $DB->get_record('quiz', array('id' => $attempt->quiz))) {
print_error('invalidcoursemodule');
}
if (! $course = $DB->get_record('course', array('id' => $quiz->course))) {
print_error('coursemisconf');
}
$attemptobj = new quiz_attempt($attemptid);
// Teachers are only allowed to comment and grade on closed attempts
if (!($attempt->timefinish > 0)) {

View file

@ -175,6 +175,8 @@
// Work out which columns we need, taking account what data is available in each attempt.
list($someoptions, $alloptions) = quiz_get_combined_reviewoptions($quiz, $attempts, $context);
$attemptcolumn = $quiz->attempts != 1;
$gradecolumn = $someoptions->scores && $quiz->grade && $quiz->sumgrades;
$markcolumn = $gradecolumn && ($quiz->grade != $quiz->sumgrades);
$overallstats = $alloptions->scores;
@ -184,9 +186,17 @@
// Prepare table header
$table->class = 'generaltable quizattemptsummary';
$table->head = array(get_string('attempt', 'quiz'), get_string('timecompleted', 'quiz'));
$table->align = array('center', 'left');
$table->size = array('', '');
$table->head = array();
$table->align = array();
$table->size = array();
if ($attemptcolumn) {
$table->head[] = get_string('attempt', 'quiz');
$table->align[] = 'center';
$table->size[] = '';
}
$table->head[] = get_string('timecompleted', 'quiz') . ' / ' . quiz_format_grade($quiz, $quiz->sumgrades);
$table->align[] = 'left';
$table->size[] = '';
if ($markcolumn) {
$table->head[] = get_string('marks', 'quiz') . ' / ' . quiz_format_grade($quiz, $quiz->sumgrades);
$table->align[] = 'center';
@ -197,6 +207,9 @@
$table->align[] = 'center';
$table->size[] = '';
}
$table->head[] = get_string('review', 'quiz');
$table->align[] = 'center';
$table->size[] = '';
if ($feedbackcolumn) {
$table->head[] = get_string('feedback', 'quiz');
$table->align[] = 'left';
@ -214,10 +227,12 @@
$row = array();
// Add the attempt number, making it a link, if appropriate.
if ($attempt->preview) {
$row[] = $accessmanager->make_review_link(get_string('preview', 'quiz'), $attempt, $canpreview, $attemptoptions);
} else {
$row[] = $accessmanager->make_review_link($attempt->attempt, $attempt, $canpreview, $attemptoptions);
if ($attemptcolumn) {
if ($attempt->preview) {
$row[] = get_string('preview', 'quiz');
} else {
$row[] = $attempt->attempt;
}
}
// prepare strings for time taken and date completed
@ -239,8 +254,7 @@
if ($markcolumn && $attempt->timefinish > 0) {
if ($attemptoptions->scores) {
$row[] = $accessmanager->make_review_link(quiz_format_grade($quiz, $attempt->sumgrades),
$attempt, $canpreview, $attemptoptions);
$row[] = quiz_format_grade($quiz, $attempt->sumgrades);
} else {
$row[] = '';
}
@ -258,12 +272,14 @@
$table->rowclass[$attempt->attempt] = 'bestrow';
}
$row[] = $accessmanager->make_review_link($formattedgrade, $attempt, $canpreview, $attemptoptions);
$row[] = $formattedgrade;
} else {
$row[] = '';
}
}
$row[] = $accessmanager->make_review_link($attempt, $canpreview, $attemptoptions);
if ($feedbackcolumn && $attempt->timefinish > 0) {
if ($attemptoptions->overallfeedback) {
$row[] = quiz_feedback_for_grade($attemptgrade, $quiz->id);