You are here

public function GetNodes::getNodes in Taxonomy Facets 8

File

src/GetNodes.php, line 36

Class

GetNodes

Namespace

Drupal\taxonomy_facets

Code

public function getNodes() {
  $query = db_select('node', 'n')
    ->fields('n', array(
    'nid',
  ));
  $cnt = 0;
  foreach ($this->filters as $key => $value) {
    $query
      ->innerJoin('taxonomy_index', 'ti' . $cnt, 'n.nid = ti' . $cnt . ' .nid ');
    $query
      ->condition('ti' . $cnt . '.tid', $value);
    $cnt++;
  }
  if ($this->nodeTypes) {
    $query
      ->condition('n.type', $this->nodeTypes, 'IN');
  }

  // Count all nodes first.
  $number_of_nodes = $query
    ->execute();
  $number_of_nodes->allowRowCount = TRUE;
  $this->number_of_nodes = $number_of_nodes
    ->rowCount();

  // Add range, for use in pager
  $query
    ->range($this->start, $this->limit);
  $nodes = $query
    ->execute()
    ->fetchAll();
  $return = array();
  foreach ($nodes as $node) {
    $return[] = $node->nid;
  }
  return $return;
}