Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
07/23/2013 03:32:47 PM (13 years ago)
Author:
boonebgorges
Message:

Tell BP_Group_Member_Query queries to order by FIELD()

BP_Group_Member_Query works by first querying for a list of group members
that match the query params, sorted by date_modified. Then, it feeds those ids
to the BP_User_Query parent class. In order to maintain the proper
date_modified sort, we have to override BP_User_Query's ORDER BY param, and
replace it with ORDER BY FIELD(), using the user ids from the first query.

This fixes a regression in BP 1.8, where the default sort order for
bp_group_has_members() was inadvertantly changed to user_id DESC, rather than
the legacy date_modified that existed before the introduction of
BP_Group_Member_Query.

Fixes #5106

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/testcases/groups/template.php

    r7185 r7294  
    352352    }
    353353
     354    /**
     355     * Default sort order should be the joined date
     356     *
     357     * @tickett BP5106
     358     * @group bp_group_has_members
     359     */
     360    public function test_bp_group_has_members_default_order() {
     361        $u1 = $this->create_user( array(
     362            'last_activity' => gmdate( 'Y-m-d H:i:s', time() - 60 ),
     363        ) );
     364        $u2 = $this->create_user( array(
     365            'last_activity' => gmdate( 'Y-m-d H:i:s', time() - 600 ),
     366        ) );
     367        $u3 = $this->create_user( array(
     368            'last_activity' => gmdate( 'Y-m-d H:i:s', time() - 6000 ),
     369        ) );
     370
     371
     372        $g = $this->factory->group->create( array(
     373            'creator_id' => $u1,
     374        ) );
     375
     376        $this->add_user_to_group( $u2, $g, array(
     377            'date_modified' => gmdate( 'Y-m-d H:i:s', time() - 60*60*24 ),
     378        ) );
     379
     380        $this->add_user_to_group( $u3, $g, array(
     381            'date_modified' => gmdate( 'Y-m-d H:i:s', time() - 60*60*12 ),
     382        ) );
     383
     384        global $members_template;
     385        bp_group_has_members( array(
     386            'group_id' => $g,
     387            'exclude_banned' => 0,
     388            'exclude_admins_mods' => false,
     389        ) );
     390
     391        $ids = wp_parse_id_list( wp_list_pluck( $members_template->members, 'user_id' ) );
     392        $this->assertEquals( array( $u1, $u3, $u2, ), $ids );
     393    }
    354394}
Note: See TracChangeset for help on using the changeset viewer.