This repository has been archived by the owner on Apr 6, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 9
/
SearchlightFacetLanguage.inc
63 lines (60 loc) · 1.74 KB
/
SearchlightFacetLanguage.inc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
<?php
/**
* Facet plugin class for language.
*/
class SearchlightFacetLanguage extends SearchlightFacet {
/**
* Override of query().
* Merges null value filtering with the site default language.
*/
function query(&$query) {
// Filter the query if there is an active facet value.
if (isset($this->value)) {
$default = language_default('language');
if (empty($this->value) || $this->value === $default) {
$query->search_filter[] = array(
'field' => $this->name,
'operator' => 'IN',
'args' => array('', $default),
);
}
else {
$query->search_filter[] = array(
'field' => $this->name,
'operator' => '=',
'args' => array($this->value),
);
}
}
// Add this facet to be built by the backend.
$limit = isset($this->options['items']) ? $this->options['items'] : 5;
$query->add_search_facet($this->name, $limit);
}
/**
* Override of render().
* Merges null value facet with the site default language facet.
*/
function render($query, $delta) {
switch ($delta) {
case 'active':
if (isset($this->value)) {
$items = array($this->value => array('id' => $this->value));
}
break;
case 'facets':
if (!isset($this->value)) {
$items = $query->get_search_facet($this->name);
}
break;
}
if (!empty($items) && $this->viewInit($query)) {
$default = language_default('language');
if (isset($items[$default], $items[''])) {
$items[$default]['count'] = $items[$default]['count'] + $items['']['count'];
unset($items['']);
}
return $this->viewRenderItems($items);
}
return array();
}
}