Skip to:
Content

BuddyPress.org

Changeset 7951


Ignore:
Timestamp:
02/21/2014 02:49:28 PM (8 years ago)
Author:
boonebgorges
Message:

Add 'offset' parameter to bp_has_activities() function stack

This param allows plugins and themes to filter results to only those activity
items whose IDs are greater than the 'offset' parameter. See eg the "load
new items" integration with the Heartbeat API.

See #5328

Props imath, boonebgorges

Location:
trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/bp-activity/bp-activity-classes.php

    r7906 r7951  
    11461146        }
    11471147
     1148        if ( ! empty( $filter_array['offset'] ) ) {
     1149            $sid_sql = absint( $filter_array['offset'] );
     1150            $filter_sql[] = "a.id >= {$sid_sql}";
     1151        }
     1152
    11481153        if ( empty( $filter_sql ) )
    11491154            return false;
  • trunk/bp-activity/bp-activity-template.php

    r7906 r7951  
    455455 *           between components/types. Accepts a single ID, or an array of
    456456 *           multiple IDs. Defaults to false.
     457 *     @type int $offset Return only activity items with an ID greater than or
     458 *           equal to this one. Note that providing an offset will disable
     459 *           pagination. Default: false.
    457460 *     @type string|bool $display_comments How to handle activity comments.
    458461 *           Possible values:
     
    544547        'primary_id'        => $primary_id,  // object ID to filter on e.g. a group_id or forum_id or blog_id etc.
    545548        'secondary_id'      => false,        // secondary object ID to filter on e.g. a post_id
     549        'offset'            => false,        // return only items >= this ID
    546550
    547551        'meta_query'        => false,        // filter on activity meta. See WP_Meta_Query for format
     
    560564    if ( in_array( $display_comments, array( 0, '0', 'none', 'false' ), true ) ) {
    561565        $display_comments = false;
     566    }
     567
     568    // Ignore pagination if an offset is passed
     569    if ( ! empty( $offset ) ) {
     570        $page = 0;
    562571    }
    563572
     
    633642    if ( isset( $_GET['afilter'] ) && apply_filters( 'bp_activity_enable_afilter_support', false ) )
    634643        $filter = array( 'object' => $_GET['afilter'] );
    635     else if ( !empty( $user_id ) || !empty( $object ) || !empty( $action ) || !empty( $primary_id ) || !empty( $secondary_id ) )
    636         $filter = array( 'user_id' => $user_id, 'object' => $object, 'action' => $action, 'primary_id' => $primary_id, 'secondary_id' => $secondary_id );
     644    else if ( ! empty( $user_id ) || ! empty( $object ) || ! empty( $action ) || ! empty( $primary_id ) || ! empty( $secondary_id ) || ! empty( $offset ) )
     645        $filter = array( 'user_id' => $user_id, 'object' => $object, 'action' => $action, 'primary_id' => $primary_id, 'secondary_id' => $secondary_id, 'offset' => $offset );
    637646    else
    638647        $filter = false;
  • trunk/tests/testcases/activity/class.BP_Activity_Activity.php

    r7922 r7951  
    258258
    259259    /**
     260     * @group get
     261     */
     262    public function test_get_with_offset() {
     263        $now = time();
     264        $a1 = $this->factory->activity->create( array(
     265            'content' => 'Life Rules',
     266            'recorded_time' => date( 'Y-m-d H:i:s', $now - 100 ),
     267        ) );
     268        $a2 = $this->factory->activity->create( array(
     269            'content' => 'Life Drools',
     270            'recorded_time' => date( 'Y-m-d H:i:s', $now - 50 ),
     271        ) );
     272        $a3 = $this->factory->activity->create( array(
     273            'content' => 'Life Drools',
     274            'recorded_time' => date( 'Y-m-d H:i:s', $now - 10 ),
     275        ) );
     276
     277        $activity = BP_Activity_Activity::get( array(
     278            'filter' => array(
     279                'offset' => $a2,
     280            ),
     281        ) );
     282        $ids = wp_list_pluck( $activity['activities'], 'id' );
     283        $this->assertEquals( array( $a3, $a2 ), $ids );
     284    }
     285    /**
    260286     * @group get_id
    261287     */
Note: See TracChangeset for help on using the changeset viewer.