You are here

public function FacetapiFacet::getQueryString in Facet API 6

Helper function that returns the query string variables for a facet item.

@reutrn An array containing the query string variables.

Parameters

$values: An array containing the item's values being added to or removed from the query string dependent on whether or not the item is active.

$active: An integer flagging whether the item is active or not.

1 call to FacetapiFacet::getQueryString()
FacetapiFacet::processQueryStrings in ./facetapi.adapter.inc
Initializes the render array's query string variables.

File

./facetapi.adapter.inc, line 353
Defines classes used by the FacetAPI module.

Class

FacetapiFacet
Stores facet data, provides methods that build the facet's render array.

Code

public function getQueryString(array $values, $active) {

  // Gets field alias for readability.
  $field_alias = $this->_facet['field alias'];

  // Builds array of query string variables.
  $qstring = $_GET;
  foreach ($values as $value) {
    if ($active && isset($this->_active[$value])) {
      unset($qstring[$field_alias][$this->_active[$value]['pos']]);
    }
    elseif (!$active) {
      if (!isset($qstring[$field_alias])) {
        $qstring[$field_alias] = array();
      }
      elseif (!is_array($qstring[$field_alias])) {
        $qstring[$field_alias] = array(
          (string) $qstring[$field_alias],
        );
      }
      $qstring[$field_alias][] = $value;
    }
  }
  return $qstring;
}