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

Ticket #4148 - Build-in API support: Action objects - Reactions.

AntonLV 3 лет назад
Родитель
Сommit
151ed02435

+ 6 - 1
inc/classes/BxDolVote.php

@@ -91,7 +91,7 @@ class BxDolVote extends BxDolObject
         if(empty($this->_sSystem))
             return;
 
-        $this->_aVote = array();
+        $this->_aVote = [];
     }
 
     /**
@@ -179,6 +179,11 @@ class BxDolVote extends BxDolObject
         return (int)$this->_aSystem['is_undo'] == 1;
     }
 
+    public function getType()
+    {
+        return $this->_sType;
+    }
+
     public function getMinValue()
     {
         return (int)$this->_aSystem['min_value'];

+ 1 - 0
inc/classes/BxDolVoteReactions.php

@@ -220,6 +220,7 @@ class BxDolVoteReactions extends BxTemplVote
             'label_emoji' => $this->_getEmojiDoWithTrack($bVoted, $aTrack),
             'label_title' => _t($this->_getTitleDoWithTrack($bVoted, $aTrack)),
             'label_click' => $sJsClick,
+            'voted' => $bVoted,
             'disabled' => $bVoted && !$this->isUndo(),
             'total' => array(
                 'rate' => $fTotalR,

+ 26 - 1
template/scripts/BxBaseVoteServices.php

@@ -29,13 +29,38 @@ class BxBaseVoteServices extends BxDol
         if(!$oVote)
             return ['code' => BX_DOL_OBJECT_ERR_NOT_AVAILABLE];
 
+        $sMethod = 'serviceDo' . bx_gen_method_name($oVote->getType());
+        if(method_exists($this, $sMethod))
+            return $this->$sMethod($aParams, $oVote);
+
+        $aResult = $oVote->vote($aParams);
+        if((int)$aResult['code'] != 0)
+            return $aResult;
+
+        return [
+            'is_voted' => $aResult['voted'],
+            'is_disabled' => $aResult['disabled'],
+            'icon' => !empty($aResult['label_emoji']) ? $aResult['label_emoji'] : $aDefaultInfo['emoji'],
+            'title' => !empty($aResult['label_title']) ? $aResult['label_title'] : '',
+            'counter' => $oVote->getVote()
+        ];
+    }
+
+    public function serviceDoReactions($aParams, &$oVote)
+    {
         $aResult = $oVote->vote($aParams);
         if((int)$aResult['code'] != 0)
             return $aResult;
 
+        $aDefault = $oVote->getReaction($oVote->getDefault());
+        $aDefaultInfo = $oVote->getReaction($aDefault['name']);
+
         return [
+            'is_voted' => $aResult['voted'],
+            'is_disabled' => $aResult['disabled'],
             'reaction' => $aResult['reaction'],
-            'icon' => !empty($aResult['label_emoji']) ? $aResult['label_emoji'] : '',
+            'icon' => !empty($aResult['label_emoji']) ? $aResult['label_emoji'] : $aDefaultInfo['emoji'],
+            'title' => !empty($aResult['label_title']) ? $aResult['label_title'] : '',
             'counter' => $oVote->getVote()
         ];
     }