AntonLV 9 лет назад
Родитель
Сommit
583dbcaa63

+ 12 - 1
modules/boonex/polls/classes/BxPollsDb.php

@@ -74,11 +74,22 @@ class BxPollsDb extends BxBaseModTextDb
                 $sWhereClause .= " AND `entry_id`=:entry_id";
                 break;
 
+            case 'entry_id_max_order':
+                $aMethod['name'] = 'getOne';
+                $aMethod['params'][1] = array(
+                	'entry_id' => $aParams['entry_id']
+                );
+
+                $sSelectClause = "MAX(`order`)";
+                $sWhereClause .= " AND `entry_id`=:entry_id";
+                break;
+
             case 'all':
             	break;
         }
 
-        $sOrderByClause = " ORDER BY " . (isset($aParams['order_by']) ? $aParams['order_by'] : '`title`');
+        $sOrderByClause = " ORDER BY " . (isset($aParams['order_by']) ? '`' . $aParams['order_by'] . '`' : '`order`');
+        $sOrderByClause .= " " . (isset($aParams['order_way']) ? strtoupper($aParams['order_way']) : 'ASC');
 
         $aMethod['params'][0] = "SELECT " . $sSelectClause . " FROM `" . $CNF['TABLE_SUBENTRIES'] . "` WHERE 1 " . $sWhereClause . $sOrderByClause;
 

+ 7 - 3
modules/boonex/polls/classes/BxPollsFormEntry.php

@@ -73,11 +73,12 @@ class BxPollsFormEntry extends BxBaseModTextFormEntry
         if(empty($aSubentries) || !is_array($aSubentries))
             return true;
 
-        foreach($aSubentries as $sSubentry)
+        foreach($aSubentries as $iIndex => $sSubentry)
             if(!empty($sSubentry))
                 $this->_oModule->_oDb->insertSubentry(array(
                     'entry_id' => $iContentId,
-                    'title' => bx_process_input($sSubentry)
+                    'title' => bx_process_input($sSubentry),
+                    'order' => $iIndex
                 ));
 
         return true;
@@ -103,12 +104,15 @@ class BxPollsFormEntry extends BxBaseModTextFormEntry
         $iSubentriesIds = count($aSubentriesIds);
         $iSubentriesValues = count($aSubentriesValues);
         if($iSubentriesValues > $iSubentriesIds) {
+            $iMaxOrder = (int)$this->_oModule->_oDb->getSubentries(array('type' => 'entry_id_max_order', 'entry_id' => $iContentId));
+
             $aSubentriesValues = array_slice($aSubentriesValues, $iSubentriesIds);
             foreach($aSubentriesValues as $sSubentriesValue)
                 if(!empty($sSubentriesValue))
                     $this->_oModule->_oDb->insertSubentry(array(
                         'entry_id' => $iContentId,
-                        'title' => bx_process_input($sSubentriesValue)
+                        'title' => bx_process_input($sSubentriesValue),
+                        'order' => ++$iMaxOrder
                     ));
         }
 

+ 6 - 1
modules/boonex/polls/classes/BxPollsTemplate.php

