adding city search function to the dataCities class and the front list model
authorAnthony Talarico <talarico@gaslightmedia.com>
Thu, 25 Jan 2018 15:47:43 +0000 (10:47 -0500)
committerAnthony Talarico <talarico@gaslightmedia.com>
Thu, 25 Jan 2018 15:47:43 +0000 (10:47 -0500)
reflecting the region search functionality with the cities to add city search to our
front end member filter

classes/data/dataCities.php
models/front/members/list.php

index 8bf0ee5..846b289 100644 (file)
@@ -175,6 +175,42 @@ class GlmDataCities extends GlmDataAbstract
         return $id;
 
     }
+    /**
+     * Get cities list sorted by alpha
+     *
+     * @param boolean $forActiveMembers Return only cities that are referenced in active members
+     *
+     * @return array Array of categories
+     * @access public
+     */
+
+    public function getListForSearch($forActiveMembers = false) {
+
+        $where = '';
+
+        // If we only want cities for active and visible members
+        if ($forActiveMembers) {
+            $where = "T.id in (
+                SELECT DISTINCT(MI.city)
+                  FROM ".GLM_MEMBERS_PLUGIN_DB_PREFIX."member_info MI,
+                       ".GLM_MEMBERS_PLUGIN_DB_PREFIX."members M
+                 WHERE MI.status = ".$this->config['status_numb']['Active']."
+                   AND M.id = MI.member
+                   AND M.access IN (
+                          ".$this->config['access_numb']['NoAccess'].",
+                          ".$this->config['access_numb']['Moderated'].",
+                          ".$this->config['access_numb']['Full']."
+                       )
+                )
+            ";
+        }
+
+        // Get a list of all cities (optionally for active members only)
+        $cities = $this->getList($where);
+
+        return $cities;
+
+    }
 }
 
 ?>
\ No newline at end of file
index 51b6e15..bc589f6 100644 (file)
@@ -158,6 +158,7 @@ class GlmMembersFront_members_list extends GlmDataMemberInfo
         $haveFilter           = false;
         $textSearch           = '';
         $blankStart           = false;
+        $citySearchSelect     = false;
         $membersFound         = false;
         $catSearchSelected    = false;
         $regionSearchSelected = false;
@@ -292,8 +293,14 @@ class GlmMembersFront_members_list extends GlmDataMemberInfo
         // Get regions for possible use in search pick list for regions used in active member info records.
         require_once GLM_MEMBERS_PLUGIN_CLASS_PATH.'/data/dataRegions.php';
         $Regions = new GlmDataRegions($this->wpdb, $this->config);
-        $regionData = $Regions->getListForSearch(true);             // Get only categories that are used in active member data
-
+        $regionData = $Regions->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);
+        $cityData = $cities->getListForSearch(true);      // Get only categories that are used in active member data
+        
         // If we have a region set in shortcode or via URL.
         $regions = array();
         if ($actionData['request']['region-search']) {
@@ -324,7 +331,36 @@ class GlmMembersFront_members_list extends GlmDataMemberInfo
             }
 
         }
+        
+        // If we have a city set in shortcode or via URL.
+        $cities = array();
+        if ($actionData['request']['city-search']) {
+
+            // Convert comma separated list to an array
+            $citiesRequested = explode( ',', $actionData['request']['city-search'] );
+
+            // Check for numeric ID's only
+            while ( list( $k, $v ) = each( $citiesRequested ) ) {
+                if ( preg_match( '/^[0-9]*$/', trim( $v ) && $v > 0 ) ) {
+                    $cities[] = ( $v - 0 );
+                }
+            }
+
+            if ( isset( $cities ) && !empty( $cities ) ) {
+                $where .= $whereSep." T.city IN (" . implode( ',', $cities ) . ")";
+                $whereSep = ' AND ';
+            }
+        }
+
+        // If there's city's shortcode or url options to restrict this page to certain cities
+        if (count($cities) > 0) {
 
+            while ( list($k,$v) = each ($cityData) ) {
+                if (!in_array($v['id'], $cities)) {
+                    unset ($cityData[$k]);
+                }
+            }
+        }
         // Check for user region selection
         $categoryRegionList = '';
         $categoryRegionSep = '';
@@ -355,7 +391,37 @@ class GlmMembersFront_members_list extends GlmDataMemberInfo
                 }
             }
         }
-
+        
+        // Check for user city selection
+        $categoryCityList = '';
+        $categoryCitySep = '';
+        if (isset($_REQUEST) && is_array($cityData) && (isset($_REQUEST['cityUserSearch']) && count($_REQUEST['cityUserSearch']) > 0) || (isset($_REQUEST['citySearch']) && $_REQUEST['citySearch'] != "")) {
+            foreach ($cityData as $r) {
+                $id = $r['id'];
+                $cityData[$id]['default'] = false;
+                if ( (isset($_REQUEST['cityUserSearch']) && in_array($id, $_REQUEST['cityUserSearch'])) || (isset($_REQUEST['citySearch']) && $id == $_REQUEST['citySearch']) ) {
+                    $cityData[$id]['default'] = true;
+                    $citySearchSelected = $id;
+                    $where .= $whereSep." T.city = $id";
+                    $whereSep = ' AND ';
+                    $categoryCityList .= $categoryCitySep."$id";
+                    $categoryCitySep = ', ';
+                }
+            }
+        } else {
+            // Double check that we have an array from $regionData
+            if ( isset( $cityData ) && is_array( $cityData ) ) {
+                reset($cityData);
+                foreach ($cityData as $r) {
+                    $id = $r['id'];
+                    $cityData[$id]['default'] = false;
+                    if (in_array($id, $cities)) {
+                        $categoryCityList .= $categoryCitySep."$id";
+                        $categoryCitySep = ', ';
+                    }
+                }
+            }
+        }
         // Get any numeric member types selected in the submitted shortcode and add to $types array.
         // We are currently only doing type selection by ID in the shortcode. No search parameters.
         $typesSelected = '';
@@ -792,6 +858,8 @@ class GlmMembersFront_members_list extends GlmDataMemberInfo
             'singleCategory'    => $singleCategory,
             'catSelected'       => $catSelected,
             'catSearchSelected' => $catSearchSelected,
+            'cities'            =>$cityData,
+            'citySearchSelected' => $citySearchSelected,
             'regions'           => $regionData,
             'regionSearchSelected' => $regionSearchSelected,
             'amenities'         => $amenityData,