quiz editing: MDL-17296 refactor print_timing_information to avoid duplicating code...
authortjhunt <tjhunt>
Wed, 26 Nov 2008 04:52:46 +0000 (04:52 +0000)
committertjhunt <tjhunt>
Wed, 26 Nov 2008 04:52:46 +0000 (04:52 +0000)
mod/quiz/accessrules.php
mod/quiz/editlib.php
mod/quiz/locallib.php

index 4940e8e2c25f9f7b8207bcb504cfed30b74f0caa..92d22fc10a123a2eec433ff70cbeb62756280b40 100644 (file)
@@ -57,7 +57,7 @@ class quiz_access_manager {
     }
 
     /**
-     * Print each message in an array, each surrounded by &lt;p>, &lt;/p> tags.
+     * Print each message in an array, surrounded by &lt;p>, &lt;/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);
+    }
 }
 
 /**
index 36dd83d9df1084d4e374c9f1bd02c3a2f7a698fa..e40f2844a6a91b6bc82efb511608ad850ba9f9b4 100644 (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
index fe95c005c6b9e0f2344e4e13efeb111b6c875528..1425f2163057f0107966a717921fa76ff0c7d554 100644 (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