@@ -60,6 +60,8 @@ class BxPollsTemplate extends BxBaseModTextTemplate
     {
         $CNF = &$this->getModule()->_oConfig->CNF;
 
+        $bAnonymous = (int)$aData[$CNF['FIELD_ANONYMOUS']] == 1;
+
         $aSubentries = $this->_oDb->getSubentries(array('type' => 'entry_id', 'entry_id' => $aData[$CNF['FIELD_ID']]));
         if(empty($aSubentries) || !is_array($aSubentries))
             return '';
@@ -70,11 +72,14 @@ class BxPollsTemplate extends BxBaseModTextTemplate
 
         $aTmplVarsSubentries = array();
         foreach($aSubentries as $aSubentry) {
+            $oVotes = BxDolVote::getObjectInstance($CNF['OBJECT_VOTES_SUBENTRIES'], $aSubentry['id']);
+
             $fPercent = 100 * (float)$aSubentry['votes']/$iTotal;
             $aTmplVarsSubentries[] = array(
                 'title' => $aSubentry['title'],
                 'width' => (int)round($fPercent) . '%',
-                'results' => _t('_bx_polls_txt_subentry_n_votes_m_percent', $aSubentry['votes'], $iTotal > 0 ? round($fPercent, 2) : 0)
+                'votes' => $oVotes->getCounter(array('show_in_brackets' => false)),
+                'percent' => _t('_bx_polls_txt_subentry_vote_percent', $iTotal > 0 ? round($fPercent, 2) : 0),
             );
         }
 

+ 7 - 1
modules/boonex/polls/classes/BxPollsVoteSubentries.php

@@ -53,6 +53,8 @@ class BxPollsVoteSubentries extends BxTemplVote
     {
         $CNF = $this->_oModule->_oConfig->CNF;
 
+        $bShowInBrackets = !isset($aParams['show_in_brackets']) || $aParams['show_in_brackets'] == true;
+
         $iObjectId = $this->getId();
 		$iAuthorId = $this->_getAuthorId();
         if((int)$this->_aContentInfo[$CNF['FIELD_HIDDEN_RESULTS']] == 1)
@@ -62,7 +64,11 @@ class BxPollsVoteSubentries extends BxTemplVote
         if((int)$this->_aContentInfo[$CNF['FIELD_ANONYMOUS']] == 1)
             $this->_sTmplNameCounter = 'subentries_vc_text.html';
 
-        return '(' . parent::getCounter($aParams) . ')';
+        $sResult = parent::getCounter($aParams);
+        if($bShowInBrackets)
+            $sResult = '(' . $sResult . ')';
+
+        return $sResult;
     }
 
     public function getObjectAuthorId($iObjectId = 0)

+ 1 - 1
modules/boonex/polls/install/langs/en.xml

@@ -213,5 +213,5 @@
     <string name="_bx_polls_txt_sample_vote_single"><![CDATA[poll's vote]]></string>
     <string name="_bx_polls_txt_subentry_vote_do_by"><![CDATA[Voted for]]></string>
     <string name="_bx_polls_txt_subentry_vote_counter"><![CDATA[{0} votes]]></string>
-    <string name="_bx_polls_txt_subentry_n_votes_m_percent"><![CDATA[{0} votes ({1}%)]]></string>
+    <string name="_bx_polls_txt_subentry_vote_percent"><![CDATA[({0}%)]]></string>
 </resources>

+ 1 - 0
modules/boonex/polls/install/sql/install.sql

@@ -32,6 +32,7 @@ CREATE TABLE IF NOT EXISTS `bx_polls_subentries` (
   `title` varchar(255) NOT NULL,
   `rate` float NOT NULL default '0',
   `votes` int(11) NOT NULL default '0',
+  `order` int(11) NOT NULL default '0',
   PRIMARY KEY (`id`),
   FULLTEXT KEY `title` (`title`)
 );

+ 1 - 1
modules/boonex/polls/template/subentries_results.html

@@ -4,7 +4,7 @@
             <div class="bx-polls-result-into">__title__</div>
             <div class="bx-polls-result-graph bx-def-margin-thd-top">
                 <div class="bx-polls-rg-bar bx-def-round-corners" style="width:__width__"></div>
-                <div class="bx-polls-rg-text bx-def-padding-left bx-def-font-middle bx-def-font-grayed">__results__</div>
+                <div class="bx-polls-rg-text bx-def-padding-left bx-def-font-middle bx-def-font-grayed">__votes__&nbsp;__percent__</div>
             </div>
         </div>
     </bx_repeat:subentries>

+ 1 - 1
modules/boonex/russian/data/langs/bx_polls/ru.xml

@@ -212,5 +212,5 @@
     <string name="_bx_polls_txt_sample_vote_single"><![CDATA[голос за голосование]]></string>
     <string name="_bx_polls_txt_subentry_vote_do_by"><![CDATA[Проголосовали за]]></string>
     <string name="_bx_polls_txt_subentry_vote_counter"><![CDATA[{0} голосов]]></string>
-    <string name="_bx_polls_txt_subentry_n_votes_m_percent"><![CDATA[{0} голосов ({1}%)]]></string>
+    <string name="_bx_polls_txt_subentry_vote_percent"><![CDATA[({0}%)]]></string>
 </resources>

+ 6 - 1
template/scripts/BxBaseVote.php

@@ -122,6 +122,11 @@ class BxBaseVote extends BxDolVote
         return $this->getJsObjectName() . '.vote(this, ' . $this->getMaxValue() . ')';
     }
 
+    public function getJsClickCounter()
+    {
+        return $this->getJsObjectName() . '.toggleByPopup(this)';
+    }
+
     public function getCounter($aParams = array())
     {
         $sJsObject = $this->getJsObjectName();
@@ -142,7 +147,7 @@ class BxBaseVote extends BxDolVote
             'bx_repeat:attrs' => array(
                 array('key' => 'id', 'value' => $this->_aHtmlIds['counter']),
                 array('key' => 'class', 'value' => $sClass),
-                array('key' => 'onclick', 'value' => 'javascript:' . $sJsObject . '.toggleByPopup(this)')
+                array('key' => 'onclick', 'value' => 'javascript:' . $this->getJsClickCounter())
             ),
             'content' => (int)$aVote['count'] > 0 ? $this->_getLabelCounter($aVote['count']) : ''
         ));