Przeglądaj źródła

Merge branch 'master' of https://github.com/unaio/una

AntonLV 3 lat temu
rodzic
commit
ee86cda812

+ 17 - 1
inc/classes/BxDolCmts.php

@@ -1746,6 +1746,16 @@ class BxDolCmts extends BxDolFactory implements iBxDolReplaceable, iBxDolContent
     {
     {
         return $this->_getAuthorInfo($iAuthorId);
         return $this->_getAuthorInfo($iAuthorId);
     }
     }
+    
+    public function getParams(&$aBp, &$aDp)
+    {
+        return $this->_getParams($aBp, $aDp);
+    }
+    
+    public function prepareParams(&$aBp, &$aDp)
+    {
+         return $this->_prepareParams($aBp, $aDp);
+    }
 
 
     /**
     /**
      * Internal functions
      * Internal functions
@@ -2175,7 +2185,7 @@ class BxDolCmts extends BxDolFactory implements iBxDolReplaceable, iBxDolContent
         $bItem = !empty($mixedItem) && is_array($mixedItem);
         $bItem = !empty($mixedItem) && is_array($mixedItem);
 
 
         if($bItem) {
         if($bItem) {
-            $iI = $mixedItem['cmt_id'];
+            $iI = 'i' . $mixedItem['cmt_id'];
             $aStructure[$iI] = array(
             $aStructure[$iI] = array(
                 'id' => $mixedItem['cmt_id'], 
                 'id' => $mixedItem['cmt_id'], 
                 'order' => isset($mixedItem['cmt_order']) ? $mixedItem['cmt_order'] : 0, 
                 'order' => isset($mixedItem['cmt_order']) ? $mixedItem['cmt_order'] : 0, 
@@ -2202,12 +2212,18 @@ class BxDolCmts extends BxDolFactory implements iBxDolReplaceable, iBxDolContent
 
 
                 //--- Sort subitems
                 //--- Sort subitems
                 $iWay = isset($aBp['order']['way']) && $aBp['order']['way'] == 'desc' ? -1 : 1;
                 $iWay = isset($aBp['order']['way']) && $aBp['order']['way'] == 'desc' ? -1 : 1;
+
+                //tODO fix
+               // print_r($aPassStructure);
                 uasort($aPassStructure, function($aItem1, $aItem2) use ($iWay) {
                 uasort($aPassStructure, function($aItem1, $aItem2) use ($iWay) {
                     if($aItem1['order'] == $aItem2['order'])
                     if($aItem1['order'] == $aItem2['order'])
                         return 0;
                         return 0;
 
 
                     return $iWay * ($aItem1['order'] < $aItem2['order'] ? -1 : 1);
                     return $iWay * ($aItem1['order'] < $aItem2['order'] ? -1 : 1);
                 });
                 });
+                $aStructure[$iI]['items'] = $aPassStructure;
+               // print_r($aPassStructure);
+            //    echo '-----------------';
             }
             }
         }
         }
     }
     }

+ 1 - 1
modules/base/general/classes/BxBaseModGeneralModule.php

@@ -3504,7 +3504,7 @@ class BxBaseModGeneralModule extends BxDolModule
             return false;
             return false;
         
         
         if (bx_is_api()){
         if (bx_is_api()){
-            return [bx_srv('system', 'get_form', [$sObject, $iId, 0], 'TemplCmtsServices')];
+            return [bx_srv('system', 'get_data_api', [['module' => $sObject, 'object_id' => $iId]], 'TemplCmtsServices')];
         }
         }
         return $oCmts->getCommentsBlock([], ['in_designbox' => false, 'show_empty' => false]);
         return $oCmts->getCommentsBlock([], ['in_designbox' => false, 'show_empty' => false]);
     }
     }

+ 7 - 3
modules/boonex/timeline/classes/BxTimelineTemplate.php

@@ -342,7 +342,9 @@ class BxTimelineTemplate extends BxBaseModNotificationsTemplate
                 $aCmts = [];
                 $aCmts = [];
                 $oCmts = $oModule->getCmtsObject($aPost['comments']['system'], $aPost['comments']['object_id']);
                 $oCmts = $oModule->getCmtsObject($aPost['comments']['system'], $aPost['comments']['object_id']);
                 if($oCmts !== false){
                 if($oCmts !== false){
-                    $aCmts = $oCmts->getCommentsBlockAPI(['per_view' => 1, 'order_by' => 'date', 'order_way' => 'desc', 'type' => 'head'], ['in_designbox' => false, 'show_empty' => false]);
+                    $aParams = ['mode' => 'feed', 'order_way' => 'desc', 'start_from' => 0, 'per_view' => 1];
+                    $aCmts = bx_srv('system', 'get_comments_api', [$oCmts, $aParams], 'TemplCmtsServices');
+                    
                     $aPost['cmts'] = $aCmts;
                     $aPost['cmts'] = $aCmts;
                     $aPost['cmts']['count'] = $aPost['comments']['count'];
                     $aPost['cmts']['count'] = $aPost['comments']['count'];
                 }
                 }
@@ -998,8 +1000,10 @@ class BxTimelineTemplate extends BxBaseModNotificationsTemplate
         if($oCmts === false)
         if($oCmts === false)
             return '';
             return '';
 
 
-        if (bx_is_api())
-            return $oCmts->getCommentsBlockAPI([], ['in_designbox' => false, 'show_empty' => false]);
+        if (bx_is_api()){
+            $aParams = ['mode' => 'feed', 'order_way' => 'desc', 'start_from' => 0];
+            return [bx_srv('system', 'get_comments_api', [$oCmts, $aParams], 'TemplCmtsServices')];
+        }
         
         
         $aCmtsBp = array();
         $aCmtsBp = array();
         if(!empty($aBrowseParams['cmts_preload_number']))
         if(!empty($aBrowseParams['cmts_preload_number']))

+ 14 - 12
template/scripts/BxBaseCmts.php

@@ -134,48 +134,50 @@ class BxBaseCmts extends BxDolCmts
         return $this->_oTemplate->_wrapInTagJsCode("if(window['" . $this->_sJsObjName . "'] == undefined) var " . $this->_sJsObjName . " = new " . $this->_sJsObjClass . "(" . json_encode($aParams) . "); " . $this->_sJsObjName . ".cmtInit();");
         return $this->_oTemplate->_wrapInTagJsCode("if(window['" . $this->_sJsObjName . "'] == undefined) var " . $this->_sJsObjName . " = new " . $this->_sJsObjClass . "(" . json_encode($aParams) . "); " . $this->_sJsObjName . ".cmtInit();");
     }
     }
 
 
-    function getCommentsBlockAPI($aBp = [], $aDp = [], $iCommentId = 0, $iStart = 0)
+    function getCommentsBlockAPI($aParams, $aBp = [], $aDp = ['in_designbox' => false, 'show_empty' => false])
     {
     {
+
         $mixedResult = $this->isViewAllowed();
         $mixedResult = $this->isViewAllowed();
         if($mixedResult !== CHECK_ACTION_RESULT_ALLOWED)
         if($mixedResult !== CHECK_ACTION_RESULT_ALLOWED)
             return $mixedResult; // TODO: error checking
             return $mixedResult; // TODO: error checking
-        
+
         $aBp['type'] = 'head';
         $aBp['type'] = 'head';
         $this->_getParams($aBp, $aDp);
         $this->_getParams($aBp, $aDp);
         $this->_prepareParams($aBp, $aDp);
         $this->_prepareParams($aBp, $aDp);
+        
         $aBp['order']['way'] = 'desc';
         $aBp['order']['way'] = 'desc';
-        $aBp['order_way'] = 'desc';
-        $aBp['start'] = $iStart ; 
+        $aBp['order_way'] =  'desc';
+        $aBp['start'] = 0 ; 
         $aPp = $aBp['per_view'];
         $aPp = $aBp['per_view'];
         $aBp['per_view'] =  $aBp['per_view'] + 1; 
         $aBp['per_view'] =  $aBp['per_view'] + 1; 
 
 
         $aCmts = [];
         $aCmts = [];
-        
-        if ($iCommentId == 0)
+
+        if (!isset($aParams['comment_id']))
             $aCmts = $this->getCommentsArray($aBp['vparent_id'], $aBp['filter'], $aBp['order'], $aBp['start'], $aBp[($aBp['init_view'] != -1 ? 'init' : 'per') . '_view']);
             $aCmts = $this->getCommentsArray($aBp['vparent_id'], $aBp['filter'], $aBp['order'], $aBp['start'], $aBp[($aBp['init_view'] != -1 ? 'init' : 'per') . '_view']);
         else
         else
-            $aCmts = [['cmt_id' => $iCommentId]];
+            $aCmts = [['cmt_id' => $aParams['comment_id']]];
         
         
-        $iStartFrom = 0;
+        $aParams['start_from'] = 0;
         if (count($aCmts) == $aBp['per_view']){
         if (count($aCmts) == $aBp['per_view']){
             $aBp['per_view'] = $aPp;
             $aBp['per_view'] = $aPp;
             $aCmts = array_slice($aCmts, 0, $aBp['per_view']); 
             $aCmts = array_slice($aCmts, 0, $aBp['per_view']); 
-            $iStartFrom = $aBp['start'] + $aBp['per_view'];
+            $aParams['start_from'] = $aBp['start'] + $aBp['per_view'];
         }
         }
             
             
         $aCmtsRv = [];
         $aCmtsRv = [];
-        
         foreach ($aCmts as $aCmt) {
         foreach ($aCmts as $aCmt) {
             $aCmtsRv[] = $this->getCommentStructure($aCmt['cmt_id'], $aBp, $aDp);
             $aCmtsRv[] = $this->getCommentStructure($aCmt['cmt_id'], $aBp, $aDp);
         }
         }
-        
         return [
         return [
             'unit' => 'comments',
             'unit' => 'comments',
-            'start' => $iStartFrom,
+            'start' => 0,
+            'order' => 'a',
             'module' => $this->_sSystem, 
             'module' => $this->_sSystem, 
             'object_id' => $this->_iId,
             'object_id' => $this->_iId,
             'data' => $aCmtsRv,
             'data' => $aCmtsRv,
         ];
         ];
+        
     }
     }
 
 
     function decodeData ($a)
     function decodeData ($a)

+ 92 - 22
template/scripts/BxBaseCmtsServices.php

@@ -408,44 +408,114 @@ class BxBaseCmtsServices extends BxDol
         );
         );
     }
     }
     
     
-    public function serviceGetForm($sObject, $iId, $iParent)
+    public function serviceGetDataApi($aParams)
     {
     {
-        $oCmts = BxDolCmts::getObjectInstance($sObject, $iId);
+         if(is_string($aParams))
+            $aParams = json_decode($aParams, true);
+        
+        $aParams['parent_id'] = !isset($aParams['parent_id']) ? 0 : $aParams['parent_id'];
+        $aParams['start_from'] = !isset($aParams['start_from']) ? 0 : $aParams['start_from'];
+        $aParams['order_way'] = !isset($aParams['order_way']) ? 'desc' : $aParams['order_way'];
+        $aParams['is_form'] = !isset($aParams['is_form']) ? true : $aParams['is_form'];
+        $aParams['insert'] = 'before';
+        
+        $oCmts = BxDolCmts::getObjectInstance($aParams['module'], $aParams['object_id']);
+        
         if (!$oCmts || !$oCmts->isEnabled())
         if (!$oCmts || !$oCmts->isEnabled())
             return false;
             return false;
         
         
-        $oForm = $oCmts->getFormPost($iParent);
+        $aRv = [
+            'id' => '1',
+            'url' => '/api.php?r=system/get_data_api/TemplCmtsServices/&params[]=',
+            'type' => 'comments'
+        ];
         
         
-        if (isset($oForm['form'])){
-            $aRv = [
-                'id' => '1', 
-                'type' => 'comments', 
-                'form' => ['id' => 'cmt_form', 'type' => 'form', 'name' => 'comment', 'data' => $oForm['form']->getCodeAPI(), 'request' => ['url' => '/api.php?r=system/get_form/TemplCmtsServices/&params=' . json_encode([$sObject, $iId, $iParent]), 'immutable' => true]]];
+        $oForm = $oCmts->getFormPost($aParams['parent_id']);
+        $bIsList =  false;
+        if (isset($oForm['form']) && $aParams['is_form']){
+            $aRv['form'] = ['id' => 'cmt_form', 'type' => 'form', 'name' => 'comment', 'data' => $oForm['form']->getCodeAPI(), 'request' => ['immutable' => true]];
             
             
-            $aRv['browse'] = [
-               'id' => 'cmt_list', 
-               'type' => 'browse', 
-               'insert' => 'before', 
-               'data' => $oCmts->getCommentsBlockAPI([], ['in_designbox' => false, 'show_empty' => false], $oForm['res'] > 0 ? $oForm['res'] : 0)
-            ];
+            // add view (form + new comment)
+            if($oForm['form']->isSubmittedAndValid()){
+                $aParams['insert'] = $aParams['order_way'] == 'desc' ? 'before' : 'after';
+                $aParams['comment_id'] = $oForm['res'];
+                $bIsList = true;
+            }
+            // default view (form + list)
+            if (!$oForm['form']->isSubmitted()){
+                $bIsList = true;
+            }
         }
         }
-        
+        else{
+            // list only view
+            $bIsList = true;                  
+            $aParams['insert'] = 'after';
+        }
+        if ($bIsList)
+            $aRv['browse'] = $this->serviceGetCommentsApi($oCmts, $aParams);
+
         return $aRv;
         return $aRv;
     }
     }
     
     
-    public function serviceGetList($sObject, $iId, $iStart)
+    public function serviceGetCommentsApi($oCmts, $aParams)
     {
     {
-        $oCmts = BxDolCmts::getObjectInstance($sObject, $iId);
+        $mixedResult = $oCmts->isViewAllowed();
+        if($mixedResult !== CHECK_ACTION_RESULT_ALLOWED)
+            return $mixedResult; // TODO: error checking
+
+        $aBp = !isset($aParams['aBp']) ? [] : $aParams['aBp'];
+        $aDp = ['in_designbox' => false, 'show_empty' => false];
         
         
-        if (!$oCmts || !$oCmts->isEnabled())
-            return false;
+
+        $aBp['type'] = 'head';
+        $oCmts->getParams($aBp, $aDp);
+        $oCmts->prepareParams($aBp, $aDp);
         
         
-        $aRv['browse'] = [
+        $aBp['order']['way'] = $aParams['order_way'];
+        $aBp['order_way'] = $aParams['order_way'];
+        $aBp['start'] = $aParams['start_from'] ; 
+        $aPp = $aBp['per_view'];
+        $aBp['per_view'] =  $aBp['per_view'] + 1; 
+        if (isset($aParams['per_view'])){
+             $aBp['per_view'] = $aParams['per_view'];
+        }
+
+        $aCmts = isset($aParams['comment_id']) ? [['cmt_id' => $aParams['comment_id']]] : $oCmts->getCommentsArray($aBp['vparent_id'], $aBp['filter'], $aBp['order'], $aBp['start'], $aBp[($aBp['init_view'] != -1 ? 'init' : 'per') . '_view']);
+
+        
+        $aParams['start_from'] = 0;
+        if (count($aCmts) == $aBp['per_view']){
+            $aBp['per_view'] = $aPp;
+            $aCmts = array_slice($aCmts, 0, $aBp['per_view']); 
+            $aParams['start_from'] = $aBp['start'] + $aBp['per_view'];
+        }
+            
+        $aCmtsRv = [];
+        foreach ($aCmts as $aCmt) {
+            $aCmtsRv[] = $oCmts->getCommentStructure($aCmt['cmt_id'], $aBp, $aDp);
+        }
+        $aData = [
+            'unit' => 'comments',
+            'start' => $aParams['start_from'],
+            'order' => $aParams['order_way'],
+            'module' => $oCmts->getSystemName(), 
+            'object_id' => $oCmts->getId(),
+            'data' => $aCmtsRv
+        ];
+        if (isset($aParams['mode']) &&  $aParams['mode'] == 'feed')
+            return $aData;
+        
+        $aRv = [
             'id' => 'cmt_list', 
             'id' => 'cmt_list', 
             'type' => 'browse', 
             'type' => 'browse', 
-            'insert' => 'after', 
-            'data' => $oCmts->getCommentsBlockAPI([], ['in_designbox' => false, 'show_empty' => false], 0, $iStart)
+            'insert' => $aParams['insert'], 
+            'data' => $aData
         ];
         ];
+        
+        if (isset($aParams['comment_id'])){
+            $aRv['new'] = $aParams['comment_id'];
+        }
+        
         return $aRv;
         return $aRv;
     }
     }
 }
 }