Changeset 3381
- Timestamp:
- 11/09/2010 12:59:25 PM (14 years ago)
- Location:
- trunk/bp-xprofile
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/bp-xprofile/bp-xprofile-classes.php
r3369 r3381 80 80 /** Static Functions **/ 81 81 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 */ 82 103 function get( $args = '' ) { 83 104 global $wpdb, $bp; 84 105 85 106 $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, 88 109 '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 91 114 ); 92 115 … … 96 119 $group_id_sql = ''; 97 120 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})"); 99 124 100 125 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" ) ); 102 127 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" ) ); 104 129 105 130 if ( !$fetch_fields ) 106 131 return $groups; 107 132 108 / * Get the group ids */133 // Get the group ids 109 134 foreach( (array)$groups as $group ) { 110 135 $group_ids[] = $group->id; … … 116 141 return $groups; 117 142 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" ) ); 120 148 121 149 if ( empty( $fields ) ) … … 123 151 124 152 if ( $fetch_field_data ) { 125 / * Fetch the field data for the user. */153 // Fetch the field data for the user. 126 154 foreach( (array)$fields as $field ) 127 155 $field_ids[] = $field->id; … … 142 170 } 143 171 144 / * Merge the field array back in with the group array */172 // Merge the field array back in with the group array 145 173 foreach( (array)$groups as $group_key => $group ) { 146 174 foreach( (array)$fields as $field ) { -
trunk/bp-xprofile/bp-xprofile-templatetags.php
r3377 r3381 18 18 var $user_id; 19 19 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 ) { 21 21 $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 27 29 ) ); 28 30 … … 145 147 $defaults = array( 146 148 '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 148 155 ); 149 156 … … 151 158 extract( $r, EXTR_SKIP ); 152 159 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 ); 154 161 return apply_filters( 'bp_has_profile', $profile_template->has_groups(), &$profile_template ); 155 162 }
Note: See TracChangeset
for help on using the changeset viewer.