Added Regions to member list filters and have that limiting categories to those with...
authorChuck Scott <cscott@gaslightmedia.com>
Tue, 25 Oct 2016 20:13:02 +0000 (16:13 -0400)
committerChuck Scott <cscott@gaslightmedia.com>
Tue, 25 Oct 2016 20:13:02 +0000 (16:13 -0400)
Added to getListSortedParentChild() in dataCategories to also filter by region selected
  Also not returning parents of categories with matching active members.
Added getListForSearch() to dataRegions to be able to select by active members.
Added code to members/list.php to handle regiona search and filtering of categories when regions are selected.
Updated update_database_V1.1.22 to change region filter default to false.
Updated members/list.html to include region pick-list.

classes/data/dataCategories.php
classes/data/dataRegions.php
models/front/members/list.php
setup/databaseScripts/update_database_V1.1.22.sql
views/front/members/list.html

index 9240b6f..93e2400 100644 (file)
@@ -309,30 +309,58 @@ class GlmDataCategories extends GlmDataAbstract
      * @access public
      */
 
-    public function getListSortedParentChild($forEdit = true, $forActiveMembers = false) {
+    public function getListSortedParentChild($forEdit = true, $forActiveMembers = false, $regionList = false) {
 
-        $where = '';
+        $regionWhere = '';
+        if ($regionList !== false && trim($regionList) != '') {
+            $regionWhere = " AND MI.region in ($regionList)";
+        }
 
-        // If we only want categories for active and visible members
+        // If we only want categories for active and visible members - and we want any of their parents (i know it's messy)
         if ($forActiveMembers) {
-            $where = "T.id in (
-                SELECT DISTINCT(CMI.category)
-                  FROM ".GLM_MEMBERS_PLUGIN_DB_PREFIX."category_member_info CMI,
-                       ".GLM_MEMBERS_PLUGIN_DB_PREFIX."member_info MI,
-                       ".GLM_MEMBERS_PLUGIN_DB_PREFIX."members M
-                 WHERE MI.id = CMI.member_info
-                   AND 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']."
-                       )
+            $where = "
+                (
+                    T.id in (
+                        SELECT DISTINCT(C.parent)
+                            from glm_glm_members_categories C
+                         WHERE C.id in (
+                            SELECT DISTINCT(CMI.category)
+                              FROM ".GLM_MEMBERS_PLUGIN_DB_PREFIX."category_member_info CMI,
+                                   ".GLM_MEMBERS_PLUGIN_DB_PREFIX."member_info MI,
+                                   ".GLM_MEMBERS_PLUGIN_DB_PREFIX."members M
+                             WHERE MI.id = CMI.member_info
+                               AND MI.status = 10
+                               AND M.id = MI.member
+                                   $regionWhere
+                               AND M.access IN (
+                                    ".$this->config['access_numb']['NoAccess'].",
+                                    ".$this->config['access_numb']['Moderated'].",
+                                    ".$this->config['access_numb']['Full']."
+                                  )
+                         )
+                    )
+                OR
+                   T.id in (
+                       SELECT  DISTINCT(CMI.category)
+                         FROM ".GLM_MEMBERS_PLUGIN_DB_PREFIX."category_member_info CMI,
+                              ".GLM_MEMBERS_PLUGIN_DB_PREFIX."member_info MI,
+                              ".GLM_MEMBERS_PLUGIN_DB_PREFIX."members M
+                        WHERE MI.id = CMI.member_info
+                          AND MI.status = 10
+                          AND M.id = MI.member
+                              $regionWhere
+                          AND M.access IN (
+                                ".$this->config['access_numb']['NoAccess'].",
+                                ".$this->config['access_numb']['Moderated'].",
+                                ".$this->config['access_numb']['Full']."
+                              )
+                     )
+
                 )
             ";
         }
 
-        // Get a list of all categories
+        // Get a list of all categories (optionally for active members only)
         $categories = $this->getList($where);
         $categoriesSorted = $this->sortParentChild($categories);
 
index 7d79840..6aeb627 100644 (file)
@@ -146,6 +146,46 @@ class GlmDataRegions extends GlmDataAbstract
         }
 
     }
