You are here

function farm_movement_asset_location in farmOS 7

Find the location 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

array Returns an array of areas that the asset is in.

5 calls to farm_movement_asset_location()
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_location_markup in modules/farm/farm_movement/farm_movement.location.inc
Generate markup that describes an asset's current location.
farm_movement_asset_location_property_get in modules/farm/farm_movement/farm_movement.module
Getter callback for the location asset property.
farm_movement_form_farm_asset_form_alter in modules/farm/farm_movement/farm_movement.location.inc
Implements hook_form_FORM_ID_alter().
farm_movement_preprocess_field in modules/farm/farm_movement/farm_movement.module
Implements hook_preprocess_field().

File

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

Code

function farm_movement_asset_location(FarmAsset $asset, $time = REQUEST_TIME, $done = TRUE) {
  $areas = array();

  // 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 $areas;
  }

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

  // Load the areas referenced in the "Move to" field.
  if (!empty($movement->field_farm_move_to[LANGUAGE_NONE])) {
    foreach ($movement->field_farm_move_to[LANGUAGE_NONE] as $area_reference) {
      if (!empty($area_reference['tid'])) {
        $term = taxonomy_term_load($area_reference['tid']);
        if (!empty($term)) {
          $areas[] = $term;
        }
      }
    }
  }
  return $areas;
}