Ticket #3430: 3430.03.patch
File 3430.03.patch, 5.2 KB (added by , 11 years ago) |
---|
-
src/bp-groups/bp-groups-classes.php
diff --git src/bp-groups/bp-groups-classes.php src/bp-groups/bp-groups-classes.php index c036b62..f5f524e 100644
class BP_Group_Member_Query extends BP_User_Query { 1711 1711 // the order according to the query performed in 1712 1712 // BP_Group_Member_Query::get_group_members(). Otherwise, fall 1713 1713 // through and let BP_User_Query do its own ordering. 1714 if ( in_array( $query->query_vars['type'], array( 'last_joined', 'first_joined' ) ) ) { 1714 if ( in_array( $query->query_vars['type'], array( 'last_joined', 'first_joined', 'group_activity' ) ) ) { 1715 1716 // Group Activity DESC 1717 if ( 'group_activity' == $query->query_vars['type'] ) { 1718 $gm_ids = $this->get_gm_ids_ordered_by_activity( $query, $gm_ids ); 1719 } 1715 1720 1716 1721 // The first param in the FIELD() clause is the sort column id 1717 1722 $gm_ids = array_merge( array( 'u.id' ), wp_parse_id_list( $gm_ids ) ); … … class BP_Group_Member_Query extends BP_User_Query { 1766 1771 // Don't filter other BP_User_Query objects on the same page 1767 1772 remove_action( 'bp_user_query_populate_extras', array( $this, 'populate_group_member_extras' ), 10, 2 ); 1768 1773 } 1774 1775 /** 1776 * Return Group member ids ordered by latest group activity. 1777 * 1778 * @since BuddyPress (2.1.0) 1779 * 1780 * @global $wpdb 1781 * @uses buddypress() 1782 * @uses wp_list_pluck() 1783 * @param BP_User_Query $query BP_User_Query object. 1784 * @param array $gm_ids array of group member ids. 1785 */ 1786 public function get_gm_ids_ordered_by_activity( $query, $gm_ids = array() ) { 1787 global $wpdb; 1788 1789 if ( empty( $gm_ids ) ) { 1790 return false; 1791 } 1792 1793 $activity_table = buddypress()->activity->table_name; 1794 1795 $sql = array( 1796 'select' => "SELECT user_id, max( date_recorded ) as date_recorded FROM {$activity_table}", 1797 'where' => array(), 1798 'groupby' => 'GROUP BY user_id', 1799 'orderby' => 'ORDER BY date_recorded', 1800 'order' => 'DESC', 1801 ); 1802 1803 $sql['where'] = array( 1804 'user_id IN (' . implode( ',', $gm_ids ) . ')', 1805 'item_id = ' . absint( $query->query_vars['group_id'] ), 1806 "component = 'groups'", 1807 ); 1808 1809 $sql['where'] = ! empty( $sql['where'] ) ? 'WHERE ' . implode( ' AND ', $sql['where'] ) : ''; 1810 1811 $group_user_ids = $wpdb->get_results( "{$sql['select']} {$sql['where']} {$sql['groupby']} {$sql['orderby']} {$sql['order']}" ); 1812 1813 return wp_list_pluck( $group_user_ids, 'user_id' ); 1814 } 1769 1815 } 1770 1816 1771 1817 /** -
src/bp-groups/bp-groups-template.php
diff --git src/bp-groups/bp-groups-template.php src/bp-groups/bp-groups-template.php index bca272a..d7b752f 100644
function bp_groups_members_filter() { 2437 2437 <select id="group_members-order-by"> 2438 2438 <option value="last_joined"><?php _e( 'Newest', 'buddypress' ); ?></option> 2439 2439 <option value="first_joined"><?php _e( 'Oldest', 'buddypress' ); ?></option> 2440 2441 <?php if ( bp_is_active( 'activity' ) ) : ?> 2442 <option value="group_activity"><?php _e( 'Group Activity', 'buddypress' ); ?></option> 2443 <?php endif; ?> 2444 2440 2445 <option value="alphabetical"><?php _e( 'Alphabetical', 'buddypress' ); ?></option> 2441 2446 2442 2447 <?php do_action( 'bp_groups_members_order_options' ); ?> -
tests/phpunit/testcases/groups/class-bp-group-member-query.php
diff --git tests/phpunit/testcases/groups/class-bp-group-member-query.php tests/phpunit/testcases/groups/class-bp-group-member-query.php index 6aa2782..d786ee2 100644
class BP_Tests_BP_Group_Member_Query_TestCases extends BP_UnitTestCase { 403 403 /** 404 404 * @group type 405 405 */ 406 public function test_get_with_type_group_activity() { 407 $g = $this->factory->group->create(); 408 $u1 = $this->create_user(); 409 $u2 = $this->create_user(); 410 $u3 = $this->create_user(); 411 $c = buddypress()->groups->id; 412 $time = time(); 413 414 $this->add_user_to_group( $u1, $g, array( 415 'date_modified' => gmdate( 'Y-m-d H:i:s', $time - 500 ), 416 ) ); 417 418 $this->add_user_to_group( $u2, $g, array( 419 'date_modified' => gmdate( 'Y-m-d H:i:s', $time - 400 ), 420 ) ); 421 422 $this->add_user_to_group( $u3, $g, array( 423 'date_modified' => gmdate( 'Y-m-d H:i:s', $time - 300 ), 424 ) ); 425 426 $this->factory->activity->create( array( 427 'component' => $c, 428 'type' => 'activity_update', 429 'user_id' => $u3, 430 'item_id' => $g, 431 'recorded_time' => gmdate( 'Y-m-d H:i:s', $time - 250 ), 432 ) ); 433 434 $this->factory->activity->create( array( 435 'component' => $c, 436 'type' => 'activity_update', 437 'user_id' => $u1, 438 'item_id' => $g, 439 'recorded_time' => gmdate( 'Y-m-d H:i:s', $time - 200 ), 440 ) ); 441 442 $this->factory->activity->create( array( 443 'component' => $c, 444 'type' => 'activity_update', 445 'user_id' => $u2, 446 'item_id' => $g, 447 'recorded_time' => gmdate( 'Y-m-d H:i:s', $time - 100 ), 448 ) ); 449 450 $query_members = new BP_Group_Member_Query( array( 451 'group_id' => $g, 452 'type' => 'group_activity', 453 ) ); 454 455 $ids = wp_parse_id_list( array_keys( $query_members->results ) ); 456 $this->assertEquals( array( $u2, $u1, $u3 ), $ids ); 457 } 458 459 /** 460 * @group type 461 */ 406 462 public function test_get_with_type_alphabetical() { 407 463 $g = $this->factory->group->create(); 408 464 $u1 = $this->create_user( array(