Преглед изворни кода

Ticket #4148 - Build-in API support: Keyword search.

AntonLV пре 3 година
родитељ
комит
ea0c09d0fd
2 измењених фајлова са 25 додато и 5 уклоњено
  1. 7 1
      template/scripts/BxBaseServicePages.php
  2. 18 4
      template/scripts/BxBaseServices.php

+ 7 - 1
template/scripts/BxBaseServicePages.php

@@ -34,7 +34,7 @@ class BxBaseServicePages extends BxDol
     /** 
      * @ref bx_system_general-get_page_by_request "get_page_by_request"
      */
-    public function serviceGetPageByRequest ($sRequest, $sBlocks = '')
+    public function serviceGetPageByRequest ($sRequest, $sBlocks = '', $sParams = '')
     {
         $mixed = BxDolPage::getPageBySeoLink($sRequest);
 
@@ -42,6 +42,12 @@ class BxBaseServicePages extends BxDol
             $aRes = ['redirect' => $sUrl];
         }
         elseif (($oPage = $mixed) && is_object($oPage)) {
+            if(!empty($sParams)) {
+                $aParams = json_decode($sParams, true);
+                if(!empty($aParams) && is_array($aParams))
+                    $_GET = array_merge($_GET, $aParams);
+            }
+
             $aBlocks = [];
             if(!empty($sBlocks))
                 $aBlocks = explode(',', $sBlocks);

+ 18 - 4
template/scripts/BxBaseServices.php

@@ -933,12 +933,26 @@ class BxBaseServices extends BxDol implements iBxDolProfileService
      */
     public function serviceSearchKeywordResult ()
     {
-        $oSearch = $this->_getSearchObject();
-        
+        $sKeyword = bx_get('keyword');
+        $bKeyword = $sKeyword !== false;
+
+        if(bx_is_api()) {
+            $sSection = bx_get('section');
+            if(empty($sSection))
+                $sSection = BxDolDb::getInstance()->fromCache('sys_global_search_items', 'getColumn', 'SELECT `ObjectName` FROM `sys_objects_search` WHERE `GlobalSearch`=\'1\' ORDER BY `Order` ASC');
+                    
+            return $this->serviceGetDataSearchApi([
+                'keyword' => $sKeyword,
+                'section' => $sSection
+            ]);
+        }
+
         $sCode = '';
-        if (bx_get('keyword') !== false) {
+        if($bKeyword) {
+            $oSearch = $this->_getSearchObject();
+
             $sCode = $oSearch->response();
-            if (!$sCode)
+            if(!$sCode)
                 $sCode = $oSearch->getEmptyResult();
         }