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

Ticket #2991 - Simple style for Reactions Counter

AntonLV 6 лет назад
Родитель
Сommit
bea4d6338b

+ 3 - 2
inc/classes/BxDolVoteReactions.php

@@ -12,8 +12,9 @@
  */
 class BxDolVoteReactions extends BxTemplVote
 {
-    protected static $_sCounterStyleDivided = 'divided';
-    protected static $_sCounterStyleCompound = 'compound';
+    protected static $_sCounterStyleSimple = 'simple'; // total counter only.
+    protected static $_sCounterStyleDivided = 'divided'; // counters [icon + counter] divided by reactions.
+    protected static $_sCounterStyleCompound = 'compound'; // total counter with a list of reaction icons.
 
     protected $_sMenuDoVote; //--- Do vote (reaction)  menu name.
 

+ 1 - 1
inc/js/classes/BxDolVoteReactions.js

@@ -243,7 +243,7 @@ BxDolVoteReactions.prototype._getCounter = function(oElement)
     var oCounter = BxDolVote.prototype._getCounter.call(this, oElement);
     if(oCounter && oCounter.length > 0)
         return oCounter;
-//.parent(':visible')
+
     return $('.' + this._aHtmlIds['counter']).find('.' + this._sSP + '-counter');
 };
 

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

@@ -473,7 +473,7 @@ class BxBaseModGeneralFormEntry extends BxTemplFormView
         $sReactions = '';
         $oReaction = BxDolVote::getObjectInstance($aInput['rateable'], $iId, true, BxDolTemplate::getInstance());
         if ($oReaction)    
-            $sReactions = $oReaction->getElementInline(array('show_counter_empty' => true, 'show_counter' => true, 'show_counter_style' => 'compound', 'dynamic_mode' => $this->_bDynamicMode));
+            $sReactions = $oReaction->getElementInline(array('show_counter_empty' => true, 'show_counter' => true, 'show_counter_style' => 'simple', 'dynamic_mode' => $this->_bDynamicMode));
         
         return $this->oTemplate->parseHtmlByName('form_view_row.html', array(
             'type' => $aInput['type'], 

+ 62 - 2
template/scripts/BxBaseVoteReactions.php

@@ -35,7 +35,7 @@ class BxBaseVoteReactions extends BxDolVoteReactions
             'show_do_vote_label' => false,
             'show_counter' => false,
             'show_counter_empty' => true,
-            'show_counter_style' => self::$_sCounterStyleDivided, //--- Alloved styles are 'divided' and 'compound'
+            'show_counter_style' => self::$_sCounterStyleDivided, //--- Alloved styles are 'simple', 'divided' and 'compound'
             'show_legend' => false,
             'show_script' => true
         );
@@ -69,7 +69,7 @@ class BxBaseVoteReactions extends BxDolVoteReactions
         $sJsObject = $this->getJsObjectName();
         $sJsMethod = 'toggleByPopup';
 
-        if(isset($aParams['show_counter_style']) && $aParams['show_counter_style'] == self::$_sCounterStyleCompound)
+        if(isset($aParams['show_counter_style']) && in_array($aParams['show_counter_style'], array(self::$_sCounterStyleCompound, self::$_sCounterStyleSimple)))
             return $sJsObject . '.' . $sJsMethod . '(this)';
 
         $sReaction = !empty($aParams['reaction']) ? $aParams['reaction'] : $this->_sDefault;
@@ -89,6 +89,66 @@ class BxBaseVoteReactions extends BxDolVoteReactions
         return $this->$sMethod($aParams);
     }
 
+    public function _getCounterSimple($aParams = array())
+    {
+        $bDynamicMode = isset($aParams['dynamic_mode']) && (bool)$aParams['dynamic_mode'] === true;
+        $bShowCounterEmpty = isset($aParams['show_counter_empty']) && (bool)$aParams['show_counter_empty'] === true;
+        $bShowScript = !isset($aParams['show_script']) || (bool)$aParams['show_script'] === true;
+
+        $bVote = $this->_isVote();
+        $aVote = $this->_getVote();
+        $aReactions = $this->getReactions();
+
+        $sClass = isset($aParams['class_counter']) ? $aParams['class_counter'] : '';
+        if(isset($aParams['show_do_vote_as_button_small']) && (bool)$aParams['show_do_vote_as_button_small'] === true)
+            $sClass .= ' bx-btn-small-height';
+        else if(isset($aParams['show_do_vote_as_button']) && (bool)$aParams['show_do_vote_as_button'] === true)
+            $sClass .= ' bx-btn-height';
+
+        $aParams['id_counter'] = '';
+
+        $iResultC = $iResultS = 0;
+        foreach($aReactions as $sName) {
+            $iResultC += (int)$aVote['count_' . $sName];
+            $iResultS += (int)$aVote['sum_' . $sName];
+        }
+
+        $aParams = array_merge($aParams, array(
+            'show_counter_active' => false,
+            'show_counter_label_icon' => false,
+            'show_counter_label_text' => true,
+            'class_counter' => ' total-count ' . $sClass,
+            'reaction' => '',
+            'vote' => array(
+                'count' => $iResultC,
+                'sum' => $iResultS,
+                'rate' => $iResultC > 0 ? round($iResultS / $iResultC, 2) : 0,
+            )
+        ));
+
+        return $this->_oTemplate->parseHtmlByContent($this->_getTmplContentCounterWrapper(), array(
+            'html_id' => $this->_aHtmlIds['counter'],
+            'style_prefix' => $this->_sStylePrefix,
+            'class' => $this->_aHtmlIds['counter'] . (!$bVote && !$bShowCounterEmpty ? ' bx-vc-hidden' : ''),
+            'type' => $this->_sType,
+            'style' => self::$_sCounterStyleSimple,
+            'bx_if:show_link' => array(
+                'condition' => true,
+                'content' => array(
+                    'href' => 'javascript:void(0)',
+                    'onclick' => 'javascript:' . $this->getJsClickCounter($aParams),
+                    'title' => bx_html_attribute($this->_getTitleDoBy($aParams)),
+                    'counter' => parent::getCounter(array_merge($aParams, array('show_script' => false))),
+                )
+            ),
+            'bx_if:show_text' => array(
+                'condition' => false,
+                'content' => array()
+            ),
+            'script' => $bShowScript ? $this->getJsScript($aParams) : ''
+        ));
+    }
+
     public function _getCounterDivided($aParams = array())
     {
         $bDynamicMode = isset($aParams['dynamic_mode']) && (bool)$aParams['dynamic_mode'] === true;