Просмотр исходного кода

Ticket #3939 - Allow to use custom filter in browsing (SearchResults).

AntonLV 4 лет назад
Родитель
Сommit
e9bd043cf3
1 измененных файлов с 36 добавлено и 0 удалено
  1. 36 0
      modules/base/general/classes/BxBaseModGeneralSearchResult.php

+ 36 - 0
modules/base/general/classes/BxBaseModGeneralSearchResult.php

@@ -60,6 +60,9 @@ class BxBaseModGeneralSearchResult extends BxTemplSearchResult
         $this->addConditionsForAuthorStatus($CNF);
 
         $this->addConditionsForCf($CNF);
+
+        if(!empty($aParams['filter']) && is_array($aParams['filter']))
+            $this->addConditionsForFilter($CNF, $sMode, $aParams);
     }
 
     protected function addConditionsForAuthorStatus($CNF)
@@ -96,6 +99,39 @@ class BxBaseModGeneralSearchResult extends BxTemplSearchResult
         if(!empty($aConditions) && is_array($aConditions))
             $this->aCurrent['restriction'] = array_merge($this->aCurrent['restriction'], $aConditions);
     }
+    
+    protected function addConditionsForFilter($CNF, $sMode, $aParams)
+    {
+        $aFilter = $aParams['filter'];
+        
+        if(empty($aFilter['field']) || empty($aFilter['value']))
+            return;
+        
+        $aRestriction = [
+            'value' => $aFilter['value'],
+            'field' => $aFilter['field'],
+            'operator' => '=',
+        ];
+
+        if(isset($aFilter['operator']))
+            $aRestriction['operator'] = $aFilter['operator'];
+
+        if(isset($aFilter['table']))
+            switch($aFilter['table']) {
+                case 'table':
+                    $aRestriction['table'] = $this->aCurrent['table'];
+                    break;
+
+                case 'tableSearch':
+                    $aRestriction['table'] = $this->aCurrent['tableSearch'];
+                    break;
+
+                default: 
+                    $aRestriction['table'] = $aFilter['table'];
+            }
+
+        $this->aCurrent['restriction']['filter'] = $aRestriction;
+    }
 
     /**
      * Add conditions for private content