+
+
+    /**
+     * Get regions list sorted by alpha
+     *
+     * @param boolean $forActiveMembers Return only regions that are referenced in active members
+     *
+     * @return array Array of categories
+     * @access public
+     */
+
+    public function getListForSearch($forActiveMembers = false) {
+
+        $where = '';
+
+        // If we only want regions for active and visible members
+        if ($forActiveMembers) {
+            $where = "T.id in (
+                SELECT DISTINCT(MI.region)
+                  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 regions (optionally for active members only)
+        $regions = $this->getList($where);
+
+        return $regions;
+
+    }
+
+
 }
 
 ?>
\ No newline at end of file
index b086fb3..3ca934a 100644 (file)
@@ -160,6 +160,7 @@ class GlmMembersFront_members_list extends GlmDataMemberInfo
         $blankStart     = false;
         $membersFound   = false;
         $catSearchSelected = false;
+        $regionSearchSelected = false;
 
         // Check for URL parameter override of shortcode parameters
         if (isset($_REQUEST['categorySearch'])) {
@@ -174,9 +175,10 @@ class GlmMembersFront_members_list extends GlmDataMemberInfo
         if (isset($_REQUEST['amenitySearch'])) {
             $actionData['request']['amenity-search'] = $_REQUEST['amenitySearch'];
         }
-        if (isset($_REQUEST['regionSearch'])) {
+/*        if (isset($_REQUEST['regionSearch'])) {
             $actionData['request']['region-search'] = $_REQUEST['regionSearch'];
         }
+*/
 
         // Check for "show" shortcode parameter (what elements to show on the page)
         $settings = array();
@@ -273,10 +275,74 @@ class GlmMembersFront_members_list extends GlmDataMemberInfo
             $textSearch = stripslashes($textSearch);
         }
 
-        // Get all category data for possible use in search pick list
+        // 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
+
+        // If we have a region set in shortcode or via URL.
+        $regions = array();
+        if ($actionData['request']['region-search']) {
+
+            // Convert comma separated list to an array
+            $regionsRequested = explode( ',', $actionData['request']['region-search'] );
+
+            // Check for numeric ID's only
+            while ( list( $k, $v ) = each( $regionsRequested ) ) {
+                if ( preg_match( '/^[0-9]*$/', trim( $v ) && $v > 0 ) ) {
+                    $regions[] = ( $v - 0 );
+                }
+            }
+
+            if ( isset( $regions ) && !empty( $regions ) ) {
+                $where .= $whereSep." T.region IN (" . implode( ',', $regions ) . ")";
+                $whereSep = ' AND ';
+            }
+        }
+
+        // If there's regions shortcode or url options to restrict this page to certain regions
+        if (count($regions) > 0) {
+
+            while ( list($k,$v) = each ($regionData) ) {
+                if (!in_array($v['id'], $regions)) {
+                    unset ($regionData[$k]);
+                }
+            }
+
+        }
+
+        // Check for user region selection
+        $categoryRegionList = '';
+        $categoryRegionSep = '';
+        if (isset($_REQUEST) && (isset($_REQUEST['regionUserSearch']) && count($_REQUEST['regionUserSearch']) > 0) || (isset($_REQUEST['regionSearch']) && $_REQUEST['regionSearch'] != "")) {
+            foreach ($regionData as $r) {
+                $id = $r['id'];
+                $regionData[$id]['default'] = false;
+                if ( (isset($_REQUEST['regionUserSearch']) && in_array($id, $_REQUEST['regionUserSearch'])) || (isset($_REQUEST['regionSearch']) && $id == $_REQUEST['regionSearch']) ) {
+                    $regionData[$id]['default'] = true;
+                    $regionSearchSelected = $id;
+                    $where .= $whereSep." T.region = $id";
+                    $whereSep = ' AND ';
+                    $categoryRegionList .= $categoryRegionSep."$id";
+                    $categoryRegionSep = ', ';
+                }
+            }
+        } else {
+             reset($regionData);
+             foreach ($regionData as $r) {
+                $id = $r['id'];
+                $regionData[$id]['default'] = false;
+                if (in_array($id, $regions)) {
+                    $categoryRegionList .= $categoryRegionSep."$id";
+                    $categoryRegionSep = ', ';
+                }
+            }
+        }
+
+        // Get category data for possible use in search pick list for categories used in active member info records.
         require_once GLM_MEMBERS_PLUGIN_CLASS_PATH.'/data/dataCategories.php';
         $Categories = new GlmDataCategories($this->wpdb, $this->config);
-        $categoryData = $Categories->getListSortedParentChild(false, true);             // Get only categories that are used in active member data
+        $categoryData = $Categories->getListSortedParentChild(false, true, $categoryRegionList);             // Get only categories that are used in active member data
 
         // Get any numeric categories selected in the submitted shortcode and add to $cats array.
         // This sets categories that are available for selection by the user
@@ -404,25 +470,6 @@ class GlmMembersFront_members_list extends GlmDataMemberInfo
 
         }
 
