Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
03/06/2014 02:32:19 AM (10 years ago)
Author:
r-a-y
Message:

Groups: Introduces new function - groups_get_invite_count_for_user().

Previously, BP_Groups_Member::get_invites() did two queries -- one to
get a paginated array of group invites for a user and the second to
get the total group invite count for a user.

This commit:

  • Splits up the total group invite count query into a separate class method - BP_Group_Member::get_invite_count_for_user()
  • Adds a wrapper function - groups_get_invite_count_for_user() - and uses it in the BP_Groups_Component class where the invite count is only needed.

The group invite count will be cached in a future commit.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/bp-groups/bp-groups-classes.php

    r8056 r8057  
    23162316
    23172317        $paged_groups = $wpdb->get_results( $wpdb->prepare( "SELECT g.*, gm1.meta_value as total_member_count, gm2.meta_value as last_activity FROM {$bp->groups->table_name_groupmeta} gm1, {$bp->groups->table_name_groupmeta} gm2, {$bp->groups->table_name_members} m, {$bp->groups->table_name} g WHERE g.id = m.group_id AND g.id = gm1.group_id AND g.id = gm2.group_id AND gm2.meta_key = 'last_activity' AND gm1.meta_key = 'total_member_count' AND m.is_confirmed = 0 AND m.inviter_id != 0 AND m.invite_sent = 1 AND m.user_id = %d {$exclude_sql} ORDER BY m.date_modified ASC {$pag_sql}", $user_id ) );
    2318         $total_groups = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(DISTINCT m.group_id) FROM {$bp->groups->table_name_members} m, {$bp->groups->table_name} g WHERE m.group_id = g.id AND m.is_confirmed = 0 AND m.inviter_id != 0 AND m.invite_sent = 1 AND m.user_id = %d {$exclude_sql} ORDER BY date_modified ASC", $user_id ) );
    2319 
    2320         return array( 'groups' => $paged_groups, 'total' => $total_groups );
     2318
     2319        return array( 'groups' => $paged_groups, 'total' => self::get_invite_count_for_user( $user_id ) );
     2320    }
     2321
     2322    /**
     2323     * Gets the total group invite count for a user.
     2324     *
     2325     * @since BuddyPress (2.0.0)
     2326     *
     2327     * @param int $user_id The user ID
     2328     * @return int
     2329     */
     2330    public static function get_invite_count_for_user( $user_id = 0 ) {
     2331        global $wpdb;
     2332
     2333        return (int) $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(DISTINCT m.group_id) FROM {$bp->groups->table_name_members} m, {$bp->groups->table_name} g WHERE m.group_id = g.id AND m.is_confirmed = 0 AND m.inviter_id != 0 AND m.invite_sent = 1 AND m.user_id = %d {$exclude_sql} ORDER BY date_modified ASC", $user_id ) );
    23212334    }
    23222335
Note: See TracChangeset for help on using the changeset viewer.