public function PrivateMessageMapper::getUserIdsFromString in Private Message 8
Same name and namespace in other branches
- 8.2 src/Mapper/PrivateMessageMapper.php \Drupal\private_message\Mapper\PrivateMessageMapper::getUserIdsFromString()
Get a list of account IDs whose account names begin with the given string.
Only accounts that have 'Use private messaging system' permission will be returned, and the viewing user must have both 'View user information' and 'access user profiles' to get any results at all.
Parameters
string $string: The string to search for.
int $count: The number of results to return.
Return value
int[] An array of account IDs for accounts whose account names begin with the given string.
Overrides PrivateMessageMapperInterface::getUserIdsFromString
File
- src/
Mapper/ PrivateMessageMapper.php, line 164
Class
- PrivateMessageMapper
- Interface for the Private Message Mapper class.
Namespace
Drupal\private_message\MapperCode
public function getUserIdsFromString($string, $count) {
if ($this->currentUser
->hasPermission('access user profiles') && $this->currentUser
->hasPermission('use private messaging system')) {
$query = 'SELECT user_data.uid 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) " . 'JOIN {config} AS config ON config.name = :authenticated_config WHERE ' . 'user_data.name LIKE :string AND user_data.name != :current_user AND ' . '(config.data LIKE :use_pm_permission ' . 'OR role_config.data LIKE :use_pm_permission) ' . 'ORDER BY user_data.name ASC';
return $this->database
->queryRange($query, 0, $count, [
':string' => $string . '%',
':current_user' => $this->currentUser
->getAccountName(),
':authenticated_config' => 'user.role.authenticated',
':use_pm_permission' => '%s:28:"use private messaging system"%',
':access_user_profiles_permission' => '%s:20:"access user profiles"%',
])
->fetchCol();
}
else {
return [];
}
}