You are here

function recipe_unit_from_name in Recipe 6

Same name and namespace in other branches
  1. 5 recipe.module \recipe_unit_from_name()

Returns information about a unit based on a unit abbreviation or name

2 calls to recipe_unit_from_name()
recipe_import_element_end in plugins/recipe_recipeML.module
Call-back function used by the XML parser.
recipe_parse_ingredient_string in ./recipe.module
Converts an ingredients name string to an ingredient object.

File

./recipe.module, line 1255
recipe.module - share recipes

Code

function recipe_unit_from_name($name) {
  if (strlen($name) > 1) {
    $string = strtolower($name);
  }
  else {
    $string = $name;
  }
  $ending = substr($string, -1, 1);
  if ($ending == 's' && $string != 'ds' || $ending == '.') {
    $string = substr($string, 0, strlen($string) - 1);
  }
  $ending = substr($string, -1, 1);
  if ($ending == 's' && $string != 'ds' || $ending == '.') {
    $string = substr($string, 0, strlen($string) - 1);
  }
  static $units_array;
  if (!$units_array) {
    $rs = db_query("SELECT id, name, abbreviation FROM {recipe_unit}");
    while ($unit = db_fetch_object($rs)) {
      $units_array[strtolower($unit->name)] = $unit;
      $units_array[$unit->abbreviation] = $unit;
    }
  }
  return $units_array[$string];
}