MDL-6376 - Include quizzes on the MyMoodle page. Initial implementation by Stephen Bourget, with refinements by Tim Hunt. The logic for which quizzes are listed is very similar to the lesson module.
This commit is contained in:
@@ -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';
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
||||
@@ -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.
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user