You are here

function matching_update_7400 in Quiz 7.6

Same name and namespace in other branches
  1. 7.4 question_types/matching/matching.install \matching_update_7400()
  2. 7.5 question_types/matching/matching.install \matching_update_7400()

Add a table to store properties for the matching questions

File

question_types/matching/matching.install, line 128
matching install file.

Code

function matching_update_7400() {
  $schema = array(
    'fields' => array(
      'nid' => array(
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
      ),
      'vid' => array(
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
      ),
      'choice_penalty' => array(
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
      ),
    ),
    'primary key' => array(
      'nid',
      'vid',
    ),
  );
  db_create_table('quiz_matching_properties', $schema);

  // Insert default properties for all of the existing matching questions
  $result = db_query("SELECT nid, vid FROM {node} WHERE type='matching'");
  foreach ($result as $question) {
    db_insert('quiz_matching_properties')
      ->fields(array(
      'nid' => $question->nid,
      'vid' => $question->vid,
      'choice_penalty' => 0,
    ))
      ->execute();
  }
}