You are here

function qcollection_export_quiz in Quiz 6.6

Viewless action that copies the questions of the collection into a new quiz node, then redirects the browser to editing the new quiz

Parameters

$collection_node:

1 string reference to 'qcollection_export_quiz'
qcollection_menu in includes/qcollection/qcollection.module
Implementation of qcollection_menu().

File

includes/qcollection/qcollection.inc, line 209

Code

function qcollection_export_quiz($collection_node) {
  global $user;
  $quiz_node = new stdClass();
  $quiz_node->type = 'quiz';
  $quiz_node->title = t("@quiz of '@qcollection_title' by @user at @unix_time", array(
    '@quiz' => QUIZ_NAME,
    '@qcollection_title' => $collection_node->title,
    '@user' => $user->name,
    '@unix_time' => time(),
  ));
  $quiz_node->teaser = $node->body = $mq->questiontext;
  $quiz_node->uid = $user->uid;
  $quiz_node->status = 0;

  // unpublished by default
  $quiz_node->log = "Autogenerated from item collection nid:{$collection_node->nid},vid:{$collection_node->vid}";
  $quiz_node->pass_rate = variable_get('quiz_default_pass_rate', 75);

  // save it, giving it nid and vid
  node_save($quiz_node);

  // TODO test whether this works in PostgreSQL and in MySQL 4.1 (the minimum for D6)
  // copy all the question relationships from the collection to the new quiz
  $sql = 'INSERT INTO {quiz_node_relationship} (parent_nid, parent_vid, child_nid, child_vid, question_status, weight)
SELECT %d as parent_nid, %d AS parent_vid, child_nid, child_vid, question_status, weight FROM {quiz_node_relationship} qnr
WHERE qnr.parent_nid = %d and qnr.parent_vid = %d';
  db_query($sql, $quiz_node->nid, $quiz_node->vid, $collection_node->nid, $collection_node->vid);

  // take them to edit the quiz that was just automatically made, e.g. node/1434/edit
  $new_nid = $quiz_node->nid;
  drupal_goto('node/' . $new_nid . '/edit');
}