// Add MyMoodle support to quiz module
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 = '
';
if($quiz->timeclose != 0) {
$str .= '
'.$strquizcloses.': '.userdate($quiz->timeclose).'
';
} else {
$str .= '
'.$strquizopens.'
';
}
// Count attempts (Most of this code is from mod/quiz/view.php
if (isteacher($quiz->course)) {
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 { // Student
if (isset($USER->id) && ($attempts = quiz_get_user_attempts($quiz->id, $USER->id))) {
$numattempts = count($attempts);
$str .= ''.$strattempted.'
';
} else {
$numattempts = 0;
$str .= ''.$strnotattempted.'
';
}
}
// Echo String to Screen
if (empty($htmlarray[$quiz->course]['quiz'])) {
$htmlarray[$quiz->course]['quiz'] = $str;
} else {
$htmlarray[$quiz->course]['quiz'] .= $str;
}
}
}
}