Changeset 7374
- Timestamp:
- 09/07/2013 01:02:33 AM (12 years ago)
- Location:
- trunk
- Files:
-
- 3 edited
-
bp-friends/bp-friends-classes.php (modified) (1 diff)
-
bp-friends/bp-friends-template.php (modified) (1 diff)
-
tests/testcases/friends/class-bp-friends-friendship.php (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/bp-friends/bp-friends-classes.php
r7308 r7374 183 183 } 184 184 185 public static function check_is_friend( $loggedin_userid, $possible_friend_userid ) { 186 global $wpdb, $bp; 187 188 if ( empty( $loggedin_userid ) || empty( $possible_friend_userid ) ) 189 return false; 190 191 $result = $wpdb->get_results( $wpdb->prepare( "SELECT id, is_confirmed FROM {$bp->friends->table_name} WHERE (initiator_user_id = %d AND friend_user_id = %d) OR (initiator_user_id = %d AND friend_user_id = %d)", $loggedin_userid, $possible_friend_userid, $possible_friend_userid, $loggedin_userid ) ); 192 193 if ( !empty( $result ) ) { 185 /** 186 * Check friendship status between two users 187 * 188 * Note that 'pending' means that $initiator_userid has sent a friend 189 * request to $possible_friend_userid that has not yet been approved, 190 * while 'awaiting_response' is the other way around ($possible_friend_userid 191 * sent the initial request) 192 * 193 * @param int $initiator_userid The id of the user who is the initiator 194 * of the potential friendship/request. 195 * @param int $possible_friend_userid The id of the user who is the 196 * recipient of the potential friendship/request. 197 * @return string The friendship status, from among 'not_friends', 198 * 'is_friend', 'pending', and 'awaiting_response' 199 */ 200 public static function check_is_friend( $initiator_userid, $possible_friend_userid ) { 201 global $wpdb, $bp; 202 203 if ( empty( $initiator_userid ) || empty( $possible_friend_userid ) ) { 204 return false; 205 } 206 207 $result = $wpdb->get_results( $wpdb->prepare( "SELECT id, initiator_user_id, is_confirmed FROM {$bp->friends->table_name} WHERE (initiator_user_id = %d AND friend_user_id = %d) OR (initiator_user_id = %d AND friend_user_id = %d)", $initiator_userid, $possible_friend_userid, $possible_friend_userid, $initiator_userid ) ); 208 209 if ( ! empty( $result ) ) { 194 210 if ( 0 == (int) $result[0]->is_confirmed ) { 195 return 'pending';211 $status = $initiator_userid == $result[0]->initiator_user_id ? 'pending' : 'awaiting_response'; 196 212 } else { 197 return'is_friend';213 $status = 'is_friend'; 198 214 } 199 215 } else { 200 return 'not_friends'; 201 } 216 $status = 'not_friends'; 217 } 218 219 return $status; 202 220 } 203 221 -
trunk/bp-friends/bp-friends-template.php
r7228 r7374 291 291 break; 292 292 293 case 'awaiting_response' : 294 $button = array( 295 'id' => 'awaiting_response', 296 'component' => 'friends', 297 'must_be_logged_in' => true, 298 'block_self' => true, 299 'wrapper_class' => 'friendship-button awaiting_response_friend', 300 'wrapper_id' => 'friendship-button-' . $potential_friend_id, 301 'link_href' => bp_loggedin_user_domain() . bp_get_friends_slug() . '/requests/', 302 'link_text' => __( 'Friendship Requested', 'buddypress' ), 303 'link_title' => __( 'Friendship Requested', 'buddypress' ), 304 'link_id' => 'friend-' . $potential_friend_id, 305 'link_rel' => 'remove', 306 'link_class' => 'friendship-button awaiting_response_friend requested' 307 ); 308 break; 309 293 310 case 'is_friend' : 294 311 $button = array( -
trunk/tests/testcases/friends/class-bp-friends-friendship.php
r7039 r7374 78 78 } 79 79 80 /** 81 * @group check_is_friend 82 */ 83 public function test_check_is_friend_not_friends() { 84 $u1 = $this->create_user(); 85 $u2 = $this->create_user(); 86 $this->assertEquals( 'not_friends', BP_Friends_Friendship::check_is_friend( $u1, $u2 ) ); 87 } 80 88 89 /** 90 * @group check_is_friend 91 */ 92 public function test_check_is_friend_pending() { 93 $u1 = $this->create_user(); 94 $u2 = $this->create_user(); 95 friends_add_friend( $u1, $u2, false ); 96 $this->assertEquals( 'pending', BP_Friends_Friendship::check_is_friend( $u1, $u2 ) ); 97 } 81 98 99 /** 100 * @group check_is_friend 101 */ 102 public function test_check_is_friend_awaiting_response() { 103 $u1 = $this->create_user(); 104 $u2 = $this->create_user(); 105 friends_add_friend( $u1, $u2, false ); 106 $this->assertEquals( 'awaiting_response', BP_Friends_Friendship::check_is_friend( $u2, $u1 ) ); 107 } 108 109 /** 110 * @group check_is_friend 111 */ 112 public function test_check_is_friend_is_friend() { 113 $u1 = $this->create_user(); 114 $u2 = $this->create_user(); 115 friends_add_friend( $u1, $u2, true ); 116 $this->assertEquals( 'is_friend', BP_Friends_Friendship::check_is_friend( $u1, $u2 ) ); 117 } 82 118 }
Note: See TracChangeset
for help on using the changeset viewer.