You are here

function currency_schema in Currency 7.2

Implements hook_schema().

File

currency/currency.install, line 13

Code

function currency_schema() {
  $schema['currency'] = array(
    'description' => 'Currency information based on ISO 4127.',
    'export' => array(
      'key' => 'ISO4217Code',
      'key name' => 'ISO 4217 code',
      'primary key' => 'ISO4217Code',
      'default hook' => 'currency_info',
      'object' => 'Currency',
      'save callback' => 'currency_save',
      'delete callback' => 'currency_delete',
      'cache defaults' => TRUE,
    ),
    'fields' => array(
      'export_module' => array(
        'type' => 'varchar',
        'length' => 255,
      ),
      'export_type' => array(
        'type' => 'int',
        'length' => 'tiny',
        'not null' => TRUE,
      ),
      'ISO4217Code' => array(
        'type' => 'varchar',
        'length' => 3,
        'not null' => TRUE,
      ),
      'ISO4217Number' => array(
        'type' => 'varchar',
        'length' => 3,
      ),
      'rounding_step' => array(
        'type' => 'int',
      ),
      'sign' => array(
        'type' => 'varchar',
        'length' => 255,
      ),
      'subunits' => array(
        'type' => 'int',
      ),
      'title' => array(
        'type' => 'varchar',
        'length' => 255,
      ),
    ),
    'primary key' => array(
      'ISO4217Code',
    ),
    'indexes' => array(
      'ISO4217Number' => array(
        'ISO4217Number',
      ),
    ),
  );

  // Set Ctools object defaults based on Currency's default values.
  // Manually include the class' file, because the registry may not have been
  // loaded yet.
  require_once __DIR__ . '/includes/Currency.inc';
  foreach (get_class_vars('Currency') as $property => $default_value) {
    if (isset($schema['currency']['fields'][$property])) {
      $schema['currency']['fields'][$property]['object default'] = $default_value;
    }
  }
  $schema['currency_locale_pattern'] = array(
    'description' => 'Locale-specific amount formatting.',
    'export' => array(
      'key' => 'locale',
      'key name' => 'Locale',
      'default hook' => 'currency_locale_pattern_info',
      'object' => 'CurrencyLocalePattern',
      'cache defaults' => TRUE,
    ),
    'fields' => array(
      'export_module' => array(
        'type' => 'varchar',
        'length' => 255,
      ),
      'export_type' => array(
        'type' => 'int',
        'length' => 'tiny',
      ),
      'locale' => array(
        'not null' => TRUE,
        'type' => 'varchar',
        'length' => 255,
      ),
      'pattern' => array(
        'type' => 'varchar',
        'length' => 255,
      ),
      'symbol_decimal_separator' => array(
        'type' => 'varchar',
        'length' => '255',
      ),
      'symbol_grouping_separator' => array(
        'type' => 'varchar',
        'length' => '255',
      ),
    ),
    'primary key' => array(
      'locale',
    ),
  );

  // Set Ctools object defaults based on CurrencyLocalePattern's default
  // values.
  // Manually include the class' file, because the registry may not have been
  // loaded yet.
  require_once __DIR__ . '/includes/CurrencyLocalePattern.inc';
  foreach (get_class_vars('CurrencyLocalePattern') as $property => $default_value) {
    if (isset($schema['currency_locale_pattern']['fields'][$property])) {
      $schema['currency_locale_pattern']['fields'][$property]['object default'] = $default_value;
    }
  }
  $schema['currency_exchanger_fixed_rates'] = array(
    'fields' => array(
      'currency_code_from' => array(
        'type' => 'varchar',
        'length' => 3,
        'not null' => TRUE,
      ),
      'currency_code_to' => array(
        'type' => 'varchar',
        'length' => 3,
        'not null' => TRUE,
      ),
      'rate' => array(
        'type' => 'varchar',
        'length' => 255,
        'not null' => TRUE,
      ),
    ),
    'primary key' => array(
      'currency_code_from',
      'currency_code_to',
    ),
  );
  return $schema;
}