Selaa lähdekoodia

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

AntonLV 3 vuotta sitten
vanhempi
sitoutus
1abb54d73c
2 muutettua tiedostoa jossa 13 lisäystä ja 10 poistoa
  1. 1 1
      inc/classes/BxDolVoteReactions.php
  2. 12 9
      template/scripts/BxBaseVoteServices.php

+ 1 - 1
inc/classes/BxDolVoteReactions.php

@@ -242,7 +242,7 @@ class BxDolVoteReactions extends BxTemplVote
         $iCount = (int)$aVote['count_' . $sReaction];
         $aResult = array(
             'code' => 0,
-            'reaction' => $sReaction,
+            'reaction' => $aReactions[$sSwitchTo]['name'],
             'rate' => $aVote['rate_' . $sReaction],
             'count' => $iCount,
             'countf' => $iCount > 0 ? $this->_getCounterLabel($iCount, array('reaction' => $sReaction)) : '',

+ 12 - 9
template/scripts/BxBaseVoteServices.php

@@ -107,21 +107,24 @@ class BxBaseVoteServices extends BxDol
 
     protected function _serviceGetPerformedByReactions($aParams, &$oVote)
     {
-        $sReaction = $aParams['reaction'];
+        $aReactions = !empty($aParams['reaction']) ? [$aParams['reaction']] : $oVote->getReactions();
 
-        $aValues = $oVote->getQueryObject()->getPerformed(['type' => 'by', 'object_id' => $oVote->getId(), 'reaction'=> $sReaction]);
+        $aResult = [];
+        foreach($aReactions as $sReaction) {
+            $aValues = $oVote->getQueryObject()->getPerformed(['type' => 'by', 'object_id' => $oVote->getId(), 'reaction'=> $sReaction]);
 
-        $aTmplUsers = [];
-        foreach($aValues as $mValue) {
-            $mValue = is_array($mValue) ? $mValue : ['author_id' => (int)$mValue, 'reaction' => ''];
+            $aTmplUsers = [];
+            foreach($aValues as $mValue) {
+                $mValue = is_array($mValue) ? $mValue : ['author_id' => (int)$mValue, 'reaction' => ''];
 
-            $aTmplUsers[] = BxDolProfile::getData($mValue['author_id']);
+                $aTmplUsers[] = BxDolProfile::getData($mValue['author_id']);
+            }
+
+            $aResult[$sReaction] = $aTmplUsers;
         }
 
         return [
-            'performed_by' => [
-                $sReaction => $aTmplUsers
-            ]
+            'performed_by' => $aResult
         ];
     }
 }