Update search overlay
authorSteve Sutton <steve@gaslightmedia.com>
Fri, 9 Feb 2018 20:36:59 +0000 (15:36 -0500)
committerSteve Sutton <steve@gaslightmedia.com>
Fri, 9 Feb 2018 20:36:59 +0000 (15:36 -0500)
Add our cities categories and regions.
Also fix member links.

functions.php
glm-member-db-events/views/front/events/searchForm.html
glm-member-db/views/front/members/list.html
inc/search-filters.php [new file with mode: 0644]
template-parts/search-overlay.php

index ca95d47..42f8b78 100644 (file)
@@ -343,3 +343,29 @@ function is_blog () {
         $posttype = get_post_type($post );
         return ( ((is_archive()) || (is_author()) || (is_category()) || (is_home()) || (is_single()) || (is_tag())) && ( $posttype == 'post')  ) ? true : false ;
   }
+add_filter('member_list_header_search', function(){
+    $regions = make_array( apply_filters('glm_getListForSearch', 'region'), 'region');
+    $cities = make_array( apply_filters('glm_getListForSearch', 'city'), 'city');
+
+    uasort($regions, function ($item1, $item2) {
+        if ($item1['name'] == $item2['name']) return 0;
+        return $item1['name'] < $item2['name'] ? -1 : 1;
+    });
+    uasort($cities, function ($item1, $item2) {
+        if ($item1['name'] == $item2['name']) return 0;
+        return $item1['name'] < $item2['name'] ? -1 : 1;
+    });
+    $search_array = array(
+        'regions' => $regions,
+        'cities'  => $cities,
+    );
+    $search_array = json_encode( $search_array );
+    return $search_array;
+});
+function make_array($category, $id_field){
+    $new_array = array();
+    foreach($category as $key=>$value){
+        $new_array[$value[$id_field]] = $value;
+    }
+    return $new_array;
+}
index cad1b7a..a0a941c 100644 (file)
@@ -6,12 +6,15 @@
         <h1>Find An Event</h1>
         <form action="{$currentUrl}">
             <input type="hidden" name="search" value="1">
+                {if $smarty.request.s}
+                <input type="hidden" name="s" value="{$smarty.request.s|escape}">
+                {/if}
             <div class="row">
                 <div class="small-12 medium-12 large-5 columns">
                     <input class="glm-search-icon right" type="image" alt="Search" src="{$assetsUrl}search-icon-24x24.png">
                     <input id="glm-event-name" name="event_name" placeholder="Event Name" value="{$eventName}">
                 </div>
-                
+
                 <div class="small-6 small-text-center medium-6 large-4 medium-text-right columns">
                     <a id="glm-event-add-event" href="{$siteBaseUrl}add-event/" class="tiny button success">Add an Event</a>
                 </div>
@@ -83,7 +86,7 @@
                     <img class="right" title="iCal Feed" id="glm-event-ical-feed" src="{$assetsUrl}calendar-icon-24x24.png" />
                     </a>
                 </div>
-                
+
             </div>
         </form>
     </div>
index 958b4be..a3b0141 100644 (file)
 <div class="glm-member-list-listing-container">
 {if $settings.list_show_search_alpha}
     <div class="glm-alpha-links">
-        <a href="{$thisUrl}?glm_action=list&textSearch={$textSearch}{if $smarty.request.s}&s={$textSearch}s={$textSearch}{/if}&categorySearch={$catSearchSelected}&regionSearch={$regionSearchSelected}" class="glm-alpha-link{if !$alphaSelected} glm-alpha-link-selected{/if}">All</a>
+        <a href="{$thisUrl}?glm_action=list&textSearch={$textSearch}{if $smarty.request.s}&s={$textSearch}{/if}&categorySearch={$catSearchSelected}&regionSearch={$regionSearchSelected}" class="glm-alpha-link{if !$alphaSelected} glm-alpha-link-selected{/if}">All</a>
   {foreach $alphaList as $a}
