Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
09/09/2011 03:06:13 PM (14 years ago)
Author:
boonebgorges
Message:

Reworks the way that total topic counts are retrieved on user forum pages. See #3557

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/bp-forums/bp-forums-functions.php

    r5112 r5129  
    291291}
    292292
    293 function bp_forums_total_topic_count_for_user( $user_id = 0 ) {
     293/**
     294 * Get a total "Topics Started" count for a given user
     295 *
     296 * @package BuddyPress
     297 *
     298 * @param int $user_id ID of the user being queried. Falls back on displayed user, then loggedin
     299 * @param str $type The current filter/sort type. 'active', 'popular', 'unreplied'
     300 * @return int $count The topic count
     301 */
     302function bp_forums_total_topic_count_for_user( $user_id = 0, $type = 'active' ) {
    294303    global $bp;
    295304
     
    300309
    301310    if ( class_exists( 'BB_Query' ) ) {
    302         $query = new BB_Query( 'topic', array( 'topic_author_id' => $user_id, 'page' => 1, 'per_page' => -1, 'count' => true ) );
     311        $args = array(
     312            'topic_author_id' => $user_id,
     313            'page'        => 1,
     314            'per_page'    => -1,
     315            'count'       => true
     316        );
     317
     318        if ( 'unreplied' == $type )
     319            $args['post_count'] = 1;
     320
     321        $query = new BB_Query( 'topic', $args );
    303322        $count = $query->count;
    304323        $query = null;
     
    321340 * @return int $count
    322341 */
    323 function bp_forums_total_replied_count_for_user( $user_id = 0 ) {
     342function bp_forums_total_replied_count_for_user( $user_id = 0, $type = 'active' ) {
    324343    global $bp;
    325344
     
    341360                $topics[] = $result->topic_id;
    342361        }
    343         $count = count( $topics );
     362
     363        // Even more unfortunate. If this is filtered by 'unreplied', we have to requery
     364        if ( 'unreplied' == $type ) {
     365            $topic_ids = implode( ',', $topics );
     366            $topics_query = new BB_Query( 'topic', array( 'topic_id' => $topic_ids, 'page' => 1, 'per_page' => -1, 'post_count' => 1 ) );
     367            $count = count( $topics_query->results );
     368        } else {
     369            $count = count( $topics );
     370        }
    344371        $query = null;
    345372    } else {
Note: See TracChangeset for help on using the changeset viewer.