Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
03/06/2014 07:58:49 PM (11 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

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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    );
Note: See TracChangeset for help on using the changeset viewer.