adding search results view, adding starting search form processing to start building
authorAnthony Talarico <talarico@gaslightmedia.com>
Mon, 6 Mar 2017 21:43:13 +0000 (16:43 -0500)
committerAnthony Talarico <talarico@gaslightmedia.com>
Mon, 6 Mar 2017 21:43:13 +0000 (16:43 -0500)
queries

models/front/obits/search.php
views/front/obits/search.html
views/front/obits/searchResults.html [new file with mode: 0644]

index 0a5c5e9..257e277 100644 (file)
@@ -19,7 +19,7 @@ require_once GLM_MEMBERS_OBITS_PLUGIN_CLASS_PATH.'/obitSupportFunctions.php';
 
 class GlmMembersFront_obits_search extends GlmDataObits
 {
-
+    public $table;
     /**
      * WordPress Database Object
      *
@@ -69,7 +69,6 @@ class GlmMembersFront_obits_search extends GlmDataObits
      */
     public function __construct ($wpdb, $config)
     {
-
         // Save WordPress Database object
         $this->wpdb = $wpdb;
 
@@ -88,24 +87,88 @@ class GlmMembersFront_obits_search extends GlmDataObits
 
     public function modelAction($actionData = false)
     {
+        $this->table = GLM_MEMBERS_OBITS_PLUGIN_DB_PREFIX . 'obits';
+        
+        $view = 'search';
+        
+//        $sql_all = "SELECT * FROM $this->table";
+//        $sql_where = "SELECT * FROM $this->table WHERE ";
+        
         $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('equals','starts','contains', 'more than', 'less than', 'between', '')
+        $logic_dropdown     = array('Contains','Starts','Equals', 'More than', 'Less than', 'Between', 'Empty');
         $form_data = $_REQUEST;
         
+        $form_fields = array(
+            $last           = filter_var( $_REQUEST['last_name'], FILTER_SANITIZE_STRING),
+            $first          = filter_var( $_REQUEST['first_mid'], FILTER_SANITIZE_STRING),
+            $byear          = filter_var( $_REQUEST['b_year'], FILTER_SANITIZE_STRING),
+            $byear_range    = filter_var( $_REQUEST['b_yr_range'], FILTER_SANITIZE_STRING),
+            $dyear          = filter_var( $_REQUEST['d_year'], FILTER_SANITIZE_STRING),
+            $dyear_range    = filter_var( $_REQUEST['d_yr_range'], FILTER_SANITIZE_STRING),
+            $maiden         = filter_var( $_REQUEST['maiden_other'], FILTER_SANITIZE_STRING),
+            $spouse         = filter_var( $_REQUEST['spouse_partner'], FILTER_SANITIZE_STRING)
+        );
+        
+//        $last           = filter_var( $_REQUEST['last_name'], FILTER_SANITIZE_STRING);
+//        $first          = filter_var( $_REQUEST['first_mid'], FILTER_SANITIZE_STRING);
+//        $byear          = filter_var( $_REQUEST['b_year'], FILTER_SANITIZE_STRING);
+//        $byear_range    = filter_var( $_REQUEST['b_yr_range'], FILTER_SANITIZE_STRING);
+//        $dyear          = filter_var( $_REQUEST['d_year'], FILTER_SANITIZE_STRING);
+//        $dyear_range    = filter_var( $_REQUEST['d_yr_range'], FILTER_SANITIZE_STRING);
+//        $maiden         = filter_var( $_REQUEST['maiden_other'], FILTER_SANITIZE_STRING);
+//        $spouse         = filter_var( $_REQUEST['spouse_partner'], FILTER_SANITIZE_STRING);
+//      
+        
+        $sql = "SELECT * FROM $this->table WHERE last_name = '$last' OR first_mid = '$first' OR b_year = '$byear' OR b_yr_range = '$byear_range' OR d_year = '$dyear' OR d_yr_range = '$dyear_range' OR maiden_other = '$maiden' OR spouse_partner = '$spouse';";
+        
+        
+        if( isset( $_REQUEST['any-condition'] ) ){
+            $clause = 'OR';
+        } else if ( isset( $_REQUEST['all-conditions'] ) ) {
+            $clause = 'AND';
+        }
+//         echo '<pre>', print_r($form_data), '</pre>';
+        // no restrictions
+        $obits = $this->wpdb->get_results($sql, 'ARRAY_A');
+//                echo '<pre>', print_r($obits), '</pre>';
+                
+                
+        foreach($form_data as $key=>$value){
+            if (isset($value) && $value !== ''){
+                if( $value !== 'Search' && $value !== 'search-results' && $key !== 'conditions'){
+                    $value = filter_var($value, FILTER_SANITIZE_STRING);
+                    $queries[$key] = array('field' => $value);
+//                    echo $value;
+                    
+                } 
+            } 
+        }
+//         echo '<pre>', print_r($queries), '</pre>';
+        foreach($queries as $key=>$value){
+//            print_r($value);
+        }
+
+        if( isset($_REQUEST['search-results']) ){
+            $view = 'searchResults';
+        }
+        
         // Compile template data
         $templateData = array(
-            'birth_death_range' => $birth_death_range
+            'birth_death_range' => $birth_death_range,
+            'sql'               => $sql,
+            'obits'             => $obits,
+            'logic'             => $logic_dropdown,
+            'clause'            => $clause
         );
              // Return status, any suggested view, and any data to controller
         return array(
             'status'        => true,
             'modelRedirect' => false,
-            'view'          => 'front/obits/search.html',
+            'view'          => "front/obits/".$view.".html",
             'data'          => $templateData
         );
 
     }
-
-
-}
+}
\ No newline at end of file
index 5e7688c..56f9f5a 100644 (file)
@@ -1,18 +1,26 @@
 <div class="search-container">
     <form action="{$thisUrl}" method="post" enctype="multipart/form-data" name="obits-search" id="obits-search">
