function recipe_unit_options in Recipe 6
Same name and namespace in other branches
- 5 recipe.module \recipe_unit_options()
- 7.2 recipe.module \recipe_unit_options()
- 7 recipe.module \recipe_unit_options()
Returns a cached array of recipe unit types
1 call to recipe_unit_options()
- recipe_form in ./
recipe.module - Implementation of hook_form().
File
- ./
recipe.module, line 865 - recipe.module - share recipes
Code
function recipe_unit_options() {
static $options;
static $unit_rs;
if (!isset($unit_rs)) {
$order_by = '';
// US measure preferred.
if (variable_get('recipe_preferred_system_of_measure', 0) == 0) {
$order_by = 'type asc, metric asc, name';
}
else {
$order_by = 'type asc, metric desc, name';
}
$unit_rs = db_query("SELECT id, type, name, abbreviation FROM {recipe_unit} ORDER BY {$order_by}");
$options = array();
while ($r = db_fetch_object($unit_rs)) {
if (isset($r->type)) {
if (!isset($options[$r->type])) {
$options[$r->type] = array();
}
$options[$r->type][$r->id] = t('@name (@abbreviation)', array(
'@name' => $r->name,
'@abbreviation' => $r->abbreviation,
));
}
else {
$options[$r->id] = t('@name (@abbreviation)', array(
'@name' => $r->name,
'@abbreviation' => $r->abbreviation,
));
}
}
}
return $options;
}