<!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] [2339] trunk:
  Fixes to group invite interface and template loop.</title>
</head>
<body>

<div id="msg">
<dl>
<dt>Revision</dt> <dd>2339</dd>
<dt>Author</dt> <dd>apeatling</dd>
<dt>Date</dt> <dd>2010-01-18 15:52:16 +0000 (Mon, 18 Jan 2010)</dd>
</dl>

<h3>Log Message</h3>
<pre>Fixes to group invite interface and template loop.</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkbpgroupsbpgroupsclassesphp">trunk/bp-groups/bp-groups-classes.php</a></li>
<li><a href="#trunkbpgroupsbpgroupstemplatetagsphp">trunk/bp-groups/bp-groups-templatetags.php</a></li>
<li><a href="#trunkbpgroupsphp">trunk/bp-groups.php</a></li>
<li><a href="#trunkbpthemesbpdefaultgroupssinglesendinvitesphp">trunk/bp-themes/bp-default/groups/single/send-invites.php</a></li>
<li><a href="#trunkbpthemesbpdefaultmemberssinglegroupsinvitesphp">trunk/bp-themes/bp-default/members/single/groups/invites.php</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkbpgroupsbpgroupsclassesphp"></a>
<div class="modfile"><h4>Modified: trunk/bp-groups/bp-groups-classes.php (2338 => 2339)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/bp-groups/bp-groups-classes.php        2010-01-18 15:01:11 UTC (rev 2338)
+++ trunk/bp-groups/bp-groups-classes.php        2010-01-18 15:52:16 UTC (rev 2339)
</span><span class="lines">@@ -852,12 +852,16 @@
</span><span class="cx">                 }
</span><span class="cx">         }
</span><span class="cx"> 
</span><del>-        function get_invites( $user_id ) {
</del><ins>+        function get_invites( $user_id, $limit = false, $page = false ) {
</ins><span class="cx">                 global $wpdb, $bp;
</span><span class="cx"> 
</span><del>-                $group_ids = $wpdb-&gt;get_results( $wpdb-&gt;prepare( &quot;SELECT group_id FROM {$bp-&gt;groups-&gt;table_name_members} WHERE user_id = %d and is_confirmed = 0 AND inviter_id != 0 AND invite_sent = 1&quot;, $user_id ) );
</del><ins>+                if ( $limit &amp;&amp; $page )
+                        $pag_sql = $wpdb-&gt;prepare( &quot; LIMIT %d, %d&quot;, intval( ( $page - 1 ) * $limit), intval( $limit ) );
</ins><span class="cx"> 
</span><del>-                return $group_ids;
</del><ins>+                $paged_groups = $wpdb-&gt;get_results( $wpdb-&gt;prepare( &quot;SELECT g.*, gm1.meta_value as total_member_count, gm2.meta_value as last_activity FROM {$bp-&gt;groups-&gt;table_name_groupmeta} gm1, {$bp-&gt;groups-&gt;table_name_groupmeta} gm2, {$bp-&gt;groups-&gt;table_name_members} m, {$bp-&gt;groups-&gt;table_name} g WHERE g.id = m.group_id AND g.id = gm1.group_id AND g.id = gm2.group_id AND gm2.meta_key = 'last_activity' AND gm1.meta_key = 'total_member_count' AND m.is_confirmed = 0 AND m.inviter_id != 0 AND m.invite_sent = 1 AND m.user_id = %d ORDER BY m.date_modified ASC {$pag_sql}&quot;, $user_id ) );
+                $total_groups = $wpdb-&gt;get_var( $wpdb-&gt;prepare( &quot;SELECT COUNT(DISTINCT m.group_id) FROM {$bp-&gt;groups-&gt;table_name_members} m, {$bp-&gt;groups-&gt;table_name} g WHERE m.group_id = g.id AND m.is_confirmed = 0 AND m.inviter_id != 0 AND m.invite_sent = 1 AND m.user_id = %d ORDER BY date_modified ASC&quot;, $user_id ) );
+
+                return array( 'groups' =&gt; $paged_groups, 'total' =&gt; $total_groups );
</ins><span class="cx">         }
</span><span class="cx"> 
</span><span class="cx">         function check_has_invite( $user_id, $group_id ) {
</span></span></pre></div>
<a id="trunkbpgroupsbpgroupstemplatetagsphp"></a>
<div class="modfile"><h4>Modified: trunk/bp-groups/bp-groups-templatetags.php (2338 => 2339)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/bp-groups/bp-groups-templatetags.php        2010-01-18 15:01:11 UTC (rev 2338)
+++ trunk/bp-groups/bp-groups-templatetags.php        2010-01-18 15:52:16 UTC (rev 2339)
</span><span class="lines">@@ -68,8 +68,7 @@
</span><span class="cx">                                 break;
</span><span class="cx"> 
</span><span class="cx">                         case 'invites':
</span><del>-                                if ( $user_id )
-                                        $this-&gt;groups = groups_get_invites_for_user();
</del><ins>+                                $this-&gt;groups = groups_get_invites_for_user( $user_id, $this-&gt;pag_num, $this-&gt;pag_page );
</ins><span class="cx">                                 break;
</span><span class="cx"> 
</span><span class="cx">                         case 'single-group':
</span><span class="lines">@@ -80,8 +79,9 @@
</span><span class="cx">                 }
</span><span class="cx"> 
</span><span class="cx">                 if ( 'invites' == $type ) {
</span><del>-                        $this-&gt;total_group_count = count($this-&gt;groups);
-                        $this-&gt;group_count = count($this-&gt;groups);
</del><ins>+                        $this-&gt;total_group_count = (int)$this-&gt;groups['total'];
+                        $this-&gt;group_count = (int)$this-&gt;groups['total'];
+                        $this-&gt;groups = $this-&gt;groups['groups'];
</ins><span class="cx">                 } else if ( 'single-group' == $type ) {
</span><span class="cx">                         $this-&gt;single_group = true;
</span><span class="cx">                         $this-&gt;total_group_count = 1;
</span></span></pre></div>
<a id="trunkbpgroupsphp"></a>
<div class="modfile"><h4>Modified: trunk/bp-groups.php (2338 => 2339)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/bp-groups.php        2010-01-18 15:01:11 UTC (rev 2338)
+++ trunk/bp-groups.php        2010-01-18 15:52:16 UTC (rev 2339)
</span><span class="lines">@@ -2260,13 +2260,13 @@
</span><span class="cx"> 
</span><span class="cx"> /*** Group Invitations *********************************************************/
</span><span class="cx"> 
</span><del>-function groups_get_invites_for_user( $user_id = false ) {
</del><ins>+function groups_get_invites_for_user( $user_id = false, $limit = false, $page = false ) {
</ins><span class="cx">         global $bp;
</span><span class="cx"> 
</span><span class="cx">         if ( !$user_id )
</span><span class="cx">                 $user_id = $bp-&gt;loggedin_user-&gt;id;
</span><span class="cx"> 
</span><del>-        return BP_Groups_Member::get_invites( $user_id );
</del><ins>+        return BP_Groups_Member::get_invites( $user_id, $limit, $page );
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> function groups_invite_user( $args = '' ) {
</span><span class="lines">@@ -2286,21 +2286,20 @@
</span><span class="cx">         if ( !$user_id || !$group_id )
</span><span class="cx">                 return false;
</span><span class="cx"> 
</span><del>-        if ( groups_is_user_member( $user_id, $group_id ) )
-                return false;
</del><ins>+        if ( !groups_is_user_member( $user_id, $group_id ) &amp;&amp; !groups_check_user_has_invite( $user_id, $group_id ) ) {
+                $invite = new BP_Groups_Member;
+                $invite-&gt;group_id = $group_id;
+                $invite-&gt;user_id = $user_id;
+                $invite-&gt;date_modified = $date_modified;
+                $invite-&gt;inviter_id = $inviter_id;
+                $invite-&gt;is_confirmed = $is_confirmed;
</ins><span class="cx"> 
</span><del>-        $invite = new BP_Groups_Member;
-        $invite-&gt;group_id = $group_id;
-        $invite-&gt;user_id = $user_id;
-        $invite-&gt;date_modified = $date_modified;
-        $invite-&gt;inviter_id = $inviter_id;
-        $invite-&gt;is_confirmed = $is_confirmed;
</del><ins>+                if ( !$invite-&gt;save() )
+                        return false;
</ins><span class="cx"> 
</span><del>-        if ( !$invite-&gt;save() )
-                return false;
</del><ins>+                do_action( 'groups_invite_user', $args );
+        }
</ins><span class="cx"> 
</span><del>-        do_action( 'groups_invite_user', $args );
-
</del><span class="cx">         return true;
</span><span class="cx"> }
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkbpthemesbpdefaultgroupssinglesendinvitesphp"></a>
<div class="modfile"><h4>Modified: trunk/bp-themes/bp-default/groups/single/send-invites.php (2338 => 2339)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/bp-themes/bp-default/groups/single/send-invites.php        2010-01-18 15:01:11 UTC (rev 2338)
+++ trunk/bp-themes/bp-default/groups/single/send-invites.php        2010-01-18 15:52:16 UTC (rev 2339)
</span><span class="lines">@@ -1,6 +1,6 @@
</span><span class="cx"> &lt;?php do_action( 'bp_before_group_send_invites_content' ) ?&gt;
</span><span class="cx"> 
</span><del>-&lt;?php if ( bp_has_friends_to_invite() ) : ?&gt;
</del><ins>+&lt;?php if ( bp_get_total_friend_count( bp_loggedin_user_id() ) ) : ?&gt;
</ins><span class="cx"> 
</span><span class="cx">         &lt;form action=&quot;&lt;?php bp_group_send_invite_form_action() ?&gt;&quot; method=&quot;post&quot; id=&quot;send-invite-form&quot; class=&quot;standard-form&quot;&gt;
</span><span class="cx"> 
</span><span class="lines">@@ -69,7 +69,7 @@
</span><span class="cx"> &lt;?php else : ?&gt;
</span><span class="cx"> 
</span><span class="cx">         &lt;div id=&quot;message&quot; class=&quot;info&quot;&gt;
</span><del>-                &lt;p&gt;&lt;?php _e( 'You either need to build up your friends list, or your friends have already been invited or are current members.', 'buddypress' ); ?&gt;&lt;/p&gt;
</del><ins>+                &lt;p&gt;&lt;?php _e( 'Once you have built up friend connections you will be able to invite others to your group. You can send invites any time in the future by selecting the &quot;Send Invites&quot; option when viewing your new group.', 'buddypress' ); ?&gt;&lt;/p&gt;
</ins><span class="cx">         &lt;/div&gt;
</span><span class="cx"> 
</span><span class="cx"> &lt;?php endif; ?&gt;
</span></span></pre></div>
<a id="trunkbpthemesbpdefaultmemberssinglegroupsinvitesphp"></a>
<div class="modfile"><h4>Modified: trunk/bp-themes/bp-default/members/single/groups/invites.php (2338 => 2339)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/bp-themes/bp-default/members/single/groups/invites.php        2010-01-18 15:01:11 UTC (rev 2338)
+++ trunk/bp-themes/bp-default/members/single/groups/invites.php        2010-01-18 15:52:16 UTC (rev 2339)
</span><span class="lines">@@ -1,6 +1,6 @@
</span><span class="cx"> &lt;?php do_action( 'bp_before_group_invites_content' ) ?&gt;
</span><span class="cx"> 
</span><del>-&lt;?php if ( bp_has_groups() ) : ?&gt;
</del><ins>+&lt;?php if ( bp_has_groups( 'type=invites&amp;user_id=' . bp_loggedin_user_id() ) ) : ?&gt;
</ins><span class="cx"> 
</span><span class="cx">         &lt;ul id=&quot;group-list&quot; class=&quot;invites item-list&quot;&gt;
</span><span class="cx"> 
</span><span class="lines">@@ -23,7 +23,6 @@
</span><span class="cx">                                         &lt;?php do_action( 'bp_group_invites_item_action' ) ?&gt;
</span><span class="cx"> 
</span><span class="cx">                                 &lt;/div&gt;
</span><del>-                                &lt;hr /&gt;
</del><span class="cx">                         &lt;/li&gt;
</span><span class="cx"> 
</span><span class="cx">                 &lt;?php endwhile; ?&gt;
</span></span></pre>
</div>
</div>

</body>
</html>