Changeset 4869
- Timestamp:
- 07/26/2011 05:26:30 PM (14 years ago)
- Location:
- trunk
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/bp-core/bp-core-template.php
r4847 r4869 651 651 $is_current_component = false; 652 652 653 // Backward compatibility: 'xprofile' should be read as 'profile' 654 if ( 'xprofile' == $component ) 655 $component = 'profile'; 656 653 657 if ( !empty( $bp->current_component ) ) { 654 658 … … 1023 1027 if ( bp_is_current_component( 'xprofile' ) && bp_is_current_action( 'edit' ) ) 1024 1028 return true; 1025 1029 1026 1030 return false; 1027 1031 } -
trunk/bp-xprofile/bp-xprofile-classes.php
r4827 r4869 100 100 * 'user_id' - Required if you want to load a specific user's data 101 101 * 'hide_empty_groups' - Hide groups without any fields 102 * 'hide_empty_fields' - Hide fields where the user has not provided data 102 103 * 'fetch_fields' - Load each group's fields 103 104 * 'fetch_field_data' - Load each field's data. Requires a user_id … … 114 115 'user_id' => $bp->displayed_user->id, 115 116 'hide_empty_groups' => false, 117 'hide_empty_fields' => false, 116 118 'fetch_fields' => false, 117 119 'fetch_field_data' => false, … … 162 164 $field_ids[] = $field->id; 163 165 164 $field_ids = implode( ',', (array) $field_ids );166 $field_ids_sql = implode( ',', (array) $field_ids ); 165 167 166 168 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 ) ); 168 169 if ( !empty( $field_data ) ) { 169 $field_data = $wpdb->get_results( $wpdb->prepare( "SELECT field_id, value FROM {$bp->profile->table_name_data} WHERE field_id IN ( {$field_ids_sql} ) AND user_id = %d", $user_id ) ); 170 171 // Remove data-less fields, if necessary 172 if ( $hide_empty_fields ) { 173 174 // Loop through the results and find the fields that have data. 175 foreach( (array)$field_data as $data ) { 176 if ( false !== $key = array_search( $data->field_id, $field_ids ) ) { 177 // Fields that have data get removed from the list 178 unset( $field_ids[$key] ); 179 } 180 } 181 182 // The remaining members of $field_ids are empty. Remove them. 183 foreach( $fields as $field_key => $field ) { 184 if ( in_array( $field->id, $field_ids ) ) { 185 unset( $fields[$field_key] ); 186 } 187 } 188 189 // Reset indexes 190 $fields = array_values( $fields ); 191 192 } 193 194 // Field data was found 195 if ( !empty( $field_data ) && !is_wp_error( $field_data ) ) { 196 197 // Loop through fields 170 198 foreach( (array)$fields as $field_key => $field ) { 199 200 // Loop throught the data in each field 171 201 foreach( (array)$field_data as $data ) { 202 203 // Assign correct data value to the field 172 204 if ( $field->id == $data->field_id ) 173 205 $fields[$field_key]->data->value = $data->value; 174 } 175 } 206 } 207 } 176 208 } 177 209 } 178 210 179 211 // Merge the field array back in with the group array 180 foreach( (array) $groups as $group_key => $group ) {181 foreach( (array) $fields as $field ) {212 foreach( (array) $groups as $group_key => $group ) { 213 foreach( (array) $fields as $field ) { 182 214 if ( $group->id == $field->group_id ) 183 215 $groups[$group_key]->fields[] = $field; 184 216 } 217 218 // When we unset fields above, we may have created empty groups. 219 // Remove them, if necessary. 220 if ( empty( $group->fields ) && $hide_empty_groups ) { 221 unset( $groups[$group_key] ); 222 } 223 224 // Reset indexes 225 $groups = array_values( $groups ); 185 226 } 186 227 -
trunk/bp-xprofile/bp-xprofile-template.php
r4840 r4869 21 21 var $user_id; 22 22 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 );25 } 26 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 ) {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 ); 25 } 26 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 ) { 28 28 $this->groups = BP_XProfile_Group::get( array( 29 29 'profile_group_id' => $profile_group_id, 30 30 'user_id' => $user_id, 31 31 'hide_empty_groups' => $hide_empty_groups, 32 'hide_empty_fields' => $hide_empty_fields, 32 33 'fetch_fields' => $fetch_fields, 33 34 'fetch_field_data' => $fetch_field_data, … … 153 154 global $bp, $profile_template; 154 155 156 // Only show empty fields if we're on the Dashboard, or on a user's profile edit page 157 $hide_empty_fields = ( !is_network_admin() && !is_admin() && !bp_is_user_profile_edit() ); 158 155 159 $defaults = array( 156 160 'user_id' => $bp->displayed_user->id, 157 161 'profile_group_id' => false, 158 162 'hide_empty_groups' => true, 163 'hide_empty_fields' => $hide_empty_fields, 159 164 'fetch_fields' => true, 160 165 'fetch_field_data' => true, … … 166 171 extract( $r, EXTR_SKIP ); 167 172 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 ); 169 174 return apply_filters( 'bp_has_profile', $profile_template->has_groups(), $profile_template ); 170 175 } … … 190 195 function bp_get_field_css_class( $class = false ) { 191 196 global $profile_template; 192 197 193 198 $css_classes = array(); 194 199
Note: See TracChangeset
for help on using the changeset viewer.