You are here

function farm_inventory in farmOS 7

Calculate an asset's inventory level.

Parameters

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

$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 any other value is used, no filtering will be applied. Defaults to TRUE.

Return value

string Returns the asset's inventory as a string. If no inventory adjustments exist for the asset, an empty string will be returned.

5 calls to farm_inventory()
farm_inventory_entity_view_alter in modules/farm/farm_inventory/farm_inventory.module
Implements hook_entity_view_alter().
farm_inventory_form_farm_asset_form_alter in modules/farm/farm_inventory/farm_inventory.module
Implements hook_form_FORM_ID_alter().
farm_inventory_set in modules/farm/farm_inventory/farm_inventory.module
Create a log for adjusting asset inventory.
farm_livestock_asset_inventory in modules/farm/farm_livestock/farm_livestock.module
Calculate the inventory for a given animal or group asset.
farm_livestock_weight_entity_view_alter in modules/farm/farm_livestock/farm_livestock_weight/farm_livestock_weight.module
Implements hook_entity_view_alter().
2 string references to 'farm_inventory'
farm_inventory_views_default_views in modules/farm/farm_inventory/farm_inventory.views_default.inc
Implements hook_views_default_views().
farm_update_7032 in ./farm.install
Enable new Farm Inventory module.

File

modules/farm/farm_inventory/farm_inventory.module, line 406

Code

function farm_inventory(FarmAsset $asset, $time = REQUEST_TIME, $done = 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 calculating the inventory.
  $query = farm_inventory_query($asset->id, $time, $done);

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

  // If there are no inventory adjustments, return an empty string. Note that
  // we use is_null($inventory) instead of empty($inventory), because empty()
  // would be TRUE if the inventory is set to 0.
  if (is_null($inventory)) {
    return '';
  }

  // Return the formatted inventory.
  return farm_inventory_format($inventory);
}