MDL-40441 fix obscure notice in the quiz.

This can only happen if you have both a user with both a real attempt
and a preview, and then edit the quiz settings.

Also clean up this code a bit.