Changeset 9906 for trunk/src/bp-groups/classes/class-bp-groups-group.php
- Timestamp:
- 06/02/2015 05:21:07 AM (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/bp-groups/classes/class-bp-groups-group.php
r9819 r9906 156 156 * Constructor method. 157 157 * 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 { 161 161 * Array of optional arguments. 162 162 * @type bool $populate_extras Whether to fetch "extra" data about … … 284 284 * @since BuddyPress (1.0.0) 285 285 * 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. 287 287 */ 288 288 do_action_ref_array( 'groups_group_before_save', array( &$this ) ); … … 364 364 * @since BuddyPress (1.0.0) 365 365 * 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. 367 367 */ 368 368 do_action_ref_array( 'groups_group_after_save', array( &$this ) ); … … 420 420 * Get whether a group exists for a given slug. 421 421 * 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 * 425 426 * @return string|null ID of the group, if one is found, else null. 426 427 */ … … 473 474 * Default: the displayed user. 474 475 * @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. 476 477 * 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. 478 479 * 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). 479 526 * @return array { 480 527 * @type array $groups Array of matched and paginated group objects. … … 482 529 * } 483 530 */ 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' and517 * '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 (default523 * 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 */530 531 public static function search_groups( $filter, $limit = null, $page = null, $sort_by = false, $order = false ) { 531 532 global $wpdb; … … 621 622 * 622 623 * @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. 624 625 * 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: 626 627 * null (no limit). 627 628 * @return array { … … 1078 1079 * Get a list of groups, sorted by those that have the most legacy forum topics. 1079 1080 * 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. 1081 1082 * 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. 1083 1084 * Default: null (no limit). 1084 1085 * @param int $user_id Optional. If present, groups will be limited to 1085 1086 * those of which the specified user is a member. 1086 * @param string $search_terms Optional. Limit groups to those whose1087 * @param string|bool $search_terms Optional. Limit groups to those whose 1087 1088 * name or description field contain the search string. 1088 1089 * @param bool $populate_extras Optional. Whether to fetch extra 1089 1090 * information about the groups. Default: true. 1090 * @param string|array Optional. Array or comma-separated list of group1091 * @param string|array|bool $exclude Optional. Array or comma-separated list of group 1091 1092 * IDs to exclude from results. 1092 1093 * @return array { … … 1147 1148 * Get a list of groups, sorted by those that have the most legacy forum posts. 1148 1149 * 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. 1150 1151 * 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. 1152 1153 * 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 1156 1155 * name or description field contain the search string. 1157 1156 * @param bool $populate_extras Optional. Whether to fetch extra 1158 1157 * information about the groups. Default: true. 1159 * @param string|array Optional. Array or comma-separated list of group1158 * @param string|array|bool Optional. Array or comma-separated list of group 1160 1159 * IDs to exclude from results. 1161 1160 * @return array { … … 1217 1216 * 1218 1217 * @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. 1220 1219 * 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. 1222 1221 * Default: null (no limit). 1223 1222 * @param bool $populate_extras Optional. Whether to fetch extra 1224 1223 * information about the groups. Default: true. 1225 * @param string|array Optional. Array or comma-separated list of group1224 * @param string|array|bool $exclude Optional. Array or comma-separated list of group 1226 1225 * IDs to exclude from results. 1227 * @return array {1226 * @return false|array { 1228 1227 * @type array $groups Array of group objects returned by the 1229 1228 * paginated query. … … 1283 1282 * Use BP_Groups_Group::get() with 'type' = 'random' instead. 1284 1283 * 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. 1286 1285 * 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. 1288 1287 * Default: null (no limit). 1289 1288 * @param int $user_id Optional. If present, groups will be limited to 1290 1289 * those of which the specified user is a member. 1291 * @param string $search_terms Optional. Limit groups to those whose1290 * @param string|bool $search_terms Optional. Limit groups to those whose 1292 1291 * name or description field contain the search string. 1293 1292 * @param bool $populate_extras Optional. Whether to fetch extra 1294 1293 * information about the groups. Default: true. 1295 * @param string|array Optional. Array or comma-separated list of group1294 * @param string|array|bool $exclude Optional. Array or comma-separated list of group 1296 1295 * IDs to exclude from results. 1297 1296 * @return array { … … 1359 1358 * @param string|array Array or comma-separated list of IDs matching 1360 1359 * $paged_groups. 1361 * @param string $type Not used.1360 * @param string|bool $type Not used. 1362 1361 * @return array $paged_groups 1363 1362 */ … … 1469 1468 * Get global count of forum topics in public groups (legacy forums). 1470 1469 * 1471 * @param $type Optional. If 'unreplied', count will be limited to1470 * @param string $type Optional. If 'unreplied', count will be limited to 1472 1471 * those topics that have received no replies. 1473 1472 * @return int Forum topic count. … … 1521 1520 * @param string $status Which group type to count. 'public', 'private', 1522 1521 * 'hidden', or 'all'. Default: 'public'. 1522 * @param string|bool $search_terms Provided search terms. 1523 * 1523 1524 * @return int The topic count 1524 1525 */
Note: See TracChangeset
for help on using the changeset viewer.