Changeset 8044
- Timestamp:
- 03/05/2014 02:37:27 PM (11 years ago)
- Location:
- trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/bp-groups/bp-groups-classes.php
r8008 r8044 1448 1448 * Query for the members of a group. 1449 1449 * 1450 * Special notes about the group members data schema: 1451 * - *Members* are entries with is_confirmed = 1 1452 * - *Pending requests* are entries with is_confirmed = 0 and inviter_id = 0 1453 * - *Pending and sent invitations* are entries with is_confirmed = 0 and 1454 * inviter_id != 0 and invite_sent = 1 1455 * - *Pending and unsent invitations* are entries with is_confirmed = 0 and 1456 * inviter_id != 0 and invite_sent = 0 1457 * 1450 1458 * @since BuddyPress (1.8.0) 1451 1459 * … … 1515 1523 'group_role' => array( 'member' ), 1516 1524 'is_confirmed' => true, 1525 'invite_sent' => null, 1526 'inviter_id' => null, 1517 1527 'type' => 'last_joined', 1518 1528 ) ); … … 1563 1573 $is_confirmed = ! empty( $this->query_vars['is_confirmed'] ) ? 1 : 0; 1564 1574 $sql['where'][] = $wpdb->prepare( "is_confirmed = %d", $is_confirmed ); 1575 1576 // invite_sent 1577 if ( ! is_null( $this->query_vars['invite_sent'] ) ) { 1578 $invite_sent = ! empty( $this->query_vars['invite_sent'] ) ? 1 : 0; 1579 $sql['where'][] = $wpdb->prepare( "invite_sent = %d", $invite_sent ); 1580 } 1581 1582 // inviter_id 1583 if ( ! is_null( $this->query_vars['inviter_id'] ) ) { 1584 $inviter_id = $this->query_vars['inviter_id']; 1585 1586 // Empty: inviter_id = 0. (pass false, 0, or empty array) 1587 if ( empty( $inviter_id ) ) { 1588 $sql['where'][] = "inviter_id = 0"; 1589 1590 // The string 'any' matches any non-zero value (inviter_id != 0) 1591 } else if ( 'any' === $inviter_id ) { 1592 $sql['where'][] = "inviter_id != 0"; 1593 1594 // Assume that a list of inviter IDs has been passed 1595 } else { 1596 // Parse and sanitize 1597 $inviter_ids = wp_parse_id_list( $inviter_id ); 1598 if ( ! empty( $inviter_ids ) ) { 1599 $inviter_ids_sql = implode( ',', $inviter_ids ); 1600 $sql['where'][] = "inviter_id IN ({$inviter_ids_sql})"; 1601 } 1602 } 1603 } 1565 1604 1566 1605 // Role information is stored as follows: admins have -
trunk/tests/testcases/groups/class-bp-group-member-query.php
r7948 r8044 423 423 $this->assertEquals( array( $u1, $u3, $u2 ), $ids ); 424 424 } 425 426 /** 427 * @group invite_sent 428 */ 429 public function test_with_invite_sent_true() { 430 $g = $this->factory->group->create(); 431 $u1 = $this->create_user(); 432 $u2 = $this->create_user(); 433 $time = time(); 434 435 $this->add_user_to_group( $u1, $g, array( 436 'date_modified' => gmdate( 'Y-m-d H:i:s', $time - 100 ), 437 'is_confirmed' => 0, 438 'invite_sent' => 0, 439 ) ); 440 441 $this->add_user_to_group( $u2, $g, array( 442 'date_modified' => gmdate( 'Y-m-d H:i:s', $time - 100 ), 443 'is_confirmed' => 0, 444 'invite_sent' => 1, 445 ) ); 446 447 $query_members = new BP_Group_Member_Query( array( 448 'group_id' => $g, 449 'is_confirmed' => false, 450 'invite_sent' => true, 451 ) ); 452 453 $ids = wp_parse_id_list( array_keys( $query_members->results ) ); 454 $this->assertEquals( array( $u2 ), $ids ); 455 } 456 457 /** 458 * @group invite_sent 459 */ 460 public function test_with_invite_sent_false() { 461 $g = $this->factory->group->create(); 462 $u1 = $this->create_user(); 463 $u2 = $this->create_user(); 464 $time = time(); 465 466 $this->add_user_to_group( $u1, $g, array( 467 'date_modified' => gmdate( 'Y-m-d H:i:s', $time - 100 ), 468 'is_confirmed' => 0, 469 'invite_sent' => 0, 470 ) ); 471 472 $this->add_user_to_group( $u2, $g, array( 473 'date_modified' => gmdate( 'Y-m-d H:i:s', $time - 100 ), 474 'is_confirmed' => 0, 475 'invite_sent' => 1, 476 ) ); 477 478 $query_members = new BP_Group_Member_Query( array( 479 'group_id' => $g, 480 'is_confirmed' => false, 481 'invite_sent' => false, 482 ) ); 483 484 $ids = wp_parse_id_list( array_keys( $query_members->results ) ); 485 $this->assertEquals( array( $u1 ), $ids ); 486 } 487 488 /** 489 * @group inviter_id 490 */ 491 public function test_with_inviter_id_false() { 492 $g = $this->factory->group->create(); 493 $u1 = $this->create_user(); 494 $u2 = $this->create_user(); 495 $time = time(); 496 497 $this->add_user_to_group( $u1, $g, array( 498 'date_modified' => gmdate( 'Y-m-d H:i:s', $time - 100 ), 499 'inviter_id' => 0, 500 ) ); 501 502 $this->add_user_to_group( $u2, $g, array( 503 'date_modified' => gmdate( 'Y-m-d H:i:s', $time - 100 ), 504 'inviter_id' => 1, 505 ) ); 506 507 $query_members = new BP_Group_Member_Query( array( 508 'group_id' => $g, 509 'inviter_id' => false, 510 ) ); 511 512 $ids = wp_parse_id_list( array_keys( $query_members->results ) ); 513 $this->assertEquals( array( $u1 ), $ids ); 514 } 515 516 /** 517 * @group inviter_id 518 */ 519 public function test_with_inviter_id_specific() { 520 $g = $this->factory->group->create(); 521 $u1 = $this->create_user(); 522 $u2 = $this->create_user(); 523 $u3 = $this->create_user(); 524 $u4 = $this->create_user(); 525 $time = time(); 526 527 $this->add_user_to_group( $u1, $g, array( 528 'date_modified' => gmdate( 'Y-m-d H:i:s', $time - 100 ), 529 'inviter_id' => 0, 530 ) ); 531 532 $this->add_user_to_group( $u2, $g, array( 533 'date_modified' => gmdate( 'Y-m-d H:i:s', $time - 200 ), 534 'inviter_id' => 1, 535 ) ); 536 537 $this->add_user_to_group( $u3, $g, array( 538 'date_modified' => gmdate( 'Y-m-d H:i:s', $time - 300 ), 539 'inviter_id' => 6, 540 ) ); 541 542 $this->add_user_to_group( $u4, $g, array( 543 'date_modified' => gmdate( 'Y-m-d H:i:s', $time - 400 ), 544 'inviter_id' => 2, 545 ) ); 546 547 $query_members = new BP_Group_Member_Query( array( 548 'group_id' => $g, 549 'inviter_id' => array( 2, 6 ), 550 ) ); 551 552 $ids = wp_parse_id_list( array_keys( $query_members->results ) ); 553 $this->assertEquals( array( $u3, $u4 ), $ids ); 554 } 555 556 /** 557 * @group inviter_id 558 */ 559 public function test_with_inviter_id_any() { 560 $g = $this->factory->group->create(); 561 $u1 = $this->create_user(); 562 $u2 = $this->create_user(); 563 $u3 = $this->create_user(); 564 $u4 = $this->create_user(); 565 $time = time(); 566 567 $this->add_user_to_group( $u1, $g, array( 568 'date_modified' => gmdate( 'Y-m-d H:i:s', $time - 100 ), 569 'inviter_id' => 0, 570 ) ); 571 572 $this->add_user_to_group( $u2, $g, array( 573 'date_modified' => gmdate( 'Y-m-d H:i:s', $time - 200 ), 574 'inviter_id' => 1, 575 ) ); 576 577 $this->add_user_to_group( $u3, $g, array( 578 'date_modified' => gmdate( 'Y-m-d H:i:s', $time - 300 ), 579 'inviter_id' => 6, 580 ) ); 581 582 $this->add_user_to_group( $u4, $g, array( 583 'date_modified' => gmdate( 'Y-m-d H:i:s', $time - 400 ), 584 'inviter_id' => 2, 585 ) ); 586 587 $query_members = new BP_Group_Member_Query( array( 588 'group_id' => $g, 589 'inviter_id' => 'any', 590 ) ); 591 592 $ids = wp_parse_id_list( array_keys( $query_members->results ) ); 593 $this->assertEquals( array( $u2, $u3, $u4 ), $ids ); 594 } 425 595 }
Note: See TracChangeset
for help on using the changeset viewer.