You are here

public function FacetapiUrlProcessorStandard::getQueryString in Facet API 7

Same name and namespace in other branches
  1. 6.3 plugins/facetapi/url_processor_standard.inc \FacetapiUrlProcessorStandard::getQueryString()
  2. 7.2 plugins/facetapi/url_processor_standard.inc \FacetapiUrlProcessorStandard::getQueryString()

Implements FacetapiUrlProcessor::getQueryString().

Overrides FacetapiUrlProcessor::getQueryString

File

plugins/facetapi/url_processor_standard.inc, line 44
The standard url processor class.

Class

FacetapiUrlProcessorStandard
Url processor plugin that retrieves facet data from the query string.

Code

public function getQueryString(array $facet, array $values, $active) {
  $qstring = $this->params;
  $active_items = $this->adapter
    ->getActiveItems($facet);

  // Appends to qstring if inactive, removes if active.
  foreach ($values as $value) {
    if ($active && isset($active_items[$value])) {
      unset($qstring[$this->filterKey][$active_items[$value]['pos']]);
    }
    elseif (!$active) {
      $field_alias = rawurlencode($facet['field alias']);

      // Strips all other filters for this facet if limit option is set.
      if ($this
        ->limitActiveItems($facet)) {
        foreach ($qstring[$this->filterKey] as $pos => $filter) {

          // Identify a filter by field alias.
          if (0 === strpos($filter, "{$field_alias}:")) {
            unset($qstring[$this->filterKey][$pos]);
          }
        }
      }

      // Adds the filter to the query string.
      $qstring[$this->filterKey][] = $field_alias . ':' . $value;
    }
  }

  // Removes duplicates, resets array keys and returns query string.
  // @see http://drupal.org/node/1340528
  $qstring[$this->filterKey] = array_values(array_unique($qstring[$this->filterKey]));
  return array_filter($qstring);
}