You are here

short_answer.install in Quiz 7.5

Short_answer questions install file.

File

question_types/short_answer/short_answer.install
View source
<?php

/**
 * @file
 * Short_answer questions install file.
 */

/**
 * Implements hook_install().
 */
function short_answer_install() {

  // Add body field to short answer node.
  quiz_question_add_body_field('short_answer');
  variable_set('node_options_short_answer', array(
    'status',
  ));
}

/**
 * Implements hook_schema().
 */
function short_answer_schema() {

  // Properties for a question nodes go in here:
  $schema['quiz_short_answer_node_properties'] = array(
    'fields' => array(
      'nid' => array(
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
      ),
      'vid' => array(
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
      ),
      'maximum_score' => array(
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 1,
      ),
      // One of (0) textfield and (1) textarea.
      'text_entry_type' => array(
        'type' => 'int',
        'size' => 'tiny',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
      ),
      // One of exact (0), case insensitive (1), regex (2), manual (3).
      'correct_answer_evaluation' => array(
        'type' => 'int',
        'size' => 'tiny',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
      ),
      // Correct answer.
      'correct_answer' => array(
        'type' => 'text',
      ),
      // Feedback if answer is correct.
      'feedback_correct' => array(
        'type' => 'text',
      ),
      // Feedback if answer is incorrect.
      'feedback_incorrect' => array(
        'type' => 'text',
      ),
    ),
    'primary key' => array(
      'nid',
      'vid',
    ),
  );

  // User answers go in here.
  $schema['quiz_short_answer_user_answers'] = array(
    'fields' => array(
      'answer_id' => array(
        'type' => 'serial',
        'unsigned' => TRUE,
        'not null' => TRUE,
      ),
      'result_answer_id' => array(
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => FALSE,
      ),
      'score' => array(
        'type' => 'float',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
      ),
      // This may be set to false if manual scoring is used.
      'is_evaluated' => array(
        'type' => 'int',
        'unsigned' => TRUE,
        'size' => 'tiny',
        'default' => 0,
        'not null' => TRUE,
      ),
      'answer' => array(
        'type' => 'text',
      ),
      'answer_feedback' => array(
        'type' => 'text',
      ),
      'answer_feedback_format' => array(
        'type' => 'varchar',
        'length' => 255,
      ),
    ),
    'primary key' => array(
      'answer_id',
    ),
    'unique keys' => array(
      'result_answer_id' => array(
        'result_answer_id',
      ),
    ),
  );
  return $schema;
}

/**
 * Adding feedback field to table {quiz_short_answer_user_answers}.
 */
function short_answer_update_7401() {
  if (!db_field_exists('quiz_short_answer_user_answers', 'answer_feedback')) {
    $spec = array(
      'type' => 'text',
      'not null' => FALSE,
    );
    db_add_field('quiz_short_answer_user_answers', 'answer_feedback', $spec);
  }
}

/**
 * Adding feedback format field to table {quiz_short_answer_user_answers}.
 */
function short_answer_update_7402() {
  if (!db_field_exists('quiz_short_answer_user_answers', 'answer_feedback_format')) {
    $spec = array(
      'type' => 'varchar',
      'length' => 255,
    );
    db_add_field('quiz_short_answer_user_answers', 'answer_feedback_format', $spec);
  }
}

/**
 * Normalize data storage.
 */
function short_answer_update_7500() {
  db_drop_unique_key('quiz_short_answer_user_answers', 'ids');
  db_add_field('quiz_short_answer_user_answers', 'result_answer_id', array(
    'type' => 'int',
    'unsigned' => TRUE,
    'not null' => FALSE,
  ));
  db_query("UPDATE {quiz_short_answer_user_answers} qtua\n    INNER JOIN {quiz_node_results_answers} qnra ON (qtua.question_nid = qnra.question_nid\n    AND qtua.question_vid = qnra.question_vid\n    AND qtua.result_id = qnra.result_id)\n    SET qtua.result_answer_id = qnra.result_answer_id");
  db_drop_field('quiz_short_answer_user_answers', 'result_id');
  db_drop_field('quiz_short_answer_user_answers', 'question_nid');
  db_drop_field('quiz_short_answer_user_answers', 'question_vid');
  db_add_unique_key('quiz_short_answer_user_answers', 'result_answer_id', array(
    'result_answer_id',
  ));
}

Functions

Namesort descending Description
short_answer_install Implements hook_install().
short_answer_schema Implements hook_schema().
short_answer_update_7401 Adding feedback field to table {quiz_short_answer_user_answers}.
short_answer_update_7402 Adding feedback format field to table {quiz_short_answer_user_answers}.
short_answer_update_7500 Normalize data storage.