Recording Teacher/Administrator quiz attempts & grades in 1.9

Recording Teacher/Administrator quiz attempts & grades in 1.9

by Matt Campbell -
Number of replies: 7
We just rolled out our annual sexual harassment training that everyone must take. Last year, we were using Moodle 1.7 at the time and I was able to add the administrators and teachers in as students, and their quiz attempts and grades were recorded and available.

I tried this again now that we're using 1.9, and this doesn't seem to work.

Now, my concern isn't that they're able to edit the questions even while they take the quiz and get the answers (I have logs that record that!) - it's that the grade is recorded.

I made three quick changes to /mod/quiz/attempt.php, and now their attempts AND grades for quizzes are recorded. If this is helpful to anyone, here's what I did:

At line 191-192:

if ($ispreviewing) {
$attempt->preview = 1;

Changed to:

if ($ispreviewing) {
$attempt->preview = 0;

Lines 366-368:

if (($attempt->attempt > 1 || $attempt->timefinish > 0) and !$attempt->preview)
quiz_save_best_grade($quiz);
}

Changed to:

/// if (($attempt->attempt > 1 || $attempt->timefinish > 0) and !$attempt->preview) { HACK - to record Teacher & Administrator attempts in mdl_quiz_attempts
quiz_save_best_grade($quiz);
/// }

Thought I would share this in case anyone else needs it.

Thanks,
Matt



Average of ratings: -
In reply to Matt Campbell

Re: Recording Teacher/Administrator quiz attempts & grades in 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
To expand a bit more on what the problem is:

There are two capabilities in the quiz module, mod/quiz:attempt, and mod/quiz:preview. Normally it is simple, students get the capability mod/quiz:attempt, and teachers get the capability mod/quiz:preview, and everything works as expected.

The difficulty is when, via the inner workings of the roles system, a user has both mod/quiz:attempt and mod/quiz:preview capabilites on the same quiz. The two most common causes of this are
  1. admin users. Admins have the super capability moodle/site:doanything, which means that whatever other capability you enquire about, it returns true.
  2. when a user is made both a teacher and a student in a course.
The question is, what to do then? So far, I have consistently applied the following principle: mod/quiz:preview supercedes mod/quiz:attempt, so if you have both capabilites, you can only preview. That is simple, and is the right thing in case 1. above. In case 2., it is not clear what the right thing to do is. The right thing may depend on the exact circumstances.

Instead of hacking the code, you should be able to allow all teachers and admins to do a quiz by using roles overrides to make sure they don't have mod:quiz/preview or moodle:site/doanything on the quiz in question.
In reply to Tim Hunt

Re: Recording Teacher/Administrator quiz attempts & grades in 1.9

by John Isner -
Tim,
Would it be technically feasible to allow a user with both capabilities allowed to both preview AND attempt? For example, add an "Attempt quiz now" button just below the "Preview quiz now" button?
In reply to John Isner

Re: Recording Teacher/Administrator quiz attempts & grades in 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
That probably is the right solution long-term, but it is not trivial to implement, and this has been a problem since Moodle 1.8 was released about a year ago, and this is the first complaint I have heard, so I don't think fixing it is a very high priority. By all means file it in the tracker so we don't forget.
In reply to Tim Hunt

Re: Recording Teacher/Administrator quiz attempts & grades in 1.9

by Matt Campbell -
Thanks, Tim.

This does not seem to work for Administrators. moodle:site/doanything does not show up in the role overrides for the administrator, and setting mod:quiz/preview to prevent did not change this. I'm still stuck with my hack, or creating a non-admin account for myself if I want my quiz to count.

However, this works for Teachers: set mod:quiz/preview to prevent and assign the student role to the teacher. Then, teachers are able to take the quiz and have their results recorded.

Thanks,
Matt
In reply to Matt Campbell

Re: Recording Teacher/Administrator quiz attempts & grades in 1.9

by John Isner -
Matt,
You wrote

for Teachers: set mod:quiz/preview to prevent and assign the student role to the teacher. Then, teachers are able to take the quiz and have their results recorded.


Just to clarify: did you override the Teacher role in the quiz context, setting Preview to Prevent?
In reply to John Isner

Re: Recording Teacher/Administrator quiz attempts & grades in 1.9

by Matt Campbell -
John,

That is correct. The teacher will get an attempt quiz button under the preview tab, and all other capabilities are still present (view results, etc.)

I wouldn't recommend setting this until you're happy with the quiz layout.

Thanks,
Matt
Average of ratings: Useful (1)