You are here

function _units_default_default_units_unit in Units of Measurement 7.2

Same name and namespace in other branches
  1. 7 units_default/units_default.module \_units_default_default_units_unit()

Generate all default units this module can provide.

2 calls to _units_default_default_units_unit()
units_default_default_units_unit in units_default/units_default.module
Implements hook_default_units_unit().
units_default_form in units_default/units_default.pages.inc
Form to manage default units and measures.

File

units_default/units_default.module, line 127
Create common units and measures such as length, volume, weight, etc.

Code

function _units_default_default_units_unit() {
  $items = array();
  $controller = entity_get_controller('units_unit');
  $meter = units_unit_machine_name_load('meter');
  $kilogram = units_unit_machine_name_load('kilogram');
  $second = units_unit_machine_name_load('second');
  $celsius = units_unit_machine_name_load('celsius');
  $items['meter'] = $controller
    ->create(array(
    'measure' => 'length',
    'machine_name' => 'meter',
    'label' => 'meter',
    'symbol' => 'm',
    'description' => '',
    'decomposition' => NULL,
  ));

  // Since all length units decompose into meter, we must assure that meter
  // exists before we can define the other units.
  if ($meter) {
    $items['millimeter'] = $controller
      ->create(array(
      'measure' => 'length',
      'machine_name' => 'millimeter',
      'label' => 'millimeter',
      'symbol' => 'mm',
      'description' => '',
      'decomposition' => units_mathematical_expression_create_from_postfix('0.001 meter *'),
    ));
    $items['centimeter'] = $controller
      ->create(array(
      'measure' => 'length',
      'machine_name' => 'centimeter',
      'label' => 'centimeter',
      'symbol' => 'cm',
      'description' => '',
      'decomposition' => units_mathematical_expression_create_from_postfix('0.01 meter *'),
    ));
    $items['decimeter'] = $controller
      ->create(array(
      'measure' => 'length',
      'machine_name' => 'decimeter',
      'label' => 'decimeter',
      'symbol' => 'dm',
      'description' => '',
      'decomposition' => units_mathematical_expression_create_from_postfix('0.1 meter *'),
    ));
    $items['kilometer'] = $controller
      ->create(array(
      'measure' => 'length',
      'machine_name' => 'kilometer',
      'label' => 'kilometer',
      'symbol' => 'km',
      'description' => '',
      'decomposition' => units_mathematical_expression_create_from_postfix('1000 meter *'),
    ));
    $items['foot'] = $controller
      ->create(array(
      'measure' => 'length',
      'machine_name' => 'foot',
      'label' => 'foot',
      'symbol' => 'ft',
      'description' => '',
      'decomposition' => units_mathematical_expression_create_from_postfix('0.3048 meter *'),
    ));
    $items['inch'] = $controller
      ->create(array(
      'measure' => 'length',
      'machine_name' => 'inch',
      'label' => 'inch',
      'symbol' => 'in',
      'description' => '',
      'decomposition' => units_mathematical_expression_create_from_postfix('0.0254 meter *'),
    ));
    $items['mile'] = $controller
      ->create(array(
      'measure' => 'length',
      'machine_name' => 'mile',
      'label' => 'mile',
      'symbol' => 'mi',
      'description' => '',
      'decomposition' => units_mathematical_expression_create_from_postfix('1609.344 meter *'),
    ));
    $items['yard'] = $controller
      ->create(array(
      'measure' => 'length',
      'machine_name' => 'yard',
      'label' => 'yard',
      'symbol' => 'yd',
      'description' => '',
      'decomposition' => units_mathematical_expression_create_from_postfix('0.9144 meter *'),
    ));
    $items['square_meter'] = $controller
      ->create(array(
      'measure' => 'area',
      'machine_name' => 'square_meter',
      'label' => 'square meter',
      'symbol' => 'm2',
      'description' => '',
      'decomposition' => units_mathematical_expression_create_from_postfix('meter 2 ^'),
    ));
    $items['acre'] = $controller
      ->create(array(
      'measure' => 'area',
      'machine_name' => 'acre',
      'label' => 'acre',
      'symbol' => 'acre',
      'description' => '',
      'decomposition' => units_mathematical_expression_create_from_postfix('4.046873e+3 meter 2 ^ *'),
    ));
    $items['are'] = $controller
      ->create(array(
      'measure' => 'area',
      'machine_name' => 'are',
      'label' => 'are',
      'symbol' => 'a',
      'description' => '',
      'decomposition' => units_mathematical_expression_create_from_postfix('1.0e+2 meter 2 ^ *'),
    ));
    $items['hectare'] = $controller
      ->create(array(
      'measure' => 'area',
      'machine_name' => 'hectare',
      'label' => 'hectare',
      'symbol' => 'ha',
      'description' => '',
      'decomposition' => units_mathematical_expression_create_from_postfix('1.0e+4 meter 2 ^ *'),
    ));
    $items['cubic_meter'] = $controller
      ->create(array(
      'measure' => 'volume',
      'machine_name' => 'cubic_meter',
      'label' => 'cubic meter',
      'symbol' => 'm3',
      'description' => '',
      'decomposition' => units_mathematical_expression_create_from_postfix('meter 3 ^'),
    ));
    $items['liter'] = $controller
      ->create(array(
      'measure' => 'volume',
      'machine_name' => 'liter',
      'label' => 'liter',
      'symbol' => 'L',
      'description' => '',
      'decomposition' => units_mathematical_expression_create_from_postfix('0.001 meter 3 ^ *'),
    ));
    $items['milliliter'] = $controller
      ->create(array(
      'measure' => 'volume',
      'machine_name' => 'milliliter',
      'label' => 'milliliter',
      'symbol' => 'mL',
      'description' => '',
      'decomposition' => units_mathematical_expression_create_from_postfix('0.000001 meter 3 ^ *'),
    ));
    $items['cup'] = $controller
      ->create(array(
      'measure' => 'volume',
      'machine_name' => 'cup',
      'label' => 'cup',
      'symbol' => 'cup',
      'description' => '',
      'decomposition' => units_mathematical_expression_create_from_postfix('2.365882e-04 meter 3 ^ *'),
    ));
    $items['us_gallon'] = $controller
      ->create(array(
      'measure' => 'volume',
      'machine_name' => 'us_gallon',
      'label' => 'US gallon',
      'symbol' => 'gal',
      'description' => '',
      'decomposition' => units_mathematical_expression_create_from_postfix('3.785412e-03 meter 3 ^ *'),
    ));
    $items['us_fluid_ounce'] = $controller
      ->create(array(
      'measure' => 'volume',
      'machine_name' => 'us_fluid_ounce',
      'label' => 'US fluid ounce',
      'symbol' => 'fl oz',
      'description' => '',
      'decomposition' => units_mathematical_expression_create_from_postfix('2.957353e-05 meter 3 ^ *'),
    ));
    $items['us_liquid_pint'] = $controller
      ->create(array(
      'measure' => 'volume',
      'machine_name' => 'us_liquid_pint',
      'label' => 'US pint (liquid)',
      'symbol' => 'pt',
      'description' => '',
      'decomposition' => units_mathematical_expression_create_from_postfix('4.731765e-04 meter 3 ^ *'),
    ));
    $items['us_liquid_quart'] = $controller
      ->create(array(
      'measure' => 'volume',
      'machine_name' => 'us_liquid_quart',
      'label' => 'US quart (liquid)',
      'symbol' => 'qt',
      'description' => '',
      'decomposition' => units_mathematical_expression_create_from_postfix('9.463529e-04 meter 3 ^ *'),
    ));
    $items['tablespoon'] = $controller
      ->create(array(
      'measure' => 'volume',
      'machine_name' => 'tablespoon',
      'label' => 'tablespoon',
      'symbol' => 'tbsp',
      'description' => '',
      'decomposition' => units_mathematical_expression_create_from_postfix('1.478676e-05 meter 3 ^ *'),
    ));
    $items['teaspoon'] = $controller
      ->create(array(
      'measure' => 'volume',
      'machine_name' => 'teaspoon',
      'label' => 'teaspoon',
      'symbol' => 'tspn',
      'description' => '',
      'decomposition' => units_mathematical_expression_create_from_postfix('4.928922E-06 meter 3 ^ *'),
    ));
  }
  if (units_unit_machine_name_load('foot')) {
    $items['square_foot'] = $controller
      ->create(array(
      'measure' => 'area',
      'machine_name' => 'square_foot',
      'label' => 'square foot',
      'symbol' => 'ft2',
      'description' => '',
      'decomposition' => units_mathematical_expression_create_from_postfix('foot 2 ^'),
    ));
    $items['cubic_foot'] = $controller
      ->create(array(
      'measure' => 'volume',
      'machine_name' => 'cubic_foot',
      'label' => 'cubic foot',
      'symbol' => 'ft3',
      'description' => '',
      'decomposition' => units_mathematical_expression_create_from_postfix('foot 3 ^'),
    ));
  }
  if (units_unit_machine_name_load('inch')) {
    $items['square_inch'] = $controller
      ->create(array(
      'measure' => 'area',
      'machine_name' => 'square_inch',
      'label' => 'square inch',
      'symbol' => 'in2',
      'description' => '',
      'decomposition_postfix' => units_mathematical_expression_create_from_postfix('inch 2 ^'),
    ));
    $items['cubic_inch'] = $controller
      ->create(array(
      'measure' => 'volume',
      'machine_name' => 'cubic_inch',
      'label' => 'cubic inch',
      'symbol' => 'in3',
      'description' => '',
      'decomposition' => units_mathematical_expression_create_from_postfix('inch 3 ^'),
    ));
  }
  if (units_unit_machine_name_load('kilometer')) {
    $items['square_kilometer'] = $controller
      ->create(array(
      'measure' => 'area',
      'machine_name' => 'square_kilometer',
      'label' => 'square kilometer',
      'symbol' => 'km2',
      'description' => '',
      'decomposition' => units_mathematical_expression_create_from_postfix('kilometer 2 ^'),
    ));
  }
  if (units_unit_machine_name_load('mile')) {
    $items['square_mile'] = $controller
      ->create(array(
      'measure' => 'area',
      'machine_name' => 'square_mile',
      'label' => 'square mile',
      'symbol' => 'mi2',
      'description' => '',
      'decomposition' => units_mathematical_expression_create_from_postfix('mile 2 ^'),
    ));
    $items['cubic_mile'] = $controller
      ->create(array(
      'measure' => 'volume',
      'machine_name' => 'cubic_mile',
      'label' => 'cubic mile',
      'symbol' => 'mi3',
      'description' => '',
      'decomposition' => units_mathematical_expression_create_from_postfix('mile 3 ^'),
    ));
  }
  if (units_unit_machine_name_load('yard')) {
    $items['square_yard'] = $controller
      ->create(array(
      'measure' => 'area',
      'machine_name' => 'square_yard',
      'label' => 'square yard',
      'symbol' => 'yd2',
      'description' => '',
      'decomposition' => units_mathematical_expression_create_from_postfix('yard 2 ^'),
    ));
    $items['cubic_yard'] = $controller
      ->create(array(
      'measure' => 'volume',
      'machine_name' => 'cubic_yard',
      'label' => 'cubic yard',
      'symbol' => 'yd3',
      'description' => '',
      'decomposition' => units_mathematical_expression_create_from_postfix('yard 3 ^'),
    ));
  }
  $items['kilogram'] = $controller
    ->create(array(
    'measure' => 'weight',
    'machine_name' => 'kilogram',
    'label' => 'kilogram',
    'symbol' => 'kg',
    'description' => '',
    'decomposition' => NULL,
  ));
  if ($kilogram) {
    $items['milligram'] = $controller
      ->create(array(
      'measure' => 'weight',
      'machine_name' => 'milligram',
      'label' => 'milligram',
      'symbol' => 'mg',
      'description' => '',
      'decomposition' => units_mathematical_expression_create_from_postfix('0.000001 kilogram *'),
    ));
    $items['gram'] = $controller
      ->create(array(
      'measure' => 'weight',
      'machine_name' => 'gram',
      'label' => 'gram',
      'symbol' => 'g',
      'description' => '',
      'decomposition' => units_mathematical_expression_create_from_postfix('0.001 kilogram *'),
    ));
    $items['carat'] = $controller
      ->create(array(
      'measure' => 'weight',
      'machine_name' => 'carat',
      'label' => 'carat',
      'symbol' => 'CD',
      'description' => '',
      'decomposition' => units_mathematical_expression_create_from_postfix('2.0e-4 kilogram *'),
    ));
    $items['ounce'] = $controller
      ->create(array(
      'measure' => 'weight',
      'machine_name' => 'ounce',
      'label' => 'ounce',
      'symbol' => 'oz',
      'description' => '',
      'decomposition' => units_mathematical_expression_create_from_postfix('2.834952e-02 kilogram *'),
    ));
    $items['pennyweight'] = $controller
      ->create(array(
      'measure' => 'weight',
      'machine_name' => 'pennyweight',
      'label' => 'pennyweight',
      'symbol' => 'dwt',
      'description' => '',
      'decomposition' => units_mathematical_expression_create_from_postfix('1.555174e-03 kilogram *'),
    ));
    $items['pound'] = $controller
      ->create(array(
      'measure' => 'weight',
      'machine_name' => 'pound',
      'label' => 'pound',
      'symbol' => 'lb',
      'description' => '',
      'decomposition' => units_mathematical_expression_create_from_postfix('4.535924e-01 kilogram *'),
    ));
    $items['ton'] = $controller
      ->create(array(
      'measure' => 'weight',
      'machine_name' => 'ton',
      'label' => 'ton',
      'symbol' => 't',
      'description' => '',
      'decomposition' => units_mathematical_expression_create_from_postfix('1.0e+3 kilogram *'),
    ));
  }
  if ($meter && $second && $kilogram) {
    $items['newton'] = $controller
      ->create(array(
      'measure' => 'force',
      'machine_name' => 'newton',
      'label' => 'newton',
      'symbol' => 'N',
      'description' => '',
      'decomposition' => units_mathematical_expression_create_from_postfix('kilogram meter * second 2 ^ /'),
    ));
    $items['pascal'] = $controller
      ->create(array(
      'measure' => 'pressure',
      'machine_name' => 'pascal',
      'label' => 'pascal',
      'symbol' => 'pa',
      'description' => '',
      'decomposition' => units_mathematical_expression_create_from_postfix('kilogram meter / second 2 ^ /'),
    ));
  }
  if (units_unit_machine_name_load('pascal')) {
    $items['torr'] = $controller
      ->create(array(
      'measure' => 'pressure',
      'machine_name' => 'torr',
      'label' => 'torr',
      'symbol' => 'Torr',
      'description' => '',
      'decomposition' => units_mathematical_expression_create_from_postfix('1.333224e+2 pascal *'),
    ));
    $items['bar'] = $controller
      ->create(array(
      'measure' => 'pressure',
      'machine_name' => 'bar',
      'label' => 'bar',
      'symbol' => 'bar',
      'description' => '',
      'decomposition' => units_mathematical_expression_create_from_postfix('1.0e+5 pascal *'),
    ));
    $items['millibar'] = $controller
      ->create(array(
      'measure' => 'pressure',
      'machine_name' => 'millibar',
      'label' => 'millibar',
      'symbol' => 'mb',
      'description' => '',
      'decomposition' => units_mathematical_expression_create_from_postfix('1.0e+2 pascal *'),
    ));
    $items['psi'] = $controller
      ->create(array(
      'measure' => 'pressure',
      'machine_name' => 'psi',
      'label' => 'psi',
      'symbol' => 'lbf/in2',
      'description' => '',
      'decomposition' => units_mathematical_expression_create_from_postfix('6.894757e+3 pascal *'),
    ));
  }
  $items['second'] = $controller
    ->create(array(
    'measure' => 'time',
    'machine_name' => 'second',
    'label' => 'second',
    'symbol' => 's',
    'description' => '',
    'decomposition' => NULL,
  ));
  if ($second) {
    $items['minute'] = $controller
      ->create(array(
      'measure' => 'time',
      'machine_name' => 'minute',
      'label' => 'minute',
      'symbol' => 'min',
      'description' => '',
      'decomposition' => units_mathematical_expression_create_from_postfix('60 second *'),
    ));
    $items['hour'] = $controller
      ->create(array(
      'measure' => 'time',
      'machine_name' => 'hour',
      'label' => 'hour',
      'symbol' => 'h',
      'description' => '',
      'decomposition' => units_mathematical_expression_create_from_postfix('3600 second *'),
    ));
    $items['day'] = $controller
      ->create(array(
      'measure' => 'time',
      'machine_name' => 'day',
      'label' => 'day',
      'symbol' => 'd',
      'description' => '',
      'decomposition' => units_mathematical_expression_create_from_postfix('86400 second *'),
    ));
    $items['year'] = $controller
      ->create(array(
      'measure' => 'time',
      'machine_name' => 'year',
      'label' => 'year',
      'symbol' => 'yr',
      'description' => '',
      'decomposition' => units_mathematical_expression_create_from_postfix('31536000 second *'),
    ));
  }
  $items['celsius'] = $controller
    ->create(array(
    'measure' => 'temperature',
    'machine_name' => 'celsius',
    'label' => 'celsius',
    'symbol' => "°C",
    'description' => '',
    'decomposition' => NULL,
  ));
  if ($celsius) {
    $items['fahrenheit'] = $controller
      ->create(array(
      'measure' => 'temperature',
      'machine_name' => 'fahrenheit',
      'label' => 'fahrenheit',
      'symbol' => "°F",
      'description' => '',
      'decomposition' => units_mathematical_expression_create_from_postfix(UNITS_QUANTITY . ' 32 - 5 * 9 / celsius *'),
    ));
    $items['kelvin'] = $controller
      ->create(array(
      'measure' => 'temperature',
      'machine_name' => 'kelvin',
      'label' => 'kelvin',
      'symbol' => 'K',
      'description' => '',
      'decomposition' => units_mathematical_expression_create_from_postfix(UNITS_QUANTITY . ' 273.15 - celsius *'),
    ));
  }
  return $items;
}