You are here

public function PrivateMessageMapper::checkPrivateMessageMemberExists in Private Message 8

Same name and namespace in other branches
  1. 8.2 src/Mapper/PrivateMessageMapper.php \Drupal\private_message\Mapper\PrivateMessageMapper::checkPrivateMessageMemberExists()

Determine whether or not the given username exists.

The user must also have the 'use private messaging system' permission.

Parameters

string $username: The username to be validated.

Return value

bool

  • TRUE if the belongs to an account that has the 'use private messaging system' permission
  • FALSE if the account doesn't exist, or does not have the required permission

Overrides PrivateMessageMapperInterface::checkPrivateMessageMemberExists

File

src/Mapper/PrivateMessageMapper.php, line 228

Class

PrivateMessageMapper
Interface for the Private Message Mapper class.

Namespace

Drupal\private_message\Mapper

Code

public function checkPrivateMessageMemberExists($username) {
  return $this->database
    ->queryRange('SELECT 1 FROM {users_field_data} AS user_data LEFT JOIN {user__roles} AS ' . 'user_roles ON user_roles.entity_id = user_data.uid  LEFT JOIN {config} ' . 'AS role_config ' . "ON role_config.name = CONCAT('user.role.', user_roles.roles_target_id) " . 'LEFT JOIN {config} AS authenticated_config ' . 'ON authenticated_config.name = :authenticated_user_role ' . 'WHERE user_data.name = :username ' . 'AND (role_config.data LIKE :permission OR authenticated_config.data LIKE :permission)', 0, 1, [
    ':username' => $username,
    ':authenticated_user_role' => 'user.role.authenticated',
    ':permission' => '%use private messaging system%',
  ])
    ->fetchField();
}