1
0
Эх сурвалжийг харах

Ticket #4558 - Build-in API support: View comment with its parents.

AntonLV 2 жил өмнө
parent
commit
e2b9a9f609

+ 29 - 1
inc/classes/BxDolCmts.php

@@ -850,6 +850,18 @@ class BxDolCmts extends BxDolFactory implements iBxDolReplaceable, iBxDolContent
         return $this->_oQuery->getComment ($this->getId(), $iCmtId);
     }
 
+    public function getCommentParents ($mixedCmt, $iDepthMax = 0)
+    {
+        if(!is_array($mixedCmt))
+            $mixedCmt = $this->_oQuery->getCommentsBy(['type' => 'id', 'id' => (int)$mixedCmt]);
+
+        $iDepth = 0;
+        $aParents = [];
+        $this->_getParents($mixedCmt, $iDepthMax, $iDepth, $aParents);
+
+        return $aParents;
+    }
+
     public function onObjectDelete ($iObjectId = 0)
     {
         // delete comments
@@ -2400,7 +2412,23 @@ class BxDolCmts extends BxDolFactory implements iBxDolReplaceable, iBxDolContent
     {
     	return '_cmt_txt_do';
     }
-    
+
+    protected function _getParents($aCmt, $iDepthMax, &$iDepth, &$aParents)
+    {
+        $iParentId = (int)$aCmt['cmt_parent_id'];
+        if($iParentId == 0)
+            return;
+
+        $aParents[] = $iParentId;
+        $iDepth++;
+
+        if($iDepthMax != 0 && $iDepth == $iDepthMax)
+            return;
+
+        $aCmt = $this->_oQuery->getCommentsBy(['type' => 'id', 'id' => $iParentId]);
+        $this->_getParents($aCmt, $iDepthMax, $iDepth, $aParents);
+    }
+
     public function _getStructure($mixedItem, $aBp, &$iLevel, &$aStructure)
     {
         $bItem = !empty($mixedItem) && is_array($mixedItem);

+ 23 - 9
template/scripts/BxBaseCmtsServices.php

@@ -70,8 +70,10 @@ class BxBaseCmtsServices extends BxDol
         return $oCmts->serviceGetInfo((int)$aCmt['cmt_id'], $bSearchableFieldsOnly);
     }
 
-    public function serviceGetBlockView($sSystem = '', $iObjectId = 0, $iCommentId = 0)
+    public function serviceGetBlockView($sSystem = '', $iObjectId = 0, $iCommentId = 0, $iParentsDepthMax = false)
     {
+        $bIsApi = bx_is_api();
+
         if(empty($sSystem) && ($sSystem = bx_get('sys')) !== false)
             $sSystem = bx_process_input($sSystem);
 
@@ -81,24 +83,35 @@ class BxBaseCmtsServices extends BxDol
         if(empty($iCommentId) && ($iCommentId = bx_get('cmt_id')) !== false)
             $iCommentId = bx_process_input($iCommentId, BX_DATA_INT);
 
-        if(bx_is_api()) {
+        $oCmts = BxDolCmts::getObjectInstance($sSystem, $iObjectId, true);
+        if(!$oCmts)
+            return $bIsApi ? [] : '';
+
+        $iCmtStartFrom = $iCommentId;
+        if($iParentsDepthMax !== false) {
+            $aCmtParents = $oCmts->getCommentParents($iCommentId, $iParentsDepthMax);
+            if(!empty($aCmtParents) && is_array($aCmtParents))
+                $iCmtStartFrom = array_pop($aCmtParents);
+        }
+
+        if($bIsApi) {
             $aRv = $this->serviceGetDataApi([
                 'module' => $sSystem,
                 'object_id' => $iObjectId,
-                'comment_id' => $iCommentId
+                'comment_id' => $iCmtStartFrom
             ]);
 
-            if(isset($aRv['browse']) && is_array($aRv['browse']))
+            if(isset($aRv['browse']) && is_array($aRv['browse'])) {
                 $aRv['browse']['data']['total_count'] = 0;
 
+                if($iParentsDepthMax !== false)
+                    $aRv['browse']['data']['highlighted'] = $iCommentId;
+            }
+
             return [$aRv];
         }
 
-        $oCmts = BxDolCmts::getObjectInstance($sSystem, $iObjectId, true);
-        if(!$oCmts)
-            return '';
-
-        return $oCmts->getCommentBlock($iCommentId);
+        return $oCmts->getCommentBlock($iCmtStartFrom);
     }
 
     public function serviceAlertResponseSysCmtsImagesFileDeleted($oAlert)
@@ -672,6 +685,7 @@ class BxBaseCmtsServices extends BxDol
             'module' => $oCmts->getSystemName(), 
             'object_id' => $oCmts->getId(),
             'max_level' => $oCmts->getSystemInfo()['number_of_levels'],
+            'highlighted' => 0,
             'data' => $aCmtsRv,
         ];
         if (isset($aParams['mode']) &&  $aParams['mode'] == 'feed')