Ticket #7397: 7397.01.patch
File 7397.01.patch, 6.1 KB (added by , 8 years ago) |
---|
-
src/bp-groups/bp-groups-functions.php
1508 1508 * Send all pending invites by a single user to a specific group. 1509 1509 * 1510 1510 * @since 1.0.0 1511 * @since 2.8.0 Added $omit_sent as a parameter. 1511 1512 * 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. 1514 1518 */ 1515 function groups_send_invites( $user_id, $group_id ) {1519 function groups_send_invites( $user_id, $group_id, $omit_sent = false ) { 1516 1520 1517 if ( empty( $user_id ) ) 1521 if ( empty( $user_id ) ) { 1518 1522 $user_id = bp_loggedin_user_id(); 1523 } 1524 1525 if ( true === $omit_sent ) { 1526 $sent = 0; 1527 } else { 1528 $sent = null; 1529 } 1519 1530 1520 1531 // 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 ); 1522 1533 $group = groups_get_group( $group_id ); 1523 1534 1524 1535 for ( $i = 0, $count = count( $invited_users ); $i < $count; ++$i ) { … … 1548 1559 * Get IDs of users with outstanding invites to a given group from a specified user. 1549 1560 * 1550 1561 * @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 */ 1573 function groups_get_invites_for_group( $user_id, $group_id, $sent = null ) { 1574 return BP_Groups_Group::get_invites( $user_id, $group_id, $sent ); 1559 1575 } 1560 1576 1561 1577 /** -
src/bp-groups/classes/class-bp-groups-group.php
648 648 * Get IDs of users with outstanding invites to a given group from a specified user. 649 649 * 650 650 * @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. 656 661 */ 657 public static function get_invites( $user_id, $group_id ) {662 public static function get_invites( $user_id, $group_id, $sent = null ) { 658 663 global $wpdb; 659 664 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 } 661 672 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 ); 663 674 } 664 675 665 676 /** -
tests/phpunit/testcases/groups/class-bp-groups-member.php
1150 1150 } 1151 1151 1152 1152 /** 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 /** 1153 1189 * @group groups_send_membership_request 1154 1190 * @group group_membership_requests 1155 1191 * @group group_membership