You are here

public static function SuggestionStorage::getCount in Autocomplete Search Suggestions 8.2

Same name and namespace in other branches
  1. 8 src/SuggestionStorage.php \Drupal\suggestion\SuggestionStorage::getCount()
  2. 3.0.x src/SuggestionStorage.php \Drupal\suggestion\SuggestionStorage::getCount()

Fetch the row count.

Parameters

string $langcode: The language code.

string $ngram: The text to search for.

Return value

int The number of rows in the suggestion table.

1 call to SuggestionStorage::getCount()
SuggestionSearchForm::buildForm in src/Form/SuggestionSearchForm.php
The suggestion search form.

File

src/SuggestionStorage.php, line 129

Class

SuggestionStorage
Database CRUD.

Namespace

Drupal\suggestion

Code

public static function getCount($langcode, $ngram = '') {
  if ($ngram) {
    return \Drupal::database()
      ->query("SELECT COUNT(*) FROM {suggestion} WHERE langcode = :langcode AND ngram LIKE :ngram", [
      ':langcode' => $langcode,
      ':ngram' => $ngram,
    ])
      ->fetchField();
  }
  return \Drupal::database()
    ->query("SELECT COUNT(*) FROM {suggestion} WHERE langcode = :langcode", [
    ':langcode' => $langcode,
  ])
    ->fetchField();
}