Closed (fixed)
Project:
Quiz
Version:
7.x-4.0-alpha11
Component:
Documentation
Priority:
Normal
Category:
Support request
Assigned:
Unassigned
Reporter:
Created:
18 Jan 2013 at 14:05 UTC
Updated:
21 Jul 2022 at 12:31 UTC
Jump to comment: Most recent
Comments
Comment #1
attisanno-one? really? I could really use a helping hand. (in fact - "a pointing finger" would suffice).
greets
Comment #2
joshf commentedIt's basically just like any other node. Here's how I was able to accomplish this with a multichoice question:
Comment #3
OliverColeman commentedI guess the API has changed as the arguments supplied to the saveRelationships function in the previous example are missing (at least from 7.x-4.0-beta3). I ended up doing the below (before node_save() on the question node).
Comment #4
djdevinThanks, and for 5.x it is
See also quiz_add_question_to_quiz() as well which is the Views Bulk Operation for adding questions to quizzes.
Comment #5
webservant316 commented#3 above, the Quiz version 4 solution, depends upon the logic of the function saveRelationships() in quiz_question.core.inc. However, if the quiz node properties specify to randomize the questions, yet there are only mandatory questions attached then saveRelationships() fails to attached the questions properly. Agreed it is curious to set the Quiz to randomize and then only attach mandatory questions. However, this situation is handled properly when using the UI to add questions. However, if programmatically adding questions with these settings then #3 does not work.
There may be a better way , but I had to create the function below for guaranteed attachment of all Questions to the Quizzes in my use case...
Comment #6
nasrin_109 commentedfor new version of quiz module we must edit code like below :
$question->alternatives = array(
array(
'answer' => array(
'value' => 'Yes',
'format' => 'plain_text',
),
// All these values are necessary to avoid integrity constraint errors.
// 'answer_format' => 'plain_text',
....
Comment #7
fishfree commentedHow to do this in 6.0.0-alpha7 version? Thanks!