You are here

public function SimpleSitemapViews::getArgumentsFromIndex in Simple XML sitemap (Views integration) 8

Get arguments from index.

Parameters

\Drupal\Core\Database\Query\ConditionInterface|null $condition: The query conditions.

int|null $limit: The number of records to return from the result set. If NULL, returns all records.

bool $convert: Defaults to FALSE. If TRUE, the argument string will be converted to an array.

Return value

array An array with information about the indexed arguments.

File

src/SimpleSitemapViews.php, line 179
Contains simple_sitemap_views service.

Class

SimpleSitemapViews
Class to manage sitemap data for views.

Namespace

Drupal\simple_sitemap_views

Code

public function getArgumentsFromIndex(ConditionInterface $condition = NULL, $limit = NULL, $convert = FALSE) {

  // Select the rows from the index table.
  $query = $this->database
    ->select('simple_sitemap_views', 'ssv');
  $query
    ->addField('ssv', 'id');
  $query
    ->addField('ssv', 'view_id');
  $query
    ->addField('ssv', 'display_id');
  $query
    ->addField('ssv', 'arguments_values', 'arguments');

  // Add conditions if necessary.
  if (!empty($condition)) {
    $query
      ->condition($condition);
  }

  // Limit results if necessary.
  if (!empty($limit)) {
    $query
      ->range(0, $limit);
  }
  $rows = $query
    ->execute()
    ->fetchAll();

  // Form the result.
  $arguments = [];
  foreach ($rows as $row) {
    $arguments[$row->id] = [
      'view_id' => $row->view_id,
      'display_id' => $row->display_id,
      'arguments' => $convert ? $this
        ->convertArgumentsStringToArray($row->arguments) : $row->arguments,
    ];
  }
  return $arguments;
}