Skip to content

Commit 2eddaa8

Browse files
jessevzjessevz
andauthored
Fixed bug in pagination where filters where not used for pagination (#1591)
* Fixed bug in pagination where filters where not used for pagination * Fixed copilot suggestions --------- Co-authored-by: jessevz <[email protected]>
1 parent 18c80c8 commit 2eddaa8

File tree

2 files changed

+18
-6
lines changed

2 files changed

+18
-6
lines changed

src/dba/PaginationFilter.class.php

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,23 @@ class PaginationFilter extends Filter {
88
private $operator;
99
private $tieBreakerKey;
1010
private $tieBreakerValue;
11+
private $filters;
1112
/**
1213
* @var AbstractModelFactory
1314
*/
1415
private $factory;
1516

16-
function __construct($key, $value, $operator, $tieBreakerKey, $tieBreakerValue, $factory = null) {
17+
function __construct($key, $value, $operator, $tieBreakerKey, $tieBreakerValue, $filters = [], $factory = null) {
18+
/**
19+
* @param QueryFilter[] $filters
20+
*/
1721
$this->key = $key;
1822
$this->value = $value;
1923
$this->operator = $operator;
2024
$this->factory = $factory;
2125
$this->tieBreakerKey = $tieBreakerKey;
2226
$this->tieBreakerValue = $tieBreakerValue;
27+
$this->filters = $filters;
2328
}
2429

2530
function getQueryString($table = "") {
@@ -29,15 +34,22 @@ function getQueryString($table = "") {
2934
if ($this->factory != null) {
3035
$table = $this->factory->getModelTable() . ".";
3136
}
37+
$parts = array_map(fn($filter) => $filter->getQueryString(), $this->filters);
3238
//ex. SELECT hashTypeId, description, isSalted, isSlowHash FROM HashType
3339
// where (HashType.isSalted < 1) OR (HashType.isSalted = 1 and HashType.hashTypeId < 12600)
3440
// ORDER BY HashType.isSalted DESC, HashType.hashTypeId DESC LIMIT 25;
35-
return "(" . $table . $this->key . $this->operator . "?" . ") OR (" . $this->key . "=" . "?"
36-
. " AND " . $this->tieBreakerKey . $this->operator . "?)";
41+
$queryString = "(" . $table . $this->key . $this->operator . "?" . ") OR (" . $this->key . "=" . "?"
42+
. " AND " . $this->tieBreakerKey . $this->operator . "?";
43+
if (count($this->filters) > 0) {
44+
$queryString = $queryString . " AND ". implode(" AND ", $parts);
45+
}
46+
$queryString .= ")";
47+
return $queryString;
3748
}
3849

3950
function getValue() {
40-
return [$this->value, $this->value, $this->tieBreakerValue];
51+
$values = [$this->value, $this->value, $this->tieBreakerValue];
52+
return array_merge($values, array_map(fn($filter) => $filter->getValue(), $this->filters));
4153
}
4254

4355
function getHasValue() {
@@ -46,4 +58,4 @@ function getHasValue() {
4658
}
4759
return true;
4860
}
49-
}
61+
}

src/inc/apiv2/common/AbstractModelAPI.class.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -710,7 +710,7 @@ public static function getManyResources(object $apiClass, Request $request, Resp
710710
$secondary_cursor_key = key($secondary_cursor);
711711
$secondary_cursor_key = $secondary_cursor_key == '_id' ? array_column($aliasedfeatures, 'alias', 'dbname')[$apiClass->getPrimaryKey()] : $secondary_cursor_key;
712712
$finalFs[Factory::FILTER][] = new PaginationFilter($primary_cursor_key, current($primary_cursor),
713-
$operator, $secondary_cursor_key, current($secondary_cursor));
713+
$operator, $secondary_cursor_key, current($secondary_cursor), $qFs_Filter);
714714
} else {
715715
$finalFs[Factory::FILTER][] = new QueryFilter($primary_cursor_key, current($primary_cursor), $operator, $factory);
716716
}

0 commit comments

Comments
 (0)