Changeset 7296
- Timestamp:
- 07/23/2013 05:31:39 PM (12 years ago)
- Location:
- branches/1.8
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/1.8/bp-groups/bp-groups-classes.php
r7275 r7296 967 967 class BP_Group_Member_Query extends BP_User_Query { 968 968 /** 969 * Array of group member ids, cached to prevent redundant lookups 970 * 971 * @var null|array Null if not yet defined, otherwise an array of ints 972 * @since BuddyPress (1.8.1) 973 */ 974 protected $group_member_ids; 975 976 /** 969 977 * Set up action hooks 970 978 * … … 978 986 $this->query_vars_raw['type'] = 'last_modified'; 979 987 } 988 989 // Set the sort order 990 add_action( 'bp_pre_user_query', array( $this, 'set_orderby' ) ); 980 991 981 992 // Set up our populate_extras method … … 1029 1040 global $wpdb; 1030 1041 1042 if ( is_array( $this->group_member_ids ) ) { 1043 return $this->group_member_ids; 1044 } 1045 1031 1046 $bp = buddypress(); 1032 1047 $sql = array( … … 1107 1122 1108 1123 /** LIMIT clause ******************************************************/ 1109 1110 $ids = $wpdb->get_col( "{$sql['select']} {$sql['where']} {$sql['orderby']} {$sql['order']} {$sql['limit']}" ); 1111 1112 return $ids; 1124 $this->group_member_ids = $wpdb->get_col( "{$sql['select']} {$sql['where']} {$sql['orderby']} {$sql['order']} {$sql['limit']}" ); 1125 1126 return $this->group_member_ids; 1127 } 1128 1129 /** 1130 * Tell BP_User_Query to order by the order of our query results 1131 * 1132 * This implementation assumes the 'last_modified' sort order 1133 * hardcoded in BP_Group_Member_Query::get_group_member_ids(). 1134 * 1135 * @param object $query BP_User_Query object 1136 */ 1137 public function set_orderby( $query ) { 1138 $gm_ids = $this->get_group_member_ids(); 1139 if ( empty( $gm_ids ) ) { 1140 $gm_ids = array( 0 ); 1141 } 1142 1143 // The first param in the FIELD() clause is the sort column id 1144 $gm_ids = array_merge( array( 'u.id' ), wp_parse_id_list( $gm_ids ) ); 1145 $gm_ids_sql = implode( ',', $gm_ids ); 1146 1147 $query->uid_clauses['orderby'] = "ORDER BY FIELD(" . $gm_ids_sql . ")"; 1148 1149 // Prevent this filter from running on future BP_User_Query 1150 // instances on the same page 1151 remove_action( 'bp_pre_user_query', array( $this, 'set_orderby' ) ); 1113 1152 } 1114 1153 -
branches/1.8/tests/testcases/groups/template.php
r7185 r7296 352 352 } 353 353 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 } 354 394 }
Note: See TracChangeset
for help on using the changeset viewer.