Skip to:
Content

BuddyPress.org

Changeset 12435


Ignore:
Timestamp:
08/12/2019 08:44:30 PM (7 years ago)
Author:
dcavins
Message:

Update BP_Nouveau_Group_Invite_Query for Invitations API compatibility.

See #6210.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/bp-templates/bp-nouveau/includes/groups/classes.php

    r12107 r12435  
    5151                $group_member_ids = $this->get_group_member_ids();
    5252
    53                 // We want to get users that are already members of the group
     53                /**
     54                 * We want to exclude users who are already members or who have been
     55                 * invited by **any** of the group members to join it.
     56                 */
    5457                $type = 'exclude';
    5558
    56                 // We want to get invited users who did not confirmed yet
     59                // We want to get the invited users who did not confirmed yet.
    5760                if ( false === $this->query_vars['is_confirmed'] ) {
    5861                        $type = 'include';
    … …  
    7881                }
    7982
     83                // Fetch **all** invited users.
     84                $pending_invites = groups_get_invites( array(
     85                        'item_id'     => $this->query_vars['group_id'],
     86                        'invite_sent' => 'sent',
     87                        'fields'      => 'user_ids'
     88                ) );
     89
     90                // This is a clue that we only want the invitations.
     91                if ( false === $this->query_vars['is_confirmed'] ) {
     92                        return $pending_invites;
     93                }
     94
     95                /**
     96                 * Otherwise, we want group members _and_ users with outstanding invitations,
     97                 * because we're doing an "exclude" query.
     98                 */
    8099                $bp  = buddypress();
    81100                $sql = array(
    … …  
    92111                $sql['where'][] = $wpdb->prepare( 'group_id = %d', $this->query_vars['group_id'] );
    93112
    94                 if ( false === $this->query_vars['is_confirmed'] ) {
    95                         $sql['where'][] = $wpdb->prepare( 'is_confirmed = %d', (int) $this->query_vars['is_confirmed'] );
    96                         $sql['where'][] = 'inviter_id != 0';
    97                 }
    98 
    99113                // Join the query part
    100114                $sql['where'] = ! empty( $sql['where'] ) ? 'WHERE ' . implode( ' AND ', $sql['where'] ) : '';
    … …  
    107121                $this->group_member_ids = $wpdb->get_col( "{$sql['select']} {$sql['where']} {$sql['orderby']} {$sql['order']} {$sql['limit']}" );
    108122
    109                 return $this->group_member_ids;
     123                return array_merge( $this->group_member_ids, $pending_invites );
    110124        }
    111125
    … …  
    138152                }
    139153
    140                 $bp = buddypress();
    141 
    142                 return $wpdb->get_col( $wpdb->prepare( "SELECT inviter_id FROM {$bp->groups->table_name_members} WHERE user_id = %d AND group_id = %d", $user_id, $group_id ) );
     154                return groups_get_invites( array(
     155                        'user_id'     => $user_id,
     156                        'item_id'     => $group_id,
     157                        'invite_sent' => 'sent',
     158                        'fields'      => 'inviter_ids'
     159                ) );
    143160        }
    144161}
Note: See TracChangeset for help on using the changeset viewer.