You are here

public function farm_inventory_handler_field_asset_inventory_value::query in farmOS 7

Called to add the field to a query.

Overrides views_handler_field::query

File

modules/farm/farm_inventory/views/handlers/farm_inventory_handler_field_asset_inventory_value.inc, line 57
Farm asset inventory value field handler.

Class

farm_inventory_handler_field_asset_inventory_value
Filter class which allows to filter by certain bundles of an entity.

Code

public function query() {
  $this
    ->ensure_my_table();

  // Build a sub-query that will be used in the join to calculate the asset's
  // current inventory level.
  $asset_id_field = $this->table_alias . '.id';
  $done = !empty($this->options['done']) ? TRUE : FALSE;
  $future = !empty($this->options['future']) ? TRUE : FALSE;
  if ($future) {
    $time = 0;
  }
  else {
    $time = REQUEST_TIME;
  }
  $query = farm_inventory_query($asset_id_field, $time, $done);

  // Add the inventory value field.
  $params = $this->options['group_type'] != 'group' ? array(
    'function' => $this->options['group_type'],
  ) : array();
  $this->field_alias = $this->query
    ->add_field(NULL, '(' . $query . ')', 'asset_inventory', $params);
  $this
    ->add_additional_fields();

  // Join in the {farm_inventory_asset_type} table and add the "individual"
  // field so we can see if we need to treat assets as individuals.
  $join = new views_join();
  $join
    ->construct('farm_inventory_asset_type', $this->table_alias, 'type', 'type');
  $this->farm_inventory_asset_type_table = $this->query
    ->ensure_table('farm_inventory_asset_type', $this->relationship, $join);
  $this->individual_field = $this->query
    ->add_field($this->farm_inventory_asset_type_table, 'individual');
}