]> git.mjollnir.org Git - moodle.git/commitdiff
MDL-6376 - Include quizzes on the MyMoodle page. Initial implementation by Stephen...
authortjhunt <tjhunt>
Fri, 21 Sep 2007 11:05:04 +0000 (11:05 +0000)
committertjhunt <tjhunt>
Fri, 21 Sep 2007 11:05:04 +0000 (11:05 +0000)
lang/en_utf8/quiz.php
mod/quiz/lib.php
mod/quiz/locallib.php

index e0a1a65c18543a8e756d57ff0d4000f99e701cab..d3e8f9e866717ec5c2b42a9a9f578545df143e11 100644 (file)
@@ -365,6 +365,7 @@ $string['notenoughanswers'] = 'This type of question requires at least $a answer
 $string['notenoughsubquestions'] = 'Not enough sub-questions have been defined!<br />Do you want to go back and fix this question?';
 $string['notimedependentitems'] = 'Time dependent items are not currently supported by the quiz module. As a work around, set a time limit for the whole quiz. Do you wish to choose a different item (or use the current item regardless)?';
 $string['numattempts'] = '$a->studentnum $a->studentstring have made $a->attemptnum attempts';
+$string['numattemptsmade'] = '$a attempts made on this quiz';
 $string['numberabbr'] = '#';
 $string['numerical'] = 'Numerical';
 $string['onlyteachersexport'] = 'Only teachers can export questions';
@@ -426,6 +427,7 @@ $string['quizavailable'] = 'The quiz is available until: $a';
 $string['quizclose'] = 'Close the quiz';
 $string['quizclosed'] = 'This quiz closed on $a';
 $string['quizcloses'] = 'Quiz closes';
+$string['quizcloseson'] = 'This quiz will close at $a';
 $string['quiznotavailable'] = 'The quiz will not be available until: $a';
 $string['quizopen'] = 'Open the quiz';
 $string['quizopens'] = 'Quiz opens';
index b92cf28465c612bcbab5f61d388804c1798e52cd..1dd6175b2542802ac67fe353d4773b9b04f658b0 100644 (file)
@@ -231,6 +231,30 @@ function quiz_cron () {
     return true;
 }
 
