Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
11/13/2021 06:54:07 PM (3 years ago)
Author:
espellcaste
Message:

Adding support to paginate messages/recipients to the BP_Messages_Box_Template class.

When querying threads using the BP_Messages_Box_Template class, one might set a default of messages/recipients, instead of returning all items.

Fixes #8597

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/bp-messages/classes/class-bp-messages-box-template.php

    r13108 r13148  
    8080
    8181    /**
    82      * The number of items being requested per page.
     82     * The number of items (threads) being requested per page.
    8383     *
    8484     * @var int
     
    112112        // Backward compatibility with old method of passing arguments.
    113113        if ( ! is_array( $args ) || count( $function_args ) > 1 ) {
    114             _deprecated_argument( __METHOD__, '2.2.0', sprintf( __( 'Arguments passed to %1$s should be in an associative array. See the inline documentation at %2$s for more details.', 'buddypress' ), __METHOD__, __FILE__ ) );
     114            _deprecated_argument(
     115                __METHOD__,
     116                '2.2.0',
     117                sprintf(
     118                    /* translators: 1: the name of the method. 2: the name of the file. */
     119                    esc_html__( 'Arguments passed to %1$s should be in an associative array. See the inline documentation at %2$s for more details.', 'buddypress' ),
     120                    __METHOD__,
     121                    __FILE__
     122                )
     123            );
    115124
    116125            $old_args_keys = array(
     
    121130                4 => 'type',
    122131                5 => 'search_terms',
    123                 6 => 'page_arg'
     132                6 => 'page_arg',
    124133            );
    125134
     
    130139            $args,
    131140            array(
    132                 'page'         => 1,
    133                 'per_page'     => 10,
    134                 'page_arg'     => 'mpage',
    135                 'box'          => 'inbox',
    136                 'type'         => 'all',
    137                 'user_id'      => bp_loggedin_user_id(),
    138                 'max'          => false,
    139                 'search_terms' => '',
    140                 'meta_query'   => array(),
     141                'page'                => 1,
     142                'per_page'            => 10,
     143                'page_arg'            => 'mpage',
     144                'box'                 => 'inbox',
     145                'type'                => 'all',
     146                'user_id'             => bp_loggedin_user_id(),
     147                'max'                 => false,
     148                'search_terms'        => '',
     149                'meta_query'          => array(),
     150                'recipients_page'     => null,
     151                'recipients_per_page' => null,
     152                'messages_page'       => null,
     153                'messages_per_page'   => null,
    141154            )
    142155        );
    143156
    144157        $this->pag_arg      = sanitize_key( $r['page_arg'] );
    145         $this->pag_page     = bp_sanitize_pagination_arg( $this->pag_arg, $r['page']     );
    146         $this->pag_num      = bp_sanitize_pagination_arg( 'num',          $r['per_page'] );
     158        $this->pag_page     = bp_sanitize_pagination_arg( $this->pag_arg, $r['page'] );
     159        $this->pag_num      = bp_sanitize_pagination_arg( 'num', $r['per_page'] );
    147160        $this->user_id      = $r['user_id'];
    148161        $this->box          = $r['box'];
     
    151164
    152165        if ( 'notices' === $this->box ) {
    153             $this->threads = BP_Messages_Notice::get_notices( array(
    154                 'pag_num'  => $this->pag_num,
    155                 'pag_page' => $this->pag_page
    156             ) );
     166            $this->threads = BP_Messages_Notice::get_notices(
     167                array(
     168                    'pag_num'  => $this->pag_num,
     169                    'pag_page' => $this->pag_page,
     170                )
     171            );
    157172        } else {
    158             $threads = BP_Messages_Thread::get_current_threads_for_user( array(
    159                 'user_id'      => $this->user_id,
    160                 'box'          => $this->box,
    161                 'type'         => $this->type,
    162                 'limit'        => $this->pag_num,
    163                 'page'         => $this->pag_page,
    164                 'search_terms' => $this->search_terms,
    165                 'meta_query'   => $r['meta_query'],
    166             ) );
     173            $threads = BP_Messages_Thread::get_current_threads_for_user(
     174                array(
     175                    'user_id'             => $this->user_id,
     176                    'box'                 => $this->box,
     177                    'type'                => $this->type,
     178                    'limit'               => $this->pag_num,
     179                    'page'                => $this->pag_page,
     180                    'search_terms'        => $this->search_terms,
     181                    'meta_query'          => $r['meta_query'],
     182                    'recipients_page'     => $r['recipients_page'],
     183                    'recipients_per_page' => $r['recipients_per_page'],
     184                    'messages_page'       => $r['messages_page'],
     185                    'messages_per_page'   => $r['messages_per_page'],
     186                )
     187            );
    167188
    168189            $this->threads            = isset( $threads['threads'] ) ? $threads['threads'] : array();
     
    170191        }
    171192
    172         if ( !$this->threads ) {
     193        if ( ! $this->threads ) {
    173194            $this->thread_count       = 0;
    174195            $this->total_thread_count = 0;
     
    212233            }
    213234
    214             $this->pag_links = paginate_links( array(
    215                 'base'      => add_query_arg( $pag_args, $base ),
    216                 'format'    => '',
    217                 'total'     => ceil( (int) $this->total_thread_count / (int) $this->pag_num ),
    218                 'current'   => $this->pag_page,
    219                 'prev_text' => _x( '←', 'Message pagination previous text', 'buddypress' ),
    220                 'next_text' => _x( '→', 'Message pagination next text', 'buddypress' ),
    221                 'mid_size'  => 1,
    222                 'add_args'  => $add_args,
    223             ) );
     235            $this->pag_links = paginate_links(
     236                array(
     237                    'base'      => add_query_arg( $pag_args, $base ),
     238                    'format'    => '',
     239                    'total'     => ceil( (int) $this->total_thread_count / (int) $this->pag_num ),
     240                    'current'   => $this->pag_page,
     241                    'prev_text' => _x( '←', 'Message pagination previous text', 'buddypress' ),
     242                    'next_text' => _x( '→', 'Message pagination next text', 'buddypress' ),
     243                    'mid_size'  => 1,
     244                    'add_args'  => $add_args,
     245                )
     246            );
    224247        }
    225248    }
     
    308331            // Set up the last message data.
    309332            if ( count( $this->thread->messages ) > 1 ) {
    310                 if ( 'inbox' == $this->box ) {
     333                if ( 'inbox' === $this->box ) {
    311334                    foreach ( (array) $this->thread->messages as $key => $message ) {
    312                         if ( bp_loggedin_user_id() != $message->sender_id ) {
     335                        if ( bp_loggedin_user_id() !== $message->sender_id ) {
    313336                            $last_message_index = $key;
    314337                            break;
    315338                        }
    316339                    }
    317 
    318                 } elseif ( 'sentbox' == $this->box ) {
     340                } elseif ( 'sentbox' === $this->box ) {
    319341                    foreach ( (array) $this->thread->messages as $key => $message ) {
    320                         if ( bp_loggedin_user_id() == $message->sender_id ) {
     342                        if ( bp_loggedin_user_id() === $message->sender_id ) {
    321343                            $last_message_index = $key;
    322344                            break;
Note: See TracChangeset for help on using the changeset viewer.