You are here

quiz_short_answer.module in Quiz 8.6

Short_answer question type for the Quiz module.

Short answer is structurally similar to long answer. However, the module mechanism makes it very difficult for these two modules (either one of which may be disabled) to effectively share code.

File

question_types/quiz_short_answer/quiz_short_answer.module
View source
<?php

/**
 * @file
 * Short_answer question type for the Quiz module.
 *
 * Short answer is structurally similar to long answer. However, the module
 * mechanism makes it very difficult for these two modules (either one of
 * which may be disabled) to effectively share code.
 */

/**
 * Implements hook_help().
 */
function short_answer_help($path, $args) {
  if ($path == 'admin/help#short_answer') {
    return t('This module provides a short answer question type for Quiz.');
  }
}

/**
 * Implements hook_permission().
 */
function short_answer_permission() {
  return array(
    'use regex for short answer' => array(
      'title' => t('use regex for short answer'),
      'description' => t('Use PHP "regular expressions" the advanced option for automated response evaluation.'),
      'restrict access' => TRUE,
    ),
  );
}

/**
 * Implements hook_quiz_question_config().
 */
function short_answer_quiz_question_config() {
  $form['short_answer_default_max_score'] = array(
    '#type' => 'textfield',
    '#title' => t('Default max score'),
    '#description' => t('Choose the default maximum score for a short answer question.'),
    '#default_value' => variable_get('short_answer_default_max_score', 5),
  );
  $form['#validate'][] = 'short_answer_config_validate';
  return $form;
}

/**
 * Validate the short_answer config form values.
 */
function short_answer_config_validate($form, $form_state) {
  if ($form_state['values']['short_answer_default_max_score'] <= 0) {
    form_set_error('short_answer_default_max_score', t('The default max score must be greater than 0'));
  }
}

/**
 * Implements hook_theme().
 */
function short_answer_theme($existing, $type, $theme, $path) {
  $module_path = drupal_get_path('module', 'short_answer');
  return array(
    'short_answer_response_form' => array(
      'render element' => 'form',
      'path' => $module_path . '/theme',
      'file' => 'short_answer.theme.inc',
    ),
    'short_answer_user_answer' => array(
      'variables' => array(
        'answer' => NULL,
        'correct' => NULL,
      ),
      'path' => $module_path . '/theme',
      'file' => 'short_answer.theme.inc',
    ),
    'short_answer_answering_form' => array(
      'render element' => 'form',
      'path' => $module_path . '/theme',
      'template' => 'short-answer-answering-form',
    ),
  );
}

Functions

Namesort descending Description
short_answer_config_validate Validate the short_answer config form values.
short_answer_help Implements hook_help().
short_answer_permission Implements hook_permission().
short_answer_quiz_question_config Implements hook_quiz_question_config().
short_answer_theme Implements hook_theme().