+/**
+ * @param integer $quizid the quiz id.
+ * @param integer $userid the userid.
+ * @param string $status 'all', 'finished' or 'unfinished' to control
+ * @return an array of all the user's attempts at this quiz. Returns an empty array if there are none.
+ */
+function quiz_get_user_attempts($quizid, $userid, $status = 'finished', $includepreviews = false) {
+    $status_condition = array(
+        'all' => '',
+        'finished' => ' AND timefinish > 0',
+        'unfinished' => ' AND timefinish = 0'
+    );
+    $previewclause = '';
+    if (!$includepreviews) {
+        $previewclause = ' AND preview = 0';
+    }
+    if ($attempts = get_records_select('quiz_attempts',
+            "quiz = '$quizid' AND userid = '$userid'" . $previewclause . $status_condition[$status],
+            'attempt ASC')) {
+        return $attempts;
+    } else {
+        return array();
+    }
+}
 
 /**
  * Return grade for given user or all users.
@@ -955,4 +979,71 @@ function quiz_check_file_access($attemptid, $questionid) {
     // otherwise, this user does not have permission
     return false;
 }
+
+/**
+ * Prints quiz summaries on MyMoodle Page
+ */
+function quiz_print_overview($courses, &$htmlarray) {
+    global $USER, $CFG;
+/// These next 6 Lines are constant in all modules (just change module name)
+    if (empty($courses) || !is_array($courses) || count($courses) == 0) {
+        return array();
+    }
+
+    if (!$quizs = get_all_instances_in_courses('quiz', $courses)) {
+        return;
+    }
+
+/// Fetch some language strings outside the main loop.
+    $strquiz = get_string('modulename', 'quiz');
+    $strnoattempts = get_string('noattempts', 'quiz');
+
+/// We want to list quizzes that are currently available, and which have a close date.
+/// This is the same as what the lesson does, and the dabate is in MDL-10568.
+    $now = date();
+    foreach ($quizs as $quiz) {
+        if ($quiz->timeclose >= $now && $quiz->timeopen < $now) {
+        /// Give a link to the quiz, and the deadline.
+            $str = '<div class="quiz overview">' .
+                    '<div class="name">' . $strquiz . ': <a ' . ($quiz->visible ? '' : ' class="dimmed"') .
+                    ' href="' . $CFG->wwwroot . '/mod/quiz/view.php?id=' . $quiz->coursemodule . '">' .
+                    $quiz->name . '</a></div>';
+            $str .= '<div class="info">' . get_string('quizcloseson', 'quiz', userdate($quiz->timeclose)) . '</div>';
+
+        /// Now provide more information depending on the uers's role.
+            $context = get_context_instance(CONTEXT_MODULE, $quiz->coursemodule);
+            if (has_capability('mod/quiz:viewreports', $context)) {
+            /// For teacher-like people, show a summary of the number of student attempts.
+                $a = new stdClass;
+                if ($a->attemptnum = count_records('quiz_attempts', 'quiz', $quiz->id, 'preview', 0)) {
+                    $a->studentnum = count_records_select('quiz_attempts', "quiz = '$quiz->id' AND preview = '0'", 'COUNT(DISTINCT userid)');
+                } else {
+                    $a->studentnum = 0;
+                    $a->attemptnum = 0;
+                }
+                $a->studentstring  = $course->students;
+                $str .= '<div class="info">' . get_string('numattempts', 'quiz', $a) . '</div>';
+            } else if (has_capability('mod/quiz:attempt', $context)){ // Student
+            /// For student-like people, tell them how many attempts they have made.
+                if (isset($USER->id) && ($attempts = quiz_get_user_attempts($quiz->id, $USER->id))) {
+                    $numattempts = count($attempts);
+                    $str .= '<div class="info">' . get_string('numattemptsmade', 'quiz', $numattempts) . '</div>';  
+                } else {
+                    $str .= '<div class="info">' . $strnoattempts . '</div>';
+                }
+            } else {
+            /// For ayone else, there is no point listing this quiz, so stop processing.
+                continue;
+            }
+
+        /// Add the output for this quiz to the rest.
+            $str .= '</div>';
+            if (empty($htmlarray[$quiz->course]['quiz'])) {
+                $htmlarray[$quiz->course]['quiz'] = $str;
+            } else {
+                $htmlarray[$quiz->course]['quiz'] .= $str;
+            }
+        }
+    }
+}
 ?>
index 46f55563403163187a9e0b48a36af662c71fefc5..fb6b8b24d2e4f1130dac5afd351b4b4b662c17de 100644 (file)
@@ -90,31 +90,6 @@ function quiz_get_user_attempt_unfinished($quizid, $userid) {
     }
 }
 
-/**
- * @param integer $quizid the quiz id.
- * @param integer $userid the userid.
- * @param string $status 'all', 'finished' or 'unfinished' to control
- * @return an array of all the user's attempts at this quiz. Returns an empty array if there are none.
- */
-function quiz_get_user_attempts($quizid, $userid, $status = 'finished', $includepreviews = false) {
-    $status_condition = array(
-        'all' => '',
-        'finished' => ' AND timefinish > 0',
-        'unfinished' => ' AND timefinish = 0'
-    );
-    $previewclause = '';
-    if (!$includepreviews) {
-        $previewclause = ' AND preview = 0';
-    }
-    if ($attempts = get_records_select('quiz_attempts',
-            "quiz = '$quizid' AND userid = '$userid'" . $previewclause . $status_condition[$status],
-            'attempt ASC')) {
-        return $attempts;
-    } else {
-        return array();
-    }
-}
-
 /**
  * Delete a quiz attempt.
  */