You are here

function farm_group_asset_latest_membership in farmOS 7

Load an asset's latest log that defines a group membership.

Parameters

FarmAsset $asset: The farm_asset object to look 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.

Return value

Log|bool Returns a log entity. FALSE if something goes wrong.

2 calls to farm_group_asset_latest_membership()
farm_group_asset_membership in modules/farm/farm_group/farm_group.module
Load groups that an asset is a member of.
farm_livestock_birth_form_submit in modules/farm/farm_livestock/farm_livestock.farm_quick.birth.inc
Submit callback for birth quick form.

File

modules/farm/farm_group/farm_group.module, line 569

Code

function farm_group_asset_latest_membership(FarmAsset $asset, $time = REQUEST_TIME, $done = TRUE) {

  /**
   * Please read the comments in farm_group_asset_membership_query() to
   * understand how this works, and to be aware of the limitations and
   * responsibilities we have in this function with regard to sanitizing query
   * inputs.
   */

  // 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 group membership log.
  $query = farm_group_asset_membership_query($asset->id, $time, $done);

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

  // If a log id exists, load and return it.
  if (!empty($log_id)) {
    return log_load($log_id);
  }
  return FALSE;
}