@@ -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+ }
0 commit comments