function subuser_load_all in Subuser 7.2
Same name and namespace in other branches
- 8 subuser.module \subuser_load_all()
Load all related accounts.
Parameters
$account: The user account to which all other accounts will be related.
$children: (Optional) Boolean TRUE to load children of account, otherwise FALSE to load parent(s) of account.
Return value
An associative array of related accounts were key and value is user ID.
7 calls to subuser_load_all()
- subuser_access_create_callback in ./
subuser.module - Determine whether the user has a given privilege.
- subuser_access_delete_callback in ./
subuser.module - Our access callback for user deleting - only permits users with 'delete subusers' to delete user or parent-user to delete subusers
- subuser_access_edit_callback in ./
subuser.module - Our access callback for user editing - only permits users with 'edit subusers' to edit user or parent-user to edit subusers
- subuser_access_view_callback in ./
subuser.module - Our access callback for user viewing - only permits users with 'view subusers' to view user or parent-user to view subusers
- subuser_form_alter in ./
subuser.module - Implements hook_form_alter().
File
- ./
subuser.module, line 327 - Provides primary Drupal hook implementations.
Code
function subuser_load_all($account, $children = TRUE) {
$related =& drupal_static(__FUNCTION__);
// Determine the index we need to look at based on the $children argument.
// The subuser relation has the child entity at index 0 and parent at 1. If
// $children is TRUE then we want to collect the uids from index 0, otherwise
// the uids from index 1.
$index = (int) (!$children);
// Check to see if the related accounts are cached, otherwise load them.
if (!isset($related[$account->uid][$index])) {
// Select all user entities where the given account is either the parent or
// child based on the value of $children.
$results = relation_query('user', $account->uid, (int) $children)
->entityCondition('bundle', 'subuser')
->execute();
// Loop over results and collect uids.
$uids = array();
foreach ($results as $result) {
if ($relation = relation_load($result->rid, $result->vid)) {
$uids[$uid = (int) $relation->endpoints[LANGUAGE_NONE][$index]['entity_id']] = $uid;
}
}
// Store collected uids in static cache.
$related[$account->uid][$index] = $uids;
}
return $related[$account->uid][$index];
}