Bring in functionality for city zoom
authorSteve Sutton <steve@gaslightmedia.com>
Tue, 6 Nov 2018 20:41:52 +0000 (15:41 -0500)
committerSteve Sutton <steve@gaslightmedia.com>
Tue, 6 Nov 2018 20:42:59 +0000 (15:42 -0500)
Will need work on main plugin to add counties into the cities table.

js/leaflet-area-map.js
models/admin/ajax/citiesMapData.php [new file with mode: 0644]
models/admin/ajax/countiesMapData.php [new file with mode: 0644]
models/front/members/interactivemap.php
setup/shortcodes.php
setup/validActions.php
views/front/members/interactivemap.html

index f3f503e..94d12d9 100644 (file)
@@ -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 (file)
index 0000000..eef1892
--- /dev/null
@@ -0,0 +1,107 @@
+<?php
+
+/**
+ * Gaslight Media Members Database
+ * File Library - File Delete
+ *
+ * PHP version 5.5
+ *
+ * @category glmWordPressPlugin
+ * @package  glmMembersDatabase
+ * @author   Chuck Scott <cscott@gaslightmedia.com>
+ * @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 (file)
index 0000000..8733351
--- /dev/null
@@ -0,0 +1,107 @@
+<?php
+
+/**
+ * Gaslight Media Members Database
+ * File Library - File Delete
+ *
+ * PHP version 5.5
+ *
+ * @category glmWordPressPlugin
+ * @package  glmMembersDatabase
+ * @author   Chuck Scott <cscott@gaslightmedia.com>
+ * @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;
+
+    }
+
+}
index 6452954..36ff470 100644 (file)
@@ -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 '<pre>$categories: ' . print_r( $this->getMemberCategories(), true ) . '</pre>';
 
@@ -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
+        );
     }
 
 
index bc917a0..ac97f40 100644 (file)
@@ -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,
             ),
         ),
     );
index 6d92f87..c39e79d 100644 (file)
@@ -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',
index 5d71f28..29054e2 100644 (file)
@@ -1,3 +1,11 @@
+<script>
+    glm_ajax_url = '{$ajaxUrl}';
+    glm_memberCats = [
+        {foreach $categories as $catId => $cat}
+            {$catId}{if !$cat@last},{/if}
+        {/foreach}
+    ];
+</script>
 {literal}
 <style>
     #category {display: none;}
@@ -431,21 +439,21 @@ div#memberLocations {
                <div id="mapCounties">
                        <b>Counties:</b>
                        <ul>
-                {* foreach regions region *}
+                {foreach $counties as $county}
                                <li class="mapCounty">
-                                       <a href="#" rel="{* region[region_id] *}">{* region[region_name] *}</a>
+                    <a href="#" data-id="{$county.id}">{$county.name}</a>
                                </li>
-                {* /foreach *}
+                {/foreach}
                        </ul>
-               </div><!-- /#mapCounties -->
+               </div>
                <div id="mapCities">
                        <b>Cities:</b>
                        <ul>
-                {* foreach cities city *}
+                {foreach $cities as $city}
                                <li class="mapCity">
-                                       <a href="#" rel="{* city[city_id] *}">{* city[city_name] *}</a>
+                                       <a href="#" data-id="{$city.id}">{$city.name}</a>
                                </li>
-                {* /foreach *}
+                {/foreach}
                        </ul>
                </div>
        </div>
@@ -454,16 +462,4 @@ div#memberLocations {
 
 </div>
 
-</div><!-- /#mapwrap -->
-<script>
-    glm_ajax_url = '{$ajaxUrl}';
-    glm_memberCats = [
-        793, // Places to Stay
-        791, // Attractions
-        794, // Recreation
-        792, // Dining
-        796, // Shopping
-        795, // Services
-        797 // Transportation
-    ];
-</script>
+