You are here

function farm_movement_area_assets in farmOS 7

Load all assets in an area.

Parameters

$area: The area to load assets from.

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.

bool $archived: Whether or not to include archived assets. Defaults to FALSE.

Return value

array Returns an array of the area's assets, keyed by asset ID.

1 call to farm_movement_area_assets()
farm_movement_area_assets_property_get in modules/farm/farm_movement/farm_movement.module
Getter callback for the area assets property.

File

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

Code

function farm_movement_area_assets($area, $time = REQUEST_TIME, $done = TRUE, $archived = FALSE) {

  /**
   * @todo
   * Merge/abstract with farm_group_members().
   */

  // Start an empty array of assets.
  $assets = array();

  // If the area doesn't have an id, bail.
  if (empty($area->tid)) {
    return $assets;
  }

  // Build a query to find all assets in the area.
  $query = farm_movement_area_assets_query($area->tid, $time, $done, $archived);

  // Execute the query to get a list of asset IDs.
  $result = $query
    ->execute();

  // Iterate through the results.
  foreach ($result as $row) {

    // If the asset ID is empty, skip it.
    if (empty($row->asset_id)) {
      continue;
    }

    // If the asset has already been loaded, skip it.
    if (array_key_exists($row->asset_id, $assets)) {
      continue;
    }

    // Load the asset.
    $assets[$row->asset_id] = farm_asset_load($row->asset_id);
  }

  // Return the array of assets.
  return $assets;
}