You are here

function farm_quantity_log_asset in farmOS 7

Load logs for an asset with a given quantity measure and/or label.

Parameters

FarmAsset $asset: The farm_asset object to look for.

string $measure: The quantity measure to search for (ie: weight).

string $label: The quantity label to search for.

int $time: Unix timestamp limiter. Only logs before this time will be included. Defaults to the current time. Set to 0 to load the absolute last.

bool|null $done: Whether or not to only show logs that are marked as "done". TRUE will limit to logs that are done, and FALSE will limit to logs that are not done. If this is set to NULL, no filtering will be applied. Defaults to TRUE.

string $type: The log type to filter by. If empty, no filtering will be applied.

bool $single: Whether or not to limit the query to a single result. Defaults to TRUE.

Return value

Log|array|bool Returns a log entity, or an array of them. FALSE if something goes wrong.

3 calls to farm_quantity_log_asset()
farm_livestock_weight in modules/farm/farm_livestock/farm_livestock_weight/farm_livestock_weight.module
Helper function for retrieving the weight of an animal.
farm_livestock_weight_all in modules/farm/farm_livestock/farm_livestock_weight/farm_livestock_weight.module
Helper function for retrieving all weight logs of an animal.
farm_livestock_weight_group_report in modules/farm/farm_livestock/farm_livestock_weight/farm_livestock_weight.module
Generate Animal Weight Group Report

File

modules/farm/farm_quantity/farm_quantity_log/farm_quantity_log.module, line 100
Farm quantity log module.

Code

function farm_quantity_log_asset(FarmAsset $asset, $measure = NULL, $label = NULL, $time = REQUEST_TIME, $done = TRUE, $type = NULL, $single = TRUE) {

  // If the asset doesn't have an ID (for instance if it is new and hasn't been
  // saved yet), bail.
  if (empty($asset->id)) {
    return FALSE;
  }

  // Make a query for loading the latest quantity log.
  $query = farm_quantity_log_asset_query($asset->id, $measure, $label, $time, $done, $type, $single);

  // Execute the query and gather the log id.
  $result = $query
    ->execute();

  // Return array of log objects. $single = FALSE
  if (empty($single)) {
    $log_item_ids = $result
      ->fetchCol();
    $logs = entity_load('log', $log_item_ids);
    return $logs;
  }
  else {
    if (!empty($single)) {
      $log_id = $result
        ->fetchField();
      if (!empty($log_id)) {
        return log_load($log_id);
      }
    }
  }

  // If all else fails, return FALSE.
  return FALSE;
}