Changeset 13082
- Timestamp:
- 08/18/2021 12:28:22 AM (3 years ago)
- Location:
- trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/bp-core/classes/class-bp-invitation.php
r12916 r13082 131 131 */ 132 132 public $accepted; 133 134 /** 135 * Columns in the invitations table. 136 * 137 * @since 9.0.0 138 * @access public 139 * @var array 140 */ 141 public static $columns = array( 142 'id', 143 'user_id', 144 'inviter_id', 145 'invitee_email', 146 'class', 147 'item_id', 148 'secondary_item_id', 149 'type', 150 'content', 151 'date_modified', 152 'invite_sent', 153 'accepted' 154 ); 133 155 134 156 /** Public Methods ****************************************************/ … … 474 496 // Order by. 475 497 if ( ! empty( $args['order_by'] ) ) { 476 $order_by = implode( ', ', (array) $args['order_by'] ); 477 $conditions['order_by'] = "{$order_by}"; 498 $order_by_clean = array(); 499 foreach ( (array) $args['order_by'] as $key => $value ) { 500 if ( in_array( $value, self::$columns, true ) ) { 501 $order_by_clean[] = $value; 502 } 503 } 504 if ( ! empty( $order_by_clean ) ) { 505 $order_by = implode( ', ', $order_by_clean ); 506 $conditions['order_by'] = "{$order_by}"; 507 } 478 508 } 479 509 -
trunk/tests/phpunit/testcases/core/invitations.php
r12914 r13082 382 382 } 383 383 384 public function test_bp_invitations_orderby_item_id() { 385 $old_current_user = get_current_user_id(); 386 387 $u1 = $this->factory->user->create(); 388 $u2 = $this->factory->user->create(); 389 $u3 = $this->factory->user->create(); 390 $this->set_current_user( $u1 ); 391 392 $invites_class = new BPTest_Invitation_Manager_Extension(); 393 394 // Create an invitation. 395 $i1_args = array( 396 'user_id' => $u2, 397 'inviter_id' => $u1, 398 'item_id' => 6, 399 ); 400 $i1 = $invites_class->add_invitation( $i1_args ); 401 $invites_class->send_invitation_by_id( $i1 ); 402 403 $i2_args = array( 404 'user_id' => $u3, 405 'inviter_id' => $u1, 406 'item_id' => 4, 407 ); 408 $i2 = $invites_class->add_invitation( $i2_args ); 409 $invites_class->send_invitation_by_id( $i2 ); 410 411 $i3_args = array( 412 'user_id' => $u2, 413 'inviter_id' => $u1, 414 'item_id' => 8, 415 ); 416 $i3 = $invites_class->add_invitation( $i3_args ); 417 $invites_class->send_invitation_by_id( $i3 ); 418 419 $get_invites = array( 420 'order_by' => 'item_id', 421 'sort_order' => 'ASC', 422 'fields' => 'ids', 423 ); 424 $invites = $invites_class->get_invitations( $get_invites ); 425 $this->assertEquals( array( $i2, $i1, $i3 ), $invites ); 426 427 $get_invites['sort_order'] = 'DESC'; 428 $invites = $invites_class->get_invitations( $get_invites ); 429 $this->assertEquals( array( $i3, $i1, $i2 ), $invites ); 430 431 $this->set_current_user( $old_current_user ); 432 } 384 433 }
Note: See TracChangeset
for help on using the changeset viewer.