I've got a situation where I am trying to use the Tincan API Quiz module to report to an LRS.
I want to have good result objects in the statements that describe that a user answered a question.
Unfortunately, when hook_quiz_finished() is fired, and _quiz_get_answers()is called, the answers the user submitted are not available on the questions.
hook_quiz_scored() implementations are not firing at all, ever.
I see that its supposed fire from: quiz_update_total_score(), but that function never runs.
i don't think I'm doing any wild with the quizzes, just trying to make it work with a couple of multiple choice questions, as plain vanilla as I can make it.
what can I do to make hook_quiz_scored() actually fire? Is this a bug, or is something new happening?
I wish that the user's answers actually made it into the hook_quiz_finished implementation(), is there a better way now?
Would it be better if hook_quiz_scored implementations were fired from quiz_end_scoring() instead of quiz_update_total_score() ?
What's the best way to react programmatically and have the answers the user submitted after a person completes a quiz?
Comments
Comment #2
djdevinHi,
In quiz.api.php those hooks have been deprecated so I suggest using the entity hooks instead.
If you want to detect a quiz being scored (manually scored) you can check for the is_evaluated flag.
This would come in with any quiz result update, so
hook_quiz_result_insert()
hook_quiz_result_update()
or, it could be the "Quiz result inserted/update" Rule event.
Then you can just check to see if the original is_evaluated is 0, and the new is_evaluated is 1.
Hope that helps!
Comment #3
markusa CreditAttribution: markusa commentedThanks for the amazingly fast response. I didn't realize the results are now Entities, that's super!
Would those same entity hooks work for "hook_quiz_finished" ? Is the creation of the result entity basically a notification that somebody is finished taking a quiz, or do you have another mechanism for deciding this?
Comment #4
djdevinNo problem, yes it's very nice :) quiz.api.php lists the supported entities.
"Finished" is really up to you regarding the criteria, I would use "is_evaluated" since that is a flag that is set when all questions have been graded, either automatically or manually. The same quiz result hook fires.
But if you wanted to detect the case where a user finished a quiz, but the quiz still required manual grading, you could check the "time_end" flag which would be filled in with a date, or empty if the user has not yet finished.
Comment #5
markusa CreditAttribution: markusa commentedSo if I use the 'is_evaluated' property in a hook_quiz_result_presave() implementation, like so:
It works fine if the system auto-evaluates the quiz.
If I throw a long answer question type in, the quiz result set when it is last updated (when the user finishes the quiz), is not evaluated.
If I then edit the score for the long answer question, the result set will show as evaluated, but the hook never fires...
Is it because if you edit the score for a long answer, that's a quiz_result_answer entity? When I look at the quiz_result entity in question, the score is updated. Is the updating to the score happening by direct sql query, and not by an entity_save() or other Entity API means?
How possible is it to work a "is_finished" property into the Quiz module. It seems this would have been a good property to set. How am I to tell if a quiz_result is finished as far as end user interaction goes, and only now "graders" or other admins would be interacting with the quiz_result?
Comment #6
markusa CreditAttribution: markusa commentedok re-read your post to check for the "time_end" flag
so really the thing is that if I update the long answer score via the result view page and the quiz_result state of is_evaluated goes from 0 to 1, the entity_presave hook is not firing
Comment #7
djdevinI'm rolling this up into #2470103: Refactor scoring system to use Entity and Question API since they touch the same area.