Skip to:
Content

BuddyPress.org

Changeset 7559


Ignore:
Timestamp:
11/11/2013 01:47:36 AM (11 years ago)
Author:
johnjamesjacoby
Message:

Add sorting of notifications via form to submit sort_order value. See #5148. Hat tip vhauri.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/bp-notifications/bp-notifications-template.php

    r7553 r7559  
    241241    public function __construct( $args = array() ) {
    242242
     243        // Parse arguments
    243244        $r = wp_parse_args( $args, array(
    244245            'user_id'      => 0,
     
    253254        ) );
    254255
     256        // Overrides
     257
     258        // Set which pagination page
     259        if ( isset( $_GET[ $r['page_arg'] ] ) ) {
     260            $pag_page = intval( $_GET[ $r['page_arg'] ] );
     261        } else {
     262            $pag_page = $r['page'];
     263        }
     264
     265        // Set the number to show per page
     266        if ( isset( $_GET['num'] ) ) {
     267            $pag_num = intval( $_GET['num'] );
     268        } else {
     269            $pag_num = intval( $r['per_page'] );
     270        }
     271
     272        // Sort order direction
     273        $orders = array( 'ASC', 'DESC' );
     274        if ( ! empty( $_GET['sort_order'] ) && in_array( $_GET['sort_order'], $orders ) ) {
     275            $sort_order = $_GET['sort_order'];
     276        } else {
     277            $sort_order = in_array( $r['sort_order'], $orders ) ? $r['sort_order'] : 'DESC';
     278        }
     279
    255280        // Setup variables
    256         $this->pag_page     = isset( $_GET[ $r['page_arg'] ] ) ? intval( $_GET[ $r['page_arg'] ] ) : $r['page'];
    257         $this->pag_num      = isset( $_GET['num']            ) ? intval( $_GET['num']            ) : $r['per_page'];
     281        $this->pag_page     = $pag_page;
     282        $this->pag_num      = $pag_num;
    258283        $this->user_id      = $r['user_id'];
    259284        $this->is_new       = $r['is_new'];
     
    261286        $this->page_arg     = $r['page_arg'];
    262287        $this->order_by     = $r['order_by'];
    263         $this->sort_order   = $r['sort_order'];
     288        $this->sort_order   = $sort_order;
    264289
    265290        // Get the notifications
     
    304329                'mid_size'  => 1,
    305330            ) );
     331
     332            // Remove first page from pagination
     333            $this->pag_links = str_replace( '?'      . $r['page_arg'] . '=1', '', $this->pag_links );
     334            $this->pag_links = str_replace( '&' . $r['page_arg'] . '=1', '', $this->pag_links );
    306335        }
    307336    }
     
    404433    }
    405434}
     435
     436/** The Loop ******************************************************************/
    406437
    407438/**
     
    489520}
    490521
     522/** Loop Output ***************************************************************/
     523
    491524/**
    492525 * Output the ID of the notification currently being iterated on.
     
    884917        return apply_filters( 'bp_get_notifications_pagination_links', buddypress()->notifications->query_loop->pag_links );
    885918    }
     919
     920/** Form Helpers **************************************************************/
     921
     922/**
     923 * Output the form for changing the sort order of notifications
     924 *
     925 * @since BuddyPress (1.9.0)
     926 */
     927function bp_notifications_sort_order_form() {
     928
     929    // Setup local variables
     930    $orders   = array( 'DESC', 'ASC' );
     931    $selected = 'DESC';
     932
     933    // Check for a custom sort_order
     934    if ( !empty( $_REQUEST['sort_order'] ) ) {
     935        if ( in_array( $_REQUEST['sort_order'], $orders ) ) {
     936            $selected = $_REQUEST['sort_order'];
     937        }
     938    } ?>
     939
     940    <form action="" method="get" id="notifications-sort-order">
     941        <label for="notifications-friends"><?php esc_html_e( 'Order By:', 'buddypress' ); ?></label>
     942
     943        <select id="notifications-sort-order-list" name="sort_order" onchange="this.form.submit();">
     944            <option value="DESC" <?php selected( $selected, 'DESC' ); ?>><?php _e( 'Newest First', 'buddypress' ); ?></option>
     945            <option value="ASC"  <?php selected( $selected, 'ASC'  ); ?>><?php _e( 'Oldest First', 'buddypress' ); ?></option>
     946        </select>
     947
     948        <noscript>
     949            <input id="submit" type="submit" name="form-submit" class="submit" value="<?php _e( 'Go', 'buddypress' ); ?>" />
     950        </noscript>
     951    </form>
     952
     953<?php
     954}
  • trunk/bp-templates/bp-legacy/buddypress/members/single/notifications.php

    r7546 r7559  
    1515
    1616        <li id="members-order-select" class="last filter">
    17 
    18             <label for="members-friends"><?php _e( 'Order By:', 'buddypress' ); ?></label>
    19             <select id="members-friends">
    20                 <option value="newest"><?php _e( 'Newest First', 'buddypress' ); ?></option>
    21                 <option value="oldest"><?php _e( 'Oldest First', 'buddypress' ); ?></option>
    22             </select>
     17            <?php bp_notifications_sort_order_form(); ?>
    2318        </li>
    2419    </ul>
Note: See TracChangeset for help on using the changeset viewer.