Bläddra i källkod

Ticket #1211 - "Voted By" list with additional info.

AntonLV 8 år sedan
förälder
incheckning
b9ecac4004

+ 2 - 1
inc/classes/BxDolObject.php

@@ -241,7 +241,8 @@ class BxDolObject extends BxDolFactory implements iBxDolReplaceable
             $oProfile->getDisplayName(),
             $oProfile->getUrl(),
             $oProfile->getThumb(),
-            $oProfile->getUnit()
+            $oProfile->getUnit(),
+            $oProfile->getUnit(0, array('template' => 'unit_wo_info'))
         );
     }
 

+ 28 - 1
inc/classes/BxDolScore.php

@@ -78,6 +78,8 @@ define('BX_DOL_SCORE_DO_DOWN', 'down');
 
 class BxDolScore extends BxDolObject
 {
+    protected $_aElementDefaults;
+
     protected function __construct($sSystem, $iId, $iInit = true, $oTemplate = false)
     {
         parent::__construct($sSystem, $iId, $iInit, $oTemplate);
@@ -203,7 +205,9 @@ class BxDolScore extends BxDolObject
         if (!$this->isEnabled())
            return '';
 
-        return $this->_getVotedBy();
+        $aParams = $this->_decodeElementParams(bx_process_input(bx_get('element_params')));
+
+        return $this->_getVotedBy($aParams);
     }
 
 
@@ -326,6 +330,29 @@ class BxDolScore extends BxDolObject
     {
     	return '_sys_score_do_by';
     }
+
+    protected function _encodeElementParams($aParams)
+    {
+        if(empty($aParams) || !is_array($aParams))
+            return '';
+
+        return urlencode(base64_encode(serialize($aParams)));
+    }
+
+    protected function _decodeElementParams($sParams, $bMergeWithDefaults = true)
+    {
+        $aParams = array();
+        if(!empty($sParams))
+            $aParams = unserialize(base64_decode(urldecode($sParams)));
+
+        if(empty($aParams) || !is_array($aParams))
+            $aParams = array();
+
+        if($bMergeWithDefaults)
+            $aParams = array_merge($this->_aElementDefaults, $aParams);
+
+        return $aParams;
+    }
 }
 
 /** @} */

+ 14 - 0
inc/classes/BxDolScoreQuery.php

@@ -32,6 +32,20 @@ class BxDolScoreQuery extends BxDolObjectQuery
         $this->_sMethodGetEntry = 'getScore';
     }
 
