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

Ticket #4971 - Build-in API support: Site and Keyword searches.

AntonLV 9 месяцев назад
Родитель
Сommit
bdce494702

+ 6 - 6
inc/classes/BxDolCmts.php

@@ -1920,7 +1920,7 @@ class BxDolCmts extends BxDolFactory implements iBxDolReplaceable, iBxDolContent
     public function serviceGetAuthor ($iContentId)
     {
         $aComment = $this->_oQuery->getCommentsBy(array('type' => 'id', 'id' => $iContentId));
-        $this->setId($aComment['cmt_object_id']);
+        $this->init($aComment['cmt_object_id']);
 
         return $aComment['cmt_author_id'];
     }
@@ -1928,7 +1928,7 @@ class BxDolCmts extends BxDolFactory implements iBxDolReplaceable, iBxDolContent
     public function serviceGetDateAdded ($iContentId)
     {
         $aComment = $this->_oQuery->getCommentsBy(array('type' => 'id', 'id' => $iContentId));
-        $this->setId($aComment['cmt_object_id']);
+        $this->init($aComment['cmt_object_id']);
 
         return $aComment['cmt_time'];
     }
@@ -1940,7 +1940,7 @@ class BxDolCmts extends BxDolFactory implements iBxDolReplaceable, iBxDolContent
     public function serviceGetLink ($iContentId)
     {
         $aComment = $this->_oQuery->getCommentsBy(array('type' => 'id', 'id' => $iContentId));
-        $this->setId($aComment['cmt_object_id']);
+        $this->init($aComment['cmt_object_id']);
 
         return $this->getViewUrl($iContentId);
     }
@@ -1953,7 +1953,7 @@ class BxDolCmts extends BxDolFactory implements iBxDolReplaceable, iBxDolContent
     public function serviceGetText ($iContentId)
     {
         $aComment = $this->_oQuery->getCommentsBy(array('type' => 'id', 'id' => $iContentId));
-        $this->setId($aComment['cmt_object_id']);
+        $this->init($aComment['cmt_object_id']);
 
         return $aComment['cmt_text'];
     }
@@ -1966,7 +1966,7 @@ class BxDolCmts extends BxDolFactory implements iBxDolReplaceable, iBxDolContent
     public function serviceGetInfo ($iContentId, $bSearchableFieldsOnly = true)
     {
         $aComment = $this->_oQuery->getCommentsBy(array('type' => 'id', 'id' => $iContentId));
-        $this->setId($aComment['cmt_object_id']);
+        $this->init($aComment['cmt_object_id']);
 
         return BxDolContentInfo::formatFields($aComment);
     }
@@ -1986,7 +1986,7 @@ class BxDolCmts extends BxDolFactory implements iBxDolReplaceable, iBxDolContent
         if(empty($aComment) || !is_array($aComment))
             return '';
 
-        $this->setId($aComment['cmt_object_id']);
+        $this->init($aComment['cmt_object_id']);
 
         return $this->getComment($aComment, array(), array('type' => BX_CMT_DISPLAY_FLAT, 'view_only' => true));
     }

+ 7 - 28
inc/classes/BxDolSearch.php

