class GetNodes in Taxonomy Facets 8
Hierarchy
- class \Drupal\taxonomy_facets\GetNodes
Expanded class hierarchy of GetNodes
File
- src/
GetNodes.php, line 5
Namespace
Drupal\taxonomy_facetsView source
class GetNodes {
private $filters;
private $nodeTypes = null;
private $start;
private $limit;
private $number_of_nodes;
public function __construct($filters) {
$this->filters = $filters;
$config = \Drupal::config('taxonomy_facets.settings');
$this->limit = $config
->get('number_of_nodes_per_page');
// Set node type that are part of filtering, from user config.
$contentTypes = \Drupal::service('entity.manager')
->getStorage('node_type')
->loadMultiple();
foreach ($contentTypes as $contentType) {
if ($config
->get('ct_' . $contentType
->id())) {
$this->nodeTypes[] = $contentType
->id();
}
}
if (empty($_REQUEST['page'])) {
$this->start = 0;
}
else {
$this->start = $_REQUEST['page'] * $this->limit;
}
}
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;
}
public function getNumberOfNodes() {
return $this->number_of_nodes;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
GetNodes:: |
private | property | ||
GetNodes:: |
private | property | ||
GetNodes:: |
private | property | ||
GetNodes:: |
private | property | ||
GetNodes:: |
private | property | ||
GetNodes:: |
public | function | ||
GetNodes:: |
public | function | ||
GetNodes:: |
public | function |