Skip to:
Content

BuddyPress.org

Ticket #5336: group-admin-invites-panel.patch

File group-admin-invites-panel.patch, 13.2 KB (added by dcavins, 10 years ago)

Patch adding single group "manage invitations" pane

  • bp-groups/admin/css/admin.css

    diff --git bp-groups/admin/css/admin.css bp-groups/admin/css/admin.css
    index 5a122cc..adf2cf8 100644
    body.toplevel_page_bp-groups table.groups th#last_active { 
    2323.bp-groups-settings-section {
    2424        margin-bottom: 15px;
    2525}
    26 .bp-groups-member-type {
     26.bp-group-admin-paginated-list {
    2727        position: relative;
    28         padding-bottom: 1.7em;
     28        padding: 1.7em 0;
     29}
     30.bp-groups-member-type {
     31        padding-top: 0;
    2932}
    3033.bp-groups-member-type > h4 {
    3134        margin-bottom: .5em;
    3235}
     36
    3337ul.bp-group-delete-list {
    3438        list-style-type: disc;
    3539        margin: 4px 26px;
  • bp-groups/admin/css/admin.min.css

    diff --git bp-groups/admin/css/admin.min.css bp-groups/admin/css/admin.min.css
    index 7983663..e46ce6d 100644
     
    1 body.toplevel_page_bp-groups table.groups th#status,body.toplevel_page_bp-groups table.groups th#members{width:10%}body.toplevel_page_bp-groups table.groups th#last_active{width:15%}#bp-groups-edit-form input{outline:medium none;padding:3px 8px}#bp-groups-edit-form input#bp-groups-name{font-size:1.7em;width:100%}#bp-groups-edit-form input#bp-groups-new-members{width:100%;max-width:90%;border:0}.bp-groups-settings-section{margin-bottom:15px}.bp-groups-member-type{position:relative;padding-bottom:1.7em}.bp-groups-member-type>h4{margin-bottom:.5em}ul.bp-group-delete-list{list-style-type:disc;margin:4px 26px}.bp-group-admin-pagination{position:absolute;text-align:right;width:100%}.bp-group-admin-pagination.table-top{top:0}.bp-group-admin-pagination.table-bottom{bottom:0}.bp-group-admin-pagination-viewing{font-family:Georgia,"Times New Roman","Bitstream Charter",Times,serif;color:#777;font-size:12px;font-style:italic}.bp-group-admin-pagination-links{white-space:nowrap;padding-left:15px}
    2  No newline at end of file
     1body.toplevel_page_bp-groups table.groups th#members,body.toplevel_page_bp-groups table.groups th#status{width:10%}body.toplevel_page_bp-groups table.groups th#last_active{width:15%}#bp-groups-edit-form input{outline:medium none;padding:3px 8px}#bp-groups-edit-form input#bp-groups-name{font-size:1.7em;width:100%}#bp-groups-edit-form input#bp-groups-new-members{width:100%;max-width:90%;border:0}.bp-groups-settings-section{margin-bottom:15px}.bp-group-admin-paginated-list{position:relative;padding:1.7em 0}.bp-groups-member-type{padding-top:0}.bp-groups-member-type>h4{margin-bottom:.5em}ul.bp-group-delete-list{list-style-type:disc;margin:4px 26px}.bp-group-admin-pagination{position:absolute;text-align:right;width:100%}.bp-group-admin-pagination.table-top{top:0}.bp-group-admin-pagination.table-bottom{bottom:0}.bp-group-admin-pagination-viewing{font-family:Georgia,"Times New Roman","Bitstream Charter",Times,serif;color:#777;font-size:12px;font-style:italic}.bp-group-admin-pagination-links{white-space:nowrap;padding-left:15px}
     2 No newline at end of file
  • bp-groups/bp-groups-admin.php

    diff --git bp-groups/bp-groups-admin.php bp-groups/bp-groups-admin.php
    index 1622692..3d74300 100644
    function bp_groups_admin_load() { 
    126126                add_meta_box( 'bp_group_settings', _x( 'Settings', 'group admin edit screen', 'buddypress' ), 'bp_groups_admin_edit_metabox_settings', get_current_screen()->id, 'side', 'core' );
    127127                add_meta_box( 'bp_group_add_members', _x( 'Add New Members', 'group admin edit screen', 'buddypress' ), 'bp_groups_admin_edit_metabox_add_new_members', get_current_screen()->id, 'normal', 'core' );
    128128                add_meta_box( 'bp_group_members', _x( 'Manage Members', 'group admin edit screen', 'buddypress' ), 'bp_groups_admin_edit_metabox_members', get_current_screen()->id, 'normal', 'core' );
     129                add_meta_box( 'bp_group_invitations', _x( 'Manage Invitations', 'group admin edit screen', 'buddypress' ), 'bp_groups_admin_edit_metabox_invitations', get_current_screen()->id, 'normal', 'core' );
    129130
    130131                do_action( 'bp_groups_admin_meta_boxes' );
    131132
    function bp_groups_admin_load() { 
    337338                        }
    338339                }
    339340
     341                // Process invitation removals
     342                if ( ! empty( $_POST['bp-groups-remove-invite'] ) ) {
     343
     344                        foreach ( (array) $_POST['bp-groups-remove-invite'] as $uninvited ) {
     345
     346                                // Remove the invitation
     347                                $result = groups_delete_invite( (int) $uninvited, $group_id );
     348                               
     349                                // Store the success or failure
     350                                if ( $result ) {
     351                                        $success_removed_invite[] = $uninvited;
     352                                } else {
     353                                        $error_removed_invite[]   = $uninvited;
     354                                }
     355
     356                        }
     357                }
     358
    340359                // Call actions for plugins to do something before we redirect
    341360                do_action( 'bp_group_admin_edit_after', $group_id );
    342361
    function bp_groups_admin_load() { 
    370389                        $redirect_to = add_query_arg( 'error_modified', $error_modified, $redirect_to );
    371390                }
    372391
     392                if ( !empty( $success_removed_invite ) ) {
     393                        $success_removed_invite = implode( ',', array_filter( $success_removed_invite, 'urlencode' ) );
     394                        $redirect_to = add_query_arg( 'success_removed_invite', $success_removed_invite, $redirect_to );
     395                }
     396
     397                if ( !empty( $error_removed_invite ) ) {
     398                        $error_removed_invite = implode( ',', array_filter( $error_removed_invite, 'urlencode' ) );
     399                        $redirect_to = add_query_arg( 'error_removed_invite', $error_removed_invite, $redirect_to );
     400                }
     401
    373402                // Redirect
    374403                wp_redirect( apply_filters( 'bp_group_admin_edit_redirect', $redirect_to ) );
    375404                exit;
    function bp_groups_admin_edit_metabox_members( $item ) { 
    767796        // Loop through each member type
    768797        foreach ( $members as $member_type => $type_users ) : ?>
    769798
    770                 <div class="bp-groups-member-type" id="bp-groups-member-type-<?php echo esc_attr( $member_type ) ?>">
     799                <div class="bp-groups-member-type bp-group-admin-paginated-list" id="bp-groups-member-type-<?php echo esc_attr( $member_type ) ?>">
    771800
    772801                        <h4>
    773802                                <?php switch ( $member_type ) :
    function bp_groups_admin_edit_metabox_members( $item ) { 
    859888}
    860889
    861890/**
     891 * Renders the Invitations metabox on single group pages.
     892 *
     893 * @since BuddyPress (2.0.0)
     894 *
     895 * @param BP_Groups_Group $item The BP_Groups_Group object for the current
     896 *        group.
     897 */
     898function bp_groups_admin_edit_metabox_invitations( $item ) {
     899        global $members_template;
     900
     901        $current_inv_page = isset( $_GET[ 'invitations_page' ] ) ? absint( $_GET[ 'invitations_page' ] ) : 1;
     902        $per_page = 10;
     903
     904        //Get invitations
     905        $invitations = BP_Groups_Member::get_group_invites( $item->id, $per_page, $current_inv_page );
     906        $total_invites = (int) $invitations['total'];
     907
     908        $pagination[ 'invitations' ] = bp_groups_admin_create_invitation_pagination_links( $current_inv_page, $per_page, $total_invites );
     909        ?>     
     910        <div id="bp-group-invitations-list" class="bp-group-admin-paginated-list">
     911               
     912                <div class="bp-group-admin-pagination table-top">
     913                        <?php echo $pagination[ 'invitations' ] ?>
     914                </div>
     915
     916               
     917        <?php if ( !empty( $invitations['invitees'] ) ) : ?>
     918
     919                <table class="widefat bp-group-invitations">
     920                        <thead>
     921                        <tr>
     922                                <th scope="col" class="uid-column"><?php _ex( 'ID', 'Group invitation recipient user_id in group admin', 'buddypress' ) ?></th>
     923                                <th scope="col" class="uname-column"><?php _ex( 'Name', 'Group invitation recipient name in group admin', 'buddypress' ) ?></th>
     924                                <th scope="col" class="inviter-name-column"><?php _ex( 'Invited By', 'User_id of group invitation sender in group admin', 'buddypress' ) ?></th>
     925                                <th scope="col" class="remove-invitation-column"><?php _ex( 'Remove Invitation', 'Remove invitation in group admin', 'buddypress' ) ?></th>
     926                        </tr>
     927                        </thead>
     928
     929                        <tbody>
     930
     931                        <?php foreach ( $invitations['invitees'] as $invitee ) : ?>
     932                                <tr>
     933                                        <th scope="row" class="uid-column"><?php echo esc_html( $invitee->user_id ); ?></th>
     934
     935                                        <td class="uname-column">
     936                                                <a style="float: left;" href="<?php echo bp_core_get_user_domain( $invitee->user_id ); ?>"><?php echo bp_core_fetch_avatar( array(
     937                                                        'item_id' => $invitee->user_id,
     938                                                        'width'   => '32',
     939                                                        'height'  => '32'
     940                                                ) ); ?></a>
     941
     942                                                <span style="margin: 8px; float: left;"><?php echo bp_core_get_userlink( $invitee->user_id ) ?></span>
     943                                        </td>
     944
     945                                        <td class="inviter-name-column">
     946                                                <span style="margin: 8px; float: left;"><?php echo bp_core_get_userlink( $invitee->inviter_id ) ?></span>
     947                                        </td>
     948                                        <td class="inviter-name-column">
     949                                                <label style="margin: 8px; float: left;"><input type="checkbox" name="bp-groups-remove-invite[<?php echo esc_html( $invitee->user_id ); ?>]" value="<?php echo esc_html( $invitee->user_id ); ?>">Remove</label>
     950                                        </td>
     951                                </tr>
     952
     953                        <?php endforeach; ?>
     954
     955                        </tbody>
     956                </table>
     957
     958                <div class="bp-group-admin-pagination table-bottom">
     959                        <?php echo $pagination[ 'invitations' ] ?>
     960                </div>
     961
     962        <?php else : ?>
     963
     964                <p class="bp-groups-no-outstanding-invites description"><?php _e( 'No outstanding invitations', 'buddypress' ) ?></p>
     965
     966        <?php endif; ?>
     967
     968        </div><!-- #bp-group-invitations-list -->
     969
     970<?php
     971}
     972
     973/**
    862974 * Renders the Status metabox for the Groups admin edit screen.
    863975 *
    864976 * @since BuddyPress (1.7.0)
    function bp_groups_admin_create_pagination_links( BP_Group_Member_Query $query, 
    9451057
    9461058        return $pagination;
    9471059}
     1060/**
     1061 * Create pagination links for invitations.
     1062 *
     1063 * This function is intended to create pagination links for use under the
     1064 * Manage Invitations section of the Groups Admin Dashboard pages. It is a stopgap
     1065 * measure until a more general pagination solution is in place for BuddyPress.
     1066 * Plugin authors should not use this function, as it is likely to be
     1067 * deprecated soon.
     1068 *
     1069 * @since BuddyPress (2.0.0)
     1070 *
     1071 * @return string Pagination links HTML.
     1072 */
     1073function bp_groups_admin_create_invitation_pagination_links( $page, $per_page, $total_invites ) {
     1074        $pagination = '';
     1075
     1076        // The key used to paginate this member type in the $_GET global
     1077        $qs_key = 'invitations_page';
     1078        $url_base = remove_query_arg( array( $qs_key, 'updated', 'success_modified' ), $_SERVER['REQUEST_URI'] );
     1079
     1080       
     1081        // Don't show anything if there's no pagination
     1082        if ( 1 === $page && $total_invites<= $per_page ) {
     1083                return $pagination;
     1084        }
     1085
     1086        $current_page_start = ( ( $page - 1 ) * $per_page ) + 1;
     1087        $current_page_end   = $page * $per_page > intval( $total_invites ) ? $total_invites : $page * $per_page;
     1088
     1089        $pag_links = paginate_links( array(
     1090                'base'      => add_query_arg( $qs_key, '%#%', $url_base ),
     1091                'format'    => '',
     1092                'prev_text' => __( '&laquo;', 'buddypress' ),
     1093                'next_text' => __( '&raquo;', 'buddypress' ),
     1094                'total'     => ceil( $total_invites / $per_page ),
     1095                'current'   => $page,
     1096        ) );
     1097
     1098        $viewing_text = sprintf(
     1099                __( 'Viewing %1$s - %2$s of %3$s', 'buddypress' ),
     1100                number_format_i18n( $current_page_start ),
     1101                number_format_i18n( $current_page_end ),
     1102                sprintf( _n( '%s member', '%s members', $total_invites, 'buddypress' ), $total_invites )
     1103        );
     1104
     1105        $pagination .= '<span class="bp-group-admin-pagination-viewing">' . $viewing_text . '</span>';
     1106        $pagination .= '<span class="bp-group-admin-pagination-links">' . $pag_links . '</span>';
     1107
     1108        return $pagination;
     1109}
     1110
    9481111
    9491112/**
    9501113 * Get a set of usernames corresponding to a set of user IDs.
  • bp-groups/bp-groups-classes.php

    diff --git bp-groups/bp-groups-classes.php bp-groups/bp-groups-classes.php
    index de81785..ea879f3 100644
    class BP_Groups_Member { 
    21682168                        return $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(DISTINCT m.group_id) FROM {$bp->groups->table_name_members} m, {$bp->groups->table_name} g WHERE m.group_id = g.id AND m.user_id = %d AND m.is_confirmed = 1 AND m.is_banned = 0", $user_id ) );
    21692169                }
    21702170        }
     2171        /**
     2172         * Get a group's outstanding group invitations.
     2173         *
     2174         * @param int $group_id ID of the group.
     2175         * @param int $limit Optional. Max number of results to return.
     2176         *        Default: false (no limit).
     2177         * @param int $page Optional. Page offset of results to return.
     2178         *        Default: false (no limit).
     2179         * @return array {
     2180         *     @type array $invitees Array of users returned by paginated query.
     2181         *     @type int $total Count of users matching query.
     2182         * }
     2183         */
     2184        public static function get_group_invites( $group_id, $limit = false, $page = false ) {
     2185                global $wpdb, $bp;
     2186
     2187                $pag_sql = ( !empty( $limit ) && !empty( $page ) ) ? $wpdb->prepare( " LIMIT %d, %d", intval( ( $page - 1 ) * $limit), intval( $limit ) ) : '';
     2188
     2189                // Outstanding invitations can be identified by checking for is_confirmed = 0 AND inviter_id != 0 AND invite_sent = 1
     2190                // Outstanding membership requests have is_confirmed = 0 AND inviter_id = 0 AND invite_sent = 0
     2191               
     2192                $paged_invitees = $wpdb->get_results( $wpdb->prepare( "SELECT m.*, i1.ID as invitee_id_check, i1.display_name as invitee_display_name, i2.ID as inviter_id_check, i2.display_name as inviter_display_name FROM {$bp->groups->table_name_members} m, {$wpdb->users} i1, {$wpdb->users} i2 WHERE m.user_id = i1.ID AND m.inviter_id = i2.ID AND m.is_confirmed = 0 AND m.inviter_id != 0 AND m.invite_sent = 1 AND m.group_id = %d ORDER BY m.date_modified ASC {$pag_sql}", $group_id ) );
     2193                $total_invitees = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(DISTINCT m.user_id) FROM {$bp->groups->table_name_members} m WHERE m.is_confirmed = 0 AND m.inviter_id != 0 AND m.invite_sent = 1 AND m.group_id = %d {$exclude_sql} ORDER BY date_modified ASC", $group_id ) );
     2194
     2195                return array( 'invitees' => $paged_invitees, 'total' => $total_invitees );
     2196        }
    21712197
    21722198        /**
    21732199         * Get a user's outstanding group invitations.