Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
05/24/2012 08:58:49 PM (12 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

File:
1 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    }
Note: See TracChangeset for help on using the changeset viewer.