You are here

function facetapi_set_facet_status in Facet API 7

Same name and namespace in other branches
  1. 6.3 facetapi.module \facetapi_set_facet_status()
  2. 7.2 facetapi.module \facetapi_set_facet_status()

Enables or disables a facet for this page load only.

Parameters

string $searcher: The machine readable name of the searcher.

string $realm_name: The machine readable name of the realm, pass NULL for all realms.

string $facet_name: The machine readable name of the facet.

bool $status: A boolean flagging whether the facet is enabled or disabled.

bool $batch_process: A boolean flagging whether batch processing is being performed. If set to TRUE, the list of enabled facets won't be rebuild and the active items won't be re-processed. Note that these tasks will have to be performed manually in order for the status to be properly set.

2 calls to facetapi_set_facet_status()
facetapi_set_facet_disabled in ./facetapi.module
Disables a facet for this page load only.
facetapi_set_facet_enabled in ./facetapi.module
Enables a facet for this page load only.

File

./facetapi.module, line 1050
An abstracted facet API that can be used by various search backends.

Code

function facetapi_set_facet_status($searcher, $realm_name, $facet_name, $status, $batch_process) {

  // Rebuild static if not batch processing.
  if (!$batch_process) {
    drupal_static('facetapi_get_enabled_facets', array(), TRUE);
  }

  // Pulls the list of enabled facets so we can modify it here.
  facetapi_get_enabled_facets($searcher, $realm_name);
  $enabled_facets =& drupal_static('facetapi_get_enabled_facets', array());

  // Performs the operation by setting or unsetting the facet.
  $cid = $searcher . ':' . (string) $realm_name;
  if ($status && !isset($enabled_facets[$cid][$facet_name])) {
    if ($facet = facetapi_facet_load($facet_name, $searcher)) {

      // Add facet to static, which enables it.
      $enabled_facets[$cid][$facet_name] = $facet;

      // If facet isn't already globally enabled, enable it.
      if (!isset($enabled_facets[$searcher . ':'][$facet_name])) {

        // Ensure sure static is set before modifying it.
        facetapi_get_enabled_facets($searcher, NULL);
        $enabled_facets[$searcher . ':'][$facet_name] = $facet;
      }
    }
  }
  elseif (!$status && isset($enabled_facets[$cid][$facet_name])) {

    // Removes facet to static, which disables it.
    unset($enabled_facets[$cid][$facet_name]);

    // If acting globally, disable facet in all realms.
    if (!$realm_name) {
      foreach (facetapi_get_realm_info() as $realm) {

        // Ensure sure static is set before unsetting the facet.
        facetapi_get_enabled_facets($searcher, $realm['name']);
        unset($enabled_facets[$searcher . ':' . $realm['name']][$facet_name]);
      }
    }
  }
  else {
    return;
  }

  // Re-process the active items since the list of active facets has changed.
  if (!$batch_process && ($adapter = facetapi_adapter_load($searcher))) {
    $adapter
      ->processActiveItems();
  }
}