private function SpiController::getAdminCount in Acquia Connector 8
Same name and namespace in other branches
- 8.2 src/Controller/SpiController.php \Drupal\acquia_connector\Controller\SpiController::getAdminCount()
- 3.x src/Controller/SpiController.php \Drupal\acquia_connector\Controller\SpiController::getAdminCount()
The number of users who have admin-level user roles.
Return value
int Count of admin users.
1 call to SpiController::getAdminCount()
- SpiController::get in src/
Controller/ SpiController.php - Gather site profile information about this site.
File
- src/
Controller/ SpiController.php, line 662
Class
- SpiController
- SPI Controller class.
Namespace
Drupal\acquia_connector\ControllerCode
private function getAdminCount() {
$roles_name = [];
$get_roles = Role::loadMultiple();
unset($get_roles[AccountInterface::ANONYMOUS_ROLE]);
$permission = [
'administer permissions',
'administer users',
];
foreach ($permission as $value) {
$filtered_roles = array_filter($get_roles, function ($role) use ($value) {
return $role
->hasPermission($value);
});
foreach ($filtered_roles as $role_name => $data) {
$roles_name[] = $role_name;
}
}
if (!empty($roles_name)) {
$roles_name_unique = array_unique($roles_name);
$query = Database::getConnection()
->select('user__roles', 'ur');
$query
->fields('ur', [
'entity_id',
]);
$query
->condition('ur.bundle', 'user', '=');
$query
->condition('ur.deleted', '0', '=');
$query
->condition('ur.roles_target_id', $roles_name_unique, 'IN');
$count = $query
->countQuery()
->execute()
->fetchField();
}
return isset($count) && is_numeric($count) ? $count : NULL;
}