Closing unfinished attempts - possible solution for 1.9

Closing unfinished attempts - possible solution for 1.9

by Sigurdur Smarason -
Number of replies: 19
Hello all,

I needed to close some quiz attempts and rather than doing so by hand I took a crack at putting something together that might work on a quiz by quiz basis.

I'm posting this to save someone the trouble of doing the same and to see if perhaps I missed something that you moodle gurus pick up on. I've tested it with real data on a test setup with moodle 1.9.4 and I hope it will work on all 1.9 variants.

What to do: unzip the contents into your mod/quiz/report folder. It is basically just a new folder called 'closeall' and a single file inside it called 'report.php'

The contents of the file is mostly copy-paste from "attempt.php" with some additions that were needed for this to work. The program does basically three things: the current date is set as the finish date of the attempt, the state for the attempt is put at 6 (close and grade) via the same mechanism as "attempt.php" does it, and the highest answer for the user is updated if needed.

So it probably won't work if the attempt has ungraded answers, but seems to work for answers that are already graded.

To use it just browse to the "Results" section of a quiz, a new menu item "closeall" with some brackets enclosed should become visible to the right of "Item analysis". Click on it and it will print out the id's of the attempts that it closed.

If the menu item for some reason does not show up, you can add the following string to the URL once you have gotten to the Results section "&mode=closeall" and that should get you going.

cheers,
Siggi
Average of ratings: Useful (6)
In reply to Sigurdur Smarason

Re: Closing unfinished attempts - possible solution for 1.9

by Ben McLuckie -
Wow! A great little file. The install is just as easy as you describe, and it works with my 1.9.1+

Perfect - Thanks a lot!
In reply to Sigurdur Smarason

Re: Closing unfinished attempts - possible solution for 1.9

by Raul Garcia Canet -
Hello all,
Great solution!

It worked for me in version 1.9.5 +.

I closed my attempts without answers selected, and no grade.
With this solution, the grade has been set to 0 and the attempt has been closed.

Thanks!!
J. Raul (juagarc4) cool

In reply to Sigurdur Smarason

Re: Closing unfinished attempts - possible solution for 1.9

by David Wong -
Hi Sigurdur,

What do I need to do change the [closeall] header link to different text link like "Close all OPEN quizzes?"

do I just need to modify your additional php file?
In reply to David Wong

Re: Closing unfinished attempts - possible solution for 1.9

by Jean-Michel Védrine -
To enhance this report you need to create some additional filees
For instance to provide a langage string instead of [closeall] you need a subfolder lang/en_utf8 in your closeall folder and you need to create a quiz_closeall.php file in this subfolder with a content like
<?php
$string['closeall'] = 'Close all attempts';
?>
Of couse you can also put some other languages strings in this file and modify your report.php to get a better display during attempts proccessing
Non english users can also create differents subfolders for languages other than en_utf8.
Thank you very much for this very usefull plugin.


Average of ratings: Useful (1)
In reply to Jean-Michel Védrine

Re: Closing unfinished attempts - possible solution for 1.9

by David Wong -
Thanks Jean-Michel...
In reply to Sigurdur Smarason

Re: Closing unfinished attempts - possible solution for 1.9

by Travis Wilhelm -
Thanks Siggi! Just what I was after.

Do you know if it's going to be included in Moodle 2.0? The application I required it for was a "long term" assignment (kind of mini-essay answers) that some students just forgot to "submit" at the end (after a few lessons of working on it in their own time). The harsh thing to say was that they forgot to "hand it up" (so to speak) but this solves that dilemna for me.

Great work!
In reply to Sigurdur Smarason

Re: Closing unfinished attempts - possible solution for 1.9

by Brian Taylor -

I hope you'll forgive my ignorance as a new Moodler. I've read several other threads concerning problems with quiz timing, automatic submission, closing open attempts, etc. and can't help wondering why these functions seem to be implemented on the server side rather than the client side (browser)? 

(At 0.0, submit)...

These functions all depend either directly or indirectly on some sort of countdown timer that could be implemented on the user's system in such a way that it cannot be "fiddled with" by the student, that would persist across browser sessions (closing and reopening the browser "quiz session" would not reset the timer) and which would be much more accurate than the one on the server side because it would eliminate any issues relative to "busy servers", network delay, ISP going down in the middle of a test, etc.,etc.  As long as the 30-minute quiz is closed and submitted (or queued for submission) by the client browser at precisely the 30-minute limit, for instance, it wouldn't matter at all that it happened to arrive and be "logged in" by the server in 31 minutes, or whatever other time.

Just throwing my 2 cents in the pot - fully recognizing that there might be problems with this idea that I'm not seeing.

In reply to Brian Taylor

Re: Closing unfinished attempts - possible solution for 1.9

by Tim Hunt -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers
"some sort of countdown timer that could be implemented on the user's system in such a way that it cannot be "fiddled with" by the student ..."

Such a thing is not possible. The student can tamper with anything on the client-side. That is just a fact of how web browsers are.
Average of ratings: Useful (1)
In reply to Tim Hunt

Re: Closing unfinished attempts - possible solution for 1.9

by Brian Taylor -

"Such a thing is not possible."

