Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
06/02/2015 05:21:07 AM (11 years ago)
Author:
tw2113
Message:

Initial documentation cleanup for the BP Groups component.

See #6401.

File:
1 edited

Legend:

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

    r9819 r9906  
    156156         * Constructor method.
    157157         *
    158          * @param int $id Optional. If the ID of an existing group is provided,
    159          *        the object will be pre-populated with info about that group.
    160          * @param array $args {
     158         * @param int|null $id Optional. If the ID of an existing group is provided,
     159         *                     the object will be pre-populated with info about that group.
     160         * @param array    $args {
    161161         *     Array of optional arguments.
    162162         *     @type bool $populate_extras Whether to fetch "extra" data about
     
    284284                 * @since BuddyPress (1.0.0)
    285285                 *
    286                  * @param BP_Groups_Group Current instance of the group item being saved. Passed by reference.
     286                 * @param BP_Groups_Group $this Current instance of the group item being saved. Passed by reference.
    287287                 */
    288288                do_action_ref_array( 'groups_group_before_save', array( &$this ) );
     
    364364                 * @since BuddyPress (1.0.0)
    365365                 *
    366                  * @param BP_Groups_Group Current instance of the group item that was saved. Passed by reference.
     366                 * @param BP_Groups_Group $this Current instance of the group item that was saved. Passed by reference.
    367367                 */
    368368                do_action_ref_array( 'groups_group_after_save', array( &$this ) );
     
    420420         * Get whether a group exists for a given slug.
    421421         *
    422          * @param string $slug Slug to check.
    423          * @param string $table_name Optional. Name of the table to check
    424          *        against. Default: $bp->groups->table_name.
     422         * @param string      $slug       Slug to check.
     423         * @param string|bool $table_name Optional. Name of the table to check
     424         *                                against. Default: $bp->groups->table_name.
     425         *
    425426         * @return string|null ID of the group, if one is found, else null.
    426427         */
     
    473474         *        Default: the displayed user.
    474475         * @param mixed $order Not used.
    475          * @param int $limit Optional. The max number of results to return.
     476         * @param int|null $limit Optional. The max number of results to return.
    476477         *        Default: null (no limit).
    477          * @param int $page Optional. The page offset of results to return.
     478         * @param int|null $page Optional. The page offset of results to return.
    478479         *        Default: null (no limit).
     480         * @return false|array {
     481         *     @type array $groups Array of matched and paginated group objects.
     482         *     @type int $total Total count of groups matching the query.
     483         * }
     484         */
     485        public static function filter_user_groups( $filter, $user_id = 0, $order = false, $limit = null, $page = null ) {
     486                global $wpdb;
     487
     488                if ( empty( $user_id ) )
     489                        $user_id = bp_displayed_user_id();
     490
     491                $search_terms_like = bp_esc_like( $filter ) . '%';
     492
     493                $pag_sql = $order_sql = $hidden_sql = '';
     494
     495                if ( !empty( $limit ) && !empty( $page ) )
     496                        $pag_sql = $wpdb->prepare( " LIMIT %d, %d", intval( ( $page - 1 ) * $limit), intval( $limit ) );
     497
     498                // Get all the group ids for the current user's groups.
     499                $gids = BP_Groups_Member::get_group_ids( $user_id );
     500
     501                if ( empty( $gids['groups'] ) )
     502                        return false;
     503
     504                $bp = buddypress();
     505
     506                $gids = esc_sql( implode( ',', wp_parse_id_list( $gids['groups'] ) ) );
     507
     508                $paged_groups = $wpdb->get_results( $wpdb->prepare( "SELECT id as group_id FROM {$bp->groups->table_name} WHERE ( name LIKE %s OR description LIKE %s ) AND id IN ({$gids}) {$pag_sql}", $search_terms_like, $search_terms_like ) );
     509                $total_groups = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(id) FROM {$bp->groups->table_name} WHERE ( name LIKE %s OR description LIKE %s ) AND id IN ({$gids})", $search_terms_like, $search_terms_like ) );
     510
     511                return array( 'groups' => $paged_groups, 'total' => $total_groups );
     512        }
     513
     514        /**
     515         * Get a list of groups, filtered by a search string.
     516         *
     517         * @param string $filter Search term. Matches against 'name' and
     518         *        'description' fields.
     519         * @param int|null $limit Optional. The max number of results to return.
     520         *        Default: null (no limit).
     521         * @param int|null $page Optional. The page offset of results to return.
     522         *        Default: null (no limit).
     523         * @param string|bool $sort_by Column to sort by. Default: false (default
     524         *        sort).
     525         * @param string|bool $order ASC or DESC. Default: false (default sort).
    479526         * @return array {
    480527         *     @type array $groups Array of matched and paginated group objects.
     
    482529         * }
    483530         */
    484         public static function filter_user_groups( $filter, $user_id = 0, $order = false, $limit = null, $page = null ) {
    485                 global $wpdb;
    486 
    487                 if ( empty( $user_id ) )
    488                         $user_id = bp_displayed_user_id();
    489 
    490                 $search_terms_like = bp_esc_like( $filter ) . '%';
    491 
    492                 $pag_sql = $order_sql = $hidden_sql = '';
    493 
    494                 if ( !empty( $limit ) && !empty( $page ) )
    495                         $pag_sql = $wpdb->prepare( " LIMIT %d, %d", intval( ( $page - 1 ) * $limit), intval( $limit ) );
    496 
    497                 // Get all the group ids for the current user's groups.
    498                 $gids = BP_Groups_Member::get_group_ids( $user_id );
    499 
    500                 if ( empty( $gids['groups'] ) )
    501                         return false;
    502 
    503                 $bp = buddypress();
    504 
    505                 $gids = esc_sql( implode( ',', wp_parse_id_list( $gids['groups'] ) ) );
    506 
    507                 $paged_groups = $wpdb->get_results( $wpdb->prepare( "SELECT id as group_id FROM {$bp->groups->table_name} WHERE ( name LIKE %s OR description LIKE %s ) AND id IN ({$gids}) {$pag_sql}", $search_terms_like, $search_terms_like ) );
    508                 $total_groups = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(id) FROM {$bp->groups->table_name} WHERE ( name LIKE %s OR description LIKE %s ) AND id IN ({$gids})", $search_terms_like, $search_terms_like ) );
    509 
    510                 return array( 'groups' => $paged_groups, 'total' => $total_groups );
    511         }
    512 
    513         /**
    514          * Get a list of groups, filtered by a search string.
    515          *
    516          * @param string $filter Search term. Matches against 'name' and
    517          *        'description' fields.
    518          * @param int $limit Optional. The max number of results to return.
    519          *        Default: null (no limit).
    520          * @param int $page Optional. The page offset of results to return.
    521          *        Default: null (no limit).
    522          * @param string $sort_by Column to sort by. Default: false (default
    523          *        sort).
    524          * @param string $order ASC or DESC. Default: false (default sort).
    525          * @return array {
    526          *     @type array $groups Array of matched and paginated group objects.
    527          *     @type int $total Total count of groups matching the query.
    528          * }
    529          */
    530531        public static function search_groups( $filter, $limit = null, $page = null, $sort_by = false, $order = false ) {
    531532                global $wpdb;
     
    621622         *
    622623         * @param int $group_id ID of the group.
    623          * @param int $limit Optional. Max number of results to return.
     624         * @param int|null $limit Optional. Max number of results to return.
    624625         *        Default: null (no limit).
    625          * @param int $page Optional. Page offset of results returned. Default:
     626         * @param int|null $page Optional. Page offset of results returned. Default:
    626627         *        null (no limit).
    627628         * @return array {
     
    10781079         * Get a list of groups, sorted by those that have the most legacy forum topics.
    10791080         *
    1080          * @param int $limit Optional. The max number of results to return.
     1081         * @param int|null $limit Optional. The max number of results to return.
    10811082         *        Default: null (no limit).
    1082          * @param int $page Optional. The page offset of results to return.
     1083         * @param int|null $page Optional. The page offset of results to return.
    10831084         *        Default: null (no limit).
    10841085         * @param int $user_id Optional. If present, groups will be limited to
    10851086         *        those of which the specified user is a member.
    1086          * @param string $search_terms Optional. Limit groups to those whose
     1087         * @param string|bool $search_terms Optional. Limit groups to those whose
    10871088         *        name or description field contain the search string.
    10881089         * @param bool $populate_extras Optional. Whether to fetch extra
    10891090         *        information about the groups. Default: true.
    1090          * @param string|array Optional. Array or comma-separated list of group
     1091         * @param string|array|bool $exclude Optional. Array or comma-separated list of group
    10911092         *        IDs to exclude from results.
    10921093         * @return array {
     
    11471148         * Get a list of groups, sorted by those that have the most legacy forum posts.
    11481149         *
    1149          * @param int $limit Optional. The max number of results to return.
     1150         * @param int|null $limit Optional. The max number of results to return.
    11501151         *        Default: null (no limit).
    1151          * @param int $page Optional. The page offset of results to return.
     1152         * @param int|null $page Optional. The page offset of results to return.
    11521153         *        Default: null (no limit).
    1153          * @param int $user_id Optional. If present, groups will be limited to
    1154          *        those of which the specified user is a member.
    1155          * @param string $search_terms Optional. Limit groups to those whose
     1154         * @param string|bool $search_terms Optional. Limit groups to those whose
    11561155         *        name or description field contain the search string.
    11571156         * @param bool $populate_extras Optional. Whether to fetch extra
    11581157         *        information about the groups. Default: true.
    1159          * @param string|array Optional. Array or comma-separated list of group
     1158         * @param string|array|bool Optional. Array or comma-separated list of group
    11601159         *        IDs to exclude from results.
    11611160         * @return array {
     
    12171216         *
    12181217         * @param string $letter The letter.
    1219          * @param int $limit Optional. The max number of results to return.
     1218         * @param int|null $limit Optional. The max number of results to return.
    12201219         *        Default: null (no limit).
    1221          * @param int $page Optional. The page offset of results to return.
     1220         * @param int|null $page Optional. The page offset of results to return.
    12221221         *        Default: null (no limit).
    12231222         * @param bool $populate_extras Optional. Whether to fetch extra
    12241223         *        information about the groups. Default: true.
    1225          * @param string|array Optional. Array or comma-separated list of group
     1224         * @param string|array|bool $exclude Optional. Array or comma-separated list of group
    12261225         *        IDs to exclude from results.
    1227          * @return array {
     1226         * @return false|array {
    12281227         *     @type array $groups Array of group objects returned by the
    12291228         *           paginated query.
     
    12831282         * Use BP_Groups_Group::get() with 'type' = 'random' instead.
    12841283         *
    1285          * @param int $limit Optional. The max number of results to return.
     1284         * @param int|null $limit Optional. The max number of results to return.
    12861285         *        Default: null (no limit).
    1287          * @param int $page Optional. The page offset of results to return.
     1286         * @param int|null $page Optional. The page offset of results to return.
    12881287         *        Default: null (no limit).
    12891288         * @param int $user_id Optional. If present, groups will be limited to
    12901289         *        those of which the specified user is a member.
    1291          * @param string $search_terms Optional. Limit groups to those whose
     1290         * @param string|bool $search_terms Optional. Limit groups to those whose
    12921291         *        name or description field contain the search string.
    12931292         * @param bool $populate_extras Optional. Whether to fetch extra
    12941293         *        information about the groups. Default: true.
    1295          * @param string|array Optional. Array or comma-separated list of group
     1294         * @param string|array|bool $exclude Optional. Array or comma-separated list of group
    12961295         *        IDs to exclude from results.
    12971296         * @return array {
     
    13591358         * @param string|array Array or comma-separated list of IDs matching
    13601359         *        $paged_groups.
    1361          * @param string $type Not used.
     1360         * @param string|bool $type Not used.
    13621361         * @return array $paged_groups
    13631362         */
     
    14691468         * Get global count of forum topics in public groups (legacy forums).
    14701469         *
    1471          * @param $type Optional. If 'unreplied', count will be limited to
     1470         * @param string $type Optional. If 'unreplied', count will be limited to
    14721471         *        those topics that have received no replies.
    14731472         * @return int Forum topic count.
     
    15211520         * @param string $status Which group type to count. 'public', 'private',
    15221521         *        'hidden', or 'all'. Default: 'public'.
     1522         * @param string|bool $search_terms Provided search terms.
     1523         *
    15231524         * @return int The topic count
    15241525         */
Note: See TracChangeset for help on using the changeset viewer.