-        <a href="{$thisUrl}?glm_action=list&alpha={$a.alpha}&textSearch={$textSearch}{if $smarty.request.s}&s={$textSearch}s={$textSearch}{/if}&categorySearch={$catSearchSelected}&regionSearch={$regionSearchSelected}" class="glm-alpha-link{if $a.default} glm-alpha-link-selected{/if}">{$a.alpha}</a>
+        <a href="{$thisUrl}?glm_action=list&alpha={$a.alpha}&textSearch={$textSearch}{if $smarty.request.s}&s={$textSearch}{/if}&categorySearch={$catSearchSelected}&regionSearch={$regionSearchSelected}" class="glm-alpha-link{if $a.default} glm-alpha-link-selected{/if}">{$a.alpha}</a>
   {/foreach}
    </div>
 {/if}
 
 {if $paging}
     <br>
-    <a href="{$thisUrl}?glm_action=list&textSearch={$textSearch}{if $smarty.request.s}&s={$textSearch}s={$textSearch}{/if}&categorySearch={$catSearchSelected}&regionSearch={$regionSearchSelected}&pageSelect=Previous&prevStart={$prevStart}&nextStart={$nextStart}&limit={$limit}&alpha={$alphaSelected}" class="glm-alpha-link" {if !$prevStart} style="pointer-events: none; opacity: 0.5;"{/if}>Previous page</a>
-    <a href="{$thisUrl}?glm_action=list&textSearch={$textSearch}{if $smarty.request.s}&s={$textSearch}s={$textSearch}{/if}&categorySearch={$catSearchSelected}&regionSearch={$regionSearchSelected}&pageSelect=Next&prevStart={$prevStart}&nextStart={$nextStart}&limit={$limit}&alpha={$alphaSelected}" class="glm-alpha-link" {if !$nextStart} style="pointer-events: none; opacity: 0.5;"{/if}>Next page</a>
+    <a href="{$thisUrl}?glm_action=list&textSearch={$textSearch}{if $smarty.request.s}&s={$textSearch}{/if}&categorySearch={$catSearchSelected}&regionSearch={$regionSearchSelected}&pageSelect=Previous&prevStart={$prevStart}&nextStart={$nextStart}&limit={$limit}&alpha={$alphaSelected}" class="glm-alpha-link" {if !$prevStart} style="pointer-events: none; opacity: 0.5;"{/if}>Previous page</a>
+    <a href="{$thisUrl}?glm_action=list&textSearch={$textSearch}{if $smarty.request.s}&s={$textSearch}{/if}&categorySearch={$catSearchSelected}&regionSearch={$regionSearchSelected}&pageSelect=Next&prevStart={$prevStart}&nextStart={$nextStart}&limit={$limit}&alpha={$alphaSelected}" class="glm-alpha-link" {if !$nextStart} style="pointer-events: none; opacity: 0.5;"{/if}>Next page</a>
     <br>
     showing {$start} through {$lastDisplayed} of {$filteredMembersFound}
 {/if}
 
-
 {if $view == grid}
     <ul class="row">
     {foreach $members as $member}
 
 {if $paging}
     <br>
-    <a href="{$thisUrl}?glm_action=list&textSearch={$textSearch}{if $smarty.request.s}&s={$textSearch}s={$textSearch}{/if}&categorySearch={$catSearchSelected}&regionSearch={$regionSearchSelected}&pageSelect=Previous&prevStart={$prevStart}&nextStart={$nextStart}&limit={$limit}&alpha={$alphaSelected}" class="glm-alpha-link" {if !$prevStart} style="pointer-events: none; opacity: 0.5;"{/if}>Previous page</a>
-    <a href="{$thisUrl}?glm_action=list&textSearch={$textSearch}{if $smarty.request.s}&s={$textSearch}s={$textSearch}{/if}&categorySearch={$catSearchSelected}&regionSearch={$regionSearchSelected}&pageSelect=Next&prevStart={$prevStart}&nextStart={$nextStart}&limit={$limit}&alpha={$alphaSelected}" class="glm-alpha-link" {if !$nextStart} style="pointer-events: none; opacity: 0.5;"{/if}>Next page</a>
+    <a href="{$thisUrl}?glm_action=list&textSearch={$textSearch}{if $smarty.request.s}&s={$textSearch}{/if}&categorySearch={$catSearchSelected}&regionSearch={$regionSearchSelected}&pageSelect=Previous&prevStart={$prevStart}&nextStart={$nextStart}&limit={$limit}&alpha={$alphaSelected}" class="glm-alpha-link" {if !$prevStart} style="pointer-events: none; opacity: 0.5;"{/if}>Previous page</a>
+    <a href="{$thisUrl}?glm_action=list&textSearch={$textSearch}{if $smarty.request.s}&s={$textSearch}{/if}&categorySearch={$catSearchSelected}&regionSearch={$regionSearchSelected}&pageSelect=Next&prevStart={$prevStart}&nextStart={$nextStart}&limit={$limit}&alpha={$alphaSelected}" class="glm-alpha-link" {if !$nextStart} style="pointer-events: none; opacity: 0.5;"{/if}>Next page</a>
     <br>
     showing {$start} through {$lastDisplayed} of {$filteredMembersFound}
 {/if}
