You are here

long_answer.install in Quiz 8.4

Long answer questions.

File

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

/**
 * Long answer questions.
 * @file
 */

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

  // TODO The drupal_(un)install_schema functions are called automatically in D7.
  // drupal_install_schema('long_answer')
  \Drupal::config('long_answer.settings')
    ->set('node_options_long_answer', array(
    'status',
  ));
  entity_info_cache_clear();
}

/**
 * Implements hook_uninstall().
 */
function long_answer_uninstall() {

  // Delete tables
  // TODO The drupal_(un)install_schema functions are called automatically in D7.
  // drupal_uninstall_schema('long_answer')
  // Delete data from other tables
  // Clear the cache.
  entity_info_cache_clear();
  drupal_set_message(t('The Long Answer module has been uninstalled and related data has been deleted.'));
}

/**
 * Implements 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;
}

/**
 * Adding feedback field to table {quiz_long_answer_user_answers}
 */
function long_answer_update_7401() {
  $spec = array(
    'type' => 'text',
    'not null' => FALSE,
  );
  db_add_field('quiz_long_answer_user_answers', 'answer_feedback', $spec);
}

Functions

Namesort descending Description
long_answer_install Implements hook_install().
long_answer_schema Implements hook_schema().
long_answer_uninstall Implements hook_uninstall().
long_answer_update_7401 Adding feedback field to table {quiz_long_answer_user_answers}