Skip to:
Content

BuddyPress.org

Changeset 2182


Ignore:
Timestamp:
12/15/2009 02:37:11 PM (17 years ago)
Author:
apeatling
Message:

Fixing messaging pagination counts.

Location:
trunk/bp-messages
Files:
2 edited

Legend:

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

    r2114 r2182  
    191191                        $type_sql = $wpdb->prepare( " AND r.unread_count = 0 " );
    192192
    193                 $sql = $wpdb->prepare( "SELECT r.thread_id FROM {$bp->messages->table_name_recipients} r, {$bp->messages->table_name_threads} t WHERE t.id = r.thread_id AND r.is_deleted = 0 AND r.user_id = %d$exclude_sender $type_sql ORDER BY t.last_post_date DESC$pag_sql", $bp->loggedin_user->id );
    194 
    195                 if ( !$thread_ids = $wpdb->get_results($sql) )
    196                         return false;
     193                $exclude_sender = false;
     194                if ( 'inbox' == $box )
     195                        $exclude_sender = $wpdb->prepare( " AND r.sender_only = 0" );
     196
     197                $thread_ids = $wpdb->get_col( $wpdb->prepare( "SELECT r.thread_id FROM {$bp->messages->table_name_recipients} r, {$bp->messages->table_name_threads} t WHERE t.id = r.thread_id AND r.is_deleted = 0 AND r.user_id = %d$exclude_sender $type_sql ORDER BY t.last_post_date DESC$pag_sql", $bp->loggedin_user->id ) );
     198                $total_threads = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(r.thread_id) FROM {$bp->messages->table_name_recipients} r, {$bp->messages->table_name_threads} t WHERE t.id = r.thread_id AND r.is_deleted = 0 AND r.user_id = %d$exclude_sender $type_sql", $bp->loggedin_user->id ) );
    197199
    198200                $threads = false;
    199 
    200                 for ( $i = 0; $i < count($thread_ids); $i++ ) {
    201                         $threads[$i] = new BP_Messages_Thread( $thread_ids[$i]->thread_id, false, $box );
    202 
    203                         if ( !$threads[$i]->message_ids )
    204                                 unset($threads[$i]);
    205                 }
    206 
    207                 // reset keys
    208                 return array_reverse( array_reverse( $threads ) );
     201                foreach ( $thread_ids as $thread_id ) {
     202                        if ( 'sentbox' == $box && !BP_Messages_Thread::user_is_sender( $thread_id ) ) {
     203                                $total_threads--;
     204                                continue;
     205                        }
     206
     207                        $threads[] = new BP_Messages_Thread( $thread_id, false, $box );
     208                }
     209
     210                return array( 'threads' => &$threads, 'total' => (int)$total_threads );
    209211        }
    210212
     
    396398                                return false;
    397399
    398 
    399400                        $this->thread_id = $wpdb->insert_id;
    400401
     
    406407                        if ( !in_array( $this->sender_id, (array)$this->recipients ) ) {
    407408                                // Finally, add a recipient entry for the sender, as replies need to go to this person too.
    408                                 $wpdb->query( $wpdb->prepare( "INSERT INTO {$bp->messages->table_name_recipients} ( user_id, thread_id, unread_count, sender_only ) VALUES ( %d, %d, 0, 0 )", $this->sender_id, $this->thread_id ) );
     409                                $wpdb->query( $wpdb->prepare( "INSERT INTO {$bp->messages->table_name_recipients} ( user_id, thread_id, unread_count, sender_only ) VALUES ( %d, %d, 0, 1 )", $this->sender_id, $this->thread_id ) );
    409410                        }
    410411                }
  • trunk/bp-messages/bp-messages-templatetags.php

    r2168 r2182  
    2828                if ( 'notices' == $this->box )
    2929                        $this->threads = BP_Messages_Notice::get_notices();
    30                 else
    31                         $this->threads = BP_Messages_Thread::get_current_threads_for_user( $this->user_id, $this->box, $this->pag_num, $this->pag_page, $type );
     30                else {
     31                        $threads = BP_Messages_Thread::get_current_threads_for_user( $this->user_id, $this->box, $this->pag_num, $this->pag_page, $type );
     32
     33                        $this->threads = $threads['threads'];
     34                        $this->total_thread_count = $threads['total'];
     35                }
    3236
    3337                if ( !$this->threads ) {
     
    4044                                if ( 'notices' == $this->box )
    4145                                        $this->total_thread_count = (int)$total_notice_count;
    42                                 else
    43                                         $this->total_thread_count = (int)BP_Messages_Thread::get_total_threads_for_user( $this->user_id, $this->box, $type );
    4446                        } else {
    4547                                $this->total_thread_count = (int)$max;
     
    6163                        'total' => ceil($this->total_thread_count / $this->pag_num),
    6264                        'current' => $this->pag_page,
    63                         'prev_text' => '&laquo;',
    64                         'next_text' => '&raquo;',
     65                        'prev_text' => '&larr;',
     66                        'next_text' => '&rarr;',
    6567                        'mid_size' => 1
    6668                ));
Note: See TracChangeset for help on using the changeset viewer.