Index: trunk/extensions/SemanticDrilldown/includes/SD_AppliedFilter.php |
— | — | @@ -8,11 +8,25 @@ |
9 | 9 | |
10 | 10 | class SDAppliedFilter { |
11 | 11 | var $filter; |
12 | | - var $values; |
| 12 | + var $values = array(); |
| 13 | + var $search_term; |
| 14 | + var $lower_date; |
| 15 | + var $upper_date; |
| 16 | + var $lower_date_string; |
| 17 | + var $upper_date_string; |
13 | 18 | |
14 | | - function create($filter, $values) { |
| 19 | + function create($filter, $values, $search_term = null, $lower_date = null, $upper_date = null) { |
15 | 20 | $af = new SDAppliedFilter(); |
16 | 21 | $af->filter = $filter; |
| 22 | + $af->search_term = str_replace('_', ' ', $search_term); |
| 23 | + if ($lower_date != null) { |
| 24 | + $af->lower_date = $lower_date; |
| 25 | + $af->lower_date_string = sdfMonthToString($lower_date['month']) . " " . $lower_date['day'] . ", " . $lower_date['year']; |
| 26 | + } |
| 27 | + if ($upper_date != null) { |
| 28 | + $af->upper_date = $upper_date; |
| 29 | + $af->upper_date_string = sdfMonthToString($upper_date['month']) . " " . $upper_date['day'] . ", " . $upper_date['year']; |
| 30 | + } |
17 | 31 | if (! is_array($values)) { |
18 | 32 | $values = array($values); |
19 | 33 | } |
— | — | @@ -30,6 +44,26 @@ |
31 | 45 | function checkSQL($value_field) { |
32 | 46 | $sql = "("; |
33 | 47 | $dbr = wfGetDB( DB_SLAVE ); |
| 48 | + if ($this->search_term != null) { |
| 49 | + if ($this->filter->is_relation) { |
| 50 | + $search_term = strtolower(str_replace(' ', '_', $this->search_term)); |
| 51 | + $sql .= "LOWER($value_field) LIKE '%{$search_term}%'"; |
| 52 | + } else { |
| 53 | + $search_term = strtolower($this->search_term); |
| 54 | + $sql .= "LOWER($value_field) LIKE '%{$search_term}%'"; |
| 55 | + } |
| 56 | + } |
| 57 | + if ($this->lower_date != null) { |
| 58 | + $date_string = $this->lower_date['year'] . "-" . $this->lower_date['month'] . "-" . $this->lower_date['day']; |
| 59 | + $sql .= "date($value_field) >= date('$date_string') "; |
| 60 | + } |
| 61 | + if ($this->upper_date != null) { |
| 62 | + if ($this->lower_date != null) { |
| 63 | + $sql .= " AND "; |
| 64 | + } |
| 65 | + $date_string = $this->upper_date['year'] . "-" . $this->upper_date['month'] . "-" . $this->upper_date['day']; |
| 66 | + $sql .= "date($value_field) <= date('$date_string') "; |
| 67 | + } |
34 | 68 | foreach ($this->values as $i => $fv) { |
35 | 69 | if ($i > 0) {$sql .= " OR ";} |
36 | 70 | if ($fv->is_other) { |