[buddypress-trac] [BuddyPress Trac] #4988: bp_has_activities to accept multi scope

buddypress-trac noreply at wordpress.org
Wed Aug 27 20:11:15 UTC 2014


#4988: bp_has_activities to accept multi scope
-------------------------+------------------
 Reporter:  henrywright  |       Owner:
     Type:  enhancement  |      Status:  new
 Priority:  normal       |   Milestone:  2.2
Component:  Activity     |     Version:  1.2
 Severity:  normal       |  Resolution:
 Keywords:  has-patch    |
-------------------------+------------------

Comment (by boonebgorges):

 r-a-y - A really nice start. The technique you've chosen for translating
 'scope' into a filter_query looks good at a glance. I definitely like that
 this is now an option available through the whole stack, not just at the
 level of bp_has_activities()

 A couple thoughts about how the proposed API syntax looks. Some of this is
 in contradiction to my initial thoughts yesterday, so bear with me :)

 1. There's currently no way to do negative filters. If I want to get all
 activity from components *other than* 'groups', there should be a way to
 do that.
 2. WP_Meta_Query and WP_Tax_Query are limited in that they only support
 one level of 'relation' - no nesting. While nested queries seem arcane,
 I'd argue that they inevitably arise in practice. Say you want activity
 items that meet the following criteria:

 {{{
 (
   ( item_id = 5 )
   AND
   ( component = 'blogs' OR type = 'activity_update' )
 )
 OR
 (
   ( component = 'groups' )
   AND
   ( item_id = 6 )
 )
 }}}

 I wonder if we can approach this in a different way that fixes both
 problems. Two changes:

 a. Instead of multiple columns into a single filter, one column per filter
 clause. Make it look pretty much just like WP_Meta_Query (though we only
 have to support a smaller subset of 'compare' operators):

 {{{
 array(
     'column' => 'component', // 'column' is a crappy name, but you get the
 idea
     'value' => array( 'groups', 'blogs' ),
     'compare' => 'IN',
 ),
 }}}

 b. Support infinite nesting. All grouping happens with AND or OR
 relations.

 A "my friends" filter is then:

 {{{
 $my_friends_filter_query = array(
     array(
         'column' => 'user_id',
         'value' => $friend_ids,
         'relation' => 'IN',
     ),
 ),
 }}}

 A "my groups" query is:

 {{{
 $my_groups_filter_query => array(
     'relation' => 'AND',
     array(
         'column' => 'component',
         'value' => 'groups',
         'relation' => 'IN',
     ),
     array(
         'column' => 'item_id',
         'value' => $group_ids,
         'relation' => 'IN',
     ),
 ),
 }}}

 scope=groups,friends would be:

 {{{
 array(
     'relation' => 'OR',
     $my_groups_filter_query,
     $my_friends_filter_query,
 ),
 }}}

 This'll let you get as fancy as you want.

 Technically, it'll require some recursion, and it'll require a technique
 for knowing whether another level of recursion is required. (Looking for a
 'column' array key is probably enough.)

 What do you think?

--
Ticket URL: <https://buddypress.trac.wordpress.org/ticket/4988#comment:5>
BuddyPress Trac <http://buddypress.org/>
BuddyPress Trac


More information about the buddypress-trac mailing list