Skip to:
Content

BuddyPress.org

Changeset 7158


Ignore:
Timestamp:
06/05/2013 12:57:43 AM (7 years ago)
Author:
boonebgorges
Message:

Introduces pagination for member types on Group Admin > Manage Members

When the Group Admin Dashboard panels were introduced in BuddyPress 1.7, the
Manage Member section was missing pagination. As a result, managing membership
in a group with more than 20 members could result in odd bugs, ranging from not
being able to see/modify all the members in your group, to receiving erroneous
error messages when attempting to modify user roles. Adding pagination for each
member type ensures that all group members can be viewed and modified by the
group administrator.

See #4977

Location:
trunk/bp-groups
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/bp-groups/admin/css/admin.css

    r6984 r7158  
    2424    margin-bottom: 15px;
    2525}
     26.bp-groups-member-type {
     27    position: relative;
     28    padding-bottom: 1.7em;
     29}
     30.bp-groups-member-type > h4 {
     31    margin-bottom: .5em;
     32}
    2633ul.bp-group-delete-list {
    2734    list-style-type: disc;
    2835    margin: 4px 26px;
    2936}
     37.bp-group-admin-pagination {
     38    position: absolute;
     39    text-align: right;
     40    width: 100%;
     41}
     42.bp-group-admin-pagination.table-top {
     43    top: 0;
     44}
     45.bp-group-admin-pagination.table-bottom {
     46    bottom: 0;
     47}
     48.bp-group-admin-pagination-viewing {
     49    font-family: Georgia, "Times New Roman", "Bitstream Charter", Times, serif;
     50    color: #777;
     51    font-size: 12px;
     52    font-style: italic;
     53}
     54.bp-group-admin-pagination-links {
     55    white-space: nowrap;
     56    padding-left: 15px;
     57}
  • trunk/bp-groups/bp-groups-admin.php

    r7146 r7158  
    714714    // We'll also keep track of group members here to place them into a
    715715    // javascript variable, which will help with group member autocomplete
    716     $member_ids = array();
    717     $members    = array(
     716    $members = array(
    718717        'admin'  => array(),
    719718        'mod'    => array(),
     
    722721    );
    723722
     723    $pagination = array(
     724        'admin'  => array(),
     725        'mod'    => array(),
     726        'member' => array(),
     727        'banned' => array(),
     728    );
     729
    724730    foreach ( $members as $type => &$member_type_users ) {
     731        $page_qs_key = $type . '_page';
     732        $current_type_page = isset( $_GET[ $page_qs_key ] ) ? absint( $_GET[ $page_qs_key ] ) : 1;
    725733        $member_type_query = new BP_Group_Member_Query( array(
    726734            'group_id'   => $item->id,
     
    728736            'type'       => 'alphabetical',
    729737            'per_page'   => 10,
     738            'page'       => $current_type_page,
    730739        ) );
    731740
    732741        $member_type_users = $member_type_query->results;
     742
     743        $pagination[ $type ] = bp_groups_admin_create_pagination_links( $member_type_query, $type );
    733744    }
    734745
     
    749760                endswitch; ?>
    750761            </h4>
     762
     763            <div class="bp-group-admin-pagination table-top">
     764                <?php echo $pagination[ $member_type ] ?>
     765            </div>
    751766
    752767        <?php if ( !empty( $type_users ) ) : ?>
     
    810825            </table>
    811826
     827            <div class="bp-group-admin-pagination table-bottom">
     828                <?php echo $pagination[ $member_type ] ?>
     829            </div>
     830
    812831        <?php else : ?>
    813832
     
    848867
    849868<?php
     869}
     870
     871/**
     872 * Create pagination links out of a BP_Group_Member_Query
     873 *
     874 * This function is intended to create pagination links for use under the
     875 * Manage Members section of the Groups Admin Dashboard pages. It is a stopgap
     876 * measure until a more general pagination solution is in place for BuddyPress.
     877 * Plugin authors should not use this function, as it is likely to be
     878 * deprecated soon.
     879 *
     880 * @since BuddyPress (1.8)
     881 * @param object $query A BP_Group_Member_Query object
     882 * @param string $member_type member|mod|admin|banned
     883 */
     884function bp_groups_admin_create_pagination_links( BP_Group_Member_Query $query, $member_type ) {
     885    $pagination = '';
     886
     887    if ( ! in_array( $member_type, array( 'admin', 'mod', 'member', 'banned' ) ) ) {
     888        return $pagination;
     889    }
     890
     891    // The key used to paginate this member type in the $_GET global
     892    $qs_key = $member_type . '_page';
     893    $url_base = remove_query_arg( array( $qs_key, 'updated', 'success_modified' ), $_SERVER['REQUEST_URI'] );
     894
     895    $page     = isset( $_GET[ $qs_key ] ) ? absint( $_GET[ $qs_key ] ) : 1;
     896    $per_page = 10; // @todo Make this customizable?
     897
     898    // Don't show anything if there's no pagination
     899    if ( 1 === $page && $query->total_users <= $per_page ) {
     900        return $pagination;
     901    }
     902
     903    $current_page_start = ( ( $page - 1 ) * $per_page ) + 1;
     904    $current_page_end   = $page * $per_page > intval( $query->total_users ) ? $query->total_users : $page * $per_page;
     905
     906    $pag_links = paginate_links( array(
     907        'base'      => add_query_arg( $qs_key, '%#%', $url_base ),
     908        'format'    => '',
     909        'prev_text' => __( '&laquo;' ),
     910        'next_text' => __( '&raquo;' ),
     911        'total'     => ceil( $query->total_users / $per_page ),
     912        'current'   => $page,
     913    ) );
     914
     915    $viewing_text = sprintf(
     916        __( 'Viewing %1$s - %2$s of %3$s', 'buddypress' ),
     917        number_format_i18n( $current_page_start ),
     918        number_format_i18n( $current_page_end ),
     919        sprintf( _n( '%s member', '%s members', $query->total_users, 'buddypress' ), $query->total_users )
     920    );
     921
     922    $pagination .= '<span class="bp-group-admin-pagination-viewing">' . $viewing_text . '</span>';
     923    $pagination .= '<span class="bp-group-admin-pagination-links">' . $pag_links . '</span>';
     924
     925    return $pagination;
    850926}
    851927
Note: See TracChangeset for help on using the changeset viewer.