Having a smaller "number of questions" set for a quiz than the number of questions that are assigned to a quiz with a condition of "always" results in bad math.
From http://drupal.org/node/85983:
#8
Somehow.. and I'll need to try and remember how I did this... I got the following error:
user warning: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '-1' at line 1 query: SELECT question_nid FROM quiz_questions WHERE quiz_nid = 7 AND question_status = 0 ORDER BY RAND() LIMIT 0, -1 in /Applications/MAMP/htdocs/drupal-4-7/includes/database.mysql.inc on line 121.
I believe I had created a quiz, taken it twice, then added a new question to it, then taken it again. My quiz progress indicator also said -100%
#15
I'm trying to remember what I did. :(
At first, my quiz only had 1 question.
Then I gave it two.
OH!
I wonder if I added another question and didn't increment the # of questions on the quiz in the quiz settings.
Let me test.
#16
Yep. that was it. So don't let that hold up this patch -- kind of an edge case. Eventually we'll want to increment this somehow so that doesn't happen, though.
And grumble grumble at the title change. ;) But fine. Once we get something here we can use, I guess we probably should look at naming this module more descriptively then if that's come up that many times.
Comment | File | Size | Author |
---|---|---|---|
#7 | quiz_num_questions2.patch | 7.12 KB | seanbfuller |
#4 | quiz_num_questions.patch | 6.91 KB | seanbfuller |
Comments
Comment #1
webchickThe point of the # of questions was so you could potentially create a large question bank of 200 questions or so, and say that each quiz should only be 10 questions in length.
Seems like it would be pretty easy to solve this with a validation function on the add questions form:
If # of questions either always or random > max number of questions specified on quiz, increase the # of max questions.
Comment #2
seanbfuller CreditAttribution: seanbfuller commentedWould it be valid to say if the number of always questions > the "number of questions" value, increase the "number of questions" value to match the number of "always" questions and let the user know what we did?
This could potentially cut out the random questions, but I think that might OK.
Comment #3
nicholasThompsonimho - number of questions in a quiz should be as follows:
Only always questions, num questions = num selected as always
Always AND Random, min num questions = num of always + 1, max num questions = num always + num random - 1 (allows for a single random change)?
Make sense? Or am I talking crap?
Comment #4
seanbfuller CreditAttribution: seanbfuller commentedHere is a first attempt at fixing this. This patch does the following:
It would be great if drupal would send the user to the "add questions" page after initially creating a quiz, but my brain is too tired to make that happen right now. Otherwise this seems to do the job pretty well.
Comment #5
nicholasThompsonAll good, except...
So if I set 10 always questions + 10 random questions and then set my quiz to 20 questions (which is valid according to your formula) then I'll actually never get any random questions, they'll all be "always" as there are no excess questions to swap with.
In the case of always & random, should the max not be "Always Count + Random Count - 1" so we get at least 1 position to swap random questions in?
Comment #6
seanbfuller CreditAttribution: seanbfuller commentedIf you only have one random question defined, it would never show up. ie- With 10 "always" questions and 1 "random" question, 11 -1 = 10.
I guess I could check for random > 1 before subtracting one from the high range...
I was trying to avoid getting into a lotof tedious and un-intuitive logic, but that doesn't actually seem too
bad.
On the other hand, is it bad to force users to choose one less than the total number of questions? At the very least, it seems that the rules governing the range is complex enough now that I should update the help description of the "number of questions" field.
Comment #7
seanbfuller CreditAttribution: seanbfuller commentedHere's a new version that just adds the rule that I posted above to the validation hook.
I did not update the help text on the number of fields form element because I was having a hard time describing the rules in a meaningful way without using a whole paragraph. I'm going to create a new issue to update the help text and add a note in there concerning the min and max values for this field.
If someone wants to give this the thumbs up, I'll start on the rest of the issues.
Comment #8
seanbfuller CreditAttribution: seanbfuller commentedNicholas gave me a thumbs up to commit this over IM.
Comment #9
seanbfuller CreditAttribution: seanbfuller commentedCommitted
Comment #10
(not verified) CreditAttribution: commented