You are here

function _quiz_insert_resultoptions in Quiz 7.4

Same name and namespace in other branches
  1. 8.4 quiz.module \_quiz_insert_resultoptions()
  2. 5.2 quiz.module \_quiz_insert_resultoptions()
  3. 6.6 quiz.module \_quiz_insert_resultoptions()
  4. 6.2 quiz.module \_quiz_insert_resultoptions()
  5. 6.3 quiz.module \_quiz_insert_resultoptions()
  6. 6.4 quiz.module \_quiz_insert_resultoptions()
  7. 6.5 quiz.module \_quiz_insert_resultoptions()
  8. 7.6 quiz.module \_quiz_insert_resultoptions()
  9. 7 quiz.module \_quiz_insert_resultoptions()
  10. 7.5 quiz.module \_quiz_insert_resultoptions()

Insert call specific to result options.

This is called by quiz_insert().

Parameters

$node: The quiz node.

2 calls to _quiz_insert_resultoptions()
quiz_insert in ./quiz.module
Implements hook_insert().
_quiz_update_resultoptions in ./quiz.module
Modify result of option-specific updates.

File

./quiz.module, line 3413
Quiz Module

Code

function _quiz_insert_resultoptions($node) {
  if (!isset($node->resultoptions)) {
    return;
  }
  $query = db_insert('quiz_node_result_options')
    ->fields(array(
    'nid',
    'vid',
    'option_name',
    'option_summary',
    'option_summary_format',
    'option_start',
    'option_end',
  ));
  foreach ($node->resultoptions as $id => $option) {
    if (!empty($option['option_name'])) {

      // When this function called direct from node form submit the $option['option_summary']['value'] and $option['option_summary']['format'] are we need
      // But when updating a quiz node eg. on manage questions page, this values come from loaded node, not from a submitted form.
      if (is_array($option['option_summary'])) {
        $option['option_summary_format'] = $option['option_summary']['format'];
        $option['option_summary'] = $option['option_summary']['value'];
      }
      $query
        ->values(array(
        'nid' => $node->nid,
        'vid' => $node->vid,
        'option_name' => $option['option_name'],
        'option_summary' => $option['option_summary'],
        'option_summary_format' => $option['option_summary_format'],
        'option_start' => $option['option_start'],
        'option_end' => $option['option_end'],
      ));
    }
  }
  $query
    ->execute();
}