/**
* 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)) {
$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