+       <input type="hidden" value="search-results" name="search-results">
+       <input type="radio" name="conditions">All Conditions
+       <input type="radio" name="conditions">Any Condition
+         
         <div class="row search-row">
-            <div class="small-12 medium-3 columns">
+            <div class="small-12 medium-3 columns"> 
                 Last Name: 
             </div>
             <div class="small-3 large-2 columns">
-               <label for="not-search">Not</label>
-               <input type="checkbox" id="not-search">
+               <label for="not-last">Not</label>
+               <input type="checkbox" id="not-last" name="not-last">
             </div>
             <div class="small-4 medium-3 large-3 columns">
-                <select name="" id=""></select>
+                <select name="lname-logic" id="lname-logic">
+                    {foreach from=$logic item=i}
+                        <option value="{$i}">{$i}</option>
+                    {/foreach}
+                </select>
             </div>
             <div class="small-12 medium-3 large-4 columns">
-                <input type="text" name="last-name">
+                <input type="text" name="last_name">
             </div>
         </div>
         <div class="row search-row">
                 First Name &amp; Middle Initial: 
             </div>
             <div class="small-3 large-2 columns">
-               <label for="not-search">Not</label>
-               <input type="checkbox" id="not-search">
+               <label for="not-fname">Not</label>
+               <input type="checkbox" id="not-fname" name="not-fname">
             </div>
             <div class="small-4 medium-3 large-3 columns">
-                <select name="" id=""></select>
+                <select name="fname-logic" id="fname-logic">
+                    {foreach from=$logic item=i}
+                        <option value="{$i}">{$i}</option>
+                    {/foreach}
+                </select>
             </div>
             <div class="small-12 medium-3 large-4 columns">
-                <input type="text" name="first-middle">
+                <input type="text" name="first_mid">
             </div>
         </div>
         <div class="row search-row">
                 Birth Year: 
             </div>
             <div class="small-3 large-2 columns">
-               <label for="not-search">Not</label>
-               <input type="checkbox" id="not-search">
+               <label for="not-byear">Not</label>
+               <input type="checkbox" id="not-byear" name="not-byear">
             </div>
             <div class="small-4 medium-3 large-3 columns">
-                <select name="" id=""></select>
+                <select name="byear-logic" id="byear-logic">
+                    {foreach from=$logic item=i}
+                       <option value="{$i}">{$i}</option>
+                    {/foreach}
+                </select>
             </div>
             <div class="small-12 medium-3 large-4 columns">
