Skip to:
Content

BuddyPress.org

Changeset 6044


Ignore:
Timestamp:
05/24/2012 08:58:49 PM (9 years ago)
Author:
boonebgorges
Message:

Fixes pagination for notices.

The Notices template has always show pagination markup, but the database
and template classes were never designed to handle pagination. This changeset
introduces the necessary logic in BP_Messages_Notice::get_notice() for
pagination to work.

Fixes #4204

Location:
trunk
Files:
3 edited

Legend:

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

    r5999 r6044  
    509509    // Static Functions
    510510
    511     function get_notices() {
    512         global $wpdb, $bp;
    513 
    514         $notices = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM {$bp->messages->table_name_notices} ORDER BY date_sent DESC" ) );
     511    /**
     512     * Pulls up a list of notices
     513     *
     514     * To get all notices, pass a value of -1 to pag_num
     515     *
     516     * @param array $args See $defaults for explanation of accepted arguments
     517     * @return array $notices
     518     */
     519    function get_notices( $args = array() ) {
     520        global $wpdb, $bp;
     521
     522        $defaults = array(
     523            'pag_num'  => 20, // Number of notices per page
     524            'pag_page' => 1   // Page number
     525        );
     526        $r = wp_parse_args( $args, $defaults );
     527        extract( $r );
     528
     529        $limit_sql = '';
     530        if ( (int) $pag_num >= 0 ) {
     531            $limit_sql = $wpdb->prepare( "LIMIT %d, %d", (int) ( ( $pag_page - 1 ) * $pag_num ), (int) $pag_num );
     532        }
     533
     534        $notices = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM {$bp->messages->table_name_notices} ORDER BY date_sent DESC {$limit_sql}" ) );
     535
    515536        return $notices;
    516537    }
  • trunk/bp-messages/bp-messages-template.php

    r5927 r6044  
    4040
    4141        if ( 'notices' == $this->box ) {
    42             $this->threads = BP_Messages_Notice::get_notices();
     42            $this->threads = BP_Messages_Notice::get_notices( array(
     43                'pag_num'  => $this->pag_num,
     44                'pag_page' => $this->pag_page
     45            ) );
    4346        } else {
    4447            $threads = BP_Messages_Thread::get_current_threads_for_user( $this->user_id, $this->box, $this->type, $this->pag_num, $this->pag_page, $this->search_terms );
  • trunk/bp-themes/bp-default/members/single/messages/notices-loop.php

    r5773 r6044  
    33<?php if ( bp_has_message_threads() ) : ?>
    44
    5     <div class="pagination" id="user-pag">
     5    <div class="pagination no-ajax" id="user-pag">
    66
    77        <div class="pag-count" id="messages-dir-count">
Note: See TracChangeset for help on using the changeset viewer.