You are here

function subuser_load_all in Subuser 8

Same name and namespace in other branches
  1. 7.2 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().

... See full list

File

./subuser.module, line 279
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
    ->id()][$index])) {
    if ($children) {

      // Select all user entities where the given account is either the parent or
      // child based on the value of $children.
      $query = \Drupal::entityQuery('user');
      $results = $query
        ->condition('subuser_parent.target_id', $account
        ->id(), '=')
        ->execute();
      $related[$account
        ->id()][$index] = $results;
    }
    else {
      $parent = user_load($account
        ->id())->subuser_parent->value;
      $related[$account
        ->id()][$index] = $parent;
    }
  }
  return $related[$account
    ->id()][$index];
}