Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
hi,
i'm trying to write a feeds importer module plugin for quiz but therefore need some help regarding the starting-point for quiz.
could someone point out
- which function actually adds the quiz functionalities to a node
- which function adds the question functionalities to a node
my idea
- create new node
- [set general node settings]
- save node
- quiz_function_that_adds_settings_to_node( node, quiz_settings )
thanks in advance!
greets
Comments
Comment #1
attisanno-one? really? I could really use a helping hand. (in fact - "a pointing finger" would suffice).
greets
Comment #2
joshf CreditAttribution: 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 CreditAttribution: 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 CreditAttribution: 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 CreditAttribution: 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 CreditAttribution: fishfree commentedHow to do this in 6.0.0-alpha7 version? Thanks!