Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
11/15/2015 07:13:42 PM (11 years ago)
Author:
tw2113
Message:

More documentation cleanup for part of BP-Core component.

See #6398.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/bp-core/classes/class-bp-user-query.php

    r10248 r10355  
    147147    public function __construct( $query = null ) {
    148148
    149         // Store the raw query vars for later access
     149        // Store the raw query vars for later access.
    150150        $this->query_vars_raw = $query;
    151151
    152         // Allow extending classes to register action/filter hooks
     152        // Allow extending classes to register action/filter hooks.
    153153        $this->setup_hooks();
    154154
     
    184184
    185185            // Get user ids
    186             // If the user_ids param is present, we skip the query
     186            // If the user_ids param is present, we skip the query.
    187187            if ( false !== $this->query_vars['user_ids'] ) {
    188188                $this->user_ids = wp_parse_id_list( $this->query_vars['user_ids'] );
     
    193193        }
    194194
    195         // Bail if no user IDs were found
     195        // Bail if no user IDs were found.
    196196        if ( empty( $this->user_ids ) ) {
    197197            return;
    198198        }
    199199
    200         // Fetch additional data. First, using WP_User_Query
     200        // Fetch additional data. First, using WP_User_Query.
    201201        $this->do_wp_user_query();
    202202
    203         // Get BuddyPress specific user data
     203        // Get BuddyPress specific user data.
    204204        $this->populate_extras();
    205205    }
     
    231231        $bp = buddypress();
    232232
    233         // Default query variables used here
     233        // Default query variables used here.
    234234        $type         = '';
    235235        $per_page     = 0;
     
    244244        extract( $this->query_vars );
    245245
    246         // Setup the main SQL query container
     246        // Setup the main SQL query container.
    247247        $sql = array(
    248248            'select'  => '',
     
    253253        );
    254254
    255         /** TYPE **************************************************************/
     255        /* TYPE **************************************************************/
    256256
    257257        // Determines the sort order, which means it also determines where the
    258         // user IDs are drawn from (the SELECT and WHERE statements)
     258        // user IDs are drawn from (the SELECT and WHERE statements).
    259259        switch ( $type ) {
    260260
    261261            // 'online' query happens against the last_activity usermeta key
    262262            // Filter 'bp_user_query_online_interval' to modify the
    263             // number of minutes used as an interval
     263            // number of minutes used as an interval.
    264264            case 'online' :
    265265                $this->uid_name = 'user_id';
     
    282282
    283283            // 'active', 'newest', and 'random' queries
    284             // all happen against the last_activity usermeta key
     284            // all happen against the last_activity usermeta key.
    285285            case 'active' :
    286286            case 'newest' :
     
    303303                break;
    304304
    305             // 'popular' sorts by the 'total_friend_count' usermeta
     305            // 'popular' sorts by the 'total_friend_count' usermeta.
    306306            case 'popular' :
    307307                $this->uid_name = 'user_id';
     
    314314                break;
    315315
    316             // 'alphabetical' sorts depend on the xprofile setup
     316            // 'alphabetical' sorts depend on the xprofile setup.
    317317            case 'alphabetical' :
    318318
     
    321321                // can do so if xprofile sync is enabled, or if xprofile is inactive.
    322322                //
    323                 // @todo remove need for bp_is_active() check
     323                // @todo remove need for bp_is_active() check.
    324324                if ( ! bp_disable_profile_sync() || ! bp_is_active( 'xprofile' ) ) {
    325325                    $this->uid_name = 'ID';
     
    330330
    331331                // When profile sync is disabled, alphabetical sorts must happen against
    332                 // the xprofile table
     332                // the xprofile table.
    333333                } else {
    334334                    $this->uid_name = 'user_id';
     
    347347                break;
    348348
    349             // Any other 'type' falls through
     349            // Any other 'type' falls through.
    350350            default :
    351351                $this->uid_name = 'ID';
     
    355355                // In this case, we assume that a plugin is
    356356                // handling order, so we leave those clauses
    357                 // blank
    358 
     357                // blank.
    359358                break;
    360359        }
    361360
    362         /** WHERE *************************************************************/
    363 
    364         // 'include' - User ids to include in the results
     361        /* WHERE *************************************************************/
     362
     363        // 'include' - User ids to include in the results.
    365364        $include     = false !== $include ? wp_parse_id_list( $include ) : array();
    366365        $include_ids = $this->get_include_ids( $include );
     
    370369        }
    371370
    372         // 'exclude' - User ids to exclude from the results
     371        // 'exclude' - User ids to exclude from the results.
    373372        if ( false !== $exclude ) {
    374373            $exclude_ids    = implode( ',', wp_parse_id_list( $exclude ) );
     
    377376
    378377        // 'user_id' - When a user id is passed, limit to the friends of the user
    379         // @todo remove need for bp_is_active() check
     378        // @todo remove need for bp_is_active() check.
    380379        if ( ! empty( $user_id ) && bp_is_active( 'friends' ) ) {
    381380            $friend_ids = friends_get_friend_user_ids( $user_id );
     
    386385
    387386            // If the user has no friends, the query should always
    388             // return no users
     387            // return no users.
    389388            } else {
    390389                $sql['where'][] = $this->no_results['where'];
     
    392391        }
    393392
    394         /** Search Terms ******************************************************/
     393        /* Search Terms ******************************************************/
    395394
    396395        // 'search_terms' searches user_login and user_nicename
    397         // xprofile field matches happen in bp_xprofile_bp_user_query_search()
     396        // xprofile field matches happen in bp_xprofile_bp_user_query_search().
    398397        if ( false !== $search_terms ) {
    399398            $search_terms = bp_esc_like( wp_kses_normalize_entities( $search_terms ) );
     
    438437
    439438        // 'meta_key', 'meta_value' allow usermeta search
    440         // To avoid global joins, do a separate query
     439        // To avoid global joins, do a separate query.
    441440        if ( false !== $meta_key ) {
    442441            $meta_sql = $wpdb->prepare( "SELECT user_id FROM {$wpdb->usermeta} WHERE meta_key = %s", $meta_key );
     
    455454        }
    456455
    457         // 'per_page', 'page' - handles LIMIT
     456        // 'per_page', 'page' - handles LIMIT.
    458457        if ( !empty( $per_page ) && !empty( $page ) ) {
    459458            $sql['limit'] = $wpdb->prepare( "LIMIT %d, %d", intval( ( $page - 1 ) * $per_page ), intval( $per_page ) );
     
    472471        $sql = apply_filters_ref_array( 'bp_user_query_uid_clauses', array( $sql, &$this ) );
    473472
    474         // Assemble the query chunks
     473        // Assemble the query chunks.
    475474        $this->uid_clauses['select']  = $sql['select'];
    476475        $this->uid_clauses['where']   = ! empty( $sql['where'] ) ? 'WHERE ' . implode( ' AND ', $sql['where'] ) : '';
     
    502501        global $wpdb;
    503502
    504         // If counting using SQL_CALC_FOUND_ROWS, set it up here
     503        // If counting using SQL_CALC_FOUND_ROWS, set it up here.
    505504        if ( 'sql_calc_found_rows' == $this->query_vars['count_total'] ) {
    506505            $this->uid_clauses['select'] = str_replace( 'SELECT', 'SELECT SQL_CALC_FOUND_ROWS', $this->uid_clauses['select'] );
    507506        }
    508507
    509         // Get the specific user ids
     508        // Get the specific user ids.
    510509        $this->user_ids = $wpdb->get_col( "{$this->uid_clauses['select']} {$this->uid_clauses['where']} {$this->uid_clauses['orderby']} {$this->uid_clauses['order']} {$this->uid_clauses['limit']}" );
    511510
    512         // Get the total user count
     511        // Get the total user count.
    513512        if ( 'sql_calc_found_rows' == $this->query_vars['count_total'] ) {
    514513
     
    557556        $wp_user_query = new WP_User_Query( apply_filters( 'bp_wp_user_query_args', array(
    558557
    559             // Relevant
     558            // Relevant.
    560559            'fields'      => $fields,
    561560            'include'     => $this->user_ids,
    562561
    563562            // Overrides
    564             'blog_id'     => 0,    // BP does not require blog roles
    565             'count_total' => false // We already have a count
     563            'blog_id'     => 0,    // BP does not require blog roles.
     564            'count_total' => false // We already have a count.
    566565
    567566        ), $this ) );
     
    583582        }
    584583
    585         // Reindex for easier matching
     584        // Reindex for easier matching.
    586585        $r = array();
    587586        foreach ( $wp_user_query->results as $u ) {
     
    589588        }
    590589
    591         // Match up to the user ids from the main query
     590        // Match up to the user ids from the main query.
    592591        foreach ( $this->user_ids as $key => $uid ) {
    593592            if ( isset( $r[ $uid ] ) ) {
     
    595594
    596595                // The BP template functions expect an 'id'
    597                 // (as opposed to 'ID') property
     596                // (as opposed to 'ID') property.
    598597                $this->results[ $uid ]->id = $uid;
    599598
    600             // remove user ID from original user_ids property
     599            // Remove user ID from original user_ids property.
    601600            } else {
    602601                unset( $this->user_ids[ $key ] );
     
    619618     * @param array $include Sanitized array of user IDs, as passed to the 'include'
    620619     *                       parameter of the class constructor.
    621      *
    622620     * @return array The list of users to which the main query should be
    623621     *               limited.
     
    640638        global $wpdb;
    641639
    642         // Bail if no users
     640        // Bail if no users.
    643641        if ( empty( $this->user_ids ) || empty( $this->results ) ) {
    644642            return;
     
    647645        // Bail if the populate_extras flag is set to false
    648646        // In the case of the 'popular' sort type, we force
    649         // populate_extras to true, because we need the friend counts
     647        // populate_extras to true, because we need the friend counts.
    650648        if ( 'popular' == $this->query_vars['type'] ) {
    651649            $this->query_vars['populate_extras'] = 1;
     
    656654        }
    657655
    658         // Turn user ID's into a query-usable, comma separated value
     656        // Turn user ID's into a query-usable, comma separated value.
    659657        $user_ids_sql = implode( ',', wp_parse_id_list( $this->user_ids ) );
    660658
     
    679677        do_action_ref_array( 'bp_user_query_populate_extras', array( $this, $user_ids_sql ) );
    680678
    681         // Fetch last_active data from the activity table
     679        // Fetch last_active data from the activity table.
    682680        $last_activities = BP_Core_User::get_last_activity( $this->user_ids );
    683681
    684         // Set a last_activity value for each user, even if it's empty
     682        // Set a last_activity value for each user, even if it's empty.
    685683        foreach ( $this->results as $user_id => $user ) {
    686684            $user_last_activity = isset( $last_activities[ $user_id ] ) ? $last_activities[ $user_id ]['date_recorded'] : '';
     
    691689        // We want the three following pieces of info from usermeta:
    692690        // - friend count
    693         // - latest update
     691        // - latest update.
    694692        $total_friend_count_key = bp_get_user_meta_key( 'total_friend_count' );
    695693        $bp_latest_update_key   = bp_get_user_meta_key( 'bp_latest_update'   );
    696694
    697         // total_friend_count must be set for each user, even if its
    698         // value is 0
     695        // Total_friend_count must be set for each user, even if its
     696        // value is 0.
    699697        foreach ( $this->results as $uindex => $user ) {
    700698            $this->results[$uindex]->total_friend_count = 0;
    701699        }
    702700
    703         // Create, prepare, and run the separate usermeta query
     701        // Create, prepare, and run the separate usermeta query.
    704702        $user_metas = $wpdb->get_results( $wpdb->prepare( "SELECT user_id, meta_key, meta_value FROM {$wpdb->usermeta} WHERE meta_key IN (%s,%s) AND user_id IN ({$user_ids_sql})", $total_friend_count_key, $bp_latest_update_key ) );
    705703
     
    723721
    724722        // When meta_key or meta_value have been passed to the query,
    725         // fetch the resulting values for use in the template functions
     723        // fetch the resulting values for use in the template functions.
    726724        if ( ! empty( $this->query_vars['meta_key'] ) ) {
    727725            $meta_sql = array(
     
    758756     * @param string|array $member_types Array or comma-separated list of member types.
    759757     * @param string       $operator     'IN' or 'NOT IN'.
    760      *
    761758     * @return string
    762759     */
     
    805802        $clause = '';
    806803
    807         // no_results clauses are the same between IN and NOT IN.
     804        // The no_results clauses are the same between IN and NOT IN.
    808805        if ( false !== strpos( $sql_clauses['where'], '0 = 1' ) ) {
    809806            $clause = $this->no_results['where'];
Note: See TracChangeset for help on using the changeset viewer.