You are here

function facetapi_get_delta_map in Facet API 7.2

Same name and namespace in other branches
  1. 6.3 facetapi.block.inc \facetapi_get_delta_map()
  2. 7 facetapi.block.inc \facetapi_get_delta_map()

Returns a cached delta map of hashes to names.

Sometimes deltas are longer than 32 chars and need to be passed to hash(). Due to the block table's schema, deltas cannot be longer than 32 characters. However, hashes are nasty as CSS IDs, so we can use the map to convert the hashes back to a nicer value in facetapi_preprocess_block().

Return value

An array containing the delta map.

2 calls to facetapi_get_delta_map()
facetapi_check_block_visibility in ./facetapi.block.inc
Checks whether the block should be displayed.
facetapi_get_block_info in ./facetapi.block.inc
Helper function to get block info for all block-like realms.

File

./facetapi.block.inc, line 195
Block realm code and hook implementations.

Code

function facetapi_get_delta_map() {
  $map =& drupal_static(__FUNCTION__);
  if (NULL === $map) {
    if ($data = cache_get('facetapi:delta_map')) {
      $map = $data->data;
    }
    else {
      $map = array();

      // Maps deltas for all realms. This is a hack since not all realms display
      // facets in blocks, but it doesn't hurt to store the extra data. The map
      // is cached anyways, so it shouldn't cause too much additional resource
      // consumption. It is also an edge-case to have non-block facets.
      $searcher_info = facetapi_get_searcher_info();
      foreach (facetapi_get_realm_info() as $realm_name => $realm_info) {
        foreach ($searcher_info as $searcher => $info) {
          foreach (facetapi_get_delta_map_queue($searcher, $realm_name) as $facet_name) {
            $delta = facetapi_build_delta($searcher, $realm_name, $facet_name);
            $map[facetapi_hash_delta($delta)] = $delta;
          }
        }
      }

      // Caches the map so we don't have to do this repeatedly.
      cache_set('facetapi:delta_map', $map, 'cache', CACHE_TEMPORARY);
    }
  }
  return $map;
}