Index: lang/en_utf8/quiz.php =================================================================== RCS file: /cvsroot/moodle/moodle/lang/en_utf8/quiz.php,v retrieving revision 1.79 diff -u -r1.79 quiz.php --- lang/en_utf8/quiz.php 19 Sep 2007 15:38:14 -0000 1.79 +++ lang/en_utf8/quiz.php 20 Sep 2007 13:33:05 -0000 @@ -365,6 +365,7 @@ $string['notenoughsubquestions'] = 'Not enough sub-questions have been defined!
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'; Index: mod/quiz/lib.php =================================================================== RCS file: /cvsroot/moodle/moodle/mod/quiz/lib.php,v retrieving revision 1.279 diff -u -r1.279 lib.php --- mod/quiz/lib.php 19 Sep 2007 15:38:15 -0000 1.279 +++ mod/quiz/lib.php 20 Sep 2007 13:33:05 -0000 @@ -231,6 +231,30 @@ 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,68 @@ // 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'); + $strquizcloses = get_string('quizcloses', 'quiz'); + $strquizopens = get_string('quizopens', 'quiz'); + $strnoattempts = get_string('noattempts', 'quiz'); + $now = date(); + + foreach ($quizs as $quiz) { + if (($quiz->timeclose != 0) && ($quiz->timeclose >= $now)) { // A quiz is scheduled + $str = '
' . + '
' . $strquiz . ': visible ? '' : ' class="dimmed"') . + ' href="' . $CFG->wwwroot . '/mod/quiz/view.php?id=' . $quiz->coursemodule . '">' . + $quiz->name . '
'; + if ($quiz->timeclose != 0) { + $str .= '
' . $strquizcloses . ': ' . userdate($quiz->timeclose) . '
'; + } else { + $str .= '
' . $strquizopens . '
'; + } + + /// Count attempts (Most of this code is from mod/quiz/view.php + $context = get_context_instance(CONTEXT_MODULE, $quiz->coursemodule); + if (has_capability('mod/quiz:viewreports', $context)) { + $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 .= '
' . get_string('numattempts', 'quiz', $a) . '
'; // Number of student attempts + } else if (has_capability('mod/quiz:attempt', $context)){ // Student + if (isset($USER->id) && ($attempts = quiz_get_user_attempts($quiz->id, $USER->id))) { + $numattempts = count($attempts); + $str .= '
' . get_string('numattemptsmade', 'quiz', $numattempts) . '
'; + } else { + $str .= '
' . $strnoattempts . '
'; + } + } + $str .= '
'; + + /// Add the output for this quiz to the rest. + if (empty($htmlarray[$quiz->course]['quiz'])) { + $htmlarray[$quiz->course]['quiz'] = $str; + } else { + $htmlarray[$quiz->course]['quiz'] .= $str; + } + } + } +} ?> Index: mod/quiz/locallib.php =================================================================== RCS file: /cvsroot/moodle/moodle/mod/quiz/locallib.php,v retrieving revision 1.122 diff -u -r1.122 locallib.php --- mod/quiz/locallib.php 17 Sep 2007 16:17:26 -0000 1.122 +++ mod/quiz/locallib.php 20 Sep 2007 13:33:06 -0000 @@ -91,31 +91,6 @@ } /** - * @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. */ function quiz_delete_attempt($attempt, $quiz) {