Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
10/08/2015 04:59:40 PM (11 years ago)
Author:
boonebgorges
Message:

Introduce fields parameter to bp_has_activities() stack.

fields=ids will fetch only the IDs of matched activities. fields=all
(or any other value of fields, for the moment) will return full activity
objects.

The structure of the array returned from BP_Activity_Activity::get() is the
same regardless of the value of fields: matched items are stored in the
'activities' member of the returned array.

Props r-a-y.
Fixes #6426.

File:
1 edited

Legend:

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

    r10210 r10217  
    261261     * Get activity items, as specified by parameters.
    262262     *
     263     * @since 1.0.0
     264     * @since 2.4.0 Introduced the `$fields` parameter.
     265     *
    263266     * @see BP_Activity_Activity::get_filter_sql() for a description of the
    264267     *      'filter' parameter.
     
    273276     *     @type int|bool     $per_page          Number of results per page. Default: 25.
    274277     *     @type int|bool     $max               Maximum number of results to return. Default: false (unlimited).
     278     *     @type string       $fields            Activity fields to return. Pass 'ids' to get only the activity IDs.
     279     *                                           'all' returns full activity objects.
    275280     *     @type string       $sort              ASC or DESC. Default: 'DESC'.
    276281     *     @type array        $exclude           Array of activity IDs to exclude. Default: false.
     
    324329            'per_page'          => 25,         // Activity items per page
    325330            'max'               => false,      // Max number of items to return
     331            'fields'            => 'all',
    326332            'sort'              => 'DESC',     // ASC or DESC
    327333            'exclude'           => false,      // Array of ids to exclude
     
    571577            }
    572578
    573             $activities = self::get_activity_data( $activity_ids );
    574         }
    575 
    576         // Get the fullnames of users so we don't have to query in the loop
    577         $activities = self::append_user_fullnames( $activities );
    578 
    579         // Get activity meta
    580         $activity_ids = array();
    581         foreach ( (array) $activities as $activity ) {
    582             $activity_ids[] = $activity->id;
    583         }
    584 
    585         if ( ! empty( $activity_ids ) && $r['update_meta_cache'] ) {
    586             bp_activity_update_meta_cache( $activity_ids );
    587         }
    588 
    589         if ( $activities && $r['display_comments'] ) {
    590             $activities = BP_Activity_Activity::append_comments( $activities, $r['spam'] );
    591         }
    592 
    593         // Pre-fetch data associated with activity users and other objects
    594         BP_Activity_Activity::prefetch_object_data( $activities );
    595 
    596         // Generate action strings
    597         $activities = BP_Activity_Activity::generate_action_strings( $activities );
     579            if ( 'ids' === $r['fields'] ) {
     580                $activities = array_map( 'intval', $activity_ids );
     581            } else {
     582                $activities = self::get_activity_data( $activity_ids );
     583            }
     584        }
     585
     586        if ( 'ids' !== $r['fields'] ) {
     587            // Get the fullnames of users so we don't have to query in the loop
     588            $activities = self::append_user_fullnames( $activities );
     589
     590            // Get activity meta
     591            $activity_ids = array();
     592            foreach ( (array) $activities as $activity ) {
     593                $activity_ids[] = $activity->id;
     594            }
     595
     596            if ( ! empty( $activity_ids ) && $r['update_meta_cache'] ) {
     597                bp_activity_update_meta_cache( $activity_ids );
     598            }
     599
     600            if ( $activities && $r['display_comments'] ) {
     601                $activities = BP_Activity_Activity::append_comments( $activities, $r['spam'] );
     602            }
     603
     604            // Pre-fetch data associated with activity users and other objects
     605            BP_Activity_Activity::prefetch_object_data( $activities );
     606
     607            // Generate action strings
     608            $activities = BP_Activity_Activity::generate_action_strings( $activities );
     609        }
    598610
    599611        $retval['activities'] = $activities;
Note: See TracChangeset for help on using the changeset viewer.