Message info
 
To:buddypress-trac@lists.automattic.com From:buddypress-trac@lists.automattic.com Subject:[buddypress-trac] [BuddyPress][6044] trunk: Fixes pagination for notices. Date:Thu, 24 May 2012 20:58:49 +0000 (UTC)
 

Revision
6044
Author
boonebgorges
Date
2012-05-24 20:58:49 +0000 (Thu, 24 May 2012)

Log 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

Modified Paths

Diff

Modified: trunk/bp-messages/bp-messages-classes.php (6043 => 6044)


--- trunk/bp-messages/bp-messages-classes.php	2012-05-18 22:36:12 UTC (rev 6043)
+++ trunk/bp-messages/bp-messages-classes.php	2012-05-24 20:58:49 UTC (rev 6044)
@@ -508,10 +508,31 @@
 
 	// Static Functions
 
-	function get_notices() {
+	/**
+	 * Pulls up a list of notices
+	 *
+	 * To get all notices, pass a value of -1 to pag_num
+	 *
+	 * @param array $args See $defaults for explanation of accepted arguments
+	 * @return array $notices
+	 */
+	function get_notices( $args = array() ) {
 		global $wpdb, $bp;
 
-		$notices = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM {$bp->messages->table_name_notices} ORDER BY date_sent DESC" ) );
+		$defaults = array(
+			'pag_num'  => 20, // Number of notices per page
+			'pag_page' => 1   // Page number
+		);
+		$r = wp_parse_args( $args, $defaults );
+		extract( $r );
+
+		$limit_sql = '';
+		if ( (int) $pag_num >= 0 ) {
+			$limit_sql = $wpdb->prepare( "LIMIT %d, %d", (int) ( ( $pag_page - 1 ) * $pag_num ), (int) $pag_num );
+		}
+
+		$notices = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM {$bp->messages->table_name_notices} ORDER BY date_sent DESC {$limit_sql}" ) );
+
 		return $notices;
 	}
 

Modified: trunk/bp-messages/bp-messages-template.php (6043 => 6044)


--- trunk/bp-messages/bp-messages-template.php	2012-05-18 22:36:12 UTC (rev 6043)
+++ trunk/bp-messages/bp-messages-template.php	2012-05-24 20:58:49 UTC (rev 6044)
@@ -39,7 +39,10 @@
 		$this->search_terms = $search_terms;
 
 		if ( 'notices' == $this->box ) {
-			$this->threads = BP_Messages_Notice::get_notices();
+			$this->threads = BP_Messages_Notice::get_notices( array(
+				'pag_num'  => $this->pag_num,
+				'pag_page' => $this->pag_page
+			) );
 		} else {
 			$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 );
 

Modified: trunk/bp-themes/bp-default/members/single/messages/notices-loop.php (6043 => 6044)


--- trunk/bp-themes/bp-default/members/single/messages/notices-loop.php	2012-05-18 22:36:12 UTC (rev 6043)
+++ trunk/bp-themes/bp-default/members/single/messages/notices-loop.php	2012-05-24 20:58:49 UTC (rev 6044)
@@ -2,7 +2,7 @@
 
 <?php if ( bp_has_message_threads() ) : ?>
 
-	<div class="pagination" id="user-pag">
+	<div class="pagination no-ajax" id="user-pag">
 
 		<div class="pag-count" id="messages-dir-count">
 			<?php bp_messages_pagination_count(); ?>