quiz editing: MDL-17296 refactor print_timing_information to avoid duplicating code from mod/quiz/accessrules.php

This commit is contained in:
tjhunt 2008-11-26 04:52:46 +00:00
parent 1e69a6562f
commit 2e883810d3
3 changed files with 14 additions and 28 deletions

View File

@ -57,7 +57,7 @@ class quiz_access_manager {
}
/**
* Print each message in an array, each surrounded by <p>, </p> tags.
* Print each message in an array, surrounded by <p>, </p> tags.
*
* @param array $messages the array of message strings.
* @param boolean $return if true, return a string, instead of outputting.
@ -510,6 +510,17 @@ class open_close_date_access_rule extends quiz_access_rule_base {
}
return false;
}
/**
* Output information about this quiz's open and close dates, and whether
* the quiz is currently open.
*/
public function print_timing_information() {
$messages = $this->description();
if (!$this->prevent_access()) {
$messages[] = get_string('quizopened', 'quiz');
}
echo implode(' | ', $messages);
}
}
/**

View File

@ -1536,7 +1536,8 @@ function quiz_print_status_bar($quiz,$sumgrades){
?></span>
| <span class="quizopeningstatus">
<?php
print_timing_information($quiz,true);
$accessrule = new open_close_date_access_rule(new quiz($quiz, NULL, NULL, false), time());
$accessrule->print_timing_information();
?></span><?php
// If questions are shuffled, notify the user about the
// question order not making much sense

View File

@ -1120,33 +1120,7 @@ function quiz_send_notification_emails($course, $quiz, $attempt, $context, $cm)
// return the number of successfully sent emails
return $emailresult['good'];
}
//TODO: refactor; http://tracker.moodle.org/browse/MDL-17296
function print_timing_information($quiz,$showopenstatus=false){
$timenow = time();
$available = ($quiz->timeopen < $timenow and ($timenow < $quiz->timeclose or !$quiz->timeclose));
if ($available) {
if ($quiz->timelimit) {
echo get_string("quiztimelimit","quiz", format_time($quiz->timelimit * 60))."</p>";
}
if ($quiz->timeopen) {
echo get_string('quizopens', 'quiz'), ': ', userdate($quiz->timeopen);
}
if ($quiz->timeclose) {
echo get_string('quizcloses', 'quiz'), ': ', userdate($quiz->timeclose);
}
if($showopenstatus){
if(!$quiz->timelimit && !$quiz->timeopen && !$quiz->timeclose){
echo get_string('quizopened', 'quiz');
}
}
} else if ($timenow < $quiz->timeopen) {
echo get_string("quiznotavailable", "quiz", userdate($quiz->timeopen));
} else {
echo get_string("quizclosed", "quiz", userdate($quiz->timeclose));
}
return $available;
}
/**
* Clean the question layout from various possible anomalies:
* - Remove consecutive ","'s