BxBaseVoteLikes.php 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  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. protected static $_sTmplContentDoVoteLabelLikes;
  15. public function __construct($sSystem, $iId, $iInit = true, $oTemplate = false)
  16. {
  17. parent::__construct($sSystem, $iId, $iInit, $oTemplate);
  18. $this->_sJsClsName .= 'Likes';
  19. $sHtmlId = str_replace(array('_' , ' '), array('-', '-'), $sSystem) . '-' . $iId;
  20. $this->_aHtmlIds = array_merge($this->_aHtmlIds, array(
  21. 'main' => 'bx-vote-likes-' . $sHtmlId
  22. ));
  23. $this->_aElementDefaults = array(
  24. 'show_do_vote_as_button' => false,
  25. 'show_do_vote_as_button_small' => false,
  26. 'show_do_vote_icon' => true,
  27. 'show_do_vote_label' => false,
  28. 'show_counter' => true,
  29. 'show_counter_empty' => false,
  30. 'show_legend' => false
  31. );
  32. if(empty(self::$_sTmplContentDoVoteLabelLikes))
  33. self::$_sTmplContentDoVoteLabelLikes = $this->_oTemplate->getHtml('vote_do_vote_likes_label.html');
  34. }
  35. public function getJsClick($iValue = 0)
  36. {
  37. if(empty($iValue))
  38. $iValue = $this->getValue();
  39. return parent::getJsClick($iValue);
  40. }
  41. public function getCounter($aParams = array())
  42. {
  43. $sClass = '';
  44. if(isset($aParams['show_do_vote_as_button_small']) && $aParams['show_do_vote_as_button_small'] == true)
  45. $sClass = 'bx-btn-small-height';
  46. else if(isset($aParams['show_do_vote_as_button']) && $aParams['show_do_vote_as_button'] == true)
  47. $sClass = 'bx-btn-height';
  48. $aParams['class_counter'] = isset($aParams['class_counter']) ? $aParams['class_counter'] : '';
  49. $aParams['class_counter'] .= ' ' . $sClass;
  50. return parent::getCounter($aParams);
  51. }
  52. public function getElement($aParams = array())
  53. {
  54. $sClass = $this->_sStylePrefix . '-' . $this->_sType;
  55. if(isset($aParams['show_do_vote_as_button_small']) && $aParams['show_do_vote_as_button_small'] == true)
  56. $sClass .= '-button-small';
  57. else if(isset($aParams['show_do_vote_as_button']) && $aParams['show_do_vote_as_button'] == true)
  58. $sClass .= '-button';
  59. $aParams['class_element'] = isset($aParams['class_element']) ? $aParams['class_element'] : '';
  60. $aParams['class_element'] .= ' ' . $sClass;
  61. return parent::getElement($aParams);
  62. }
  63. /**
  64. * Internal methods.
  65. */
  66. protected function _getDoVote($aParams = array(), $isAllowedVote = true)
  67. {
  68. $bVoted = isset($aParams['is_voted']) && $aParams['is_voted'] === true;
  69. $bShowDoVoteAsButtonSmall = isset($aParams['show_do_vote_as_button_small']) && $aParams['show_do_vote_as_button_small'] == true;
  70. $bShowDoVoteAsButton = !$bShowDoVoteAsButtonSmall && isset($aParams['show_do_vote_as_button']) && $aParams['show_do_vote_as_button'] == true;
  71. $bDisabled = !$isAllowedVote || ($bVoted && !$this->isUndo());
  72. $sClass = '';
  73. if($bShowDoVoteAsButton)
  74. $sClass = 'bx-btn';
  75. else if ($bShowDoVoteAsButtonSmall)
  76. $sClass = 'bx-btn bx-btn-small';
  77. if($bDisabled)
  78. $sClass .= $bShowDoVoteAsButton || $bShowDoVoteAsButtonSmall ? ' bx-btn-disabled' : 'bx-vote-disabled';
  79. return $this->_oTemplate->parseLink('javascript:void(0)', $this->_getDoVoteLabel($aParams), array(
  80. 'class' => $this->_sStylePrefix . '-do-vote ' . $sClass,
  81. 'title' => _t($this->_getTitleDo($bVoted)),
  82. 'onclick' => !$bDisabled ? $this->getJsClick() : ''
  83. ));
  84. }
  85. protected function _getDoVoteLabel($aParams = array())
  86. {
  87. $bVoted = isset($aParams['is_voted']) && $aParams['is_voted'] === true;
  88. return $this->_oTemplate->parseHtmlByContent($this->_getTmplContentDoVoteLabel(), array(
  89. 'bx_if:show_icon' => array(
  90. 'condition' => isset($aParams['show_do_vote_icon']) && $aParams['show_do_vote_icon'] == true,
  91. 'content' => array(
  92. 'name' => $this->_getIconDo($bVoted)
  93. )
  94. ),
  95. 'bx_if:show_text' => array(
  96. 'condition' => isset($aParams['show_do_vote_label']) && $aParams['show_do_vote_label'] == true,
  97. 'content' => array(
  98. 'text' => _t($this->_getTitleDo($bVoted))
  99. )
  100. )
  101. ));
  102. }
  103. protected function _isShowDoVote($aParams, $isAllowedVote, $bCount)
  104. {
  105. $bResult = parent::_isShowDoVote($aParams, $isAllowedVote, $bCount);
  106. if(!$bResult)
  107. return $bResult;
  108. return $isAllowedVote || $bCount;
  109. }
  110. protected function _getTmplContentDoVoteLabel()
  111. {
  112. return self::$_sTmplContentDoVoteLabelLikes;
  113. }
  114. }
  115. /** @} */