Skip to content

Commit

Permalink
MDL-28012 Quiz editing status line can display screwy dates.
Browse files Browse the repository at this point in the history
  • Loading branch information
timhunt committed Jun 23, 2011
1 parent b4bb80b commit c5da295
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 21 deletions.
53 changes: 32 additions & 21 deletions mod/quiz/editlib.php
Expand Up @@ -1237,44 +1237,55 @@ function quiz_print_grading_form($quiz, $pageurl, $tabindex) {
*/
function quiz_print_status_bar($quiz) {
global $CFG;
$numberofquestions = quiz_number_of_questions_in_quiz($quiz->questions);
?><div class="statusbar"><span class="totalpoints">
<?php echo get_string('totalpointsx', 'quiz',
quiz_format_grade($quiz, $quiz->sumgrades)) ?></span>
| <span class="numberofquestions">
<?php
echo get_string('numquestionsx', 'quiz', $numberofquestions);
?></span>
<?php
// Current status of the quiz, with open an close dates as a tool tip.
$currentstatus = get_string('quizisopen', 'quiz');
$dates = array();

$bits = array();

$bits[] = html_writer::tag('span',
get_string('totalpointsx', 'quiz', quiz_format_grade($quiz, $quiz->sumgrades)),
array('class' => 'totalpoints'));

$bits[] = html_writer::tag('span',
get_string('numquestionsx', 'quiz', quiz_number_of_questions_in_quiz($quiz->questions)),
array('class' => 'numberofquestions'));

$timenow = time();

// Exact open and close dates for the tool-tip.
$dates = array();
if ($quiz->timeopen > 0) {
if ($timenow > $quiz->timeopen) {
$dates[] = get_string('quizopenedon', 'quiz', userdate($quiz->timeopen));
} else {
$dates[] = get_string('quizwillopen', 'quiz', userdate($quiz->timeopen));
print_string('quizisclosed', 'quiz');
}
}
if ($quiz->timeclose > 0) {
if ($timenow > $quiz->timeclose) {
$dates[] = get_string('quizclosed', 'quiz', userdate($quiz->timeclose));
print_string('quizisclosed', 'quiz');
} else {
$dates[] = get_string('quizcloseson', 'quiz', userdate($quiz->timeclose));
$currentstatus = get_string('quizisopenwillclose', 'quiz',
userdate($quiz->timeclose, get_string('strftimedatetimeshort', 'langconfig')));
}
}
if (empty($dates)) {
$dates[] = get_string('alwaysavailable', 'quiz');
}
$dates = implode(', ', $dates);
echo ' | <span class="quizopeningstatus" title="' . $dates . '">' . $currentstatus . '</span>';
$tooltip = implode(', ', $dates);;

// Brief summary on the page.
if ($timenow < $quiz->timeopen) {
$currentstatus = get_string('quizisclosedwillopen', 'quiz',
userdate($quiz->timeclose, get_string('strftimedatetimeshort', 'langconfig')));
} else if ($quiz->timeclose && $timenow <= $quiz->timeclose) {
$currentstatus = get_string('quizisopenwillclose', 'quiz',
userdate($quiz->timeclose, get_string('strftimedatetimeshort', 'langconfig')));
} else if ($quiz->timeclose && $timenow > $quiz->timeclose) {
$currentstatus = get_string('quizisclosed', 'quiz');
} else {
$currentstatus = get_string('quizisopen', 'quiz');
}

?>
</div>
<?php
$bits[] = html_writer::tag('span', $currentstatus,
array('class' => 'quizopeningstatus', 'title' => implode(', ', $dates)));

echo html_writer::tag('div', implode(' | ', $bits), array('class' => 'statusbar'));
}
1 change: 1 addition & 0 deletions mod/quiz/lang/en/quiz.php
Expand Up @@ -555,6 +555,7 @@
$string['quiz:ignoretimelimits'] = 'Ignores time limit on quizzes';
$string['quizisclosed'] = 'This quiz is closed';
$string['quizisopen'] = 'This quiz is open';
$string['quizisclosedwillopen'] = 'Quiz closed (opens {$a})';
$string['quizisopenwillclose'] = 'Quiz open (closes {$a})';
$string['quiz:manage'] = 'Manage quizzes';
$string['quiz:manageoverrides'] = 'Manage quiz overrides';
Expand Down

0 comments on commit c5da295

Please sign in to comment.