diff --git a/inc/search-filters.php b/inc/search-filters.php
new file mode 100644 (file)
index 0000000..74f3fc9
--- /dev/null
@@ -0,0 +1,7 @@
+<?php
+$search_array = apply_filters('member_list_header_search', '');
+$decode_array = json_decode($search_array, true);
+$regions = $decode_array['regions'];
+$cities = $decode_array['cities'];
+
+?>
index 2193853..676b0d7 100644 (file)
@@ -6,65 +6,45 @@
         <form id="search-wmta" method="get"  action="" onsubmit="event.preventDefault();">
 
             <div><input tabindex="0" autofocus id="tag" type="search" class="search-all" value="" placeholder="Search by topic, keyword, etc." ></div>
+<?php
+$search_array = apply_filters('member_list_header_search', '');
+$decode_array = json_decode($search_array, true);
+$regions = $decode_array['regions'];
+$cities = $decode_array['cities'];
 
+?>
              <div class="select-wrap">
                 <div class="select-arrow">
 
+            <?php $categories = apply_filters('member_categories', false); ?>
                     <select id="lbl" class="chosen-select" data-placeholder="Select a category">
-                        <option value="">Search All Categories</option>
-                        <option value="569f1813ec5a499f06831f5f">Agri-tourism &amp; Farmers Markets</option>
-                        <option value="569f16d34f952e0e62684e64">Area Information</option>
-                        <option value="569f16d94f952e0e62684e65">Arts &amp; Culture</option>
-                        <option value="569f1821ec5a49c906831f5f">Attractions</option>
-                        <option value="569f16e04f952e4562684e64">Beaches</option>
-                        <option value="569f16e64f952ec762684e64">Bed &amp; Breakfast</option>
-                        <option value="569f1864ec5a497506831f5f">Eat & Drink</option>
-                        <option value="569f186fec5a494406831f61">Boating</option>
-                        <option value="569f17354f952ec462684e65">Breweries</option>
-                        <option value="569f187dec5a49c906831f60">Campgrounds &amp; RV Parks</option>
-                        <option value="569f17404f952e4d62684e65">Casinos</option>
-                        <option value="569f17444f952e4d62684e66">Confections</option>
-                        <option value="569f17494f952e9462684e66">Cottages &amp; Cabins</option>
-                        <option value="569f1892ec5a499d06831f5f">Culinary Tours</option>
-                        <option value="569f17544f952ec562684e64">Dinner Cruises &amp; Shows</option>
-                        <option value="569f189cec5a494406831f62">Distilleries</option>
-                        <option value="569f175c4f952ee960684e64">Entertainment/Nightlife</option>
-                        <option value="569f17614f952e6d62684e64">Equestrian</option>
-                        <option value="569f17654f952e6d62684e65">Experiences &amp; Tours</option>
-                        <option value="569f17694f952ea362684e64">Festivals &amp; Fairs</option>
-                        <option value="569f176c4f952e4d62684e67">Golf</option>
-                        <option value="569f17704f952e9f62684e64">Haunted</option>
-                        <option value="569f18b8ec5a49c406831f5f">Historic Sites</option>
-                        <option value="569f17784f952e1362684e64">Hotels &amp; Motels</option>
-                        <option value="569f18c0ec5a496206831f60">Hunting &amp; Fishing</option>
-                        <option value="569f177f4f952e1362684e65">Kids Activities</option>
-                        <option value="569f17834f952ee960684e65">Local Info</option>
-                        <option value="5924621d9865a11a13e009f4">Mead</option>
-                        <option value="569f18ccec5a496406831f62">Museums</option>
-                        <option value="569f18d0ec5a49dc06831f5f">Outdoor Recreation</option>
-                        <option value="569f18d4ec5a494606831f61">Paddle Sports</option>
-                        <option value="569f17954f952ea162684e64">Places To Stay</option>
-                        <option value="569f18deec5a493d06831f60">Resorts</option>
-                        <option value="569f179d4f952ea162684e65">Restaurants</option>
-                        <option value="569f17a04f952e6862684e65">Shopping</option>
-                        <option value="569f18e8ec5a493e06831f60">Snow Sports</option>
-                        <option value="569f17a94f952e6862684e66">Spas &amp; Wellness</option>
-                        <option value="569f18f2ec5a499b06831f61">Things To Do</option>
-                        <option value="569f17b14f952e8562684e65">Transportation</option>
-                        <option value="569f17b64f952e1a62684e64">Vacation Rentals</option>
-                        <option value="569f18feec5a49af06831f5f">Vendors</option>
-                        <option value="569f1903ec5a49bf06831f5f">Water Parks</option>
-                        <option value="569f17c44f952e5b62684e64">Wedding/Event Venues</option>
-                        <option value="569f190dec5a49af06831f60">Wineries</option>
-                        <option value="569f1912ec5a49aa06831f5f">Zoos &amp; Nature Centers</option>
+                    <option value="">Search All Categories</option>
 
