function farm_livestock_weight in farmOS 7
Helper function for retrieving the weight of an animal.
Parameters
FarmAsset $asset: The animal asset to get weight for.
Return value
array Returns an array of quantity information about the asset's weight, based on its latest weight quantity log. Returns an empty array if nothing is found.
3 calls to farm_livestock_weight()
- farm_livestock_weight_entity_view_alter in modules/
farm/ farm_livestock/ farm_livestock_weight/ farm_livestock_weight.module - Implements hook_entity_view_alter().
- farm_livestock_weight_form_farm_asset_form_alter in modules/
farm/ farm_livestock/ farm_livestock_weight/ farm_livestock_weight.module - Implements hook_form_FORM_ID_alter().
- farm_livestock_weight_individual_report in modules/
farm/ farm_livestock/ farm_livestock_weight/ farm_livestock_weight.report.inc - Asset Report view callback.
3 string references to 'farm_livestock_weight'
- farm_livestock_update_7007 in modules/
farm/ farm_livestock/ farm_livestock.install - Install the Farm Livestock Weight module.
- farm_livestock_weight_group_report_form in modules/
farm/ farm_livestock/ farm_livestock_weight/ farm_livestock_weight.module - Animal group report form.
- farm_livestock_weight_individual_report in modules/
farm/ farm_livestock/ farm_livestock_weight/ farm_livestock_weight.report.inc - Asset Report view callback.
File
- modules/
farm/ farm_livestock/ farm_livestock_weight/ farm_livestock_weight.module, line 18 - Farm livestock weight module.
Code
function farm_livestock_weight($asset) {
// Load the latest log with a 'weight' quantity measurement for this asset.
$log = farm_quantity_log_asset($asset, 'weight', NULL, REQUEST_TIME, TRUE, 'farm_observation');
// if no weight observation log exists for asset
if (empty($log)) {
return array();
}
// Extract quantity data from the log.
$data = farm_quantity_log_data($log, 'weight');
// Iterate through the data and return the first one with a value.
foreach ($data as $quantity) {
if (!empty($quantity['value'])) {
return $quantity;
}
}
// If nothing was returned, return an empty array.
return array();
}