Now only member categories that are used by active member data are listed in the...
authorChuck Scott <cscott@gaslightmedia.com>
Fri, 21 Oct 2016 19:51:59 +0000 (15:51 -0400)
committerChuck Scott <cscott@gaslightmedia.com>
Fri, 21 Oct 2016 19:51:59 +0000 (15:51 -0400)
Added a second parameter, $forActiveMembers,  to getListSortedParentChild() that returns an organized list of member categories.
Added a "WHERE" clause that is used to select categories when $forActiveMembers is true that limit the category list to those used in active members info records.
Added "true" as the $forActiveMembers parameter in the members "list.php" where getListSortedParentChild() is used to get categories for the filter picklist.

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

index 8db004d..5967b08 100644 (file)
@@ -302,15 +302,38 @@ class GlmDataCategories extends GlmDataAbstract
     /**
      * Get categories list sorted by parent/child then alpha
      *
-     * @return array Array of categories
      * @param boolean $forEdit If true include list of options for each parent field
+     * @param boolean $forActiveMembers Return only categories that are referenced in active members
      *
+     * @return array Array of categories
      * @access public
      */
 
-    public function getListSortedParentChild($forEdit = true) {
+    public function getListSortedParentChild($forEdit = true, $forActiveMembers = false) {
+
+        $where = '';
+
+        // If we only want categories for active and visible members
+        if ($forActiveMembers) {
+            $where = "T.id in (
+                SELECT DISTINCT(CMI.category)
+                  FROM glm_glm_members_category_member_info CMI,
+                       glm_glm_members_member_info MI,
+                       glm_glm_members_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']."
+                       )
+                )
+            ";
+        }
 
-        $categories = $this->getList();
+        // Get a list of all categories
+        $categories = $this->getList($where);
         $categoriesSorted = $this->sortParentChild($categories);
 
         if (!$forEdit && is_array($categoriesSorted)) {
index 4324d7e..b086fb3 100644 (file)
@@ -273,10 +273,10 @@ class GlmMembersFront_members_list extends GlmDataMemberInfo
             $textSearch = stripslashes($textSearch);
         }
 
-        // Get all category data for possible user in search pick list
+        // Get all category data for possible use in search pick list
         require_once GLM_MEMBERS_PLUGIN_CLASS_PATH.'/data/dataCategories.php';
         $Categories = new GlmDataCategories($this->wpdb, $this->config);
-        $categoryData = $Categories->getListSortedParentChild(false);
+        $categoryData = $Categories->getListSortedParentChild(false, true);             // 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