function farm_livestock_weight_set in farmOS 7
Create a weight measurement log associated with an animal.
Parameters
array $assets: The assets to add a weight measurement to.
string $weight: The animal's current weight.
string $units: The units of measurement.
int $timestamp: The timestamp of the measurement. Defaults to the current time.
bool $done: Boolean indicating whether or not the log should be marked "done". Defaults to TRUE.
Return value
\Log Returns the log that was created.
3 calls to farm_livestock_weight_set()
- farm_livestock_weight_action in modules/
farm/ farm_livestock/ farm_livestock_weight/ farm_livestock_weight.module - Action function for farm_livestock_weight_action.
- farm_livestock_weight_asset_form_submit in modules/
farm/ farm_livestock/ farm_livestock_weight/ farm_livestock_weight.module - Submit handler for processing the animal weight field.
- farm_livestock_weight_form_farm_livestock_birth_form_submit in modules/
farm/ farm_livestock/ farm_livestock_weight/ farm_livestock_weight.module - Submit function for livestock birth form to set child birth weights.
File
- modules/
farm/ farm_livestock/ farm_livestock_weight/ farm_livestock_weight.module, line 194 - Farm livestock weight module.
Code
function farm_livestock_weight_set($assets, $weight, $units, $timestamp = REQUEST_TIME, $done = TRUE) {
// The log will be an observation.
$log_type = 'farm_observation';
// Set the name to: "Weight of [assets] is [weight] [units]".
$assets_summary = farm_log_entity_label_summary('farm_asset', $assets);
$log_name = t('Weight of !assets is !weight !units', array(
'!assets' => $assets_summary,
'!weight' => $weight,
'!units' => $units,
));
// If $assets isn't an array, wrap it.
if (!is_array($assets)) {
$assets = array(
$assets,
);
}
// Assemble an array of measurements.
$measurements = array(
array(
'measure' => 'weight',
'value' => $weight,
'units' => $units,
'label' => '',
),
);
// Create a new log entity.
$log = farm_quantity_log_create($log_type, $log_name, $timestamp, $done, $assets, $measurements);
// Return the log.
return $log;
}