Changeset 540 for trunk/bp-groups/bp-groups-classes.php
- Timestamp:
- 11/13/2008 11:20:15 PM (18 years ago)
- File:
-
- 1 edited
-
trunk/bp-groups/bp-groups-classes.php (modified) (14 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/bp-groups/bp-groups-classes.php
r531 r540 186 186 global $wpdb, $bp; 187 187 188 return $wpdb->get_results( $wpdb->prepare( "SELECT user_id, is_admin, inviter_id, user_title FROM " . $bp['groups']['table_name_members'] . " WHERE group_id = %d AND is_confirmed = 1ORDER BY rand()", $this->id ) );188 return $wpdb->get_results( $wpdb->prepare( "SELECT user_id, is_admin, inviter_id, user_title, is_mod FROM " . $bp['groups']['table_name_members'] . " WHERE group_id = %d AND is_confirmed = 1 AND is_banned = 0 ORDER BY rand()", $this->id ) ); 189 189 } 190 190 191 191 function get_administrators() { 192 192 for ( $i = 0; $i < count($this->user_dataset); $i++ ) { 193 if ( $this->user_dataset[$i]->is_admin ) {193 if ( $this->user_dataset[$i]->is_admin ) 194 194 $admins[] = new BP_Groups_Member( $this->user_dataset[$i]->user_id, $this->id ); 195 }196 195 } 197 196 … … 203 202 204 203 for ( $i = 0; $i < $total_randoms; $i++ ) { 205 $users[] = new BP_Groups_Member( $this->user_dataset[$i]->user_id, $this->id ); 204 if ( !(int)$this->user_dataset[$i]->is_banned ) 205 $users[] = new BP_Groups_Member( $this->user_dataset[$i]->user_id, $this->id ); 206 206 } 207 207 return $users; … … 459 459 var $inviter_id; 460 460 var $is_admin; 461 var $is_mod; 462 var $is_banned; 461 463 var $user_title; 462 464 var $date_modified; … … 500 502 $this->inviter_id = $member->inviter_id; 501 503 $this->is_admin = $member->is_admin; 504 $this->is_mod = $member->is_mod; 505 $this->is_banned = $member->is_banned; 502 506 $this->user_title = $member->user_title; 503 $this->date_modified = $member->date_modified;507 $this->date_modified = strtotime($member->date_modified); 504 508 $this->is_confirmed = $member->is_confirmed; 505 509 $this->comments = $member->comments; … … 513 517 514 518 if ( $this->id ) { 515 $sql = $wpdb->prepare( "UPDATE " . $bp['groups']['table_name_members'] . " SET inviter_id = %d, is_admin = %d, user_title = %s, date_modified = FROM_UNIXTIME(%d), is_confirmed = %d, comments = %s WHERE id = %d", $this->inviter_id, $this->is_admin, $this->user_title, $this->date_modified, $this->is_confirmed, $this->comments, $this->id ); 516 519 $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 = FROM_UNIXTIME(%d), is_confirmed = %d, comments = %s 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->id ); 517 520 } else { 518 $sql = $wpdb->prepare( "INSERT INTO " . $bp['groups']['table_name_members'] . " ( user_id, group_id, inviter_id, is_admin, user_title, date_modified, is_confirmed, comments ) VALUES ( %d, %d, %d, %d, %s, FROM_UNIXTIME(%d), %d, %s )", $this->user_id, $this->group_id, $this->inviter_id, $this->is_admin, $this->user_title, $this->date_modified, $this->is_confirmed, $this->comments );521 $sql = $wpdb->prepare( "INSERT INTO " . $bp['groups']['table_name_members'] . " ( user_id, group_id, inviter_id, is_admin, is_mod, is_banned, user_title, date_modified, is_confirmed, comments ) VALUES ( %d, %d, %d, %d, %d, %d, %s, FROM_UNIXTIME(%d), %d, %s )", $this->user_id, $this->group_id, $this->inviter_id, $this->is_admin, $this->is_mod, $this->is_banned, $this->user_title, $this->date_modified, $this->is_confirmed, $this->comments ); 519 522 } 520 523 … … 527 530 528 531 function promote() { 529 532 // Check the users current status 533 534 // Not letting mods be promoted to admins right now. In the future though yes. 535 if ( $this->is_admin || $this->is_mod ) 536 return false; 537 538 $this->is_mod = 1; 539 return $this->save(); 530 540 } 531 541 532 542 function demote() { 533 543 if ( $this->is_admin ) 544 return false; 545 546 if ( !$this->is_mod ) 547 return false; 548 549 $this->is_mod = 0; 550 return $this->save(); 551 } 552 553 function ban() { 554 if ( $this->is_admin ) 555 return false; 556 557 $this->is_mod = 0; 558 $this->is_banned = 1; 559 560 groups_update_groupmeta( $this->group_id, 'total_member_count', ( (int) groups_get_groupmeta( $this->group_id, 'total_member_count' ) - 1 ) ); 561 562 return $this->save(); 563 } 564 565 function unban() { 566 if ( $this->is_admin ) 567 return false; 568 569 $this->is_banned = 0; 570 571 groups_update_groupmeta( $this->group_id, 'total_member_count', ( (int) groups_get_groupmeta( $this->group_id, 'total_member_count' ) + 1 ) ); 572 573 return $this->save(); 534 574 } 535 575 … … 551 591 552 592 $delete_result = $wpdb->query( $wpdb->prepare( "DELETE FROM " . $bp['groups']['table_name_members'] . " WHERE user_id = %d AND group_id = %d", $user_id, $group_id ) ); 553 593 554 594 return $delete_result; 555 595 } … … 563 603 // If the user is logged in and viewing their own groups, we can show hidden and closed groups 564 604 if ( bp_is_home() ) { 565 $group_ids = $wpdb->get_col( $wpdb->prepare( "SELECT DISTINCT group_id FROM " . $bp['groups']['table_name_members'] . " WHERE user_id = %d AND inviter_id = 0 $pag_sql", $user_id ) );605 $group_ids = $wpdb->get_col( $wpdb->prepare( "SELECT DISTINCT group_id FROM " . $bp['groups']['table_name_members'] . " WHERE user_id = %d AND inviter_id = 0 AND is_banned = 0{$pag_sql}", $user_id ) ); 566 606 } else { 567 $group_ids = $wpdb->get_col( $wpdb->prepare( "SELECT DISTINCT m.group_id FROM " . $bp['groups']['table_name_members'] . " m, " . $bp['groups']['table_name'] . " g WHERE m.group_id = g.id AND g.status != 'hidden' AND m.user_id = %d AND m.inviter_id = 0 $pag_sql", $user_id ) );607 $group_ids = $wpdb->get_col( $wpdb->prepare( "SELECT DISTINCT m.group_id FROM " . $bp['groups']['table_name_members'] . " m, " . $bp['groups']['table_name'] . " g WHERE m.group_id = g.id AND g.status != 'hidden' AND m.user_id = %d AND m.inviter_id = 0 AND m.is_banned = 0{$pag_sql}", $user_id ) ); 568 608 } 569 609 … … 581 621 582 622 if ( bp_is_home() ) { 583 return $wpdb->get_var( $wpdb->prepare( "SELECT DISTINCT count(group_id) FROM " . $bp['groups']['table_name_members'] . " WHERE user_id = %d AND inviter_id = 0 ", $user_id ) );623 return $wpdb->get_var( $wpdb->prepare( "SELECT DISTINCT count(group_id) FROM " . $bp['groups']['table_name_members'] . " WHERE user_id = %d AND inviter_id = 0 AND is_banned = 0", $user_id ) ); 584 624 } else { 585 return $wpdb->get_var( $wpdb->prepare( "SELECT DISTINCT count(m.group_id) FROM " . $bp['groups']['table_name_members'] . " m, " . $bp['groups']['table_name'] . " g WHERE m.group_id = g.id AND g.status != 'hidden' AND m.user_id = %d AND m.inviter_id = 0 ", $user_id ) );625 return $wpdb->get_var( $wpdb->prepare( "SELECT DISTINCT count(m.group_id) FROM " . $bp['groups']['table_name_members'] . " m, " . $bp['groups']['table_name'] . " g WHERE m.group_id = g.id AND g.status != 'hidden' AND m.user_id = %d AND m.inviter_id = 0 m.is_banned = 0", $user_id ) ); 586 626 } 587 627 } … … 602 642 global $wpdb, $bp; 603 643 604 return $wpdb->query( $wpdb->prepare( "SELECT id FROM " . $bp['groups']['table_name_members'] . " WHERE user_id = %d AND group_id = %d AND is_admin = 1", $user_id, $group_id ) ); 644 return $wpdb->query( $wpdb->prepare( "SELECT id FROM " . $bp['groups']['table_name_members'] . " WHERE user_id = %d AND group_id = %d AND is_admin = 1 AND is_banned = 0", $user_id, $group_id ) ); 645 } 646 647 function check_is_mod( $user_id, $group_id ) { 648 global $wpdb, $bp; 649 650 return $wpdb->query( $wpdb->prepare( "SELECT id FROM " . $bp['groups']['table_name_members'] . " WHERE user_id = %d AND group_id = %d AND is_mod = 1 AND is_banned = 0", $user_id, $group_id ) ); 605 651 } 606 652 … … 608 654 global $wpdb, $bp; 609 655 610 return $wpdb->query( $wpdb->prepare( "SELECT id FROM " . $bp['groups']['table_name_members'] . " WHERE user_id = %d AND group_id = %d AND is_confirmed = 1", $user_id, $group_id ) ); 656 return $wpdb->query( $wpdb->prepare( "SELECT id FROM " . $bp['groups']['table_name_members'] . " WHERE user_id = %d AND group_id = %d AND is_confirmed = 1 AND is_banned = 0", $user_id, $group_id ) ); 657 } 658 659 function check_is_banned( $user_id, $group_id ) { 660 global $wpdb, $bp; 661 662 return $wpdb->get_var( $wpdb->prepare( "SELECT is_banned FROM " . $bp['groups']['table_name_members'] . " WHERE user_id = %d AND group_id = %d", $user_id, $group_id ) ); 611 663 } 612 664 … … 614 666 global $wpdb, $bp; 615 667 616 return $wpdb->query( $wpdb->prepare( "SELECT id FROM " . $bp['groups']['table_name_members'] . " WHERE user_id = %d AND group_id = %d AND is_confirmed = 0 ", $user_id, $group_id ) );668 return $wpdb->query( $wpdb->prepare( "SELECT id FROM " . $bp['groups']['table_name_members'] . " WHERE user_id = %d AND group_id = %d AND is_confirmed = 0 AND is_banned = 0", $user_id, $group_id ) ); 617 669 } 618 670 … … 622 674 // If the user is logged in and viewing their random groups, we can show hidden and closed groups 623 675 if ( bp_is_home() ) { 624 return $wpdb->get_col( $wpdb->prepare( "SELECT DISTINCT group_id FROM " . $bp['groups']['table_name_members'] . " WHERE user_id = %d AND is_confirmed = 1 ORDER BY rand() LIMIT $total_groups", $user_id ) );676 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 $total_groups", $user_id ) ); 625 677 } else { 626 return $wpdb->get_col( $wpdb->prepare( "SELECT DISTINCT m.group_id FROM " . $bp['groups']['table_name_members'] . " m, " . $bp['groups']['table_name'] . " g WHERE m.group_id = g.id AND g.status != 'hidden' AND m.user_id = %d AND m.is_confirmed = 1 ORDER BY rand() LIMIT $total_groups", $user_id ) );627 } 628 } 629 630 function get_group_administrator_id ( $group_id ) {678 return $wpdb->get_col( $wpdb->prepare( "SELECT DISTINCT m.group_id FROM " . $bp['groups']['table_name_members'] . " m, " . $bp['groups']['table_name'] . " g WHERE m.group_id = g.id AND g.status != 'hidden' AND m.user_id = %d AND m.is_confirmed = 1 AND m.is_banned = 0 ORDER BY rand() LIMIT $total_groups", $user_id ) ); 679 } 680 } 681 682 function get_group_administrator_ids( $group_id ) { 631 683 global $bp, $wpdb; 632 684 633 return $wpdb->get_r ow( $wpdb->prepare( "SELECT user_id FROM " . $bp['groups']['table_name_members'] . " WHERE group_id = %d AND is_admin = 1", $group_id ) );634 } 635 636 function get_ all_for_group( $group_id, $limit = false, $page = false) {685 return $wpdb->get_results( $wpdb->prepare( "SELECT user_id, date_modified FROM " . $bp['groups']['table_name_members'] . " WHERE group_id = %d AND is_admin = 1 AND is_banned = 0", $group_id ) ); 686 } 687 688 function get_group_moderator_ids( $group_id ) { 637 689 global $bp, $wpdb; 638 690 691 return $wpdb->get_results( $wpdb->prepare( "SELECT user_id, date_modified FROM " . $bp['groups']['table_name_members'] . " WHERE group_id = %d AND is_mod = 1 AND is_banned = 0", $group_id ) ); 692 } 693 694 function get_all_for_group( $group_id, $limit = false, $page = false, $exclude_admins_mods = true, $exclude_banned = true ) { 695 global $bp, $wpdb; 696 639 697 if ( $limit && $page ) 640 $pag_sql = $wpdb->prepare( " LIMIT %d, %d", intval( ( $page - 1 ) * $limit), intval( $limit ) ); 641 642 $members = $wpdb->get_results( $wpdb->prepare( "SELECT user_id, date_modified FROM " . $bp['groups']['table_name_members'] . " WHERE group_id = %d AND is_confirmed = 1 {$pag_sql}", $group_id ) ); 698 $pag_sql = $wpdb->prepare( "LIMIT %d, %d", intval( ( $page - 1 ) * $limit), intval( $limit ) ); 699 700 if ( $exclude_admins_mods ) 701 $exclude_sql = $wpdb->prepare( "AND is_admin = 0 AND is_mod = 0" ); 702 703 if ( $exclude_banned ) 704 $banned_sql = $wpdb->prepare( " AND is_banned = 0" ); 705 706 $members = $wpdb->get_results( $wpdb->prepare( "SELECT user_id, date_modified FROM " . $bp['groups']['table_name_members'] . " WHERE group_id = %d AND is_confirmed = 1 {$banned_sql} {$exclude_sql} {$pag_sql}", $group_id ) ); 643 707 644 708 if ( !$members ) … … 648 712 $total_member_count = count($members); 649 713 else 650 $total_member_count = $wpdb->get_var( $wpdb->prepare( "SELECT count(user_id) FROM " . $bp['groups']['table_name_members'] . " WHERE group_id = %d AND is_confirmed = 1 ", $group_id ) );714 $total_member_count = $wpdb->get_var( $wpdb->prepare( "SELECT count(user_id) FROM " . $bp['groups']['table_name_members'] . " WHERE group_id = %d AND is_confirmed = 1 {$banned_sql} {$exclude_sql}", $group_id ) ); 651 715 652 716 return array( 'members' => $members, 'count' => $total_member_count );
Note:
See TracChangeset
for help on using the changeset viewer.
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)