<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" /><style type="text/css"><!--
#msg dl { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;  }
#msg dl a { font-weight: bold}
#msg dl a:link    { color:#fc3; }
#msg dl a:active  { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fc0 solid; padding: 6px; }
#msg ul, pre { overflow: auto; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff  {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<title>[BuddyPress] [3381] trunk/bp-xprofile:
  Adds several exclude parameters to bp_has_profile().</title>
</head>
<body>

<div id="msg">
<dl>
<dt>Revision</dt> <dd>3381</dd>
<dt>Author</dt> <dd>boonebgorges</dd>
<dt>Date</dt> <dd>2010-11-09 12:59:25 +0000 (Tue, 09 Nov 2010)</dd>
</dl>

<h3>Log Message</h3>
<pre>Adds several exclude parameters to bp_has_profile(). Fixes #2655</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkbpxprofilebpxprofileclassesphp">trunk/bp-xprofile/bp-xprofile-classes.php</a></li>
<li><a href="#trunkbpxprofilebpxprofiletemplatetagsphp">trunk/bp-xprofile/bp-xprofile-templatetags.php</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkbpxprofilebpxprofileclassesphp"></a>
<div class="modfile"><h4>Modified: trunk/bp-xprofile/bp-xprofile-classes.php (3380 => 3381)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/bp-xprofile/bp-xprofile-classes.php        2010-11-07 22:56:27 UTC (rev 3380)
+++ trunk/bp-xprofile/bp-xprofile-classes.php        2010-11-09 12:59:25 UTC (rev 3381)
</span><span class="lines">@@ -79,15 +79,38 @@
</span><span class="cx"> 
</span><span class="cx">         /** Static Functions **/
</span><span class="cx"> 
</span><ins>+        /**
+         * get()
+         *
+         * Populates the BP_XProfile_Group object with profile field groups, fields, and field data
+         *
+         * @package BuddyPress XProfile
+         *
+         * @global $wpdb WordPress DB access object.
+         * @global $bp The global BuddyPress settings variable created in bp_core_setup_globals()
+         *
+         * @param array $args Takes an array of parameters:
+         *                'profile_group_id' - Limit results to a single profile group
+         *                'user_id' - Required if you want to load a specific user's data
+         *                'hide_empty_groups' - Hide groups without any fields
+         *                'fetch_fields' - Load each group's fields
+         *                'fetch_field_data' - Load each field's data. Requires a user_id
+         *                'exclude_groups' - Comma-separated list of groups to exclude
+         *                'exclude_fields' - Comma-separated list of fields to exclude
+         *
+         * @return array $groups
+         */
</ins><span class="cx">         function get( $args = '' ) {
</span><span class="cx">                 global $wpdb, $bp;
</span><span class="cx"> 
</span><span class="cx">                 $defaults = array(
</span><del>-                        'profile_group_id' =&gt; false,
-                        'user_id' =&gt; $bp-&gt;displayed_user-&gt;id,
</del><ins>+                        'profile_group_id'         =&gt; false,
+                        'user_id'                         =&gt; $bp-&gt;displayed_user-&gt;id,
</ins><span class="cx">                         'hide_empty_groups' =&gt; false,
</span><del>-                        'fetch_fields' =&gt; false,
-                        'fetch_field_data' =&gt; false
</del><ins>+                        'fetch_fields'                 =&gt; false,
+                        'fetch_field_data'         =&gt; false,
+                        'exclude_groups'         =&gt; false,
+                        'exclude_fields'         =&gt; false
</ins><span class="cx">                 );
</span><span class="cx"> 
</span><span class="cx">                 $r = wp_parse_args( $args, $defaults );
</span><span class="lines">@@ -95,17 +118,19 @@
</span><span class="cx"> 
</span><span class="cx">                 $group_id_sql = '';
</span><span class="cx">                 if ( $profile_group_id )
</span><del>-                        $group_id_sql = $wpdb-&gt;prepare( 'WHERE g.id = %d', $profile_group_id );
</del><ins>+                        $where_sql = $wpdb-&gt;prepare( 'WHERE g.id = %d', $profile_group_id );
+                else if ( $exclude_groups )
+                        $where_sql = $wpdb-&gt;prepare( &quot;WHERE g.id NOT IN ({$exclude_groups})&quot;);
</ins><span class="cx"> 
</span><span class="cx">                 if ( $hide_empty_groups )
</span><del>-                        $groups = $wpdb-&gt;get_results( $wpdb-&gt;prepare( &quot;SELECT DISTINCT g.* FROM {$bp-&gt;profile-&gt;table_name_groups} g INNER JOIN {$bp-&gt;profile-&gt;table_name_fields} f ON g.id = f.group_id {$group_id_sql} ORDER BY g.group_order ASC&quot; ) );
</del><ins>+                        $groups = $wpdb-&gt;get_results( $wpdb-&gt;prepare( &quot;SELECT DISTINCT g.* FROM {$bp-&gt;profile-&gt;table_name_groups} g INNER JOIN {$bp-&gt;profile-&gt;table_name_fields} f ON g.id = f.group_id {$where_sql} ORDER BY g.group_order ASC&quot; ) );
</ins><span class="cx">                 else
</span><del>-                        $groups = $wpdb-&gt;get_results( $wpdb-&gt;prepare( &quot;SELECT DISTINCT g.* FROM {$bp-&gt;profile-&gt;table_name_groups} g {$group_id_sql} ORDER BY g.group_order ASC&quot; ) );
</del><ins>+                        $groups = $wpdb-&gt;get_results( $wpdb-&gt;prepare( &quot;SELECT DISTINCT g.* FROM {$bp-&gt;profile-&gt;table_name_groups} g {$where_sql} ORDER BY g.group_order ASC&quot; ) );
</ins><span class="cx"> 
</span><span class="cx">                 if ( !$fetch_fields )
</span><span class="cx">                         return $groups;
</span><span class="cx"> 
</span><del>-                /* Get the group ids */
</del><ins>+                // Get the group ids
</ins><span class="cx">                 foreach( (array)$groups as $group ) {
</span><span class="cx">                         $group_ids[] = $group-&gt;id;
</span><span class="cx">                 }
</span><span class="lines">@@ -115,14 +140,17 @@
</span><span class="cx">                 if ( empty( $group_ids ) )
</span><span class="cx">                         return $groups;
</span><span class="cx"> 
</span><del>-                /* Fetch the fields */
-                $fields = $wpdb-&gt;get_results( $wpdb-&gt;prepare( &quot;SELECT id, name, description, type, group_id, is_required FROM {$bp-&gt;profile-&gt;table_name_fields} WHERE group_id IN ( {$group_ids} ) AND parent_id = 0 ORDER BY field_order&quot; ) );
</del><ins>+                if ( $exclude_fields )
+                        $exclude_fields_sql = $wpdb-&gt;prepare( &quot;AND id NOT IN ({$exclude_fields})&quot; );
</ins><span class="cx"> 
</span><ins>+                // Fetch the fields
+                $fields = $wpdb-&gt;get_results( $wpdb-&gt;prepare( &quot;SELECT id, name, description, type, group_id, is_required FROM {$bp-&gt;profile-&gt;table_name_fields} WHERE group_id IN ( {$group_ids} ) AND parent_id = 0 {$exclude_fields_sql} ORDER BY field_order&quot; ) );
+
</ins><span class="cx">                 if ( empty( $fields ) )
</span><span class="cx">                         return $groups;
</span><span class="cx"> 
</span><span class="cx">                 if ( $fetch_field_data ) {
</span><del>-                        /* Fetch the field data for the user. */
</del><ins>+                        // Fetch the field data for the user.
</ins><span class="cx">                         foreach( (array)$fields as $field )
</span><span class="cx">                                 $field_ids[] = $field-&gt;id;
</span><span class="cx"> 
</span><span class="lines">@@ -141,7 +169,7 @@
</span><span class="cx">                         }
</span><span class="cx">                 }
</span><span class="cx"> 
</span><del>-                /* Merge the field array back in with the group array */
</del><ins>+                // Merge the field array back in with the group array
</ins><span class="cx">                 foreach( (array)$groups as $group_key =&gt; $group ) {
</span><span class="cx">                         foreach( (array)$fields as $field ) {
</span><span class="cx">                                 if ( $group-&gt;id == $field-&gt;group_id )
</span></span></pre></div>
<a id="trunkbpxprofilebpxprofiletemplatetagsphp"></a>
<div class="modfile"><h4>Modified: trunk/bp-xprofile/bp-xprofile-templatetags.php (3380 => 3381)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/bp-xprofile/bp-xprofile-templatetags.php        2010-11-07 22:56:27 UTC (rev 3380)
+++ trunk/bp-xprofile/bp-xprofile-templatetags.php        2010-11-09 12:59:25 UTC (rev 3381)
</span><span class="lines">@@ -17,13 +17,15 @@
</span><span class="cx">         var $in_the_loop;
</span><span class="cx">         var $user_id;
</span><span class="cx"> 
</span><del>-        function bp_xprofile_data_template( $user_id, $profile_group_id ) {
</del><ins>+        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 ) {
</ins><span class="cx">                 $this-&gt;groups = BP_XProfile_Group::get( array(
</span><del>-                        'profile_group_id' =&gt; $profile_group_id,
-                        'user_id' =&gt; $user_id,
-                        'hide_empty_groups' =&gt; true,
-                        'fetch_fields' =&gt; true,
-                        'fetch_field_data' =&gt; true
</del><ins>+                        'profile_group_id'         =&gt; $profile_group_id,
+                        'user_id'                         =&gt; $user_id,
+                        'hide_empty_groups' =&gt; $hide_empty_groups,
+                        'fetch_fields'                 =&gt; $fetch_fields,
+                        'fetch_field_data'         =&gt; $fetch_field_data,
+                        'exclude_groups'        =&gt; $exclude_groups,
+                        'exclude_fields'        =&gt; $exclude_fields
</ins><span class="cx">                 ) );
</span><span class="cx"> 
</span><span class="cx">                 $this-&gt;group_count = count($this-&gt;groups);
</span><span class="lines">@@ -144,13 +146,18 @@
</span><span class="cx"> 
</span><span class="cx">         $defaults = array(
</span><span class="cx">                 'user_id' =&gt; $bp-&gt;displayed_user-&gt;id,
</span><del>-                'profile_group_id' =&gt; false
</del><ins>+                'profile_group_id' =&gt; false,
+                'hide_empty_groups'        =&gt; true,
+                'fetch_fields'                =&gt; true,
+                'fetch_field_data'        =&gt; true,
+                'exclude_groups' =&gt; false, // Comma-separated list of profile field group IDs to exclude
+                'exclude_fields' =&gt; false // Comma-separated list of profile field IDs to exclude
</ins><span class="cx">         );
</span><span class="cx"> 
</span><span class="cx">         $r = wp_parse_args( $args, $defaults );
</span><span class="cx">         extract( $r, EXTR_SKIP );
</span><span class="cx"> 
</span><del>-        $profile_template = new BP_XProfile_Data_Template( $user_id, $profile_group_id );
</del><ins>+        $profile_template = new BP_XProfile_Data_Template( $user_id, $profile_group_id, $hide_empty_groups, $fetch_fields, $fetch_field_data, $exclude_groups, $exclude_fields );
</ins><span class="cx">         return apply_filters( 'bp_has_profile', $profile_template-&gt;has_groups(), &amp;$profile_template );
</span><span class="cx"> }
</span><span class="cx"> 
</span></span></pre>
</div>
</div>

</body>
</html>