-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathbuild-search-query.php
96 lines (92 loc) · 3.46 KB
/
build-search-query.php
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
<?
/* Build a standard PHP object from the first available source of search properties:
* > DO NOTHING if the expected object is already defined and non-empty
* > LATER: build from DB record (stored query) if $savedSearchID is provided
* > try to build from $_GET vars, if found
*
* NOTE: We should be able to include this mutiple times, with NO side effects
* since it only builds once. This makes it easy to build an accurate search UI,
* to embed the results panel in the main search page, and also call separately
* for results via AJAX.
*/
if (!isset($search) || ($search == null)) {
// try to build the expected search object (skip if it's already defined)
// build default search (show all calibrations, most recently added first)
$search = Array(
'SimpleSearch' => '',
// TODO: allow for a SERIES of tags/tokens here?
'FilterByTipTaxa' => Array(
'TaxonA' => '',
'TaxonB' => ''
),
'FilterByClade' => '',
// a single name (different from single tip taxon?)
'FilterByAge' => Array(
'MinAge' => '',
'MaxAge' => ''
),
'FilterByGeologicalTime' => '',
// allow one age only?
'HiddenFilters' => Array(
'FilterByTipTaxa',
'FilterByClade',
'FilterByAge',
'FilterByGeologicalTime'
),
// to preserve values that were entered, then hidden
'BlockedFilters' => Array(),
// to preserve values that were entered, but blocked by rules
'SortResultsBy' => 'RELEVANCE_DESC', // was 'DATE_ADDED_DESC',
'ResponseType' => 'HTML'
// support JSON response, others?
);
// apply submitted ($_GET) variables, if found
if (isset($_GET['SimpleSearch'])) {
$search['SimpleSearch'] = trim($_GET['SimpleSearch']);
if (isset($_GET['TaxonA'])) {
$search['FilterByTipTaxa']['TaxonA'] = trim($_GET['TaxonA']);
}
if (isset($_GET['TaxonB'])) {
$search['FilterByTipTaxa']['TaxonB'] = trim($_GET['TaxonB']);
}
if (isset($_GET['FilterByClade'])) {
$search['FilterByClade'] = trim($_GET['FilterByClade']);
}
if (isset($_GET['MinAge'])) {
$search['FilterByAge']['MinAge'] = trim($_GET['MinAge']);
}
if (isset($_GET['MaxAge'])) {
// clear zero in MaxAge (will disappear on page reload)
$search['FilterByAge']['MaxAge'] = trim($_GET['MaxAge']) == '0' ?
'' : trim($_GET['MaxAge']);
}
if (isset($_GET['FilterByGeologicalTime'])) {
$search['FilterByGeologicalTime'] = trim($_GET['FilterByGeologicalTime']);
}
if (isset($_GET['HiddenFilters'])) {
$search['HiddenFilters'] = $_GET['HiddenFilters']; // should be an Array
}
if (isset($_GET['BlockedFilters'])) {
$search['BlockedFilters'] = $_GET['BlockedFilters']; // should be an Array
}
if (isset($_GET['SortResultsBy'])) {
$search['SortResultsBy'] = trim($_GET['SortResultsBy']);
}
if (isset($_GET['ResponseType'])) {
$search['ResponseType'] = trim($_GET['ResponseType']);
}
}
// add diagnostic info to page
?>
<a href="#" onclick="$('.search-details').toggle();" style="color: #c33; background-color: #ffd; padding: 2px 4px;; font-size: 10px; position: absolute; left: 0; top: 0;">show/hide search details</a>
<div class="search-details" style="">
<pre id="request-details" style="color: #c33; width: 48%; float: left;">======== GET (form) values ========
<?= htmlentities(print_r($_GET, TRUE)); ?>
</pre>
<pre id="search-object-details" style="color: #33c; width: 48%; float: left;">======== $search object ========
<?= htmlentities(print_r($search, TRUE)); ?>
</pre>
</div>
<?
}
?>