First, a simple solution opening up the quiz module in general:
1. in /mod/quiz/view.php as well as in /mod/quiz/attempt.php exchange the following lines:
old:
if (isguest()) {
print_heading(get_string("guestsno", "quiz"));
print_footer($course);
exit;
}
new:
if ($resource->blockguests == 1) {
require_login($course->id);
if (isguest($USER->id)) {
error(get_string('noguestaccess', 'resource').".");
}
}
Now, if you want to close individual quizzes for guests, extend the moodle data structure in mdl_quiz:
2. with phpMyAdmin or some other tool, add a new field:
name: blockguests
type: tinyint(4)
Default: 0
Manually turning on guest blocking for individual quizzes now works by setting the value 'blockguests' from 0 to 1.
However, if you want to have this more conveniently done by a check option in you quiz setup page, add the following changes:
3. in /mod/quiz/mod.html behind last "</tr>" insert the following lines:
<tr>
<td> </td>
<td>
<input type="checkbox" name="blockguests" value=1 <?php echo ($form->blockguests == "1") ? "checked" : "" ?> >
<?php print_string("blockguests", "resource") ?>
</td>
</tr>
4. in /mod/lang/en/quiz.php insert the line (alphabetically):
$string['blockguests'] = 'Block access by guests';5. in /mod/quiz/lib.php within the function function quiz_update_instance($quiz) behind the line "$quiz->id = $quiz->instance;" insert the following lines:
if (isset($quiz->blockguests)) {
$quiz->blockguests = 1;
} else {
$quiz->blockguests = 0;
}
6. Testing:
When adding or changing a quiz, you should now see the additional option "Block access by guests" on the first page. By selecting this option, continuing to the next page, then saving the complete quiz (!) and re-editing the first page, you should see your selection of the block guests parameter.
Now, running the course as guest, you have access only to those quizzes not marked as "block access by guests".
Good luck,
Klaus