Remove Attempt(orO Preview quiz button before taking or accessing a quiz

Remove Attempt(orO Preview quiz button before taking or accessing a quiz

by Bala kumar -
Number of replies: 16
Hi,

We want to show the moodle quiz directly to our students when they click on the appropriate quiz link.

We don't want to display the confirmation section like Attempt/Preview quiz.Could any one help me in Tweeking the quiz code and getting this done!..




Average of ratings: -
In reply to Bala kumar

Re: Remove Attempt(orO Preview quiz button before taking or accessing a quiz

by Tim Hunt -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers
A quick and dirty way would be to add something like

if (has_capabilitiy('mod/quiz:attempt', $context)) {
redirect($CFG->wwwroot . '/mod/quiz/attempt.php?q=' . $quiz->id);
}

somewhere near the top of mod/quiz/view.php. It think that should work. You might need to put that at the place where the script has already worked out whether this student should be allowed to attempt this quiz right now.
In reply to Tim Hunt

Re: Remove Attempt(orO Preview quiz button before taking or accessing a quiz

by Bala kumar -
Thanks Tim,

I have implemented it,It is working fine for me!..
In reply to Tim Hunt

Re: Remove Attempt(orO Preview quiz button before taking or accessing a quiz

by Rij Blr -

Hi Tim,

Is the following still valid in moodle 2.0?

redirect($CFG->wwwroot . '/mod/quiz/attempt.php?q=' . $quiz->id);

Thanks,
RJ

In reply to Rij Blr

Re: Remove Attempt(orO Preview quiz button before taking or accessing a quiz

by Tim Hunt -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers

No, it would need to be

redirect(new moodle_url('/mod/quiz/startattempt.php', array('id' => $cm->id));

In reply to Tim Hunt

Re: Remove Attempt(orO Preview quiz button before taking or accessing a quiz

by Max Elander -

Well, that doesn't seem to work in 2.1, any pointers on how to get it working there? 

I get "missing parameter cmid", and when I try to alleviate that by changing the "array('id'->$id)" to "array('cmid'->$id)" I instead get "missing parameter sesskey" so I obviously don't know what I'm doing...

In reply to Max Elander

Re: Remove Attempt(orO Preview quiz button before taking or accessing a quiz

by Tim Hunt -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers

redirect(new moodle_url('/mod/quiz/startattempt.php', array('cmid' => $cm->id, 'sesskey' => sesskey()));

Apologies for getting that wrong before.

In reply to Tim Hunt

Re: Remove Attempt(orO Preview quiz button before taking or accessing a quiz

by Max Elander -

Thanks, that did the trick!

In reply to Max Elander

Re: Remove Attempt(orO Preview quiz button before taking or accessing a quiz

by Max Elander -

Well, it did the trick, but now I keep getting back to the first question page whenever I click "Submit all and finish", so the quiz repeats indefinitely, I don't get to see the summary after the quiz either, and that is not good. Then the student will never know if he's done or not.

 

I'm probably inserting the code in the wrong place or perhaps I need to surrond the line with a special condition?

In reply to Max Elander

Re: Remove Attempt(orO Preview quiz button before taking or accessing a quiz

by Tim Hunt -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers

Yes, we need to only do the redirect conditionally. I suggest moving it to just before the 

$output->header();

line and wrapping it in

if ($buttontext) {

}

That will cause it to only redirect if the student is allowed another attempt.

Possibly 

if (!empty($lastfinishedattempt)) {

is better logic. It depends what you want.

In reply to Tim Hunt

Re: Remove Attempt(orO Preview quiz button before taking or accessing a quiz

by Max Elander -

Sorry but none of these work, still in an infinite loop. As soon as I click "Submit all and finish", and click "Yes" in the alert box asking if I want to finish the attempt, I get redirected to the first question page again.

Problem is, students are allowed unlimited number of attempts, so testing if he is allowed another attempt is not enough: he always is, so the condition is always true. 

I guess what I need is a way to determine if I'm coming to view.php from the summary page or not. If I am, I shouldn't redirect, and if I'm not I should. Problem is, as far as I can see, that we never come straight from summary.php, but pass through processattempt.php first, maybe we can check for that?

In reply to Max Elander

Re: Remove Attempt(orO Preview quiz button before taking or accessing a quiz

by Max Elander -

Found a halfway solution. In view.php there is a check to see if there are any previous attempts (line 196 , if($viewobj->numattempts==0)).

 

If I put the redirect there instead of $buttontext=get_string('attemptquiznow','quiz'), it will only redirect the first time a student tries a quiz, but all other times it will show the table with attempt data, which actually makes sense.

In reply to Max Elander

Re: Remove Attempt(orO Preview quiz button before taking or accessing a quiz

by Tim Hunt -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers

Yes. That will do it.

I still don't see much point in your requirement to skip the view.php page the first time.

In reply to Tim Hunt

Re: Remove Attempt(orO Preview quiz button before taking or accessing a quiz

by Max Elander -

Well, I don't see the point of having a page where the only thing yuo can do is to click a button that does what the original link should have done: take you to the quiz.

Sure, once you'v e done the quiz, then it makes sense to view previous results, but the first time it's just an extra, and in my view, unnecessary step.

Average of ratings: Useful (1)
In reply to Max Elander

Re: Remove Attempt(orO Preview quiz button before taking or accessing a quiz

by Jacob Westerhof -

Max,

Am interested in implementing the same code, do you have that working for Moodle 2.3.  I can not seem to make it work.

thanks

Jacob

In reply to Jacob Westerhof

Re: Remove Attempt(orO Preview quiz button before taking or accessing a quiz

by Eugene Venter -

Hi Jacob,

See the attached patch file, for what I modified in mod/quiz/renderer.php to skip the summary/review page.

I basically added the submit button to the last page of the quiz.

Hope this helps ;)

Eugene.

In reply to Eugene Venter

Re: Remove Attempt(orO Preview quiz button before taking or accessing a quiz

by David Castillo -

Hi,

this doesn't work on pages with other languages right?

 

Is there a way to make it language agnostic?

 

thank you!