You are here

function _bean_usage_field_data in Bean (for Drupal 7) 7

Get the data from the field_data tables for bean usage based on bean.bid and bean.delta

Parameters

string $data_table:

int $i:

string $field_name:

array $entity_types:

array $bundles:

string $filter:

boolean $delta_specific:

object bean:

Return value

SelectQuery

1 call to _bean_usage_field_data()
bean_usage_output in bean_usage/bean_usage.module
Displays a table of Beans and their usage

File

bean_usage/bean_usage.module, line 419
Bean Admin Functions and Display

Code

function _bean_usage_field_data($data_table, $i, $field_name, $entity_types, $bundles, $filters = NULL, $delta_specific = FALSE, $bean = NULL) {
  $query = db_select($data_table, 'fd' . $i);
  $query
    ->leftJoin('block', 'bl', 'fd' . $i . '.' . $field_name . '_bid = bl.bid');
  $query
    ->join('bean', 'b', 'b.delta = bl.delta');
  $query
    ->fields('b', array(
    'bid',
    'label',
    'title',
    'type',
  ));
  $query
    ->fields('fd' . $i, array(
    'entity_id',
    'delta',
    'entity_type',
  ));
  $query
    ->addField('fd' . $i, $field_name . '_bid', 'bid');
  $query_and = db_and();
  $query_and
    ->condition('bl.module', 'bean');
  $query_and
    ->condition('bl.theme', variable_get('theme_default', NULL));
  $query_and
    ->condition('fd' . $i . '.entity_type', $entity_types, 'IN');
  $query_and
    ->condition('fd' . $i . '.bundle', $bundles, 'IN');
  if (!empty($filters['type'])) {
    $query_and
      ->condition('b.type', array(
      $filters['type'],
    ), 'IN');
  }
  if (!empty($filters['title'])) {
    $query_and
      ->condition('b.title', '%' . $filters['title'] . '%', 'LIKE');
  }
  if (!empty($filters['label'])) {
    $query_and
      ->condition('b.label', '%' . $filters['label'] . '%', 'LIKE');
  }
  if ($delta_specific && !empty($bean)) {
    $query_and
      ->condition('b.bid', intval($bean->bid));
  }
  $query
    ->condition($query_and);
  return $query;
}