Skip to:
Content

BuddyPress.org

Changeset 8069


Ignore:
Timestamp:
03/06/2014 07:58:49 PM (7 years ago)
Author:
boonebgorges
Message:

Replace internals of BP_Group_Membership_Requests_Template with BP_Group_Member_Query

This brings us more in line with the Invites template functions, and is another
step toward centralizing all of our group queries.

The change also allows for true pagination. This changeset also adds the 'page'
parameter to the stack.

See #5440

Props dcavins

Location:
trunk
Files:
3 edited

Legend:

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

    r8061 r8069  
    14551455 * - *Pending and unsent invitations* are entries with is_confirmed = 0 and
    14561456 *   inviter_id != 0 and invite_sent = 0
     1457 * - *Membership requests* are entries with is_confirmed = 0 and
     1458 *   inviter_id = 0 (and invite_sent = 0)
    14571459 *
    14581460 * @since BuddyPress (1.8.0)
     
    17231725
    17241726        $bp     = buddypress();
    1725         $extras = $wpdb->get_results( $wpdb->prepare( "SELECT user_id, date_modified, is_banned FROM {$bp->groups->table_name_members} WHERE user_id IN ({$user_ids_sql}) AND group_id = %d", $this->query_vars['group_id'] ) );
     1727        $extras = $wpdb->get_results( $wpdb->prepare( "SELECT id, user_id, date_modified, is_admin, is_mod, comments, user_title, invite_sent, is_confirmed, inviter_id, is_banned FROM {$bp->groups->table_name_members} WHERE user_id IN ({$user_ids_sql}) AND group_id = %d", $this->query_vars['group_id'] ) );
    17261728
    17271729        foreach ( (array) $extras as $extra ) {
     
    17291731                // user_id is provided for backward compatibility
    17301732                $this->results[ $extra->user_id ]->user_id       = (int) $extra->user_id;
     1733                $this->results[ $extra->user_id ]->is_admin      = (int) $extra->is_admin;
     1734                $this->results[ $extra->user_id ]->is_mod        = (int) $extra->is_mod;
    17311735                $this->results[ $extra->user_id ]->is_banned     = (int) $extra->is_banned;
    17321736                $this->results[ $extra->user_id ]->date_modified = $extra->date_modified;
     1737                $this->results[ $extra->user_id ]->user_title    = $extra->user_title;
     1738                $this->results[ $extra->user_id ]->comments      = $extra->comments;
     1739                $this->results[ $extra->user_id ]->invite_sent   = (int) $extra->invite_sent;
     1740                $this->results[ $extra->user_id ]->inviter_id    = (int) $extra->inviter_id;
     1741                $this->results[ $extra->user_id ]->is_confirmed  = (int) $extra->is_confirmed;
     1742                $this->results[ $extra->user_id ]->membership_id = (int) $extra->id;
    17331743            }
    17341744        }
  • trunk/bp-groups/bp-groups-template.php

    r8066 r8069  
    29372937     *     @type int $per_page Number of records to return per page of
    29382938     *           results. Default: 10.
     2939     *     @type int $page Page of results to show. Default: 1.
    29392940     *     @type int $max Max items to return. Default: false (show all)
    29402941     * }
     
    29592960            'group_id' => bp_get_current_group_id(),
    29602961            'per_page' => 10,
    2961             'max' => false,
     2962            'page'     => 1,
     2963            'max'      => false,
     2964            'type'     => 'first_joined',
    29622965        ) );
    29632966
    2964         $this->pag_page = isset( $_REQUEST['mrpage'] ) ? intval( $_REQUEST['mrpage'] ) : 1;
     2967        $this->pag_page = isset( $_REQUEST['mrpage'] ) ? intval( $_REQUEST['mrpage'] ) : $r['page'];
    29652968        $this->pag_num  = isset( $_REQUEST['num'] ) ? intval( $_REQUEST['num'] ) : $r['per_page'];
    2966         $this->requests = BP_Groups_Group::get_membership_requests( $r['group_id'], $this->pag_num, $this->pag_page );
    2967 
    2968         if ( !$r['max'] || $r['max'] >= (int) $this->requests['total'] )
    2969             $this->total_request_count = (int) $this->requests['total'];
     2969
     2970        $mquery = new BP_Group_Member_Query( array(
     2971            'group_id' => $r['group_id'],
     2972            'type'     => $r['type'],
     2973            'per_page' => $this->pag_num,
     2974            'page'     => $this->pag_page,
     2975
     2976            // These filters ensure we only get pending requests
     2977            'is_confirmed' => false,
     2978            'inviter_id'   => 0,
     2979        ) );
     2980
     2981        $this->requests      = array_values( $mquery->results );
     2982        $this->request_count = count( $this->requests );
     2983
     2984        // Compatibility with legacy format of request data objects
     2985        foreach ( $this->requests as $rk => $rv ) {
     2986            // For legacy reasons, the 'id' property of each
     2987            // request must match the membership id, not the ID of
     2988            // the user (as it's returned by BP_Group_Member_Query)
     2989            $this->requests[ $rk ]->user_id = $rv->ID;
     2990            $this->requests[ $rk ]->id      = $rv->membership_id;
     2991
     2992            // Miscellaneous values
     2993            $this->requests[ $rk ]->group_id   = $r['group_id'];
     2994        }
     2995
     2996        if ( !$r['max'] || $r['max'] >= (int) $mquery->total_users )
     2997            $this->total_request_count = (int) $mquery->total_users;
    29702998        else
    29712999            $this->total_request_count = (int) $r['max'];
    2972 
    2973         $this->requests = $this->requests['requests'];
    29743000
    29753001        if ( $r['max'] ) {
     
    30363062}
    30373063
     3064/**
     3065 * Initialize a group membership request template loop.
     3066 *
     3067 * @param array $args {
     3068 *     @type int $group_id ID of the group. Defaults to current group.
     3069 *     @type int $per_page Number of records to return per page. Default: 10.
     3070 *     @type int $page Page of results to return. Default: 1.
     3071 *     @type int $max Max number of items to return. Default: false.
     3072 * }
     3073 * @return bool True if there are requests, otherwise false.
     3074 */
    30383075function bp_group_has_membership_requests( $args = '' ) {
    30393076    global $requests_template, $groups_template;
     
    30423079        'group_id' => $groups_template->group->id,
    30433080        'per_page' => 10,
     3081        'page'     => 1,
    30443082        'max'      => false
    30453083    );
  • trunk/tests/testcases/groups/template.php

    r8065 r8069  
    548548        for ( $i = 1; $i < 15; $i++ ) {
    549549            $users[ $i ] = $this->create_user( array(
    550                 'last_activity' => gmdate( 'Y-m-d H:i:s', time() - $i ),
     550                'last_activity' => gmdate( 'Y-m-d H:i:s', time() - ( 100 - $i ) ),
    551551            ) );
    552552
    553553            $memberships[ $i ] = $this->add_user_to_group( $users[ $i ], $g, array(
    554                 'date_modified' => gmdate( 'Y-m-d H:i:s', time() - $i ),
     554                // this date_modified ensures that order will match
     555                // id order. necessary due to a quirk in the legacy
     556                // implementation
     557                'date_modified' => gmdate( 'Y-m-d H:i:s', time() - ( 100 - $i ) ),
    555558                'is_confirmed' => 0,
    556559                'inviter_id' => 0,
Note: See TracChangeset for help on using the changeset viewer.