From b8bdbd87b3e7a4228a9bb296f7a029457817d34c Mon Sep 17 00:00:00 2001 From: Steve Sutton Date: Mon, 5 Nov 2018 11:11:34 -0500 Subject: [PATCH] Add county search into the shortcode. Can now add county into shortcode. --- models/front/members/list.php | 36 +++++++++++++++++++++++++++++++++++ setup/shortcodes.php | 12 ++++++++++++ 2 files changed, 48 insertions(+) diff --git a/models/front/members/list.php b/models/front/members/list.php index 566583e3..bcaaadfc 100755 --- a/models/front/members/list.php +++ b/models/front/members/list.php @@ -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'] ) diff --git a/setup/shortcodes.php b/setup/shortcodes.php index f0fcca22..bc917a05 100644 --- a/setup/shortcodes.php +++ b/setup/shortcodes.php @@ -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. + + +   + + county-search="{ county ID }" + + + 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. +   -- 2.17.1