adding operators the get params and fixing the where clause for pagination
authorAnthony Talarico <talarico@gaslightmedia.com>
Tue, 4 Apr 2017 20:31:35 +0000 (16:31 -0400)
committerAnthony Talarico <talarico@gaslightmedia.com>
Tue, 4 Apr 2017 20:31:35 +0000 (16:31 -0400)
models/front/obits/search.php
views/front/obits/searchResults.html

index dcdefb8..3bcb6be 100644 (file)
@@ -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
index bc16001..0cb27b2 100644 (file)
@@ -6,8 +6,8 @@
     <!--            {include file='front/obits/search.html'}-->
                 <div class="search-container sidebar-container row">
                     <div class="small-12 columns">
-                       <input class="sidebar-criteria" type="radio" {if $clause == ' AND '}checked {/if} value="all" name="conditions[]">All 
-                       <input class="sidebar-criteria" type="radio" {if $clause == ' OR '}checked {/if} value="any" name="conditions[]">Any 
+                       <input class="sidebar-criteria" type="radio" {if $clause == 'AND'}checked {/if} value="all" name="conditions[]">All 
+                       <input class="sidebar-criteria" type="radio" {if $clause == 'OR'}checked {/if} value="any" name="conditions[]">Any 
                    
                            <a href="#" class="expand-collapse">Show Options</a>