You are here

public function FacetapiAdapter::loadQueryTypePlugins in Facet API 7

Same name and namespace in other branches
  1. 7.2 plugins/facetapi/adapter.inc \FacetapiAdapter::loadQueryTypePlugins()

Returns an array of instantiated query type plugins for enabled facets.

Iterates over the adapter's enabled facets and loads the appropriate query type plugin. If the adapter does not support the plugin, FALSE is set in place of a FacetapiQueryTypeInterface object.

Return value

array An associative array keyed by facet name to FacetapiQueryTypeInterface object, FALSE if the query type is not supported by this searcher.

See also

FacetapiAdapter::processActiveItems()

1 call to FacetapiAdapter::loadQueryTypePlugins()
FacetapiAdapter::processActiveItems in plugins/facetapi/adapter.inc
Processes active facet items.

File

plugins/facetapi/adapter.inc, line 355
Adapter plugin and adapter related classes.

Class

FacetapiAdapter
Abstract class extended by Facet API adapters.

Code

public function loadQueryTypePlugins() {
  $query_types = array();

  // Gather a whitelist of query type plugins supported by this searcher.
  $plugin_ids = array();
  foreach (ctools_get_plugins('facetapi', 'query_types') as $plugin) {
    if ($this->info['adapter'] == $plugin['handler']['adapter']) {
      $type = call_user_func(array(
        $plugin['handler']['class'],
        'getType',
      ));
      $plugin_ids[$type] = $plugin['handler']['class'];
    }
  }

  // Iterate over enabled facets and instantiate each one's query type plugin.
  foreach ($this
    ->getEnabledFacets() as $facet) {

    // Get the machine name of the query type plugin used by this facet.
    if (1 == count($facet['query types'])) {

      // There is only one query type supported by this facet, so use it.
      $query_type = $facet['query types'][0];
    }
    else {

      // Get query type from settings if there is more than one supported by
      // this facet. For example, some facets only support simple term queries
      // while others also support numeric range queries. In those instances,
      // administrators have to select which one to use in the facet's
      // administrative interface.
      $settings = $this
        ->getFacetSettingsGlobal($facet)->settings;
      $query_type = !empty($settings['query_type']) ? $settings['query_type'] : FALSE;
    }

    // Instantiate the query type plugin if it is in the whitelist of query
    // types supported by the backend. Store objects in an instance variable
    // keyed by the machine name of the facet.
    if ($query_type && isset($plugin_ids[$query_type])) {
      $plugin = new $plugin_ids[$query_type]($this, $facet);
      $query_types[$facet['name']] = $plugin;
    }
    else {
      $query_types[$facet['name']] = FALSE;
    }
  }

  // Return the instantiated query type plugins.
  return $query_types;
}