Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
11/22/2015 04:58:34 AM (9 years ago)
Author:
tw2113
Message:

More docs cleanup for BP-Groups component.

See #6401.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/bp-groups/classes/class-bp-groups-group.php

    r10248 r10373  
    145145     * Constructor method.
    146146     *
    147      * @param int|null $id Optional. If the ID of an existing group is provided,
    148      *                     the object will be pre-populated with info about that group.
     147     * @param int|null $id   Optional. If the ID of an existing group is provided,
     148     *                       the object will be pre-populated with info about that group.
    149149     * @param array    $args {
    150150     *     Array of optional arguments.
     
    171171        global $wpdb;
    172172
    173         // Get BuddyPress
     173        // Get BuddyPress.
    174174        $bp    = buddypress();
    175175
    176         // Check cache for group data
     176        // Check cache for group data.
    177177        $group = wp_cache_get( $this->id, 'bp_groups' );
    178178
    179         // Cache missed, so query the DB
     179        // Cache missed, so query the DB.
    180180        if ( false === $group ) {
    181181            $group = $wpdb->get_row( $wpdb->prepare( "SELECT g.* FROM {$bp->groups->table_name} g WHERE g.id = %d", $this->id ) );
     
    184184        }
    185185
    186         // No group found so set the ID and bail
     186        // No group found so set the ID and bail.
    187187        if ( empty( $group ) || is_wp_error( $group ) ) {
    188188            $this->id = 0;
     
    190190        }
    191191
    192         // Group found so setup the object variables
     192        // Group found so setup the object variables.
    193193        $this->id           = $group->id;
    194194        $this->creator_id   = $group->creator_id;
     
    212212            $admin_mods = $wpdb->get_results( apply_filters( 'bp_group_admin_mods_user_join_filter', $wpdb->prepare( "SELECT u.ID as user_id, u.user_login, u.user_email, u.user_nicename, m.is_admin, m.is_mod FROM {$wpdb->users} u, {$bp->groups->table_name_members} m WHERE u.ID = m.user_id AND m.group_id = %d AND ( m.is_admin = 1 OR m.is_mod = 1 )", $this->id ) ) );
    213213
    214             // Add admins and moderators to their respective arrays
     214            // Add admins and moderators to their respective arrays.
    215215            foreach ( (array) $admin_mods as $user ) {
    216216                if ( !empty( $user->is_admin ) ) {
     
    222222
    223223            // Set up some specific group vars from meta. Excluded
    224             // from the bp_groups cache because it's cached independently
     224            // from the bp_groups cache because it's cached independently.
    225225            $this->last_activity      = groups_get_groupmeta( $this->id, 'last_activity' );
    226226            $this->total_member_count = groups_get_groupmeta( $this->id, 'total_member_count' );
    227227
    228             // Set user-specific data
     228            // Set user-specific data.
    229229            $user_id          = bp_loggedin_user_id();
    230230            $this->is_member  = BP_Groups_Member::check_is_member( $user_id, $this->id );
     
    235235            if ( ( 'private' === $this->status ) || ( 'hidden' === $this->status ) ) {
    236236
    237                 // Assume user does not have access to hidden/private groups
     237                // Assume user does not have access to hidden/private groups.
    238238                $this->user_has_access = false;
    239239
    240                 // Group members or community moderators have access
     240                // Group members or community moderators have access.
    241241                if ( ( $this->is_member && is_user_logged_in() ) || bp_current_user_can( 'bp_moderate' ) ) {
    242242                    $this->user_has_access = true;
     
    277277        do_action_ref_array( 'groups_group_before_save', array( &$this ) );
    278278
    279         // Groups need at least a name
     279        // Groups need at least a name.
    280280        if ( empty( $this->name ) ) {
    281281            return false;
    282282        }
    283283
    284         // Set slug with group title if not passed
     284        // Set slug with group title if not passed.
    285285        if ( empty( $this->slug ) ) {
    286286            $this->slug = sanitize_title( $this->name );
    287287        }
    288288
    289         // Sanity check
     289        // Sanity check.
    290290        if ( empty( $this->slug ) ) {
    291291            return false;
    292292        }
    293293
    294         // Check for slug conflicts if creating new group
     294        // Check for slug conflicts if creating new group.
    295295        if ( empty( $this->id ) ) {
    296296            $this->slug = groups_check_slug( $this->slug );
     
    370370        global $wpdb;
    371371
    372         // Delete groupmeta for the group
     372        // Delete groupmeta for the group.
    373373        groups_delete_groupmeta( $this->id );
    374374
    375         // Fetch the user IDs of all the members of the group
     375        // Fetch the user IDs of all the members of the group.
    376376        $user_ids    = BP_Groups_Member::get_group_member_ids( $this->id );
    377377        $user_id_str = esc_sql( implode( ',', wp_parse_id_list( $user_ids ) ) );
    378378
    379         // Modify group count usermeta for members
     379        // Modify group count usermeta for members.
    380380        $wpdb->query( "UPDATE {$wpdb->usermeta} SET meta_value = meta_value - 1 WHERE meta_key = 'total_group_count' AND user_id IN ( {$user_id_str} )" );
    381381
    382         // Now delete all group member entries
     382        // Now delete all group member entries.
    383383        BP_Groups_Member::delete_all( $this->id );
    384384
     
    397397        $bp = buddypress();
    398398
    399         // Finally remove the group entry from the DB
     399        // Finally remove the group entry from the DB.
    400400        if ( !$wpdb->query( $wpdb->prepare( "DELETE FROM {$bp->groups->table_name} WHERE id = %d", $this->id ) ) )
    401401            return false;
     
    412412     * @param string|bool $table_name Optional. Name of the table to check
    413413     *                                against. Default: $bp->groups->table_name.
    414      *
    415414     * @return string|null ID of the group, if one is found, else null.
    416415     */
     
    433432     *
    434433     * @param string $slug See {@link BP_Groups_Group::group_exists()}.
    435      *
    436434     * @return string|null See {@link BP_Groups_Group::group_exists()}.
    437435     */
     
    445443     * @param int $user_id ID of the inviting user.
    446444     * @param int $group_id ID of the group.
    447      *
    448445     * @return array IDs of users who have been invited to the group by the
    449446     *               user but have not yet accepted.
     
    515512     *        sort).
    516513     * @param string|bool $order   ASC or DESC. Default: false (default sort).
    517      *
    518514     * @return array {
    519515     *     @type array $groups Array of matched and paginated group objects.
     
    552548     *
    553549     * @param string $slug Slug to check.
    554      *
    555550     * @return string|null The slug, if found. Otherwise null.
    556551     */
     
    567562     *
    568563     * @param int $group_id ID of the group.
    569      *
    570564     * @return string|null The slug, if found. Otherwise null.
    571565     */
     
    582576     *
    583577     * @param int $group_id ID of the group.
    584      *
    585578     * @return bool True if the group has members, otherwise false.
    586579     */
     
    602595     *
    603596     * @param int $group_id ID of the group.
    604      *
    605597     * @return int|null The number of outstanding requests, or null if
    606598     *                  none are found.
     
    649641     *      parameter format.
    650642     *
    651      * @param array {
     643     * @param array $args {
    652644     *     Array of parameters. All items are optional.
    653645     *     @type string       $type              Optional. Shorthand for certain orderby/
     
    692684        global $wpdb;
    693685
    694         // Backward compatibility with old method of passing arguments
     686        // Backward compatibility with old method of passing arguments.
    695687        if ( ! is_array( $args ) || func_num_args() > 1 ) {
    696688            _deprecated_argument( __METHOD__, '1.7', sprintf( __( 'Arguments passed to %1$s should be in an associative array. See the inline documentation at %2$s for more details.', 'buddypress' ), __METHOD__, __FILE__ ) );
     
    783775        }
    784776
    785         /** Order/orderby ********************************************/
     777        /* Order/orderby ********************************************/
    786778
    787779        $order   = $r['order'];
     
    789781
    790782        // If a 'type' parameter was passed, parse it and overwrite
    791         // 'order' and 'orderby' params passed to the function
     783        // 'order' and 'orderby' params passed to the function.
    792784        if (  ! empty( $r['type'] ) ) {
    793785
     
    804796            // If an invalid type is passed, $order_orderby will be
    805797            // an array with empty values. In this case, we stick
    806             // with the default values of $order and $orderby
     798            // with the default values of $order and $orderby.
    807799            if ( ! empty( $order_orderby['order'] ) ) {
    808800                $order = $order_orderby['order'];
     
    814806        }
    815807
    816         // Sanitize 'order'
     808        // Sanitize 'order'.
    817809        $order = bp_esc_sql_order( $order );
    818810
     
    828820        $orderby = apply_filters( 'bp_groups_get_orderby_converted_by_term', self::convert_orderby_to_order_by_term( $orderby ), $orderby, $r['type'] );
    829821
    830         // Random order is a special case
     822        // Random order is a special case.
    831823        if ( 'rand()' === $orderby ) {
    832824            $sql[] = "ORDER BY rand()";
     
    870862
    871863        // Temporary implementation of meta_query for total count
    872         // See #5099
     864        // See #5099.
    873865        if ( ! empty( $meta_query_sql['where'] ) ) {
    874             // Join the groupmeta table
     866            // Join the groupmeta table.
    875867            $total_sql['select'] .= ", ". substr( $meta_query_sql['join'], 0, -2 );
    876868
    877             // Modify the meta_query clause from paged_sql for our syntax
     869            // Modify the meta_query clause from paged_sql for our syntax.
    878870            $meta_query_clause = preg_replace( '/^\s*AND/', '', $meta_query_sql['where'] );
    879871            $total_sql['where'][] = $meta_query_clause;
    880872        }
    881873
    882         // Already escaped in the paginated results block
     874        // Already escaped in the paginated results block.
    883875        if ( ! empty( $include ) ) {
    884876            $total_sql['where'][] = "g.id IN ({$include})";
    885877        }
    886878
    887         // Already escaped in the paginated results block
     879        // Already escaped in the paginated results block.
    888880        if ( ! empty( $exclude ) ) {
    889881            $total_sql['where'][] = "g.id NOT IN ({$exclude})";
     
    916908        }
    917909
    918         // Populate some extra information instead of querying each time in the loop
     910        // Populate some extra information instead of querying each time in the loop.
    919911        if ( !empty( $r['populate_extras'] ) ) {
    920912            $paged_groups = BP_Groups_Group::get_group_extras( $paged_groups, $group_ids, $r['type'] );
    921913        }
    922914
    923         // Grab all groupmeta
     915        // Grab all groupmeta.
    924916        if ( ! empty( $r['update_meta_cache'] ) ) {
    925917            bp_groups_update_meta_cache( $group_ids );
     
    944936     * @param array $meta_query An array of meta_query filters. See the
    945937     *                          documentation for {@link WP_Meta_Query} for details.
    946      *
    947938     * @return array $sql_array 'join' and 'where' clauses.
    948939     */
     
    959950
    960951            // WP_Meta_Query expects the table name at
    961             // $wpdb->group
     952            // $wpdb->group.
    962953            $wpdb->groupmeta = buddypress()->groups->table_name_groupmeta;
    963954
     
    971962            // @todo It may be better in the long run to refactor
    972963            // the more general query syntax to accord better with
    973             // BP/WP convention
     964            // BP/WP convention.
    974965            preg_match_all( '/JOIN (.+?) ON/', $meta_sql['join'], $matches_a );
    975966            preg_match_all( '/ON \((.+?)\)/', $meta_sql['join'], $matches_b );
     
    992983     *
    993984     * @return array {
    994      *  @type string $order   SQL-friendly order string.
    995      *  @type string $orderby SQL-friendly orderby column name.
     985     *     @type string $order   SQL-friendly order string.
     986     *     @type string $orderby SQL-friendly orderby column name.
    996987     * }
    997988     */
     
    10441035     * @param string|array|bool $exclude         Optional. Array or comma-separated list of group
    10451036     *                                           IDs to exclude from results.
    1046      *
    10471037     * @return array {
    10481038     *     @type array $groups Array of group objects returned by the
     
    11051095     *
    11061096     * @param string $orderby Orderby term as passed to get().
    1107      *
    11081097     * @return string $order_by_term SQL-friendly orderby term.
    11091098     */
     
    11501139     * @param string|array|bool $exclude         Optional. Array or comma-separated list of group
    11511140     *                                           IDs to exclude from results.
    1152      *
    11531141     * @return array {
    11541142     *     @type array $groups Array of group objects returned by the
     
    12291217        $pag_sql = $hidden_sql = $exclude_sql = '';
    12301218
    1231         // Multibyte compliance
     1219        // Multibyte compliance.
    12321220        if ( function_exists( 'mb_strlen' ) ) {
    12331221            if ( mb_strlen( $letter, 'UTF-8' ) > 1 || is_numeric( $letter ) || !$letter ) {
     
    12871275     * @param string|array|bool $exclude         Optional. Array or comma-separated list of group
    12881276     *                                           IDs to exclude from results.
    1289      *
    12901277     * @return array {
    12911278     *     @type array $groups Array of group objects returned by the
     
    13451332     *
    13461333     * Data fetched:
    1347      *
    13481334     *     - Logged-in user's status within each group (is_member,
    13491335     *       is_confirmed, is_pending, is_banned)
     
    13531339     *                                   $paged_groups.
    13541340     * @param string|bool  $type         Not used.
    1355      *
    13561341     * @return array $paged_groups
    13571342     */
     
    13641349        $bp = buddypress();
    13651350
    1366         // Sanitize group IDs
     1351        // Sanitize group IDs.
    13671352        $group_ids = implode( ',', wp_parse_id_list( $group_ids ) );
    13681353
    1369         // Fetch the logged-in user's status within each group
     1354        // Fetch the logged-in user's status within each group.
    13701355        if ( is_user_logged_in() ) {
    13711356            $user_status_results = $wpdb->get_results( $wpdb->prepare( "SELECT group_id, is_confirmed, invite_sent FROM {$bp->groups->table_name_members} WHERE user_id = %d AND group_id IN ( {$group_ids} ) AND is_banned = 0", bp_loggedin_user_id() ) );
     
    13741359        }
    13751360
    1376         // Reindex
     1361        // Reindex.
    13771362        $user_status = array();
    13781363        foreach ( $user_status_results as $user_status_result ) {
     
    13861371            if ( isset( $user_status[ $gid ] ) ) {
    13871372
    1388                 // is_confirmed means the user is a member
     1373                // The is_confirmed means the user is a member.
    13891374                if ( $user_status[ $gid ]->is_confirmed ) {
    13901375                    $is_member = '1';
    13911376
    1392                 // invite_sent means the user has been invited
     1377                // The invite_sent means the user has been invited.
    13931378                } elseif ( $user_status[ $gid ]->invite_sent ) {
    13941379                    $is_invited = '1';
    13951380
    1396                 // User has sent request, but has not been confirmed
     1381                // User has sent request, but has not been confirmed.
    13971382                } else {
    13981383                    $is_pending = '1';
     
    14281413     *
    14291414     * @param int $group_id ID of the group whose invitations are being deleted.
    1430      *
    14311415     * @return int|null Number of rows records deleted on success, null on
    14321416     *                  failure.
     
    14651449     * @param string $type Optional. If 'unreplied', count will be limited to
    14661450     *                     those topics that have received no replies.
    1467      *
    14681451     * @return int Forum topic count.
    14691452     */
     
    14791462         * Filters the portion of the SQL related to global count of forum topics in public groups.
    14801463         *
    1481          * https://buddypress.trac.wordpress.org/ticket/4306.
     1464         * See https://buddypress.trac.wordpress.org/ticket/4306.
    14821465         *
    14831466         * @since 1.6.0
     
    14881471        $extra_sql = apply_filters( 'get_global_forum_topic_count_extra_sql', $bp->groups->filter_sql, $type );
    14891472
    1490         // Make sure the $extra_sql begins with an AND
     1473        // Make sure the $extra_sql begins with an AND.
    14911474        if ( 'AND' != substr( trim( strtoupper( $extra_sql ) ), 0, 3 ) )
    14921475            $extra_sql = ' AND ' . $extra_sql;
     
    14991482     *
    15001483     * @param int $group_id Group ID.
    1501      *
    15021484     * @return int Count of confirmed members for the group.
    15031485     */
     
    15181500     *                                  'hidden', or 'all'. Default: 'public'.
    15191501     * @param string|bool $search_terms Provided search terms.
    1520      *
    15211502     * @return int The topic count
    15221503     */
Note: See TracChangeset for help on using the changeset viewer.