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-member.php

    r10248 r10373  
    131131    public function __construct( $user_id = 0, $group_id = 0, $id = false, $populate = true ) {
    132132
    133         // User and group are not empty, and ID is
     133        // User and group are not empty, and ID is.
    134134        if ( !empty( $user_id ) && !empty( $group_id ) && empty( $id ) ) {
    135135            $this->user_id  = $user_id;
     
    141141        }
    142142
    143         // ID is not empty
     143        // ID is not empty.
    144144        if ( !empty( $id ) ) {
    145145            $this->id = $id;
     
    226226            $sql = $wpdb->prepare( "UPDATE {$bp->groups->table_name_members} SET inviter_id = %d, is_admin = %d, is_mod = %d, is_banned = %d, user_title = %s, date_modified = %s, is_confirmed = %d, comments = %s, invite_sent = %d WHERE id = %d", $this->inviter_id, $this->is_admin, $this->is_mod, $this->is_banned, $this->user_title, $this->date_modified, $this->is_confirmed, $this->comments, $this->invite_sent, $this->id );
    227227        } else {
    228             // Ensure that user is not already a member of the group before inserting
     228            // Ensure that user is not already a member of the group before inserting.
    229229            if ( $wpdb->get_var( $wpdb->prepare( "SELECT id FROM {$bp->groups->table_name_members} WHERE user_id = %d AND group_id = %d AND is_confirmed = 1 LIMIT 1", $this->user_id, $this->group_id ) ) ) {
    230230                return false;
     
    239239        $this->id = $wpdb->insert_id;
    240240
    241         // Update the user's group count
     241        // Update the user's group count.
    242242        self::refresh_total_group_count_for_user( $this->user_id );
    243243
    244         // Update the group's member count
     244        // Update the group's member count.
    245245        self::refresh_total_member_count_for_group( $this->group_id );
    246246
     
    263263     *
    264264     * @param string $status The new status. 'mod' or 'admin'.
    265      *
    266265     * @return bool True on success, false on failure.
    267266     */
     
    364363            return false;
    365364
    366         // Update the user's group count
     365        // Update the user's group count.
    367366        self::refresh_total_group_count_for_user( $this->user_id );
    368367
    369         // Update the group's member count
     368        // Update the group's member count.
    370369        self::refresh_total_member_count_for_group( $this->group_id );
    371370
     
    390389     *
    391390     * @param int $user_id ID of the user.
    392      *
    393391     * @return bool True on success, false on failure.
    394392     */
     
    403401     *
    404402     * @param int $group_id ID of the group.
    405      *
    406403     * @return bool True on success, false on failure.
    407404     */
     
    415412     * @param int $user_id  ID of the user.
    416413     * @param int $group_id ID of the group.
    417      *
    418414     * @return True on success, false on failure.
    419415     */
     
    434430        $remove = $wpdb->query( $wpdb->prepare( "DELETE FROM {$bp->groups->table_name_members} WHERE user_id = %d AND group_id = %d", $user_id, $group_id ) );
    435431
    436         // Update the user's group count
     432        // Update the user's group count.
    437433        self::refresh_total_group_count_for_user( $user_id );
    438434
    439         // Update the group's member count
     435        // Update the group's member count.
    440436        self::refresh_total_member_count_for_group( $group_id );
    441437
     
    475471        $bp = buddypress();
    476472
    477         // If the user is logged in and viewing their own groups, we can show hidden and private groups
     473        // If the user is logged in and viewing their own groups, we can show hidden and private groups.
    478474        if ( $user_id != bp_loggedin_user_id() ) {
    479475            $group_sql = $wpdb->prepare( "SELECT DISTINCT m.group_id FROM {$bp->groups->table_name_members} m, {$bp->groups->table_name} g WHERE g.status != 'hidden' AND m.user_id = %d AND m.is_confirmed = 1 AND m.is_banned = 0{$pag_sql}", $user_id );
     
    540536     * @param string|bool $filter  Optional. Limit results to groups whose name or
    541537     *                             description field matches search terms.
    542      *
    543538     * @return array {
    544539     *     @type array $groups Array of groups returned by paginated query.
     
    574569    /**
    575570     * Get the IDs of the groups of which a specified user is a moderator.
    576      *
    577      * @param int         $user_id ID of the user.
    578      * @param int|bool    $limit   Optional. Max number of results to return.
    579      *                             Default: false (no limit).
    580      * @param int|bool    $page    Optional. Page offset of results to return.
    581      *                             Default: false (no limit).
    582      * @param string|bool $filter  Optional. Limit results to groups whose name or
    583      *                             description field matches search terms.
    584      *
    585      * @return array {
    586      *     @type array $groups Array of groups returned by paginated query.
    587      *     @type int   $total  Count of groups matching query.
    588      * }
    589      */
    590     public static function get_is_mod_of( $user_id, $limit = false, $page = false, $filter = false ) {
    591         global $wpdb;
    592 
    593         $user_id_sql = $pag_sql = $hidden_sql = $filter_sql = '';
    594 
    595         $user_id_sql = $wpdb->prepare( 'm.user_id = %d', $user_id );
    596 
    597         if ( !empty( $limit ) && !empty( $page ) )
    598             $pag_sql = $wpdb->prepare( " LIMIT %d, %d", intval( ( $page - 1 ) * $limit), intval( $limit ) );
    599 
    600         if ( !empty( $filter ) ) {
    601             $search_terms_like = '%' . bp_esc_like( $filter ) . '%';
    602             $filter_sql = $wpdb->prepare( " AND ( g.name LIKE %s OR g.description LIKE %s )", $search_terms_like, $search_terms_like );
    603         }
    604 
    605         if ( $user_id != bp_loggedin_user_id() )
    606             $hidden_sql = " AND g.status != 'hidden'";
    607 
    608         $bp = buddypress();
    609 
    610         $paged_groups = $wpdb->get_results( "SELECT g.*, gm1.meta_value as total_member_count, gm2.meta_value as last_activity FROM {$bp->groups->table_name_groupmeta} gm1, {$bp->groups->table_name_groupmeta} gm2, {$bp->groups->table_name_members} m, {$bp->groups->table_name} g WHERE g.id = m.group_id AND g.id = gm1.group_id AND g.id = gm2.group_id AND gm2.meta_key = 'last_activity' AND gm1.meta_key = 'total_member_count'{$hidden_sql}{$filter_sql} AND {$user_id_sql} AND m.is_confirmed = 1 AND m.is_banned = 0 AND m.is_mod = 1 ORDER BY m.date_modified ASC {$pag_sql}" );
    611         $total_groups = $wpdb->get_var( "SELECT COUNT(DISTINCT m.group_id) FROM {$bp->groups->table_name_members} m, {$bp->groups->table_name} g WHERE m.group_id = g.id{$hidden_sql}{$filter_sql} AND {$user_id_sql} AND m.is_confirmed = 1 AND m.is_banned = 0 AND m.is_mod = 1 ORDER BY date_modified ASC" );
    612 
    613         return array( 'groups' => $paged_groups, 'total' => $total_groups );
    614     }
    615 
    616     /**
    617      * Get the groups of which a specified user is banned from.
    618      *
    619      * @since 2.4
    620571     *
    621572     * @param int         $user_id ID of the user.
     
    631582     * }
    632583     */
     584    public static function get_is_mod_of( $user_id, $limit = false, $page = false, $filter = false ) {
     585        global $wpdb;
     586
     587        $user_id_sql = $pag_sql = $hidden_sql = $filter_sql = '';
     588
     589        $user_id_sql = $wpdb->prepare( 'm.user_id = %d', $user_id );
     590
     591        if ( !empty( $limit ) && !empty( $page ) )
     592            $pag_sql = $wpdb->prepare( " LIMIT %d, %d", intval( ( $page - 1 ) * $limit), intval( $limit ) );
     593
     594        if ( !empty( $filter ) ) {
     595            $search_terms_like = '%' . bp_esc_like( $filter ) . '%';
     596            $filter_sql = $wpdb->prepare( " AND ( g.name LIKE %s OR g.description LIKE %s )", $search_terms_like, $search_terms_like );
     597        }
     598
     599        if ( $user_id != bp_loggedin_user_id() )
     600            $hidden_sql = " AND g.status != 'hidden'";
     601
     602        $bp = buddypress();
     603
     604        $paged_groups = $wpdb->get_results( "SELECT g.*, gm1.meta_value as total_member_count, gm2.meta_value as last_activity FROM {$bp->groups->table_name_groupmeta} gm1, {$bp->groups->table_name_groupmeta} gm2, {$bp->groups->table_name_members} m, {$bp->groups->table_name} g WHERE g.id = m.group_id AND g.id = gm1.group_id AND g.id = gm2.group_id AND gm2.meta_key = 'last_activity' AND gm1.meta_key = 'total_member_count'{$hidden_sql}{$filter_sql} AND {$user_id_sql} AND m.is_confirmed = 1 AND m.is_banned = 0 AND m.is_mod = 1 ORDER BY m.date_modified ASC {$pag_sql}" );
     605        $total_groups = $wpdb->get_var( "SELECT COUNT(DISTINCT m.group_id) FROM {$bp->groups->table_name_members} m, {$bp->groups->table_name} g WHERE m.group_id = g.id{$hidden_sql}{$filter_sql} AND {$user_id_sql} AND m.is_confirmed = 1 AND m.is_banned = 0 AND m.is_mod = 1 ORDER BY date_modified ASC" );
     606
     607        return array( 'groups' => $paged_groups, 'total' => $total_groups );
     608    }
     609
     610    /**
     611     * Get the groups of which a specified user is banned from.
     612     *
     613     * @since 2.4
     614     *
     615     * @param int         $user_id ID of the user.
     616     * @param int|bool    $limit   Optional. Max number of results to return.
     617     *                             Default: false (no limit).
     618     * @param int|bool    $page    Optional. Page offset of results to return.
     619     *                             Default: false (no limit).
     620     * @param string|bool $filter  Optional. Limit results to groups whose name or
     621     *                             description field matches search terms.
     622     * @return array {
     623     *     @type array $groups Array of groups returned by paginated query.
     624     *     @type int   $total  Count of groups matching query.
     625     * }
     626     */
    633627    public static function get_is_banned_of( $user_id, $limit = false, $page = false, $filter = false ) {
    634628        global $wpdb;
     
    662656     *
    663657     * @param int $user_id Optional. Default: ID of the displayed user.
    664      *
    665658     * @return int Group count.
    666659     */
     
    690683     * @param string|array|bool $exclude Optional. Array or comma-separated list
    691684     *                                   of group IDs to exclude from results.
    692      *
    693685     * @return array {
    694686     *     @type array $groups Array of groups returned by paginated query.
     
    721713     *
    722714     * @param int $user_id The user ID.
    723      *
    724715     * @return int
    725716     */
     
    746737     * @param string $type     If 'sent', results are limited to those invitations
    747738     *                         that have actually been sent (non-draft). Default: 'sent'.
    748      *
    749739     * @return int|null The ID of the invitation if found, otherwise null.
    750740     */
     
    771761     * @param  int $user_id  ID of the user.
    772762     * @param  int $group_id ID of the group.
    773      *
    774763     * @return int Number of records deleted.
    775764     */
     
    799788     * @param int $user_id  ID of the user.
    800789     * @param int $group_id ID of the group.
    801      *
    802790     * @return int Number of records deleted.
    803791     */
     
    818806     * @param int $user_id  ID of the user.
    819807     * @param int $group_id ID of the group.
    820      *
    821808     * @return mixed
    822809     */
     
    837824     * @param int $user_id  ID of the user.
    838825     * @param int $group_id ID of the group.
    839      *
    840826     * @return mixed
    841827     */
     
    856842     * @param int $user_id  ID of the user.
    857843     * @param int $group_id ID of the group.
    858      *
    859844     * @return mixed
    860845     */
     
    875860     * @param int $user_id  ID of the user.
    876861     * @param int $group_id ID of the group.
    877      *
    878862     * @return mixed
    879863     */
     
    896880     * @param int $user_id  ID of the user.
    897881     * @param int $group_id ID of the group.
    898      *
    899882     * @return int|null ID of the group if the user is the creator,
    900883     *                  otherwise false.
     
    916899     * @param int $user_id  ID of the user.
    917900     * @param int $group_id ID of the group.
    918      *
    919901     * @return int|null ID of the membership if found, otherwise false.
    920902     */
     
    935917     * @param int $user_id      ID of the user.
    936918     * @param int $total_groups Max number of group IDs to return. Default: 5.
    937      *
    938919     * @return array Group IDs.
    939920     */
     
    943924        $bp = buddypress();
    944925
    945         // If the user is logged in and viewing their random groups, we can show hidden and private groups
     926        // If the user is logged in and viewing their random groups, we can show hidden and private groups.
    946927        if ( bp_is_my_profile() ) {
    947928            return $wpdb->get_col( $wpdb->prepare( "SELECT DISTINCT group_id FROM {$bp->groups->table_name_members} WHERE user_id = %d AND is_confirmed = 1 AND is_banned = 0 ORDER BY rand() LIMIT %d", $user_id, $total_groups ) );
     
    955936     *
    956937     * @param int $group_id ID of the group.
    957      *
    958938     * @return array IDs of all group members.
    959939     */
     
    970950     *
    971951     * @param int $group_id ID of the group.
    972      *
    973952     * @return array Info about group admins (user_id + date_modified).
    974953     */
     
    992971     *
    993972     * @param int $group_id ID of the group.
    994      *
    995973     * @return array Info about group mods (user_id + date_modified).
    996974     */
     
    1007985     *
    1008986     * @param int $group_id ID of the group.
    1009      *
    1010987     * @return array IDs of users with outstanding membership requests.
    1011988     */
     
    10231000     * @deprecated 1.8.0
    10241001     *
    1025      * @param $group_id
    1026      * @param $limit
    1027      * @param $page
    1028      * @param $exclude_admins_mods
    1029      * @param $exclude_banned
    1030      * @param $exclude
    1031      *
     1002     * @param int        $group_id            ID of the group being queried for.
     1003     * @param bool/int   $limit               Max amount to return.
     1004     * @param bool/int   $page                Pagination value.
     1005     * @param bool       $exclude_admins_mods Whether or not to exclude admins and moderators.
     1006     * @param bool       $exclude_banned      Whether or not to exclude banned members.
     1007     * @param bool/array $exclude             Array of user IDs to exclude.
    10321008     * @return mixed
    10331009     */
     
    10911067        }
    10921068
    1093         // Fetch whether or not the user is a friend
     1069        // Fetch whether or not the user is a friend.
    10941070        foreach ( (array) $members as $user )
    10951071            $user_ids[] = $user->user_id;
     
    11151091     *
    11161092     * @param int $group_id ID of the group.
    1117      *
    11181093     * @return int Number of records deleted.
    11191094     */
     
    11321107     *
    11331108     * @param int $user_id ID of the user.
    1134      *
    11351109     * @return mixed
    11361110     */
     
    11401114        $bp = buddypress();
    11411115
    1142         // Get all the group ids for the current user's groups and update counts
     1116        // Get all the group ids for the current user's groups and update counts.
    11431117        $group_ids = BP_Groups_Member::get_group_ids( $user_id );
    11441118        foreach ( $group_ids['groups'] as $group_id ) {
    11451119            groups_update_groupmeta( $group_id, 'total_member_count', groups_get_total_member_count( $group_id ) - 1 );
    11461120
    1147             // If current user is the creator of a group and is the sole admin, delete that group to avoid counts going out-of-sync
     1121            // If current user is the creator of a group and is the sole admin, delete that group to avoid counts going out-of-sync.
    11481122            if ( groups_is_user_admin( $user_id, $group_id ) && count( groups_get_group_admins( $group_id ) ) < 2 && groups_is_user_creator( $user_id, $group_id ) )
    11491123                groups_delete_group( $group_id );
Note: See TracChangeset for help on using the changeset viewer.