Skip to:
Content

BuddyPress.org

Changeset 5129


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

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

Location:
trunk/bp-forums
Files:
3 edited

Legend:

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

    r5093 r5129  
    201201    $sql .= $wpdb->prepare( " AND p.poster_id = %s ", bp_displayed_user_id() );
    202202
     203    // Remove any topic_author information
     204    $sql = str_replace( " AND t.topic_poster = '" . bp_displayed_user_id() . "'", '', $sql );
     205
    203206    return $sql;
    204207}
  • 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 {
  • trunk/bp-forums/bp-forums-template.php

    r5112 r5129  
    137137            $this->total_topic_count = 0;
    138138        } else {
     139            // Get a total topic count, for use in pagination. This value will differ
     140            // depending on scope
    139141            if ( !empty( $forum_id ) ) {
     142                // Group forums
    140143                $topic_count = bp_forums_get_forum( $forum_id );
    141144                $topic_count = (int)$topic_count->topics;
    142145            } else if ( !empty( $bp->groups->current_group ) ) {
    143146                $topic_count = (int)groups_total_public_forum_topic_count( $type );
    144             } else if ( bp_is_user_forums_started() ) {
    145                 $topic_count = bp_forums_total_topic_count_for_user( bp_displayed_user_id() );
     147            } else if ( bp_is_user_forums_started() || ( bp_is_directory() && $user_id ) ) {
     148                // This covers the case of Profile > Forums > Topics Started, as
     149                // well as Forum Directory > My Topics
     150                $topic_count = bp_forums_total_topic_count_for_user( bp_displayed_user_id(), $type );
    146151            } else if ( bp_is_user_forums_replied_to() ) {
    147                 $topic_count = bp_forums_total_replied_count_for_user( bp_displayed_user_id() );
     152                // Profile > Forums > Replied To
     153                $topic_count = bp_forums_total_replied_count_for_user( bp_displayed_user_id(), $type );
    148154            } else {
    149                 // For forum directories, get a true count
     155                // For forum directories (All Topics), get a true count
    150156                $status = is_super_admin() ? 'all' : 'public'; // todo: member-of
    151157                $topic_count = (int)groups_total_forum_topic_count( $status, $search_terms );
Note: See TracChangeset for help on using the changeset viewer.