Add county search into the shortcode.
authorSteve Sutton <steve@gaslightmedia.com>
Mon, 5 Nov 2018 16:11:34 +0000 (11:11 -0500)
committerSteve Sutton <steve@gaslightmedia.com>
Mon, 5 Nov 2018 16:13:20 +0000 (11:13 -0500)
Can now add county into shortcode.

models/front/members/list.php
setup/shortcodes.php

index 566583e..bcaaadf 100755 (executable)
@@ -329,6 +329,11 @@ class GlmMembersFront_members_list extends GlmDataMemberInfo
         $Regions = new GlmDataRegions($this->wpdb, $this->config);
         $regionData = $Regions->getListForSearch(true);
 
+        // Get counties for possible use in search pick list for counties used in active member info records.
+        require_once GLM_MEMBERS_PLUGIN_CLASS_PATH.'/data/dataCounties.php';
+        $Counties = new GlmDataCounties($this->wpdb, $this->config);
+        $countyData = $Counties->getListForSearch(true);
+
         // Get cities for possible use in search pick list for cities used in active member info records.
         require_once GLM_MEMBERS_PLUGIN_CLASS_PATH.'/data/dataCities.php';
         $cities = new GlmDataCities($this->wpdb, $this->config);
@@ -366,6 +371,37 @@ class GlmMembersFront_members_list extends GlmDataMemberInfo
 
         }
 
+        $counties = array();
+        // If we have a county set in shortcode or via URL.
+        if ($actionData['request']['county-search']) {
+
+            // Convert comma separated list to an array
+            $countiesRequested = explode( ',', $actionData['request']['county-search'] );
+
+            // Check for numeric ID's only
+            while ( list( $k, $v ) = each( $countiesRequested ) ) {
+                if ( preg_match( '/^[0-9]*$/', trim( $v ) && $v > 0 ) ) {
+                    $counties[] = ( $v - 0 );
+                }
+            }
+
+            if ( isset( $counties ) && !empty( $counties ) ) {
+                $where .= $whereSep." T.county IN (" . implode( ',', $counties ) . ")";
+                $whereSep = ' AND ';
+            }
+        }
+
+        // If there's counties shortcode or url options to restrict this page to certain counties
+        if (count($counties) > 0) {
+
+            while ( list($k,$v) = each ($countyData) ) {
+                if (!in_array($v['id'], $counties)) {
+                    unset ($countyData[$k]);
+                }
+            }
+
+        }
+
         // If we have a city set in shortcode or via URL.
         $cities = array();
         if ( isset( $actionData['request']['city-search'] )
index f0fcca2..bc917a0 100644 (file)
@@ -88,6 +88,7 @@ if ( isset( $config['settings'] ) && $config['settings']['enable_members'] ) {
                 'text-search'           => false,
                 'amenity-search'        => false,
                 'region-search'         => false,
+                'county-search'         => false,
                 'alpha'                 => false,
                 'blank-start'           => false,
                 'show'                  => false,
@@ -313,6 +314,17 @@ if ( isset( $config['settings'] ) && $config['settings']['enable_members'] ) {
                 region. The region is specified by ID rather than name. This may be overridden by
                 a "regionSearch" URL parameter.
             </td>
+        </tr>
+        <tr>
+            <td>&nbsp;</td>
+            <th>
+                county-search="{ county ID }"
+            </th>
+            <td>
+                The "county-search" attribute selects members who are listed in the specified
+                county. The county is specified by ID rather than name. This may be overridden by
+                a "countySearch" URL parameter.
+            </td>
         </tr>
             <tr>
             <td>&nbsp;</td>