You are here

public static function SuggestionStorage::getTitles in Autocomplete Search Suggestions 3.0.x

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

Fetch an array of node titles.

Parameters

int $nid: The Node ID of the last node batched.

int $limit: The query limit.

Return value

array A node ID to title hash.

1 call to SuggestionStorage::getTitles()
SuggestionHelper::index in src/SuggestionHelper.php
Create a suggestion index from content titles.

File

src/SuggestionStorage.php, line 215

Class

SuggestionStorage
Database CRUD.

Namespace

Drupal\suggestion

Code

public static function getTitles($nid = 0, $limit = NULL) {
  $args = [
    ':nid' => (int) $nid,
    ':types[]' => SuggestionHelper::types(),
  ];
  if (!count($args[':types[]'])) {
    return [];
  }
  $stmt = "\n      SELECT\n        nid,\n        title\n      FROM\n        {node_field_data}\n      WHERE\n        status = 1\n        AND nid > :nid\n        AND type IN (:types[])\n      ORDER BY\n        nid ASC\n    ";
  if (is_numeric($limit)) {
    return \Drupal::database()
      ->queryRange($stmt, 0, $limit, $args)
      ->fetchAllKeyed();
  }
  return \Drupal::database()
    ->query($stmt, $args)
    ->fetchAllKeyed();
}