function farm_group_asset_membership in farmOS 7
Load groups that an asset is a member of.
Parameters
FarmAsset $asset: The farm_asset object to look for.
int $time: Unix timestamp limiter. Only logs before this time will be included. Defaults to the current time. Set to 0 to load the absolute last.
bool|null $done: Whether or not to only show logs that are marked as "done". TRUE will limit to logs that are done, and FALSE will limit to logs that are not done. If this is set to NULL, no filtering will be applied. Defaults to TRUE.
Return value
array Returns an array of groups that the asset is a member of.
3 calls to farm_group_asset_membership()
- farm_group_circular_membership in modules/
farm/ farm_group/ farm_group.module - Recursively check for circular group membership.
- farm_group_entity_view_alter in modules/
farm/ farm_group/ farm_group.module - Implements hook_entity_view_alter().
- farm_group_form_farm_asset_form_alter in modules/
farm/ farm_group/ farm_group.module - Implements hook_form_FORM_ID_alter().
File
- modules/
farm/ farm_group/ farm_group.module, line 524
Code
function farm_group_asset_membership(FarmAsset $asset, $time = REQUEST_TIME, $done = TRUE) {
$groups = array();
// Load the log using our helper function.
$log = farm_group_asset_latest_membership($asset, $time, $done);
// Load the log's membership field, if it exists.
if (!empty($log->field_farm_membership[LANGUAGE_NONE][0]['value'])) {
$membership = field_collection_item_load($log->field_farm_membership[LANGUAGE_NONE][0]['value']);
}
// Create an entity metadata wrapper so we can get the membership info.
// If no groups are specified, bail.
if (empty($membership->field_farm_group[LANGUAGE_NONE])) {
return $groups;
}
// Iterate through the referenced groups and load them.
foreach ($membership->field_farm_group[LANGUAGE_NONE] as $group_reference) {
if (!empty($group_reference['target_id'])) {
$group = farm_asset_load($group_reference['target_id']);
if (!empty($group)) {
$groups[] = $group;
}
}
}
return $groups;
}