Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 17 additions & 5 deletions src/dba/PaginationFilter.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,23 @@ class PaginationFilter extends Filter {
private $operator;
private $tieBreakerKey;
private $tieBreakerValue;
private $filters;
/**
* @var AbstractModelFactory
*/
private $factory;

function __construct($key, $value, $operator, $tieBreakerKey, $tieBreakerValue, $factory = null) {
function __construct($key, $value, $operator, $tieBreakerKey, $tieBreakerValue, $filters = [], $factory = null) {
/**
* @param QueryFilter[] $filters
*/
$this->key = $key;
$this->value = $value;
$this->operator = $operator;
$this->factory = $factory;
$this->tieBreakerKey = $tieBreakerKey;
$this->tieBreakerValue = $tieBreakerValue;
$this->filters = $filters;
}

function getQueryString($table = "") {
Expand All @@ -29,15 +34,22 @@ function getQueryString($table = "") {
if ($this->factory != null) {
$table = $this->factory->getModelTable() . ".";
}
$parts = array_map(fn($filter) => $filter->getQueryString(), $this->filters);
//ex. SELECT hashTypeId, description, isSalted, isSlowHash FROM HashType
// where (HashType.isSalted < 1) OR (HashType.isSalted = 1 and HashType.hashTypeId < 12600)
// ORDER BY HashType.isSalted DESC, HashType.hashTypeId DESC LIMIT 25;
return "(" . $table . $this->key . $this->operator . "?" . ") OR (" . $this->key . "=" . "?"
. " AND " . $this->tieBreakerKey . $this->operator . "?)";
$queryString = "(" . $table . $this->key . $this->operator . "?" . ") OR (" . $this->key . "=" . "?"
. " AND " . $this->tieBreakerKey . $this->operator . "?";
if (count($this->filters) > 0) {
$queryString = $queryString . " AND ". implode(" AND ", $parts);
}
$queryString .= ")";
return $queryString;
}

function getValue() {
return [$this->value, $this->value, $this->tieBreakerValue];
$values = [$this->value, $this->value, $this->tieBreakerValue];
return array_merge($values, array_map(fn($filter) => $filter->getValue(), $this->filters));
}

function getHasValue() {
Expand All @@ -46,4 +58,4 @@ function getHasValue() {
}
return true;
}
}
}
2 changes: 1 addition & 1 deletion src/inc/apiv2/common/AbstractModelAPI.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -710,7 +710,7 @@ public static function getManyResources(object $apiClass, Request $request, Resp
$secondary_cursor_key = key($secondary_cursor);
$secondary_cursor_key = $secondary_cursor_key == '_id' ? array_column($aliasedfeatures, 'alias', 'dbname')[$apiClass->getPrimaryKey()] : $secondary_cursor_key;
$finalFs[Factory::FILTER][] = new PaginationFilter($primary_cursor_key, current($primary_cursor),
$operator, $secondary_cursor_key, current($secondary_cursor));
$operator, $secondary_cursor_key, current($secondary_cursor),$qFs_Filter);
} else {
$finalFs[Factory::FILTER][] = new QueryFilter($primary_cursor_key, current($primary_cursor), $operator, $factory);
}
Expand Down