+    public function getPerformedBy($iObjectId)
+    {
+        $sQuery = "SELECT 
+            	`author_id` AS `id`, 
+            	`type` AS `vote_type`, 
+            	`date` AS `vote_date` 
+			FROM `{$this->_sTableTrack}` 
+			WHERE `object_id`=:object_id";
+
+        return $this->getAll($sQuery, array(
+        	'object_id' => $iObjectId
+        ));
+    }
+
     public function isPostTimeoutEnded($iObjectId, $sAuthorIp)
     {
         if($this->_iPostTimeout == 0)

+ 5 - 3
inc/js/classes/BxDolScore.js

@@ -9,9 +9,10 @@
 function BxDolScore(options)
 {
 	this._sObjName = undefined == options.sObjName ? 'oScore' : options.sObjName; // javascript object name, to run current object instance from onTimer
-	this._sSystem = options.sSystem; // current comment system
-	this._iAuthorId = options.iAuthorId; // this comment's author ID.
-    this._iObjId = options.iObjId; // this object id comments
+	this._sSystem = options.sSystem; // current score system
+	this._iAuthorId = options.iAuthorId; // score's author ID.
+	this._iObjId = options.iObjId; // object id the scores are collected for
+    this._sElementParams = options.sElementParams;
 
     this._sActionsUri = 'score.php';
     this._sActionsUrl = options.sRootUrl + this._sActionsUri; // actions url address
@@ -118,6 +119,7 @@ BxDolScore.prototype._getDefaultParams = function() {
     return {
         sys: this._sSystem,
         id: this._iObjId,
+        element_params: this._sElementParams,
         _t: oDate.getTime()
     };
 };

+ 24 - 1
template/css/score.css

@@ -1,4 +1,4 @@
-/*--- Comment Plused By ---*/
+/*--- Comment Voted By ---*/
 div.bx-score-by-list {}
 div.bx-score-by-list-cnt {
 	max-height: 200px;
@@ -12,6 +12,29 @@ div.bx-score-by-list div.bx-base-pofile-unit {
 	margin-right: 0px;
 	margin-bottom: 0px;
 }
+div.bx-score-by-item {
+	display: -webkit-flex;
+    display: flex;
+    align-items: center;
+    -webkit-align-items: center;
+	flex-wrap: nowrap;
+    -webkit-flex-wrap: nowrap;
+}
+div.bx-score-by-item .bx-score-bi-user,
+div.bx-score-by-item .bx-score-bi-info,
+div.bx-score-by-item .bx-score-bi-vote {
+	-webkit-flex: 0 1 auto; 
+    -ms-flex: 0 1 auto; 
+    flex: 0 1 auto;
+}
+div.bx-score-by-item .bx-score-bi-info {
+	-webkit-flex-grow: 3; 
+    flex-grow: 3;
+}
+div.bx-score-by-item .bx-score-bi-vote {
+	width: 1.25rem;
+    height: 1.25rem;
+}
 
 /*--- Vote Element Styles ---*/
 div.bx-score-element-holder,

+ 8 - 1
template/score_by_list.html

@@ -2,7 +2,14 @@
 	<div class="__style_prefix__-by-list-cnt">
 		<div class="__style_prefix__-by-items">
 			<bx_repeat:list>
-				<div class="__style_prefix__-by-item bx-def-padding-sec bx-clearfix">__user_unit__</div>
+				<div class="__style_prefix__-by-item bx-def-padding-sec bx-clearfix">
+				    <div class="__style_prefix__-bi-user">__user_unit__</div>
+				    <div class="__style_prefix__-bi-info bx-def-padding-sec-left">
+				        <div><a href="__user_link__">__user_name__</a></div>
+				        <div class="bx-def-font-small bx-def-font-grayed">__date__</div>
+				    </div>
+				    <div class="__style_prefix__-bi-vote">__vote__</div>
+				</div>
 			</bx_repeat:list>
 		</div>
 	</div>

+ 16 - 12
template/scripts/BxBaseScore.php

@@ -23,8 +23,6 @@ class BxBaseScore extends BxDolScore
 
     protected $_aHtmlIds;
 
-    protected $_aElementDefaults;
-
     protected $_sTmplNameLegend;
     protected $_sTmplNameByList;
 
@@ -85,18 +83,21 @@ class BxBaseScore extends BxDolScore
         return $this->_sJsObjName;
     }
 
-    public function getJsScript($bDynamicMode = false)
+    public function getJsScript($aParams = array())
     {
-        $aParams = array(
+        $bDynamicMode = isset($aParams['dynamic_mode']) && $aParams['dynamic_mode'] === true;
+
+        $aParamsJs = array(
             'sObjName' => $this->_sJsObjName,
             'sSystem' => $this->getSystemName(),
             'iAuthorId' => $this->_getAuthorId(),
             'iObjId' => $this->getId(),
+            'sElementParams' => $this->_encodeElementParams($aParams),
             'sRootUrl' => BX_DOL_URL_ROOT,
             'sStylePrefix' => $this->_sStylePrefix,
             'aHtmlIds' => $this->_aHtmlIds
         );
-        $sCode = $this->_sJsObjName . " = new BxDolScore(" . json_encode($aParams) . ");";
+        $sCode = $this->_sJsObjName . " = new BxDolScore(" . json_encode($aParamsJs) . ");";
 
         if($bDynamicMode) {
 			$sCode = "var " . $this->_sJsObjName . " = null; 
@@ -188,7 +189,6 @@ class BxBaseScore extends BxDolScore
     public function getElement($aParams = array())
     {
     	$aParams = array_merge($this->_aElementDefaults, $aParams);
-    	$bDynamicMode = isset($aParams['dynamic_mode']) && $aParams['dynamic_mode'] === 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;
@@ -266,7 +266,7 @@ class BxBaseScore extends BxDolScore
             	'condition' => $bTmplVarsLegend,
             	'content' => $aTmplVarsLegend
             ),
-            'script' => $this->getJsScript($bDynamicMode)
+            'script' => $this->getJsScript($aParams)
         ));
     }
 
@@ -322,16 +322,20 @@ class BxBaseScore extends BxDolScore
         ));
     }
 
-    protected function _getVotedBy()
+    protected function _getVotedBy($aParams)
     {
         $aTmplUsers = array();
 
-        $aUserIds = $this->_oQuery->getPerformedBy($this->getId());
-        foreach($aUserIds as $iUserId) {
-            list($sUserName, $sUserUrl, $sUserIcon, $sUserUnit) = $this->_getAuthorInfo($iUserId);
+        $aUsers = $this->_oQuery->getPerformedBy($this->getId());
+        foreach($aUsers as $aUser) {
+            list($sUserName, $sUserLink, $sUserIcon, $sUserUnit, $sUserUnitWoInfo) = $this->_getAuthorInfo($aUser['id']);
             $aTmplUsers[] = array(
                 'style_prefix' => $this->_sStylePrefix,
-                'user_unit' => $sUserUnit
+            	'user_name' => $sUserName,
+            	'user_link' => $sUserLink,
+                'user_unit' => $sUserUnitWoInfo,
+                'vote' => $this->_getLabelDo($aUser['vote_type'], $aParams),
+                'date' => bx_time_js($aUser['vote_date']),
             );
         }