You are here

function farm_movement_asset_geometry in farmOS 7

Find the geometry of an asset, based on movement logs.

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

string Returns the asset's current geometry, in WKT (well-known text).

3 calls to farm_movement_asset_geometry()
farm_livestock_move_form in modules/farm/farm_livestock/farm_livestock.farm_quick.move.inc
Form for adding animal movement logs.
farm_livestock_move_form_submit in modules/farm/farm_livestock/farm_livestock.farm_quick.move.inc
Submit function for movement quick form.
farm_movement_asset_geometry_property_get in modules/farm/farm_movement/farm_movement.module
Getter callback for the geometry asset property.

File

modules/farm/farm_movement/farm_movement.location.inc, line 248
Code for managing the location of assets with movement logs.

Code

function farm_movement_asset_geometry(FarmAsset $asset, $time = REQUEST_TIME, $done = TRUE) {
  $geometry = '';

  // Load the log using our helper function.
  $log = farm_movement_asset_latest_movement($asset, $time, $done);

  // If a movement field doesn't exist, bail.
  if (empty($log->field_farm_movement[LANGUAGE_NONE][0]['value'])) {
    return $geometry;
  }

  // Load the log's movement field
  $movement = field_collection_item_load($log->field_farm_movement[LANGUAGE_NONE][0]['value']);

  // Load the movement geometry.
  if (!empty($movement->field_farm_geofield[LANGUAGE_NONE][0]['geom'])) {
    $geometry = $movement->field_farm_geofield[LANGUAGE_NONE][0]['geom'];
  }
  return $geometry;
}