r44201 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r44200‎ | r44201 | r44202 >
Date:23:27, 3 December 2008
Author:yaron
Status:deferred
Tags:
Comment:
Added handling for new fields - search term, and lower and upper dates for a date range
Modified paths:
  • /trunk/extensions/SemanticDrilldown/includes/SD_AppliedFilter.php (modified) (history)

Diff [purge]

Index: trunk/extensions/SemanticDrilldown/includes/SD_AppliedFilter.php
@@ -8,11 +8,25 @@
99
1010 class SDAppliedFilter {
1111 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;
1318
14 - function create($filter, $values) {
 19+ function create($filter, $values, $search_term = null, $lower_date = null, $upper_date = null) {
1520 $af = new SDAppliedFilter();
1621 $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+ }
1731 if (! is_array($values)) {
1832 $values = array($values);
1933 }
@@ -30,6 +44,26 @@
3145 function checkSQL($value_field) {
3246 $sql = "(";
3347 $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+ }
3468 foreach ($this->values as $i => $fv) {
3569 if ($i > 0) {$sql .= " OR ";}
3670 if ($fv->is_other) {

Status & tagging log