Skip to:
Content

BuddyPress.org

Ticket #7397: 7397.01.patch

File 7397.01.patch, 6.1 KB (added by r-a-y, 3 years ago)
  • src/bp-groups/bp-groups-functions.php

     
    15081508 * Send all pending invites by a single user to a specific group.
    15091509 *
    15101510 * @since 1.0.0
     1511 * @since 2.8.0 Added $omit_sent as a parameter.
    15111512 *
    1512  * @param int $user_id  ID of the inviting user.
    1513  * @param int $group_id ID of the group.
     1513 * @param int  $user_id   ID of the inviting user.
     1514 * @param int  $group_id  ID of the group.
     1515 * @param bool $omit_sent If true, we will not send invites to those we have already sent
     1516 *                        an invite to. If false, we will send an invite regardless of sent
     1517 *                        status.
    15141518 */
    1515 function groups_send_invites( $user_id, $group_id ) {
     1519function groups_send_invites( $user_id, $group_id, $omit_sent = false ) {
    15161520
    1517         if ( empty( $user_id ) )
     1521        if ( empty( $user_id ) ) {
    15181522                $user_id = bp_loggedin_user_id();
     1523        }
     1524
     1525        if ( true === $omit_sent ) {
     1526                $sent = 0;
     1527        } else {
     1528                $sent = null;
     1529        }
    15191530
    15201531        // Send friend invites.
    1521         $invited_users = groups_get_invites_for_group( $user_id, $group_id );
     1532        $invited_users = groups_get_invites_for_group( $user_id, $group_id, $sent );
    15221533        $group = groups_get_group( $group_id );
    15231534
    15241535        for ( $i = 0, $count = count( $invited_users ); $i < $count; ++$i ) {
     
    15481559 * Get IDs of users with outstanding invites to a given group from a specified user.
    15491560 *
    15501561 * @since 1.0.0
    1551  *
    1552  * @param int $user_id  ID of the inviting user.
    1553  * @param int $group_id ID of the group.
    1554  * @return array $value IDs of users who have been invited to the group by the
    1555  *                      user but have not yet accepted.
    1556  */
    1557 function groups_get_invites_for_group( $user_id, $group_id ) {
    1558         return BP_Groups_Group::get_invites( $user_id, $group_id );
     1562 * @since 2.8.0 Added $sent as a parameter.
     1563 *
     1564 * @param  int      $user_id  ID of the inviting user.
     1565 * @param  int      $group_id ID of the group.
     1566 * @param  int|null $sent     Query for a specific invite sent status. If 0, this will query for users
     1567 *                            that haven't had an invite sent to them yet. If 1, this will query for
     1568 *                            users that have had an invite sent to them. If null, no invite status will
     1569 *                            queried. Default: null.
     1570 * @return array    IDs of users who have been invited to the group by the user but have not
     1571 *                  yet accepted.
     1572 */
     1573function groups_get_invites_for_group( $user_id, $group_id, $sent = null ) {
     1574        return BP_Groups_Group::get_invites( $user_id, $group_id, $sent );
    15591575}
    15601576
    15611577/**
  • src/bp-groups/classes/class-bp-groups-group.php

     
    648648         * Get IDs of users with outstanding invites to a given group from a specified user.
    649649         *
    650650         * @since 1.6.0
    651          *
    652          * @param int $user_id ID of the inviting user.
    653          * @param int $group_id ID of the group.
    654          * @return array IDs of users who have been invited to the group by the
    655          *               user but have not yet accepted.
     651         * @since 2.8.0 Added $sent as a parameter.
     652         *
     653         * @param  int      $user_id  ID of the inviting user.
     654         * @param  int      $group_id ID of the group.
     655         * @param  int|null $sent     Query for a specific invite sent status. If 0, this will query for users
     656         *                            that haven't had an invite sent to them yet. If 1, this will query for
     657         *                            users that have had an invite sent to them. If null, no invite status will
     658         *                            queried. Default: null.
     659         * @return array    IDs of users who have been invited to the group by the user but have not
     660         *                  yet accepted.
    656661         */
    657         public static function get_invites( $user_id, $group_id ) {
     662        public static function get_invites( $user_id, $group_id, $sent = null ) {
    658663                global $wpdb;
    659664
    660                 $bp = buddypress();
     665                $bp  = buddypress();
     666                $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 );
     667
     668                // Query for a specific invite sent status.
     669                if ( ! is_null( $sent ) ) {
     670                        $sql .= $wpdb->prepare( ' AND invite_sent = %d', $sent );
     671                }
    661672
    662                 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 ) );
     673                return $wpdb->get_col( $sql );
    663674        }
    664675
    665676        /**
  • tests/phpunit/testcases/groups/class-bp-groups-member.php

     
    11501150        }
    11511151
    11521152        /**
     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 ) );
     1162
     1163                // Create draft invitation
     1164                groups_invite_user( array(
     1165                        'user_id'       => $u2,
     1166                        'group_id'      => $g1,
     1167                        'inviter_id'    => $u1,
     1168                        'date_modified' => bp_core_current_time(),
     1169                        'is_confirmed'  => 0
     1170                ) );
     1171
     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        /**
    11531189         * @group groups_send_membership_request
    11541190         * @group group_membership_requests
    11551191         * @group group_membership