You are here

function opigno_scorm_update_8002 in Opigno SCORM 8

Installs the "opigno_scorm_user_answer_results" table.

File

./opigno_scorm.install, line 300
Module install/update functionality.

Code

function opigno_scorm_update_8002() {
  $table = [
    'description' => 'Table storing user H5P answer results.',
    'fields' => [
      'id' => [
        'description' => 'Primary Key.',
        'type' => 'serial',
        'unsigned' => TRUE,
        'not null' => TRUE,
      ],
      'question_id' => [
        'description' => 'Opigno activity ID.',
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
      ],
      'question_vid' => [
        'description' => 'Opigno activity vid.',
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
      ],
      'answer_id' => [
        'description' => 'Opigno answer ID.',
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
      ],
      'answer_vid' => [
        'description' => 'Opigno answer vid.',
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => FALSE,
      ],
      'interaction_id' => [
        'description' => 'Question ID.',
        'type' => 'varchar',
        'length' => 255,
        'not null' => TRUE,
        'default' => '',
      ],
      'interaction_type' => [
        'description' => 'Question type.',
        'type' => 'varchar',
        'length' => 32,
        'not null' => TRUE,
        'default' => '',
      ],
      'description' => [
        'description' => 'Question text.',
        'type' => 'text',
        'size' => 'medium',
      ],
      'correct_responses_pattern' => [
        'description' => 'Correct responses pattern.',
        'type' => 'text',
        'size' => 'medium',
      ],
      'response' => [
        'type' => 'varchar',
        'length' => 255,
        'not null' => TRUE,
        'default' => '',
      ],
      'result' => [
        'type' => 'varchar',
        'length' => 16,
        'not null' => TRUE,
        'default' => '',
      ],
      'timestamp' => [
        'description' => 'Time of question answered',
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
      ],
    ],
    'primary key' => [
      'id',
    ],
    'indexes' => [
      'interaction_id' => [
        'interaction_id',
      ],
      'answer_id' => [
        'answer_id',
      ],
      'answer_vid' => [
        'answer_vid',
      ],
      'question_id' => [
        'question_id',
      ],
      'question_vid' => [
        'question_vid',
      ],
      'timestamp' => [
        'timestamp',
      ],
    ],
  ];
  $schema = \Drupal::database()
    ->schema();
  if (!$schema
    ->tableExists('opigno_scorm_user_answer_results')) {
    $schema
      ->createTable('opigno_scorm_user_answer_results', $table);
  }
}