You are here

function current_search_check_visibility in Facet API 6.3

Same name and namespace in other branches
  1. 7.2 contrib/current_search/current_search.block.inc \current_search_check_visibility()
  2. 7 contrib/current_search/current_search.block.inc \current_search_check_visibility()

Checks whether the block should be displayed.

In cases where modules like Context are being used, hook_block_list_alter() is not invoked and we get fatal errors. We have to test whether or not the hook has been invoked and call this function manually otherwise.

Parameters

$delta: The block delta.

Return value

A boolean flagging whether to display this block or not.

2 calls to current_search_check_visibility()
current_search_block_list_alter in contrib/current_search/current_search.block.inc
Implements hook_block_list_alter().
current_search_block_view in contrib/current_search/current_search.block.inc
Returns the content for a facet based on the delta.

File

contrib/current_search/current_search.block.inc, line 192
Block hook implementations and block form alterations.

Code

function current_search_check_visibility($delta) {

  // Caches the delta map, defaults to NULL so we can test whether this function
  // was called in hook_block_list_alter() or not.
  $map =& ctools_static('current_search_delta_map');
  if (NULL === $map) {
    $map = array();
    $result = db_query('SELECT delta, searcher FROM {block_current_search}');
    foreach ($result as $record) {
      if (isset($record)) {
        $map[$record->delta] = $record->searcher;
      }
    }
  }

  // Apply default if necessary.
  if (empty($map[$delta])) {

    // Gets the default value for this block.
    $searcher = db_result(db_query("SELECT searcher FROM {block_current_search} WHERE delta = %d", $delta));
    $map[$delta] = $searcher ? $searcher : current_search_get_default_searcher();
  }

  // Checks whether block should be displayed.
  if (!facetapi_is_active_searcher($map[$delta])) {
    return FALSE;
  }
  if (!($adapter = facetapi_adapter_load($map[$delta]))) {
    return FALSE;
  }
  if (!$adapter
    ->searchExecuted($map[$delta])) {
    return FALSE;
  }
  if (!($config = current_search_item_load($delta))) {
    return FALSE;
  }

  // Returns TRUE based on the empty_searches setting and the current search.
  switch ($config->settings['advanced']['empty_searches']) {
    case CURRENT_SEARCH_DISPLAY_KEYS:
      return $adapter
        ->getSearchKeys();
    case CURRENT_SEARCH_DISPLAY_FILTERS:
      return $adapter
        ->getAllActiveItems();
    case CURRENT_SEARCH_DISPLAY_KEYS_FILTERS:
      return $adapter
        ->getSearchKeys() || $adapter
        ->getAllActiveItems();
    case CURRENT_SEARCH_DISPLAY_ALWAYS:
    default:
      return TRUE;
  }
}