You are here

function quiz_load in Quiz 7

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

Implements hook_load().

File

./quiz.module, line 870
Quiz Module

Code

function quiz_load($nodes) {
  foreach ($nodes as $nid => &$node) {

    // Fetching defaults.
    $default_additions = _quiz_get_node_defaults();

    // Fetching node settings.
    $query = db_select('quiz_node_properties', 'qnp');
    foreach (array_keys($default_additions) as $field) {
      $query
        ->addField('qnp', $field);
    }
    $query
      ->condition('vid', $node->vid);
    $query
      ->condition('nid', $node->nid);
    $fetched_additions = (array) $query
      ->execute()
      ->fetch();
    $additions = $fetched_additions ? (object) ($fetched_additions += $default_additions) : NULL;

    // Fetching result options.
    $query = db_select('quiz_node_result_options', 'qnro');
    $query
      ->fields('qnro');
    $query
      ->condition('nid', $node->nid);
    $query
      ->condition('vid', $node->vid);
    $options = $query
      ->execute();
    foreach ($options as $option) {
      $additions->resultoptions[$option->option_id] = (array) $option;
    }
    foreach ($additions as $property => &$value) {
      $node->{$property} = $value;
    }
  }
}