You are here

public function SiteAuditCheckRolesRolesList::calculateScore in Site Audit 7

Implements \SiteAudit\Check\Abstract\calculateScore().

Overrides SiteAuditCheckAbstract::calculateScore

File

Check/Roles/RolesList.php, line 60
Contains \SiteAudit\Check\Users\RolesList.

Class

SiteAuditCheckRolesRolesList
Class SiteAuditCheckRolesRolesList.

Code

public function calculateScore() {
  $sql_query = 'SELECT name';
  $sql_query .= ', COUNT(uid) AS count_users ';
  $sql_query .= 'FROM {role} ';
  $sql_query .= 'LEFT JOIN {users_roles} ON {role}.rid = {users_roles}.rid ';
  $sql_query .= 'GROUP BY {role}.rid ';
  $sql_query .= 'ORDER BY name ASC ';
  $result = db_query($sql_query);
  foreach ($result as $row) {
    if ($row->name === 'authenticated user') {
      $sql_query = 'SELECT COUNT(uid) AS count from {users}';
      $count = db_query($sql_query)
        ->fetchField();
      $this->registry['roles'][$row->name] = $count;
    }
    else {
      $this->registry['roles'][$row->name] = $row->count_users;
    }
  }
  return SiteAuditCheckAbstract::AUDIT_CHECK_SCORE_INFO;
}