@@ -1527,33 +1527,12 @@ protected function addRelationColumns($columns,$select) {
1527
1527
return $ columns ;
1528
1528
}
1529
1529
1530
- protected function excludeFields ($ fields ,$ exclude ) {
1531
- if ($ fields && $ exclude ) {
1532
- $ columns = explode (', ' ,$ exclude );
1533
- foreach ($ columns as $ column ) {
1534
- $ table = "" ;
1535
- if (strpos ($ column ,'. ' )) {
1536
- $ key = explode ('. ' ,$ column );
1537
- $ table = $ key [0 ];
1538
- $ column = $ key [1 ];
1539
- } else {
1540
- if (count ($ fields )==1 ) {
1541
- $ table = array_keys ($ fields )[0 ];
1542
- }
1543
- }
1544
- if (array_key_exists ($ table ,$ fields ) and array_key_exists ($ column ,$ fields [$ table ])) {
1545
- unset($ fields [$ table ][$ column ]);
1546
- }
1547
- }
1548
- }
1549
- return $ fields ;
1550
- }
1551
-
1552
- protected function findFields ($ tables ,$ columns ,$ database ) {
1530
+ protected function findFields ($ tables ,$ columns ,$ exclude ,$ database ) {
1553
1531
$ fields = array ();
1554
1532
foreach ($ tables as $ i =>$ table ) {
1555
1533
$ fields [$ table ] = $ this ->findTableFields ($ table ,$ database );
1556
1534
$ fields [$ table ] = $ this ->filterFieldsByColumns ($ fields [$ table ],$ columns ,$ i ==0 ,$ table );
1535
+ $ fields [$ table ] = $ this ->filterFieldsByExclude ($ fields [$ table ],$ exclude ,$ i ==0 ,$ table );
1557
1536
}
1558
1537
return $ fields ;
1559
1538
}
@@ -1580,6 +1559,28 @@ protected function filterFieldsByColumns($fields,$columns,$first,$table) {
1580
1559
return $ fields ;
1581
1560
}
1582
1561
1562
+ protected function filterFieldsByExclude ($ fields ,$ exclude ,$ first ,$ table ) {
1563
+ if ($ exclude ) {
1564
+ $ columns = explode (', ' ,$ exclude );
1565
+ foreach (array_keys ($ fields ) as $ key ) {
1566
+ $ keep = true ;
1567
+ foreach ($ columns as $ column ) {
1568
+ if (strpos ($ column ,'. ' )) {
1569
+ if ($ column =="$ table. $ key " || $ column =="$ table.* " ) {
1570
+ $ keep = false ;
1571
+ }
1572
+ } elseif ($ first ) {
1573
+ if ($ column ==$ key || $ column =="* " ) {
1574
+ $ keep = false ;
1575
+ }
1576
+ }
1577
+ }
1578
+ if (!$ keep ) unset($ fields [$ key ]);
1579
+ }
1580
+ }
1581
+ return $ fields ;
1582
+ }
1583
+
1583
1584
protected function findTableFields ($ table ,$ database ) {
1584
1585
$ fields = array ();
1585
1586
foreach ($ this ->db ->fetchFields ($ table ) as $ field ) {
@@ -1631,12 +1632,12 @@ protected function getParameters($settings) {
1631
1632
$ table = $ this ->parseRequestParameter ($ request , 'a-zA-Z0-9\-_ ' );
1632
1633
$ key = $ this ->parseRequestParameter ($ request , 'a-zA-Z0-9\-_, ' ); // auto-increment or uuid
1633
1634
$ action = $ this ->mapMethodToAction ($ method ,$ key );
1634
- $ exclude = $ this ->parseGetParameter ($ get , 'exclude ' , 'a-zA-Z0-9\-_,. ' );
1635
1635
$ include = $ this ->parseGetParameter ($ get , 'include ' , 'a-zA-Z0-9\-_, ' );
1636
1636
$ page = $ this ->parseGetParameter ($ get , 'page ' , '0-9, ' );
1637
1637
$ filters = $ this ->parseGetParameterArray ($ get , 'filter ' , false );
1638
1638
$ satisfy = $ this ->parseGetParameter ($ get , 'satisfy ' , 'a-zA-Z0-9\-_,. ' );
1639
1639
$ columns = $ this ->parseGetParameter ($ get , 'columns ' , 'a-zA-Z0-9\-_,.* ' );
1640
+ $ exclude = $ this ->parseGetParameter ($ get , 'exclude ' , 'a-zA-Z0-9\-_,.* ' );
1640
1641
$ orderings = $ this ->parseGetParameterArray ($ get , 'order ' , 'a-zA-Z0-9\-_, ' );
1641
1642
$ transform = $ this ->parseGetParameter ($ get , 'transform ' , 't1 ' );
1642
1643
@@ -1650,8 +1651,7 @@ protected function getParameters($settings) {
1650
1651
// reflection
1651
1652
list ($ tables ,$ collect ,$ select ) = $ this ->findRelations ($ tables ,$ database ,$ auto_include );
1652
1653
$ columns = $ this ->addRelationColumns ($ columns ,$ select );
1653
- $ fields = $ this ->findFields ($ tables ,$ columns ,$ database );
1654
- $ fields = $ this ->excludeFields ($ fields ,$ exclude );
1654
+ $ fields = $ this ->findFields ($ tables ,$ columns ,$ exclude ,$ database );
1655
1655
1656
1656
// permissions
1657
1657
if ($ table_authorizer ) $ this ->applyTableAuthorizer ($ table_authorizer ,$ action ,$ database ,$ tables );
0 commit comments