Role assignment on completion of Quiz

222 views Asked by At

I want to assign the user a role on successful completion of quiz so that a badge based on role can be assigned.

Here is what I have tried: 1. In Quiz module, Taking Options in Edit Quiz, added Assign Action of Node > save content 2. Created a VBO for Quiz which has context parameter of (Quiz) NID and User UID 3. Tried to call this VBO as a condition

Issues: 1. When assign this action, I get an error on Quiz that you need to start again and don't see the content actually getting saved right (shows the results incorrectly) 2. When I try to call the VBO from Rule, it gives me handler error

Questions: 1. Is the approach right or there is a better way to do it? 2. If the approach is fine, any obvious mistakes I am making.

Got this approach from drupal site after much searching - https://www.drupal.org/node/1149930

1

There are 1 answers

0
Mario Araque On

I recommend you to use a quiz hook to do that:

Read it: http://api.dlcdev.com/quiz/doc/html/group__quiz__public.html#ga6dce0ee8805024c0ba2058b8871f3d3b

Quiz has a hook named hook_quiz_finished, that is fired after the last question is submitted.

You have to implement your own module and use it like this:

function yourmodulename_quiz_finished($quiz, $score, $session_data) {
  //$score contains the final score of the quiz
  //$quiz is the object that contains the quiz "pass rate" that you have to compare with score
  //$session_data gives you additional information that you can use to get the uid yo assign the new role
}

Hope it helps.

Regards.