- Timestamp:
- 11/02/2015 02:07:44 AM (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/bp-friends/classes/class-bp-friends-friendship.php
r10248 r10323 149 149 do_action_ref_array( 'friends_friendship_before_save', array( &$this ) ); 150 150 151 // Update 151 // Update. 152 152 if (!empty( $this->id ) ) { 153 153 $result = $wpdb->query( $wpdb->prepare( "UPDATE {$bp->friends->table_name} SET initiator_user_id = %d, friend_user_id = %d, is_confirmed = %d, is_limited = %d, date_created = %s WHERE id = %d", $this->initiator_user_id, $this->friend_user_id, $this->is_confirmed, $this->is_limited, $this->date_created, $this->id ) ); 154 154 155 // Save 155 // Save. 156 156 } else { 157 157 $result = $wpdb->query( $wpdb->prepare( "INSERT INTO {$bp->friends->table_name} ( initiator_user_id, friend_user_id, is_confirmed, is_limited, date_created ) VALUES ( %d, %d, %d, %d, %s )", $this->initiator_user_id, $this->friend_user_id, $this->is_confirmed, $this->is_limited, $this->date_created ) ); … … 171 171 } 172 172 173 /** 174 * Delete the current friendship from the database. 175 * 176 * @return bool|int 177 */ 173 178 public function delete() { 174 179 global $wpdb; … … 190 195 * keyed as 'user_id' => $user_id; false to get a one-dimensional 191 196 * array of user IDs. Default: false. 192 *193 197 * @return array $fids IDs of friends for provided user. 194 198 */ … … 224 228 * @param int $user_id The ID of the first user. 225 229 * @param int $friend_id The ID of the second user. 226 *227 230 * @return int|bool The ID of the friendship object if found, otherwise false. 228 231 */ … … 240 243 * @param int $user_id The ID of the user who has received the 241 244 * friendship requests. 242 *243 245 * @return array|bool An array of user IDs, or false if none are found. 244 246 */ … … 265 267 * are counting. Default: displayed user (if any), otherwise 266 268 * logged-in user. 267 *268 269 * @return int Friend count for the user. 269 270 */ … … 276 277 $bp = buddypress(); 277 278 278 /* This is stored in 'total_friend_count' usermeta. 279 This function will recalculate, update and return. */ 279 /* 280 * This is stored in 'total_friend_count' usermeta. 281 * This function will recalculate, update and return. 282 */ 280 283 281 284 $count = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(id) FROM {$bp->friends->table_name} WHERE (initiator_user_id = %d OR friend_user_id = %d) AND is_confirmed = 1", $user_id, $user_id ) ); 282 285 283 // Do not update meta if user has never had friends 286 // Do not update meta if user has never had friends. 284 287 if ( empty( $count ) && !bp_get_user_meta( $user_id, 'total_friend_count', true ) ) 285 288 return 0; … … 309 312 global $wpdb; 310 313 311 // TODO: Optimize this function. 314 /* 315 * TODO: Optimize this function. 316 */ 312 317 313 318 if ( empty( $user_id ) ) … … 315 320 316 321 // Only search for matching strings at the beginning of the 317 // name (@todo - figure out why this restriction) 322 // name (@todo - figure out why this restriction). 318 323 $search_terms_like = bp_esc_like( $filter ) . '%'; 319 324 … … 333 338 $bp = buddypress(); 334 339 335 // filter the user_ids based on the search criteria.340 // Filter the user_ids based on the search criteria. 336 341 if ( bp_is_active( 'xprofile' ) ) { 337 342 $sql = $wpdb->prepare( "SELECT DISTINCT user_id FROM {$bp->profile->table_name_data} WHERE user_id IN ({$fids}) AND value LIKE %s {$pag_sql}", $search_terms_like ); … … 357 362 * request to $possible_friend_userid that has not yet been approved, 358 363 * while 'awaiting_response' is the other way around ($possible_friend_userid 359 * sent the initial request) 364 * sent the initial request). 360 365 * 361 366 * @param int $initiator_userid The ID of the user who is the initiator … … 363 368 * @param int $possible_friend_userid The ID of the user who is the 364 369 * recipient of the potential friendship/request. 365 *366 370 * @return string $value The friendship status, from among 'not_friends', 367 371 * 'is_friend', 'pending', and 'awaiting_response'. … … 398 402 * @param array $user_ids IDs of users whose last_active meta is 399 403 * being queried. 400 *401 404 * @return array $retval Array of last_active values + user_ids. 402 405 */ … … 406 409 $last_activities = BP_Core_User::get_last_activity( $user_ids ); 407 410 408 // Sort and structure as expected in legacy function 411 // Sort and structure as expected in legacy function. 409 412 usort( $last_activities, create_function( '$a, $b', ' 410 413 if ( $a["date_recorded"] == $b["date_recorded"] ) { … … 431 434 * 432 435 * @param int $friendship_id ID of the friendship to be accepted. 433 *434 436 * @return int Number of database rows updated. 435 437 */ … … 446 448 * 447 449 * @param int $friendship_id ID of the friendship to be withdrawn. 448 *449 450 * @return int Number of database rows deleted. 450 451 */ … … 461 462 * 462 463 * @param int $friendship_id ID of the friendship to be rejected. 463 *464 464 * @return int Number of database rows deleted. 465 465 */ … … 482 482 * @param int $page Optional. Number of the page to return. Default: 483 483 * false (no pagination - return all results). 484 *485 484 * @return array $filtered_ids IDs of users who match the query. 486 485 */ … … 489 488 490 489 // Only search for matching strings at the beginning of the 491 // name (@todo - figure out why this restriction) 490 // name (@todo - figure out why this restriction). 492 491 $search_terms_like = bp_esc_like( $filter ) . '%'; 493 492 … … 501 500 $bp = buddypress(); 502 501 503 // filter the user_ids based on the search criteria.502 // Filter the user_ids based on the search criteria. 504 503 if ( bp_is_active( 'xprofile' ) ) { 505 504 $sql = $wpdb->prepare( "SELECT DISTINCT d.user_id as id FROM {$bp->profile->table_name_data} d, {$users_table} u WHERE d.user_id = u.id AND d.value LIKE %s ORDER BY d.value DESC {$pag_sql}", $search_terms_like ); … … 522 521 * 523 522 * @param string $filter Search term. 524 *525 523 * @return int Count of users matching the search term. 526 524 */ … … 529 527 530 528 // Only search for matching strings at the beginning of the 531 // name (@todo - figure out why this restriction) 529 // name (@todo - figure out why this restriction). 532 530 $search_terms_like = bp_esc_like( $filter ) . '%'; 533 531 … … 537 535 $bp = buddypress(); 538 536 539 // filter the user_ids based on the search criteria.537 // Filter the user_ids based on the search criteria. 540 538 if ( bp_is_active( 'xprofile' ) ) { 541 539 $sql = $wpdb->prepare( "SELECT COUNT(DISTINCT d.user_id) FROM {$bp->profile->table_name_data} d, {$users_table} u WHERE d.user_id = u.id AND d.value LIKE %s", $search_terms_like ); … … 558 556 * 559 557 * @param array $user_ids Array of user IDs. 560 *561 558 * @return array User IDs, sorted by the associated display names. 562 559 */ … … 580 577 * @param int $total_friends Optional. Number of random friends to get. 581 578 * Default: 5. 582 *583 579 * @return array|bool An array of random friend user IDs on success; 584 580 * false if none are found. … … 596 592 } 597 593 598 // remove duplicates594 // Remove duplicates. 599 595 if ( count( $fids ) > 0 ) 600 596 return array_flip( array_flip( $fids ) ); … … 614 610 * @param int $user_id ID of the user whose friends are being counted. 615 611 * @param int $group_id ID of the group friends are being invited to. 616 *617 612 * @return int $invitable_count Eligible friend count. 618 613 */ 619 614 public static function get_invitable_friend_count( $user_id, $group_id ) { 620 615 621 // Setup some data we'll use below 616 // Setup some data we'll use below. 622 617 $is_group_admin = BP_Groups_Member::check_is_admin( $user_id, $group_id ); 623 618 $friend_ids = BP_Friends_Friendship::get_friend_user_ids( $user_id ); … … 626 621 for ( $i = 0, $count = count( $friend_ids ); $i < $count; ++$i ) { 627 622 628 // If already a member, they cannot be invited again 623 // If already a member, they cannot be invited again. 629 624 if ( BP_Groups_Member::check_is_member( (int) $friend_ids[$i], $group_id ) ) 630 625 continue; 631 626 632 // If user already has invite, they cannot be added 627 // If user already has invite, they cannot be added. 633 628 if ( BP_Groups_Member::check_has_invite( (int) $friend_ids[$i], $group_id ) ) 634 629 continue; 635 630 636 // If user is not group admin and friend is banned, they cannot be invited 631 // If user is not group admin and friend is banned, they cannot be invited. 637 632 if ( ( false === $is_group_admin ) && BP_Groups_Member::check_is_banned( (int) $friend_ids[$i], $group_id ) ) 638 633 continue; … … 648 643 * 649 644 * @param int $friendship_id ID of the friendship. 650 *651 645 * @return object friend_user_id and initiator_user_id. 652 646 */ … … 669 663 $bp = buddypress(); 670 664 671 // Get friends of $user_id 665 // Get friends of $user_id. 672 666 $friend_ids = BP_Friends_Friendship::get_friend_user_ids( $user_id ); 673 667 674 // Delete all friendships related to $user_id 668 // Delete all friendships related to $user_id. 675 669 $wpdb->query( $wpdb->prepare( "DELETE FROM {$bp->friends->table_name} WHERE friend_user_id = %d OR initiator_user_id = %d", $user_id, $user_id ) ); 676 670 … … 681 675 } 682 676 683 // Loop through friend_ids and update their counts 677 // Loop through friend_ids and update their counts. 684 678 foreach ( (array) $friend_ids as $friend_id ) { 685 679 BP_Friends_Friendship::total_friend_count( $friend_id );
Note: See TracChangeset
for help on using the changeset viewer.