From 2e883810d3df90d32236f0700dd9629897ee223e Mon Sep 17 00:00:00 2001 From: tjhunt <tjhunt> Date: Wed, 26 Nov 2008 04:52:46 +0000 Subject: [PATCH] quiz editing: MDL-17296 refactor print_timing_information to avoid duplicating code from mod/quiz/accessrules.php --- mod/quiz/accessrules.php | 13 ++++++++++++- mod/quiz/editlib.php | 3 ++- mod/quiz/locallib.php | 26 -------------------------- 3 files changed, 14 insertions(+), 28 deletions(-) diff --git a/mod/quiz/accessrules.php b/mod/quiz/accessrules.php index 4940e8e2c2..92d22fc10a 100644 --- a/mod/quiz/accessrules.php +++ b/mod/quiz/accessrules.php @@ -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); + } } /** diff --git a/mod/quiz/editlib.php b/mod/quiz/editlib.php index 36dd83d9df..e40f2844a6 100644 --- a/mod/quiz/editlib.php +++ b/mod/quiz/editlib.php @@ -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 diff --git a/mod/quiz/locallib.php b/mod/quiz/locallib.php index fe95c005c6..1425f21630 100644 --- a/mod/quiz/locallib.php +++ b/mod/quiz/locallib.php @@ -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 -- 2.39.5