function farm_quantity_units in farmOS 7
Return an array of standard unit names for given measures.
@todo This is a first step towards more complete unit management in farmOS. It is provided as a central helper function for other modules to use as a placeholder until then.
Parameters
string $measure: An optional measure to filter by. See available options in farm_quantity_measures() above.
Return value
array Returns an array of standard unit strings for a given measure. Or an array of all unit strings, organized into sub-arrays keyed by measure.
1 call to farm_quantity_units()
- farm_soil_amendment_form in modules/
farm/ farm_soil/ farm_soil.farm_quick.amendment.inc - Soil amendment quick form.
6 string references to 'farm_quantity_units'
- farm_api_restws_request_alter in modules/
farm/ farm_api/ farm_api.module - Implements hook_restws_request_alter().
- farm_quantity_field_default_field_bases in modules/
farm/ farm_quantity/ farm_quantity.features.field_base.inc - Implements hook_field_default_field_bases().
- farm_quantity_log_add_measurements in modules/
farm/ farm_quantity/ farm_quantity_log/ farm_quantity_log.module - Helper function for adding quantity measurements to a log.
- farm_quantity_report_views_default_views in modules/
farm/ farm_quantity/ farm_quantity_report/ farm_quantity_report.views_default.inc - Implements hook_views_default_views().
- farm_quantity_taxonomy_default_vocabularies in modules/
farm/ farm_quantity/ farm_quantity.features.taxonomy.inc - Implements hook_taxonomy_default_vocabularies().
File
- modules/
farm/ farm_quantity/ farm_quantity.module, line 238 - Farm quantity module.
Code
function farm_quantity_units($measure = '') {
// Load the available measures.
$measures = farm_quantity_measures();
// Build an empty array of quantity unit sub-arrays, keyed by measure.
$units = array();
foreach ($measures as $name => $info) {
$units[$name] = array();
}
// Look up the system of measurement.
$system = farm_quantity_system_of_measurement();
// Depending on the system of measurement, add unit options to measures.
if ($system == 'metric') {
// Length units.
$units['length'][] = t('kilometers');
$units['length'][] = t('meters');
$units['length'][] = t('centimeters');
// Weight units.
$units['weight'][] = t('kilograms');
$units['weight'][] = t('grams');
// Area units.
$units['area'][] = t('hectares');
$units['area'][] = t('square meters');
// Volume units.
$units['volume'][] = t('kiloliters');
$units['volume'][] = t('liters');
$units['volume'][] = t('milliliters');
// Temperature units.
$units['temperature'][] = 'C';
}
elseif ($system == 'us') {
// Length units.
$units['length'][] = t('miles');
$units['length'][] = t('feet');
$units['length'][] = t('inches');
// Weight units.
$units['weight'][] = t('tons');
$units['weight'][] = t('lbs');
$units['weight'][] = t('ounces');
// Area units.
$units['area'][] = t('acres');
$units['area'][] = t('square feet');
// Volume units.
$units['volume'][] = t('cubic yards');
$units['volume'][] = t('cubic feet');
$units['volume'][] = t('gallons');
$units['volume'][] = t('quarts');
$units['volume'][] = t('cups');
// Temperature units.
$units['temperature'][] = t('F');
}
// Time units are independent of system.
$units['time'][] = t('years');
$units['time'][] = t('months');
$units['time'][] = t('weeks');
$units['time'][] = t('days');
$units['time'][] = t('hours');
$units['time'][] = t('minutes');
$units['time'][] = t('seconds');
// If a measure is specified, only return units for that measure.
if (!empty($measure)) {
if (!empty($units[$measure])) {
return $units[$measure];
}
else {
return array();
}
}
// Return all quantity units.
return $units;
}