@@ -132,15 +132,15 @@ public function setUserId(string $userId): void {
132132 * @return int[]
133133 * @throws InternalError
134134 */
135- private function getWantedRowIds (string $ userId , int $ tableId , ?array $ filter = null , ?array $ sort = null , ?int $ limit = null , ?int $ offset = null ): array {
135+ private function getWantedRowIds (string $ userId , int $ tableId , ?array $ filter = null , ?array $ sort = null , ?int $ limit = null , ?int $ offset = null , array $ customFilters = [] ): array {
136136 $ qb = $ this ->db ->getQueryBuilder ();
137137
138138 $ qb ->select ('sleeves.id ' )
139139 ->from ('tables_row_sleeves ' , 'sleeves ' )
140140 ->where ($ qb ->expr ()->eq ('table_id ' , $ qb ->createNamedParameter ($ tableId , IQueryBuilder::PARAM_INT )));
141141
142- if ($ filter ) {
143- $ this ->addFilterToQuery ($ qb , $ filter , $ userId );
142+ if ($ filter || $ customFilters ) {
143+ $ this ->addFilterToQuery ($ qb , $ filter ?? [], $ customFilters , $ userId );
144144 }
145145
146146 $ this ->addSortQueryForMultipleSleeveFinder ($ qb , 'sleeves ' , $ sort );
@@ -172,14 +172,15 @@ private function getWantedRowIds(string $userId, int $tableId, ?array $filter =
172172 * @param array|null $filter
173173 * @param array|null $sort
174174 * @param string|null $userId
175+ * @param array $customFilters
175176 * @return Row2[]
176177 * @throws InternalError
177178 */
178- public function findAll (array $ showColumnIds , int $ tableId , ?int $ limit = null , ?int $ offset = null , ?array $ filter = null , ?array $ sort = null , ?string $ userId = null ): array {
179+ public function findAll (array $ showColumnIds , int $ tableId , ?int $ limit = null , ?int $ offset = null , ?array $ filter = null , ?array $ sort = null , ?string $ userId = null , array $ customFilters = [] ): array {
179180 try {
180181 $ this ->columnMapper ->preloadColumns ($ showColumnIds , $ filter , $ sort );
181182
182- $ wantedRowIdsArray = $ this ->getWantedRowIds ($ userId , $ tableId , $ filter , $ sort , $ limit , $ offset );
183+ $ wantedRowIdsArray = $ this ->getWantedRowIds ($ userId , $ tableId , $ filter , $ sort , $ limit , $ offset, $ customFilters );
183184
184185 // Get rows without SQL sorting
185186 $ rows = $ this ->getRows ($ wantedRowIdsArray , $ showColumnIds );
@@ -273,16 +274,22 @@ private function getRowsChunk(array $rowIds, array $columnIds): array {
273274 /**
274275 * @throws InternalError
275276 */
276- private function addFilterToQuery (IQueryBuilder $ qb , array $ filters , string $ userId ): void {
277- // TODO move this into service
278- $ this ->replacePlaceholderValues ($ filters , $ userId );
279-
277+ private function addFilterToQuery (IQueryBuilder $ qb , array $ filters , array $ customFilters , string $ userId ): void {
278+ $ conditions = [];
280279 if (count ($ filters ) > 0 ) {
281- $ qb ->andWhere (
282- $ qb ->expr ()->orX (
283- ...$ this ->getFilterGroups ($ qb , $ filters )
284- )
285- );
280+ $ this ->replacePlaceholderValues ($ filters , $ userId );
281+ $ conditions [] = $ qb ->expr ()->orX (...$ this ->getFilterGroups ($ qb , $ filters ));
282+ }
283+
284+ if (count ($ customFilters ) > 0 ) {
285+ $ this ->replacePlaceholderValues ($ customFilters , $ userId );
286+ $ conditions [] = $ qb ->expr ()->orX (...$ this ->getFilterGroups ($ qb , $ customFilters ));
287+ }
288+
289+ if (count ($ conditions ) == 1 ) {
290+ $ qb ->andWhere ($ conditions [0 ]);
291+ } elseif (count ($ conditions ) > 1 ) {
292+ $ qb ->andWhere ($ qb ->expr ()->andX (...$ conditions ));
286293 }
287294 }
288295
@@ -350,7 +357,7 @@ private function addSortQueryForMultipleSleeveFinder(IQueryBuilder $qb, string $
350357 private function replacePlaceholderValues (array &$ filters , string $ userId ): void {
351358 foreach ($ filters as &$ filterGroup ) {
352359 foreach ($ filterGroup as &$ filter ) {
353- if (str_starts_with ($ filter ['value ' ], '@ ' )) {
360+ if (is_string ( $ filter [ ' value ' ]) && str_starts_with ($ filter ['value ' ], '@ ' )) {
354361 $ columnId = (int )($ filter ['columnId ' ] ?? 0 );
355362 $ column = $ columnId > 0 ? $ this ->columnMapper ->find ($ columnId ) : null ;
356363 $ filter ['value ' ] = $ this ->columnsHelper ->resolveSearchValue ($ filter ['value ' ], $ userId , $ column );
@@ -593,14 +600,14 @@ private function getFilterExpression(IQueryBuilder $qb, Column $column, string $
593600 /**
594601 * @throws InternalError
595602 */
596- private function getMetaFilterExpression (IQueryBuilder $ qb , int $ columnId , string $ operator , string $ value ): IQueryBuilder {
603+ private function getMetaFilterExpression (IQueryBuilder $ qb , int $ columnId , string $ operator , string | array $ value ): IQueryBuilder {
597604 $ qb2 = $ this ->db ->getQueryBuilder ();
598605 $ qb2 ->select ('id ' );
599606 $ qb2 ->from ('tables_row_sleeves ' );
600607
601608 switch ($ columnId ) {
602609 case Column::TYPE_META_ID :
603- $ qb2 ->where ($ this ->getSqlOperator ($ operator , $ qb , 'id ' , (int )$ value , IQueryBuilder::PARAM_INT ));
610+ $ qb2 ->where ($ this ->getSqlOperator ($ operator , $ qb , 'id ' , (array )$ value , IQueryBuilder::PARAM_INT_ARRAY ));
604611 break ;
605612 case Column::TYPE_META_CREATED_BY :
606613 $ qb2 ->where ($ this ->getSqlOperator ($ operator , $ qb , 'created_by ' , $ value , IQueryBuilder::PARAM_STR ));
@@ -638,6 +645,9 @@ private function getSqlOperator(string $operator, IQueryBuilder $qb, string $col
638645 case 'does-not-contain ' :
639646 return $ qb ->expr ()->notLike ($ columnName , $ qb ->createNamedParameter ('% ' . $ this ->db ->escapeLikeParameter ($ value ) . '% ' , $ paramType ));
640647 case 'is-equal ' :
648+ if (is_array ($ value )) {
649+ return $ qb ->expr ()->in ($ columnName , $ qb ->createNamedParameter ($ value , $ paramType ));
650+ }
641651 return $ qb ->expr ()->eq ($ columnName , $ qb ->createNamedParameter ($ value , $ paramType ));
642652 case 'is-not-equal ' :
643653 return $ qb ->expr ()->neq ($ columnName , $ qb ->createNamedParameter ($ value , $ paramType ));
0 commit comments