You are here

function farm_livestock_weight_all in farmOS 7

Helper function for retrieving all weight logs of an animal.

Parameters

FarmAsset $asset: The animal asset to get weight for.

Return value

array Returns an array of arrays with the following information from each weight log: weight, value, units, label, log Newest is the first, oldest last.

2 calls to farm_livestock_weight_all()
farm_livestock_weight_dlwg in modules/farm/farm_livestock/farm_livestock_weight/farm_livestock_weight.module
Helper function for retrieving the latest daily liveweight gain for an animal
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 53
Farm livestock weight module.

Code

function farm_livestock_weight_all($asset) {

  // Load the logs with a 'weight' quantity measurement for this asset.
  $logs = farm_quantity_log_asset($asset, 'weight', NULL, REQUEST_TIME, TRUE, 'farm_observation', FALSE);

  // If only a single log was returned, wrap it in an array.
  if (!is_array($logs)) {
    $logs = array(
      $logs,
    );
  }

  // Start array of log weights.
  $log_weights = array();

  // Check that there are some logs!
  if (!empty($logs)) {
    foreach ($logs as $log) {

      // Get weight quantity data from log.
      $data = farm_quantity_log_data($log, 'weight');
      foreach ($data as $quantity) {
        if (!empty($quantity['value'])) {

          // Save the log with the quantity info.
          $quantity['log'] = $log;

          // Add quantity to log weights.
          $log_weights[] = $quantity;
        }
      }
    }
  }

  // Return log weights.
  return $log_weights;
}