You are here

public function SearchApiDenormalizedEntityDataSourceController::loadItems in Search API Grouping 7.2

Load items of the type of this data source controller.

Parameters

array $ids: The IDs of the items to load.

Return value

array The loaded items, keyed by ID.

Overrides SearchApiEntityDataSourceController::loadItems

File

includes/datasource_denormalized_entity.inc, line 76
Contains the SearchApiDenormalizedEntityDataSourceController class.

Class

SearchApiDenormalizedEntityDataSourceController
Data source for all entities known to the Entity API.

Code

public function loadItems(array $ids) {

  // Fetch mapped entity ids.
  $entity_ids = db_select($this->table)
    ->fields($this->table, array(
    $this->itemIdColumn,
    'etid',
  ))
    ->condition($this->itemIdColumn, $ids)
    ->condition('entity_type', $this
    ->getEntityType())
    ->execute()
    ->fetchAll(PDO::FETCH_KEY_PAIR);
  $entities = entity_load($this
    ->getEntityType(), $entity_ids);

  // Assign entities to item ids.
  $items = array();
  foreach ($entity_ids as $item_id => $entity_id) {

    // Ensure inconsistencies don't throw an error.
    if (isset($entities[$entity_id])) {
      $items[$item_id] = $entities[$entity_id];
    }
  }

  // If some items couldn't be loaded, remove them from tracking.
  if (count($items) != count($ids)) {
    $ids = array_flip($ids);
    $unknown = array_keys(array_diff_key($ids, $items));
    if ($unknown) {
      search_api_track_item_delete($this->type, $unknown);
    }
  }
  return $items;
}