Changeset 11762 for trunk/src/bp-groups/classes/class-bp-groups-group.php
- Timestamp:
- 12/06/2017 04:18:11 PM (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/bp-groups/classes/class-bp-groups-group.php
r11703 r11762 1026 1026 * results to. If specified, $show_hidden is ignored. 1027 1027 * Default: empty array. 1028 * @type string $fields Which fields to return. Specify 'ids' to fetch a list of IDs. 1029 * Default: 'all' (return BP_Groups_Group objects). 1030 * If set, meta and admin caches will not be prefetched. 1028 1031 * } 1029 1032 * @return array { 1030 1033 * @type array $groups Array of group objects returned by the 1031 * paginated query. 1034 * paginated query. (IDs only if `fields` is set to `ids`.) 1032 1035 * @type int $total Total count of all groups matching non- 1033 1036 * paginated query params. … … 1076 1079 'exclude' => false, 1077 1080 'show_hidden' => false, 1078 'status' => array() 1081 'status' => array(), 1082 'fields' => 'all', 1079 1083 ); 1080 1084 … … 1300 1304 } 1301 1305 1302 $uncached_group_ids = bp_get_non_cached_ids( $paged_group_ids, 'bp_groups' ); 1303 if ( $uncached_group_ids ) { 1304 $group_ids_sql = implode( ',', array_map( 'intval', $uncached_group_ids ) ); 1305 $group_data_objects = $wpdb->get_results( "SELECT g.* FROM {$bp->groups->table_name} g WHERE g.id IN ({$group_ids_sql})" ); 1306 foreach ( $group_data_objects as $group_data_object ) { 1307 wp_cache_set( $group_data_object->id, $group_data_object, 'bp_groups' ); 1306 if ( 'ids' === $r['fields'] ) { 1307 // We only want the IDs. 1308 $paged_groups = array_map( 'intval', $paged_group_ids ); 1309 } else { 1310 $uncached_group_ids = bp_get_non_cached_ids( $paged_group_ids, 'bp_groups' ); 1311 if ( $uncached_group_ids ) { 1312 $group_ids_sql = implode( ',', array_map( 'intval', $uncached_group_ids ) ); 1313 $group_data_objects = $wpdb->get_results( "SELECT g.* FROM {$bp->groups->table_name} g WHERE g.id IN ({$group_ids_sql})" ); 1314 foreach ( $group_data_objects as $group_data_object ) { 1315 wp_cache_set( $group_data_object->id, $group_data_object, 'bp_groups' ); 1316 } 1308 1317 } 1309 } 1310 1311 $paged_groups = array(); 1312 foreach ( $paged_group_ids as $paged_group_id ) { 1313 $paged_groups[] = new BP_Groups_Group( $paged_group_id ); 1314 } 1315 1318 1319 $paged_groups = array(); 1320 foreach ( $paged_group_ids as $paged_group_id ) { 1321 $paged_groups[] = new BP_Groups_Group( $paged_group_id ); 1322 } 1323 1324 $group_ids = array(); 1325 foreach ( (array) $paged_groups as $group ) { 1326 $group_ids[] = $group->id; 1327 } 1328 1329 // Grab all groupmeta. 1330 if ( ! empty( $r['update_meta_cache'] ) ) { 1331 bp_groups_update_meta_cache( $group_ids ); 1332 } 1333 1334 // Prefetch all administrator IDs, if requested. 1335 if ( $r['update_admin_cache'] ) { 1336 BP_Groups_Member::prime_group_admins_mods_cache( $group_ids ); 1337 } 1338 1339 // Set up integer properties needing casting. 1340 $int_props = array( 1341 'id', 'creator_id', 'enable_forum' 1342 ); 1343 1344 // Integer casting. 1345 foreach ( $paged_groups as $key => $g ) { 1346 foreach ( $int_props as $int_prop ) { 1347 $paged_groups[ $key ]->{$int_prop} = (int) $paged_groups[ $key ]->{$int_prop}; 1348 } 1349 } 1350 1351 } 1352 1353 // Find the total number of groups in the results set. 1316 1354 $total_groups_sql = "SELECT COUNT(DISTINCT g.id) FROM {$sql['from']} $where"; 1317 1355 … … 1334 1372 $total_groups = (int) $cached; 1335 1373 } 1336 1337 $group_ids = array();1338 foreach ( (array) $paged_groups as $group ) {1339 $group_ids[] = $group->id;1340 }1341 1342 // Grab all groupmeta.1343 if ( ! empty( $r['update_meta_cache'] ) ) {1344 bp_groups_update_meta_cache( $group_ids );1345 }1346 1347 // Prefetch all administrator IDs, if requested.1348 if ( $r['update_admin_cache'] ) {1349 BP_Groups_Member::prime_group_admins_mods_cache( $group_ids );1350 }1351 1352 // Set up integer properties needing casting.1353 $int_props = array(1354 'id', 'creator_id', 'enable_forum'1355 );1356 1357 // Integer casting.1358 foreach ( $paged_groups as $key => $g ) {1359 foreach ( $int_props as $int_prop ) {1360 $paged_groups[ $key ]->{$int_prop} = (int) $paged_groups[ $key ]->{$int_prop};1361 }1362 }1363 1364 unset( $sql, $total_sql );1365 1374 1366 1375 return array( 'groups' => $paged_groups, 'total' => $total_groups );
Note: See TracChangeset
for help on using the changeset viewer.