Skip to:
Content

BuddyPress.org

Changeset 8057


Ignore:
Timestamp:
03/06/2014 02:32:19 AM (11 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.

Location:
trunk/bp-groups
Files:
3 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
  • trunk/bp-groups/bp-groups-functions.php

    r8056 r8057  
    664664}
    665665
     666/**
     667 * Gets the total group invite count for a user.
     668 *
     669 * @since BuddyPress (2.0.0)
     670 *
     671 * @param int $user_id The user ID
     672 * @return int
     673 */
     674function groups_get_invite_count_for_user( $user_id = 0 ) {
     675    if ( empty( $user_id ) ) {
     676        $user_id = bp_loggedin_user_id();
     677    }
     678
     679    return BP_Groups_Member::get_invite_count_for_user( $user_id );
     680}
     681
    666682function groups_invite_user( $args = '' ) {
    667683
  • trunk/bp-groups/bp-groups-loader.php

    r8056 r8057  
    537537
    538538            // Pending group invites
    539             $count   = groups_get_invites_for_user( bp_loggedin_user_id() );
     539            $count   = groups_get_invite_count_for_user();
    540540            $title   = __( 'Groups',             'buddypress' );
    541541            $pending = __( 'No Pending Invites', 'buddypress' );
    542542
    543543            if ( !empty( $count['total'] ) ) {
    544                 $title   = sprintf( __( 'Groups <span class="count">%s</span>',          'buddypress' ), $count['total'] );
    545                 $pending = sprintf( __( 'Pending Invites <span class="count">%s</span>', 'buddypress' ), $count['total'] );
     544                $title   = sprintf( __( 'Groups <span class="count">%s</span>',          'buddypress' ), $count );
     545                $pending = sprintf( __( 'Pending Invites <span class="count">%s</span>', 'buddypress' ), $count );
    546546            }
    547547
Note: See TracChangeset for help on using the changeset viewer.