Skip to:
Content

BuddyPress.org

Changeset 11604


Ignore:
Timestamp:
06/21/2017 10:37:23 PM (2 years ago)
Author:
r-a-y
Message:

Groups: Add fine-grained querying of invite sent status in groups_get_invites_for_group().

This commit introduces a new $sent parameter to groups_get_invites_for_group()
and BP_Groups_Group::get_invites(). With this parameter, developers can
now query group invites by sent status or not.

See #7397.

Location:
trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/bp-groups/bp-groups-functions.php

    r11603 r11604  
    16261626 *
    16271627 * @since 1.0.0
    1628  *
    1629  * @param int $user_id  ID of the inviting user.
    1630  * @param int $group_id ID of the group.
    1631  * @return array $value IDs of users who have been invited to the group by the
    1632  *                      user but have not yet accepted.
    1633  */
    1634 function groups_get_invites_for_group( $user_id, $group_id ) {
    1635     return BP_Groups_Group::get_invites( $user_id, $group_id );
     1628 * @since 2.9.0 Added $sent as a parameter.
     1629 *
     1630 * @param  int      $user_id  ID of the inviting user.
     1631 * @param  int      $group_id ID of the group.
     1632 * @param  int|null $sent     Query for a specific invite sent status. If 0, this will query for users
     1633 *                            that haven't had an invite sent to them yet. If 1, this will query for
     1634 *                            users that have had an invite sent to them. If null, no invite status will
     1635 *                            queried. Default: null.
     1636 * @return array    IDs of users who have been invited to the group by the user but have not
     1637 *                  yet accepted.
     1638 */
     1639function groups_get_invites_for_group( $user_id, $group_id, $sent = null ) {
     1640    return BP_Groups_Group::get_invites( $user_id, $group_id, $sent );
    16361641}
    16371642
  • trunk/src/bp-groups/classes/class-bp-groups-group.php

    r11558 r11604  
    753753     *
    754754     * @since 1.6.0
    755      *
    756      * @param int $user_id ID of the inviting user.
    757      * @param int $group_id ID of the group.
    758      * @return array IDs of users who have been invited to the group by the
    759      *               user but have not yet accepted.
    760      */
    761     public static function get_invites( $user_id, $group_id ) {
     755     * @since 2.9.0 Added $sent as a parameter.
     756     *
     757     * @param  int      $user_id  ID of the inviting user.
     758     * @param  int      $group_id ID of the group.
     759     * @param  int|null $sent     Query for a specific invite sent status. If 0, this will query for users
     760     *                            that haven't had an invite sent to them yet. If 1, this will query for
     761     *                            users that have had an invite sent to them. If null, no invite status will
     762     *                            queried. Default: null.
     763     * @return array    IDs of users who have been invited to the group by the user but have not
     764     *                  yet accepted.
     765     */
     766    public static function get_invites( $user_id, $group_id, $sent = null ) {
    762767        global $wpdb;
    763768
    764         $bp = buddypress();
    765 
    766         return $wpdb->get_col( $wpdb->prepare( "SELECT user_id FROM {$bp->groups->table_name_members} WHERE group_id = %d and is_confirmed = 0 AND inviter_id = %d", $group_id, $user_id ) );
     769        $bp  = buddypress();
     770        $sql = $wpdb->prepare( "SELECT user_id FROM {$bp->groups->table_name_members} WHERE group_id = %d and is_confirmed = 0 AND inviter_id = %d", $group_id, $user_id );
     771
     772        // Query for a specific invite sent status.
     773        if ( ! is_null( $sent ) ) {
     774            $sql .= $wpdb->prepare( ' AND invite_sent = %d', $sent );
     775        }
     776
     777        return $wpdb->get_col( $sql );
    767778    }
    768779
  • trunk/tests/phpunit/testcases/groups/class-bp-groups-member.php

    r11378 r11604  
    11511151
    11521152    /**
    1153      * @group groups_send_membership_request
    1154      * @group group_membership_requests
    1155      * @group group_membership
    1156      */
    1157     public function test_groups_send_membership_request() {
    1158         $u1 = $this->factory->user->create();
    1159         $g1 = $this->factory->group->create();
    1160 
    1161         // Create membership request
    1162         groups_send_membership_request( $u1, $g1 );
    1163 
    1164         $request = groups_check_for_membership_request( $u1, $g1 );
    1165         $this->assertTrue( is_numeric( $request ) && $request > 0 );
    1166     }
    1167 
    1168     /**
    1169      * @group groups_accept_membership_request
    1170      * @group group_membership_requests
    1171      * @group group_membership
    1172      */
    1173     public function test_groups_accept_membership_request_by_membership_id() {
    1174         $u1 = $this->factory->user->create();
    1175         $g1 = $this->factory->group->create();
    1176 
    1177         // Create membership request
    1178         groups_send_membership_request( $u1, $g1 );
    1179 
    1180         // Get group invitations of any type, from any user in the group.
    1181         $member = new BP_Groups_Member( $u1, $g1 );
    1182 
    1183         groups_accept_membership_request( $member->id );
    1184 
    1185         // User should now be a group member.
    1186         $member = groups_is_user_member( $u1, $g1 );
    1187 
    1188         $this->assertTrue( is_numeric( $member ) && $member > 0 );
    1189     }
    1190 
    1191     /**
    1192      * @group groups_accept_membership_request
    1193      * @group group_membership_requests
    1194      * @group group_membership
    1195      */
    1196     public function test_groups_accept_membership_request_by_user_id_group_id() {
    1197         $u1 = $this->factory->user->create();
    1198         $g1 = $this->factory->group->create();
    1199 
    1200         // Create membership request
    1201         groups_send_membership_request( $u1, $g1 );
    1202 
    1203         groups_accept_membership_request( null, $u1, $g1 );
    1204 
    1205         // User should now be a group member
    1206         $member = groups_is_user_member( $u1, $g1 );
    1207         $this->assertTrue( is_numeric( $member ) && $member > 0 );
    1208     }
    1209 
    1210     /**
    1211      * @group groups_send_invites
    1212      * @group group_invitations
    1213      * @group group_membership_requests
    1214      * @group group_membership
    1215      */
    1216     public function test_groups_membership_request_plus_invite_equals_member() {
    1217         $u1 = $this->factory->user->create();
    1218         $u2 = $this->factory->user->create();
    1219         $g1 = $this->factory->group->create( array( 'creator_id' => $u1 ) );
    1220 
    1221         // Create membership request
    1222         groups_send_membership_request( $u2, $g1 );
     1153     * @group groups_get_invites_for_group
     1154     * @group group_send_invites
     1155     * @group group_invitations
     1156     * @group group_membership
     1157     */
     1158    public function test_groups_get_invites_for_group_with_sent_parameter() {
     1159        $u1 = $this->factory->user->create();
     1160        $u2 = $this->factory->user->create();
     1161        $g1 = $this->factory->group->create( array( 'creator_id' => $u1 ) );
    12231162
    12241163        // Create draft invitation
     
    12311170        ) );
    12321171
     1172        // Send the invitation; this will set the 'invite_sent' value to 1.
     1173        groups_send_invites( $u1, $g1 );
     1174
     1175        // Default groups_get_invites_for_group() call
     1176        $i = groups_get_invites_for_group( $u1, $g1 );
     1177        $this->assertEqualSets( array( $u2 ), $i );
     1178
     1179        // Fetch users whose invites have been sent out; should be the same as above.
     1180        $i = groups_get_invites_for_group( $u1, $g1 );
     1181        $this->assertEqualSets( array( $u2 ), $i );
     1182
     1183        // Fetch users whose invites haven't been sent yet.
     1184        $i = groups_get_invites_for_group( $u1, $g1, 0 );
     1185        $this->assertEmpty( $i );
     1186    }
     1187
     1188    /**
     1189     * @group groups_send_membership_request
     1190     * @group group_membership_requests
     1191     * @group group_membership
     1192     */
     1193    public function test_groups_send_membership_request() {
     1194        $u1 = $this->factory->user->create();
     1195        $g1 = $this->factory->group->create();
     1196
     1197        // Create membership request
     1198        groups_send_membership_request( $u1, $g1 );
     1199
     1200        $request = groups_check_for_membership_request( $u1, $g1 );
     1201        $this->assertTrue( is_numeric( $request ) && $request > 0 );
     1202    }
     1203
     1204    /**
     1205     * @group groups_accept_membership_request
     1206     * @group group_membership_requests
     1207     * @group group_membership
     1208     */
     1209    public function test_groups_accept_membership_request_by_membership_id() {
     1210        $u1 = $this->factory->user->create();
     1211        $g1 = $this->factory->group->create();
     1212
     1213        // Create membership request
     1214        groups_send_membership_request( $u1, $g1 );
     1215
     1216        // Get group invitations of any type, from any user in the group.
     1217        $member = new BP_Groups_Member( $u1, $g1 );
     1218
     1219        groups_accept_membership_request( $member->id );
     1220
     1221        // User should now be a group member.
     1222        $member = groups_is_user_member( $u1, $g1 );
     1223
     1224        $this->assertTrue( is_numeric( $member ) && $member > 0 );
     1225    }
     1226
     1227    /**
     1228     * @group groups_accept_membership_request
     1229     * @group group_membership_requests
     1230     * @group group_membership
     1231     */
     1232    public function test_groups_accept_membership_request_by_user_id_group_id() {
     1233        $u1 = $this->factory->user->create();
     1234        $g1 = $this->factory->group->create();
     1235
     1236        // Create membership request
     1237        groups_send_membership_request( $u1, $g1 );
     1238
     1239        groups_accept_membership_request( null, $u1, $g1 );
     1240
     1241        // User should now be a group member
     1242        $member = groups_is_user_member( $u1, $g1 );
     1243        $this->assertTrue( is_numeric( $member ) && $member > 0 );
     1244    }
     1245
     1246    /**
     1247     * @group groups_send_invites
     1248     * @group group_invitations
     1249     * @group group_membership_requests
     1250     * @group group_membership
     1251     */
     1252    public function test_groups_membership_request_plus_invite_equals_member() {
     1253        $u1 = $this->factory->user->create();
     1254        $u2 = $this->factory->user->create();
     1255        $g1 = $this->factory->group->create( array( 'creator_id' => $u1 ) );
     1256
     1257        // Create membership request
     1258        groups_send_membership_request( $u2, $g1 );
     1259
     1260        // Create draft invitation
     1261        groups_invite_user( array(
     1262            'user_id'       => $u2,
     1263            'group_id'      => $g1,
     1264            'inviter_id'    => $u1,
     1265            'date_modified' => bp_core_current_time(),
     1266            'is_confirmed'  => 0
     1267        ) );
     1268
    12331269        // Send the invitation
    12341270        groups_send_invites( $u1, $g1 );
Note: See TracChangeset for help on using the changeset viewer.