From e25fcf2b02e55500cf70eb7cf68406617b683dd1 Mon Sep 17 00:00:00 2001 From: Steve Sutton Date: Thu, 14 Feb 2019 10:04:43 -0500 Subject: [PATCH] Updates for counties. Add event form updates: Switch over to using nominatim for the lat lon (geocoding). Move county field between city and state. --- models/front/events/frontAdd.php | 67 ++++++++++++++++------------ views/admin/events/editLocation.html | 52 +++++++++++---------- views/admin/management/events.html | 6 ++- views/front/events/frontAdd.html | 23 +++++++--- 4 files changed, 89 insertions(+), 59 deletions(-) diff --git a/models/front/events/frontAdd.php b/models/front/events/frontAdd.php index aaae766..4197800 100644 --- a/models/front/events/frontAdd.php +++ b/models/front/events/frontAdd.php @@ -13,6 +13,7 @@ require_once GLM_MEMBERS_PLUGIN_PATH.'/models/admin/ajax/imageUpload.php'; require_once GLM_MEMBERS_EVENTS_PLUGIN_CLASS_PATH.'/data/dataRecurrences.php'; require_once GLM_MEMBERS_EVENTS_PLUGIN_CLASS_PATH.'/data/dataManagement.php'; require_once GLM_MEMBERS_PLUGIN_CLASS_PATH.'/data/dataCities.php'; +require_once GLM_MEMBERS_PLUGIN_CLASS_PATH.'/data/dataCounties.php'; /** * GLmMembersFront_event_fontAdd @@ -65,19 +66,12 @@ class GLmMembersFront_events_frontAdd extends GlmDataEvents foreach ($address as $key => &$part) { $part = urlencode($part); } - $addressString = implode( ',', $address); - $url = "//maps.googleapis.com/maps/api/geocode/json?address={$addressString}"; - $ch = curl_init($url); - curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); - $return = json_decode(curl_exec($ch)); - curl_close($ch); - if (isset($return->results)) { - $location = $return->results[0]->geometry->location; - - return array( - $location->lat, - $location->lng - );; + $addressString = $address[0] . ',+' . $address[1] . '+' . $address[2]; + + $url = "https://nominatim.openstreetmap.org/search/?format=json&addressdetails=1&q={$addressString}&limit=1"; + $return = json_decode( wp_remote_retrieve_body( wp_remote_get( $url ) ) ); + if ( $return[0]->lat && $return[0]->lon ) { + return array( $return[0]->lat, $return[0]->lon); } else { return false; } @@ -212,8 +206,9 @@ class GLmMembersFront_events_frontAdd extends GlmDataEvents $eventAmenities = array(); $venues = false; $startTimeOnly = 0; - $eventCategories = []; + $eventCategories = array(); $cities = array(); + $counties = array(); if ( isset( $actionData['request']['member_only'] ) && $memberOnly = filter_var( $actionData['request']['member_only'], FILTER_VALIDATE_BOOLEAN ) ) { @@ -241,8 +236,18 @@ class GLmMembersFront_events_frontAdd extends GlmDataEvents // populate cities dropdown $cityData = new GlmDataCities( $this->wpdb, $this->config ); $cityVals = $cityData->getList( null, 'name' ); - foreach ( $cityVals as $city ) { - $cities[$city['id']] = $city['name']; + if ( isset( $cityVals ) && is_array( $cityVals ) && !empty( $cityVals ) ) { + foreach ( $cityVals as $city ) { + $cities[$city['id']] = $city['name']; + } + } + // populate counties dropdown + $countyData = new GlmDataCounties( $this->wpdb, $this->config ); + $countyVals = $countyData->getList( null, 'name' ); + if ( isset( $countyVals ) && is_array( $countyVals ) && !empty( $countyVals ) ) { + foreach ( $countyVals as $county ) { + $counties[$county['id']] = $county['name']; + } } // populate category dropdown $categories = new GlmDataEventsCategories( $this->wpdb, $this->config ); @@ -353,6 +358,7 @@ class GLmMembersFront_events_frontAdd extends GlmDataEvents $place = $this->filterInput( $_REQUEST['place'] ); $address = $this->filterInput( $_REQUEST['address'] ); $city = $this->filterInput( $_REQUEST['city'] ); + $county = $this->filterInput( $_REQUEST['county'] ); $state = $this->filterInput( $_REQUEST['state'] ); $zip = $this->filterInput( $_REQUEST['zip'] ); $contactEmail = $this->filterInput( $_REQUEST['contact_email'] ); @@ -531,29 +537,31 @@ class GLmMembersFront_events_frontAdd extends GlmDataEvents 'name' => $place, 'address' => $address, 'city' => $city, + 'county' => $county, 'state' => $state, 'zip' => $zip, 'phone' => $contactPhone, 'contact_fname' => $contactFirst, 'contact_lname' => $contactLast, - 'email' => $contactEmail + 'email' => $contactEmail, ); $locationDataFormat = array( - '%d', - '%s', - '%s', - '%d', - '%s', - '%s', - '%s', - '%s', - '%s', - '%s' + '%d', // eventID + '%s', // place + '%s', // address + '%d', // city + '%d', // county + '%s', // state + '%s', // zip + '%s', // contactPhone + '%s', // contactFirst + '%s', // contactLast + '%s', // contactEmail ); if ( isset( $lat ) && isset( $lon ) && $lat && $lon) { - $locationData['lat'] = $lat; - $locationData['lon'] = $lon; + $locationData['lat'] = $lat; + $locationData['lon'] = $lon; $locationDataFormat[] = '%s'; $locationDataFormat[] = '%s'; } @@ -739,6 +747,7 @@ class GLmMembersFront_events_frontAdd extends GlmDataEvents 'confirmation_page' => $redirect_url, 'mainImgUrl' => GLM_MEMBERS_PLUGIN_MEDIA_URL . '/images/large/', 'cities' => $cities, + 'counties' => $counties, ); //error_reporting(E_ALL ^ E_NOTICE); diff --git a/views/admin/events/editLocation.html b/views/admin/events/editLocation.html index f2dede9..0ac0930 100755 --- a/views/admin/events/editLocation.html +++ b/views/admin/events/editLocation.html @@ -117,6 +117,21 @@ + {if $settings.enable_counties} + + County: + + + + + {/if} State: @@ -136,19 +151,6 @@ - - County: - - - - Country: @@ -280,6 +282,19 @@ + {if $settings.enable_counties} + + County: + + + + + {/if} State: @@ -298,17 +313,6 @@ - - County: - - - - Country: diff --git a/views/admin/management/events.html b/views/admin/management/events.html index c7cdbc6..167d16f 100644 --- a/views/admin/management/events.html +++ b/views/admin/management/events.html @@ -116,7 +116,11 @@





-

+

diff --git a/views/front/events/frontAdd.html b/views/front/events/frontAdd.html index bacd2f3..3fa0322 100644 --- a/views/front/events/frontAdd.html +++ b/views/front/events/frontAdd.html @@ -336,9 +336,22 @@
+
+ +
+
+ +
+
+
@@ -352,8 +365,8 @@ -- 2.17.1