Skip to:
Content

BuddyPress.org

Ticket #3074: 3074.04.patch

File 3074.04.patch, 7.1 KB (added by johnjamesjacoby, 14 years ago)

Attached patch fixes issue with querying empty fields and zebra striping. Also removes a fix on the Profile view for an old issue where the Base XProfile Group couldn't be renamed, where we hid the "Base" title.

  • bp-themes/bp-default/members/single/profile/profile-loop.php

     
    99                        <?php do_action( 'bp_before_profile_field_content' ) ?>
    1010
    1111                        <div class="bp-widget <?php bp_the_profile_group_slug() ?>">
    12                                 <?php if ( 1 != bp_get_the_profile_group_id() ) : ?>
    13                                         <h4><?php bp_the_profile_group_name() ?></h4>
    14                                 <?php endif; ?>
    1512
     13                                <h4><?php bp_the_profile_group_name() ?></h4>
     14
    1615                                <table class="profile-fields">
     16
    1717                                        <?php while ( bp_profile_fields() ) : bp_the_profile_field(); ?>
    1818
    1919                                                <?php if ( bp_field_has_data() ) : ?>
     
    3333                                                <?php do_action( 'bp_profile_field_item' ) ?>
    3434
    3535                                        <?php endwhile; ?>
     36
    3637                                </table>
    3738                        </div>
    3839
  • bp-xprofile/bp-xprofile-classes.php

     
    113113                        'profile_group_id'  => false,
    114114                        'user_id'           => $bp->displayed_user->id,
    115115                        'hide_empty_groups' => false,
     116                        'hide_empty_fields' => false,
    116117                        'fetch_fields'      => false,
    117118                        'fetch_field_data'  => false,
    118119                        'exclude_groups'    => false,
     
    157158                        return $groups;
    158159
    159160                if ( $fetch_field_data ) {
     161
    160162                        // Fetch the field data for the user.
    161                         foreach( (array)$fields as $field )
     163                        foreach( (array) $fields as $field ) {
    162164                                $field_ids[] = $field->id;
     165                        }
    163166
    164                         $field_ids = implode( ',', (array) $field_ids );
     167                        // Get field data if fields exist
     168                        if ( !empty( $field_ids ) ) {
    165169
    166                         if ( !empty( $field_ids ) )
    167                                 $field_data = $wpdb->get_results( $wpdb->prepare( "SELECT field_id, value FROM {$bp->profile->table_name_data} WHERE field_id IN ( {$field_ids} ) AND user_id = %d", $user_id ) );
     170                                // Remove data-less fields, if necessary
     171                                $exclude_empty_data = '';
     172                                if ( $hide_empty_fields )
     173                                        $exclude_empty_data = $wpdb->prepare( "AND (value != '' AND value IS NOT NULL)" );
     174                               
     175                                $field_ids_sql = implode( ',', (array) $field_ids );
     176                                $field_data    = $wpdb->get_results( $wpdb->prepare( "SELECT field_id, value FROM {$bp->profile->table_name_data} WHERE field_id IN ( {$field_ids_sql} ) {$exclude_empty_data} AND user_id = %d", $user_id ) );
     177                        }
    168178
    169                         if ( !empty( $field_data ) ) {
    170                                 foreach( (array)$fields as $field_key => $field ) {
    171                                         foreach( (array)$field_data as $data ) {
    172                                                 if ( $field->id == $data->field_id )
     179                        // Field data was found
     180                        if ( !empty( $field_data ) && !is_wp_error( $field_data ) ) {
     181
     182                                // Loop through fields
     183                                foreach( (array) $fields as $field_key => $field ) {
     184                                       
     185                                        // Loop through data in each field
     186                                        foreach( (array) $field_data as $data ) {
     187                                               
     188                                                // Assign correct data value to each field
     189                                                if ( $field->id == $data->field_id ) {
    173190                                                        $fields[$field_key]->data->value = $data->value;
     191                                                }
    174192                                        }
    175193                                }
    176194                        }
    177195                }
    178196
    179197                // Merge the field array back in with the group array
    180                 foreach( (array)$groups as $group_key => $group ) {
    181                         foreach( (array)$fields as $field ) {
    182                                 if ( $group->id == $field->group_id )
     198                foreach( (array) $groups as $group_key => $group ) {
     199                        foreach( (array) $fields as $field ) {
     200                                if ( $group->id == $field->group_id ) {
    183201                                        $groups[$group_key]->fields[] = $field;
     202                                }
    184203                        }
     204                       
     205                        if ( empty( $group->fields ) ) {
     206                                unset( $groups[$group_key] );
     207                        }
     208                       
     209                        // Reset indexes
     210                        $groups = array_values( $groups );
    185211                }
    186212
    187213                return $groups;
  • bp-xprofile/bp-xprofile-template.php

     
    2020        var $in_the_loop;
    2121        var $user_id;
    2222
    23         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 ) {
    24                 $this->__construct( $user_id, $profile_group_id, $hide_empty_groups, $fetch_fields, $fetch_field_data, $exclude_groups, $exclude_fields );
     23        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, $hide_empty_fields = false ) {
     24                $this->__construct( $user_id, $profile_group_id, $hide_empty_groups, $fetch_fields, $fetch_field_data, $exclude_groups, $exclude_fields, $hide_empty_fields );
    2525        }
    2626
    27         function __construct( $user_id, $profile_group_id, $hide_empty_groups = false, $fetch_fields = false, $fetch_field_data = false, $exclude_groups = false, $exclude_fields = false ) {
     27        function __construct( $user_id, $profile_group_id, $hide_empty_groups = false, $fetch_fields = false, $fetch_field_data = false, $exclude_groups = false, $exclude_fields = false, $hide_empty_fields = false ) {
    2828                $this->groups = BP_XProfile_Group::get( array(
    2929                        'profile_group_id'  => $profile_group_id,
    3030                        'user_id'           => $user_id,
    3131                        'hide_empty_groups' => $hide_empty_groups,
     32                        'hide_empty_fields' => $hide_empty_fields,
    3233                        'fetch_fields'      => $fetch_fields,
    3334                        'fetch_field_data'  => $fetch_field_data,
    3435                        'exclude_groups'    => $exclude_groups,
     
    152153function bp_has_profile( $args = '' ) {
    153154        global $bp, $profile_template;
    154155
     156        // Only show empty fields on the Dashboard or the user profile edit screen
     157        $hide_empty_fields = ( bp_is_user_profile_edit() || is_admin() || is_network_admin() );
     158
    155159        $defaults = array(
    156                 'user_id' => $bp->displayed_user->id,
     160                'user_id'           => $bp->displayed_user->id,
    157161                'profile_group_id'  => false,
    158162                'hide_empty_groups' => true,
     163                'hide_empty_fields' => $hide_empty_fields,
    159164                'fetch_fields'      => true,
    160165                'fetch_field_data'  => true,
    161166                'exclude_groups'    => false, // Comma-separated list of profile field group IDs to exclude
     
    165170        $r = wp_parse_args( $args, $defaults );
    166171        extract( $r, EXTR_SKIP );
    167172
    168         $profile_template = new BP_XProfile_Data_Template( $user_id, $profile_group_id, $hide_empty_groups, $fetch_fields, $fetch_field_data, $exclude_groups, $exclude_fields );
     173        $profile_template = new BP_XProfile_Data_Template( $user_id, $profile_group_id, $hide_empty_groups, $fetch_fields, $fetch_field_data, $exclude_groups, $exclude_fields, $hide_empty_fields );
    169174        return apply_filters( 'bp_has_profile', $profile_template->has_groups(), $profile_template );
    170175}
    171176
     
    189194}
    190195        function bp_get_field_css_class( $class = false ) {
    191196                global $profile_template;
    192 
     197                static $alt_row;
     198               
     199                $alt_row     = ( $alt_row === 1 ) ? 2 : 1;
    193200                $css_classes = array();
    194201
    195202                if ( $class )
     
    201208                // Set a class with the field name (sanitized)
    202209                $css_classes[] = 'field_' . sanitize_title( $profile_template->field->name );
    203210
    204                 if ( $profile_template->current_field % 2 == 1 )
    205                         $css_classes[] = 'alt';
    206  No newline at end of file
     211                // Add alt row class
     212                $css_classes[] = ( $alt_row === 1 ) ? '' : 'alt';
    207213
    208214                $css_classes = apply_filters_ref_array( 'bp_field_css_classes', array( &$css_classes ) );
    209215