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

  1. create new node
  2. [set general node settings]
  3. save node
  4. quiz_function_that_adds_settings_to_node( node, quiz_settings )

thanks in advance!

greets

Comments

attisan’s picture

no-one? really? I could really use a helping hand. (in fact - "a pointing finger" would suffice).

greets

joshf’s picture

Issue summary:View changes

It's basically just like any other node. Here's how I was able to accomplish this with a multichoice question:

<?php
global $user;

$quiz = new stdClass();
$quiz->title = 'Loyalty Test';
$quiz->type = 'quiz';
$quiz->language = LANGUAGE_NONE;
$quiz->uid = $user->uid;
$quiz->status = 1;

node_object_prepare($quiz);
$quiz = node_submit($quiz);
node_save($quiz);

$question = new stdClass();
$question->title = 'User is a fan';
$question->type = 'multichoice';
$question->body = array(LANGUAGE_NONE => array(array('value' => 'Do you totally love this website or what?')));
$question->choice_multi = 0;
$question->choice_random = 0;
$question->choice_boolean = 0;
$question->language = LANGUAGE_NONE;
$question->uid = $user->uid;
$question->status = 1;
$question->alternatives = array(
  array(
   
'answer' => array(
     
'value' => 'Yes',
    ),
   
// All these values are necessary to avoid integrity constraint errors.
   
'answer_format' => 'plain_text',
   
'feedback_if_chosen_format' => 'plain_text',
   
'feedback_if_not_chosen_format' => 'plain_text',
   
'score_if_chosen' => 1,
  ),
  array(
   
'answer' => array(
     
'value' => 'No',
    ),
   
'answer_format' => 'plain_text',
   
'feedback_if_chosen_format' => 'plain_text',
   
'feedback_if_not_chosen_format' => 'plain_text',
   
'score_if_chosen' => 0,
  ),
);

node_object_prepare($question);
$question = node_submit($question);
node_save($question);

// This is how you add a question to a quiz.
module_load_include('inc', 'multichoice', 'multichoice.classes');
$question_wrapper = new MultichoiceQuestion($question);
$question_wrapper->saveRelationships($quiz->nid, $quiz->vid);
quiz_update_max_score_properties(array($quiz->vid));
?>