BxBaseVoteLikes.php 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. <?php defined('BX_DOL') or die('hack attempt');
  2. /**
  3. * Copyright (c) UNA, Inc - https://una.io
  4. * MIT License - https://opensource.org/licenses/MIT
  5. *
  6. * @defgroup UnaBaseView UNA Base Representation Classes
  7. * @{
  8. */
  9. /**
  10. * @see BxDolVote, BxDolVoteLikes
  11. */
  12. class BxBaseVoteLikes extends BxDolVoteLikes
  13. {
  14. public function __construct($sSystem, $iId, $iInit = true, $oTemplate = false)
  15. {
  16. parent::__construct($sSystem, $iId, $iInit, $oTemplate);
  17. $this->_sJsClsName .= 'Likes';
  18. $sHtmlId = str_replace(array('_' , ' '), array('-', '-'), $sSystem) . '-' . $iId;
  19. $this->_aHtmlIds = array_merge($this->_aHtmlIds, array(
  20. 'main' => 'bx-vote-likes-' . $sHtmlId
  21. ));
  22. $this->_aElementDefaults = array(
  23. 'show_do_vote_as_button' => false,
  24. 'show_do_vote_as_button_small' => false,
  25. 'show_do_vote_icon' => true,
  26. 'show_do_vote_label' => false,
  27. 'show_counter' => true,
  28. 'show_counter_empty' => false,
  29. 'show_counter_label_icon' => false,
  30. 'show_counter_label_text' => true,
  31. 'show_legend' => false,
  32. 'show_script' => true
  33. );
  34. $this->_sTmplContentDoActionLabel = $this->_oTemplate->getHtml('vote_do_vote_label_likes.html');
  35. $this->_sTmplContentCounterLabel = $this->_oTemplate->getHtml('vote_counter_label_likes.html');
  36. }
  37. public function getJsClick($iValue = 0)
  38. {
  39. if(empty($iValue))
  40. $iValue = $this->getValue();
  41. return parent::getJsClick($iValue);
  42. }
  43. public function getCounter($aParams = array())
  44. {
  45. $sClass = '';
  46. if(isset($aParams['show_do_vote_as_button_small']) && $aParams['show_do_vote_as_button_small'] == true)
  47. $sClass = 'bx-btn-small-height';
  48. else if(isset($aParams['show_do_vote_as_button']) && $aParams['show_do_vote_as_button'] == true)
  49. $sClass = 'bx-btn-height';
  50. $aParams['class_counter'] = isset($aParams['class_counter']) ? $aParams['class_counter'] : '';
  51. $aParams['class_counter'] .= ' ' . $sClass;
  52. return parent::getCounter($aParams);
  53. }
  54. public function getElement($aParams = array())
  55. {
  56. $sClass = $this->_sStylePrefix . '-' . $this->_sType;
  57. if(isset($aParams['show_do_vote_as_button_small']) && $aParams['show_do_vote_as_button_small'] == true)
  58. $sClass .= '-button-small';
  59. else if(isset($aParams['show_do_vote_as_button']) && $aParams['show_do_vote_as_button'] == true)
  60. $sClass .= '-button';
  61. $aParams['class_element'] = isset($aParams['class_element']) ? $aParams['class_element'] : '';
  62. $aParams['class_element'] .= ' ' . $sClass;
  63. return parent::getElement($aParams);
  64. }
  65. /**
  66. * Internal methods.
  67. */
  68. protected function _getDoVote($aParams = array(), $isAllowedVote = true)
  69. {
  70. $bVoted = isset($aParams['is_voted']) && $aParams['is_voted'] === true;
  71. $bShowDoVoteAsButtonSmall = isset($aParams['show_do_vote_as_button_small']) && $aParams['show_do_vote_as_button_small'] == true;
  72. $bShowDoVoteAsButton = !$bShowDoVoteAsButtonSmall && isset($aParams['show_do_vote_as_button']) && $aParams['show_do_vote_as_button'] == true;
  73. $bDisabled = !$isAllowedVote || ($bVoted && !$this->isUndo());
  74. $sClass = '';
  75. if($bShowDoVoteAsButton)
  76. $sClass = 'bx-btn';
  77. else if ($bShowDoVoteAsButtonSmall)
  78. $sClass = 'bx-btn bx-btn-small';
  79. if($bDisabled)
  80. $sClass .= $bShowDoVoteAsButton || $bShowDoVoteAsButtonSmall ? ' bx-btn-disabled' : 'bx-vote-disabled';
  81. return $this->_oTemplate->parseLink('javascript:void(0)', $this->_getDoVoteLabel($aParams), array(
  82. 'class' => $this->_sStylePrefix . '-do-vote ' . $sClass,
  83. 'title' => _t($this->_getTitleDo($bVoted)),
  84. 'onclick' => !$bDisabled ? $this->getJsClick() : ''
  85. ));
  86. }
  87. protected function _getDoVoteLabel($aParams = array())
  88. {
  89. $bVoted = isset($aParams['is_voted']) && $aParams['is_voted'] === true;
  90. return $this->_oTemplate->parseHtmlByContent($this->_getTmplContentDoActionLabel(), array(
  91. 'bx_if:show_icon' => array(
  92. 'condition' => isset($aParams['show_do_vote_icon']) && $aParams['show_do_vote_icon'] == true,
  93. 'content' => array(
  94. 'style_prefix' => $this->_sStylePrefix,
  95. 'name' => $this->_getIconDo($bVoted)
  96. )
  97. ),
  98. 'bx_if:show_text' => array(
  99. 'condition' => isset($aParams['show_do_vote_label']) && $aParams['show_do_vote_label'] == true,
  100. 'content' => array(
  101. 'style_prefix' => $this->_sStylePrefix,
  102. 'text' => _t($this->_getTitleDo($bVoted))
  103. )
  104. )
  105. ));
  106. }
  107. protected function _getCounterLabel($iCount, $aParams = array())
  108. {
  109. $bVoted = isset($aParams['is_voted']) && $aParams['is_voted'] === true;
  110. return $this->_oTemplate->parseHtmlByContent($this->_getTmplContentCounterLabel(), array(
  111. 'bx_if:show_icon' => array(
  112. 'condition' => !isset($aParams['show_counter_label_icon']) || $aParams['show_counter_label_icon'] === true,
  113. 'content' => array(
  114. 'style_prefix' => $this->_sStylePrefix,
  115. 'name' => $this->_getIconDo($bVoted)
  116. )
  117. ),
  118. 'bx_if:show_text' => array(
  119. 'condition' => !isset($aParams['show_counter_label_text']) || $aParams['show_counter_label_text'] === true,
  120. 'content' => array(
  121. 'style_prefix' => $this->_sStylePrefix,
  122. 'text' => parent::_getCounterLabel($iCount)
  123. )
  124. )
  125. ));
  126. }
  127. protected function _isShowDoVote($aParams, $isAllowedVote, $bCount)
  128. {
  129. $bResult = parent::_isShowDoVote($aParams, $isAllowedVote, $bCount);
  130. if(!$bResult)
  131. return $bResult;
  132. return $isAllowedVote || $bCount;
  133. }
  134. }
  135. /** @} */