Award points only for first Attempt

Events happening in the community are now at Drupal community events on www.drupal.org.
sujanstha's picture

I want to allow users to attempt quiz multiple times but award points only for the first attempt. Is this possible?

Thanks in advance.
Special thanks to all the maintainers of the Quiz module. Its really an awesome module.

Comments

Try this ...

gouky10's picture

Hello!
I wanted to do the same so I noticed that there are two hooks that can help: hook_quiz_finished which is called when a user finished a quiz and hook_quiz_scored which is called when the quiz is scored completely like when the quiz need to be sccored manually. See http://drupal.org/node/460456.

However to make only the first attempt award points I had to modified these two hooks in the quiz module: quiz_quiz_finished and quiz_quiz_scored both are in the quiz.module

First I added && _isfirst($quiz, $taker) in lines 2456 and 2494

Then at the end of the page I added:

function _isfirst($quiz, $taker){
$alltake = db_query('SELECT qnr.result_id FROM {quiz_node_results} qnr WHERE nid = :nid AND vid = :vid AND uid = :uid', array(':nid' => $quiz->nid, ':vid' => $quiz->vid, ':uid' => $taker->uid));
$count=0;
foreach($alltake as $take){
  $count++;
}
return !$count;
}

This works for me I hope you can use it.
Regards from Perú

Quiz

Group organizers

Group notifications

This group offers an RSS feed. Or subscribe to these personalized, sitewide feeds:

Hot content this week