--- /Users/sbourget/Desktop/MDL/moodle 1.9 CLEAN/mod/quiz/lib.php 2007-06-21 10:02:56.000000000 -0400 +++ /Applications/MAMP/htdocs/moodle19/mod/quiz/lib.php 2007-07-22 09:39:31.000000000 -0400 @@ -12,6 +12,7 @@ require_once($CFG->libdir.'/pagelib.php'); require_once($CFG->libdir.'/questionlib.php'); +require_once("locallib.php"); /// CONSTANTS /////////////////////////////////////////////////////////////////// @@ -893,4 +894,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; + } +// Get Necessary Sirings + $strquiz = get_string('modulename', 'quiz'); + $strquizcloses = get_string('quizcloses', 'quiz'); + $strquizopens = get_string('quizopens', 'quiz'); + $strattempts = get_string('attempts', 'quiz'); + $strnotattempted = get_string('noattempts', 'quiz'); + $strattempted = get_string('attempted', 'quiz'); + + foreach ($quizs as $quiz) { + if ($quiz->timeclose != 0) { // 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)) { + 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; + } + $str .= '
'.$a->attemptnum.' '.$strattempts.'
'; // 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 .= '
'.$strattempted.'
'; + } else { + $numattempts = 0; + $str .= '
'.$strnotattempted.'
'; + } + } + $str .='
'; + // Echo String to Screen + if (empty($htmlarray[$quiz->course]['quiz'])) { + $htmlarray[$quiz->course]['quiz'] = $str; + } else { + $htmlarray[$quiz->course]['quiz'] .= $str; + } + } + } +} + ?> \ No newline at end of file