@@ -127,8 +127,13 @@ class BxDolSearch extends BxDol
 
             if($this->_bDataProcessing) {
                 if($this->_bIsApi) {
-                    if($bSingle)
-                        $sCode = $oEx->{'decode' . ( $this->_bLiveSearch ? 'Ls' : '') . 'DataAPI'}($oEx->getSearchData());
+                    if($bSingle) {
+                        $sMethod = 'decodeDataAPI';
+                        if($this->_bLiveSearch && ($sMethodLs = 'decodeLsDataAPI') && method_exists($oEx, $sMethodLs))
+                            $sMethod = $sMethodLs;
+
+                        $sCode = $oEx->$sMethod($oEx->getSearchData());
+                    }
                     else
                         $sCode[$sKey] = $oEx->getSearchQuery($sKey);
                 }
@@ -620,32 +625,6 @@ class BxDolSearchResult implements iBxDolReplaceable
     {
         return $a;
     }
-    
-    function decodeLsDataAPI ($aItems)
-    {
-        if(empty($aItems) || !is_array($aItems))
-            return $aItems;
-
-        var_dump($this->getModuleName() . ' --- ' . $this->getContentInfoName());
-
-        $aResult = [];
-        foreach($aItems as $aItem) {
-            $iItemId = $aItem['id'] ?? false;
-            if(!$iItemId)
-                continue;
-
-            $aItemData = $this->_getLsItemDataAPI($iItemId);
-            if($aItemData && is_array($aItemData) && ($aIdContent = ($aItemData['content'] ?? false)))
-                $aResult[] = $aIdContent;
-        }
-
-        return $aResult;
-    }
-
-    protected function _getLsItemDataAPI($iItemId)
-    {
-        return [];
-    }
 
     /**
      * Get html output of search result

+ 12 - 6
modules/base/general/classes/BxBaseModGeneralCmtsSearchResult.php

@@ -96,15 +96,21 @@ class BxBaseModGeneralCmtsSearchResult extends BxBaseModGeneralSearchResult
         return $a;
     }
 
-    protected function _getLsItemDataAPI($iItemId)
+    function decodeLsDataAPI ($aItems)
     {
+        if(empty($aItems) || !is_array($aItems))
+            return $aItems;
+
         $oCmts = BxDolCmts::getObjectInstance($this->sModuleObjectComments, 0, false);
-        if(!$oCmts)
-            return [];
-         
-        return bx_srv('system', 'get_timeline_post', [['object_id' => $oCmts->getCommentUniqId($iItemId)]], 'TemplCmtsServices');
+        foreach($aItems as $i => $aItem) {
+            $oCmts->init($aItem['object_id']);
+
+            $aItems[$i] = $oCmts->getCommentStructure($aItem['id']);
+        }
+
+        return $aItems;
     }
-    
+
     function _getPseud ()
     {
         return array(

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

@@ -297,11 +297,6 @@ class BxBaseModGeneralSearchResult extends BxTemplSearchResult
         return $a;
     }
 
-    protected function _getLsItemDataAPI($iItemId)
-    {
-        return bx_srv($this->getModuleName(), 'get_timeline_post', [['object_id' => $iItemId]]);
-    }
-
     protected function _updateCurrentForFollowedContexts($sMode, $aParams, &$oProfileContext)
     {
         $CNF = &$this->oModule->_oConfig->CNF;

+ 28 - 0
modules/boonex/timeline/classes/BxTimelineSearchResult.php

@@ -80,6 +80,34 @@ class BxTimelineSearchResult extends BxBaseModNotificationsSearchResult
         }
         return $aSql;
     }
+
+    function decodeLsDataAPI ($aItems)
+    {
+        if(empty($aItems) || !is_array($aItems))
+            return $aItems;
+
+        $oMenuActions = false;
+        if(!($oMenuActions = BxDolMenu::getObjectInstance($this->oModule->_oConfig->getObject('menu_item_actions_all'))))
+            $oMenuActions = BxDolMenu::getObjectInstance($this->oModule->_oConfig->getObject('menu_item_actions'));
+
+        $oMenuManage = BxDolMenu::getObjectInstance($this->oModule->_oConfig->getObject('menu_item_manage'));
+
+        $aResults = [];
+        foreach($aItems as $aItem) {
+            $sItem = $this->oModule->_oTemplate->getPost($aItem);
+            if(empty($sItem))
+                continue;
+                
+            $aItem = array_merge($aItem, [
+                'menu_actions' => $oMenuActions,
+                'menu_manage' => $oMenuManage
+            ]);
+
+            $aResults[] = $this->oModule->_oTemplate->getPostApi($aItem);
+        }
+
+        return $aResults;
+    }
 }
 
 /** @} */