Changeset 7948 for trunk/bp-groups/bp-groups-classes.php
- Timestamp:
- 02/21/2014 01:50:30 PM (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/bp-groups/bp-groups-classes.php
r7939 r7948 1437 1437 public function setup_hooks() { 1438 1438 // Take this early opportunity to set the default 'type' param 1439 // to 'last_ modified', which will ensure that BP_User_Query1439 // to 'last_joined', which will ensure that BP_User_Query 1440 1440 // trusts our order and does not try to apply its own 1441 1441 if ( empty( $this->query_vars_raw['type'] ) ) { 1442 $this->query_vars_raw['type'] = 'last_ modified';1442 $this->query_vars_raw['type'] = 'last_joined'; 1443 1443 } 1444 1444 … … 1472 1472 'group_role' => array( 'member' ), 1473 1473 'is_confirmed' => true, 1474 'type' => 'last_joined', 1474 1475 ) ); 1475 1476 … … 1509 1510 'orderby' => '', 1510 1511 'order' => '', 1511 'limit' => '',1512 1512 ); 1513 1513 … … 1572 1572 $sql['where'] = ! empty( $sql['where'] ) ? 'WHERE ' . implode( ' AND ', $sql['where'] ) : ''; 1573 1573 1574 /** ORDER BY clause ***************************************************/ 1575 1576 // @todo For now, mimicking legacy behavior of 1577 // bp_group_has_members(), which has us order by date_modified 1578 // only. Should abstract it in the future 1574 // We fetch group members in order of last_joined, regardless 1575 // of 'type'. If the 'type' value is not 'last_joined' or 1576 // 'first_joined', the order will be overridden in 1577 // BP_Group_Member_Query::set_orderby() 1579 1578 $sql['orderby'] = "ORDER BY date_modified"; 1580 $sql['order'] = "DESC"; 1581 1582 /** LIMIT clause ******************************************************/ 1583 $this->group_member_ids = $wpdb->get_col( "{$sql['select']} {$sql['where']} {$sql['orderby']} {$sql['order']} {$sql['limit']}" ); 1579 $sql['order'] = 'first_joined' === $this->query_vars['type'] ? 'ASC' : 'DESC'; 1580 1581 $this->group_member_ids = $wpdb->get_col( "{$sql['select']} {$sql['where']} {$sql['orderby']} {$sql['order']}" ); 1582 1583 /** 1584 * Use this filter to build a custom query (such as when you've 1585 * defined a custom 'type'). 1586 */ 1587 $this->group_member_ids = apply_filters( 'bp_group_member_query_group_member_ids', $this->group_member_ids, $this ); 1584 1588 1585 1589 return $this->group_member_ids; … … 1589 1593 * Tell BP_User_Query to order by the order of our query results. 1590 1594 * 1591 * This implementation assumes the 'last_modified' sort order1592 * hardcoded in BP_Group_Member_Query::get_group_member_ids().1595 * We only override BP_User_Query's native ordering in case of the 1596 * 'last_joined' and 'first_joined' $type parameters. 1593 1597 * 1594 1598 * @param BP_User_Query $query BP_User_Query object. … … 1600 1604 } 1601 1605 1602 // The first param in the FIELD() clause is the sort column id 1603 $gm_ids = array_merge( array( 'u.id' ), wp_parse_id_list( $gm_ids ) ); 1604 $gm_ids_sql = implode( ',', $gm_ids ); 1605 1606 $query->uid_clauses['orderby'] = "ORDER BY FIELD(" . $gm_ids_sql . ")"; 1606 // For 'last_joined' and 'first_joined' types, we force 1607 // the order according to the query performed in 1608 // BP_Group_Member_Query::get_group_members(). Otherwise, fall 1609 // through and let BP_User_Query do its own ordering. 1610 if ( in_array( $query->query_vars['type'], array( 'last_joined', 'first_joined' ) ) ) { 1611 1612 // The first param in the FIELD() clause is the sort column id 1613 $gm_ids = array_merge( array( 'u.id' ), wp_parse_id_list( $gm_ids ) ); 1614 $gm_ids_sql = implode( ',', $gm_ids ); 1615 1616 $query->uid_clauses['orderby'] = "ORDER BY FIELD(" . $gm_ids_sql . ")"; 1617 } 1607 1618 1608 1619 // Prevent this filter from running on future BP_User_Query
Note: See TracChangeset
for help on using the changeset viewer.