Changeset 7182
- Timestamp:
- 06/07/2013 02:06:51 AM (12 years ago)
- Location:
- trunk
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/bp-groups/bp-groups-classes.php
r7180 r7182 1226 1226 self::refresh_total_group_count_for_user( $this->user_id ); 1227 1227 1228 // Update the group's member count 1229 self::refresh_total_member_count_for_group( $this->group_id ); 1230 1228 1231 do_action_ref_array( 'groups_member_after_save', array( &$this ) ); 1229 1232 … … 1256 1259 1257 1260 function ban() { 1258 1259 1261 if ( !empty( $this->is_admin ) ) 1260 1262 return false; … … 1263 1265 $this->is_banned = 1; 1264 1266 1265 groups_update_groupmeta( $this->group_id, 'total_member_count', ( (int) groups_get_groupmeta( $this->group_id, 'total_member_count' ) - 1 ) );1266 1267 1267 return $this->save(); 1268 1268 } 1269 1269 1270 1270 function unban() { 1271 1272 1271 if ( !empty( $this->is_admin ) ) 1273 1272 return false; 1274 1273 1275 1274 $this->is_banned = 0; 1276 1277 groups_update_groupmeta( $this->group_id, 'total_member_count', ( (int) groups_get_groupmeta( $this->group_id, 'total_member_count' ) + 1 ) );1278 1275 1279 1276 return $this->save(); … … 1299 1296 return false; 1300 1297 1301 groups_update_groupmeta( $this->group_id, 'total_member_count', ( (int) groups_get_groupmeta( $this->group_id, 'total_member_count' ) - 1 ) );1302 1303 1298 // Update the user's group count 1304 1299 self::refresh_total_group_count_for_user( $this->user_id ); 1305 1300 1301 // Update the group's member count 1302 self::refresh_total_member_count_for_group( $this->group_id ); 1303 1306 1304 return $result; 1307 1305 } … … 1309 1307 /** Static Methods ********************************************************/ 1310 1308 1309 /** 1310 * Refresh the total_group_count for a user 1311 * 1312 * @since BuddyPress (1.8) 1313 * @param int $user_id 1314 * @return bool True on success 1315 */ 1311 1316 public static function refresh_total_group_count_for_user( $user_id ) { 1312 bp_update_user_meta( $user_id, 'total_group_count', (int) self::total_group_count( $user_id ) ); 1317 return bp_update_user_meta( $user_id, 'total_group_count', (int) self::total_group_count( $user_id ) ); 1318 } 1319 1320 /** 1321 * Refresh the total_member_count for a group 1322 * 1323 * @since BuddyPress (1.8) 1324 * @param int $group_id 1325 * @return bool True on success 1326 */ 1327 public static function refresh_total_member_count_for_group( $group_id ) { 1328 return groups_update_groupmeta( $group_id, 'total_member_count', (int) BP_Groups_Group::get_total_member_count( $group_id ) ); 1313 1329 } 1314 1330 … … 1320 1336 // Update the user's group count 1321 1337 self::refresh_total_group_count_for_user( $user_id ); 1338 1339 // Update the group's member count 1340 self::refresh_total_member_count_for_group( $group_id ); 1322 1341 1323 1342 return $remove; -
trunk/bp-groups/bp-groups-functions.php
r7179 r7182 124 124 $member->save(); 125 125 126 groups_update_groupmeta( $group->id, 'total_member_count', 1 );127 126 groups_update_groupmeta( $group->id, 'last_activity', bp_core_current_time() ); 128 127 … … 299 298 if ( !groups_uninvite_user( $user_id, $group_id ) ) 300 299 return false; 301 302 // Modify group member count303 groups_update_groupmeta( $group_id, 'total_member_count', (int) groups_get_groupmeta( $group_id, 'total_member_count') - 1 );304 300 305 301 /** … … 362 358 363 359 // Modify group meta 364 groups_update_groupmeta( $group_id, 'total_member_count', (int) groups_get_groupmeta( $group_id, 'total_member_count') + 1 );365 360 groups_update_groupmeta( $group_id, 'last_activity', bp_core_current_time() ); 366 361 … … 722 717 723 718 // Modify group meta 724 groups_update_groupmeta( $group_id, 'total_member_count', (int) groups_get_groupmeta( $group_id, 'total_member_count') + 1 );725 719 groups_update_groupmeta( $group_id, 'last_activity', bp_core_current_time() ); 726 720 … … 920 914 groups_delete_invite( $membership->user_id, $membership->group_id ); 921 915 922 // Modify group member count923 groups_update_groupmeta( $membership->group_id, 'total_member_count', (int) groups_get_groupmeta( $membership->group_id, 'total_member_count') + 1 );924 925 916 // Record this in activity streams 926 917 $group = groups_get_group( array( 'group_id' => $membership->group_id ) ); -
trunk/tests/testcases/groups/functions.php
r7179 r7182 58 58 /** 59 59 * @group total_group_count 60 * @group BP_Groups_Member 61 * @group unban 62 */ 63 public function test_total_group_count_BP_Groups_Member_unban() { 60 * @group groups_unban_member 61 */ 62 public function test_total_group_count_groups_unban_member() { 64 63 $u1 = $this->create_user(); 65 64 $u2 = $this->create_user(); … … 113 112 } 114 113 114 /** 115 * @group total_group_count 116 * @group groups_remove_member 117 */ 115 118 public function test_total_group_count_groups_remove_member() { 116 119 $u1 = $this->create_user(); … … 129 132 $this->assertEquals( 1, bp_get_user_meta( $u2, 'total_group_count', true ) ); 130 133 } 134 135 /** 136 * @group total_member_count 137 * @group groups_join_group 138 */ 139 public function test_total_member_count_groups_join_group() { 140 $u1 = $this->create_user(); 141 $u2 = $this->create_user(); 142 $g = $this->factory->group->create( array( 'creator_id' => $u1 ) ); 143 144 groups_join_group( $g, $u2 ); 145 $this->assertEquals( 2, groups_get_groupmeta( $g, 'total_member_count' ) ); 146 } 147 148 /** 149 * @group total_member_count 150 * @group groups_leave_group 151 */ 152 public function test_total_member_count_groups_leave_group() { 153 $u1 = $this->create_user(); 154 $g1 = $this->factory->group->create( array( 'creator_id' => $u1 ) ); 155 groups_join_group( $g1, $u2 ); 156 157 groups_leave_group( $g1, $u2 ); 158 $this->assertEquals( 1, groups_get_groupmeta( $g1, 'total_member_count' ) ); 159 } 160 161 /** 162 * @group total_member_count 163 * @group groups_ban_member 164 */ 165 public function test_total_member_count_groups_ban_member() { 166 $u1 = $this->create_user(); 167 $u2 = $this->create_user(); 168 $g1 = $this->factory->group->create( array( 'creator_id' => $u1 ) ); 169 groups_join_group( $g1, $u2 ); 170 171 // Fool the admin check 172 $this->set_current_user( $u1 ); 173 buddypress()->is_item_admin = true; 174 175 groups_ban_member( $u2, $g1 ); 176 177 $this->assertEquals( 1, groups_get_groupmeta( $g1, 'total_member_count' ) ); 178 } 179 180 /** 181 * @group total_member_count 182 * @group groups_unban_member 183 */ 184 public function test_total_member_count_groups_unban_member() { 185 $u1 = $this->create_user(); 186 $u2 = $this->create_user(); 187 $g1 = $this->factory->group->create( array( 'creator_id' => $u1 ) ); 188 groups_join_group( $g1, $u2 ); 189 190 // Fool the admin check 191 $this->set_current_user( $u1 ); 192 buddypress()->is_item_admin = true; 193 194 groups_ban_member( $u2, $g1 ); 195 196 groups_unban_member( $u2, $g1 ); 197 198 $this->assertEquals( 2, groups_get_groupmeta( $g1, 'total_member_count' ) ); 199 } 200 201 /** 202 * @group total_member_count 203 * @group groups_accept_invite 204 */ 205 public function test_total_member_count_groups_accept_invite() { 206 $u1 = $this->create_user(); 207 $u2 = $this->create_user(); 208 $g = $this->factory->group->create( array( 'creator_id' => $u1 ) ); 209 groups_invite_user( array( 210 'user_id' => $u1, 211 'group_id' => $g, 212 'inviter_id' => $u2, 213 ) ); 214 215 groups_accept_invite( $u2, $g ); 216 217 $this->assertEquals( 2, groups_get_groupmeta( $g, 'total_member_count' ) ); 218 } 219 220 /** 221 * @group total_member_count 222 * @group groups_accept_membership_request 223 */ 224 public function test_total_member_count_groups_accept_membership_request() { 225 $u1 = $this->create_user(); 226 $u2 = $this->create_user(); 227 $g = $this->factory->group->create( array( 'creator_id' => $u1 ) ); 228 groups_send_membership_request( $u2, $g ); 229 230 groups_accept_membership_request( 0, $u2, $g ); 231 232 $this->assertEquals( 2, groups_get_groupmeta( $g, 'total_member_count' ) ); 233 } 234 235 /** 236 * @group total_member_count 237 * @group groups_remove_member 238 */ 239 public function test_total_member_count_groups_remove_member() { 240 $u1 = $this->create_user(); 241 $u2 = $this->create_user(); 242 $g1 = $this->factory->group->create( array( 'creator_id' => $u1 ) ); 243 groups_join_group( $g1, $u2 ); 244 245 // Fool the admin check 246 $this->set_current_user( $u1 ); 247 buddypress()->is_item_admin = true; 248 249 groups_remove_member( $u2, $g1 ); 250 251 $this->assertEquals( 1, groups_get_groupmeta( $g1, 'total_member_count' ) ); 252 } 253 254 /** 255 * @group total_member_count 256 * @group groups_create_group 257 */ 258 public function test_total_member_count_groups_create_group() { 259 $u1 = $this->create_user(); 260 $g = groups_create_group( array( 261 'creator_id' => $u1, 262 'name' => 'Boone Is Handsome', 263 'description' => 'Yes', 264 'slug' => 'boone-is-handsome', 265 'status' => 'public', 266 'enable_forum' => 0, 267 'date_created' => bp_core_current_time(), 268 ) ); 269 270 $this->assertEquals( 1, groups_get_groupmeta( $g, 'total_member_count' ) ); 271 } 131 272 }
Note: See TracChangeset
for help on using the changeset viewer.