+            <?php if( isset($categories) && is_array($categories) ){
+                    foreach ($categories as $key=>$val){ ?>
+                <?php if( $val['parent']['value'] !== 0){ ?>
+                    <option value="<?php echo $val['id']; ?>">&nbsp;&nbsp;&nbsp;<?php echo $val['name']; ?></option>
+                <?php } else { ?>
+                    <option value="<?php echo $val['id']; ?>"><?php echo $val['name']; ?></option>
+                <?php }  ?>
+            <?php } }?>
 
                     </select>
                 </div>
 
                  <div class="select-arrow">
 
-                     <?php select_dropdown_cities(); ?>
+                    <select id="xlo" class="chosen-select" data-placeholder="Select a location">
+                    <option value="">Search All Locations</option>
+                        <?php foreach($cities as $city){ ?>
+                            <?php $city_id = str_replace("'", "", $city['city']); ?>
+                            <?php if( $selected_city == $city['city']) { ?>
+                            <option selected value="<?php echo $city_id; ?>"><?php echo $city['name']; ?></option>
+                              <?php } else { ?>
+                                  <option value="<?php echo $city_id; ?>"><?php echo $city['name']; ?></option>
+                               <?php } ?>
+                        <?php } ?>
+                    </select>
 
                  </div>
 
 
                      <select id="xre" class="chosen-select" data-placeholder="Select a region">
                          <option value="">Search All Regions</option>
-                         <option value="North">North</option>
-                         <option value="Central">Central</option>
-                         <option value="South">South</option>
-                         <option value="Statewide">Statewide</option>
-                         <option value="Upper Peninsula">Upper Peninsula</option>
+
+                            <?php foreach($regions as $region){ ?>
+                            <?php if( $selected_region == $region['region']) { ?>
+                                <option selected value="<?php echo $region['region']; ?>"><?php echo $region['name']; ?></option>
+                                <?php } else { ?>
+                                     <option value="<?php echo $region['region']; ?>"><?php echo $region['name']; ?></option>
+                                 <?php } ?>
+                            <?php } ?>
 
                      </select>
                  </div>
 
         var myEl = document.getElementById('overlay_search');
 
-        myEl.addEventListener('click', function() {window.location = '<?php esc_url( home_url());echo '/?s='; ?>' + encodeURI(document.getElementById('tag').value) + '&textSearch='+ encodeURI(document.getElementById('tag').value) +'&glm_action=list';
+        myEl.addEventListener('click', function() {
+            var search_url = '<?php esc_url( home_url());?>'
+                + '/?s=' + encodeURI(document.getElementById('tag').value) + '&textSearch='+ encodeURI(document.getElementById('tag').value) +'&glm_action=list'
+                + '&categorySearch=' + encodeURI(document.getElementById('lbl').value)
+                + '&cityUserSearch[]=' + encodeURI(document.getElementById('xlo').value)
+                + '&regionUserSearch[]=' + encodeURI(document.getElementById('xre').value);
+            window.location = search_url;
+
         //'#!directory/map/ord=rnd/tag=' + encodeURI(document.getElementById('tag').value) + '/lbl=' + encodeURI(document.getElementById('lbl').value)  + '/xlo=' + encodeURI(document.getElementById('xlo').value) + '/xre=' + encodeURI(document.getElementById('xre').value) ;