Răsfoiți Sursa

#24 - System Votes integration update.

AntonLV 12 ani în urmă
părinte
comite
833f22c90e

+ 14 - 11
inc/classes/BxDolVote.php

@@ -183,11 +183,10 @@ class BxDolVote extends BxDolObject
 
     public function isLikeMode()
     {
-        $bUndo = $this->isUndo();
         $iMinValue = $this->getMinValue();
         $iMaxValue = $this->getMaxValue();
 
-        return $iMinValue == $iMaxValue && $bUndo;
+        return $iMinValue == $iMaxValue;
     }
 
     public function getMinValue()
@@ -236,16 +235,19 @@ class BxDolVote extends BxDolObject
         $iObjectId = $this->getId();
         $iAuthorId = $this->_getAuthorId();
         $iAuthorIp = $this->_getAuthorIp();
+
+        $bUndo = $this->isUndo();
         $bLikeMode = $this->isLikeMode();
 
-        $bUndo = $this->isUndo() && $this->_oQuery->isVoted($iObjectId, $iAuthorId) ? true : false;
+        $bVoted = $this->_oQuery->isVoted($iObjectId, $iAuthorId);
+        $bPerformUndo = $bVoted && $bUndo ? true : false;
 
-        if(!$bUndo && !$this->isAllowedVote(true)) {
+        if(!$bPerformUndo && !$this->isAllowedVote(true)) {
             $this->_echoResultJson(array('code' => 2, 'msg' => $this->msgErrAllowedVote()));
             return;
         }
 
-        if(!$bLikeMode && !$this->_oQuery->isPostTimeoutEnded($iObjectId, $iAuthorIp)) {
+        if((!$bLikeMode && !$this->_oQuery->isPostTimeoutEnded($iObjectId, $iAuthorIp)) || ($bLikeMode && $bVoted && !$bUndo)) {
             $this->_echoResultJson(array('code' => 3, 'msg' => _t('_vote_err_duplicate_vote')));
             return;
         }
@@ -266,14 +268,14 @@ class BxDolVote extends BxDolObject
         if($iValue > $iMaxValue)
             $iValue = $iMaxValue;
 
-        if(!$this->_oQuery->putVote($iObjectId, $iAuthorId, $iAuthorIp, $iValue, $bUndo)) {
+        if(!$this->_oQuery->putVote($iObjectId, $iAuthorId, $iAuthorIp, $iValue, $bPerformUndo)) {
             $this->_echoResultJson(array('code' => 5));
             return;
         }
 
         $this->_triggerVote();
 
-        $oZ = new BxDolAlerts($this->_sSystem, 'rate', $this->getId(), $iAuthorId, array('value' => $iValue, 'undo' => $bUndo));
+        $oZ = new BxDolAlerts($this->_sSystem, 'rate', $this->getId(), $iAuthorId, array('value' => $iValue, 'undo' => $bPerformUndo));
         $oZ->alert();
 
         $aVote = $this->_oQuery->getVote($iObjectId);
@@ -282,8 +284,9 @@ class BxDolVote extends BxDolObject
             'rate' => $aVote['rate'],
             'count' => $aVote['count'],
             'countf' => (int)$aVote['count'] > 0 ? $this->_getLabelCounter($aVote['count']) : '',
-        	'label_icon' => $bLikeMode ? $this->_getIconDoLike(!$bUndo) : '',
-        	'label_title' => $bLikeMode ? _t($this->_getTitleDoLike(!$bUndo)) : ''
+        	'label_icon' => $bLikeMode ? $this->_getIconDoLike(!$bVoted) : '',
+        	'label_title' => $bLikeMode ? _t($this->_getTitleDoLike(!$bVoted)) : '',
+        	'disabled' => !$bVoted && !$bUndo,
         ));
     }
 
@@ -369,12 +372,12 @@ class BxDolVote extends BxDolObject
 
     protected function _getIconDoLike($bVoted)
     {
-    	return $bVoted ?  'thumbs-down' : 'thumbs-up';
+    	return $bVoted && $this->isUndo() ?  'thumbs-down' : 'thumbs-up';
     }
 
     protected function _getTitleDoLike($bVoted)
     {
-    	return $bVoted ? '_vote_do_unlike' : '_vote_do_like';
+    	return $bVoted && $this->isUndo() ? '_vote_do_unlike' : '_vote_do_like';
     }
 
     protected function _triggerVote()

+ 3 - 0
inc/js/classes/BxDolVote.js

@@ -86,6 +86,9 @@ BxDolVote.prototype.vote = function (oLink, iValue)
 	    			$(oLink).attr('title', oData.label_title);
 	    			$(oLink).find('span').html(oData.label_title);
 	    		}
+
+	    		if(oData && oData.disabled)
+	    			$(oLink).removeAttr('onclick').addClass('bx-btn-disabled');
     		}
 
     		if(!$this._iLikeMode)

+ 1 - 1
modules/boonex/posts/install/sql/install.sql

