Skip to:
Content

BuddyPress.org

Ticket #1284: bp-groups-classes.php.patch

File bp-groups-classes.php.patch, 3.3 KB (added by MrMaz, 15 years ago)
  • bp-groups-classes.php

    # This patch file was generated by NetBeans IDE
    # Following Index: paths are relative to: \\UBU\www\sandbox\public_html\wp-content\plugins\buddypress\bp-groups
    # This patch can be applied using context Tools: Patch action on respective folder.
    # It uses platform neutral UTF-8 encoding and \n newlines.
    # Above lines and this line are ignored by the patching process.
     
    421421        function get_all( $limit = null, $page = null, $only_public = true, $sort_by = false, $order = false ) {
    422422                global $wpdb, $bp;
    423423
     424                // TODO this optional where statement code should be refactored into its own generic function for re-use by many other functions
     425                // default sql WHERE conditions are blank
     426                $where_sql = null;
     427                $where_conditions = array();
     428
     429                // limit results to public status
    424430                if ( $only_public )
    425                         $public_sql = $wpdb->prepare( " WHERE g.status = 'public'" );
     431                        $where_conditions[] = $wpdb->prepare( "g.status = 'public'" );
    426432
     433                // limit results to non-hidden status
    427434                if ( !is_site_admin() )
    428                         $hidden_sql = $wpdb->prepare( " AND g.status != 'hidden'");
     435                        $where_conditions[] = $wpdb->prepare( "g.status != 'hidden'");
    429436
     437                // build where sql statement if necessary
     438                if ( !empty( $where_conditions ) ) {
     439                        $where_sql = 'WHERE ' . join( ' AND ', $where_conditions );
     440                }
     441
    430442                if ( $limit && $page )
    431443                        $pag_sql = $wpdb->prepare( " LIMIT %d, %d", intval( ( $page - 1 ) * $limit), intval( $limit ) );
    432444
     
    437449
    438450                        switch ( $sort_by ) {
    439451                                default:
    440                                         $sql = $wpdb->prepare( "SELECT * FROM {$bp->groups->table_name} g {$public_sql} {$hidden_sql} {$order_sql} {$pag_sql}" );
     452                                        $sql = $wpdb->prepare( "SELECT * FROM {$bp->groups->table_name} g {$where_sql} {$order_sql} {$pag_sql}" );
    441453                                        break;
    442454                                case 'members':
    443                                         $sql = $wpdb->prepare( "SELECT * FROM {$bp->groups->table_name} g, {$bp->groups->table_name_groupmeta} gm WHERE g.id = gm.group_id AND gm.meta_key = 'total_member_count' {$hidden_sql} {$public_sql} ORDER BY CONVERT(gm.meta_value, SIGNED) {$order} {$pag_sql}" );
     455                                        $sql = $wpdb->prepare( "SELECT * FROM {$bp->groups->table_name} g, {$bp->groups->table_name_groupmeta} gm WHERE g.id = gm.group_id AND gm.meta_key = 'total_member_count' {$where_sql} ORDER BY CONVERT(gm.meta_value, SIGNED) {$order} {$pag_sql}" );
    444456                                        break;
    445457                                case 'last_active':
    446                                         $sql = $wpdb->prepare( "SELECT * FROM {$bp->groups->table_name} g, {$bp->groups->table_name_groupmeta} gm WHERE g.id = gm.group_id AND gm.meta_key = 'last_activity' {$hidden_sql} {$public_sql} ORDER BY CONVERT(gm.meta_value, SIGNED) {$order} {$pag_sql}" );
     458                                        $sql = $wpdb->prepare( "SELECT * FROM {$bp->groups->table_name} g, {$bp->groups->table_name_groupmeta} gm WHERE g.id = gm.group_id AND gm.meta_key = 'last_activity' {$where_sql} ORDER BY CONVERT(gm.meta_value, SIGNED) {$order} {$pag_sql}" );
    447459                                        break;
    448460                        }
    449461                } else {
    450                         $sql = $wpdb->prepare( "SELECT * FROM {$bp->groups->table_name} g {$public_sql} {$hidden_sql} {$order_sql} {$pag_sql}" );
    451  No newline at end of file
     462                        $sql = $wpdb->prepare( "SELECT * FROM {$bp->groups->table_name} g {$where_sql} {$order_sql} {$pag_sql}" );
     463 No newline at end of file
    452464                }
    453465