You are here

function facetapi_delta_map_get in Facet API 6

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

Parameters

$reset: A boolean flagging whether the static should be reset.

Return value

An array containing the delta map.

3 calls to facetapi_delta_map_get()
facetapi_block_info in ./facetapi.widget.inc
Returns data for the "list" operation of hook_block().
facetapi_block_view in ./facetapi.widget.inc
Returns data for the "view" operation of hook_block().
facetapi_preprocess_block in ./facetapi.module
Process variables for block.tpl.php.

File

./facetapi.widget.inc, line 252
Widget callbacks and building functions.

Code

function facetapi_delta_map_get($reset = FALSE) {
  static $map;
  if (NULL === $map || $reset) {
    if ($data = cache_get('facetapi:delta_map')) {
      $map = $data->data;
    }
    else {
      $map = array();

      // Calculates deltas for each facet in each realms for each searcher.
      foreach (facetapi_adapter_info_get() as $searcher => $definition) {
        foreach (facetapi_realms_get() as $realm) {
          foreach (facetapi_enabled_facets_get($searcher, $realm['name']) as $facet) {
            $string = $searcher . ':' . $realm['name'] . ':' . $facet['name'];

            // NOTE: We don't need drupal_strlen() becuase there will be no UTF8
            // characters in this string, and strlen() is much faster.
            $key = strlen($string) <= 32 ? $string : md5($string);
            $map[$key] = $string;
          }
        }
      }

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