function farm_group_members_count_recursive in farmOS 7
Recursively count group members.
Parameters
FarmAsset $group: The group asset to recurse into.
Return value
int Returns the number of group members in the group, and in sub-groups.
1 call to farm_group_members_count_recursive()
- farm_group_farm_area_link_alter in modules/
farm/ farm_group/ farm_group.farm_area.inc - Implements hook_farm_area_link_alter().
File
- modules/
farm/ farm_group/ farm_group.farm_area.inc, line 51
Code
function farm_group_members_count_recursive(FarmAsset $group) {
// Start an empty counter.
$count = 0;
// Load the members of the group.
$members = farm_group_members($group);
// If there are no members, return.
if (empty($members)) {
return $count;
}
// Count the members.
$count += count($members);
// Iterate through the members.
foreach ($members as $member) {
// If the member is a group, recurse into it and count it's members.
if ($member->type == 'group') {
$count += farm_group_members_count_recursive($member);
}
}
// Return the final count.
return $count;
}