Remove Attempt(orO Preview quiz button before taking or accessing a quiz
Re: Remove Attempt(orO Preview quiz button before taking or accessing a quiz
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.
Re: Remove Attempt(orO Preview quiz button before taking or accessing a quiz
I have implemented it,It is working fine for me!..
Re: Remove Attempt(orO Preview quiz button before taking or accessing a quiz
No, it would need to be
redirect(new moodle_url('/mod/quiz/startattempt.php', array('id' => $cm->id));
Re: Remove Attempt(orO Preview quiz button before taking or accessing a quiz
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...
Re: Remove Attempt(orO Preview quiz button before taking or accessing a quiz
redirect(new moodle_url('/mod/quiz/startattempt.php', array('cmid' => $cm->id, 'sesskey' => sesskey()));
Apologies for getting that wrong before.
Re: Remove Attempt(orO Preview quiz button before taking or accessing a quiz
Thanks, that did the trick!
Re: Remove Attempt(orO Preview quiz button before taking or accessing a quiz
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?
Re: Remove Attempt(orO Preview quiz button before taking or accessing a quiz
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.
Re: Remove Attempt(orO Preview quiz button before taking or accessing a quiz
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?
Re: Remove Attempt(orO Preview quiz button before taking or accessing a quiz
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.
Re: Remove Attempt(orO Preview quiz button before taking or accessing a quiz
Yes. That will do it.
I still don't see much point in your requirement to skip the view.php page the first time.
Re: Remove Attempt(orO Preview quiz button before taking or accessing a quiz
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.
Re: Remove Attempt(orO Preview quiz button before taking or accessing a quiz
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
Re: Remove Attempt(orO Preview quiz button before taking or accessing a quiz
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.
Re: Remove Attempt(orO Preview quiz button before taking or accessing a quiz
Hi,
this doesn't work on pages with other languages right?
Is there a way to make it language agnostic?
thank you!