Changeset 10373 for trunk/src/bp-groups/classes/class-bp-groups-group.php
- Timestamp:
- 11/22/2015 04:58:34 AM (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/bp-groups/classes/class-bp-groups-group.php
r10248 r10373 145 145 * Constructor method. 146 146 * 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. 149 149 * @param array $args { 150 150 * Array of optional arguments. … … 171 171 global $wpdb; 172 172 173 // Get BuddyPress 173 // Get BuddyPress. 174 174 $bp = buddypress(); 175 175 176 // Check cache for group data 176 // Check cache for group data. 177 177 $group = wp_cache_get( $this->id, 'bp_groups' ); 178 178 179 // Cache missed, so query the DB 179 // Cache missed, so query the DB. 180 180 if ( false === $group ) { 181 181 $group = $wpdb->get_row( $wpdb->prepare( "SELECT g.* FROM {$bp->groups->table_name} g WHERE g.id = %d", $this->id ) ); … … 184 184 } 185 185 186 // No group found so set the ID and bail 186 // No group found so set the ID and bail. 187 187 if ( empty( $group ) || is_wp_error( $group ) ) { 188 188 $this->id = 0; … … 190 190 } 191 191 192 // Group found so setup the object variables 192 // Group found so setup the object variables. 193 193 $this->id = $group->id; 194 194 $this->creator_id = $group->creator_id; … … 212 212 $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 ) ) ); 213 213 214 // Add admins and moderators to their respective arrays 214 // Add admins and moderators to their respective arrays. 215 215 foreach ( (array) $admin_mods as $user ) { 216 216 if ( !empty( $user->is_admin ) ) { … … 222 222 223 223 // 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. 225 225 $this->last_activity = groups_get_groupmeta( $this->id, 'last_activity' ); 226 226 $this->total_member_count = groups_get_groupmeta( $this->id, 'total_member_count' ); 227 227 228 // Set user-specific data 228 // Set user-specific data. 229 229 $user_id = bp_loggedin_user_id(); 230 230 $this->is_member = BP_Groups_Member::check_is_member( $user_id, $this->id ); … … 235 235 if ( ( 'private' === $this->status ) || ( 'hidden' === $this->status ) ) { 236 236 237 // Assume user does not have access to hidden/private groups 237 // Assume user does not have access to hidden/private groups. 238 238 $this->user_has_access = false; 239 239 240 // Group members or community moderators have access 240 // Group members or community moderators have access. 241 241 if ( ( $this->is_member && is_user_logged_in() ) || bp_current_user_can( 'bp_moderate' ) ) { 242 242 $this->user_has_access = true; … … 277 277 do_action_ref_array( 'groups_group_before_save', array( &$this ) ); 278 278 279 // Groups need at least a name 279 // Groups need at least a name. 280 280 if ( empty( $this->name ) ) { 281 281 return false; 282 282 } 283 283 284 // Set slug with group title if not passed 284 // Set slug with group title if not passed. 285 285 if ( empty( $this->slug ) ) { 286 286 $this->slug = sanitize_title( $this->name ); 287 287 } 288 288 289 // Sanity check 289 // Sanity check. 290 290 if ( empty( $this->slug ) ) { 291 291 return false; 292 292 } 293 293 294 // Check for slug conflicts if creating new group 294 // Check for slug conflicts if creating new group. 295 295 if ( empty( $this->id ) ) { 296 296 $this->slug = groups_check_slug( $this->slug ); … … 370 370 global $wpdb; 371 371 372 // Delete groupmeta for the group 372 // Delete groupmeta for the group. 373 373 groups_delete_groupmeta( $this->id ); 374 374 375 // Fetch the user IDs of all the members of the group 375 // Fetch the user IDs of all the members of the group. 376 376 $user_ids = BP_Groups_Member::get_group_member_ids( $this->id ); 377 377 $user_id_str = esc_sql( implode( ',', wp_parse_id_list( $user_ids ) ) ); 378 378 379 // Modify group count usermeta for members 379 // Modify group count usermeta for members. 380 380 $wpdb->query( "UPDATE {$wpdb->usermeta} SET meta_value = meta_value - 1 WHERE meta_key = 'total_group_count' AND user_id IN ( {$user_id_str} )" ); 381 381 382 // Now delete all group member entries 382 // Now delete all group member entries. 383 383 BP_Groups_Member::delete_all( $this->id ); 384 384 … … 397 397 $bp = buddypress(); 398 398 399 // Finally remove the group entry from the DB 399 // Finally remove the group entry from the DB. 400 400 if ( !$wpdb->query( $wpdb->prepare( "DELETE FROM {$bp->groups->table_name} WHERE id = %d", $this->id ) ) ) 401 401 return false; … … 412 412 * @param string|bool $table_name Optional. Name of the table to check 413 413 * against. Default: $bp->groups->table_name. 414 *415 414 * @return string|null ID of the group, if one is found, else null. 416 415 */ … … 433 432 * 434 433 * @param string $slug See {@link BP_Groups_Group::group_exists()}. 435 *436 434 * @return string|null See {@link BP_Groups_Group::group_exists()}. 437 435 */ … … 445 443 * @param int $user_id ID of the inviting user. 446 444 * @param int $group_id ID of the group. 447 *448 445 * @return array IDs of users who have been invited to the group by the 449 446 * user but have not yet accepted. … … 515 512 * sort). 516 513 * @param string|bool $order ASC or DESC. Default: false (default sort). 517 *518 514 * @return array { 519 515 * @type array $groups Array of matched and paginated group objects. … … 552 548 * 553 549 * @param string $slug Slug to check. 554 *555 550 * @return string|null The slug, if found. Otherwise null. 556 551 */ … … 567 562 * 568 563 * @param int $group_id ID of the group. 569 *570 564 * @return string|null The slug, if found. Otherwise null. 571 565 */ … … 582 576 * 583 577 * @param int $group_id ID of the group. 584 *585 578 * @return bool True if the group has members, otherwise false. 586 579 */ … … 602 595 * 603 596 * @param int $group_id ID of the group. 604 *605 597 * @return int|null The number of outstanding requests, or null if 606 598 * none are found. … … 649 641 * parameter format. 650 642 * 651 * @param array {643 * @param array $args { 652 644 * Array of parameters. All items are optional. 653 645 * @type string $type Optional. Shorthand for certain orderby/ … … 692 684 global $wpdb; 693 685 694 // Backward compatibility with old method of passing arguments 686 // Backward compatibility with old method of passing arguments. 695 687 if ( ! is_array( $args ) || func_num_args() > 1 ) { 696 688 _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__ ) ); … … 783 775 } 784 776 785 /* *Order/orderby ********************************************/777 /* Order/orderby ********************************************/ 786 778 787 779 $order = $r['order']; … … 789 781 790 782 // 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. 792 784 if ( ! empty( $r['type'] ) ) { 793 785 … … 804 796 // If an invalid type is passed, $order_orderby will be 805 797 // 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. 807 799 if ( ! empty( $order_orderby['order'] ) ) { 808 800 $order = $order_orderby['order']; … … 814 806 } 815 807 816 // Sanitize 'order' 808 // Sanitize 'order'. 817 809 $order = bp_esc_sql_order( $order ); 818 810 … … 828 820 $orderby = apply_filters( 'bp_groups_get_orderby_converted_by_term', self::convert_orderby_to_order_by_term( $orderby ), $orderby, $r['type'] ); 829 821 830 // Random order is a special case 822 // Random order is a special case. 831 823 if ( 'rand()' === $orderby ) { 832 824 $sql[] = "ORDER BY rand()"; … … 870 862 871 863 // Temporary implementation of meta_query for total count 872 // See #5099 864 // See #5099. 873 865 if ( ! empty( $meta_query_sql['where'] ) ) { 874 // Join the groupmeta table 866 // Join the groupmeta table. 875 867 $total_sql['select'] .= ", ". substr( $meta_query_sql['join'], 0, -2 ); 876 868 877 // Modify the meta_query clause from paged_sql for our syntax 869 // Modify the meta_query clause from paged_sql for our syntax. 878 870 $meta_query_clause = preg_replace( '/^\s*AND/', '', $meta_query_sql['where'] ); 879 871 $total_sql['where'][] = $meta_query_clause; 880 872 } 881 873 882 // Already escaped in the paginated results block 874 // Already escaped in the paginated results block. 883 875 if ( ! empty( $include ) ) { 884 876 $total_sql['where'][] = "g.id IN ({$include})"; 885 877 } 886 878 887 // Already escaped in the paginated results block 879 // Already escaped in the paginated results block. 888 880 if ( ! empty( $exclude ) ) { 889 881 $total_sql['where'][] = "g.id NOT IN ({$exclude})"; … … 916 908 } 917 909 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. 919 911 if ( !empty( $r['populate_extras'] ) ) { 920 912 $paged_groups = BP_Groups_Group::get_group_extras( $paged_groups, $group_ids, $r['type'] ); 921 913 } 922 914 923 // Grab all groupmeta 915 // Grab all groupmeta. 924 916 if ( ! empty( $r['update_meta_cache'] ) ) { 925 917 bp_groups_update_meta_cache( $group_ids ); … … 944 936 * @param array $meta_query An array of meta_query filters. See the 945 937 * documentation for {@link WP_Meta_Query} for details. 946 *947 938 * @return array $sql_array 'join' and 'where' clauses. 948 939 */ … … 959 950 960 951 // WP_Meta_Query expects the table name at 961 // $wpdb->group 952 // $wpdb->group. 962 953 $wpdb->groupmeta = buddypress()->groups->table_name_groupmeta; 963 954 … … 971 962 // @todo It may be better in the long run to refactor 972 963 // the more general query syntax to accord better with 973 // BP/WP convention 964 // BP/WP convention. 974 965 preg_match_all( '/JOIN (.+?) ON/', $meta_sql['join'], $matches_a ); 975 966 preg_match_all( '/ON \((.+?)\)/', $meta_sql['join'], $matches_b ); … … 992 983 * 993 984 * @return array { 994 * 995 * 985 * @type string $order SQL-friendly order string. 986 * @type string $orderby SQL-friendly orderby column name. 996 987 * } 997 988 */ … … 1044 1035 * @param string|array|bool $exclude Optional. Array or comma-separated list of group 1045 1036 * IDs to exclude from results. 1046 *1047 1037 * @return array { 1048 1038 * @type array $groups Array of group objects returned by the … … 1105 1095 * 1106 1096 * @param string $orderby Orderby term as passed to get(). 1107 *1108 1097 * @return string $order_by_term SQL-friendly orderby term. 1109 1098 */ … … 1150 1139 * @param string|array|bool $exclude Optional. Array or comma-separated list of group 1151 1140 * IDs to exclude from results. 1152 *1153 1141 * @return array { 1154 1142 * @type array $groups Array of group objects returned by the … … 1229 1217 $pag_sql = $hidden_sql = $exclude_sql = ''; 1230 1218 1231 // Multibyte compliance 1219 // Multibyte compliance. 1232 1220 if ( function_exists( 'mb_strlen' ) ) { 1233 1221 if ( mb_strlen( $letter, 'UTF-8' ) > 1 || is_numeric( $letter ) || !$letter ) { … … 1287 1275 * @param string|array|bool $exclude Optional. Array or comma-separated list of group 1288 1276 * IDs to exclude from results. 1289 *1290 1277 * @return array { 1291 1278 * @type array $groups Array of group objects returned by the … … 1345 1332 * 1346 1333 * Data fetched: 1347 *1348 1334 * - Logged-in user's status within each group (is_member, 1349 1335 * is_confirmed, is_pending, is_banned) … … 1353 1339 * $paged_groups. 1354 1340 * @param string|bool $type Not used. 1355 *1356 1341 * @return array $paged_groups 1357 1342 */ … … 1364 1349 $bp = buddypress(); 1365 1350 1366 // Sanitize group IDs 1351 // Sanitize group IDs. 1367 1352 $group_ids = implode( ',', wp_parse_id_list( $group_ids ) ); 1368 1353 1369 // Fetch the logged-in user's status within each group 1354 // Fetch the logged-in user's status within each group. 1370 1355 if ( is_user_logged_in() ) { 1371 1356 $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() ) ); … … 1374 1359 } 1375 1360 1376 // Reindex 1361 // Reindex. 1377 1362 $user_status = array(); 1378 1363 foreach ( $user_status_results as $user_status_result ) { … … 1386 1371 if ( isset( $user_status[ $gid ] ) ) { 1387 1372 1388 // is_confirmed means the user is a member1373 // The is_confirmed means the user is a member. 1389 1374 if ( $user_status[ $gid ]->is_confirmed ) { 1390 1375 $is_member = '1'; 1391 1376 1392 // invite_sent means the user has been invited1377 // The invite_sent means the user has been invited. 1393 1378 } elseif ( $user_status[ $gid ]->invite_sent ) { 1394 1379 $is_invited = '1'; 1395 1380 1396 // User has sent request, but has not been confirmed 1381 // User has sent request, but has not been confirmed. 1397 1382 } else { 1398 1383 $is_pending = '1'; … … 1428 1413 * 1429 1414 * @param int $group_id ID of the group whose invitations are being deleted. 1430 *1431 1415 * @return int|null Number of rows records deleted on success, null on 1432 1416 * failure. … … 1465 1449 * @param string $type Optional. If 'unreplied', count will be limited to 1466 1450 * those topics that have received no replies. 1467 *1468 1451 * @return int Forum topic count. 1469 1452 */ … … 1479 1462 * Filters the portion of the SQL related to global count of forum topics in public groups. 1480 1463 * 1481 * https://buddypress.trac.wordpress.org/ticket/4306.1464 * See https://buddypress.trac.wordpress.org/ticket/4306. 1482 1465 * 1483 1466 * @since 1.6.0 … … 1488 1471 $extra_sql = apply_filters( 'get_global_forum_topic_count_extra_sql', $bp->groups->filter_sql, $type ); 1489 1472 1490 // Make sure the $extra_sql begins with an AND 1473 // Make sure the $extra_sql begins with an AND. 1491 1474 if ( 'AND' != substr( trim( strtoupper( $extra_sql ) ), 0, 3 ) ) 1492 1475 $extra_sql = ' AND ' . $extra_sql; … … 1499 1482 * 1500 1483 * @param int $group_id Group ID. 1501 *1502 1484 * @return int Count of confirmed members for the group. 1503 1485 */ … … 1518 1500 * 'hidden', or 'all'. Default: 'public'. 1519 1501 * @param string|bool $search_terms Provided search terms. 1520 *1521 1502 * @return int The topic count 1522 1503 */
Note: See TracChangeset
for help on using the changeset viewer.