Skip to:
Content

BuddyPress.org

Changeset 3381


Ignore:
Timestamp:
11/09/2010 12:59:25 PM (16 years ago)
Author:
boonebgorges
Message:

Adds several exclude parameters to bp_has_profile(). Fixes #2655

Location:
trunk/bp-xprofile
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/bp-xprofile/bp-xprofile-classes.php

    r3369 r3381  
    8080        /** Static Functions **/
    8181
     82        /**
     83         * get()
     84         *
     85         * Populates the BP_XProfile_Group object with profile field groups, fields, and field data
     86         *
     87         * @package BuddyPress XProfile
     88         *
     89         * @global $wpdb WordPress DB access object.
     90         * @global $bp The global BuddyPress settings variable created in bp_core_setup_globals()
     91         *
     92         * @param array $args Takes an array of parameters:
     93         *              'profile_group_id' - Limit results to a single profile group
     94         *              'user_id' - Required if you want to load a specific user's data
     95         *              'hide_empty_groups' - Hide groups without any fields
     96         *              'fetch_fields' - Load each group's fields
     97         *              'fetch_field_data' - Load each field's data. Requires a user_id
     98         *              'exclude_groups' - Comma-separated list of groups to exclude
     99         *              'exclude_fields' - Comma-separated list of fields to exclude
     100         *
     101         * @return array $groups
     102         */
    82103        function get( $args = '' ) {
    83104                global $wpdb, $bp;
    84105
    85106                $defaults = array(
    86                         'profile_group_id' => false,
    87                         'user_id' => $bp->displayed_user->id,
     107                        'profile_group_id'      => false,
     108                        'user_id'                       => $bp->displayed_user->id,
    88109                        'hide_empty_groups' => false,
    89                         'fetch_fields' => false,
    90                         'fetch_field_data' => false
     110                        'fetch_fields'          => false,
     111                        'fetch_field_data'      => false,
     112                        'exclude_groups'        => false,
     113                        'exclude_fields'        => false
    91114                );
    92115
    … …  
    96119                $group_id_sql = '';
    97120                if ( $profile_group_id )
    98                         $group_id_sql = $wpdb->prepare( 'WHERE g.id = %d', $profile_group_id );
     121                        $where_sql = $wpdb->prepare( 'WHERE g.id = %d', $profile_group_id );
     122                else if ( $exclude_groups )
     123                        $where_sql = $wpdb->prepare( "WHERE g.id NOT IN ({$exclude_groups})");
    99124
    100125                if ( $hide_empty_groups )
    101                         $groups = $wpdb->get_results( $wpdb->prepare( "SELECT DISTINCT g.* FROM {$bp->profile->table_name_groups} g INNER JOIN {$bp->profile->table_name_fields} f ON g.id = f.group_id {$group_id_sql} ORDER BY g.group_order ASC" ) );
     126                        $groups = $wpdb->get_results( $wpdb->prepare( "SELECT DISTINCT g.* FROM {$bp->profile->table_name_groups} g INNER JOIN {$bp->profile->table_name_fields} f ON g.id = f.group_id {$where_sql} ORDER BY g.group_order ASC" ) );
    102127                else
    103                         $groups = $wpdb->get_results( $wpdb->prepare( "SELECT DISTINCT g.* FROM {$bp->profile->table_name_groups} g {$group_id_sql} ORDER BY g.group_order ASC" ) );
     128                        $groups = $wpdb->get_results( $wpdb->prepare( "SELECT DISTINCT g.* FROM {$bp->profile->table_name_groups} g {$where_sql} ORDER BY g.group_order ASC" ) );
    104129
    105130                if ( !$fetch_fields )
    106131                        return $groups;
    107132
    108                 /* Get the group ids */
     133                // Get the group ids
    109134                foreach( (array)$groups as $group ) {
    110135                        $group_ids[] = $group->id;
    … …  
    116141                        return $groups;
    117142
    118                 /* Fetch the fields */
    119                 $fields = $wpdb->get_results( $wpdb->prepare( "SELECT id, name, description, type, group_id, is_required FROM {$bp->profile->table_name_fields} WHERE group_id IN ( {$group_ids} ) AND parent_id = 0 ORDER BY field_order" ) );
     143                if ( $exclude_fields )
     144                        $exclude_fields_sql = $wpdb->prepare( "AND id NOT IN ({$exclude_fields})" );
     145
     146                // Fetch the fields
     147                $fields = $wpdb->get_results( $wpdb->prepare( "SELECT id, name, description, type, group_id, is_required FROM {$bp->profile->table_name_fields} WHERE group_id IN ( {$group_ids} ) AND parent_id = 0 {$exclude_fields_sql} ORDER BY field_order" ) );
    120148
    121149                if ( empty( $fields ) )
    … …  
    123151
    124152                if ( $fetch_field_data ) {
    125                         /* Fetch the field data for the user. */
     153                        // Fetch the field data for the user.
    126154                        foreach( (array)$fields as $field )
    127155                                $field_ids[] = $field->id;
    … …  
    142170                }
    143171
    144                 /* Merge the field array back in with the group array */
     172                // Merge the field array back in with the group array
    145173                foreach( (array)$groups as $group_key => $group ) {
    146174                        foreach( (array)$fields as $field ) {
  • trunk/bp-xprofile/bp-xprofile-templatetags.php

    r3377 r3381  
    1818        var $user_id;
    1919
    20         function bp_xprofile_data_template( $user_id, $profile_group_id ) {
     20        function bp_xprofile_data_template( $user_id, $profile_group_id, $hide_empty_groups = false, $fetch_fields = false, $fetch_field_data = false, $exclude_groups = false, $exclude_fields = false ) {
    2121                $this->groups = BP_XProfile_Group::get( array(
    22                         'profile_group_id' => $profile_group_id,
    23                         'user_id' => $user_id,
    24                         'hide_empty_groups' => true,
    25                         'fetch_fields' => true,
    26                         'fetch_field_data' => true
     22                        'profile_group_id'      => $profile_group_id,
     23                        'user_id'                       => $user_id,
     24                        'hide_empty_groups' => $hide_empty_groups,
     25                        'fetch_fields'          => $fetch_fields,
     26                        'fetch_field_data'      => $fetch_field_data,
     27                        'exclude_groups'        => $exclude_groups,
     28                        'exclude_fields'        => $exclude_fields
    2729                ) );
    2830
    … …  
    145147        $defaults = array(
    146148                'user_id' => $bp->displayed_user->id,
    147                 'profile_group_id' => false
     149                'profile_group_id' => false,
     150                'hide_empty_groups'     => true,
     151                'fetch_fields'          => true,
     152                'fetch_field_data'      => true,
     153                'exclude_groups' => false, // Comma-separated list of profile field group IDs to exclude
     154                'exclude_fields' => false // Comma-separated list of profile field IDs to exclude
    148155        );
    149156
    … …  
    151158        extract( $r, EXTR_SKIP );
    152159
    153         $profile_template = new BP_XProfile_Data_Template( $user_id, $profile_group_id );
     160        $profile_template = new BP_XProfile_Data_Template( $user_id, $profile_group_id, $hide_empty_groups, $fetch_fields, $fetch_field_data, $exclude_groups, $exclude_fields );
    154161        return apply_filters( 'bp_has_profile', $profile_template->has_groups(), &$profile_template );
    155162}
Note: See TracChangeset for help on using the changeset viewer.