Sure it is...unless maybe the student is a software engineer.  You can encrypt the quiz web page so that a timer script can't be "decoded", for instance.  Better yet (since scripts are single-threaded and hence not the best way to implement a timer anyway), you can use a Java applet or other form of executable as part of the quiz payload  instead of a script.  It could be quite tiny and could accomplish other tasks as well (for instance, only allowing the test to be taken while the system is online, etc.)...

There might be other objections to the idea, but "impossibility" isn't one of them unless we're talking "impossibility to the millionth decimal place", and of course any student who's willing to take things that far would almost certainly be cheating in some other (easier) way.

In reply to Brian Taylor

Re: Closing unfinished attempts - possible solution for 1.9

by Tim Hunt -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers
What proportion of users have Java installed? (I'll give you a clue, it is not 100%). Not all users use JavaScript either - and the most important people in that category are users who need to use assistive technology. They have to be able to use the Moodle quiz.

It is a fundamental principle of web-site design. If something needs to be secure and trustworthy, you have to do it on the server side.

Anything we tried to do client-side, it would only take one moderately bright person to create a greasemonkey script to defeat it, and put the instructions for using it on facebook.

That is why the quiz enforces the timing rules on the server. The small problem we have is what happens when network latency becomes big (or server load becomes high so response becomes slow). Why don't you focus on solutions to that small problem, rather than suggesting we change everything to a fundamentally insecure architecture?

It seems plausible to me that we could get the browser to send some sort of time-stamp when submit it pressed, and that could improve the heuristics we use for distinguishing 'slight network delay' from 'student trying to cheat the timer', but I have not yet thought of a scheme that could not be fooled. However, I have not given it much thought.

Just to be clear, what we need in Moodle is a function like

function quiz_was_submitted_in_time($timenow, $sumbitteddata, $quizsettings)

and the question is: what is the best implementation of that function, and can we add anything to $submitteddata or $quizsettings to help?
In reply to Tim Hunt

Re: Closing unfinished attempts - possible solution for 1.9

by ankush bambole -
Thanks Sigurdur,
Solution works for me too..I'm using moodle 1.9.4
In reply to Sigurdur Smarason

Re: Closing unfinished attempts - possible solution for 1.9

by Nadav Kavalerchik -
Picture of Core developers Picture of Plugin developers Picture of Testers Picture of Translators
Thank you for this great improvement.

i'v added a tiny patch: a question (yes/no) should the quiz be closed?
(in case the teacher click it by accident)

$confirm = optional_param('confirm', 0, PARAM_BOOL);
$q = optional_param('q', 0, PARAM_INT);
if (empty($confirm)) {
notice_yesno(get_string('closeallquizattempts','quiz'), 'report.php', 'report.php', array('q' => $q,'confirm' => 'yes','mode'=>'closeall') , array('q' => $q,'confirm' => 'no','mode'=>'overview'), 'get', 'get');
}
if ($confirm == '0') { return true; }

echo get_string('closingallquizattempts','quiz');

you should add it before:

// get all unfinished attempt for the quiz
$attempts= get_records_select('quiz_attempts',
"quiz = '{$quiz->id}' AND timefinish=0 AND preview = 0",
'attempt ASC');

and do not forget to add the closeallquizattempts and closingallquizattempts strings in the quiz.php language files with a clear question.

smile
Average of ratings: Useful (2)
In reply to Sigurdur Smarason

Re: Closing unfinished attempts - possible solution for 1.9

by hon wai lau -

Thanks for this simple plugin. Closing each quiz manually is very tedious. Though it may not be useful for normal quiz, it does occationally happening for the adaptive mode. Simply because people can try it again and again so they are likely not close it and the result is half-filled answers. It should really be considered to add in the moodle 1.9.

In reply to hon wai lau

Re: Closing unfinished attempts - possible solution for 1.9

by Rik Hall -

I am too new at this and not a Server side programmer.  Here is my situation:

I have a student with an "open" quiz that they say they finished, but the professor cannot mark.

What do I do (I am Admin) or what do I tell the professor to do?

Many thanks

Rik

In reply to Rik Hall

Re: Closing unfinished attempts - possible solution for 1.9

by Elena Ivanova -

Hi Rik,

Overall, student just have to click Submit for Grading button, but I guess he cannot do that because of the enforced due date on the quiz.

If you want to use UI only, then teacher can temporarily open the the quiz (extend/remove the due date), and ask that student to login and click Submit for grading. Teacher can even add a password on the quiz, to prevent other students jumping in.

(If your installation and policies allow, you as an Admin can do all of that yourself, by using Login As option)

In reply to Elena Ivanova

Re: Closing unfinished attempts - possible solution for 1.9

by Rik Hall -

Thanks Elena

I am full admin, but it would be neat if there was an easy way for the teacher to just do something that closes it and lets her mark it.

Thanks again.

Any other thoughts out there?

Rik

In reply to Sigurdur Smarason

Re: Closing unfinished attempts - possible solution for 1.9

by Mike Berman -

Do you know if closeall.zip file works with Moodle 2.2? 

In reply to Mike Berman

Re: Closing unfinished attempts - possible solution for 1.9

by Jean-Michel Védrine -

Hello mike,

php script in closeall.zip contains instructions specific to Moodle 1.9 so it will not work with Moodle 2.0/2.1/2.2

But good news is that a proper solution to this problem is currently in developpment (see MDL-3030) and we all hope it can be integrated in upcoming Moodle 2.3.