You are here

function farm_asset_property_get in farmOS 7

Get the value of an asset's property, given its ID and property name.

Parameters

$asset_id: The ID of the asset.

$name: The name of the property.

$default: A default value to use if the asset property is not set.

Return value

string Returns the value string. This will return the default value provided by the $default paremeter (which defaults to an empty string) if the property is not set. If you need to check whether or not a property is set, use farm_asset_property_is_set() instead, which returns a boolean.

File

modules/farm/farm_asset/farm_asset_property/farm_asset_property.module, line 24
Farm asset property.

Code

function farm_asset_property_get($asset_id, $name, $default = '') {

  // Query the database for the value.
  $value = db_query('SELECT value FROM {farm_asset_property} WHERE id=:id AND name=:name', array(
    ':id' => $asset_id,
    ':name' => $name,
  ))
    ->fetchField();

  // If nothing was found, return the default.
  if (empty($value)) {
    return $default;
  }

  // If it's empty for whatever reason, return the default.
  if (empty($value)) {
    return $default;
  }

  // Return the value.
  return $value;
}