From: Steve Sutton Date: Tue, 6 Nov 2018 20:41:52 +0000 (-0500) Subject: Bring in functionality for city zoom X-Git-Tag: v2.11.0^2~62 X-Git-Url: http://cvs2.gaslightmedia.com/gitweb/?a=commitdiff_plain;h=ff0c6a8cf0b92e74a13876948368d939fedb95cd;p=WP-Plugins%2Fglm-member-db.git Bring in functionality for city zoom Will need work on main plugin to add counties into the cities table. --- diff --git a/js/leaflet-area-map.js b/js/leaflet-area-map.js index f3f503e6..94d12d9e 100644 --- a/js/leaflet-area-map.js +++ b/js/leaflet-area-map.js @@ -58,14 +58,33 @@ var GlmMap = { }); jQuery(".mapCity a").click(function (){ GlmMap._hideLocations(); - var params = "?city_id=" + jQuery(this).attr('rel'); - jQuery.get(glm_base_url + "member-city-google-map/" + params, GlmMap._centerCity, 'xml'); + var params = "city_id=" + jQuery(this).data('id'); + + jQuery.ajax({ + url: glm_ajax_url + '?action=glm_members_admin_ajax&glm_action=citiesMapData&' + params, + cache: false, + dataType: 'json', + success: function( mapData ){ + console.log( 'mapData: ', mapData ); + GlmMap._centerCity( mapData ) + } + }); + return false; }); jQuery(".mapCounty a").click(function (){ GlmMap._hideLocations(); - var params = "?region=" + jQuery(this).attr('rel'); - jQuery.get(glm_base_url + "member-city-google-map/" + params, GlmMap._centerCounty, 'xml'); + var params = "county_id=" + jQuery(this).data('id'); + jQuery.ajax({ + url: glm_ajax_url + '?action=glm_members_admin_ajax&glm_action=countiesMapData&' + params, + cache: false, + dataType: 'json', + success: function( mapData ){ + console.log( 'mapData: ', mapData ); + GlmMap._centerCounty( mapData ) + } + }); + return false; }); }, @@ -100,13 +119,11 @@ var GlmMap = { _getCategoryValues: function(){ var values = jQuery("#category-form").serialize(); - // jQuery.get(glm_base_url + 'member-area-google-map/?' + values, GlmMap._loadData, 'xml'); jQuery.ajax({ url: glm_ajax_url + '?action=glm_members_admin_ajax&glm_action=membersMapData&' + values, cache: false, dataType: 'json', success: function( mapData ){ - console.log( 'mapData: ', mapData ); GlmMap._loadData( mapData ) } }); @@ -228,13 +245,12 @@ var GlmMap = { }); }, - _loadCityData: function(data) + _loadCityData: function( markers ) { - var markers = data.documentElement.getElementsByTagName("marker"); for (i = 0; i < markers.length; i++) { - var name = markers[i].getAttribute('city_name'); - var lat = markers[i].getAttribute('lat'); - var lng = markers[i].getAttribute('lng'); + var name = markers[i].name; + var lat = markers[i].lat; + var lng = markers[i].lon; var point = new google.maps.LatLng( parseFloat(lat), @@ -252,26 +268,24 @@ var GlmMap = { }, - _centerCity: function(data) { + _centerCity: function( markers ) { GlmMap.markerAreaGroup.clearLayers(); - var markers = data.documentElement.getElementsByTagName("marker"); for (i = 0; i < markers.length; i++) { - var lat = markers[i].getAttribute('lat'); - var lng = markers[i].getAttribute('lng'); - var leafletMarker = L.marker([lat, lng], { title: name }) + var lat = markers[i].lat; + var lng = markers[i].lon; + var leafletMarker = L.marker([lat, lng]) .addTo(GlmMap.markerAreaGroup); } GlmMap.leafletMap.fitBounds(GlmMap.markerAreaGroup.getBounds()); GlmMap.leafletMap.setZoom(13); }, - _centerCounty: function(data) { + _centerCounty: function( markers ) { GlmMap.markerAreaGroup.clearLayers(); - var markers = data.documentElement.getElementsByTagName("marker"); for (i = 0; i < markers.length; i++) { - var lat = markers[i].getAttribute('lat'); - var lng = markers[i].getAttribute('lng'); - var leafletMarker = L.marker([lat, lng], { title: name }) + var lat = markers[i].lat; + var lng = markers[i].lon; + var leafletMarker = L.marker([lat, lng]) .addTo(GlmMap.markerAreaGroup); } GlmMap.leafletMap.fitBounds(GlmMap.markerAreaGroup.getBounds()); diff --git a/models/admin/ajax/citiesMapData.php b/models/admin/ajax/citiesMapData.php new file mode 100644 index 00000000..eef1892a --- /dev/null +++ b/models/admin/ajax/citiesMapData.php @@ -0,0 +1,107 @@ + + * @license http://www.gaslightmedia.com Gaslightmedia + * @version 0.1 + */ + +// Load Members data abstract +require_once GLM_MEMBERS_PLUGIN_CLASS_PATH.'/data/dataCities.php'; + +/* + * This class performs the work of handling images passed to it via + * an AJAX call that goes through the WorPress AJAX Handler. + * + */ +class GlmMembersAdmin_ajax_citiesMapData extends GlmDataCities +{ + + /** + * WordPress Database Object + * + * @var $wpdb + * @access public + */ + public $wpdb; + /** + * Plugin Configuration Data + * + * @var $config + * @access public + */ + public $config; + + /* + * Constructor + * + * This contructor sets up this model. At this time that only includes + * storing away the WordPress data object. + * + * @return object Class object + * + */ + public function __construct ($wpdb, $config) + { + + // Save WordPress Database object + $this->wpdb = $wpdb; + + // Save plugin configuration object + $this->config = $config; + + // Run constructor for members data class + parent::__construct(false, false); + + } + + /* + * Perform Model Action + * + * This modelAction takes an AJAX image upload and stores the image in the + * media/images directory of the plugin. + * + * This model action does not return, it simply does it's work then calls die(); + * + * @param $_REQUEST['id'] File Library ID + */ + public function modelAction ( $actionData = false ) + { + $cityData = array(); + + trigger_error( print_r( $_REQUEST, true ), E_USER_NOTICE ); + + if ( isset( $_REQUEST['values'] ) ) { + trigger_error( print_r( $_REQUEST['values'], true ), E_USER_NOTICE ); + } + + $city_id = filter_var( $_REQUEST['city_id'], FILTER_VALIDATE_INT ); + + $where = "T.id = $city_id"; + + $cityData = $this->wpdb->get_results( + $this->wpdb->prepare( + "SELECT * + FROM " . GLM_MEMBERS_PLUGIN_DB_PREFIX . "cities + WHERE id = %d", + $city_id + ), + ARRAY_A + ); + + + header( 'Content-type: application/json' ); + echo json_encode( $cityData ); + + exit; + + } + +} diff --git a/models/admin/ajax/countiesMapData.php b/models/admin/ajax/countiesMapData.php new file mode 100644 index 00000000..8733351e --- /dev/null +++ b/models/admin/ajax/countiesMapData.php @@ -0,0 +1,107 @@ + + * @license http://www.gaslightmedia.com Gaslightmedia + * @version 0.1 + */ + +// Load Members data abstract +require_once GLM_MEMBERS_PLUGIN_CLASS_PATH.'/data/dataCounties.php'; + +/* + * This class performs the work of handling images passed to it via + * an AJAX call that goes through the WorPress AJAX Handler. + * + */ +class GlmMembersAdmin_ajax_countiesMapData extends GlmDataCounties +{ + + /** + * WordPress Database Object + * + * @var $wpdb + * @access public + */ + public $wpdb; + /** + * Plugin Configuration Data + * + * @var $config + * @access public + */ + public $config; + + /* + * Constructor + * + * This contructor sets up this model. At this time that only includes + * storing away the WordPress data object. + * + * @return object Class object + * + */ + public function __construct ($wpdb, $config) + { + + // Save WordPress Database object + $this->wpdb = $wpdb; + + // Save plugin configuration object + $this->config = $config; + + // Run constructor for members data class + parent::__construct(false, false); + + } + + /* + * Perform Model Action + * + * This modelAction takes an AJAX image upload and stores the image in the + * media/images directory of the plugin. + * + * This model action does not return, it simply does it's work then calls die(); + * + * @param $_REQUEST['id'] File Library ID + */ + public function modelAction ( $actionData = false ) + { + $countyData = array(); + + trigger_error( print_r( $_REQUEST, true ), E_USER_NOTICE ); + + if ( isset( $_REQUEST['values'] ) ) { + trigger_error( print_r( $_REQUEST['values'], true ), E_USER_NOTICE ); + } + + $county_id = filter_var( $_REQUEST['county_id'], FILTER_VALIDATE_INT ); + + $where = "T.id = $county_id"; + + $countyData = $this->wpdb->get_results( + $this->wpdb->prepare( + "SELECT * + FROM " . GLM_MEMBERS_PLUGIN_DB_PREFIX . "counties + WHERE id = %d", + $county_id + ), + ARRAY_A + ); + + + header( 'Content-type: application/json' ); + echo json_encode( $countyData ); + + exit; + + } + +} diff --git a/models/front/members/interactivemap.php b/models/front/members/interactivemap.php index 6452954b..36ff470b 100644 --- a/models/front/members/interactivemap.php +++ b/models/front/members/interactivemap.php @@ -101,6 +101,18 @@ class GlmMembersFront_members_interactivemap //extends GlmDataMemberInfo { $settings = array(); $success = true; + $mainCats = array(); + + if ( $actionData['request']['main-level-cats'] ) { + // Setup the main level categories for the Map. + $mainCatsRequested = explode( ',', $actionData['request']['main-level-cats'] ); + + foreach ( $mainCatsRequested as $k => $v ) { + if ( preg_match( '%^[0-9]*$%', trim( $v ) && $v > 0 ) ) { + $mainCats[] = ( $v - 0 ); + } + } + } // Need Member Categories (with active members) // Need Cities (with active members) @@ -108,8 +120,10 @@ class GlmMembersFront_members_interactivemap //extends GlmDataMemberInfo $templateData = array( 'jsUrl' => GLM_MEMBERS_PLUGIN_JS_URL, - 'categories' => $this->getMemberCategories(), - + 'categories' => $this->getMemberCategories( $mainCats ), + 'counties' => $this->getCounties(), + 'counties' => $this->getCounties(), + 'cities' => $this->getCities(), ); // echo '
$categories: ' . print_r( $this->getMemberCategories(), true ) . '
'; @@ -120,46 +134,35 @@ class GlmMembersFront_members_interactivemap //extends GlmDataMemberInfo 'modelRedirect' => false, 'view' => "front/members/interactivemap.html", 'data' => $templateData, - 'settings' => $settings + 'settings' => $settings, ); } - public function getMemberCategories() + public function getMemberCategories( $mainCats ) { - $categories = array( - 793 => array( - 'name' => 'Places To Stay', - 'subCats' => $this->getSubCategories( 793 ), - ), - 791 => array( - 'name' => 'Attractions', - 'subCats' => $this->getSubCategories( 791 ), - ), - 794 => array( - 'name' => 'Recreation', - 'subCats' => $this->getSubCategories( 794 ), - ), - 792 => array( - 'name' => 'Dining', - 'subCats' => $this->getSubCategories( 792 ), - ), - 796 => array( - 'name' => 'Shopping', - 'subCats' => $this->getSubCategories( 796 ), - ), - 795 => array( - 'name' => 'Services', - 'subCats' => $this->getSubCategories( 795 ), - ), - 797 => array( - 'name' => 'Transportation', - 'subCats' => $this->getSubCategories( 797 ), - ), - ); + $categories = array(); + foreach ( $mainCats as $cat ) { + $categories[$cat] = array( + 'name' => $this->getCategoryName( $cat ), + 'subCats' => $this->getSubCategories( $cat ) + ); + } return $categories; } + public function getCategoryName( $id ) + { + return $this->wpdb->get_var( + $this->wpdb->prepare( + "SELECT name + FROM " . GLM_MEMBERS_PLUGIN_DB_PREFIX . "categories + WHERE id = %d", + $id + ) + ); + } + public function getSubCategories( $id ) { $categories = array(); @@ -174,12 +177,22 @@ class GlmMembersFront_members_interactivemap //extends GlmDataMemberInfo return $categories; } - public function getRegions() + public function getCounties() { + return $this->wpdb->get_results( + "SELECT * + FROM " . GLM_MEMBERS_PLUGIN_DB_PREFIX . "counties", + ARRAY_A + ); } public function getCities() { + return $this->wpdb->get_results( + "SELECT * + FROM " . GLM_MEMBERS_PLUGIN_DB_PREFIX . "cities", + ARRAY_A + ); } diff --git a/setup/shortcodes.php b/setup/shortcodes.php index bc917a05..ac97f401 100644 --- a/setup/shortcodes.php +++ b/setup/shortcodes.php @@ -206,7 +206,8 @@ if ( isset( $config['settings'] ) && $config['settings']['enable_members'] ) { 'action' => 'interactivemap', 'table' => false, 'attributes' => array( - 'client' => 'uptra', + 'client' => 'uptra', + 'main-level-cats' => false, ), ), ); diff --git a/setup/validActions.php b/setup/validActions.php index 6d92f879..c39e79df 100644 --- a/setup/validActions.php +++ b/setup/validActions.php @@ -46,6 +46,8 @@ $glmMembersValidActions = array( 'fileLibraryUpdate' => 'glm-member-db', 'glmCron' => 'glm-member-db', 'membersMapData' => 'glm-member-db', + 'citiesMapData' => 'glm-member-db', + 'countiesMapData' => 'glm-member-db', ), 'dashboard' => array( 'index' => 'glm-member-db', diff --git a/views/front/members/interactivemap.html b/views/front/members/interactivemap.html index 5d71f289..29054e2e 100644 --- a/views/front/members/interactivemap.html +++ b/views/front/members/interactivemap.html @@ -1,3 +1,11 @@ + {literal}