@@ -192,7 +192,7 @@ INSERT INTO `sys_objects_cmts` (`Name`, `Table`, `CharsPostMin`, `CharsPostMax`,
 -- VOTES
 
 INSERT INTO `sys_objects_vote` (`Name`, `TableMain`, `TableTrack`, `PostTimeout`, `MinValue`, `MaxValue`, `IsUndo`, `IsOn`, `TriggerTable`, `TriggerFieldId`, `TriggerFieldRate`, `TriggerFieldRateCount`, `ClassName`, `ClassFile`) VALUES 
-('bx_posts', 'bx_posts_votes', 'bx_posts_votes_track', '604800', '1', '1', '1', '1', 'bx_posts_posts', 'id', 'rate', 'votes', '', '');
+('bx_posts', 'bx_posts_votes', 'bx_posts_votes_track', '604800', '1', '1', '0', '1', 'bx_posts_posts', 'id', 'rate', 'votes', '', '');
 
 -- VIEWS
 

+ 1 - 1
modules/boonex/timeline/install/sql/enable.sql

@@ -138,7 +138,7 @@ INSERT INTO `sys_objects_cmts` (`Name`, `Table`, `CharsPostMin`, `CharsPostMax`,
 
 -- VOTES
 INSERT INTO `sys_objects_vote`(`Name`, `TableMain`, `TableTrack`, `PostTimeout`, `MinValue`, `MaxValue`, `IsUndo`, `IsOn`, `TriggerTable`, `TriggerFieldId`, `TriggerFieldRate`, `TriggerFieldRateCount`, `ClassName`, `ClassFile`) VALUES 
-('bx_timeline', 'bx_timeline_votes', 'bx_timeline_votes_track', '604800', '1', '1', '1', '1', 'bx_timeline_events', 'id', 'rate', 'votes', 'BxTimelineVote', 'modules/boonex/timeline/classes/BxTimelineVote.php');
+('bx_timeline', 'bx_timeline_votes', 'bx_timeline_votes_track', '604800', '1', '1', '0', '1', 'bx_timeline_events', 'id', 'rate', 'votes', 'BxTimelineVote', 'modules/boonex/timeline/classes/BxTimelineVote.php');
 
 
 -- SEARCH

+ 21 - 5
template/scripts/BxBaseVote.php

@@ -150,7 +150,7 @@ class BxBaseVote extends BxDolVote
         $aVote = $this->_oQuery->getVote($iObjectId);
 
         $aParams = array_merge($this->_aElementDefaults[$sType], $aParams);
-        $aParams['is_voted'] = $this->isUndo() && $this->_oQuery->isVoted($iObjectId, $iAuthorId) ? true : false;
+        $aParams['is_voted'] = $this->_oQuery->isVoted($iObjectId, $iAuthorId) ? true : false;
 
         $sTmplName = 'vote_element_' . (!empty($aParams['usage']) ? $aParams['usage'] : BX_DOL_VOTE_USAGE_DEFAULT) . '.html';
         return BxDolTemplate::getInstance()->parseHtmlByName($sTmplName, array(
@@ -221,15 +221,31 @@ class BxBaseVote extends BxDolVote
 
     protected function _getDoVoteLikes($aParams = array())
     {
+    	$bVoted = isset($aParams['is_voted']) && $aParams['is_voted'] === true;
         $bShowDoVoteAsButtonSmall = isset($aParams['show_do_vote_as_button_small']) && $aParams['show_do_vote_as_button_small'] == true;
         $bShowDoVoteAsButton = !$bShowDoVoteAsButtonSmall && isset($aParams['show_do_vote_as_button']) && $aParams['show_do_vote_as_button'] == true;
+		$bDisabled = $bVoted && !$this->isUndo();
+
+        $sClass = '';
+		if($bShowDoVoteAsButton)
+			$sClass = 'bx-btn';
+		else if ($bShowDoVoteAsButtonSmall)
+			$sClass = 'bx-btn bx-btn-small';
+
+		if($bDisabled)
+			$sClass .= ' bx-btn-disabled';
 
         return BxDolTemplate::getInstance()->parseHtmlByName($this->_sTmplNameDoVoteLikes, array(
             'style_prefix' => $this->_sStylePrefix,
-            'js_object' => $this->getJsObjectName(),
-            'class' => ($bShowDoVoteAsButton ? 'bx-btn' : '') . ($bShowDoVoteAsButtonSmall ? 'bx-btn bx-btn-small' : ''),
-            'title' => _t('_vote_do_like'),
-            'value' => $this->getMinValue(),
+            'class' => $sClass,
+            'title' => _t($bVoted && $this->isUndo() ? '_vote_do_unlike' : '_vote_do_like'),
+        	'bx_if:show_onclick' => array(
+        		'condition' => !$bDisabled,
+        		'content' => array(
+        			'js_object' => $this->getJsObjectName(),
+        			'value' => $this->getMinValue(),
+        		)
+        	),
             'do_vote' => $this->_getLabelDoLike($aParams),
         ));
     }

+ 1 - 1
template/vote_do_vote_likes.html

@@ -1 +1 @@
-<a class="__style_prefix__-do-vote __class__" href="javascript:void(0)" onclick="javascript:__js_object__.vote(this, __value__)" title="__title__">__do_vote__</a>
+<a class="__style_prefix__-do-vote __class__" href="javascript:void(0)" <bx_if:show_onclick>onclick="javascript:__js_object__.vote(this, __value__)"</bx_if:show_onclick> title="__title__">__do_vote__</a>