Allow guests to run a quiz

Allow guests to run a quiz

Klaus Schramm發表於
Number of replies: 13
By default, moodle does not allow guests to run a quiz.  However, to invite students to take a look before going through the rather tedious procedure of signing on, you might want to have quizzes open for guests.  You might also consider this change in order to allow your students anonymous access for training quizzes.

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>&nbsp;</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

評比平均分數: -
In reply to Klaus Schramm

p.s.: Allow guests to run a quiz

Klaus Schramm發表於
Sorry, the new code at 1. is:
    if ($quiz->blockguests == 1) {
require_login($course->id);
if (isguest($USER->id)) {
print_heading(get_string("guestsno", "quiz"));
print_footer($course);
exit;
}
}


Klaus
In reply to Klaus Schramm

Re: p.s.: Allow guests to run a quiz

Michael Penney發表於
Cool, but what happens if two guests are in the same quiz? Does this give an error on submit or...?
In reply to Michael Penney

Re: p.s.: Allow guests to run a quiz

Klaus Schramm發表於
There have not been any conflicts, yet.  In my experience, about half of the class prefer to run the quiz anonymously as guests, the rest signs up and gets individual score reports from moodle.  The guest account's list for former quiz runs can get quite long, though.
In reply to Klaus Schramm

Re: p.s.: Allow guests to run a quiz

Piotr B發表於
Hi Klaus.

  I just want to say that it is almost what i was looking forbig grin. I just have one question: is there a possibility for guest to send that finished quiz (answers and points) to an administrator or teacher with their name etc????

Thumbs UP!!!!

Piotr
In reply to Piotr B

Re: p.s.: Allow guests to run a quiz

Klaus Schramm發表於
Can't see how.  There is a global "attempt" number attached to each attempt.  The teacher can display the result if he knows that number.  However, the number is not displayed during the student's attempt.

Anyhow, students can always repeat guest-attempts until their results are perfect.

Klaus
In reply to Klaus Schramm

Re: Allow guests to run a quiz

Michael Kowalczyk發表於
Hi..

the code in attempt.php changed in moodle 1.5 ? to:

if (isguest()) { $wwwroot = $CFG->wwwroot.'/login/index.php'; if (!empty($CFG->loginhttps)) { $wwwroot = str_replace('http','https', $wwwroot); } notice_yesno(get_string('guestno', 'quiz').'

'.get_string('liketologin'), $wwwroot, $_SERVER['HTTP_REFERER']); print_footer($course); exit;

which new code will make guests allow to take a test ?

Thanks for any suggestions
Michael

In reply to Michael Kowalczyk

Re: Allow guests to run a quiz

Heather P發表於

Hi

I too would like to be able to allow guests to run quizzes in Moodle 1.5 I had a bit of a go with the code but made more mess than I solved so if you solve it before I do please share.

Thanks

In reply to Heather P

Re: Allow guests to run a quiz

Michael Penney發表於
Well, an easy way to do this would be to create a user like demo, password demo, and put that info where guests can see it.

But with this method or if you hack the code to let guests take the quiz, there will still be problems. If two people take a quiz as a guest or demo student at the same time, the system will see them as the same person, and scoring will not work correctly.

The system is built to keep careful track of a student's score during a quiz, so hacking it to ignore this is a pretty big undertaking.
In reply to Michael Penney

Re: Allow guests to run a quiz

Michael Kowalczyk發表於
Hmm, i didnt noticed any problems at my old moodle installtion where i had allowed ("hacked") guest to take quizzes.
IMO it is a practicable way to let people see moodle from inside without all the register to the site procedures.
Just click and go 微笑

For the future in moodle I whish an implementation of a "make this quiz available for guest" checkbox, when adding a new set of questions to a quiz.

But by now its still unsolved how to hack the code properly for 1.5+ ?

please help

Michael


In reply to Michael Kowalczyk

Re: Allow guests to run a quiz

Klaus Schramm發表於
Dear Michael:

The checkbox is part of the hack (see above, only for Moodle 1.4.x, yet). When editing a quiz, you can switch guest access on/off with the checkbox.

Take care,
Klaus
In reply to Klaus Schramm

Re: Allow guests to run a quiz

Vinay H S發表於

Hi,

I am not able to find /mod/quiz/mod.html file .do i need to add this file in quiz folder.

In reply to Vinay H S

Re: Allow guests to run a quiz

Vinay H S發表於

i am using moodle 2.0 .i replaced the code with the given code in quiz/view.php but a button continue has displayed when i click on that it takes me to moodle home page ,still i cant able to run the test as a guest user, and i have set permissions to previews,attempt and view the quiz .can you tell me where the priblem is.