Changeset 8045
- Timestamp:
- 03/05/2014 02:37:30 PM (11 years ago)
- Location:
- trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/bp-groups/bp-groups-template.php
r7985 r8045 3095 3095 var $total_invite_count; 3096 3096 3097 function __construct( $user_id, $group_id ) { 3098 $this->invites = groups_get_invites_for_group( $user_id, $group_id ); 3099 $this->invite_count = count( $this->invites ); 3097 public function __construct( $args = array() ) { 3098 3099 // Backward compatibility with old method of passing arguments 3100 if ( ! is_array( $args ) || func_num_args() > 1 ) { 3101 _deprecated_argument( __METHOD__, '2.0.0', sprintf( __( 'Arguments passed to %1$s should be in an associative array. See the inline documentation at %2$s for more details.', 'buddypress' ), __METHOD__, __FILE__ ) ); 3102 3103 $old_args_keys = array( 3104 0 => 'user_id', 3105 1 => 'group_id', 3106 ); 3107 3108 $func_args = func_get_args(); 3109 $args = bp_core_parse_args_array( $old_args_keys, $func_args ); 3110 } 3111 3112 $r = wp_parse_args( $args, array( 3113 'user_id' => bp_loggedin_user_id(), 3114 'group_id' => bp_get_current_group_id(), 3115 'page' => 1, 3116 'per_page' => 10, 3117 ) ); 3118 3119 $this->pag_num = intval( $r['per_page'] ); 3120 $this->pag_page = isset( $_REQUEST['invitepage'] ) ? intval( $_REQUEST['invitepage'] ) : $r['page']; 3121 3122 $iquery = new BP_Group_Member_Query( array( 3123 'group_id' => $r['group_id'], 3124 'type' => 'first_joined', 3125 'per_page' => $this->pag_num, 3126 'page' => $this->pag_page, 3127 3128 // These filters ensure we get only pending invites 3129 'is_confirmed' => false, 3130 'inviter_id' => $r['user_id'], 3131 ) ); 3132 $this->invite_data = $iquery->results; 3133 3134 $this->total_invite_count = $iquery->total_users; 3135 $this->invites = array_values( wp_list_pluck( $this->invite_data, 'ID' ) ); 3136 $this->invite_count = count( $this->invites ); 3137 3138 $this->pag_links = paginate_links( array( 3139 'base' => add_query_arg( 'invitepage', '%#%' ), 3140 'format' => '', 3141 'total' => ceil( $this->total_invite_count / $this->pag_num ), 3142 'current' => $this->pag_page, 3143 'prev_text' => '←', 3144 'next_text' => '→', 3145 'mid_size' => 1, 3146 ) ); 3100 3147 } 3101 3148 … … 3135 3182 function the_invite() { 3136 3183 global $group_id; 3137 3138 3184 $this->in_the_loop = true; 3139 3185 $user_id = $this->next_invite(); 3186 3140 3187 $this->invite = new stdClass; 3141 $this->invite->user = new BP_Core_User( $user_id ); 3188 $this->invite->user = $this->invite_data[ $user_id ]; 3189 3190 // This method previously populated the user object with 3191 // BP_Core_User. We manually configure BP_Core_User data for 3192 // backward compatibility. 3193 if ( bp_is_active( 'xprofile' ) ) { 3194 $this->invite->user->profile_data = BP_XProfile_ProfileData::get_all_for_user( $user_id ); 3195 } 3196 3197 $this->invite->user->avatar = bp_core_fetch_avatar( array( 'item_id' => $user_id, 'type' => 'full', 'alt' => sprintf( __( 'Avatar of %s', 'buddypress' ), $this->invite->user->fullname ) ) ); 3198 $this->invite->user->avatar_thumb = bp_core_fetch_avatar( array( 'item_id' => $user_id, 'type' => 'thumb', 'alt' => sprintf( __( 'Avatar of %s', 'buddypress' ), $this->invite->user->fullname ) ) ); 3199 $this->invite->user->avatar_mini = bp_core_fetch_avatar( array( 'item_id' => $user_id, 'type' => 'thumb', 'alt' => sprintf( __( 'Avatar of %s', 'buddypress' ), $this->invite->user->fullname ), 'width' => 30, 'height' => 30 ) ); 3200 $this->invite->user->email = $this->invite->user->user_email; 3201 $this->invite->user->user_url = bp_core_get_user_domain( $user_id, $this->invite->user->user_nicename, $this->invite->user->user_login ); 3202 $this->invite->user->user_link = "<a href='{$this->invite->user->user_url}' title='{$this->invite->user->fullname}'>{$this->invite->user->fullname}</a>"; 3203 $this->invite->user->last_active = bp_core_get_last_activity( $this->invite->user->last_activity, __( 'active %s', 'buddypress' ) ); 3204 3205 if ( bp_is_active( 'groups' ) ) { 3206 $total_groups = BP_Groups_Member::total_group_count( $user_id ); 3207 $this->invite->user->total_groups = sprintf( _n( '%d group', '%d groups', $total_groups, 'buddypress' ), $total_groups ); 3208 } 3209 3210 if ( bp_is_active( 'friends' ) ) { 3211 $this->invite->user->total_friends = BP_Friends_Friendship::total_friend_count( $user_id ); 3212 } 3213 3214 if ( bp_is_active( 'friends' ) ) { 3215 $this->invite->user->total_friends = BP_Friends_Friendship::total_friend_count( $user_id ); 3216 } 3217 3218 $this->invite->user->total_blogs = null; 3219 3142 3220 $this->invite->group_id = $group_id; // Globaled in bp_group_has_invites() 3143 3221 … … 3152 3230 $r = wp_parse_args( $args, array( 3153 3231 'group_id' => false, 3154 'user_id' => bp_loggedin_user_id() 3232 'user_id' => bp_loggedin_user_id(), 3233 'per_page' => 10, 3234 'page' => 1, 3155 3235 ) ); 3156 3236 … … 3172 3252 } 3173 3253 3174 $invites_template = new BP_Groups_Invite_Template( $r ['user_id'], $r['group_id']);3254 $invites_template = new BP_Groups_Invite_Template( $r ); 3175 3255 return apply_filters( 'bp_group_has_invites', $invites_template->has_invites(), $invites_template ); 3176 3256 } -
trunk/tests/testcases/groups/template.php
r7986 r8045 476 476 $this_user = new BP_Core_User( $found_users[ $counter ] ); 477 477 foreach ( get_object_vars( $this_user ) as $k => $v ) { 478 // Doesn't matter if the backpat provides *more* 479 // details than the old method, so we skip cases 480 // where the BP_Core_User value is empty 481 if ( empty( $v ) ) { 482 continue; 483 } 484 478 485 $this->assertEquals( $v, $invites_template->invite->user->{$k} ); 479 486 } … … 481 488 endwhile; 482 489 } 490 491 /** 492 * @group bp_group_has_invites 493 * @group BP_Groups_Invite_Template 494 */ 495 public function test_bp_group_has_invites_pagination() { 496 $u1 = $this->create_user( array( 497 'last_activity' => gmdate( 'Y-m-d H:i:s', time() - 60 ), 498 ) ); 499 500 $g = $this->factory->group->create( array( 501 'creator_id' => $u1, 502 ) ); 503 504 $users = array(); 505 for ( $i = 1; $i < 15; $i++ ) { 506 $users[ $i ] = $this->create_user( array( 507 'last_activity' => gmdate( 'Y-m-d H:i:s', time() - $i ), 508 ) ); 509 510 $this->add_user_to_group( $users[ $i ], $g, array( 511 'date_modified' => gmdate( 'Y-m-d H:i:s', time() - $i ), 512 'is_confirmed' => 0, 513 'inviter_id' => $u1, 514 'invite_sent' => true, 515 ) ); 516 } 517 518 // Populate the global 519 bp_group_has_invites( array( 520 'group_id' => $g, 521 'user_id' => $u1, 522 'page' => 2, 523 'per_page' => 5, 524 ) ); 525 526 global $invites_template; 527 528 $this->assertEquals( array( $users[ 9 ], $users[ 8 ], $users[ 7 ], $users[ 6 ], $users[ 5 ], ), $invites_template->invites ); 529 } 483 530 }
Note: See TracChangeset
for help on using the changeset viewer.