You are here

protected function SensorDatabaseAggregator::getFieldName in Monitoring 7

Returns the field name to use for a condition and ensures necessary joins.

Parameters

\SelectQueryInterface $query: Select query instance.

array $condition: A query condition array, containing at least the field.

Return value

string The field name to use for conditions for that condition definition, can contain a table name alias if the field is part of a joined table.

2 calls to SensorDatabaseAggregator::getFieldName()
SensorCommerceTurnover::buildQuery in lib/Drupal/monitoring/Sensor/Sensors/SensorCommerceTurnover.php
Builds the database query.
SensorDatabaseAggregator::buildQuery in lib/Drupal/monitoring/Sensor/Sensors/SensorDatabaseAggregator.php
Builds the database query.

File

lib/Drupal/monitoring/Sensor/Sensors/SensorDatabaseAggregator.php, line 162
Contains \Drupal\monitoring\Sensor\Sensors\SensorDatabaseAggregator.

Class

SensorDatabaseAggregator
Base for database aggregator sensors.

Namespace

Drupal\monitoring\Sensor\Sensors

Code

protected function getFieldName(\SelectQueryInterface $query, array $condition) {
  if (strpos($condition['field'], '.') !== FALSE) {

    // Configurable field conditions are only supported if this is an entity
    // table.
    $entity_type = $this
      ->getEntityTypeFromTable($this->info
      ->getSetting('table'));
    list($field_name, $column) = explode('.', $condition['field']);

    // Add a join to the field table.
    $alias = $this
      ->joinFieldTable($query, $entity_type, $field_name);

    // Return the combination of alias table name and field column.
    return $alias . '.' . _field_sql_storage_columnname($field_name, $column);
  }
  else {

    // A simple base table field.
    return $condition['field'];
  }
}