You are here

public function FacetapiAdapter::__construct in Facet API 6.3

Same name and namespace in other branches
  1. 6 facetapi.adapter.inc \FacetapiAdapter::__construct()
  2. 7.2 plugins/facetapi/adapter.inc \FacetapiAdapter::__construct()
  3. 7 plugins/facetapi/adapter.inc \FacetapiAdapter::__construct()

Constructor, sets searcher and type of content being indexed.

Parameters

array $searcher_info: The searcher definition.

File

plugins/facetapi/adapter.inc, line 97
Adapter plugin and adapter related calsses.

Class

FacetapiAdapter
Abstract class extended by search backends that retrieves facet information from the database.

Code

public function __construct(array $searcher_info) {
  $this->info = $searcher_info;

  // Registers the query type plugins classes associated with this adapter.
  $registered_types = array();
  foreach (ctools_get_plugins('facetapi', 'query_types') as $plugin) {
    if (isset($searcher_info['adapter']) && isset($plugin['handler']['adapter']) && $searcher_info['adapter'] == $plugin['handler']['adapter']) {
      $class = ctools_plugin_get_class($plugin, 'handler');
      $type = call_user_func(array(
        $class,
        'getType',
      ));
      $registered_types[$type] = $class;
    }
  }

  // Iterates over facets and registers query type plugins.
  foreach ($this
    ->getEnabledFacets() as $facet) {

    // Gets widget type from setting if there are more than one available.
    if (1 == count($facet['query types'])) {
      $query_type = $facet['query types'][0];
    }
    else {
      $settings = $this
        ->getFacetSettingsGlobal($facet)->settings;
      $query_type = !empty($settings['query_type']) ? $settings['query_type'] : FALSE;
    }

    // If we found a query type, register the query type plugin.
    if ($query_type && isset($registered_types[$query_type])) {
      $plugin = new $registered_types[$query_type]($this, $facet);
      $this->queryTypes[$facet['name']] = $plugin;
    }
    else {
      $this->queryTypes[$facet['name']] = FALSE;
    }
  }

  // Instantiates URL processor plugin.
  $id = $searcher_info['url processor'];
  $class = ctools_plugin_load_class('facetapi', 'url_processors', $id, 'handler');
  if (!$class) {
    $class = ctools_plugin_load_class('facetapi', 'url_processors', 'standard', 'handler');
  }
  $this->urlProcessor = new $class($this);

  // Fetches, normalizes, and sets filter params.
  $filter_key = $this->urlProcessor
    ->getFilterKey();
  $params = $this->urlProcessor
    ->fetchParams();
  $this
    ->setParams($params, $filter_key);
}