public function SocialProfileTrait::getUserIdsFromName in Open Social 8.7
Same name and namespace in other branches
- 8.9 modules/social_features/social_profile/src/SocialProfileTrait.php \Drupal\social_profile\SocialProfileTrait::getUserIdsFromName()
- 8.2 modules/social_features/social_profile/src/SocialProfileTrait.php \Drupal\social_profile\SocialProfileTrait::getUserIdsFromName()
- 8.3 modules/social_features/social_profile/src/SocialProfileTrait.php \Drupal\social_profile\SocialProfileTrait::getUserIdsFromName()
- 8.4 modules/social_features/social_profile/src/SocialProfileTrait.php \Drupal\social_profile\SocialProfileTrait::getUserIdsFromName()
- 8.5 modules/social_features/social_profile/src/SocialProfileTrait.php \Drupal\social_profile\SocialProfileTrait::getUserIdsFromName()
- 8.6 modules/social_features/social_profile/src/SocialProfileTrait.php \Drupal\social_profile\SocialProfileTrait::getUserIdsFromName()
- 8.8 modules/social_features/social_profile/src/SocialProfileTrait.php \Drupal\social_profile\SocialProfileTrait::getUserIdsFromName()
- 10.3.x modules/social_features/social_profile/src/SocialProfileTrait.php \Drupal\social_profile\SocialProfileTrait::getUserIdsFromName()
- 10.0.x modules/social_features/social_profile/src/SocialProfileTrait.php \Drupal\social_profile\SocialProfileTrait::getUserIdsFromName()
- 10.1.x modules/social_features/social_profile/src/SocialProfileTrait.php \Drupal\social_profile\SocialProfileTrait::getUserIdsFromName()
- 10.2.x modules/social_features/social_profile/src/SocialProfileTrait.php \Drupal\social_profile\SocialProfileTrait::getUserIdsFromName()
Get a list of account IDs whose account names begin with the given string.
Parameters
string $name: The string to search for.
int $count: The number of results to return.
string $suggestion_format: (optional) The suggestion format.
Return value
int[] An array of account IDs for accounts whose account names begin with the given string.
2 calls to SocialProfileTrait::getUserIdsFromName()
- AutocompleteController::suggestions in modules/
social_features/ social_mentions/ src/ Controller/ AutocompleteController.php - Function for suggestions.
- PrivateMessageMapper::getUserIdsFromString in modules/
social_features/ social_private_message/ src/ Mapper/ PrivateMessageMapper.php
File
- modules/
social_features/ social_profile/ src/ SocialProfileTrait.php, line 51
Class
- SocialProfileTrait
- Trait SocialProfileTrait.
Namespace
Drupal\social_profileCode
public function getUserIdsFromName($name, $count, $suggestion_format = SOCIAL_PROFILE_SUGGESTIONS_ALL) {
$query = $this
->startQuery();
$name = '%' . ltrim($query
->escapeLike($name)) . '%';
switch ($suggestion_format) {
case SOCIAL_PROFILE_SUGGESTIONS_USERNAME:
$query
->condition('uf.name', $name, 'LIKE');
break;
case SOCIAL_PROFILE_SUGGESTIONS_FULL_NAME:
case SOCIAL_PROFILE_SUGGESTIONS_ALL:
if ($this
->useFullName()) {
$strings = explode(' ', $name);
if (count($strings) > 1) {
$query
->where("CONCAT(TRIM(fn.field_profile_first_name_value), ' ', TRIM(ln.field_profile_last_name_value)) LIKE :full_name", [
':full_name' => $name,
]);
$query = $this
->sortQuery($query, $name, $suggestion_format);
$results = $this
->endQuery($query, $count);
if (count($results) > 0) {
return $results;
}
// Fallback to creating a new query if there is no hit on full name.
$query = $this
->startQuery();
}
}
$or_query = $query
->orConditionGroup();
if ($this
->useFullName()) {
$or_query
->condition('fn.field_profile_first_name_value', $name, 'LIKE')
->condition('ln.field_profile_last_name_value', $name, 'LIKE');
}
// Add name only when needed.
if ($suggestion_format === SOCIAL_PROFILE_SUGGESTIONS_ALL) {
$or_query
->condition('uf.name', $name, 'LIKE');
}
if ($this
->addNickName() === TRUE) {
$or_query
->condition('nn.field_profile_nick_name_value', $name, 'LIKE');
}
$query
->condition($or_query);
break;
}
// Now we sort the query.
$query = $this
->sortQuery($query, $name, $suggestion_format);
return $this
->endQuery($query, $count);
}