Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
11/02/2015 02:07:44 AM (8 years ago)
Author:
tw2113
Message:

More docs cleanup for Friends component.

See #6400.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/bp-friends/classes/class-bp-friends-friendship.php

    r10248 r10323  
    149149        do_action_ref_array( 'friends_friendship_before_save', array( &$this ) );
    150150
    151         // Update
     151        // Update.
    152152        if (!empty( $this->id ) ) {
    153153            $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 ) );
    154154
    155         // Save
     155        // Save.
    156156        } else {
    157157            $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 ) );
     
    171171    }
    172172
     173    /**
     174     * Delete the current friendship from the database.
     175     *
     176     * @return bool|int
     177     */
    173178    public function delete() {
    174179        global $wpdb;
     
    190195     *                                   keyed as 'user_id' => $user_id; false to get a one-dimensional
    191196     *                                   array of user IDs. Default: false.
    192      *
    193197     * @return array $fids IDs of friends for provided user.
    194198     */
     
    224228     * @param int $user_id   The ID of the first user.
    225229     * @param int $friend_id The ID of the second user.
    226      *
    227230     * @return int|bool The ID of the friendship object if found, otherwise false.
    228231     */
     
    240243     * @param int $user_id The ID of the user who has received the
    241244     *                     friendship requests.
    242      *
    243245     * @return array|bool An array of user IDs, or false if none are found.
    244246     */
     
    265267     *                     are counting. Default: displayed user (if any), otherwise
    266268     *                     logged-in user.
    267      *
    268269     * @return int Friend count for the user.
    269270     */
     
    276277        $bp = buddypress();
    277278
    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         */
    280283
    281284        $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 ) );
    282285
    283         // Do not update meta if user has never had friends
     286        // Do not update meta if user has never had friends.
    284287        if ( empty( $count ) && !bp_get_user_meta( $user_id, 'total_friend_count', true ) )
    285288            return 0;
     
    309312        global $wpdb;
    310313
    311         // TODO: Optimize this function.
     314        /*
     315         * TODO: Optimize this function.
     316         */
    312317
    313318        if ( empty( $user_id ) )
     
    315320
    316321        // 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).
    318323        $search_terms_like = bp_esc_like( $filter ) . '%';
    319324
     
    333338        $bp = buddypress();
    334339
    335         // filter the user_ids based on the search criteria.
     340        // Filter the user_ids based on the search criteria.
    336341        if ( bp_is_active( 'xprofile' ) ) {
    337342            $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 );
     
    357362     * request to $possible_friend_userid that has not yet been approved,
    358363     * while 'awaiting_response' is the other way around ($possible_friend_userid
    359      * sent the initial request)
     364     * sent the initial request).
    360365     *
    361366     * @param int $initiator_userid       The ID of the user who is the initiator
     
    363368     * @param int $possible_friend_userid The ID of the user who is the
    364369     *                                    recipient of the potential friendship/request.
    365      *
    366370     * @return string $value The friendship status, from among 'not_friends',
    367371     *                       'is_friend', 'pending', and 'awaiting_response'.
     
    398402     * @param array $user_ids IDs of users whose last_active meta is
    399403     *                        being queried.
    400      *
    401404     * @return array $retval Array of last_active values + user_ids.
    402405     */
     
    406409        $last_activities = BP_Core_User::get_last_activity( $user_ids );
    407410
    408         // Sort and structure as expected in legacy function
     411        // Sort and structure as expected in legacy function.
    409412        usort( $last_activities, create_function( '$a, $b', '
    410413            if ( $a["date_recorded"] == $b["date_recorded"] ) {
     
    431434     *
    432435     * @param int $friendship_id ID of the friendship to be accepted.
    433      *
    434436     * @return int Number of database rows updated.
    435437     */
     
    446448     *
    447449     * @param int $friendship_id ID of the friendship to be withdrawn.
    448      *
    449450     * @return int Number of database rows deleted.
    450451     */
     
    461462     *
    462463     * @param int $friendship_id ID of the friendship to be rejected.
    463      *
    464464     * @return int Number of database rows deleted.
    465465     */
     
    482482     * @param int    $page    Optional. Number of the page to return. Default:
    483483     *                        false (no pagination - return all results).
    484      *
    485484     * @return array $filtered_ids IDs of users who match the query.
    486485     */
     
    489488
    490489        // 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).
    492491        $search_terms_like = bp_esc_like( $filter ) . '%';
    493492
     
    501500        $bp = buddypress();
    502501
    503         // filter the user_ids based on the search criteria.
     502        // Filter the user_ids based on the search criteria.
    504503        if ( bp_is_active( 'xprofile' ) ) {
    505504            $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 );
     
    522521     *
    523522     * @param string $filter Search term.
    524      *
    525523     * @return int Count of users matching the search term.
    526524     */
     
    529527
    530528        // 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).
    532530        $search_terms_like = bp_esc_like( $filter ) . '%';
    533531
     
    537535        $bp = buddypress();
    538536
    539         // filter the user_ids based on the search criteria.
     537        // Filter the user_ids based on the search criteria.
    540538        if ( bp_is_active( 'xprofile' ) ) {
    541539            $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 );
     
    558556     *
    559557     * @param array $user_ids Array of user IDs.
    560      *
    561558     * @return array User IDs, sorted by the associated display names.
    562559     */
     
    580577     * @param int $total_friends Optional. Number of random friends to get.
    581578     *                           Default: 5.
    582      *
    583579     * @return array|bool An array of random friend user IDs on success;
    584580     *                    false if none are found.
     
    596592        }
    597593
    598         // remove duplicates
     594        // Remove duplicates.
    599595        if ( count( $fids ) > 0 )
    600596            return array_flip( array_flip( $fids ) );
     
    614610     * @param int $user_id  ID of the user whose friends are being counted.
    615611     * @param int $group_id ID of the group friends are being invited to.
    616      *
    617612     * @return int $invitable_count Eligible friend count.
    618613     */
    619614    public static function get_invitable_friend_count( $user_id, $group_id ) {
    620615
    621         // Setup some data we'll use below
     616        // Setup some data we'll use below.
    622617        $is_group_admin  = BP_Groups_Member::check_is_admin( $user_id, $group_id );
    623618        $friend_ids      = BP_Friends_Friendship::get_friend_user_ids( $user_id );
     
    626621        for ( $i = 0, $count = count( $friend_ids ); $i < $count; ++$i ) {
    627622
    628             // If already a member, they cannot be invited again
     623            // If already a member, they cannot be invited again.
    629624            if ( BP_Groups_Member::check_is_member( (int) $friend_ids[$i], $group_id ) )
    630625                continue;
    631626
    632             // If user already has invite, they cannot be added
     627            // If user already has invite, they cannot be added.
    633628            if ( BP_Groups_Member::check_has_invite( (int) $friend_ids[$i], $group_id )  )
    634629                continue;
    635630
    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.
    637632            if ( ( false === $is_group_admin ) && BP_Groups_Member::check_is_banned( (int) $friend_ids[$i], $group_id ) )
    638633                continue;
     
    648643     *
    649644     * @param int $friendship_id ID of the friendship.
    650      *
    651645     * @return object friend_user_id and initiator_user_id.
    652646     */
     
    669663        $bp = buddypress();
    670664
    671         // Get friends of $user_id
     665        // Get friends of $user_id.
    672666        $friend_ids = BP_Friends_Friendship::get_friend_user_ids( $user_id );
    673667
    674         // Delete all friendships related to $user_id
     668        // Delete all friendships related to $user_id.
    675669        $wpdb->query( $wpdb->prepare( "DELETE FROM {$bp->friends->table_name} WHERE friend_user_id = %d OR initiator_user_id = %d", $user_id, $user_id ) );
    676670
     
    681675        }
    682676
    683         // Loop through friend_ids and update their counts
     677        // Loop through friend_ids and update their counts.
    684678        foreach ( (array) $friend_ids as $friend_id ) {
    685679            BP_Friends_Friendship::total_friend_count( $friend_id );
Note: See TracChangeset for help on using the changeset viewer.