Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
03/05/2014 02:37:30 PM (13 years ago)
Author:
boonebgorges
Message:

Swap bp_group_has_invites() internals for BP_Group_Member_Query, and introduce pagination arguments

See #5423

Props boonebgorges, dcavins

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/bp-groups/bp-groups-template.php

    r7985 r8045  
    30953095        var $total_invite_count;
    30963096
    3097         function __construct( $user_id, $group_id ) {
    3098                 $this->invites      = groups_get_invites_for_group( $user_id, $group_id );
    3099                 $this->invite_count = count( $this->invites );
     3097        public function __construct( $args = array() ) {
     3098
     3099                // Backward compatibility with old method of passing arguments
     3100                if ( ! is_array( $args ) || func_num_args() > 1 ) {
     3101                        _deprecated_argument( __METHOD__, '2.0.0', sprintf( __( 'Arguments passed to %1$s should be in an associative array. See the inline documentation at %2$s for more details.', 'buddypress' ), __METHOD__, __FILE__ ) );
     3102
     3103                        $old_args_keys = array(
     3104                                0  => 'user_id',
     3105                                1  => 'group_id',
     3106                        );
     3107
     3108                        $func_args = func_get_args();
     3109                        $args      = bp_core_parse_args_array( $old_args_keys, $func_args );
     3110                }
     3111
     3112                $r = wp_parse_args( $args, array(
     3113                        'user_id'  => bp_loggedin_user_id(),
     3114                        'group_id' => bp_get_current_group_id(),
     3115                        'page'     => 1,
     3116                        'per_page' => 10,
     3117                ) );
     3118
     3119                $this->pag_num  = intval( $r['per_page'] );
     3120                $this->pag_page = isset( $_REQUEST['invitepage'] ) ? intval( $_REQUEST['invitepage'] ) : $r['page'];
     3121
     3122                $iquery = new BP_Group_Member_Query( array(
     3123                        'group_id' => $r['group_id'],
     3124                        'type'     => 'first_joined',
     3125                        'per_page' => $this->pag_num,
     3126                        'page'     => $this->pag_page,
     3127
     3128                        // These filters ensure we get only pending invites
     3129                        'is_confirmed' => false,
     3130                        'inviter_id'   => $r['user_id'],
     3131                ) );
     3132                $this->invite_data = $iquery->results;
     3133
     3134                $this->total_invite_count = $iquery->total_users;
     3135                $this->invites            = array_values( wp_list_pluck( $this->invite_data, 'ID' ) );
     3136                $this->invite_count       = count( $this->invites );
     3137
     3138                $this->pag_links = paginate_links( array(
     3139                        'base'      => add_query_arg( 'invitepage', '%#%' ),
     3140                        'format'    => '',
     3141                        'total'     => ceil( $this->total_invite_count / $this->pag_num ),
     3142                        'current'   => $this->pag_page,
     3143                        'prev_text' => '←',
     3144                        'next_text' => '→',
     3145                        'mid_size'  => 1,
     3146                ) );
    31003147        }
    31013148
    … …  
    31353182        function the_invite() {
    31363183                global $group_id;
    3137 
    31383184                $this->in_the_loop      = true;
    31393185                $user_id                = $this->next_invite();
     3186
    31403187                $this->invite           = new stdClass;
    3141                 $this->invite->user     = new BP_Core_User( $user_id );
     3188                $this->invite->user     = $this->invite_data[ $user_id ];
     3189
     3190                // This method previously populated the user object with
     3191                // BP_Core_User. We manually configure BP_Core_User data for
     3192                // backward compatibility.
     3193                if ( bp_is_active( 'xprofile' ) ) {
     3194                        $this->invite->user->profile_data = BP_XProfile_ProfileData::get_all_for_user( $user_id );
     3195                }
     3196
     3197                $this->invite->user->avatar       = bp_core_fetch_avatar( array( 'item_id' => $user_id, 'type' => 'full', 'alt' => sprintf( __( 'Avatar of %s', 'buddypress' ), $this->invite->user->fullname ) ) );
     3198                $this->invite->user->avatar_thumb = bp_core_fetch_avatar( array( 'item_id' => $user_id, 'type' => 'thumb', 'alt' => sprintf( __( 'Avatar of %s', 'buddypress' ), $this->invite->user->fullname ) ) );
     3199                $this->invite->user->avatar_mini  = bp_core_fetch_avatar( array( 'item_id' => $user_id, 'type' => 'thumb', 'alt' => sprintf( __( 'Avatar of %s', 'buddypress' ), $this->invite->user->fullname ), 'width' => 30, 'height' => 30 ) );
     3200                $this->invite->user->email        = $this->invite->user->user_email;
     3201                $this->invite->user->user_url     = bp_core_get_user_domain( $user_id, $this->invite->user->user_nicename, $this->invite->user->user_login );
     3202                $this->invite->user->user_link    = "<a href='{$this->invite->user->user_url}' title='{$this->invite->user->fullname}'>{$this->invite->user->fullname}</a>";
     3203                $this->invite->user->last_active  = bp_core_get_last_activity( $this->invite->user->last_activity, __( 'active %s', 'buddypress' ) );
     3204
     3205                if ( bp_is_active( 'groups' ) ) {
     3206                        $total_groups = BP_Groups_Member::total_group_count( $user_id );
     3207                        $this->invite->user->total_groups = sprintf( _n( '%d group', '%d groups', $total_groups, 'buddypress' ), $total_groups );
     3208                }
     3209
     3210                if ( bp_is_active( 'friends' ) ) {
     3211                        $this->invite->user->total_friends = BP_Friends_Friendship::total_friend_count( $user_id );
     3212                }
     3213
     3214                if ( bp_is_active( 'friends' ) ) {
     3215                        $this->invite->user->total_friends = BP_Friends_Friendship::total_friend_count( $user_id );
     3216                }
     3217
     3218                $this->invite->user->total_blogs = null;
     3219
    31423220                $this->invite->group_id = $group_id; // Globaled in bp_group_has_invites()
    31433221
    … …  
    31523230        $r = wp_parse_args( $args, array(
    31533231                'group_id' => false,
    3154                 'user_id' => bp_loggedin_user_id()
     3232                'user_id'  => bp_loggedin_user_id(),
     3233                'per_page' => 10,
     3234                'page'     => 1,
    31553235        ) );
    31563236
    … …  
    31723252        }
    31733253
    3174         $invites_template = new BP_Groups_Invite_Template( $r['user_id'], $r['group_id'] );
     3254        $invites_template = new BP_Groups_Invite_Template( $r );
    31753255        return apply_filters( 'bp_group_has_invites', $invites_template->has_invites(), $invites_template );
    31763256}
Note: See TracChangeset for help on using the changeset viewer.