<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[BuddyPress][7559] trunk: Add sorting of notifications via form to submit `sort_order` value.</title>
</head>
<body>

<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;  }
#msg dl a { font-weight: bold}
#msg dl a:link    { color:#fc3; }
#msg dl a:active  { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff  {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://buddypress.trac.wordpress.org/changeset/7559">7559</a></dd>
<dt>Author</dt> <dd>johnjamesjacoby</dd>
<dt>Date</dt> <dd>2013-11-11 01:47:36 +0000 (Mon, 11 Nov 2013)</dd>
</dl>

<h3>Log Message</h3>
<pre>Add sorting of notifications via form to submit `sort_order` value. See <a href="http://buddypress.trac.wordpress.org/ticket/5148">#5148</a>. Hat tip vhauri.</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkbpnotificationsbpnotificationstemplatephp">trunk/bp-notifications/bp-notifications-template.php</a></li>
<li><a href="#trunkbptemplatesbplegacybuddypressmemberssinglenotificationsphp">trunk/bp-templates/bp-legacy/buddypress/members/single/notifications.php</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkbpnotificationsbpnotificationstemplatephp"></a>
<div class="modfile"><h4>Modified: trunk/bp-notifications/bp-notifications-template.php (7558 => 7559)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/bp-notifications/bp-notifications-template.php     2013-11-11 00:52:44 UTC (rev 7558)
+++ trunk/bp-notifications/bp-notifications-template.php        2013-11-11 01:47:36 UTC (rev 7559)
</span><span class="lines">@@ -240,6 +240,7 @@
</span><span class="cx">   */
</span><span class="cx">  public function __construct( $args = array() ) {
</span><span class="cx"> 
</span><ins>+               // Parse arguments
</ins><span class="cx">           $r = wp_parse_args( $args, array(
</span><span class="cx">                  'user_id'      => 0,
</span><span class="cx">                  'is_new'       => true,
</span><span class="lines">@@ -252,15 +253,39 @@
</span><span class="cx">                  'page_arg'     => 'npage',
</span><span class="cx">          ) );
</span><span class="cx"> 
</span><ins>+               // Overrides
+
+               // Set which pagination page
+               if ( isset( $_GET[ $r['page_arg'] ] ) ) {
+                       $pag_page = intval( $_GET[ $r['page_arg'] ] );
+               } else {
+                       $pag_page = $r['page'];
+               }
+
+               // Set the number to show per page
+               if ( isset( $_GET['num'] ) ) {
+                       $pag_num = intval( $_GET['num'] );
+               } else {
+                       $pag_num = intval( $r['per_page'] );
+               }
+
+               // Sort order direction
+               $orders = array( 'ASC', 'DESC' );
+               if ( ! empty( $_GET['sort_order'] ) && in_array( $_GET['sort_order'], $orders ) ) {
+                       $sort_order = $_GET['sort_order'];
+               } else {
+                       $sort_order = in_array( $r['sort_order'], $orders ) ? $r['sort_order'] : 'DESC';
+               }
+
</ins><span class="cx">           // Setup variables
</span><del>-               $this->pag_page     = isset( $_GET[ $r['page_arg'] ] ) ? intval( $_GET[ $r['page_arg'] ] ) : $r['page'];
-               $this->pag_num      = isset( $_GET['num']            ) ? intval( $_GET['num']            ) : $r['per_page'];
</del><ins>+                $this->pag_page     = $pag_page;
+               $this->pag_num      = $pag_num;
</ins><span class="cx">           $this->user_id      = $r['user_id'];
</span><span class="cx">          $this->is_new       = $r['is_new'];
</span><span class="cx">          $this->search_terms = $r['search_terms'];
</span><span class="cx">          $this->page_arg     = $r['page_arg'];
</span><span class="cx">          $this->order_by     = $r['order_by'];
</span><del>-               $this->sort_order   = $r['sort_order'];
</del><ins>+                $this->sort_order   = $sort_order;
</ins><span class="cx"> 
</span><span class="cx">          // Get the notifications
</span><span class="cx">          $notifications      = BP_Notifications_Notification::get_current_notifications_for_user( array(
</span><span class="lines">@@ -303,6 +328,10 @@
</span><span class="cx">                          'next_text' => _x( '&rarr;', 'Notifications pagination next text',     'buddypress' ),
</span><span class="cx">                          'mid_size'  => 1,
</span><span class="cx">                  ) );
</span><ins>+
+                       // Remove first page from pagination
+                       $this->pag_links = str_replace( '?'      . $r['page_arg'] . '=1', '', $this->pag_links );
+                       $this->pag_links = str_replace( '&#038;' . $r['page_arg'] . '=1', '', $this->pag_links );
</ins><span class="cx">           }
</span><span class="cx">  }
</span><span class="cx"> 
</span><span class="lines">@@ -404,6 +433,8 @@
</span><span class="cx">  }
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+/** The Loop ******************************************************************/
+
</ins><span class="cx"> /**
</span><span class="cx">  * Initialize the notifications loop.
</span><span class="cx">  *
</span><span class="lines">@@ -488,6 +519,8 @@
</span><span class="cx">  return buddypress()->notifications->query_loop->the_notification();
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+/** Loop Output ***************************************************************/
+
</ins><span class="cx"> /**
</span><span class="cx">  * Output the ID of the notification currently being iterated on.
</span><span class="cx">  *
</span><span class="lines">@@ -883,3 +916,39 @@
</span><span class="cx">  function bp_get_notifications_pagination_links() {
</span><span class="cx">          return apply_filters( 'bp_get_notifications_pagination_links', buddypress()->notifications->query_loop->pag_links );
</span><span class="cx">  }
</span><ins>+
+/** Form Helpers **************************************************************/
+
+/**
+ * Output the form for changing the sort order of notifications
+ *
+ * @since BuddyPress (1.9.0)
+ */
+function bp_notifications_sort_order_form() {
+
+       // Setup local variables
+       $orders   = array( 'DESC', 'ASC' );
+       $selected = 'DESC';
+
+       // Check for a custom sort_order
+       if ( !empty( $_REQUEST['sort_order'] ) ) {
+               if ( in_array( $_REQUEST['sort_order'], $orders ) ) {
+                       $selected = $_REQUEST['sort_order'];
+               }
+       } ?>
+
+       <form action="" method="get" id="notifications-sort-order">
+               <label for="notifications-friends"><?php esc_html_e( 'Order By:', 'buddypress' ); ?></label>
+
+               <select id="notifications-sort-order-list" name="sort_order" onchange="this.form.submit();">
+                       <option value="DESC" <?php selected( $selected, 'DESC' ); ?>><?php _e( 'Newest First', 'buddypress' ); ?></option>
+                       <option value="ASC"  <?php selected( $selected, 'ASC'  ); ?>><?php _e( 'Oldest First', 'buddypress' ); ?></option>
+               </select>
+
+               <noscript>
+                       <input id="submit" type="submit" name="form-submit" class="submit" value="<?php _e( 'Go', 'buddypress' ); ?>" />
+               </noscript>
+       </form>
+
+<?php
+}
</ins></span></pre></div>
<a id="trunkbptemplatesbplegacybuddypressmemberssinglenotificationsphp"></a>
<div class="modfile"><h4>Modified: trunk/bp-templates/bp-legacy/buddypress/members/single/notifications.php (7558 => 7559)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/bp-templates/bp-legacy/buddypress/members/single/notifications.php 2013-11-11 00:52:44 UTC (rev 7558)
+++ trunk/bp-templates/bp-legacy/buddypress/members/single/notifications.php    2013-11-11 01:47:36 UTC (rev 7559)
</span><span class="lines">@@ -14,12 +14,7 @@
</span><span class="cx">          <?php bp_get_options_nav(); ?>
</span><span class="cx"> 
</span><span class="cx">          <li id="members-order-select" class="last filter">
</span><del>-
-                       <label for="members-friends"><?php _e( 'Order By:', 'buddypress' ); ?></label>
-                       <select id="members-friends">
-                               <option value="newest"><?php _e( 'Newest First', 'buddypress' ); ?></option>
-                               <option value="oldest"><?php _e( 'Oldest First', 'buddypress' ); ?></option>
-                       </select>
</del><ins>+                        <?php bp_notifications_sort_order_form(); ?>
</ins><span class="cx">           </li>
</span><span class="cx">  </ul>
</span><span class="cx"> </div>
</span></span></pre>
</div>
</div>

</body>
</html>