-                <input type="text" name="birth-year">
+                <input type="text" name="b_yr_range">
             </div>
         </div>
         <div class="row search-row">
                 Birth Year Range:
             </div>
             <div class="small-3 large-2 columns">
-               <label for="not-search">Not</label>
-               <input type="checkbox" id="not-search">
+               <label for="not-brange">Not</label>
+               <input type="checkbox" id="not-brange" name="not-brange">
             </div>
             <div class="small-4 medium-3 large-3 columns">
-                <select name="" id=""></select>
+                <select name="brange-logic" id="brange-logic">
+                     <option>Equals</option>
+                </select>
             </div>
             <div class="small-12 medium-3 large-4 columns">
                <select name="birth-range" id="">
+               <option value="">Select a date range</option>
                 {foreach from=$birth_death_range.birth item=r}
                    <option value="{$r.start}">{$r.start} - {$r.end}</option>
                 {/foreach}
                 Death Year: 
             </div>
             <div class="small-3 large-2 columns">
-               <label for="not-search">Not</label>
-               <input type="checkbox" id="not-search">
+               <label for="not-death">Not</label>
+               <input type="checkbox" id="not-death">
             </div>
             <div class="small-4 medium-3 large-3 columns">
-                <select name="" id=""></select>
+                <select name="dyear-logic" id="dyear-logic">
+                    {foreach from=$logic item=i}
+                        <option value="{$i}">{$i}</option>
+                    {/foreach}
+                </select>
             </div>
             <div class="small-12 medium-3 large-4 columns">
-                <input type="text" name="death-year">
+                <input type="text" name="d_year">
             </div>
         </div>
         <div class="row search-row">
                Death Year Range: 
             </div>
             <div class="small-3 large-2 columns">
-               <label for="not-search">Not</label>
-               <input type="checkbox" id="not-search">
+               <label for="not-drange">Not</label>
+               <input type="checkbox" id="not-drange" name="not-drange">
             </div>
             <div class="small-4 medium-3 large-3 columns">
-                <select name="" id=""></select>
+                <select name="drange-logic" id="drange-logic">
+                    <option value="equals">Equals</option>
+                </select>
             </div>
             <div class="small-12 medium-3 large-4 columns">
-                <select name="death-range" id="">
+                <select name="d_yr_range" id="death-range">
+                <option value="">Select a date range</option>
                 {foreach from=$birth_death_range.death item=r}
                    <option value="{$r.start}">{$r.start} - {$r.end}</option>
                 {/foreach}
                 Maiden or Other Name:
             </div>
             <div class="small-3 large-2 columns">
-               <label for="not-search">Not</label>
-               <input type="checkbox" id="not-search">
+               <label for="not-maiden">Not</label>
+               <input type="checkbox" id="not-maiden" name="not-maiden">
             </div>
             <div class="small-4 medium-3 large-3 columns">
-                <select name="" id=""></select>
+                <select name="maiden-logic" id="maiden-logic">
+                    {foreach from=$logic item=i}
+                        <option value="{$i}">{$i}</option>
+                    {/foreach}
+                </select>
             </div>
             <div class="small-12 medium-3 large-4 columns">
-                <input type="text" name="maiden">
+                <input type="text" name="maiden_other">
             </div>
         </div>
         <div class="row search-row">
                 Spouse / Partner Name: 
             </div>
             <div class="small-3 large-2 columns">
-               <label for="not-search">Not</label>
-               <input type="checkbox" id="not-search">
+               <label for="not-spouse">Not</label>
+               <input type="checkbox" value="not" id="not-spouse" name="not-spouse">
             </div>
             <div class="small-4 medium-3 large-3 columns">
-                <select name="" id=""></select>
+                <select name="spouse-logic" id="spouse-logic">
+                    {foreach from=$logic item=i}
+                        <option value="{$i}">{$i}</option>
+                    {/foreach}
+                </select>
             </div>
             <div class="small-12 medium-3 large-4 columns">
-                <input type="text" name="spouse">
+                <input type="text" name="spouse_partner">
             </div>
         </div>
         <input id="input" class="search-button" name="searchButton" value="Search" type="submit">
diff --git a/views/front/obits/searchResults.html b/views/front/obits/searchResults.html
new file mode 100644 (file)
index 0000000..e69de29