matching.install in Quiz 7.6
Same filename and directory in other branches
- 8.4 question_types/matching/matching.install
- 6.6 question_types/matching/matching.install
- 6.3 question_types/matching/matching.install
- 6.4 question_types/matching/matching.install
- 6.5 question_types/matching/matching.install
- 7 question_types/matching/matching.install
- 7.4 question_types/matching/matching.install
- 7.5 question_types/matching/matching.install
matching install file.
File
question_types/matching/matching.installView source
<?php
/**
* @file
* matching install file.
*/
/**
* Implements hook_install().
*/
function matching_install() {
// Add body field to matching node
quiz_question_add_body_field('matching');
variable_set('node_options_matching', array(
'status',
));
}
/**
* Implements hook_schema().
*/
function matching_schema() {
// Properties for a question nodes go in here:
$schema['quiz_matching_properties'] = 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',
),
);
$schema['quiz_matching_node'] = array(
'fields' => array(
'match_id' => array(
'type' => 'serial',
'unsigned' => TRUE,
'not null' => TRUE,
),
'nid' => array(
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
),
'vid' => array(
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
),
'question' => array(
'type' => 'text',
'not null' => TRUE,
),
'answer' => array(
'type' => 'text',
'not null' => TRUE,
),
'feedback' => array(
'type' => 'text',
'not null' => TRUE,
),
),
'primary key' => array(
'match_id',
),
'indexes' => array(
'question_id' => array(
'nid',
'vid',
),
),
);
// User answers go in here.
$schema['quiz_matching_user_answers'] = array(
'fields' => array(
'answer_id' => array(
'type' => 'serial',
'unsigned' => TRUE,
'not null' => TRUE,
),
'match_id' => array(
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
),
'result_id' => array(
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
),
'score' => array(
'type' => 'int',
'size' => 'tiny',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
),
'answer' => array(
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
),
),
'primary key' => array(
'answer_id',
),
);
return $schema;
}
/**
* Implements hook_update_N()
*/
/**
* Add a table to store properties for the matching questions
*/
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();
}
}
Functions
Name | Description |
---|---|
matching_install | Implements hook_install(). |
matching_schema | Implements hook_schema(). |
matching_update_7400 | Add a table to store properties for the matching questions |