Quiz give us the posibility to control "The number of times a user is allowed to take this Quiz".
When "All" option in "Store Results" is checked everything works fine, but if other option ("the best", "the newest") is selected the times counters always shows 1, and the evaluated can still answer the test even if he exceeded the configured number of times for this test.

The origin of the problem is the way quiz compute the taken test per user. It uses a SQL query (quiz.module: line 2324):

$taken = db_query("SELECT COUNT(*) AS takes FROM {quiz_node_results} WHERE uid = :uid AND nid = :nid", array(':uid' => $user->uid, ':nid' => $quiz->nid))->fetchField();

When, Store Results, use All, it will be one record per test application, but when other opción is selected, there will be only one record per user (two records when the test is in progress, because a new record is created during this moment). The proposed solution is to modified the SQL query, in order to have something like this:

$taken = db_query("SELECT MAX(attempt) AS takes FROM {quiz_node_results} WHERE is_evaluated = 1 AND uid = :uid AND nid = :nid", array(':uid' => $user->uid, ':nid' => $quiz->nid))->fetchField();

It works because count the max attempt (a field with the attempt number per record), and with the filter is_evaluated, to avoid count the in progress test. I have a path, but I still testing it. I will post this patch soon.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

rcechang created an issue. See original summary.

rcechang’s picture

Here is the patch

Status: Needs review » Needs work

The last submitted patch, 2: quiz-attempt_counter-2687741-2.patch, failed testing.

djdevin’s picture

Interesting approach, the only issue I see here is that if you set it to "best", then the max of "attempt" might be a different number than you expect. If you can take the quiz 5 times, but you get the best score on the 3rd attempt, you would be able to take the Quiz forever since the value of max(attempt) will always be 3.

Da_Cloud’s picture

Status: Needs work » Fixed

With #2838611: Access denied upon completing a quiz when Store results is set to The best being committed this issue has been resolved as well. The new purging mechanism will take in consideration how many times the user is allowed to take a quiz. If this is a limited amount we'll keep the results which means that all the count queries work again.

Might be a good thing to add some additional test cases to make sure these queries keep working with future updates.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.