<!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" />
<title>[BuddyPress][7146] trunk/bp-groups: Updates the Groups Admin member interface to use BP_Group_Member_Query</title>
</head>
<body>

<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { 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 #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#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>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://buddypress.trac.wordpress.org/changeset/7146">7146</a></dd>
<dt>Author</dt> <dd>boonebgorges</dd>
<dt>Date</dt> <dd>2013-06-04 03:04:33 +0000 (Tue, 04 Jun 2013)</dd>
</dl>

<h3>Log Message</h3>
<pre>Updates the Groups Admin member interface to use BP_Group_Member_Query

This provides increased flexibility for fixes to be introduced for <a href="http://buddypress.trac.wordpress.org/ticket/4977">#4977</a></pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkbpgroupsadminjsadminjs">trunk/bp-groups/admin/js/admin.js</a></li>
<li><a href="#trunkbpgroupsbpgroupsadminphp">trunk/bp-groups/bp-groups-admin.php</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkbpgroupsadminjsadminjs"></a>
<div class="modfile"><h4>Modified: trunk/bp-groups/admin/js/admin.js (7145 => 7146)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/bp-groups/admin/js/admin.js        2013-06-04 03:04:29 UTC (rev 7145)
+++ trunk/bp-groups/admin/js/admin.js   2013-06-04 03:04:33 UTC (rev 7146)
</span><span class="lines">@@ -11,7 +11,7 @@
</span><span class="cx">          $(e.target).closest('li').remove();
</span><span class="cx">  }
</span><span class="cx"> 
</span><del>-       var id = 'undefined' !== typeof group_members ? '&group_members=' + group_members : '';
</del><ins>+        var id = 'undefined' !== typeof group_id ? '&group_id=' + group_id : '';
</ins><span class="cx">   $(document).ready( function() {
</span><span class="cx">          /* Initialize autocomplete */
</span><span class="cx">          $( '.bp-suggest-user' ).autocomplete({
</span></span></pre></div>
<a id="trunkbpgroupsbpgroupsadminphp"></a>
<div class="modfile"><h4>Modified: trunk/bp-groups/bp-groups-admin.php (7145 => 7146)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/bp-groups/bp-groups-admin.php      2013-06-04 03:04:29 UTC (rev 7145)
+++ trunk/bp-groups/bp-groups-admin.php 2013-06-04 03:04:33 UTC (rev 7146)
</span><span class="lines">@@ -718,45 +718,22 @@
</span><span class="cx">          'admin'  => array(),
</span><span class="cx">          'mod'    => array(),
</span><span class="cx">          'member' => array(),
</span><del>-               'banned' => array()
</del><ins>+                'banned' => array(),
</ins><span class="cx">   );
</span><span class="cx"> 
</span><del>-       if ( bp_group_has_members( array(
-               'group_id' => $item->id,
-               'exclude_admins_mods' => false,
-               'exclude_banned' => false
-       ) ) ) {
-               // Get a list of admins and mods, to reduce lookups
-               // We'll rekey them by user_id for convenience
-               $admins = $mods = array();
</del><ins>+        foreach ( $members as $type => &$member_type_users ) {
+               $member_type_query = new BP_Group_Member_Query( array(
+                       'group_id'   => $item->id,
+                       'group_role' => array( $type ),
+                       'type'       => 'alphabetical',
+                       'per_page'   => 10,
+               ) );
</ins><span class="cx"> 
</span><del>-               foreach ( (array) groups_get_group_admins( $item->id ) as $admin_obj ) {
-                       $admins[ $admin_obj->user_id ] = $admin_obj;
-               }
-
-               foreach ( (array) groups_get_group_mods( $item->id ) as $admin_obj ) {
-                       $mods[ $admin_obj->user_id ] = $admin_obj;
-               }
-
-               while ( bp_group_members() ) {
-                       bp_group_the_member();
-                       if ( bp_get_group_member_is_banned() ) {
-                               $members['banned'][] = $members_template->member;
-                       } else if ( isset( $admins[ bp_get_group_member_id() ] ) ) {
-                               $members['admin'][]  = $members_template->member;
-                       } else if ( isset( $mods[ bp_get_group_member_id() ] ) ) {
-                               $members['mod'][]    = $members_template->member;
-                       } else {
-                               $members['member'][] = $members_template->member;
-                       }
-
-                       $member_ids[] = bp_get_group_member_id();
-               }
</del><ins>+                $member_type_users = $member_type_query->results;
</ins><span class="cx">   }
</span><span class="cx"> 
</span><span class="cx">  // Echo out the javascript variable
</span><del>-       $member_ids = ! empty( $member_ids ) ? implode( ',', $member_ids ) : '';
-       echo '<script type="text/javascript">var group_members = "' . $member_ids . '";</script>';
</del><ins>+        echo '<script type="text/javascript">var group_id = "' . $item->id . '";</script>';
</ins><span class="cx"> 
</span><span class="cx">  // Loop through each member type
</span><span class="cx">  foreach ( $members as $member_type => $type_users ) : ?>
</span><span class="lines">@@ -786,22 +763,21 @@
</span><span class="cx">                          <tbody>
</span><span class="cx"> 
</span><span class="cx">                          <?php foreach ( $type_users as $type_user ) : ?>
</span><del>-
</del><span class="cx">                                   <tr>
</span><del>-                                               <th scope="row" class="uid-column"><?php echo esc_html( $type_user->user_id ); ?></th>
</del><ins>+                                                <th scope="row" class="uid-column"><?php echo esc_html( $type_user->ID ); ?></th>
</ins><span class="cx"> 
</span><span class="cx">                                          <td class="uname-column">
</span><del>-                                                       <a style="float: left;" href="<?php echo bp_core_get_user_domain( $type_user->user_id ); ?>"><?php echo bp_core_fetch_avatar( array(
-                                                               'item_id' => $type_user->user_id,
</del><ins>+                                                        <a style="float: left;" href="<?php echo bp_core_get_user_domain( $type_user->ID ); ?>"><?php echo bp_core_fetch_avatar( array(
+                                                               'item_id' => $type_user->ID,
</ins><span class="cx">                                                           'width'   => '32',
</span><span class="cx">                                                          'height'  => '32'
</span><span class="cx">                                                  ) ); ?></a>
</span><span class="cx"> 
</span><del>-                                                       <span style="margin: 8px; float: left;"><?php echo bp_core_get_userlink( $type_user->user_id ) ?></span>
</del><ins>+                                                        <span style="margin: 8px; float: left;"><?php echo bp_core_get_userlink( $type_user->ID ) ?></span>
</ins><span class="cx">                                           </td>
</span><span class="cx"> 
</span><span class="cx">                                          <td class="urole-column">
</span><del>-                                                       <select class="bp-groups-role" id="bp-groups-role-<?php echo esc_attr( $type_user->user_id ); ?>" name="bp-groups-role[<?php echo esc_attr( $type_user->user_id ); ?>]">
</del><ins>+                                                        <select class="bp-groups-role" id="bp-groups-role-<?php echo esc_attr( $type_user->ID ); ?>" name="bp-groups-role[<?php echo esc_attr( $type_user->ID ); ?>]">
</ins><span class="cx">                                                           <option value="admin" <?php selected( 'admin', $member_type ) ?>><?php _e( 'Administrator', 'buddypress' ) ?></option>
</span><span class="cx">                                                          <option value="mod" <?php selected( 'mod', $member_type ) ?>><?php _e( 'Moderator', 'buddypress' ) ?></option>
</span><span class="cx">                                                          <option value="member" <?php selected( 'member', $member_type ) ?>><?php _e( 'Member', 'buddypress' ) ?></option>
</span><span class="lines">@@ -816,14 +792,14 @@
</span><span class="cx">                                                   *
</span><span class="cx">                                                   * @todo remove this, and do database detection on save
</span><span class="cx">                                                   */ ?>
</span><del>-                                                       <input type="hidden" name="bp-groups-existing-role[<?php echo esc_attr( $type_user->user_id ); ?>]" value="<?php echo esc_attr( $member_type ); ?>" />
</del><ins>+                                                        <input type="hidden" name="bp-groups-existing-role[<?php echo esc_attr( $type_user->ID ); ?>]" value="<?php echo esc_attr( $member_type ); ?>" />
</ins><span class="cx">                                           </td>
</span><span class="cx">                                  </tr>
</span><span class="cx"> 
</span><span class="cx">                                  <?php if ( has_filter( 'bp_groups_admin_manage_member_row' ) ) : ?>
</span><span class="cx">                                          <tr>
</span><span class="cx">                                                  <td colspan="3">
</span><del>-                                                               <?php do_action( 'bp_groups_admin_manage_member_row', $type_user->user_id, $item ); ?>
</del><ins>+                                                                <?php do_action( 'bp_groups_admin_manage_member_row', $type_user->ID, $item ); ?>
</ins><span class="cx">                                                   </td>
</span><span class="cx">                                          </tr>
</span><span class="cx">                                  <?php endif; ?>
</span><span class="lines">@@ -904,9 +880,19 @@
</span><span class="cx">  $return = array();
</span><span class="cx"> 
</span><span class="cx">  // Exclude current group members
</span><del>-       $group_members = isset( $_REQUEST['group_members'] ) ? wp_parse_id_list( $_REQUEST['group_members'] ) : array();
-       $terms         = isset( $_REQUEST['term']          ) ? $_REQUEST['term'] : '';
-       $users         = get_users( array(
</del><ins>+        $group_id = isset( $_GET['group_id'] ) ? wp_parse_id_list( $_GET['group_id'] ) : array();
+       $group_member_query = new BP_Group_Member_Query( array(
+               'group_id'        => $group_id,
+               'per_page'        => 0, // show all
+               'group_type'      => array( 'member', 'mod', 'admin', ),
+               'populate_extras' => false,
+               'count_total'     => false,
+       ) );
+
+       $group_members = ! empty( $group_member_query->results ) ? wp_list_pluck( $group_member_query->results, 'ID' ) : array();
+
+       $terms = isset( $_GET['term'] ) ? $_GET['term'] : '';
+       $users = get_users( array(
</ins><span class="cx">           'blog_id'        => false,
</span><span class="cx">          'search'         => '*' . $terms . '*',
</span><span class="cx">          'exclude'        => $group_members,
</span></span></pre>
</div>
</div>

</body>
</html>