Changeset 10373 for trunk/src/bp-groups/classes/class-bp-groups-member.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-member.php
r10248 r10373 131 131 public function __construct( $user_id = 0, $group_id = 0, $id = false, $populate = true ) { 132 132 133 // User and group are not empty, and ID is 133 // User and group are not empty, and ID is. 134 134 if ( !empty( $user_id ) && !empty( $group_id ) && empty( $id ) ) { 135 135 $this->user_id = $user_id; … … 141 141 } 142 142 143 // ID is not empty 143 // ID is not empty. 144 144 if ( !empty( $id ) ) { 145 145 $this->id = $id; … … 226 226 $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 ); 227 227 } 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. 229 229 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 ) ) ) { 230 230 return false; … … 239 239 $this->id = $wpdb->insert_id; 240 240 241 // Update the user's group count 241 // Update the user's group count. 242 242 self::refresh_total_group_count_for_user( $this->user_id ); 243 243 244 // Update the group's member count 244 // Update the group's member count. 245 245 self::refresh_total_member_count_for_group( $this->group_id ); 246 246 … … 263 263 * 264 264 * @param string $status The new status. 'mod' or 'admin'. 265 *266 265 * @return bool True on success, false on failure. 267 266 */ … … 364 363 return false; 365 364 366 // Update the user's group count 365 // Update the user's group count. 367 366 self::refresh_total_group_count_for_user( $this->user_id ); 368 367 369 // Update the group's member count 368 // Update the group's member count. 370 369 self::refresh_total_member_count_for_group( $this->group_id ); 371 370 … … 390 389 * 391 390 * @param int $user_id ID of the user. 392 *393 391 * @return bool True on success, false on failure. 394 392 */ … … 403 401 * 404 402 * @param int $group_id ID of the group. 405 *406 403 * @return bool True on success, false on failure. 407 404 */ … … 415 412 * @param int $user_id ID of the user. 416 413 * @param int $group_id ID of the group. 417 *418 414 * @return True on success, false on failure. 419 415 */ … … 434 430 $remove = $wpdb->query( $wpdb->prepare( "DELETE FROM {$bp->groups->table_name_members} WHERE user_id = %d AND group_id = %d", $user_id, $group_id ) ); 435 431 436 // Update the user's group count 432 // Update the user's group count. 437 433 self::refresh_total_group_count_for_user( $user_id ); 438 434 439 // Update the group's member count 435 // Update the group's member count. 440 436 self::refresh_total_member_count_for_group( $group_id ); 441 437 … … 475 471 $bp = buddypress(); 476 472 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. 478 474 if ( $user_id != bp_loggedin_user_id() ) { 479 475 $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 ); … … 540 536 * @param string|bool $filter Optional. Limit results to groups whose name or 541 537 * description field matches search terms. 542 *543 538 * @return array { 544 539 * @type array $groups Array of groups returned by paginated query. … … 574 569 /** 575 570 * 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 or583 * 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.4620 571 * 621 572 * @param int $user_id ID of the user. … … 631 582 * } 632 583 */ 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 */ 633 627 public static function get_is_banned_of( $user_id, $limit = false, $page = false, $filter = false ) { 634 628 global $wpdb; … … 662 656 * 663 657 * @param int $user_id Optional. Default: ID of the displayed user. 664 *665 658 * @return int Group count. 666 659 */ … … 690 683 * @param string|array|bool $exclude Optional. Array or comma-separated list 691 684 * of group IDs to exclude from results. 692 *693 685 * @return array { 694 686 * @type array $groups Array of groups returned by paginated query. … … 721 713 * 722 714 * @param int $user_id The user ID. 723 *724 715 * @return int 725 716 */ … … 746 737 * @param string $type If 'sent', results are limited to those invitations 747 738 * that have actually been sent (non-draft). Default: 'sent'. 748 *749 739 * @return int|null The ID of the invitation if found, otherwise null. 750 740 */ … … 771 761 * @param int $user_id ID of the user. 772 762 * @param int $group_id ID of the group. 773 *774 763 * @return int Number of records deleted. 775 764 */ … … 799 788 * @param int $user_id ID of the user. 800 789 * @param int $group_id ID of the group. 801 *802 790 * @return int Number of records deleted. 803 791 */ … … 818 806 * @param int $user_id ID of the user. 819 807 * @param int $group_id ID of the group. 820 *821 808 * @return mixed 822 809 */ … … 837 824 * @param int $user_id ID of the user. 838 825 * @param int $group_id ID of the group. 839 *840 826 * @return mixed 841 827 */ … … 856 842 * @param int $user_id ID of the user. 857 843 * @param int $group_id ID of the group. 858 *859 844 * @return mixed 860 845 */ … … 875 860 * @param int $user_id ID of the user. 876 861 * @param int $group_id ID of the group. 877 *878 862 * @return mixed 879 863 */ … … 896 880 * @param int $user_id ID of the user. 897 881 * @param int $group_id ID of the group. 898 *899 882 * @return int|null ID of the group if the user is the creator, 900 883 * otherwise false. … … 916 899 * @param int $user_id ID of the user. 917 900 * @param int $group_id ID of the group. 918 *919 901 * @return int|null ID of the membership if found, otherwise false. 920 902 */ … … 935 917 * @param int $user_id ID of the user. 936 918 * @param int $total_groups Max number of group IDs to return. Default: 5. 937 *938 919 * @return array Group IDs. 939 920 */ … … 943 924 $bp = buddypress(); 944 925 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. 946 927 if ( bp_is_my_profile() ) { 947 928 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 ) ); … … 955 936 * 956 937 * @param int $group_id ID of the group. 957 *958 938 * @return array IDs of all group members. 959 939 */ … … 970 950 * 971 951 * @param int $group_id ID of the group. 972 *973 952 * @return array Info about group admins (user_id + date_modified). 974 953 */ … … 992 971 * 993 972 * @param int $group_id ID of the group. 994 *995 973 * @return array Info about group mods (user_id + date_modified). 996 974 */ … … 1007 985 * 1008 986 * @param int $group_id ID of the group. 1009 *1010 987 * @return array IDs of users with outstanding membership requests. 1011 988 */ … … 1023 1000 * @deprecated 1.8.0 1024 1001 * 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. 1032 1008 * @return mixed 1033 1009 */ … … 1091 1067 } 1092 1068 1093 // Fetch whether or not the user is a friend 1069 // Fetch whether or not the user is a friend. 1094 1070 foreach ( (array) $members as $user ) 1095 1071 $user_ids[] = $user->user_id; … … 1115 1091 * 1116 1092 * @param int $group_id ID of the group. 1117 *1118 1093 * @return int Number of records deleted. 1119 1094 */ … … 1132 1107 * 1133 1108 * @param int $user_id ID of the user. 1134 *1135 1109 * @return mixed 1136 1110 */ … … 1140 1114 $bp = buddypress(); 1141 1115 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. 1143 1117 $group_ids = BP_Groups_Member::get_group_ids( $user_id ); 1144 1118 foreach ( $group_ids['groups'] as $group_id ) { 1145 1119 groups_update_groupmeta( $group_id, 'total_member_count', groups_get_total_member_count( $group_id ) - 1 ); 1146 1120 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. 1148 1122 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 ) ) 1149 1123 groups_delete_group( $group_id );
Note: See TracChangeset
for help on using the changeset viewer.