Changeset 4869 for trunk/bp-xprofile/bp-xprofile-classes.php
- Timestamp:
- 07/26/2011 05:26:30 PM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
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
Note: See TracChangeset
for help on using the changeset viewer.