From b50ee2b8d3d61cf9942ac93e1c11d34ebec225a1 Mon Sep 17 00:00:00 2001 From: Anthony Talarico Date: Tue, 4 Apr 2017 16:31:35 -0400 Subject: [PATCH] adding operators the get params and fixing the where clause for pagination --- models/front/obits/search.php | 26 ++++++++++++++++++-------- views/front/obits/searchResults.html | 4 ++-- 2 files changed, 20 insertions(+), 10 deletions(-) diff --git a/models/front/obits/search.php b/models/front/obits/search.php index dcdefb8..3bcb6be 100644 --- a/models/front/obits/search.php +++ b/models/front/obits/search.php @@ -104,16 +104,16 @@ class GlmMembersFront_obits_search extends GlmDataObits $empty_search = false; $search_fields = false; - $this->table = GLM_MEMBERS_OBITS_PLUGIN_DB_PREFIX . 'obits'; + $this->table = GLM_MEMBERS_OBITS_PLUGIN_DB_PREFIX . 'obits'; - $view = 'search'; - $placeholders = array('Last Name', 'First Middle', 'Birth Year', 'Death Year', 'Maiden or Other Name', 'Spouse or Partner Name'); + $view = 'search'; + $placeholders = array('Last Name', 'First Middle', 'Birth Year', 'Death Year', 'Maiden or Other Name', 'Spouse or Partner Name'); $year_ranges = new glmObitSupportFunctions($this->wpdb, $this->config); $birth_death_range = array('birth' => $year_ranges->getObitYearRange(BIRTH_YEAR_START), 'death' => $year_ranges->getObitYearRange(DEATH_YEAR_START)); $logic_dropdown = array('Contains' => 'LIKE' ,'Starts With' => 'LIKE%','Equals' => '=', 'More than' => '>', 'Less than' => '<'); - $per_page = isset( $_REQUEST['results-limit']) ? (int)filter_var( $_REQUEST['results-limit'], FILTER_SANITIZE_STRING) : 50; + $per_page = isset( $_REQUEST['results-limit']) ? (int)filter_var( $_REQUEST['results-limit'], FILTER_SANITIZE_STRING) : 50; // only execute search if the search button is clicked or there are search params in the url if ( isset( $_REQUEST['searchButton'] ) || !empty( $_GET['alpha'] ) || !empty( $_GET['pageSelect'] ) ){ @@ -162,6 +162,12 @@ class GlmMembersFront_obits_search extends GlmDataObits $clause = ' OR '; } else if ( isset( $_REQUEST['conditions'] ) && $_REQUEST['conditions'][0] == 'all') { $clause = ' AND '; + } else if( isset( $_REQUEST['clause'] ) && $_REQUEST['clause'] == 'OR'){ + $clause = ' OR '; + } else if( isset( $_REQUEST['clause'] ) && $_REQUEST['clause'] == 'AND' ) { + $clause = ' AND '; + }else { + $clause = ' AND '; } // separate the search fields from the logic ('not', 'contains, 'equals') etc. @@ -243,10 +249,14 @@ class GlmMembersFront_obits_search extends GlmDataObits if($value !== ''){ $where .= "$key LIKE '%$value%' $clause "; } - } // remove the last AND or OR statement from the query string -// $where = substr($where, 0, -5); + if ($clause === ' AND '){ + $where = substr($where, 0, -5); + } else { + $where = substr($where, 0, -4); + } + } else { @@ -270,9 +280,9 @@ class GlmMembersFront_obits_search extends GlmDataObits $start = $newStart; } } - + $obits = $this->getList($where, 'last_name', $fieldVals = true, $idField = 'id', $start, $per_page); - echo $where; + $returned = $obits['returned']; // Get paging results diff --git a/views/front/obits/searchResults.html b/views/front/obits/searchResults.html index bc16001..0cb27b2 100644 --- a/views/front/obits/searchResults.html +++ b/views/front/obits/searchResults.html @@ -6,8 +6,8 @@