public function AlphaPagination::getEntityIds in Views Alpha Pagination 7.2
Construct the actual SQL query for the view being generated.
Then parse it to short-circuit certain conditions that may exist and make any alterations. This is not the most elegant of solutions, but it is very effective.
Return value
array An indexed array of entity identifiers.
1 call to AlphaPagination::getEntityIds()
- AlphaPagination::getEntityPrefixes in src/
AlphaPagination.php - Retrieve the distinct first character prefix from the field tables.
File
- src/
AlphaPagination.php, line 393
Class
- AlphaPagination
- A base views handler for alpha pagination.
Code
public function getEntityIds() {
$this
->ensureQuery();
$query_parts = explode("\n", $this
->getOption('query'));
// Get the base field. This will change depending on the type of view we
// are putting the paginator on.
$base_field = $this->handler->view->base_field;
// If we are dealing with a substring, then short circuit it as we are most
// likely dealing with a glossary contextual filter.
foreach ($query_parts as $k => $part) {
if ($position = strpos($part, "SUBSTRING")) {
$part = substr($part, 0, $position) . " 1 OR " . substr($part, $position);
$query_parts[$k] = $part;
}
}
// Evaluate the last line looking for anything which may limit the result
// set as we need results against the entire set of data and not just what
// is configured in the view.
$last_line = array_pop($query_parts);
if (substr($last_line, 0, 5) != "LIMIT") {
$query_parts[] = $last_line;
}
// Construct the query from the array and change the single quotes from
// HTML special characters back into single quotes.
$query = join("\n", $query_parts);
$query = str_replace("'", '\'', $query);
$query = str_replace("&", '&', $query);
$query = str_replace("<", '<', $query);
$query = str_replace(">", '>', $query);
// Based on our query, get the list of entity identifiers that are affected.
// These will be used to generate the pagination items.
$entity_ids = [];
$result = db_query($query);
while ($data = $result
->fetchObject()) {
$entity_ids[] = $data->{$base_field};
}
return $entity_ids;
}