From a2ba65846a0ce2c5b91643cb50a10d81f526d582 Mon Sep 17 00:00:00 2001 From: Anthony Talarico Date: Wed, 26 Apr 2017 09:36:56 -0400 Subject: [PATCH] adding fronthooks filter to get active member info data added filter to retrieve categories and other member info fields based on a provided argument to get only the fields that are part of active member profiles. adding separate where clauses based on whether or not the field is a category, which can accept a parent or if it is a column from the member info table --- setup/frontHooks.php | 63 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) diff --git a/setup/frontHooks.php b/setup/frontHooks.php index 928e92c5..7c73c172 100644 --- a/setup/frontHooks.php +++ b/setup/frontHooks.php @@ -369,6 +369,69 @@ function is_member( $id = false ) { } return false; } +/** + * Get search fields list sorted by alpha + * + * @param boolean $forActiveMembers Return only fields that are referenced in active members + * + * @return array Array of categories + * @access public + */ +add_filter('glm_getListForSearch', function( $field,$cat_parent = false, $forActiveMembers = true ){ + + $where = ''; + $member_category = false; + $parent_id = 'null'; + + switch($field){ + case 'city': + $table = 'cities'; + break; + case 'region': + $table = 'regions'; + break; + case 'county': + $table = 'counties'; + break; + case 'category': + $member_category = true; + $table = 'category_member_info'; + break; + default: + break; + } + + if($cat_parent !== false){ + $sql = 'SELECT id FROM '.GLM_MEMBERS_PLUGIN_DB_PREFIX."categories WHERE name = '$cat_parent';"; + $parent_id = $this->wpdb->get_var($sql); + } + // If we only want fields for active and visible members + if ($forActiveMembers && $member_category === false) { + $where = " + SELECT MI.$field, T.name + FROM ".GLM_MEMBERS_PLUGIN_DB_PREFIX."member_info MI, + ".GLM_MEMBERS_PLUGIN_DB_PREFIX."members M, + ".GLM_MEMBERS_PLUGIN_DB_PREFIX."$table T + WHERE MI.status = ".$this->config['status_numb']['Active']." + AND M.id = MI.member AND T.id = MI.$field GROUP BY MI.$field, T.name + "; + } else if($forActiveMembers && $member_category === true){ + $where = " + SELECT T.$field, C.name, C.parent + FROM ".GLM_MEMBERS_PLUGIN_DB_PREFIX."member_info MI, + ".GLM_MEMBERS_PLUGIN_DB_PREFIX."members M, + ".GLM_MEMBERS_PLUGIN_DB_PREFIX."$table T, + ".GLM_MEMBERS_PLUGIN_DB_PREFIX."categories C + WHERE MI.status = ".$this->config['status_numb']['Active']." + AND M.id = MI.member AND T.$field = C.id AND C.parent = '$parent_id' GROUP BY T.$field, C.name + "; + } + // Get a list of all fields (optionally for active members only) + $search_fields = $this->wpdb->get_results($where, ARRAY_A); + + return $search_fields; + +}, 10, 3); // Getting the current admin theme colors as set by Wordpress. // This will be useful for styling our menu when we figure out how best to use -- 2.17.1