You are here

function apachesolr_block_visibility in Apache Solr Search 6.2

This code makes a decision whether to show a block or not.

Parameters

$query: The current query object.

string $module: The module's name to whom this block belongs.

string $delta: The delta string the identifies the block within $module.

Return value

boolean Whether the block should be visible. Other factors, like the block system's visibility settings, apply as well.

3 calls to apachesolr_block_visibility()
apachesolr_date_block in contrib/apachesolr_date/apachesolr_date.module
Implementation of hook_block().
apachesolr_search_add_facet_params in ./apachesolr_search.module
apachesolr_search_block in ./apachesolr_search.module
Implementation of hook_block().

File

./apachesolr.module, line 913
Integration with the Apache Solr search application.

Code

function apachesolr_block_visibility($query, $module, $delta) {

  // TYPE HIERARCHY.
  // If the block is configured to heed type hierarchy then it looks to see if a
  // suitable type filter has been chosen. If not, the function returns.
  // This variable is not static cached because variable_get() already does that.
  $type_filters = variable_get('apachesolr_type_filter', array());
  if (isset($type_filters[$module][$delta]) && $type_filters[$module][$delta] == TRUE) {
    $facet_info = apachesolr_get_facet_definitions();
    if (isset($facet_info[$module][$delta]['content_types'])) {
      $has_filter = $query
        ->get_filters($facet_info[$module][$delta]['facet_field']);
      $show = count($has_filter);
      foreach ($facet_info[$module][$delta]['content_types'] as $content_type) {
        if ($query
          ->has_filter('type', $content_type)) {
          $show = TRUE;
        }
      }
      if (!$show) {
        return FALSE;
      }
    }
  }
  return TRUE;
}