Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
08/05/2014 10:40:49 PM (10 years ago)
Author:
r-a-y
Message:

Allow notifications loop to accept all available parameters.

Previously, the notifications loop accepted only a subset of parameters
from the BP_Notification_Notification::get() method. This made
notification loop filtering very restrictive.

This commit opens up the notifications loop so all parameters are available
as per the BP_Notifications_Notification::get() fetch method.

Fixes #5558.

File:
1 edited

Legend:

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

    r8706 r8761  
    221221     * Constructor method.
    222222     *
     223     * @see bp_has_notifications() For information on the array format.
     224     *
    223225     * @since BuddyPress (1.9.0)
    224226     *
    225227     * @param array $args {
    226      *     @type int $user_id ID of the user to whom the displayed
    227      *           notifications belong.
    228      *     @type bool $is_new Whether to limit the query to unread
    229      *           notifications. Default: true.
    230      *     @type int $page Number of the page of results to return.
    231      *           Will be overridden by URL parameter. Default: 1.
    232      *     @type int $per_page Number of results to return per page.
    233      *           Will be overridden by URL parameter. Default: 25.
    234      *     @type int $max Optional. Max results to display.
    235      *     @type string $search_terms Optional. Term to match against
    236      *           component_name and component_action.
    237      *     @type string $page_arg URL argument to use for pagination.
    238      *           Default: 'npage'.
     228     *     An array of arguments. See {@link bp_has_notifications()}
     229     *     for more details.
    239230     * }
    240231     */
     
    243234        // Parse arguments
    244235        $r = wp_parse_args( $args, array(
    245             'user_id'      => 0,
    246             'is_new'       => true,
    247             'page'         => 1,
    248             'per_page'     => 25,
    249             'order_by'     => 'date_notified',
    250             'sort_order'   => 'DESC',
    251             'max'          => null,
    252             'search_terms' => '',
    253             'page_arg'     => 'npage',
     236            'id'                => false,
     237            'user_id'           => 0,
     238            'secondary_item_id' => false,
     239            'component_name'    => bp_notifications_get_registered_components(),
     240            'component_action'  => false,
     241            'is_new'            => true,
     242            'search_terms'      => '',
     243            'order_by'          => 'date_notified',
     244            'sort_order'        => 'DESC',
     245            'page'              => 1,
     246            'per_page'          => 25,
     247            'max'               => null,
     248            'page_arg'          => 'npage',
    254249        ) );
    255250
     
    258253        // Set which pagination page
    259254        if ( isset( $_GET[ $r['page_arg'] ] ) ) {
    260             $pag_page = intval( $_GET[ $r['page_arg'] ] );
    261         } else {
    262             $pag_page = $r['page'];
     255            $r['page'] = intval( $_GET[ $r['page_arg'] ] );
    263256        }
    264257
    265258        // Set the number to show per page
    266259        if ( isset( $_GET['num'] ) ) {
    267             $pag_num = intval( $_GET['num'] );
     260            $r['per_page'] = intval( $_GET['num'] );
    268261        } else {
    269             $pag_num = intval( $r['per_page'] );
     262            $r['per_page'] = intval( $r['per_page'] );
    270263        }
    271264
     
    273266        $orders = array( 'ASC', 'DESC' );
    274267        if ( ! empty( $_GET['sort_order'] ) && in_array( $_GET['sort_order'], $orders ) ) {
    275             $sort_order = $_GET['sort_order'];
     268            $r['sort_order'] = $_GET['sort_order'];
    276269        } else {
    277             $sort_order = in_array( $r['sort_order'], $orders ) ? $r['sort_order'] : 'DESC';
     270            $r['sort_order'] = in_array( $r['sort_order'], $orders ) ? $r['sort_order'] : 'DESC';
    278271        }
    279272
    280273        // Setup variables
    281         $this->pag_page     = $pag_page;
    282         $this->pag_num      = $pag_num;
     274        $this->pag_page     = $r['page'];
     275        $this->pag_num      = $r['per_page'];
    283276        $this->user_id      = $r['user_id'];
    284277        $this->is_new       = $r['is_new'];
     
    286279        $this->page_arg     = $r['page_arg'];
    287280        $this->order_by     = $r['order_by'];
    288         $this->sort_order   = $sort_order;
    289 
    290         // Get the notifications
    291         $notifications      = BP_Notifications_Notification::get_current_notifications_for_user( array(
    292             'user_id'      => $this->user_id,
    293             'is_new'       => $this->is_new,
    294             'page'         => $this->pag_page,
    295             'per_page'     => $this->pag_num,
    296             'search_terms' => $this->search_terms,
    297             'order_by'     => $this->order_by,
    298             'sort_order'   => $this->sort_order,
    299         ) );
     281        $this->sort_order   = $r['sort_order'];
    300282
    301283        // Setup the notifications to loop through
    302         $this->notifications            = $notifications['notifications'];
    303         $this->total_notification_count = $notifications['total'];
     284        $this->notifications            = BP_Notifications_Notification::get( $r );
     285        $this->total_notification_count = BP_Notifications_Notification::get_total_count( $r );
    304286
    305287        if ( empty( $this->notifications ) ) {
     
    448430 *     Arguments for limiting the contents of the notifications loop. Can be
    449431 *     passed as an associative array, or as a URL query string.
    450  *     @type int $user_id ID of the user to whom notifications belong. Default:
    451  *           ID of the logged-in user.
    452  *     @type bool $is_new Whether to limit query to unread notifications.
    453  *           Default: when viewing the 'unread' tab, defaults to true; when
    454  *           viewing the 'read' tab, defaults to false.
    455  *     @type int $page The page of notifications being fetched. Default: 1.
    456  *     @type int $per_page Number of items to display on a page. Default: 25.
     432 *
     433 *     See {@link BP_Notifications_Notification::get()} for detailed
     434 *     information on the arguments.  In addition, also supports:
     435 *
    457436 *     @type int $max Optional. Max items to display. Default: false.
    458  *     @type string $search_terms Optional. Term to match against
    459  *           component_name and component_action.
    460437 *     @type string $page_arg URL argument to use for pagination.
    461438 *           Default: 'npage'.
     
    469446    } elseif ( bp_is_current_action( 'read' ) ) {
    470447        $is_new = 0;
     448
     449    // not on a notifications page? default to fetch new notifications
     450    } else {
     451        $is_new = 1;
    471452    }
    472453
     
    480461    // Parse the args
    481462    $r = bp_parse_args( $args, array(
    482         'user_id'      => $user_id,
    483         'is_new'       => $is_new,
    484         'page'         => 1,
    485         'per_page'     => 25,
    486         'max'          => false,
    487         'search_terms' => isset( $_REQUEST['s'] ) ? stripslashes( $_REQUEST['s'] ) : '',
    488         'page_arg'     => 'npage',
     463        'id'                => false,
     464        'user_id'           => $user_id,
     465        'secondary_item_id' => false,
     466        'component_name'    => bp_notifications_get_registered_components(),
     467        'component_action'  => false,
     468        'is_new'            => $is_new,
     469        'search_terms'      => isset( $_REQUEST['s'] ) ? stripslashes( $_REQUEST['s'] ) : '',
     470        'order_by'          => 'date_notified',
     471        'sort_order'        => 'DESC',
     472        'page'              => 1,
     473        'per_page'          => 25,
     474
     475        // these are additional arguments that are not available in
     476        // BP_Notifications_Notification::get()
     477        'max'               => false,
     478        'page_arg'          => 'npage',
    489479    ), 'has_notifications' );
    490480
Note: See TracChangeset for help on using the changeset viewer.