1

I'm using the latest version of drupal and quiz module. In my custom module, I have created a quiz by using below code

 $quiz = new stdClass();
  $quiz->title = 'Testing Quiz';
  $quiz->type = 'quiz';
  $quiz->language = LANGUAGE_NONE;
  $quiz->uid = 1;
  $quiz->status = 1;
  node_object_prepare($quiz);
  $quiz = node_submit($quiz);
  node_save($quiz);

However, the quiz is created successfully. I have a list of multichoice question, which is imported using feeds module. Now what I want is assign those multichoice question to this custom quiz node.

How can I do this?

1 Answer 1

1

Finally, I got the solution. The below code is used to add the multichoice question node to quiz node.

  $multichoice_node = node_load($nid); //load multichoice question nid  
  $multichoice_node->add_directly = array(
    'latest' => array(
      $quiz->nid. '-'. $quiz->vid => $quiz->nid. '-'. $quiz->vid
    )
  );
  node_save($multichoice_node);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.