|
|
@@ -12,9 +12,8 @@
|
|
|
*/
|
|
|
class BxBaseVoteReactions extends BxDolVoteReactions
|
|
|
{
|
|
|
- protected static $_sTmplContentDoVoteLabelReactions;
|
|
|
- protected static $_sTmplContentCounterWrapper;
|
|
|
- protected static $_sTmplContentCounterLabel;
|
|
|
+ protected $_sTmplNameBySummary;
|
|
|
+ protected $_sTmplContentCounterWrapper = '';
|
|
|
|
|
|
public function __construct($sSystem, $iId, $iInit = true, $oTemplate = false)
|
|
|
{
|
|
|
@@ -36,17 +35,17 @@ class BxBaseVoteReactions extends BxDolVoteReactions
|
|
|
'show_do_vote_label' => false,
|
|
|
'show_counter' => false,
|
|
|
'show_counter_empty' => true,
|
|
|
- 'show_legend' => false
|
|
|
+ 'show_counter_style' => self::$_sCounterStyleDivided, //--- Alloved styles are 'divided' and 'compound'
|
|
|
+ 'show_legend' => false,
|
|
|
+ 'show_script' => true
|
|
|
);
|
|
|
|
|
|
- if(empty(self::$_sTmplContentDoVoteLabelReactions))
|
|
|
- self::$_sTmplContentDoVoteLabelReactions = $this->_oTemplate->getHtml('vote_do_vote_reactions_label.html');
|
|
|
+ $this->_sTmplNameBySummary = 'vote_by_summary_reactions.html';
|
|
|
+ $this->_sTmplNameByList = 'vote_by_list_reactions.html';
|
|
|
|
|
|
- if(empty(self::$_sTmplContentCounterWrapper))
|
|
|
- self::$_sTmplContentCounterWrapper = $this->_oTemplate->getHtml('vote_counter_wrapper_reactions.html');
|
|
|
-
|
|
|
- if(empty(self::$_sTmplContentCounterLabel))
|
|
|
- self::$_sTmplContentCounterLabel = $this->_oTemplate->getHtml('vote_counter_label_reactions.html');
|
|
|
+ $this->_sTmplContentDoActionLabel = $this->_oTemplate->getHtml('vote_do_vote_label_reactions.html');
|
|
|
+ $this->_sTmplContentCounterLabel = $this->_oTemplate->getHtml('vote_counter_label_reactions.html');
|
|
|
+ $this->_sTmplContentCounterWrapper = $this->_oTemplate->getHtml('vote_counter_wrapper_reactions.html');
|
|
|
}
|
|
|
|
|
|
public function getJsClick($iValue = 0)
|
|
|
@@ -67,13 +66,34 @@ class BxBaseVoteReactions extends BxDolVoteReactions
|
|
|
|
|
|
public function getJsClickCounter($aParams = array())
|
|
|
{
|
|
|
- $sReaction = !empty($aParams['reaction']) ? $aParams['reaction'] : $this->_sDefault;
|
|
|
+ $sJsObject = $this->getJsObjectName();
|
|
|
+ $sJsMethod = 'toggleByPopup';
|
|
|
+
|
|
|
+ if(isset($aParams['show_counter_style']) && $aParams['show_counter_style'] == self::$_sCounterStyleCompound)
|
|
|
+ return $sJsObject . '.' . $sJsMethod . '(this)';
|
|
|
|
|
|
- return $this->getJsObjectName() . '.toggleByPopup(this, \'' . $sReaction . '\')';
|
|
|
+ $sReaction = !empty($aParams['reaction']) ? $aParams['reaction'] : $this->_sDefault;
|
|
|
+ return $sJsObject . '.' . $sJsMethod . '(this, \'' . $sReaction . '\')';
|
|
|
}
|
|
|
|
|
|
public function getCounter($aParams = array())
|
|
|
{
|
|
|
+ $sDefault = $this->_aElementDefaults['show_counter_style'];
|
|
|
+ $sCounterStyle = !empty($aParams['show_counter_style']) ? $aParams['show_counter_style'] : $sDefault;
|
|
|
+
|
|
|
+ $sMethodPrefix = '_getCounter';
|
|
|
+ $sMethod = $sMethodPrefix . bx_gen_method_name($sCounterStyle);
|
|
|
+ if(!method_exists($this, $sMethod))
|
|
|
+ $sMethod = $sMethodPrefix . bx_gen_method_name($sDefault);
|
|
|
+
|
|
|
+ return $this->$sMethod($aParams);
|
|
|
+ }
|
|
|
+
|
|
|
+ public function _getCounterDivided($aParams = array())
|
|
|
+ {
|
|
|
+ $bDynamicMode = isset($aParams['dynamic_mode']) && $aParams['dynamic_mode'] === true;
|
|
|
+ $bShowScript = !isset($aParams['show_script']) || $aParams['show_script'] == true;
|
|
|
+
|
|
|
$aVote = $this->_getVote();
|
|
|
$aReactions = $this->getReactions();
|
|
|
|
|
|
@@ -96,14 +116,79 @@ class BxBaseVoteReactions extends BxDolVoteReactions
|
|
|
'rate' => $aVote['rate_' . $sName],
|
|
|
);
|
|
|
|
|
|
- $sResult .= parent::getCounter($aParams);
|
|
|
+ $sResult .= parent::getCounter(array_merge($aParams, array('show_script' => false)));
|
|
|
+ }
|
|
|
+
|
|
|
+ return $this->_oTemplate->parseHtmlByContent($this->_getTmplContentCounterWrapper(), array(
|
|
|
+ 'html_id' => $this->_aHtmlIds['counter'],
|
|
|
+ 'style_prefix' => $this->_sStylePrefix,
|
|
|
+ 'type' => $this->_sType,
|
|
|
+ 'style' => self::$_sCounterStyleDivided,
|
|
|
+ 'counter' => $sResult,
|
|
|
+ 'script' => $bShowScript ? $this->getJsScript($bDynamicMode) : ''
|
|
|
+ ));
|
|
|
+ }
|
|
|
+
|
|
|
+ public function _getCounterCompound($aParams = array())
|
|
|
+ {
|
|
|
+ $bDynamicMode = isset($aParams['dynamic_mode']) && $aParams['dynamic_mode'] === true;
|
|
|
+ $bShowScript = !isset($aParams['show_script']) || $aParams['show_script'] == true;
|
|
|
+
|
|
|
+ $aVote = $this->_getVote();
|
|
|
+ $aReactions = $this->getReactions();
|
|
|
+
|
|
|
+ $sClass = isset($aParams['class_counter']) ? $aParams['class_counter'] : '';
|
|
|
+ if(isset($aParams['show_do_vote_as_button_small']) && $aParams['show_do_vote_as_button_small'] == true)
|
|
|
+ $sClass .= ' bx-btn-small-height';
|
|
|
+ else if(isset($aParams['show_do_vote_as_button']) && $aParams['show_do_vote_as_button'] == true)
|
|
|
+ $sClass .= ' bx-btn-height';
|
|
|
+
|
|
|
+ $aParams['id_counter'] = '';
|
|
|
+
|
|
|
+ $sResult = '';
|
|
|
+ $iResultC = $iResultS = 0;
|
|
|
+ foreach($aReactions as $sName) {
|
|
|
+ $iCount = (int)$aVote['count_' . $sName];
|
|
|
+
|
|
|
+ $aParams = array_merge($aParams, array(
|
|
|
+ 'show_counter_active' => false,
|
|
|
+ 'show_counter_label_icon' => true,
|
|
|
+ 'show_counter_label_text' => false,
|
|
|
+ 'class_counter' => ($iCount == 0 ? ' bx-vc-hidden' : '') . ' ' . $sName . ' ' . $sClass,
|
|
|
+ 'reaction' => $sName,
|
|
|
+ 'vote' => array(
|
|
|
+ 'count' => $iCount,
|
|
|
+ 'sum' => $aVote['sum_' . $sName],
|
|
|
+ 'rate' => $aVote['rate_' . $sName],
|
|
|
+ )
|
|
|
+ ));
|
|
|
+
|
|
|
+ $iResultC += $iCount;
|
|
|
+ $iResultS += (int)$aVote['sum_' . $sName];
|
|
|
+ $sResult .= trim(parent::getCounter(array_merge($aParams, array('show_script' => false))));
|
|
|
}
|
|
|
|
|
|
+ $aParams = array_merge($aParams, array(
|
|
|
+ 'show_counter_active' => true,
|
|
|
+ '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,
|
|
|
+ )
|
|
|
+ ));
|
|
|
+ $sResult .= parent::getCounter(array_merge($aParams, array('show_script' => false)));
|
|
|
+
|
|
|
return $this->_oTemplate->parseHtmlByContent($this->_getTmplContentCounterWrapper(), array(
|
|
|
'html_id' => $this->_aHtmlIds['counter'],
|
|
|
'style_prefix' => $this->_sStylePrefix,
|
|
|
'type' => $this->_sType,
|
|
|
- 'counter' => $sResult
|
|
|
+ 'style' => self::$_sCounterStyleCompound,
|
|
|
+ 'counter' => $sResult,
|
|
|
+ 'script' => $bShowScript ? $this->getJsScript($bDynamicMode) : ''
|
|
|
));
|
|
|
}
|
|
|
|
|
|
@@ -170,16 +255,18 @@ class BxBaseVoteReactions extends BxDolVoteReactions
|
|
|
{
|
|
|
$bVoted = isset($aParams['is_voted']) && $aParams['is_voted'] === true;
|
|
|
|
|
|
- return $this->_oTemplate->parseHtmlByContent($this->_getTmplContentDoVoteLabel(), array(
|
|
|
+ return $this->_oTemplate->parseHtmlByContent($this->_getTmplContentDoActionLabel(), array(
|
|
|
'bx_if:show_icon' => array(
|
|
|
'condition' => isset($aParams['show_do_vote_icon']) && $aParams['show_do_vote_icon'] == true,
|
|
|
'content' => array(
|
|
|
+ 'style_prefix' => $this->_sStylePrefix,
|
|
|
'name' => $this->_getIconDoWithTrack($bVoted, $aParams['track'])
|
|
|
)
|
|
|
),
|
|
|
'bx_if:show_text' => array(
|
|
|
'condition' => isset($aParams['show_do_vote_label']) && $aParams['show_do_vote_label'] == true,
|
|
|
'content' => array(
|
|
|
+ 'style_prefix' => $this->_sStylePrefix,
|
|
|
'text' => _t($this->_getTitleDoWithTrack($bVoted, $aParams['track']))
|
|
|
)
|
|
|
)
|
|
|
@@ -202,26 +289,56 @@ class BxBaseVoteReactions extends BxDolVoteReactions
|
|
|
return $oMenu->getCode();
|
|
|
}
|
|
|
|
|
|
- protected function _getLabelCounter($iCount, $aParams = array())
|
|
|
+ protected function _getCounterLabel($iCount, $aParams = array())
|
|
|
{
|
|
|
$sReaction = !empty($aParams['reaction']) ? $aParams['reaction'] : $this->_sDefault;
|
|
|
|
|
|
return $this->_oTemplate->parseHtmlByContent($this->_getTmplContentCounterLabel(), array(
|
|
|
- 'name' => $this->_aDataList[$sReaction]['icon'],
|
|
|
- 'text' => parent::_getLabelCounter($iCount)
|
|
|
+ 'bx_if:show_icon' => array(
|
|
|
+ 'condition' => !isset($aParams['show_counter_label_icon']) || $aParams['show_counter_label_icon'] === true,
|
|
|
+ 'content' => array(
|
|
|
+ 'style_prefix' => $this->_sStylePrefix,
|
|
|
+ 'name' => $this->_aDataList[$sReaction]['icon']
|
|
|
+ )
|
|
|
+ ),
|
|
|
+ 'bx_if:show_text' => array(
|
|
|
+ 'condition' => !isset($aParams['show_counter_label_text']) || $aParams['show_counter_label_text'] === true,
|
|
|
+ 'content' => array(
|
|
|
+ 'style_prefix' => $this->_sStylePrefix,
|
|
|
+ 'text' => parent::_getCounterLabel($iCount)
|
|
|
+ )
|
|
|
+ )
|
|
|
));
|
|
|
}
|
|
|
|
|
|
protected function _getVotedBy($aParams = array())
|
|
|
{
|
|
|
+ if(!isset($aParams['reaction']))
|
|
|
+ return $this->_getVotedBySummary($aParams);
|
|
|
+
|
|
|
+ $bSummary = $aParams['reaction'] == 'summary';
|
|
|
+
|
|
|
+ $aBrowseParams = array('type' => 'by', 'object_id' => $this->getId());
|
|
|
+ if(!$bSummary)
|
|
|
+ $aBrowseParams['reaction'] = $aParams['reaction'];
|
|
|
+
|
|
|
+ $aValues = $this->_oQuery->getPerformed($aBrowseParams);
|
|
|
+
|
|
|
$aTmplUsers = array();
|
|
|
+ foreach($aValues as $mValue) {
|
|
|
+ $mValue = is_array($mValue) ? $mValue : array('author_id' => (int)$mValue, 'reaction' => '');
|
|
|
|
|
|
- $aUserIds = $this->_oQuery->getPerformed(array('type' => 'by', 'object_id' => $this->getId(), 'reaction' => $aParams['reaction']));
|
|
|
- foreach($aUserIds as $iUserId) {
|
|
|
- list($sUserName, $sUserUrl, $sUserIcon, $sUserUnit) = $this->_getAuthorInfo($iUserId);
|
|
|
+ list($sUserName, $sUserUrl, $sUserIcon, $sUserUnit) = $this->_getAuthorInfo($mValue['author_id']);
|
|
|
$aTmplUsers[] = array(
|
|
|
'style_prefix' => $this->_sStylePrefix,
|
|
|
- 'user_unit' => $sUserUnit
|
|
|
+ 'user_unit' => $sUserUnit,
|
|
|
+ 'bx_if:show_reaction' => array(
|
|
|
+ 'condition' => $bSummary,
|
|
|
+ 'content' => array(
|
|
|
+ 'style_prefix' => $this->_sStylePrefix,
|
|
|
+ 'icon' => $bSummary ? $this->_aDataList[$mValue['reaction']]['icon'] : ''
|
|
|
+ )
|
|
|
+ )
|
|
|
);
|
|
|
}
|
|
|
|
|
|
@@ -230,23 +347,48 @@ class BxBaseVoteReactions extends BxDolVoteReactions
|
|
|
|
|
|
return $this->_oTemplate->parseHtmlByName($this->_sTmplNameByList, array(
|
|
|
'style_prefix' => $this->_sStylePrefix,
|
|
|
+ 'class' => ' ' . $this->_sStylePrefix . '-bl-' . $aParams['reaction'],
|
|
|
'bx_repeat:list' => $aTmplUsers
|
|
|
));
|
|
|
}
|
|
|
|
|
|
- protected function _getTmplContentDoVoteLabel()
|
|
|
+ protected function _getVotedBySummary($aParams = array())
|
|
|
{
|
|
|
- return self::$_sTmplContentDoVoteLabelReactions;
|
|
|
- }
|
|
|
+ $sJsObject = $this->getJsObjectName();
|
|
|
|
|
|
- protected function _getTmplContentCounterWrapper()
|
|
|
- {
|
|
|
- return self::$_sTmplContentCounterWrapper;
|
|
|
+ $sTxtSummary = _t('_vote_do_by_summary');
|
|
|
+ $aReactions = array_merge(array('summary'), $this->getReactions());
|
|
|
+
|
|
|
+ $aMenuItems = array();
|
|
|
+ $aTmplVarsLists = array();
|
|
|
+ foreach ($aReactions as $sReaction) {
|
|
|
+ $bSummary = $sReaction == 'summary';
|
|
|
+
|
|
|
+ $sName = $this->_sStylePrefix . '-' . $sReaction;
|
|
|
+ $sTitle = !$bSummary ? $this->_oTemplate->parseIcon($this->_aDataList[$sReaction]['icon']) : $sTxtSummary;
|
|
|
+ $sTitleAttr = !$bSummary ? _t('_vote_do_by_x_reaction', _t($this->_aDataList[$sReaction]['title'])) : $sTxtSummary;
|
|
|
+
|
|
|
+ $aMenuItems[] = array('id' => $sName, 'name' => $sName, 'class' => '', 'link' => 'javascript:void(0)', 'onclick' => 'javascript:' . $sJsObject . '.changeVotedBy(this, \'' . $sReaction . '\')', 'target' => '_self', 'title' => $sTitle, 'title_attr' => $sTitleAttr, 'active' => 1);
|
|
|
+
|
|
|
+ $aTmplVarsLists[] = array(
|
|
|
+ 'content' => $this->_getVotedBy(array('reaction' => $sReaction))
|
|
|
+ );
|
|
|
+ }
|
|
|
+
|
|
|
+ $oMenu = new BxTemplMenuInteractive(array('template' => 'menu_interactive_vertical.html', 'menu_id'=> $this->_sStylePrefix . '-voted-by', 'menu_items' => $aMenuItems));
|
|
|
+ $oMenu->setSelected('', $this->_sStylePrefix . '-summary');
|
|
|
+
|
|
|
+ return $this->_oTemplate->parseHtmlByName($this->_sTmplNameBySummary, array(
|
|
|
+ 'style_prefix' => $this->_sStylePrefix,
|
|
|
+ 'title' => '',
|
|
|
+ 'menu' => $oMenu->getCode(),
|
|
|
+ 'bx_repeat:lists' => $aTmplVarsLists
|
|
|
+ ));
|
|
|
}
|
|
|
|
|
|
- protected function _getTmplContentCounterLabel()
|
|
|
+ protected function _getTmplContentCounterWrapper()
|
|
|
{
|
|
|
- return self::$_sTmplContentCounterLabel;
|
|
|
+ return $this->_sTmplContentCounterWrapper;
|
|
|
}
|
|
|
}
|
|
|
|