long_answer.install in Quiz 6.4
Same filename and directory in other branches
- 8.4 question_types/long_answer/long_answer.install
- 6.6 question_types/long_answer/long_answer.install
- 6.3 question_types/long_answer/long_answer.install
- 6.5 question_types/long_answer/long_answer.install
- 7.6 question_types/long_answer/long_answer.install
- 7 question_types/long_answer/long_answer.install
- 7.4 question_types/long_answer/long_answer.install
- 7.5 question_types/long_answer/long_answer.install
Long answer questions.
File
question_types/long_answer/long_answer.installView source
<?php
/**
* Long answer questions.
* @file
*/
/**
* Implementation of hook_install().
*/
function long_answer_install() {
drupal_install_schema('long_answer');
variable_set('node_options_long_answer', array(
'status',
));
cache_clear_all('autoload:', 'cache');
}
/**
* Implementation of hook_uninstall().
*/
function long_answer_uninstall() {
// Delete tables
drupal_uninstall_schema('long_answer');
// Delete data from other tables
// Clear the cache.
cache_clear_all('variables', 'cache');
drupal_set_message(t('The Long Answer module has been uninstalled and related data has been deleted.'));
}
/**
* Implementation of hook_schema().
*/
function long_answer_schema() {
// Properties for a question nodes go in here:
$schema['quiz_long_answer_node_properties'] = array(
'fields' => array(
'nid' => array(
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
),
'vid' => array(
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
),
'rubric' => array(
'type' => 'text',
),
),
'primary key' => array(
'nid',
'vid',
),
);
// User answers go in here.
$schema['quiz_long_answer_user_answers'] = array(
'fields' => array(
'answer_id' => array(
'type' => 'serial',
'unsigned' => TRUE,
'not null' => TRUE,
),
'question_nid' => array(
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
),
'question_vid' => array(
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
),
'result_id' => array(
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
),
'score' => array(
'type' => 'float',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
),
'is_evaluated' => array(
'type' => 'int',
'unsigned' => TRUE,
'size' => 'tiny',
'default' => 0,
'not null' => TRUE,
),
'answer' => array(
'type' => 'text',
),
'answer_feedback' => array(
'type' => 'text',
),
),
'primary key' => array(
'answer_id',
),
'unique keys' => array(
'ids' => array(
'result_id',
'question_nid',
'question_vid',
),
),
);
return $schema;
}
/**
* Implementation of hook_update_N()
*
* Use float instead of int on the score field. This is to better suit the use of max score...
*/
function long_answer_update_6400() {
$results = array();
$spec = array(
'type' => 'float',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
);
db_change_field($results, 'quiz_long_answer_user_answers', 'score', 'score', $spec);
return $results;
}
/**
* Implementation of hook_update_N()
*
* Add a table for storing the rubric
*
* @return
*/
function long_answer_update_6401() {
$results = array();
if (db_table_exists('quiz_long_answer_node_properties') && !db_column_exists('quiz_long_answer_node_properties', 'rubric')) {
db_add_field($results, 'quiz_long_answer_node_properties', 'rubric', array(
'type' => 'text',
));
}
else {
db_create_table($results, 'quiz_long_answer_node_properties', array(
'fields' => array(
'nid' => array(
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
),
'vid' => array(
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
),
'rubric' => array(
'type' => 'text',
),
),
'primary key' => array(
'nid',
'vid',
),
));
$sql = "INSERT INTO {quiz_long_answer_node_properties} (nid, vid)\n SELECT nid, vid FROM node WHERE `type` = 'long_answer'";
$results[] = update_sql($sql);
}
return $results;
}
/**
* Implementation of hook_update_N()
*
* Adding feedback field to table {quiz_short_answer_user_answers}
*/
function long_answer_update_6402() {
$to_return = array();
$spec = array(
'type' => 'text',
'not null' => FALSE,
);
db_add_field($to_return, 'quiz_long_answer_user_answers', 'answer_feedback', $spec);
return $to_return;
}
Functions
Name![]() |
Description |
---|---|
long_answer_install | Implementation of hook_install(). |
long_answer_schema | Implementation of hook_schema(). |
long_answer_uninstall | Implementation of hook_uninstall(). |
long_answer_update_6400 | Implementation of hook_update_N() |
long_answer_update_6401 | Implementation of hook_update_N() |
long_answer_update_6402 | Implementation of hook_update_N() |