You are here

function facetapi_map_query in Facet API 6

Helper function to execute a map query. A map query is useful for converting unique identifiers to human readable values, for example a uid to username.

Parameters

$sql: A string containing the SQL query mapping the ID to another value. The query must select the "id" and "name" fields.

$ids: An array containing the IDs being mapped.

$type: The Schema API type of the ID field (e.g. 'int', 'text', or 'varchar').

Return value

An array of mapped IDs.

3 calls to facetapi_map_query()
facetapi_callback_taxonomy_map in ./facetapi.callbacks.inc
Maps a taxonomy ID to a term name.
facetapi_callback_type_map in ./facetapi.callbacks.inc
Converts machine readable content types to display names.
facetapi_callback_uid_map in ./facetapi.callbacks.inc
Converts UIDs to username.

File

./facetapi.adapter.inc, line 678
Defines classes used by the FacetAPI module.

Code

function facetapi_map_query($sql, array $ids, $type = 'int') {
  $map = array();
  if (!empty($ids)) {
    $sql = str_replace('!placeholders', db_placeholders($ids, $type), $sql);
    if ($result = db_query($sql, $ids)) {
      while ($record = db_fetch_object($result)) {
        $map[$record->id] = $record->name;
      }
    }
  }
  return $map;
}