-        // If we have a region
-        if ($actionData['request']['region-search']) {
-            $regions = array();
-            // Convert comma separated list to an array
-            $regionsRequested = explode( ',', $actionData['request']['region-search'] );
-
-            // Check for numeric ID's only
-            while ( list( $k, $v ) = each( $regionsRequested ) ) {
-                if ( preg_match( '/^[0-9]*$/', trim( $v ) && $v > 0 ) ) {
-                    $regions[] = ( $v - 0 );
-                }
-            }
-
-            if ( isset( $regions ) && !empty( $regions ) ) {
-                $where .= $whereSep." T.region IN (" . implode( ',', $regions ) . ")";
-                $whereSep = ' AND ';
-            }
-        }
-
         // Get amenity filter data
         $amenityData = false;
         $amenSelected = '';
@@ -492,7 +539,7 @@ class GlmMembersFront_members_list extends GlmDataMemberInfo
 
                 } // If we have a sane amenity ID
             } // If an amenity search has been selected
-        } // it doing amenity search
+        } // if doing amenity search
         $amenityData = ( is_array( $amenityData ) ) ? array_filter( $amenityData ) : array();
 
         // Only look at active member information where the member is displayable  (access = 20, 30, 40)
@@ -608,6 +655,8 @@ class GlmMembersFront_members_list extends GlmDataMemberInfo
             'singleCategory'    => $singleCategory,
             'catSelected'       => $catSelected,
             'catSearchSelected' => $catSearchSelected,
+            'regions'           => $regionData,
+            'regionSearchSelected' => $regionSearchSelected,
             'amenities'         => $amenityData,
             'amenSelected'      => $amenSelected,
             'alphaList'         => $alphaList,
index da6350e..497ec18 100644 (file)
@@ -11,7 +11,7 @@ ALTER TABLE {prefix}settings_general ADD COLUMN list_show_search_region BOOLEAN
 
 ----
 
-UPDATE {prefix}settings_general SET list_show_search_region = true;
+UPDATE {prefix}settings_general SET list_show_search_region = false;
 
 ----
 
index d6614b1..fb191d8 100644 (file)
                             </div>
                             {/if}
                         {/if}
+                        {if $settings.list_show_search_region}
+                            {if $regions|@count gt 0}
+                            <div>
+                                By Regions:
+                                <select name="regionUserSearch[]">
+                                    {if $regions|@count gt 1}
+                                        <option value"">(all)</option>
+                                    {/if}
+                                    {foreach from=$regions item=v}
+                                        <option value="{$v.id}" {if $v.default} selected="selected"{/if}>
+                                            {$v.name}
+                                        </option>
+                                    {/foreach}
+                                </select>
+                            </div>
+                            {/if}
+                        {/if}
 
                         {if $settings.list_show_search_text}
                             <div>
     <div class="glm-member-list-listing-container">
     {if $settings.list_show_search_alpha}
         <div class="glm-alpha-links">
-            <a href="{$thisUrl}?glm_action=list&textSearch={$textSearch}&categorySearch={$catSearchSelected}" class="glm-alpha-link{if !$alphaSelected} glm-alpha-link-selected{/if}">All</a>
+            <a href="{$thisUrl}?glm_action=list&textSearch={$textSearch}&categorySearch={$catSearchSelected}&regionSearch={$regionSearchSelected}" class="glm-alpha-link{if !$alphaSelected} glm-alpha-link-selected{/if}">All</a>
       {foreach $alphaList as $a}
-            <a href="{$thisUrl}?glm_action=list&alpha={$a.alpha}&textSearch={$textSearch}&categorySearch={$catSearchSelected}" class="glm-alpha-link{if $a.default} glm-alpha-link-selected{/if}">{$a.alpha}</a>
+            <a href="{$thisUrl}?glm_action=list&alpha={$a.alpha}&textSearch={$textSearch}&categorySearch={$catSearchSelected}&regionSearch={$regionSearchSelected}" class="glm-alpha-link{if $a.default} glm-alpha-link-selected{/if}">{$a.alpha}</a>
       {/foreach}
        </div>
     {/if}