Changeset 13337
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/bp-activity/bp-activity-functions.php
r13309 r13337 1848 1848 'date_query' => false, // Filter by date. See first parameter of WP_Date_Query for format. 1849 1849 'filter_query' => false, 1850 'user_id__in' => array(), // Array of user ids to include. 1851 'user_id__not_in' => array(), // Array of user ids to excluce. 1850 1852 'show_hidden' => false, // Show activity items that are hidden site-wide? 1851 1853 'exclude' => false, // Comma-separated list of activity IDs to exclude. … … 1883 1885 'filter_query' => $r['filter_query'], 1884 1886 'filter' => $r['filter'], 1887 'user_id__in' => $r['user_id__in'], 1888 'user_id__not_in' => $r['user_id__not_in'], 1885 1889 'scope' => $r['scope'], 1886 1890 'display_comments' => $r['display_comments'], -
trunk/src/bp-activity/classes/class-bp-activity-activity.php
r13312 r13337 343 343 * @since 2.9.0 Introduced the `$order_by` parameter. 344 344 * @since 10.0.0 Introduced the `$count_total_only` parameter. 345 * @since 11.0.0 Introduced the `$user_id__in` and `$user_id__not_in` parameters. 345 346 * 346 347 * @see BP_Activity_Activity::get_filter_sql() for a description of the … … 367 368 * @type string|array $scope Pre-determined set of activity arguments. 368 369 * @type array $filter See BP_Activity_Activity::get_filter_sql(). 370 * @type array $user_id__in An array of user ids to include. Activity posted by users matching one of these 371 * user ids will be included in results. Default empty array. 372 * @type array $user_id__not_in An array of user ids to exclude. Activity posted by users matching one of these 373 * user ids will not be included in results. Default empty array. 369 374 * @type string $search_terms Limit results by a search term. Default: false. 370 375 * @type bool $display_comments Whether to include activity comments. Default: false. … … 431 436 'date_query' => false, // Filter by date. 432 437 'filter_query' => false, // Advanced filtering - see BP_Activity_Query. 438 'user_id__in' => array(), // Array of user ids to include. 439 'user_id__not_in' => array(), // Array of user ids to excluce. 433 440 'filter' => false, // See self::get_filter_sql(). 434 441 'scope' => false, // Preset activity arguments. … … 482 489 if ( $r['filter'] && $filter_sql = BP_Activity_Activity::get_filter_sql( $r['filter'] ) ) { 483 490 $where_conditions['filter_sql'] = $filter_sql; 491 } 492 493 // User IDs filtering. 494 $user_ids_clause = array(); 495 $user_ids_filters = array_filter( 496 array_intersect_key( 497 $r, 498 array( 499 'user_id__in' => true, 500 'user_id__not_in' => true, 501 ) 502 ) 503 ); 504 505 foreach ( $user_ids_filters as $user_ids_filter_key => $user_ids_filter ) { 506 $user_ids_operator = 'IN'; 507 if ( 'user_id__not_in' === $user_ids_filter_key ) { 508 $user_ids_operator = 'NOT IN'; 509 } 510 511 if ( $user_ids_clause ) { 512 $user_ids_clause[] = array( 513 'column' => 'user_id', 514 'compare' => $user_ids_operator, 515 'value' => (array) $user_ids_filter, 516 ); 517 } else { 518 $user_ids_clause = array( 519 'relation' => 'AND', 520 array( 521 'column' => 'user_id', 522 'compare' => $user_ids_operator, 523 'value' => (array) $user_ids_filter, 524 ), 525 ); 526 } 527 } 528 529 if ( $user_ids_clause ) { 530 $user_ids_query = new BP_Activity_Query( $user_ids_clause ); 531 $user_ids_sql = $user_ids_query->get_sql(); 532 if ( ! empty( $user_ids_sql ) ) { 533 $where_conditions['user_ids_query_sql'] = $user_ids_sql; 534 } 484 535 } 485 536 -
trunk/tests/phpunit/testcases/activity/class.BP_Activity_Activity.php
r13150 r13337 413 413 /** 414 414 * @group get 415 */ 416 public function test_get_with_user_id__in() { 417 $u1 = self::factory()->user->create(); 418 $u2 = self::factory()->user->create(); 419 $u3 = self::factory()->user->create(); 420 $a1 = self::factory()->activity->create( array( 'user_id' => $u1 ) ); 421 $a2 = self::factory()->activity->create( array( 'user_id' => $u2 ) ); 422 $a3 = self::factory()->activity->create( array( 'user_id' => $u3 ) ); 423 424 $activities = BP_Activity_Activity::get( array( 425 'user_id__in' => array( $u1, $u2 ), 426 ) ); 427 428 $ids = wp_list_pluck( $activities['activities'], 'id' ); 429 sort( $ids ); 430 $this->assertEquals( array( $a1, $a2 ), $ids ); 431 } 432 433 /** 434 * @group get 435 */ 436 public function test_get_with_user_id__not_in() { 437 $u1 = self::factory()->user->create(); 438 $u2 = self::factory()->user->create(); 439 $u3 = self::factory()->user->create(); 440 $a1 = self::factory()->activity->create( array( 'user_id' => $u1 ) ); 441 $a2 = self::factory()->activity->create( array( 'user_id' => $u2 ) ); 442 $a3 = self::factory()->activity->create( array( 'user_id' => $u3 ) ); 443 444 $activities = BP_Activity_Activity::get( array( 445 'user_id__not_in' => array( $u2, $u3 ), 446 ) ); 447 448 $ids = wp_list_pluck( $activities['activities'], 'id' ); 449 $this->assertEquals( array( $a1 ), $ids ); 450 } 451 452 /** 453 * @group get 454 */ 455 public function test_get_with_user_id__in_andnot_in() { 456 $u1 = self::factory()->user->create(); 457 $u2 = self::factory()->user->create(); 458 $u3 = self::factory()->user->create(); 459 $u4 = self::factory()->user->create(); 460 $u5 = self::factory()->user->create(); 461 $a1 = self::factory()->activity->create( array( 'user_id' => $u1 ) ); 462 $a2 = self::factory()->activity->create( array( 'user_id' => $u2 ) ); 463 $a3 = self::factory()->activity->create( array( 'user_id' => $u3 ) ); 464 $a4 = self::factory()->activity->create( array( 'user_id' => $u4 ) ); 465 $a5 = self::factory()->activity->create( array( 'user_id' => $u5 ) ); 466 467 $activities = BP_Activity_Activity::get( array( 468 'user_id__in' => array( $u1, $u2, $u4, $u5 ), 469 'user_id__not_in' => array( $u4, $u5 ), 470 ) ); 471 472 $ids = wp_list_pluck( $activities['activities'], 'id' ); 473 sort( $ids ); 474 $this->assertEquals( array( $a1, $a2 ), $ids ); 475 } 476 477 /** 478 * @group get 415 479 * @group count_total 416 480 */
Note: See TracChangeset
for help on using the changeset viewer.