class SearchApiQueryFilter in Search API 7
Provides a standard implementation of SearchApiQueryFilterInterface.
Hierarchy
- class \SearchApiQueryFilter implements SearchApiQueryFilterInterface
Expanded class hierarchy of SearchApiQueryFilter
1 string reference to 'SearchApiQueryFilter'
- SearchApiQuery::__construct in includes/
query.inc - Constructs a new search query.
File
- includes/
query.inc, line 997 - Contains SearchApiQueryInterface and SearchApiQuery.
View source
class SearchApiQueryFilter implements SearchApiQueryFilterInterface {
/**
* Array containing subfilters.
*
* Each of these is either an array (field, value, operator), or another
* SearchApiFilter object.
*
* @var array
*/
protected $filters;
/**
* String specifying this filter's conjunction ('AND' or 'OR').
*
* @var string
*/
protected $conjunction;
/**
* {@inheritdoc}
*/
public function __construct($conjunction = 'AND', array $tags = array()) {
$this
->setConjunction($conjunction);
$this->filters = array();
$this->tags = drupal_map_assoc($tags);
}
/**
* {@inheritdoc}
*/
public function setConjunction($conjunction) {
$this->conjunction = strtoupper(trim($conjunction)) == 'OR' ? 'OR' : 'AND';
return $this;
}
/**
* {@inheritdoc}
*/
public function filter(SearchApiQueryFilterInterface $filter) {
$this->filters[] = $filter;
return $this;
}
/**
* {@inheritdoc}
*/
public function condition($field, $value, $operator = '=') {
$this->filters[] = array(
$field,
$value,
$operator,
);
return $this;
}
/**
* {@inheritdoc}
*/
public function getConjunction() {
return $this->conjunction;
}
/**
* {@inheritdoc}
*/
public function &getFilters() {
return $this->filters;
}
/**
* {@inheritdoc}
*/
public function hasTag($tag) {
return isset($this->tags[$tag]);
}
/**
* {@inheritdoc}
*/
public function &getTags() {
// Tags can sometimes be NULL for old serialized query filter objects.
if (!isset($this->tags)) {
$this->tags = array();
}
return $this->tags;
}
/**
* Implements the magic __clone() method to clone nested filters, too.
*/
public function __clone() {
foreach ($this->filters as $i => $filter) {
if (is_object($filter)) {
$this->filters[$i] = clone $filter;
}
}
}
/**
* Implements the magic __toString() method to simplify debugging.
*/
public function __toString() {
// Special case for a single, nested filter:
if (count($this->filters) == 1 && is_object($this->filters[0])) {
return (string) $this->filters[0];
}
$ret = array();
foreach ($this->filters as $filter) {
if (is_object($filter)) {
$ret[] = "[\n " . str_replace("\n", "\n ", (string) $filter) . "\n ]";
}
else {
$ret[] = "{$filter[0]} {$filter[2]} " . str_replace("\n", "\n ", var_export($filter[1], TRUE));
}
}
return $ret ? ' ' . implode("\n{$this->conjunction}\n ", $ret) : '';
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
SearchApiQueryFilter:: |
protected | property | String specifying this filter's conjunction ('AND' or 'OR'). | |
SearchApiQueryFilter:: |
protected | property | Array containing subfilters. | |
SearchApiQueryFilter:: |
public | function |
Adds a new ($field $operator $value) condition. Overrides SearchApiQueryFilterInterface:: |
|
SearchApiQueryFilter:: |
public | function |
Adds a subfilter. Overrides SearchApiQueryFilterInterface:: |
|
SearchApiQueryFilter:: |
public | function |
Retrieves the conjunction used by this filter. Overrides SearchApiQueryFilterInterface:: |
|
SearchApiQueryFilter:: |
public | function |
Return all conditions and nested filters contained in this filter. Overrides SearchApiQueryFilterInterface:: |
|
SearchApiQueryFilter:: |
public | function |
Retrieves the tags set on this filter. Overrides SearchApiQueryFilterInterface:: |
|
SearchApiQueryFilter:: |
public | function |
Checks whether a certain tag was set on this filter. Overrides SearchApiQueryFilterInterface:: |
|
SearchApiQueryFilter:: |
public | function |
Sets this filter's conjunction. Overrides SearchApiQueryFilterInterface:: |
|
SearchApiQueryFilter:: |
public | function | Implements the magic __clone() method to clone nested filters, too. | |
SearchApiQueryFilter:: |
public | function |
Constructs a new filter that uses the specified conjunction. Overrides SearchApiQueryFilterInterface:: |
|
SearchApiQueryFilter:: |
public | function | Implements the magic __toString() method to simplify debugging. |