Przeglądaj źródła

Ticket #4971 - Build-in API support: Search.

AntonLV 1 rok temu
rodzic
commit
f8fbe0be19
2 zmienionych plików z 32 dodań i 11 usunięć
  1. 23 0
      inc/classes/BxDolSearch.php
  2. 9 11
      template/scripts/BxBaseServices.php

+ 23 - 0
inc/classes/BxDolSearch.php

@@ -164,6 +164,29 @@ class BxDolSearch extends BxDol
         return DesignBoxContent($sKey, MsgBox($sKey), BX_DB_PADDING_DEF);
     }
 
+    public function getSearchResultObject($sChoice = '')
+    {
+        $aSearchResult = [];
+
+        if($sChoice) {
+            if(empty($this->aChoice[$sChoice]) || !is_array($this->aChoice[$sChoice]))
+                return false;
+
+            $aSearchResult = $this->aChoice[$sChoice];
+        }
+        else
+            $aSearchResult = reset($this->aChoice);
+
+        $sClassName = 'BxTemplSearchResult';
+        if(!empty($aSearchResult['class'])) {
+            $sClassName = $aSearchResult['class'];
+            if(!empty($aSearchResult['file']))
+                require_once(BX_DIRECTORY_PATH_ROOT . $aSearchResult['file']);
+        }
+
+        return new $sClassName();
+    }
+
     protected function getKeyTitlesPairs ()
     {
         $a = array();

+ 9 - 11
template/scripts/BxBaseServices.php

@@ -1146,20 +1146,19 @@ class BxBaseServices extends BxDol implements iBxDolProfileService
                 $aData = $oSearch->response();
                 if(count($aData) > $aParamsBrowse['per_page'])
                     $aData = array_slice($aData, $aParamsBrowse['start'], $aParamsBrowse['per_page']);
-                
-                
-                if (count($aData) > 0){
-                    $oModule = BxDolModule::getInstance($sSection);
+
+                if (count($aData) > 0) {
+                    $oSearchResult = $oSearch->getSearchResultObject($sSection);
+                    $sSectionTitle = $oSearchResult->aCurrent['title'];
+
                     $aParamsBrowse['section'][] = $sSection;
-                    $aParamsBrowse['sections'][] = ['name' => $sSection, 'title' => $oModule->getModuleTitle()];
-                   
-                    $bIsProfile = BxDolRequest::serviceExists($sSection, 'act_as_profile') && BxDolService::call($sSection, 'act_as_profile');
-                    
+                    $aParamsBrowse['sections'][] = ['name' => $sSection, 'title' => $sSectionTitle];
+
                     $aDataRv[] = [
                         'section' => $sSection, 
-                        'section_name' => $oModule->getModuleTitle(), 
+                        'section_name' => $sSectionTitle, 
                         'data' => $aData,
-                        'is_profile' => $bIsProfile
+                        'is_profile' => bx_srv('system', 'is_module_profile', [$oSearchResult->aCurrent['module_name']])
                     ];
                 }
                 
@@ -1168,7 +1167,6 @@ class BxBaseServices extends BxDol implements iBxDolProfileService
                 'data' => $aDataRv,
                 'params' => $aParamsBrowse
             ])];
-
         }
         else{
             $oSearch = new $sClass($aParamsBrowse['section']);