@@ -51,7 +51,9 @@ public function index(array $options): void
51
51
$ options ['filters ' ][] = 'filteringTags ' ;
52
52
}
53
53
$ optionFilters = [];
54
- $ optionFilters += empty ($ options ['filters ' ]) ? [] : $ options ['filters ' ];
54
+ $ optionFilters += array_map (function ($ filter ) {
55
+ return is_array ($ filter ) ? $ filter ['name ' ] : $ filter ;
56
+ }, empty ($ options ['filters ' ]) ? [] : $ options ['filters ' ]);
55
57
foreach ($ optionFilters as $ i => $ filter ) {
56
58
$ optionFilters [] = "{$ filter } != " ;
57
59
$ optionFilters [] = "{$ filter } >= " ;
@@ -90,14 +92,17 @@ public function index(array $options): void
90
92
if ($ this ->_validOrderFields ($ sort ) && ($ direction === 'asc ' || $ direction === 'desc ' )) {
91
93
$ sort = explode ('. ' , $ sort );
92
94
if (count ($ sort ) > 1 ) {
93
- $ sort [0 ] = Inflector::camelize (Inflector::pluralize ($ sort [0 ]));
95
+ if ($ sort [0 ] != $ this ->Table ->getAlias ()) {
96
+ $ sort [0 ] = Inflector::camelize (Inflector::pluralize ($ sort [0 ]));
97
+ }
94
98
}
95
99
$ sort = implode ('. ' , $ sort );
96
100
$ query ->order ($ sort . ' ' . $ direction );
97
101
}
98
102
}
103
+ $ isRestOrCSV = $ this ->Controller ->ParamHandler ->isRest () || $ this ->request ->is ('csv ' );
99
104
if ($ this ->metaFieldsSupported ()) {
100
- $ query = $ this ->includeRequestedMetaFields ($ query );
105
+ $ query = $ this ->includeRequestedMetaFields ($ query, $ isRestOrCSV );
101
106
}
102
107
103
108
if (!$ this ->Controller ->ParamHandler ->isRest ()) {
@@ -107,7 +112,7 @@ public function index(array $options): void
107
112
}
108
113
$ data = $ this ->Controller ->paginate ($ query , $ this ->Controller ->paginate ?? []);
109
114
$ totalCount = $ this ->Controller ->getRequest ()->getAttribute ('paging ' )[$ this ->TableAlias ]['count ' ];
110
- if ($ this -> Controller -> ParamHandler -> isRest () || $ this -> request -> is ( ' csv ' ) ) {
115
+ if ($ isRestOrCSV ) {
111
116
if (isset ($ options ['hidden ' ])) {
112
117
$ data ->each (function ($ value , $ key ) use ($ options ) {
113
118
$ hidden = is_array ($ options ['hidden ' ]) ? $ options ['hidden ' ] : [$ options ['hidden ' ]];
@@ -256,6 +261,13 @@ public function filtering(): void
256
261
foreach ($ filtersConfigRaw as $ fieldConfig ) {
257
262
if (is_array ($ fieldConfig )) {
258
263
$ filtersConfig [$ fieldConfig ['name ' ]] = $ fieldConfig ;
264
+ if (!empty ($ fieldConfig ['options ' ])) {
265
+ if (is_string ($ fieldConfig ['options ' ])) {
266
+ $ filtersConfig [$ fieldConfig ['name ' ]]['options ' ] = $ this ->Table ->{$ fieldConfig ['options ' ]}($ this ->Controller ->ACL ->getUser ());
267
+ } else {
268
+ $ filtersConfig [$ fieldConfig ['name ' ]]['options ' ] = $ fieldConfig ['options ' ];
269
+ }
270
+ }
259
271
} else {
260
272
$ filtersConfig [$ fieldConfig ] = ['name ' => $ fieldConfig ];
261
273
}
@@ -777,8 +789,11 @@ public function attachMetaTemplates($data, $metaTemplates, $pruneEmptyDisabled=t
777
789
return $ data ;
778
790
}
779
791
780
- protected function includeRequestedMetaFields ($ query )
792
+ protected function includeRequestedMetaFields ($ query, $ isREST = false )
781
793
{
794
+ if (!empty ($ isREST )) {
795
+ return $ query ->contain (['MetaFields ' ]);
796
+ }
782
797
$ user = $ this ->Controller ->ACL ->getUser ();
783
798
$ tableSettings = IndexSetting::getTableSetting ($ user , $ this ->Table );
784
799
if (empty ($ tableSettings ['visible_meta_column ' ])) {
@@ -1362,7 +1377,12 @@ protected function setNestedRelatedCondition($query, $filterParts, $filterValue)
1362
1377
protected function setRelatedCondition ($ query , $ modelName , $ fieldName , $ filterValue )
1363
1378
{
1364
1379
return $ query ->matching ($ modelName , function (\Cake \ORM \Query $ q ) use ($ fieldName , $ filterValue ) {
1365
- return $ this ->setValueCondition ($ q , $ fieldName , $ filterValue );
1380
+ if (is_array ($ filterValue )) {
1381
+ $ query = $ this ->setInCondition ($ q , $ fieldName , $ filterValue );
1382
+ } else {
1383
+ $ query = $ this ->setValueCondition ($ q , $ fieldName , $ filterValue );
1384
+ }
1385
+ return $ query ;
1366
1386
});
1367
1387
}
1368
1388
0 commit comments