You are here

private function SocialProfileTrait::sortQuery in Open Social 8.9

Same name and namespace in other branches
  1. 8.4 modules/social_features/social_profile/src/SocialProfileTrait.php \Drupal\social_profile\SocialProfileTrait::sortQuery()
  2. 8.5 modules/social_features/social_profile/src/SocialProfileTrait.php \Drupal\social_profile\SocialProfileTrait::sortQuery()
  3. 8.6 modules/social_features/social_profile/src/SocialProfileTrait.php \Drupal\social_profile\SocialProfileTrait::sortQuery()
  4. 8.7 modules/social_features/social_profile/src/SocialProfileTrait.php \Drupal\social_profile\SocialProfileTrait::sortQuery()
  5. 8.8 modules/social_features/social_profile/src/SocialProfileTrait.php \Drupal\social_profile\SocialProfileTrait::sortQuery()
  6. 10.3.x modules/social_features/social_profile/src/SocialProfileTrait.php \Drupal\social_profile\SocialProfileTrait::sortQuery()
  7. 10.0.x modules/social_features/social_profile/src/SocialProfileTrait.php \Drupal\social_profile\SocialProfileTrait::sortQuery()
  8. 10.1.x modules/social_features/social_profile/src/SocialProfileTrait.php \Drupal\social_profile\SocialProfileTrait::sortQuery()
  9. 10.2.x modules/social_features/social_profile/src/SocialProfileTrait.php \Drupal\social_profile\SocialProfileTrait::sortQuery()

Sorts the query.

Following the rules: 1. Users whose have first name starting by the given string; 2. Users whose have last name starting by the given string; 3. Users whose have nickname starting by the given string; 4. Users whose have username starting by the given string; 5. Users containing the string.

Parameters

\Drupal\Core\Database\Query\SelectInterface $query: The select query.

string $name: The sanitized string to search for.

string $suggestion_format: (optional) The suggestion format.

Return value

\Drupal\Core\Database\Query\SelectInterface The select query.

1 call to SocialProfileTrait::sortQuery()
SocialProfileTrait::getUserIdsFromName in modules/social_features/social_profile/src/SocialProfileTrait.php
Get a list of account IDs whose account names begin with the given string.

File

modules/social_features/social_profile/src/SocialProfileTrait.php, line 157

Class

SocialProfileTrait
Trait SocialProfileTrait.

Namespace

Drupal\social_profile

Code

private function sortQuery(SelectInterface $query, $name, $suggestion_format) {
  if ($suggestion_format !== SOCIAL_PROFILE_SUGGESTIONS_USERNAME && $this
    ->useFullName()) {

    // Delete percent symbol on the beginning of the phrase for search from
    // the start of field values.
    $name = substr($name, 1);
    $query
      ->addExpression("\n    CASE WHEN fn.field_profile_first_name_value LIKE :name THEN 0\n      WHEN ln.field_profile_last_name_value LIKE :name THEN 1\n      ELSE 2\n    END\n  ", 'mention_sort', [
      ':name' => $name,
    ]);
    $query
      ->orderBy('mention_sort');
    $query
      ->orderBy('fn.field_profile_first_name_value');
    $query
      ->orderBy('ln.field_profile_last_name_value');
  }
  if ($this
    ->addNickName() === TRUE) {
    $query
      ->orderBy('nn.field_profile_nick_name_value');
  }
  $query
    ->orderBy('uf.name');
  return $query;
}